Ejemplo n.º 1
0
static bool
lgtd_jsonrpc_extract_and_validate_params_against_schema(void *output,
                                                        const struct lgtd_jsonrpc_node *schema,
                                                        int schema_size,
                                                        const jsmntok_t *tokens,
                                                        int ntokens,
                                                        const char *json)
{
    if (!ntokens) {
        // "params" were omitted, make sure no args were required or that they
        // are all optional:
        while (schema_size--) {
            if (!schema[schema_size].optional) {
                return false;
            }
        }
        return true;
    }

    switch (tokens[0].type) {
    case JSMN_OBJECT:
        return lgtd_jsonrpc_extract_values_from_schema_and_dict(
            output, schema, schema_size, tokens, ntokens, json
        );
    case JSMN_ARRAY:
        return lgtd_jsonrpc_extract_values_from_schema_and_array(
            output, schema, schema_size, tokens, ntokens, json
        );
    default:
        return false;
    }
}
Ejemplo n.º 2
0
static bool
lgtd_jsonrpc_extract_and_validate_params_against_schema(void *output,
                                                        const struct lgtd_jsonrpc_node *schema,
                                                        int schema_size,
                                                        const jsmntok_t *tokens,
                                                        int ntokens,
                                                        const char *json)
{
    switch (tokens[0].type) {
    case JSMN_OBJECT:
        return lgtd_jsonrpc_extract_values_from_schema_and_dict(
            output, schema, schema_size, tokens, ntokens, json
        );
    case JSMN_ARRAY:
        return lgtd_jsonrpc_extract_values_from_schema_and_array(
            output, schema, schema_size, tokens, ntokens, json
        );
    default:
        return false;
    }
}