summaryrefslogtreecommitdiffstats
path: root/src/xplist.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-09-16 06:03:57 +0200
committerGravatar Nikias Bassen2012-09-16 06:03:57 +0200
commit817749dd4e27768da64e3883fe04580cd22461a8 (patch)
tree1fbe11711f085da8db8b128a9f09eebd1aa06daa /src/xplist.c
parentfee6a9eacd62ddc7ce969413dd4083d4f4804120 (diff)
downloadlibplist-817749dd4e27768da64e3883fe04580cd22461a8.tar.gz
libplist-817749dd4e27768da64e3883fe04580cd22461a8.tar.bz2
implemented handling of UID keyed encoding type
Diffstat (limited to 'src/xplist.c')
-rw-r--r--src/xplist.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/xplist.c b/src/xplist.c
index ba312a1..b551179 100644
--- a/src/xplist.c
+++ b/src/xplist.c
@@ -126,6 +126,25 @@ static xmlDocPtr new_xml_plist(void)
return plist_xml;
}
+static struct node_t* new_key_node(const char* name)
+{
+ plist_data_t data = plist_new_plist_data();
+ data->type = PLIST_KEY;
+ int size = strlen(name);
+ data->strval = strdup(name);
+ data->length = size;
+ return node_create(NULL, data);
+}
+
+static struct node_t* new_uint_node(uint64_t uint)
+{
+ plist_data_t data = plist_new_plist_data();
+ data->type = PLIST_UINT;
+ data->intval = uint;
+ data->length = sizeof(uint64_t);
+ return node_create(NULL, data);
+}
+
static void node_to_xml(node_t* node, void *xml_struct)
{
struct xml_node *xstruct = NULL;
@@ -133,6 +152,7 @@ static void node_to_xml(node_t* node, void *xml_struct)
xmlNodePtr child_node = NULL;
char isStruct = FALSE;
+ char isUIDNode = FALSE;
const xmlChar *tag = NULL;
char *val = NULL;
@@ -214,6 +234,15 @@ static void node_to_xml(node_t* node, void *xml_struct)
}
}
break;
+ case PLIST_UID:
+ // special case for keyed encoding
+ tag = XPLIST_DICT;
+ isStruct = TRUE;
+ isUIDNode = TRUE;
+ node_data->type = PLIST_DICT;
+ node_attach(node, new_key_node("CF$UID"));
+ node_attach(node, new_uint_node(node_data->intval));
+ break;
default:
break;
}
@@ -256,6 +285,17 @@ static void node_to_xml(node_t* node, void *xml_struct)
xmlNodeAddContent(child_node, BAD_CAST("\t"));
}
}
+ if (isUIDNode)
+ {
+ unsigned int num = node_n_children(node);
+ unsigned int i;
+ for (i = num; i > 0; i--) {
+ node_t* ch = node_nth_child(node, i-1);
+ node_detach(node, ch);
+ node_destroy(ch);
+ }
+ node_data->type = PLIST_UID;
+ }
return;
}
@@ -406,6 +446,21 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node)
{
data->type = PLIST_DICT;
xml_to_node(node, &subnode);
+ if (plist_get_node_type(subnode) == PLIST_DICT) {
+ if (plist_dict_get_size(subnode) == 1) {
+ plist_t uid = plist_dict_get_item(subnode, "CF$UID");
+ if (uid) {
+ uint64_t val = 0;
+ plist_get_uint_val(uid, &val);
+ plist_dict_remove_item(subnode, "CF$UID");
+ plist_data_t nodedata = plist_get_data((node_t*)subnode);
+ free(nodedata->buff);
+ nodedata->type = PLIST_UID;
+ nodedata->length = sizeof(uint64_t);
+ nodedata->intval = val;
+ }
+ }
+ }
continue;
}
}