diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bplist.c | 52 | ||||
| -rw-r--r-- | src/plist.c | 103 | ||||
| -rw-r--r-- | src/plist.h | 41 | ||||
| -rw-r--r-- | src/xplist.c | 6 |
4 files changed, 110 insertions, 92 deletions
diff --git a/src/bplist.c b/src/bplist.c index a5b1c9b..48b996d 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -83,9 +83,9 @@ void byte_convert(char *address, size_t size) | |||
| 83 | #define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= 1<<32 ? 4 : 8))) | 83 | #define get_needed_bytes(x) (x <= 1<<8 ? 1 : ( x <= 1<<16 ? 2 : ( x <= 1<<32 ? 4 : 8))) |
| 84 | #define get_real_bytes(x) (x >> 32 ? 4 : 8) | 84 | #define get_real_bytes(x) (x >> 32 ? 4 : 8) |
| 85 | 85 | ||
| 86 | GNode *parse_uint_node(char *bnode, uint8_t size, char **next_object) | 86 | plist_t parse_uint_node(char *bnode, uint8_t size, char **next_object) |
| 87 | { | 87 | { |
| 88 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 88 | plist_data_t data = plist_new_plist_data(); |
| 89 | 89 | ||
| 90 | size = 1 << size; // make length less misleading | 90 | size = 1 << size; // make length less misleading |
| 91 | switch (size) { | 91 | switch (size) { |
| @@ -114,9 +114,9 @@ GNode *parse_uint_node(char *bnode, uint8_t size, char **next_object) | |||
| 114 | return g_node_new(data); | 114 | return g_node_new(data); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | GNode *parse_real_node(char *bnode, uint8_t size) | 117 | plist_t parse_real_node(char *bnode, uint8_t size) |
| 118 | { | 118 | { |
| 119 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 119 | plist_data_t data = plist_new_plist_data(); |
| 120 | 120 | ||
| 121 | size = 1 << size; // make length less misleading | 121 | size = 1 << size; // make length less misleading |
| 122 | switch (size) { | 122 | switch (size) { |
| @@ -136,9 +136,9 @@ GNode *parse_real_node(char *bnode, uint8_t size) | |||
| 136 | return g_node_new(data); | 136 | return g_node_new(data); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | GNode *parse_string_node(char *bnode, uint8_t size) | 139 | plist_t parse_string_node(char *bnode, uint8_t size) |
| 140 | { | 140 | { |
| 141 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 141 | plist_data_t data = plist_new_plist_data(); |
| 142 | 142 | ||
| 143 | data->type = PLIST_STRING; | 143 | data->type = PLIST_STRING; |
| 144 | data->strval = (char *) malloc(sizeof(char) * (size + 1)); | 144 | data->strval = (char *) malloc(sizeof(char) * (size + 1)); |
| @@ -148,9 +148,9 @@ GNode *parse_string_node(char *bnode, uint8_t size) | |||
| 148 | return g_node_new(data); | 148 | return g_node_new(data); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | GNode *parse_unicode_node(char *bnode, uint8_t size) | 151 | plist_t parse_unicode_node(char *bnode, uint8_t size) |
| 152 | { | 152 | { |
| 153 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 153 | plist_data_t data = plist_new_plist_data(); |
| 154 | 154 | ||
| 155 | data->type = PLIST_UNICODE; | 155 | data->type = PLIST_UNICODE; |
| 156 | data->unicodeval = (wchar_t *) malloc(sizeof(wchar_t) * (size + 1)); | 156 | data->unicodeval = (wchar_t *) malloc(sizeof(wchar_t) * (size + 1)); |
| @@ -160,9 +160,9 @@ GNode *parse_unicode_node(char *bnode, uint8_t size) | |||
| 160 | return g_node_new(data); | 160 | return g_node_new(data); |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | GNode *parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) | 163 | plist_t parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) |
| 164 | { | 164 | { |
| 165 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 165 | plist_data_t data = plist_new_plist_data(); |
| 166 | 166 | ||
| 167 | data->type = PLIST_DATA; | 167 | data->type = PLIST_DATA; |
| 168 | data->length = size; | 168 | data->length = size; |
| @@ -172,9 +172,9 @@ GNode *parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) | |||
| 172 | return g_node_new(data); | 172 | return g_node_new(data); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| 175 | GNode *parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) | 175 | plist_t parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) |
| 176 | { | 176 | { |
| 177 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 177 | plist_data_t data = plist_new_plist_data(); |
| 178 | 178 | ||
| 179 | data->type = PLIST_DICT; | 179 | data->type = PLIST_DICT; |
| 180 | data->length = size; | 180 | data->length = size; |
| @@ -184,9 +184,9 @@ GNode *parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) | |||
| 184 | return g_node_new(data); | 184 | return g_node_new(data); |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | GNode *parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) | 187 | plist_t parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) |
| 188 | { | 188 | { |
| 189 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 189 | plist_data_t data = plist_new_plist_data(); |
| 190 | 190 | ||
| 191 | data->type = PLIST_ARRAY; | 191 | data->type = PLIST_ARRAY; |
| 192 | data->length = size; | 192 | data->length = size; |
| @@ -198,7 +198,7 @@ GNode *parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) | |||
| 198 | 198 | ||
| 199 | 199 | ||
| 200 | 200 | ||
| 201 | GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object) | 201 | plist_t parse_bin_node(char *object, uint8_t dict_size, char **next_object) |
| 202 | { | 202 | { |
| 203 | if (!object) | 203 | if (!object) |
| 204 | return NULL; | 204 | return NULL; |
| @@ -214,7 +214,7 @@ GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object) | |||
| 214 | 214 | ||
| 215 | case BPLIST_TRUE: | 215 | case BPLIST_TRUE: |
| 216 | { | 216 | { |
| 217 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 217 | plist_data_t data = plist_new_plist_data(); |
| 218 | data->type = PLIST_BOOLEAN; | 218 | data->type = PLIST_BOOLEAN; |
| 219 | data->boolval = TRUE; | 219 | data->boolval = TRUE; |
| 220 | return g_node_new(data); | 220 | return g_node_new(data); |
| @@ -222,7 +222,7 @@ GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object) | |||
| 222 | 222 | ||
| 223 | case BPLIST_FALSE: | 223 | case BPLIST_FALSE: |
| 224 | { | 224 | { |
| 225 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 225 | plist_data_t data = plist_new_plist_data(); |
| 226 | data->type = PLIST_BOOLEAN; | 226 | data->type = PLIST_BOOLEAN; |
| 227 | data->boolval = FALSE; | 227 | data->boolval = FALSE; |
| 228 | return g_node_new(data); | 228 | return g_node_new(data); |
| @@ -299,8 +299,8 @@ GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object) | |||
| 299 | 299 | ||
| 300 | gpointer copy_plist_data(gconstpointer src, gpointer data) | 300 | gpointer copy_plist_data(gconstpointer src, gpointer data) |
| 301 | { | 301 | { |
| 302 | struct plist_data *srcdata = (struct plist_data *) src; | 302 | plist_data_t srcdata = (plist_data_t) src; |
| 303 | struct plist_data *dstdata = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 303 | plist_data_t dstdata = plist_new_plist_data(); |
| 304 | 304 | ||
| 305 | dstdata->type = srcdata->type; | 305 | dstdata->type = srcdata->type; |
| 306 | dstdata->length = srcdata->length; | 306 | dstdata->length = srcdata->length; |
| @@ -336,7 +336,7 @@ gpointer copy_plist_data(gconstpointer src, gpointer data) | |||
| 336 | return dstdata; | 336 | return dstdata; |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist) | 339 | void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist) |
| 340 | { | 340 | { |
| 341 | //first check we have enough data | 341 | //first check we have enough data |
| 342 | if (!(length >= BPLIST_MAGIC_SIZE + BPLIST_VERSION_SIZE + BPLIST_TRL_SIZE)) | 342 | if (!(length >= BPLIST_MAGIC_SIZE + BPLIST_VERSION_SIZE + BPLIST_TRL_SIZE)) |
| @@ -393,7 +393,7 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist) | |||
| 393 | for (i = 0; i < num_objects; i++) { | 393 | for (i = 0; i < num_objects; i++) { |
| 394 | 394 | ||
| 395 | log_debug_msg("parse_nodes: on node %i\n", i); | 395 | log_debug_msg("parse_nodes: on node %i\n", i); |
| 396 | struct plist_data *data = (struct plist_data *) nodeslist[i]->data; | 396 | plist_data_t data = plist_get_data(nodeslist[i]); |
| 397 | 397 | ||
| 398 | switch (data->type) { | 398 | switch (data->type) { |
| 399 | case PLIST_DICT: | 399 | case PLIST_DICT: |
| @@ -406,7 +406,7 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist) | |||
| 406 | index2 = swap_n_bytes(data->buff + str_j, dict_param_size); | 406 | index2 = swap_n_bytes(data->buff + str_j, dict_param_size); |
| 407 | 407 | ||
| 408 | //first one is actually a key | 408 | //first one is actually a key |
| 409 | ((struct plist_data *) nodeslist[index1]->data)->type = PLIST_KEY; | 409 | plist_get_data(nodeslist[index1])->type = PLIST_KEY; |
| 410 | 410 | ||
| 411 | if (G_NODE_IS_ROOT(nodeslist[index1])) | 411 | if (G_NODE_IS_ROOT(nodeslist[index1])) |
| 412 | g_node_append(nodeslist[i], nodeslist[index1]); | 412 | g_node_append(nodeslist[i], nodeslist[index1]); |
| @@ -446,7 +446,7 @@ void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist) | |||
| 446 | 446 | ||
| 447 | guint plist_data_hash(gconstpointer key) | 447 | guint plist_data_hash(gconstpointer key) |
| 448 | { | 448 | { |
| 449 | struct plist_data *data = (struct plist_data *) ((GNode *) key)->data; | 449 | plist_data_t data = plist_get_data(key); |
| 450 | 450 | ||
| 451 | guint hash = data->type; | 451 | guint hash = data->type; |
| 452 | guint i = 0; | 452 | guint i = 0; |
| @@ -497,8 +497,8 @@ gboolean plist_data_compare(gconstpointer a, gconstpointer b) | |||
| 497 | if (!((GNode *) a)->data || !((GNode *) b)->data) | 497 | if (!((GNode *) a)->data || !((GNode *) b)->data) |
| 498 | return FALSE; | 498 | return FALSE; |
| 499 | 499 | ||
| 500 | struct plist_data *val_a = (struct plist_data *) ((GNode *) a)->data; | 500 | plist_data_t val_a = plist_get_data(a); |
| 501 | struct plist_data *val_b = (struct plist_data *) ((GNode *) b)->data; | 501 | plist_data_t val_b = plist_get_data(b); |
| 502 | 502 | ||
| 503 | if (val_a->type != val_b->type) | 503 | if (val_a->type != val_b->type) |
| 504 | return FALSE; | 504 | return FALSE; |
| @@ -718,7 +718,7 @@ void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 718 | for (i = 0; i < num_objects; i++) { | 718 | for (i = 0; i < num_objects; i++) { |
| 719 | 719 | ||
| 720 | offsets[i] = bplist_buff->len; | 720 | offsets[i] = bplist_buff->len; |
| 721 | struct plist_data *data = (struct plist_data *) ((GNode *) g_ptr_array_index(objects, i))->data; | 721 | plist_data_t data = plist_get_data(g_ptr_array_index(objects, i)); |
| 722 | 722 | ||
| 723 | switch (data->type) { | 723 | switch (data->type) { |
| 724 | case PLIST_BOOLEAN: | 724 | case PLIST_BOOLEAN: |
diff --git a/src/plist.c b/src/plist.c index 932ea5e..172eceb 100644 --- a/src/plist.c +++ b/src/plist.c | |||
| @@ -28,23 +28,45 @@ | |||
| 28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
| 29 | #include <stdio.h> | 29 | #include <stdio.h> |
| 30 | 30 | ||
| 31 | plist_t plist_new_node(plist_data_t data) | ||
| 32 | { | ||
| 33 | return (plist_t)g_node_new(data); | ||
| 34 | } | ||
| 35 | |||
| 36 | plist_data_t plist_get_data(plist_t node) | ||
| 37 | { | ||
| 38 | if (!node) | ||
| 39 | return NULL; | ||
| 40 | return ((GNode*)node)->data; | ||
| 41 | } | ||
| 42 | |||
| 43 | plist_data_t plist_new_plist_data() | ||
| 44 | { | ||
| 45 | plist_data_t data = (plist_data_t) calloc(sizeof(struct plist_data_s), 1); | ||
| 46 | return data; | ||
| 47 | } | ||
| 48 | |||
| 49 | void plist_free_plist_data(plist_data_t data) | ||
| 50 | { | ||
| 51 | free(data); | ||
| 52 | } | ||
| 31 | 53 | ||
| 32 | void plist_new_dict(plist_t * plist) | 54 | void plist_new_dict(plist_t * plist) |
| 33 | { | 55 | { |
| 34 | if (*plist != NULL) | 56 | if (*plist != NULL) |
| 35 | return; | 57 | return; |
| 36 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 58 | plist_data_t data = plist_new_plist_data(); |
| 37 | data->type = PLIST_DICT; | 59 | data->type = PLIST_DICT; |
| 38 | *plist = g_node_new(data); | 60 | *plist = plist_new_node(data); |
| 39 | } | 61 | } |
| 40 | 62 | ||
| 41 | void plist_new_array(plist_t * plist) | 63 | void plist_new_array(plist_t * plist) |
| 42 | { | 64 | { |
| 43 | if (*plist != NULL) | 65 | if (*plist != NULL) |
| 44 | return; | 66 | return; |
| 45 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 67 | plist_data_t data = plist_new_plist_data(); |
| 46 | data->type = PLIST_ARRAY; | 68 | data->type = PLIST_ARRAY; |
| 47 | *plist = g_node_new(data); | 69 | *plist = plist_new_node(data); |
| 48 | } | 70 | } |
| 49 | 71 | ||
| 50 | void plist_new_dict_in_plist(plist_t plist, plist_t * dict) | 72 | void plist_new_dict_in_plist(plist_t plist, plist_t * dict) |
| @@ -52,9 +74,9 @@ void plist_new_dict_in_plist(plist_t plist, plist_t * dict) | |||
| 52 | if (!plist || *dict) | 74 | if (!plist || *dict) |
| 53 | return; | 75 | return; |
| 54 | 76 | ||
| 55 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 77 | plist_data_t data = plist_new_plist_data(); |
| 56 | data->type = PLIST_DICT; | 78 | data->type = PLIST_DICT; |
| 57 | *dict = g_node_new(data); | 79 | *dict = plist_new_node(data); |
| 58 | g_node_append(plist, *dict); | 80 | g_node_append(plist, *dict); |
| 59 | } | 81 | } |
| 60 | 82 | ||
| @@ -72,14 +94,14 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu | |||
| 72 | if (!dict || !key || !value) | 94 | if (!dict || !key || !value) |
| 73 | return; | 95 | return; |
| 74 | 96 | ||
| 75 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 97 | plist_data_t data = plist_new_plist_data(); |
| 76 | data->type = PLIST_KEY; | 98 | data->type = PLIST_KEY; |
| 77 | data->strval = strdup(key); | 99 | data->strval = strdup(key); |
| 78 | GNode *keynode = g_node_new(data); | 100 | plist_t keynode = plist_new_node(data); |
| 79 | g_node_append(dict, keynode); | 101 | g_node_append(dict, keynode); |
| 80 | 102 | ||
| 81 | //now handle value | 103 | //now handle value |
| 82 | struct plist_data *val = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 104 | plist_data_t val = plist_new_plist_data(); |
| 83 | val->type = type; | 105 | val->type = type; |
| 84 | val->length = length; | 106 | val->length = length; |
| 85 | 107 | ||
| @@ -108,7 +130,7 @@ void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *valu | |||
| 108 | default: | 130 | default: |
| 109 | break; | 131 | break; |
| 110 | } | 132 | } |
| 111 | GNode *valnode = g_node_new(val); | 133 | plist_t valnode = plist_new_node(val); |
| 112 | g_node_append(dict, valnode); | 134 | g_node_append(dict, valnode); |
| 113 | } | 135 | } |
| 114 | 136 | ||
| @@ -117,24 +139,41 @@ void plist_free(plist_t plist) | |||
| 117 | g_node_destroy(plist); | 139 | g_node_destroy(plist); |
| 118 | } | 140 | } |
| 119 | 141 | ||
| 120 | plist_t find_query_node(plist_t plist, char *key, char *request) | 142 | plist_t plist_get_first_child(plist_t node) |
| 143 | { | ||
| 144 | return (plist_t)g_node_first_child( (GNode*)node ); | ||
| 145 | } | ||
| 146 | |||
| 147 | plist_t plist_get_next_sibling(plist_t node) | ||
| 148 | { | ||
| 149 | return (plist_t)g_node_next_sibling( (GNode*)node ); | ||
| 150 | } | ||
| 151 | |||
| 152 | plist_t plist_get_prev_sibling(plist_t node) | ||
| 153 | { | ||
| 154 | return (plist_t)g_node_prev_sibling( (GNode*)node ); | ||
| 155 | } | ||
| 156 | |||
| 157 | plist_t plist_find_query_node(plist_t plist, char *key, char *request) | ||
| 121 | { | 158 | { |
| 122 | if (!plist) | 159 | if (!plist) |
| 123 | return NULL; | 160 | return NULL; |
| 124 | 161 | ||
| 125 | GNode *current = NULL; | 162 | plist_t current = NULL; |
| 126 | for (current = plist->children; current; current = current->next) { | 163 | plist_t next = NULL; |
| 164 | for (current = plist_get_first_child(plist); current; current = next) { | ||
| 127 | 165 | ||
| 128 | struct plist_data *data = (struct plist_data *) current->data; | 166 | next = plist_get_next_sibling(current); |
| 167 | plist_data_t data = plist_get_data(current); | ||
| 129 | 168 | ||
| 130 | if (data->type == PLIST_KEY && !strcmp(data->strval, key) && current->next) { | 169 | if (data->type == PLIST_KEY && !strcmp(data->strval, key) && next) { |
| 131 | 170 | ||
| 132 | data = (struct plist_data *) current->next->data; | 171 | data = plist_get_data(next); |
| 133 | if (data->type == PLIST_STRING && !strcmp(data->strval, request)) | 172 | if (data->type == PLIST_STRING && !strcmp(data->strval, request)) |
| 134 | return current->next; | 173 | return next; |
| 135 | } | 174 | } |
| 136 | if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) { | 175 | if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) { |
| 137 | GNode *sub = find_query_node(current, key, request); | 176 | plist_t sub = plist_find_query_node(current, key, request); |
| 138 | if (sub) | 177 | if (sub) |
| 139 | return sub; | 178 | return sub; |
| 140 | } | 179 | } |
| @@ -142,7 +181,7 @@ plist_t find_query_node(plist_t plist, char *key, char *request) | |||
| 142 | return NULL; | 181 | return NULL; |
| 143 | } | 182 | } |
| 144 | 183 | ||
| 145 | char compare_node_value(plist_type type, struct plist_data *data, void *value) | 184 | char compare_node_value(plist_type type, plist_data_t data, void *value) |
| 146 | { | 185 | { |
| 147 | char res = FALSE; | 186 | char res = FALSE; |
| 148 | switch (type) { | 187 | switch (type) { |
| @@ -174,21 +213,21 @@ char compare_node_value(plist_type type, struct plist_data *data, void *value) | |||
| 174 | return res; | 213 | return res; |
| 175 | } | 214 | } |
| 176 | 215 | ||
| 177 | plist_t find_node(plist_t plist, plist_type type, void *value) | 216 | plist_t plist_find_node(plist_t plist, plist_type type, void *value) |
| 178 | { | 217 | { |
| 179 | if (!plist) | 218 | if (!plist) |
| 180 | return NULL; | 219 | return NULL; |
| 181 | 220 | ||
| 182 | GNode *current = NULL; | 221 | plist_t current = NULL; |
| 183 | for (current = plist->children; current; current = current->next) { | 222 | for (current = plist_get_first_child(plist); current; current = plist_get_next_sibling(current)) { |
| 184 | 223 | ||
| 185 | struct plist_data *data = (struct plist_data *) current->data; | 224 | plist_data_t data = plist_get_data(current); |
| 186 | 225 | ||
| 187 | if (data->type == type && compare_node_value(type, data, value)) { | 226 | if (data->type == type && compare_node_value(type, data, value)) { |
| 188 | return current; | 227 | return current; |
| 189 | } | 228 | } |
| 190 | if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) { | 229 | if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) { |
| 191 | GNode *sub = find_node(current, type, value); | 230 | plist_t sub = plist_find_node(current, type, value); |
| 192 | if (sub) | 231 | if (sub) |
| 193 | return sub; | 232 | return sub; |
| 194 | } | 233 | } |
| @@ -196,12 +235,12 @@ plist_t find_node(plist_t plist, plist_type type, void *value) | |||
| 196 | return NULL; | 235 | return NULL; |
| 197 | } | 236 | } |
| 198 | 237 | ||
| 199 | void get_type_and_value(GNode * node, plist_type * type, void *value, uint64_t * length) | 238 | void plist_get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length) |
| 200 | { | 239 | { |
| 201 | if (!node) | 240 | if (!node) |
| 202 | return; | 241 | return; |
| 203 | 242 | ||
| 204 | struct plist_data *data = (struct plist_data *) node->data; | 243 | plist_data_t data = plist_get_data(node); |
| 205 | 244 | ||
| 206 | *type = data->type; | 245 | *type = data->type; |
| 207 | *length = data->length; | 246 | *length = data->length; |
| @@ -236,16 +275,18 @@ void get_type_and_value(GNode * node, plist_type * type, void *value, uint64_t * | |||
| 236 | 275 | ||
| 237 | plist_type plist_get_node_type(plist_t node) | 276 | plist_type plist_get_node_type(plist_t node) |
| 238 | { | 277 | { |
| 239 | if (node && node->data) | 278 | if (node) { |
| 240 | return ((struct plist_data *) node->data)->type; | 279 | plist_data_t data = plist_get_data(node); |
| 241 | else | 280 | if (data) |
| 242 | return PLIST_NONE; | 281 | return data->type; |
| 282 | } | ||
| 283 | return PLIST_NONE; | ||
| 243 | } | 284 | } |
| 244 | 285 | ||
| 245 | uint64_t plist_get_node_uint_val(plist_t node) | 286 | uint64_t plist_get_node_uint_val(plist_t node) |
| 246 | { | 287 | { |
| 247 | if (PLIST_UINT == plist_get_node_type(node)) | 288 | if (PLIST_UINT == plist_get_node_type(node)) |
| 248 | return ((struct plist_data *) node->data)->intval; | 289 | return plist_get_data(node)->intval; |
| 249 | else | 290 | else |
| 250 | return 0; | 291 | return 0; |
| 251 | } | 292 | } |
diff --git a/src/plist.h b/src/plist.h index 1dc464a..ca3201a 100644 --- a/src/plist.h +++ b/src/plist.h | |||
| @@ -22,6 +22,8 @@ | |||
| 22 | #ifndef PLIST_H | 22 | #ifndef PLIST_H |
| 23 | #define PLIST_H | 23 | #define PLIST_H |
| 24 | 24 | ||
| 25 | #include "plist/plist.h" | ||
| 26 | |||
| 25 | #include <stdint.h> | 27 | #include <stdint.h> |
| 26 | #include <wchar.h> | 28 | #include <wchar.h> |
| 27 | 29 | ||
| @@ -31,22 +33,10 @@ | |||
| 31 | #include <glib.h> | 33 | #include <glib.h> |
| 32 | 34 | ||
| 33 | 35 | ||
| 34 | typedef enum { | ||
| 35 | PLIST_BOOLEAN, | ||
| 36 | PLIST_UINT, | ||
| 37 | PLIST_REAL, | ||
| 38 | PLIST_STRING, | ||
| 39 | PLIST_UNICODE, | ||
| 40 | PLIST_ARRAY, | ||
| 41 | PLIST_DICT, | ||
| 42 | PLIST_DATE, | ||
| 43 | PLIST_DATA, | ||
| 44 | PLIST_KEY, | ||
| 45 | PLIST_NONE | ||
| 46 | } plist_type; | ||
| 47 | 36 | ||
| 48 | 37 | ||
| 49 | struct plist_data { | 38 | |
| 39 | struct plist_data_s { | ||
| 50 | union { | 40 | union { |
| 51 | char boolval; | 41 | char boolval; |
| 52 | uint64_t intval; | 42 | uint64_t intval; |
| @@ -59,25 +49,12 @@ struct plist_data { | |||
| 59 | plist_type type; | 49 | plist_type type; |
| 60 | }; | 50 | }; |
| 61 | 51 | ||
| 52 | typedef struct plist_data_s* plist_data_t; | ||
| 62 | 53 | ||
| 54 | plist_t plist_new_node(plist_data_t data); | ||
| 55 | plist_data_t plist_get_data(plist_t node); | ||
| 56 | plist_data_t plist_new_plist_data(); | ||
| 57 | void plist_free_plist_data(plist_data_t node); | ||
| 63 | 58 | ||
| 64 | typedef GNode *plist_t; | ||
| 65 | |||
| 66 | |||
| 67 | void plist_new_dict(plist_t * plist); | ||
| 68 | void plist_new_array(plist_t * plist); | ||
| 69 | void plist_new_dict_in_plist(plist_t plist, plist_t * dict); | ||
| 70 | void plist_add_dict_element(plist_t dict, char *key, plist_type type, void *value, uint64_t length); | ||
| 71 | void plist_free(plist_t plist); | ||
| 72 | |||
| 73 | void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); | ||
| 74 | void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length); | ||
| 75 | |||
| 76 | void xml_to_plist(const char *plist_xml, uint32_t length, plist_t * plist); | ||
| 77 | void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist); | ||
| 78 | |||
| 79 | plist_t find_query_node(plist_t plist, char *key, char *request); | ||
| 80 | plist_t find_node(plist_t plist, plist_type type, void *value); | ||
| 81 | void get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length); | ||
| 82 | 59 | ||
| 83 | #endif | 60 | #endif |
diff --git a/src/xplist.c b/src/xplist.c index 2d650b4..4f81e1b 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -120,7 +120,7 @@ void node_to_xml(GNode * node, gpointer xml_struct) | |||
| 120 | return; | 120 | return; |
| 121 | 121 | ||
| 122 | struct xml_node *xstruct = (struct xml_node *) xml_struct; | 122 | struct xml_node *xstruct = (struct xml_node *) xml_struct; |
| 123 | struct plist_data *node_data = (struct plist_data *) node->data; | 123 | plist_data_t node_data = plist_get_data(node); |
| 124 | 124 | ||
| 125 | xmlNodePtr child_node = NULL; | 125 | xmlNodePtr child_node = NULL; |
| 126 | char isStruct = FALSE; | 126 | char isStruct = FALSE; |
| @@ -220,7 +220,7 @@ void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 220 | if (!node) | 220 | if (!node) |
| 221 | break; | 221 | break; |
| 222 | 222 | ||
| 223 | struct plist_data *data = (struct plist_data *) calloc(sizeof(struct plist_data), 1); | 223 | plist_data_t data = plist_new_plist_data(); |
| 224 | GNode *subnode = g_node_new(data); | 224 | GNode *subnode = g_node_new(data); |
| 225 | if (*plist_node) | 225 | if (*plist_node) |
| 226 | g_node_append(*plist_node, subnode); | 226 | g_node_append(*plist_node, subnode); |
| @@ -303,7 +303,7 @@ void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length) | |||
| 303 | xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, length); | 303 | xmlDocDumpMemory(plist_doc, (xmlChar **) plist_xml, length); |
| 304 | } | 304 | } |
| 305 | 305 | ||
| 306 | void xml_to_plist(const char *plist_xml, uint32_t length, plist_t * plist) | 306 | void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist) |
| 307 | { | 307 | { |
| 308 | xmlDocPtr plist_doc = xmlReadMemory(plist_xml, length, NULL, NULL, 0); | 308 | xmlDocPtr plist_doc = xmlReadMemory(plist_xml, length, NULL, NULL, 0); |
| 309 | xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); | 309 | xmlNodePtr root_node = xmlDocGetRootElement(plist_doc); |
