diff options
| -rw-r--r-- | NEWS | 1 | ||||
| -rw-r--r-- | doc/gpgme.texi | 13 | ||||
| -rw-r--r-- | src/gpgme.c | 93 | ||||
| -rw-r--r-- | src/gpgme.def | 1 | ||||
| -rw-r--r-- | src/gpgme.h.in | 3 | ||||
| -rw-r--r-- | src/libgpgme.vers | 1 | ||||
| -rw-r--r-- | tests/run-tofu.c | 22 | 
7 files changed, 101 insertions, 33 deletions
| @@ -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 7eabab48..e47979c5 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -2929,6 +2929,19 @@ This function returns @code{0} on success.  @end deftypefun +@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. + +@end deftypefun + +  @node Locale  @subsection Locale  @cindex locale, default diff --git a/src/gpgme.c b/src/gpgme.c index 7b14b5e9..32abc282 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 35f43411..cd0d0848 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 2a0e16e3..43e07b06 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 9a3ecb2e..362909ae 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 ff557893..9e3b1172 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); | 
