feat(xmpp): add comprehensive connection debug logging
Some checks failed
CI Code / Check spelling (pull_request) Successful in 33s
CI Code / Check coding style (pull_request) Failing after 2m13s
CI Code / Linux (arch) (pull_request) Successful in 10m20s
CI Code / Linux (debian) (pull_request) Successful in 14m41s
CI Code / Linux (ubuntu) (pull_request) Successful in 15m26s

Add detailed debug output tracking connection lifecycle, autoping events,
and session state transitions with timestamps and counters.

- Track connection attempts, successes, disconnects, and reconnects
- Log autoping timer events, responses, and timeouts
- Record session login, logout, and reconnection attempts
- Add elapsed time calculations since key events
- Use [CONNDBG] tag for easy log filtering

Files: connection.c, iq.c, session.c, connection.h
This commit is contained in:
2025-11-20 11:36:56 +03:00
parent 74cfd32c1e
commit 12ae019394
4 changed files with 285 additions and 1 deletions

View File

@@ -39,9 +39,11 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <time.h>
#include <strophe.h>
@@ -84,6 +86,74 @@ static ProfConnection conn;
static gchar* profanity_instance_id = NULL;
static gchar* prof_identifier = NULL;
// Extended debug tracking
static time_t prof_last_connect_attempt_ts = 0; // when connection_connect was last called
static time_t prof_last_successful_connect_ts = 0; // when we last transitioned to CONNECT/RAW_CONNECT
static time_t prof_last_disconnect_ts = 0; // when we last transitioned to DISCONNECT
static unsigned long prof_connect_attempt_counter = 0; // total calls to connection_connect
static unsigned long prof_successful_connect_counter = 0; // successful CONNECTs
static unsigned long prof_reconnect_counter = 0; // times we forced a reconnect (XMPP_CONN_RECONNECT logic)
// helper to format elapsed seconds (returns "n/a" if base == 0)
char*
_connection_format_elapsed_time(time_t base, time_t now, char* buf, size_t len)
{
if (base == 0) {
snprintf(buf, len, "n/a");
} else {
snprintf(buf, len, "%lds", (long)(now - base));
}
return buf;
}
static void
_log_event_header(const char* tag)
{
time_t now = time(NULL);
struct tm tm_now;
localtime_r(&now, &tm_now);
char ts[32];
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", &tm_now);
char elapsed_success[32];
char elapsed_disconnect[32];
_connection_format_elapsed_time(prof_last_successful_connect_ts, now, elapsed_success, sizeof(elapsed_success));
_connection_format_elapsed_time(prof_last_disconnect_ts, now, elapsed_disconnect, sizeof(elapsed_disconnect));
log_debug("[CONNDBG] %s ts=%s attempts=%lu successes=%lu reconnects=%lu elapsed-since-success=%s elapsed-since-disconnect=%s", tag, ts,
prof_connect_attempt_counter, prof_successful_connect_counter, prof_reconnect_counter,
elapsed_success, elapsed_disconnect);
}
// Helper to log connection details
static void
_log_connection_details(const char* jid, const char* altdomain, int port,
const char* tls_policy, const char* auth_policy)
{
char elapsed_disconnect[32];
time_t now = time(NULL);
_connection_format_elapsed_time(prof_last_disconnect_ts, now, elapsed_disconnect, sizeof(elapsed_disconnect));
log_debug("[CONNDBG] details jid=%s altdomain=%s port=%d tls_policy=%s auth_policy=%s attempt#=%lu since-last-disconnect=%s", jid,
altdomain ? altdomain : "(default)", port, tls_policy ? tls_policy : "(default)",
auth_policy ? auth_policy : "(default)", prof_connect_attempt_counter, elapsed_disconnect);
}
// Helper to log connection status with formatted extra info
static void
_log_connection_status_simple(const char* event, const char* jid, gboolean secured, long flags, const char* format, ...)
{
auto_gchar gchar* extra_info = NULL;
if (format) {
va_list args;
va_start(args, format);
extra_info = g_strdup_vprintf(format, args);
va_end(args);
}
log_debug("[CONNDBG] %s jid=%s secured=%d flags=0x%lx %s", event, jid ? jid : "(null)", secured, flags, extra_info ? extra_info : "");
}
static void _xmpp_file_logger(void* const userdata, const xmpp_log_level_t level, const char* const area, const char* const msg);
static void _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status, const int error,
@@ -267,7 +337,12 @@ connection_connect(const char* const jid, const char* const passwd, const char*
{
assert(jid != NULL);
assert(passwd != NULL);
prof_connect_attempt_counter++;
prof_last_connect_attempt_ts = time(NULL);
_log_event_header("CONNECT_ATTEMPT");
log_info("Connecting as %s", jid);
_log_connection_details(jid, altdomain, port, tls_policy, auth_policy);
_conn_apply_settings(jid, passwd, tls_policy, auth_policy);
@@ -280,8 +355,10 @@ connection_connect(const char* const jid, const char* const passwd, const char*
if (connect_status == 0) {
conn.conn_status = JABBER_CONNECTING;
log_debug("[CONNDBG] libstrophe connect_client returned success (async). status=JABBER_CONNECTING flags=0x%lx", xmpp_conn_get_flags(conn.xmpp_conn));
} else {
conn.conn_status = JABBER_DISCONNECTED;
log_debug("[CONNDBG] libstrophe connect_client returned failure (sync). status=JABBER_DISCONNECTED error=%d", connect_status);
}
return conn.conn_status;
@@ -974,8 +1051,15 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
// login success
case XMPP_CONN_CONNECT:
_log_event_header("CONNECT_SUCCESS");
log_debug("Connection handler: XMPP_CONN_CONNECT");
conn.conn_status = JABBER_CONNECTED;
prof_successful_connect_counter++;
prof_last_successful_connect_ts = time(NULL);
_log_connection_status_simple("connected", xmpp_conn_get_jid(conn.xmpp_conn), xmpp_conn_is_secured(xmpp_conn),
xmpp_conn_get_flags(conn.xmpp_conn),
conn.queued_messages ? "queued_messages=yes" : "queued_messages=no");
connection_get_jid();
conn.domain = strdup(conn.jid->domainpart);
@@ -1000,8 +1084,14 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
// raw connection success
case XMPP_CONN_RAW_CONNECT:
_log_event_header("RAW_CONNECT_SUCCESS");
log_debug("Connection handler: XMPP_CONN_RAW_CONNECT");
conn.conn_status = JABBER_RAW_CONNECTED;
prof_successful_connect_counter++;
prof_last_successful_connect_ts = time(NULL);
_log_connection_status_simple("raw connected", xmpp_conn_get_jid(conn.xmpp_conn), FALSE,
xmpp_conn_get_flags(conn.xmpp_conn), "");
connection_get_jid();
conn.jid = jid_create(xmpp_conn_get_jid(conn.xmpp_conn));
@@ -1018,13 +1108,25 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
// disconnected
case XMPP_CONN_DISCONNECT:
_log_event_header("DISCONNECT_EVENT");
log_debug("Connection handler: XMPP_CONN_DISCONNECT");
_log_connection_status_simple("disconnect", NULL, FALSE, 0,
"previous_status=%d error=%d has_stream_error=%s",
(int)conn.conn_status, error,
(stream_error && stream_error->stanza) ? "yes" : "no");
prof_last_disconnect_ts = time(NULL);
// lost connection for unknown reason
if (conn.conn_status == JABBER_CONNECTED || conn.conn_status == JABBER_DISCONNECTING) {
if (prefs_get_boolean(PREF_STROPHE_SM_ENABLED)) {
int send_queue_len = xmpp_conn_send_queue_len(conn.xmpp_conn);
log_debug("Connection handler: Lost connection for unknown reason, %d messages in send queue", send_queue_len);
log_debug("[CONNDBG] SM enabled=%d resend_pref=%d send_queue_len=%d",
prefs_get_boolean(PREF_STROPHE_SM_ENABLED),
prefs_get_boolean(PREF_STROPHE_SM_RESEND),
send_queue_len);
conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn);
if (send_queue_len > 0 && prefs_get_boolean(PREF_STROPHE_SM_RESEND)) {
conn.queued_messages = calloc(send_queue_len + 1, sizeof(*conn.queued_messages));
@@ -1045,6 +1147,10 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
if (stream_error && stream_error->stanza && _get_other_host(stream_error->stanza, &host, &port)) {
session_reconnect(host, port);
log_debug("Connection handler: Forcing a re-connect to \"%s\"", host);
prof_reconnect_counter++;
log_debug("[CONNDBG] trigger=see-other-host host=%s port=%d reconnect_counter=%lu",
host, port, prof_reconnect_counter);
conn.conn_status = JABBER_RECONNECT;
return;
}
@@ -1059,7 +1165,10 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
// connection failed
case XMPP_CONN_FAIL:
_log_event_header("CONNECT_FAIL_EVENT");
log_debug("Connection handler: XMPP_CONN_FAIL");
_log_connection_status_simple("fail", NULL, FALSE, 0, "previous_status=%d error=%d", (int)conn.conn_status, error);
break;
// unknown state
@@ -1193,3 +1302,10 @@ connection_debug_print_features()
log_debug("=== End of Features ===");
}
// --- Extended debug accessors ---
time_t connection_last_successful_connect_ts(void) { return prof_last_successful_connect_ts; }
time_t connection_last_disconnect_ts(void) { return prof_last_disconnect_ts; }
unsigned long connection_connect_attempts(void) { return prof_connect_attempt_counter; }
unsigned long connection_successful_connects(void) { return prof_successful_connect_counter; }
unsigned long connection_reconnect_counter(void) { return prof_reconnect_counter; }

View File

@@ -37,6 +37,7 @@
#define XMPP_CONNECTION_H
#include "xmpp/xmpp.h"
#include <time.h>
#define CON_RAND_ID_LEN 15
@@ -68,4 +69,13 @@ void connection_remove_available_resource(const char* const resource);
char* connection_create_stanza_id(void);
// Extended debug accessors
time_t connection_last_successful_connect_ts(void);
time_t connection_last_disconnect_ts(void);
unsigned long connection_connect_attempts(void);
unsigned long connection_successful_connects(void);
unsigned long connection_reconnect_counter(void);
char* _connection_format_elapsed_time(time_t base, time_t now, char* buf, size_t len);
#endif

View File

@@ -38,6 +38,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <glib.h>
#include <strophe.h>
@@ -172,6 +173,32 @@ static GHashTable* rooms_cache = NULL;
static GSList* late_delivery_windows = NULL;
static gboolean received_disco_items = FALSE;
static void
_iq_get_debug_stats(time_t* now_out, char* elapsed_connect, size_t len)
{
time_t now = time(NULL);
time_t last_success = connection_last_successful_connect_ts();
if (now_out) *now_out = now;
_connection_format_elapsed_time(last_success, now, elapsed_connect, len);
}
// Helper function to log autoping debug info
static void
_iq_log_autoping_debug(const char* event, const char* extra_info)
{
time_t now;
char elapsed_connect[32];
_iq_get_debug_stats(&now, elapsed_connect, sizeof(elapsed_connect));
if (extra_info) {
log_debug("[CONNDBG] %s ts=%ld elapsed-since-connect=%s %s",
event, (long)now, elapsed_connect, extra_info);
} else {
log_debug("[CONNDBG] %s ts=%ld elapsed-since-connect=%s",
event, (long)now, elapsed_connect);
}
}
static int
_iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata)
{
@@ -371,6 +398,10 @@ iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback
void
iq_autoping_timer_cancel(void)
{
gdouble elapsed = autoping_time ? g_timer_elapsed(autoping_time, NULL) : 0.0;
auto_gchar gchar* extra = g_strdup_printf("was_waiting=%d elapsed=%.3fs", autoping_wait, elapsed);
_iq_log_autoping_debug("AUTOPING_TIMER_CANCEL", extra);
autoping_wait = FALSE;
if (autoping_time) {
g_timer_destroy(autoping_time);
@@ -397,6 +428,9 @@ iq_autoping_check(void)
unsigned long seconds_elapsed = elapsed * 1.0;
gint timeout = prefs_get_autoping_timeout();
if (timeout > 0 && seconds_elapsed >= timeout) {
auto_gchar gchar* extra = g_strdup_printf("elapsed=%.1fs timeout=%ds", elapsed, timeout);
_iq_log_autoping_debug("AUTOPING_TIMEOUT", extra);
cons_show("Autoping response timed out after %u seconds.", timeout);
log_debug("Autoping check: timed out after %u seconds, disconnecting", timeout);
iq_autoping_timer_cancel();
@@ -408,6 +442,8 @@ void
iq_set_autoping(const int seconds)
{
if (connection_get_status() != JABBER_CONNECTED) {
auto_gchar gchar* extra = g_strdup_printf("seconds=%d reason=not_connected", seconds);
_iq_log_autoping_debug("AUTOPING_SET_SKIPPED", extra);
return;
}
@@ -415,9 +451,14 @@ iq_set_autoping(const int seconds)
xmpp_timed_handler_delete(conn, _autoping_timed_send);
if (seconds == 0) {
_iq_log_autoping_debug("AUTOPING_DISABLED", "seconds=0");
return;
}
int timeout = prefs_get_autoping_timeout();
auto_gchar gchar* extra = g_strdup_printf("interval=%ds timeout=%ds", seconds, timeout);
_iq_log_autoping_debug("AUTOPING_SET", extra);
int millis = seconds * 1000;
xmpp_ctx_t* const ctx = connection_get_ctx();
xmpp_timed_handler_add(conn, _autoping_timed_send, millis, ctx);
@@ -1426,9 +1467,16 @@ _autoping_timed_send(xmpp_conn_t* const conn, void* const userdata)
return 1;
}
int autoping_interval = prefs_get_autoping();
int autoping_timeout = prefs_get_autoping_timeout();
auto_gchar gchar* extra = g_strdup_printf("interval=%ds timeout=%ds", autoping_interval, autoping_timeout);
_iq_log_autoping_debug("AUTOPING_TIMER_FIRED", extra);
if (connection_supports(XMPP_FEATURE_PING) == FALSE) {
// TODO: do we need to check it on each autoping call?
log_warning("Server doesn't advertise %s feature.", XMPP_FEATURE_PING);
auto_gchar gchar* feat_extra = g_strdup_printf("feature=%s", XMPP_FEATURE_PING);
_iq_log_autoping_debug("AUTOPING_FEATURE_MISSING", feat_extra);
if (!autoping_error_shown) {
connection_debug_print_features();
cons_show_error("Server ping not supported (%s). Check log for details.", XMPP_FEATURE_PING);
@@ -1438,6 +1486,7 @@ _autoping_timed_send(xmpp_conn_t* const conn, void* const userdata)
if (autoping_wait) {
log_debug("Autoping: Existing ping already in progress, aborting");
_iq_log_autoping_debug("AUTOPING_ALREADY_PENDING", NULL);
return 1;
}
@@ -1445,6 +1494,9 @@ _autoping_timed_send(xmpp_conn_t* const conn, void* const userdata)
xmpp_stanza_t* iq = stanza_create_ping_iq(ctx, NULL);
const char* id = xmpp_stanza_get_id(iq);
log_debug("Autoping: Sending ping request: %s", id);
auto_gchar gchar* send_extra = g_strdup_printf("id=%s timeout=%ds", id, autoping_timeout);
_iq_log_autoping_debug("AUTOPING_SEND", send_extra);
// add pong handler
iq_id_handler_add(id, _auto_pong_id_handler, NULL, NULL);
@@ -1463,8 +1515,12 @@ _autoping_timed_send(xmpp_conn_t* const conn, void* const userdata)
void
autoping_timer_extend(void)
{
if (autoping_time)
if (autoping_time) {
gdouble elapsed = g_timer_elapsed(autoping_time, NULL);
auto_gchar gchar* extra = g_strdup_printf("elapsed_before_reset=%.3fs", elapsed);
_iq_log_autoping_debug("AUTOPING_TIMER_EXTEND", extra);
g_timer_start(autoping_time);
}
}
static int
@@ -1473,8 +1529,12 @@ _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
iq_autoping_timer_cancel();
const char* id = xmpp_stanza_get_id(stanza);
gdouble response_time = autoping_time ? g_timer_elapsed(autoping_time, NULL) : 0.0;
if (id == NULL) {
log_debug("Autoping: Pong handler fired.");
auto_gchar gchar* extra = g_strdup_printf("id=(null) response_time=%.3fs", response_time);
_iq_log_autoping_debug("AUTOPING_PONG_RECEIVED", extra);
return 0;
}
@@ -1482,15 +1542,21 @@ _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
const char* type = xmpp_stanza_get_type(stanza);
if (type == NULL) {
auto_gchar gchar* extra = g_strdup_printf("id=%s response_time=%.3fs type=(null)", id, response_time);
_iq_log_autoping_debug("AUTOPING_PONG_RECEIVED", extra);
return 0;
}
if (g_strcmp0(type, STANZA_TYPE_ERROR) != 0) {
auto_gchar gchar* extra = g_strdup_printf("id=%s response_time=%.3fs type=%s", id, response_time, type);
_iq_log_autoping_debug("AUTOPING_PONG_SUCCESS", extra);
return 0;
}
// show warning if error
auto_char char* error_msg = stanza_get_error_message(stanza);
log_warning("Server ping (id=%s) responded with error: %s", id, error_msg);
auto_gchar gchar* err_extra = g_strdup_printf("id=%s response_time=%.3fs error=%s", id, response_time, error_msg);
_iq_log_autoping_debug("AUTOPING_PONG_ERROR", err_extra);
// turn off autoping if error type is 'cancel'
xmpp_stanza_t* error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
@@ -1503,6 +1569,8 @@ _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
}
if (g_strcmp0(errtype, STANZA_TYPE_CANCEL) == 0) {
log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id);
auto_gchar gchar* disable_extra = g_strdup_printf("id=%s errtype=cancel", id);
_iq_log_autoping_debug("AUTOPING_DISABLED", disable_extra);
prefs_set_autoping(0);
cons_show_error("Autoping is not supported by the server (stanza cancelled). The feature has been disabled automatically.");
xmpp_timed_handler_delete(connection_get_conn(), _autoping_timed_send);

View File

@@ -38,6 +38,7 @@
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "profanity.h"
#include "log.h"
@@ -95,6 +96,72 @@ static GTimer* reconnect_timer;
static activity_state_t activity_state;
static resource_presence_t saved_presence;
static char* saved_status;
static unsigned long session_reconnect_attempt_counter = 0; // extended debug counter
static void
_session_get_debug_stats(time_t* now_out, char* elapsed_success, size_t success_len, char* elapsed_disconnect, size_t disconnect_len)
{
time_t now = time(NULL);
time_t last_success = connection_last_successful_connect_ts();
time_t last_disc = connection_last_disconnect_ts();
if (now_out) *now_out = now;
_connection_format_elapsed_time(last_success, now, elapsed_success, success_len);
_connection_format_elapsed_time(last_disc, now, elapsed_disconnect, disconnect_len);
}
// Helper function to log connection debug info
static void
_session_log_connect_debug(const char* event, const char* account, const char* jid,
const char* server, int port, const char* tls_policy, const char* auth_policy)
{
time_t now;
char elapsed_success[32];
char elapsed_disconnect[32];
_session_get_debug_stats(&now, elapsed_success, sizeof(elapsed_success), elapsed_disconnect, sizeof(elapsed_disconnect));
log_debug("[CONNDBG] %s ts=%ld account=%s jid=%s server=%s port=%d tls_policy=%s auth_policy=%s elapsed-since-success=%s elapsed-since-disconnect=%s total-attempts=%lu total-success=%lu",
event, (long)now, account ? account : "(none)", jid ? jid : "(none)",
server ? server : "(default)", port,
tls_policy ? tls_policy : "(default)",
auth_policy ? auth_policy : "(default)",
elapsed_success, elapsed_disconnect,
connection_connect_attempts(), connection_successful_connects());
}
// Helper function to log session state debug info
static void
_session_log_state_debug(const char* event, int extra_param)
{
time_t now;
char elapsed_success[32];
char elapsed_disconnect[32];
_session_get_debug_stats(&now, elapsed_success, sizeof(elapsed_success), elapsed_disconnect, sizeof(elapsed_disconnect));
log_debug("[CONNDBG] %s ts=%ld param=%d account=%s elapsed-since-success=%s elapsed-since-disconnect=%s total-attempts=%lu total-success=%lu session-reconnects=%lu",
event, (long)now, extra_param,
saved_account.name ? saved_account.name : "(none)",
elapsed_success, elapsed_disconnect,
connection_connect_attempts(), connection_successful_connects(),
session_reconnect_attempt_counter);
}
// Helper function to log reconnect attempt
static void
_session_log_reconnect_debug(unsigned long attempt_num, const char* account, const char* jid,
const char* server, unsigned short port, const char* tls_policy, const char* auth_policy)
{
time_t now;
char elapsed_success[32];
char elapsed_disconnect[32];
_session_get_debug_stats(&now, elapsed_success, sizeof(elapsed_success), elapsed_disconnect, sizeof(elapsed_disconnect));
log_debug("[CONNDBG] RECONNECT_ATTEMPT #%lu ts=%ld account=%s jid=%s server=%s port=%u tls_policy=%s auth_policy=%s elapsed-since-success=%s elapsed-since-disconnect=%s total-connect-attempts=%lu total-success=%lu global-reconnects=%lu",
attempt_num, (long)now, account, jid, server ? server : "(null)", port,
tls_policy ? tls_policy : "(default)", auth_policy ? auth_policy : "(default)",
elapsed_success, elapsed_disconnect,
connection_connect_attempts(), connection_successful_connects(), connection_reconnect_counter());
}
static void _session_free_internals(void);
static void _session_free_saved_details(void);
@@ -133,6 +200,8 @@ session_connect_with_account(const ProfAccount* const account)
assert(account != NULL);
log_info("Connecting using account: %s", account->name);
_session_log_connect_debug("SESSION_CONNECT_WITH_ACCOUNT", account->name, account->jid,
account->server, account->port, account->tls_policy, account->auth_policy);
_session_free_internals();
@@ -166,6 +235,9 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
assert(jid != NULL);
assert(passwd != NULL);
_session_log_connect_debug("SESSION_CONNECT_WITH_DETAILS", NULL, jid,
altdomain, port, tls_policy, auth_policy);
_session_free_internals();
// save details for reconnect, remember name for account creating on success
@@ -218,12 +290,17 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
void
session_autoping_fail(void)
{
int autoping_timeout = prefs_get_autoping_timeout();
_session_log_state_debug("SESSION_AUTOPING_FAIL", autoping_timeout);
session_lost_connection();
}
void
session_disconnect(void)
{
jabber_conn_status_t conn_status = connection_get_status();
_session_log_state_debug("SESSION_DISCONNECT", (int)conn_status);
// if connected, send end stream and wait for response
if (connection_get_status() == JABBER_CONNECTED) {
log_info("Closing connection");
@@ -319,6 +396,8 @@ _receive_mood(xmpp_stanza_t* const stanza, void* const userdata)
void
session_login_success(gboolean secured)
{
_session_log_state_debug("SESSION_LOGIN_SUCCESS", secured);
chat_sessions_init();
message_handlers_init();
@@ -370,6 +449,8 @@ session_login_success(gboolean secured)
void
session_login_failed(void)
{
_session_log_state_debug("SESSION_LOGIN_FAILED", reconnect_timer != NULL);
if (reconnect_timer == NULL) {
log_debug("Connection handler: No reconnect timer");
sv_ev_failed_login();
@@ -389,12 +470,17 @@ session_login_failed(void)
void
session_lost_connection(void)
{
int reconnect_sec = prefs_get_reconnect();
_session_log_state_debug("SESSION_LOST_CONNECTION", reconnect_sec);
/* this callback also clears all cached data */
sv_ev_lost_connection();
if (prefs_get_reconnect() != 0) {
assert(reconnect_timer == NULL);
reconnect_timer = g_timer_new();
log_debug("[CONNDBG] created reconnect timer, will reconnect in %d seconds", reconnect_sec);
} else {
log_debug("[CONNDBG] reconnect disabled, freeing session internals");
_session_free_internals();
}
}
@@ -574,6 +660,10 @@ session_reconnect_now(void)
port = account->port;
}
session_reconnect_attempt_counter++;
_session_log_reconnect_debug(session_reconnect_attempt_counter, account->name, jid,
server, port, account->tls_policy, account->auth_policy);
log_debug("Attempting reconnect with account %s", account->name);
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
account_free(account);