Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
srchpref.c File Reference
#include "ldap-int.h"
#include "srchpref.h"

Go to the source code of this file.

Functions

int nsldapi_next_line_tokens (char **bufp, long *blenp, char ***toksp)
void nsldapi_free_strarray (char **sap)
static void free_searchobj (struct ldap_searchobj *so)
static int read_next_searchobj (char **bufp, long *blenp, struct ldap_searchobj **sop, int soversion)
int LDAP_CALL ldap_init_searchprefs (char *file, struct ldap_searchobj **solistp)
int LDAP_CALL ldap_init_searchprefs_buf (char *buf, long buflen, struct ldap_searchobj **solistp)
void LDAP_CALL ldap_free_searchprefs (struct ldap_searchobj *solist)
struct ldap_searchobj *LDAP_CALL ldap_first_searchobj (struct ldap_searchobj *solist)
struct ldap_searchobj *LDAP_CALL ldap_next_searchobj (struct ldap_searchobj *solist, struct ldap_searchobj *so)

Variables

static char * sobjoptions []
static unsigned long sobjoptvals []

Function Documentation

static void free_searchobj ( struct ldap_searchobj so) [static]

Definition at line 179 of file srchpref.c.

{
    if ( so != NULL ) {
       if ( so->so_objtypeprompt != NULL ) {
           NSLDAPI_FREE(  so->so_objtypeprompt );
       }
       if ( so->so_prompt != NULL ) {
           NSLDAPI_FREE(  so->so_prompt );
       }
       if ( so->so_filterprefix != NULL ) {
           NSLDAPI_FREE(  so->so_filterprefix );
       }
       if ( so->so_filtertag != NULL ) {
           NSLDAPI_FREE(  so->so_filtertag );
       }
       if ( so->so_defaultselectattr != NULL ) {
           NSLDAPI_FREE(  so->so_defaultselectattr );
       }
       if ( so->so_defaultselecttext != NULL ) {
           NSLDAPI_FREE(  so->so_defaultselecttext );
       }
       if ( so->so_salist != NULL ) {
           struct ldap_searchattr *sa, *nextsa;
           for ( sa = so->so_salist; sa != NULL; sa = nextsa ) {
              nextsa = sa->sa_next;
              if ( sa->sa_attrlabel != NULL ) {
                  NSLDAPI_FREE( sa->sa_attrlabel );
              }
              if ( sa->sa_attr != NULL ) {
                  NSLDAPI_FREE( sa->sa_attr );
              }
              if ( sa->sa_selectattr != NULL ) {
                  NSLDAPI_FREE( sa->sa_selectattr );
              }
              if ( sa->sa_selecttext != NULL ) {
                  NSLDAPI_FREE( sa->sa_selecttext );
              }
              NSLDAPI_FREE( sa );
           }
       }
       if ( so->so_smlist != NULL ) {
           struct ldap_searchmatch *sm, *nextsm;
           for ( sm = so->so_smlist; sm != NULL; sm = nextsm ) {
              nextsm = sm->sm_next;
              if ( sm->sm_matchprompt != NULL ) {
                  NSLDAPI_FREE( sm->sm_matchprompt );
              }
              if ( sm->sm_filter != NULL ) {
                  NSLDAPI_FREE( sm->sm_filter );
              }
              NSLDAPI_FREE( sm );
           }
       }
       NSLDAPI_FREE( so );
    }
}

Here is the caller graph for this function:

struct ldap_searchobj* LDAP_CALL ldap_first_searchobj ( struct ldap_searchobj solist) [read]

Definition at line 240 of file srchpref.c.

{
    return( solist );
}

Here is the caller graph for this function:

Definition at line 164 of file srchpref.c.

