1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

libwbclient: Add debugging hooks.

This commit is contained in:
Kai Blin 2009-06-01 23:33:27 +02:00
parent 04afa4b6b5
commit a88bbaf670
2 changed files with 91 additions and 0 deletions

View File

@ -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);
}

View File

@ -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);