Пример #1
0
cParseQueryBuilder *cparse_query_build_related_to(cParseQueryBuilder *query, const char *key, cParseObject *obj)
{
    cParseJson *inner = NULL;
    cParseJson *pointer = NULL;

    if (query == NULL || obj == NULL) {
        cparse_log_errno(EINVAL);
        return NULL;
    }

    inner = cparse_json_new();

    if (inner == NULL) {
        return query;
    }

    pointer = cparse_pointer_from_object(obj);

    cparse_json_set(inner, "object", pointer);

    cparse_json_set_string(inner, "key", key);

    cparse_json_set(query->json, CPARSE_QUERY_RELATED_TO, inner);

    return query;
}
Пример #2
0
static void __cparse_role_add_dependency(cParseRole *role, const char *key, cParseObject *ref)
{
	cParseJson *users = NULL;
	cParseJson *objects = NULL;
	cParseJson *pointer = NULL;

	if (!role || cparse_str_empty(key) || !ref) {
		cparse_log_errno(EINVAL);
		return;
	}

	/* only allow certain values for key/pointer type */
	if (strcmp(key, CPARSE_USERS_PATH) && strcmp(key, CPARSE_ROLES_PATH))
	{
		cparse_log_error("can only by of type users or roles");
		return;
	}

	users = cparse_object_get(role, key);

	if (users == NULL) {
		users = cparse_json_new();
		cparse_json_set_string(users, CPARSE_KEY_OP, CPARSE_KEY_ADD_RELATION);
		cparse_object_set(role, key, users);
	}

	objects = cparse_json_get(users, "objects");

	if (objects == NULL) {
		objects = cparse_json_new_array();
		cparse_json_set(users, "objects", objects);
	}

	if (!cparse_json_is_array(objects)) {
		cparse_log_error("objects is not an array");
		return;
	}

	pointer = cparse_pointer_from_object(ref);

	cparse_json_array_add(objects, pointer);
}