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
|
@@ -212,7 +212,7 @@ rdb_bigalloc_dump(rdb_BIGALLOC *alloc, FILE *fp)
|
|
|
212
212
|
{
|
|
213
213
|
static const char *indent = " ";
|
|
214
214
|
fprintf(fp, "BIGALLOC @%p\n", (void *)alloc);
|
|
215
|
-
fprintf(fp, "%sPooled Blocks: %lu\n", indent, LCB_CLIST_SIZE(&alloc->bufs));
|
|
215
|
+
fprintf(fp, "%sPooled Blocks: %lu\n", indent, (unsigned long int)LCB_CLIST_SIZE(&alloc->bufs));
|
|
216
216
|
fprintf(fp, "%sMinAlloc: %u\n", indent, alloc->min_blk_alloc);
|
|
217
217
|
fprintf(fp, "%sMaxAlloc: %u\n", indent, alloc->max_blk_alloc);
|
|
218
218
|
fprintf(fp, "%sMaxBlocks: %u\n", indent, alloc->max_blk_count);
|
|
@@ -195,8 +195,8 @@ RetryQueue::schedule(hrtime_t now)
|
|
|
195
195
|
diff = selected - now;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
lcb_log(LOGARGS(this, TRACE), "Next tick in %
|
|
198
|
+
uint64_t us_interval = LCB_NS2US(diff);
|
|
199
|
+
lcb_log(LOGARGS(this, TRACE), "Next tick in %" PRIu64 " ms", us_interval/1000);
|
|
200
200
|
lcbio_timer_rearm(timer, us_interval);
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -349,6 +349,10 @@ RetryQueue::add(mc_EXPACKET *pkt, const lcb_error_t err,
|
|
|
349
349
|
|
|
350
350
|
lcb_log(LOGARGS(this, DEBUG), "Adding PKT=%p to retry queue. Try count=%u", (void*)pkt, pkt->base.retries);
|
|
351
351
|
schedule();
|
|
352
|
+
|
|
353
|
+
if (settings->metrics) {
|
|
354
|
+
settings->metrics->packets_retried++;
|
|
355
|
+
}
|
|
352
356
|
}
|
|
353
357
|
|
|
354
358
|
void
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
#include "rnd.h"
|
|
19
|
+
#include "internal.h"
|
|
20
|
+
|
|
21
|
+
#if !defined(COMPILER_SUPPORTS_CXX11) || (defined(_MSC_VER) && _MSC_VER < 1600)
|
|
22
|
+
static volatile int rnd_initialized = 0;
|
|
23
|
+
LCB_INTERNAL_API
|
|
24
|
+
void lcb_rnd_global_init(void)
|
|
25
|
+
{
|
|
26
|
+
if (rnd_initialized) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
rnd_initialized = 1;
|
|
30
|
+
if (lcb_getenv_boolean("LCB_NO_SRAND")) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
srand(time(NULL));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
LCB_INTERNAL_API
|
|
37
|
+
lcb_U32 lcb_next_rand32(void)
|
|
38
|
+
{
|
|
39
|
+
return (lcb_U32)rand();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
LCB_INTERNAL_API
|
|
43
|
+
lcb_U64 lcb_next_rand64(void)
|
|
44
|
+
{
|
|
45
|
+
return (lcb_U64)rand();
|
|
46
|
+
}
|
|
47
|
+
#else
|
|
48
|
+
|
|
49
|
+
#include <random>
|
|
50
|
+
|
|
51
|
+
LCB_INTERNAL_API
|
|
52
|
+
lcb_U32 lcb_next_rand32(void)
|
|
53
|
+
{
|
|
54
|
+
static std::random_device rd;
|
|
55
|
+
static std::mt19937 gen(rd());
|
|
56
|
+
static std::uniform_int_distribution< lcb_U32 > dis;
|
|
57
|
+
return dis(gen);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
LCB_INTERNAL_API
|
|
61
|
+
lcb_U64 lcb_next_rand64(void)
|
|
62
|
+
{
|
|
63
|
+
static std::random_device rd;
|
|
64
|
+
static std::mt19937 gen(rd());
|
|
65
|
+
static std::uniform_int_distribution< lcb_U64 > dis;
|
|
66
|
+
return dis(gen);
|
|
67
|
+
}
|
|
68
|
+
#endif
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
#ifndef LIBCOUCHBASE_RND_H
|
|
19
|
+
#define LIBCOUCHBASE_RND_H 1
|
|
20
|
+
|
|
21
|
+
#include "config.h"
|
|
22
|
+
#include <libcouchbase/couchbase.h>
|
|
23
|
+
|
|
24
|
+
#ifdef __cplusplus
|
|
25
|
+
extern "C" {
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
LCB_INTERNAL_API lcb_U32 lcb_next_rand32(void);
|
|
29
|
+
LCB_INTERNAL_API lcb_U64 lcb_next_rand64(void);
|
|
30
|
+
|
|
31
|
+
#if !defined(COMPILER_SUPPORTS_CXX11) || (defined(_MSC_VER) && _MSC_VER < 1600)
|
|
32
|
+
LCB_INTERNAL_API void lcb_rnd_global_init(void);
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#ifdef __cplusplus
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#endif
|
|
@@ -46,6 +46,8 @@ void lcb_default_settings(lcb_settings *settings)
|
|
|
46
46
|
settings->retry[LCB_RETRY_ON_MISSINGNODE] = 0;
|
|
47
47
|
settings->bc_http_urltype = LCB_DEFAULT_HTCONFIG_URLTYPE;
|
|
48
48
|
settings->compressopts = LCB_DEFAULT_COMPRESSOPTS;
|
|
49
|
+
settings->compress_min_size = LCB_DEFAULT_COMPRESS_MIN_SIZE;
|
|
50
|
+
settings->compress_min_ratio = LCB_DEFAULT_COMPRESS_MIN_RATIO;
|
|
49
51
|
settings->allocator_factory = rdb_bigalloc_new;
|
|
50
52
|
settings->syncmode = LCB_ASYNCHRONOUS;
|
|
51
53
|
settings->detailed_neterr = 0;
|
|
@@ -57,11 +59,26 @@ void lcb_default_settings(lcb_settings *settings)
|
|
|
57
59
|
settings->tcp_nodelay = LCB_DEFAULT_TCP_NODELAY;
|
|
58
60
|
settings->retry_nmv_interval = LCB_DEFAULT_RETRY_NMV_INTERVAL;
|
|
59
61
|
settings->vb_noguess = LCB_DEFAULT_VB_NOGUESS;
|
|
62
|
+
settings->vb_noremap = LCB_DEFAULT_VB_NOREMAP;
|
|
60
63
|
settings->select_bucket = LCB_DEFAULT_SELECT_BUCKET;
|
|
61
64
|
settings->tcp_keepalive = LCB_DEFAULT_TCP_KEEPALIVE;
|
|
62
65
|
settings->send_hello = 1;
|
|
63
66
|
settings->config_poll_interval = LCB_DEFAULT_CONFIG_POLL_INTERVAL;
|
|
64
67
|
settings->use_errmap = 1;
|
|
68
|
+
settings->use_collections = 0;
|
|
69
|
+
settings->log_redaction = 0;
|
|
70
|
+
settings->use_tracing = 0;
|
|
71
|
+
#ifdef LCB_TRACING
|
|
72
|
+
settings->tracer_orphaned_queue_flush_interval = LCBTRACE_DEFAULT_ORPHANED_QUEUE_FLUSH_INTERVAL;
|
|
73
|
+
settings->tracer_orphaned_queue_size = LCBTRACE_DEFAULT_ORPHANED_QUEUE_SIZE;
|
|
74
|
+
settings->tracer_threshold_queue_flush_interval = LCBTRACE_DEFAULT_THRESHOLD_QUEUE_FLUSH_INTERVAL;
|
|
75
|
+
settings->tracer_threshold_queue_size = LCBTRACE_DEFAULT_THRESHOLD_QUEUE_SIZE;
|
|
76
|
+
settings->tracer_threshold[LCBTRACE_THRESHOLD_KV] = LCBTRACE_DEFAULT_THRESHOLD_KV;
|
|
77
|
+
settings->tracer_threshold[LCBTRACE_THRESHOLD_N1QL] = LCBTRACE_DEFAULT_THRESHOLD_N1QL;
|
|
78
|
+
settings->tracer_threshold[LCBTRACE_THRESHOLD_VIEW] = LCBTRACE_DEFAULT_THRESHOLD_VIEW;
|
|
79
|
+
settings->tracer_threshold[LCBTRACE_THRESHOLD_FTS] = LCBTRACE_DEFAULT_THRESHOLD_FTS;
|
|
80
|
+
settings->tracer_threshold[LCBTRACE_THRESHOLD_ANALYTICS] = LCBTRACE_DEFAULT_THRESHOLD_ANALYTICS;
|
|
81
|
+
#endif
|
|
65
82
|
}
|
|
66
83
|
|
|
67
84
|
LCB_INTERNAL_API
|
|
@@ -86,6 +103,7 @@ lcb_settings_unref(lcb_settings *settings)
|
|
|
86
103
|
free(settings->bucket);
|
|
87
104
|
free(settings->sasl_mech_force);
|
|
88
105
|
free(settings->certpath);
|
|
106
|
+
free(settings->keypath);
|
|
89
107
|
free(settings->client_string);
|
|
90
108
|
|
|
91
109
|
lcbauth_unref(settings->auth);
|
|
@@ -94,6 +112,15 @@ lcb_settings_unref(lcb_settings *settings)
|
|
|
94
112
|
if (settings->ssl_ctx) {
|
|
95
113
|
lcbio_ssl_free(settings->ssl_ctx);
|
|
96
114
|
}
|
|
115
|
+
if (settings->metrics) {
|
|
116
|
+
lcb_metrics_destroy(settings->metrics);
|
|
117
|
+
}
|
|
118
|
+
#ifdef LCB_TRACING
|
|
119
|
+
if (settings->tracer) {
|
|
120
|
+
lcbtrace_destroy(settings->tracer);
|
|
121
|
+
settings->tracer = NULL;
|
|
122
|
+
}
|
|
123
|
+
#endif
|
|
97
124
|
if (settings->dtorcb) {
|
|
98
125
|
settings->dtorcb(settings->dtorarg);
|
|
99
126
|
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
#define LCB_S2NS(s) (((hrtime_t)s) * 1000000000)
|
|
33
33
|
|
|
34
34
|
/** Convert nanoseconds to microseconds */
|
|
35
|
-
#define LCB_NS2US(s) (
|
|
35
|
+
#define LCB_NS2US(s) ((s) / 1000)
|
|
36
36
|
|
|
37
37
|
#define LCB_MS2US(s) ((s) * 1000)
|
|
38
38
|
|
|
@@ -80,11 +80,17 @@
|
|
|
80
80
|
#define LCB_DEFAULT_NETRETRY LCB_RETRY_CMDS_ALL
|
|
81
81
|
#define LCB_DEFAULT_NMVRETRY LCB_RETRY_CMDS_ALL
|
|
82
82
|
#define LCB_DEFAULT_HTCONFIG_URLTYPE LCB_HTCONFIG_URLTYPE_TRYALL
|
|
83
|
-
#define LCB_DEFAULT_COMPRESSOPTS
|
|
83
|
+
#define LCB_DEFAULT_COMPRESSOPTS LCB_COMPRESS_INOUT
|
|
84
|
+
|
|
85
|
+
/* in bytes */
|
|
86
|
+
#define LCB_DEFAULT_COMPRESS_MIN_SIZE 32
|
|
87
|
+
/* compressed_bytes / original_bytes */
|
|
88
|
+
#define LCB_DEFAULT_COMPRESS_MIN_RATIO 0.83
|
|
84
89
|
|
|
85
90
|
#define LCB_DEFAULT_NVM_RETRY_IMM 1
|
|
86
91
|
#define LCB_DEFAULT_RETRY_NMV_INTERVAL LCB_MS2US(100)
|
|
87
92
|
#define LCB_DEFAULT_VB_NOGUESS 1
|
|
93
|
+
#define LCB_DEFAULT_VB_NOREMAP 0
|
|
88
94
|
#define LCB_DEFAULT_TCP_NODELAY 1
|
|
89
95
|
#define LCB_DEFAULT_SELECT_BUCKET 1
|
|
90
96
|
#define LCB_DEFAULT_TCP_KEEPALIVE 1
|
|
@@ -93,10 +99,25 @@
|
|
|
93
99
|
/* 50 ms */
|
|
94
100
|
#define LCB_CONFIG_POLL_INTERVAL_FLOOR LCB_MS2US(50)
|
|
95
101
|
|
|
102
|
+
#define LCBTRACE_DEFAULT_ORPHANED_QUEUE_FLUSH_INTERVAL LCB_MS2US(1000)
|
|
103
|
+
#define LCBTRACE_DEFAULT_ORPHANED_QUEUE_SIZE 128
|
|
104
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_QUEUE_FLUSH_INTERVAL LCB_MS2US(3000)
|
|
105
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_QUEUE_SIZE 128
|
|
106
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_KV LCB_MS2US(500)
|
|
107
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_N1QL LCB_MS2US(1000)
|
|
108
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_VIEW LCB_MS2US(1000)
|
|
109
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_FTS LCB_MS2US(1000)
|
|
110
|
+
#define LCBTRACE_DEFAULT_THRESHOLD_ANALYTICS LCB_MS2US(1000)
|
|
111
|
+
|
|
96
112
|
#include "config.h"
|
|
97
113
|
#include <libcouchbase/couchbase.h>
|
|
114
|
+
#include <libcouchbase/metrics.h>
|
|
98
115
|
#include "errmap.h"
|
|
99
116
|
|
|
117
|
+
#ifdef LCB_TRACING
|
|
118
|
+
#include <libcouchbase/tracing.h>
|
|
119
|
+
#endif
|
|
120
|
+
|
|
100
121
|
#ifdef __cplusplus
|
|
101
122
|
extern "C" {
|
|
102
123
|
#endif
|
|
@@ -104,6 +125,7 @@ extern "C" {
|
|
|
104
125
|
struct lcb_logprocs_st;
|
|
105
126
|
struct lcbio_SSLCTX;
|
|
106
127
|
struct rdb_ALLOCATOR;
|
|
128
|
+
struct lcb_METRICS_st;
|
|
107
129
|
|
|
108
130
|
/**
|
|
109
131
|
* Stateless setting structure.
|
|
@@ -111,7 +133,8 @@ struct rdb_ALLOCATOR;
|
|
|
111
133
|
* which are intended to be passed around to other objects.
|
|
112
134
|
*/
|
|
113
135
|
typedef struct lcb_settings_st {
|
|
114
|
-
|
|
136
|
+
/* TODO: [SDK3] change to uint64_t as per RFC. logging API exposes it as unsigned int currently */
|
|
137
|
+
lcb_U32 iid;
|
|
115
138
|
lcb_U8 compressopts;
|
|
116
139
|
lcb_U8 syncmode;
|
|
117
140
|
lcb_U32 read_chunk_size;
|
|
@@ -164,6 +187,11 @@ typedef struct lcb_settings_st {
|
|
|
164
187
|
unsigned select_bucket : 1;
|
|
165
188
|
unsigned tcp_keepalive : 1;
|
|
166
189
|
unsigned send_hello : 1;
|
|
190
|
+
unsigned use_collections : 1;
|
|
191
|
+
unsigned log_redaction : 1;
|
|
192
|
+
unsigned use_tracing : 1;
|
|
193
|
+
/** Do not use remap vbuckets (do not use fast forward map, or any other heuristics) */
|
|
194
|
+
unsigned vb_noremap : 1;
|
|
167
195
|
|
|
168
196
|
short max_redir;
|
|
169
197
|
unsigned refcount;
|
|
@@ -173,7 +201,9 @@ typedef struct lcb_settings_st {
|
|
|
173
201
|
|
|
174
202
|
char *bucket;
|
|
175
203
|
char *sasl_mech_force;
|
|
204
|
+
char *truststorepath;
|
|
176
205
|
char *certpath;
|
|
206
|
+
char *keypath;
|
|
177
207
|
lcb_AUTHENTICATOR *auth;
|
|
178
208
|
struct rdb_ALLOCATOR* (*allocator_factory)(void);
|
|
179
209
|
struct lcbio_SSLCTX *ssl_ctx;
|
|
@@ -183,6 +213,17 @@ typedef struct lcb_settings_st {
|
|
|
183
213
|
char *client_string;
|
|
184
214
|
lcb_pERRMAP errmap;
|
|
185
215
|
lcb_U32 retry_nmv_interval;
|
|
216
|
+
struct lcb_METRICS_st *metrics;
|
|
217
|
+
#ifdef LCB_TRACING
|
|
218
|
+
lcbtrace_TRACER *tracer;
|
|
219
|
+
lcb_U32 tracer_orphaned_queue_flush_interval;
|
|
220
|
+
lcb_U32 tracer_orphaned_queue_size;
|
|
221
|
+
lcb_U32 tracer_threshold_queue_flush_interval;
|
|
222
|
+
lcb_U32 tracer_threshold_queue_size;
|
|
223
|
+
lcb_U32 tracer_threshold[LCBTRACE_THRESHOLD__MAX];
|
|
224
|
+
#endif
|
|
225
|
+
lcb_U32 compress_min_size;
|
|
226
|
+
float compress_min_ratio;
|
|
186
227
|
} lcb_settings;
|
|
187
228
|
|
|
188
229
|
LCB_INTERNAL_API
|
|
@@ -199,6 +240,29 @@ lcb_settings_unref(lcb_settings *);
|
|
|
199
240
|
#define lcb_settings_ref(settings) ((void)(settings)->refcount++)
|
|
200
241
|
#define lcb_settings_ref2(settings) ((settings)->refcount++, settings)
|
|
201
242
|
|
|
243
|
+
/**
|
|
244
|
+
* Metric functionality. Defined in metrics.h, but retains a global-like
|
|
245
|
+
* setting similar to lcb_settings
|
|
246
|
+
*/
|
|
247
|
+
void
|
|
248
|
+
lcb_metrics_dumpio(const lcb_IOMETRICS *metrics, FILE *fp);
|
|
249
|
+
|
|
250
|
+
void
|
|
251
|
+
lcb_metrics_dumpserver(const lcb_SERVERMETRICS *metrics, FILE *fp);
|
|
252
|
+
|
|
253
|
+
lcb_METRICS *
|
|
254
|
+
lcb_metrics_new(void);
|
|
255
|
+
|
|
256
|
+
void
|
|
257
|
+
lcb_metrics_destroy(lcb_METRICS *metrics);
|
|
258
|
+
|
|
259
|
+
lcb_SERVERMETRICS *
|
|
260
|
+
lcb_metrics_getserver(lcb_METRICS *metrics,
|
|
261
|
+
const char *host, const char *port, int create);
|
|
262
|
+
|
|
263
|
+
void
|
|
264
|
+
lcb_metrics_reset_pipeline_gauges(lcb_SERVERMETRICS *metrics);
|
|
265
|
+
|
|
202
266
|
#ifdef __cplusplus
|
|
203
267
|
}
|
|
204
268
|
#endif
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
IF(APPLE)
|
|
2
|
-
IF(NOT OpenSSL_DIR)
|
|
3
|
-
EXECUTE_PROCESS(COMMAND brew --prefix openssl
|
|
4
|
-
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
|
|
5
|
-
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
6
|
-
MESSAGE(STATUS "Found OpenSSL Prefix: ${OPENSSL_ROOT_DIR}")
|
|
7
|
-
ENDIF()
|
|
8
|
-
ENDIF()
|
|
9
|
-
|
|
10
|
-
FIND_PACKAGE(OpenSSL)
|
|
11
1
|
IF(OPENSSL_FOUND AND (NOT LCB_NO_SSL))
|
|
12
2
|
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
|
|
13
3
|
ADD_DEFINITIONS(${OPENSSL_DEFINITIONS})
|
|
@@ -15,9 +5,7 @@ IF(OPENSSL_FOUND AND (NOT LCB_NO_SSL))
|
|
|
15
5
|
SET(lcb_ssl_libs ${OPENSSL_LIBRARIES} PARENT_SCOPE)
|
|
16
6
|
SET(lcb_ssl_objs $<TARGET_OBJECTS:lcbssl> PARENT_SCOPE)
|
|
17
7
|
LCB_UTIL(lcbssl)
|
|
18
|
-
MESSAGE(STATUS "SSL Found")
|
|
19
8
|
ELSE()
|
|
20
9
|
SET(LCB_NO_SSL ON PARENT_SCOPE)
|
|
21
10
|
SET(lcb_ssl_libs "" PARENT_SCOPE)
|
|
22
|
-
MESSAGE(STATUS "SSL Not Found")
|
|
23
11
|
ENDIF()
|
|
@@ -255,9 +255,10 @@ struct lcbio_SSLCTX {
|
|
|
255
255
|
SSL_CTX *ctx;
|
|
256
256
|
};
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
#define LOGARGS_S(settings, lvl) settings, "SSL", lvl, __FILE__, __LINE__
|
|
259
|
+
|
|
260
|
+
lcbio_pSSLCTX lcbio_ssl_new(const char *tsfile, const char *cafile, const char *keyfile, int noverify,
|
|
261
|
+
lcb_error_t *errp, lcb_settings *settings)
|
|
261
262
|
{
|
|
262
263
|
lcb_error_t err_s;
|
|
263
264
|
lcbio_pSSLCTX ret;
|
|
@@ -281,10 +282,28 @@ lcbio_ssl_new(const char *cafile, int noverify, lcb_error_t *errp,
|
|
|
281
282
|
// SSL_CTX_set_cipher_list(ret->ctx, "!NULL");
|
|
282
283
|
|
|
283
284
|
if (cafile) {
|
|
284
|
-
|
|
285
|
+
lcb_log(LOGARGS_S(settings, LCB_LOG_DEBUG), "Load verify locations from \"%s\"", tsfile ? tsfile : keyfile);
|
|
286
|
+
if (!SSL_CTX_load_verify_locations(ret->ctx, tsfile ? tsfile : cafile, NULL)) {
|
|
285
287
|
*errp = LCB_SSL_ERROR;
|
|
286
288
|
goto GT_ERR;
|
|
287
289
|
}
|
|
290
|
+
if (keyfile) {
|
|
291
|
+
lcb_log(LOGARGS_S(settings, LCB_LOG_DEBUG), "Authenticate with key \"%s\", cert \"%s\"", keyfile, cafile);
|
|
292
|
+
if (!SSL_CTX_use_certificate_file(ret->ctx, cafile, SSL_FILETYPE_PEM)) {
|
|
293
|
+
*errp = LCB_SSL_ERROR;
|
|
294
|
+
goto GT_ERR;
|
|
295
|
+
}
|
|
296
|
+
if (!SSL_CTX_use_PrivateKey_file(ret->ctx, keyfile, SSL_FILETYPE_PEM)) {
|
|
297
|
+
lcb_log(LOGARGS_S(settings, LCB_LOG_ERROR), "Unable to load private key \"%s\"", keyfile);
|
|
298
|
+
*errp = LCB_SSL_ERROR;
|
|
299
|
+
goto GT_ERR;
|
|
300
|
+
}
|
|
301
|
+
if (!SSL_CTX_check_private_key(ret->ctx)) {
|
|
302
|
+
lcb_log(LOGARGS_S(settings, LCB_LOG_ERROR), "Unable to verify private key \"%s\"", keyfile);
|
|
303
|
+
*errp = LCB_SSL_ERROR;
|
|
304
|
+
goto GT_ERR;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
288
307
|
}
|
|
289
308
|
|
|
290
309
|
if (noverify) {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#include "strcodecs.h"
|
|
19
19
|
#include <string.h>
|
|
20
|
+
#include <stdlib.h>
|
|
20
21
|
|
|
21
22
|
/*
|
|
22
23
|
* Function to base64 encode a text string as described in RFC 4648
|
|
@@ -37,19 +38,19 @@ static const lcb_uint8_t code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrs
|
|
|
37
38
|
* @param num the number of characters from s to encode
|
|
38
39
|
* @return 0 upon success, -1 otherwise.
|
|
39
40
|
*/
|
|
40
|
-
static int encode_rest(const lcb_uint8_t *s, lcb_uint8_t *d,
|
|
41
|
+
static int encode_rest(const lcb_uint8_t *s, lcb_uint8_t *d, lcb_SIZE num)
|
|
41
42
|
{
|
|
42
43
|
lcb_uint32_t val = 0;
|
|
43
44
|
|
|
44
45
|
switch (num) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
case 2:
|
|
47
|
+
val = (lcb_uint32_t)((*s << 16) | (*(s + 1) << 8));
|
|
48
|
+
break;
|
|
49
|
+
case 1:
|
|
50
|
+
val = (lcb_uint32_t)((*s << 16));
|
|
51
|
+
break;
|
|
52
|
+
default:
|
|
53
|
+
return -1;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
d[3] = '=';
|
|
@@ -75,7 +76,7 @@ static int encode_rest(const lcb_uint8_t *s, lcb_uint8_t *d, lcb_size_t num)
|
|
|
75
76
|
static int encode_triplet(const lcb_uint8_t *s, lcb_uint8_t *d)
|
|
76
77
|
{
|
|
77
78
|
lcb_uint32_t val = (lcb_uint32_t)((*s << 16) | (*(s + 1) << 8) | (*(s + 2)));
|
|
78
|
-
d[3] = code[val & 63]
|
|
79
|
+
d[3] = code[val & 63];
|
|
79
80
|
d[2] = code[(val >> 6) & 63];
|
|
80
81
|
d[1] = code[(val >> 12) & 63];
|
|
81
82
|
d[0] = code[(val >> 18) & 63];
|
|
@@ -90,16 +91,15 @@ static int encode_triplet(const lcb_uint8_t *s, lcb_uint8_t *d)
|
|
|
90
91
|
* @param sz size of destination buffer
|
|
91
92
|
* @return 0 if success, -1 if the destination buffer isn't big enough
|
|
92
93
|
*/
|
|
93
|
-
int lcb_base64_encode(const char *src, char *dst,
|
|
94
|
+
int lcb_base64_encode(const char *src, lcb_SIZE len, char *dst, lcb_SIZE sz)
|
|
94
95
|
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
lcb_size_t ii;
|
|
96
|
+
lcb_SIZE triplets = len / 3;
|
|
97
|
+
lcb_SIZE rest = len % 3;
|
|
98
|
+
lcb_SIZE ii;
|
|
99
99
|
const lcb_uint8_t *in = (const lcb_uint8_t *)src;
|
|
100
100
|
lcb_uint8_t *out = (lcb_uint8_t *)dst;
|
|
101
101
|
|
|
102
|
-
if (sz < (
|
|
102
|
+
if (sz < (lcb_SIZE)((triplets + 1) * 4)) {
|
|
103
103
|
return -1;
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -121,3 +121,128 @@ int lcb_base64_encode(const char *src, char *dst, lcb_size_t sz)
|
|
|
121
121
|
|
|
122
122
|
return 0;
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
int lcb_base64_encode2(const char *src, lcb_SIZE nsrc, char **dst, lcb_SIZE *ndst)
|
|
126
|
+
{
|
|
127
|
+
lcb_SIZE len = (nsrc / 3 + 1) * 4 + 1;
|
|
128
|
+
char *ptr = calloc(len, sizeof(char));
|
|
129
|
+
int rc = lcb_base64_encode(src, nsrc, ptr, len);
|
|
130
|
+
if (rc == 0) {
|
|
131
|
+
*ndst = strlen(ptr);
|
|
132
|
+
*dst = ptr;
|
|
133
|
+
} else {
|
|
134
|
+
free(ptr);
|
|
135
|
+
}
|
|
136
|
+
return rc;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static int code2val(char c)
|
|
140
|
+
{
|
|
141
|
+
if (c >= 'A' && c <= 'Z') {
|
|
142
|
+
return c - 'A';
|
|
143
|
+
}
|
|
144
|
+
if (c >= 'a' && c <= 'z') {
|
|
145
|
+
return c - 'a' + 26;
|
|
146
|
+
}
|
|
147
|
+
if (c >= '0' && c <= '9') {
|
|
148
|
+
return c - '0' + 52;
|
|
149
|
+
}
|
|
150
|
+
if (c == '+') {
|
|
151
|
+
return 62;
|
|
152
|
+
}
|
|
153
|
+
if (c == '/') {
|
|
154
|
+
return 63;
|
|
155
|
+
}
|
|
156
|
+
return -1;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
lcb_SSIZE lcb_base64_decode(const char *src, lcb_SIZE nsrc, char *dst, lcb_SIZE ndst)
|
|
160
|
+
{
|
|
161
|
+
lcb_SIZE offset = 0;
|
|
162
|
+
lcb_SSIZE idx = 0;
|
|
163
|
+
|
|
164
|
+
if (nsrc == 0) {
|
|
165
|
+
*dst = '\0';
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
while (offset < nsrc) {
|
|
170
|
+
int val, ins;
|
|
171
|
+
lcb_U32 value;
|
|
172
|
+
|
|
173
|
+
if (isspace((int)*src)) {
|
|
174
|
+
++offset;
|
|
175
|
+
++src;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// We need at least 4 bytes
|
|
180
|
+
if ((offset + 4) > nsrc) {
|
|
181
|
+
return -1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
val = code2val(src[0]);
|
|
185
|
+
if (val < 0) {
|
|
186
|
+
return -1;
|
|
187
|
+
}
|
|
188
|
+
value = val << 18;
|
|
189
|
+
val = code2val(src[1]);
|
|
190
|
+
if (val < 0) {
|
|
191
|
+
return -1;
|
|
192
|
+
}
|
|
193
|
+
value |= val << 12;
|
|
194
|
+
|
|
195
|
+
ins = 3; /* number of characters to insert */
|
|
196
|
+
if (src[2] == '=') {
|
|
197
|
+
ins = 1;
|
|
198
|
+
} else {
|
|
199
|
+
value |= code2val(src[2]) << 6;
|
|
200
|
+
if (src[3] == '=') {
|
|
201
|
+
ins = 2;
|
|
202
|
+
} else {
|
|
203
|
+
value |= code2val(src[3]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if ((lcb_SIZE)idx >= ndst) {
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
dst[idx++] = (char)(value >> 16);
|
|
211
|
+
if (ins > 1) {
|
|
212
|
+
if ((lcb_SIZE)idx >= ndst) {
|
|
213
|
+
return -1;
|
|
214
|
+
}
|
|
215
|
+
dst[idx++] = (char)(value >> 8);
|
|
216
|
+
if (ins > 2) {
|
|
217
|
+
if ((lcb_SIZE)idx >= ndst) {
|
|
218
|
+
return -1;
|
|
219
|
+
}
|
|
220
|
+
dst[idx++] = (char)(value);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
src += 4;
|
|
225
|
+
offset += 4;
|
|
226
|
+
}
|
|
227
|
+
dst[idx + 1] = '\0';
|
|
228
|
+
|
|
229
|
+
return idx;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
lcb_SSIZE lcb_base64_decode2(const char *src, lcb_SIZE nsrc, char **dst, lcb_SIZE *ndst)
|
|
233
|
+
{
|
|
234
|
+
// To reduce the number of reallocations, start by reserving an
|
|
235
|
+
// output buffer of 75% of the input size (and add 3 to avoid dealing
|
|
236
|
+
// with zero)
|
|
237
|
+
lcb_SIZE len = nsrc * 3 / 4 + 3;
|
|
238
|
+
char *ptr = calloc(len, sizeof(char));
|
|
239
|
+
|
|
240
|
+
lcb_SSIZE rc = lcb_base64_decode(src, nsrc, ptr, len);
|
|
241
|
+
if (rc < 0) {
|
|
242
|
+
free(ptr);
|
|
243
|
+
} else {
|
|
244
|
+
*ndst = rc;
|
|
245
|
+
*dst = ptr;
|
|
246
|
+
}
|
|
247
|
+
return rc;
|
|
248
|
+
}
|