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