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

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