libcouchbase 0.0.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.
Files changed (561) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +35 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +24 -0
  8. data/README.md +389 -0
  9. data/Rakefile +75 -0
  10. data/ext/README.md +6 -0
  11. data/ext/Rakefile +20 -0
  12. data/ext/libcouchbase/.gitignore +130 -0
  13. data/ext/libcouchbase/.travis.yml +19 -0
  14. data/ext/libcouchbase/CMakeLists.txt +429 -0
  15. data/ext/libcouchbase/CONTRIBUTING.md +124 -0
  16. data/ext/libcouchbase/LICENSE +202 -0
  17. data/ext/libcouchbase/README.markdown +163 -0
  18. data/ext/libcouchbase/RELEASE_NOTES.markdown +2691 -0
  19. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +27 -0
  20. data/ext/libcouchbase/cmake/Modules/CopyPDB.cmake +42 -0
  21. data/ext/libcouchbase/cmake/Modules/DistScript.cmake +17 -0
  22. data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +20 -0
  23. data/ext/libcouchbase/cmake/Modules/FindCouchbaseHdrHistogram.cmake +15 -0
  24. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibev.cmake +73 -0
  25. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +52 -0
  26. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +56 -0
  27. data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +11 -0
  28. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +29 -0
  29. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +133 -0
  30. data/ext/libcouchbase/cmake/Modules/GetPlatformCCInfo.cmake +45 -0
  31. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +70 -0
  32. data/ext/libcouchbase/cmake/config-cmake.h.in +60 -0
  33. data/ext/libcouchbase/cmake/configure +357 -0
  34. data/ext/libcouchbase/cmake/defs.mk.in +8 -0
  35. data/ext/libcouchbase/cmake/dtrace-instr-link.pl +38 -0
  36. data/ext/libcouchbase/cmake/source_files.cmake +73 -0
  37. data/ext/libcouchbase/configure.pl +1 -0
  38. data/ext/libcouchbase/contrib/cJSON/cJSON.c +624 -0
  39. data/ext/libcouchbase/contrib/cJSON/cJSON.h +158 -0
  40. data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +9 -0
  41. data/ext/libcouchbase/contrib/cbsasl/COPYING +202 -0
  42. data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +217 -0
  43. data/ext/libcouchbase/contrib/cbsasl/src/client.c +205 -0
  44. data/ext/libcouchbase/contrib/cbsasl/src/common.c +46 -0
  45. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.c +67 -0
  46. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.h +33 -0
  47. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.c +296 -0
  48. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.h +45 -0
  49. data/ext/libcouchbase/contrib/cbsasl/src/hash.c +573 -0
  50. data/ext/libcouchbase/contrib/cbsasl/src/hash.h +15 -0
  51. data/ext/libcouchbase/contrib/cbsasl/src/util.h +31 -0
  52. data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +2 -0
  53. data/ext/libcouchbase/contrib/cliopts/cliopts.c +747 -0
  54. data/ext/libcouchbase/contrib/cliopts/cliopts.h +493 -0
  55. data/ext/libcouchbase/contrib/genhash/genhash.c +372 -0
  56. data/ext/libcouchbase/contrib/genhash/genhash.h +235 -0
  57. data/ext/libcouchbase/contrib/gtest-1.7.0/CHANGES +157 -0
  58. data/ext/libcouchbase/contrib/gtest-1.7.0/CMakeLists.txt +252 -0
  59. data/ext/libcouchbase/contrib/gtest-1.7.0/CONTRIBUTORS +37 -0
  60. data/ext/libcouchbase/contrib/gtest-1.7.0/LICENSE +28 -0
  61. data/ext/libcouchbase/contrib/gtest-1.7.0/MINIFY.sh +15 -0
  62. data/ext/libcouchbase/contrib/gtest-1.7.0/README +435 -0
  63. data/ext/libcouchbase/contrib/gtest-1.7.0/cmake/internal_utils.cmake +227 -0
  64. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-death-test.h +294 -0
  65. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-message.h +250 -0
  66. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h +1421 -0
  67. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h.pump +487 -0
  68. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-printers.h +855 -0
  69. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-spi.h +232 -0
  70. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-test-part.h +179 -0
  71. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-typed-test.h +259 -0
  72. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest.h +2291 -0
  73. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_pred_impl.h +358 -0
  74. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_prod.h +58 -0
  75. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-death-test-internal.h +319 -0
  76. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-filepath.h +206 -0
  77. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-internal.h +1158 -0
  78. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-linked_ptr.h +233 -0
  79. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h +5143 -0
  80. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  81. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util.h +619 -0
  82. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-port.h +1947 -0
  83. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-string.h +167 -0
  84. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h +1012 -0
  85. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h.pump +339 -0
  86. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h +3331 -0
  87. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump +297 -0
  88. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-all.cc +48 -0
  89. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-death-test.cc +1344 -0
  90. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-filepath.cc +382 -0
  91. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-internal-inl.h +1218 -0
  92. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-port.cc +805 -0
  93. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-printers.cc +363 -0
  94. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-test-part.cc +110 -0
  95. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-typed-test.cc +110 -0
  96. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest.cc +5015 -0
  97. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest_main.cc +38 -0
  98. data/ext/libcouchbase/contrib/http_parser/LICENSE-MIT +23 -0
  99. data/ext/libcouchbase/contrib/http_parser/README.md +178 -0
  100. data/ext/libcouchbase/contrib/http_parser/http_parser.c +2060 -0
  101. data/ext/libcouchbase/contrib/http_parser/http_parser.h +321 -0
  102. data/ext/libcouchbase/contrib/jsonsl/LICENSE +20 -0
  103. data/ext/libcouchbase/contrib/jsonsl/jsonsl.c +1452 -0
  104. data/ext/libcouchbase/contrib/jsonsl/jsonsl.h +971 -0
  105. data/ext/libcouchbase/contrib/lcb-jsoncpp/CMakeLists.txt +6 -0
  106. data/ext/libcouchbase/contrib/lcb-jsoncpp/LICENSE +55 -0
  107. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp-forwards.h +255 -0
  108. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +4892 -0
  109. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.h +1961 -0
  110. data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +8 -0
  111. data/ext/libcouchbase/contrib/snappy/COPYING +28 -0
  112. data/ext/libcouchbase/contrib/snappy/snappy-c.cc +90 -0
  113. data/ext/libcouchbase/contrib/snappy/snappy-c.h +138 -0
  114. data/ext/libcouchbase/contrib/snappy/snappy-internal.h +150 -0
  115. data/ext/libcouchbase/contrib/snappy/snappy-lcb-msvc.h +5 -0
  116. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +71 -0
  117. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.h +137 -0
  118. data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.cc +42 -0
  119. data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.h +491 -0
  120. data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +98 -0
  121. data/ext/libcouchbase/contrib/snappy/snappy.cc +1307 -0
  122. data/ext/libcouchbase/contrib/snappy/snappy.h +184 -0
  123. data/ext/libcouchbase/contrib/win32-defs/iocpdefs.h +133 -0
  124. data/ext/libcouchbase/contrib/win32-defs/mingwdefs.h +4396 -0
  125. data/ext/libcouchbase/contrib/win32-defs/win_stdint.h +258 -0
  126. data/ext/libcouchbase/example/CMakeLists.txt +37 -0
  127. data/ext/libcouchbase/example/README.markdown +47 -0
  128. data/ext/libcouchbase/example/db/db.c +167 -0
  129. data/ext/libcouchbase/example/db/vb.c +227 -0
  130. data/ext/libcouchbase/example/instancepool/main.cc +102 -0
  131. data/ext/libcouchbase/example/instancepool/pool.cc +102 -0
  132. data/ext/libcouchbase/example/instancepool/pool.h +69 -0
  133. data/ext/libcouchbase/example/libeventdirect/main.c +148 -0
  134. data/ext/libcouchbase/example/mcc/mcc.cc +246 -0
  135. data/ext/libcouchbase/example/minimal/minimal.c +130 -0
  136. data/ext/libcouchbase/example/observe/observe.c +146 -0
  137. data/ext/libcouchbase/example/subdoc/subdoc-multi.cc +132 -0
  138. data/ext/libcouchbase/example/subdoc/subdoc-simple.cc +191 -0
  139. data/ext/libcouchbase/example/tick/tick.c +119 -0
  140. data/ext/libcouchbase/example/views/views-example.cc +83 -0
  141. data/ext/libcouchbase/include/libcouchbase/_cxxwrap.h +150 -0
  142. data/ext/libcouchbase/include/libcouchbase/api-legacy.h +1689 -0
  143. data/ext/libcouchbase/include/libcouchbase/api3.h +2 -0
  144. data/ext/libcouchbase/include/libcouchbase/assert.h +44 -0
  145. data/ext/libcouchbase/include/libcouchbase/cbft.h +109 -0
  146. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +356 -0
  147. data/ext/libcouchbase/include/libcouchbase/cntl.h +937 -0
  148. data/ext/libcouchbase/include/libcouchbase/configuration.h.in +23 -0
  149. data/ext/libcouchbase/include/libcouchbase/couchbase.h +3677 -0
  150. data/ext/libcouchbase/include/libcouchbase/deprecated.h +300 -0
  151. data/ext/libcouchbase/include/libcouchbase/error.h +595 -0
  152. data/ext/libcouchbase/include/libcouchbase/http.h +1 -0
  153. data/ext/libcouchbase/include/libcouchbase/iops.h +1050 -0
  154. data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +263 -0
  155. data/ext/libcouchbase/include/libcouchbase/kvbuf.h +132 -0
  156. data/ext/libcouchbase/include/libcouchbase/n1ql.h +364 -0
  157. data/ext/libcouchbase/include/libcouchbase/pktfwd.h +270 -0
  158. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +367 -0
  159. data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr-inl.c +76 -0
  160. data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr.h +199 -0
  161. data/ext/libcouchbase/include/libcouchbase/subdoc.h +312 -0
  162. data/ext/libcouchbase/include/libcouchbase/sysdefs.h +98 -0
  163. data/ext/libcouchbase/include/libcouchbase/vbucket.h +643 -0
  164. data/ext/libcouchbase/include/libcouchbase/views.h +298 -0
  165. data/ext/libcouchbase/include/libcouchbase/visibility.h +65 -0
  166. data/ext/libcouchbase/include/memcached/COPYING +30 -0
  167. data/ext/libcouchbase/include/memcached/README +10 -0
  168. data/ext/libcouchbase/include/memcached/protocol_binary.h +1916 -0
  169. data/ext/libcouchbase/include/memcached/vbucket.h +42 -0
  170. data/ext/libcouchbase/packaging/README +7 -0
  171. data/ext/libcouchbase/packaging/abicheck/.gitignore +4 -0
  172. data/ext/libcouchbase/packaging/abicheck/Makefile +17 -0
  173. data/ext/libcouchbase/packaging/abicheck/README.md +27 -0
  174. data/ext/libcouchbase/packaging/abicheck/template.xml +3 -0
  175. data/ext/libcouchbase/packaging/deb/compat +1 -0
  176. data/ext/libcouchbase/packaging/deb/control +73 -0
  177. data/ext/libcouchbase/packaging/deb/copyright +10 -0
  178. data/ext/libcouchbase/packaging/deb/libcouchbase-dev.docs +3 -0
  179. data/ext/libcouchbase/packaging/deb/package.mk +31 -0
  180. data/ext/libcouchbase/packaging/deb/rules +46 -0
  181. data/ext/libcouchbase/packaging/deb/source/format +1 -0
  182. data/ext/libcouchbase/packaging/distinfo/README +1 -0
  183. data/ext/libcouchbase/packaging/distinfo/distinfo.cmake.in +4 -0
  184. data/ext/libcouchbase/packaging/dllversion.rc.in +39 -0
  185. data/ext/libcouchbase/packaging/libcouchbase.pc.in +10 -0
  186. data/ext/libcouchbase/packaging/nuget/libcouchbase.autopkg +76 -0
  187. data/ext/libcouchbase/packaging/parse-git-describe.pl +166 -0
  188. data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +108 -0
  189. data/ext/libcouchbase/packaging/rpm/package.mk +40 -0
  190. data/ext/libcouchbase/plugins/io/iocp/CMakeLists.txt +9 -0
  191. data/ext/libcouchbase/plugins/io/iocp/iocp_iops.c +466 -0
  192. data/ext/libcouchbase/plugins/io/iocp/iocp_iops.h +217 -0
  193. data/ext/libcouchbase/plugins/io/iocp/iocp_loop.c +295 -0
  194. data/ext/libcouchbase/plugins/io/iocp/iocp_timer.c +79 -0
  195. data/ext/libcouchbase/plugins/io/iocp/iocp_util.c +229 -0
  196. data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +29 -0
  197. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +65 -0
  198. data/ext/libcouchbase/plugins/io/libev/plugin-libev.c +289 -0
  199. data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +29 -0
  200. data/ext/libcouchbase/plugins/io/libevent/libevent_io_opts.h +67 -0
  201. data/ext/libcouchbase/plugins/io/libevent/plugin-libevent.c +292 -0
  202. data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +42 -0
  203. data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +212 -0
  204. data/ext/libcouchbase/plugins/io/libuv/libuv_io_opts.h +118 -0
  205. data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +148 -0
  206. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +648 -0
  207. data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +11 -0
  208. data/ext/libcouchbase/plugins/io/select/plugin-select.c +448 -0
  209. data/ext/libcouchbase/plugins/io/select/select_io_opts.h +39 -0
  210. data/ext/libcouchbase/src/README.md +103 -0
  211. data/ext/libcouchbase/src/aspend.h +106 -0
  212. data/ext/libcouchbase/src/auth.cc +74 -0
  213. data/ext/libcouchbase/src/auth.h +54 -0
  214. data/ext/libcouchbase/src/bootstrap.c +269 -0
  215. data/ext/libcouchbase/src/bootstrap.h +129 -0
  216. data/ext/libcouchbase/src/bucketconfig/bc_cccp.c +495 -0
  217. data/ext/libcouchbase/src/bucketconfig/bc_file.c +347 -0
  218. data/ext/libcouchbase/src/bucketconfig/bc_http.c +630 -0
  219. data/ext/libcouchbase/src/bucketconfig/bc_http.h +82 -0
  220. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +150 -0
  221. data/ext/libcouchbase/src/bucketconfig/clconfig.h +681 -0
  222. data/ext/libcouchbase/src/bucketconfig/confmon.c +474 -0
  223. data/ext/libcouchbase/src/callbacks.c +378 -0
  224. data/ext/libcouchbase/src/cbft.cc +210 -0
  225. data/ext/libcouchbase/src/cntl.cc +847 -0
  226. data/ext/libcouchbase/src/config_static.h +159 -0
  227. data/ext/libcouchbase/src/connspec.cc +462 -0
  228. data/ext/libcouchbase/src/connspec.h +105 -0
  229. data/ext/libcouchbase/src/ctx-log-inl.h +27 -0
  230. data/ext/libcouchbase/src/dump.c +98 -0
  231. data/ext/libcouchbase/src/getconfig.c +100 -0
  232. data/ext/libcouchbase/src/gethrtime.c +109 -0
  233. data/ext/libcouchbase/src/handler.c +922 -0
  234. data/ext/libcouchbase/src/hashset.c +164 -0
  235. data/ext/libcouchbase/src/hashset.h +86 -0
  236. data/ext/libcouchbase/src/hashtable.c +75 -0
  237. data/ext/libcouchbase/src/hdr_timings.c +92 -0
  238. data/ext/libcouchbase/src/hostlist.cc +301 -0
  239. data/ext/libcouchbase/src/hostlist.h +171 -0
  240. data/ext/libcouchbase/src/http/http-priv.h +307 -0
  241. data/ext/libcouchbase/src/http/http.cc +633 -0
  242. data/ext/libcouchbase/src/http/http.h +34 -0
  243. data/ext/libcouchbase/src/http/http_io.cc +307 -0
  244. data/ext/libcouchbase/src/instance.cc +722 -0
  245. data/ext/libcouchbase/src/internal.h +244 -0
  246. data/ext/libcouchbase/src/iofactory.c +575 -0
  247. data/ext/libcouchbase/src/jsparse/parser.cc +519 -0
  248. data/ext/libcouchbase/src/jsparse/parser.h +173 -0
  249. data/ext/libcouchbase/src/lcbht/lcbht.c +282 -0
  250. data/ext/libcouchbase/src/lcbht/lcbht.h +199 -0
  251. data/ext/libcouchbase/src/lcbio/connect.c +557 -0
  252. data/ext/libcouchbase/src/lcbio/connect.h +364 -0
  253. data/ext/libcouchbase/src/lcbio/ctx.c +611 -0
  254. data/ext/libcouchbase/src/lcbio/ctx.h +405 -0
  255. data/ext/libcouchbase/src/lcbio/iotable.c +290 -0
  256. data/ext/libcouchbase/src/lcbio/iotable.h +84 -0
  257. data/ext/libcouchbase/src/lcbio/ioutils.c +350 -0
  258. data/ext/libcouchbase/src/lcbio/ioutils.h +203 -0
  259. data/ext/libcouchbase/src/lcbio/lcbio.h +51 -0
  260. data/ext/libcouchbase/src/lcbio/manager.c +584 -0
  261. data/ext/libcouchbase/src/lcbio/manager.h +156 -0
  262. data/ext/libcouchbase/src/lcbio/protoctx.c +84 -0
  263. data/ext/libcouchbase/src/lcbio/rw-inl.h +115 -0
  264. data/ext/libcouchbase/src/lcbio/ssl.h +149 -0
  265. data/ext/libcouchbase/src/lcbio/timer-ng.h +179 -0
  266. data/ext/libcouchbase/src/lcbio/timer.c +132 -0
  267. data/ext/libcouchbase/src/legacy.c +430 -0
  268. data/ext/libcouchbase/src/list.c +144 -0
  269. data/ext/libcouchbase/src/list.h +127 -0
  270. data/ext/libcouchbase/src/logging.c +244 -0
  271. data/ext/libcouchbase/src/logging.h +86 -0
  272. data/ext/libcouchbase/src/mc/compress.c +90 -0
  273. data/ext/libcouchbase/src/mc/compress.h +61 -0
  274. data/ext/libcouchbase/src/mc/forward.c +186 -0
  275. data/ext/libcouchbase/src/mc/forward.h +90 -0
  276. data/ext/libcouchbase/src/mc/iovcursor-inl.h +279 -0
  277. data/ext/libcouchbase/src/mc/iovcursor.h +66 -0
  278. data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +111 -0
  279. data/ext/libcouchbase/src/mc/mcreq.c +954 -0
  280. data/ext/libcouchbase/src/mc/mcreq.h +977 -0
  281. data/ext/libcouchbase/src/mcserver/mcserver.c +784 -0
  282. data/ext/libcouchbase/src/mcserver/mcserver.h +121 -0
  283. data/ext/libcouchbase/src/mcserver/negotiate.c +656 -0
  284. data/ext/libcouchbase/src/mcserver/negotiate.h +119 -0
  285. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +860 -0
  286. data/ext/libcouchbase/src/n1ql/n1ql-internal.h +22 -0
  287. data/ext/libcouchbase/src/n1ql/n1ql.cc +729 -0
  288. data/ext/libcouchbase/src/n1ql/params.cc +215 -0
  289. data/ext/libcouchbase/src/netbuf/netbuf-defs.h +89 -0
  290. data/ext/libcouchbase/src/netbuf/netbuf-mblock.h +235 -0
  291. data/ext/libcouchbase/src/netbuf/netbuf.c +929 -0
  292. data/ext/libcouchbase/src/netbuf/netbuf.h +452 -0
  293. data/ext/libcouchbase/src/newconfig.c +385 -0
  294. data/ext/libcouchbase/src/nodeinfo.cc +194 -0
  295. data/ext/libcouchbase/src/operations/cbflush.c +71 -0
  296. data/ext/libcouchbase/src/operations/counter.c +116 -0
  297. data/ext/libcouchbase/src/operations/durability-cas.c +224 -0
  298. data/ext/libcouchbase/src/operations/durability-seqno.c +157 -0
  299. data/ext/libcouchbase/src/operations/durability.c +668 -0
  300. data/ext/libcouchbase/src/operations/durability_internal.h +199 -0
  301. data/ext/libcouchbase/src/operations/get.c +409 -0
  302. data/ext/libcouchbase/src/operations/observe-seqno.c +96 -0
  303. data/ext/libcouchbase/src/operations/observe.c +340 -0
  304. data/ext/libcouchbase/src/operations/pktfwd.c +86 -0
  305. data/ext/libcouchbase/src/operations/remove.c +83 -0
  306. data/ext/libcouchbase/src/operations/stats.c +461 -0
  307. data/ext/libcouchbase/src/operations/store.c +360 -0
  308. data/ext/libcouchbase/src/operations/subdoc.cc +510 -0
  309. data/ext/libcouchbase/src/operations/touch.c +81 -0
  310. data/ext/libcouchbase/src/packetutils.c +60 -0
  311. data/ext/libcouchbase/src/packetutils.h +147 -0
  312. data/ext/libcouchbase/src/probes.d +211 -0
  313. data/ext/libcouchbase/src/rdb/bigalloc.c +225 -0
  314. data/ext/libcouchbase/src/rdb/bigalloc.h +73 -0
  315. data/ext/libcouchbase/src/rdb/chunkalloc.c +174 -0
  316. data/ext/libcouchbase/src/rdb/libcalloc.c +94 -0
  317. data/ext/libcouchbase/src/rdb/rope.c +419 -0
  318. data/ext/libcouchbase/src/rdb/rope.h +488 -0
  319. data/ext/libcouchbase/src/retrychk.c +113 -0
  320. data/ext/libcouchbase/src/retryq.c +424 -0
  321. data/ext/libcouchbase/src/retryq.h +157 -0
  322. data/ext/libcouchbase/src/ringbuffer.c +442 -0
  323. data/ext/libcouchbase/src/ringbuffer.h +100 -0
  324. data/ext/libcouchbase/src/settings.c +95 -0
  325. data/ext/libcouchbase/src/settings.h +188 -0
  326. data/ext/libcouchbase/src/simplestring.c +211 -0
  327. data/ext/libcouchbase/src/simplestring.h +228 -0
  328. data/ext/libcouchbase/src/sllist-inl.h +197 -0
  329. data/ext/libcouchbase/src/sllist.h +76 -0
  330. data/ext/libcouchbase/src/ssl/CMakeLists.txt +23 -0
  331. data/ext/libcouchbase/src/ssl/ssl_c.c +415 -0
  332. data/ext/libcouchbase/src/ssl/ssl_common.c +454 -0
  333. data/ext/libcouchbase/src/ssl/ssl_e.c +408 -0
  334. data/ext/libcouchbase/src/ssl/ssl_iot_common.h +180 -0
  335. data/ext/libcouchbase/src/ssobuf.h +82 -0
  336. data/ext/libcouchbase/src/strcodecs/base64.c +123 -0
  337. data/ext/libcouchbase/src/strcodecs/strcodecs.h +285 -0
  338. data/ext/libcouchbase/src/timings.c +208 -0
  339. data/ext/libcouchbase/src/trace.h +105 -0
  340. data/ext/libcouchbase/src/utilities.c +171 -0
  341. data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -0
  342. data/ext/libcouchbase/src/vbucket/aliases.h +35 -0
  343. data/ext/libcouchbase/src/vbucket/crc32.h +83 -0
  344. data/ext/libcouchbase/src/vbucket/hash.h +30 -0
  345. data/ext/libcouchbase/src/vbucket/json-inl.h +112 -0
  346. data/ext/libcouchbase/src/vbucket/ketama.c +66 -0
  347. data/ext/libcouchbase/src/vbucket/rfc1321/global.h +32 -0
  348. data/ext/libcouchbase/src/vbucket/rfc1321/md5.h +35 -0
  349. data/ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h +335 -0
  350. data/ext/libcouchbase/src/vbucket/vbucket.c +1543 -0
  351. data/ext/libcouchbase/src/views/docreq.c +194 -0
  352. data/ext/libcouchbase/src/views/docreq.h +83 -0
  353. data/ext/libcouchbase/src/views/viewreq.c +358 -0
  354. data/ext/libcouchbase/src/views/viewreq.h +36 -0
  355. data/ext/libcouchbase/src/wait.c +161 -0
  356. data/ext/libcouchbase/tests/CMakeLists.txt +140 -0
  357. data/ext/libcouchbase/tests/basic/t_base64.cc +81 -0
  358. data/ext/libcouchbase/tests/basic/t_ccbc103.cc +95 -0
  359. data/ext/libcouchbase/tests/basic/t_connstr.cc +404 -0
  360. data/ext/libcouchbase/tests/basic/t_creds.cc +32 -0
  361. data/ext/libcouchbase/tests/basic/t_ctlcodes.cc +92 -0
  362. data/ext/libcouchbase/tests/basic/t_hashset.cc +262 -0
  363. data/ext/libcouchbase/tests/basic/t_host.cc +198 -0
  364. data/ext/libcouchbase/tests/basic/t_jsparse.cc +137 -0
  365. data/ext/libcouchbase/tests/basic/t_jsparse.h +589 -0
  366. data/ext/libcouchbase/tests/basic/t_list.cc +155 -0
  367. data/ext/libcouchbase/tests/basic/t_logger.cc +65 -0
  368. data/ext/libcouchbase/tests/basic/t_misc.cc +24 -0
  369. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +18 -0
  370. data/ext/libcouchbase/tests/basic/t_netbuf.cc +446 -0
  371. data/ext/libcouchbase/tests/basic/t_packet.cc +222 -0
  372. data/ext/libcouchbase/tests/basic/t_ringbuffer.cc +278 -0
  373. data/ext/libcouchbase/tests/basic/t_slist.cc +429 -0
  374. data/ext/libcouchbase/tests/basic/t_strerror.cc +64 -0
  375. data/ext/libcouchbase/tests/basic/t_string.cc +112 -0
  376. data/ext/libcouchbase/tests/basic/t_urlencode.cc +132 -0
  377. data/ext/libcouchbase/tests/check-all.cc +608 -0
  378. data/ext/libcouchbase/tests/htparse/t_basic.cc +193 -0
  379. data/ext/libcouchbase/tests/ioserver/connection.cc +166 -0
  380. data/ext/libcouchbase/tests/ioserver/future.cc +50 -0
  381. data/ext/libcouchbase/tests/ioserver/ioserver.cc +104 -0
  382. data/ext/libcouchbase/tests/ioserver/ioserver.h +478 -0
  383. data/ext/libcouchbase/tests/ioserver/socket.cc +88 -0
  384. data/ext/libcouchbase/tests/ioserver/ssl_connection.cc +145 -0
  385. data/ext/libcouchbase/tests/ioserver/threads-pthreads.cc +119 -0
  386. data/ext/libcouchbase/tests/ioserver/threads-win32.cc +117 -0
  387. data/ext/libcouchbase/tests/ioserver/threads.h +66 -0
  388. data/ext/libcouchbase/tests/iotests/iotests.h +15 -0
  389. data/ext/libcouchbase/tests/iotests/mock-environment.cc +524 -0
  390. data/ext/libcouchbase/tests/iotests/mock-environment.h +385 -0
  391. data/ext/libcouchbase/tests/iotests/mock-unit-test.cc +67 -0
  392. data/ext/libcouchbase/tests/iotests/mock-unit-test.h +61 -0
  393. data/ext/libcouchbase/tests/iotests/serverparams.h +76 -0
  394. data/ext/libcouchbase/tests/iotests/t_arithmetic.cc +143 -0
  395. data/ext/libcouchbase/tests/iotests/t_behavior.cc +226 -0
  396. data/ext/libcouchbase/tests/iotests/t_configcache.cc +117 -0
  397. data/ext/libcouchbase/tests/iotests/t_confmon.cc +241 -0
  398. data/ext/libcouchbase/tests/iotests/t_durability.cc +1059 -0
  399. data/ext/libcouchbase/tests/iotests/t_forward.cc +110 -0
  400. data/ext/libcouchbase/tests/iotests/t_get.cc +512 -0
  401. data/ext/libcouchbase/tests/iotests/t_http.cc +438 -0
  402. data/ext/libcouchbase/tests/iotests/t_iops.cc +175 -0
  403. data/ext/libcouchbase/tests/iotests/t_lock.cc +275 -0
  404. data/ext/libcouchbase/tests/iotests/t_misc.cc +713 -0
  405. data/ext/libcouchbase/tests/iotests/t_mutate.cc +609 -0
  406. data/ext/libcouchbase/tests/iotests/t_n1ql.cc +270 -0
  407. data/ext/libcouchbase/tests/iotests/t_netfail.cc +654 -0
  408. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +157 -0
  409. data/ext/libcouchbase/tests/iotests/t_regression.cc +321 -0
  410. data/ext/libcouchbase/tests/iotests/t_sched.cc +88 -0
  411. data/ext/libcouchbase/tests/iotests/t_serverops.cc +230 -0
  412. data/ext/libcouchbase/tests/iotests/t_smoke.cc +528 -0
  413. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +822 -0
  414. data/ext/libcouchbase/tests/iotests/t_syncmode.cc +64 -0
  415. data/ext/libcouchbase/tests/iotests/t_views.cc +405 -0
  416. data/ext/libcouchbase/tests/iotests/testutil.cc +250 -0
  417. data/ext/libcouchbase/tests/iotests/testutil.h +163 -0
  418. data/ext/libcouchbase/tests/mc/mctest.h +119 -0
  419. data/ext/libcouchbase/tests/mc/pktmaker.h +101 -0
  420. data/ext/libcouchbase/tests/mc/t_alloc.cc +269 -0
  421. data/ext/libcouchbase/tests/mc/t_context.cc +100 -0
  422. data/ext/libcouchbase/tests/mc/t_flush.cc +185 -0
  423. data/ext/libcouchbase/tests/mc/t_forward.cc +239 -0
  424. data/ext/libcouchbase/tests/mc/t_ioflush.cc +102 -0
  425. data/ext/libcouchbase/tests/mc/t_iovcursor.cc +173 -0
  426. data/ext/libcouchbase/tests/mocksupport/procutil.c +305 -0
  427. data/ext/libcouchbase/tests/mocksupport/procutil.h +89 -0
  428. data/ext/libcouchbase/tests/mocksupport/server.c +391 -0
  429. data/ext/libcouchbase/tests/mocksupport/server.h +72 -0
  430. data/ext/libcouchbase/tests/mocksupport/timeout.c +69 -0
  431. data/ext/libcouchbase/tests/nonio_tests.cc +23 -0
  432. data/ext/libcouchbase/tests/rdb/rdbtest.h +133 -0
  433. data/ext/libcouchbase/tests/rdb/t_basic.cc +128 -0
  434. data/ext/libcouchbase/tests/rdb/t_bigalloc.cc +93 -0
  435. data/ext/libcouchbase/tests/rdb/t_refs.cc +112 -0
  436. data/ext/libcouchbase/tests/socktests/socktest.cc +347 -0
  437. data/ext/libcouchbase/tests/socktests/socktest.h +448 -0
  438. data/ext/libcouchbase/tests/socktests/t_basic.cc +143 -0
  439. data/ext/libcouchbase/tests/socktests/t_ctx.cc +73 -0
  440. data/ext/libcouchbase/tests/socktests/t_manager.cc +179 -0
  441. data/ext/libcouchbase/tests/socktests/t_putex.cc +256 -0
  442. data/ext/libcouchbase/tests/socktests/t_read.cc +187 -0
  443. data/ext/libcouchbase/tests/socktests/t_reentrant.cc +143 -0
  444. data/ext/libcouchbase/tests/socktests/t_ssl.cc +80 -0
  445. data/ext/libcouchbase/tests/socktests/t_write.cc +95 -0
  446. data/ext/libcouchbase/tests/start_mock.bat +15 -0
  447. data/ext/libcouchbase/tests/start_mock.sh +42 -0
  448. data/ext/libcouchbase/tests/unit_tests.cc +43 -0
  449. data/ext/libcouchbase/tests/vbucket/confdata/bad.json +101 -0
  450. data/ext/libcouchbase/tests/vbucket/confdata/full_25.json +363 -0
  451. data/ext/libcouchbase/tests/vbucket/confdata/memd_25.json +90 -0
  452. data/ext/libcouchbase/tests/vbucket/confdata/memd_30.json +1 -0
  453. data/ext/libcouchbase/tests/vbucket/confdata/memd_45.json +1 -0
  454. data/ext/libcouchbase/tests/vbucket/confdata/terse_25.json +291 -0
  455. data/ext/libcouchbase/tests/vbucket/confdata/terse_30.json +1 -0
  456. data/ext/libcouchbase/tests/vbucket/t_config.cc +341 -0
  457. data/ext/libcouchbase/tools/CMakeLists.txt +51 -0
  458. data/ext/libcouchbase/tools/cbc-handlers.h +462 -0
  459. data/ext/libcouchbase/tools/cbc-n1qlback.cc +439 -0
  460. data/ext/libcouchbase/tools/cbc-pillowfight.cc +822 -0
  461. data/ext/libcouchbase/tools/cbc.cc +1541 -0
  462. data/ext/libcouchbase/tools/common/histogram.cc +43 -0
  463. data/ext/libcouchbase/tools/common/histogram.h +23 -0
  464. data/ext/libcouchbase/tools/common/my_inttypes.h +22 -0
  465. data/ext/libcouchbase/tools/common/options.cc +420 -0
  466. data/ext/libcouchbase/tools/common/options.h +81 -0
  467. data/ext/libcouchbase/tools/docgen/docgen.h +469 -0
  468. data/ext/libcouchbase/tools/docgen/loc.h +210 -0
  469. data/ext/libcouchbase/tools/docgen/placeholders.h +211 -0
  470. data/ext/libcouchbase/tools/docgen/seqgen.h +94 -0
  471. data/lib/libcouchbase.rb +36 -0
  472. data/lib/libcouchbase/bucket.rb +819 -0
  473. data/lib/libcouchbase/callbacks.rb +72 -0
  474. data/lib/libcouchbase/connection.rb +790 -0
  475. data/lib/libcouchbase/design_docs.rb +86 -0
  476. data/lib/libcouchbase/error.rb +68 -0
  477. data/lib/libcouchbase/ext/libcouchbase.rb +1135 -0
  478. data/lib/libcouchbase/ext/libcouchbase/cmdbase.rb +23 -0
  479. data/lib/libcouchbase/ext/libcouchbase/cmdcounter.rb +36 -0
  480. data/lib/libcouchbase/ext/libcouchbase/cmdendure.rb +26 -0
  481. data/lib/libcouchbase/ext/libcouchbase/cmdfts.rb +24 -0
  482. data/lib/libcouchbase/ext/libcouchbase/cmdget.rb +30 -0
  483. data/lib/libcouchbase/ext/libcouchbase/cmdgetreplica.rb +49 -0
  484. data/lib/libcouchbase/ext/libcouchbase/cmdhttp.rb +58 -0
  485. data/lib/libcouchbase/ext/libcouchbase/cmdn1ql.rb +40 -0
  486. data/lib/libcouchbase/ext/libcouchbase/cmdobseqno.rb +33 -0
  487. data/lib/libcouchbase/ext/libcouchbase/cmdobserve.rb +30 -0
  488. data/lib/libcouchbase/ext/libcouchbase/cmdstore.rb +40 -0
  489. data/lib/libcouchbase/ext/libcouchbase/cmdstoredur.rb +45 -0
  490. data/lib/libcouchbase/ext/libcouchbase/cmdsubdoc.rb +49 -0
  491. data/lib/libcouchbase/ext/libcouchbase/cmdverbosity.rb +29 -0
  492. data/lib/libcouchbase/ext/libcouchbase/cmdviewquery.rb +61 -0
  493. data/lib/libcouchbase/ext/libcouchbase/contigbuf.rb +14 -0
  494. data/lib/libcouchbase/ext/libcouchbase/create_st.rb +15 -0
  495. data/lib/libcouchbase/ext/libcouchbase/create_st0.rb +23 -0
  496. data/lib/libcouchbase/ext/libcouchbase/create_st1.rb +26 -0
  497. data/lib/libcouchbase/ext/libcouchbase/create_st2.rb +32 -0
  498. data/lib/libcouchbase/ext/libcouchbase/create_st3.rb +26 -0
  499. data/lib/libcouchbase/ext/libcouchbase/crst_u.rb +20 -0
  500. data/lib/libcouchbase/ext/libcouchbase/durability_opts_st_v.rb +11 -0
  501. data/lib/libcouchbase/ext/libcouchbase/durability_opts_t.rb +14 -0
  502. data/lib/libcouchbase/ext/libcouchbase/durabilityopt_sv0.rb +63 -0
  503. data/lib/libcouchbase/ext/libcouchbase/enums.rb +991 -0
  504. data/lib/libcouchbase/ext/libcouchbase/fragbuf.rb +18 -0
  505. data/lib/libcouchbase/ext/libcouchbase/ftshandle.rb +7 -0
  506. data/lib/libcouchbase/ext/libcouchbase/histogram.rb +34 -0
  507. data/lib/libcouchbase/ext/libcouchbase/http_request_t.rb +7 -0
  508. data/lib/libcouchbase/ext/libcouchbase/keybuf.rb +20 -0
  509. data/lib/libcouchbase/ext/libcouchbase/multicmd_ctx.rb +30 -0
  510. data/lib/libcouchbase/ext/libcouchbase/mutation_token.rb +17 -0
  511. data/lib/libcouchbase/ext/libcouchbase/n1qlhandle.rb +7 -0
  512. data/lib/libcouchbase/ext/libcouchbase/n1qlparams.rb +7 -0
  513. data/lib/libcouchbase/ext/libcouchbase/respbase.rb +29 -0
  514. data/lib/libcouchbase/ext/libcouchbase/respcounter.rb +32 -0
  515. data/lib/libcouchbase/ext/libcouchbase/respendure.rb +49 -0
  516. data/lib/libcouchbase/ext/libcouchbase/respfts.rb +40 -0
  517. data/lib/libcouchbase/ext/libcouchbase/respget.rb +44 -0
  518. data/lib/libcouchbase/ext/libcouchbase/resphttp.rb +48 -0
  519. data/lib/libcouchbase/ext/libcouchbase/respmcversion.rb +38 -0
  520. data/lib/libcouchbase/ext/libcouchbase/respn1ql.rb +41 -0
  521. data/lib/libcouchbase/ext/libcouchbase/respobseqno.rb +52 -0
  522. data/lib/libcouchbase/ext/libcouchbase/respobserve.rb +41 -0
  523. data/lib/libcouchbase/ext/libcouchbase/respserverbase.rb +32 -0
  524. data/lib/libcouchbase/ext/libcouchbase/respstats.rb +38 -0
  525. data/lib/libcouchbase/ext/libcouchbase/respstore.rb +32 -0
  526. data/lib/libcouchbase/ext/libcouchbase/respstoredur.rb +38 -0
  527. data/lib/libcouchbase/ext/libcouchbase/respsubdoc.rb +35 -0
  528. data/lib/libcouchbase/ext/libcouchbase/respviewquery.rb +67 -0
  529. data/lib/libcouchbase/ext/libcouchbase/sdentry.rb +22 -0
  530. data/lib/libcouchbase/ext/libcouchbase/sdspec.rb +26 -0
  531. data/lib/libcouchbase/ext/libcouchbase/t.rb +7 -0
  532. data/lib/libcouchbase/ext/libcouchbase/valbuf.rb +22 -0
  533. data/lib/libcouchbase/ext/libcouchbase/valbuf_u_buf.rb +14 -0
  534. data/lib/libcouchbase/ext/libcouchbase/viewhandle.rb +7 -0
  535. data/lib/libcouchbase/ext/libcouchbase_iocp.rb +26 -0
  536. data/lib/libcouchbase/ext/libcouchbase_libuv.rb +18 -0
  537. data/lib/libcouchbase/ext/tasks.rb +87 -0
  538. data/lib/libcouchbase/n1ql.rb +73 -0
  539. data/lib/libcouchbase/query_full_text.rb +147 -0
  540. data/lib/libcouchbase/query_n1ql.rb +121 -0
  541. data/lib/libcouchbase/query_view.rb +129 -0
  542. data/lib/libcouchbase/results_fiber.rb +262 -0
  543. data/lib/libcouchbase/results_native.rb +211 -0
  544. data/lib/libcouchbase/version.rb +5 -0
  545. data/libcouchbase.gemspec +61 -0
  546. data/spec/bucket_spec.rb +270 -0
  547. data/spec/connection_spec.rb +277 -0
  548. data/spec/design_docs_spec.rb +23 -0
  549. data/spec/error_spec.rb +26 -0
  550. data/spec/fts_spec.rb +129 -0
  551. data/spec/n1ql_spec.rb +201 -0
  552. data/spec/results_libuv_spec.rb +229 -0
  553. data/spec/results_native_spec.rb +259 -0
  554. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
  555. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
  556. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
  557. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
  558. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
  559. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
  560. data/spec/view_spec.rb +195 -0
  561. metadata +775 -0
