Mercurial > hg
comparison mcabber/mcabber/histolog.c @ 2252:2c7cca6dec6a
Simplify hlog_enable()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 27 Feb 2016 11:02:19 +0100 |
parents | c06488852cdc |
children | 5a107c907e71 |
comparison
equal
deleted
inserted
replaced
2251:f3bd1564fa70 | 2252:2c7cca6dec6a |
---|---|
370 void hlog_enable(guint enable, const char *root_dir, guint loadfiles) | 370 void hlog_enable(guint enable, const char *root_dir, guint loadfiles) |
371 { | 371 { |
372 UseFileLogging = enable; | 372 UseFileLogging = enable; |
373 FileLoadLogs = loadfiles; | 373 FileLoadLogs = loadfiles; |
374 | 374 |
375 if (enable || loadfiles) { | 375 g_free(RootDir); |
376 if (root_dir) { | 376 RootDir = NULL; |
377 char *xp_root_dir; | 377 |
378 int l = strlen(root_dir); | 378 if (!enable && !loadfiles) |
379 if (l < 1) { | 379 return; |
380 scr_LogPrint(LPRINT_LOGNORM, "Error: logging dir name too short"); | 380 |
381 UseFileLogging = FileLoadLogs = FALSE; | 381 if (root_dir) { |
382 return; | 382 char *xp_root_dir; |
383 } | 383 int l = strlen(root_dir); |
384 xp_root_dir = expand_filename(root_dir); | 384 if (l < 1) { |
385 // RootDir must be slash-terminated | 385 scr_LogPrint(LPRINT_LOGNORM, "Error: logging dir name too short"); |
386 if (root_dir[l-1] == '/') { | 386 UseFileLogging = FileLoadLogs = FALSE; |
387 RootDir = xp_root_dir; | 387 return; |
388 } else { | 388 } |
389 RootDir = g_strdup_printf("%s/", xp_root_dir); | 389 xp_root_dir = expand_filename(root_dir); |
390 g_free(xp_root_dir); | 390 // RootDir must be slash-terminated |
391 } | 391 if (root_dir[l-1] == '/') { |
392 RootDir = xp_root_dir; | |
392 } else { | 393 } else { |
393 const char *cfgdir = settings_get_mcabber_config_dir(); | 394 RootDir = g_strdup_printf("%s/", xp_root_dir); |
394 const char *hdir = "/histo/"; | 395 g_free(xp_root_dir); |
395 RootDir = g_strdup_printf("%s%s", cfgdir, hdir); | 396 } |
396 } | 397 } else { |
397 // Check directory permissions (should not be readable by group/others) | 398 const char *cfgdir = settings_get_mcabber_config_dir(); |
398 if (checkset_perm(RootDir, TRUE) == -1) { | 399 const char *hdir = "/histo/"; |
399 // The directory does not actually exists | 400 RootDir = g_strdup_printf("%s%s", cfgdir, hdir); |
400 g_free(RootDir); | 401 } |
401 RootDir = NULL; | 402 |
402 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access " | 403 // Check directory permissions (should not be readable by group/others) |
403 "history log directory, logging DISABLED"); | 404 if (checkset_perm(RootDir, TRUE) == -1) { |
404 UseFileLogging = FileLoadLogs = FALSE; | 405 // The directory does not actually exists |
405 } | |
406 } else { // Disable history logging | |
407 g_free(RootDir); | 406 g_free(RootDir); |
408 RootDir = NULL; | 407 RootDir = NULL; |
408 scr_LogPrint(LPRINT_LOGNORM, "ERROR: Cannot access " | |
409 "history log directory, logging DISABLED"); | |
410 UseFileLogging = FileLoadLogs = FALSE; | |
409 } | 411 } |
410 } | 412 } |
411 | 413 |
412 guint hlog_is_enabled(void) | 414 guint hlog_is_enabled(void) |
413 { | 415 { |