libcouchbase 1.2.8 → 1.3.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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/README.md +16 -8
- data/ext/libcouchbase/CMakeLists.txt +34 -32
- data/ext/libcouchbase/RELEASE_NOTES.markdown +277 -6
- data/ext/libcouchbase/cmake/Modules/ConfigureDtrace.cmake +14 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibevent.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseLibuv.cmake +2 -1
- data/ext/libcouchbase/cmake/Modules/GenerateConfigDotH.cmake +2 -0
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +8 -1
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +3 -3
- data/ext/libcouchbase/cmake/config-cmake.h.in +14 -0
- data/ext/libcouchbase/cmake/configure +8 -26
- data/ext/libcouchbase/cmake/defs.mk.in +2 -2
- data/ext/libcouchbase/cmake/libcouchbase.stp.in +829 -0
- data/ext/libcouchbase/cmake/source_files.cmake +11 -2
- data/ext/libcouchbase/contrib/cbsasl/CMakeLists.txt +18 -2
- data/ext/libcouchbase/contrib/cbsasl/include/cbsasl/cbsasl.h +44 -2
- data/ext/libcouchbase/contrib/cbsasl/src/client.c +285 -73
- data/ext/libcouchbase/contrib/cbsasl/src/common.c +4 -0
- data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.c +500 -0
- data/ext/libcouchbase/contrib/cbsasl/src/scram-sha/scram_utils.h +99 -0
- data/ext/libcouchbase/contrib/cliopts/CMakeLists.txt +1 -1
- data/ext/libcouchbase/contrib/cliopts/cliopts.h +14 -1
- data/ext/libcouchbase/contrib/snappy/CMakeLists.txt +2 -3
- data/ext/libcouchbase/contrib/snappy/snappy-sinksource.cc +4 -0
- data/ext/libcouchbase/contrib/snappy/snappy-stubs-public.h +7 -5
- data/ext/libcouchbase/contrib/snappy/snappy.cc +7 -2
- data/ext/libcouchbase/example/crypto/.gitignore +2 -0
- data/ext/libcouchbase/example/crypto/Makefile +13 -0
- data/ext/libcouchbase/example/crypto/common_provider.c +24 -0
- data/ext/libcouchbase/example/crypto/common_provider.h +31 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +139 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +147 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +281 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.h +29 -0
- data/ext/libcouchbase/example/tracing/.gitignore +2 -0
- data/ext/libcouchbase/example/tracing/Makefile +8 -0
- data/ext/libcouchbase/example/tracing/cJSON.c +1 -0
- data/ext/libcouchbase/example/tracing/cJSON.h +1 -0
- data/ext/libcouchbase/example/tracing/tracing.c +439 -0
- data/ext/libcouchbase/example/tracing/views.c +444 -0
- data/ext/libcouchbase/include/libcouchbase/auth.h +56 -4
- data/ext/libcouchbase/include/libcouchbase/cbft.h +8 -0
- data/ext/libcouchbase/include/libcouchbase/cntl-private.h +55 -1
- data/ext/libcouchbase/include/libcouchbase/cntl.h +101 -1
- data/ext/libcouchbase/include/libcouchbase/configuration.h.in +6 -0
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +109 -6
- data/ext/libcouchbase/include/libcouchbase/crypto.h +140 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +38 -2
- data/ext/libcouchbase/include/libcouchbase/kvbuf.h +6 -1
- data/ext/libcouchbase/include/libcouchbase/metrics.h +79 -0
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +9 -0
- data/ext/libcouchbase/include/libcouchbase/tracing.h +319 -0
- data/ext/libcouchbase/include/libcouchbase/vbucket.h +1 -1
- data/ext/libcouchbase/include/libcouchbase/views.h +8 -0
- data/ext/libcouchbase/include/memcached/protocol_binary.h +40 -10
- data/ext/libcouchbase/packaging/rpm/libcouchbase.spec.in +6 -14
- data/ext/libcouchbase/plugins/io/libuv/plugin-internal.h +3 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +1 -0
- data/ext/libcouchbase/plugins/io/select/plugin-select.c +4 -1
- data/ext/libcouchbase/src/auth-priv.h +36 -4
- data/ext/libcouchbase/src/auth.cc +66 -27
- data/ext/libcouchbase/src/bootstrap.cc +1 -1
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +12 -7
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +26 -17
- data/ext/libcouchbase/src/bucketconfig/bc_http.h +1 -1
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +4 -2
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +6 -3
- data/ext/libcouchbase/src/cbft.cc +48 -0
- data/ext/libcouchbase/src/cntl.cc +138 -2
- data/ext/libcouchbase/src/config_static.h +17 -0
- data/ext/libcouchbase/src/connspec.cc +54 -6
- data/ext/libcouchbase/src/connspec.h +9 -1
- data/ext/libcouchbase/src/crypto.cc +386 -0
- data/ext/libcouchbase/src/ctx-log-inl.h +23 -6
- data/ext/libcouchbase/src/dump.cc +4 -0
- data/ext/libcouchbase/src/getconfig.cc +1 -2
- data/ext/libcouchbase/src/handler.cc +65 -27
- data/ext/libcouchbase/src/hostlist.cc +35 -7
- data/ext/libcouchbase/src/hostlist.h +7 -0
- data/ext/libcouchbase/src/http/http-priv.h +2 -0
- data/ext/libcouchbase/src/http/http.cc +77 -37
- data/ext/libcouchbase/src/http/http_io.cc +19 -2
- data/ext/libcouchbase/src/instance.cc +90 -17
- data/ext/libcouchbase/src/internal.h +5 -0
- data/ext/libcouchbase/src/lcbio/connect.cc +39 -4
- data/ext/libcouchbase/src/lcbio/connect.h +27 -0
- data/ext/libcouchbase/src/lcbio/ctx.c +49 -23
- data/ext/libcouchbase/src/lcbio/ioutils.cc +30 -3
- data/ext/libcouchbase/src/lcbio/ioutils.h +2 -0
- data/ext/libcouchbase/src/lcbio/manager.cc +44 -8
- data/ext/libcouchbase/src/lcbio/manager.h +2 -0
- data/ext/libcouchbase/src/lcbio/rw-inl.h +1 -0
- data/ext/libcouchbase/src/lcbio/ssl.h +3 -5
- data/ext/libcouchbase/src/logging.c +1 -1
- data/ext/libcouchbase/src/logging.h +2 -0
- data/ext/libcouchbase/src/mc/compress.cc +164 -0
- data/ext/libcouchbase/src/mc/compress.h +7 -12
- data/ext/libcouchbase/src/mc/mcreq-flush-inl.h +5 -1
- data/ext/libcouchbase/src/mc/mcreq.c +11 -1
- data/ext/libcouchbase/src/mc/mcreq.h +35 -4
- data/ext/libcouchbase/src/mcserver/mcserver.cc +30 -7
- data/ext/libcouchbase/src/mcserver/mcserver.h +7 -0
- data/ext/libcouchbase/src/mcserver/negotiate.cc +103 -57
- data/ext/libcouchbase/src/mcserver/negotiate.h +2 -2
- data/ext/libcouchbase/src/mctx-helper.h +11 -0
- data/ext/libcouchbase/src/metrics.cc +132 -0
- data/ext/libcouchbase/src/n1ql/ixmgmt.cc +2 -1
- data/ext/libcouchbase/src/n1ql/n1ql.cc +66 -0
- data/ext/libcouchbase/src/newconfig.cc +9 -2
- data/ext/libcouchbase/src/operations/counter.cc +2 -1
- data/ext/libcouchbase/src/operations/durability-cas.cc +11 -0
- data/ext/libcouchbase/src/operations/durability-seqno.cc +3 -0
- data/ext/libcouchbase/src/operations/durability.cc +24 -2
- data/ext/libcouchbase/src/operations/durability_internal.h +19 -0
- data/ext/libcouchbase/src/operations/get.cc +4 -2
- data/ext/libcouchbase/src/operations/observe-seqno.cc +1 -0
- data/ext/libcouchbase/src/operations/observe.cc +113 -62
- data/ext/libcouchbase/src/operations/ping.cc +246 -67
- data/ext/libcouchbase/src/operations/remove.cc +2 -1
- data/ext/libcouchbase/src/operations/store.cc +17 -14
- data/ext/libcouchbase/src/operations/touch.cc +3 -0
- data/ext/libcouchbase/src/packetutils.h +68 -4
- data/ext/libcouchbase/src/probes.d +132 -161
- data/ext/libcouchbase/src/rdb/bigalloc.c +1 -1
- data/ext/libcouchbase/src/retryq.cc +6 -2
- data/ext/libcouchbase/src/rnd.cc +68 -0
- data/ext/libcouchbase/src/rnd.h +39 -0
- data/ext/libcouchbase/src/settings.c +27 -0
- data/ext/libcouchbase/src/settings.h +67 -3
- data/ext/libcouchbase/src/ssl/CMakeLists.txt +0 -12
- data/ext/libcouchbase/src/ssl/ssl_common.c +23 -4
- data/ext/libcouchbase/src/strcodecs/base64.c +141 -16
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +16 -1
- data/ext/libcouchbase/src/trace.h +68 -61
- data/ext/libcouchbase/src/tracing/span.cc +289 -0
- data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +171 -0
- data/ext/libcouchbase/src/tracing/tracer.cc +53 -0
- data/ext/libcouchbase/src/tracing/tracing-internal.h +213 -0
- data/ext/libcouchbase/src/utilities.c +5 -0
- data/ext/libcouchbase/src/vbucket/CMakeLists.txt +2 -2
- data/ext/libcouchbase/src/vbucket/vbucket.c +50 -18
- data/ext/libcouchbase/src/views/docreq.cc +26 -1
- data/ext/libcouchbase/src/views/docreq.h +17 -0
- data/ext/libcouchbase/src/views/viewreq.cc +64 -1
- data/ext/libcouchbase/src/views/viewreq.h +21 -0
- data/ext/libcouchbase/tests/CMakeLists.txt +6 -6
- data/ext/libcouchbase/tests/basic/t_base64.cc +34 -6
- data/ext/libcouchbase/tests/basic/t_connstr.cc +14 -0
- data/ext/libcouchbase/tests/basic/t_creds.cc +10 -10
- data/ext/libcouchbase/tests/basic/t_host.cc +22 -2
- data/ext/libcouchbase/tests/basic/t_scram.cc +514 -0
- data/ext/libcouchbase/tests/check-all.cc +6 -2
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +64 -0
- data/ext/libcouchbase/tests/iotests/mock-environment.h +27 -1
- data/ext/libcouchbase/tests/iotests/t_confmon.cc +2 -2
- data/ext/libcouchbase/tests/iotests/t_forward.cc +8 -0
- data/ext/libcouchbase/tests/iotests/t_netfail.cc +124 -0
- data/ext/libcouchbase/tests/iotests/t_smoke.cc +1 -1
- data/ext/libcouchbase/tests/iotests/t_snappy.cc +316 -0
- data/ext/libcouchbase/tests/socktests/socktest.cc +2 -2
- data/ext/libcouchbase/tests/socktests/t_basic.cc +6 -6
- data/ext/libcouchbase/tests/socktests/t_manager.cc +1 -1
- data/ext/libcouchbase/tests/socktests/t_ssl.cc +1 -1
- data/ext/libcouchbase/tools/CMakeLists.txt +1 -1
- data/ext/libcouchbase/tools/cbc-handlers.h +17 -0
- data/ext/libcouchbase/tools/cbc-n1qlback.cc +7 -4
- data/ext/libcouchbase/tools/cbc-pillowfight.cc +408 -100
- data/ext/libcouchbase/tools/cbc-proxy.cc +134 -3
- data/ext/libcouchbase/tools/cbc-subdoc.cc +1 -2
- data/ext/libcouchbase/tools/cbc.cc +113 -8
- data/ext/libcouchbase/tools/common/histogram.cc +1 -0
- data/ext/libcouchbase/tools/common/options.cc +28 -1
- data/ext/libcouchbase/tools/common/options.h +5 -0
- data/ext/libcouchbase/tools/docgen/docgen.h +36 -10
- data/ext/libcouchbase/tools/docgen/loc.h +5 -4
- data/ext/libcouchbase/tools/docgen/seqgen.h +28 -0
- data/lib/libcouchbase/ext/libcouchbase/enums.rb +10 -0
- data/lib/libcouchbase/n1ql.rb +6 -1
- data/lib/libcouchbase/version.rb +1 -1
- data/spec/connection_spec.rb +6 -6
- metadata +38 -5
- data/ext/libcouchbase/cmake/Modules/FindCouchbaseSnappy.cmake +0 -11
- data/ext/libcouchbase/src/mc/compress.c +0 -90
- data/ext/libcouchbase/tools/common/my_inttypes.h +0 -22
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
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
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @file
|
|
20
|
+
*
|
|
21
|
+
* This is a minimal example file showing how to connect to a cluster and
|
|
22
|
+
* set and retrieve a single item. This is copy of minimal.c, but with
|
|
23
|
+
* tracing enabled.
|
|
24
|
+
*
|
|
25
|
+
* docker run -d -p 9411:9411 openzipkin/zipkin
|
|
26
|
+
* make
|
|
27
|
+
* ./views couchbase://localhost/beer-sample password Administrator
|
|
28
|
+
*
|
|
29
|
+
* open browser at http://localhost:9411
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
#include <stdio.h>
|
|
33
|
+
#include <libcouchbase/couchbase.h>
|
|
34
|
+
#include <libcouchbase/api3.h>
|
|
35
|
+
#include <libcouchbase/views.h>
|
|
36
|
+
#include <stdlib.h>
|
|
37
|
+
#include <unistd.h>
|
|
38
|
+
#include <string.h> /* strlen */
|
|
39
|
+
#ifdef _WIN32
|
|
40
|
+
#define PRIx64 "I64x"
|
|
41
|
+
#define PRId64 "I64d"
|
|
42
|
+
#else
|
|
43
|
+
#include <inttypes.h>
|
|
44
|
+
#endif
|
|
45
|
+
|
|
46
|
+
#include <netdb.h>
|
|
47
|
+
#include <sys/types.h>
|
|
48
|
+
#include <netinet/in.h>
|
|
49
|
+
#include <sys/socket.h>
|
|
50
|
+
#include <arpa/inet.h>
|
|
51
|
+
|
|
52
|
+
#include "cJSON.h"
|
|
53
|
+
|
|
54
|
+
#define COMPONENT_NAME "demo"
|
|
55
|
+
|
|
56
|
+
struct zipkin_payload;
|
|
57
|
+
typedef struct zipkin_payload {
|
|
58
|
+
char *data;
|
|
59
|
+
struct zipkin_payload *next;
|
|
60
|
+
} zipkin_payload;
|
|
61
|
+
|
|
62
|
+
typedef struct zipkin_state {
|
|
63
|
+
char *json_api_host;
|
|
64
|
+
char *json_api_port;
|
|
65
|
+
/* [0, 100], where 0 is "never", 100 is "always" */
|
|
66
|
+
int sample_rate;
|
|
67
|
+
zipkin_payload *root;
|
|
68
|
+
zipkin_payload *last;
|
|
69
|
+
size_t content_length;
|
|
70
|
+
} zipkin_state;
|
|
71
|
+
|
|
72
|
+
void zipkin_destructor(lcbtrace_TRACER *tracer)
|
|
73
|
+
{
|
|
74
|
+
if (tracer) {
|
|
75
|
+
if (tracer->cookie) {
|
|
76
|
+
free(tracer->cookie);
|
|
77
|
+
tracer->cookie = NULL;
|
|
78
|
+
}
|
|
79
|
+
free(tracer);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void zipkin_report(lcbtrace_TRACER *tracer, lcbtrace_SPAN *span)
|
|
84
|
+
{
|
|
85
|
+
zipkin_state *state = NULL;
|
|
86
|
+
|
|
87
|
+
if (tracer == NULL) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
state = tracer->cookie;
|
|
91
|
+
if (state == NULL) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (rand() % 100 > state->sample_rate) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
#define BUFSZ 1000
|
|
100
|
+
size_t nbuf = BUFSZ;
|
|
101
|
+
char *buf;
|
|
102
|
+
lcbtrace_SPAN *parent;
|
|
103
|
+
uint64_t start;
|
|
104
|
+
zipkin_payload *payload = calloc(1, sizeof(zipkin_payload));
|
|
105
|
+
cJSON *json = cJSON_CreateObject();
|
|
106
|
+
|
|
107
|
+
buf = calloc(nbuf, sizeof(char));
|
|
108
|
+
cJSON_AddItemToObject(json, "name", cJSON_CreateString(lcbtrace_span_get_operation(span)));
|
|
109
|
+
snprintf(buf, nbuf, "%" PRIx64, lcbtrace_span_get_span_id(span));
|
|
110
|
+
cJSON_AddItemToObject(json, "id", cJSON_CreateString(buf));
|
|
111
|
+
snprintf(buf, nbuf, "%" PRIx64, lcbtrace_span_get_trace_id(span));
|
|
112
|
+
cJSON_AddItemToObject(json, "traceId", cJSON_CreateString(buf));
|
|
113
|
+
parent = lcbtrace_span_get_parent(span);
|
|
114
|
+
if (parent) {
|
|
115
|
+
snprintf(buf, nbuf, "%" PRIx64, lcbtrace_span_get_trace_id(parent));
|
|
116
|
+
cJSON_AddItemToObject(json, "parentId", cJSON_CreateString(buf));
|
|
117
|
+
}
|
|
118
|
+
start = lcbtrace_span_get_start_ts(span);
|
|
119
|
+
cJSON_AddItemToObject(json, "timestamp", cJSON_CreateNumber(start));
|
|
120
|
+
cJSON_AddItemToObject(json, "duration", cJSON_CreateNumber(lcbtrace_span_get_finish_ts(span) - start));
|
|
121
|
+
|
|
122
|
+
{
|
|
123
|
+
cJSON *endpoint = cJSON_CreateObject();
|
|
124
|
+
|
|
125
|
+
nbuf = BUFSZ;
|
|
126
|
+
if (lcbtrace_span_get_tag_str(span, LCBTRACE_TAG_DB_TYPE, &buf, &nbuf) == LCB_SUCCESS) {
|
|
127
|
+
buf[nbuf] = '\0';
|
|
128
|
+
cJSON_AddItemToObject(endpoint, "serviceName", cJSON_CreateString(buf));
|
|
129
|
+
}
|
|
130
|
+
cJSON_AddItemToObject(json, "localEndpoint", endpoint);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
{
|
|
134
|
+
cJSON *tags = cJSON_CreateObject();
|
|
135
|
+
uint64_t latency, operation_id;
|
|
136
|
+
if (lcbtrace_span_get_tag_uint64(span, LCBTRACE_TAG_PEER_LATENCY, &latency) == LCB_SUCCESS) {
|
|
137
|
+
cJSON_AddItemToObject(tags, LCBTRACE_TAG_PEER_LATENCY, cJSON_CreateNumber(latency));
|
|
138
|
+
}
|
|
139
|
+
if (lcbtrace_span_get_tag_uint64(span, LCBTRACE_TAG_OPERATION_ID, &operation_id) == LCB_SUCCESS) {
|
|
140
|
+
cJSON_AddItemToObject(tags, LCBTRACE_TAG_OPERATION_ID, cJSON_CreateNumber(operation_id));
|
|
141
|
+
}
|
|
142
|
+
nbuf = BUFSZ;
|
|
143
|
+
if (lcbtrace_span_get_tag_str(span, LCBTRACE_TAG_COMPONENT, &buf, &nbuf) == LCB_SUCCESS) {
|
|
144
|
+
buf[nbuf] = '\0';
|
|
145
|
+
cJSON_AddItemToObject(tags, LCBTRACE_TAG_COMPONENT, cJSON_CreateString(buf));
|
|
146
|
+
}
|
|
147
|
+
nbuf = BUFSZ;
|
|
148
|
+
if (lcbtrace_span_get_tag_str(span, LCBTRACE_TAG_PEER_ADDRESS, &buf, &nbuf) == LCB_SUCCESS) {
|
|
149
|
+
buf[nbuf] = '\0';
|
|
150
|
+
cJSON_AddItemToObject(tags, LCBTRACE_TAG_PEER_ADDRESS, cJSON_CreateString(buf));
|
|
151
|
+
}
|
|
152
|
+
nbuf = BUFSZ;
|
|
153
|
+
if (lcbtrace_span_get_tag_str(span, LCBTRACE_TAG_LOCAL_ADDRESS, &buf, &nbuf) == LCB_SUCCESS) {
|
|
154
|
+
buf[nbuf] = '\0';
|
|
155
|
+
cJSON_AddItemToObject(tags, LCBTRACE_TAG_LOCAL_ADDRESS, cJSON_CreateString(buf));
|
|
156
|
+
}
|
|
157
|
+
nbuf = BUFSZ;
|
|
158
|
+
if (lcbtrace_span_get_tag_str(span, LCBTRACE_TAG_DB_INSTANCE, &buf, &nbuf) == LCB_SUCCESS) {
|
|
159
|
+
buf[nbuf] = '\0';
|
|
160
|
+
cJSON_AddItemToObject(tags, LCBTRACE_TAG_DB_INSTANCE, cJSON_CreateString(buf));
|
|
161
|
+
}
|
|
162
|
+
if (cJSON_GetArraySize(tags) > 0) {
|
|
163
|
+
cJSON_AddItemToObject(json, "tags", tags);
|
|
164
|
+
} else {
|
|
165
|
+
cJSON_Delete(tags);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
free(buf);
|
|
169
|
+
|
|
170
|
+
payload->data = cJSON_PrintUnformatted(json);
|
|
171
|
+
cJSON_Delete(json);
|
|
172
|
+
if (state->last) {
|
|
173
|
+
state->last->next = payload;
|
|
174
|
+
}
|
|
175
|
+
state->last = payload;
|
|
176
|
+
state->content_length += strlen(payload->data) + 1; /* for comma/closing bracket */
|
|
177
|
+
if (state->root == NULL) {
|
|
178
|
+
state->root = payload;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void loop_send(int sock, char *bytes, ssize_t nbytes)
|
|
184
|
+
{
|
|
185
|
+
do {
|
|
186
|
+
ssize_t rv = send(sock, bytes, nbytes, 0);
|
|
187
|
+
if (rv < 0) {
|
|
188
|
+
perror("failed to send data to zipkin: ");
|
|
189
|
+
exit(EXIT_FAILURE);
|
|
190
|
+
} else if (rv < nbytes) {
|
|
191
|
+
nbytes -= rv;
|
|
192
|
+
bytes += rv;
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
} while (1);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
void zipkin_flush(lcbtrace_TRACER *tracer)
|
|
200
|
+
{
|
|
201
|
+
zipkin_state *state = NULL;
|
|
202
|
+
int sock, rv;
|
|
203
|
+
|
|
204
|
+
if (tracer == NULL) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
state = tracer->cookie;
|
|
208
|
+
if (state == NULL) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (state->root == NULL || state->content_length == 0) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
{
|
|
215
|
+
struct addrinfo hints, *addr, *a;
|
|
216
|
+
|
|
217
|
+
memset(&hints, 0, sizeof(hints));
|
|
218
|
+
hints.ai_family = AF_UNSPEC;
|
|
219
|
+
hints.ai_socktype = SOCK_STREAM;
|
|
220
|
+
rv = getaddrinfo(state->json_api_host, state->json_api_port, &hints, &addr);
|
|
221
|
+
if (rv != 0) {
|
|
222
|
+
fprintf(stderr, "failed to resolve zipkin address getaddrinfo: %s\n", gai_strerror(rv));
|
|
223
|
+
exit(EXIT_FAILURE);
|
|
224
|
+
}
|
|
225
|
+
for (a = addr; a != NULL; a = a->ai_next) {
|
|
226
|
+
sock = socket(a->ai_family, a->ai_socktype, a->ai_protocol);
|
|
227
|
+
if (sock == -1) {
|
|
228
|
+
perror("failed to create socket for zipkin: ");
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
rv = connect(sock, a->ai_addr, a->ai_addrlen);
|
|
232
|
+
if (rv == -1) {
|
|
233
|
+
perror("failed to connect socket for zipkin: ");
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
if (a == NULL) {
|
|
239
|
+
fprintf(stderr, "unable to connect to zipkin. terminating\n");
|
|
240
|
+
exit(EXIT_FAILURE);
|
|
241
|
+
}
|
|
242
|
+
freeaddrinfo(addr);
|
|
243
|
+
}
|
|
244
|
+
{
|
|
245
|
+
char preamble[1000] = "";
|
|
246
|
+
size_t size;
|
|
247
|
+
|
|
248
|
+
snprintf(preamble, sizeof(preamble),
|
|
249
|
+
"POST /api/v2/spans HTTP/1.1\r\n"
|
|
250
|
+
"Content-Type: application/json\r\n"
|
|
251
|
+
"Accept: */*\r\n"
|
|
252
|
+
"Connection: close\r\n"
|
|
253
|
+
"Host: %s:%s\r\n"
|
|
254
|
+
"Content-Length: %ld\r\n\r\n",
|
|
255
|
+
state->json_api_host, state->json_api_port, (long)state->content_length + 1 /* for open bracket */);
|
|
256
|
+
size = strlen(preamble);
|
|
257
|
+
|
|
258
|
+
rv = send(sock, preamble, size, 0);
|
|
259
|
+
if (rv == -1) {
|
|
260
|
+
perror("failed to send HTTP headers to zipkin: ");
|
|
261
|
+
exit(EXIT_FAILURE);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
{
|
|
265
|
+
zipkin_payload *ptr = state->root;
|
|
266
|
+
loop_send(sock, "[", 1);
|
|
267
|
+
while (ptr) {
|
|
268
|
+
zipkin_payload *tmp = ptr;
|
|
269
|
+
loop_send(sock, ptr->data, strlen(ptr->data));
|
|
270
|
+
ptr = ptr->next;
|
|
271
|
+
if (ptr) {
|
|
272
|
+
loop_send(sock, ",", 1);
|
|
273
|
+
}
|
|
274
|
+
free(tmp->data);
|
|
275
|
+
free(tmp);
|
|
276
|
+
}
|
|
277
|
+
loop_send(sock, "]", 1);
|
|
278
|
+
}
|
|
279
|
+
close(sock);
|
|
280
|
+
state->root = state->last = NULL;
|
|
281
|
+
state->content_length = 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
lcbtrace_TRACER *zipkin_new()
|
|
285
|
+
{
|
|
286
|
+
lcbtrace_TRACER *tracer = calloc(1, sizeof(lcbtrace_TRACER));
|
|
287
|
+
zipkin_state *zipkin = calloc(1, sizeof(zipkin_state));
|
|
288
|
+
tracer->destructor = zipkin_destructor;
|
|
289
|
+
tracer->flags = 0;
|
|
290
|
+
tracer->version = 0;
|
|
291
|
+
tracer->v.v0.report = zipkin_report;
|
|
292
|
+
zipkin->json_api_host = "localhost";
|
|
293
|
+
zipkin->json_api_port = "9411";
|
|
294
|
+
zipkin->sample_rate = 100;
|
|
295
|
+
zipkin->root = NULL;
|
|
296
|
+
zipkin->last = NULL;
|
|
297
|
+
zipkin->content_length = 0;
|
|
298
|
+
tracer->cookie = zipkin;
|
|
299
|
+
return tracer;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
static void die(lcb_t instance, const char *msg, lcb_error_t err)
|
|
303
|
+
{
|
|
304
|
+
fprintf(stderr, "%s. Received code 0x%X (%s)\n", msg, err, lcb_strerror(instance, err));
|
|
305
|
+
exit(EXIT_FAILURE);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
static void op_callback(lcb_t instance, int cbtype, const lcb_RESPBASE *rb)
|
|
309
|
+
{
|
|
310
|
+
fprintf(stderr, "=== %s ===\n", lcb_strcbtype(cbtype));
|
|
311
|
+
if (rb->rc == LCB_SUCCESS) {
|
|
312
|
+
fprintf(stderr, "KEY: %.*s\n", (int)rb->nkey, rb->key);
|
|
313
|
+
fprintf(stderr, "CAS: 0x%" PRIx64 "\n", rb->cas);
|
|
314
|
+
if (cbtype == LCB_CALLBACK_GET) {
|
|
315
|
+
const lcb_RESPGET *rg = (const lcb_RESPGET *)rb;
|
|
316
|
+
fprintf(stderr, "VALUE: %.*s\n", (int)rg->nvalue, rg->value);
|
|
317
|
+
fprintf(stderr, "FLAGS: 0x%x\n", rg->itmflags);
|
|
318
|
+
}
|
|
319
|
+
} else {
|
|
320
|
+
die(instance, lcb_strcbtype(cbtype), rb->rc);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
static void view_callback(lcb_t instance, int cbtype, const lcb_RESPVIEWQUERY *rv)
|
|
325
|
+
{
|
|
326
|
+
if (rv->rflags & LCB_RESP_F_FINAL) {
|
|
327
|
+
printf("*** META FROM VIEWS ***\n");
|
|
328
|
+
fprintf(stderr, "%.*s\n", (int)rv->nvalue, rv->value);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
printf("Got row callback from LCB: RC=0x%X, DOCID=%.*s. KEY=%.*s\n", rv->rc, (int)rv->ndocid, rv->docid,
|
|
333
|
+
(int)rv->nkey, rv->key);
|
|
334
|
+
|
|
335
|
+
if (rv->docresp) {
|
|
336
|
+
printf(" Document for response. RC=0x%X. CAS=0x%" PRIx64 "\n", rv->docresp->rc, rv->docresp->cas);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
int main(int argc, char *argv[])
|
|
341
|
+
{
|
|
342
|
+
lcb_error_t err;
|
|
343
|
+
lcb_t instance;
|
|
344
|
+
struct lcb_create_st create_options = {0};
|
|
345
|
+
lcb_CMDSTORE scmd = {0};
|
|
346
|
+
lcb_CMDGET gcmd = {0};
|
|
347
|
+
lcbtrace_SPAN *span = NULL;
|
|
348
|
+
lcbtrace_TRACER *tracer = NULL;
|
|
349
|
+
|
|
350
|
+
create_options.version = 3;
|
|
351
|
+
|
|
352
|
+
if (argc < 2) {
|
|
353
|
+
fprintf(stderr, "Usage: %s couchbase://host/bucket [ password [ username ] ]\n", argv[0]);
|
|
354
|
+
exit(EXIT_FAILURE);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
create_options.v.v3.connstr = argv[1];
|
|
358
|
+
if (argc > 2) {
|
|
359
|
+
create_options.v.v3.passwd = argv[2];
|
|
360
|
+
}
|
|
361
|
+
if (argc > 3) {
|
|
362
|
+
create_options.v.v3.username = argv[3];
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
srand(time(NULL));
|
|
366
|
+
|
|
367
|
+
err = lcb_create(&instance, &create_options);
|
|
368
|
+
if (err != LCB_SUCCESS) {
|
|
369
|
+
die(NULL, "Couldn't create couchbase handle", err);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
err = lcb_connect(instance);
|
|
373
|
+
if (err != LCB_SUCCESS) {
|
|
374
|
+
die(instance, "Couldn't schedule connection", err);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
lcb_wait(instance);
|
|
378
|
+
|
|
379
|
+
err = lcb_get_bootstrap_status(instance);
|
|
380
|
+
if (err != LCB_SUCCESS) {
|
|
381
|
+
die(instance, "Couldn't bootstrap from cluster", err);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/* Assign the handlers to be called for the operation types */
|
|
385
|
+
lcb_install_callback3(instance, LCB_CALLBACK_GET, op_callback);
|
|
386
|
+
lcb_install_callback3(instance, LCB_CALLBACK_STORE, op_callback);
|
|
387
|
+
|
|
388
|
+
tracer = zipkin_new();
|
|
389
|
+
|
|
390
|
+
lcb_set_tracer(instance, tracer);
|
|
391
|
+
|
|
392
|
+
span = lcbtrace_span_start(tracer, "transaction", 0, NULL);
|
|
393
|
+
lcbtrace_span_add_tag_str(span, LCBTRACE_TAG_COMPONENT, COMPONENT_NAME);
|
|
394
|
+
|
|
395
|
+
{
|
|
396
|
+
int encoding_time_us = rand() % 1000;
|
|
397
|
+
lcbtrace_SPAN *encoding;
|
|
398
|
+
lcbtrace_REF ref;
|
|
399
|
+
|
|
400
|
+
ref.type = LCBTRACE_REF_CHILD_OF;
|
|
401
|
+
ref.span = span;
|
|
402
|
+
|
|
403
|
+
encoding = lcbtrace_span_start(tracer, LCBTRACE_OP_REQUEST_ENCODING, 0, &ref);
|
|
404
|
+
lcbtrace_span_add_tag_str(encoding, LCBTRACE_TAG_COMPONENT, COMPONENT_NAME);
|
|
405
|
+
usleep(encoding_time_us);
|
|
406
|
+
lcbtrace_span_finish(encoding, LCBTRACE_NOW);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
lcb_CMDVIEWQUERY vcmd = {0};
|
|
410
|
+
char *doc_name = "beer";
|
|
411
|
+
char *view_name = "by_location";
|
|
412
|
+
char *options = "reduce=false&limit=3";
|
|
413
|
+
|
|
414
|
+
vcmd.callback = view_callback;
|
|
415
|
+
vcmd.ddoc = doc_name;
|
|
416
|
+
vcmd.nddoc = strlen(doc_name);
|
|
417
|
+
vcmd.view = view_name;
|
|
418
|
+
vcmd.nview = strlen(view_name);
|
|
419
|
+
vcmd.optstr = options;
|
|
420
|
+
vcmd.noptstr = strlen(options);
|
|
421
|
+
vcmd.cmdflags = LCB_CMDVIEWQUERY_F_INCLUDE_DOCS;
|
|
422
|
+
|
|
423
|
+
lcb_VIEWHANDLE handle;
|
|
424
|
+
vcmd.handle = &handle;
|
|
425
|
+
|
|
426
|
+
err = lcb_view_query(instance, NULL, &vcmd);
|
|
427
|
+
if (err != LCB_SUCCESS) {
|
|
428
|
+
die(instance, "Couldn't schedule view operation", err);
|
|
429
|
+
}
|
|
430
|
+
lcb_view_set_parent_span(instance, handle, span);
|
|
431
|
+
|
|
432
|
+
/* The store_callback is invoked from lcb_wait() */
|
|
433
|
+
fprintf(stderr, "Will wait for view operation to complete..\n");
|
|
434
|
+
lcb_wait(instance);
|
|
435
|
+
|
|
436
|
+
lcbtrace_span_finish(span, LCBTRACE_NOW);
|
|
437
|
+
|
|
438
|
+
zipkin_flush(tracer);
|
|
439
|
+
|
|
440
|
+
/* Now that we're all done, close down the connection handle */
|
|
441
|
+
lcb_destroy(instance);
|
|
442
|
+
|
|
443
|
+
return 0;
|
|
444
|
+
}
|
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2017-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
|
+
|
|
1
18
|
#ifndef LCB_AUTH_H
|
|
2
19
|
#define LCB_AUTH_H
|
|
3
20
|
|
|
@@ -178,7 +195,7 @@ void
|
|
|
178
195
|
lcbauth_ref(lcb_AUTHENTICATOR *auth);
|
|
179
196
|
|
|
180
197
|
/**
|
|
181
|
-
* @
|
|
198
|
+
* @uncommitted
|
|
182
199
|
*
|
|
183
200
|
* Decrements the refcount on the authenticator object, freeing it if there
|
|
184
201
|
* are no more owners.
|
|
@@ -190,7 +207,7 @@ void
|
|
|
190
207
|
lcbauth_unref(lcb_AUTHENTICATOR *auth);
|
|
191
208
|
|
|
192
209
|
/**
|
|
193
|
-
* @
|
|
210
|
+
* @uncommitted
|
|
194
211
|
*
|
|
195
212
|
* Makes a copy of an existing lcb_AUTHENTICATOR object. The returned
|
|
196
213
|
* authenticator object has a reference count of 1.
|
|
@@ -204,6 +221,33 @@ LIBCOUCHBASE_API
|
|
|
204
221
|
lcb_AUTHENTICATOR *
|
|
205
222
|
lcbauth_clone(const lcb_AUTHENTICATOR *src);
|
|
206
223
|
|
|
224
|
+
/**
|
|
225
|
+
* @private
|
|
226
|
+
*
|
|
227
|
+
* Callback invoked for LCBAUTH_MODE_DYNAMIC type of authenticator.
|
|
228
|
+
*
|
|
229
|
+
* @param cookie The opaque pointer, configured during callbacks setup.
|
|
230
|
+
* @param host The hostname of the service.
|
|
231
|
+
* @param port The port of the service.
|
|
232
|
+
* @param bucket The bucket name.
|
|
233
|
+
* @return password or username, depending on where the callback used
|
|
234
|
+
*/
|
|
235
|
+
typedef const char *(*lcb_AUTHCALLBACK)(void *cookie, const char *host, const char *port, const char *bucket);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @private
|
|
239
|
+
*
|
|
240
|
+
* Sets callback, which will be invoked every time the library needs credentials.
|
|
241
|
+
*
|
|
242
|
+
* @param auth
|
|
243
|
+
* @param cookie the opaque pointer, which will be passed to callbacks
|
|
244
|
+
* @param usercb the callback, which should return user name
|
|
245
|
+
* @param passcb the callback, which should return user name
|
|
246
|
+
*/
|
|
247
|
+
LIBCOUCHBASE_API
|
|
248
|
+
lcb_error_t lcbauth_set_callbacks(lcb_AUTHENTICATOR *auth, void *cookie, lcb_AUTHCALLBACK usercb,
|
|
249
|
+
lcb_AUTHCALLBACK passcb);
|
|
250
|
+
|
|
207
251
|
typedef enum {
|
|
208
252
|
/**
|
|
209
253
|
* Use "bucket-specific" credentials when authenticating. This is the
|
|
@@ -218,11 +262,19 @@ typedef enum {
|
|
|
218
262
|
* Note that if this option is selected, it becomes impossible to use
|
|
219
263
|
* @ref LCBAUTH_F_BUCKET with lcbauth_add_pass()
|
|
220
264
|
*/
|
|
221
|
-
LCBAUTH_MODE_RBAC = 1
|
|
265
|
+
LCBAUTH_MODE_RBAC = 1,
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* @private
|
|
269
|
+
*
|
|
270
|
+
* This mode allows to supply username/password with user-specified
|
|
271
|
+
* callback. See lcbauth_set_callback().
|
|
272
|
+
*/
|
|
273
|
+
LCBAUTH_MODE_DYNAMIC = 2
|
|
222
274
|
} lcbauth_MODE;
|
|
223
275
|
|
|
224
276
|
/**
|
|
225
|
-
* @
|
|
277
|
+
* @uncommitted
|
|
226
278
|
*
|
|
227
279
|
* Set the mode of this authenticator.
|
|
228
280
|
* @param src the authenticator
|