libcouchbase 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/libcouchbase/.gitignore +2 -0
- data/ext/libcouchbase/CMakeLists.txt +5 -7
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +49 -0
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +2 -1
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
- data/ext/libcouchbase/cmake/defs.mk.in +0 -2
- data/ext/libcouchbase/cmake/source_files.cmake +34 -14
- data/ext/libcouchbase/configure.pl +1 -1
- data/ext/libcouchbase/contrib/genhash/genhash.h +6 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +10 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +10 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +7 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +13 -1
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +9 -0
- data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
- data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +21 -1132
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
- data/ext/libcouchbase/src/README.md +0 -2
- data/ext/libcouchbase/src/auth-priv.h +1 -0
- data/ext/libcouchbase/src/auth.cc +10 -0
- data/ext/libcouchbase/src/bootstrap.cc +216 -0
- data/ext/libcouchbase/src/bootstrap.h +50 -39
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +455 -0
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +528 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +115 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +407 -386
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +378 -0
- data/ext/libcouchbase/src/cbft.cc +22 -27
- data/ext/libcouchbase/src/cntl.cc +24 -24
- data/ext/libcouchbase/src/connspec.cc +30 -1
- data/ext/libcouchbase/src/connspec.h +17 -0
- data/ext/libcouchbase/src/dns-srv.cc +143 -0
- data/ext/libcouchbase/src/{dump.c → dump.cc} +8 -11
- data/ext/libcouchbase/src/getconfig.cc +73 -0
- data/ext/libcouchbase/src/handler.cc +84 -85
- data/ext/libcouchbase/src/hostlist.cc +0 -1
- data/ext/libcouchbase/src/hostlist.h +6 -1
- data/ext/libcouchbase/src/http/http-priv.h +125 -112
- data/ext/libcouchbase/src/http/http.cc +9 -29
- data/ext/libcouchbase/src/http/http.h +1 -34
- data/ext/libcouchbase/src/http/http_io.cc +22 -26
- data/ext/libcouchbase/src/instance.cc +102 -28
- data/ext/libcouchbase/src/internal.h +47 -29
- data/ext/libcouchbase/src/jsparse/parser.cc +146 -202
- data/ext/libcouchbase/src/jsparse/parser.h +91 -98
- data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
- data/ext/libcouchbase/src/lcbio/connect.cc +562 -0
- data/ext/libcouchbase/src/lcbio/connect.h +9 -2
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +61 -16
- data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
- data/ext/libcouchbase/src/lcbio/manager.c +2 -2
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
- data/ext/libcouchbase/src/mc/mcreq.h +9 -2
- data/ext/libcouchbase/src/mcserver/mcserver.cc +723 -0
- data/ext/libcouchbase/src/mcserver/mcserver.h +160 -70
- data/ext/libcouchbase/src/mcserver/negotiate.cc +118 -152
- data/ext/libcouchbase/src/mcserver/negotiate.h +85 -74
- data/ext/libcouchbase/src/mctx-helper.h +51 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
- data/ext/libcouchbase/src/n1ql/n1ql.cc +56 -32
- data/ext/libcouchbase/src/{newconfig.c → newconfig.cc} +42 -70
- data/ext/libcouchbase/src/nodeinfo.cc +4 -8
- data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
- data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
- data/ext/libcouchbase/src/operations/{durability-cas.c → durability-cas.cc} +92 -76
- data/ext/libcouchbase/src/operations/{durability-seqno.c → durability-seqno.cc} +55 -49
- data/ext/libcouchbase/src/operations/durability.cc +643 -0
- data/ext/libcouchbase/src/operations/durability_internal.h +212 -124
- data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
- data/ext/libcouchbase/src/operations/{observe-seqno.c → observe-seqno.cc} +5 -8
- data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +69 -94
- data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
- data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
- data/ext/libcouchbase/src/operations/{stats.c → stats.cc} +66 -78
- data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
- data/ext/libcouchbase/src/operations/subdoc.cc +38 -18
- data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
- data/ext/libcouchbase/src/packetutils.h +200 -137
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +3 -4
- data/ext/libcouchbase/src/retryq.cc +394 -0
- data/ext/libcouchbase/src/retryq.h +116 -104
- data/ext/libcouchbase/src/settings.h +2 -1
- data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
- data/ext/libcouchbase/src/trace.h +8 -8
- data/ext/libcouchbase/src/vbucket/vbucket.c +0 -1
- data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
- data/ext/libcouchbase/src/views/docreq.h +24 -30
- data/ext/libcouchbase/src/views/viewreq.cc +318 -0
- data/ext/libcouchbase/src/views/viewreq.h +43 -13
- data/ext/libcouchbase/src/{wait.c → wait.cc} +12 -17
- data/ext/libcouchbase/tests/basic/t_connstr.cc +89 -50
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -78
- data/ext/libcouchbase/tests/basic/t_packet.cc +35 -42
- data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +94 -111
- data/ext/libcouchbase/tests/iotests/t_sched.cc +1 -2
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
- data/lib/libcouchbase/version.rb +1 -1
- metadata +36 -39
- data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
- data/ext/libcouchbase/src/bootstrap.c +0 -269
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +0 -495
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
- data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
- data/ext/libcouchbase/src/getconfig.c +0 -100
- data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
- data/ext/libcouchbase/src/lcbio/connect.c +0 -557
- data/ext/libcouchbase/src/mcserver/mcserver.c +0 -784
- data/ext/libcouchbase/src/operations/durability.c +0 -668
- data/ext/libcouchbase/src/packetutils.c +0 -60
- data/ext/libcouchbase/src/retryq.c +0 -424
- data/ext/libcouchbase/src/simplestring.c +0 -211
- data/ext/libcouchbase/src/simplestring.h +0 -228
- data/ext/libcouchbase/src/ssobuf.h +0 -82
- data/ext/libcouchbase/src/views/viewreq.c +0 -358
- data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
|
@@ -35,27 +35,30 @@ DECLARE_JSONSL_CALLBACK(initial_pop_callback);
|
|
|
35
35
|
DECLARE_JSONSL_CALLBACK(meta_header_complete_callback);
|
|
36
36
|
DECLARE_JSONSL_CALLBACK(trailer_pop_callback);
|
|
37
37
|
|
|
38
|
+
using namespace lcb::jsparse;
|
|
39
|
+
|
|
38
40
|
/* conform to void */
|
|
39
41
|
#define JOBJ_RESPONSE_ROOT (void*)1
|
|
40
42
|
#define JOBJ_ROWSET (void*)2
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
template <typename T>
|
|
45
|
+
void NORMALIZE_OFFSETS(const char *& buf, T& len) {
|
|
46
|
+
buf++;
|
|
47
|
+
len--;
|
|
48
|
+
}
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
51
|
* Gets a buffer, given an (absolute) position offset.
|
|
48
52
|
* It will try to get a buffer of size desired. The actual size is
|
|
49
53
|
* returned in 'actual' (and may be less than desired, maybe even 0)
|
|
50
54
|
*/
|
|
51
|
-
|
|
52
|
-
get_buffer_region(lcbjsp_PARSER *ctx, size_t pos, size_t desired, size_t *actual)
|
|
55
|
+
const char * Parser::get_buffer_region(size_t pos, size_t desired, size_t *actual)
|
|
53
56
|
{
|
|
54
|
-
const char *ret =
|
|
55
|
-
const char *end =
|
|
57
|
+
const char *ret = current_buf.c_str() + pos - min_pos;
|
|
58
|
+
const char *end = current_buf.c_str() + current_buf.size();
|
|
56
59
|
*actual = end - ret;
|
|
57
60
|
|
|
58
|
-
if (
|
|
61
|
+
if (min_pos > pos) {
|
|
59
62
|
/* swallowed */
|
|
60
63
|
*actual = 0;
|
|
61
64
|
return NULL;
|
|
@@ -71,55 +74,46 @@ get_buffer_region(lcbjsp_PARSER *ctx, size_t pos, size_t desired, size_t *actual
|
|
|
71
74
|
/**
|
|
72
75
|
* Consolidate the meta data into a single parsable string..
|
|
73
76
|
*/
|
|
74
|
-
|
|
75
|
-
combine_meta(lcbjsp_PARSER *ctx)
|
|
76
|
-
{
|
|
77
|
+
void Parser::combine_meta() {
|
|
77
78
|
const char *meta_trailer;
|
|
78
79
|
size_t ntrailer;
|
|
79
80
|
|
|
80
|
-
if (
|
|
81
|
+
if (meta_complete) {
|
|
81
82
|
return;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
assert(
|
|
85
|
+
assert(header_len <= meta_buf.size());
|
|
85
86
|
|
|
86
87
|
/* Adjust the length for the first portion */
|
|
87
|
-
|
|
88
|
+
meta_buf.resize(header_len);
|
|
88
89
|
|
|
89
90
|
/* Append any trailing data */
|
|
90
|
-
meta_trailer = get_buffer_region(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
ctx->meta_complete = 1;
|
|
91
|
+
meta_trailer = get_buffer_region(last_row_endpos, -1, &ntrailer);
|
|
92
|
+
meta_buf.append(meta_trailer, ntrailer);
|
|
93
|
+
meta_complete = 1;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
static
|
|
97
|
-
|
|
98
|
-
{
|
|
99
|
-
return reinterpret_cast<lcbjsp_PARSER*>(jsn->data);
|
|
96
|
+
static Parser * get_ctx(jsonsl_t jsn) {
|
|
97
|
+
return reinterpret_cast<Parser*>(jsn->data);
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
static void
|
|
103
|
-
meta_header_complete_callback(jsonsl_t jsn, jsonsl_action_t
|
|
104
|
-
struct jsonsl_state_st *state, const jsonsl_char_t *
|
|
101
|
+
meta_header_complete_callback(jsonsl_t jsn, jsonsl_action_t,
|
|
102
|
+
struct jsonsl_state_st *state, const jsonsl_char_t *)
|
|
105
103
|
{
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
buffer_append(&ctx->meta_buf, ctx->current_buf.base, state->pos_begin);
|
|
104
|
+
Parser *ctx = get_ctx(jsn);
|
|
105
|
+
ctx->meta_buf.append(ctx->current_buf.c_str(), state->pos_begin);
|
|
109
106
|
|
|
110
107
|
ctx->header_len = state->pos_begin;
|
|
111
108
|
jsn->action_callback_PUSH = NULL;
|
|
112
|
-
|
|
113
|
-
(void)action; (void)at;
|
|
114
109
|
}
|
|
115
110
|
|
|
116
111
|
|
|
117
112
|
static void
|
|
118
|
-
row_pop_callback(jsonsl_t jsn, jsonsl_action_t
|
|
119
|
-
struct jsonsl_state_st *state, const jsonsl_char_t *
|
|
113
|
+
row_pop_callback(jsonsl_t jsn, jsonsl_action_t,
|
|
114
|
+
struct jsonsl_state_st *state, const jsonsl_char_t *)
|
|
120
115
|
{
|
|
121
|
-
|
|
122
|
-
lcbjsp_PARSER *ctx = get_ctx(jsn);
|
|
116
|
+
Parser *ctx = get_ctx(jsn);
|
|
123
117
|
const char *rowbuf;
|
|
124
118
|
size_t szdummy;
|
|
125
119
|
|
|
@@ -139,71 +133,59 @@ row_pop_callback(jsonsl_t jsn, jsonsl_action_t action,
|
|
|
139
133
|
|
|
140
134
|
/* While the entire meta is available to us, the _closing_ part
|
|
141
135
|
* of the meta is handled in a different callback. */
|
|
142
|
-
|
|
136
|
+
ctx->meta_buf.append(ctx->current_buf.c_str(), jsn->pos);
|
|
143
137
|
ctx->header_len = jsn->pos;
|
|
144
138
|
}
|
|
145
139
|
return;
|
|
146
140
|
}
|
|
147
141
|
|
|
148
142
|
ctx->rowcount++;
|
|
149
|
-
|
|
150
|
-
if (!ctx->callback) {
|
|
143
|
+
if (!ctx->actions) {
|
|
151
144
|
return;
|
|
152
145
|
}
|
|
153
146
|
|
|
154
|
-
rowbuf = get_buffer_region(
|
|
155
|
-
dt
|
|
147
|
+
rowbuf = ctx->get_buffer_region(state->pos_begin, -1, &szdummy);
|
|
148
|
+
Row dt = {{0}};
|
|
156
149
|
dt.row.iov_base = (void *)rowbuf;
|
|
157
150
|
dt.row.iov_len = jsn->pos - state->pos_begin + 1;
|
|
158
|
-
ctx->
|
|
159
|
-
|
|
160
|
-
(void)action; (void)at;
|
|
151
|
+
ctx->actions->JSPARSE_on_row(dt);
|
|
161
152
|
}
|
|
162
153
|
|
|
163
154
|
static int
|
|
164
|
-
parse_error_callback(jsonsl_t jsn, jsonsl_error_t
|
|
165
|
-
struct jsonsl_state_st
|
|
155
|
+
parse_error_callback(jsonsl_t jsn, jsonsl_error_t,
|
|
156
|
+
struct jsonsl_state_st *, jsonsl_char_t *)
|
|
166
157
|
{
|
|
167
|
-
|
|
168
|
-
lcbjsp_ROW dt;
|
|
169
|
-
|
|
158
|
+
Parser *ctx = get_ctx(jsn);
|
|
170
159
|
ctx->have_error = 1;
|
|
171
160
|
|
|
172
161
|
/* invoke the callback */
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
(void)error; (void)state; (void)at;
|
|
179
|
-
|
|
162
|
+
if (ctx->actions) {
|
|
163
|
+
ctx->actions->JSPARSE_on_error(ctx->current_buf);
|
|
164
|
+
ctx->actions = NULL;
|
|
165
|
+
}
|
|
180
166
|
return 0;
|
|
181
167
|
}
|
|
182
168
|
|
|
183
169
|
static void
|
|
184
|
-
trailer_pop_callback(jsonsl_t jsn, jsonsl_action_t
|
|
185
|
-
struct jsonsl_state_st *state, const jsonsl_char_t *
|
|
170
|
+
trailer_pop_callback(jsonsl_t jsn, jsonsl_action_t,
|
|
171
|
+
struct jsonsl_state_st *state, const jsonsl_char_t *)
|
|
186
172
|
{
|
|
187
|
-
|
|
188
|
-
lcbjsp_ROW dt;
|
|
173
|
+
Parser *ctx = get_ctx(jsn);
|
|
189
174
|
if (state->data != JOBJ_RESPONSE_ROOT) {
|
|
190
175
|
return;
|
|
191
176
|
}
|
|
192
|
-
combine_meta(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
(void)action; (void)at;
|
|
177
|
+
ctx->combine_meta();
|
|
178
|
+
if (ctx->actions) {
|
|
179
|
+
ctx->actions->JSPARSE_on_complete(ctx->meta_buf);
|
|
180
|
+
ctx->actions = NULL;
|
|
181
|
+
}
|
|
199
182
|
}
|
|
200
183
|
|
|
201
184
|
static void
|
|
202
|
-
initial_pop_callback(jsonsl_t jsn, jsonsl_action_t
|
|
203
|
-
struct jsonsl_state_st *state, const jsonsl_char_t *
|
|
185
|
+
initial_pop_callback(jsonsl_t jsn, jsonsl_action_t,
|
|
186
|
+
struct jsonsl_state_st *state, const jsonsl_char_t *)
|
|
204
187
|
{
|
|
205
|
-
|
|
206
|
-
char *key;
|
|
188
|
+
Parser *ctx = get_ctx(jsn);
|
|
207
189
|
unsigned long len;
|
|
208
190
|
|
|
209
191
|
if (ctx->have_error) {
|
|
@@ -216,14 +198,10 @@ initial_pop_callback(jsonsl_t jsn, jsonsl_action_t action,
|
|
|
216
198
|
return;
|
|
217
199
|
}
|
|
218
200
|
|
|
219
|
-
key = ctx->current_buf.
|
|
201
|
+
const char *key = ctx->current_buf.c_str() + state->pos_begin;
|
|
220
202
|
len = jsn->pos - state->pos_begin;
|
|
221
203
|
NORMALIZE_OFFSETS(key, len);
|
|
222
|
-
|
|
223
|
-
lcb_string_clear(&ctx->last_hk);
|
|
224
|
-
buffer_append(&ctx->last_hk, key, len);
|
|
225
|
-
|
|
226
|
-
(void)action; (void)at;
|
|
204
|
+
ctx->last_hk.assign(key, len);
|
|
227
205
|
}
|
|
228
206
|
|
|
229
207
|
/**
|
|
@@ -231,10 +209,10 @@ initial_pop_callback(jsonsl_t jsn, jsonsl_action_t action,
|
|
|
231
209
|
* for the row set.
|
|
232
210
|
*/
|
|
233
211
|
static void
|
|
234
|
-
initial_push_callback(jsonsl_t jsn, jsonsl_action_t
|
|
235
|
-
struct jsonsl_state_st *state, const jsonsl_char_t *
|
|
212
|
+
initial_push_callback(jsonsl_t jsn, jsonsl_action_t,
|
|
213
|
+
struct jsonsl_state_st *state, const jsonsl_char_t *)
|
|
236
214
|
{
|
|
237
|
-
|
|
215
|
+
Parser *ctx = (Parser*)jsn->data;
|
|
238
216
|
jsonsl_jpr_match_t match = JSONSL_MATCH_UNKNOWN;
|
|
239
217
|
|
|
240
218
|
if (ctx->have_error) {
|
|
@@ -242,11 +220,10 @@ initial_push_callback(jsonsl_t jsn, jsonsl_action_t action,
|
|
|
242
220
|
}
|
|
243
221
|
|
|
244
222
|
if (JSONSL_STATE_IS_CONTAINER(state)) {
|
|
245
|
-
jsonsl_jpr_match_state(jsn, state, ctx->last_hk.
|
|
223
|
+
jsonsl_jpr_match_state(jsn, state, ctx->last_hk.c_str(), ctx->last_hk.size(),
|
|
246
224
|
&match);
|
|
247
225
|
}
|
|
248
|
-
|
|
249
|
-
lcb_string_clear(&ctx->last_hk);
|
|
226
|
+
ctx->last_hk.clear();
|
|
250
227
|
|
|
251
228
|
if (ctx->initialized == 0) {
|
|
252
229
|
if (state->type != JSONSL_T_OBJECT) {
|
|
@@ -270,149 +247,119 @@ initial_push_callback(jsonsl_t jsn, jsonsl_action_t action,
|
|
|
270
247
|
jsn->action_callback_PUSH = meta_header_complete_callback;
|
|
271
248
|
state->data = JOBJ_ROWSET;
|
|
272
249
|
}
|
|
273
|
-
|
|
274
|
-
(void)action; /* always PUSH */
|
|
275
|
-
(void)at;
|
|
276
250
|
}
|
|
277
251
|
|
|
278
|
-
|
|
279
|
-
feed_data(lcbjsp_PARSER *ctx, const char *data, size_t ndata)
|
|
252
|
+
void Parser::feed(const char *data_, size_t ndata)
|
|
280
253
|
{
|
|
281
|
-
size_t old_len =
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
jsonsl_feed(ctx->jsn, ctx->current_buf.base + old_len, ndata);
|
|
254
|
+
size_t old_len = current_buf.size();
|
|
255
|
+
current_buf.append(data_, ndata);
|
|
256
|
+
jsonsl_feed(jsn, current_buf.c_str() + old_len, ndata);
|
|
285
257
|
|
|
286
258
|
/* Do we need to cut off some bytes? */
|
|
287
|
-
if (
|
|
288
|
-
|
|
289
|
-
const char *buf = get_buffer_region(ctx, ctx->keep_pos, -1, &lentmp);
|
|
290
|
-
memmove(ctx->current_buf.base, buf, ctx->current_buf.nused - diff);
|
|
291
|
-
ctx->current_buf.nused -= diff;
|
|
259
|
+
if (keep_pos > min_pos) {
|
|
260
|
+
current_buf.erase(0, keep_pos - min_pos);
|
|
292
261
|
}
|
|
293
262
|
|
|
294
|
-
|
|
263
|
+
min_pos = keep_pos;
|
|
295
264
|
}
|
|
296
265
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
jsonsl_error_t err;
|
|
309
|
-
|
|
310
|
-
ctx = reinterpret_cast<lcbjsp_PARSER*>(calloc(1, sizeof(*ctx)));
|
|
311
|
-
ctx->jsn = jsonsl_new(512);
|
|
312
|
-
ctx->mode = mode;
|
|
313
|
-
ctx->cxx_data = new Json::Value();
|
|
314
|
-
|
|
315
|
-
if (ctx->mode == LCBJSP_MODE_VIEWS) {
|
|
316
|
-
ctx->jpr = jsonsl_jpr_new("/rows/^", &err);
|
|
317
|
-
} else if (ctx->mode == LCBJSP_MODE_N1QL) {
|
|
318
|
-
ctx->jpr = jsonsl_jpr_new("/results/^", &err);
|
|
319
|
-
} else {
|
|
320
|
-
ctx->jpr = jsonsl_jpr_new("/hits/^", &err);
|
|
266
|
+
const char* Parser::jprstr_for_mode(Mode mode) {
|
|
267
|
+
switch (mode) {
|
|
268
|
+
case MODE_VIEWS:
|
|
269
|
+
return "/rows/^";
|
|
270
|
+
case MODE_N1QL:
|
|
271
|
+
return "/results/^";
|
|
272
|
+
case MODE_FTS:
|
|
273
|
+
return "/hits/^";
|
|
274
|
+
default:
|
|
275
|
+
lcb_assert(0 && "Invalid mode passed!");
|
|
276
|
+
return "/";
|
|
321
277
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
lcb_string_init(&ctx->meta_buf);
|
|
325
|
-
lcb_string_init(&ctx->current_buf);
|
|
326
|
-
lcb_string_init(&ctx->last_hk);
|
|
327
|
-
|
|
328
|
-
if (!ctx->jpr) { abort(); }
|
|
329
|
-
if (!ctx->jsn_rdetails) { abort(); }
|
|
330
|
-
|
|
331
|
-
jsonsl_jpr_match_state_init(ctx->jsn, &ctx->jpr, 1);
|
|
332
|
-
assert(ctx->jsn_rdetails);
|
|
278
|
+
}
|
|
333
279
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
280
|
+
Parser::Parser(Mode mode_, Parser::Actions* actions_) :
|
|
281
|
+
jsn(jsonsl_new(512)),
|
|
282
|
+
jsn_rdetails(jsonsl_new(32)),
|
|
283
|
+
jpr(jsonsl_jpr_new(jprstr_for_mode(mode_), NULL)),
|
|
284
|
+
mode(mode_),
|
|
285
|
+
have_error(0),
|
|
286
|
+
initialized(0),
|
|
287
|
+
meta_complete(0),
|
|
288
|
+
rowcount(0),
|
|
289
|
+
min_pos(0),
|
|
290
|
+
keep_pos(0),
|
|
291
|
+
header_len(0),
|
|
292
|
+
last_row_endpos(0),
|
|
293
|
+
cxx_data(),
|
|
294
|
+
actions(actions_) {
|
|
295
|
+
|
|
296
|
+
jsonsl_jpr_match_state_init(jsn, &jpr, 1);
|
|
297
|
+
reset();
|
|
337
298
|
}
|
|
338
299
|
|
|
339
|
-
void
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
out->iov_base = v->meta_buf.base;
|
|
344
|
-
out->iov_len = v->meta_buf.nused;
|
|
300
|
+
void Parser::get_postmortem(lcb_IOV &out) const {
|
|
301
|
+
if (meta_complete) {
|
|
302
|
+
out.iov_base = const_cast<char*>(meta_buf.c_str());
|
|
303
|
+
out.iov_len = meta_buf.size();
|
|
345
304
|
} else {
|
|
346
|
-
out
|
|
347
|
-
out
|
|
305
|
+
out.iov_base = const_cast<char*>(current_buf.c_str());
|
|
306
|
+
out.iov_len = current_buf.size();
|
|
348
307
|
}
|
|
349
308
|
}
|
|
350
309
|
|
|
351
|
-
void
|
|
352
|
-
lcbjsp_reset(lcbjsp_PARSER* ctx)
|
|
353
|
-
{
|
|
310
|
+
void Parser::reset() {
|
|
354
311
|
/**
|
|
355
312
|
* We create a copy, and set its relevant fields. All other
|
|
356
313
|
* fields are zeroed implicitly. Then we copy the object back.
|
|
357
314
|
*/
|
|
358
|
-
jsonsl_reset(
|
|
359
|
-
jsonsl_reset(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
lcb_string_clear(&ctx->last_hk);
|
|
315
|
+
jsonsl_reset(jsn);
|
|
316
|
+
jsonsl_reset(jsn_rdetails);
|
|
317
|
+
current_buf.clear();
|
|
318
|
+
meta_buf.clear();
|
|
319
|
+
last_hk.clear();
|
|
364
320
|
|
|
365
321
|
/* Initially all callbacks are enabled so that we can search for the
|
|
366
322
|
* rows array. */
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
jsonsl_enable_all_callbacks(
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
323
|
+
jsn->action_callback_POP = initial_pop_callback;
|
|
324
|
+
jsn->action_callback_PUSH = initial_push_callback;
|
|
325
|
+
jsn->error_callback = parse_error_callback;
|
|
326
|
+
jsn->max_callback_level = 4;
|
|
327
|
+
jsn->data = this;
|
|
328
|
+
jsonsl_enable_all_callbacks(jsn);
|
|
329
|
+
|
|
330
|
+
have_error = 0;
|
|
331
|
+
initialized = 0;
|
|
332
|
+
meta_complete = 0;
|
|
333
|
+
rowcount = 0;
|
|
334
|
+
min_pos = 0;
|
|
335
|
+
keep_pos = 0;
|
|
336
|
+
header_len = 0;
|
|
337
|
+
last_row_endpos = 0;
|
|
338
|
+
cxx_data.clear();
|
|
383
339
|
}
|
|
384
340
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
jsonsl_destroy(ctx->jsn_rdetails);
|
|
391
|
-
jsonsl_jpr_destroy(ctx->jpr);
|
|
392
|
-
|
|
393
|
-
lcb_string_release(&ctx->current_buf);
|
|
394
|
-
lcb_string_release(&ctx->meta_buf);
|
|
395
|
-
lcb_string_release(&ctx->last_hk);
|
|
396
|
-
delete reinterpret_cast<Json::Value*>(ctx->cxx_data);
|
|
397
|
-
|
|
398
|
-
free(ctx);
|
|
341
|
+
Parser::~Parser() {
|
|
342
|
+
jsonsl_jpr_match_state_cleanup(jsn);
|
|
343
|
+
jsonsl_destroy(jsn);
|
|
344
|
+
jsonsl_destroy(jsn_rdetails);
|
|
345
|
+
jsonsl_jpr_destroy(jpr);
|
|
399
346
|
}
|
|
400
347
|
|
|
401
348
|
typedef struct {
|
|
402
349
|
const char *root;
|
|
403
350
|
lcb_IOV *next_iov;
|
|
404
|
-
|
|
405
|
-
|
|
351
|
+
Row *datum;
|
|
352
|
+
Parser *parent;
|
|
406
353
|
} miniparse_ctx;
|
|
407
354
|
|
|
408
355
|
static void
|
|
409
|
-
parse_json_docid(lcb_IOV* iov,
|
|
356
|
+
parse_json_docid(lcb_IOV* iov, Parser *parent)
|
|
410
357
|
{
|
|
411
358
|
Json::Reader r;
|
|
412
359
|
const char *s = static_cast<char*>(iov->iov_base);
|
|
413
360
|
const char *s_end = s + iov->iov_len;
|
|
414
|
-
Json::Value
|
|
415
|
-
bool rv = r.parse(s, s_end,
|
|
361
|
+
Json::Value& jvp = parent->cxx_data;
|
|
362
|
+
bool rv = r.parse(s, s_end, jvp);
|
|
416
363
|
if (!rv) {
|
|
417
364
|
// fprintf(stderr, "libcouchbase: Failed to parse document ID as JSON!\n");
|
|
418
365
|
return;
|
|
@@ -421,10 +368,10 @@ parse_json_docid(lcb_IOV* iov, lcbjsp_PARSER *parent)
|
|
|
421
368
|
s = NULL;
|
|
422
369
|
s_end = NULL;
|
|
423
370
|
|
|
424
|
-
assert(jvp
|
|
371
|
+
assert(jvp.isString());
|
|
425
372
|
|
|
426
373
|
// Re-use s and s_end values for the string value itself
|
|
427
|
-
if (!jvp
|
|
374
|
+
if (!jvp.getString(&s, &s_end)) {
|
|
428
375
|
// fprintf(stderr, "libcouchbase: couldn't get string value!\n");
|
|
429
376
|
iov->iov_base = NULL;
|
|
430
377
|
iov->iov_len = 0;
|
|
@@ -434,7 +381,7 @@ parse_json_docid(lcb_IOV* iov, lcbjsp_PARSER *parent)
|
|
|
434
381
|
}
|
|
435
382
|
|
|
436
383
|
static void
|
|
437
|
-
miniparse_callback(jsonsl_t jsn, jsonsl_action_t
|
|
384
|
+
miniparse_callback(jsonsl_t jsn, jsonsl_action_t,
|
|
438
385
|
struct jsonsl_state_st *state, const jsonsl_char_t *at)
|
|
439
386
|
{
|
|
440
387
|
miniparse_ctx *ctx = reinterpret_cast<miniparse_ctx*>(jsn->data);
|
|
@@ -496,24 +443,21 @@ miniparse_callback(jsonsl_t jsn, jsonsl_action_t action,
|
|
|
496
443
|
iov->iov_len++;
|
|
497
444
|
}
|
|
498
445
|
}
|
|
499
|
-
(void)at; (void)action;
|
|
500
446
|
}
|
|
501
447
|
|
|
502
|
-
void
|
|
503
|
-
lcbjsp_parse_viewrow(lcbjsp_PARSER *vp, lcbjsp_ROW *vr)
|
|
504
|
-
{
|
|
448
|
+
void Parser::parse_viewrow(Row &vr) {
|
|
505
449
|
miniparse_ctx ctx = { NULL };
|
|
506
|
-
ctx.datum = vr;
|
|
507
|
-
ctx.root = static_cast<const char*>(vr
|
|
508
|
-
ctx.parent =
|
|
450
|
+
ctx.datum = &vr;
|
|
451
|
+
ctx.root = static_cast<const char*>(vr.row.iov_base);
|
|
452
|
+
ctx.parent = this;
|
|
509
453
|
|
|
510
|
-
jsonsl_reset(
|
|
454
|
+
jsonsl_reset(jsn_rdetails);
|
|
511
455
|
|
|
512
|
-
jsonsl_enable_all_callbacks(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
456
|
+
jsonsl_enable_all_callbacks(jsn_rdetails);
|
|
457
|
+
jsn_rdetails->max_callback_level = 3;
|
|
458
|
+
jsn_rdetails->action_callback_POP = miniparse_callback;
|
|
459
|
+
jsn_rdetails->data = &ctx;
|
|
516
460
|
|
|
517
|
-
jsonsl_feed(
|
|
518
|
-
static_cast<const char*>(vr
|
|
461
|
+
jsonsl_feed(jsn_rdetails,
|
|
462
|
+
static_cast<const char*>(vr.row.iov_base), vr.row.iov_len);
|
|
519
463
|
}
|