X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblber%2Fbprint.c;h=0535603b0c39df3cb37cb59e2a7c38b526e5c7ae;hb=1702d408bfc09716ed0fbd42ef8c6bd11c51fd3a;hp=04497a79eabfdedba12603ab69b8037696ad160e;hpb=d37f3e6ee2e39c44dfb19b47174ecf182d233b1e;p=openldap diff --git a/libraries/liblber/bprint.c b/libraries/liblber/bprint.c index 04497a79ea..0535603b0c 100644 --- a/libraries/liblber/bprint.c +++ b/libraries/liblber/bprint.c @@ -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,6 +14,8 @@ #include "lber-int.h" +#define ber_log_check(errlvl, loglvl) ((errlvl) & (loglvl)) + BER_LOG_FN ber_int_log_proc = NULL; /* @@ -67,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; @@ -79,27 +85,18 @@ int ber_pvt_log_output( char *subsystem, int level, const char *fmt, ... ) } else { -#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 - (*ber_pvt_log_print)( buf ); - } + int level; + ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level ); + buf[sizeof(buf) - 1] = '\0'; + vsnprintf( buf, sizeof(buf)-1, fmt, vl ); + if ( ber_log_check( LDAP_DEBUG_BER, level ) ) + (*ber_pvt_log_print)( buf ); + } va_end(vl); 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 ]; @@ -113,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); @@ -206,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 ] = '.'; @@ -216,6 +206,82 @@ ber_bprint( (*ber_pvt_log_print)( line ); } +#ifdef NEW_LOGGING +int ber_output_dump( + const char *subsys, + int level, + BerElement *ber, + int inout ) +{ + static const char hexdig[] = "0123456789abcdef"; + char buf[132]; + ber_len_t len; + char line[ BP_LEN ]; + ber_len_t i; + char *data = ber->ber_ptr; + + if ( inout == 1 ) { + len = ber_pvt_ber_remaining(ber); + } else { + len = ber_pvt_ber_write(ber); + } + + sprintf( buf, "ber_dump: buf=0x%08lx ptr=0x%08lx end=0x%08lx len=%ld\n", + (long) ber->ber_buf, + (long) ber->ber_ptr, + (long) ber->ber_end, + (long) len ); + + (void) ber_pvt_log_output( subsys, level, "%s", buf ); + +#define BP_OFFSET 9 +#define BP_GRAPH 60 +#define BP_LEN 80 + + assert( data != NULL ); + + /* in case len is zero */ + line[0] = '\n'; + line[1] = '\0'; + + for ( i = 0 ; i < len ; i++ ) { + int n = i % 16; + unsigned off; + + if( !n ) { + 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'; + + off = i % 0x0ffffU; + + line[ 2 ] = hexdig[ 0x0f & (off >> 12) ]; + line[ 3 ] = hexdig[ 0x0f & (off >> 8) ]; + line[ 4 ] = hexdig[ 0x0f & (off >> 4) ]; + line[ 5 ] = hexdig[ 0x0f & off ]; + line[ 6 ] = ':'; + } + + off = BP_OFFSET + n*3 + ((n >= 8)?1:0); + line[ off ] = hexdig[ 0x0f & ( data[i] >> 4 ) ]; + line[ off+1 ] = hexdig[ 0x0f & data[i] ]; + + off = BP_GRAPH + n + ((n >= 8)?1:0); + + if ( isprint( (unsigned char) data[i] )) { + line[ BP_GRAPH + n ] = data[i]; + } else { + line[ BP_GRAPH + n ] = '.'; + } + } + + return ber_pvt_log_output( subsys, level, "%s", line ); +} +#endif + int ber_log_dump( int errlvl, @@ -224,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; @@ -243,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); @@ -257,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 ); }