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
@@ -16,6 +16,7 @@
|
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include "hostlist.h"
|
19
|
+
#include "simplestring.h"
|
19
20
|
#include <stdio.h>
|
20
21
|
#include <ctype.h>
|
21
22
|
#include <limits.h>
|
@@ -263,3 +264,38 @@ Hostlist::assign(const Hostlist& src)
|
|
263
264
|
}
|
264
265
|
return *this;
|
265
266
|
}
|
267
|
+
|
268
|
+
extern "C" {
|
269
|
+
Hostlist* hostlist_create(void) { return new Hostlist(); }
|
270
|
+
void hostlist_destroy(hostlist_t l) { delete l; }
|
271
|
+
void hostlist_clear(hostlist_t l) { l->clear(); }
|
272
|
+
void hostlist_reset_strlist(hostlist_t l) { l->reset_strlist(); }
|
273
|
+
lcb_error_t hostlist_add_host(hostlist_t l, const lcb_host_t *h) { l->add(*h); return LCB_SUCCESS; }
|
274
|
+
lcb_host_t *hostlist_shift_next(hostlist_t hl, int wrap) { return hl->next(wrap); }
|
275
|
+
int hostlist_finished(hostlist_t l) { return l->ix == l->hosts.size(); }
|
276
|
+
size_t hostlist_size(hostlist_t l) { return l->size(); }
|
277
|
+
void hostlist_randomize(hostlist_t l) { l->randomize(); }
|
278
|
+
|
279
|
+
lcb_error_t
|
280
|
+
hostlist_add_string(hostlist_t hl, const char *spec, int len, int deflport) {
|
281
|
+
return hl->add(spec, len, deflport);
|
282
|
+
}
|
283
|
+
|
284
|
+
void
|
285
|
+
hostlist_assign(hostlist_t dst, const hostlist_t src) {
|
286
|
+
dst->assign(*src);
|
287
|
+
}
|
288
|
+
|
289
|
+
const lcb_host_t*
|
290
|
+
hostlist_get(const hostlist_t h, size_t ix) { return &h->hosts[ix]; }
|
291
|
+
|
292
|
+
const char * const *
|
293
|
+
hostlist_strents(const hostlist_t h) {
|
294
|
+
h->ensure_strlist();
|
295
|
+
if (h->hoststrs.size()) {
|
296
|
+
return &h->hoststrs[0];
|
297
|
+
} else {
|
298
|
+
return NULL;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}
|
@@ -45,56 +45,21 @@ struct Hostlist {
|
|
45
45
|
Hostlist() : ix(0) {}
|
46
46
|
~Hostlist();
|
47
47
|
|
48
|
-
|
49
|
-
* Adds a string to the hostlist. See lcb_host_parse for details.
|
50
|
-
* Note that if the host already exists (see 'lcb_host_equals') it will
|
51
|
-
* not be added
|
52
|
-
* @param s the string to parse
|
53
|
-
* @param len the length of the string
|
54
|
-
* @param deflport If `s` does not contain an explicit port, use this
|
55
|
-
* port instead.
|
56
|
-
* @return LCB_EINVAL if the host string is not valid
|
57
|
-
*/
|
48
|
+
void add(const lcb_host_t&);
|
58
49
|
lcb_error_t add(const char *s, long len, int deflport);
|
59
50
|
lcb_error_t add(const char *s, int deflport) { return add(s, -1, deflport); }
|
60
|
-
void add(const lcb_host_t&);
|
61
|
-
|
62
51
|
bool exists(const lcb_host_t&) const;
|
63
52
|
bool exists(const char *hostport) const;
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Return the next host in the list.
|
67
|
-
* @param wrap If the internal iterator has reached its limit, this
|
68
|
-
* indicates whether it should be reset, or if it should return NULL
|
69
|
-
* @return a new host if available, or NULL if the list is empty or the
|
70
|
-
* iterator is finished.
|
71
|
-
*/
|
72
53
|
lcb_host_t *next(bool wrap);
|
73
54
|
bool finished() const;
|
74
55
|
|
75
56
|
size_t size() const { return hosts.size(); }
|
76
57
|
bool empty() const { return hosts.empty(); }
|
77
58
|
Hostlist& assign(const Hostlist& other);
|
78
|
-
|
79
|
-
/** Clears the hostlist */
|
80
59
|
void clear() { hosts.clear(); reset_strlist(); ix = 0; }
|
81
|
-
|
82
|
-
/** Randomize the hostlist by shuffling the order. */
|
83
60
|
void randomize();
|
84
|
-
|
85
|
-
/**
|
86
|
-
* String list handling functions. These are used to return the hostlist via
|
87
|
-
* the API where we return a char*[] terminated by a NULL pointer.
|
88
|
-
*/
|
89
|
-
|
90
|
-
/** Ensure that the string list contains at least one entry */
|
91
61
|
void ensure_strlist();
|
92
|
-
|
93
|
-
/** Frees the current list of strings */
|
94
62
|
void reset_strlist();
|
95
|
-
|
96
|
-
const char * const *get_strlist() const { return &hoststrs[0]; }
|
97
|
-
|
98
63
|
unsigned int ix;
|
99
64
|
const lcb_host_t& operator[](size_t ix_) const { return hosts[ix_]; }
|
100
65
|
|
@@ -103,16 +68,28 @@ struct Hostlist {
|
|
103
68
|
};
|
104
69
|
}
|
105
70
|
typedef lcb::Hostlist* hostlist_t;
|
106
|
-
|
107
|
-
struct hostlist_st : lcb::Hostlist {
|
108
|
-
hostlist_st() : Hostlist() {
|
109
|
-
}
|
110
|
-
};
|
71
|
+
#define hostlist_st lcb::Hostlist
|
111
72
|
#endif
|
112
73
|
|
113
74
|
#ifdef __cplusplus
|
114
75
|
extern "C" {
|
115
76
|
#endif
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Creates a new hostlist. Returns NULL on allocation failure
|
80
|
+
*/
|
81
|
+
hostlist_t hostlist_create(void);
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Frees resources associated with the hostlist
|
85
|
+
*/
|
86
|
+
void hostlist_destroy(hostlist_t hostlist);
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Clears the hostlist
|
90
|
+
*/
|
91
|
+
void hostlist_clear(hostlist_t hostlist);
|
92
|
+
|
116
93
|
/**
|
117
94
|
* Parses a string into a hostlist
|
118
95
|
* @param host the target host to populate
|
@@ -144,6 +121,50 @@ lcb_host_parse(lcb_host_t *host, const char *spec, int speclen, int deflport);
|
|
144
121
|
*/
|
145
122
|
int lcb_host_equals(const lcb_host_t *a, const lcb_host_t *b);
|
146
123
|
|
124
|
+
/**
|
125
|
+
* Adds a string to the hostlist. See lcb_host_parse for details.
|
126
|
+
* Note that if the host already exists (see 'lcb_host_equals') it will
|
127
|
+
* not be added
|
128
|
+
* @return LCB_EINVAL if the host string is not value, LCB_CLIENT_ENOMEM on
|
129
|
+
* allocation failure.
|
130
|
+
*/
|
131
|
+
lcb_error_t hostlist_add_string(hostlist_t hostlist,
|
132
|
+
const char *spec,
|
133
|
+
int speclen,
|
134
|
+
int deflport);
|
135
|
+
|
136
|
+
#define hostlist_add_stringz(hostlist, spec, deflport) \
|
137
|
+
hostlist_add_string(hostlist, spec, -1, deflport)
|
138
|
+
|
139
|
+
lcb_error_t hostlist_add_host(hostlist_t hostlist, const lcb_host_t *host);
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Return the next host in the list.
|
143
|
+
* @param hostlist the hostlist to use
|
144
|
+
* @param rollover If the internal iterator has reached its limit, this
|
145
|
+
* indicates whether it should be reset, or if it should return NULL
|
146
|
+
* @return a new host if available, or NULL if the list is empty or the
|
147
|
+
* iterator is finished.
|
148
|
+
*/
|
149
|
+
lcb_host_t *hostlist_shift_next(hostlist_t hostlist, int rollover);
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Randomize the hostlist
|
153
|
+
*/
|
154
|
+
void hostlist_randomize(hostlist_t hostlist);
|
155
|
+
|
156
|
+
/**
|
157
|
+
* String list handling functions. These are used to return the hostlist via
|
158
|
+
* the API where we return a char*[] terminated by a NULL pointer.
|
159
|
+
*/
|
160
|
+
void hostlist_reset_strlist(hostlist_t hostlist);
|
161
|
+
|
162
|
+
/** Whether the internal iterator has finished. */
|
163
|
+
int hostlist_finished(hostlist_t);
|
164
|
+
size_t hostlist_size(const hostlist_t hl);
|
165
|
+
void hostlist_assign(hostlist_t dst, const hostlist_t src);
|
166
|
+
const lcb_host_t *hostlist_get(const hostlist_t, size_t);
|
167
|
+
const char * const *hostlist_strents(const hostlist_t hl);
|
147
168
|
#ifdef __cplusplus
|
148
169
|
}
|
149
170
|
#endif
|
@@ -21,7 +21,6 @@
|
|
21
21
|
#include <libcouchbase/couchbase.h>
|
22
22
|
#include <lcbio/lcbio.h>
|
23
23
|
#include <lcbio/timer-ng.h>
|
24
|
-
#include <lcbio/timer-cxx.h>
|
25
24
|
#include <lcbht/lcbht.h>
|
26
25
|
#include "contrib/http_parser/http_parser.h"
|
27
26
|
#include "http.h"
|
@@ -42,34 +41,100 @@ struct Header {
|
|
42
41
|
};
|
43
42
|
|
44
43
|
struct Request {
|
44
|
+
enum State {
|
45
|
+
/**
|
46
|
+
* The request is still ongoing. Callbacks are still active.
|
47
|
+
* Note that this essentially means the absence of any flags :)
|
48
|
+
*/
|
49
|
+
ONGOING = 0,
|
50
|
+
|
51
|
+
/**
|
52
|
+
* This flag is set when the on_complete callback has been invoked. This
|
53
|
+
* is used as a marker to prevent us from calling that callback more than
|
54
|
+
* once per request
|
55
|
+
*/
|
56
|
+
CBINVOKED = 1 << 0,
|
57
|
+
|
58
|
+
/**
|
59
|
+
* This flag is set by lcb_http_request_finish, and indicates that the
|
60
|
+
* request is no longer active per se. This means that while the request
|
61
|
+
* may still be valid in memory, it is simply waiting for any pending I/O
|
62
|
+
* operations to close, so the reference count can hit zero.
|
63
|
+
*/
|
64
|
+
FINISHED = 1 << 1,
|
65
|
+
|
66
|
+
/**
|
67
|
+
* Internal flag used to indicate that finish() should not not attempt
|
68
|
+
* to modify any instance-level globals. This is currently used
|
69
|
+
* from within lcb_destroy()
|
70
|
+
*/
|
71
|
+
NOLCB = 1 << 2
|
72
|
+
};
|
73
|
+
|
74
|
+
lcb_t instance; /**< Library handle */
|
75
|
+
std::string url; /**<Base URL: http://host:port/path?query*/
|
76
|
+
std::string host; /**< Host, derived from URL */
|
77
|
+
std::string port; /**< Port, derived from URL */
|
78
|
+
|
79
|
+
std::string pending_redirect; /**< New redirected URL */
|
80
|
+
bool has_pending_redirect() const { return !pending_redirect.empty(); }
|
81
|
+
const std::vector<char> body; /**< Input body (for POST/PUT) */
|
82
|
+
|
83
|
+
/** Request buffer (excluding body). Reassembled from inputs */
|
84
|
+
std::vector<char> preamble;
|
85
|
+
|
86
|
+
struct http_parser_url url_info; /**< Parser info for the URL */
|
87
|
+
const lcb_http_method_t method; /**< Request method constant */
|
88
|
+
const bool chunked; /**< Whether to invoke callback for each data chunk */
|
89
|
+
bool paused; /**< See pause() and resume() */
|
90
|
+
const void * const command_cookie; /** User context for callback */
|
91
|
+
size_t refcount; /** Initialized to 1. See incref() and decref() */
|
92
|
+
int redircount; /** Times this request was redirected */
|
93
|
+
|
45
94
|
/**
|
46
|
-
*
|
47
|
-
*
|
48
|
-
*
|
95
|
+
* Whether this request has delivered data to the user. This is relevant
|
96
|
+
* in cases where a retry is requested. If any data has been passed at
|
97
|
+
* all, we cannot retry the request.
|
49
98
|
*/
|
50
|
-
|
51
|
-
|
52
|
-
/** Creates a new request object and verifies the input (setup_inputs()) */
|
53
|
-
static Request * create(lcb_t instance, const void *cookie,
|
54
|
-
const lcb_CMDHTTP *cmd, lcb_error_t *rc);
|
99
|
+
bool passed_data;
|
55
100
|
|
56
|
-
/**
|
57
|
-
|
101
|
+
/** Sparse map indicating which nodes the request was already sent to */
|
102
|
+
std::vector<int> used_nodes;
|
58
103
|
|
59
|
-
/**
|
60
|
-
|
104
|
+
/**
|
105
|
+
* Last revision ID of vBucket config. If the current revision does not
|
106
|
+
* match this number, the ::used_nodes field is cleared
|
107
|
+
*/
|
108
|
+
int last_vbcrev;
|
61
109
|
|
62
|
-
|
63
|
-
|
110
|
+
const lcb_http_type_t reqtype; /**< HTTP API type */
|
111
|
+
int status; /**< OR'd flags of ::State */
|
112
|
+
std::vector<Header> request_headers; /**< List of request headers */
|
64
113
|
|
65
114
|
/**
|
66
|
-
*
|
67
|
-
*
|
68
|
-
* will begin (this function calls start_io())
|
115
|
+
* Response headers for callback (array of char*). Buffers are mapped to
|
116
|
+
* ::response_headers
|
69
117
|
*/
|
70
|
-
|
118
|
+
std::vector<const char*> response_headers_clist;
|
119
|
+
|
120
|
+
/** Backing buffers for response headers */
|
121
|
+
std::vector<Header> response_headers;
|
122
|
+
|
123
|
+
/** Callback to invoke */
|
124
|
+
lcb_RESPCALLBACK callback;
|
125
|
+
|
126
|
+
// IO variables
|
127
|
+
lcbio_pTABLE io;
|
128
|
+
lcbio_pCTX ioctx;
|
129
|
+
lcbio_pTIMER timer;
|
130
|
+
lcbio_CONNREQ creq;
|
131
|
+
|
132
|
+
/** HTTP Protocol parser */
|
133
|
+
lcbht_pPARSER parser;
|
134
|
+
|
135
|
+
/** overrides default timeout if nonzero */
|
136
|
+
const uint32_t user_timeout;
|
71
137
|
|
72
|
-
bool has_pending_redirect() const { return !pending_redirect.empty(); }
|
73
138
|
/**
|
74
139
|
* @return The effective timeout. This is either the user timeout or the
|
75
140
|
* default timeout for the API type
|
@@ -87,6 +152,13 @@ struct Request {
|
|
87
152
|
*/
|
88
153
|
bool is_ongoing() const { return status == ONGOING; }
|
89
154
|
|
155
|
+
/**
|
156
|
+
* Initializes the request. This simply copies the relevant fields from the
|
157
|
+
* body and initializes instance members to their default values. The static
|
158
|
+
* ::create() method should be used instead to construct a new object
|
159
|
+
*/
|
160
|
+
inline Request(lcb_t instance, const void *cookie, const lcb_CMDHTTP* cmd);
|
161
|
+
|
90
162
|
/**
|
91
163
|
* Sets up inputs from the command. This should really be in the
|
92
164
|
* constructor, however we also need a return value. The ::create()
|
@@ -108,6 +180,10 @@ struct Request {
|
|
108
180
|
const char *get_api_node(lcb_error_t &rc);
|
109
181
|
const char *get_api_node() { lcb_error_t dummy; return get_api_node(dummy); }
|
110
182
|
|
183
|
+
/** Creates a new request object and verifies the input (setup_inputs()) */
|
184
|
+
static Request * create(lcb_t instance, const void *cookie,
|
185
|
+
const lcb_CMDHTTP *cmd, lcb_error_t *rc);
|
186
|
+
|
111
187
|
/**
|
112
188
|
* Sets the URL for the field
|
113
189
|
* @param base The URL base (i.e. http://foo.com)
|
@@ -144,6 +220,13 @@ struct Request {
|
|
144
220
|
inline void add_to_preamble(const std::string&);
|
145
221
|
inline void add_to_preamble(const Header&);
|
146
222
|
|
223
|
+
/**
|
224
|
+
* Start all operations required to make this request. This should be
|
225
|
+
* called once all inputs have been completed. If successful, I/O operations
|
226
|
+
* will begin (this function calls start_io())
|
227
|
+
*/
|
228
|
+
lcb_error_t submit();
|
229
|
+
|
147
230
|
/**
|
148
231
|
* Starts the IO on the current request. This really belongs in submit(),
|
149
232
|
* but submit() handles building the request while start_io() sets up
|
@@ -158,7 +241,7 @@ struct Request {
|
|
158
241
|
|
159
242
|
// Helper functions for parsing response data from network
|
160
243
|
inline int handle_parse_chunked(const char *buf, unsigned nbuf);
|
161
|
-
inline void assign_response_headers(const
|
244
|
+
inline void assign_response_headers(const lcbht_RESPONSE*);
|
162
245
|
|
163
246
|
/**
|
164
247
|
* Called when a redirect has happened. pending_redirect must not be empty.
|
@@ -190,15 +273,14 @@ struct Request {
|
|
190
273
|
**/
|
191
274
|
void finish_or_retry(lcb_error_t rc);
|
192
275
|
|
193
|
-
/**
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
}
|
276
|
+
/** Pause IO on this request */
|
277
|
+
void pause();
|
278
|
+
|
279
|
+
/** Resume previously paused IO */
|
280
|
+
void resume();
|
281
|
+
|
282
|
+
/** Cancel and finish this request, suppressing callbacks */
|
283
|
+
void cancel();
|
202
284
|
|
203
285
|
/**
|
204
286
|
* Let the request finish its normal course, suppressing any callbacks.
|
@@ -215,101 +297,6 @@ struct Request {
|
|
215
297
|
|
216
298
|
/** Increment refcount */
|
217
299
|
void incref() { refcount++; }
|
218
|
-
|
219
|
-
lcb_t instance; /**< Library handle */
|
220
|
-
std::string url; /**<Base URL: http://host:port/path?query*/
|
221
|
-
std::string host; /**< Host, derived from URL */
|
222
|
-
std::string port; /**< Port, derived from URL */
|
223
|
-
|
224
|
-
std::string pending_redirect; /**< New redirected URL */
|
225
|
-
|
226
|
-
const std::vector<char> body; /**< Input body (for POST/PUT) */
|
227
|
-
|
228
|
-
/** Request buffer (excluding body). Reassembled from inputs */
|
229
|
-
std::vector<char> preamble;
|
230
|
-
|
231
|
-
struct http_parser_url url_info; /**< Parser info for the URL */
|
232
|
-
const lcb_http_method_t method; /**< Request method constant */
|
233
|
-
const bool chunked; /**< Whether to invoke callback for each data chunk */
|
234
|
-
bool paused; /**< See pause() and resume() */
|
235
|
-
const void * const command_cookie; /** User context for callback */
|
236
|
-
size_t refcount; /** Initialized to 1. See incref() and decref() */
|
237
|
-
int redircount; /** Times this request was redirected */
|
238
|
-
|
239
|
-
/**
|
240
|
-
* Whether this request has delivered data to the user. This is relevant
|
241
|
-
* in cases where a retry is requested. If any data has been passed at
|
242
|
-
* all, we cannot retry the request.
|
243
|
-
*/
|
244
|
-
bool passed_data;
|
245
|
-
|
246
|
-
/** Sparse map indicating which nodes the request was already sent to */
|
247
|
-
std::vector<int> used_nodes;
|
248
|
-
|
249
|
-
/**
|
250
|
-
* Last revision ID of vBucket config. If the current revision does not
|
251
|
-
* match this number, the ::used_nodes field is cleared
|
252
|
-
*/
|
253
|
-
int last_vbcrev;
|
254
|
-
|
255
|
-
const lcb_http_type_t reqtype; /**< HTTP API type */
|
256
|
-
|
257
|
-
|
258
|
-
enum State {
|
259
|
-
/**
|
260
|
-
* The request is still ongoing. Callbacks are still active.
|
261
|
-
* Note that this essentially means the absence of any flags :)
|
262
|
-
*/
|
263
|
-
ONGOING = 0,
|
264
|
-
|
265
|
-
/**
|
266
|
-
* This flag is set when the on_complete callback has been invoked. This
|
267
|
-
* is used as a marker to prevent us from calling that callback more than
|
268
|
-
* once per request
|
269
|
-
*/
|
270
|
-
CBINVOKED = 1 << 0,
|
271
|
-
|
272
|
-
/**
|
273
|
-
* This flag is set by lcb_http_request_finish, and indicates that the
|
274
|
-
* request is no longer active per se. This means that while the request
|
275
|
-
* may still be valid in memory, it is simply waiting for any pending I/O
|
276
|
-
* operations to close, so the reference count can hit zero.
|
277
|
-
*/
|
278
|
-
FINISHED = 1 << 1,
|
279
|
-
|
280
|
-
/**
|
281
|
-
* Internal flag used to indicate that finish() should not not attempt
|
282
|
-
* to modify any instance-level globals. This is currently used
|
283
|
-
* from within lcb_destroy()
|
284
|
-
*/
|
285
|
-
NOLCB = 1 << 2
|
286
|
-
};
|
287
|
-
int status; /**< OR'd flags of ::State */
|
288
|
-
std::vector<Header> request_headers; /**< List of request headers */
|
289
|
-
|
290
|
-
/**
|
291
|
-
* Response headers for callback (array of char*). Buffers are mapped to
|
292
|
-
* ::response_headers
|
293
|
-
*/
|
294
|
-
std::vector<const char*> response_headers_clist;
|
295
|
-
|
296
|
-
/** Backing buffers for response headers */
|
297
|
-
std::vector<lcb::htparse::MimeHeader> response_headers;
|
298
|
-
|
299
|
-
/** Callback to invoke */
|
300
|
-
lcb_RESPCALLBACK callback;
|
301
|
-
|
302
|
-
// IO variables
|
303
|
-
lcbio_pTABLE io;
|
304
|
-
lcbio_pCTX ioctx;
|
305
|
-
lcbio_pTIMER timer;
|
306
|
-
lcbio_CONNREQ creq;
|
307
|
-
|
308
|
-
/** HTTP Protocol parser */
|
309
|
-
lcb::htparse::Parser* parser;
|
310
|
-
|
311
|
-
/** overrides default timeout if nonzero */
|
312
|
-
const uint32_t user_timeout;
|
313
300
|
};
|
314
301
|
|
315
302
|
} // namespace: http
|