|
|
27390d |
From 90884eeb92527a8f0dbc2d90b3665b40ada3d426 Mon Sep 17 00:00:00 2001
|
|
|
27390d |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
27390d |
Date: Fri, 21 Feb 2014 22:41:05 +0100
|
|
|
27390d |
Subject: [LIBREPORT PATCH 31/33] introduce import-event-options in xml event
|
|
|
27390d |
definitions
|
|
|
27390d |
|
|
|
27390d |
Related to rhbz#1069111
|
|
|
27390d |
|
|
|
27390d |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
27390d |
---
|
|
|
27390d |
src/include/event_config.h | 1 +
|
|
|
27390d |
src/lib/event_config.c | 49 +++++++++++++++++++++++++++++++++++++---------
|
|
|
27390d |
src/lib/event_xml_parser.c | 15 ++++++++++++++
|
|
|
27390d |
3 files changed, 56 insertions(+), 9 deletions(-)
|
|
|
27390d |
|
|
|
27390d |
diff --git a/src/include/event_config.h b/src/include/event_config.h
|
|
|
27390d |
index 24e1eac..e2fcc23 100644
|
|
|
27390d |
--- a/src/include/event_config.h
|
|
|
27390d |
+++ b/src/include/event_config.h
|
|
|
27390d |
@@ -81,6 +81,7 @@ typedef struct
|
|
|
27390d |
bool ec_skip_review;
|
|
|
27390d |
bool ec_sending_sensitive_data;
|
|
|
27390d |
|
|
|
27390d |
+ GList *ec_imported_event_names;
|
|
|
27390d |
GList *options;
|
|
|
27390d |
} event_config_t;
|
|
|
27390d |
|
|
|
27390d |
diff --git a/src/lib/event_config.c b/src/lib/event_config.c
|
|
|
27390d |
index 6d12695..b25517d 100644
|
|
|
27390d |
--- a/src/lib/event_config.c
|
|
|
27390d |
+++ b/src/lib/event_config.c
|
|
|
27390d |
@@ -112,10 +112,8 @@ void free_event_config(event_config_t *p)
|
|
|
27390d |
free(p->ec_exclude_items_by_default);
|
|
|
27390d |
free(p->ec_include_items_by_default);
|
|
|
27390d |
free(p->ec_exclude_items_always);
|
|
|
27390d |
- GList *opt;
|
|
|
27390d |
- for (opt = p->options; opt; opt = opt->next)
|
|
|
27390d |
- free_event_option(opt->data);
|
|
|
27390d |
- g_list_free(p->options);
|
|
|
27390d |
+ g_list_free_full(p->ec_imported_event_names, free);
|
|
|
27390d |
+ g_list_free_full(p->options, (GDestroyNotify)free_event_option);
|
|
|
27390d |
|
|
|
27390d |
free(p);
|
|
|
27390d |
}
|
|
|
27390d |
@@ -282,22 +280,54 @@ GList *export_event_config(const char *event_name)
|
|
|
27390d |
event_config_t *config = get_event_config(event_name);
|
|
|
27390d |
if (config)
|
|
|
27390d |
{
|
|
|
27390d |
+ GList *imported = config->ec_imported_event_names;
|
|
|
27390d |
+ while (imported)
|
|
|
27390d |
+ {
|
|
|
27390d |
+ GList *exported = export_event_config(/*Event name*/imported->data);
|
|
|
27390d |
+ while (exported)
|
|
|
27390d |
+ {
|
|
|
27390d |
+ if (!g_list_find_custom(env_list, exported->data, (GCompareFunc)strcmp))
|
|
|
27390d |
+ /* It is not necessary to make a copy of opt->eo_name */
|
|
|
27390d |
+ /* since its memory is owned by event_option_t and it */
|
|
|
27390d |
+ /* has global scope */
|
|
|
27390d |
+ env_list = g_list_prepend(env_list, exported->data);
|
|
|
27390d |
+
|
|
|
27390d |
+ exported = g_list_remove_link(exported, exported);
|
|
|
27390d |
+ }
|
|
|
27390d |
+
|
|
|
27390d |
+ imported = g_list_next(imported);
|
|
|
27390d |
+ }
|
|
|
27390d |
+
|
|
|
27390d |
GList *lopt;
|
|
|
27390d |
for (lopt = config->options; lopt; lopt = lopt->next)
|
|
|
27390d |
{
|
|
|
27390d |
event_option_t *opt = lopt->data;
|
|
|
27390d |
if (!opt->eo_value)
|
|
|
27390d |
continue;
|
|
|
27390d |
- char *var_val = xasprintf("%s=%s", opt->eo_name, opt->eo_value);
|
|
|
27390d |
- log_debug("Exporting '%s'", var_val);
|
|
|
27390d |
- env_list = g_list_prepend(env_list, var_val);
|
|
|
27390d |
- putenv(var_val);
|
|
|
27390d |
+
|
|
|
27390d |
+ log_debug("Exporting '%s=%s'", opt->eo_name, opt->eo_value);
|
|
|
27390d |
+
|
|
|
27390d |
+ /* Add the exported key only if it is not in the list */
|
|
|
27390d |
+ if (!g_list_find_custom(env_list, opt->eo_name, (GCompareFunc)strcmp))
|
|
|
27390d |
+ /* It is not necessary to make a copy of opt->eo_name */
|
|
|
27390d |
+ /* since its memory is owned by opt and it has global scope */
|
|
|
27390d |
+ env_list = g_list_prepend(env_list, opt->eo_name);
|
|
|
27390d |
+
|
|
|
27390d |
+ /* setenv() makes copies of strings */
|
|
|
27390d |
+ xsetenv(opt->eo_name, opt->eo_value);
|
|
|
27390d |
}
|
|
|
27390d |
}
|
|
|
27390d |
|
|
|
27390d |
return env_list;
|
|
|
27390d |
}
|
|
|
27390d |
|
|
|
27390d |
+/*
|
|
|
27390d |
+ * Goes through given list and calls unsetnev() for each list item.
|
|
|
27390d |
+ *
|
|
|
27390d |
+ * Accepts a list of 'const char *' type items which contains names of exported
|
|
|
27390d |
+ * environment variables and which was returned from export_event_config()
|
|
|
27390d |
+ * function.
|
|
|
27390d |
+ */
|
|
|
27390d |
void unexport_event_config(GList *env_list)
|
|
|
27390d |
{
|
|
|
27390d |
while (env_list)
|
|
|
27390d |
@@ -305,8 +335,9 @@ void unexport_event_config(GList *env_list)
|
|
|
27390d |
char *var_val = env_list->data;
|
|
|
27390d |
log_debug("Unexporting '%s'", var_val);
|
|
|
27390d |
safe_unsetenv(var_val);
|
|
|
27390d |
+
|
|
|
27390d |
+ /* The list doesn't own memory of values: see export_event_config() */
|
|
|
27390d |
env_list = g_list_remove(env_list, var_val);
|
|
|
27390d |
- free(var_val);
|
|
|
27390d |
}
|
|
|
27390d |
}
|
|
|
27390d |
|
|
|
27390d |
diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c
|
|
|
27390d |
index 1f98158..a15f1e1 100644
|
|
|
27390d |
--- a/src/lib/event_xml_parser.c
|
|
|
27390d |
+++ b/src/lib/event_xml_parser.c
|
|
|
27390d |
@@ -40,6 +40,7 @@
|
|
|
27390d |
#define EXCL_ALWAYS_ELEMENT "exclude-items-always"
|
|
|
27390d |
#define EXCL_BINARY_ELEMENT "exclude-binary-items"
|
|
|
27390d |
#define ADV_OPTIONS_ELEMENT "advanced-options"
|
|
|
27390d |
+#define IMPORT_OPTIONS_ELEMENT "import-event-options"
|
|
|
27390d |
|
|
|
27390d |
typedef struct
|
|
|
27390d |
{
|
|
|
27390d |
@@ -210,6 +211,20 @@ static void start_element(GMarkupParseContext *context,
|
|
|
27390d |
}
|
|
|
27390d |
}
|
|
|
27390d |
else
|
|
|
27390d |
+ if (strcmp(element_name, IMPORT_OPTIONS_ELEMENT) == 0)
|
|
|
27390d |
+ {
|
|
|
27390d |
+ if (attribute_names[0] == NULL
|
|
|
27390d |
+ || attribute_names[1] != NULL
|
|
|
27390d |
+ || strcmp(attribute_names[0], "event") != 0)
|
|
|
27390d |
+ {
|
|
|
27390d |
+ error_msg("XML event configuration error: import-event-options element misses attribute 'event'");
|
|
|
27390d |
+ return;
|
|
|
27390d |
+ }
|
|
|
27390d |
+
|
|
|
27390d |
+ GList *head = parse_data->event_config.values->ec_imported_event_names;
|
|
|
27390d |
+ parse_data->event_config.values->ec_imported_event_names = g_list_append(head, xstrdup(attribute_values[0]));
|
|
|
27390d |
+ }
|
|
|
27390d |
+ else
|
|
|
27390d |
if (strcmp(element_name, LABEL_ELEMENT) == 0
|
|
|
27390d |
|| strcmp(element_name, DESCRIPTION_ELEMENT) == 0
|
|
|
27390d |
|| strcmp(element_name, LONG_DESCR_ELEMENT) == 0
|
|
|
27390d |
--
|
|
|
27390d |
1.8.3.1
|
|
|
27390d |
|