libcouchbase 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/README.md +1 -1
  4. data/ext/libcouchbase/CMakeLists.txt +8 -6
  5. data/ext/libcouchbase/README.markdown +2 -2
  6. data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
  7. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
  8. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
  9. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
  10. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  11. data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
  12. data/ext/libcouchbase/cmake/defs.mk.in +2 -0
  13. data/ext/libcouchbase/cmake/source_files.cmake +5 -21
  14. data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
  15. data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
  16. data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
  17. data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
  18. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
  19. data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
  20. data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
  21. data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
  22. data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
  23. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  24. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  25. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
  26. data/ext/libcouchbase/src/README.md +2 -0
  27. data/ext/libcouchbase/src/auth-priv.h +0 -1
  28. data/ext/libcouchbase/src/auth.cc +4 -10
  29. data/ext/libcouchbase/src/bootstrap.c +269 -0
  30. data/ext/libcouchbase/src/bootstrap.h +39 -50
  31. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
  32. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  33. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  34. data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
  35. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  36. data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
  37. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  38. data/ext/libcouchbase/src/cbft.cc +27 -22
  39. data/ext/libcouchbase/src/cntl.cc +19 -30
  40. data/ext/libcouchbase/src/connspec.cc +1 -48
  41. data/ext/libcouchbase/src/connspec.h +0 -27
  42. data/ext/libcouchbase/src/dump.cc +2 -2
  43. data/ext/libcouchbase/src/getconfig.cc +33 -7
  44. data/ext/libcouchbase/src/handler.cc +2 -0
  45. data/ext/libcouchbase/src/hostlist.cc +36 -0
  46. data/ext/libcouchbase/src/hostlist.h +62 -41
  47. data/ext/libcouchbase/src/http/http-priv.h +112 -125
  48. data/ext/libcouchbase/src/http/http.cc +30 -15
  49. data/ext/libcouchbase/src/http/http.h +34 -1
  50. data/ext/libcouchbase/src/http/http_io.cc +26 -22
  51. data/ext/libcouchbase/src/instance.cc +23 -94
  52. data/ext/libcouchbase/src/internal.h +26 -52
  53. data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
  54. data/ext/libcouchbase/src/jsparse/parser.h +98 -91
  55. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  56. data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
  57. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  58. data/ext/libcouchbase/src/lcbio/connect.h +2 -9
  59. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  60. data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
  61. data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
  62. data/ext/libcouchbase/src/lcbio/manager.c +2 -2
  63. data/ext/libcouchbase/src/mc/mcreq.h +2 -9
  64. data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
  65. data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
  66. data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
  67. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
  68. data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
  69. data/ext/libcouchbase/src/newconfig.cc +6 -6
  70. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  71. data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
  72. data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
  73. data/ext/libcouchbase/src/operations/durability.cc +26 -6
  74. data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
  75. data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
  76. data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
  77. data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
  78. data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
  79. data/ext/libcouchbase/src/operations/stats.cc +8 -3
  80. data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
  81. data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
  82. data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
  83. data/ext/libcouchbase/src/packetutils.c +37 -0
  84. data/ext/libcouchbase/src/packetutils.h +2 -2
  85. data/ext/libcouchbase/src/probes.d +1 -1
  86. data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
  87. data/ext/libcouchbase/src/retryq.cc +4 -4
  88. data/ext/libcouchbase/src/settings.c +0 -3
  89. data/ext/libcouchbase/src/settings.h +0 -5
  90. data/ext/libcouchbase/src/simplestring.c +211 -0
  91. data/ext/libcouchbase/src/simplestring.h +228 -0
  92. data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
  93. data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
  94. data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
  95. data/ext/libcouchbase/src/ssobuf.h +82 -0
  96. data/ext/libcouchbase/src/trace.h +4 -4
  97. data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
  98. data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
  99. data/ext/libcouchbase/src/views/docreq.h +30 -24
  100. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  101. data/ext/libcouchbase/src/views/viewreq.h +13 -43
  102. data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
  103. data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
  104. data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
  105. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  106. data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
  107. data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
  108. data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
  109. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  110. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
  111. data/lib/libcouchbase/ext/tasks.rb +6 -2
  112. data/lib/libcouchbase/query_view.rb +1 -1
  113. data/lib/libcouchbase/results_fiber.rb +6 -6
  114. data/lib/libcouchbase/version.rb +1 -1
  115. metadata +26 -26
  116. data/ext/libcouchbase/src/bootstrap.cc +0 -216
  117. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
  118. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
  119. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
  120. data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
  121. data/ext/libcouchbase/src/dns-srv.cc +0 -142
  122. data/ext/libcouchbase/src/errmap.cc +0 -107
  123. data/ext/libcouchbase/src/errmap.h +0 -113
  124. data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
  125. data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
  126. data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
  127. data/ext/libcouchbase/src/mctx-helper.h +0 -51
  128. data/ext/libcouchbase/src/views/viewreq.cc +0 -318
  129. data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -1,87 +0,0 @@
