Blame SOURCES/0188-lib-move-CREATE_PRIVATE_TICKET-to-the-global-configu.patch

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