summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/plist/plist.h8
-rw-r--r--src/plist.c38
2 files changed, 43 insertions, 3 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index bfd934f..55ae9e7 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -411,6 +411,14 @@ extern "C" {
411 ********************************************/ 411 ********************************************/
412 412
413/** 413/**
414 * Forces type of node. Changing type of structured nodes is only allowed if node is empty.
415 * Reset value of node;
416 * @param node the node
417 * @param type the key value
418 */
419 PLIST_API void plist_set_type(plist_t node, plist_type type);
420
421/**
414 * Set the value of a node. 422 * Set the value of a node.
415 * Forces type of node to #PLIST_KEY 423 * Forces type of node to #PLIST_KEY
416 * 424 *
diff --git a/src/plist.c b/src/plist.c
index 3b0387e..df98a7a 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -44,10 +44,8 @@ plist_data_t plist_new_plist_data(void)
44 return data; 44 return data;
45} 45}
46 46
47static void plist_free_node(GNode * node, gpointer none) 47static void plist_free_data(plist_data_t data)
48{ 48{
49 g_node_unlink(node);
50 plist_data_t data = plist_get_data(node);
51 if (data) { 49 if (data) {
52 switch (data->type) { 50 switch (data->type) {
53 case PLIST_KEY: 51 case PLIST_KEY:
@@ -62,6 +60,13 @@ static void plist_free_node(GNode * node, gpointer none)
62 } 60 }
63 free(data); 61 free(data);
64 } 62 }
63}
64
65static void plist_free_node(GNode * node, gpointer none)
66{
67 g_node_unlink(node);
68 plist_data_t data = plist_get_data(node);
69 plist_free_data(data);
65 node->data = NULL; 70 node->data = NULL;
66 g_node_children_foreach(node, G_TRAVERSE_ALL, plist_free_node, NULL); 71 g_node_children_foreach(node, G_TRAVERSE_ALL, plist_free_node, NULL);
67} 72}
@@ -664,6 +669,33 @@ static plist_t plist_set_element_val(plist_t node, plist_type type, const void *
664 } 669 }
665} 670}
666 671
672void plist_set_type(plist_t node, plist_type type)
673{
674 if ( g_node_n_children(node) == 0 ) {
675 plist_data_t data = plist_get_data(node);
676 plist_free_data( data );
677 data = plist_new_plist_data();
678 data->type = type;
679 switch(type){
680 case PLIST_BOOLEAN:
681 data->length = sizeof(uint8_t);
682 break;
683 case PLIST_UINT:
684 data->length = sizeof(uint64_t);
685 break;
686 case PLIST_REAL:
687 data->length = sizeof(double);
688 break;
689 case PLIST_DATE:
690 data->length = sizeof(GTimeVal);
691 break;
692 default:
693 data->length = 0;
694 break;
695 }
696 }
697}
698
667void plist_set_key_val(plist_t node, const char *val) 699void plist_set_key_val(plist_t node, const char *val)
668{ 700{
669 plist_set_element_val(node, PLIST_KEY, val, strlen(val)); 701 plist_set_element_val(node, PLIST_KEY, val, strlen(val));