Skip to content

Commit 9d3b99e

Browse files
committed
Merged pull request #672
2 parents 8c85f0b + 3a413de commit 9d3b99e

17 files changed

+107
-189
lines changed

config.m4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ if test "$MONGODB" != "no"; then
127127
PHP_CHECK_GCC_ARG(-Wempty-body, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wempty-body")
128128
PHP_CHECK_GCC_ARG(-Wparentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wparentheses")
129129
PHP_CHECK_GCC_ARG(-Wdeclaration-after-statement, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdeclaration-after-statement")
130+
PHP_CHECK_GCC_ARG(-Wmaybe-uninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmaybe-uninitialized")
130131
PHP_CHECK_GCC_ARG(-Werror, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Werror")
131132
PHP_CHECK_GCC_ARG(-Wextra, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wextra")
132133
PHP_CHECK_GCC_ARG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter")
@@ -280,7 +281,7 @@ if test "$MONGODB" != "no"; then
280281
PHP_MONGODB_MONGOC_CFLAGS="$STD_CFLAGS -DMONGOC_COMPILATION -DMONGOC_TRACE"
281282

282283
dnl Generated with: find src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 5- | sort -z | tr '\000' ' '
283-
PHP_MONGODB_MONGOC_SOURCES="mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-b64.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-client.c mongoc-client-pool.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-gssapi.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-cursorid.c mongoc-cursor-transform.c mongoc-cyrus.c mongoc-database.c mongoc-find-and-modify.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-gssapi.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-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-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-concern.c"
284+
PHP_MONGODB_MONGOC_SOURCES="mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-b64.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-gssapi.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-cursorid.c mongoc-cursor-transform.c mongoc-cyrus.c mongoc-database.c mongoc-find-and-modify.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-gssapi.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-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-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"
284285

285286
PHP_ADD_SOURCES_X(PHP_EXT_DIR(mongodb)[src/libmongoc/src/mongoc], $PHP_MONGODB_MONGOC_SOURCES, $PHP_MONGODB_MONGOC_CFLAGS, shared_objects_mongodb, yes)
286287

@@ -296,7 +297,7 @@ if test "$MONGODB" != "no"; then
296297
AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 1)
297298
AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 1)
298299
299-
AC_CHECK_DECLS([ASN1_STRING_get0_data], [AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 1)], [AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 1)], [[#include <openssl/asn1.h>]])
300+
AC_CHECK_DECLS([ASN1_STRING_get0_data], [AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 1)], [AC_SUBST(MONGOC_HAVE_ASN1_STRING_GET0_DATA, 0)], [[#include <openssl/asn1.h>]])
300301
])
301302

302303
if test "$PHP_SYSTEM_CIPHERS" != "no"; then
@@ -374,6 +375,7 @@ if test "$MONGODB" != "no"; then
374375

375376
m4_include(src/libmongoc/build/autotools/m4/ax_prototype.m4)
376377
m4_include(src/libmongoc/build/autotools/CheckCompiler.m4)
378+
m4_include(src/libmongoc/build/autotools/FindResSearch.m4)
377379
m4_include(src/libmongoc/build/autotools/WeakSymbols.m4)
378380
m4_include(src/libmongoc/build/autotools/m4/ax_pthread.m4)
379381
AX_PTHREAD

config.w32

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

8282
// Generated with: find src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 4- | sort -z | tr '\000' ' '
83-
var PHP_MONGODB_MONGOC_SOURCES="mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-b64.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-client.c mongoc-client-pool.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-gssapi.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-cursorid.c mongoc-cursor-transform.c mongoc-cyrus.c mongoc-database.c mongoc-find-and-modify.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-gssapi.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-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-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-concern.c";
83+
var PHP_MONGODB_MONGOC_SOURCES="mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-b64.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-gssapi.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-cursorid.c mongoc-cursor-transform.c mongoc-cyrus.c mongoc-database.c mongoc-find-and-modify.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-gssapi.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-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-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";
8484

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

php_phongo.c

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -590,48 +590,84 @@ int phongo_execute_query(mongoc_client_t *client, const char *namespace, zval *z
590590
return true;
591591
} /* }}} */
592592

593+
static bson_t *create_wrapped_command_envelope(const char *db, bson_t *reply)
594+
{
595+
bson_t *tmp;
596+
size_t max_ns_len = strlen(db) + 5 + 1; /* db + ".$cmd" + '\0' */
597+
char *ns = emalloc(max_ns_len);
598+
599+
snprintf(ns, max_ns_len, "%s.$cmd", db);
600+
tmp = BCON_NEW("cursor", "{", "id", BCON_INT64(0), "ns", BCON_UTF8(ns), "firstBatch", "[", BCON_DOCUMENT(reply), "]", "}");
601+
efree(ns);
602+
603+
return tmp;
604+
}
605+
593606
int phongo_execute_command(mongoc_client_t *client, const char *db, zval *zcommand, zval *zreadPreference, int server_id, zval *return_value, int return_value_used TSRMLS_DC) /* {{{ */
594607
{
595608
const php_phongo_command_t *command;
596-
mongoc_cursor_t *cursor;
597609
bson_iter_t iter;
610+
bson_t reply;
611+
bson_error_t error;
612+
bson_t *opts;
613+
mongoc_cursor_t *cmd_cursor;
614+
uint32_t selected_server_id;
598615

599616
command = Z_COMMAND_OBJ_P(zcommand);
600617

601-
cursor = mongoc_client_command(client, db, MONGOC_QUERY_NONE, 0, 1, 0, command->bson, NULL, phongo_read_preference_from_zval(zreadPreference TSRMLS_CC));
618+
opts = bson_new();
619+
if (server_id > 0) {
620+
bson_append_int32(opts, "serverId", -1, server_id);
621+
selected_server_id = server_id;
622+
} else {
623+
mongoc_server_description_t *selected_server = NULL;
602624

603-
if (server_id > 0 && !mongoc_cursor_set_hint(cursor, server_id)) {
604-
phongo_throw_exception(PHONGO_ERROR_MONGOC_FAILED TSRMLS_CC, "%s", "Could not set cursor server_id");
605-
return false;
625+
selected_server = mongoc_client_select_server(client, false, (zreadPreference ? phongo_read_preference_from_zval(zreadPreference TSRMLS_CC) : mongoc_client_get_read_prefs(client)), &error);
626+
if (selected_server) {
627+
selected_server_id = mongoc_server_description_id(selected_server);
628+
bson_append_int32(opts, "serverId", -1, selected_server_id);
629+
mongoc_server_description_destroy(selected_server);
630+
} else {
631+
/* Check for connection related exceptions */
632+
if (!EG(exception)) {
633+
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
634+
}
635+
636+
bson_free(opts);
637+
return false;
638+
}
606639
}
607640

608-
if (!phongo_advance_cursor_and_check_for_error(cursor TSRMLS_CC)) {
641+
if (!mongoc_client_command_with_opts(client, db, command->bson, phongo_read_preference_from_zval(zreadPreference TSRMLS_CC), opts, &reply, &error)) {
642+
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
643+
bson_free(opts);
609644
return false;
610645
}
611646

647+
bson_free(opts);
648+
612649
if (!return_value_used) {
613-
mongoc_cursor_destroy(cursor);
650+
bson_destroy(&reply);
614651
return true;
615652
}
616653

617-
if (bson_iter_init_find(&iter, mongoc_cursor_current(cursor), "cursor") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
618-
mongoc_cursor_t *cmd_cursor;
619-
620-
/* According to mongoc_cursor_new_from_command_reply(), the reply bson_t
621-
* is ultimately destroyed on both success and failure. Use bson_copy()
622-
* to create a writable copy of the const bson_t we fetched above. */
623-
cmd_cursor = mongoc_cursor_new_from_command_reply(client, bson_copy(mongoc_cursor_current(cursor)), mongoc_cursor_get_hint(cursor));
624-
mongoc_cursor_destroy(cursor);
654+
/* According to mongoc_cursor_new_from_command_reply(), the reply bson_t
655+
* is ultimately destroyed on both success and failure. */
656+
if (bson_iter_init_find(&iter, &reply, "cursor") && BSON_ITER_HOLDS_DOCUMENT(&iter)) {
657+
cmd_cursor = mongoc_cursor_new_from_command_reply(client, &reply, selected_server_id);
658+
} else {
659+
bson_t *wrapped_reply = create_wrapped_command_envelope(db, &reply);
625660

626-
if (!phongo_advance_cursor_and_check_for_error(cmd_cursor TSRMLS_CC)) {
627-
return false;
628-
}
661+
cmd_cursor = mongoc_cursor_new_from_command_reply(client, wrapped_reply, selected_server_id);
662+
bson_destroy(&reply);
663+
}
629664

630-
phongo_cursor_init_for_command(return_value, client, cmd_cursor, db, zcommand, zreadPreference TSRMLS_CC);
631-
return true;
665+
if (!phongo_advance_cursor_and_check_for_error(cmd_cursor TSRMLS_CC)) {
666+
mongoc_cursor_destroy(cmd_cursor);
667+
return false;
632668
}
633669

634-
phongo_cursor_init_for_command(return_value, client, cursor, db, zcommand, zreadPreference TSRMLS_CC);
670+
phongo_cursor_init_for_command(return_value, client, cmd_cursor, db, zcommand, zreadPreference TSRMLS_CC);
635671
return true;
636672
} /* }}} */
637673

@@ -1116,6 +1152,32 @@ static bool php_phongo_apply_options_to_uri(mongoc_uri_t *uri, bson_t *options T
11161152

11171153
continue;
11181154
}
1155+
1156+
if (!strcasecmp(key, MONGOC_URI_GSSAPISERVICENAME)) {
1157+
bson_t unused, properties = BSON_INITIALIZER;
1158+
1159+
if (mongoc_uri_get_mechanism_properties(uri, &unused)) {
1160+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "authMechanismProperties SERVICE_NAME already set, ignoring \"%s\"", key);
1161+
return false;
1162+
}
1163+
1164+
if (!BSON_ITER_HOLDS_UTF8(&iter)) {
1165+
PHONGO_URI_INVALID_TYPE(iter, "string");
1166+
return false;
1167+
}
1168+
1169+
bson_append_utf8(&properties, "SERVICE_NAME", -1, bson_iter_utf8(&iter, NULL), -1);
1170+
1171+
if (!mongoc_uri_set_mechanism_properties(uri, &properties)) {
1172+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Failed to parse \"%s\" URI option", key);
1173+
bson_destroy(&properties);
1174+
return false;
1175+
}
1176+
1177+
bson_destroy(&properties);
1178+
1179+
continue;
1180+
}
11191181
}
11201182

11211183
return true;

src/libmongoc

Submodule libmongoc updated 399 files

tests/apm/overview.phpt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object(MongoDB\Driver\Monitoring\CommandStartedEvent)#%d (%d) {
4848
["command"]=>
4949
object(stdClass)#%d (%d) {
5050
["drop"]=>
51-
string(12) "apm_overview"
51+
string(12) "apm_overview"%A
5252
}
5353
["commandName"]=>
5454
string(4) "drop"
@@ -105,20 +105,7 @@ object(MongoDB\Driver\Monitoring\CommandStartedEvent)#%d (%d) {
105105
object(stdClass)#%d (%d) {
106106
}
107107
["ordered"]=>
108-
bool(false)
109-
["documents"]=>
110-
array(%d) {
111-
[0]=>
112-
object(stdClass)#%d (%d) {
113-
["decimal"]=>
114-
int(12345678)
115-
["_id"]=>
116-
object(MongoDB\BSON\ObjectId)#%d (%d) {
117-
["oid"]=>
118-
string(24) "%s"
119-
}
120-
}
121-
}
108+
bool(false)%A
122109
}
123110
["commandName"]=>
124111
string(6) "insert"
@@ -160,7 +147,7 @@ object(MongoDB\Driver\Monitoring\CommandStartedEvent)#%d (%d) {
160147
string(12) "apm_overview"
161148
["filter"]=>
162149
object(stdClass)#%d (%d) {
163-
}
150+
}%A
164151
}
165152
["commandName"]=>
166153
string(4) "find"

