Skip to content

Commit 8bc8be5

Browse files
committed
PHPC-1369: Upgrade libmongoc to 1.15-dev
Use int64_t API for wTimeoutMS. The initial commit for CDRIVER-3087 deprecated the int32_t API for wTimeoutMS. Migrate to the int64_t API to avoid deprecation warnings. Note: PHPC (and libmongoc's URI parsing) still require 32-bit values for wTimeoutMS, so this does not affect users. Having said that, PHPC-1411 may introduce support for 64-bit values and necessitate changes to the code where we read wTimeoutMS values. Use mongoc_uri_get_tls to read tls/ssl URI option. As part of CDRIVER-2869, libmongoc deprecated mongoc_uri_get_ssl and introduced a "tls" alias. Migrate to the new API to avoid deprecation warnings. Expect lowercase URI option in error. As part of CDRIVER-2869, libmongoc does case-folding on option keys to facilitate deduplication.
1 parent 5875b8d commit 8bc8be5

File tree

7 files changed

+30
-22
lines changed

7 files changed

+30
-22
lines changed

config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ if test "$PHP_MONGODB" != "no"; then
300300
PHP_MONGODB_JSONSL_SOURCES="jsonsl.c"
301301

302302
dnl Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -z | tr '\000' ' '
303-
PHP_MONGODB_MONGOC_SOURCES="mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-index.c mongoc-init.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-openssl.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-description.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c"
303+
PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-index.c mongoc-init.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-openssl.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-description.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c"
304304

305305
dnl Generated with: find src/libmongoc/src/zlib-1.2.11 -maxdepth 1 -name '*.c' -print0 | cut -sz -d / -f 5- | sort -z | tr '\000' ' '
306306
PHP_MONGODB_ZLIB_SOURCES="adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c"

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ if (PHP_MONGODB != "no") {
8383
var PHP_MONGODB_JSONSL_SOURCES="jsonsl.c";
8484

8585
// Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -z | tr '\000' ' '
86-
var PHP_MONGODB_MONGOC_SOURCES="mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-index.c mongoc-init.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-openssl.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-description.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c";
86+
var PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-index.c mongoc-init.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-openssl.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-description.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c";
8787

8888
EXTENSION("mongodb", "php_phongo.c phongo_compat.c", null, PHP_MONGODB_CFLAGS);
8989
ADD_SOURCES(configure_module_dirname + "/src", "bson.c bson-encode.c", "mongodb");

php_phongo.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ void php_phongo_write_concern_to_zval(zval* retval, const mongoc_write_concern_t
13601360
{
13611361
const char* wtag = mongoc_write_concern_get_wtag(write_concern);
13621362
const int32_t w = mongoc_write_concern_get_w(write_concern);
1363-
const int32_t wtimeout = mongoc_write_concern_get_wtimeout(write_concern);
1363+
const int64_t wtimeout = mongoc_write_concern_get_wtimeout_int64(write_concern);
13641364

13651365
array_init_size(retval, 4);
13661366

@@ -1377,7 +1377,10 @@ void php_phongo_write_concern_to_zval(zval* retval, const mongoc_write_concern_t
13771377
}
13781378

13791379
if (wtimeout != 0) {
1380-
ADD_ASSOC_LONG_EX(retval, "wtimeout", wtimeout);
1380+
/* Note: PHP currently enforces that wimeoutMS is a 32-bit integer, so
1381+
* casting will never truncate the value. This may change with
1382+
* PHPC-1411. */
1383+
ADD_ASSOC_LONG_EX(retval, "wtimeout", (int32_t) wtimeout);
13811384
}
13821385
} /* }}} */
13831386
/* }}} */
@@ -1900,25 +1903,27 @@ static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t* uri, bson_t* option
19001903
}
19011904

19021905
if (bson_iter_init_find_case(&iter, options, MONGOC_URI_WTIMEOUTMS)) {
1903-
int32_t wtimeout;
1906+
int64_t wtimeout;
19041907

1908+
/* Although the write concern spec defines wtimeoutMS as 64-bit, PHP has
1909+
* historically required 32-bit. This may change with PHPC-1411. */
19051910
if (!BSON_ITER_HOLDS_INT32(&iter)) {
19061911
PHONGO_URI_INVALID_TYPE(iter, "32-bit integer");
19071912
mongoc_write_concern_destroy(new_wc);
19081913

19091914
return false;
19101915
}
19111916

1912-
wtimeout = bson_iter_int32(&iter);
1917+
wtimeout = bson_iter_as_int64(&iter);
19131918

19141919
if (wtimeout < 0) {
1915-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected wtimeoutMS to be >= 0, %d given", wtimeout);
1920+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected wtimeoutMS to be >= 0, %" PRId64 " given", wtimeout);
19161921
mongoc_write_concern_destroy(new_wc);
19171922

19181923
return false;
19191924
}
19201925

1921-
mongoc_write_concern_set_wtimeout(new_wc, wtimeout);
1926+
mongoc_write_concern_set_wtimeout_int64(new_wc, wtimeout);
19221927
}
19231928

19241929
if (bson_iter_init_find_case(&iter, options, MONGOC_URI_JOURNAL)) {
@@ -1956,8 +1961,7 @@ static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t* uri, bson_t* option
19561961
const char* str = bson_iter_utf8(&iter, NULL);
19571962

19581963
if (0 == strcasecmp(PHONGO_WRITE_CONCERN_W_MAJORITY, str)) {
1959-
/* wtimeoutMS is set independently, so preserve its value here */
1960-
mongoc_write_concern_set_wmajority(new_wc, mongoc_write_concern_get_wtimeout(new_wc));
1964+
mongoc_write_concern_set_w(new_wc, MONGOC_WRITE_CONCERN_W_MAJORITY);
19611965
} else {
19621966
mongoc_write_concern_set_wtag(new_wc, str);
19631967
}
@@ -2066,7 +2070,7 @@ static mongoc_ssl_opt_t* php_phongo_make_ssl_opt(mongoc_uri_t* uri, zval* zoptio
20662070
/* If SSL options are set in the URL, we need to read them and set them on
20672071
* the options struct so we can merge potential options from passed in
20682072
* driverOptions (zoptions) */
2069-
if (mongoc_uri_get_ssl(uri)) {
2073+
if (mongoc_uri_get_tls(uri)) {
20702074
php_phongo_mongoc_ssl_opts_from_uri(ssl_opt, uri, &any_ssl_option_set);
20712075
}
20722076

@@ -2557,7 +2561,7 @@ void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string,
25572561
goto cleanup;
25582562
}
25592563
#else
2560-
if (mongoc_uri_get_ssl(uri)) {
2564+
if (mongoc_uri_get_tls(uri)) {
25612565
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Cannot create SSL client. SSL is not enabled in this build.");
25622566
goto cleanup;
25632567
}
@@ -2572,7 +2576,7 @@ void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string,
25722576
}
25732577

25742578
#ifdef MONGOC_ENABLE_SSL
2575-
if (ssl_opt && mongoc_uri_get_ssl(uri)) {
2579+
if (ssl_opt && mongoc_uri_get_tls(uri)) {
25762580
mongoc_client_set_ssl_opts(manager->client, ssl_opt);
25772581
}
25782582
#endif

src/LIBMONGOC_VERSION_CURRENT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.14.0
1+
1.15.0-20190717+gitc88b84ff38

src/MongoDB/WriteConcern.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static bool php_phongo_writeconcern_init_from_hash(php_phongo_writeconcern_t* in
6565
goto failure;
6666
}
6767

68-
mongoc_write_concern_set_wtimeout(intern->write_concern, Z_LVAL_P(wtimeout));
68+
mongoc_write_concern_set_wtimeout_int64(intern->write_concern, (int64_t) Z_LVAL_P(wtimeout));
6969
} else {
7070
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"wtimeout\" field to be integer", ZSTR_VAL(php_phongo_writeconcern_ce->name));
7171
goto failure;
@@ -115,7 +115,7 @@ static bool php_phongo_writeconcern_init_from_hash(php_phongo_writeconcern_t* in
115115
goto failure;
116116
}
117117

118-
mongoc_write_concern_set_wtimeout(intern->write_concern, Z_LVAL_PP(wtimeout));
118+
mongoc_write_concern_set_wtimeout_int64(intern->write_concern, (int64_t) Z_LVAL_PP(wtimeout));
119119
} else {
120120
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"wtimeout\" field to be integer", ZSTR_VAL(php_phongo_writeconcern_ce->name));
121121
goto failure;
@@ -199,7 +199,7 @@ static PHP_METHOD(WriteConcern, __construct)
199199
return;
200200
}
201201

202-
mongoc_write_concern_set_wtimeout(intern->write_concern, wtimeout);
202+
mongoc_write_concern_set_wtimeout_int64(intern->write_concern, (int64_t) wtimeout);
203203
}
204204
} /* }}} */
205205

