Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
ldif.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define LDIF_VERSION_ONE   1 /* LDIF standard version */
#define LDIF_MAX_LINE_WIDTH   76 /* maximum length of LDIF lines */
#define LDIF_BASE64_LEN(vlen)   (((vlen) * 4 / 3 ) + 3)
#define LDIF_SIZE_NEEDED(tlen, vlen)
#define LDIF_OPT_NOWRAP   0x01UL
#define LDIF_OPT_VALUE_IS_URL   0x02UL
#define LDIF_OPT_MINIMAL_ENCODING   0x04UL

Functions

int ldif_parse_line (char *line, char **type, char **value, int *vlen)
char * ldif_getline (char **next)
void ldif_put_type_and_value (char **out, char *t, char *val, int vlen)
void ldif_put_type_and_value_nowrap (char **out, char *t, char *val, int vlen)
void ldif_put_type_and_value_with_options (char **out, char *t, char *val, int vlen, unsigned long options)
char * ldif_type_and_value (char *type, char *val, int vlen)
char * ldif_type_and_value_nowrap (char *type, char *val, int vlen)
char * ldif_type_and_value_with_options (char *type, char *val, int vlen, unsigned long options)
int ldif_base64_decode (char *src, unsigned char *dst)
int ldif_base64_encode (unsigned char *src, char *dst, int srclen, int lenused)
int ldif_base64_encode_nowrap (unsigned char *src, char *dst, int srclen, int lenused)
char * ldif_get_entry (FILE *fp, int *lineno)

Define Documentation

#define LDIF_BASE64_LEN (   vlen)    (((vlen) * 4 / 3 ) + 3)

Definition at line 66 of file ldif.h.

#define LDIF_MAX_LINE_WIDTH   76 /* maximum length of LDIF lines */

Definition at line 59 of file ldif.h.

Definition at line 84 of file ldif.h.

#define LDIF_OPT_NOWRAP   0x01UL

Definition at line 82 of file ldif.h.

Definition at line 83 of file ldif.h.

#define LDIF_SIZE_NEEDED (   tlen,
  vlen 
)
Value:
((tlen) + 4 + LDIF_BASE64_LEN(vlen) \
    + ((LDIF_BASE64_LEN(vlen) + tlen + 3) / LDIF_MAX_LINE_WIDTH * 2 ))

Definition at line 74 of file ldif.h.

#define LDIF_VERSION_ONE   1 /* LDIF standard version */

Definition at line 57 of file ldif.h.


Function Documentation

int ldif_base64_decode ( char *  src,
unsigned char *  dst 
)

Definition at line 211 of file line64.c.

