From fcc1bb855efb6860417ed827d3b50feba24a9a8b Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 26 Feb 2013 03:20:56 +0100 Subject: Refactor port number use into service descriptor to enable SSL for services This is a major change which breaks API but is required in order to support SSL communication for services as used by network connections. --- tools/idevicebackup2.c | 54 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'tools/idevicebackup2.c') diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index a0e732d..0353c9b 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c @@ -479,7 +479,7 @@ static int mb2_status_check_snapshot_state(const char *path, const char *udid, c static void do_post_notification(idevice_t device, const char *notification) { - uint16_t nport = 0; + lockdownd_service_descriptor_t service = NULL; np_client_t np; lockdownd_client_t lockdown = NULL; @@ -488,9 +488,9 @@ static void do_post_notification(idevice_t device, const char *notification) return; } - lockdownd_start_service(lockdown, NP_SERVICE_NAME, &nport); - if (nport) { - np_client_new(device, nport, &np); + lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); + if (service->port) { + np_client_new(device, service, &np); if (np) { np_post_notification(np, notification); np_client_free(np); @@ -498,6 +498,11 @@ static void do_post_notification(idevice_t device, const char *notification) } else { printf("Could not start %s\n", NP_SERVICE_NAME); } + + if (service) { + lockdownd_service_descriptor_free(service); + service = NULL; + } } static void print_progress_real(double progress, int flush) @@ -1277,7 +1282,7 @@ int main(int argc, char *argv[]) int i; char* udid = NULL; char* source_udid = NULL; - uint16_t port = 0; + lockdownd_service_descriptor_t service = NULL; int cmd = -1; int cmd_flags = 0; int is_full_backup = 0; @@ -1551,9 +1556,9 @@ int main(int argc, char *argv[]) /* start notification_proxy */ np_client_t np = NULL; - ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &port); - if ((ret == LOCKDOWN_E_SUCCESS) && port) { - np_client_new(device, port, &np); + ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); + if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { + np_client_new(device, service, &np); np_set_notify_callback(np, notify_cb, NULL); const char *noties[5] = { NP_SYNC_CANCEL_REQUEST, @@ -1567,23 +1572,38 @@ int main(int argc, char *argv[]) printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); } + if (service) { + lockdownd_service_descriptor_free(service); + service = NULL; + } + afc_client_t afc = NULL; if (cmd == CMD_BACKUP) { /* start AFC, we need this for the lock file */ - port = 0; - ret = lockdownd_start_service(lockdown, "com.apple.afc", &port); - if ((ret == LOCKDOWN_E_SUCCESS) && port) { - afc_client_new(device, port, &afc); + service->port = 0; + service->ssl_enabled = 0; + ret = lockdownd_start_service(lockdown, "com.apple.afc", &service); + if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { + afc_client_new(device, service, &afc); } } + if (service) { + lockdownd_service_descriptor_free(service); + service = NULL; + } + /* start mobilebackup service and retrieve port */ mobilebackup2_client_t mobilebackup2 = NULL; - port = 0; - ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &port); - if ((ret == LOCKDOWN_E_SUCCESS) && port) { - PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, port); - mobilebackup2_client_new(device, port, &mobilebackup2); + ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service); + if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { + PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port); + mobilebackup2_client_new(device, service, &mobilebackup2); + + if (service) { + lockdownd_service_descriptor_free(service); + service = NULL; + } /* send Hello message */ double local_versions[2] = {2.0, 2.1}; -- cgit v1.1-32-gdbae