MAN page from Mandrake Other ldap-devel-3.3-3.i386.rpm
LDAP_SORT
Section: C Library Functions (3)
Updated: 14 November 1994
Index NAME
ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp - LDAP sorting routines
SYNOPSIS
#include <lber.h>#include <ldap.h>ldap_sort_entries(ld, chain, attr, cmp)LDAP *ld;LDAPMessage **chain;char *attr;int (*cmp)();ldap_sort_values(ld, vals, cmp)LDAP *ld;char **vals;int (*cmp)();ldap_sort_strcasecmp(a, b)char *a;char *b;
DESCRIPTION
These routines are used to sort lists of entries and values retrievedfrom an LDAP server.
ldap_sort_entries()is used to sort a chainof entries retrieved from an LDAP search call either by DN or by somearbitrary attribute in the entries. It takes
ld, the LDAPstructure, which is only used for error reporting,
chain, thelist of entries as returned by
ldap_search_s(3)or
ldap_result(3).
attr is the attribute to use as a key in the sortor NULL to sort by DN, and
cmp is the comparison function to usewhen comparing values (or individual DN components if sorting by DN).In this case,
cmp should be a function taking two single valuesof the
attr to sort by, and returning a value less than zero,equal to zero, or greater than zero, depending on whether the firstargument is less than, equal to, or greater than the second argument.The convention is the same as used by
qsort(3),which is called to do the actual sorting.
ldap_sort_values()is used to sort an array of values from an entry,as returned byldap_get_values(3).It takes the LDAP connectionstructure ld, the array of valuesto sort vals, and cmp, the comparisonfunction to use during the sort.Note that cmp will be passed a pointer to each element in thevals array, so if you pass the normal char ** for this parameter,cmp should take two char **'s as arguments (i.e., you cannotpass strcasecmp or its friends for cmp). You can, however,pass the functionldap_sort_strcasecmp()for this purpose.
For example:
LDAP *ld; LDAPMessage *res; /* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */ /* now sort the entries on surname attribute */ if ( ldap_sort_entries( ld, &res, "sn", ldap_sort_strcasecmp ) != 0 ) ldap_perror( ld, "ldap_sort_entries" );
NOTES
Theldap_sort_entries()routine applies the comparison function toeach value of the attribute in the array as returned by a call toldap_get_values(3),until a mismatch is found.This works fine for single-valued attributes, butmay produce unexpected results for multi-valued attributes.When sorting by DN, the comparison function isapplied to an exploded version of the DN, without types.The return values for all of these functions are declared in the<ldap.h> header file. Some routines may malloc memory.
SEE ALSO
ldap(3),
ldap_search(3),
ldap_result(3),
qsort(3)
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- NOTES
- SEE ALSO
This document was created byman2html,using the manual pages.