summaryrefslogtreecommitdiffstats
path: root/lib/Plugins/Bugzilla.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-11-09 18:39:20 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2009-11-09 18:39:20 +0100
commit2094c666c6175e6e8cfb5a5a7a49da6004d042d8 (patch)
tree4a5ef1b1d9f3b653b4a522dddc65e0401d3e32c2 /lib/Plugins/Bugzilla.cpp
parent48d30ac32352545800bbc70130796a85ab7a62c3 (diff)
downloadabrt-2094c666c6175e6e8cfb5a5a7a49da6004d042d8.tar.gz
abrt-2094c666c6175e6e8cfb5a5a7a49da6004d042d8.tar.xz
abrt-2094c666c6175e6e8cfb5a5a7a49da6004d042d8.zip
applied gavin's patch to Catcut. Refactored common xmlrpc code into lib/Utils.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'lib/Plugins/Bugzilla.cpp')
-rw-r--r--lib/Plugins/Bugzilla.cpp110
1 files changed, 17 insertions, 93 deletions
diff --git a/lib/Plugins/Bugzilla.cpp b/lib/Plugins/Bugzilla.cpp
index ecd4dd6..b3cef92 100644
--- a/lib/Plugins/Bugzilla.cpp
+++ b/lib/Plugins/Bugzilla.cpp
@@ -1,6 +1,7 @@
#include <xmlrpc-c/base.h>
#include <xmlrpc-c/client.h>
#include "abrtlib.h"
+#include "abrt_xmlrpc.h"
#include "Bugzilla.h"
#include "CrashTypes.h"
#include "DebugDump.h"
@@ -50,20 +51,6 @@ static void create_new_bug_description(const map_crash_report_t& pCrashReport, s
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(xmlrpc_env *env)
-{
- if (env->fault_occurred)
- {
- 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 namespace for xmlrpc stuff.
@@ -72,81 +59,18 @@ static void throw_if_xml_fault_occurred(xmlrpc_env *env)
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(); }
+struct ctx: public abrt_xmlrpc_conn {
+ ctx(const char* url, bool no_ssl_verify): abrt_xmlrpc_conn(url, no_ssl_verify) {}
- 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 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);
-
- /* 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
- curlParms.user_agent = PACKAGE_NAME"/"VERSION;
-#else
- 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);
-
- 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);
- if (env.fault_occurred)
- {
- xmlrpc_client_destroy(client);
- client = NULL;
- }
- throw_if_xml_fault_occurred(&env);
-}
-
-void ctx::destroy_xmlrpc_client()
-{
- if (server_info)
- {
- xmlrpc_server_info_free(server_info);
- server_info = NULL;
- }
- if (client)
- {
- xmlrpc_client_destroy(client);
- client = NULL;
- }
-}
-
void ctx::login(const char* login, const char* passwd)
{
xmlrpc_env env;
@@ -156,7 +80,7 @@ void ctx::login(const char* login, const char* passwd)
throw_if_xml_fault_occurred(&env);
xmlrpc_value* result = NULL;
- xmlrpc_client_call2(&env, client, server_info, "User.login", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "User.login", param, &result);
xmlrpc_DECREF(param);
if (result)
xmlrpc_DECREF(result);
@@ -179,7 +103,7 @@ void ctx::logout()
throw_if_xml_fault_occurred(&env);
xmlrpc_value* result = NULL;
- xmlrpc_client_call2(&env, client, server_info, "User.logout", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "User.logout", param, &result);
xmlrpc_DECREF(param);
if (result)
xmlrpc_DECREF(result);
@@ -195,7 +119,7 @@ bool ctx::check_cc_and_reporter(uint32_t bug_id, const char* login)
throw_if_xml_fault_occurred(&env);
xmlrpc_value* result = NULL;
- xmlrpc_client_call2(&env, client, server_info, "bugzilla.getBug", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "bugzilla.getBug", param, &result);
throw_if_xml_fault_occurred(&env);
xmlrpc_DECREF(param);
@@ -263,7 +187,7 @@ void ctx::add_plus_one_cc(uint32_t bug_id, const char* login)
throw_if_xml_fault_occurred(&env);
xmlrpc_value* result = NULL;
- xmlrpc_client_call2(&env, client, server_info, "Bug.update", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "Bug.update", param, &result);
throw_if_xml_fault_occurred(&env);
xmlrpc_DECREF(result);
@@ -281,7 +205,7 @@ int32_t ctx::check_uuid_in_bugzilla(const char* component, const char* UUID)
throw_if_xml_fault_occurred(&env);
xmlrpc_value* result = NULL;
- xmlrpc_client_call2(&env, client, server_info, "Bug.search", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "Bug.search", param, &result);
throw_if_xml_fault_occurred(&env);
xmlrpc_DECREF(param);
@@ -362,7 +286,7 @@ uint32_t ctx::new_bug(const map_crash_report_t& pCrashReport)
throw_if_xml_fault_occurred(&env);
xmlrpc_value* result;
- xmlrpc_client_call2(&env, client, server_info, "Bug.create", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "Bug.create", param, &result);
throw_if_xml_fault_occurred(&env);
xmlrpc_value* id;
@@ -409,7 +333,7 @@ void ctx::add_attachments(const char* bug_id_str, const map_crash_report_t& pCra
free(encoded64);
throw_if_xml_fault_occurred(&env);
- xmlrpc_client_call2(&env, client, server_info, "bugzilla.addAttachment", param, &result);
+ xmlrpc_client_call2(&env, m_pClient, m_pServer_info, "bugzilla.addAttachment", param, &result);
throw_if_xml_fault_occurred(&env);
xmlrpc_DECREF(result);
xmlrpc_DECREF(param);