aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-buffer.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2004-05-11 09:14:56 +0000
committerWerner Koch <[email protected]>2004-05-11 09:14:56 +0000
commit2284687515072f8824dc352e8d90bcdace558fee (patch)
treefe57cf5439963a3a3c8ac53c513c77d5b014a6e1 /src/assuan-buffer.c
parentpost release version bump (diff)
downloadlibassuan-2284687515072f8824dc352e8d90bcdace558fee.tar.gz
libassuan-2284687515072f8824dc352e8d90bcdace558fee.zip
* assuan-listen.c (assuan_set_hello_line, assuan_accept): Allow
for multi line hello strings. * assuan-buffer.c (_assuan_write_line): New with parts of .. (assuan_write_line): .. factored out.
Diffstat (limited to 'src/assuan-buffer.c')
-rw-r--r--src/assuan-buffer.c78
1 files changed, 57 insertions, 21 deletions
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index dbb3604..6d81441 100644
--- a/src/assuan-buffer.c
+++ b/src/assuan-buffer.c
@@ -1,5 +1,5 @@
/* assuan-buffer.c - read and send data
- * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -227,29 +227,33 @@ assuan_pending_line (ASSUAN_CONTEXT ctx)
}
-AssuanError
-assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
+assuan_error_t
+_assuan_write_line (assuan_context_t ctx, const char *prefix,
+ const char *line, size_t len)
{
- int rc;
- size_t len;
- const char *s;
+ int rc = 0;
+ size_t prefixlen = prefix? strlen (prefix):0;
- if (!ctx)
- return ASSUAN_Invalid_Value;
-
- /* Make sure that we never take a LF from the user - this might
- violate the protocol. */
- s = strchr (line, '\n');
- len = s? (s-line) : strlen (line);
+ /* Make sure that the line is short enough. */
+ if (len + prefixlen + 2 > ASSUAN_LINELENGTH)
+ {
+ if (ctx->log_fp)
+ fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> "
+ "[supplied line too long -truncated]\n",
+ assuan_get_assuan_log_prefix (),
+ (unsigned int)getpid (), ctx);
+ if (prefixlen > 5)
+ prefixlen = 5;
+ if (len > ASSUAN_LINELENGTH - prefixlen - 2)
+ len = ASSUAN_LINELENGTH - prefixlen - 2 - 1;
+ }
- /* fixme: we should do some kind of line buffering. */
+ /* Fixme: we should do some kind of line buffering. */
if (ctx->log_fp)
{
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)
fputs ("[Confidential data not shown]", ctx->log_fp);
else
@@ -257,20 +261,52 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
putc ('\n', ctx->log_fp);
}
- rc = writen (ctx, line, len);
- if (rc)
- rc = ASSUAN_Write_Error;
+ if (prefixlen)
+ {
+ rc = writen (ctx, prefix, prefixlen);
+ if (rc)
+ rc = ASSUAN_Write_Error;
+ }
if (!rc)
{
- rc = writen (ctx, "\n", 1);
+ rc = writen (ctx, line, len);
if (rc)
rc = ASSUAN_Write_Error;
+ if (!rc)
+ {
+ rc = writen (ctx, "\n", 1);
+ if (rc)
+ rc = ASSUAN_Write_Error;
+ }
}
-
return rc;
}
+AssuanError
+assuan_write_line (ASSUAN_CONTEXT ctx, const char *line)
+{
+ size_t len;
+ const char *s;
+
+ if (!ctx)
+ return ASSUAN_Invalid_Value;
+
+ /* Make sure that we never take a LF from the user - this might
+ violate the protocol. */
+ s = strchr (line, '\n');
+ len = s? (s-line) : strlen (line);
+
+ if (ctx->log_fp && s)
+ fprintf (ctx->log_fp, "%s[%u.%p] DBG: -> "
+ "[supplied line contained a LF -truncated]\n",
+ assuan_get_assuan_log_prefix (),
+ (unsigned int)getpid (), ctx);
+
+ return _assuan_write_line (ctx, NULL, line, len);
+}
+
+
/* Write out the data in buffer as datalines with line wrapping and
percent escaping. This function is used for GNU's custom streams */