@@ -1435,126 +1435,6 @@ static const char* php_phongo_bson_type_to_string(bson_type_t type) /* {{{ */
1435
1435
bson_iter_key(&(iter)), \
1436
1436
php_phongo_bson_type_to_string(bson_iter_type(&(iter))))
1437
1437
1438
- static bool php_phongo_uri_finalize_auth (mongoc_uri_t * uri ) /* {{{ */
1439
- {
1440
- const bson_t * credentials = mongoc_uri_get_credentials (uri );
1441
- bson_iter_t iter ;
1442
- const char * source = NULL ;
1443
- const char * username = mongoc_uri_get_username (uri );
1444
- bool require_auth = username != NULL ;
1445
-
1446
- if (bson_iter_init_find_case (& iter , credentials , MONGOC_URI_AUTHSOURCE )) {
1447
- source = bson_iter_utf8 (& iter , NULL );
1448
- require_auth = true;
1449
- }
1450
-
1451
- /* authSource with GSSAPI or X509 should always be external */
1452
- if (mongoc_uri_get_auth_mechanism (uri )) {
1453
- if (!strcasecmp (mongoc_uri_get_auth_mechanism (uri ), "GSSAPI" ) ||
1454
- !strcasecmp (mongoc_uri_get_auth_mechanism (uri ), "MONGODB-X509" )) {
1455
-
1456
- if (source ) {
1457
- if (strcasecmp (source , "$external" )) {
1458
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: GSSAPI and X509 require \"$external\" authSource." );
1459
- return false;
1460
- }
1461
- } else {
1462
- mongoc_uri_set_auth_source (uri , "$external" );
1463
- }
1464
- }
1465
-
1466
- /* Mechanisms other than MONGODB-X509 and MONGODB-AWS require a username */
1467
- if (strcasecmp (mongoc_uri_get_auth_mechanism (uri ), "MONGODB-X509" ) &&
1468
- strcasecmp (mongoc_uri_get_auth_mechanism (uri ), "MONGODB-AWS" )) {
1469
- if (!mongoc_uri_get_username (uri ) ||
1470
- !strcmp (mongoc_uri_get_username (uri ), "" )) {
1471
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: '%s' authentication mechanism requires username." , mongoc_uri_get_auth_mechanism (uri ));
1472
- return false;
1473
- }
1474
- }
1475
-
1476
- /* MONGODB-X509 errors if a password is supplied. */
1477
- if (!strcasecmp (mongoc_uri_get_auth_mechanism (uri ), "MONGODB-X509" )) {
1478
- if (mongoc_uri_get_password (uri )) {
1479
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: X509 authentication mechanism does not accept a password." );
1480
- return false;
1481
- }
1482
- }
1483
- } else if (require_auth ) {
1484
- if (source && strcmp (source , "$external" ) != 0 && (!username || strcmp (username , "" ) == 0 )) {
1485
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: Default authentication mechanism requires username." );
1486
- return false;
1487
- }
1488
- }
1489
-
1490
- return true;
1491
- } /* }}} */
1492
-
1493
- static bool php_phongo_uri_finalize_directconnection (mongoc_uri_t * uri ) /* {{{ */
1494
- {
1495
- const mongoc_host_list_t * hosts ;
1496
-
1497
- if (!mongoc_uri_get_option_as_bool (uri , MONGOC_URI_DIRECTCONNECTION , false)) {
1498
- return true;
1499
- }
1500
-
1501
- /* Per the URI options spec, directConnection conflicts with multiple hosts
1502
- * and SRV URIs, which may resolve to multiple hosts. */
1503
- if (!strncmp (mongoc_uri_get_string (uri ), "mongodb+srv://" , 14 )) {
1504
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: SRV URI not allowed with directConnection option." );
1505
- return false;
1506
- }
1507
-
1508
- hosts = mongoc_uri_get_hosts (uri );
1509
-
1510
- if (hosts && hosts -> next ) {
1511
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: Multiple seeds not allowed with directConnection option." );
1512
- return false;
1513
- }
1514
-
1515
- return true;
1516
- } /* }}} */
1517
-
1518
- static bool php_phongo_uri_finalize_tls (mongoc_uri_t * uri ) /* {{{ */
1519
- {
1520
- const bson_t * options ;
1521
- bson_iter_t iter ;
1522
-
1523
- if (!(options = mongoc_uri_get_options (uri ))) {
1524
- return true;
1525
- }
1526
-
1527
- if (bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSINSECURE ) &&
1528
- (bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSALLOWINVALIDCERTIFICATES ) ||
1529
- bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSALLOWINVALIDHOSTNAMES ) ||
1530
- bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK ) ||
1531
- bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK ))) {
1532
- phongo_throw_exception (
1533
- PHONGO_ERROR_INVALID_ARGUMENT ,
1534
- "Failed to parse URI options: %s may not be combined with %s, %s, %s, or %s." ,
1535
- MONGOC_URI_TLSINSECURE ,
1536
- MONGOC_URI_TLSALLOWINVALIDCERTIFICATES ,
1537
- MONGOC_URI_TLSALLOWINVALIDHOSTNAMES ,
1538
- MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK ,
1539
- MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK );
1540
- return false;
1541
- }
1542
-
1543
- if (bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSALLOWINVALIDCERTIFICATES ) &&
1544
- (bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK ) ||
1545
- bson_iter_init_find_case (& iter , options , MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK ))) {
1546
- phongo_throw_exception (
1547
- PHONGO_ERROR_INVALID_ARGUMENT ,
1548
- "Failed to parse URI options: %s may not be combined with %s or %s." ,
1549
- MONGOC_URI_TLSALLOWINVALIDCERTIFICATES ,
1550
- MONGOC_URI_TLSDISABLEOCSPENDPOINTCHECK ,
1551
- MONGOC_URI_TLSDISABLECERTIFICATEREVOCATIONCHECK );
1552
- return false;
1553
- }
1554
-
1555
- return true;
1556
- } /* }}} */
1557
-
1558
1438
static bool php_phongo_apply_options_to_uri (mongoc_uri_t * uri , bson_t * options ) /* {{{ */
1559
1439
{
1560
1440
bson_iter_t iter ;
@@ -1755,17 +1635,6 @@ static bool php_phongo_apply_options_to_uri(mongoc_uri_t* uri, bson_t* options)
1755
1635
}
1756
1636
}
1757
1637
1758
- /* Validate any interactions between URI options */
1759
- if (!php_phongo_uri_finalize_auth (uri )) {
1760
- /* Exception should already have been thrown */
1761
- return false;
1762
- }
1763
-
1764
- if (!php_phongo_uri_finalize_directconnection (uri )) {
1765
- /* Exception should already have been thrown */
1766
- return false;
1767
- }
1768
-
1769
1638
return true;
1770
1639
} /* }}} */
1771
1640
@@ -2566,7 +2435,9 @@ static void php_phongo_set_handshake_data(zval* driverOptions)
2566
2435
2567
2436
static mongoc_client_t * php_phongo_make_mongo_client (const mongoc_uri_t * uri , zval * driverOptions ) /* {{{ */
2568
2437
{
2569
- const char * mongoc_version , * bson_version ;
2438
+ const char * mongoc_version , * bson_version ;
2439
+ mongoc_client_t * client ;
2440
+ bson_error_t error = { 0 };
2570
2441
2571
2442
#ifdef HAVE_SYSTEM_LIBMONGOC
2572
2443
mongoc_version = mongoc_get_version ();
@@ -2592,7 +2463,11 @@ static mongoc_client_t* php_phongo_make_mongo_client(const mongoc_uri_t* uri, zv
2592
2463
2593
2464
php_phongo_set_handshake_data (driverOptions );
2594
2465
2595
- return mongoc_client_new_from_uri (uri );
2466
+ if (!(client = mongoc_client_new_from_uri_with_error (uri , & error ))) {
2467
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Failed to parse URI options: %s" , error .message );
2468
+ }
2469
+
2470
+ return client ;
2596
2471
} /* }}} */
2597
2472
2598
2473
/* Adds a client to the appropriate registry. Persistent and request-scoped
@@ -3321,22 +3196,12 @@ void phongo_manager_init(php_phongo_manager_t* manager, const char* uri_string,
3321
3196
if (EG (exception )) {
3322
3197
goto cleanup ;
3323
3198
}
3324
-
3325
- if (!php_phongo_uri_finalize_tls (uri )) {
3326
- /* Exception should already have been thrown */
3327
- goto cleanup ;
3328
- }
3329
- #else
3330
- if (mongoc_uri_get_tls (uri )) {
3331
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT , "Cannot create SSL client. SSL is not enabled in this build." );
3332
- goto cleanup ;
3333
- }
3334
3199
#endif
3335
3200
3336
3201
manager -> client = php_phongo_make_mongo_client (uri , driverOptions );
3337
3202
3338
3203
if (!manager -> client ) {
3339
- phongo_throw_exception ( PHONGO_ERROR_RUNTIME , "Failed to create Manager from URI: '%s'" , uri_string );
3204
+ /* Exception should already have been thrown */
3340
3205
goto cleanup ;
3341
3206
}
3342
3207
0 commit comments