summaryrefslogtreecommitdiffstats
path: root/src/plist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plist.c')
-rw-r--r--src/plist.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/plist.c b/src/plist.c
index 5b61570..1c00cc6 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -946,6 +946,73 @@ GNode *find_query_node(plist_t plist, char *key, char *request)
946 return NULL; 946 return NULL;
947} 947}
948 948
949char compare_node_value(plist_type type, struct plist_data *data, void *value)
950{
951 char res = FALSE;
952 switch (type) {
953 case PLIST_BOOLEAN:
954 res = data->boolval == *((char *) value) ? TRUE : FALSE;
955 break;
956 case PLIST_UINT8:
957 res = data->intval8 == *((uint8_t *) value) ? TRUE : FALSE;
958 break;
959 case PLIST_UINT16:
960 res = data->intval16 == *((uint16_t *) value) ? TRUE : FALSE;
961 break;
962 case PLIST_UINT32:
963 res = data->intval32 == *((uint32_t *) value) ? TRUE : FALSE;
964 break;
965 case PLIST_UINT64:
966 res = data->intval64 == *((uint64_t *) value) ? TRUE : FALSE;
967 break;
968 case PLIST_FLOAT32:
969 res = data->realval32 == *((float *) value) ? TRUE : FALSE;
970 break;
971 case PLIST_FLOAT64:
972 res = data->realval64 == *((double *) value) ? TRUE : FALSE;
973 break;
974 case PLIST_KEY:
975 case PLIST_STRING:
976 res = !strcmp(data->strval, ((char *) value));
977 break;
978 case PLIST_UNICODE:
979 res = !wcscmp(data->unicodeval, ((wchar_t *) value));
980 break;
981 case PLIST_DATA:
982 res = !strcmp(data->buff, ((char *) value));
983 break;
984 case PLIST_ARRAY:
985 case PLIST_DICT:
986 case PLIST_DATE:
987 case PLIST_PLIST:
988 default:
989 break;
990 }
991 return res;
992}
993
994GNode *find_node(plist_t plist, plist_type type, void *value)
995{
996 if (!plist)
997 return NULL;
998
999 GNode *current = NULL;
1000 for (current = plist->children; current; current = current->next) {
1001
1002 struct plist_data *data = (struct plist_data *) current->data;
1003
1004 if (data->type == type && compare_node_value(type, data, value)) {
1005 return current;
1006 }
1007 if (data->type == PLIST_DICT || data->type == PLIST_ARRAY || data->type == PLIST_PLIST) {
1008 GNode *sub = find_node(current, type, value);
1009 if (sub)
1010 return sub;
1011 }
1012 }
1013 return NULL;
1014}
1015
949void get_type_and_value(GNode * node, plist_type * type, void *value) 1016void get_type_and_value(GNode * node, plist_type * type, void *value)
950{ 1017{
951 if (!node) 1018 if (!node)