From 764c3a1e4f21c635c565cf5c20c480dbf48d1599 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Jan 2010 16:48:54 +0100 Subject: unify "crash data, "crash info" and "crash report" data types. they are the same Signed-off-by: Denys Vlasenko --- doc/DESIGN | 6 +- doc/PLUGINS-HOWTO | 4 +- inc/CrashTypes.h | 52 +++++++------ inc/CrashTypesSocket.h | 12 +-- lib/Plugins/Bugzilla.cpp | 34 ++++----- lib/Plugins/Bugzilla.h | 2 +- lib/Plugins/Catcut.cpp | 30 ++++---- lib/Plugins/Catcut.h | 2 +- lib/Plugins/KerneloopsReporter.cpp | 6 +- lib/Plugins/KerneloopsReporter.h | 2 +- lib/Plugins/Logger.cpp | 4 +- lib/Plugins/Logger.h | 4 +- lib/Plugins/Mailx.cpp | 8 +- lib/Plugins/Mailx.h | 2 +- lib/Plugins/TicketUploader.cpp | 6 +- lib/Plugins/TicketUploader.h | 2 +- lib/Utils/CrashTypes.cpp | 61 ++++++++++++++++ lib/Utils/CrashTypesSocket.cpp | 12 +-- lib/Utils/Makefile.am | 1 + lib/Utils/Plugin.h | 6 +- lib/Utils/Reporter.h | 4 +- lib/Utils/make_descr.cpp | 30 ++++---- lib/Utils/test.cpp | 4 +- src/CLI/ABRTSocket.cpp | 6 +- src/CLI/ABRTSocket.h | 6 +- src/CLI/CLI.cpp | 6 +- src/CLI/dbus.cpp | 10 +-- src/CLI/dbus.h | 6 +- src/CLI/report.cpp | 14 ++-- src/Daemon/CommLayerServerDBus.cpp | 10 +-- src/Daemon/CommLayerServerSocket.cpp | 16 ++-- src/Daemon/CommLayerServerSocket.h | 4 +- src/Daemon/CrashWatcher.cpp | 12 +-- src/Daemon/CrashWatcher.h | 4 +- src/Daemon/Daemon.cpp | 12 +-- src/Daemon/MiddleWare.cpp | 138 ++++++++++++++++++----------------- src/Daemon/MiddleWare.h | 18 ++--- 37 files changed, 315 insertions(+), 241 deletions(-) create mode 100644 lib/Utils/CrashTypes.cpp diff --git a/doc/DESIGN b/doc/DESIGN index 8ef25ab6..ff950b51 100644 --- a/doc/DESIGN +++ b/doc/DESIGN @@ -84,7 +84,7 @@ if no new dbus calls are arriving to it. The key dbus calls served by abrt-process are: -- GetCrashInfos(): returns a vector_crash_infos_t (vector_map_vector_string_t) +- GetCrashInfos(): returns a vector_map_crash_data_t (vector_map_vector_string_t) of crashes for given uid v[N]["executable"/"uid"/"kernel"/"backtrace"][N] = "contents" [see above the problem with producing this list] @@ -97,8 +97,8 @@ The key dbus calls served by abrt-process are: abrt should be run by root anyway - debuginfo gets installed using pk-debuginfo-install, which cares about privileges itself, so no problem here -- GetJobResult(UUID): returns map_crash_report_t (map_vector_string_t) -- Report(map_crash_report_t (map_vector_string_t)): +- GetJobResult(UUID): returns map_crash_data_t (map_vector_string_t) +- Report(map_crash_data_t (map_vector_string_t)): "Please report this crash": calls Report() of all registered reporter plugins Returns report_status_t (map_vector_string_t) - the status of each call - DeleteDebugDump(UUID): delete corresponding /var/cache/abrt/DIR. Returns bool diff --git a/doc/PLUGINS-HOWTO b/doc/PLUGINS-HOWTO index d8467801..a7c08088 100644 --- a/doc/PLUGINS-HOWTO +++ b/doc/PLUGINS-HOWTO @@ -74,8 +74,8 @@ it on some web tool...) You have to override this method: -virtual void Report(const crash_report_t& pCrashReport, - const std::string& pArgs); +virtual void Report(const map_crash_data_t& pCrashData, + const char *pArgs); -It is self-explanatory, that this method takes the report and presents it somewhere to the world. The second argument is a string with arguments specified for the reporter. diff --git a/inc/CrashTypes.h b/inc/CrashTypes.h index ccbdd929..4778b707 100644 --- a/inc/CrashTypes.h +++ b/inc/CrashTypes.h @@ -1,3 +1,21 @@ +/* + Copyright (C) 2009 Abrt team. + 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 CRASHTYPES_H_ #define CRASHTYPES_H_ @@ -40,29 +58,19 @@ // typedef map_vector_string_t map_crash_data_t; -typedef map_crash_data_t map_crash_info_t; -typedef map_crash_data_t map_crash_report_t; -typedef std::vector vector_crash_infos_t; +typedef std::vector vector_map_crash_data_t; -inline void add_crash_data_to_crash_info(map_crash_info_t& pCrashInfo, - const std::string& pItem, - const std::string& pContent) -{ - pCrashInfo[pItem].push_back(CD_TXT); - pCrashInfo[pItem].push_back(CD_ISNOTEDITABLE); - pCrashInfo[pItem].push_back(pContent); -} +void add_to_crash_data(map_crash_data_t& pCrashData, + const char *pItem, + const char *pContent); -inline void add_crash_data_to_crash_report(map_crash_report_t& pCrashReport, - const std::string& pItem, - const std::string& pType, - const std::string& pEditable, - const std::string& pContent) -{ - pCrashReport[pItem].push_back(pType); - pCrashReport[pItem].push_back(pEditable); - pCrashReport[pItem].push_back(pContent); -} +void add_to_crash_data_ext(map_crash_data_t& pCrashData, + const char *pItem, + const char *pType, + const char *pEditable, + const char *pContent); +const std::string& get_crash_data_item_content(const map_crash_data_t& crash_data, + const char *key); -#endif /* CRASHTYPES_H_ */ +#endif diff --git a/inc/CrashTypesSocket.h b/inc/CrashTypesSocket.h index 166a8a81..db3ee44e 100644 --- a/inc/CrashTypesSocket.h +++ b/inc/CrashTypesSocket.h @@ -70,19 +70,19 @@ #define MESSAGE_CREATE_REPORT "(CREATE_REPORT)" #define MESSAGE_END_MARKER 23 -std::string crash_infos_to_string(const vector_crash_infos_t& pCrashInfos); +std::string crash_infos_to_string(const vector_map_crash_data_t& pCrashDatas); std::string crash_data_to_string(const map_crash_data_t& pCrashData); -inline std::string crash_report_to_string(const map_crash_report_t& pCrashReport) +inline std::string crash_report_to_string(const map_crash_data_t& pCrashData) { - return crash_data_to_string(pCrashReport); + return crash_data_to_string(pCrashData); } -vector_crash_infos_t string_to_crash_infos(const std::string& pMessage); +vector_map_crash_data_t string_to_crash_infos(const std::string& pMessage); map_crash_data_t string_to_crash_data(const std::string& pMessage, int& len); -inline map_crash_report_t string_to_crash_report(const std::string& pMessage) +inline map_crash_data_t string_to_crash_report(const std::string& pMessage) { int len; return string_to_crash_data(pMessage, len); } -#endif /* SOCKETCRASHTYPES_H_ */ +#endif diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index f963eb9c..5fdaa750 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -32,8 +32,8 @@ struct ctx: public abrt_xmlrpc_conn { int32_t check_uuid_in_bugzilla(const char* component, const char* UUID); bool check_cc_and_reporter(uint32_t bug_id, const char* login); void add_plus_one_cc(uint32_t bug_id, const char* login); - uint32_t new_bug(const map_crash_report_t& pCrashReport); - void add_attachments(const char* bug_id_str, const map_crash_report_t& pCrashReport); + uint32_t new_bug(const map_crash_data_t& pCrashData); + void add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashData); }; void ctx::login(const char* login, const char* passwd) @@ -278,22 +278,22 @@ int32_t ctx::check_uuid_in_bugzilla(const char* component, const char* UUID) return -1; } -uint32_t ctx::new_bug(const map_crash_report_t& pCrashReport) +uint32_t ctx::new_bug(const map_crash_data_t& pCrashData) { xmlrpc_env env; xmlrpc_env_init(&env); - std::string package = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; - std::string component = pCrashReport.find(FILENAME_COMPONENT)->second[CD_CONTENT]; - std::string release = pCrashReport.find(FILENAME_RELEASE)->second[CD_CONTENT]; - std::string arch = pCrashReport.find(FILENAME_ARCHITECTURE)->second[CD_CONTENT]; - std::string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; + std::string package = pCrashData.find(FILENAME_PACKAGE)->second[CD_CONTENT]; + std::string component = pCrashData.find(FILENAME_COMPONENT)->second[CD_CONTENT]; + std::string release = pCrashData.find(FILENAME_RELEASE)->second[CD_CONTENT]; + std::string arch = pCrashData.find(FILENAME_ARCHITECTURE)->second[CD_CONTENT]; + std::string uuid = pCrashData.find(CD_UUID)->second[CD_CONTENT]; std::string summary = "[abrt] crash in " + package; std::string status_whiteboard = "abrt_hash:" + uuid; std::string description = "abrt "VERSION" detected a crash.\n\n"; - description += make_description_bz(pCrashReport); + description += make_description_bz(pCrashData); std::string product; std::string version; @@ -346,15 +346,15 @@ uint32_t ctx::new_bug(const map_crash_report_t& pCrashReport) return bug_id; } -void ctx::add_attachments(const char* bug_id_str, const map_crash_report_t& pCrashReport) +void ctx::add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashData) { xmlrpc_env env; xmlrpc_env_init(&env); xmlrpc_value* result = NULL; - map_crash_report_t::const_iterator it = pCrashReport.begin(); - for (; it != pCrashReport.end(); it++) + map_crash_data_t::const_iterator it = pCrashData.begin(); + for (; it != pCrashData.end(); it++) { const std::string &filename = it->first; const std::string &type = it->second[CD_TYPE]; @@ -404,7 +404,7 @@ CReporterBugzilla::CReporterBugzilla() : CReporterBugzilla::~CReporterBugzilla() {} -std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, +std::string CReporterBugzilla::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { @@ -433,8 +433,8 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, NoSSLVerify = m_bNoSSLVerify; } - std::string component = pCrashReport.find(FILENAME_COMPONENT)->second[CD_CONTENT]; - std::string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; + std::string component = pCrashData.find(FILENAME_COMPONENT)->second[CD_CONTENT]; + std::string uuid = pCrashData.find(CD_UUID)->second[CD_CONTENT]; try { ctx bz_server(BugzillaXMLRPC.c_str(), NoSSLVerify); @@ -462,8 +462,8 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, } update_client(_("Creating new bug...")); - bug_id = bz_server.new_bug(pCrashReport); - bz_server.add_attachments(to_string(bug_id).c_str(), pCrashReport); + bug_id = bz_server.new_bug(pCrashData); + bz_server.add_attachments(to_string(bug_id).c_str(), pCrashData); update_client(_("Logging out...")); bz_server.logout(); diff --git a/lib/Plugins/Bugzilla.h b/lib/Plugins/Bugzilla.h index ee6bc6a5..571d0c60 100644 --- a/lib/Plugins/Bugzilla.h +++ b/lib/Plugins/Bugzilla.h @@ -20,7 +20,7 @@ class CReporterBugzilla : public CReporter CReporterBugzilla(); virtual ~CReporterBugzilla(); - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs); diff --git a/lib/Plugins/Catcut.cpp b/lib/Plugins/Catcut.cpp index b69038fb..73316e70 100644 --- a/lib/Plugins/Catcut.cpp +++ b/lib/Plugins/Catcut.cpp @@ -215,13 +215,13 @@ struct ctx: public abrt_xmlrpc_conn { ctx(const char* url, bool no_ssl_verify): abrt_xmlrpc_conn(url, no_ssl_verify) {} string login(const char* login, const char* passwd); - string new_bug(const char *auth_cookie, const map_crash_report_t& pCrashReport); + string new_bug(const char *auth_cookie, const map_crash_data_t& pCrashData); string request_upload(const char* auth_cookie, const char* pTicketName, const char* fileName, const char* description); void add_attachments(const char* xmlrpc_URL, const char* auth_cookie, const char* pTicketName, - const map_crash_report_t& pCrashReport, + const map_crash_data_t& pCrashData, int retryCount, int retryDelaySeconds); }; @@ -263,21 +263,21 @@ ctx::login(const char* login, const char* passwd) } string -ctx::new_bug(const char *auth_cookie, const map_crash_report_t& pCrashReport) +ctx::new_bug(const char *auth_cookie, const map_crash_data_t& pCrashData) { xmlrpc_env env; xmlrpc_env_init(&env); - string package = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; - string component = pCrashReport.find(FILENAME_COMPONENT)->second[CD_CONTENT]; - string release = pCrashReport.find(FILENAME_RELEASE)->second[CD_CONTENT]; - string arch = pCrashReport.find(FILENAME_ARCHITECTURE)->second[CD_CONTENT]; - string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; + string package = pCrashData.find(FILENAME_PACKAGE)->second[CD_CONTENT]; + string component = pCrashData.find(FILENAME_COMPONENT)->second[CD_CONTENT]; + string release = pCrashData.find(FILENAME_RELEASE)->second[CD_CONTENT]; + string arch = pCrashData.find(FILENAME_ARCHITECTURE)->second[CD_CONTENT]; + string uuid = pCrashData.find(CD_UUID)->second[CD_CONTENT]; string summary = "[abrt] crash in " + package; string status_whiteboard = "abrt_hash:" + uuid; - string description = make_description_catcut(pCrashReport); + string description = make_description_catcut(pCrashData); string product; string version; @@ -382,13 +382,13 @@ void ctx::add_attachments(const char* xmlrpc_URL, const char* auth_cookie, const char* pTicketName, - const map_crash_report_t& pCrashReport, + const map_crash_data_t& pCrashData, int retryCount, int retryDelaySeconds) { - map_crash_report_t::const_iterator it = pCrashReport.begin(); - for (; it != pCrashReport.end(); it++) + map_crash_data_t::const_iterator it = pCrashData.begin(); + for (; it != pCrashData.end(); it++) { if (it->second[CD_TYPE] == CD_TXT && it->second[CD_TYPE].size() > CD_TEXT_ATT_SIZE) { @@ -446,7 +446,7 @@ CReporterCatcut::CReporterCatcut() : CReporterCatcut::~CReporterCatcut() {} -string CReporterCatcut::Report(const map_crash_report_t& pCrashReport, +string CReporterCatcut::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { @@ -459,14 +459,14 @@ string CReporterCatcut::Report(const map_crash_report_t& pCrashReport, string message; if (auth_cookie != "") { - string ticket_name = catcut_server.new_bug(auth_cookie.c_str(), pCrashReport); + string ticket_name = catcut_server.new_bug(auth_cookie.c_str(), pCrashData); if (ticket_name != "") { catcut_server.add_attachments( m_sCatcutURL.c_str(), auth_cookie.c_str(), ticket_name.c_str(), - pCrashReport, + pCrashData, m_nRetryCount, m_nRetryDelay ); diff --git a/lib/Plugins/Catcut.h b/lib/Plugins/Catcut.h index 00f486c0..65c70444 100644 --- a/lib/Plugins/Catcut.h +++ b/lib/Plugins/Catcut.h @@ -20,7 +20,7 @@ class CReporterCatcut : public CReporter virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *Args); }; diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index 5cb525bc..7c488363 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -93,7 +93,7 @@ CKerneloopsReporter::CKerneloopsReporter() : m_sSubmitURL("http://submit.kerneloops.org/submitoops.php") {} -std::string CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, +std::string CKerneloopsReporter::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { @@ -101,8 +101,8 @@ std::string CKerneloopsReporter::Report(const map_crash_report_t& pCrashReport, update_client(_("Creating and submitting a report...")); - map_crash_report_t::const_iterator it = pCrashReport.find(FILENAME_KERNELOOPS); - if (it != pCrashReport.end()) { + map_crash_data_t::const_iterator it = pCrashData.find(FILENAME_KERNELOOPS); + if (it != pCrashData.end()) { ret = http_post_to_kerneloops_site( m_sSubmitURL.c_str(), it->second[CD_CONTENT].c_str() diff --git a/lib/Plugins/KerneloopsReporter.h b/lib/Plugins/KerneloopsReporter.h index 10e5e644..91326526 100644 --- a/lib/Plugins/KerneloopsReporter.h +++ b/lib/Plugins/KerneloopsReporter.h @@ -43,7 +43,7 @@ class CKerneloopsReporter : public CReporter virtual void SetSettings(const map_plugin_settings_t& pSettings); //ok to delete? // virtual const map_plugin_settings_t& GetSettings(); - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs); }; diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index d6cc124e..f428aec5 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -59,12 +59,12 @@ void CLogger::SetSettings(const map_plugin_settings_t& pSettings) // return m_pSettings; //} -std::string CLogger::Report(const map_crash_report_t& pCrashReport, +std::string CLogger::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { - std::string description = make_description_logger(pCrashReport); + std::string description = make_description_logger(pCrashData); description += "\n\n\n"; FILE *fOut; diff --git a/lib/Plugins/Logger.h b/lib/Plugins/Logger.h index c7d76798..02429b2c 100644 --- a/lib/Plugins/Logger.h +++ b/lib/Plugins/Logger.h @@ -1,6 +1,6 @@ /* Logger.h - header file for Logger reporter plugin - - it simple writes report to specific file + - it simply writes report to specific file Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com) Copyright (C) 2009 RedHat inc. @@ -37,7 +37,7 @@ class CLogger : public CReporter virtual void SetSettings(const map_plugin_settings_t& pSettings); //ok to delete? // virtual const map_plugin_settings_t& GetSettings(); - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs); }; diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp index 2f8448f5..ae8c2dc9 100644 --- a/lib/Plugins/Mailx.cpp +++ b/lib/Plugins/Mailx.cpp @@ -65,7 +65,7 @@ static char** append_str_to_vector(char **vec, unsigned &size, const char *str) return vec; } -std::string CMailx::Report(const map_crash_report_t& pCrashReport, +std::string CMailx::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { @@ -75,8 +75,8 @@ std::string CMailx::Report(const map_crash_report_t& pCrashReport, //TODO: move email body generation to make_descr.cpp std::string binaryFiles, commonFiles, additionalFiles, UUIDFile; - map_crash_report_t::const_iterator it; - for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) + map_crash_data_t::const_iterator it; + for (it = pCrashData.begin(); it != pCrashData.end(); it++) { if (it->second[CD_TYPE] == CD_TXT) { @@ -135,7 +135,7 @@ std::string CMailx::Report(const map_crash_report_t& pCrashReport, args = append_str_to_vector(args, arg_size, m_sEmailTo.c_str()); update_client(_("Sending an email...")); - const char *uid_str = pCrashReport.find(CD_MWUID)->second[CD_CONTENT].c_str(); + const char *uid_str = get_crash_data_item_content(pCrashData, CD_MWUID).c_str(); exec_and_feed_input(xatoi_u(uid_str), emailBody.c_str(), args); while (*args) diff --git a/lib/Plugins/Mailx.h b/lib/Plugins/Mailx.h index 1ddb5ff0..619e349c 100644 --- a/lib/Plugins/Mailx.h +++ b/lib/Plugins/Mailx.h @@ -41,7 +41,7 @@ class CMailx : public CReporter virtual void SetSettings(const map_plugin_settings_t& pSettings); //ok to delete? // virtual const map_plugin_settings_t& GetSettings(); - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs); }; diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp index 7483768d..b273ae8b 100644 --- a/lib/Plugins/TicketUploader.cpp +++ b/lib/Plugins/TicketUploader.cpp @@ -150,7 +150,7 @@ void CTicketUploader::SendFile(const char *pURL, const char *pFilename) } -string CTicketUploader::Report(const map_crash_report_t& pCrashReport, +string CTicketUploader::Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) { @@ -200,8 +200,8 @@ string CTicketUploader::Report(const map_crash_report_t& pCrashReport, // Copy each entry into the tarball root, // files are simply copied, strings are written to a file - map_crash_report_t::const_iterator it; - for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) + map_crash_data_t::const_iterator it; + for (it = pCrashData.begin(); it != pCrashData.end(); it++) { if (it->second[CD_TYPE] == CD_TXT) { diff --git a/lib/Plugins/TicketUploader.h b/lib/Plugins/TicketUploader.h index 1bc8f6ba..fcc59f06 100644 --- a/lib/Plugins/TicketUploader.h +++ b/lib/Plugins/TicketUploader.h @@ -48,7 +48,7 @@ class CTicketUploader : public CReporter virtual const map_plugin_settings_t& GetSettings(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs); }; diff --git a/lib/Utils/CrashTypes.cpp b/lib/Utils/CrashTypes.cpp new file mode 100644 index 00000000..4824e507 --- /dev/null +++ b/lib/Utils/CrashTypes.cpp @@ -0,0 +1,61 @@ +/* + Copyright (C) 2010 Denys Vlasenko (dvlasenk@redhat.com) + Copyright (C) 2010 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 "abrt_types.h" +#include "abrtlib.h" +#include "CrashTypes.h" + +void add_to_crash_data_ext(map_crash_data_t& pCrashData, + const char *pItem, + const char *pType, + const char *pEditable, + const char *pContent) +{ + map_crash_data_t::iterator it = pCrashData.find(pItem); + if (it == pCrashData.end()) { + pCrashData[pItem].push_back(pType); + pCrashData[pItem].push_back(pEditable); + pCrashData[pItem].push_back(pContent); + return; + } + vector_string_t& v = it->second; + while (v.size() < 3) + v.push_back(""); + v[CD_TYPE] = pType; + v[CD_EDITABLE] = pEditable; + v[CD_CONTENT] = pContent; +} + +void add_to_crash_data(map_crash_data_t& pCrashData, + const char *pItem, + const char *pContent) +{ + add_to_crash_data_ext(pCrashData, pItem, CD_TXT, CD_ISNOTEDITABLE, pContent); +} + +const std::string& get_crash_data_item_content(const map_crash_data_t& crash_data, const char *key) +{ + map_crash_data_t::const_iterator it = crash_data.find(key); + if (it == crash_data.end()) { + error_msg_and_die("Error accessing crash data: no ['%s']", key); + } + if (it->second.size() <= CD_CONTENT) { + error_msg_and_die("Error accessing crash data: no ['%s'][%d]", key, CD_CONTENT); + } + return it->second[CD_CONTENT]; +} diff --git a/lib/Utils/CrashTypesSocket.cpp b/lib/Utils/CrashTypesSocket.cpp index 3525c6a5..d555571b 100644 --- a/lib/Utils/CrashTypesSocket.cpp +++ b/lib/Utils/CrashTypesSocket.cpp @@ -87,13 +87,13 @@ std::string crash_data_to_string(const map_crash_data_t& pCrashData) return sCD.str(); } -std::string crash_infos_to_string(const vector_crash_infos_t& pCrashInfos) +std::string crash_infos_to_string(const vector_map_crash_data_t& pCrashDatas) { std::stringstream sCI; unsigned int ii; - for (ii = 0; ii < pCrashInfos.size(); ii++) + for (ii = 0; ii < pCrashDatas.size(); ii++) { - sCI << crash_data_to_string(pCrashInfos[ii]); + sCI << crash_data_to_string(pCrashDatas[ii]); } return sCI.str(); } @@ -164,15 +164,15 @@ map_crash_data_t string_to_crash_data(const std::string& pMessage, int& len) return ci; } -vector_crash_infos_t string_to_crash_infos(const std::string& pMessage) +vector_map_crash_data_t string_to_crash_infos(const std::string& pMessage) { - vector_crash_infos_t vci; + vector_map_crash_data_t vci; std::string message = pMessage; int len; while (message != "") { - map_crash_info_t crash_info = string_to_crash_data(message, len); + map_crash_data_t crash_info = string_to_crash_data(message, len); if (crash_info.size() == 0) { return vci; diff --git a/lib/Utils/Makefile.am b/lib/Utils/Makefile.am index a944d977..59607104 100644 --- a/lib/Utils/Makefile.am +++ b/lib/Utils/Makefile.am @@ -20,6 +20,7 @@ libABRTUtils_la_SOURCES = \ stringops.cpp \ dirsize.cpp \ DebugDump.h DebugDump.cpp \ + CrashTypes.cpp \ ABRTException.cpp libABRTUtils_la_CPPFLAGS = \ -Wall -Werror \ diff --git a/lib/Utils/Plugin.h b/lib/Utils/Plugin.h index d7108ce9..e8464032 100644 --- a/lib/Utils/Plugin.h +++ b/lib/Utils/Plugin.h @@ -120,8 +120,8 @@ typedef struct SPluginInfo }; /* helper finctions */ -std::string make_description_bz(const map_crash_report_t& pCrashReport); -std::string make_description_logger(const map_crash_report_t& pCrashReport); -std::string make_description_catcut(const map_crash_report_t& pCrashReport); +std::string make_description_bz(const map_crash_data_t& pCrashData); +std::string make_description_logger(const map_crash_data_t& pCrashData); +std::string make_description_catcut(const map_crash_data_t& pCrashData); #endif diff --git a/lib/Utils/Reporter.h b/lib/Utils/Reporter.h index 0a06a7c9..e9445f93 100644 --- a/lib/Utils/Reporter.h +++ b/lib/Utils/Reporter.h @@ -36,11 +36,11 @@ class CReporter : public CPlugin * A method, which reports a crash report to particular receiver. * The plugin can takes arguments, but the plugin has to parse them * by itself. - * @param pCrashReport A crash report. + * @param pCrashData A crash report. * @param pArgs Plugin's arguments. * @retun A message which can be displayed after a report is created. */ - virtual std::string Report(const map_crash_report_t& pCrashReport, + virtual std::string Report(const map_crash_data_t& pCrashData, const map_plugin_settings_t& pSettings, const char *pArgs) = 0; }; diff --git a/lib/Utils/make_descr.cpp b/lib/Utils/make_descr.cpp index 2a0d4a99..e74e9b1d 100644 --- a/lib/Utils/make_descr.cpp +++ b/lib/Utils/make_descr.cpp @@ -50,27 +50,27 @@ static void add_content(bool &was_multiline, string& description, const char *he } } -string make_description_bz(const map_crash_report_t& pCrashReport) +string make_description_bz(const map_crash_data_t& pCrashData) { string description; - map_crash_report_t::const_iterator it; - map_crash_report_t::const_iterator end = pCrashReport.end(); + map_crash_data_t::const_iterator it; + map_crash_data_t::const_iterator end = pCrashData.end(); bool was_multiline = 0; - it = pCrashReport.find(CD_REPRODUCE); + it = pCrashData.find(CD_REPRODUCE); if (it != end && it->second[CD_CONTENT] != "1.\n2.\n3.\n") { add_content(was_multiline, description, "How to reproduce", it->second[CD_CONTENT].c_str()); } - it = pCrashReport.find(CD_COMMENT); + it = pCrashData.find(CD_COMMENT); if (it != end) { add_content(was_multiline, description, "Comment", it->second[CD_CONTENT].c_str()); } - it = pCrashReport.begin(); + it = pCrashData.begin(); for (; it != end; it++) { const string &filename = it->first; @@ -97,13 +97,13 @@ string make_description_bz(const map_crash_report_t& pCrashReport) return description; } -string make_description_logger(const map_crash_report_t& pCrashReport) +string make_description_logger(const map_crash_data_t& pCrashData) { string description; string long_description; - map_crash_report_t::const_iterator it = pCrashReport.begin(); - for (; it != pCrashReport.end(); it++) + map_crash_data_t::const_iterator it = pCrashData.begin(); + for (; it != pCrashData.end(); it++) { const string &filename = it->first; const string &type = it->second[CD_TYPE]; @@ -141,13 +141,13 @@ string make_description_logger(const map_crash_report_t& pCrashReport) } /* This needs more work to make the result less ugly */ -string make_description_catcut(const map_crash_report_t& pCrashReport) +string make_description_catcut(const map_crash_data_t& pCrashData) { - map_crash_report_t::const_iterator end = pCrashReport.end(); - map_crash_report_t::const_iterator it; + map_crash_data_t::const_iterator end = pCrashData.end(); + map_crash_data_t::const_iterator it; string howToReproduce; - it = pCrashReport.find(CD_REPRODUCE); + it = pCrashData.find(CD_REPRODUCE); if (it != end) { howToReproduce = "\n\nHow to reproduce\n" @@ -155,7 +155,7 @@ string make_description_catcut(const map_crash_report_t& pCrashReport) howToReproduce += it->second[CD_CONTENT]; } string comment; - it = pCrashReport.find(CD_COMMENT); + it = pCrashData.find(CD_COMMENT); if (it != end) { comment = "\n\nComment\n" @@ -169,7 +169,7 @@ string make_description_catcut(const map_crash_report_t& pCrashReport) pDescription += "\n\nAdditional information\n" "======\n"; - for (it = pCrashReport.begin(); it != end; it++) + for (it = pCrashData.begin(); it != end; it++) { const string &filename = it->first; const string &type = it->second[CD_TYPE]; diff --git a/lib/Utils/test.cpp b/lib/Utils/test.cpp index fbad1db9..160c107b 100644 --- a/lib/Utils/test.cpp +++ b/lib/Utils/test.cpp @@ -80,7 +80,7 @@ int main(int argc, char** argv) std::cout << "-------------------------------------------" << std::endl; } /* Try to save it into DB */ - map_crash_info_t crashInfo; + map_crash_data_t crashInfo; if (middleWare.SaveDebugDump(argv[1], crashInfo)) { std::cout << "Application Crashed! " << @@ -91,7 +91,7 @@ int main(int argc, char** argv) /* Get Report, so user can change data (remove private stuff) * If we do not want user interaction, just send data immediately */ - map_crash_report_t crashReport; + map_crash_data_t crashReport; middleWare.CreateCrashReport(crashInfo[CD_UUID][CD_CONTENT], crashInfo[CD_UID][CD_CONTENT], crashReport); diff --git a/src/CLI/ABRTSocket.cpp b/src/CLI/ABRTSocket.cpp index 13531342..82c304ee 100644 --- a/src/CLI/ABRTSocket.cpp +++ b/src/CLI/ABRTSocket.cpp @@ -106,7 +106,7 @@ void CABRTSocket::Disconnect() close(m_nSocket); } -vector_crash_infos_t CABRTSocket::GetCrashInfos() +vector_map_crash_data_t CABRTSocket::GetCrashInfos() { std::string message = MESSAGE_GET_CRASH_INFOS; Send(message); @@ -115,7 +115,7 @@ vector_crash_infos_t CABRTSocket::GetCrashInfos() return string_to_crash_infos(message); } -map_crash_report_t CABRTSocket::CreateReport(const std::string &pUUID) +map_crash_data_t CABRTSocket::CreateReport(const std::string &pUUID) { std::string message = MESSAGE_CREATE_REPORT + pUUID; Send(message); @@ -124,7 +124,7 @@ map_crash_report_t CABRTSocket::CreateReport(const std::string &pUUID) return string_to_crash_report(message); } -void CABRTSocket::Report(const map_crash_report_t& pReport) +void CABRTSocket::Report(const map_crash_data_t& pReport) { std::string message = MESSAGE_REPORT + crash_report_to_string(pReport); Send(message); diff --git a/src/CLI/ABRTSocket.h b/src/CLI/ABRTSocket.h index c3a63e51..d4905be1 100644 --- a/src/CLI/ABRTSocket.h +++ b/src/CLI/ABRTSocket.h @@ -20,9 +20,9 @@ class CABRTSocket void Connect(const char *pPath); void Disconnect(); - vector_crash_infos_t GetCrashInfos(); - map_crash_report_t CreateReport(const char *pUUID); - void Report(const map_crash_report_t& pReport); + vector_map_crash_data_t GetCrashInfos(); + map_crash_data_t CreateReport(const char *pUUID); + void Report(const map_crash_data_t& pReport); int32_t DeleteDebugDump(const char *pUUID); }; diff --git a/src/CLI/CLI.cpp b/src/CLI/CLI.cpp index bc8ddf60..2f3b4048 100644 --- a/src/CLI/CLI.cpp +++ b/src/CLI/CLI.cpp @@ -47,12 +47,12 @@ enum OPT_DELETE }; -static void print_crash_infos(vector_crash_infos_t& pCrashInfos, int pMode) +static void print_crash_infos(vector_map_crash_data_t& pCrashInfos, int pMode) { unsigned int ii; for (ii = 0; ii < pCrashInfos.size(); ii++) { - map_crash_info_t& info = pCrashInfos[ii]; + map_crash_data_t& info = pCrashInfos[ii]; if (pMode == OPT_GET_LIST_FULL || info[CD_REPORTED][CD_CONTENT] != "1") { const char *timestr = info[CD_TIME][CD_CONTENT].c_str(); @@ -189,7 +189,7 @@ int main(int argc, char** argv) case OPT_GET_LIST: case OPT_GET_LIST_FULL: { - vector_crash_infos_t ci = call_GetCrashInfos(); + vector_map_crash_data_t ci = call_GetCrashInfos(); print_crash_infos(ci, op); break; } diff --git a/src/CLI/dbus.cpp b/src/CLI/dbus.cpp index 0d03c4d7..ffd1157e 100644 --- a/src/CLI/dbus.cpp +++ b/src/CLI/dbus.cpp @@ -104,7 +104,7 @@ static DBusMessage* send_get_reply_and_unref(DBusMessage* msg) } } -vector_crash_infos_t call_GetCrashInfos() +vector_map_crash_data_t call_GetCrashInfos() { DBusMessage* msg = new_call_msg(__func__ + 5); DBusMessage *reply = send_get_reply_and_unref(msg); @@ -112,7 +112,7 @@ vector_crash_infos_t call_GetCrashInfos() DBusMessageIter in_iter; dbus_message_iter_init(reply, &in_iter); - vector_crash_infos_t argout; + vector_map_crash_data_t argout; int r = load_val(&in_iter, argout); if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); @@ -121,7 +121,7 @@ vector_crash_infos_t call_GetCrashInfos() return argout; } -map_crash_report_t call_CreateReport(const char* uuid) +map_crash_data_t call_CreateReport(const char* uuid) { DBusMessage* msg = new_call_msg(__func__ + 5); dbus_message_append_args(msg, @@ -133,7 +133,7 @@ map_crash_report_t call_CreateReport(const char* uuid) DBusMessageIter in_iter; dbus_message_iter_init(reply, &in_iter); - map_crash_report_t argout; + map_crash_data_t argout; int r = load_val(&in_iter, argout); if (r != ABRT_DBUS_LAST_FIELD) /* more values present, or bad type */ error_msg_and_die("dbus call %s: return type mismatch", __func__ + 5); @@ -142,7 +142,7 @@ map_crash_report_t call_CreateReport(const char* uuid) return argout; } -report_status_t call_Report(const map_crash_report_t& report) +report_status_t call_Report(const map_crash_data_t& report) { DBusMessage* msg = new_call_msg(__func__ + 5); DBusMessageIter out_iter; diff --git a/src/CLI/dbus.h b/src/CLI/dbus.h index c692e198..c6fd7a4d 100644 --- a/src/CLI/dbus.h +++ b/src/CLI/dbus.h @@ -23,9 +23,9 @@ extern DBusConnection* s_dbus_conn; -vector_crash_infos_t call_GetCrashInfos(); -map_crash_report_t call_CreateReport(const char *uuid); -report_status_t call_Report(const map_crash_report_t& report); +vector_map_crash_data_t call_GetCrashInfos(); +map_crash_data_t call_CreateReport(const char *uuid); +report_status_t call_Report(const map_crash_data_t& report); int32_t call_DeleteDebugDump(const char* uuid); #ifdef UNUSED diff --git a/src/CLI/report.cpp b/src/CLI/report.cpp index bc8f9008..eca2d419 100644 --- a/src/CLI/report.cpp +++ b/src/CLI/report.cpp @@ -151,10 +151,10 @@ static void remove_comments_and_unescape(char *str) * Writes a field of crash report to a file. * Field must be writable. */ -static void write_crash_report_field(FILE *fp, const map_crash_report_t &report, +static void write_crash_report_field(FILE *fp, const map_crash_data_t &report, const char *field, const char *description) { - const map_crash_report_t::const_iterator it = report.find(field); + const map_crash_data_t::const_iterator it = report.find(field); if (it == report.end()) { // exit silently, all fields are optional for now @@ -186,7 +186,7 @@ static void write_crash_report_field(FILE *fp, const map_crash_report_t &report, * If the report is successfully stored to the file, a zero value is returned. * On failure, nonzero value is returned. */ -static void write_crash_report(const map_crash_report_t &report, FILE *fp) +static void write_crash_report(const map_crash_data_t &report, FILE *fp) { fprintf(fp, "# Please check this report. Lines starting with '#' will be ignored.\n" "# Lines starting with '%%----' separate fields, please do not delete them.\n\n"); @@ -217,7 +217,7 @@ static void write_crash_report(const map_crash_report_t &report, FILE *fp) * 1 if the field was changed. * Changes to read-only fields are ignored. */ -static int read_crash_report_field(const char *text, map_crash_report_t &report, +static int read_crash_report_field(const char *text, map_crash_data_t &report, const char *field) { char separator[strlen("\n" FIELD_SEP) + strlen(field) + 2]; // 2 = '\n\0' @@ -234,7 +234,7 @@ static int read_crash_report_field(const char *text, map_crash_report_t &report, else length = end - textfield; - const map_crash_report_t::iterator it = report.find(field); + const map_crash_data_t::iterator it = report.find(field); if (it == report.end()) { error_msg("Field %s not found.\n", field); @@ -278,7 +278,7 @@ static int read_crash_report_field(const char *text, map_crash_report_t &report, * 1 if any field was changed. * Changes to read-only fields are ignored. */ -static int read_crash_report(map_crash_report_t &report, const char *text) +static int read_crash_report(map_crash_data_t &report, const char *text) { int result = 0; result |= read_crash_report_field(text, report, CD_COMMENT); @@ -331,7 +331,7 @@ static int launch_editor(const char *path) int report(const char *uuid, bool always) { // Ask for an initial report. - map_crash_report_t cr = call_CreateReport(uuid); + map_crash_data_t cr = call_CreateReport(uuid); //TODO: error check? if (!always) diff --git a/src/Daemon/CommLayerServerDBus.cpp b/src/Daemon/CommLayerServerDBus.cpp index 182aa6c2..22d1bd0f 100644 --- a/src/Daemon/CommLayerServerDBus.cpp +++ b/src/Daemon/CommLayerServerDBus.cpp @@ -133,7 +133,7 @@ static long get_remote_uid(DBusMessage* call, const char** ppSender = NULL) static int handle_GetCrashInfos(DBusMessage* call, DBusMessage* reply) { long unix_uid = get_remote_uid(call); - vector_crash_infos_t argout1 = GetCrashInfos(to_string(unix_uid).c_str()); + vector_map_crash_data_t argout1 = GetCrashInfos(to_string(unix_uid).c_str()); DBusMessageIter out_iter; dbus_message_iter_init_append(reply, &out_iter); @@ -190,7 +190,7 @@ static int handle_CreateReport(DBusMessage* call, DBusMessage* reply) } long unix_uid = get_remote_uid(call); - map_crash_report_t report = CreateReport(pUUID, to_string(unix_uid).c_str(), /*force:*/ 0); + map_crash_data_t report = CreateReport(pUUID, to_string(unix_uid).c_str(), /*force:*/ 0); DBusMessageIter out_iter; dbus_message_iter_init_append(reply, &out_iter); @@ -206,7 +206,7 @@ static int handle_Report(DBusMessage* call, DBusMessage* reply) DBusMessageIter in_iter; dbus_message_iter_init(call, &in_iter); - map_crash_report_t argin1; + map_crash_data_t argin1; r = load_val(&in_iter, argin1); if (r == ABRT_DBUS_ERROR) { @@ -214,8 +214,8 @@ static int handle_Report(DBusMessage* call, DBusMessage* reply) return -1; } - map_crash_report_t::const_iterator it_comment = argin1.find(CD_COMMENT); - map_crash_report_t::const_iterator it_reproduce = argin1.find(CD_REPRODUCE); + map_crash_data_t::const_iterator it_comment = argin1.find(CD_COMMENT); + map_crash_data_t::const_iterator it_reproduce = argin1.find(CD_REPRODUCE); const char* comment = (it_comment != argin1.end()) ? it_comment->second[CD_CONTENT].c_str() : ""; const char* reproduce = (it_reproduce != argin1.end()) ? it_reproduce->second[CD_CONTENT].c_str() : ""; const char* errmsg = NULL; diff --git a/src/Daemon/CommLayerServerSocket.cpp b/src/Daemon/CommLayerServerSocket.cpp index 0c5f2e31..b54f9a6e 100644 --- a/src/Daemon/CommLayerServerSocket.cpp +++ b/src/Daemon/CommLayerServerSocket.cpp @@ -130,14 +130,14 @@ void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChan if (!strncmp(pMessage.c_str(), MESSAGE_GET_CRASH_INFOS, sizeof(MESSAGE_GET_CRASH_INFOS) - 1)) { - vector_crash_infos_t crashInfos = GetCrashInfos(UID); + vector_map_crash_data_t crashInfos = GetCrashInfos(UID); std::string message = MESSAGE_GET_CRASH_INFOS + crash_infos_to_string(crashInfos); Send(message, pSource); } else if (!strncmp(pMessage.c_str(), MESSAGE_REPORT, sizeof(MESSAGE_REPORT) - 1)) { std::string message = pMessage.substr(sizeof(MESSAGE_REPORT) - 1); - map_crash_report_t report = string_to_crash_report(message); + map_crash_data_t report = string_to_crash_report(message); map_plugin_settings_t plugin_settings; //FIXME: another hack to make this compile // Report(report, plugin_settings, UID); @@ -145,7 +145,7 @@ void CCommLayerServerSocket::ProcessMessage(const std::string& pMessage, GIOChan else if (!strncmp(pMessage.c_str(), MESSAGE_CREATE_REPORT, sizeof(MESSAGE_CREATE_REPORT) - 1)) { // std::string UUID = pMessage.substr(sizeof(MESSAGE_CREATE_REPORT) - 1); -// map_crash_report_t crashReport = CreateReport(UUID, UID); +// map_crash_data_t crashReport = CreateReport(UUID, UID); //use CreateReportThread instead of CreateReport? // std::string message = MESSAGE_CREATE_REPORT + crash_report_to_string(crashReport); // Send(message, pSource); @@ -211,22 +211,22 @@ CCommLayerServerSocket::~CCommLayerServerSocket() close(m_nSocket); } -vector_crash_infos_t CCommLayerServerSocket::GetCrashInfos(const std::string &pSender) +vector_map_crash_data_t CCommLayerServerSocket::GetCrashInfos(const std::string &pSender) { - vector_crash_infos_t crashInfos; + vector_map_crash_data_t crashInfos; crashInfos = ::GetCrashInfos(pSender); return crashInfos; } //reimplement as CreateReportThread(...)? -//map_crash_report_t CCommLayerServerSocket::CreateReport(const std::string &pUUID, const std::string &pSender) +//map_crash_data_t CCommLayerServerSocket::CreateReport(const std::string &pUUID, const std::string &pSender) //{ -// map_crash_report_t crashReport; +// map_crash_data_t crashReport; // crashReport = ::CreateReport(pUUID, pSender); // return crashReport; //} -report_status_t CCommLayerServerSocket::Report(const map_crash_report_t& pReport, const std::string& pSender) +report_status_t CCommLayerServerSocket::Report(const map_crash_data_t& pReport, const std::string& pSender) { report_status_t rs; //FIXME: a hack to make this compile, but we don't use sockets anyway diff --git a/src/Daemon/CommLayerServerSocket.h b/src/Daemon/CommLayerServerSocket.h index 753b67af..c511954c 100644 --- a/src/Daemon/CommLayerServerSocket.h +++ b/src/Daemon/CommLayerServerSocket.h @@ -26,8 +26,8 @@ class CCommLayerServerSocket : public CCommLayerServer CCommLayerServerSocket(); virtual ~CCommLayerServerSocket(); - virtual vector_crash_infos_t GetCrashInfos(const char *pSender); - virtual report_status_t Report(const map_crash_report_t& pReport, const char *pSender); + virtual vector_map_crash_data_t GetCrashInfos(const char *pSender); + virtual report_status_t Report(const map_crash_data_t& pReport, const char *pSender); virtual void DeleteDebugDump(const char *pUUID, const char *pSender); virtual void Crash(const char *arg1); diff --git a/src/Daemon/CrashWatcher.cpp b/src/Daemon/CrashWatcher.cpp index 59f9e65b..8a1aacdd 100644 --- a/src/Daemon/CrashWatcher.cpp +++ b/src/Daemon/CrashWatcher.cpp @@ -45,9 +45,9 @@ CCrashWatcher::~CCrashWatcher() { } -vector_crash_infos_t GetCrashInfos(const char *pUID) +vector_map_crash_data_t GetCrashInfos(const char *pUID) { - vector_crash_infos_t retval; + vector_map_crash_data_t retval; log("Getting crash infos..."); try { @@ -58,7 +58,7 @@ vector_crash_infos_t GetCrashInfos(const char *pUID) for (ii = 0; ii < UUIDsUIDs.size(); ii++) { mw_result_t res; - map_crash_info_t info; + map_crash_data_t info; const char *uuid = UUIDsUIDs[ii].first.c_str(); const char *uid = UUIDsUIDs[ii].second.c_str(); @@ -96,9 +96,9 @@ vector_crash_infos_t GetCrashInfos(const char *pUID) * StartJob dbus call already did all the processing, and we just retrieve * the result from dump directory, which is fast. */ -map_crash_report_t CreateReport(const char* pUUID, const char* pUID, int force) +map_crash_data_t CreateReport(const char* pUUID, const char* pUID, int force) { - map_crash_info_t crashReport; + map_crash_data_t crashReport; /* FIXME: starting from here, any shared data must be protected with a mutex. * For example, CreateCrashReport does: @@ -141,7 +141,7 @@ static void* create_report(void* arg) try { log("Creating report..."); - map_crash_info_t crashReport = CreateReport(thread_data->UUID, thread_data->UID, thread_data->force); + map_crash_data_t crashReport = CreateReport(thread_data->UUID, thread_data->UID, thread_data->force); g_pCommLayer->JobDone(thread_data->peer, thread_data->UUID); } catch (CABRTException& e) diff --git a/src/Daemon/CrashWatcher.h b/src/Daemon/CrashWatcher.h index 8d56c4ec..1e672b96 100644 --- a/src/Daemon/CrashWatcher.h +++ b/src/Daemon/CrashWatcher.h @@ -48,9 +48,9 @@ class CCrashWatcher virtual void Warning(const char *pMessage, const char* peer, uint64_t pJobID); }; -vector_crash_infos_t GetCrashInfos(const char *pUID); +vector_map_crash_data_t GetCrashInfos(const char *pUID); int CreateReportThread(const char* pUUID, const char* pUID, int force, const char* pSender); -map_crash_report_t CreateReport(const char* pUUID, const char* pUID, int force); +map_crash_data_t CreateReport(const char* pUUID, const char* pUID, int force); int DeleteDebugDump(const char *pUUID, const char *pUID); void DeleteDebugDump_by_dir(const char *dump_dir); diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index dc547af3..2964d582 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -51,15 +51,15 @@ * - signal: we got SIGTERM or SIGINT * * DBus methods we have: - * - GetCrashInfos(): returns a vector_crash_infos_t (vector_map_vector_string_t) + * - GetCrashInfos(): returns a vector_map_crash_data_t (vector_map_vector_string_t) * of crashes for given uid * v[N]["executable"/"uid"/"kernel"/"backtrace"][N] = "contents" * - StartJob(UUID,force): starts creating a report for /var/cache/abrt/DIR with this UUID. * Returns job id (uint64). * After thread returns, when report creation thread has finished, * JobDone(client_dbus_ID,UUID) dbus signal is emitted. - * - CreateReport(UUID): returns map_crash_report_t (map_vector_string_t) - * - Report(map_crash_report_t (map_vector_string_t[, map_map_string_t])): + * - CreateReport(UUID): returns map_crash_data_t (map_vector_string_t) + * - Report(map_crash_data_t (map_vector_string_t[, map_map_string_t])): * "Please report this crash": calls Report() of all registered reporter plugins. * Returns report_status_t (map_vector_string_t) - the status of each call. * 2nd parameter is the contents of user's abrt.conf. @@ -320,7 +320,7 @@ static void FindNewDumps(const char* pPath) vector_string_t::iterator itt = dirs.begin(); for (; itt != dirs.end(); ++itt) { - map_crash_info_t crashinfo; + map_crash_data_t crashinfo; try { mw_result_t res = SaveDebugDump(itt->c_str(), crashinfo); @@ -476,7 +476,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin worst_dir = ""; } - map_crash_info_t crashinfo; + map_crash_data_t crashinfo; try { std::string fullname = concat_path_file(DEBUG_DUMPS_DIR, name); @@ -501,7 +501,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin if (analyzer_has_AutoReportUIDs(analyzer, uid_str)) { VERB1 log("Reporting the crash automatically"); - map_crash_report_t crash_report; + map_crash_data_t crash_report; mw_result_t crash_result = CreateCrashReport( crashinfo[CD_UUID][CD_CONTENT].c_str(), uid_str, /*force:*/ 0, crash_report diff --git a/src/Daemon/MiddleWare.cpp b/src/Daemon/MiddleWare.cpp index c2a122a7..af52b85e 100644 --- a/src/Daemon/MiddleWare.cpp +++ b/src/Daemon/MiddleWare.cpp @@ -124,9 +124,9 @@ static char* is_text_file(const char *name, ssize_t *sz) * 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. + * @param pCrashData A created crash report. */ -static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t& pCrashReport) +static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_data_t& pCrashData) { CDebugDump dd; dd.Open(pDebugDumpDir); @@ -142,7 +142,7 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t std::string short_name; std::string full_name; - pCrashReport.clear(); + pCrashData.clear(); dd.InitGetNextFile(); while (dd.GetNextFile(&short_name, &full_name)) { @@ -150,11 +150,11 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t char *text = is_text_file(full_name.c_str(), &sz); if (!text) { - add_crash_data_to_crash_report(pCrashReport, - short_name, - CD_BIN, - CD_ISNOTEDITABLE, - full_name + add_to_crash_data_ext(pCrashData, + short_name.c_str(), + CD_BIN, + CD_ISNOTEDITABLE, + full_name.c_str() ); continue; } @@ -173,7 +173,12 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t || short_name == FILENAME_RELEASE || short_name == FILENAME_EXECUTABLE ) { - add_crash_data_to_crash_report(pCrashReport, short_name, CD_TXT, CD_ISNOTEDITABLE, content); + add_to_crash_data_ext(pCrashData, + short_name.c_str(), + CD_TXT, + CD_ISNOTEDITABLE, + content.c_str() + ); continue; } @@ -184,12 +189,12 @@ static void DebugDumpToCrashReport(const char *pDebugDumpDir, map_crash_report_t && short_name != FILENAME_REPRODUCE && short_name != FILENAME_COMMENT ) { - add_crash_data_to_crash_report( - pCrashReport, - short_name, + add_to_crash_data_ext( + pCrashData, + short_name.c_str(), CD_TXT, CD_ISEDITABLE, - content + content.c_str() ); } } @@ -250,7 +255,7 @@ static void CreateReport(const char *pAnalyzer, mw_result_t CreateCrashReport(const char *pUUID, const char *pUID, int force, - map_crash_report_t& pCrashReport) + map_crash_data_t& pCrashData) { VERB2 log("CreateCrashReport('%s','%s',result)", pUUID, pUID); @@ -272,7 +277,6 @@ mw_result_t CreateCrashReport(const char *pUUID, { CDebugDump dd; std::string analyzer; - std::string gUUID; std::string comment; std::string reproduce = "1.\n2.\n3.\n"; @@ -292,20 +296,20 @@ mw_result_t CreateCrashReport(const char *pUUID, VERB3 log(" CreateReport('%s')", analyzer.c_str()); CreateReport(analyzer.c_str(), row.m_sDebugDumpDir.c_str(), force); - gUUID = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); + std::string gUUID = GetGlobalUUID(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); VERB3 log(" GetGlobalUUID:'%s'", gUUID.c_str()); VERB3 log(" RunAnalyzerActions"); RunAnalyzerActions(analyzer.c_str(), row.m_sDebugDumpDir.c_str()); VERB3 log(" DebugDumpToCrashReport"); - DebugDumpToCrashReport(row.m_sDebugDumpDir.c_str(), pCrashReport); + DebugDumpToCrashReport(row.m_sDebugDumpDir.c_str(), pCrashData); - 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, comment); - add_crash_data_to_crash_report(pCrashReport, CD_REPRODUCE, CD_TXT, CD_ISEDITABLE, reproduce); + add_to_crash_data_ext(pCrashData, CD_UUID , CD_TXT, CD_ISNOTEDITABLE, gUUID.c_str() ); + add_to_crash_data_ext(pCrashData, CD_MWANALYZER, CD_SYS, CD_ISNOTEDITABLE, analyzer.c_str() ); + add_to_crash_data_ext(pCrashData, CD_MWUID , CD_SYS, CD_ISNOTEDITABLE, pUID ); + add_to_crash_data_ext(pCrashData, CD_MWUUID , CD_SYS, CD_ISNOTEDITABLE, pUUID ); + add_to_crash_data_ext(pCrashData, CD_COMMENT , CD_TXT, CD_ISEDITABLE , comment.c_str() ); + add_to_crash_data_ext(pCrashData, CD_REPRODUCE , CD_TXT, CD_ISEDITABLE , reproduce.c_str()); } catch (CABRTException& e) { @@ -362,7 +366,7 @@ void RunActionsAndReporters(const char *pDebugDumpDir) if (tp == REPORTER) { CReporter* reporter = g_pPluginManager->GetReporter(plugin_name); /* can't be NULL */ - map_crash_report_t crashReport; + map_crash_data_t crashReport; DebugDumpToCrashReport(pDebugDumpDir, crashReport); VERB2 log("%s.Report(...)", plugin_name); reporter->Report(crashReport, plugin_settings, it_ar->second.c_str()); @@ -382,20 +386,20 @@ void RunActionsAndReporters(const char *pDebugDumpDir) } -static bool CheckReport(const map_crash_report_t& pCrashReport) +static bool CheckReport(const map_crash_data_t& pCrashData) { - map_crash_report_t::const_iterator it_analyzer = pCrashReport.find(CD_MWANALYZER); - map_crash_report_t::const_iterator it_mwuid = pCrashReport.find(CD_MWUID); - map_crash_report_t::const_iterator it_mwuuid = pCrashReport.find(CD_MWUUID); + map_crash_data_t::const_iterator it_analyzer = pCrashData.find(CD_MWANALYZER); + map_crash_data_t::const_iterator it_mwuid = pCrashData.find(CD_MWUID); + map_crash_data_t::const_iterator it_mwuuid = pCrashData.find(CD_MWUUID); - map_crash_report_t::const_iterator it_package = pCrashReport.find(FILENAME_PACKAGE); - map_crash_report_t::const_iterator it_architecture = pCrashReport.find(FILENAME_ARCHITECTURE); - map_crash_report_t::const_iterator it_kernel = pCrashReport.find(FILENAME_KERNEL); - map_crash_report_t::const_iterator it_component = pCrashReport.find(FILENAME_COMPONENT); - map_crash_report_t::const_iterator it_release = pCrashReport.find(FILENAME_RELEASE); - map_crash_report_t::const_iterator it_executable = pCrashReport.find(FILENAME_EXECUTABLE); + map_crash_data_t::const_iterator it_package = pCrashData.find(FILENAME_PACKAGE); + map_crash_data_t::const_iterator it_architecture = pCrashData.find(FILENAME_ARCHITECTURE); + map_crash_data_t::const_iterator it_kernel = pCrashData.find(FILENAME_KERNEL); + map_crash_data_t::const_iterator it_component = pCrashData.find(FILENAME_COMPONENT); + map_crash_data_t::const_iterator it_release = pCrashData.find(FILENAME_RELEASE); + map_crash_data_t::const_iterator it_executable = pCrashData.find(FILENAME_EXECUTABLE); - map_crash_report_t::const_iterator end = pCrashReport.end(); + map_crash_data_t::const_iterator end = pCrashData.end(); if (it_package == end) { @@ -427,38 +431,38 @@ static bool CheckReport(const map_crash_report_t& pCrashReport) return true; } -report_status_t Report(const map_crash_report_t& pCrashReport, +report_status_t Report(const map_crash_data_t& pCrashData, map_map_string_t& pSettings, const char *pUID) { report_status_t ret; - /* dbus handler passes pCrashReport from user without checking it */ + /* dbus handler passes pCrashData from user without checking it */ - if (!CheckReport(pCrashReport)) + if (!CheckReport(pCrashData)) { throw CABRTException(EXCEP_ERROR, "Report(): Some of mandatory report data are missing."); } - 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]; - std::string packageNVR = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; + std::string analyzer = pCrashData.find(CD_MWANALYZER)->second[CD_CONTENT]; + std::string UID = pCrashData.find(CD_MWUID)->second[CD_CONTENT]; + std::string UUID = pCrashData.find(CD_MWUUID)->second[CD_CONTENT]; + std::string packageNVR = pCrashData.find(FILENAME_PACKAGE)->second[CD_CONTENT]; std::string packageName = packageNVR.substr(0, packageNVR.rfind("-", packageNVR.rfind("-") - 1)); // Save comment and "how to reproduce" - map_crash_report_t::const_iterator it_comment = pCrashReport.find(CD_COMMENT); - map_crash_report_t::const_iterator it_reproduce = pCrashReport.find(CD_REPRODUCE); - if (it_comment != pCrashReport.end() || it_reproduce != pCrashReport.end()) + map_crash_data_t::const_iterator it_comment = pCrashData.find(CD_COMMENT); + map_crash_data_t::const_iterator it_reproduce = pCrashData.find(CD_REPRODUCE); + if (it_comment != pCrashData.end() || it_reproduce != pCrashData.end()) { std::string pDumpDir = getDebugDumpDir(UUID.c_str(), UID.c_str()); CDebugDump dd; dd.Open(pDumpDir.c_str()); - if (it_comment != pCrashReport.end()) + if (it_comment != pCrashData.end()) { dd.SaveText(FILENAME_COMMENT, it_comment->second[CD_CONTENT].c_str()); } - if (it_reproduce != pCrashReport.end()) + if (it_reproduce != pCrashData.end()) { dd.SaveText(FILENAME_REPRODUCE, it_reproduce->second[CD_CONTENT].c_str()); } @@ -509,7 +513,7 @@ report_status_t Report(const map_crash_report_t& pCrashReport, } #endif map_plugin_settings_t plugin_settings = pSettings[plugin_name]; - std::string res = reporter->Report(pCrashReport, plugin_settings, it_r->second.c_str()); + std::string res = reporter->Report(pCrashData, plugin_settings, it_r->second.c_str()); #if 0 /* Using ~user/.abrt/ is bad wrt security */ if (home != "") @@ -767,7 +771,7 @@ bool analyzer_has_AutoReportUIDs(const char *analyzer_name, const char* uid) return false; } -void autoreport(const pair_string_string_t& reporter_options, const map_crash_report_t& crash_report) +void autoreport(const pair_string_string_t& reporter_options, const map_crash_data_t& crash_report) { CReporter* reporter = g_pPluginManager->GetReporter(reporter_options.first.c_str()); if (!reporter) @@ -821,14 +825,14 @@ static void RunAnalyzerActions(const char *pAnalyzer, const char *pDebugDumpDir) * @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. + * @param pCrashData A filled crash info. * @return It return results of operation. See mw_result_t. */ static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, const char *pUID, const char *pTime, const char *pDebugDumpDir, - map_crash_info_t& pCrashInfo) + map_crash_data_t& pCrashData) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); @@ -837,7 +841,7 @@ static mw_result_t SaveDebugDumpToDatabase(const char *pUUID, database_row_t row = database->GetRow(pUUID, pUID); database->DisConnect(); - mw_result_t res = FillCrashInfo(pUUID, pUID, pCrashInfo); + mw_result_t res = FillCrashInfo(pUUID, pUID, pCrashData); if (res == MW_OK) { if (row.m_sReported == "1") @@ -865,7 +869,7 @@ std::string getDebugDumpDir(const char *pUUID, } mw_result_t SaveDebugDump(const char *pDebugDumpDir, - map_crash_info_t& pCrashInfo) + map_crash_data_t& pCrashData) { std::string UID; std::string time; @@ -907,12 +911,12 @@ mw_result_t SaveDebugDump(const char *pDebugDumpDir, const char *uid_str = analyzer_has_InformAllUsers(analyzer.c_str()) ? "-1" : UID.c_str(); - return SaveDebugDumpToDatabase(lUUID.c_str(), uid_str, time.c_str(), pDebugDumpDir, pCrashInfo); + return SaveDebugDumpToDatabase(lUUID.c_str(), uid_str, time.c_str(), pDebugDumpDir, pCrashData); } mw_result_t FillCrashInfo(const char *pUUID, const char *pUID, - map_crash_info_t& pCrashInfo) + map_crash_data_t& pCrashData) { CDatabase* database = g_pPluginManager->GetDatabase(g_settings_sDatabase.c_str()); database->Connect(); @@ -938,18 +942,18 @@ mw_result_t FillCrashInfo(const char *pUUID, return MW_ERROR; } - pCrashInfo.clear(); - 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_MESSAGE, row.m_sMessage); - add_crash_data_to_crash_info(pCrashInfo, CD_MWDDD, row.m_sDebugDumpDir); - add_crash_data_to_crash_info(pCrashInfo, CD_MWANALYZER, analyzer); + pCrashData.clear(); + add_to_crash_data(pCrashData, CD_EXECUTABLE , executable.c_str() ); + add_to_crash_data(pCrashData, CD_PACKAGE , package.c_str() ); + add_to_crash_data(pCrashData, CD_DESCRIPTION, description.c_str() ); + add_to_crash_data(pCrashData, CD_UUID , row.m_sUUID.c_str() ); + add_to_crash_data(pCrashData, CD_UID , row.m_sUID.c_str() ); + add_to_crash_data(pCrashData, CD_COUNT , row.m_sCount.c_str() ); + add_to_crash_data(pCrashData, CD_TIME , row.m_sTime.c_str() ); + add_to_crash_data(pCrashData, CD_REPORTED , row.m_sReported.c_str() ); + add_to_crash_data(pCrashData, CD_MESSAGE , row.m_sMessage.c_str() ); + add_to_crash_data(pCrashData, CD_MWDDD , row.m_sDebugDumpDir.c_str()); + add_to_crash_data(pCrashData, CD_MWANALYZER , analyzer.c_str() ); return MW_OK; } diff --git a/src/Daemon/MiddleWare.h b/src/Daemon/MiddleWare.h index b2b58dcd..5fab84d3 100644 --- a/src/Daemon/MiddleWare.h +++ b/src/Daemon/MiddleWare.h @@ -60,13 +60,13 @@ void LoadOpenGPGPublicKey(const char* key); * 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. + * @param pCrashData A filled crash report. * @return It return results of operation. See mw_result_t. */ mw_result_t CreateCrashReport(const char *pUUID, const char *pUID, int force, - map_crash_report_t& pCrashReport); + map_crash_data_t& pCrashData); /** * Activates particular action plugin. * @param pActionDir A directory, which is passed as working to a action plugin. @@ -88,11 +88,11 @@ void RunActionsAndReporters(const char *pDebugDumpDir); * fails, then default config is used. If pUID is emply string, default * config is used. * ...). - * @param pCrashReport A crash report. + * @param pCrashData A crash report. * @param pUID An user uid * @return A report status, which reporters ends successfuly with messages. */ -report_status_t Report(const map_crash_report_t& pCrashReport, +report_status_t Report(const map_crash_data_t& pCrashData, map_map_string_t& pSettings, const char *pUID); /** @@ -108,22 +108,22 @@ std::string getDebugDumpDir( const char *pUUID, * Saves debugdump into database. If saving is successful, * it fills crash info. * @param pDebugDumpDir A debugdump directory. - * @param pCrashInfo A crash info. + * @param pCrashData A crash info. * @return It return results of operation. See mw_result_t. */ mw_result_t SaveDebugDump(const char *pDebugDumpDir, - map_crash_info_t& pCrashInfo); + map_crash_data_t& pCrashData); /** * Get one crash info. If getting is successful, * then crash info is filled. * @param pUUID A local UUID of a crash. * @param pUID An UID of an user. - * @param pCrashInfo A crash info. + * @param pCrashData A crash info. * @return It return results of operation. See mw_result_t. */ mw_result_t FillCrashInfo(const char *pUUID, const char *pUID, - map_crash_info_t& pCrashInfo); + map_crash_data_t& pCrashData); /** * Gets all local UUIDs and UIDs of crashes. These crashes * occurred when a particular user was logged in. @@ -154,5 +154,5 @@ bool analyzer_has_InformAllUsers(const char *analyzer_name); bool analyzer_has_AutoReportUIDs(const char *analyzer_name, const char* uid); -void autoreport(const pair_string_string_t& reporter_options, const map_crash_report_t& crash_report); +void autoreport(const pair_string_string_t& reporter_options, const map_crash_data_t& crash_report); #endif /*MIDDLEWARE_H_*/ -- cgit