summaryrefslogtreecommitdiffstats
path: root/src/bplist.c
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-12-13 13:56:55 +0100
committerGravatar Jonathan Beck2008-12-13 13:56:55 +0100
commite220e2cf08809a6a8853a8c9c7b06cef4e90cb57 (patch)
tree51472b19b56c5816fc050fcac6273a5931f9f4f6 /src/bplist.c
parent3fdd24aea06a9bf38d9d34fb8bccbb7023ed3100 (diff)
downloadlibplist-e220e2cf08809a6a8853a8c9c7b06cef4e90cb57.tar.gz
libplist-e220e2cf08809a6a8853a8c9c7b06cef4e90cb57.tar.bz2
Add plutil and do some cleaning.
Diffstat (limited to 'src/bplist.c')
-rw-r--r--src/bplist.c52
1 files changed, 26 insertions, 26 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
86GNode *parse_uint_node(char *bnode, uint8_t size, char **next_object) 86plist_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
117GNode *parse_real_node(char *bnode, uint8_t size) 117plist_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
139GNode *parse_string_node(char *bnode, uint8_t size) 139plist_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
151GNode *parse_unicode_node(char *bnode, uint8_t size) 151plist_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
163GNode *parse_data_node(char *bnode, uint64_t size, uint32_t ref_size) 163plist_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
175GNode *parse_dict_node(char *bnode, uint64_t size, uint32_t ref_size) 175plist_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
187GNode *parse_array_node(char *bnode, uint64_t size, uint32_t ref_size) 187plist_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
201GNode *parse_bin_node(char *object, uint8_t dict_size, char **next_object) 201plist_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
300gpointer copy_plist_data(gconstpointer src, gpointer data) 300gpointer 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
339void bin_to_plist(const char *plist_bin, uint32_t length, plist_t * plist) 339void 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
447guint plist_data_hash(gconstpointer key) 447guint 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: