Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend /pgp command to make key exchange procedure easier #1850

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 16 additions & 35 deletions src/command/cmd_ac.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ static Autocomplete notify_chat_ac;
static Autocomplete notify_room_ac;
static Autocomplete notify_typing_ac;
static Autocomplete notify_mention_ac;
static Autocomplete notify_offline_ac;
static Autocomplete notify_trigger_ac;
static Autocomplete prefs_ac;
static Autocomplete sub_ac;
Expand Down Expand Up @@ -197,7 +196,6 @@ static Autocomplete bookmark_ignore_ac;
static Autocomplete otr_ac;
static Autocomplete otr_log_ac;
static Autocomplete otr_policy_ac;
static Autocomplete otr_sendfile_ac;
#endif
#ifdef HAVE_OMEMO
static Autocomplete omemo_ac;
Expand Down Expand Up @@ -237,7 +235,6 @@ static Autocomplete reconnect_ac;
#ifdef HAVE_LIBGPGME
static Autocomplete pgp_ac;
static Autocomplete pgp_log_ac;
static Autocomplete pgp_sendfile_ac;
static Autocomplete ox_ac;
static Autocomplete ox_log_ac;
#endif
Expand Down Expand Up @@ -293,7 +290,6 @@ static Autocomplete vcard_set_ac;
static Autocomplete vcard_name_ac;
static Autocomplete vcard_set_param_ac;
static Autocomplete vcard_togglable_param_ac;
static Autocomplete vcard_toggle_ac;
static Autocomplete vcard_address_type_ac;

static GHashTable* ac_funcs = NULL;
Expand Down Expand Up @@ -386,10 +382,6 @@ cmd_ac_init(void)
autocomplete_add(notify_mention_ac, "word_whole");
autocomplete_add(notify_mention_ac, "word_part");

notify_offline_ac = autocomplete_new();
autocomplete_add(notify_offline_ac, "on");
autocomplete_add(notify_offline_ac, "off");

notify_trigger_ac = autocomplete_new();
autocomplete_add(notify_trigger_ac, "add");
autocomplete_add(notify_trigger_ac, "remove");
Expand Down Expand Up @@ -715,10 +707,6 @@ cmd_ac_init(void)
autocomplete_add(otr_policy_ac, "manual");
autocomplete_add(otr_policy_ac, "opportunistic");
autocomplete_add(otr_policy_ac, "always");

otr_sendfile_ac = autocomplete_new();
autocomplete_add(otr_sendfile_ac, "on");
autocomplete_add(otr_sendfile_ac, "off");
#endif

#ifdef HAVE_OMEMO
Expand Down Expand Up @@ -910,16 +898,14 @@ cmd_ac_init(void)
autocomplete_add(pgp_ac, "log");
autocomplete_add(pgp_ac, "char");
autocomplete_add(pgp_ac, "sendfile");
autocomplete_add(pgp_ac, "sendpub");
autocomplete_add(pgp_ac, "autoimport");

pgp_log_ac = autocomplete_new();
autocomplete_add(pgp_log_ac, "on");
autocomplete_add(pgp_log_ac, "off");
autocomplete_add(pgp_log_ac, "redact");

pgp_sendfile_ac = autocomplete_new();
autocomplete_add(pgp_sendfile_ac, "on");
autocomplete_add(pgp_sendfile_ac, "off");

ox_ac = autocomplete_new();
autocomplete_add(ox_ac, "keys");
autocomplete_add(ox_ac, "contacts");
Expand Down Expand Up @@ -1309,10 +1295,6 @@ cmd_ac_init(void)
autocomplete_add(vcard_togglable_param_ac, "preferred");
autocomplete_add(vcard_togglable_param_ac, "x400");

vcard_toggle_ac = autocomplete_new();
autocomplete_add(vcard_toggle_ac, "on");
autocomplete_add(vcard_toggle_ac, "off");

vcard_address_type_ac = autocomplete_new();
autocomplete_add(vcard_address_type_ac, "domestic");
autocomplete_add(vcard_address_type_ac, "international");
Expand Down Expand Up @@ -1633,7 +1615,6 @@ cmd_ac_reset(ProfWin* window)
autocomplete_reset(otr_ac);
autocomplete_reset(otr_log_ac);
autocomplete_reset(otr_policy_ac);
autocomplete_reset(otr_sendfile_ac);
#endif
#ifdef HAVE_OMEMO
autocomplete_reset(omemo_ac);
Expand Down Expand Up @@ -1673,7 +1654,6 @@ cmd_ac_reset(ProfWin* window)
#ifdef HAVE_LIBGPGME
autocomplete_reset(pgp_ac);
autocomplete_reset(pgp_log_ac);
autocomplete_reset(pgp_sendfile_ac);
autocomplete_reset(ox_ac);
autocomplete_reset(ox_log_ac);
#endif
Expand Down Expand Up @@ -1723,7 +1703,6 @@ cmd_ac_reset(ProfWin* window)
autocomplete_reset(vcard_name_ac);
autocomplete_reset(vcard_set_param_ac);
autocomplete_reset(vcard_togglable_param_ac);
autocomplete_reset(vcard_toggle_ac);
autocomplete_reset(vcard_address_type_ac);

