From 7eec2674364993167a2b2495d1aefb84809a5386 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 26 Jan 1999 00:27:51 +0000 Subject: [PATCH] Add lber_log_print support to libldap. Redefine Debug macro to call ldap_log_printf(NULL, lvl, fmt, ...) Should replace each Debug statement with direct call to ldap_log_printf passing LDAP session if available. --- libraries/libldap/Makefile.in | 4 +- libraries/libldap/init.c | 6 +-- libraries/libldap/ldap-int.h | 12 ++++- libraries/libldap/print.c | 89 +++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 libraries/libldap/print.c diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index 25c1d518bd..95989f1605 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -15,7 +15,7 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \ free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c getdxbyname.c os-ip.c url.c charset.c \ - init.c options.c string.c util-int.c + init.c options.c print.c string.c util-int.c OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ controls.lo messages.lo references.lo \ modify.lo add.lo modrdn.lo delete.lo abandon.lo ufn.lo cache.lo \ @@ -23,7 +23,7 @@ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ free.lo disptmpl.lo srchpref.lo dsparse.lo tmplout.lo sort.lo \ getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \ request.lo getdxbyname.lo os-ip.lo url.lo charset.lo \ - init.lo options.lo string.lo util-int.lo + init.lo options.lo print.lo string.lo util-int.lo LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index 056b5920ee..3da4d7bf4b 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -15,7 +15,7 @@ #include "ldap-int.h" #include "ldapconfig.h" -struct ldapoptions openldap_ldap_global_options; +struct ldapoptions openldap_ldap_global_options = { LDAP_DEBUG_NONE }; #undef gopts #define gopts openldap_ldap_global_options @@ -284,9 +284,9 @@ void openldap_ldap_initialize( void ) if ( openldap_ldap_initialized ) { return; } - + ldap_pvt_init_utils(); - + gopts.ldo_version = LDAP_VERSION2; gopts.ldo_deref = LDAP_DEREF_NEVER; gopts.ldo_timelimit = LDAP_NO_LIMIT; diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 153013a958..ea28e44fd7 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -19,6 +19,9 @@ #include "../liblber/lber-int.h" #define ldap_debug (openldap_ldap_global_options.ldo_debug) +#undef Debug +#define Debug( level, fmt, arg1, arg2, arg3 ) \ + ldap_log_printf( NULL, (level), (fmt), (arg1), (arg2), (arg3) ) #include "ldap_log.h" @@ -76,13 +79,13 @@ struct ldapmsg { * which have global defaults. */ struct ldapoptions { + int ldo_debug; + int ldo_version; /* version to connect at */ int ldo_deref; int ldo_timelimit; int ldo_sizelimit; - int ldo_debug; - int ldo_defport; char* ldo_defbase; char* ldo_defhost; @@ -239,6 +242,11 @@ extern int openldap_ldap_initialized; extern struct ldapoptions openldap_ldap_global_options; void openldap_ldap_initialize LDAP_P((void)); +/* + * in print.c + */ +int ldap_log_printf LDAP_P((LDAP *ld, int level, char *fmt, ...)); + /* * in cache.c */ diff --git a/libraries/libldap/print.c b/libraries/libldap/print.c new file mode 100644 index 0000000000..4b865b7b48 --- /dev/null +++ b/libraries/libldap/print.c @@ -0,0 +1,89 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include + +#include +#include +#include +#include + +#include "ldap-int.h" + +extern BER_LOG_PRINT_FN lber_log_print; + +/* + * ldap log + */ + +static int ldap_log_check( LDAP *ld, int loglvl ) +{ + int errlvl; + + if(ld == NULL) { + errlvl = ldap_debug; + } else { + errlvl = ld->ld_errno; + } + + return errlvl & loglvl ? 1 : 0; +} + +int ldap_log_printf +#ifdef HAVE_STDARG + ( LDAP *ld, int loglvl, char *fmt, ... ) +#else + ( va_alist ) +va_dcl +#endif +{ + char buf[ 1024 ]; + va_list ap; + +#ifdef HAVE_STDARG + va_start( ap, fmt ); +#else + LD *ld + int loglvl; + char *fmt; + + va_start( ap ); + + errlvl = va_arg( ap, LD * ); + loglvl = va_arg( ap, int ); + fmt = va_arg( ap, char * ); +#endif + + if ( !ldap_log_check( ld, loglvl )) { + return 0; + } + +#ifdef HAVE_VSNPRINTF + buf[sizeof(buf) - 1] = '\0'; + vsnprintf( buf, sizeof(buf)-1, fmt, ap ); +#elif HAVE_VSPRINTF + vsprintf( buf, fmt, ap ); /* hope it's not too long */ +#else + /* use doprnt() */ + chokeme = "choke me! I don't have a doprnt manual handy!"; +#endif + + va_end(ap); + + (*lber_log_print)( buf ); + return 1; +} + +static int lber_log_puts(int errlvl, int loglvl, char *buf) +{ + if ( !ldap_log_check( errlvl, loglvl )) { + return 0; + } + + (*lber_log_print)( buf ); + return 1; +} -- 2.39.5