diff options
author | James Booth <boothj5@gmail.com> | 2014-04-22 23:53:15 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-04-22 23:53:15 +0100 |
commit | 1a0f12b0e6d7f191f1d765e426dd0d53d411741a (patch) | |
tree | 72e7bcd273022db9439249ccec2fb39122e11f37 /src/command | |
parent | 2c15aba92a8288e41bea6e12933a14ffe390e1f4 (diff) | |
parent | 1192e67cf76ba953031f420e5ac790989a81530c (diff) | |
download | profani-tty-1a0f12b0e6d7f191f1d765e426dd0d53d411741a.tar.gz |
Merge remote-tracking branch 'lucian/master'
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/command.c | 11 | ||||
-rw-r--r-- | src/command/commands.c | 41 |
2 files changed, 48 insertions, 4 deletions
diff --git a/src/command/command.c b/src/command/command.c index 23d5bae4..82e53c05 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -594,9 +594,9 @@ static struct cmd_t command_defs[] = { "/otr", cmd_otr, parse_args, 1, 2, NULL, - { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver", "Off The Record encryption commands.", - { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver", - "-------------------------------------------------------------", + { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver|policy", "Off The Record encryption commands.", + { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn|libver|policy", + "--------------------------------------------------------------------", "gen - Generate your private key.", "myfp - Show your fingerprint.", "theirfp - Show contacts fingerprint.", @@ -607,6 +607,7 @@ static struct cmd_t command_defs[] = "log - How to log OTR messages, options are 'on', 'off' and 'redact', with redaction being the default.", "warn - Show when unencrypted messaging is being used in the title bar, options are 'on' and 'off' with 'on' being the default.", "libver - Show which version of the libotr library is being used.", + "policy - manual, opportunistic or always.", NULL } } }, { "/outtype", @@ -1327,6 +1328,10 @@ cmd_execute_default(const char * const inp) ui_current_print_line("You are not currently connected."); } else { #ifdef HAVE_LIBOTR + if ((strcmp(prefs_get_string(PREF_OTR_POLICY), "always") == 0) && !otr_is_secure(recipient)) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } if (otr_is_secure(recipient)) { char *encrypted = otr_encrypt_message(recipient, inp); if (encrypted != NULL) { diff --git a/src/command/commands.c b/src/command/commands.c index 0a96d318..c0729630 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include <errno.h> #include <glib.h> +#include <libotr/proto.h> #include "chat_session.h" #include "command/commands.h" @@ -967,7 +968,24 @@ cmd_msg(gchar **args, struct cmd_help_t help) cons_show_error("Failed to encrypt and send message,"); } } else { - message_send(msg, usr_jid); + char *policy = prefs_get_string(PREF_OTR_POLICY); + + if (strcmp(policy, "always") == 0) { + cons_show_error("Failed to send message. Please check OTR policy"); + return TRUE; + } else if (strcmp(policy, "opportunistic") == 0) { + char *otr_base_tag = OTRL_MESSAGE_TAG_BASE; + char *otr_v2_tag = OTRL_MESSAGE_TAG_V2; + int N = strlen(otr_base_tag) + strlen(otr_v2_tag) + strlen(msg) + 1; + char *temp = (char *) malloc( (unsigned) N*sizeof(char *) ); + strcpy( temp , msg ); + strcat( temp , otr_base_tag); + strcat( temp, otr_v2_tag); + message_send(temp, usr_jid); + free(temp); + } else { + message_send(msg, usr_jid); + } ui_outgoing_msg("me", usr_jid, msg); if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) { @@ -2610,6 +2628,27 @@ cmd_otr(gchar **args, struct cmd_help_t help) char *version = otr_libotr_version(); cons_show("Using libotr version %s", version); return TRUE; + } else if (strcmp(args[0], "policy") == 0) { + if (args[1] == NULL) { + char *policy = prefs_get_string(PREF_OTR_POLICY); + cons_show("OTR policy is now set to: %s", policy); + return TRUE; + } + + char *choice = args[1]; + if (g_strcmp0(choice, "manual") == 0) { + prefs_set_string(PREF_OTR_POLICY, "manual"); + cons_show("OTR policy is now set to: manual"); + } else if (g_strcmp0(choice, "opportunistic") == 0) { + prefs_set_string(PREF_OTR_POLICY, "opportunistic"); + cons_show("OTR policy is now set to: opportunistic"); + } else if (g_strcmp0(choice, "always") == 0) { + prefs_set_string(PREF_OTR_POLICY, "always"); + cons_show("OTR policy is now set to: always"); + } else { + cons_show("OTR policy can be set to: manual, opportunistic or always."); + } + return TRUE; } if (jabber_get_connection_status() != JABBER_CONNECTED) { |