mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-07 22:01:07 +01:00
* assuan-util.c (assuan_set_io_func): New.
* assuan-buffer.c (writen, readline): Use the new functions instead of pth. * assuan-socket-server.c (accept_connection): Don't use the pth_accept - using the assuan included accept code would be a bad idea within Pth so we don't need a replacement function.
This commit is contained in:
parent
3910c0f005
commit
72f48d9e8a
@ -1,3 +1,18 @@
|
|||||||
|
2002-05-23 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
* assuan-util.c (assuan_set_io_func): New.
|
||||||
|
* assuan-buffer.c (writen, readline): Use the new functions
|
||||||
|
instead of pth.
|
||||||
|
* assuan-socket-server.c (accept_connection): Don't use the
|
||||||
|
pth_accept - using the assuan included accept code would be a bad
|
||||||
|
idea within Pth so we don't need a replacement function.
|
||||||
|
|
||||||
|
2002-05-22 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
* assuan-socket-server.c (assuan_init_connected_socket_server): New.
|
||||||
|
(accept_connection): Factored most code out to..
|
||||||
|
(accept_connection_bottom): .. new function.
|
||||||
|
|
||||||
2002-04-04 Werner Koch <wk@gnupg.org>
|
2002-04-04 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* assuan-buffer.c (my_log_prefix): New. Use it for all i/o debug
|
* assuan-buffer.c (my_log_prefix): New. Use it for all i/o debug
|
||||||
|
@ -25,9 +25,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#ifdef USE_GNU_PTH
|
|
||||||
# include <pth.h>
|
|
||||||
#endif
|
|
||||||
#include "assuan-defs.h"
|
#include "assuan-defs.h"
|
||||||
|
|
||||||
#ifdef HAVE_JNLIB_LOGGING
|
#ifdef HAVE_JNLIB_LOGGING
|
||||||
@ -51,11 +48,9 @@ writen ( int fd, const char *buffer, size_t length )
|
|||||||
{
|
{
|
||||||
while (length)
|
while (length)
|
||||||
{
|
{
|
||||||
#ifdef USE_GNU_PTH
|
int nwritten = _assuan_write_wrapper?
|
||||||
int nwritten = pth_write (fd, buffer, length);
|
_assuan_write_wrapper (fd, buffer, length):
|
||||||
#else
|
write (fd, buffer, length);
|
||||||
int nwritten = write (fd, buffer, length);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
{
|
{
|
||||||
@ -80,11 +75,10 @@ readline (int fd, char *buf, size_t buflen, int *r_nread, int *eof)
|
|||||||
*r_nread = 0;
|
*r_nread = 0;
|
||||||
while (nleft > 0)
|
while (nleft > 0)
|
||||||
{
|
{
|
||||||
#ifdef USE_GNU_PTH
|
int n = _assuan_read_wrapper?
|
||||||
int n = pth_read (fd, buf, nleft);
|
_assuan_read_wrapper (fd, buf, nleft):
|
||||||
#else
|
read (fd, buf, nleft);
|
||||||
int n = read (fd, buf, nleft);
|
|
||||||
#endif
|
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
|
@ -76,6 +76,7 @@ struct assuan_context_s {
|
|||||||
pid_t pid; /* In pipe mode, the pid of the child server process.
|
pid_t pid; /* In pipe mode, the pid of the child server process.
|
||||||
In socket mode, the pid of the server */
|
In socket mode, the pid of the server */
|
||||||
int listen_fd; /* The fd we are listening on (used by socket servers) */
|
int listen_fd; /* The fd we are listening on (used by socket servers) */
|
||||||
|
int connected_fd; /* helper */
|
||||||
|
|
||||||
pid_t client_pid; /* for a socket server the PID of the client or -1
|
pid_t client_pid; /* for a socket server the PID of the client or -1
|
||||||
if not available */
|
if not available */
|
||||||
@ -101,6 +102,7 @@ struct assuan_context_s {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-- assuan-pipe-server.c --*/
|
/*-- assuan-pipe-server.c --*/
|
||||||
int _assuan_new_context (ASSUAN_CONTEXT *r_ctx);
|
int _assuan_new_context (ASSUAN_CONTEXT *r_ctx);
|
||||||
void _assuan_release_context (ASSUAN_CONTEXT ctx);
|
void _assuan_release_context (ASSUAN_CONTEXT ctx);
|
||||||
@ -119,6 +121,9 @@ AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
|
|||||||
|
|
||||||
|
|
||||||
/*-- assuan-util.c --*/
|
/*-- assuan-util.c --*/
|
||||||
|
extern ssize_t (*_assuan_read_wrapper)(int,void*,size_t);
|
||||||
|
extern ssize_t (*_assuan_write_wrapper)(int,const void*,size_t);
|
||||||
|
|
||||||
void *_assuan_malloc (size_t n);
|
void *_assuan_malloc (size_t n);
|
||||||
void *_assuan_calloc (size_t n, size_t m);
|
void *_assuan_calloc (size_t n, size_t m);
|
||||||
void *_assuan_realloc (void *p, size_t n);
|
void *_assuan_realloc (void *p, size_t n);
|
||||||
|
@ -46,7 +46,7 @@ finish_connection (ASSUAN_CONTEXT ctx)
|
|||||||
|
|
||||||
|
|
||||||
/* Create a new context. Note that the handlers are set up for a pipe
|
/* Create a new context. Note that the handlers are set up for a pipe
|
||||||
server/client - this wau we don't need extra dummy functions */
|
server/client - this way we don't need extra dummy functions */
|
||||||
int
|
int
|
||||||
_assuan_new_context (ASSUAN_CONTEXT *r_ctx)
|
_assuan_new_context (ASSUAN_CONTEXT *r_ctx)
|
||||||
{
|
{
|
||||||
|
@ -25,31 +25,15 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#ifdef USE_GNU_PTH
|
|
||||||
# include <pth.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "assuan-defs.h"
|
#include "assuan-defs.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
accept_connection (ASSUAN_CONTEXT ctx)
|
accept_connection_bottom (ASSUAN_CONTEXT ctx)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd = ctx->connected_fd;
|
||||||
struct sockaddr_un clnt_addr;
|
|
||||||
size_t len = sizeof clnt_addr;
|
|
||||||
|
|
||||||
ctx->client_pid = (pid_t)-1;
|
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
|
#ifdef HAVE_SO_PEERCRED
|
||||||
{
|
{
|
||||||
struct ucred cr;
|
struct ucred cr;
|
||||||
@ -75,6 +59,26 @@ accept_connection (ASSUAN_CONTEXT ctx)
|
|||||||
return 0;
|
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
|
static int
|
||||||
finish_connection (ASSUAN_CONTEXT ctx)
|
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->outbound.fd = -1;
|
||||||
|
|
||||||
ctx->listen_fd = listen_fd;
|
ctx->listen_fd = listen_fd;
|
||||||
|
ctx->connected_fd = -1;
|
||||||
ctx->deinit_handler = deinit_socket_server;
|
ctx->deinit_handler = deinit_socket_server;
|
||||||
ctx->accept_handler = accept_connection;
|
ctx->accept_handler = accept_connection;
|
||||||
ctx->finish_handler = finish_connection;
|
ctx->finish_handler = finish_connection;
|
||||||
@ -128,12 +133,37 @@ assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd)
|
|||||||
return rc;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
#include "../jnlib/logging.h"
|
#include "../jnlib/logging.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ssize_t (*_assuan_read_wrapper)(int,void*,size_t) = NULL;
|
||||||
|
ssize_t (*_assuan_write_wrapper)(int,const void*,size_t) = NULL;
|
||||||
|
|
||||||
|
|
||||||
static void *(*alloc_func)(size_t n) = malloc;
|
static void *(*alloc_func)(size_t n) = malloc;
|
||||||
static void *(*realloc_func)(void *p, size_t n) = realloc;
|
static void *(*realloc_func)(void *p, size_t n) = realloc;
|
||||||
@ -74,6 +77,17 @@ _assuan_free (void *p)
|
|||||||
free_func (p);
|
free_func (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* For use with Pth it is required to have special read and write
|
||||||
|
functions. We can't assume an ELF based system so we have to
|
||||||
|
explicitly set them if we are going to use Pth. */
|
||||||
|
void
|
||||||
|
assuan_set_io_func (ssize_t (*r)(int,void*,size_t),
|
||||||
|
ssize_t (*w)(int,const void*,size_t))
|
||||||
|
{
|
||||||
|
_assuan_read_wrapper = r;
|
||||||
|
_assuan_write_wrapper = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Store the error in the context so that the error sending function
|
/* Store the error in the context so that the error sending function
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h> /* for ssize_t */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -170,6 +171,7 @@ void assuan_deinit_server (ASSUAN_CONTEXT ctx);
|
|||||||
|
|
||||||
/*-- assuan-socket-server.c --*/
|
/*-- assuan-socket-server.c --*/
|
||||||
int assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd);
|
int assuan_init_socket_server (ASSUAN_CONTEXT *r_ctx, int listen_fd);
|
||||||
|
int assuan_init_connected_socket_server (ASSUAN_CONTEXT *r_ctx, int fd);
|
||||||
|
|
||||||
|
|
||||||
/*-- assuan-pipe-connect.c --*/
|
/*-- assuan-pipe-connect.c --*/
|
||||||
@ -212,6 +214,8 @@ AssuanError assuan_send_data (ASSUAN_CONTEXT ctx,
|
|||||||
void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
|
void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
|
||||||
void *(*new_realloc_func)(void *p, size_t n),
|
void *(*new_realloc_func)(void *p, size_t n),
|
||||||
void (*new_free_func)(void*) );
|
void (*new_free_func)(void*) );
|
||||||
|
void assuan_set_io_func (ssize_t (*r)(int,void*,size_t),
|
||||||
|
ssize_t (*w)(int,const void*,size_t));
|
||||||
void assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp);
|
void assuan_set_log_stream (ASSUAN_CONTEXT ctx, FILE *fp);
|
||||||
int assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text);
|
int assuan_set_error (ASSUAN_CONTEXT ctx, int err, const char *text);
|
||||||
void assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer);
|
void assuan_set_pointer (ASSUAN_CONTEXT ctx, void *pointer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user