-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMACRequests.cpp
More file actions
106 lines (81 loc) · 3.28 KB
/
MACRequests.cpp
File metadata and controls
106 lines (81 loc) · 3.28 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
105
106
//
// Created by Christopher Miller on 1/16/17.
//
#include "MACRequests.h"
#include <cstring>
MACRequests::MACRequests() : Network() {}
/**
* Here you can construct the MACRequests object how ever you need to,
* as well as load signatures for the Java instance method calls.
*/
MACRequests::MACRequests(JNIEnv *env) : Network(env)
{
initialize(env);
thisObj = toJavaObject(env);
if (thisObj == NULL) {
JavaExceptionUtils::throwExceptionOfType(env, kTypeIllegalStateException,
"MACRequests's thisObj variable not intialized, methods of this class use the thisObj Java instance.");
}
}
void MACRequests::initialize(JNIEnv *env)
{
setClass(env);
cacheConstructor(env);
addNativeSignature("getInstance", (void*)&MACRequests::getInstance, "()Lus/the/mac/android/jni/helpers/MACRequests;");
addNativeSignature("getBytes", (void*)&MACRequests::getBytes, "()[B");
addNativeSignature("getHttpPost", (void*)&MACRequests::getHttpPost, "()Lorg/apache/http/client/methods/HttpPost;");
addNativeSignature("setRequestType", (void*)&MACRequests::setRequestType, "(I)V");
registerNativeMethods(env);
}
void MACRequests::mapFields()
{
// mapField("requestUrl", kTypeString, &requestUrl);
}
jobject MACRequests::getInstance(JNIEnv *env, jobject java_this)
{
MACRequests *network = new MACRequests(env);
return network->thisObj;
}
jbyteArray MACRequests::getBytes(JNIEnv *env, jobject java_this) {
MACRequests *object = gClasses.getNativeInstance<MACRequests>(env, java_this);
if (object != NULL) {
const char certificate[] = {
#include "httpbin_root_certificate" // THIS VALIDATES CONNECTION TO: https://httpbin.org/post
//FOUND W/: true | openssl s_client -connect httpbin.org:443 2>/dev/null | openssl x509 -in /dev/stdin
// #include "github_root_certificate" // TRY THIS INSTEAD FOR VALIDATION OF httpbin_root_certificate
//FOUND W/: true | openssl s_client -connect gist.githubusercontent.com:443 2>/dev/null | openssl x509 -in /dev/stdin
};
int size = std::strlen(certificate);
jbyte *data = (jbyte *) certificate;
jbyteArray array = env->NewByteArray(size);
env->SetByteArrayRegion(array, 0, size, data);
return array;
}
return NULL;
}
jobject MACRequests::getHttpPost(JNIEnv *env, jobject java_this) {
MACRequests *object = gClasses.getNativeInstance<MACRequests>(env, java_this);
if (object != NULL)
{
if (!object->requestSession.empty()) {
object->mappingObject["session"] = object->requestSession;
}
return Network::getHttpPost(env, java_this);
}
return NULL;
}
void MACRequests::setRequestType(JNIEnv *env, jobject java_this, jint requestType) {
MACRequests *object = gClasses.getNativeInstance<MACRequests>(env, java_this);
if (object != NULL) {
switch (requestType) {
case HTTP_BIN:
object->requestUrl = "https://httpbin.org/post";
object->requestSession = "SESSION-TOKEN-ONE";
break;
case JSON_TEST:
object->requestUrl = "http://ip.jsontest.com";
object->requestSession = "SESSION-TOKEN-TWO";
break;
}
}
}