libcouchbase 0.3.3 → 1.0.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 (167) hide show
  1. checksums.yaml +4 -4
  2. data/ext/libcouchbase/CMakeLists.txt +6 -8
  3. data/ext/libcouchbase/README.markdown +2 -2
  4. data/ext/libcouchbase/RELEASE_NOTES.markdown +229 -2
  5. data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +11 -0
  6. data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +18 -0
  7. data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +3 -2
  8. data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
  9. data/ext/libcouchbase/cmake/config-cmake.h.in +4 -0
  10. data/ext/libcouchbase/cmake/defs.mk.in +0 -2
  11. data/ext/libcouchbase/cmake/source_files.cmake +21 -5
  12. data/ext/libcouchbase/contrib/cJSON/cJSON.c +1 -1
  13. data/ext/libcouchbase/contrib/cbsasl/src/client.c +2 -0
  14. data/ext/libcouchbase/example/users/README +48 -0
  15. data/ext/libcouchbase/example/users/users.c +147 -0
  16. data/ext/libcouchbase/include/libcouchbase/auth.h +175 -31
  17. data/ext/libcouchbase/include/libcouchbase/cntl.h +82 -1
  18. data/ext/libcouchbase/include/libcouchbase/couchbase.h +45 -3
  19. data/ext/libcouchbase/include/libcouchbase/error.h +19 -1
  20. data/ext/libcouchbase/include/libcouchbase/iops.h +3 -0
  21. data/ext/libcouchbase/include/libcouchbase/n1ql.h +31 -1
  22. data/ext/libcouchbase/include/libcouchbase/plugins/io/bsdio-inl.c +4 -1
  23. data/ext/libcouchbase/include/libcouchbase/subdoc.h +36 -2
  24. data/ext/libcouchbase/include/libcouchbase/views.h +7 -1
  25. data/ext/libcouchbase/include/libcouchbase/visibility.h +1 -0
  26. data/ext/libcouchbase/include/memcached/protocol_binary.h +24 -1146
  27. data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
  28. data/ext/libcouchbase/plugins/io/libev/libev_io_opts.h +3 -2
  29. data/ext/libcouchbase/src/README.md +0 -2
  30. data/ext/libcouchbase/src/auth-priv.h +23 -4
  31. data/ext/libcouchbase/src/auth.cc +51 -43
  32. data/ext/libcouchbase/src/bootstrap.cc +244 -0
  33. data/ext/libcouchbase/src/bootstrap.h +58 -38
  34. data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +120 -158
  35. data/ext/libcouchbase/src/bucketconfig/bc_file.cc +281 -0
  36. data/ext/libcouchbase/src/bucketconfig/bc_http.cc +526 -0
  37. data/ext/libcouchbase/src/bucketconfig/bc_http.h +50 -25
  38. data/ext/libcouchbase/src/bucketconfig/bc_static.cc +150 -0
  39. data/ext/libcouchbase/src/bucketconfig/clconfig.h +410 -386
  40. data/ext/libcouchbase/src/bucketconfig/confmon.cc +393 -0
  41. data/ext/libcouchbase/src/cbft.cc +22 -27
  42. data/ext/libcouchbase/src/cntl.cc +56 -22
  43. data/ext/libcouchbase/src/connspec.cc +47 -6
  44. data/ext/libcouchbase/src/connspec.h +27 -0
  45. data/ext/libcouchbase/src/dns-srv.cc +147 -0
  46. data/ext/libcouchbase/src/dump.cc +3 -3
  47. data/ext/libcouchbase/src/errmap.cc +173 -0
  48. data/ext/libcouchbase/src/errmap.h +198 -0
  49. data/ext/libcouchbase/src/getconfig.cc +7 -33
  50. data/ext/libcouchbase/src/handler.cc +118 -7
  51. data/ext/libcouchbase/src/hostlist.cc +0 -36
  52. data/ext/libcouchbase/src/hostlist.h +44 -62
  53. data/ext/libcouchbase/src/http/http-priv.h +125 -112
  54. data/ext/libcouchbase/src/http/http.cc +27 -35
  55. data/ext/libcouchbase/src/http/http.h +1 -34
  56. data/ext/libcouchbase/src/http/http_io.cc +28 -36
  57. data/ext/libcouchbase/src/instance.cc +131 -34
  58. data/ext/libcouchbase/src/internal.h +58 -26
  59. data/ext/libcouchbase/src/jsparse/parser.cc +136 -210
  60. data/ext/libcouchbase/src/jsparse/parser.h +84 -98
  61. data/ext/libcouchbase/src/lcbht/lcbht.cc +177 -0
  62. data/ext/libcouchbase/src/lcbht/lcbht.h +174 -163
  63. data/ext/libcouchbase/src/lcbio/connect.cc +569 -0
  64. data/ext/libcouchbase/src/lcbio/connect.h +16 -7
  65. data/ext/libcouchbase/src/lcbio/ctx.c +1 -1
  66. data/ext/libcouchbase/src/lcbio/iotable.h +101 -16
  67. data/ext/libcouchbase/src/lcbio/{ioutils.c → ioutils.cc} +30 -51
  68. data/ext/libcouchbase/src/lcbio/ioutils.h +29 -90
  69. data/ext/libcouchbase/src/lcbio/manager.cc +543 -0
  70. data/ext/libcouchbase/src/lcbio/manager.h +133 -96
  71. data/ext/libcouchbase/src/lcbio/protoctx.c +2 -2
  72. data/ext/libcouchbase/src/lcbio/timer-cxx.h +87 -0
  73. data/ext/libcouchbase/src/mc/mcreq.c +11 -2
  74. data/ext/libcouchbase/src/mc/mcreq.h +9 -2
  75. data/ext/libcouchbase/src/mcserver/mcserver.cc +175 -43
  76. data/ext/libcouchbase/src/mcserver/mcserver.h +9 -13
  77. data/ext/libcouchbase/src/mcserver/negotiate.cc +181 -62
  78. data/ext/libcouchbase/src/mcserver/negotiate.h +1 -3
  79. data/ext/libcouchbase/src/mctx-helper.h +51 -0
  80. data/ext/libcouchbase/src/n1ql/ixmgmt.cc +1 -2
  81. data/ext/libcouchbase/src/n1ql/n1ql.cc +74 -42
  82. data/ext/libcouchbase/src/netbuf/netbuf.c +4 -4
  83. data/ext/libcouchbase/src/newconfig.cc +6 -6
  84. data/ext/libcouchbase/src/nodeinfo.cc +2 -2
  85. data/ext/libcouchbase/src/operations/{cbflush.c → cbflush.cc} +7 -15
  86. data/ext/libcouchbase/src/operations/{counter.c → counter.cc} +0 -0
  87. data/ext/libcouchbase/src/operations/durability.cc +6 -26
  88. data/ext/libcouchbase/src/operations/durability_internal.h +6 -3
  89. data/ext/libcouchbase/src/operations/{get.c → get.cc} +24 -26
  90. data/ext/libcouchbase/src/operations/{observe.c → observe.cc} +68 -93
  91. data/ext/libcouchbase/src/operations/{pktfwd.c → pktfwd.cc} +0 -0
  92. data/ext/libcouchbase/src/operations/{remove.c → remove.cc} +0 -0
  93. data/ext/libcouchbase/src/operations/stats.cc +3 -8
  94. data/ext/libcouchbase/src/operations/{store.c → store.cc} +27 -32
  95. data/ext/libcouchbase/src/operations/subdoc.cc +129 -42
  96. data/ext/libcouchbase/src/operations/{touch.c → touch.cc} +0 -0
  97. data/ext/libcouchbase/src/packetutils.h +30 -2
  98. data/ext/libcouchbase/src/probes.d +1 -1
  99. data/ext/libcouchbase/src/rdb/rope.c +1 -1
  100. data/ext/libcouchbase/src/{retrychk.c → retrychk.cc} +2 -3
  101. data/ext/libcouchbase/src/retryq.cc +52 -14
  102. data/ext/libcouchbase/src/retryq.h +3 -3
  103. data/ext/libcouchbase/src/settings.c +5 -0
  104. data/ext/libcouchbase/src/settings.h +11 -0
  105. data/ext/libcouchbase/src/ssl/ssl_c.c +1 -0
  106. data/ext/libcouchbase/src/ssl/ssl_common.c +2 -0
  107. data/ext/libcouchbase/src/ssl/ssl_e.c +0 -1
  108. data/ext/libcouchbase/src/strcodecs/strcodecs.h +1 -1
  109. data/ext/libcouchbase/src/trace.h +4 -4
  110. data/ext/libcouchbase/src/vbucket/vbucket.c +6 -10
  111. data/ext/libcouchbase/src/views/{docreq.c → docreq.cc} +48 -54
  112. data/ext/libcouchbase/src/views/docreq.h +24 -30
  113. data/ext/libcouchbase/src/views/viewreq.cc +318 -0
  114. data/ext/libcouchbase/src/views/viewreq.h +43 -13
  115. data/ext/libcouchbase/tests/basic/t_connstr.cc +88 -50
  116. data/ext/libcouchbase/tests/basic/t_creds.cc +47 -5
  117. data/ext/libcouchbase/tests/basic/t_host.cc +67 -75
  118. data/ext/libcouchbase/tests/basic/t_jsparse.cc +27 -82
  119. data/ext/libcouchbase/tests/basic/t_misc.cc +1 -1
  120. data/ext/libcouchbase/tests/basic/t_n1qlstrings.cc +0 -1
  121. data/ext/libcouchbase/tests/htparse/t_basic.cc +58 -78
  122. data/ext/libcouchbase/tests/ioserver/connection.cc +1 -1
  123. data/ext/libcouchbase/tests/ioserver/ioserver.cc +19 -6
  124. data/ext/libcouchbase/tests/iotests/mock-environment.cc +28 -2
  125. data/ext/libcouchbase/tests/iotests/mock-environment.h +51 -1
  126. data/ext/libcouchbase/tests/iotests/t_behavior.cc +1 -7
  127. data/ext/libcouchbase/tests/iotests/t_confmon.cc +97 -115
  128. data/ext/libcouchbase/tests/iotests/t_durability.cc +0 -1
  129. data/ext/libcouchbase/tests/iotests/t_eerrs.cc +119 -0
  130. data/ext/libcouchbase/tests/iotests/t_errmap.cc +178 -0
  131. data/ext/libcouchbase/tests/iotests/t_misc.cc +3 -3
  132. data/ext/libcouchbase/tests/iotests/t_netfail.cc +1 -1
  133. data/ext/libcouchbase/tests/iotests/t_obseqno.cc +0 -1
  134. data/ext/libcouchbase/tests/iotests/t_subdoc.cc +18 -11
  135. data/ext/libcouchbase/tests/mc/t_alloc.cc +9 -9
  136. data/ext/libcouchbase/tests/socktests/socktest.cc +7 -10
  137. data/ext/libcouchbase/tests/socktests/socktest.h +2 -3
  138. data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
  139. data/ext/libcouchbase/tests/socktests/t_manager.cc +5 -6
  140. data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
  141. data/ext/libcouchbase/tests/vbucket/confdata/ketama_expected.json +2562 -0
  142. data/ext/libcouchbase/tests/vbucket/confdata/memd_ketama_config.json +31 -0
  143. data/ext/libcouchbase/tests/vbucket/t_config.cc +35 -5
  144. data/ext/libcouchbase/tools/CMakeLists.txt +2 -2
  145. data/ext/libcouchbase/tools/cbc-handlers.h +128 -0
  146. data/ext/libcouchbase/tools/cbc-n1qlback.cc +64 -10
  147. data/ext/libcouchbase/tools/cbc-pillowfight.cc +2 -2
  148. data/ext/libcouchbase/tools/cbc.cc +143 -10
  149. data/ext/libcouchbase/tools/docgen/loc.h +1 -1
  150. data/lib/libcouchbase/connection.rb +4 -3
  151. data/lib/libcouchbase/version.rb +1 -1
  152. metadata +37 -28
  153. data/ext/libcouchbase/include/memcached/vbucket.h +0 -42
  154. data/ext/libcouchbase/src/bootstrap.c +0 -269
  155. data/ext/libcouchbase/src/bucketconfig/bc_file.c +0 -347
  156. data/ext/libcouchbase/src/bucketconfig/bc_http.c +0 -630
  157. data/ext/libcouchbase/src/bucketconfig/bc_mcraw.c +0 -150
  158. data/ext/libcouchbase/src/bucketconfig/confmon.c +0 -474
  159. data/ext/libcouchbase/src/lcbht/lcbht.c +0 -282
  160. data/ext/libcouchbase/src/lcbio/connect.c +0 -557
  161. data/ext/libcouchbase/src/lcbio/manager.c +0 -584
  162. data/ext/libcouchbase/src/packetutils.c +0 -37
  163. data/ext/libcouchbase/src/simplestring.c +0 -211
  164. data/ext/libcouchbase/src/simplestring.h +0 -228
  165. data/ext/libcouchbase/src/ssobuf.h +0 -82
  166. data/ext/libcouchbase/src/views/viewreq.c +0 -358
  167. data/ext/libcouchbase/tests/basic/t_string.cc +0 -112