tests/bulk/bulkwrite-insert-002.phpt

Lines changed: 0 additions & 47 deletions
This file was deleted.

tests/bulk/bulkwrite-insert-003.phpt

Lines changed: 0 additions & 56 deletions
This file was deleted.

tests/bulk/bulkwrite-insert_error-004.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ echo throws(function() use ($bulk) {
2222
?>
2323
===DONE===
2424
<?php exit(0); ?>
25-
--EXPECT--
25+
--EXPECTF--
2626
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
27-
legacy index document contains invalid key: empty key
27+
%s contains invalid key: empty key
2828

2929
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
30-
legacy index document contains invalid key: keys cannot begin with "$": "$x"
30+
%s contains invalid key: keys cannot begin with "$": "$x"
3131

3232
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
33-
legacy index document contains invalid key: corrupt BSON
33+
%s contains invalid key: corrupt BSON
3434
===DONE===

tests/cursor/cursor-destruct-001.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function getNumOpenCursors(MongoDB\Driver\Manager $manager)
1111
{
1212
$cursor = $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(array('serverStatus' => 1)));
1313
$result = current($cursor->toArray());
14-
1514
if (isset($result->metrics->cursor->open->total)) {
1615
return $result->metrics->cursor->open->total;
1716
}

0 commit comments

Comments
 (0)