@@ -265,7 +265,9 @@ static PHP_METHOD(WriteConcern, getWtimeout)
265265
return;
266266
}
267267

268-
RETURN_LONG(mongoc_write_concern_get_wtimeout(intern->write_concern));
268+
/* Note: PHP currently enforces that wimeoutMS is a 32-bit integer, so
269+
* casting will never truncate the value. This may change with PHPC-1411. */
270+
RETURN_LONG((int32_t) mongoc_write_concern_get_wtimeout_int64(intern->write_concern));
269271
} /* }}} */
270272

271273
/* {{{ proto null|boolean MongoDB\Driver\WriteConcern::getJournal()
@@ -321,7 +323,9 @@ static HashTable* php_phongo_write_concern_get_properties_hash(zval* object, boo
321323

322324
wtag = mongoc_write_concern_get_wtag(intern->write_concern);
323325
w = mongoc_write_concern_get_w(intern->write_concern);
324-
wtimeout = mongoc_write_concern_get_wtimeout(intern->write_concern);
326+
/* Note: PHP currently enforces that wimeoutMS is a 32-bit integer, so
327+
* casting will never truncate the value. This may change with PHPC-1411. */
328+
wtimeout = (int32_t) mongoc_write_concern_get_wtimeout_int64(intern->write_concern);
325329

