summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2012-03-08 22:23:36 +0100
committerGravatar Martin Szulecki2012-03-08 22:23:36 +0100
commitb586203dbef26f9e94325b57867478eda504e5a1 (patch)
treeb70abe91ddc719eca913132890d3e14adb010285
parent96e06ea1e4dabd2a3d4b51c799842dee2e279f30 (diff)
downloadlibimobiledevice-b586203dbef26f9e94325b57867478eda504e5a1.tar.gz
libimobiledevice-b586203dbef26f9e94325b57867478eda504e5a1.tar.bz2
restored: Add restored_query_value() to query for values in restore mode
-rw-r--r--include/libimobiledevice/restore.h1
-rw-r--r--src/restore.c51
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
restored_error_t restored_client_free(restored_client_t client);
restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version);
+restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value);
restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) ;
restored_error_t restored_send(restored_client_t client, plist_t plist);
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
}
/**
+ * Queries a value from the device specified by a key.
+ *
+ * @param client An initialized restored client.
+ * @param key The key name to request
+ * @param value A plist node representing the result value node
+ *
+ * @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
+ */
+restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value)
+{
+ if (!client || !key)
+ return RESTORE_E_INVALID_ARG;
+
+ plist_t dict = NULL;
+ restored_error_t ret = RESTORE_E_UNKNOWN_ERROR;
+
+ /* setup request plist */
+ dict = plist_new_dict();
+ plist_dict_add_label(dict, client->label);
+ if (key) {
+ plist_dict_insert_item(dict,"QueryKey", plist_new_string(key));
+ }
+ plist_dict_insert_item(dict,"Request", plist_new_string("QueryValue"));
+
+ /* send to device */
+ ret = restored_send(client, dict);
+
+ plist_free(dict);
+ dict = NULL;
+
+ if (ret != RESTORE_E_SUCCESS)
+ return ret;
+
+ /* Now get device's answer */
+ ret = restored_receive(client, &dict);
+ if (ret != RESTORE_E_SUCCESS)
+ return ret;
+
+ plist_t value_node = plist_dict_get_item(dict, key);
+ if (value_node) {
+ debug_info("has a value");
+ *value = plist_copy(value_node);
+ } else {
+ ret = RESTORE_E_PLIST_ERROR;
+ }
+
+ plist_free(dict);
+ return ret;
+}
+
+/**
* Retrieves a value from information plist specified by a key.
*
* @param client An initialized restored client.