From 609d05366c00670c176c842a19be760ad54f384b Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 20 Nov 2016 02:09:34 +0000 Subject: [PATCH 1/6] Use server features for account muc service issue #878 --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 8 +- src/command/cmd_funcs.c | 51 ++++++++---- src/config/account.c | 55 ++++++------- src/config/accounts.c | 102 ++++++++++++++---------- src/config/accounts.h | 1 + src/xmpp/connection.c | 4 + src/xmpp/connection.h | 1 - src/xmpp/xmpp.h | 2 + tests/functionaltests/functionaltests.c | 1 - tests/functionaltests/test_muc.c | 15 ---- tests/functionaltests/test_muc.h | 1 - tests/functionaltests/test_rooms.c | 2 +- tests/unittests/config/stub_accounts.c | 1 + 14 files changed, 133 insertions(+), 112 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 2d3209d5..be198e2a 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -360,6 +360,7 @@ cmd_ac_init(void) autocomplete_add(account_clear_ac, "pgpkeyid"); autocomplete_add(account_clear_ac, "startscript"); autocomplete_add(account_clear_ac, "theme"); + autocomplete_add(account_clear_ac, "muc"); account_default_ac = autocomplete_new(); autocomplete_add(account_default_ac, "set"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 34400ae3..3c2be4db 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1989,7 +1989,8 @@ static struct cmd_t command_defs[] = "/account clear port", "/account clear otr", "/account clear pgpkeyid", - "/account clear startscript") + "/account clear startscript", + "/account clean muc") CMD_DESC( "Commands for creating and managing accounts. " "Calling with no arguments will display information for the current account.") @@ -2012,7 +2013,7 @@ static struct cmd_t command_defs[] = { "set resource ", "The resource to be used for this account, defaults to 'profanity'." }, { "set password ", "Password for the account, note this is currently stored in plaintext if set." }, { "set eval_password ", "Shell command evaluated to retrieve password for the account. Can be used to retrieve password from keyring." }, - { "set muc ", "The default MUC chat service to use, defaults to 'conference.' where the domain part is from the account JID." }, + { "set muc ", "The default MUC chat service to use, defaults to the servers disco info response." }, { "set nick ", "The default nickname to use when joining chat rooms." }, { "set otr ", "Override global OTR policy for this account, see /otr." }, { "set pgpkeyid ", "Set the ID of the PGP key for this account, see /pgp." }, @@ -2028,7 +2029,8 @@ static struct cmd_t command_defs[] = { "clear otr", "Remove the OTR policy setting for this account." }, { "clear pgpkeyid", "Remove pgpkeyid associated with this account." }, { "clear startscript", "Remove startscript associated with this account." }, - { "clear theme", "Clear the theme setting for the account, the global theme will be used." }) + { "clear theme", "Clear the theme setting for the account, the global theme will be used." }, + { "clear muc", "Remove the default MUC service setting."}) CMD_EXAMPLES( "/account add me", "/account set me jid me@chatty", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 145752ca..08570e96 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -959,6 +959,10 @@ cmd_account_clear(ProfWin *window, const char *const command, gchar **args) accounts_clear_theme(account_name); cons_show("Removed theme for account %s", account_name); cons_show(""); + } else if (strcmp(property, "muc") == 0) { + accounts_clear_muc(account_name); + cons_show("Removed MUC service for account %s", account_name); + cons_show(""); } else { cons_show("Invalid property: %s", property); cons_show(""); @@ -3426,17 +3430,20 @@ cmd_join(ProfWin *window, const char *const command, gchar **args) if (args[0] == NULL) { char *account_name = session_get_account_name(); ProfAccount *account = accounts_get_account(account_name); + if (account->muc_service) { + GString *room_str = g_string_new(""); + char *uuid = connection_create_uuid(); + g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service); + connection_free_uuid(uuid); - GString *room_str = g_string_new(""); - char *uuid = connection_create_uuid(); - g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service); - connection_free_uuid(uuid); + presence_join_room(room_str->str, account->muc_nick, NULL); + muc_join(room_str->str, account->muc_nick, NULL, FALSE); - presence_join_room(room_str->str, account->muc_nick, NULL); - muc_join(room_str->str, account->muc_nick, NULL, FALSE); - - g_string_free(room_str, TRUE); - account_free(account); + g_string_free(room_str, TRUE); + account_free(account); + } else { + cons_show("Account MUC service property not found."); + } return TRUE; } @@ -3451,7 +3458,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args) char *room = NULL; char *nick = NULL; char *passwd = NULL; - GString *room_str = g_string_new(""); char *account_name = session_get_account_name(); ProfAccount *account = accounts_get_account(account_name); @@ -3460,11 +3466,18 @@ cmd_join(ProfWin *window, const char *const command, gchar **args) room = args[0]; // server not supplied (room), use account preference - } else { + } else if (account->muc_service) { + GString *room_str = g_string_new(""); g_string_append(room_str, args[0]); g_string_append(room_str, "@"); g_string_append(room_str, account->muc_service); room = room_str->str; + g_string_free(room_str, FALSE); + + // no account preference + } else { + cons_show("Account MUC service property not found."); + return TRUE; } // Additional args supplied @@ -3502,7 +3515,6 @@ cmd_join(ProfWin *window, const char *const command, gchar **args) } jid_destroy(room_arg); - g_string_free(room_str, TRUE); account_free(account); return TRUE; @@ -4307,14 +4319,19 @@ cmd_rooms(ProfWin *window, const char *const command, gchar **args) return TRUE; } - if (args[0] == NULL) { - ProfAccount *account = accounts_get_account(session_get_account_name()); - iq_room_list_request(account->muc_service); - account_free(account); - } else { + if (args[0]) { iq_room_list_request(args[0]); + return TRUE; } + ProfAccount *account = accounts_get_account(session_get_account_name()); + if (account->muc_service) { + iq_room_list_request(account->muc_service); + } else { + cons_show("Account MUC service property not found."); + } + account_free(account); + return TRUE; } diff --git a/src/config/account.c b/src/config/account.c index 3e8c8cf1..40b91224 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -115,17 +115,10 @@ account_new(const gchar *const name, const gchar *const jid, new_account->priority_xa = priority_xa; new_account->priority_dnd = priority_dnd; - if (muc_service == NULL) { - GString *g_muc_service = g_string_new("conference."); - Jid *jidp = jid_create(new_account->jid); - g_string_append(g_muc_service, jidp->domainpart); - - new_account->muc_service = g_muc_service->str; - - g_string_free(g_muc_service, FALSE); - jid_destroy(jidp); - } else { + if (muc_service) { new_account->muc_service = strdup(muc_service); + } else { + new_account->muc_service = NULL; } if (muc_nick == NULL) { @@ -224,25 +217,27 @@ account_eval_password(ProfAccount *account) void account_free(ProfAccount *account) { - if (account) { - free(account->name); - free(account->jid); - free(account->password); - free(account->eval_password); - free(account->resource); - free(account->server); - free(account->last_presence); - free(account->login_presence); - free(account->muc_service); - free(account->muc_nick); - free(account->otr_policy); - free(account->pgp_keyid); - free(account->startscript); - free(account->theme); - free(account->tls_policy); - g_list_free_full(account->otr_manual, g_free); - g_list_free_full(account->otr_opportunistic, g_free); - g_list_free_full(account->otr_always, g_free); - free(account); + if (account == NULL) { + return; } + + free(account->name); + free(account->jid); + free(account->password); + free(account->eval_password); + free(account->resource); + free(account->server); + free(account->last_presence); + free(account->login_presence); + free(account->muc_service); + free(account->muc_nick); + free(account->otr_policy); + free(account->pgp_keyid); + free(account->startscript); + free(account->theme); + free(account->tls_policy); + g_list_free_full(account->otr_manual, g_free); + g_list_free_full(account->otr_opportunistic, g_free); + g_list_free_full(account->otr_always, g_free); + free(account); } diff --git a/src/config/accounts.c b/src/config/accounts.c index 96168b5b..233a5aa8 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -133,46 +133,46 @@ accounts_add(const char *account_name, const char *altdomain, const int port, co } } - // doesn't yet exist - if (!g_key_file_has_group(accounts, account_name)) { - g_key_file_set_boolean(accounts, account_name, "enabled", TRUE); - g_key_file_set_string(accounts, account_name, "jid", barejid); - g_key_file_set_string(accounts, account_name, "resource", resource); - if (altdomain) { - g_key_file_set_string(accounts, account_name, "server", altdomain); - } - if (port != 0) { - g_key_file_set_integer(accounts, account_name, "port", port); - } - if (tls_policy) { - g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy); - } - - Jid *jidp = jid_create(barejid); - GString *muc_service = g_string_new("conference."); - g_string_append(muc_service, jidp->domainpart); - g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str); - g_string_free(muc_service, TRUE); - if (jidp->localpart == NULL) { - g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart); - } else { - g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart); - } - jid_destroy(jidp); - - g_key_file_set_string(accounts, account_name, "presence.last", "online"); - g_key_file_set_string(accounts, account_name, "presence.login", "online"); - g_key_file_set_integer(accounts, account_name, "priority.online", 0); - g_key_file_set_integer(accounts, account_name, "priority.chat", 0); - g_key_file_set_integer(accounts, account_name, "priority.away", 0); - g_key_file_set_integer(accounts, account_name, "priority.xa", 0); - g_key_file_set_integer(accounts, account_name, "priority.dnd", 0); - - _save_accounts(); - autocomplete_add(all_ac, account_name); - autocomplete_add(enabled_ac, account_name); + if (g_key_file_has_group(accounts, account_name)) { + jid_destroy(jid); + return; } + g_key_file_set_boolean(accounts, account_name, "enabled", TRUE); + g_key_file_set_string(accounts, account_name, "jid", barejid); + g_key_file_set_string(accounts, account_name, "resource", resource); + if (altdomain) { + g_key_file_set_string(accounts, account_name, "server", altdomain); + } + if (port != 0) { + g_key_file_set_integer(accounts, account_name, "port", port); + } + if (tls_policy) { + g_key_file_set_string(accounts, account_name, "tls.policy", tls_policy); + } + + Jid *jidp = jid_create(barejid); + + if (jidp->localpart == NULL) { + g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart); + } else { + g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart); + } + + jid_destroy(jidp); + + g_key_file_set_string(accounts, account_name, "presence.last", "online"); + g_key_file_set_string(accounts, account_name, "presence.login", "online"); + g_key_file_set_integer(accounts, account_name, "priority.online", 0); + g_key_file_set_integer(accounts, account_name, "priority.chat", 0); + g_key_file_set_integer(accounts, account_name, "priority.away", 0); + g_key_file_set_integer(accounts, account_name, "priority.xa", 0); + g_key_file_set_integer(accounts, account_name, "priority.dnd", 0); + + _save_accounts(); + autocomplete_add(all_ac, account_name); + autocomplete_add(enabled_ac, account_name); + jid_destroy(jid); } @@ -223,7 +223,18 @@ accounts_get_account(const char *const name) int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL); int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL); - gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL); + gchar *muc_service = NULL; + if (g_key_file_has_key(accounts, name, "muc.service", NULL)) { + muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL); + } else { + jabber_conn_status_t conn_status = connection_get_status(); + if (conn_status == JABBER_CONNECTED) { + char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC); + if (conf_jid) { + muc_service = strdup(conf_jid); + } + } + } gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL); gchar *otr_policy = NULL; @@ -416,10 +427,6 @@ accounts_set_jid(const char *const account_name, const char *const value) g_key_file_set_string(accounts, account_name, "resource", jid->resourcepart); } - GString *muc_service = g_string_new("conference."); - g_string_append(muc_service, jid->domainpart); - g_key_file_set_string(accounts, account_name, "muc.service", muc_service->str); - g_string_free(muc_service, TRUE); if (jid->localpart == NULL) { g_key_file_set_string(accounts, account_name, "muc.nick", jid->domainpart); } else { @@ -568,6 +575,15 @@ accounts_clear_theme(const char *const account_name) } } +void +accounts_clear_muc(const char *const account_name) +{ + if (accounts_account_exists(account_name)) { + g_key_file_remove_key(accounts, account_name, "muc.service", NULL); + _save_accounts(); + } +} + void accounts_clear_otr(const char *const account_name) { diff --git a/src/config/accounts.h b/src/config/accounts.h index 7524c65e..6c6cb1c9 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -93,6 +93,7 @@ void accounts_clear_otr(const char *const account_name); void accounts_clear_pgp_keyid(const char *const account_name); void accounts_clear_script_start(const char *const account_name); void accounts_clear_theme(const char *const account_name); +void accounts_clear_muc(const char *const account_name); void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy); #endif diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 304d984d..4e0ca9a8 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -290,6 +290,10 @@ connection_supports(const char *const feature) char* connection_jid_for_feature(const char *const feature) { + if (conn.features_by_jid == NULL) { + return NULL; + } + GList *jids = g_hash_table_get_keys(conn.features_by_jid); GList *curr = jids; diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h index ef997a29..b691e90d 100644 --- a/src/xmpp/connection.h +++ b/src/xmpp/connection.h @@ -54,7 +54,6 @@ void connection_set_disco_items(GSList *items); xmpp_conn_t* connection_get_conn(void); xmpp_ctx_t* connection_get_ctx(void); char *connection_get_domain(void); -char* connection_jid_for_feature(const char *const feature); GHashTable* connection_get_features(const char *const jid); void connection_clear_data(void); diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 8dfe7c0e..7302b279 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -58,6 +58,7 @@ #define XMPP_FEATURE_BLOCKING "urn:xmpp:blocking" #define XMPP_FEATURE_RECEIPTS "urn:xmpp:receipts" #define XMPP_FEATURE_LASTACTIVITY "jabber:iq:last" +#define XMPP_FEATURE_MUC "http://jabber.org/protocol/muc" typedef enum { JABBER_CONNECTING, @@ -129,6 +130,7 @@ gboolean connection_is_secured(void); gboolean connection_send_stanza(const char *const stanza); GList* connection_get_available_resources(void); gboolean connection_supports(const char *const feature); +char* connection_jid_for_feature(const char *const feature); char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url, gboolean request_receipt); diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 617ab838..ef9f0e39 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -89,7 +89,6 @@ int main(int argc, char* argv[]) { PROF_FUNC_TEST(display_software_version_result_in_chat), PROF_FUNC_TEST(sends_room_join), - PROF_FUNC_TEST(sends_room_join_with_default_muc_service), PROF_FUNC_TEST(sends_room_join_with_nick), PROF_FUNC_TEST(sends_room_join_with_password), PROF_FUNC_TEST(sends_room_join_with_nick_and_password), diff --git a/tests/functionaltests/test_muc.c b/tests/functionaltests/test_muc.c index 5a117045..e7fc8dcb 100644 --- a/tests/functionaltests/test_muc.c +++ b/tests/functionaltests/test_muc.c @@ -26,21 +26,6 @@ sends_room_join(void **state) )); } -void -sends_room_join_with_default_muc_service(void **state) -{ - prof_connect(); - - prof_input("/join testroom"); - - assert_true(stbbr_last_received( - "" - "" - "" - "" - )); -} - void sends_room_join_with_nick(void **state) { diff --git a/tests/functionaltests/test_muc.h b/tests/functionaltests/test_muc.h index 30a6c2c8..4f3c4f5d 100644 --- a/tests/functionaltests/test_muc.h +++ b/tests/functionaltests/test_muc.h @@ -1,5 +1,4 @@ void sends_room_join(void **state); -void sends_room_join_with_default_muc_service(void **state); void sends_room_join_with_nick(void **state); void sends_room_join_with_password(void **state); void sends_room_join_with_nick_and_password(void **state); diff --git a/tests/functionaltests/test_rooms.c b/tests/functionaltests/test_rooms.c index 9bff2e19..c0103279 100644 --- a/tests/functionaltests/test_rooms.c +++ b/tests/functionaltests/test_rooms.c @@ -25,7 +25,7 @@ rooms_query(void **state) prof_connect(); - prof_input("/rooms"); + prof_input("/rooms conference.localhost"); assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)")); assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)")); diff --git a/tests/unittests/config/stub_accounts.c b/tests/unittests/config/stub_accounts.c index 4c0449d6..669ceb33 100644 --- a/tests/unittests/config/stub_accounts.c +++ b/tests/unittests/config/stub_accounts.c @@ -196,6 +196,7 @@ void accounts_clear_otr(const char * const account_name) {} void accounts_clear_pgp_keyid(const char * const account_name) {} void accounts_clear_script_start(const char * const account_name) {} void accounts_clear_theme(const char * const account_name) {} +void accounts_clear_muc(const char * const account_name) {} void accounts_add_otr_policy(const char * const account_name, const char * const contact_jid, const char * const policy) {} char* accounts_get_last_activity(const char *const account_name) { From c441dbfa42e58796f87fdcbb02ee4aa19cca2469 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 20 Nov 2016 02:21:22 +0000 Subject: [PATCH 2/6] Fix typo --- src/command/cmd_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 3c2be4db..997f2c39 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1990,7 +1990,7 @@ static struct cmd_t command_defs[] = "/account clear otr", "/account clear pgpkeyid", "/account clear startscript", - "/account clean muc") + "/account clear muc") CMD_DESC( "Commands for creating and managing accounts. " "Calling with no arguments will display information for the current account.") From e043029a5069a30e8a7154a07d46260bece6358c Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 22 Nov 2016 00:39:52 +0000 Subject: [PATCH 3/6] Allow clearing account resource issue #880 --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 4 +++- src/command/cmd_funcs.c | 6 +++++- src/config/account.c | 2 +- src/config/account.h | 2 +- src/config/accounts.c | 9 ++++++++ src/config/accounts.h | 1 + src/event/client_events.c | 14 +++++++++---- src/ui/console.c | 4 +++- src/ui/core.c | 6 +----- src/xmpp/connection.c | 28 ++++++++++++------------- src/xmpp/jid.c | 4 ++-- src/xmpp/jid.h | 2 +- src/xmpp/session.c | 27 +++++++++++++++++------- tests/functionaltests/proftest.c | 2 +- tests/functionaltests/test_disconnect.c | 2 +- tests/unittests/config/stub_accounts.c | 1 + 17 files changed, 75 insertions(+), 40 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index be198e2a..628fb6b8 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -361,6 +361,7 @@ cmd_ac_init(void) autocomplete_add(account_clear_ac, "startscript"); autocomplete_add(account_clear_ac, "theme"); autocomplete_add(account_clear_ac, "muc"); + autocomplete_add(account_clear_ac, "resource"); account_default_ac = autocomplete_new(); autocomplete_add(account_default_ac, "set"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 997f2c39..8a44e83f 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1990,7 +1990,8 @@ static struct cmd_t command_defs[] = "/account clear otr", "/account clear pgpkeyid", "/account clear startscript", - "/account clear muc") + "/account clear muc", + "/account clear resource") CMD_DESC( "Commands for creating and managing accounts. " "Calling with no arguments will display information for the current account.") @@ -2030,6 +2031,7 @@ static struct cmd_t command_defs[] = { "clear pgpkeyid", "Remove pgpkeyid associated with this account." }, { "clear startscript", "Remove startscript associated with this account." }, { "clear theme", "Clear the theme setting for the account, the global theme will be used." }, + { "clear resource", "Remove the resource setting for this account."}, { "clear muc", "Remove the default MUC service setting."}) CMD_EXAMPLES( "/account add me", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 08570e96..eea37459 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -416,7 +416,7 @@ cmd_connect(ProfWin *window, const char *const command, gchar **args) account->password = NULL; } - jid = account_create_full_jid(account); + jid = account_create_connect_jid(account); account_free(account); // connect with JID @@ -963,6 +963,10 @@ cmd_account_clear(ProfWin *window, const char *const command, gchar **args) accounts_clear_muc(account_name); cons_show("Removed MUC service for account %s", account_name); cons_show(""); + } else if (strcmp(property, "resource") == 0) { + accounts_clear_resource(account_name); + cons_show("Removed resource for account %s", account_name); + cons_show(""); } else { cons_show("Invalid property: %s", property); cons_show(""); diff --git a/src/config/account.c b/src/config/account.c index 40b91224..8baa1dbb 100644 --- a/src/config/account.c +++ b/src/config/account.c @@ -167,7 +167,7 @@ account_new(const gchar *const name, const gchar *const jid, } char* -account_create_full_jid(ProfAccount *account) +account_create_connect_jid(ProfAccount *account) { if (account->resource) { return create_fulljid(account->jid, account->resource); diff --git a/src/config/account.h b/src/config/account.h index 09166752..32fee0f8 100644 --- a/src/config/account.h +++ b/src/config/account.h @@ -74,7 +74,7 @@ ProfAccount* account_new(const gchar *const name, const gchar *const jid, const gchar *const otr_policy, GList *otr_manual, GList *otr_opportunistic, GList *otr_always, const gchar *const pgp_keyid, const char *const startscript, const char *const theme, gchar *tls_policy); -char* account_create_full_jid(ProfAccount *account); +char* account_create_connect_jid(ProfAccount *account); gboolean account_eval_password(ProfAccount *account); void account_free(ProfAccount *account); diff --git a/src/config/accounts.c b/src/config/accounts.c index 233a5aa8..7dc852ae 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -584,6 +584,15 @@ accounts_clear_muc(const char *const account_name) } } +void +accounts_clear_resource(const char *const account_name) +{ + if (accounts_account_exists(account_name)) { + g_key_file_remove_key(accounts, account_name, "resource", NULL); + _save_accounts(); + } +} + void accounts_clear_otr(const char *const account_name) { diff --git a/src/config/accounts.h b/src/config/accounts.h index 6c6cb1c9..4d30cbd9 100644 --- a/src/config/accounts.h +++ b/src/config/accounts.h @@ -94,6 +94,7 @@ void accounts_clear_pgp_keyid(const char *const account_name); void accounts_clear_script_start(const char *const account_name); void accounts_clear_theme(const char *const account_name); void accounts_clear_muc(const char *const account_name); +void accounts_clear_resource(const char *const account_name); void accounts_add_otr_policy(const char *const account_name, const char *const contact_jid, const char *const policy); #endif diff --git a/src/event/client_events.c b/src/event/client_events.c index 0f85a61a..dcd49b94 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -64,9 +64,13 @@ cl_ev_connect_jid(const char *const jid, const char *const passwd, const char *c jabber_conn_status_t cl_ev_connect_account(ProfAccount *account) { - char *jid = account_create_full_jid(account); - cons_show("Connecting with account %s as %s", account->name, jid); - free(jid); + if (account->resource) { + cons_show("Connecting with account %s as %s/%s", account->name, account->jid, account->resource); + } else if (g_strcmp0(account->name, account->jid) == 0) { + cons_show("Connecting with account %s", account->name); + } else { + cons_show("Connecting with account %s as %s", account->name, account->jid); + } return session_connect_with_account(account); } @@ -75,7 +79,9 @@ void cl_ev_disconnect(void) { const char *jid = connection_get_fulljid(); - cons_show("%s logged out successfully.", jid); + Jid *jidp = jid_create(jid); + cons_show("%s logged out successfully.", jidp->barejid); + jid_destroy(jidp); ui_disconnected(); ui_close_all_wins(); diff --git a/src/ui/console.c b/src/ui/console.c index ba6e5b38..75b66451 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -461,7 +461,9 @@ void cons_show_login_success(ProfAccount *account, gboolean secured) { ProfWin *console = wins_get_console(); - win_print(console, THEME_DEFAULT, '-', "%s logged in successfully, ", account->jid); + + const char *fulljid = connection_get_fulljid(); + win_print(console, THEME_DEFAULT, '-', "%s logged in successfully, ", fulljid); resource_presence_t presence = accounts_get_login_presence(account->name); const char *presence_str = string_from_resource_presence(presence); diff --git a/src/ui/core.c b/src/ui/core.c index 8078d7b7..f16080a2 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -383,11 +383,7 @@ ui_handle_login_account_success(ProfAccount *account, gboolean secured) title_bar_set_connected(TRUE); title_bar_set_tls(secured); - GString *fulljid = g_string_new(account->jid); - g_string_append(fulljid, "/"); - g_string_append(fulljid, account->resource); - status_bar_print_message(fulljid->str); - g_string_free(fulljid, TRUE); + status_bar_print_message(connection_get_fulljid()); status_bar_update_virtual(); } diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 4e0ca9a8..2c74f1e4 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -108,26 +108,21 @@ connection_shutdown(void) } jabber_conn_status_t -connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port, +connection_connect(const char *const jid, const char *const passwd, const char *const altdomain, int port, const char *const tls_policy) { - assert(fulljid != NULL); + assert(jid != NULL); assert(passwd != NULL); - Jid *jid = jid_create(fulljid); - if (jid == NULL) { - log_error("Malformed JID not able to connect: %s", fulljid); + Jid *jidp = jid_create(jid); + if (jidp == NULL) { + log_error("Malformed JID not able to connect: %s", jid); conn.conn_status = JABBER_DISCONNECTED; return conn.conn_status; - } else if (jid->fulljid == NULL) { - log_error("Full JID required to connect, received: %s", fulljid); - conn.conn_status = JABBER_DISCONNECTED; - jid_destroy(jid); - return conn.conn_status; } - jid_destroy(jid); + jid_destroy(jidp); - log_info("Connecting as %s", fulljid); + log_info("Connecting as %s", jid); if (conn.xmpp_log) { free(conn.xmpp_log); @@ -150,7 +145,7 @@ connection_connect(const char *const fulljid, const char *const passwd, const ch log_warning("Failed to get libstrophe conn during connect"); return JABBER_DISCONNECTED; } - xmpp_conn_set_jid(conn.xmpp_conn, fulljid); + xmpp_conn_set_jid(conn.xmpp_conn, jid); xmpp_conn_set_pass(conn.xmpp_conn, passwd); if (!tls_policy || (g_strcmp0(tls_policy, "force") == 0)) { @@ -349,7 +344,12 @@ connection_get_ctx(void) const char* connection_get_fulljid(void) { - return xmpp_conn_get_jid(conn.xmpp_conn); + const char *jid = xmpp_conn_get_bound_jid(conn.xmpp_conn); + if (jid) { + return jid; + } else { + return xmpp_conn_get_jid(conn.xmpp_conn); + } } GHashTable* diff --git a/src/xmpp/jid.c b/src/xmpp/jid.c index 7289ca4c..135a21df 100644 --- a/src/xmpp/jid.c +++ b/src/xmpp/jid.c @@ -106,10 +106,10 @@ jid_create(const gchar *const str) } Jid* -jid_create_from_bare_and_resource(const char *const room, const char *const nick) +jid_create_from_bare_and_resource(const char *const barejid, const char *const resource) { Jid *result; - char *jid = create_fulljid(room, nick); + char *jid = create_fulljid(barejid, resource); result = jid_create(jid); free(jid); diff --git a/src/xmpp/jid.h b/src/xmpp/jid.h index d82c3add..16e6e78b 100644 --- a/src/xmpp/jid.h +++ b/src/xmpp/jid.h @@ -49,7 +49,7 @@ struct jid_t { typedef struct jid_t Jid; Jid* jid_create(const gchar *const str); -Jid* jid_create_from_bare_and_resource(const char *const room, const char *const nick); +Jid* jid_create_from_bare_and_resource(const char *const barejid, const char *const resource); void jid_destroy(Jid *jid); gboolean jid_is_valid_room_form(Jid *jid); diff --git a/src/xmpp/session.c b/src/xmpp/session.c index 95930802..032ca77a 100644 --- a/src/xmpp/session.c +++ b/src/xmpp/session.c @@ -118,15 +118,22 @@ session_connect_with_account(const ProfAccount *const account) } saved_account.passwd = strdup(account->password); - // connect with fulljid - Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource); + char *jid = NULL; + if (account->resource) { + Jid *jidp = jid_create_from_bare_and_resource(account->jid, account->resource); + jid = strdup(jidp->fulljid); + jid_destroy(jidp); + } else { + jid = strdup(account->jid); + } + jabber_conn_status_t result = connection_connect( - jidp->fulljid, + jid, account->password, account->server, account->port, account->tls_policy); - jid_destroy(jidp); + free(jid); return result; } @@ -499,10 +506,16 @@ _session_reconnect(void) return; } - char *fulljid = create_fulljid(account->jid, account->resource); + char *jid = NULL; + if (account->resource) { + jid = create_fulljid(account->jid, account->resource); + } else { + jid = strdup(account->jid); + } + log_debug("Attempting reconnect with account %s", account->name); - connection_connect(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy); - free(fulljid); + connection_connect(jid, saved_account.passwd, account->server, account->port, account->tls_policy); + free(jid); account_free(account); g_timer_start(reconnect_timer); } diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index 0af26a68..90121249 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -253,7 +253,7 @@ prof_connect_with_roster(char *roster) // Allow time for profanity to connect exp_timeout = 30; - assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\.")); + assert_true(prof_output_regex("stabber@localhost/profanity logged in successfully, .+online.+ \\(priority 0\\)\\.")); exp_timeout = 10; stbbr_wait_for("prof_presence_*"); } diff --git a/tests/functionaltests/test_disconnect.c b/tests/functionaltests/test_disconnect.c index 7529da18..83861980 100644 --- a/tests/functionaltests/test_disconnect.c +++ b/tests/functionaltests/test_disconnect.c @@ -17,7 +17,7 @@ disconnect_ends_session(void **state) prof_connect(); prof_input("/disconnect"); - assert_true(prof_output_exact("stabber@localhost/profanity logged out successfully.")); + assert_true(prof_output_exact("stabber@localhost logged out successfully.")); prof_input("/roster"); assert_true(prof_output_exact("You are not currently connected.")); diff --git a/tests/unittests/config/stub_accounts.c b/tests/unittests/config/stub_accounts.c index 669ceb33..e1a33b0c 100644 --- a/tests/unittests/config/stub_accounts.c +++ b/tests/unittests/config/stub_accounts.c @@ -197,6 +197,7 @@ void accounts_clear_pgp_keyid(const char * const account_name) {} void accounts_clear_script_start(const char * const account_name) {} void accounts_clear_theme(const char * const account_name) {} void accounts_clear_muc(const char * const account_name) {} +void accounts_clear_resource(const char * const account_name) {} void accounts_add_otr_policy(const char * const account_name, const char * const contact_jid, const char * const policy) {} char* accounts_get_last_activity(const char *const account_name) { From 926d935e26c3dddd193d3ca70645c512ebc7fe60 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 23 Nov 2016 00:17:50 +0000 Subject: [PATCH 4/6] Fix help tags for /account --- src/command/cmd_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 8a44e83f..33ae1a76 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1953,7 +1953,7 @@ static struct cmd_t command_defs[] = { "clear", cmd_account_clear }) CMD_MAINFUNC(cmd_account) CMD_TAGS( - CMD_TAG_CONNECTION + CMD_TAG_CONNECTION, CMD_TAG_PRESENCE, CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) From b64646979ea50a13d0c7ec0b1a46969f661569a8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 24 Nov 2016 00:09:14 +0000 Subject: [PATCH 5/6] Remove unused function --- src/tools/http_upload.c | 1 - src/ui/window.c | 10 ---------- src/ui/window.h | 1 - 3 files changed, 12 deletions(-) diff --git a/src/tools/http_upload.c b/src/tools/http_upload.c index 23315460..8a31b25c 100644 --- a/src/tools/http_upload.c +++ b/src/tools/http_upload.c @@ -256,7 +256,6 @@ end: msg = strdup(FALLBACK_MSG); } win_update_entry_message(upload->window, upload->put_url, msg); - //win_update_entry_theme(upload->window, upload->put_url, THEME_THEM); win_mark_received(upload->window, upload->put_url); free(msg); diff --git a/src/ui/window.c b/src/ui/window.c index 1a7dc6bd..a000f1aa 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1279,16 +1279,6 @@ win_update_entry_message(ProfWin *window, const char *const id, const char *cons } } -void -win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item) -{ - ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, id); - if (entry) { - entry->theme_item = theme_item; - win_redraw(window); - } -} - void win_newline(ProfWin *window) { diff --git a/src/ui/window.h b/src/ui/window.h index e29cd62f..21c9154a 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -82,7 +82,6 @@ void win_sub_print(WINDOW *win, char *msg, gboolean newline, gboolean wrap, int void win_sub_newline_lazy(WINDOW *win); void win_mark_received(ProfWin *window, const char *const id); void win_update_entry_message(ProfWin *window, const char *const id, const char *const message); -void win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item); gboolean win_has_active_subwin(ProfWin *window); From 2b7894ccff4c12003572af965b7f098669f0a7c3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 15 Jan 2017 23:59:31 +0000 Subject: [PATCH 6/6] Remove status from cl_ev_presence_send fixes #888 --- src/command/cmd_funcs.c | 8 ++++---- src/event/client_events.c | 5 +++-- src/event/client_events.h | 2 +- src/event/server_events.c | 12 +++++++---- src/plugins/api.c | 2 +- src/plugins/plugins.c | 3 +-- src/xmpp/capabilities.c | 4 ++-- src/xmpp/connection.h | 1 - src/xmpp/presence.c | 5 ++--- src/xmpp/session.c | 22 ++++++++++++-------- src/xmpp/xmpp.h | 3 ++- tests/functionaltests/functionaltests.c | 1 + tests/functionaltests/test_presence.c | 27 +++++++++++++++++++++++++ tests/functionaltests/test_presence.h | 1 + tests/unittests/test_cmd_account.c | 4 +--- tests/unittests/xmpp/stub_xmpp.c | 5 +++-- 16 files changed, 71 insertions(+), 34 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index eea37459..eab3c596 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -860,8 +860,7 @@ _account_set_presence_priority(char *account_name, char *presence, char *priorit char *connected_account = session_get_account_name(); resource_presence_t last_presence = accounts_get_last_presence(connected_account); if (presence_type == last_presence) { - char *message = connection_get_presence_msg(); - cl_ev_presence_send(last_presence, message, 0); + cl_ev_presence_send(last_presence, 0); } } cons_show("Updated %s priority for account %s: %s", presence, account_name, priority); @@ -5961,7 +5960,7 @@ cmd_priority(ProfWin *window, const char *const command, gchar **args) if (res) { accounts_set_priority_all(session_get_account_name(), intval); resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name()); - cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0); + cl_ev_presence_send(last_presence, 0); cons_show("Priority set to %d.", intval); } else { cons_show(err_msg); @@ -7198,7 +7197,8 @@ _update_presence(const resource_presence_t resource_presence, if (conn_status != JABBER_CONNECTED) { cons_show("You are not currently connected."); } else { - cl_ev_presence_send(resource_presence, msg, 0); + connection_set_presence_msg(msg); + cl_ev_presence_send(resource_presence, 0); ui_update_presence(resource_presence, msg, show); } } diff --git a/src/event/client_events.c b/src/event/client_events.c index dcd49b94..d2dc29c6 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -96,9 +96,10 @@ cl_ev_disconnect(void) } void -cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs) +cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs) { char *signed_status = NULL; + char *msg = connection_get_presence_msg(); #ifdef HAVE_LIBGPGME char *account_name = session_get_account_name(); @@ -109,7 +110,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const char *const m account_free(account); #endif - presence_send(presence_type, msg, idle_secs, signed_status); + presence_send(presence_type, idle_secs, signed_status); free(signed_status); } diff --git a/src/event/client_events.h b/src/event/client_events.h index 876a0d54..b46a0a13 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -42,7 +42,7 @@ jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); void cl_ev_disconnect(void); -void cl_ev_presence_send(const resource_presence_t presence_type, const char *const msg, const int idle_secs); +void cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs); void cl_ev_send_msg(ProfChatWin *chatwin, const char *const msg, const char *const oob_url); void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char *const msg, const char *const oob_url); diff --git a/src/event/server_events.c b/src/event/server_events.c index a434bf47..56971e6a 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -135,19 +135,23 @@ sv_ev_roster_received(void) GTimeSpan diff_micros = g_date_time_difference(nowdt, lastdt); int diff_secs = (diff_micros / 1000) / 1000; if (prefs_get_boolean(PREF_LASTACTIVITY)) { - cl_ev_presence_send(conn_presence, NULL, diff_secs); + connection_set_presence_msg(NULL); + cl_ev_presence_send(conn_presence, diff_secs); } else { - cl_ev_presence_send(conn_presence, NULL, 0); + connection_set_presence_msg(NULL); + cl_ev_presence_send(conn_presence, 0); } g_date_time_unref(lastdt); } else { - cl_ev_presence_send(conn_presence, NULL, 0); + connection_set_presence_msg(NULL); + cl_ev_presence_send(conn_presence, 0); } free(last_activity_str); g_date_time_unref(nowdt); } else { - cl_ev_presence_send(conn_presence, NULL, 0); + connection_set_presence_msg(NULL); + cl_ev_presence_send(conn_presence, 0); } const char *fulljid = connection_get_fulljid(); diff --git a/src/plugins/api.c b/src/plugins/api.c index a4a1f998..8ebb0bb8 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -493,7 +493,7 @@ api_disco_add_feature(char *plugin_name, char *feature) // resend presence to update server's disco info data for this client if (connection_get_status() == JABBER_CONNECTED) { resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name()); - cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0); + cl_ev_presence_send(last_presence, 0); } } diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index a4846b20..054cb8e1 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -214,8 +214,7 @@ plugins_unload(const char *const name) if (connection_get_status() == JABBER_CONNECTED) { char* account_name = session_get_account_name(); resource_presence_t last_presence = accounts_get_last_presence(account_name); - char *msg = connection_get_presence_msg(); - cl_ev_presence_send(last_presence, msg, 0); + cl_ev_presence_send(last_presence, 0); } } return TRUE; diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index e09270cb..7571ad0c 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -125,7 +125,7 @@ caps_add_feature(char *feature) // resend presence to update server's disco info data for this client if (connection_get_status() == JABBER_CONNECTED) { resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name()); - cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0); + cl_ev_presence_send(last_presence, 0); } } @@ -143,7 +143,7 @@ caps_remove_feature(char *feature) // resend presence to update server's disco info data for this client if (connection_get_status() == JABBER_CONNECTED) { resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name()); - cl_ev_presence_send(last_presence, connection_get_presence_msg(), 0); + cl_ev_presence_send(last_presence, 0); } } diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h index b691e90d..7bedb94a 100644 --- a/src/xmpp/connection.h +++ b/src/xmpp/connection.h @@ -46,7 +46,6 @@ jabber_conn_status_t connection_connect(const char *const fulljid, const char *c void connection_disconnect(void); void connection_set_disconnected(void); -void connection_set_presence_msg(const char *const message); void connection_set_priority(const int priority); void connection_set_priority(int priority); void connection_set_disco_items(GSList *items); diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 4c686b7d..2a844ac6 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -191,21 +191,20 @@ presence_reset_sub_request_search(void) } void -presence_send(const resource_presence_t presence_type, const char *const msg, const int idle, char *signed_status) +presence_send(const resource_presence_t presence_type, const int idle, char *signed_status) { if (connection_get_status() != JABBER_CONNECTED) { log_warning("Error setting presence, not connected."); return; } + char *msg = connection_get_presence_msg(); if (msg) { log_debug("Updating presence: %s, \"%s\"", string_from_resource_presence(presence_type), msg); } else { log_debug("Updating presence: %s", string_from_resource_presence(presence_type)); } - connection_set_presence_msg(msg); - const int pri = accounts_get_priority_for_presence_type(session_get_account_name(), presence_type); connection_set_priority(pri); diff --git a/src/xmpp/session.c b/src/xmpp/session.c index 032ca77a..ea6a8a7f 100644 --- a/src/xmpp/session.c +++ b/src/xmpp/session.c @@ -412,10 +412,11 @@ session_check_autoaway(void) // send away presence with last activity char *message = prefs_get_string(PREF_AUTOAWAY_MESSAGE); + connection_set_presence_msg(message); if (prefs_get_boolean(PREF_LASTACTIVITY)) { - cl_ev_presence_send(RESOURCE_AWAY, message, idle_ms / 1000); + cl_ev_presence_send(RESOURCE_AWAY, idle_ms / 1000); } else { - cl_ev_presence_send(RESOURCE_AWAY, message, 0); + cl_ev_presence_send(RESOURCE_AWAY, 0); } int pri = accounts_get_priority_for_presence_type(account, RESOURCE_AWAY); @@ -432,7 +433,8 @@ session_check_autoaway(void) activity_state = ACTIVITY_ST_IDLE; // send current presence with last activity - cl_ev_presence_send(curr_presence, curr_status, idle_ms / 1000); + connection_set_presence_msg(curr_status); + cl_ev_presence_send(curr_presence, idle_ms / 1000); } } break; @@ -443,7 +445,8 @@ session_check_autoaway(void) cons_show("No longer idle."); // send current presence without last activity - cl_ev_presence_send(curr_presence, curr_status, 0); + connection_set_presence_msg(curr_status); + cl_ev_presence_send(curr_presence, 0); } break; case ACTIVITY_ST_AWAY: @@ -452,10 +455,11 @@ session_check_autoaway(void) // send extended away presence with last activity char *message = prefs_get_string(PREF_AUTOXA_MESSAGE); + connection_set_presence_msg(message); if (prefs_get_boolean(PREF_LASTACTIVITY)) { - cl_ev_presence_send(RESOURCE_XA, message, idle_ms / 1000); + cl_ev_presence_send(RESOURCE_XA, idle_ms / 1000); } else { - cl_ev_presence_send(RESOURCE_XA, message, 0); + cl_ev_presence_send(RESOURCE_XA, 0); } int pri = accounts_get_priority_for_presence_type(account, RESOURCE_XA); @@ -473,7 +477,8 @@ session_check_autoaway(void) cons_show("No longer idle."); // send saved presence without last activity - cl_ev_presence_send(saved_presence, saved_status, 0); + connection_set_presence_msg(saved_status); + cl_ev_presence_send(saved_presence, 0); contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence); title_bar_set_presence(contact_pres); } @@ -485,7 +490,8 @@ session_check_autoaway(void) cons_show("No longer idle."); // send saved presence without last activity - cl_ev_presence_send(saved_presence, saved_status, 0); + connection_set_presence_msg(saved_status); + cl_ev_presence_send(saved_presence, 0); contact_presence_t contact_pres = contact_presence_from_resource_presence(saved_presence); title_bar_set_presence(contact_pres); } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 7302b279..c70fd4dd 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -120,6 +120,7 @@ char* session_get_account_name(void); jabber_conn_status_t connection_get_status(void); char *connection_get_presence_msg(void); +void connection_set_presence_msg(const char *const message); const char* connection_get_fulljid(void); char* connection_create_uuid(void); void connection_free_uuid(char *uuid); @@ -153,7 +154,7 @@ char* presence_sub_request_find(const char *const search_str); void presence_join_room(const char *const room, const char *const nick, const char *const passwd); void presence_change_room_nick(const char *const room, const char *const nick); void presence_leave_chat_room(const char *const room_jid); -void presence_send(resource_presence_t status, const char *const msg, int idle, char *signed_status); +void presence_send(resource_presence_t status, int idle, char *signed_status); gboolean presence_sub_request_exists(const char *const bare_jid); void iq_enable_carbons(void); diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index ef9f0e39..1e01071d 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -52,6 +52,7 @@ int main(int argc, char* argv[]) { PROF_FUNC_TEST(presence_chat_with_message), PROF_FUNC_TEST(presence_set_priority), PROF_FUNC_TEST(presence_includes_priority), + PROF_FUNC_TEST(presence_keeps_status), PROF_FUNC_TEST(presence_received), PROF_FUNC_TEST(presence_missing_resource_defaults), diff --git a/tests/functionaltests/test_presence.c b/tests/functionaltests/test_presence.c index 97cf168c..bf0171a7 100644 --- a/tests/functionaltests/test_presence.c +++ b/tests/functionaltests/test_presence.c @@ -227,6 +227,33 @@ presence_includes_priority(void **state) assert_true(prof_output_exact("Status set to chat (priority 25), \"Free to talk\".")); } +void +presence_keeps_status(void **state) +{ + prof_connect(); + + prof_input("/chat \"Free to talk\""); + assert_true(stbbr_received( + "" + "chat" + "Free to talk" + "" + "" + )); + assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\".")); + + prof_input("/priority 25"); + assert_true(stbbr_received( + "" + "chat" + "Free to talk" + "25" + "" + "" + )); + assert_true(prof_output_exact("Priority set to 25.")); +} + void presence_received(void **state) { diff --git a/tests/functionaltests/test_presence.h b/tests/functionaltests/test_presence.h index 7df362bf..107fa794 100644 --- a/tests/functionaltests/test_presence.h +++ b/tests/functionaltests/test_presence.h @@ -10,5 +10,6 @@ void presence_chat(void **state); void presence_chat_with_message(void **state); void presence_set_priority(void **state); void presence_includes_priority(void **state); +void presence_keeps_status(void **state); void presence_received(void **state); void presence_missing_resource_defaults(void **state); diff --git a/tests/unittests/test_cmd_account.c b/tests/unittests/test_cmd_account.c index 0b723bde..9e7ae197 100644 --- a/tests/unittests/test_cmd_account.c +++ b/tests/unittests/test_cmd_account.c @@ -806,17 +806,15 @@ void cmd_account_set_priority_updates_presence_when_account_connected_with_prese expect_any(accounts_get_account, name); will_return(accounts_get_account, account); #endif - will_return(connection_get_presence_msg, "Free to chat"); - expect_value(presence_send, status, RESOURCE_ONLINE); - expect_string(presence_send, msg, "Free to chat"); expect_value(presence_send, idle, 0); expect_value(presence_send, signed_status, NULL); expect_cons_show("Updated online priority for account a_account: 10"); expect_cons_show(""); + gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args); assert_true(result); } diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c index e4ef7ea1..38f7428e 100644 --- a/tests/unittests/xmpp/stub_xmpp.c +++ b/tests/unittests/xmpp/stub_xmpp.c @@ -78,6 +78,8 @@ GList * session_get_available_resources(void) return NULL; } +void connection_set_presence_msg(const char *const message) {} + gboolean connection_send_stanza(const char *const stanza) { @@ -153,10 +155,9 @@ void presence_join_room(const char *const room, const char *const nick, const ch void presence_change_room_nick(const char * const room, const char * const nick) {} void presence_leave_chat_room(const char * const room_jid) {} -void presence_send(resource_presence_t status, const char * const msg, int idle, char *signed_status) +void presence_send(resource_presence_t status, int idle, char *signed_status) { check_expected(status); - check_expected(msg); check_expected(idle); check_expected(signed_status); }