Back to index

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

Go to the source code of this file.

Functions

static int next_line (char **bufp, long *blenp, char **linep)
static char * next_token (char **sp)
int nsldapi_next_line_tokens (char **bufp, long *blenp, char ***toksp)
void nsldapi_free_strarray (char **sap)

Function Documentation

static int next_line ( char **  bufp,
long blenp,
char **  linep 
) [static]

Definition at line 110 of file dsparse.c.

{
    char      *linestart, *line, *p;
    long      plen;

    linestart = *bufp;
    p = *bufp;
    plen = *blenp;

    do {
       for ( linestart = p; plen > 0; ++p, --plen ) {
           if ( *p == '\r' ) {
              if ( plen > 1 && *(p+1) == '\n' ) {
                  ++p;
                  --plen;
              }
              break;
           }

           if ( *p == '\n' ) {
              if ( plen > 1 && *(p+1) == '\r' ) {
                  ++p;
                  --plen;
              }
              break;
           }
       }
       ++p;
       --plen;
    } while ( plen > 0 && ( *linestart == '#' || linestart + 1 == p ));


    *bufp = p;
    *blenp = plen;


    if ( plen <= 0 ) {
       *linep = NULL;
       return( 0 );  /* end of file */
    }

    if (( line = NSLDAPI_MALLOC( p - linestart )) == NULL ) {
       *linep = NULL;
       return( -1 ); /* fatal error */
    }

    SAFEMEMCPY( line, linestart, p - linestart );
    line[ p - linestart - 1 ] = '\0';
    *linep = line;
    return( strlen( line ));
}

Here is the caller graph for this function:

static char * next_token ( char **  sp) [static]

Definition at line 164 of file dsparse.c.

{
    int              in_quote = 0;
    char      *p, *tokstart, *t;

    if ( **sp == '\0' ) {
       return( NULL );
    }

    p = *sp;

    while ( ldap_utf8isspace( p )) {             /* skip leading white space */
       ++p;
    }

    if ( *p == '\0' ) {
       return( NULL );
    }

    if ( *p == '\"' ) {
       in_quote = 1;
       ++p;
    }
    t = tokstart = p;

    for ( ;; ) {
       if ( *p == '\0' || ( ldap_utf8isspace( p ) && !in_quote )) {
           if ( *p != '\0' ) {
              ++p;
           }
           *t++ = '\0';            /* end of token */
           break;
       }

       if ( *p == '\"' ) {
           in_quote = !in_quote;
           ++p;
       } else {
           *t++ = *p++;
       }
    }

    *sp = p;

    if ( t == tokstart ) {
       return( NULL );
    }

    return( nsldapi_strdup( tokstart ));
}

Here is the call graph for this function:

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 );
    }
}

Here is the caller graph for this function:

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:

Here is the caller graph for this function: