@@ -1435,6 +1435,31 @@ static bool php_phongo_uri_finalize_auth(mongoc_uri_t* uri) /* {{{ */
1435
1435
return true;
1436
1436
} /* }}} */
1437
1437
1438
+ static bool php_phongo_uri_finalize_directconnection (mongoc_uri_t * uri ) /* {{{ */
1439
+ {
1440
+ const mongoc_host_list_t * hosts ;
1441
+
1442
+ if (!mongoc_uri_get_option_as_bool (uri , MONGOC_URI_DIRECTCONNECTION , false)) {
1443
+ return true;
1444
+ }
1445
+
1446
+ /* Per the URI options spec, directConnection conflicts with multiple hosts
1447
+ * and SRV URIs, which may resolve to multiple hosts. */
1448
+ if (!strncmp (mongoc_uri_get_string (uri ), "mongodb+srv://" , 14 )) {
1449
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: SRV URI not allowed with directConnection option." );
1450
+ return false;
1451
+ }
1452
+
1453
+ hosts = mongoc_uri_get_hosts (uri );
1454
+
1455
+ if (hosts && hosts -> next ) {
1456
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: Multiple seeds not allowed with directConnection option." );
1457
+ return false;
1458
+ }
1459
+
1460
+ return true;
1461
+ } /* }}} */
1462
+
1438
1463
static bool php_phongo_uri_finalize_tls (mongoc_uri_t * uri ) /* {{{ */
1439
1464
{
1440
1465
const bson_t * options ;
@@ -1676,12 +1701,17 @@ static bool php_phongo_apply_options_to_uri(mongoc_uri_t* uri, bson_t* options)
1676
1701
}
1677
1702
}
1678
1703
1679
- // Finalize auth options
1704
+ /* Validate any interactions between URI options */
1680
1705
if (!php_phongo_uri_finalize_auth (uri )) {
1681
1706
/* Exception should already have been thrown */
1682
1707
return false;
1683
1708
}
1684
1709
1710
+ if (!php_phongo_uri_finalize_directconnection (uri )) {
1711
+ /* Exception should already have been thrown */
1712
+ return false;
1713
+ }
1714
+
1685
1715
return true;
1686
1716
} /* }}} */
1687
1717
@@ -2502,7 +2532,7 @@ static bool php_phongo_extract_handshake_data(zval* driver, const char* key, cha
2502
2532
zval * zvalue ;
2503
2533
2504
2534
if (!php_array_exists (driver , key )) {
2505
- * value = NULL ;
2535
+ * value = NULL ;
2506
2536
* value_len = 0 ;
2507
2537
2508
2538
return true;
@@ -2523,7 +2553,7 @@ static bool php_phongo_extract_handshake_data(zval* driver, const char* key, cha
2523
2553
2524
2554
static char * php_phongo_concat_handshake_data (const char * default_value , const char * custom_value , size_t custom_value_len )
2525
2555
{
2526
- char * ret ;
2556
+ char * ret ;
2527
2557
/* Length of the returned value needs to include the trailing null byte */
2528
2558
size_t ret_len = strlen (default_value ) + 1 ;
2529
2559
@@ -2552,7 +2582,7 @@ static void php_phongo_handshake_data_append(const char* name, size_t name_len,
2552
2582
char * full_platform ;
2553
2583
2554
2584
php_version_string_len = strlen (PHP_VERSION );
2555
- php_version_string = ecalloc (sizeof (char * ), 4 + php_version_string_len );
2585
+ php_version_string = ecalloc (sizeof (char * ), 4 + php_version_string_len );
2556
2586
snprintf (php_version_string , 4 + php_version_string_len , "PHP %s" , PHP_VERSION );
2557
2587
2558
2588
driver_name = php_phongo_concat_handshake_data ("ext-mongodb:PHP" , name , name_len );
@@ -2583,7 +2613,7 @@ static void php_phongo_set_handshake_data(zval* driverOptions)
2583
2613
size_t platform_len = 0 ;
2584
2614
2585
2615
if (driverOptions && php_array_existsc (driverOptions , "driver" )) {
2586
- zval * driver = php_array_fetchc (driverOptions , "driver" );
2616
+ zval * driver = php_array_fetchc (driverOptions , "driver" );
2587
2617
2588
2618
if (Z_TYPE_P (driver ) != IS_ARRAY ) {
2589
2619
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected \"driver\" driver option to be an array, %s given" , PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P (driver ));
@@ -3489,7 +3519,7 @@ static zend_class_entry* php_phongo_fetch_internal_class(const char* class_name,
3489
3519
static HashTable * php_phongo_std_get_gc (zval * object , zval * * table , int * n ) /* {{{ */
3490
3520
{
3491
3521
* table = NULL ;
3492
- * n = 0 ;
3522
+ * n = 0 ;
3493
3523
return zend_std_get_properties (object );
3494
3524
} /* }}} */
3495
3525
0 commit comments