summaryrefslogtreecommitdiffstats
path: root/src/preflight.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-11-04 22:56:48 +0100
committerGravatar Martin Szulecki2013-11-04 22:56:48 +0100
commit66b552798c0700ac851b53f6915d5a24aeeefdd9 (patch)
treeb53d0fa36c14749155ec48eff3ad8de0a4809a11 /src/preflight.c
parent791b19338bb781e8a8b7f3fbb8e0a85af57f8d96 (diff)
downloadusbmuxd-66b552798c0700ac851b53f6915d5a24aeeefdd9.tar.gz
usbmuxd-66b552798c0700ac851b53f6915d5a24aeeefdd9.tar.bz2
preflight: Make device visible during trust dialog pairing and handle unplug
The usbmuxd implementation on Win/OS X does allow enumerating and accessing the device during the "trust dialog" pairing process. We now also exit the waiting loop during unplugging of a device while waiting for the trust dialog to be dismissed.
Diffstat (limited to 'src/preflight.c')
-rw-r--r--src/preflight.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/preflight.c b/src/preflight.c
index 28485db..dc4b3dc 100644
--- a/src/preflight.c
+++ b/src/preflight.c
@@ -49,9 +49,10 @@ struct idevice_private {
void *conn_data;
};
-struct np_cb_data {
+struct cb_data {
idevice_t dev;
np_client_t np;
+ int is_device_connected;
};
extern uint16_t userpref_remove_device_record(const char* udid);
@@ -65,9 +66,20 @@ static void lockdownd_set_untrusted_host_buid(lockdownd_client_t lockdown)
free(system_buid);
}
+static void idevice_callback(const idevice_event_t* event, void* userdata)
+{
+ struct cb_data *cbdata = (struct cb_data*)userdata;
+ idevice_t dev = cbdata->dev;
+ struct idevice_private *_dev = (struct idevice_private*)dev;
+
+ if (event->event == IDEVICE_DEVICE_REMOVE && !strcmp(_dev->udid, event->udid)) {
+ cbdata->is_device_connected = 0;
+ }
+}
+
static void np_callback(const char* notification, void* userdata)
{
- struct np_cb_data *cbdata = (struct np_cb_data*)userdata;
+ struct cb_data *cbdata = (struct cb_data*)userdata;
idevice_t dev = cbdata->dev;
struct idevice_private *_dev = (struct idevice_private*)dev;
@@ -224,11 +236,13 @@ retry:
lockdownd_client_free(lockdown);
lockdown = NULL;
- struct np_cb_data cbdata;
+ struct cb_data cbdata;
cbdata.dev = dev;
cbdata.np = np;
+ cbdata.is_device_connected = 1;
np_set_notify_callback(np, np_callback, (void*)&cbdata);
+ idevice_event_subscribe(idevice_callback, (void*)&cbdata);
const char* spec[] = {
"com.apple.mobile.lockdown.request_pair",
@@ -237,11 +251,19 @@ retry:
};
np_observe_notifications(np, spec);
- usbmuxd_log(LL_INFO, "%s: Waiting for user to trust this computer on device %s", __func__, _dev->udid);
/* TODO send notification to user's desktop */
- while (cbdata.np) {
+
+ usbmuxd_log(LL_INFO, "%s: Waiting for user to trust this computer on device %s", __func__, _dev->udid);
+
+ /* make device visible anyways */
+ client_device_add(info);
+
+ while (cbdata.np && cbdata.is_device_connected == 1) {
sleep(1);
}
+ usbmuxd_log(LL_INFO, "%s: Finished waiting for notification from device %s, is_device_connected %d", __func__, _dev->udid, cbdata.is_device_connected);
+
+ idevice_event_unsubscribe();
if (cbdata.np) {
np_client_free(cbdata.np);