From caf36ce1ce34e88de870ea4e7586c3133a9f7afa Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 9 Jun 2009 16:01:02 +0000 Subject: [PATCH] Add gpgme_io_write and gpgme_io_read. Minor cleanups. --- NEWS | 6 ++++++ src/ChangeLog | 7 +++++++ src/gpgme.c | 28 ++++++++++++++++++++++++++++ src/gpgme.def | 4 ++++ src/gpgme.h.in | 5 +++++ src/libgpgme.vers | 4 ++++ src/version.c | 2 +- tests/ChangeLog | 9 +++++++++ tests/gpg/Makefile.am | 5 +++-- tests/gpg/mkdemodirs.in | 4 ++-- tests/gpg/t-edit.c | 4 ++-- 11 files changed, 71 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 55288b4..8629d31 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ Noteworthy changes in version 1.1.9 selftest failed (for example, if -mms-bitfields was not used on MingW32 targets). + * New functions gpgme_io_read and gpgme_io_write for use with + gpgme_passphrase_cb_t and gpgme_edit_cb_t functions. + + * Interface changes relative to the 1.1.7 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GPGME_KEYLIST_MODE_EPHEMERAL NEW. @@ -22,6 +26,8 @@ Noteworthy changes in version 1.1.9 GPGME_ENCRYPT_NO_ENCRYPT_TO NEW. gpgme_check_version CHANGED: Is now a macro. gpgme_new EXTENDED: More failure codes. + gpgme_io_read NEW. + gpgme_io_write NEW. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/ChangeLog b/src/ChangeLog index 5bd6ca8..7f67b02 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2009-06-09 Werner Koch + * version.c (gpgme_check_version_internal): Make result const. + + * gpgme.c: Include priv-io.h. + (gpgme_io_read, gpgme_io_write): New. + * libgpgme.vers (GPGME_1.1): Add them. + * gpgme.def: Ditto. + * Makefile.am (main_sources): Remove gpgme.h. (include_HEADERS): Rename to nodist_include_HEADERS so that a VPATH build won't use the distributed one. diff --git a/src/gpgme.c b/src/gpgme.c index b76b399..203cd71 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -34,6 +34,7 @@ #include "ops.h" #include "wait.h" #include "debug.h" +#include "priv-io.h" /* The default locale. */ @@ -428,6 +429,33 @@ gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs) } +/* This function provides access to the internal read function; it is + normally not used. */ +ssize_t +gpgme_io_read (int fd, void *buffer, size_t count) +{ + int ret; + + ret = _gpgme_io_read (fd, buffer, count); + + return ret; +} + + +/* This function provides access to the internal write function. It + is to be used by user callbacks to return data to gpgme. See + gpgme_passphrase_cb_t and gpgme_edit_cb_t. */ +ssize_t +gpgme_io_write (int fd, const void *buffer, size_t count) +{ + int ret; + + ret = _gpgme_io_write (fd, buffer, count); + + return ret; +} + + /* This function returns the callback function for I/O. */ void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs) diff --git a/src/gpgme.def b/src/gpgme.def index 14636d6..b1969ea 100644 --- a/src/gpgme.def +++ b/src/gpgme.def @@ -173,6 +173,10 @@ EXPORTS gpgme_op_assuan_transact @134 gpgme_check_version_internal @135 + + gpgme_io_read @136 + gpgme_io_write @137 + ; END diff --git a/src/gpgme.h.in b/src/gpgme.h.in index a9a4a3f..46f8769 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -961,6 +961,11 @@ void gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs); /* Get the current I/O callback functions. */ void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs); +/* Wrappers around the internal I/O functions for use with + gpgme_passphrase_cb_t and gpgme_edit_cb_t. */ +ssize_t gpgme_io_read (int fd, void *buffer, size_t count); +ssize_t gpgme_io_write (int fd, const void *buffer, size_t count); + /* Process the pending operation and, if HANG is non-zero, wait for the pending operation to finish. */ gpgme_ctx_t gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang); diff --git a/src/libgpgme.vers b/src/libgpgme.vers index bc6eb7c..fe32392 100644 --- a/src/libgpgme.vers +++ b/src/libgpgme.vers @@ -53,6 +53,10 @@ GPGME_1.1 { gpgme_op_assuan_transact_start; gpgme_check_version_internal; + + gpgme_io_read; + gpgme_io_write; + }; diff --git a/src/version.c b/src/version.c index 213df6d..cef49a3 100644 --- a/src/version.c +++ b/src/version.c @@ -213,7 +213,7 @@ const char * gpgme_check_version_internal (const char *req_version, size_t offset_sig_validity) { - char *result; + const char *result; TRACE2 (DEBUG_INIT, "gpgme_check_version_internal: ", 0, "req_version=%s, offset_sig_validity=%i", diff --git a/tests/ChangeLog b/tests/ChangeLog index 154de99..a727a89 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,12 @@ +2009-06-09 Werner Koch + + * gpg/Makefile.am (./pubring.gpg): Ignore errors in case of + already imported keys. Add --no-permission-warning and remove + obsolete --allow-secret-key-import. + * gpg/mkdemodirs.in (GPG): Add --no-permission-warning. + + * gpg/t-edit.c (edit_fnc): Use gpgme_io_write. + 2009-04-19 Moritz * gpg/Makefile.am (EXTRA_DIST): Replaced mkdemodirs with mkdemodirs.in. diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am index 57e5313..5da0bbb 100644 --- a/tests/gpg/Makefile.am +++ b/tests/gpg/Makefile.am @@ -63,8 +63,9 @@ clean-local: all-local: ./pubring.gpg ./gpg.conf ./gpg-agent.conf ./pubring.gpg: $(srcdir)/pubdemo.asc ./Alpha/Secret.gpg - $(GPG) --homedir . --import $(srcdir)/pubdemo.asc - $(GPG) --homedir . --allow-secret-key-import \ + -$(GPG) --homedir . --no-permission-warning \ + --import $(srcdir)/pubdemo.asc + -$(GPG) --homedir . --no-permission-warning \ --import Alpha/Secret.gpg Zulu/Secret.gpg ./Alpha/Secret.gpg: mkdemodirs secdemo.asc diff --git a/tests/gpg/mkdemodirs.in b/tests/gpg/mkdemodirs.in index 653c91f..2299e11 100755 --- a/tests/gpg/mkdemodirs.in +++ b/tests/gpg/mkdemodirs.in @@ -19,7 +19,7 @@ set -e -GPG="@GPG@ --batch --quiet --no-secmem-warning" +GPG="@GPG@ --batch --quiet --no-secmem-warning --no-permission-warning" NAMES='Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whisky XRay Yankee Zulu' @@ -45,7 +45,7 @@ for name in $NAMES; do [ -d $name ] && rm -r $name mkdir $name $GPGDEMO --export-secret-key -o - $name > $name/Secret.gpg - $GPG --homedir $name --allow-secret-key-import --import $name/Secret.gpg + $GPG --homedir $name --import $name/Secret.gpg $GPGDEMO --export -o - $name > $name/Public.gpg $GPG --homedir $name --import $name/Public.gpg [ -f $name/pubring.gpg~ ] && rm $name/pubring.gpg~ diff --git a/tests/gpg/t-edit.c b/tests/gpg/t-edit.c index f2f406d..394379d 100644 --- a/tests/gpg/t-edit.c +++ b/tests/gpg/t-edit.c @@ -103,8 +103,8 @@ edit_fnc (void *opaque, gpgme_status_code_t status, const char *args, int fd) if (result) { - write (fd, result, strlen (result)); - write (fd, "\n", 1); + gpgme_io_write (fd, result, strlen (result)); + gpgme_io_write (fd, "\n", 1); } return 0; } -- 2.26.2