[Pkg-gnupg-commit] [libassuan] 66/437: 2003-02-17 Neal H. Walfield <neal at g10code.de>
Eric Dorland
eric at moszumanska.debian.org
Fri May 22 05:33:24 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libassuan.
commit 95f307d9b5511ba70fa92838b2b13f6b42776205
Author: Neal Walfield <neal at walfield.org>
Date: Tue Feb 18 02:41:58 2003 +0000
2003-02-17 Neal H. Walfield <neal at g10code.de>
* Makefile.am (lib_LIBRARIES): Use this instead of . . .
(noinst_LIBRARIES): . . . this.
(include_HEADERS): New variable.
(libassuan_a_SOURCES): Remove assuan.h, add assuan-logging.c.
* assuan.h (assuan_set_assuan_log_stream): New prototype.
(assuan_get_assuan_log_stream): Likewise.
(assuan_get_assuan_log_prefix): Likewise.
* assuan-logging.c: New file.
* assuan-buffer.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(my_log_prefix): Remove function.
(_assuan_read_line): Use assuan_get_assuan_log_prefix in lieu of
my_log_prefix.
(assuan_write_line): Likewise.
(_assuan_cookie_write_data): Likewise.
(_assuan_cookie_write_flush): Likewise.
* assuan-domain-connect.c (LOGERROR, LOGERROR1, LOGERROR2,
LOGERRORX): Remove.
(LOG): New macro.
(domain_reader): Use it.
(domain_writer): Likewise.
(domain_sendfd): Likewise.
(domain_receivefd): Likewise.
(_assuan_domain_init): Likewise.
(assuan_domain_connect): Likewise.
* assuan-pipe-connect.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(LOGERROR, LOGERROR1, LOGERROR2, LOGERRORX): Remove.
(LOG): New macro.
(assuan_pipe_connect): Use it.
* assuan-socket-connect.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(LOGERROR, LOGERROR1, LOGERROR2, LOGERRORX): Remove.
(LOG): New macro.
(assuan_socket_connect): Use it.
(socket_reader): Remove dead code.
(socket_writer): Likewise.
* assuan-util.c [HAVE_JNLIB_LOGGIN]: Do not include
"../jnlib/logging.h".
(_assuan_log_sanitized_string): Use assuan_get_assuan_log_stream,
not jnlib.
---
src/ChangeLog | 51 +++++++++++++++++++---
src/Makefile.am | 9 ++--
src/assuan-buffer.c | 65 ++++++++++++----------------
src/assuan-domain-connect.c | 81 ++++++++++++++++-------------------
src/assuan-inquire.c | 3 +-
src/assuan-io.c | 2 +-
src/assuan-listen.c | 2 +-
src/{assuan-io.c => assuan-logging.c} | 29 +++++++------
src/assuan-pipe-connect.c | 68 ++++++++++++++---------------
src/assuan-socket-connect.c | 71 ++++++++----------------------
src/assuan-util.c | 15 +------
src/assuan.h | 31 ++++++++++----
12 files changed, 205 insertions(+), 222 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 3fbe19d..0e65c29 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,49 @@
+2003-02-17 Neal H. Walfield <neal at g10code.de>
+
+ * Makefile.am (lib_LIBRARIES): Use this instead of . . .
+ (noinst_LIBRARIES): . . . this.
+ (include_HEADERS): New variable.
+ (libassuan_a_SOURCES): Remove assuan.h, add assuan-logging.c.
+
+ * assuan.h (assuan_set_assuan_log_stream): New prototype.
+ (assuan_get_assuan_log_stream): Likewise.
+ (assuan_get_assuan_log_prefix): Likewise.
+ * assuan-logging.c: New file.
+
+ * assuan-buffer.c [HAVE_JNLIB_LOGGIN]: Do not include
+ "../jnlib/logging.h".
+ (my_log_prefix): Remove function.
+ (_assuan_read_line): Use assuan_get_assuan_log_prefix in lieu of
+ my_log_prefix.
+ (assuan_write_line): Likewise.
+ (_assuan_cookie_write_data): Likewise.
+ (_assuan_cookie_write_flush): Likewise.
+ * assuan-domain-connect.c (LOGERROR, LOGERROR1, LOGERROR2,
+ LOGERRORX): Remove.
+ (LOG): New macro.
+ (domain_reader): Use it.
+ (domain_writer): Likewise.
+ (domain_sendfd): Likewise.
+ (domain_receivefd): Likewise.
+ (_assuan_domain_init): Likewise.
+ (assuan_domain_connect): Likewise.
+ * assuan-pipe-connect.c [HAVE_JNLIB_LOGGIN]: Do not include
+ "../jnlib/logging.h".
+ (LOGERROR, LOGERROR1, LOGERROR2, LOGERRORX): Remove.
+ (LOG): New macro.
+ (assuan_pipe_connect): Use it.
+ * assuan-socket-connect.c [HAVE_JNLIB_LOGGIN]: Do not include
+ "../jnlib/logging.h".
+ (LOGERROR, LOGERROR1, LOGERROR2, LOGERRORX): Remove.
+ (LOG): New macro.
+ (assuan_socket_connect): Use it.
+ (socket_reader): Remove dead code.
+ (socket_writer): Likewise.
+ * assuan-util.c [HAVE_JNLIB_LOGGIN]: Do not include
+ "../jnlib/logging.h".
+ (_assuan_log_sanitized_string): Use assuan_get_assuan_log_stream,
+ not jnlib.
+
2002-11-24 Neal H. Walfield <neal at g10code.de>
* assuan.h (assuan_command_parse_fd): New prototype.
@@ -378,11 +424,6 @@
* assuan-defs.h: Add space in the context for this.
- ***********************************************************
- * Please note that Assuan is maintained as part of GnuPG. *
- * You may find it source-copied in other packages. *
- ***********************************************************
-
Copyright 2001, 2002 Free Software Foundation, Inc.
This file is free software; as a special exception the author gives
diff --git a/src/Makefile.am b/src/Makefile.am
index f741a25..7948802 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
# Assuan Makefile
-# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
#
# This file is part of Assuan.
#
@@ -24,12 +24,12 @@ INCLUDES = -I.. -I$(top_srcdir)/include
BUILT_SOURCES = assuan-errors.c
MOSTLYCLEANFILES = assuan-errors.c
-noinst_LIBRARIES = libassuan.a
+lib_LIBRARIES = libassuan.a
+include_HEADERS = assuan.h
#libassuan_a_LDFLAGS =
libassuan_a_SOURCES = \
- assuan.h \
assuan-defs.h \
assuan-util.c \
assuan-errors.c \
@@ -45,7 +45,8 @@ libassuan_a_SOURCES = \
assuan-socket-connect.c \
assuan-io.c \
assuan-domain-connect.c \
- assuan-domain-server.c
+ assuan-domain-server.c \
+ assuan-logging.c
assuan-errors.c : assuan.h
$(srcdir)/mkerrors < $(srcdir)/assuan.h > assuan-errors.c
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index bbe3990..59518f2 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 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -27,22 +27,6 @@
#include <assert.h>
#include "assuan-defs.h"
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#endif
-
-
-static const char *
-my_log_prefix (void)
-{
-#ifdef HAVE_JNLIB_LOGGING
- return log_get_prefix (NULL);
-#else
- return "";
-#endif
-}
-
-
static int
writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length)
{
@@ -141,16 +125,17 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
if (rc)
{
if (ctx->log_fp)
- fprintf (ctx->log_fp, "%s[%p] <- [Error: %s]\n",
- my_log_prefix (), ctx, strerror (errno));
+ fprintf (ctx->log_fp, "%s[%p] <- [Error: %s]\n",
+ assuan_get_assuan_log_prefix (), 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", my_log_prefix (),ctx);
- return -1;
+ fprintf (ctx->log_fp, "%s[%p] <- [EOF]\n",
+ assuan_get_assuan_log_prefix (), ctx);
+ return -1;
}
ctx->inbound.attic.pending = 0;
@@ -180,11 +165,12 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
ctx->inbound.linelen = endp - line;
if (ctx->log_fp)
{
- fprintf (ctx->log_fp, "%s[%p] <- ", my_log_prefix (), ctx);
+ fprintf (ctx->log_fp, "%s[%p] <- ",
+ assuan_get_assuan_log_prefix (), ctx);
if (ctx->confidential)
fputs ("[Confidential data not shown]", ctx->log_fp);
else
- _assuan_log_print_buffer (ctx->log_fp,
+ _assuan_log_print_buffer (ctx->log_fp,
ctx->inbound.line,
ctx->inbound.linelen);
putc ('\n', ctx->log_fp);
@@ -195,7 +181,7 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
{
if (ctx->log_fp)
fprintf (ctx->log_fp, "%s[%p] <- [Invalid line]\n",
- my_log_prefix (), ctx);
+ assuan_get_assuan_log_prefix (), ctx);
*line = 0;
ctx->inbound.linelen = 0;
return ctx->inbound.eof ? ASSUAN_Line_Not_Terminated
@@ -255,13 +241,14 @@ 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] -> ", my_log_prefix (), ctx);
+ fprintf (ctx->log_fp, "%s[%p] -> ",
+ assuan_get_assuan_log_prefix (), ctx);
if (s)
- fputs ("[supplied line contained a LF]", ctx->log_fp);
+ fputs ("[supplied line contained a LF]", ctx->log_fp);
if (ctx->confidential)
- fputs ("[Confidential data not shown]", ctx->log_fp);
+ fputs ("[Confidential data not shown]", ctx->log_fp);
else
- _assuan_log_print_buffer (ctx->log_fp, line, len);
+ _assuan_log_print_buffer (ctx->log_fp, line, len);
putc ('\n', ctx->log_fp);
}
@@ -327,7 +314,9 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size)
{
if (ctx->log_fp)
{
- fprintf (ctx->log_fp, "%s[%p] -> ", my_log_prefix (), ctx);
+ fprintf (ctx->log_fp, "%s[%p] -> ",
+ assuan_get_assuan_log_prefix (), ctx);
+
if (ctx->confidential)
fputs ("[Confidential data not shown]", ctx->log_fp);
else
@@ -371,15 +360,15 @@ _assuan_cookie_write_flush (void *cookie)
if (linelen)
{
if (ctx->log_fp)
- {
- fprintf (ctx->log_fp, "%s[%p] -> ", my_log_prefix (), 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);
+ {
+ fprintf (ctx->log_fp, "%s[%p] -> ",
+ assuan_get_assuan_log_prefix (), 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++;
diff --git a/src/assuan-domain-connect.c b/src/assuan-domain-connect.c
index b4ce519..49dcb55 100644
--- a/src/assuan-domain-connect.c
+++ b/src/assuan-domain-connect.c
@@ -1,5 +1,5 @@
/* assuan-domain-connect.c - Assuan unix domain socket based client
- * Copyright (C) 2002 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -36,18 +36,11 @@
#include "assuan-defs.h"
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#define LOGERROR(a) log_error ((a))
-#define LOGERROR1(a,b) log_error ((a), (b))
-#define LOGERROR2(a,b,c) log_error ((a), (b), (c))
-#define LOGERRORX(a) log_printf ((a))
-#else
-#define LOGERROR(a) fprintf (stderr, (a))
-#define LOGERROR1(a,b) fprintf (stderr, (a), (b))
-#define LOGERROR2(a,b,c) fprintf (stderr, (a), (b), (c))
-#define LOGERRORX(a) fputs ((a), stderr)
-#endif
+#define LOG(format, args...) \
+ fprintf (assuan_get_assuan_log_stream (), \
+ assuan_get_assuan_log_prefix (), \
+ "%s" format , ## args)
+
static void
do_deinit (ASSUAN_CONTEXT ctx)
@@ -91,11 +84,12 @@ domain_reader (ASSUAN_CONTEXT ctx, void *buf, size_t buflen)
struct msghdr msg;
struct iovec iovec;
struct sockaddr_un sender;
- struct
+ struct
{
struct cmsghdr hdr;
int fd;
- } cmsg;
+ }
+ cmsg;
memset (&msg, 0, sizeof (msg));
@@ -169,15 +163,15 @@ domain_reader (ASSUAN_CONTEXT ctx, void *buf, size_t buflen)
/* XXX: Arg. Not from whom we expected! What do we want to
do? Should we just ignore it? We shall do the latter
for the moment. */
- LOGERROR1 ("Not setup to receive messages from: `%s'.",
- ((struct sockaddr_un *) msg.msg_name)->sun_path);
+ LOG ("Not setup to receive messages from: `%s'.",
+ ((struct sockaddr_un *) msg.msg_name)->sun_path);
goto start;
}
len = recvmsg (ctx->inbound.fd, &msg, 0);
if (len < 0)
{
- LOGERROR1 ("domain_reader: %s\n", strerror (errno));
+ LOG ("domain_reader: %s\n", strerror (errno));
return -1;
}
@@ -193,16 +187,16 @@ domain_reader (ASSUAN_CONTEXT ctx, void *buf, size_t buflen)
sizeof (int) * (ctx->pendingfdscount + 1));
if (! tmp)
{
- LOGERROR1 ("domain_reader: %s\n", strerror (errno));
+ LOG ("domain_reader: %s\n", strerror (errno));
return -1;
}
ctx->pendingfds = tmp;
- ctx->pendingfds[ctx->pendingfdscount ++]
- = * (int *) CMSG_DATA (&cmsg.hdr);
+ ctx->pendingfds[ctx->pendingfdscount++]
+ = *(int *) CMSG_DATA (&cmsg.hdr);
- LOGERROR1 ("Received file descriptor %d from peer.\n",
- ctx->pendingfds[ctx->pendingfdscount - 1]);
+ LOG ("Received file descriptor %d from peer.\n",
+ ctx->pendingfds[ctx->pendingfdscount - 1]);
}
if (len == 0)
@@ -247,7 +241,7 @@ domain_writer (ASSUAN_CONTEXT ctx, const void *buf, size_t buflen)
len = sendmsg (ctx->outbound.fd, &msg, 0);
if (len < 0)
- LOGERROR1 ("domain_writer: %s\n", strerror (errno));
+ LOG ("domain_writer: %s\n", strerror (errno));
return len;
}
@@ -256,11 +250,12 @@ static AssuanError
domain_sendfd (ASSUAN_CONTEXT ctx, int fd)
{
struct msghdr msg;
- struct
+ struct
{
struct cmsghdr hdr;
int fd;
- } cmsg;
+ }
+ cmsg;
int len;
memset (&msg, 0, sizeof (msg));
@@ -279,12 +274,12 @@ domain_sendfd (ASSUAN_CONTEXT ctx, int fd)
msg.msg_control = &cmsg;
msg.msg_controllen = sizeof (cmsg);
- * (int *) CMSG_DATA (&cmsg.hdr) = fd;
+ *(int *) CMSG_DATA (&cmsg.hdr) = fd;
len = sendmsg (ctx->outbound.fd, &msg, 0);
if (len < 0)
{
- LOGERROR1 ("domain_sendfd: %s\n", strerror (errno));
+ LOG ("domain_sendfd: %s\n", strerror (errno));
return ASSUAN_General_Error;
}
else
@@ -296,7 +291,7 @@ domain_receivefd (ASSUAN_CONTEXT ctx, int *fd)
{
if (ctx->pendingfds == 0)
{
- LOGERROR ("No pending file descriptors!\n");
+ LOG ("No pending file descriptors!\n");
return ASSUAN_General_Error;
}
@@ -324,9 +319,7 @@ domain_receivefd (ASSUAN_CONTEXT ctx, int *fd)
Assuan context in CTX. SERVER_PID is currently not used but may
become handy in the future. */
AssuanError
-_assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
- int rendezvousfd,
- pid_t peer)
+_assuan_domain_init (ASSUAN_CONTEXT *r_ctx, int rendezvousfd, pid_t peer)
{
static struct assuan_io io = { domain_reader, domain_writer,
domain_sendfd, domain_receivefd };
@@ -356,7 +349,7 @@ _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
fd = socket (PF_LOCAL, SOCK_DGRAM, 0);
if (fd == -1)
{
- LOGERROR1 ("can't create socket: %s\n", strerror (errno));
+ LOG ("can't create socket: %s\n", strerror (errno));
_assuan_release_context (ctx);
return ASSUAN_General_Error;
}
@@ -387,13 +380,13 @@ _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
p = tmpnam (buf);
if (! p)
{
- LOGERROR ("cannot determine an appropriate temporary file "
- "name. DOS in progress?\n");
+ LOG ("cannot determine an appropriate temporary file "
+ "name. DOS in progress?\n");
_assuan_release_context (ctx);
close (fd);
return ASSUAN_General_Error;
}
-
+
memset (&ctx->myaddr, 0, sizeof ctx->myaddr);
ctx->myaddr.sun_family = AF_LOCAL;
len = strlen (buf) + 1;
@@ -407,8 +400,8 @@ _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
if (err)
{
- LOGERROR2 ("can't bind to `%s': %s\n", ctx->myaddr.sun_path,
- strerror (errno));
+ LOG ("can't bind to `%s': %s\n", ctx->myaddr.sun_path,
+ strerror (errno));
_assuan_release_context (ctx);
close (fd);
return ASSUAN_Connect_Failed;
@@ -422,7 +415,7 @@ _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
fp = fdopen (rendezvousfd, "w+");
if (! fp)
{
- LOGERROR1 ("can't open rendezvous port: %s\n", strerror (errno));
+ LOG ("can't open rendezvous port: %s\n", strerror (errno));
return ASSUAN_Connect_Failed;
}
@@ -452,9 +445,7 @@ _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
}
AssuanError
-assuan_domain_connect (ASSUAN_CONTEXT *r_ctx,
- int rendezvousfd,
- pid_t peer)
+assuan_domain_connect (ASSUAN_CONTEXT * r_ctx, int rendezvousfd, pid_t peer)
{
AssuanError aerr;
int okay, off;
@@ -466,12 +457,12 @@ assuan_domain_connect (ASSUAN_CONTEXT *r_ctx,
/* Initial handshake. */
aerr = _assuan_read_from_server (*r_ctx, &okay, &off);
if (aerr)
- LOGERROR1 ("can't connect to server: %s\n", assuan_strerror (aerr));
+ LOG ("can't connect to server: %s\n", assuan_strerror (aerr));
else if (okay != 1)
{
- LOGERROR ("can't connect to server: `");
+ LOG ("can't connect to server: `");
_assuan_log_sanitized_string ((*r_ctx)->inbound.line);
- LOGERRORX ("'\n");
+ fprintf (assuan_get_assuan_log_stream (), "'\n");
aerr = ASSUAN_Connect_Failed;
}
diff --git a/src/assuan-inquire.c b/src/assuan-inquire.c
index 197e210..f4336cb 100644
--- a/src/assuan-inquire.c
+++ b/src/assuan-inquire.c
@@ -31,7 +31,8 @@
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
-struct membuf {
+struct membuf
+{
size_t len;
size_t size;
char *buf;
diff --git a/src/assuan-io.c b/src/assuan-io.c
index 924a4ec..b10571b 100644
--- a/src/assuan-io.c
+++ b/src/assuan-io.c
@@ -1,4 +1,4 @@
-/* assuan-buffer.c - Wraps the read and write functions.
+/* assuan-io.c - Wraps the read and write functions.
* Copyright (C) 2002 Free Software Foundation, Inc.
*
* This file is part of Assuan.
diff --git a/src/assuan-listen.c b/src/assuan-listen.c
index 3d4ee5f..aae3f7b 100644
--- a/src/assuan-listen.c
+++ b/src/assuan-listen.c
@@ -54,7 +54,7 @@ assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line)
* assuan_accept:
* @ctx: context
*
- * Cancel any existing connectiion and wait for a connection from a
+ * Cancel any existing connection and wait for a connection from a
* client. The initial handshake is performed which may include an
* initial authentication or encryption negotiation.
*
diff --git a/src/assuan-io.c b/src/assuan-logging.c
similarity index 56%
copy from src/assuan-io.c
copy to src/assuan-logging.c
index 924a4ec..340ce72 100644
--- a/src/assuan-io.c
+++ b/src/assuan-logging.c
@@ -1,5 +1,5 @@
-/* assuan-buffer.c - Wraps the read and write functions.
- * Copyright (C) 2002 Free Software Foundation, Inc.
+/* assuan-logging.c - Default logging function.
+ * Copyright (C) 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -19,23 +19,24 @@
*/
#include "assuan-defs.h"
-#include <sys/types.h>
-#include <unistd.h>
+#include <stdio.h>
-extern ssize_t pth_read (int fd, void *buffer, size_t size);
-extern ssize_t pth_write (int fd, const void *buffer, size_t size);
+static FILE *_assuan_log;
-#pragma weak pth_read
-#pragma weak pth_write
+void
+assuan_set_assuan_log_stream (FILE *fp)
+{
+ _assuan_log = fp;
+}
-ssize_t
-_assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size)
+FILE *
+assuan_get_assuan_log_stream (void)
{
- return (pth_read ? pth_read : read) (ctx->inbound.fd, buffer, size);
+ return _assuan_log ? _assuan_log : stderr;
}
-ssize_t
-_assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer, size_t size)
+const char *
+assuan_get_assuan_log_prefix (void)
{
- return (pth_write ? pth_write : write) (ctx->outbound.fd, buffer, size);
+ return "";
}
diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c
index d7595c9..d30c106 100644
--- a/src/assuan-pipe-connect.c
+++ b/src/assuan-pipe-connect.c
@@ -1,5 +1,5 @@
/* assuan-pipe-connect.c - Establish a pipe connection (client)
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -40,17 +40,13 @@
#define MAX_OPEN_FDS 20
#endif
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#define LOGERROR1(a,b) log_error ((a), (b))
-#else
-#define LOGERROR1(a,b) fprintf (stderr, (a), (b))
-#endif
-
-
+#define LOG(format, args...) \
+ fprintf (assuan_get_assuan_log_stream (), \
+ assuan_get_assuan_log_prefix (), \
+ "%s" format , ## args)
static int
-writen ( int fd, const char *buffer, size_t length )
+writen (int fd, const char *buffer, size_t length)
{
while (length)
{
@@ -174,21 +170,21 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
/* Dup handles to stdin/stdout. */
if (rp[1] != STDOUT_FILENO)
- {
- if (dup2 (rp[1], STDOUT_FILENO) == -1)
- {
- LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno));
- _exit (4);
- }
- }
+ {
+ if (dup2 (rp[1], STDOUT_FILENO) == -1)
+ {
+ LOG ("dup2 failed in child: %s\n", strerror (errno));
+ _exit (4);
+ }
+ }
if (wp[0] != STDIN_FILENO)
- {
- if (dup2 (wp[0], STDIN_FILENO) == -1)
- {
- LOGERROR1 ("dup2 failed in child: %s\n", strerror (errno));
- _exit (4);
- }
- }
+ {
+ if (dup2 (wp[0], STDIN_FILENO) == -1)
+ {
+ LOG ("dup2 failed in child: %s\n", strerror (errno));
+ _exit (4);
+ }
+ }
/* Dup stderr to /dev/null unless it is in the list of FDs to be
passed to the child. */
@@ -203,15 +199,15 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
int fd = open ("/dev/null", O_WRONLY);
if (fd == -1)
{
- LOGERROR1 ("can't open `/dev/null': %s\n", strerror (errno));
+ LOG ("can't open `/dev/null': %s\n", strerror (errno));
_exit (4);
- }
- if (dup2 (fd, STDERR_FILENO) == -1)
- {
- LOGERROR1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno));
- _exit (4);
- }
- }
+ }
+ if (dup2 (fd, STDERR_FILENO) == -1)
+ {
+ LOG ("dup2(dev/null, 2) failed: %s\n", strerror (errno));
+ _exit (4);
+ }
+ }
/* Close all files which will not be duped and are not in the
@@ -253,13 +249,11 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[],
err = _assuan_read_from_server (*ctx, &okay, &off);
if (err)
- {
- LOGERROR1 ("can't connect server: %s\n", assuan_strerror (err));
- }
+ LOG ("can't connect server: %s\n", assuan_strerror (err));
else if (okay != 1)
{
- LOGERROR1 ("can't connect server: `%s'\n", (*ctx)->inbound.line);
- err = ASSUAN_Connect_Failed;
+ LOG ("can't connect server: `%s'\n", (*ctx)->inbound.line);
+ err = ASSUAN_Connect_Failed;
}
}
diff --git a/src/assuan-socket-connect.c b/src/assuan-socket-connect.c
index a1bec84..a7246cc 100644
--- a/src/assuan-socket-connect.c
+++ b/src/assuan-socket-connect.c
@@ -1,5 +1,5 @@
/* assuan-socket-connect.c - Assuan socket based client
- * Copyright (C) 2002 Free Software Foundation, Inc.
+ * Copyright (C) 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -29,20 +29,10 @@
#include "assuan-defs.h"
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#define LOGERROR(a) log_error ((a))
-#define LOGERROR1(a,b) log_error ((a), (b))
-#define LOGERROR2(a,b,c) log_error ((a), (b), (c))
-#define LOGERRORX(a) log_printf ((a))
-#else
-#define LOGERROR(a) fprintf (stderr, (a))
-#define LOGERROR1(a,b) fprintf (stderr, (a), (b))
-#define LOGERROR2(a,b,c) fprintf (stderr, (a), (b), (c))
-#define LOGERRORX(a) fputs ((a), stderr)
-#endif
-
-
+#define LOG(format, args...) \
+ fprintf (assuan_get_assuan_log_stream (), \
+ assuan_get_assuan_log_prefix (), \
+ "%s" format , ## args)
static int
do_finish (ASSUAN_CONTEXT ctx)
@@ -61,29 +51,6 @@ do_deinit (ASSUAN_CONTEXT ctx)
{
do_finish (ctx);
}
-
-
-/* Read from the socket server. */
-static ssize_t
-socket_reader (ASSUAN_CONTEXT ctx, void *buf, size_t buflen)
-{
-#pragma weak pth_read
- extern ssize_t pth_read (int, void *, size_t);
-
- return (pth_read ? pth_read : read) (ctx->inbound.fd, buf, buflen);
-}
-
-/* Write to the pipe server. */
-static ssize_t
-socket_writer (ASSUAN_CONTEXT ctx, const void *buf, size_t buflen)
-{
-#pragma weak pth_write
-
- extern ssize_t pth_write (int, const void *, size_t);
-
- return (pth_write ? pth_write : write) (ctx->outbound.fd, buf, buflen);
-}
-
/* Make a connection to the Unix domain socket NAME and return a new
Assuan context in CTX. SERVER_PID is currently not used but may
become handy in the future. */
@@ -121,22 +88,22 @@ assuan_socket_connect (ASSUAN_CONTEXT *r_ctx,
fd = socket (PF_LOCAL, SOCK_STREAM, 0);
if (fd == -1)
{
- LOGERROR1 ("can't create socket: %s\n", strerror (errno));
+ LOG ("can't create socket: %s\n", strerror (errno));
_assuan_release_context (ctx);
return ASSUAN_General_Error;
}
-
- memset (&srvr_addr, 0, sizeof srvr_addr );
+
+ memset (&srvr_addr, 0, sizeof srvr_addr);
srvr_addr.sun_family = AF_LOCAL;
len = strlen (srvr_addr.sun_path) + 1;
memcpy (srvr_addr.sun_path, name, len);
len += (offsetof (struct sockaddr_un, sun_path));
-
- if (connect (fd, (struct sockaddr*)&srvr_addr, len) == -1)
+
+ if (connect (fd, (struct sockaddr *) &srvr_addr, len) == -1)
{
- LOGERROR2 ("can't connect to `%s': %s\n", name, strerror (errno));
+ LOG ("can't connect to `%s': %s\n", name, strerror (errno));
_assuan_release_context (ctx);
- close (fd );
+ close (fd);
return ASSUAN_Connect_Failed;
}
@@ -150,15 +117,13 @@ assuan_socket_connect (ASSUAN_CONTEXT *r_ctx,
err = _assuan_read_from_server (ctx, &okay, &off);
if (err)
- {
- LOGERROR1 ("can't connect server: %s\n", assuan_strerror (err));
- }
+ LOG ("can't connect to server: %s\n", assuan_strerror (err));
else if (okay != 1)
{
- LOGERROR ("can't connect server: `");
- _assuan_log_sanitized_string (ctx->inbound.line);
- LOGERRORX ("'\n");
- err = ASSUAN_Connect_Failed;
+ LOG ("can't connect to server: `");
+ _assuan_log_sanitized_string (ctx->inbound.line);
+ fprintf (assuan_get_assuan_log_stream (), "'\n");
+ err = ASSUAN_Connect_Failed;
}
}
@@ -170,5 +135,3 @@ assuan_socket_connect (ASSUAN_CONTEXT *r_ctx,
*r_ctx = ctx;
return 0;
}
-
-
diff --git a/src/assuan-util.c b/src/assuan-util.c
index 76f7f06..fc0beed 100644
--- a/src/assuan-util.c
+++ b/src/assuan-util.c
@@ -1,5 +1,5 @@
/* assuan-util.c - Utility functions for Assuan
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -26,10 +26,6 @@
#include "assuan-defs.h"
-#ifdef HAVE_JNLIB_LOGGING
-#include "../jnlib/logging.h"
-#endif
-
static void *(*alloc_func)(size_t n) = malloc;
static void *(*realloc_func)(void *p, size_t n) = realloc;
static void (*free_func)(void*) = free;
@@ -159,18 +155,13 @@ _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length)
}
}
-
/* Log a user supplied string. Escapes non-printable before
printing. */
void
_assuan_log_sanitized_string (const char *string)
{
const unsigned char *s = string;
-#ifdef HAVE_JNLIB_LOGGING
- FILE *fp = log_get_stream ();
-#else
- FILE *fp = stderr;
-#endif
+ FILE *fp = assuan_get_assuan_log_stream ();
if (! *s)
return;
@@ -226,5 +217,3 @@ _assuan_log_sanitized_string (const char *string)
funlockfile (fp);
#endif
}
-
-
diff --git a/src/assuan.h b/src/assuan.h
index 37bdd69..5f53827 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -1,5 +1,5 @@
/* assuan.c - Definitions for the Assuan protocol
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Assuan.
*
@@ -26,18 +26,17 @@
#include <unistd.h>
#ifdef __cplusplus
-extern "C" {
-#if 0
- }
-#endif
+extern "C"
+{
#endif
-typedef enum {
+typedef enum
+{
ASSUAN_No_Error = 0,
ASSUAN_General_Error = 1,
ASSUAN_Out_Of_Core = 2,
ASSUAN_Invalid_Value = 3,
- ASSUAN_Timeout = 4,
+ ASSUAN_Timeout = 4,
ASSUAN_Read_Error = 5,
ASSUAN_Write_Error = 6,
ASSUAN_Problem_Starting_Server = 7,
@@ -105,7 +104,8 @@ typedef enum {
} AssuanError;
/* This is a list of pre-registered ASSUAN commands */
-typedef enum {
+typedef enum
+{
ASSUAN_CMD_NOP = 0,
ASSUAN_CMD_CANCEL, /* cancel the current request */
ASSUAN_CMD_BYE,
@@ -257,8 +257,21 @@ void assuan_end_confidential (ASSUAN_CONTEXT ctx);
/*-- assuan-errors.c (built) --*/
const char *assuan_strerror (AssuanError err);
+/*-- assuan-logging.c --*/
+
+/* Set the stream to which assuan should log. By default, this is
+ stderr. */
+extern void assuan_set_assuan_log_stream (FILE *fp);
+
+/* Return the stream which is currently being using for 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);
#ifdef __cplusplus
}
#endif
-#endif /*ASSUAN_H*/
+#endif /* ASSUAN_H */
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/libassuan.git
More information about the Pkg-gnupg-commit
mailing list