diff options
| author | 2013-02-26 03:20:56 +0100 | |
|---|---|---|
| committer | 2013-02-26 03:20:56 +0100 | |
| commit | fcc1bb855efb6860417ed827d3b50feba24a9a8b (patch) | |
| tree | 47d3c7d6a985dc647f7962329014c8116d657cc9 /tools/idevicebackup2.c | |
| parent | 3b54aac30447bc02fafd721a63a752968628e7e0 (diff) | |
| download | libimobiledevice-fcc1bb855efb6860417ed827d3b50feba24a9a8b.tar.gz libimobiledevice-fcc1bb855efb6860417ed827d3b50feba24a9a8b.tar.bz2 | |
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.
Diffstat (limited to 'tools/idevicebackup2.c')
| -rw-r--r-- | tools/idevicebackup2.c | 54 |
1 files changed, 37 insertions, 17 deletions
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 | |||
| 479 | 479 | ||
| 480 | static void do_post_notification(idevice_t device, const char *notification) | 480 | static void do_post_notification(idevice_t device, const char *notification) |
| 481 | { | 481 | { |
| 482 | uint16_t nport = 0; | 482 | lockdownd_service_descriptor_t service = NULL; |
| 483 | np_client_t np; | 483 | np_client_t np; |
| 484 | 484 | ||
| 485 | lockdownd_client_t lockdown = NULL; | 485 | lockdownd_client_t lockdown = NULL; |
| @@ -488,9 +488,9 @@ static void do_post_notification(idevice_t device, const char *notification) | |||
| 488 | return; | 488 | return; |
| 489 | } | 489 | } |
| 490 | 490 | ||
| 491 | lockdownd_start_service(lockdown, NP_SERVICE_NAME, &nport); | 491 | lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); |
| 492 | if (nport) { | 492 | if (service->port) { |
| 493 | np_client_new(device, nport, &np); | 493 | np_client_new(device, service, &np); |
| 494 | if (np) { | 494 | if (np) { |
| 495 | np_post_notification(np, notification); | 495 | np_post_notification(np, notification); |
| 496 | np_client_free(np); | 496 | np_client_free(np); |
| @@ -498,6 +498,11 @@ static void do_post_notification(idevice_t device, const char *notification) | |||
| 498 | } else { | 498 | } else { |
| 499 | printf("Could not start %s\n", NP_SERVICE_NAME); | 499 | printf("Could not start %s\n", NP_SERVICE_NAME); |
| 500 | } | 500 | } |
| 501 | |||
| 502 | if (service) { | ||
| 503 | lockdownd_service_descriptor_free(service); | ||
| 504 | service = NULL; | ||
| 505 | } | ||
| 501 | } | 506 | } |
| 502 | 507 | ||
| 503 | static void print_progress_real(double progress, int flush) | 508 | static void print_progress_real(double progress, int flush) |
| @@ -1277,7 +1282,7 @@ int main(int argc, char *argv[]) | |||
| 1277 | int i; | 1282 | int i; |
| 1278 | char* udid = NULL; | 1283 | char* udid = NULL; |
| 1279 | char* source_udid = NULL; | 1284 | char* source_udid = NULL; |
| 1280 | uint16_t port = 0; | 1285 | lockdownd_service_descriptor_t service = NULL; |
| 1281 | int cmd = -1; | 1286 | int cmd = -1; |
| 1282 | int cmd_flags = 0; | 1287 | int cmd_flags = 0; |
| 1283 | int is_full_backup = 0; | 1288 | int is_full_backup = 0; |
| @@ -1551,9 +1556,9 @@ int main(int argc, char *argv[]) | |||
| 1551 | 1556 | ||
| 1552 | /* start notification_proxy */ | 1557 | /* start notification_proxy */ |
| 1553 | np_client_t np = NULL; | 1558 | np_client_t np = NULL; |
| 1554 | ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &port); | 1559 | ret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); |
| 1555 | if ((ret == LOCKDOWN_E_SUCCESS) && port) { | 1560 | if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { |
| 1556 | np_client_new(device, port, &np); | 1561 | np_client_new(device, service, &np); |
| 1557 | np_set_notify_callback(np, notify_cb, NULL); | 1562 | np_set_notify_callback(np, notify_cb, NULL); |
| 1558 | const char *noties[5] = { | 1563 | const char *noties[5] = { |
| 1559 | NP_SYNC_CANCEL_REQUEST, | 1564 | NP_SYNC_CANCEL_REQUEST, |
| @@ -1567,23 +1572,38 @@ int main(int argc, char *argv[]) | |||
| 1567 | printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); | 1572 | printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); |
| 1568 | } | 1573 | } |
| 1569 | 1574 | ||
| 1575 | if (service) { | ||
| 1576 | lockdownd_service_descriptor_free(service); | ||
| 1577 | service = NULL; | ||
| 1578 | } | ||
| 1579 | |||
| 1570 | afc_client_t afc = NULL; | 1580 | afc_client_t afc = NULL; |
| 1571 | if (cmd == CMD_BACKUP) { | 1581 | if (cmd == CMD_BACKUP) { |
| 1572 | /* start AFC, we need this for the lock file */ | 1582 | /* start AFC, we need this for the lock file */ |
| 1573 | port = 0; | 1583 | service->port = 0; |
| 1574 | ret = lockdownd_start_service(lockdown, "com.apple.afc", &port); | 1584 | service->ssl_enabled = 0; |
| 1575 | if ((ret == LOCKDOWN_E_SUCCESS) && port) { | 1585 | ret = lockdownd_start_service(lockdown, "com.apple.afc", &service); |
| 1576 | afc_client_new(device, port, &afc); | 1586 | if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { |
| 1587 | afc_client_new(device, service, &afc); | ||
| 1577 | } | 1588 | } |
| 1578 | } | 1589 | } |
| 1579 | 1590 | ||
| 1591 | if (service) { | ||
| 1592 | lockdownd_service_descriptor_free(service); | ||
| 1593 | service = NULL; | ||
| 1594 | } | ||
| 1595 | |||
| 1580 | /* start mobilebackup service and retrieve port */ | 1596 | /* start mobilebackup service and retrieve port */ |
| 1581 | mobilebackup2_client_t mobilebackup2 = NULL; | 1597 | mobilebackup2_client_t mobilebackup2 = NULL; |
| 1582 | port = 0; | 1598 | ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service); |
| 1583 | ret = lockdownd_start_service(lockdown, MOBILEBACKUP2_SERVICE_NAME, &port); | 1599 | if ((ret == LOCKDOWN_E_SUCCESS) && service->port) { |
| 1584 | if ((ret == LOCKDOWN_E_SUCCESS) && port) { | 1600 | PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port); |
| 1585 | PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, port); | 1601 | mobilebackup2_client_new(device, service, &mobilebackup2); |
| 1586 | mobilebackup2_client_new(device, port, &mobilebackup2); | 1602 | |
| 1603 | if (service) { | ||
| 1604 | lockdownd_service_descriptor_free(service); | ||
| 1605 | service = NULL; | ||
| 1606 | } | ||
| 1587 | 1607 | ||
| 1588 | /* send Hello message */ | 1608 | /* send Hello message */ |
| 1589 | double local_versions[2] = {2.0, 2.1}; | 1609 | double local_versions[2] = {2.0, 2.1}; |