{
       char          *p, *stop;
       unsigned char nib, *byte;
       int           i, len;

       stop = strchr( src, '\0' );
       byte = dst;
       for ( p = src, len = 0; p < stop; p += 4, len += 3 ) {
              for ( i = 0; i < 4; i++ ) {
                     if ( p[i] != '=' && (p[i] & 0x80 ||
                         b642nib[ p[i] & 0x7f ] > 0x3f) ) {
                            return( -1 );
                     }
              }

              /* first digit */
              nib = b642nib[ p[0] & 0x7f ];
              byte[0] = nib << 2;

              /* second digit */
              nib = b642nib[ p[1] & 0x7f ];
              byte[0] |= nib >> 4;

              /* third digit */
              if ( p[2] == '=' ) {
                     len += 1;
                     break;
              }
              byte[1] = (nib & RIGHT4) << 4;
              nib = b642nib[ p[2] & 0x7f ];
              byte[1] |= nib >> 2;

              /* fourth digit */
              if ( p[3] == '=' ) {
                     len += 2;
                     break;
              }
              byte[2] = (nib & RIGHT2) << 6;
              nib = b642nib[ p[3] & 0x7f ];
              byte[2] |= nib;

              byte += 3;
       }

       return( len );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ldif_base64_encode ( unsigned char *  src,
char *  dst,
int  srclen,
int  lenused 
)

Definition at line 504 of file line64.c.

{
    return ldif_base64_encode_internal( src, dst, srclen, lenused, LDIF_MAX_LINE_WIDTH );
}

Here is the call graph for this function:

int ldif_base64_encode_nowrap ( unsigned char *  src,
char *  dst,
int  srclen,
int  lenused 
)

Definition at line 510 of file line64.c.

{
    return ldif_base64_encode_internal( src, dst, srclen, lenused, -1 );
}

Here is the call graph for this function:

char* ldif_get_entry ( FILE fp,
int lineno 
)

Definition at line 555 of file line64.c.

{
       char   line[BUFSIZ];
       char   *buf;
       int    max, cur, len, gotsome;

       buf = NULL;
       max = cur = gotsome = 0;
       while ( fgets( line, sizeof(line), fp ) != NULL ) {
              if ( lineno != NULL ) {
                     (*lineno)++;
              }
              /* ldif entries are terminated by a \n on a line by itself */
              if ( line[0] == '\0' || line[0] == '\n'
#if !defined( XP_WIN32 )
                   || ( line[0] == '\r' && line[1] == '\n' ) /* DOS format */
#endif
                 ) {
                     if ( gotsome ) {
                            break;
                     } else {
                            continue;
                     }
              } else if ( line[0] == '#' ) {
                     continue;
              }
              gotsome = 1;
              len = strlen( line );
#if !defined( XP_WIN32 )
              /* DOS format */
              if ( len > 0 && line[len-1] == '\r' ) {
                     --len;
                     line[len] = '\0';
              } else if ( len > 1 && line[len-2] == '\r' && line[len-1] == '\n' ) {
                     --len;
                     line[len-1] = line[len];
                     line[len] = '\0';
              }
#endif
              while ( cur + (len + 1) > max ) {
                     if ( buf == NULL ) {
                            max += BUFSIZ;
                            buf = (char *) malloc( max );
                     } else {
                            max *= 2;
                            buf = (char *) realloc( buf, max );
                     }
                     if ( buf == NULL ) {
                            return( NULL );
                     }
              }

              memcpy( buf + cur, line, len + 1 );
              cur += len;
       }

       return( buf );
}

Here is the call graph for this function:

char* ldif_getline ( char **  next)

Definition at line 277 of file line64.c.

{
       char   *l;
       char   c;
       char   *p;

       if ( *next == NULL || **next == '\n' || **next == '\0' ) {
              return( NULL );
       }

       while ( **next == '#' ) {   /* skip comment lines */
              if (( *next = strchr( *next, '\n' )) == NULL ) {
                     return( NULL );
              }
              (*next)++;
       }

       l = *next;
       while ( (*next = strchr( *next, '\n' )) != NULL ) {
              p = *next - 1; /* pointer to character previous to the newline */
              c = *(*next + 1); /* character after the newline */
              if ( ISBLANK( c ) && c != '\n' ) {
                     /* DOS EOL is \r\n, so if the character before */
                     /* the \n is \r, continue it too */
                     if (*p == '\r')
                            *p = CONTINUED_LINE_MARKER;
                     **next = CONTINUED_LINE_MARKER;
                     *(*next+1) = CONTINUED_LINE_MARKER;
              } else {
                     /* DOS EOL is \r\n, so if the character before */
                     /* the \n is \r, null it too */
                     if (*p == '\r')
                            *p = '\0';
                     *(*next)++ = '\0';
                     break;
              }
              (*next)++;
       }

       return( l );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ldif_parse_line ( char *  line,
char **  type,
char **  value,
int vlen 
)

Definition at line 100 of file line64.c.

{
       char   *p, *s, *d;
       int    b64;

       /* skip any leading space */
       while ( ISBLANK( *line ) ) {
              line++;
       }
       *type = line;

       for ( s = line; *s && *s != ':'; s++ )
              ;      /* NULL */
       if ( *s == '\0' ) {

              /* Comment-out while we address calling libldif from ns-back-ldbm
                     on NT. 1 of 3 */
#if defined( _WIN32 )
              /*
#endif
               LDAPDebug( LDAP_DEBUG_PARSE, "ldif_parse_line: missing ':' "
                     "on line \"%s\"\n", line, 0, 0 ); 
#if defined( _WIN32 )
              */
#endif
              return( -1 );
       }

       /* trim any space between type and : */
       for ( p = s - 1; p > line && ISBLANK( *p ); p-- ) {
              *p = '\0';
       }
       *s++ = '\0';

       /* check for double : - indicates base 64 encoded value */
       if ( *s == ':' ) {
              s++;
              b64 = 1;

       /* single : - normally encoded value */
       } else {
              b64 = 0;
       }

       /* skip space between : and value */
       while ( ISBLANK( *s ) ) {
              s++;
       }

       /* 
        * If no value is present, return a zero-length string for
        * *value, with *vlen set to zero.
        */
       if ( *s == '\0' ) {
              *value = s;
              *vlen = 0;
              return( 0 );
       }

       /* check for continued line markers that should be deleted */
       for ( p = s, d = s; *p; p++ ) {
              if ( *p != CONTINUED_LINE_MARKER )
                     *d++ = *p;
       }
       *d = '\0';

       *value = s;
       if ( b64 ) {
              if (( *vlen = ldif_base64_decode( s, (unsigned char *)s ))
                  < 0 ) {
                     /* Comment-out while we address calling libldif from ns-back-ldbm
                            on NT. 3 of 3 */
#if defined( _WIN32 )
              /*
#endif
                      LDAPDebug( LDAP_DEBUG_ANY,
                         "ldif_parse_line: invalid base 64 char on line \"%s\"\n",
                         line, 0, 0 ); 
#if defined( _WIN32 )
              */
#endif
                     return( -1 );
              }
              s[ *vlen ] = '\0';
       } else {
              *vlen = (int) (d - s);
       }

       return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ldif_put_type_and_value ( char **  out,
char *  t,
char *  val,
int  vlen 
)

Definition at line 411 of file line64.c.

Here is the call graph for this function:

void ldif_put_type_and_value_nowrap ( char **  out,
char *  t,
char *  val,
int  vlen 
)

Definition at line 417 of file line64.c.

Here is the call graph for this function:

void ldif_put_type_and_value_with_options ( char **  out,
char *  t,
char *  val,
int  vlen,
unsigned long  options 
)

Definition at line 331 of file line64.c.

{
       unsigned char *p, *byte, *stop;
       char          *save;
       int           b64, len, savelen, wraplen;
       len = 0;

       if ( LDIF_OPT_ISSET( options, LDIF_OPT_NOWRAP )) {
              wraplen = -1;
       } else {
              wraplen = LDIF_MAX_LINE_WIDTH;
       }

       /* put the type + ": " */
       for ( p = (unsigned char *) t; *p; p++, len++ ) {
              *(*out)++ = *p;
       }
       *(*out)++ = ':';
       len++;
       if ( LDIF_OPT_ISSET( options, LDIF_OPT_VALUE_IS_URL )) {
              *(*out)++ = '<';     /* add '<' for URLs */
              len++;
       }
       save = *out;
       savelen = len;
       b64 = 0;

       stop = (unsigned char *)val;
       if ( val && vlen > 0 ) {
              *(*out)++ = ' ';
              stop = (unsigned char *) (val + vlen);
              if ( LDIF_OPT_ISSET( options, LDIF_OPT_MINIMAL_ENCODING )) {
                     if ( !LDIF_SAFE_INITCHAR( val[0] )) {
                            b64 = 1;
                     }
              } else {
                     if ( !LDIF_CONSERVATIVE_INITCHAR( val[0] ) ||
                             !LDIF_CONSERVATIVE_FINALCHAR( val[vlen-1] )) {
                            b64 = 1;
                     }
              }
       }

       if ( !b64 ) {
              for ( byte = (unsigned char *) val; byte < stop;
                  byte++, len++ ) {
                     if ( LDIF_OPT_ISSET( options,
                         LDIF_OPT_MINIMAL_ENCODING )) {
                            if ( !LDIF_SAFE_CHAR( *byte )) {
                                   b64 = 1;
                                   break;
                            }
                     } else if ( !LDIF_CONSERVATIVE_CHAR( *byte )) {
                            b64 = 1;
                            break;
                     }
                     
                     if ( wraplen != -1 && len > wraplen ) {
                            *(*out)++ = '\n';
                            *(*out)++ = ' ';
                            len = 1;
                     }
                     *(*out)++ = *byte;
              }
       }

       if ( b64 ) {
              *out = save;
              *(*out)++ = ':';
              *(*out)++ = ' ';
              len = ldif_base64_encode_internal( (unsigned char *)val, *out, vlen,
                  savelen + 2, wraplen );
              *out += len;
       }

       *(*out)++ = '\n';
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* ldif_type_and_value ( char *  type,
char *  val,
int  vlen 
)

Definition at line 538 of file line64.c.

{
    return ldif_type_and_value_with_options( type, val, vlen, 0 );
}

Here is the call graph for this function:

char* ldif_type_and_value_nowrap ( char *  type,
char *  val,
int  vlen 
)

Definition at line 544 of file line64.c.

Here is the call graph for this function:

char* ldif_type_and_value_with_options ( char *  type,
char *  val,
int  vlen,
unsigned long  options 
)

Definition at line 520 of file line64.c.

{
    char      *buf, *p;
    int              tlen;

    tlen = strlen( type );
    if (( buf = (char *)malloc( LDIF_SIZE_NEEDED( tlen, vlen ) + 1 )) !=
           NULL ) {
       p = buf;
       ldif_put_type_and_value_with_options( &p, type, val, vlen, options );
       *p = '\0';
    }

    return( buf );
}

Here is the call graph for this function:

Here is the caller graph for this function: