ext/ldap: Add API parsing zval to LDAP value

This commit is contained in:
Gina Peter Banyard 2024-10-02 13:32:58 +01:00
parent 9709887815
commit 495837bfa9

View file

@ -234,6 +234,26 @@ static void ldap_result_entry_free_obj(zend_object *obj)
} \ } \
} }
/* An LDAP value must be a string, however it defines a format for integer and
* booleans, thus we parse zvals to the corresponding string if possible
* See RFC 4517: https://datatracker.ietf.org/doc/html/rfc4517 */
static zend_string* php_ldap_try_get_ldap_value_from_zval(zval *zv) {
switch (Z_TYPE_P(zv)) {
case IS_STRING:
case IS_LONG:
/* Object might be stringable */
case IS_OBJECT:
return zval_try_get_string(zv);
case IS_TRUE:
return ZSTR_INIT_LITERAL("TRUE", false);
case IS_FALSE:
return ZSTR_INIT_LITERAL("FALSE", false);
default:
zend_type_error("LDAP value must be of type string|int|bool, %s given", zend_zval_value_name(zv));
return NULL;
}
}
/* {{{ Parse controls from and to arrays */ /* {{{ Parse controls from and to arrays */
static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array, int request) static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array, int request)
{ {