#include "portable.h"
#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
+
+#include <ac/stdlib.h>
+#include <ac/ctype.h>
#include <ac/string.h>
#include <ac/socket.h>
int ldif_debug = 0;
-#define ldap_debug ldif_debug
#include "ldap_log.h"
+#include "lber_pvt.h"
#include "ldif.h"
#define RIGHT2 0x03
#define RIGHT4 0x0f
#define CONTINUED_LINE_MARKER '\001'
-static char nib2b64[0x40f] =
+static const char nib2b64[0x40f] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static unsigned char b642nib[0x80] = {
+static const unsigned char b642nib[0x80] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
int
ldif_parse_line(
- char *line,
+ LDAP_CONST char *line,
char **type,
char **value,
int *vlen
int i, b64;
/* skip any leading space */
- while ( isspace( *line ) ) {
+ while ( isspace( (unsigned char) *line ) ) {
line++;
}
*type = line;
for ( s = line; *s && *s != ':'; s++ )
; /* NULL */
if ( *s == '\0' ) {
- Debug( LDAP_DEBUG_PARSE, "parse_line missing ':'\n", 0, 0, 0 );
+ ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
+ "ldif_parse_line missing ':'\n");
return( -1 );
}
/* trim any space between type and : */
- for ( p = s - 1; p > line && isspace( *p ); p-- ) {
+ for ( p = s - 1; p > line && isspace( (unsigned char) *p ); p-- ) {
*p = '\0';
}
*s++ = '\0';
}
/* skip space between : and value */
- while ( isspace( *s ) ) {
+ while ( isspace( (unsigned char) *s ) ) {
s++;
}
/* if no value is present, error out */
if ( *s == '\0' ) {
- Debug( LDAP_DEBUG_PARSE, "parse_line missing value\n", 0,0,0 );
+ ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
+ "ldif_parse_line missing value\n");
return( -1 );
}
for ( i = 0; i < 4; i++ ) {
if ( p[i] != '=' && (p[i] & 0x80 ||
b642nib[ p[i] & 0x7f ] > 0x3f) ) {
- Debug( LDAP_DEBUG_ANY,
- "invalid base 64 encoding char (%c) 0x%x\n",
- p[i], p[i], 0 );
+ ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
+"ldif_parse_line: invalid base 64 encoding char (%c) 0x%x\n",
+ p[i], p[i] );
return( -1 );
}
}
char *
ldif_getline( char **next )
{
- char *l;
- char c;
+ char *l;
if ( *next == NULL || **next == '\n' || **next == '\0' ) {
return( NULL );
l = *next;
while ( (*next = strchr( *next, '\n' )) != NULL ) {
- c = *(*next + 1);
+ unsigned char c = *(*next + 1);
if ( isspace( c ) && c != '\n' ) {
**next = CONTINUED_LINE_MARKER;
*(*next+1) = CONTINUED_LINE_MARKER;
}
void
-ldif_put_type_and_value( char **out, char *t, char *val, int vlen )
+ldif_put_type_and_value(
+ char **out,
+ LDAP_CONST char *t,
+ LDAP_CONST char *val,
+ int vlen )
{
unsigned char *byte, *p, *stop;
unsigned char buf[3];
b64 = 1;
break;
}
- if ( len > LINE_WIDTH ) {
+ if ( len > LDIF_LINE_WIDTH ) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
bits |= (byte[2] & 0xff);
for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
- if ( len > LINE_WIDTH ) {
+ if ( len > LDIF_LINE_WIDTH ) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
bits |= (byte[2] & 0xff);
for ( i = 0; i < 4; i++, len++, bits <<= 6 ) {
- if ( len > LINE_WIDTH ) {
+ if ( len > LDIF_LINE_WIDTH ) {
*(*out)++ = '\n';
*(*out)++ = ' ';
len = 1;
char *
-ldif_type_and_value( char *type, char *val, int vlen )
+ldif_type_and_value( LDAP_CONST char *type, LDAP_CONST char *val, int vlen )
/*
- * return malloc'd, zero-terminated LDIF line
+ * return BER malloc'd, zero-terminated LDIF line
*/
{
char *buf, *p;
int tlen;
tlen = strlen( type );
- if (( buf = (char *)malloc( LDIF_SIZE_NEEDED( tlen, vlen ) + 1 )) !=
- NULL ) {
+ if (( buf = (char *) ber_memalloc( LDIF_SIZE_NEEDED( tlen, vlen ) + 1 ))
+ == NULL )
+ {
+ ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
+ "ldif_type_and_value: malloc failed!" );
+ return NULL;
}
p = buf;