libcouchbase 1.3.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +2 -2
  3. data/ext/libcouchbase/CMakeLists.txt +51 -25
  4. data/ext/libcouchbase/CONTRIBUTING.md +46 -65
  5. data/ext/libcouchbase/RELEASE_NOTES.markdown +163 -0
  6. data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +9 -11
  7. data/ext/libcouchbase/cmake/Modules/FindProfiler.cmake +16 -0
  8. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +6 -6
  9. data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
  10. data/ext/libcouchbase/cmake/configure +16 -0
  11. data/ext/libcouchbase/example/CMakeLists.txt +17 -2
  12. data/ext/libcouchbase/example/analytics/.gitignore +1 -0
  13. data/ext/libcouchbase/example/analytics/analytics.c +158 -0
  14. data/ext/libcouchbase/example/analytics/build-queries.rb +34 -0
  15. data/ext/libcouchbase/example/analytics/cJSON.c +1 -0
  16. data/ext/libcouchbase/example/analytics/cJSON.h +1 -0
  17. data/ext/libcouchbase/example/analytics/queries.h +113 -0
  18. data/ext/libcouchbase/example/analytics/queries/00-show-dataverse.json +5 -0
  19. data/ext/libcouchbase/example/analytics/queries/01-setup-dataset-breweries.json +6 -0
  20. data/ext/libcouchbase/example/analytics/queries/02-setup-dataset-beers.json +6 -0
  21. data/ext/libcouchbase/example/analytics/queries/03-initiate-shadow.json +6 -0
  22. data/ext/libcouchbase/example/analytics/queries/04-list-datasets.json +7 -0
  23. data/ext/libcouchbase/example/analytics/queries/05-count-breweries.json +5 -0
  24. data/ext/libcouchbase/example/analytics/queries/06-first-brewery.json +6 -0
  25. data/ext/libcouchbase/example/analytics/queries/07-key-based-lookup.json +6 -0
  26. data/ext/libcouchbase/example/analytics/queries/08-exact-match-lookup.json +7 -0
  27. data/ext/libcouchbase/example/analytics/queries/09-exact-match-lookup-different-shape.json +6 -0
  28. data/ext/libcouchbase/example/analytics/queries/10-other-query-filters.json +6 -0
  29. data/ext/libcouchbase/example/analytics/queries/11-equijoin.json +9 -0
  30. data/ext/libcouchbase/example/analytics/queries/12-equijoin-select-star.json +10 -0
  31. data/ext/libcouchbase/example/analytics/queries/13-ansi-join.json +8 -0
  32. data/ext/libcouchbase/example/analytics/queries/14-join-select-values.json +8 -0
  33. data/ext/libcouchbase/example/analytics/queries/15-nested-outer-join.json +7 -0
  34. data/ext/libcouchbase/example/analytics/queries/16-theta-join.json +8 -0
  35. data/ext/libcouchbase/example/analytics/queries/17-existential-quantification.json +9 -0
  36. data/ext/libcouchbase/example/analytics/queries/18-universal-quantification.json +7 -0
  37. data/ext/libcouchbase/example/analytics/queries/19-simple-aggregation.json +6 -0
  38. data/ext/libcouchbase/example/analytics/queries/20-simple-aggregation-unwrapped-value.json +6 -0
  39. data/ext/libcouchbase/example/analytics/queries/21-simple-aggregation-explicit.json +6 -0
  40. data/ext/libcouchbase/example/analytics/queries/22-grouping-and-aggregation.json +6 -0
  41. data/ext/libcouchbase/example/analytics/queries/23-grouping-and-aggregation-with-hint.json +7 -0
  42. data/ext/libcouchbase/example/analytics/queries/24-grouping-and-limits.json +7 -0
  43. data/ext/libcouchbase/example/analytics/queries/25-named-parameters.json +7 -0
  44. data/ext/libcouchbase/example/analytics/queries/26-positional-parameters.json +7 -0
  45. data/ext/libcouchbase/example/crypto/common_provider.c +2 -0
  46. data/ext/libcouchbase/example/crypto/common_provider.h +2 -0
  47. data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +5 -0
  48. data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +0 -1
  49. data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +16 -26
  50. data/ext/libcouchbase/example/db/db.c +10 -6
  51. data/ext/libcouchbase/example/fts/.gitignore +1 -0
  52. data/ext/libcouchbase/example/fts/build-queries.rb +33 -0
  53. data/ext/libcouchbase/example/fts/fts.c +142 -0
  54. data/ext/libcouchbase/example/fts/queries.h +61 -0
  55. data/ext/libcouchbase/example/fts/queries/00-simple-text-query.json +12 -0
  56. data/ext/libcouchbase/example/fts/queries/01-simple-text-query-on-non-default-index.json +9 -0
  57. data/ext/libcouchbase/example/fts/queries/02-simple-text-query-on-stored-field.json +13 -0
  58. data/ext/libcouchbase/example/fts/queries/03-match-query-with-facet.json +19 -0
  59. data/ext/libcouchbase/example/fts/queries/04-docid-query.json +11 -0
  60. data/ext/libcouchbase/example/fts/queries/05-unanalyzed-term-query-with-fuzziness-level-of-0.json +13 -0
  61. data/ext/libcouchbase/example/fts/queries/06-unanalyzed-term-query-with-fuzziness-level-of-2.json +14 -0
  62. data/ext/libcouchbase/example/fts/queries/07-match-phrase-query.json +13 -0
  63. data/ext/libcouchbase/example/fts/queries/08-phrase-query.json +16 -0
  64. data/ext/libcouchbase/example/fts/queries/09-query-string-query.json +9 -0
  65. data/ext/libcouchbase/example/fts/queries/10-conjunction-query.json +21 -0
  66. data/ext/libcouchbase/example/fts/queries/11-wild-card-query.json +13 -0
  67. data/ext/libcouchbase/example/fts/queries/12-numeric-range-query.json +11 -0
  68. data/ext/libcouchbase/example/fts/queries/13-regexp-query.json +13 -0
  69. data/ext/libcouchbase/example/minimal/.gitignore +1 -0
  70. data/ext/libcouchbase/example/minimal/query.c +185 -0
  71. data/ext/libcouchbase/example/subdoc/subdoc-xattrs.c +2 -2
  72. data/ext/libcouchbase/example/tracing/cJSON.c +1 -1
  73. data/ext/libcouchbase/example/tracing/cJSON.h +1 -1
  74. data/ext/libcouchbase/include/libcouchbase/cbft.h +38 -4
  75. data/ext/libcouchbase/include/libcouchbase/cntl-private.h +8 -97
  76. data/ext/libcouchbase/include/libcouchbase/cntl.h +288 -8
  77. data/ext/libcouchbase/include/libcouchbase/couchbase.h +47 -10
  78. data/ext/libcouchbase/include/libcouchbase/crypto.h +214 -48
  79. data/ext/libcouchbase/include/libcouchbase/deprecated.h +12 -0
  80. data/ext/libcouchbase/include/libcouchbase/error.h +33 -2
  81. data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +1 -1
  82. data/ext/libcouchbase/include/libcouchbase/n1ql.h +87 -13
  83. data/ext/libcouchbase/include/libcouchbase/subdoc.h +3 -7
  84. data/ext/libcouchbase/include/libcouchbase/tracing.h +174 -56
  85. data/ext/libcouchbase/include/libcouchbase/vbucket.h +21 -1
  86. data/ext/libcouchbase/include/libcouchbase/views.h +49 -4
  87. data/ext/libcouchbase/packaging/deb/control +2 -3
  88. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  89. data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +7 -5
  90. data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +7 -5
  91. data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +14 -12
  92. data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +3 -0
  93. data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +14 -6
  94. data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +7 -5
  95. data/ext/libcouchbase/src/bootstrap.cc +6 -1
  96. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +2 -7
  97. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +1 -1
  98. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +4 -11
  99. data/ext/libcouchbase/src/bucketconfig/clconfig.h +29 -36
  100. data/ext/libcouchbase/src/bucketconfig/confmon.cc +4 -2
  101. data/ext/libcouchbase/src/cntl.cc +181 -151
  102. data/ext/libcouchbase/src/config_static.h +1 -1
  103. data/ext/libcouchbase/src/connspec.cc +5 -1
  104. data/ext/libcouchbase/src/connspec.h +3 -1
  105. data/ext/libcouchbase/src/crypto.cc +93 -80
  106. data/ext/libcouchbase/src/dns-srv.cc +1 -1
  107. data/ext/libcouchbase/src/handler.cc +0 -1
  108. data/ext/libcouchbase/src/http/http-priv.h +1 -0
  109. data/ext/libcouchbase/src/http/http.cc +1 -2
  110. data/ext/libcouchbase/src/instance.cc +21 -2
  111. data/ext/libcouchbase/src/internal.h +1 -0
  112. data/ext/libcouchbase/src/lcbio/ctx.c +24 -3
  113. data/ext/libcouchbase/src/lcbio/ioutils.cc +1 -1
  114. data/ext/libcouchbase/src/lcbio/rw-inl.h +22 -1
  115. data/ext/libcouchbase/src/lcbio/ssl.h +2 -0
  116. data/ext/libcouchbase/src/mc/compress.cc +18 -11
  117. data/ext/libcouchbase/src/mc/mcreq.c +2 -0
  118. data/ext/libcouchbase/src/mc/mcreq.h +1 -1
  119. data/ext/libcouchbase/src/mcserver/mcserver.cc +163 -6
  120. data/ext/libcouchbase/src/mcserver/negotiate.cc +17 -7
  121. data/ext/libcouchbase/src/n1ql/n1ql.cc +12 -3
  122. data/ext/libcouchbase/src/newconfig.cc +4 -3
  123. data/ext/libcouchbase/src/nodeinfo.cc +1 -7
  124. data/ext/libcouchbase/src/operations/observe.cc +1 -0
  125. data/ext/libcouchbase/src/operations/ping.cc +5 -3
  126. data/ext/libcouchbase/src/retryq.cc +22 -0
  127. data/ext/libcouchbase/src/retryq.h +2 -1
  128. data/ext/libcouchbase/src/rnd.cc +5 -12
  129. data/ext/libcouchbase/src/settings.c +4 -7
  130. data/ext/libcouchbase/src/settings.h +6 -2
  131. data/ext/libcouchbase/src/strcodecs/base64.c +59 -0
  132. data/ext/libcouchbase/src/strcodecs/strcodecs.h +2 -0
  133. data/ext/libcouchbase/src/trace.h +2 -2
  134. data/ext/libcouchbase/src/tracing/span.cc +177 -45
  135. data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +70 -28
  136. data/ext/libcouchbase/src/tracing/tracing-internal.h +33 -48
  137. data/ext/libcouchbase/src/vbucket/vbucket.c +146 -30
  138. data/ext/libcouchbase/src/wait.cc +1 -1
  139. data/ext/libcouchbase/tests/CMakeLists.txt +13 -4
  140. data/ext/libcouchbase/tests/iotests/mock-environment.cc +1 -1
  141. data/ext/libcouchbase/tests/iotests/t_misc.cc +2 -2
  142. data/ext/libcouchbase/tests/iotests/t_views.cc +1 -1
  143. data/ext/libcouchbase/tests/iotests/testutil.cc +3 -2
  144. data/ext/libcouchbase/tests/vbucket/confdata/map_node_present_nodesext_missing_nodes.json +94 -0
  145. data/ext/libcouchbase/tests/vbucket/t_config.cc +15 -0
  146. data/ext/libcouchbase/tools/CMakeLists.txt +11 -6
  147. data/ext/libcouchbase/tools/cbc-handlers.h +9 -0
  148. data/ext/libcouchbase/tools/cbc-proxy.cc +1 -1
  149. data/ext/libcouchbase/tools/cbc.cc +33 -5
  150. data/ext/libcouchbase/tools/common/options.cc +1 -1
  151. data/ext/libcouchbase/tools/extract-packets.rb +110 -0
  152. data/lib/libcouchbase/connection.rb +13 -5
  153. data/lib/libcouchbase/ext/tasks.rb +1 -1
  154. data/lib/libcouchbase/version.rb +1 -1
  155. metadata +62 -7
