]> git.sur5r.net Git - openldap/blob - doc/man/man3/ldap_sort.3
3d451e55ff5a1b4d89b6a9c11effee486404d783
[openldap] / doc / man / man3 / ldap_sort.3
1 .TH LDAP_SORT 3 "22 September 1998" "OpenLDAP LDVERSION"
2 .\" $OpenLDAP$
3 .\" Copyright 1998-2000 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 SYNOPSIS
8 .nf
9 .ft B
10 #include <ldap.h>
11 .LP
12 .ft B
13 ldap_sort_entries(ld, chain, attr, cmp)
14 .ft
15 LDAP *ld;
16 LDAPMessage **chain;
17 char *attr;
18 int (*cmp)();
19 .LP
20 .ft B
21 ldap_sort_values(ld, vals, cmp)
22 .ft
23 LDAP *ld;
24 char **vals;
25 int (*cmp)();
26 .LP
27 .ft B
28 ldap_sort_strcasecmp(a, b)
29 .ft
30 char *a;
31 char *b;
32 .SH DESCRIPTION
33 These routines are used to sort lists of entries and values retrieved
34 from an LDAP server.
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
41 .BR ldap_search_s (3)
42 or
43 .BR ldap_result (3).
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
52 .BR qsort (3),
53 which is called to do the actual sorting.
54 .LP
55 .B ldap_sort_values()
56 is used to sort an array of values from an entry,
57 as returned by
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,
67 pass the function
68 .B ldap_sort_strcasecmp()
69 for this purpose.
70 .LP
71 For example:
72 .LP
73 .nf
74 .ft tt
75         LDAP *ld;
76         LDAPMessage *res;
77
78         /* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */
79
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" );
83 .ft
84 .fi
85 .SH NOTES
86 .LP
87 The
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.
101 .SH SEE ALSO
102 .BR ldap (3),
103 .BR ldap_search (3),
104 .BR ldap_result (3),
105 .BR qsort (3)
106 .SH ACKNOWLEDGEMENTS
107 .B      OpenLDAP
108 is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).
109 .B      OpenLDAP
110 is derived from University of Michigan LDAP 3.3 Release.