Remove unnecessary casts statements
This commit is contained in:
parent
e19578a7ea
commit
e3ccff9b83
@ -257,7 +257,7 @@ extension REST {
|
|||||||
request: LegacyStorekitRequest,
|
request: LegacyStorekitRequest,
|
||||||
retryStrategy: REST.RetryStrategy,
|
retryStrategy: REST.RetryStrategy,
|
||||||
completionHandler: @escaping ProxyCompletionHandler<REST.CreateApplePaymentResponse>
|
completionHandler: @escaping ProxyCompletionHandler<REST.CreateApplePaymentResponse>
|
||||||
) -> any MullvadTypes.Cancellable {
|
) -> any Cancellable {
|
||||||
AnyCancellable()
|
AnyCancellable()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,25 +266,25 @@ extension REST {
|
|||||||
accountNumber: String,
|
accountNumber: String,
|
||||||
retryStrategy: REST.RetryStrategy,
|
retryStrategy: REST.RetryStrategy,
|
||||||
completionHandler: @escaping ProxyCompletionHandler<String>
|
completionHandler: @escaping ProxyCompletionHandler<String>
|
||||||
) -> any MullvadTypes.Cancellable {
|
) -> any Cancellable {
|
||||||
AnyCancellable()
|
AnyCancellable()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Not implemented. Use `MullvadAPIProxy` instead.
|
/// Not implemented. Use `MullvadAPIProxy` instead.
|
||||||
public func checkStorekitPayment(
|
public func checkStorekitPayment(
|
||||||
accountNumber: String,
|
accountNumber: String,
|
||||||
transaction: MullvadTypes.StorekitTransaction,
|
transaction: StorekitTransaction,
|
||||||
retryStrategy: REST.RetryStrategy,
|
retryStrategy: REST.RetryStrategy,
|
||||||
completionHandler: @escaping ProxyCompletionHandler<Void>
|
completionHandler: @escaping ProxyCompletionHandler<Void>
|
||||||
) -> any MullvadTypes.Cancellable {
|
) -> any Cancellable {
|
||||||
AnyCancellable()
|
AnyCancellable()
|
||||||
}
|
}
|
||||||
|
|
||||||
public func checkApiAvailability(
|
public func checkApiAvailability(
|
||||||
retryStrategy: REST.RetryStrategy,
|
retryStrategy: REST.RetryStrategy,
|
||||||
accessMethod: MullvadTypes.PersistentAccessMethod,
|
accessMethod: PersistentAccessMethod,
|
||||||
completion: @escaping ProxyCompletionHandler<Bool>
|
completion: @escaping ProxyCompletionHandler<Bool>
|
||||||
) -> any MullvadTypes.Cancellable {
|
) -> any Cancellable {
|
||||||
AnyCancellable()
|
AnyCancellable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,10 +89,10 @@ typedef struct LateStringDeallocator {
|
|||||||
typedef struct SwiftMullvadApiResponse {
|
typedef struct SwiftMullvadApiResponse {
|
||||||
uint8_t *body;
|
uint8_t *body;
|
||||||
uintptr_t body_size;
|
uintptr_t body_size;
|
||||||
uint8_t *etag;
|
char *etag;
|
||||||
uint16_t status_code;
|
uint16_t status_code;
|
||||||
uint8_t *error_description;
|
char *error_description;
|
||||||
uint8_t *server_response_code;
|
char *server_response_code;
|
||||||
bool success;
|
bool success;
|
||||||
} SwiftMullvadApiResponse;
|
} SwiftMullvadApiResponse;
|
||||||
|
|
||||||
|
@ -102,31 +102,27 @@ pub unsafe extern "C" fn mullvad_ios_api_addrs_available(
|
|||||||
.resolve(access_method_setting.clone())
|
.resolve(access_method_setting.clone())
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(maybe_resolved_connection_mode) => match maybe_resolved_connection_mode {
|
Ok(Some(resolved_connection_mode)) => {
|
||||||
Some(resolved_connection_mode) => {
|
let oneshot_client = api_context
|
||||||
let oneshot_client = api_context.api_client.mullvad_rest_handle(
|
.api_client
|
||||||
resolved_connection_mode.connection_mode.into_provider(),
|
.mullvad_rest_handle(resolved_connection_mode.connection_mode.into_provider());
|
||||||
);
|
|
||||||
|
|
||||||
match mullvad_ios_api_addrs_available_inner(oneshot_client, retry_strategy)
|
match mullvad_ios_api_addrs_available_inner(oneshot_client, retry_strategy).await {
|
||||||
.await
|
Ok(_) => completion.finish(SwiftMullvadApiResponse::ok()),
|
||||||
{
|
Err(err) => {
|
||||||
Ok(_) => completion.finish(SwiftMullvadApiResponse::ok()),
|
log::error!("{err:?}");
|
||||||
Err(err) => {
|
completion.finish(SwiftMullvadApiResponse::rest_error(err));
|
||||||
log::error!("{err:?}");
|
|
||||||
completion.finish(SwiftMullvadApiResponse::rest_error(err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
}
|
||||||
log::error!("Invalid access method configuration, {access_method_setting:?}");
|
Ok(None) => {
|
||||||
completion.finish(SwiftMullvadApiResponse::access_method_error(
|
log::error!("Invalid access method configuration, {access_method_setting:?}");
|
||||||
mullvad_api::access_mode::Error::Resolve {
|
completion.finish(SwiftMullvadApiResponse::access_method_error(
|
||||||
access_method: access_method_setting.access_method,
|
mullvad_api::access_mode::Error::Resolve {
|
||||||
},
|
access_method: access_method_setting.access_method,
|
||||||
));
|
},
|
||||||
}
|
));
|
||||||
},
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("{err:?}");
|
log::error!("{err:?}");
|
||||||
completion.finish(SwiftMullvadApiResponse::access_method_error(err));
|
completion.finish(SwiftMullvadApiResponse::access_method_error(err));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
ffi::CString,
|
ffi::{c_char, CString},
|
||||||
ptr::{self, null_mut},
|
ptr::{self, null_mut},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12,10 +12,10 @@ use mullvad_api::{
|
|||||||
pub struct SwiftMullvadApiResponse {
|
pub struct SwiftMullvadApiResponse {
|
||||||
body: *mut u8,
|
body: *mut u8,
|
||||||
body_size: usize,
|
body_size: usize,
|
||||||
etag: *mut u8,
|
etag: *mut c_char,
|
||||||
status_code: u16,
|
status_code: u16,
|
||||||
error_description: *mut u8,
|
error_description: *mut c_char,
|
||||||
server_response_code: *mut u8,
|
server_response_code: *mut c_char,
|
||||||
success: bool,
|
success: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ impl SwiftMullvadApiResponse {
|
|||||||
Some(etag) => {
|
Some(etag) => {
|
||||||
let header_value =
|
let header_value =
|
||||||
CString::new(etag).map_err(|_| rest::Error::InvalidHeaderError)?;
|
CString::new(etag).map_err(|_| rest::Error::InvalidHeaderError)?;
|
||||||
header_value.into_raw().cast()
|
header_value.into_raw()
|
||||||
}
|
}
|
||||||
None => ptr::null_mut(),
|
None => ptr::null_mut(),
|
||||||
};
|
};
|
||||||
@ -64,7 +64,7 @@ impl SwiftMullvadApiResponse {
|
|||||||
pub fn access_method_error(err: mullvad_api::access_mode::Error) -> Self {
|
pub fn access_method_error(err: mullvad_api::access_mode::Error) -> Self {
|
||||||
let to_cstr_pointer = |str| {
|
let to_cstr_pointer = |str| {
|
||||||
CString::new(str)
|
CString::new(str)
|
||||||
.map(|cstr| cstr.into_raw().cast())
|
.map(|cstr| cstr.into_raw())
|
||||||
.unwrap_or(null_mut())
|
.unwrap_or(null_mut())
|
||||||
};
|
};
|
||||||
let error_description = to_cstr_pointer(err.to_string());
|
let error_description = to_cstr_pointer(err.to_string());
|
||||||
@ -87,7 +87,7 @@ impl SwiftMullvadApiResponse {
|
|||||||
|
|
||||||
let to_cstr_pointer = |str| {
|
let to_cstr_pointer = |str| {
|
||||||
CString::new(str)
|
CString::new(str)
|
||||||
.map(|cstr| cstr.into_raw().cast())
|
.map(|cstr| cstr.into_raw())
|
||||||
.unwrap_or(null_mut())
|
.unwrap_or(null_mut())
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ impl SwiftMullvadApiResponse {
|
|||||||
pub fn cancelled() -> Self {
|
pub fn cancelled() -> Self {
|
||||||
Self {
|
Self {
|
||||||
success: false,
|
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: null_mut(),
|
||||||
body_size: 0,
|
body_size: 0,
|
||||||
etag: null_mut(),
|
etag: null_mut(),
|
||||||
@ -125,7 +125,7 @@ impl SwiftMullvadApiResponse {
|
|||||||
pub fn no_tokio_runtime() -> Self {
|
pub fn no_tokio_runtime() -> Self {
|
||||||
Self {
|
Self {
|
||||||
success: false,
|
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: null_mut(),
|
||||||
body_size: 0,
|
body_size: 0,
|
||||||
etag: null_mut(),
|
etag: null_mut(),
|
||||||
@ -149,14 +149,14 @@ pub unsafe extern "C" fn mullvad_response_drop(response: SwiftMullvadApiResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !response.etag.is_null() {
|
if !response.etag.is_null() {
|
||||||
let _ = CString::from_raw(response.etag.cast());
|
let _ = CString::from_raw(response.etag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !response.error_description.is_null() {
|
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() {
|
if !response.server_response_code.is_null() {
|
||||||
let _ = CString::from_raw(response.server_response_code.cast());
|
let _ = CString::from_raw(response.server_response_code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user