mt-libcouchbase 1.4.0

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 (707) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +38 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +24 -0
  8. data/README.md +445 -0
  9. data/Rakefile +76 -0
  10. data/ext/README.md +6 -0
  11. data/ext/Rakefile +19 -0
  12. data/ext/libcouchbase/.gitignore +132 -0
  13. data/ext/libcouchbase/CMakeLists.txt +455 -0
  14. data/ext/libcouchbase/CONTRIBUTING.md +105 -0
  15. data/ext/libcouchbase/LICENSE +202 -0
  16. data/ext/libcouchbase/README.markdown +195 -0
  17. data/ext/libcouchbase/RELEASE_NOTES.markdown +3523 -0
  18. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +52 -0
  19. data/ext/libcouchbase/cmake/Modules/CopyPDB.cmake +42 -0
  20. data/ext/libcouchbase/cmake/Modules/DistScript.cmake +17 -0
  21. data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +18 -0
  22. data/ext/libcouchbase/cmake/Modules/FindCouchbaseHdrHistogram.cmake +15 -0
  23. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibev.cmake +73 -0
  24. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +54 -0
  25. data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +57 -0
  26. data/ext/libcouchbase/cmake/Modules/FindProfiler.cmake +16 -0
  27. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +49 -0
  28. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +142 -0
  29. data/ext/libcouchbase/cmake/Modules/GetPlatformCCInfo.cmake +45 -0
  30. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +70 -0
  31. data/ext/libcouchbase/cmake/config-cmake.h.in +80 -0
  32. data/ext/libcouchbase/cmake/configure +355 -0
  33. data/ext/libcouchbase/cmake/defs.mk.in +6 -0
  34. data/ext/libcouchbase/cmake/dtrace-instr-link.pl +51 -0
  35. data/ext/libcouchbase/cmake/libcouchbase.stp.in +829 -0
  36. data/ext/libcouchbase/cmake/source_files.cmake +104 -0
  37. data/ext/libcouchbase/contrib/cJSON/cJSON.c +1022 -0
  38. data/ext/libcouchbase/contrib/cJSON/cJSON.h +158 -0
  39. data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +25 -0
  40. data/ext/libcouchbase/contrib/cbsasl/COPYING +202 -0
  41. data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +259 -0
  42. data/ext/libcouchbase/contrib/cbsasl/src/client.c +419 -0
  43. data/ext/libcouchbase/contrib/cbsasl/src/common.c +50 -0
  44. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.c +67 -0
  45. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/hmac.h +33 -0
  46. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.c +296 -0
  47. data/ext/libcouchbase/contrib/cbsasl/src/cram-md5/md5.h +45 -0
  48. data/ext/libcouchbase/contrib/cbsasl/src/hash.c +573 -0
  49. data/ext/libcouchbase/contrib/cbsasl/src/hash.h +15 -0
  50. data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.c +500 -0
  51. data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.h +99 -0
  52. data/ext/libcouchbase/contrib/cbsasl/src/util.h +31 -0
  53. data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +2 -0
  54. data/ext/libcouchbase/contrib/cliopts/cliopts.c +938 -0
  55. data/ext/libcouchbase/contrib/cliopts/cliopts.h +610 -0
  56. data/ext/libcouchbase/contrib/genhash/genhash.c +371 -0
  57. data/ext/libcouchbase/contrib/genhash/genhash.h +241 -0
  58. data/ext/libcouchbase/contrib/gtest-1.7.0/CHANGES +157 -0
  59. data/ext/libcouchbase/contrib/gtest-1.7.0/CMakeLists.txt +252 -0
  60. data/ext/libcouchbase/contrib/gtest-1.7.0/CONTRIBUTORS +37 -0
  61. data/ext/libcouchbase/contrib/gtest-1.7.0/LICENSE +28 -0
  62. data/ext/libcouchbase/contrib/gtest-1.7.0/MINIFY.sh +15 -0
  63. data/ext/libcouchbase/contrib/gtest-1.7.0/README +435 -0
  64. data/ext/libcouchbase/contrib/gtest-1.7.0/cmake/internal_utils.cmake +227 -0
  65. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-death-test.h +294 -0
  66. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-message.h +250 -0
  67. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h +1421 -0
  68. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-param-test.h.pump +487 -0
  69. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-printers.h +855 -0
  70. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-spi.h +232 -0
  71. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-test-part.h +179 -0
  72. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest-typed-test.h +259 -0
  73. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest.h +2291 -0
  74. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_pred_impl.h +358 -0
  75. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/gtest_prod.h +58 -0
  76. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-death-test-internal.h +319 -0
  77. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-filepath.h +206 -0
  78. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-internal.h +1158 -0
  79. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-linked_ptr.h +233 -0
  80. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h +5143 -0
  81. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util-generated.h.pump +301 -0
  82. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-param-util.h +619 -0
  83. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-port.h +1947 -0
  84. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-string.h +167 -0
  85. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h +1012 -0
  86. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-tuple.h.pump +339 -0
  87. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h +3331 -0
  88. data/ext/libcouchbase/contrib/gtest-1.7.0/include/gtest/internal/gtest-type-util.h.pump +297 -0
  89. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-all.cc +48 -0
  90. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-death-test.cc +1344 -0
  91. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-filepath.cc +382 -0
  92. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-internal-inl.h +1218 -0
  93. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-port.cc +805 -0
  94. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-printers.cc +363 -0
  95. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-test-part.cc +110 -0
  96. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest-typed-test.cc +110 -0
  97. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest.cc +5015 -0
  98. data/ext/libcouchbase/contrib/gtest-1.7.0/src/gtest_main.cc +38 -0
  99. data/ext/libcouchbase/contrib/http_parser/LICENSE-MIT +23 -0
  100. data/ext/libcouchbase/contrib/http_parser/README.md +178 -0
  101. data/ext/libcouchbase/contrib/http_parser/http_parser.c +2060 -0
  102. data/ext/libcouchbase/contrib/http_parser/http_parser.h +321 -0
  103. data/ext/libcouchbase/contrib/jsonsl/LICENSE +20 -0
  104. data/ext/libcouchbase/contrib/jsonsl/jsonsl.c +1452 -0
  105. data/ext/libcouchbase/contrib/jsonsl/jsonsl.h +971 -0
  106. data/ext/libcouchbase/contrib/lcb-jsoncpp/CMakeLists.txt +6 -0
  107. data/ext/libcouchbase/contrib/lcb-jsoncpp/LICENSE +55 -0
  108. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp-forwards.h +255 -0
  109. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.cpp +4893 -0
  110. data/ext/libcouchbase/contrib/lcb-jsoncpp/lcb-jsoncpp.h +1961 -0
  111. data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +7 -0
  112. data/ext/libcouchbase/contrib/snappy/COPYING +28 -0
  113. data/ext/libcouchbase/contrib/snappy/snappy-c.cc +90 -0
  114. data/ext/libcouchbase/contrib/snappy/snappy-c.h +138 -0
  115. data/ext/libcouchbase/contrib/snappy/snappy-internal.h +150 -0
  116. data/ext/libcouchbase/contrib/snappy/snappy-lcb-msvc.h +5 -0
  117. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +75 -0
  118. data/ext/libcouchbase/contrib/snappy/snappy-sinksource.h +137 -0
  119. data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.cc +42 -0
  120. data/ext/libcouchbase/contrib/snappy/snappy-stubs-internal.h +491 -0
  121. data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +100 -0
  122. data/ext/libcouchbase/contrib/snappy/snappy.cc +1312 -0
  123. data/ext/libcouchbase/contrib/snappy/snappy.h +184 -0
  124. data/ext/libcouchbase/contrib/win32-defs/iocpdefs.h +133 -0
  125. data/ext/libcouchbase/contrib/win32-defs/mingwdefs.h +4396 -0
  126. data/ext/libcouchbase/contrib/win32-defs/win_stdint.h +258 -0
  127. data/ext/libcouchbase/doc/Doxyfile +2495 -0
  128. data/ext/libcouchbase/doc/DoxygenLayout.xml +109 -0
  129. data/ext/libcouchbase/doc/Makefile +44 -0
  130. data/ext/libcouchbase/doc/apiattr.h +117 -0
  131. data/ext/libcouchbase/doc/cbc-n1qlback.markdown +88 -0
  132. data/ext/libcouchbase/doc/cbc-pillowfight.markdown +296 -0
  133. data/ext/libcouchbase/doc/cbc-subdoc.markdown +299 -0
  134. data/ext/libcouchbase/doc/cbc.markdown +763 -0
  135. data/ext/libcouchbase/doc/cbcrc.markdown +52 -0
  136. data/ext/libcouchbase/doc/common-additional-options.markdown +82 -0
  137. data/ext/libcouchbase/doc/common-options.markdown +71 -0
  138. data/ext/libcouchbase/doc/environment.h +93 -0
  139. data/ext/libcouchbase/doc/example/threads.c +77 -0
  140. data/ext/libcouchbase/doc/footer.html +22 -0
  141. data/ext/libcouchbase/doc/genman.sh +25 -0
  142. data/ext/libcouchbase/doc/header.html +52 -0
  143. data/ext/libcouchbase/doc/intro.h +130 -0
  144. data/ext/libcouchbase/doc/mainpage.h +136 -0
  145. data/ext/libcouchbase/doc/man/cbc-admin.1 +1 -0
  146. data/ext/libcouchbase/doc/man/cbc-bucket-create.1 +1 -0
  147. data/ext/libcouchbase/doc/man/cbc-bucket-delete.1 +1 -0
  148. data/ext/libcouchbase/doc/man/cbc-cat.1 +1 -0
  149. data/ext/libcouchbase/doc/man/cbc-connstr.1 +1 -0
  150. data/ext/libcouchbase/doc/man/cbc-cp.1 +1 -0
  151. data/ext/libcouchbase/doc/man/cbc-create.1 +1 -0
  152. data/ext/libcouchbase/doc/man/cbc-decr.1 +1 -0
  153. data/ext/libcouchbase/doc/man/cbc-flush.1 +1 -0
  154. data/ext/libcouchbase/doc/man/cbc-hash.1 +1 -0
  155. data/ext/libcouchbase/doc/man/cbc-incr.1 +1 -0
  156. data/ext/libcouchbase/doc/man/cbc-lock.1 +1 -0
  157. data/ext/libcouchbase/doc/man/cbc-mcflush.1 +1 -0
  158. data/ext/libcouchbase/doc/man/cbc-mcversion.1 +1 -0
  159. data/ext/libcouchbase/doc/man/cbc-n1ql.1 +1 -0
  160. data/ext/libcouchbase/doc/man/cbc-n1qlback.1 +198 -0
  161. data/ext/libcouchbase/doc/man/cbc-observe.1 +1 -0
  162. data/ext/libcouchbase/doc/man/cbc-pillowfight.1 +499 -0
  163. data/ext/libcouchbase/doc/man/cbc-ping.1 +1 -0
  164. data/ext/libcouchbase/doc/man/cbc-rm.1 +1 -0
  165. data/ext/libcouchbase/doc/man/cbc-role-list.1 +1 -0
  166. data/ext/libcouchbase/doc/man/cbc-stats.1 +1 -0
  167. data/ext/libcouchbase/doc/man/cbc-subdoc.1 +494 -0
  168. data/ext/libcouchbase/doc/man/cbc-unlock.1 +1 -0
  169. data/ext/libcouchbase/doc/man/cbc-user-delete.1 +1 -0
  170. data/ext/libcouchbase/doc/man/cbc-user-list.1 +1 -0
  171. data/ext/libcouchbase/doc/man/cbc-user-upsert.1 +1 -0
  172. data/ext/libcouchbase/doc/man/cbc-verbosity.1 +1 -0
  173. data/ext/libcouchbase/doc/man/cbc-version.1 +1 -0
  174. data/ext/libcouchbase/doc/man/cbc-view.1 +1 -0
  175. data/ext/libcouchbase/doc/man/cbc-watch.1 +1 -0
  176. data/ext/libcouchbase/doc/man/cbc.1 +1035 -0
  177. data/ext/libcouchbase/doc/man/cbcrc.4 +71 -0
  178. data/ext/libcouchbase/doc/style.css +1162 -0
  179. data/ext/libcouchbase/example/CMakeLists.txt +52 -0
  180. data/ext/libcouchbase/example/README.markdown +47 -0
  181. data/ext/libcouchbase/example/analytics/.gitignore +1 -0
  182. data/ext/libcouchbase/example/analytics/analytics.c +158 -0
  183. data/ext/libcouchbase/example/analytics/build-queries.rb +34 -0
  184. data/ext/libcouchbase/example/analytics/cJSON.c +1 -0
  185. data/ext/libcouchbase/example/analytics/cJSON.h +1 -0
  186. data/ext/libcouchbase/example/analytics/queries/00-show-dataverse.json +5 -0
  187. data/ext/libcouchbase/example/analytics/queries/01-setup-dataset-breweries.json +6 -0
  188. data/ext/libcouchbase/example/analytics/queries/02-setup-dataset-beers.json +6 -0
  189. data/ext/libcouchbase/example/analytics/queries/03-initiate-shadow.json +6 -0
  190. data/ext/libcouchbase/example/analytics/queries/04-list-datasets.json +7 -0
  191. data/ext/libcouchbase/example/analytics/queries/05-count-breweries.json +5 -0
  192. data/ext/libcouchbase/example/analytics/queries/06-first-brewery.json +6 -0
  193. data/ext/libcouchbase/example/analytics/queries/07-key-based-lookup.json +6 -0
  194. data/ext/libcouchbase/example/analytics/queries/08-exact-match-lookup.json +7 -0
  195. data/ext/libcouchbase/example/analytics/queries/09-exact-match-lookup-different-shape.json +6 -0
  196. data/ext/libcouchbase/example/analytics/queries/10-other-query-filters.json +6 -0
  197. data/ext/libcouchbase/example/analytics/queries/11-equijoin.json +9 -0
  198. data/ext/libcouchbase/example/analytics/queries/12-equijoin-select-star.json +10 -0
  199. data/ext/libcouchbase/example/analytics/queries/13-ansi-join.json +8 -0
  200. data/ext/libcouchbase/example/analytics/queries/14-join-select-values.json +8 -0
  201. data/ext/libcouchbase/example/analytics/queries/15-nested-outer-join.json +7 -0
  202. data/ext/libcouchbase/example/analytics/queries/16-theta-join.json +8 -0
  203. data/ext/libcouchbase/example/analytics/queries/17-existential-quantification.json +9 -0
  204. data/ext/libcouchbase/example/analytics/queries/18-universal-quantification.json +7 -0
  205. data/ext/libcouchbase/example/analytics/queries/19-simple-aggregation.json +6 -0
  206. data/ext/libcouchbase/example/analytics/queries/20-simple-aggregation-unwrapped-value.json +6 -0
  207. data/ext/libcouchbase/example/analytics/queries/21-simple-aggregation-explicit.json +6 -0
  208. data/ext/libcouchbase/example/analytics/queries/22-grouping-and-aggregation.json +6 -0
  209. data/ext/libcouchbase/example/analytics/queries/23-grouping-and-aggregation-with-hint.json +7 -0
  210. data/ext/libcouchbase/example/analytics/queries/24-grouping-and-limits.json +7 -0
  211. data/ext/libcouchbase/example/analytics/queries/25-named-parameters.json +7 -0
  212. data/ext/libcouchbase/example/analytics/queries/26-positional-parameters.json +7 -0
  213. data/ext/libcouchbase/example/analytics/queries.h +113 -0
  214. data/ext/libcouchbase/example/crypto/.gitignore +2 -0
  215. data/ext/libcouchbase/example/crypto/Makefile +13 -0
  216. data/ext/libcouchbase/example/crypto/common_provider.c +26 -0
  217. data/ext/libcouchbase/example/crypto/common_provider.h +33 -0
  218. data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +144 -0
  219. data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +146 -0
  220. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +271 -0
  221. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.h +29 -0
  222. data/ext/libcouchbase/example/db/db.c +171 -0
  223. data/ext/libcouchbase/example/db/vb.c +227 -0
  224. data/ext/libcouchbase/example/fts/.gitignore +1 -0
  225. data/ext/libcouchbase/example/fts/build-queries.rb +33 -0
  226. data/ext/libcouchbase/example/fts/fts.c +142 -0
  227. data/ext/libcouchbase/example/fts/queries/00-simple-text-query.json +12 -0
  228. data/ext/libcouchbase/example/fts/queries/01-simple-text-query-on-non-default-index.json +9 -0
  229. data/ext/libcouchbase/example/fts/queries/02-simple-text-query-on-stored-field.json +13 -0
  230. data/ext/libcouchbase/example/fts/queries/03-match-query-with-facet.json +19 -0
  231. data/ext/libcouchbase/example/fts/queries/04-docid-query.json +11 -0
  232. data/ext/libcouchbase/example/fts/queries/05-unanalyzed-term-query-with-fuzziness-level-of-0.json +13 -0
  233. data/ext/libcouchbase/example/fts/queries/06-unanalyzed-term-query-with-fuzziness-level-of-2.json +14 -0
  234. data/ext/libcouchbase/example/fts/queries/07-match-phrase-query.json +13 -0
  235. data/ext/libcouchbase/example/fts/queries/08-phrase-query.json +16 -0
  236. data/ext/libcouchbase/example/fts/queries/09-query-string-query.json +9 -0
  237. data/ext/libcouchbase/example/fts/queries/10-conjunction-query.json +21 -0
  238. data/ext/libcouchbase/example/fts/queries/11-wild-card-query.json +13 -0
  239. data/ext/libcouchbase/example/fts/queries/12-numeric-range-query.json +11 -0
  240. data/ext/libcouchbase/example/fts/queries/13-regexp-query.json +13 -0
  241. data/ext/libcouchbase/example/fts/queries.h +61 -0
  242. data/ext/libcouchbase/example/instancepool/main.cc +112 -0
  243. data/ext/libcouchbase/example/instancepool/pool.cc +102 -0
  244. data/ext/libcouchbase/example/instancepool/pool.h +69 -0
  245. data/ext/libcouchbase/example/libeventdirect/main.c +222 -0
  246. data/ext/libcouchbase/example/mcc/mcc.cc +246 -0
  247. data/ext/libcouchbase/example/minimal/.gitignore +1 -0
  248. data/ext/libcouchbase/example/minimal/minimal.c +132 -0
  249. data/ext/libcouchbase/example/minimal/query.c +185 -0
  250. data/ext/libcouchbase/example/observe/durability.c +102 -0
  251. data/ext/libcouchbase/example/observe/observe.c +159 -0
  252. data/ext/libcouchbase/example/subdoc/subdoc-multi.cc +143 -0
  253. data/ext/libcouchbase/example/subdoc/subdoc-simple.cc +201 -0
  254. data/ext/libcouchbase/example/subdoc/subdoc-xattrs.c +286 -0
  255. data/ext/libcouchbase/example/tick/tick.c +119 -0
  256. data/ext/libcouchbase/example/tracing/.gitignore +2 -0
  257. data/ext/libcouchbase/example/tracing/Makefile +8 -0
  258. data/ext/libcouchbase/example/tracing/cJSON.c +1 -0
  259. data/ext/libcouchbase/example/tracing/cJSON.h +1 -0
  260. data/ext/libcouchbase/example/tracing/tracing.c +439 -0
  261. data/ext/libcouchbase/example/tracing/views.c +444 -0
  262. data/ext/libcouchbase/example/users/README +48 -0
  263. data/ext/libcouchbase/example/users/users.c +147 -0
  264. data/ext/libcouchbase/example/views/views-example.cc +83 -0
  265. data/ext/libcouchbase/include/libcouchbase/_cxxwrap.h +150 -0
  266. data/ext/libcouchbase/include/libcouchbase/api-legacy.h +1689 -0
  267. data/ext/libcouchbase/include/libcouchbase/api3.h +2 -0
  268. data/ext/libcouchbase/include/libcouchbase/assert.h +44 -0
  269. data/ext/libcouchbase/include/libcouchbase/auth.h +297 -0
  270. data/ext/libcouchbase/include/libcouchbase/cbft.h +151 -0
  271. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +319 -0
  272. data/ext/libcouchbase/include/libcouchbase/cntl.h +1418 -0
  273. data/ext/libcouchbase/include/libcouchbase/configuration.h.in +29 -0
  274. data/ext/libcouchbase/include/libcouchbase/couchbase.h +4089 -0
  275. data/ext/libcouchbase/include/libcouchbase/crypto.h +306 -0
  276. data/ext/libcouchbase/include/libcouchbase/deprecated.h +312 -0
  277. data/ext/libcouchbase/include/libcouchbase/error.h +680 -0
  278. data/ext/libcouchbase/include/libcouchbase/http.h +1 -0
  279. data/ext/libcouchbase/include/libcouchbase/iops.h +1053 -0
  280. data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +263 -0
  281. data/ext/libcouchbase/include/libcouchbase/kvbuf.h +137 -0
  282. data/ext/libcouchbase/include/libcouchbase/metrics.h +79 -0
  283. data/ext/libcouchbase/include/libcouchbase/n1ql.h +539 -0
  284. data/ext/libcouchbase/include/libcouchbase/pktfwd.h +270 -0
  285. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +370 -0
  286. data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr-inl.c +76 -0
  287. data/ext/libcouchbase/include/libcouchbase/plugins/io/wsaerr.h +199 -0
  288. data/ext/libcouchbase/include/libcouchbase/subdoc.h +347 -0
  289. data/ext/libcouchbase/include/libcouchbase/sysdefs.h +98 -0
  290. data/ext/libcouchbase/include/libcouchbase/tracing.h +437 -0
  291. data/ext/libcouchbase/include/libcouchbase/vbucket.h +680 -0
  292. data/ext/libcouchbase/include/libcouchbase/views.h +357 -0
  293. data/ext/libcouchbase/include/libcouchbase/visibility.h +66 -0
  294. data/ext/libcouchbase/include/memcached/COPYING +30 -0
  295. data/ext/libcouchbase/include/memcached/README +10 -0
  296. data/ext/libcouchbase/include/memcached/protocol_binary.h +885 -0
  297. data/ext/libcouchbase/packaging/README +7 -0
  298. data/ext/libcouchbase/packaging/abicheck/.gitignore +4 -0
  299. data/ext/libcouchbase/packaging/abicheck/Makefile +17 -0
  300. data/ext/libcouchbase/packaging/abicheck/README.md +27 -0
  301. data/ext/libcouchbase/packaging/abicheck/template.xml +3 -0
  302. data/ext/libcouchbase/packaging/deb/compat +1 -0
  303. data/ext/libcouchbase/packaging/deb/control +72 -0
  304. data/ext/libcouchbase/packaging/deb/copyright +10 -0
  305. data/ext/libcouchbase/packaging/deb/libcouchbase-dev.docs +3 -0
  306. data/ext/libcouchbase/packaging/deb/package.mk +31 -0
  307. data/ext/libcouchbase/packaging/deb/rules +46 -0
  308. data/ext/libcouchbase/packaging/deb/source/format +1 -0
  309. data/ext/libcouchbase/packaging/distinfo/README +1 -0
  310. data/ext/libcouchbase/packaging/distinfo/distinfo.cmake.in +4 -0
  311. data/ext/libcouchbase/packaging/dllversion.rc.in +39 -0
  312. data/ext/libcouchbase/packaging/libcouchbase.pc.in +10 -0
  313. data/ext/libcouchbase/packaging/nuget/libcouchbase.autopkg +76 -0
  314. data/ext/libcouchbase/packaging/parse-git-describe.pl +166 -0
  315. data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +101 -0
  316. data/ext/libcouchbase/packaging/rpm/package.mk +40 -0
  317. data/ext/libcouchbase/plugins/io/iocp/CMakeLists.txt +9 -0
  318. data/ext/libcouchbase/plugins/io/iocp/iocp_iops.c +467 -0
  319. data/ext/libcouchbase/plugins/io/iocp/iocp_iops.h +217 -0
  320. data/ext/libcouchbase/plugins/io/iocp/iocp_loop.c +295 -0
  321. data/ext/libcouchbase/plugins/io/iocp/iocp_timer.c +79 -0
  322. data/ext/libcouchbase/plugins/io/iocp/iocp_util.c +229 -0
  323. data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +31 -0
  324. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +66 -0
  325. data/ext/libcouchbase/plugins/io/libev/plugin-libev.c +289 -0
  326. data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +31 -0
  327. data/ext/libcouchbase/plugins/io/libevent/libevent_io_opts.h +67 -0
  328. data/ext/libcouchbase/plugins/io/libevent/plugin-libevent.c +292 -0
  329. data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +44 -0
  330. data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +218 -0
  331. data/ext/libcouchbase/plugins/io/libuv/libuv_io_opts.h +118 -0
  332. data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +155 -0
  333. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +709 -0
  334. data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +13 -0
  335. data/ext/libcouchbase/plugins/io/select/plugin-select.c +451 -0
  336. data/ext/libcouchbase/plugins/io/select/select_io_opts.h +39 -0
  337. data/ext/libcouchbase/src/README.md +101 -0
  338. data/ext/libcouchbase/src/aspend.h +105 -0
  339. data/ext/libcouchbase/src/auth-priv.h +85 -0
  340. data/ext/libcouchbase/src/auth.cc +146 -0
  341. data/ext/libcouchbase/src/bootstrap.cc +263 -0
  342. data/ext/libcouchbase/src/bootstrap.h +149 -0
  343. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +450 -0
  344. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  345. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +527 -0
  346. data/ext/libcouchbase/src/bucketconfig/bc_http.h +107 -0
  347. data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
  348. data/ext/libcouchbase/src/bucketconfig/clconfig.h +700 -0
  349. data/ext/libcouchbase/src/bucketconfig/confmon.cc +403 -0
  350. data/ext/libcouchbase/src/callbacks.c +380 -0
  351. data/ext/libcouchbase/src/cbft.cc +253 -0
  352. data/ext/libcouchbase/src/cntl.cc +1057 -0
  353. data/ext/libcouchbase/src/config_static.h +176 -0
  354. data/ext/libcouchbase/src/connspec.cc +555 -0
  355. data/ext/libcouchbase/src/connspec.h +155 -0
  356. data/ext/libcouchbase/src/crypto.cc +399 -0
  357. data/ext/libcouchbase/src/ctx-log-inl.h +44 -0
  358. data/ext/libcouchbase/src/dns-srv.cc +146 -0
  359. data/ext/libcouchbase/src/dump.cc +103 -0
  360. data/ext/libcouchbase/src/errmap.cc +173 -0
  361. data/ext/libcouchbase/src/errmap.h +271 -0
  362. data/ext/libcouchbase/src/getconfig.cc +72 -0
  363. data/ext/libcouchbase/src/gethrtime.c +109 -0
  364. data/ext/libcouchbase/src/handler.cc +1101 -0
  365. data/ext/libcouchbase/src/hashtable.c +75 -0
  366. data/ext/libcouchbase/src/hdr_timings.c +92 -0
  367. data/ext/libcouchbase/src/hostlist.cc +293 -0
  368. data/ext/libcouchbase/src/hostlist.h +160 -0
  369. data/ext/libcouchbase/src/http/http-priv.h +326 -0
  370. data/ext/libcouchbase/src/http/http.cc +672 -0
  371. data/ext/libcouchbase/src/http/http.h +1 -0
  372. data/ext/libcouchbase/src/http/http_io.cc +316 -0
  373. data/ext/libcouchbase/src/instance.cc +917 -0
  374. data/ext/libcouchbase/src/internal.h +285 -0
  375. data/ext/libcouchbase/src/iofactory.c +575 -0
  376. data/ext/libcouchbase/src/jsparse/parser.cc +445 -0
  377. data/ext/libcouchbase/src/jsparse/parser.h +159 -0
  378. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  379. data/ext/libcouchbase/src/lcbht/lcbht.h +210 -0
  380. data/ext/libcouchbase/src/lcbio/connect.cc +603 -0
  381. data/ext/libcouchbase/src/lcbio/connect.h +400 -0
  382. data/ext/libcouchbase/src/lcbio/ctx.c +658 -0
  383. data/ext/libcouchbase/src/lcbio/ctx.h +405 -0
  384. data/ext/libcouchbase/src/lcbio/iotable.c +290 -0
  385. data/ext/libcouchbase/src/lcbio/iotable.h +169 -0
  386. data/ext/libcouchbase/src/lcbio/ioutils.cc +356 -0
  387. data/ext/libcouchbase/src/lcbio/ioutils.h +144 -0
  388. data/ext/libcouchbase/src/lcbio/lcbio.h +51 -0
  389. data/ext/libcouchbase/src/lcbio/manager.cc +579 -0
  390. data/ext/libcouchbase/src/lcbio/manager.h +195 -0
  391. data/ext/libcouchbase/src/lcbio/protoctx.c +84 -0
  392. data/ext/libcouchbase/src/lcbio/rw-inl.h +137 -0
  393. data/ext/libcouchbase/src/lcbio/ssl.h +159 -0
  394. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  395. data/ext/libcouchbase/src/lcbio/timer-ng.h +179 -0
  396. data/ext/libcouchbase/src/lcbio/timer.c +132 -0
  397. data/ext/libcouchbase/src/legacy.c +431 -0
  398. data/ext/libcouchbase/src/list.c +144 -0
  399. data/ext/libcouchbase/src/list.h +127 -0
  400. data/ext/libcouchbase/src/logging.c +244 -0
  401. data/ext/libcouchbase/src/logging.h +88 -0
  402. data/ext/libcouchbase/src/mc/compress.cc +171 -0
  403. data/ext/libcouchbase/src/mc/compress.h +56 -0
  404. data/ext/libcouchbase/src/mc/forward.c +186 -0
  405. data/ext/libcouchbase/src/mc/forward.h +90 -0
  406. data/ext/libcouchbase/src/mc/iovcursor-inl.h +279 -0
  407. data/ext/libcouchbase/src/mc/iovcursor.h +66 -0
  408. data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +115 -0
  409. data/ext/libcouchbase/src/mc/mcreq.c +983 -0
  410. data/ext/libcouchbase/src/mc/mcreq.h +1015 -0
  411. data/ext/libcouchbase/src/mcserver/mcserver.cc +1055 -0
  412. data/ext/libcouchbase/src/mcserver/mcserver.h +221 -0
  413. data/ext/libcouchbase/src/mcserver/negotiate.cc +757 -0
  414. data/ext/libcouchbase/src/mcserver/negotiate.h +128 -0
  415. data/ext/libcouchbase/src/mctx-helper.h +62 -0
  416. data/ext/libcouchbase/src/metrics.cc +132 -0
  417. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +857 -0
  418. data/ext/libcouchbase/src/n1ql/n1ql-internal.h +22 -0
  419. data/ext/libcouchbase/src/n1ql/n1ql.cc +830 -0
  420. data/ext/libcouchbase/src/n1ql/params.cc +260 -0
  421. data/ext/libcouchbase/src/netbuf/netbuf-defs.h +89 -0
  422. data/ext/libcouchbase/src/netbuf/netbuf-mblock.h +235 -0
  423. data/ext/libcouchbase/src/netbuf/netbuf.c +929 -0
  424. data/ext/libcouchbase/src/netbuf/netbuf.h +452 -0
  425. data/ext/libcouchbase/src/newconfig.cc +365 -0
  426. data/ext/libcouchbase/src/nodeinfo.cc +184 -0
  427. data/ext/libcouchbase/src/operations/cbflush.cc +63 -0
  428. data/ext/libcouchbase/src/operations/counter.cc +117 -0
  429. data/ext/libcouchbase/src/operations/durability-cas.cc +251 -0
  430. data/ext/libcouchbase/src/operations/durability-seqno.cc +170 -0
  431. data/ext/libcouchbase/src/operations/durability.cc +668 -0
  432. data/ext/libcouchbase/src/operations/durability_internal.h +306 -0
  433. data/ext/libcouchbase/src/operations/get.cc +409 -0
  434. data/ext/libcouchbase/src/operations/observe-seqno.cc +94 -0
  435. data/ext/libcouchbase/src/operations/observe.cc +367 -0
  436. data/ext/libcouchbase/src/operations/ping.cc +496 -0
  437. data/ext/libcouchbase/src/operations/pktfwd.cc +86 -0
  438. data/ext/libcouchbase/src/operations/remove.cc +84 -0
  439. data/ext/libcouchbase/src/operations/stats.cc +459 -0
  440. data/ext/libcouchbase/src/operations/store.cc +358 -0
  441. data/ext/libcouchbase/src/operations/subdoc.cc +614 -0
  442. data/ext/libcouchbase/src/operations/touch.cc +84 -0
  443. data/ext/libcouchbase/src/packetutils.h +388 -0
  444. data/ext/libcouchbase/src/probes.d +182 -0
  445. data/ext/libcouchbase/src/rdb/bigalloc.c +225 -0
  446. data/ext/libcouchbase/src/rdb/bigalloc.h +73 -0
  447. data/ext/libcouchbase/src/rdb/chunkalloc.c +174 -0
  448. data/ext/libcouchbase/src/rdb/libcalloc.c +94 -0
  449. data/ext/libcouchbase/src/rdb/rope.c +419 -0
  450. data/ext/libcouchbase/src/rdb/rope.h +488 -0
  451. data/ext/libcouchbase/src/retrychk.cc +113 -0
  452. data/ext/libcouchbase/src/retryq.cc +458 -0
  453. data/ext/libcouchbase/src/retryq.h +170 -0
  454. data/ext/libcouchbase/src/ringbuffer.c +442 -0
  455. data/ext/libcouchbase/src/ringbuffer.h +100 -0
  456. data/ext/libcouchbase/src/rnd.cc +61 -0
  457. data/ext/libcouchbase/src/rnd.h +39 -0
  458. data/ext/libcouchbase/src/settings.c +125 -0
  459. data/ext/libcouchbase/src/settings.h +273 -0
  460. data/ext/libcouchbase/src/sllist-inl.h +197 -0
  461. data/ext/libcouchbase/src/sllist.h +76 -0
  462. data/ext/libcouchbase/src/ssl/CMakeLists.txt +11 -0
  463. data/ext/libcouchbase/src/ssl/ssl_c.c +442 -0
  464. data/ext/libcouchbase/src/ssl/ssl_common.c +478 -0
  465. data/ext/libcouchbase/src/ssl/ssl_e.c +421 -0
  466. data/ext/libcouchbase/src/ssl/ssl_iot_common.h +182 -0
  467. data/ext/libcouchbase/src/strcodecs/base64.c +307 -0
  468. data/ext/libcouchbase/src/strcodecs/strcodecs.h +302 -0
  469. data/ext/libcouchbase/src/timings.c +207 -0
  470. data/ext/libcouchbase/src/trace.h +117 -0
  471. data/ext/libcouchbase/src/tracing/span.cc +421 -0
  472. data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +213 -0
  473. data/ext/libcouchbase/src/tracing/tracer.cc +53 -0
  474. data/ext/libcouchbase/src/tracing/tracing-internal.h +198 -0
  475. data/ext/libcouchbase/src/utilities.c +176 -0
  476. data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -0
  477. data/ext/libcouchbase/src/vbucket/aliases.h +35 -0
  478. data/ext/libcouchbase/src/vbucket/crc32.h +83 -0
  479. data/ext/libcouchbase/src/vbucket/hash.h +30 -0
  480. data/ext/libcouchbase/src/vbucket/json-inl.h +112 -0
  481. data/ext/libcouchbase/src/vbucket/ketama.c +66 -0
  482. data/ext/libcouchbase/src/vbucket/rfc1321/global.h +32 -0
  483. data/ext/libcouchbase/src/vbucket/rfc1321/md5.h +35 -0
  484. data/ext/libcouchbase/src/vbucket/rfc1321/md5c-inl.h +335 -0
  485. data/ext/libcouchbase/src/vbucket/vbucket.c +1735 -0
  486. data/ext/libcouchbase/src/views/docreq.cc +213 -0
  487. data/ext/libcouchbase/src/views/docreq.h +94 -0
  488. data/ext/libcouchbase/src/views/viewreq.cc +381 -0
  489. data/ext/libcouchbase/src/views/viewreq.h +87 -0
  490. data/ext/libcouchbase/src/wait.cc +156 -0
  491. data/ext/libcouchbase/tests/CMakeLists.txt +149 -0
  492. data/ext/libcouchbase/tests/basic/t_base64.cc +109 -0
  493. data/ext/libcouchbase/tests/basic/t_ccbc103.cc +95 -0
  494. data/ext/libcouchbase/tests/basic/t_connstr.cc +456 -0
  495. data/ext/libcouchbase/tests/basic/t_creds.cc +96 -0
  496. data/ext/libcouchbase/tests/basic/t_ctlcodes.cc +92 -0
  497. data/ext/libcouchbase/tests/basic/t_host.cc +210 -0
  498. data/ext/libcouchbase/tests/basic/t_jsparse.cc +82 -0
  499. data/ext/libcouchbase/tests/basic/t_jsparse.h +589 -0
  500. data/ext/libcouchbase/tests/basic/t_list.cc +155 -0
  501. data/ext/libcouchbase/tests/basic/t_logger.cc +65 -0
  502. data/ext/libcouchbase/tests/basic/t_misc.cc +24 -0
  503. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +17 -0
  504. data/ext/libcouchbase/tests/basic/t_netbuf.cc +446 -0
  505. data/ext/libcouchbase/tests/basic/t_packet.cc +215 -0
  506. data/ext/libcouchbase/tests/basic/t_ringbuffer.cc +278 -0
  507. data/ext/libcouchbase/tests/basic/t_scram.cc +514 -0
  508. data/ext/libcouchbase/tests/basic/t_slist.cc +429 -0
  509. data/ext/libcouchbase/tests/basic/t_strerror.cc +64 -0
  510. data/ext/libcouchbase/tests/basic/t_urlencode.cc +132 -0
  511. data/ext/libcouchbase/tests/check-all.cc +612 -0
  512. data/ext/libcouchbase/tests/htparse/t_basic.cc +173 -0
  513. data/ext/libcouchbase/tests/ioserver/connection.cc +166 -0
  514. data/ext/libcouchbase/tests/ioserver/future.cc +50 -0
  515. data/ext/libcouchbase/tests/ioserver/ioserver.cc +117 -0
  516. data/ext/libcouchbase/tests/ioserver/ioserver.h +478 -0
  517. data/ext/libcouchbase/tests/ioserver/socket.cc +88 -0
  518. data/ext/libcouchbase/tests/ioserver/ssl_connection.cc +145 -0
  519. data/ext/libcouchbase/tests/ioserver/threads-pthreads.cc +119 -0
  520. data/ext/libcouchbase/tests/ioserver/threads-win32.cc +117 -0
  521. data/ext/libcouchbase/tests/ioserver/threads.h +66 -0
  522. data/ext/libcouchbase/tests/iotests/iotests.h +15 -0
  523. data/ext/libcouchbase/tests/iotests/mock-environment.cc +632 -0
  524. data/ext/libcouchbase/tests/iotests/mock-environment.h +480 -0
  525. data/ext/libcouchbase/tests/iotests/mock-unit-test.cc +67 -0
  526. data/ext/libcouchbase/tests/iotests/mock-unit-test.h +61 -0
  527. data/ext/libcouchbase/tests/iotests/serverparams.h +76 -0
  528. data/ext/libcouchbase/tests/iotests/t_arithmetic.cc +143 -0
  529. data/ext/libcouchbase/tests/iotests/t_behavior.cc +220 -0
  530. data/ext/libcouchbase/tests/iotests/t_configcache.cc +117 -0
  531. data/ext/libcouchbase/tests/iotests/t_confmon.cc +223 -0
  532. data/ext/libcouchbase/tests/iotests/t_durability.cc +1108 -0
  533. data/ext/libcouchbase/tests/iotests/t_eerrs.cc +121 -0
  534. data/ext/libcouchbase/tests/iotests/t_errmap.cc +181 -0
  535. data/ext/libcouchbase/tests/iotests/t_forward.cc +118 -0
  536. data/ext/libcouchbase/tests/iotests/t_get.cc +512 -0
  537. data/ext/libcouchbase/tests/iotests/t_http.cc +438 -0
  538. data/ext/libcouchbase/tests/iotests/t_iops.cc +175 -0
  539. data/ext/libcouchbase/tests/iotests/t_lock.cc +274 -0
  540. data/ext/libcouchbase/tests/iotests/t_misc.cc +777 -0
  541. data/ext/libcouchbase/tests/iotests/t_mutate.cc +609 -0
  542. data/ext/libcouchbase/tests/iotests/t_n1ql.cc +270 -0
  543. data/ext/libcouchbase/tests/iotests/t_netfail.cc +778 -0
  544. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +156 -0
  545. data/ext/libcouchbase/tests/iotests/t_regression.cc +321 -0
  546. data/ext/libcouchbase/tests/iotests/t_sched.cc +87 -0
  547. data/ext/libcouchbase/tests/iotests/t_serverops.cc +231 -0
  548. data/ext/libcouchbase/tests/iotests/t_smoke.cc +528 -0
  549. data/ext/libcouchbase/tests/iotests/t_snappy.cc +316 -0
  550. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +857 -0
  551. data/ext/libcouchbase/tests/iotests/t_syncmode.cc +64 -0
  552. data/ext/libcouchbase/tests/iotests/t_views.cc +417 -0
  553. data/ext/libcouchbase/tests/iotests/testutil.cc +251 -0
  554. data/ext/libcouchbase/tests/iotests/testutil.h +163 -0
  555. data/ext/libcouchbase/tests/mc/mctest.h +119 -0
  556. data/ext/libcouchbase/tests/mc/pktmaker.h +101 -0
  557. data/ext/libcouchbase/tests/mc/t_alloc.cc +269 -0
  558. data/ext/libcouchbase/tests/mc/t_context.cc +100 -0
  559. data/ext/libcouchbase/tests/mc/t_flush.cc +185 -0
  560. data/ext/libcouchbase/tests/mc/t_forward.cc +239 -0
  561. data/ext/libcouchbase/tests/mc/t_ioflush.cc +102 -0
  562. data/ext/libcouchbase/tests/mc/t_iovcursor.cc +173 -0
  563. data/ext/libcouchbase/tests/mocksupport/procutil.c +305 -0
  564. data/ext/libcouchbase/tests/mocksupport/procutil.h +89 -0
  565. data/ext/libcouchbase/tests/mocksupport/server.c +391 -0
  566. data/ext/libcouchbase/tests/mocksupport/server.h +72 -0
  567. data/ext/libcouchbase/tests/mocksupport/timeout.c +69 -0
  568. data/ext/libcouchbase/tests/nonio_tests.cc +23 -0
  569. data/ext/libcouchbase/tests/rdb/rdbtest.h +133 -0
  570. data/ext/libcouchbase/tests/rdb/t_basic.cc +128 -0
  571. data/ext/libcouchbase/tests/rdb/t_bigalloc.cc +93 -0
  572. data/ext/libcouchbase/tests/rdb/t_refs.cc +112 -0
  573. data/ext/libcouchbase/tests/socktests/socktest.cc +344 -0
  574. data/ext/libcouchbase/tests/socktests/socktest.h +447 -0
  575. data/ext/libcouchbase/tests/socktests/t_basic.cc +143 -0
  576. data/ext/libcouchbase/tests/socktests/t_ctx.cc +73 -0
  577. data/ext/libcouchbase/tests/socktests/t_manager.cc +159 -0
  578. data/ext/libcouchbase/tests/socktests/t_putex.cc +256 -0
  579. data/ext/libcouchbase/tests/socktests/t_read.cc +187 -0
  580. data/ext/libcouchbase/tests/socktests/t_reentrant.cc +143 -0
  581. data/ext/libcouchbase/tests/socktests/t_ssl.cc +80 -0
  582. data/ext/libcouchbase/tests/socktests/t_write.cc +95 -0
  583. data/ext/libcouchbase/tests/start_mock.bat +15 -0
  584. data/ext/libcouchbase/tests/start_mock.sh +42 -0
  585. data/ext/libcouchbase/tests/unit_tests.cc +43 -0
  586. data/ext/libcouchbase/tests/vbucket/confdata/bad.json +101 -0
  587. data/ext/libcouchbase/tests/vbucket/confdata/full_25.json +363 -0
  588. data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
  589. data/ext/libcouchbase/tests/vbucket/confdata/map_node_present_nodesext_missing_nodes.json +94 -0
  590. data/ext/libcouchbase/tests/vbucket/confdata/memd_25.json +90 -0
  591. data/ext/libcouchbase/tests/vbucket/confdata/memd_30.json +1 -0
  592. data/ext/libcouchbase/tests/vbucket/confdata/memd_45.json +1 -0
  593. data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
  594. data/ext/libcouchbase/tests/vbucket/confdata/terse_25.json +291 -0
  595. data/ext/libcouchbase/tests/vbucket/confdata/terse_30.json +1 -0
  596. data/ext/libcouchbase/tests/vbucket/t_config.cc +386 -0
  597. data/ext/libcouchbase/tools/CMakeLists.txt +80 -0
  598. data/ext/libcouchbase/tools/cbc-handlers.h +636 -0
  599. data/ext/libcouchbase/tools/cbc-n1qlback.cc +496 -0
  600. data/ext/libcouchbase/tools/cbc-pillowfight.cc +1230 -0
  601. data/ext/libcouchbase/tools/cbc-proxy.cc +534 -0
  602. data/ext/libcouchbase/tools/cbc-subdoc.cc +825 -0
  603. data/ext/libcouchbase/tools/cbc.cc +1928 -0
  604. data/ext/libcouchbase/tools/common/histogram.cc +44 -0
  605. data/ext/libcouchbase/tools/common/histogram.h +23 -0
  606. data/ext/libcouchbase/tools/common/options.cc +451 -0
  607. data/ext/libcouchbase/tools/common/options.h +90 -0
  608. data/ext/libcouchbase/tools/docgen/docgen.h +495 -0
  609. data/ext/libcouchbase/tools/docgen/loc.h +211 -0
  610. data/ext/libcouchbase/tools/docgen/placeholders.h +211 -0
  611. data/ext/libcouchbase/tools/docgen/seqgen.h +122 -0
  612. data/ext/libcouchbase/tools/extract-packets.rb +110 -0
  613. data/ext/libcouchbase/tools/linenoise/linenoise.c +1199 -0
  614. data/ext/libcouchbase/tools/linenoise/linenoise.h +73 -0
  615. data/lib/mt-libcouchbase/bucket.rb +825 -0
  616. data/lib/mt-libcouchbase/callbacks.rb +69 -0
  617. data/lib/mt-libcouchbase/connection.rb +896 -0
  618. data/lib/mt-libcouchbase/design_docs.rb +92 -0
  619. data/lib/mt-libcouchbase/error.rb +68 -0
  620. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdbase.rb +23 -0
  621. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdcounter.rb +36 -0
  622. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdendure.rb +26 -0
  623. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdfts.rb +24 -0
  624. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdget.rb +30 -0
  625. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdgetreplica.rb +49 -0
  626. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdhttp.rb +58 -0
  627. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdn1ql.rb +40 -0
  628. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdobseqno.rb +33 -0
  629. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdobserve.rb +30 -0
  630. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdstore.rb +40 -0
  631. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdstoredur.rb +45 -0
  632. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdsubdoc.rb +61 -0
  633. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdverbosity.rb +29 -0
  634. data/lib/mt-libcouchbase/ext/mt-libcouchbase/cmdviewquery.rb +61 -0
  635. data/lib/mt-libcouchbase/ext/mt-libcouchbase/contigbuf.rb +14 -0
  636. data/lib/mt-libcouchbase/ext/mt-libcouchbase/create_st.rb +15 -0
  637. data/lib/mt-libcouchbase/ext/mt-libcouchbase/create_st0.rb +23 -0
  638. data/lib/mt-libcouchbase/ext/mt-libcouchbase/create_st1.rb +26 -0
  639. data/lib/mt-libcouchbase/ext/mt-libcouchbase/create_st2.rb +32 -0
  640. data/lib/mt-libcouchbase/ext/mt-libcouchbase/create_st3.rb +26 -0
  641. data/lib/mt-libcouchbase/ext/mt-libcouchbase/crst_u.rb +20 -0
  642. data/lib/mt-libcouchbase/ext/mt-libcouchbase/durability_opts_st_v.rb +11 -0
  643. data/lib/mt-libcouchbase/ext/mt-libcouchbase/durability_opts_t.rb +14 -0
  644. data/lib/mt-libcouchbase/ext/mt-libcouchbase/durabilityopt_sv0.rb +63 -0
  645. data/lib/mt-libcouchbase/ext/mt-libcouchbase/enums.rb +1007 -0
  646. data/lib/mt-libcouchbase/ext/mt-libcouchbase/fragbuf.rb +18 -0
  647. data/lib/mt-libcouchbase/ext/mt-libcouchbase/ftshandle.rb +7 -0
  648. data/lib/mt-libcouchbase/ext/mt-libcouchbase/histogram.rb +34 -0
  649. data/lib/mt-libcouchbase/ext/mt-libcouchbase/http_request_t.rb +7 -0
  650. data/lib/mt-libcouchbase/ext/mt-libcouchbase/keybuf.rb +20 -0
  651. data/lib/mt-libcouchbase/ext/mt-libcouchbase/multicmd_ctx.rb +30 -0
  652. data/lib/mt-libcouchbase/ext/mt-libcouchbase/mutation_token.rb +17 -0
  653. data/lib/mt-libcouchbase/ext/mt-libcouchbase/n1qlhandle.rb +7 -0
  654. data/lib/mt-libcouchbase/ext/mt-libcouchbase/n1qlparams.rb +7 -0
  655. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respbase.rb +29 -0
  656. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respcounter.rb +32 -0
  657. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respendure.rb +49 -0
  658. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respfts.rb +40 -0
  659. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respget.rb +44 -0
  660. data/lib/mt-libcouchbase/ext/mt-libcouchbase/resphttp.rb +48 -0
  661. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respmcversion.rb +38 -0
  662. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respn1ql.rb +41 -0
  663. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respobseqno.rb +52 -0
  664. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respobserve.rb +41 -0
  665. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respserverbase.rb +32 -0
  666. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respstats.rb +38 -0
  667. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respstore.rb +32 -0
  668. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respstoredur.rb +38 -0
  669. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respsubdoc.rb +35 -0
  670. data/lib/mt-libcouchbase/ext/mt-libcouchbase/respviewquery.rb +67 -0
  671. data/lib/mt-libcouchbase/ext/mt-libcouchbase/sdentry.rb +22 -0
  672. data/lib/mt-libcouchbase/ext/mt-libcouchbase/sdspec.rb +31 -0
  673. data/lib/mt-libcouchbase/ext/mt-libcouchbase/t.rb +7 -0
  674. data/lib/mt-libcouchbase/ext/mt-libcouchbase/valbuf.rb +22 -0
  675. data/lib/mt-libcouchbase/ext/mt-libcouchbase/valbuf_u_buf.rb +14 -0
  676. data/lib/mt-libcouchbase/ext/mt-libcouchbase/viewhandle.rb +7 -0
  677. data/lib/mt-libcouchbase/ext/mt-libcouchbase.rb +1175 -0
  678. data/lib/mt-libcouchbase/ext/mt-libcouchbase_libuv.rb +22 -0
  679. data/lib/mt-libcouchbase/ext/tasks.rb +39 -0
  680. data/lib/mt-libcouchbase/n1ql.rb +80 -0
  681. data/lib/mt-libcouchbase/query_full_text.rb +147 -0
  682. data/lib/mt-libcouchbase/query_n1ql.rb +123 -0
  683. data/lib/mt-libcouchbase/query_view.rb +135 -0
  684. data/lib/mt-libcouchbase/results_fiber.rb +281 -0
  685. data/lib/mt-libcouchbase/results_native.rb +220 -0
  686. data/lib/mt-libcouchbase/subdoc_request.rb +139 -0
  687. data/lib/mt-libcouchbase/version.rb +5 -0
  688. data/lib/mt-libcouchbase.rb +40 -0
  689. data/mt-libcouchbase.gemspec +68 -0
  690. data/spec/bucket_spec.rb +290 -0
  691. data/spec/connection_spec.rb +257 -0
  692. data/spec/design_docs_spec.rb +31 -0
  693. data/spec/error_spec.rb +26 -0
  694. data/spec/fts_spec.rb +135 -0
  695. data/spec/n1ql_spec.rb +260 -0
  696. data/spec/results_libuv_spec.rb +244 -0
  697. data/spec/results_native_spec.rb +259 -0
  698. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/design.json +1 -0
  699. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/data-0000.cbb +0 -0
  700. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/failover.json +1 -0
  701. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/meta.json +1 -0
  702. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/seqno.json +1 -0
  703. data/spec/seed/2016-10-25T043505Z/2016-10-25T043505Z-full/bucket-default/node-127.0.0.1%3A8091/snapshot_markers.json +1 -0
  704. data/spec/subdoc_spec.rb +192 -0
  705. data/spec/view_spec.rb +201 -0
  706. data/windows_build.md +36 -0
  707. metadata +873 -0
