diff options
| author | 2009-10-11 14:00:31 +0200 | |
|---|---|---|
| committer | 2009-10-11 14:00:31 +0200 | |
| commit | 583bb249458fcca6cdf2581896681e618cf4547e (patch) | |
| tree | b46b47170728b3b063cc2620c7ed7b7f987e0ad7 /src | |
| parent | 120b7348e7b9d4c92e463590de5a4de4e6bc1228 (diff) | |
| download | libplist-583bb249458fcca6cdf2581896681e618cf4547e.tar.gz libplist-583bb249458fcca6cdf2581896681e618cf4547e.tar.bz2 | |
Add function to change a node's type.
Diffstat (limited to 'src')
| -rw-r--r-- | src/plist.c | 38 |
1 files changed, 35 insertions, 3 deletions
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 | ||
| 47 | static void plist_free_node(GNode * node, gpointer none) | 47 | static 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 | |||
| 65 | static 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 | ||
| 672 | void 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 | |||
| 667 | void plist_set_key_val(plist_t node, const char *val) | 699 | void 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)); |
