diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2025-06-03 10:17:25 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2025-06-04 11:33:17 +0200 |
| commit | e3ccff9b8313e5a13ce526c5b9cb531bd82f623c (patch) | |
| tree | cc871d6c0e360d910ebda7c6f05b1d71ad5d1216 | |
| parent | e19578a7eaea23502ef01559ae0a74e21a27383a (diff) | |
| download | mullvadvpn-e3ccff9b8313e5a13ce526c5b9cb531bd82f623c.tar.xz mullvadvpn-e3ccff9b8313e5a13ce526c5b9cb531bd82f623c.zip | |
Remove unnecessary casts statements
| -rw-r--r-- | ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift | 12 | ||||
| -rw-r--r-- | ios/MullvadRustRuntime/include/mullvad_rust_runtime.h | 6 | ||||
| -rw-r--r-- | mullvad-ios/src/api_client/api.rs | 40 | ||||
| -rw-r--r-- | mullvad-ios/src/api_client/response.rs | 24 |
4 files changed, 39 insertions, 43 deletions
diff --git a/ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift b/ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift index c1577c3fae..943c0afc3d 100644 --- a/ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift +++ b/ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift @@ -257,7 +257,7 @@ extension REST { request: LegacyStorekitRequest, retryStrategy: REST.RetryStrategy, completionHandler: @escaping ProxyCompletionHandler<REST.CreateApplePaymentResponse> - ) -> any MullvadTypes.Cancellable { + ) -> any Cancellable { AnyCancellable() } @@ -266,25 +266,25 @@ extension REST { accountNumber: String, retryStrategy: REST.RetryStrategy, completionHandler: @escaping ProxyCompletionHandler<String> - ) -> any MullvadTypes.Cancellable { + ) -> any Cancellable { AnyCancellable() } /// Not implemented. Use `MullvadAPIProxy` instead. public func checkStorekitPayment( accountNumber: String, - transaction: MullvadTypes.StorekitTransaction, + transaction: StorekitTransaction, retryStrategy: REST.RetryStrategy, completionHandler: @escaping ProxyCompletionHandler<Void> - ) -> any MullvadTypes.Cancellable { + ) -> any Cancellable { AnyCancellable() } public func checkApiAvailability( retryStrategy: REST.RetryStrategy, - accessMethod: MullvadTypes.PersistentAccessMethod, + accessMethod: PersistentAccessMethod, completion: @escaping ProxyCompletionHandler<Bool> - ) -> any MullvadTypes.Cancellable { + ) -> any Cancellable { AnyCancellable() } } diff --git a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h index d0021443c3..d4c0bf334f 100644 --- a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h +++ b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h @@ -89,10 +89,10 @@ typedef struct LateStringDeallocator { typedef struct SwiftMullvadApiResponse { uint8_t *body; uintptr_t body_size; - uint8_t *etag; + char *etag; uint16_t status_code; - uint8_t *error_description; - uint8_t *server_response_code; + char *error_description; + char *server_response_code; bool success; } SwiftMullvadApiResponse; diff --git a/mullvad-ios/src/api_client/api.rs b/mullvad-ios/src/api_client/api.rs index be4e6dbc0c..14c36bc595 100644 --- a/mullvad-ios/src/api_client/api.rs +++ b/mullvad-ios/src/api_client/api.rs @@ -102,31 +102,27 @@ pub unsafe extern "C" fn mullvad_ios_api_addrs_available( .resolve(access_method_setting.clone()) .await { - Ok(maybe_resolved_connection_mode) => match maybe_resolved_connection_mode { - Some(resolved_connection_mode) => { - let oneshot_client = api_context.api_client.mullvad_rest_handle( - resolved_connection_mode.connection_mode.into_provider(), - ); + Ok(Some(resolved_connection_mode)) => { + let oneshot_client = api_context + .api_client + .mullvad_rest_handle(resolved_connection_mode.connection_mode.into_provider()); - match mullvad_ios_api_addrs_available_inner(oneshot_client, retry_strategy) - .await - { - Ok(_) => completion.finish(SwiftMullvadApiResponse::ok()), - Err(err) => { - log::error!("{err:?}"); - completion.finish(SwiftMullvadApiResponse::rest_error(err)); - } + match mullvad_ios_api_addrs_available_inner(oneshot_client, retry_strategy).await { + Ok(_) => completion.finish(SwiftMullvadApiResponse::ok()), + Err(err) => { + log::error!("{err:?}"); + completion.finish(SwiftMullvadApiResponse::rest_error(err)); } } - None => { - log::error!("Invalid access method configuration, {access_method_setting:?}"); - completion.finish(SwiftMullvadApiResponse::access_method_error( - mullvad_api::access_mode::Error::Resolve { - access_method: access_method_setting.access_method, - }, - )); - } - }, + } + Ok(None) => { + log::error!("Invalid access method configuration, {access_method_setting:?}"); + completion.finish(SwiftMullvadApiResponse::access_method_error( + mullvad_api::access_mode::Error::Resolve { + access_method: access_method_setting.access_method, + }, + )); + } Err(err) => { log::error!("{err:?}"); completion.finish(SwiftMullvadApiResponse::access_method_error(err)); diff --git a/mullvad-ios/src/api_client/response.rs b/mullvad-ios/src/api_client/response.rs index a238951297..4871a5d4bf 100644 --- a/mullvad-ios/src/api_client/response.rs +++ b/mullvad-ios/src/api_client/response.rs @@ -1,5 +1,5 @@ use std::{ - ffi::CString, + ffi::{c_char, CString}, ptr::{self, null_mut}, }; @@ -12,10 +12,10 @@ use mullvad_api::{ pub struct SwiftMullvadApiResponse { body: *mut u8, body_size: usize, - etag: *mut u8, + etag: *mut c_char, status_code: u16, - error_description: *mut u8, - server_response_code: *mut u8, + error_description: *mut c_char, + server_response_code: *mut c_char, success: bool, } @@ -33,7 +33,7 @@ impl SwiftMullvadApiResponse { Some(etag) => { let header_value = CString::new(etag).map_err(|_| rest::Error::InvalidHeaderError)?; - header_value.into_raw().cast() + header_value.into_raw() } None => ptr::null_mut(), }; @@ -64,7 +64,7 @@ impl SwiftMullvadApiResponse { pub fn access_method_error(err: mullvad_api::access_mode::Error) -> Self { let to_cstr_pointer = |str| { CString::new(str) - .map(|cstr| cstr.into_raw().cast()) + .map(|cstr| cstr.into_raw()) .unwrap_or(null_mut()) }; let error_description = to_cstr_pointer(err.to_string()); @@ -87,7 +87,7 @@ impl SwiftMullvadApiResponse { let to_cstr_pointer = |str| { CString::new(str) - .map(|cstr| cstr.into_raw().cast()) + .map(|cstr| cstr.into_raw()) .unwrap_or(null_mut()) }; @@ -113,7 +113,7 @@ impl SwiftMullvadApiResponse { pub fn cancelled() -> Self { Self { success: false, - error_description: c"Request was cancelled".to_owned().into_raw().cast(), + error_description: c"Request was cancelled".to_owned().into_raw(), body: null_mut(), body_size: 0, etag: null_mut(), @@ -125,7 +125,7 @@ impl SwiftMullvadApiResponse { pub fn no_tokio_runtime() -> Self { Self { success: false, - error_description: c"Failed to get Tokio runtime".to_owned().into_raw().cast(), + error_description: c"Failed to get Tokio runtime".to_owned().into_raw(), body: null_mut(), body_size: 0, etag: null_mut(), @@ -149,14 +149,14 @@ pub unsafe extern "C" fn mullvad_response_drop(response: SwiftMullvadApiResponse } if !response.etag.is_null() { - let _ = CString::from_raw(response.etag.cast()); + let _ = CString::from_raw(response.etag); } if !response.error_description.is_null() { - let _ = CString::from_raw(response.error_description.cast()); + let _ = CString::from_raw(response.error_description); } if !response.server_response_code.is_null() { - let _ = CString::from_raw(response.server_response_code.cast()); + let _ = CString::from_raw(response.server_response_code); } } |
