summaryrefslogtreecommitdiffstats
path: root/src/Daemon/Settings.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-24 13:25:24 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-24 13:25:24 +0200
commit604dcb6694701281b0e42dfee597cbd205c68649 (patch)
treef0dd957ba225a31d8fb82cde06a4871264f3b727 /src/Daemon/Settings.cpp
parent7c223d2142bf11cda27fd43c387cbfa66838f433 (diff)
downloadabrt-604dcb6694701281b0e42dfee597cbd205c68649.tar.gz
abrt-604dcb6694701281b0e42dfee597cbd205c68649.tar.xz
abrt-604dcb6694701281b0e42dfee597cbd205c68649.zip
dismantle single-instance class CSettings
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Daemon/Settings.cpp')
-rw-r--r--src/Daemon/Settings.cpp388
1 files changed, 177 insertions, 211 deletions
diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp
index 4c85b999..955bd1bd 100644
--- a/src/Daemon/Settings.cpp
+++ b/src/Daemon/Settings.cpp
@@ -6,161 +6,47 @@
#define SECTION_ANALYZER_ACTIONS_AND_REPORTERS "AnalyzerActionsAndReporters"
#define SECTION_CRON "Cron"
-CSettings::CSettings() :
- m_bOpenGPGCheck(false),
- m_nMaxCrashReportsSize(1000)
-{}
-void CSettings::LoadSettings(const std::string& pPath)
-{
- std::ifstream fIn;
- fIn.open(pPath.c_str());
- if (fIn.is_open())
- {
- std::string line;
- std::string section = "";
- while (!fIn.eof())
- {
- getline(fIn, line);
+set_strings_t g_settings_setOpenGPGPublicKeys;
+set_strings_t g_settings_mapSettingsBlackList;
+vector_pair_string_string_t g_settings_vectorActionsAndReporters;
+set_strings_t g_settings_setEnabledPlugins;
+map_analyzer_actions_and_reporters_t g_settings_mapAnalyzerActionsAndReporters;
+unsigned int g_settings_nMaxCrashReportsSize = 1000;
+bool g_settings_bOpenGPGCheck = false;
+std::string g_settings_sDatabase;
+map_cron_t g_settings_mapCron;
- unsigned int ii;
- bool is_key = true;
- bool is_section = false;
- bool is_quote = false;
- std::string key = "";
- std::string value = "";
- for (ii = 0; ii < line.length(); ii++)
- {
- if (isspace(line[ii]) && !is_quote)
- {
- continue;
- }
- else if (line[ii] == '#' && !is_quote && key == "")
- {
- break;
- }
- else if (line[ii] == '[' && !is_quote)
- {
- is_section = true;
- section = "";
- }
- else if (line[ii] == '\"')
- {
- is_quote = is_quote == true ? false : true;
- value += line[ii];
- }
- else if (is_section)
- {
- if (line[ii] == ']')
- {
- break;
- }
- section += line[ii];
- }
- else if (line[ii] == '=' && !is_quote)
- {
- is_key = false;
- key = value;
- value = "";
- }
- else
- {
- value += line[ii];
- }
- }
- if (!is_key && !is_quote)
- {
- if (section == SECTION_COMMON)
- {
- if (m_mapSettingsCommon[key] != "")
- {
- m_mapSettingsCommon[key] += ",";
- }
- m_mapSettingsCommon[key] += value;
- }
- else if (section == SECTION_ANALYZER_ACTIONS_AND_REPORTERS)
- {
- if (m_mapSettingsAnalyzerActionsAndReporters[key] != "")
- {
- m_mapSettingsAnalyzerActionsAndReporters[key] += ",";
- }
- m_mapSettingsAnalyzerActionsAndReporters[key] += value;
- }
- else if (section == SECTION_CRON)
- {
- if (m_mapSettingsCron[key] != "")
- {
- m_mapSettingsCron[key] += ",";
- }
- m_mapSettingsCron[key] += value;
- }
- }
- }
- fIn.close();
- }
- ParseCommon();
- ParseAnalyzerActionsAndReporters();
- ParseCron();
-}
-
-void CSettings::ParseCommon()
-{
- if (m_mapSettingsCommon.find("OpenGPGCheck") != m_mapSettingsCommon.end())
- {
- m_bOpenGPGCheck = m_mapSettingsCommon["OpenGPGCheck"] == "yes";
- }
- if (m_mapSettingsCommon.find("OpenGPGPublicKeys") != m_mapSettingsCommon.end())
- {
- m_setOpenGPGPublicKeys = ParseList(m_mapSettingsCommon["OpenGPGPublicKeys"]);
- }
- if (m_mapSettingsCommon.find("BlackList") != m_mapSettingsCommon.end())
- {
- m_setBlackList = ParseList(m_mapSettingsCommon["BlackList"]);
- }
- if (m_mapSettingsCommon.find("Database") != m_mapSettingsCommon.end())
- {
- m_sDatabase =m_mapSettingsCommon["Database"];
- }
- if (m_mapSettingsCommon.find("EnabledPlugins") != m_mapSettingsCommon.end())
- {
- m_setEnabledPlugins = ParseList(m_mapSettingsCommon["EnabledPlugins"]);
- }
- if (m_mapSettingsCommon.find("MaxCrashReportsSize") != m_mapSettingsCommon.end())
- {
- m_nMaxCrashReportsSize = atoi(m_mapSettingsCommon["MaxCrashReportsSize"].c_str());
- }
- if (m_mapSettingsCommon.find("ActionsAndReporters") != m_mapSettingsCommon.end())
- {
- m_vectorActionsAndReporters = ParseListWithArgs(m_mapSettingsCommon["ActionsAndReporters"]);
- }
-}
+static map_settings_t s_mapSettingsCommon;
+static map_settings_t s_mapSettingsAnalyzerActionsAndReporters;
+static map_settings_t s_mapSettingsCron;
-void CSettings::ParseAnalyzerActionsAndReporters()
-{
- map_settings_t::iterator it;
- for (it = m_mapSettingsAnalyzerActionsAndReporters.begin(); it != m_mapSettingsAnalyzerActionsAndReporters.end(); it++)
- {
- set_strings_t keys = ParseKey(it->first);
- vector_pair_strings_t actionsAndReporters = ParseListWithArgs(it->second);
- set_strings_t::iterator it_keys;
- for (it_keys = keys.begin(); it_keys != keys.end(); it_keys++)
- {
- m_mapAnalyzerActionsAndReporters[*it_keys] = actionsAndReporters;
- }
- }
-}
-void CSettings::ParseCron()
+static set_strings_t ParseList(const std::string& pList)
{
- map_settings_t::iterator it;
- for (it = m_mapSettingsCron.begin(); it != m_mapSettingsCron.end(); it++)
- {
- vector_pair_strings_t actionsAndReporters = ParseListWithArgs(it->second);
- m_mapCron[it->first] = actionsAndReporters;
- }
+ unsigned int ii;
+ std::string item = "";
+ set_strings_t set;
+ for(ii = 0; ii < pList.size(); ii++)
+ {
+ if (pList[ii] == ',')
+ {
+ set.insert(item);
+ item = "";
+ }
+ else
+ {
+ item += pList[ii];
+ }
+ }
+ if (item != "")
+ {
+ set.insert(item);
+ }
+ return set;
}
-vector_pair_strings_t CSettings::ParseListWithArgs(const std::string& pValue)
+static vector_pair_strings_t ParseListWithArgs(const std::string& pValue)
{
vector_pair_strings_t pluginsWithArgs;
unsigned int ii;
@@ -208,7 +94,49 @@ vector_pair_strings_t CSettings::ParseListWithArgs(const std::string& pValue)
return pluginsWithArgs;
}
-set_strings_t CSettings::ParseKey(const std::string& Key)
+static void ParseCommon()
+{
+ if (s_mapSettingsCommon.find("OpenGPGCheck") != s_mapSettingsCommon.end())
+ {
+ g_settings_bOpenGPGCheck = s_mapSettingsCommon["OpenGPGCheck"] == "yes";
+ }
+ if (s_mapSettingsCommon.find("OpenGPGPublicKeys") != s_mapSettingsCommon.end())
+ {
+ g_settings_setOpenGPGPublicKeys = ParseList(s_mapSettingsCommon["OpenGPGPublicKeys"]);
+ }
+ if (s_mapSettingsCommon.find("BlackList") != s_mapSettingsCommon.end())
+ {
+ g_settings_mapSettingsBlackList = ParseList(s_mapSettingsCommon["BlackList"]);
+ }
+ if (s_mapSettingsCommon.find("Database") != s_mapSettingsCommon.end())
+ {
+ g_settings_sDatabase = s_mapSettingsCommon["Database"];
+ }
+ if (s_mapSettingsCommon.find("EnabledPlugins") != s_mapSettingsCommon.end())
+ {
+ g_settings_setEnabledPlugins = ParseList(s_mapSettingsCommon["EnabledPlugins"]);
+ }
+ if (s_mapSettingsCommon.find("MaxCrashReportsSize") != s_mapSettingsCommon.end())
+ {
+ g_settings_nMaxCrashReportsSize = atoi(s_mapSettingsCommon["MaxCrashReportsSize"].c_str());
+ }
+ if (s_mapSettingsCommon.find("ActionsAndReporters") != s_mapSettingsCommon.end())
+ {
+ g_settings_vectorActionsAndReporters = ParseListWithArgs(s_mapSettingsCommon["ActionsAndReporters"]);
+ }
+}
+
+static void ParseCron()
+{
+ map_settings_t::iterator it;
+ for (it = s_mapSettingsCron.begin(); it != s_mapSettingsCron.end(); it++)
+ {
+ vector_pair_strings_t actionsAndReporters = ParseListWithArgs(it->second);
+ g_settings_mapCron[it->first] = actionsAndReporters;
+ }
+}
+
+static set_strings_t ParseKey(const std::string& Key)
{
unsigned int ii;
std::string item = "";
@@ -250,72 +178,110 @@ set_strings_t CSettings::ParseKey(const std::string& Key)
return set;
}
-set_strings_t CSettings::ParseList(const std::string& pList)
-{
- unsigned int ii;
- std::string item = "";
- set_strings_t set;
- for(ii = 0; ii < pList.size(); ii++)
- {
- if (pList[ii] == ',')
- {
- set.insert(item);
- item = "";
- }
- else
- {
- item += pList[ii];
- }
- }
- if (item != "")
- {
- set.insert(item);
- }
- return set;
-}
-
-
-const set_strings_t& CSettings::GetBlackList()
-{
- return m_setBlackList;
-}
-
-const set_strings_t& CSettings::GetEnabledPlugins()
-{
- return m_setEnabledPlugins;
-}
-
-const set_strings_t& CSettings::GetOpenGPGPublicKeys()
-{
- return m_setOpenGPGPublicKeys;
-}
-
-bool CSettings::GetOpenGPGCheck()
+static void ParseAnalyzerActionsAndReporters()
{
- return m_bOpenGPGCheck;
-}
-
-const map_analyzer_actions_and_reporters_t& CSettings::GetAnalyzerActionsAndReporters()
-{
- return m_mapAnalyzerActionsAndReporters;
-}
-
-const unsigned int& CSettings::GetMaxCrashReportsSize()
-{
- return m_nMaxCrashReportsSize;
+ map_settings_t::iterator it;
+ for (it = s_mapSettingsAnalyzerActionsAndReporters.begin(); it != s_mapSettingsAnalyzerActionsAndReporters.end(); it++)
+ {
+ set_strings_t keys = ParseKey(it->first);
+ vector_pair_strings_t actionsAndReporters = ParseListWithArgs(it->second);
+ set_strings_t::iterator it_keys;
+ for (it_keys = keys.begin(); it_keys != keys.end(); it_keys++)
+ {
+ g_settings_mapAnalyzerActionsAndReporters[*it_keys] = actionsAndReporters;
+ }
+ }
}
-const vector_pair_strings_t& CSettings::GetActionsAndReporters()
+void LoadSettings(const std::string& pPath)
{
- return m_vectorActionsAndReporters;
-}
+ std::ifstream fIn;
+ fIn.open(pPath.c_str());
+ if (fIn.is_open())
+ {
+ std::string line;
+ std::string section = "";
+ while (!fIn.eof())
+ {
+ getline(fIn, line);
-const std::string& CSettings::GetDatabase()
-{
- return m_sDatabase;
+ unsigned int ii;
+ bool is_key = true;
+ bool is_section = false;
+ bool is_quote = false;
+ std::string key = "";
+ std::string value = "";
+ for (ii = 0; ii < line.length(); ii++)
+ {
+ if (isspace(line[ii]) && !is_quote)
+ {
+ continue;
+ }
+ else if (line[ii] == '#' && !is_quote && key == "")
+ {
+ break;
+ }
+ else if (line[ii] == '[' && !is_quote)
+ {
+ is_section = true;
+ section = "";
+ }
+ else if (line[ii] == '\"')
+ {
+ is_quote = is_quote == true ? false : true;
+ value += line[ii];
+ }
+ else if (is_section)
+ {
+ if (line[ii] == ']')
+ {
+ break;
+ }
+ section += line[ii];
+ }
+ else if (line[ii] == '=' && !is_quote)
+ {
+ is_key = false;
+ key = value;
+ value = "";
+ }
+ else
+ {
+ value += line[ii];
+ }
+ }
+ if (!is_key && !is_quote)
+ {
+ if (section == SECTION_COMMON)
+ {
+ if (s_mapSettingsCommon[key] != "")
+ {
+ s_mapSettingsCommon[key] += ",";
+ }
+ s_mapSettingsCommon[key] += value;
+ }
+ else if (section == SECTION_ANALYZER_ACTIONS_AND_REPORTERS)
+ {
+ if (s_mapSettingsAnalyzerActionsAndReporters[key] != "")
+ {
+ s_mapSettingsAnalyzerActionsAndReporters[key] += ",";
+ }
+ s_mapSettingsAnalyzerActionsAndReporters[key] += value;
+ }
+ else if (section == SECTION_CRON)
+ {
+ if (s_mapSettingsCron[key] != "")
+ {
+ s_mapSettingsCron[key] += ",";
+ }
+ s_mapSettingsCron[key] += value;
+ }
+ }
+ }
+ fIn.close();
+ }
+ ParseCommon();
+ ParseAnalyzerActionsAndReporters();
+ ParseCron();
}
-const map_cron_t& CSettings::GetCron()
-{
- return m_mapCron;
-}