@@ -2511,6 +2511,66 @@ int php_phongo_set_monitoring_callbacks(mongoc_client_t* client)
2511
2511
return retval ;
2512
2512
}
2513
2513
2514
+ static zval * php_phongo_manager_prepare_manager_for_hash (zval * driverOptions , bool * free TSRMLS_DC )
2515
+ {
2516
+ php_phongo_manager_t * manager ;
2517
+ zval * autoEncryptionOpts = NULL ;
2518
+ zval * keyVaultClient = NULL ;
2519
+ zval * driverOptionsClone = NULL ;
2520
+ zval * autoEncryptionOptsClone = NULL ;
2521
+ #if PHP_VERSION_ID >= 70000
2522
+ zval stackAutoEncryptionOptsClone ;
2523
+ #endif
2524
+
2525
+ * free = false;
2526
+
2527
+ if (!driverOptions ) {
2528
+ return NULL ;
2529
+ }
2530
+
2531
+ if (!php_array_existsc (driverOptions , "autoEncryption" )) {
2532
+ goto ref ;
2533
+ }
2534
+
2535
+ autoEncryptionOpts = php_array_fetchc (driverOptions , "autoEncryption" );
2536
+ if (Z_TYPE_P (autoEncryptionOpts ) != IS_ARRAY ) {
2537
+ goto ref ;
2538
+ }
2539
+
2540
+ if (!php_array_existsc (autoEncryptionOpts , "keyVaultClient" )) {
2541
+ goto ref ;
2542
+ }
2543
+
2544
+ keyVaultClient = php_array_fetchc (autoEncryptionOpts , "keyVaultClient" );
2545
+ if (Z_TYPE_P (keyVaultClient ) != IS_OBJECT || !instanceof_function (Z_OBJCE_P (keyVaultClient ), php_phongo_manager_ce TSRMLS_CC )) {
2546
+ goto ref ;
2547
+ }
2548
+
2549
+ * free = true;
2550
+
2551
+ manager = Z_MANAGER_OBJ_P (keyVaultClient );
2552
+
2553
+ #if PHP_VERSION_ID >= 70000
2554
+ driverOptionsClone = ecalloc (sizeof (zval ), 1 );
2555
+ autoEncryptionOptsClone = & stackAutoEncryptionOptsClone ;
2556
+ #else
2557
+ ALLOC_INIT_ZVAL (driverOptionsClone );
2558
+ MAKE_STD_ZVAL (autoEncryptionOptsClone );
2559
+ #endif
2560
+
2561
+ ZVAL_DUP (autoEncryptionOptsClone , autoEncryptionOpts );
2562
+ ADD_ASSOC_STRINGL (autoEncryptionOptsClone , "keyVaultClient" , manager -> client_hash , manager -> client_hash_len );
2563
+
2564
+ ZVAL_DUP (driverOptionsClone , driverOptions );
2565
+ ADD_ASSOC_ZVAL_EX (driverOptionsClone , "autoEncryption" , autoEncryptionOptsClone );
2566
+
2567
+ return driverOptionsClone ;
2568
+
2569
+ ref :
2570
+ Z_ADDREF_P (driverOptions );
2571
+ return driverOptions ;
2572
+ }
2573
+
2514
2574
/* Creates a hash for a client by concatenating the URI string with serialized
2515
2575
* options arrays. On success, a persistent string is returned (i.e. pefree()
2516
2576
* should be used to free it) and hash_len will be set to the string's length.
@@ -2520,6 +2580,8 @@ static char* php_phongo_manager_make_client_hash(const char* uri_string, zval* o
2520
2580
char * hash = NULL ;
2521
2581
smart_str var_buf = { 0 };
2522
2582
php_serialize_data_t var_hash ;
2583
+ zval * serializable_driver_options = NULL ;
2584
+ bool free_driver_options = false;
2523
2585
2524
2586
#if PHP_VERSION_ID >= 70000
2525
2587
zval args ;
@@ -2536,8 +2598,8 @@ static char* php_phongo_manager_make_client_hash(const char* uri_string, zval* o
2536
2598
}
2537
2599
2538
2600
if (driverOptions ) {
2539
- ADD_ASSOC_ZVAL_EX ( & args , " driverOptions" , driverOptions );
2540
- Z_ADDREF_P ( driverOptions );
2601
+ serializable_driver_options = php_phongo_manager_prepare_manager_for_hash ( driverOptions , & free_driver_options TSRMLS_CC );
2602
+ ADD_ASSOC_ZVAL_EX ( & args , " driverOptions" , serializable_driver_options );
2541
2603
} else {
2542
2604
ADD_ASSOC_NULL_EX (& args , "driverOptions" );
2543
2605
}
@@ -2552,6 +2614,11 @@ static char* php_phongo_manager_make_client_hash(const char* uri_string, zval* o
2552
2614
}
2553
2615
2554
2616
zval_ptr_dtor (& args );
2617
+
2618
+ if (free_driver_options ) {
2619
+ efree (serializable_driver_options );
2620
+ }
2621
+
2555
2622
#else
2556
2623
zval * args ;
2557
2624
@@ -2568,8 +2635,8 @@ static char* php_phongo_manager_make_client_hash(const char* uri_string, zval* o
2568
2635
}
2569
2636
2570
2637
if (driverOptions ) {
2571
- ADD_ASSOC_ZVAL_EX ( args , " driverOptions" , driverOptions );
2572
- Z_ADDREF_P ( driverOptions );
2638
+ serializable_driver_options = php_phongo_manager_prepare_manager_for_hash ( driverOptions , & free_driver_options TSRMLS_CC );
2639
+ ADD_ASSOC_ZVAL_EX ( args , " driverOptions" , serializable_driver_options );
2573
2640
} else {
2574
2641
ADD_ASSOC_NULL_EX (args , "driverOptions" );
2575
2642
}
0 commit comments