From 1224aa414e56a763412ee33c2b8779d4e6cb1608 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 1 Jul 2020 10:05:45 +0200 Subject: Use files_get_account_data_path instead of duplicate code We often had a use case where we want the account specific data dir. Let's create a function for this instead of doing it by hand each time. --- src/config/files.c | 20 +++++++++++++++++++- src/config/files.h | 3 ++- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'src/config') diff --git a/src/config/files.c b/src/config/files.c index da2b66bb..80a777ae 100644 --- a/src/config/files.c +++ b/src/config/files.c @@ -154,7 +154,7 @@ files_get_config_path(char *config_base) } gchar* -files_get_data_path(char *data_base) +files_get_data_path(const char *const data_base) { gchar *xdg_data = _files_get_xdg_data_home(); GString *file_str = g_string_new(xdg_data); @@ -167,6 +167,24 @@ files_get_data_path(char *data_base) return result; } +gchar* +files_get_account_data_path(const char *const specific_dir, const char *const jid) +{ + gchar *data_dir = files_get_data_path(specific_dir); + GString *result_dir = g_string_new(data_dir); + g_free(data_dir); + + gchar *account_dir = str_replace(jid, "@", "_at_"); + g_string_append(result_dir, "/"); + g_string_append(result_dir, account_dir); + g_free(account_dir); + + gchar *result = g_strdup(result_dir->str); + g_string_free(result_dir, TRUE); + + return result; +} + static char* _files_get_xdg_config_home(void) { diff --git a/src/config/files.h b/src/config/files.h index c87c4501..7b6b37a5 100644 --- a/src/config/files.h +++ b/src/config/files.h @@ -61,7 +61,8 @@ void files_create_directories(void); gchar* files_get_config_path(char *config_base); -gchar* files_get_data_path(char *data_base); +gchar* files_get_data_path(const char *const data_base); +gchar* files_get_account_data_path(const char *const specific_dir, const char *const jid); gchar* files_get_log_file(char *log_file); gchar* files_get_inputrc_file(void); -- cgit 1.4.1-2-gfad0