Table of Contents | Previous | Next | Index

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

ldap_sort_values()

The ldap_sort_values() function sorts an array of values retrieved from an ldap_get_values() call.

For additional information, see "Sorting the Search Results" on page 135.

Syntax

#include <ldap.h>
int ldap_sort_values( LDAP *ld, char **vals,
   LDAP_VALCMP_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.

vals

The array of values to sort.

cmp

Comparison function used when sorting the values.

In the ldap_sort_values() function, the comparison function must pass (char **) parameters. Because of this, you need to use the ldap_sort_strcasecmp() function, rather than a function like strcasecmp().

Returns

One of the following values:

Example

The following section of code sorts the values of attributes before printing them.

#include <stdio.h>
#include <string.h>
#include <ldap.h>
...
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
char *a, *dn;
char **vals;
int i;
char *my_searchbase = "o=Airius.com";
char *my_filter = "(sn=Jensen)";
...
      if ( ( vals = ldap_get_values( ld, e, a ) ) != NULL ) {
         /* Sort the values of the attribute */
         if ( ldap_sort_values( ld, vals, strcasecmp ) ) != LDAP_SUCCESS ) {
            ldap_perror( ld, "ldap_sort_values" );
            return( 1 );
         }
         /* Print the values of the attribute */
         for ( i = 0; vals[i] != NULL; i++ ) {
            printf( "%s: %s\n", a, vals[i] );
         }
         /* Free the values from memory */
         ldap_value_free( vals );
      }
...

See Also

ldap_get_values(), ldap_sort_strcasecmp().


Table of Contents | Previous | Next | Index

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