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.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/.gitignore +2 -0
  3. data/ext/libcouchbase/CMakeLists.txt +5 -7
  4. data/ext/libcouchbase/README.markdown +2 -2
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +49 -0
  6. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  7. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
  8. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +2 -1
  9. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  10. data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
  11. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  12. data/ext/libcouchbase/cmake/source_files.cmake +34 -14
  13. data/ext/libcouchbase/configure.pl +1 -1
  14. data/ext/libcouchbase/contrib/genhash/genhash.h +6 -0
  15. data/ext/libcouchbase/include/libcouchbase/auth.h +10 -0
  16. data/ext/libcouchbase/include/libcouchbase/couchbase.h +10 -0
  17. data/ext/libcouchbase/include/libcouchbase/error.h +7 -0
  18. data/ext/libcouchbase/include/libcouchbase/n1ql.h +13 -1
  19. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  20. data/ext/libcouchbase/include/libcouchbase/subdoc.h +9 -0
  21. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  22. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  23. data/ext/libcouchbase/include/memcached/protocol_binary.h +21 -1132
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  26. data/ext/libcouchbase/src/README.md +0 -2
  27. data/ext/libcouchbase/src/auth-priv.h +1 -0
  28. data/ext/libcouchbase/src/auth.cc +10 -0
  29. data/ext/libcouchbase/src/bootstrap.cc +216 -0
  30. data/ext/libcouchbase/src/bootstrap.h +50 -39
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +455 -0
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +528 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +115 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +407 -386
  37. data/ext/libcouchbase/src/bucketconfig/confmon.cc +378 -0
  38. data/ext/libcouchbase/src/cbft.cc +22 -27
  39. data/ext/libcouchbase/src/cntl.cc +24 -24
  40. data/ext/libcouchbase/src/connspec.cc +30 -1
  41. data/ext/libcouchbase/src/connspec.h +17 -0
  42. data/ext/libcouchbase/src/dns-srv.cc +143 -0
  43. data/ext/libcouchbase/src/{dump.c → dump.cc} +8 -11
  44. data/ext/libcouchbase/src/getconfig.cc +73 -0
  45. data/ext/libcouchbase/src/handler.cc +84 -85
  46. data/ext/libcouchbase/src/hostlist.cc +0 -1
  47. data/ext/libcouchbase/src/hostlist.h +6 -1
  48. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  49. data/ext/libcouchbase/src/http/http.cc +9 -29
  50. data/ext/libcouchbase/src/http/http.h +1 -34
  51. data/ext/libcouchbase/src/http/http_io.cc +22 -26
  52. data/ext/libcouchbase/src/instance.cc +102 -28
  53. data/ext/libcouchbase/src/internal.h +47 -29
  54. data/ext/libcouchbase/src/jsparse/parser.cc +146 -202
  55. data/ext/libcouchbase/src/jsparse/parser.h +91 -98
  56. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  57. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  58. data/ext/libcouchbase/src/lcbio/connect.cc +562 -0
  59. data/ext/libcouchbase/src/lcbio/connect.h +9 -2
  60. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  61. data/ext/libcouchbase/src/lcbio/iotable.h +61 -16
  62. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  63. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  64. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  65. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  66. data/ext/libcouchbase/src/mcserver/mcserver.cc +723 -0
  67. data/ext/libcouchbase/src/mcserver/mcserver.h +160 -70
  68. data/ext/libcouchbase/src/mcserver/negotiate.cc +118 -152
  69. data/ext/libcouchbase/src/mcserver/negotiate.h +85 -74
  70. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  71. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  72. data/ext/libcouchbase/src/n1ql/n1ql.cc +56 -32
  73. data/ext/libcouchbase/src/{newconfig.c → newconfig.cc} +42 -70
  74. data/ext/libcouchbase/src/nodeinfo.cc +4 -8
  75. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  76. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  77. data/ext/libcouchbase/src/operations/{durability-cas.c → durability-cas.cc} +92 -76
  78. data/ext/libcouchbase/src/operations/{durability-seqno.c → durability-seqno.cc} +55 -49
  79. data/ext/libcouchbase/src/operations/durability.cc +643 -0
  80. data/ext/libcouchbase/src/operations/durability_internal.h +212 -124
  81. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  82. data/ext/libcouchbase/src/operations/{observe-seqno.c → observe-seqno.cc} +5 -8
  83. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +69 -94
  84. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  85. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  86. data/ext/libcouchbase/src/operations/{stats.c → stats.cc} +66 -78
  87. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  88. data/ext/libcouchbase/src/operations/subdoc.cc +38 -18
  89. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  90. data/ext/libcouchbase/src/packetutils.h +200 -137
  91. data/ext/libcouchbase/src/probes.d +1 -1
  92. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +3 -4
  93. data/ext/libcouchbase/src/retryq.cc +394 -0
  94. data/ext/libcouchbase/src/retryq.h +116 -104
  95. data/ext/libcouchbase/src/settings.h +2 -1
  96. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  97. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  98. data/ext/libcouchbase/src/trace.h +8 -8
  99. data/ext/libcouchbase/src/vbucket/vbucket.c +0 -1
  100. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  101. data/ext/libcouchbase/src/views/docreq.h +24 -30
  102. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  103. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  104. data/ext/libcouchbase/src/{wait.c → wait.cc} +12 -17
  105. data/ext/libcouchbase/tests/basic/t_connstr.cc +89 -50
  106. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -78
  107. data/ext/libcouchbase/tests/basic/t_packet.cc +35 -42
  108. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  109. data/ext/libcouchbase/tests/iotests/t_confmon.cc +94 -111
  110. data/ext/libcouchbase/tests/iotests/t_sched.cc +1 -2
  111. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  112. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  113. data/lib/libcouchbase/version.rb +1 -1
  114. metadata +36 -39
  115. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  116. data/ext/libcouchbase/src/bootstrap.c +0 -269
  117. data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +0 -495
  118. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  119. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  120. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  121. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  122. data/ext/libcouchbase/src/getconfig.c +0 -100
  123. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  124. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  125. data/ext/libcouchbase/src/mcserver/mcserver.c +0 -784
  126. data/ext/libcouchbase/src/operations/durability.c +0 -668
  127. data/ext/libcouchbase/src/packetutils.c +0 -60
  128. data/ext/libcouchbase/src/retryq.c +0 -424
  129. data/ext/libcouchbase/src/simplestring.c +0 -211
  130. data/ext/libcouchbase/src/simplestring.h +0 -228
  131. data/ext/libcouchbase/src/ssobuf.h +0 -82
  132. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  133. 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
