Skip to content

Commit 355f320

Browse files
committed
ext/ldap: Use HashTable* for controls
1 parent a165f1f commit 355f320

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

ext/ldap/ldap.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,17 @@ static void _php_ldap_controls_to_array(LDAP *ld, LDAPControl** ctrls, zval* arr
745745
ldap_controls_free(ctrls);
746746
}
747747

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)
749749
{
750-
int ncontrols;
751750
LDAPControl** ctrlp, **ctrls = NULL;
752751
zval* ctrlarray;
753752
int error = 0;
754753

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);
757756
*ctrls = NULL;
758757
ctrlp = ctrls;
759-
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), ctrlarray) {
758+
ZEND_HASH_FOREACH_VAL(controls, ctrlarray) {
760759
if (Z_TYPE_P(ctrlarray) != IS_ARRAY) {
761760
zend_argument_type_error(arg_num, "must contain only arrays, where each array is a control");
762761
error = 1;
@@ -1145,25 +1144,25 @@ PHP_FUNCTION(ldap_bind)
11451144
/* {{{ Bind to LDAP directory */
11461145
PHP_FUNCTION(ldap_bind_ext)
11471146
{
1148-
zval *serverctrls = NULL;
11491147
zval *link;
11501148
char *ldap_bind_dn = NULL, *ldap_bind_pw = NULL;
11511149
size_t ldap_bind_dnlen, ldap_bind_pwlen;
1150+
HashTable *server_controls_ht = NULL;
11521151
ldap_linkdata *ld;
11531152
LDAPControl **lserverctrls = NULL;
11541153
ldap_resultdata *result;
11551154
LDAPMessage *ldap_res;
11561155
int rc;
11571156

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) {
11591158
RETURN_THROWS();
11601159
}
11611160

11621161
ld = Z_LDAP_LINK_P(link);
11631162
VERIFY_LDAP_LINK_CONNECTED(ld);
11641163

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);
11671166
if (lserverctrls == NULL) {
11681167
RETVAL_FALSE;
11691168
goto cleanup;
@@ -1402,12 +1401,13 @@ static void php_set_opts(LDAP *ldap, int sizelimit, int timelimit, int deref, in
14021401
/* {{{ php_ldap_do_search */
14031402
static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14041403
{
1405-
zval *link, *attrs = NULL, *serverctrls = NULL;
1404+
zval *link, *attrs = NULL;
14061405
HashTable *base_dn_ht = NULL;
14071406
zend_string *base_dn_str = NULL;
14081407
HashTable *filter_ht = NULL;
14091408
zend_string *filter_str = NULL;
14101409
zend_long attrsonly, sizelimit, timelimit, deref;
1410+
HashTable *server_controls_ht = NULL;
14111411
char **ldap_attrs = NULL;
14121412
ldap_linkdata *ld = NULL;
14131413
ldap_resultdata *result;
@@ -1427,7 +1427,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
14271427
Z_PARAM_LONG(sizelimit)
14281428
Z_PARAM_LONG(timelimit)
14291429
Z_PARAM_LONG(deref)
1430-
Z_PARAM_ARRAY_EX(serverctrls, 1, 1)
1430+
Z_PARAM_ARRAY_HT_EX(server_controls_ht, 1, 1)
14311431
ZEND_PARSE_PARAMETERS_END();
14321432

14331433
/* Reverse -> fall through */
@@ -1600,10 +1600,10 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16001600
}
16011601
}
16021602

1603-
if (serverctrls) {
1603+
if (server_controls_ht) {
16041604
/* We have to parse controls again for each link as they use it */
16051605
_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);
16071607
if (lserverctrls == NULL) {
16081608
rcs[ldap_link_index] = -1;
16091609
// TODO Throw an exception/cleanup?
@@ -1661,8 +1661,8 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
16611661
goto cleanup;
16621662
}
16631663

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);
16661666
if (lserverctrls == NULL) {
16671667
ret = 0;
16681668
goto cleanup;
@@ -2193,19 +2193,19 @@ PHP_FUNCTION(ldap_dn2ufn)
21932193
/* {{{ php_ldap_do_modify */
21942194
static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
21952195
{
2196-
zval *serverctrls = NULL;
21972196
zval *link;
21982197
ldap_linkdata *ld;
21992198
char *dn;
22002199
HashTable *attributes_ht;
2200+
HashTable *server_controls_ht = NULL;
22012201
LDAPMod **ldap_mods;
22022202
LDAPControl **lserverctrls = NULL;
22032203
ldap_resultdata *result;
22042204
LDAPMessage *ldap_res;
22052205
size_t dn_len;
22062206
int is_full_add=0; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
22072207

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) {
22092209
RETURN_THROWS();
22102210
}
22112211

@@ -2305,8 +2305,8 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
23052305
} ZEND_HASH_FOREACH_END();
23062306
ldap_mods[num_attribs] = NULL;
23072307

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);
23102310
if (lserverctrls == NULL) {
23112311
RETVAL_FALSE;
23122312
goto cleanup;
@@ -2446,8 +2446,8 @@ PHP_FUNCTION(ldap_mod_del_ext)
24462446
/* {{{ php_ldap_do_delete */
24472447
static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
24482448
{
2449-
zval *serverctrls = NULL;
24502449
zval *link;
2450+
HashTable *server_controls_ht = NULL;
24512451
ldap_linkdata *ld;
24522452
LDAPControl **lserverctrls = NULL;
24532453
ldap_resultdata *result;
@@ -2456,15 +2456,15 @@ static void php_ldap_do_delete(INTERNAL_FUNCTION_PARAMETERS, int ext)
24562456
int rc, msgid;
24572457
size_t dn_len;
24582458

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) {
24602460
RETURN_THROWS();
24612461
}
24622462

24632463
ld = Z_LDAP_LINK_P(link);
24642464
VERIFY_LDAP_LINK_CONNECTED(ld);
24652465

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);
24682468
if (lserverctrls == NULL) {
24692469
RETVAL_FALSE;
24702470
goto cleanup;
@@ -2522,11 +2522,11 @@ PHP_FUNCTION(ldap_delete_ext)
25222522
/* {{{ Perform multiple modifications as part of one operation */
25232523
PHP_FUNCTION(ldap_modify_batch)
25242524
{
2525-
zval *server_controls_zv = NULL;
25262525
zval *link;
25272526
char *dn;
25282527
size_t dn_len;
25292528
HashTable *modifications;
2529+
HashTable *server_controls_ht = NULL;
25302530
LDAPControl **lserverctrls = NULL;
25312531

25322532
/*
@@ -2553,7 +2553,7 @@ PHP_FUNCTION(ldap_modify_batch)
25532553
];
25542554
*/
25552555

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) {
25572557
RETURN_THROWS();
25582558
}
25592559

@@ -2669,8 +2669,8 @@ PHP_FUNCTION(ldap_modify_batch)
26692669
/* validation of modifications array was successful */
26702670

26712671
/* 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);
26742674
if (lserverctrls == NULL) {
26752675
_php_ldap_controls_free(&lserverctrls);
26762676
RETURN_FALSE;
@@ -2846,30 +2846,30 @@ PHP_FUNCTION(ldap_error)
28462846
/* {{{ Determine if an entry has a specific value for one of its attributes */
28472847
PHP_FUNCTION(ldap_compare)
28482848
{
2849-
zval *serverctrls = NULL;
28502849
zval *link;
28512850
char *dn, *attr;
28522851
size_t dn_len, attr_len;
2852+
HashTable *server_controls_ht = NULL;
28532853
ldap_linkdata *ld;
28542854
LDAPControl **lserverctrls = NULL;
28552855
int ldap_errno;
28562856
struct berval lvalue;
28572857

2858-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opps|a!",
2858+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Opps|h!",
28592859
&link, ldap_link_ce,
28602860
&dn, &dn_len,
28612861
&attr, &attr_len,
28622862
&lvalue.bv_val, &lvalue.bv_len,
2863-
&serverctrls
2863+
&server_controls_ht
28642864
) != SUCCESS) {
28652865
RETURN_THROWS();
28662866
}
28672867

28682868
ld = Z_LDAP_LINK_P(link);
28692869
VERIFY_LDAP_LINK_CONNECTED(ld);
28702870

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);
28732873
if (lserverctrls == NULL) {
28742874
RETVAL_FALSE;
28752875
goto cleanup;
@@ -3251,7 +3251,7 @@ PHP_FUNCTION(ldap_set_option)
32513251
RETURN_THROWS();
32523252
}
32533253

3254-
ctrls = _php_ldap_controls_from_array(ldap, newval, 3);
3254+
ctrls = php_ldap_controls_from_array(ldap, Z_ARRVAL_P(newval), 3);
32553255

32563256
if (ctrls == NULL) {
32573257
RETURN_FALSE;
@@ -3526,7 +3526,6 @@ PHP_FUNCTION(ldap_parse_reference)
35263526
/* {{{ php_ldap_do_rename */
35273527
static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
35283528
{
3529-
zval *serverctrls = NULL;
35303529
zval *link;
35313530
ldap_linkdata *ld;
35323531
LDAPControl **lserverctrls = NULL;
@@ -3536,8 +3535,9 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
35363535
char *dn, *newrdn, *newparent;
35373536
size_t dn_len, newrdn_len, newparent_len;
35383537
bool deleteoldrdn;
3538+
HashTable *server_controls_ht = NULL;
35393539

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) {
35413541
RETURN_THROWS();
35423542
}
35433543

@@ -3549,8 +3549,8 @@ static void php_ldap_do_rename(INTERNAL_FUNCTION_PARAMETERS, int ext)
35493549
}
35503550

35513551
#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);
35543554
if (lserverctrls == NULL) {
35553555
RETVAL_FALSE;
35563556
goto cleanup;
@@ -3857,10 +3857,10 @@ PHP_FUNCTION(ldap_8859_to_t61)
38573857
/* {{{ Extended operations, Pierangelo Masarati */
38583858
#ifdef HAVE_LDAP_EXTENDED_OPERATION_S
38593859
static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
3860-
zval *serverctrls = NULL;
38613860
zval *link, *retdata = NULL, *retoid = NULL;
38623861
char *lretoid = NULL;
38633862
zend_string *reqoid, *reqdata = NULL;
3863+
HashTable *server_controls_ht = NULL;
38643864
struct berval lreqdata, *lretdata = NULL;
38653865
ldap_linkdata *ld;
38663866
ldap_resultdata *result;
@@ -3875,7 +3875,7 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
38753875
}
38763876
}
38773877

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) {
38793879
RETURN_THROWS();
38803880
}
38813881

@@ -3889,8 +3889,8 @@ static void php_ldap_exop(INTERNAL_FUNCTION_PARAMETERS, bool force_sync) {
38893889
lreqdata.bv_len = 0;
38903890
}
38913891

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);
38943894
if (lserverctrls == NULL) {
38953895
RETVAL_FALSE;
38963896
goto cleanup;

0 commit comments

Comments
 (0)