diff options
author | Werner Koch <[email protected]> | 2003-12-16 16:32:33 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2003-12-16 16:32:33 +0000 |
commit | effc4649f13c5eea3f546e196d628cb38693499f (patch) | |
tree | c124e57fb53d94b09c2bbe8677d5d858b5671a2b | |
parent | Add some notes (diff) | |
download | libassuan-effc4649f13c5eea3f546e196d628cb38693499f.tar.gz libassuan-effc4649f13c5eea3f546e196d628cb38693499f.zip |
* assuan-buffer.c: Changed formatting of the debug output prefix.
* assuan-util.c (assuan_set_log_stream): Set global log stream if
it has not been done yet.
* assuan-logging.c (_assuan_set_default_log_stream): New.
(assuan_set_assuan_log_prefix): New.
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | src/ChangeLog | 8 | ||||
-rw-r--r-- | src/assuan-buffer.c | 35 | ||||
-rw-r--r-- | src/assuan-defs.h | 3 | ||||
-rw-r--r-- | src/assuan-logging.c | 25 | ||||
-rw-r--r-- | src/assuan-util.c | 1 | ||||
-rw-r--r-- | src/assuan.h | 23 |
7 files changed, 78 insertions, 22 deletions
@@ -1,6 +1,11 @@ Noteworthy changes in version 0.6.2 (unreleased) ------------------------------------------------ + * New function assuan_set_assuan_log_prefix to store a log prefix to + be used when no context is available. The existing function + assuan_get_assuan_log_context is not anymore declared as user + overridable. + Noteworthy changes in version 0.6.1 (2003-11-17) ------------------------------------------------ diff --git a/src/ChangeLog b/src/ChangeLog index 542e6be..bb61f3e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2003-12-16 Werner Koch <[email protected]> + + * assuan-buffer.c: Changed formatting of the debug output prefix. + * assuan-util.c (assuan_set_log_stream): Set global log stream if + it has not been done yet. + * assuan-logging.c (_assuan_set_default_log_stream): New. + (assuan_set_assuan_log_prefix): New. + 2003-12-11 Werner Koch <[email protected]> * funopen.c (_assuan_funopen): Renamed from funopen, to keep the diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c index 59518f2..3684b3e 100644 --- a/src/assuan-buffer.c +++ b/src/assuan-buffer.c @@ -125,16 +125,18 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) if (rc) { if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%p] <- [Error: %s]\n", - assuan_get_assuan_log_prefix (), ctx, strerror (errno)); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- [Error: %s]\n", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx, strerror (errno)); return ASSUAN_Read_Error; } if (!nread) { assert (ctx->inbound.eof); if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%p] <- [EOF]\n", - assuan_get_assuan_log_prefix (), ctx); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- [EOF]\n", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx); return -1; } @@ -165,8 +167,9 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) ctx->inbound.linelen = endp - line; if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%p] <- ", - assuan_get_assuan_log_prefix (), ctx); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- ", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); else @@ -180,8 +183,9 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) else { if (ctx->log_fp) - fprintf (ctx->log_fp, "%s[%p] <- [Invalid line]\n", - assuan_get_assuan_log_prefix (), ctx); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: <- [Invalid line]\n", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx); *line = 0; ctx->inbound.linelen = 0; return ctx->inbound.eof ? ASSUAN_Line_Not_Terminated @@ -241,8 +245,9 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) /* fixme: we should do some kind of line buffering. */ if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%p] -> ", - assuan_get_assuan_log_prefix (), ctx); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx); if (s) fputs ("[supplied line contained a LF]", ctx->log_fp); if (ctx->confidential) @@ -314,8 +319,9 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size) { if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%p] -> ", - assuan_get_assuan_log_prefix (), ctx); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); @@ -361,8 +367,9 @@ _assuan_cookie_write_flush (void *cookie) { if (ctx->log_fp) { - fprintf (ctx->log_fp, "%s[%p] -> ", - assuan_get_assuan_log_prefix (), ctx); + fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> ", + assuan_get_assuan_log_prefix (), + (unsigned int)getpid (), ctx); if (ctx->confidential) fputs ("[Confidential data not shown]", ctx->log_fp); else diff --git a/src/assuan-defs.h b/src/assuan-defs.h index e25fc6a..e2d9811 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -177,6 +177,9 @@ void _assuan_free (void *p); void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length); void _assuan_log_sanitized_string (const char *string); +/*-- assuan-logging.c --*/ +void _assuan_set_default_log_stream (FILE *fp); + /*-- assuan-io.c --*/ ssize_t _assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size); ssize_t _assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer, diff --git a/src/assuan-logging.c b/src/assuan-logging.c index 340ce72..e129187 100644 --- a/src/assuan-logging.c +++ b/src/assuan-logging.c @@ -21,9 +21,17 @@ #include "assuan-defs.h" #include <stdio.h> +static char prefix_buffer[80]; static FILE *_assuan_log; void +_assuan_set_default_log_stream (FILE *fp) +{ + if (!_assuan_log) + _assuan_log = fp; +} + +void assuan_set_assuan_log_stream (FILE *fp) { _assuan_log = fp; @@ -35,8 +43,23 @@ assuan_get_assuan_log_stream (void) return _assuan_log ? _assuan_log : stderr; } + +/* Set the prefix to be used for logging to TEXT or + resets it to the default if TEXT is NULL. */ +void +assuan_set_assuan_log_prefix (const char *text) +{ + if (text) + { + strncpy (prefix_buffer, text, sizeof (prefix_buffer)-1); + prefix_buffer[sizeof (prefix_buffer)-1] = 0; + } + else + *prefix_buffer = 0; +} + const char * assuan_get_assuan_log_prefix (void) { - return ""; + return prefix_buffer; } diff --git a/src/assuan-util.c b/src/assuan-util.c index fc0beed..a09982a 100644 --- a/src/assuan-util.c +++ b/src/assuan-util.c @@ -102,6 +102,7 @@ assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp) if (ctx->log_fp) fflush (ctx->log_fp); ctx->log_fp = fp; + _assuan_set_default_log_stream (fp); } } diff --git a/src/assuan.h b/src/assuan.h index 07f56b3..261a752 100644 --- a/src/assuan.h +++ b/src/assuan.h @@ -266,17 +266,26 @@ const char *assuan_strerror (AssuanError err); /*-- assuan-logging.c --*/ -/* Set the stream to which assuan should log. By default, this is - stderr. */ +/* Set the stream to which assuan should log message not associated + with a context. By default, this is stderr. The default value + will be changed when the first log stream is associated with a + context. Note, that this function is not thread-safe and should + in general be used right at startup. */ extern void assuan_set_assuan_log_stream (FILE *fp); -/* Return the stream which is currently being using for logging. */ +/* Return the stream which is currently being using for global logging. */ extern FILE *assuan_get_assuan_log_stream (void); -/* User defined call back. Return a prefix to be used at the start of - a line emitted by assuan on the log stream. The default - implementation returns the empty string, i.e. "" */ -extern const char *assuan_get_assuan_log_prefix (void); +/* Set the prefix to be used at the start of a line emitted by assuan + on the log stream. The default is the empty string. Note, that + this function is not thread-safe and should in general be used + right at startup. */ +void assuan_set_assuan_log_prefix (const char *text); + +/* Return a prefix to be used at the start of a line emitted by assuan + on the log stream. The default implementation returns the empty + string, i.e. "" */ +const char *assuan_get_assuan_log_prefix (void); #ifdef __cplusplus } |