aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog52
-rw-r--r--src/Makefile.am75
-rw-r--r--src/assuan-buffer.c83
-rw-r--r--src/assuan-client.c65
-rw-r--r--src/assuan-connect.c40
-rw-r--r--src/assuan-defs.h76
-rw-r--r--src/assuan-error.c70
-rw-r--r--src/assuan-handler.c204
-rw-r--r--src/assuan-inquire.c85
-rw-r--r--src/assuan-io-pth.c38
-rw-r--r--src/assuan-io.c38
-rw-r--r--src/assuan-listen.c63
-rw-r--r--src/assuan-logging.c78
-rw-r--r--src/assuan-pipe-connect.c115
-rw-r--r--src/assuan-pipe-server.c51
-rw-r--r--src/assuan-socket-connect.c52
-rw-r--r--src/assuan-socket-server.c45
-rw-r--r--src/assuan-socket.c35
-rw-r--r--src/assuan-uds.c54
-rw-r--r--src/assuan-util.c42
-rw-r--r--src/assuan.h265
-rw-r--r--src/libassuan-config.in9
-rw-r--r--src/libassuan.def88
-rw-r--r--src/libassuan.vers93
-rwxr-xr-xsrc/mkerrors257
-rw-r--r--src/versioninfo.rc.in52
26 files changed, 1003 insertions, 1122 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b2ed9b2..1897f0e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,55 @@
+2009-08-26 Marcus Brinkmann <[email protected]>
+
+ * libassuan-config.in: Add gpg-error.
+ * assuan-buffer.c, assuan-inquire.c, assuan-handler.c,
+ assuan-util.c, assuan-client.c, assuan-socket-connect.c,
+ assuan-pipe-connect.c, assuan-defs.h, assuan-socket.c,
+ assuan-connect.c, assuan-uds.c, assuan-socket-server.c,
+ assuan-listen.c, assuan-pipe-server.c: Return gpg_error_t instead
+ assuan_error_t everywhere. Return gpg error codes everywhere.
+ Replace xtrymalloc, xfree, etc with _assuan_malloc, _assuan_free
+ etc. Protect include <config.h> by HAVE_CONFIG_H where not done
+ so already.
+ * versioninfo.rc.in, libassuan.vers, libassuan.def,
+ assuan-error.c: New files.
+ * Makefile.am: Add libtool handling and gpg-error (also for W32).
+ (EXTRA_DIST): Remove mkerrors, add libassuan.vers,
+ versioninfo.rc.in and libassuan.def.
+ (BUILT_SOURCES, MOSTLYCLEANFILES): Removed.
+ (common_sources): Remove assuan-errors.c, add assuan-error.c.
+ * assuan.h: Include <gpg-error.h>.
+ [_ASSUAN_ONLY_GPG_ERRORS]: Feature removed.
+ (assuan_init_connected_socket_server, assuan_strerror)
+ (assuan_pipe_connect2): Removed obsolete interfaces.
+ (assuan_error_t): Removed type.
+ (assuan_flag_t): Changed from enum to unsigned int.
+ (ASSUAN_NO_WAITPID, ASSUAN_CONFIDENTIAL): Changed from enum to macro.
+ (assuan_process): Return gpg_error_t instead of int.
+ (assuan_set_assuan_err_source): Change argument type from int to
+ gpg_err_source_t.
+ * assuan-defs.h (_assuan_error): Change types to gpg_error_t.
+ (err_code, err_is_eof, xtrymalloc, xtrycalloc, xtryrealloc)
+ (xfree): Removed.
+ (set_error): Adjust for gpg-error codes.
+ (_assuan_gpg_strerror_r, _assuan_gpg_strsource): Removed.
+ (struct assuan_context_s): Remove member os_errno.
+ * assuan-socket-server.c (accept_connection): Don't set CTX->os_errno.
+ * mkerrors: Removed file.
+ * assuan-io-pth.c (_assuan_simple_sendmsg)
+ (_assuan_simple_recvmsg), assuan-io.c (_assuan_simple_sendmsg,
+ _assuan_simple_recvmsg): Set errno instead returning error
+ directly (and return -1).
+ * assuan-handler.c (assuan_process_done): Remove handling for old
+ style error values.
+ (process_request, assuan_process): Change return type from int to
+ gpg_error_t.
+ * assuan-client.c (assuan_transact): Remove support for old style
+ error values.
+ * assuan-pipe-connect.c (assuan_pipe_connect2): Removed.
+ * assuan-logging.c (my_strerror_r, my_strsource)
+ (load_libgpg_error, _assuan_gpg_strerror_r)
+ (_assuan_gpg_strsource): Removed.
+
2009-04-03 Werner Koch <[email protected]>
* assuan-handler.c (std_cmd_table): Remove second OPTION entry.
diff --git a/src/Makefile.am b/src/Makefile.am
index 77d87af..6749801 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
# Assuan Makefile
-# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
#
# This file is part of Assuan.
#
@@ -17,13 +17,12 @@
# License along with this program; if not, see <http://www.gnu.org/licenses/>.
## Process this file with automake to produce Makefile.in
-EXTRA_DIST = libassuan-config.in mkerrors libassuan.m4
+EXTRA_DIST = libassuan-config.in libassuan.m4 libassuan.vers \
+ versioninfo.rc.in libassuan.def
INCLUDES = -I.. -I$(top_srcdir)/include
-BUILT_SOURCES = assuan-errors.c
-MOSTLYCLEANFILES = assuan-errors.c
if HAVE_PTH
-libassuan_pth = libassuan-pth.a
+libassuan_pth = libassuan-pth.la
else
libassuan_pth =
endif
@@ -31,14 +30,20 @@ endif
bin_SCRIPTS = libassuan-config
m4datadir = $(datadir)/aclocal
m4data_DATA = libassuan.m4
-lib_LIBRARIES = libassuan.a $(libassuan_pth)
+lib_LTLIBRARIES = libassuan.la $(libassuan_pth)
include_HEADERS = assuan.h
+if HAVE_LD_VERSION_SCRIPT
+libassuan_version_script_cmd = -Wl,--version-script=$(srcdir)/libassuan.vers
+else
+libassuan_version_script_cmd =
+endif
+
common_sources = \
assuan-defs.h \
assuan-util.c \
- assuan-errors.c \
+ assuan-error.c \
assuan-buffer.c \
assuan-handler.c \
assuan-inquire.c \
@@ -53,14 +58,56 @@ common_sources = \
assuan-logging.c \
assuan-socket.c
-libassuan_a_SOURCES = $(common_sources) assuan-io.c
-libassuan_a_LIBADD = @LIBOBJS@
+if HAVE_W32_SYSTEM
+
+LTRCCOMPILE = $(LIBTOOL) --mode=compile $(RC) \
+ `echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \
+ sed -e 's/-I/--include-dir /g;s/-D/--define /g'`
+
+SUFFIXES: .rc .lo
+
+.rc.lo:
+ $(LTRCCOMPILE) -i $< -o $@
+
+libassuan_res = versioninfo.lo
+libassuan_res_ldflag = -Wl,.libs/versioninfo.o
+
+no_undefined = -no-undefined
+export_symbols = -export-symbols $(srcdir)/libassuan.def
+
+install-def-file:
+ $(INSTALL) $(srcdir)/libassuan.def $(DESTDIR)$(libdir)/libassuan.def
+
+uninstall-def-file:
+ -rm $(DESTDIR)$(libdir)/libassuan.def
+
+libassuan_deps = $(libassuan_res) libassuan.def
+
+else
+libassuan_res =
+libassuan_res_ldflag =
+no_undefined =
+export_symbols =
+install-def-file:
+uninstall-def-file:
+
+libassuan_deps =
+endif
+
+
+libassuan_la_SOURCES = $(common_sources) assuan-io.c
+libassuan_la_CPPFLAGS = $(AM_CPPFLAGS) @GPG_ERROR_CFLAGS@
+libassuan_la_LDFLAGS = $(libassuan_res_ldflag) $(no_undefined) \
+ $(export_symbols) $(libassuan_version_script_cmd) -version-info \
+ @LIBASSUAN_LT_CURRENT@:@LIBASSUAN_LT_REVISION@:@LIBASSUAN_LT_AGE@
+libassuan_la_DEPENDENCIES = @LTLIBOBJS@ \
+ $(srcdir)/libassuan.vers $(libassuan_deps)
+libassuan_la_LIBADD = @LTLIBOBJS@ @GPG_ERROR_LIBS@
if HAVE_PTH
-libassuan_pth_a_SOURCES = $(common_sources) assuan-io-pth.c
-libassuan_pth_a_CFLAGS = $(AM_CFLAGS) $(PTH_CFLAGS)
-libassuan_pth_a_LIBADD = @LIBOBJS@
+libassuan_pth_la_SOURCES = $(common_sources) assuan-io-pth.c
+libassuan_pth_la_CPPFLAGS = $(AM_CPPFLAGS) @GPG_ERROR_CFLAGS@ @PTH_CFLAGS@
+libassuan_pth_la_CFLAGS = $(AM_CFLAGS) @GPG_ERROR_CFLAGS@ $(PTH_CFLAGS)
+libassuan_pth_la_LIBADD = @LTLIBOBJS@ @GPG_ERROR_LIBS@ @PTH_LIBS@
endif
-assuan-errors.c : assuan.h mkerrors
- $(srcdir)/mkerrors < $(srcdir)/assuan.h > assuan-errors.c
diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c
index b9e3572..84538f4 100644
--- a/src/assuan-buffer.c
+++ b/src/assuan-buffer.c
@@ -1,20 +1,20 @@
/* assuan-buffer.c - read and send data
- * Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001-2004, 2006, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
@@ -94,7 +94,7 @@ readline (assuan_context_t ctx, char *buf, size_t buflen,
/* Function returns an Assuan error. */
-assuan_error_t
+gpg_error_t
_assuan_read_line (assuan_context_t ctx)
{
char *line = ctx->inbound.line;
@@ -150,7 +150,7 @@ _assuan_read_line (assuan_context_t ctx)
}
errno = saved_errno;
- return _assuan_error (ASSUAN_Read_Error);
+ return _assuan_error (gpg_err_code_from_syserror ());
}
if (!nread)
{
@@ -159,7 +159,8 @@ _assuan_read_line (assuan_context_t ctx)
fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- [EOF]\n",
assuan_get_assuan_log_prefix (),
(unsigned int)getpid (), (int)ctx->inbound.fd);
- return _assuan_error (-1);
+
+ return _assuan_error (GPG_ERR_EOF);
}
ctx->inbound.attic.pending = 0;
@@ -222,8 +223,8 @@ _assuan_read_line (assuan_context_t ctx)
*line = 0;
ctx->inbound.linelen = 0;
return _assuan_error (ctx->inbound.eof
- ? ASSUAN_Line_Not_Terminated
- : ASSUAN_Line_Too_Long);
+ ? GPG_ERR_ASS_INCOMPLETE_LINE
+ : GPG_ERR_ASS_LINE_TOO_LONG);
}
}
@@ -237,13 +238,13 @@ _assuan_read_line (assuan_context_t ctx)
Returns 0 on success or an assuan error code.
See also: assuan_pending_line().
*/
-assuan_error_t
+gpg_error_t
assuan_read_line (assuan_context_t ctx, char **line, size_t *linelen)
{
- assuan_error_t err;
+ gpg_error_t err;
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
do
{
@@ -266,11 +267,11 @@ assuan_pending_line (assuan_context_t ctx)
}
-assuan_error_t
+gpg_error_t
_assuan_write_line (assuan_context_t ctx, const char *prefix,
const char *line, size_t len)
{
- assuan_error_t rc = 0;
+ gpg_error_t rc = 0;
size_t prefixlen = prefix? strlen (prefix):0;
unsigned int monitor_result;
@@ -313,32 +314,32 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix,
{
rc = writen (ctx, prefix, prefixlen);
if (rc)
- rc = _assuan_error (ASSUAN_Write_Error);
+ rc = _assuan_error (gpg_err_code_from_syserror ());
}
if (!rc && !(monitor_result & 2))
{
rc = writen (ctx, line, len);
if (rc)
- rc = _assuan_error (ASSUAN_Write_Error);
+ rc = _assuan_error (gpg_err_code_from_syserror ());
if (!rc)
{
rc = writen (ctx, "\n", 1);
if (rc)
- rc = _assuan_error (ASSUAN_Write_Error);
+ rc = _assuan_error (gpg_err_code_from_syserror ());
}
}
return rc;
}
-assuan_error_t
+gpg_error_t
assuan_write_line (assuan_context_t ctx, const char *line)
{
size_t len;
const char *s;
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
/* Make sure that we never take a LF from the user - this might
violate the protocol. */
@@ -429,7 +430,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size)
if ( !(monitor_result & 2)
&& writen (ctx, ctx->outbound.data.line, linelen))
{
- ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error);
+ ctx->outbound.data.error = gpg_err_code_from_syserror ();
return 0;
}
line = ctx->outbound.data.line;
@@ -483,7 +484,7 @@ _assuan_cookie_write_flush (void *cookie)
if ( !(monitor_result & 2)
&& writen (ctx, ctx->outbound.data.line, linelen))
{
- ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error);
+ ctx->outbound.data.error = gpg_err_code_from_syserror ();
return 0;
}
ctx->outbound.data.linelen = 0;
@@ -513,13 +514,13 @@ _assuan_cookie_write_flush (void *cookie)
* Return value: 0 on success or an error code
**/
-assuan_error_t
+gpg_error_t
assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length)
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!buffer && length > 1)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!buffer)
{ /* flush what we have */
@@ -539,7 +540,7 @@ assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length)
return 0;
}
-assuan_error_t
+gpg_error_t
assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd)
{
/* It is explicitly allowed to use (NULL, -1) as a runtime test to
@@ -548,21 +549,21 @@ assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd)
#ifdef USE_DESCRIPTOR_PASSING
return 0;
#else
- return _assuan_error (ASSUAN_Not_Implemented);
+ return _assuan_error (GPG_ERR_NOT_IMPLEMENTED);
#endif
if (! ctx->io->sendfd)
- return set_error (ctx, Not_Implemented,
+ return set_error (ctx, GPG_ERR_NOT_IMPLEMENTED,
"server does not support sending and receiving "
"of file descriptors");
return ctx->io->sendfd (ctx, fd);
}
-assuan_error_t
+gpg_error_t
assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd)
{
if (! ctx->io->receivefd)
- return set_error (ctx, Not_Implemented,
+ return set_error (ctx, GPG_ERR_NOT_IMPLEMENTED,
"server does not support sending and receiving "
"of file descriptors");
return ctx->io->receivefd (ctx, fd);
diff --git a/src/assuan-client.c b/src/assuan-client.c
index 15f4f1c..3d3748c 100644
--- a/src/assuan-client.c
+++ b/src/assuan-client.c
@@ -1,23 +1,26 @@
/* assuan-client.c - client functions
- * Copyright (C) 2001, 2002, 2005 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001, 2002, 2005, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
@@ -31,12 +34,12 @@
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
-assuan_error_t
+gpg_error_t
_assuan_read_from_server (assuan_context_t ctx, int *okay, int *off)
{
char *line;
int linelen;
- assuan_error_t rc;
+ gpg_error_t rc;
*okay = 0;
*off = 0;
@@ -106,7 +109,7 @@ _assuan_read_from_server (assuan_context_t ctx, int *okay, int *off)
*off = 3;
}
else
- rc = _assuan_error (ASSUAN_Invalid_Response);
+ rc = _assuan_error (GPG_ERR_ASS_INV_RESPONSE);
return rc;
}
@@ -131,17 +134,17 @@ _assuan_read_from_server (assuan_context_t ctx, int *okay, int *off)
* this function returns immediately with an error and thus the caller
* will altter return an Assuan error (write erro in most cases).
**/
-assuan_error_t
+gpg_error_t
assuan_transact (assuan_context_t ctx,
const char *command,
- int (*data_cb)(void *, const void *, size_t),
+ gpg_error_t (*data_cb)(void *, const void *, size_t),
void *data_cb_arg,
- int (*inquire_cb)(void*, const char *),
+ gpg_error_t (*inquire_cb)(void*, const char *),
void *inquire_cb_arg,
- int (*status_cb)(void*, const char *),
+ gpg_error_t (*status_cb)(void*, const char *),
void *status_cb_arg)
{
- assuan_error_t rc;
+ gpg_error_t rc;
int okay, off;
char *line;
int linelen;
@@ -162,17 +165,11 @@ assuan_transact (assuan_context_t ctx,
linelen = ctx->inbound.linelen - off;
if (!okay)
- {
- rc = atoi (line);
- if (rc > 0 && rc < 100)
- rc = _assuan_error (ASSUAN_Server_Fault);
- else if (rc > 0 && rc <= 405)
- rc = _assuan_error (rc);
- }
+ rc = atoi (line);
else if (okay == 2)
{
if (!data_cb)
- rc = _assuan_error (ASSUAN_No_Data_Callback);
+ rc = _assuan_error (GPG_ERR_ASS_NO_DATA_CB);
else
{
char *s, *d;
@@ -201,7 +198,7 @@ assuan_transact (assuan_context_t ctx,
{
assuan_write_line (ctx, "END"); /* get out of inquire mode */
_assuan_read_from_server (ctx, &okay, &off); /* dummy read */
- rc = _assuan_error (ASSUAN_No_Inquire_Callback);
+ rc = _assuan_error (GPG_ERR_ASS_NO_INQUIRE_CB);
}
else
{
@@ -222,7 +219,7 @@ assuan_transact (assuan_context_t ctx,
else if (okay == 5)
{
if (!data_cb)
- rc = _assuan_error (ASSUAN_No_Data_Callback);
+ rc = _assuan_error (GPG_ERR_ASS_NO_DATA_CB);
else
{
rc = data_cb (data_cb_arg, NULL, 0);
diff --git a/src/assuan-connect.c b/src/assuan-connect.c
index 2106ac3..c2c7f42 100644
--- a/src/assuan-connect.c
+++ b/src/assuan-connect.c
@@ -1,20 +1,20 @@
/* assuan-connect.c - Establish a connection (client)
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001, 2002, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
@@ -53,7 +53,7 @@ assuan_disconnect (assuan_context_t ctx)
pid_t
assuan_get_pid (assuan_context_t ctx)
{
- return (ctx && ctx->pid)? ctx->pid : -1;
+ return (ctx && ctx->pid) ? ctx->pid : -1;
}
@@ -61,13 +61,13 @@ assuan_get_pid (assuan_context_t ctx)
/* Return user credentials. PID, UID and GID may be given as NULL if
you are not interested in a value. For getting the pid of the
peer the assuan_get_pid is usually better suited. */
-assuan_error_t
+gpg_error_t
assuan_get_peercred (assuan_context_t ctx, pid_t *pid, uid_t *uid, gid_t *gid)
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!ctx->peercred.valid)
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
#ifdef HAVE_SO_PEERCRED
if (pid)
diff --git a/src/assuan-defs.h b/src/assuan-defs.h
index e2d0f52..c87e946 100644
--- a/src/assuan-defs.h
+++ b/src/assuan-defs.h
@@ -1,22 +1,20 @@
-/* assuan-defs.c - Internal definitions to Assuan
- * Copyright (C) 2001, 2002, 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
+/* assuan-defs.h - Internal definitions to Assuan
+ Copyright (C) 2001, 2002, 2004, 2005, 2007-2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASSUAN_DEFS_H
@@ -69,9 +67,9 @@ struct assuan_io
/* Routine to write to output_fd. */
ssize_t (*writefnc) (assuan_context_t, const void *, size_t);
/* Send a file descriptor. */
- assuan_error_t (*sendfd) (assuan_context_t, assuan_fd_t);
+ gpg_error_t (*sendfd) (assuan_context_t, assuan_fd_t);
/* Receive a file descriptor. */
- assuan_error_t (*receivefd) (assuan_context_t, assuan_fd_t *);
+ gpg_error_t (*receivefd) (assuan_context_t, assuan_fd_t *);
};
@@ -82,10 +80,8 @@ extern struct assuan_io_hooks _assuan_io_hooks;
/* The context we use with most functions. */
struct assuan_context_s
{
- assuan_error_t err_no;
+ gpg_error_t err_no;
const char *err_str;
- int os_errno; /* Last system error number used with certain
- error codes. */
/* Context specific flags (cf. assuan_flag_t). */
struct
@@ -219,14 +215,14 @@ void _assuan_init_uds_io (assuan_context_t ctx);
int _assuan_register_std_commands (assuan_context_t ctx);
/*-- assuan-buffer.c --*/
-assuan_error_t _assuan_read_line (assuan_context_t ctx);
+gpg_error_t _assuan_read_line (assuan_context_t ctx);
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
int _assuan_cookie_write_flush (void *cookie);
-assuan_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix,
+gpg_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix,
const char *line, size_t len);
/*-- assuan-client.c --*/
-assuan_error_t _assuan_read_from_server (assuan_context_t ctx,
+gpg_error_t _assuan_read_from_server (assuan_context_t ctx,
int *okay, int *off);
/*-- assuan-error.c --*/
@@ -235,21 +231,8 @@ assuan_error_t _assuan_read_from_server (assuan_context_t ctx,
int _assuan_inquire_ext_cb (assuan_context_t ctx);
void _assuan_inquire_release (assuan_context_t ctx);
-/* Map error codes as used in this implementation to the libgpg-error
- codes. */
-assuan_error_t _assuan_error (int oldcode);
/* Check if ERR means EAGAIN. */
-int _assuan_error_is_eagain (assuan_error_t err);
-
-/* Extract the error code from A. This works for both the old and the
- new style error codes. This needs to be used whenever an error
- code is compared. */
-#define err_code(a) ((a) & 0x00ffffff)
-
-/* Check whether A is the erro code for EOF. We allow for old and new
- style EOF error codes here. */
-#define err_is_eof(a) ((a) == (-1) || err_code (a) == 16383)
-
+int _assuan_error_is_eagain (gpg_error_t err);
/*-- assuan-util.c --*/
@@ -258,19 +241,14 @@ 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))
+gpg_error_t _assuan_error (gpg_err_code_t errcode);
-#define set_error(c,e,t) \
- assuan_set_error ((c), _assuan_error (ASSUAN_ ## e), (t))
+#define set_error(c,e,t) \
+ assuan_set_error ((c), _assuan_error (e), (t))
#ifdef HAVE_W32_SYSTEM
const char *_assuan_w32_strerror (int ec);
#define w32_strerror(e) _assuan_w32_strerror ((e))
-int _assuan_gpg_strerror_r (unsigned int err, char *buf, size_t buflen);
-const char *_assuan_gpg_strsource (unsigned int err);
#endif /*HAVE_W32_SYSTEM*/
diff --git a/src/assuan-error.c b/src/assuan-error.c
new file mode 100644
index 0000000..4eba7ff
--- /dev/null
+++ b/src/assuan-error.c
@@ -0,0 +1,70 @@
+/* assuan-error.c
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <assert.h>
+#include <errno.h>
+
+#undef _ASSUAN_IN_LIBASSUAN /* undef to get all error codes. */
+#include "assuan.h"
+#include "assuan-defs.h"
+
+/* If true the modern gpg-error style error codes are used in the
+ API. */
+static gpg_err_source_t err_source;
+
+/* 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)
+{
+ errsource &= 0xff;
+ err_source = errsource ? errsource : 31 /*GPG_ERR_SOURCE_ANY*/;
+}
+
+
+/* Helper to map old style Assuan error codes to gpg-error codes.
+ This is used internally to keep an compatible ABI. */
+gpg_error_t
+_assuan_error (gpg_err_code_t errcode)
+{
+ return gpg_err_make (err_source, errcode);
+}
+
+
+/* A small helper function to treat EAGAIN transparently to the
+ caller. */
+int
+_assuan_error_is_eagain (gpg_error_t err)
+{
+ if (gpg_err_code (err) == GPG_ERR_EAGAIN)
+ {
+ /* Avoid spinning by sleeping for one tenth of a second. */
+ _assuan_usleep (100000);
+ return 1;
+ }
+ else
+ return 0;
+}
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index 007bba2..bc8ec51 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -1,23 +1,26 @@
/* assuan-handler.c - dispatch commands
- * Copyright (C) 2001, 2002, 2003, 2007 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001, 2002, 2003, 2007, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -40,7 +43,8 @@ static int
dummy_handler (assuan_context_t ctx, char *line)
{
return
- PROCESS_DONE (ctx, set_error (ctx, Server_Fault, "no handler registered"));
+ PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_ASSUAN_SERVER_FAULT,
+ "no handler registered"));
}
@@ -55,7 +59,7 @@ std_handler_cancel (assuan_context_t ctx, char *line)
{
if (ctx->cancel_notify_fnc)
ctx->cancel_notify_fnc (ctx);
- return PROCESS_DONE (ctx, set_error (ctx, Not_Implemented, NULL));
+ return PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_NOT_IMPLEMENTED, NULL));
}
static int
@@ -67,10 +71,10 @@ std_handler_option (assuan_context_t ctx, char *line)
;
if (!*key)
return
- PROCESS_DONE (ctx, set_error (ctx, Syntax_Error, "argument required"));
+ PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_ASS_SYNTAX, "argument required"));
if (*key == '=')
return
- PROCESS_DONE (ctx, set_error (ctx, Syntax_Error,
+ PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_ASS_SYNTAX,
"no option name given"));
for (value=key; *value && !spacep (value) && *value != '='; value++)
;
@@ -87,7 +91,7 @@ std_handler_option (assuan_context_t ctx, char *line)
;
if (!*value)
return
- PROCESS_DONE (ctx, set_error (ctx, Syntax_Error,
+ PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_ASS_SYNTAX,
"option argument expected"));
}
if (*value)
@@ -103,7 +107,7 @@ std_handler_option (assuan_context_t ctx, char *line)
key += 2; /* the double dashes are optional */
if (*key == '-')
return PROCESS_DONE (ctx,
- set_error (ctx, Syntax_Error,
+ set_error (ctx, GPG_ERR_ASS_SYNTAX,
"option should not begin with one dash"));
if (ctx->option_handler_fnc)
@@ -118,13 +122,14 @@ std_handler_bye (assuan_context_t ctx, char *line)
ctx->bye_notify_fnc (ctx);
assuan_close_input_fd (ctx);
assuan_close_output_fd (ctx);
- return PROCESS_DONE (ctx, _assuan_error (-1)); /* pretty simple :-) */
+ /* pretty simple :-) */
+ return PROCESS_DONE (ctx, _assuan_error (GPG_ERR_EOF));
}
static int
std_handler_auth (assuan_context_t ctx, char *line)
{
- return PROCESS_DONE (ctx, set_error (ctx, Not_Implemented, NULL));
+ return PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_NOT_IMPLEMENTED, NULL));
}
static int
@@ -158,24 +163,24 @@ std_handler_help (assuan_context_t ctx, char *line)
static int
std_handler_end (assuan_context_t ctx, char *line)
{
- return PROCESS_DONE (ctx, set_error (ctx, Not_Implemented, NULL));
+ return PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_NOT_IMPLEMENTED, NULL));
}
-assuan_error_t
+gpg_error_t
assuan_command_parse_fd (assuan_context_t ctx, char *line, assuan_fd_t *rfd)
{
char *endp;
if ((strncmp (line, "FD", 2) && strncmp (line, "fd", 2))
|| (line[2] != '=' && line[2] != '\0' && !spacep(&line[2])))
- return set_error (ctx, Syntax_Error, "FD[=<n>] expected");
+ return set_error (ctx, GPG_ERR_ASS_SYNTAX, "FD[=<n>] expected");
line += 2;
if (*line == '=')
{
line ++;
if (!digitp (*line))
- return set_error (ctx, Syntax_Error, "number required");
+ return set_error (ctx, GPG_ERR_ASS_SYNTAX, "number required");
#ifdef HAVE_W32_SYSTEM
/* Fixme: For a W32/64bit system we will need to change the cast
and the conversion fucntion. */
@@ -187,9 +192,9 @@ assuan_command_parse_fd (assuan_context_t ctx, char *line, assuan_fd_t *rfd)
memset (line, ' ', endp? (endp-line):strlen(line));
if (*rfd == ctx->inbound.fd)
- return set_error (ctx, Parameter_Conflict, "fd same as inbound fd");
+ return set_error (ctx, GPG_ERR_ASS_PARAMETER, "fd same as inbound fd");
if (*rfd == ctx->outbound.fd)
- return set_error (ctx, Parameter_Conflict, "fd same as outbound fd");
+ return set_error (ctx, GPG_ERR_ASS_PARAMETER, "fd same as outbound fd");
return 0;
}
else
@@ -282,7 +287,7 @@ assuan_register_command (assuan_context_t ctx,
cmd_name = NULL;
if (!cmd_name)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!handler)
{ /* find a default handler. */
@@ -303,18 +308,18 @@ assuan_register_command (assuan_context_t ctx,
if (!ctx->cmdtbl)
{
ctx->cmdtbl_size = 50;
- ctx->cmdtbl = xtrycalloc ( ctx->cmdtbl_size, sizeof *ctx->cmdtbl);
+ ctx->cmdtbl = _assuan_calloc (ctx->cmdtbl_size, sizeof *ctx->cmdtbl);
if (!ctx->cmdtbl)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
ctx->cmdtbl_used = 0;
}
else if (ctx->cmdtbl_used >= ctx->cmdtbl_size)
{
struct cmdtbl_s *x;
- x = xtryrealloc ( ctx->cmdtbl, (ctx->cmdtbl_size+10) * sizeof *x);
+ x = _assuan_realloc ( ctx->cmdtbl, (ctx->cmdtbl_size+10) * sizeof *x);
if (!x)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
ctx->cmdtbl = x;
ctx->cmdtbl_size += 50;
}
@@ -330,7 +335,7 @@ assuan_register_post_cmd_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t, int))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->post_cmd_notify_fnc = fnc;
return 0;
}
@@ -340,7 +345,7 @@ assuan_register_bye_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->bye_notify_fnc = fnc;
return 0;
}
@@ -350,7 +355,7 @@ assuan_register_reset_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->reset_notify_fnc = fnc;
return 0;
}
@@ -360,7 +365,7 @@ assuan_register_cancel_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->cancel_notify_fnc = fnc;
return 0;
}
@@ -371,7 +376,7 @@ assuan_register_option_handler (assuan_context_t ctx,
const char*, const char*))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->option_handler_fnc = fnc;
return 0;
}
@@ -381,7 +386,7 @@ assuan_register_input_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t, const char *))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->input_notify_fnc = fnc;
return 0;
}
@@ -391,7 +396,7 @@ assuan_register_output_notify (assuan_context_t ctx,
void (*fnc)(assuan_context_t, const char *))
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
ctx->output_notify_fnc = fnc;
return 0;
}
@@ -422,7 +427,7 @@ _assuan_register_std_commands (assuan_context_t ctx)
static int
handle_data_line (assuan_context_t ctx, char *line, int linelen)
{
- return set_error (ctx, Not_Implemented, NULL);
+ return set_error (ctx, GPG_ERR_NOT_IMPLEMENTED, NULL);
}
/* like ascii_strcasecmp but assume that B is already uppercase */
@@ -465,7 +470,7 @@ dispatch_command (assuan_context_t ctx, char *line, int linelen)
;
if (p==line)
return PROCESS_DONE
- (ctx, set_error (ctx, Syntax_Error, "leading white-space"));
+ (ctx, set_error (ctx, GPG_ERR_ASS_SYNTAX, "leading white-space"));
if (*p)
{ /* Skip over leading WS after the keyword */
*p++ = 0;
@@ -488,7 +493,7 @@ dispatch_command (assuan_context_t ctx, char *line, int linelen)
}
}
if (!s)
- return PROCESS_DONE (ctx, set_error (ctx, Unknown_Command, NULL));
+ return PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_ASS_UNKNOWN_CMD, NULL));
line += shift;
linelen -= shift;
@@ -502,7 +507,7 @@ int
assuan_process_done (assuan_context_t ctx, int rc)
{
if (!ctx->in_command)
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
ctx->in_command = 0;
@@ -526,9 +531,9 @@ assuan_process_done (assuan_context_t ctx, int rc)
/* Error handling. */
if (!rc)
{
- rc = assuan_write_line (ctx, ctx->okay_line? ctx->okay_line : "OK");
+ rc = assuan_write_line (ctx, ctx->okay_line ? ctx->okay_line : "OK");
}
- else if (err_is_eof (rc))
+ else if (gpg_err_code (rc) == GPG_ERR_EOF)
{ /* No error checking because the peer may have already disconnect. */
assuan_write_line (ctx, "OK closing connection");
ctx->finish_handler (ctx);
@@ -536,72 +541,15 @@ assuan_process_done (assuan_context_t ctx, int rc)
else
{
char errline[300];
-
- if (rc < 100)
- sprintf (errline, "ERR %d server fault (%.50s)",
- _assuan_error (ASSUAN_Server_Fault), assuan_strerror (rc));
- else
- {
- const char *text = ctx->err_no == rc? ctx->err_str:NULL;
-
-#if defined(HAVE_W32_SYSTEM)
- unsigned int source, code;
- char ebuf[50];
- const char *esrc;
+
+ const char *text = ctx->err_no == rc ? ctx->err_str : NULL;
+ char ebuf[50];
- source = ((rc >> 24) & 0xff);
- code = (rc & 0x00ffffff);
- if (source
- && !_assuan_gpg_strerror_r (rc, ebuf, sizeof ebuf)
- && (esrc=_assuan_gpg_strsource (rc)))
- {
- /* Assume this is an libgpg-error. */
- sprintf (errline, "ERR %d %.50s <%.30s>%s%.100s",
- rc, ebuf, esrc,
- text? " - ":"", text?text:"");
- }
- else
-#elif defined(__GNUC__) && defined(__ELF__)
- /* If we have weak symbol support we try to use the error
- strings from libgpg-error without creating a dependency.
- They are used for debugging purposes only, so there is no
- problem if they are not available. We need to make sure
- that we are using ELF because only this guarantees that
- weak symbol support is available in case GNU ld is not
- used. It seems that old gcc versions don't implement the
- weak attribute properly but it works with the weak
- pragma. */
-
- unsigned int source, code;
-
- int gpg_strerror_r (unsigned int err, char *buf, size_t buflen)
- __attribute__ ((weak));
- const char *gpg_strsource (unsigned int err)
- __attribute__ ((weak));
-#if __GNUC__ < 3
-#pragma weak gpg_strerror_r
-#pragma weak gpg_strsource
-#endif
+ gpg_strerror_r (rc, ebuf, sizeof (ebuf));
+ sprintf (errline, "ERR %d %.50s <%.30s>%s%.100s",
+ rc, ebuf, gpg_strsource (rc),
+ text? " - ":"", text?text:"");
- source = ((rc >> 24) & 0xff);
- code = (rc & 0x00ffffff);
- if (source && gpg_strsource && gpg_strerror_r)
- {
- /* Assume this is an libgpg-error. */
- char ebuf[50];
-
- gpg_strerror_r (rc, ebuf, sizeof ebuf );
- sprintf (errline, "ERR %d %.50s <%.30s>%s%.100s",
- rc,
- ebuf,
- gpg_strsource (rc),
- text? " - ":"", text?text:"");
- }
- else
-#endif /* __GNUC__ && __ELF__ */
- sprintf (errline, "ERR %d %.50s%s%.100s",
- rc, assuan_strerror (rc), text? " - ":"", text?text:"");
- }
rc = assuan_write_line (ctx, errline);
}
@@ -611,7 +559,7 @@ assuan_process_done (assuan_context_t ctx, int rc)
ctx->confidential = 0;
if (ctx->okay_line)
{
- xfree (ctx->okay_line);
+ _assuan_free (ctx->okay_line);
ctx->okay_line = NULL;
}
@@ -694,13 +642,13 @@ assuan_process_next (assuan_context_t ctx)
-static int
+static gpg_error_t
process_request (assuan_context_t ctx)
{
int rc;
if (ctx->in_inquire)
- return _assuan_error (ASSUAN_Nested_Commands);
+ return _assuan_error (GPG_ERR_ASS_NESTED_COMMANDS);
do
{
@@ -732,7 +680,7 @@ process_request (assuan_context_t ctx)
* Return value: 0 on success or an error code if the assuan operation
* failed. Note, that no error is returned for operational errors.
**/
-int
+gpg_error_t
assuan_process (assuan_context_t ctx)
{
int rc;
@@ -741,7 +689,7 @@ assuan_process (assuan_context_t ctx)
rc = process_request (ctx);
} while (!rc);
- if (err_is_eof (rc))
+ if (gpg_err_code (rc) == GPG_ERR_EOF)
rc = 0;
return rc;
@@ -845,26 +793,26 @@ assuan_get_data_fp (assuan_context_t ctx)
/* Set the text used for the next OK reponse. This string is
automatically reset to NULL after the next command. */
-assuan_error_t
+gpg_error_t
assuan_set_okay_line (assuan_context_t ctx, const char *line)
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!line)
{
- xfree (ctx->okay_line);
+ _assuan_free (ctx->okay_line);
ctx->okay_line = NULL;
}
else
{
/* FIXME: we need to use gcry_is_secure() to test whether
we should allocate the entire line in secure memory */
- char *buf = xtrymalloc (3+strlen(line)+1);
+ char *buf = _assuan_malloc (3 + strlen(line) + 1);
if (!buf)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
strcpy (buf, "OK ");
strcpy (buf+3, line);
- xfree (ctx->okay_line);
+ _assuan_free (ctx->okay_line);
ctx->okay_line = buf;
}
return 0;
@@ -872,17 +820,17 @@ assuan_set_okay_line (assuan_context_t ctx, const char *line)
-assuan_error_t
+gpg_error_t
assuan_write_status (assuan_context_t ctx,
const char *keyword, const char *text)
{
char buffer[256];
char *helpbuf;
size_t n;
- assuan_error_t ae;
+ gpg_error_t ae;
if ( !ctx || !keyword)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!text)
text = "";
@@ -898,7 +846,7 @@ assuan_write_status (assuan_context_t ctx,
}
ae = assuan_write_line (ctx, buffer);
}
- else if ( (helpbuf = xtrymalloc (n)) )
+ else if ( (helpbuf = _assuan_malloc (n)) )
{
strcpy (helpbuf, "S ");
strcat (helpbuf, keyword);
@@ -908,7 +856,7 @@ assuan_write_status (assuan_context_t ctx,
strcat (helpbuf, text);
}
ae = assuan_write_line (ctx, helpbuf);
- xfree (helpbuf);
+ _assuan_free (helpbuf);
}
else
ae = 0;
diff --git a/src/assuan-inquire.c b/src/assuan-inquire.c
index 58b9f02..8fdf14d 100644
--- a/src/assuan-inquire.c
+++ b/src/assuan-inquire.c
@@ -1,23 +1,26 @@
/* assuan-inquire.c - handle inquire stuff
- * Copyright (C) 2001, 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001-2003, 2005, 2007, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -57,7 +60,7 @@ init_membuf (struct membuf *mb, int initiallen, size_t maxlen)
mb->too_large = 0;
mb->maxlen = maxlen;
/* we need to allocate one byte more for get_membuf */
- mb->buf = xtrymalloc (initiallen+1);
+ mb->buf = _assuan_malloc (initiallen+1);
if (!mb->buf)
mb->out_of_core = 1;
}
@@ -80,7 +83,7 @@ put_membuf (struct membuf *mb, const void *buf, size_t len)
mb->size += len + 1024;
/* we need to allocate one byte more for get_membuf */
- p = xtryrealloc (mb->buf, mb->size+1);
+ p = _assuan_realloc (mb->buf, mb->size+1);
if (!p)
{
mb->out_of_core = 1;
@@ -99,7 +102,7 @@ get_membuf (struct membuf *mb, size_t *len)
if (mb->out_of_core || mb->too_large)
{
- xfree (mb->buf);
+ _assuan_free (mb->buf);
mb->buf = NULL;
return NULL;
}
@@ -115,7 +118,7 @@ get_membuf (struct membuf *mb, size_t *len)
static void
free_membuf (struct membuf *mb)
{
- xfree (mb->buf);
+ _assuan_free (mb->buf);
mb->buf = NULL;
}
@@ -133,11 +136,11 @@ free_membuf (struct membuf *mb)
*
* Return value: 0 on success or an ASSUAN error code
**/
-assuan_error_t
+gpg_error_t
assuan_inquire (assuan_context_t ctx, const char *keyword,
unsigned char **r_buffer, size_t *r_length, size_t maxlen)
{
- assuan_error_t rc;
+ gpg_error_t rc;
struct membuf mb;
char cmdbuf[LINELENGTH-10]; /* (10 = strlen ("INQUIRE ")+CR,LF) */
unsigned char *line, *p;
@@ -145,14 +148,14 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
int nodataexpected;
if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf)))
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
nodataexpected = !r_buffer && !r_length && !maxlen;
if (!nodataexpected && (!r_buffer || !r_length))
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!ctx->is_server)
- return _assuan_error (ASSUAN_Not_A_Server);
+ return _assuan_error (GPG_ERR_ASS_NOT_A_SERVER);
if (ctx->in_inquire)
- return _assuan_error (ASSUAN_Nested_Commands);
+ return _assuan_error (GPG_ERR_ASS_NESTED_COMMANDS);
ctx->in_inquire = 1;
if (nodataexpected)
@@ -183,12 +186,12 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
break; /* END command received*/
if (line[0] == 'C' && line[1] == 'A' && line[2] == 'N')
{
- rc = _assuan_error (ASSUAN_Canceled);
+ rc = _assuan_error (GPG_ERR_ASS_CANCELED);
goto leave;
}
if (line[0] != 'D' || line[1] != ' ' || nodataexpected)
{
- rc = _assuan_error (ASSUAN_Unexpected_Command);
+ rc = _assuan_error (GPG_ERR_ASS_UNEXPECTED_CMD);
goto leave;
}
if (linelen < 3)
@@ -215,7 +218,7 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
}
if (mb.too_large)
{
- rc = _assuan_error (ASSUAN_Too_Much_Data);
+ rc = _assuan_error (GPG_ERR_ASS_TOO_MUCH_DATA);
goto leave;
}
}
@@ -224,7 +227,7 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
{
*r_buffer = get_membuf (&mb, r_length);
if (!*r_buffer)
- rc = _assuan_error (ASSUAN_Out_Of_Core);
+ rc = _assuan_error (gpg_err_code_from_syserror ());
}
leave:
@@ -265,7 +268,7 @@ _assuan_inquire_ext_cb (assuan_context_t ctx)
if (line[0] == 'C' && line[1] == 'A' && line[2] == 'N')
{
- rc = _assuan_error (ASSUAN_Canceled);
+ rc = _assuan_error (GPG_ERR_ASS_CANCELED);
goto leave;
}
if (line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
@@ -277,7 +280,7 @@ _assuan_inquire_ext_cb (assuan_context_t ctx)
if (line[0] != 'D' || line[1] != ' ' || mb == NULL)
{
- rc = _assuan_error (ASSUAN_Unexpected_Command);
+ rc = _assuan_error (GPG_ERR_ASS_UNEXPECTED_CMD);
goto leave;
}
@@ -305,7 +308,7 @@ _assuan_inquire_ext_cb (assuan_context_t ctx)
}
if (mb->too_large)
{
- rc = _assuan_error (ASSUAN_Too_Much_Data);
+ rc = _assuan_error (GPG_ERR_ASS_TOO_MUCH_DATA);
goto leave;
}
@@ -315,12 +318,12 @@ _assuan_inquire_ext_cb (assuan_context_t ctx)
{
size_t buf_len = 0;
unsigned char *buf = NULL;
-
+
if (mb)
{
buf = get_membuf (mb, &buf_len);
if (!buf)
- rc = _assuan_error (ASSUAN_Out_Of_Core);
+ rc = _assuan_error (gpg_err_code_from_syserror ());
free_membuf (mb);
free (mb);
ctx->inquire_membuf = NULL;
@@ -345,26 +348,26 @@ _assuan_inquire_ext_cb (assuan_context_t ctx)
*
* Return value: 0 on success or an ASSUAN error code
**/
-assuan_error_t
+gpg_error_t
assuan_inquire_ext (assuan_context_t ctx, const char *keyword, size_t maxlen,
int (*cb) (void *cb_data, int rc, unsigned char *buf,
size_t len),
void *cb_data)
{
- assuan_error_t rc;
+ gpg_error_t rc;
struct membuf *mb = NULL;
char cmdbuf[LINELENGTH-10]; /* (10 = strlen ("INQUIRE ")+CR,LF) */
if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf)))
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!ctx->is_server)
- return _assuan_error (ASSUAN_Not_A_Server);
+ return _assuan_error (GPG_ERR_ASS_NOT_A_SERVER);
if (ctx->in_inquire)
- return _assuan_error (ASSUAN_Nested_Commands);
+ return _assuan_error (GPG_ERR_ASS_NESTED_COMMANDS);
mb = malloc (sizeof (struct membuf));
if (!mb)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
init_membuf (mb, maxlen ? maxlen : 1024, maxlen);
strcpy (stpcpy (cmdbuf, "INQUIRE "), keyword);
diff --git a/src/assuan-io-pth.c b/src/assuan-io-pth.c
index 6064ec4..e24d435 100644
--- a/src/assuan-io-pth.c
+++ b/src/assuan-io-pth.c
@@ -1,20 +1,20 @@
/* assuan-io-pth.c - Pth version of assua-io.c.
- * Copyright (C) 2002, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2002, 2004, 2006-2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
@@ -110,7 +110,8 @@ _assuan_simple_sendmsg (assuan_context_t ctx, struct msghdr *msg)
#endif
{
#if defined(HAVE_W32_SYSTEM)
- return _assuan_error (ASSUAN_Not_Implemented);
+ errno = ENOSYS;
+ return -1;
#else
/* Pth does not provide a sendmsg function. Thus we implement it here. */
int ret;
@@ -151,7 +152,8 @@ _assuan_simple_recvmsg (assuan_context_t ctx, struct msghdr *msg)
#endif
{
#if defined(HAVE_W32_SYSTEM)
- return _assuan_error (ASSUAN_Not_Implemented);
+ errno = ENOSYS;
+ return -1;
#else
/* Pth does not provide a recvmsg function. Thus we implement it here. */
int ret;
diff --git a/src/assuan-io.c b/src/assuan-io.c
index 647237d..80e26ea 100644
--- a/src/assuan-io.c
+++ b/src/assuan-io.c
@@ -1,20 +1,20 @@
/* assuan-io.c - Wraps the read and write functions.
- * Copyright (C) 2002, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2002, 2004, 2006-2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
@@ -187,7 +187,8 @@ _assuan_simple_sendmsg (assuan_context_t ctx, struct msghdr *msg)
#endif
{
#ifdef HAVE_W32_SYSTEM
- return _assuan_error (ASSUAN_Not_Implemented);
+ errno = ENOSYS;
+ return -1;
#else
int ret;
while ( (ret = sendmsg (ctx->outbound.fd, msg, 0)) == -1 && errno == EINTR)
@@ -206,7 +207,8 @@ _assuan_simple_recvmsg (assuan_context_t ctx, struct msghdr *msg)
#endif
{
#ifdef HAVE_W32_SYSTEM
- return _assuan_error (ASSUAN_Not_Implemented);
+ errno = ENOSYS;
+ return -1;
#else
int ret;
while ( (ret = recvmsg (ctx->inbound.fd, msg, 0)) == -1 && errno == EINTR)
diff --git a/src/assuan-listen.c b/src/assuan-listen.c
index 2ef9334..3fe6975 100644
--- a/src/assuan-listen.c
+++ b/src/assuan-listen.c
@@ -1,23 +1,26 @@
/* assuan-listen.c - Wait for a connection (server)
- * Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001, 2002, 2004, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -26,21 +29,21 @@
#include "assuan-defs.h"
-assuan_error_t
+gpg_error_t
assuan_set_hello_line (assuan_context_t ctx, const char *line)
{
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (!line)
{
- xfree (ctx->hello_line);
+ _assuan_free (ctx->hello_line);
ctx->hello_line = NULL;
}
else
{
- char *buf = xtrymalloc (3+strlen(line)+1);
+ char *buf = _assuan_malloc (3+strlen(line)+1);
if (!buf)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
if (strchr (line, '\n'))
strcpy (buf, line);
else
@@ -48,7 +51,7 @@ assuan_set_hello_line (assuan_context_t ctx, const char *line)
strcpy (buf, "OK ");
strcpy (buf+3, line);
}
- xfree (ctx->hello_line);
+ _assuan_free (ctx->hello_line);
ctx->hello_line = buf;
}
return 0;
@@ -66,14 +69,14 @@ assuan_set_hello_line (assuan_context_t ctx, const char *line)
* Return value: 0 on success or an error if the connection could for
* some reason not be established.
**/
-assuan_error_t
+gpg_error_t
assuan_accept (assuan_context_t ctx)
{
int rc;
const char *p, *pend;
if (!ctx)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (ctx->pipe_mode > 1)
return -1; /* second invocation for pipemode -> terminate */
@@ -117,24 +120,24 @@ assuan_accept (assuan_context_t ctx)
assuan_fd_t
assuan_get_input_fd (assuan_context_t ctx)
{
- return ctx? ctx->input_fd : ASSUAN_INVALID_FD;
+ return ctx ? ctx->input_fd : ASSUAN_INVALID_FD;
}
assuan_fd_t
assuan_get_output_fd (assuan_context_t ctx)
{
- return ctx? ctx->output_fd : ASSUAN_INVALID_FD;
+ return ctx ? ctx->output_fd : ASSUAN_INVALID_FD;
}
/* Close the fd descriptor set by the command INPUT FD=n. We handle
this fd inside assuan so that we can do some initial checks */
-assuan_error_t
+gpg_error_t
assuan_close_input_fd (assuan_context_t ctx)
{
if (!ctx || ctx->input_fd == ASSUAN_INVALID_FD)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
_assuan_close (ctx->input_fd);
ctx->input_fd = ASSUAN_INVALID_FD;
return 0;
@@ -142,11 +145,11 @@ assuan_close_input_fd (assuan_context_t ctx)
/* Close the fd descriptor set by the command OUTPUT FD=n. We handle
this fd inside assuan so that we can do some initial checks */
-assuan_error_t
+gpg_error_t
assuan_close_output_fd (assuan_context_t ctx)
{
if (!ctx || ctx->output_fd == ASSUAN_INVALID_FD)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
_assuan_close (ctx->output_fd);
ctx->output_fd = ASSUAN_INVALID_FD;
diff --git a/src/assuan-logging.c b/src/assuan-logging.c
index 2ebd667..576f84a 100644
--- a/src/assuan-logging.c
+++ b/src/assuan-logging.c
@@ -1,20 +1,20 @@
/* assuan-logging.c - Default logging function.
- * Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2002, 2003, 2004, 2007, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
@@ -242,50 +242,4 @@ _assuan_w32_strerror (int ec)
return strerr;
}
-static int (*my_strerror_r) (unsigned int err, char *buf, size_t buflen);
-static const char * (*my_strsource) (unsigned int err);
-
-static int
-load_libgpg_error (void)
-{
- /* This code is not race free but suitable for our purpose. */
- static volatile int initialized;
- void *handle;
-
- if (initialized)
- return (my_strerror_r && my_strsource)? 0:-1;
- handle = LoadLibrary ("libgpg-error-0.dll");
- if (handle)
- {
- void *foo, *bar;
- foo = GetProcAddress (handle, "gpg_strerror_r");
- bar = GetProcAddress (handle, "gpg_strsource");
- if (foo && bar)
- {
- my_strerror_r = foo;
- my_strsource = bar;
- }
- else
- CloseHandle (handle);
- }
- initialized = 1;
- return 0;
-}
-
-int
-_assuan_gpg_strerror_r (unsigned int err, char *buf, size_t buflen)
-{
- if (load_libgpg_error ())
- return -1;
- return my_strerror_r (err, buf, buflen);
-}
-
-
-const char *
-_assuan_gpg_strsource (unsigned int err)
-{
- if (load_libgpg_error ())
- return NULL;
- return my_strsource (err);
-}
#endif /*HAVE_W32_SYSTEM*/
diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c
index 05a3be9..7b6322c 100644
--- a/src/assuan-pipe-connect.c
+++ b/src/assuan-pipe-connect.c
@@ -1,21 +1,20 @@
/* assuan-pipe-connect.c - Establish a pipe connection (client)
- * Copyright (C) 2001, 2002, 2003, 2005, 2006,
- * 2007 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001-2003, 2005-2007, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
@@ -147,21 +146,21 @@ do_deinit (assuan_context_t ctx)
/* Helper for pipe_connect. */
-static assuan_error_t
+static gpg_error_t
initial_handshake (assuan_context_t *ctx)
{
int okay, off;
- assuan_error_t err;
+ gpg_error_t err;
err = _assuan_read_from_server (*ctx, &okay, &off);
if (err)
_assuan_log_printf ("can't connect server: %s\n",
- assuan_strerror (err));
+ gpg_strerror (err));
else if (okay != 1)
{
_assuan_log_printf ("can't connect server: `%s'\n",
(*ctx)->inbound.line);
- err = _assuan_error (ASSUAN_Connect_Failed);
+ err = _assuan_error (GPG_ERR_ASS_CONNECT_FAILED);
}
if (err)
@@ -177,14 +176,14 @@ initial_handshake (assuan_context_t *ctx)
#define pipe_connect pipe_connect_unix
/* Unix version of the pipe connection code. We use an extra macro to
make ChangeLog entries easier. */
-static assuan_error_t
+static gpg_error_t
pipe_connect_unix (assuan_context_t *ctx,
const char *name, const char *const argv[],
int *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
- assuan_error_t err;
+ gpg_error_t err;
int rp[2];
int wp[2];
char mypidstr[50];
@@ -192,20 +191,20 @@ pipe_connect_unix (assuan_context_t *ctx,
(void)flags;
if (!ctx || !name || !argv || !argv[0])
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
fix_signals ();
sprintf (mypidstr, "%lu", (unsigned long)getpid ());
if (pipe (rp) < 0)
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
if (pipe (wp) < 0)
{
close (rp[0]);
close (rp[1]);
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
err = _assuan_new_context (ctx);
@@ -233,7 +232,7 @@ pipe_connect_unix (assuan_context_t *ctx,
close (wp[0]);
close (wp[1]);
_assuan_release_context (*ctx);
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
if ((*ctx)->pid == 0)
@@ -334,7 +333,7 @@ pipe_connect_unix (assuan_context_t *ctx,
/* oops - use the pipe to tell the parent about it */
snprintf (errbuf, sizeof(errbuf)-1,
"ERR %d can't exec `%s': %.50s\n",
- _assuan_error (ASSUAN_Problem_Starting_Server),
+ _assuan_error (GPG_ERR_ASS_SERVER_START),
name, strerror (errno));
errbuf[sizeof(errbuf)-1] = 0;
writen (1, errbuf, strlen (errbuf));
@@ -364,21 +363,21 @@ pipe_connect_unix (assuan_context_t *ctx,
#ifndef HAVE_W32_SYSTEM
/* This function is similar to pipe_connect but uses a socketpair and
sets the I/O up to use sendmsg/recvmsg. */
-static assuan_error_t
+static gpg_error_t
socketpair_connect (assuan_context_t *ctx,
const char *name, const char *const argv[],
int *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue)
{
- assuan_error_t err;
+ gpg_error_t err;
int fds[2];
char mypidstr[50];
if (!ctx
|| (name && (!argv || !argv[0]))
|| (!name && argv))
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
fix_signals ();
@@ -387,7 +386,7 @@ socketpair_connect (assuan_context_t *ctx,
if ( socketpair (AF_LOCAL, SOCK_STREAM, 0, fds) )
{
_assuan_log_printf ("socketpair failed: %s\n", strerror (errno));
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
err = _assuan_new_context (ctx);
@@ -411,7 +410,7 @@ socketpair_connect (assuan_context_t *ctx,
close (fds[1]);
_assuan_release_context (*ctx);
*ctx = NULL;
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
if ((*ctx)->pid == 0)
@@ -516,7 +515,7 @@ socketpair_connect (assuan_context_t *ctx,
/* oops - use the pipe to tell the parent about it */
snprintf (errbuf, sizeof(errbuf)-1,
"ERR %d can't exec `%s': %.50s\n",
- _assuan_error (ASSUAN_Problem_Starting_Server),
+ _assuan_error (GPG_ERR_ASS_SERVER_START),
name, strerror (errno));
errbuf[sizeof(errbuf)-1] = 0;
writen (fds[1], errbuf, strlen (errbuf));
@@ -565,7 +564,7 @@ build_w32_commandline (const char * const *argv, char **cmdline)
}
n++;
- buf = p = xtrymalloc (n);
+ buf = p = _assuan_malloc (n);
if (!buf)
return -1;
@@ -645,14 +644,14 @@ create_inheritable_pipe (assuan_fd_t filedes[2], int for_write)
#ifdef HAVE_W32_SYSTEM
#define pipe_connect pipe_connect_w32
/* W32 version of the pipe connection code. */
-static assuan_error_t
+static gpg_error_t
pipe_connect_w32 (assuan_context_t *ctx,
const char *name, const char *const argv[],
int *fd_child_list,
void (*atfork) (void *opaque, int reserved),
void *atforkvalue, unsigned int flags)
{
- assuan_error_t err;
+ gpg_error_t err;
assuan_fd_t rp[2];
assuan_fd_t wp[2];
char mypidstr[50];
@@ -670,7 +669,7 @@ pipe_connect_w32 (assuan_context_t *ctx,
HANDLE nullfd = INVALID_HANDLE_VALUE;
if (!ctx || !name || !argv || !argv[0])
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
fix_signals ();
@@ -678,21 +677,21 @@ pipe_connect_w32 (assuan_context_t *ctx,
/* Build the command line. */
if (build_w32_commandline (argv, &cmdline))
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code from_syserror ());
/* Create thew two pipes. */
if (create_inheritable_pipe (rp, 0))
{
- xfree (cmdline);
- return _assuan_error (ASSUAN_General_Error);
+ _assuan_free (cmdline);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
if (create_inheritable_pipe (wp, 1))
{
CloseHandle (rp[0]);
CloseHandle (rp[1]);
- xfree (cmdline);
- return _assuan_error (ASSUAN_General_Error);
+ _assuan_free (cmdline);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
@@ -703,8 +702,8 @@ pipe_connect_w32 (assuan_context_t *ctx,
CloseHandle (rp[1]);
CloseHandle (wp[0]);
CloseHandle (wp[1]);
- xfree (cmdline);
- return _assuan_error (ASSUAN_General_Error);
+ _assuan_free (cmdline);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
(*ctx)->pipe_mode = 1;
@@ -753,7 +752,7 @@ pipe_connect_w32 (assuan_context_t *ctx,
CloseHandle (rp[1]);
CloseHandle (wp[0]);
CloseHandle (wp[1]);
- xfree (cmdline);
+ _assuan_free (cmdline);
_assuan_release_context (*ctx);
return -1;
}
@@ -790,11 +789,11 @@ pipe_connect_w32 (assuan_context_t *ctx,
CloseHandle (wp[1]);
if (nullfd != INVALID_HANDLE_VALUE)
CloseHandle (nullfd);
- xfree (cmdline);
+ _assuan_free (cmdline);
_assuan_release_context (*ctx);
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
- xfree (cmdline);
+ _assuan_free (cmdline);
cmdline = NULL;
if (nullfd != INVALID_HANDLE_VALUE)
{
@@ -823,7 +822,7 @@ pipe_connect_w32 (assuan_context_t *ctx,
returning it in CTX. The server filename is NAME, the argument
vector in ARGV. FD_CHILD_LIST is a -1 terminated list of file
descriptors not to close in the child. */
-assuan_error_t
+gpg_error_t
assuan_pipe_connect (assuan_context_t *ctx, const char *name,
const char *const argv[], int *fd_child_list)
{
@@ -831,18 +830,6 @@ assuan_pipe_connect (assuan_context_t *ctx, const char *name,
}
-
-assuan_error_t
-assuan_pipe_connect2 (assuan_context_t *ctx,
- const char *name, const char *const argv[],
- int *fd_child_list,
- void (*atfork) (void *opaque, int reserved),
- void *atforkvalue)
-{
- return pipe_connect (ctx, name, argv, fd_child_list, atfork, atforkvalue, 0);
-}
-
-
/* Connect to a server over a full-duplex socket (i.e. created by
socketpair), creating the assuan context and returning it in CTX.
The server filename is NAME, the argument vector in ARGV.
@@ -871,7 +858,7 @@ assuan_pipe_connect2 (assuan_context_t *ctx,
some special environment variables are set. To let the caller
detect whether the child or the parent continues, the child returns
a CTX of NULL. */
-assuan_error_t
+gpg_error_t
assuan_pipe_connect_ext (assuan_context_t *ctx,
const char *name, const char *const argv[],
int *fd_child_list,
@@ -881,7 +868,7 @@ assuan_pipe_connect_ext (assuan_context_t *ctx,
if ((flags & 1))
{
#ifdef HAVE_W32_SYSTEM
- return _assuan_error (ASSUAN_Not_Implemented);
+ return _assuan_error (GPG_ERR_NOT_IMPLEMENTED);
#else
return socketpair_connect (ctx, name, argv, fd_child_list,
atfork, atforkvalue);
diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c
index 7040414..afc0848 100644
--- a/src/assuan-pipe-server.c
+++ b/src/assuan-pipe-server.c
@@ -1,23 +1,26 @@
/* assuan-pipe-server.c - Assuan server working over a pipe
- * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001, 2002, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
@@ -64,9 +67,9 @@ _assuan_new_context (assuan_context_t *r_ctx)
int rc;
*r_ctx = NULL;
- ctx = xtrycalloc (1, sizeof *ctx);
+ ctx = _assuan_calloc (1, sizeof *ctx);
if (!ctx)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
ctx->input_fd = ASSUAN_INVALID_FD;
ctx->output_fd = ASSUAN_INVALID_FD;
@@ -82,7 +85,7 @@ _assuan_new_context (assuan_context_t *r_ctx)
rc = _assuan_register_std_commands (ctx);
if (rc)
- xfree (ctx);
+ _assuan_free (ctx);
else
*r_ctx = ctx;
return rc;
@@ -146,7 +149,7 @@ assuan_init_pipe_server (assuan_context_t *r_ctx, int filedes[2])
{
_assuan_release_context (*r_ctx);
*r_ctx = NULL;
- return ASSUAN_Problem_Starting_Server;
+ return _assuan_error (GPG_ERR_ASS_SERVER_START);
}
#endif
ctx->pipe_mode = 1;
@@ -168,10 +171,10 @@ _assuan_release_context (assuan_context_t ctx)
if (ctx)
{
_assuan_inquire_release (ctx);
- xfree (ctx->hello_line);
- xfree (ctx->okay_line);
- xfree (ctx->cmdtbl);
- xfree (ctx);
+ _assuan_free (ctx->hello_line);
+ _assuan_free (ctx->okay_line);
+ _assuan_free (ctx->cmdtbl);
+ _assuan_free (ctx);
}
}
diff --git a/src/assuan-socket-connect.c b/src/assuan-socket-connect.c
index 8eb6d82..8a8cb92 100644
--- a/src/assuan-socket-connect.c
+++ b/src/assuan-socket-connect.c
@@ -1,20 +1,20 @@
/* assuan-socket-connect.c - Assuan socket based client
- * Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2002, 2003, 2004, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
@@ -74,7 +74,7 @@ do_deinit (assuan_context_t ctx)
/* 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. */
-assuan_error_t
+gpg_error_t
assuan_socket_connect (assuan_context_t *r_ctx,
const char *name, pid_t server_pid)
{
@@ -86,14 +86,14 @@ assuan_socket_connect (assuan_context_t *r_ctx,
Assuan context in CTX. SERVER_PID is currently not used but may
become handy in the future. With flags set to 1 sendmsg and
recvmsg are used. */
-assuan_error_t
+gpg_error_t
assuan_socket_connect_ext (assuan_context_t *r_ctx,
const char *name, pid_t server_pid,
unsigned int flags)
{
static struct assuan_io io = { _assuan_simple_read, _assuan_simple_write,
NULL, NULL };
- assuan_error_t err;
+ gpg_error_t err;
assuan_context_t ctx;
assuan_fd_t fd;
struct sockaddr_un srvr_addr;
@@ -101,7 +101,7 @@ assuan_socket_connect_ext (assuan_context_t *r_ctx,
const char *s;
if (!r_ctx || !name)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
*r_ctx = NULL;
/* We require that the name starts with a slash, so that we
@@ -111,10 +111,10 @@ assuan_socket_connect_ext (assuan_context_t *r_ctx,
if (*s && s[1] == ':')
s += 2;
if (*s != DIRSEP_C && *s != '/')
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
if (strlen (name)+1 >= sizeof srvr_addr.sun_path)
- return _assuan_error (ASSUAN_Invalid_Value);
+ return _assuan_error (GPG_ERR_ASS_INV_VALUE);
err = _assuan_new_context (&ctx);
if (err)
@@ -127,7 +127,7 @@ assuan_socket_connect_ext (assuan_context_t *r_ctx,
{
_assuan_log_printf ("can't create socket: %s\n", strerror (errno));
_assuan_release_context (ctx);
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
memset (&srvr_addr, 0, sizeof srvr_addr);
@@ -142,7 +142,7 @@ assuan_socket_connect_ext (assuan_context_t *r_ctx,
name, strerror (errno));
_assuan_release_context (ctx);
_assuan_close (fd);
- return _assuan_error (ASSUAN_Connect_Failed);
+ return _assuan_error (GPG_ERR_ASS_CONNECT_FAILED);
}
ctx->inbound.fd = fd;
@@ -158,13 +158,13 @@ assuan_socket_connect_ext (assuan_context_t *r_ctx,
err = _assuan_read_from_server (ctx, &okay, &off);
if (err)
_assuan_log_printf ("can't connect to server: %s\n",
- assuan_strerror (err));
+ gpg_strerror (err));
else if (okay != 1)
{
/*LOG ("can't connect to server: `");*/
_assuan_log_sanitized_string (ctx->inbound.line);
fprintf (assuan_get_assuan_log_stream (), "'\n");
- err = _assuan_error (ASSUAN_Connect_Failed);
+ err = _assuan_error (GPG_ERR_ASS_CONNECT_FAILED);
}
}
diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c
index c536dba..f88110d 100644
--- a/src/assuan-socket-server.c
+++ b/src/assuan-socket-server.c
@@ -1,23 +1,26 @@
/* assuan-socket-server.c - Assuan socket based server
- * Copyright (C) 2002, 2007 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2002, 2007, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
@@ -94,14 +97,12 @@ accept_connection (assuan_context_t ctx)
(struct sockaddr*)&clnt_addr, &len ));
if (fd == ASSUAN_INVALID_FD)
{
- ctx->os_errno = errno;
- return _assuan_error (ASSUAN_Accept_Failed);
+ return _assuan_error (gpg_err_code_from_syserror ());
}
if (_assuan_sock_check_nonce (fd, &ctx->listen_nonce))
{
_assuan_close (fd);
- ctx->os_errno = EACCES;
- return _assuan_error (ASSUAN_Accept_Failed);
+ return _assuan_error (GPG_ERR_ASS_ACCEPT_FAILED);
}
ctx->connected_fd = fd;
@@ -156,9 +157,9 @@ assuan_init_socket_server_ext (assuan_context_t *r_ctx, assuan_fd_t fd,
int rc;
*r_ctx = NULL;
- ctx = xtrycalloc (1, sizeof *ctx);
+ ctx = _assuan_calloc (1, sizeof *ctx);
if (!ctx)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return _assuan_error (gpg_err_code_from_syserror ());
ctx->is_server = 1;
if ((flags & 2))
ctx->pipe_mode = 1; /* We want a second accept to indicate EOF. */
diff --git a/src/assuan-socket.c b/src/assuan-socket.c
index 044b1f1..e638503 100644
--- a/src/assuan-socket.c
+++ b/src/assuan-socket.c
@@ -1,23 +1,26 @@
/* assuan-socket.c
- * Copyright (C) 2004, 2005 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_W32_SYSTEM
diff --git a/src/assuan-uds.c b/src/assuan-uds.c
index 02f77a5..9497992 100644
--- a/src/assuan-uds.c
+++ b/src/assuan-uds.c
@@ -1,20 +1,20 @@
/* assuan-uds.c - Assuan unix domain socket utilities
- * Copyright (C) 2006 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2006, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
@@ -75,9 +75,9 @@ uds_reader (assuan_context_t ctx, void *buf, size_t buflen)
if (!ctx->uds.bufferallocated)
{
- ctx->uds.buffer = xtrymalloc (2048);
+ ctx->uds.buffer = _assuan_malloc (2048);
if (!ctx->uds.buffer)
- return _assuan_error (ASSUAN_Out_Of_Core);
+ return gpg_error_from_syserror ();
ctx->uds.bufferallocated = 2048;
}
@@ -192,7 +192,7 @@ uds_writer (assuan_context_t ctx, const void *buf, size_t buflen)
}
-static assuan_error_t
+static gpg_error_t
uds_sendfd (assuan_context_t ctx, assuan_fd_t fd)
{
#ifdef USE_DESCRIPTOR_PASSING
@@ -231,18 +231,20 @@ uds_sendfd (assuan_context_t ctx, assuan_fd_t fd)
len = _assuan_simple_sendmsg (ctx, &msg);
if (len < 0)
{
+ int saved_errno = errno;
_assuan_log_printf ("uds_sendfd: %s\n", strerror (errno));
- return _assuan_error (ASSUAN_Write_Error);
+ errno = saved_errno;
+ return _assuan_error (gpg_err_code_from_syserror ());
}
else
return 0;
#else
- return _assuan_error (ASSUAN_Not_Implemented);
+ return _assuan_error (GPG_ERR_NOT_IMPLEMENTED);
#endif
}
-static assuan_error_t
+static gpg_error_t
uds_receivefd (assuan_context_t ctx, assuan_fd_t *fd)
{
#ifdef USE_DESCRIPTOR_PASSING
@@ -251,7 +253,7 @@ uds_receivefd (assuan_context_t ctx, assuan_fd_t *fd)
if (!ctx->uds.pendingfdscount)
{
_assuan_log_printf ("no pending file descriptors!\n");
- return _assuan_error (ASSUAN_General_Error);
+ return _assuan_error (GPG_ERR_ASS_GENERAL);
}
assert (ctx->uds.pendingfdscount <= DIM(ctx->uds.pendingfds));
@@ -262,7 +264,7 @@ uds_receivefd (assuan_context_t ctx, assuan_fd_t *fd)
return 0;
#else
- return _assuan_error (ASSUAN_Not_Implemented);
+ return _assuan_error (GPG_ERR_NOT_IMPLEMENTED);
#endif
}
@@ -289,14 +291,14 @@ _assuan_uds_deinit (assuan_context_t ctx)
{
assert (ctx->uds.bufferallocated);
ctx->uds.bufferallocated = 0;
- xfree (ctx->uds.buffer);
+ _assuan_free (ctx->uds.buffer);
}
_assuan_uds_close_fds (ctx);
}
-/* Helper function to initialize a context for domain I/O. */
+/* Helper function to initialize a context for domain I/O. */
void
_assuan_init_uds_io (assuan_context_t ctx)
{
diff --git a/src/assuan-util.c b/src/assuan-util.c
index cefefcb..589e98f 100644
--- a/src/assuan-util.c
+++ b/src/assuan-util.c
@@ -1,23 +1,26 @@
/* assuan-util.c - Utility functions for Assuan
- * Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ Copyright (C) 2001-2005, 2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -33,11 +36,10 @@ static void (*free_func)(void*) = free;
struct assuan_io_hooks _assuan_io_hooks;
-
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*) )
+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*))
{
alloc_func = new_alloc_func;
realloc_func = new_realloc_func;
diff --git a/src/assuan.h b/src/assuan.h
index f2d2feb..306dd75 100644
--- a/src/assuan.h
+++ b/src/assuan.h
@@ -1,21 +1,20 @@
/* assuan.h - Definitions for the Assuan IPC library
- * Copyright (C) 2001, 2002, 2003, 2005, 2007,
- * 2008 Free Software Foundation, Inc.
- *
- * This file is part of Assuan.
- *
- * 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.
- *
- * 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 Lesser General Public
- * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ * Copyright (C) 2001-2003, 2005, 2007-2009 Free Software Foundation, Inc.
+
+ This file is part of Assuan.
+
+ 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.
+
+ 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 Lesser General Public
+ License along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ASSUAN_H
@@ -30,6 +29,9 @@
#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:
@@ -38,11 +40,6 @@
This prefixes all external symbols with "_foo_".
- #define _ASSUAN_ONLY_GPG_ERRORS
-
- If this is defined all old-style Assuan error codes are made
- inactive as well as other deprecated stuff.
-
#define _ASSUAN_NO_SOCKET_WRAPPER
Do not include the definitions for the socket wrapper feature.
@@ -101,8 +98,6 @@
#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_connected_socket_server \
- _ASSUAN_PREFIX(assuan_init_connected_socket_server)
#define assuan_init_socket_server_ext \
_ASSUAN_PREFIX(assuan_init_socket_server_ext)
#define assuan_pipe_connect _ASSUAN_PREFIX(assuan_pipe_connect)
@@ -130,7 +125,6 @@
#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_strerror _ASSUAN_PREFIX(assuan_strerror)
#define assuan_set_assuan_err_source \
_ASSUAN_PREFIX(assuan_set_assuan_err_source)
#define assuan_set_assuan_log_stream \
@@ -141,7 +135,6 @@
_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_pipe_connect2 _ASSUAN_PREFIX(assuan_pipe_connect2)
#define assuan_set_assuan_log_prefix \
_ASSUAN_PREFIX(assuan_set_assuan_log_prefix)
#define assuan_sock_close _ASSUAN_PREFIX(assuan_sock_close)
@@ -224,157 +217,24 @@ extern "C"
#endif
-/* Assuan error codes. These are only used by old applications or
- those applications which won't make use of libgpg-error. */
-#ifndef _ASSUAN_ONLY_GPG_ERRORS
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_No_Error 0
-#endif
-#define ASSUAN_General_Error 1
-#define ASSUAN_Out_Of_Core 2
-#define ASSUAN_Invalid_Value 3
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Timeout 4
-#endif
-#define ASSUAN_Read_Error 5
-#define ASSUAN_Write_Error 6
-#define ASSUAN_Problem_Starting_Server 7
-#define ASSUAN_Not_A_Server 8
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Not_A_Client 9
-#endif
-#define ASSUAN_Nested_Commands 10
-#define ASSUAN_Invalid_Response 11
-#define ASSUAN_No_Data_Callback 12
-#define ASSUAN_No_Inquire_Callback 13
-#define ASSUAN_Connect_Failed 14
-#define ASSUAN_Accept_Failed 15
-
- /* Error codes above 99 are meant as status codes */
-#define ASSUAN_Not_Implemented 100
-#define ASSUAN_Server_Fault 101
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Invalid_Command 102
-#endif
-#define ASSUAN_Unknown_Command 103
-#define ASSUAN_Syntax_Error 104
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Parameter_Error 105
-#endif
-#define ASSUAN_Parameter_Conflict 106
-#define ASSUAN_Line_Too_Long 107
-#define ASSUAN_Line_Not_Terminated 108
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_No_Input 109
-#define ASSUAN_No_Output 110
-#endif
-#define ASSUAN_Canceled 111
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Unsupported_Algorithm 112
-#define ASSUAN_Server_Resource_Problem 113
-#define ASSUAN_Server_IO_Error 114
-#define ASSUAN_Server_Bug 115
-#define ASSUAN_No_Data_Available 116
-#define ASSUAN_Invalid_Data 117
-#endif
-#define ASSUAN_Unexpected_Command 118
-#define ASSUAN_Too_Much_Data 119
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Inquire_Unknown 120
-#define ASSUAN_Inquire_Error 121
-#define ASSUAN_Invalid_Option 122
-#define ASSUAN_Invalid_Index 123
-#define ASSUAN_Unexpected_Status 124
-#define ASSUAN_Unexpected_Data 125
-#define ASSUAN_Invalid_Status 126
-#define ASSUAN_Locale_Problem 127
-#endif
-#define ASSUAN_Not_Confirmed 128
-
- /* Warning: Don't use the Error codes, below they are deprecated. */
-#ifndef _ASSUAN_IN_LIBASSUAN
-#define ASSUAN_Bad_Certificate 201
-#define ASSUAN_Bad_Certificate_Chain 202
-#define ASSUAN_Missing_Certificate 203
-#define ASSUAN_Bad_Signature 204
-#define ASSUAN_No_Agent 205
-#define ASSUAN_Agent_Error 206
-#define ASSUAN_No_Public_Key 207
-#define ASSUAN_No_Secret_Key 208
-#define ASSUAN_Invalid_Name 209
-
-#define ASSUAN_Cert_Revoked 301
-#define ASSUAN_No_CRL_For_Cert 302
-#define ASSUAN_CRL_Too_Old 303
-#define ASSUAN_Not_Trusted 304
-
-#define ASSUAN_Card_Error 401
-#define ASSUAN_Invalid_Card 402
-#define ASSUAN_No_PKCS15_App 403
-#define ASSUAN_Card_Not_Present 404
-#define ASSUAN_Invalid_Id 405
-
- /* Error codes in the range 1000 to 9999 may be used by applications
- at their own discretion. */
-#define ASSUAN_USER_ERROR_FIRST 1000
-#define ASSUAN_USER_ERROR_LAST 9999
-#endif
-
-typedef int assuan_error_t;
+/* Definitions of flags for assuan_set_flag(). */
+typedef unsigned int assuan_flag_t;
-typedef assuan_error_t AssuanError _ASSUAN_DEPRECATED;
+/* 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
-/* This is a list of pre-registered ASSUAN commands */
-/* Note, these command IDs are now deprectated and solely exists for
- compatibility reasons. */
-typedef enum
-{
- ASSUAN_CMD_NOP = 0,
- ASSUAN_CMD_CANCEL, /* cancel the current request */
- ASSUAN_CMD_BYE,
- ASSUAN_CMD_AUTH,
- ASSUAN_CMD_RESET,
- ASSUAN_CMD_OPTION,
- ASSUAN_CMD_DATA,
- ASSUAN_CMD_END,
- ASSUAN_CMD_INPUT,
- ASSUAN_CMD_OUTPUT,
-
- ASSUAN_CMD_USER = 256 /* Other commands should be used with this offset*/
-} AssuanCommand;
-
-
-#else /*!_ASSUAN_ONLY_GPG_ERRORS*/
-
-/* Choose a type compatible with gpg_error_t. */
-typedef unsigned int assuan_error_t;
-
-#endif /*!_ASSUAN_ONLY_GPG_ERRORS*/
-
-
-/* Definitions of flags for assuan_set_flag(). */
-typedef enum
- {
- /* 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. */
- ASSUAN_NO_WAITPID = 1,
- /* This flag indicates whether Assuan logging is in confidential
- mode. Use assuan_{begin,end}_condidential to change the
- mode. */
- ASSUAN_CONFIDENTIAL = 2
- }
-assuan_flag_t;
#define ASSUAN_LINELENGTH 1002 /* 1000 + [CR,]LF */
struct assuan_context_s;
typedef struct assuan_context_s *assuan_context_t;
-#ifndef _ASSUAN_ONLY_GPG_ERRORS
-typedef struct assuan_context_s *ASSUAN_CONTEXT _ASSUAN_DEPRECATED;
-#endif /*_ASSUAN_ONLY_GPG_ERRORS*/
/* Because we use system handles and not libc low level file
descriptors on W32, we need to declare them as HANDLE (which
@@ -457,7 +317,7 @@ int assuan_register_option_handler (assuan_context_t ctx,
int (*fnc)(assuan_context_t,
const char*, const char*));
-int assuan_process (assuan_context_t ctx);
+gpg_error_t assuan_process (assuan_context_t ctx);
int assuan_process_next (assuan_context_t ctx);
int assuan_process_done (assuan_context_t ctx, int rc);
int assuan_get_active_fds (assuan_context_t ctx, int what,
@@ -465,8 +325,8 @@ int assuan_get_active_fds (assuan_context_t ctx, int what,
FILE *assuan_get_data_fp (assuan_context_t ctx);
-assuan_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line);
-assuan_error_t assuan_write_status (assuan_context_t ctx,
+gpg_error_t assuan_set_okay_line (assuan_context_t ctx, const char *line);
+gpg_error_t assuan_write_status (assuan_context_t ctx,
const char *keyword, const char *text);
/* Negotiate a file descriptor. If LINE contains "FD=N", returns N
@@ -474,17 +334,17 @@ assuan_error_t assuan_write_status (assuan_context_t ctx,
file descriptor via CTX and stores it in *RDF (the CTX must be
capable of passing file descriptors). Under W32 the returned FD is
a libc-type one. */
-assuan_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line,
+gpg_error_t assuan_command_parse_fd (assuan_context_t ctx, char *line,
assuan_fd_t *rfd);
/*-- assuan-listen.c --*/
-assuan_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line);
-assuan_error_t assuan_accept (assuan_context_t ctx);
+gpg_error_t assuan_set_hello_line (assuan_context_t ctx, const char *line);
+gpg_error_t assuan_accept (assuan_context_t ctx);
assuan_fd_t assuan_get_input_fd (assuan_context_t ctx);
assuan_fd_t assuan_get_output_fd (assuan_context_t ctx);
-assuan_error_t assuan_close_input_fd (assuan_context_t ctx);
-assuan_error_t assuan_close_output_fd (assuan_context_t ctx);
+gpg_error_t assuan_close_input_fd (assuan_context_t ctx);
+gpg_error_t assuan_close_output_fd (assuan_context_t ctx);
/*-- assuan-pipe-server.c --*/
@@ -493,24 +353,16 @@ void assuan_deinit_server (assuan_context_t ctx);
/*-- assuan-socket-server.c --*/
int assuan_init_socket_server (assuan_context_t *r_ctx, assuan_fd_t listen_fd);
-int assuan_init_connected_socket_server (assuan_context_t *r_ctx,
- assuan_fd_t fd) _ASSUAN_DEPRECATED;
int assuan_init_socket_server_ext (assuan_context_t *r_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 --*/
-assuan_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[],
int *fd_child_list);
-assuan_error_t assuan_pipe_connect2 (assuan_context_t *ctx,
- const char *name,
- const char *const argv[],
- int *fd_child_list,
- void (*atfork) (void*, int),
- void *atforkvalue) _ASSUAN_DEPRECATED;
-assuan_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[],
int *fd_child_list,
@@ -519,10 +371,10 @@ assuan_error_t assuan_pipe_connect_ext (assuan_context_t *ctx,
unsigned int flags);
/*-- assuan-socket-connect.c --*/
-assuan_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);
-assuan_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);
@@ -531,45 +383,45 @@ assuan_error_t assuan_socket_connect_ext (assuan_context_t *ctx,
void assuan_disconnect (assuan_context_t ctx);
pid_t assuan_get_pid (assuan_context_t ctx);
#ifndef _WIN32
-assuan_error_t assuan_get_peercred (assuan_context_t ctx,
+gpg_error_t assuan_get_peercred (assuan_context_t ctx,
pid_t *pid, uid_t *uid, gid_t *gid);
#endif
/*-- assuan-client.c --*/
-assuan_error_t
+gpg_error_t
assuan_transact (assuan_context_t ctx,
const char *command,
- assuan_error_t (*data_cb)(void *, const void *, size_t),
+ gpg_error_t (*data_cb)(void *, const void *, size_t),
void *data_cb_arg,
- assuan_error_t (*inquire_cb)(void*, const char *),
+ gpg_error_t (*inquire_cb)(void*, const char *),
void *inquire_cb_arg,
- assuan_error_t (*status_cb)(void*, const char *),
+ gpg_error_t (*status_cb)(void*, const char *),
void *status_cb_arg);
/*-- assuan-inquire.c --*/
-assuan_error_t assuan_inquire (assuan_context_t ctx, const char *keyword,
+gpg_error_t assuan_inquire (assuan_context_t ctx, const char *keyword,
unsigned char **r_buffer, size_t *r_length,
size_t maxlen);
-assuan_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword,
+gpg_error_t assuan_inquire_ext (assuan_context_t ctx, const char *keyword,
size_t maxlen,
int (*cb) (void *cb_data, int rc,
unsigned char *buf,
size_t buf_len),
void *cb_data);
/*-- assuan-buffer.c --*/
-assuan_error_t assuan_read_line (assuan_context_t ctx,
+gpg_error_t assuan_read_line (assuan_context_t ctx,
char **line, size_t *linelen);
int assuan_pending_line (assuan_context_t ctx);
-assuan_error_t assuan_write_line (assuan_context_t ctx, const char *line );
-assuan_error_t assuan_send_data (assuan_context_t ctx,
+gpg_error_t assuan_write_line (assuan_context_t ctx, const char *line );
+gpg_error_t assuan_send_data (assuan_context_t ctx,
const void *buffer, size_t length);
/* The file descriptor must be pending before assuan_receivefd is
called. This means that assuan_sendfd should be called *before* the
trigger is sent (normally via assuan_write_line ("INPUT FD")). */
-assuan_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd);
-assuan_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd);
+gpg_error_t assuan_sendfd (assuan_context_t ctx, assuan_fd_t fd);
+gpg_error_t assuan_receivefd (assuan_context_t ctx, assuan_fd_t *fd);
/*-- assuan-util.c --*/
@@ -602,18 +454,11 @@ int assuan_get_flag (assuan_context_t ctx, assuan_flag_t flag);
/*-- assuan-errors.c --*/
-#ifndef _ASSUAN_ONLY_GPG_ERRORS
-/* Return a string describing the assuan error. The use of this
- function is deprecated; it is better to call
- assuan_set_assuan_err_source once and then make use libgpg-error. */
-const char *assuan_strerror (assuan_error_t err);
-#endif /*_ASSUAN_ONLY_GPG_ERRORS*/
-
/* 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 (int errsource);
+void assuan_set_assuan_err_source (gpg_err_source_t errsource);
/*-- assuan-logging.c --*/
diff --git a/src/libassuan-config.in b/src/libassuan-config.in
index 60f4aa2..50c9805 100644
--- a/src/libassuan-config.in
+++ b/src/libassuan-config.in
@@ -9,10 +9,14 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# Configure libgpg-error.
+gpg_error_cflags="@GPG_ERROR_CFLAGS@"
+gpg_error_libs="@GPG_ERROR_LIBS@"
+
PGM=libassuan-config
lib="@LIBASSUAN_CONFIG_LIB@"
-extralibs="@LIBASSUAN_CONFIG_EXTRA_LIBS@"
-cflags="@LIBASSUAN_CONFIG_CFLAGS@"
+extralibs="@LIBASSUAN_CONFIG_EXTRA_LIBS@ $gpg_error_libs"
+cflags="@LIBASSUAN_CONFIG_CFLAGS@ $gpg_error_cflags"
api_version="@LIBASSUAN_CONFIG_API_VERSION@"
all_thread_modules="@LIBASSUAN_CONFIG_THREAD_MODULES@"
thread_module=
@@ -26,6 +30,7 @@ echo_cflags=no
echo_prefix=no
echo_exec_prefix=no
+
if test x"$all_thread_modules" = x; then
all_thread_modules="none pthread"
else
diff --git a/src/libassuan.def b/src/libassuan.def
new file mode 100644
index 0000000..839d95f
--- /dev/null
+++ b/src/libassuan.def
@@ -0,0 +1,88 @@
+; assuan.def - List of symbols to export.
+; Copyright (C) 2005, 2009 g10 Code GmbH
+;
+; This file is part of ASSUAN.
+;
+; 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.
+;
+; 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 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
+
+
+EXPORTS
+ assuan_accept @1
+ assuan_begin_confidential @2
+ assuan_close_input_fd @3
+ assuan_close_output_fd @4
+ assuan_command_parse_fd @5
+ assuan_deinit_server @6
+ assuan_disconnect @7
+ assuan_end_confidential @8
+ assuan_get_active_fds @9
+ assuan_get_assuan_log_prefix @10
+ assuan_get_assuan_log_stream @11
+ assuan_get_data_fp @12
+ assuan_get_flag @13
+ assuan_get_input_fd @14
+ assuan_get_output_fd @15
+ assuan_get_peercred @16
+ assuan_get_pid @17
+ assuan_get_pointer @18
+ assuan_init_pipe_server @19
+ assuan_init_socket_server @21
+ assuan_init_socket_server_ext @22
+ assuan_inquire @23
+ assuan_inquire_ext @24
+ assuan_pending_line @25
+ assuan_pipe_connect @27
+ assuan_pipe_connect_ext @28
+ assuan_process @29
+ assuan_process_done @30
+ assuan_process_next @31
+ assuan_read_line @32
+ assuan_receivefd @33
+ assuan_register_bye_notify @34
+ assuan_register_cancel_notify @35
+ assuan_register_command @36
+ assuan_register_input_notify @37
+ assuan_register_option_handler @38
+ assuan_register_output_notify @39
+ assuan_register_post_cmd_notify @40
+ assuan_register_reset_notify @41
+ assuan_send_data @42
+ assuan_sendfd @43
+ assuan_set_assuan_err_source @44
+ assuan_set_assuan_log_prefix @45
+ assuan_set_assuan_log_stream @46
+ assuan_set_error @47
+ assuan_set_flag @48
+ assuan_set_hello_line @49
+ assuan_set_io_hooks @50
+ assuan_set_io_monitor @51
+ assuan_set_log_stream @52
+ assuan_set_malloc_hooks @53
+ assuan_set_okay_line @54
+ assuan_set_pointer @55
+ assuan_sock_bind @56
+ assuan_sock_check_nonce @57
+ assuan_sock_close @58
+ assuan_sock_connect @59
+ assuan_sock_get_nonce @60
+ assuan_sock_new @61
+ assuan_socket_connect @62
+ assuan_socket_connect_ext @63
+ assuan_transact @64
+ assuan_write_line @65
+ assuan_write_status @66
+
+; END
+
diff --git a/src/libassuan.vers b/src/libassuan.vers
new file mode 100644
index 0000000..b139143
--- /dev/null
+++ b/src/libassuan.vers
@@ -0,0 +1,93 @@
+# libassuan.vers - List of symbols to export.
+# Copyright (C) 2009 g10 Code GmbH
+#
+# This file is part of LIBASSUAN.
+#
+# LIBASSUAN 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.
+#
+# LIBASSUAN 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 Lesser General Public
+# License along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+#-----------------------------------------------------------
+# Please remember to add new functions also to libassuan.def
+#-----------------------------------------------------------
+
+LIBASSUAN_1.0 {
+ global:
+ assuan_accept;
+ assuan_begin_confidential;
+ assuan_close_input_fd;
+ assuan_close_output_fd;
+ assuan_command_parse_fd;
+ assuan_deinit_server;
+ assuan_disconnect;
+ assuan_end_confidential;
+ assuan_get_active_fds;
+ assuan_get_assuan_log_prefix;
+ assuan_get_assuan_log_stream;
+ assuan_get_data_fp;
+ assuan_get_flag;
+ assuan_get_input_fd;
+ assuan_get_output_fd;
+ assuan_get_peercred;
+ assuan_get_pid;
+ assuan_get_pointer;
+ assuan_init_pipe_server;
+ assuan_init_socket_server;
+ assuan_init_socket_server_ext;
+ assuan_inquire;
+ assuan_inquire_ext;
+ assuan_pending_line;
+ assuan_pipe_connect;
+ assuan_pipe_connect_ext;
+ assuan_process;
+ assuan_process_done;
+ assuan_process_next;
+ assuan_read_line;
+ assuan_receivefd;
+ assuan_register_bye_notify;
+ assuan_register_cancel_notify;
+ assuan_register_command;
+ assuan_register_input_notify;
+ assuan_register_option_handler;
+ assuan_register_output_notify;
+ assuan_register_post_cmd_notify;
+ assuan_register_reset_notify;
+ assuan_send_data;
+ assuan_sendfd;
+ assuan_set_assuan_err_source;
+ assuan_set_assuan_log_prefix;
+ assuan_set_assuan_log_stream;
+ assuan_set_error;
+ assuan_set_flag;
+ assuan_set_hello_line;
+ assuan_set_io_hooks;
+ assuan_set_io_monitor;
+ assuan_set_log_stream;
+ assuan_set_malloc_hooks;
+ assuan_set_okay_line;
+ assuan_set_pointer;
+ assuan_sock_bind;
+ assuan_sock_check_nonce;
+ assuan_sock_close;
+ assuan_sock_connect;
+ assuan_sock_get_nonce;
+ assuan_sock_new;
+ assuan_socket_connect;
+ assuan_socket_connect_ext;
+ assuan_transact;
+ assuan_write_line;
+ assuan_write_status;
+
+ local:
+ *;
+
+};
diff --git a/src/mkerrors b/src/mkerrors
deleted file mode 100755
index 79ac23b..0000000
--- a/src/mkerrors
+++ /dev/null
@@ -1,257 +0,0 @@
-#!/bin/sh
-# mkerrors - Extract error strings from assuan.h
-# and create C source for assuan_strerror
-# Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
-#
-# This file is part of Assuan.
-#
-# 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.
-#
-# 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 Lesser General Public
-# License along with this program; if not, see <http://www.gnu.org/licenses/>.
-cat <<EOF
-/* Generated automatically by mkerrors */
-/* Do not edit! See mkerrors for copyright notice. */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <assert.h>
-#include <errno.h>
-
-#undef _ASSUAN_IN_LIBASSUAN /* undef to get all error codes. */
-#include "assuan.h"
-#include "assuan-defs.h"
-
-/* If true the modern gpg-error style error codes are used in the
- API. */
-static unsigned int err_source;
-
-/* 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 (int errsource)
-{
- errsource &= 0xff;
- err_source = errsource? errsource : 31 /*GPG_ERR_SOURCE_ANY*/;
-}
-
-
-/* Helper to map old style Assuan error codes to gpg-error codes.
- This is used internally to keep an compatible ABI. */
-assuan_error_t
-_assuan_error (int oldcode)
-{
- unsigned int n;
-
- if (!err_source)
- {
- if (oldcode == -1)
- return -1;
- else
- return (oldcode & 0x00ffffff); /* Make sure that the gpg-error
- source part is cleared. */
- }
-
- switch (oldcode)
- {
- case ASSUAN_General_Error: n = 257; break;
- case ASSUAN_Accept_Failed: n = 258; break;
- case ASSUAN_Connect_Failed: n = 259; break;
- case ASSUAN_Invalid_Response: n = 260; break;
- case ASSUAN_Invalid_Value: n = 261; break;
- case ASSUAN_Line_Not_Terminated: n = 262; break;
- case ASSUAN_Line_Too_Long: n = 263; break;
- case ASSUAN_Nested_Commands: n = 264; break;
- case ASSUAN_No_Data_Callback: n = 265; break;
- case ASSUAN_No_Inquire_Callback: n = 266; break;
- case ASSUAN_Not_A_Server: n = 267; break;
- case ASSUAN_Not_Implemented: n = 69; break;
- case ASSUAN_Parameter_Conflict: n = 280; break;
- case ASSUAN_Problem_Starting_Server: n = 269; break;
- case ASSUAN_Server_Fault: n = 80; break;
- case ASSUAN_Syntax_Error: n = 276; break;
- case ASSUAN_Too_Much_Data: n = 273; break;
- case ASSUAN_Unexpected_Command: n = 274; break;
- case ASSUAN_Unknown_Command: n = 275; break;
- case ASSUAN_Canceled: n = 277; break;
- case ASSUAN_No_Secret_Key: n = 17; break;
- case ASSUAN_Not_Confirmed: n = 114; break;
-
- case ASSUAN_Read_Error:
- switch (errno)
- {
- case 0: n = 16381; /*GPG_ERR_MISSING_ERRNO*/ break;
- case EAGAIN:
- n = (6 | (1 << 15));
- break;
- default: n = 270; /*GPG_ERR_ASS_READ_ERROR*/ break;
- }
- break;
-
- case ASSUAN_Write_Error:
- switch (errno)
- {
- case 0: n = 16381; /*GPG_ERR_MISSING_ERRNO*/ break;
- case EAGAIN:
- n = (6 | (1 << 15));
- break;
- default: n = 271; /*GPG_ERR_ASS_WRITE_ERROR*/ break;
- }
- break;
-
- case ASSUAN_Out_Of_Core:
- switch (errno)
- {
- case 0: /* Should not happen but a user might have provided
- an incomplete implemented malloc function. Give
- him a chance to correct this fault but make sure
- an error is indeed returned. */
- n = 16381; /*GPG_ERR_MISSING_ERRNO*/
- break;
- case ENOMEM:
- n = (86 | (1 << 15));
- break;
- default:
- n = 16382; /*GPG_ERR_UNKNOWN_ERRNO*/
- break;
- }
- break;
-
- case -1: n = 16383 /*GPG_ERR_EOF*/; break;
-
- default:
- n = 257;
- break;
- }
-
- return ((err_source << 24) | (n & 0x00ffffff));
-
-}
-
-
-/* A small helper function to treat EAGAIN transparently to the
- caller. */
-int
-_assuan_error_is_eagain (assuan_error_t err)
-{
- if ((!err_source && err == ASSUAN_Read_Error && errno == EAGAIN)
- || (err_source && (err & ((1 << 24) - 1)) == (6 | (1 << 15))))
- {
- /* Avoid spinning by sleeping for one tenth of a second. */
- _assuan_usleep (100000);
- return 1;
- }
- else
- return 0;
-}
-
-
-/**
- * assuan_strerror:
- * @err: Error code
- *
- * This function returns a textual representaion of the given
- * errorcode. If this is an unknown value, a string with the value
- * is returned (Beware: it is hold in a static buffer).
- *
- * Return value: String with the error description.
- **/
-const char *
-assuan_strerror (assuan_error_t err)
-{
- const char *s;
- static char buf[50];
-
- switch (err)
- {
-EOF
-
-awk '
-/ASSUAN_No_Error/ { okay=1 }
-!okay {next}
-/^#define[ ]+ASSUAN_[A-Za-z_]*/ { print_code($2) }
-/ASSUAN_USER_ERROR_LAST/ { exit 0 }
-
-
-function print_code( s )
-{
-printf " case %s: s=\"", s ;
-gsub(/_/, " ", s );
-printf "%s\"; break;\n", tolower(substr(s,8));
-}
-'
-
-cat <<EOF
- case -1: s = "EOF (-1)"; break;
- default:
- {
- unsigned int source, code, n;
-
- source = ((err >> 24) & 0xff);
- code = (err & 0x00ffffff);
- if (source)
- {
- /* Assume this is an libgpg-error and try to map the codes
- back. */
- switch (code)
- {
- case 257: n = ASSUAN_General_Error ; break;
- case 258: n = ASSUAN_Accept_Failed ; break;
- case 259: n = ASSUAN_Connect_Failed ; break;
- case 260: n = ASSUAN_Invalid_Response ; break;
- case 261: n = ASSUAN_Invalid_Value ; break;
- case 262: n = ASSUAN_Line_Not_Terminated ; break;
- case 263: n = ASSUAN_Line_Too_Long ; break;
- case 264: n = ASSUAN_Nested_Commands ; break;
- case 265: n = ASSUAN_No_Data_Callback ; break;
- case 266: n = ASSUAN_No_Inquire_Callback ; break;
- case 267: n = ASSUAN_Not_A_Server ; break;
- case 69: n = ASSUAN_Not_Implemented ; break;
- case 280: n = ASSUAN_Parameter_Conflict ; break;
- case 269: n = ASSUAN_Problem_Starting_Server; break;
- case 270: n = ASSUAN_Read_Error ; break;
- case 271: n = ASSUAN_Write_Error ; break;
- case 80: n = ASSUAN_Server_Fault ; break;
- case 276: n = ASSUAN_Syntax_Error ; break;
- case 273: n = ASSUAN_Too_Much_Data ; break;
- case 274: n = ASSUAN_Unexpected_Command ; break;
- case 275: n = ASSUAN_Unknown_Command ; break;
- case 277: n = ASSUAN_Canceled ; break;
- case 114: n = ASSUAN_Not_Confirmed ; break;
- case ((1<<15)|86): n = ASSUAN_Out_Of_Core ; break;
- default: n = 0; break;
- }
- if (n)
- s = assuan_strerror (n);
- else
- {
- sprintf (buf, "ec=%u.%u", source, code );
- s=buf;
- }
- }
- else
- {
- sprintf (buf, "ec=%d", err );
- s=buf;
- }
- }
- break;
- }
-
- return s;
-}
-
-EOF
diff --git a/src/versioninfo.rc.in b/src/versioninfo.rc.in
new file mode 100644
index 0000000..bfb652e
--- /dev/null
+++ b/src/versioninfo.rc.in
@@ -0,0 +1,52 @@
+/* versioninfo.rc.in - for gpgme
+ * Copyright (C) 2005 g10 Code GmbH
+ *
+ * This file is free software; as a special exception the author gives
+ * unlimited permission to copy and/or distribute it, with or without
+ * modifications, as long as this notice is preserved.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/* This file is processed by configure to create versioninfo.rc */
+
+#line __LINE__ "versioninfo.rc.in"
+
+#include <afxres.h>
+
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @LIBGPGME_LT_CURRENT@,@LIBGPGME_LT_AGE@,@LIBGPGME_LT_REVISION@,@BUILD_REVISION@
+ PRODUCTVERSION @BUILD_FILEVERSION@
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x21L
+#else
+ FILEFLAGS 0x20L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", "Provided under the terms of the GNU Lesser General Public License.\0"
+ VALUE "CompanyName", "g10 Code GmbH\0"
+ VALUE "FileDescription", "GPGME - GnuPG Made Easy\0"
+ VALUE "FileVersion", "@LIBGPGME_LT_CURRENT@.@LIBGPGME_LT_AGE@.@LIBGPGME_LT_REVISION@.@BUILD_REVISION@\0"
+ VALUE "InternalName", "gpgme\0"
+ VALUE "LegalCopyright", "Copyright � 2005 g10 Code GmbH\0"
+ VALUE "LegalTrademarks", "\0"
+ VALUE "OriginalFilename", "gpgme.dll\0"
+ VALUE "PrivateBuild", "\0"
+ VALUE "ProductName", "GPGME\0"
+ VALUE "ProductVersion", "@VERSION@\0"
+ VALUE "SpecialBuild", "@BUILD_TIMESTAMP@\0"
+ END
+ END
+END
+