From 974f21efdc1e97902633df0b0eae5f0e855e27fa Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 28 Jun 2022 20:49:22 +0200 Subject: chatlog: sort and rename some functions --- src/chatlog.c | 70 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/chatlog.c b/src/chatlog.c index fdc80d74..da5c7e2b 100644 --- a/src/chatlog.c +++ b/src/chatlog.c @@ -66,11 +66,10 @@ struct dated_chat_log }; static gboolean _log_roll_needed(struct dated_chat_log* dated_log); -static struct dated_chat_log* _create_log(const char* const other, const char* const login); +static struct dated_chat_log* _create_chatlog(const char* const other, const char* const login); static struct dated_chat_log* _create_groupchat_log(const char* const room, const char* const login); static void _free_chat_log(struct dated_chat_log* dated_log); static gboolean _key_equals(void* key1, void* key2); -static char* _get_log_filename(const char* const other, const char* const login, GDateTime* dt, gboolean is_room); static void _chat_log_chat(const char* const login, const char* const other, const gchar* const msg, chat_log_direction_t direction, GDateTime* timestamp, const char* const resourcepart); static void _groupchat_log_chat(const gchar* const login, const gchar* const room, const gchar* const nick, @@ -84,14 +83,6 @@ chat_log_init(void) (GDestroyNotify)_free_chat_log); } -void -groupchat_log_init(void) -{ - log_info("Initialising groupchat logs"); - groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, free, - (GDestroyNotify)_free_chat_log); -} - void chat_log_msg_out(const char* const barejid, const char* const msg, const char* const resource) { @@ -259,17 +250,17 @@ _chat_log_chat(const char* const login, const char* const other, const char* con // no log for user if (dated_log == NULL) { - dated_log = _create_log(other_name, login); + dated_log = _create_chatlog(other_name, login); g_hash_table_insert(logs, strdup(other_name), dated_log); // log entry exists but file removed } else if (!g_file_test(dated_log->filename, G_FILE_TEST_EXISTS)) { - dated_log = _create_log(other_name, login); + dated_log = _create_chatlog(other_name, login); g_hash_table_replace(logs, strdup(other_name), dated_log); // log file needs rolling } else if (_log_roll_needed(dated_log)) { - dated_log = _create_log(other_name, login); + dated_log = _create_chatlog(other_name, login); g_hash_table_replace(logs, strdup(other_name), dated_log); } @@ -319,6 +310,14 @@ _chat_log_chat(const char* const login, const char* const other, const char* con g_date_time_unref(timestamp); } +void +groupchat_log_init(void) +{ + log_info("Initialising groupchat logs"); + groupchat_logs = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, free, + (GDestroyNotify)_free_chat_log); +} + void groupchat_log_msg_out(const gchar* const room, const gchar* const msg) { @@ -426,8 +425,29 @@ chat_log_close(void) g_date_time_unref(session_started); } +static char* +_get_log_filename(const char* const other, const char* const login, GDateTime* dt, gboolean is_room) +{ + gchar* chatlogs_dir = files_file_in_account_data_path(DIR_CHATLOGS, login, is_room ? "rooms" : NULL); + gchar* logfile_name = g_date_time_format(dt, "%Y_%m_%d.log"); + gchar* other_ = str_replace(other, "@", "_at_"); + gchar* logs_path = g_strdup_printf("%s/%s", chatlogs_dir, other_); + gchar* logfile_path = NULL; + + if (create_dir(logs_path)) { + logfile_path = g_strdup_printf("%s/%s", logs_path, logfile_name); + } + + g_free(logs_path); + g_free(other_); + g_free(logfile_name); + g_free(chatlogs_dir); + + return logfile_path; +} + static struct dated_chat_log* -_create_log(const char* const other, const char* const login) +_create_chatlog(const char* const other, const char* const login) { GDateTime* now = g_date_time_new_now_local(); char* filename = _get_log_filename(other, login, now, FALSE); @@ -493,25 +513,3 @@ _key_equals(void* key1, void* key2) return (g_strcmp0(str1, str2) == 0); } - -static char* -_get_log_filename(const char* const other, const char* const login, GDateTime* dt, gboolean is_room) -{ - gchar* chatlogs_dir = files_file_in_account_data_path(DIR_CHATLOGS, login, is_room ? "rooms" : NULL); - gchar* logfile_name = g_date_time_format(dt, "%Y_%m_%d.log"); - gchar* other_ = str_replace(other, "@", "_at_"); - gchar* logs_path = g_strdup_printf("%s/%s", chatlogs_dir, other_); - gchar* logfile_path = NULL; - - if (create_dir(logs_path)) { - logfile_path = g_strdup_printf("%s/%s", logs_path, logfile_name); - } - - g_free(logs_path); - g_free(other_); - g_free(logfile_name); - g_free(chatlogs_dir); - - return logfile_path; -} - -- cgit 1.4.1-2-gfad0