[git] GPA - branch, master, updated. gpa-0.9.10-21-g9e11986

by Werner Koch cvs at cvs.gnupg.org
Mon Oct 15 19:24:13 CEST 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Assistant".

The branch, master has been updated
       via  9e119866c02ceba8f596fa16a990b5fae562c202 (commit)
       via  f160e92d908e01d8d16e8bc1bca59e48b25746da (commit)
      from  fea939b6fe082fa2fd8276f7d59f9018e89af0fe (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9e119866c02ceba8f596fa16a990b5fae562c202
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Oct 15 16:53:52 2018 +0200

    Add diagnostic button to some error report dialogs.
    
    * src/gpgmetools.c (_gpa_gpgme_warning): Rename to _gpa_gpgme_warn and
    add arg CTX.
    * src/gpgmetools.h (gpa_gpgme_warn): New macro
    (gpa_gpgme_warning, gpa_gpgme_warning_ext): Adjust macros.
    * src/gtktools.h: Include gpacontext.h.
    * src/gtktools.c (show_gtk_message): Add arg CTX and add button to
    show details.
    (gpa_show_info): Adjust to provide NULL for new arg.
    (gpa_show_warning): Renamed to ...
    (gpa_show_warn): this and add arg CTX.  Change all callers to use new
    name and to pass NULL for CTX.
    * src/gpacontext.h (_GpaContext): Add field inhibit_gpgme_events.
    * src/gpacontext.c (gpa_context_get_diag): New.
    (gpa_context_event_cb): Inhibit events as needed.
    * src/gpafiledecryptop.c (gpa_file_decrypt_operation_done_error_cb):
    Pass the gpgme contextto gpa_show_warn or gpa_gpgme_warn.
    --
    
    We need the inhibit thingy because we use gpgme_op_getauditlog in
    synchronous mode whilst the context has also been setup for asynchronous
    mode for the real operations.  This is a peculiarity of getauditevent.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/confdialog.c b/src/confdialog.c
index 35ac05e..7f83165 100644
--- a/src/confdialog.c
+++ b/src/confdialog.c
@@ -1614,8 +1614,8 @@ gpa_configure_keyserver (GtkWidget *parent)
   keyserver = gpa_load_configured_keyserver ();
   if (!keyserver)
     {
-      gpa_show_warning
-        (parent, _("Configuring the backend to use a keyserver failed"));
+      gpa_show_warn
+        (parent, NULL, _("Configuring the backend to use a keyserver failed"));
       return NULL;
     }
   return keyserver;
diff --git a/src/gpacontext.c b/src/gpacontext.c
index b049f84..72d532f 100644
--- a/src/gpacontext.c
+++ b/src/gpacontext.c
@@ -45,7 +45,7 @@ static void gpa_context_progress (GpaContext *context, int current, int total);
 /* The GPGME I/O callbacks */
 
 static gpg_error_t gpa_context_register_cb (void *data, int fd, int dir,
-                                           gpgme_io_cb_t fnc, void *fnc_data, 
+                                           gpgme_io_cb_t fnc, void *fnc_data,
                                            void **tag);
 static void gpa_context_remove_cb (void *tag);
 static void gpa_context_event_cb (void *data, gpgme_event_io_t type,
@@ -53,7 +53,7 @@ static void gpa_context_event_cb (void *data, gpgme_event_io_t type,
 
 static gpg_error_t
 gpa_context_passphrase_cb (void *hook, const char *uid_hint,
-			   const char *passphrase_info, int prev_was_bad, 
+			   const char *passphrase_info, int prev_was_bad,
 			   int fd);
 static void
 gpa_context_progress_cb (void *opaque, const char *what,
@@ -77,7 +77,7 @@ GType
 gpa_context_get_type (void)
 {
   static GType context_type = 0;
-  
+
   if (!context_type)
     {
       static const GTypeInfo context_info =
@@ -92,12 +92,12 @@ gpa_context_get_type (void)
         0,              /* n_preallocs */
         (GInstanceInitFunc) gpa_context_init,
       };
-      
+
       context_type = g_type_register_static (G_TYPE_OBJECT,
                                              "GpaContext",
                                              &context_info, 0);
     }
-  
+
   return context_type;
 }
 
@@ -105,7 +105,7 @@ static void
 gpa_context_class_init (GpaContextClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  
+
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->finalize = gpa_context_finalize;
@@ -169,6 +169,7 @@ gpa_context_init (GpaContext *context)
   gpg_error_t err;
 
   context->busy = FALSE;
+  context->inhibit_gpgme_events = 0;
 
   /* The callback queue */
   context->cbs = NULL;
@@ -206,11 +207,11 @@ static void
 gpa_context_finalize (GObject *object)
 {
   GpaContext *context = GPA_CONTEXT (object);
-  
+
   gpgme_release (context->ctx);
   g_list_free (context->cbs);
   g_free (context->io_cbs);
-  
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -222,7 +223,7 @@ GpaContext *
 gpa_context_new (void)
 {
   GpaContext *context;
-  
+
   context = g_object_new (GPA_CONTEXT_TYPE, NULL);
 
   return context;
@@ -239,8 +240,47 @@ gpa_context_busy (GpaContext *context)
   return context->busy;
 }
 
-/* 
- * The GPGME I/O callbacks 
+
+/* Return a malloced string with the last diagnostic data of the
+ * context.  Returns NULL if no diagnostics are available.  */
+char *
+gpa_context_get_diag (GpaContext *context)
+{
+#if GPGME_VERSION_NUMBER >= 0x010c00 /* >= 1.12 */
+  gpgme_data_t diag;
+  char *buffer, *result;
+  gpg_error_t err;
+
+  if (!context)
+    return NULL;
+  if (gpgme_data_new (&diag))
+    return NULL;  /* Ooops.  */
+
+  context->inhibit_gpgme_events++;
+  err = gpgme_op_getauditlog (context->ctx, diag, GPGME_AUDITLOG_DIAG);
+  context->inhibit_gpgme_events--;
+  if (err)
+    {
+      gpgme_data_release (diag);
+      return NULL;  /* No data.  */
+    }
+
+  /* Append a trailing zero and return the string.  */
+  gpgme_data_seek (diag, 0, SEEK_END);
+  gpgme_data_write (diag, "", 1);
+  buffer = gpgme_data_release_and_get_mem (diag, NULL);
+  result = g_strdup (buffer);
+  gpgme_free (buffer);
+  return result;
+#else
+  return NULL;
+#endif
+}
+
+
+

+/*
+ * The GPGME I/O callbacks
  */
 
 /* Registering callbacks with GLib */
@@ -282,7 +322,7 @@ static void
 register_callback (struct gpa_io_cb_data *cb)
 {
   GIOChannel *channel;
- 
+
 #ifdef G_OS_WIN32
   /* We have to ask GPGME for the GIOChannel to use.  The "file
      descriptor" may not be a system file descriptor.  */
@@ -292,7 +332,7 @@ register_callback (struct gpa_io_cb_data *cb)
   channel = g_io_channel_unix_new (cb->fd);
 #endif
 
-  cb->watch = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, 
+  cb->watch = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT,
 				   cb->dir ? READ_CONDITION : WRITE_CONDITION,
 				   gpa_io_cb, cb, NULL);
   cb->registered = TRUE;
@@ -310,7 +350,7 @@ register_callback (struct gpa_io_cb_data *cb)
  */
 static void
 add_callback (GpaContext *context, struct gpa_io_cb_data *cb)
-{ 
+{
   context->cbs = g_list_append (context->cbs, cb);
 }
 
@@ -321,7 +361,7 @@ register_all_callbacks (GpaContext *context)
 {
   struct gpa_io_cb_data *cb;
   GList *list;
-  
+
   for (list = context->cbs; list; list = g_list_next (list))
     {
       cb = list->data;
@@ -337,7 +377,7 @@ unregister_all_callbacks (GpaContext *context)
 {
   struct gpa_io_cb_data *cb;
   GList *list;
-  
+
   for (list = context->cbs; list; list = g_list_next (list))
     {
       cb = list->data;
@@ -353,7 +393,7 @@ unregister_all_callbacks (GpaContext *context)
 /* The real GPGME callbacks */
 
 /* Register a callback.  This is called by GPGME when a crypto
-   operation is initiated in this context.  */ 
+   operation is initiated in this context.  */
 static gpg_error_t
 gpa_context_register_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
                          void *fnc_data, void **tag)
@@ -364,7 +404,7 @@ gpa_context_register_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
 
   cb->registered = FALSE;
   cb->fd = fd;
-  cb->dir = dir;  
+  cb->dir = dir;
   cb->fnc = fnc;
   cb->fnc_data = fnc_data;
   cb->context = context;
@@ -407,6 +447,9 @@ gpa_context_event_cb (void *data, gpgme_event_io_t type, void *type_data)
   GpaContext *context = data;
   gpg_error_t err, op_err;
 
+  if (context->inhibit_gpgme_events)
+    return;
+
   switch (type)
     {
     case GPGME_EVENT_START:
@@ -474,7 +517,7 @@ gpa_context_progress (GpaContext *context, int current, int total)
 /* The passphrase callback */
 static gpg_error_t
 gpa_context_passphrase_cb (void *hook, const char *uid_hint,
-			   const char *passphrase_info, int prev_was_bad, 
+			   const char *passphrase_info, int prev_was_bad,
 			   int fd)
 {
   GpaContext *context = hook;
@@ -493,6 +536,5 @@ gpa_context_progress_cb (void *opaque, const char *what,
 			 int type, int current, int total)
 {
   GpaContext *context = opaque;
-  g_signal_emit (context, signals[PROGRESS], 0, current, total);  
+  g_signal_emit (context, signals[PROGRESS], 0, current, total);
 }
-
diff --git a/src/gpacontext.h b/src/gpacontext.h
index 42bcfc3..0a091bb 100644
--- a/src/gpacontext.h
+++ b/src/gpacontext.h
@@ -52,6 +52,8 @@ struct _GpaContext {
   GList *cbs;
   /* The IO callback structure */
   struct gpgme_io_cbs *io_cbs;
+  /* Hack to block certain events.  */
+  int inhibit_gpgme_events;
 };
 
 struct _GpaContextClass {
@@ -77,5 +79,7 @@ GpaContext *gpa_context_new (void);
  */
 gboolean gpa_context_busy (GpaContext *context);
 
-#endif
+/* Return a string with the diagnostics from gpgme.  */
+char *gpa_context_get_diag (GpaContext *context);
 
+#endif /*GPA_CONTEXT_H*/
diff --git a/src/gpaexportserverop.c b/src/gpaexportserverop.c
index de3f781..ceae0b7 100644
--- a/src/gpaexportserverop.c
+++ b/src/gpaexportserverop.c
@@ -228,7 +228,7 @@ send_keys (GpaExportServerOperation *op, GList *keylist)
 
   if (err)
     {
-      gpa_show_warning (GPA_OPERATION (op)->window,
+      gpa_show_warn (GPA_OPERATION (op)->window, NULL,
                         "%s\n\n(%s <%s>)",
                         _("Error sending key(s) to the server."),
                         gpg_strerror (err), gpg_strsource (err));
diff --git a/src/gpafiledecryptop.c b/src/gpafiledecryptop.c
index c36da44..da8765d 100644
--- a/src/gpafiledecryptop.c
+++ b/src/gpafiledecryptop.c
@@ -502,7 +502,6 @@ gpa_file_decrypt_operation_done_error_cb (GpaContext *context, gpg_error_t err,
 					  GpaFileDecryptOperation *op)
 {
   gpa_file_item_t file_item = GPA_FILE_OPERATION (op)->current->data;
-  gchar *message;
 
   switch (gpg_err_code (err))
     {
@@ -511,33 +510,32 @@ gpa_file_decrypt_operation_done_error_cb (GpaContext *context, gpg_error_t err,
       /* Ignore these */
       break;
     case GPG_ERR_NO_DATA:
-      message = g_strdup_printf (file_item->direct_name
-				 ? _("\"%s\" contained no OpenPGP data.")
-				 : _("The file \"%s\" contained no OpenPGP"
-				     "data."),
-				 file_item->direct_name
-				 ? file_item->direct_name
-				 : file_item->filename_in);
-      gpa_window_error (message, GPA_OPERATION (op)->window);
-      g_free (message);
+      gpa_show_warn (GPA_OPERATION (op)->window, GPA_OPERATION (op)->context,
+                     file_item->direct_name
+                     ? _("\"%s\" contained no OpenPGP data.")
+                     : _("The file \"%s\" contained no OpenPGP"
+                         "data."),
+                     file_item->direct_name
+                     ? file_item->direct_name
+                     : file_item->filename_in);
       break;
     case GPG_ERR_DECRYPT_FAILED:
-      message = g_strdup_printf (file_item->direct_name
-				 ? _("\"%s\" contained no valid "
-				     "encrypted data.")
-				 : _("The file \"%s\" contained no valid "
-				     "encrypted data."),
-				 file_item->direct_name
-				 ? file_item->direct_name
-				 : file_item->filename_in);
-      gpa_window_error (message, GPA_OPERATION (op)->window);
-      g_free (message);
+      gpa_show_warn (GPA_OPERATION (op)->window, GPA_OPERATION (op)->context,
+                     file_item->direct_name
+                     ? _("\"%s\" contained no valid "
+                         "encrypted data.")
+                     : _("The file \"%s\" contained no valid "
+                         "encrypted data."),
+                     file_item->direct_name
+                     ? file_item->direct_name
+                     : file_item->filename_in);
       break;
     case GPG_ERR_BAD_PASSPHRASE:
-      gpa_window_error (_("Wrong passphrase!"), GPA_OPERATION (op)->window);
+      gpa_show_warn (GPA_OPERATION (op)->window, GPA_OPERATION (op)->context,
+                     _("Wrong passphrase!"));
       break;
     default:
-      gpa_gpgme_warning (err);
+      gpa_gpgme_warn (err, NULL, GPA_OPERATION (op)->context);
       break;
     }
 }
diff --git a/src/gpafileimportop.c b/src/gpafileimportop.c
index 4cc0dc1..bb78c3f 100644
--- a/src/gpafileimportop.c
+++ b/src/gpafileimportop.c
@@ -289,7 +289,7 @@ gpa_file_import_operation_done_error_cb (GpaContext *context, gpg_error_t err,
       break;
 
     case GPG_ERR_NO_DATA:
-      gpa_show_warning (GPA_OPERATION (op)->window,
+      gpa_show_warn (GPA_OPERATION (op)->window, NULL,
                         file_item->direct_name
                         ? _("\"%s\" contained no OpenPGP data.")
                         : _("The file \"%s\" contained no OpenPGP"
@@ -300,7 +300,7 @@ gpa_file_import_operation_done_error_cb (GpaContext *context, gpg_error_t err,
       break;
 
     default:
-      gpa_show_warning (GPA_OPERATION (op)->window,
+      gpa_show_warn (GPA_OPERATION (op)->window, NULL,
                         _("Error importing \"%s\": %s <%s>"),
                         file_item->direct_name
                         ? file_item->direct_name
diff --git a/src/gpaimportserverop.c b/src/gpaimportserverop.c
index fb3e0b9..7e347a2 100644
--- a/src/gpaimportserverop.c
+++ b/src/gpaimportserverop.c
@@ -166,7 +166,7 @@ search_keys (GpaImportOperation *operation, const char *keyid)
     {
       if (nkeys >= MAX_KEYSEARCH_RESULTS)
         {
-          gpa_show_warning (GPA_OPERATION (operation)->window,
+          gpa_show_warn (GPA_OPERATION (operation)->window, NULL,
                             _("More than %d keys match your search pattern.\n"
                               "Use the long keyid or a fingerprint "
                               "for a better match"), nkeys);
@@ -182,7 +182,7 @@ search_keys (GpaImportOperation *operation, const char *keyid)
 
   if (!err && !nkeys)
     {
-      gpa_show_warning (GPA_OPERATION (operation)->window,
+      gpa_show_warn (GPA_OPERATION (operation)->window, NULL,
                         _("No keys were found."));
     }
   else if (!err)
diff --git a/src/gpgmetools.c b/src/gpgmetools.c
index 2dfd741..e2631ff 100644
--- a/src/gpgmetools.c
+++ b/src/gpgmetools.c
@@ -81,14 +81,13 @@ _gpa_gpgme_error (gpg_error_t err, const char *file, int line)
 }
 
 
-/* (Please use the gpa_gpgme_warning macros).  */
+/* (Please use the gpa_gpgme_warn macros).  */
 void
-_gpa_gpgme_warning (gpg_error_t err, const char *desc,
-                    const char *file, int line)
+_gpa_gpgme_warn (gpg_error_t err, const char *desc, GpaContext *ctx,
+                 const char *file, int line)
 {
   char *argbuf = NULL;
   const char *arg;
-  char *message;
 
   if (desc && (!err || gpg_err_code (err) == GPG_ERR_GENERAL))
     arg = desc;
@@ -100,16 +99,14 @@ _gpa_gpgme_warning (gpg_error_t err, const char *desc,
   else
     arg = gpgme_strerror (err);
 
-  message = g_strdup_printf
-    (_("The GPGME library returned an unexpected\n"
-       "error at %s:%d. The error was:\n\n"
-       "\t%s\n\n"
-       "This is either an installation problem or a bug in %s.\n"
-       "%s will now try to recover from this error."),
-     strip_path (file), line, arg, GPA_NAME, GPA_NAME);
+  gpa_show_warn (NULL, ctx,
+                 _("The GPGME library returned an unexpected\n"
+                   "error at %s:%d. The error was:\n\n"
+                   "\t%s\n\n"
+                   "This is either an installation problem or a bug in %s.\n"
+                   "%s will now try to recover from this error."),
+                 strip_path (file), line, arg, GPA_NAME, GPA_NAME);
   g_free (argbuf);
-  gpa_window_error (message, NULL);
-  g_free (message);
 }
 
 
@@ -1310,7 +1307,7 @@ gpa_gpgme_show_import_results (GtkWidget *parent, gpa_import_result_t result)
 
 
   if (!result->considered)
-    gpa_show_warning (parent, "%s%s%s",
+    gpa_show_warn (parent, NULL, "%s%s%s",
                       _("No keys were found."),
                       buf2? "\n":"",
                       buf2? buf2:"");
diff --git a/src/gpgmetools.h b/src/gpgmetools.h
index dc39839..95ab4d5 100644
--- a/src/gpgmetools.h
+++ b/src/gpgmetools.h
@@ -27,6 +27,8 @@
 #include <gtk/gtk.h>
 #include <gpgme.h>
 
+#include "gpacontext.h"
+
 /* Internal algorithm identifiers, describing which keys to
    create.  */
 typedef enum
@@ -96,12 +98,14 @@ void _gpa_gpgme_error (gpg_error_t err,
                        const char *file, int line) G_GNUC_NORETURN;
 
 /* The same as gpa_gpgme_error, without quitting.  */
+#define gpa_gpgme_warn(err,desc,ctx)                                       \
+  do { _gpa_gpgme_warn (err, desc, ctx, __FILE__, __LINE__); } while (0)
 #define gpa_gpgme_warning_ext(err,desc) \
-         do { _gpa_gpgme_warning (err, desc, __FILE__, __LINE__); } while (0)
+  do { _gpa_gpgme_warn (err, desc, NULL, __FILE__, __LINE__); } while (0)
 #define gpa_gpgme_warning(err) \
-         do { _gpa_gpgme_warning (err, NULL, __FILE__, __LINE__); } while (0)
-void _gpa_gpgme_warning (gpg_error_t err, const char *desc,
-                         const char *file, int line);
+  do { _gpa_gpgme_warn (err, NULL, NULL, __FILE__, __LINE__); } while (0)
+void _gpa_gpgme_warn (gpg_error_t err, const char *desc, GpaContext *ctx,
+                      const char *file, int line);
 
 /* Initialize a gpgme_ctx_t for use with GPA.  */
 gpgme_ctx_t gpa_gpgme_new (void);
diff --git a/src/gtktools.c b/src/gtktools.c
index 8bf2867..b0f9ba8 100644
--- a/src/gtktools.c
+++ b/src/gtktools.c
@@ -34,12 +34,11 @@
 #include "gpawindowkeeper.h"
 #include "icons.h"
 
-
 /* Deprecated - use gpa_show_warning instead.  */
 void
 gpa_window_error (const gchar *message, GtkWidget *messenger)
 {
-  gpa_show_warning (messenger, "%s", message);
+  gpa_show_warn (messenger, NULL, "%s", message);
 }
 
 
@@ -52,7 +51,7 @@ gpa_window_message (const gchar *message, GtkWidget * messenger)
 
 
 static void
-show_gtk_message (GtkWidget *parent, GtkMessageType mtype,
+show_gtk_message (GtkWidget *parent, GtkMessageType mtype, GpaContext *ctx,
                   const char *format, va_list arg_ptr)
 {
   GtkWidget *dialog;
@@ -65,9 +64,26 @@ show_gtk_message (GtkWidget *parent, GtkMessageType mtype,
                                    GTK_BUTTONS_CLOSE,
                                    "%s", buffer);
   g_free (buffer);
+  buffer = NULL;
+  if (ctx)
+    gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                            _("_Details"), GTK_RESPONSE_HELP,
+                            NULL);
 
   gtk_widget_show_all (dialog);
-  gtk_dialog_run (GTK_DIALOG (dialog));
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_HELP && ctx)
+    {
+      /* If requested and possible get diagnostics from GPGME.  */
+      buffer = gpa_context_get_diag (ctx);
+      if (!buffer)
+        gpa_show_info (parent, "No diagnostic data available");
+      else
+        {
+          gpa_show_info (parent, "Diagnostics:\n%s", buffer);
+          g_free (buffer);
+        }
+    }
+
   gtk_widget_destroy (dialog);
 }
 
@@ -79,19 +95,21 @@ gpa_show_info (GtkWidget *parent, const char *format, ...)
   va_list arg_ptr;
 
   va_start (arg_ptr, format);
-  show_gtk_message (parent, GTK_MESSAGE_INFO, format, arg_ptr);
+  show_gtk_message (parent, GTK_MESSAGE_INFO, NULL, format, arg_ptr);
   va_end (arg_ptr);
 }
 
 
-/* Show a modal warning message. */
+/* Show a modal warning message.  PARENT is the parent windows, CTX is
+ * eitehr NULL or a related GPGME context to be used to allow shoing
+ * additional information. */
 void
-gpa_show_warning (GtkWidget *parent, const char *format, ...)
+gpa_show_warn (GtkWidget *parent, GpaContext *ctx, const char *format, ...)
 {
   va_list arg_ptr;
 
   va_start (arg_ptr, format);
-  show_gtk_message (parent, GTK_MESSAGE_WARNING, format, arg_ptr);
+  show_gtk_message (parent, GTK_MESSAGE_WARNING, ctx, format, arg_ptr);
   va_end (arg_ptr);
 }
 
diff --git a/src/gtktools.h b/src/gtktools.h
index 41fafc5..ce9a969 100644
--- a/src/gtktools.h
+++ b/src/gtktools.h
@@ -21,15 +21,18 @@
 #ifndef GTK_TOOLS_H_
 #define GTK_TOOLS_H_
 
+#include <gpgme.h>
 #include <gtk/gtk.h>
 
+#include "gpacontext.h"
+
 
 /* Show a modal info message. */
 void gpa_show_info (GtkWidget *parent,
                     const char *format, ...) G_GNUC_PRINTF(2,3);
 /* Show a modal warning message. */
-void gpa_show_warning (GtkWidget *parent,
-                       const char *format, ...) G_GNUC_PRINTF(2,3);
+void gpa_show_warn (GtkWidget *parent, GpaContext *ctx,
+                    const char *format, ...) G_GNUC_PRINTF(3,4);
 
 /* Set a tooltip TEXT to WIDGET.  TEXT and WIDGET may both be NULL.
    This function is useful so that GPA can be build with older GTK+

commit f160e92d908e01d8d16e8bc1bca59e48b25746da
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Oct 15 14:47:25 2018 +0200

    Let Server->Retrieve_Key use --locate-key for a mail address.
    
    * src/gpaimportserverop.c (search_keys): Detect mbox style keyids and
    use --locate-key.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/gpaimportserverop.c b/src/gpaimportserverop.c
index fe383a3..fb3e0b9 100644
--- a/src/gpaimportserverop.c
+++ b/src/gpaimportserverop.c
@@ -128,6 +128,8 @@ search_keys (GpaImportOperation *operation, const char *keyid)
   gpgme_key_t key;
   gpgme_key_t *keyarray;
   int i, nkeys;
+  gpgme_keylist_mode_t listmode;
+  char *mbox = NULL;
 
   if (!keyid || !*keyid)
     return FALSE;
@@ -139,8 +141,20 @@ search_keys (GpaImportOperation *operation, const char *keyid)
      actual import operation done later.  */
   ctx = gpa_gpgme_new ();
   gpgme_set_protocol (ctx, GPGME_PROTOCOL_OpenPGP);
-  /* Switch to extern-only list mode.  */
-  err = gpgme_set_keylist_mode (ctx, GPGME_KEYLIST_MODE_EXTERN);
+  /* Switch to extern-only or locate list mode.  We use --locate-key
+   * iff KEYID is a single mail address.  */
+  listmode = GPGME_KEYLIST_MODE_EXTERN;
+#if GPGME_VERSION_NUMBER >= 0x010701
+  mbox = gpgme_addrspec_from_uid (keyid);
+  if (mbox)
+    {
+      listmode = GPGME_KEYLIST_MODE_LOCATE;
+      /* We already extracted the mbox - use it directly than letting
+       * gnupg extract it.  */
+      keyid = mbox;
+    }
+#endif /* GPGME >= 1.7.1 */
+  err = gpgme_set_keylist_mode (ctx, listmode);
   if (err)
     gpa_gpgme_error (err);
 
@@ -187,6 +201,8 @@ search_keys (GpaImportOperation *operation, const char *keyid)
         gpgme_key_unref (keyarray[i]);
       g_free (keyarray);
     }
+
+  gpgme_free (mbox);
   return result;
 }
 

-----------------------------------------------------------------------

Summary of changes:
 src/confdialog.c        |  4 +--
 src/gpacontext.c        | 84 ++++++++++++++++++++++++++++++++++++-------------
 src/gpacontext.h        |  6 +++-
 src/gpaexportserverop.c |  2 +-
 src/gpafiledecryptop.c  | 42 ++++++++++++-------------
 src/gpafileimportop.c   |  4 +--
 src/gpaimportserverop.c | 24 +++++++++++---
 src/gpgmetools.c        | 25 +++++++--------
 src/gpgmetools.h        | 12 ++++---
 src/gtktools.c          | 34 +++++++++++++++-----
 src/gtktools.h          |  7 +++--
 11 files changed, 163 insertions(+), 81 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Assistant
http://git.gnupg.org




More information about the Gnupg-commits mailing list