diff options
| -rw-r--r-- | include/libimobiledevice/restore.h | 1 | ||||
| -rw-r--r-- | src/restore.c | 51 |
2 files changed, 52 insertions, 0 deletions
diff --git a/include/libimobiledevice/restore.h b/include/libimobiledevice/restore.h index aa8233f..a0a1b77 100644 --- a/include/libimobiledevice/restore.h +++ b/include/libimobiledevice/restore.h | |||
| @@ -54,6 +54,7 @@ restored_error_t restored_client_new(idevice_t device, restored_client_t *client | |||
| 54 | restored_error_t restored_client_free(restored_client_t client); | 54 | restored_error_t restored_client_free(restored_client_t client); |
| 55 | 55 | ||
| 56 | restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version); | 56 | restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version); |
| 57 | restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value); | ||
| 57 | restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) ; | 58 | restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) ; |
| 58 | restored_error_t restored_send(restored_client_t client, plist_t plist); | 59 | restored_error_t restored_send(restored_client_t client, plist_t plist); |
| 59 | restored_error_t restored_receive(restored_client_t client, plist_t *plist); | 60 | restored_error_t restored_receive(restored_client_t client, plist_t *plist); |
diff --git a/src/restore.c b/src/restore.c index 10642da..031eaea 100644 --- a/src/restore.c +++ b/src/restore.c | |||
| @@ -268,6 +268,57 @@ restored_error_t restored_query_type(restored_client_t client, char **type, uint | |||
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | /** | 270 | /** |
| 271 | * Queries a value from the device specified by a key. | ||
| 272 | * | ||
| 273 | * @param client An initialized restored client. | ||
| 274 | * @param key The key name to request | ||
| 275 | * @param value A plist node representing the result value node | ||
| 276 | * | ||
| 277 | * @return RESTORE_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, RESTORE_E_PLIST_ERROR if value for key can't be found | ||
| 278 | */ | ||
| 279 | restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value) | ||
| 280 | { | ||
| 281 | if (!client || !key) | ||
| 282 | return RESTORE_E_INVALID_ARG; | ||
| 283 | |||
| 284 | plist_t dict = NULL; | ||
| 285 | restored_error_t ret = RESTORE_E_UNKNOWN_ERROR; | ||
| 286 | |||
| 287 | /* setup request plist */ | ||
| 288 | dict = plist_new_dict(); | ||
| 289 | plist_dict_add_label(dict, client->label); | ||
| 290 | if (key) { | ||
| 291 | plist_dict_insert_item(dict,"QueryKey", plist_new_string(key)); | ||
| 292 | } | ||
| 293 | plist_dict_insert_item(dict,"Request", plist_new_string("QueryValue")); | ||
| 294 | |||
| 295 | /* send to device */ | ||
| 296 | ret = restored_send(client, dict); | ||
| 297 | |||
| 298 | plist_free(dict); | ||
| 299 | dict = NULL; | ||
| 300 | |||
| 301 | if (ret != RESTORE_E_SUCCESS) | ||
| 302 | return ret; | ||
| 303 | |||
| 304 | /* Now get device's answer */ | ||
| 305 | ret = restored_receive(client, &dict); | ||
| 306 | if (ret != RESTORE_E_SUCCESS) | ||
| 307 | return ret; | ||
| 308 | |||
| 309 | plist_t value_node = plist_dict_get_item(dict, key); | ||
| 310 | if (value_node) { | ||
| 311 | debug_info("has a value"); | ||
| 312 | *value = plist_copy(value_node); | ||
| 313 | } else { | ||
| 314 | ret = RESTORE_E_PLIST_ERROR; | ||
| 315 | } | ||
| 316 | |||
| 317 | plist_free(dict); | ||
| 318 | return ret; | ||
| 319 | } | ||
| 320 | |||
| 321 | /** | ||
| 271 | * Retrieves a value from information plist specified by a key. | 322 | * Retrieves a value from information plist specified by a key. |
| 272 | * | 323 | * |
| 273 | * @param client An initialized restored client. | 324 | * @param client An initialized restored client. |
