summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-02-26 03:20:56 +0100
committerGravatar Martin Szulecki2013-02-26 03:20:56 +0100
commitfcc1bb855efb6860417ed827d3b50feba24a9a8b (patch)
tree47d3c7d6a985dc647f7962329014c8116d657cc9
parent3b54aac30447bc02fafd721a63a752968628e7e0 (diff)
downloadlibimobiledevice-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.
-rw-r--r--dev/afccheck.c11
-rw-r--r--dev/filerelaytest.c11
-rw-r--r--dev/housearresttest.c11
-rw-r--r--dev/ideviceclient.c43
-rw-r--r--dev/lckdclient.c10
-rw-r--r--include/libimobiledevice/afc.h3
-rw-r--r--include/libimobiledevice/diagnostics_relay.h3
-rw-r--r--include/libimobiledevice/file_relay.h3
-rw-r--r--include/libimobiledevice/house_arrest.h3
-rw-r--r--include/libimobiledevice/installation_proxy.h3
-rw-r--r--include/libimobiledevice/lockdown.h10
-rw-r--r--include/libimobiledevice/misagent.h3
-rw-r--r--include/libimobiledevice/mobile_image_mounter.h3
-rw-r--r--include/libimobiledevice/mobilebackup.h3
-rw-r--r--include/libimobiledevice/mobilebackup2.h3
-rw-r--r--include/libimobiledevice/mobilesync.h3
-rw-r--r--include/libimobiledevice/notification_proxy.h3
-rw-r--r--include/libimobiledevice/sbservices.h3
-rw-r--r--include/libimobiledevice/screenshotr.h3
-rw-r--r--include/libimobiledevice/webinspector.h3
-rw-r--r--src/afc.c12
-rw-r--r--src/device_link_service.c12
-rw-r--r--src/device_link_service.h2
-rw-r--r--src/diagnostics_relay.c8
-rw-r--r--src/file_relay.c8
-rw-r--r--src/house_arrest.c6
-rw-r--r--src/installation_proxy.c6
-rw-r--r--src/lockdown.c58
-rw-r--r--src/misagent.c6
-rw-r--r--src/mobile_image_mounter.c6
-rw-r--r--src/mobilebackup.c8
-rw-r--r--src/mobilebackup2.c8
-rw-r--r--src/mobilesync.c8
-rw-r--r--src/notification_proxy.c6
-rw-r--r--src/property_list_service.c15
-rw-r--r--src/property_list_service.h3
-rw-r--r--src/restore.c7
-rw-r--r--src/sbservices.c6
-rw-r--r--src/screenshotr.c8
-rw-r--r--src/webinspector.c27
-rw-r--r--tools/idevicebackup.c54
-rw-r--r--tools/idevicebackup2.c54
-rw-r--r--tools/idevicedebugserverproxy.c15
-rw-r--r--tools/idevicediagnostics.c17
-rw-r--r--tools/ideviceimagemounter.c24
-rw-r--r--tools/ideviceprovision.c11
-rw-r--r--tools/idevicescreenshot.c14
-rw-r--r--tools/idevicesyslog.c13
48 files changed, 373 insertions, 187 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c
index 2dab6db..ead0ca0 100644
--- a/dev/afccheck.c
+++ b/dev/afccheck.c
@@ -92,7 +92,7 @@ int main(int argc, char *argv[])
92{ 92{
93 lockdownd_client_t client = NULL; 93 lockdownd_client_t client = NULL;
94 idevice_t phone = NULL; 94 idevice_t phone = NULL;
95 uint16_t port = 0; 95 lockdownd_service_descriptor_t service = NULL;
96 afc_client_t afc = NULL; 96 afc_client_t afc = NULL;
97 97
98 if (argc > 1 && !strcasecmp(argv[1], "--debug")) { 98 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
@@ -111,14 +111,19 @@ int main(int argc, char *argv[])
111 return 1; 111 return 1;
112 } 112 }
113 113
114 if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { 114 if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &service) && !service->port) {
115 lockdownd_client_free(client); 115 lockdownd_client_free(client);
116 idevice_free(phone); 116 idevice_free(phone);
117 fprintf(stderr, "Something went wrong when starting AFC."); 117 fprintf(stderr, "Something went wrong when starting AFC.");
118 return 1; 118 return 1;
119 } 119 }
120 120
121 afc_client_new(phone, port, &afc); 121 afc_client_new(phone, service, &afc);
122
123 if (service) {
124 lockdownd_service_descriptor_free(service);
125 service = NULL;
126 }
122 127
123 pthread_t threads[NB_THREADS]; 128 pthread_t threads[NB_THREADS];
124 param data[NB_THREADS]; 129 param data[NB_THREADS];
diff --git a/dev/filerelaytest.c b/dev/filerelaytest.c
index 8c9514b..9094130 100644
--- a/dev/filerelaytest.c
+++ b/dev/filerelaytest.c
@@ -27,6 +27,7 @@ int main(int argc, char **argv)
27{ 27{
28 idevice_t dev = NULL; 28 idevice_t dev = NULL;
29 lockdownd_client_t client = NULL; 29 lockdownd_client_t client = NULL;
30 lockdownd_service_descriptor_t service = NULL;
30 file_relay_client_t frc = NULL; 31 file_relay_client_t frc = NULL;
31 32
32 if (idevice_new(&dev, NULL) != IDEVICE_E_SUCCESS) { 33 if (idevice_new(&dev, NULL) != IDEVICE_E_SUCCESS) {
@@ -40,8 +41,7 @@ int main(int argc, char **argv)
40 goto leave_cleanup; 41 goto leave_cleanup;
41 } 42 }
42 43
43 uint16_t port = 0; 44 if (lockdownd_start_service(client, "com.apple.mobile.file_relay", &service) != LOCKDOWN_E_SUCCESS) {
44 if (lockdownd_start_service(client, "com.apple.mobile.file_relay", &port) != LOCKDOWN_E_SUCCESS) {
45 printf("could not start file_relay service!\n"); 45 printf("could not start file_relay service!\n");
46 goto leave_cleanup; 46 goto leave_cleanup;
47 } 47 }
@@ -51,11 +51,16 @@ int main(int argc, char **argv)
51 client = NULL; 51 client = NULL;
52 } 52 }
53 53
54 if (file_relay_client_new(dev, port, &frc) != FILE_RELAY_E_SUCCESS) { 54 if (file_relay_client_new(dev, service, &frc) != FILE_RELAY_E_SUCCESS) {
55 printf("could not connect to file_relay service!\n"); 55 printf("could not connect to file_relay service!\n");
56 goto leave_cleanup; 56 goto leave_cleanup;
57 } 57 }
58 58
59 if (service) {
60 lockdownd_service_descriptor_free(service);
61 service = NULL;
62 }
63
59 idevice_connection_t dump = NULL; 64 idevice_connection_t dump = NULL;
60 const char *sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL}; 65 const char *sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL};
61 66
diff --git a/dev/housearresttest.c b/dev/housearresttest.c
index 951ebe4..2e24670 100644
--- a/dev/housearresttest.c
+++ b/dev/housearresttest.c
@@ -96,8 +96,8 @@ int main(int argc, char **argv)
96 goto leave_cleanup; 96 goto leave_cleanup;
97 } 97 }
98 98
99 uint16_t port = 0; 99 lockdownd_service_descriptor_t service = NULL;
100 if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &port) != LOCKDOWN_E_SUCCESS) { 100 if (lockdownd_start_service(client, "com.apple.mobile.house_arrest", &service) != LOCKDOWN_E_SUCCESS) {
101 printf("could not start house_arrest service!\n"); 101 printf("could not start house_arrest service!\n");
102 goto leave_cleanup; 102 goto leave_cleanup;
103 } 103 }
@@ -107,11 +107,16 @@ int main(int argc, char **argv)
107 client = NULL; 107 client = NULL;
108 } 108 }
109 109
110 if (house_arrest_client_new(dev, port, &hac) != HOUSE_ARREST_E_SUCCESS) { 110 if (house_arrest_client_new(dev, service, &hac) != HOUSE_ARREST_E_SUCCESS) {
111 printf("could not connect to house_arrest service!\n"); 111 printf("could not connect to house_arrest service!\n");
112 goto leave_cleanup; 112 goto leave_cleanup;
113 } 113 }
114 114
115 if (service) {
116 lockdownd_service_descriptor_free(service);
117 service = NULL;
118 }
119
115 res = house_arrest_send_command(hac, "VendDocuments", appid); 120 res = house_arrest_send_command(hac, "VendDocuments", appid);
116 if (res != HOUSE_ARREST_E_SUCCESS) { 121 if (res != HOUSE_ARREST_E_SUCCESS) {
117 printf("error %d when trying to get VendDocuments\n", res); 122 printf("error %d when trying to get VendDocuments\n", res);
diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c
index d467ee8..c8635d8 100644
--- a/dev/ideviceclient.c
+++ b/dev/ideviceclient.c
@@ -45,13 +45,13 @@ static void notifier(const char *notification, void *userdata)
45 45
46static void perform_notification(idevice_t phone, lockdownd_client_t client, const char *notification) 46static void perform_notification(idevice_t phone, lockdownd_client_t client, const char *notification)
47{ 47{
48 uint16_t nport = 0; 48 lockdownd_service_descriptor_t service = NULL;
49 np_client_t np; 49 np_client_t np;
50 50
51 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); 51 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service);
52 if (nport) { 52 if (service->port) {
53 printf("::::::::::::::: np was started ::::::::::::\n"); 53 printf("::::::::::::::: np was started ::::::::::::\n");
54 np_client_new(phone, nport, &np); 54 np_client_new(phone, service, &np);
55 if (np) { 55 if (np) {
56 printf("::::::::: PostNotification %s\n", notification); 56 printf("::::::::: PostNotification %s\n", notification);
57 np_post_notification(np, notification); 57 np_post_notification(np, notification);
@@ -60,13 +60,18 @@ static void perform_notification(idevice_t phone, lockdownd_client_t client, con
60 } else { 60 } else {
61 printf("::::::::::::::: np was NOT started ::::::::::::\n"); 61 printf("::::::::::::::: np was NOT started ::::::::::::\n");
62 } 62 }
63
64 if (service) {
65 lockdownd_service_descriptor_free(service);
66 service = NULL;
67 }
63} 68}
64 69
65int main(int argc, char *argv[]) 70int main(int argc, char *argv[])
66{ 71{
67 unsigned int bytes = 0; 72 unsigned int bytes = 0;
68 uint16_t port = 0, i = 0; 73 uint16_t i = 0;
69 uint16_t npp; 74 lockdownd_service_descriptor_t service = NULL;
70 lockdownd_client_t client = NULL; 75 lockdownd_client_t client = NULL;
71 idevice_t phone = NULL; 76 idevice_t phone = NULL;
72 uint64_t lockfile = 0; 77 uint64_t lockfile = 0;
@@ -102,19 +107,33 @@ int main(int argc, char *argv[])
102 free(nnn); 107 free(nnn);
103 } 108 }
104 109
105 lockdownd_start_service(client, "com.apple.afc", &port); 110 lockdownd_start_service(client, "com.apple.afc", &service);
106 111
107 if (port) { 112 if (service->port) {
108 afc_client_t afc = NULL; 113 afc_client_t afc = NULL;
109 afc_client_new(phone, port, &afc); 114 afc_client_new(phone, service, &afc);
115
116 if (service) {
117 lockdownd_service_descriptor_free(service);
118 service = NULL;
119 }
120
110 if (afc) { 121 if (afc) {
111 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); 122 service->port = 0;
112 if (npp) { 123 service->ssl_enabled = 0;
124 lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &service);
125 if (service->port) {
113 printf("Notification Proxy started.\n"); 126 printf("Notification Proxy started.\n");
114 np_client_new(phone, npp, &gnp); 127 np_client_new(phone, service, &gnp);
115 } else { 128 } else {
116 printf("ERROR: Notification proxy could not be started.\n"); 129 printf("ERROR: Notification proxy could not be started.\n");
117 } 130 }
131
132 if (service) {
133 lockdownd_service_descriptor_free(service);
134 service = NULL;
135 }
136
118 if (gnp) { 137 if (gnp) {
119 const char *nspec[5] = { 138 const char *nspec[5] = {
120 NP_SYNC_CANCEL_REQUEST, 139 NP_SYNC_CANCEL_REQUEST,
diff --git a/dev/lckdclient.c b/dev/lckdclient.c
index cc89634..b9be4de 100644
--- a/dev/lckdclient.c
+++ b/dev/lckdclient.c
@@ -136,9 +136,13 @@ int main(int argc, char *argv[])
136 } 136 }
137 137
138 if (!strcmp(*args, "start") && len == 2) { 138 if (!strcmp(*args, "start") && len == 2) {
139 uint16_t port = 0; 139 lockdownd_service_descriptor_t service = NULL;
140 if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &port)) { 140 if(LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, *(args + 1), &service)) {
141 printf("started service %s on port %i\n", *(args + 1), port); 141 printf("started service %s on port %i\n", *(args + 1), service->port);
142 if (service) {
143 lockdownd_service_descriptor_free(service);
144 service = NULL;
145 }
142 } 146 }
143 else 147 else
144 { 148 {
diff --git a/include/libimobiledevice/afc.h b/include/libimobiledevice/afc.h
index 8d47696..1b4ad5b 100644
--- a/include/libimobiledevice/afc.h
+++ b/include/libimobiledevice/afc.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -93,7 +94,7 @@ typedef afc_client_private *afc_client_t; /**< The client handle. */
93 94
94/* Interface */ 95/* Interface */
95afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_client_t *client); 96afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_client_t *client);
96afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t *client); 97afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t *client);
97afc_error_t afc_client_free(afc_client_t client); 98afc_error_t afc_client_free(afc_client_t client);
98afc_error_t afc_get_device_info(afc_client_t client, char ***infos); 99afc_error_t afc_get_device_info(afc_client_t client, char ***infos);
99afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list); 100afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list);
diff --git a/include/libimobiledevice/diagnostics_relay.h b/include/libimobiledevice/diagnostics_relay.h
index bdb3f36..ec87732 100644
--- a/include/libimobiledevice/diagnostics_relay.h
+++ b/include/libimobiledevice/diagnostics_relay.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -55,7 +56,7 @@ typedef int16_t diagnostics_relay_error_t;
55typedef struct diagnostics_relay_client_private diagnostics_relay_client_private; 56typedef struct diagnostics_relay_client_private diagnostics_relay_client_private;
56typedef diagnostics_relay_client_private *diagnostics_relay_client_t; /**< The client handle. */ 57typedef diagnostics_relay_client_private *diagnostics_relay_client_t; /**< The client handle. */
57 58
58diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, uint16_t port, diagnostics_relay_client_t *client); 59diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client);
59diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client); 60diagnostics_relay_error_t diagnostics_relay_client_free(diagnostics_relay_client_t client);
60 61
61diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client); 62diagnostics_relay_error_t diagnostics_relay_goodbye(diagnostics_relay_client_t client);
diff --git a/include/libimobiledevice/file_relay.h b/include/libimobiledevice/file_relay.h
index 52d4758..85f9213 100644
--- a/include/libimobiledevice/file_relay.h
+++ b/include/libimobiledevice/file_relay.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -47,7 +48,7 @@ typedef int16_t file_relay_error_t;
47typedef struct file_relay_client_private file_relay_client_private; 48typedef struct file_relay_client_private file_relay_client_private;
48typedef file_relay_client_private *file_relay_client_t; /**< The client handle. */ 49typedef file_relay_client_private *file_relay_client_t; /**< The client handle. */
49 50
50file_relay_error_t file_relay_client_new(idevice_t device, uint16_t port, file_relay_client_t *client); 51file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client);
51file_relay_error_t file_relay_client_free(file_relay_client_t client); 52file_relay_error_t file_relay_client_free(file_relay_client_t client);
52 53
53file_relay_error_t file_relay_request_sources(file_relay_client_t client, const char **sources, idevice_connection_t *connection); 54file_relay_error_t file_relay_request_sources(file_relay_client_t client, const char **sources, idevice_connection_t *connection);
diff --git a/include/libimobiledevice/house_arrest.h b/include/libimobiledevice/house_arrest.h
index 04290f1..ee03072 100644
--- a/include/libimobiledevice/house_arrest.h
+++ b/include/libimobiledevice/house_arrest.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31#include <libimobiledevice/afc.h> 32#include <libimobiledevice/afc.h>
32 33
33/** @name Error Codes */ 34/** @name Error Codes */
@@ -48,7 +49,7 @@ typedef struct house_arrest_client_private house_arrest_client_private;
48typedef house_arrest_client_private *house_arrest_client_t; /**< The client handle. */ 49typedef house_arrest_client_private *house_arrest_client_t; /**< The client handle. */
49 50
50/* Interface */ 51/* Interface */
51house_arrest_error_t house_arrest_client_new(idevice_t device, uint16_t port, house_arrest_client_t *client); 52house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client);
52house_arrest_error_t house_arrest_client_free(house_arrest_client_t client); 53house_arrest_error_t house_arrest_client_free(house_arrest_client_t client);
53 54
54house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict); 55house_arrest_error_t house_arrest_send_request(house_arrest_client_t client, plist_t dict);
diff --git a/include/libimobiledevice/installation_proxy.h b/include/libimobiledevice/installation_proxy.h
index 11fb66e..6a20c0b 100644
--- a/include/libimobiledevice/installation_proxy.h
+++ b/include/libimobiledevice/installation_proxy.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -51,7 +52,7 @@ typedef instproxy_client_private *instproxy_client_t; /**< The client handle. */
51typedef void (*instproxy_status_cb_t) (const char *operation, plist_t status, void *user_data); 52typedef void (*instproxy_status_cb_t) (const char *operation, plist_t status, void *user_data);
52 53
53/* Interface */ 54/* Interface */
54instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client); 55instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client);
55instproxy_error_t instproxy_client_free(instproxy_client_t client); 56instproxy_error_t instproxy_client_free(instproxy_client_t client);
56 57
57instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result); 58instproxy_error_t instproxy_browse(instproxy_client_t client, plist_t client_options, plist_t *result);
diff --git a/include/libimobiledevice/lockdown.h b/include/libimobiledevice/lockdown.h
index 4e7a4e8..287d3f6 100644
--- a/include/libimobiledevice/lockdown.h
+++ b/include/libimobiledevice/lockdown.h
@@ -29,6 +29,7 @@ extern "C" {
29#endif 29#endif
30 30
31#include <libimobiledevice/libimobiledevice.h> 31#include <libimobiledevice/libimobiledevice.h>
32#include <libimobiledevice/lockdown.h>
32 33
33/** @name Error Codes */ 34/** @name Error Codes */
34/*@{*/ 35/*@{*/
@@ -70,6 +71,12 @@ struct lockdownd_pair_record {
70/** A pair record holding device, host and root certificates along the host_id */ 71/** A pair record holding device, host and root certificates along the host_id */
71typedef struct lockdownd_pair_record *lockdownd_pair_record_t; 72typedef struct lockdownd_pair_record *lockdownd_pair_record_t;
72 73
74struct lockdownd_service_descriptor {
75 uint16_t port;
76 uint8_t ssl_enabled;
77};
78typedef struct lockdownd_service_descriptor *lockdownd_service_descriptor_t;
79
73/* Interface */ 80/* Interface */
74lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label); 81lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label);
75lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label); 82lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label);
@@ -79,7 +86,7 @@ lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type);
79lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); 86lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value);
80lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); 87lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value);
81lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); 88lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key);
82lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port); 89lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service);
83lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled); 90lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled);
84lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id); 91lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id);
85lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); 92lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist);
@@ -98,6 +105,7 @@ lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t control, char **u
98lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); 105lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name);
99lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count); 106lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count);
100lockdownd_error_t lockdownd_data_classes_free(char **classes); 107lockdownd_error_t lockdownd_data_classes_free(char **classes);
108lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service);
101 109
102#ifdef __cplusplus 110#ifdef __cplusplus
103} 111}
diff --git a/include/libimobiledevice/misagent.h b/include/libimobiledevice/misagent.h
index 7aa609b..3adfd9d 100644
--- a/include/libimobiledevice/misagent.h
+++ b/include/libimobiledevice/misagent.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -47,7 +48,7 @@ typedef struct misagent_client_private misagent_client_private;
47typedef misagent_client_private *misagent_client_t; /**< The client handle. */ 48typedef misagent_client_private *misagent_client_t; /**< The client handle. */
48 49
49/* Interface */ 50/* Interface */
50misagent_error_t misagent_client_new(idevice_t device, uint16_t port, misagent_client_t *client); 51misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client);
51misagent_error_t misagent_client_free(misagent_client_t client); 52misagent_error_t misagent_client_free(misagent_client_t client);
52 53
53misagent_error_t misagent_install(misagent_client_t client, plist_t profile); 54misagent_error_t misagent_install(misagent_client_t client, plist_t profile);
diff --git a/include/libimobiledevice/mobile_image_mounter.h b/include/libimobiledevice/mobile_image_mounter.h
index 04c65d5..a9f500d 100644
--- a/include/libimobiledevice/mobile_image_mounter.h
+++ b/include/libimobiledevice/mobile_image_mounter.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -46,7 +47,7 @@ typedef struct mobile_image_mounter_client_private mobile_image_mounter_client_p
46typedef mobile_image_mounter_client_private *mobile_image_mounter_client_t; /**< The client handle. */ 47typedef mobile_image_mounter_client_private *mobile_image_mounter_client_t; /**< The client handle. */
47 48
48/* Interface */ 49/* Interface */
49mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client); 50mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client);
50mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client); 51mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_client_t client);
51mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, const char *image_type, plist_t *result); 52mobile_image_mounter_error_t mobile_image_mounter_lookup_image(mobile_image_mounter_client_t client, const char *image_type, plist_t *result);
52mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const char *image_signature, uint16_t signature_length, const char *image_type, plist_t *result); 53mobile_image_mounter_error_t mobile_image_mounter_mount_image(mobile_image_mounter_client_t client, const char *image_path, const char *image_signature, uint16_t signature_length, const char *image_type, plist_t *result);
diff --git a/include/libimobiledevice/mobilebackup.h b/include/libimobiledevice/mobilebackup.h
index 8f31cc4..358103d 100644
--- a/include/libimobiledevice/mobilebackup.h
+++ b/include/libimobiledevice/mobilebackup.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -53,7 +54,7 @@ typedef enum {
53 MB_RESTORE_PRESERVE_CAMERA_ROLL = 1 << 2 54 MB_RESTORE_PRESERVE_CAMERA_ROLL = 1 << 2
54} mobilebackup_flags_t; 55} mobilebackup_flags_t;
55 56
56mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, mobilebackup_client_t * client); 57mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client);
57mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client); 58mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client);
58mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist); 59mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist);
59mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist); 60mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist);
diff --git a/include/libimobiledevice/mobilebackup2.h b/include/libimobiledevice/mobilebackup2.h
index 6557f42..215c339 100644
--- a/include/libimobiledevice/mobilebackup2.h
+++ b/include/libimobiledevice/mobilebackup2.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -48,7 +49,7 @@ typedef int16_t mobilebackup2_error_t;
48typedef struct mobilebackup2_client_private mobilebackup2_client_private; 49typedef struct mobilebackup2_client_private mobilebackup2_client_private;
49typedef mobilebackup2_client_private *mobilebackup2_client_t; /**< The client handle. */ 50typedef mobilebackup2_client_private *mobilebackup2_client_t; /**< The client handle. */
50 51
51mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, uint16_t port, mobilebackup2_client_t * client); 52mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup2_client_t * client);
52mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client); 53mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client);
53mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options); 54mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options);
54mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage); 55mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage);
diff --git a/include/libimobiledevice/mobilesync.h b/include/libimobiledevice/mobilesync.h
index cfab8d9..ef1f4df 100644
--- a/include/libimobiledevice/mobilesync.h
+++ b/include/libimobiledevice/mobilesync.h
@@ -29,6 +29,7 @@ extern "C" {
29#endif 29#endif
30 30
31#include <libimobiledevice/libimobiledevice.h> 31#include <libimobiledevice/libimobiledevice.h>
32#include <libimobiledevice/lockdown.h>
32 33
33/** @name Error Codes */ 34/** @name Error Codes */
34/*@{*/ 35/*@{*/
@@ -65,7 +66,7 @@ typedef struct {
65typedef mobilesync_anchors *mobilesync_anchors_t; /**< Anchors used by the device and computer. */ 66typedef mobilesync_anchors *mobilesync_anchors_t; /**< Anchors used by the device and computer. */
66 67
67/* Interface */ 68/* Interface */
68mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, mobilesync_client_t * client); 69mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilesync_client_t * client);
69mobilesync_error_t mobilesync_client_free(mobilesync_client_t client); 70mobilesync_error_t mobilesync_client_free(mobilesync_client_t client);
70 71
71mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t *plist); 72mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t *plist);
diff --git a/include/libimobiledevice/notification_proxy.h b/include/libimobiledevice/notification_proxy.h
index 43c479d..3f883e5 100644
--- a/include/libimobiledevice/notification_proxy.h
+++ b/include/libimobiledevice/notification_proxy.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -90,7 +91,7 @@ typedef np_client_private *np_client_t; /**< The client handle. */
90typedef void (*np_notify_cb_t) (const char *notification, void *user_data); 91typedef void (*np_notify_cb_t) (const char *notification, void *user_data);
91 92
92/* Interface */ 93/* Interface */
93np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client); 94np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client);
94np_error_t np_client_free(np_client_t client); 95np_error_t np_client_free(np_client_t client);
95np_error_t np_post_notification(np_client_t client, const char *notification); 96np_error_t np_post_notification(np_client_t client, const char *notification);
96np_error_t np_observe_notification(np_client_t client, const char *notification); 97np_error_t np_observe_notification(np_client_t client, const char *notification);
diff --git a/include/libimobiledevice/sbservices.h b/include/libimobiledevice/sbservices.h
index 08cb740..55d8b93 100644
--- a/include/libimobiledevice/sbservices.h
+++ b/include/libimobiledevice/sbservices.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32/** @name Error Codes */ 33/** @name Error Codes */
33/*@{*/ 34/*@{*/
@@ -57,7 +58,7 @@ typedef struct sbservices_client_private sbservices_client_private;
57typedef sbservices_client_private *sbservices_client_t; /**< The client handle. */ 58typedef sbservices_client_private *sbservices_client_t; /**< The client handle. */
58 59
59/* Interface */ 60/* Interface */
60sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client); 61sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client);
61sbservices_error_t sbservices_client_free(sbservices_client_t client); 62sbservices_error_t sbservices_client_free(sbservices_client_t client);
62sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version); 63sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version);
63sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate); 64sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate);
diff --git a/include/libimobiledevice/screenshotr.h b/include/libimobiledevice/screenshotr.h
index b3669ee..b9497d0 100644
--- a/include/libimobiledevice/screenshotr.h
+++ b/include/libimobiledevice/screenshotr.h
@@ -29,6 +29,7 @@ extern "C" {
29#endif 29#endif
30 30
31#include <libimobiledevice/libimobiledevice.h> 31#include <libimobiledevice/libimobiledevice.h>
32#include <libimobiledevice/lockdown.h>
32 33
33/** @name Error Codes */ 34/** @name Error Codes */
34/*@{*/ 35/*@{*/
@@ -47,7 +48,7 @@ typedef int16_t screenshotr_error_t;
47typedef struct screenshotr_client_private screenshotr_client_private; 48typedef struct screenshotr_client_private screenshotr_client_private;
48typedef screenshotr_client_private *screenshotr_client_t; /**< The client handle. */ 49typedef screenshotr_client_private *screenshotr_client_t; /**< The client handle. */
49 50
50screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, screenshotr_client_t * client); 51screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service, screenshotr_client_t * client);
51screenshotr_error_t screenshotr_client_free(screenshotr_client_t client); 52screenshotr_error_t screenshotr_client_free(screenshotr_client_t client);
52screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize); 53screenshotr_error_t screenshotr_take_screenshot(screenshotr_client_t client, char **imgdata, uint64_t *imgsize);
53 54
diff --git a/include/libimobiledevice/webinspector.h b/include/libimobiledevice/webinspector.h
index d499d72..ed9faad 100644
--- a/include/libimobiledevice/webinspector.h
+++ b/include/libimobiledevice/webinspector.h
@@ -28,6 +28,7 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
31 32
32#define WEBINSPECTOR_SERVICE_NAME "com.apple.webinspector" 33#define WEBINSPECTOR_SERVICE_NAME "com.apple.webinspector"
33 34
@@ -47,7 +48,7 @@ typedef int16_t webinspector_error_t;
47typedef struct webinspector_client_private webinspector_client_private; 48typedef struct webinspector_client_private webinspector_client_private;
48typedef webinspector_client_private *webinspector_client_t; /**< The client handle. */ 49typedef webinspector_client_private *webinspector_client_t; /**< The client handle. */
49 50
50webinspector_error_t webinspector_client_new(idevice_t device, uint16_t port, webinspector_client_t * client); 51webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client);
51webinspector_error_t webinspector_client_free(webinspector_client_t client); 52webinspector_error_t webinspector_client_free(webinspector_client_t client);
52 53
53webinspector_error_t webinspector_start_service(idevice_t device, webinspector_client_t * client); 54webinspector_error_t webinspector_start_service(idevice_t device, webinspector_client_t * client);
diff --git a/src/afc.c b/src/afc.c
index b405d52..b5228aa 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -119,7 +119,7 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_
119 * @see afc_client_new_from_connection 119 * @see afc_client_new_from_connection
120 * 120 *
121 * @param device The device to connect to. 121 * @param device The device to connect to.
122 * @param port The destination port. 122 * @param service The service descriptor returned by lockdownd_start_service.
123 * @param client Pointer that will be set to a newly allocated afc_client_t 123 * @param client Pointer that will be set to a newly allocated afc_client_t
124 * upon successful return. 124 * upon successful return.
125 * 125 *
@@ -127,17 +127,21 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_
127 * invalid, AFC_E_MUX_ERROR if the connection cannot be established, 127 * invalid, AFC_E_MUX_ERROR if the connection cannot be established,
128 * or AFC_E_NO_MEM if there is a memory allocation problem. 128 * or AFC_E_NO_MEM if there is a memory allocation problem.
129 */ 129 */
130afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client) 130afc_error_t afc_client_new(idevice_t device, lockdownd_service_descriptor_t service, afc_client_t * client)
131{ 131{
132 if (!device || port==0) 132 if (!device || service->port == 0)
133 return AFC_E_INVALID_ARG; 133 return AFC_E_INVALID_ARG;
134 134
135 /* attempt connection */ 135 /* attempt connection */
136 idevice_connection_t connection = NULL; 136 idevice_connection_t connection = NULL;
137 if (idevice_connect(device, port, &connection) != IDEVICE_E_SUCCESS) { 137 if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) {
138 return AFC_E_MUX_ERROR; 138 return AFC_E_MUX_ERROR;
139 } 139 }
140 140
141 /* enable SSL if requested */
142 if (service->ssl_enabled)
143 idevice_connection_enable_ssl(connection);
144
141 afc_error_t err = afc_client_new_from_connection(connection, client); 145 afc_error_t err = afc_client_new_from_connection(connection, client);
142 if (err != AFC_E_SUCCESS) { 146 if (err != AFC_E_SUCCESS) {
143 idevice_disconnect(connection); 147 idevice_disconnect(connection);
diff --git a/src/device_link_service.c b/src/device_link_service.c
index 5825f0c..ac89211 100644
--- a/src/device_link_service.c
+++ b/src/device_link_service.c
@@ -74,7 +74,7 @@ static int device_link_service_get_message(plist_t dl_msg, char **message)
74 * Creates a new device link service client. 74 * Creates a new device link service client.
75 * 75 *
76 * @param device The device to connect to. 76 * @param device The device to connect to.
77 * @param port Port on device to connect to. 77 * @param service The service descriptor returned by lockdownd_start_service.
78 * @param client Reference that will point to a newly allocated 78 * @param client Reference that will point to a newly allocated
79 * device_link_service_client_t upon successful return. 79 * device_link_service_client_t upon successful return.
80 * 80 *
@@ -82,14 +82,14 @@ static int device_link_service_get_message(plist_t dl_msg, char **message)
82 * DEVICE_LINK_SERVICE_E_INVALID_ARG when one of the parameters is invalid, 82 * DEVICE_LINK_SERVICE_E_INVALID_ARG when one of the parameters is invalid,
83 * or DEVICE_LINK_SERVICE_E_MUX_ERROR when the connection failed. 83 * or DEVICE_LINK_SERVICE_E_MUX_ERROR when the connection failed.
84 */ 84 */
85device_link_service_error_t device_link_service_client_new(idevice_t device, uint16_t port, device_link_service_client_t *client) 85device_link_service_error_t device_link_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, device_link_service_client_t *client)
86{ 86{
87 if (!device || port == 0 || !client || *client) { 87 if (!device || service->port == 0 || !client || *client) {
88 return DEVICE_LINK_SERVICE_E_INVALID_ARG; 88 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
89 } 89 }
90 90
91 property_list_service_client_t plistclient = NULL; 91 property_list_service_client_t plistclient = NULL;
92 if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 92 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
93 return DEVICE_LINK_SERVICE_E_MUX_ERROR; 93 return DEVICE_LINK_SERVICE_E_MUX_ERROR;
94 } 94 }
95 95
@@ -97,6 +97,10 @@ device_link_service_error_t device_link_service_client_new(idevice_t device, uin
97 device_link_service_client_t client_loc = (device_link_service_client_t) malloc(sizeof(struct device_link_service_client_private)); 97 device_link_service_client_t client_loc = (device_link_service_client_t) malloc(sizeof(struct device_link_service_client_private));
98 client_loc->parent = plistclient; 98 client_loc->parent = plistclient;
99 99
100 /* enable SSL if requested */
101 if (service->ssl_enabled)
102 property_list_service_enable_ssl(client_loc->parent);
103
100 /* all done, return success */ 104 /* all done, return success */
101 *client = client_loc; 105 *client = client_loc;
102 return DEVICE_LINK_SERVICE_E_SUCCESS; 106 return DEVICE_LINK_SERVICE_E_SUCCESS;
diff --git a/src/device_link_service.h b/src/device_link_service.h
index 8589428..d625341 100644
--- a/src/device_link_service.h
+++ b/src/device_link_service.h
@@ -41,7 +41,7 @@ struct device_link_service_client_private {
41 41
42typedef struct device_link_service_client_private *device_link_service_client_t; 42typedef struct device_link_service_client_private *device_link_service_client_t;
43 43
44device_link_service_error_t device_link_service_client_new(idevice_t device, uint16_t port, device_link_service_client_t *client); 44device_link_service_error_t device_link_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, device_link_service_client_t *client);
45device_link_service_error_t device_link_service_client_free(device_link_service_client_t client); 45device_link_service_error_t device_link_service_client_free(device_link_service_client_t client);
46device_link_service_error_t device_link_service_version_exchange(device_link_service_client_t client, uint64_t version_major, uint64_t version_minor); 46device_link_service_error_t device_link_service_version_exchange(device_link_service_client_t client, uint64_t version_major, uint64_t version_minor);
47device_link_service_error_t device_link_service_send_ping(device_link_service_client_t client, const char *message); 47device_link_service_error_t device_link_service_send_ping(device_link_service_client_t client, const char *message);
diff --git a/src/diagnostics_relay.c b/src/diagnostics_relay.c
index 7178952..3469ae4 100644
--- a/src/diagnostics_relay.c
+++ b/src/diagnostics_relay.c
@@ -73,7 +73,7 @@ static int diagnostics_relay_check_result(plist_t dict)
73 * Connects to the diagnostics_relay service on the specified device. 73 * Connects to the diagnostics_relay service on the specified device.
74 * 74 *
75 * @param device The device to connect to. 75 * @param device The device to connect to.
76 * @param port Destination port (usually given by lockdownd_start_service). 76 * @param service The service descriptor returned by lockdownd_start_service.
77 * @param client Reference that will point to a newly allocated 77 * @param client Reference that will point to a newly allocated
78 * diagnostics_relay_client_t upon successful return. 78 * diagnostics_relay_client_t upon successful return.
79 * 79 *
@@ -81,14 +81,14 @@ static int diagnostics_relay_check_result(plist_t dict)
81 * DIAGNOSTICS_RELAY_E_INVALID_ARG when one of the parameters is invalid, 81 * DIAGNOSTICS_RELAY_E_INVALID_ARG when one of the parameters is invalid,
82 * or DIAGNOSTICS_RELAY_E_MUX_ERROR when the connection failed. 82 * or DIAGNOSTICS_RELAY_E_MUX_ERROR when the connection failed.
83 */ 83 */
84diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, uint16_t port, diagnostics_relay_client_t *client) 84diagnostics_relay_error_t diagnostics_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, diagnostics_relay_client_t *client)
85{ 85{
86 if (!device || port == 0 || !client || *client) { 86 if (!device || service->port == 0 || !client || *client) {
87 return DIAGNOSTICS_RELAY_E_INVALID_ARG; 87 return DIAGNOSTICS_RELAY_E_INVALID_ARG;
88 } 88 }
89 89
90 property_list_service_client_t plistclient = NULL; 90 property_list_service_client_t plistclient = NULL;
91 if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 91 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
92 return DIAGNOSTICS_RELAY_E_MUX_ERROR; 92 return DIAGNOSTICS_RELAY_E_MUX_ERROR;
93 } 93 }
94 94
diff --git a/src/file_relay.c b/src/file_relay.c
index 680e28d..e72be66 100644
--- a/src/file_relay.c
+++ b/src/file_relay.c
@@ -28,7 +28,7 @@
28 * Connects to the file_relay service on the specified device. 28 * Connects to the file_relay service on the specified device.
29 * 29 *
30 * @param device The device to connect to. 30 * @param device The device to connect to.
31 * @param port Destination port (usually given by lockdownd_start_service). 31 * @param service The service descriptor returned by lockdownd_start_service.
32 * @param client Reference that will point to a newly allocated 32 * @param client Reference that will point to a newly allocated
33 * file_relay_client_t upon successful return. 33 * file_relay_client_t upon successful return.
34 * 34 *
@@ -36,14 +36,14 @@
36 * FILE_RELAY_E_INVALID_ARG when one of the parameters is invalid, 36 * FILE_RELAY_E_INVALID_ARG when one of the parameters is invalid,
37 * or FILE_RELAY_E_MUX_ERROR when the connection failed. 37 * or FILE_RELAY_E_MUX_ERROR when the connection failed.
38 */ 38 */
39file_relay_error_t file_relay_client_new(idevice_t device, uint16_t port, file_relay_client_t *client) 39file_relay_error_t file_relay_client_new(idevice_t device, lockdownd_service_descriptor_t service, file_relay_client_t *client)
40{ 40{
41 if (!device || port == 0 || !client || *client) { 41 if (!device || service->port == 0 || !client || *client) {
42 return FILE_RELAY_E_INVALID_ARG; 42 return FILE_RELAY_E_INVALID_ARG;
43 } 43 }
44 44
45 property_list_service_client_t plistclient = NULL; 45 property_list_service_client_t plistclient = NULL;
46 if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 46 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
47 return FILE_RELAY_E_MUX_ERROR; 47 return FILE_RELAY_E_MUX_ERROR;
48 } 48 }
49 49
diff --git a/src/house_arrest.c b/src/house_arrest.c
index 5baa76e..e0d7771 100644
--- a/src/house_arrest.c
+++ b/src/house_arrest.c
@@ -59,20 +59,20 @@ static house_arrest_error_t house_arrest_error(property_list_service_error_t err
59 * Connects to the house_arrest service on the specified device. 59 * Connects to the house_arrest service on the specified device.
60 * 60 *
61 * @param device The device to connect to. 61 * @param device The device to connect to.
62 * @param port Destination port (usually given by lockdownd_start_service). 62 * @param service The service descriptor returned by lockdownd_start_service.
63 * @param client Pointer that will point to a newly allocated 63 * @param client Pointer that will point to a newly allocated
64 * housearrest_client_t upon successful return. 64 * housearrest_client_t upon successful return.
65 * 65 *
66 * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when 66 * @return HOUSE_ARREST_E_SUCCESS on success, HOUSE_ARREST_E_INVALID_ARG when
67 * client is NULL, or an HOUSE_ARREST_E_* error code otherwise. 67 * client is NULL, or an HOUSE_ARREST_E_* error code otherwise.
68 */ 68 */
69house_arrest_error_t house_arrest_client_new(idevice_t device, uint16_t port, house_arrest_client_t *client) 69house_arrest_error_t house_arrest_client_new(idevice_t device, lockdownd_service_descriptor_t service, house_arrest_client_t *client)
70{ 70{
71 if (!device) 71 if (!device)
72 return HOUSE_ARREST_E_INVALID_ARG; 72 return HOUSE_ARREST_E_INVALID_ARG;
73 73
74 property_list_service_client_t plistclient = NULL; 74 property_list_service_client_t plistclient = NULL;
75 house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, port, &plistclient)); 75 house_arrest_error_t err = house_arrest_error(property_list_service_client_new(device, service, &plistclient));
76 if (err != HOUSE_ARREST_E_SUCCESS) { 76 if (err != HOUSE_ARREST_E_SUCCESS) {
77 return err; 77 return err;
78 } 78 }
diff --git a/src/installation_proxy.c b/src/installation_proxy.c
index bab6ab2..eacab9d 100644
--- a/src/installation_proxy.c
+++ b/src/installation_proxy.c
@@ -95,20 +95,20 @@ static instproxy_error_t instproxy_error(property_list_service_error_t err)
95 * Connects to the installation_proxy service on the specified device. 95 * Connects to the installation_proxy service on the specified device.
96 * 96 *
97 * @param device The device to connect to 97 * @param device The device to connect to
98 * @param port Destination port (usually given by lockdownd_start_service). 98 * @param service The service descriptor returned by lockdownd_start_service.
99 * @param client Pointer that will be set to a newly allocated 99 * @param client Pointer that will be set to a newly allocated
100 * instproxy_client_t upon successful return. 100 * instproxy_client_t upon successful return.
101 * 101 *
102 * @return INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error value 102 * @return INSTPROXY_E_SUCCESS on success, or an INSTPROXY_E_* error value
103 * when an error occured. 103 * when an error occured.
104 */ 104 */
105instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client) 105instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, instproxy_client_t *client)
106{ 106{
107 if (!device) 107 if (!device)
108 return INSTPROXY_E_INVALID_ARG; 108 return INSTPROXY_E_INVALID_ARG;
109 109
110 property_list_service_client_t plistclient = NULL; 110 property_list_service_client_t plistclient = NULL;
111 if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 111 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
112 return INSTPROXY_E_CONN_FAILED; 112 return INSTPROXY_E_CONN_FAILED;
113 } 113 }
114 114
diff --git a/src/lockdown.c b/src/lockdown.c
index e899baa..df1f60f 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -646,8 +646,13 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli
646 if (!client) 646 if (!client)
647 return LOCKDOWN_E_INVALID_ARG; 647 return LOCKDOWN_E_INVALID_ARG;
648 648
649 static struct lockdownd_service_descriptor service = {
650 .port = 0xf27e,
651 .ssl_enabled = 0
652 };
653
649 property_list_service_client_t plistclient = NULL; 654 property_list_service_client_t plistclient = NULL;
650 if (property_list_service_client_new(device, 0xf27e, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 655 if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
651 debug_info("could not connect to lockdownd (device %s)", device->udid); 656 debug_info("could not connect to lockdownd (device %s)", device->udid);
652 return LOCKDOWN_E_MUX_ERROR; 657 return LOCKDOWN_E_MUX_ERROR;
653 } 658 }
@@ -1494,17 +1499,17 @@ lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char
1494 * Requests to start a service and retrieve it's port on success. 1499 * Requests to start a service and retrieve it's port on success.
1495 * 1500 *
1496 * @param client The lockdownd client 1501 * @param client The lockdownd client
1497 * @param service The name of the service to start 1502 * @param identifier The identifier of the service to start
1498 * @param port The port number the service was started on 1503 * @param descriptor The service descriptor on success or NULL on failure
1499 1504
1500 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter 1505 * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter
1501 * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known 1506 * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known
1502 * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because 1507 * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because
1503 * started by the device 1508 * started by the device
1504 */ 1509 */
1505lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port) 1510lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service)
1506{ 1511{
1507 if (!client || !service || !port) 1512 if (!client || !identifier || !service)
1508 return LOCKDOWN_E_INVALID_ARG; 1513 return LOCKDOWN_E_INVALID_ARG;
1509 1514
1510 char *host_id = NULL; 1515 char *host_id = NULL;
@@ -1524,7 +1529,7 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
1524 dict = plist_new_dict(); 1529 dict = plist_new_dict();
1525 plist_dict_add_label(dict, client->label); 1530 plist_dict_add_label(dict, client->label);
1526 plist_dict_insert_item(dict,"Request", plist_new_string("StartService")); 1531 plist_dict_insert_item(dict,"Request", plist_new_string("StartService"));
1527 plist_dict_insert_item(dict,"Service", plist_new_string(service)); 1532 plist_dict_insert_item(dict,"Service", plist_new_string(identifier));
1528 1533
1529 /* send to device */ 1534 /* send to device */
1530 ret = lockdownd_send(client, dict); 1535 ret = lockdownd_send(client, dict);
@@ -1542,20 +1547,34 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
1542 if (!dict) 1547 if (!dict)
1543 return LOCKDOWN_E_PLIST_ERROR; 1548 return LOCKDOWN_E_PLIST_ERROR;
1544 1549
1550 if (*service == NULL)
1551 *service = (lockdownd_service_descriptor_t)malloc(sizeof(struct lockdownd_service_descriptor));
1552 (*service)->port = 0;
1553 (*service)->ssl_enabled = 0;
1554
1545 ret = LOCKDOWN_E_UNKNOWN_ERROR; 1555 ret = LOCKDOWN_E_UNKNOWN_ERROR;
1546 if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { 1556 if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) {
1547 plist_t port_value_node = plist_dict_get_item(dict, "Port"); 1557 /* read service port number */
1548 1558 plist_t node = plist_dict_get_item(dict, "Port");
1549 if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) { 1559 if (node && (plist_get_node_type(node) == PLIST_UINT)) {
1550 uint64_t port_value = 0; 1560 uint64_t port_value = 0;
1551 plist_get_uint_val(port_value_node, &port_value); 1561 plist_get_uint_val(node, &port_value);
1552 1562
1553 if (port_value) { 1563 if (port_value) {
1554 port_loc = port_value; 1564 port_loc = port_value;
1555 ret = LOCKDOWN_E_SUCCESS; 1565 ret = LOCKDOWN_E_SUCCESS;
1556 } 1566 }
1557 if (port && ret == LOCKDOWN_E_SUCCESS) 1567 if (port_loc && ret == LOCKDOWN_E_SUCCESS) {
1558 *port = port_loc; 1568 (*service)->port = port_loc;
1569 }
1570 }
1571
1572 /* check if the service requires SSL */
1573 node = plist_dict_get_item(dict, "EnableServiceSSL");
1574 if (node && (plist_get_node_type(node) == PLIST_BOOLEAN)) {
1575 uint8_t b = 0;
1576 plist_get_bool_val(node, &b);
1577 (*service)->ssl_enabled = b;
1559 } 1578 }
1560 } else { 1579 } else {
1561 ret = LOCKDOWN_E_START_SERVICE_FAILED; 1580 ret = LOCKDOWN_E_START_SERVICE_FAILED;
@@ -1785,3 +1804,18 @@ lockdownd_error_t lockdownd_data_classes_free(char **classes)
1785 } 1804 }
1786 return LOCKDOWN_E_SUCCESS; 1805 return LOCKDOWN_E_SUCCESS;
1787} 1806}
1807
1808/**
1809 * Frees memory of a service descriptor as returned by lockdownd_start_service()
1810 *
1811 * @param sevice A service descriptor instance to free.
1812 *
1813 * @return LOCKDOWN_E_SUCCESS on success
1814 */
1815lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service)
1816{
1817 if (service)
1818 free(service);
1819
1820 return LOCKDOWN_E_SUCCESS;
1821}
diff --git a/src/misagent.c b/src/misagent.c
index 45f1391..c624603 100644
--- a/src/misagent.c
+++ b/src/misagent.c
@@ -91,20 +91,20 @@ static misagent_error_t misagent_check_result(plist_t response, int* status_code
91 * Connects to the misagent service on the specified device. 91 * Connects to the misagent service on the specified device.
92 * 92 *
93 * @param device The device to connect to. 93 * @param device The device to connect to.
94 * @param port Destination port (usually given by lockdownd_start_service). 94 * @param service The service descriptor returned by lockdownd_start_service.
95 * @param client Pointer that will point to a newly allocated 95 * @param client Pointer that will point to a newly allocated
96 * misagent_client_t upon successful return. 96 * misagent_client_t upon successful return.
97 * 97 *
98 * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when 98 * @return MISAGENT_E_SUCCESS on success, MISAGENT_E_INVALID_ARG when
99 * client is NULL, or an MISAGENT_E_* error code otherwise. 99 * client is NULL, or an MISAGENT_E_* error code otherwise.
100 */ 100 */
101misagent_error_t misagent_client_new(idevice_t device, uint16_t port, misagent_client_t *client) 101misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client)
102{ 102{
103 if (!device) 103 if (!device)
104 return MISAGENT_E_INVALID_ARG; 104 return MISAGENT_E_INVALID_ARG;
105 105
106 property_list_service_client_t plistclient = NULL; 106 property_list_service_client_t plistclient = NULL;
107 misagent_error_t err = misagent_error(property_list_service_client_new(device, port, &plistclient)); 107 misagent_error_t err = misagent_error(property_list_service_client_new(device, service, &plistclient));
108 if (err != MISAGENT_E_SUCCESS) { 108 if (err != MISAGENT_E_SUCCESS) {
109 return err; 109 return err;
110 } 110 }
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c
index 557fbda..3e31ef4 100644
--- a/src/mobile_image_mounter.c
+++ b/src/mobile_image_mounter.c
@@ -87,7 +87,7 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser
87 * Connects to the mobile_image_mounter service on the specified device. 87 * Connects to the mobile_image_mounter service on the specified device.
88 * 88 *
89 * @param device The device to connect to. 89 * @param device The device to connect to.
90 * @param port Destination port (usually given by lockdownd_start_service). 90 * @param service The service descriptor returned by lockdownd_start_service.
91 * @param client Pointer that will be set to a newly allocated 91 * @param client Pointer that will be set to a newly allocated
92 * mobile_image_mounter_client_t upon successful return. 92 * mobile_image_mounter_client_t upon successful return.
93 * 93 *
@@ -96,13 +96,13 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser
96 * or MOBILE_IMAGE_MOUNTER_E_CONN_FAILED if the connection to the 96 * or MOBILE_IMAGE_MOUNTER_E_CONN_FAILED if the connection to the
97 * device could not be established. 97 * device could not be established.
98 */ 98 */
99mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) 99mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdownd_service_descriptor_t service, mobile_image_mounter_client_t *client)
100{ 100{
101 if (!device) 101 if (!device)
102 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; 102 return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG;
103 103
104 property_list_service_client_t plistclient = NULL; 104 property_list_service_client_t plistclient = NULL;
105 if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 105 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
106 return MOBILE_IMAGE_MOUNTER_E_CONN_FAILED; 106 return MOBILE_IMAGE_MOUNTER_E_CONN_FAILED;
107 } 107 }
108 108
diff --git a/src/mobilebackup.c b/src/mobilebackup.c
index 78f9a5c..ab4dec0 100644
--- a/src/mobilebackup.c
+++ b/src/mobilebackup.c
@@ -64,7 +64,7 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)
64 * Connects to the mobilebackup service on the specified device. 64 * Connects to the mobilebackup service on the specified device.
65 * 65 *
66 * @param device The device to connect to. 66 * @param device The device to connect to.
67 * @param port Destination port (usually given by lockdownd_start_service). 67 * @param service The service descriptor returned by lockdownd_start_service.
68 * @param client Pointer that will be set to a newly allocated 68 * @param client Pointer that will be set to a newly allocated
69 * mobilebackup_client_t upon successful return. 69 * mobilebackup_client_t upon successful return.
70 * 70 *
@@ -72,14 +72,14 @@ static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)
72 * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if 72 * or more parameters are invalid, or DEVICE_LINK_SERVICE_E_BAD_VERSION if
73 * the mobilebackup version on the device is newer. 73 * the mobilebackup version on the device is newer.
74 */ 74 */
75mobilebackup_error_t mobilebackup_client_new(idevice_t device, uint16_t port, 75mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service,
76 mobilebackup_client_t * client) 76 mobilebackup_client_t * client)
77{ 77{
78 if (!device || port == 0 || !client || *client) 78 if (!device || service->port == 0 || !client || *client)
79 return MOBILEBACKUP_E_INVALID_ARG; 79 return MOBILEBACKUP_E_INVALID_ARG;
80 80
81 device_link_service_client_t dlclient = NULL; 81 device_link_service_client_t dlclient = NULL;
82 mobilebackup_error_t ret = mobilebackup_error(device_link_service_client_new(device, port, &dlclient)); 82 mobilebackup_error_t ret = mobilebackup_error(device_link_service_client_new(device, service, &dlclient));
83 if (ret != MOBILEBACKUP_E_SUCCESS) { 83 if (ret != MOBILEBACKUP_E_SUCCESS) {
84 return ret; 84 return ret;
85 } 85 }
diff --git a/src/mobilebackup2.c b/src/mobilebackup2.c
index 2089c87..bcf5944 100644
--- a/src/mobilebackup2.c
+++ b/src/mobilebackup2.c
@@ -65,7 +65,7 @@ static mobilebackup2_error_t mobilebackup2_error(device_link_service_error_t err
65 * Connects to the mobilebackup2 service on the specified device. 65 * Connects to the mobilebackup2 service on the specified device.
66 * 66 *
67 * @param device The device to connect to. 67 * @param device The device to connect to.
68 * @param port Destination port (usually given by lockdownd_start_service). 68 * @param service The service descriptor returned by lockdownd_start_service.
69 * @param client Pointer that will be set to a newly allocated 69 * @param client Pointer that will be set to a newly allocated
70 * mobilebackup2_client_t upon successful return. 70 * mobilebackup2_client_t upon successful return.
71 * 71 *
@@ -73,14 +73,14 @@ static mobilebackup2_error_t mobilebackup2_error(device_link_service_error_t err
73 * if one or more parameter is invalid, or MOBILEBACKUP2_E_BAD_VERSION 73 * if one or more parameter is invalid, or MOBILEBACKUP2_E_BAD_VERSION
74 * if the mobilebackup2 version on the device is newer. 74 * if the mobilebackup2 version on the device is newer.
75 */ 75 */
76mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, uint16_t port, 76mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service,
77 mobilebackup2_client_t * client) 77 mobilebackup2_client_t * client)
78{ 78{
79 if (!device || port == 0 || !client || *client) 79 if (!device || service->port == 0 || !client || *client)
80 return MOBILEBACKUP2_E_INVALID_ARG; 80 return MOBILEBACKUP2_E_INVALID_ARG;
81 81
82 device_link_service_client_t dlclient = NULL; 82 device_link_service_client_t dlclient = NULL;
83 mobilebackup2_error_t ret = mobilebackup2_error(device_link_service_client_new(device, port, &dlclient)); 83 mobilebackup2_error_t ret = mobilebackup2_error(device_link_service_client_new(device, service, &dlclient));
84 if (ret != MOBILEBACKUP2_E_SUCCESS) { 84 if (ret != MOBILEBACKUP2_E_SUCCESS) {
85 return ret; 85 return ret;
86 } 86 }
diff --git a/src/mobilesync.c b/src/mobilesync.c
index 39b1da8..4fe24b2 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -69,7 +69,7 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)
69 * Connects to the mobilesync service on the specified device. 69 * Connects to the mobilesync service on the specified device.
70 * 70 *
71 * @param device The device to connect to. 71 * @param device The device to connect to.
72 * @param port Destination port (usually given by lockdownd_start_service()). 72 * @param service The service descriptor returned by lockdownd_start_service.
73 * @param client Pointer that will be set to a newly allocated 73 * @param client Pointer that will be set to a newly allocated
74 * #mobilesync_client_t upon successful return. 74 * #mobilesync_client_t upon successful return.
75 * 75 *
@@ -78,14 +78,14 @@ static mobilesync_error_t mobilesync_error(device_link_service_error_t err)
78 * @retval DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on 78 * @retval DEVICE_LINK_SERVICE_E_BAD_VERSION if the mobilesync version on
79 * the device is newer. 79 * the device is newer.
80 */ 80 */
81mobilesync_error_t mobilesync_client_new(idevice_t device, uint16_t port, 81mobilesync_error_t mobilesync_client_new(idevice_t device, lockdownd_service_descriptor_t service,
82 mobilesync_client_t * client) 82 mobilesync_client_t * client)
83{ 83{
84 if (!device || port == 0 || !client || *client) 84 if (!device || service->port == 0 || !client || *client)
85 return MOBILESYNC_E_INVALID_ARG; 85 return MOBILESYNC_E_INVALID_ARG;
86 86
87 device_link_service_client_t dlclient = NULL; 87 device_link_service_client_t dlclient = NULL;
88 mobilesync_error_t ret = mobilesync_error(device_link_service_client_new(device, port, &dlclient)); 88 mobilesync_error_t ret = mobilesync_error(device_link_service_client_new(device, service, &dlclient));
89 if (ret != MOBILESYNC_E_SUCCESS) { 89 if (ret != MOBILESYNC_E_SUCCESS) {
90 return ret; 90 return ret;
91 } 91 }
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index 6e09840..8fb9ad0 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -98,7 +98,7 @@ static np_error_t np_error(property_list_service_error_t err)
98 * Connects to the notification_proxy on the specified device. 98 * Connects to the notification_proxy on the specified device.
99 * 99 *
100 * @param device The device to connect to. 100 * @param device The device to connect to.
101 * @param port Destination port (usually given by lockdownd_start_service). 101 * @param service The service descriptor returned by lockdownd_start_service.
102 * @param client Pointer that will be set to a newly allocated np_client_t 102 * @param client Pointer that will be set to a newly allocated np_client_t
103 * upon successful return. 103 * upon successful return.
104 * 104 *
@@ -106,13 +106,13 @@ static np_error_t np_error(property_list_service_error_t err)
106 * or NP_E_CONN_FAILED when the connection to the device could not be 106 * or NP_E_CONN_FAILED when the connection to the device could not be
107 * established. 107 * established.
108 */ 108 */
109np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) 109np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t service, np_client_t *client)
110{ 110{
111 if (!device) 111 if (!device)
112 return NP_E_INVALID_ARG; 112 return NP_E_INVALID_ARG;
113 113
114 property_list_service_client_t plistclient = NULL; 114 property_list_service_client_t plistclient = NULL;
115 if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 115 if (property_list_service_client_new(device, service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
116 return NP_E_CONN_FAILED; 116 return NP_E_CONN_FAILED;
117 } 117 }
118 118
diff --git a/src/property_list_service.c b/src/property_list_service.c
index c9a8edf..15adbc8 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -57,8 +57,7 @@ static property_list_service_error_t idevice_to_property_list_service_error(idev
57 * Creates a new property list service for the specified port. 57 * Creates a new property list service for the specified port.
58 * 58 *
59 * @param device The device to connect to. 59 * @param device The device to connect to.
60 * @param port The port on the device to connect to, usually opened by a call to 60 * @param service The service descriptor returned by lockdownd_start_service.
61 * lockdownd_start_service.
62 * @param client Pointer that will be set to a newly allocated 61 * @param client Pointer that will be set to a newly allocated
63 * property_list_service_client_t upon successful return. 62 * property_list_service_client_t upon successful return.
64 * 63 *
@@ -66,14 +65,14 @@ static property_list_service_error_t idevice_to_property_list_service_error(idev
66 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when one of the arguments is invalid, 65 * PROPERTY_LIST_SERVICE_E_INVALID_ARG when one of the arguments is invalid,
67 * or PROPERTY_LIST_SERVICE_E_MUX_ERROR when connecting to the device failed. 66 * or PROPERTY_LIST_SERVICE_E_MUX_ERROR when connecting to the device failed.
68 */ 67 */
69property_list_service_error_t property_list_service_client_new(idevice_t device, uint16_t port, property_list_service_client_t *client) 68property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client)
70{ 69{
71 if (!device || port == 0 || !client || *client) 70 if (!device || (service->port == 0) || !client || *client)
72 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 71 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
73 72
74 /* Attempt connection */ 73 /* Attempt connection */
75 idevice_connection_t connection = NULL; 74 idevice_connection_t connection = NULL;
76 if (idevice_connect(device, port, &connection) != IDEVICE_E_SUCCESS) { 75 if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) {
77 return PROPERTY_LIST_SERVICE_E_MUX_ERROR; 76 return PROPERTY_LIST_SERVICE_E_MUX_ERROR;
78 } 77 }
79 78
@@ -81,8 +80,12 @@ property_list_service_error_t property_list_service_client_new(idevice_t device,
81 property_list_service_client_t client_loc = (property_list_service_client_t)malloc(sizeof(struct property_list_service_client_private)); 80 property_list_service_client_t client_loc = (property_list_service_client_t)malloc(sizeof(struct property_list_service_client_private));
82 client_loc->connection = connection; 81 client_loc->connection = connection;
83 82
84 *client = client_loc; 83 /* enable SSL if requested */
84 if (service->ssl_enabled == 1)
85 property_list_service_enable_ssl(client_loc);
85 86
87 /* all done, return success */
88 *client = client_loc;
86 return PROPERTY_LIST_SERVICE_E_SUCCESS; 89 return PROPERTY_LIST_SERVICE_E_SUCCESS;
87} 90}
88 91
diff --git a/src/property_list_service.h b/src/property_list_service.h
index 037f9aa..db1c09d 100644
--- a/src/property_list_service.h
+++ b/src/property_list_service.h
@@ -21,6 +21,7 @@
21#ifndef PROPERTY_LIST_SERVICE_H 21#ifndef PROPERTY_LIST_SERVICE_H
22#define PROPERTY_LIST_SERVICE_H 22#define PROPERTY_LIST_SERVICE_H
23 23
24#include <libimobiledevice/lockdown.h>
24#include "idevice.h" 25#include "idevice.h"
25 26
26/* Error Codes */ 27/* Error Codes */
@@ -41,7 +42,7 @@ typedef struct property_list_service_client_private *property_list_service_clien
41typedef int16_t property_list_service_error_t; 42typedef int16_t property_list_service_error_t;
42 43
43/* creation and destruction */ 44/* creation and destruction */
44property_list_service_error_t property_list_service_client_new(idevice_t device, uint16_t port, property_list_service_client_t *client); 45property_list_service_error_t property_list_service_client_new(idevice_t device, lockdownd_service_descriptor_t service, property_list_service_client_t *client);
45property_list_service_error_t property_list_service_client_free(property_list_service_client_t client); 46property_list_service_error_t property_list_service_client_free(property_list_service_client_t client);
46 47
47/* sending */ 48/* sending */
diff --git a/src/restore.c b/src/restore.c
index 3474091..1b2ff78 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -368,8 +368,13 @@ restored_error_t restored_client_new(idevice_t device, restored_client_t *client
368 368
369 restored_error_t ret = RESTORE_E_SUCCESS; 369 restored_error_t ret = RESTORE_E_SUCCESS;
370 370
371 static struct lockdownd_service_descriptor service = {
372 .port = 0xf27e,
373 .ssl_enabled = 0
374 };
375
371 property_list_service_client_t plistclient = NULL; 376 property_list_service_client_t plistclient = NULL;
372 if (property_list_service_client_new(device, 0xf27e, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { 377 if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
373 debug_info("could not connect to restored (device %s)", device->udid); 378 debug_info("could not connect to restored (device %s)", device->udid);
374 return RESTORE_E_MUX_ERROR; 379 return RESTORE_E_MUX_ERROR;
375 } 380 }
diff --git a/src/sbservices.c b/src/sbservices.c
index 2c17d8c..6b1a4d1 100644
--- a/src/sbservices.c
+++ b/src/sbservices.c
@@ -88,20 +88,20 @@ static sbservices_error_t sbservices_error(property_list_service_error_t err)
88 * Connects to the springboardservices service on the specified device. 88 * Connects to the springboardservices service on the specified device.
89 * 89 *
90 * @param device The device to connect to. 90 * @param device The device to connect to.
91 * @param port Destination port (usually given by lockdownd_start_service). 91 * @param service The service descriptor returned by lockdownd_start_service.
92 * @param client Pointer that will point to a newly allocated 92 * @param client Pointer that will point to a newly allocated
93 * sbservices_client_t upon successful return. 93 * sbservices_client_t upon successful return.
94 * 94 *
95 * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when 95 * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when
96 * client is NULL, or an SBSERVICES_E_* error code otherwise. 96 * client is NULL, or an SBSERVICES_E_* error code otherwise.
97 */ 97 */
98sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) 98sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_descriptor_t service, sbservices_client_t *client)
99{ 99{
100 if (!device) 100 if (!device)
101 return SBSERVICES_E_INVALID_ARG; 101 return SBSERVICES_E_INVALID_ARG;
102 102
103 property_list_service_client_t plistclient = NULL; 103 property_list_service_client_t plistclient = NULL;
104 sbservices_error_t err = sbservices_error(property_list_service_client_new(device, port, &plistclient)); 104 sbservices_error_t err = sbservices_error(property_list_service_client_new(device, service, &plistclient));
105 if (err != SBSERVICES_E_SUCCESS) { 105 if (err != SBSERVICES_E_SUCCESS) {
106 return err; 106 return err;
107 } 107 }
diff --git a/src/screenshotr.c b/src/screenshotr.c
index 063d282..e2bc979 100644
--- a/src/screenshotr.c
+++ b/src/screenshotr.c
@@ -62,7 +62,7 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err)
62 * Connects to the screenshotr service on the specified device. 62 * Connects to the screenshotr service on the specified device.
63 * 63 *
64 * @param device The device to connect to. 64 * @param device The device to connect to.
65 * @param port Destination port (usually given by lockdownd_start_service). 65 * @param service The service descriptor returned by lockdownd_start_service.
66 * @param client Pointer that will be set to a newly allocated 66 * @param client Pointer that will be set to a newly allocated
67 * screenshotr_client_t upon successful return. 67 * screenshotr_client_t upon successful return.
68 * 68 *
@@ -73,14 +73,14 @@ static screenshotr_error_t screenshotr_error(device_link_service_error_t err)
73 * or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the 73 * or more parameters are invalid, or SCREENSHOTR_E_CONN_FAILED if the
74 * connection to the device could not be established. 74 * connection to the device could not be established.
75 */ 75 */
76screenshotr_error_t screenshotr_client_new(idevice_t device, uint16_t port, 76screenshotr_error_t screenshotr_client_new(idevice_t device, lockdownd_service_descriptor_t service,
77 screenshotr_client_t * client) 77 screenshotr_client_t * client)
78{ 78{
79 if (!device || port == 0 || !client || *client) 79 if (!device || service->port == 0 || !client || *client)
80 return SCREENSHOTR_E_INVALID_ARG; 80 return SCREENSHOTR_E_INVALID_ARG;
81 81
82 device_link_service_client_t dlclient = NULL; 82 device_link_service_client_t dlclient = NULL;
83 screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, port, &dlclient)); 83 screenshotr_error_t ret = screenshotr_error(device_link_service_client_new(device, service, &dlclient));
84 if (ret != SCREENSHOTR_E_SUCCESS) { 84 if (ret != SCREENSHOTR_E_SUCCESS) {
85 return ret; 85 return ret;
86 } 86 }
diff --git a/src/webinspector.c b/src/webinspector.c
index c3d57cc..eb12d4d 100644
--- a/src/webinspector.c
+++ b/src/webinspector.c
@@ -62,7 +62,7 @@ static webinspector_error_t webinspector_error(property_list_service_error_t err
62 * Connects to the webinspector service on the specified device. 62 * Connects to the webinspector service on the specified device.
63 * 63 *
64 * @param device The device to connect to. 64 * @param device The device to connect to.
65 * @param port Destination port (usually given by lockdownd_start_service). 65 * @param service The service descriptor returned by lockdownd_start_service.
66 * @param client Pointer that will point to a newly allocated 66 * @param client Pointer that will point to a newly allocated
67 * webinspector_client_t upon successful return. Must be freed using 67 * webinspector_client_t upon successful return. Must be freed using
68 * webinspector_client_free() after use. 68 * webinspector_client_free() after use.
@@ -70,19 +70,19 @@ static webinspector_error_t webinspector_error(property_list_service_error_t err
70 * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when 70 * @return WEBINSPECTOR_E_SUCCESS on success, WEBINSPECTOR_E_INVALID_ARG when
71 * client is NULL, or an WEBINSPECTOR_E_* error code otherwise. 71 * client is NULL, or an WEBINSPECTOR_E_* error code otherwise.
72 */ 72 */
73webinspector_error_t webinspector_client_new(idevice_t device, uint16_t port, webinspector_client_t * client) 73webinspector_error_t webinspector_client_new(idevice_t device, lockdownd_service_descriptor_t service, webinspector_client_t * client)
74{ 74{
75 *client = NULL; 75 *client = NULL;
76 76
77 debug_info("Creating webinspector_client, port = %d.", port); 77 debug_info("Creating webinspector_client, port = %d.", service->port);
78 78
79 if (!device || port == 0 || !client || *client) { 79 if (!device || service->port == 0 || !client || *client) {
80 debug_info("Incorrect parameter passed to webinspector_client_new."); 80 debug_info("Incorrect parameter passed to webinspector_client_new.");
81 return WEBINSPECTOR_E_INVALID_ARG; 81 return WEBINSPECTOR_E_INVALID_ARG;
82 } 82 }
83 83
84 property_list_service_client_t plclient = NULL; 84 property_list_service_client_t plclient = NULL;
85 webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, port, &plclient)); 85 webinspector_error_t ret = webinspector_error(property_list_service_client_new(device, service, &plclient));
86 if (ret != WEBINSPECTOR_E_SUCCESS) { 86 if (ret != WEBINSPECTOR_E_SUCCESS) {
87 debug_info("Creating a property list client failed. Error: %i", ret); 87 debug_info("Creating a property list client failed. Error: %i", ret);
88 return ret; 88 return ret;
@@ -118,22 +118,27 @@ webinspector_error_t webinspector_start_service(idevice_t device, webinspector_c
118 debug_info("Could not create a lockdown client."); 118 debug_info("Could not create a lockdown client.");
119 return WEBINSPECTOR_E_UNKNOWN_ERROR; 119 return WEBINSPECTOR_E_UNKNOWN_ERROR;
120 } 120 }
121 121
122 uint16_t port = 0; 122 lockdownd_service_descriptor_t service = NULL;
123 lockdownd_start_service(lckd, WEBINSPECTOR_SERVICE_NAME, &port); 123 lockdownd_start_service(lckd, WEBINSPECTOR_SERVICE_NAME, &service);
124 lockdownd_client_free(lckd); 124 lockdownd_client_free(lckd);
125 125
126 if (port <= 0) { 126 if (service->port <= 0) {
127 debug_info("Could not start webinspector service!"); 127 debug_info("Could not start webinspector service!");
128 return WEBINSPECTOR_E_UNKNOWN_ERROR; 128 return WEBINSPECTOR_E_UNKNOWN_ERROR;
129 } 129 }
130 130
131 webinspector_error_t res = webinspector_client_new(device, port, client); 131 webinspector_error_t res = webinspector_client_new(device, service, client);
132 if (res != WEBINSPECTOR_E_SUCCESS) { 132 if (res != WEBINSPECTOR_E_SUCCESS) {
133 debug_info("Could not connect to webinspector! Port: %i, error: %i", port, res); 133 debug_info("Could not connect to webinspector! Port: %i, error: %i", service->port, res);
134 return res; 134 return res;
135 } 135 }
136 136
137 if (service) {
138 lockdownd_service_descriptor_free(service);
139 service = NULL;
140 }
141
137 return WEBINSPECTOR_E_SUCCESS; 142 return WEBINSPECTOR_E_SUCCESS;
138} 143}
139 144
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
745 745
746static void do_post_notification(const char *notification) 746static void do_post_notification(const char *notification)
747{ 747{
748 uint16_t nport = 0; 748 lockdownd_service_descriptor_t service = NULL;
749 np_client_t np; 749 np_client_t np;
750 750
751 if (!client) { 751 if (!client) {
@@ -754,9 +754,9 @@ static void do_post_notification(const char *notification)
754 } 754 }
755 } 755 }
756 756
757 lockdownd_start_service(client, NP_SERVICE_NAME, &nport); 757 lockdownd_start_service(client, NP_SERVICE_NAME, &service);
758 if (nport) { 758 if (service->port) {
759 np_client_new(device, nport, &np); 759 np_client_new(device, service, &np);
760 if (np) { 760 if (np) {
761 np_post_notification(np, notification); 761 np_post_notification(np, notification);
762 np_client_free(np); 762 np_client_free(np);
@@ -764,6 +764,11 @@ static void do_post_notification(const char *notification)
764 } else { 764 } else {
765 printf("Could not start %s\n", NP_SERVICE_NAME); 765 printf("Could not start %s\n", NP_SERVICE_NAME);
766 } 766 }
767
768 if (service) {
769 lockdownd_service_descriptor_free(service);
770 service = NULL;
771 }
767} 772}
768 773
769static void print_progress(double progress) 774static void print_progress(double progress)
@@ -819,7 +824,7 @@ int main(int argc, char *argv[])
819 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; 824 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
820 int i; 825 int i;
821 char* udid = NULL; 826 char* udid = NULL;
822 uint16_t port = 0; 827 lockdownd_service_descriptor_t service = NULL;
823 int cmd = -1; 828 int cmd = -1;
824 int is_full_backup = 0; 829 int is_full_backup = 0;
825 char *backup_directory = NULL; 830 char *backup_directory = NULL;
@@ -931,9 +936,9 @@ int main(int argc, char *argv[])
931 936
932 /* start notification_proxy */ 937 /* start notification_proxy */
933 np_client_t np = NULL; 938 np_client_t np = NULL;
934 ret = lockdownd_start_service(client, NP_SERVICE_NAME, &port); 939 ret = lockdownd_start_service(client, NP_SERVICE_NAME, &service);
935 if ((ret == LOCKDOWN_E_SUCCESS) && port) { 940 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) {
936 np_client_new(device, port, &np); 941 np_client_new(device, service, &np);
937 np_set_notify_callback(np, notify_cb, NULL); 942 np_set_notify_callback(np, notify_cb, NULL);
938 const char *noties[5] = { 943 const char *noties[5] = {
939 NP_SYNC_CANCEL_REQUEST, 944 NP_SYNC_CANCEL_REQUEST,
@@ -947,22 +952,37 @@ int main(int argc, char *argv[])
947 printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME); 952 printf("ERROR: Could not start service %s.\n", NP_SERVICE_NAME);
948 } 953 }
949 954
955 if (service) {
956 lockdownd_service_descriptor_free(service);
957 service = NULL;
958 }
959
950 afc_client_t afc = NULL; 960 afc_client_t afc = NULL;
951 if (cmd == CMD_BACKUP) { 961 if (cmd == CMD_BACKUP) {
952 /* start AFC, we need this for the lock file */ 962 /* start AFC, we need this for the lock file */
953 port = 0; 963 service->port = 0;
954 ret = lockdownd_start_service(client, "com.apple.afc", &port); 964 service->ssl_enabled = 0;
955 if ((ret == LOCKDOWN_E_SUCCESS) && port) { 965 ret = lockdownd_start_service(client, "com.apple.afc", &service);
956 afc_client_new(device, port, &afc); 966 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) {
967 afc_client_new(device, service, &afc);
957 } 968 }
958 } 969 }
959 970
971 if (service) {
972 lockdownd_service_descriptor_free(service);
973 service = NULL;
974 }
975
960 /* start mobilebackup service and retrieve port */ 976 /* start mobilebackup service and retrieve port */
961 port = 0; 977 ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &service);
962 ret = lockdownd_start_service(client, MOBILEBACKUP_SERVICE_NAME, &port); 978 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) {
963 if ((ret == LOCKDOWN_E_SUCCESS) && port) { 979 printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, service->port);
964 printf("Started \"%s\" service on port %d.\n", MOBILEBACKUP_SERVICE_NAME, port); 980 mobilebackup_client_new(device, service, &mobilebackup);
965 mobilebackup_client_new(device, port, &mobilebackup); 981
982 if (service) {
983 lockdownd_service_descriptor_free(service);
984 service = NULL;
985 }
966 986
967 /* check abort conditions */ 987 /* check abort conditions */
968 if (quit_flag > 0) { 988 if (quit_flag > 0) {
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
480static void do_post_notification(idevice_t device, const char *notification) 480static 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
503static void print_progress_real(double progress, int flush) 508static 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};
diff --git a/tools/idevicedebugserverproxy.c b/tools/idevicedebugserverproxy.c
index 3253e6a..32438ad 100644
--- a/tools/idevicedebugserverproxy.c
+++ b/tools/idevicedebugserverproxy.c
@@ -228,7 +228,7 @@ int main(int argc, char *argv[])
228 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; 228 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
229 thread_t th; 229 thread_t th;
230 const char* udid = NULL; 230 const char* udid = NULL;
231 uint16_t port = 0; 231 lockdownd_service_descriptor_t service = NULL;
232 uint16_t local_port = 0; 232 uint16_t local_port = 0;
233 int result = EXIT_SUCCESS; 233 int result = EXIT_SUCCESS;
234 int i; 234 int i;
@@ -297,14 +297,14 @@ int main(int argc, char *argv[])
297 goto leave_cleanup; 297 goto leave_cleanup;
298 } 298 }
299 299
300 if ((lockdownd_start_service(lockdown, "com.apple.debugserver", &port) != LOCKDOWN_E_SUCCESS) || !port) { 300 if ((lockdownd_start_service(lockdown, "com.apple.debugserver", &service) != LOCKDOWN_E_SUCCESS) || !service->port) {
301 fprintf(stderr, "Could not start com.apple.debugserver!\nPlease make sure to mount the developer disk image first.\n"); 301 fprintf(stderr, "Could not start com.apple.debugserver!\nPlease make sure to mount the developer disk image first.\n");
302 result = EXIT_FAILURE; 302 result = EXIT_FAILURE;
303 goto leave_cleanup; 303 goto leave_cleanup;
304 } 304 }
305 305
306 if (idevice_connect(device, port, &connection) != IDEVICE_E_SUCCESS) { 306 if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) {
307 fprintf(stderr, "Connection to debugserver port %d failed!\n", (int)port); 307 fprintf(stderr, "Connection to debugserver port %d failed!\n", (int)service->port);
308 result = EXIT_FAILURE; 308 result = EXIT_FAILURE;
309 goto leave_cleanup; 309 goto leave_cleanup;
310 } 310 }
@@ -320,7 +320,12 @@ int main(int argc, char *argv[])
320 320
321 socket_info.device_connection = connection; 321 socket_info.device_connection = connection;
322 socket_info.local_port = local_port; 322 socket_info.local_port = local_port;
323 socket_info.remote_port = port; 323 socket_info.remote_port = service->port;
324
325 if (service) {
326 lockdownd_service_descriptor_free(service);
327 service = NULL;
328 }
324 329
325 /* create local socket */ 330 /* create local socket */
326 socket_info.server_fd = socket_create(socket_info.local_port); 331 socket_info.server_fd = socket_create(socket_info.local_port);
diff --git a/tools/idevicediagnostics.c b/tools/idevicediagnostics.c
index 10dab77..410d054 100644
--- a/tools/idevicediagnostics.c
+++ b/tools/idevicediagnostics.c
@@ -57,7 +57,7 @@ int main(int argc, char **argv)
57 lockdownd_client_t lockdown_client = NULL; 57 lockdownd_client_t lockdown_client = NULL;
58 diagnostics_relay_client_t diagnostics_client = NULL; 58 diagnostics_relay_client_t diagnostics_client = NULL;
59 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 59 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
60 uint16_t port = 0; 60 lockdownd_service_descriptor_t service = NULL;
61 int result = -1; 61 int result = -1;
62 int i; 62 int i;
63 const char *udid = NULL; 63 const char *udid = NULL;
@@ -173,23 +173,23 @@ int main(int argc, char **argv)
173 goto cleanup; 173 goto cleanup;
174 } 174 }
175 175
176 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown_client, NULL)) { 176 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown_client, "idevicediagnostics")) {
177 idevice_free(device); 177 idevice_free(device);
178 printf("Unable to connect to lockdownd.\n"); 178 printf("Unable to connect to lockdownd.\n");
179 goto cleanup; 179 goto cleanup;
180 } 180 }
181 181
182 /* attempt to use newer diagnostics service available on iOS 5 and later */ 182 /* attempt to use newer diagnostics service available on iOS 5 and later */
183 ret = lockdownd_start_service(lockdown_client, "com.apple.mobile.diagnostics_relay", &port); 183 ret = lockdownd_start_service(lockdown_client, "com.apple.mobile.diagnostics_relay", &service);
184 if (ret != LOCKDOWN_E_SUCCESS) { 184 if (ret != LOCKDOWN_E_SUCCESS) {
185 /* attempt to use older diagnostics service */ 185 /* attempt to use older diagnostics service */
186 ret = lockdownd_start_service(lockdown_client, "com.apple.iosdiagnostics.relay", &port); 186 ret = lockdownd_start_service(lockdown_client, "com.apple.iosdiagnostics.relay", &service);
187 } 187 }
188 188
189 lockdownd_client_free(lockdown_client); 189 lockdownd_client_free(lockdown_client);
190 190
191 if ((ret == LOCKDOWN_E_SUCCESS) && (port > 0)) { 191 if ((ret == LOCKDOWN_E_SUCCESS) && (service->port > 0)) {
192 if (diagnostics_relay_client_new(device, port, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) { 192 if (diagnostics_relay_client_new(device, service, &diagnostics_client) != DIAGNOSTICS_RELAY_E_SUCCESS) {
193 printf("Could not connect to diagnostics_relay!\n"); 193 printf("Could not connect to diagnostics_relay!\n");
194 result = -1; 194 result = -1;
195 } else { 195 } else {
@@ -258,6 +258,11 @@ int main(int argc, char **argv)
258 printf("Could not start diagnostics service!\n"); 258 printf("Could not start diagnostics service!\n");
259 } 259 }
260 260
261 if (service) {
262 lockdownd_service_descriptor_free(service);
263 service = NULL;
264 }
265
261 idevice_free(device); 266 idevice_free(device);
262 267
263cleanup: 268cleanup:
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c
index 9b65a0e..57a2e27 100644
--- a/tools/ideviceimagemounter.c
+++ b/tools/ideviceimagemounter.c
@@ -267,7 +267,7 @@ int main(int argc, char **argv)
267 lockdownd_client_t lckd = NULL; 267 lockdownd_client_t lckd = NULL;
268 mobile_image_mounter_client_t mim = NULL; 268 mobile_image_mounter_client_t mim = NULL;
269 afc_client_t afc = NULL; 269 afc_client_t afc = NULL;
270 uint16_t port = 0; 270 lockdownd_service_descriptor_t service = NULL;
271 int res = -1; 271 int res = -1;
272 char *image_path = NULL; 272 char *image_path = NULL;
273 char *image_sig_path = NULL; 273 char *image_sig_path = NULL;
@@ -303,30 +303,38 @@ int main(int argc, char **argv)
303 goto leave; 303 goto leave;
304 } 304 }
305 305
306 lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &port); 306 lockdownd_start_service(lckd, "com.apple.mobile.mobile_image_mounter", &service);
307 307
308 if (port == 0) { 308 if (service->port == 0) {
309 printf("ERROR: Could not start mobile_image_mounter service!\n"); 309 printf("ERROR: Could not start mobile_image_mounter service!\n");
310 goto leave; 310 goto leave;
311 } 311 }
312 312
313 if (mobile_image_mounter_new(device, port, &mim) != MOBILE_IMAGE_MOUNTER_E_SUCCESS) { 313 if (mobile_image_mounter_new(device, service, &mim) != MOBILE_IMAGE_MOUNTER_E_SUCCESS) {
314 printf("ERROR: Could not connect to mobile_image_mounter!\n"); 314 printf("ERROR: Could not connect to mobile_image_mounter!\n");
315 goto leave; 315 goto leave;
316 } 316 }
317 317
318 if (service) {
319 lockdownd_service_descriptor_free(service);
320 service = NULL;
321 }
322
318 if (!list_mode) { 323 if (!list_mode) {
319 struct stat fst; 324 struct stat fst;
320 port = 0; 325 if ((lockdownd_start_service(lckd, "com.apple.afc", &service) !=
321 if ((lockdownd_start_service(lckd, "com.apple.afc", &port) != 326 LOCKDOWN_E_SUCCESS) || !service->port) {
322 LOCKDOWN_E_SUCCESS) || !port) {
323 fprintf(stderr, "Could not start com.apple.afc!\n"); 327 fprintf(stderr, "Could not start com.apple.afc!\n");
324 goto leave; 328 goto leave;
325 } 329 }
326 if (afc_client_new(device, port, &afc) != AFC_E_SUCCESS) { 330 if (afc_client_new(device, service, &afc) != AFC_E_SUCCESS) {
327 fprintf(stderr, "Could not connect to AFC!\n"); 331 fprintf(stderr, "Could not connect to AFC!\n");
328 goto leave; 332 goto leave;
329 } 333 }
334 if (service) {
335 lockdownd_service_descriptor_free(service);
336 service = NULL;
337 }
330 if (stat(image_path, &fst) != 0) { 338 if (stat(image_path, &fst) != 0) {
331 fprintf(stderr, "ERROR: stat: %s: %s\n", image_path, strerror(errno)); 339 fprintf(stderr, "ERROR: stat: %s: %s\n", image_path, strerror(errno));
332 goto leave; 340 goto leave;
diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c
index 1c6866d..13fd239 100644
--- a/tools/ideviceprovision.c
+++ b/tools/ideviceprovision.c
@@ -193,6 +193,7 @@ static plist_t profile_get_embedded_plist(plist_t profile)
193int main(int argc, char *argv[]) 193int main(int argc, char *argv[])
194{ 194{
195 lockdownd_client_t client = NULL; 195 lockdownd_client_t client = NULL;
196 lockdownd_service_descriptor_t service = NULL;
196 idevice_t device = NULL; 197 idevice_t device = NULL;
197 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; 198 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
198 int i; 199 int i;
@@ -278,8 +279,7 @@ int main(int argc, char *argv[])
278 return -1; 279 return -1;
279 } 280 }
280 281
281 uint16_t port = 0; 282 if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.misagent", &service)) {
282 if (LOCKDOWN_E_SUCCESS != lockdownd_start_service(client, "com.apple.misagent", &port)) {
283 fprintf(stderr, "Could not start service \"com.apple.misagent\"\n"); 283 fprintf(stderr, "Could not start service \"com.apple.misagent\"\n");
284 lockdownd_client_free(client); 284 lockdownd_client_free(client);
285 idevice_free(device); 285 idevice_free(device);
@@ -289,13 +289,18 @@ int main(int argc, char *argv[])
289 client = NULL; 289 client = NULL;
290 290
291 misagent_client_t mis = NULL; 291 misagent_client_t mis = NULL;
292 if (misagent_client_new(device, port, &mis) != MISAGENT_E_SUCCESS) { 292 if (misagent_client_new(device, service, &mis) != MISAGENT_E_SUCCESS) {
293 fprintf(stderr, "Could not connect to \"com.apple.misagent\" on device\n"); 293 fprintf(stderr, "Could not connect to \"com.apple.misagent\" on device\n");
294 if (service)
295 lockdownd_service_descriptor_free(service);
294 lockdownd_client_free(client); 296 lockdownd_client_free(client);
295 idevice_free(device); 297 idevice_free(device);
296 return -1; 298 return -1;
297 } 299 }
298 300
301 if (service)
302 lockdownd_service_descriptor_free(service);
303
299 switch (op) { 304 switch (op) {
300 case OP_INSTALL: 305 case OP_INSTALL:
301 { 306 {
diff --git a/tools/idevicescreenshot.c b/tools/idevicescreenshot.c
index cba62a2..23e7b41 100644
--- a/tools/idevicescreenshot.c
+++ b/tools/idevicescreenshot.c
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
36 idevice_t device = NULL; 36 idevice_t device = NULL;
37 lockdownd_client_t lckd = NULL; 37 lockdownd_client_t lckd = NULL;
38 screenshotr_client_t shotr = NULL; 38 screenshotr_client_t shotr = NULL;
39 uint16_t port = 0; 39 lockdownd_service_descriptor_t service = NULL;
40 int result = -1; 40 int result = -1;
41 int i; 41 int i;
42 const char *udid = NULL; 42 const char *udid = NULL;
@@ -81,10 +81,10 @@ int main(int argc, char **argv)
81 return -1; 81 return -1;
82 } 82 }
83 83
84 lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &port); 84 lockdownd_start_service(lckd, "com.apple.mobile.screenshotr", &service);
85 lockdownd_client_free(lckd); 85 lockdownd_client_free(lckd);
86 if (port > 0) { 86 if (service->port > 0) {
87 if (screenshotr_client_new(device, port, &shotr) != SCREENSHOTR_E_SUCCESS) { 87 if (screenshotr_client_new(device, service, &shotr) != SCREENSHOTR_E_SUCCESS) {
88 printf("Could not connect to screenshotr!\n"); 88 printf("Could not connect to screenshotr!\n");
89 } else { 89 } else {
90 char *imgdata = NULL; 90 char *imgdata = NULL;
@@ -113,8 +113,12 @@ int main(int argc, char **argv)
113 } else { 113 } else {
114 printf("Could not start screenshotr service! Remember that you have to mount the Developer disk image on your device if you want to use the screenshotr service.\n"); 114 printf("Could not start screenshotr service! Remember that you have to mount the Developer disk image on your device if you want to use the screenshotr service.\n");
115 } 115 }
116
117 if (service)
118 lockdownd_service_descriptor_free(service);
119
116 idevice_free(device); 120 idevice_free(device);
117 121
118 return result; 122 return result;
119} 123}
120 124
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index a17999c..6ce6d0e 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
49 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR; 49 idevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;
50 int i; 50 int i;
51 const char* udid = NULL; 51 const char* udid = NULL;
52 uint16_t port = 0; 52 lockdownd_service_descriptor_t service = NULL;
53 53
54 signal(SIGINT, clean_exit); 54 signal(SIGINT, clean_exit);
55 signal(SIGTERM, clean_exit); 55 signal(SIGTERM, clean_exit);
@@ -99,13 +99,13 @@ int main(int argc, char *argv[])
99 } 99 }
100 100
101 /* start syslog_relay service and retrieve port */ 101 /* start syslog_relay service and retrieve port */
102 ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port); 102 ret = lockdownd_start_service(client, "com.apple.syslog_relay", &service);
103 if ((ret == LOCKDOWN_E_SUCCESS) && port) { 103 if ((ret == LOCKDOWN_E_SUCCESS) && service->port) {
104 lockdownd_client_free(client); 104 lockdownd_client_free(client);
105 105
106 /* connect to socket relay messages */ 106 /* connect to socket relay messages */
107 idevice_connection_t conn = NULL; 107 idevice_connection_t conn = NULL;
108 if ((idevice_connect(device, port, &conn) != IDEVICE_E_SUCCESS) || !conn) { 108 if ((idevice_connect(device, service->port, &conn) != IDEVICE_E_SUCCESS) || !conn) {
109 printf("ERROR: Could not open usbmux connection.\n"); 109 printf("ERROR: Could not open usbmux connection.\n");
110 } else { 110 } else {
111 while (!quit_flag) { 111 while (!quit_flag) {
@@ -126,6 +126,9 @@ int main(int argc, char *argv[])
126 printf("ERROR: Could not start service com.apple.syslog_relay.\n"); 126 printf("ERROR: Could not start service com.apple.syslog_relay.\n");
127 } 127 }
128 128
129 if (service)
130 lockdownd_service_descriptor_free(service);
131
129 idevice_free(device); 132 idevice_free(device);
130 133
131 return 0; 134 return 0;