3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/stdarg.h>
13 #include <ac/string.h>
18 * We don't just set ber_pvt_err_file to stderr here, because in NT,
19 * stderr is a symbol imported from a DLL. As such, the compiler
20 * doesn't recognize the symbol as having a constant address. Thus
21 * we set ber_pvt_err_file to stderr later, when it first gets
24 FILE *ber_pvt_err_file;
29 BER_ERRNO_FN ber_int_errno_fn;
31 int * ber_errno_addr(void)
33 static int ber_int_errno = LBER_ERROR_NONE;
35 if( ber_int_errno_fn ) {
36 return (*ber_int_errno_fn)();
39 return &ber_int_errno;
45 void ber_error_print( LDAP_CONST char *data )
47 assert( data != NULL );
49 if (!ber_pvt_err_file)
50 ber_pvt_err_file = stderr;
52 fputs( data, ber_pvt_err_file );
54 /* Print to both streams */
55 if (ber_pvt_err_file != stderr)
57 fputs( data, stderr );
61 fflush( ber_pvt_err_file );
64 BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
70 static int ber_log_check( int errlvl, int loglvl )
72 return errlvl & loglvl ? 1 : 0;
75 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
80 assert( fmt != NULL );
82 if ( !ber_log_check( errlvl, loglvl )) {
89 buf[sizeof(buf) - 1] = '\0';
90 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
92 vsprintf( buf, fmt, ap ); /* hope it's not too long */
95 #error "vsprintf() required."
100 (*ber_pvt_log_print)( buf );
104 static int ber_log_puts(int errlvl, int loglvl, char *buf)
106 assert( buf != NULL );
108 if ( !ber_log_check( errlvl, loglvl )) {
112 (*ber_pvt_log_print)( buf );
117 * Print arbitrary stuff, for debugging.
121 ber_log_bprint(int errlvl,
126 assert( data != NULL );
128 if ( !ber_log_check( errlvl, loglvl )) {
132 ber_bprint(data, len);
138 LDAP_CONST char *data,
141 static const char hexdig[] = "0123456789abcdef";
144 char buf[ BPLEN + sizeof("\t%s\n") ];
147 assert( data != NULL );
149 memset( out, '\0', BPLEN );
152 sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
153 (*ber_pvt_log_print)( buf );
158 if ( isgraph( (unsigned char)*data )) {
163 out[ i ] = hexdig[ ( *data & 0xf0U ) >> 4 ];
164 out[ i+1 ] = hexdig[ *data & 0x0fU ];
172 if ( i > BPLEN - 2 ) {
173 char data[128 + BPLEN];
174 sprintf( data, "\t%s\n", out );
175 (*ber_pvt_log_print)(data);
176 memset( out, '\0', BPLEN );
191 assert( ber != NULL );
192 assert( BER_VALID( ber ) );
194 if ( !ber_log_check( errlvl, loglvl )) {
198 ber_dump(ber, inout);
209 assert( ber != NULL );
210 assert( BER_VALID( ber ) );
212 sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
215 (long) ber->ber_end );
217 (*ber_pvt_log_print)( buf );
220 sprintf( buf, " current len %ld, contents:\n",
221 (long) (ber->ber_end - ber->ber_ptr) );
222 ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
225 sprintf( buf, " current len %ld, contents:\n",
226 (long) (ber->ber_ptr - ber->ber_buf) );
228 ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
238 assert( sos != NULL );
240 if ( !ber_log_check( errlvl, loglvl )) {
254 assert( sos != NULL );
256 (*ber_pvt_log_print)( "*** sos dump ***\n" );
258 while ( sos != NULL ) {
259 sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
260 (long) sos->sos_clen,
261 (long) sos->sos_first,
262 (long) sos->sos_ptr );
263 (*ber_pvt_log_print)( buf );
265 sprintf( buf, " current len %ld contents:\n",
266 (long) (sos->sos_ptr - sos->sos_first) );
267 (*ber_pvt_log_print)( buf );
269 ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
274 (*ber_pvt_log_print)( "*** end dump ***\n" );