summaryrefslogtreecommitdiffstats
path: root/nsswitch
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2009-06-01 23:33:27 +0200
committerKai Blin <kai@samba.org>2009-06-13 09:39:01 +0200
commita88bbaf6706d6e5902839dfa395641500b5c4064 (patch)
treead90a9227ac12740dcdc4bac6c8ae74f60c9d0c1 /nsswitch
parent04afa4b6b50f3a23a1872983c75653dc5f670279 (diff)
downloadsamba-a88bbaf6706d6e5902839dfa395641500b5c4064.tar.gz
samba-a88bbaf6706d6e5902839dfa395641500b5c4064.tar.xz
samba-a88bbaf6706d6e5902839dfa395641500b5c4064.zip
libwbclient: Add debugging hooks.
Diffstat (limited to 'nsswitch')
-rw-r--r--nsswitch/libwbclient/wbc_async.c75
-rw-r--r--nsswitch/libwbclient/wbc_async.h16
2 files changed, 91 insertions, 0 deletions
diff --git a/nsswitch/libwbclient/wbc_async.c b/nsswitch/libwbclient/wbc_async.c
index fb8d8b102d4..181d5463e94 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 607dd9de282..76e02cadf22 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);