summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormojganii <mojgan.jelodar@codic.se>2025-04-15 12:50:54 +0200
committermojganii <mojgan.jelodar@codic.se>2025-04-15 15:38:45 +0200
commit14db956bcd66b841734ed86b647e95f69034bffe (patch)
treed0f5fa50299da5bfeb65ed591e6c16c70e5cc4dc
parent9eab3722f672e8073218c9ce81999945ef095794 (diff)
downloadmullvadvpn-14db956bcd66b841734ed86b647e95f69034bffe.tar.xz
mullvadvpn-14db956bcd66b841734ed86b647e95f69034bffe.zip
Fix namespace clashing in rust code
-rw-r--r--ios/MullvadREST/MullvadAPI/MullvadApiRequestFactory.swift12
-rw-r--r--ios/MullvadRustRuntime/include/mullvad_rust_runtime.h24
-rw-r--r--ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift6
-rw-r--r--mullvad-ios/src/api_client/account.rs18
-rw-r--r--mullvad-ios/src/api_client/api.rs12
-rw-r--r--mullvad-ios/src/api_client/problem_report.rs21
6 files changed, 42 insertions, 51 deletions
diff --git a/ios/MullvadREST/MullvadAPI/MullvadApiRequestFactory.swift b/ios/MullvadREST/MullvadAPI/MullvadApiRequestFactory.swift
index 647b1b71be..0b3271c80b 100644
--- a/ios/MullvadREST/MullvadAPI/MullvadApiRequestFactory.swift
+++ b/ios/MullvadREST/MullvadAPI/MullvadApiRequestFactory.swift
@@ -26,14 +26,14 @@ public struct MullvadApiRequestFactory: Sendable {
switch request {
case let .getAddressList(retryStrategy):
- return MullvadApiCancellable(handle: mullvad_api_get_addresses(
+ return MullvadApiCancellable(handle: mullvad_ios_get_addresses(
apiContext.context,
rawCompletionPointer,
retryStrategy.toRustStrategy()
))
case let .getRelayList(retryStrategy, etag: etag):
- return MullvadApiCancellable(handle: mullvad_api_get_relays(
+ return MullvadApiCancellable(handle: mullvad_ios_get_relays(
apiContext.context,
rawCompletionPointer,
retryStrategy.toRustStrategy(),
@@ -41,27 +41,27 @@ public struct MullvadApiRequestFactory: Sendable {
))
case let .sendProblemReport(retryStrategy, problemReportRequest):
let rustRequest = RustProblemReportRequest(from: problemReportRequest)
- return MullvadApiCancellable(handle: mullvad_api_send_problem_report(
+ return MullvadApiCancellable(handle: mullvad_ios_send_problem_report(
apiContext.context,
rawCompletionPointer,
retryStrategy.toRustStrategy(),
rustRequest.toRust()
))
case let .getAccount(retryStrategy, accountNumber: accountNumber):
- return MullvadApiCancellable(handle: mullvad_api_get_account(
+ return MullvadApiCancellable(handle: mullvad_ios_get_account(
apiContext.context,
rawCompletionPointer,
retryStrategy.toRustStrategy(),
accountNumber
))
case let .createAccount(retryStrategy):
- return MullvadApiCancellable(handle: mullvad_api_create_account(
+ return MullvadApiCancellable(handle: mullvad_ios_create_account(
apiContext.context,
rawCompletionPointer,
retryStrategy.toRustStrategy()
))
case let .deleteAccount(retryStrategy, accountNumber: accountNumber):
- return MullvadApiCancellable(handle: mullvad_api_delete_account(
+ return MullvadApiCancellable(handle: mullvad_ios_delete_account(
apiContext.context,
rawCompletionPointer,
retryStrategy.toRustStrategy(),
diff --git a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h
index bb87b1baa7..36774f2d4e 100644
--- a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h
+++ b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h
@@ -125,7 +125,7 @@ struct SwiftApiContext mullvad_api_init_new(const uint8_t *host,
*
* This function is not safe to call multiple times with the same `CompletionCookie`.
*/
-struct SwiftCancelHandle mullvad_api_get_account(struct SwiftApiContext api_context,
+struct SwiftCancelHandle mullvad_ios_get_account(struct SwiftApiContext api_context,
void *completion_cookie,
struct SwiftRetryStrategy retry_strategy,
const char *account_number);
@@ -142,7 +142,7 @@ struct SwiftCancelHandle mullvad_api_get_account(struct SwiftApiContext api_cont
*
* This function is not safe to call multiple times with the same `CompletionCookie`.
*/
-struct SwiftCancelHandle mullvad_api_create_account(struct SwiftApiContext api_context,
+struct SwiftCancelHandle mullvad_ios_create_account(struct SwiftApiContext api_context,
void *completion_cookie,
struct SwiftRetryStrategy retry_strategy);
@@ -160,7 +160,7 @@ struct SwiftCancelHandle mullvad_api_create_account(struct SwiftApiContext api_c
*
* This function is not safe to call multiple times with the same `CompletionCookie`.
*/
-struct SwiftCancelHandle mullvad_api_delete_account(struct SwiftApiContext api_context,
+struct SwiftCancelHandle mullvad_ios_delete_account(struct SwiftApiContext api_context,
void *completion_cookie,
struct SwiftRetryStrategy retry_strategy,
const char *account_number);
@@ -177,7 +177,7 @@ struct SwiftCancelHandle mullvad_api_delete_account(struct SwiftApiContext api_c
*
* This function is not safe to call multiple times with the same `CompletionCookie`.
*/
-struct SwiftCancelHandle mullvad_api_get_addresses(struct SwiftApiContext api_context,
+struct SwiftCancelHandle mullvad_ios_get_addresses(struct SwiftApiContext api_context,
void *completion_cookie,
struct SwiftRetryStrategy retry_strategy);
@@ -195,7 +195,7 @@ struct SwiftCancelHandle mullvad_api_get_addresses(struct SwiftApiContext api_co
*
* This function is not safe to call multiple times with the same `CompletionCookie`.
*/
-struct SwiftCancelHandle mullvad_api_get_relays(struct SwiftApiContext api_context,
+struct SwiftCancelHandle mullvad_ios_get_relays(struct SwiftApiContext api_context,
void *completion_cookie,
struct SwiftRetryStrategy retry_strategy,
const char *etag);
@@ -245,19 +245,15 @@ extern void mullvad_api_completion_finish(struct SwiftMullvadApiResponse respons
* `api_context` must be pointing to a valid instance of `SwiftApiContext`. A `SwiftApiContext` is created
* by calling `mullvad_api_init_new`.
*
- * `completion_cookie` must be pointing to a valid instance of `CompletionCookie`. `CompletionCookie` is
- * safe because the pointer in `MullvadApiCompletion` is valid for the lifetime of the process where this
- * type is intended to be used.
+ * This function takes ownership of `completion_cookie`, which must be pointing to a valid instance of Swift
+ * object `MullvadApiCompletion`. The pointer will be freed by calling `mullvad_api_completion_finish`
+ * when completion finishes (in completion.finish).
*
* the string properties of `SwiftProblemReportRequest` must be pointers to a null terminated strings.
*
* This function is not safe to call multiple times with the same `CompletionCookie`.
- *
- * Ownership of the `CompletionCookie` is transferred to the Rust side upon calling this function.
- * After this call, the pointer must be considered invalid and must not be reused or accessed in any way.
- * Calling this function again with the same cookie, either sequentially or concurrently, results in undefined behavior.
*/
-struct SwiftCancelHandle mullvad_api_send_problem_report(struct SwiftApiContext api_context,
+struct SwiftCancelHandle mullvad_ios_send_problem_report(struct SwiftApiContext api_context,
void *completion_cookie,
struct SwiftRetryStrategy retry_strategy,
struct SwiftProblemReportRequest request);
@@ -269,7 +265,7 @@ struct ProblemReportMetadata swift_problem_report_metadata_new(void);
*
* # Safety
*
- * `self` must be a valid, exclusive pointer to `ProblemReportMetadata`, initialized
+ * `map.inner` must be non-null and point to a valid
* - `key` must be a null-terminated UTF-8 string, containing LF-separated machines.
* - `value` must be a valid pointer to some valid and aligned pointer-sized memory.
*/
diff --git a/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift b/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift
index b4058fba85..aefcfea931 100644
--- a/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift
+++ b/ios/MullvadVPNTests/MullvadREST/MullvadApi/RustProblemReportRequestTests.swift
@@ -31,7 +31,7 @@ struct RustProblemReportRequestTests {
)
let rustRequest = RustProblemReportRequest(from: request)
let rustStruct = rustRequest.toRust()
- #expect(rustStruct.meta_data != nil, "Metadata should not be for \(metadata)")
+ #expect(rustStruct.metadata != nil, "Metadata should not be for \(metadata)")
}
@Test("Test invalid metadata insertion for SendProblemReport")
@@ -41,7 +41,7 @@ struct RustProblemReportRequestTests {
[0x7E]: [0x80], // Valid key , but invalid start byte in UTF-8
[0xE0, 0x80]: [0xC2, 0x80], // Malformed UTF-8 multibyte sequence for key and valid value
]
- let metadata = swift_problem_report_meta_data_new()
+ let metadata = swift_problem_report_metadata_new()
for (keyBytes, valueBytes) in invalidMetadata {
keyBytes.withUnsafeBytes { (keyPtr: UnsafeRawBufferPointer) in
valueBytes.withUnsafeBytes { (valuePtr: UnsafeRawBufferPointer) in
@@ -50,7 +50,7 @@ struct RustProblemReportRequestTests {
return
}
- let result = swift_problem_report_meta_data_add(
+ let result = swift_problem_report_metadata_add(
metadata,
keyBaseAddress,
valueBaseAddress
diff --git a/mullvad-ios/src/api_client/account.rs b/mullvad-ios/src/api_client/account.rs
index ff3b0294cf..768832fcb7 100644
--- a/mullvad-ios/src/api_client/account.rs
+++ b/mullvad-ios/src/api_client/account.rs
@@ -28,7 +28,7 @@ use super::{
///
/// This function is not safe to call multiple times with the same `CompletionCookie`.
#[no_mangle]
-pub unsafe extern "C" fn mullvad_api_get_account(
+pub unsafe extern "C" fn mullvad_ios_get_account(
api_context: SwiftApiContext,
completion_cookie: *mut libc::c_void,
retry_strategy: SwiftRetryStrategy,
@@ -51,7 +51,7 @@ pub unsafe extern "C" fn mullvad_api_get_account(
let completion = completion_handler.clone();
let task = tokio_handle.clone().spawn(async move {
- match mullvad_api_get_account_inner(
+ match mullvad_ios_get_account_inner(
api_context.rest_handle(),
retry_strategy,
account_number,
@@ -80,7 +80,7 @@ pub unsafe extern "C" fn mullvad_api_get_account(
///
/// This function is not safe to call multiple times with the same `CompletionCookie`.
#[no_mangle]
-pub unsafe extern "C" fn mullvad_api_create_account(
+pub unsafe extern "C" fn mullvad_ios_create_account(
api_context: SwiftApiContext,
completion_cookie: *mut libc::c_void,
retry_strategy: SwiftRetryStrategy,
@@ -97,7 +97,7 @@ pub unsafe extern "C" fn mullvad_api_create_account(
let completion = completion_handler.clone();
let task = tokio_handle.clone().spawn(async move {
- match mullvad_api_create_account_inner(api_context.rest_handle(), retry_strategy).await {
+ match mullvad_ios_create_account_inner(api_context.rest_handle(), retry_strategy).await {
Ok(response) => completion.finish(response),
Err(err) => {
log::error!("{err:?}");
@@ -122,7 +122,7 @@ pub unsafe extern "C" fn mullvad_api_create_account(
///
/// This function is not safe to call multiple times with the same `CompletionCookie`.
#[no_mangle]
-pub unsafe extern "C" fn mullvad_api_delete_account(
+pub unsafe extern "C" fn mullvad_ios_delete_account(
api_context: SwiftApiContext,
completion_cookie: *mut libc::c_void,
retry_strategy: SwiftRetryStrategy,
@@ -145,7 +145,7 @@ pub unsafe extern "C" fn mullvad_api_delete_account(
let completion = completion_handler.clone();
let task = tokio_handle.clone().spawn(async move {
- match mullvad_api_delete_account_inner(
+ match mullvad_ios_delete_account_inner(
api_context.rest_handle(),
retry_strategy,
account_number,
@@ -163,7 +163,7 @@ pub unsafe extern "C" fn mullvad_api_delete_account(
RequestCancelHandle::new(task, completion_handler.clone()).into_swift()
}
-async fn mullvad_api_get_account_inner(
+async fn mullvad_ios_get_account_inner(
rest_client: MullvadRestHandle,
retry_strategy: RetryStrategy,
account_number: String,
@@ -174,7 +174,7 @@ async fn mullvad_api_get_account_inner(
do_request(retry_strategy, future_factory).await
}
-async fn mullvad_api_create_account_inner(
+async fn mullvad_ios_create_account_inner(
rest_client: MullvadRestHandle,
retry_strategy: RetryStrategy,
) -> Result<SwiftMullvadApiResponse, rest::Error> {
@@ -184,7 +184,7 @@ async fn mullvad_api_create_account_inner(
do_request(retry_strategy, future_factory).await
}
-async fn mullvad_api_delete_account_inner(
+async fn mullvad_ios_delete_account_inner(
rest_client: MullvadRestHandle,
retry_strategy: RetryStrategy,
account_number: String,
diff --git a/mullvad-ios/src/api_client/api.rs b/mullvad-ios/src/api_client/api.rs
index c6c14bb14c..62060dfacb 100644
--- a/mullvad-ios/src/api_client/api.rs
+++ b/mullvad-ios/src/api_client/api.rs
@@ -26,7 +26,7 @@ use super::{
///
/// This function is not safe to call multiple times with the same `CompletionCookie`.
#[no_mangle]
-pub unsafe extern "C" fn mullvad_api_get_addresses(
+pub unsafe extern "C" fn mullvad_ios_get_addresses(
api_context: SwiftApiContext,
completion_cookie: *mut libc::c_void,
retry_strategy: SwiftRetryStrategy,
@@ -43,7 +43,7 @@ pub unsafe extern "C" fn mullvad_api_get_addresses(
let completion = completion_handler.clone();
let task = tokio_handle.clone().spawn(async move {
- match mullvad_api_get_addresses_inner(api_context.rest_handle(), retry_strategy).await {
+ match mullvad_ios_get_addresses_inner(api_context.rest_handle(), retry_strategy).await {
Ok(response) => completion.finish(response),
Err(err) => {
log::error!("{err:?}");
@@ -68,7 +68,7 @@ pub unsafe extern "C" fn mullvad_api_get_addresses(
///
/// This function is not safe to call multiple times with the same `CompletionCookie`.
#[no_mangle]
-pub unsafe extern "C" fn mullvad_api_get_relays(
+pub unsafe extern "C" fn mullvad_ios_get_relays(
api_context: SwiftApiContext,
completion_cookie: *mut libc::c_void,
retry_strategy: SwiftRetryStrategy,
@@ -93,7 +93,7 @@ pub unsafe extern "C" fn mullvad_api_get_relays(
let completion = completion_handler.clone();
let task = tokio_handle.clone().spawn(async move {
- match mullvad_api_get_relays_inner(api_context.rest_handle(), retry_strategy, maybe_etag)
+ match mullvad_ios_get_relays_inner(api_context.rest_handle(), retry_strategy, maybe_etag)
.await
{
Ok(response) => completion.finish(response),
@@ -107,7 +107,7 @@ pub unsafe extern "C" fn mullvad_api_get_relays(
RequestCancelHandle::new(task, completion_handler.clone()).into_swift()
}
-async fn mullvad_api_get_addresses_inner(
+async fn mullvad_ios_get_addresses_inner(
rest_client: MullvadRestHandle,
retry_strategy: RetryStrategy,
) -> Result<SwiftMullvadApiResponse, rest::Error> {
@@ -118,7 +118,7 @@ async fn mullvad_api_get_addresses_inner(
do_request(retry_strategy, future_factory).await
}
-async fn mullvad_api_get_relays_inner(
+async fn mullvad_ios_get_relays_inner(
rest_client: MullvadRestHandle,
retry_strategy: RetryStrategy,
etag: Option<String>,
diff --git a/mullvad-ios/src/api_client/problem_report.rs b/mullvad-ios/src/api_client/problem_report.rs
index ed416f824c..a12238c789 100644
--- a/mullvad-ios/src/api_client/problem_report.rs
+++ b/mullvad-ios/src/api_client/problem_report.rs
@@ -25,19 +25,15 @@ use tokio::task::JoinHandle;
/// `api_context` must be pointing to a valid instance of `SwiftApiContext`. A `SwiftApiContext` is created
/// by calling `mullvad_api_init_new`.
///
-/// `completion_cookie` must be pointing to a valid instance of `CompletionCookie`. `CompletionCookie` is
-/// safe because the pointer in `MullvadApiCompletion` is valid for the lifetime of the process where this
-/// type is intended to be used.
+/// This function takes ownership of `completion_cookie`, which must be pointing to a valid instance of Swift
+/// object `MullvadApiCompletion`. The pointer will be freed by calling `mullvad_api_completion_finish`
+/// when completion finishes (in completion.finish).
///
/// the string properties of `SwiftProblemReportRequest` must be pointers to a null terminated strings.
///
/// This function is not safe to call multiple times with the same `CompletionCookie`.
-///
-/// Ownership of the `CompletionCookie` is transferred to the Rust side upon calling this function.
-/// After this call, the pointer must be considered invalid and must not be reused or accessed in any way.
-/// Calling this function again with the same cookie, either sequentially or concurrently, results in undefined behavior.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn mullvad_api_send_problem_report(
+pub unsafe extern "C" fn mullvad_ios_send_problem_report(
api_context: SwiftApiContext,
completion_cookie: *mut libc::c_void,
retry_strategy: SwiftRetryStrategy,
@@ -66,7 +62,7 @@ pub unsafe extern "C" fn mullvad_api_send_problem_report(
};
let task: JoinHandle<()> = tokio_handle.spawn(async move {
- match mullvad_api_send_problem_report_inner(
+ match mullvad_ios_send_problem_report_inner(
api_context.rest_handle(),
retry_strategy,
problem_report_request,
@@ -84,7 +80,7 @@ pub unsafe extern "C" fn mullvad_api_send_problem_report(
RequestCancelHandle::new(task, completion_handler.clone()).into_swift()
}
-async fn mullvad_api_send_problem_report_inner(
+async fn mullvad_ios_send_problem_report_inner(
rest_client: MullvadRestHandle,
retry_strategy: RetryStrategy,
problem_report_request: ProblemReportRequest,
@@ -175,7 +171,6 @@ impl Map {
///
/// # Safety
///
- /// `self` must be a valid, exclusive pointer to `Map`, initialized
/// - `key` must be a null-terminated UTF-8 string, containing LF-separated machines.
/// - `value` must be a valid pointer to some valid and aligned pointer-sized memory.
unsafe fn add(&mut self, key: *const c_char, value: *const c_char) -> bool {
@@ -222,7 +217,7 @@ pub extern "C" fn swift_problem_report_metadata_new() -> ProblemReportMetadata {
///
/// # Safety
///
-/// `self` must be a valid, exclusive pointer to `ProblemReportMetadata`, initialized
+/// `map.inner` must be non-null and point to a valid
/// - `key` must be a null-terminated UTF-8 string, containing LF-separated machines.
/// - `value` must be a valid pointer to some valid and aligned pointer-sized memory.
#[unsafe(no_mangle)]
@@ -242,7 +237,7 @@ pub unsafe extern "C" fn swift_problem_report_metadata_add(
}
#[no_mangle]
-pub extern "C" fn swift_problem_report_metadata_free(mut map: ProblemReportMetadata) {
+pub extern "C" fn swift_problem_report_metadata_free(map: ProblemReportMetadata) {
if !map.inner.is_null() {
// SAFETY: `map.inner` must be properly aligned and non-null
// The caller must guarantee that `map.inner` is not null and has not been freed