summaryrefslogtreecommitdiff
path: root/ext/ldap
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-01-07 12:28:51 +0100
committerNikita Popov <nikita.ppv@gmail.com>2019-01-11 15:49:06 +0100
commite219ec144ef6682b71e135fd18654ee1bb4676b4 (patch)
treee4a3ae2b619cdc9fe50ee8e1fa5adb99d804dddf /ext/ldap
parentfe8fdfa3bd588d80ce60f6b3848058239e0a760f (diff)
downloadphp-git-e219ec144ef6682b71e135fd18654ee1bb4676b4.tar.gz
Implement typed properties
RFC: https://wiki.php.net/rfc/typed_properties_v2 This is a squash of PR #3734, which is a squash of PR #3313. Co-authored-by: Bob Weinand <bobwei9@hotmail.com> Co-authored-by: Joe Watkins <krakjoe@php.net> Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Diffstat (limited to 'ext/ldap')
-rw-r--r--ext/ldap/ldap.c93
1 files changed, 44 insertions, 49 deletions
diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c
index 1ddf1a77ca..0528ea08d7 100644
--- a/ext/ldap/ldap.c
+++ b/ext/ldap/ldap.c
@@ -576,7 +576,11 @@ static void _php_ldap_controls_to_array(LDAP *ld, LDAPControl** ctrls, zval* arr
zval tmp1;
LDAPControl **ctrlp;
- array_init(array);
+ array = zend_try_array_init(array);
+ if (!array) {
+ return;
+ }
+
if (ctrls == NULL) {
return;
}
@@ -2975,7 +2979,7 @@ PHP_FUNCTION(ldap_get_option)
ldap_linkdata *ld;
zend_long option;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz/", &link, &option, &retval) != SUCCESS) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlz", &link, &option, &retval) != SUCCESS) {
return;
}
@@ -3017,8 +3021,7 @@ PHP_FUNCTION(ldap_get_option)
if (ldap_get_option(ld->link, option, &val)) {
RETURN_FALSE;
}
- zval_ptr_dtor(retval);
- ZVAL_LONG(retval, val);
+ ZEND_TRY_ASSIGN_LONG(retval, val);
} break;
#ifdef LDAP_OPT_NETWORK_TIMEOUT
case LDAP_OPT_NETWORK_TIMEOUT:
@@ -3034,8 +3037,7 @@ PHP_FUNCTION(ldap_get_option)
if (!timeout) {
RETURN_FALSE;
}
- zval_ptr_dtor(retval);
- ZVAL_LONG(retval, timeout->tv_sec);
+ ZEND_TRY_ASSIGN_LONG(retval, timeout->tv_sec);
ldap_memfree(timeout);
} break;
#elif defined(LDAP_X_OPT_CONNECT_TIMEOUT)
@@ -3046,8 +3048,7 @@ PHP_FUNCTION(ldap_get_option)
if (ldap_get_option(ld->link, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout)) {
RETURN_FALSE;
}
- zval_ptr_dtor(retval);
- ZVAL_LONG(retval, (timeout / 1000));
+ ZEND_TRY_ASSIGN_LONG(retval, (timeout / 1000));
} break;
#endif
#ifdef LDAP_OPT_TIMEOUT
@@ -3064,8 +3065,7 @@ PHP_FUNCTION(ldap_get_option)
if (!timeout) {
RETURN_FALSE;
}
- zval_ptr_dtor(retval);
- ZVAL_LONG(retval, timeout->tv_sec);
+ ZEND_TRY_ASSIGN_LONG(retval, timeout->tv_sec);
ldap_memfree(timeout);
} break;
#endif
@@ -3112,8 +3112,7 @@ PHP_FUNCTION(ldap_get_option)
}
RETURN_FALSE;
}
- zval_ptr_dtor(retval);
- ZVAL_STRING(retval, val);
+ ZEND_TRY_ASSIGN_STRING(retval, val);
ldap_memfree(val);
} break;
case LDAP_OPT_SERVER_CONTROLS:
@@ -3333,7 +3332,7 @@ PHP_FUNCTION(ldap_parse_result)
char *lmatcheddn, *lerrmsg;
int rc, lerrcode, myargcount = ZEND_NUM_ARGS();
- if (zend_parse_parameters(myargcount, "rrz/|z/z/z/z/", &link, &result, &errcode, &matcheddn, &errmsg, &referrals, &serverctrls) != SUCCESS) {
+ if (zend_parse_parameters(myargcount, "rrz|zzzz", &link, &result, &errcode, &matcheddn, &errmsg, &referrals, &serverctrls) != SUCCESS) {
return;
}
@@ -3356,16 +3355,17 @@ PHP_FUNCTION(ldap_parse_result)
RETURN_FALSE;
}
- zval_ptr_dtor(errcode);
- ZVAL_LONG(errcode, lerrcode);
+ ZEND_TRY_ASSIGN_LONG(errcode, lerrcode);
/* Reverse -> fall through */
switch (myargcount) {
case 7:
_php_ldap_controls_to_array(ld->link, lserverctrls, serverctrls, 0);
case 6:
- zval_ptr_dtor(referrals);
- array_init(referrals);
+ referrals = zend_try_array_init(referrals);
+ if (!referrals) {
+ return;
+ }
if (lreferrals != NULL) {
refp = lreferrals;
while (*refp) {
@@ -3375,19 +3375,17 @@ PHP_FUNCTION(ldap_parse_result)
ldap_memvfree((void**)lreferrals);
}
case 5:
- zval_ptr_dtor(errmsg);
if (lerrmsg == NULL) {
- ZVAL_EMPTY_STRING(errmsg);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(errmsg);
} else {
- ZVAL_STRING(errmsg, lerrmsg);
+ ZEND_TRY_ASSIGN_STRING(errmsg, lerrmsg);
ldap_memfree(lerrmsg);
}
case 4:
- zval_ptr_dtor(matcheddn);
if (lmatcheddn == NULL) {
- ZVAL_EMPTY_STRING(matcheddn);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(matcheddn);
} else {
- ZVAL_STRING(matcheddn, lmatcheddn);
+ ZEND_TRY_ASSIGN_STRING(matcheddn, lmatcheddn);
ldap_memfree(lmatcheddn);
}
}
@@ -3398,7 +3396,7 @@ PHP_FUNCTION(ldap_parse_result)
/* {{{ Extended operation response parsing, Pierangelo Masarati */
#ifdef HAVE_LDAP_PARSE_EXTENDED_RESULT
-/* {{{ proto bool ldap_parse_exop(resource link, resource result [, string retdata [, string retoid]])
+/* {{{ proto bool ldap_parse_exop(resource link, resource result [, string &retdata [, string &retoid]])
Extract information from extended operation result */
PHP_FUNCTION(ldap_parse_exop)
{
@@ -3409,7 +3407,7 @@ PHP_FUNCTION(ldap_parse_exop)
struct berval *lretdata;
int rc, myargcount = ZEND_NUM_ARGS();
- if (zend_parse_parameters(myargcount, "rr|z/z/", &link, &result, &retdata, &retoid) != SUCCESS) {
+ if (zend_parse_parameters(myargcount, "rr|zz", &link, &result, &retdata, &retoid) != SUCCESS) {
WRONG_PARAM_COUNT;
}
@@ -3433,20 +3431,18 @@ PHP_FUNCTION(ldap_parse_exop)
/* Reverse -> fall through */
switch (myargcount) {
case 4:
- zval_ptr_dtor(retoid);
if (lretoid == NULL) {
- ZVAL_EMPTY_STRING(retoid);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(retoid);
} else {
- ZVAL_STRING(retoid, lretoid);
+ ZEND_TRY_ASSIGN_STRING(retoid, lretoid);
ldap_memfree(lretoid);
}
case 3:
/* use arg #3 as the data returned by the server */
- zval_ptr_dtor(retdata);
if (lretdata == NULL) {
- ZVAL_EMPTY_STRING(retdata);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(retdata);
} else {
- ZVAL_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
+ ZEND_TRY_ASSIGN_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
ldap_memfree(lretdata->bv_val);
ldap_memfree(lretdata);
}
@@ -3524,7 +3520,7 @@ PHP_FUNCTION(ldap_next_reference)
/* }}} */
#ifdef HAVE_LDAP_PARSE_REFERENCE
-/* {{{ proto bool ldap_parse_reference(resource link, resource reference_entry, array referrals)
+/* {{{ proto bool ldap_parse_reference(resource link, resource reference_entry, array &referrals)
Extract information from reference entry */
PHP_FUNCTION(ldap_parse_reference)
{
@@ -3533,7 +3529,7 @@ PHP_FUNCTION(ldap_parse_reference)
ldap_resultentry *resultentry;
char **lreferrals, **refp;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrz/", &link, &result_entry, &referrals) != SUCCESS) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrz", &link, &result_entry, &referrals) != SUCCESS) {
return;
}
@@ -3549,8 +3545,11 @@ PHP_FUNCTION(ldap_parse_reference)
RETURN_FALSE;
}
- zval_ptr_dtor(referrals);
- array_init(referrals);
+ referrals = zend_try_array_init(referrals);
+ if (!referrals) {
+ return;
+ }
+
if (lreferrals != NULL) {
refp = lreferrals;
while (*refp) {
@@ -4015,7 +4014,7 @@ PHP_FUNCTION(ldap_control_paged_result_response)
ber_tag_t tag;
int rc, lerrcode, myargcount = ZEND_NUM_ARGS();
- if (zend_parse_parameters(myargcount, "rr|z/z/", &link, &result, &cookie, &estimated) != SUCCESS) {
+ if (zend_parse_parameters(myargcount, "rr|zz", &link, &result, &cookie, &estimated) != SUCCESS) {
return;
}
@@ -4082,15 +4081,13 @@ PHP_FUNCTION(ldap_control_paged_result_response)
ldap_controls_free(lserverctrls);
if (myargcount == 4) {
- zval_ptr_dtor(estimated);
- ZVAL_LONG(estimated, lestimated);
+ ZEND_TRY_ASSIGN_LONG(estimated, lestimated);
}
- zval_ptr_dtor(cookie);
if (lcookie.bv_len == 0) {
- ZVAL_EMPTY_STRING(cookie);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(cookie);
} else {
- ZVAL_STRINGL(cookie, lcookie.bv_val, lcookie.bv_len);
+ ZEND_TRY_ASSIGN_STRINGL(cookie, lcookie.bv_val, lcookie.bv_len);
}
ldap_memfree(lcookie.bv_val);
@@ -4115,7 +4112,7 @@ PHP_FUNCTION(ldap_exop)
LDAPControl **lserverctrls = NULL;
int rc, msgid;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|S!a!z/z/", &link, &reqoid, &reqdata, &serverctrls, &retdata, &retoid) != SUCCESS) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|S!a!zz", &link, &reqoid, &reqdata, &serverctrls, &retdata, &retoid) != SUCCESS) {
return;
}
@@ -4153,22 +4150,20 @@ PHP_FUNCTION(ldap_exop)
}
if (retoid) {
- zval_ptr_dtor(retoid);
if (lretoid) {
- ZVAL_STRING(retoid, lretoid);
+ ZEND_TRY_ASSIGN_STRING(retoid, lretoid);
ldap_memfree(lretoid);
} else {
- ZVAL_EMPTY_STRING(retoid);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(retoid);
}
}
- zval_ptr_dtor(retdata);
if (lretdata) {
- ZVAL_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
+ ZEND_TRY_ASSIGN_STRINGL(retdata, lretdata->bv_val, lretdata->bv_len);
ldap_memfree(lretdata->bv_val);
ldap_memfree(lretdata);
} else {
- ZVAL_EMPTY_STRING(retdata);
+ ZEND_TRY_ASSIGN_EMPTY_STRING(retdata);
}
RETVAL_TRUE;
@@ -4219,7 +4214,7 @@ PHP_FUNCTION(ldap_exop_passwd)
int rc, myargcount = ZEND_NUM_ARGS(), msgid, err;
char* errmsg;
- if (zend_parse_parameters(myargcount, "r|zzzz/", &link, &user, &oldpw, &newpw, &serverctrls) == FAILURE) {
+ if (zend_parse_parameters(myargcount, "r|zzzz", &link, &user, &oldpw, &newpw, &serverctrls) == FAILURE) {
WRONG_PARAM_COUNT;
}