ldap_sort_entries() function sorts a chain of entries retrieved from an LDAP search call (ldap_search_s() or ldap_result()) either by distinguished name (DN) or by a specified attribute in the entries.
For additional information, see "Sorting the Search Results" on page 135.
#include <ldap.h>
int ldap_sort_entries( LDAP *ld, LDAPMessage *chain, char *attr,
LDAP_CMP_CALLBACK *cmp );
ld |
Connection handle, which is a pointer to an |
chain |
Chain of entries returned by the |
attr | |
cmp | Comparison function used when sorting the values. For details, see "Sorting Entries by an Attribute" on page 136. |
LDAP_SUCCESS if successful. LDAP structure. To get the error code, call ldap_get_lderrno(). (See "Result Codes" on page 691 for a complete listing of error codes.) roomNumber attribute.
#include <stdio.h>
#include <string.h>
#include <ldap.h>
LDAP *ld;
LDAPMessage *result;
char *my_searchbase = "o=Airius.com";
char *my_filter = "(sn=Jensen)";
char *sortby = "roomNumber";
...
/* Search the directory */
if ( ldap_search_s( ld, my_searchbase, LDAP_SCOPE_SUBTREE, my_filter, NULL, 0, &result ) != LDAP_SUCCESS ) {ldap_perror( ld, "ldap_search_s" );
return( 1 );
}
/* Sort the results by room number, using strcasecmp */
if ( ldap_sort_entries( ld, &result, sortby, strcasecmp ) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_sort_entries" );
return( 1 );
}
...
ldap_multisort_entries(), ldap_result(), ldap_search_s().
Last Updated: 10/01/98 17:06:23