Table of Contents | Previous | Next | Index

Netscape Directory SDK 3.0 for C Programmer’s Guide
     Chapter 18 Functions

ldap_sort_entries()

The 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.

Syntax

#include <ldap.h>
int ldap_sort_entries( LDAP *ld, LDAPMessage *chain, char *attr,
   LDAP_CMP_CALLBACK *cmp );

Parameters

This function has the following parameters:

ld

Connection handle, which is a pointer to an LDAP structure containing information about the connection to the LDAP server.

chain

Chain of entries returned by the ldap_result() or ldap_search_s() function.

attr

Attribute to use when sorting the results. To sort by distinguished name instead of by attribute, use NULL.

cmp

Comparison function used when sorting the values. For details, see "Sorting Entries by an Attribute" on page 136.

Returns

One of the following values:

Example

The following section of code sorts entries by the 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 );
}
... 

See Also

ldap_multisort_entries(), ldap_result(), ldap_search_s().


Table of Contents | Previous | Next | Index

Last Updated: 10/01/98 17:06:23