style: apply clang-format and const qualifiers from master
All checks were successful
CI Code / Check spelling (pull_request) Successful in 21s
CI Code / Check coding style (pull_request) Successful in 37s
CI Code / Code Coverage (pull_request) Successful in 7m12s
CI Code / Linux (ubuntu) (pull_request) Successful in 8m37s
CI Code / Linux (debian) (pull_request) Successful in 8m37s
CI Code / Linux (arch) (pull_request) Successful in 8m55s

This commit is contained in:
2026-03-09 12:54:55 +03:00
parent e91e8403b0
commit 16476676f0
7 changed files with 135 additions and 137 deletions

View File

@@ -379,7 +379,7 @@ log_database_export_to_flatfile(const gchar* const contact_jid)
g_slist_free_full(merged, (GDestroyNotify)ff_parsed_line_free); g_slist_free_full(merged, (GDestroyNotify)ff_parsed_line_free);
fflush(fp); fflush(fp);
fsync(fd); // ensure data is on disk before atomic rename fsync(fd); // ensure data is on disk before atomic rename
fclose(fp); // also releases flock fclose(fp); // also releases flock
// Atomic rename // Atomic rename

View File

@@ -55,7 +55,7 @@
static sqlite3* g_chatlog_database; static sqlite3* g_chatlog_database;
static void _add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid); static void _add_to_db(ProfMessage* message, const char* type, const Jid* const from_jid, const Jid* const to_jid);
static char* _get_db_filename(ProfAccount* account); static char* _get_db_filename(ProfAccount* account);
static prof_msg_type_t _get_message_type_type(const char* const type); static prof_msg_type_t _get_message_type_type(const char* const type);
static prof_enc_t _get_message_enc_type(const char* const encstr); static prof_enc_t _get_message_enc_type(const char* const encstr);
@@ -147,22 +147,22 @@ _sqlite_init(ProfAccount* account)
return TRUE; return TRUE;
} }
char* query = "CREATE TABLE IF NOT EXISTS `ChatLogs` (" const char* query = "CREATE TABLE IF NOT EXISTS `ChatLogs` ("
"`id` INTEGER PRIMARY KEY AUTOINCREMENT, " "`id` INTEGER PRIMARY KEY AUTOINCREMENT, "
"`from_jid` TEXT NOT NULL, " "`from_jid` TEXT NOT NULL, "
"`to_jid` TEXT NOT NULL, " "`to_jid` TEXT NOT NULL, "
"`from_resource` TEXT, " "`from_resource` TEXT, "
"`to_resource` TEXT, " "`to_resource` TEXT, "
"`message` TEXT, " "`message` TEXT, "
"`timestamp` TEXT, " "`timestamp` TEXT, "
"`type` TEXT, " "`type` TEXT, "
"`stanza_id` TEXT, " "`stanza_id` TEXT, "
"`archive_id` TEXT, " "`archive_id` TEXT, "
"`encryption` TEXT, " "`encryption` TEXT, "
"`marked_read` INTEGER, " "`marked_read` INTEGER, "
"`replace_id` TEXT, " "`replace_id` TEXT, "
"`replaces_db_id` INTEGER, " "`replaces_db_id` INTEGER, "
"`replaced_by_db_id` INTEGER)"; "`replaced_by_db_id` INTEGER)";
if (SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) { if (SQLITE_OK != sqlite3_exec(g_chatlog_database, query, NULL, 0, &err_msg)) {
goto out; goto out;
} }
@@ -251,7 +251,7 @@ _sqlite_add_incoming(ProfMessage* message)
} }
static void static void
_log_database_add_outgoing(char* type, const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc) _log_database_add_outgoing(const char* type, const char* const id, const char* const barejid, const char* const message, const char* const replace_id, prof_enc_t enc)
{ {
ProfMessage* msg = message_init(); ProfMessage* msg = message_init();
@@ -350,8 +350,8 @@ _sqlite_get_previous_chat(const gchar* const contact_barejid, const gchar* start
return DB_RESPONSE_ERROR; return DB_RESPONSE_ERROR;
} }
gchar* sort1 = from_start ? "ASC" : "DESC"; const gchar* sort1 = from_start ? "ASC" : "DESC";
gchar* sort2 = !flip ? "ASC" : "DESC"; const gchar* sort2 = !flip ? "ASC" : "DESC";
GDateTime* now = g_date_time_new_now_local(); GDateTime* now = g_date_time_new_now_local();
auto_gchar gchar* end_date_fmt = end_time ? g_strdup(end_time) : g_date_time_format_iso8601(now); auto_gchar gchar* end_date_fmt = end_time ? g_strdup(end_time) : g_date_time_format_iso8601(now);
auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM (" auto_sqlite gchar* query = sqlite3_mprintf("SELECT * FROM ("
@@ -571,7 +571,7 @@ _get_message_enc_type(const char* const encstr)
// --- Core write logic --- // --- Core write logic ---
static void static void
_add_to_db(ProfMessage* message, char* type, const Jid* const from_jid, const Jid* const to_jid) _add_to_db(ProfMessage* message, const char* type, const Jid* const from_jid, const Jid* const to_jid)
{ {
auto_gchar gchar* pref_dblog = prefs_get_string(PREF_DBLOG); auto_gchar gchar* pref_dblog = prefs_get_string(PREF_DBLOG);
sqlite_int64 original_message_id = -1; sqlite_int64 original_message_id = -1;

View File

@@ -66,7 +66,7 @@
int int
main(int argc, char* argv[]) main(int argc, char* argv[])
{ {
int group = 0; /* 0 = all groups */ int group = 0; /* 0 = all groups */
if (argc > 1) { if (argc > 1) {
group = atoi(argv[1]); group = atoi(argv[1]);
if (group < 1 || group > 4) { if (group < 1 || group > 4) {
@@ -268,7 +268,8 @@ main(int argc, char* argv[])
}; };
/* Test group registry for easy extension */ /* Test group registry for easy extension */
struct { struct
{
const char* name; const char* name;
const struct CMUnitTest* tests; const struct CMUnitTest* tests;
size_t count; size_t count;

View File

@@ -20,8 +20,8 @@
/* Number of parallel test groups for CI builds */ /* Number of parallel test groups for CI builds */
#define TEST_GROUPS 4 #define TEST_GROUPS 4
char *config_orig; char* config_orig;
char *data_orig; char* data_orig;
int fd = 0; int fd = 0;
int stub_port = 5230; int stub_port = 5230;
@@ -47,7 +47,7 @@ static size_t output_len = 0;
static int expect_timeout = 30; static int expect_timeout = 30;
gboolean gboolean
_create_dir(const char *name) _create_dir(const char* name)
{ {
struct stat sb; struct stat sb;
@@ -65,14 +65,14 @@ _create_dir(const char *name)
} }
gboolean gboolean
_mkdir_recursive(const char *dir) _mkdir_recursive(const char* dir)
{ {
int i; int i;
gboolean result = TRUE; gboolean result = TRUE;
for (i = 1; i <= strlen(dir); i++) { for (i = 1; i <= strlen(dir); i++) {
if (dir[i] == '/' || dir[i] == '\0') { if (dir[i] == '/' || dir[i] == '\0') {
gchar *next_dir = g_strndup(dir, i); gchar* next_dir = g_strndup(dir, i);
result = _create_dir(next_dir); result = _create_dir(next_dir);
g_free(next_dir); g_free(next_dir);
if (!result) { if (!result) {
@@ -87,7 +87,7 @@ _mkdir_recursive(const char *dir)
void void
_create_config_dir(void) _create_config_dir(void)
{ {
GString *profanity_dir = g_string_new(xdg_config_home); GString* profanity_dir = g_string_new(xdg_config_home);
g_string_append(profanity_dir, "/profanity"); g_string_append(profanity_dir, "/profanity");
if (!_mkdir_recursive(profanity_dir->str)) { if (!_mkdir_recursive(profanity_dir->str)) {
@@ -100,7 +100,7 @@ _create_config_dir(void)
void void
_create_data_dir(void) _create_data_dir(void)
{ {
GString *profanity_dir = g_string_new(xdg_data_home); GString* profanity_dir = g_string_new(xdg_data_home);
g_string_append(profanity_dir, "/profanity"); g_string_append(profanity_dir, "/profanity");
if (!_mkdir_recursive(profanity_dir->str)) { if (!_mkdir_recursive(profanity_dir->str)) {
@@ -113,7 +113,7 @@ _create_data_dir(void)
void void
_create_chatlogs_dir(void) _create_chatlogs_dir(void)
{ {
GString *chatlogs_dir = g_string_new(xdg_data_home); GString* chatlogs_dir = g_string_new(xdg_data_home);
g_string_append(chatlogs_dir, "/profanity/chatlogs"); g_string_append(chatlogs_dir, "/profanity/chatlogs");
if (!_mkdir_recursive(chatlogs_dir->str)) { if (!_mkdir_recursive(chatlogs_dir->str)) {
@@ -126,7 +126,7 @@ _create_chatlogs_dir(void)
void void
_create_logs_dir(void) _create_logs_dir(void)
{ {
GString *logs_dir = g_string_new(xdg_data_home); GString* logs_dir = g_string_new(xdg_data_home);
g_string_append(logs_dir, "/profanity/logs"); g_string_append(logs_dir, "/profanity/logs");
if (!_mkdir_recursive(logs_dir->str)) { if (!_mkdir_recursive(logs_dir->str)) {
@@ -139,7 +139,7 @@ _create_logs_dir(void)
void void
_cleanup_dirs(void) _cleanup_dirs(void)
{ {
const char *group_env = getenv("PROF_TEST_GROUP"); const char* group_env = getenv("PROF_TEST_GROUP");
int group = group_env ? atoi(group_env) : 0; int group = group_env ? atoi(group_env) : 0;
int dir_id = (group >= 1 && group <= TEST_GROUPS) ? group : stub_port; int dir_id = (group >= 1 && group <= TEST_GROUPS) ? group : stub_port;
@@ -177,8 +177,8 @@ _read_output(int timeout_ms)
size_t space = OUTPUT_BUF_SIZE - output_len - 1; size_t space = OUTPUT_BUF_SIZE - output_len - 1;
if (space <= 0) { if (space <= 0) {
/* Buffer full, shift content */ /* Buffer full, shift content */
memmove(output_buffer, output_buffer + OUTPUT_BUF_SIZE/2, OUTPUT_BUF_SIZE/2); memmove(output_buffer, output_buffer + OUTPUT_BUF_SIZE / 2, OUTPUT_BUF_SIZE / 2);
output_len = OUTPUT_BUF_SIZE/2; output_len = OUTPUT_BUF_SIZE / 2;
space = OUTPUT_BUF_SIZE - output_len - 1; space = OUTPUT_BUF_SIZE - output_len - 1;
} }
@@ -199,7 +199,7 @@ prof_start(void)
{ {
struct winsize ws; struct winsize ws;
ws.ws_row = 24; ws.ws_row = 24;
ws.ws_col = 300; /* Match COLUMNS=300 from start_profanity.sh */ ws.ws_col = 300; /* Match COLUMNS=300 from start_profanity.sh */
ws.ws_xpixel = 0; ws.ws_xpixel = 0;
ws.ws_ypixel = 0; ws.ws_ypixel = 0;
@@ -232,18 +232,18 @@ prof_start(void)
fcntl(fd, F_SETFL, flags | O_NONBLOCK); fcntl(fd, F_SETFL, flags | O_NONBLOCK);
/* Brief wait for process to initialize */ /* Brief wait for process to initialize */
usleep(50000); /* 50ms */ usleep(50000); /* 50ms */
} }
int int
init_prof_test(void **state) init_prof_test(void** state)
{ {
/* Get test group from environment for static resource allocation */ /* Get test group from environment for static resource allocation */
const char *group_env = getenv("PROF_TEST_GROUP"); const char* group_env = getenv("PROF_TEST_GROUP");
int group = group_env ? atoi(group_env) : 0; int group = group_env ? atoi(group_env) : 0;
/* Get build index for port offset (for parallel CI builds) */ /* Get build index for port offset (for parallel CI builds) */
const char *build_env = getenv("PROF_BUILD_INDEX"); const char* build_env = getenv("PROF_BUILD_INDEX");
int build_idx = build_env ? atoi(build_env) : 0; int build_idx = build_env ? atoi(build_env) : 0;
/* Calculate port base: each build uses a different range of TEST_GROUPS ports. /* Calculate port base: each build uses a different range of TEST_GROUPS ports.
@@ -316,12 +316,12 @@ init_prof_test(void **state)
_create_logs_dir(); _create_logs_dir();
/* If PROF_FLATFILE=1 is set, write a profrc that selects the flat-file backend */ /* If PROF_FLATFILE=1 is set, write a profrc that selects the flat-file backend */
const char *flatfile_env = getenv("PROF_FLATFILE"); const char* flatfile_env = getenv("PROF_FLATFILE");
if (flatfile_env && strcmp(flatfile_env, "1") == 0) { if (flatfile_env && strcmp(flatfile_env, "1") == 0) {
char profrc_path[512]; char profrc_path[512];
snprintf(profrc_path, sizeof(profrc_path), snprintf(profrc_path, sizeof(profrc_path),
"%s/profanity/profrc", xdg_config_home); "%s/profanity/profrc", xdg_config_home);
FILE *prc = fopen(profrc_path, "w"); FILE* prc = fopen(profrc_path, "w");
if (prc) { if (prc) {
fprintf(prc, "[logging]\ndblog=flatfile\n"); fprintf(prc, "[logging]\ndblog=flatfile\n");
fclose(prc); fclose(prc);
@@ -365,7 +365,7 @@ init_prof_test(void **state)
} }
int int
close_prof_test(void **state) close_prof_test(void** state)
{ {
if (fd > 0 && child_pid > 0) { if (fd > 0 && child_pid > 0) {
prof_input("/quit"); prof_input("/quit");
@@ -391,7 +391,7 @@ close_prof_test(void **state)
* to ensure the port is released before the next test starts. * to ensure the port is released before the next test starts.
* See: https://git.jabber.space/devs/stabber/issues/3 * See: https://git.jabber.space/devs/stabber/issues/3
*/ */
usleep(100000); // 100ms usleep(100000); // 100ms
return 0; return 0;
} }
@@ -410,13 +410,13 @@ prof_stop(void)
output_len = 0; output_len = 0;
output_buffer[0] = '\0'; output_buffer[0] = '\0';
/* Brief delay to let stabber release old connection state */ /* Brief delay to let stabber release old connection state */
usleep(200000); /* 200ms */ usleep(200000); /* 200ms */
} }
void void
prof_input(const char *input) prof_input(const char* input)
{ {
GString *inp_str = g_string_new(input); GString* inp_str = g_string_new(input);
g_string_append(inp_str, "\r"); g_string_append(inp_str, "\r");
ssize_t _wn = write(fd, inp_str->str, inp_str->len); ssize_t _wn = write(fd, inp_str->str, inp_str->len);
(void)_wn; (void)_wn;
@@ -431,7 +431,7 @@ prof_input(const char *input)
* Returns 1 if found, 0 if timeout. * Returns 1 if found, 0 if timeout.
*/ */
int int
prof_output_exact(const char *text) prof_output_exact(const char* text)
{ {
time_t start = time(NULL); time_t start = time(NULL);
@@ -446,7 +446,7 @@ prof_output_exact(const char *text)
return 1; return 1;
} }
usleep(50000); /* 50ms */ usleep(50000); /* 50ms */
} }
return 0; return 0;
@@ -457,7 +457,7 @@ prof_output_exact(const char *text)
* Returns 1 if found, 0 if timeout. * Returns 1 if found, 0 if timeout.
*/ */
int int
prof_output_regex(const char *pattern) prof_output_regex(const char* pattern)
{ {
regex_t regex; regex_t regex;
int ret; int ret;
@@ -482,7 +482,7 @@ prof_output_regex(const char *pattern)
return 1; return 1;
} }
usleep(50000); /* 50ms */ usleep(50000); /* 50ms */
} }
/* Timeout reached - log diagnostic info */ /* Timeout reached - log diagnostic info */
@@ -500,17 +500,15 @@ prof_output_regex(const char *pattern)
} }
void void
prof_connect_with_roster(const char *roster) prof_connect_with_roster(const char* roster)
{ {
GString *roster_str = g_string_new( GString* roster_str = g_string_new(
"<iq type='result' to='stabber@localhost/profanity'>" "<iq type='result' to='stabber@localhost/profanity'>"
"<query xmlns='jabber:iq:roster' ver='362'>" "<query xmlns='jabber:iq:roster' ver='362'>");
);
g_string_append(roster_str, roster); g_string_append(roster_str, roster);
g_string_append(roster_str, g_string_append(roster_str,
"</query>" "</query>"
"</iq>" "</iq>");
);
stbbr_for_query("jabber:iq:roster", roster_str->str); stbbr_for_query("jabber:iq:roster", roster_str->str);
g_string_free(roster_str, TRUE); g_string_free(roster_str, TRUE);
@@ -534,9 +532,8 @@ prof_connect_with_roster(const char *roster)
// Match the actual attribute order from stanza_attach_caps // Match the actual attribute order from stanza_attach_caps
assert_true(stbbr_received( assert_true(stbbr_received(
"<presence id=\"*\">" "<presence id=\"*\">"
"<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://profanity-im.github.io\" ver=\"*\"/>" "<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://profanity-im.github.io\" ver=\"*\"/>"
"</presence>" "</presence>"));
));
} }
void void
@@ -556,6 +553,5 @@ prof_connect(void)
{ {
prof_connect_with_roster( prof_connect_with_roster(
"<item jid='buddy1@localhost' subscription='both' name='Buddy1'/>" "<item jid='buddy1@localhost' subscription='both' name='Buddy1'/>"
"<item jid='buddy2@localhost' subscription='both' name='Buddy2'/>" "<item jid='buddy2@localhost' subscription='both' name='Buddy2'/>");
);
} }

View File

@@ -11,17 +11,17 @@ extern char xdg_data_home[256];
extern int stub_port; extern int stub_port;
int init_prof_test(void **state); int init_prof_test(void** state);
int close_prof_test(void **state); int close_prof_test(void** state);
void prof_start(void); void prof_start(void);
void prof_stop(void); void prof_stop(void);
void prof_connect(void); void prof_connect(void);
void prof_connect_with_roster(const char *roster); void prof_connect_with_roster(const char* roster);
void prof_input(const char *input); void prof_input(const char* input);
int prof_output_exact(const char *text); int prof_output_exact(const char* text);
int prof_output_regex(const char *text); int prof_output_regex(const char* text);
void prof_timeout(int timeout); void prof_timeout(int timeout);
void prof_timeout_reset(void); void prof_timeout_reset(void);

View File

@@ -36,7 +36,7 @@
* it was persisted to and read back from the database * it was persisted to and read back from the database
*/ */
void void
message_db_history_on_reopen(void **state) message_db_history_on_reopen(void** state)
{ {
prof_connect(); prof_connect();
@@ -81,7 +81,7 @@ message_db_history_on_reopen(void **state)
* we can reliably synchronise on each delivery before proceeding. * we can reliably synchronise on each delivery before proceeding.
*/ */
void void
message_db_history_multiple(void **state) message_db_history_multiple(void** state)
{ {
prof_connect(); prof_connect();
@@ -131,7 +131,7 @@ message_db_history_multiple(void **state)
* 3. Open buddy1 → verify buddy1's body present, buddy2's body absent * 3. Open buddy1 → verify buddy1's body present, buddy2's body absent
*/ */
void void
message_db_history_contact_isolation(void **state) message_db_history_contact_isolation(void** state)
{ {
prof_connect(); prof_connect();
@@ -177,7 +177,7 @@ message_db_history_contact_isolation(void **state)
* characters and return them unchanged. * characters and return them unchanged.
*/ */
void void
message_db_history_special_chars(void **state) message_db_history_special_chars(void** state)
{ {
prof_connect(); prof_connect();
@@ -210,7 +210,7 @@ message_db_history_special_chars(void **state)
* and catches crashes in the outgoing DB code. * and catches crashes in the outgoing DB code.
*/ */
void void
message_db_history_outgoing(void **state) message_db_history_outgoing(void** state)
{ {
prof_connect(); prof_connect();
@@ -238,7 +238,7 @@ message_db_history_outgoing(void **state)
* and the outgoing write path completed without error. * and the outgoing write path completed without error.
*/ */
void void
message_db_history_dialog(void **state) message_db_history_dialog(void** state)
{ {
prof_connect(); prof_connect();
@@ -279,7 +279,7 @@ message_db_history_dialog(void **state)
* does not crash and the window is usable. * does not crash and the window is usable.
*/ */
void void
message_db_history_empty(void **state) message_db_history_empty(void** state)
{ {
prof_connect(); prof_connect();
@@ -299,7 +299,7 @@ message_db_history_empty(void **state)
* Test: a long message (1000+ characters) is not truncated by the DB. * Test: a long message (1000+ characters) is not truncated by the DB.
*/ */
void void
message_db_history_long_message(void **state) message_db_history_long_message(void** state)
{ {
prof_connect(); prof_connect();
@@ -313,10 +313,11 @@ message_db_history_long_message(void **state)
char xml[1500]; char xml[1500];
snprintf(xml, sizeof(xml), snprintf(xml, sizeof(xml),
"<message id='long1' to='stabber@localhost' " "<message id='long1' to='stabber@localhost' "
"from='buddy1@localhost/phone' type='chat'>" "from='buddy1@localhost/phone' type='chat'>"
"<body>%s</body>" "<body>%s</body>"
"</message>", body); "</message>",
body);
stbbr_send(xml); stbbr_send(xml);
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)")); assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
@@ -335,7 +336,7 @@ message_db_history_long_message(void **state)
* Uses XML character reference &#10; for literal newline in body. * Uses XML character reference &#10; for literal newline in body.
*/ */
void void
message_db_history_newline(void **state) message_db_history_newline(void** state)
{ {
prof_connect(); prof_connect();
@@ -364,7 +365,7 @@ message_db_history_newline(void **state)
* percent, braces, brackets, equals) survive DB round-trip. * percent, braces, brackets, equals) survive DB round-trip.
*/ */
void void
message_db_history_service_chars(void **state) message_db_history_service_chars(void** state)
{ {
prof_connect(); prof_connect();
@@ -389,7 +390,7 @@ message_db_history_service_chars(void **state)
* Test: /history verify reports no issues after normal message writes. * Test: /history verify reports no issues after normal message writes.
*/ */
void void
message_db_history_verify(void **state) message_db_history_verify(void** state)
{ {
prof_connect(); prof_connect();
@@ -425,7 +426,7 @@ message_db_history_verify(void **state)
* text should appear — the original should be absent. * text should appear — the original should be absent.
*/ */
void void
message_db_history_lmc(void **state) message_db_history_lmc(void** state)
{ {
prof_connect(); prof_connect();

View File

@@ -1,12 +1,12 @@
void message_db_history_on_reopen(void **state); void message_db_history_on_reopen(void** state);
void message_db_history_multiple(void **state); void message_db_history_multiple(void** state);
void message_db_history_contact_isolation(void **state); void message_db_history_contact_isolation(void** state);
void message_db_history_special_chars(void **state); void message_db_history_special_chars(void** state);
void message_db_history_outgoing(void **state); void message_db_history_outgoing(void** state);
void message_db_history_dialog(void **state); void message_db_history_dialog(void** state);
void message_db_history_empty(void **state); void message_db_history_empty(void** state);
void message_db_history_long_message(void **state); void message_db_history_long_message(void** state);
void message_db_history_newline(void **state); void message_db_history_newline(void** state);
void message_db_history_service_chars(void **state); void message_db_history_service_chars(void** state);
void message_db_history_verify(void **state); void message_db_history_verify(void** state);
void message_db_history_lmc(void **state); void message_db_history_lmc(void** state);