libcouchbase 0.3.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/CMakeLists.txt +6 -8
  3. data/ext/libcouchbase/README.markdown +2 -2
  4. data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
  5. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  6. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
  7. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
  8. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  9. data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
  10. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  11. data/ext/libcouchbase/cmake/source_files.cmake +21 -5
  12. data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
  13. data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
  14. data/ext/libcouchbase/example/users/README +48 -0
  15. data/ext/libcouchbase/example/users/users.c +147 -0
  16. data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
  17. data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
  18. data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
  19. data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
  20. data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
  21. data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
  22. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
  23. data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
  24. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  25. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  26. data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
  27. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  28. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  29. data/ext/libcouchbase/src/README.md +0 -2
  30. data/ext/libcouchbase/src/auth-priv.h +23 -4
  31. data/ext/libcouchbase/src/auth.cc +51 -43
  32. data/ext/libcouchbase/src/bootstrap.cc +244 -0
  33. data/ext/libcouchbase/src/bootstrap.h +58 -38
  34. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
  35. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  36. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
  37. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  38. data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
  39. data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
  40. data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
  41. data/ext/libcouchbase/src/cbft.cc +22 -27
  42. data/ext/libcouchbase/src/cntl.cc +56 -22
  43. data/ext/libcouchbase/src/connspec.cc +47 -6
  44. data/ext/libcouchbase/src/connspec.h +27 -0
  45. data/ext/libcouchbase/src/dns-srv.cc +147 -0
  46. data/ext/libcouchbase/src/dump.cc +3 -3
  47. data/ext/libcouchbase/src/errmap.cc +173 -0
  48. data/ext/libcouchbase/src/errmap.h +198 -0
  49. data/ext/libcouchbase/src/getconfig.cc +7 -33
  50. data/ext/libcouchbase/src/handler.cc +118 -7
  51. data/ext/libcouchbase/src/hostlist.cc +0 -36
  52. data/ext/libcouchbase/src/hostlist.h +44 -62
  53. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  54. data/ext/libcouchbase/src/http/http.cc +27 -35
  55. data/ext/libcouchbase/src/http/http.h +1 -34
  56. data/ext/libcouchbase/src/http/http_io.cc +28 -36
  57. data/ext/libcouchbase/src/instance.cc +131 -34
  58. data/ext/libcouchbase/src/internal.h +58 -26
  59. data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
  60. data/ext/libcouchbase/src/jsparse/parser.h +84 -98
  61. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  62. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  63. data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
  64. data/ext/libcouchbase/src/lcbio/connect.h +16 -7
  65. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  66. data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
  67. data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
  68. data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
  69. data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
  70. data/ext/libcouchbase/src/lcbio/manager.h +133 -96
  71. data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
  72. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  73. data/ext/libcouchbase/src/mc/mcreq.c +11 -2
  74. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  75. data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
  76. data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
  77. data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
  78. data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
  79. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  80. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  81. data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
  82. data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
  83. data/ext/libcouchbase/src/newconfig.cc +6 -6
  84. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  85. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  86. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  87. data/ext/libcouchbase/src/operations/durability.cc +6 -26
  88. data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
  89. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  90. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
  91. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  92. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  93. data/ext/libcouchbase/src/operations/stats.cc +3 -8
  94. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  95. data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
  96. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  97. data/ext/libcouchbase/src/packetutils.h +30 -2
  98. data/ext/libcouchbase/src/probes.d +1 -1
  99. data/ext/libcouchbase/src/rdb/rope.c +1 -1
  100. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
  101. data/ext/libcouchbase/src/retryq.cc +52 -14
  102. data/ext/libcouchbase/src/retryq.h +3 -3
  103. data/ext/libcouchbase/src/settings.c +5 -0
  104. data/ext/libcouchbase/src/settings.h +11 -0
  105. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  106. data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
  107. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  108. data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
  109. data/ext/libcouchbase/src/trace.h +4 -4
  110. data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
  111. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  112. data/ext/libcouchbase/src/views/docreq.h +24 -30
  113. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  114. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  115. data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
  116. data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
  117. data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
  118. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
  119. data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
  120. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
  121. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  122. data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
  123. data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
  124. data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
  125. data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
  126. data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
  127. data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
  128. data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
  129. data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
  130. data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
  131. data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
  132. data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
  133. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
  134. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
  135. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  136. data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
  137. data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
  138. data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
  139. data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
  140. data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
  141. data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
  142. data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
  143. data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
  144. data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
  145. data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
  146. data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
  147. data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
  148. data/ext/libcouchbase/tools/cbc.cc +143 -10
  149. data/ext/libcouchbase/tools/docgen/loc.h +1 -1
  150. data/lib/libcouchbase/connection.rb +4 -3
  151. data/lib/libcouchbase/version.rb +1 -1
  152. metadata +37 -28
  153. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  154. data/ext/libcouchbase/src/bootstrap.c +0 -269
  155. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  156. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  157. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  158. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  159. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  160. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  161. data/ext/libcouchbase/src/lcbio/manager.c +0 -584
  162. data/ext/libcouchbase/src/packetutils.c +0 -37
  163. data/ext/libcouchbase/src/simplestring.c +0 -211
  164. data/ext/libcouchbase/src/simplestring.h +0 -228
  165. data/ext/libcouchbase/src/ssobuf.h +0 -82
  166. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  167. data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -1,82 +0,0 @@
