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