mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-31 07:06:21 +00:00
fix(xmpp): clang-tidy warnings for extended debug info
This commit is contained in:
@@ -87,12 +87,12 @@ static gchar* profanity_instance_id = NULL;
|
|||||||
static gchar* prof_identifier = NULL;
|
static gchar* prof_identifier = NULL;
|
||||||
|
|
||||||
// Extended debug tracking
|
// Extended debug tracking
|
||||||
static time_t prof_last_connect_attempt_ts = 0; // when connection_connect was last called
|
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_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 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_connect_attempt_counter = 0; // total calls to connection_connect
|
||||||
static unsigned long prof_successful_connect_counter = 0; // successful CONNECTs
|
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)
|
// helper to format elapsed seconds (returns "n/a" if base == 0)
|
||||||
char*
|
char*
|
||||||
@@ -114,7 +114,7 @@ _log_event_header(const char* tag)
|
|||||||
localtime_r(&now, &tm_now);
|
localtime_r(&now, &tm_now);
|
||||||
char ts[32];
|
char ts[32];
|
||||||
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", &tm_now);
|
strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S", &tm_now);
|
||||||
|
|
||||||
char elapsed_success[32];
|
char elapsed_success[32];
|
||||||
char elapsed_disconnect[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_successful_connect_ts, now, elapsed_success, sizeof(elapsed_success));
|
||||||
@@ -127,7 +127,7 @@ _log_event_header(const char* tag)
|
|||||||
|
|
||||||
// Helper to log connection details
|
// Helper to log connection details
|
||||||
static void
|
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)
|
const char* tls_policy, const char* auth_policy)
|
||||||
{
|
{
|
||||||
char elapsed_disconnect[32];
|
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));
|
_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,
|
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);
|
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);
|
extra_info = g_strdup_vprintf(format, args);
|
||||||
va_end(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 : "");
|
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);
|
prof_last_connect_attempt_ts = time(NULL);
|
||||||
_log_event_header("CONNECT_ATTEMPT");
|
_log_event_header("CONNECT_ATTEMPT");
|
||||||
log_info("Connecting as %s", jid);
|
log_info("Connecting as %s", jid);
|
||||||
|
|
||||||
_log_connection_details(jid, altdomain, port, tls_policy, auth_policy);
|
_log_connection_details(jid, altdomain, port, tls_policy, auth_policy);
|
||||||
|
|
||||||
_conn_apply_settings(jid, passwd, 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;
|
conn.conn_status = JABBER_CONNECTED;
|
||||||
prof_successful_connect_counter++;
|
prof_successful_connect_counter++;
|
||||||
prof_last_successful_connect_ts = time(NULL);
|
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),
|
_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),
|
xmpp_conn_get_flags(conn.xmpp_conn),
|
||||||
conn.queued_messages ? "queued_messages=yes" : "queued_messages=no");
|
conn.queued_messages ? "queued_messages=yes" : "queued_messages=no");
|
||||||
|
|
||||||
connection_get_jid();
|
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;
|
conn.conn_status = JABBER_RAW_CONNECTED;
|
||||||
prof_successful_connect_counter++;
|
prof_successful_connect_counter++;
|
||||||
prof_last_successful_connect_ts = time(NULL);
|
prof_last_successful_connect_ts = time(NULL);
|
||||||
|
|
||||||
_log_connection_status_simple("raw connected", xmpp_conn_get_jid(conn.xmpp_conn), FALSE,
|
_log_connection_status_simple("raw connected", xmpp_conn_get_jid(conn.xmpp_conn), FALSE,
|
||||||
xmpp_conn_get_flags(conn.xmpp_conn), "");
|
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:
|
case XMPP_CONN_DISCONNECT:
|
||||||
_log_event_header("DISCONNECT_EVENT");
|
_log_event_header("DISCONNECT_EVENT");
|
||||||
log_debug("Connection handler: XMPP_CONN_DISCONNECT");
|
log_debug("Connection handler: XMPP_CONN_DISCONNECT");
|
||||||
|
|
||||||
_log_connection_status_simple("disconnect", NULL, FALSE, 0,
|
_log_connection_status_simple("disconnect", NULL, FALSE, 0,
|
||||||
"previous_status=%d error=%d has_stream_error=%s",
|
"previous_status=%d error=%d has_stream_error=%s",
|
||||||
(int)conn.conn_status, error,
|
(int)conn.conn_status, error,
|
||||||
(stream_error && stream_error->stanza) ? "yes" : "no");
|
(stream_error && stream_error->stanza) ? "yes" : "no");
|
||||||
prof_last_disconnect_ts = time(NULL);
|
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)) {
|
if (prefs_get_boolean(PREF_STROPHE_SM_ENABLED)) {
|
||||||
int send_queue_len = xmpp_conn_send_queue_len(conn.xmpp_conn);
|
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("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",
|
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_ENABLED),
|
||||||
prefs_get_boolean(PREF_STROPHE_SM_RESEND),
|
prefs_get_boolean(PREF_STROPHE_SM_RESEND),
|
||||||
send_queue_len);
|
send_queue_len);
|
||||||
|
|
||||||
conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn);
|
conn.sm_state = xmpp_conn_get_sm_state(conn.xmpp_conn);
|
||||||
if (send_queue_len > 0 && prefs_get_boolean(PREF_STROPHE_SM_RESEND)) {
|
if (send_queue_len > 0 && prefs_get_boolean(PREF_STROPHE_SM_RESEND)) {
|
||||||
conn.queued_messages = calloc(send_queue_len + 1, sizeof(*conn.queued_messages));
|
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);
|
session_reconnect(host, port);
|
||||||
log_debug("Connection handler: Forcing a re-connect to \"%s\"", host);
|
log_debug("Connection handler: Forcing a re-connect to \"%s\"", host);
|
||||||
prof_reconnect_counter++;
|
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);
|
host, port, prof_reconnect_counter);
|
||||||
|
|
||||||
conn.conn_status = JABBER_RECONNECT;
|
conn.conn_status = JABBER_RECONNECT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1167,7 +1167,7 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
|
|||||||
case XMPP_CONN_FAIL:
|
case XMPP_CONN_FAIL:
|
||||||
_log_event_header("CONNECT_FAIL_EVENT");
|
_log_event_header("CONNECT_FAIL_EVENT");
|
||||||
log_debug("Connection handler: XMPP_CONN_FAIL");
|
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);
|
_log_connection_status_simple("fail", NULL, FALSE, 0, "previous_status=%d error=%d", (int)conn.conn_status, error);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1304,8 +1304,28 @@ connection_debug_print_features()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Extended debug accessors ---
|
// --- Extended debug accessors ---
|
||||||
time_t connection_last_successful_connect_ts(void) { return prof_last_successful_connect_ts; }
|
time_t
|
||||||
time_t connection_last_disconnect_ts(void) { return prof_last_disconnect_ts; }
|
connection_last_successful_connect_ts(void)
|
||||||
unsigned long connection_connect_attempts(void) { return prof_connect_attempt_counter; }
|
{
|
||||||
unsigned long connection_successful_connects(void) { return prof_successful_connect_counter; }
|
return prof_last_successful_connect_ts;
|
||||||
unsigned long connection_reconnect_counter(void) { return prof_reconnect_counter; }
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -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 now = time(NULL);
|
||||||
time_t last_success = connection_last_successful_connect_ts();
|
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);
|
_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;
|
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);
|
auto_gchar gchar* extra = g_strdup_printf("was_waiting=%d elapsed=%.3fs", autoping_wait, elapsed);
|
||||||
_iq_log_autoping_debug("AUTOPING_TIMER_CANCEL", extra);
|
_iq_log_autoping_debug("AUTOPING_TIMER_CANCEL", extra);
|
||||||
|
|
||||||
autoping_wait = FALSE;
|
autoping_wait = FALSE;
|
||||||
if (autoping_time) {
|
if (autoping_time) {
|
||||||
g_timer_destroy(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);
|
xmpp_stanza_t* iq = stanza_create_ping_iq(ctx, NULL);
|
||||||
const char* id = xmpp_stanza_get_id(iq);
|
const char* id = xmpp_stanza_get_id(iq);
|
||||||
log_debug("Autoping: Sending ping request: %s", id);
|
log_debug("Autoping: Sending ping request: %s", id);
|
||||||
|
|
||||||
auto_gchar gchar* send_extra = g_strdup_printf("id=%s timeout=%ds", id, autoping_timeout);
|
auto_gchar gchar* send_extra = g_strdup_printf("id=%s timeout=%ds", id, autoping_timeout);
|
||||||
_iq_log_autoping_debug("AUTOPING_SEND", send_extra);
|
_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);
|
const char* id = xmpp_stanza_get_id(stanza);
|
||||||
gdouble response_time = autoping_time ? g_timer_elapsed(autoping_time, NULL) : 0.0;
|
gdouble response_time = autoping_time ? g_timer_elapsed(autoping_time, NULL) : 0.0;
|
||||||
|
|
||||||
if (id == NULL) {
|
if (id == NULL) {
|
||||||
log_debug("Autoping: Pong handler fired.");
|
log_debug("Autoping: Pong handler fired.");
|
||||||
auto_gchar gchar* extra = g_strdup_printf("id=(null) response_time=%.3fs", response_time);
|
auto_gchar gchar* extra = g_strdup_printf("id=(null) response_time=%.3fs", response_time);
|
||||||
|
|||||||
@@ -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_success = connection_last_successful_connect_ts();
|
||||||
time_t last_disc = connection_last_disconnect_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_success, now, elapsed_success, success_len);
|
||||||
_connection_format_elapsed_time(last_disc, now, elapsed_disconnect, disconnect_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
|
// Helper function to log connection debug info
|
||||||
static void
|
static void
|
||||||
_session_log_connect_debug(const char* event, const char* account, const char* jid,
|
_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;
|
time_t now;
|
||||||
char elapsed_success[32];
|
char elapsed_success[32];
|
||||||
@@ -149,7 +150,7 @@ _session_log_state_debug(const char* event, int extra_param)
|
|||||||
// Helper function to log reconnect attempt
|
// Helper function to log reconnect attempt
|
||||||
static void
|
static void
|
||||||
_session_log_reconnect_debug(unsigned long attempt_num, const char* account, const char* jid,
|
_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;
|
time_t now;
|
||||||
char elapsed_success[32];
|
char elapsed_success[32];
|
||||||
@@ -201,7 +202,7 @@ session_connect_with_account(const ProfAccount* const account)
|
|||||||
|
|
||||||
log_info("Connecting using account: %s", account->name);
|
log_info("Connecting using account: %s", account->name);
|
||||||
_session_log_connect_debug("SESSION_CONNECT_WITH_ACCOUNT", account->name, account->jid,
|
_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();
|
_session_free_internals();
|
||||||
|
|
||||||
@@ -236,7 +237,7 @@ session_connect_with_details(const char* const jid, const char* const passwd, co
|
|||||||
assert(passwd != NULL);
|
assert(passwd != NULL);
|
||||||
|
|
||||||
_session_log_connect_debug("SESSION_CONNECT_WITH_DETAILS", NULL, jid,
|
_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();
|
_session_free_internals();
|
||||||
|
|
||||||
@@ -662,7 +663,7 @@ session_reconnect_now(void)
|
|||||||
|
|
||||||
session_reconnect_attempt_counter++;
|
session_reconnect_attempt_counter++;
|
||||||
_session_log_reconnect_debug(session_reconnect_attempt_counter, account->name, jid,
|
_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);
|
log_debug("Attempting reconnect with account %s", account->name);
|
||||||
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
|
connection_connect(jid, saved_account.passwd, server, port, account->tls_policy, account->auth_policy);
|
||||||
|
|||||||
Reference in New Issue
Block a user