@@ -745,18 +745,17 @@ static void _php_ldap_controls_to_array(LDAP *ld, LDAPControl** ctrls, zval* arr
745
745
ldap_controls_free (ctrls );
746
746
}
747
747
748
- static LDAPControl * * _php_ldap_controls_from_array (LDAP * ld , zval * array , uint32_t arg_num )
748
+ static LDAPControl * * php_ldap_controls_from_array (LDAP * ld , const HashTable * controls , uint32_t arg_num )
749
749
{
750
- int ncontrols ;
751
750
LDAPControl * * ctrlp , * * ctrls = NULL ;
752
751
zval * ctrlarray ;
753
752
int error = 0 ;
754
753
755
- ncontrols = zend_hash_num_elements (Z_ARRVAL_P ( array ) );
756
- ctrls = safe_emalloc ((1 + ncontrols ), sizeof (* ctrls ), 0 );
754
+ uint32_t num_controls = zend_hash_num_elements (controls );
755
+ ctrls = safe_emalloc ((1 + num_controls ), sizeof (* ctrls ), 0 );
757
756
* ctrls = NULL ;
758
757
ctrlp = ctrls ;
759
- ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P ( array ) , ctrlarray ) {
758
+ ZEND_HASH_FOREACH_VAL (controls , ctrlarray ) {
760
759
if (Z_TYPE_P (ctrlarray ) != IS_ARRAY ) {
761
760
zend_argument_type_error (arg_num , "must contain only arrays, where each array is a control" );
762
761
error = 1 ;
@@ -1145,25 +1144,25 @@ PHP_FUNCTION(ldap_bind)
1145
1144
/* {{{ Bind to LDAP directory */
1146
1145
PHP_FUNCTION (ldap_bind_ext )
1147
1146
{
1148
- zval * serverctrls = NULL ;
1149
1147
zval * link ;
1150
1148
char * ldap_bind_dn = NULL , * ldap_bind_pw = NULL ;
1151
1149
size_t ldap_bind_dnlen , ldap_bind_pwlen ;
1150
+ HashTable * server_controls_ht = NULL ;
1152
1151
ldap_linkdata * ld ;
1153
1152
LDAPControl * * lserverctrls = NULL ;
1154
1153
ldap_resultdata * result ;
1155
1154
LDAPMessage * ldap_res ;
1156
1155
int rc ;
1157
1156
1158
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|p!p!a !" , & link , ldap_link_ce , & ldap_bind_dn , & ldap_bind_dnlen , & ldap_bind_pw , & ldap_bind_pwlen , & serverctrls ) != SUCCESS ) {
1157
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O|p!p!h !" , & link , ldap_link_ce , & ldap_bind_dn , & ldap_bind_dnlen , & ldap_bind_pw , & ldap_bind_pwlen , & server_controls_ht ) != SUCCESS ) {
1159
1158
RETURN_THROWS ();
1160
1159
}
1161
1160
1162
1161
ld = Z_LDAP_LINK_P (link );
1163
1162
VERIFY_LDAP_LINK_CONNECTED (ld );
1164
1163
1165
- if (serverctrls ) {
1166
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 4 );
1164
+ if (server_controls_ht ) {
1165
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 4 );
1167
1166
if (lserverctrls == NULL ) {
1168
1167
RETVAL_FALSE ;
1169
1168
goto cleanup ;
@@ -1402,12 +1401,13 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in
1402
1401
/* {{{ php_ldap_do_search */
1403
1402
static void php_ldap_do_search (INTERNAL_FUNCTION_PARAMETERS , int scope )
1404
1403
{
1405
- zval * link , * attrs = NULL , * serverctrls = NULL ;
1404
+ zval * link , * attrs = NULL ;
1406
1405
HashTable * base_dn_ht = NULL ;
1407
1406
zend_string * base_dn_str = NULL ;
1408
1407
HashTable * filter_ht = NULL ;
1409
1408
zend_string * filter_str = NULL ;
1410
1409
zend_long attrsonly , sizelimit , timelimit , deref ;
1410
+ HashTable * server_controls_ht = NULL ;
1411
1411
char * * ldap_attrs = NULL ;
1412
1412
ldap_linkdata * ld = NULL ;
1413
1413
ldap_resultdata * result ;
@@ -1427,7 +1427,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1427
1427
Z_PARAM_LONG (sizelimit )
1428
1428
Z_PARAM_LONG (timelimit )
1429
1429
Z_PARAM_LONG (deref )
1430
- Z_PARAM_ARRAY_EX ( serverctrls , 1 , 1 )
1430
+ Z_PARAM_ARRAY_HT_EX ( server_controls_ht , 1 , 1 )
1431
1431
ZEND_PARSE_PARAMETERS_END ();
1432
1432
1433
1433
/* Reverse -> fall through */
@@ -1600,10 +1600,10 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1600
1600
}
1601
1601
}
1602
1602
1603
- if (serverctrls ) {
1603
+ if (server_controls_ht ) {
1604
1604
/* We have to parse controls again for each link as they use it */
1605
1605
_php_ldap_controls_free (& lserverctrls );
1606
- lserverctrls = _php_ldap_controls_from_array (current_ld -> link , serverctrls , 9 );
1606
+ lserverctrls = php_ldap_controls_from_array (current_ld -> link , server_controls_ht , 9 );
1607
1607
if (lserverctrls == NULL ) {
1608
1608
rcs [ldap_link_index ] = -1 ;
1609
1609
// TODO Throw an exception/cleanup?
@@ -1661,8 +1661,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1661
1661
goto cleanup ;
1662
1662
}
1663
1663
1664
- if (serverctrls ) {
1665
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 9 );
1664
+ if (server_controls_ht ) {
1665
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 9 );
1666
1666
if (lserverctrls == NULL ) {
1667
1667
ret = 0 ;
1668
1668
goto cleanup ;
@@ -2193,19 +2193,19 @@ PHP_FUNCTION(ldap_dn2ufn)
2193
2193
/* {{{ php_ldap_do_modify */
2194
2194
static void php_ldap_do_modify (INTERNAL_FUNCTION_PARAMETERS , int oper , int ext )
2195
2195
{
2196
- zval * serverctrls = NULL ;
2197
2196
zval * link ;
2198
2197
ldap_linkdata * ld ;
2199
2198
char * dn ;
2200
2199
HashTable * attributes_ht ;
2200
+ HashTable * server_controls_ht = NULL ;
2201
2201
LDAPMod * * ldap_mods ;
2202
2202
LDAPControl * * lserverctrls = NULL ;
2203
2203
ldap_resultdata * result ;
2204
2204
LDAPMessage * ldap_res ;
2205
2205
size_t dn_len ;
2206
2206
int is_full_add = 0 ; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
2207
2207
2208
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oph/|a !" , & link , ldap_link_ce , & dn , & dn_len , & attributes_ht , & serverctrls ) != SUCCESS ) {
2208
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oph/|h !" , & link , ldap_link_ce , & dn , & dn_len , & attributes_ht , & server_controls_ht ) != SUCCESS ) {
2209
2209
RETURN_THROWS ();
2210
2210
}
2211
2211
@@ -2305,8 +2305,8 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2305
2305
} ZEND_HASH_FOREACH_END ();
2306
2306
ldap_mods [num_attribs ] = NULL ;
2307
2307
2308
- if (serverctrls ) {
2309
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 4 );
2308
+ if (server_controls_ht ) {
2309
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 4 );
2310
2310
if (lserverctrls == NULL ) {
2311
2311
RETVAL_FALSE ;
2312
2312
goto cleanup ;
@@ -2446,8 +2446,8 @@ PHP_FUNCTION(ldap_mod_del_ext)
2446
2446
/* {{{ php_ldap_do_delete */
2447
2447
static void php_ldap_do_delete (INTERNAL_FUNCTION_PARAMETERS , int ext )
2448
2448
{
2449
- zval * serverctrls = NULL ;
2450
2449
zval * link ;
2450
+ HashTable * server_controls_ht = NULL ;
2451
2451
ldap_linkdata * ld ;
2452
2452
LDAPControl * * lserverctrls = NULL ;
2453
2453
ldap_resultdata * result ;
@@ -2456,15 +2456,15 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
2456
2456
int rc , msgid ;
2457
2457
size_t dn_len ;
2458
2458
2459
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Op|a !" , & link , ldap_link_ce , & dn , & dn_len , & serverctrls ) != SUCCESS ) {
2459
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Op|h !" , & link , ldap_link_ce , & dn , & dn_len , & server_controls_ht ) != SUCCESS ) {
2460
2460
RETURN_THROWS ();
2461
2461
}
2462
2462
2463
2463
ld = Z_LDAP_LINK_P (link );
2464
2464
VERIFY_LDAP_LINK_CONNECTED (ld );
2465
2465
2466
- if (serverctrls ) {
2467
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 3 );
2466
+ if (server_controls_ht ) {
2467
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 3 );
2468
2468
if (lserverctrls == NULL ) {
2469
2469
RETVAL_FALSE ;
2470
2470
goto cleanup ;
@@ -2522,11 +2522,11 @@ PHP_FUNCTION(ldap_delete_ext)
2522
2522
/* {{{ Perform multiple modifications as part of one operation */
2523
2523
PHP_FUNCTION (ldap_modify_batch )
2524
2524
{
2525
- zval * server_controls_zv = NULL ;
2526
2525
zval * link ;
2527
2526
char * dn ;
2528
2527
size_t dn_len ;
2529
2528
HashTable * modifications ;
2529
+ HashTable * server_controls_ht = NULL ;
2530
2530
LDAPControl * * lserverctrls = NULL ;
2531
2531
2532
2532
/*
@@ -2553,7 +2553,7 @@ PHP_FUNCTION(ldap_modify_batch)
2553
2553
];
2554
2554
*/
2555
2555
2556
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oph/|a !" , & link , ldap_link_ce , & dn , & dn_len , & modifications , & server_controls_zv ) != SUCCESS ) {
2556
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Oph/|h !" , & link , ldap_link_ce , & dn , & dn_len , & modifications , & server_controls_ht ) != SUCCESS ) {
2557
2557
RETURN_THROWS ();
2558
2558
}
2559
2559
@@ -2669,8 +2669,8 @@ PHP_FUNCTION(ldap_modify_batch)
2669
2669
/* validation of modifications array was successful */
2670
2670
2671
2671
/* Check that the LDAP server controls array is valid */
2672
- if (server_controls_zv ) {
2673
- lserverctrls = _php_ldap_controls_from_array (ld -> link , server_controls_zv , 4 );
2672
+ if (server_controls_ht ) {
2673
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 4 );
2674
2674
if (lserverctrls == NULL ) {
2675
2675
_php_ldap_controls_free (& lserverctrls );
2676
2676
RETURN_FALSE ;
@@ -2846,30 +2846,30 @@ PHP_FUNCTION(ldap_error)
2846
2846
/* {{{ Determine if an entry has a specific value for one of its attributes */
2847
2847
PHP_FUNCTION (ldap_compare )
2848
2848
{
2849
- zval * serverctrls = NULL ;
2850
2849
zval * link ;
2851
2850
char * dn , * attr ;
2852
2851
size_t dn_len , attr_len ;
2852
+ HashTable * server_controls_ht = NULL ;
2853
2853
ldap_linkdata * ld ;
2854
2854
LDAPControl * * lserverctrls = NULL ;
2855
2855
int ldap_errno ;
2856
2856
struct berval lvalue ;
2857
2857
2858
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Opps|a !" ,
2858
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Opps|h !" ,
2859
2859
& link , ldap_link_ce ,
2860
2860
& dn , & dn_len ,
2861
2861
& attr , & attr_len ,
2862
2862
& lvalue .bv_val , & lvalue .bv_len ,
2863
- & serverctrls
2863
+ & server_controls_ht
2864
2864
) != SUCCESS ) {
2865
2865
RETURN_THROWS ();
2866
2866
}
2867
2867
2868
2868
ld = Z_LDAP_LINK_P (link );
2869
2869
VERIFY_LDAP_LINK_CONNECTED (ld );
2870
2870
2871
- if (serverctrls ) {
2872
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 5 );
2871
+ if (server_controls_ht ) {
2872
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 5 );
2873
2873
if (lserverctrls == NULL ) {
2874
2874
RETVAL_FALSE ;
2875
2875
goto cleanup ;
@@ -3251,7 +3251,7 @@ PHP_FUNCTION(ldap_set_option)
3251
3251
RETURN_THROWS ();
3252
3252
}
3253
3253
3254
- ctrls = _php_ldap_controls_from_array (ldap , newval , 3 );
3254
+ ctrls = php_ldap_controls_from_array (ldap , Z_ARRVAL_P ( newval ) , 3 );
3255
3255
3256
3256
if (ctrls == NULL ) {
3257
3257
RETURN_FALSE ;
@@ -3526,7 +3526,6 @@ PHP_FUNCTION(ldap_parse_reference)
3526
3526
/* {{{ php_ldap_do_rename */
3527
3527
static void php_ldap_do_rename (INTERNAL_FUNCTION_PARAMETERS , int ext )
3528
3528
{
3529
- zval * serverctrls = NULL ;
3530
3529
zval * link ;
3531
3530
ldap_linkdata * ld ;
3532
3531
LDAPControl * * lserverctrls = NULL ;
@@ -3536,8 +3535,9 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
3536
3535
char * dn , * newrdn , * newparent ;
3537
3536
size_t dn_len , newrdn_len , newparent_len ;
3538
3537
bool deleteoldrdn ;
3538
+ HashTable * server_controls_ht = NULL ;
3539
3539
3540
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "Opppb|a !" , & link , ldap_link_ce , & dn , & dn_len , & newrdn , & newrdn_len , & newparent , & newparent_len , & deleteoldrdn , & serverctrls ) != SUCCESS ) {
3540
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "Opppb|h !" , & link , ldap_link_ce , & dn , & dn_len , & newrdn , & newrdn_len , & newparent , & newparent_len , & deleteoldrdn , & server_controls_ht ) != SUCCESS ) {
3541
3541
RETURN_THROWS ();
3542
3542
}
3543
3543
@@ -3549,8 +3549,8 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
3549
3549
}
3550
3550
3551
3551
#if (LDAP_API_VERSION > 2000 ) || defined(HAVE_ORALDAP )
3552
- if (serverctrls ) {
3553
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 6 );
3552
+ if (server_controls_ht ) {
3553
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 6 );
3554
3554
if (lserverctrls == NULL ) {
3555
3555
RETVAL_FALSE ;
3556
3556
goto cleanup ;
@@ -3857,10 +3857,10 @@ PHP_FUNCTION(ldap_8859_to_t61)
3857
3857
/* {{{ Extended operations, Pierangelo Masarati */
3858
3858
#ifdef HAVE_LDAP_EXTENDED_OPERATION_S
3859
3859
static void php_ldap_exop (INTERNAL_FUNCTION_PARAMETERS , bool force_sync ) {
3860
- zval * serverctrls = NULL ;
3861
3860
zval * link , * retdata = NULL , * retoid = NULL ;
3862
3861
char * lretoid = NULL ;
3863
3862
zend_string * reqoid , * reqdata = NULL ;
3863
+ HashTable * server_controls_ht = NULL ;
3864
3864
struct berval lreqdata , * lretdata = NULL ;
3865
3865
ldap_linkdata * ld ;
3866
3866
ldap_resultdata * result ;
@@ -3875,7 +3875,7 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
3875
3875
}
3876
3876
}
3877
3877
3878
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "OP|S!a !zz" , & link , ldap_link_ce , & reqoid , & reqdata , & serverctrls , & retdata , & retoid ) != SUCCESS ) {
3878
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "OP|S!h !zz" , & link , ldap_link_ce , & reqoid , & reqdata , & server_controls_ht , & retdata , & retoid ) != SUCCESS ) {
3879
3879
RETURN_THROWS ();
3880
3880
}
3881
3881
@@ -3889,8 +3889,8 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
3889
3889
lreqdata .bv_len = 0 ;
3890
3890
}
3891
3891
3892
- if (serverctrls ) {
3893
- lserverctrls = _php_ldap_controls_from_array (ld -> link , serverctrls , 4 );
3892
+ if (server_controls_ht ) {
3893
+ lserverctrls = php_ldap_controls_from_array (ld -> link , server_controls_ht , 4 );
3894
3894
if (lserverctrls == NULL ) {
3895
3895
RETVAL_FALSE ;
3896
3896
goto cleanup ;
0 commit comments