2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/stdarg.h>
12 #include <ac/string.h>
20 ber_error_print( char *data )
22 assert( data != NULL );
24 fputs( data, stderr );
28 BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
34 static int ber_log_check( int errlvl, int loglvl )
36 return errlvl & loglvl ? 1 : 0;
39 int ber_pvt_log_printf
41 (int errlvl, int loglvl, const char *fmt, ...)
58 errlvl = va_arg( ap, int );
59 loglvl = va_arg( ap, int );
60 fmt = va_arg( ap, char * );
63 assert( fmt != NULL );
65 if ( !ber_log_check( errlvl, loglvl )) {
70 buf[sizeof(buf) - 1] = '\0';
71 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
73 vsprintf( buf, fmt, ap ); /* hope it's not too long */
76 #error "vsprintf() required."
81 (*ber_pvt_log_print)( buf );
85 static int ber_log_puts(int errlvl, int loglvl, char *buf)
87 assert( buf != NULL );
89 if ( !ber_log_check( errlvl, loglvl )) {
93 (*ber_pvt_log_print)( buf );
98 * Print arbitrary stuff, for debugging.
102 ber_log_bprint(int errlvl,
107 assert( data != NULL );
109 if ( !ber_log_check( errlvl, loglvl )) {
113 ber_bprint(data, len);
119 LDAP_CONST char *data,
122 static const char hexdig[] = "0123456789abcdef";
125 char buf[ BPLEN + sizeof("\t%s\n") ];
128 assert( data != NULL );
130 memset( out, 0, BPLEN );
133 sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
134 (*ber_pvt_log_print)( buf );
139 if ( isgraph( (unsigned char)*data )) {
144 out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
145 out[ i+1 ] = hexdig[ *data & 0x0f ];
153 if ( i > BPLEN - 2 ) {
154 char data[128 + BPLEN];
155 sprintf( data, "\t%s\n", out );
156 (*ber_pvt_log_print)(data);
157 memset( out, 0, BPLEN );
169 const BerElement *ber,
172 assert( ber != NULL );
174 if ( !ber_log_check( errlvl, loglvl )) {
178 ber_dump(ber, inout);
184 LDAP_CONST BerElement *ber,
189 assert( ber != NULL );
191 sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
194 (long) ber->ber_end );
196 (*ber_pvt_log_print)( buf );
199 sprintf( buf, " current len %ld, contents:\n",
200 (long) (ber->ber_end - ber->ber_ptr) );
201 ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
204 sprintf( buf, " current len %ld, contents:\n",
205 (long) (ber->ber_ptr - ber->ber_buf) );
207 ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
215 const Seqorset *sos )
217 assert( sos != NULL );
219 if ( !ber_log_check( errlvl, loglvl )) {
229 LDAP_CONST Seqorset *sos )
233 assert( sos != NULL );
235 (*ber_pvt_log_print)( "*** sos dump ***\n" );
237 while ( sos != NULLSEQORSET ) {
238 sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
239 (long) sos->sos_clen, (long) sos->sos_first, (long) sos->sos_ptr );
240 (*ber_pvt_log_print)( buf );
242 sprintf( buf, " current len %ld contents:\n",
243 (long) (sos->sos_ptr - sos->sos_first) );
244 (*ber_pvt_log_print)( buf );
246 ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
251 (*ber_pvt_log_print)( "*** end dump ***\n" );