Blame SOURCES/0084-rhtsupport-check-for-hints-only-when-creating-a-new-.patch

28bab8
From 5ff7f36c1a06f5317241b43999f4f03a21594c79 Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Tue, 23 Sep 2014 13:54:51 +0200
28bab8
Subject: [LIBREPORT PATCH 84/93] rhtsupport: check for hints only when
28bab8
 creating a new case
28bab8
28bab8
If the check for hints finds something, reporter-rhtsupport asks the
28bab8
user whether he wants to continue in creating a new case. While it is a
28bab8
useful feature, the reporter should ask that question only if the user
28bab8
runs the reporter with option -t (create a new case).
28bab8
28bab8
We also want to receive as many uReports as possible, so we need to
28bab8
submit uReport before checking for hints because the report might
28bab8
interrupt the reporting process in case of positive hints results.
28bab8
28bab8
Related to rhbz#1139987
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/plugins/reporter-rhtsupport.c | 120 ++++++++++++++++++++------------------
28bab8
 1 file changed, 63 insertions(+), 57 deletions(-)
28bab8
28bab8
diff --git a/src/plugins/reporter-rhtsupport.c b/src/plugins/reporter-rhtsupport.c
28bab8
index cd72c87..47e544d 100644
28bab8
--- a/src/plugins/reporter-rhtsupport.c
28bab8
+++ b/src/plugins/reporter-rhtsupport.c
28bab8
@@ -215,6 +215,56 @@ char *submit_ureport(const char *dump_dir_name, struct ureport_server_config *co
28bab8
 }
28bab8
 
28bab8
 static
28bab8
+bool check_for_hints(const char *url, const char *login, const char *password, bool ssl_verify, const char *tempfile)
28bab8
+{
28bab8
+    rhts_result_t *result = get_rhts_hints(url, login, password, ssl_verify, tempfile);
28bab8
+#if 0 /* testing */
28bab8
+    log("ERR:%d", result->error);
28bab8
+    log("MSG:'%s'", result->msg);
28bab8
+    log("BODY:'%s'", result->body);
28bab8
+    result->error = 0;
28bab8
+    result->body = xstrdup(
28bab8
+            ""
28bab8
+            "<problems xmlns=\"http://www.redhat.com/gss/strata\">"
28bab8
+            "<link uri=\"http://access.redhat.com/\" rel=\"help\">The main Red Hat Support web site</link>"
28bab8
+            "<property name=\"content\">an ABRT report</property>"
28bab8
+            "<problem>"
28bab8
+            "<property name=\"source\">a backtrace in the ABRT report</property>"
28bab8
+            "<link uri=\"https://avalon-ci.gss.redhat.com/kb/docs/DOC-22029\" rel=\"suggestion\">[RHEL 5.3] EVO autocompletion lookup hang</link>"
28bab8
+            "</problem>"
28bab8
+            "</problems>"
28bab8
+            );
28bab8
+#endif
28bab8
+    if (result->error)
28bab8
+    {
28bab8
+        /* We don't use result->msg here because it looks like this:
28bab8
+         *  Error in file upload at 'URL', HTTP code: 404,
28bab8
+         *  server says: '<error...>404<message>...</message></error>'
28bab8
+         * TODO: make server send bare textual msgs, not XML.
28bab8
+         */
28bab8
+        error_msg("Error in file upload at '%s', HTTP code: %d", url, result->http_resp_code);
28bab8
+    }
28bab8
+    else if (result->body)
28bab8
+    {
28bab8
+        /* The message might contain URLs to known solutions and such */
28bab8
+        char *hint = parse_response_from_RHTS_hint_xml2txt(result->body);
28bab8
+        if (hint)
28bab8
+        {
28bab8
+            hint = append_to_malloced_string(hint, " ");
28bab8
+            hint = append_to_malloced_string(hint,
28bab8
+                    _("Do you still want to create a RHTSupport ticket?")
28bab8
+                    );
28bab8
+            int create_ticket = ask_yes_no(hint);
28bab8
+            free(hint);
28bab8
+            if (!create_ticket)
28bab8
+                return true;
28bab8
+        }
28bab8
+    }
28bab8
+    free_rhts_result(result);
28bab8
+    return false;
28bab8
+}
28bab8
+
28bab8
+static
28bab8
 char *ask_rh_login(const char *message)
