libcouchbase 0.3.3 → 1.0.0

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 (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,37 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2014 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 "packetutils.h"
19
- #include "rdb/rope.h"
20
-
21
- #ifndef _WIN32 /* for win32 this is inside winsock, included in sysdefs.h */
22
- #include <arpa/inet.h>
23
- #endif
24
-
25
- int
26
- lcb_pktinfo_ior_get(packet_info *info, rdb_IOROPE *ior, unsigned *required)
27
- {
28
- }
29
-
30
- void
31
- lcb_pktinfo_ior_done(packet_info *info, rdb_IOROPE *ior)
32
- {
33
- if (!PACKET_NBODY(info)) {
34
- return;
35
- }
36
- rdb_consumed(ior, PACKET_NBODY(info));
37
- }
@@ -1,211 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2014 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 "simplestring.h"
19
- #include "assert.h"
20
-
21
- static void ensure_cstr(lcb_string *str);
22
-
23
- int lcb_string_init(lcb_string *str)
24
- {
25
- str->base = NULL;
26
- str->nalloc = 0;
27
- str->nused = 0;
28
- return 0;
29
- }
30
-
31
- void lcb_string_release(lcb_string *str)
32
- {
33
- if (str->base == NULL) {
34
- return;
35
- }
36
- free(str->base);
37
- memset(str, 0, sizeof(*str));
38
- }
39
-
40
- void lcb_string_clear(lcb_string *str)
41
- {
42
- str->nused = 0;
43
- if (str->nalloc) {
44
- ensure_cstr(str);
45
- }
46
- }
47
-
48
- void lcb_string_added(lcb_string *str, lcb_size_t nused)
49
- {
50
- str->nused += nused;
51
- lcb_assert(str->nused <= str->nalloc);
52
- ensure_cstr(str);
53
- }
54
-
55
- int lcb_string_reserve(lcb_string *str, lcb_size_t size)
56
- {
57
- lcb_size_t newalloc;
58
- char *newbuf;
59
-
60
- /** Set size to one greater, for the terminating NUL */
61
- size++;
62
- if (!size) {
63
- return -1;
64
- }
65
-
66
- if (str->nalloc - str->nused >= size) {
67
- return 0;
68
- }
69
-
70
- newalloc = str->nalloc;
71
- if (!newalloc) {
72
- newalloc = 1;
73
- }
74
-
75
- while (newalloc - str->nused < size) {
76
- if (newalloc * 2 < newalloc) {
77
- return -1;
78
- }
79
-
80
- newalloc *= 2;
81
- }
82
-
83
- newbuf = realloc(str->base, newalloc);
84
- if (newbuf == NULL) {
85
- return -1;
86
- }
87
-
88
- str->base = newbuf;
89
- str->nalloc = newalloc;
90
- return 0;
91
- }
92
-
93
- static void ensure_cstr(lcb_string *str)
94
- {
95
- str->base[str->nused] = '\0';
96
- }
97
-
98
- int lcb_string_append(lcb_string *str, const void *data, lcb_size_t size)
99
- {
100
- if (lcb_string_reserve(str, size)) {
101
- return -1;
102
- }
103
-
104
- memcpy(str->base + str->nused, data, size);
105
- str->nused += size;
106
- ensure_cstr(str);
107
- return 0;
108
- }
109
-
110
- int lcb_string_appendz(lcb_string *str, const char *s)
111
- {
112
- return lcb_string_append(str, s, strlen(s));
113
- }
114
-
115
- int lcb_string_appendv(lcb_string *str, ...)
116
- {
117
- va_list ap;
118
- va_start(ap, str);
119
-
120
- while (1) {
121
- size_t len;
122
- int rc;
123
- const char *ptr;
124
-
125
- if ((ptr = va_arg(ap, const char *)) == NULL) {
126
- return 0;
127
- }
128
-
129
- len = va_arg(ap, size_t);
130
- if (len == (size_t)-1) {
131
- len = strlen(ptr);
132
- }
133
-
134
- rc = lcb_string_append(str, ptr, len);
135
- if (rc != 0) {
136
- return -1;
137
- }
138
- }
139
- return 0;
140
- }
141
-
142
- int lcb_string_rbappend(lcb_string *str, ringbuffer_t *rb, int rbadvance)
143
- {
144
- lcb_size_t expected, nw;
145
- expected = rb->nbytes;
146
- if (!expected) {
147
- return 0;
148
- }
149
-
150
- if (lcb_string_reserve(str, expected)) {
151
- return -1;
152
- }
153
-
154
- nw = ringbuffer_peek(rb, lcb_string_tail(str), expected);
155
- if (nw != expected) {
156
- return -1;
157
- }
158
-
159
- if (rbadvance) {
160
- ringbuffer_consumed(rb, nw);
161
- }
162
-
163
- lcb_string_added(str, nw);
164
- return 0;
165
- }
166
-
167
- void lcb_string_erase_end(lcb_string *str, lcb_size_t to_remove)
168
- {
169
- lcb_assert(to_remove <= str->nused);
170
- str->nused -= to_remove;
171
- ensure_cstr(str);
172
- }
173
-
174
- void lcb_string_erase_beginning(lcb_string *str, lcb_size_t to_remove)
175
- {
176
- lcb_assert(to_remove <= str->nused);
177
- if (!to_remove) {
178
- str->nused = 0;
179
- return;
180
- }
181
-
182
- memmove(str->base, str->base + to_remove, str->nused - to_remove);
183
- str->nused -= to_remove;
184
- ensure_cstr(str);
185
- }
186
-
187
- int lcb_string_insert(lcb_string *str, size_t at, const char *src, size_t nsrc)
188
- {
189
- if (!nsrc) {
190
- return 0;
191
- }
192
- if (at == str->nused) {
193
- return lcb_string_append(str, src, nsrc);
194
- }
195
-
196
- if (lcb_string_reserve(str, nsrc) != 0) {
197
- return -1;
198
- }
199
- memmove(str->base + at + nsrc, str->base + at, str->nused - at);
200
- memcpy(str->base + at, src, nsrc);
201
- str->nused += nsrc;
202
- ensure_cstr(str);
203
- return 0;
204
- }
205
-
206
- void lcb_string_transfer(lcb_string *from, lcb_string *to)
207
- {
208
- lcb_assert(to->base == NULL);
209
- *to = *from;
210
- memset(from, 0, sizeof(*from));
211
- }
@@ -1,228 +0,0 @@
1
- /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
- /*
3
- * Copyright 2013 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
- #ifndef LCB_STRING_H
19
- #define LCB_STRING_H
20
-
21
- #include <libcouchbase/couchbase.h>
22
- #include <stdarg.h>
23
-
24
- #include "config.h"
25
- #include "assert.h"
26
- #include "ringbuffer.h"
27
-
28
- /**
29
- * Simple string type.
30
- *
31
- * This structure is designed mainly for ease of use when dealing with actual
32
- * "string" data - i.e. data which must be null-terminated and contiguous.
33
- *
34
- * This won't replace the ringbuffer structure as this string's removal and
35
- * copying operations are comparatively expensive.
36
- *
37
- * Note that all API functions which update the position of the buffer ALSO
38
- * add a trailing NUL byte at the end.
39
- */
40
- typedef struct lcb_string_st {
41
- /** Buffer that's allocated */
42
- char *base;
43
-
44
- /** Number of bytes allocated */
45
- lcb_size_t nalloc;
46
-
47
- /** Number of bytes used */
48
- lcb_size_t nused;
49
- #ifdef __cplusplus
50
- typedef char *iterator;
51
- typedef const char *const_iterator;
52
-
53
- iterator begin() { return base; };
54
- iterator end() { return base + nused; }
55
- const_iterator begin() const { return base; }
56
- const_iterator end() const { return base + nused; }
57
- size_t size() const { return nused; }
58
- size_t capacity() const { return nalloc; }
59
- const char *c_str() const { return base; }
60
-
61
- inline void insert(iterator p, const char *first, const char *last);
62
- #endif
63
- } lcb_string;
64
-
65
- #ifdef __cplusplus
66
- extern "C" {
67
- #endif
68
-
69
- int lcb_string_init(lcb_string *str);
70
-
71
- /**
72
- * Free any storage associated with the string. The string's state will be
73
- * empty as if string_init() had just been called.
74
- */
75
- void lcb_string_release(lcb_string *str);
76
-
77
- /**
78
- * Clear the contents of the string, but don't free the underlying buffer
79
- */
80
- void lcb_string_clear(lcb_string *str);
81
-
82
-
83
- /**
84
- * Indicate that bytes have been added to the string. This is used in conjunction
85
- * with reserve(). As such, the number of bytes added should not exceed the
86
- * number of bytes passed to reserver.
87
- *
88
- * @param str the string
89
- * @param nbytes the number of bytes added
90
- */
91
- void lcb_string_added(lcb_string *str, lcb_size_t nbytes);
92
-
93
- /**
94
- * Reserve an amount of free bytes within the string. When this is done,
95
- * up to @c size bytes may be added to the string starting at @c base+str->nbytes
96
- */
97
- int lcb_string_reserve(lcb_string *str, lcb_size_t size);
98
-
99
-
100
- /**
101
- * Adds data to the string.
102
- * @param str the string to append to
103
- * @param data the data to copy
104
- * @param size the size of data to copy
105
- */
106
- int lcb_string_append(lcb_string *str, const void *data, lcb_size_t size);
107
-
108
- /**
109
- * Adds a C-style string
110
- * @param str the target lcb_string
111
- * @param zstr a NUL-terminated string to add
112
- */
113
- int lcb_string_appendz(lcb_string *str, const char *zstr);
114
-
115
-
116
- /**
117
- * Appends a list of pointer-length pairs. Useful if you need to concatenate
118
- * many small buffers
119
- * @param str The string to append to. This should be followed by a list of
120
- * `pointer, size` arguments (where `size` is `size_t`). If the length is
121
- * `-1` then `strlen(pointer)` will be called to determine the length.
122
- *
123
- * A terminal `NULL` should be placed at the end of the argument list
124
- *
125
- * @return 0 if appended, nonzero on memory error
126
- */
127
- int lcb_string_appendv(lcb_string *str, ...);
128
-
129
- /**
130
- * Adds a string from a ringbuffer structure. This copies the contents
131
- * of the ringbuffer into a string.
132
- * @param str the target string
133
- * @param rb the source ringbuffer
134
- * @param rbadvance whether to advance the ringbuffer's read head
135
- */
136
- int lcb_string_rbappend(lcb_string *str, ringbuffer_t *rb, int rbadvance);
137
-
138
- /**
139
- * Removes bytes from the end of the string. The resultant string will be
140
- * NUL-terminated
141
- * @param str the string to operate on
142
- * @param to_remove the number of bytes to trim from the end
143
- */
144
- void lcb_string_erase_end(lcb_string *str, lcb_size_t to_remove);
145
-
146
-
147
- /**
148
- * Removes bytes from the beginning of the string. The resultant string will
149
- * be NUL-terminated.
150
- * @param str the string to operate on
151
- * @param to_remove the number of bytes to remove from the beginning of
152
- * the string.
153
- */
154
- void lcb_string_erase_beginning(lcb_string *str, lcb_size_t to_remove);
155
-
156
- /**
157
- * Transfers ownership of the underlying buffer contained within the structure
158
- * 'to' to the structure 'from', as such, 'from' becomes a newly initialized
159
- * empty string structure and 'to' contains the existing buffer.
160
- *
161
- * @param from the string which contains the existing buffer
162
- * @param to a new string structure which contains no buffer. It will receive
163
- * from's buffer
164
- */
165
- void lcb_string_transfer(lcb_string *from, lcb_string *to);
166
-
167
- /**
168
- * Inserts a string at a given position
169
- * @param str the string object
170
- * @param at position at which to insert
171
- * @param src the string to insert
172
- * @param len length of string to insert
173
- */
174
- int lcb_string_insert(lcb_string *str, size_t at, const char *src, size_t len);
175
-
176
- #define lcb_string_tail(str) ((str)->base + (str)->nused)
177
-
178
- #ifdef __cplusplus
179
- }
180
-
181
- #include <stdexcept>
182
- #include <new>
183
- void
184
- lcb_string_st::insert(iterator p, const char *first, const char *last) {
185
- size_t at = p - base;
186
- size_t n = last - first;
187
- if (lcb_string_insert(this, at, first, n) != 0) {
188
- throw std::bad_alloc();
189
- }
190
- }
191
-
192
- namespace lcb {
193
- class AutoString : public lcb_string_st {
194
- public:
195
- AutoString() {
196
- lcb_string_init(this);
197
- }
198
- ~AutoString() {
199
- lcb_string_release(this);
200
- }
201
-
202
- char *take(size_t& len, size_t& cap) {
203
- char *ret = base;
204
- len = nused;
205
- cap = nalloc;
206
-
207
- base = NULL;
208
- nalloc = 0;
209
- nused = 0;
210
- return ret;
211
- }
212
- char *take(size_t& len) {
213
- size_t dummy;
214
- return take(len, dummy);
215
- }
216
- char *take() {
217
- size_t dummy;
218
- return take(dummy, dummy);
219
- }
220
-
221
- private:
222
- AutoString(lcb_string_st&);
223
- AutoString(const lcb_string_st&);
224
- };
225
- }
226
-
227
- #endif /** __cplusplus */
228
- #endif /* LCB_STRING_H */