summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com>2009-08-11 18:37:33 +0200
committerZdenek Prikryl <zdeny@dhcp-lab-218.englab.brq.redhat.com>2009-08-11 18:37:33 +0200
commit3335a8cc4e772ed027e400cfac10b17c1536ad9f (patch)
tree5a5dca74ecd6b2ea5376f4ee9b73510b68cfa3db /src
parentc0a64f7f5ed5abc1f729177da84d496a49e10081 (diff)
downloadabrt-3335a8cc4e772ed027e400cfac10b17c1536ad9f.tar.gz
abrt-3335a8cc4e772ed027e400cfac10b17c1536ad9f.tar.xz
abrt-3335a8cc4e772ed027e400cfac10b17c1536ad9f.zip
moved LoadSettings from plugins into PluginManager
Diffstat (limited to 'src')
-rw-r--r--src/Daemon/CrashWatcher.cpp15
-rw-r--r--src/Daemon/CrashWatcher.h2
-rw-r--r--src/Daemon/MiddleWare.cpp40
-rw-r--r--src/Daemon/MiddleWare.h28
-rw-r--r--src/Daemon/PluginManager.cpp122
-rw-r--r--src/Daemon/PluginManager.h30
6 files changed, 186 insertions, 51 deletions
diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp
index 0b98454e..4c0ba64e 100644
--- a/src/Daemon/CrashWatcher.cpp
+++ b/src/Daemon/CrashWatcher.cpp
@@ -820,16 +820,7 @@ bool CCrashWatcher::Report(map_crash_report_t pReport, const std::string& pUID)
//}
try
{
- struct passwd* pw = getpwuid(atoi(pUID.c_str()));
- std::string home = pw ? pw->pw_dir : "";
- if (home != "")
- {
- m_pMW->Report(pReport, home + "/.abrt/");
- }
- else
- {
- m_pMW->Report(pReport);
- }
+ m_pMW->Report(pReport, pUID);
}
catch (CABRTException& e)
{
@@ -893,11 +884,11 @@ vector_map_string_string_t CCrashWatcher::GetPluginsInfo()
return vector_map_string_string_t();
}
-map_plugin_settings_t CCrashWatcher::GetPluginSettings(const std::string& pName)
+map_plugin_settings_t CCrashWatcher::GetPluginSettings(const std::string& pName, const std::string& pUID)
{
try
{
- return m_pMW->GetPluginSettings(pName);
+ return m_pMW->GetPluginSettings(pName, pUID);
}
catch(CABRTException &e)
{
diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h
index 689d2108..bc8c6f64 100644
--- a/src/Daemon/CrashWatcher.h
+++ b/src/Daemon/CrashWatcher.h
@@ -132,7 +132,7 @@ class CCrashWatcher
virtual map_crash_report_t GetJobResult(uint64_t pJobID, const std::string& pSender);
/* plugins related */
virtual vector_map_string_string_t GetPluginsInfo();
- virtual map_plugin_settings_t GetPluginSettings(const std::string& pName);
+ virtual map_plugin_settings_t GetPluginSettings(const std::string& pName, const std::string& pUID);
void RegisterPlugin(const std::string& pName);
void UnRegisterPlugin(const std::string& pName);
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp
index 6ebeffda..80380555 100644
--- a/src/Daemon/MiddleWare.cpp
+++ b/src/Daemon/MiddleWare.cpp
@@ -110,14 +110,16 @@ void CMiddleWare::UnRegisterPlugin(const std::string& pName)
}
void CMiddleWare::SetPluginSettings(const std::string& pName,
+ const std::string& pUID,
const map_plugin_settings_t& pSettings)
{
- m_pPluginManager->SetPluginSettings(pName, pSettings);
+ m_pPluginManager->SetPluginSettings(pName, pUID, pSettings);
}
-map_plugin_settings_t CMiddleWare::GetPluginSettings(const std::string& pName)
+map_plugin_settings_t CMiddleWare::GetPluginSettings(const std::string& pName,
+ const std::string& pUID)
{
- return m_pPluginManager->GetPluginSettings(pName);
+ return m_pPluginManager->GetPluginSettings(pName, pUID);
}
std::string CMiddleWare::GetLocalUUID(const std::string& pAnalyzer,
@@ -245,13 +247,8 @@ void CMiddleWare::RunActionsAndReporters(const std::string& pDebugDumpDir)
}
}
-void CMiddleWare::Report(const map_crash_report_t& pCrashReport)
-{
- Report(pCrashReport, m_sPluginsConfDir);
-}
-
void CMiddleWare::Report(const map_crash_report_t& pCrashReport,
- const std::string& pPluginsConfDir)
+ const std::string& pUID)
{
if (pCrashReport.find(CD_MWANALYZER) == pCrashReport.end() ||
pCrashReport.find(CD_MWUID) == pCrashReport.end() ||
@@ -275,16 +272,29 @@ void CMiddleWare::Report(const map_crash_report_t& pCrashReport,
if (m_pPluginManager->GetPluginType((*it_r).first) == REPORTER)
{
CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first);
+ std::string home = "";
+ map_plugin_settings_t oldSettings;
+ map_plugin_settings_t newSettings;
- if (pPluginsConfDir == m_sPluginsConfDir)
+ if (pUID != "")
{
- reporter->Report(pCrashReport, (*it_r).second);
+ home = get_home_dir(atoi(pUID.c_str()));
+ if (home != "")
+ {
+ oldSettings = reporter->GetSettings();
+
+ if (m_pPluginManager->LoadPluginSettings(home + "/.abrt/" + (*it_r).first + "." + PLUGINS_CONF_EXTENSION, newSettings))
+ {
+ reporter->SetSettings(newSettings);
+ }
+ }
}
- else
+
+ reporter->Report(pCrashReport, (*it_r).second);
+
+ if (home != "")
{
- reporter->LoadSettings(pPluginsConfDir + "/" + (*it_r).first + "." + PLUGINS_CONF_EXTENSION);
- reporter->Report(pCrashReport, (*it_r).second);
- reporter->LoadSettings(m_sPluginsConfDir + "/" + (*it_r).first + "." + PLUGINS_CONF_EXTENSION);
+ reporter->SetSettings(oldSettings);
}
}
}
diff --git a/src/Daemon/MiddleWare.h b/src/Daemon/MiddleWare.h
index c9fc73a9..bb845435 100644
--- a/src/Daemon/MiddleWare.h
+++ b/src/Daemon/MiddleWare.h
@@ -199,23 +199,28 @@ class CMiddleWare
*/
void UnRegisterPlugin(const std::string& pName);
/**
- * A method, which sets up a plugin.
+ * A method, which sets up a plugin. The settings are also saved in home
+ * directory of an user.
* @param pName A plugin name.
+ * @param pUID An uid of user.
* @param pSettings A plugin's settings.
*/
void SetPluginSettings(const std::string& pName,
+ const std::string& pUID,
const map_plugin_settings_t& pSettings);
/**
- * A method, which returns plugin's settings.
+ * A method, which returns plugin's settings according to user.
* @param pName A plugin name.
- * @return Plugin's settings
+ * @param pUID An uid of user.
+ * @return Plugin's settings accorting to user.
*/
- map_plugin_settings_t GetPluginSettings(const std::string& pName);
+ map_plugin_settings_t GetPluginSettings(const std::string& pName,
+ const std::string& pUID);
/**
* A method, which gets all plugins info (event those plugins which are
* disabled). It can be send via DBus to GUI and displayed to an user.
* Then a user can fill all needed informations like URLs etc.
- * @return A vector of maps <key, vaule>
+ * @return A vector of maps <key, vaule>.
*/
vector_map_string_string_t GetPluginsInfo();
/**
@@ -247,19 +252,16 @@ class CMiddleWare
*/
void RunActionsAndReporters(const std::string& pDebugDumpDir);
/**
- * A method, which reports a crash report to particular receiver.
- * @param pCrashReport A crash report.
- */
- void Report(const map_crash_report_t& pCrashReport);
- /**
* A method, which reports a crash report to particular receiver. It
- * takes a path where settings of reporter are stored (e.g. $HOME/.abrt,
+ * takes an user uid, tries to find user config file and load it. If it
+ * fails, then default config is used. If pUID is emply string, default
+ * config is used.
* ...).
* @param pCrashReport A crash report.
- * @param pSettingsPath A path to setting files.
+ * @param pUID An user uid
*/
void Report(const map_crash_report_t& pCrashReport,
- const std::string& pSettingsPath);
+ const std::string& pUID);
/**
* A method, which deletes particular debugdump directory.
* @param pDebugDumpDir A debugdump directory.
diff --git a/src/Daemon/PluginManager.cpp b/src/Daemon/PluginManager.cpp
index b0ba0dba..06db64a7 100644
--- a/src/Daemon/PluginManager.cpp
+++ b/src/Daemon/PluginManager.cpp
@@ -26,6 +26,9 @@
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
+#include <stdlib.h>
+#include "abrtlib.h"
+#include <fstream>
/**
* Text representation of plugin types.
@@ -130,18 +133,20 @@ void CPluginManager::RegisterPlugin(const std::string& pName)
{
if (m_mapPlugins.find(pName) == m_mapPlugins.end())
{
- std::string path = m_sPluginsConfDir + "/" + pName + "." + PLUGINS_CONF_EXTENSION;
CPlugin* plugin = m_mapABRTPlugins[pName]->PluginNew();
+ map_plugin_settings_t pluginSettings;
+
+ LoadPluginSettings(m_sPluginsConfDir + "/" + pName + "." + PLUGINS_CONF_EXTENSION, pluginSettings);
try
{
plugin->Init();
- plugin->LoadSettings(path);
+ plugin->SetSettings(pluginSettings);
}
- catch (std::string sError)
+ catch (CABRTException& e)
{
comm_layer_inner_warning("Can not initialize plugin " + pName + "("
+ std::string(plugin_type_str_t[m_mapABRTPlugins[pName]->GetType()])
- + ")");
+ + "): " + e.what());
UnLoadPlugin(pName);
return;
}
@@ -262,6 +267,7 @@ vector_map_string_string_t CPluginManager::GetPluginsInfo()
}
void CPluginManager::SetPluginSettings(const std::string& pName,
+ const std::string& pUID,
const map_plugin_settings_t& pSettings)
{
if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end())
@@ -269,19 +275,123 @@ void CPluginManager::SetPluginSettings(const std::string& pName,
if (m_mapPlugins.find(pName) != m_mapPlugins.end())
{
m_mapPlugins[pName]->SetSettings(pSettings);
+
+ if (m_mapABRTPlugins[pName]->GetType() == REPORTER)
+ {
+ std::string home = get_home_dir(atoi(pUID.c_str()));
+ if (home != "")
+ {
+ SavePluginSettings(home + "/.abrt/" + pName + "." + PLUGINS_CONF_EXTENSION, pSettings);
+ }
+ }
}
}
}
-map_plugin_settings_t CPluginManager::GetPluginSettings(const std::string& pName)
+map_plugin_settings_t CPluginManager::GetPluginSettings(const std::string& pName,
+ const std::string& pUID)
{
map_plugin_settings_t ret;
if (m_mapABRTPlugins.find(pName) != m_mapABRTPlugins.end())
{
if (m_mapPlugins.find(pName) != m_mapPlugins.end())
{
- ret = m_mapPlugins[pName]->GetSettings();
+ if (m_mapABRTPlugins[pName]->GetType() == REPORTER)
+ {
+ std::string home = get_home_dir(atoi(pUID.c_str()));
+ if (home != "")
+ {
+ comm_layer_inner_debug("home: " + home);
+ if (LoadPluginSettings(home + "/.abrt/" + pName + "." + PLUGINS_CONF_EXTENSION, ret))
+ {
+ comm_layer_inner_debug("success");
+ return ret;
+ }
+ }
+ }
+ return m_mapPlugins[pName]->GetSettings();
}
}
return ret;
}
+
+bool CPluginManager::LoadPluginSettings(const std::string& pPath, map_plugin_settings_t& pSettings)
+{
+ std::ifstream fIn;
+ fIn.open(pPath.c_str());
+ if (fIn.is_open())
+ {
+ std::string line;
+ while (!fIn.eof())
+ {
+ getline(fIn, line);
+
+ int ii;
+ bool is_value = false;
+ bool valid = false;
+ bool in_quote = false;
+ std::string key = "";
+ std::string value = "";
+ for (ii = 0; ii < line.length(); ii++)
+ {
+ if (line[ii] == '\"')
+ {
+ in_quote = in_quote == true ? false : true;
+ }
+ if (isspace(line[ii]) && !in_quote)
+ {
+ continue;
+ }
+ if (line[ii] == '#' && !in_quote)
+ {
+ break;
+ }
+ else if (line[ii] == '=' && !in_quote)
+ {
+ is_value = true;
+ }
+ else if (line[ii] == '=' && is_value && !in_quote)
+ {
+ key = "";
+ value = "";
+ break;
+ }
+ else if (!is_value)
+ {
+ key += line[ii];
+ }
+ else
+ {
+ valid = true;
+ value += line[ii];
+ }
+ }
+ if (valid && !in_quote)
+ {
+ pSettings[key] = value;
+ }
+ }
+ fIn.close();
+ return true;
+ }
+ return false;
+
+}
+
+bool CPluginManager::SavePluginSettings(const std::string& pPath, const map_plugin_settings_t& pSettings)
+{
+ std::ofstream fOut;
+ fOut.open(pPath.c_str());
+ if (fOut.is_open())
+ {
+ fOut << "Settings were written by abrt." << std::endl;
+ map_plugin_settings_t::const_iterator it;
+ for (it = pSettings.begin(); it != pSettings.end(); it++)
+ {
+ fOut << it->first << " = " << it->second << std::endl;
+ }
+ fOut.close();
+ return true;
+ }
+ return false;
+}
diff --git a/src/Daemon/PluginManager.h b/src/Daemon/PluginManager.h
index 53ec77c9..47487d68 100644
--- a/src/Daemon/PluginManager.h
+++ b/src/Daemon/PluginManager.h
@@ -139,18 +139,40 @@ class CPluginManager
*/
vector_map_string_string_t GetPluginsInfo();
/**
- * A method, which sets up a plugin.
+ * A method, which sets up a plugin. The settings are also saved in home
+ * directory of an user.
* @param pName A plugin name.
+ * @param pUID An uid of user.
* @param pSettings A plugin's settings.
*/
void SetPluginSettings(const std::string& pName,
+ const std::string& pUID,
const map_plugin_settings_t& pSettings);
/**
- * A method, which returns plugin's settings.
+ * A method, which returns plugin's settings according to user.
* @param pName A plugin name.
- * @return Plugin's settings
+ * @param pUID An uid of user.
+ * @return Plugin's settings accorting to user.
*/
- map_plugin_settings_t GetPluginSettings(const std::string& pName);
+ map_plugin_settings_t GetPluginSettings(const std::string& pName,
+ const std::string& pUID);
+ /**
+ * A function. It loads settings and store it in second parameter. On success it
+ * returns true, otherwise returns false.
+ * @param path A path of config file.
+ * @param settings A readed plugin's settings.
+ * @return if it success it returns true, otherwise it returns false.
+ */
+ bool LoadPluginSettings(const std::string& pPath,
+ map_plugin_settings_t& pSettings);
+ /**
+ * A function. It saves settings. On success it returns true, otherwise returns false.
+ * @param path A path of config file.
+ * @param settings Plugin's settings.
+ * @return if it success it returns true, otherwise it returns false.
+ */
+ bool SavePluginSettings(const std::string& pPath,
+ const map_plugin_settings_t& pSettings);
};
#endif /*PLUGINMANAGER_H_*/