diff options
author | James Booth <boothj5@gmail.com> | 2015-06-20 23:49:24 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-06-20 23:49:24 +0100 |
commit | 6617bb5a2b432d9c4178984386855f30be76ecf3 (patch) | |
tree | 2ff69c01e8d01013e377cec841317becd3d3267a /src/command | |
parent | 16999a396497c90778ef6bdbab11a419a570aa0f (diff) | |
download | profani-tty-6617bb5a2b432d9c4178984386855f30be76ecf3.tar.gz |
Added window encyption mode for PGP
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/command.c | 39 | ||||
-rw-r--r-- | src/command/commands.c | 139 |
2 files changed, 133 insertions, 45 deletions
diff --git a/src/command/command.c b/src/command/command.c index fbb9f29d..5e38a7be 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -83,6 +83,7 @@ static char * _roster_autocomplete(ProfWin *window, const char * const input); static char * _group_autocomplete(ProfWin *window, const char * const input); static char * _bookmark_autocomplete(ProfWin *window, const char * const input); static char * _otr_autocomplete(ProfWin *window, const char * const input); +static char * _pgp_autocomplete(ProfWin *window, const char * const input); static char * _connect_autocomplete(ProfWin *window, const char * const input); static char * _statuses_autocomplete(ProfWin *window, const char * const input); static char * _alias_autocomplete(ProfWin *window, const char * const input); @@ -860,13 +861,15 @@ static struct cmd_t command_defs[] = NULL } } }, { "/pgp", - cmd_pgp, parse_args, 1, 1, NULL, - { "/pgp keys|libver", "Open PGP.", - { "/pgp keys|libver", - "----------------", + cmd_pgp, parse_args, 1, 3, NULL, + { "/pgp keys|libver|fps|start [contact]", "Open PGP.", + { "/pgp keys|libver|fps|start [contact]", + "------------------------------------", "Open PGP.", - "keys : List private keys." - "libver : Show which version of the libgpgme library is being used.", + "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.", NULL } } }, { "/otr", @@ -1597,6 +1600,7 @@ cmd_init(void) autocomplete_add(pgp_ac, "keys"); autocomplete_add(pgp_ac, "fps"); autocomplete_add(pgp_ac, "libver"); + autocomplete_add(pgp_ac, "start"); } void @@ -2017,8 +2021,8 @@ _cmd_complete_parameters(ProfWin *window, const char * const input) } } - 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 }; + 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 }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE); @@ -2040,6 +2044,7 @@ _cmd_complete_parameters(ProfWin *window, const char * const input) g_hash_table_insert(ac_funcs, "/bookmark", _bookmark_autocomplete); g_hash_table_insert(ac_funcs, "/autoconnect", _autoconnect_autocomplete); g_hash_table_insert(ac_funcs, "/otr", _otr_autocomplete); + g_hash_table_insert(ac_funcs, "/pgp", _pgp_autocomplete); g_hash_table_insert(ac_funcs, "/connect", _connect_autocomplete); g_hash_table_insert(ac_funcs, "/statuses", _statuses_autocomplete); g_hash_table_insert(ac_funcs, "/alias", _alias_autocomplete); @@ -2469,6 +2474,24 @@ _otr_autocomplete(ProfWin *window, const char * const input) } static char * +_pgp_autocomplete(ProfWin *window, const char * const input) +{ + char *found = NULL; + + found = autocomplete_param_with_func(input, "/pgp start", roster_contact_autocomplete); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/pgp", pgp_ac, TRUE); + if (found) { + return found; + } + + return NULL; +} + +static char * _theme_autocomplete(ProfWin *window, const char * const input) { char *result = NULL; diff --git a/src/command/commands.c b/src/command/commands.c index 113532a5..6717157e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4143,59 +4143,124 @@ cmd_pgp(ProfWin *window, gchar **args, struct cmd_help_t help) if (args[0] == NULL) { cons_show("Usage: %s", help.usage); return TRUE; - } else if (g_strcmp0(args[0], "keys") == 0) { + } + + 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 { + if (!keys) { cons_show("No keys found"); + return TRUE; + } + + cons_show("PGP keys:"); + GSList *curr = keys; + while (curr) { + ProfPGPKey *key = curr->data; + cons_show(" %s", key->name); + cons_show(" ID : %s", key->id); + cons_show(" Fingerprint : %s", key->fp); + curr = g_slist_next(curr); } g_slist_free_full(keys, (GDestroyNotify)p_gpg_free_key); - } else if (g_strcmp0(args[0], "fps") == 0) { + return TRUE; + } + + 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); + return TRUE; } - } else if (g_strcmp0(args[0], "libver") == 0) { + GHashTable *fingerprints = p_gpg_fingerprints(); + GList *jids = g_hash_table_get_keys(fingerprints); + if (!jids) { + cons_show("No PGP fingerprints received."); + return TRUE; + } + + 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); + } + g_list_free(jids); + return TRUE; + } + + 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 { + if (!libver) { cons_show("Could not get libgpgme version"); + return TRUE; } - } else if (g_strcmp0(args[0], "start") == 0) { + + GString *fullstr = g_string_new("Using libgpgme version "); + g_string_append(fullstr, libver); + cons_show("%s", fullstr->str); + g_string_free(fullstr, TRUE); + + return TRUE; + } + + if (g_strcmp0(args[0], "start") == 0) { jabber_conn_status_t conn_status = jabber_get_connection_status(); if (conn_status != JABBER_CONNECTED) { cons_show("You must be connected to start PGP encrpytion."); - } else if (window->type != WIN_CHAT && args[1] == NULL) { + return TRUE; + } + + if (window->type != WIN_CHAT && args[1] == NULL) { cons_show("You must be in a regular chat window to start PGP encrpytion."); + return TRUE; + } + + ProfChatWin *chatwin = NULL; + + if (args[1]) { + char *contact = args[1]; + char *barejid = roster_barejid_from_name(contact); + if (barejid == NULL) { + barejid = contact; + } + + chatwin = wins_get_chat(barejid); + if (!chatwin) { + chatwin = ui_ev_new_chat_win(barejid); + } + ui_ev_focus_win((ProfWin*)chatwin); + } else { + chatwin = (ProfChatWin*)window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); } + + if (chatwin->enc_mode == PROF_ENC_OTR) { + ui_current_print_formatted_line('!', 0, "You must end the OTR session to start PGP encryption."); + return TRUE; + } + + if (chatwin->enc_mode == PROF_ENC_PGP) { + ui_current_print_formatted_line('!', 0, "You have already started PGP encryption."); + return TRUE; + } + + ProfAccount *account = accounts_get_account(jabber_get_account_name()); + if (!account->pgp_keyid) { + ui_current_print_formatted_line('!', 0, "You must specify a PGP key ID for this account to start PGP encryption."); + account_free(account); + return TRUE; + } + account_free(account); + + if (!p_gpg_available(chatwin->barejid)) { + ui_current_print_formatted_line('!', 0, "No PGP key found for %s.", chatwin->barejid); + return TRUE; + } + + chatwin->enc_mode = PROF_ENC_PGP; + ui_current_print_formatted_line('!', 0, "PGP encyption enabled."); } return TRUE; |