summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-01-10 19:46:04 +0000
committerWerner Koch <wk@gnupg.org>2002-01-10 19:46:04 +0000
commit0ee0e9e344116a48adce8351b9b6ada58ec4df3e (patch)
tree2eb8fc172584a71adb9657c7d5a5f949102cba24
parent09e2199a5394b339192d163ccc2e09660331c6ce (diff)
downloadlibassuan-0ee0e9e344116a48adce8351b9b6ada58ec4df3e.tar.gz
* assuan-handler.c (assuan_set_okay_line): New.
(process_request): And use it here.
-rw-r--r--src/ChangeLog13
-rw-r--r--src/assuan-defs.h1
-rw-r--r--src/assuan-handler.c36
-rw-r--r--src/assuan-inquire.c9
-rw-r--r--src/assuan-pipe-server.c1
-rw-r--r--src/assuan.h1
6 files changed, 56 insertions, 5 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index dbf5f43..e79c2ba 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2002-01-03 Werner Koch <wk@gnupg.org>
+
+ * assuan-handler.c (assuan_set_okay_line): New.
+ (process_request): And use it here.
+
+2002-01-02 Werner Koch <wk@gnupg.org>
+
+ * assuan-inquire.c (init_membuf,put_membuf,get_membuf): Apply a
+ hidden 0 behind the buffer so that the buffer can be used as a
+ string in certain contexts.
+
2001-12-14 Marcus Brinkmann <marcus@g10code.de>
* assuan-connect.c (assuan_pipe_connect): New argument
@@ -90,7 +101,7 @@
* You may find it source-copied in other packages. *
***********************************************************
- Copyright 2001 Free Software Foundation, Inc.
+ Copyright 2001, 2002 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
unlimited permission to copy and/or distribute it, with or without
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index ecabd38..07f56e3 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -39,6 +39,7 @@ struct assuan_context_s {
int is_server; /* set if this is context belongs to a server */
int in_inquire;
char *hello_line;
+ char *okay_line; /* see assan_set_okay_line() */
void *user_pointer; /* for assuan_[gs]et_pointer () */
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index a82bd53..ce7476a 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -382,7 +382,7 @@ process_request (ASSUAN_CONTEXT ctx)
/* Error handling */
if (!rc)
{
- rc = assuan_write_line (ctx, "OK");
+ rc = assuan_write_line (ctx, ctx->okay_line? ctx->okay_line : "OK");
}
else if (rc == -1)
{ /* No error checking because the peer may have already disconnect */
@@ -405,6 +405,11 @@ process_request (ASSUAN_CONTEXT ctx)
rc = assuan_write_line (ctx, errline);
}
+ if (ctx->okay_line)
+ {
+ xfree (ctx->okay_line);
+ ctx->okay_line = NULL;
+ }
return rc;
}
@@ -522,6 +527,35 @@ assuan_get_data_fp (ASSUAN_CONTEXT ctx)
}
+/* Set the text used for the next OK reponse. This string is
+ automatically reset to NULL after the next command. */
+AssuanError
+assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line)
+{
+ if (!ctx)
+ return ASSUAN_Invalid_Value;
+ if (!line)
+ {
+ xfree (ctx->okay_line);
+ ctx->okay_line = NULL;
+ }
+ else
+ {
+ /* FIXME: we need to use gcry_is_secure() to test whether
+ we should allocate the entire line in secure memory */
+ char *buf = xtrymalloc (3+strlen(line)+1);
+ if (!buf)
+ return ASSUAN_Out_Of_Core;
+ strcpy (buf, "OK ");
+ strcpy (buf+3, line);
+ xfree (ctx->okay_line);
+ ctx->okay_line = buf;
+ }
+ return 0;
+}
+
+
+
void
assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text)
{
diff --git a/src/assuan-inquire.c b/src/assuan-inquire.c
index 8fec77e..933091e 100644
--- a/src/assuan-inquire.c
+++ b/src/assuan-inquire.c
@@ -1,5 +1,5 @@
/* assuan-inquire.c - handle inquire stuff
- * Copyright (C) 2001 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -56,7 +56,8 @@ init_membuf (struct membuf *mb, int initiallen, size_t maxlen)
mb->out_of_core = 0;
mb->too_large = 0;
mb->maxlen = maxlen;
- mb->buf = xtrymalloc (initiallen);
+ /* we need to allocate one byte more for get_membuf */
+ mb->buf = xtrymalloc (initiallen+1);
if (!mb->buf)
mb->out_of_core = 1;
}
@@ -78,7 +79,8 @@ put_membuf (struct membuf *mb, const void *buf, size_t len)
char *p;
mb->size += len + 1024;
- p = xtryrealloc (mb->buf, mb->size);
+ /* we need to allocate one byte more for get_membuf */
+ p = xtryrealloc (mb->buf, mb->size+1);
if (!p)
{
mb->out_of_core = 1;
@@ -102,6 +104,7 @@ get_membuf (struct membuf *mb, size_t *len)
return NULL;
}
+ mb->buf[mb->len] = 0; /* there is enough space for the hidden eos */
p = mb->buf;
*len = mb->len;
mb->buf = NULL;
diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c
index 2a9b829..58f981a 100644
--- a/src/assuan-pipe-server.c
+++ b/src/assuan-pipe-server.c
@@ -58,6 +58,7 @@ assuan_deinit_pipe_server (ASSUAN_CONTEXT ctx)
if (ctx)
{
xfree (ctx->hello_line);
+ xfree (ctx->okay_line);
xfree (ctx);
}
}
diff --git a/src/assuan.h b/src/assuan.h
index cddc98c..12f80ca 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -127,6 +127,7 @@ int assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
FILE *assuan_get_data_fp (ASSUAN_CONTEXT ctx);
+AssuanError assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line);
void assuan_write_status (ASSUAN_CONTEXT ctx,
const char *keyword, const char *text);