|
|
4b6aa8 |
From 8d8919987929cc5eb27e45dfc58f18b78dd0e484 Mon Sep 17 00:00:00 2001
|
|
|
4b6aa8 |
From: Matej Habrnal <mhabrnal@redhat.com>
|
|
|
4b6aa8 |
Date: Tue, 22 Mar 2016 15:15:43 +0100
|
|
|
4b6aa8 |
Subject: [PATCH] lib: move CREATE_PRIVATE_TICKET to the global configuration
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
The plugins should not rely directly on the environment variables. This
|
|
|
4b6aa8 |
patch should ensure that every one uses the same logic to interpret the
|
|
|
4b6aa8 |
environment variables.
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Related to rhbz#1279453
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
4b6aa8 |
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
|
|
|
4b6aa8 |
---
|
|
|
4b6aa8 |
src/gui-wizard-gtk/main.c | 1 +
|
|
|
4b6aa8 |
src/gui-wizard-gtk/wizard.c | 9 +----
|
|
|
4b6aa8 |
src/include/global_configuration.h | 15 +++++++++
|
|
|
4b6aa8 |
src/lib/global_configuration.c | 22 +++++++++++++
|
|
|
4b6aa8 |
src/plugins/reporter-bugzilla.c | 4 +--
|
|
|
4b6aa8 |
tests/global_config.at | 67 ++++++++++++++++++++++++++++++++++++++
|
|
|
4b6aa8 |
6 files changed, 107 insertions(+), 11 deletions(-)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
diff --git a/src/gui-wizard-gtk/main.c b/src/gui-wizard-gtk/main.c
|
|
|
4b6aa8 |
index 41a8089..1a10258 100644
|
|
|
4b6aa8 |
--- a/src/gui-wizard-gtk/main.c
|
|
|
4b6aa8 |
+++ b/src/gui-wizard-gtk/main.c
|
|
|
4b6aa8 |
@@ -186,6 +186,7 @@ int main(int argc, char **argv)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
g_dump_dir_name = xstrdup(argv[0]);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
+ load_global_configuration();
|
|
|
4b6aa8 |
/* load /etc/abrt/events/foo.{conf,xml} stuff
|
|
|
4b6aa8 |
and $XDG_CACHE_HOME/abrt/events/foo.conf */
|
|
|
4b6aa8 |
g_event_config_list = load_event_config_data();
|
|
|
4b6aa8 |
diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c
|
|
|
4b6aa8 |
index 17257ec..6a1bdc0 100644
|
|
|
4b6aa8 |
--- a/src/gui-wizard-gtk/wizard.c
|
|
|
4b6aa8 |
+++ b/src/gui-wizard-gtk/wizard.c
|
|
|
4b6aa8 |
@@ -2168,14 +2168,7 @@ static void add_warning(const char *warning)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
static void on_sensitive_ticket_clicked_cb(GtkWidget *button, gpointer user_data)
|
|
|
4b6aa8 |
{
|
|
|
4b6aa8 |
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
|
|
|
4b6aa8 |
- {
|
|
|
4b6aa8 |
- xsetenv(CREATE_PRIVATE_TICKET, "1");
|
|
|
4b6aa8 |
- }
|
|
|
4b6aa8 |
- else
|
|
|
4b6aa8 |
- {
|
|
|
4b6aa8 |
- safe_unsetenv(CREATE_PRIVATE_TICKET);
|
|
|
4b6aa8 |
- }
|
|
|
4b6aa8 |
+ set_global_create_private_ticket(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)), /*transient*/0);
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
static void on_privacy_info_btn(GtkWidget *button, gpointer user_data)
|
|
|
4b6aa8 |
diff --git a/src/include/global_configuration.h b/src/include/global_configuration.h
|
|
|
4b6aa8 |
index 9666796..bc5513d 100644
|
|
|
4b6aa8 |
--- a/src/include/global_configuration.h
|
|
|
4b6aa8 |
+++ b/src/include/global_configuration.h
|
|
|
4b6aa8 |
@@ -38,6 +38,21 @@ void free_global_configuration(void);
|
|
|
4b6aa8 |
#define get_global_always_excluded_elements libreport_get_global_always_excluded_elements
|
|
|
4b6aa8 |
string_vector_ptr_t get_global_always_excluded_elements(void);
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
+#define get_global_create_private_ticket libreport_get_global_create_private_ticket
|
|
|
4b6aa8 |
+bool get_global_create_private_ticket(void);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+/**
|
|
|
4b6aa8 |
+ * Configures the create private ticket global option
|
|
|
4b6aa8 |
+ *
|
|
|
4b6aa8 |
+ * The function changes the configuration only for the current process by
|
|
|
4b6aa8 |
+ * default.
|
|
|
4b6aa8 |
+ *
|
|
|
4b6aa8 |
+ * @param enabled The option's value
|
|
|
4b6aa8 |
+ * @param flags For future needs (enable persistent configuration)
|
|
|
4b6aa8 |
+ */
|
|
|
4b6aa8 |
+#define set_global_create_private_ticket libreport_set_global_create_private_ticket
|
|
|
4b6aa8 |
+void set_global_create_private_ticket(bool enabled, int flags);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
#ifdef __cplusplus
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
#endif
|
|
|
4b6aa8 |
diff --git a/src/lib/global_configuration.c b/src/lib/global_configuration.c
|
|
|
4b6aa8 |
index 903a2fb..ef921e9 100644
|
|
|
4b6aa8 |
--- a/src/lib/global_configuration.c
|
|
|
4b6aa8 |
+++ b/src/lib/global_configuration.c
|
|
|
4b6aa8 |
@@ -141,3 +141,25 @@ string_vector_ptr_t get_global_always_excluded_elements(void)
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
return ret;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+bool get_global_create_private_ticket(void)
|
|
|
4b6aa8 |
+{
|
|
|
4b6aa8 |
+ assert_global_configuration_initialized();
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ char *env_create_private = getenv(CREATE_PRIVATE_TICKET);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ if (env_create_private == NULL)
|
|
|
4b6aa8 |
+ return false;
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ return string_to_bool(env_create_private);
|
|
|
4b6aa8 |
+}
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+void set_global_create_private_ticket(bool enabled, int flags/*unused - persistent*/)
|
|
|
4b6aa8 |
+{
|
|
|
4b6aa8 |
+ assert_global_configuration_initialized();
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ if (enabled)
|
|
|
4b6aa8 |
+ xsetenv(CREATE_PRIVATE_TICKET, "1");
|
|
|
4b6aa8 |
+ else
|
|
|
4b6aa8 |
+ safe_unsetenv(CREATE_PRIVATE_TICKET);
|
|
|
4b6aa8 |
+}
|
|
|
4b6aa8 |
diff --git a/src/plugins/reporter-bugzilla.c b/src/plugins/reporter-bugzilla.c
|
|
|
4b6aa8 |
index d11fadf..941c91f 100644
|
|
|
4b6aa8 |
--- a/src/plugins/reporter-bugzilla.c
|
|
|
4b6aa8 |
+++ b/src/plugins/reporter-bugzilla.c
|
|
|
4b6aa8 |
@@ -740,9 +740,7 @@ static void set_settings(struct bugzilla_struct *b, map_string_t *settings)
|
|
|
4b6aa8 |
environ = getenv("Bugzilla_DontMatchComponents");
|
|
|
4b6aa8 |
b->b_DontMatchComponents = environ ? environ : get_map_string_item_or_empty(settings, "DontMatchComponents");
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
- environ = getenv(CREATE_PRIVATE_TICKET);
|
|
|
4b6aa8 |
- if (environ)
|
|
|
4b6aa8 |
- b->b_create_private = string_to_bool(environ);
|
|
|
4b6aa8 |
+ b->b_create_private = get_global_create_private_ticket();
|
|
|
4b6aa8 |
|
|
|
4b6aa8 |
if (!b->b_create_private)
|
|
|
4b6aa8 |
{
|
|
|
4b6aa8 |
diff --git a/tests/global_config.at b/tests/global_config.at
|
|
|
4b6aa8 |
index a6f5423..05a0ffa 100644
|
|
|
4b6aa8 |
--- a/tests/global_config.at
|
|
|
4b6aa8 |
+++ b/tests/global_config.at
|
|
|
4b6aa8 |
@@ -102,3 +102,70 @@ int main(int argc, char **argv)
|
|
|
4b6aa8 |
return EXIT_SUCCESS;
|
|
|
4b6aa8 |
}
|
|
|
4b6aa8 |
]])
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+## --------------------- ##
|
|
|
4b6aa8 |
+## create_private_ticket ##
|
|
|
4b6aa8 |
+## --------------------- ##
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+AT_TESTFUN([create_private_ticket],
|
|
|
4b6aa8 |
+[[
|
|
|
4b6aa8 |
+#include "testsuite.h"
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+TS_MAIN
|
|
|
4b6aa8 |
+{
|
|
|
4b6aa8 |
+ char cwd_buf[PATH_MAX + 1];
|
|
|
4b6aa8 |
+ static const char *dirs[] = {
|
|
|
4b6aa8 |
+ NULL,
|
|
|
4b6aa8 |
+ NULL,
|
|
|
4b6aa8 |
+ };
|
|
|
4b6aa8 |
+ dirs[0] = getcwd(cwd_buf, sizeof(cwd_buf));
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ static int dir_flags[] = {
|
|
|
4b6aa8 |
+ CONF_DIR_FLAG_NONE,
|
|
|
4b6aa8 |
+ -1,
|
|
|
4b6aa8 |
+ };
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ unlink("libreport.conf");
|
|
|
4b6aa8 |
+ FILE *lrf = fopen("libreport.conf", "wx");
|
|
|
4b6aa8 |
+ assert(lrf != NULL);
|
|
|
4b6aa8 |
+ fclose(lrf);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ assert(load_global_configuration_from_dirs(dirs, dir_flags));
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "False by default");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ set_global_create_private_ticket(false, 0);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Still false");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ set_global_create_private_ticket(true, 0);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_TRUE_MESSAGE(get_global_create_private_ticket(), "Configuration accepted");
|
|
|
4b6aa8 |
+ TS_ASSERT_STRING_EQ(getenv(CREATE_PRIVATE_TICKET), "1", "Correct ENVIRONMENT value");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ set_global_create_private_ticket(true, 0);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_TRUE_MESSAGE(get_global_create_private_ticket(), "Configuration sanity");
|
|
|
4b6aa8 |
+ TS_ASSERT_STRING_EQ(getenv(CREATE_PRIVATE_TICKET), "1", "Correct ENVIRONMENT value");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ set_global_create_private_ticket(false, 0);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Reverted back to False");
|
|
|
4b6aa8 |
+ TS_ASSERT_STRING_NULL_OR_EMPTY(getenv(CREATE_PRIVATE_TICKET), "Correct ENVIRONMENT value");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ xsetenv(CREATE_PRIVATE_TICKET, "1");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_TRUE_MESSAGE(get_global_create_private_ticket(), "Loaded from environment");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ unsetenv(CREATE_PRIVATE_TICKET);
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Reflects environment");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ xsetenv(CREATE_PRIVATE_TICKET, "0");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ TS_ASSERT_FALSE_MESSAGE(get_global_create_private_ticket(), "Zero is false");
|
|
|
4b6aa8 |
+
|
|
|
4b6aa8 |
+ free_global_configuration();
|
|
|
4b6aa8 |
+}
|
|
|
4b6aa8 |
+TS_RETURN_MAIN
|
|
|
4b6aa8 |
+]])
|
|
|
4b6aa8 |
--
|
|
|
4b6aa8 |
1.8.3.1
|
|
|
4b6aa8 |
|