1
- /*
2
- * Copyright 2015 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
- /**
18
- * Implementation of dynamic arrays or strings suitable for one or more than
19
- * one element. If only a single element is used, extra memory is not allocated
20
- * via malloc.
21
- */
22
-
23
- #include "simplestring.h"
24
-
25
- #define LCB_SSOBUF_DECLARE(T) \
26
- struct { \
27
- unsigned count; \
28
- union { \
29
- lcb_string alloc; \
30
- T single; \
31
- } u;\
32
- } \
33
-
34
- #define LCB_SSOBUF_ALLOC(p, o, T) do { \
35
- if ((o)->count == 0) { /* Only allocate a single element */ \
36
- *(p) = &(o)->u.single; \
37
- (o)->count++; \
38
- } else if ((o)->count == 1) { /* Switch over to malloc */ \
39
- T ssobuf__tmp = (o)->u.single; \
40
- (o)->u.alloc.nused = 0; \
41
- (o)->u.alloc.nalloc = 0; \
42
- (o)->u.alloc.base = NULL; \
43
- if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T) * 2)) { \
44
- *(p) = NULL; \
45
- } else { \
46
- memcpy((o)->u.alloc.base, &ssobuf__tmp, sizeof(T)); \
47
- lcb_string_added(&(o)->u.alloc, sizeof(T)); \
48
- *(p) = (T*) ((o)->u.alloc.base + (o)->u.alloc.nused); \
49
- lcb_string_added(&(o)->u.alloc, sizeof(T)); \
50
- } \
51
- (o)->count++; \
52
- } else if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T))) { \
53
- *(p) = NULL; \
54
- } else { \
55
- *(p) = (T*) ((o)->u.alloc.base + (o)->u.alloc.nused); \
56
- lcb_string_added(&(o)->u.alloc, sizeof(T)); \
57
- (o)->count++; \
58
- } \
59
- } while (0);
60
-
61
- #define LCB_SSOBUF_ALLOC_N(p, o, T, n) do { \
62
- if (n == 1) { \
63
- LCB_SSOBUF_ALLOC(p, o, T); \
64
- } else if (n > 1) { \
65
- if (-1 == lcb_string_reserve(&(o)->u.alloc, sizeof(T) * (n) )) { \
66
- *(p) = NULL; \
67
- } else { \
68
- lcb_string_added(&(o)->u.alloc, sizeof(T) * (n) ); \
69
- *(p) = (T*)(o)->u.alloc.base; \
70
- (o)->count = n; \
71
- } \
72
- } \
73
- } while (0);
74
-
75
- #define LCB_SSOBUF_CLEAN(o) do { \
76
- if ((o)->count > 1) { \
77
- lcb_string_release(&(o)->u.alloc); \
78
- } \
79
- } while (0);
80
-
81
- #define LCB_SSOBUF_ARRAY(o, t) \
82
- ((o)->count > 1 ? ((t*)(o)->u.alloc.base) : &(o)->u.single)
@@ -1,358 +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
-
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,112 +0,0 @@
1
- /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2012 Couchbase, Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- #include "config.h"
19
- #include <gtest/gtest.h>
20
- #include <libcouchbase/couchbase.h>
21
- #include "simplestring.h"
22
-
23
- class String : public ::testing::Test
24
- {
25
- };
26
-
27
- TEST_F(String, testBasic)
28
- {
29
- int rv;
30
- lcb_string str;
31
- rv = lcb_string_init(&str);
32
- ASSERT_EQ(0, rv);
33
- ASSERT_EQ(NULL, str.base);
34
- ASSERT_EQ(0, str.nalloc);
35
- ASSERT_EQ(0, str.nused);
36
-
37
- rv = lcb_string_append(&str, "Hello", 5);
38
- ASSERT_EQ(0, rv);
39
-
40
- rv = lcb_string_append(&str, "blah", -1);
41
- ASSERT_EQ(-1, rv);
42
-
43
- rv = lcb_string_appendz(&str, "blah");
44
- ASSERT_EQ(0, rv);
45
-
46
- ASSERT_EQ(0, strcmp("Helloblah", str.base));
47
-
48
- lcb_string_erase_beginning(&str, 5);
49
- ASSERT_EQ(0, strcmp("blah", str.base));
50
-
51
- lcb_string_erase_end(&str, 4);
52
- ASSERT_EQ(0, strcmp("", str.base));
53
-
54
- lcb_string_clear(&str);
55
- ASSERT_TRUE(str.base != NULL);
56
-
57
- lcb_string_release(&str);
58
- ASSERT_EQ(NULL, str.base);
59
- }
60
-
61
- TEST_F(String, testAdvance)
62
- {
63
- int rv;
64
- lcb_string str;
65
- rv = lcb_string_init(&str);
66
- ASSERT_EQ(0, rv);
67
-
68
- rv = lcb_string_reserve(&str, 30);
69
- ASSERT_EQ(0, rv);
70
- ASSERT_TRUE(str.nalloc >= 30);
71
- ASSERT_EQ(0, str.nused);
72
-
73
- memcpy(lcb_string_tail(&str), "Hello", 5);
74
- lcb_string_added(&str, 5);
75
- ASSERT_EQ(5, str.nused);
76
- ASSERT_EQ(0, strcmp(str.base, "Hello"));
77
- lcb_string_release(&str);
78
- }
79
-
80
-
81
- TEST_F(String, testRbCopy)
82
- {
83
- int rv;
84
- ringbuffer_t rb;
85
- rv = ringbuffer_initialize(&rb, 10);
86
- ASSERT_TRUE(rv != 0);
87
-
88
- lcb_string str;
89
- rv = lcb_string_init(&str);
90
- ASSERT_EQ(0, rv);
91
-
92
- const char *txt = "The quick brown fox jumped over the lazy dog";
93
- const int ntxt = strlen(txt);
94
- ringbuffer_ensure_capacity(&rb, ntxt);
95
-
96
- ASSERT_EQ(ntxt, ringbuffer_write(&rb, txt, ntxt));
97
- ASSERT_EQ(ntxt, rb.nbytes);
98
-
99
- rv = lcb_string_rbappend(&str, &rb, 0);
100
- ASSERT_EQ(0, rv);
101
-
102
- ASSERT_EQ(0, strcmp(txt, str.base));
103
- ASSERT_EQ(ntxt, str.nused);
104
-
105
- lcb_string_clear(&str);
106
- lcb_string_rbappend(&str, &rb, 1);
107
- ASSERT_EQ(0, rb.nbytes);
108
- ASSERT_EQ(0, strcmp(txt, str.base));
109
-
110
- ringbuffer_destruct(&rb);
111
- lcb_string_release(&str);
112
- }