static void
initial_pop_callback(jsonsl_t jsn,
                     jsonsl_action_t action,
                     struct jsonsl_state_st *state,
                     const jsonsl_char_t *at)
{
    lcbex_vrow_ctx_t *ctx = (lcbex_vrow_ctx_t*)jsn->data;
    char *key;
    unsigned long len;

    if (ctx->have_error) {
        return;
    }

    if (JSONSL_STATE_IS_CONTAINER(state)) {
        return;
    }

    if (state->type != JSONSL_T_HKEY) {
        return;
    }

    key = ctx->current_buf.s + state->pos_begin;
    len = state->pos_cur - state->pos_begin;
    NORMALIZE_OFFSETS(key, len);

    buffer_reset(&ctx->last_hk, 0);
    buffer_append(&ctx->last_hk, key, len);

    (void)action;
    (void)at;
}
Exemple #2
0
static void
initial_pop_callback(jsonsl_t jsn, jsonsl_action_t action,
    struct jsonsl_state_st *state, const jsonsl_char_t *at)
{
    lcbjsp_PARSER *ctx = jsn->data;
    char *key;
    unsigned long len;

    if (ctx->have_error) {
        return;
    }
    if (JSONSL_STATE_IS_CONTAINER(state)) {
        return;
    }
    if (state->type != JSONSL_T_HKEY) {
        return;
    }

    key = ctx->current_buf.base + state->pos_begin;
    len = jsn->pos - state->pos_begin;
    NORMALIZE_OFFSETS(key, len);

    lcb_string_clear(&ctx->last_hk);
    buffer_append(&ctx->last_hk, key, len);

    (void)action; (void)at;
}
Exemple #3
0
static void
miniparse_callback(jsonsl_t jsn, jsonsl_action_t action,
    struct jsonsl_state_st *state, const jsonsl_char_t *at)
{
    miniparse_ctx *ctx = jsn->data;
    lcb_IOV *iov;

    if (state->level == 1) {
        return;
    }

    /* Is a hashkey? */
    if (state->type == JSONSL_T_HKEY) {
        size_t nhk = state->pos_cur - state->pos_begin;

        nhk--;

        #define IS_ROWFIELD(s) \
            (nhk == sizeof(s)-1 && !strncmp(s, at- (sizeof(s)-1) , sizeof(s)-1) )

        if (IS_ROWFIELD("id")) {
            /* "id" */
            ctx->next_iov = &ctx->datum->docid;
        } else if (IS_ROWFIELD("key")) {
            /* "key" */
            ctx->next_iov = &ctx->datum->key;
        } else if (IS_ROWFIELD("value")) {
            /* "value" */
            ctx->next_iov = &ctx->datum->value;
        } else if (IS_ROWFIELD("geometry")) {
            ctx->next_iov = &ctx->datum->geo;
        } else {
            ctx->next_iov = NULL;
        }
        #undef IS_ROWFIELD
        return;
    }

    if (ctx->next_iov == NULL) {
        return;
    }

    iov = ctx->next_iov;

    if (JSONSL_STATE_IS_CONTAINER(state)) {
        iov->iov_base = (void *) (ctx->root + state->pos_begin);
        iov->iov_len = (jsn->pos - state->pos_begin) + 1;
    } else if (iov == &ctx->datum->docid) {
        iov->iov_base = (void *) (ctx->root + state->pos_begin + 1);
        iov->iov_len = (state->pos_cur - state->pos_begin) - 1;
    } else {
        iov->iov_base = (void *) (ctx->root + state->pos_begin);
        iov->iov_len = state->pos_cur - state->pos_begin;
        if (state->type == JSONSL_T_STRING) {
            iov->iov_len++;
        }
    }
    (void)at; (void)action;
}
/**
 * This is called for the first few tokens, where we are still searching
 * for the row set.
 */
