fix(xmpp): clang-tidy warnings for extended debug info

This commit is contained in:
2025-11-20 11:45:21 +03:00
parent 12ae019394
commit 4933e1cff9
3 changed files with 62 additions and 40 deletions

View File

@@ -87,12 +87,12 @@ 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 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)
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*
@@ -114,7 +114,7 @@ _log_event_header(const char* tag)
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));
@@ -127,7 +127,7 @@ _log_event_header(const char* tag)
// Helper to log connection details
static void
_log_connection_details(const char* jid, const char* altdomain, int port,
_log_connection_details(const char* jid, const char* altdomain, int port,
const char* tls_policy, const char* auth_policy)
{
char elapsed_disconnect[32];
@@ -135,7 +135,7 @@ _log_connection_details(const char* jid, const char* altdomain, int port,
_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)",
altdomain ? altdomain : "(default)", port, tls_policy ? tls_policy : "(default)",
auth_policy ? auth_policy : "(default)", prof_connect_attempt_counter, elapsed_disconnect);
}
@@ -150,7 +150,7 @@ _log_connection_status_simple(const char* event, const char* jid, gboolean secur
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 : "");
}
@@ -341,7 +341,7 @@ connection_connect(const char* const jid, const char* const passwd, const char*
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);
@@ -1056,9 +1056,9 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
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),
_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();
@@ -1089,7 +1089,7 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
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), "");
@@ -1110,10 +1110,10 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
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,
_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);
@@ -1122,11 +1122,11 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
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),
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));
@@ -1148,9 +1148,9 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
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",
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;
}
@@ -1167,7 +1167,7 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
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;
@@ -1304,8 +1304,28 @@ connection_debug_print_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; }
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

@@ -178,7 +178,8 @@ _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;
if (now_out)
*now_out = now;
_connection_format_elapsed_time(last_success, now, elapsed_connect, len);
}
@@ -401,7 +402,7 @@ 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);
@@ -1494,7 +1495,7 @@ _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);
@@ -1530,7 +1531,7 @@ _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata)
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);

View File

@@ -105,7 +105,8 @@ _session_get_debug_stats(time_t* now_out, char* elapsed_success, size_t success_
time_t last_success = connection_last_successful_connect_ts();
time_t last_disc = connection_last_disconnect_ts();
if (now_out) *now_out = now;
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);
}
@@ -113,7 +114,7 @@ _session_get_debug_stats(time_t* now_out, char* elapsed_success, size_t success_
// 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)
const char* server, int port, const char* tls_policy, const char* auth_policy)
{
time_t now;
char elapsed_success[32];
@@ -149,7 +150,7 @@ _session_log_state_debug(const char* event, int extra_param)
// 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)
const char* server, unsigned short port, const char* tls_policy, const char* auth_policy)
{
time_t now;
char elapsed_success[32];
@@ -201,7 +202,7 @@ session_connect_with_account(const ProfAccount* const account)
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);
account->server, account->port, account->tls_policy, account->auth_policy);
_session_free_internals();
@@ -236,7 +237,7 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
assert(passwd != NULL);
_session_log_connect_debug("SESSION_CONNECT_WITH_DETAILS", NULL, jid,
altdomain, port, tls_policy, auth_policy);
altdomain, port, tls_policy, auth_policy);
_session_free_internals();
@@ -662,7 +663,7 @@ session_reconnect_now(void)
session_reconnect_attempt_counter++;
_session_log_reconnect_debug(session_reconnect_attempt_counter, account->name, jid,
server, port, account->tls_policy, account->auth_policy);
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);