@@ -0,0 +1,347 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2013 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include "internal.h"
19
+ #include "clconfig.h"
20
+ #include "simplestring.h"
21
+ #include <lcbio/lcbio.h>
22
+ #include <lcbio/timer-ng.h>
23
+
24
+ #define CONFIG_CACHE_MAGIC "{{{fb85b563d0a8f65fa8d3d58f1b3a0708}}}"
25
+
26
+ #define LOGARGS(pb, lvl) pb->base.parent->settings, "bc_file", LCB_LOG_##lvl, __FILE__, __LINE__
27
+ #define LOGFMT "(cache=%s) "
28
+ #define LOGID(fb) fb->filename
29
+
30
+ typedef struct {
31
+ clconfig_provider base;
32
+ char *filename;
33
+ clconfig_info *config;
34
+ time_t last_mtime;
35
+ int last_errno;
36
+ int ro_mode; /* Whether the config cache should _not_ overwrite the file */
37
+ lcbio_pTIMER timer;
38
+ clconfig_listener listener;
39
+ } file_provider;
40
+
41
+ static int load_cache(file_provider *provider)
42
+ {
43
+ lcb_string str;
44
+ char line[1024];
45
+ lcb_ssize_t nr;
46
+ int fail;
47
+ FILE *fp = NULL;
48
+ lcbvb_CONFIG *config = NULL;
49
+ char *end;
50
+ struct stat st;
51
+ int status = -1;
52
+
53
+ lcb_string_init(&str);
54
+
55
+ if (provider->filename == NULL) {
56
+ return -1;
57
+ }
58
+
59
+ fp = fopen(provider->filename, "r");
60
+ if (fp == NULL) {
61
+ int save_errno = errno;
62
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't open for reading: %s", LOGID(provider), strerror(save_errno));
63
+ return -1;
64
+ }
65
+
66
+ if (fstat(fileno(fp), &st)) {
67
+ provider->last_errno = errno;
68
+ goto GT_DONE;
69
+ }
70
+
71
+ if (provider->last_mtime == st.st_mtime) {
72
+ lcb_log(LOGARGS(provider, WARN), LOGFMT "Modification time too old", LOGID(provider));
73
+ goto GT_DONE;
74
+ }
75
+
76
+ config = lcbvb_create();
77
+ if (config == NULL) {
78
+ goto GT_DONE;
79
+ }
80
+
81
+ lcb_string_init(&str);
82
+
83
+ while ((nr = fread(line, 1, sizeof(line), fp)) > 0) {
84
+ if (lcb_string_append(&str, line, nr)) {
85
+ goto GT_DONE;
86
+ }
87
+ }
88
+
89
+ if (ferror(fp)) {
90
+ goto GT_DONE;
91
+ }
92
+
93
+ fclose(fp);
94
+ fp = NULL;
95
+
96
+ if (!str.nused) {
97
+ status = -1;
98
+ goto GT_DONE;
99
+ }
100
+
101
+ end = strstr(str.base, CONFIG_CACHE_MAGIC);
102
+ if (end == NULL) {
103
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't find magic", LOGID(provider));
104
+ if (!provider->ro_mode) {
105
+ remove(provider->filename);
106
+ }
107
+ status = -1;
108
+ goto GT_DONE;
109
+ }
110
+
111
+ fail = lcbvb_load_json(config, str.base);
112
+ if (fail) {
113
+ status = -1;
114
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't parse configuration", LOGID(provider));
115
+ lcb_log_badconfig(LOGARGS(provider, ERROR), config, str.base);
116
+ if (!provider->ro_mode) {
117
+ remove(provider->filename);
118
+ }
119
+ goto GT_DONE;
120
+ }
121
+
122
+ if (lcbvb_get_distmode(config) != LCBVB_DIST_VBUCKET) {
123
+ status = -1;
124
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Not applying cached memcached config", LOGID(provider));
125
+ goto GT_DONE;
126
+ }
127
+
128
+ if (strcmp(config->bname, PROVIDER_SETTING(&provider->base, bucket)) != 0) {
129
+ status = -1;
130
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Bucket name in file is different from the one requested", LOGID(provider));
131
+ }
132
+
133
+ if (provider->config) {
134
+ lcb_clconfig_decref(provider->config);
135
+ }
136
+
137
+ provider->config = lcb_clconfig_create(config, LCB_CLCONFIG_FILE);
138
+ provider->config->cmpclock = gethrtime();
139
+ provider->config->origin = provider->base.type;
140
+ provider->last_mtime = st.st_mtime;
141
+ status = 0;
142
+ config = NULL;
143
+
144
+ GT_DONE:
145
+ if (fp != NULL) {
146
+ fclose(fp);
147
+ }
148
+
149
+ if (config != NULL) {
150
+ lcbvb_destroy(config);
151
+ }
152
+
153
+ lcb_string_release(&str);
154
+ return status;
155
+ }
156
+
157
+ static void
158
+ write_to_file(file_provider *provider, lcbvb_CONFIG *cfg)
159
+ {
160
+ FILE *fp;
161
+
162
+ if (provider->filename == NULL || provider->ro_mode) {
163
+ return;
164
+ }
165
+
166
+ fp = fopen(provider->filename, "w");
167
+ if (fp) {
168
+ char *json = lcbvb_save_json(cfg);
169
+ lcb_log(LOGARGS(provider, INFO), LOGFMT "Writing configuration to file", LOGID(provider));
170
+ fprintf(fp, "%s%s", json, CONFIG_CACHE_MAGIC);
171
+ fclose(fp);
172
+ free(json);
173
+ } else {
174
+ int save_errno = errno;
175
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't open file for writing: %s", LOGID(provider), strerror(save_errno));
176
+ }
177
+ }
178
+
179
+ static clconfig_info * get_cached(clconfig_provider *pb)
180
+ {
181
+ file_provider *provider = (file_provider *)pb;
182
+ if (!provider->filename) {
183
+ return NULL;
184
+ }
185
+
186
+ return provider->config;
187
+ }
188
+
189
+ static void async_callback(void *cookie)
190
+ {
191
+ time_t last_mtime;
192
+ file_provider *provider = (file_provider *)cookie;
193
+ last_mtime = provider->last_mtime;
194
+ if (load_cache(provider) == 0) {
195
+ if (last_mtime != provider->last_mtime) {
196
+ lcb_confmon_provider_success(&provider->base, provider->config);
197
+ return;
198
+ }
199
+ }
200
+
201
+ lcb_confmon_provider_failed(&provider->base, LCB_ERROR);
202
+ }
203
+
204
+ static lcb_error_t refresh_file(clconfig_provider *pb)
205
+ {
206
+ file_provider *provider = (file_provider *)pb;
207
+ if (lcbio_timer_armed(provider->timer)) {
208
+ return LCB_SUCCESS;
209
+ }
210
+
211
+ lcbio_async_signal(provider->timer);
212
+ return LCB_SUCCESS;
213
+ }
214
+
215
+ static lcb_error_t pause_file(clconfig_provider *pb)
216
+ {
217
+ (void)pb;
218
+ return LCB_SUCCESS;
219
+ }
220
+
221
+ static void shutdown_file(clconfig_provider *pb)
222
+ {
223
+ file_provider *provider = (file_provider *)pb;
224
+ free(provider->filename);
225
+ if (provider->timer) {
226
+ lcbio_timer_destroy(provider->timer);
227
+ }
228
+ if (provider->config) {
229
+ lcb_clconfig_decref(provider->config);
230
+ }
231
+ free(provider);
232
+ }
233
+
234
+ static void config_listener(clconfig_listener *lsn, clconfig_event_t event,
235
+ clconfig_info *info)
236
+ {
237
+ file_provider *provider;
238
+
239
+ if (event != CLCONFIG_EVENT_GOT_NEW_CONFIG) {
240
+ return;
241
+ }
242
+
243
+ provider = (file_provider *) (void*)(((char *)lsn) - offsetof(file_provider, listener));
244
+ if (!provider->base.enabled) {
245
+ return;
246
+ }
247
+
248
+ if (info->origin == LCB_CLCONFIG_PHONY || info->origin == LCB_CLCONFIG_FILE) {
249
+ lcb_log(LOGARGS(provider, TRACE), "Not writing configuration originating from PHONY or FILE to cache");
250
+ return;
251
+ }
252
+
253
+ write_to_file(provider, info->vbc);
254
+ }
255
+
256
+ static void
257
+ do_file_dump(clconfig_provider *pb, FILE *fp)
258
+ {
259
+ file_provider *pr = (file_provider *)pb;
260
+
261
+ fprintf(fp, "## BEGIN FILE PROVIEDER DUMP ##\n");
262
+ if (pr->filename) {
263
+ fprintf(fp, "FILENAME: %s\n", pr->filename);
264
+ }
265
+ fprintf(fp, "LAST SYSTEM ERRNO: %d\n", pr->last_errno);
266
+ fprintf(fp, "LAST MTIME: %lu\n", (unsigned long)pr->last_mtime);
267
+ fprintf(fp, "## END FILE PROVIDER DUMP ##\n");
268
+
269
+ }
270
+
271
+ clconfig_provider * lcb_clconfig_create_file(lcb_confmon *parent)
272
+ {
273
+ file_provider *provider = calloc(1, sizeof(*provider));
274
+
275
+ if (!provider) {
276
+ return NULL;
277
+ }
278
+
279
+ provider->base.get_cached = get_cached;
280
+ provider->base.refresh = refresh_file;
281
+ provider->base.pause = pause_file;
282
+ provider->base.shutdown = shutdown_file;
283
+ provider->base.dump = do_file_dump;
284
+ provider->base.type = LCB_CLCONFIG_FILE;
285
+ provider->listener.callback = config_listener;
286
+ provider->timer = lcbio_timer_new(parent->iot, provider, async_callback);
287
+
288
+ lcb_confmon_add_listener(parent, &provider->listener);
289
+
290
+ return &provider->base;
291
+ }
292
+
293
+
294
+ static char *mkcachefile(const char *name, const char *bucket)
295
+ {
296
+ if (name != NULL) {
297
+ return strdup(name);
298
+ } else {
299
+ char buffer[1024];
300
+ const char *tmpdir = lcb_get_tmpdir();
301
+
302
+ snprintf(buffer, sizeof(buffer),
303
+ "%s/%s", tmpdir ? tmpdir : ".", bucket);
304
+ return strdup(buffer);
305
+ }
306
+ }
307
+
308
+ int lcb_clconfig_file_set_filename(clconfig_provider *p, const char *f, int ro)
309
+ {
310
+ file_provider *provider = (file_provider *)p;
311
+ lcb_assert(provider->base.type == LCB_CLCONFIG_FILE);
312
+ provider->base.enabled = 1;
313
+
314
+ if (provider->filename) {
315
+ free(provider->filename);
316
+ }
317
+
318
+ provider->filename = mkcachefile(f, p->parent->settings->bucket);
319
+
320
+ if (ro) {
321
+ FILE *fp_tmp;
322
+ provider->ro_mode = 1;
323
+
324
+ fp_tmp = fopen(provider->filename, "r");
325
+ if (!fp_tmp) {
326
+ lcb_log(LOGARGS(provider, ERROR), LOGFMT "Couldn't open for reading: %s", LOGID(provider), strerror(errno));
327
+ return -1;
328
+ } else {
329
+ fclose(fp_tmp);
330
+ }
331
+ }
332
+
333
+ return 0;
334
+ }
335
+
336
+ const char *
337
+ lcb_clconfig_file_get_filename(clconfig_provider *p)
338
+ {
339
+ file_provider *fp = (file_provider *)p;
340
+ return fp->filename;
341
+ }
342
+
343
+ void
344
+ lcb_clconfig_file_set_readonly(clconfig_provider *p, int val)
345
+ {
346
+ ((file_provider *)p)->ro_mode = val;
347
+ }
@@ -0,0 +1,630 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2013 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ #include "internal.h"
19
+ #include "clconfig.h"
20
+ #include "bc_http.h"
21
+ #include <lcbio/ssl.h>
22
+ #include "ctx-log-inl.h"
23
+ #define LOGARGS(ht, lvlbase) ht->base.parent->settings, "htconfig", LCB_LOG_##lvlbase, __FILE__, __LINE__
24
+ #define LOGFMT "<%s:%s> "
25
+ #define LOGID(h) get_ctx_host(h->ioctx), get_ctx_port(h->ioctx)
26
+
27
+ static void io_error_handler(lcbio_CTX *, lcb_error_t);
28
+ static void on_connected(lcbio_SOCKET *, void *, lcb_error_t, lcbio_OSERR);
29
+ static lcb_error_t connect_next(http_provider *);
30
+ static void read_common(lcbio_CTX *, unsigned);
31
+ static lcb_error_t setup_request_header(http_provider *, const lcb_host_t *);
32
+
33
+ /**
34
+ * Determine if we're in compatibility mode with the previous versions of the
35
+ * library - where the idle timeout is disabled and a perpetual streaming
36
+ * connection will always remain open (regardless of whether it was triggered
37
+ * by start_refresh/get_refresh).
38
+ */
39
+ static int is_v220_compat(http_provider *http)
40
+ {
41
+ lcb_uint32_t setting = PROVIDER_SETTING(&http->base, bc_http_stream_time);
42
+ if (setting == (lcb_uint32_t)-1) {
43
+ return 1;
44
+ }
45
+ return 0;
46
+ }
47
+
48
+ /**
49
+ * Closes the current connection and removes the disconn timer along with it
50
+ */
51
+ static void close_current(http_provider *http)
52
+ {
53
+ lcbio_timer_disarm(http->disconn_timer);
54
+ if (http->ioctx) {
55
+ lcbio_ctx_close(http->ioctx, NULL, NULL);
56
+ } else if (http->creq){
57
+ lcbio_connect_cancel(http->creq);
58
+ }
59
+ http->creq = NULL;
60
+ http->ioctx = NULL;
61
+ }
62
+
63
+ /**
64
+ * Call when there is an error in I/O. This includes read, write, connect
65
+ * and timeouts.
66
+ */
67
+ static lcb_error_t
68
+ io_error(http_provider *http, lcb_error_t origerr)
69
+ {
70
+ lcb_confmon *mon = http->base.parent;
71
+ lcb_settings *settings = mon->settings;
72
+
73
+ close_current(http);
74
+
75
+ http->creq = lcbio_connect_hl(
76
+ mon->iot, settings, http->nodes, 0, settings->config_node_timeout,
77
+ on_connected, http);
78
+ if (http->creq) {
79
+ return LCB_SUCCESS;
80
+ }
81
+
82
+ lcb_confmon_provider_failed(&http->base, origerr);
83
+ lcbio_timer_disarm(http->io_timer);
84
+ if (is_v220_compat(http) && http->base.parent->config != NULL) {
85
+ lcb_log(LOGARGS(http, INFO), "HTTP node list finished. Trying to obtain connection from first node in list");
86
+ if (!lcbio_timer_armed(http->as_reconnect)) {
87
+ lcbio_timer_rearm(http->as_reconnect,
88
+ PROVIDER_SETTING(&http->base, grace_next_cycle));
89
+ }
90
+ }
91
+ return origerr;
92
+ }
93
+
94
+ /**
95
+ * Call this if the configuration generation has changed.
96
+ */
97
+ static void set_new_config(http_provider *http)
98
+ {
99
+ const lcb_host_t *curhost;
100
+ if (http->current_config) {
101
+ lcb_clconfig_decref(http->current_config);
102
+ }
103
+
104
+ curhost = lcbio_get_host(lcbio_ctx_sock(http->ioctx));
105
+ http->current_config = http->last_parsed;
106
+ lcb_clconfig_incref(http->current_config);
107
+ lcbvb_replace_host(http->current_config->vbc, curhost->host);
108
+ lcb_confmon_provider_success(&http->base, http->current_config);
109
+ }
110
+
111
+ static lcb_error_t
112
+ process_chunk(http_provider *http, const void *buf, unsigned nbuf)
113
+ {
114
+ lcb_error_t err = LCB_SUCCESS;
115
+ char *term;
116
+ int rv;
117
+ lcbvb_CONFIG *cfgh;
118
+ lcbht_RESPSTATE state, oldstate, diff;
119
+ lcbht_RESPONSE *resp = lcbht_get_response(http->htp);
120
+
121
+ oldstate = resp->state;
122
+ state = lcbht_parse(http->htp, buf, nbuf);
123
+ diff = state ^ oldstate;
124
+
125
+ if (state & LCBHT_S_ERROR) {
126
+ return LCB_PROTOCOL_ERROR;
127
+ }
128
+
129
+ if (diff & LCBHT_S_HEADER) {
130
+ /* see that we got a success? */
131
+ if (resp->status == 200) {
132
+ /* nothing */
133
+ } else if (resp->status == 404) {
134
+ const int urlmode = PROVIDER_SETTING(&http->base, bc_http_urltype);
135
+ err = LCB_BUCKET_ENOENT;
136
+
137
+ if (++http->uritype > LCB_HTCONFIG_URLTYPE_COMPAT) {
138
+ lcb_log(LOGARGS(http, ERR), LOGFMT "Got 404 on config stream. Assuming bucket does not exist as we've tried both URL types", LOGID(http));
139
+ goto GT_HT_ERROR;
140
+
141
+ } else if ((urlmode & LCB_HTCONFIG_URLTYPE_COMPAT) == 0) {
142
+ lcb_log(LOGARGS(http, ERR), LOGFMT "Got 404 on config stream for terse URI. Compat URI disabled, so not trying", LOGID(http));
143
+
144
+ } else {
145
+ /* reissue the request; but wait for it to drain */
146
+ lcb_log(LOGARGS(http, WARN), LOGFMT "Got 404 on config stream. Assuming terse URI not supported on cluster", LOGID(http));
147
+ http->try_nexturi = 1;
148
+ err = LCB_SUCCESS;
149
+ goto GT_CHECKDONE;
150
+ }
151
+ } else if (resp->status == 401) {
152
+ err = LCB_AUTH_ERROR;
153
+ } else {
154
+ err = LCB_ERROR;
155
+ }
156
+
157
+ GT_HT_ERROR:
158
+ if (err != LCB_SUCCESS) {
159
+ lcb_log(LOGARGS(http, ERR), LOGFMT "Got non-success HTTP status code %d", LOGID(http), resp->status);
160
+ return err;
161
+ }
162
+ }
163
+
164
+ GT_CHECKDONE:
165
+ if (http->try_nexturi) {
166
+ lcb_host_t *host;
167
+ if (!(state & LCBHT_S_DONE)) {
168
+ return LCB_SUCCESS;
169
+ }
170
+ host = lcbio_get_host(lcbio_ctx_sock(http->ioctx));
171
+ http->try_nexturi = 0;
172
+ if ((err = setup_request_header(http, host)) != LCB_SUCCESS) {
173
+ return err;
174
+ }
175
+
176
+ /* reset the state? */
177
+ lcbht_reset(http->htp);
178
+ lcbio_ctx_put(http->ioctx, http->request_buf, strlen(http->request_buf));
179
+ return LCB_SUCCESS;
180
+ }
181
+
182
+ if (PROVIDER_SETTING(&http->base, conntype) == LCB_TYPE_CLUSTER) {
183
+ /* don't bother with parsing the actual config */
184
+ resp->body.nused = 0;
185
+ return LCB_SUCCESS;
186
+ }
187
+ if (!(state & LCBHT_S_BODY)) {
188
+ /* nothing to parse yet */
189
+ return LCB_SUCCESS;
190
+ }
191
+
192
+ /* seek ahead for strstr */
193
+ term = strstr(resp->body.base, CONFIG_DELIMITER);
194
+ if (!term) {
195
+ return LCB_SUCCESS;
196
+ }
197
+
198
+ *term = '\0';
199
+ cfgh = lcbvb_create();
200
+ if (!cfgh) {
201
+ return LCB_CLIENT_ENOMEM;
202
+ }
203
+ rv = lcbvb_load_json(cfgh, resp->body.base);
204
+ if (rv != 0) {
205
+ lcb_log(LOGARGS(http, ERR), LOGFMT "Failed to parse a valid config from HTTP stream", LOGID(http));
206
+ lcb_log_badconfig(LOGARGS(http, ERR), cfgh, resp->body.base);
207
+ lcbvb_destroy(cfgh);
208
+ return LCB_PROTOCOL_ERROR;
209
+ }
210
+ if (http->last_parsed) {
211
+ lcb_clconfig_decref(http->last_parsed);
212
+ }
213
+ http->last_parsed = lcb_clconfig_create(cfgh, LCB_CLCONFIG_HTTP);
214
+ http->last_parsed->cmpclock = gethrtime();
215
+ http->generation++;
216
+
217
+ /** Relocate the stream */
218
+ lcb_string_erase_beginning(&resp->body,
219
+ (term+sizeof(CONFIG_DELIMITER)-1)-resp->body.base);
220
+
221
+ return LCB_SUCCESS;
222
+ }
223
+
224
+ /**
225
+ * Common function to handle parsing the HTTP stream for both v0 and v1 io
226
+ * implementations.
227
+ */
228
+ static void
229
+ read_common(lcbio_CTX *ctx, unsigned nr)
230
+ {
231
+ lcbio_CTXRDITER riter;
232
+ http_provider *http = lcbio_ctx_data(ctx);
233
+ int old_generation = http->generation;
234
+
235
+ lcb_log(LOGARGS(http, TRACE), LOGFMT "Received %d bytes on HTTP stream", LOGID(http), nr);
236
+
237
+ lcbio_timer_rearm(http->io_timer,
238
+ PROVIDER_SETTING(&http->base, config_node_timeout));
239
+
240
+ LCBIO_CTX_ITERFOR(ctx, &riter, nr) {
241
+ unsigned nbuf = lcbio_ctx_risize(&riter);
242
+ void *buf = lcbio_ctx_ribuf(&riter);
243
+ lcb_error_t err = process_chunk(http, buf, nbuf);
244
+
245
+ if (err != LCB_SUCCESS) {
246
+ io_error(http, err);
247
+ return;
248
+ }
249
+ }
250
+
251
+ if (http->generation != old_generation) {
252
+ lcb_log(LOGARGS(http, DEBUG), LOGFMT "Generation %d -> %d", LOGID(http), old_generation, http->generation);
253
+ lcbio_timer_disarm(http->io_timer);
254
+ set_new_config(http);
255
+ }
256
+
257
+ lcbio_ctx_rwant(ctx, 1);
258
+ lcbio_ctx_schedule(ctx);
259
+ }
260
+
261
+ static lcb_error_t
262
+ setup_request_header(http_provider *http, const lcb_host_t *host)
263
+ {
264
+ lcb_settings *settings = http->base.parent->settings;
265
+
266
+ char *buf = http->request_buf;
267
+ const char *username = NULL, *password = NULL;
268
+ lcb_size_t nbuf = sizeof(http->request_buf);
269
+
270
+ lcb_size_t offset = 0;
271
+ http->request_buf[0] = '\0';
272
+
273
+ if (settings->conntype == LCB_TYPE_BUCKET) {
274
+ const char *fmt;
275
+ if (http->uritype == LCB_HTCONFIG_URLTYPE_25PLUS) {
276
+ fmt = REQBUCKET_TERSE_FMT;
277
+ } else {
278
+ fmt = REQBUCKET_COMPAT_FMT;
279
+ }
280
+ offset = snprintf(buf, nbuf, fmt, settings->bucket);
281
+
282
+ } else if (settings->conntype == LCB_TYPE_CLUSTER) {
283
+ offset = snprintf(buf, nbuf, REQPOOLS_FMT);
284
+
285
+ } else {
286
+ return LCB_EINVAL;
287
+ }
288
+ lcbauth_get_upass(settings->auth, &username, &password);
289
+
290
+ if (password) {
291
+ char cred[256], b64[256];
292
+ snprintf(cred, sizeof(cred), "%s:%s", username, password);
293
+
294
+ if (lcb_base64_encode(cred, b64, sizeof(b64)) == -1) {
295
+ return LCB_EINTERNAL;
296
+ }
297
+
298
+ offset += snprintf(buf + offset, nbuf - offset, AUTHDR_FMT, b64);
299
+ }
300
+
301
+ offset += snprintf(buf + offset, nbuf - offset, HOSTHDR_FMT,
302
+ host->host, host->port);
303
+
304
+ offset += snprintf(buf + offset, nbuf - offset, "%s\r\n", LAST_HTTP_HEADER);
305
+
306
+ return LCB_SUCCESS;
307
+ }
308
+
309
+ static void reset_stream_state(http_provider *http)
310
+ {
311
+ const int urlmode = PROVIDER_SETTING(&http->base, bc_http_urltype);
312
+ if (http->last_parsed) {
313
+ lcb_clconfig_decref(http->last_parsed);
314
+ http->last_parsed = NULL;
315
+ }
316
+ if (urlmode & LCB_HTCONFIG_URLTYPE_25PLUS) {
317
+ http->uritype = LCB_HTCONFIG_URLTYPE_25PLUS;
318
+ } else {
319
+ http->uritype = LCB_HTCONFIG_URLTYPE_COMPAT;
320
+ }
321
+ http->try_nexturi = 0;
322
+ lcbht_reset(http->htp);
323
+ }
324
+
325
+ static void
326
+ on_connected(lcbio_SOCKET *sock, void *arg, lcb_error_t err, lcbio_OSERR syserr)
327
+ {
328
+ http_provider *http = arg;
329
+ lcb_host_t *host;
330
+ lcbio_CTXPROCS procs;
331
+ http->creq = NULL;
332
+
333
+ if (err != LCB_SUCCESS) {
334
+ lcb_log(LOGARGS(http, ERR), "Connection to REST API failed with code=0x%x (%d)", err, syserr);
335
+ io_error(http, err);
336
+ return;
337
+ }
338
+ host = lcbio_get_host(sock);
339
+ lcb_log(LOGARGS(http, DEBUG), "Successfuly connected to REST API %s:%s", host->host, host->port);
340
+
341
+ lcbio_sslify_if_needed(sock, http->base.parent->settings);
342
+ reset_stream_state(http);
343
+
344
+ if ((err = setup_request_header(http, host)) != LCB_SUCCESS) {
345
+ lcb_log(LOGARGS(http, ERR), "Couldn't setup request header");
346
+ io_error(http, err);
347
+ return;
348
+ }
349
+
350
+ memset(&procs, 0, sizeof(procs));
351
+ procs.cb_err = io_error_handler;
352
+ procs.cb_read = read_common;
353
+ http->ioctx = lcbio_ctx_new(sock, http, &procs);
354
+ http->ioctx->subsys = "bc_http";
355
+
356
+ lcbio_ctx_put(http->ioctx, http->request_buf, strlen(http->request_buf));
357
+ lcbio_ctx_rwant(http->ioctx, 1);
358
+ lcbio_ctx_schedule(http->ioctx);
359
+ lcbio_timer_rearm(http->io_timer,
360
+ PROVIDER_SETTING(&http->base, config_node_timeout));
361
+ }
362
+
363
+ static void
364
+ timeout_handler(void *arg)
365
+ {
366
+ http_provider *http = arg;
367
+
368
+ lcb_log(LOGARGS(http, ERR), LOGFMT "HTTP Provider timed out waiting for I/O", LOGID(http));
369
+
370
+ /**
371
+ * If we're not the current provider then ignore the timeout until we're
372
+ * actively requested to do so
373
+ */
374
+ if (&http->base != http->base.parent->cur_provider ||
375
+ lcb_confmon_is_refreshing(http->base.parent) == 0) {
376
+ lcb_log(LOGARGS(http, DEBUG), LOGFMT "Ignoring timeout because we're either not in a refresh or not the current provider", LOGID(http));
377
+ return;
378
+ }
379
+
380
+ io_error(http, LCB_ETIMEDOUT);
381
+ }
382
+
383
+
384
+ static lcb_error_t
385
+ connect_next(http_provider *http)
386
+ {
387
+ lcb_settings *settings = http->base.parent->settings;
388
+ lcb_log(LOGARGS(http, TRACE), "Starting HTTP Configuration Provider %p", (void*)http);
389
+ close_current(http);
390
+ lcbio_timer_disarm(http->as_reconnect);
391
+
392
+ if (!hostlist_size(http->nodes)) {
393
+ lcb_log(LOGARGS(http, ERROR), "Not scheduling HTTP provider since no nodes have been configured for HTTP bootstrap");
394
+ return LCB_CONNECT_ERROR;
395
+ }
396
+
397
+ http->creq = lcbio_connect_hl(http->base.parent->iot, settings, http->nodes, 1,
398
+ settings->config_node_timeout, on_connected, http);
399
+ if (http->creq) {
400
+ return LCB_SUCCESS;
401
+ }
402
+ lcb_log(LOGARGS(http, ERROR), "%p: Couldn't schedule connection", (void*)http);
403
+ return LCB_CONNECT_ERROR;
404
+ }
405
+
406
+ static void delayed_disconn(void *arg)
407
+ {
408
+ http_provider *http = arg;
409
+ lcb_log(LOGARGS(http, DEBUG), "Stopping HTTP provider %p", (void*)http);
410
+
411
+ /** closes the connection and cleans up the timer */
412
+ close_current(http);
413
+ lcbio_timer_disarm(http->io_timer);
414
+ }
415
+
416
+ static void delayed_reconnect(void *arg)
417
+ {
418
+ http_provider *http = arg;
419
+ lcb_error_t err;
420
+ if (http->ioctx) {
421
+ /* have a context already */
422
+ return;
423
+ }
424
+ err = connect_next(http);
425
+ if (err != LCB_SUCCESS) {
426
+ io_error(http, err);
427
+ }
428
+ }
429
+
430
+ static lcb_error_t pause_http(clconfig_provider *pb)
431
+ {
432
+ http_provider *http = (http_provider *)pb;
433
+ if (is_v220_compat(http)) {
434
+ return LCB_SUCCESS;
435
+ }
436
+
437
+ if (!lcbio_timer_armed(http->disconn_timer)) {
438
+ lcbio_timer_rearm(http->disconn_timer,
439
+ PROVIDER_SETTING(pb, bc_http_stream_time));
440
+ }
441
+ return LCB_SUCCESS;
442
+ }
443
+
444
+ static lcb_error_t get_refresh(clconfig_provider *provider)
445
+ {
446
+ http_provider *http = (http_provider *)provider;
447
+
448
+ /**
449
+ * We want a grace interval here because we might already be fetching a
450
+ * connection. HOWEVER we don't want to indefinitely wait on a socket
451
+ * so we issue a timer indicating how long we expect to wait for a
452
+ * streaming update until we get something.
453
+ */
454
+
455
+ /** If we need a new socket, we do connect_next. */
456
+ if (http->ioctx == NULL && http->creq == NULL) {
457
+ lcbio_async_signal(http->as_reconnect);
458
+ }
459
+
460
+ lcbio_timer_disarm(http->disconn_timer);
461
+ if (http->ioctx) {
462
+ lcbio_timer_rearm(http->io_timer,
463
+ PROVIDER_SETTING(provider, config_node_timeout));
464
+ }
465
+ return LCB_SUCCESS;
466
+ }
467
+
468
+ static clconfig_info* http_get_cached(clconfig_provider *provider)
469
+ {
470
+ http_provider *http = (http_provider *)provider;
471
+ return http->current_config;
472
+ }
473
+
474
+ static void
475
+ config_updated(clconfig_provider *pb, lcbvb_CONFIG *newconfig)
476
+ {
477
+ unsigned int ii;
478
+ http_provider *http = (http_provider *)pb;
479
+ lcb_SSLOPTS sopts;
480
+ lcbvb_SVCMODE mode;
481
+
482
+ hostlist_clear(http->nodes);
483
+
484
+ sopts = PROVIDER_SETTING(pb, sslopts);
485
+ if (sopts & LCB_SSL_ENABLED) {
486
+ mode = LCBVB_SVCMODE_SSL;
487
+ } else {
488
+ mode = LCBVB_SVCMODE_PLAIN;
489
+ }
490
+
491
+ for (ii = 0; ii < newconfig->nsrv; ++ii) {
492
+ const char *ss;
493
+ lcb_error_t status;
494
+ ss = lcbvb_get_hostport(newconfig, ii, LCBVB_SVCTYPE_MGMT, mode);
495
+ if (!ss) {
496
+ /* not supported? */
497
+ continue;
498
+ }
499
+ status = hostlist_add_stringz(http->nodes, ss, LCB_CONFIG_HTTP_PORT);
500
+ lcb_assert(status == LCB_SUCCESS);
501
+ }
502
+ if (!hostlist_size(http->nodes)) {
503
+ lcb_log(LOGARGS(http, FATAL), "New nodes do not contain management ports");
504
+ }
505
+
506
+ if (PROVIDER_SETTING(pb, randomize_bootstrap_nodes)) {
507
+ hostlist_randomize(http->nodes);
508
+ }
509
+ }
510
+
511
+ static void
512
+ configure_nodes(clconfig_provider *pb, const hostlist_t newnodes)
513
+ {
514
+ http_provider *http = (void *)pb;
515
+ hostlist_assign(http->nodes, newnodes);
516
+ if (PROVIDER_SETTING(pb, randomize_bootstrap_nodes)) {
517
+ hostlist_randomize(http->nodes);
518
+ }
519
+ }
520
+
521
+ static hostlist_t
522
+ get_nodes(const clconfig_provider *pb)
523
+ {
524
+ return ((http_provider *)pb)->nodes;
525
+ }
526
+
527
+ static void shutdown_http(clconfig_provider *provider)
528
+ {
529
+ http_provider *http = (http_provider *)provider;
530
+ reset_stream_state(http);
531
+ close_current(http);
532
+ lcbht_free(http->htp);
533
+
534
+ if (http->current_config) {
535
+ lcb_clconfig_decref(http->current_config);
536
+ }
537
+ if (http->disconn_timer) {
538
+ lcbio_timer_destroy(http->disconn_timer);
539
+ }
540
+ if (http->io_timer) {
541
+ lcbio_timer_destroy(http->io_timer);
542
+ }
543
+ if (http->as_reconnect) {
544
+ lcbio_timer_destroy(http->as_reconnect);
545
+ }
546
+ if (http->nodes) {
547
+ hostlist_destroy(http->nodes);
548
+ }
549
+ free(http);
550
+ }
551
+
552
+ static void
553
+ do_http_dump(clconfig_provider *pb, FILE *fp)
554
+ {
555
+ http_provider *ht = (http_provider *)pb;
556
+ fprintf(fp, "## BEGIN HTTP PROVIDER DUMP\n");
557
+ fprintf(fp, "NUMBER OF CONFIGS RECEIVED: %u\n", ht->generation);
558
+ fprintf(fp, "DUMPING I/O TIMER\n");
559
+ lcbio_timer_dump(ht->io_timer, fp);
560
+ if (ht->ioctx) {
561
+ fprintf(fp, "DUMPING CURRENT CONNECTION:\n");
562
+ lcbio_ctx_dump(ht->ioctx, fp);
563
+ } else if (ht->creq) {
564
+ fprintf(fp, "CURRENTLY CONNECTING..\n");
565
+ } else {
566
+ fprintf(fp, "NO CONNECTION ACTIVE\n");
567
+ }
568
+ }
569
+
570
+ clconfig_provider * lcb_clconfig_create_http(lcb_confmon *parent)
571
+ {
572
+ http_provider *http = calloc(1, sizeof(*http));
573
+
574
+ if (!http) {
575
+ return NULL;
576
+ }
577
+
578
+ if (! (http->nodes = hostlist_create())) {
579
+ free(http);
580
+ return NULL;
581
+ }
582
+
583
+ http->base.type = LCB_CLCONFIG_HTTP;
584
+ http->base.refresh = get_refresh;
585
+ http->base.pause = pause_http;
586
+ http->base.get_cached = http_get_cached;
587
+ http->base.shutdown = shutdown_http;
588
+ http->base.config_updated = config_updated;
589
+ http->base.configure_nodes = configure_nodes;
590
+ http->base.get_nodes = get_nodes;
591
+ http->base.dump = do_http_dump;
592
+ http->base.enabled = 0;
593
+ http->io_timer = lcbio_timer_new(parent->iot, http, timeout_handler);
594
+ http->disconn_timer = lcbio_timer_new(parent->iot, http, delayed_disconn);
595
+ http->as_reconnect = lcbio_timer_new(parent->iot, http, delayed_reconnect);
596
+ http->htp = lcbht_new(parent->settings);
597
+ return &http->base;
598
+ }
599
+
600
+ static void
601
+ io_error_handler(lcbio_CTX *ctx, lcb_error_t err)
602
+ {
603
+ io_error((http_provider *)lcbio_ctx_data(ctx), err);
604
+ }
605
+
606
+ void lcb_clconfig_http_enable(clconfig_provider *http)
607
+ {
608
+ http->enabled = 1;
609
+ }
610
+
611
+ lcbio_SOCKET *
612
+ lcb_confmon_get_rest_connection(lcb_confmon *mon)
613
+ {
614
+ http_provider *http = (http_provider *)mon->all_providers[LCB_CLCONFIG_HTTP];
615
+ if (!http->ioctx) {
616
+ return NULL;
617
+ }
618
+ return lcbio_ctx_sock(http->ioctx);
619
+
620
+ }
621
+
622
+ lcb_host_t *
623
+ lcb_confmon_get_rest_host(lcb_confmon *mon)
624
+ {
625
+ lcbio_SOCKET *sock = lcb_confmon_get_rest_connection(mon);
626
+ if (sock) {
627
+ return lcbio_get_host(sock);
628
+ }
629
+ return NULL;
630
+ }