summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-06-05 23:41:35 +0200
committerGravatar Nikias Bassen2010-06-05 23:41:35 +0200
commite5d4b8e126b0160c80103b814ef59a3f1319f22e (patch)
treebbdd8dabd2c13e4f544848c4e0b57bf31d5155d3
parent7a2811b76793b262237b4b61bc777edf9ec37257 (diff)
downloadlibimobiledevice-e5d4b8e126b0160c80103b814ef59a3f1319f22e.tar.gz
libimobiledevice-e5d4b8e126b0160c80103b814ef59a3f1319f22e.tar.bz2
Added function to fetch device values from the QueryType response
-rw-r--r--include/libimobiledevice/restore.h1
-rw-r--r--src/restore.c46
-rw-r--r--src/restore.h1
3 files changed, 46 insertions, 2 deletions
diff --git a/include/libimobiledevice/restore.h b/include/libimobiledevice/restore.h
index 6f3ff53..9c30b03 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_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);
restored_error_t restored_goodbye(restored_client_t client);
diff --git a/src/restore.c b/src/restore.c
index 8acefef..ab14c28 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -119,6 +119,10 @@ restored_error_t restored_client_free(restored_client_t client)
if (client->label) {
free(client->label);
}
+
+ if (client->info) {
+ plist_free(client->info);
+ }
free(client);
return ret;
@@ -154,6 +158,7 @@ restored_error_t restored_receive(restored_client_t client, plist_t *plist)
{
if (!client || !plist || (plist && *plist))
return RESTORE_E_INVALID_ARG;
+
restored_error_t ret = RESTORE_E_SUCCESS;
property_list_service_error_t err;
@@ -229,6 +234,9 @@ restored_error_t restored_query_type(restored_client_t client, char **type, uint
ret = RESTORE_E_UNKNOWN_ERROR;
if (restored_check_result(dict) == RESULT_SUCCESS) {
+ /* save our device information info */
+ client->info = dict;
+
/* return the type if requested */
if (type != NULL) {
plist_t type_node = plist_dict_get_item(dict, "Type");
@@ -247,13 +255,47 @@ restored_error_t restored_query_type(restored_client_t client, char **type, uint
ret = RESTORE_E_UNKNOWN_ERROR;
}
- plist_free(dict);
- dict = NULL;
return ret;
}
/**
+ * Retrieves a value from information plist specified by a key.
+ *
+ * @param client An initialized restored client.
+ * @param key The key name to request or NULL to query for all keys
+ * @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_get_value(restored_client_t client, const char *key, plist_t *value)
+{
+ if (!client || !value || (value && *value))
+ return RESTORE_E_INVALID_ARG;
+
+ if (!client->info)
+ return RESTORE_E_NOT_ENOUGH_DATA;
+
+ restored_error_t ret = RESTORE_E_SUCCESS;
+ plist_t item = NULL;
+
+ if (!key) {
+ *value = plist_copy(client->info);
+ return RESTORE_E_SUCCESS;
+ } else {
+ item = plist_dict_get_item(client->info, key);
+ }
+
+ if (item) {
+ *value = plist_copy(item);
+ } else {
+ ret = RESTORE_E_PLIST_ERROR;
+ }
+
+ return ret;
+}
+
+/**
* Creates a new restored client for the device.
*
* @param device The device to create a restored client for
diff --git a/src/restore.h b/src/restore.h
index 8b4cbbb..d790d01 100644
--- a/src/restore.h
+++ b/src/restore.h
@@ -31,6 +31,7 @@ struct restored_client_private {
property_list_service_client_t parent;
char *uuid;
char *label;
+ plist_t info;
};
#endif