Add debugging facility to tldap, analogous to tevent
authorVolker Lendecke <vl@samba.org>
Fri, 12 Jun 2009 12:50:46 +0000 (14:50 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 12 Jun 2009 13:04:21 +0000 (15:04 +0200)
source3/include/tldap.h
source3/lib/tldap.c

index c79a142654ea9e45277924dfd9fae00c61a617cc..d57484c5f81caaab01f163d57b1b66a807899cb8 100644 (file)
@@ -145,6 +145,21 @@ const char *tldap_ctx_diagnosticmessage(struct tldap_context *ctx);
 const char *tldap_ctx_referral(struct tldap_context *ctx);
 const char *tldap_err2string(int rc);
 
+/* DEBUG */
+enum tldap_debug_level {
+       TLDAP_DEBUG_FATAL,
+       TLDAP_DEBUG_ERROR,
+       TLDAP_DEBUG_WARNING,
+       TLDAP_DEBUG_TRACE
+};
+
+void tldap_set_debug(struct tldap_context *ld,
+                    void (*log_fn)(void *log_private,
+                                   enum tldap_debug_level level,
+                                   const char *fmt,
+                                   va_list ap) PRINTF_ATTRIBUTE(3,0),
+                    void *log_private);
+
 /*
  * "+ 0x60" is from ASN1_APPLICATION
  */
index df86f95e2c7d617c96aa386d084cceb3d8820c36..c823f88d04460512faf959accfb8d776dfd0ae80 100644 (file)
@@ -59,6 +59,11 @@ struct tldap_context {
        char *res_matcheddn;
        char *res_diagnosticmessage;
        char *res_referral;
+
+       /* debug */
+       void (*log_fn)(void *context, enum tldap_debug_level level,
+                      const char *fmt, va_list ap);
+       void *log_private;
 };
 
 struct tldap_message {
@@ -72,6 +77,33 @@ struct tldap_message {
        struct tldap_attribute *attribs;
 };
 
+void tldap_set_debug(struct tldap_context *ld,
+                    void (*log_fn)(void *log_private,
+                                   enum tldap_debug_level level,
+                                   const char *fmt,
+                                   va_list ap) PRINTF_ATTRIBUTE(3,0),
+                    void *log_private)
+{
+       ld->log_fn = log_fn;
+       ld->log_private = log_private;
+}
+
+static void tldap_debug(struct tldap_context *ld,
+                        enum tldap_debug_level level,
+                        const char *fmt, ...)
+{
+       va_list ap;
+       if (!ld) {
+               return;
+       }
+       if (ld->log_fn == NULL) {
+               return;
+       }
+       va_start(ap, fmt);
+       ld->log_fn(ld->log_private, level, fmt, ap);
+       va_end(ap);
+}
+
 static int tldap_next_msgid(struct tldap_context *ld)
 {
        int result;