From eaf80002c6e82c6b7a376bb61c9884ec3cf750b4 Mon Sep 17 00:00:00 2001 From: Jonathan Beck Date: Tue, 10 Nov 2009 23:31:49 +0100 Subject: Finish migration to latest plist API. [#77 state:resolved] Signed-off-by: Matt Colyer --- dev/msyncclient.c | 34 +++++++++++++++------- src/MobileSync.c | 36 ++++++++++++++++++------ src/NotificationProxy.c | 14 ++------- src/lockdown.c | 75 +++++++++++++++---------------------------------- tools/iphoneinfo.c | 33 ++++++++++++++-------- 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 @@ #include #include +static char check_string(plist_t node, char* string) +{ + char ret = 1; + char* msg = NULL; + plist_type type = plist_get_node_type(node); + if (PLIST_STRING == type) { + plist_get_string_val(node, &msg); + } + if (PLIST_STRING != type || strcmp(msg, string)) { + log_debug_msg("%s: ERROR: MobileSync client did not find %s !\n", __func__, string); + ret = 0; + } + free(msg); + msg = NULL; + return ret; +} + static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client) { if (!client) @@ -49,11 +66,6 @@ static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client ret = mobilesync_recv(client, &array); - plist_t rep_node = plist_find_node_by_string(array, "SDSyncTypeSlow"); - - if (!rep_node) - return ret; - plist_free(array); array = NULL; @@ -70,10 +82,12 @@ static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client plist_t contact_node; plist_t switch_node; - contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); - switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); + contact_node = plist_array_get_item(array, 0); + switch_node = plist_array_get_item(array, 0); - while (NULL == switch_node) { + while (NULL == switch_node + && check_string(contact_node, "com.apple.Contacts") + && check_string(switch_node, "SDMessageDeviceReadyToReceiveChanges")) { plist_free(array); array = NULL; @@ -88,8 +102,8 @@ static mobilesync_error_t mobilesync_get_all_contacts(mobilesync_client_t client ret = mobilesync_recv(client, &array); - contact_node = plist_find_node_by_string(array, "com.apple.Contacts"); - switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges"); + contact_node = plist_array_get_item(array, 0); + switch_node = plist_array_get_item(array, 0); } 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, /* first receive version */ ret = mobilesync_recv(client_loc, &array); - plist_t msg_node = plist_find_node_by_string(array, "DLMessageVersionExchange"); - plist_t ver_1 = plist_get_next_sibling(msg_node); - plist_t ver_2 = plist_get_next_sibling(ver_1); + plist_t msg_node = plist_array_get_item(array, 0); + + char* msg = NULL; + plist_type type = plist_get_node_type(msg_node); + if (PLIST_STRING == type) { + plist_get_string_val(msg_node, &msg); + } + if (PLIST_STRING != type || strcmp(msg, "DLMessageVersionExchange") || plist_array_get_size(array) < 3) { + log_debug_msg("%s: ERROR: MobileSync client expected a version exchange !\n", __func__); + } + free(msg); + msg = NULL; + + plist_t ver_1 = plist_array_get_item(array, 1); + plist_t ver_2 = plist_array_get_item(array, 2); plist_type ver_1_type = plist_get_node_type(ver_1); 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, array = NULL; ret = mobilesync_recv(client_loc, &array); - plist_t rep_node = plist_find_node_by_string(array, "DLMessageDeviceReady"); + plist_t rep_node = plist_array_get_item(array, 0); - if (rep_node) { - ret = MOBILESYNC_E_SUCCESS; - *client = client_loc; + type = plist_get_node_type(rep_node); + if (PLIST_STRING == type) { + plist_get_string_val(rep_node, &msg); + } + if (PLIST_STRING != type || strcmp(msg, "DLMessageDeviceReady")) { + log_debug_msg("%s: ERROR: MobileSync client failed to start session !\n", __func__); + ret = MOBILESYNC_E_BAD_VERSION; } else { - ret = MOBILESYNC_E_BAD_VERSION; + ret = MOBILESYNC_E_SUCCESS; + *client = client_loc; } + free(msg); + msg = NULL; + plist_free(array); array = NULL; } 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) return -2; } - plist_t cmd_key_node = plist_find_node_by_key(dict, "Command"); - plist_t cmd_value_node = plist_get_next_sibling(cmd_key_node); char *cmd_value = NULL; + plist_t cmd_value_node = plist_dict_get_item(dict, "Command"); if (plist_get_node_type(cmd_value_node) == PLIST_STRING) { plist_get_string_val(cmd_value_node, &cmd_value); } if (cmd_value && !strcmp(cmd_value, "RelayNotification")) { - plist_t name_key_node = plist_get_next_sibling(cmd_value_node); - plist_t name_value_node = plist_get_next_sibling(name_key_node); - - char *name_key = NULL; char *name_value = NULL; + plist_t name_value_node = plist_dict_get_item(dict, "Name"); - if (plist_get_node_type(name_key_node) == PLIST_KEY) { - plist_get_key_val(name_key_node, &name_key); - } if (plist_get_node_type(name_value_node) == PLIST_STRING) { plist_get_string_val(name_value_node, &name_value); } res = -2; - if (name_key && name_value && !strcmp(name_key, "Name")) { + if (name_value_node && name_value) { *notification = name_value; log_debug_msg("%s: got notification %s\n", __func__, name_value); res = 0; } - free(name_key); } else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) { log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__); 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) { int ret = -1; - plist_t query_key = plist_find_node_by_key(dict, "Request"); - if (!query_key) { - return ret; - } - plist_t query_node = plist_get_next_sibling(query_key); + plist_t query_node = plist_dict_get_item(dict, "Request"); if (!query_node) { return ret; } @@ -83,40 +79,30 @@ static int lockdown_check_result(plist_t dict, const char *query_match) free(query_value); } - plist_t result_node = plist_get_next_sibling(query_node); + plist_t result_node = plist_dict_get_item(dict, "Result"); if (!result_node) { return ret; } - plist_t value_node = plist_get_next_sibling(result_node); - if (!value_node) { - return ret; - } - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { + if (result_type == PLIST_STRING) { char *result_value = NULL; - char *value_value = NULL; - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); + plist_get_string_val(result_node, &result_value); - if (result_value && value_value && !strcmp(result_value, "Result")) { - if (!strcmp(value_value, "Success")) { + if (result_value) { + if (!strcmp(result_value, "Success")) { ret = RESULT_SUCCESS; - } else if (!strcmp(value_value, "Failure")) { + } else if (!strcmp(result_value, "Failure")) { ret = RESULT_FAILURE; } else { - log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, value_value); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, result_value); } } if (result_value) free(result_value); - if (value_value) - free(value_value); } return ret; } @@ -437,20 +423,11 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom return ret; } - plist_t value_key_node = plist_find_node_by_key(dict, "Value"); - plist_t value_value_node = plist_get_next_sibling(value_key_node); - - plist_type value_key_type = plist_get_node_type(value_key_node); + plist_t value_node = plist_dict_get_item(dict, "Value"); - if (value_key_type == PLIST_KEY) { - char *result_key = NULL; - plist_get_key_val(value_key_node, &result_key); - - if (!strcmp(result_key, "Value")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__); - *value = plist_copy(value_value_node); - } - free(result_key); + if (value_node) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__); + *value = plist_copy(value_node); } plist_free(dict); @@ -1024,7 +1001,7 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c return LOCKDOWN_E_PLIST_ERROR; if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { - plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); + plist_t error_node = plist_dict_get_item(dict, "Error"); if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { char *error = NULL; plist_get_string_val(error_node, &error); @@ -1108,18 +1085,17 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c } } /* store session id */ - plist_t session_node = plist_find_node_by_key(dict, "SessionID"); + plist_t session_node = plist_dict_get_item(dict, "SessionID"); if (session_node) { - plist_t session_node_val = plist_get_next_sibling(session_node); - plist_type session_node_val_type = plist_get_node_type(session_node_val); + plist_type session_node_type = plist_get_node_type(session_node); - if (session_node_val_type == PLIST_STRING) { + if (session_node_type == PLIST_STRING) { char *session_id = NULL; - plist_get_string_val(session_node_val, &session_id); + plist_get_string_val(session_node, &session_id); - if (session_node_val_type == PLIST_STRING && session_id) { + if (session_node_type == PLIST_STRING && session_id) { /* we need to store the session ID for StopSession */ strcpy(client->session_id, session_id); 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 ret = LOCKDOWN_E_UNKNOWN_ERROR; if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { - plist_t port_key_node = plist_find_node_by_key(dict, "Port"); - plist_t port_value_node = plist_get_next_sibling(port_key_node); + plist_t port_value_node = plist_dict_get_item(dict, "Port"); - if ((plist_get_node_type(port_key_node) == PLIST_KEY) - && (plist_get_node_type(port_value_node) == PLIST_UINT)) { - char *port_key = NULL; + if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) { uint64_t port_value = 0; - - plist_get_key_val(port_key_node, &port_key); plist_get_uint_val(port_value_node, &port_value); - if (port_key && !strcmp(port_key, "Port")) { + + if (port_value) { port_loc = port_value; ret = LOCKDOWN_E_SUCCESS; } - if (port_key) - free(port_key); - if (port && ret == LOCKDOWN_E_SUCCESS) *port = port_loc; } 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[] = { int is_domain_known(char *domain); void print_usage(int argc, char **argv); -void plist_node_to_string(plist_t *node); -void plist_children_to_string(plist_t *node); +void plist_node_to_string(plist_t node); +void plist_children_to_string(plist_t node); int main(int argc, char *argv[]) { @@ -145,7 +145,7 @@ int main(int argc, char *argv[]) if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) { if (plist_get_node_type(node) == PLIST_DICT) { - if (plist_get_first_child(node)) + if (plist_dict_get_size(node)) { switch (format) { case FORMAT_XML: @@ -208,7 +208,7 @@ void print_usage(int argc, char **argv) printf("\n"); } -void plist_node_to_string(plist_t *node) +void plist_node_to_string(plist_t node) { char *s = NULL; double d; @@ -267,15 +267,26 @@ void plist_node_to_string(plist_t *node) } } -void plist_children_to_string(plist_t *node) +void plist_children_to_string(plist_t node) { /* iterate over key/value pairs */ - for ( - node = plist_get_first_child(node); - node != NULL; - node = plist_get_next_sibling(node) - ) { - plist_node_to_string(node); + plist_dict_iter it = NULL; + + char* key = NULL; + plist_t subnode = NULL; + plist_dict_new_iter(node, &it); + plist_dict_next_item(node, it, &key, &subnode); + while (subnode) + { + subnode = NULL; + + printf("%s: ", key); + free(key); + key = NULL; + plist_node_to_string(subnode); + + plist_dict_next_item(node, it, &key, &subnode); } + free(it); } -- cgit v1.1-32-gdbae