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

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