aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/assuan.h')
-rw-r--r--src/assuan.h377
1 files changed, 150 insertions, 227 deletions
diff --git a/src/assuan.h b/src/assuan.h
index 105862f..9e7db89 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -1,5 +1,5 @@
/* assuan.h - Definitions for the Assuan IPC library
- * Copyright (C) 2001-2003, 2005, 2007-2009 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2005, 2007-2009 Free Software Foundation, Inc.
This file is part of Assuan.
@@ -23,24 +23,21 @@
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
+#include <stdarg.h>
+
#ifndef _ASSUAN_NO_SOCKET_WRAPPER
#ifdef _WIN32
#include <ws2tcpip.h>
#else
#include <sys/socket.h>
#endif
-
-#include <gpg-error.h>
-
#endif /*!_ASSUAN_NO_SOCKET_WRAPPER*/
-/* To use this file with libraries the following macros are useful:
+#include <gpg-error.h>
- #define _ASSUAN_EXT_SYM_PREFIX _foo_
-
- This prefixes all external symbols with "_foo_".
+/* Compile time configuration:
- #define _ASSUAN_NO_SOCKET_WRAPPER
+ #define _ASSUAN_NO_SOCKET_WRAPPER
Do not include the definitions for the socket wrapper feature.
@@ -62,137 +59,6 @@
*/
-#ifdef _ASSUAN_EXT_SYM_PREFIX
-#define _ASSUAN_PREFIX1(x,y) x ## y
-#define _ASSUAN_PREFIX2(x,y) _ASSUAN_PREFIX1(x,y)
-#define _ASSUAN_PREFIX(x) _ASSUAN_PREFIX2(_ASSUAN_EXT_SYM_PREFIX,x)
-#define assuan_ _ASSUAN_PREFIX(assuan_)
-#define assuan_register_command _ASSUAN_PREFIX(assuan_register_command)
-#define assuan_register_post_cmd_notify \
- _ASSUAN_PREFIX(assuan_register_post_cmd_notify)
-#define assuan_register_bye_notify _ASSUAN_PREFIX(assuan_register_bye_notify)
-#define assuan_register_reset_notify \
- _ASSUAN_PREFIX(assuan_register_reset_notify)
-#define assuan_register_cancel_notify \
- _ASSUAN_PREFIX(assuan_register_cancel_notify)
-#define assuan_register_input_notify \
- _ASSUAN_PREFIX(assuan_register_input_notify)
-#define assuan_register_output_notify \
- _ASSUAN_PREFIX(assuan_register_output_notify)
-#define assuan_register_option_handler \
- _ASSUAN_PREFIX(assuan_register_option_handler)
-#define assuan_process _ASSUAN_PREFIX(assuan_process)
-#define assuan_process_next _ASSUAN_PREFIX(assuan_process_next)
-#define assuan_process_done _ASSUAN_PREFIX(assuan_process_done)
-#define assuan_get_active_fds _ASSUAN_PREFIX(assuan_get_active_fds)
-#define assuan_get_data_fp _ASSUAN_PREFIX(assuan_get_data_fp)
-#define assuan_set_okay_line _ASSUAN_PREFIX(assuan_set_okay_line)
-#define assuan_write_status _ASSUAN_PREFIX(assuan_write_status)
-#define assuan_command_parse_fd _ASSUAN_PREFIX(assuan_command_parse_fd)
-#define assuan_set_hello_line _ASSUAN_PREFIX(assuan_set_hello_line)
-#define assuan_accept _ASSUAN_PREFIX(assuan_accept)
-#define assuan_get_input_fd _ASSUAN_PREFIX(assuan_get_input_fd)
-#define assuan_get_output_fd _ASSUAN_PREFIX(assuan_get_output_fd)
-#define assuan_close_input_fd _ASSUAN_PREFIX(assuan_close_input_fd)
-#define assuan_close_output_fd _ASSUAN_PREFIX(assuan_close_output_fd)
-#define assuan_init_pipe_server _ASSUAN_PREFIX(assuan_init_pipe_server)
-#define assuan_deinit_server _ASSUAN_PREFIX(assuan_deinit_server)
-#define assuan_init_socket_server _ASSUAN_PREFIX(assuan_init_socket_server)
-#define assuan_init_socket_server_ext \
- _ASSUAN_PREFIX(assuan_init_socket_server_ext)
-#define assuan_pipe_connect _ASSUAN_PREFIX(assuan_pipe_connect)
-#define assuan_pipe_connect_ext _ASSUAN_PREFIX(assuan_pipe_connect_ext)
-#define assuan_socket_connect _ASSUAN_PREFIX(assuan_socket_connect)
-#define assuan_socket_connect_ext _ASSUAN_PREFIX(assuan_socket_connect_ext)
-#define assuan_disconnect _ASSUAN_PREFIX(assuan_disconnect)
-#define assuan_get_pid _ASSUAN_PREFIX(assuan_get_pid)
-#define assuan_get_peercred _ASSUAN_PREFIX(assuan_get_peercred)
-#define assuan_transact _ASSUAN_PREFIX(assuan_transact)
-#define assuan_inquire _ASSUAN_PREFIX(assuan_inquire)
-#define assuan_inquire_ext _ASSUAN_PREFIX(assuan_inquire_ext)
-#define assuan_read_line _ASSUAN_PREFIX(assuan_read_line)
-#define assuan_pending_line _ASSUAN_PREFIX(assuan_pending_line)
-#define assuan_write_line _ASSUAN_PREFIX(assuan_write_line)
-#define assuan_send_data _ASSUAN_PREFIX(assuan_send_data)
-#define assuan_sendfd _ASSUAN_PREFIX(assuan_sendfd)
-#define assuan_receivefd _ASSUAN_PREFIX(assuan_receivefd)
-#define assuan_set_malloc_hooks _ASSUAN_PREFIX(assuan_set_malloc_hooks)
-#define assuan_set_io_hooks _ASSUAN_PREFIX(assuan_set_io_hooks)
-#define assuan_set_log_stream _ASSUAN_PREFIX(assuan_set_log_stream)
-#define assuan_set_error _ASSUAN_PREFIX(assuan_set_error)
-#define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer)
-#define assuan_get_pointer _ASSUAN_PREFIX(assuan_get_pointer)
-#define assuan_set_io_monitor _ASSUAN_PREFIX(assuan_set_io_monitor)
-#define assuan_begin_confidential _ASSUAN_PREFIX(assuan_begin_confidential)
-#define assuan_end_confidential _ASSUAN_PREFIX(assuan_end_confidential)
-#define assuan_set_assuan_err_source \
- _ASSUAN_PREFIX(assuan_set_assuan_err_source)
-#define assuan_set_assuan_log_stream \
- _ASSUAN_PREFIX(assuan_set_assuan_log_stream)
-#define assuan_get_assuan_log_stream \
- _ASSUAN_PREFIX(assuan_get_assuan_log_stream)
-#define assuan_get_assuan_log_prefix \
- _ASSUAN_PREFIX(assuan_get_assuan_log_prefix)
-#define assuan_set_flag _ASSUAN_PREFIX(assuan_set_flag)
-#define assuan_get_flag _ASSUAN_PREFIX(assuan_get_flag)
-#define assuan_set_assuan_log_prefix \
- _ASSUAN_PREFIX(assuan_set_assuan_log_prefix)
-#define assuan_sock_close _ASSUAN_PREFIX(assuan_sock_close)
-#define assuan_sock_new _ASSUAN_PREFIX(assuan_sock_new)
-#define assuan_sock_connect _ASSUAN_PREFIX(assuan_sock_connect)
-#define assuan_sock_bind _ASSUAN_PREFIX(assuan_sock_bind)
-#define assuan_sock_get_nonce _ASSUAN_PREFIX(assuan_sock_get_nonce)
-#define assuan_sock_check_nonce _ASSUAN_PREFIX(assuan_sock_check_nonce)
-
-
-/* And now the internal functions, argh... */
-#define _assuan_read_line _ASSUAN_PREFIX(_assuan_read_line)
-#define _assuan_cookie_write_data _ASSUAN_PREFIX(_assuan_cookie_write_data)
-#define _assuan_cookie_write_flush _ASSUAN_PREFIX(_assuan_cookie_write_flush)
-#define _assuan_read_from_server _ASSUAN_PREFIX(_assuan_read_from_server)
-#define _assuan_domain_init _ASSUAN_PREFIX(_assuan_domain_init)
-#define _assuan_register_std_commands \
- _ASSUAN_PREFIX(_assuan_register_std_commands)
-#define _assuan_simple_read _ASSUAN_PREFIX(_assuan_simple_read)
-#define _assuan_simple_write _ASSUAN_PREFIX(_assuan_simple_write)
-#define _assuan_io_read _ASSUAN_PREFIX(_assuan_io_read)
-#define _assuan_io_write _ASSUAN_PREFIX(_assuan_io_write)
-#define _assuan_io_hooks _ASSUAN_PREFIX(_assuan_io_hooks)
-#define _assuan_new_context _ASSUAN_PREFIX(_assuan_new_context)
-#define _assuan_release_context _ASSUAN_PREFIX(_assuan_release_context)
-#define _assuan_malloc _ASSUAN_PREFIX(_assuan_malloc)
-#define _assuan_realloc _ASSUAN_PREFIX(_assuan_realloc)
-#define _assuan_calloc _ASSUAN_PREFIX(_assuan_calloc)
-#define _assuan_free _ASSUAN_PREFIX(_assuan_free)
-#define _assuan_log_print_buffer _ASSUAN_PREFIX(_assuan_log_print_buffer)
-#define _assuan_log_sanitized_string \
- _ASSUAN_PREFIX(_assuan_log_sanitized_string)
-#define _assuan_log_printf _ASSUAN_PREFIX(_assuan_log_printf)
-#define _assuan_set_default_log_stream \
- _ASSUAN_PREFIX(_assuan_set_default_log_stream)
-#define _assuan_w32_strerror _ASSUAN_PREFIX(_assuan_w32_strerror)
-#define _assuan_gpg_strerror_r _ASSUAN_PREFIX(_assuan_gpg_strerror_r)
-#define _assuan_gpg_strsource _ASSUAN_PREFIX(_assuan_gpg_strsource)
-#define _assuan_write_line _ASSUAN_PREFIX(_assuan_write_line)
-#define _assuan_error _ASSUAN_PREFIX(_assuan_error)
-#define _assuan_error_is_eagain _ASSUAN_PREFIX(_assuan_error_is_eagain)
-#define _assuan_init_uds_io _ASSUAN_PREFIX(_assuan_init_uds_io)
-#define _assuan_uds_close_fds _ASSUAN_PREFIX(_assuan_uds_close_fds)
-#define _assuan_uds_deinit _ASSUAN_PREFIX(_assuan_uds_deinit)
-#define _assuan_simple_recvmsg _ASSUAN_PREFIX(_assuan_simple_recvmsg)
-#define _assuan_simple_sendmsg _ASSUAN_PREFIX(_assuan_simple_sendmsg)
-#define _assuan_waitpid _ASSUAN_PREFIX(_assuan_waitpid)
-#define _assuan_sock_wsa2errno _ASSUAN_PREFIX(_assuan_sock_wsa2errno)
-#define _assuan_sock_close _ASSUAN_PREFIX(_assuan_sock_close)
-#define _assuan_sock_new _ASSUAN_PREFIX(_assuan_sock_new)
-#define _assuan_sock_connect _ASSUAN_PREFIX(_assuan_sock_connect)
-#define _assuan_sock_bind _ASSUAN_PREFIX(_assuan_sock_bind)
-#define _assuan_sock_get_nonce _ASSUAN_PREFIX(_assuan_sock_get_nonce)
-#define _assuan_sock_check_nonce _ASSUAN_PREFIX(_assuan_sock_check_nonce)
-
-#endif /*_ASSUAN_EXT_SYM_PREFIX*/
-
-
#ifdef __cplusplus
extern "C"
{
@@ -217,20 +83,6 @@ extern "C"
#endif
-/* Definitions of flags for assuan_set_flag(). */
-typedef unsigned int assuan_flag_t;
-
-/* When using a pipe server, by default Assuan will wait for the
- forked process to die in assuan_disconnect. In certain cases this
- is not desirable. By setting this flag, the waitpid will be
- skipped and the caller is responsible to cleanup a forked
- process. */
-#define ASSUAN_NO_WAITPID 1
-/* This flag indicates whether Assuan logging is in confidential
- mode. Use assuan_{begin,end}_condidential to change the mode. */
-#define ASSUAN_CONFIDENTIAL 2
-
-
#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */
struct assuan_context_s;
@@ -279,19 +131,146 @@ struct sockaddr_un
};
#endif
+
+/* Global interface. */
-/* Definition of hook functions used to conditionally replace the
- default I/O functions. */
-struct assuan_io_hooks
+struct assuan_malloc_hooks
{
- int (*read_hook)(assuan_context_t, assuan_fd_t, void *, size_t, ssize_t *);
- int (*write_hook)(assuan_context_t, assuan_fd_t fd,
- const void *, size_t, ssize_t *);
+ void *(*malloc) (size_t cnt);
+ void *(*realloc) (void *ptr, size_t cnt);
+ void (*free) (void *ptr);
};
-typedef struct assuan_io_hooks *assuan_io_hooks_t;
+typedef struct assuan_malloc_hooks *assuan_malloc_hooks_t;
+
+/* Categories for log messages. */
+#define ASSUAN_LOG_INIT 1
+#define ASSUAN_LOG_CTX 2
+#define ASSUAN_LOG_ENGINE 3
+#define ASSUAN_LOG_DATA 4
+#define ASSUAN_LOG_SYSIO 5
+
+/* If MSG is NULL, return true/false depending on if this category is
+ logged. This is used to probe before expensive log message
+ generation (buffer dumps). */
+typedef int (*assuan_log_cb_t) (assuan_context_t ctx, void *hook,
+ unsigned int cat, const char *msg);
+
+/* Set the default gpg error source. */
+void assuan_set_gpg_err_source (gpg_err_source_t errsource);
+
+/* Get the default gpg error source. */
+gpg_err_source_t assuan_get_gpg_err_source (void);
+
+
+/* Set the default malloc hooks. */
+void assuan_set_malloc_hooks (assuan_malloc_hooks_t malloc_hooks);
+
+/* Get the default malloc hooks. */
+assuan_malloc_hooks_t assuan_get_malloc_hooks (void);
+
+
+/* Set the default log callback handler. */
+void assuan_set_log_cb (assuan_log_cb_t log_cb, void *log_cb_data);
+
+/* Get the default log callback handler. */
+void assuan_get_log_cb (assuan_log_cb_t *log_cb, void **log_cb_data);
+
+
+/* Create a new Assuan context. The initial parameters are all needed
+ in the creation of the context. */
+gpg_error_t assuan_new_ext (assuan_context_t *ctx, gpg_err_source_t errsource,
+ assuan_malloc_hooks_t malloc_hooks,
+ assuan_log_cb_t log_cb, void *log_cb_data);
+
+/* Create a new context with default arguments. */
+gpg_error_t assuan_new (assuan_context_t *ctx);
+
+/* Release all resources associated with the given context. */
+void assuan_release (assuan_context_t ctx);
+
+/* Set user-data in a context. */
+void assuan_set_pointer (assuan_context_t ctx, void *pointer);
+
+/* Get user-data in a context. */
+void *assuan_get_pointer (assuan_context_t ctx);
+
+
+/* Definitions of flags for assuan_set_flag(). */
+typedef unsigned int assuan_flag_t;
+
+/* When using a pipe server, by default Assuan will wait for the
+ forked process to die in assuan_release. In certain cases this
+ is not desirable. By setting this flag, the waitpid will be
+ skipped and the caller is responsible to cleanup a forked
+ process. */
+#define ASSUAN_NO_WAITPID 1
+/* This flag indicates whether Assuan logging is in confidential mode.
+ You can use assuan_{begin,end}_condidential to change the mode. */
+#define ASSUAN_CONFIDENTIAL 2
+
+/* For context CTX, set the flag FLAG to VALUE. Values for flags
+ are usually 1 or 0 but certain flags might allow for other values;
+ see the description of the type assuan_flag_t for details. */
+void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value);
+
+/* Return the VALUE of FLAG in context CTX. */
+int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag);
+
+
+/* Same as assuan_set_flag (ctx, ASSUAN_NO_WAITPID, 1). */
+void assuan_begin_confidential (assuan_context_t ctx);
+
+/* Same as assuan_set_flag (ctx, ASSUAN_NO_WAITPID, 0). */
+void assuan_end_confidential (assuan_context_t ctx);
+
+
+/* Direction values for assuan_set_io_monitor. */
+#define ASSUAN_IO_FROM_PEER 0
+#define ASSUAN_IO_TO_PEER 1
+
+/* Return flags of I/O monitor. */
+#define ASSUAN_IO_MONITOR_NOLOG 1
+#define ASSUAN_IO_MONITOR_IGNORE 2
+
+/* The IO monitor gets to see all I/O on the context, and can return
+ ASSUAN_IO_MONITOR_* bits to control actions on it. */
+typedef unsigned int (*assuan_io_monitor_t) (assuan_context_t ctx, void *hook,
+ int inout, const char *line,
+ size_t linelen);
+
+/* Set the IO monitor function. */
+void assuan_set_io_monitor (assuan_context_t ctx,
+ assuan_io_monitor_t io_monitor, void *hook_data);
+
+/* Configuration of the default log handler. */
+/* Set the stream to which assuan should log message not associated
+ with a context. By default, this is stderr. The default value
+ will be changed when the first log stream is associated with a
+ context. Note, that this function is not thread-safe and should
+ in general be used right at startup. */
+extern void assuan_set_assuan_log_stream (FILE *fp);
+
+/* Return the stream which is currently being using for global logging. */
+extern FILE *assuan_get_assuan_log_stream (void);
+
+/* Set the prefix to be used at the start of a line emitted by assuan
+ on the log stream. The default is the empty string. Note, that
+ this function is not thread-safe and should in general be used
+ right at startup. */
+void assuan_set_assuan_log_prefix (const char *text);
+
+/* Return a prefix to be used at the start of a line emitted by assuan
+ on the log stream. The default implementation returns the empty
+ string, i.e. "" */
+const char *assuan_get_assuan_log_prefix (void);
+
+/* Set the per context log stream for the default log handler. */
+void assuan_set_log_stream (assuan_context_t ctx, FILE *fp);
+
+
/*-- assuan-handler.c --*/
gpg_error_t assuan_register_command (assuan_context_t ctx,
const char *cmd_string,
@@ -344,41 +323,40 @@ gpg_error_t assuan_close_output_fd (assuan_context_t ctx);
/*-- assuan-pipe-server.c --*/
-gpg_error_t assuan_init_pipe_server (assuan_context_t *r_ctx, int filedes[2]);
-void assuan_deinit_server (assuan_context_t ctx);
+gpg_error_t assuan_init_pipe_server (assuan_context_t ctx, int filedes[2]);
/*-- assuan-socket-server.c --*/
-gpg_error_t assuan_init_socket_server (assuan_context_t *r_ctx,
+gpg_error_t assuan_init_socket_server (assuan_context_t ctx,
assuan_fd_t listen_fd);
-gpg_error_t assuan_init_socket_server_ext (assuan_context_t *r_ctx,
+gpg_error_t assuan_init_socket_server_ext (assuan_context_t ctx,
assuan_fd_t fd,
unsigned int flags);
void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce);
/*-- assuan-pipe-connect.c --*/
-gpg_error_t assuan_pipe_connect (assuan_context_t *ctx,
+gpg_error_t assuan_pipe_connect (assuan_context_t ctx,
const char *name,
- const char *const argv[],
+ const char *argv[],
int *fd_child_list);
-gpg_error_t assuan_pipe_connect_ext (assuan_context_t *ctx,
+gpg_error_t assuan_pipe_connect_ext (assuan_context_t ctx,
const char *name,
- const char *const argv[],
+ const char *argv[],
int *fd_child_list,
void (*atfork) (void *, int),
void *atforkvalue,
unsigned int flags);
/*-- assuan-socket-connect.c --*/
-gpg_error_t assuan_socket_connect (assuan_context_t *ctx,
+gpg_error_t assuan_socket_connect (assuan_context_t ctx,
const char *name,
pid_t server_pid);
-gpg_error_t assuan_socket_connect_ext (assuan_context_t *ctx,
+
+gpg_error_t assuan_socket_connect_ext (assuan_context_t ctx,
const char *name,
pid_t server_pid,
unsigned int flags);
/*-- assuan-connect.c --*/
-void assuan_disconnect (assuan_context_t ctx);
pid_t assuan_get_pid (assuan_context_t ctx);
#ifndef _WIN32
gpg_error_t assuan_get_peercred (assuan_context_t ctx,
@@ -424,63 +402,8 @@ gpg_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd);
/*-- assuan-util.c --*/
-void assuan_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
- void *(*new_realloc_func)(void *p, size_t n),
- void (*new_free_func)(void*) );
-void assuan_set_io_hooks (assuan_io_hooks_t io_hooks);
-void assuan_set_log_stream (assuan_context_t ctx, FILE *fp);
gpg_error_t assuan_set_error (assuan_context_t ctx, gpg_error_t err, const char *text);
-void assuan_set_pointer (assuan_context_t ctx, void *pointer);
-void *assuan_get_pointer (assuan_context_t ctx);
-
-void assuan_begin_confidential (assuan_context_t ctx);
-void assuan_end_confidential (assuan_context_t ctx);
-
-void assuan_set_io_monitor (assuan_context_t ctx,
- unsigned int (*monitor)(assuan_context_t ctx,
- int direction,
- const char *line,
- size_t linelen));
-
-/* For context CTX, set the flag FLAG to VALUE. Values for flags
- are usually 1 or 0 but certain flags might allow for other values;
- see the description of the type assuan_flag_t for details. */
-void assuan_set_flag (assuan_context_t ctx, assuan_flag_t flag, int value);
-
-/* Return the VALUE of FLAG in context CTX. */
-int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag);
-
-/*-- assuan-errors.c --*/
-
-/* Enable gpg-error style error codes. ERRSOURCE is one of gpg-error
- sources. Note, that this function is not thread-safe and should be
- used right at startup. Switching back to the old style mode is not
- supported. */
-void assuan_set_assuan_err_source (gpg_err_source_t errsource);
-
-/*-- assuan-logging.c --*/
-
-/* Set the stream to which assuan should log message not associated
- with a context. By default, this is stderr. The default value
- will be changed when the first log stream is associated with a
- context. Note, that this function is not thread-safe and should
- in general be used right at startup. */
-extern void assuan_set_assuan_log_stream (FILE *fp);
-
-/* Return the stream which is currently being using for global logging. */
-extern FILE *assuan_get_assuan_log_stream (void);
-
-/* Set the prefix to be used at the start of a line emitted by assuan
- on the log stream. The default is the empty string. Note, that
- this function is not thread-safe and should in general be used
- right at startup. */
-void assuan_set_assuan_log_prefix (const char *text);
-
-/* Return a prefix to be used at the start of a line emitted by assuan
- on the log stream. The default implementation returns the empty
- string, i.e. "" */
-const char *assuan_get_assuan_log_prefix (void);
/*-- assuan-socket.c --*/