diff options
| author | 2008-11-30 21:49:56 +0100 | |
|---|---|---|
| committer | 2008-11-30 21:49:56 +0100 | |
| commit | d560cf5a15d1aef74e95b208ed69b7d324d94354 (patch) | |
| tree | dbb5ffacf09ae6abbe002c53604f580996d5cdb6 /src/lockdown.c | |
| parent | 889cb32a1231c41762d7e2bbe6c891bd3a6c9a7d (diff) | |
| download | libimobiledevice-d560cf5a15d1aef74e95b208ed69b7d324d94354.tar.gz libimobiledevice-d560cf5a15d1aef74e95b208ed69b7d324d94354.tar.bz2 | |
complete xml plist abstraction and migrate lockdownd_hello to new plist API.
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 6b8f298..2906fdf 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -201,49 +201,57 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control) | |||
| 201 | { | 201 | { |
| 202 | if (!control) | 202 | if (!control) |
| 203 | return IPHONE_E_INVALID_ARG; | 203 | return IPHONE_E_INVALID_ARG; |
| 204 | xmlDocPtr plist = new_plist(); | 204 | |
| 205 | xmlNode *dict, *key; | ||
| 206 | char **dictionary; | ||
| 207 | int bytes = 0, i = 0; | 205 | int bytes = 0, i = 0; |
| 208 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 206 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 209 | 207 | ||
| 208 | plist_t plist = NULL; | ||
| 209 | plist_new_plist(&plist); | ||
| 210 | |||
| 211 | dict_t dict = NULL; | ||
| 212 | plist_new_dict_in_plist(plist, &dict); | ||
| 213 | |||
| 214 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "QueryType"); | ||
| 215 | |||
| 210 | log_debug_msg("lockdownd_hello() called\n"); | 216 | log_debug_msg("lockdownd_hello() called\n"); |
| 211 | dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); | 217 | char *XML_content = NULL; |
| 212 | key = add_key_str_dict_element(plist, dict, "Request", "QueryType", 1); | 218 | uint32_t length = 0; |
| 213 | char *XML_content; | ||
| 214 | uint32_t length; | ||
| 215 | 219 | ||
| 216 | xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); | 220 | plist_to_xml(plist, &XML_content, &length); |
| 221 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); | ||
| 217 | ret = iphone_lckd_send(control, XML_content, length, &bytes); | 222 | ret = iphone_lckd_send(control, XML_content, length, &bytes); |
| 218 | 223 | ||
| 219 | xmlFree(XML_content); | 224 | xmlFree(XML_content); |
| 220 | xmlFreeDoc(plist); | 225 | XML_content = NULL; |
| 226 | plist_free(plist); | ||
| 221 | plist = NULL; | 227 | plist = NULL; |
| 228 | |||
| 222 | ret = iphone_lckd_recv(control, &XML_content, &bytes); | 229 | ret = iphone_lckd_recv(control, &XML_content, &bytes); |
| 230 | log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); | ||
| 231 | xml_to_plist(XML_content, bytes, &plist); | ||
| 223 | 232 | ||
| 224 | plist = xmlReadMemory(XML_content, bytes, NULL, NULL, 0); | ||
| 225 | if (!plist) | 233 | if (!plist) |
| 226 | return IPHONE_E_PLIST_ERROR; | 234 | return IPHONE_E_PLIST_ERROR; |
| 227 | dict = xmlDocGetRootElement(plist); | ||
| 228 | for (dict = dict->children; dict; dict = dict->next) { | ||
| 229 | if (!xmlStrcmp(dict->name, "dict")) | ||
| 230 | break; | ||
| 231 | } | ||
| 232 | if (!dict) | ||
| 233 | return IPHONE_E_DICT_ERROR; | ||
| 234 | dictionary = read_dict_element_strings(dict); | ||
| 235 | xmlFreeDoc(plist); | ||
| 236 | free(XML_content); | ||
| 237 | 235 | ||
| 238 | for (i = 0; dictionary[i]; i += 2) { | 236 | plist_t query_node = find_query_node(plist, "Request", "QueryType"); |
| 239 | if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i + 1], "Success")) { | 237 | plist_t result_node = g_node_next_sibling(query_node); |
| 240 | log_debug_msg("lockdownd_hello(): success\n"); | 238 | plist_t value_node = g_node_next_sibling(result_node); |
| 241 | ret = IPHONE_E_SUCCESS; | 239 | |
| 242 | break; | 240 | plist_type result_type; |
| 243 | } | 241 | plist_type value_type; |
| 242 | |||
| 243 | char *result_value = NULL; | ||
| 244 | char *value_value = NULL; | ||
| 245 | |||
| 246 | get_type_and_value(result_node, &result_type, (void *) (&result_value)); | ||
| 247 | get_type_and_value(value_node, &value_type, (void *) (&value_value)); | ||
| 248 | |||
| 249 | if (result_type == PLIST_KEY && | ||
| 250 | value_type == PLIST_STRING && !strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { | ||
| 251 | log_debug_msg("lockdownd_hello(): success\n"); | ||
| 252 | ret = IPHONE_E_SUCCESS; | ||
| 244 | } | 253 | } |
| 245 | 254 | ||
| 246 | free_dictionary(dictionary); | ||
| 247 | return ret; | 255 | return ret; |
| 248 | } | 256 | } |
| 249 | 257 | ||
