]> git.sur5r.net Git - openldap/blob - doc/man/man3/ldap_sort.3
Update misleading statement about ldap_init(). It use is actually
[openldap] / doc / man / man3 / ldap_sort.3
1 .TH LDAP_SORT 3 "22 September 1998" "OpenLDAP LDVERSION"
2 .SH NAME
3 ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp \- LDAP sorting routines
4 .SH SYNOPSIS
5 .nf
6 .ft B
7 #include <lber.h>
8 #include <ldap.h>
9 .LP
10 .ft B
11 ldap_sort_entries(ld, chain, attr, cmp)
12 .ft
13 LDAP *ld;
14 LDAPMessage **chain;
15 char *attr;
16 int (*cmp)();
17 .LP
18 .ft B
19 ldap_sort_values(ld, vals, cmp)
20 .ft
21 LDAP *ld;
22 char **vals;
23 int (*cmp)();
24 .LP
25 .ft B
26 ldap_sort_strcasecmp(a, b)
27 .ft
28 char *a;
29 char *b;
30 .SH DESCRIPTION
31 These routines are used to sort lists of entries and values retrieved
32 from an LDAP server.
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
39 .BR ldap_search_s (3)
40 or
41 .BR ldap_result (3).
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
50 .BR qsort (3),
51 which is called to do the actual sorting.
52 .LP
53 .B ldap_sort_values()
54 is used to sort an array of values from an entry,
55 as returned by
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,
65 pass the function
66 .B ldap_sort_strcasecmp()
67 for this purpose.
68 .LP
69 For example:
70 .LP
71 .nf
72 .ft tt
73         LDAP *ld;
74         LDAPMessage *res;
75
76         /* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */
77
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" );
81 .ft
82 .fi
83 .SH NOTES
84 .LP
85 The
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 dynamically allocate memory.
97 Callers are responsible for freeing such memory using the supplied
98 deallocation routines.
99 .SH SEE ALSO
100 .BR ldap (3),
101 .BR ldap_search (3),
102 .BR ldap_result (3),
103 .BR qsort (3)
104 .SH ACKNOWLEDGEMENTS
105 .B      OpenLDAP
106 is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).
107 .B      OpenLDAP
108 is derived from University of Michigan LDAP 3.3 Release.