[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-2293-ga88bbaf

Kai Blin kai at samba.org
Sat Jun 13 07:39:21 GMT 2009


The branch, master has been updated
       via  a88bbaf6706d6e5902839dfa395641500b5c4064 (commit)
      from  04afa4b6b50f3a23a1872983c75653dc5f670279 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a88bbaf6706d6e5902839dfa395641500b5c4064
Author: Kai Blin <kai at samba.org>
Date:   Mon Jun 1 23:33:27 2009 +0200

    libwbclient: Add debugging hooks.

-----------------------------------------------------------------------

Summary of changes:
 nsswitch/libwbclient/wbc_async.c |   75 ++++++++++++++++++++++++++++++++++++++
 nsswitch/libwbclient/wbc_async.h |   16 ++++++++
 2 files changed, 91 insertions(+), 0 deletions(-)


Changeset truncated at 500 lines:

diff --git a/nsswitch/libwbclient/wbc_async.c b/nsswitch/libwbclient/wbc_async.c
index fb8d8b1..181d546 100644
--- a/nsswitch/libwbclient/wbc_async.c
+++ b/nsswitch/libwbclient/wbc_async.c
@@ -82,11 +82,18 @@ wbcErr tevent_req_simple_recv_wbcerr(struct tevent_req *req)
 	return WBC_ERR_SUCCESS;
 }
 
+struct wbc_debug_ops {
+	void (*debug)(void *context, enum wbcDebugLevel level,
+		      const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0);
+	void *context;
+};
+
 struct wb_context {
 	struct tevent_queue *queue;
 	int fd;
 	bool is_priv;
 	const char *dir;
+	struct wbc_debug_ops debug_ops;
 };
 
 static int make_nonstd_fd(int fd)
@@ -697,3 +704,71 @@ wbcErr wb_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 	*presponse = talloc_move(mem_ctx, &state->wb_resp);
 	return WBC_ERR_SUCCESS;
 }
+
+/********************************************************************
+ * Debug wrapper functions, modeled (with lot's of code copied as is)
+ * after the tevent debug wrapper functions
+ ********************************************************************/
+
+/*
+  this allows the user to choose their own debug function
+*/
+int wbcSetDebug(struct wb_context *wb_ctx,
+		void (*debug)(void *context,
+			      enum wbcDebugLevel level,
+			      const char *fmt,
+			      va_list ap) PRINTF_ATTRIBUTE(3,0),
+		void *context)
+{
+	wb_ctx->debug_ops.debug = debug;
+	wb_ctx->debug_ops.context = context;
+	return 0;
+}
+
+/*
+  debug function for wbcSetDebugStderr
+*/
+static void wbcDebugStderr(void *private_data,
+			   enum wbcDebugLevel level,
+			   const char *fmt,
+			   va_list ap) PRINTF_ATTRIBUTE(3,0);
+static void wbcDebugStderr(void *private_data,
+			   enum wbcDebugLevel level,
+			   const char *fmt, va_list ap)
+{
+	if (level <= WBC_DEBUG_WARNING) {
+		vfprintf(stderr, fmt, ap);
+	}
+}
+
+/*
+  convenience function to setup debug messages on stderr
+  messages of level WBC_DEBUG_WARNING and higher are printed
+*/
+int wbcSetDebugStderr(struct wb_context *wb_ctx)
+{
+	return wbcSetDebug(wb_ctx, wbcDebugStderr, wb_ctx);
+}
+
+/*
+ * log a message
+ *
+ * The default debug action is to ignore debugging messages.
+ * This is the most appropriate action for a library.
+ * Applications using the library must decide where to
+ * redirect debugging messages
+*/
+void wbcDebug(struct wb_context *wb_ctx, enum wbcDebugLevel level,
+	      const char *fmt, ...)
+{
+	va_list ap;
+	if (!wb_ctx) {
+		return;
+	}
+	if (wb_ctx->debug_ops.debug == NULL) {
+		return;
+	}
+	va_start(ap, fmt);
+	wb_ctx->debug_ops.debug(wb_ctx->debug_ops.context, level, fmt, ap);
+	va_end(ap);
+}
diff --git a/nsswitch/libwbclient/wbc_async.h b/nsswitch/libwbclient/wbc_async.h
index 607dd9d..76e02ca 100644
--- a/nsswitch/libwbclient/wbc_async.h
+++ b/nsswitch/libwbclient/wbc_async.h
@@ -32,6 +32,13 @@ struct wb_context;
 struct winbindd_request;
 struct winbindd_response;
 
+enum wbcDebugLevel {
+	WBC_DEBUG_FATAL,
+	WBC_DEBUG_ERROR,
+	WBC_DEBUG_WARNING,
+	WBC_DEBUG_TRACE
+};
+
 struct tevent_req *wb_trans_send(TALLOC_CTX *mem_ctx,
 				 struct tevent_context *ev,
 				 struct wb_context *wb_ctx, bool need_priv,
@@ -39,6 +46,15 @@ struct tevent_req *wb_trans_send(TALLOC_CTX *mem_ctx,
 wbcErr wb_trans_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 		     struct winbindd_response **presponse);
 struct wb_context *wb_context_init(TALLOC_CTX *mem_ctx, const char* dir);
+int wbcSetDebug(struct wb_context *wb_ctx,
+		void (*debug)(void *context,
+			      enum wbcDebugLevel level,
+			      const char *fmt,
+			      va_list ap) PRINTF_ATTRIBUTE(3,0),
+		void *context);
+int wbcSetDebugStderr(struct wb_context *wb_ctx);
+void wbcDebug(struct wb_context *wb_ctx, enum wbcDebugLevel level,
+	      const char *fmt, ...) PRINTF_ATTRIBUTE(3,0);
 
 /* Definitions from wb_reqtrans.c */
 wbcErr map_wbc_err_from_errno(int error);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list