1998-12-29 04:38:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
1998-12-22 09:34:01 +08:00
|
|
|
#include <ac/stdarg.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/string.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-10-26 09:18:41 +08:00
|
|
|
#include "lber-int.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
/*
|
1998-10-27 15:50:07 +08:00
|
|
|
* Print stuff
|
1998-08-09 08:43:13 +08:00
|
|
|
*/
|
1998-12-22 09:34:01 +08:00
|
|
|
static void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_error_print( char *data )
|
1998-10-27 15:50:07 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
1998-10-27 15:50:07 +08:00
|
|
|
fputs( data, stderr );
|
|
|
|
fflush( stderr );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
BER_LOG_PRINT_FN ber_pvt_log_print = ber_error_print;
|
1999-01-26 06:55:00 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
/*
|
|
|
|
* lber log
|
|
|
|
*/
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
static int ber_log_check( int errlvl, int loglvl )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
return errlvl & loglvl ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
int ber_pvt_log_printf
|
1998-12-22 09:34:01 +08:00
|
|
|
#ifdef HAVE_STDARG
|
1999-05-19 09:12:33 +08:00
|
|
|
(int errlvl, int loglvl, const char *fmt, ...)
|
1998-12-22 09:34:01 +08:00
|
|
|
#else
|
|
|
|
( va_alist )
|
|
|
|
va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
char buf[ 1024 ];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
#ifdef HAVE_STDARG
|
|
|
|
va_start( ap, fmt );
|
|
|
|
#else
|
|
|
|
int errlvl, loglvl;
|
|
|
|
char *fmt;
|
|
|
|
|
|
|
|
va_start( ap );
|
|
|
|
|
|
|
|
errlvl = va_arg( ap, int );
|
|
|
|
loglvl = va_arg( ap, int );
|
|
|
|
fmt = va_arg( ap, char * );
|
|
|
|
#endif
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( fmt != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_VSNPRINTF
|
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
|
|
|
vsnprintf( buf, sizeof(buf)-1, fmt, ap );
|
1998-12-24 09:31:40 +08:00
|
|
|
#elif HAVE_VSPRINTF
|
1998-12-22 09:34:01 +08:00
|
|
|
vsprintf( buf, fmt, ap ); /* hope it's not too long */
|
|
|
|
#else
|
|
|
|
/* use doprnt() */
|
1999-05-19 09:12:33 +08:00
|
|
|
#error "vsprintf() required."
|
1998-12-22 09:34:01 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
static int ber_log_puts(int errlvl, int loglvl, char *buf)
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( buf != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-27 15:50:07 +08:00
|
|
|
/*
|
|
|
|
* Print arbitrary stuff, for debugging.
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_log_bprint(int errlvl,
|
|
|
|
int loglvl,
|
|
|
|
const char *data,
|
|
|
|
int len )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
ber_bprint(data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_bprint(
|
|
|
|
LDAP_CONST char *data,
|
|
|
|
int len )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-03-09 16:40:36 +08:00
|
|
|
static const char hexdig[] = "0123456789abcdef";
|
1998-12-22 09:34:01 +08:00
|
|
|
#define BPLEN 48
|
1998-08-09 08:43:13 +08:00
|
|
|
char out[ BPLEN ];
|
1998-12-22 09:34:01 +08:00
|
|
|
char buf[ BPLEN + sizeof("\t%s\n") ];
|
1998-08-09 08:43:13 +08:00
|
|
|
int i = 0;
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( data != NULL );
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
memset( out, 0, BPLEN );
|
|
|
|
for ( ;; ) {
|
|
|
|
if ( len < 1 ) {
|
1998-12-22 09:34:01 +08:00
|
|
|
sprintf( buf, "\t%s\n", ( i == 0 ) ? "(end)" : out );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-08-09 08:43:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
#ifndef LDAP_HEX
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( isgraph( (unsigned char)*data )) {
|
|
|
|
out[ i ] = ' ';
|
|
|
|
out[ i+1 ] = *data;
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
|
|
|
|
out[ i+1 ] = hexdig[ *data & 0x0f ];
|
1998-12-22 09:34:01 +08:00
|
|
|
#ifndef LDAP_HEX
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
i += 2;
|
|
|
|
len--;
|
|
|
|
data++;
|
|
|
|
|
|
|
|
if ( i > BPLEN - 2 ) {
|
1998-10-27 15:50:07 +08:00
|
|
|
char data[128 + BPLEN];
|
|
|
|
sprintf( data, "\t%s\n", out );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)(data);
|
1998-08-09 08:43:13 +08:00
|
|
|
memset( out, 0, BPLEN );
|
|
|
|
i = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
out[ i++ ] = ' ';
|
|
|
|
}
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_log_dump(
|
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
|
|
|
const BerElement *ber,
|
|
|
|
int inout )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( ber != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_dump(ber, inout);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_dump(
|
|
|
|
LDAP_CONST BerElement *ber,
|
|
|
|
int inout )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
char buf[132];
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( ber != NULL );
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
sprintf( buf, "ber_dump: buf 0x%lx, ptr 0x%lx, end 0x%lx\n",
|
|
|
|
(long) ber->ber_buf,
|
|
|
|
(long) ber->ber_ptr,
|
|
|
|
(long) ber->ber_end );
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
if ( inout == 1 ) {
|
|
|
|
sprintf( buf, " current len %ld, contents:\n",
|
|
|
|
(long) (ber->ber_end - ber->ber_ptr) );
|
|
|
|
ber_bprint( ber->ber_ptr, ber->ber_end - ber->ber_ptr );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
sprintf( buf, " current len %ld, contents:\n",
|
|
|
|
(long) (ber->ber_ptr - ber->ber_buf) );
|
|
|
|
|
|
|
|
ber_bprint( ber->ber_buf, ber->ber_ptr - ber->ber_buf );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
lber_log_sos_dump(
|
|
|
|
int errlvl,
|
|
|
|
int loglvl,
|
|
|
|
const Seqorset *sos )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( sos != NULL );
|
|
|
|
|
|
|
|
if ( !ber_log_check( errlvl, loglvl )) {
|
1998-12-22 09:34:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_sos_dump( sos );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_sos_dump(
|
|
|
|
LDAP_CONST Seqorset *sos )
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
char buf[132];
|
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
assert( sos != NULL );
|
|
|
|
|
|
|
|
(*ber_pvt_log_print)( "*** sos dump ***\n" );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
while ( sos != NULLSEQORSET ) {
|
|
|
|
sprintf( buf, "ber_sos_dump: clen %ld first 0x%lx ptr 0x%lx\n",
|
|
|
|
(long) sos->sos_clen, (long) sos->sos_first, (long) sos->sos_ptr );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
sprintf( buf, " current len %ld contents:\n",
|
|
|
|
(long) (sos->sos_ptr - sos->sos_first) );
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( buf );
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
ber_bprint( sos->sos_first, sos->sos_ptr - sos->sos_first );
|
|
|
|
|
|
|
|
sos = sos->sos_next;
|
|
|
|
}
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1999-05-19 09:12:33 +08:00
|
|
|
(*ber_pvt_log_print)( "*** end dump ***\n" );
|
|
|
|
}
|