1 .TH LDAP_SORT 3 "RELEASEDATE" "OpenLDAP LDVERSION"
3 .\" Copyright 1998-2002 The OpenLDAP Foundation All Rights Reserved.
4 .\" Copying restrictions apply. See COPYRIGHT/LICENSE.
6 ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp \- LDAP sorting routines
13 ldap_sort_entries(ld, chain, attr, cmp)
21 ldap_sort_values(ld, vals, cmp)
28 ldap_sort_strcasecmp(a, b)
33 These routines are used to sort lists of entries and values retrieved
35 .B ldap_sort_entries()
36 is used to sort a chain
37 of entries retrieved from an LDAP search call either by DN or by some
38 arbitrary attribute in the entries. It takes \fIld\fP, the LDAP
39 structure, which is only used for error reporting, \fIchain\fP, the
40 list of entries as returned by
44 \fIattr\fP is the attribute to use as a key in the sort
45 or NULL to sort by DN, and \fIcmp\fP is the comparison function to use
46 when comparing values (or individual DN components if sorting by DN).
47 In this case, \fIcmp\fP should be a function taking two single values
48 of the \fIattr\fP to sort by, and returning a value less than zero,
49 equal to zero, or greater than zero, depending on whether the first
50 argument is less than, equal to, or greater than the second argument.
51 The convention is the same as used by
53 which is called to do the actual sorting.
56 is used to sort an array of values from an entry,
58 .BR ldap_get_values (3).
59 It takes the LDAP connection
60 structure \fIld\fP, the array of values
61 to sort \fIvals\fP, and \fIcmp\fP, the comparison
62 function to use during the sort.
63 Note that \fIcmp\fP will be passed a pointer to each element in the
64 \fIvals\fP array, so if you pass the normal char ** for this parameter,
65 \fIcmp\fP should take two char **'s as arguments (i.e., you cannot
66 pass \fIstrcasecmp\fP or its friends for \fIcmp\fP). You can, however,
68 .B ldap_sort_strcasecmp()
78 /* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */
80 /* now sort the entries on surname attribute */
81 if ( ldap_sort_entries( ld, &res, "sn", ldap_sort_strcasecmp ) != 0 )
82 ldap_perror( ld, "ldap_sort_entries" );
88 .B ldap_sort_entries()
89 routine applies the comparison function to
90 each value of the attribute in the array as returned by a call to
91 .BR ldap_get_values (3),
92 until a mismatch is found.
93 This works fine for single-valued attributes, but
94 may produce unexpected results for multi-valued attributes.
95 When sorting by DN, the comparison function is
96 applied to an exploded version of the DN, without types.
97 The return values for all of these functions are declared in the
98 <ldap.h> header file. Some routines may dynamically allocate memory.
99 Callers are responsible for freeing such memory using the supplied
100 deallocation routines.
108 is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).
110 is derived from University of Michigan LDAP 3.3 Release.