ZaStoGram/TMessagesProj/jni/zsg_naive/WebProxyJni.cpp
loop-uh 15792a0f67
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
WARP entry hop (opt-in): native WireGuard+lwIP engine from naive-core (848f94c), loopback forward ports for tgnet/WSS/Naive/pool first hops, settings row, account registration
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-27 15:02:26 -05:00

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