{
    struct ldap_searchobj   *so, *nextso;

    if ( solist != NULL ) {
       for ( so = solist; so != NULL; so = nextso ) {
           nextso = so->so_next;
           free_searchobj( so );
       }
    }
    /* XXX XXX need to do some work here */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_init_searchprefs ( char *  file,
struct ldap_searchobj **  solistp 
)

Definition at line 76 of file srchpref.c.

{
    FILE      *fp;
    char      *buf;
    long      rlen, len;
    int              rc, eof;

    if (( fp = fopen( file, "r" )) == NULL ) {
       return( LDAP_SEARCHPREF_ERR_FILE );
    }

    if ( fseek( fp, 0L, SEEK_END ) != 0 ) {      /* move to end to get len */
       fclose( fp );
       return( LDAP_SEARCHPREF_ERR_FILE );
    }

    len = ftell( fp );

    if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {      /* back to start of file */
       fclose( fp );
       return( LDAP_SEARCHPREF_ERR_FILE );
    }

    if (( buf = NSLDAPI_MALLOC( (size_t)len )) == NULL ) {
       fclose( fp );
       return( LDAP_SEARCHPREF_ERR_MEM );
    }

    rlen = fread( buf, 1, (size_t)len, fp );
    eof = feof( fp );
    fclose( fp );

    if ( rlen != len && !eof ) {   /* error:  didn't get the whole file */
       NSLDAPI_FREE( buf );
       return( LDAP_SEARCHPREF_ERR_FILE );
    }

    rc = ldap_init_searchprefs_buf( buf, rlen, solistp );
    NSLDAPI_FREE( buf );

    return( rc );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int LDAP_CALL ldap_init_searchprefs_buf ( char *  buf,
long  buflen,
struct ldap_searchobj **  solistp 
)

Definition at line 122 of file srchpref.c.

{
    int                            rc = 0, version;
    char                    **toks;
    struct ldap_searchobj   *prevso, *so;

    *solistp = prevso = NULLSEARCHOBJ;

    if ( nsldapi_next_line_tokens( &buf, &buflen, &toks ) != 2 ||
           strcasecmp( toks[ 0 ], "version" ) != 0 ) {
       nsldapi_free_strarray( toks );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    version = atoi( toks[ 1 ] );
    nsldapi_free_strarray( toks );
    if ( version != LDAP_SEARCHPREF_VERSION &&
           version != LDAP_SEARCHPREF_VERSION_ZERO ) {
       return( LDAP_SEARCHPREF_ERR_VERSION );
    }

    while ( buflen > 0 && ( rc = read_next_searchobj( &buf, &buflen, &so,
           version )) == 0 && so != NULLSEARCHOBJ ) {
       if ( prevso == NULLSEARCHOBJ ) {
           *solistp = so;
       } else {
           prevso->so_next = so;
       }
       prevso = so;
    }

    if ( rc != 0 ) {
       ldap_free_searchprefs( *solistp );
    }

    return( rc );
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct ldap_searchobj* LDAP_CALL ldap_next_searchobj ( struct ldap_searchobj solist,
struct ldap_searchobj so 
) [read]

Definition at line 248 of file srchpref.c.

{
    return( so == NULLSEARCHOBJ ? so : so->so_next );
}

Here is the caller graph for this function:

void nsldapi_free_strarray ( char **  sap)

Definition at line 217 of file dsparse.c.

{
    int              i;

    if ( sap != NULL ) {
       for ( i = 0; sap[ i ] != NULL; ++i ) {
           NSLDAPI_FREE( sap[ i ] );
       }
       NSLDAPI_FREE( (char *)sap );
    }
}
int nsldapi_next_line_tokens ( char **  bufp,
long blenp,
char ***  toksp 
)

Definition at line 60 of file dsparse.c.

{
    char      *p, *line, *token, **toks;
    int              rc, tokcnt;

    *toksp = NULL;

    if (( rc = next_line( bufp, blenp, &line )) <= 0 ) {
       return( rc );
    }

    if (( toks = (char **)NSLDAPI_CALLOC( 1, sizeof( char * ))) == NULL ) {
       NSLDAPI_FREE( line );
       return( -1 );
    }
    tokcnt = 0;

    p = line;
    while (( token = next_token( &p )) != NULL ) {
       if (( toks = (char **)NSLDAPI_REALLOC( toks, ( tokcnt + 2 ) *
              sizeof( char * ))) == NULL ) {
           NSLDAPI_FREE( (char *)toks );
           NSLDAPI_FREE( line );
           return( -1 );
       }
       toks[ tokcnt ] = token;
       toks[ ++tokcnt ] = NULL;
    }

    if ( tokcnt == 1 && strcasecmp( toks[ 0 ], "END" ) == 0 ) {
       tokcnt = 0;
       nsldapi_free_strarray( toks );
       toks = NULL;
    }

    NSLDAPI_FREE( line );

    if ( tokcnt == 0 ) {
       if ( toks != NULL ) {
           NSLDAPI_FREE( (char *)toks );
       }
    } else {
       *toksp = toks;
    }

    return( tokcnt );
}

Here is the call graph for this function:

static int read_next_searchobj ( char **  bufp,
long blenp,
struct ldap_searchobj **  sop,
int  soversion 
) [static]

Definition at line 256 of file srchpref.c.

{
    int                            i, j, tokcnt;
    char                    **toks;
    struct ldap_searchobj   *so;
    struct ldap_searchattr  **sa;
    struct ldap_searchmatch **sm;

    *sop = NULL;

    /*
     * Object type prompt comes first
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       return( tokcnt == 0 ? 0 : LDAP_SEARCHPREF_ERR_SYNTAX );
    }

    if (( so = (struct ldap_searchobj *)NSLDAPI_CALLOC( 1,
           sizeof( struct ldap_searchobj ))) == NULL ) {
       nsldapi_free_strarray( toks );
       return(  LDAP_SEARCHPREF_ERR_MEM );
    }
    so->so_objtypeprompt = toks[ 0 ];
    NSLDAPI_FREE( (char *)toks );

    /*
     * if this is post-version zero, options come next
     */
    if ( soversion > LDAP_SEARCHPREF_VERSION_ZERO ) {
       if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) < 1 ) {
           nsldapi_free_strarray( toks );
           ldap_free_searchprefs( so );
           return( LDAP_SEARCHPREF_ERR_SYNTAX );
       }
       for ( i = 0; toks[ i ] != NULL; ++i ) {
           for ( j = 0; sobjoptions[ j ] != NULL; ++j ) {
              if ( strcasecmp( toks[ i ], sobjoptions[ j ] ) == 0 ) {
                  so->so_options |= sobjoptvals[ j ];
              }
           }
       }
       nsldapi_free_strarray( toks );
    }

    /*
     * "Fewer choices" prompt is next
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    so->so_prompt = toks[ 0 ];
    NSLDAPI_FREE( (char *)toks );

    /*
     * Filter prefix for "More Choices" searching is next
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    so->so_filterprefix = toks[ 0 ];
    NSLDAPI_FREE( (char *)toks );

    /*
     * "Fewer Choices" filter tag comes next
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    so->so_filtertag = toks[ 0 ];
    NSLDAPI_FREE( (char *)toks );

    /*
     * Selection (disambiguation) attribute comes next
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    so->so_defaultselectattr = toks[ 0 ];
    NSLDAPI_FREE( (char *)toks );

    /*
     * Label for selection (disambiguation) attribute
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    so->so_defaultselecttext = toks[ 0 ];
    NSLDAPI_FREE( (char *)toks );

    /*
     * Search scope is next
     */
    if (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
       nsldapi_free_strarray( toks );
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    if ( !strcasecmp(toks[ 0 ], "subtree" )) {
       so->so_defaultscope = LDAP_SCOPE_SUBTREE;
    } else if ( !strcasecmp(toks[ 0 ], "onelevel" )) {
       so->so_defaultscope = LDAP_SCOPE_ONELEVEL;
    } else if ( !strcasecmp(toks[ 0 ], "base" )) {
       so->so_defaultscope = LDAP_SCOPE_BASE;
    } else {
       ldap_free_searchprefs( so );
       return( LDAP_SEARCHPREF_ERR_SYNTAX );
    }
    nsldapi_free_strarray( toks );


    /*
     * "More Choices" search option list comes next
     */
    sa = &( so->so_salist );
    while (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
       if ( tokcnt < 5 ) {
           nsldapi_free_strarray( toks );
           ldap_free_searchprefs( so );
           return( LDAP_SEARCHPREF_ERR_SYNTAX );
       }
       if (( *sa = ( struct ldap_searchattr * )NSLDAPI_CALLOC( 1,
              sizeof( struct ldap_searchattr ))) == NULL ) {
           nsldapi_free_strarray( toks );
           ldap_free_searchprefs( so );
           return(  LDAP_SEARCHPREF_ERR_MEM );
       }
       ( *sa )->sa_attrlabel = toks[ 0 ];
       ( *sa )->sa_attr = toks[ 1 ];
       ( *sa )->sa_selectattr = toks[ 3 ];
       ( *sa )->sa_selecttext = toks[ 4 ];
       /* Deal with bitmap */
       ( *sa )->sa_matchtypebitmap = 0;
       for ( i = strlen( toks[ 2 ] ) - 1, j = 0; i >= 0; i--, j++ ) {
           if ( toks[ 2 ][ i ] == '1' ) {
              ( *sa )->sa_matchtypebitmap |= (1 << j);
           }
       }
       NSLDAPI_FREE( toks[ 2 ] );
       NSLDAPI_FREE( ( char * ) toks );
       sa = &(( *sa )->sa_next);
    }
    *sa = NULL;

    /*
     * Match types are last
     */
    sm = &( so->so_smlist );
    while (( tokcnt = nsldapi_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
       if ( tokcnt < 2 ) {
           nsldapi_free_strarray( toks );
           ldap_free_searchprefs( so );
           return( LDAP_SEARCHPREF_ERR_SYNTAX );
       }
       if (( *sm = ( struct ldap_searchmatch * )NSLDAPI_CALLOC( 1,
              sizeof( struct ldap_searchmatch ))) == NULL ) {
           nsldapi_free_strarray( toks );
           ldap_free_searchprefs( so );
           return(  LDAP_SEARCHPREF_ERR_MEM );
       }
       ( *sm )->sm_matchprompt = toks[ 0 ];
       ( *sm )->sm_filter = toks[ 1 ];
       NSLDAPI_FREE( ( char * ) toks );
       sm = &(( *sm )->sm_next );
    }
    *sm = NULL;

    *sop = so;
    return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char* sobjoptions[] [static]
Initial value:
 {
    "internal",
    NULL
}

Definition at line 63 of file srchpref.c.

unsigned long sobjoptvals[] [static]
Initial value:

Definition at line 69 of file srchpref.c.