mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add default connection for usbmuxd
This commit is contained in:
5
ffi/README.md
Normal file
5
ffi/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Bindings for idevice
|
||||||
|
|
||||||
|
These bindings will try their best to stay up to date with the Rust library.
|
||||||
|
While jkcoxson is the only contributor, they will be maintained on a best-effort
|
||||||
|
basis.
|
||||||
1
ffi/src/installation_proxy.rs
Normal file
1
ffi/src/installation_proxy.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// Jackson Coxson
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
|
pub mod installation_proxy;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
mod pairing_file;
|
mod pairing_file;
|
||||||
pub mod provider;
|
pub mod provider;
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ pub struct UsbmuxdAddrHandle(pub UsbmuxdAddr);
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `addr` must be a valid sockaddr
|
/// `addr` must be a valid sockaddr
|
||||||
/// `label` must be a valid null-terminated C string
|
|
||||||
/// `usbmuxd_connection` must be a valid, non-null pointer to a location where the handle will be stored
|
/// `usbmuxd_connection` must be a valid, non-null pointer to a location where the handle will be stored
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub unsafe extern "C" fn idevice_usbmuxd_new_tcp_connection(
|
pub unsafe extern "C" fn idevice_usbmuxd_new_tcp_connection(
|
||||||
@@ -65,7 +64,6 @@ pub unsafe extern "C" fn idevice_usbmuxd_new_tcp_connection(
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// `addr` must be a valid CStr
|
/// `addr` must be a valid CStr
|
||||||
/// `label` must be a valid null-terminated C string
|
|
||||||
/// `usbmuxd_connection` must be a valid, non-null pointer to a location where the handle will be stored
|
/// `usbmuxd_connection` must be a valid, non-null pointer to a location where the handle will be stored
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
@@ -94,6 +92,44 @@ pub unsafe extern "C" fn idevice_usbmuxd_new_unix_socket_connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Connects to a usbmuxd instance over the default connection for the platform
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * [`addr`] - The socket path to connect to
|
||||||
|
/// * [`tag`] - A tag that will be returned by usbmuxd responses
|
||||||
|
/// * [`usbmuxd_connection`] - On success, will be set to point to a newly allocated UsbmuxdConnection handle
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// An error code indicating success or failure
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
/// `addr` must be a valid CStr
|
||||||
|
/// `usbmuxd_connection` must be a valid, non-null pointer to a location where the handle will be stored
|
||||||
|
pub unsafe extern "C" fn idevice_usbmuxd_new_default_connection(
|
||||||
|
tag: u32,
|
||||||
|
usbmuxd_connection: *mut *mut UsbmuxdConnectionHandle,
|
||||||
|
) -> IdeviceErrorCode {
|
||||||
|
let addr = match UsbmuxdAddr::from_env_var() {
|
||||||
|
Ok(a) => a,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Invalid address set: {e:?}");
|
||||||
|
return IdeviceErrorCode::InvalidArg;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let res: Result<UsbmuxdConnection, IdeviceError> =
|
||||||
|
RUNTIME.block_on(async move { addr.connect(tag).await });
|
||||||
|
|
||||||
|
match res {
|
||||||
|
Ok(r) => {
|
||||||
|
let boxed = Box::new(UsbmuxdConnectionHandle(r));
|
||||||
|
unsafe { *usbmuxd_connection = Box::into_raw(boxed) };
|
||||||
|
IdeviceErrorCode::IdeviceSuccess
|
||||||
|
}
|
||||||
|
Err(e) => e.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Frees a UsbmuxdConnection handle
|
/// Frees a UsbmuxdConnection handle
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user