2002-06-13 11:59:10 +08:00
|
|
|
.TH LDAP_SORT 3 "RELEASEDATE" "OpenLDAP LDVERSION"
|
1999-09-12 12:41:47 +08:00
|
|
|
.\" $OpenLDAP$
|
2004-01-02 03:15:16 +08:00
|
|
|
.\" Copyright 1998-2004 The OpenLDAP Foundation All Rights Reserved.
|
1999-09-12 12:41:47 +08:00
|
|
|
.\" Copying restrictions apply. See COPYRIGHT/LICENSE.
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH NAME
|
|
|
|
ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp \- LDAP sorting routines
|
2002-06-21 15:32:54 +08:00
|
|
|
.SH LIBRARY
|
2002-06-22 05:25:38 +08:00
|
|
|
OpenLDAP LDAP (libldap, -lldap)
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.ft B
|
|
|
|
#include <ldap.h>
|
|
|
|
.LP
|
|
|
|
.ft B
|
|
|
|
ldap_sort_entries(ld, chain, attr, cmp)
|
|
|
|
.ft
|
|
|
|
LDAP *ld;
|
|
|
|
LDAPMessage **chain;
|
|
|
|
char *attr;
|
|
|
|
int (*cmp)();
|
|
|
|
.LP
|
|
|
|
.ft B
|
|
|
|
ldap_sort_values(ld, vals, cmp)
|
|
|
|
.ft
|
|
|
|
LDAP *ld;
|
|
|
|
char **vals;
|
|
|
|
int (*cmp)();
|
|
|
|
.LP
|
|
|
|
.ft B
|
|
|
|
ldap_sort_strcasecmp(a, b)
|
|
|
|
.ft
|
|
|
|
char *a;
|
|
|
|
char *b;
|
|
|
|
.SH DESCRIPTION
|
|
|
|
These routines are used to sort lists of entries and values retrieved
|
|
|
|
from an LDAP server.
|
|
|
|
.B ldap_sort_entries()
|
|
|
|
is used to sort a chain
|
|
|
|
of entries retrieved from an LDAP search call either by DN or by some
|
|
|
|
arbitrary attribute in the entries. It takes \fIld\fP, the LDAP
|
|
|
|
structure, which is only used for error reporting, \fIchain\fP, the
|
|
|
|
list of entries as returned by
|
|
|
|
.BR ldap_search_s (3)
|
|
|
|
or
|
|
|
|
.BR ldap_result (3).
|
|
|
|
\fIattr\fP is the attribute to use as a key in the sort
|
|
|
|
or NULL to sort by DN, and \fIcmp\fP is the comparison function to use
|
|
|
|
when comparing values (or individual DN components if sorting by DN).
|
|
|
|
In this case, \fIcmp\fP should be a function taking two single values
|
|
|
|
of the \fIattr\fP to sort by, and returning a value less than zero,
|
|
|
|
equal to zero, or greater than zero, depending on whether the first
|
|
|
|
argument is less than, equal to, or greater than the second argument.
|
|
|
|
The convention is the same as used by
|
|
|
|
.BR qsort (3),
|
|
|
|
which is called to do the actual sorting.
|
|
|
|
.LP
|
|
|
|
.B ldap_sort_values()
|
|
|
|
is used to sort an array of values from an entry,
|
|
|
|
as returned by
|
|
|
|
.BR ldap_get_values (3).
|
|
|
|
It takes the LDAP connection
|
|
|
|
structure \fIld\fP, the array of values
|
|
|
|
to sort \fIvals\fP, and \fIcmp\fP, the comparison
|
|
|
|
function to use during the sort.
|
|
|
|
Note that \fIcmp\fP will be passed a pointer to each element in the
|
|
|
|
\fIvals\fP array, so if you pass the normal char ** for this parameter,
|
|
|
|
\fIcmp\fP should take two char **'s as arguments (i.e., you cannot
|
|
|
|
pass \fIstrcasecmp\fP or its friends for \fIcmp\fP). You can, however,
|
|
|
|
pass the function
|
|
|
|
.B ldap_sort_strcasecmp()
|
|
|
|
for this purpose.
|
|
|
|
.LP
|
|
|
|
For example:
|
|
|
|
.LP
|
|
|
|
.nf
|
|
|
|
.ft tt
|
|
|
|
LDAP *ld;
|
|
|
|
LDAPMessage *res;
|
|
|
|
|
2003-06-29 23:34:32 +08:00
|
|
|
/*
|
|
|
|
* ... call to ldap_search_s(), fill in res,
|
|
|
|
* retrieve sn attr ...
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/* now sort the entries on surname attribute */
|
2003-06-29 23:34:32 +08:00
|
|
|
if ( ldap_sort_entries( ld, &res, "sn",
|
|
|
|
ldap_sort_strcasecmp ) != 0 )
|
1998-08-09 08:43:13 +08:00
|
|
|
ldap_perror( ld, "ldap_sort_entries" );
|
|
|
|
.ft
|
|
|
|
.fi
|
|
|
|
.SH NOTES
|
|
|
|
.LP
|
|
|
|
The
|
|
|
|
.B ldap_sort_entries()
|
|
|
|
routine applies the comparison function to
|
|
|
|
each value of the attribute in the array as returned by a call to
|
|
|
|
.BR ldap_get_values (3),
|
|
|
|
until a mismatch is found.
|
|
|
|
This works fine for single-valued attributes, but
|
|
|
|
may produce unexpected results for multi-valued attributes.
|
|
|
|
When sorting by DN, the comparison function is
|
|
|
|
applied to an exploded version of the DN, without types.
|
|
|
|
The return values for all of these functions are declared in the
|
1998-12-23 03:08:27 +08:00
|
|
|
<ldap.h> header file. Some routines may dynamically allocate memory.
|
|
|
|
Callers are responsible for freeing such memory using the supplied
|
|
|
|
deallocation routines.
|
1998-08-09 08:43:13 +08:00
|
|
|
.SH SEE ALSO
|
|
|
|
.BR ldap (3),
|
|
|
|
.BR ldap_search (3),
|
|
|
|
.BR ldap_result (3),
|
|
|
|
.BR qsort (3)
|
1998-10-25 09:41:42 +08:00
|
|
|
.SH ACKNOWLEDGEMENTS
|
2003-06-29 23:34:32 +08:00
|
|
|
.B OpenLDAP
|
1998-10-25 09:41:42 +08:00
|
|
|
is developed and maintained by The OpenLDAP Project (http://www.openldap.org/).
|
2003-06-29 23:34:32 +08:00
|
|
|
.B OpenLDAP
|
1998-10-25 09:41:42 +08:00
|
|
|
is derived from University of Michigan LDAP 3.3 Release.
|