libcouchbase 0.3.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/CMakeLists.txt +6 -8
  3. data/ext/libcouchbase/README.markdown +2 -2
  4. data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
  5. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  6. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
  7. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
  8. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  9. data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
  10. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  11. data/ext/libcouchbase/cmake/source_files.cmake +21 -5
  12. data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
  13. data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
  14. data/ext/libcouchbase/example/users/README +48 -0
  15. data/ext/libcouchbase/example/users/users.c +147 -0
  16. data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
  17. data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
  18. data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
  19. data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
  20. data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
  21. data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
  22. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
  23. data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
  24. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  25. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  26. data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
  27. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  28. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  29. data/ext/libcouchbase/src/README.md +0 -2
  30. data/ext/libcouchbase/src/auth-priv.h +23 -4
  31. data/ext/libcouchbase/src/auth.cc +51 -43
  32. data/ext/libcouchbase/src/bootstrap.cc +244 -0
  33. data/ext/libcouchbase/src/bootstrap.h +58 -38
  34. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
  35. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  36. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
  37. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  38. data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
  39. data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
  40. data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
  41. data/ext/libcouchbase/src/cbft.cc +22 -27
  42. data/ext/libcouchbase/src/cntl.cc +56 -22
  43. data/ext/libcouchbase/src/connspec.cc +47 -6
  44. data/ext/libcouchbase/src/connspec.h +27 -0
  45. data/ext/libcouchbase/src/dns-srv.cc +147 -0
  46. data/ext/libcouchbase/src/dump.cc +3 -3
  47. data/ext/libcouchbase/src/errmap.cc +173 -0
  48. data/ext/libcouchbase/src/errmap.h +198 -0
  49. data/ext/libcouchbase/src/getconfig.cc +7 -33
  50. data/ext/libcouchbase/src/handler.cc +118 -7
  51. data/ext/libcouchbase/src/hostlist.cc +0 -36
  52. data/ext/libcouchbase/src/hostlist.h +44 -62
  53. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  54. data/ext/libcouchbase/src/http/http.cc +27 -35
  55. data/ext/libcouchbase/src/http/http.h +1 -34
  56. data/ext/libcouchbase/src/http/http_io.cc +28 -36
  57. data/ext/libcouchbase/src/instance.cc +131 -34
  58. data/ext/libcouchbase/src/internal.h +58 -26
  59. data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
  60. data/ext/libcouchbase/src/jsparse/parser.h +84 -98
  61. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  62. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  63. data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
  64. data/ext/libcouchbase/src/lcbio/connect.h +16 -7
  65. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  66. data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
  67. data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
  68. data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
  69. data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
  70. data/ext/libcouchbase/src/lcbio/manager.h +133 -96
  71. data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
  72. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  73. data/ext/libcouchbase/src/mc/mcreq.c +11 -2
  74. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  75. data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
  76. data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
  77. data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
  78. data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
  79. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  80. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  81. data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
  82. data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
  83. data/ext/libcouchbase/src/newconfig.cc +6 -6
  84. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  85. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  86. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  87. data/ext/libcouchbase/src/operations/durability.cc +6 -26
  88. data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
  89. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  90. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
  91. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  92. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  93. data/ext/libcouchbase/src/operations/stats.cc +3 -8
  94. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  95. data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
  96. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  97. data/ext/libcouchbase/src/packetutils.h +30 -2
  98. data/ext/libcouchbase/src/probes.d +1 -1
  99. data/ext/libcouchbase/src/rdb/rope.c +1 -1
  100. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
  101. data/ext/libcouchbase/src/retryq.cc +52 -14
  102. data/ext/libcouchbase/src/retryq.h +3 -3
  103. data/ext/libcouchbase/src/settings.c +5 -0
  104. data/ext/libcouchbase/src/settings.h +11 -0
  105. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  106. data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
  107. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  108. data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
  109. data/ext/libcouchbase/src/trace.h +4 -4
  110. data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
  111. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  112. data/ext/libcouchbase/src/views/docreq.h +24 -30
  113. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  114. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  115. data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
  116. data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
  117. data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
  118. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
  119. data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
  120. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
  121. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  122. data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
  123. data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
  124. data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
  125. data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
  126. data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
  127. data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
  128. data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
  129. data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
  130. data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
  131. data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
  132. data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
  133. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
  134. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
  135. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  136. data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
  137. data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
  138. data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
  139. data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
  140. data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
  141. data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
  142. data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
  143. data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
  144. data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
  145. data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
  146. data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
  147. data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
  148. data/ext/libcouchbase/tools/cbc.cc +143 -10
  149. data/ext/libcouchbase/tools/docgen/loc.h +1 -1
  150. data/lib/libcouchbase/connection.rb +4 -3
  151. data/lib/libcouchbase/version.rb +1 -1
  152. metadata +37 -28
  153. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  154. data/ext/libcouchbase/src/bootstrap.c +0 -269
  155. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  156. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  157. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  158. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  159. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  160. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  161. data/ext/libcouchbase/src/lcbio/manager.c +0 -584
  162. data/ext/libcouchbase/src/packetutils.c +0 -37
  163. data/ext/libcouchbase/src/simplestring.c +0 -211
  164. data/ext/libcouchbase/src/simplestring.h +0 -228
  165. data/ext/libcouchbase/src/ssobuf.h +0 -82
  166. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  167. data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -8,8 +8,13 @@
