diff options
author | Sterling Hughes <sterling@php.net> | 2000-04-07 23:20:22 +0000 |
---|---|---|
committer | Sterling Hughes <sterling@php.net> | 2000-04-07 23:20:22 +0000 |
commit | cd3305a2d10740ff6d7c54e4fba62c05af12078d (patch) | |
tree | d27ac09beaa5383dd14b496f5819b970ca3b040e | |
parent | a0ba44495980e76c4bdad7590bdbb02b7e3c257b (diff) | |
download | php-git-cd3305a2d10740ff6d7c54e4fba62c05af12078d.tar.gz |
@-Added ldap_get_values_len function from PHP3 to PHP4. (Sterling)
-rw-r--r-- | ext/ldap/ldap.c | 53 | ||||
-rw-r--r-- | ext/ldap/php_ldap.h | 1 |
2 files changed, 54 insertions, 0 deletions
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; i<num_values; i++) { + add_next_index_string(return_value, ldap_value_len[i]->bv_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); |