Skip to content

Commit e02e8c3

Browse files
committed
Fix reconnect when no account has been set up yet.
e.g. if one connects with an account for the first time and the server returns a `see-other-host` error. Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 0aa719c commit e02e8c3

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

src/xmpp/session.c

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static struct
7373
char* passwd;
7474
} saved_account;
7575

76-
static struct
76+
static struct session_details
7777
{
7878
char* name;
7979
char* jid;
@@ -159,6 +159,18 @@ session_connect_with_account(const ProfAccount* const account)
159159
return result;
160160
}
161161

162+
static jabber_conn_status_t
163+
_session_connect(struct session_details* details)
164+
{
165+
return connection_connect(
166+
details->jid,
167+
details->passwd,
168+
details->altdomain,
169+
details->port,
170+
details->tls_policy,
171+
details->auth_policy);
172+
}
173+
162174
jabber_conn_status_t
163175
session_connect_with_details(const char* const jid, const char* const passwd, const char* const altdomain,
164176
const int port, const char* const tls_policy, const char* const auth_policy)
@@ -206,13 +218,7 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
206218
// connect with fulljid
207219
log_info("Connecting without account, JID: %s", saved_details.jid);
208220

209-
return connection_connect(
210-
saved_details.jid,
211-
passwd,
212-
saved_details.altdomain,
213-
saved_details.port,
214-
saved_details.tls_policy,
215-
saved_details.auth_policy);
221+
return _session_connect(&saved_details);
216222
}
217223

218224
void
@@ -552,31 +558,35 @@ void
552558
session_reconnect_now(void)
553559
{
554560
// reconnect with account.
555-
ProfAccount* account = accounts_get_account(saved_account.name);
556-
if (account == NULL) {
557-
log_error("Unable to reconnect, account no longer exists: %s", saved_account.name);
558-
return;
559-
}
561+
if (saved_account.name) {
562+
ProfAccount* account = accounts_get_account(saved_account.name);
563+
if (account == NULL) {
564+
log_error("Unable to reconnect, account no longer exists: %s", saved_account.name);
565+
return;
566+
}
560567

561-
auto_char char* jid = NULL;
562-
if (account->resource) {
563-
jid = create_fulljid(account->jid, account->resource);
564-
} else {
565-
jid = strdup(account->jid);
566-
}
567-
const char* server;
568-
unsigned short port;
569-
if (reconnect.altdomain) {
570-
server = reconnect.altdomain;
571-
port = reconnect.altport;
568+
auto_char char* jid = NULL;
569+
if (account->resource) {
570+
jid = create_fulljid(account->jid, account->resource);
571+
} else {
572+
jid = strdup(account->jid);
573+
}
574+
const char* server;
575+
unsigned short port;
576+
if (reconnect.altdomain) {
577+
server = reconnect.altdomain;
578+
port = reconnect.altport;
579+
} else {
580+
server = account->server;
581+
port = account->port;
582+
}
583+
584+
log_debug("Attempting reconnect with account %s", account->name);
585+
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
586+
account_free(account);
572587
} else {
573-
server = account->server;
574-
port = account->port;
588+
_session_connect(&saved_details);
575589
}
576-
577-
log_debug("Attempting reconnect with account %s", account->name);
578-
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
579-
account_free(account);
580590
if (reconnect_timer)
581591
g_timer_start(reconnect_timer);
582592
}

0 commit comments

Comments
 (0)