1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Added OTR policy account preference

This commit is contained in:
James Booth 2014-05-11 14:13:15 +01:00
parent f2ebbdb8de
commit 95ff13136b
10 changed files with 46 additions and 17 deletions

View File

@ -269,8 +269,9 @@ cmd_account(gchar **args, struct cmd_help_t help)
if ((g_strcmp0(value, "manual") != 0)
&& (g_strcmp0(value, "opportunistic") != 0)
&& (g_strcmp0(value, "always") != 0)) {
cons_show("Invalid setting.");
cons_show("OTR policy must be one of: manual, opportunistic or always.");
} else {
accounts_set_otr_policy(account_name, value);
cons_show("Updated OTR policy for account %s: %s", account_name, value);
cons_show("");
}

View File

@ -34,7 +34,7 @@ account_new(const gchar * const name, const gchar * const jid,
int port, const gchar * const resource, const gchar * const last_presence,
const gchar * const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd,
const gchar * const muc_service, const gchar * const muc_nick)
const gchar * const muc_service, const gchar * const muc_nick, const gchar * const otr_policy)
{
ProfAccount *new_account = malloc(sizeof(ProfAccount));
@ -111,6 +111,12 @@ account_new(const gchar * const name, const gchar * const jid,
new_account->muc_nick = strdup(muc_nick);
}
if (otr_policy != NULL) {
new_account->otr_policy = strdup(otr_policy);
} else {
new_account->otr_policy = NULL;
}
return new_account;
}
@ -137,7 +143,7 @@ account_free(ProfAccount *account)
free(account->login_presence);
free(account->muc_service);
free(account->muc_nick);
free(account->otr_policy);
free(account);
}
}
}

View File

@ -42,6 +42,7 @@ typedef struct prof_account_t {
gchar *muc_service;
gchar *muc_nick;
gboolean enabled;
gchar *otr_policy;
} ProfAccount;
ProfAccount* account_new(const gchar * const name, const gchar * const jid,
@ -49,7 +50,7 @@ ProfAccount* account_new(const gchar * const name, const gchar * const jid,
int port, const gchar * const resource, const gchar * const last_presence,
const gchar * const login_presence, int priority_online, int priority_chat,
int priority_away, int priority_xa, int priority_dnd,
const gchar * const muc_service, const gchar * const muc_nick);
const gchar * const muc_service, const gchar * const muc_nick, const gchar * const otr_policy);
char* account_create_full_jid(ProfAccount *account);

View File

@ -50,7 +50,8 @@ static gchar *string_keys[] = {
"presence.last",
"presence.login",
"muc.service",
"muc.nick"
"muc.nick",
"otr.policy"
};
static void _fix_legacy_accounts(const char * const account_name);
@ -212,10 +213,15 @@ _accounts_get_account(const char * const name)
gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL);
gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL);
gchar *otr_policy = NULL;
if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) {
otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL);
}
ProfAccount *new_account = account_new(name, jid, password, enabled,
server, port, resource, last_presence, login_presence,
priority_online, priority_chat, priority_away, priority_xa,
priority_dnd, muc_service, muc_nick);
priority_dnd, muc_service, muc_nick, otr_policy);
g_free(jid);
g_free(password);
@ -225,6 +231,7 @@ _accounts_get_account(const char * const name)
g_free(login_presence);
g_free(muc_service);
g_free(muc_nick);
g_free(otr_policy);
return new_account;
}
@ -400,6 +407,15 @@ _accounts_set_muc_nick(const char * const account_name, const char * const value
}
}
static void
_accounts_set_otr_policy(const char * const account_name, const char * const value)
{
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "otr.policy", value);
_save_accounts();
}
}
static void
_accounts_set_priority_online(const char * const account_name, const gint value)
{
@ -660,6 +676,7 @@ accounts_init_module(void)
accounts_set_password = _accounts_set_password;
accounts_set_muc_service = _accounts_set_muc_service;
accounts_set_muc_nick = _accounts_set_muc_nick;
accounts_set_otr_policy = _accounts_set_otr_policy;
accounts_set_last_presence = _accounts_set_last_presence;
accounts_set_login_presence = _accounts_set_login_presence;
accounts_get_last_presence = _accounts_get_last_presence;

View File

@ -52,6 +52,7 @@ void (*accounts_set_resource)(const char * const account_name, const char * cons
void (*accounts_set_password)(const char * const account_name, const char * const value);
void (*accounts_set_muc_service)(const char * const account_name, const char * const value);
void (*accounts_set_muc_nick)(const char * const account_name, const char * const value);
void (*accounts_set_otr_policy)(const char * const account_name, const char * const value);
void (*accounts_set_last_presence)(const char * const account_name, const char * const value);
void (*accounts_set_login_presence)(const char * const account_name, const char * const value);
resource_presence_t (*accounts_get_login_presence)(const char * const account_name);

View File

@ -885,6 +885,9 @@ _cons_show_account(ProfAccount *account)
if (account->muc_nick != NULL) {
cons_show ("muc nick : %s", account->muc_nick);
}
if (account->otr_policy != NULL) {
cons_show ("OTR policy : %s", account->otr_policy);
}
if (account->last_presence != NULL) {
cons_show ("Last presence : %s", account->last_presence);
}

View File

@ -40,7 +40,7 @@ void cmd_account_shows_account_when_connected_and_no_args(void **state)
mock_accounts_get_account();
CommandHelp *help = malloc(sizeof(CommandHelp));
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
gchar *args[] = { NULL };
mock_connection_status(JABBER_CONNECTED);
@ -119,7 +119,7 @@ void cmd_account_show_shows_account_when_exists(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "show", "account_name", NULL };
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
accounts_get_account_return(account);

View File

@ -424,7 +424,7 @@ void cmd_connect_asks_password_when_not_in_account(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "jabber_org", NULL };
ProfAccount *account = account_new("jabber_org", "me@jabber.org", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
mock_connection_status(JABBER_DISCONNECTED);
@ -448,7 +448,7 @@ void cmd_connect_shows_message_when_connecting_with_account(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "jabber_org", NULL };
ProfAccount *account = account_new("jabber_org", "user@jabber.org", "password",
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
mock_connection_status(JABBER_DISCONNECTED);
@ -472,7 +472,7 @@ void cmd_connect_connects_with_account(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "jabber_org", NULL };
ProfAccount *account = account_new("jabber_org", "me@jabber.org", "password",
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
mock_connection_status(JABBER_DISCONNECTED);

View File

@ -98,7 +98,7 @@ void cmd_join_uses_account_mucservice_when_no_service_specified(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { room, "nick", nick, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL);
muc_init();
@ -124,7 +124,7 @@ void cmd_join_uses_supplied_nick(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { room, "nick", nick, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
muc_init();
@ -150,7 +150,7 @@ void cmd_join_uses_account_nick_when_not_supplied(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { room, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, NULL, account_nick, NULL);
muc_init();
@ -179,7 +179,7 @@ void cmd_join_uses_password_when_supplied(void **state)
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { room, "password", password, NULL };
ProfAccount *account = account_new(account_name, "user@server.org", NULL,
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick);
TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL);
muc_init();

View File

@ -325,7 +325,7 @@ void cmd_otr_gen_generates_key_for_connected_account(void **state)
gchar *args[] = { "gen", NULL };
char *account_name = "myaccount";
ProfAccount *account = account_new(account_name, "me@jabber.org", NULL,
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL);
TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL);
stub_cons_show();
mock_connection_status(JABBER_CONNECTED);