[svn] gpgme - r1410 - in trunk: . src
svn author marcus
cvs at cvs.gnupg.org
Fri Oct 30 15:21:08 CET 2009
Author: marcus
Date: 2009-10-30 15:21:08 +0100 (Fri, 30 Oct 2009)
New Revision: 1410
Added:
trunk/src/gpgme-tool.c
Modified:
trunk/ChangeLog
trunk/configure.ac
trunk/src/ChangeLog
trunk/src/Makefile.am
trunk/src/assuan-support.c
trunk/src/conversion.c
trunk/src/debug.h
trunk/src/engine-assuan.c
trunk/src/engine-g13.c
trunk/src/g13.c
trunk/src/gpgme.c
trunk/src/ops.h
trunk/src/signers.c
trunk/src/version.c
Log:
2009-10-30 Marcus Brinkmann <marcus at g10code.de>
* configure.ac: Check for argp.h and error_t.
src/
2009-10-30 Marcus Brinkmann <marcus at g10code.de>
* Makefile.am (noinst_PROGRAMS): New target gpgme-tool.
(gpgme_tool_LDADD): New variable.
* gpgme-tool.c: New file.
* ops.h (_gpgme_sig_notation_clearm _gpgme_signers_clear): New
prototypes.
* gpgme.c (gpgme_set_protocol): Allow GPGME_PROTOCOL_GPGCONF (when
had that gone missing?).
(_gpgme_sig_notation_clear): New function without debug output.
(gpgme_release): Call it and _gpgme_signers_clear.
* signers.c (_gpgme_signers_clear): New function without debug output.
* g13.c (gpgme_op_vfs_mount): Add debug output.
* assuan-support.c (my_spawn): Allow fd_child_list to be NULL.
* conversion.c (_gpgme_encode_percent_string): Fix infinite loop.
* debug.h: Put tag in front of debug lines, should make for nicer
output.
* engine-assuan.c (llass_new): Use our new system hooks for libassuan.
* engine-g13.c (g13_new): Remove redundant assuan context allocation.
* version.c (gpgme_check_version_internal): Delay debug output
until after gpgme_check_version was called.
[The diff below has been truncated]
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/ChangeLog 2009-10-30 14:21:08 UTC (rev 1410)
@@ -1,3 +1,7 @@
+2009-10-30 Marcus Brinkmann <marcus at g10code.de>
+
+ * configure.ac: Check for argp.h and error_t.
+
2009-10-26 Marcus Brinkmann <marcus at g10code.de>
* configure.ac (NEED_GPG_VERSION_DEFAULT): Bump to 1.4.0 as 1.3.0
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/ChangeLog 2009-10-30 14:21:08 UTC (rev 1410)
@@ -1,3 +1,25 @@
+2009-10-30 Marcus Brinkmann <marcus at g10code.de>
+
+ * Makefile.am (noinst_PROGRAMS): New target gpgme-tool.
+ (gpgme_tool_LDADD): New variable.
+ * gpgme-tool.c: New file.
+ * ops.h (_gpgme_sig_notation_clearm _gpgme_signers_clear): New
+ prototypes.
+ * gpgme.c (gpgme_set_protocol): Allow GPGME_PROTOCOL_GPGCONF (when
+ had that gone missing?).
+ (_gpgme_sig_notation_clear): New function without debug output.
+ (gpgme_release): Call it and _gpgme_signers_clear.
+ * signers.c (_gpgme_signers_clear): New function without debug output.
+ * g13.c (gpgme_op_vfs_mount): Add debug output.
+ * assuan-support.c (my_spawn): Allow fd_child_list to be NULL.
+ * conversion.c (_gpgme_encode_percent_string): Fix infinite loop.
+ * debug.h: Put tag in front of debug lines, should make for nicer
+ output.
+ * engine-assuan.c (llass_new): Use our new system hooks for libassuan.
+ * engine-g13.c (g13_new): Remove redundant assuan context allocation.
+ * version.c (gpgme_check_version_internal): Delay debug output
+ until after gpgme_check_version was called.
+
2009-10-28 Marcus Brinkmann <marcus at g10code.de>
* signers.c, encrypt-sign.c, encrypt.c, delete.c, keylist.c,
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/configure.ac 2009-10-30 14:21:08 UTC (rev 1410)
@@ -850,6 +850,14 @@
sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'`
AC_SUBST(LTLIBOBJS)
+# Some checks for gpgme-tool
+AC_CHECK_HEADER([argp.h])
+AC_CHECK_TYPES([error_t], [],
+ [AC_DEFINE([error_t], [int],
+ [Define to a type to use for `error_t' if it is not otherwise available.])],
+ [#include <errno.h>])
+
+
# Last check.
die=no
if test "$require_libassuan" = "no"; then
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/Makefile.am 2009-10-30 14:21:08 UTC (rev 1410)
@@ -153,7 +153,6 @@
# wrapper process.
libexec_PROGRAMS = gpgme-w32spawn
-
LTRCCOMPILE = $(LIBTOOL) --mode=compile $(RC) \
`echo $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) | \
sed -e 's/-I/--include-dir /g;s/-D/--define /g'`
@@ -226,6 +225,9 @@
@GPG_ERROR_LIBS@ @QT4_CORE_LIBS@
endif
+noinst_PROGRAMS = gpgme-tool
+gpgme_tool_LDADD = libgpgme.la
+
status-table.h : gpgme.h
$(srcdir)/mkstatus < $(builddir)/gpgme.h > status-table.h
Modified: trunk/src/assuan-support.c
===================================================================
--- trunk/src/assuan-support.c 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/assuan-support.c 2009-10-30 14:21:08 UTC (rev 1410)
@@ -117,19 +117,25 @@
return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
i = 0;
- while (fd_child_list[i] != ASSUAN_INVALID_FD)
- i++;
+ if (fd_child_list)
+ {
+ while (fd_child_list[i] != ASSUAN_INVALID_FD)
+ i++;
+ }
/* fd_in, fd_out, terminator */
i += 3;
fd_items = malloc (sizeof (struct spawn_fd_item_s) * i);
if (! fd_items)
return gpg_error_from_syserror ();
i = 0;
- while (fd_child_list[i] != ASSUAN_INVALID_FD)
+ if (fd_child_list)
{
- fd_items[i].fd = fd_child_list[i];
- fd_items[i].dup_to = -1;
- i++;
+ while (fd_child_list[i] != ASSUAN_INVALID_FD)
+ {
+ fd_items[i].fd = fd_child_list[i];
+ fd_items[i].dup_to = -1;
+ i++;
+ }
}
if (fd_in != ASSUAN_INVALID_FD)
{
@@ -151,10 +157,13 @@
{
i = 0;
- while (fd_child_list[i] != ASSUAN_INVALID_FD)
+ if (fd_child_list)
{
- fd_child_list[i] = fd_items[i].peer_name;
- i++;
+ while (fd_child_list[i] != ASSUAN_INVALID_FD)
+ {
+ fd_child_list[i] = fd_items[i].peer_name;
+ i++;
+ }
}
}
free (fd_items);
Modified: trunk/src/conversion.c
===================================================================
--- trunk/src/conversion.c 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/conversion.c 2009-10-30 14:21:08 UTC (rev 1410)
@@ -272,6 +272,7 @@
destlen += 3;
else
destlen++;
+ str++;
}
/* Terminating nul byte. */
destlen++;
Modified: trunk/src/debug.h
===================================================================
--- trunk/src/debug.h 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/debug.h 2009-10-30 14:21:08 UTC (rev 1410)
@@ -89,155 +89,155 @@
#define TRACE_BEG(lvl, name, tag) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func), 0
#define TRACE_BEG0(lvl, name, tag, fmt) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func), 0
#define TRACE_BEG1(lvl, name, tag, fmt, arg1) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1), 0
#define TRACE_BEG2(lvl, name, tag, fmt, arg1, arg2) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2), 0
#define TRACE_BEG3(lvl, name, tag, fmt, arg1, arg2, arg3) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3), 0
#define TRACE_BEG4(lvl, name, tag, fmt, arg1, arg2, arg3, arg4) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4), 0
#define TRACE_BEG5(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5), 0
#define TRACE_BEG7(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
arg5, arg6, arg7) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5, \
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7), 0
#define TRACE_BEG8(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, \
arg5, arg6, arg7, arg8) \
_TRACE (lvl, name, tag); \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): enter: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5, \
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: enter: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7, arg8), 0
#define TRACE(lvl, name, tag) \
- _gpgme_debug (lvl, "%s (%s=%p): call\n", \
- name, STRINGIFY (tag), (void *) (uintptr_t) tag), 0
+ _gpgme_debug (lvl, "[%s=%p] %s: call\n", \
+ STRINGIFY (tag), (void *) (uintptr_t) tag, name), 0
#define TRACE0(lvl, name, tag, fmt) \
- _gpgme_debug (lvl, "%s (%s=%p): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) (uintptr_t) tag), 0
+ _gpgme_debug (lvl, "[%s=%p] %s: call: " fmt "\n", \
+ STRINGIFY (tag), (void *) (uintptr_t) tag, name), 0
#define TRACE1(lvl, name, tag, fmt, arg1) \
- _gpgme_debug (lvl, "%s (%s=%p): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1), 0
+ _gpgme_debug (lvl, "[%s=%p] %s: call: " fmt "\n", \
+ STRINGIFY (tag), (void *) (uintptr_t) tag, name, arg1), 0
#define TRACE2(lvl, name, tag, fmt, arg1, arg2) \
- _gpgme_debug (lvl, "%s (%s=%p): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
+ _gpgme_debug (lvl, "[%s=%p] %s: call: " fmt "\n", \
+ STRINGIFY (tag), (void *) (uintptr_t) tag, name, arg1, \
arg2), 0
#define TRACE3(lvl, name, tag, fmt, arg1, arg2, arg3) \
- _gpgme_debug (lvl, "%s (%s=%p): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
+ _gpgme_debug (lvl, "[%s=%p] %s: call: " fmt "\n", \
+ STRINGIFY (tag), (void *) (uintptr_t) tag, name, arg1, \
arg2, arg3), 0
#define TRACE6(lvl, name, tag, fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
- _gpgme_debug (lvl, "%s (%s=%p): call: " fmt "\n", \
- name, STRINGIFY (tag), (void *) (uintptr_t) tag, arg1, \
+ _gpgme_debug (lvl, "[%s=%p] %s: call: " fmt "\n", \
+ STRINGIFY (tag), (void *) (uintptr_t) tag, name, arg1, \
arg2, arg3, arg4, arg5, arg6), 0
#define TRACE_ERR(err) \
err == 0 ? (TRACE_SUC ()) : \
- (_gpgme_debug (_gpgme_trace_level, "%s (%s=%p): error: %s <%s>\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, gpgme_strerror (err), \
+ (_gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: error: %s <%s>\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, gpgme_strerror (err), \
gpgme_strsource (err)), (err))
/* The cast to void suppresses GCC warnings. */
#define TRACE_SYSRES(res) \
res >= 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) : \
- (_gpgme_debug (_gpgme_trace_level, "%s (%s=%p): error: %s\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, strerror (errno)), (res))
+ (_gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: error: %s\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, strerror (errno)), (res))
#define TRACE_SYSERR(res) \
res == 0 ? ((void) (TRACE_SUC1 ("result=%i", res)), (res)) : \
- (_gpgme_debug (_gpgme_trace_level, "%s (%s=%p): error: %s\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, strerror (res)), (res))
+ (_gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: error: %s\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, strerror (res)), (res))
#define TRACE_SUC() \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): leave\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: leave\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func), 0
#define TRACE_SUC0(fmt) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): leave: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: leave: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func), 0
#define TRACE_SUC1(fmt, arg1) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): leave: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: leave: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1), 0
#define TRACE_SUC2(fmt, arg1, arg2) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): leave: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: leave: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2), 0
#define TRACE_SUC5(fmt, arg1, arg2, arg3, arg4, arg5) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): leave: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: leave: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5), 0
#define TRACE_LOG(fmt) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func), 0
#define TRACE_LOG1(fmt, arg1) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1), 0
#define TRACE_LOG2(fmt, arg1, arg2) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2), 0
#define TRACE_LOG3(fmt, arg1, arg2, arg3) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3), 0
#define TRACE_LOG4(fmt, arg1, arg2, arg3, arg4) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4), 0
#define TRACE_LOG5(fmt, arg1, arg2, arg3, arg4, arg5) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5), 0
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5), 0
#define TRACE_LOG6(fmt, arg1, arg2, arg3, arg4, arg5, arg6) \
- _gpgme_debug (_gpgme_trace_level, "%s (%s=%p): check: " fmt "\n", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, arg1, arg2, arg3, arg4, arg5, \
+ _gpgme_debug (_gpgme_trace_level, "[%s=%p] %s: check: " fmt "\n", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, arg1, arg2, arg3, arg4, arg5, \
arg6), 0
#define TRACE_LOGBUF(buf, len) \
- _gpgme_debug_buffer (_gpgme_trace_level, "%s (%s=%p): check: %s", \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag, buf, len)
+ _gpgme_debug_buffer (_gpgme_trace_level, "[%s=%p] %s: check: %s", \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func, buf, len)
#define TRACE_SEQ(hlp,fmt) \
_gpgme_debug_begin (&(hlp), _gpgme_trace_level, \
- "%s (%s=%p): check: " fmt, \
- _gpgme_trace_func, _gpgme_trace_tagname, \
- _gpgme_trace_tag)
+ "[%s=%p] %s: check: " fmt, \
+ _gpgme_trace_tagname, _gpgme_trace_tag, \
+ _gpgme_trace_func)
#define TRACE_ADD0(hlp,fmt) \
_gpgme_debug_add (&(hlp), fmt)
#define TRACE_ADD1(hlp,fmt,a) \
Modified: trunk/src/engine-assuan.c
===================================================================
--- trunk/src/engine-assuan.c 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/engine-assuan.c 2009-10-30 14:21:08 UTC (rev 1410)
@@ -233,9 +233,13 @@
llass->opt.gpg_agent = 1;
}
- err = assuan_new (&llass->assuan_ctx);
+ err = assuan_new_ext (&llass->assuan_ctx, GPG_ERR_SOURCE_GPGME,
+ &_gpgme_assuan_malloc_hooks, _gpgme_assuan_log_cb,
+ NULL);
if (err)
goto leave;
+ assuan_ctx_set_system_hooks (llass->assuan_ctx, &_gpgme_assuan_system_hooks);
+
err = assuan_socket_connect (llass->assuan_ctx, file_name, 0);
if (err)
goto leave;
Modified: trunk/src/engine-g13.c
===================================================================
--- trunk/src/engine-g13.c 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/engine-g13.c 2009-10-30 14:21:08 UTC (rev 1410)
@@ -230,10 +230,6 @@
g13->status_cb.tag = 0;
g13->status_cb.data = g13;
- err = assuan_new (&g13->assuan_ctx);
- if (err)
- goto leave;
-
argc = 0;
argv[argc++] = "g13";
if (home_dir)
Modified: trunk/src/g13.c
===================================================================
--- trunk/src/g13.c 2009-10-30 14:13:42 UTC (rev 1409)
+++ trunk/src/g13.c 2009-10-30 14:21:08 UTC (rev 1410)
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include "gpgme.h"
+#include "debug.h"
#include "context.h"
#include "ops.h"
#include "util.h"
@@ -135,9 +136,9 @@
or destroyed. This is a synchronous convenience interface, which
automatically returns an operation error if there is no
transmission error. */
-gpgme_error_t
-gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
- const char *mount_dir, int flags, gpgme_error_t *op_err)
+static gpgme_error_t
+_gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
+ const char *mount_dir, int flags, gpgme_error_t *op_err)
{
gpg_error_t err;
char *cmd;
@@ -194,3 +195,15 @@
return err;
}
+
+gpgme_error_t
+gpgme_op_vfs_mount (gpgme_ctx_t ctx, const char *container_file,
+ const char *mount_dir, int flags, gpgme_error_t *op_err)
+{
+ TRACE_BEG4 (DEBUG_CTX, "gpgme_op_vfs_mount", ctx,
+ "container=%s, mount_dir=%s, flags=0x%x, op_err=%p",
+ container_file, mount_dir, flags, op_err);
+ return TRACE_ERR (_gpgme_op_vfs_mount (ctx, container_file, mount_dir,
+ flags, op_err));
+}
+
Added: trunk/src/gpgme-tool.c
===================================================================
--- trunk/src/gpgme-tool.c (rev 0)
+++ trunk/src/gpgme-tool.c 2009-10-30 14:21:08 UTC (rev 1410)
@@ -0,0 +1,2012 @@
+/* gpgme-tool.c - GnuPG Made Easy.
+ Copyright (C) 2000 Werner Koch (dd9jn)
+ Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007 g10 Code GmbH
+
+ This file is part of GPGME.
+
+ GPGME 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.
+
+ GPGME 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. */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <getopt.h>
+#include <ctype.h>
+#include <stdarg.h>
+#include <locale.h>
+#ifdef HAVE_ARGP_H
+#include <argp.h>
+#endif
+
+#include "gpgme.h"
+
+
+#ifndef HAVE_ARGP_H
+/* Minimal argp implementation. */
+
+/* Differences to ARGP:
+ argp_program_version: Required.
+ argp_program_bug_address: Required.
+ argp_program_version_hook: Not supported.
+ argp_err_exit_status: Required.
+ struct argp: Children and help_filter not supported.
+ argp_domain: Not supported.
+ struct argp_option: Group not supported. Options are printed in
+ order given. Flags OPTION_ALIAS, OPTION_DOC and OPTION_NO_USAGE
+ are not supported.
+ argp_parse: No flags are supported (ARGP_PARSE_ARGV0, ARGP_NO_ERRS,
+ ARGP_NO_ARGS, ARGP_IN_ORDER, ARGP_NO_HELP, ARGP_NO_EXIT,
+ ARGP_LONG_ONLY, ARGP_SILENT). ARGP must not be NULL.
+ argp_help: Flag ARGP_HELP_LONG_ONLY not supported.
+ argp_state: argc, argv, next may not be modified and should not be used. */
+
+extern const char *argp_program_version;
+extern const char *argp_program_bug_address;
+extern error_t argp_err_exit_status;
+
+struct argp_option
+{
+ const char *name;
+ int key;
+ const char *arg;
+#define OPTION_ARG_OPTIONAL 0x1
+#define OPTION_HIDDEN 0x2
+ int flags;
+ const char *doc;
+ int group;
+};
+
+struct argp;
+struct argp_state
+{
+ const struct argp *const root_argp;
+ int argc;
+ char **argv;
+ int next;
+ unsigned flags;
+ unsigned arg_num;
+ int quoted;
+ void *input;
+ void **child_inputs;
+ void *hook;
+ char *name;
+ FILE *err_stream;
+ FILE *out_stream;
+ void *pstate;
+};
+
+#define ARGP_ERR_UNKNOWN E2BIG
+#define ARGP_KEY_ARG 0
+#define ARGP_KEY_ARGS 0x1000006
+#define ARGP_KEY_END 0x1000001
+#define ARGP_KEY_NO_ARGS 0x1000002
+#define ARGP_KEY_INIT 0x1000003
+#define ARGP_KEY_FINI 0x1000007
+#define ARGP_KEY_SUCCESS 0x1000004
+#define ARGP_KEY_ERROR 0x1000005
+typedef error_t (*argp_parser_t) (int key, char *arg, struct argp_state *state);
+
+struct argp
+{
+ const struct argp_option *options;
+ argp_parser_t parser;
+ const char *args_doc;
+ const char *doc;
+
+ const struct argp_child *children;
+ char *(*help_filter) (int key, const char *text, void *input);
+ const char *argp_domain;
+};
+
+#define ARGP_HELP_USAGE ARGP_HELP_SHORT_USAGE
+#define ARGP_HELP_SHORT_USAGE 0x02
+#define ARGP_HELP_SEE 0x04
+#define ARGP_HELP_LONG 0x08
+#define ARGP_HELP_PRE_DOC 0x10
+#define ARGP_HELP_POST_DOC 0x20
+#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
+#define ARGP_HELP_BUG_ADDR 0x40
+#define ARGP_HELP_EXIT_ERR 0x100
+#define ARGP_HELP_EXIT_OK 0x200
+#define ARGP_HELP_STD_ERR (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
+#define ARGP_HELP_STD_USAGE \
+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
+#define ARGP_HELP_STD_HELP \
+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
+ | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
+
+
+char *
+_argp_pname (char *name)
+{
+ char *pname = name;
+ char *bname = strrchr (pname, '/');
+ if (! bname)
+ bname = strrchr (pname, '\\');
+ if (bname)
+ pname = bname + 1;
+ return pname;
+}
+
+
+void
+_argp_state_help (const struct argp *argp, const struct argp_state *state,
+ FILE *stream, unsigned flags, char *name)
+{
+ if (state)
+ name = state->name;
+
+ if (flags & ARGP_HELP_SHORT_USAGE)
+ fprintf (stream, "Usage: %s [OPTIONS...] %s\n", name, argp->args_doc);
+ if (flags & ARGP_HELP_SEE)
+ fprintf (stream, "Try `%s --help' or `%s --usage' for more information.\n",
+ name, name);
+ if (flags & ARGP_HELP_PRE_DOC)
+ {
+ char buf[1024];
+ char *end;
+ strncpy (buf, argp->doc, sizeof (buf));
+ buf[sizeof (buf) - 1] = '\0';
+ end = strchr (buf, '\v');
+ if (end)
+ *end = '\0';
+ fprintf (stream, "%s\n%s", buf, buf[0] ? "\n" : "");
+ }
+ if (flags & ARGP_HELP_LONG)
+ {
+ const struct argp_option *opt = argp->options;
+ while (opt->key)
+ {
+ #define NSPACES 29
+ char spaces[NSPACES + 1] = " ";
+ int len = 0;
+ fprintf (stream, " ");
+ len += 2;
+ if (isascii (opt->key))
+ {
+ fprintf (stream, "-%c", opt->key);
+ len += 2;
+ if (opt->name)
+ {
+ fprintf (stream, ", ");
+ len += 2;
+ }
+ }
+ if (opt->name)
+ {
+ fprintf (stream, "--%s", opt->name);
+ len += 2 + strlen (opt->name);
+ }
+ if (opt->arg && (opt->flags & OPTION_ARG_OPTIONAL))
+ {
+ fprintf (stream, "[=%s]", opt->arg);
+ len += 3 + strlen (opt->arg);
+ }
+ else if (opt->arg)
+ {
+ fprintf (stream, "=%s", opt->arg);
+ len += 1 + strlen (opt->arg);
+ }
+ if (len >= NSPACES)
+ len = NSPACES - 1;
+ spaces[NSPACES - len] = '\0';
+ fprintf (stream, "%s%s\n", spaces, opt->doc);
+ opt++;
+ }
+ fprintf (stream, " -?, --help Give this help list\n");
+ fprintf (stream, " --usage Give a short usage "
+ "message\n");
+ }
+ if (flags & ARGP_HELP_POST_DOC)
+ {
+ char buf[1024];
+ char *end;
+ strncpy (buf, argp->doc, sizeof (buf));
+ buf[sizeof (buf) - 1] = '\0';
+ end = strchr (buf, '\v');
+ if (end)
+ {
+ end++;
+ if (*end)
+ fprintf (stream, "\n%s\n", end);
+ }
+ fprintf (stream, "\nMandatory or optional arguments to long options are also mandatory or optional\n");
+ fprintf (stream, "for any corresponding short options.\n");
+ }
+ if (flags & ARGP_HELP_BUG_ADDR)
+ fprintf (stream, "\nReport bugs to %s.\n", argp_program_bug_address);
+
+ if (flags & ARGP_HELP_EXIT_ERR)
+ exit (argp_err_exit_status);
+ if (flags & ARGP_HELP_EXIT_OK)
+ exit (0);
+}
+
+
+void
+argp_usage (const struct argp_state *state)
+{
+ _argp_state_help (state->root_argp, state, state->err_stream,
+ ARGP_HELP_STD_USAGE, state->name);
+}
+
+
+void
+argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
+{
+ _argp_state_help (state->root_argp, state, stream, flags, state->name);
+}
+
+
+void
+argp_error (const struct argp_state *state, const char *fmt, ...)
+{
+ va_list ap;
+
+ fprintf (state->err_stream, "%s: ", state->name);
+ va_start (ap, fmt);
+ vfprintf (state->err_stream, fmt, ap);
+ va_end (ap);
+ fprintf (state->err_stream, "\n");
+ argp_state_help (state, state->err_stream, ARGP_HELP_STD_ERR);
+ exit (argp_err_exit_status);
+}
+
+
+void
+argp_help (const struct argp *argp, FILE *stream, unsigned flags, char *name)
+{
+ _argp_state_help (argp, NULL, stream, flags, name);
+}
+
+
+error_t
+argp_parse (const struct argp *argp, int argc,
+ char **argv, unsigned flags, int *arg_index, void *input)
+{
+ int rc = 0;
+ struct argp_state state = { argp, argc, argv, 1, flags, 0, 0, input,
+ NULL, NULL, _argp_pname (argv[0]),
+ stderr, stdout, NULL };
+ /* All non-option arguments are collected at the beginning of
+ &argv[1] during processing. This is a counter for their number. */
+ int non_opt_args = 0;
+
+ rc = argp->parser (ARGP_KEY_INIT, NULL, &state);
+ if (rc && rc != ARGP_ERR_UNKNOWN)
+ goto argperror;
+
+ while (state.next < state.argc - non_opt_args)
+ {
+ int idx = state.next;
+ state.next++;
+
+ if (! strcasecmp (state.argv[idx], "--"))
+ {
+ state.quoted = idx;
+ continue;
+ }
+
+ if (state.quoted || state.argv[idx][0] != '-')
+ {
+ char *arg_saved = state.argv[idx];
+ non_opt_args++;
+ memmove (&state.argv[idx], &state.argv[idx + 1],
+ (state.argc - 1 - idx) * sizeof (char *));
+ state.argv[argc - 1] = arg_saved;
+ state.next--;
+ }
+ else if (! strcasecmp (state.argv[idx], "--help")
+ || !strcmp (state.argv[idx], "-?"))
+ {
+ argp_state_help (&state, state.out_stream, ARGP_HELP_STD_HELP);
+ }
+ else if (! strcasecmp (state.argv[idx], "--usage"))
+ {
+ argp_state_help (&state, state.out_stream,
+ ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
+ }
+ else if (! strcasecmp (state.argv[idx], "--version")
+ || !strcmp (state.argv[idx], "-V"))
+ {
+ fprintf (state.out_stream, "%s\n", argp_program_version);
+ exit (0);
+ }
+ else
+ {
+ /* Search for option and call parser with its KEY. */
+ int key = ARGP_KEY_ARG; /* Just some dummy value. */
+ const struct argp_option *opt = argp->options;
+ char *arg = NULL;
+ int found = 0;
+
+ /* Check for --opt=value syntax. */
+ arg = strchr (state.argv[idx], '=');
+ if (arg)
+ {
+ *arg = '\0';
+ arg++;
+ }
+
+ if (state.argv[idx][1] != '-')
+ key = state.argv[idx][1];
+
+ while (! found && opt->key)
+ {
+ if (key == opt->key
+ || (key == ARGP_KEY_ARG
+ && ! strcasecmp (&state.argv[idx][2], opt->name)))
+ {
+ if (arg && !opt->arg)
+ argp_error (&state, "Option %s does not take an argument",
+ state.argv[idx]);
+ if (opt->arg && state.next < state.argc
+ && state.argv[idx + 1][0] != '-')
+ {
+ arg = state.argv[idx + 1];
+ state.next++;
+ }
+ if (opt->arg && !(opt->flags & OPTION_ARG_OPTIONAL))
+ argp_error (&state, "Option %s requires an argument",
+ state.argv[idx]);
+
+ rc = argp->parser (opt->key, arg, &state);
+ if (rc == ARGP_ERR_UNKNOWN)
+ break;
+ else if (rc)
+ goto argperror;
+ found = 1;
+ }
+ opt++;
+ }
+ if (! found)
+ argp_error (&state, "Unknown option %s", state.argv[idx]);
+ }
+ }
+
+ while (state.next < state.argc)
+ {
+ /* Call parser for all non-option args. */
+ int idx = state.next;
+ state.next++;
+ rc = argp->parser (ARGP_KEY_ARG, state.argv[idx], &state);
+ if (rc && rc != ARGP_ERR_UNKNOWN)
+ goto argperror;
+ if (rc == ARGP_ERR_UNKNOWN)
+ {
+ int old_next = state.next;
+ rc = argp->parser (ARGP_KEY_ARGS, NULL, &state);
+ if (rc == ARGP_ERR_UNKNOWN)
+ {
+ argp_error (&state, "Too many arguments", state.argv[idx]);
+ goto argperror;
+ }
+ if (! rc && state.next == old_next)
+ {
+ state.arg_num += state.argc - state.next;
+ state.next = state.argc;
+ }
+ }
+ else
+ state.arg_num++;
+ }
+
+ if (state.arg_num == 0)
+ {
+ rc = argp->parser (ARGP_KEY_NO_ARGS, NULL, &state);
+ if (rc && rc != ARGP_ERR_UNKNOWN)
+ goto argperror;
+ }
+ if (state.next == state.argc)
+ {
+ rc = argp->parser (ARGP_KEY_END, NULL, &state);
+ if (rc && rc != ARGP_ERR_UNKNOWN)
+ goto argperror;
+ }
+ rc = argp->parser (ARGP_KEY_FINI, NULL, &state);
+ if (rc && rc != ARGP_ERR_UNKNOWN)
+ goto argperror;
+
+ rc = 0;
+ argp->parser (ARGP_KEY_SUCCESS, NULL, &state);
+
+ argperror:
+ if (rc)
+ {
+ argp_error (&state, "unexpected error: %s", strerror (rc));
+ argp->parser (ARGP_KEY_ERROR, NULL, &state);
+ }
+
+ argp->parser (ARGP_KEY_FINI, NULL, &state);
+
+ if (arg_index)
+ *arg_index = state.next - 1;
+
+ return 0;
+}
+#endif
+
+
+/* SUPPORT. */
+FILE *log_stream;
+char *program_name = "gpgme-tool";
+
+void
+log_init (void)
+{
+ log_stream = stderr;
+}
+
+
+void
+log_error (int status, gpg_error_t errnum, const char *fmt, ...)
+{
+ va_list ap;
+
+ fprintf (log_stream, "%s: ", program_name);
+ va_start (ap, fmt);
+ vfprintf (log_stream, fmt, ap);
+ va_end (ap);
+ if (errnum)
+ fprintf (log_stream, ": %s <%s>", gpg_strerror (errnum),
+ gpg_strsource (errnum));
+ fprintf (log_stream, "\n");
+ if (status)
+ exit (status);
+}
+
+
+
+typedef enum status
+ {
+ STATUS_PROTOCOL,
+ STATUS_PROGRESS,
+ STATUS_ENGINE,
+ STATUS_ARMOR,
+ STATUS_TEXTMODE,
+ STATUS_INCLUDE_CERTS,
+ STATUS_KEYLIST_MODE,
+ STATUS_ENCRYPT_RESULT
+ } status_t;
+
+const char *status_string[] =
+ {
+ "PROTOCOL",
+ "PROGRESS",
+ "ENGINE",
+ "ARMOR",
+ "TEXTMODE",
+ "INCLUDE_CERTS",
+ "KEYLIST_MODE",
+ "ENCRYPT_RESULT"
+ };
+
+struct gpgme_tool
+{
+ gpgme_ctx_t ctx;
+#define MAX_RECIPIENTS 10
+ gpgme_key_t recipients[MAX_RECIPIENTS + 1];
+ int recipients_nr;
+
+ gpg_error_t (*write_status) (void *hook, const char *status, const char *msg);
+ void *write_status_hook;
+};
+typedef struct gpgme_tool *gpgme_tool_t;
+
+
+/* Forward declaration. */
+void gt_write_status (gpgme_tool_t gt, status_t status, ...);
+
+void
+_gt_progress_cb (void *opaque, const char *what,
+ int type, int current, int total)
+{
+ gpgme_tool_t gt = opaque;
+ char buf[100];
+
+ snprintf (buf, sizeof (buf), "0x%02x %i %i", type, current, total);
+ gt_write_status (gt, STATUS_PROGRESS, what, buf);
+}
+
+
+gpg_error_t
+_gt_gpgme_new (gpgme_tool_t gt, gpgme_ctx_t *ctx)
+{
+ gpg_error_t err;
+
+ err = gpgme_new (ctx);
+ if (err)
+ return err;
+ gpgme_set_progress_cb (*ctx, _gt_progress_cb, gt);
+ return 0;
+}
+
+
+void
+gt_init (gpgme_tool_t gt)
+{
+ memset (gt, '\0', sizeof (*gt));
+ gpg_error_t err;
+
+ err = _gt_gpgme_new (gt, >->ctx);
+ if (err)
+ log_error (1, err, "can't create gpgme context");
+}
+
+
+gpg_error_t
+gt_signers_add (gpgme_tool_t gt, const char *fpr)
+{
+ gpg_error_t err;
+ gpgme_key_t key;
+
+ err = gpgme_get_key (gt->ctx, fpr, &key, 0);
+ if (err)
+ return err;
+
+ return gpgme_signers_add (gt->ctx, key);
+}
+
+
+gpg_error_t
+gt_signers_clear (gpgme_tool_t gt)
+{
+ gpgme_signers_clear (gt->ctx);
+ return 0;
+}
+
+
+gpg_error_t
+gt_recipients_add (gpgme_tool_t gt, const char *fpr)
+{
+ gpg_error_t err;
+ gpgme_key_t key;
+
+ if (gt->recipients_nr >= MAX_RECIPIENTS)
+ return gpg_error_from_errno (ENOMEM);
+
+ err = gpgme_get_key (gt->ctx, fpr, &key, 0);
+ if (err)
+ return err;
+
+ gt->recipients[gt->recipients_nr++] = key;
+ return 0;
+}
+
+
+void
+gt_recipients_clear (gpgme_tool_t gt)
+{
+ int idx;
+
+ for (idx = 0; idx < gt->recipients_nr; idx++)
+ gpgme_key_unref (gt->recipients[idx]);
+ memset (gt->recipients, '\0', gt->recipients_nr * sizeof (gpgme_key_t));
+ gt->recipients_nr = 0;
+}
+
+
+gpg_error_t
+gt_reset (gpgme_tool_t gt)
+{
+ gpg_error_t err;
+ gpgme_ctx_t ctx;
+
+ err = _gt_gpgme_new (gt, &ctx);
+ if (err)
+ return err;
+
+ gpgme_release (gt->ctx);
+ gt->ctx = ctx;
+ gt_recipients_clear (gt);
+ return 0;
+}
+
+
+void
+gt_write_status (gpgme_tool_t gt, status_t status, ...)
+{
+ va_list ap;
+ const char *text;
+ char buf[950];
+ char *p;
+ size_t n;
+ gpg_error_t err;
+
+ va_start (ap, status);
+ p = buf;
+ n = 0;
+ while ((text = va_arg (ap, const char *)))
+ {
+ if (n)
+ {
+ *p++ = ' ';
+ n++;
+ }
+ while (*text && n < sizeof (buf) - 2)
+ {
+ *p++ = *text++;
+ n++;
+ }
+ }
+ *p = 0;
+ va_end (ap);
+
+ err = gt->write_status (gt->write_status_hook, status_string[status], buf);
+ if (err)
+ log_error (1, err, "can't write status line");
+}
+
+
+gpg_error_t
+gt_get_engine_info (gpgme_tool_t gt, gpgme_protocol_t proto)
+{
+ gpgme_engine_info_t info;
+ info = gpgme_ctx_get_engine_info (gt->ctx);
+ while (info)
+ {
+ if (proto == GPGME_PROTOCOL_UNKNOWN || proto == info->protocol)
+ gt_write_status (gt, STATUS_ENGINE,
+ gpgme_get_protocol_name (info->protocol),
+ info->file_name, info->version,
+ info->req_version, info->home_dir);
+ info = info->next;
+ }
+ return 0;
+}
+
+
+gpgme_protocol_t
+gt_protocol_from_name (const char *name)
+{
+ if (! strcasecmp (name, gpgme_get_protocol_name (GPGME_PROTOCOL_OpenPGP)))
+ return GPGME_PROTOCOL_OpenPGP;
+ if (! strcasecmp (name, gpgme_get_protocol_name (GPGME_PROTOCOL_CMS)))
+ return GPGME_PROTOCOL_CMS;
+ if (! strcasecmp (name,gpgme_get_protocol_name (GPGME_PROTOCOL_GPGCONF)))
+ return GPGME_PROTOCOL_GPGCONF;
+ if (! strcasecmp (name, gpgme_get_protocol_name (GPGME_PROTOCOL_ASSUAN)))
+ return GPGME_PROTOCOL_ASSUAN;
+ if (! strcasecmp (name, gpgme_get_protocol_name (GPGME_PROTOCOL_G13)))
+ return GPGME_PROTOCOL_G13;
+ return GPGME_PROTOCOL_UNKNOWN;
+}
+
+
+gpg_error_t
+gt_set_protocol (gpgme_tool_t gt, gpgme_protocol_t proto)
+{
+ return gpgme_set_protocol (gt->ctx, proto);
+}
+
+
+gpg_error_t
+gt_get_protocol (gpgme_tool_t gt)
+{
+ gpgme_protocol_t proto = gpgme_get_protocol (gt->ctx);
+
+ gt_write_status (gt, STATUS_PROTOCOL, gpgme_get_protocol_name (proto),
+ NULL);
+
+ return 0;
+}
+
+
+gpg_error_t
+gt_set_armor (gpgme_tool_t gt, int armor)
+{
+ gpgme_set_armor (gt->ctx, armor);
+ return 0;
+}
+
+
+gpg_error_t
+gt_get_armor (gpgme_tool_t gt)
+{
+ gt_write_status (gt, STATUS_ARMOR,
+ gpgme_get_armor (gt->ctx) ? "true" : "false", NULL);
+
+ return 0;
+}
+
+
+gpg_error_t
+gt_set_textmode (gpgme_tool_t gt, int textmode)
+{
+ gpgme_set_textmode (gt->ctx, textmode);
+ return 0;
+}
+
+
+gpg_error_t
+gt_get_textmode (gpgme_tool_t gt)
+{
+ gt_write_status (gt, STATUS_TEXTMODE,
+ gpgme_get_textmode (gt->ctx) ? "true" : "false", NULL);
+
+ return 0;
+}
+
+
+gpg_error_t
+gt_set_keylist_mode (gpgme_tool_t gt, gpgme_keylist_mode_t keylist_mode)
+{
+ gpgme_set_keylist_mode (gt->ctx, keylist_mode);
+ return 0;
+}
+
+
+gpg_error_t
+gt_get_keylist_mode (gpgme_tool_t gt)
+{
+#define NR_KEYLIST_MODES 6
+ const char *modes[NR_KEYLIST_MODES + 1];
+ int idx = 0;
+ gpgme_keylist_mode_t mode = gpgme_get_keylist_mode (gt->ctx);
+
+ if (mode & GPGME_KEYLIST_MODE_LOCAL)
+ modes[idx++] = "local";
+ if (mode & GPGME_KEYLIST_MODE_EXTERN)
+ modes[idx++] = "extern";
+ if (mode & GPGME_KEYLIST_MODE_SIGS)
+ modes[idx++] = "sigs";
+ if (mode & GPGME_KEYLIST_MODE_SIG_NOTATIONS)
+ modes[idx++] = "sig_notations";
+ if (mode & GPGME_KEYLIST_MODE_EPHEMERAL)
+ modes[idx++] = "ephemeral";
+ if (mode & GPGME_KEYLIST_MODE_VALIDATE)
+ modes[idx++] = "validate";
+ modes[idx++] = NULL;
+
+ gt_write_status (gt, STATUS_KEYLIST_MODE, modes[0], modes[1], modes[2],
+ modes[3], modes[4], modes[5], modes[6]);
+
+ return 0;
+}
+
+
+gpg_error_t
+gt_set_include_certs (gpgme_tool_t gt, int include_certs)
+{
+ gpgme_set_include_certs (gt->ctx, include_certs);
+ return 0;
+}
+
+
+gpg_error_t
+gt_get_include_certs (gpgme_tool_t gt)
+{
+ int include_certs = gpgme_get_include_certs (gt->ctx);
+ char buf[100];
+
+ if (include_certs == GPGME_INCLUDE_CERTS_DEFAULT)
+ strcpy (buf, "default");
+ else
+ snprintf (buf, sizeof (buf), "%i", include_certs);
+
+ gt_write_status (gt, STATUS_INCLUDE_CERTS, buf, NULL);
+
+ return 0;
+}
+
+
+gpg_error_t
+gt_decrypt_verify (gpgme_tool_t gt, gpgme_data_t cipher, gpgme_data_t plain,
+ int verify)
+{
+ if (verify)
+ return gpgme_op_decrypt_verify (gt->ctx, cipher, plain);
+ else
+ return gpgme_op_decrypt (gt->ctx, cipher, plain);
+}
+
+
+gpg_error_t
+gt_sign_encrypt (gpgme_tool_t gt, gpgme_encrypt_flags_t flags,
+ gpgme_data_t plain, gpgme_data_t cipher, int sign)
+{
+ gpg_error_t err;
+
+ if (sign)
+ err = gpgme_op_encrypt (gt->ctx, gt->recipients, flags, plain, cipher);
+ else
+ err = gpgme_op_encrypt_sign (gt->ctx, gt->recipients, flags, plain, cipher);
+
+ gt_recipients_clear (gt);
+
+ return err;
+}
+
+
+gpg_error_t
+gt_sign (gpgme_tool_t gt, gpgme_data_t plain, gpgme_data_t sig,
+ gpgme_sig_mode_t mode)
+{
+ return gpgme_op_sign (gt->ctx, plain, sig, mode);
+}
+
+
+gpg_error_t
+gt_verify (gpgme_tool_t gt, gpgme_data_t sig, gpgme_data_t sig_text,
+ gpgme_data_t plain)
+{
+ return gpgme_op_verify (gt->ctx, sig, sig_text, plain);
+}
+
+
+gpg_error_t
+gt_import (gpgme_tool_t gt, gpgme_data_t data)
+{
+ return gpgme_op_import (gt->ctx, data);
+}
+
+
+gpg_error_t
+gt_export (gpgme_tool_t gt, const char *pattern[], gpgme_export_mode_t mode,
+ gpgme_data_t data)
+{
+ return gpgme_op_export_ext (gt->ctx, pattern, mode, data);
+}
+
+
+gpg_error_t
+gt_genkey (gpgme_tool_t gt, const char *parms, gpgme_data_t public,
+ gpgme_data_t secret)
+{
+ return gpgme_op_genkey (gt->ctx, parms, public, secret);
+}
+
+
+gpg_error_t
+gt_import_keys (gpgme_tool_t gt, char *fpr[])
+{
+ gpg_error_t err;
+ int cnt;
+ int idx;
+ gpgme_key_t *keys;
+
+ cnt = 0;
+ while (fpr[cnt])
+ cnt++;
+
+ if (! cnt)
+ return gpg_error (GPG_ERR_INV_VALUE);
+
+ keys = malloc ((cnt + 1) * sizeof (gpgme_key_t));
+ if (! keys)
+ return gpg_error_from_syserror ();
+
+ for (idx = 0; idx < cnt; idx++)
+ {
+ err = gpgme_get_key (gt->ctx, fpr[idx], &keys[idx], 0);
+ if (err)
+ break;
+ }
+ if (! err)
+ {
+ keys[cnt] = NULL;
+ err = gpgme_op_import_keys (gt->ctx, keys);
+ }
+
+ /* Rollback. */
+ while (--idx >= 0)
+ gpgme_key_unref (keys[idx]);
+ free (keys);
+
+ return err;
+}
+
+
+gpg_error_t
+gt_delete (gpgme_tool_t gt, char *fpr, int allow_secret)
+{
+ gpg_error_t err;
+ gpgme_key_t key;
+
+ err = gpgme_get_key (gt->ctx, fpr, &key, 0);
+ if (err)
+ return err;
+
+ err = gpgme_op_delete (gt->ctx, key, allow_secret);
+ gpgme_key_unref (key);
+ return err;
+}
+
+
+gpg_error_t
+gt_keylist_start (gpgme_tool_t gt, const char *pattern[], int secret_only)
+{
+ return gpgme_op_keylist_ext_start (gt->ctx, pattern, secret_only, 0);
+}
+
+
+gpg_error_t
+gt_keylist_next (gpgme_tool_t gt, gpgme_key_t *key)
+{
+ return gpgme_op_keylist_next (gt->ctx, key);
+}
+
+
+gpg_error_t
+gt_getauditlog (gpgme_tool_t gt, gpgme_data_t output, unsigned int flags)
+{
+ return gpgme_op_getauditlog (gt->ctx, output, flags);
+}
+
+
+gpg_error_t
+gt_vfs_mount (gpgme_tool_t gt, const char *container_file,
+ const char *mount_dir, int flags)
+{
+ gpg_error_t err;
+ gpg_error_t op_err;
+ err = gpgme_op_vfs_mount (gt->ctx, container_file, mount_dir, flags, &op_err);
+ return err || op_err;
+}
+
+
+// TODO
+#define GT_RESULT_ENCRYPT 0x1
+#define GT_RESULT_DECRYPT 0x2
+#define GT_RESULT_SIGN 0x4
+#define GT_RESULT_VERIFY 0x8
+#define GT_RESULT_IMPORT 0x10
+#define GT_RESULT_GENKEY 0x20
+#define GT_RESULT_KEYLIST 0x40
+#define GT_RESULT_VFS_MOUNT 0x80
+#define GT_RESULT_ALL (~0U)
+
+gpg_error_t
+gt_result (gpgme_tool_t gt, unsigned int flags)
+{
+ if (flags & GT_RESULT_ENCRYPT)
+ {
+ gpgme_encrypt_result_t res = gpgme_op_encrypt_result (gt->ctx);
+ if (res)
+ {
+ gpgme_invalid_key_t invrec = res->invalid_recipients;
+ while (invrec)
+ {
+ gt_write_status (gt, STATUS_ENCRYPT_RESULT, "invalid_recipient",
+ invrec->fpr, invrec->reason);
+ invrec = invrec->next;
+ }
+ }
+ }
+ return 0;
+}
+
+
+/* GPGME SERVER. */
+
+#include <assuan.h>
+
+struct server
+{
+ gpgme_tool_t gt;
+ assuan_context_t assuan_ctx;
+
+ gpgme_data_encoding_t input_enc;
+ gpgme_data_encoding_t output_enc;
+ assuan_fd_t message_fd;
+ gpgme_data_encoding_t message_enc;
+};
+
+
+gpg_error_t
+server_write_status (void *hook, const char *status, const char *msg)
+{
+ struct server *server = hook;
+ return assuan_write_status (server->assuan_ctx, status, msg);
+}
+
+
+static gpgme_data_encoding_t
+server_data_encoding (const char *line)
+{
+ if (strstr (line, "--binary"))
+ return GPGME_DATA_ENCODING_BINARY;
+ if (strstr (line, "--base64"))
+ return GPGME_DATA_ENCODING_BASE64;
+ if (strstr (line, "--armor"))
+ return GPGME_DATA_ENCODING_ARMOR;
+ if (strstr (line, "--url"))
+ return GPGME_DATA_ENCODING_URL;
+ if (strstr (line, "--urlesc"))
+ return GPGME_DATA_ENCODING_URLESC;
+ if (strstr (line, "--url0"))
+ return GPGME_DATA_ENCODING_URL0;
+ return GPGME_DATA_ENCODING_NONE;
+}
+
+
+static gpgme_error_t
+server_data_obj (assuan_fd_t fd, gpgme_data_encoding_t encoding,
+ gpgme_data_t *data)
+{
+ gpgme_error_t err;
+
+ err = gpgme_data_new_from_fd (data, fd);
+ if (err)
+ return err;
+ return gpgme_data_set_encoding (*data, encoding);
+}
+
+
+void
+server_reset_fds (struct server *server)
+{
+ /* assuan closes the input and output FDs for us when doing a RESET,
More information about the Gnupg-commits
mailing list