diff options
author | Marcus Brinkmann <mb@g10code.com> | 2009-09-21 01:08:08 +0000 |
---|---|---|
committer | Marcus Brinkmann <mb@g10code.com> | 2009-09-21 01:08:08 +0000 |
commit | cd87e56dac64c74d45f42838fc1049848f8aadcd (patch) | |
tree | ff70f9a6e8601305d06bebb55709350d3d8dbae4 /src/assuan-defs.h | |
parent | 0650eaa24a8a54dbfb1d5aea113ffd7a1536861a (diff) | |
download | libassuan-cd87e56dac64c74d45f42838fc1049848f8aadcd.tar.gz |
2009-09-19 Marcus Brinkmann <marcus@g10code.de>
* tests/fdpassing.c: Update to new API.
* configure.ac: Check for stdint.h and inttypes.h. Invoke
AC_TYPE_UINTPTR_T.
doc/
2009-09-21 Marcus Brinkmann <marcus@g10code.de>
* assuan.texi: Update to new API.
src/
2009-09-19 Marcus Brinkmann <marcus@g10code.de>
* src/libassuan.vers, src/libassuan.def: Update to new API.
* assuan.c, context.c, system.c, debug.c: New files.
* Makefile.am (common_sources): Add assuan.c, context.c, system.c
and debug.c.
* assuan.h: Include <stdarg.h>. Fix inclusion of <gpg-error.h>.
(_ASSUAN_EXT_SYM_PREFIX, _ASSUAN_PREFIX1, _ASSUAN_PREFIX2)
(_ASSUAN_PREFIX): Remove support for renaming the whole library,
now that we have a stable shared library interface that can evolve
to cover all needs (particularly those of GPGME).
(assuan_malloc_hooks, assuan_malloc_hooks_t, assuan_log_cb_t)
(assuan_io_monitor_t): New types.
(ASSUAN_LOG_INIT, ASSUAN_LOG_CTX, ASSUAN_LOG_ENGINE)
(ASSUAN_LOG_DATA, ASSUAN_LOG_SYSIO, ASSUAN_IO_FROM_PEER)
(ASSUAN_IO_TO_PEER, ASSUAN_IO_MONITOR_NOLOG)
(ASSUAN_IO_MONITOR_IGNORE): New symbols.
(assuan_set_gpg_err_source, assuan_get_gpg_err_source)
(assuan_get_malloc_hooks, assuan_set_log_cb, assuan_get_log_cb)
(assuan_new, assuan_new_ext, assuan_release): New function
prototypes.
(assuan_init_pipe_server, assuan_init_socket_server)
(assuan_init_socket_server_ext, assuan_pipe_connect)
(assuan_pipe_connect_ext, assuan_socket_connect)
(assuan_socket_connect_ext): Take a context argument instead of
pointer to context.
(assuan_deinit_server, assuan_disconnect)
(assuan_set_assuan_err_source): Remove function prototypes.
* assuan-defs.h (ASSUAN_GCC_A_PURE): Moved here from XXX
(_assuan_error): New macro.
(struct assuan_context_s): New members err_source, w32_strerror,
malloc_hooks, log_cb, log_cb_data: New members. Move confidential
into flags. New member engine.
(_assuan_log_handler, _assuan_error_default, _assuan_disconnect):
New prototypes.
(_assuan_new_context): Remove prototype.
(_assuan_malloc, _assuan_calloc, _assuan_realloc, _assuan_free):
Add context argument to prototype.
* assuan-util.c (alloc_func, realloc_func, free_func): Remove
global variables.
(assuan_set_malloc_hooks, _assuan_malloc, _assuan_realloc)
(_assuan_calloc, _assuan_free, assuan_set_pointer)
(assuan_get_pointer, assuan_begin_confidential)
(assuan_end_confidential, assuan_set_io_monitor, assuan_set_flag)
(assuan_get_flag): Move functions to ...
* assuan-client.c: Add ctx argument to all invocations of
_assuan_error.
* assuan-socket-server.c, assuan-socket-connect.c,
assuan-connect.c: Likewise.
* assuan-buffer.c: Likewise. Also update access to confidential
flag.
* assuan-uds.c: Add ctx argument to all invocations of
_assuan_malloc, _assuan_realloc, _assuan_calloc, _assuan_free and
_assuan_error.
* assuan_listen.c, assuan-inquire.c, assuan-handler.c: Likewise.
* assuan-error.c (err_source): Remove global variable.
(assuan_set_assuan_err_source): Removed function.
(_assuan_w32_strerror): Moved here from assuan-logging.c and made
thread-safe.
(_assuan_error): Removed function (is now macro).
* assuan-handler.c: Update access to confidential flag.
* assuan-socket-server.c (accept_connection_bottom): Update access
to confidential flag in context.
(assuan_init_socket_server, assuan_init_socket_server_ext): Take
ctx argument instead of pointer to ctx.
* assuan-inquire.c (init_membuf, put_membuf, get_membuf)
(free_membuf): Take context argument and change all callers.
* assuan-socket-server.c (assuan_socket_connect)
(assuan_socket_connect_ext): Take ctx argument instead of pointer
to ctx.
* assuan-pipe-connect.c (initial_handshake, pipe_connect_unix)
(socketpair_connect, assuan_pipe_connect)
(assuan_pipe_connect_ext): Likewise.
(socketpair_connect): Now that ctx is not a pointer argument
anymore, return if we are server or client in the argv argument.
* assuan-logging.c (_assuan_log_handler): New function.
(_assuan_w32_strerror): Move to assuan-error.c
* assuan-connect.c (assuan_disconnect): Renamed to ...
(_assuan_disconnect): ... this.
* assuan-pipe-server.c (_assuan_new_context): Removed function.
(assuan_init_pipe_server): Take ctx argument instead of pointer to
ctx.
(_assuan_release_context): Removed function.
(_assuan_deinit_server): Reimplement.
Diffstat (limited to 'src/assuan-defs.h')
-rw-r--r-- | src/assuan-defs.h | 125 |
1 files changed, 82 insertions, 43 deletions
diff --git a/src/assuan-defs.h b/src/assuan-defs.h index 5fc14f4..1d6acee 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -31,6 +31,12 @@ #include "assuan.h" +#if __GNUC__ > 2 +# define ASSUAN_GCC_A_PURE __attribute__ ((__pure__)) +#else +# define ASSUAN_GCC_A_PURE +#endif + #ifndef HAVE_W32_SYSTEM #define DIRSEP_C '/' #else @@ -39,6 +45,9 @@ #define LINELENGTH ASSUAN_LINELENGTH +/* Generate an error code specific to a context. */ +#define _assuan_error(ctx, errcode) gpg_err_make ((ctx)->err_source, errcode) + struct cmdtbl_s { @@ -60,40 +69,71 @@ struct assuan_io gpg_error_t (*receivefd) (assuan_context_t, assuan_fd_t *); }; - -/* The global variable with the optional hook fucntions. */ -extern struct assuan_io_hooks _assuan_io_hooks; - - + /* The context we use with most functions. */ struct assuan_context_s { - gpg_error_t err_no; - const char *err_str; + /* Members managed by the generic routines in assuan.c. */ + + /* The error source for errors generated from this context. */ + gpg_err_source_t err_source; + +#ifdef HAVE_W32_SYSTEM + /* The per-context w32 error string. */ + char w32_strerror[256]; +#endif + + /* The allocation hooks. */ + struct assuan_malloc_hooks malloc_hooks; + + /* Logging callback handler. */ + assuan_log_cb_t log_cb; + void *log_cb_data; + + void *user_pointer; /* Context specific flags (cf. assuan_flag_t). */ struct { - unsigned int no_waitpid : 1; /* See ASSUAN_NO_WAITPID. */ + unsigned int no_waitpid : 1; + unsigned int confidential : 1; } flags; - int confidential; + /* If set, this is called right before logging an I/O line. */ + assuan_io_monitor_t io_monitor; + void *io_monitor_data; + + /* Now come the members specific to subsystems or engines. FIXME: + This is not developed yet. See below for the legacy members. */ + struct + { + void (*release) (assuan_context_t ctx); + } engine; + + + /* Engine specific or other subsystem members. */ + + /* assuan-logging.c. Does not require deallocation from us. */ + FILE *log_fp; + + /* assuan-util.c */ + gpg_error_t err_no; + const char *err_str; + int is_server; /* Set if this is context belongs to a server */ int in_inquire; int in_process_next; int in_command; /* The following members are used by assuan_inquire_ext. */ - int (*inquire_cb) (void *cb_data, int rc, unsigned char *buf, size_t len); + gpg_error_t (*inquire_cb) (void *cb_data, gpg_error_t rc, + unsigned char *buf, size_t len); void *inquire_cb_data; void *inquire_membuf; char *hello_line; char *okay_line; /* See assuan_set_okay_line() */ - void *user_pointer; /* For assuan_get_pointer and assuan_set_pointer (). */ - - FILE *log_fp; struct { assuan_fd_t fd; @@ -155,7 +195,7 @@ struct assuan_context_s void (*deinit_handler)(assuan_context_t); gpg_error_t (*accept_handler)(assuan_context_t); - gpg_error_t (*finish_handler)(assuan_context_t); + void (*finish_handler)(assuan_context_t); struct cmdtbl_s *cmdtbl; size_t cmdtbl_used; /* used entries */ @@ -170,27 +210,35 @@ struct assuan_context_s /* This function is called right after a command has been processed. It may be used to command related cleanup. */ - void (*post_cmd_notify_fnc)(assuan_context_t, int); - - /* If set, this is called right before logging an I/O line. With - DIRECTION set to 1 it is called for an output oeration; 0 means - an input operation. If bit 0 is set in the return value, the - logging of the line will be suppressed. With bit 1 set, the - entire line will be ignored. */ - unsigned int (*io_monitor)(assuan_context_t ctx, - int direction, - const char *line, - size_t linelen); + void (*post_cmd_notify_fnc)(assuan_context_t, gpg_error_t); + assuan_fd_t input_fd; /* Set by the INPUT command. */ assuan_fd_t output_fd; /* Set by the OUTPUT command. */ /* io routines. */ struct assuan_io *io; + + }; + +/* Release all resources associated with an engine operation. */ +void _assuan_reset (assuan_context_t ctx); + +/* Default log handler. */ +int _assuan_log_handler (assuan_context_t ctx, void *hook, + unsigned int cat, const char *msg); + + +/* Manage memory specific to a context. */ +void *_assuan_malloc (assuan_context_t ctx, size_t cnt); +void *_assuan_realloc (assuan_context_t ctx, void *ptr, size_t cnt); +void *_assuan_calloc (assuan_context_t ctx, size_t cnt, size_t elsize); +void _assuan_free (assuan_context_t ctx, void *ptr); + + /*-- assuan-pipe-server.c --*/ -gpg_error_t _assuan_new_context (assuan_context_t *r_ctx); void _assuan_release_context (assuan_context_t ctx); /*-- assuan-uds.c --*/ @@ -223,16 +271,9 @@ void _assuan_inquire_release (assuan_context_t ctx); int _assuan_error_is_eagain (gpg_error_t err); -/*-- 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); - -gpg_error_t _assuan_error (gpg_err_code_t errcode); #define set_error(c,e,t) \ - assuan_set_error ((c), _assuan_error (e), (t)) + assuan_set_error ((c), _assuan_error (c,e), (t)) #ifdef HAVE_W32_SYSTEM const char *_assuan_w32_strerror (int ec); @@ -241,15 +282,7 @@ const char *_assuan_w32_strerror (int ec); /*-- 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 - ; -void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length); -void _assuan_log_sanitized_string (const char *string); +void _assuan_log_print_buffer (FILE *fp, const void *buffer, size_t length); /*-- assuan-io.c --*/ @@ -322,4 +355,10 @@ int putc_unlocked (int c, FILE *stream); #endif +void _assuan_disconnect (assuan_context_t ctx); + +/* Encode the C formatted string SRC and return the malloc'ed result. */ +char *_assuan_encode_c_string (assuan_context_t ctx, const char *src); + + #endif /*ASSUAN_DEFS_H*/ |