@@ -0,0 +1,1928 @@
1
+ #define NOMINMAX
2
+ #include <map>
3
+ #include <sstream>
4
+ #include <iostream>
5
+ #include <iomanip>
6
+ #include <fstream>
7
+ #include <algorithm>
8
+ #include <libcouchbase/vbucket.h>
9
+ #include <libcouchbase/views.h>
10
+ #include <libcouchbase/n1ql.h>
11
+ #include <limits>
12
+ #include <stddef.h>
13
+ #include <errno.h>
14
+ #include "common/options.h"
15
+ #include "common/histogram.h"
16
+ #include "cbc-handlers.h"
17
+ #include "connspec.h"
18
+ #include "contrib/lcb-jsoncpp/lcb-jsoncpp.h"
19
+
20
+ #ifndef LCB_NO_SSL
21
+ #include <openssl/crypto.h>
22
+ #endif
23
+ #include <snappy-stubs-public.h>
24
+
25
+ using namespace cbc;
26
+
27
+ using std::string;
28
+ using std::map;
29
+ using std::vector;
30
+ using std::stringstream;
31
+
32
+ string getRespKey(const lcb_RESPBASE* resp)
33
+ {
34
+ if (!resp->nkey) {
35
+ return "";
36
+ }
37
+
38
+ return string((const char *)resp->key, resp->nkey);
39
+ }
40
+
41
+ static void
42
+ printKeyError(string& key, int cbtype, const lcb_RESPBASE *resp, const char *additional = NULL)
43
+ {
44
+ fprintf(stderr, "%-20s %s (0x%x)\n", key.c_str(), lcb_strerror(NULL, resp->rc), resp->rc);
45
+ const char *ctx = lcb_resp_get_error_context(cbtype, resp);
46
+ if (ctx != NULL) {
47
+ fprintf(stderr, "%-20s %s\n", "", ctx);
48
+ }
49
+ const char *ref = lcb_resp_get_error_ref(cbtype, resp);
50
+ if (ref != NULL) {
51
+ fprintf(stderr, "%-20s Ref: %s\n", "", ref);
52
+ }
53
+ if (additional) {
54
+ fprintf(stderr, "%-20s %s\n", "", additional);
55
+ }
56
+ }
57
+
58
+ static void
59
+ printKeyCasStatus(string& key, int cbtype, const lcb_RESPBASE *resp,
60
+ const char *message = NULL)
61
+ {
62
+ fprintf(stderr, "%-20s", key.c_str());
63
+ if (message != NULL) {
64
+ fprintf(stderr, "%s ", message);
65
+ }
66
+ fprintf(stderr, "CAS=0x%" PRIx64 "\n", resp->cas);
67
+ const lcb_MUTATION_TOKEN *st = lcb_resp_get_mutation_token(cbtype, resp);
68
+ if (st != NULL) {
69
+ fprintf(stderr, "%-20sSYNCTOKEN=%u,%" PRIu64 ",%" PRIu64 "\n",
70
+ "", st->vbid_, st->uuid_, st->seqno_);
71
+ }
72
+ }
73
+
74
+ extern "C" {
75
+ static void
76
+ get_callback(lcb_t, lcb_CALLBACKTYPE cbtype, const lcb_RESPGET *resp)
77
+ {
78
+ string key = getRespKey((const lcb_RESPBASE *)resp);
79
+ if (resp->rc == LCB_SUCCESS) {
80
+ fprintf(stderr, "%-20s CAS=0x%" PRIx64 ", Flags=0x%x, Size=%lu, Datatype=0x%02x",
81
+ key.c_str(), resp->cas, resp->itmflags, (unsigned long)resp->nvalue,
82
+ (int)resp->datatype);
83
+ if (resp->datatype) {
84
+ int nflags = 0;
85
+ fprintf(stderr, "(");
86
+ if (resp->datatype & LCB_VALUE_F_JSON) {
87
+ fprintf(stderr, "JSON");
88
+ nflags++;
89
+ }
90
+ if (resp->datatype & LCB_VALUE_F_SNAPPYCOMP) {
91
+ fprintf(stderr, "%sSNAPPY", nflags > 0 ? "," : "");
92
+ nflags++;
93
+ }
94
+ fprintf(stderr, ")");
95
+ }
96
+ fprintf(stderr, "\n");
97
+ fflush(stderr);
98
+ fwrite(resp->value, 1, resp->nvalue, stdout);
99
+ fflush(stdout);
100
+ fprintf(stderr, "\n");
101
+ } else {
102
+ printKeyError(key, cbtype, (const lcb_RESPBASE *)resp);
103
+ }
104
+ }
105
+
106
+ static void
107
+ store_callback(lcb_t, lcb_CALLBACKTYPE cbtype, const lcb_RESPBASE *resp)
108
+ {
109
+ string key = getRespKey((const lcb_RESPBASE*)resp);
110
+
111
+ if (cbtype == LCB_CALLBACK_STOREDUR) {
112
+ // Storage with durability
113
+ const lcb_RESPSTOREDUR *dresp =
114
+ reinterpret_cast<const lcb_RESPSTOREDUR *>(resp);
115
+ char buf[4096];
116
+ if (resp->rc == LCB_SUCCESS) {
117
+ sprintf(buf, "Stored. Persisted(%u). Replicated(%u)",
118
+ dresp->dur_resp->npersisted, dresp->dur_resp->nreplicated);
119
+ printKeyCasStatus(key, cbtype, resp, buf);
120
+ } else {
121
+ if (dresp->store_ok) {
122
+ sprintf(buf, "Store OK, but durability failed. Persisted(%u). Replicated(%u)",
123
+ dresp->dur_resp->npersisted, dresp->dur_resp->nreplicated);
124
+ } else {
125
+ sprintf(buf, "%s", "Store failed");
126
+ }
127
+ printKeyError(key, cbtype, resp);
128
+ }
129
+ } else {
130
+ if (resp->rc == LCB_SUCCESS) {
131
+ printKeyCasStatus(key, cbtype, resp, "Stored.");
132
+ } else {
133
+ printKeyError(key, cbtype, resp);
134
+ }
135
+ }
136
+ }
137
+
138
+ static void
139
+ common_callback(lcb_t, int type, const lcb_RESPBASE *resp)
140
+ {
141
+ string key = getRespKey(resp);
142
+ if (resp->rc != LCB_SUCCESS) {
143
+ printKeyError(key, type, resp);
144
+ return;
145
+ }
146
+ switch (type) {
147
+ case LCB_CALLBACK_UNLOCK:
148
+ fprintf(stderr, "%-20s Unlocked\n", key.c_str());
149
+ break;
150
+ case LCB_CALLBACK_REMOVE:
151
+ printKeyCasStatus(key, type, resp, "Deleted.");
152
+ break;
153
+ case LCB_CALLBACK_TOUCH:
154
+ printKeyCasStatus(key, type, resp, "Touched.");
155
+ break;
156
+ default:
157
+ abort(); // didn't request it
158
+ }
159
+ }
160
+
161
+ static void
162
+ observe_callback(lcb_t, lcb_CALLBACKTYPE cbtype, const lcb_RESPOBSERVE *resp)
163
+ {
164
+ if (resp->nkey == 0) {
165
+ return;
166
+ }
167
+
168
+ string key = getRespKey((const lcb_RESPBASE *)resp);
169
+ if (resp->rc == LCB_SUCCESS) {
170
+ fprintf(stderr,
171
+ "%-20s [%s] Status=0x%x, CAS=0x%" PRIx64 "\n", key.c_str(),
172
+ resp->ismaster ? "Master" : "Replica",
173
+ resp->status, resp->cas);
174
+ } else {
175
+ printKeyError(key, cbtype, (const lcb_RESPBASE *)resp);
176
+ }
177
+ }
178
+
179
+ static void
180
+ obseqno_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPOBSEQNO *resp)
181
+ {
182
+ int ix = resp->server_index;
183
+ if (resp->rc != LCB_SUCCESS) {
184
+ fprintf(stderr,
185
+ "[%d] ERROR 0x%X (%s)\n", ix, resp->rc, lcb_strerror(NULL, resp->rc));
186
+ return;
187
+ }
188
+ lcb_U64 uuid, seq_disk, seq_mem;
189
+ if (resp->old_uuid) {
190
+ seq_disk = seq_mem = resp->old_seqno;
191
+ uuid = resp->old_uuid;
192
+ } else {
193
+ uuid = resp->cur_uuid;
194
+ seq_disk = resp->persisted_seqno;
195
+ seq_mem = resp->mem_seqno;
196
+ }
197
+ fprintf(stderr, "[%d] UUID=0x%" PRIx64 ", Cache=%" PRIu64 ", Disk=%" PRIu64,
198
+ ix, uuid, seq_mem, seq_disk);
199
+ if (resp->old_uuid) {
200
+ fprintf(stderr, "\n");
201
+ fprintf(stderr, " FAILOVER. New: UUID=%" PRIx64 ", Cache=%" PRIu64 ", Disk=%" PRIu64,
202
+ resp->cur_uuid, resp->mem_seqno, resp->persisted_seqno);
203
+ }
204
+ fprintf(stderr, "\n");
205
+ }
206
+
207
+ static void
208
+ stats_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPSTATS *resp)
209
+ {
210
+ if (resp->rc != LCB_SUCCESS) {
211
+ fprintf(stderr, "ERROR 0x%02X (%s)\n", resp->rc, lcb_strerror(NULL, resp->rc));
212
+ return;
213
+ }
214
+ if (resp->server == NULL || resp->key == NULL) {
215
+ return;
216
+ }
217
+
218
+ string server = resp->server;
219
+ string key = getRespKey((const lcb_RESPBASE *)resp);
220
+ string value;
221
+ if (resp->nvalue > 0) {
222
+ value.assign((const char *)resp->value, resp->nvalue);
223
+ }
224
+ fprintf(stdout, "%s\t%s", server.c_str(), key.c_str());
225
+ if (!value.empty()) {
226
+ if (*static_cast<bool*>(resp->cookie) && key == "key_flags") {
227
+ // Is keystats
228
+ // Flip the bits so the display formats correctly
229
+ unsigned flags_u = 0;
230
+ sscanf(value.c_str(), "%u", &flags_u);
231
+ flags_u = htonl(flags_u);
232
+ fprintf(stdout, "\t%u (cbc: converted via htonl)", flags_u);
233
+ } else {
234
+ fprintf(stdout, "\t%s", value.c_str());
235
+ }
236
+ }
237
+ fprintf(stdout, "\n");
238
+ }
239
+
240
+ static void
241
+ watch_callback(lcb_t, lcb_CALLBACKTYPE, const lcb_RESPSTATS *resp)
242
+ {
243
+ if (resp->rc != LCB_SUCCESS) {
244
+ fprintf(stderr, "ERROR 0x%02X (%s)\n", resp->rc, lcb_strerror(NULL, resp->rc));
245
+ return;
246
+ }
247
+ if (resp->server == NULL || resp->key == NULL) {
248
+ return;
249
+ }
250
+
251
+ string key = getRespKey((const lcb_RESPBASE *)resp);
252
+ if (resp->nvalue > 0) {
253
+ char *nptr = NULL;
254
+ uint64_t val =
255
+ #ifdef _WIN32
256
+ _strtoi64
257
+ #else
258
+ strtoll
259
+ #endif
260
+ ((const char *)resp->value, &nptr, 10);
261
+ if (nptr != (const char *)resp->value) {
262
+ map<string, int64_t> *entry = reinterpret_cast< map<string, int64_t> *>(resp->cookie);
263
+ (*entry)[key] += val;
264
+ }
265
+ }
266
+ }
267
+
268
+ static void
269
+ common_server_callback(lcb_t, int cbtype, const lcb_RESPSERVERBASE *sbase)
270
+ {
271
+ string msg;
272
+ if (cbtype == LCB_CALLBACK_VERBOSITY) {
273
+ msg = "Set verbosity";
274
+ } else if (cbtype == LCB_CALLBACK_FLUSH) {
275
+ msg = "Flush";
276
+ } else if (cbtype == LCB_CALLBACK_VERSIONS) {
277
+ const lcb_RESPMCVERSION *resp = (const lcb_RESPMCVERSION *)sbase;
278
+ msg = string(resp->mcversion, resp->nversion);
279
+ } else {
280
+ msg = "";
281
+ }
282
+ if (!sbase->server) {
283
+ return;
284
+ }
285
+ if (sbase->rc != LCB_SUCCESS) {
286
+ fprintf(stderr, "%s failed for server %s: %s\n", msg.c_str(), sbase->server,
287
+ lcb_strerror(NULL, sbase->rc));
288
+ } else {
289
+ fprintf(stderr, "%s: %s\n", msg.c_str(), sbase->server);
290
+ }
291
+ }
292
+
293
+ static void
294
+ ping_callback(lcb_t, int, const lcb_RESPPING *resp)
295
+ {
296
+ if (resp->rc != LCB_SUCCESS) {
297
+ fprintf(stderr, "failed: %s\n", lcb_strerror(NULL, resp->rc));
298
+ } else {
299
+ if (resp->njson) {
300
+ printf("%.*s", (int)resp->njson, resp->json);
301
+ }
302
+ }
303
+ }
304
+
305
+ static void
306
+ arithmetic_callback(lcb_t, lcb_CALLBACKTYPE type, const lcb_RESPCOUNTER *resp)
307
+ {
308
+ string key = getRespKey((const lcb_RESPBASE *)resp);
309
+ if (resp->rc != LCB_SUCCESS) {
310
+ printKeyError(key, type, (lcb_RESPBASE *)resp);
311
+ } else {
312
+ char buf[4096] = { 0 };
313
+ sprintf(buf, "Current value is %" PRIu64 ".", resp->value);
314
+ printKeyCasStatus(key, type, (const lcb_RESPBASE *)resp, buf);
315
+ }
316
+ }
317
+
318
+ static void
319
+ http_callback(lcb_t, int, const lcb_RESPHTTP *resp)
320
+ {
321
+ HttpReceiver *ctx = (HttpReceiver *)resp->cookie;
322
+ ctx->maybeInvokeStatus(resp);
323
+ if (resp->nbody) {
324
+ ctx->onChunk((const char*)resp->body, resp->nbody);
325
+ }
326
+ if (resp->rflags & LCB_RESP_F_FINAL) {
327
+ ctx->onDone();
328
+ }
329
+ }
330
+
331
+ static void
332
+ view_callback(lcb_t, int, const lcb_RESPVIEWQUERY *resp)
333
+ {
334
+ if (resp->rflags & LCB_RESP_F_FINAL) {
335
+ fprintf(stderr, "View query complete!\n");
336
+ }
337
+
338
+ if (resp->rc != LCB_SUCCESS) {
339
+ fprintf(stderr, "View query failed: 0x%x (%s)\n",
340
+ resp->rc, lcb_strerror(NULL, resp->rc));
341
+
342
+ if (resp->rc == LCB_HTTP_ERROR) {
343
+ if (resp->htresp != NULL) {
344
+ HttpReceiver ctx;
345
+ ctx.maybeInvokeStatus(resp->htresp);
346
+ if (resp->htresp->nbody) {
347
+ fprintf(stderr, "%.*s", (int)resp->htresp->nbody,
348
+ static_cast<const char *>(resp->htresp->body));
349
+ }
350
+ }
351
+ }
352
+ }
353
+
354
+ if (resp->rflags & LCB_RESP_F_FINAL) {
355
+ if (resp->value) {
356
+ fprintf(stderr, "Non-row data: %.*s\n",
357
+ (int)resp->nvalue, resp->value);
358
+ }
359
+ return;
360
+ }
361
+
362
+ printf("KEY: %.*s\n", (int)resp->nkey, static_cast<const char*>(resp->key));
363
+ printf(" VALUE: %.*s\n", (int)resp->nvalue, resp->value);
364
+ printf(" DOCID: %.*s\n", (int)resp->ndocid, resp->docid);
365
+ if (resp->docresp) {
366
+ get_callback(NULL, LCB_CALLBACK_GET, resp->docresp);
367
+ }
368
+ if (resp->geometry) {
369
+ printf(" GEO: %.*s\n", (int)resp->ngeometry, resp->geometry);
370
+ }
371
+ }
372
+ }
373
+
374
+
375
+ Handler::Handler(const char *name) : parser(name), instance(NULL)
376
+ {
377
+ if (name != NULL) {
378
+ cmdname = name;
379
+ }
380
+ }
381
+
382
+ Handler::~Handler()
383
+ {
384
+ if (params.shouldDump()) {
385
+ lcb_dump(instance, stderr, LCB_DUMP_ALL);
386
+ }
387
+ if (instance) {
388
+ lcb_destroy(instance);
389
+ }
390
+ }
391
+
392
+ void
393
+ Handler::execute(int argc, char **argv)
394
+ {
395
+ addOptions();
396
+ parser.default_settings.argstring = usagestr();
397
+ parser.default_settings.shortdesc = description();
398
+ parser.parse(argc, argv, true);
399
+ run();
400
+ if (instance != NULL && params.useTimings()) {
401
+ fprintf(stderr, "Output command timings as requested (--timings)\n");
402
+ hg.write();
403
+ }
404
+ }
405
+
406
+ void
407
+ Handler::addOptions()
408
+ {
409
+ params.addToParser(parser);
410
+ }
411
+
412
+ void
413
+ Handler::run()
414
+ {
415
+ lcb_create_st cropts;
416
+ memset(&cropts, 0, sizeof cropts);
417
+ params.fillCropts(cropts);
418
+ lcb_error_t err;
419
+ err = lcb_create(&instance, &cropts);
420
+ if (err != LCB_SUCCESS) {
421
+ throw LcbError(err, "Failed to create instance");
422
+ }
423
+ params.doCtls(instance);
424
+ err = lcb_connect(instance);
425
+ if (err != LCB_SUCCESS) {
426
+ throw LcbError(err, "Failed to connect instance");
427
+ }
428
+ lcb_wait(instance);
429
+ err = lcb_get_bootstrap_status(instance);
430
+ if (err != LCB_SUCCESS) {
431
+ throw LcbError(err, "Failed to bootstrap instance");
432
+ }
433
+
434
+ if (params.useTimings()) {
435
+ hg.install(instance, stdout);
436
+ }
437
+ }
438
+
439
+ const string&
440
+ Handler::getLoneArg(bool required)
441
+ {
442
+ static string empty("");
443
+
444
+ const vector<string>& args = parser.getRestArgs();
445
+ if (args.empty() || args.size() != 1) {
446
+ if (required) {
447
+ throw std::runtime_error("Command requires single argument");
448
+ }
449
+ return empty;
450
+ }
451
+ return args[0];
452
+ }
453
+
454
+ void
455
+ GetHandler::addOptions()
456
+ {
457
+ Handler::addOptions();
458
+ o_exptime.abbrev('e');
459
+ if (isLock()) {
460
+ o_exptime.description("Time the lock should be held for");
461
+ } else {
462
+ o_exptime.description("Update the expiration time for the item");
463
+ o_replica.abbrev('r');
464
+ o_replica.description("Read from replica. Possible values are 'first': read from first available replica. 'all': read from all replicas, and <N>, where 0 < N < nreplicas");
465
+ parser.addOption(o_replica);
466
+ }
467
+ parser.addOption(o_exptime);
468
+ }
469
+
470
+ void
471
+ GetHandler::run()
472
+ {
473
+ Handler::run();
474
+ lcb_install_callback3(instance, LCB_CALLBACK_GET, (lcb_RESPCALLBACK)get_callback);
475
+ lcb_install_callback3(instance, LCB_CALLBACK_GETREPLICA, (lcb_RESPCALLBACK)get_callback);
476
+ const vector<string>& keys = parser.getRestArgs();
477
+ std::string replica_mode = o_replica.result();
478
+
479
+ lcb_sched_enter(instance);
480
+ for (size_t ii = 0; ii < keys.size(); ++ii) {
481
+ lcb_error_t err;
482
+ if (o_replica.passed()) {
483
+ lcb_CMDGETREPLICA cmd = { 0 };
484
+ const string& key = keys[ii];
485
+ LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
486
+ if (replica_mode == "first") {
487
+ cmd.strategy = LCB_REPLICA_FIRST;
488
+ } else if (replica_mode == "all") {
489
+ cmd.strategy = LCB_REPLICA_ALL;
490
+ } else {
491
+ cmd.strategy = LCB_REPLICA_SELECT;
492
+ cmd.index = std::atoi(replica_mode.c_str());
493
+ }
494
+ err = lcb_rget3(instance, this, &cmd);
495
+ } else {
496
+ lcb_CMDGET cmd = { 0 };
497
+ const string& key = keys[ii];
498
+ LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
499
+ if (o_exptime.passed()) {
500
+ cmd.exptime = o_exptime.result();
501
+ }
502
+ if (isLock()) {
503
+ cmd.lock = 1;
504
+ }
505
+ err = lcb_get3(instance, this, &cmd);
506
+ }
507
+ if (err != LCB_SUCCESS) {
508
+ throw LcbError(err);
509
+ }
510
+ }
511
+ lcb_sched_leave(instance);
512
+ lcb_wait(instance);
513
+ }
514
+
515
+ void
516
+ TouchHandler::addOptions()
517
+ {
518
+ Handler::addOptions();
519
+ parser.addOption(o_exptime);
520
+ }
521
+
522
+ void
523
+ TouchHandler::run()
524
+ {
525
+ Handler::run();
526
+ lcb_install_callback3(instance, LCB_CALLBACK_TOUCH, (lcb_RESPCALLBACK)common_callback);
527
+ const vector<string>& keys = parser.getRestArgs();
528
+ lcb_error_t err;
529
+ lcb_sched_enter(instance);
530
+ for (size_t ii = 0; ii < keys.size(); ++ii) {
531
+ lcb_CMDTOUCH cmd = { 0 };
532
+ const string& key = keys[ii];
533
+ LCB_CMD_SET_KEY(&cmd, key.c_str(), key.size());
534
+ cmd.exptime = o_exptime.result();
535
+ err = lcb_touch3(instance, this, &cmd);
536
+ if (err != LCB_SUCCESS) {
537
+ throw LcbError(err);
538
+ }
539
+ }
540
+ lcb_sched_leave(instance);
541
+ lcb_wait(instance);
542
+ }
543
+
544
+ void
545
+ SetHandler::addOptions()
546
+ {
547
+ Handler::addOptions();
548
+ parser.addOption(o_mode);
549
+ parser.addOption(o_flags);
550
+ parser.addOption(o_exp);
551
+ parser.addOption(o_add);
552
+ parser.addOption(o_persist);
553
+ parser.addOption(o_replicate);
554
+ if (!hasFileList()) {
555
+ parser.addOption(o_value);
556
+ }
557
+ parser.addOption(o_json);
558
+ }
559
+
560
+ lcb_storage_t
561
+ SetHandler::mode()
562
+ {
563
+ if (o_add.passed()) {
564
+ return LCB_ADD;
565
+ }
566
+
567
+ string s = o_mode.const_result();
568
+ std::transform(s.begin(), s.end(), s.begin(), ::tolower);
569
+ if (s == "upsert") {
570
+ return LCB_SET;
571
+ } else if (s == "replace") {
572
+ return LCB_REPLACE;
573
+ } else if (s == "insert") {
574
+ return LCB_ADD;
575
+ } else if (s == "append") {
576
+ return LCB_APPEND;
577
+ } else if (s == "prepend") {
578
+ return LCB_PREPEND;
579
+ } else {
580
+ throw BadArg(string("Mode must be one of upsert, insert, replace. Got ") + s);
581
+ return LCB_SET;
582
+ }
583
+ }
584
+
585
+ void
586
+ SetHandler::storeItem(const string& key, const char *value, size_t nvalue)
587
+ {
588
+ lcb_error_t err;
589
+ lcb_CMDSTOREDUR cmd = { 0 };
590
+ LCB_CMD_SET_KEY(&cmd, key.c_str(), key.size());
591
+ cmd.value.vtype = LCB_KV_COPY;
592
+ cmd.value.u_buf.contig.bytes = value;
593
+ cmd.value.u_buf.contig.nbytes = nvalue;
594
+ cmd.operation = mode();
595
+
596
+ if (o_json.result()) {
597
+ cmd.datatype = LCB_VALUE_F_JSON;
598
+ }
599
+ if (o_exp.passed()) {
600
+ cmd.exptime = o_exp.result();
601
+ }
602
+ if (o_flags.passed()) {
603
+ cmd.flags = o_flags.result();
604
+ }
605
+ if (o_persist.passed() || o_replicate.passed()) {
606
+ cmd.persist_to = o_persist.result();
607
+ cmd.replicate_to = o_replicate.result();
608
+ err = lcb_storedur3(instance, NULL, &cmd);
609
+ } else {
610
+ err = lcb_store3(instance, NULL, reinterpret_cast<lcb_CMDSTORE*>(&cmd));
611
+ }
612
+ if (err != LCB_SUCCESS) {
613
+ throw LcbError(err);
614
+ }
615
+ }
616
+
617
+ void
618
+ SetHandler::storeItem(const string& key, FILE *input)
619
+ {
620
+ char tmpbuf[4096];
621
+ vector<char> vbuf;
622
+ size_t nr;
623
+ while ((nr = fread(tmpbuf, 1, sizeof tmpbuf, input))) {
624
+ vbuf.insert(vbuf.end(), tmpbuf, &tmpbuf[nr]);
625
+ }
626
+ storeItem(key, &vbuf[0], vbuf.size());
627
+ }
628
+
629
+ void
630
+ SetHandler::run()
631
+ {
632
+ Handler::run();
633
+ lcb_install_callback3(instance, LCB_CALLBACK_STORE, (lcb_RESPCALLBACK)store_callback);
634
+ lcb_install_callback3(instance, LCB_CALLBACK_STOREDUR, (lcb_RESPCALLBACK)store_callback);
635
+ const vector<string>& keys = parser.getRestArgs();
636
+
637
+ lcb_sched_enter(instance);
638
+
639
+ if (hasFileList()) {
640
+ for (size_t ii = 0; ii < keys.size(); ii++) {
641
+ const string& key = keys[ii];
642
+ FILE *fp = fopen(key.c_str(), "rb");
643
+ if (fp == NULL) {
644
+ perror(key.c_str());
645
+ continue;
646
+ }
647
+ storeItem(key, fp);
648
+ fclose(fp);
649
+ }
650
+ } else if (keys.size() > 1 || keys.empty()) {
651
+ throw BadArg("create must be passed a single key");
652
+ } else {
653
+ const string& key = keys[0];
654
+ if (o_value.passed()) {
655
+ const string& value = o_value.const_result();
656
+ storeItem(key, value.c_str(), value.size());
657
+ } else {
658
+ storeItem(key, stdin);
659
+ }
660
+ }
661
+
662
+ lcb_sched_leave(instance);
663
+ lcb_wait(instance);
664
+ }
665
+
666
+ void
667
+ HashHandler::run()
668
+ {
669
+ Handler::run();
670
+
671
+ lcbvb_CONFIG *vbc;
672
+ lcb_error_t err;
673
+ err = lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &vbc);
674
+ if (err != LCB_SUCCESS) {
675
+ throw LcbError(err);
676
+ }
677
+
678
+ const vector<string>& args = parser.getRestArgs();
679
+ for (size_t ii = 0; ii < args.size(); ii++) {
680
+ const string& key = args[ii];
681
+ const void *vkey = (const void *)key.c_str();
682
+ int vbid, srvix;
683
+ lcbvb_map_key(vbc, vkey, key.size(), &vbid, &srvix);
684
+ fprintf(stderr, "%s: [vBucket=%d, Index=%d]", key.c_str(), vbid, srvix);
685
+ if (srvix != -1) {
686
+ fprintf(stderr, " Server: %s",
687
+ lcbvb_get_hostport(vbc, srvix, LCBVB_SVCTYPE_DATA, LCBVB_SVCMODE_PLAIN));
688
+ const char *vapi = lcbvb_get_capibase(vbc, srvix, LCBVB_SVCMODE_PLAIN);
689
+ if (vapi) {
690
+ fprintf(stderr, ", CouchAPI: %s", vapi);
691
+ }
692
+ }
693
+ fprintf(stderr, "\n");
694
+
695
+ for (size_t jj = 0; jj < lcbvb_get_nreplicas(vbc); jj++) {
696
+ int rix = lcbvb_vbreplica(vbc, vbid, jj);
697
+ const char *rname = NULL;
698
+ if (rix >= 0) {
699
+ rname = lcbvb_get_hostport(vbc, rix, LCBVB_SVCTYPE_DATA, LCBVB_SVCMODE_PLAIN);
700
+ }
701
+ if (rname == NULL) {
702
+ rname = "N/A";
703
+ }
704
+ fprintf(stderr, "Replica #%d: Index=%d, Host=%s\n", (int)jj, rix, rname);
705
+ }
706
+ }
707
+ }
708
+
709
+ void
710
+ ObserveHandler::run()
711
+ {
712
+ Handler::run();
713
+ lcb_install_callback3(instance, LCB_CALLBACK_OBSERVE, (lcb_RESPCALLBACK)observe_callback);
714
+ const vector<string>& keys = parser.getRestArgs();
715
+ lcb_MULTICMD_CTX *mctx = lcb_observe3_ctxnew(instance);
716
+ if (mctx == NULL) {
717
+ throw std::bad_alloc();
718
+ }
719
+
720
+ lcb_error_t err;
721
+ for (size_t ii = 0; ii < keys.size(); ii++) {
722
+ lcb_CMDOBSERVE cmd = { 0 };
723
+ LCB_KREQ_SIMPLE(&cmd.key, keys[ii].c_str(), keys[ii].size());
724
+ err = mctx->addcmd(mctx, (lcb_CMDBASE*)&cmd);
725
+ if (err != LCB_SUCCESS) {
726
+ throw LcbError(err);
727
+ }
728
+ }
729
+
730
+ lcb_sched_enter(instance);
731
+ err = mctx->done(mctx, NULL);
732
+ if (err == LCB_SUCCESS) {
733
+ lcb_sched_leave(instance);
734
+ lcb_wait(instance);
735
+ } else {
736
+ lcb_sched_fail(instance);
737
+ throw LcbError(err);
738
+ }
739
+ }
740
+
741
+ void
742
+ ObserveSeqnoHandler::run()
743
+ {
744
+ Handler::run();
745
+ lcb_install_callback3(instance, LCB_CALLBACK_OBSEQNO, (lcb_RESPCALLBACK)obseqno_callback);
746
+ const vector<string>& infos = parser.getRestArgs();
747
+ lcb_CMDOBSEQNO cmd = { 0 };
748
+ lcbvb_CONFIG *vbc;
749
+ lcb_error_t rc;
750
+
751
+ rc = lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_VBCONFIG, &vbc);
752
+ if (rc != LCB_SUCCESS) {
753
+ throw LcbError(rc);
754
+ }
755
+
756
+ lcb_sched_enter(instance);
757
+
758
+ for (size_t ii = 0; ii < infos.size(); ++ii) {
759
+ const string& cur = infos[ii];
760
+ unsigned vbid;
761
+ unsigned long long uuid;
762
+ int rv = sscanf(cur.c_str(), "%u,%llu", &vbid, &uuid);
763
+ if (rv != 2) {
764
+ throw BadArg("Must pass sequences of base10 vbid and base16 uuids");
765
+ }
766
+ cmd.uuid = uuid;
767
+ cmd.vbid = vbid;
768
+ for (size_t jj = 0; jj < lcbvb_get_nreplicas(vbc) + 1; ++jj) {
769
+ int ix = lcbvb_vbserver(vbc, vbid, jj);
770
+ if (ix < 0) {
771
+ fprintf(stderr, "Server %d unavailable (skipping)\n", ix);
772
+ }
773
+ cmd.server_index = ix;
774
+ rc = lcb_observe_seqno3(instance, NULL, &cmd);
775
+ if (rc != LCB_SUCCESS) {
776
+ throw LcbError(rc);
777
+ }
778
+ }
779
+ }
780
+ lcb_sched_leave(instance);
781
+ lcb_wait(instance);
782
+ }
783
+
784
+ void
785
+ UnlockHandler::run()
786
+ {
787
+ Handler::run();
788
+ lcb_install_callback3(instance, LCB_CALLBACK_UNLOCK, common_callback);
789
+ const vector<string>& args = parser.getRestArgs();
790
+
791
+ if (args.size() % 2) {
792
+ throw BadArg("Expect key-cas pairs. Argument list must be even");
793
+ }
794
+
795
+ lcb_sched_enter(instance);
796
+ for (size_t ii = 0; ii < args.size(); ii += 2) {
797
+ const string& key = args[ii];
798
+ lcb_CAS cas;
799
+ int rv;
800
+ rv = sscanf(args[ii+1].c_str(), "0x%" PRIx64, &cas);
801
+ if (rv != 1) {
802
+ throw BadArg("CAS must be formatted as a hex string beginning with '0x'");
803
+ }
804
+
805
+ lcb_CMDUNLOCK cmd;
806
+ memset(&cmd, 0, sizeof cmd);
807
+ LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
808
+ cmd.cas = cas;
809
+ lcb_error_t err = lcb_unlock3(instance, NULL, &cmd);
810
+ if (err != LCB_SUCCESS) {
811
+ throw LcbError(err);
812
+ }
813
+ }
814
+ lcb_sched_leave(instance);
815
+ lcb_wait(instance);
816
+ }
817
+
818
+ static const char *
819
+ iops_to_string(lcb_io_ops_type_t type)
820
+ {
821
+ switch (type) {
822
+ case LCB_IO_OPS_LIBEV: return "libev";
823
+ case LCB_IO_OPS_LIBEVENT: return "libevent";
824
+ case LCB_IO_OPS_LIBUV: return "libuv";
825
+ case LCB_IO_OPS_SELECT: return "select";
826
+ case LCB_IO_OPS_WINIOCP: return "iocp";
827
+ case LCB_IO_OPS_INVALID: return "user-defined";
828
+ default: return "invalid";
829
+ }
830
+ }
831
+
832
+ void
833
+ VersionHandler::run()
834
+ {
835
+ const char *changeset;
836
+ lcb_error_t err;
837
+ err = lcb_cntl(NULL, LCB_CNTL_GET, LCB_CNTL_CHANGESET, (void*)&changeset);
838
+ if (err != LCB_SUCCESS) {
839
+ changeset = "UNKNOWN";
840
+ }
841
+ fprintf(stderr, "cbc:\n");
842
+ fprintf(stderr, " Runtime: Version=%s, Changeset=%s\n",
843
+ lcb_get_version(NULL), changeset);
844
+ fprintf(stderr, " Headers: Version=%s, Changeset=%s\n",
845
+ LCB_VERSION_STRING, LCB_VERSION_CHANGESET);
846
+ fprintf(stderr, " Build Timestamp: %s\n", LCB_BUILD_TIMESTAMP);
847
+
848
+ struct lcb_cntl_iops_info_st info;
849
+ memset(&info, 0, sizeof info);
850
+ err = lcb_cntl(NULL, LCB_CNTL_GET, LCB_CNTL_IOPS_DEFAULT_TYPES, &info);
851
+ if (err == LCB_SUCCESS) {
852
+ fprintf(stderr, " IO: Default=%s, Current=%s, Accessible=",
853
+ iops_to_string(info.v.v0.os_default), iops_to_string(info.v.v0.effective));
854
+ }
855
+ {
856
+ size_t ii;
857
+ char buf[256] = {0}, *p = buf;
858
+ lcb_io_ops_type_t known_io[] = {
859
+ LCB_IO_OPS_WINIOCP,
860
+ LCB_IO_OPS_LIBEVENT,
861
+ LCB_IO_OPS_LIBUV,
862
+ LCB_IO_OPS_LIBEV,
863
+ LCB_IO_OPS_SELECT
864
+ };
865
+
866
+
867
+ for (ii = 0; ii < sizeof(known_io) / sizeof(known_io[0]); ii++) {
868
+ struct lcb_create_io_ops_st cio = {0};
869
+ lcb_io_opt_t io = NULL;
870
+
871
+ cio.v.v0.type = known_io[ii];
872
+ if (lcb_create_io_ops(&io, &cio) == LCB_SUCCESS) {
873
+ p += sprintf(p, "%s,", iops_to_string(known_io[ii]));
874
+ lcb_destroy_io_ops(io);
875
+ }
876
+ }
877
+ *(--p) = '\n';
878
+ fprintf(stderr, "%s", buf);
879
+ }
880
+
881
+ if (lcb_supports_feature(LCB_SUPPORTS_SSL)) {
882
+ #ifdef LCB_NO_SSL
883
+ printf(" SSL: SUPPORTED\n");
884
+ #else
885
+ #if defined(OPENSSL_VERSION)
886
+ printf(" SSL Runtime: %s\n", OpenSSL_version(OPENSSL_VERSION));
887
+ #elif defined(SSLEAY_VERSION)
888
+ printf(" SSL Runtime: %s\n", SSLeay_version(SSLEAY_VERSION));
889
+ #endif
890
+ printf(" SSL Headers: %s\n", OPENSSL_VERSION_TEXT);
891
+ #endif
892
+ } else {
893
+ printf(" SSL: NOT SUPPORTED\n");
894
+ }
895
+ if (lcb_supports_feature(LCB_SUPPORTS_SNAPPY)) {
896
+ #define EXPAND(VAR) VAR ## 1
897
+ #define IS_EMPTY(VAR) EXPAND(VAR)
898
+
899
+ #if defined(SNAPPY_MAJOR) && (IS_EMPTY(SNAPPY_MAJOR) != 1)
900
+ printf(" Snappy: %d.%d.%d\n", SNAPPY_MAJOR, SNAPPY_MINOR, SNAPPY_PATCHLEVEL);
901
+ #else
902
+ printf(" Snappy: unknown\n");
903
+ #endif
904
+ } else {
905
+ printf(" Snappy: NOT SUPPORTED\n");
906
+ }
907
+ printf(" Tracing: %sSUPPORTED\n", lcb_supports_feature(LCB_SUPPORTS_TRACING) ? "" : "NOT ");
908
+ printf(" System: %s; %s\n", LCB_SYSTEM, LCB_SYSTEM_PROCESSOR);
909
+ printf(" CC: %s; %s\n", LCB_C_COMPILER, LCB_C_FLAGS);
910
+ printf(" CXX: %s; %s\n", LCB_CXX_COMPILER, LCB_CXX_FLAGS);
911
+ }
912
+
913
+ void
914
+ RemoveHandler::run()
915
+ {
916
+ Handler::run();
917
+ const vector<string> &keys = parser.getRestArgs();
918
+ lcb_sched_enter(instance);
919
+ lcb_install_callback3(instance, LCB_CALLBACK_REMOVE, common_callback);
920
+ for (size_t ii = 0; ii < keys.size(); ++ii) {
921
+ lcb_CMDREMOVE cmd;
922
+ const string& key = keys[ii];
923
+ memset(&cmd, 0, sizeof cmd);
924
+ LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
925
+ lcb_error_t err = lcb_remove3(instance, NULL, &cmd);
926
+ if (err != LCB_SUCCESS) {
927
+ throw LcbError(err);
928
+ }
929
+ }
930
+ lcb_sched_leave(instance);
931
+ lcb_wait(instance);
932
+ }
933
+
934
+ void
935
+ StatsHandler::run()
936
+ {
937
+ Handler::run();
938
+ lcb_install_callback3(instance, LCB_CALLBACK_STATS, (lcb_RESPCALLBACK)stats_callback);
939
+ vector<string> keys = parser.getRestArgs();
940
+ if (keys.empty()) {
941
+ keys.push_back("");
942
+ }
943
+ lcb_sched_enter(instance);
944
+ for (size_t ii = 0; ii < keys.size(); ii++) {
945
+ lcb_CMDSTATS cmd = { 0 };
946
+ const string& key = keys[ii];
947
+ if (!key.empty()) {
948
+ LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
949
+ if (o_keystats.result()) {
950
+ cmd.cmdflags = LCB_CMDSTATS_F_KV;
951
+ }
952
+ }
953
+ bool is_keystats = o_keystats.result();
954
+ lcb_error_t err = lcb_stats3(instance, &is_keystats, &cmd);
955
+ if (err != LCB_SUCCESS) {
956
+ throw LcbError(err);
957
+ }
958
+ }
959
+ lcb_sched_leave(instance);
960
+ lcb_wait(instance);
961
+ }
962
+
963
+ void
964
+ WatchHandler::run()
965
+ {
966
+ Handler::run();
967
+ lcb_install_callback3(instance, LCB_CALLBACK_STATS, (lcb_RESPCALLBACK)watch_callback);
968
+ vector<string> keys = parser.getRestArgs();
969
+ if (keys.empty()) {
970
+ keys.push_back("cmd_total_ops");
971
+ keys.push_back("cmd_total_gets");
972
+ keys.push_back("cmd_total_sets");
973
+ }
974
+ int interval = o_interval.result();
975
+
976
+ map<string, int64_t> prev;
977
+
978
+ bool first = true;
979
+ while (true) {
980
+ map<string, int64_t> entry;
981
+ lcb_sched_enter(instance);
982
+ lcb_CMDSTATS cmd = { 0 };
983
+ lcb_error_t err = lcb_stats3(instance, (void *)&entry, &cmd);
984
+ if (err != LCB_SUCCESS) {
985
+ throw LcbError(err);
986
+ }
987
+ lcb_sched_leave(instance);
988
+ lcb_wait(instance);
989
+ if (first) {
990
+ for (vector<string>::iterator it = keys.begin(); it != keys.end(); ++it) {
991
+ fprintf(stderr, "%s: %" PRId64 "\n", it->c_str(), entry[*it]);
992
+ }
993
+ first = false;
994
+ } else {
995
+ #ifndef _WIN32
996
+ if (isatty(STDERR_FILENO)) {
997
+ fprintf(stderr, "\033[%dA", (int)keys.size());
998
+ }
999
+ #endif
1000
+ for (vector<string>::iterator it = keys.begin(); it != keys.end(); ++it) {
1001
+ fprintf(stderr, "%s: %" PRId64 "%20s\n", it->c_str(), (entry[*it] - prev[*it]) / interval, "");
1002
+ }
1003
+ }
1004
+ prev = entry;
1005
+ #ifdef _WIN32
1006
+ Sleep(interval * 1000);
1007
+ #else
1008
+ sleep(interval);
1009
+ #endif
1010
+ }
1011
+ }
1012
+
1013
+
1014
+ void
1015
+ VerbosityHandler::run()
1016
+ {
1017
+ Handler::run();
1018
+
1019
+ const string& slevel = getRequiredArg();
1020
+ lcb_verbosity_level_t level;
1021
+ if (slevel == "detail") {
1022
+ level = LCB_VERBOSITY_DETAIL;
1023
+ } else if (slevel == "debug") {
1024
+ level = LCB_VERBOSITY_DEBUG;
1025
+ } else if (slevel == "info") {
1026
+ level = LCB_VERBOSITY_INFO;
1027
+ } else if (slevel == "warning") {
1028
+ level = LCB_VERBOSITY_WARNING;
1029
+ } else {
1030
+ throw BadArg("Verbosity level must be {detail,debug,info,warning}");
1031
+ }
1032
+
1033
+ lcb_install_callback3(instance, LCB_CALLBACK_VERBOSITY, (lcb_RESPCALLBACK)common_server_callback);
1034
+ lcb_CMDVERBOSITY cmd = { 0 };
1035
+ cmd.level = level;
1036
+ lcb_error_t err;
1037
+ lcb_sched_enter(instance);
1038
+ err = lcb_server_verbosity3(instance, NULL, &cmd);
1039
+ if (err != LCB_SUCCESS) {
1040
+ throw LcbError(err);
1041
+ }
1042
+ lcb_sched_leave(instance);
1043
+ lcb_wait(instance);
1044
+ }
1045
+
1046
+ void
1047
+ McVersionHandler::run()
1048
+ {
1049
+ Handler::run();
1050
+
1051
+ lcb_install_callback3(instance, LCB_CALLBACK_VERSIONS, (lcb_RESPCALLBACK)common_server_callback);
1052
+ lcb_CMDBASE cmd = { 0 };
1053
+ lcb_error_t err;
1054
+ lcb_sched_enter(instance);
1055
+ err = lcb_server_versions3(instance, NULL, &cmd);
1056
+ if (err != LCB_SUCCESS) {
1057
+ throw LcbError(err);
1058
+ }
1059
+ lcb_sched_leave(instance);
1060
+ lcb_wait(instance);
1061
+ }
1062
+
1063
+ void
1064
+ PingHandler::run()
1065
+ {
1066
+ Handler::run();
1067
+
1068
+ lcb_install_callback3(instance, LCB_CALLBACK_PING, (lcb_RESPCALLBACK)ping_callback);
1069
+ lcb_CMDPING cmd = { 0 };
1070
+ lcb_error_t err;
1071
+ cmd.services = LCB_PINGSVC_F_KV | LCB_PINGSVC_F_N1QL | LCB_PINGSVC_F_VIEWS | LCB_PINGSVC_F_FTS | LCB_PINGSVC_F_ANALYTICS;
1072
+ cmd.options = LCB_PINGOPT_F_JSON | LCB_PINGOPT_F_JSONPRETTY;
1073
+ if (o_details.passed()) {
1074
+ cmd.options |= LCB_PINGOPT_F_JSONDETAILS;
1075
+ }
1076
+ lcb_sched_enter(instance);
1077
+ err = lcb_ping3(instance, NULL, &cmd);
1078
+ if (err != LCB_SUCCESS) {
1079
+ throw LcbError(err);
1080
+ }
1081
+ lcb_sched_leave(instance);
1082
+ lcb_wait(instance);
1083
+ }
1084
+
1085
+ void
1086
+ McFlushHandler::run()
1087
+ {
1088
+ Handler::run();
1089
+
1090
+ lcb_CMDFLUSH cmd = { 0 };
1091
+ lcb_error_t err;
1092
+ lcb_install_callback3(instance, LCB_CALLBACK_FLUSH, (lcb_RESPCALLBACK)common_server_callback);
1093
+ lcb_sched_enter(instance);
1094
+ err = lcb_flush3(instance, NULL, &cmd);
1095
+ if (err != LCB_SUCCESS) {
1096
+ throw LcbError(err);
1097
+ }
1098
+ lcb_sched_leave(instance);
1099
+ lcb_wait(instance);
1100
+ }
1101
+
1102
+
1103
+ extern "C" {
1104
+ static void cbFlushCb(lcb_t, int, const lcb_RESPBASE *resp)
1105
+ {
1106
+ if (resp->rc == LCB_SUCCESS) {
1107
+ fprintf(stderr, "Flush OK\n");
1108
+ } else {
1109
+ fprintf(stderr, "Flush failed: %s (0x%x)\n",
1110
+ lcb_strerror(NULL, resp->rc), resp->rc);
1111
+ }
1112
+ }
1113
+ }
1114
+ void
1115
+ BucketFlushHandler::run()
1116
+ {
1117
+ Handler::run();
1118
+ lcb_CMDCBFLUSH cmd = { 0 };
1119
+ lcb_error_t err;
1120
+ lcb_install_callback3(instance, LCB_CALLBACK_CBFLUSH, cbFlushCb);
1121
+ err = lcb_cbflush3(instance, NULL, &cmd);
1122
+ if (err != LCB_SUCCESS) {
1123
+ throw LcbError(err);
1124
+ } else {
1125
+ lcb_wait(instance);
1126
+ }
1127
+ }
1128
+
1129
+ void
1130
+ ArithmeticHandler::run()
1131
+ {
1132
+ Handler::run();
1133
+
1134
+ const vector<string>& keys = parser.getRestArgs();
1135
+ lcb_install_callback3(instance, LCB_CALLBACK_COUNTER, (lcb_RESPCALLBACK)arithmetic_callback);
1136
+ lcb_sched_enter(instance);
1137
+ for (size_t ii = 0; ii < keys.size(); ++ii) {
1138
+ const string& key = keys[ii];
1139
+ lcb_CMDCOUNTER cmd = { 0 };
1140
+ LCB_KREQ_SIMPLE(&cmd.key, key.c_str(), key.size());
1141
+ if (o_initial.passed()) {
1142
+ cmd.create = 1;
1143
+ cmd.initial = o_initial.result();
1144
+ }
1145
+ uint64_t delta = o_delta.result();
1146
+ if (delta > static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) {
1147
+ throw BadArg("Delta too big");
1148
+ }
1149
+ cmd.delta = static_cast<int64_t>(delta);
1150
+ if (shouldInvert()) {
1151
+ cmd.delta *= -1;
1152
+ }
1153
+ cmd.exptime = o_expiry.result();
1154
+ lcb_error_t err = lcb_counter3(instance, NULL, &cmd);
1155
+ if (err != LCB_SUCCESS) {
1156
+ throw LcbError(err);
1157
+ }
1158
+ }
1159
+ lcb_sched_leave(instance);
1160
+ lcb_wait(instance);
1161
+ }
1162
+
1163
+ void
1164
+ ViewsHandler::run()
1165
+ {
1166
+ Handler::run();
1167
+
1168
+ const string& s = getRequiredArg();
1169
+ size_t pos = s.find('/');
1170
+ if (pos == string::npos) {
1171
+ throw BadArg("View must be in the format of design/view");
1172
+ }
1173
+
1174
+ string ddoc = s.substr(0, pos);
1175
+ string view = s.substr(pos+1);
1176
+ string opts = o_params.result();
1177
+
1178
+ lcb_CMDVIEWQUERY cmd = { 0 };
1179
+ lcb_view_query_initcmd(&cmd,
1180
+ ddoc.c_str(), view.c_str(), opts.c_str(), view_callback);
1181
+ if (o_spatial) {
1182
+ cmd.cmdflags |= LCB_CMDVIEWQUERY_F_SPATIAL;
1183
+ }
1184
+ if (o_incdocs) {
1185
+ cmd.cmdflags |= LCB_CMDVIEWQUERY_F_INCLUDE_DOCS;
1186
+ }
1187
+
1188
+ lcb_error_t rc;
1189
+ rc = lcb_view_query(instance, NULL, &cmd);
1190
+ if (rc != LCB_SUCCESS) {
1191
+ throw LcbError(rc);
1192
+ }
1193
+ lcb_wait(instance);
1194
+ }
1195
+
1196
+ static void
1197
+ splitKvParam(const string& src, string& key, string& value)
1198
+ {
1199
+ size_t pp = src.find('=');
1200
+ if (pp == string::npos) {
1201
+ throw BadArg("Param must be in the form of key=value");
1202
+ }
1203
+
1204
+ key = src.substr(0, pp);
1205
+ value = src.substr(pp+1);
1206
+ }
1207
+
1208
+ extern "C" {
1209
+ static void n1qlCallback(lcb_t, int, const lcb_RESPN1QL *resp)
1210
+ {
1211
+ if (resp->rflags & LCB_RESP_F_FINAL) {
1212
+ fprintf(stderr, "---> Query response finished\n");
1213
+ if (resp->rc != LCB_SUCCESS) {
1214
+ fprintf(stderr, "---> Query failed with library code 0x%x (%s)\n", resp->rc, lcb_strerror(NULL, resp->rc));
1215
+ if (resp->htresp) {
1216
+ fprintf(stderr, "---> Inner HTTP request failed with library code 0x%x and HTTP status %d\n",
1217
+ resp->htresp->rc, resp->htresp->htstatus);
1218
+ }
1219
+ }
1220
+ if (resp->row) {
1221
+ printf("%.*s\n", (int)resp->nrow, resp->row);
1222
+ }
1223
+ } else {
1224
+ printf("%.*s,\n", (int)resp->nrow, resp->row);
1225
+ }
1226
+ }
1227
+ }
1228
+
1229
+ void
1230
+ N1qlHandler::run()
1231
+ {
1232
+ Handler::run();
1233
+ const string& qstr = getRequiredArg();
1234
+
1235
+ lcb_N1QLPARAMS *nparams = lcb_n1p_new();
1236
+ lcb_error_t rc;
1237
+
1238
+ rc = lcb_n1p_setquery(nparams, qstr.c_str(), -1, LCB_N1P_QUERY_STATEMENT);
1239
+ if (rc != LCB_SUCCESS) {
1240
+ throw LcbError(rc);
1241
+ }
1242
+
1243
+ const vector<string>& vv_args = o_args.const_result();
1244
+ for (size_t ii = 0; ii < vv_args.size(); ii++) {
1245
+ string key, value;
1246
+ splitKvParam(vv_args[ii], key, value);
1247
+ string ktmp = "$" + key;
1248
+ rc = lcb_n1p_namedparamz(nparams, ktmp.c_str(), value.c_str());
1249
+ if (rc != LCB_SUCCESS) {
1250
+ throw LcbError(rc);
1251
+ }
1252
+ }
1253
+
1254
+ const vector<string>& vv_opts = o_opts.const_result();
1255
+ for (size_t ii = 0; ii < vv_opts.size(); ii++) {
1256
+ string key, value;
1257
+ splitKvParam(vv_opts[ii], key, value);
1258
+ rc = lcb_n1p_setoptz(nparams, key.c_str(), value.c_str());
1259
+ if (rc != LCB_SUCCESS) {
1260
+ throw LcbError(rc);
1261
+ }
1262
+ }
1263
+
1264
+ lcb_CMDN1QL cmd = { 0 };
1265
+ rc = lcb_n1p_mkcmd(nparams, &cmd);
1266
+ if (rc != LCB_SUCCESS) {
1267
+ throw LcbError(rc);
1268
+ }
1269
+ if (o_prepare.passed()) {
1270
+ cmd.cmdflags |= LCB_CMDN1QL_F_PREPCACHE;
1271
+ }
1272
+ if (o_analytics.passed()) {
1273
+ cmd.cmdflags |= LCB_CMDN1QL_F_ANALYTICSQUERY;
1274
+ }
1275
+ fprintf(stderr, "---> Encoded query: %.*s\n", (int)cmd.nquery, cmd.query);
1276
+ cmd.callback = n1qlCallback;
1277
+ rc = lcb_n1ql_query(instance, NULL, &cmd);
1278
+ if (rc != LCB_SUCCESS) {
1279
+ throw LcbError(rc);
1280
+ }
1281
+ lcb_n1p_free(nparams);
1282
+ lcb_wait(instance);
1283
+ }
1284
+
1285
+ void
1286
+ HttpReceiver::install(lcb_t instance)
1287
+ {
1288
+ lcb_install_callback3(instance, LCB_CALLBACK_HTTP,
1289
+ (lcb_RESPCALLBACK)http_callback);
1290
+ }
1291
+
1292
+ void
1293
+ HttpReceiver::maybeInvokeStatus(const lcb_RESPHTTP *resp)
1294
+ {
1295
+ if (statusInvoked) {
1296
+ return;
1297
+ }
1298
+
1299
+ statusInvoked = true;
1300
+ if (resp->headers) {
1301
+ for (const char * const *cur = resp->headers; *cur; cur += 2) {
1302
+ string key = cur[0];
1303
+ string value = cur[1];
1304
+ headers[key] = value;
1305
+ }
1306
+ }
1307
+ handleStatus(resp->rc, resp->htstatus);
1308
+ }
1309
+
1310
+ void
1311
+ HttpBaseHandler::run()
1312
+ {
1313
+ Handler::run();
1314
+ install(instance);
1315
+ lcb_http_cmd_st cmd;
1316
+ memset(&cmd, 0, sizeof cmd);
1317
+ string uri = getURI();
1318
+ const string& body = getBody();
1319
+
1320
+ cmd.v.v0.method = getMethod();
1321
+ cmd.v.v0.chunked = 1;
1322
+ cmd.v.v0.path = uri.c_str();
1323
+ cmd.v.v0.npath = uri.size();
1324
+ if (!body.empty()) {
1325
+ cmd.v.v0.body = body.c_str();
1326
+ cmd.v.v0.nbody = body.size();
1327
+ }
1328
+ string ctype = getContentType();
1329
+ if (!ctype.empty()) {
1330
+ cmd.v.v0.content_type = ctype.c_str();
1331
+ }
1332
+
1333
+ lcb_http_request_t dummy;
1334
+ lcb_error_t err;
1335
+ err = lcb_make_http_request(instance, (HttpReceiver*)this,
1336
+ isAdmin() ? LCB_HTTP_TYPE_MANAGEMENT : LCB_HTTP_TYPE_VIEW,
1337
+ &cmd, &dummy);
1338
+ if (err != LCB_SUCCESS) {
1339
+ throw LcbError(err);
1340
+ }
1341
+
1342
+ lcb_wait(instance);
1343
+ }
1344
+
1345
+ lcb_http_method_t
1346
+ HttpBaseHandler::getMethod()
1347
+ {
1348
+ string smeth = o_method.result();
1349
+ if (smeth == "GET") {
1350
+ return LCB_HTTP_METHOD_GET;
1351
+ } else if (smeth == "POST") {
1352
+ return LCB_HTTP_METHOD_POST;
1353
+ } else if (smeth == "DELETE") {
1354
+ return LCB_HTTP_METHOD_DELETE;
1355
+ } else if (smeth == "PUT") {
1356
+ return LCB_HTTP_METHOD_PUT;
1357
+ } else {
1358
+ throw BadArg("Unrecognized method string");
1359
+ }
1360
+ }
1361
+
1362
+ const string&
1363
+ HttpBaseHandler::getBody()
1364
+ {
1365
+ if (!body_cached.empty()) {
1366
+ return body_cached;
1367
+ }
1368
+ lcb_http_method_t meth = getMethod();
1369
+ if (meth == LCB_HTTP_METHOD_GET || meth == LCB_HTTP_METHOD_DELETE) {
1370
+ return body_cached; // empty
1371
+ }
1372
+
1373
+ char buf[4096];
1374
+ size_t nr;
1375
+ while ( (nr = fread(buf, 1, sizeof buf, stdin)) != 0) {
1376
+ body_cached.append(buf, nr);
1377
+ }
1378
+ return body_cached;
1379
+ }
1380
+
1381
+ void
1382
+ HttpBaseHandler::handleStatus(lcb_error_t err, int code)
1383
+ {
1384
+ if (err != LCB_SUCCESS) {
1385
+ fprintf(stderr, "ERROR=0x%x (%s) ", err, lcb_strerror(NULL, err));
1386
+ }
1387
+ fprintf(stderr, "%d\n", code);
1388
+ map<string,string>::const_iterator ii = headers.begin();
1389
+ for (; ii != headers.end(); ii++) {
1390
+ fprintf(stderr, " %s: %s\n", ii->first.c_str(), ii->second.c_str());
1391
+ }
1392
+ }
1393
+
1394
+ string
1395
+ AdminHandler::getURI()
1396
+ {
1397
+ return getRequiredArg();
1398
+ }
1399
+
1400
+ void
1401
+ AdminHandler::run()
1402
+ {
1403
+ fprintf(stderr, "Requesting %s\n", getURI().c_str());
1404
+ HttpBaseHandler::run();
1405
+ printf("%s\n", resbuf.c_str());
1406
+ }
1407
+
1408
+ void
1409
+ BucketCreateHandler::run()
1410
+ {
1411
+ const string& name = getRequiredArg();
1412
+ const string& btype = o_btype.const_result();
1413
+ stringstream ss;
1414
+
1415
+ if (btype == "couchbase" || btype == "membase") {
1416
+ isMemcached = false;
1417
+ } else if (btype == "memcached") {
1418
+ isMemcached = true;
1419
+ } else {
1420
+ throw BadArg("Unrecognized bucket type");
1421
+ }
1422
+ if (o_proxyport.passed() && o_bpass.passed()) {
1423
+ throw BadArg("Custom ASCII port is only available for auth-less buckets");
1424
+ }
1425
+
1426
+ ss << "name=" << name;
1427
+ ss << "&bucketType=" << btype;
1428
+ ss << "&ramQuotaMB=" << o_ramquota.result();
1429
+ if (o_proxyport.passed()) {
1430
+ ss << "&authType=none&proxyPort=" << o_proxyport.result();
1431
+ } else {
1432
+ ss << "&authType=sasl&saslPassword=" << o_bpass.result();
1433
+ }
1434
+
1435
+ ss << "&replicaNumber=" << o_replicas.result();
1436
+ body_s = ss.str();
1437
+
1438
+ AdminHandler::run();
1439
+ }
1440
+
1441
+ void
1442
+ RbacHandler::run()
1443
+ {
1444
+ fprintf(stderr, "Requesting %s\n", getURI().c_str());
1445
+ HttpBaseHandler::run();
1446
+ if (o_raw.result()) {
1447
+ printf("%s\n", resbuf.c_str());
1448
+ } else {
1449
+ format();
1450
+ }
1451
+ }
1452
+
1453
+ void
1454
+ RoleListHandler::format()
1455
+ {
1456
+ Json::Value json;
1457
+ if (!Json::Reader().parse(resbuf, json)) {
1458
+ fprintf(stderr, "Failed to parse response as JSON, falling back to raw mode\n");
1459
+ printf("%s\n", resbuf.c_str());
1460
+ }
1461
+
1462
+ std::map<string, string> roles;
1463
+ size_t max_width = 0;
1464
+ for (Json::Value::iterator i = json.begin(); i != json.end(); i++) {
1465
+ Json::Value role = *i;
1466
+ string role_id = role["role"].asString() + ": ";
1467
+ roles[role_id] = role["desc"].asString();
1468
+ if (max_width < role_id.size()) {
1469
+ max_width = role_id.size();
1470
+ }
1471
+ }
1472
+ for (map<string, string>::iterator i = roles.begin(); i != roles.end(); i++) {
1473
+ std::cout << std::left << std::setw(max_width) << i->first << i->second << std::endl;
1474
+ }
1475
+ }
1476
+
1477
+ void
1478
+ UserListHandler::format()
1479
+ {
1480
+ Json::Value json;
1481
+ if (!Json::Reader().parse(resbuf, json)) {
1482
+ fprintf(stderr, "Failed to parse response as JSON, falling back to raw mode\n");
1483
+ printf("%s\n", resbuf.c_str());
1484
+ }
1485
+
1486
+ map<string, map<string, string> > users;
1487
+ size_t max_width = 0;
1488
+ for (Json::Value::iterator i = json.begin(); i != json.end(); i++) {
1489
+ Json::Value user = *i;
1490
+ string domain = user["domain"].asString();
1491
+ string user_id = user["id"].asString();
1492
+ string user_name = user["name"].asString();
1493
+ if (!user_name.empty()) {
1494
+ user_id += " (" + user_name + "): ";
1495
+ }
1496
+ stringstream roles;
1497
+ Json::Value roles_ary = user["roles"];
1498
+ for (Json::Value::iterator j = roles_ary.begin(); j != roles_ary.end(); j++) {
1499
+ Json::Value role = *j;
1500
+ roles << "\n - " << role["role"].asString();
1501
+ if (!role["bucket_name"].empty()) {
1502
+ roles << "[" << role["bucket_name"].asString() << "]";
1503
+ }
1504
+ }
1505
+ if (max_width < user_id.size()) {
1506
+ max_width = user_id.size();
1507
+ }
1508
+ users[domain][user_id] = roles.str();
1509
+ }
1510
+ if (!users["local"].empty()) {
1511
+ std::cout << "Local users:" << std::endl;
1512
+ int j = 1;
1513
+ for (map<string, string>::iterator i = users["local"].begin(); i != users["local"].end(); i++, j++) {
1514
+ std::cout << j << ". " << std::left << std::setw(max_width) << i->first << i->second << std::endl;
1515
+ }
1516
+ }
1517
+ if (!users["external"].empty()) {
1518
+ std::cout << "External users:" << std::endl;
1519
+ int j = 1;
1520
+ for (map<string, string>::iterator i = users["external"].begin(); i != users["external"].end(); i++, j++) {
1521
+ std::cout << j << ". " << std::left << std::setw(max_width) << i->first << i->second << std::endl;
1522
+ }
1523
+ }
1524
+ }
1525
+
1526
+ void
1527
+ UserUpsertHandler::run()
1528
+ {
1529
+ stringstream ss;
1530
+
1531
+ name = getRequiredArg();
1532
+ domain = o_domain.result();
1533
+ if (domain != "local" && domain != "external") {
1534
+ throw BadArg("Unrecognized domain type");
1535
+ }
1536
+ if (!o_roles.passed()) {
1537
+ throw BadArg("At least one role has to be specified");
1538
+ }
1539
+ std::vector<std::string> roles = o_roles.result();
1540
+ std::string roles_param;
1541
+ for (size_t ii = 0; ii < roles.size(); ii++) {
1542
+ if (roles_param.empty()) {
1543
+ roles_param += roles[ii];
1544
+ } else {
1545
+ roles_param += std::string(",") + roles[ii];
1546
+ }
1547
+ }
1548
+ ss << "roles=" << roles_param;
1549
+ if (o_full_name.passed()) {
1550
+ ss << "&name=" << o_full_name.result();
1551
+ }
1552
+ if (o_password.passed()) {
1553
+ ss << "&password=" << o_password.result();
1554
+ }
1555
+ body = ss.str();
1556
+
1557
+ AdminHandler::run();
1558
+ }
1559
+
1560
+ struct HostEnt {
1561
+ string protostr;
1562
+ string hostname;
1563
+ HostEnt(const std::string& host, const char *proto) {
1564
+ protostr = proto;
1565
+ hostname = host;
1566
+ }
1567
+ HostEnt(const std::string& host, const char* proto, int port) {
1568
+ protostr = proto;
1569
+ hostname = host;
1570
+ stringstream ss;
1571
+ ss << std::dec << port;
1572
+ hostname += ":";
1573
+ hostname += ss.str();
1574
+ }
1575
+ };
1576
+
1577
+ void
1578
+ ConnstrHandler::run()
1579
+ {
1580
+ const string& connstr_s = getRequiredArg();
1581
+ lcb_error_t err;
1582
+ const char *errmsg;
1583
+ lcb::Connspec spec;
1584
+ err = spec.parse(connstr_s.c_str(), &errmsg);
1585
+ if (err != LCB_SUCCESS) {
1586
+ throw BadArg(errmsg);
1587
+ }
1588
+
1589
+ printf("Bucket: %s\n", spec.bucket().c_str());
1590
+ printf("Implicit port: %d\n", spec.default_port());
1591
+ string sslOpts;
1592
+ if (spec.sslopts() & LCB_SSL_ENABLED) {
1593
+ sslOpts = "ENABLED";
1594
+ if (spec.sslopts() & LCB_SSL_NOVERIFY) {
1595
+ sslOpts += "|NOVERIFY";
1596
+ }
1597
+ } else {
1598
+ sslOpts = "DISABLED";
1599
+ }
1600
+ printf("SSL: %s\n", sslOpts.c_str());
1601
+
1602
+ printf("Boostrap Protocols: ");
1603
+ string bsStr;
1604
+ if (spec.is_bs_cccp()) {
1605
+ bsStr += "CCCP, ";
1606
+ }
1607
+ if (spec.is_bs_http()) {
1608
+ bsStr += "HTTP, ";
1609
+ }
1610
+ if (bsStr.empty()) {
1611
+ bsStr = "CCCP,HTTP";
1612
+ } else {
1613
+ bsStr.erase(bsStr.size()-1, 1);
1614
+ }
1615
+ printf("%s\n", bsStr.c_str());
1616
+ printf("Hosts:\n");
1617
+ vector<HostEnt> hosts;
1618
+
1619
+ for (size_t ii = 0; ii < spec.hosts().size(); ++ii) {
1620
+ const lcb::Spechost *dh = &spec.hosts()[ii];
1621
+ lcb_U16 port = dh->port;
1622
+ if (!port) {
1623
+ port = spec.default_port();
1624
+ }
1625
+
1626
+ if (dh->type == LCB_CONFIG_MCD_PORT) {
1627
+ hosts.push_back(HostEnt(dh->hostname, "memcached", port));
1628
+ } else if (dh->type == LCB_CONFIG_MCD_SSL_PORT) {
1629
+ hosts.push_back(HostEnt(dh->hostname, "memcached+ssl", port));
1630
+ } else if (dh->type == LCB_CONFIG_HTTP_PORT) {
1631
+ hosts.push_back(HostEnt(dh->hostname, "restapi", port));
1632
+ } else if (dh->type == LCB_CONFIG_HTTP_SSL_PORT) {
1633
+ hosts.push_back(HostEnt(dh->hostname, "restapi+ssl", port));
1634
+ } else {
1635
+ if (spec.sslopts()) {
1636
+ hosts.push_back(HostEnt(dh->hostname, "memcached+ssl", LCB_CONFIG_MCD_SSL_PORT));
1637
+ hosts.push_back(HostEnt(dh->hostname, "restapi+ssl", LCB_CONFIG_HTTP_SSL_PORT));
1638
+ } else {
1639
+ hosts.push_back(HostEnt(dh->hostname, "memcached", LCB_CONFIG_MCD_PORT));
1640
+ hosts.push_back(HostEnt(dh->hostname, "restapi", LCB_CONFIG_HTTP_PORT));
1641
+ }
1642
+ }
1643
+ }
1644
+ for (size_t ii = 0; ii < hosts.size(); ii++) {
1645
+ HostEnt& ent = hosts[ii];
1646
+ string protostr = "[" + ent.protostr + "]";
1647
+ printf(" %-20s%s\n", protostr.c_str(), ent.hostname.c_str());
1648
+ }
1649
+
1650
+ printf("Options: \n");
1651
+ lcb::Connspec::Options::const_iterator it = spec.options().begin();
1652
+ for (; it != spec.options().end(); ++it) {
1653
+ printf(" %s=%s\n", it->first.c_str(), it->second.c_str());
1654
+ }
1655
+ }
1656
+
1657
+ void
1658
+ WriteConfigHandler::run()
1659
+ {
1660
+ lcb_create_st cropts;
1661
+ params.fillCropts(cropts);
1662
+ string outname = getLoneArg();
1663
+ if (outname.empty()) {
1664
+ outname = ConnParams::getConfigfileName();
1665
+ }
1666
+ // Generate the config
1667
+ params.writeConfig(outname);
1668
+ }
1669
+
1670
+ static map<string,Handler*> handlers;
1671
+ static map<string,Handler*> handlers_s;
1672
+ static const char* optionsOrder[] = {
1673
+ "help",
1674
+ "cat",
1675
+ "create",
1676
+ "touch",
1677
+ "observe",
1678
+ "observe-seqno",
1679
+ "incr",
1680
+ "decr",
1681
+ "mcflush",
1682
+ "hash",
1683
+ "lock",
1684
+ "unlock",
1685
+ "cp",
1686
+ "rm",
1687
+ "stats",
1688
+ // "verify,
1689
+ "version",
1690
+ "verbosity",
1691
+ "view",
1692
+ "query",
1693
+ "admin",
1694
+ "bucket-create",
1695
+ "bucket-delete",
1696
+ "bucket-flush",
1697
+ "role-list",
1698
+ "user-list",
1699
+ "user-upsert",
1700
+ "user-delete",
1701
+ "connstr",
1702
+ "write-config",
1703
+ "strerror",
1704
+ "ping",
1705
+ "watch",
1706
+ NULL
1707
+ };
1708
+
1709
+ class HelpHandler : public Handler {
1710
+ public:
1711
+ HelpHandler() : Handler("help") {}
1712
+ HANDLER_DESCRIPTION("Show help")
1713
+ protected:
1714
+ void run() {
1715
+ fprintf(stderr, "Usage: cbc <command> [options]\n");
1716
+ fprintf(stderr, "command may be:\n");
1717
+ for (const char ** cur = optionsOrder; *cur; cur++) {
1718
+ const Handler *handler = handlers[*cur];
1719
+ fprintf(stderr, " %-20s", *cur);
1720
+ fprintf(stderr, "%s\n", handler->description());
1721
+ }
1722
+ }
1723
+ };
1724
+
1725
+ class StrErrorHandler : public Handler {
1726
+ public:
1727
+ StrErrorHandler() : Handler("strerror") {}
1728
+ HANDLER_DESCRIPTION("Decode library error code")
1729
+ HANDLER_USAGE("HEX OR DECIMAL CODE")
1730
+ protected:
1731
+ void handleOptions() { }
1732
+ void run() {
1733
+ std::string nn = getRequiredArg();
1734
+ // Try to parse it as a hexadecimal number
1735
+ unsigned errcode;
1736
+ int rv = sscanf(nn.c_str(), "0x%x", &errcode);
1737
+ if (rv != 1) {
1738
+ rv = sscanf(nn.c_str(), "%u", &errcode);
1739
+ if (rv != 1) {
1740
+ throw BadArg("Need decimal or hex code!");
1741
+ }
1742
+ }
1743
+
1744
+ #define X(cname, code, cat, desc) \
1745
+ if (code == errcode) { \
1746
+ fprintf(stderr, "%s\n", #cname); \
1747
+ fprintf(stderr, " Type: 0x%x\n", cat); \
1748
+ fprintf(stderr, " Description: %s\n", desc); \
1749
+ return; \
1750
+ } \
1751
+
1752
+ LCB_XERR(X)
1753
+ #undef X
1754
+
1755
+ fprintf(stderr, "-- Error code not found in header. Trying runtime..\n");
1756
+ fprintf(stderr, "0x%x: %s\n", errcode, lcb_strerror(NULL, (lcb_error_t)errcode));
1757
+ }
1758
+ };
1759
+
1760
+ static void
1761
+ setupHandlers()
1762
+ {
1763
+ handlers_s["get"] = new GetHandler();
1764
+ handlers_s["create"] = new SetHandler();
1765
+ handlers_s["hash"] = new HashHandler();
1766
+ handlers_s["help"] = new HelpHandler();
1767
+ handlers_s["lock"] = new GetHandler("lock");
1768
+ handlers_s["observe"] = new ObserveHandler();
1769
+ handlers_s["unlock"] = new UnlockHandler();
1770
+ handlers_s["version"] = new VersionHandler();
1771
+ handlers_s["rm"] = new RemoveHandler();
1772
+ handlers_s["cp"] = new SetHandler("cp");
1773
+ handlers_s["stats"] = new StatsHandler();
1774
+ handlers_s["watch"] = new WatchHandler();
1775
+ handlers_s["verbosity"] = new VerbosityHandler();
1776
+ handlers_s["ping"] = new PingHandler();
1777
+ handlers_s["mcflush"] = new McFlushHandler();
1778
+ handlers_s["incr"] = new IncrHandler();
1779
+ handlers_s["decr"] = new DecrHandler();
1780
+ handlers_s["admin"] = new AdminHandler();
1781
+ handlers_s["bucket-create"] = new BucketCreateHandler();
1782
+ handlers_s["bucket-delete"] = new BucketDeleteHandler();
1783
+ handlers_s["bucket-flush"] = new BucketFlushHandler();
1784
+ handlers_s["view"] = new ViewsHandler();
1785
+ handlers_s["query"] = new N1qlHandler();
1786
+ handlers_s["connstr"] = new ConnstrHandler();
1787
+ handlers_s["write-config"] = new WriteConfigHandler();
1788
+ handlers_s["strerror"] = new StrErrorHandler();
1789
+ handlers_s["observe-seqno"] = new ObserveSeqnoHandler();
1790
+ handlers_s["touch"] = new TouchHandler();
1791
+ handlers_s["role-list"] = new RoleListHandler();
1792
+ handlers_s["user-list"] = new UserListHandler();
1793
+ handlers_s["user-upsert"] = new UserUpsertHandler();
1794
+ handlers_s["user-delete"] = new UserDeleteHandler();
1795
+ handlers_s["mcversion"] = new McVersionHandler();
1796
+
1797
+ map<string,Handler*>::iterator ii;
1798
+ for (ii = handlers_s.begin(); ii != handlers_s.end(); ++ii) {
1799
+ handlers[ii->first] = ii->second;
1800
+ }
1801
+
1802
+ handlers["cat"] = handlers["get"];
1803
+ handlers["n1ql"] = handlers["query"];
1804
+ }
1805
+
1806
+ #if _POSIX_VERSION >= 200112L
1807
+ #include <libgen.h>
1808
+ #define HAVE_BASENAME
1809
+ #endif
1810
+
1811
+ static void
1812
+ parseCommandname(string& cmdname, int&, char**& argv)
1813
+ {
1814
+ #ifdef HAVE_BASENAME
1815
+ cmdname = basename(argv[0]);
1816
+ size_t dashpos;
1817
+
1818
+ if (cmdname.find("cbc") != 0) {
1819
+ cmdname.clear();
1820
+ // Doesn't start with cbc
1821
+ return;
1822
+ }
1823
+
1824
+ if ((dashpos = cmdname.find('-')) != string::npos &&
1825
+ cmdname.find("cbc") != string::npos &&
1826
+ dashpos+1 < cmdname.size()) {
1827
+
1828
+ // Get the actual command name
1829
+ cmdname = cmdname.substr(dashpos+1);
1830
+ return;
1831
+ }
1832
+ #else
1833
+ (void)argv;
1834
+ #endif
1835
+ cmdname.clear();
1836
+ }
1837
+
1838
+ static void
1839
+ wrapExternalBinary(int argc, char **argv, const std::string& name)
1840
+ {
1841
+ #ifdef _POSIX_VERSION
1842
+ vector<char *> args;
1843
+ string exePath(argv[0]);
1844
+ size_t cbc_pos = exePath.find("cbc");
1845
+
1846
+ if (cbc_pos == string::npos) {
1847
+ fprintf(stderr, "Failed to invoke %s (%s)\n", name.c_str(), exePath.c_str());
1848
+ exit(EXIT_FAILURE);
1849
+ }
1850
+
1851
+ exePath.replace(cbc_pos, 3, name);
1852
+ args.push_back((char*)exePath.c_str());
1853
+
1854
+ // { "cbc", "name" }
1855
+ argv += 2; argc -= 2;
1856
+ for (int ii = 0; ii < argc; ii++) {
1857
+ args.push_back(argv[ii]);
1858
+ }
1859
+ args.push_back((char*)NULL);
1860
+ execvp(exePath.c_str(), &args[0]);
1861
+ fprintf(stderr, "Failed to execute execute %s (%s): %s\n", name.c_str(), exePath.c_str(), strerror(errno));
1862
+ #else
1863
+ fprintf(stderr, "Can't wrap around %s on non-POSIX environments", name.c_str());
1864
+ #endif
1865
+ exit(EXIT_FAILURE);
1866
+ }
1867
+
1868
+ static void cleanupHandlers()
1869
+ {
1870
+ map<string,Handler*>::iterator iter = handlers_s.begin();
1871
+ for (; iter != handlers_s.end(); iter++) {
1872
+ delete iter->second;
1873
+ }
1874
+ }
1875
+
1876
+ int main(int argc, char **argv)
1877
+ {
1878
+
1879
+ // Wrap external binaries immediately
1880
+ if (argc >= 2) {
1881
+ if (strcmp(argv[1], "pillowfight") == 0) {
1882
+ wrapExternalBinary(argc, argv, "cbc-pillowfight");
1883
+ } else if (strcmp(argv[1], "n1qlback") == 0) {
1884
+ wrapExternalBinary(argc, argv, "cbc-n1qlback");
1885
+ } else if (strcmp(argv[1], "subdoc") == 0) {
1886
+ wrapExternalBinary(argc, argv, "cbc-subdoc");
1887
+ } else if (strcmp(argv[1], "proxy") == 0) {
1888
+ wrapExternalBinary(argc, argv, "cbc-proxy");
1889
+ }
1890
+ }
1891
+
1892
+ setupHandlers();
1893
+ std::atexit(cleanupHandlers);
1894
+
1895
+ string cmdname;
1896
+ parseCommandname(cmdname, argc, argv);
1897
+
1898
+ if (cmdname.empty()) {
1899
+ if (argc < 2) {
1900
+ fprintf(stderr, "Must provide an option name\n");
1901
+ try {
1902
+ HelpHandler().execute(argc, argv);
1903
+ } catch (std::exception& exc) {
1904
+ std::cerr << exc.what() << std::endl;
1905
+ }
1906
+ exit(EXIT_FAILURE);
1907
+ } else {
1908
+ cmdname = argv[1];
1909
+ argv++;
1910
+ argc--;
1911
+ }
1912
+ }
1913
+
1914
+ Handler *handler = handlers[cmdname];
1915
+ if (handler == NULL) {
1916
+ fprintf(stderr, "Unknown command %s\n", cmdname.c_str());
1917
+ HelpHandler().execute(argc, argv);
1918
+ exit(EXIT_FAILURE);
1919
+ }
1920
+
1921
+ try {
1922
+ handler->execute(argc, argv);
1923
+
1924
+ } catch (std::exception& err) {
1925
+ fprintf(stderr, "%s\n", err.what());
1926
+ exit(EXIT_FAILURE);
1927
+ }
1928
+ }