326330
#if PHP_VERSION_ID >= 70000
327331
{

src/libmongoc

Submodule libmongoc updated 272 files

tests/manager/manager-ctor-read_preference-error-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ echo throws(function() {
5656
<?php exit(0); ?>
5757
--EXPECT--
5858
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
59-
Failed to parse MongoDB URI: 'mongodb://127.0.0.1/?readPreference=secondary&maxStalenessSeconds=invalid'. Unsupported value for "maxStalenessSeconds": "invalid".
59+
Failed to parse MongoDB URI: 'mongodb://127.0.0.1/?readPreference=secondary&maxStalenessSeconds=invalid'. Unsupported value for "maxstalenessseconds": "invalid".
6060
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
6161
Expected integer for "maxStalenessSeconds" URI option, string given
6262
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
63-
Failed to parse MongoDB URI: 'mongodb://127.0.0.1/?readPreference=secondary&maxStalenessSeconds=2147483648'. Unsupported value for "maxStalenessSeconds": "2147483648".
63+
Failed to parse MongoDB URI: 'mongodb://127.0.0.1/?readPreference=secondary&maxStalenessSeconds=2147483648'. Unsupported value for "maxstalenessseconds": "2147483648".
6464
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
6565
Failed to parse MongoDB URI: 'mongodb://127.0.0.1/?maxstalenessseconds=1231'. Invalid readPreferences.
6666
OK: Got MongoDB\Driver\Exception\InvalidArgumentException

0 commit comments

Comments
 (0)