3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/stdarg.h>
13 #include <ac/string.h>
16 #define LDAP_F_PRE LDAP_F_EXPORT
24 ber_error_print( char *data )
26 assert( data != NULL );
28 fputs( data, stderr );
32 BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
38 static int ber_log_check( int errlvl, int loglvl )
40 return errlvl & loglvl ? 1 : 0;
43 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
48 assert( fmt != NULL );
50 if ( !ber_log_check( errlvl, loglvl )) {
57 buf[sizeof(buf) - 1] = '\0';
58 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
60 vsprintf( buf, fmt, ap ); /* hope it's not too long */
63 #error "vsprintf() required."
68 (*ber_pvt_log_print)( buf );
72 static int ber_log_puts(int errlvl, int loglvl, char *buf)
74 assert( buf != NULL );
76 if ( !ber_log_check( errlvl, loglvl )) {
80 (*ber_pvt_log_print)( buf );
85 * Print arbitrary stuff, for debugging.
89 ber_log_bprint(int errlvl,
94 assert( data != NULL );
96 if ( !ber_log_check( errlvl, loglvl )) {
100 ber_bprint(data, len);
106 LDAP_CONST char *data,
109 static const char hexdig[] = "0123456789abcdef";
112 char buf[ BPLEN + sizeof("\t%s\n") ];
115 assert( data != NULL );
117 memset( out, 0, BPLEN );
120 sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
121 (*ber_pvt_log_print)( buf );
126 if ( isgraph( (unsigned char)*data )) {
131 out[ i ] = hexdig[ ( *data & 0xf0U ) >> 4 ];
132 out[ i+1 ] = hexdig[ *data & 0x0fU ];
140 if ( i > BPLEN - 2 ) {
141 char data[128 + BPLEN];
142 sprintf( data, "\t%s\n", out );
143 (*ber_pvt_log_print)(data);
144 memset( out, 0, BPLEN );
156 const BerElement *ber,
159 assert( ber != NULL );
160 assert( BER_VALID( ber ) );
162 if ( !ber_log_check( errlvl, loglvl )) {
166 ber_dump(ber, inout);
172 LDAP_CONST BerElement *ber,
177 assert( ber != NULL );
178 assert( BER_VALID( ber ) );
180 sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
183 (long) ber->ber_end );
185 (*ber_pvt_log_print)( buf );
188 sprintf( buf, " current len %ld, contents:\n",
189 (long) (ber->ber_end - ber->ber_ptr) );
190 ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
193 sprintf( buf, " current len %ld, contents:\n",
194 (long) (ber->ber_ptr - ber->ber_buf) );
196 ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
204 const Seqorset *sos )
206 assert( sos != NULL );
208 if ( !ber_log_check( errlvl, loglvl )) {
218 LDAP_CONST Seqorset *sos )
222 assert( sos != NULL );
224 (*ber_pvt_log_print)( "*** sos dump ***\n" );
226 while ( sos != NULL ) {
227 sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
228 (long) sos->sos_clen,
229 (long) sos->sos_first,
230 (long) sos->sos_ptr );
231 (*ber_pvt_log_print)( buf );
233 sprintf( buf, " current len %ld contents:\n",
234 (long) (sos->sos_ptr - sos->sos_first) );
235 (*ber_pvt_log_print)( buf );
237 ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
242 (*ber_pvt_log_print)( "*** end dump ***\n" );