diff options
| author | 2008-11-30 23:33:39 +0100 | |
|---|---|---|
| committer | 2008-11-30 23:33:39 +0100 | |
| commit | 3d08602c6e5c86538e447fccd774a0eac0391868 (patch) | |
| tree | c08b26616a9bd245ec7fd4ce92905b602260016c /src | |
| parent | d560cf5a15d1aef74e95b208ed69b7d324d94354 (diff) | |
| download | libimobiledevice-3d08602c6e5c86538e447fccd774a0eac0391868.tar.gz libimobiledevice-3d08602c6e5c86538e447fccd774a0eac0391868.tar.bz2 | |
migrate lockdownd_generic_get_value to new plisy API.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lockdown.c | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 2906fdf..1782d45 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -267,26 +267,27 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 267 | { | 267 | { |
| 268 | if (!control || !req_key || !value || (value && *value)) | 268 | if (!control || !req_key || !value || (value && *value)) |
| 269 | return IPHONE_E_INVALID_ARG; | 269 | return IPHONE_E_INVALID_ARG; |
| 270 | xmlDocPtr plist = new_plist(); | 270 | plist_t plist = NULL; |
| 271 | xmlNode *dict = NULL; | 271 | dict_t dict = NULL; |
| 272 | xmlNode *key = NULL;; | ||
| 273 | char **dictionary = NULL; | ||
| 274 | int bytes = 0, i = 0; | 272 | int bytes = 0, i = 0; |
| 275 | char *XML_content = NULL; | 273 | char *XML_content = NULL; |
| 276 | uint32_t length = 0; | 274 | uint32_t length = 0; |
| 277 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 275 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 278 | 276 | ||
| 279 | /* Setup DevicePublicKey request plist */ | 277 | /* Setup DevicePublicKey request plist */ |
| 280 | dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); | 278 | plist_new_plist(&plist); |
| 281 | key = add_key_str_dict_element(plist, dict, req_key, req_string, 1); | 279 | plist_new_dict_in_plist(plist, &dict); |
| 282 | key = add_key_str_dict_element(plist, dict, "Request", "GetValue", 1); | 280 | plist_add_dict_element(dict, req_key, PLIST_STRING, (void *) req_string); |
| 283 | xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); | 281 | plist_add_dict_element(dict, "Request", PLIST_STRING, (void *) "GetValue"); |
| 282 | plist_to_xml(plist, &XML_content, &length); | ||
| 284 | 283 | ||
| 285 | /* send to iPhone */ | 284 | /* send to iPhone */ |
| 285 | log_debug_msg("Send msg :\nsize : %i\nxml : %s", length, XML_content); | ||
| 286 | ret = iphone_lckd_send(control, XML_content, length, &bytes); | 286 | ret = iphone_lckd_send(control, XML_content, length, &bytes); |
| 287 | 287 | ||
| 288 | xmlFree(XML_content); | 288 | xmlFree(XML_content); |
| 289 | xmlFreeDoc(plist); | 289 | XML_content = NULL; |
| 290 | plist_free(plist); | ||
| 290 | plist = NULL; | 291 | plist = NULL; |
| 291 | 292 | ||
| 292 | if (ret != IPHONE_E_SUCCESS) | 293 | if (ret != IPHONE_E_SUCCESS) |
| @@ -294,42 +295,55 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, char *r | |||
| 294 | 295 | ||
| 295 | /* Now get iPhone's answer */ | 296 | /* Now get iPhone's answer */ |
| 296 | ret = iphone_lckd_recv(control, &XML_content, &bytes); | 297 | ret = iphone_lckd_recv(control, &XML_content, &bytes); |
| 298 | log_debug_msg("Receive msg :\nsize : %i\nxml : %s", bytes, XML_content); | ||
| 297 | 299 | ||
| 298 | if (ret != IPHONE_E_SUCCESS) | 300 | if (ret != IPHONE_E_SUCCESS) |
| 299 | return ret; | 301 | return ret; |
| 300 | 302 | ||
| 301 | plist = xmlReadMemory(XML_content, bytes, NULL, NULL, 0); | 303 | xml_to_plist(XML_content, bytes, &plist); |
| 302 | if (!plist) | 304 | if (!plist) |
| 303 | return IPHONE_E_PLIST_ERROR; | 305 | return IPHONE_E_PLIST_ERROR; |
| 304 | dict = xmlDocGetRootElement(plist); | ||
| 305 | for (dict = dict->children; dict; dict = dict->next) { | ||
| 306 | if (!xmlStrcmp(dict->name, "dict")) | ||
| 307 | break; | ||
| 308 | } | ||
| 309 | if (!dict) | ||
| 310 | return IPHONE_E_DICT_ERROR; | ||
| 311 | 306 | ||
| 312 | /* Parse xml to check success and to find public key */ | 307 | plist_t query_node = find_query_node(plist, "Request", "GetValue"); |
| 313 | dictionary = read_dict_element_strings(dict); | 308 | plist_t result_key_node = g_node_next_sibling(query_node); |
| 314 | xmlFreeDoc(plist); | 309 | plist_t result_value_node = g_node_next_sibling(result_key_node); |
| 315 | free(XML_content); | ||
| 316 | 310 | ||
| 317 | int success = 0; | 311 | plist_type result_key_type; |
| 318 | for (i = 0; dictionary[i]; i += 2) { | 312 | plist_type result_value_type; |
| 319 | if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i + 1], "Success")) { | 313 | char *result_key = NULL; |
| 320 | success = 1; | 314 | char *result_value = NULL; |
| 321 | } | 315 | |
| 322 | if (!strcmp(dictionary[i], "Value")) { | 316 | get_type_and_value(result_key_node, &result_key_type, (void *) (&result_key)); |
| 323 | *value = strdup(dictionary[i + 1]); | 317 | get_type_and_value(result_value_node, &result_value_type, (void *) (&result_value)); |
| 324 | } | 318 | |
| 319 | if (result_key_type == PLIST_KEY && | ||
| 320 | result_value_type == PLIST_STRING && !strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { | ||
| 321 | log_debug_msg("lockdownd_generic_get_value(): success\n"); | ||
| 322 | ret = IPHONE_E_SUCCESS; | ||
| 325 | } | 323 | } |
| 326 | 324 | ||
| 327 | if (dictionary) { | 325 | if (ret != IPHONE_E_SUCCESS) { |
| 328 | free_dictionary(dictionary); | 326 | return IPHONE_E_DICT_ERROR; |
| 329 | dictionary = NULL; | ||
| 330 | } | 327 | } |
| 331 | if (success) | 328 | |
| 329 | plist_t value_key_node = g_node_next_sibling(result_key_node); | ||
| 330 | plist_t value_value_node = g_node_next_sibling(value_key_node); | ||
| 331 | plist_type value_key_type; | ||
| 332 | plist_type value_value_type; | ||
| 333 | char *value_key = NULL; | ||
| 334 | char *value_value = NULL; | ||
| 335 | |||
| 336 | get_type_and_value(value_key_node, &value_key_type, (void *) (&value_key)); | ||
| 337 | get_type_and_value(value_value_node, &value_value_type, (void *) (&value_value)); | ||
| 338 | |||
| 339 | if (value_key_type == PLIST_KEY && !strcmp(result_key, "Value")) { | ||
| 340 | log_debug_msg("lockdownd_generic_get_value(): success\n"); | ||
| 341 | *value = value_value; | ||
| 332 | ret = IPHONE_E_SUCCESS; | 342 | ret = IPHONE_E_SUCCESS; |
| 343 | } | ||
| 344 | |||
| 345 | plist_free(plist); | ||
| 346 | free(XML_content); | ||
| 333 | return ret; | 347 | return ret; |
| 334 | } | 348 | } |
| 335 | 349 | ||
