diff options
author | Marcus Brinkmann <[email protected]> | 2003-02-01 18:53:06 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2003-02-01 18:53:06 +0000 |
commit | 90beb50551e3fe8be777115cb6ea88b8f54b76b1 (patch) | |
tree | 4fcf705e9b3a2d67932bd201beebd22f4cf46425 /assuan/assuan-socket-server.c | |
parent | 2003-01-30 Marcus Brinkmann <[email protected]> (diff) | |
download | gpgme-90beb50551e3fe8be777115cb6ea88b8f54b76b1.tar.gz gpgme-90beb50551e3fe8be777115cb6ea88b8f54b76b1.zip |
2003-02-01 Marcus Brinkmann <[email protected]>
* assuan/: Update files to 2002-11-10 version of assuan.
gpgme/
2003-02-01 Marcus Brinkmann <[email protected]>
* engine-gpgsm.c (map_assuan_error): Replace
ASSUAN_Bad_Certificate_Path with ASSUAN_Bad_Certificate_Chain.
(gpgsm_new): Use assuan_pipe_connect instead assuan_pipe_connect2.
* util.h (DIMof): Remove macro.
* ops.h (_gpgme_op_event_cb, _gpgme_op_event_cb_user,
_gpgme_data_unread): Prototypes removed.
Diffstat (limited to 'assuan/assuan-socket-server.c')
-rw-r--r-- | assuan/assuan-socket-server.c | 96 |
1 files changed, 63 insertions, 33 deletions
diff --git a/assuan/assuan-socket-server.c b/assuan/assuan-socket-server.c index 39dd84a1..bfa9cfa7 100644 --- a/assuan/assuan-socket-server.c +++ b/assuan/assuan-socket-server.c @@ -1,21 +1,21 @@ /* assuan-socket-server.c - Assuan socket based server * Copyright (C) 2002 Free Software Foundation, Inc. * - * This file is part of GnuPG. + * This file is part of Assuan. * - * GnuPG is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * 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. * - * GnuPG 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 General Public License for more details. + * 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 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 + * 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 <config.h> @@ -25,31 +25,15 @@ #include <sys/socket.h> #include <sys/un.h> #include <unistd.h> -#ifdef USE_GNU_PTH -# include <pth.h> -#endif #include "assuan-defs.h" static int -accept_connection (ASSUAN_CONTEXT ctx) +accept_connection_bottom (ASSUAN_CONTEXT ctx) { - int fd; - struct sockaddr_un clnt_addr; - size_t len = sizeof clnt_addr; + int fd = ctx->connected_fd; ctx->client_pid = (pid_t)-1; -#ifdef USE_GNU_PTH - fd = pth_accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len ); -#else - fd = accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len ); -#endif - if (fd == -1) - { - ctx->os_errno = errno; - return ASSUAN_Accept_Failed; - } - #ifdef HAVE_SO_PEERCRED { struct ucred cr; @@ -75,6 +59,26 @@ accept_connection (ASSUAN_CONTEXT ctx) return 0; } + +static int +accept_connection (ASSUAN_CONTEXT ctx) +{ + int fd; + struct sockaddr_un clnt_addr; + size_t len = sizeof clnt_addr; + + ctx->client_pid = (pid_t)-1; + fd = accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len ); + if (fd == -1) + { + ctx->os_errno = errno; + return ASSUAN_Accept_Failed; + } + + ctx->connected_fd = fd; + return accept_connection_bottom (ctx); +} + static int finish_connection (ASSUAN_CONTEXT ctx) { @@ -116,6 +120,7 @@ assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd) ctx->outbound.fd = -1; ctx->listen_fd = listen_fd; + ctx->connected_fd = -1; ctx->deinit_handler = deinit_socket_server; ctx->accept_handler = accept_connection; ctx->finish_handler = finish_connection; @@ -128,12 +133,37 @@ assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd) return rc; } +/* Initialize a server using the already accepted socket FD. */ +int +assuan_init_connected_socket_server (ASSUAN_CONTEXT *r_ctx, int fd) +{ + ASSUAN_CONTEXT ctx; + int rc; + *r_ctx = NULL; + ctx = xtrycalloc (1, sizeof *ctx); + 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->input_fd = -1; + ctx->output_fd = -1; + ctx->inbound.fd = -1; + ctx->outbound.fd = -1; + ctx->listen_fd = -1; + ctx->connected_fd = fd; + ctx->deinit_handler = deinit_socket_server; + ctx->accept_handler = accept_connection_bottom; + ctx->finish_handler = finish_connection; - - - + rc = _assuan_register_std_commands (ctx); + if (rc) + xfree (ctx); + else + *r_ctx = ctx; + return rc; +} |