@@ -350,7 +350,7 @@ static const char *parse_object(cJSON *item,const char *value);
350
350
  static char *print_object(cJSON *item,int depth,int fmt);
351
351
 
352
352
  /* Utility to jump whitespace and cr/lf */
353
- static const char *skip(const char *in) {while (in && (unsigned char)*in<=32) in++; return in;}
353
+ static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
354
354
 
355
355
  /* Parse an object - create a new root, and populate. */
356
356
  cJSON *cJSON_Parse(const char *value)
@@ -163,6 +163,8 @@ cbsasl_error_t cbsasl_client_step(cbsasl_conn_t *conn,
163
163
  cbsasl_secret_t *pass;
164
164
  cbsasl_error_t ret;
165
165
 
166
+ (void)not_used;
167
+
166
168
  if (conn->client == 0) {
167
169
  return SASL_BADPARAM;
168
170
  }
@@ -0,0 +1,48 @@
1
+ This sample demonstrates how to manage user accounts.
2
+
3
+ $ cc -lcouchbase users.c
4
+
5
+ $ ./a.out couchbase://192.168.1.194 Administrator password
6
+ 1. Create account 'cbtestuser' with predefined set of roles
7
+ HTTP status: 200
8
+ Server: Couchbase Server
9
+ Pragma: no-cache
10
+ Date: Fri, 23 Jun 2017 12:39:52 GMT
11
+ Content-Type: application/json
12
+ Content-Length: 2
13
+ Cache-Control: no-cache
14
+ ""
15
+ 2. Retrieve list of all accounts in the cluster
16
+ HTTP status: 200
17
+ Transfer-Encoding: chunked
18
+ Server: Couchbase Server
19
+ Pragma: no-cache
20
+ Date: Fri, 23 Jun 2017 12:39:52 GMT
21
+ Content-Type: application/json
22
+ Cache-Control: no-cache
23
+ [
24
+ {
25
+ "name": "TestUser",
26
+ "id": "cbtestuser",
27
+ "domain": "local",
28
+ "roles": [
29
+ {
30
+ "role": "bucket_admin",
31
+ "bucket_name": "default"
32
+ },
33
+ {
34
+ "role": "cluster_admin"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+
40
+ 3. Remove account 'cbtestuser'
41
+ HTTP status: 200
42
+ Server: Couchbase Server
43
+ Pragma: no-cache
44
+ Date: Fri, 23 Jun 2017 12:39:52 GMT
45
+ Content-Type: application/json
46
+ Content-Length: 2
47
+ Cache-Control: no-cache
48
+ ""
@@ -0,0 +1,147 @@
1
+ /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
+ /*
3
+ * Copyright 2017 Couchbase, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ /**
19
+ * @file
20
+ *
21
+ * This is an example file showing how to create and list user accounts
22
+ * on Couchbase Cluster 5.
23
+ *
24
+ * https://developer.couchbase.com/documentation/server/current/rest-api/rbac.html
25
+ */
26
+
27
+ #include <stdio.h>
28
+ #include <stdlib.h>
29
+ #include <string.h>
30
+
31
+ #include <libcouchbase/couchbase.h>
32
+
33
+ static void die(lcb_t instance, const char *msg, lcb_error_t err)
34
+ {
35
+ fprintf(stderr, "%s. Received code 0x%X (%s)\n", msg, err, lcb_strerror(instance, err));
36
+ exit(EXIT_FAILURE);
37
+ }
38
+
39
+ void http_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *r)
40
+ {
41
+ const lcb_RESPHTTP *resp = (const lcb_RESPHTTP *)r;
42
+
43
+ printf("HTTP status: %d\n", resp->htstatus);
44
+ if (resp->headers) {
45
+ for (const char *const *cur = resp->headers; *cur; cur += 2) {
46
+ printf("%s: %s\n", cur[0], cur[1]);
47
+ }
48
+ }
49
+ if (resp->nbody) {
50
+ printf("%*s\n", (int)resp->nbody, (char *)resp->body);
51
+ }
52
+ if (resp->rc != LCB_SUCCESS) {
53
+ die(instance, "Failed to execute HTTP request", resp->rc);
54
+ }
55
+ }
56
+
57
+ int main(int argc, char *argv[])
58
+ {
59
+ lcb_error_t err;
60
+ lcb_t instance;
61
+ struct lcb_create_st create_options = {0};
62
+
63
+ create_options.version = 3;
64
+
65
+ if (argc < 3) {
66
+ fprintf(stderr, "Usage: %s couchbase://host/bucket ADMIN_NAME ADMIN_PASSWORD\n", argv[0]);
67
+ exit(EXIT_FAILURE);
68
+ }
69
+
70
+ create_options.v.v3.connstr = argv[1];
71
+ create_options.v.v3.username = argv[2];
72
+ create_options.v.v3.passwd = argv[3];
73
+
74
+ err = lcb_create(&instance, &create_options);
75
+ if (err != LCB_SUCCESS) {
76
+ die(NULL, "Failed create couchbase handle", err);
77
+ }
78
+
79
+ err = lcb_connect(instance);
80
+ if (err != LCB_SUCCESS) {
81
+ die(instance, "Failed schedule connection", err);
82
+ }
83
+
84
+ lcb_wait(instance);
85
+
86
+ err = lcb_get_bootstrap_status(instance);
87
+ if (err != LCB_SUCCESS) {
88
+ die(instance, "Failed bootstrap from cluster", err);
89
+ }
90
+
91
+ lcb_install_callback3(instance, LCB_CALLBACK_HTTP, http_callback);
92
+
93
+ printf("1. Create account 'cbtestuser' with predefined set of roles\n");
94
+ {
95
+ lcb_CMDHTTP cmd = {0};
96
+ char *path = "/settings/rbac/users/local/cbtestuser";
97
+ char *body = "name=TestUser&password=cbtestuserpwd&roles=cluster_admin,bucket_admin[default]";
98
+
99
+ cmd.type = LCB_HTTP_TYPE_MANAGEMENT;
100
+ cmd.method = LCB_HTTP_METHOD_PUT;
101
+ cmd.content_type = "application/x-www-form-urlencoded";
102
+ LCB_CMD_SET_KEY(&cmd, path, strlen(path));
103
+ cmd.body = body;
104
+ cmd.nbody = strlen(body);
105
+
106
+ err = lcb_http3(instance, NULL, &cmd);
107
+ if (err != LCB_SUCCESS) {
108
+ die(instance, "Failed schedule command to upsert user", err);
109
+ }
110
+ lcb_wait(instance);
111
+ }
112
+
113
+ printf("2. Retrieve list of all accounts in the cluster\n");
114
+ {
115
+ lcb_CMDHTTP cmd = {0};
116
+ char *path = "/settings/rbac/users/local";
117
+
118
+ cmd.type = LCB_HTTP_TYPE_MANAGEMENT;
119
+ cmd.method = LCB_HTTP_METHOD_GET;
120
+ LCB_CMD_SET_KEY(&cmd, path, strlen(path));
121
+
122
+ err = lcb_http3(instance, NULL, &cmd);
123
+ if (err != LCB_SUCCESS) {
124
+ die(instance, "Failed schedule command to upsert user", err);
125
+ }
126
+ lcb_wait(instance);
127
+ }
128
+
129
+ printf("3. Remove account 'cbtestuser'\n");
130
+ {
131
+ lcb_CMDHTTP cmd = {0};
132
+ char *path = "/settings/rbac/users/local/cbtestuser";
133
+
134
+ cmd.type = LCB_HTTP_TYPE_MANAGEMENT;
135
+ cmd.method = LCB_HTTP_METHOD_DELETE;
136
+ LCB_CMD_SET_KEY(&cmd, path, strlen(path));
137
+
138
+ err = lcb_http3(instance, NULL, &cmd);
139
+ if (err != LCB_SUCCESS) {
140
+ die(instance, "Failed schedule command to upsert user", err);
141
+ }
142
+ lcb_wait(instance);
143
+ }
144
+ /* Now that we're all done, close down the connection handle */
145
+ lcb_destroy(instance);
146
+ return 0;
147
+ }
@@ -1,6 +1,11 @@
1
1
  #ifndef LCB_AUTH_H
2
2
  #define LCB_AUTH_H
3
3
 
4
+ /**
5
+ * @file
6
+ * Credentials store for Couchbase
7
+ */
8
+
4
9
  #ifdef __cplusplus
5
10
  namespace lcb { class Authenticator; }
6
11
  typedef lcb::Authenticator lcb_AUTHENTICATOR;
@@ -10,20 +15,109 @@ typedef struct lcb_AUTHENTICATOR_Cdummy lcb_AUTHENTICATOR;
10
15
  #endif
11
16
 
12
17
  /**
13
- * @class lcb_AUTHENTICATOR
18
+ * @ingroup lcb-public-api
19
+ * @defgroup lcb-auth Authentication
20
+ *
21
+ * @details
22
+ *
23
+ * The @ref lcb_AUTHENTICATOR object is how the library stores credentials
24
+ * internally, and may be used in cases where you'd like to manage credentials
25
+ * in an object separate from the library. This interface also provides better
26
+ * clarification between 'old style' (Classic) and new style (RBAC) auth.
27
+ *
28
+ * If you don't have a specific need to have credentials managed in their own.
29
+ * @ref lcb_create_st3::username and @ref lcb_create_st3::passwd fields (note
30
+ * that `username` is only valid on clusters 5.0 and higher):
31
+ *
32
+ * @code{.c}
33
+ * crst.v.v3.username = "user"; // Only for newer clusters
34
+ * crst.v.v3.passwd = "s3cr3t";
35
+ * lcb_create(&instance, &crst);
36
+ * @endcode
14
37
  *
15
- * The lcb_AUTHENTICATOR object allows greater flexibility with regard to
16
- * adding more than a single bucket/password credential pair. It also restores
17
- * the ability to use "true" usernames (though these are not used at present
18
- * yet).
38
+ * If you are connecting to a cluster older than 5.0 and would like to issue
39
+ * N1QL queries against multiple password-protected buckets, you can use
40
+ * the @ref LCB_CNTL_BUCKET_CRED setting to "add" more bucket:password pairs
41
+ * to the library. The library will then send these credentials whenever you
42
+ * issue a query with the @ref LCB_CMD_F_MULTIAUTH flag set.
43
+ *
44
+ * @code{.c}
45
+ * lcb_BUCKETCRED creds;
46
+ * creds[0] = "secondBucket";
47
+ * creds[1] = "secondPass";
48
+ * lcb_cntl(instance, LCB_CNTL_SET, LCB_CNTL_BUCKET_CRED, creds);
49
+ * @endcode
50
+ *
51
+ * Or if you have a JSON encoder handy (or are interfacing from a higher level
52
+ * language) you can use the lcb_cntl_string() variant:
53
+ *
54
+ * @code{.c}
55
+ * JsonArray *arr = new_json_array();
56
+ * json_array_push_string("secondBucket");
57
+ * json_array_push_string("secondPass");
58
+ * char *s = json_encode(arr);
59
+ * lcb_cntl_string(instance, "bucket_cred", s);
60
+ * @endcode
61
+ *
62
+ * The json functions in the above example are mockups of however you would
63
+ * actually create a JSON array.
64
+ *
65
+ * @addtogroup lcb-auth
66
+ * @{
19
67
  */
20
68
 
21
69
  /**
22
- * @volatile
70
+ * @class lcb_AUTHENTICATOR
71
+ * Opaque pointer containing credentials for the library.
72
+ */
73
+
74
+ /**
75
+ * @uncommitted
76
+ *
23
77
  * Creates a new authenticator object. You may destroy it using lcbauth_unref().
24
78
  * The returned object initially has a refcount of 1.
25
79
  *
26
80
  * @return A new authenticator object.
81
+ *
82
+ * You must set the mode on this object before adding credentials to it. See
83
+ * @ref lcbauth_set_mode().
84
+ *
85
+ * Once you have added all the credentials to the object, you may assign it
86
+ * (or a copy, see lcbauth_clone()) to a library handle via lcb_set_auth().
87
+ *
88
+ * Setting RBAC Auth:
89
+ *
90
+ * @code{.c}
91
+ * lcb_AUTHENTICATOR *auth = lcbauth_new();
92
+ * lcbauth_set_mode(auth, LCBAUTH_MODE_RBAC);
93
+ * lcbauth_add_pass(auth, "mark", "secret", LCBAUTH_F_CLUSTER);
94
+ *
95
+ * lcb_t instance;
96
+ * lcb_create_st crst = { 0 };
97
+ * crst.version = 3;
98
+ * crst.v.v3.connstr = "couchbase://cbhost.com/myBucket";
99
+ * lcb_create(&instance, &crst);
100
+ * lcb_set_auth(instance, auth);
101
+ * lcbauth_unref(auth);
102
+ * @endcode
103
+ *
104
+ * Setting multi-bucket classic auth, also with cluster administrative
105
+ * credentials:
106
+ *
107
+ * @code{.c}
108
+ * lcb_AUTHENTICATOR *auth = lcbauth_new();
109
+ * lcbauth_set_mode(auth, LCBAUTH_MODE_CLASSIC);
110
+ * lcbauth_add_pass(auth, "myBucket", "secret", LCBAUTH_F_BUCKET);
111
+ * lcbauth_add_pass(auth, "otherBucket", "otherSecret", LCBAUTH_F_BUCKET);
112
+ * lcbauth_add_pass(auth, "Administrator", "password", LCBAUTH_F_CLUSTER);
113
+ * lcb_t instance;
114
+ * lcb_create_st crst = { 0 };
115
+ * crst.version = 3;
116
+ * crst.v.v3.connstr = "couchbase://cbhost.com/myBucket";
117
+ * lcb_create(&instance, &crst);
118
+ * lcb_set_auth(instance, auth);
119
+ * lcbauth_unref(auth);
120
+ * @endcode
27
121
  */
28
122
  LIBCOUCHBASE_API
29
123
  lcb_AUTHENTICATOR *
@@ -36,18 +130,34 @@ typedef enum {
36
130
  /** User/Password is administrative; for cluster */
37
131
  LCBAUTH_F_CLUSTER = 1<<1,
38
132
 
39
- /** User is bucket name. Password is bucket password */
133
+ /**
134
+ * User is bucket name. Password is bucket password. This flag is only
135
+ * used for legacy authentication. Using it with RBAC authentication will
136
+ * return an error
137
+ */
40
138
  LCBAUTH_F_BUCKET = 1<<2
41
139
  } lcbauth_ADDPASSFLAGS;
42
140
 
43
141
  /**
44
- * @volatile
142
+ * @uncommitted
45
143
  *
46
144
  * Add a set of credentials
47
145
  * @param auth
48
146
  * @param user the username (or bucketname, if LCBAUTH_F_BUCKET is passed)
49
147
  * @param pass the password. If the password is NULL, the credential is removed
50
- * @param flags one of @ref LCBAUTH_F_CLUSTER or @ref LCBAUTH_F_BUCKET.
148
+ * @param flags one of @ref LCBAUTH_F_CLUSTER or @ref LCBAUTH_F_BUCKET. If both
149
+ * flags are combined then the credential will be used for both bucket-level
150
+ * and cluster-level administrative operations
151
+ * (using @ref LCB_HTTP_TYPE_MANAGEMENT).
152
+ * @return LCB_OPTIONS_CONFLICT if @ref LCBAUTH_F_BUCKET is used in conjunction
153
+ * with @ref LCBAUTH_MODE_RBAC.
154
+ *
155
+ * @note
156
+ * You must set the mode of the authenticator using @ref lcbauth_set_mode()
157
+ * before calling this function
158
+ *
159
+ * @note when using @ref LCBAUTH_MODE_RBAC, only @ref LCBAUTH_F_CLUSTER is
160
+ * supported.
51
161
  */
52
162
  LIBCOUCHBASE_API
53
163
  lcb_error_t
@@ -56,44 +166,78 @@ lcbauth_add_pass(lcb_AUTHENTICATOR *auth, const char *user, const char *pass, in
56
166
  /**
57
167
  * @volatile
58
168
  *
59
- * Gets the global username and password. This is either the lone bucket
60
- * password, or an explicit cluster password.
169
+ * Increments the refcount on the authenticator object
61
170
  * @param auth
62
- * @param[out] u Global username
63
- * @param[out] p Global password
171
+ *
172
+ * The only time you would want to call this function is when sharing a single
173
+ * @ref lcb_AUTHENTICATOR with multiple @ref lcb_t instances. While doing
174
+ * so is theoretically possible, it is not supported or tested.
64
175
  */
176
+ LIBCOUCHBASE_API
65
177
  void
66
- lcbauth_get_upass(const lcb_AUTHENTICATOR *auth, const char **u, const char **p);
67
-
178
+ lcbauth_ref(lcb_AUTHENTICATOR *auth);
68
179
 
69
180
  /**
70
- * @private
181
+ * @uncomitted
71
182
  *
72
- * Get a user/bucket password
73
- * @param auth the authenticator
74
- * @param name the name of the bucket
75
- * @return the password for the bucket, or NULL if the bucket has no password
76
- * (or is unknown to the authenticator)
183
+ * Decrements the refcount on the authenticator object, freeing it if there
184
+ * are no more owners.
185
+ *
186
+ * @param auth
77
187
  */
78
- const char *
79
- lcbauth_get_bpass(const lcb_AUTHENTICATOR *auth, const char *name);
188
+ LIBCOUCHBASE_API
189
+ void
190
+ lcbauth_unref(lcb_AUTHENTICATOR *auth);
80
191
 
81
192
  /**
82
193
  * @uncomitted
83
- * Increments the refcount on the authenticator object
84
- * @param auth
194
+ *
195
+ * Makes a copy of an existing lcb_AUTHENTICATOR object. The returned
196
+ * authenticator object has a reference count of 1.
197
+ * @param src the authenticator object to clone
198
+ * @return the cloned authenticator.
199
+ *
200
+ * This function is useful when you wish to copy an existing set of credentials
201
+ * for use with a new client.
85
202
  */
86
203
  LIBCOUCHBASE_API
87
- void
88
- lcbauth_ref(lcb_AUTHENTICATOR *auth);
204
+ lcb_AUTHENTICATOR *
205
+ lcbauth_clone(const lcb_AUTHENTICATOR *src);
206
+
207
+ typedef enum {
208
+ /**
209
+ * Use "bucket-specific" credentials when authenticating. This is the
210
+ * only way of authenticating up to server version 5.0
211
+ */
212
+ LCBAUTH_MODE_CLASSIC = 0,
213
+
214
+ /**
215
+ * Use role-based access control. This allows the same user to have
216
+ * access to multiple buckets with a single set of credentials.
217
+ *
218
+ * Note that if this option is selected, it becomes impossible to use
219
+ * @ref LCBAUTH_F_BUCKET with lcbauth_add_pass()
220
+ */
221
+ LCBAUTH_MODE_RBAC = 1
222
+ } lcbauth_MODE;
89
223
 
90
224
  /**
91
- * Decrements the refcount on the authenticator object
92
- * @param auth
225
+ * @uncomitted
226
+ *
227
+ * Set the mode of this authenticator.
228
+ * @param src the authenticator
229
+ * @param mode the mode to use.
230
+ * @return error if the authenticator already contains credentials.
231
+ *
232
+ * @note
233
+ * This function should be called as early as possible. It is not possible to
234
+ * change the mode after credentials have been added
93
235
  */
94
236
  LIBCOUCHBASE_API
95
- void
96
- lcbauth_unref(lcb_AUTHENTICATOR *auth);
237
+ lcb_error_t
238
+ lcbauth_set_mode(lcb_AUTHENTICATOR *src, lcbauth_MODE mode);
239
+
240
+ /** @} */
97
241
 
98
242
  #ifdef __cplusplus
99
243
  }