mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-01 00:39:24 +00:00
13f2ebfe12
Add config server client support for the C FFI and Android JNI bindings. Reuse the existing easytier::web_client::run_web_client path and NetworkInstanceManager; OHOS is unchanged. Report successful remote config apply/delete operations through a callback, with one JSON event per affected instance. Keep the config server client and FFI data plane mutually exclusive: once either side is in use, the other side returns an error instead of sharing lifecycle state.
24 lines
668 B
Rust
24 lines
668 B
Rust
use std::ffi::CString;
|
|
|
|
use jni::JNIEnv;
|
|
use jni::objects::JString;
|
|
|
|
pub(crate) fn jstring_to_cstring(env: &mut JNIEnv, jstr: &JString) -> Result<CString, String> {
|
|
let java_str = env
|
|
.get_string(jstr)
|
|
.map_err(|e| format!("Failed to get string: {:?}", e))?;
|
|
let rust_str = java_str.to_str().map_err(|_| "Invalid UTF-8".to_string())?;
|
|
CString::new(rust_str).map_err(|_| "String contains null byte".to_string())
|
|
}
|
|
|
|
pub(crate) fn optional_jstring_to_cstring(
|
|
env: &mut JNIEnv,
|
|
jstr: &JString,
|
|
) -> Result<Option<CString>, String> {
|
|
if jstr.is_null() {
|
|
return Ok(None);
|
|
}
|
|
|
|
jstring_to_cstring(env, jstr).map(Some)
|
|
}
|