예제 #1
0
파일: role.c 프로젝트: gitter-badger/cparse
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);
}
예제 #2
0
파일: query.c 프로젝트: ryjen/cparse
cParseQueryBuilder *cparse_query_build_all(cParseQueryBuilder *query, const char *key, cParseJson *value)
{
    cParseJson *inner = NULL;

    if (query == NULL || cparse_str_empty(key) || value == NULL) {
        cparse_log_errno(EINVAL);
        return NULL;
    }

    inner = cparse_json_new();

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

    cparse_json_set(inner, CPARSE_QUERY_ALL, value);

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

    return query;
}
예제 #3
0
파일: query.c 프로젝트: ryjen/cparse
cParseQueryBuilder *cparse_query_build_nin(cParseQueryBuilder *query, const char *key, cParseJson *inArray)
{
    cParseJson *inner = NULL;

    if (query == NULL || cparse_str_empty(key) || inArray == NULL) {
        cparse_log_errno(EINVAL);
        return NULL;
    }

    inner = cparse_json_new();

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

    cparse_json_set(inner, CPARSE_QUERY_NOT_IN, inArray);

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

    return query;
}
예제 #4
0
파일: query.c 프로젝트: ryjen/cparse
cParseQueryBuilder *cparse_query_build_lte(cParseQueryBuilder *query, const char *key, cParseJson *value)
{
    cParseJson *lte = NULL;

    if (query == NULL || cparse_str_empty(key) || value == NULL) {
        cparse_log_errno(EINVAL);
        return NULL;
    }

    lte = cparse_json_new();

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

    cparse_json_set(lte, CPARSE_QUERY_LESS_THAN_EQUAL, value);

    cparse_json_set(query->json, key, lte);

    return query;
}
예제 #5
0
파일: query.c 프로젝트: ryjen/cparse
void cparse_query_where_all(cParseQuery *query, const char *key, cParseJson *value)
{
    cParseQueryBuilder *builder = NULL;

    if (query == NULL || cparse_str_empty(key) || value == NULL) {
        cparse_log_errno(EINVAL);
        return;
    }

    builder = cparse_query_build_new();

    if (builder == NULL) {
        cparse_log_errno(ENOMEM);
        return;
    }

    cparse_query_build_all(builder, key, value);

    cparse_query_build_where(query, builder);

    cparse_query_build_free(builder);
}
예제 #6
0
파일: query.c 프로젝트: ryjen/cparse
cParseQuery *cparse_query_with_class_name(const char *className)
{
    char buf[CPARSE_BUF_SIZE + 1] = {0};
    cParseQuery *query = NULL;

    if (cparse_str_empty(className)) {
        cparse_log_errno(EINVAL);
        return NULL;
    }

    query = cparse_query_new();

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

    query->className = strdup(className);

    snprintf(buf, CPARSE_BUF_SIZE, "%s%s", CPARSE_OBJECTS_PATH, className);

    query->urlPath = strdup(buf);

    return query;
}