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

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