1
- /*
2
- * Copyright 2016 Couchbase, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- #ifndef LCBIO_TIMER_CXX
18
- #define LCBIO_TIMER_CXX
19
-
20
- #include <lcbio/timer-ng.h>
21
- #include <cstdlib>
22
-
23
- namespace lcb {
24
- namespace io {
25
-
26
- class SimpleTimer {
27
- public:
28
- typedef void (Callback)(void*);
29
- SimpleTimer(lcbio_pTABLE iot, void *data, Callback cb)
30
- : inner(lcbio_timer_new(iot, data, cb)) {
31
- }
32
- ~SimpleTimer() {
33
- release();
34
- }
35
- void release() {
36
- if (inner != NULL) {
37
- lcbio_timer_destroy(inner);
38
- inner = NULL;
39
- }
40
- }
41
- void signal() {
42
- lcbio_async_signal(inner);
43
- }
44
- void cancel() {
45
- lcbio_timer_disarm(inner);
46
- }
47
- bool is_armed() const {
48
- return lcbio_timer_armed(inner);
49
- }
50
- void rearm(uint32_t usec) {
51
- lcbio_timer_rearm(inner, usec);
52
- }
53
- void arm_if_disarmed(uint32_t usec) {
54
- if (!is_armed()) {
55
- rearm(usec);
56
- }
57
- }
58
- void dump(FILE *fp) const {
59
- lcbio_timer_dump(inner, fp);
60
- }
61
- private:
62
- lcbio_pTIMER inner;
63
- SimpleTimer(const SimpleTimer&);
64
- };
65
-
66
- template <typename T, void (T::*M)(void)>
67
- class Timer : public SimpleTimer {
68
- public:
69
- Timer(lcbio_pTABLE iot, T* ptr)
70
- : SimpleTimer(iot, ptr, cb) {
71
- }
72
-
73
- ~Timer() {
74
- release();
75
- }
76
-
77
- private:
78
- static void cb(void *arg) {
79
- T *obj = reinterpret_cast<T*>(arg);
80
- (obj->*M)();
81
- }
82
- Timer(const Timer&);
83
- };
84
-
85
- }
86
- }
87
- #endif
@@ -1,51 +0,0 @@
1
- /*
2
- * Copyright 2016 Couchbase, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- #ifndef LCB_MCTX_HELPER_H
18
- #define LCB_MCTX_HELPER_H
19
- #include <libcouchbase/couchbase.h>
20
-
21
- namespace lcb {
22
-
23
- class MultiCmdContext : public lcb_MULTICMD_CTX {
24
- protected:
25
- virtual lcb_error_t MCTX_addcmd(const lcb_CMDBASE* cmd) = 0;
26
- virtual lcb_error_t MCTX_done(const void *cookie) = 0;
27
- virtual void MCTX_fail() = 0;
28
-
29
- MultiCmdContext() {
30
- lcb_MULTICMD_CTX::addcmd = dispatch_mctx_addcmd;
31
- lcb_MULTICMD_CTX::done = dispatch_mctx_done;
32
- lcb_MULTICMD_CTX::fail = dispatch_mctx_fail;
33
- }
34
-
35
- virtual ~MultiCmdContext() {}
36
-
37
- private:
38
- static lcb_error_t dispatch_mctx_addcmd(lcb_MULTICMD_CTX* ctx, const lcb_CMDBASE * cmd) {
39
- return static_cast<MultiCmdContext*>(ctx)->MCTX_addcmd(cmd);
40
- }
41
- static lcb_error_t dispatch_mctx_done(lcb_MULTICMD_CTX* ctx, const void *cookie) {
42
- return static_cast<MultiCmdContext*>(ctx)->MCTX_done(cookie);
43
- }
44
- static void dispatch_mctx_fail(lcb_MULTICMD_CTX* ctx) {
45
- static_cast<MultiCmdContext*>(ctx)->MCTX_fail();
46
- }
47
- };
48
-
49
- }
50
-
51
- #endif
@@ -1,318 +0,0 @@
1
- #include "viewreq.h"
2
- #include "sllist-inl.h"
3
- #include "http/http.h"
4
- #include "internal.h"
5
-
6
- #define MAX_GET_URI_LENGTH 2048
7
- using namespace lcb::views;
8
-
9
- static void chunk_callback(lcb_t, int, const lcb_RESPBASE*);
10
-
11
- template <typename value_type, typename size_type>
12
- void IOV2PTRLEN(const lcb_IOV* iov, value_type*& ptr, size_type& len) {
13
- ptr = reinterpret_cast<const value_type*>(iov->iov_base);
14
- len = iov->iov_len;
15
- }
16
-
17
- /* Whether the request (from the user side) is still ongoing */
18
- #define CAN_CONTINUE(req) ((req)->callback != NULL)
19
- #define LOGARGS(instance, lvl) instance->settings, "views", LCB_LOG_##lvl, __FILE__, __LINE__
20
-
21
- void ViewRequest::invoke_last(lcb_error_t err) {
22
- lcb_RESPVIEWQUERY resp = { 0 };
23
- if (callback == NULL) {
24
- return;
25
- }
26
- if (docq && docq->has_pending()) {
27
- return;
28
- }
29
-
30
- resp.rc = err;
31
- resp.htresp = cur_htresp;
32
- resp.cookie = const_cast<void*>(cookie);
33
- resp.rflags = LCB_RESP_F_FINAL;
34
- if (parser && parser->meta_complete) {
35
- resp.value = parser->meta_buf.c_str();
36
- resp.nvalue = parser->meta_buf.size();
37
- } else {
38
- resp.rflags |= LCB_RESP_F_CLIENTGEN;
39
- }
40
- callback(instance, LCB_CALLBACK_VIEWQUERY, &resp);
41
- cancel();
42
- }
43
-
44
- void ViewRequest::invoke_row(lcb_RESPVIEWQUERY *resp) {
45
- if (callback == NULL) {
46
- return;
47
- }
48
- resp->htresp = cur_htresp;
49
- resp->cookie = const_cast<void*>(cookie);
50
- callback(instance, LCB_CALLBACK_VIEWQUERY, resp);
51
- }
52
-
53
- static void
54
- chunk_callback(lcb_t instance, int, const lcb_RESPBASE *rb)
55
- {
56
- const lcb_RESPHTTP *rh = (const lcb_RESPHTTP *)rb;
57
- ViewRequest *req = reinterpret_cast<ViewRequest*>(rh->cookie);
58
-
59
- req->cur_htresp = rh;
60
-
61
- if (rh->rc != LCB_SUCCESS || rh->htstatus != 200 || (rh->rflags & LCB_RESP_F_FINAL)) {
62
- if (req->lasterr == LCB_SUCCESS && rh->htstatus != 200) {
63
- if (rh->rc != LCB_SUCCESS) {
64
- req->lasterr = rh->rc;
65
- } else {
66
- lcb_log(LOGARGS(instance, DEBUG), "Got not ok http status %d", rh->htstatus);
67
- req->lasterr = LCB_HTTP_ERROR;
68
- }
69
- }
70
- req->ref();
71
- req->invoke_last();
72
- if (rh->rflags & LCB_RESP_F_FINAL) {
73
- req->htreq = NULL;
74
- req->unref();
75
- }
76
- req->cur_htresp = NULL;
77
- req->unref();
78
- return;
79
- }
80
-
81
- if (!CAN_CONTINUE(req)) {
82
- return;
83
- }
84
-
85
- req->refcount++;
86
- req->parser->feed(reinterpret_cast<const char*>(rh->body), rh->nbody);
87
- req->cur_htresp = NULL;
88
- req->unref();
89
- }
90
-
91
- static void
92
- do_copy_iov(std::string& dstbuf, lcb_IOV *dstiov, const lcb_IOV *srciov)
93
- {
94
- dstiov->iov_len = srciov->iov_len;
95
- dstiov->iov_base = const_cast<char*>(dstbuf.c_str() + dstbuf.size());
96
- dstbuf.append(reinterpret_cast<const char*>(srciov->iov_base), srciov->iov_len);
97
- }
98
-
99
- static VRDocRequest *
100
- mk_docreq(const lcb::jsparse::Row *datum)
101
- {
102
- size_t extra_alloc = 0;
103
- VRDocRequest *dreq;
104
- extra_alloc =
105
- datum->key.iov_len + datum->value.iov_len +
106
- datum->geo.iov_len + datum->docid.iov_len;
107
-
108
- dreq = new VRDocRequest();
109
- dreq->rowbuf.reserve(extra_alloc);
110
- do_copy_iov(dreq->rowbuf, &dreq->key, &datum->key);
111
- do_copy_iov(dreq->rowbuf, &dreq->value, &datum->value);
112
- do_copy_iov(dreq->rowbuf, &dreq->docid, &datum->docid);
113
- do_copy_iov(dreq->rowbuf, &dreq->geo, &datum->geo);
114
- return dreq;
115
- }
116
-
117
- void ViewRequest::JSPARSE_on_row(const lcb::jsparse::Row& datum) {
118
- using lcb::jsparse::Row;
119
- if (!is_no_rowparse()) {
120
- parser->parse_viewrow(const_cast<Row&>(datum));
121
- }
122
-
123
- if (is_include_docs() && datum.docid.iov_len && callback) {
124
- VRDocRequest *dreq = mk_docreq(&datum);
125
- dreq->parent = this;
126
- docq->add(dreq);
127
- ref();
128
-
129
- } else {
130
- lcb_RESPVIEWQUERY resp = { 0 };
131
- if (is_no_rowparse()) {
132
- IOV2PTRLEN(&datum.row, resp.value, resp.nvalue);
133
- } else {
134
- IOV2PTRLEN(&datum.key, resp.key, resp.nkey);
135
- IOV2PTRLEN(&datum.docid, resp.docid, resp.ndocid);
136
- IOV2PTRLEN(&datum.value, resp.value, resp.nvalue);
137
- IOV2PTRLEN(&datum.geo, resp.geometry, resp.ngeometry);
138
- }
139
- resp.htresp = cur_htresp;
140
- invoke_row(&resp);
141
- }
142
- }
143
-
144
- void ViewRequest::JSPARSE_on_error(const std::string&) {
145
- invoke_last(LCB_PROTOCOL_ERROR);
146
- }
147
-
148
- void ViewRequest::JSPARSE_on_complete(const std::string&) {
149
- // Nothing
150
- }
151
-
152
- static void
153
- cb_doc_ready(lcb::docreq::Queue *q, lcb::docreq::DocRequest *req_base)
154
- {
155
- lcb_RESPVIEWQUERY resp = { 0 };
156
- VRDocRequest *dreq = (VRDocRequest*)req_base;
157
- resp.docresp = &dreq->docresp;
158
- IOV2PTRLEN(&dreq->key, resp.key, resp.nkey);
159
- IOV2PTRLEN(&dreq->value, resp.value, resp.nvalue);
160
- IOV2PTRLEN(&dreq->docid, resp.docid, resp.ndocid);
161
- IOV2PTRLEN(&dreq->geo, resp.geometry, resp.ngeometry);
162
-
163
- if (q->parent) {
164
- reinterpret_cast<ViewRequest*>(q->parent)->invoke_row(&resp);
165
- }
166
-
167
- delete dreq;
168
-
169
- if (q->parent) {
170
- reinterpret_cast<ViewRequest*>(q->parent)->unref();
171
- }
172
- }
173
-
174
- static void
175
- cb_docq_throttle(lcb::docreq::Queue *q, int enabled)
176
- {
177
- ViewRequest *req = reinterpret_cast<ViewRequest*>(q->parent);
178
- if (req == NULL || req->htreq == NULL) {
179
- return;
180
- }
181
- if (enabled) {
182
- req->htreq->pause();
183
- } else {
184
- req->htreq->resume();
185
- }
186
- }
187
-
188
- ViewRequest::~ViewRequest() {
189
- invoke_last();
190
-
191
- if (parser != NULL) {
192
- delete parser;
193
- }
194
- if (htreq != NULL) {
195
- lcb_cancel_http_request(instance, htreq);
196
- }
197
- if (docq != NULL) {
198
- docq->parent = NULL;
199
- docq->unref();
200
- }
201
- }
202
-
203
- lcb_error_t ViewRequest::request_http(const lcb_CMDVIEWQUERY *cmd) {
204
- lcb_CMDHTTP htcmd = { 0 };
205
- htcmd.method = LCB_HTTP_METHOD_GET;
206
- htcmd.type = LCB_HTTP_TYPE_VIEW;
207
- htcmd.cmdflags = LCB_CMDHTTP_F_STREAM;
208
-
209
- std::string path;
210
- path.append("_design/");
211
- path.append(cmd->ddoc, cmd->nddoc);
212
- path.append(is_spatial() ? "/_spatial/" : "/_view/");
213
- path.append(cmd->view, cmd->nview);
214
- if (cmd->noptstr) {
215
- path.append("?").append(cmd->optstr, cmd->noptstr);
216
- }
217
-
218
- if (cmd->npostdata) {
219
- htcmd.method = LCB_HTTP_METHOD_POST;
220
- htcmd.body = cmd->postdata;
221
- htcmd.nbody = cmd->npostdata;
222
- htcmd.content_type = "application/json";
223
- }
224
-
225
- LCB_CMD_SET_KEY(&htcmd, path.c_str(), path.size());
226
- htcmd.reqhandle = &htreq;
227
-
228
- lcb_error_t err = lcb_http3(instance, this, &htcmd);
229
- if (err == LCB_SUCCESS) {
230
- htreq->set_callback(chunk_callback);
231
- }
232
- return err;
233
- }
234
-
235
- ViewRequest::ViewRequest(lcb_t instance_, const void *cookie_,
236
- const lcb_CMDVIEWQUERY* cmd)
237
- : cur_htresp(NULL), htreq(NULL),
238
- parser(new lcb::jsparse::Parser(lcb::jsparse::Parser::MODE_VIEWS, this)),
239
- cookie(cookie_), docq(NULL), callback(cmd->callback),
240
- instance(instance_), refcount(1),
241
- cmdflags(cmd->cmdflags),
242
- lasterr(LCB_SUCCESS) {
243
-
244
- // Validate:
245
- if (cmd->nddoc == 0 || cmd->nview == 0 || callback == NULL) {
246
- lasterr = LCB_EINVAL;
247
- } else if (is_include_docs() && is_no_rowparse()) {
248
- lasterr = LCB_OPTIONS_CONFLICT;
249
- } else if (cmd->noptstr > MAX_GET_URI_LENGTH) {
250
- lasterr = LCB_E2BIG;
251
- }
252
- if (lasterr != LCB_SUCCESS) {
253
- return;
254
- }
255
-
256
- if (is_include_docs()) {
257
- docq = new lcb::docreq::Queue(instance);
258
- docq->parent = this;
259
- docq->cb_ready = cb_doc_ready;
260
- docq->cb_throttle = cb_docq_throttle;
261
- if (cmd->docs_concurrent_max) {
262
- docq->max_pending_response = cmd->docs_concurrent_max;
263
- }
264
- }
265
-
266
- if (cmd->handle) {
267
- *cmd->handle = this;
268
- }
269
-
270
- lcb_aspend_add(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
271
-
272
- lasterr = request_http(cmd);
273
- }
274
-
275
- LIBCOUCHBASE_API
276
- lcb_error_t
277
- lcb_view_query(lcb_t instance, const void *cookie, const lcb_CMDVIEWQUERY *cmd)
278
- {
279
- ViewRequest *req = new ViewRequest(instance, cookie, cmd);
280
- lcb_error_t err = req->lasterr;
281
- if (err != LCB_SUCCESS) {
282
- req->cancel();
283
- delete req;
284
- }
285
- return err;
286
- }
287
-
288
- LIBCOUCHBASE_API
289
- void
290
- lcb_view_query_initcmd(lcb_CMDVIEWQUERY *vq,
291
- const char *design, const char *view, const char *options,
292
- lcb_VIEWQUERYCALLBACK callback)
293
- {
294
- vq->view = view;
295
- vq->nview = strlen(view);
296
- vq->ddoc = design;
297
- vq->nddoc = strlen(design);
298
- if (options != NULL) {
299
- vq->optstr = options;
300
- vq->noptstr = strlen(options);
301
- }
302
- vq->callback = callback;
303
- }
304
-
305
- LIBCOUCHBASE_API
306
- void lcb_view_cancel(lcb_t, lcb_VIEWHANDLE handle) {
307
- handle->cancel();
308
- }
309
-
310
- void ViewRequest::cancel() {
311
- if (callback) {
312
- callback = NULL;
313
- lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
314
- if (docq) {
315
- docq->cancel();
316
- }
317
- }
318
- }