예제 #1
0
char compare_plist(plist_t node_l, plist_t node_r)
{
    plist_t cur_l = NULL;
    plist_t cur_r = NULL;
    int res = 1;

    cur_l = plist_get_first_child(node_l);
    cur_r = plist_get_first_child(node_r);

    if ( (!cur_l && cur_r) || (cur_l && !cur_r))
        return 0;

    if ( !cur_l && !cur_r )
        return plist_compare_node_value( node_l, node_r );

    while (cur_l && cur_r && res)
    {

        if (!(res = compare_plist(cur_l, cur_r)))
            return res;

        cur_l = plist_get_next_sibling(cur_l);
        cur_r = plist_get_next_sibling(cur_r);
        if ( (!cur_l && cur_r) || (cur_l && !cur_r))
            return 0;
    }

    return res;
}
예제 #2
0
void plist_children_to_string(plist_t *node)
{
	/* iterate over key/value pairs */
	for (
		node = plist_get_first_child(node);
		node != NULL;
		node = plist_get_next_sibling(node)
	) {
		plist_node_to_string(node);
	}
}
예제 #3
0
plist_t plist_get_array_nth_el(plist_t node, uint32_t n)
{
	plist_t ret = NULL;
	if (node && PLIST_ARRAY == plist_get_node_type(node)) {
		uint32_t i = 0;
		plist_t temp = plist_get_first_child(node);

		while (i <= n && temp) {
			if (i == n)
				ret = temp;
			temp = plist_get_next_sibling(temp);
			i++;
		}
	}
	return ret;
}
예제 #4
0
static plist_t plist_find_node(plist_t plist, plist_type type, const void *value, uint64_t length)
{
	plist_t current = NULL;

	if (!plist)
		return NULL;

	for (current = plist_get_first_child(plist); current; current = plist_get_next_sibling(current)) {

		plist_data_t data = plist_get_data(current);

		if (data->type == type && data->length == length && compare_node_value(type, data, value, length)) {
			return current;
		}
		if (data->type == PLIST_DICT || data->type == PLIST_ARRAY) {
			plist_t sub = plist_find_node(current, type, value, length);
			if (sub)
				return sub;
		}
	}
	return NULL;
}
예제 #5
0
void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format) {
	char *xml_doc = NULL;
	char *s = NULL;
	uint32_t xml_length = 0;
	iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
	
	plist_t node = plist_new_dict();
	if (domain) {
		plist_add_sub_key_el(node, "Domain");
		plist_add_sub_string_el(node, domain);
	}
	if (key) {
		plist_add_sub_key_el(node, "Key");
		plist_add_sub_string_el(node, key);
	}
	plist_add_sub_key_el(node, "Request");
	plist_add_sub_string_el(node, request);

	ret = iphone_lckd_send(control, node);
	if (ret == IPHONE_E_SUCCESS) {
		plist_free(node);
		node = NULL;
		ret = iphone_lckd_recv(control, &node);
		if (ret == IPHONE_E_SUCCESS) {
			/* seek to value node */
			for (
				node = plist_get_first_child(node);
				node != NULL;
				node = plist_get_next_sibling(node)
			) {
				if(plist_get_node_type(node) == PLIST_KEY)
				{
					plist_get_key_val(node, &s);

					if (strcmp("Value", s))
						continue;

					node = plist_get_next_sibling(node);

					if (plist_get_node_type(node) == PLIST_DICT) {
						if (plist_get_first_child(node))
						{
							switch (format) {
							case FORMAT_XML:
								plist_to_xml(node, &xml_doc, &xml_length);
								printf(xml_doc);
								free(xml_doc);
								break;
							case FORMAT_KEY_VALUE:
							default:
								plist_children_to_string(node);
								break;
							}
						}
					}
					else if(node && (key != NULL))
						plist_node_to_string(node);
				}
			}
		}
	}
	if (node)
		plist_free(node);
	node = NULL;
}