summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2023-02-27 09:37:17 +0100
committerDavid Lönnhager <david.l@mullvad.net>2023-03-01 15:25:57 +0100
commit135848f6304561438cb3aa04e35ab1fbd329cde1 (patch)
tree4fb9f6cdd69d224699bdcb60f23bc66cddc2fce2
parent2bd5e536d34bb60ba4a77fb6d37f2c5eff23463c (diff)
downloadmullvadvpn-135848f6304561438cb3aa04e35ab1fbd329cde1.tar.xz
mullvadvpn-135848f6304561438cb3aa04e35ab1fbd329cde1.zip
If set, override the API hostname from the InetSocketAddress
-rw-r--r--mullvad-jni/src/lib.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/mullvad-jni/src/lib.rs b/mullvad-jni/src/lib.rs
index b7e0815bfa..370959c4e5 100644
--- a/mullvad-jni/src/lib.rs
+++ b/mullvad-jni/src/lib.rs
@@ -257,6 +257,9 @@ fn api_endpoint_from_java(env: &JnixEnv<'_>, object: JObject<'_>) -> mullvad_api
endpoint.addr =
try_socketaddr_from_java(env, address).expect("received unresolved InetSocketAddress");
+ if let Some(host) = try_hostname_from_java(env, address) {
+ endpoint.host = host;
+ }
endpoint.disable_address_cache = env
.call_method(object, "component2", "()Z", &[])
.expect("missing ApiEndpoint.disableAddressCache")
@@ -314,6 +317,30 @@ fn try_socketaddr_from_java(env: &JnixEnv<'_>, address: JObject<'_>) -> Option<S
))
}
+/// Returns the hostname for an InetSocketAddress. This may be an IP address converted to
+/// a string.
+#[cfg(feature = "api-override")]
+fn try_hostname_from_java(env: &JnixEnv<'_>, address: JObject<'_>) -> Option<String> {
+ let class = env.get_class("java/net/InetSocketAddress");
+
+ let method_id = env
+ .get_method_id(&class, "getHostString", "()Ljava/lang/String;")
+ .expect("Failed to get method ID for InetSocketAddress.getHostString()");
+ let return_type = JavaType::Object("java/lang/String".to_owned());
+
+ let hostname = env
+ .call_method_unchecked(address, method_id, return_type, &[])
+ .expect("Failed to call InetSocketAddress.getHostString()")
+ .l()
+ .expect("Call to InetSocketAddress.getHostString() did not return an object");
+
+ if hostname.is_null() {
+ return None;
+ }
+
+ Some(String::from_java(env, hostname))
+}
+
fn start_logging(log_dir: &Path) -> Result<(), String> {
unsafe {
LOG_START.call_once(|| LOG_INIT_RESULT = Some(initialize_logging(log_dir)));