1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into osx-functional

Conflicts:
	tests/functionaltests/proftest.c
This commit is contained in:
James Booth 2016-11-22 00:42:50 +00:00
commit 97d57cd8c0
17 changed files with 75 additions and 40 deletions

View File

@ -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");

View File

@ -1990,7 +1990,8 @@ static struct cmd_t command_defs[] =
"/account clear <account> otr",
"/account clear <account> pgpkeyid",
"/account clear <account> startscript",
"/account clear <account> muc")
"/account clear <account> muc",
"/account clear <account> 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 <account> pgpkeyid", "Remove pgpkeyid associated with this account." },
{ "clear <account> startscript", "Remove startscript associated with this account." },
{ "clear <account> theme", "Clear the theme setting for the account, the global theme will be used." },
{ "clear <account> resource", "Remove the resource setting for this account."},
{ "clear <account> muc", "Remove the default MUC service setting."})
CMD_EXAMPLES(
"/account add me",

View File

@ -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("");

View File

@ -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);

View File

@ -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);

View File

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

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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();
}

View File

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

View File

@ -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);

View File

@ -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);

View File

@ -118,15 +118,22 @@ session_connect_with_account(const ProfAccount *const account)
}
saved_account.passwd = strdup(account->password);
// connect with fulljid
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);
}

View File

@ -285,7 +285,7 @@ prof_connect_with_roster(char *roster)
// Allow time for profanity to connect
exp_timeout = 30;
assert_true(prof_output_glob("stabber@localhost logged in successfully, *online* (priority 0)."));
assert_true(prof_output_glob("stabber@localhost/profanity logged in successfully, *online* (priority 0)."));
exp_timeout = 10;
stbbr_wait_for("prof_presence_*");
}

View File

@ -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."));

View File

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