Jiri 8ad42fe
From b26c6d5a3b9aff0933fb9abd393fd3c5f3b6cd02 Mon Sep 17 00:00:00 2001
Jiri 8ad42fe
From: Nikola Pajkovsky <npajkovs@redhat.com>
Jiri 8ad42fe
Date: Mon, 5 Dec 2011 18:48:17 +0100
Jiri 8ad42fe
Subject: [PATCH 1/6] allow to specify bodh url and fix one NULL dereferencing
Jiri 8ad42fe
Jiri 8ad42fe
Signed-off-by: Nikola Pajkovsky <npajkovs@redhat.com>
Jiri 8ad42fe
---
Jiri 8ad42fe
 src/include/internal_libreport.h |    2 +-
Jiri 8ad42fe
 src/plugins/abrt-bodhi.c         |   20 ++++++++++++++++----
Jiri 8ad42fe
 2 files changed, 17 insertions(+), 5 deletions(-)
Jiri 8ad42fe
Jiri 8ad42fe
diff --git a/src/include/internal_libreport.h b/src/include/internal_libreport.h
Jiri 8ad42fe
index 4c50a26..c153aaa 100644
Jiri 8ad42fe
--- a/src/include/internal_libreport.h
Jiri 8ad42fe
+++ b/src/include/internal_libreport.h
Jiri 8ad42fe
@@ -715,7 +715,7 @@ struct options {
Jiri 8ad42fe
 #define OPT_LIST(     s, l, v, a, h) { OPTION_LIST     , (s), (l), (v), (a)  , (h) }
Jiri 8ad42fe
 
Jiri 8ad42fe
 #define OPT__VERBOSE(v)     OPT_BOOL('v', "verbose", (v), _("Be verbose"))
Jiri 8ad42fe
-#define OPT__DUMP_DIR(v)    OPT_STRING('d', "dump-dir", (v), "DIR", _("Dump directory"))
Jiri 8ad42fe
+#define OPT__DUMP_DIR(v)    OPT_STRING('d', "problem-dir", (v), "DIR", _("Problem directory"))
Jiri 8ad42fe
 
Jiri 8ad42fe
 #define parse_opts libreport_parse_opts
Jiri 8ad42fe
 unsigned parse_opts(int argc, char **argv, const struct options *opt,
Jiri 8ad42fe
diff --git a/src/plugins/abrt-bodhi.c b/src/plugins/abrt-bodhi.c
Jiri 8ad42fe
index 28aa439..3495c24 100644
Jiri 8ad42fe
--- a/src/plugins/abrt-bodhi.c
Jiri 8ad42fe
+++ b/src/plugins/abrt-bodhi.c
Jiri 8ad42fe
@@ -110,7 +110,7 @@
Jiri 8ad42fe
 }
Jiri 8ad42fe
 */
Jiri 8ad42fe
 
Jiri 8ad42fe
-static const char *const bodhi_url = "https://admin.fedoraproject.org/updates/%s";
Jiri 8ad42fe
+static const char *bodhi_url = "https://admin.fedoraproject.org/updates/";
Jiri 8ad42fe
 
Jiri 8ad42fe
 struct bodhi {
Jiri 8ad42fe
     char *nvr;
Jiri 8ad42fe
@@ -288,10 +288,10 @@ static GHashTable *bodhi_parse_json(json_object *json, const char *release)
Jiri 8ad42fe
 
Jiri 8ad42fe
 static GHashTable *bodhi_query_list(const char *query, const char *release)
Jiri 8ad42fe
 {
Jiri 8ad42fe
-    char *bodhi_url_bugs = xasprintf(bodhi_url, "list");
Jiri 8ad42fe
+    char *bodhi_url_bugs = xasprintf("%s/list", bodhi_url);
Jiri 8ad42fe
 
Jiri 8ad42fe
     abrt_post_state_t *post_state = new_abrt_post_state(
Jiri 8ad42fe
-        ABRT_POST_WANT_BODY|ABRT_POST_WANT_SSL_VERIFY);
Jiri 8ad42fe
+        ABRT_POST_WANT_BODY | ABRT_POST_WANT_SSL_VERIFY | ABRT_POST_WANT_ERROR_MSG);
Jiri 8ad42fe
 
Jiri 8ad42fe
     const char *headers[] = {
Jiri 8ad42fe
         "Accept: application/json",
Jiri 8ad42fe
@@ -301,6 +301,13 @@ static GHashTable *bodhi_query_list(const char *query, const char *release)
Jiri b86b7b8
     log(_("Searching for updates"));
Jiri 8ad42fe
     abrt_post_string(post_state, bodhi_url_bugs, "application/x-www-form-urlencoded",
Jiri 8ad42fe
                      headers, query);
Jiri 8ad42fe
+
Jiri 8ad42fe
+    if (post_state->http_resp_code != 200)
Jiri 8ad42fe
+    {
Jiri 8ad42fe
+        char *errmsg = post_state->curl_error_msg;
Jiri 8ad42fe
+        if (errmsg && errmsg[0])
Jiri 8ad42fe
+            error_msg_and_die("%s '%s'", errmsg, bodhi_url_bugs);
Jiri 8ad42fe
+    }
Jiri 8ad42fe
     free(bodhi_url_bugs);
Jiri 8ad42fe
 
Jiri 8ad42fe
 //    log("%s", post_state->body);
Jiri 8ad42fe
@@ -357,9 +364,11 @@ int main(int argc, char **argv)
Jiri 8ad42fe
     /* Keep enum above and order of options below in sync! */
Jiri 8ad42fe
     struct options program_options[] = {
Jiri 8ad42fe
         OPT__VERBOSE(&g_verbose),
Jiri 8ad42fe
+        OPT__DUMP_DIR(&dump_dir_path),
Jiri 8ad42fe
+        OPT_GROUP(""),
Jiri 8ad42fe
         OPT_STRING('b', "bugs", &bugs, "ID1[,ID2,...]" , _("List of bug ids")),
Jiri 8ad42fe
+        OPT_STRING('u', "url", &bodhi_url, "URL", _("Specify a bodhi server url")),
Jiri 8ad42fe
         OPT_OPTSTRING('r', "release", &release, "RELEASE", _("Specify a release")),
Jiri 8ad42fe
-        OPT__DUMP_DIR(&dump_dir_path),
Jiri 8ad42fe
         OPT_END()
Jiri 8ad42fe
     };
Jiri 8ad42fe
 
Jiri 8ad42fe
@@ -387,6 +396,9 @@ int main(int argc, char **argv)
Jiri 8ad42fe
         else
Jiri 8ad42fe
         {
Jiri 8ad42fe
             struct dump_dir *dd = dd_opendir(dump_dir_path, DD_OPEN_READONLY);
Jiri 8ad42fe
+            if (!dd)
Jiri 8ad42fe
+                xfunc_die();
Jiri 8ad42fe
+
Jiri 8ad42fe
             problem_data_t *problem_data = create_problem_data_from_dump_dir(dd);
Jiri 8ad42fe
             dd_close(dd);
Jiri 8ad42fe
             if (!problem_data)
Jiri 8ad42fe
-- 
Jiri 8ad42fe
1.7.7.3
Jiri 8ad42fe