libcouchbase 0.3.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libcouchbase/CMakeLists.txt +6 -8
- data/ext/libcouchbase/README.markdown +2 -2
- data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
- data/ext/libcouchbase/cmake/defs.mk.in +0 -2
- data/ext/libcouchbase/cmake/source_files.cmake +21 -5
- data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
- data/ext/libcouchbase/example/users/README +48 -0
- data/ext/libcouchbase/example/users/users.c +147 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
- data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
- data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
- data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
- data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
- data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
- data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
- data/ext/libcouchbase/src/README.md +0 -2
- data/ext/libcouchbase/src/auth-priv.h +23 -4
- data/ext/libcouchbase/src/auth.cc +51 -43
- data/ext/libcouchbase/src/bootstrap.cc +244 -0
- data/ext/libcouchbase/src/bootstrap.h +58 -38
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
- data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
- data/ext/libcouchbase/src/cbft.cc +22 -27
- data/ext/libcouchbase/src/cntl.cc +56 -22
- data/ext/libcouchbase/src/connspec.cc +47 -6
- data/ext/libcouchbase/src/connspec.h +27 -0
- data/ext/libcouchbase/src/dns-srv.cc +147 -0
- data/ext/libcouchbase/src/dump.cc +3 -3
- data/ext/libcouchbase/src/errmap.cc +173 -0
- data/ext/libcouchbase/src/errmap.h +198 -0
- data/ext/libcouchbase/src/getconfig.cc +7 -33
- data/ext/libcouchbase/src/handler.cc +118 -7
- data/ext/libcouchbase/src/hostlist.cc +0 -36
- data/ext/libcouchbase/src/hostlist.h +44 -62
- data/ext/libcouchbase/src/http/http-priv.h +125 -112
- data/ext/libcouchbase/src/http/http.cc +27 -35
- data/ext/libcouchbase/src/http/http.h +1 -34
- data/ext/libcouchbase/src/http/http_io.cc +28 -36
- data/ext/libcouchbase/src/instance.cc +131 -34
- data/ext/libcouchbase/src/internal.h +58 -26
- data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
- data/ext/libcouchbase/src/jsparse/parser.h +84 -98
- data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
- data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
- data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
- data/ext/libcouchbase/src/lcbio/connect.h +16 -7
- data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
- data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
- data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
- data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
- data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
- data/ext/libcouchbase/src/lcbio/manager.h +133 -96
- data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
- data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
- data/ext/libcouchbase/src/mc/mcreq.c +11 -2
- data/ext/libcouchbase/src/mc/mcreq.h +9 -2
- data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
- data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
- data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
- data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
- data/ext/libcouchbase/src/mctx-helper.h +51 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
- data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
- data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
- data/ext/libcouchbase/src/newconfig.cc +6 -6
- data/ext/libcouchbase/src/nodeinfo.cc +2 -2
- data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
- data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
- data/ext/libcouchbase/src/operations/durability.cc +6 -26
- data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
- data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
- data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
- data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
- data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
- data/ext/libcouchbase/src/operations/stats.cc +3 -8
- data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
- data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
- data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
- data/ext/libcouchbase/src/packetutils.h +30 -2
- data/ext/libcouchbase/src/probes.d +1 -1
- data/ext/libcouchbase/src/rdb/rope.c +1 -1
- data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
- data/ext/libcouchbase/src/retryq.cc +52 -14
- data/ext/libcouchbase/src/retryq.h +3 -3
- data/ext/libcouchbase/src/settings.c +5 -0
- data/ext/libcouchbase/src/settings.h +11 -0
- data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
- data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
- data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
- data/ext/libcouchbase/src/trace.h +4 -4
- data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
- data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
- data/ext/libcouchbase/src/views/docreq.h +24 -30
- data/ext/libcouchbase/src/views/viewreq.cc +318 -0
- data/ext/libcouchbase/src/views/viewreq.h +43 -13
- data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
- data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
- data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
- data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
- data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
- data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
- data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
- data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
- data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
- data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
- data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
- data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
- data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
- data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
- data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
- data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
- data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
- data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
- data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
- data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
- data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
- data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
- data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
- data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
- data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
- data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
- data/ext/libcouchbase/tools/cbc.cc +143 -10
- data/ext/libcouchbase/tools/docgen/loc.h +1 -1
- data/lib/libcouchbase/connection.rb +4 -3
- data/lib/libcouchbase/version.rb +1 -1
- metadata +37 -28
- data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
- data/ext/libcouchbase/src/bootstrap.c +0 -269
- data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
- data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
- data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
- data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
- data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
- data/ext/libcouchbase/src/lcbio/connect.c +0 -557
- data/ext/libcouchbase/src/lcbio/manager.c +0 -584
- data/ext/libcouchbase/src/packetutils.c +0 -37
- data/ext/libcouchbase/src/simplestring.c +0 -211
- data/ext/libcouchbase/src/simplestring.h +0 -228
- data/ext/libcouchbase/src/ssobuf.h +0 -82
- data/ext/libcouchbase/src/views/viewreq.c +0 -358
- data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -8,8 +8,13 @@
|
|
8
8
|
class JsonParseTest : public ::testing::Test {
|
9
9
|
};
|
10
10
|
|
11
|
+
using namespace lcb::jsparse;
|
11
12
|
|
12
|
-
|
13
|
+
static std::string iov2s(const lcb_IOV& iov) {
|
14
|
+
return std::string(reinterpret_cast<const char*>(iov.iov_base), iov.iov_len);
|
15
|
+
}
|
16
|
+
|
17
|
+
struct Context : Parser::Actions {
|
13
18
|
lcb_error_t rc;
|
14
19
|
bool received_done;
|
15
20
|
std::string meta;
|
@@ -23,115 +28,55 @@ struct Context {
|
|
23
28
|
meta.clear();
|
24
29
|
rows.clear();
|
25
30
|
}
|
26
|
-
|
27
|
-
|
28
|
-
class Parser {
|
29
|
-
public:
|
30
|
-
Parser(int mode_) : mode(mode_), inner(NULL) {
|
31
|
-
reset();
|
31
|
+
void JSPARSE_on_row(const Row& row) {
|
32
|
+
rows.push_back(iov2s(row.row));
|
32
33
|
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
lcbjsp_free(inner);
|
37
|
-
}
|
38
|
-
inner = lcbjsp_create(mode);
|
39
|
-
}
|
40
|
-
|
41
|
-
~Parser() {
|
42
|
-
if (inner != NULL) {
|
43
|
-
lcbjsp_free(inner);
|
44
|
-
}
|
34
|
+
void JSPARSE_on_complete(const std::string& s) {
|
35
|
+
meta.assign(s);
|
36
|
+
received_done = true;
|
45
37
|
}
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
void JSPARSE_on_error(const std::string&) {
|
39
|
+
rc = LCB_PROTOCOL_ERROR;
|
40
|
+
received_done = true;
|
49
41
|
}
|
50
|
-
|
51
|
-
lcbjsp_PARSER *getInner() {
|
52
|
-
return inner;
|
53
|
-
}
|
54
|
-
|
55
|
-
private:
|
56
|
-
int mode;
|
57
|
-
lcbjsp_PARSER *inner;
|
58
|
-
Parser(Parser&);
|
59
42
|
};
|
60
43
|
|
61
|
-
static
|
62
|
-
return std::string(reinterpret_cast<const char*>(iov.iov_base), iov.iov_len);
|
63
|
-
}
|
64
|
-
|
65
|
-
extern "C" {
|
66
|
-
static void rowCallback(lcbjsp_PARSER *parser, const lcbjsp_ROW *row) {
|
67
|
-
Context *ctx = reinterpret_cast<Context*>(parser->data);
|
68
|
-
if (row->type == LCBJSP_TYPE_ERROR) {
|
69
|
-
ctx->rc = LCB_PROTOCOL_ERROR;
|
70
|
-
ctx->received_done = true;
|
71
|
-
} else if (row->type == LCBJSP_TYPE_ROW) {
|
72
|
-
ctx->rows.push_back(iov2s(row->row));
|
73
|
-
} else if (row->type == LCBJSP_TYPE_COMPLETE) {
|
74
|
-
ctx->meta = iov2s(row->row);
|
75
|
-
ctx->received_done = true;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
static bool validateJsonRows(const char *txt, size_t ntxt, int mode)
|
44
|
+
static bool validateJsonRows(const char *txt, size_t ntxt, Parser::Mode mode)
|
81
45
|
{
|
82
|
-
Parser parser(mode);
|
83
|
-
EXPECT_TRUE(parser != NULL);
|
84
|
-
if (parser == NULL) {
|
85
|
-
return false;
|
86
|
-
}
|
87
|
-
|
88
|
-
// Feed it once
|
89
46
|
Context cx;
|
90
|
-
parser
|
91
|
-
parser.getInner()->data = &cx;
|
47
|
+
Parser parser(mode, &cx);
|
92
48
|
|
93
49
|
for (size_t ii = 0; ii < ntxt; ii++) {
|
94
|
-
|
50
|
+
parser.feed(txt + ii, 1);
|
95
51
|
}
|
96
52
|
EXPECT_EQ(LCB_SUCCESS, cx.rc);
|
97
53
|
|
98
54
|
lcb_IOV out;
|
99
|
-
|
55
|
+
parser.get_postmortem(out);
|
100
56
|
EXPECT_EQ(cx.meta, iov2s(out));
|
101
57
|
Json::Value root;
|
102
58
|
EXPECT_TRUE(Json::Reader().parse(cx.meta, root));
|
103
59
|
return true;
|
104
60
|
}
|
105
61
|
|
106
|
-
static bool validateBadParse(const char *txt, size_t ntxt,
|
62
|
+
static bool validateBadParse(const char *txt, size_t ntxt, Parser::Mode mode)
|
107
63
|
{
|
108
|
-
Parser p(mode);
|
109
64
|
Context cx;
|
110
|
-
p
|
111
|
-
p.
|
112
|
-
lcbjsp_feed(p, JSON_fts_bad, sizeof(JSON_fts_bad));
|
65
|
+
Parser p(mode, &cx);
|
66
|
+
p.feed(JSON_fts_bad, sizeof(JSON_fts_bad));
|
113
67
|
EXPECT_EQ(LCB_PROTOCOL_ERROR, cx.rc);
|
114
|
-
|
115
|
-
p.reset();
|
116
|
-
cx.reset();
|
117
|
-
|
118
|
-
p.getInner()->callback = rowCallback;
|
119
|
-
p.getInner()->data = &cx;
|
120
|
-
|
121
|
-
for (size_t ii = 0; ii < ntxt; ++ii) {
|
122
|
-
}
|
123
68
|
return true;
|
124
69
|
}
|
125
70
|
|
126
71
|
TEST_F(JsonParseTest, testFTS)
|
127
72
|
{
|
128
|
-
ASSERT_TRUE(validateJsonRows(JSON_fts_good, sizeof(JSON_fts_good),
|
129
|
-
ASSERT_TRUE(validateBadParse(JSON_fts_bad, sizeof(JSON_fts_bad),
|
130
|
-
ASSERT_TRUE(validateBadParse(JSON_fts_bad2, sizeof(JSON_fts_bad2),
|
73
|
+
ASSERT_TRUE(validateJsonRows(JSON_fts_good, sizeof(JSON_fts_good), Parser::MODE_FTS));
|
74
|
+
ASSERT_TRUE(validateBadParse(JSON_fts_bad, sizeof(JSON_fts_bad), Parser::MODE_FTS));
|
75
|
+
ASSERT_TRUE(validateBadParse(JSON_fts_bad2, sizeof(JSON_fts_bad2), Parser::MODE_FTS));
|
131
76
|
}
|
132
77
|
|
133
78
|
TEST_F(JsonParseTest, testN1QL) {
|
134
|
-
ASSERT_TRUE(validateJsonRows(JSON_n1ql_nonempty, sizeof(JSON_n1ql_nonempty),
|
135
|
-
ASSERT_TRUE(validateJsonRows(JSON_n1ql_empty, sizeof(JSON_n1ql_empty),
|
136
|
-
ASSERT_TRUE(validateBadParse(JSON_n1ql_bad, sizeof(JSON_n1ql_bad),
|
79
|
+
ASSERT_TRUE(validateJsonRows(JSON_n1ql_nonempty, sizeof(JSON_n1ql_nonempty), Parser::MODE_N1QL));
|
80
|
+
ASSERT_TRUE(validateJsonRows(JSON_n1ql_empty, sizeof(JSON_n1ql_empty), Parser::MODE_N1QL));
|
81
|
+
ASSERT_TRUE(validateBadParse(JSON_n1ql_bad, sizeof(JSON_n1ql_bad), Parser::MODE_N1QL));
|
137
82
|
}
|
@@ -8,7 +8,6 @@ class N1qLStringTests : public ::testing::Test {
|
|
8
8
|
|
9
9
|
TEST_F(N1qLStringTests, testParseTimeout)
|
10
10
|
{
|
11
|
-
lcb_U32 value;
|
12
11
|
ASSERT_EQ(1500000, lcb_n1qlreq_parsetmo("1.5s"));
|
13
12
|
ASSERT_EQ(1500000, lcb_n1qlreq_parsetmo("1500ms"));
|
14
13
|
ASSERT_EQ(1500000, lcb_n1qlreq_parsetmo("1500000us"));
|
@@ -5,6 +5,7 @@
|
|
5
5
|
#include "settings.h"
|
6
6
|
|
7
7
|
using std::string;
|
8
|
+
using namespace lcb::htparse;
|
8
9
|
|
9
10
|
class HtparseTest : public ::testing::Test {
|
10
11
|
};
|
@@ -13,52 +14,51 @@ TEST_F(HtparseTest, testBasic)
|
|
13
14
|
{
|
14
15
|
lcb_settings *settings = lcb_settings_new();
|
15
16
|
// Allocate a parser
|
16
|
-
|
17
|
+
Parser *parser = new Parser(settings);
|
17
18
|
ASSERT_FALSE(parser == NULL);
|
18
19
|
|
19
20
|
// Feed the parser some stuff
|
20
|
-
|
21
|
+
unsigned state;
|
21
22
|
|
22
23
|
string buf;
|
23
24
|
buf = "HTTP/1.0 200 OK\r\n";
|
24
25
|
|
25
|
-
state =
|
26
|
+
state = parser->parse(buf.c_str(), buf.size());
|
26
27
|
ASSERT_EQ(0, state);
|
27
28
|
|
28
29
|
buf = "Connec";
|
29
|
-
state =
|
30
|
+
state = parser->parse(buf.c_str(), buf.size());
|
30
31
|
ASSERT_EQ(0, state);
|
31
32
|
buf = "tion: Keep-Alive\r\n";
|
32
|
-
state =
|
33
|
+
state = parser->parse(buf.c_str(), buf.size());
|
33
34
|
ASSERT_EQ(0, state);
|
34
35
|
buf += "Content-Length: 5\r\n\r\n";
|
35
|
-
state =
|
36
|
-
ASSERT_EQ(
|
36
|
+
state = parser->parse(buf.c_str(), buf.size());
|
37
|
+
ASSERT_EQ(Parser::S_HEADER|Parser::S_HTSTATUS, state);
|
37
38
|
|
38
|
-
|
39
|
-
ASSERT_EQ(200, resp
|
39
|
+
Response& resp = parser->get_cur_response();
|
40
|
+
ASSERT_EQ(200, resp.status);
|
40
41
|
|
41
42
|
// Add some data into the body
|
42
43
|
buf = "H";
|
43
|
-
state =
|
44
|
-
ASSERT_EQ(0, state &
|
45
|
-
|
44
|
+
state = parser->parse(buf.c_str(), buf.size());
|
45
|
+
ASSERT_EQ(0, state & Parser::S_ERROR);
|
46
|
+
ASSERT_EQ("H", resp.body);
|
46
47
|
|
47
48
|
buf = "ello";
|
48
|
-
state =
|
49
|
-
ASSERT_NE(0, state &
|
50
|
-
|
49
|
+
state = parser->parse(buf.c_str(), buf.size());
|
50
|
+
ASSERT_NE(0, state & Parser::S_DONE);
|
51
|
+
ASSERT_EQ("Hello", resp.body);
|
51
52
|
|
52
53
|
// Now find the header
|
53
|
-
|
54
|
-
lcbht_free(parser);
|
54
|
+
delete parser;
|
55
55
|
lcb_settings_unref(settings);
|
56
56
|
}
|
57
57
|
|
58
58
|
TEST_F(HtparseTest, testHeaderFunctions)
|
59
59
|
{
|
60
60
|
lcb_settings *settings = lcb_settings_new();
|
61
|
-
|
61
|
+
Parser *parser = new Parser(settings);
|
62
62
|
|
63
63
|
string buf = "HTTP/1.0 200 OK\r\n"
|
64
64
|
"Connection: keep-alive\r\n"
|
@@ -66,45 +66,28 @@ TEST_F(HtparseTest, testHeaderFunctions)
|
|
66
66
|
"Content-Type: application/json\r\n"
|
67
67
|
"Content-Length: 0\r\n"
|
68
68
|
"\r\n";
|
69
|
-
|
70
|
-
state =
|
71
|
-
ASSERT_NE(0, state &
|
69
|
+
unsigned state;
|
70
|
+
state = parser->parse(buf.c_str(), buf.size());
|
71
|
+
ASSERT_NE(0, state & Parser::S_DONE);
|
72
72
|
|
73
|
-
|
73
|
+
Response &resp = parser->get_cur_response();
|
74
74
|
// Now fine the header value stuff
|
75
|
-
ASSERT_STREQ("keep-alive",
|
76
|
-
ASSERT_STREQ("dummy/1.0",
|
77
|
-
ASSERT_STREQ("application/json",
|
78
|
-
|
79
|
-
using std::map;
|
80
|
-
map<string,string> hdrmap;
|
81
|
-
char **hdrlist = lcbht_make_resphdrlist(resp);
|
82
|
-
for (char **cur = hdrlist; *cur != NULL; cur += 2) {
|
83
|
-
string k = cur[0];
|
84
|
-
string v = cur[1];
|
85
|
-
hdrmap[k] = v;
|
86
|
-
free(cur[0]);
|
87
|
-
free(cur[1]);
|
88
|
-
}
|
89
|
-
free(hdrlist);
|
90
|
-
|
91
|
-
ASSERT_EQ("keep-alive", hdrmap["Connection"]);
|
92
|
-
ASSERT_EQ("dummy/1.0", hdrmap["X-Server"]);
|
93
|
-
ASSERT_EQ("application/json", hdrmap["Content-Type"]);
|
94
|
-
|
95
|
-
lcbht_free(parser);
|
75
|
+
ASSERT_STREQ("keep-alive", resp.get_header_value("Connection"));
|
76
|
+
ASSERT_STREQ("dummy/1.0", resp.get_header_value("X-Server"));
|
77
|
+
ASSERT_STREQ("application/json", resp.get_header_value("Content-Type"));
|
78
|
+
delete parser;
|
96
79
|
lcb_settings_unref(settings);
|
97
80
|
}
|
98
81
|
|
99
82
|
TEST_F(HtparseTest, testParseErrors)
|
100
83
|
{
|
101
84
|
lcb_settings *settings = lcb_settings_new();
|
102
|
-
|
85
|
+
Parser *parser = new Parser(settings);
|
103
86
|
|
104
87
|
string buf = "blahblahblah";
|
105
|
-
|
106
|
-
ASSERT_NE(0, state &
|
107
|
-
|
88
|
+
unsigned state = parser->parse(buf.c_str(), buf.size());
|
89
|
+
ASSERT_NE(0, state & Parser::S_ERROR);
|
90
|
+
delete parser;
|
108
91
|
lcb_settings_unref(settings);
|
109
92
|
}
|
110
93
|
|
@@ -112,8 +95,7 @@ TEST_F(HtparseTest, testParseErrors)
|
|
112
95
|
TEST_F(HtparseTest, testParseExtended)
|
113
96
|
{
|
114
97
|
lcb_settings *settings = lcb_settings_new();
|
115
|
-
|
116
|
-
lcbht_RESPONSE *resp;
|
98
|
+
Parser *parser = new Parser(settings);
|
117
99
|
|
118
100
|
const char *body;
|
119
101
|
unsigned nbody, nused;
|
@@ -122,18 +104,18 @@ TEST_F(HtparseTest, testParseExtended)
|
|
122
104
|
"Connection: keep-alive\r\n"
|
123
105
|
"Content-Length: 5\r\n";
|
124
106
|
|
125
|
-
|
126
|
-
state =
|
127
|
-
ASSERT_EQ(0, state &
|
107
|
+
unsigned state;
|
108
|
+
state = parser->parse_ex(buf.c_str(), buf.size(), &nused, &nbody, &body);
|
109
|
+
ASSERT_EQ(0, state & Parser::S_ERROR);
|
128
110
|
ASSERT_EQ(NULL, body);
|
129
111
|
ASSERT_EQ(buf.size(), nused);
|
130
112
|
ASSERT_EQ(0, nbody);
|
131
113
|
|
132
|
-
resp =
|
114
|
+
Response& resp = parser->get_cur_response();
|
133
115
|
buf = "\r\nHello";
|
134
116
|
// Feed the buffer
|
135
|
-
state =
|
136
|
-
ASSERT_EQ(0, state &
|
117
|
+
state = parser->parse_ex(buf.c_str(), buf.size(), &nused, &nbody, &body);
|
118
|
+
ASSERT_EQ(0, state & Parser::S_DONE);
|
137
119
|
ASSERT_EQ(5, nbody);
|
138
120
|
ASSERT_FALSE(NULL == body);
|
139
121
|
ASSERT_STREQ("Hello", body);
|
@@ -142,52 +124,50 @@ TEST_F(HtparseTest, testParseExtended)
|
|
142
124
|
size_t off = nused;
|
143
125
|
|
144
126
|
// Parse again
|
145
|
-
state =
|
127
|
+
state = parser->parse_ex(buf.c_str()+off, buf.size()-off, &nused, &nbody, &body);
|
146
128
|
ASSERT_EQ(nused, buf.size()-off);
|
147
129
|
ASSERT_TRUE(body == NULL);
|
148
130
|
ASSERT_EQ(0, nbody);
|
149
|
-
ASSERT_NE(0, state &
|
150
|
-
ASSERT_EQ(0, state &
|
151
|
-
ASSERT_EQ(0, resp
|
152
|
-
|
153
|
-
lcbht_free(parser);
|
131
|
+
ASSERT_NE(0, state & Parser::S_DONE);
|
132
|
+
ASSERT_EQ(0, state & Parser::S_ERROR);
|
133
|
+
ASSERT_EQ(0, resp.body.size());
|
134
|
+
delete parser;
|
154
135
|
lcb_settings_unref(settings);
|
155
136
|
}
|
156
137
|
|
157
138
|
TEST_F(HtparseTest, testCanKeepalive)
|
158
139
|
{
|
159
140
|
lcb_settings *settings = lcb_settings_new();
|
160
|
-
|
141
|
+
Parser *parser = new Parser(settings);
|
161
142
|
string buf = "HTTP/1.0 200 OK\r\n"
|
162
143
|
"Content-Length: 0\r\n"
|
163
144
|
"\r\n";
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
ASSERT_EQ(0, lcbht_can_keepalive(parser));
|
145
|
+
unsigned state = parser->parse(buf.c_str(), buf.size());
|
146
|
+
ASSERT_NE(0, state & Parser::S_DONE);
|
147
|
+
ASSERT_EQ(0, state & Parser::S_ERROR);
|
148
|
+
ASSERT_FALSE(parser->can_keepalive());
|
169
149
|
|
170
150
|
// Use HTTP/1.1 with Connection: close
|
171
|
-
|
151
|
+
parser->reset();
|
172
152
|
buf = "HTTP/1.1 200 OK\r\n"
|
173
153
|
"Content-Length: 0\r\n"
|
174
154
|
"Connection: close\r\n"
|
175
155
|
"\r\n";
|
176
|
-
state =
|
177
|
-
ASSERT_NE(0, state &
|
178
|
-
ASSERT_EQ(0, state &
|
179
|
-
|
156
|
+
state = parser->parse(buf.c_str(), buf.size());
|
157
|
+
ASSERT_NE(0, state & Parser::S_DONE);
|
158
|
+
ASSERT_EQ(0, state & Parser::S_ERROR);
|
159
|
+
ASSERT_FALSE(parser->can_keepalive());
|
180
160
|
|
181
|
-
|
161
|
+
parser->reset();
|
182
162
|
// Default HTTP/1.1
|
183
163
|
buf = "HTTP/1.1 200 OK\r\n"
|
184
164
|
"Content-Length: 0\r\n"
|
185
165
|
"\r\n";
|
186
|
-
state =
|
187
|
-
ASSERT_NE(0, state &
|
188
|
-
ASSERT_EQ(0, state &
|
189
|
-
|
166
|
+
state = parser->parse(buf.c_str(), buf.size());
|
167
|
+
ASSERT_NE(0, state & Parser::S_DONE);
|
168
|
+
ASSERT_EQ(0, state & Parser::S_ERROR);
|
169
|
+
ASSERT_TRUE(parser->can_keepalive());
|
190
170
|
|
191
|
-
|
171
|
+
delete parser;
|
192
172
|
lcb_settings_unref(settings);
|
193
173
|
}
|
@@ -16,17 +16,30 @@ server_runfunc(void *arg)
|
|
16
16
|
void
|
17
17
|
TestServer::run()
|
18
18
|
{
|
19
|
+
if (closed) {
|
20
|
+
return;
|
21
|
+
}
|
22
|
+
|
23
|
+
fd_set fds;
|
24
|
+
struct timeval tmout = { 1, 0 };
|
25
|
+
|
26
|
+
FD_ZERO(&fds);
|
27
|
+
FD_SET(*lsn, &fds);
|
28
|
+
|
19
29
|
while (!closed) {
|
20
30
|
struct sockaddr_in newaddr;
|
21
31
|
socklen_t naddr = sizeof(newaddr);
|
22
|
-
int newsock = accept(*lsn, (struct sockaddr *)&newaddr, &naddr);
|
23
32
|
|
24
|
-
if (
|
25
|
-
|
26
|
-
}
|
33
|
+
if (select(*lsn + 1, &fds, NULL, NULL, &tmout) == 1) {
|
34
|
+
int newsock = accept(*lsn, (struct sockaddr *)&newaddr, &naddr);
|
27
35
|
|
28
|
-
|
29
|
-
|
36
|
+
if (newsock == -1) {
|
37
|
+
break;
|
38
|
+
}
|
39
|
+
|
40
|
+
TestConnection *newconn = new TestConnection(this, factory(newsock));
|
41
|
+
startConnection(newconn);
|
42
|
+
}
|
30
43
|
}
|
31
44
|
}
|
32
45
|
|