[Pkg-gnupg-commit] [gpgme] 42/62: core: Add public function gpgme_get_ctx_flag.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Sat Nov 19 04:03:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gpgme.

commit 3234b1bf1d6939772677d64f6c1e1820ec98e3cd
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Nov 15 09:24:17 2016 +0100

    core: Add public function gpgme_get_ctx_flag.
    
    * src/gpgme.h.in (gpgme_get_ctx_flag): New.
    * src/gpgme.c (gpgme_set_ctx_flag): Move down the file and add a trace
    statement.
    (gpgme_get_ctx_flag): New.
    * src/gpgme.def, src/libgpgme.vers: Add new interface.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 NEWS              |  1 +
 doc/gpgme.texi    | 13 ++++++++
 src/gpgme.c       | 93 +++++++++++++++++++++++++++++++++++--------------------
 src/gpgme.def     |  1 +
 src/gpgme.h.in    |  3 ++
 src/libgpgme.vers |  1 +
 tests/run-tofu.c  | 22 +++++++++++++
 7 files changed, 101 insertions(+), 33 deletions(-)

diff --git a/NEWS b/NEWS
index 4bb0cfb..c194d8f 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ Noteworthy changes in version 1.7.2 (unreleased)
  gpgme_op_query_swdb             NEW.
  gpgme_op_query_swdb_result      NEW.
  gpgme_query_swdb_result_t       NEW.
+ gpgme_get_ctx_flag              NEW.
  qt: DN                          NEW.
  qt: DN::Attribute               NEW.
  qt: Job::context(Job*)          NEW.
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index 7eabab4..e47979c 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -2929,6 +2929,19 @@ This function returns @code{0} on success.
 @end deftypefun
 
 
+ at deftypefun {const char *} gpgme_get_ctx_flag  @
+            (@w{gpgme_ctx_t @var{ctx}}, @
+            @w{const char *@var{name}})
+
+The value of flags settable by @code{gpgme_set_ctx_flag} can be
+retrieved by this function.  If @var{name} is unknown the function
+returns @code{NULL}.  For boolean flags an empty string is returned
+for False and the string "1" is returned for True; either atoi(3) or a
+test for an empty string can be used to get the boolean value.
+
+ at end deftypefun
+
+
 @node Locale
 @subsection Locale
 @cindex locale, default
diff --git a/src/gpgme.c b/src/gpgme.c
index 7b14b5e..32abc28 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -85,39 +85,6 @@ gpgme_set_global_flag (const char *name, const char *value)
 }
 
 
-/* Set the flag NAME for CTX to VALUE.  The supported flags are:
- *
- * - full-status :: With a value of "1" the status callback set by
- *                  gpgme_set_status_cb returns all status lines
- *                  except for PROGRESS lines.  With the default of
- *                  "0" the status callback is only called in certain
- *                  situations.
- */
-gpgme_error_t
-gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value)
-{
-  int abool;
-
-  if (!ctx || !name || !value)
-    return gpg_error (GPG_ERR_INV_VALUE);
-
-  abool = *value? !!atoi (value) : 0;
-
-  if (!strcmp (name, "full-status"))
-    {
-      ctx->full_status = abool;
-    }
-  else if (!strcmp (name, "raw-description"))
-    {
-      ctx->raw_description = abool;
-    }
-  else
-    return gpg_error (GPG_ERR_UNKNOWN_NAME);
-
-  return 0;
-}
-
-
 

 /* Create a new context as an environment for GPGME crypto
    operations.  */
@@ -518,6 +485,66 @@ gpgme_get_armor (gpgme_ctx_t ctx)
 }
 
 
