2001-11-20 05:27:46 +00:00
|
|
|
/* assuan-defs.c - Internal definitions to Assuan
|
2005-08-09 13:19:24 +00:00
|
|
|
* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
|
2001-11-20 05:27:46 +00:00
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
* This file is part of Assuan.
|
2001-11-20 05:27:46 +00:00
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
* 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.
|
2001-11-20 05:27:46 +00:00
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
* 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.
|
2001-11-20 05:27:46 +00:00
|
|
|
*
|
2003-02-01 18:53:06 +00:00
|
|
|
* 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
|
2001-11-20 05:27:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ASSUAN_DEFS_H
|
|
|
|
#define ASSUAN_DEFS_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2005-08-09 13:19:24 +00:00
|
|
|
#ifndef HAVE_W32_SYSTEM
|
2003-08-18 19:17:08 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2005-08-09 13:19:24 +00:00
|
|
|
#else
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2003-08-18 19:17:08 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2001-11-20 05:27:46 +00:00
|
|
|
#include "assuan.h"
|
|
|
|
|
2005-08-09 13:19:24 +00:00
|
|
|
#ifndef HAVE_W32_SYSTEM
|
|
|
|
#define DIRSEP_C '/'
|
|
|
|
#else
|
|
|
|
#define DIRSEP_C '\\'
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
#define AF_LOCAL AF_UNIX
|
|
|
|
/* We need to prefix the structure with a sockaddr_in header so we can
|
|
|
|
use it later for sendto and recvfrom. */
|
|
|
|
struct sockaddr_un
|
|
|
|
{
|
|
|
|
short sun_family;
|
|
|
|
unsigned short sun_port;
|
|
|
|
struct in_addr sun_addr;
|
|
|
|
char sun_path[108-2-4]; /* Path name. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Not needed anymore because the current mingw32 defines this in
|
|
|
|
sys/types.h */
|
|
|
|
/* typedef int ssize_t; */
|
|
|
|
|
|
|
|
/* Missing W32 functions */
|
|
|
|
int putc_unlocked (int c, FILE *stream);
|
|
|
|
void * memrchr (const void *block, int c, size_t size);
|
|
|
|
char * stpcpy (char *dest, const char *src);
|
|
|
|
#endif
|
|
|
|
|
2001-12-13 23:12:37 +00:00
|
|
|
#define LINELENGTH ASSUAN_LINELENGTH
|
2001-11-20 05:27:46 +00:00
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
struct cmdtbl_s
|
|
|
|
{
|
2001-11-20 05:27:46 +00:00
|
|
|
const char *name;
|
|
|
|
int (*handler)(ASSUAN_CONTEXT, char *line);
|
|
|
|
};
|
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
struct assuan_io
|
|
|
|
{
|
|
|
|
/* Routine to read from input_fd. */
|
2005-03-22 09:10:36 +00:00
|
|
|
ssize_t (*readfnc) (ASSUAN_CONTEXT, void *, size_t);
|
2003-08-18 19:17:08 +00:00
|
|
|
/* Routine to write to output_fd. */
|
2005-03-22 09:10:36 +00:00
|
|
|
ssize_t (*writefnc) (ASSUAN_CONTEXT, const void *, size_t);
|
2003-08-18 19:17:08 +00:00
|
|
|
/* Send a file descriptor. */
|
2005-08-09 13:19:24 +00:00
|
|
|
assuan_error_t (*sendfd) (ASSUAN_CONTEXT, int);
|
2003-08-18 19:17:08 +00:00
|
|
|
/* Receive a file descriptor. */
|
2005-08-09 13:19:24 +00:00
|
|
|
assuan_error_t (*receivefd) (ASSUAN_CONTEXT, int *);
|
2003-08-18 19:17:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct assuan_context_s
|
|
|
|
{
|
2005-08-09 13:19:24 +00:00
|
|
|
assuan_error_t err_no;
|
2001-11-20 05:27:46 +00:00
|
|
|
const char *err_str;
|
2005-08-09 13:19:24 +00:00
|
|
|
int os_errno; /* Last system error number used with certain
|
|
|
|
error codes. */
|
|
|
|
|
|
|
|
/* Context specific flags (cf. assuan_flag_t). */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int no_waitpid:1; /* See ASSUAN_NO_WAITPID. */
|
|
|
|
} flags;
|
2001-12-13 15:04:36 +00:00
|
|
|
|
2002-01-22 16:29:12 +00:00
|
|
|
int confidential;
|
2005-08-09 13:19:24 +00:00
|
|
|
int is_server; /* Set if this is context belongs to a server */
|
2001-12-13 15:04:36 +00:00
|
|
|
int in_inquire;
|
|
|
|
char *hello_line;
|
2005-08-09 13:19:24 +00:00
|
|
|
char *okay_line; /* See assuan_set_okay_line() */
|
2001-11-20 05:27:46 +00:00
|
|
|
|
2005-08-09 13:19:24 +00:00
|
|
|
void *user_pointer; /* For assuan_get_pointer and assuan-set_pointer (). */
|
2001-11-20 05:27:46 +00:00
|
|
|
|
2002-01-22 16:29:12 +00:00
|
|
|
FILE *log_fp;
|
|
|
|
|
2001-11-20 05:27:46 +00:00
|
|
|
struct {
|
|
|
|
int fd;
|
|
|
|
int eof;
|
|
|
|
char line[LINELENGTH];
|
|
|
|
int linelen; /* w/o CR, LF - might not be the same as
|
|
|
|
strlen(line) due to embedded nuls. However a nul
|
|
|
|
is always written at this pos */
|
2001-11-24 21:22:18 +00:00
|
|
|
struct {
|
|
|
|
char line[LINELENGTH];
|
|
|
|
int linelen ;
|
2001-12-13 15:04:36 +00:00
|
|
|
int pending; /* i.e. at least one line is available in the attic */
|
2001-11-24 21:22:18 +00:00
|
|
|
} attic;
|
2001-11-20 05:27:46 +00:00
|
|
|
} inbound;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
int fd;
|
|
|
|
struct {
|
|
|
|
FILE *fp;
|
|
|
|
char line[LINELENGTH];
|
|
|
|
int linelen;
|
|
|
|
int error;
|
|
|
|
} data;
|
|
|
|
} outbound;
|
|
|
|
|
|
|
|
int pipe_mode; /* We are in pipe mode, i.e. we can handle just one
|
|
|
|
connection and must terminate then */
|
2005-08-09 13:19:24 +00:00
|
|
|
pid_t pid; /* The the pid of the peer. */
|
2002-01-22 16:29:12 +00:00
|
|
|
int listen_fd; /* The fd we are listening on (used by socket servers) */
|
2003-02-01 18:53:06 +00:00
|
|
|
int connected_fd; /* helper */
|
2002-01-22 16:29:12 +00:00
|
|
|
|
2002-04-24 01:55:58 +00:00
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
/* Used for Unix domain sockets. */
|
|
|
|
struct sockaddr_un myaddr;
|
|
|
|
struct sockaddr_un serveraddr;
|
|
|
|
/* When reading from datagram sockets, we must read an entire
|
|
|
|
message at a time. This means that we have to do our own
|
|
|
|
buffering to be able to get the semantics of read. */
|
|
|
|
void *domainbuffer;
|
|
|
|
/* Offset of start of buffer. */
|
|
|
|
int domainbufferoffset;
|
|
|
|
/* Bytes buffered. */
|
|
|
|
int domainbuffersize;
|
|
|
|
/* Memory allocated. */
|
|
|
|
int domainbufferallocated;
|
|
|
|
|
|
|
|
int *pendingfds;
|
|
|
|
int pendingfdscount;
|
|
|
|
|
2002-01-22 16:29:12 +00:00
|
|
|
void (*deinit_handler)(ASSUAN_CONTEXT);
|
|
|
|
int (*accept_handler)(ASSUAN_CONTEXT);
|
|
|
|
int (*finish_handler)(ASSUAN_CONTEXT);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
|
|
struct cmdtbl_s *cmdtbl;
|
|
|
|
size_t cmdtbl_used; /* used entries */
|
|
|
|
size_t cmdtbl_size; /* allocated size of table */
|
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
void (*bye_notify_fnc)(ASSUAN_CONTEXT);
|
|
|
|
void (*reset_notify_fnc)(ASSUAN_CONTEXT);
|
|
|
|
void (*cancel_notify_fnc)(ASSUAN_CONTEXT);
|
2002-01-22 16:29:12 +00:00
|
|
|
int (*option_handler_fnc)(ASSUAN_CONTEXT,const char*, const char*);
|
2001-12-13 15:04:36 +00:00
|
|
|
void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *);
|
|
|
|
void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *);
|
|
|
|
|
2001-11-20 05:27:46 +00:00
|
|
|
int input_fd; /* set by INPUT command */
|
|
|
|
int output_fd; /* set by OUTPUT command */
|
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
/* io routines. */
|
|
|
|
struct assuan_io *io;
|
2002-01-22 16:29:12 +00:00
|
|
|
};
|
2001-11-20 05:27:46 +00:00
|
|
|
|
2002-01-22 16:29:12 +00:00
|
|
|
/*-- assuan-pipe-server.c --*/
|
|
|
|
int _assuan_new_context (ASSUAN_CONTEXT *r_ctx);
|
|
|
|
void _assuan_release_context (ASSUAN_CONTEXT ctx);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
/*-- assuan-domain-connect.c --*/
|
|
|
|
/* 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. */
|
2005-08-09 13:19:24 +00:00
|
|
|
assuan_error_t _assuan_domain_init (ASSUAN_CONTEXT *r_ctx,
|
2003-08-18 19:17:08 +00:00
|
|
|
int rendezvousfd,
|
|
|
|
pid_t peer);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
|
|
/*-- assuan-handler.c --*/
|
|
|
|
int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
|
|
|
|
|
|
|
|
/*-- assuan-buffer.c --*/
|
|
|
|
int _assuan_read_line (ASSUAN_CONTEXT ctx);
|
|
|
|
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
|
|
|
|
int _assuan_cookie_write_flush (void *cookie);
|
2005-08-09 13:19:24 +00:00
|
|
|
assuan_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix,
|
|
|
|
const char *line, size_t len);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
2001-12-13 15:04:36 +00:00
|
|
|
/*-- assuan-client.c --*/
|
2005-08-09 13:19:24 +00:00
|
|
|
assuan_error_t _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-- assuan-util.c --*/
|
|
|
|
void *_assuan_malloc (size_t n);
|
|
|
|
void *_assuan_calloc (size_t n, size_t m);
|
|
|
|
void *_assuan_realloc (void *p, size_t n);
|
|
|
|
void _assuan_free (void *p);
|
|
|
|
|
|
|
|
#define xtrymalloc(a) _assuan_malloc ((a))
|
|
|
|
#define xtrycalloc(a,b) _assuan_calloc ((a),(b))
|
|
|
|
#define xtryrealloc(a,b) _assuan_realloc((a),(b))
|
|
|
|
#define xfree(a) _assuan_free ((a))
|
|
|
|
|
|
|
|
#define set_error(c,e,t) assuan_set_error ((c), ASSUAN_ ## e, (t))
|
|
|
|
|
2002-01-22 16:29:12 +00:00
|
|
|
void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length);
|
|
|
|
void _assuan_log_sanitized_string (const char *string);
|
|
|
|
|
2005-08-09 13:19:24 +00:00
|
|
|
#ifdef HAVE_W32_SYSTEM
|
|
|
|
const char *_assuan_w32_strerror (int ec);
|
|
|
|
#define w32_strerror(e) _assuan_w32_strerror ((e))
|
|
|
|
#endif /*HAVE_W32_SYSTEM*/
|
|
|
|
|
|
|
|
|
|
|
|
/*-- assuan-logging.c --*/
|
|
|
|
void _assuan_set_default_log_stream (FILE *fp);
|
|
|
|
|
|
|
|
void _assuan_log_printf (const char *format, ...)
|
|
|
|
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
|
|
|
|
__attribute__ ((format (printf,1,2)))
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2003-02-01 18:53:06 +00:00
|
|
|
/*-- assuan-io.c --*/
|
2003-08-18 19:17:08 +00:00
|
|
|
ssize_t _assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size);
|
|
|
|
ssize_t _assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer,
|
|
|
|
size_t size);
|
|
|
|
|
2005-08-09 13:19:24 +00:00
|
|
|
/*-- assuan-socket.c --*/
|
|
|
|
int _assuan_close (int fd);
|
|
|
|
int _assuan_sock_new (int domain, int type, int proto);
|
|
|
|
int _assuan_sock_bind (int sockfd, struct sockaddr *addr, int addrlen);
|
|
|
|
int _assuan_sock_connect (int sockfd, struct sockaddr *addr, int addrlen);
|
|
|
|
|
2003-08-18 19:17:08 +00:00
|
|
|
#ifdef HAVE_FOPENCOOKIE
|
|
|
|
/* We have to implement funopen in terms of glibc's fopencookie. */
|
2005-08-09 13:19:24 +00:00
|
|
|
FILE *_assuan_funopen(void *cookie,
|
|
|
|
cookie_read_function_t *readfn,
|
|
|
|
cookie_write_function_t *writefn,
|
|
|
|
cookie_seek_function_t *seekfn,
|
|
|
|
cookie_close_function_t *closefn);
|
|
|
|
#define funopen(a,r,w,s,c) _assuan_funopen ((a), (r), (w), (s), (c))
|
2003-08-18 19:17:08 +00:00
|
|
|
#endif /*HAVE_FOPENCOOKIE*/
|
2001-11-20 05:27:46 +00:00
|
|
|
|
|
|
|
#endif /*ASSUAN_DEFS_H*/
|
|
|
|
|