summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c81
1 files changed, 56 insertions, 25 deletions
diff --git a/src/plist.c b/src/plist.c
index 78ac07c..ed73d53 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -408,37 +408,36 @@ static char compare_node_value(plist_type type, plist_data_t data, const void *v
408 return res; 408 return res;
409} 409}
410 410
411static plist_t plist_find_node(plist_t plist, plist_type type, const void *value, uint64_t length) 411plist_t plist_access_pathv(plist_t plist, uint32_t length, va_list v)
412{ 412{
413 plist_t current = NULL; 413 plist_t current = plist;
414 414 plist_type type = PLIST_NONE;
415 if (!plist) 415 uint32_t i = 0;
416 return NULL; 416
417 417 for (i = 0; i < length && current; i++) {
418 for (current = (plist_t)g_node_first_child(plist); current; current = (plist_t)g_node_next_sibling(current)) { 418 type = plist_get_node_type(current);
419 419
420 plist_data_t data = plist_get_data(current); 420 if (type == PLIST_ARRAY) {
421 421 uint32_t index = va_arg(v, uint32_t);
422 if (data->type == type && data->length == length && compare_node_value(type, data, value, length)) { 422 current = plist_array_get_item(current, index);
423 return current;
424 } 423 }
425 if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) { 424 else if (type == PLIST_DICT) {
426 plist_t sub = plist_find_node(current, type, value, length); 425 const char* key = va_arg(v, const char*);
427 if (sub) 426 current = plist_dict_get_item(current, key);
428 return sub;
429 } 427 }
430 } 428 }
431 return NULL; 429 return current;
432} 430}
433 431
434plist_t plist_find_node_by_key(plist_t plist, const char *value) 432plist_t plist_access_path(plist_t plist, uint32_t length, ...)
435{ 433{
436 return plist_find_node(plist, PLIST_KEY, value, strlen(value)); 434 plist_t ret = NULL;
437} 435 va_list v;
438 436
439plist_t plist_find_node_by_string(plist_t plist, const char *value) 437 va_start(v, length);
440{ 438 ret = plist_access_pathv(plist, length, v);
441 return plist_find_node(plist, PLIST_STRING, value, strlen(value)); 439 va_end(v);
440 return ret;
442} 441}
443 442
444static void plist_get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length) 443static void plist_get_type_and_value(plist_t node, plist_type * type, void *value, uint64_t * length)
@@ -886,4 +885,36 @@ void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec)
886 plist_add_sub_element(node, PLIST_DATE, &val, sizeof(GTimeVal)); 885 plist_add_sub_element(node, PLIST_DATE, &val, sizeof(GTimeVal));
887} 886}
888 887
888static plist_t plist_find_node(plist_t plist, plist_type type, const void *value, uint64_t length)
889{
890 plist_t current = NULL;
891
892 if (!plist)
893 return NULL;
894
895 for (current = (plist_t)g_node_first_child(plist); current; current = (plist_t)g_node_next_sibling(current)) {
896
897 plist_data_t data = plist_get_data(current);
898
899 if (data->type == type && data->length == length && compare_node_value(type, data, value, length)) {
900 return current;
901 }
902 if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) {
903 plist_t sub = plist_find_node(current, type, value, length);
904 if (sub)
905 return sub;
906 }
907 }
908 return NULL;
909}
910
911plist_t plist_find_node_by_key(plist_t plist, const char *value)
912{
913 return plist_find_node(plist, PLIST_KEY, value, strlen(value));
914}
915
916plist_t plist_find_node_by_string(plist_t plist, const char *value)
917{
918 return plist_find_node(plist, PLIST_STRING, value, strlen(value));
919}
889 920