@@ -0,0 +1,5 @@
1
+ // vim: ft=javascript
2
+ // Display dataverses defined by Analytics service
3
+ {
4
+ "statement": "SELECT * FROM Metadata.`Dataverse`"
5
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Tell analytics service to shadow the data from beer-sample bucket using
3
+ // breweries dataset.
4
+ {
5
+ "statement": "CREATE DATASET breweries ON `beer-sample` WHERE `type` = \"brewery\""
6
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Tell analytics service to shadow the data from beer-sample bucket using
3
+ // beers dataset.
4
+ {
5
+ "statement": "CREATE DATASET beers ON `beer-sample` WHERE `type` = \"beer\""
6
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Initiate the shadowing relationship of datasets to the data in Couchbase
3
+ // Server
4
+ {
5
+ "statement": "CONNECT LINK Local"
6
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // List populated datasets
3
+ {
4
+ "statement": "SELECT ds.BucketName, ds.DatasetName, ds.`Filter` FROM Metadata.`Dataset` ds WHERE ds.DataverseName = \"Default\""
5
+ }
6
+
7
+
@@ -0,0 +1,5 @@
1
+ // vim: ft=javascript
2
+ // Ask Analytics the number of breweries
3
+ {
4
+ "statement": "SELECT VALUE COUNT(*) FROM breweries"
5
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Retrieve first brewery, ordered by name
3
+ {
4
+ "statement": "SELECT * FROM breweries ORDER BY name LIMIT 1",
5
+ "pretty": true
6
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Find a particular brewery based on its Couchbase Server key
3
+ {
4
+ "statement": "SELECT meta(bw) AS meta, bw AS data FROM breweries bw WHERE meta(bw).id = 'kona_brewing'",
5
+ "pretty": true
6
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // Find the same brewery information but in a slightly simpler or cleaner way
3
+ // based only on the data
4
+ {
5
+ "statement": "SELECT VALUE bw FROM breweries bw WHERE bw.name = 'Kona Brewing'",
6
+ "pretty": true
7
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Find brewery by name, but return objects instead of values
3
+ {
4
+ "statement": "SELECT bw FROM breweries bw WHERE bw.name = 'Kona Brewing'",
5
+ "pretty": true
6
+ }
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Apply a range condition together with a string condition to select breweries
3
+ {
4
+ "statement": "SELECT VALUE bw FROM breweries bw WHERE bw.geo.lat > 60.0 AND bw.name LIKE '%Brewing%' ORDER BY bw.name",
5
+ "pretty": true
6
+ }
@@ -0,0 +1,9 @@
1
+ // vim: ft=javascript
2
+ // Fetch list of all breweries paired with their associated beers, with the
3
+ // list enumerating the brewery name and the beer name for each such pair,
4
+ // while also limiting the answer set size to at most 3 results.
5
+ {
6
+ "statement": "SELECT bw.name AS brewer, br.name AS beer FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3"
7
+ }
8
+
9
+
@@ -0,0 +1,10 @@
1
+ // vim: ft=javascript
2
+ // Fetch list of all breweries paired with their associated beers, including
3
+ // all attributes, while also limiting the answer set size to at most 3
4
+ // results.
5
+ {
6
+ "statement": "SELECT * FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3",
7
+ "pretty": true
8
+ }
9
+
10
+
@@ -0,0 +1,8 @@
1
+ // vim: ft=javascript
2
+ // Fetch list of all breweries paired with their associated beers, including
3
+ // all attributes, while also limiting the answer set size to at most 3
4
+ // results. With ANSI JOINS!
5
+ {
6
+ "statement": "SELECT * FROM breweries bw JOIN beers br ON br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3",
7
+ "pretty": true
8
+ }
@@ -0,0 +1,8 @@
1
+ // vim: ft=javascript
2
+ // Fetch list of all breweries paired with their associated beers, including
3
+ // all attributes, while also limiting the answer set size to at most 3
4
+ // results. Select values explicitly.
5
+ {
6
+ "statement": "SELECT VALUE {\"bw\": bw, \"br\": br} FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id ORDER BY bw.name, br.name LIMIT 3",
7
+ "pretty": true
8
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // For each brewery produce an object that contains the brewery name along with
3
+ // a list of all of the brewery’s offered beer names and alcohol percentages
4
+ {
5
+ "statement": "SELECT bw.name AS brewer, (SELECT br.name, br.abv FROM beers br WHERE br.brewery_id = meta(bw).id ORDER BY br.name) AS beers FROM breweries bw ORDER BY bw.name LIMIT 2",
6
+ "pretty": true
7
+ }
@@ -0,0 +1,8 @@
1
+ // vim: ft=javascript
2
+ // For each Arizona brewery get the brewery's name, location, and a list of
3
+ // competitors' names -- where competitors are other breweries that are
4
+ // geographically close to their location
5
+ {
6
+ "statement": "SELECT bw1.name AS brewer, bw1.geo AS location, (SELECT VALUE bw2.name FROM breweries bw2 WHERE bw2.name != bw1.name AND abs(bw1.geo.lat - bw2.geo.lat) <= 0.1 AND abs(bw2.geo.lon - bw1.geo.lon) <= 0.1) AS competitors FROM breweries bw1 WHERE bw1.state = 'Arizona' ORDER BY bw1.name LIMIT 3",
7
+ "pretty": true
8
+ }
@@ -0,0 +1,9 @@
1
+ // vim: ft=javascript
2
+ // Find those breweries whose beers include at least one IPA and return the
3
+ // brewery’s name, phone number, and complete list of beer names and associated
4
+ // alcohol levels.
5
+ {
6
+ "statement": "WITH nested_breweries AS ( SELECT bw.name AS brewer, bw.phone, ( SELECT br.name, br.abv FROM beers br WHERE br.brewery_id = meta(bw).id ORDER BY br.name) AS beers FROM breweries bw) SELECT VALUE nb FROM nested_breweries nb WHERE (SOME b IN nb.beers SATISFIES b.name LIKE '%IPA%') ORDER BY nb.brewer LIMIT 2",
7
+ "pretty": true
8
+ }
9
+
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // Find those breweries that only have seriously strong beers
3
+ {
4
+ "statement": "WITH nested_breweries AS ( SELECT bw.name AS brewer, bw.phone, ( SELECT br.name, br.abv FROM beers br WHERE br.brewery_id = meta(bw).id ORDER BY br.name) AS beers FROM breweries bw) SELECT VALUE nb FROM nested_breweries nb WHERE (EVERY b IN nb.beers SATISFIES b.abv >= 10) AND ARRAY_COUNT(nb.beers) > 0 ORDER BY nb.brewer LIMIT 5",
5
+ "pretty": true
6
+ }
7
+
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Compute the total number of beers in a SQL-like way
3
+ {
4
+ "statement": "SELECT COUNT(*) AS num_beers FROM beers"
5
+ }
6
+
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Compute the total number of beers and return unwrapped value
3
+ {
4
+ "statement": "SELECT VALUE COUNT(b) FROM beers b"
5
+ }
6
+
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // Compute the total number of beers with explicit aggregate function
3
+ {
4
+ "statement": "SELECT VALUE ARRAY_COUNT((SELECT b FROM beers b))"
5
+ }
6
+
@@ -0,0 +1,6 @@
1
+ // vim: ft=javascript
2
+ // For each brewery that offers more than 30 beers, the following group-by or
3
+ // aggregate query reports the number of beers that it offers
4
+ {
5
+ "statement": "SELECT br.brewery_id, COUNT(*) AS num_beers FROM beers br GROUP BY br.brewery_id HAVING COUNT(*) > 30 ORDER BY COUNT(*) DESC"
6
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // For each brewery that offers more than 30 beers, the following group-by or
3
+ // aggregate query reports the number of beers that it offers. With a
4
+ // hash-based aggregation hint.
5
+ {
6
+ "statement": "SELECT br.brewery_id, COUNT(*) AS num_beers FROM beers br /*+ hash */ GROUP BY br.brewery_id HAVING COUNT(*) > 30 ORDER BY COUNT(*) DESC"
7
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // Return the top three breweries based on their numbers of offered beers. Also
3
+ // illustrate the use of multiple aggregate functions to compute various
4
+ // alcohol content statistics for their beers
5
+ {
6
+ "statement": "SELECT bw.name, COUNT(*) AS num_beers, AVG(br.abv) AS abv_avg, MIN(br.abv) AS abv_min, MAX(br.abv) AS abv_max FROM breweries bw, beers br WHERE br.brewery_id = meta(bw).id GROUP BY bw.name ORDER BY num_beers DESC LIMIT 3"
7
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // Find the same brewery information but specify name as parameter
3
+ {
4
+ "statement": "SELECT VALUE bw FROM breweries bw WHERE bw.name = $name",
5
+ "$name": "Kona Brewing",
6
+ "pretty": true
7
+ }
@@ -0,0 +1,7 @@
1
+ // vim: ft=javascript
2
+ // Find the same brewery information but specify name as parameter
3
+ {
4
+ "statement": "SELECT VALUE bw FROM breweries bw WHERE bw.name = ?",
5
+ "args": ["Kona Brewing"],
6
+ "pretty": true
7
+ }
@@ -17,6 +17,8 @@
17
17
 
18
18
  #include "common_provider.h"
19
19
 
20
+ char * common_aes256_key_id = "mykeyid";
21
+
20
22
  uint8_t *common_hmac_sha256_key = "myauthpassword";
21
23
 
22
24
  uint8_t common_aes256_key[AES256_KEY_SIZE] = "!mysecretkey#9^5usdk39d&dlf)03sL";
@@ -20,6 +20,8 @@
20
20
 
21
21
  #include <libcouchbase/couchbase.h>
22
22
 
23
+ extern char * common_aes256_key_id;
24
+
23
25
  #define AES256_KEY_SIZE 32
24
26
  #define AES256_IV_SIZE 16
25
27
 
@@ -39,6 +39,7 @@ static void op_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
39
39
  if (rb->rc == LCB_SUCCESS) {
40
40
  const lcb_RESPGET *rg = (const lcb_RESPGET *)rb;
41
41
  lcbcrypto_CMDDECRYPT dcmd = {};
42
+ lcbcrypto_FIELDSPEC field = {};
42
43
  lcb_error_t err;
43
44
 
44
45
  printf("VALUE: %.*s\n", (int)rg->nvalue, rg->value);
@@ -48,6 +49,10 @@ static void op_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
48
49
  dcmd.ndoc = rg->nvalue;
49
50
  dcmd.out = NULL;
50
51
  dcmd.nout = 0;
52
+ dcmd.nfields = 1;
53
+ dcmd.fields = &field;
54
+ field.name = "message";
55
+ field.alg = "AES-256-HMAC-SHA256";
51
56
  err = lcbcrypto_decrypt_fields(instance, &dcmd);
52
57
  if (err != LCB_SUCCESS) {
53
58
  die(instance, "Couldn't decrypt field 'message'", err);
@@ -63,7 +63,6 @@ static void store_encrypted(lcb_t instance, const char *key, const char *val)
63
63
  ecmd.fields = &field;
64
64
  field.name = "message";
65
65
  field.alg = "AES-256-HMAC-SHA256";
66
- field.kid = "mypublickey";
67
66
 
68
67
  err = lcbcrypto_encrypt_fields(instance, &ecmd);
69
68
  if (err != LCB_SUCCESS) {
@@ -41,17 +41,9 @@ static void osp_release_bytes(lcbcrypto_PROVIDER *provider, void *bytes)
41
41
  (void)provider;
42
42
  }
43
43
 
44
- static lcb_error_t osp_load_key(struct lcbcrypto_PROVIDER *provider, lcbcrypto_KEYTYPE type, const char *keyid,
45
- uint8_t **key, size_t *key_len)
44
+ static const char *osp_get_key_id(lcbcrypto_PROVIDER *provider)
46
45
  {
47
- *key_len = AES256_KEY_SIZE;
48
- *key = malloc(*key_len);
49
- memcpy(*key, common_aes256_key, *key_len);
50
-
51
- (void)type;
52
- (void)keyid;
53
- (void)provider;
54
- return LCB_SUCCESS;
46
+ return common_aes256_key_id;
55
47
  }
56
48
 
57
49
  static lcb_error_t osp_generate_iv(struct lcbcrypto_PROVIDER *provider, uint8_t **iv, size_t *iv_len)
@@ -170,15 +162,14 @@ static lcb_error_t osp_verify_signature(struct lcbcrypto_PROVIDER *provider, con
170
162
  }
171
163
 
172
164
  static lcb_error_t osp_encrypt(struct lcbcrypto_PROVIDER *provider, const uint8_t *input, size_t input_len,
173
- const uint8_t *key, size_t key_len, const uint8_t *iv, size_t iv_len, uint8_t **output,
174
- size_t *output_len)
165
+ const uint8_t *iv, size_t iv_len, uint8_t **output, size_t *output_len)
175
166
  {
176
167
  EVP_CIPHER_CTX *ctx;
177
168
  const EVP_CIPHER *cipher;
178
169
  int rc, len, block_len, out_len;
179
170
  uint8_t *out;
180
171
 
181
- if (iv_len != 16 || key_len != 32) {
172
+ if (iv_len != 16) {
182
173
  return LCB_EINVAL;
183
174
  }
184
175
 
@@ -187,7 +178,7 @@ static lcb_error_t osp_encrypt(struct lcbcrypto_PROVIDER *provider, const uint8_
187
178
  return LCB_EINVAL;
188
179
  }
189
180
  cipher = EVP_aes_256_cbc();
190
- rc = EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv);
181
+ rc = EVP_EncryptInit_ex(ctx, cipher, NULL, common_aes256_key, iv);
191
182
  if (rc != 1) {
192
183
  EVP_CIPHER_CTX_free(ctx);
193
184
  return LCB_EINVAL;
@@ -215,15 +206,14 @@ static lcb_error_t osp_encrypt(struct lcbcrypto_PROVIDER *provider, const uint8_
215
206
  }
216
207
 
217
208
  static lcb_error_t osp_decrypt(struct lcbcrypto_PROVIDER *provider, const uint8_t *input, size_t input_len,
218
- const uint8_t *key, size_t key_len, const uint8_t *iv, size_t iv_len, uint8_t **output,
219
- size_t *output_len)
209
+ const uint8_t *iv, size_t iv_len, uint8_t **output, size_t *output_len)
220
210
  {
221
211
  EVP_CIPHER_CTX *ctx;
222
212
  const EVP_CIPHER *cipher;
223
213
  int rc, len, out_len;
224
214
  uint8_t *out;
225
215
 
226
- if (iv_len != 16 || key_len != 32) {
216
+ if (iv_len != 16) {
227
217
  return LCB_EINVAL;
228
218
  }
229
219
 
@@ -232,7 +222,7 @@ static lcb_error_t osp_decrypt(struct lcbcrypto_PROVIDER *provider, const uint8_
232
222
  return LCB_EINVAL;
233
223
  }
234
224
  cipher = EVP_aes_256_cbc();
235
- rc = EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv);
225
+ rc = EVP_DecryptInit_ex(ctx, cipher, NULL, common_aes256_key, iv);
236
226
  if (rc != 1) {
237
227
  EVP_CIPHER_CTX_free(ctx);
238
228
  return LCB_EINVAL;
@@ -261,15 +251,15 @@ static lcb_error_t osp_decrypt(struct lcbcrypto_PROVIDER *provider, const uint8_
261
251
  lcbcrypto_PROVIDER *osp_create()
262
252
  {
263
253
  lcbcrypto_PROVIDER *provider = calloc(1, sizeof(lcbcrypto_PROVIDER));
264
- provider->version = 0;
254
+ provider->version = 1;
265
255
  provider->destructor = osp_free;
266
- provider->v.v0.release_bytes = osp_release_bytes;
267
- provider->v.v0.load_key = osp_load_key;
268
- provider->v.v0.generate_iv = osp_generate_iv;
269
- provider->v.v0.sign = osp_sign;
270
- provider->v.v0.verify_signature = osp_verify_signature;
271
- provider->v.v0.encrypt = osp_encrypt;
272
- provider->v.v0.decrypt = osp_decrypt;
256
+ provider->v.v1.release_bytes = osp_release_bytes;
257
+ provider->v.v1.generate_iv = osp_generate_iv;
258
+ provider->v.v1.sign = osp_sign;
259
+ provider->v.v1.verify_signature = osp_verify_signature;
260
+ provider->v.v1.encrypt = osp_encrypt;
261
+ provider->v.v1.decrypt = osp_decrypt;
262
+ provider->v.v1.get_key_id = osp_get_key_id;
273
263
  return provider;
274
264
  }
275
265
 
@@ -26,8 +26,8 @@
26
26
  * RUN:
27
27
  *
28
28
  * valgrind -v --tool=memcheck --leak-check=full --show-reachable=yes ./db
29
- * ./db key size <host:port> <bucket> <passwd>
30
- * db.exe key size <host:port> <bucket> <passwd>
29
+ * ./db key size <host:port> <bucket> <passwd> <username>
30
+ * db.exe key size <host:port> <bucket> <passwd> <username>
31
31
  */
32
32
  #include <stdio.h>
33
33
  #include <libcouchbase/couchbase.h>
@@ -106,6 +106,9 @@ int main(int argc, char *argv[])
106
106
  if (argc > 4) {
107
107
  create_options.v.v3.passwd = argv[4];
108
108
  }
109
+ if (argc > 5) {
110
+ create_options.v.v3.username = argv[5];
111
+ }
109
112
 
110
113
  INSTALL_SIGINT_HANDLER();
111
114
 
@@ -151,16 +154,17 @@ int main(int argc, char *argv[])
151
154
  }
152
155
  lcb_wait3(instance, LCB_WAIT_NOCHECK);
153
156
  fprintf(stderr, "Benchmarking... CTRL-C to stop\n");
154
- {
155
- lcb_CMDGET cmd = { 0 };
157
+ while (1) {
158
+ lcb_CMDGET cmd = {0};
156
159
  LCB_CMD_SET_KEY(&cmd, key, nkey);
157
160
  err = lcb_get3(instance, NULL, &cmd);
158
161
  if (err != LCB_SUCCESS) {
159
- fprintf(stderr, "Failed to get: %s\n", lcb_strerror(NULL, err));
162
+ fprintf(stderr, "Failed to schedule get operation: %s\n", lcb_strerror(NULL, err));
160
163
  exit(EXIT_FAILURE);
161
164
  }
165
+ lcb_wait3(instance, LCB_WAIT_NOCHECK);
166
+ fprintf(stderr, "retry\n");
162
167
  }
163
- lcb_wait3(instance, LCB_WAIT_NOCHECK);
164
168
  lcb_destroy(instance);
165
169
 
166
170
  exit(EXIT_SUCCESS);
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # Copyright 2018 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'json'
18
+
19
+ paths = Dir[File.join(__dir__, 'queries', '*.json')].sort
20
+ File.open(File.join(__dir__, 'queries.h'), 'w+') do |out|
21
+ out.puts("// This file was generated by queries.rb")
22
+ out.puts("typedef struct fts_query_str { const char *comment; size_t query_len; const char *query; } fts_query_str;")
23
+ out.puts("size_t num_queries = #{paths.size};")
24
+ out.puts("fts_query_str queries[#{paths.size + 1}] = {")
25
+ paths.each do |path|
26
+ lines = File.readlines(path)
27
+ comment = lines[1].gsub(%r{^//\s*}, '').strip
28
+ query = lines.reject { |line| line.start_with?('//') }.join
29
+ query_str = JSON.generate(JSON.parse(query))
30
+ out.puts("{#{comment.inspect},\n #{query_str.size},\n #{query_str.inspect}},\n\n")
31
+ end
32
+ out.puts("{NULL, 0, NULL}};")
33
+ end