aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-buffer.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2002-01-19 18:20:15 +0000
committerWerner Koch <[email protected]>2002-01-19 18:20:15 +0000
commitc5698a48387a9b7fb252222eb40c42a7c9f76310 (patch)
treec9a897a17f2b1660beb13aa3a1617f17a5299146 /src/assuan-buffer.c
parent* maperror.c: Add mapping for Not_Trusted. (diff)
downloadlibassuan-c5698a48387a9b7fb252222eb40c42a7c9f76310.tar.gz
libassuan-c5698a48387a9b7fb252222eb40c42a7c9f76310.zip
* assuan-buffer.c (_assuan_read_line): Add output logging.
(assuan_write_line): Ditto. (_assuan_cookie_write_data): Ditto. (_assuan_cookie_write_flush): Ditto. * assuan-util.c (_assuan_log_print_buffer): New. (assuan_set_log_stream): New. (assuan_begin_confidential): New. (assuan_end_confidential): New. * assuan-defs.h: Add a few handler variables. * assuan-pipe-server.c (assuan_deinit_pipe_server): Removed. (deinit_pipe_server): New. (assuan_deinit_server): New. Changed all callers to use this. * assuan-listen.c (assuan_accept): Use the accept handler. * assuan-handler.c (process_request): Use the close Handler. * assuan-socket-server.c: New.
Diffstat (limited to '')
-rw-r--r--src/assuan-buffer.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index 399d11d..bd08817 100644
--- a/src/assuan-buffer.c
+++ b/src/assuan-buffer.c
@@ -20,6 +20,7 @@
#include <config.h>
#include <stdlib.h>
+#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
@@ -119,10 +120,17 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
rc = readline (ctx->inbound.fd, line, LINELENGTH,
&nread, &ctx->inbound.eof);
if (rc)
- return ASSUAN_Read_Error;
+ {
+ if (ctx->log_fp)
+ fprintf (ctx->log_fp, "%p <- [Error: %s]\n",
+ ctx, strerror (errno));
+ return ASSUAN_Read_Error;
+ }
if (!nread)
{
assert (ctx->inbound.eof);
+ if (ctx->log_fp)
+ fprintf (ctx->log_fp, "%p <- [EOF]\n", ctx);
return -1;
}
@@ -153,10 +161,23 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
n--;
line[n] = 0;
ctx->inbound.linelen = n;
+ if (ctx->log_fp)
+ {
+ fprintf (ctx->log_fp, "%p <- ", ctx);
+ if (ctx->confidential)
+ fputs ("[Confidential data not shown]", ctx->log_fp);
+ else
+ _assuan_log_print_buffer (ctx->log_fp,
+ ctx->inbound.line,
+ ctx->inbound.linelen);
+ putc ('\n', ctx->log_fp);
+ }
return 0;
}
}
+ if (ctx->log_fp)
+ fprintf (ctx->log_fp, "%p <- [Invalid line]\n", ctx);
*line = 0;
ctx->inbound.linelen = 0;
return ctx->inbound.eof? ASSUAN_Line_Not_Terminated : ASSUAN_Line_Too_Long;
@@ -206,6 +227,17 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line )
return ASSUAN_Invalid_Value;
/* fixme: we should do some kind of line buffering */
+ if (ctx->log_fp)
+ {
+ fprintf (ctx->log_fp, "%p -> ", ctx);
+ if (ctx->confidential)
+ fputs ("[Confidential data not shown]", ctx->log_fp);
+ else
+ _assuan_log_print_buffer (ctx->log_fp,
+ line, strlen (line));
+ putc ('\n', ctx->log_fp);
+ }
+
rc = writen (ctx->outbound.fd, line, strlen(line));
if (rc)
rc = ASSUAN_Write_Error;
@@ -266,6 +298,17 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size)
if (linelen >= LINELENGTH-2-2)
{
+ if (ctx->log_fp)
+ {
+ fprintf (ctx->log_fp, "%p -> ", ctx);
+ if (ctx->confidential)
+ fputs ("[Confidential data not shown]", ctx->log_fp);
+ else
+ _assuan_log_print_buffer (ctx->log_fp,
+ ctx->outbound.data.line,
+ linelen);
+ putc ('\n', ctx->log_fp);
+ }
*line++ = '\n';
linelen++;
if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen))
@@ -300,6 +343,17 @@ _assuan_cookie_write_flush (void *cookie)
line += linelen;
if (linelen)
{
+ if (ctx->log_fp)
+ {
+ fprintf (ctx->log_fp, "%p -> ", ctx);
+ if (ctx->confidential)
+ fputs ("[Confidential data not shown]", ctx->log_fp);
+ else
+ _assuan_log_print_buffer (ctx->log_fp,
+ ctx->outbound.data.line,
+ linelen);
+ putc ('\n', ctx->log_fp);
+ }
*line++ = '\n';
linelen++;
if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen))