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) ber_pvt_err_file = stderr;
51 fputs( data, ber_pvt_err_file );
53 /* Print to both streams */
54 if (ber_pvt_err_file != stderr) {
55 fputs( data, stderr );
59 fflush( ber_pvt_err_file );
62 BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
68 static int ber_log_check( int errlvl, int loglvl )
70 return errlvl & loglvl ? 1 : 0;
73 int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
78 assert( fmt != NULL );
80 if ( !ber_log_check( errlvl, loglvl )) {
87 buf[sizeof(buf) - 1] = '\0';
88 vsnprintf( buf, sizeof(buf)-1, fmt, ap );
90 vsprintf( buf, fmt, ap ); /* hope it's not too long */
93 #error "vsprintf() required."
98 (*ber_pvt_log_print)( buf );
102 static int ber_log_puts(int errlvl, int loglvl, char *buf)
104 assert( buf != NULL );
106 if ( !ber_log_check( errlvl, loglvl )) {
110 (*ber_pvt_log_print)( buf );
115 * Print arbitrary stuff, for debugging.
119 ber_log_bprint(int errlvl,
124 assert( data != NULL );
126 if ( !ber_log_check( errlvl, loglvl )) {
130 ber_bprint(data, len);
136 LDAP_CONST char *data,
139 static const char hexdig[] = "0123456789abcdef";
142 char buf[ BPLEN + sizeof("\t%s\n") ];
145 assert( data != NULL );
147 memset( out, '\0', BPLEN );
150 sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
151 (*ber_pvt_log_print)( buf );
156 if ( isgraph( (unsigned char)*data )) {
161 out[ i ] = hexdig[ ( *data & 0xf0U ) >> 4 ];
162 out[ i+1 ] = hexdig[ *data & 0x0fU ];
170 if ( i > BPLEN - 2 ) {
171 char data[128 + BPLEN];
172 sprintf( data, "\t%s\n", out );
173 (*ber_pvt_log_print)(data);
174 memset( out, '\0', BPLEN );
189 assert( ber != NULL );
190 assert( BER_VALID( ber ) );
192 if ( !ber_log_check( errlvl, loglvl )) {
196 ber_dump(ber, inout);
207 assert( ber != NULL );
208 assert( BER_VALID( ber ) );
210 sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
213 (long) ber->ber_end );
215 (*ber_pvt_log_print)( buf );
218 sprintf( buf, " current len %ld, contents:\n",
219 (long) (ber->ber_end - ber->ber_ptr) );
220 ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
223 sprintf( buf, " current len %ld, contents:\n",
224 (long) (ber->ber_ptr - ber->ber_buf) );
226 ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
236 assert( sos != NULL );
238 if ( !ber_log_check( errlvl, loglvl )) {
252 assert( sos != NULL );
254 (*ber_pvt_log_print)( "*** sos dump ***\n" );
256 while ( sos != NULL ) {
257 sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
258 (long) sos->sos_clen,
259 (long) sos->sos_first,
260 (long) sos->sos_ptr );
261 (*ber_pvt_log_print)( buf );
263 sprintf( buf, " current len %ld contents:\n",
264 (long) (sos->sos_ptr - sos->sos_first) );
265 (*ber_pvt_log_print)( buf );
267 ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
272 (*ber_pvt_log_print)( "*** end dump ***\n" );