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