diff options
| -rw-r--r-- | ext/ldap/ldap.c | 31 | ||||
| -rw-r--r-- | ext/ldap/php_ldap.h | 2 | 
2 files changed, 33 insertions, 0 deletions
| diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index b8794fadfd..0415fb9566 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -99,6 +99,7 @@ function_entry ldap_functions[] = {  	PHP_FE(ldap_err2str,								NULL)  	PHP_FE(ldap_error,									NULL)  	PHP_FE(ldap_compare,								NULL) +	PHP_FE(ldap_sort,									NULL)  #if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP  	PHP_FE(ldap_get_option,			third_argument_force_ref) @@ -1532,6 +1533,36 @@ PHP_FUNCTION(ldap_compare)  }  /* }}} */ +/* {{{ proto int ldap_sort(int link, int result, string sortfilter) +   Sort LDAP result entries */ +PHP_FUNCTION(ldap_sort) +{ +	zval *link, *result; +	LDAP *ldap; +	char *sortfilter; +	int sflen; +	zend_rsrc_list_entry *le; + +	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rrs", &link, &result, &sortfilter, &sflen) == FAILURE) { +		RETURN_FALSE; +	} + +	ZEND_FETCH_RESOURCE(ldap, LDAP *, &link, -1, "ldap link", le_link); + +	if (zend_hash_index_find(&EG(regular_list), Z_LVAL_P(result), (void **) &le) == FAILURE || le->type != le_result) { +		php_error(E_WARNING, "Supplied resource is not a valid ldap result resource"); +		RETURN_FALSE; +	} + +	if (ldap_sort_entries(ldap, (LDAPMessage **) &le->ptr, sflen ? sortfilter : NULL, strcmp) != LDAP_SUCCESS) { +		php_error(E_WARNING, "LDAP sort failed: %s", ldap_err2string(errno)); +		RETURN_FALSE; +	} + +	RETURN_TRUE; +} +/* }}} */ +  #if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP  /* {{{ proto boolean ldap_get_option(int link, int option, mixed retval) diff --git a/ext/ldap/php_ldap.h b/ext/ldap/php_ldap.h index ab6a2bc98d..1f3d5191c2 100644 --- a/ext/ldap/php_ldap.h +++ b/ext/ldap/php_ldap.h @@ -78,6 +78,8 @@ PHP_FUNCTION(ldap_error);  PHP_FUNCTION(ldap_compare); +PHP_FUNCTION(ldap_sort); +  #if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP  PHP_FUNCTION(ldap_get_option);  PHP_FUNCTION(ldap_set_option); | 
