summaryrefslogtreecommitdiffstats
path: root/src/daemon/Settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/Settings.cpp')
-rw-r--r--src/daemon/Settings.cpp277
1 files changed, 65 insertions, 212 deletions
diff --git a/src/daemon/Settings.cpp b/src/daemon/Settings.cpp
index cb77d191..90efd199 100644
--- a/src/daemon/Settings.cpp
+++ b/src/daemon/Settings.cpp
@@ -19,31 +19,7 @@
#include "abrtlib.h"
#include "Settings.h"
-#define SECTION_COMMON "Common"
-#define SECTION_LOG_SCANNERS "LogScanners"
-
-/* Conf file has this format:
- * [ section_name1 ]
- * name1 = value1
- * name2 = value2
- * [ section_name2 ]
- * name = value
- */
-
-/* Static data */
-/* Filled by load_settings() */
-
-/* map["name"] = "value" strings from [ Common ] section.
- * If the same name found on more than one line,
- * the values are appended, separated by comma: map["name"] = "value1,value2" */
-static map_string_t s_mapSectionCommon;
-
-/* Public data */
-
-/* [ Common ] */
-/* one line: "OpenGPGCheck = value" */
bool g_settings_bOpenGPGCheck = false;
-/* one line: "OpenGPGPublicKeys = value1,value2" */
GList * g_settings_setOpenGPGPublicKeys = NULL;
GList * g_settings_setBlackListedPkgs = NULL;
GList * g_settings_setBlackListedPaths = NULL;
@@ -51,13 +27,21 @@ char * g_settings_sWatchCrashdumpArchiveDir = NULL;
unsigned int g_settings_nMaxCrashReportsSize = 1000;
bool g_settings_bProcessUnpackaged = false;
-/* [ LogScanners ] */
-char * g_settings_sLogScanners = NULL;
+void free_settings()
+{
+ list_free_with_free(g_settings_setOpenGPGPublicKeys);
+ g_settings_setOpenGPGPublicKeys = NULL;
-/*
- * Loading
- */
+ list_free_with_free(g_settings_setBlackListedPkgs);
+ g_settings_setBlackListedPkgs = NULL;
+
+ list_free_with_free(g_settings_setBlackListedPaths);
+ g_settings_setBlackListedPaths = NULL;
+
+ free(g_settings_sWatchCrashdumpArchiveDir);
+ g_settings_sWatchCrashdumpArchiveDir = NULL;
+}
static GList *parse_list(const char* list)
{
@@ -85,43 +69,65 @@ static GList *parse_list(const char* list)
}
strbuf_free(item);
+
return l;
}
-static int ParseCommon()
+static void ParseCommon(map_string_h *settings, const char *conf_filename)
{
- map_string_t::const_iterator end = s_mapSectionCommon.end();
- map_string_t::const_iterator it = s_mapSectionCommon.find("OpenGPGCheck");
- if (it != end)
+ char *value;
+
+ value = g_hash_table_lookup(settings, "OpenGPGCheck");
+ if (value)
{
- g_settings_bOpenGPGCheck = string_to_bool(it->second.c_str());
+ g_settings_bOpenGPGCheck = string_to_bool(value);
+ g_hash_table_remove(settings, "OpenGPGCheck");
}
- it = s_mapSectionCommon.find("BlackList");
- if (it != end)
+
+ value = g_hash_table_lookup(settings, "BlackList");
+ if (value)
+ {
+ g_settings_setBlackListedPkgs = parse_list(value);
+ g_hash_table_remove(settings, "BlackList");
+ }
+
+ value = g_hash_table_lookup(settings, "BlackListedPaths");
+ if (value)
{
- g_settings_setBlackListedPkgs = parse_list(it->second.c_str());
+ g_settings_setBlackListedPaths = parse_list(value);
+ g_hash_table_remove(settings, "BlackListedPaths");
}
- it = s_mapSectionCommon.find("BlackListedPaths");
- if (it != end)
+
+ value = g_hash_table_lookup(settings, "WatchCrashdumpArchiveDir");
+ if (value)
{
- g_settings_setBlackListedPaths = parse_list(it->second.c_str());
+ g_settings_sWatchCrashdumpArchiveDir = xstrdup(value);
+ g_hash_table_remove(settings, "WatchCrashdumpArchiveDir");
}
- it = s_mapSectionCommon.find("WatchCrashdumpArchiveDir");
- if (it != end)
+
+ value = g_hash_table_lookup(settings, "MaxCrashReportsSize");
+ if (value)
{
- g_settings_sWatchCrashdumpArchiveDir = xstrdup(it->second.c_str());
+//fixme: dont die
+ g_settings_nMaxCrashReportsSize = xatoi_positive(value);
+ g_hash_table_remove(settings, "MaxCrashReportsSize");
}
- it = s_mapSectionCommon.find("MaxCrashReportsSize");
- if (it != end)
+
+ value = g_hash_table_lookup(settings, "ProcessUnpackaged");
+ if (value)
{
- g_settings_nMaxCrashReportsSize = xatoi_positive(it->second.c_str());
+ g_settings_bProcessUnpackaged = string_to_bool(value);
+ g_hash_table_remove(settings, "ProcessUnpackaged");
}
- it = s_mapSectionCommon.find("ProcessUnpackaged");
- if (it != end)
+
+ GHashTableIter iter;
+ char *name;
+ /*char *value; - already declared */
+ g_hash_table_iter_init(&iter, settings);
+ while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value))
{
- g_settings_bProcessUnpackaged = string_to_bool(it->second.c_str());
+ error_msg("Unrecognized variable '%s' in '%s'", name, conf_filename);
}
- return 0; /* no error */
}
static void LoadGPGKeys()
@@ -135,7 +141,7 @@ static void LoadGPGKeys()
char *line;
while ((line = xmalloc_fgetline(fp)) != NULL)
{
- if (line[0] == '/') // probably the begining of path, so let's handle it as a key
+ if (line[0] == '/') // probably the beginning of a path, so let's handle it as a key
g_settings_setOpenGPGPublicKeys = g_list_append(g_settings_setOpenGPGPublicKeys, line);
else
free(line);
@@ -144,171 +150,18 @@ static void LoadGPGKeys()
}
}
-/**
- * Reads configuration from file to s_mapSection* static variables.
- * The file must be opened for reading.
- */
-static int ReadConfigurationFromFile(FILE *fp)
-{
- char *line;
- std::string section;
- int lineno = 0;
- while ((line = xmalloc_fgetline(fp)) != NULL)
- {
- ++lineno;
- bool is_key = true;
- bool is_section = false;
- bool is_quote = false;
- unsigned ii;
- std::string key, value;
- for (ii = 0; line[ii] != '\0'; ii++)
- {
- if (is_quote && line[ii] == '\\' && line[ii + 1])
- {
- value += line[ii];
- ii++;
- value += line[ii];
- continue;
- }
- if (isspace(line[ii]) && !is_quote && is_key)
- {
- continue;
- }
- if (line[ii] == '#' && !is_quote && key == "")
- {
- break;
- }
- if (line[ii] == '[' && !is_quote)
- {
- is_section = true;
- section = "";
- continue;
- }
- if (line[ii] == '"')
- {
- is_quote = !is_quote;
- value += line[ii];
- continue;
- }
- if (is_section)
- {
- if (line[ii] == ']')
- break;
- section += line[ii];
- continue;
- }
- if (is_key && line[ii] == '=' && !is_quote)
- {
- while (isspace(line[ii + 1])) ii++;
- is_key = false;
- key = value;
- value = "";
- continue;
- }
- value += line[ii];
- } /* for */
-
- if (is_quote)
- {
- error_msg("abrt.conf: Invalid syntax on line %d", lineno);
- goto return_error;
- }
-
- if (is_section)
- {
- if (line[ii] != ']') /* section not closed */
- {
- error_msg("abrt.conf: Section not closed on line %d", lineno);
- goto return_error;
- }
- goto free_line;
- }
-
- if (is_key)
- {
- if (!value.empty()) /* the key is stored in value */
- {
- error_msg("abrt.conf: Invalid syntax on line %d", lineno);
- goto return_error;
- }
- goto free_line;
- }
- if (key.empty()) /* A line without key: " = something" */
- {
- error_msg("abrt.conf: Invalid syntax on line %d", lineno);
- goto return_error;
- }
-
- if (section == SECTION_COMMON)
- {
- if (s_mapSectionCommon[key] != "")
- s_mapSectionCommon[key] += ",";
- s_mapSectionCommon[key] += value;
- }
- else if (section == SECTION_LOG_SCANNERS)
- {
- g_settings_sLogScanners = xstrdup(value.c_str());
- }
- else
- {
- error_msg("abrt.conf: Ignoring entry in invalid section [%s]", section.c_str());
- return_error:
- free(line);
- return 1; /* error */
- }
- free_line:
- free(line);
- } /* while */
-
- return 0; /* success */
-}
-
-/* abrt daemon loads .conf file */
int load_settings()
{
- int err = 0;
-
- FILE *fp = fopen(CONF_DIR"/abrt.conf", "r");
- if (fp)
- {
- err = ReadConfigurationFromFile(fp);
- fclose(fp);
- }
- else
- error_msg("Unable to read configuration file %s", CONF_DIR"/abrt.conf");
-
- if (err == 0)
- err = ParseCommon();
-
- if (err == 0)
- {
- /*
- * loading gpg keys will invoke rpm_load_gpgkey() from rpm.cpp
- * pgpReadPkts which makes nss to re-init and thus makes
- * bugzilla plugin work :-/
- */
- //FIXME FIXME FIXME FIXME FIXME FIXME!!!
- //if (g_settings_bOpenGPGCheck)
- LoadGPGKeys();
- }
-
- return err;
-}
-
-void free_settings()
-{
- list_free_with_free(g_settings_setOpenGPGPublicKeys);
- g_settings_setOpenGPGPublicKeys = NULL;
+ free_settings();
- list_free_with_free(g_settings_setBlackListedPkgs);
- g_settings_setBlackListedPkgs = NULL;
+ map_string_h *settings = new_map_string();
+ if (!load_conf_file(CONF_DIR"/abrt.conf", settings, /*skip key w/o values:*/ false))
+ error_msg("Can't open '%s'", CONF_DIR"/abrt.conf");
- list_free_with_free(g_settings_setBlackListedPaths);
- g_settings_setBlackListedPaths = NULL;
+ ParseCommon(settings, CONF_DIR"/abrt.conf");
+ free_map_string(settings);
- free(g_settings_sWatchCrashdumpArchiveDir);
- g_settings_sWatchCrashdumpArchiveDir = NULL;
+ LoadGPGKeys();
- free(g_settings_sLogScanners);
- g_settings_sLogScanners = NULL;
+ return 0;
}