Skip to content

Commit 0e06719

Browse files
committed
Merge pull request #650
2 parents e15b54e + b840547 commit 0e06719

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

config.m4

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,17 @@ if test "$MONGODB" != "no"; then
267267

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

270-
PHP_SETUP_OPENSSL(MONGODB_SHARED_LIBADD)
271-
AC_SUBST(MONGOC_ENABLE_CRYPTO, 1)
272-
AC_SUBST(MONGOC_ENABLE_SSL, 1)
273-
AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 1)
274-
AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 1)
270+
AC_SUBST(MONGOC_ENABLE_CRYPTO, 0)
271+
AC_SUBST(MONGOC_ENABLE_SSL, 0)
272+
AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 0)
273+
AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 0)
274+
275+
PHP_SETUP_OPENSSL(MONGODB_SHARED_LIBADD, [
276+
AC_SUBST(MONGOC_ENABLE_CRYPTO, 1)
277+
AC_SUBST(MONGOC_ENABLE_SSL, 1)
278+
AC_SUBST(MONGOC_ENABLE_CRYPTO_LIBCRYPTO, 1)
279+
AC_SUBST(MONGOC_ENABLE_SSL_OPENSSL, 1)
280+
])
275281

276282
if test "$PHP_SYSTEM_CIPHERS" != "no"; then
277283
AC_SUBST(MONGOC_ENABLE_CRYPTO_SYSTEM_PROFILE, 1)

php_phongo.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,7 @@ static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t *uri, bson_t *option
12811281
return true;
12821282
} /* }}} */
12831283

1284+
#ifdef MONGOC_ENABLE_SSL
12841285
static inline char *php_phongo_fetch_ssl_opt_string(zval *zoptions, const char *key, int key_len)
12851286
{
12861287
int plen;
@@ -1389,6 +1390,7 @@ static void php_phongo_free_ssl_opt(mongoc_ssl_opt_t *ssl_opt)
13891390

13901391
efree(ssl_opt);
13911392
}
1393+
#endif
13921394

13931395
/* Creates a hash for a client by concatenating the URI string with serialized
13941396
* options arrays. On success, a persistent string is returned (i.e. pefree()
@@ -1470,10 +1472,9 @@ static char *php_phongo_manager_make_client_hash(const char *uri_string, zval *o
14701472
return hash;
14711473
}
14721474

1473-
static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, mongoc_ssl_opt_t *ssl_opt TSRMLS_DC) /* {{{ */
1475+
static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri TSRMLS_DC) /* {{{ */
14741476
{
1475-
const char *mongoc_version, *bson_version;
1476-
mongoc_client_t *client;
1477+
const char *mongoc_version, *bson_version;
14771478

14781479
#ifdef HAVE_SYSTEM_LIBMONGOC
14791480
mongoc_version = mongoc_get_version();
@@ -1496,17 +1497,8 @@ static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, mo
14961497
bson_version,
14971498
PHP_VERSION
14981499
);
1499-
client = mongoc_client_new_from_uri(uri);
1500-
1501-
if (!client) {
1502-
return NULL;
1503-
}
15041500

1505-
if (mongoc_uri_get_ssl(uri) && ssl_opt) {
1506-
mongoc_client_set_ssl_opts(client, ssl_opt);
1507-
}
1508-
1509-
return client;
1501+
return mongoc_client_new_from_uri(uri);
15101502
} /* }}} */
15111503

15121504
static void php_phongo_persist_client(const char *hash, size_t hash_len, mongoc_client_t *client TSRMLS_DC)
@@ -1548,8 +1540,10 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
15481540
size_t hash_len = 0;
15491541
bson_t bson_options = BSON_INITIALIZER;
15501542
mongoc_uri_t *uri = NULL;
1551-
mongoc_ssl_opt_t *ssl_opt = NULL;
15521543
bson_iter_t iter;
1544+
#ifdef MONGOC_ENABLE_SSL
1545+
mongoc_ssl_opt_t *ssl_opt = NULL;
1546+
#endif
15531547

15541548
if (!(hash = php_phongo_manager_make_client_hash(uri_string, options, driverOptions, &hash_len TSRMLS_CC))) {
15551549
/* Exception should already have been thrown and there is nothing to free */
@@ -1591,20 +1585,35 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
15911585
}
15921586
}
15931587

1588+
#ifdef MONGOC_ENABLE_SSL
1589+
/* Construct SSL options even if SSL is not enabled so that exceptions can
1590+
* be thrown for unsupported driver options. */
15941591
ssl_opt = php_phongo_make_ssl_opt(driverOptions TSRMLS_CC);
15951592

15961593
/* An exception may be thrown during SSL option creation */
15971594
if (EG(exception)) {
15981595
goto cleanup;
15991596
}
1597+
#else
1598+
if (mongoc_uri_get_ssl(uri)) {
1599+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Cannot create SSL client. SSL is not enabled in this build.");
1600+
goto cleanup;
1601+
}
1602+
#endif
16001603

1601-
manager->client = php_phongo_make_mongo_client(uri, ssl_opt TSRMLS_CC);
1604+
manager->client = php_phongo_make_mongo_client(uri TSRMLS_CC);
16021605

16031606
if (!manager->client) {
16041607
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "Failed to create Manager from URI: '%s'", uri_string);
16051608
goto cleanup;
16061609
}
16071610

1611+
#ifdef MONGOC_ENABLE_SSL
1612+
if (ssl_opt && mongoc_uri_get_ssl(uri)) {
1613+
mongoc_client_set_ssl_opts(manager->client, ssl_opt);
1614+
}
1615+
#endif
1616+
16081617
MONGOC_DEBUG("Created client hash: %s\n", hash);
16091618
php_phongo_persist_client(hash, hash_len, manager->client TSRMLS_CC);
16101619

@@ -1619,9 +1628,11 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
16191628
mongoc_uri_destroy(uri);
16201629
}
16211630

1631+
#ifdef MONGOC_ENABLE_SSL
16221632
if (ssl_opt) {
16231633
php_phongo_free_ssl_opt(ssl_opt);
16241634
}
1635+
#endif
16251636
} /* }}} */
16261637

16271638
void php_phongo_new_utcdatetime_from_epoch(zval *object, int64_t msec_since_epoch TSRMLS_DC) /* {{{ */

0 commit comments

Comments
 (0)