autocomplete_reset(script_ac);
Expand Down Expand Up @@ -1816,7 +1795,6 @@ cmd_ac_uninit(void)
autocomplete_free(otr_ac);
autocomplete_free(otr_log_ac);
autocomplete_free(otr_policy_ac);
autocomplete_free(otr_sendfile_ac);
#endif
#ifdef HAVE_OMEMO
autocomplete_free(omemo_ac);
Expand Down Expand Up @@ -1855,7 +1833,6 @@ cmd_ac_uninit(void)
#ifdef HAVE_LIBGPGME
autocomplete_free(pgp_ac);
autocomplete_free(pgp_log_ac);
autocomplete_free(pgp_sendfile_ac);
autocomplete_free(ox_ac);
autocomplete_free(ox_log_ac);
#endif
Expand Down Expand Up @@ -1906,7 +1883,6 @@ cmd_ac_uninit(void)
autocomplete_free(vcard_name_ac);
autocomplete_free(vcard_set_param_ac);
autocomplete_free(vcard_togglable_param_ac);
autocomplete_free(vcard_toggle_ac);
autocomplete_free(vcard_address_type_ac);
}

Expand Down Expand Up @@ -2535,7 +2511,7 @@ _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous
}

gchar* boolean_choices1[] = { "/notify room current", "/notify chat current", "/notify typing current",
"/notify room text", "/notify chat text" };
"/notify room text", "/notify chat text", "/notify room offline" };
for (int i = 0; i < ARRAY_SIZE(boolean_choices1); i++) {
result = autocomplete_param_with_func(input, boolean_choices1[i], prefs_autocomplete_boolean_choice, previous, NULL);
if (result) {
Expand All @@ -2548,11 +2524,6 @@ _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous
return result;
}

result = autocomplete_param_with_ac(input, "/notify room offline", notify_offline_ac, TRUE, previous);
if (result) {
return result;
}

result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE, previous);
if (result) {
return result;
Expand Down Expand Up @@ -2709,7 +2680,7 @@ _otr_autocomplete(ProfWin* window, const char* const input, gboolean previous)
return found;
}

found = autocomplete_param_with_ac(input, "/otr sendfile", otr_sendfile_ac, TRUE, previous);
found = autocomplete_param_with_func(input, "/otr sendfile", prefs_autocomplete_boolean_choice, previous, NULL);
if (found) {
return found;
}
Expand All @@ -2736,14 +2707,24 @@ _pgp_autocomplete(ProfWin* window, const char* const input, gboolean previous)
if (found) {
return found;
}

found = autocomplete_param_with_func(input, "/pgp sendpub", roster_contact_autocomplete, previous, NULL);
if (found) {
return found;
}
}

found = autocomplete_param_with_ac(input, "/pgp log", pgp_log_ac, TRUE, previous);
if (found) {
return found;
}

found = autocomplete_param_with_ac(input, "/pgp sendfile", pgp_sendfile_ac, TRUE, previous);
found = autocomplete_param_with_func(input, "/pgp sendfile", prefs_autocomplete_boolean_choice, previous, NULL);
if (found) {
return found;
}

found = autocomplete_param_with_func(input, "/pgp autoimport", prefs_autocomplete_boolean_choice, previous, NULL);
if (found) {
return found;
}
Expand Down Expand Up @@ -4546,7 +4527,7 @@ _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous)
} else if ((num_args == 3 && space_at_end && is_num && autocomplete_contains(vcard_togglable_param_ac, args[2])) || (num_args == 4 && !space_at_end && is_num && autocomplete_contains(vcard_togglable_param_ac, args[2]))) {
GString* beginning = g_string_new("/vcard");
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
result = autocomplete_param_with_ac(input, beginning->str, vcard_toggle_ac, TRUE, previous);
result = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice, previous, NULL);
g_string_free(beginning, TRUE);
if (result) {
return result;
Expand Down
7 changes: 5 additions & 2 deletions src/command/cmd_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,8 @@ static const struct cmd_t command_defs[] = {
"/pgp end",
"/pgp log on|off|redact",
"/pgp char <char>",
"/pgp sendfile on|off")
"/pgp sendfile on|off",
"/pgp sendpub [<contact>]")
CMD_DESC(
"Open PGP commands to manage keys, and perform PGP encryption during chat sessions. "
"See the /account command to set your own PGP key.")
Expand All @@ -1719,7 +1720,9 @@ static const struct cmd_t command_defs[] = {
{ "log on|off", "Enable or disable plaintext logging of PGP encrypted messages." },
{ "log redact", "Log PGP encrypted messages, but replace the contents with [redacted]. This is the default." },
{ "char <char>", "Set the character to be displayed next to PGP encrypted messages." },
{ "sendfile on|off", "Allow /sendfile to send unencrypted files while otherwise using PGP." })
{ "sendfile on|off", "Allow /sendfile to send unencrypted files while otherwise using PGP." },
{ "autoimport on|off", "Autoimport PGP keys from messages." },
H3rnand3zzz marked this conversation as resolved.
Show resolved Hide resolved
{ "sendpub [<contact>]", "Sends a message to the current recipient with your PGP public key, current contact will be used if not specified." })
CMD_EXAMPLES(
"/pgp log off",
"/pgp setkey odin@valhalla.edda BA19CACE5A9592C5",
Expand Down
Loading