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/idevicebackup.c | 54 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'tools/idevicebackup.c') diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index abd269a..95c5694 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c @@ -745,7 +745,7 @@ static int mobilebackup_check_file_integrity(const char *backup_directory, const static void do_post_notification(const char *notification) { - uint16_t nport = 0; + lockdownd_service_descriptor_t service = NULL; np_client_t np; if (!client) { @@ -754,9 +754,9 @@ static void do_post_notification(const char *notification) } } - lockdownd_start_service(client, NP_SERVICE_NAME, &nport); - if (nport) { - np_client_new(device, nport, &np); + lockdownd_start_service(client, NP_SERVICE_NAME, &service); + if (service->port) { + np_client_new(device, service, &np); if (np) { np_post_notification(np, notification); np_client_free(np); @@ -764,6 +764,11 @@ static void do_post_notification(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(double progress) @@ -819,7 +824,7 @@ int main(int argc, char *argv[]) idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; int i; char* udid = NULL; - uint16_t port = 0; + lockdownd_service_descriptor_t service = NULL; int cmd = -1; int is_full_backup = 0; char *backup_directory = NULL; @@ -931,9 +936,9 @@ int main(int argc, char *argv[]) /* start notification_proxy */ np_client_t np = NULL; - ret = lockdownd_start_service(client, NP_SERVICE_NAME, &port); - if ((ret == LOCKDOWN_E_SUCCESS) && port) { - np_client_new(device, port, &np); + ret = lockdownd_start_service(client, 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, @@ -947,22 +952,37 @@ 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(client, "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(client, "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 */ - port = 0; - ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &port); - if ((ret == LOCKDOWN_E_SUCCESS) && port) { - printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, port); - mobilebackup_client_new(device, port, &mobilebackup); + ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &service); + if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { + printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, service->port); + mobilebackup_client_new(device, service, &mobilebackup); + + if (service) { + lockdownd_service_descriptor_free(service); + service = NULL; + } /* check abort conditions */ if (quit_flag > 0) { -- cgit v1.1-32-gdbae