Use option<&str> instead of owned option string

This commit is contained in:
Jackson Coxson
2025-08-08 10:18:31 -06:00
parent 21584f4190
commit d59f028251
10 changed files with 76 additions and 164 deletions

View File

@@ -3,7 +3,7 @@
use std::ptr::null_mut;
use idevice::{IdeviceError, IdeviceService, lockdown::LockdownClient, provider::IdeviceProvider};
use plist_ffi::{PlistWrapper, plist_t};
use plist_ffi::plist_t;
use crate::{
IdeviceFfiError, IdeviceHandle, IdevicePairingFile, RUNTIME, ffi_err,
@@ -183,18 +183,26 @@ pub unsafe extern "C" fn lockdownd_get_value(
return ffi_err!(IdeviceError::FfiInvalidArg);
}
let value = unsafe { std::ffi::CStr::from_ptr(key) }
.to_string_lossy()
.into_owned();
let value = if key.is_null() {
None
} else {
Some(match unsafe { std::ffi::CStr::from_ptr(key) }.to_str() {
Ok(v) => v,
Err(_) => {
return ffi_err!(IdeviceError::InvalidCString);
}
})
};
let domain = if domain.is_null() {
None
} else {
Some(
unsafe { std::ffi::CStr::from_ptr(domain) }
.to_string_lossy()
.into_owned(),
)
Some(match unsafe { std::ffi::CStr::from_ptr(domain) }.to_str() {
Ok(v) => v,
Err(_) => {
return ffi_err!(IdeviceError::InvalidCString);
}
})
};
let res: Result<plist::Value, IdeviceError> = RUNTIME.block_on(async move {
@@ -213,54 +221,6 @@ pub unsafe extern "C" fn lockdownd_get_value(
}
}
/// Gets all values from lockdownd
///
/// # Arguments
/// * `client` - A valid LockdowndClient handle
/// * `out_plist` - Pointer to store the returned plist dictionary
///
/// # Returns
/// An IdeviceFfiError on error, null on success
///
/// # Safety
/// `client` must be a valid pointer to a handle allocated by this library
/// `out_plist` must be a valid pointer to store the plist
#[unsafe(no_mangle)]
pub unsafe extern "C" fn lockdownd_get_all_values(
client: *mut LockdowndClientHandle,
domain: *const libc::c_char,
out_plist: *mut plist_t,
) -> *mut IdeviceFfiError {
if out_plist.is_null() {
return ffi_err!(IdeviceError::FfiInvalidArg);
}
let domain = if domain.is_null() {
None
} else {
Some(
unsafe { std::ffi::CStr::from_ptr(domain) }
.to_string_lossy()
.into_owned(),
)
};
let res: Result<plist::Dictionary, IdeviceError> = RUNTIME.block_on(async move {
let client_ref = unsafe { &mut (*client).0 };
client_ref.get_all_values(domain).await
});
match res {
Ok(dict) => {
unsafe {
*out_plist = PlistWrapper::new_node(plist::Value::Dictionary(dict)).into_ptr();
}
null_mut()
}
Err(e) => ffi_err!(e),
}
}
/// Frees a LockdowndClient handle
///
/// # Arguments