static void
initial_push_callback(jsonsl_t jsn,
                      jsonsl_action_t action,
                      struct jsonsl_state_st *state,
                      const jsonsl_char_t *at)
{
    lcbex_vrow_ctx_t *ctx = (lcbex_vrow_ctx_t*)jsn->data;
    jsonsl_jpr_match_t match;

    if (ctx->have_error) {
        return;
    }

    if (JSONSL_STATE_IS_CONTAINER(state)) {
        jsonsl_jpr_match_state(jsn,
                               state,
                               ctx->last_hk.s,
                               ctx->last_hk.len,
                               &match);
    }

    buffer_reset(&ctx->last_hk, 0);

    if (ctx->initialized == 0) {
        if (state->type != JSONSL_T_OBJECT) {
            ctx->have_error = 1;
            return;
        }

        if (match != JSONSL_MATCH_POSSIBLE) {
            ctx->have_error = 1;
            return;
        }
        /* tag the state */
        state->data = JOBJ_RESPONSE_ROOT;
        ctx->initialized = 1;
        return;
    }

    if (state->type == JSONSL_T_LIST && match == JSONSL_MATCH_POSSIBLE) {
        /* we have a match */
        jsn->action_callback_POP = row_pop_callback;
        jsn->action_callback_PUSH = meta_header_complete_callback;
        state->data = JOBJ_ROWSET;
    }

    (void)action; /* always PUSH */
    (void)at;
}
Exemple #5
0
static void
miniparse_callback(jsonsl_t jsn, jsonsl_action_t action,
    struct jsonsl_state_st *state, const jsonsl_char_t *at)
{
    miniparse_ctx *ctx = jsn->data;
    lcb_IOV *iov;

    if (state->level == 1) {
        return;
    }

    /* Is a hashkey? */
    if (state->type == JSONSL_T_HKEY) {
        size_t nhk = state->pos_cur - state->pos_begin;
        nhk--;
        if (nhk == 2 && !strncmp("id", at-2, 2)) {
            /* "id" */
            ctx->next_iov = &ctx->datum->docid;
        } else if (nhk == 3 && !strncmp("key", at-3, 3)) {
            /* "key" */
            ctx->next_iov = &ctx->datum->key;
        } else if (nhk == 5 && !strncmp("value", at-5, 5)) {
            /* "value" */
            ctx->next_iov = &ctx->datum->value;
        } else {
            ctx->next_iov = NULL;
        }
        return;
    }

    if (ctx->next_iov == NULL) {
        return;
    }

    iov = ctx->next_iov;

    if (JSONSL_STATE_IS_CONTAINER(state)) {
        iov->iov_base = (void *) (ctx->root + state->pos_begin);
        iov->iov_len = (jsn->pos - state->pos_begin) + 1;
    } else if (state->type == JSONSL_T_STRING) {
        iov->iov_base = (void *) (ctx->root + state->pos_begin + 1);
        iov->iov_len = (state->pos_cur - state->pos_begin) - 1;
    } else {
        iov->iov_base = (void *) (ctx->root + state->pos_begin);
        iov->iov_len = state->pos_cur - state->pos_begin;
    }
    (void)at; (void)action;
}
Exemple #6
0
/**
 * This is called for the first few tokens, where we are still searching
 * for the row set.
 */
static void
initial_push_callback(jsonsl_t jsn, jsonsl_action_t action,
    struct jsonsl_state_st *state, const jsonsl_char_t *at)
{
    lcbvrow_PARSER *ctx = (lcbvrow_PARSER*)jsn->data;
    jsonsl_jpr_match_t match = JSONSL_MATCH_UNKNOWN;

    if (ctx->have_error) {
        return;
    }

    if (JSONSL_STATE_IS_CONTAINER(state)) {
        jsonsl_jpr_match_state(jsn, state, ctx->last_hk.base, ctx->last_hk.nused,
            &match);
    }

    lcb_string_clear(&ctx->last_hk);

    if (ctx->initialized == 0) {
        if (state->type != JSONSL_T_OBJECT) {
            ctx->have_error = 1;
            return;
        }

        if (match != JSONSL_MATCH_POSSIBLE) {
            ctx->have_error = 1;
            return;
        }
        /* tag the state */
        state->data = JOBJ_RESPONSE_ROOT;
        ctx->initialized = 1;
        return;
    }

    if (state->type == JSONSL_T_LIST && match == JSONSL_MATCH_POSSIBLE) {
        /* we have a match, e.g. "rows:[]" */
        jsn->action_callback_POP = row_pop_callback;
        jsn->action_callback_PUSH = meta_header_complete_callback;
        state->data = JOBJ_ROWSET;
    }

    (void)action; /* always PUSH */
    (void)at;
}