+/* Set the flag NAME for CTX to VALUE.  The supported flags are:
+ *
+ * - full-status :: With a value of "1" the status callback set by
+ *                  gpgme_set_status_cb returns all status lines
+ *                  except for PROGRESS lines.  With the default of
+ *                  "0" the status callback is only called in certain
+ *                  situations.
+ */
+gpgme_error_t
+gpgme_set_ctx_flag (gpgme_ctx_t ctx, const char *name, const char *value)
+{
+  gpgme_error_t err = 0;
+  int abool;
+
+  TRACE2 (DEBUG_CTX, "gpgme_set_ctx_flag", ctx,
+          "name='%s' value='%s'",
+	  name? name:"(null)", value?value:"(null)");
+
+  abool = (value && *value)? !!atoi (value) : 0;
+
+  if (!ctx || !name || !value)
+    err = gpg_error (GPG_ERR_INV_VALUE);
+  else if (!strcmp (name, "full-status"))
+    {
+      ctx->full_status = abool;
+    }
+  else if (!strcmp (name, "raw-description"))
+    {
+      ctx->raw_description = abool;
+    }
+  else
+    err = gpg_error (GPG_ERR_UNKNOWN_NAME);
+
+  return err;
+}
+
+
+/* Get the context flag named NAME.  See gpgme_set_ctx_flag for a list
+ * of valid names.  If the NAME is unknown NULL is returned.  For a
+ * boolean flag an empty string is returned for False and the string
+ * "1" for True; thus either atoi or a simple string test can be
+ * used. */
+const char *
+gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name)
+{
+  if (!ctx || !name)
+    return NULL;
+  else if (!strcmp (name, "full-status"))
+    {
+      return ctx->full_status? "1":"";
+    }
+  else if (!strcmp (name, "raw-description"))
+    {
+      return ctx->raw_description? "1":"";
+    }
+  else
+    return NULL;
+}
+
+
 /* Enable or disable the exporting session keys upon decryption.  */
 void
 gpgme_set_export_session_keys (gpgme_ctx_t ctx, int export_session_keys)
diff --git a/src/gpgme.def b/src/gpgme.def
index 35f4341..cd0d084 100644
--- a/src/gpgme.def
+++ b/src/gpgme.def
@@ -254,5 +254,6 @@ EXPORTS
 
     gpgme_set_export_session_keys         @191
     gpgme_get_export_session_keys         @192
+    gpgme_get_ctx_flag                    @193
 ; END
 
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 2a0e16e..43e07b0 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -999,6 +999,9 @@ void gpgme_release (gpgme_ctx_t ctx);
 gpgme_error_t gpgme_set_ctx_flag (gpgme_ctx_t ctx,
                                   const char *name, const char *value);
 
+/* Get the value of the flag NAME from CTX.  */
+const char *gpgme_get_ctx_flag (gpgme_ctx_t ctx, const char *name);
+
 /* Set the protocol to be used by CTX to PROTO.  */
 gpgme_error_t gpgme_set_protocol (gpgme_ctx_t ctx, gpgme_protocol_t proto);
 
diff --git a/src/libgpgme.vers b/src/libgpgme.vers
index 9a3ecb2..362909a 100644
--- a/src/libgpgme.vers
+++ b/src/libgpgme.vers
@@ -101,6 +101,7 @@ GPGME_1.1 {
 
     gpgme_pubkey_algo_string;
     gpgme_set_ctx_flag;
+    gpgme_get_ctx_flag;
     gpgme_data_set_flag;
 
     gpgme_op_createkey_start;
diff --git a/tests/run-tofu.c b/tests/run-tofu.c
index ff55789..9e3b117 100644
--- a/tests/run-tofu.c
+++ b/tests/run-tofu.c
@@ -99,6 +99,7 @@ main (int argc, char **argv)
   const char *fpr;
   const char *policystr = NULL;
   gpgme_tofu_policy_t policy;
+  const char *s;
 
   if (argc)
     { argc--; argv++; }
@@ -145,10 +146,31 @@ main (int argc, char **argv)
   fail_if_err (err);
   gpgme_set_protocol (ctx, protocol);
   gpgme_set_armor (ctx, 1);
+
+
+  s = gpgme_get_ctx_flag (ctx, "no_such-flag");
+  if (s)
+    {
+      fprintf (stderr, PGM ": gpgme_get_ctx_flag failed "
+               "(bad name not detected)\n");
+      exit (1);
+    }
+  s = gpgme_get_ctx_flag (ctx, "full-status");
+  if (!s || *s)
+    {
+      fprintf (stderr, PGM ": gpgme_get_ctx_flag failed (wrong false)\n");
+      exit (1);
+    }
   if (print_status)
     {
       gpgme_set_status_cb (ctx, status_cb, NULL);
       gpgme_set_ctx_flag (ctx, "full-status", "1");
+      s = gpgme_get_ctx_flag (ctx, "full-status");
+      if (!s || strcmp (s, "1"))
+        {
+          fprintf (stderr, PGM ": gpgme_get_ctx_flag fauled (wrong true)\n");
+          exit (1);
+        }
     }
 
   err = gpgme_get_key (ctx, fpr, &thekey, 0);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list