]> git.sur5r.net Git - openldap/commitdiff
Add lber_log_print support to libldap.
authorKurt Zeilenga <kurt@openldap.org>
Tue, 26 Jan 1999 00:27:51 +0000 (00:27 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 26 Jan 1999 00:27:51 +0000 (00:27 +0000)
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
libraries/libldap/init.c
libraries/libldap/ldap-int.h
libraries/libldap/print.c [new file with mode: 0644]

index 25c1d518bd29d103e06ac65deb88b85a8a5e6f70..95989f1605c7ffcc6e15bdb101027fb2acdb39f3 100644 (file)
@@ -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
index 056b5920eefc20d24e5fda542bd7dbd591b9d8e7..3da4d7bf4b2554c943a6d8a0af7cc98236b53a97 100644 (file)
@@ -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;
index 153013a958e806908ffaf8f44fac55fd1fa937da..ea28e44fd79e0480ff5737dcfd3eb48ecb1640de 100644 (file)
@@ -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 (file)
index 0000000..4b865b7
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/ctype.h>
+#include <ac/stdarg.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#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;
+}