mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Use option<&str> instead of owned option string
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user