8
8
  class JsonParseTest : public ::testing::Test {
9
9
  };
10
10
 
11
+ using namespace lcb::jsparse;
11
12
 
12
- struct Context {
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
- void reset() {
35
- if (inner != NULL) {
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
- operator lcbjsp_PARSER* () {
48
- return inner;
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 std::string iov2s(const lcb_IOV& iov) {
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.getInner()->callback = rowCallback;
91
- parser.getInner()->data = &cx;
47
+ Parser parser(mode, &cx);
92
48
 
93
49
  for (size_t ii = 0; ii < ntxt; ii++) {
94
- lcbjsp_feed(parser, txt + ii, 1);
50
+ parser.feed(txt + ii, 1);
95
51
  }
96
52
  EXPECT_EQ(LCB_SUCCESS, cx.rc);
97
53
 
98
54
  lcb_IOV out;
99
- lcbjsp_get_postmortem(parser, &out);
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, int mode)
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.getInner()->callback = rowCallback;
111
- p.getInner()->data = &cx;
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), LCBJSP_MODE_FTS));
129
- ASSERT_TRUE(validateBadParse(JSON_fts_bad, sizeof(JSON_fts_bad), LCBJSP_MODE_FTS));
130
- ASSERT_TRUE(validateBadParse(JSON_fts_bad2, sizeof(JSON_fts_bad2), LCBJSP_MODE_FTS));
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), LCBJSP_MODE_N1QL));
135
- ASSERT_TRUE(validateJsonRows(JSON_n1ql_empty, sizeof(JSON_n1ql_empty), LCBJSP_MODE_N1QL));
136
- ASSERT_TRUE(validateBadParse(JSON_n1ql_bad, sizeof(JSON_n1ql_bad), LCBJSP_MODE_N1QL));
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
  }
@@ -20,5 +20,5 @@ TEST_F(MiscTests, testGetTmpdir)
20
20
  ASSERT_STRNE("", tmpdir);
21
21
  }
22
22
  TEST_F(MiscTests, testVersionG) {
23
- ASSERT_GT(lcb_version_g, 0);
23
+ ASSERT_GT(lcb_version_g, (lcb_U32)0);
24
24
  }
@@ -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
- lcbht_pPARSER parser = lcbht_new(settings);
17
+ Parser *parser = new Parser(settings);
17
18
  ASSERT_FALSE(parser == NULL);
18
19
 
19
20
  // Feed the parser some stuff
20
- lcbht_RESPSTATE state;
21
+ unsigned state;
21
22
 
22
23
  string buf;
23
24
  buf = "HTTP/1.0 200 OK\r\n";
24
25
 
25
- state = lcbht_parse(parser, buf.c_str(), buf.size());
26
+ state = parser->parse(buf.c_str(), buf.size());
26
27
  ASSERT_EQ(0, state);
27
28
 
28
29
  buf = "Connec";
29
- state = lcbht_parse(parser, buf.c_str(), buf.size());
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 = lcbht_parse(parser, buf.c_str(), buf.size());
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 = lcbht_parse(parser, buf.c_str(), buf.size());
36
- ASSERT_EQ(LCBHT_S_HEADER|LCBHT_S_HTSTATUS, state);
36
+ state = parser->parse(buf.c_str(), buf.size());
37
+ ASSERT_EQ(Parser::S_HEADER|Parser::S_HTSTATUS, state);
37
38
 
