Added /otr policy for contacts in account preferences

This commit is contained in:
James Booth
2014-05-11 18:13:04 +01:00
parent 2aa39fc362
commit 6d955609c5
3 changed files with 148 additions and 11 deletions

View File

@@ -2656,15 +2656,18 @@ cmd_otr(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage);
}
return TRUE;
} else if (strcmp(args[0], "warn") == 0) {
gboolean result = _cmd_set_boolean_preference(args[1], help,
"OTR warning message", PREF_OTR_WARN);
ui_current_update_virtual();
return result;
} else if (strcmp(args[0], "libver") == 0) {
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);
@@ -2673,19 +2676,27 @@ cmd_otr(gchar **args, struct cmd_help_t help)
}
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 {
if ((g_strcmp0(choice, "manual") != 0) &&
(g_strcmp0(choice, "opportunistic") != 0) &&
(g_strcmp0(choice, "always") != 0)) {
cons_show("OTR policy can be set to: manual, opportunistic or always.");
return TRUE;
}
char *contact = args[2];
if (contact == NULL) {
prefs_set_string(PREF_OTR_POLICY, choice);
cons_show("OTR policy is now set to: %s", choice);
return TRUE;
} else {
char *contact_jid = roster_barejid_from_name(contact);
if (contact_jid == NULL) {
contact_jid = contact;
}
accounts_add_otr_policy(jabber_get_account_name(), contact_jid, choice);
cons_show("OTR policy for %s set to: %s", contact_jid, choice);
return TRUE;
}
return TRUE;
}
if (jabber_get_connection_status() != JABBER_CONNECTED) {
@@ -2697,6 +2708,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
ProfAccount *account = accounts_get_account(jabber_get_account_name());
otr_keygen(account);
return TRUE;
} else if (strcmp(args[0], "myfp") == 0) {
if (!otr_key_loaded()) {
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
@@ -2706,6 +2718,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
free(fingerprint);
}
return TRUE;
} else if (strcmp(args[0], "theirfp") == 0) {
win_type_t win_type = ui_current_win_type();
@@ -2720,6 +2733,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
free(fingerprint);
}
return TRUE;
} else if (strcmp(args[0], "start") == 0) {
if (args[1] != NULL) {
char *contact = args[1];
@@ -2766,6 +2780,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
}
}
return TRUE;
} else if (strcmp(args[0], "end") == 0) {
win_type_t win_type = ui_current_win_type();
@@ -2779,6 +2794,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
otr_end_session(recipient);
}
return TRUE;
} else if (strcmp(args[0], "trust") == 0) {
win_type_t win_type = ui_current_win_type();
@@ -2792,6 +2808,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
otr_trust(recipient);
}
return TRUE;
} else if (strcmp(args[0], "untrust") == 0) {
win_type_t win_type = ui_current_win_type();
@@ -2805,6 +2822,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
otr_untrust(recipient);
}
return TRUE;
} else if (strcmp(args[0], "secret") == 0) {
win_type_t win_type = ui_current_win_type();
if (win_type != WIN_CHAT) {
@@ -2821,6 +2839,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
}
}
return TRUE;
} else if (strcmp(args[0], "question") == 0) {
char *question = args[1];
char *answer = args[2];
@@ -2840,6 +2859,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
}
return TRUE;
}
} else if (strcmp(args[0], "answer") == 0) {
win_type_t win_type = ui_current_win_type();
if (win_type != WIN_CHAT) {
@@ -2856,6 +2876,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
}
}
return TRUE;
} else {
cons_show("Usage: %s", help.usage);
return TRUE;