about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c24
-rw-r--r--src/command/commands.c71
-rw-r--r--src/command/commands.h1
3 files changed, 94 insertions, 2 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 00223b29..840a23e5 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -860,6 +860,16 @@ static struct cmd_t command_defs[] =
           "Send chat state notifications during chat sessions.",
           NULL } } },
 
+    { "/pgp",
+        cmd_pgp, parse_args, 1, 1, NULL,
+        { "/pgp keys|libver", "Open PGP.",
+        { "/pgp keys|libver",
+          "----------------",
+          "Open PGP.",
+          "keys   : List private keys."
+          "libver : Show which version of the libgpgme library is being used.",
+          NULL } } },
+
     { "/otr",
         cmd_otr, parse_args, 1, 3, NULL,
         { "/otr command [args..]", "Off The Record encryption commands.",
@@ -1215,6 +1225,7 @@ static Autocomplete time_statusbar_ac;
 static Autocomplete resource_ac;
 static Autocomplete inpblock_ac;
 static Autocomplete receipts_ac;
+static Autocomplete pgp_ac;
 
 /*
  * Initialise command autocompleter and history
@@ -1371,6 +1382,7 @@ cmd_init(void)
     autocomplete_add(account_set_ac, "muc");
     autocomplete_add(account_set_ac, "nick");
     autocomplete_add(account_set_ac, "otr");
+    autocomplete_add(account_set_ac, "pgpkeyid");
 
     account_clear_ac = autocomplete_new();
     autocomplete_add(account_clear_ac, "password");
@@ -1378,6 +1390,7 @@ cmd_init(void)
     autocomplete_add(account_clear_ac, "server");
     autocomplete_add(account_clear_ac, "port");
     autocomplete_add(account_clear_ac, "otr");
+    autocomplete_add(account_clear_ac, "pgpkeyid");
 
     account_default_ac = autocomplete_new();
     autocomplete_add(account_default_ac, "set");
@@ -1579,6 +1592,11 @@ cmd_init(void)
     receipts_ac = autocomplete_new();
     autocomplete_add(receipts_ac, "send");
     autocomplete_add(receipts_ac, "request");
+
+    pgp_ac = autocomplete_new();
+    autocomplete_add(pgp_ac, "keys");
+    autocomplete_add(pgp_ac, "fps");
+    autocomplete_add(pgp_ac, "libver");
 }
 
 void
@@ -1638,6 +1656,7 @@ cmd_uninit(void)
     autocomplete_free(resource_ac);
     autocomplete_free(inpblock_ac);
     autocomplete_free(receipts_ac);
+    autocomplete_free(pgp_ac);
 }
 
 gboolean
@@ -1810,6 +1829,7 @@ cmd_reset_autocomplete()
     autocomplete_reset(resource_ac);
     autocomplete_reset(inpblock_ac);
     autocomplete_reset(receipts_ac);
+    autocomplete_reset(pgp_ac);
 
     if (ui_current_win_type() == WIN_CHAT) {
         ProfChatWin *chatwin = wins_get_current_chat();
@@ -1993,8 +2013,8 @@ _cmd_complete_parameters(const char * const input)
         }
     }
 
-    gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room" };
-    Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac };
+    gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room", "/pgp" };
+    Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac, pgp_ac };
 
     for (i = 0; i < ARRAY_SIZE(cmds); i++) {
         result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE);
diff --git a/src/command/commands.c b/src/command/commands.c
index 6ae4cf91..854d2061 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -57,6 +57,9 @@
 #ifdef HAVE_LIBOTR
 #include "otr/otr.h"
 #endif
+#ifdef HAVE_LIBGPGME
+#include "pgp/gpg.h"
+#endif
 #include "profanity.h"
 #include "tools/autocomplete.h"
 #include "tools/parser.h"
@@ -475,6 +478,10 @@ cmd_account(gchar **args, struct cmd_help_t help)
                         cons_show("Updated login status for account %s: %s", account_name, value);
                     }
                     cons_show("");
+                } else if (strcmp(property, "pgpkeyid") == 0) {
+                    accounts_set_pgp_keyid(account_name, value);
+                    cons_show("Updated PGP key ID for account %s: %s", account_name, value);
+                    cons_show("");
                 } else if (valid_resource_presence_string(property)) {
                     int intval;
                     char *err_msg = NULL;
@@ -553,6 +560,10 @@ cmd_account(gchar **args, struct cmd_help_t help)
                     accounts_clear_otr(account_name);
                     cons_show("OTR policy removed for account %s", account_name);
                     cons_show("");
+                } else if (strcmp(property, "pgpkeyid") == 0) {
+                    accounts_clear_pgp_keyid(account_name);
+                    cons_show("Removed PGP key ID for account %s", account_name);
+                    cons_show("");
                 } else {
                     cons_show("Invalid property: %s", property);
                     cons_show("");
@@ -4110,6 +4121,66 @@ cmd_xa(gchar **args, struct cmd_help_t help)
 }
 
 gboolean
+cmd_pgp(gchar **args, struct cmd_help_t help)
+{
+#ifdef HAVE_LIBGPGME
+    if (g_strcmp0(args[0], "keys") == 0) {
+        GSList *keys = p_gpg_list_keys();
+        if (keys) {
+            cons_show("PGP keys:");
+            while (keys) {
+                ProfPGPKey *key = keys->data;
+                cons_show("  %s", key->name);
+                cons_show("    ID          : %s", key->id);
+                cons_show("    Fingerprint : %s", key->fp);
+                keys = g_slist_next(keys);
+            }
+        } else {
+            cons_show("No keys found");
+        }
+        g_slist_free_full(keys, (GDestroyNotify)p_gpg_free_key);
+    } else if (g_strcmp0(args[0], "fps") == 0) {
+        jabber_conn_status_t conn_status = jabber_get_connection_status();
+        if (conn_status != JABBER_CONNECTED) {
+            cons_show("You are not currently connected.");
+        } else {
+            GHashTable *fingerprints = p_gpg_fingerprints();
+            GList *jids = g_hash_table_get_keys(fingerprints);
+            if (jids) {
+                cons_show("Received PGP fingerprints:");
+                GList *curr = jids;
+                while (curr) {
+                    char *jid = curr->data;
+                    char *fingerprint = g_hash_table_lookup(fingerprints, jid);
+                    cons_show("  %s: %s", jid, fingerprint);
+                    curr = g_list_next(curr);
+                }
+            } else {
+                cons_show("No PGP fingerprints received.");
+            }
+            g_list_free(jids);
+        }
+    } else if (g_strcmp0(args[0], "libver") == 0) {
+        const char *libver = p_gpg_libver();
+        if (libver) {
+            GString *fullstr = g_string_new("Using libgpgme version ");
+            g_string_append(fullstr, libver);
+            cons_show("%s", fullstr->str);
+            g_string_free(fullstr, TRUE);
+        } else {
+            cons_show("Could not get libgpgme version");
+        }
+    }
+
+    return TRUE;
+#else
+    cons_show("This version of Profanity has not been built with PGP support enabled");
+    return TRUE;
+#endif
+
+}
+
+gboolean
 cmd_otr(gchar **args, struct cmd_help_t help)
 {
 #ifdef HAVE_LIBOTR
diff --git a/src/command/commands.h b/src/command/commands.h
index fb5372a6..8a75c03d 100644
--- a/src/command/commands.h
+++ b/src/command/commands.h
@@ -103,6 +103,7 @@ gboolean cmd_nick(gchar **args, struct cmd_help_t help);
 gboolean cmd_notify(gchar **args, struct cmd_help_t help);
 gboolean cmd_online(gchar **args, struct cmd_help_t help);
 gboolean cmd_otr(gchar **args, struct cmd_help_t help);
+gboolean cmd_pgp(gchar **args, struct cmd_help_t help);
 gboolean cmd_outtype(gchar **args, struct cmd_help_t help);
 gboolean cmd_prefs(gchar **args, struct cmd_help_t help);
 gboolean cmd_priority(gchar **args, struct cmd_help_t help);