summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-11-19 22:03:21 +0100
committerGravatar Nikias Bassen2013-11-19 22:03:21 +0100
commit26f34f031287b232b45df00e566c356fb95c399a (patch)
treeb2ffeec94567ace3be2632fc8b2b75fafd9de479
parent992d1815114245028a1691788e3fca92e90f3906 (diff)
downloadidevicerestore-26f34f031287b232b45df00e566c356fb95c399a.tar.gz
idevicerestore-26f34f031287b232b45df00e566c356fb95c399a.tar.bz2
common: Add plist_dict_merge() helper to merge dictionaries
-rw-r--r--src/common.c26
-rw-r--r--src/common.h2
2 files changed, 28 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c
index 6c2b613..426b96f 100644
--- a/src/common.c
+++ b/src/common.c
@@ -262,3 +262,29 @@ void idevicerestore_progress(struct idevicerestore_client_t* client, int step, d
}
}
}
+
+void plist_dict_merge(plist_t* dictionary, plist_t node)
+{
+ if (dictionary == NULL || (plist_get_node_type(*dictionary) != PLIST_DICT))
+ return;
+
+ char* key = NULL;
+ plist_dict_iter it = NULL;
+ plist_t subnode = NULL;
+ plist_dict_new_iter(node, &it);
+ plist_dict_next_item(node, it, &key, &subnode);
+
+ while (subnode)
+ {
+ if (plist_dict_get_item(*dictionary, key) != NULL)
+ plist_dict_remove_item(*dictionary, key);
+
+ plist_dict_insert_item(*dictionary, key, plist_copy(subnode));
+ if (key) {
+ free(key);
+ key = NULL;
+ }
+ plist_dict_next_item(node, it, &key, &subnode);
+ }
+ free(it);
+} \ No newline at end of file
diff --git a/src/common.h b/src/common.h
index 2ea4a91..0805e0a 100644
--- a/src/common.h
+++ b/src/common.h
@@ -137,6 +137,8 @@ int mkdir_with_parents(const char *dir, int mode);
void idevicerestore_progress(struct idevicerestore_client_t* client, int step, double progress);
+void plist_dict_merge(plist_t* dictionary, plist_t node);
+
#ifdef __cplusplus
}
#endif