]> git.sur5r.net Git - openldap/blobdiff - libraries/libldif/line64.c
ldap-int.h
[openldap] / libraries / libldif / line64.c
index d0af5ae29be248acba19652d72af45bce917f215..527bd4f9d9c46960794302a481f2d4dbd103dc0b 100644 (file)
@@ -3,8 +3,9 @@
 #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>
@@ -20,10 +21,10 @@ int ldif_debug = 0;
 #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,
@@ -51,7 +52,7 @@ static unsigned char b642nib[0x80] = {
 
 int
 ldif_parse_line(
-    char       *line,
+    LDAP_CONST char    *line,
     char       **type,
     char       **value,
     int                *vlen
@@ -70,7 +71,7 @@ ldif_parse_line(
        for ( s = line; *s && *s != ':'; s++ )
                ;       /* NULL */
        if ( *s == '\0' ) {
-               lber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
+               ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
                        "ldif_parse_line missing ':'\n");
                return( -1 );
        }
@@ -98,7 +99,7 @@ ldif_parse_line(
 
        /* if no value is present, error out */
        if ( *s == '\0' ) {
-               lber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
+               ber_pvt_log_printf( LDAP_DEBUG_PARSE, ldif_debug,
                        "ldif_parse_line missing value\n");
                return( -1 );
        }
@@ -118,7 +119,7 @@ ldif_parse_line(
                        for ( i = 0; i < 4; i++ ) {
                                if ( p[i] != '=' && (p[i] & 0x80 ||
                                    b642nib[ p[i] & 0x7f ] > 0x3f) ) {
-                                       lber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
+                                       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 );
@@ -198,7 +199,11 @@ ldif_getline( char **next )
 }
 
 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];
@@ -228,7 +233,7 @@ ldif_put_type_and_value( char **out, char *t, char *val, int vlen )
                                b64 = 1;
                                break;
                        }
-                       if ( len > LINE_WIDTH ) {
+                       if ( len > LDIF_LINE_WIDTH ) {
                                *(*out)++ = '\n';
                                *(*out)++ = ' ';
                                len = 1;
@@ -249,7 +254,7 @@ ldif_put_type_and_value( char **out, char *t, char *val, int vlen )
                        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;
@@ -274,7 +279,7 @@ ldif_put_type_and_value( char **out, char *t, char *val, int vlen )
                        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;
@@ -294,19 +299,19 @@ ldif_put_type_and_value( char **out, char *t, char *val, int vlen )
 
 
 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 ))
+    if (( buf = (char *) ber_memalloc( LDIF_SIZE_NEEDED( tlen, vlen ) + 1 ))
                == NULL )
        {
-               lber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
+               ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
                        "ldif_type_and_value: malloc failed!" );
                return NULL;
     }