From b9305465f239d3cd338d0c913b95bdc264f76ea9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Oct 2009 21:34:07 +0100 Subject: Bugzilla: simplifications: remove dead member m_bLoggedIn, use statics Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index d6f6c0c..4ed5946 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -1,3 +1,6 @@ +#include +#include +#include #include "abrtlib.h" #include "Bugzilla.h" @@ -45,7 +48,9 @@ static void throw_if_fault_occurred(xmlrpc_env* e) { if (e->fault_occurred) { - throw CABRTException(EXCEP_PLUGIN, ssprintf("XML-RPC Fault: %s(%d)", e->fault_string, e->fault_code));; + std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", e->fault_string, e->fault_code); + error_msg("%s", errmsg.c_str()); // show error in daemon log + throw CABRTException(EXCEP_PLUGIN, errmsg); } } @@ -85,27 +90,22 @@ static void destroy_xmlrpc_client() CReporterBugzilla::CReporterBugzilla() : m_bNoSSLVerify(false), - m_bLoggedIn(false), m_sBugzillaURL("https://bugzilla.redhat.com"), - m_sBugzillaXMLRPC("https://bugzilla.redhat.com" + std::string(XML_RPC_SUFFIX)) + m_sBugzillaXMLRPC("https://bugzilla.redhat.com"XML_RPC_SUFFIX) {} CReporterBugzilla::~CReporterBugzilla() {} -#if 1 -PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 size) -#else -static PRint32 base64_encode_cb(void *arg, const char* obuff, PRInt32 size) -#endif +static PRInt32 base64_encode_cb(void *arg, const char* obuf, PRInt32 size) { - CReporterBugzilla* bz = static_cast(arg); + std::string& attachment_b64 = *static_cast(arg); int ii; for (ii = 0; ii < size; ii++) { if (isprint(obuf[ii])) { - bz->m_sAttchmentInBase64 += obuf[ii]; + attachment_b64 += obuf[ii]; } } return 1; @@ -285,8 +285,8 @@ static void create_new_bug_description(const map_crash_report_t& pCrashReport, s "\n\nAdditional information\n" "======\n"; - map_crash_report_t::const_iterator it; - for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) + map_crash_report_t::const_iterator it = pCrashReport.begin(); + for (; it != pCrashReport.end(); it++) { if (it->second[CD_TYPE] == CD_TXT) { @@ -400,37 +400,33 @@ static uint32_t new_bug(const map_crash_report_t& pCrashReport) return bug_id; } -void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_crash_report_t& pCrashReport) +static void add_attachments(const std::string& pBugId, const map_crash_report_t& pCrashReport) { - xmlrpc_value* param = NULL; xmlrpc_value* result = NULL; - NSSBase64Encoder* base64 = NULL; - map_crash_report_t::const_iterator it; - for (it = pCrashReport.begin(); it != pCrashReport.end(); it++) + map_crash_report_t::const_iterator it = pCrashReport.begin(); + for (; it != pCrashReport.end(); it++) { if (it->second[CD_TYPE] == CD_ATT) { - m_sAttchmentInBase64 = ""; - base64 = NSSBase64Encoder_Create(Base64Encode_cb, this); + std::string attachment_b64; + NSSBase64Encoder* base64 = NSSBase64Encoder_Create(&base64_encode_cb, &attachment_b64); if (!base64) { - throw CABRTException(EXCEP_PLUGIN, "CReporterBugzilla::AddAttachemnt(): cannot initialize base64."); + error_msg_and_die("cannot initialize base64"); // never happens } - NSSBase64Encoder_Update(base64, reinterpret_cast(it->second[CD_CONTENT].c_str()), it->second[CD_CONTENT].length()); NSSBase64Encoder_Destroy(base64, PR_FALSE); - std::string description = "File: " + it->first; - param = xmlrpc_build_value(&env,"(s{s:s,s:s,s:s,s:s})", + xmlrpc_value* param = xmlrpc_build_value(&env,"(s{s:s,s:s,s:s,s:s})", pBugId.c_str(), "description", description.c_str(), "filename", it->first.c_str(), "contenttype", "text/plain", - "data", m_sAttchmentInBase64.c_str() + "data", attachment_b64.c_str() ); throw_if_fault_occurred(&env); @@ -474,7 +470,7 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co update_client(_("Creating new bug...")); bug_id = new_bug(pCrashReport); - AddAttachments(to_string(bug_id), pCrashReport); + add_attachments(to_string(bug_id), pCrashReport); update_client(_("Logging out...")); logout(); @@ -519,7 +515,7 @@ void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) m_sBugzillaURL.erase(--m_sBugzillaURL.end()); } */ - m_sBugzillaXMLRPC = m_sBugzillaURL + std::string(XML_RPC_SUFFIX); + m_sBugzillaXMLRPC = m_sBugzillaURL + XML_RPC_SUFFIX; } if (pSettings.find("Login") != pSettings.end()) { -- cgit From de73835bdadaf13a7cc5a2f1b08428da3a8e78b6 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 27 Oct 2009 11:50:01 +0100 Subject: simplify base64 conversion text data bss dec hexfilename 39575 2016 288 41879 old/libBugzilla.so 38598 1840 288 40726 new/libBugzilla.so Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 4ed5946..2da3908 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -97,21 +96,6 @@ CReporterBugzilla::CReporterBugzilla() : CReporterBugzilla::~CReporterBugzilla() {} -static PRInt32 base64_encode_cb(void *arg, const char* obuf, PRInt32 size) -{ - std::string& attachment_b64 = *static_cast(arg); - int ii; - for (ii = 0; ii < size; ii++) - { - if (isprint(obuf[ii])) - { - attachment_b64 += obuf[ii]; - } - } - return 1; -} - - static void login(const char* login, const char* passwd) { xmlrpc_value* result = NULL; @@ -409,25 +393,17 @@ static void add_attachments(const std::string& pBugId, const map_crash_report_t& { if (it->second[CD_TYPE] == CD_ATT) { - std::string attachment_b64; - NSSBase64Encoder* base64 = NSSBase64Encoder_Create(&base64_encode_cb, &attachment_b64); - if (!base64) - { - error_msg_and_die("cannot initialize base64"); // never happens - } - NSSBase64Encoder_Update(base64, - reinterpret_cast(it->second[CD_CONTENT].c_str()), - it->second[CD_CONTENT].length()); - NSSBase64Encoder_Destroy(base64, PR_FALSE); - std::string description = "File: " + it->first; + const std::string& to_encode = it->second[CD_CONTENT]; + char *encoded64 = encode_base64(to_encode.c_str(), to_encode.length()); xmlrpc_value* param = xmlrpc_build_value(&env,"(s{s:s,s:s,s:s,s:s})", pBugId.c_str(), "description", description.c_str(), "filename", it->first.c_str(), "contenttype", "text/plain", - "data", attachment_b64.c_str() + "data", encoded64 ); + free(encoded64); throw_if_fault_occurred(&env); xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result); -- cgit From f1931bb8749b3d6f224065e7e60684bb08dfae13 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 27 Oct 2009 12:01:46 +0100 Subject: simplify messags handling text data bss dec hex filename 38598 1840 288 40726 9f16 old/libBugzilla.so 38474 1840 288 40602 9e9a new/libBugzilla.so 37433 2144 24 39601 9ab1 old/libFileTransfer.so 37382 2144 24 39550 9a7e new/libFileTransfer.so Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 2da3908..dcabf1a 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -293,9 +293,8 @@ static void create_new_bug_description(const map_crash_report_t& pCrashReport, s } else if (it->second[CD_TYPE] == CD_BIN) { - char buffer[1024]; - snprintf(buffer, 1024, _("Binary file %s will not be reported."), it->first.c_str()); - warn_client(std::string(buffer)); + std::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.")); } } -- cgit From 2f413d9496ad34caede223ba680e16db868691fa Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 27 Oct 2009 12:08:42 +0100 Subject: remove redundant return after throw Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index dcabf1a..60e4469 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -455,7 +455,6 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co { destroy_xmlrpc_client(); throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Report(): ") + e.what()); - return ""; } destroy_xmlrpc_client(); -- cgit From 3a44ae798e7bdfb692965f562a75383c486913e7 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 27 Oct 2009 12:29:08 +0100 Subject: trivial simplifications by removing redundant initializations Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 60e4469..be81ebc 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -259,7 +259,7 @@ static void create_new_bug_description(const map_crash_report_t& pCrashReport, s } if (pCrashReport.find(CD_COMMENT) != pCrashReport.end()) { - comment = "\n\nComment\n" + comment = "\n\nComment\n" "-----\n" + pCrashReport.find(CD_COMMENT)->second[CD_CONTENT]; } @@ -333,28 +333,23 @@ static void get_product_and_version(const std::string& pRelease, static uint32_t new_bug(const map_crash_report_t& pCrashReport) { - xmlrpc_value* param = NULL; - xmlrpc_value* result = NULL; - xmlrpc_value* id = NULL; - - xmlrpc_int bug_id = -1; - 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 description; - std::string product; - std::string version; std::string summary = "[abrt] crash detected in " + package; std::string status_whiteboard = "abrt_hash:" + uuid; + std::string description; create_new_bug_description(pCrashReport, description); + + std::string product; + std::string version; get_product_and_version(release, product, version); - param = xmlrpc_build_value(&env, "({s:s,s:s,s:s,s:s,s:s,s:s,s:s})", + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s,s:s,s:s,s:s,s:s,s:s,s:s})", "product", product.c_str(), "component", component.c_str(), "version", version.c_str(), @@ -365,12 +360,15 @@ static uint32_t new_bug(const map_crash_report_t& pCrashReport) ); throw_if_fault_occurred(&env); + xmlrpc_value* result; xmlrpc_client_call2(&env, client, server_info, "Bug.create", param, &result); throw_if_fault_occurred(&env); + xmlrpc_value* id; xmlrpc_struct_find_value(&env, result, "id", &id); throw_if_fault_occurred(&env); + xmlrpc_int bug_id = -1; if (id) { xmlrpc_read_int(&env, id, &bug_id); -- cgit