- #define NORMALIZE_OFFSETS(buf, len) buf++; len--;
43
-
44
- #define buffer_append lcb_string_append
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
- static const char *
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 = ctx->current_buf.base + pos - ctx->min_pos;
55
- const char *end = ctx->current_buf.base + ctx->current_buf.nused;
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 (ctx->min_pos > pos) {
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
- static void
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 (ctx->meta_complete) {
81
+ if (meta_complete) {
81
82
  return;
82
83
  }
83
84
 
84
- assert(ctx->header_len <= ctx->meta_buf.nused);
85
+ assert(header_len <= meta_buf.size());
85
86
 
86
87
  /* Adjust the length for the first portion */
87
- ctx->meta_buf.nused = ctx->header_len;
88
+ meta_buf.resize(header_len);
88
89
 
89
90
  /* Append any trailing data */
90
- meta_trailer = get_buffer_region(ctx, ctx->last_row_endpos, -1, &ntrailer);
91
-
92
- buffer_append(&ctx->meta_buf, meta_trailer, ntrailer);
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 lcbjsp_PARSER *
97
- get_ctx(jsonsl_t jsn)
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 action,
104
- struct jsonsl_state_st *state, const jsonsl_char_t *at)
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
- lcbjsp_PARSER *ctx = get_ctx(jsn);
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 action,
119
- struct jsonsl_state_st *state, const jsonsl_char_t *at)
113
+ row_pop_callback(jsonsl_t jsn, jsonsl_action_t,
114
+ struct jsonsl_state_st *state, const jsonsl_char_t *)
120
115
  {
121
- lcbjsp_ROW dt = { LCBJSP_TYPE_ROW };
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
- buffer_append(&ctx->meta_buf, ctx->current_buf.base, jsn->pos);
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(ctx, state->pos_begin, -1, &szdummy);
155
- dt.type = LCBJSP_TYPE_ROW;
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->callback(ctx, &dt);
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 error,
165
- struct jsonsl_state_st *state, jsonsl_char_t *at)
155
+ parse_error_callback(jsonsl_t jsn, jsonsl_error_t,
156
+ struct jsonsl_state_st *, jsonsl_char_t *)
166
157
  {
167
- lcbjsp_PARSER *ctx = get_ctx(jsn);
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
- dt.type = LCBJSP_TYPE_ERROR;
174
- dt.row.iov_base = ctx->current_buf.base;
175
- dt.row.iov_len = ctx->current_buf.nused;
176
- ctx->callback(ctx, &dt);
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 action,
185
- struct jsonsl_state_st *state, const jsonsl_char_t *at)
170
+ trailer_pop_callback(jsonsl_t jsn, jsonsl_action_t,
171
+ struct jsonsl_state_st *state, const jsonsl_char_t *)
186
172
  {
187
- lcbjsp_PARSER *ctx = get_ctx(jsn);
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(ctx);
193
- dt.row.iov_base = ctx->meta_buf.base;
194
- dt.row.iov_len = ctx->meta_buf.nused;
195
- dt.type = LCBJSP_TYPE_COMPLETE;
196
- ctx->callback(ctx, &dt);
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 action,
203
- struct jsonsl_state_st *state, const jsonsl_char_t *at)
185
+ initial_pop_callback(jsonsl_t jsn, jsonsl_action_t,
186
+ struct jsonsl_state_st *state, const jsonsl_char_t *)
204
187
  {
205
- lcbjsp_PARSER *ctx = get_ctx(jsn);
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.base + state->pos_begin;
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 action,
235
- struct jsonsl_state_st *state, const jsonsl_char_t *at)
212
+ initial_push_callback(jsonsl_t jsn, jsonsl_action_t,
213
+ struct jsonsl_state_st *state, const jsonsl_char_t *)
236
214
  {
237
- lcbjsp_PARSER *ctx = (lcbjsp_PARSER*)jsn->data;
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.base, ctx->last_hk.nused,
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
- static void
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 = ctx->current_buf.nused;
282
-
283
- buffer_append(&ctx->current_buf, data, ndata);
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 (ctx->keep_pos > ctx->min_pos) {
288
- size_t lentmp, diff = ctx->keep_pos - ctx->min_pos;
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
- ctx->min_pos = ctx->keep_pos;
263
+ min_pos = keep_pos;
295
264
  }
296
265
 
297
- /* Non-static wrapper */
298
- void
299
- lcbjsp_feed(lcbjsp_PARSER *ctx, const char *data, size_t ndata)
300
- {
301
- feed_data(ctx, data, ndata);
302
- }
303
-
304
- lcbjsp_PARSER*
305
- lcbjsp_create(int mode)
306
- {
307
- lcbjsp_PARSER *ctx;
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
- ctx->jsn_rdetails = jsonsl_new(32);
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
- lcbjsp_reset(ctx);
335
- assert(ctx->jsn_rdetails);
336
- return ctx;
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
- lcbjsp_get_postmortem(const lcbjsp_PARSER *v, lcb_IOV *out)
341
- {
342
- if (v->meta_complete) {
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->iov_base = v->current_buf.base;
347
- out->iov_len = v->current_buf.nused;
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(ctx->jsn);
359
- jsonsl_reset(ctx->jsn_rdetails);
360
-
361
- lcb_string_clear(&ctx->current_buf);
362
- lcb_string_clear(&ctx->meta_buf);
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
- ctx->jsn->action_callback_POP = initial_pop_callback;
368
- ctx->jsn->action_callback_PUSH = initial_push_callback;
369
- ctx->jsn->error_callback = parse_error_callback;
370
- ctx->jsn->max_callback_level = 4;
371
- ctx->jsn->data = ctx;
372
- jsonsl_enable_all_callbacks(ctx->jsn);
373
-
374
- ctx->have_error = 0;
375
- ctx->initialized = 0;
376
- ctx->meta_complete = 0;
377
- ctx->rowcount = 0;
378
- ctx->min_pos = 0;
379
- ctx->keep_pos = 0;
380
- ctx->header_len = 0;
381
- ctx->last_row_endpos = 0;
382
- reinterpret_cast<Json::Value*>(ctx->cxx_data)->clear();
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
- void
386
- lcbjsp_free(lcbjsp_PARSER *ctx)
387
- {
388
- jsonsl_jpr_match_state_cleanup(ctx->jsn);
389
- jsonsl_destroy(ctx->jsn);
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
- lcbjsp_ROW *datum;
405
- lcbjsp_PARSER *parent;
351
+ Row *datum;
352
+ Parser *parent;
406
353
  } miniparse_ctx;
407
354
 
408
355
  static void
409
- parse_json_docid(lcb_IOV* iov, lcbjsp_PARSER *parent)
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 *jvp = reinterpret_cast<Json::Value*>(parent->cxx_data);
415
- bool rv = r.parse(s, s_end, *jvp);
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->isString());
371
+ assert(jvp.isString());
425
372
 
426
373
  // Re-use s and s_end values for the string value itself
427
- if (!jvp->getString(&s, &s_end)) {
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 action,
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->row.iov_base);
508
- ctx.parent = vp;
450
+ ctx.datum = &vr;
451
+ ctx.root = static_cast<const char*>(vr.row.iov_base);
452
+ ctx.parent = this;
509
453
 
510
- jsonsl_reset(vp->jsn_rdetails);
454
+ jsonsl_reset(jsn_rdetails);
511
455
 
512
- jsonsl_enable_all_callbacks(vp->jsn_rdetails);
513
- vp->jsn_rdetails->max_callback_level = 3;
514
- vp->jsn_rdetails->action_callback_POP = miniparse_callback;
515
- vp->jsn_rdetails->data = &ctx;
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(vp->jsn_rdetails,
518
- static_cast<const char*>(vr->row.iov_base), vr->row.iov_len);
461
+ jsonsl_feed(jsn_rdetails,
462
+ static_cast<const char*>(vr.row.iov_base), vr.row.iov_len);
519
463
  }