Jiri Moskovcak 60afc81
From add5f6eed5cae2f0618707ed9c642f692426d8d7 Mon Sep 17 00:00:00 2001
Jiri Moskovcak 60afc81
From: Nikola Pajkovsky <npajkovs@redhat.com>
Jiri Moskovcak 60afc81
Date: Mon, 14 May 2012 13:53:51 +0200
Jiri Moskovcak 60afc81
Subject: [PATCH 2/3] bugzilla: query bz version and for 4.2 use 'id' element
Jiri Moskovcak 60afc81
 for getting bug number, for others use 'bug_id'
Jiri Moskovcak 60afc81
Jiri Moskovcak 60afc81
Signed-off-by: Nikola Pajkovsky <npajkovs@redhat.com>
Jiri Moskovcak 60afc81
---
Jiri Moskovcak 60afc81
 src/plugins/reporter-bugzilla.c |    8 ++++++--
Jiri Moskovcak 60afc81
 src/plugins/rhbz.c              |   28 ++++++++++++++++++++++++++--
Jiri Moskovcak 60afc81
 src/plugins/rhbz.h              |    3 ++-
Jiri Moskovcak 60afc81
 3 files changed, 34 insertions(+), 5 deletions(-)
Jiri Moskovcak 60afc81
Jiri Moskovcak 60afc81
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
Jiri Moskovcak 60afc81
index 6584f0f..3b6d168 100644
Jiri Moskovcak 60afc81
--- a/src/plugins/reporter-bugzilla.c
Jiri Moskovcak 60afc81
+++ b/src/plugins/reporter-bugzilla.c
Jiri Moskovcak 60afc81
@@ -168,8 +168,10 @@ int main(int argc, char **argv)
Jiri Moskovcak 60afc81
         int all_bugs_size = rhbz_array_size(all_bugs);
Jiri Moskovcak 60afc81
         if (all_bugs_size > 0)
Jiri Moskovcak 60afc81
         {
Jiri Moskovcak 60afc81
-            int bug_id = rhbz_bug_id(all_bugs);
Jiri Moskovcak 60afc81
+            char *rhbz_ver = rhbz_version(client);
Jiri Moskovcak 60afc81
+            int bug_id = rhbz_bug_id(all_bugs, rhbz_ver);
Jiri Moskovcak 60afc81
             printf("%i", bug_id);
Jiri Moskovcak 60afc81
+            free(rhbz_ver);
Jiri Moskovcak 60afc81
         }
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
         exit(EXIT_SUCCESS);
Jiri Moskovcak 60afc81
@@ -357,9 +359,11 @@ int main(int argc, char **argv)
Jiri Moskovcak 60afc81
         }
Jiri Moskovcak 60afc81
         else
Jiri Moskovcak 60afc81
         {
Jiri Moskovcak 60afc81
-            int bug_id = rhbz_bug_id(all_bugs);
Jiri Moskovcak 60afc81
+            char *rhbz_ver = rhbz_version(client);
Jiri Moskovcak 60afc81
+            int bug_id = rhbz_bug_id(all_bugs, rhbz_ver);
Jiri Moskovcak 60afc81
             xmlrpc_DECREF(all_bugs);
Jiri Moskovcak 60afc81
             bz = rhbz_bug_info(client, bug_id);
Jiri Moskovcak 60afc81
+            free(rhbz_ver);
Jiri Moskovcak 60afc81
         }
Jiri Moskovcak 60afc81
     }
Jiri Moskovcak 60afc81
     else
Jiri Moskovcak 60afc81
diff --git a/src/plugins/rhbz.c b/src/plugins/rhbz.c
Jiri Moskovcak 60afc81
index 24bec16..df2838f 100644
Jiri Moskovcak 60afc81
--- a/src/plugins/rhbz.c
Jiri Moskovcak 60afc81
+++ b/src/plugins/rhbz.c
Jiri Moskovcak 60afc81
@@ -243,8 +243,26 @@ int rhbz_array_size(xmlrpc_value *xml)
Jiri Moskovcak 60afc81
     return size;
