From: Sterling Hughes Date: Fri, 7 Apr 2000 23:20:22 +0000 (+0000) Subject: @-Added ldap_get_values_len function from PHP3 to PHP4. (Sterling) X-Git-Tag: php-4.0RC2~436 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd3305a2d10740ff6d7c54e4fba62c05af12078d;p=php @-Added ldap_get_values_len function from PHP3 to PHP4. (Sterling) --- diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index 0de522f58e..ae648023ae 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -74,6 +74,7 @@ function_entry ldap_functions[] = { PHP_FE(ldap_next_attribute, NULL) PHP_FE(ldap_get_attributes, NULL) PHP_FE(ldap_get_values, NULL) + PHP_FE(ldap_get_values_len, NULL) PHP_FE(ldap_get_dn, NULL) PHP_FE(ldap_explode_dn, NULL) PHP_FE(ldap_dn2ufn, NULL) @@ -936,6 +937,58 @@ PHP_FUNCTION(ldap_get_values) } /* }}} */ +/* {{{ proto array ldap_get_values_len(int link, int result, string attribute) + Get all values from a result entry */ +PHP_FUNCTION(ldap_get_values_len) +{ + pval **link, **result_entry, **attr; + LDAP* ldap; + LDAPMessage* ldap_result_entry; + char* attribute; + struct berval **ldap_value_len; + int i, num_values; + + if (ARG_COUNT(ht) != 3 || + zend_get_parameters_ex(3, &link, &result_entry, &attr) == FAILURE) { + WRONG_PARAM_COUNT; + } + + if ((ldap = _get_ldap_link(link)) == NULL) { + RETURN_FALSE; + } + + ldap_result_entry = _get_ldap_result_entry(result_entry); + convert_to_string_ex(attr); + attribute = (*attr)->value.str.val; + + if ((ldap_value_len = ldap_get_values_len(ldap, ldap_result_entry, attribute)) == NULL) { +#if !HAVE_NSLDAP +#if LDAP_API_VERSION > 2000 + php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s", ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); +#else + php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s", ldap_err2string(ldap->ld_errno)); +#endif +#else + php_error(E_WARNING, "LDAP: Cannot get the value(s) of attribute %s", ldap_err2string(ldap_get_lderrno(ldap,NULL,NULL))); +#endif + RETURN_FALSE; + } + + num_values = ldap_count_values_len(ldap_value_len); + if (array_init(return_value) == FAILURE) { + php_error(E_ERROR, "Cannot initialize return value"); + RETURN_FALSE; + } + + for (i=0; ibv_val, 1); + } + + add_assoc_long(return_value, "count", num_values); +} +/* }}} */ + + /* {{{ proto string ldap_get_dn(int link, int result) Get the DN of a result entry */ PHP_FUNCTION(ldap_get_dn) diff --git a/ext/ldap/php_ldap.h b/ext/ldap/php_ldap.h index 45b5f45cb5..21afab7a4d 100644 --- a/ext/ldap/php_ldap.h +++ b/ext/ldap/php_ldap.h @@ -69,6 +69,7 @@ PHP_FUNCTION(ldap_next_attribute); PHP_FUNCTION(ldap_get_attributes); PHP_FUNCTION(ldap_get_values); +PHP_FUNCTION(ldap_get_values_len); PHP_FUNCTION(ber_free); PHP_FUNCTION(ldap_get_dn);