Seth Woolley's Man Viewer

ldap_sort_entries(3) - ldap_sort_entries, ldap_sort_strcasecmp, ldap_sort_values - LDAP sorting routines - man 3 ldap_sort_entries

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

LDAP_SORT(3)                                                      LDAP_SORT(3)

       ldap_sort_entries,  ldap_sort_values, ldap_sort_strcasecmp - LDAP sort-
       ing routines

       OpenLDAP LDAP (libldap, -lldap)

       #include <ldap.h>

       ldap_sort_entries(ld(1,8), chain, attr(1,5), cmp)
       LDAP *ld(1,8);
       LDAPMessage **chain;
       char *attr(1,5);
       int (*cmp)();

       ldap_sort_values(ld(1,8), vals, cmp)
       LDAP *ld(1,8);
       char **vals;
       int (*cmp)();

       ldap_sort_strcasecmp(a, b)
       char *a;
       char *b;

       These routines are used to sort(1,3) lists of entries and  values  retrieved
       from  an  LDAP  server.  ldap_sort_entries() is used to sort(1,3) a chain of
       entries retrieved from an LDAP search call either  by  DN  or  by  some
       arbitrary  attribute  in(1,8) the entries.  It takes ld(1,8), the LDAP structure,
       which is only used for error(8,n) reporting, chain, the list of  entries  as
       returned  by ldap_search_s(3) or ldap_result(3).  attr(1,5) is the attribute
       to use as a key in(1,8) the sort(1,3) or NULL to sort(1,3) by DN, and cmp is the  com-
       parison  function to use when comparing values (or individual DN compo-
       nents if(3,n) sorting by DN).  In this case, cmp should be a function taking
       two  single  values  of the attr(1,5) to sort(1,3) by, and returning a value less(1,3)
       than zero, equal to zero, or greater than zero,  depending  on  whether
       the  first  argument is less(1,3) than, equal to, or greater than the second
       argument.  The convention is the same as used  by  qsort(3),  which  is
       called to do the actual sorting.

       ldap_sort_values() is used to sort(1,3) an array of values from an entry, as
       returned by ldap_get_values(3).  It takes the LDAP connection structure
       ld(1,8),  the array of values to sort(1,3) vals, and cmp, the comparison function
       to use during the sort.  Note that cmp will be passed a pointer to each
       element  in(1,8)  the vals array, so if(3,n) you pass the normal char ** for this
       parameter, cmp should take two char **'s as arguments (i.e., you cannot
       pass  strcasecmp  or  its friends for cmp).  You can, however, pass the
       function ldap_sort_strcasecmp() for this purpose.

       For example:

            LDAP *ld(1,8);
            LDAPMessage *res;

             * ... call to ldap_search_s(), fill in(1,8) res,
             * retrieve sn attr(1,5) ...

            /* now sort(1,3) the entries on surname attribute */
            if(3,n) ( ldap_sort_entries( ld(1,8), &res, "sn",
                      ldap_sort_strcasecmp ) != 0 )
                 ldap_perror( ld(1,8), "ldap_sort_entries" );

       The ldap_sort_entries() routine applies the comparison function to each
       value  of  the  attribute  in(1,8)  the  array  as  returned  by  a  call to
       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(1,3,5) of the DN, without types.  The return
       values for all of these functions are declared in(1,8) the  <ldap.h>  header
       file.   Some  routines  may  dynamically  allocate memory.  Callers are
       responsible for freeing such memory  using  the  supplied  deallocation

       ldap(3,5,n)(3), ldap_search(3), ldap_result(3), qsort(3)

       OpenLDAP   is   developed   and  maintained  by  The  OpenLDAP  Project
       (  OpenLDAP is  derived  from  University  of
       Michigan LDAP 3.3 Release.

OpenLDAP 2.2.15                   2004/07/27                      LDAP_SORT(3)

References for this manual (incoming links)