Jiri Moskovcak 60afc81
 }
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
+
Jiri Moskovcak 60afc81
+char *rhbz_version(struct abrt_xmlrpc *ax)
Jiri Moskovcak 60afc81
+{
Jiri Moskovcak 60afc81
+    func_entry();
Jiri Moskovcak 60afc81
+
Jiri Moskovcak 60afc81
+    xmlrpc_value *result;
Jiri Moskovcak 60afc81
+    result = abrt_xmlrpc_call(ax, "Bugzilla.version", "()");
Jiri Moskovcak 60afc81
+
Jiri Moskovcak 60afc81
+    char *version = NULL;
Jiri Moskovcak 60afc81
+    if (result)
Jiri Moskovcak 60afc81
+    {
Jiri Moskovcak 60afc81
+        version = rhbz_bug_read_item("version", result, RHBZ_READ_STR);
Jiri Moskovcak 60afc81
+        xmlrpc_DECREF(result);
Jiri Moskovcak 60afc81
+    }
Jiri Moskovcak 60afc81
+
Jiri Moskovcak 60afc81
+    return version;
Jiri Moskovcak 60afc81
+}
Jiri Moskovcak 60afc81
+
Jiri Moskovcak 60afc81
 /* die or return bug id; each bug must have bug id otherwise xml is corrupted */
Jiri Moskovcak 60afc81
-int rhbz_bug_id(xmlrpc_value* xml)
Jiri Moskovcak 60afc81
+int rhbz_bug_id(xmlrpc_value* xml, const char *ver)
Jiri Moskovcak 60afc81
 {
Jiri Moskovcak 60afc81
     func_entry();
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
@@ -259,7 +277,13 @@ int rhbz_bug_id(xmlrpc_value* xml)
Jiri Moskovcak 60afc81
     if (env.fault_occurred)
Jiri Moskovcak 60afc81
         abrt_xmlrpc_die(&env;;
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
-    bug = rhbz_get_member("id", item);
Jiri Moskovcak 60afc81
+    char *id;
Jiri Moskovcak 60afc81
+    if (!prefixcmp(ver, "4.2"))
Jiri Moskovcak 60afc81
+        id = "id";
Jiri Moskovcak 60afc81
+    else
Jiri Moskovcak 60afc81
+        id = "bug_id";
Jiri Moskovcak 60afc81
+
Jiri Moskovcak 60afc81
+    bug = rhbz_get_member(id, item);
Jiri Moskovcak 60afc81
     xmlrpc_DECREF(item);
Jiri Moskovcak 60afc81
     if (!bug)
Jiri Moskovcak 60afc81
         abrt_xmlrpc_die(&env;;
Jiri Moskovcak 60afc81
diff --git a/src/plugins/rhbz.h b/src/plugins/rhbz.h
Jiri Moskovcak 60afc81
index c9023e9..85bcca1 100644
Jiri Moskovcak 60afc81
--- a/src/plugins/rhbz.h
Jiri Moskovcak 60afc81
+++ b/src/plugins/rhbz.h
Jiri Moskovcak 60afc81
@@ -97,7 +97,7 @@ xmlrpc_value *rhbz_get_member(const char *member, xmlrpc_value *xml);
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
 int rhbz_array_size(xmlrpc_value *xml);
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
-int rhbz_bug_id(xmlrpc_value *xml);
Jiri Moskovcak 60afc81
+int rhbz_bug_id(xmlrpc_value *xml, const char *ver);
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
 int rhbz_new_bug(struct abrt_xmlrpc *ax, problem_data_t *problem_data,
Jiri Moskovcak 60afc81
                  const char *release);
Jiri Moskovcak 60afc81
@@ -120,6 +120,7 @@ struct bug_info *rhbz_bug_info(struct abrt_xmlrpc *ax, int bug_id);
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
 struct bug_info *rhbz_find_origin_bug_closed_duplicate(struct abrt_xmlrpc *ax,
Jiri Moskovcak 60afc81
                                                        struct bug_info *bi);
Jiri Moskovcak 60afc81
+char *rhbz_version(struct abrt_xmlrpc *ax);
Jiri Moskovcak 60afc81
 
Jiri Moskovcak 60afc81
 #ifdef __cplusplus
Jiri Moskovcak 60afc81
 }
Jiri Moskovcak 60afc81
-- 
Jiri Moskovcak 60afc81
1.7.10.1
Jiri Moskovcak 60afc81