aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-06-23 23:29:10 +0100
committerJames Booth <boothj5@gmail.com>2015-06-23 23:29:10 +0100
commit358e9d6af0677354fa70fa089124de07d8423eb7 (patch)
tree71554c57d40f5267307e0b815bd50be6b397400c /src/command
parent2d3537515d9b0dbba51265ed7819dd80b31a33d8 (diff)
downloadprofani-tty-358e9d6af0677354fa70fa089124de07d8423eb7.tar.gz
Added /pgp setkey command
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c21
-rw-r--r--src/command/commands.c37
2 files changed, 49 insertions, 9 deletions
diff --git a/src/command/command.c b/src/command/command.c
index c43e968e..dd160adc 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -869,18 +869,19 @@ static struct cmd_t command_defs[] =
NULL } } },
{ "/pgp",
- cmd_pgp, parse_args, 1, 2, NULL,
+ cmd_pgp, parse_args, 1, 3, NULL,
{ "/pgp command [args..]", "Open PGP commands.",
{ "/pgp command [args..]",
"---------------------",
"Open PGP commands.",
"",
- "keys : List private keys.",
- "libver : Show which version of the libgpgme library is being used.",
- "fps : Show received fingerprints.",
- "start [contact] : Start PGP encrypted chat, current contact will be used if not specified.",
- "end : End PGP encrypted chat with the current recipient.",
- "log on|off|redact : PGP message logging, default: redact.",
+ "keys : List all keys.",
+ "libver : Show which version of the libgpgme library is being used.",
+ "fps : Show known fingerprints.",
+ "setkey contact keyid : Manually associate a key ID with a JID.",
+ "start [contact] : Start PGP encrypted chat, current contact will be used if not specified.",
+ "end : End PGP encrypted chat with the current recipient.",
+ "log on|off|redact : PGP message logging, default: redact.",
NULL } } },
{ "/otr",
@@ -1611,6 +1612,7 @@ cmd_init(void)
pgp_ac = autocomplete_new();
autocomplete_add(pgp_ac, "keys");
autocomplete_add(pgp_ac, "fps");
+ autocomplete_add(pgp_ac, "setkey");
autocomplete_add(pgp_ac, "libver");
autocomplete_add(pgp_ac, "start");
autocomplete_add(pgp_ac, "end");
@@ -2503,6 +2505,11 @@ _pgp_autocomplete(ProfWin *window, const char * const input)
return found;
}
+ found = autocomplete_param_with_func(input, "/pgp setkey", roster_barejid_autocomplete);
+ if (found) {
+ return found;
+ }
+
found = autocomplete_param_with_ac(input, "/pgp", pgp_ac, TRUE);
if (found) {
return found;
diff --git a/src/command/commands.c b/src/command/commands.c
index f865b873..65fdeb98 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -680,6 +680,9 @@ cmd_disconnect(ProfWin *window, gchar **args, struct cmd_help_t help)
muc_invites_clear();
chat_sessions_clear();
ui_disconnected();
+#ifdef HAVE_LIBGPGME
+ p_gpg_on_disconnect();
+#endif
free(jid);
} else {
cons_show("You are not currently connected.");
@@ -4192,6 +4195,35 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
+ if (g_strcmp0(args[0], "setkey") == 0) {
+ jabber_conn_status_t conn_status = jabber_get_connection_status();
+ if (conn_status != JABBER_CONNECTED) {
+ cons_show("You are not currently connected.");
+ return TRUE;
+ }
+
+ char *jid = args[1];
+ if (!args[1]) {
+ cons_show("Usage: %s", help.usage);
+ return TRUE;
+ }
+
+ char *keyid = args[2];
+ if (!args[2]) {
+ cons_show("Usage: %s", help.usage);
+ return TRUE;
+ }
+
+ gboolean res = p_gpg_addkey(jid, keyid);
+ if (!res) {
+ cons_show("Key ID not found.");
+ } else {
+ cons_show("Key %s set for %s.", keyid, jid);
+ }
+
+ return TRUE;
+ }
+
if (g_strcmp0(args[0], "fps") == 0) {
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status != JABBER_CONNECTED) {
@@ -4201,11 +4233,11 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help)
GHashTable *fingerprints = p_gpg_fingerprints();
GList *jids = g_hash_table_get_keys(fingerprints);
if (!jids) {
- cons_show("No PGP fingerprints received.");
+ cons_show("No PGP fingerprints available.");
return TRUE;
}
- cons_show("Received PGP fingerprints:");
+ cons_show("Known PGP fingerprints:");
GList *curr = jids;
while (curr) {
char *jid = curr->data;
@@ -4314,6 +4346,7 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
+ cons_show("Usage: %s", help.usage);
return TRUE;
#else
cons_show("This version of Profanity has not been built with PGP support enabled");