about summary refs log tree commit diff stats
path: root/src/command/commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/command/commands.c')
-rw-r--r--src/command/commands.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 35e424b9..5f24d33e 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("");
@@ -4070,6 +4081,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