Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
sort.c File Reference
#include "ldap-int.h"

Go to the source code of this file.

Classes

struct  keycmp
struct  keything
struct  entrything

Defines

#define XP_QSORT   qsort

Typedefs

typedef struct keycmp keycmp_t
typedef struct keything keything_t
typedef char *typedef int (LDAP_C LDAP_CALLBACK LDAP_VOIDCMP_CALLBACK)(const void *
typedef char *typedef const
void *static
LDAP_CHARCMP_CALLBACK * 
et_cmp_fn

Functions

static int LDAP_C LDAP_CALLBACK ldapi_keycmp (const void *Lv, const void *Rv)
int LDAP_CALL ldap_keysort_entries (LDAP *ld, LDAPMessage **chain, void *arg, LDAP_KEYGEN_CALLBACK *gen, LDAP_KEYCMP_CALLBACK *cmp, LDAP_KEYFREE_CALLBACK *fre)
typedef int (LDAP_C LDAP_CALLBACK LDAP_CHARCMP_CALLBACK)(char *
int LDAP_C LDAP_CALLBACK ldap_sort_strcasecmp (const char **a, const char **b)
static int LDAP_C LDAP_CALLBACK et_cmp (const void *aa, const void *bb)
int LDAP_CALL ldap_multisort_entries (LDAP *ld, LDAPMessage **chain, char **attr, LDAP_CMP_CALLBACK *cmp)
int LDAP_CALL ldap_sort_entries (LDAP *ld, LDAPMessage **chain, char *attr, LDAP_CMP_CALLBACK *cmp)
int LDAP_CALL ldap_sort_values (LDAP *ld, char **vals, LDAP_VALCMP_CALLBACK *cmp)

Variables

static LDAP_VOIDCMP_CALLBACK et_cmp

Class Documentation

struct keycmp

Definition at line 67 of file sort.c.

Class Members
void * kc_arg
LDAP_KEYCMP_CALLBACK * kc_cmp
struct keything

Definition at line 72 of file sort.c.

Collaboration diagram for keything:
Class Members
keycmp_t * kt_cmp
struct berval * kt_key
LDAPMessage * kt_msg
struct entrything

Definition at line 148 of file sort.c.

Class Members
LDAPMessage * et_msg
char ** et_vals

Define Documentation

#define XP_QSORT   qsort

Definition at line 64 of file sort.c.


Typedef Documentation

typedef char* typedef const void* static LDAP_CHARCMP_CALLBACK* et_cmp_fn [static]

Definition at line 155 of file sort.c.

typedef char* typedef int(LDAP_C LDAP_CALLBACK LDAP_VOIDCMP_CALLBACK)(const void *

Definition at line 154 of file sort.c.

typedef struct keycmp keycmp_t
typedef struct keything keything_t

Function Documentation

static int LDAP_C LDAP_CALLBACK et_cmp ( const void aa,
const void bb 
) [static]

Definition at line 180 of file sort.c.

{
       int                  i, rc;
       struct entrything    *a = (struct entrything *)aa;
       struct entrything    *b = (struct entrything *)bb;

       if ( a->et_vals == NULL && b->et_vals == NULL )
              return( 0 );
       if ( a->et_vals == NULL )
              return( -1 );
       if ( b->et_vals == NULL )
              return( 1 );

       for ( i = 0; a->et_vals[i] && b->et_vals[i]; i++ ) {
              if ( (rc = (*et_cmp_fn)( a->et_vals[i], b->et_vals[i] ))
                  != 0 ) {
                     return( rc );
              }
       }

       if ( a->et_vals[i] == NULL && b->et_vals[i] == NULL )
              return( 0 );
       if ( a->et_vals[i] == NULL )
              return( -1 );
       return( 1 );
}
typedef int ( LDAP_C LDAP_CALLBACK  LDAP_CHARCMP_CALLBACK)
int LDAP_CALL ldap_keysort_entries ( LDAP *  ld,
LDAPMessage **  chain,
void arg,
LDAP_KEYGEN_CALLBACK gen,
LDAP_KEYCMP_CALLBACK *  cmp,
LDAP_KEYFREE_CALLBACK *  fre 
)

Definition at line 89 of file sort.c.

{
       size_t        count, i;
       keycmp_t      kc = {0};
       keything_t    **kt;
       LDAPMessage   *e, *last;
       LDAPMessage   **ep;

       if ( !NSLDAPI_VALID_LDAP_POINTER( ld )
           || chain == NULL || cmp == NULL ) {
              return( LDAP_PARAM_ERROR );
       }

       count = ldap_count_entries( ld, *chain );

       kt = (keything_t**)NSLDAPI_MALLOC( count * (sizeof(keything_t*) + sizeof(keything_t)) );
       if ( kt == NULL ) {
              LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
              return( -1 );
       }
       for ( i = 0; i < count; i++ ) {
              kt[i] = i + (keything_t*)(kt + count);
       }
       kc.kc_arg = arg;
       kc.kc_cmp = cmp;

       for ( e = *chain, i = 0; i < count; i++, e = e->lm_chain ) {
              kt[i]->kt_msg = e;
              kt[i]->kt_cmp = &kc;
              kt[i]->kt_key = gen( arg, ld, e );
              if ( kt[i]->kt_key == NULL ) {
                     if ( fre ) while ( i-- > 0 ) fre( arg, kt[i]->kt_key );
                     NSLDAPI_FREE( (char*)kt );
                     LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
                     return( -1 );
              }
       }
       last = e;

       XP_QSORT( (void*)kt, count, (size_t)sizeof(keything_t*), ldapi_keycmp );
    
       ep = chain;
       for ( i = 0; i < count; i++ ) {
              *ep = kt[i]->kt_msg;
              ep = &(*ep)->lm_chain;
              if ( fre ) fre( arg, kt[i]->kt_key );
       }
       *ep = last;
       NSLDAPI_FREE( (char*)kt );
       return( 0 );
}

Here is the call graph for this function:

int LDAP_CALL ldap_multisort_entries ( LDAP *  ld,
LDAPMessage **  chain,
char **  attr,
LDAP_CMP_CALLBACK *  cmp 
)

Definition at line 212 of file sort.c.

{
       int                  i, count;
       struct entrything    *et;
       LDAPMessage          *e, *last;
       LDAPMessage          **ep;

       if ( !NSLDAPI_VALID_LDAP_POINTER( ld )
           || chain == NULL || cmp == NULL ) {
              return( LDAP_PARAM_ERROR );
       }

       count = ldap_count_entries( ld, *chain );

       if ( (et = (struct entrything *)NSLDAPI_MALLOC( count *
           sizeof(struct entrything) )) == NULL ) {
              LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
              return( -1 );
       }

       e = *chain;
       for ( i = 0; i < count; i++ ) {
              et[i].et_msg = e;
              et[i].et_vals = NULL;
              if ( attr == NULL ) {
                     char   *dn;

                     dn = ldap_get_dn( ld, e );
                     et[i].et_vals = ldap_explode_dn( dn, 1 );
                     NSLDAPI_FREE( dn );
              } else {
                     int    attrcnt;
                     char   **vals;

                     for ( attrcnt = 0; attr[attrcnt] != NULL; attrcnt++ ) {
                         vals = ldap_get_values( ld, e, attr[attrcnt] );
                         if ( ldap_charray_merge( &(et[i].et_vals), vals )
                            != 0 ) {
                            int    j;

                            /* XXX risky: ldap_value_free( vals ); */
                            for ( j = 0; j <= i; j++ )
                                ldap_value_free( et[j].et_vals );
                            NSLDAPI_FREE( (char *) et );
                            LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, 
                                NULL );
                            return( -1 );
                         }
                         if ( vals != NULL ) {
                            NSLDAPI_FREE( (char *)vals );
                         }
                     }
              }

              e = e->lm_chain;
       }
       last = e;

       et_cmp_fn = (LDAP_CHARCMP_CALLBACK *)cmp;
       XP_QSORT( (void *) et, (size_t) count,
              (size_t) sizeof(struct entrything), et_cmp );

       ep = chain;
       for ( i = 0; i < count; i++ ) {
              *ep = et[i].et_msg;
              ep = &(*ep)->lm_chain;

              ldap_value_free( et[i].et_vals );
       }
       *ep = last;
       NSLDAPI_FREE( (char *) et );

       return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_sort_entries ( LDAP *  ld,
LDAPMessage **  chain,
char *  attr,
LDAP_CMP_CALLBACK *  cmp 
)

Definition at line 294 of file sort.c.

{
       char   *attrs[2];

       attrs[0] = attr;
       attrs[1] = NULL;
       return( ldap_multisort_entries( ld, chain, attr ? attrs : NULL, cmp ) );
}

Here is the call graph for this function:

int LDAP_C LDAP_CALLBACK ldap_sort_strcasecmp ( const char **  a,
const char **  b 
)

Definition at line 163 of file sort.c.

{
    /* XXXceb
     * I am not 100% sure this is the way this should be handled.  
     * For now we will return a 0 on invalid.
     */    
    if (NULL == a || NULL == b)
        return (0);
       return( strcasecmp( (char *)*a, (char *)*b ) );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_sort_values ( LDAP *  ld,
char **  vals,
LDAP_VALCMP_CALLBACK *  cmp 
)

Definition at line 310 of file sort.c.

{
       int    nel;

       if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) || cmp == NULL ) {
              return( LDAP_PARAM_ERROR );
       }

    if ( NULL == vals) 
    {
              LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
              return( LDAP_PARAM_ERROR );
       }
       for ( nel = 0; vals[nel] != NULL; nel++ )
              ;      /* NULL */

       XP_QSORT( vals, nel, sizeof(char *), (LDAP_VOIDCMP_CALLBACK *)cmp );

       return( LDAP_SUCCESS );
}

Here is the caller graph for this function:

static int LDAP_C LDAP_CALLBACK ldapi_keycmp ( const void Lv,
const void Rv 
) [static]

Definition at line 79 of file sort.c.

{
    auto keything_t **L = (keything_t**)Lv;
    auto keything_t **R = (keything_t**)Rv;
    auto keycmp_t *cmp = (*L)->kt_cmp;
    return cmp->kc_cmp( cmp->kc_arg, (*L)->kt_key, (*R)->kt_key );
}

Here is the caller graph for this function:


Variable Documentation

LDAP_VOIDCMP_CALLBACK et_cmp [static]

Definition at line 158 of file sort.c.