couchbase 1.2.0.z.beta4-x86-mingw32 → 1.2.0.z.beta5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.markdown +9 -0
- data/ext/couchbase_ext/arguments.c +132 -128
- data/ext/couchbase_ext/arithmetic.c +25 -22
- data/ext/couchbase_ext/bucket.c +147 -114
- data/ext/couchbase_ext/couchbase_ext.c +419 -399
- data/ext/couchbase_ext/couchbase_ext.h +195 -189
- data/ext/couchbase_ext/delete.c +22 -19
- data/ext/couchbase_ext/extconf.rb +9 -2
- data/ext/couchbase_ext/get.c +32 -29
- data/ext/couchbase_ext/http.c +73 -59
- data/ext/couchbase_ext/observe.c +30 -27
- data/ext/couchbase_ext/result.c +13 -13
- data/ext/couchbase_ext/stats.c +22 -20
- data/ext/couchbase_ext/store.c +37 -30
- data/ext/couchbase_ext/timer.c +10 -10
- data/ext/couchbase_ext/touch.c +22 -19
- data/ext/couchbase_ext/unlock.c +22 -19
- data/ext/couchbase_ext/utils.c +78 -78
- data/ext/couchbase_ext/version.c +21 -18
- data/lib/couchbase/version.rb +1 -1
- data/lib/couchbase/view.rb +18 -0
- data/tasks/compile.rake +1 -1
- data/tasks/test.rake +40 -33
- data/test/setup.rb +4 -0
- data/test/test_arithmetic.rb +37 -0
- metadata +4 -25
data/ext/couchbase_ext/delete.c
CHANGED
@@ -18,20 +18,20 @@
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
20
|
void
|
21
|
-
|
21
|
+
cb_delete_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_remove_resp_t *resp)
|
22
22
|
{
|
23
|
-
struct
|
24
|
-
struct
|
23
|
+
struct cb_context_st *ctx = (struct cb_context_st *)cookie;
|
24
|
+
struct cb_bucket_st *bucket = ctx->bucket;
|
25
25
|
VALUE key, *rv = ctx->rv, exc = Qnil, res;
|
26
26
|
|
27
27
|
ctx->nqueries--;
|
28
28
|
key = STR_NEW((const char*)resp->v.v0.key, resp->v.v0.nkey);
|
29
|
-
|
29
|
+
cb_strip_key_prefix(bucket, key);
|
30
30
|
|
31
31
|
if (error != LCB_KEY_ENOENT || !ctx->quiet) {
|
32
32
|
exc = cb_check_error(error, "failed to remove value", key);
|
33
33
|
if (exc != Qnil) {
|
34
|
-
rb_ivar_set(exc,
|
34
|
+
rb_ivar_set(exc, cb_id_iv_operation, cb_sym_delete);
|
35
35
|
if (NIL_P(ctx->exception)) {
|
36
36
|
ctx->exception = cb_gc_protect(bucket, exc);
|
37
37
|
}
|
@@ -39,10 +39,10 @@ delete_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_r
|
|
39
39
|
}
|
40
40
|
if (bucket->async) { /* asynchronous */
|
41
41
|
if (ctx->proc != Qnil) {
|
42
|
-
res = rb_class_new_instance(0, NULL,
|
43
|
-
rb_ivar_set(res,
|
44
|
-
rb_ivar_set(res,
|
45
|
-
rb_ivar_set(res,
|
42
|
+
res = rb_class_new_instance(0, NULL, cb_cResult);
|
43
|
+
rb_ivar_set(res, cb_id_iv_error, exc);
|
44
|
+
rb_ivar_set(res, cb_id_iv_operation, cb_sym_delete);
|
45
|
+
rb_ivar_set(res, cb_id_iv_key, key);
|
46
46
|
cb_proc_call(ctx->proc, 1, res);
|
47
47
|
}
|
48
48
|
} else { /* synchronous */
|
@@ -50,6 +50,9 @@ delete_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_r
|
|
50
50
|
}
|
51
51
|
if (ctx->nqueries == 0) {
|
52
52
|
cb_gc_unprotect(bucket, ctx->proc);
|
53
|
+
if (bucket->async) {
|
54
|
+
xfree(ctx);
|
55
|
+
}
|
53
56
|
}
|
54
57
|
(void)handle;
|
55
58
|
}
|
@@ -99,29 +102,29 @@ delete_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_r
|
|
99
102
|
VALUE
|
100
103
|
cb_bucket_delete(int argc, VALUE *argv, VALUE self)
|
101
104
|
{
|
102
|
-
struct
|
103
|
-
struct
|
105
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
106
|
+
struct cb_context_st *ctx;
|
104
107
|
VALUE rv, exc;
|
105
108
|
VALUE args, proc;
|
106
109
|
lcb_error_t err;
|
107
|
-
struct
|
110
|
+
struct cb_params_st params;
|
108
111
|
|
109
112
|
if (bucket->handle == NULL) {
|
110
|
-
rb_raise(
|
113
|
+
rb_raise(cb_eConnectError, "closed connection");
|
111
114
|
}
|
112
115
|
rb_scan_args(argc, argv, "0*&", &args, &proc);
|
113
116
|
if (!bucket->async && proc != Qnil) {
|
114
117
|
rb_raise(rb_eArgError, "synchronous mode doesn't support callbacks");
|
115
118
|
}
|
116
|
-
rb_funcall(args,
|
117
|
-
memset(¶ms, 0, sizeof(struct
|
118
|
-
params.type =
|
119
|
+
rb_funcall(args, cb_id_flatten_bang, 0);
|
120
|
+
memset(¶ms, 0, sizeof(struct cb_params_st));
|
121
|
+
params.type = cb_cmd_remove;
|
119
122
|
params.bucket = bucket;
|
120
123
|
cb_params_build(¶ms, RARRAY_LEN(args), args);
|
121
124
|
|
122
|
-
ctx = xcalloc(1, sizeof(struct
|
125
|
+
ctx = xcalloc(1, sizeof(struct cb_context_st));
|
123
126
|
if (ctx == NULL) {
|
124
|
-
rb_raise(
|
127
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for context");
|
125
128
|
}
|
126
129
|
ctx->quiet = params.cmd.remove.quiet;
|
127
130
|
ctx->proc = cb_gc_protect(bucket, proc);
|
@@ -140,7 +143,7 @@ cb_bucket_delete(int argc, VALUE *argv, VALUE self)
|
|
140
143
|
}
|
141
144
|
bucket->nbytes += params.npayload;
|
142
145
|
if (bucket->async) {
|
143
|
-
|
146
|
+
cb_maybe_do_loop(bucket);
|
144
147
|
return Qnil;
|
145
148
|
} else {
|
146
149
|
if (ctx->nqueries > 0) {
|
@@ -119,9 +119,16 @@ if try_compile(<<-SRC)
|
|
119
119
|
define("HAVE_STDARG_PROTOTYPES")
|
120
120
|
end
|
121
121
|
|
122
|
-
|
122
|
+
def die(message)
|
123
|
+
STDERR.puts "\n#{"*" * 70}"
|
124
|
+
STDERR.puts "#{message}"
|
125
|
+
STDERR.puts "#{"*" * 70}\n\n"
|
126
|
+
abort
|
127
|
+
end
|
128
|
+
|
129
|
+
have_library("couchbase", "lcb_verify_compiler_setup", "libcouchbase/couchbase.h") or die("You must install libcouchbase >= 2.0.0beta3. See http://www.couchbase.com/develop/ for more details")
|
123
130
|
have_header("mach/mach_time.h")
|
124
|
-
have_header("stdint.h") or
|
131
|
+
have_header("stdint.h") or die("Failed to locate stdint.h")
|
125
132
|
have_header("sys/time.h")
|
126
133
|
have_func("clock_gettime")
|
127
134
|
have_func("gettimeofday")
|
data/ext/couchbase_ext/get.c
CHANGED
@@ -18,20 +18,20 @@
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
20
|
void
|
21
|
-
|
21
|
+
cb_get_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_get_resp_t *resp)
|
22
22
|
{
|
23
|
-
struct
|
24
|
-
struct
|
23
|
+
struct cb_context_st *ctx = (struct cb_context_st *)cookie;
|
24
|
+
struct cb_bucket_st *bucket = ctx->bucket;
|
25
25
|
VALUE key, val, flags, cas, *rv = ctx->rv, exc = Qnil, res;
|
26
26
|
|
27
27
|
ctx->nqueries--;
|
28
28
|
key = STR_NEW((const char*)resp->v.v0.key, resp->v.v0.nkey);
|
29
|
-
|
29
|
+
cb_strip_key_prefix(bucket, key);
|
30
30
|
|
31
31
|
if (error != LCB_KEY_ENOENT || !ctx->quiet) {
|
32
32
|
exc = cb_check_error(error, "failed to get value", key);
|
33
33
|
if (exc != Qnil) {
|
34
|
-
rb_ivar_set(exc,
|
34
|
+
rb_ivar_set(exc, cb_id_iv_operation, cb_sym_get);
|
35
35
|
if (NIL_P(ctx->exception)) {
|
36
36
|
ctx->exception = cb_gc_protect(bucket, exc);
|
37
37
|
}
|
@@ -43,33 +43,33 @@ get_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_get_
|
|
43
43
|
val = Qnil;
|
44
44
|
if (resp->v.v0.nbytes != 0) {
|
45
45
|
VALUE raw = STR_NEW((const char*)resp->v.v0.bytes, resp->v.v0.nbytes);
|
46
|
-
val =
|
46
|
+
val = cb_decode_value(raw, resp->v.v0.flags, ctx->force_format);
|
47
47
|
if (rb_obj_is_kind_of(val, rb_eStandardError)) {
|
48
|
-
VALUE exc_str = rb_funcall(val,
|
49
|
-
VALUE msg = rb_funcall(rb_mKernel,
|
48
|
+
VALUE exc_str = rb_funcall(val, cb_id_to_s, 0);
|
49
|
+
VALUE msg = rb_funcall(rb_mKernel, cb_id_sprintf, 3,
|
50
50
|
rb_str_new2("unable to convert value for key '%s': %s"), key, exc_str);
|
51
51
|
if (ctx->exception != Qnil) {
|
52
52
|
cb_gc_unprotect(bucket, ctx->exception);
|
53
53
|
}
|
54
|
-
ctx->exception = rb_exc_new3(
|
55
|
-
rb_ivar_set(ctx->exception,
|
56
|
-
rb_ivar_set(ctx->exception,
|
57
|
-
rb_ivar_set(ctx->exception,
|
54
|
+
ctx->exception = rb_exc_new3(cb_eValueFormatError, msg);
|
55
|
+
rb_ivar_set(ctx->exception, cb_id_iv_operation, cb_sym_get);
|
56
|
+
rb_ivar_set(ctx->exception, cb_id_iv_key, key);
|
57
|
+
rb_ivar_set(ctx->exception, cb_id_iv_inner_exception, val);
|
58
58
|
cb_gc_protect(bucket, ctx->exception);
|
59
59
|
val = raw;
|
60
60
|
}
|
61
|
-
} else if (
|
61
|
+
} else if (cb_flags_get_format(resp->v.v0.flags) == cb_sym_plain) {
|
62
62
|
val = STR_NEW_CSTR("");
|
63
63
|
}
|
64
64
|
if (bucket->async) { /* asynchronous */
|
65
65
|
if (ctx->proc != Qnil) {
|
66
|
-
res = rb_class_new_instance(0, NULL,
|
67
|
-
rb_ivar_set(res,
|
68
|
-
rb_ivar_set(res,
|
69
|
-
rb_ivar_set(res,
|
70
|
-
rb_ivar_set(res,
|
71
|
-
rb_ivar_set(res,
|
72
|
-
rb_ivar_set(res,
|
66
|
+
res = rb_class_new_instance(0, NULL, cb_cResult);
|
67
|
+
rb_ivar_set(res, cb_id_iv_error, exc);
|
68
|
+
rb_ivar_set(res, cb_id_iv_operation, cb_sym_get);
|
69
|
+
rb_ivar_set(res, cb_id_iv_key, key);
|
70
|
+
rb_ivar_set(res, cb_id_iv_value, val);
|
71
|
+
rb_ivar_set(res, cb_id_iv_flags, flags);
|
72
|
+
rb_ivar_set(res, cb_id_iv_cas, cas);
|
73
73
|
cb_proc_call(ctx->proc, 1, res);
|
74
74
|
}
|
75
75
|
} else { /* synchronous */
|
@@ -84,6 +84,9 @@ get_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_get_
|
|
84
84
|
|
85
85
|
if (ctx->nqueries == 0) {
|
86
86
|
cb_gc_unprotect(bucket, ctx->proc);
|
87
|
+
if (bucket->async) {
|
88
|
+
xfree(ctx);
|
89
|
+
}
|
87
90
|
}
|
88
91
|
(void)handle;
|
89
92
|
}
|
@@ -219,28 +222,28 @@ get_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_get_
|
|
219
222
|
VALUE
|
220
223
|
cb_bucket_get(int argc, VALUE *argv, VALUE self)
|
221
224
|
{
|
222
|
-
struct
|
223
|
-
struct
|
225
|
+
struct cb_bucket_st *bucket = DATA_PTR(self);
|
226
|
+
struct cb_context_st *ctx;
|
224
227
|
VALUE args, rv, proc, exc;
|
225
228
|
size_t ii;
|
226
229
|
lcb_error_t err = LCB_SUCCESS;
|
227
|
-
struct
|
230
|
+
struct cb_params_st params;
|
228
231
|
|
229
232
|
if (bucket->handle == NULL) {
|
230
|
-
rb_raise(
|
233
|
+
rb_raise(cb_eConnectError, "closed connection");
|
231
234
|
}
|
232
235
|
rb_scan_args(argc, argv, "0*&", &args, &proc);
|
233
236
|
if (!bucket->async && proc != Qnil) {
|
234
237
|
rb_raise(rb_eArgError, "synchronous mode doesn't support callbacks");
|
235
238
|
}
|
236
|
-
memset(¶ms, 0, sizeof(struct
|
237
|
-
params.type =
|
239
|
+
memset(¶ms, 0, sizeof(struct cb_params_st));
|
240
|
+
params.type = cb_cmd_get;
|
238
241
|
params.bucket = bucket;
|
239
242
|
params.cmd.get.keys_ary = cb_gc_protect(bucket, rb_ary_new());
|
240
243
|
cb_params_build(¶ms, RARRAY_LEN(args), args);
|
241
|
-
ctx = xcalloc(1, sizeof(struct
|
244
|
+
ctx = xcalloc(1, sizeof(struct cb_context_st));
|
242
245
|
if (ctx == NULL) {
|
243
|
-
rb_raise(
|
246
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for context");
|
244
247
|
}
|
245
248
|
ctx->extended = params.cmd.get.extended;
|
246
249
|
ctx->quiet = params.cmd.get.quiet;
|
@@ -267,7 +270,7 @@ cb_bucket_get(int argc, VALUE *argv, VALUE self)
|
|
267
270
|
}
|
268
271
|
bucket->nbytes += params.npayload;
|
269
272
|
if (bucket->async) {
|
270
|
-
|
273
|
+
cb_maybe_do_loop(bucket);
|
271
274
|
return Qnil;
|
272
275
|
} else {
|
273
276
|
if (ctx->nqueries > 0) {
|
data/ext/couchbase_ext/http.c
CHANGED
@@ -18,35 +18,39 @@
|
|
18
18
|
#include "couchbase_ext.h"
|
19
19
|
|
20
20
|
void
|
21
|
-
|
21
|
+
cb_http_complete_callback(lcb_http_request_t request, lcb_t handle, const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp)
|
22
22
|
{
|
23
|
-
struct
|
24
|
-
struct
|
23
|
+
struct cb_context_st *ctx = (struct cb_context_st *)cookie;
|
24
|
+
struct cb_bucket_st *bucket = ctx->bucket;
|
25
25
|
VALUE *rv = ctx->rv, key, val, res;
|
26
26
|
lcb_http_status_t status;
|
27
27
|
|
28
28
|
ctx->request->completed = 1;
|
29
29
|
key = STR_NEW((const char*)resp->v.v0.path, resp->v.v0.npath);
|
30
|
+
val = resp->v.v0.nbytes ? STR_NEW((const char*)resp->v.v0.bytes, resp->v.v0.nbytes) : Qnil;
|
30
31
|
ctx->exception = cb_check_error_with_status(error,
|
31
32
|
"failed to execute HTTP request", key, resp->v.v0.status);
|
32
33
|
if (ctx->exception != Qnil) {
|
34
|
+
if (val != Qnil) {
|
35
|
+
rb_ivar_set(ctx->exception, cb_id_iv_body, val);
|
36
|
+
}
|
37
|
+
rb_funcall(ctx->exception, cb_id_parse_body_bang, 0);
|
33
38
|
cb_gc_protect(bucket, ctx->exception);
|
34
39
|
}
|
35
|
-
val = resp->v.v0.nbytes ? STR_NEW((const char*)resp->v.v0.bytes, resp->v.v0.nbytes) : Qnil;
|
36
40
|
status = resp->v.v0.status;
|
37
41
|
if (resp->v.v0.headers) {
|
38
42
|
cb_build_headers(ctx, resp->v.v0.headers);
|
39
43
|
cb_gc_unprotect(bucket, ctx->headers_val);
|
40
44
|
}
|
41
45
|
if (ctx->extended) {
|
42
|
-
res = rb_class_new_instance(0, NULL,
|
43
|
-
rb_ivar_set(res,
|
44
|
-
rb_ivar_set(res,
|
45
|
-
rb_ivar_set(res,
|
46
|
-
rb_ivar_set(res,
|
47
|
-
rb_ivar_set(res,
|
48
|
-
rb_ivar_set(res,
|
49
|
-
rb_ivar_set(res,
|
46
|
+
res = rb_class_new_instance(0, NULL, cb_cResult);
|
47
|
+
rb_ivar_set(res, cb_id_iv_error, ctx->exception);
|
48
|
+
rb_ivar_set(res, cb_id_iv_status, status ? INT2FIX(status) : Qnil);
|
49
|
+
rb_ivar_set(res, cb_id_iv_operation, cb_sym_http_request);
|
50
|
+
rb_ivar_set(res, cb_id_iv_key, key);
|
51
|
+
rb_ivar_set(res, cb_id_iv_value, val);
|
52
|
+
rb_ivar_set(res, cb_id_iv_completed, Qtrue);
|
53
|
+
rb_ivar_set(res, cb_id_iv_headers, ctx->headers_val);
|
50
54
|
} else {
|
51
55
|
res = val;
|
52
56
|
}
|
@@ -61,35 +65,45 @@ http_complete_callback(lcb_http_request_t request, lcb_t handle, const void *coo
|
|
61
65
|
}
|
62
66
|
|
63
67
|
void
|
64
|
-
|
68
|
+
cb_http_data_callback(lcb_http_request_t request, lcb_t handle, const void *cookie, lcb_error_t error, const lcb_http_resp_t *resp)
|
65
69
|
{
|
66
|
-
struct
|
67
|
-
struct
|
70
|
+
struct cb_context_st *ctx = (struct cb_context_st *)cookie;
|
71
|
+
struct cb_bucket_st *bucket = ctx->bucket;
|
68
72
|
VALUE key, val, res;
|
69
73
|
lcb_http_status_t status;
|
70
74
|
|
71
75
|
key = STR_NEW((const char*)resp->v.v0.path, resp->v.v0.npath);
|
72
|
-
ctx->exception = cb_check_error_with_status(error,
|
73
|
-
"failed to execute HTTP request", key, resp->v.v0.status);
|
74
76
|
val = resp->v.v0.nbytes ? STR_NEW((const char*)resp->v.v0.bytes, resp->v.v0.nbytes) : Qnil;
|
75
77
|
status = resp->v.v0.status;
|
76
|
-
if (ctx->exception
|
77
|
-
|
78
|
-
|
78
|
+
if (NIL_P(ctx->exception)) {
|
79
|
+
ctx->exception = cb_check_error_with_status(error,
|
80
|
+
"failed to execute HTTP request", key, resp->v.v0.status);
|
81
|
+
if (ctx->exception != Qnil) {
|
82
|
+
VALUE body_str = rb_ivar_get(ctx->exception, cb_id_iv_body);
|
83
|
+
if (NIL_P(body_str)) {
|
84
|
+
cb_gc_protect(bucket, ctx->exception);
|
85
|
+
rb_ivar_set(ctx->exception, cb_id_iv_body, val);
|
86
|
+
} else {
|
87
|
+
rb_str_concat(body_str, val);
|
88
|
+
}
|
89
|
+
if (ctx->http_cancel_on_error) {
|
90
|
+
lcb_cancel_http_request(bucket->handle, request);
|
91
|
+
}
|
92
|
+
}
|
79
93
|
}
|
80
94
|
if (resp->v.v0.headers) {
|
81
95
|
cb_build_headers(ctx, resp->v.v0.headers);
|
82
96
|
}
|
83
97
|
if (ctx->proc != Qnil) {
|
84
98
|
if (ctx->extended) {
|
85
|
-
res = rb_class_new_instance(0, NULL,
|
86
|
-
rb_ivar_set(res,
|
87
|
-
rb_ivar_set(res,
|
88
|
-
rb_ivar_set(res,
|
89
|
-
rb_ivar_set(res,
|
90
|
-
rb_ivar_set(res,
|
91
|
-
rb_ivar_set(res,
|
92
|
-
rb_ivar_set(res,
|
99
|
+
res = rb_class_new_instance(0, NULL, cb_cResult);
|
100
|
+
rb_ivar_set(res, cb_id_iv_error, ctx->exception);
|
101
|
+
rb_ivar_set(res, cb_id_iv_status, status ? INT2FIX(status) : Qnil);
|
102
|
+
rb_ivar_set(res, cb_id_iv_operation, cb_sym_http_request);
|
103
|
+
rb_ivar_set(res, cb_id_iv_key, key);
|
104
|
+
rb_ivar_set(res, cb_id_iv_value, val);
|
105
|
+
rb_ivar_set(res, cb_id_iv_completed, Qfalse);
|
106
|
+
rb_ivar_set(res, cb_id_iv_headers, ctx->headers_val);
|
93
107
|
} else {
|
94
108
|
res = val;
|
95
109
|
}
|
@@ -101,7 +115,7 @@ http_data_callback(lcb_http_request_t request, lcb_t handle, const void *cookie,
|
|
101
115
|
void
|
102
116
|
cb_http_request_free(void *ptr)
|
103
117
|
{
|
104
|
-
struct
|
118
|
+
struct cb_http_request_st *request = ptr;
|
105
119
|
if (request) {
|
106
120
|
request->running = 0;
|
107
121
|
if (TYPE(request->bucket_obj) == T_DATA
|
@@ -119,7 +133,7 @@ cb_http_request_free(void *ptr)
|
|
119
133
|
void
|
120
134
|
cb_http_request_mark(void *ptr)
|
121
135
|
{
|
122
|
-
struct
|
136
|
+
struct cb_http_request_st *request = ptr;
|
123
137
|
if (request) {
|
124
138
|
rb_gc_mark(request->on_body_callback);
|
125
139
|
}
|
@@ -129,10 +143,10 @@ cb_http_request_mark(void *ptr)
|
|
129
143
|
cb_http_request_alloc(VALUE klass)
|
130
144
|
{
|
131
145
|
VALUE obj;
|
132
|
-
struct
|
146
|
+
struct cb_http_request_st *request;
|
133
147
|
|
134
148
|
/* allocate new bucket struct and set it to zero */
|
135
|
-
obj = Data_Make_Struct(klass, struct
|
149
|
+
obj = Data_Make_Struct(klass, struct cb_http_request_st, cb_http_request_mark,
|
136
150
|
cb_http_request_free, request);
|
137
151
|
return obj;
|
138
152
|
}
|
@@ -149,7 +163,7 @@ cb_http_request_alloc(VALUE klass)
|
|
149
163
|
cb_http_request_inspect(VALUE self)
|
150
164
|
{
|
151
165
|
VALUE str;
|
152
|
-
struct
|
166
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
153
167
|
char buf[200];
|
154
168
|
|
155
169
|
str = rb_str_buf_new2("#<");
|
@@ -173,14 +187,14 @@ cb_http_request_inspect(VALUE self)
|
|
173
187
|
VALUE
|
174
188
|
cb_http_request_init(int argc, VALUE *argv, VALUE self)
|
175
189
|
{
|
176
|
-
struct
|
190
|
+
struct cb_http_request_st *request = DATA_PTR(self);
|
177
191
|
VALUE bucket, path, opts, on_body, pp, arg;
|
178
192
|
rb_scan_args(argc, argv, "22", &bucket, &pp, &opts, &on_body);
|
179
193
|
|
180
194
|
if (NIL_P(on_body) && rb_block_given_p()) {
|
181
195
|
on_body = rb_block_proc();
|
182
196
|
}
|
183
|
-
if (CLASS_OF(bucket) !=
|
197
|
+
if (CLASS_OF(bucket) != cb_cBucket) {
|
184
198
|
rb_raise(rb_eTypeError, "wrong argument type (expected Couchbase::Bucket)");
|
185
199
|
}
|
186
200
|
memset(&request->cmd, 0, sizeof(lcb_http_cmd_t));
|
@@ -197,36 +211,36 @@ cb_http_request_init(int argc, VALUE *argv, VALUE self)
|
|
197
211
|
|
198
212
|
if (opts != Qnil) {
|
199
213
|
Check_Type(opts, T_HASH);
|
200
|
-
request->extended = RTEST(rb_hash_aref(opts,
|
201
|
-
request->cmd.v.v0.chunked = RTEST(rb_hash_aref(opts,
|
202
|
-
if ((arg = rb_hash_aref(opts,
|
203
|
-
if (arg ==
|
214
|
+
request->extended = RTEST(rb_hash_aref(opts, cb_sym_extended));
|
215
|
+
request->cmd.v.v0.chunked = RTEST(rb_hash_aref(opts, cb_sym_chunked));
|
216
|
+
if ((arg = rb_hash_aref(opts, cb_sym_type)) != Qnil) {
|
217
|
+
if (arg == cb_sym_view) {
|
204
218
|
request->type = LCB_HTTP_TYPE_VIEW;
|
205
|
-
} else if (arg ==
|
219
|
+
} else if (arg == cb_sym_management) {
|
206
220
|
request->type = LCB_HTTP_TYPE_MANAGEMENT;
|
207
221
|
} else {
|
208
222
|
rb_raise(rb_eArgError, "unsupported request type");
|
209
223
|
}
|
210
224
|
}
|
211
|
-
if ((arg = rb_hash_aref(opts,
|
212
|
-
if (arg ==
|
225
|
+
if ((arg = rb_hash_aref(opts, cb_sym_method)) != Qnil) {
|
226
|
+
if (arg == cb_sym_get) {
|
213
227
|
request->cmd.v.v0.method = LCB_HTTP_METHOD_GET;
|
214
|
-
} else if (arg ==
|
228
|
+
} else if (arg == cb_sym_post) {
|
215
229
|
request->cmd.v.v0.method = LCB_HTTP_METHOD_POST;
|
216
|
-
} else if (arg ==
|
230
|
+
} else if (arg == cb_sym_put) {
|
217
231
|
request->cmd.v.v0.method = LCB_HTTP_METHOD_PUT;
|
218
|
-
} else if (arg ==
|
232
|
+
} else if (arg == cb_sym_delete) {
|
219
233
|
request->cmd.v.v0.method = LCB_HTTP_METHOD_DELETE;
|
220
234
|
} else {
|
221
235
|
rb_raise(rb_eArgError, "unsupported HTTP method");
|
222
236
|
}
|
223
237
|
}
|
224
|
-
if ((arg = rb_hash_aref(opts,
|
238
|
+
if ((arg = rb_hash_aref(opts, cb_sym_body)) != Qnil) {
|
225
239
|
Check_Type(arg, T_STRING);
|
226
240
|
request->cmd.v.v0.body = strdup(RSTRING_PTR(arg));
|
227
241
|
request->cmd.v.v0.nbody = RSTRING_LEN(arg);
|
228
242
|
}
|
229
|
-
if ((arg = rb_hash_aref(opts,
|
243
|
+
if ((arg = rb_hash_aref(opts, cb_sym_content_type)) != Qnil) {
|
230
244
|
Check_Type(arg, T_STRING);
|
231
245
|
xfree((char *)request->cmd.v.v0.content_type);
|
232
246
|
request->cmd.v.v0.content_type = strdup(RSTRING_PTR(arg));
|
@@ -244,7 +258,7 @@ cb_http_request_init(int argc, VALUE *argv, VALUE self)
|
|
244
258
|
VALUE
|
245
259
|
cb_http_request_on_body(VALUE self)
|
246
260
|
{
|
247
|
-
struct
|
261
|
+
struct cb_http_request_st *request = DATA_PTR(self);
|
248
262
|
VALUE old = request->on_body_callback;
|
249
263
|
if (rb_block_given_p()) {
|
250
264
|
request->on_body_callback = rb_block_proc();
|
@@ -260,15 +274,15 @@ cb_http_request_on_body(VALUE self)
|
|
260
274
|
VALUE
|
261
275
|
cb_http_request_perform(VALUE self)
|
262
276
|
{
|
263
|
-
struct
|
264
|
-
struct
|
277
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
278
|
+
struct cb_context_st *ctx;
|
265
279
|
VALUE rv, exc;
|
266
280
|
lcb_error_t err;
|
267
|
-
struct
|
281
|
+
struct cb_bucket_st *bucket;
|
268
282
|
|
269
|
-
ctx = xcalloc(1, sizeof(struct
|
283
|
+
ctx = xcalloc(1, sizeof(struct cb_context_st));
|
270
284
|
if (ctx == NULL) {
|
271
|
-
rb_raise(
|
285
|
+
rb_raise(cb_eClientNoMemoryError, "failed to allocate memory");
|
272
286
|
}
|
273
287
|
rv = Qnil;
|
274
288
|
ctx->rv = &rv;
|
@@ -310,7 +324,7 @@ cb_http_request_perform(VALUE self)
|
|
310
324
|
VALUE
|
311
325
|
cb_http_request_pause(VALUE self)
|
312
326
|
{
|
313
|
-
struct
|
327
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
314
328
|
lcb_breakout(req->bucket->handle);
|
315
329
|
return Qnil;
|
316
330
|
}
|
@@ -319,7 +333,7 @@ cb_http_request_pause(VALUE self)
|
|
319
333
|
cb_http_request_continue(VALUE self)
|
320
334
|
{
|
321
335
|
VALUE exc, *rv;
|
322
|
-
struct
|
336
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
323
337
|
|
324
338
|
if (req->running) {
|
325
339
|
lcb_wait(req->bucket->handle);
|
@@ -348,7 +362,7 @@ cb_http_request_continue(VALUE self)
|
|
348
362
|
VALUE
|
349
363
|
cb_http_request_path_get(VALUE self)
|
350
364
|
{
|
351
|
-
struct
|
365
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
352
366
|
return STR_NEW_CSTR(req->cmd.v.v0.path);
|
353
367
|
}
|
354
368
|
|
@@ -362,7 +376,7 @@ cb_http_request_path_get(VALUE self)
|
|
362
376
|
VALUE
|
363
377
|
cb_http_request_chunked_get(VALUE self)
|
364
378
|
{
|
365
|
-
struct
|
379
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
366
380
|
return req->cmd.v.v0.chunked ? Qtrue : Qfalse;
|
367
381
|
}
|
368
382
|
|
@@ -376,7 +390,7 @@ cb_http_request_chunked_get(VALUE self)
|
|
376
390
|
VALUE
|
377
391
|
cb_http_request_extended_get(VALUE self)
|
378
392
|
{
|
379
|
-
struct
|
393
|
+
struct cb_http_request_st *req = DATA_PTR(self);
|
380
394
|
return req->extended ? Qtrue : Qfalse;
|
381
395
|
}
|
382
396
|
|
@@ -402,7 +416,7 @@ cb_bucket_make_http_request(int argc, VALUE *argv, VALUE self)
|
|
402
416
|
args[0] = self;
|
403
417
|
rb_scan_args(argc, argv, "11&", &args[1], &args[2], &args[3]);
|
404
418
|
|
405
|
-
return rb_class_new_instance(4, args,
|
419
|
+
return rb_class_new_instance(4, args, cb_cCouchRequest);
|
406
420
|
}
|
407
421
|
|
408
422
|
|