summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dev/msyncclient.c34
-rw-r--r--src/MobileSync.c36
-rw-r--r--src/NotificationProxy.c14
-rw-r--r--src/lockdown.c75
-rw-r--r--tools/iphoneinfo.c33
5 files changed, 99 insertions, 93 deletions
diff --git a/dev/msyncclient.c b/dev/msyncclient.c
index b3cc81e..08092cb 100644
--- a/dev/msyncclient.c
+++ b/dev/msyncclient.c
@@ -27,6 +27,23 @@
27#include <libiphone/lockdown.h> 27#include <libiphone/lockdown.h>
28#include <libiphone/mobilesync.h> 28#include <libiphone/mobilesync.h>
29 29
30static char check_string(plist_t node, char* string)
31{
32 char ret = 1;
33 char* msg = NULL;
34 plist_type type = plist_get_node_type(node);
35 if (PLIST_STRING == type) {
36 plist_get_string_val(node, &msg);
37 }
38 if (PLIST_STRING != type || strcmp(msg, string)) {
39 log_debug_msg("%s: ERROR: MobileSync client did not find %s !\n", __func__, string);
40 ret = 0;
41 }
42 free(msg);
43 msg = NULL;
44 return ret;
45}
46
30static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client) 47static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client)
31{ 48{
32 if (!client) 49 if (!client)
@@ -49,11 +66,6 @@ static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client
49 66
50 ret = mobilesync_recv(client, &array); 67 ret = mobilesync_recv(client, &array);
51 68
52 plist_t rep_node = plist_find_node_by_string(array, "SDSyncTypeSlow");
53
54 if (!rep_node)
55 return ret;
56
57 plist_free(array); 69 plist_free(array);
58 array = NULL; 70 array = NULL;
59 71
@@ -70,10 +82,12 @@ static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client
70 plist_t contact_node; 82 plist_t contact_node;
71 plist_t switch_node; 83 plist_t switch_node;
72 84
73 contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); 85 contact_node = plist_array_get_item(array, 0);
74 switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); 86 switch_node = plist_array_get_item(array, 0);
75 87
76 while (NULL == switch_node) { 88 while (NULL == switch_node
89 && check_string(contact_node, "com.apple.Contacts")
90 && check_string(switch_node, "SDMessageDeviceReadyToReceiveChanges")) {
77 91
78 plist_free(array); 92 plist_free(array);
79 array = NULL; 93 array = NULL;
@@ -88,8 +102,8 @@ static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client
88 102
89 ret = mobilesync_recv(client, &array); 103 ret = mobilesync_recv(client, &array);
90 104
91 contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); 105 contact_node = plist_array_get_item(array, 0);
92 switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); 106 switch_node = plist_array_get_item(array, 0);
93 } 107 }
94 108
95 array = plist_new_array(); 109 array = plist_new_array();
diff --git a/src/MobileSync.c b/src/MobileSync.c
index 9e52f32..77d2710 100644
--- a/src/MobileSync.c
+++ b/src/MobileSync.c
@@ -54,9 +54,21 @@ mobilesync_error_t mobilesync_client_new(iphone_device_t device, int dst_port,
54 /* first receive version */ 54 /* first receive version */
55 ret = mobilesync_recv(client_loc, &array); 55 ret = mobilesync_recv(client_loc, &array);
56 56
57 plist_t msg_node = plist_find_node_by_string(array, "DLMessageVersionExchange"); 57 plist_t msg_node = plist_array_get_item(array, 0);
58 plist_t ver_1 = plist_get_next_sibling(msg_node); 58
59 plist_t ver_2 = plist_get_next_sibling(ver_1); 59 char* msg = NULL;
60 plist_type type = plist_get_node_type(msg_node);
61 if (PLIST_STRING == type) {
62 plist_get_string_val(msg_node, &msg);
63 }
64 if (PLIST_STRING != type || strcmp(msg, "DLMessageVersionExchange") || plist_array_get_size(array) < 3) {
65 log_debug_msg("%s: ERROR: MobileSync client expected a version exchange !\n", __func__);
66 }
67 free(msg);
68 msg = NULL;
69
70 plist_t ver_1 = plist_array_get_item(array, 1);
71 plist_t ver_2 = plist_array_get_item(array, 2);
60 72
61 plist_type ver_1_type = plist_get_node_type(ver_1); 73 plist_type ver_1_type = plist_get_node_type(ver_1);
62 plist_type ver_2_type = plist_get_node_type(ver_2); 74 plist_type ver_2_type = plist_get_node_type(ver_2);
@@ -85,16 +97,24 @@ mobilesync_error_t mobilesync_client_new(iphone_device_t device, int dst_port,
85 array = NULL; 97 array = NULL;
86 98
87 ret = mobilesync_recv(client_loc, &array); 99 ret = mobilesync_recv(client_loc, &array);
88 plist_t rep_node = plist_find_node_by_string(array, "DLMessageDeviceReady"); 100 plist_t rep_node = plist_array_get_item(array, 0);
89 101
90 if (rep_node) { 102 type = plist_get_node_type(rep_node);
91 ret = MOBILESYNC_E_SUCCESS; 103 if (PLIST_STRING == type) {
92 *client = client_loc; 104 plist_get_string_val(rep_node, &msg);
105 }
106 if (PLIST_STRING != type || strcmp(msg, "DLMessageDeviceReady")) {
107 log_debug_msg("%s: ERROR: MobileSync client failed to start session !\n", __func__);
108 ret = MOBILESYNC_E_BAD_VERSION;
93 } 109 }
94 else 110 else
95 { 111 {
96 ret = MOBILESYNC_E_BAD_VERSION; 112 ret = MOBILESYNC_E_SUCCESS;
113 *client = client_loc;
97 } 114 }
115 free(msg);
116 msg = NULL;
117
98 plist_free(array); 118 plist_free(array);
99 array = NULL; 119 array = NULL;
100 } 120 }
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index ee2ad95..884be5f 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -318,35 +318,27 @@ static int np_get_notification(np_client_t client, char **notification)
318 return -2; 318 return -2;
319 } 319 }
320 320
321 plist_t cmd_key_node = plist_find_node_by_key(dict, "Command");
322 plist_t cmd_value_node = plist_get_next_sibling(cmd_key_node);
323 char *cmd_value = NULL; 321 char *cmd_value = NULL;
322 plist_t cmd_value_node = plist_dict_get_item(dict, "Command");
324 323
325 if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { 324 if (plist_get_node_type(cmd_value_node) == PLIST_STRING) {
326 plist_get_string_val(cmd_value_node, &cmd_value); 325 plist_get_string_val(cmd_value_node, &cmd_value);
327 } 326 }
328 327
329 if (cmd_value && !strcmp(cmd_value, "RelayNotification")) { 328 if (cmd_value && !strcmp(cmd_value, "RelayNotification")) {
330 plist_t name_key_node = plist_get_next_sibling(cmd_value_node);
331 plist_t name_value_node = plist_get_next_sibling(name_key_node);
332
333 char *name_key = NULL;
334 char *name_value = NULL; 329 char *name_value = NULL;
330 plist_t name_value_node = plist_dict_get_item(dict, "Name");
335 331
336 if (plist_get_node_type(name_key_node) == PLIST_KEY) {
337 plist_get_key_val(name_key_node, &name_key);
338 }
339 if (plist_get_node_type(name_value_node) == PLIST_STRING) { 332 if (plist_get_node_type(name_value_node) == PLIST_STRING) {
340 plist_get_string_val(name_value_node, &name_value); 333 plist_get_string_val(name_value_node, &name_value);
341 } 334 }
342 335
343 res = -2; 336 res = -2;
344 if (name_key && name_value && !strcmp(name_key, "Name")) { 337 if (name_value_node && name_value) {
345 *notification = name_value; 338 *notification = name_value;
346 log_debug_msg("%s: got notification %s\n", __func__, name_value); 339 log_debug_msg("%s: got notification %s\n", __func__, name_value);
347 res = 0; 340 res = 0;
348 } 341 }
349 free(name_key);
350 } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { 342 } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) {
351 log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__); 343 log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__);
352 res = -1; 344 res = -1;
diff --git a/src/lockdown.c b/src/lockdown.c
index 6f9c922..80a89dc 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -60,11 +60,7 @@ static int lockdown_check_result(plist_t dict, const char *query_match)
60{ 60{
61 int ret = -1; 61 int ret = -1;
62 62
63 plist_t query_key = plist_find_node_by_key(dict, "Request"); 63 plist_t query_node = plist_dict_get_item(dict, "Request");
64 if (!query_key) {
65 return ret;
66 }
67 plist_t query_node = plist_get_next_sibling(query_key);
68 if (!query_node) { 64 if (!query_node) {
69 return ret; 65 return ret;
70 } 66 }
@@ -83,40 +79,30 @@ static int lockdown_check_result(plist_t dict, const char *query_match)
83 free(query_value); 79 free(query_value);
84 } 80 }
85 81
86 plist_t result_node = plist_get_next_sibling(query_node); 82 plist_t result_node = plist_dict_get_item(dict, "Result");
87 if (!result_node) { 83 if (!result_node) {
88 return ret; 84 return ret;
89 } 85 }
90 86
91 plist_t value_node = plist_get_next_sibling(result_node);
92 if (!value_node) {
93 return ret;
94 }
95
96 plist_type result_type = plist_get_node_type(result_node); 87 plist_type result_type = plist_get_node_type(result_node);
97 plist_type value_type = plist_get_node_type(value_node);
98 88
99 if (result_type == PLIST_KEY && value_type == PLIST_STRING) { 89 if (result_type == PLIST_STRING) {
100 90
101 char *result_value = NULL; 91 char *result_value = NULL;
102 char *value_value = NULL;
103 92
104 plist_get_key_val(result_node, &result_value); 93 plist_get_string_val(result_node, &result_value);
105 plist_get_string_val(value_node, &value_value);
106 94
107 if (result_value && value_value && !strcmp(result_value, "Result")) { 95 if (result_value) {
108 if (!strcmp(value_value, "Success")) { 96 if (!strcmp(result_value, "Success")) {
109 ret = RESULT_SUCCESS; 97 ret = RESULT_SUCCESS;
110 } else if (!strcmp(value_value, "Failure")) { 98 } else if (!strcmp(result_value, "Failure")) {
111 ret = RESULT_FAILURE; 99 ret = RESULT_FAILURE;
112 } else { 100 } else {
113 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, value_value); 101 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, result_value);
114 } 102 }
115 } 103 }
116 if (result_value) 104 if (result_value)
117 free(result_value); 105 free(result_value);
118 if (value_value)
119 free(value_value);
120 } 106 }
121 return ret; 107 return ret;
122} 108}
@@ -437,20 +423,11 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom
437 return ret; 423 return ret;
438 } 424 }
439 425
440 plist_t value_key_node = plist_find_node_by_key(dict, "Value"); 426 plist_t value_node = plist_dict_get_item(dict, "Value");
441 plist_t value_value_node = plist_get_next_sibling(value_key_node);
442
443 plist_type value_key_type = plist_get_node_type(value_key_node);
444 427
445 if (value_key_type == PLIST_KEY) { 428 if (value_node) {
446 char *result_key = NULL; 429 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__);
447 plist_get_key_val(value_key_node, &result_key); 430 *value = plist_copy(value_node);
448
449 if (!strcmp(result_key, "Value")) {
450 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__);
451 *value = plist_copy(value_value_node);
452 }
453 free(result_key);
454 } 431 }
455 432
456 plist_free(dict); 433 plist_free(dict);
@@ -1024,7 +1001,7 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
1024 return LOCKDOWN_E_PLIST_ERROR; 1001 return LOCKDOWN_E_PLIST_ERROR;
1025 1002
1026 if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { 1003 if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) {
1027 plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); 1004 plist_t error_node = plist_dict_get_item(dict, "Error");
1028 if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { 1005 if (error_node && PLIST_STRING == plist_get_node_type(error_node)) {
1029 char *error = NULL; 1006 char *error = NULL;
1030 plist_get_string_val(error_node, &error); 1007 plist_get_string_val(error_node, &error);
@@ -1108,18 +1085,17 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
1108 } 1085 }
1109 } 1086 }
1110 /* store session id */ 1087 /* store session id */
1111 plist_t session_node = plist_find_node_by_key(dict, "SessionID"); 1088 plist_t session_node = plist_dict_get_item(dict, "SessionID");
1112 if (session_node) { 1089 if (session_node) {
1113 1090
1114 plist_t session_node_val = plist_get_next_sibling(session_node); 1091 plist_type session_node_type = plist_get_node_type(session_node);
1115 plist_type session_node_val_type = plist_get_node_type(session_node_val);
1116 1092
1117 if (session_node_val_type == PLIST_STRING) { 1093 if (session_node_type == PLIST_STRING) {
1118 1094
1119 char *session_id = NULL; 1095 char *session_id = NULL;
1120 plist_get_string_val(session_node_val, &session_id); 1096 plist_get_string_val(session_node, &session_id);
1121 1097
1122 if (session_node_val_type == PLIST_STRING && session_id) { 1098 if (session_node_type == PLIST_STRING && session_id) {
1123 /* we need to store the session ID for StopSession */ 1099 /* we need to store the session ID for StopSession */
1124 strcpy(client->session_id, session_id); 1100 strcpy(client->session_id, session_id);
1125 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id); 1101 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
@@ -1260,23 +1236,16 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
1260 1236
1261 ret = LOCKDOWN_E_UNKNOWN_ERROR; 1237 ret = LOCKDOWN_E_UNKNOWN_ERROR;
1262 if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { 1238 if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) {
1263 plist_t port_key_node = plist_find_node_by_key(dict, "Port"); 1239 plist_t port_value_node = plist_dict_get_item(dict, "Port");
1264 plist_t port_value_node = plist_get_next_sibling(port_key_node);
1265 1240
1266 if ((plist_get_node_type(port_key_node) == PLIST_KEY) 1241 if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) {
1267 && (plist_get_node_type(port_value_node) == PLIST_UINT)) {
1268 char *port_key = NULL;
1269 uint64_t port_value = 0; 1242 uint64_t port_value = 0;
1270
1271 plist_get_key_val(port_key_node, &port_key);
1272 plist_get_uint_val(port_value_node, &port_value); 1243 plist_get_uint_val(port_value_node, &port_value);
1273 if (port_key && !strcmp(port_key, "Port")) { 1244
1245 if (port_value) {
1274 port_loc = port_value; 1246 port_loc = port_value;
1275 ret = LOCKDOWN_E_SUCCESS; 1247 ret = LOCKDOWN_E_SUCCESS;
1276 } 1248 }
1277 if (port_key)
1278 free(port_key);
1279
1280 if (port && ret == LOCKDOWN_E_SUCCESS) 1249 if (port && ret == LOCKDOWN_E_SUCCESS)
1281 *port = port_loc; 1250 *port = port_loc;
1282 } 1251 }
diff --git a/tools/iphoneinfo.c b/tools/iphoneinfo.c
index 4d6da31..e0d7693 100644
--- a/tools/iphoneinfo.c
+++ b/tools/iphoneinfo.c
@@ -51,8 +51,8 @@ static const char *domains[] = {
51 51
52int is_domain_known(char *domain); 52int is_domain_known(char *domain);
53void print_usage(int argc, char **argv); 53void print_usage(int argc, char **argv);
54void plist_node_to_string(plist_t *node); 54void plist_node_to_string(plist_t node);
55void plist_children_to_string(plist_t *node); 55void plist_children_to_string(plist_t node);
56 56
57int main(int argc, char *argv[]) 57int main(int argc, char *argv[])
58{ 58{
@@ -145,7 +145,7 @@ int main(int argc, char *argv[])
145 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) 145 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS)
146 { 146 {
147 if (plist_get_node_type(node) == PLIST_DICT) { 147 if (plist_get_node_type(node) == PLIST_DICT) {
148 if (plist_get_first_child(node)) 148 if (plist_dict_get_size(node))
149 { 149 {
150 switch (format) { 150 switch (format) {
151 case FORMAT_XML: 151 case FORMAT_XML:
@@ -208,7 +208,7 @@ void print_usage(int argc, char **argv)
208 printf("\n"); 208 printf("\n");
209} 209}
210 210
211void plist_node_to_string(plist_t *node) 211void plist_node_to_string(plist_t node)
212{ 212{
213 char *s = NULL; 213 char *s = NULL;
214 double d; 214 double d;
@@ -267,15 +267,26 @@ void plist_node_to_string(plist_t *node)
267 } 267 }
268} 268}
269 269
270void plist_children_to_string(plist_t *node) 270void plist_children_to_string(plist_t node)
271{ 271{
272 /* iterate over key/value pairs */ 272 /* iterate over key/value pairs */
273 for ( 273 plist_dict_iter it = NULL;
274 node = plist_get_first_child(node); 274
275 node != NULL; 275 char* key = NULL;
276 node = plist_get_next_sibling(node) 276 plist_t subnode = NULL;
277 ) { 277 plist_dict_new_iter(node, &it);
278 plist_node_to_string(node); 278 plist_dict_next_item(node, it, &key, &subnode);
279 while (subnode)
280 {
281 subnode = NULL;
282
283 printf("%s: ", key);
284 free(key);
285 key = NULL;
286 plist_node_to_string(subnode);
287
288 plist_dict_next_item(node, it, &key, &subnode);
279 } 289 }
290 free(it);
280} 291}
281 292