1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include "crt.h"
7 #include "java_class_ids.h"
8
9 #include <jni.h>
10 #include <string.h>
11
12 #include <aws/http/proxy.h>
13 #include <aws/io/tls_channel_handler.h>
14
15 /* on 32-bit platforms, casting pointers to longs throws a warning we don't need */
16 #if UINTPTR_MAX == 0xffffffff
17 # if defined(_MSC_VER)
18 # pragma warning(push)
19 # pragma warning(disable : 4305) /* 'type cast': truncation from 'jlong' to 'jni_tls_ctx_options *' */
20 # else
21 # pragma GCC diagnostic push
22 # pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
23 # pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
24 # endif
25 #endif
26
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,int proxy_authorization_type,struct aws_tls_ctx * proxy_tls_ctx)27 void aws_http_proxy_options_jni_init(
28 JNIEnv *env,
29 struct aws_http_proxy_options *options,
30 jint proxy_connection_type,
31 struct aws_tls_connection_options *tls_options,
32 jbyteArray proxy_host,
33 jint proxy_port,
34 jbyteArray proxy_authorization_username,
35 jbyteArray proxy_authorization_password,
36 int proxy_authorization_type,
37 struct aws_tls_ctx *proxy_tls_ctx) {
38
39 struct aws_allocator *allocator = aws_jni_get_allocator();
40
41 options->connection_type = proxy_connection_type;
42 options->port = (uint32_t)proxy_port;
43 options->auth_type = proxy_authorization_type;
44
45 if (proxy_host != NULL) {
46 options->host = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_host);
47 }
48
49 if (proxy_authorization_username != NULL) {
50 options->auth_username = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_authorization_username);
51 }
52
53 if (proxy_authorization_password != NULL) {
54 options->auth_password = aws_jni_byte_cursor_from_jbyteArray_acquire(env, proxy_authorization_password);
55 }
56
57 if (proxy_tls_ctx != NULL) {
58 aws_tls_connection_options_init_from_ctx(tls_options, proxy_tls_ctx);
59 aws_tls_connection_options_set_server_name(tls_options, allocator, &options->host);
60 options->tls_options = tls_options;
61 }
62 }
63
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)64 void aws_http_proxy_options_jni_clean_up(
65 JNIEnv *env,
66 struct aws_http_proxy_options *options,
67 jbyteArray proxy_host,
68 jbyteArray proxy_authorization_username,
69 jbyteArray proxy_authorization_password) {
70
71 if (options->host.ptr != NULL) {
72 aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_host, options->host);
73 }
74
75 if (options->auth_username.ptr != NULL) {
76 aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_authorization_username, options->auth_username);
77 }
78
79 if (options->auth_password.ptr != NULL) {
80 aws_jni_byte_cursor_from_jbyteArray_release(env, proxy_authorization_password, options->auth_password);
81 }
82
83 if (options->tls_options != NULL) {
84 aws_tls_connection_options_clean_up((struct aws_tls_connection_options *)options->tls_options);
85 }
86 }
87
88 #if UINTPTR_MAX == 0xffffffff
89 # if defined(_MSC_VER)
90 # pragma warning(pop)
91 # else
92 # pragma GCC diagnostic pop
93 # endif
94 #endif
95