Debian Codegraph @

source/http_proxy.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5 #include "http.h"
6
7 #include "io.h"
8
9 #include <aws/http/connection.h>
10 #include <aws/http/proxy.h>
11
12 bool aws_py_http_proxy_options_init(struct aws_http_proxy_options *proxy_options, PyObject *py_proxy_options) {
13 AWS_ZERO_STRUCT(*proxy_options);
14
15 bool success = false;
16
17 /* These references all need to be cleaned up before function returns */
18 PyObject *py_host_name = NULL;
19 PyObject *py_tls_options = NULL;
20 PyObject *py_username = NULL;
21 PyObject *py_password = NULL;
22
23 py_host_name = PyObject_GetAttrString(py_proxy_options, "host_name");
24 proxy_options->host = aws_byte_cursor_from_pyunicode(py_host_name);
25 if (!proxy_options->host.ptr) {
26 PyErr_SetString(PyExc_TypeError, "HttpProxyOptions.host_name is not a valid string");
27 goto done;
28 }
29
30 proxy_options->port = PyObject_GetAttrAsUint32(py_proxy_options, "HttpProxyOptions", "port");
31 if (PyErr_Occurred()) {
32 goto done;
33 }
34
35 py_tls_options = PyObject_GetAttrString(py_proxy_options, "tls_connection_options");
36 if (py_tls_options != Py_None) {
37 proxy_options->tls_options = aws_py_get_tls_connection_options(py_tls_options);
38 if (!proxy_options->tls_options) {
39 PyErr_SetString(
40 PyExc_TypeError, "HttpProxyOptions.tls_connection_options is not a valid TlsConnectionOptions");
41 goto done;
42 }
43 }
44
45 proxy_options->auth_type = PyObject_GetAttrAsIntEnum(py_proxy_options, "HttpProxyOptions", "auth_type");
46 if (PyErr_Occurred()) {
47 goto done;
48 }
49
50 py_username = PyObject_GetAttrString(py_proxy_options, "auth_username");
51 if (py_username != Py_None) {
52 proxy_options->auth_username = aws_byte_cursor_from_pyunicode(py_username);
53 if (!proxy_options->auth_username.ptr) {
54 PyErr_SetString(PyExc_TypeError, "HttpProxyOptions.auth_username is not a valid string");
55 goto done;
56 }
57 }
58
59 py_password = PyObject_GetAttrString(py_proxy_options, "auth_password");
60 if (py_password != Py_None) {
61 proxy_options->auth_password = aws_byte_cursor_from_pyunicode(py_password);
62 if (!proxy_options->auth_password.ptr) {
63 PyErr_SetString(PyExc_TypeError, "HttpProxyOptions.auth_password is not a valid string");
64 goto done;
65 }
66 }
67
68 proxy_options->connection_type = PyObject_GetAttrAsIntEnum(py_proxy_options, "HttpProxyOptions", "connection_type");
69 if (PyErr_Occurred()) {
70 goto done;
71 }
72
73 success = true;
74 done:
75 Py_XDECREF(py_host_name);
76 Py_XDECREF(py_tls_options);
77 Py_XDECREF(py_username);
78 Py_XDECREF(py_password);
79 if (!success) {
80 AWS_ZERO_STRUCT(*proxy_options);
81 }
82 return success;
83 }