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