@@ -1281,6 +1281,7 @@ static bool php_phongo_apply_wc_options_to_uri(mongoc_uri_t *uri, bson_t *option
1281
1281
return true;
1282
1282
} /* }}} */
1283
1283
1284
+ #ifdef MONGOC_ENABLE_SSL
1284
1285
static inline char * php_phongo_fetch_ssl_opt_string (zval * zoptions , const char * key , int key_len )
1285
1286
{
1286
1287
int plen ;
@@ -1389,6 +1390,7 @@ static void php_phongo_free_ssl_opt(mongoc_ssl_opt_t *ssl_opt)
1389
1390
1390
1391
efree (ssl_opt );
1391
1392
}
1393
+ #endif
1392
1394
1393
1395
/* Creates a hash for a client by concatenating the URI string with serialized
1394
1396
* 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
1470
1472
return hash ;
1471
1473
}
1472
1474
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 ) /* {{{ */
1474
1476
{
1475
- const char * mongoc_version , * bson_version ;
1476
- mongoc_client_t * client ;
1477
+ const char * mongoc_version , * bson_version ;
1477
1478
1478
1479
#ifdef HAVE_SYSTEM_LIBMONGOC
1479
1480
mongoc_version = mongoc_get_version ();
@@ -1496,17 +1497,8 @@ static mongoc_client_t *php_phongo_make_mongo_client(const mongoc_uri_t *uri, mo
1496
1497
bson_version ,
1497
1498
PHP_VERSION
1498
1499
);
1499
- client = mongoc_client_new_from_uri (uri );
1500
-
1501
- if (!client ) {
1502
- return NULL ;
1503
- }
1504
1500
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 );
1510
1502
} /* }}} */
1511
1503
1512
1504
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,
1548
1540
size_t hash_len = 0 ;
1549
1541
bson_t bson_options = BSON_INITIALIZER ;
1550
1542
mongoc_uri_t * uri = NULL ;
1551
- mongoc_ssl_opt_t * ssl_opt = NULL ;
1552
1543
bson_iter_t iter ;
1544
+ #ifdef MONGOC_ENABLE_SSL
1545
+ mongoc_ssl_opt_t * ssl_opt = NULL ;
1546
+ #endif
1553
1547
1554
1548
if (!(hash = php_phongo_manager_make_client_hash (uri_string , options , driverOptions , & hash_len TSRMLS_CC ))) {
1555
1549
/* 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,
1591
1585
}
1592
1586
}
1593
1587
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. */
1594
1591
ssl_opt = php_phongo_make_ssl_opt (driverOptions TSRMLS_CC );
1595
1592
1596
1593
/* An exception may be thrown during SSL option creation */
1597
1594
if (EG (exception )) {
1598
1595
goto cleanup ;
1599
1596
}
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
1600
1603
1601
- manager -> client = php_phongo_make_mongo_client (uri , ssl_opt TSRMLS_CC );
1604
+ manager -> client = php_phongo_make_mongo_client (uri TSRMLS_CC );
1602
1605
1603
1606
if (!manager -> client ) {
1604
1607
phongo_throw_exception (PHONGO_ERROR_RUNTIME TSRMLS_CC , "Failed to create Manager from URI: '%s'" , uri_string );
1605
1608
goto cleanup ;
1606
1609
}
1607
1610
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
+
1608
1617
MONGOC_DEBUG ("Created client hash: %s\n" , hash );
1609
1618
php_phongo_persist_client (hash , hash_len , manager -> client TSRMLS_CC );
1610
1619
@@ -1619,9 +1628,11 @@ void phongo_manager_init(php_phongo_manager_t *manager, const char *uri_string,
1619
1628
mongoc_uri_destroy (uri );
1620
1629
}
1621
1630
1631
+ #ifdef MONGOC_ENABLE_SSL
1622
1632
if (ssl_opt ) {
1623
1633
php_phongo_free_ssl_opt (ssl_opt );
1624
1634
}
1635
+ #endif
1625
1636
} /* }}} */
1626
1637
1627
1638
void php_phongo_new_utcdatetime_from_epoch (zval * object , int64_t msec_since_epoch TSRMLS_DC ) /* {{{ */
0 commit comments