about summary refs log tree commit diff stats
path: root/src/config/files.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-07-01 10:05:45 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-01 10:05:45 +0200
commit1224aa414e56a763412ee33c2b8779d4e6cb1608 (patch)
tree45c16465961c5365379f4f99971be1fafe031b1f /src/config/files.c
parent7d6ef8f4c8fd4d2a6560095b16e9ba147d3c4c47 (diff)
downloadprofani-tty-1224aa414e56a763412ee33c2b8779d4e6cb1608.tar.gz
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.
Diffstat (limited to 'src/config/files.c')
-rw-r--r--src/config/files.c20
1 files changed, 19 insertions, 1 deletions
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)
 {
n188' href='#n188'>188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392