summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZdenek Prikryl <zprikryl@redhat.com>2009-08-25 18:23:51 +0200
committerZdenek Prikryl <zprikryl@redhat.com>2009-08-25 18:23:51 +0200
commit0724397c1a2133a18f3783dd3429ba8cb2258ac1 (patch)
tree02bd2851792939aa99742ed8f9184d2df88d57cd /src
parent9be125e13683cf7defb3d78f9e53c83a0221372c (diff)
downloadabrt-0724397c1a2133a18f3783dd3429ba8cb2258ac1.tar.gz
abrt-0724397c1a2133a18f3783dd3429ba8cb2258ac1.tar.xz
abrt-0724397c1a2133a18f3783dd3429ba8cb2258ac1.zip
added support for saving settings
Diffstat (limited to 'src')
-rw-r--r--src/Daemon/Settings.cpp104
-rw-r--r--src/Daemon/Settings.h6
2 files changed, 108 insertions, 2 deletions
diff --git a/src/Daemon/Settings.cpp b/src/Daemon/Settings.cpp
index b7497ef4..468213dc 100644
--- a/src/Daemon/Settings.cpp
+++ b/src/Daemon/Settings.cpp
@@ -286,3 +286,107 @@ void LoadSettings(const char* pPath)
ParseCron();
}
+static void SaveSetString(const std::string& pKey, const set_strings_t& pSet, std::ofstream& pFOut, bool pNewLine = true)
+{
+ set_strings_t::const_iterator it_set;
+ if (pKey != "")
+ {
+ pFOut << pKey << " = ";
+ }
+ int ii = 0;
+ for (it_set = pSet.begin(); it_set != pSet.end(); it_set++)
+ {
+ pFOut << (*it_set);
+ ii++;
+ if (ii < pSet.size())
+ {
+ pFOut << ",";
+ }
+ }
+ if (pNewLine)
+ {
+ pFOut << std::endl;
+ }
+}
+
+static void SaveVectorPairStrings(const std::string& pKey, const vector_pair_string_string_t& pVector, std::ofstream& pFOut, bool pNewLine = true)
+{
+ int ii;
+ if (pKey != "")
+ {
+ pFOut << pKey << " = ";
+ }
+ for (ii = 0; ii < pVector.size(); ii++)
+ {
+ pFOut << pVector[ii].first;
+ if (pVector[ii].second != "")
+ {
+ pFOut << "(" << pVector[ii].second << ")";
+ }
+ if ((ii + 1) < pVector.size())
+ {
+ pFOut << ",";
+ }
+ }
+ if (pNewLine)
+ {
+ pFOut << std::endl;
+ }
+}
+
+static void SaveMapVectorPairStrings(const map_vector_pair_strings_t& pMap, std::ofstream& pFOut, bool pNewLine = true)
+{
+ map_vector_pair_strings_t::const_iterator it;
+ for (it = pMap.begin(); it != pMap.end(); it++)
+ {
+ pFOut << it->first << " = ";
+ SaveVectorPairStrings("", it->second, pFOut, false);
+ pFOut << std::endl;
+ }
+ if (pNewLine)
+ {
+ pFOut << std::endl;
+ }
+
+}
+
+static void SaveSection(const std::string& pSection, std::ofstream& pFOut)
+{
+ pFOut << std::endl << "[" << pSection << "]" << std::endl << std::endl;
+}
+
+static void SaveBool(const std::string& pKey, const bool pBool, std::ofstream& pFOut, bool pNewLine = true)
+{
+ if (pKey != "")
+ {
+ pFOut << pKey << " = ";
+ }
+ pFOut << (pBool ? "yes" : "no");
+ if (pNewLine)
+ {
+ pFOut << std::endl;
+ }
+}
+
+void SaveSettings(const char* pPath)
+{
+ std::ofstream fOut;
+ fOut.open(pPath);
+
+ if (fOut.is_open())
+ {
+ SaveSection(SECTION_COMMON, fOut);
+ SaveBool("OpenGPGCheck", g_settings_bOpenGPGCheck, fOut);
+ SaveSetString("OpenGPGPublicKeys", g_settings_setOpenGPGPublicKeys, fOut);
+ SaveSetString("BlackList", g_settings_mapSettingsBlackList, fOut);
+ SaveSetString("EnabledPlugins", g_settings_setEnabledPlugins, fOut);
+ fOut << "Database = " << g_settings_sDatabase << std::endl;
+ fOut << "MaxCrashReportsSize = " << g_settings_nMaxCrashReportsSize << std::endl;
+ SaveVectorPairStrings("ActionsAndReporters", g_settings_vectorActionsAndReporters, fOut);
+ SaveSection(SECTION_ANALYZER_ACTIONS_AND_REPORTERS, fOut);
+ SaveMapVectorPairStrings(g_settings_mapAnalyzerActionsAndReporters, fOut);
+ SaveSection(SECTION_CRON, fOut);
+ SaveMapVectorPairStrings(g_settings_mapCron, fOut);
+ fOut.close();
+ }
+}
diff --git a/src/Daemon/Settings.h b/src/Daemon/Settings.h
index c95786d3..3d3154f6 100644
--- a/src/Daemon/Settings.h
+++ b/src/Daemon/Settings.h
@@ -12,10 +12,12 @@ typedef std::map<std::string, std::string> map_settings_t;
typedef std::set<std::string> set_strings_t;
typedef std::pair<std::string, std::string> pair_string_string_t;
typedef std::vector<pair_string_string_t> vector_pair_strings_t;
-typedef std::map<std::string, vector_pair_strings_t> map_analyzer_actions_and_reporters_t;
-typedef std::map<std::string, vector_pair_strings_t> map_cron_t;
+typedef std::map<std::string, vector_pair_strings_t> map_vector_pair_strings_t;
+typedef map_vector_pair_strings_t map_analyzer_actions_and_reporters_t;
+typedef map_vector_pair_strings_t map_cron_t;
void LoadSettings(const char* pPath);
+void SaveSettings(const char* pPath);
extern set_strings_t g_settings_setOpenGPGPublicKeys;
extern set_strings_t g_settings_mapSettingsBlackList;