[seahorse-plugins] Bug 586855 - seahorse-agent does not work with gnupg-2.0.12



commit 3c4cbf986cee18016b958634e47beacb2748b567
Author: Peter Bloomfield <peterbloomfield bellsouth net>
Date:   Sun Oct 4 17:15:45 2009 -0400

    Bug 586855 - seahorse-agent does not work with gnupg-2.0.12
    
    Patch from Peter Bloomfield to add the get-info command to
    seahorse-agent

 agent/seahorse-agent-io.c     |   83 ++++++++++++++++++++++++++++++++++++++++-
 agent/seahorse-agent-prompt.c |    9 +++-
 agent/seahorse-agent.h        |    1 +
 3 files changed, 90 insertions(+), 3 deletions(-)
---
diff --git a/agent/seahorse-agent-io.c b/agent/seahorse-agent-io.c
index 11f2a3c..ffb9417 100644
--- a/agent/seahorse-agent-io.c
+++ b/agent/seahorse-agent-io.c
@@ -93,12 +93,14 @@ struct _SeahorseAgentConn {
 #define ASS_OPTION  "OPTION"
 #define ASS_GETPASS "GET_PASSPHRASE"
 #define ASS_CLRPASS "CLEAR_PASSPHRASE"
+#define ASS_GETINFO "GETINFO"
 
 #define ASS_OPT_DISPLAY "display="
 
 /* Options */
 #define ASS_FLAG_DATA   "data"
 #define ASS_FLAG_CHECK  "check"
+#define ASS_FLAG_REPEAT "repeat"
 
 /* Responses */
 #define ASS_OK      "OK "
@@ -269,8 +271,21 @@ static guint32
 parse_assuan_flag (gchar *flag)
 {
     g_assert (flag);
-    if (g_str_equal (flag, "data"))
+    if (g_str_equal (flag, ASS_FLAG_DATA))
         return SEAHORSE_AGENT_PASS_AS_DATA;
+    else if (g_str_has_prefix (flag, ASS_FLAG_REPEAT)) {
+        gint count = 1;
+
+        flag += strlen(ASS_FLAG_REPEAT);
+        if (*flag == '=') {
+            count = atoi (++flag);
+            if (!(count == 0 || count == 1))
+                g_warning ("--repeat=%d treated as --repeat=1", count);
+        }
+
+        if (count)
+            return SEAHORSE_AGENT_REPEAT;
+    }
     return 0;
 }
 
@@ -373,6 +388,68 @@ x11_displays_eq (const gchar *d1, const gchar *d2)
     return (g_ascii_strncasecmp (d1, d2, l1 > l2 ? l1 : l2) == 0);
 }
 
+/* Does command have option? */
+static gboolean
+command_has_option (SeahorseAgentConn *cn, gchar * command, gchar * option)
+{
+    gboolean has_option = FALSE;
+
+    if (!strcmp (command, ASS_GETPASS)) {
+        has_option = (!strcmp (option, ASS_FLAG_DATA) ||
+                      !strcmp (option, ASS_FLAG_REPEAT));
+    }
+    /* else if (other commands) */
+
+    if (has_option)
+        seahorse_agent_io_reply (cn, TRUE, NULL);
+
+    return has_option;
+}
+
+/* Process a GETINFO request */
+static void
+ass_getinfo (SeahorseAgentConn *cn, gchar * request)
+{
+    gchar *args;
+    gboolean implemented = FALSE;
+
+    args = strchr (request, ' ');
+    if (args) {
+        *args = 0;
+        args++;
+        while (isspace (*args))
+            args++;
+    }
+
+    if (!strcmp (request, "cmd_has_option")) {
+        gchar *command = args;
+        gchar *option;
+
+        if (!command || !*command) {
+            seahorse_agent_io_reply (cn, FALSE, "105 parameter error");
+            return;
+        }
+
+        option = strchr(args, ' ');
+
+        if (option) {
+            *option = 0;
+            option++;
+            while (isspace (*option))
+                option++;
+        } else {
+            seahorse_agent_io_reply (cn, FALSE, "105 parameter error");
+            return;
+        }
+
+        implemented = command_has_option(cn, command, option);
+    }
+    /* else if (other info request) */
+
+    if (!implemented)
+        seahorse_agent_io_reply (cn, FALSE, "100 not implemented");
+}
+
 /* Process a request line from client */
 static void
 process_line (SeahorseAgentConn *cn, gchar *string)
@@ -484,6 +561,10 @@ process_line (SeahorseAgentConn *cn, gchar *string)
         seahorse_agent_actions_clrpass (cn, id);
     }
 
+    else if (strcasecmp (string, ASS_GETINFO) == 0) {
+        ass_getinfo (cn, args);
+    }
+
     else if (strcasecmp (string, ASS_NOP) == 0) {
         seahorse_agent_io_reply (cn, TRUE, NULL);
     }
diff --git a/agent/seahorse-agent-prompt.c b/agent/seahorse-agent-prompt.c
index e897464..b69b773 100644
--- a/agent/seahorse-agent-prompt.c
+++ b/agent/seahorse-agent-prompt.c
@@ -155,8 +155,13 @@ seahorse_agent_prompt_pass (SeahorseAgentPassReq *pr)
 
     g_return_if_fail (!seahorse_agent_prompt_have ());
     
-    dialog = seahorse_passphrase_prompt_show (NULL, pr->errmsg ? pr->errmsg : pr->description, 
-                                              pr->prompt, NULL, FALSE);
+    dialog =
+        seahorse_passphrase_prompt_show (NULL,
+                                         (pr->errmsg ?
+                                          pr->errmsg : pr->description),
+                                         pr->prompt, NULL,
+                                         pr->flags & SEAHORSE_AGENT_REPEAT);
+
     g_signal_connect (dialog, "response", G_CALLBACK (passphrase_response), pr);
     g_current_win = GTK_WIDGET (dialog);
 }
diff --git a/agent/seahorse-agent.h b/agent/seahorse-agent.h
index 92267a9..0be3209 100644
--- a/agent/seahorse-agent.h
+++ b/agent/seahorse-agent.h
@@ -81,6 +81,7 @@ void seahorse_agent_io_data (SeahorseAgentConn *cn, const gchar *data);
  */
 
 #define SEAHORSE_AGENT_PASS_AS_DATA    0x00000001
+#define SEAHORSE_AGENT_REPEAT          0x00000002
 
 typedef struct _SeahorseAgentPassReq {
     const gchar *id;



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