]> git.sur5r.net Git - openldap/blob - doc/man/man3/ldap_sort.3
8ef18ed1259f972d5bdb4c1d62c9ac0fcee79d0c
[openldap] / doc / man / man3 / ldap_sort.3
1 .TH LDAP_SORT 3 "RELEASEDATE" "OpenLDAP LDVERSION"
2 .\" $OpenLDAP$
3 .\" Copyright 1998-2003 The OpenLDAP Foundation All Rights Reserved.
4 .\" Copying restrictions apply.  See COPYRIGHT/LICENSE.
5 .SH NAME
6 ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp \- LDAP sorting routines
7 .SH LIBRARY
8 OpenLDAP LDAP (libldap, -lldap)
9 .SH SYNOPSIS
10 .nf
11 .ft B
12 #include <ldap.h>
13 .LP
14 .ft B
15 ldap_sort_entries(ld, chain, attr, cmp)
16 .ft
17 LDAP *ld;
18 LDAPMessage **chain;
19 char *attr;
20 int (*cmp)();
21 .LP
22 .ft B
23 ldap_sort_values(ld, vals, cmp)
24 .ft
25 LDAP *ld;
26 char **vals;
27 int (*cmp)();
28 .LP
29 .ft B
30 ldap_sort_strcasecmp(a, b)
31 .ft
32 char *a;
33 char *b;
34 .SH DESCRIPTION
35 These routines are used to sort lists of entries and values retrieved
36 from an LDAP server.
37 .B ldap_sort_entries()
38 is used to sort a chain
39 of entries retrieved from an LDAP search call either by DN or by some
40 arbitrary attribute in the entries.  It takes \fIld\fP, the LDAP
41 structure, which is only used for error reporting, \fIchain\fP, the
42 list of entries as returned by
43 .BR ldap_search_s (3)
44 or
45 .BR ldap_result (3).
46 \fIattr\fP is the attribute to use as a key in the sort
47 or NULL to sort by DN, and \fIcmp\fP is the comparison function to use
48 when comparing values (or individual DN components if sorting by DN).
49 In this case, \fIcmp\fP should be a function taking two single values
50 of the \fIattr\fP to sort by, and returning a value less than zero,
51 equal to zero, or greater than zero, depending on whether the first
52 argument is less than, equal to, or greater than the second argument.
53 The convention is the same as used by
54 .BR qsort (3),
55 which is called to do the actual sorting.
56 .LP
57 .B ldap_sort_values()
58 is used to sort an array of values from an entry,
59 as returned by
60 .BR ldap_get_values (3).
61 It takes the LDAP connection
62 structure \fIld\fP, the array of values
63 to sort \fIvals\fP, and \fIcmp\fP, the comparison
64 function to use during the sort.
65 Note that \fIcmp\fP will be passed a pointer to each element in the
66 \fIvals\fP array, so if you pass the normal char ** for this parameter,
67 \fIcmp\fP should take two char **'s as arguments (i.e., you cannot
68 pass \fIstrcasecmp\fP or its friends for \fIcmp\fP).  You can, however,
69 pass the function
70 .B ldap_sort_strcasecmp()
71 for this purpose.
72 .LP
73 For example:
74 .LP
75 .nf
76 .ft tt
77         LDAP *ld;
78         LDAPMessage *res;
79
80         /* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */
81
82         /* now sort the entries on surname attribute */
83         if ( ldap_sort_entries( ld, &res, "sn", ldap_sort_strcasecmp ) != 0 )
84                 ldap_perror( ld, "ldap_sort_entries" );
85 .ft
86 .fi
87 .SH NOTES
88 .LP
89 The
90 .B ldap_sort_entries()
91 routine applies the comparison function to
92 each value of the attribute in the array as returned by a call to
93 .BR ldap_get_values (3),
94 until a mismatch is found.
95 This works fine for single-valued attributes, but
96 may produce unexpected results for multi-valued attributes.
97 When sorting by DN, the comparison function is
98 applied to an exploded version of the DN, without types.
99 The return values for all of these functions are declared in the
100 <ldap.h> header file.  Some routines may dynamically allocate memory.
101 Callers are responsible for freeing such memory using the supplied
102 deallocation routines.
103 .SH SEE ALSO
104 .BR ldap (3),
105 .BR ldap_search (3),
106 .BR ldap_result (3),
107 .BR qsort (3)
108 .SH ACKNOWLEDGEMENTS
109 .B      OpenLDAP
110 is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).
111 .B      OpenLDAP
112 is derived from University of Michigan LDAP 3.3 Release.