]> git.sur5r.net Git - openldap/blobdiff - libraries/liblber/bprint.c
ITS#2184 maxbuf tweaks from Larry Greenfield @ CMU
[openldap] / libraries / liblber / bprint.c
index 0f4850ede36bddd1b201bb2cd7af1cdf0dd9a63a..0535603b0c39df3cb37cb59e2a7c38b526e5c7ae 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
@@ -14,9 +14,7 @@
 
 #include "lber-int.h"
 
-typedef void (*BER_LOG_FN) LDAP_P((FILE *file, char *subsys, int level, const char *fmt, va_list vl));
-
-static int ber_log_check( int errlvl, int loglvl );
+#define        ber_log_check(errlvl, loglvl)   ((errlvl) & (loglvl))
 
 BER_LOG_FN ber_int_log_proc = NULL;
 
@@ -71,7 +69,11 @@ BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
  * lber log 
  */
 
-int ber_pvt_log_output( char *subsystem, int level, const char *fmt, ... )
+int ber_pvt_log_output(
+       const char *subsystem,
+       int level,
+       const char *fmt,
+       ... )
 {
        char buf[ 1024 ];
        va_list vl;
@@ -85,15 +87,8 @@ int ber_pvt_log_output( char *subsystem, int level, const char *fmt, ... )
        {
             int level;
             ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level );
-#ifdef HAVE_VSNPRINTF
             buf[sizeof(buf) - 1] = '\0';
             vsnprintf( buf, sizeof(buf)-1, fmt, vl );
-#elif HAVE_VSPRINTF
-            vsprintf( buf, fmt, vl ); /* hope it's not too long */
-#else
-                /* use doprnt() */
-#error "vsprintf() required.";
-#endif
             if ( ber_log_check( LDAP_DEBUG_BER, level ) )
                 (*ber_pvt_log_print)( buf );
         }
@@ -102,11 +97,6 @@ int ber_pvt_log_output( char *subsystem, int level, const char *fmt, ... )
        return 1;
 }
        
-static int ber_log_check( int errlvl, int loglvl )
-{
-       return errlvl & loglvl ? 1 : 0;
-}
-
 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
 {
        char buf[ 1024 ];
@@ -120,15 +110,8 @@ int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
 
        va_start( ap, fmt );
 
-#ifdef HAVE_VSNPRINTF
        buf[sizeof(buf) - 1] = '\0';
        vsnprintf( buf, sizeof(buf)-1, fmt, ap );
-#elif HAVE_VSPRINTF
-       vsprintf( buf, fmt, ap ); /* hope it's not too long */
-#else
-       /* use doprnt() */
-#error "vsprintf() required."
-#endif
 
        va_end(ap);
 
@@ -213,7 +196,7 @@ ber_bprint(
                
                off = BP_GRAPH + n + ((n >= 8)?1:0);
 
-               if ( isprint( data[i] )) {
+               if ( isprint( (unsigned char) data[i] )) {
                        line[ BP_GRAPH + n ] = data[i];
                } else {
                        line[ BP_GRAPH + n ] = '.';
@@ -225,10 +208,10 @@ ber_bprint(
 
 #ifdef NEW_LOGGING
 int ber_output_dump(
-                    char *subsys,
-                    int level,
-                    BerElement *ber,
-                    int inout )
+       const char *subsys,
+       int level,
+       BerElement *ber,
+       int inout )
 {
     static const char  hexdig[] = "0123456789abcdef";
     char buf[132];
@@ -249,7 +232,7 @@ int ber_output_dump(
              (long) ber->ber_end,
              (long) len );
 
-    ber_pvt_log_output( subsys, level, "%s", buf );
+    (void) ber_pvt_log_output( subsys, level, "%s", buf );
 
 #define BP_OFFSET 9
 #define BP_GRAPH 60
@@ -266,7 +249,9 @@ int ber_output_dump(
         unsigned off;
         
         if( !n ) {
-            if( i ) ber_pvt_log_output( subsys, level, "%s", line );
+            if( i ) {
+                               (void) ber_pvt_log_output( subsys, level, "%s", line );
+                       }
             memset( line, ' ', sizeof(line)-2 );
             line[sizeof(line)-2] = '\n';
             line[sizeof(line)-1] = '\0';
@@ -286,14 +271,14 @@ int ber_output_dump(
         
         off = BP_GRAPH + n + ((n >= 8)?1:0);
         
-        if ( isprint( data[i] )) {
+        if ( isprint( (unsigned char) data[i] )) {
             line[ BP_GRAPH + n ] = data[i];
         } else {
             line[ BP_GRAPH + n ] = '.';
         }
     }
 
-    ber_pvt_log_output( subsys, level, "%s", line );
+    return ber_pvt_log_output( subsys, level, "%s", line );
 }
 #endif
 
@@ -305,7 +290,7 @@ ber_log_dump(
        int inout )
 {
        assert( ber != NULL );
-       assert( BER_VALID( ber ) );
+       assert( LBER_VALID( ber ) );
 
        if ( !ber_log_check( errlvl, loglvl )) {
                return 0;
@@ -324,7 +309,7 @@ ber_dump(
        ber_len_t len;
 
        assert( ber != NULL );
-       assert( BER_VALID( ber ) );
+       assert( LBER_VALID( ber ) );
 
        if ( inout == 1 ) {
                len = ber_pvt_ber_remaining(ber);
@@ -338,7 +323,7 @@ ber_dump(
                (long) ber->ber_end,
                (long) len );
 
-       (*ber_pvt_log_print)( buf );
+       (void) (*ber_pvt_log_print)( buf );
 
        ber_bprint( ber->ber_ptr, len );
 }