diff options
-rw-r--r-- | inc/CrashTypes.h | 2 | ||||
-rw-r--r-- | lib/Plugins/Bugzilla.conf | 4 | ||||
-rw-r--r-- | lib/Plugins/Bugzilla.cpp | 75 | ||||
-rw-r--r-- | lib/Plugins/Bugzilla.h | 5 |
4 files changed, 81 insertions, 5 deletions
diff --git a/inc/CrashTypes.h b/inc/CrashTypes.h index d53e680..38095b9 100644 --- a/inc/CrashTypes.h +++ b/inc/CrashTypes.h @@ -6,7 +6,7 @@ #include <vector> // SYS - system value, should not be displayed -// BIN - binary value, should be displayed +// BIN - binary value, should be displayed as a path to binary file // TXT - text value, should be displayed // ATT - text value which can be sent as attachment via reporters #define CD_SYS "s" diff --git a/lib/Plugins/Bugzilla.conf b/lib/Plugins/Bugzilla.conf index 24cc566..24947fe 100644 --- a/lib/Plugins/Bugzilla.conf +++ b/lib/Plugins/Bugzilla.conf @@ -1,5 +1,5 @@ -# Bugzila URL -BugzilaURL = https://bugzilla.redhat.com/xmlrpc.cgi +# Bugzilla URL +BugzillaURL = https://bugzilla.redhat.com/xmlrpc.cgi # your login has to exist, if you don have anyone, please create one Login = # your password diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 3671ac8..8ad28cf 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -6,6 +6,7 @@ #include "ABRTException.h" #include "CommLayerInner.h" #include <sstream> +#include <string.h> CReporterBugzilla::CReporterBugzilla() : m_sBugzillaURL("https://bugzilla.redhat.com/xmlrpc.cgi") @@ -22,6 +23,14 @@ CReporterBugzilla::~CReporterBugzilla() delete m_pCarriageParm; } +PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 size) +{ + CReporterBugzilla* bz = static_cast<CReporterBugzilla*>(arg); + bz->m_sAttchmentInBase64 += obuf; + return 1; +} + + void CReporterBugzilla::Login() { xmlrpc_c::paramList paramList; @@ -101,7 +110,7 @@ void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrash map_crash_report_t::const_iterator it; for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) { - if (it->second[CD_TYPE] == CD_TXT || it->second[CD_TYPE] == CD_ATT) + if (it->second[CD_TYPE] == CD_TXT) { if (it->first != CD_UUID && it->first != FILENAME_ARCHITECTURE && @@ -109,11 +118,22 @@ void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrash it->first != CD_REPRODUCE && it->first != CD_COMMENT) { - pDescription += it->first + "\n"; + pDescription += "\n" + it->first + "\n"; pDescription += "-----\n"; pDescription += it->second[CD_CONTENT] + "\n\n"; } } + else if (it->second[CD_TYPE] == CD_ATT) + { + pDescription += "\n\nAttached files\n" + "----\n"; + pDescription += it->first + "\n"; + } + else if (it->second[CD_TYPE] == CD_BIN) + { + comm_layer_inner_warning("Binary file "+it->first+" will not be reported."); + comm_layer_inner_status("Binary file "+it->first+" will not be reported."); + } } } @@ -166,6 +186,7 @@ void CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) bugParams["product"] = xmlrpc_c::value_string(product); bugParams["component"] = xmlrpc_c::value_string(component); bugParams["version"] = xmlrpc_c::value_string(version); + //bugParams["op_sys"] = xmlrpc_c::value_string("Linux"); bugParams["summary"] = xmlrpc_c::value_string("[abrt] crash detected in " + component); bugParams["description"] = xmlrpc_c::value_string(description); bugParams["status_whiteboard"] = xmlrpc_c::value_string("abrt_hash:" + pCrashReport.find(CD_UUID)->second[CD_CONTENT]); @@ -180,6 +201,7 @@ void CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) std::stringstream ss; ss << xmlrpc_c::value_int(ret["id"]); comm_layer_inner_debug("New bug id: " + ss.str()); + AddAttachments(ss.str(), pCrashReport); } catch (std::exception& e) { @@ -188,6 +210,55 @@ void CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) } +void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_crash_report_t& pCrashReport) +{ + xmlrpc_c::paramList paramList; + map_xmlrpc_params_t attachmentParams; + std::vector<xmlrpc_c::value> ret; + NSSBase64Encoder* base64; + std::string::size_type pos; + + map_crash_report_t::const_iterator it; + for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) + { + if (it->second[CD_TYPE] == CD_ATT) + { + base64 = NSSBase64Encoder_Create(Base64Encode_cb, this); + NSSBase64Encoder_Update(base64, + reinterpret_cast<const unsigned char*>(it->second[CD_CONTENT].c_str()), + it->second[CD_CONTENT].length()); + NSSBase64Encoder_Destroy(base64, PR_FALSE); + std::string attchmentInBase64Printable = ""; + for(unsigned int ii = 0; ii < m_sAttchmentInBase64.length(); ii++) + { + if (isprint(m_sAttchmentInBase64[ii])) + { + attchmentInBase64Printable += m_sAttchmentInBase64[ii]; + } + } + paramList.add(xmlrpc_c::value_string(pBugId)); + attachmentParams["description"] = xmlrpc_c::value_string("File: " + it->first); + attachmentParams["filename"] = xmlrpc_c::value_string(it->first); + attachmentParams["contenttype"] = xmlrpc_c::value_string("text/plain"); + attachmentParams["data"] = xmlrpc_c::value_string(attchmentInBase64Printable); + paramList.add(xmlrpc_c::value_struct(attachmentParams)); + xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("bugzilla.addAttachment", paramList)); + try + { + rpc->call(m_pXmlrpcClient, m_pCarriageParm); + ret = xmlrpc_c::value_array(rpc->getResult()).vectorValueValue(); + std::stringstream ss; + ss << xmlrpc_c::value_int(ret[0]); + comm_layer_inner_debug("New attachment id: " + ss.str()); + } + catch (std::exception& e) + { + throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::AddAttachemnt(): ") + e.what()); + } + } + } +} + void CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) { std::string package = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; diff --git a/lib/Plugins/Bugzilla.h b/lib/Plugins/Bugzilla.h index 075484a..cd2d5cd 100644 --- a/lib/Plugins/Bugzilla.h +++ b/lib/Plugins/Bugzilla.h @@ -5,15 +5,19 @@ #include "Reporter.h" #include <xmlrpc-c/client.hpp> +#include <nssb64.h> + class CReporterBugzilla : public CReporter { private: typedef std::map<std::string, xmlrpc_c::value> map_xmlrpc_params_t; + static PRInt32 Base64Encode_cb(void *arg, const char *obuf, PRInt32 size); void Login(); void Logout(); bool CheckUUIDInBugzilla(const std::string& pComponent, const std::string& pUUID); void NewBug(const map_crash_report_t& pCrashReport); + void AddAttachments(const std::string& pBugId, const map_crash_report_t& pCrashReport); void CreateNewBugDescription(const map_crash_report_t& pCrashReport, std::string& pDescription); void GetProductAndVersion(const std::string& pRelease, @@ -26,6 +30,7 @@ class CReporterBugzilla : public CReporter std::string m_sBugzillaURL; std::string m_sLogin; std::string m_sPassword; + std::string m_sAttchmentInBase64; public: CReporterBugzilla(); |