1ldap_sort(3LDAP)            LDAP Library Functions            ldap_sort(3LDAP)
2
3
4

NAME

6       ldap_sort,  ldap_sort_entries, ldap_sort_values, ldap_sort_strcasecmp -
7       LDAP entry sorting functions
8

SYNOPSIS

10       cc[ flag... ] file... -lldap[ library... ]
11       #include <lber.h>
12       #include <ldap.h>
13
14       ldap_sort_entries(LDAP *ld, LDAPMessage **chain, char *attr,
15            int (*cmp)());
16
17
18       ldap_sort_values(LDAP *ld, char **vals, int (*cmp)());
19
20
21       ldap_sort_strcasecmp(char *a, char *b);
22
23

DESCRIPTION

25       These functions are used to sort lists of entries and values  retrieved
26       from  an  LDAP  server.  ldap_sort_entries() is used to sort a chain of
27       entries retrieved from an LDAP search call either  by  DN  or  by  some
28       arbitrary  attribute in the entries.  It takes  ld, the LDAP structure,
29       which is only used for error reporting,  chain, the list of entries  as
30       returned  by  ldap_search_s(3LDAP)  or  ldap_result(3LDAP). attr is the
31       attribute to use as a key in the sort or NULL to sort by DN,  and   cmp
32       is  the comparison function to use when comparing values (or individual
33       DN components if sorting by DN). In this case,  cmp should be  a  func‐
34       tion  taking two single values of the  attr to sort by, and returning a
35       value less than zero, equal to zero, or greater than zero, depending on
36       whether  the first argument is less than, equal to, or greater than the
37       second argument. The convention is the same as used by qsort(3C), which
38       is called to do the actual sorting.
39
40
41       ldap_sort_values() is used to sort an array of values from an entry, as
42       returned by ldap_get_values(3LDAP). It takes the LDAP connection struc‐
43       ture   ld,  the array of values to sort  vals, and  cmp, the comparison
44       function to use during the sort.  Note  that   cmp  will  be  passed  a
45       pointer  to  each  element in the vals array, so if you pass the normal
46       char ** for this parameter, cmp should take two char **'s as  arguments
47       (that  is,  you  cannot  pass  strcasecmp or its friends for  cmp). You
48       can, however, pass the function ldap_sort_strcasecmp()  for  this  pur‐
49       pose.
50
51
52       For example:
53
54              LDAP *ld;
55              LDAPMessage *res;
56              /* ... call to ldap_search_s(), fill in res, retrieve sn attr ... */
57
58              /* now sort the entries on surname attribute */
59              if ( ldap_sort_entries( ld, &res, "sn", ldap_sort_strcasecmp ) != 0 )
60                   ldap_perror( ld, "ldap_sort_entries" );
61
62

ATTRIBUTES

64       See attributes(5) for a description of the following attributes:
65
66
67
68
69       ┌─────────────────────────────┬─────────────────────────────┐
70       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
71       │Availability                 │SUNWcsl (32-bit)             │
72       │                             │SUNWcslx (64-bit)            │
73       │Interface Stability          │Evolving                     │
74       └─────────────────────────────┴─────────────────────────────┘
75

SEE ALSO

77       ldap(3LDAP),    ldap_search(3LDAP),    ldap_result(3LDAP),   qsort(3C),
78       attributes(5)
79

NOTES

81       The ldap_sort_entries() function applies  the  comparison  function  to
82       each  value  of  the  attribute  in  the array as returned by a call to
83       ldap_get_values(3LDAP), until a mismatch is found. This works fine  for
84       single-valued attributes, but may produce unexpected results for multi-
85       valued attributes. When sorting  by  DN,  the  comparison  function  is
86       applied  to  an  exploded  version of the DN, without types. The return
87       values for all of these functions are declared in the  <ldap.h>  header
88       file.   Some  functions  may allocate memory which must be freed by the
89       calling application.
90
91
92
93SunOS 5.11                        27 Jan 2002                 ldap_sort(3LDAP)
Impressum