[gmime] Allow passing NULL for gpg path in g_mime_gpg_context_new()



commit 85a6110dda867a7954c379f862f55a62bcc002ea
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Fri Dec 2 08:58:56 2016 -0500

    Allow passing NULL for gpg path in g_mime_gpg_context_new()
    
    2016-12-02  Jeffrey Stedfast  <fejj gnome org>
    
        * gmime/gmime-gpg-context.c (g_mime_gpg_context_new): Allow NULL for the gpg path
        in order to use the default gpg path (i.e. "gpg").
    
        * tests/test-pgp*.c: Updated unit tests to pass NULL for the gpg path so that
        running the unit tests don't depend on a specific location of gpg.
    
        Thanks to Daniel Kahn Gillmor for this patch.

 ChangeLog                 |   10 ++++++++++
 gmime/gmime-gpg-context.c |    6 ++----
 tests/test-pgp.c          |    4 ++--
 tests/test-pgpmime.c      |    4 ++--
 tests/test-smime.c        |    2 +-
 5 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d641cf7..0efb23c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-12-02  Jeffrey Stedfast  <fejj gnome org>
+
+       * gmime/gmime-gpg-context.c (g_mime_gpg_context_new): Allow NULL for the gpg path
+       in order to use the default gpg path (i.e. "gpg").
+
+       * tests/test-pgp*.c: Updated unit tests to pass NULL for the gpg path so that
+       running the unit tests don't depend on a specific location of gpg.
+
+       Thanks to Daniel Kahn Gillmor for this patch.
+
 2016-08-30  Jeffrey Stedfast  <fejj gnome org>
 
        * gmime/gmime-multipart.c (read_random_pool): Only initialized srand() once.
diff --git a/gmime/gmime-gpg-context.c b/gmime/gmime-gpg-context.c
index 0a05ed2..afc1d52 100644
--- a/gmime/gmime-gpg-context.c
+++ b/gmime/gmime-gpg-context.c
@@ -2190,7 +2190,7 @@ gpg_export_keys (GMimeCryptoContext *context, GPtrArray *keys, GMimeStream *ostr
 /**
  * g_mime_gpg_context_new:
  * @request_passwd: a #GMimePasswordRequestFunc
- * @path: path to gpg binary
+ * @path: path to gpg binary or %NULL for the default
  *
  * Creates a new gpg crypto context object.
  *
@@ -2203,10 +2203,8 @@ g_mime_gpg_context_new (GMimePasswordRequestFunc request_passwd, const char *pat
        GMimeCryptoContext *crypto;
        GMimeGpgContext *ctx;
        
-       g_return_val_if_fail (path != NULL, NULL);
-       
        ctx = g_object_newv (GMIME_TYPE_GPG_CONTEXT, 0, NULL);
-       ctx->path = g_strdup (path);
+       ctx->path = g_strdup (path ? path : "gpg");
        
        crypto = (GMimeCryptoContext *) ctx;
        crypto->request_passwd = request_passwd;
diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index bfdae74..3e7a2a4 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -289,7 +289,7 @@ int main (int argc, char **argv)
        if (system ("/bin/mkdir ./tmp") != 0)
                return EXIT_FAILURE;
        setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("/usr/bin/gpg --list-keys > /dev/null 2>&1") != 0)
+       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -304,7 +304,7 @@ int main (int argc, char **argv)
        
        testsuite_start ("GnuPG crypto context");
        
-       ctx = g_mime_gpg_context_new (request_passwd, "/usr/bin/gpg");
+       ctx = g_mime_gpg_context_new (request_passwd, NULL);
        g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) ctx, TRUE);
        
        testsuite_check ("GMimeGpgContext::import");
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index 546df1b..b5a8b21 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -425,7 +425,7 @@ int main (int argc, char *argv[])
        if (system ("/bin/mkdir ./tmp") != 0)
                return EXIT_FAILURE;
        setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("/usr/bin/gpg --list-keys > /dev/null 2>&1") != 0)
+       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -440,7 +440,7 @@ int main (int argc, char *argv[])
        
        testsuite_start ("PGP/MIME implementation");
        
-       ctx = g_mime_gpg_context_new (request_passwd, "/usr/bin/gpg");
+       ctx = g_mime_gpg_context_new (request_passwd, NULL);
        g_mime_gpg_context_set_always_trust ((GMimeGpgContext *) ctx, TRUE);
        
        testsuite_check ("GMimeGpgContext::import");
diff --git a/tests/test-smime.c b/tests/test-smime.c
index f4549c7..f05e03a 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -426,7 +426,7 @@ int main (int argc, char *argv[])
        if (system ("/bin/mkdir ./tmp") != 0)
                return EXIT_FAILURE;
        g_setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("/usr/bin/gpg --list-keys > /dev/null 2>&1") != 0)
+       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]