Exemplo n.º 1
0
    void
cb_build_headers(struct cb_context_st *ctx, const char * const *headers)
{
    if (!ctx->headers_built) {
        VALUE key = Qnil, val;
        for (size_t ii = 1; *headers != NULL; ++ii, ++headers) {
            if (ii % 2 == 0) {
                if (key == Qnil) {
                    break;
                }
                val = rb_hash_aref(ctx->headers_val, key);
                switch (TYPE(val)) {
                    case T_NIL:
                        rb_hash_aset(ctx->headers_val, key, STR_NEW_CSTR(*headers));
                        break;
                    case T_ARRAY:
                        rb_ary_push(val, STR_NEW_CSTR(*headers));
                        break;
                    default:
                        {
                            VALUE ary = rb_ary_new();
                            rb_ary_push(ary, val);
                            rb_ary_push(ary, STR_NEW_CSTR(*headers));
                            rb_hash_aset(ctx->headers_val, key, ary);
                        }
                }
            } else {
                key = STR_NEW_CSTR(*headers);
            }
        }
        ctx->headers_built = 1;
    }
}
    static VALUE
cb_libcouchbase_version(VALUE self)
{
    const char *ver = lcb_get_version(NULL);
    (void)self;
    return STR_NEW_CSTR(ver);
}
    static VALUE
cb_intern_string(VALUE ar, const char *str)
{
    VALUE tmp = STR_NEW_CSTR(str);
    rb_str_freeze(tmp);
    rb_ary_push(ar, tmp);
    return tmp;
}
Exemplo n.º 4
0
    VALUE
cb_unify_key(struct cb_bucket_st *bucket, VALUE key, int apply_prefix)
{
    VALUE ret = Qnil, tmp;

    if (RTEST(bucket->key_prefix_val) && apply_prefix) {
        ret = rb_str_dup(bucket->key_prefix_val);
    }
    switch (TYPE(key)) {
        case T_STRING:
            return NIL_P(ret) ? key : rb_str_concat(ret, key);
        case T_SYMBOL:
            tmp = STR_NEW_CSTR(rb_id2name(SYM2ID(key)));
            return NIL_P(ret) ? tmp : rb_str_concat(ret, tmp);
        default:    /* call #to_str or raise error */
            tmp = StringValue(key);
            return NIL_P(ret) ? tmp : rb_str_concat(ret, tmp);
    }
}
Exemplo n.º 5
0
    void
cb_version_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_server_version_resp_t *resp)
{
    struct cb_context_st *ctx = (struct cb_context_st *)cookie;
    struct cb_bucket_st *bucket = ctx->bucket;
    VALUE node, val, exc, res;

    node = resp->v.v0.server_endpoint ? STR_NEW_CSTR(resp->v.v0.server_endpoint) : Qnil;
    exc = cb_check_error(error, "failed to get version", node);
    if (exc != Qnil) {
        rb_ivar_set(exc, cb_id_iv_operation, cb_sym_version);
        ctx->exception = exc;
    }

    if (node != Qnil) {
        val = STR_NEW((const char*)resp->v.v0.vstring, resp->v.v0.nvstring);
        if (bucket->async) {    /* asynchronous */
            if (ctx->proc != Qnil) {
                res = rb_class_new_instance(0, NULL, cb_cResult);
                rb_ivar_set(res, cb_id_iv_error, exc);
                rb_ivar_set(res, cb_id_iv_operation, cb_sym_version);
                rb_ivar_set(res, cb_id_iv_node, node);
                rb_ivar_set(res, cb_id_iv_value, val);
                cb_proc_call(bucket, ctx->proc, 1, res);
            }
        } else {                /* synchronous */
            if (NIL_P(exc)) {
                rb_hash_aset(ctx->rv, node, val);
            }
        }
    } else {
        ctx->nqueries--;
        ctx->proc = Qnil;
        if (bucket->async) {
            cb_context_free(ctx);
        }
    }

    (void)handle;
}
Exemplo n.º 6
0
/* Document-method: path
 *
 * @since 1.2.0
 *
 * @return [String] the requested path
 */
VALUE
cb_http_request_path_get(VALUE self)
{
    struct cb_http_request_st *req = DATA_PTR(self);
    return STR_NEW_CSTR(req->cmd.v.v0.path);
}