28bab8
 {
28bab8
     char *login = ask(message);
28bab8
@@ -519,63 +569,6 @@ int main(int argc, char **argv)
28bab8
 
28bab8
     off_t tempfile_size = stat_st_size_or_die(tempfile);
28bab8
 
28bab8
-    if (tempfile_size <= QUERY_HINTS_IF_SMALLER_THAN)
28bab8
-    {
28bab8
-        /* Check for hints and show them if we have something */
28bab8
-        log(_("Checking for hints"));
28bab8
-        result = get_rhts_hints(base_api_url,
28bab8
-                login,
28bab8
-                password,
28bab8
-                ssl_verify,
28bab8
-                tempfile
28bab8
-        );
28bab8
-#if 0 /* testing */
28bab8
-        log("ERR:%d", result->error);
28bab8
-        log("MSG:'%s'", result->msg);
28bab8
-        log("BODY:'%s'", result->body);
28bab8
-        result->error = 0;
28bab8
-        result->body = xstrdup(
28bab8
-        ""
28bab8
-        "<problems xmlns=\"http://www.redhat.com/gss/strata\">"
28bab8
-          "<link uri=\"http://access.redhat.com/\" rel=\"help\">The main Red Hat Support web site</link>"
28bab8
-          "<property name=\"content\">an ABRT report</property>"
28bab8
-          "<problem>"
28bab8
-            "<property name=\"source\">a backtrace in the ABRT report</property>"
28bab8
-            "<link uri=\"https://avalon-ci.gss.redhat.com/kb/docs/DOC-22029\" rel=\"suggestion\">[RHEL 5.3] EVO autocompletion lookup hang</link>"
28bab8
-          "</problem>"
28bab8
-        "</problems>"
28bab8
-        );
28bab8
-#endif
28bab8
-        if (result->error)
28bab8
-        {
28bab8
-            /* We don't use result->msg here because it looks like this:
28bab8
-             *  Error in file upload at 'URL', HTTP code: 404,
28bab8
-             *  server says: '<error...>404<message>...</message></error>'
28bab8
-             * TODO: make server send bare textual msgs, not XML.
28bab8
-             */
28bab8
-            error_msg("Error in file upload at '%s', HTTP code: %d",
28bab8
-                    base_api_url, result->http_resp_code);
28bab8
-        }
28bab8
-        if (result->error == 0 && result->body)
28bab8
-        {
28bab8
-            /* The message might contain URLs to known solutions and such */
28bab8
-            char *hint = parse_response_from_RHTS_hint_xml2txt(result->body);
28bab8
-            if (hint)
28bab8
-            {
28bab8
-                hint = append_to_malloced_string(hint, " ");
28bab8
-                hint = append_to_malloced_string(hint,
28bab8
-                        _("Do you still want to create a RHTSupport ticket?")
28bab8
-                );
28bab8
-                int create_ticket = ask_yes_no(hint);
28bab8
-                free(hint);
28bab8
-                if (!create_ticket)
28bab8
-                    goto ret;
28bab8
-            }
28bab8
-        }
28bab8
-        free_rhts_result(result);
28bab8
-        result = NULL;
28bab8
-    }
28bab8
-
28bab8
     if (!(opts & OPT_t))
28bab8
     {
28bab8
         char *bthash = NULL;
28bab8
@@ -593,6 +586,19 @@ int main(int argc, char **argv)
28bab8
             bthash = submit_ureport(dump_dir_name, &urconf);
28bab8
         }
28bab8
 
28bab8
+        if (tempfile_size <= QUERY_HINTS_IF_SMALLER_THAN)
28bab8
+        {
28bab8
+            /* Check for hints and show them if we have something */
28bab8
+            log(_("Checking for hints"));
28bab8
+            if (check_for_hints(base_api_url, login, password, ssl_verify, tempfile))
28bab8
+            {
28bab8
+                ureport_server_config_destroy(&urconf);
28bab8
+                free_map_string(ursettings);
28bab8
+                free(bthash);
28bab8
+                goto ret;
28bab8
+            }
28bab8
+        }
28bab8
+
28bab8
         log(_("Creating a new case"));
28bab8
 
28bab8
         char *product = NULL;
28bab8
-- 
28bab8
1.8.3.1
28bab8