diff --git a/ffi/README.md b/ffi/README.md new file mode 100644 index 0000000..b38f5ac --- /dev/null +++ b/ffi/README.md @@ -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. diff --git a/ffi/src/installation_proxy.rs b/ffi/src/installation_proxy.rs new file mode 100644 index 0000000..447a0b2 --- /dev/null +++ b/ffi/src/installation_proxy.rs @@ -0,0 +1 @@ +// Jackson Coxson diff --git a/ffi/src/lib.rs b/ffi/src/lib.rs index 09f58da..ddc34f0 100644 --- a/ffi/src/lib.rs +++ b/ffi/src/lib.rs @@ -1,6 +1,7 @@ // Jackson Coxson mod errors; +pub mod installation_proxy; pub mod logging; mod pairing_file; pub mod provider; diff --git a/ffi/src/usbmuxd.rs b/ffi/src/usbmuxd.rs index 0012006..ce6956c 100644 --- a/ffi/src/usbmuxd.rs +++ b/ffi/src/usbmuxd.rs @@ -24,7 +24,6 @@ pub struct UsbmuxdAddrHandle(pub UsbmuxdAddr); /// /// # Safety /// `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 #[unsafe(no_mangle)] 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 /// `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 #[unsafe(no_mangle)] #[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 = + 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 /// /// # Arguments