libcouchbase 0.2.0 → 0.3.1
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.
- 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
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
#include <libcouchbase/couchbase.h>
|
|
2
|
-
|
|
3
|
-
#include "config.h"
|
|
4
|
-
#include "hostlist.h"
|
|
5
|
-
#include "connspec.h"
|
|
6
|
-
#include "hostlist.h"
|
|
7
|
-
|
|
8
|
-
#ifndef _WIN32
|
|
9
|
-
#include <string>
|
|
10
|
-
|
|
11
|
-
#ifdef HAVE_ARPA_NAMESER_H
|
|
12
|
-
#include <arpa/nameser.h>
|
|
13
|
-
#if __NAMESER < 19991006
|
|
14
|
-
#undef HAVE_RES_SEARCH
|
|
15
|
-
#endif /* __NAMESER < NNN */
|
|
16
|
-
#endif /* HAVE_ARPA_NAMESER_H */
|
|
17
|
-
|
|
18
|
-
#if defined(HAVE_ARPA_NAMESER_H) && defined(HAVE_RES_SEARCH)
|
|
19
|
-
#define CAN_SRV_LOOKUP
|
|
20
|
-
#include <cstdio>
|
|
21
|
-
#include <sys/types.h>
|
|
22
|
-
#include <netinet/in.h>
|
|
23
|
-
#include <resolv.h>
|
|
24
|
-
|
|
25
|
-
lcb_error_t
|
|
26
|
-
lcb::dnssrv_query(const char* name, lcb::Hostlist& hostlist)
|
|
27
|
-
{
|
|
28
|
-
ns_msg msg;
|
|
29
|
-
|
|
30
|
-
int rv = 0, nresp, ii;
|
|
31
|
-
lcb_U16 dns_rv;
|
|
32
|
-
|
|
33
|
-
std::vector<unsigned char> pkt(NS_PACKETSZ);
|
|
34
|
-
nresp = res_search(name, ns_c_in, ns_t_srv, &pkt[0], NS_PACKETSZ);
|
|
35
|
-
if (nresp < 0) {
|
|
36
|
-
return LCB_UNKNOWN_HOST;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
rv = ns_initparse(&pkt[0], nresp, &msg);
|
|
40
|
-
if (rv != 0) {
|
|
41
|
-
return LCB_PROTOCOL_ERROR;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
dns_rv = ns_msg_getflag(msg, ns_f_rcode);
|
|
45
|
-
if (dns_rv != ns_r_noerror) {
|
|
46
|
-
return LCB_UNKNOWN_HOST;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (!ns_msg_count(msg, ns_s_an)) {
|
|
50
|
-
return LCB_UNKNOWN_HOST;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for (ii = 0; ii < ns_msg_count(msg, ns_s_an); ii++) {
|
|
54
|
-
lcb_U16 srv_prio, srv_weight, srv_port;
|
|
55
|
-
ns_rr rr;
|
|
56
|
-
const lcb_U8 *rdata;
|
|
57
|
-
size_t rdlen;
|
|
58
|
-
|
|
59
|
-
if (ns_parserr(&msg, ns_s_an, ii, &rr) != 0) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (ns_rr_type(rr) != ns_t_srv) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* Get the rdata and length fields */
|
|
68
|
-
rdata = ns_rr_rdata(rr);
|
|
69
|
-
rdlen = ns_rr_rdlen(rr);
|
|
70
|
-
|
|
71
|
-
if (rdlen < 6) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#define do_get16(t) t = ns_get16(rdata); rdata += 2; rdlen -=2
|
|
76
|
-
do_get16(srv_prio);
|
|
77
|
-
do_get16(srv_weight);
|
|
78
|
-
do_get16(srv_port);
|
|
79
|
-
#undef do_get_16
|
|
80
|
-
|
|
81
|
-
(void)srv_prio; (void)srv_weight; /* Handle these in the future */
|
|
82
|
-
std::vector<char> dname(NS_MAXDNAME + 1);
|
|
83
|
-
ns_name_uncompress(
|
|
84
|
-
ns_msg_base(msg), ns_msg_end(msg),
|
|
85
|
-
rdata, &dname[0], NS_MAXDNAME);
|
|
86
|
-
hostlist.add(&dname[0], srv_port);
|
|
87
|
-
}
|
|
88
|
-
return LCB_SUCCESS;
|
|
89
|
-
}
|
|
90
|
-
#endif /* HAVE_RES_SEARCH */
|
|
91
|
-
|
|
92
|
-
#else
|
|
93
|
-
#include <windns.h>
|
|
94
|
-
#define CAN_SRV_LOOKUP
|
|
95
|
-
/* Implement via DnsQuery() */
|
|
96
|
-
lcb_error_t
|
|
97
|
-
lcb::dnssrv_query(const char *addr, Hostlist& hs)
|
|
98
|
-
{
|
|
99
|
-
DNS_STATUS status;
|
|
100
|
-
PDNS_RECORDA root, cur;
|
|
101
|
-
|
|
102
|
-
status = DnsQuery_A(
|
|
103
|
-
addr, DNS_TYPE_SRV, DNS_QUERY_STANDARD, NULL, (PDNS_RECORD*)&root, NULL);
|
|
104
|
-
if (status != 0) {
|
|
105
|
-
return LCB_UNKNOWN_HOST;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
for (cur = root; cur; cur = cur->pNext) {
|
|
109
|
-
// Use the ASCII version of the DNS lookup structure
|
|
110
|
-
const DNS_SRV_DATAA *srv = &cur->Data.SRV;
|
|
111
|
-
hs.add(srv->pNameTarget, srv->wPort);
|
|
112
|
-
}
|
|
113
|
-
DnsRecordListFree(root, DnsFreeRecordList);
|
|
114
|
-
return LCB_SUCCESS;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
#endif /* !WIN32 */
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
#ifndef CAN_SRV_LOOKUP
|
|
121
|
-
lcb_error_t lcb::dnssrv_query(const char *, Hostlist&) {
|
|
122
|
-
return LCB_CLIENT_FEATURE_UNAVAILABLE;
|
|
123
|
-
}
|
|
124
|
-
#endif
|
|
125
|
-
|
|
126
|
-
#define SVCNAME_PLAIN "_couchbase._tcp."
|
|
127
|
-
#define SVCNAME_SSL "_couchbases._tcp."
|
|
128
|
-
|
|
129
|
-
lcb::Hostlist*
|
|
130
|
-
lcb::dnssrv_getbslist(const char *addr, bool is_ssl, lcb_error_t& errp) {
|
|
131
|
-
std::string ss;
|
|
132
|
-
Hostlist *ret = new Hostlist();
|
|
133
|
-
ss.append(is_ssl ? SVCNAME_SSL : SVCNAME_PLAIN);
|
|
134
|
-
ss.append(addr);
|
|
135
|
-
|
|
136
|
-
errp = dnssrv_query(ss.c_str(), *ret);
|
|
137
|
-
if (errp != LCB_SUCCESS) {
|
|
138
|
-
delete ret;
|
|
139
|
-
ret = NULL;
|
|
140
|
-
}
|
|
141
|
-
return ret;
|
|
142
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
#include "internal.h"
|
|
2
|
-
#include "errmap.h"
|
|
3
|
-
#include "contrib/lcb-jsoncpp/lcb-jsoncpp.h"
|
|
4
|
-
|
|
5
|
-
using namespace lcb::errmap;
|
|
6
|
-
|
|
7
|
-
ErrorMap::ErrorMap() : revision(0), version(0) {
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
static ErrorAttribute getAttribute(const std::string& s) {
|
|
11
|
-
#define X(c, s_) if (s == s_) { return c; }
|
|
12
|
-
LCB_XERRMAP_ATTRIBUTES(X)
|
|
13
|
-
#undef X
|
|
14
|
-
return INVALID_ATTRIBUTE;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const uint32_t ErrorMap::MAX_VERSION = 1;
|
|
18
|
-
|
|
19
|
-
ErrorMap::ParseStatus
|
|
20
|
-
ErrorMap::parse(const char *s, size_t n, std::string& errmsg) {
|
|
21
|
-
Json::Value root_nonconst;
|
|
22
|
-
Json::Reader reader;
|
|
23
|
-
if (!reader.parse(s, s + n, root_nonconst)) {
|
|
24
|
-
errmsg = "Invalid JSON";
|
|
25
|
-
return PARSE_ERROR;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const Json::Value& root = root_nonconst;
|
|
29
|
-
const Json::Value& verJson = root["version"];
|
|
30
|
-
if (!verJson.isNumeric()) {
|
|
31
|
-
errmsg = "'version' is not a number";
|
|
32
|
-
return PARSE_ERROR;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (verJson.asUInt() > MAX_VERSION) {
|
|
36
|
-
errmsg = "'version' is unreasonably high";
|
|
37
|
-
return UNKNOWN_VERSION;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const Json::Value& revJson = root["revision"];
|
|
41
|
-
if (!revJson.isNumeric()) {
|
|
42
|
-
errmsg = "'revision' is not a number";
|
|
43
|
-
return PARSE_ERROR;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (revJson.asUInt() <= revision) {
|
|
47
|
-
return NOT_UPDATED;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const Json::Value& errsJson = root["errors"];
|
|
51
|
-
if (!errsJson.isObject()) {
|
|
52
|
-
errmsg = "'errors' is not an object";
|
|
53
|
-
return PARSE_ERROR;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Json::Value::const_iterator ii = errsJson.begin();
|
|
57
|
-
for (; ii != errsJson.end(); ++ii) {
|
|
58
|
-
// Key is the version in hex
|
|
59
|
-
unsigned ec = 0;
|
|
60
|
-
if (sscanf(ii.key().asCString(), "%x", &ec) != 1) {
|
|
61
|
-
errmsg = "key " + ii.key().asString() + " is not a hex number";
|
|
62
|
-
return PARSE_ERROR;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const Json::Value& errorJson = *ii;
|
|
66
|
-
|
|
67
|
-
// Descend into the error attributes
|
|
68
|
-
Error error;
|
|
69
|
-
error.code = static_cast<uint16_t>(ec);
|
|
70
|
-
|
|
71
|
-
error.shortname = errorJson["name"].asString();
|
|
72
|
-
error.description = errorJson["desc"].asString();
|
|
73
|
-
|
|
74
|
-
const Json::Value& attrs = errorJson["attrs"];
|
|
75
|
-
if (!attrs.isArray()) {
|
|
76
|
-
errmsg = "'attrs' is not an array";
|
|
77
|
-
return PARSE_ERROR;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
Json::Value::const_iterator jj = attrs.begin();
|
|
81
|
-
for (; jj != attrs.end(); ++jj) {
|
|
82
|
-
ErrorAttribute attr = getAttribute(jj->asString());
|
|
83
|
-
if (attr == INVALID_ATTRIBUTE) {
|
|
84
|
-
errmsg = "unknown attribute received";
|
|
85
|
-
return UNKNOWN_VERSION;
|
|
86
|
-
}
|
|
87
|
-
error.attributes.insert(attr);
|
|
88
|
-
}
|
|
89
|
-
errors.insert(MapType::value_type(ec, error));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return UPDATED;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const Error& ErrorMap::getError(uint16_t code) const {
|
|
96
|
-
static const Error invalid;
|
|
97
|
-
MapType::const_iterator it = errors.find(code);
|
|
98
|
-
|
|
99
|
-
if (it != errors.end()) {
|
|
100
|
-
return it->second;
|
|
101
|
-
} else {
|
|
102
|
-
return invalid;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
ErrorMap *lcb_errmap_new() { return new ErrorMap(); }
|
|
107
|
-
void lcb_errmap_free(ErrorMap* m) { delete m; }
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
#ifndef LCB_ERRMAP_H
|
|
2
|
-
#define LCB_ERRMAP_H
|
|
3
|
-
|
|
4
|
-
#ifdef __cplusplus
|
|
5
|
-
|
|
6
|
-
#include <map>
|
|
7
|
-
#include <set>
|
|
8
|
-
#include <string>
|
|
9
|
-
|
|
10
|
-
namespace lcb {
|
|
11
|
-
namespace errmap {
|
|
12
|
-
|
|
13
|
-
enum ErrorAttribute {
|
|
14
|
-
#define LCB_XERRMAP_ATTRIBUTES(X) \
|
|
15
|
-
X(TEMPORARY, "temp") \
|
|
16
|
-
X(SUBDOC, "subdoc") \
|
|
17
|
-
X(RETRY_NOW, "retry-now") \
|
|
18
|
-
X(RETRY_LATER, "retry-later") \
|
|
19
|
-
X(INVALID_INPUT, "invalid-input") \
|
|
20
|
-
X(NOT_ENABLED, "support") \
|
|
21
|
-
X(AUTH, "auth") \
|
|
22
|
-
X(CONN_STATE_INVALIDATED, "conn-state-invalidated") \
|
|
23
|
-
X(CONSTRAINT_FAILURE, "item-only") \
|
|
24
|
-
X(RETRY_EXP_BACKOFF, "retry-exp-backoff") \
|
|
25
|
-
X(RETRY_LINEAR_BACKOFF, "retry-linear-backoff") \
|
|
26
|
-
X(INTERNAL, "internal") \
|
|
27
|
-
X(DCP, "dcp") \
|
|
28
|
-
X(FETCH_CONFIG, "fetch-config") \
|
|
29
|
-
X(SPECIAL_HANDLING, "special-handling")
|
|
30
|
-
|
|
31
|
-
#define X(c, s) c,
|
|
32
|
-
LCB_XERRMAP_ATTRIBUTES(X)
|
|
33
|
-
#undef X
|
|
34
|
-
|
|
35
|
-
INVALID_ATTRIBUTE
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
struct Error {
|
|
39
|
-
uint16_t code;
|
|
40
|
-
std::string shortname;
|
|
41
|
-
std::string description;
|
|
42
|
-
std::set<ErrorAttribute> attributes;
|
|
43
|
-
|
|
44
|
-
Error() : code(-1) {
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
bool isValid() const {
|
|
48
|
-
return code != uint16_t(-1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
bool hasAttribute(ErrorAttribute attr) const {
|
|
52
|
-
return attributes.find(attr) != attributes.end();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
class ErrorMap {
|
|
57
|
-
public:
|
|
58
|
-
enum ParseStatus {
|
|
59
|
-
/** Couldn't parse JSON!*/
|
|
60
|
-
PARSE_ERROR,
|
|
61
|
-
|
|
62
|
-
/** Version is too high */
|
|
63
|
-
UNKNOWN_VERSION,
|
|
64
|
-
|
|
65
|
-
/** Current version/revision is higher or equal */
|
|
66
|
-
NOT_UPDATED,
|
|
67
|
-
|
|
68
|
-
/** Updated */
|
|
69
|
-
UPDATED
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
ErrorMap();
|
|
73
|
-
ParseStatus parse(const char *s, size_t n, std::string& errmsg);
|
|
74
|
-
ParseStatus parse(const char *s, size_t n) {
|
|
75
|
-
std::string tmp;
|
|
76
|
-
return parse(s, n, tmp);
|
|
77
|
-
}
|
|
78
|
-
size_t getVersion() const { return version; }
|
|
79
|
-
size_t getRevision() const { return revision; };
|
|
80
|
-
const Error& getError(uint16_t code) const;
|
|
81
|
-
bool isLoaded() const {
|
|
82
|
-
return !errors.empty();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private:
|
|
86
|
-
static const uint32_t MAX_VERSION;
|
|
87
|
-
ErrorMap(const ErrorMap&);
|
|
88
|
-
typedef std::map<uint16_t, Error> MapType;
|
|
89
|
-
MapType errors;
|
|
90
|
-
uint32_t revision;
|
|
91
|
-
uint32_t version;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
} // namespace
|
|
95
|
-
} // namespace
|
|
96
|
-
|
|
97
|
-
typedef lcb::errmap::ErrorMap* lcb_pERRMAP;
|
|
98
|
-
#else
|
|
99
|
-
typedef struct lcb_ERRMAP* lcb_pERRMAP;
|
|
100
|
-
#endif /* __cplusplus */
|
|
101
|
-
|
|
102
|
-
#ifdef __cplusplus
|
|
103
|
-
extern "C" {
|
|
104
|
-
#endif
|
|
105
|
-
|
|
106
|
-
lcb_pERRMAP lcb_errmap_new(void);
|
|
107
|
-
void lcb_errmap_free(lcb_pERRMAP);
|
|
108
|
-
|
|
109
|
-
#ifdef __cplusplus
|
|
110
|
-
}
|
|
111
|
-
#endif
|
|
112
|
-
|
|
113
|
-
#endif /* LCB_ERRMAP_H */
|
|
@@ -1,177 +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 "lcbht.h"
|
|
19
|
-
#include "contrib/http_parser/http_parser.h"
|
|
20
|
-
#include "settings.h"
|
|
21
|
-
|
|
22
|
-
using namespace lcb::htparse;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Parser::Parser(lcb_settings_st *settings_)
|
|
26
|
-
: http_parser(), settings(settings_), lastcall(CB_NONE),
|
|
27
|
-
last_body(0), last_bodylen(0), paused(false), is_ex(false) {
|
|
28
|
-
lcb_settings_ref(settings);
|
|
29
|
-
reset();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
Parser::~Parser() {
|
|
33
|
-
lcb_settings_unref(settings);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
static int on_hdr_key(http_parser *pb, const char *s, size_t n) {
|
|
37
|
-
return Parser::from_htp(pb)->on_hdr_key(s, n);
|
|
38
|
-
}
|
|
39
|
-
int Parser::on_hdr_key(const char *s, size_t n) {
|
|
40
|
-
if (lastcall != CB_HDR_KEY) {
|
|
41
|
-
/* new key */
|
|
42
|
-
resp.headers.push_back(MimeHeader());
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
resp.headers.back().key.append(s, n);
|
|
46
|
-
lastcall = CB_HDR_KEY;
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static int on_hdr_value(http_parser *pb, const char *s, size_t n) {
|
|
51
|
-
return Parser::from_htp(pb)->on_hdr_value(s, n);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
int Parser::on_hdr_value(const char *s, size_t n) {
|
|
55
|
-
MimeHeader *header = &resp.headers.back();
|
|
56
|
-
header->value.append(s, n);
|
|
57
|
-
lastcall = CB_HDR_VALUE;
|
|
58
|
-
return 0;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static int on_hdr_done(http_parser *pb) {
|
|
62
|
-
return Parser::from_htp(pb)->on_hdr_done();
|
|
63
|
-
}
|
|
64
|
-
int Parser::on_hdr_done() {
|
|
65
|
-
resp.state |= S_HTSTATUS|S_HEADER;
|
|
66
|
-
|
|
67
|
-
/* extract the status */
|
|
68
|
-
resp.status = http_parser::status_code;
|
|
69
|
-
lastcall = CB_HDR_DONE;
|
|
70
|
-
return 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
static int on_body(http_parser *pb, const char *s, size_t n) {
|
|
74
|
-
return Parser::from_htp(pb)->on_body(s, n);
|
|
75
|
-
}
|
|
76
|
-
int Parser::on_body(const char *s, size_t n) {
|
|
77
|
-
if (is_ex) {
|
|
78
|
-
last_body = s;
|
|
79
|
-
last_bodylen = n;
|
|
80
|
-
paused = true;
|
|
81
|
-
_lcb_http_parser_pause(this, 1);
|
|
82
|
-
} else {
|
|
83
|
-
resp.body.append(s, n);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
lastcall = CB_BODY;
|
|
87
|
-
resp.state |= S_BODY;
|
|
88
|
-
return 0;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
static int on_msg_done(http_parser *pb) {
|
|
92
|
-
return Parser::from_htp(pb)->on_msg_done();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
int Parser::on_msg_done() {
|
|
96
|
-
resp.state |= S_DONE;
|
|
97
|
-
return 0;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
static struct http_parser_settings Parser_Settings = {
|
|
102
|
-
NULL, /* msg_begin */
|
|
103
|
-
NULL, /* on_url */
|
|
104
|
-
::on_hdr_key,
|
|
105
|
-
::on_hdr_value,
|
|
106
|
-
::on_hdr_done,
|
|
107
|
-
::on_body,
|
|
108
|
-
::on_msg_done
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
unsigned
|
|
112
|
-
Parser::parse(const void *data_, size_t ndata) {
|
|
113
|
-
is_ex = false;
|
|
114
|
-
size_t nb = _lcb_http_parser_execute(this,
|
|
115
|
-
&Parser_Settings,
|
|
116
|
-
reinterpret_cast<const char *>(data_), ndata);
|
|
117
|
-
|
|
118
|
-
if (nb != ndata) {
|
|
119
|
-
resp.state |= S_ERROR;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return resp.state;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
unsigned
|
|
126
|
-
Parser::parse_ex(const void *data_, unsigned ndata,
|
|
127
|
-
unsigned *nused, unsigned *nbody, const char **pbody)
|
|
128
|
-
{
|
|
129
|
-
is_ex = true;
|
|
130
|
-
size_t nb = _lcb_http_parser_execute(this,
|
|
131
|
-
&Parser_Settings, reinterpret_cast<const char*>(data_), ndata);
|
|
132
|
-
if (nb != ndata) {
|
|
133
|
-
if (paused) {
|
|
134
|
-
_lcb_http_parser_pause(this, 0);
|
|
135
|
-
paused = false;
|
|
136
|
-
} else {
|
|
137
|
-
resp.state |= S_ERROR;
|
|
138
|
-
return resp.state;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
*nused = nb;
|
|
143
|
-
*nbody = last_bodylen;
|
|
144
|
-
*pbody = last_body;
|
|
145
|
-
|
|
146
|
-
last_body = NULL;
|
|
147
|
-
last_bodylen = 0;
|
|
148
|
-
return resp.state;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
bool Parser::can_keepalive() const {
|
|
152
|
-
if (!(resp.state & S_DONE)) {
|
|
153
|
-
return 0;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (resp.state & S_ERROR) {
|
|
157
|
-
return 0;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return _lcb_http_should_keep_alive(
|
|
161
|
-
const_cast<http_parser*>(static_cast<const http_parser*>(this)));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
void Parser::reset() {
|
|
165
|
-
resp.clear();
|
|
166
|
-
_lcb_http_parser_init(this, HTTP_RESPONSE);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const MimeHeader* Response::get_header(const std::string& key) const {
|
|
170
|
-
std::list<MimeHeader>::const_iterator it;
|
|
171
|
-
for (it = headers.begin(); it != headers.end(); ++it) {
|
|
172
|
-
if (it->key == key) {
|
|
173
|
-
return &*it;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return NULL;
|
|
177
|
-
}
|