summaryrefslogtreecommitdiffstats
path: root/src/plugins/abrt-action-bugzilla.cpp
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-12-06 16:56:50 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2010-12-06 16:56:50 +0100
commit47728cc3c70c2b6d3a645e5760b39b20bd946e39 (patch)
tree6fd64dc8d124d5a10dd4efddd69a71f921f4a1d1 /src/plugins/abrt-action-bugzilla.cpp
parent300a498bdc7b2912f8aaebeb87a7b4cc0a9970a5 (diff)
downloadabrt-47728cc3c70c2b6d3a645e5760b39b20bd946e39.tar.gz
abrt-47728cc3c70c2b6d3a645e5760b39b20bd946e39.tar.xz
abrt-47728cc3c70c2b6d3a645e5760b39b20bd946e39.zip
This patch changes crash data to use C structures.
The smallest data element is: struct crash_item { char *content; unsigned flags; }; where content is, eh, content, and flags is a bit flag field. crash_data_t is a map of crash_item's, implemented as a pointer to heap-allocated GHashTable. vector_of_crash_data_t is a vector of crash_data_t's, implemented as a pointer to heap-allocated GPtrArray. Most operations have light wrappers around them to hide the nature of the containers. For example, to free vector_of_crash_data, you need to use free_vector_of_crash_data(ptr) instead of open-coding g_ptr_array_free. The wrapper is thin. The goal is not so much to hide the implementation, but more to make it easier to use the correct function. dbus (un)marshalling functions convert crash_item to three-element array of strings, in order to keep compatibility with abrt-gui (python). This can be changed later to use native representation. crash_data_t and vector_of_crash_data_t are represented in "natural" way, no funny stuff there. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'src/plugins/abrt-action-bugzilla.cpp')
-rw-r--r--src/plugins/abrt-action-bugzilla.cpp71
1 files changed, 36 insertions, 35 deletions
diff --git a/src/plugins/abrt-action-bugzilla.cpp b/src/plugins/abrt-action-bugzilla.cpp
index b396e453..b215735b 100644
--- a/src/plugins/abrt-action-bugzilla.cpp
+++ b/src/plugins/abrt-action-bugzilla.cpp
@@ -112,8 +112,8 @@ struct ctx: public abrt_xmlrpc_conn {
xmlrpc_int32 get_bug_dup_id(xmlrpc_value* result_xml);
void get_bug_cc(xmlrpc_value* result_xml, struct bug_info* bz);
int add_plus_one_cc(xmlrpc_int32 bug_id, const char* login);
- xmlrpc_int32 new_bug(const map_crash_data_t& pCrashData, int depend_on_bugno);
- int add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashData);
+ xmlrpc_int32 new_bug(crash_data_t *crash_data, int depend_on_bugno);
+ int add_attachments(const char* bug_id_str, crash_data_t *crash_data);
int get_bug_info(struct bug_info* bz, xmlrpc_int32 bug_id);
int add_comment(xmlrpc_int32 bug_id, const char* comment, bool is_private);
@@ -442,17 +442,17 @@ static const char *tainted_string(unsigned tainted)
return taint_warnings[idx];
}
-xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugno)
+xmlrpc_int32 ctx::new_bug(crash_data_t *crash_data, int depend_on_bugno)
{
- const char *package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE);
- const char *component = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_COMPONENT);
- const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE);
- const char *arch = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ARCHITECTURE);
- const char *duphash = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_DUPHASH);
- const char *reason = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_REASON);
- const char *function = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_CRASH_FUNCTION);
- const char *analyzer = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ANALYZER);
- const char *tainted_str = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_TAINTED);
+ const char *package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE);
+ const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT);
+ const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE);
+ const char *arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE);
+ const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH);
+ const char *reason = get_crash_item_content_or_NULL(crash_data, FILENAME_REASON);
+ const char *function = get_crash_item_content_or_NULL(crash_data, FILENAME_CRASH_FUNCTION);
+ const char *analyzer = get_crash_item_content_or_NULL(crash_data, FILENAME_ANALYZER);
+ const char *tainted_str = get_crash_item_content_or_NULL(crash_data, FILENAME_TAINTED);
struct strbuf *buf_summary = strbuf_new();
strbuf_append_strf(buf_summary, "[abrt] %s", package);
@@ -474,7 +474,7 @@ xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugn
char *status_whiteboard = xasprintf("abrt_hash:%s", duphash);
- char *bz_dsc = make_description_bz(pCrashData);
+ char *bz_dsc = make_description_bz(crash_data);
char *full_dsc = xasprintf("abrt version: "VERSION"\n%s", bz_dsc);
free(bz_dsc);
@@ -534,23 +534,24 @@ xmlrpc_int32 ctx::new_bug(const map_crash_data_t& pCrashData, int depend_on_bugn
return bug_id;
}
-int ctx::add_attachments(const char* bug_id_str, const map_crash_data_t& pCrashData)
+int ctx::add_attachments(const char* bug_id_str, crash_data_t *crash_data)
{
- map_crash_data_t::const_iterator it = pCrashData.begin();
- for (; it != pCrashData.end(); it++)
+ GHashTableIter iter;
+ char *name;
+ struct crash_item *value;
+ g_hash_table_iter_init(&iter, crash_data);
+ while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value))
{
- const char *itemname = it->first.c_str();
- const char *type = it->second[CD_TYPE].c_str();
- const char *content = it->second[CD_CONTENT].c_str();
+ const char *content = value->content;
- if ((strcmp(type, CD_TXT) == 0)
- && (strlen(content) > CD_TEXT_ATT_SIZE || (strcmp(itemname, FILENAME_BACKTRACE) == 0))
+ if ((value->flags & CD_FLAG_TXT)
+ && (strlen(content) > CD_TEXT_ATT_SIZE || (strcmp(name, FILENAME_BACKTRACE) == 0))
) {
char *encoded64 = encode_base64(content, strlen(content));
- char *filename = xasprintf("File: %s", itemname);
+ char *filename = xasprintf("File: %s", name);
xmlrpc_value* result = call("bugzilla.addAttachment", "(s{s:s,s:s,s:s,s:s})", bug_id_str,
"description", filename,
- "filename", itemname,
+ "filename", name,
"contenttype", "text/plain",
"data", encoded64
);
@@ -644,8 +645,7 @@ static void report_to_bugzilla(
{
throw CABRTException(EXCEP_PLUGIN, _("Can't open '%s'"), dump_dir_name);
}
- map_crash_data_t pCrashData;
- load_crash_data_from_crash_dump_dir(dd, pCrashData);
+ crash_data_t *crash_data = load_crash_data_from_crash_dump_dir(dd);
dd_close(dd);
const char *env;
@@ -674,9 +674,9 @@ static void report_to_bugzilla(
env = getenv("Bugzilla_SSLVerify");
ssl_verify = string_to_bool(env ? env : settings["SSLVerify"].c_str());
- const char *component = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_COMPONENT);
- const char *duphash = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_DUPHASH);
- const char *release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE);
+ const char *component = get_crash_item_content_or_NULL(crash_data, FILENAME_COMPONENT);
+ const char *duphash = get_crash_item_content_or_NULL(crash_data, FILENAME_DUPHASH);
+ const char *release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE);
ctx bz_server(bugzilla_xmlrpc, ssl_verify);
@@ -773,7 +773,7 @@ static void report_to_bugzilla(
else if (all_bugs_size == 0) // Create new bug
{
log(_("Creating a new bug..."));
- bug_id = bz_server.new_bug(pCrashData, depend_on_bugno);
+ bug_id = bz_server.new_bug(crash_data, depend_on_bugno);
if (bug_id < 0)
{
throw_if_xml_fault_occurred(&bz_server.env);
@@ -781,7 +781,7 @@ static void report_to_bugzilla(
}
log("Adding attachments to bug %d...", bug_id);
- int ret = bz_server.add_attachments(to_string(bug_id).c_str(), pCrashData);
+ int ret = bz_server.add_attachments(to_string(bug_id).c_str(), crash_data);
if (ret == -1)
{
throw_if_xml_fault_occurred(&bz_server.env);
@@ -855,13 +855,13 @@ static void report_to_bugzilla(
throw_if_xml_fault_occurred(&bz_server.env);
}
- char *dsc = make_description_reproduce_comment(pCrashData);
+ char *dsc = make_description_reproduce_comment(crash_data);
if (dsc)
{
- const char* package = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_PACKAGE);
- const char* release = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_RELEASE);
- const char* arch = get_crash_data_item_content_or_NULL(pCrashData, FILENAME_ARCHITECTURE);
- const char* is_private = get_crash_data_item_content_or_NULL(pCrashData, "is_private");
+ const char* package = get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE);
+ const char* release = get_crash_item_content_or_NULL(crash_data, FILENAME_RELEASE);
+ const char* arch = get_crash_item_content_or_NULL(crash_data, FILENAME_ARCHITECTURE);
+ const char* is_private = get_crash_item_content_or_NULL(crash_data, "is_private");
char *full_dsc = xasprintf("Package: %s\n"
"Architecture: %s\n"
@@ -895,6 +895,7 @@ static void report_to_bugzilla(
(int)bug_id
);
+ free_crash_data(crash_data);
bug_info_destroy(&bz);
}