diff options
| author | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-11-09 11:06:14 +0100 |
|---|---|---|
| committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2009-11-09 11:06:14 +0100 |
| commit | ca69be0df85ac461824ff06eda61669d7741ca4f (patch) | |
| tree | 607fb84953af65135109d47dfb8ad19472027fae /lib | |
| parent | d8d3f8d838ef4656c2f786c2316577f202827dbf (diff) | |
| parent | bff039d2e6d0d721447335311f83c5e9ff50d528 (diff) | |
| download | abrt-ca69be0df85ac461824ff06eda61669d7741ca4f.tar.gz abrt-ca69be0df85ac461824ff06eda61669d7741ca4f.tar.xz abrt-ca69be0df85ac461824ff06eda61669d7741ca4f.zip | |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'lib')
28 files changed, 167 insertions, 190 deletions
diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index ca83d36..ecd4dd6 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -313,7 +313,7 @@ int32_t ctx::check_uuid_in_bugzilla(const char* component, const char* UUID) xmlrpc_int bug_id; xmlrpc_read_int(&env, bug, &bug_id); log("Bug is already reported: %i", (int)bug_id); - update_client(_("Bug is already reported: ") + to_string(bug_id)); + update_client(_("Bug is already reported: %i"), (int)bug_id); xmlrpc_DECREF(bug); xmlrpc_DECREF(item); @@ -375,7 +375,7 @@ uint32_t ctx::new_bug(const map_crash_report_t& pCrashReport) xmlrpc_read_int(&env, id, &bug_id); throw_if_xml_fault_occurred(&env); log("New bug id: %i", bug_id); - update_client(_("New bug id: ") + to_string(bug_id)); + update_client(_("New bug id: %i"), bug_id); } xmlrpc_DECREF(result); @@ -618,16 +618,14 @@ void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CReporterBugzilla::GetSettings() +const map_plugin_settings_t& CReporterBugzilla::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["BugzillaURL"] = m_sBugzillaURL; + m_pSettings["Login"] = m_sLogin; + m_pSettings["Password"] = m_sPassword; + m_pSettings["NoSSLVerify"] = m_bNoSSLVerify ? "yes" : "no"; - ret["BugzillaURL"] = m_sBugzillaURL; - ret["Login"] = m_sLogin; - ret["Password"] = m_sPassword; - ret["NoSSLVerify"] = m_bNoSSLVerify ? "yes" : "no"; - - return ret; + return m_pSettings; } PLUGIN_INFO(REPORTER, diff --git a/lib/Plugins/Bugzilla.h b/lib/Plugins/Bugzilla.h index 702eead..55a5f5f 100644 --- a/lib/Plugins/Bugzilla.h +++ b/lib/Plugins/Bugzilla.h @@ -8,20 +8,19 @@ class CReporterBugzilla : public CReporter { private: bool m_bNoSSLVerify; - std::string m_sBugzillaURL; std::string m_sBugzillaXMLRPC; std::string m_sLogin; std::string m_sPassword; std::string m_sAttchmentInBase64; - + map_plugin_settings_t parse_settings(const map_plugin_settings_t& pSettings); public: CReporterBugzilla(); virtual ~CReporterBugzilla(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, const std::string& pArgs); diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index a2d65f3..4b73938 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -610,8 +610,8 @@ Another application is holding the yum lock, cannot continue if (last >= 0 && buff[last] == '\n') buff[last] = '\0'; - /* log(buff); - update_client logs it too */ - update_client(buff); /* maybe only if buff != ""? */ + log("%s", buff); + update_client("%s", buff); /* maybe only if buff != ""? */ #ifdef COMPLAIN_IF_NO_DEBUGINFO if (already_installed == false) @@ -715,8 +715,8 @@ static void InstallDebugInfos(const char *pDebugDumpDir, std::string& build_ids) } if (*p) { - /* log(buff); - update_client logs it too */ - update_client(buff); + log("%s", buff); + update_client("%s", buff); } } @@ -975,16 +975,14 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CAnalyzerCCpp::GetSettings() +const map_plugin_settings_t& CAnalyzerCCpp::GetSettings() { - map_plugin_settings_t ret = m_pSettings; + m_pSettings["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; + m_pSettings["DebugInfo"] = m_sDebugInfo; + m_pSettings["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); + m_pSettings["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; - ret["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; - ret["DebugInfo"] = m_sDebugInfo; - ret["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); - ret["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; - - return ret; + return m_pSettings; } PLUGIN_INFO(ANALYZER, diff --git a/lib/Plugins/CCpp.h b/lib/Plugins/CCpp.h index a768c0a..e2abdec 100644 --- a/lib/Plugins/CCpp.h +++ b/lib/Plugins/CCpp.h @@ -35,7 +35,6 @@ class CAnalyzerCCpp : public CAnalyzer unsigned m_nDebugInfoCacheMB; std::string m_sOldCorePattern; std::string m_sDebugInfo; - map_plugin_settings_t m_pSettings; public: CAnalyzerCCpp(); @@ -45,7 +44,7 @@ class CAnalyzerCCpp : public CAnalyzer virtual void Init(); virtual void DeInit(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); }; #endif /* CCPP */ diff --git a/lib/Plugins/Catcut.cpp b/lib/Plugins/Catcut.cpp index 6bb44a9..13fa8a4 100644 --- a/lib/Plugins/Catcut.cpp +++ b/lib/Plugins/Catcut.cpp @@ -162,9 +162,7 @@ static void create_new_bug_description(const map_crash_report_t& pCrashReport, s } else if (it->second[CD_TYPE] == CD_BIN) { - string msg = ssprintf(_("Binary file %s will not be reported."), it->first.c_str()); - warn_client(msg); - //update_client(_("Binary file ")+it->first+_(" will not be reported.")); + error_msg(_("Binary file %s will not be reported"), it->first.c_str()); } } } @@ -244,7 +242,7 @@ static string new_bug(const char *auth_cookie, const map_crash_report_t& pCrashR throw_if_xml_fault_occurred(); bug_id_str = bug_id; log("New bug id: %s", bug_id); - update_client(_("New bug id: ") + bug_id_str); + update_client(_("New bug id: %s"), bug_id); free((void*)bug_id); xmlrpc_DECREF(bug_id_xml); @@ -350,16 +348,14 @@ void CReporterCatcut::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CReporterCatcut::GetSettings() +const map_plugin_settings_t& CReporterCatcut::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["CatcutURL"] = m_sCatcutURL; + m_pSettings["Login"] = m_sLogin; + m_pSettings["Password"] = m_sPassword; + m_pSettings["NoSSLVerify"] = m_bNoSSLVerify ? "yes" : "no"; - ret["CatcutURL"] = m_sCatcutURL; - ret["Login"] = m_sLogin; - ret["Password"] = m_sPassword; - ret["NoSSLVerify"] = m_bNoSSLVerify ? "yes" : "no"; - - return ret; + return m_pSettings; } PLUGIN_INFO(REPORTER, diff --git a/lib/Plugins/Catcut.h b/lib/Plugins/Catcut.h index 40ef399..15efdc1 100644 --- a/lib/Plugins/Catcut.h +++ b/lib/Plugins/Catcut.h @@ -17,7 +17,7 @@ class CReporterCatcut : public CReporter virtual ~CReporterCatcut(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp index 856a326..72b3b16 100644 --- a/lib/Plugins/FileTransfer.cpp +++ b/lib/Plugins/FileTransfer.cpp @@ -60,12 +60,11 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename) int len = strlen(pURL); if (len == 0) { - warn_client(_("FileTransfer: URL not specified")); + error_msg(_("FileTransfer: URL not specified")); return; } - string msg = ssprintf(_("Sending archive %s to %s"), pFilename, pURL); - update_client(msg.c_str()); + update_client(_("Sending archive %s to %s"), pFilename, pURL); string wholeURL = concat_path_file(pURL, pFilename); @@ -332,8 +331,7 @@ void CFileTransfer::Run(const char *pActionDir, const char *pArgs) } catch (CABRTException& e) { - warn_client(_("CFileTransfer::Run(): Cannot create and send an archive: ") + e.what()); - //update_client("CFileTransfer::Run(): Cannot create and send an archive: " + e.what()); + error_msg(_("Can't create and send an archive: %s"), e.what()); } unlink(archivename.c_str()); } @@ -358,8 +356,7 @@ void CFileTransfer::Run(const char *pActionDir, const char *pArgs) } catch (CABRTException& e) { - warn_client(_("CFileTransfer::Run(): Cannot create and send an archive: ") + e.what()); -// update_client("CFileTransfer::Run(): Cannot create and send an archive: " + e.what()); + error_msg(_("Can't create and send an archive %s"), e.what()); } unlink(archivename.c_str()); } @@ -381,7 +378,7 @@ void CFileTransfer::SetSettings(const map_plugin_settings_t& pSettings) } else { - warn_client(_("FileTransfer: URL not specified")); + error_msg(_("FileTransfer: URL not specified")); } it = pSettings.find("RetryCount"); @@ -408,16 +405,14 @@ void CFileTransfer::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CFileTransfer::GetSettings() +const map_plugin_settings_t& CFileTransfer::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["URL"] = m_sURL; + m_pSettings["RetryCount"] = to_string(m_nRetryCount); + m_pSettings["RetryDelay"] = to_string(m_nRetryDelay); + m_pSettings["ArchiveType"] = m_sArchiveType; - ret["URL"] = m_sURL; - ret["RetryCount"] = to_string(m_nRetryCount); - ret["RetryDelay"] = to_string(m_nRetryDelay); - ret["ArchiveType"] = m_sArchiveType; - - return ret; + return m_pSettings; } PLUGIN_INFO(ACTION, diff --git a/lib/Plugins/FileTransfer.h b/lib/Plugins/FileTransfer.h index 526fbc3..9caa256 100644 --- a/lib/Plugins/FileTransfer.h +++ b/lib/Plugins/FileTransfer.h @@ -41,7 +41,7 @@ class CFileTransfer : public CAction public: CFileTransfer(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); virtual void Run(const char *pActionDir, const char *pArgs); }; diff --git a/lib/Plugins/Kerneloops.cpp b/lib/Plugins/Kerneloops.cpp index f2a8a59..b99183c 100644 --- a/lib/Plugins/Kerneloops.cpp +++ b/lib/Plugins/Kerneloops.cpp @@ -63,16 +63,6 @@ std::string CAnalyzerKerneloops::GetGlobalUUID(const char *pDebugDumpDir) return GetLocalUUID(pDebugDumpDir); } -void CAnalyzerKerneloops::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; -} - -map_plugin_settings_t CAnalyzerKerneloops::GetSettings() -{ - return m_pSettings; -} - PLUGIN_INFO(ANALYZER, CAnalyzerKerneloops, "Kerneloops", diff --git a/lib/Plugins/Kerneloops.h b/lib/Plugins/Kerneloops.h index cda223d..9e2010c 100644 --- a/lib/Plugins/Kerneloops.h +++ b/lib/Plugins/Kerneloops.h @@ -33,15 +33,10 @@ class CAnalyzerKerneloops : public CAnalyzer { - private: - map_plugin_settings_t m_pSettings; - public: virtual std::string GetLocalUUID(const char *pDebugDumpDir); virtual std::string GetGlobalUUID(const char *pDebugDumpDir); virtual void CreateReport(const char *pDebugDumpDir, int force) {} - virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); }; #endif diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index 712adf0..cfb4e05 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -124,13 +124,11 @@ void CKerneloopsReporter::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CKerneloopsReporter::GetSettings() +const map_plugin_settings_t& CKerneloopsReporter::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["SubmitURL"] = m_sSubmitURL; - ret["SubmitURL"] = m_sSubmitURL; - - return ret; + return m_pSettings; } PLUGIN_INFO(REPORTER, diff --git a/lib/Plugins/KerneloopsReporter.h b/lib/Plugins/KerneloopsReporter.h index 3c16592..7f6ab8c 100644 --- a/lib/Plugins/KerneloopsReporter.h +++ b/lib/Plugins/KerneloopsReporter.h @@ -41,7 +41,7 @@ class CKerneloopsReporter : public CReporter CKerneloopsReporter(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, const std::string& pArgs); diff --git a/lib/Plugins/KerneloopsScanner.cpp b/lib/Plugins/KerneloopsScanner.cpp index 3572ef2..8c8cd4b 100644 --- a/lib/Plugins/KerneloopsScanner.cpp +++ b/lib/Plugins/KerneloopsScanner.cpp @@ -180,16 +180,6 @@ int CKerneloopsScanner::ScanSysLogFile(const char *filename) return cnt_FoundOopses; } -void CKerneloopsScanner::SetSettings(const map_plugin_settings_t& pSettings) -{ - m_pSettings = pSettings; -} - -map_plugin_settings_t CKerneloopsScanner::GetSettings() -{ - return m_pSettings; -} - PLUGIN_INFO(ACTION, CKerneloopsScanner, "KerneloopsScanner", diff --git a/lib/Plugins/KerneloopsScanner.h b/lib/Plugins/KerneloopsScanner.h index a2a4e4b..9f00df2 100644 --- a/lib/Plugins/KerneloopsScanner.h +++ b/lib/Plugins/KerneloopsScanner.h @@ -33,9 +33,6 @@ class CKerneloopsScanner : public CAction { - private: - map_plugin_settings_t m_pSettings; - /* For "dumpoops" tool */ public: vector_string_t m_pOopsList; @@ -50,8 +47,6 @@ class CKerneloopsScanner : public CAction public: CKerneloopsScanner(); virtual void Run(const char *pActionDir, const char *pArgs); - virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); }; #endif diff --git a/lib/Plugins/Logger.cpp b/lib/Plugins/Logger.cpp index 716d3a9..b2ac1ad 100644 --- a/lib/Plugins/Logger.cpp +++ b/lib/Plugins/Logger.cpp @@ -43,14 +43,12 @@ void CLogger::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CLogger::GetSettings() +const map_plugin_settings_t& CLogger::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["LogPath"] = m_sLogPath; + m_pSettings["AppendLogs"] = m_bAppendLogs ? "yes" : "no"; - ret["LogPath"] = m_sLogPath; - ret["AppendLogs"] = m_bAppendLogs ? "yes" : "no"; - - return ret; + return m_pSettings; } std::string CLogger::Report(const map_crash_report_t& pCrashReport, diff --git a/lib/Plugins/Logger.h b/lib/Plugins/Logger.h index 33f957d..0969bea 100644 --- a/lib/Plugins/Logger.h +++ b/lib/Plugins/Logger.h @@ -35,7 +35,7 @@ class CLogger : public CReporter CLogger(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, const std::string& pArgs); diff --git a/lib/Plugins/Mailx.cpp b/lib/Plugins/Mailx.cpp index ef3a8d2..f083404 100644 --- a/lib/Plugins/Mailx.cpp +++ b/lib/Plugins/Mailx.cpp @@ -219,16 +219,14 @@ void CMailx::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CMailx::GetSettings() +const map_plugin_settings_t& CMailx::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["Subject"] = m_sSubject; + m_pSettings["EmailFrom"] = m_sEmailFrom; + m_pSettings["EmailTo"] = m_sEmailTo; + m_pSettings["SendBinaryData"] = m_bSendBinaryData ? "yes" : "no"; - ret["Subject"] = m_sSubject; - ret["EmailFrom"] = m_sEmailFrom; - ret["EmailTo"] = m_sEmailTo; - ret["SendBinaryData"] = m_bSendBinaryData ? "yes" : "no"; - - return ret; + return m_pSettings; } PLUGIN_INFO(REPORTER, diff --git a/lib/Plugins/Mailx.h b/lib/Plugins/Mailx.h index e3c86e7..7af1188 100644 --- a/lib/Plugins/Mailx.h +++ b/lib/Plugins/Mailx.h @@ -47,7 +47,7 @@ class CMailx : public CReporter CMailx(); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); virtual std::string Report(const map_crash_report_t& pCrashReport, const map_plugin_settings_t& pSettings, const std::string& pArgs); diff --git a/lib/Plugins/SOSreport.cpp b/lib/Plugins/SOSreport.cpp index da77cce..fedc51a 100644 --- a/lib/Plugins/SOSreport.cpp +++ b/lib/Plugins/SOSreport.cpp @@ -119,7 +119,7 @@ void CActionSOSreport::Run(const char *pActionDir, const char *pArgs) command = ssprintf("%s %s 2>&1", command_prefix, args[0].c_str()); } - update_client(_("running sosreport: ") + command); + update_client(_("running sosreport: %s"), command.c_str()); FILE *fp = popen(command.c_str(), "r"); if (fp == NULL) { diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index d55c0a9..ab39d04 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -404,13 +404,11 @@ void CSQLite3::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CSQLite3::GetSettings() +const map_plugin_settings_t& CSQLite3::GetSettings() { - map_plugin_settings_t ret; + m_pSettings["DBPath"] = m_sDBPath; - ret["DBPath"] = m_sDBPath; - - return ret; + return m_pSettings; } PLUGIN_INFO(DATABASE, diff --git a/lib/Plugins/SQLite3.h b/lib/Plugins/SQLite3.h index e7ca8ae..0eb3d08 100644 --- a/lib/Plugins/SQLite3.h +++ b/lib/Plugins/SQLite3.h @@ -58,7 +58,7 @@ class CSQLite3 : public CDatabase virtual database_row_t GetUUIDData(const std::string& pUUID, const std::string& pUID); virtual void SetSettings(const map_plugin_settings_t& pSettings); - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); }; #endif /* SQLITE3_H_ */ diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp index 4aa05b7..e380de0 100644 --- a/lib/Plugins/TicketUploader.cpp +++ b/lib/Plugins/TicketUploader.cpp @@ -43,7 +43,7 @@ CTicketUploader::~CTicketUploader() static void Error(const char *msg) { - update_client(msg); + update_client("%s", msg); throw CABRTException(EXCEP_PLUGIN, msg); } @@ -102,11 +102,11 @@ void CTicketUploader::SendFile(const char *pURL, const char *pFilename) { if (pURL[0] == '\0') { - warn_client(_("FileTransfer: URL not specified")); + error_msg(_("FileTransfer: URL not specified")); return; } - update_client(ssprintf(_("Sending archive %s to %s"), pFilename, pURL)); + update_client(_("Sending archive %s to %s"), pFilename, pURL); const char *base = (strrchr(pFilename, '/') ? : pFilename-1) + 1; string wholeURL = concat_path_file(pURL, base); @@ -133,7 +133,6 @@ void CTicketUploader::SendFile(const char *pURL, const char *pFilename) curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str()); - /*file handle: passed to the default callback, it will fread() it*/ curl_easy_setopt(curl, CURLOPT_READDATA, f); curl_easy_setopt(curl, CURLOPT_INFILESIZE, buf.st_size); /* everything is done here; result 0 means success */ @@ -143,7 +142,7 @@ void CTicketUploader::SendFile(const char *pURL, const char *pFilename) fclose(f); if (result != 0) { - update_client(ssprintf(_("Sending failed, trying again. %s"), curl_easy_strerror((CURLcode)result))); + update_client(_("Sending failed, trying again. %s"), curl_easy_strerror((CURLcode)result)); } } /*retry the upload if not succesful, wait a bit before next try*/ @@ -317,19 +316,19 @@ string CTicketUploader::Report(const map_crash_report_t& pCrashReport, } msgbuf << _("END: ") << endl; - warn_client(msgbuf.str()); + error_msg("%s", msgbuf.str().c_str()); string ret; if (do_upload) { string xx = _("report sent to ") + upload_url + '/' + outfile_basename; - update_client(xx); + update_client("%s", xx.c_str()); ret = xx; } else { string xx = _("report copied to /tmp/") + outfile_basename; - update_client(xx); + update_client("%s", xx.c_str()); ret = xx; } @@ -382,20 +381,17 @@ void CTicketUploader::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CTicketUploader::GetSettings() +const map_plugin_settings_t& CTicketUploader::GetSettings() { - map_plugin_settings_t ret; - - ret["Customer"] = m_sCustomer; - ret["Ticket"] = m_sTicket; - ret["URL"] = m_sURL; - ret["Encrypt"] = m_bEncrypt ? "yes" : "no"; - ret["Upload"] = m_bEncrypt ? "yes" : "no"; - - ret["RetryCount"] = to_string(m_nRetryCount); - ret["RetryDelay"] = to_string(m_nRetryDelay); - - return ret; + m_pSettings["Customer"] = m_sCustomer; + m_pSettings["Ticket"] = m_sTicket; + m_pSettings["URL"] = m_sURL; + m_pSettings["Encrypt"] = m_bEncrypt ? "yes" : "no"; + m_pSettings["Upload"] = m_bEncrypt ? "yes" : "no"; + m_pSettings["RetryCount"] = to_string(m_nRetryCount); + m_pSettings["RetryDelay"] = to_string(m_nRetryDelay); + + return m_pSettings; } PLUGIN_INFO(REPORTER, diff --git a/lib/Plugins/TicketUploader.h b/lib/Plugins/TicketUploader.h index 8995481..9ae3478 100644 --- a/lib/Plugins/TicketUploader.h +++ b/lib/Plugins/TicketUploader.h @@ -45,7 +45,7 @@ class CTicketUploader : public CReporter public: CTicketUploader(); virtual ~CTicketUploader(); - virtual map_plugin_settings_t GetSettings(); + 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, diff --git a/lib/Utils/CommLayerInner.cpp b/lib/Utils/CommLayerInner.cpp index 8490e2f..307fe66 100644 --- a/lib/Utils/CommLayerInner.cpp +++ b/lib/Utils/CommLayerInner.cpp @@ -10,29 +10,48 @@ static map_uint_str_t s_mapClientID; static pthread_mutex_t s_map_mutex; static bool s_map_mutex_inited; +/* called via [p]error_msg() */ +static void warn_client(const char *msg) +{ + if (!s_pObs) + return; + + uint64_t key = uint64_t(pthread_self()); + + pthread_mutex_lock(&s_map_mutex); + map_uint_str_t::const_iterator ki = s_mapClientID.find(key); + const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); + pthread_mutex_unlock(&s_map_mutex); + + if (peer) + s_pObs->Warning(msg, peer, key); +} + void init_daemon_logging(CObserver *pObs) { s_pObs = pObs; if (!s_map_mutex_inited) { - pthread_mutex_init(&s_map_mutex, NULL); s_map_mutex_inited = true; + pthread_mutex_init(&s_map_mutex, NULL); + g_custom_logger = &warn_client; } } -void set_client_name(const char* name) +void set_client_name(const char *name) { uint64_t key = uint64_t(pthread_self()); pthread_mutex_lock(&s_map_mutex); - if (!name) + if (!name) { s_mapClientID.erase(key); - else + } else { s_mapClientID[key] = name; + } pthread_mutex_unlock(&s_map_mutex); } -void warn_client(const std::string& pMessage) +void update_client(const char *fmt, ...) { if (!s_pObs) return; @@ -44,26 +63,16 @@ void warn_client(const std::string& pMessage) const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); pthread_mutex_unlock(&s_map_mutex); - if (peer) - s_pObs->Warning(pMessage.c_str(), peer, key); - else /* Bug: someone tries to warn_client() without set_client_name()!? */ - log("Hmm, stray %s: '%s'", __func__, pMessage.c_str()); -} - -void update_client(const std::string& pMessage) -{ - if (!s_pObs) + if (!peer) return; - uint64_t key = uint64_t(pthread_self()); + va_list p; + va_start(p, fmt); + char *msg; + int used = vasprintf(&msg, fmt, p); + va_end(p); + if (used < 0) + return; - pthread_mutex_lock(&s_map_mutex); - map_uint_str_t::const_iterator ki = s_mapClientID.find(key); - const char* peer = (ki != s_mapClientID.end() ? ki->second.c_str() : NULL); - pthread_mutex_unlock(&s_map_mutex); - - if (peer) - s_pObs->Status(pMessage.c_str(), peer, key); - else - log("Hmm, stray %s: '%s'", __func__, pMessage.c_str()); + s_pObs->Status(msg, peer, key); } diff --git a/lib/Utils/CommLayerInner.h b/lib/Utils/CommLayerInner.h index d161cfc..9c22968 100644 --- a/lib/Utils/CommLayerInner.h +++ b/lib/Utils/CommLayerInner.h @@ -9,15 +9,19 @@ void init_daemon_logging(CObserver *pObs); * Set client's name (dbus ID). NULL unsets it. */ void set_client_name(const char* name); -/* Ask a client to warn the user about a non-fatal, but unexpected condition. + +/* + * Ask a client to warn the user about a non-fatal, but unexpected condition. * In GUI, it will usually be presented as a popup message. + * Usually there is no need to call it directly, just use [p]error_msg(). */ -void warn_client(const std::string& pMessage); -/* Logs a message to a client. +//now static: void warn_client(const char *msg); + +/* + * Logs a message to a client. * In UI, it will usually appear as a new status line message in GUI, * or as a new message line in CLI. */ -void update_client(const std::string& pMessage); - -#endif /* COMMLAYERINNER_H_ */ +void update_client(const char *fmt, ...); +#endif diff --git a/lib/Utils/Plugin.cpp b/lib/Utils/Plugin.cpp index 161ead8..4d561b4 100644 --- a/lib/Utils/Plugin.cpp +++ b/lib/Utils/Plugin.cpp @@ -19,9 +19,18 @@ #include "Plugin.h" +CPlugin::CPlugin() {} + /* class CPlugin's virtuals */ CPlugin::~CPlugin() {} void CPlugin::Init() {} void CPlugin::DeInit() {} -void CPlugin::SetSettings(const map_plugin_settings_t& pSettings) {} -map_plugin_settings_t CPlugin::GetSettings() {return map_plugin_settings_t();} +void CPlugin::SetSettings(const map_plugin_settings_t& pSettings) +{ + m_pSettings = pSettings; +} + +const map_plugin_settings_t& CPlugin::GetSettings() +{ + return m_pSettings; +} diff --git a/lib/Utils/Plugin.h b/lib/Utils/Plugin.h index 00c7e5b..f93f7e7 100644 --- a/lib/Utils/Plugin.h +++ b/lib/Utils/Plugin.h @@ -47,7 +47,11 @@ */ class CPlugin { + protected: + map_plugin_settings_t m_pSettings; + public: + CPlugin(); /** * A destructor. */ @@ -69,7 +73,7 @@ class CPlugin * A method, which return current settings. It is not mandatory method. * @return Plugin's settings */ - virtual map_plugin_settings_t GetSettings(); + virtual const map_plugin_settings_t& GetSettings(); }; /** diff --git a/lib/Utils/logging.cpp b/lib/Utils/logging.cpp index f70d23f..cae609b 100644 --- a/lib/Utils/logging.cpp +++ b/lib/Utils/logging.cpp @@ -7,19 +7,18 @@ #include <syslog.h> int xfunc_error_retval = EXIT_FAILURE; - int g_verbose; +int logmode = LOGMODE_STDIO; +const char *msg_prefix = ""; +const char *msg_eol = "\n"; +void (*g_custom_logger)(const char*); void xfunc_die(void) { exit(xfunc_error_retval); } -const char *msg_prefix = ""; -const char *msg_eol = "\n"; -int logmode = LOGMODE_STDIO; - -void verror_msg(const char *s, va_list p, const char* strerr) +static void verror_msg_helper(const char *s, va_list p, const char* strerr, int flags) { char *msg; int prefix_len, strerr_len, msgeol_len, used; @@ -27,9 +26,6 @@ void verror_msg(const char *s, va_list p, const char* strerr) if (!logmode) return; - if (!s) /* nomsg[_and_die] uses NULL fmt */ - s = ""; /* some libc don't like printf(NULL) */ - used = vasprintf(&msg, s, p); if (used < 0) return; @@ -51,7 +47,7 @@ void verror_msg(const char *s, va_list p, const char* strerr) memcpy(msg, msg_prefix, prefix_len); } if (strerr) { - if (s[0]) { /* not perror_nomsg? */ + if (s[0]) { msg[used++] = ':'; msg[used++] = ' '; } @@ -60,24 +56,26 @@ void verror_msg(const char *s, va_list p, const char* strerr) } strcpy(&msg[used], msg_eol); - if (logmode & LOGMODE_STDIO) { + if (flags & LOGMODE_STDIO) { fflush(stdout); full_write(STDERR_FILENO, msg, used + msgeol_len); } - if (logmode & LOGMODE_SYSLOG) { + if (flags & LOGMODE_SYSLOG) { syslog(LOG_ERR, "%s", msg + prefix_len); } + if ((flags & LOGMODE_CUSTOM) && g_custom_logger) { + g_custom_logger(msg + prefix_len); + } free(msg); } -void error_msg_and_die(const char *s, ...) +void log_msg(const char *s, ...) { va_list p; va_start(p, s); - verror_msg(s, p, NULL); + verror_msg_helper(s, p, NULL, logmode); va_end(p); - xfunc_die(); } void error_msg(const char *s, ...) @@ -85,8 +83,18 @@ void error_msg(const char *s, ...) va_list p; va_start(p, s); - verror_msg(s, p, NULL); + verror_msg_helper(s, p, NULL, (logmode | LOGMODE_CUSTOM)); + va_end(p); +} + +void error_msg_and_die(const char *s, ...) +{ + va_list p; + + va_start(p, s); + verror_msg_helper(s, p, NULL, (logmode | LOGMODE_CUSTOM)); va_end(p); + xfunc_die(); } void perror_msg_and_die(const char *s, ...) @@ -95,7 +103,7 @@ void perror_msg_and_die(const char *s, ...) va_start(p, s); /* Guard against "<error message>: Success" */ - verror_msg(s, p, errno ? strerror(errno) : NULL); + verror_msg_helper(s, p, errno ? strerror(errno) : NULL, (logmode | LOGMODE_CUSTOM)); va_end(p); xfunc_die(); } @@ -106,7 +114,7 @@ void perror_msg(const char *s, ...) va_start(p, s); /* Guard against "<error message>: Success" */ - verror_msg(s, p, errno ? strerror(errno) : NULL); + verror_msg_helper(s, p, errno ? strerror(errno) : NULL, (logmode | LOGMODE_CUSTOM)); va_end(p); } @@ -122,5 +130,5 @@ void simple_perror_msg(const char *s) void die_out_of_memory(void) { - error_msg_and_die("Out of memory, exiting"); + error_msg_and_die("Out of memory, exiting"); } |
