libcouchbase 0.2.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/ext/libcouchbase/CMakeLists.txt +8 -6
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +0 -86
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +0 -11
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +0 -2
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -2
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +0 -2
- data/ext/libcouchbase/cmake/defs.mk.in +2 -0
- data/ext/libcouchbase/cmake/source_files.cmake +5 -21
- data/ext/libcouchbase/include/libcouchbase/auth.h +0 -10
- data/ext/libcouchbase/include/libcouchbase/cntl.h +1 -27
- data/ext/libcouchbase/include/libcouchbase/error.h +1 -15
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +1 -13
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +1 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +0 -9
- data/ext/libcouchbase/include/libcouchbase/views.h +1 -7
- data/ext/libcouchbase/include/libcouchbase/visibility.h +0 -1
- data/ext/libcouchbase/include/memcached/protocol_binary.h +1131 -29
- data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +2 -3
- data/ext/libcouchbase/src/README.md +2 -0
- data/ext/libcouchbase/src/auth-priv.h +0 -1
- data/ext/libcouchbase/src/auth.cc +4 -10
- data/ext/libcouchbase/src/bootstrap.c +269 -0
- data/ext/libcouchbase/src/bootstrap.h +39 -50
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +117 -84
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +25 -50
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +386 -407
- data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
- data/ext/libcouchbase/src/cbft.cc +27 -22
- data/ext/libcouchbase/src/cntl.cc +19 -30
- data/ext/libcouchbase/src/connspec.cc +1 -48
- data/ext/libcouchbase/src/connspec.h +0 -27
- data/ext/libcouchbase/src/dump.cc +2 -2
- data/ext/libcouchbase/src/getconfig.cc +33 -7
- data/ext/libcouchbase/src/handler.cc +2 -0
- data/ext/libcouchbase/src/hostlist.cc +36 -0
- data/ext/libcouchbase/src/hostlist.h +62 -41
- data/ext/libcouchbase/src/http/http-priv.h +112 -125
- data/ext/libcouchbase/src/http/http.cc +30 -15
- data/ext/libcouchbase/src/http/http.h +34 -1
- data/ext/libcouchbase/src/http/http_io.cc +26 -22
- data/ext/libcouchbase/src/instance.cc +23 -94
- data/ext/libcouchbase/src/internal.h +26 -52
- data/ext/libcouchbase/src/jsparse/parser.cc +202 -146
- data/ext/libcouchbase/src/jsparse/parser.h +98 -91
- data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +163 -174
- data/ext/libcouchbase/src/lcbio/connect.c +557 -0
- data/ext/libcouchbase/src/lcbio/connect.h +2 -9
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +16 -61
- data/ext/libcouchbase/src/lcbio/ioutils.h +1 -1
- data/ext/libcouchbase/src/lcbio/manager.c +2 -2
- data/ext/libcouchbase/src/mc/mcreq.h +2 -9
- data/ext/libcouchbase/src/mcserver/mcserver.cc +34 -143
- data/ext/libcouchbase/src/mcserver/mcserver.h +12 -7
- data/ext/libcouchbase/src/mcserver/negotiate.cc +38 -132
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
- data/ext/libcouchbase/src/n1ql/n1ql.cc +32 -56
- data/ext/libcouchbase/src/newconfig.cc +6 -6
- data/ext/libcouchbase/src/nodeinfo.cc +2 -2
- data/ext/libcouchbase/src/operations/{cbflush.cc → cbflush.c} +15 -7
- data/ext/libcouchbase/src/operations/{counter.cc → counter.c} +0 -0
- data/ext/libcouchbase/src/operations/durability.cc +26 -6
- data/ext/libcouchbase/src/operations/durability_internal.h +3 -6
- data/ext/libcouchbase/src/operations/{get.cc → get.c} +26 -24
- data/ext/libcouchbase/src/operations/{observe.cc → observe.c} +93 -68
- data/ext/libcouchbase/src/operations/{pktfwd.cc → pktfwd.c} +0 -0
- data/ext/libcouchbase/src/operations/{remove.cc → remove.c} +0 -0
- data/ext/libcouchbase/src/operations/stats.cc +8 -3
- data/ext/libcouchbase/src/operations/{store.cc → store.c} +32 -27
- data/ext/libcouchbase/src/operations/subdoc.cc +18 -38
- data/ext/libcouchbase/src/operations/{touch.cc → touch.c} +0 -0
- data/ext/libcouchbase/src/packetutils.c +37 -0
- data/ext/libcouchbase/src/packetutils.h +2 -2
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/{retrychk.cc → retrychk.c} +3 -2
- data/ext/libcouchbase/src/retryq.cc +4 -4
- data/ext/libcouchbase/src/settings.c +0 -3
- data/ext/libcouchbase/src/settings.h +0 -5
- data/ext/libcouchbase/src/simplestring.c +211 -0
- data/ext/libcouchbase/src/simplestring.h +228 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +0 -1
- data/ext/libcouchbase/src/ssl/ssl_common.c +0 -2
- data/ext/libcouchbase/src/ssl/ssl_e.c +1 -0
- data/ext/libcouchbase/src/ssobuf.h +82 -0
- data/ext/libcouchbase/src/trace.h +4 -4
- data/ext/libcouchbase/src/vbucket/vbucket.c +1 -0
- data/ext/libcouchbase/src/views/{docreq.cc → docreq.c} +54 -48
- data/ext/libcouchbase/src/views/docreq.h +30 -24
- data/ext/libcouchbase/src/views/viewreq.c +358 -0
- data/ext/libcouchbase/src/views/viewreq.h +13 -43
- data/ext/libcouchbase/tests/basic/t_connstr.cc +50 -89
- data/ext/libcouchbase/tests/basic/t_host.cc +75 -67
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +78 -27
- data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
- data/ext/libcouchbase/tests/htparse/t_basic.cc +78 -58
- data/ext/libcouchbase/tests/iotests/mock-environment.h +1 -2
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +114 -96
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +1 -1
- data/lib/libcouchbase/ext/tasks.rb +6 -2
- data/lib/libcouchbase/query_view.rb +1 -1
- data/lib/libcouchbase/results_fiber.rb +6 -6
- data/lib/libcouchbase/version.rb +1 -1
- metadata +26 -26
- data/ext/libcouchbase/src/bootstrap.cc +0 -216
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +0 -281
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +0 -528
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.cc +0 -115
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +0 -378
- data/ext/libcouchbase/src/dns-srv.cc +0 -142
- data/ext/libcouchbase/src/errmap.cc +0 -107
- data/ext/libcouchbase/src/errmap.h +0 -113
- data/ext/libcouchbase/src/lcbht/lcbht.cc +0 -177
- data/ext/libcouchbase/src/lcbio/connect.cc +0 -562
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +0 -87
- data/ext/libcouchbase/src/mctx-helper.h +0 -51
- data/ext/libcouchbase/src/views/viewreq.cc +0 -318
- data/ext/libcouchbase/tests/iotests/t_errmap.cc +0 -97
@@ -10,23 +10,14 @@
|
|
10
10
|
#include <lcbio/lcbio.h>
|
11
11
|
#include "sllist.h"
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
struct
|
18
|
-
|
19
|
-
struct Queue {
|
20
|
-
Queue(lcb_t);
|
21
|
-
~Queue();
|
22
|
-
void add(DocRequest*);
|
23
|
-
void unref();
|
24
|
-
void ref() {refcount++;}
|
25
|
-
void cancel();
|
26
|
-
bool has_pending() const {
|
27
|
-
return n_awaiting_response || n_awaiting_schedule;
|
28
|
-
}
|
13
|
+
#ifdef __cplusplus
|
14
|
+
extern "C" {
|
15
|
+
#endif
|
16
|
+
|
17
|
+
struct lcb_DOCQUEUE_st;
|
18
|
+
struct lcb_DOCREQ_st;
|
29
19
|
|
20
|
+
typedef struct lcb_DOCQUEUE_st{
|
30
21
|
lcb_t instance;
|
31
22
|
void *parent;
|
32
23
|
lcbio_pTIMER timer;
|
@@ -34,13 +25,13 @@ struct Queue {
|
|
34
25
|
/**Called when a document is ready
|
35
26
|
* @param The queue
|
36
27
|
* @param The document */
|
37
|
-
void (*cb_ready)(struct
|
28
|
+
void (*cb_ready)(struct lcb_DOCQUEUE_st*,struct lcb_DOCREQ_st*);
|
38
29
|
|
39
30
|
/**Called when throttle state changes. This may be used by higher layers
|
40
31
|
* for appropriate flow control
|
41
32
|
* @param The queue
|
42
33
|
* @param enabled Whether throttling has been enabled or disabled */
|
43
|
-
void (*cb_throttle)(struct
|
34
|
+
void (*cb_throttle)(struct lcb_DOCQUEUE_st*, int enabled);
|
44
35
|
|
45
36
|
/**This queue holds requests which were not yet issued to the library
|
46
37
|
* via lcb_get3(). This list is aggregated after each chunk callback and
|
@@ -58,20 +49,35 @@ struct Queue {
|
|
58
49
|
unsigned min_batch_size;
|
59
50
|
unsigned cancelled;
|
60
51
|
unsigned refcount;
|
61
|
-
};
|
52
|
+
} lcb_DOCQUEUE;
|
62
53
|
|
63
|
-
struct
|
54
|
+
typedef struct lcb_DOCREQ_st {
|
64
55
|
/* Callback. Must be first */
|
65
56
|
lcb_RESPCALLBACK callback;
|
66
57
|
sllist_node slnode;
|
67
|
-
|
58
|
+
lcb_DOCQUEUE *parent;
|
68
59
|
lcb_RESPGET docresp;
|
69
60
|
/* To be filled in by the subclass */
|
70
61
|
lcb_IOV docid;
|
71
62
|
unsigned ready;
|
72
|
-
};
|
63
|
+
} lcb_DOCQREQ;
|
64
|
+
|
65
|
+
lcb_DOCQUEUE *
|
66
|
+
lcbdocq_create(lcb_t instance);
|
67
|
+
|
68
|
+
void
|
69
|
+
lcbdocq_add(lcb_DOCQUEUE *q, lcb_DOCQREQ *req);
|
73
70
|
|
71
|
+
void
|
72
|
+
lcbdocq_unref(lcb_DOCQUEUE *);
|
74
73
|
|
75
|
-
|
76
|
-
|
74
|
+
void
|
75
|
+
lcbdocq_cancel(lcb_DOCQUEUE *q);
|
76
|
+
|
77
|
+
#define lcbdocq_has_pending(q) \
|
78
|
+
((q)->n_awaiting_response || (q)->n_awaiting_schedule)
|
79
|
+
|
80
|
+
#ifdef __cplusplus
|
81
|
+
}
|
82
|
+
#endif
|
77
83
|
#endif
|
@@ -0,0 +1,358 @@
|
|
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
|
+
|
8
|
+
static void chunk_callback(lcb_t, int, const lcb_RESPBASE*);
|
9
|
+
static void row_callback(lcbjsp_PARSER*, const lcbjsp_ROW*);
|
10
|
+
static void invoke_row(lcbview_REQUEST *req, lcb_RESPVIEWQUERY *resp);
|
11
|
+
static void unref_request(lcbview_REQUEST *req);
|
12
|
+
|
13
|
+
#define IOV2PTRLEN(iov, ptr, len) do { \
|
14
|
+
ptr = (iov)->iov_base; \
|
15
|
+
len = (iov)->iov_len; \
|
16
|
+
} while (0);
|
17
|
+
|
18
|
+
/* Whether the request (from the user side) is still ongoing */
|
19
|
+
#define CAN_CONTINUE(req) ((req)->callback != NULL)
|
20
|
+
#define LOGARGS(instance, lvl) instance->settings, "views", LCB_LOG_##lvl, __FILE__, __LINE__
|
21
|
+
|
22
|
+
static void
|
23
|
+
invoke_last(lcbview_REQUEST *req, lcb_error_t err)
|
24
|
+
{
|
25
|
+
lcb_RESPVIEWQUERY resp = { 0 };
|
26
|
+
if (req->callback == NULL) {
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
if (req->docq && lcbdocq_has_pending(req->docq)) {
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
|
33
|
+
resp.rc = err;
|
34
|
+
resp.htresp = req->cur_htresp;
|
35
|
+
resp.cookie = (void *)req->cookie;
|
36
|
+
resp.rflags = LCB_RESP_F_FINAL;
|
37
|
+
if (req->parser && req->parser->meta_complete) {
|
38
|
+
resp.value = req->parser->meta_buf.base;
|
39
|
+
resp.nvalue = req->parser->meta_buf.nused;
|
40
|
+
} else {
|
41
|
+
resp.rflags |= LCB_RESP_F_CLIENTGEN;
|
42
|
+
}
|
43
|
+
req->callback(req->instance, LCB_CALLBACK_VIEWQUERY, &resp);
|
44
|
+
lcb_view_cancel(req->instance, req);
|
45
|
+
}
|
46
|
+
|
47
|
+
static void
|
48
|
+
invoke_row(lcbview_REQUEST *req, lcb_RESPVIEWQUERY *resp)
|
49
|
+
{
|
50
|
+
if (req->callback == NULL) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
resp->htresp = req->cur_htresp;
|
54
|
+
resp->cookie = (void *)req->cookie;
|
55
|
+
req->callback(req->instance, LCB_CALLBACK_VIEWQUERY, resp);
|
56
|
+
}
|
57
|
+
|
58
|
+
static void
|
59
|
+
chunk_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
|
60
|
+
{
|
61
|
+
const lcb_RESPHTTP *rh = (const lcb_RESPHTTP *)rb;
|
62
|
+
lcbview_REQUEST *req = rh->cookie;
|
63
|
+
|
64
|
+
(void)cbtype;
|
65
|
+
req->cur_htresp = rh;
|
66
|
+
|
67
|
+
if (rh->rc != LCB_SUCCESS || rh->htstatus != 200 || (rh->rflags & LCB_RESP_F_FINAL)) {
|
68
|
+
if (req->lasterr == LCB_SUCCESS && rh->htstatus != 200) {
|
69
|
+
if (rh->rc != LCB_SUCCESS) {
|
70
|
+
req->lasterr = rh->rc;
|
71
|
+
} else {
|
72
|
+
lcb_log(LOGARGS(instance, DEBUG), "Got not ok http status %d", rh->htstatus);
|
73
|
+
req->lasterr = LCB_HTTP_ERROR;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
req->refcount++;
|
77
|
+
invoke_last(req, req->lasterr);
|
78
|
+
if (rh->rflags & LCB_RESP_F_FINAL) {
|
79
|
+
req->htreq = NULL;
|
80
|
+
unref_request(req);
|
81
|
+
}
|
82
|
+
req->cur_htresp = NULL;
|
83
|
+
unref_request(req);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
|
87
|
+
if (!CAN_CONTINUE(req)) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
req->refcount++;
|
92
|
+
lcbjsp_feed(req->parser, rh->body, rh->nbody);
|
93
|
+
req->cur_htresp = NULL;
|
94
|
+
unref_request(req);
|
95
|
+
(void)instance;
|
96
|
+
}
|
97
|
+
|
98
|
+
static void
|
99
|
+
do_copy_iov(char *dstbuf, lcb_IOV *dstiov, const lcb_IOV *srciov, size_t *off)
|
100
|
+
{
|
101
|
+
dstiov->iov_len = srciov->iov_len;
|
102
|
+
dstiov->iov_base = dstbuf + *off;
|
103
|
+
*off += dstiov->iov_len;
|
104
|
+
memcpy(dstiov->iov_base, srciov->iov_base, srciov->iov_len);
|
105
|
+
}
|
106
|
+
|
107
|
+
static lcbview_DOCREQ *
|
108
|
+
mk_docreq(const lcbjsp_ROW *datum)
|
109
|
+
{
|
110
|
+
size_t extra_alloc = 0;
|
111
|
+
size_t cur_offset = 0;
|
112
|
+
lcbview_DOCREQ *dreq;
|
113
|
+
|
114
|
+
extra_alloc =
|
115
|
+
datum->key.iov_len + datum->value.iov_len +
|
116
|
+
datum->geo.iov_len + datum->docid.iov_len;
|
117
|
+
|
118
|
+
dreq = calloc(1, sizeof(*dreq) + extra_alloc);
|
119
|
+
do_copy_iov(dreq->rowbuf, &dreq->key, &datum->key, &cur_offset);
|
120
|
+
do_copy_iov(dreq->rowbuf, &dreq->value, &datum->value, &cur_offset);
|
121
|
+
do_copy_iov(dreq->rowbuf, &dreq->base.docid, &datum->docid, &cur_offset);
|
122
|
+
do_copy_iov(dreq->rowbuf, &dreq->geo, &datum->geo, &cur_offset);
|
123
|
+
return dreq;
|
124
|
+
}
|
125
|
+
|
126
|
+
static void
|
127
|
+
row_callback(lcbjsp_PARSER *parser, const lcbjsp_ROW *datum)
|
128
|
+
{
|
129
|
+
lcbview_REQUEST *req = parser->data;
|
130
|
+
if (datum->type == LCBJSP_TYPE_ROW) {
|
131
|
+
if (!req->no_parse_rows) {
|
132
|
+
lcbjsp_parse_viewrow(req->parser, (lcbjsp_ROW*)datum);
|
133
|
+
}
|
134
|
+
|
135
|
+
if (req->include_docs && datum->docid.iov_len && req->callback) {
|
136
|
+
lcbview_DOCREQ *dreq = mk_docreq(datum);
|
137
|
+
dreq->parent = req;
|
138
|
+
lcbdocq_add(req->docq, &dreq->base);
|
139
|
+
req->refcount++;
|
140
|
+
|
141
|
+
} else {
|
142
|
+
lcb_RESPVIEWQUERY resp = { 0 };
|
143
|
+
if (req->no_parse_rows) {
|
144
|
+
IOV2PTRLEN(&datum->row, resp.value, resp.nvalue);
|
145
|
+
} else {
|
146
|
+
IOV2PTRLEN(&datum->key, resp.key, resp.nkey);
|
147
|
+
IOV2PTRLEN(&datum->docid, resp.docid, resp.ndocid);
|
148
|
+
IOV2PTRLEN(&datum->value, resp.value, resp.nvalue);
|
149
|
+
IOV2PTRLEN(&datum->geo, resp.geometry, resp.ngeometry);
|
150
|
+
}
|
151
|
+
resp.htresp = req->cur_htresp;
|
152
|
+
invoke_row(req, &resp);
|
153
|
+
}
|
154
|
+
} else if (datum->type == LCBJSP_TYPE_ERROR) {
|
155
|
+
invoke_last(req, LCB_PROTOCOL_ERROR);
|
156
|
+
} else if (datum->type == LCBJSP_TYPE_COMPLETE) {
|
157
|
+
/* nothing */
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
static void
|
162
|
+
cb_doc_ready(lcb_DOCQUEUE *q, lcb_DOCQREQ *req_base)
|
163
|
+
{
|
164
|
+
lcb_RESPVIEWQUERY resp = { 0 };
|
165
|
+
lcbview_DOCREQ *dreq = (lcbview_DOCREQ*)req_base;
|
166
|
+
resp.docresp = &dreq->base.docresp;
|
167
|
+
IOV2PTRLEN(&dreq->key, resp.key, resp.nkey);
|
168
|
+
IOV2PTRLEN(&dreq->value, resp.value, resp.nvalue);
|
169
|
+
IOV2PTRLEN(&dreq->base.docid, resp.docid, resp.ndocid);
|
170
|
+
IOV2PTRLEN(&dreq->geo, resp.geometry, resp.ngeometry);
|
171
|
+
|
172
|
+
if (q->parent) {
|
173
|
+
invoke_row(q->parent, &resp);
|
174
|
+
}
|
175
|
+
|
176
|
+
free(dreq);
|
177
|
+
|
178
|
+
if (q->parent) {
|
179
|
+
unref_request(q->parent);
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
static void
|
184
|
+
cb_docq_throttle(lcb_DOCQUEUE *q, int enabled)
|
185
|
+
{
|
186
|
+
lcbview_REQUEST *req = q->parent;
|
187
|
+
if (req == NULL || req->htreq == NULL) {
|
188
|
+
return;
|
189
|
+
}
|
190
|
+
if (enabled) {
|
191
|
+
lcb_htreq_pause(req->htreq);
|
192
|
+
} else {
|
193
|
+
lcb_htreq_resume(req->htreq);
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
static void
|
198
|
+
destroy_request(lcbview_REQUEST *req)
|
199
|
+
{
|
200
|
+
invoke_last(req, req->lasterr);
|
201
|
+
|
202
|
+
if (req->parser != NULL) {
|
203
|
+
lcbjsp_free(req->parser);
|
204
|
+
}
|
205
|
+
if (req->htreq != NULL) {
|
206
|
+
lcb_cancel_http_request(req->instance, req->htreq);
|
207
|
+
}
|
208
|
+
if (req->docq != NULL) {
|
209
|
+
req->docq->parent = NULL;
|
210
|
+
lcbdocq_unref(req->docq);
|
211
|
+
}
|
212
|
+
free(req);
|
213
|
+
}
|
214
|
+
|
215
|
+
static void
|
216
|
+
unref_request(lcbview_REQUEST *req)
|
217
|
+
{
|
218
|
+
if (!--req->refcount) {
|
219
|
+
destroy_request(req);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
LIBCOUCHBASE_API
|
224
|
+
lcb_error_t
|
225
|
+
lcb_view_query(lcb_t instance, const void *cookie, const lcb_CMDVIEWQUERY *cmd)
|
226
|
+
{
|
227
|
+
lcb_string path;
|
228
|
+
lcb_CMDHTTP htcmd = { 0 };
|
229
|
+
lcb_error_t rc;
|
230
|
+
lcbview_REQUEST *req = NULL;
|
231
|
+
int include_docs = 0;
|
232
|
+
int no_parse_rows = 0;
|
233
|
+
const char *vpstr = NULL;
|
234
|
+
|
235
|
+
if (cmd->nddoc == 0 || cmd->nview == 0 || cmd->callback == NULL) {
|
236
|
+
return LCB_EINVAL;
|
237
|
+
}
|
238
|
+
|
239
|
+
htcmd.method = LCB_HTTP_METHOD_GET;
|
240
|
+
htcmd.type = LCB_HTTP_TYPE_VIEW;
|
241
|
+
htcmd.cmdflags = LCB_CMDHTTP_F_STREAM;
|
242
|
+
|
243
|
+
include_docs = cmd->cmdflags & LCB_CMDVIEWQUERY_F_INCLUDE_DOCS;
|
244
|
+
no_parse_rows = cmd->cmdflags & LCB_CMDVIEWQUERY_F_NOROWPARSE;
|
245
|
+
|
246
|
+
if (include_docs && no_parse_rows) {
|
247
|
+
return LCB_OPTIONS_CONFLICT;
|
248
|
+
}
|
249
|
+
|
250
|
+
lcb_string_init(&path);
|
251
|
+
if (cmd->cmdflags & LCB_CMDVIEWQUERY_F_SPATIAL) {
|
252
|
+
vpstr = "/_spatial/";
|
253
|
+
} else {
|
254
|
+
vpstr = "/_view/";
|
255
|
+
}
|
256
|
+
|
257
|
+
if (lcb_string_appendv(&path,
|
258
|
+
"_design/", (size_t)-1, cmd->ddoc, cmd->nddoc,
|
259
|
+
vpstr, (size_t)-1, cmd->view, cmd->nview, NULL) != 0) {
|
260
|
+
|
261
|
+
lcb_string_release(&path);
|
262
|
+
return LCB_CLIENT_ENOMEM;
|
263
|
+
}
|
264
|
+
|
265
|
+
if (cmd->optstr) {
|
266
|
+
if (cmd->noptstr > MAX_GET_URI_LENGTH) {
|
267
|
+
return LCB_E2BIG;
|
268
|
+
} else {
|
269
|
+
if (lcb_string_appendv(&path,
|
270
|
+
"?", (size_t)-1, cmd->optstr, cmd->noptstr, NULL) != 0) {
|
271
|
+
|
272
|
+
lcb_string_release(&path);
|
273
|
+
return LCB_CLIENT_ENOMEM;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
if (cmd->npostdata) {
|
279
|
+
htcmd.method = LCB_HTTP_METHOD_POST;
|
280
|
+
htcmd.body = cmd->postdata;
|
281
|
+
htcmd.nbody = cmd->npostdata;
|
282
|
+
htcmd.content_type = "application/json";
|
283
|
+
}
|
284
|
+
|
285
|
+
if ( (req = calloc(1, sizeof(*req))) == NULL ||
|
286
|
+
(req->parser = lcbjsp_create(LCBJSP_MODE_VIEWS)) == NULL) {
|
287
|
+
free(req);
|
288
|
+
lcb_string_release(&path);
|
289
|
+
return LCB_CLIENT_ENOMEM;
|
290
|
+
}
|
291
|
+
|
292
|
+
req->instance = instance;
|
293
|
+
req->cookie = cookie;
|
294
|
+
req->include_docs = include_docs;
|
295
|
+
req->no_parse_rows = no_parse_rows;
|
296
|
+
req->callback = cmd->callback;
|
297
|
+
req->parser->callback = row_callback;
|
298
|
+
req->parser->data = req;
|
299
|
+
|
300
|
+
LCB_CMD_SET_KEY(&htcmd, path.base, path.nused);
|
301
|
+
htcmd.reqhandle = &req->htreq;
|
302
|
+
|
303
|
+
rc = lcb_http3(instance, req, &htcmd);
|
304
|
+
lcb_string_release(&path);
|
305
|
+
|
306
|
+
if (rc == LCB_SUCCESS) {
|
307
|
+
lcb_htreq_setcb(req->htreq, chunk_callback);
|
308
|
+
req->refcount++;
|
309
|
+
if (cmd->handle) {
|
310
|
+
*cmd->handle = req;
|
311
|
+
}
|
312
|
+
if (include_docs) {
|
313
|
+
req->docq = lcbdocq_create(instance);
|
314
|
+
req->docq->parent = req;
|
315
|
+
req->docq->cb_ready = cb_doc_ready;
|
316
|
+
req->docq->cb_throttle = cb_docq_throttle;
|
317
|
+
if (cmd->docs_concurrent_max) {
|
318
|
+
req->docq->max_pending_response = cmd->docs_concurrent_max;
|
319
|
+
}
|
320
|
+
}
|
321
|
+
lcb_aspend_add(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
|
322
|
+
} else {
|
323
|
+
req->callback = NULL;
|
324
|
+
destroy_request(req);
|
325
|
+
}
|
326
|
+
return rc;
|
327
|
+
}
|
328
|
+
|
329
|
+
LIBCOUCHBASE_API
|
330
|
+
void
|
331
|
+
lcb_view_query_initcmd(lcb_CMDVIEWQUERY *vq,
|
332
|
+
const char *design, const char *view, const char *options,
|
333
|
+
lcb_VIEWQUERYCALLBACK callback)
|
334
|
+
{
|
335
|
+
vq->view = view;
|
336
|
+
vq->nview = strlen(view);
|
337
|
+
vq->ddoc = design;
|
338
|
+
vq->nddoc = strlen(design);
|
339
|
+
if (options != NULL) {
|
340
|
+
vq->optstr = options;
|
341
|
+
vq->noptstr = strlen(options);
|
342
|
+
}
|
343
|
+
vq->callback = callback;
|
344
|
+
}
|
345
|
+
|
346
|
+
LIBCOUCHBASE_API
|
347
|
+
void
|
348
|
+
lcb_view_cancel(lcb_t instance, lcb_VIEWHANDLE handle)
|
349
|
+
{
|
350
|
+
if (handle->callback) {
|
351
|
+
handle->callback = NULL;
|
352
|
+
lcb_aspend_del(&instance->pendops, LCB_PENDTYPE_COUNTER, NULL);
|
353
|
+
if (handle->docq) {
|
354
|
+
lcbdocq_cancel(handle->docq);
|
355
|
+
}
|
356
|
+
}
|
357
|
+
(void)instance;
|
358
|
+
}
|
@@ -1,66 +1,36 @@
|
|
1
1
|
#include <libcouchbase/couchbase.h>
|
2
2
|
#include <libcouchbase/views.h>
|
3
3
|
#include <libcouchbase/pktfwd.h>
|
4
|
+
|
4
5
|
#include <jsparse/parser.h>
|
5
|
-
#include <string>
|
6
6
|
#include "docreq.h"
|
7
7
|
|
8
|
-
|
9
|
-
namespace views {
|
8
|
+
struct lcbview_REQUEST_st;
|
10
9
|
|
11
|
-
struct
|
12
|
-
|
13
|
-
|
10
|
+
typedef struct {
|
11
|
+
lcb_DOCQREQ base;
|
12
|
+
struct lcbview_REQUEST_st *parent;
|
14
13
|
lcb_IOV key;
|
15
14
|
lcb_IOV value;
|
16
15
|
lcb_IOV geo;
|
17
|
-
|
18
|
-
};
|
19
|
-
|
20
|
-
struct ViewRequest : lcb::jsparse::Parser::Actions {
|
21
|
-
ViewRequest(lcb_t, const void*, const lcb_CMDVIEWQUERY*);
|
22
|
-
~ViewRequest();
|
23
|
-
void invoke_last(lcb_error_t err);
|
24
|
-
void invoke_last() { invoke_last(lasterr); }
|
25
|
-
void invoke_row(lcb_RESPVIEWQUERY*);
|
26
|
-
void unref() {if(!--refcount){delete this;}}
|
27
|
-
void ref() {refcount++;}
|
28
|
-
void cancel();
|
29
|
-
|
30
|
-
/**
|
31
|
-
* Perform the actual HTTP request
|
32
|
-
* @param cmd User's command
|
33
|
-
*/
|
34
|
-
inline lcb_error_t request_http(const lcb_CMDVIEWQUERY* cmd);
|
35
|
-
|
36
|
-
bool is_include_docs() const {
|
37
|
-
return cmdflags & LCB_CMDVIEWQUERY_F_INCLUDE_DOCS;
|
38
|
-
}
|
39
|
-
bool is_no_rowparse() const {
|
40
|
-
return cmdflags & LCB_CMDVIEWQUERY_F_NOROWPARSE;
|
41
|
-
}
|
42
|
-
bool is_spatial() const {
|
43
|
-
return cmdflags & LCB_CMDVIEWQUERY_F_SPATIAL;
|
44
|
-
}
|
45
|
-
|
46
|
-
void JSPARSE_on_row(const lcb::jsparse::Row&);
|
47
|
-
void JSPARSE_on_error(const std::string&);
|
48
|
-
void JSPARSE_on_complete(const std::string&);
|
16
|
+
char rowbuf[1];
|
17
|
+
} lcbview_DOCREQ;
|
49
18
|
|
19
|
+
struct lcbview_REQUEST_st {
|
50
20
|
/** Current HTTP response to provide in callbacks */
|
51
21
|
const lcb_RESPHTTP *cur_htresp;
|
52
22
|
/** HTTP request object, in case we need to cancel prematurely */
|
53
23
|
struct lcb_http_request_st *htreq;
|
54
|
-
|
24
|
+
lcbjsp_PARSER *parser;
|
55
25
|
const void *cookie;
|
56
|
-
|
26
|
+
lcb_DOCQUEUE *docq;
|
57
27
|
lcb_VIEWQUERYCALLBACK callback;
|
58
28
|
lcb_t instance;
|
59
29
|
|
60
30
|
unsigned refcount;
|
61
|
-
|
31
|
+
unsigned include_docs;
|
32
|
+
unsigned no_parse_rows;
|
62
33
|
lcb_error_t lasterr;
|
63
34
|
};
|
64
35
|
|
65
|
-
|
66
|
-
}
|
36
|
+
typedef struct lcbview_REQUEST_st lcbview_REQUEST;
|