From 05af2c6ad9e43bf530435694a7f7e81d6b22fe3c Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Fri, 9 Oct 2009 15:57:06 +0200 Subject: start rewriting login and check uuid from xmlrpc++ to xmlrpc --- lib/Plugins/Bugzilla.cpp | 197 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 160 insertions(+), 37 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 48c5eb5..62c2991 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -1,5 +1,5 @@ -#include +//#include #include "abrtlib.h" #include "Bugzilla.h" #include "CrashTypes.h" @@ -7,12 +7,75 @@ #include "ABRTException.h" #include "CommLayerInner.h" + +#ifdef HAVE_CONFIG_H + #include +#endif + #define XML_RPC_SUFFIX "/xmlrpc.cgi" +#define C_I 1 + +static xmlrpc_env env; +static xmlrpc_client* client = NULL; +static struct xmlrpc_clientparms clientParms; +static struct xmlrpc_curl_xportparms curlParms; +static xmlrpc_server_info* server_info = NULL; + + +static void throw_if_fault_occurred(xmlrpc_env* const env); + +static void new_xmlrpc_client(const char* url, bool no_ssl_verify); +static void destroy_xmlrpc_client(); + + + + +static void throw_if_fault_occurred(xmlrpc_env* const env) +{ + if (env->fault_occurred) + { + char buffer[2048]; + snprintf(buffer, 2047, "XML-RPC Fault: %s(%d)\n", env->fault_string, env->fault_code); + throw CABRTException(EXCEP_PLUGIN, std::string(buffer)); + } +} + +static void new_xmlrpc_client(const char* url, bool no_ssl_verify) +{ + xmlrpc_env_init(&env); + xmlrpc_client_setup_global_const(&env); + + curlParms.network_interface = NULL; + curlParms.no_ssl_verifypeer = no_ssl_verify; + curlParms.no_ssl_verifyhost = no_ssl_verify; +#ifdef VERSION + curlParms.user_agent = PACKAGE_NAME"/"VERSION; +#else + curlParms.user_agent = "abrt"; +#endif + + clientParms.transport = "curl"; + clientParms.transportparmsP = &curlParms; + clientParms.transportparm_size = XMLRPC_CXPSIZE(user_agent); + + xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, PACKAGE_NAME, VERSION, &clientParms, XMLRPC_CPSIZE(transportparm_size), + &client); + throw_if_fault_occurred(&env); + + server_info = xmlrpc_server_info_new(&env, url); + throw_if_fault_occurred(&env); +} + +static void destroy_xmlrpc_client() +{ + xmlrpc_server_info_free(server_info); + xmlrpc_env_clean(&env); + xmlrpc_client_destroy(client); + xmlrpc_client_teardown_global_const(); +} + CReporterBugzilla::CReporterBugzilla() : - m_pXmlrpcTransport(NULL), - m_pXmlrpcClient(NULL), - m_pCarriageParm(NULL), m_sBugzillaURL("https://bugzilla.redhat.com"), m_sBugzillaXMLRPC("https://bugzilla.redhat.com" + std::string(XML_RPC_SUFFIX)), m_bNoSSLVerify(false), @@ -24,6 +87,7 @@ CReporterBugzilla::~CReporterBugzilla() void CReporterBugzilla::NewXMLRPCClient() { +/* m_pXmlrpcTransport = new xmlrpc_c::clientXmlTransport_curl( xmlrpc_c::clientXmlTransport_curl::constrOpt() .no_ssl_verifyhost(m_bNoSSLVerify) @@ -31,10 +95,13 @@ void CReporterBugzilla::NewXMLRPCClient() ); m_pXmlrpcClient = new xmlrpc_c::client_xml(m_pXmlrpcTransport); m_pCarriageParm = new xmlrpc_c::carriageParm_curl0(m_sBugzillaXMLRPC); +*/ } void CReporterBugzilla::DeleteXMLRPCClient() { + +/* if (m_pCarriageParm != NULL) { delete m_pCarriageParm; @@ -50,6 +117,7 @@ void CReporterBugzilla::DeleteXMLRPCClient() delete m_pXmlrpcTransport; m_pXmlrpcTransport = NULL; } +*/ } PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 size) @@ -66,8 +134,20 @@ PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 return 1; } -void CReporterBugzilla::Login() +void CReporterBugzilla::Login(const char* login, const char* passwd) { + new_xmlrpc_client(m_sBugzillaXMLRPC.c_str(), m_bNoSSLVerify); + xmlrpc_value* result; + + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); + throw_if_fault_occurred(&env); + + xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); + throw_if_fault_occurred(&env); + + destroy_xmlrpc_client(); + + /* xmlrpc_c::paramList paramList; map_xmlrpc_params_t loginParams; map_xmlrpc_params_t ret; @@ -96,10 +176,12 @@ void CReporterBugzilla::Login() { throw CABRTException(EXCEP_PLUGIN, s); } + */ } void CReporterBugzilla::Logout() { + /* xmlrpc_c::paramList paramList; paramList.add(xmlrpc_c::value_string("")); xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("User.logout", paramList)); @@ -111,10 +193,12 @@ void CReporterBugzilla::Logout() { throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Logout(): ") + e.what()); } + */ } bool CReporterBugzilla::CheckCCAndReporter(const std::string& pBugId) { + /* xmlrpc_c::paramList paramList; map_xmlrpc_params_t ret; @@ -145,10 +229,12 @@ bool CReporterBugzilla::CheckCCAndReporter(const std::string& pBugId) } } return false; + */ } void CReporterBugzilla::AddPlusOneCC(const std::string& pBugId) { + /* xmlrpc_c::paramList paramList; map_xmlrpc_params_t addCCParams; map_xmlrpc_params_t ret; @@ -172,45 +258,70 @@ void CReporterBugzilla::AddPlusOneCC(const std::string& pBugId) throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::AddPlusOneComment(): ") + e.what()); } ret = xmlrpc_c::value_struct(rpc->getResult()); + */ } std::string CReporterBugzilla::CheckUUIDInBugzilla(const std::string& pComponent, const std::string& pUUID) { - xmlrpc_c::paramList paramList; - map_xmlrpc_params_t searchParams; - map_xmlrpc_params_t ret; - std::string quicksearch = "ALL component:\""+ pComponent +"\" statuswhiteboard:\""+ pUUID + "\""; - searchParams["quicksearch"] = xmlrpc_c::value_string(quicksearch.c_str()); - paramList.add(xmlrpc_c::value_struct(searchParams)); - xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("Bug.search", paramList)); - try - { - rpc->call(m_pXmlrpcClient, m_pCarriageParm); - } - catch (std::exception& e) - { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::CheckUUIDInBugzilla(): ") + e.what()); - } - ret = xmlrpc_c::value_struct(rpc->getResult()); - std::vector bugs = xmlrpc_c::value_array(ret["bugs"]).vectorValueValue(); - if (bugs.size() > 0) + + xmlrpc_value* result = NULL; + xmlrpc_value* bugs_member = NULL; + xmlrpc_int bug_id; + + char component[1024]; + snprintf(component, 1023, "ALL component:\"%s\" statuswhiteboard:\"%s\"", pComponent.c_str(), pUUID.c_str()); + + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", component); + throw_if_fault_occurred(&env); + + xmlrpc_client_call2(&env, client, server_info, "Bug.search", param, &result); + throw_if_fault_occurred(&env); + + xmlrpc_struct_find_value(&env, result, "bugs", &bugs_member); + throw_if_fault_occurred(&env); + + if (bugs_member) { - map_xmlrpc_params_t bug; - std::stringstream ss; + uint32_t array_size = xmlrpc_array_size(&env, bugs_member); + throw_if_fault_occurred(&env); - bug = xmlrpc_c::value_struct(bugs[0]); - ss << xmlrpc_c::value_int(bug["bug_id"]); + xmlrpc_value* item = NULL; + xmlrpc_array_read_item(&env, bugs_member, 0, &item); // Correct + throw_if_fault_occurred(&env); - log("Bug is already reported: %s", ss.str().c_str()); - update_client(_("Bug is already reported: ") + ss.str()); + xmlrpc_value* bug = NULL; + xmlrpc_struct_find_value(&env, item,"bug_id", &bug); + throw_if_fault_occurred(&env); + if (bug) + { + xmlrpc_read_int(&env, bug, &bug_id); + log("Bug is already reported: %i", bug_id); + update_client(_("Bug is already reported: ") + to_string(bug_id)); + + xmlrpc_DECREF(param); + xmlrpc_DECREF(bugs_member); + xmlrpc_DECREF(result); + return to_string(bug_id); + } + else + { + std::cout << "There is no member named 'bug_id'" << std::endl; + } - return ss.str(); } + else + { + std::cout << "There is no member named 'bugs'" << std::endl; + } + xmlrpc_DECREF(param); + xmlrpc_DECREF(bugs_member); + xmlrpc_DECREF(result); return ""; } void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrashReport, std::string& pDescription) { + /* std::string howToReproduce; std::string comment; @@ -262,12 +373,14 @@ void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrash //update_client(_("Binary file ")+it->first+_(" will not be reported.")); } } + */ } void CReporterBugzilla::GetProductAndVersion(const std::string& pRelease, std::string& pProduct, std::string& pVersion) { + /* if (pRelease.find("Rawhide") != std::string::npos) { pProduct = "Fedora"; @@ -293,10 +406,12 @@ void CReporterBugzilla::GetProductAndVersion(const std::string& pRelease, } pos++; } + */ } std::string CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) { + /* xmlrpc_c::paramList paramList; map_xmlrpc_params_t bugParams; map_xmlrpc_params_t ret; @@ -334,10 +449,12 @@ std::string CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::NewBug(): ") + e.what()); } return bugId.str(); + */ } void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_crash_report_t& pCrashReport) { + /* xmlrpc_c::paramList paramList; map_xmlrpc_params_t attachmentParams; std::vector ret; @@ -381,6 +498,7 @@ void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_cras } } } + */ } std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) @@ -391,17 +509,21 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co std::string bugId; - NewXMLRPCClient(); m_bLoggedIn = false; try { + new_xmlrpc_client(m_sBugzillaXMLRPC.c_str(), m_bNoSSLVerify); + // NewXMLRPCClient(); update_client(_("Checking for duplicates...")); bugId = CheckUUIDInBugzilla(component, uuid); + if ( bugId != "" ) { update_client(_("Logging into bugzilla...")); - Login(); + Login(m_sLogin.c_str(), m_sPassword.c_str()); m_bLoggedIn = true; + } +/* update_client(_("Checking CC...")); if (!CheckCCAndReporter(bugId) && m_bLoggedIn) { @@ -413,15 +535,16 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co update_client(_("Logging into bugzilla...")); Login(); m_bLoggedIn = true; +*/ } catch (CABRTException& e) { - DeleteXMLRPCClient(); + destroy_xmlrpc_client(); throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Report(): ") + e.what()); return ""; } - +/* update_client(_("Creating new bug...")); try { @@ -435,9 +558,9 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co DeleteXMLRPCClient(); throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Report(): ") + e.what()); } - - - DeleteXMLRPCClient(); +*/ + destroy_xmlrpc_client(); +// DeleteXMLRPCClient(); return m_sBugzillaURL + "/show_bug.cgi?id=" + bugId; } -- cgit From 0f4e6e5f5fc53be8cc2871abb7c1b7e66db6925c Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Thu, 22 Oct 2009 14:27:29 +0200 Subject: rewritten check_uuid, login, check_cc_and_reporter and add_plus_one_cc --- lib/Plugins/Bugzilla.cpp | 308 ++++++++++++++++++----------------------------- 1 file changed, 114 insertions(+), 194 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 62c2991..a16f74f 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -14,8 +14,6 @@ #define XML_RPC_SUFFIX "/xmlrpc.cgi" -#define C_I 1 - static xmlrpc_env env; static xmlrpc_client* client = NULL; static struct xmlrpc_clientparms clientParms; @@ -23,23 +21,23 @@ static struct xmlrpc_curl_xportparms curlParms; static xmlrpc_server_info* server_info = NULL; -static void throw_if_fault_occurred(xmlrpc_env* const env); - static void new_xmlrpc_client(const char* url, bool no_ssl_verify); static void destroy_xmlrpc_client(); - - - - -static void throw_if_fault_occurred(xmlrpc_env* const env) -{ - if (env->fault_occurred) - { - char buffer[2048]; - snprintf(buffer, 2047, "XML-RPC Fault: %s(%d)\n", env->fault_string, env->fault_code); - throw CABRTException(EXCEP_PLUGIN, std::string(buffer)); - } -} +static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID); +static bool check_cc_and_reporter(const uint32_t bug_id, const char* login); +static void add_plus_one_cc(const uint32_t bug_id, const char* login); + +#define throw_if_fault_occurred(env) \ +do \ +{ \ + xmlrpc_env* e = (env); \ + if (e->fault_occurred) \ + { \ + char buffer[2048]; \ + snprintf(buffer, 2047, "XML-RPC Fault: %s(%d)", e->fault_string, e->fault_code); \ + throw CABRTException(EXCEP_PLUGIN, std::string(buffer)); \ + } \ +}while(0) static void new_xmlrpc_client(const char* url, bool no_ssl_verify) { @@ -85,43 +83,9 @@ CReporterBugzilla::CReporterBugzilla() : CReporterBugzilla::~CReporterBugzilla() {} -void CReporterBugzilla::NewXMLRPCClient() -{ -/* - m_pXmlrpcTransport = new xmlrpc_c::clientXmlTransport_curl( - xmlrpc_c::clientXmlTransport_curl::constrOpt() - .no_ssl_verifyhost(m_bNoSSLVerify) - .no_ssl_verifypeer(m_bNoSSLVerify) - ); - m_pXmlrpcClient = new xmlrpc_c::client_xml(m_pXmlrpcTransport); - m_pCarriageParm = new xmlrpc_c::carriageParm_curl0(m_sBugzillaXMLRPC); -*/ -} - -void CReporterBugzilla::DeleteXMLRPCClient() -{ - -/* - if (m_pCarriageParm != NULL) - { - delete m_pCarriageParm; - m_pCarriageParm = NULL; - } - if (m_pXmlrpcClient != NULL) - { - delete m_pXmlrpcClient; - m_pXmlrpcClient = NULL; - } - if (m_pXmlrpcTransport != NULL) - { - delete m_pXmlrpcTransport; - m_pXmlrpcTransport = NULL; - } -*/ -} - PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 size) { + /* CReporterBugzilla* bz = static_cast(arg); int ii; for (ii = 0; ii < size; ii++) @@ -131,12 +95,13 @@ PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 bz->m_sAttchmentInBase64 += obuf[ii]; } } + */ return 1; } -void CReporterBugzilla::Login(const char* login, const char* passwd) + +static void login(const char* login, const char* passwd) { - new_xmlrpc_client(m_sBugzillaXMLRPC.c_str(), m_bNoSSLVerify); xmlrpc_value* result; xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); @@ -144,39 +109,6 @@ void CReporterBugzilla::Login(const char* login, const char* passwd) xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); throw_if_fault_occurred(&env); - - destroy_xmlrpc_client(); - - /* - xmlrpc_c::paramList paramList; - map_xmlrpc_params_t loginParams; - map_xmlrpc_params_t ret; - loginParams["login"] = xmlrpc_c::value_string(m_sLogin); - loginParams["password"] = xmlrpc_c::value_string(m_sPassword); - paramList.add(xmlrpc_c::value_struct(loginParams)); - xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("User.login", paramList)); - try - { - if( (m_sLogin == "") && (m_sPassword=="") ) - { - log("Empty login and password"); - throw std::string(_("Empty login and password. Please check Bugzilla.conf")); - } - rpc->call(m_pXmlrpcClient, m_pCarriageParm); - ret = xmlrpc_c::value_struct(rpc->getResult()); - std::stringstream ss; - ss << xmlrpc_c::value_int(ret["id"]); - log("Login id: %s", ss.str().c_str()); - } - catch (std::exception& e) - { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Login(): ") + e.what()); - } - catch (std::string& s) - { - throw CABRTException(EXCEP_PLUGIN, s); - } - */ } void CReporterBugzilla::Logout() @@ -196,82 +128,93 @@ void CReporterBugzilla::Logout() */ } -bool CReporterBugzilla::CheckCCAndReporter(const std::string& pBugId) +static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) { - /* - xmlrpc_c::paramList paramList; - map_xmlrpc_params_t ret; + xmlrpc_value* param = NULL; + xmlrpc_value* result = NULL; + xmlrpc_value* reporter_member = NULL; + xmlrpc_value* cc_member = NULL; - paramList.add(xmlrpc_c::value_string(pBugId)); - xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("bugzilla.getBug", paramList)); - try - { - rpc->call(m_pXmlrpcClient, m_pCarriageParm); - ret = xmlrpc_c::value_struct(rpc->getResult()); - } - catch (std::exception& e) - { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::CheckCCAndReporter(): ") + e.what()); - } - std::string reporter = xmlrpc_c::value_string(ret["reporter"]); - if (reporter == m_sLogin) + const char* bug = to_string(bug_id).c_str(); + + param = xmlrpc_build_value(&env, "(s)", bug); + throw_if_fault_occurred(&env); + + xmlrpc_client_call2(&env, client, server_info, "bugzilla.getBug", param, &result); + throw_if_fault_occurred(&env); + + xmlrpc_struct_find_value(&env, result, "reporter", &reporter_member); + throw_if_fault_occurred(&env); + + if (reporter_member) { - return true; + const char* reporter = NULL; + xmlrpc_read_string(&env, reporter_member, &reporter); + throw_if_fault_occurred(&env); + + if (strcmp(reporter, login) == 0 ) + { + std::cout << "reporter=login" << std::endl; + return true; + } } - std::vector ccs = xmlrpc_c::value_array(ret["cc"]).vectorValueValue(); - int ii; - for (ii = 0; ii < ccs.size(); ii++) + + xmlrpc_struct_find_value(&env, result, "cc", &cc_member); + throw_if_fault_occurred(&env); + + if (cc_member) { - std::string cc = xmlrpc_c::value_string(ccs[ii]); - if (cc == m_sLogin) + xmlrpc_value* item = NULL; + uint32_t array_size = xmlrpc_array_size(&env, cc_member); + + for (uint32_t i = 0; i < array_size; i++) { - return true; + xmlrpc_array_read_item(&env, cc_member, i, &item); // Correct + throw_if_fault_occurred(&env); + + const char* cc = NULL; + xmlrpc_read_string(&env, item, &cc); + throw_if_fault_occurred(&env); + + if (strcmp(cc, login) == 0) + { + std::cout << "cc=login" << std::endl; + return true; + } } } + + xmlrpc_DECREF(result); return false; - */ } -void CReporterBugzilla::AddPlusOneCC(const std::string& pBugId) +static void add_plus_one_cc(const uint32_t bug_id, const char* login) { - /* - xmlrpc_c::paramList paramList; - map_xmlrpc_params_t addCCParams; - map_xmlrpc_params_t ret; - map_xmlrpc_params_t updates; + xmlrpc_value* param = NULL; + xmlrpc_value* result = NULL; - std::vector CCList; - CCList.push_back(xmlrpc_c::value_string(m_sLogin)); - updates["add_cc"] = xmlrpc_c::value_array(CCList); + param = xmlrpc_build_value(&env, "({s:i,s:{s:(s)}})", "ids", bug_id, "updates", "add_cc", login); + throw_if_fault_occurred(&env); - addCCParams["ids"] = xmlrpc_c::value_int(atoi(pBugId.c_str())); - addCCParams["updates"] = xmlrpc_c::value_struct(updates); + xmlrpc_client_call2(&env, client, server_info, "Bug.update", param, &result); + throw_if_fault_occurred(&env); + + xmlrpc_DECREF(result); - paramList.add(xmlrpc_c::value_struct(addCCParams)); - xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("Bug.update", paramList)); - try - { - rpc->call(m_pXmlrpcClient, m_pCarriageParm); - } - catch (std::exception& e) - { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::AddPlusOneComment(): ") + e.what()); - } - ret = xmlrpc_c::value_struct(rpc->getResult()); - */ } -std::string CReporterBugzilla::CheckUUIDInBugzilla(const std::string& pComponent, const std::string& pUUID) +static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) { - + xmlrpc_value* param = NULL; xmlrpc_value* result = NULL; xmlrpc_value* bugs_member = NULL; + xmlrpc_int bug_id; - char component[1024]; - snprintf(component, 1023, "ALL component:\"%s\" statuswhiteboard:\"%s\"", pComponent.c_str(), pUUID.c_str()); + char query[1024]; + snprintf(query, 1023, "ALL component:\"%s\" statuswhiteboard:\"%s\"", component, UUID); - xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", component); + param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", query); throw_if_fault_occurred(&env); xmlrpc_client_call2(&env, client, server_info, "Bug.search", param, &result); @@ -282,8 +225,11 @@ std::string CReporterBugzilla::CheckUUIDInBugzilla(const std::string& pComponent if (bugs_member) { + // when array size is equal 0 that means no bug reportet uint32_t array_size = xmlrpc_array_size(&env, bugs_member); throw_if_fault_occurred(&env); + if( array_size == 0 ) + return -1; xmlrpc_value* item = NULL; xmlrpc_array_read_item(&env, bugs_member, 0, &item); // Correct @@ -297,26 +243,17 @@ std::string CReporterBugzilla::CheckUUIDInBugzilla(const std::string& pComponent xmlrpc_read_int(&env, bug, &bug_id); log("Bug is already reported: %i", bug_id); update_client(_("Bug is already reported: ") + to_string(bug_id)); - - xmlrpc_DECREF(param); - xmlrpc_DECREF(bugs_member); xmlrpc_DECREF(result); - return to_string(bug_id); - } - else - { - std::cout << "There is no member named 'bug_id'" << std::endl; + xmlrpc_DECREF(bug); + xmlrpc_DECREF(item); + xmlrpc_DECREF(bugs_member); + return bug_id; } - } - else - { - std::cout << "There is no member named 'bugs'" << std::endl; - } - xmlrpc_DECREF(param); - xmlrpc_DECREF(bugs_member); + xmlrpc_DECREF(result); - return ""; + xmlrpc_DECREF(bugs_member); + return -1; } void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrashReport, std::string& pDescription) @@ -503,39 +440,34 @@ void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_cras std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) { - std::string package = pCrashReport.find(FILENAME_PACKAGE)->second[CD_CONTENT]; + int32_t bug_id = -1; + std::string component = pCrashReport.find(FILENAME_COMPONENT)->second[CD_CONTENT]; std::string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; - std::string bugId; - - - - m_bLoggedIn = false; try { new_xmlrpc_client(m_sBugzillaXMLRPC.c_str(), m_bNoSSLVerify); - // NewXMLRPCClient(); - update_client(_("Checking for duplicates...")); - bugId = CheckUUIDInBugzilla(component, uuid); - if ( bugId != "" ) { + update_client(_("Checking for duplicates...")); + bug_id = check_uuid_in_bugzilla(component.c_str(), uuid.c_str()); + if (bug_id > 0) + { update_client(_("Logging into bugzilla...")); - Login(m_sLogin.c_str(), m_sPassword.c_str()); - m_bLoggedIn = true; - } -/* + if ((m_sLogin == "") && (m_sPassword=="")) + { + VERB3 log("Empty login and password"); + throw CABRTException(EXCEP_PLUGIN, std::string(_("Empty login and password. Please check Bugzilla.conf"))); + } + login(m_sLogin.c_str(), m_sPassword.c_str()); + update_client(_("Checking CC...")); - if (!CheckCCAndReporter(bugId) && m_bLoggedIn) + if (!check_cc_and_reporter(bug_id, m_sLogin.c_str())) { - AddPlusOneCC(bugId); + add_plus_one_cc(bug_id, m_sLogin.c_str()); } - DeleteXMLRPCClient(); - return m_sBugzillaURL + "/show_bug.cgi?id=" + bugId; + destroy_xmlrpc_client(); + return m_sBugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); } - update_client(_("Logging into bugzilla...")); - Login(); - m_bLoggedIn = true; -*/ } catch (CABRTException& e) { @@ -543,26 +475,14 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Report(): ") + e.what()); return ""; } + destroy_xmlrpc_client(); -/* - update_client(_("Creating new bug...")); - try - { - bugId = NewBug(pCrashReport); - AddAttachments(bugId, pCrashReport); - update_client(_("Logging out...")); - Logout(); - } - catch (CABRTException& e) + if (bug_id > 0) { - DeleteXMLRPCClient(); - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Report(): ") + e.what()); + return m_sBugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); } -*/ - destroy_xmlrpc_client(); -// DeleteXMLRPCClient(); - return m_sBugzillaURL + "/show_bug.cgi?id=" + bugId; + return m_sBugzillaURL + "/show_bug.cgi?id="; } void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) -- cgit From 65869764558afc330f9ba0227032d49b9b676e27 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Mon, 26 Oct 2009 15:20:03 +0100 Subject: New insides in bugzilla.{cpp/h}. Hole xmlrpc protocol was rewritten into C. --- lib/Plugins/Bugzilla.cpp | 213 +++++++++++++++++++++++++---------------------- 1 file changed, 114 insertions(+), 99 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index a16f74f..55ce62e 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -1,5 +1,4 @@ -//#include #include "abrtlib.h" #include "Bugzilla.h" #include "CrashTypes.h" @@ -21,12 +20,27 @@ static struct xmlrpc_curl_xportparms curlParms; static xmlrpc_server_info* server_info = NULL; +static void login(const char* login, const char* passwd); + +static void logout(); + static void new_xmlrpc_client(const char* url, bool no_ssl_verify); + static void destroy_xmlrpc_client(); + static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID); + static bool check_cc_and_reporter(const uint32_t bug_id, const char* login); + static void add_plus_one_cc(const uint32_t bug_id, const char* login); +static void create_new_bug_description(const map_crash_report_t& pCrashReport, std::string& pDescription); + +static void get_product_and_version(const std::string& pRelease, + std::string& pProduct, + std::string& pVersion); + + #define throw_if_fault_occurred(env) \ do \ { \ @@ -83,9 +97,12 @@ CReporterBugzilla::CReporterBugzilla() : 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 { - /* CReporterBugzilla* bz = static_cast(arg); int ii; for (ii = 0; ii < size; ii++) @@ -95,37 +112,32 @@ PRInt32 CReporterBugzilla::Base64Encode_cb(void *arg, const char *obuf, PRInt32 bz->m_sAttchmentInBase64 += obuf[ii]; } } - */ return 1; } static void login(const char* login, const char* passwd) { - xmlrpc_value* result; + xmlrpc_value* result = NULL; + xmlrpc_value* param = NULL; - xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); + param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); throw_if_fault_occurred(&env); xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); throw_if_fault_occurred(&env); } -void CReporterBugzilla::Logout() +static void logout() { - /* - xmlrpc_c::paramList paramList; - paramList.add(xmlrpc_c::value_string("")); - xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("User.logout", paramList)); - try - { - rpc->call(m_pXmlrpcClient, m_pCarriageParm); - } - catch (std::exception& e) - { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Logout(): ") + e.what()); - } - */ + xmlrpc_value* result = NULL; + xmlrpc_value* param = NULL; + + param = xmlrpc_build_value(&env, "(s)", ""); + throw_if_fault_occurred(&env); + + xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result); + throw_if_fault_occurred(&env); } static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) @@ -154,7 +166,6 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) if (strcmp(reporter, login) == 0 ) { - std::cout << "reporter=login" << std::endl; return true; } } @@ -178,7 +189,6 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) if (strcmp(cc, login) == 0) { - std::cout << "cc=login" << std::endl; return true; } } @@ -200,7 +210,6 @@ static void add_plus_one_cc(const uint32_t bug_id, const char* login) throw_if_fault_occurred(&env); xmlrpc_DECREF(result); - } static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) @@ -225,7 +234,7 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) if (bugs_member) { - // when array size is equal 0 that means no bug reportet + // when array size is equal 0 that means no bug reported uint32_t array_size = xmlrpc_array_size(&env, bugs_member); throw_if_fault_occurred(&env); if( array_size == 0 ) @@ -243,6 +252,7 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) xmlrpc_read_int(&env, bug, &bug_id); log("Bug is already reported: %i", bug_id); update_client(_("Bug is already reported: ") + to_string(bug_id)); + xmlrpc_DECREF(result); xmlrpc_DECREF(bug); xmlrpc_DECREF(item); @@ -256,9 +266,8 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) return -1; } -void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrashReport, std::string& pDescription) +static void create_new_bug_description(const map_crash_report_t& pCrashReport, std::string& pDescription) { - /* std::string howToReproduce; std::string comment; @@ -310,14 +319,12 @@ void CReporterBugzilla::CreateNewBugDescription(const map_crash_report_t& pCrash //update_client(_("Binary file ")+it->first+_(" will not be reported.")); } } - */ } -void CReporterBugzilla::GetProductAndVersion(const std::string& pRelease, - std::string& pProduct, - std::string& pVersion) +static void get_product_and_version(const std::string& pRelease, + std::string& pProduct, + std::string& pVersion) { - /* if (pRelease.find("Rawhide") != std::string::npos) { pProduct = "Fedora"; @@ -343,59 +350,65 @@ void CReporterBugzilla::GetProductAndVersion(const std::string& pRelease, } pos++; } - */ } -std::string CReporterBugzilla::NewBug(const map_crash_report_t& pCrashReport) +static uint32_t new_bug(const map_crash_report_t& pCrashReport) { - /* - xmlrpc_c::paramList paramList; - map_xmlrpc_params_t bugParams; - map_xmlrpc_params_t ret; + 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 release = pCrashReport.find(FILENAME_RELEASE)->second[CD_CONTENT];; std::string product; std::string version; - std::stringstream bugId; - CreateNewBugDescription(pCrashReport, description); - GetProductAndVersion(release, product, version); - - 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 " + package); - bugParams["description"] = xmlrpc_c::value_string(description); - bugParams["status_whiteboard"] = xmlrpc_c::value_string("abrt_hash:" + pCrashReport.find(CD_UUID)->second[CD_CONTENT]); - bugParams["platform"] = xmlrpc_c::value_string(pCrashReport.find(FILENAME_ARCHITECTURE)->second[CD_CONTENT]); - paramList.add(xmlrpc_c::value_struct(bugParams)); - - xmlrpc_c::rpcPtr rpc(new xmlrpc_c::rpc("Bug.create", paramList)); - try - { - rpc->call(m_pXmlrpcClient, m_pCarriageParm); - ret = xmlrpc_c::value_struct(rpc->getResult()); - bugId << xmlrpc_c::value_int(ret["id"]); - log("New bug id: %s", bugId.str().c_str()); - update_client(_("New bug id: ") + bugId.str()); - } - catch (std::exception& e) + std::string summary = "[abrt] crash detected in " + package; + std::string status_whiteboard = "abrt_hash:" + uuid; + + create_new_bug_description(pCrashReport, description); + 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})", + "product", product.c_str(), + "component", component.c_str(), + "version", version.c_str(), + "summary", summary.c_str(), + "description", description.c_str(), + "status_whiteboard", status_whiteboard.c_str(), + "platform", arch.c_str() + ); + throw_if_fault_occurred(&env); + + xmlrpc_client_call2(&env, client, server_info, "Bug.create", param, &result); + throw_if_fault_occurred(&env); + + xmlrpc_struct_find_value(&env, result, "id", &id); + throw_if_fault_occurred(&env); + + if (id) { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::NewBug(): ") + e.what()); + xmlrpc_read_int(&env, id, &bug_id); + throw_if_fault_occurred(&env); + log("New bug id: %i", bug_id); + update_client(_("New bug id: ") + to_string(bug_id)); } - return bugId.str(); - */ + + xmlrpc_DECREF(result); + return bug_id; } void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_crash_report_t& pCrashReport) { - /* - xmlrpc_c::paramList paramList; - map_xmlrpc_params_t attachmentParams; - std::vector ret; - NSSBase64Encoder* base64; + 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++) @@ -414,28 +427,21 @@ void CReporterBugzilla::AddAttachments(const std::string& pBugId, const map_cras it->second[CD_CONTENT].length()); NSSBase64Encoder_Destroy(base64, PR_FALSE); - 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(m_sAttchmentInBase64); - 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]); - log("New attachment id: %s", ss.str().c_str()); - } - catch (std::exception& e) - { - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::AddAttachemnt(): ") + e.what()); - } + + std::string description = "File: " + it->first; + 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() + ); + throw_if_fault_occurred(&env); + + xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result); + throw_if_fault_occurred(&env); } } - */ } std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) @@ -450,16 +456,17 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co update_client(_("Checking for duplicates...")); bug_id = check_uuid_in_bugzilla(component.c_str(), uuid.c_str()); - if (bug_id > 0) + + update_client(_("Logging into bugzilla...")); + if ((m_sLogin == "") && (m_sPassword=="")) { - update_client(_("Logging into bugzilla...")); - if ((m_sLogin == "") && (m_sPassword=="")) - { - VERB3 log("Empty login and password"); - throw CABRTException(EXCEP_PLUGIN, std::string(_("Empty login and password. Please check Bugzilla.conf"))); - } - login(m_sLogin.c_str(), m_sPassword.c_str()); + VERB3 log("Empty login and password"); + throw CABRTException(EXCEP_PLUGIN, std::string(_("Empty login and password. Please check Bugzilla.conf"))); + } + login(m_sLogin.c_str(), m_sPassword.c_str()); + if (bug_id > 0) + { update_client(_("Checking CC...")); if (!check_cc_and_reporter(bug_id, m_sLogin.c_str())) { @@ -468,6 +475,14 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co destroy_xmlrpc_client(); return m_sBugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); } + + update_client(_("Creating new bug...")); + bug_id = new_bug(pCrashReport); + AddAttachments(to_string(bug_id), pCrashReport); + + update_client(_("Logging out...")); + logout(); + } catch (CABRTException& e) { @@ -539,9 +554,9 @@ map_plugin_settings_t CReporterBugzilla::GetSettings() PLUGIN_INFO(REPORTER, CReporterBugzilla, "Bugzilla", - "0.0.3", + "0.0.4", "Check if a bug isn't already reported in a bugzilla " "and if not, report it.", - "zprikryl@redhat.com", + "npajkovs@redhat.com", "https://fedorahosted.org/abrt/wiki", PLUGINS_LIB_DIR"/Bugzilla.GTKBuilder"); -- cgit From b1756b440359c381ebafd62709ddcfa78ea74805 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 26 Oct 2009 16:06:57 +0100 Subject: small corrections to nicola's new xmlrpc code Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 55ce62e..d6f6c0c 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -41,17 +41,13 @@ static void get_product_and_version(const std::string& pRelease, std::string& pVersion); -#define throw_if_fault_occurred(env) \ -do \ -{ \ - xmlrpc_env* e = (env); \ - if (e->fault_occurred) \ - { \ - char buffer[2048]; \ - snprintf(buffer, 2047, "XML-RPC Fault: %s(%d)", e->fault_string, e->fault_code); \ - throw CABRTException(EXCEP_PLUGIN, std::string(buffer)); \ - } \ -}while(0) +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));; + } +} static void new_xmlrpc_client(const char* url, bool no_ssl_verify) { @@ -88,10 +84,10 @@ static void destroy_xmlrpc_client() } CReporterBugzilla::CReporterBugzilla() : - m_sBugzillaURL("https://bugzilla.redhat.com"), - m_sBugzillaXMLRPC("https://bugzilla.redhat.com" + std::string(XML_RPC_SUFFIX)), m_bNoSSLVerify(false), - m_bLoggedIn(false) + m_bLoggedIn(false), + m_sBugzillaURL("https://bugzilla.redhat.com"), + m_sBugzillaXMLRPC("https://bugzilla.redhat.com" + std::string(XML_RPC_SUFFIX)) {} CReporterBugzilla::~CReporterBugzilla() -- cgit 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 From 7f10181be367d77e5f3203e938ab24cf722119df Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Thu, 29 Oct 2009 15:20:56 +0100 Subject: Normal user can see kerneloops and report it Bugzilla memory leaks fix --- lib/Plugins/Bugzilla.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index be81ebc..2303316 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -106,6 +106,9 @@ static void login(const char* login, const char* passwd) xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); throw_if_fault_occurred(&env); + + xmlrpc_DECREF(result); + xmlrpc_DECREF(param); } static void logout() @@ -118,6 +121,9 @@ static void logout() xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result); throw_if_fault_occurred(&env); + + xmlrpc_DECREF(result); + xmlrpc_DECREF(param); } static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) @@ -146,6 +152,10 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) if (strcmp(reporter, login) == 0 ) { + xmlrpc_DECREF(param); + xmlrpc_DECREF(result); + xmlrpc_DECREF(reporter_member); + free((void*)reporter); return true; } } @@ -169,12 +179,20 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) if (strcmp(cc, login) == 0) { + xmlrpc_DECREF(param); + xmlrpc_DECREF(result); + xmlrpc_DECREF(reporter_member); + xmlrpc_DECREF(cc_member); + xmlrpc_DECREF(item); + free((void*)cc); return true; } } } - + xmlrpc_DECREF(cc_member); + xmlrpc_DECREF(param); xmlrpc_DECREF(result); + xmlrpc_DECREF(reporter_member); return false; } @@ -190,6 +208,7 @@ static void add_plus_one_cc(const uint32_t bug_id, const char* login) throw_if_fault_occurred(&env); xmlrpc_DECREF(result); + xmlrpc_DECREF(param); } static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) @@ -237,12 +256,14 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) xmlrpc_DECREF(bug); xmlrpc_DECREF(item); xmlrpc_DECREF(bugs_member); + xmlrpc_DECREF(param); return bug_id; } } xmlrpc_DECREF(result); xmlrpc_DECREF(bugs_member); + xmlrpc_DECREF(param); return -1; } @@ -378,6 +399,8 @@ static uint32_t new_bug(const map_crash_report_t& pCrashReport) } xmlrpc_DECREF(result); + xmlrpc_DECREF(param); + xmlrpc_DECREF(id); return bug_id; } @@ -405,6 +428,8 @@ static void add_attachments(const std::string& pBugId, const map_crash_report_t& xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result); throw_if_fault_occurred(&env); + xmlrpc_DECREF(result); + xmlrpc_DECREF(param); } } } -- cgit From 995bb1352eb5a461047d0acfc5f9648270c9b446 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 13:22:56 +0100 Subject: Bugzilla: simplify; CCpp, DebugDump: don't add EOL to one-line data files Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 63 +++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 2303316..7827113 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -1,14 +1,11 @@ #include #include - #include "abrtlib.h" #include "Bugzilla.h" #include "CrashTypes.h" #include "DebugDump.h" #include "ABRTException.h" #include "CommLayerInner.h" - - #ifdef HAVE_CONFIG_H #include #endif @@ -43,11 +40,11 @@ static void get_product_and_version(const std::string& pRelease, std::string& pVersion); -static void throw_if_fault_occurred(xmlrpc_env* e) +static void throw_if_xml_fault_occurred() { - if (e->fault_occurred) + if (env.fault_occurred) { - std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", e->fault_string, e->fault_code); + std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); error_msg("%s", errmsg.c_str()); // show error in daemon log throw CABRTException(EXCEP_PLUGIN, errmsg); } @@ -73,10 +70,10 @@ static void new_xmlrpc_client(const char* url, bool no_ssl_verify) xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, PACKAGE_NAME, VERSION, &clientParms, XMLRPC_CPSIZE(transportparm_size), &client); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); server_info = xmlrpc_server_info_new(&env, url); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); } static void destroy_xmlrpc_client() @@ -102,10 +99,10 @@ static void login(const char* login, const char* passwd) xmlrpc_value* param = NULL; param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_DECREF(result); xmlrpc_DECREF(param); @@ -117,10 +114,10 @@ static void logout() xmlrpc_value* param = NULL; param = xmlrpc_build_value(&env, "(s)", ""); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_DECREF(result); xmlrpc_DECREF(param); @@ -136,19 +133,19 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) const char* bug = to_string(bug_id).c_str(); param = xmlrpc_build_value(&env, "(s)", bug); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_client_call2(&env, client, server_info, "bugzilla.getBug", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_struct_find_value(&env, result, "reporter", &reporter_member); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if (reporter_member) { const char* reporter = NULL; xmlrpc_read_string(&env, reporter_member, &reporter); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if (strcmp(reporter, login) == 0 ) { @@ -161,7 +158,7 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) } xmlrpc_struct_find_value(&env, result, "cc", &cc_member); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if (cc_member) { @@ -171,11 +168,11 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) for (uint32_t i = 0; i < array_size; i++) { xmlrpc_array_read_item(&env, cc_member, i, &item); // Correct - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); const char* cc = NULL; xmlrpc_read_string(&env, item, &cc); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if (strcmp(cc, login) == 0) { @@ -202,10 +199,10 @@ static void add_plus_one_cc(const uint32_t bug_id, const char* login) xmlrpc_value* result = NULL; param = xmlrpc_build_value(&env, "({s:i,s:{s:(s)}})", "ids", bug_id, "updates", "add_cc", login); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_client_call2(&env, client, server_info, "Bug.update", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_DECREF(result); xmlrpc_DECREF(param); @@ -223,29 +220,29 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) snprintf(query, 1023, "ALL component:\"%s\" statuswhiteboard:\"%s\"", component, UUID); param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", query); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_client_call2(&env, client, server_info, "Bug.search", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_struct_find_value(&env, result, "bugs", &bugs_member); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if (bugs_member) { // when array size is equal 0 that means no bug reported uint32_t array_size = xmlrpc_array_size(&env, bugs_member); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if( array_size == 0 ) return -1; xmlrpc_value* item = NULL; xmlrpc_array_read_item(&env, bugs_member, 0, &item); // Correct - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_value* bug = NULL; xmlrpc_struct_find_value(&env, item,"bug_id", &bug); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); if (bug) { xmlrpc_read_int(&env, bug, &bug_id); @@ -379,21 +376,21 @@ static uint32_t new_bug(const map_crash_report_t& pCrashReport) "status_whiteboard", status_whiteboard.c_str(), "platform", arch.c_str() ); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_value* result; xmlrpc_client_call2(&env, client, server_info, "Bug.create", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_value* id; xmlrpc_struct_find_value(&env, result, "id", &id); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_int bug_id = -1; if (id) { xmlrpc_read_int(&env, id, &bug_id); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); log("New bug id: %i", bug_id); update_client(_("New bug id: ") + to_string(bug_id)); } @@ -424,10 +421,10 @@ static void add_attachments(const std::string& pBugId, const map_crash_report_t& "data", encoded64 ); free(encoded64); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result); - throw_if_fault_occurred(&env); + throw_if_xml_fault_occurred(); xmlrpc_DECREF(result); xmlrpc_DECREF(param); } -- cgit From b19716454b2cf37b6bbce927467b504704f1420d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 14:01:59 +0100 Subject: Bugzilla: fix some memory leaks. More reamins on error path... Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 93 ++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 51 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 7827113..2f0b2e1 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -40,6 +40,8 @@ static void get_product_and_version(const std::string& pRelease, std::string& pVersion); +// FIXME: we still leak memmory if this function detects a fault: +// many instances when we leave non-freed or non-xmlrpc_DECREF'ed data behind. static void throw_if_xml_fault_occurred() { if (env.fault_occurred) @@ -95,12 +97,10 @@ CReporterBugzilla::~CReporterBugzilla() static void login(const char* login, const char* passwd) { - xmlrpc_value* result = NULL; - xmlrpc_value* param = NULL; - - param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); throw_if_xml_fault_occurred(); + xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); throw_if_xml_fault_occurred(); @@ -110,12 +110,10 @@ static void login(const char* login, const char* passwd) static void logout() { - xmlrpc_value* result = NULL; - xmlrpc_value* param = NULL; - - param = xmlrpc_build_value(&env, "(s)", ""); + xmlrpc_value* param = xmlrpc_build_value(&env, "(s)", ""); throw_if_xml_fault_occurred(); + xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result); throw_if_xml_fault_occurred(); @@ -125,19 +123,15 @@ static void logout() static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) { - xmlrpc_value* param = NULL; - xmlrpc_value* result = NULL; - xmlrpc_value* reporter_member = NULL; - xmlrpc_value* cc_member = NULL; - - const char* bug = to_string(bug_id).c_str(); - - param = xmlrpc_build_value(&env, "(s)", bug); + xmlrpc_value* param = xmlrpc_build_value(&env, "(s)", to_string(bug_id).c_str()); throw_if_xml_fault_occurred(); + xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "bugzilla.getBug", param, &result); throw_if_xml_fault_occurred(); + xmlrpc_DECREF(param); + xmlrpc_value* reporter_member = NULL; xmlrpc_struct_find_value(&env, result, "reporter", &reporter_member); throw_if_xml_fault_occurred(); @@ -147,26 +141,27 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) xmlrpc_read_string(&env, reporter_member, &reporter); throw_if_xml_fault_occurred(); - if (strcmp(reporter, login) == 0 ) + bool eq = (strcmp(reporter, login) == 0); + free((void*)reporter); + xmlrpc_DECREF(reporter_member); + if (eq) { - xmlrpc_DECREF(param); xmlrpc_DECREF(result); - xmlrpc_DECREF(reporter_member); - free((void*)reporter); return true; } } + xmlrpc_value* cc_member = NULL; xmlrpc_struct_find_value(&env, result, "cc", &cc_member); throw_if_xml_fault_occurred(); if (cc_member) { - xmlrpc_value* item = NULL; uint32_t array_size = xmlrpc_array_size(&env, cc_member); for (uint32_t i = 0; i < array_size; i++) { + xmlrpc_value* item = NULL; xmlrpc_array_read_item(&env, cc_member, i, &item); // Correct throw_if_xml_fault_occurred(); @@ -174,33 +169,29 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) xmlrpc_read_string(&env, item, &cc); throw_if_xml_fault_occurred(); - if (strcmp(cc, login) == 0) + bool eq = (strcmp(cc, login) == 0); + free((void*)cc); + xmlrpc_DECREF(item); + if (eq) { - xmlrpc_DECREF(param); - xmlrpc_DECREF(result); - xmlrpc_DECREF(reporter_member); xmlrpc_DECREF(cc_member); - xmlrpc_DECREF(item); - free((void*)cc); + xmlrpc_DECREF(result); return true; } } + xmlrpc_DECREF(cc_member); } - xmlrpc_DECREF(cc_member); - xmlrpc_DECREF(param); + xmlrpc_DECREF(result); - xmlrpc_DECREF(reporter_member); return false; } static void add_plus_one_cc(const uint32_t bug_id, const char* login) { - xmlrpc_value* param = NULL; - xmlrpc_value* result = NULL; - - param = xmlrpc_build_value(&env, "({s:i,s:{s:(s)}})", "ids", bug_id, "updates", "add_cc", login); + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:i,s:{s:(s)}})", "ids", bug_id, "updates", "add_cc", login); throw_if_xml_fault_occurred(); + xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "Bug.update", param, &result); throw_if_xml_fault_occurred(); @@ -210,21 +201,17 @@ static void add_plus_one_cc(const uint32_t bug_id, const char* login) static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) { - xmlrpc_value* param = NULL; - xmlrpc_value* result = NULL; - xmlrpc_value* bugs_member = NULL; + std::string query = ssprintf("ALL component:\"%s\" statuswhiteboard:\"%s\"", component, UUID); - xmlrpc_int bug_id; - - char query[1024]; - snprintf(query, 1023, "ALL component:\"%s\" statuswhiteboard:\"%s\"", component, UUID); - - param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", query); + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", query.c_str()); throw_if_xml_fault_occurred(); + xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "Bug.search", param, &result); throw_if_xml_fault_occurred(); + xmlrpc_DECREF(param); + xmlrpc_value* bugs_member = NULL; xmlrpc_struct_find_value(&env, result, "bugs", &bugs_member); throw_if_xml_fault_occurred(); @@ -233,34 +220,38 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) // when array size is equal 0 that means no bug reported uint32_t array_size = xmlrpc_array_size(&env, bugs_member); throw_if_xml_fault_occurred(); - if( array_size == 0 ) + if (array_size == 0) + { + xmlrpc_DECREF(bugs_member); + xmlrpc_DECREF(result); return -1; + } xmlrpc_value* item = NULL; xmlrpc_array_read_item(&env, bugs_member, 0, &item); // Correct throw_if_xml_fault_occurred(); - xmlrpc_value* bug = NULL; - xmlrpc_struct_find_value(&env, item,"bug_id", &bug); + xmlrpc_struct_find_value(&env, item, "bug_id", &bug); throw_if_xml_fault_occurred(); + if (bug) { + xmlrpc_int bug_id; xmlrpc_read_int(&env, bug, &bug_id); - log("Bug is already reported: %i", bug_id); + log("Bug is already reported: %i", (int)bug_id); update_client(_("Bug is already reported: ") + to_string(bug_id)); - xmlrpc_DECREF(result); xmlrpc_DECREF(bug); xmlrpc_DECREF(item); xmlrpc_DECREF(bugs_member); - xmlrpc_DECREF(param); + xmlrpc_DECREF(result); return bug_id; } + xmlrpc_DECREF(item); + xmlrpc_DECREF(bugs_member); } xmlrpc_DECREF(result); - xmlrpc_DECREF(bugs_member); - xmlrpc_DECREF(param); return -1; } -- cgit From c012b30190f018a5682c86ae1428fdb8e412e12b Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 15:08:10 +0100 Subject: document a bad interaction with keyring Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 2f0b2e1..7d521be 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -436,7 +436,7 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co bug_id = check_uuid_in_bugzilla(component.c_str(), uuid.c_str()); update_client(_("Logging into bugzilla...")); - if ((m_sLogin == "") && (m_sPassword=="")) + if ((m_sLogin == "") && (m_sPassword == "")) { VERB3 log("Empty login and password"); throw CABRTException(EXCEP_PLUGIN, std::string(_("Empty login and password. Please check Bugzilla.conf"))); @@ -479,13 +479,24 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) { - if (pSettings.find("BugzillaURL") != pSettings.end()) +//BUG! This gets called when user's keyring contains login data, +//then it takes precedence over /etc/abrt/plugins/Bugzilla.conf. +//I got a case when keyring had a STALE password, and there was no way +//for me to know that it is being used. Moreover, when I discovered it +//(by hacking abrt source!), I don't know how to purge it from the keyring. +//At the very least, log("SOMETHING") here. + + map_plugin_settings_t::const_iterator it; + map_plugin_settings_t::const_iterator end = pSettings.end(); + + it = pSettings.find("BugzillaURL"); + if (it != end) { - m_sBugzillaURL = pSettings.find("BugzillaURL")->second; + m_sBugzillaURL = it->second; //remove the /xmlrpc.cgi part from old settings //FIXME: can be removed after users are informed about new config format std::string::size_type pos = m_sBugzillaURL.find(XML_RPC_SUFFIX); - if(pos != std::string::npos) + if (pos != std::string::npos) { m_sBugzillaURL.erase(pos); } @@ -502,17 +513,20 @@ void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) */ m_sBugzillaXMLRPC = m_sBugzillaURL + XML_RPC_SUFFIX; } - if (pSettings.find("Login") != pSettings.end()) + it = pSettings.find("Login"); + if (it != end) { - m_sLogin = pSettings.find("Login")->second; + m_sLogin = it->second; } - if (pSettings.find("Password") != pSettings.end()) + it = pSettings.find("Password"); + if (it != end) { - m_sPassword = pSettings.find("Password")->second; + m_sPassword = it->second; } - if (pSettings.find("NoSSLVerify") != pSettings.end()) + it = pSettings.find("NoSSLVerify"); + if (it != end) { - m_bNoSSLVerify = pSettings.find("NoSSLVerify")->second == "yes"; + m_bNoSSLVerify = (it->second == "yes"); } } -- cgit From 7ed940376e92f31dd7fb79720788d6b6f7425b43 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 16:54:16 +0100 Subject: lib/Plugins/Bugzilla: better message at login failure Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 7d521be..d78c765 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -47,6 +47,8 @@ static void throw_if_xml_fault_occurred() if (env.fault_occurred) { std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); + xmlrpc_env_clean(&env); + xmlrpc_env_init(&env); error_msg("%s", errmsg.c_str()); // show error in daemon log throw CABRTException(EXCEP_PLUGIN, errmsg); } @@ -102,10 +104,18 @@ static void login(const char* login, const char* passwd) xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); - throw_if_xml_fault_occurred(); - - xmlrpc_DECREF(result); xmlrpc_DECREF(param); + if (result) + xmlrpc_DECREF(result); + + if (env.fault_occurred) + { + std::string errmsg = ssprintf("Can't login. Check Edit->Plugins->Bugzilla and /etc/abrt/plugins/Bugzilla.conf. Server said: %s", env.fault_string); + xmlrpc_env_clean(&env); + xmlrpc_env_init(&env); + error_msg("%s", errmsg.c_str()); // show error in daemon log + throw CABRTException(EXCEP_PLUGIN, errmsg); + } } static void logout() @@ -115,10 +125,10 @@ static void logout() xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result); - throw_if_xml_fault_occurred(); - - xmlrpc_DECREF(result); xmlrpc_DECREF(param); + if (result) + xmlrpc_DECREF(result); + throw_if_xml_fault_occurred(); } static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) @@ -465,7 +475,7 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co catch (CABRTException& e) { destroy_xmlrpc_client(); - throw CABRTException(EXCEP_PLUGIN, std::string("CReporterBugzilla::Report(): ") + e.what()); + throw CABRTException(EXCEP_PLUGIN, e.what()); } destroy_xmlrpc_client(); -- cgit From 70e0330d6919b3e7e372e5cdd04282a51fe64788 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 17:46:26 +0100 Subject: lib/Plugins/Bugzilla: generate less sparse bug report comments Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 52 ++---------------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index d78c765..84c7934 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -267,56 +267,8 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) static void create_new_bug_description(const map_crash_report_t& pCrashReport, std::string& pDescription) { - std::string howToReproduce; - std::string comment; - - if (pCrashReport.find(CD_REPRODUCE) != pCrashReport.end()) - { - howToReproduce = "\n\nHow to reproduce\n" - "-----\n" + - pCrashReport.find(CD_REPRODUCE)->second[CD_CONTENT]; - } - if (pCrashReport.find(CD_COMMENT) != pCrashReport.end()) - { - comment = "\n\nComment\n" - "-----\n" + - pCrashReport.find(CD_COMMENT)->second[CD_CONTENT]; - } - pDescription = "\nabrt detected a crash.\n" + - howToReproduce + - comment + - "\n\nAdditional information\n" - "======\n"; - - map_crash_report_t::const_iterator it = pCrashReport.begin(); - for (; it != pCrashReport.end(); it++) - { - if (it->second[CD_TYPE] == CD_TXT) - { - if (it->first != CD_UUID && - it->first != FILENAME_ARCHITECTURE && - it->first != FILENAME_RELEASE && - it->first != CD_REPRODUCE && - it->first != CD_COMMENT) - { - 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) - { - 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.")); - } - } + pDescription = "abrt detected a crash.\n\n"; + pDescription += make_description_bz(pCrashReport); } static void get_product_and_version(const std::string& pRelease, -- cgit From 0586639caf9fd8218257a16006bb9783ee490102 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Sun, 1 Nov 2009 23:25:19 +0100 Subject: Hack to fix the problem with daemon remembering the last used settings --- lib/Plugins/Bugzilla.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 10 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 84c7934..6a547cf 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -39,6 +39,68 @@ static void get_product_and_version(const std::string& pRelease, std::string& pProduct, std::string& pVersion); +map_plugin_settings_t CReporterBugzilla::parse_settings(const map_plugin_settings_t& pSettings) +{ + map_plugin_settings_t plugin_settings; + map_plugin_settings_t::const_iterator it; + map_plugin_settings_t::const_iterator end = pSettings.end(); + + std::string BugzillaURL; + std::string BugzillaXMLRPC; + + it = pSettings.find("BugzillaURL"); + if (it != end) + { + BugzillaURL = it->second; + //remove the /xmlrpc.cgi part from old settings + //FIXME: can be removed after users are informed about new config format + std::string::size_type pos = BugzillaURL.find(XML_RPC_SUFFIX); + if (pos != std::string::npos) + { + BugzillaURL.erase(pos); + } + //remove the trailing '/' + while (BugzillaURL[BugzillaURL.length() - 1] == '/') + { + BugzillaURL.erase(BugzillaURL.length() - 1); + } + plugin_settings["BugzillaXMLRPC"] = BugzillaURL + XML_RPC_SUFFIX; + plugin_settings["BugzillaURL"] = BugzillaURL; + } + it = pSettings.find("Login"); + if (it != end) + { + plugin_settings["Login"] = it->second; + } + else + { + /* if any of the option is not set we use the defaults for everything */ + plugin_settings.clear(); + return plugin_settings; + } + it = pSettings.find("Password"); + if (it != end) + { + plugin_settings["Password"] = it->second; + } + else + { + plugin_settings.clear(); + return plugin_settings; + } + it = pSettings.find("NoSSLVerify"); + if (it != end) + { + plugin_settings["NoSSLVerify"] = (it->second == "yes"); + } + else + { + plugin_settings.clear(); + return plugin_settings; + } + VERB1 log("User settings ok, using it instead of defaults"); + return plugin_settings; +} // FIXME: we still leak memmory if this function detects a fault: // many instances when we leave non-freed or non-xmlrpc_DECREF'ed data behind. @@ -384,36 +446,61 @@ static void add_attachments(const std::string& pBugId, const map_crash_report_t& } } -std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, const std::string& pArgs) +std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, + const map_plugin_settings_t& pSettings, + const std::string& pArgs) { int32_t bug_id = -1; - + std::string Login; + std::string Password; + std::string BugzillaXMLRPC; + std::string BugzillaURL; + bool NoSSLVerify; + map_plugin_settings_t settings = parse_settings(pSettings); + /* if parse_settings fails it returns an empty map so we need to use defaults*/ + if(!settings.empty()) + { + Login = settings["Login"]; + Password = settings["Password"]; + BugzillaXMLRPC = settings["BugzillaXMLRPC"]; + BugzillaURL = settings["BugzillaURL"]; + NoSSLVerify = settings["NoSSLVerify"] == "yes"; + } + else + { + Login = m_sLogin; + Password = m_sPassword; + BugzillaXMLRPC = m_sBugzillaXMLRPC; + BugzillaURL = m_sBugzillaURL; + NoSSLVerify = m_bNoSSLVerify; + } + std::string component = pCrashReport.find(FILENAME_COMPONENT)->second[CD_CONTENT]; std::string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; try { - new_xmlrpc_client(m_sBugzillaXMLRPC.c_str(), m_bNoSSLVerify); + new_xmlrpc_client(BugzillaXMLRPC.c_str(), NoSSLVerify); update_client(_("Checking for duplicates...")); bug_id = check_uuid_in_bugzilla(component.c_str(), uuid.c_str()); update_client(_("Logging into bugzilla...")); - if ((m_sLogin == "") && (m_sPassword == "")) + if ((Login == "") && (Password == "")) { VERB3 log("Empty login and password"); throw CABRTException(EXCEP_PLUGIN, std::string(_("Empty login and password. Please check Bugzilla.conf"))); } - login(m_sLogin.c_str(), m_sPassword.c_str()); + login(Login.c_str(), Password.c_str()); if (bug_id > 0) { update_client(_("Checking CC...")); - if (!check_cc_and_reporter(bug_id, m_sLogin.c_str())) + if (!check_cc_and_reporter(bug_id, Login.c_str())) { - add_plus_one_cc(bug_id, m_sLogin.c_str()); + add_plus_one_cc(bug_id, Login.c_str()); } destroy_xmlrpc_client(); - return m_sBugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); + return BugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); } update_client(_("Creating new bug...")); @@ -433,10 +520,10 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, co if (bug_id > 0) { - return m_sBugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); + return BugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); } - return m_sBugzillaURL + "/show_bug.cgi?id="; + return BugzillaURL + "/show_bug.cgi?id="; } void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) -- cgit From 7ea8edef92be0c7812699d3e9d9a20bad8227ef3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 3 Nov 2009 20:26:14 +0100 Subject: lib/Plugins/Bugzilla: sanitize xmlrpc init; fix bug where ssl_verify=1 always Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 417 ++++++++++++++++++++++++++--------------------- 1 file changed, 228 insertions(+), 189 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 6a547cf..ca83d36 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -12,116 +12,97 @@ #define XML_RPC_SUFFIX "/xmlrpc.cgi" -static xmlrpc_env env; -static xmlrpc_client* client = NULL; -static struct xmlrpc_clientparms clientParms; -static struct xmlrpc_curl_xportparms curlParms; -static xmlrpc_server_info* server_info = NULL; - - -static void login(const char* login, const char* passwd); - -static void logout(); - -static void new_xmlrpc_client(const char* url, bool no_ssl_verify); - -static void destroy_xmlrpc_client(); - -static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID); - -static bool check_cc_and_reporter(const uint32_t bug_id, const char* login); - -static void add_plus_one_cc(const uint32_t bug_id, const char* login); - -static void create_new_bug_description(const map_crash_report_t& pCrashReport, std::string& pDescription); static void get_product_and_version(const std::string& pRelease, std::string& pProduct, - std::string& pVersion); - -map_plugin_settings_t CReporterBugzilla::parse_settings(const map_plugin_settings_t& pSettings) + std::string& pVersion) { - map_plugin_settings_t plugin_settings; - map_plugin_settings_t::const_iterator it; - map_plugin_settings_t::const_iterator end = pSettings.end(); - - std::string BugzillaURL; - std::string BugzillaXMLRPC; - - it = pSettings.find("BugzillaURL"); - if (it != end) - { - BugzillaURL = it->second; - //remove the /xmlrpc.cgi part from old settings - //FIXME: can be removed after users are informed about new config format - std::string::size_type pos = BugzillaURL.find(XML_RPC_SUFFIX); - if (pos != std::string::npos) - { - BugzillaURL.erase(pos); - } - //remove the trailing '/' - while (BugzillaURL[BugzillaURL.length() - 1] == '/') - { - BugzillaURL.erase(BugzillaURL.length() - 1); - } - plugin_settings["BugzillaXMLRPC"] = BugzillaURL + XML_RPC_SUFFIX; - plugin_settings["BugzillaURL"] = BugzillaURL; - } - it = pSettings.find("Login"); - if (it != end) - { - plugin_settings["Login"] = it->second; - } - else - { - /* if any of the option is not set we use the defaults for everything */ - plugin_settings.clear(); - return plugin_settings; - } - it = pSettings.find("Password"); - if (it != end) + if (pRelease.find("Rawhide") != std::string::npos) { - plugin_settings["Password"] = it->second; + pProduct = "Fedora"; + pVersion = "rawhide"; + return; } - else + if (pRelease.find("Fedora") != std::string::npos) { - plugin_settings.clear(); - return plugin_settings; + pProduct = "Fedora"; } - it = pSettings.find("NoSSLVerify"); - if (it != end) + else if (pRelease.find("Red Hat Enterprise Linux") != std::string::npos) { - plugin_settings["NoSSLVerify"] = (it->second == "yes"); + pProduct = "Red Hat Enterprise Linux "; } - else + std::string::size_type pos = pRelease.find("release"); + pos = pRelease.find(" ", pos) + 1; + while (pRelease[pos] != ' ') { - plugin_settings.clear(); - return plugin_settings; + pVersion += pRelease[pos]; + if (pProduct == "Red Hat Enterprise Linux ") + { + pProduct += pRelease[pos]; + } + pos++; } - VERB1 log("User settings ok, using it instead of defaults"); - return plugin_settings; } -// FIXME: we still leak memmory if this function detects a fault: +static void create_new_bug_description(const map_crash_report_t& pCrashReport, std::string& pDescription) +{ + pDescription = "abrt detected a crash.\n\n"; + pDescription += make_description_bz(pCrashReport); +} + +// FIXME: we still leak memory if this function detects a fault: // many instances when we leave non-freed or non-xmlrpc_DECREF'ed data behind. -static void throw_if_xml_fault_occurred() +static void throw_if_xml_fault_occurred(xmlrpc_env *env) { - if (env.fault_occurred) + if (env->fault_occurred) { - std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", env.fault_string, env.fault_code); - xmlrpc_env_clean(&env); - xmlrpc_env_init(&env); + std::string errmsg = ssprintf("XML-RPC Fault: %s(%d)", env->fault_string, env->fault_code); + xmlrpc_env_clean(env); // this is needed ONLY if fault_occurred + xmlrpc_env_init(env); // just in case user catches ex and _continues_ to use env error_msg("%s", errmsg.c_str()); // show error in daemon log throw CABRTException(EXCEP_PLUGIN, errmsg); } } -static void new_xmlrpc_client(const char* url, bool no_ssl_verify) + +/* + * Static namespace for xmlrpc stuff. + * Used mainly to ensure we always destroy xmlrpc client and server_info. + */ + +namespace { + +struct ctx { + xmlrpc_client* client; + xmlrpc_server_info* server_info; + + ctx(const char* url, bool no_ssl_verify) { new_xmlrpc_client(url, no_ssl_verify); } + ~ctx() { destroy_xmlrpc_client(); } + + void new_xmlrpc_client(const char* url, bool no_ssl_verify); + void destroy_xmlrpc_client(); + + void login(const char* login, const char* passwd); + void logout(); + 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); +}; + +void ctx::new_xmlrpc_client(const char* url, bool no_ssl_verify) { + xmlrpc_env env; xmlrpc_env_init(&env); - xmlrpc_client_setup_global_const(&env); - curlParms.network_interface = NULL; + /* This should be done at program startup, once. + * We do it in abrtd's main */ + /* xmlrpc_client_setup_global_const(&env); */ + + struct xmlrpc_curl_xportparms curlParms; + memset(&curlParms, 0, sizeof(curlParms)); + /* curlParms.network_interface = NULL; - done by memset */ curlParms.no_ssl_verifypeer = no_ssl_verify; curlParms.no_ssl_verifyhost = no_ssl_verify; #ifdef VERSION @@ -130,39 +111,49 @@ static void new_xmlrpc_client(const char* url, bool no_ssl_verify) curlParms.user_agent = "abrt"; #endif + struct xmlrpc_clientparms clientParms; + memset(&clientParms, 0, sizeof(clientParms)); clientParms.transport = "curl"; clientParms.transportparmsP = &curlParms; clientParms.transportparm_size = XMLRPC_CXPSIZE(user_agent); - xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, PACKAGE_NAME, VERSION, &clientParms, XMLRPC_CPSIZE(transportparm_size), - &client); - throw_if_xml_fault_occurred(); + client = NULL; + xmlrpc_client_create(&env, XMLRPC_CLIENT_NO_FLAGS, + PACKAGE_NAME, VERSION, + &clientParms, XMLRPC_CPSIZE(transportparm_size), + &client); + throw_if_xml_fault_occurred(&env); server_info = xmlrpc_server_info_new(&env, url); - throw_if_xml_fault_occurred(); + if (env.fault_occurred) + { + xmlrpc_client_destroy(client); + client = NULL; + } + throw_if_xml_fault_occurred(&env); } -static void destroy_xmlrpc_client() +void ctx::destroy_xmlrpc_client() { - xmlrpc_server_info_free(server_info); - xmlrpc_env_clean(&env); - xmlrpc_client_destroy(client); - xmlrpc_client_teardown_global_const(); + if (server_info) + { + xmlrpc_server_info_free(server_info); + server_info = NULL; + } + if (client) + { + xmlrpc_client_destroy(client); + client = NULL; + } } -CReporterBugzilla::CReporterBugzilla() : - m_bNoSSLVerify(false), - m_sBugzillaURL("https://bugzilla.redhat.com"), - m_sBugzillaXMLRPC("https://bugzilla.redhat.com"XML_RPC_SUFFIX) -{} - -CReporterBugzilla::~CReporterBugzilla() -{} - -static void login(const char* login, const char* passwd) +void ctx::login(const char* login, const char* passwd) { + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s,s:s})", "login", login, "password", passwd); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result); @@ -174,44 +165,49 @@ static void login(const char* login, const char* passwd) { std::string errmsg = ssprintf("Can't login. Check Edit->Plugins->Bugzilla and /etc/abrt/plugins/Bugzilla.conf. Server said: %s", env.fault_string); xmlrpc_env_clean(&env); - xmlrpc_env_init(&env); error_msg("%s", errmsg.c_str()); // show error in daemon log throw CABRTException(EXCEP_PLUGIN, errmsg); } } -static void logout() +void ctx::logout() { + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_value* param = xmlrpc_build_value(&env, "(s)", ""); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result); xmlrpc_DECREF(param); if (result) xmlrpc_DECREF(result); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); } -static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) +bool ctx::check_cc_and_reporter(uint32_t bug_id, const char* login) { + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_value* param = xmlrpc_build_value(&env, "(s)", to_string(bug_id).c_str()); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "bugzilla.getBug", param, &result); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_DECREF(param); xmlrpc_value* reporter_member = NULL; xmlrpc_struct_find_value(&env, result, "reporter", &reporter_member); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); if (reporter_member) { const char* reporter = NULL; xmlrpc_read_string(&env, reporter_member, &reporter); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); bool eq = (strcmp(reporter, login) == 0); free((void*)reporter); @@ -225,7 +221,7 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) xmlrpc_value* cc_member = NULL; xmlrpc_struct_find_value(&env, result, "cc", &cc_member); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); if (cc_member) { @@ -235,11 +231,11 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) { xmlrpc_value* item = NULL; xmlrpc_array_read_item(&env, cc_member, i, &item); // Correct - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); const char* cc = NULL; xmlrpc_read_string(&env, item, &cc); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); bool eq = (strcmp(cc, login) == 0); free((void*)cc); @@ -258,40 +254,46 @@ static bool check_cc_and_reporter(const uint32_t bug_id, const char* login) return false; } -static void add_plus_one_cc(const uint32_t bug_id, const char* login) +void ctx::add_plus_one_cc(uint32_t bug_id, const char* login) { + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_value* param = xmlrpc_build_value(&env, "({s:i,s:{s:(s)}})", "ids", bug_id, "updates", "add_cc", login); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "Bug.update", param, &result); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_DECREF(result); xmlrpc_DECREF(param); } -static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) +int32_t ctx::check_uuid_in_bugzilla(const char* component, const char* UUID) { + xmlrpc_env env; + xmlrpc_env_init(&env); + std::string query = ssprintf("ALL component:\"%s\" statuswhiteboard:\"%s\"", component, UUID); xmlrpc_value* param = xmlrpc_build_value(&env, "({s:s})", "quicksearch", query.c_str()); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* result = NULL; xmlrpc_client_call2(&env, client, server_info, "Bug.search", param, &result); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_DECREF(param); xmlrpc_value* bugs_member = NULL; xmlrpc_struct_find_value(&env, result, "bugs", &bugs_member); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); if (bugs_member) { // when array size is equal 0 that means no bug reported uint32_t array_size = xmlrpc_array_size(&env, bugs_member); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); if (array_size == 0) { xmlrpc_DECREF(bugs_member); @@ -301,10 +303,10 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) xmlrpc_value* item = NULL; xmlrpc_array_read_item(&env, bugs_member, 0, &item); // Correct - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* bug = NULL; xmlrpc_struct_find_value(&env, item, "bug_id", &bug); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); if (bug) { @@ -327,45 +329,11 @@ static int32_t check_uuid_in_bugzilla(const char* component, const char* UUID) return -1; } -static void create_new_bug_description(const map_crash_report_t& pCrashReport, std::string& pDescription) +uint32_t ctx::new_bug(const map_crash_report_t& pCrashReport) { - pDescription = "abrt detected a crash.\n\n"; - pDescription += make_description_bz(pCrashReport); -} - -static void get_product_and_version(const std::string& pRelease, - std::string& pProduct, - std::string& pVersion) -{ - if (pRelease.find("Rawhide") != std::string::npos) - { - pProduct = "Fedora"; - pVersion = "rawhide"; - return; - } - if (pRelease.find("Fedora") != std::string::npos) - { - pProduct = "Fedora"; - } - else if (pRelease.find("Red Hat Enterprise Linux") != std::string::npos) - { - pProduct = "Red Hat Enterprise Linux "; - } - std::string::size_type pos = pRelease.find("release"); - pos = pRelease.find(" ", pos) + 1; - while (pRelease[pos] != ' ') - { - pVersion += pRelease[pos]; - if (pProduct == "Red Hat Enterprise Linux ") - { - pProduct += pRelease[pos]; - } - pos++; - } -} + xmlrpc_env env; + xmlrpc_env_init(&env); -static uint32_t new_bug(const map_crash_report_t& pCrashReport) -{ 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]; @@ -391,21 +359,21 @@ static uint32_t new_bug(const map_crash_report_t& pCrashReport) "status_whiteboard", status_whiteboard.c_str(), "platform", arch.c_str() ); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* result; xmlrpc_client_call2(&env, client, server_info, "Bug.create", param, &result); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_value* id; xmlrpc_struct_find_value(&env, result, "id", &id); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_int bug_id = -1; if (id) { xmlrpc_read_int(&env, id, &bug_id); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); log("New bug id: %i", bug_id); update_client(_("New bug id: ") + to_string(bug_id)); } @@ -416,8 +384,11 @@ static uint32_t new_bug(const map_crash_report_t& pCrashReport) return bug_id; } -static void add_attachments(const std::string& pBugId, const map_crash_report_t& pCrashReport) +void ctx::add_attachments(const char* bug_id_str, const map_crash_report_t& pCrashReport) { + xmlrpc_env env; + xmlrpc_env_init(&env); + xmlrpc_value* result = NULL; map_crash_report_t::const_iterator it = pCrashReport.begin(); @@ -429,25 +400,41 @@ static void add_attachments(const std::string& pBugId, const map_crash_report_t& 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(), + bug_id_str, "description", description.c_str(), "filename", it->first.c_str(), "contenttype", "text/plain", "data", encoded64 ); free(encoded64); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result); - throw_if_xml_fault_occurred(); + throw_if_xml_fault_occurred(&env); xmlrpc_DECREF(result); xmlrpc_DECREF(param); } } } -std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, - const map_plugin_settings_t& pSettings, +} /* namespace */ + + +/* + * CReporterBugzilla + */ + +CReporterBugzilla::CReporterBugzilla() : + m_bNoSSLVerify(false), + m_sBugzillaURL("https://bugzilla.redhat.com"), + m_sBugzillaXMLRPC("https://bugzilla.redhat.com"XML_RPC_SUFFIX) +{} + +CReporterBugzilla::~CReporterBugzilla() +{} + +std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, + const map_plugin_settings_t& pSettings, const std::string& pArgs) { int32_t bug_id = -1; @@ -474,15 +461,15 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, BugzillaURL = m_sBugzillaURL; NoSSLVerify = m_bNoSSLVerify; } - + std::string component = pCrashReport.find(FILENAME_COMPONENT)->second[CD_CONTENT]; std::string uuid = pCrashReport.find(CD_UUID)->second[CD_CONTENT]; try { - new_xmlrpc_client(BugzillaXMLRPC.c_str(), NoSSLVerify); + ctx bz_server(BugzillaXMLRPC.c_str(), NoSSLVerify); update_client(_("Checking for duplicates...")); - bug_id = check_uuid_in_bugzilla(component.c_str(), uuid.c_str()); + bug_id = bz_server.check_uuid_in_bugzilla(component.c_str(), uuid.c_str()); update_client(_("Logging into bugzilla...")); if ((Login == "") && (Password == "")) @@ -490,42 +477,94 @@ std::string CReporterBugzilla::Report(const map_crash_report_t& pCrashReport, VERB3 log("Empty login and password"); throw CABRTException(EXCEP_PLUGIN, std::string(_("Empty login and password. Please check Bugzilla.conf"))); } - login(Login.c_str(), Password.c_str()); + bz_server.login(Login.c_str(), Password.c_str()); if (bug_id > 0) { update_client(_("Checking CC...")); - if (!check_cc_and_reporter(bug_id, Login.c_str())) + if (!bz_server.check_cc_and_reporter(bug_id, Login.c_str())) { - add_plus_one_cc(bug_id, Login.c_str()); + bz_server.add_plus_one_cc(bug_id, Login.c_str()); } - destroy_xmlrpc_client(); - return BugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); + bz_server.logout(); + return BugzillaURL + "/show_bug.cgi?id=" + to_string(bug_id); } update_client(_("Creating new bug...")); - bug_id = new_bug(pCrashReport); - add_attachments(to_string(bug_id), pCrashReport); + bug_id = bz_server.new_bug(pCrashReport); + bz_server.add_attachments(to_string(bug_id).c_str(), pCrashReport); update_client(_("Logging out...")); - logout(); - + bz_server.logout(); } catch (CABRTException& e) { - destroy_xmlrpc_client(); throw CABRTException(EXCEP_PLUGIN, e.what()); } - destroy_xmlrpc_client(); if (bug_id > 0) { - return BugzillaURL + "/show_bug.cgi?id="+to_string(bug_id); + return BugzillaURL + "/show_bug.cgi?id=" + to_string(bug_id); } return BugzillaURL + "/show_bug.cgi?id="; } +map_plugin_settings_t CReporterBugzilla::parse_settings(const map_plugin_settings_t& pSettings) +{ + map_plugin_settings_t plugin_settings; + map_plugin_settings_t::const_iterator it; + map_plugin_settings_t::const_iterator end = pSettings.end(); + + it = pSettings.find("BugzillaURL"); + if (it != end) + { + std::string BugzillaURL = it->second; + //remove the /xmlrpc.cgi part from old settings + //FIXME: can be removed after users are informed about new config format + std::string::size_type pos = BugzillaURL.find(XML_RPC_SUFFIX); + if (pos != std::string::npos) + { + BugzillaURL.erase(pos); + } + //remove the trailing '/' + while (BugzillaURL[BugzillaURL.length() - 1] == '/') + { + BugzillaURL.erase(BugzillaURL.length() - 1); + } + plugin_settings["BugzillaXMLRPC"] = BugzillaURL + XML_RPC_SUFFIX; + plugin_settings["BugzillaURL"] = BugzillaURL; + } + + it = pSettings.find("Login"); + if (it == end) + { + /* if any of the option is not set we use the defaults for everything */ + plugin_settings.clear(); + return plugin_settings; + } + plugin_settings["Login"] = it->second; + + it = pSettings.find("Password"); + if (it == end) + { + plugin_settings.clear(); + return plugin_settings; + } + plugin_settings["Password"] = it->second; + + it = pSettings.find("NoSSLVerify"); + if (it == end) + { + plugin_settings.clear(); + return plugin_settings; + } + plugin_settings["NoSSLVerify"] = it->second; + + VERB1 log("User settings ok, using them instead of defaults"); + return plugin_settings; +} + void CReporterBugzilla::SetSettings(const map_plugin_settings_t& pSettings) { //BUG! This gets called when user's keyring contains login data, -- cgit From 1202706839ec42299e8794750cec66dfa7db0206 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 17:51:17 +0100 Subject: simplify logging a bit. warn_client() is gone, reuse error_msg() for it. Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index ca83d36..18ab5c8 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); -- cgit From 57039b590e4411606795893c90f9871e0412ca31 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 18:26:42 +0100 Subject: give Plugin class a map_plugin_settings_t member This simplifies and unifies get/set settings ops Signed-off-by: Denys Vlasenko --- lib/Plugins/Bugzilla.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/Plugins/Bugzilla.cpp') diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp index 18ab5c8..ecd4dd6 100644 --- a/lib/Plugins/Bugzilla.cpp +++ b/lib/Plugins/Bugzilla.cpp @@ -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, -- cgit