diff options
Diffstat (limited to 'src/xplist.c')
-rw-r--r-- | src/xplist.c | 55 |
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; } } |