summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-08-06 03:07:25 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-08-06 03:07:25 +0200
commita882a401349a6205d7ff0039b7ce463e68b03b38 (patch)
tree22b719b6cddc62177bdcbf00d426ff44383da966 /src
parent37747efdd3c92c1b3736aa3a46ec6290bc7e824f (diff)
downloadabrt-a882a401349a6205d7ff0039b7ce463e68b03b38.tar.gz
abrt-a882a401349a6205d7ff0039b7ce463e68b03b38.tar.xz
abrt-a882a401349a6205d7ff0039b7ce463e68b03b38.zip
forgotten "git add"
Diffstat (limited to 'src')
-rw-r--r--src/Daemon/MiddleWare.cpp615
-rw-r--r--src/Daemon/MiddleWare.h349
2 files changed, 964 insertions, 0 deletions
diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp
new file mode 100644
index 0000000..7f1250c
--- /dev/null
+++ b/src/Daemon/MiddleWare.cpp
@@ -0,0 +1,615 @@
+/*
+ MiddleWare.cpp
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "MiddleWare.h"
+#include "DebugDump.h"
+#include "ABRTException.h"
+#include "CommLayerInner.h"
+
+CMiddleWare::CMiddleWare(const std::string& pPluginsConfDir,
+ const std::string& pPluginsLibDir) :
+ m_pPluginManager(NULL),
+ m_bOpenGPGCheck(true),
+ m_sPluginsConfDir(pPluginsConfDir)
+{
+ m_pPluginManager = new CPluginManager(pPluginsConfDir, pPluginsLibDir);
+ m_pPluginManager->LoadPlugins();
+}
+
+CMiddleWare::~CMiddleWare()
+{
+ m_pPluginManager->UnLoadPlugins();
+ delete m_pPluginManager;
+}
+
+void CMiddleWare::DebugDumpToCrashReport(const std::string& pDebugDumpDir, map_crash_report_t& pCrashReport)
+{
+ std::string fileName;
+ std::string content;
+ bool isTextFile;
+ CDebugDump dd;
+ dd.Open(pDebugDumpDir);
+
+ if (!dd.Exist(FILENAME_ARCHITECTURE) ||
+ !dd.Exist(FILENAME_KERNEL) ||
+ !dd.Exist(FILENAME_PACKAGE) ||
+ !dd.Exist(FILENAME_RELEASE) ||
+ !dd.Exist(FILENAME_EXECUTABLE))
+ {
+ dd.Close();
+ throw CABRTException(EXCEP_ERROR, "CMiddleWare::DebugDumpToCrashReport(): One or more of important file(s)'re missing.");
+ }
+ pCrashReport.clear();
+ dd.InitGetNextFile();
+ while (dd.GetNextFile(fileName, content, isTextFile))
+ {
+ if (!isTextFile)
+ {
+ add_crash_data_to_crash_report(pCrashReport,
+ fileName,
+ CD_BIN,
+ CD_ISNOTEDITABLE,
+ pDebugDumpDir + "/" + fileName);
+ }
+ else
+ {
+ if (fileName == FILENAME_ARCHITECTURE ||
+ fileName == FILENAME_KERNEL ||
+ fileName == FILENAME_PACKAGE ||
+ fileName == FILENAME_RELEASE ||
+ fileName == FILENAME_EXECUTABLE)
+ {
+ add_crash_data_to_crash_report(pCrashReport, fileName, CD_TXT, CD_ISNOTEDITABLE, content);
+ }
+ else if (fileName != FILENAME_UID &&
+ fileName != FILENAME_ANALYZER &&
+ fileName != FILENAME_TIME &&
+ fileName != FILENAME_DESCRIPTION )
+ {
+ if (content.length() < CD_ATT_SIZE)
+ {
+ add_crash_data_to_crash_report(pCrashReport, fileName, CD_TXT, CD_ISEDITABLE, content);
+ }
+ else
+ {
+ add_crash_data_to_crash_report(pCrashReport, fileName, CD_ATT, CD_ISEDITABLE, content);
+ }
+ }
+ }
+ }
+ dd.Close();
+}
+
+void CMiddleWare::RegisterPlugin(const std::string& pName)
+{
+ m_pPluginManager->RegisterPlugin(pName);
+}
+
+void CMiddleWare::UnRegisterPlugin(const std::string& pName)
+{
+ m_pPluginManager->UnRegisterPlugin(pName);
+}
+
+void CMiddleWare::SetPluginSettings(const std::string& pName,
+ const map_plugin_settings_t& pSettings)
+{
+ m_pPluginManager->SetPluginSettings(pName, pSettings);
+}
+
+map_plugin_settings_t CMiddleWare::GetPluginSettings(const std::string& pName)
+{
+ return m_pPluginManager->GetPluginSettings(pName);
+}
+
+std::string CMiddleWare::GetLocalUUID(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir)
+{
+ CAnalyzer* analyzer = m_pPluginManager->GetAnalyzer(pAnalyzer);
+ return analyzer->GetLocalUUID(pDebugDumpDir);
+}
+
+std::string CMiddleWare::GetGlobalUUID(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir)
+{
+ CAnalyzer* analyzer = m_pPluginManager->GetAnalyzer(pAnalyzer);
+ return analyzer->GetGlobalUUID(pDebugDumpDir);
+}
+
+void CMiddleWare::CreateReport(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir)
+{
+ CAnalyzer* analyzer = m_pPluginManager->GetAnalyzer(pAnalyzer);
+ analyzer->CreateReport(pDebugDumpDir);
+}
+
+CMiddleWare::mw_result_t CMiddleWare::CreateCrashReport(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_report_t& pCrashReport)
+{
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ database_row_t row;
+ database->Connect();
+ row = database->GetUUIDData(pUUID, pUID);
+ database->DisConnect();
+ CDebugDump dd;
+
+ if (pUUID == "" || row.m_sUUID != pUUID)
+ {
+ comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): UUID '"+pUUID+"' is not in database.");
+ return MW_IN_DB_ERROR;
+ }
+
+ try
+ {
+ std::string analyzer;
+ std::string gUUID;
+
+ dd.Open(row.m_sDebugDumpDir);
+ dd.LoadText(FILENAME_ANALYZER, analyzer);
+ dd.Close();
+
+ CreateReport(analyzer, row.m_sDebugDumpDir);
+
+ gUUID = GetGlobalUUID(analyzer, row.m_sDebugDumpDir);
+
+ RunAnalyzerActions(analyzer, row.m_sDebugDumpDir);
+ DebugDumpToCrashReport(row.m_sDebugDumpDir, pCrashReport);
+
+ add_crash_data_to_crash_report(pCrashReport, CD_UUID, CD_TXT, CD_ISNOTEDITABLE, gUUID);
+ add_crash_data_to_crash_report(pCrashReport, CD_MWANALYZER, CD_SYS, CD_ISNOTEDITABLE, analyzer);
+ add_crash_data_to_crash_report(pCrashReport, CD_MWUID, CD_SYS, CD_ISNOTEDITABLE, pUID);
+ add_crash_data_to_crash_report(pCrashReport, CD_MWUUID, CD_SYS, CD_ISNOTEDITABLE, pUUID);
+ add_crash_data_to_crash_report(pCrashReport, CD_COMMENT, CD_TXT, CD_ISEDITABLE, "");
+ add_crash_data_to_crash_report(pCrashReport, CD_REPRODUCE, CD_TXT, CD_ISEDITABLE, "1.\n2.\n3.\n");
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::CreateCrashReport(): " + e.what());
+ if (e.type() == EXCEP_DD_OPEN)
+ {
+ return MW_ERROR;
+ }
+ else if (e.type() == EXCEP_DD_LOAD)
+ {
+ return MW_FILE_ERROR;
+ }
+ return MW_CORRUPTED;
+ }
+
+ return MW_OK;
+}
+
+void CMiddleWare::RunAction(const std::string& pActionDir,
+ const std::string& pPluginName,
+ const std::string& pPluginArgs)
+{
+ try
+ {
+ CAction* action = m_pPluginManager->GetAction(pPluginName);
+
+ action->Run(pActionDir, pPluginArgs);
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::RunAction(): " + e.what());
+ comm_layer_inner_status("Execution of '"+pPluginName+"' was not successful: " + e.what());
+ }
+
+}
+
+void CMiddleWare::RunActionsAndReporters(const std::string& pDebugDumpDir)
+{
+ vector_actions_and_reporters_t::iterator it_ar;
+ for (it_ar = m_vectorActionsAndReporters.begin(); it_ar != m_vectorActionsAndReporters.end(); it_ar++)
+ {
+ try
+ {
+ if (m_pPluginManager->GetPluginType((*it_ar).first) == REPORTER)
+ {
+ CReporter* reporter = m_pPluginManager->GetReporter((*it_ar).first);
+
+ map_crash_report_t crashReport;
+ DebugDumpToCrashReport(pDebugDumpDir, crashReport);
+ reporter->Report(crashReport, (*it_ar).second);
+ }
+ else if (m_pPluginManager->GetPluginType((*it_ar).first) == ACTION)
+ {
+ CAction* action = m_pPluginManager->GetAction((*it_ar).first);
+ action->Run(pDebugDumpDir, (*it_ar).second);
+ }
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::RunActionsAndReporters(): " + e.what());
+ comm_layer_inner_status("Activation of plugin '"+(*it_ar).first+"' was not successful: " + e.what());
+ }
+ }
+}
+
+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)
+{
+ if (pCrashReport.find(CD_MWANALYZER) == pCrashReport.end() ||
+ pCrashReport.find(CD_MWUID) == pCrashReport.end() ||
+ pCrashReport.find(CD_MWUUID) == pCrashReport.end())
+ {
+ throw CABRTException(EXCEP_ERROR, "CMiddleWare::Report(): System data are missing in crash report.");
+ }
+ std::string analyzer = pCrashReport.find(CD_MWANALYZER)->second[CD_CONTENT];
+ std::string UID = pCrashReport.find(CD_MWUID)->second[CD_CONTENT];
+ std::string UUID = pCrashReport.find(CD_MWUUID)->second[CD_CONTENT];
+
+ if (m_mapAnalyzerActionsAndReporters.find(analyzer) != m_mapAnalyzerActionsAndReporters.end())
+ {
+ vector_actions_and_reporters_t::iterator it_r;
+ for (it_r = m_mapAnalyzerActionsAndReporters[analyzer].begin();
+ it_r != m_mapAnalyzerActionsAndReporters[analyzer].end();
+ it_r++)
+ {
+ try
+ {
+ if (m_pPluginManager->GetPluginType((*it_r).first) == REPORTER)
+ {
+ CReporter* reporter = m_pPluginManager->GetReporter((*it_r).first);
+
+ if (pPluginsConfDir == m_sPluginsConfDir)
+ {
+ reporter->Report(pCrashReport, (*it_r).second);
+ }
+ else
+ {
+ 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);
+ }
+ }
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::Report(): " + e.what());
+ comm_layer_inner_status("Reporting via '"+(*it_r).first+"' was not successful: " + e.what());
+ }
+ }
+ }
+
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ database->Connect();
+ database->SetReported(UUID, UID);
+ database->DisConnect();
+}
+
+void CMiddleWare::DeleteDebugDumpDir(const std::string& pDebugDumpDir)
+{
+ CDebugDump dd;
+ dd.Open(pDebugDumpDir);
+ dd.Delete();
+ dd.Close();
+}
+
+std::string CMiddleWare::DeleteCrashInfo(const std::string& pUUID,
+ const std::string& pUID)
+{
+ database_row_t row;
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ database->Connect();
+ row = database->GetUUIDData(pUUID, pUID);
+ database->Delete(pUUID, pUID);
+ database->DisConnect();
+
+ return row.m_sDebugDumpDir;
+}
+
+
+bool CMiddleWare::IsDebugDumpSaved(const std::string& pUID,
+ const std::string& pDebugDumpDir)
+{
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ vector_database_rows_t rows;
+ database->Connect();
+ rows = database->GetUIDData(pUID);
+ database->DisConnect();
+
+ int ii;
+ bool found = false;
+ for (ii = 0; ii < rows.size(); ii++)
+ {
+ if (rows[ii].m_sDebugDumpDir == pDebugDumpDir)
+ {
+ found = true;
+ break;
+ }
+ }
+
+ return found;
+}
+
+CMiddleWare::mw_result_t CMiddleWare::SavePackageDescriptionToDebugDump(const std::string& pExecutable,
+ const std::string& pDebugDumpDir)
+{
+ std::string package;
+ std::string packageName;
+
+ if (pExecutable == "kernel")
+ {
+ packageName = package = "kernel";
+ }
+ else
+ {
+ package = m_RPM.GetPackage(pExecutable);
+ packageName = package.substr(0, package.rfind("-", package.rfind("-") - 1));
+ if (packageName == "" ||
+ (m_setBlackList.find(packageName) != m_setBlackList.end()))
+ {
+ if (packageName == "")
+ {
+ comm_layer_inner_debug("Executable doesn't belong to any package");
+ return MW_PACKAGE_ERROR;
+ }
+ comm_layer_inner_debug("Blacklisted package");
+ return MW_BLACKLISTED;
+ }
+ if (m_bOpenGPGCheck)
+ {
+ if (!m_RPM.CheckFingerprint(packageName) ||
+ !m_RPM.CheckHash(packageName, pExecutable))
+ {
+ comm_layer_inner_debug("Can not find package");
+ return MW_GPG_ERROR;
+ }
+ }
+ }
+
+ std::string description = m_RPM.GetDescription(packageName);
+
+ CDebugDump dd;
+ try
+ {
+ dd.Open(pDebugDumpDir);
+ dd.SaveText(FILENAME_PACKAGE, package);
+ dd.SaveText(FILENAME_DESCRIPTION, description);
+ dd.Close();
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::SavePackageDescriptionToDebugDump(): " + e.what());
+ if (e.type() == EXCEP_DD_SAVE)
+ {
+ dd.Close();
+ return MW_FILE_ERROR;
+ }
+ return MW_ERROR;
+ }
+
+ return MW_OK;
+}
+
+void CMiddleWare::RunAnalyzerActions(const std::string& pAnalyzer, const std::string& pDebugDumpDir)
+{
+ if (m_mapAnalyzerActionsAndReporters.find(pAnalyzer) != m_mapAnalyzerActionsAndReporters.end())
+ {
+ vector_actions_and_reporters_t::iterator it_a;
+ for (it_a = m_mapAnalyzerActionsAndReporters[pAnalyzer].begin();
+ it_a != m_mapAnalyzerActionsAndReporters[pAnalyzer].end();
+ it_a++)
+ {
+ try
+ {
+ if (m_pPluginManager->GetPluginType((*it_a).first) == ACTION)
+ {
+ CAction* action = m_pPluginManager->GetAction((*it_a).first);
+
+ action->Run(pDebugDumpDir, (*it_a).second);
+ }
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::RunAnalyzerActions(): " + e.what());
+ comm_layer_inner_status("Action performed by '"+(*it_a).first+"' was not successful: " + e.what());
+ }
+ }
+ }
+}
+
+CMiddleWare::mw_result_t CMiddleWare::SaveDebugDumpToDatabase(const std::string& pUUID,
+ const std::string& pUID,
+ const std::string& pTime,
+ const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo)
+{
+ mw_result_t res;
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ database_row_t row;
+ database->Connect();
+ database->Insert(pUUID, pUID, pDebugDumpDir, pTime);
+ row = database->GetUUIDData(pUUID, pUID);
+ database->DisConnect();
+ res = GetCrashInfo(pUUID, pUID, pCrashInfo);
+ if (row.m_sReported == "1")
+ {
+ comm_layer_inner_debug("Crash is already reported");
+ return MW_REPORTED;
+ }
+ if (row.m_sCount != "1")
+ {
+ comm_layer_inner_debug("Crash is in database already");
+ return MW_OCCURED;
+ }
+ return res;
+}
+
+CMiddleWare::mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir)
+{
+ map_crash_info_t info;
+ return SaveDebugDump(pDebugDumpDir, info);
+}
+
+CMiddleWare::mw_result_t CMiddleWare::SaveDebugDump(const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo)
+{
+ std::string lUUID;
+ std::string UID;
+ std::string time;
+ std::string analyzer;
+ std::string executable;
+ CDebugDump dd;
+ mw_result_t res;
+
+ try
+ {
+ dd.Open(pDebugDumpDir);
+ dd.LoadText(FILENAME_TIME, time);
+ dd.LoadText(FILENAME_UID, UID);
+ dd.LoadText(FILENAME_ANALYZER, analyzer);
+ dd.LoadText(FILENAME_EXECUTABLE, executable);
+ dd.Close();
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::SaveDebugDump(): " + e.what());
+ if (e.type() == EXCEP_DD_SAVE)
+ {
+ dd.Close();
+ return MW_FILE_ERROR;
+ }
+ return MW_ERROR;
+ }
+
+ if (IsDebugDumpSaved(UID, pDebugDumpDir))
+ {
+ return MW_IN_DB;
+ }
+ if ((res = SavePackageDescriptionToDebugDump(executable, pDebugDumpDir)) != MW_OK)
+ {
+ return res;
+ }
+
+ lUUID = GetLocalUUID(analyzer, pDebugDumpDir);
+
+ return SaveDebugDumpToDatabase(lUUID, UID, time, pDebugDumpDir, pCrashInfo);
+}
+
+CMiddleWare::mw_result_t CMiddleWare::GetCrashInfo(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_info_t& pCrashInfo)
+{
+ pCrashInfo.clear();
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ database_row_t row;
+ database->Connect();
+ row = database->GetUUIDData(pUUID, pUID);
+ database->DisConnect();
+
+ CDebugDump dd;
+ std::string package;
+ std::string executable;
+ std::string description;
+
+ try
+ {
+ dd.Open(row.m_sDebugDumpDir);
+ dd.LoadText(FILENAME_EXECUTABLE, executable);
+ dd.LoadText(FILENAME_PACKAGE, package);
+ dd.LoadText(FILENAME_DESCRIPTION, description);
+ dd.Close();
+ }
+ catch (CABRTException& e)
+ {
+ comm_layer_inner_warning("CMiddleWare::GetCrashInfo(): " + e.what());
+ if (e.type() == EXCEP_DD_LOAD)
+ {
+ dd.Close();
+ return MW_FILE_ERROR;
+ }
+ return MW_ERROR;
+ }
+ add_crash_data_to_crash_info(pCrashInfo, CD_EXECUTABLE, executable);
+ add_crash_data_to_crash_info(pCrashInfo, CD_PACKAGE, package);
+ add_crash_data_to_crash_info(pCrashInfo, CD_DESCRIPTION, description);
+ add_crash_data_to_crash_info(pCrashInfo, CD_UUID, row.m_sUUID);
+ add_crash_data_to_crash_info(pCrashInfo, CD_UID, row.m_sUID);
+ add_crash_data_to_crash_info(pCrashInfo, CD_COUNT, row.m_sCount);
+ add_crash_data_to_crash_info(pCrashInfo, CD_TIME, row.m_sTime);
+ add_crash_data_to_crash_info(pCrashInfo, CD_REPORTED, row.m_sReported);
+ add_crash_data_to_crash_info(pCrashInfo, CD_MWDDD, row.m_sDebugDumpDir);
+
+ return MW_OK;
+}
+
+vector_pair_string_string_t CMiddleWare::GetUUIDsOfCrash(const std::string& pUID)
+{
+ CDatabase* database = m_pPluginManager->GetDatabase(m_sDatabase);
+ vector_database_rows_t rows;
+ database->Connect();
+ rows = database->GetUIDData(pUID);
+ database->DisConnect();
+
+ vector_pair_string_string_t UUIDsUIDs;
+ int ii;
+ for (ii = 0; ii < rows.size(); ii++)
+ {
+ UUIDsUIDs.push_back(make_pair(rows[ii].m_sUUID, rows[ii].m_sUID));
+ }
+
+ return UUIDsUIDs;
+}
+
+vector_map_string_string_t CMiddleWare::GetPluginsInfo()
+{
+ return m_pPluginManager->GetPluginsInfo();
+}
+
+void CMiddleWare::SetOpenGPGCheck(bool pCheck)
+{
+ m_bOpenGPGCheck = pCheck;
+}
+
+void CMiddleWare::SetDatabase(const std::string& pDatabase)
+{
+ m_sDatabase = pDatabase;
+}
+
+void CMiddleWare::AddOpenGPGPublicKey(const std::string& pKey)
+{
+ m_RPM.LoadOpenGPGPublicKey(pKey);
+}
+
+void CMiddleWare::AddBlackListedPackage(const std::string& pPackage)
+{
+ m_setBlackList.insert(pPackage);
+}
+
+void CMiddleWare::AddAnalyzerActionOrReporter(const std::string& pAnalyzer,
+ const std::string& pAnalyzerOrReporter,
+ const std::string& pArgs)
+{
+ m_mapAnalyzerActionsAndReporters[pAnalyzer].push_back(make_pair(pAnalyzerOrReporter, pArgs));
+}
+
+void CMiddleWare::AddActionOrReporter(const std::string& pActionOrReporter,
+ const std::string& pArgs)
+{
+ m_vectorActionsAndReporters.push_back(make_pair(pActionOrReporter, pArgs));
+}
diff --git a/src/Daemon/MiddleWare.h b/src/Daemon/MiddleWare.h
new file mode 100644
index 0000000..8b7376d
--- /dev/null
+++ b/src/Daemon/MiddleWare.h
@@ -0,0 +1,349 @@
+/*
+ MiddleWare.h - header file for MiddleWare library. It wraps plugins and
+ take case of them.
+
+ Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
+ Copyright (C) 2009 RedHat inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#ifndef MIDDLEWARE_H_
+#define MIDDLEWARE_H_
+
+#include "PluginManager.h"
+#include "CrashTypes.h"
+#include "MiddleWareTypes.h"
+#include "RPM.h"
+
+/**
+ * A very important class :-). It manages part of user demands like creating
+ * reports, or reporting stuff somewhere etc.
+ */
+class CMiddleWare
+{
+ public:
+ /**
+ * An emun contains all return codes.
+ */
+ typedef enum { MW_ERROR, /**< Common error.*/
+ MW_OK, /**< No error.*/
+ MW_BLACKLISTED, /**< Package is blacklisted.*/
+ MW_CORRUPTED, /**< Debugdump directory is corrupted.*/
+ MW_PACKAGE_ERROR, /**< Cannot determine package name.*/
+ MW_GPG_ERROR, /**< Package is not signed properly.*/
+ MW_REPORTED, /**< Crash is already reported.*/
+ MW_OCCURED, /**< Crash occurred in the past, but it is not reported yet.*/
+ MW_IN_DB, /**< Debugdump directory is already saved in a database.*/
+ MW_IN_DB_ERROR, /**< Error while working with a database.*/
+ MW_FILE_ERROR /**< Error when trying open debugdump directory or
+ when trying open file in debug dump directory..*/
+ } mw_result_t;
+
+ private:
+ typedef set_strings_t set_blacklist_t;
+ typedef set_strings_t set_enabled_plugins_t;
+ typedef std::vector<pair_string_string_t> vector_pairt_strings_t;
+ typedef vector_pairt_strings_t vector_actions_and_reporters_t;
+ typedef std::map<std::string, vector_actions_and_reporters_t> map_analyzer_actions_and_reporters_t;
+
+ /**
+ * An instance of CPluginManager. When MiddleWare wants to do something
+ * with plugins, it calls the plugin manager.
+ * @see PluginManager.h
+ */
+ CPluginManager* m_pPluginManager;
+ /**
+ * An instance of CRPM used for package checking.
+ * @see RPM.h
+ */
+ CRPM m_RPM;
+ /**
+ * A set of blacklisted packages.
+ */
+ set_blacklist_t m_setBlackList;
+ /**
+ * A name of database plugin, which is used for metadata.
+ */
+ std::string m_sDatabase;
+ /**
+ * A map, which associates particular analyzer to one or more
+ * action or reporter plugins. These are activated when a crash, which
+ * is maintained by particular analyzer, occurs.
+ */
+ map_analyzer_actions_and_reporters_t m_mapAnalyzerActionsAndReporters;
+ /**
+ * A vector of one or more action or reporter plugins. These are
+ * activated when any crash occurs.
+ */
+ vector_actions_and_reporters_t m_vectorActionsAndReporters;
+ /**
+ * Plugins configuration directory (e.g. /etc/abrt/plugins, ...).
+ */
+ std::string m_sPluginsConfDir;
+ /**
+ * Check GPG finger print?
+ */
+ bool m_bOpenGPGCheck;
+ /**
+ * A method, which gets a local UUID from particular analyzer plugin.
+ * @param pAnalyzer A name of an analyzer plugin.
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
+ * @return A local UUID.
+ */
+ std::string GetLocalUUID(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir);
+ /**
+ * A method, which gets a global UUID from particular analyzer plugin.
+ * @param pAnalyzer A name of an analyzer plugin.
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
+ * @return A global UUID.
+ */
+ std::string GetGlobalUUID(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir);
+ /**
+ * A method, which takes care of getting all additional data needed
+ * for computing UUIDs and creating a report for particular analyzer
+ * plugin. This report could be send somewhere afterwards.
+ * @param pAnalyzer A name of an analyzer plugin.
+ * @param pDebugDumpPath A debugdump dir containing all necessary data.
+ */
+ void CreateReport(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir);
+ /**
+ * A method, which executes all action plugins, which are associated to
+ * particular analyzer plugin.
+ * @param pAnalyzer A name of an analyzer plugin.
+ * @param pDebugDumpPath A debugdump dir containing all necessary data.
+ */
+ void RunAnalyzerActions(const std::string& pAnalyzer,
+ const std::string& pDebugDumpDir);
+ /**
+ * A method, which transforms a debugdump direcortry to inner crash
+ * report form. This form is used for later reporting.
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
+ * @param pCrashReport A created crash report.
+ */
+ void DebugDumpToCrashReport(const std::string& pDebugDumpDir,
+ map_crash_report_t& pCrashReport);
+ /**
+ * A method, which checks is particular debugdump directory is saved
+ * in database. This check is done together with an UID of an user.
+ * @param pUID an UID of an user.
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
+ * @return It returns true if debugdump dir is already saved, otherwise
+ * it returns false.
+ */
+ bool IsDebugDumpSaved(const std::string& pUID,
+ const std::string& pDebugDumpDir);
+ /**
+ * A method, which gets a package name from executable name and saves
+ * package description to particular debugdump directory of a crash.
+ * @param pExecutable A name of crashed application.
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
+ * @return It return results of operation. See mw_result_t.
+ */
+ mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable,
+ const std::string& pDebugDumpDir);
+ /**
+ * A method, which save a debugdump into database. If a saving is
+ * successful, then a crash info is filled. Otherwise the crash info is
+ * not changed.
+ * @param pUUID A local UUID of a crash.
+ * @param pUID An UID of an user.
+ * @param pTime Time when a crash occurs.
+ * @param pDebugDumpPath A debugdump path.
+ * @param pCrashInfo A filled crash info.
+ * @return It return results of operation. See mw_result_t.
+ */
+ mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID,
+ const std::string& pUID,
+ const std::string& pTime,
+ const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo);
+
+ public:
+ /**
+ * A constructor.
+ * @param pPluginsConfDir A plugins configuration directory.
+ * @param pPluginsLibDir A plugins library directory.
+ */
+ CMiddleWare(const std::string& pPluginsConfDir,
+ const std::string& pPluginsLibDir);
+ /**
+ * A destructor.
+ */
+ ~CMiddleWare();
+ /**
+ * A method, which registers particular plugin.
+ * @param pName A plugin name.
+ */
+ void RegisterPlugin(const std::string& pName);
+ /**
+ * A method, which unregister particular plugin.
+ * @param pName A plugin name.
+ */
+ void UnRegisterPlugin(const std::string& pName);
+ /**
+ * A method, which sets up a plugin.
+ * @param pName A plugin name.
+ * @param pSettings A plugin's settings.
+ */
+ void SetPluginSettings(const std::string& pName,
+ const map_plugin_settings_t& pSettings);
+ /**
+ * A method, which returns plugin's settings.
+ * @param pName A plugin name.
+ * @return Plugin's settings
+ */
+ map_plugin_settings_t GetPluginSettings(const std::string& pName);
+ /**
+ * 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>
+ */
+ vector_map_string_string_t GetPluginsInfo();
+ /**
+ * A method, which takes care of getting all additional data needed
+ * for computing UUIDs and creating a report for particular analyzer
+ * plugin. This report could be send somewhere afterwards. If a creation
+ * is successful, then a crash report is filled.
+ * @param pAnalyzer A name of an analyzer plugin.
+ * @param pDebugDumpPath A debugdump dir containing all necessary data.
+ * @param pCrashReport A filled crash report.
+ * @return It return results of operation. See mw_result_t.
+ */
+ mw_result_t CreateCrashReport(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_report_t& pCrashReport);
+ /**
+ * A method, which activate particular action plugin.
+ * @param pActionDir A directory, which is passed as working to a action plugin.
+ * @param pPluginName An action plugin name.
+ * @param pPluginArgs Action plugin's arguments.
+ */
+ void RunAction(const std::string& pActionDir,
+ const std::string& pPluginName,
+ const std::string& pPluginArgs);
+ /**
+ * A method, which activate all action and reporter plugins when any
+ * crash occurs.
+ * @param pDebugDumpDir A debugdump dir containing all necessary data.
+ */
+ 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,
+ * ...).
+ * @param pCrashReport A crash report.
+ * @param pSettingsPath A path to setting files.
+ */
+ void Report(const map_crash_report_t& pCrashReport,
+ const std::string& pSettingsPath);
+ /**
+ * A method, which deletes particular debugdump directory.
+ * @param pDebugDumpDir A debugdump directory.
+ */
+ void DeleteDebugDumpDir(const std::string& pDebugDumpDir);
+ /**
+ * A method, which delete a row from database. If a deleting is
+ * successfull, it returns a debugdump directort, which is not
+ * deleted. Otherwise, it returns empty string.
+ * @param pUUID A local UUID of a crash.
+ * @param pUID An UID of an user.
+ * @return A debugdump directory.
+ */
+ std::string DeleteCrashInfo(const std::string& pUUID,
+ const std::string& pUID);
+ /**
+ * A method, whis saves debugdump into database.
+ * @param pDebugDumpDir A debugdump directory.
+ * @return It return results of operation. See mw_result_t.
+ */
+ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir);
+ /**
+ * A method, whis saves debugdump into database. If saving is sucessful
+ * it fills crash info.
+ * @param pDebugDumpDir A debugdump directory.
+ * @param pCrashInfo A crash info.
+ * @return It return results of operation. See mw_result_t.
+ */
+ mw_result_t SaveDebugDump(const std::string& pDebugDumpDir,
+ map_crash_info_t& pCrashInfo);
+ /**
+ * A method, which gets one crash info. If a getting is successful,
+ * then a crash info is filled.
+ * @param pUUID A local UUID of a crash.
+ * @param pUID An UID of an user.
+ * @param pCrashInfo A crash info.
+ * @return It return results of operation. See mw_result_t.
+ */
+ mw_result_t GetCrashInfo(const std::string& pUUID,
+ const std::string& pUID,
+ map_crash_info_t& pCrashInfo);
+ /**
+ * A method, which gets all local UUIDs and UIDs of crashes. These crashes
+ * occurred when a particular user was logged in.
+ * @param pUID an UID of an user.
+ * @return A vector of pairs (local UUID, UID).
+ */
+ vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID);
+ /**
+ * A method, which set a GPG finger print check.
+ * @param pCheck Is it enabled?
+ */
+ void SetOpenGPGCheck(bool pCheck);
+ /**
+ * A method, which sets a name of database.
+ * @param pDatabase A database name.
+ */
+ void SetDatabase(const std::string& pDatabase);
+ /**
+ * A method, which adds one path to a GPG public key into MW's set.
+ * @param pKey A path to a GPG public key.
+ */
+ void AddOpenGPGPublicKey(const std::string& pKey);
+ /**
+ * A method, which adds one blacklisted package.
+ */
+ void AddBlackListedPackage(const std::string& pPackage);
+ /**
+ * A method, which adds one association among alanyzer plugin and its
+ * action and reporter plugins.
+ * @param pAnalyzer A name of an analyzer plugin.
+ * @param pActionOrReporter A name of an action or reporter plugin.
+ * @param pArgs An arguments for action or reporter plugin.
+ */
+ void AddAnalyzerActionOrReporter(const std::string& pAnalyzer,
+ const std::string& pActionOrReporter,
+ const std::string& pArgs);
+ /**
+ * A method, which adds action and reporter plugins, which are activated
+ * when any crash occurs.
+ * @param pActionOrReporter A name of an action or reporter plugin.
+ * @param pArgs An arguments for action or reporter plugin.
+ */
+ void AddActionOrReporter(const std::string& pActionOrReporter,
+ const std::string& pArgs);
+};
+
+#endif /*MIDDLEWARE_H_*/