diff options
-rw-r--r-- | src/ChangeLog | 27 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/assuan-buffer.c | 25 | ||||
-rw-r--r-- | src/assuan-defs.h | 20 | ||||
-rw-r--r-- | src/assuan-io.c | 60 | ||||
-rw-r--r-- | src/assuan-pipe-server.c | 28 | ||||
-rw-r--r-- | src/assuan-socket-connect.c | 25 | ||||
-rw-r--r-- | src/assuan-socket-server.c | 2 |
8 files changed, 104 insertions, 86 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 85dc5ef..ebf1764 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,30 @@ +2002-11-20 Neal H. Walfield <[email protected]> + + * assuan-defs.h (struct assuan_io): New structure. + (struct assuan_context_s): New field, io. + (_assuan_read): Depreciated. + (_assuan_write): Likewise. + * assuan-pipe-server.c: Include <unistd.h>. + (pipe_reader): New function. + (pipe_writer): Likewise. + (_assuan_new_context.IO): New local static. Set to pipe_reader + and pipe_writer. Use it to initialize new context. + * assuan-socket-connect.c (socket_reader): New function. + (socket_writer): New function. + (assuan_socket_connect.IO): New local static. Set to socket_reader + and socket_writer. Use it to initialize new context. + * assuan-buffer.c (writen): Take an ASSUAN_CONTEXT rather than a + file descriptor. Do not use _assuan_write but the write method + in the supplied context. + (readline): Likewise for _assuan_read. + (assuan_write_line): When calling writen, pass CTX; not the file + descriptor directly. + (_assuan_cookie_write_data): Likewise. + (_assuan_cookie_write_flush): Likewise. + (_assuan_read_line): Likewise for readline. + * Makefile.am (libassuan_a_SOURCES): Remove assuan-io.c. + * assuan-io.c: Removed. + 2002-11-10 Werner Koch <[email protected]> * assuan-pipe-connect.c (assuan_pipe_connect): Changed the order diff --git a/src/Makefile.am b/src/Makefile.am index 2207145..a97352d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,8 +42,7 @@ libassuan_a_SOURCES = \ assuan-pipe-server.c \ assuan-socket-server.c \ assuan-pipe-connect.c \ - assuan-socket-connect.c \ - assuan-io.c + assuan-socket-connect.c assuan-errors.c : assuan.h diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c index 8017183..515dbf9 100644 --- a/src/assuan-buffer.c +++ b/src/assuan-buffer.c @@ -44,11 +44,11 @@ my_log_prefix (void) static int -writen ( int fd, const char *buffer, size_t length ) +writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length) { while (length) { - ssize_t nwritten = _assuan_write (fd, buffer, length); + ssize_t nwritten = ctx->io->write (ctx, buffer, length); if (nwritten < 0) { @@ -62,9 +62,10 @@ writen ( int fd, const char *buffer, size_t length ) return 0; /* okay */ } -/* read an entire line */ +/* Read an entire line. */ static int -readline (int fd, char *buf, size_t buflen, int *r_nread, int *eof) +readline (ASSUAN_CONTEXT ctx, char *buf, size_t buflen, + int *r_nread, int *eof) { size_t nleft = buflen; char *p; @@ -73,7 +74,7 @@ readline (int fd, char *buf, size_t buflen, int *r_nread, int *eof) *r_nread = 0; while (nleft > 0) { - ssize_t n = _assuan_read (fd, buf, nleft); + ssize_t n = ctx->io->read (ctx, buf, nleft); if (n < 0) { @@ -127,12 +128,12 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) else { /* read the rest */ assert (atticlen < LINELENGTH); - rc = readline (ctx->inbound.fd, line + atticlen, + rc = readline (ctx, line + atticlen, LINELENGTH - atticlen, &nread, &ctx->inbound.eof); } } else - rc = readline (ctx->inbound.fd, line, LINELENGTH, + rc = readline (ctx, line, LINELENGTH, &nread, &ctx->inbound.eof); if (rc) { @@ -233,7 +234,7 @@ assuan_pending_line (ASSUAN_CONTEXT ctx) AssuanError -assuan_write_line (ASSUAN_CONTEXT ctx, const char *line ) +assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) { int rc; size_t len; @@ -260,12 +261,12 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line ) putc ('\n', ctx->log_fp); } - rc = writen (ctx->outbound.fd, line, len); + rc = writen (ctx, line, len); if (rc) rc = ASSUAN_Write_Error; if (!rc) { - rc = writen (ctx->outbound.fd, "\n", 1); + rc = writen (ctx, "\n", 1); if (rc) rc = ASSUAN_Write_Error; } @@ -333,7 +334,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size) } *line++ = '\n'; linelen++; - if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen)) + if (writen (ctx, ctx->outbound.data.line, linelen)) { ctx->outbound.data.error = ASSUAN_Write_Error; return 0; @@ -378,7 +379,7 @@ _assuan_cookie_write_flush (void *cookie) } *line++ = '\n'; linelen++; - if (writen (ctx->outbound.fd, ctx->outbound.data.line, linelen)) + if (writen (ctx, ctx->outbound.data.line, linelen)) { ctx->outbound.data.error = ASSUAN_Write_Error; return 0; diff --git a/src/assuan-defs.h b/src/assuan-defs.h index f885869..a5cd64c 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -32,7 +32,16 @@ struct cmdtbl_s { int (*handler)(ASSUAN_CONTEXT, char *line); }; -struct assuan_context_s { +struct assuan_io +{ + /* Routine to read from input_fd. */ + ssize_t (*read) (ASSUAN_CONTEXT, void *, size_t); + /* Routine to write to output_fd. */ + ssize_t (*write) (ASSUAN_CONTEXT, const void *, size_t); +}; + +struct assuan_context_s +{ AssuanError err_no; const char *err_str; int os_errno; /* last system error number used with certain error codes*/ @@ -99,6 +108,8 @@ struct assuan_context_s { int input_fd; /* set by INPUT command */ int output_fd; /* set by OUTPUT command */ + /* io routines. */ + struct assuan_io *io; }; @@ -136,12 +147,5 @@ 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-io.c --*/ - -/* Wraps the standard read and write functions to do the Right - Thing depending on our linkage. */ -ssize_t _assuan_read (int fd, void *buffer, size_t size); -ssize_t _assuan_write (int fd, const void *buffer, size_t size); - #endif /*ASSUAN_DEFS_H*/ diff --git a/src/assuan-io.c b/src/assuan-io.c deleted file mode 100644 index 135cb02..0000000 --- a/src/assuan-io.c +++ /dev/null @@ -1,60 +0,0 @@ -/* assuan-buffer.c - Wraps the read and write functions. - * Copyright (C) 2002 Free Software Foundation, Inc. - * - * This file is part of Assuan. - * - * Assuan is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * Assuan is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - */ - -#include <sys/types.h> -#include <unistd.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); - -#pragma weak pth_read -#pragma weak pth_write - -ssize_t -_assuan_read (int fd, void *buffer, size_t size) -{ - static ssize_t (*reader) (int, void *, size_t); - - if (! reader) - { - if (pth_read) - reader = pth_read; - else - reader = read; - } - - return reader (fd, buffer, size); -} - -ssize_t -_assuan_write (int fd, const void *buffer, size_t size) -{ - static ssize_t (*writer) (int, const void *, size_t); - - if (! writer) - { - if (pth_write) - writer = pth_write; - else - writer = write; - } - - return writer (fd, buffer, size); -} diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c index 82bb322..73d9de2 100644 --- a/src/assuan-pipe-server.c +++ b/src/assuan-pipe-server.c @@ -21,6 +21,7 @@ #include <config.h> #include <stdlib.h> #include <stdio.h> +#include <unistd.h> #include "assuan-defs.h" @@ -44,12 +45,34 @@ finish_connection (ASSUAN_CONTEXT ctx) return 0; } +/* Read from the pipe server. */ +static ssize_t +pipe_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 +pipe_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); +} /* Create a new context. Note that the handlers are set up for a pipe server/client - this way we don't need extra dummy functions */ int _assuan_new_context (ASSUAN_CONTEXT *r_ctx) { + static struct assuan_io io = { pipe_reader, pipe_writer }; + ASSUAN_CONTEXT ctx; int rc; @@ -62,10 +85,11 @@ _assuan_new_context (ASSUAN_CONTEXT *r_ctx) ctx->inbound.fd = -1; ctx->outbound.fd = -1; + ctx->io = &io; ctx->listen_fd = -1; ctx->client_pid = (pid_t)-1; - /* use the pipe server handler as a default */ + /* Use the pipe server handler as a default. */ ctx->deinit_handler = deinit_pipe_server; ctx->accept_handler = accept_connection; ctx->finish_handler = finish_connection; @@ -116,7 +140,7 @@ assuan_deinit_server (ASSUAN_CONTEXT ctx) if (ctx) { /* We use this function pointer to avoid linking other server - when not needed but still allow for a generic deinit function */ + when not needed but still allow for a generic deinit function. */ ctx->deinit_handler (ctx); ctx->deinit_handler = NULL; _assuan_release_context (ctx); diff --git a/src/assuan-socket-connect.c b/src/assuan-socket-connect.c index 64a22bf..c27c351 100644 --- a/src/assuan-socket-connect.c +++ b/src/assuan-socket-connect.c @@ -63,14 +63,36 @@ do_deinit (ASSUAN_CONTEXT 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. */ + become handy in the future. */ AssuanError assuan_socket_connect (ASSUAN_CONTEXT *r_ctx, const char *name, pid_t server_pid) { + static struct assuan_io io = { socket_reader, socket_writer }; + AssuanError err; ASSUAN_CONTEXT ctx; int fd; @@ -119,6 +141,7 @@ assuan_socket_connect (ASSUAN_CONTEXT *r_ctx, ctx->inbound.fd = fd; ctx->outbound.fd = fd; + ctx->io = &io; /* initial handshake */ { diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c index bfa9cfa..c0a9a25 100644 --- a/src/assuan-socket-server.c +++ b/src/assuan-socket-server.c @@ -145,7 +145,7 @@ assuan_init_connected_socket_server (ASSUAN_CONTEXT *r_ctx, int fd) if (!ctx) return ASSUAN_Out_Of_Core; ctx->is_server = 1; - ctx->pipe_mode = 1; /* we wan't a second accept to indicate EOF */ + ctx->pipe_mode = 1; /* we want a second accept to indicate EOF */ ctx->input_fd = -1; ctx->output_fd = -1; |