38
- lcbht_RESPONSE *resp = lcbht_get_response(parser);
39
- ASSERT_EQ(200, resp->status);
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 = lcbht_parse(parser, buf.c_str(), buf.size());
44
- ASSERT_EQ(0, state & LCBHT_S_ERROR);
45
- ASSERT_STREQ("H", resp->body.base);
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 = lcbht_parse(parser, buf.c_str(), buf.size());
49
- ASSERT_NE(0, state & LCBHT_S_DONE);
50
- ASSERT_STREQ("Hello", resp->body.base);
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
- lcbht_pPARSER parser = lcbht_new(settings);
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
- lcbht_RESPSTATE state;
70
- state = lcbht_parse(parser, buf.c_str(), buf.size());
71
- ASSERT_NE(0, state & LCBHT_S_DONE);
69
+ unsigned state;
70
+ state = parser->parse(buf.c_str(), buf.size());
71
+ ASSERT_NE(0, state & Parser::S_DONE);
72
72
 
73
- lcbht_RESPONSE *resp = lcbht_get_response(parser);
73
+ Response &resp = parser->get_cur_response();
74
74
  // Now fine the header value stuff
75
- ASSERT_STREQ("keep-alive", lcbht_get_resphdr(resp, "Connection"));
76
- ASSERT_STREQ("dummy/1.0", lcbht_get_resphdr(resp, "X-Server"));
77
- ASSERT_STREQ("application/json", lcbht_get_resphdr(resp, "Content-Type"));
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
- lcbht_pPARSER parser = lcbht_new(settings);
85
+ Parser *parser = new Parser(settings);
103
86
 
104
87
  string buf = "blahblahblah";
105
- lcbht_RESPSTATE state = lcbht_parse(parser, buf.c_str(), buf.size());
106
- ASSERT_NE(0, state & LCBHT_S_ERROR);
107
- lcbht_free(parser);
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
- lcbht_pPARSER parser = lcbht_new(settings);
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
- lcbht_RESPSTATE state;
126
- state = lcbht_parse_ex(parser, buf.c_str(), buf.size(), &nused, &nbody, &body);
127
- ASSERT_EQ(0, state & LCBHT_S_ERROR);
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 = lcbht_get_response(parser);
114
+ Response& resp = parser->get_cur_response();
133
115
  buf = "\r\nHello";
134
116
  // Feed the buffer
135
- state = lcbht_parse_ex(parser, buf.c_str(), buf.size(), &nused, &nbody, &body);
136
- ASSERT_EQ(0, state & LCBHT_S_DONE);
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 = lcbht_parse_ex(parser, buf.c_str()+off, buf.size()-off, &nused, &nbody, &body);
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 & LCBHT_S_DONE);
150
- ASSERT_EQ(0, state & LCBHT_S_ERROR);
151
- ASSERT_EQ(0, resp->body.nused);
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
- lcbht_pPARSER parser = lcbht_new(settings);
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
- lcbht_RESPSTATE state;
165
- state = lcbht_parse(parser, buf.c_str(), buf.size());
166
- ASSERT_NE(0, state & LCBHT_S_DONE);
167
- ASSERT_EQ(0, state & LCBHT_S_ERROR);
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
- lcbht_reset(parser);
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 = lcbht_parse(parser, buf.c_str(), buf.size());
177
- ASSERT_NE(0, state & LCBHT_S_DONE);
178
- ASSERT_EQ(0, state & LCBHT_S_ERROR);
179
- ASSERT_EQ(0, lcbht_can_keepalive(parser));
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
- lcbht_reset(parser);
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 = lcbht_parse(parser, buf.c_str(), buf.size());
187
- ASSERT_NE(0, state & LCBHT_S_DONE);
188
- ASSERT_EQ(0, state & LCBHT_S_ERROR);
189
- ASSERT_NE(0, lcbht_can_keepalive(parser));
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
- lcbht_free(parser);
171
+ delete parser;
192
172
  lcb_settings_unref(settings);
193
173
  }
@@ -37,7 +37,7 @@ TestConnection::sendData()
37
37
  void *outbuf;
38
38
  #endif
39
39
  size_t n = f_send->getBuf((void**)&outbuf);
40
- size_t nw = datasock->send(outbuf, n);
40
+ ssize_t nw = datasock->send(outbuf, n);
41
41
  if (nw < 0) {
42
42
  f_send->bail();
43
43
  } else {
@@ -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 (newsock == -1) {
25
- break;
26
- }
33
+ if (select(*lsn + 1, &fds, NULL, NULL, &tmout) == 1) {
34
+ int newsock = accept(*lsn, (struct sockaddr *)&newaddr, &naddr);
27
35
 
28
- TestConnection *newconn = new TestConnection(this, factory(newsock));
29
- startConnection(newconn);
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