6198 Let's EOL cachefs
[illumos-gate.git] / usr / src / man / man3ldap / ldap_sort.3ldap
blobe6a623a8f8833bb79641770d764a36d50d7f8cd1
1 '\" te
2 .\" Copyright (C) 1990, Regents of the University of Michigan.  All Rights Reserved.
3 .\" Portions Copyright (C) 2002, Sun Microsystems, Inc. All Rights Reserved.
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH LDAP_SORT 3LDAP "Jan 27, 2002"
8 .SH NAME
9 ldap_sort, ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp \- LDAP
10 entry sorting functions
11 .SH SYNOPSIS
12 .LP
13 .nf
14 cc[ \fIflag\fR... ] \fIfile\fR... -lldap[ \fIlibrary\fR... ]
15 #include <lber.h>
16 #include <ldap.h>
18 \fB\fR\fBldap_sort_entries\fR(\fBLDAP\fR \fI*ld\fR, \fBLDAPMessage\fR \fI**chain\fR, \fBchar\fR \fI*attr\fR,
19      \fBint (\fR\fI*cmp\fR)());
20 .fi
22 .LP
23 .nf
24 \fB\fR\fBldap_sort_values\fR(\fBLDAP\fR \fI*ld\fR, \fBchar\fR \fI**vals\fR, \fBint (\fR\fI*cmp\fR)());
25 .fi
27 .LP
28 .nf
29 \fB\fR\fBldap_sort_strcasecmp\fR(\fBchar\fR \fI*a\fR, \fBchar\fR \fI*b\fR);
30 .fi
32 .SH DESCRIPTION
33 .sp
34 .LP
35 These functions are used to sort lists of entries and values retrieved from an
36 LDAP server. \fBldap_sort_entries()\fR is used to sort a chain of entries
37 retrieved from an LDAP search call either by DN or by some arbitrary attribute
38 in the entries.  It takes  \fIld\fR, the LDAP structure, which is only used for
39 error reporting,  \fIchain\fR, the list of entries as returned by
40 \fBldap_search_s\fR(3LDAP) or \fBldap_result\fR(3LDAP). \fIattr\fR is the
41 attribute to use as a key in the sort or NULL to sort by DN, and  \fIcmp\fR is
42 the comparison function to use when comparing values (or individual DN
43 components if sorting by DN). In this case,  \fIcmp\fR should be a function
44 taking two single values of the  \fIattr\fR to sort by, and returning a value
45 less than zero, equal to zero, or greater than zero, depending on whether the
46 first argument is less than, equal to, or greater than the second argument. The
47 convention is the same as used by \fBqsort\fR(3C), which is called to do the
48 actual sorting.
49 .sp
50 .LP
51 \fBldap_sort_values()\fR is used to sort an array of values from an entry, as
52 returned by \fBldap_get_values\fR(3LDAP). It takes the LDAP connection
53 structure  \fIld\fR, the array of values to sort  \fIvals\fR, and  \fIcmp\fR,
54 the comparison function to use during the sort. Note that  \fIcmp\fR will be
55 passed a pointer to each element in the \fIvals\fR array, so if you pass the
56 normal char ** for this parameter, \fIcmp\fR should take two char **'s as
57 arguments (that is, you cannot pass  \fIstrcasecmp\fR or its friends for
58 \fIcmp\fR). You can, however, pass the function \fBldap_sort_strcasecmp()\fR
59 for this purpose.
60 .sp
61 .LP
62 For example:
63 .sp
64 .in +2
65 .nf
66         LDAP *ld;
67         LDAPMessage *res;
68         /* ... call to ldap_search_s(\|), fill in res, retrieve sn attr ... */
70         /* now sort the entries on surname attribute */
71         if ( ldap_sort_entries( ld, &res, "sn", ldap_sort_strcasecmp ) != 0 )
72                 ldap_perror( ld, "ldap_sort_entries" );
73 .fi
74 .in -2
76 .SH ATTRIBUTES
77 .sp
78 .LP
79 See \fBattributes\fR(5) for a description of the following attributes:
80 .sp
82 .sp
83 .TS
84 box;
85 c | c
86 l | l .
87 ATTRIBUTE TYPE  ATTRIBUTE VALUE
88 Interface Stability     Evolving
89 .TE
91 .SH SEE ALSO
92 .sp
93 .LP
94 \fBldap\fR(3LDAP), \fBldap_search\fR(3LDAP), \fBldap_result\fR(3LDAP),
95 \fBqsort\fR(3C), \fBattributes\fR(5)
96 .SH NOTES
97 .sp
98 .LP
99 The \fBldap_sort_entries()\fR function applies the comparison function to each
100 value of the attribute in the array as returned by a call to
101 \fBldap_get_values\fR(3LDAP), until a mismatch is found. This works fine for
102 single-valued attributes, but may produce unexpected results for multi-valued
103 attributes. When sorting by DN, the comparison function is applied to an
104 exploded version of the DN, without types. The return values for all of these
105 functions are declared in the <\fBldap.h\fR> header file.  Some functions may
106 allocate memory which must be freed by the calling application.