-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathhttp_proxy_options.c
More file actions
104 lines (85 loc) · 3.33 KB
/
http_proxy_options.c
File metadata and controls
104 lines (85 loc) · 3.33 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include "crt.h"
#include "java_class_ids.h"
#include <jni.h>
#include <string.h>
#include <aws/http/proxy.h>
#include <aws/io/tls_channel_handler.h>
/* on 32-bit platforms, casting pointers to longs throws a warning we don't need */
#if UINTPTR_MAX == 0xffffffff
# if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4305) /* 'type cast': truncation from 'jlong' to 'jni_tls_ctx_options *' */
# else
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
# pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
# endif
#endif
void aws_http_proxy_options_jni_init(
JNIEnv *env,
struct aws_http_proxy_options *options,
jint proxy_connection_type,
struct aws_tls_connection_options *tls_options,
jbyteArray proxy_host,
jint proxy_port,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password,
jbyteArray no_proxy_hosts,
int proxy_authorization_type,
struct aws_tls_ctx *proxy_tls_ctx) {
struct aws_allocator *allocator = aws_jni_get_allocator();
options->connection_type = proxy_connection_type;
options->port = (uint32_t)proxy_port;
options->auth_type = proxy_authorization_type;
if (proxy_host != NULL) {
options->host = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_host);
}
if (proxy_authorization_username != NULL) {
options->auth_username = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_authorization_username);
}
if (proxy_authorization_password != NULL) {
options->auth_password = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_authorization_password);
}
if (no_proxy_hosts != NULL) {
options->no_proxy_hosts = aws_jni_byte_cursor_from_jbyteArray_acquire(env, no_proxy_hosts);
}
if (proxy_tls_ctx != NULL) {
aws_tls_connection_options_init_from_ctx(tls_options, proxy_tls_ctx);
aws_tls_connection_options_set_server_name(tls_options, allocator, &options->host);
options->tls_options = tls_options;
}
}
void aws_http_proxy_options_jni_clean_up(
JNIEnv *env,
struct aws_http_proxy_options *options,
jbyteArray proxy_host,
jbyteArray proxy_authorization_username,
jbyteArray proxy_authorization_password,
jbyteArray no_proxy_hosts) {
if (options->host.ptr != NULL) {
aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_host, options->host);
}
if (options->auth_username.ptr != NULL) {
aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_authorization_username, options->auth_username);
}
if (options->auth_password.ptr != NULL) {
aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_authorization_password, options->auth_password);
}
if (options->no_proxy_hosts.ptr != NULL) {
aws_jni_byte_cursor_from_jbyteArray_release(env, no_proxy_hosts, options->no_proxy_hosts);
}
if (options->tls_options != NULL) {
aws_tls_connection_options_clean_up((struct aws_tls_connection_options *)options->tls_options);
}
}
#if UINTPTR_MAX == 0xffffffff
# if defined(_MSC_VER)
# pragma warning(pop)
# else
# pragma GCC diagnostic pop
# endif
#endif