OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 *arrayList)); | 70 *arrayList)); |
71 | 71 |
72 if (!env->ExceptionCheck()) | 72 if (!env->ExceptionCheck()) |
73 { | 73 { |
74 sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), | 74 sResponse.status = JniGetLongField(*env, serverResponseClass->Get(), |
75 *response, "status"); | 75 *response, "status"); |
76 sResponse.responseStatus = JniGetIntField(*env, | 76 sResponse.responseStatus = JniGetIntField(*env, |
77 serverResponseClass->Get(), *response, "responseStatus"); | 77 serverResponseClass->Get(), *response, "responseStatus"); |
78 sResponse.responseText = JniGetStringField(*env, | 78 sResponse.responseText = JniGetStringField(*env, |
79 serverResponseClass->Get(), *response, "response"); | 79 serverResponseClass->Get(), *response, "response"); |
80 // TODO: transform Headers | 80 |
| 81 // map headers |
| 82 jobjectArray responseHeadersArray = JniGetStringArrayField(*env, |
| 83 serverResponseClass->Get(), *response, "headers"); |
| 84 |
| 85 if (responseHeadersArray) { |
| 86 int itemsCount = env->GetArrayLength(responseHeadersArray) / 2; |
| 87 for (int i=0; i<itemsCount; i++) { |
| 88 // key |
| 89 jstring jKey = (jstring)env->GetObjectArrayElement(responseHeadersArra
y, i * 2); |
| 90 const char *cKey = env->GetStringUTFChars(jKey, 0); |
| 91 std::string stdCKey(cKey); |
| 92 env->ReleaseStringUTFChars(jKey, cKey); |
| 93 |
| 94 // value |
| 95 jstring jValue = (jstring)env->GetObjectArrayElement(responseHeadersAr
ray, i * 2 + 1); |
| 96 const char *cValue = env->GetStringUTFChars(jValue, 0); |
| 97 std::string stdCValue(cValue); |
| 98 env->ReleaseStringUTFChars(jValue, cValue); |
| 99 |
| 100 std::pair<std::string,std::string> keyValue(stdCKey, stdCValue); |
| 101 sResponse.responseHeaders.push_back(keyValue); |
| 102 } |
| 103 } |
81 } | 104 } |
82 } | 105 } |
83 | 106 |
84 CheckAndLogJavaException(*env); | 107 CheckAndLogJavaException(*env); |
85 | 108 |
86 return sResponse; | 109 return sResponse; |
87 } | 110 } |
88 | 111 |
89 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, | 112 jobject JniWebRequest::NewTuple(JNIEnv* env, const std::string& a, |
90 const std::string& b) const | 113 const std::string& b) const |
(...skipping 10 matching lines...) Expand all Loading... |
101 static JNINativeMethod methods[] = | 124 static JNINativeMethod methods[] = |
102 { | 125 { |
103 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, | 126 { (char*)"ctor", (char*)"(Ljava/lang/Object;)J", (void*)JniCtor }, |
104 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } | 127 { (char*)"dtor", (char*)"(J)V", (void*)JniDtor } |
105 }; | 128 }; |
106 | 129 |
107 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest
_registerNatives(JNIEnv *env, jclass clazz) | 130 extern "C" JNIEXPORT void JNICALL Java_org_adblockplus_libadblockplus_WebRequest
_registerNatives(JNIEnv *env, jclass clazz) |
108 { | 131 { |
109 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); | 132 env->RegisterNatives(clazz, methods, sizeof(methods) / sizeof(methods[0])); |
110 } | 133 } |
OLD | NEW |