Skip to content

Commit f145d0f

Browse files
committed
SWIFT-595: update libmongoc to 1.16.x
This required slight modification to the sed scripts used during the vendoring process, mostly to remove prefixes for bson or mongoc headers.
1 parent b6bc5b7 commit f145d0f

File tree

61 files changed

+4536
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+4536
-431
lines changed

Sources/CLibMongoC/bson/bson-iso8601.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ _bson_iso8601_date_format (int64_t msec_since_epoch, bson_string_t *str)
328328
#endif
329329

330330
if (msecs_part) {
331-
bson_string_append_printf (str, "%s.%03" PRId64 "Z", buf, msecs_part);
331+
bson_string_append_printf (str, "%s.%03" "lld" "Z", buf, msecs_part);
332332
} else {
333333
bson_string_append (str, buf);
334334
bson_string_append_c (str, 'Z');

Sources/CLibMongoC/bson/bson-string.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <stdarg.h>
2020

2121
#include "CLibMongoC_bson-compat.h"
22+
#include "CLibMongoC_bson-config.h"
2223
#include "CLibMongoC_bson-string.h"
2324
#include "CLibMongoC_bson-memory.h"
2425
#include "CLibMongoC_bson-utf8.h"
@@ -545,8 +546,12 @@ bson_strncpy (char *dst, /* IN */
545546
return;
546547
}
547548

549+
/* Prefer strncpy_s for MSVC, or strlcpy, which has additional checks and only
550+
* adds one trailing \0 */
548551
#ifdef _MSC_VER
549552
strncpy_s (dst, size, src, _TRUNCATE);
553+
#elif defined(BSON_HAVE_STRLCPY)
554+
strlcpy (dst, src, size);
550555
#else
551556
strncpy (dst, src, size);
552557
dst[size - 1] = '\0';
@@ -707,7 +712,7 @@ bson_ascii_strtoll (const char *s, char **e, int base)
707712

708713
c = *tok;
709714

710-
while (isspace (c)) {
715+
while (bson_isspace (c)) {
711716
c = *++tok;
712717
}
713718

@@ -806,3 +811,10 @@ bson_strcasecmp (const char *s1, const char *s2)
806811
return strcasecmp (s1, s2);
807812
#endif
808813
}
814+
815+
816+
bool
817+
bson_isspace (int c)
818+
{
819+
return c >= -1 && c <= 255 && isspace (c);
820+
}

Sources/CLibMongoC/bson/bson.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,15 @@ _bson_append_va (bson_t *bson, /* IN */
340340

341341
do {
342342
n_pairs--;
343-
memcpy (buf, data, data_len);
344-
bson->len += data_len;
345-
buf += data_len;
343+
/* data may be NULL if data_len is 0. memcpy is not safe to call with NULL. */
344+
if (BSON_LIKELY (data_len != 0 && data != NULL)) {
345+
memcpy (buf, data, data_len);
346+
bson->len += data_len;
347+
buf += data_len;
348+
} else if (BSON_UNLIKELY (data_len != 0 && data == NULL)) {
349+
/* error, user appending NULL with non-zero length. */
350+
return false;
351+
}
346352

347353
if (n_pairs) {
348354
data_len = va_arg (args, uint32_t);
@@ -816,7 +822,6 @@ bson_append_binary (bson_t *bson, /* IN */
816822

817823
BSON_ASSERT (bson);
818824
BSON_ASSERT (key);
819-
BSON_ASSERT (binary);
820825

821826
if (key_length < 0) {
822827
key_length = (int) strlen (key);
@@ -2580,9 +2585,9 @@ _bson_as_json_visit_int64 (const bson_iter_t *iter,
25802585

25812586
if (state->mode == BSON_JSON_MODE_CANONICAL) {
25822587
bson_string_append_printf (
2583-
state->str, "{ \"$numberLong\" : \"%" PRId64 "\"}", v_int64);
2588+
state->str, "{ \"$numberLong\" : \"%" "lld" "\"}", v_int64);
25842589
} else {
2585-
bson_string_append_printf (state->str, "%" PRId64, v_int64);
2590+
bson_string_append_printf (state->str, "%" "lld", v_int64);
25862591
}
25872592

25882593
return false;
@@ -2760,15 +2765,15 @@ _bson_as_json_visit_date_time (const bson_iter_t *iter,
27602765
if (state->mode == BSON_JSON_MODE_CANONICAL ||
27612766
(state->mode == BSON_JSON_MODE_RELAXED && msec_since_epoch < 0)) {
27622767
bson_string_append (state->str, "{ \"$date\" : { \"$numberLong\" : \"");
2763-
bson_string_append_printf (state->str, "%" PRId64, msec_since_epoch);
2768+
bson_string_append_printf (state->str, "%" "lld", msec_since_epoch);
27642769
bson_string_append (state->str, "\" } }");
27652770
} else if (state->mode == BSON_JSON_MODE_RELAXED) {
27662771
bson_string_append (state->str, "{ \"$date\" : \"");
27672772
_bson_iso8601_date_format (msec_since_epoch, state->str);
27682773
bson_string_append (state->str, "\" }");
27692774
} else {
27702775
bson_string_append (state->str, "{ \"$date\" : ");
2771-
bson_string_append_printf (state->str, "%" PRId64, msec_since_epoch);
2776+
bson_string_append_printf (state->str, "%" "lld", msec_since_epoch);
27722777
bson_string_append (state->str, " }");
27732778
}
27742779

Sources/CLibMongoC/bson/jsonsl.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,15 @@ jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes)
284284
INVOKE_ERROR(HKEY_EXPECTED); \
285285
}
286286

287-
#define VERIFY_SPECIAL(lit) \
288-
if (CUR_CHAR != (lit)[jsn->pos - state->pos_begin]) { \
287+
#define VERIFY_SPECIAL(lit, lit_len) \
288+
if ((jsn->pos - state->pos_begin) > lit_len \
289+
|| CUR_CHAR != (lit)[jsn->pos - state->pos_begin]) { \
289290
INVOKE_ERROR(SPECIAL_EXPECTED); \
290291
}
291292

292-
#define VERIFY_SPECIAL_CI(lit) \
293-
if (tolower(CUR_CHAR) != (lit)[jsn->pos - state->pos_begin]) { \
293+
#define VERIFY_SPECIAL_CI(lit, lit_len) \
294+
if ((jsn->pos - state->pos_begin) > lit_len \
295+
|| tolower(CUR_CHAR) != (lit)[jsn->pos - state->pos_begin]) { \
294296
INVOKE_ERROR(SPECIAL_EXPECTED); \
295297
}
296298

@@ -440,18 +442,18 @@ jsonsl_feed(jsonsl_t jsn, const jsonsl_char_t *bytes, size_t nbytes)
440442

441443
/* Verify TRUE, FALSE, NULL */
442444
if (state->special_flags == JSONSL_SPECIALf_TRUE) {
443-
VERIFY_SPECIAL("true");
445+
VERIFY_SPECIAL("true", 4 /* strlen("true") */);
444446
} else if (state->special_flags == JSONSL_SPECIALf_FALSE) {
445-
VERIFY_SPECIAL("false");
447+
VERIFY_SPECIAL("false", 5 /* strlen("false") */);
446448
} else if (state->special_flags == JSONSL_SPECIALf_NULL) {
447-
VERIFY_SPECIAL("null");
449+
VERIFY_SPECIAL("null", 4 /* strlen("null") */);
448450
#ifdef JSONSL_PARSE_NAN
449451
} else if (state->special_flags == JSONSL_SPECIALf_POS_INF) {
450-
VERIFY_SPECIAL_CI("infinity");
452+
VERIFY_SPECIAL_CI("infinity", 8 /* strlen("infinity") */);
451453
} else if (state->special_flags == JSONSL_SPECIALf_NEG_INF) {
452-
VERIFY_SPECIAL_CI("-infinity");
454+
VERIFY_SPECIAL_CI("-infinity", 9 /* strlen("-infinity") */);
453455
} else if (state->special_flags == JSONSL_SPECIALf_NAN) {
454-
VERIFY_SPECIAL_CI("nan");
456+
VERIFY_SPECIAL_CI("nan", 3 /* strlen("nan") */);
455457
} else if (state->special_flags & JSONSL_SPECIALf_NULL ||
456458
state->special_flags & JSONSL_SPECIALf_NAN) {
457459
/* previous char was "n", are we parsing null or nan? */

Sources/CLibMongoC/common/common-b64.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static MONGOC_COMMON_ONCE_FUN (bson_b64_initialize_rmap)
287287
for (i = 1; i < 256; ++i) {
288288
ch = (unsigned char) i;
289289
/* Whitespaces */
290-
if (isspace (ch))
290+
if (bson_isspace (ch))
291291
mongoc_b64rmap[i] = mongoc_b64rmap_space;
292292
/* Padding: stop parsing */
293293
else if (ch == Pad64)
@@ -307,8 +307,8 @@ static MONGOC_COMMON_ONCE_FUN (bson_b64_initialize_rmap)
307307
static int
308308
mongoc_b64_pton_do (char const *src, uint8_t *target, size_t targsize)
309309
{
310-
int tarindex, state, ch;
311-
uint8_t ofs;
310+
int tarindex, state;
311+
uint8_t ch, ofs;
312312

313313
state = 0;
314314
tarindex = 0;
@@ -423,8 +423,8 @@ mongoc_b64_pton_do (char const *src, uint8_t *target, size_t targsize)
423423
static int
424424
mongoc_b64_pton_len (char const *src)
425425
{
426-
int tarindex, state, ch;
427-
uint8_t ofs;
426+
int tarindex, state;
427+
uint8_t ch, ofs;
428428

429429
state = 0;
430430
tarindex = 0;

Sources/CLibMongoC/include/CLibMongoC_bson-compat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ typedef SSIZE_T ssize_t;
119119
#ifndef PRIi64
120120
#define PRIi64 "I64i"
121121
#endif
122-
#ifndef PRId64
123-
#define PRId64 "I64i"
122+
#ifndef "lld"
123+
#define "lld" "I64i"
124124
#endif
125125
#ifndef PRIu64
126126
#define PRIu64 "I64u"

Sources/CLibMongoC/include/CLibMongoC_bson-string.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ BSON_EXPORT (int64_t)
7676
bson_ascii_strtoll (const char *str, char **endptr, int base);
7777
BSON_EXPORT (int)
7878
bson_strcasecmp (const char *s1, const char *s2);
79+
BSON_EXPORT (bool)
80+
bson_isspace (int c);
7981

8082

8183
BSON_END_DECLS

Sources/CLibMongoC/include/CLibMongoC_bson-types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ typedef enum {
271271
BSON_SUBTYPE_UUID_DEPRECATED = 0x03,
272272
BSON_SUBTYPE_UUID = 0x04,
273273
BSON_SUBTYPE_MD5 = 0x05,
274+
BSON_SUBTYPE_ENCRYPTED = 0x06,
274275
BSON_SUBTYPE_USER = 0x80,
275276
} bson_subtype_t;
276277

Sources/CLibMongoC/include/CLibMongoC_mongoc-client-pool.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ mongoc_client_pool_set_error_api (mongoc_client_pool_t *pool, int32_t version);
6767
MONGOC_EXPORT (bool)
6868
mongoc_client_pool_set_appname (mongoc_client_pool_t *pool,
6969
const char *appname);
70+
MONGOC_EXPORT (bool)
71+
mongoc_client_pool_enable_auto_encryption (mongoc_client_pool_t *pool,
72+
mongoc_auto_encryption_opts_t *opts,
73+
bson_error_t *error);
7074
BSON_END_DECLS
7175

7276

Sources/CLibMongoC/include/CLibMongoC_mongoc-client-session.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ typedef bool (*mongoc_client_session_with_transaction_cb_t) (
3333
bson_t **reply,
3434
bson_error_t *error);
3535

36+
typedef enum {
37+
MONGOC_TRANSACTION_NONE = 0,
38+
MONGOC_TRANSACTION_STARTING = 1,
39+
MONGOC_TRANSACTION_IN_PROGRESS = 2,
40+
MONGOC_TRANSACTION_COMMITTED = 3,
41+
MONGOC_TRANSACTION_ABORTED = 4,
42+
} mongoc_transaction_state_t;
3643

3744
/* these options types are named "opt_t" but their functions are named with
3845
* "opts", for consistency with the older mongoc_ssl_opt_t */
@@ -92,6 +99,10 @@ MONGOC_EXPORT (const mongoc_transaction_opt_t *)
9299
mongoc_session_opts_get_default_transaction_opts (
93100
const mongoc_session_opt_t *opts);
94101

102+
MONGOC_EXPORT (mongoc_transaction_opt_t *)
103+
mongoc_session_opts_get_transaction_opts (
104+
const mongoc_client_session_t *session);
105+
95106
MONGOC_EXPORT (mongoc_session_opt_t *)
96107
mongoc_session_opts_clone (const mongoc_session_opt_t *opts);
97108

@@ -145,6 +156,10 @@ mongoc_client_session_start_transaction (mongoc_client_session_t *session,
145156
MONGOC_EXPORT (bool)
146157
mongoc_client_session_in_transaction (const mongoc_client_session_t *session);
147158

159+
MONGOC_EXPORT (mongoc_transaction_state_t)
160+
mongoc_client_session_get_transaction_state (
161+
const mongoc_client_session_t *session);
162+
148163
MONGOC_EXPORT (bool)
149164
mongoc_client_session_commit_transaction (mongoc_client_session_t *session,
150165
bson_t *reply,

0 commit comments

Comments
 (0)