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) {