diff --git a/config.m4 b/config.m4 index d590a05db..f8e4611dc 100644 --- a/config.m4 +++ b/config.m4 @@ -241,6 +241,7 @@ if test "$MONGODB" != "no"; then mongoc-cursor-cursorid.c \ mongoc-cursor-transform.c \ mongoc-database.c \ + mongoc-linux-distro-scanner.c \ mongoc-find-and-modify.c \ mongoc-host-list.c \ mongoc-init.c \ @@ -248,6 +249,7 @@ if test "$MONGODB" != "no"; then mongoc-gridfs-file.c \ mongoc-gridfs-file-page.c \ mongoc-gridfs-file-list.c \ + mongoc-handshake.c \ mongoc-index.c \ mongoc-list.c \ mongoc-log.c \ @@ -414,6 +416,8 @@ PHP_ARG_WITH(libmongoc, whether to use system libmongoc, AC_SUBST(MONGOC_ENABLE_SSL_SECURE_CHANNEL, 0) AC_SUBST(MONGOC_ENABLE_CRYPTO_CNG, 0) + AC_SUBST(MONGOC_ENABLE_SSL_LIBRESSL, 0) + AC_SUBST(MONGOC_NO_AUTOMATIC_GLOBALS, 1) AC_SUBST(MONGOC_EXPERIMENTAL_FEATURES, 0) fi diff --git a/php_phongo.c b/php_phongo.c index 9793b2d9d..cbc263d2c 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -1004,7 +1004,9 @@ static mongoc_uri_t *php_phongo_make_uri(const char *uri_string, bson_t *options !strcasecmp(key, "safe") || !strcasecmp(key, "slaveok") || !strcasecmp(key, "w") || - !strcasecmp(key, "wtimeoutms")) { + !strcasecmp(key, "wtimeoutms") || + !strcasecmp(key, "maxstalenessms") + ) { continue; } @@ -1090,7 +1092,9 @@ static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *option if (!bson_iter_init_find_case(&iter, options, "slaveok") && !bson_iter_init_find_case(&iter, options, "readpreference") && - !bson_iter_init_find_case(&iter, options, "readpreferencetags")) { + !bson_iter_init_find_case(&iter, options, "readpreferencetags") && + !bson_iter_init_find_case(&iter, options, "maxstalenessms") + ) { return true; } @@ -1141,6 +1145,19 @@ static bool php_phongo_apply_rp_options_to_uri(mongoc_uri_t *uri, bson_t *option return false; } + /* Handle maxStalenessMS, and make sure it is not combined with primary + * readPreference */ + if (bson_iter_init_find_case(&iter, options, "maxstalenessms") && BSON_ITER_HOLDS_INT32(&iter)) { + if (mongoc_read_prefs_get_mode(new_rp) == MONGOC_READ_PRIMARY) { + phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Primary read preference mode conflicts with maxStalenessMS"); + mongoc_read_prefs_destroy(new_rp); + + return false; + } + + mongoc_read_prefs_set_max_staleness_ms(new_rp, bson_iter_int32(&iter)); + } + /* This may be redundant in light of the last check (primary with tags), but * we'll check anyway in case additional validation is implemented. */ if (!mongoc_read_prefs_is_valid(new_rp)) { @@ -1390,8 +1407,6 @@ static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, zv const char *mongoc_version, *bson_version; mongoc_client_t *client; - ENTRY; - #if PHP_VERSION_ID >= 70000 if (driverOptions && (zdebug = zend_hash_str_find(Z_ARRVAL_P(driverOptions), "debug", sizeof("debug")-1)) != NULL) { zend_string *key = zend_string_init(PHONGO_DEBUG_INI, sizeof(PHONGO_DEBUG_INI)-1, 0); @@ -1432,17 +1447,17 @@ static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, zv client = mongoc_client_new_from_uri(uri); if (!client) { - RETURN(NULL); + return NULL; } if (mongoc_uri_get_ssl(uri) && driverOptions) { if (!php_phongo_apply_ssl_opts(client, driverOptions TSRMLS_CC)) { mongoc_client_destroy(client); - RETURN(NULL); + return NULL; } } - RETURN(client); + return client; } /* }}} */ bool phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string, bson_t *bson_options, zval *driverOptions TSRMLS_DC) /* {{{ */ @@ -1880,11 +1895,17 @@ PHP_MINIT_FUNCTION(mongodb) { (void)type; /* We don't care if we are loaded via dl() or extension= */ + char *php_version_string = malloc(4 + sizeof(MONGODB_VERSION_S) + 1); REGISTER_INI_ENTRIES(); /* Initialize libmongoc */ mongoc_init(); + + /* Set handshake options */ + snprintf(php_version_string, 4 + sizeof(MONGODB_VERSION_S) + 1, "PHP %s", PHP_VERSION); + mongoc_handshake_data_append("ext-mongodb:PHP", MONGODB_VERSION_S, php_version_string); + /* Initialize libbson */ bson_mem_set_vtable(&MONGODB_G(bsonMemVTable)); diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 2ec227d69..f723d051d 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -201,6 +201,7 @@ PHP_MINIT_FUNCTION(ReadConcern) zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LOCAL"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LOCAL) TSRMLS_CC); zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("MAJORITY"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_MAJORITY) TSRMLS_CC); + zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LINEARIZABLE"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LINEARIZABLE) TSRMLS_CC); return SUCCESS; } diff --git a/src/libbson b/src/libbson index 1a8b6acd0..3d92097aa 160000 --- a/src/libbson +++ b/src/libbson @@ -1 +1 @@ -Subproject commit 1a8b6acd0bee74dd04c352adec90286f109693a5 +Subproject commit 3d92097aa46e297a77b68fe3d20b96ef98c959df diff --git a/src/libmongoc b/src/libmongoc index ad14cc362..0bb66a196 160000 --- a/src/libmongoc +++ b/src/libmongoc @@ -1 +1 @@ -Subproject commit ad14cc362e8ff898b63fbe8b80c7d15f26df7f08 +Subproject commit 0bb66a19629e52c061f1d63f72298e396eca8466 diff --git a/tests/bson/bug0544.phpt b/tests/bson/bug0544.phpt index 440484c65..a2d1d47b4 100644 --- a/tests/bson/bug0544.phpt +++ b/tests/bson/bug0544.phpt @@ -2,8 +2,6 @@ PHPC-544: Consult SIZEOF_ZEND_LONG for 64-bit integer support --SKIPIF-- ---INI-- -mongodb.debug=stderr --FILE-- ---INI-- -mongodb.debug=stderr --FILE-- - ---INI-- -mongodb.debug=stdout ---FILE-- -insert(array('_id' => 1, 'x' => 1)); -$result = $manager->executeBulkWrite(NS, $bulk); - -ini_set("mongodb.debug", "off"); -?> -===DONE=== - ---EXPECTF-- -%a -[%s] PHONGO: TRACE > ENTRY: php_phongo_make_mongo_client():%d -[%s] PHONGO: DEBUG > Creating Manager, phongo-1.%d.%d%S[%s] - mongoc-1.%s(%s), libbson-1.%s(%s), php-%s -%a -===DONE=== diff --git a/tests/manager/manager-maxstalenessms-001.phpt b/tests/manager/manager-maxstalenessms-001.phpt new file mode 100644 index 000000000..4e3ab24eb --- /dev/null +++ b/tests/manager/manager-maxstalenessms-001.phpt @@ -0,0 +1,13 @@ +--TEST-- +MongoDB\Driver\Manager: maxStalenessMS +--FILE-- + 1231 ] ); +$manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY&maxstalenessms=1231"); +$manager = new MongoDB\Driver\Manager("mongodb://localhost/?readPreference=SECONDARY", [ 'maxstalenessms' => 1231 ] ); +?> +==DONE== +--EXPECTF-- +==DONE== diff --git a/tests/manager/manager-maxstalenessms_error-001.phpt b/tests/manager/manager-maxstalenessms_error-001.phpt new file mode 100644 index 000000000..d6fafb5ef --- /dev/null +++ b/tests/manager/manager-maxstalenessms_error-001.phpt @@ -0,0 +1,33 @@ +--TEST-- +MongoDB\Driver\Manager: maxStalenessMS +--FILE-- +getMessage(), "\n"; +} + +try { + $manager = new MongoDB\Driver\Manager("mongodb://localhost/?maxStalenessMS=1231"); +} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) { + echo $e->getMessage(), "\n"; +} + +try { + $manager = new MongoDB\Driver\Manager("mongodb://localhost/", [ 'maxstalenessms' => 1231 ] ); +} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) { + echo $e->getMessage(), "\n"; +} + +try { + $manager = new MongoDB\Driver\Manager("mongodb://localhost/", [ 'maxStalenessMS' => 1231 ] ); +} catch ( MongoDB\Driver\Exception\InvalidArgumentException $e ) { + echo $e->getMessage(), "\n"; +} +?> +--EXPECTF-- +Failed to parse MongoDB URI: 'mongodb://localhost/?maxstalenessms=1231' +Failed to parse MongoDB URI: 'mongodb://localhost/?maxStalenessMS=1231' +Primary read preference mode conflicts with maxStalenessMS +Primary read preference mode conflicts with maxStalenessMS diff --git a/tests/manager/manager-var-dump-001.phpt b/tests/manager/manager-var-dump-001.phpt index 1719bd62b..20032cc89 100644 --- a/tests/manager/manager-var-dump-001.phpt +++ b/tests/manager/manager-var-dump-001.phpt @@ -50,7 +50,7 @@ object(MongoDB\Driver\Manager)#%d (%d) { ["is_passive"]=> bool(false) ["last_is_master"]=> - array(8) { + array(%d) { ["ismaster"]=> bool(true) ["maxBsonObjectSize"]=> @@ -68,6 +68,7 @@ object(MongoDB\Driver\Manager)#%d (%d) { int(%d) ["minWireVersion"]=> int(0) + %a ["ok"]=> float(1) } diff --git a/tests/server/server-debug.phpt b/tests/server/server-debug.phpt index 03ebe351e..843bf0520 100644 --- a/tests/server/server-debug.phpt +++ b/tests/server/server-debug.phpt @@ -33,7 +33,7 @@ object(MongoDB\Driver\Server)#%d (%d) { ["is_passive"]=> bool(false) ["last_is_master"]=> - array(8) { + array(%d) { ["ismaster"]=> bool(true) ["maxBsonObjectSize"]=> @@ -51,6 +51,7 @@ object(MongoDB\Driver\Server)#%d (%d) { int(%d) ["minWireVersion"]=> int(0) + %a ["ok"]=> float(1) }