about summary refs log tree commit diff stats
path: root/src/otr
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-03-13 11:58:56 +0100
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2022-03-13 14:15:02 +0100
commitb8e46552bffc559263e86b2dcc0331b3f47065b7 (patch)
treeedd714bd6487ae39a3d6b7c77f799391b5071151 /src/otr
parent764a7fb71b6cc401ed77233bbcd4d67201f9ca85 (diff)
downloadprofani-tty-b8e46552bffc559263e86b2dcc0331b3f47065b7.tar.gz
add `files_file_in_account_data_path()`
As all parts of the code invoking the `files_get_account_data_path()`
function did the same afterwards, a function has been added with the same
behavior.

1. create path
2. `mkdir` of that path
3. return final path

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Diffstat (limited to 'src/otr')
-rw-r--r--src/otr/otr.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/otr/otr.c b/src/otr/otr.c
index 5f45e23c..562914a2 100644
--- a/src/otr/otr.c
+++ b/src/otr/otr.c
@@ -129,19 +129,20 @@ static void
 cb_write_fingerprints(void* opdata)
 {
     gcry_error_t err = 0;
-    gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid);
-
-    GString* fpsfilename = g_string_new(otr_dir);
-    g_string_append(fpsfilename, "/fingerprints.txt");
+    gchar* fpsfilename = files_file_in_account_data_path(DIR_OTR, jid, "fingerprints.txt");
+    if (!fpsfilename) {
+        log_error("Failed to create fingerprints file");
+        cons_show_error("Failed to create fingerprints file");
+        return;
+    }
 
-    err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str);
+    err = otrl_privkey_write_fingerprints(user_state, fpsfilename);
     if (err != GPG_ERR_NO_ERROR) {
         log_error("Failed to write fingerprints file");
-        cons_show_error("Failed to create fingerprints file");
+        cons_show_error("Failed to write fingerprints file");
     }
 
-    g_free(otr_dir);
-    g_string_free(fpsfilename, TRUE);
+    g_free(fpsfilename);
 }
 
 static void
@@ -212,12 +213,10 @@ otr_on_connect(ProfAccount* account)
     jid = strdup(account->jid);
     log_info("Loading OTR key for %s", jid);
 
-    gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid);
-
-    if (!mkdir_recursive(otr_dir)) {
-        log_error("Could not create %s for account %s.", otr_dir, jid);
-        cons_show_error("Could not create %s for account %s.", otr_dir, jid);
-        g_free(otr_dir);
+    gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
+    if (!otr_dir) {
+        log_error("Could not create directory for account %s.", jid);
+        cons_show_error("Could not create directory for account %s.", jid);
         return;
     }
 
@@ -381,12 +380,11 @@ otr_keygen(ProfAccount* account)
     jid = strdup(account->jid);
     log_info("Generating OTR key for %s", jid);
 
-    gchar* otr_dir = files_get_account_data_path(DIR_OTR, jid);
+    gchar* otr_dir = files_file_in_account_data_path(DIR_OTR, jid, NULL);
 
-    if (!mkdir_recursive(otr_dir)) {
-        log_error("Could not create %s for account %s.", otr_dir, jid);
-        cons_show_error("Could not create %s for account %s.", otr_dir, jid);
-        g_free(otr_dir);
+    if (!otr_dir) {
+        log_error("Could not create directory for account %s.", jid);
+        cons_show_error("Could not create directory for account %s.", jid);
         return;
     }