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>
15 #define LDAP_F_PRE LDAP_F_EXPORT
23 ber_error_print( char *data )
25 assert( data != NULL );
27 fputs( data, stderr );
31 BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
37 static int ber_log_check( int errlvl, int loglvl )
39 return errlvl & loglvl ? 1 : 0;
42 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
47 assert( fmt != NULL );
49 if ( !ber_log_check( errlvl, loglvl )) {
56 buf[sizeof(buf) - 1] = '\0';
57 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
59 vsprintf( buf, fmt, ap ); /* hope it's not too long */
62 #error "vsprintf() required."
67 (*ber_pvt_log_print)( buf );
71 static int ber_log_puts(int errlvl, int loglvl, char *buf)
73 assert( buf != NULL );
75 if ( !ber_log_check( errlvl, loglvl )) {
79 (*ber_pvt_log_print)( buf );
84 * Print arbitrary stuff, for debugging.
88 ber_log_bprint(int errlvl,
93 assert( data != NULL );
95 if ( !ber_log_check( errlvl, loglvl )) {
99 ber_bprint(data, len);
105 LDAP_CONST char *data,
108 static const char hexdig[] = "0123456789abcdef";
111 char buf[ BPLEN + sizeof("\t%s\n") ];
114 assert( data != NULL );
116 memset( out, 0, BPLEN );
119 sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
120 (*ber_pvt_log_print)( buf );
125 if ( isgraph( (unsigned char)*data )) {
130 out[ i ] = hexdig[ ( *data & 0xf0U ) >> 4 ];
131 out[ i+1 ] = hexdig[ *data & 0x0fU ];
139 if ( i > BPLEN - 2 ) {
140 char data[128 + BPLEN];
141 sprintf( data, "\t%s\n", out );
142 (*ber_pvt_log_print)(data);
143 memset( out, 0, BPLEN );
155 const BerElement *ber,
158 assert( ber != NULL );
159 assert( BER_VALID( ber ) );
161 if ( !ber_log_check( errlvl, loglvl )) {
165 ber_dump(ber, inout);
171 LDAP_CONST BerElement *ber,
176 assert( ber != NULL );
177 assert( BER_VALID( ber ) );
179 sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
182 (long) ber->ber_end );
184 (*ber_pvt_log_print)( buf );
187 sprintf( buf, " current len %ld, contents:\n",
188 (long) (ber->ber_end - ber->ber_ptr) );
189 ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
192 sprintf( buf, " current len %ld, contents:\n",
193 (long) (ber->ber_ptr - ber->ber_buf) );
195 ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
203 const Seqorset *sos )
205 assert( sos != NULL );
207 if ( !ber_log_check( errlvl, loglvl )) {
217 LDAP_CONST Seqorset *sos )
221 assert( sos != NULL );
223 (*ber_pvt_log_print)( "*** sos dump ***\n" );
225 while ( sos != NULL ) {
226 sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
227 (long) sos->sos_clen,
228 (long) sos->sos_first,
229 (long) sos->sos_ptr );
230 (*ber_pvt_log_print)( buf );
232 sprintf( buf, " current len %ld contents:\n",
233 (long) (sos->sos_ptr - sos->sos_first) );
234 (*ber_pvt_log_print)( buf );
236 ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
241 (*ber_pvt_log_print)( "*** end dump ***\n" );