From 817749dd4e27768da64e3883fe04580cd22461a8 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 16 Sep 2012 06:03:57 +0200 Subject: implemented handling of UID keyed encoding type --- src/xplist.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/xplist.c') 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; } } -- cgit v1.1-32-gdbae