mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Use option<&str> instead of owned option string
This commit is contained in:
@@ -109,11 +109,14 @@ pub unsafe extern "C" fn installation_proxy_get_apps(
|
||||
let app_type = if application_type.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe {
|
||||
std::ffi::CStr::from_ptr(application_type)
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
})
|
||||
Some(
|
||||
match unsafe { std::ffi::CStr::from_ptr(application_type) }.to_str() {
|
||||
Ok(a) => a,
|
||||
Err(_) => {
|
||||
return ffi_err!(IdeviceError::InvalidCString);
|
||||
}
|
||||
},
|
||||
)
|
||||
};
|
||||
|
||||
let bundle_ids = if bundle_identifiers.is_null() {
|
||||
@@ -125,9 +128,9 @@ pub unsafe extern "C" fn installation_proxy_get_apps(
|
||||
.map(|&s| {
|
||||
unsafe { std::ffi::CStr::from_ptr(s) }
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
.to_string()
|
||||
})
|
||||
.collect(),
|
||||
.collect::<Vec<String>>(),
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -514,7 +514,7 @@ pub unsafe extern "C" fn image_mounter_query_nonce(
|
||||
let image_type = if !personalized_image_type.is_null() {
|
||||
let image_type_cstr = unsafe { std::ffi::CStr::from_ptr(personalized_image_type) };
|
||||
match image_type_cstr.to_str() {
|
||||
Ok(s) => Some(s.to_string()),
|
||||
Ok(s) => Some(s),
|
||||
Err(_) => return ffi_err!(IdeviceError::FfiInvalidArg),
|
||||
}
|
||||
} else {
|
||||
@@ -566,7 +566,7 @@ pub unsafe extern "C" fn image_mounter_query_personalization_identifiers(
|
||||
let image_type = if !image_type.is_null() {
|
||||
let image_type_cstr = unsafe { std::ffi::CStr::from_ptr(image_type) };
|
||||
match image_type_cstr.to_str() {
|
||||
Ok(s) => Some(s.to_string()),
|
||||
Ok(s) => Some(s),
|
||||
Err(_) => return ffi_err!(IdeviceError::FfiInvalidArg),
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user