Some checks failed
Build three ZaStoGram APKs / build (arm64-v8a, ZaStoGram-standalone-arm64-v8a, Arm64, arm64) (push) Failing after 41s
Build three ZaStoGram APKs / build (armeabi-v7a, ZaStoGram-standalone-armeabi-v7a, Armv7, armv7) (push) Failing after 41s
ZaStoGram source guards / guards (push) Failing after 16s
Build three ZaStoGram APKs / build (x86, ZaStoGram-standalone-x86, X86, x86) (push) Failing after 36s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
#include "WebProxyJni.h"
|
|
|
|
#include <string>
|
|
|
|
#include "WarpEntry.h"
|
|
#include "WebProxy.h"
|
|
|
|
namespace tgnet {
|
|
namespace naive {
|
|
|
|
namespace {
|
|
|
|
std::string ToString(JNIEnv *env, jstring s) {
|
|
if (s == nullptr) {
|
|
return std::string();
|
|
}
|
|
const char *chars = env->GetStringUTFChars(s, nullptr);
|
|
std::string result(chars != nullptr ? chars : "");
|
|
if (chars != nullptr) {
|
|
env->ReleaseStringUTFChars(s, chars);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
jint nativeStart(JNIEnv *env, jclass, jstring host, jint port, jstring user, jstring password) {
|
|
WebProxyConfig config;
|
|
config.proxyHost = ToString(env, host);
|
|
config.proxyPort = static_cast<uint16_t>(port > 0 && port < 65536 ? port : 443);
|
|
config.user = ToString(env, user);
|
|
config.password = ToString(env, password);
|
|
if (config.proxyHost.empty()) {
|
|
return 0;
|
|
}
|
|
return StartWebProxy(config);
|
|
}
|
|
|
|
void nativeStop(JNIEnv *, jclass) { StopWebProxy(); }
|
|
|
|
const JNINativeMethod kMethods[] = {
|
|
{"native_start", "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I", reinterpret_cast<void *>(nativeStart)},
|
|
{"native_stop", "()V", reinterpret_cast<void *>(nativeStop)},
|
|
};
|
|
|
|
} // namespace
|
|
|
|
bool RegisterWebProxyJni(JNIEnv *env) {
|
|
jclass clazz = env->FindClass("org/telegram/zastogram/naive/NaiveWebProxy");
|
|
if (clazz == nullptr) {
|
|
return false;
|
|
}
|
|
if (env->RegisterNatives(clazz, kMethods, sizeof(kMethods) / sizeof(kMethods[0])) < 0) {
|
|
return false;
|
|
}
|
|
return RegisterWarpJni(env);
|
|
}
|
|
|
|
} // namespace naive
|
|
} // namespace tgnet
|