On 02/13/2012 12:03 PM, Nikola Pajkovsky wrote:
we called more then once get_problem_* function for the same static
value.
This will merge static values into structure and thus simplify rhbz_* call.
rhbz_* calls will take only bugzilla_struct and all information will be read
from that.
Another benefit is, that if we put bugzilla_struct into list and than we can read
multiple different configuration for one problem-dir and send them to different
locations at once or vice versa.
Signed-off-by: Nikola Pajkovsky<npajkovs(a)redhat.com>
---
src/include/internal_libreport.h | 7 ++-
src/lib/parse_release.c | 8 +---
src/plugins/abrt-bodhi.c | 2 +-
src/plugins/reporter-bugzilla.c | 39 ++++++++++--------
src/plugins/rhbz.c | 80 ++++++++++++-------------------------
src/plugins/rhbz.h | 18 +++++++-
6 files changed, 68 insertions(+), 86 deletions(-)
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
index 95b600b..884e815 100644
--- a/src/include/internal_libreport.h
+++ b/src/include/internal_libreport.h
@@ -583,11 +583,12 @@ char* make_description_logger(problem_data_t *problem_data,
unsigned max_text_si
//#define make_description_mailx libreport_make_description_mailx
//char* make_description_mailx(problem_data_t *problem_data);
-#define parse_release_for_bz libreport_parse_release_for_bz
-void parse_release_for_bz(const char *pRelease, char **product, char **version);
+//#define parse_release_for_bz libreport_parse_release_for_bz
+//void parse_release_for_bz(const char *pRelease, char **product, char **version);
#define parse_release_for_rhts libreport_parse_release_for_rhts
void parse_release_for_rhts(const char *pRelease, char **product, char **version);
-
+#define parse_release libreport_parse_release
+void parse_release(const char *release, char** product, char** version, bool
append_rhel_version);
- no, the wrapper function parse_release_for_bz makes it more readable
/**
* Loads settings and stores it in second parameter. On success it
* returns true, otherwise returns false.
diff --git a/src/lib/parse_release.c b/src/lib/parse_release.c
index 9a4f69f..3f3ecc1 100644
--- a/src/lib/parse_release.c
+++ b/src/lib/parse_release.c
@@ -19,7 +19,7 @@
#include "internal_libreport.h"
// caller is reposible for freeing *product* and *version*
-static void parse_release(const char *release, char** product, char** version, bool
append_rhel_version)
+void parse_release(const char *release, char** product, char** version, bool
append_rhel_version)
{
if (strstr(release, "Rawhide"))
{
@@ -84,12 +84,6 @@ static void parse_release(const char *release, char** product, char**
version, b
VERB3 log("%s: version:'%s' product:'%s'", __func__,
*version, *product);
}
-void parse_release_for_bz(const char *release, char** product, char** version)
-{
- /* Fedora/RH bugzilla uses "Red Hat Enterprise Linux N" product RHEL */
- parse_release(release, product, version, /*append_rhel_version:*/ true);
-}
-
void parse_release_for_rhts(const char *release, char** product, char** version)
{
/* RHTS uses "Red Hat Enterprise Linux" product for RHEL */
diff --git a/src/plugins/abrt-bodhi.c b/src/plugins/abrt-bodhi.c
index 43a3b42..5bb3024 100644
--- a/src/plugins/abrt-bodhi.c
+++ b/src/plugins/abrt-bodhi.c
@@ -415,7 +415,7 @@ int main(int argc, char **argv)
//COMPAT, remove in abrt-2.1
if (!release) release = get_problem_item_content_or_die(problem_data,
"release");
char *product = NULL, *version = NULL;
- parse_release_for_bz(release,&product,&version);
+ parse_release(release,&product,&version, /* fedora */ true);
- and here we go.... ^ the previous version using the wrapper is more
readable, so please keep it...
query = strbuf_append_strf(query,
"release=f%s&", version);
}
}
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
index b941d49..cd31f5b 100644
--- a/src/plugins/reporter-bugzilla.c
+++ b/src/plugins/reporter-bugzilla.c
@@ -261,10 +261,10 @@ int main(int argc, char **argv)
if (!problem_data)
xfunc_die(); /* create_problem_data_for_reporting already emitted error msg */
- const char *component = get_problem_item_content_or_die(problem_data,
FILENAME_COMPONENT);
- const char *duphash = get_problem_item_content_or_NULL(problem_data,
FILENAME_DUPHASH);
+ rhbz.b_component = get_problem_item_content_or_die(problem_data,
FILENAME_COMPONENT);
+ rhbz.b_duphash = get_problem_item_content_or_NULL(problem_data,
FILENAME_DUPHASH);
//COMPAT, remove after 2.1 release
- if (!duphash) duphash = get_problem_item_content_or_die(problem_data,
"global_uuid");
+ if (!rhbz.b_duphash) rhbz.b_duphash = get_problem_item_content_or_die(problem_data,
"global_uuid");
if (!rhbz.b_release || !*rhbz.b_release) /* if not overridden or empty... */
{
rhbz.b_release = get_problem_item_content_or_NULL(problem_data,
FILENAME_OS_RELEASE);
@@ -273,15 +273,20 @@ int main(int argc, char **argv)
rhbz.b_release = get_problem_item_content_or_die(problem_data, "release");
}
+ rhbz.b_arch = get_problem_item_content_or_NULL(problem_data,
FILENAME_ARCHITECTURE);
+ rhbz.b_package = get_problem_item_content_or_NULL(problem_data, FILENAME_PACKAGE);
+ rhbz.b_reason = get_problem_item_content_or_NULL(problem_data, FILENAME_REASON);
+ rhbz.b_function = get_problem_item_content_or_NULL(problem_data,
FILENAME_CRASH_FUNCTION);
+ rhbz.b_analyzer = get_problem_item_content_or_NULL(problem_data,
FILENAME_ANALYZER);
+ rhbz.b_tainted_short = get_problem_item_content_or_NULL(problem_data,
+ FILENAME_TAINTED_SHORT);
+
log(_("Logging into Bugzilla at %s"), rhbz.b_bugzilla_url);
rhbz_login(client,&rhbz);
- char *version = NULL;
- parse_release_for_bz(rhbz.b_release,&rhbz.b_product,&version);
- free(version);
+ rhbz_parse_release(&rhbz);
log(_("Checking for duplicates"));
-
/*
selinux guy's almost always move filled bug from component selinux-policy
to right component.
@@ -294,9 +299,9 @@ int main(int argc, char **argv)
returns NULL and creates a new bug.
*/
const char *product_substitute = (!strcmp(rhbz.b_product, "Fedora")) ?
rhbz.b_product : NULL;
- const char *component_substitute = (!strcmp(component, "selinux-policy"))
? NULL : component;
+ const char *component_substitute = (!strcmp(rhbz.b_component,
"selinux-policy")) ? NULL : rhbz.b_component;
xmlrpc_value *result = rhbz_search_duphash(client, component_substitute,
- product_substitute, duphash);
+ product_substitute, rhbz.b_duphash);
xmlrpc_value *all_bugs = rhbz_get_member("bugs", result);
xmlrpc_DECREF(result);
@@ -307,7 +312,7 @@ int main(int argc, char **argv)
// When someone clones bug it has same duphash, so we can find more than 1.
// Need to be checked if component is same.
VERB3 log("Bugzilla has %i reports with same duphash '%s'",
- all_bugs_size, duphash);
+ all_bugs_size, rhbz.b_duphash);
int bug_id = -1;
struct bug_info *bz = NULL;
@@ -323,7 +328,7 @@ int main(int argc, char **argv)
free_bug_info(bz);
xmlrpc_value *result = rhbz_search_duphash(client, component_substitute,
- product_substitute, duphash);
+ product_substitute,
rhbz.b_duphash);
xmlrpc_value *all_bugs = rhbz_get_member("bugs", result);
xmlrpc_DECREF(result);
@@ -341,7 +346,7 @@ int main(int argc, char **argv)
{
/* Create new bug */
log(_("Creating a new bug"));
- bug_id = rhbz_new_bug(client, problem_data, rhbz.b_release, bug_id);
+ bug_id = rhbz_new_bug(client, problem_data,&rhbz, bug_id);
log(_("Adding attachments to bug %i"), bug_id);
char bug_id_str[sizeof(int)*3 + 2];
@@ -387,8 +392,6 @@ int main(int argc, char **argv)
const char *comment = get_problem_item_content_or_NULL(problem_data,
FILENAME_COMMENT);
if (comment&& comment[0])
{
- const char *package = get_problem_item_content_or_NULL(problem_data,
FILENAME_PACKAGE);
- const char *arch = get_problem_item_content_or_NULL(problem_data,
FILENAME_ARCHITECTURE);
const char *rating_str = get_problem_item_content_or_NULL(problem_data,
FILENAME_RATING);
struct strbuf *full_desc = strbuf_new();
@@ -397,15 +400,15 @@ int main(int argc, char **argv)
/* python doesn't have rating file */
if (rating_str)
strbuf_append_strf(full_desc, "%s: %s\n", FILENAME_RATING,
rating_str);
- strbuf_append_strf(full_desc, "Package: %s\n", package);
+ strbuf_append_strf(full_desc, "Package: %s\n", rhbz.b_package);
/* attach the architecture only if it's different from the initial
report */
if ((strcmp(bz->bi_platform, "All") != 0)&&
(strcmp(bz->bi_platform, "Unspecified") != 0)&&
- (strcmp(bz->bi_platform, arch) !=0))
- strbuf_append_strf(full_desc, "Architecture: %s\n", arch);
+ (strcmp(bz->bi_platform, rhbz.b_arch) !=0))
+ strbuf_append_strf(full_desc, "Architecture: %s\n",
rhbz.b_arch);
else
{
- VERB3 log("not adding the arch: %s because rep_plat is %s",
arch, bz->bi_platform);
+ VERB3 log("not adding the arch: %s because rep_plat is %s",
rhbz.b_arch, bz->bi_platform);
}
strbuf_append_strf(full_desc, "OS Release: %s\n",
rhbz.b_release);
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
index ebe3616..fbf5bba 100644
--- a/src/plugins/rhbz.c
+++ b/src/plugins/rhbz.c
@@ -383,94 +383,60 @@ struct bug_info *rhbz_bug_info(struct abrt_xmlrpc *ax, int bug_id)
/* suppress mail notify by {s:i} (nomail:1) (driven by flag) */
int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
- const char *release,
- int depend_on_bug)
+ struct bugzilla_struct *b, int depend_on_bug)
{
- const char *package = get_problem_item_content_or_NULL(problem_data,
- FILENAME_PACKAGE);
- const char *component = get_problem_item_content_or_NULL(problem_data,
- FILENAME_COMPONENT);
- if (!release)
- {
- release = get_problem_item_content_or_NULL(problem_data,
- FILENAME_OS_RELEASE);
- if (!release) /* Old dump dir format compat. Remove in abrt-2.1 */
- release = get_problem_item_content_or_NULL(problem_data,
"release");
- }
- const char *arch = get_problem_item_content_or_NULL(problem_data,
- FILENAME_ARCHITECTURE);
- const char *duphash = get_problem_item_content_or_NULL(problem_data,
- FILENAME_DUPHASH);
-//COMPAT, remove after 2.1 release
- if (!duphash) duphash = get_problem_item_content_or_NULL(problem_data,
-
"global_uuid");
- const char *reason = get_problem_item_content_or_NULL(problem_data,
- FILENAME_REASON);
- const char *function = get_problem_item_content_or_NULL(problem_data,
-
FILENAME_CRASH_FUNCTION);
- const char *analyzer = get_problem_item_content_or_NULL(problem_data,
- FILENAME_ANALYZER);
- const char *tainted_short = get_problem_item_content_or_NULL(problem_data,
-
FILENAME_TAINTED_SHORT);
-
struct strbuf *buf_summary = strbuf_new();
- if (analyzer&& strcmp(analyzer, "libreport") == 0)
+ if (b->b_analyzer&& strcmp(b->b_analyzer, "libreport") ==
0)
{
- strbuf_append_str(buf_summary, reason);
+ strbuf_append_str(buf_summary, b->b_reason);
}
else
{
- strbuf_append_strf(buf_summary, "[abrt] %s", package);
- if (function&& strlen(function)< 30)
- strbuf_append_strf(buf_summary, ": %s", function);
+ strbuf_append_strf(buf_summary, "[abrt] %s", b->b_package);
+ if (b->b_function&& strlen(b->b_function)< 30)
+ strbuf_append_strf(buf_summary, ": %s", b->b_function);
- if (reason)
- strbuf_append_strf(buf_summary, ": %s", reason);
+ if (b->b_reason)
+ strbuf_append_strf(buf_summary, ": %s", b->b_reason);
- if (tainted_short&& analyzer
-&& (strcmp(analyzer, "Kerneloops") == 0))
+ if (b->b_tainted_short&& b->b_analyzer
+&& (strcmp(b->b_analyzer, "Kerneloops") == 0))
{
- strbuf_append_strf(buf_summary, ": TAINTED %s", tainted_short);
+ strbuf_append_strf(buf_summary, ": TAINTED %s",
b->b_tainted_short);
}
}
- char *status_whiteboard = xasprintf("abrt_hash:%s", duphash);
+ char *status_whiteboard = xasprintf("abrt_hash:%s", b->b_duphash);
char *bz_dsc = make_description_bz(problem_data, CD_TEXT_ATT_SIZE_BZ);
char *full_dsc = xasprintf("libreport version: "VERSION"\n%s",
bz_dsc);
free(bz_dsc);
- char *product = NULL;
- char *version = NULL;
- parse_release_for_bz(release,&product,&version);
-
xmlrpc_value* result = NULL;
char *summary = strbuf_free_nobuf(buf_summary);
if (depend_on_bug> -1)
{
result = abrt_xmlrpc_call(ax, "Bug.create",
"({s:s,s:s,s:s,s:s,s:s,s:s,s:s,s:i})",
- "product", product,
- "component", component,
- "version", version,
+ "product", b->b_product,
+ "component", b->b_component,
+ "version", b->b_version,
"summary", summary,
"description", full_dsc,
"status_whiteboard", status_whiteboard,
- "platform", arch,
+ "platform", b->b_arch,
"dependson", depend_on_bug);
}
else
{
result = abrt_xmlrpc_call(ax, "Bug.create",
"({s:s,s:s,s:s,s:s,s:s,s:s,s:s})",
- "product", product,
- "component", component,
- "version", version,
+ "product", b->b_product,
+ "component", b->b_component,
+ "version", b->b_version,
"summary", summary,
"description", full_dsc,
"status_whiteboard", status_whiteboard,
- "platform", arch);
+ "platform", b->b_arch);
}
free(status_whiteboard);
- free(product);
- free(version);
free(summary);
free(full_dsc);
@@ -665,3 +631,9 @@ void rhbz_add_comment(struct abrt_xmlrpc *ax, int bug_id, const char
*comment,
if (result)
xmlrpc_DECREF(result);
}
+
+void rhbz_parse_release(struct bugzilla_struct *b)
+{
+ /* Fedora/RH bugzilla uses "Red Hat Enterprise Linux N" product RHEL */
+ parse_release(b->b_release,&b->b_product,&b->b_version,
/*append_rhel_version:*/ true);
+}
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
index 38c6430..d517052 100644
--- a/src/plugins/rhbz.h
+++ b/src/plugins/rhbz.h
@@ -65,9 +65,19 @@ struct bugzilla_struct {
const char *b_password;
const char *b_bugzilla_xmlrpc;
const char *b_bugzilla_url;
+ int b_ssl_verify;
+
+ const char *b_component;
const char *b_release;
+ const char *b_duphash;
+ const char *b_package;
+ const char *b_reason;
+ const char *b_function;
+ const char *b_tainted_short;
+ const char *b_analyzer;
+ const char *b_arch;
char *b_product;
- int b_ssl_verify;
+ char *b_version;
};
- since you want to represent the bug by this struct I think you should
add also a summary, so everything is on one place
- the rest seems ok
#define INIT_BUGZILLA(name) \
@@ -97,8 +107,8 @@ int rhbz_array_size(xmlrpc_value *xml);
int rhbz_bug_id(xmlrpc_value *xml);
int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
- const char *release,
- int depend_on_bug);
+ struct bugzilla_struct *b, int depend_on_bug);
+
int rhbz_attach_big_files(struct abrt_xmlrpc *ax, const char *bug_id,
problem_data_t *problem_data, int flags);
@@ -109,6 +119,8 @@ int rhbz_attach_blob(struct abrt_xmlrpc *ax, const char *filename,
int rhbz_attach_fd(struct abrt_xmlrpc *ax, const char *filename,
const char *bug_id, int fd, int flags);
+void rhbz_parse_release(struct bugzilla_struct *b);
+
int is_comment_dup(GList *comments, const char *comment);
GList *rhbz_bug_cc(xmlrpc_value *result_xml);