Blame SOURCES/0016-cli-list-show-a-hint-about-creating-a-case-in-RHTS.patch

a60cd7
From 7966e5737e8d3af43b1ecdd6a823234b8d25931d Mon Sep 17 00:00:00 2001
a60cd7
From: Jakub Filak <jfilak@redhat.com>
a60cd7
Date: Wed, 22 Jan 2014 22:16:22 +0100
a60cd7
Subject: [ABRT PATCH 16/16] cli list: show a hint about creating a case in
a60cd7
 RHTS
a60cd7
a60cd7
Resolves rhbz#1055565
a60cd7
a60cd7
Signed-off-by: Jakub Filak <jfilak@redhat.com>
a60cd7
---
a60cd7
 configure.ac        |  2 ++
a60cd7
 src/cli/Makefile.am |  3 ++-
a60cd7
 src/cli/list.c      | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
a60cd7
 3 files changed, 53 insertions(+), 1 deletion(-)
a60cd7
a60cd7
diff --git a/configure.ac b/configure.ac
a60cd7
index 479289c..3bd13bc 100644
a60cd7
--- a/configure.ac
a60cd7
+++ b/configure.ac
a60cd7
@@ -137,6 +137,7 @@ PLUGINS_CONF_DIR='${sysconfdir}/${PACKAGE_NAME}/plugins'
a60cd7
 DEFAULT_PLUGINS_CONF_DIR='${datadir}/${PACKAGE_NAME}/conf.d/plugins'
a60cd7
 EVENTS_DIR='${datadir}/libreport/events'
a60cd7
 EVENTS_CONF_DIR='${sysconfdir}/libreport/events.d'
a60cd7
+WORKFLOWS_DIR='${datadir}/libreport/workflows'
a60cd7
 ENABLE_SOCKET_OR_DBUS='-DENABLE_DBUS=1'
a60cd7
 DEFAULT_DUMP_DIR_MODE=$($PKG_CONFIG --variable=dd_mode libreport)
a60cd7
 LIBREPORT_PLUGINS_CONF_DIR=$($PKG_CONFIG --variable=plugins_conf_dir libreport)
a60cd7
@@ -224,6 +225,7 @@ AC_SUBST(VAR_RUN)
a60cd7
 AC_SUBST(PLUGINS_CONF_DIR)
a60cd7
 AC_SUBST(DEFAULT_PLUGINS_CONF_DIR)
a60cd7
 AC_SUBST(EVENTS_CONF_DIR)
a60cd7
+AC_SUBST(WORKFLOWS_DIR)
a60cd7
 AC_SUBST(EVENTS_DIR)
a60cd7
 AC_SUBST(DEFAULT_DUMP_LOCATION)
a60cd7
 AC_SUBST(DEFAULT_DUMP_DIR_MODE)
a60cd7
diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
a60cd7
index 5b840ee..75efac5 100644
a60cd7
--- a/src/cli/Makefile.am
a60cd7
+++ b/src/cli/Makefile.am
a60cd7
@@ -15,7 +15,8 @@ abrt_cli_SOURCES = $(CLI_C) $(BUILTIN_C) builtin-cmd.h abrt-cli-core.h
a60cd7
 abrt_cli_CFLAGS = \
a60cd7
 	-I$(srcdir)/../include \
a60cd7
 	-I$(srcdir)/../lib \
a60cd7
-	$(LIBREPORT_CFLAGS)
a60cd7
+	$(LIBREPORT_CFLAGS) \
a60cd7
+	-DWORKFLOWS_DIR=\"${WORKFLOWS_DIR}\"
a60cd7
 
a60cd7
 if SUGGEST_AUTOREPORTING
a60cd7
 abrt_cli_CFLAGS += -DSUGGEST_AUTOREPORTING=1
a60cd7
diff --git a/src/cli/list.c b/src/cli/list.c
a60cd7
index 2eefcfe..b6b4790 100644
a60cd7
--- a/src/cli/list.c
a60cd7
+++ b/src/cli/list.c
a60cd7
@@ -80,6 +80,55 @@ static void print_crash(problem_data_t *problem_data, int detailed, int text_siz
a60cd7
                             /*names_to_skip:*/ NULL,
a60cd7
                             /*max_text_size:*/ text_size,
a60cd7
                             MAKEDESC_SHOW_ONLY_LIST | MAKEDESC_SHOW_URLS);
a60cd7
+
a60cd7
+        /*
a60cd7
+         * If the problem is reportable and has not yet been reported into RHTS
a60cd7
+         * and there is at least one applicable Workflow which contains
a60cd7
+         * 'report_RHTSupport' event, then append a short message informing
a60cd7
+         * user that he can create a new case in Red Hat Customer Portal.
a60cd7
+         */
a60cd7
+        const char *const not_reportable =  problem_data_get_content_or_NULL(problem_data, FILENAME_NOT_REPORTABLE);
a60cd7
+        const char *const reported_to    =  not_reportable            ? NULL : problem_data_get_content_or_NULL(problem_data, FILENAME_REPORTED_TO);
a60cd7
+        report_result_t *const report    = !reported_to               ? NULL : find_in_reported_to_data(reported_to, "RHTSupport");
a60cd7
+
a60cd7
+        if (!not_reportable && !report)
a60cd7
+        {
a60cd7
+            /* The lines below should be replaced by something simpler, I'd
a60cd7
+             * like to see:
a60cd7
+             * GHashTable *possible_worfklows = load_applicable_workflows_for_dump();
a60cd7
+             *
a60cd7
+             * However, this feature (rhbz#1055565) is intended for RHEL only
a60cd7
+             * and I'm not sure whether it's worth to file another bug against
a60cd7
+             * libreport and try to improve libreport public API.
a60cd7
+             */
a60cd7
+            const char *const dump_dir_name = problem_data_get_content_or_NULL(problem_data, CD_DUMPDIR);
a60cd7
+            GList *const wf_names = list_possible_events_glist(dump_dir_name, "workflow");
a60cd7
+            GHashTable *const possible_workflows = load_workflow_config_data_from_list(wf_names, WORKFLOWS_DIR);
a60cd7
+            g_list_free_full(wf_names, free);
a60cd7
+
a60cd7
+            int event_found = 0;
a60cd7
+
a60cd7
+            GHashTableIter iter;
a60cd7
+            gpointer key = NULL;
a60cd7
+            gpointer value = NULL;
a60cd7
+
a60cd7
+            g_hash_table_iter_init(&iter, possible_workflows);
a60cd7
+            while (!event_found && g_hash_table_iter_next(&iter, &key, &value))
a60cd7
+            {
a60cd7
+                GList *const event_names = wf_get_event_names((workflow_t *)value);
a60cd7
+                event_found = !!g_list_find_custom(event_names, "report_RHTSupport", (GCompareFunc)g_strcmp0);
a60cd7
+                g_list_free_full(event_names, free);
a60cd7
+            }
a60cd7
+
a60cd7
+            g_hash_table_destroy(possible_workflows);
a60cd7
+
a60cd7
+            if (event_found)
a60cd7
+            {
a60cd7
+                char *tmp = xasprintf("%sRun 'abrt-cli report %s' for creating a case in Red Hat Customer Portal\n", desc, dump_dir_name);
a60cd7
+                free(desc);
a60cd7
+                desc = tmp;
a60cd7
+            }
a60cd7
+        }
a60cd7
     }
a60cd7
     fputs(desc, stdout);
a60cd7
     free(desc);
a60cd7
-- 
a60cd7
1.8.3.1
a60cd7