File: http_proxy.c

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (83 lines) | stat: -rw-r--r-- 2,849 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#include "http.h"

#include "io.h"

#include <aws/http/connection.h>
#include <aws/http/proxy.h>

bool aws_py_http_proxy_options_init(struct aws_http_proxy_options *proxy_options, PyObject *py_proxy_options) {
    AWS_ZERO_STRUCT(*proxy_options);

    bool success = false;

    /* These references all need to be cleaned up before function returns */
    PyObject *py_host_name = NULL;
    PyObject *py_tls_options = NULL;
    PyObject *py_username = NULL;
    PyObject *py_password = NULL;

    py_host_name = PyObject_GetAttrString(py_proxy_options, "host_name");
    proxy_options->host = aws_byte_cursor_from_pyunicode(py_host_name);
    if (!proxy_options->host.ptr) {
        PyErr_SetString(PyExc_TypeError, "HttpProxyOptions.host_name is not a valid string");
        goto done;
    }

    proxy_options->port = PyObject_GetAttrAsUint32(py_proxy_options, "HttpProxyOptions", "port");
    if (PyErr_Occurred()) {
        goto done;
    }

    py_tls_options = PyObject_GetAttrString(py_proxy_options, "tls_connection_options");
    if (py_tls_options != Py_None) {
        proxy_options->tls_options = aws_py_get_tls_connection_options(py_tls_options);
        if (!proxy_options->tls_options) {
            PyErr_SetString(
                PyExc_TypeError, "HttpProxyOptions.tls_connection_options is not a valid TlsConnectionOptions");
            goto done;
        }
    }

    proxy_options->auth_type = PyObject_GetAttrAsIntEnum(py_proxy_options, "HttpProxyOptions", "auth_type");
    if (PyErr_Occurred()) {
        goto done;
    }

    py_username = PyObject_GetAttrString(py_proxy_options, "auth_username");
    if (py_username != Py_None) {
        proxy_options->auth_username = aws_byte_cursor_from_pyunicode(py_username);
        if (!proxy_options->auth_username.ptr) {
            PyErr_SetString(PyExc_TypeError, "HttpProxyOptions.auth_username is not a valid string");
            goto done;
        }
    }

    py_password = PyObject_GetAttrString(py_proxy_options, "auth_password");
    if (py_password != Py_None) {
        proxy_options->auth_password = aws_byte_cursor_from_pyunicode(py_password);
        if (!proxy_options->auth_password.ptr) {
            PyErr_SetString(PyExc_TypeError, "HttpProxyOptions.auth_password is not a valid string");
            goto done;
        }
    }

    proxy_options->connection_type = PyObject_GetAttrAsIntEnum(py_proxy_options, "HttpProxyOptions", "connection_type");
    if (PyErr_Occurred()) {
        goto done;
    }

    success = true;
done:
    Py_XDECREF(py_host_name);
    Py_XDECREF(py_tls_options);
    Py_XDECREF(py_username);
    Py_XDECREF(py_password);
    if (!success) {
        AWS_ZERO_STRUCT(*proxy_options);
    }
    return success;
}