From f2e2bba844ed36ab3b9ce0c936dad673cfc865b9 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 7 Mar 2011 15:36:07 +0100 Subject: added function to parse event description from xml file --- src/lib/Makefile.am | 3 +- src/lib/event_xml_parser.c | 186 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 src/lib/event_xml_parser.c (limited to 'src/lib') diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index bad3e63a..9e9a7324 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -43,7 +43,8 @@ libreport_la_SOURCES = \ hooklib.c hooklib.h \ parse_release.c \ parse_options.c parse_options.h \ - steal_directory.c + steal_directory.c \ + event_xml_parser.c libreport_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c new file mode 100644 index 00000000..6b562957 --- /dev/null +++ b/src/lib/event_xml_parser.c @@ -0,0 +1,186 @@ +//#include +#include +#include +#include +#include "event_xml_parser.h" + +#define EVENT_ELEMENT "event" +#define LABEL_ELEMENT "label" +#define DESCRIPTION_ELEMENT "description" +#define ALLOW_EMPTY_ELEMENT "allow-empty" +#define OPTION_ELEMENT "option" +#define ACTION_ELEMENT "action" +#define NAME_ELEMENT "name" + +int in_option = 0; + +static const char *option_types[] = +{ + "text", + "bool", + "password", + "number", + NULL +}; + +// Called for open tags +void start_element(GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + //g_print("start: %s\n", element_name); + + event_obj_t *ui = (event_obj_t *)user_data; + + if(strcmp(element_name, OPTION_ELEMENT) == 0) + { + if(in_option == 0) + { + in_option = 1; + event_option_obj_t *option = (event_option_obj_t *)malloc(sizeof(event_option_obj_t)); + //we need to prepend, so ui->options always points to the last created option + ui->options = g_list_prepend(ui->options, option); + + int i; + for(i = 0; attribute_names[i] != NULL; ++i) + { + //g_print("attr: %s:%s\n", attribute_names[i], attribute_values[i]); + if(strcmp(attribute_names[i], "name") == 0) + option->name = strdup(attribute_values[i]); + if(strcmp(attribute_names[i], "type") == 0) + { + option_type_t type = 0; + for(type = OPTION_TYPE_TEXT; type < OPTION_TYPE_INVALID; ++type) + { + if(strcmp(option_types[type], attribute_values[i]) == 0) + option->type = type; + } + } + } + } + else + { + g_print("error, option nested in option!\n"); + exit(-127); + } + } + +} + + // Called for close tags +void end_element(GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + event_obj_t *ui = (event_obj_t *)user_data; + if(strcmp(element_name, OPTION_ELEMENT) == 0) + { + in_option = 0; + } + if(strcmp(element_name, EVENT_ELEMENT) == 0) + { + //we need to revers the list, because we we're prepending + ui->options = g_list_reverse(ui->options); + in_option = 0; + } +} + + // Called for character data + // text is not nul-terminated +void text(GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error) +{ + event_obj_t *ui = (event_obj_t *)user_data; + const gchar * inner_element = g_markup_parse_context_get_element(context); + char *_text = (char *)malloc(text_len+1); + strncpy(_text, text, text_len); + _text[text_len] = '\0'; + if(in_option == 1) + { + event_option_obj_t *option = (event_option_obj_t *)((ui->options)->data); + if(strcmp(inner_element, LABEL_ELEMENT) == 0) + { + //g_print("\tnew label: \t\t%s\n", _text); + option->label = _text; + } + if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) + { + //g_print("\ttooltip: \t\t%s\n", _text); + option->description = _text; + } + } + else + { + /* we're not in option, so the description is for the event */ + if(strcmp(inner_element, ACTION_ELEMENT) == 0) + { + //g_print("\taction description: \t%s\n", _text); + ui->action = _text; + } + if(strcmp(inner_element, NAME_ELEMENT) == 0) + { + //g_print("\tevent name: \t\t%s\n", _text); + ui->name = _text; + } + } + //will be freed when the event_option is freed + //free(_text); +} + + // Called for strings that should be re-saved verbatim in this same + // position, but are not otherwise interpretable. At the moment + // this includes comments and processing instructions. + // text is not nul-terminated +void passthrough(GMarkupParseContext *context, + const gchar *passthrough_text, + gsize text_len, + gpointer user_data, + GError **error) +{ + g_print("passthrough\n"); +} + +// Called on error, including one set by other +// methods in the vtable. The GError should not be freed. +void error(GMarkupParseContext *context, + GError *error, + gpointer user_data) +{ + g_print("error\n"); +} + +/* this function takes 2 parameters + * ui -> pointer to event_obj_t + * filename -> filename to read + * event_obj_t contains list of options, which is malloced by hits function + * and must be freed by the caller + */ + +void load_event_from_file(event_obj_t *ui, const char* filename) +{ + GMarkupParser parser; + parser.start_element = &start_element; + parser.end_element = &end_element; + parser.text = &text; + parser.passthrough = &passthrough; + parser.error = &error; + GMarkupParseContext *context = g_markup_parse_context_new( + &parser, G_MARKUP_TREAT_CDATA_AS_TEXT, + ui, NULL); + FILE* fin = fopen(filename, "r"); + size_t read_bytes = 0; + char buff[1024] = {'\0'}; + while((read_bytes = fread(buff, 1, 1024, fin))) + { + g_markup_parse_context_parse(context, buff, read_bytes, NULL); + } + fclose(fin); + free(context); +} -- cgit From bad8487bf919ba4b221b7be065c346221943812c Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 7 Mar 2011 15:47:54 +0100 Subject: minor build fixes --- src/lib/event_xml_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index 6b562957..d429291f 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -163,7 +163,7 @@ void error(GMarkupParseContext *context, * and must be freed by the caller */ -void load_event_from_file(event_obj_t *ui, const char* filename) +void load_event_description_from_file(event_obj_t *ui, const char* filename) { GMarkupParser parser; parser.start_element = &start_element; -- cgit From d18a48afc602a19130d13af6097df566fa260690 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 7 Mar 2011 16:11:33 +0100 Subject: event_option_obj_t -> event_option_t, event_obj_t -> event_config_t --- src/lib/event_xml_parser.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index d429291f..da56a51c 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -33,14 +33,14 @@ void start_element(GMarkupParseContext *context, { //g_print("start: %s\n", element_name); - event_obj_t *ui = (event_obj_t *)user_data; + event_config_t *ui = (event_config_t *)user_data; if(strcmp(element_name, OPTION_ELEMENT) == 0) { if(in_option == 0) { in_option = 1; - event_option_obj_t *option = (event_option_obj_t *)malloc(sizeof(event_option_obj_t)); + event_option_t *option = (event_option_t *)malloc(sizeof(event_option_t)); //we need to prepend, so ui->options always points to the last created option ui->options = g_list_prepend(ui->options, option); @@ -76,7 +76,7 @@ void end_element(GMarkupParseContext *context, gpointer user_data, GError **error) { - event_obj_t *ui = (event_obj_t *)user_data; + event_config_t *ui = (event_config_t *)user_data; if(strcmp(element_name, OPTION_ELEMENT) == 0) { in_option = 0; @@ -97,14 +97,14 @@ void text(GMarkupParseContext *context, gpointer user_data, GError **error) { - event_obj_t *ui = (event_obj_t *)user_data; + event_config_t *ui = (event_config_t *)user_data; const gchar * inner_element = g_markup_parse_context_get_element(context); char *_text = (char *)malloc(text_len+1); strncpy(_text, text, text_len); _text[text_len] = '\0'; if(in_option == 1) { - event_option_obj_t *option = (event_option_obj_t *)((ui->options)->data); + event_option_t *option = (event_option_t *)((ui->options)->data); if(strcmp(inner_element, LABEL_ELEMENT) == 0) { //g_print("\tnew label: \t\t%s\n", _text); @@ -157,13 +157,13 @@ void error(GMarkupParseContext *context, } /* this function takes 2 parameters - * ui -> pointer to event_obj_t + * ui -> pointer to event_config_t * filename -> filename to read - * event_obj_t contains list of options, which is malloced by hits function + * event_config_t contains list of options, which is malloced by hits function * and must be freed by the caller */ -void load_event_description_from_file(event_obj_t *ui, const char* filename) +void load_event_description_from_file(event_config_t *event_config, const char* filename) { GMarkupParser parser; parser.start_element = &start_element; @@ -173,7 +173,7 @@ void load_event_description_from_file(event_obj_t *ui, const char* filename) parser.error = &error; GMarkupParseContext *context = g_markup_parse_context_new( &parser, G_MARKUP_TREAT_CDATA_AS_TEXT, - ui, NULL); + event_config, NULL); FILE* fin = fopen(filename, "r"); size_t read_bytes = 0; char buff[1024] = {'\0'}; -- cgit From 75d2a56b6420fd65f596b8ee18b02e121147ea4e Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 7 Mar 2011 17:09:43 +0100 Subject: renamed some files, no code changes --- src/lib/event_xml_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index da56a51c..7b9edc4f 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -2,7 +2,7 @@ #include #include #include -#include "event_xml_parser.h" +#include "event_config.h" #define EVENT_ELEMENT "event" #define LABEL_ELEMENT "label" -- cgit From 62890f4365ce10d71d1e122aec1d65566825b1f6 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Mon, 7 Mar 2011 17:32:37 +0100 Subject: added event_config.c stub --- src/lib/Makefile.am | 3 ++- src/lib/event_config.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/lib/event_config.c (limited to 'src/lib') diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 9e9a7324..4f800a0e 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -44,7 +44,8 @@ libreport_la_SOURCES = \ parse_release.c \ parse_options.c parse_options.h \ steal_directory.c \ - event_xml_parser.c + event_xml_parser.c \ + event_config.c libreport_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ diff --git a/src/lib/event_config.c b/src/lib/event_config.c new file mode 100644 index 00000000..77cbaf4b --- /dev/null +++ b/src/lib/event_config.c @@ -0,0 +1,26 @@ +#include "event_config.h" + +GHashTable *g_event_config_list; + +// (Re)loads data from /etc/abrt/events/*.{conf,xml} +void load_event_config_data(void) +{ + /* for each xml file call load_event_description_from_file */ + /* for each conf file call load_even_options_value_from_file? + * - we don't have this + * - should re-use the event_config structure created when parsing xml - if exists + * - or should this one be called first? + */ +} +/* Frees all loaded data */ +void free_event_config_data(void) +{ + +} + +event_config_t *get_event_config(const char *name) +{ + //could g_event_config_list be null? + gpointer event_config = g_hash_table_lookup(g_event_config_list, name); + return event_config; +} -- cgit From ef47609ab73ba222e0ef9f2da51dca4650af69d8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 21:49:51 +0100 Subject: gui-wizard-gtk: add code to export/unexport config variables. Untested Signed-off-by: Denys Vlasenko --- src/lib/xfuncs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/lib') diff --git a/src/lib/xfuncs.c b/src/lib/xfuncs.c index f451693a..3766d231 100644 --- a/src/lib/xfuncs.c +++ b/src/lib/xfuncs.c @@ -215,6 +215,20 @@ void xsetenv(const char *key, const char *value) die_out_of_memory(); } +void safe_unsetenv(const char *var_val) +{ + //char *name = xstrndup(var_val, strchrnul(var_val, '=') - var_val); + //unsetenv(name); + //free(name); + + /* Avoid malloc/free (name is usually very short) */ + unsigned len = strchrnul(var_val, '=') - var_val; + char name[len + 1]; + memcpy(name, var_val, len); + name[len] = '\0'; + unsetenv(name); +} + // Die with an error message if we can't open a new socket. int xsocket(int domain, int type, int protocol) { -- cgit From 077b157218254437185b5cb9d0267df72a918b79 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 7 Mar 2011 21:58:08 +0100 Subject: Fixes for g_event_config_list == NULL Signed-off-by: Denys Vlasenko --- src/lib/event_config.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 77cbaf4b..3eebb197 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -5,6 +5,7 @@ GHashTable *g_event_config_list; // (Re)loads data from /etc/abrt/events/*.{conf,xml} void load_event_config_data(void) { + free_event_config_data(); /* for each xml file call load_event_description_from_file */ /* for each conf file call load_even_options_value_from_file? * - we don't have this @@ -12,15 +13,20 @@ void load_event_config_data(void) * - or should this one be called first? */ } + /* Frees all loaded data */ void free_event_config_data(void) { - + if (g_event_config_list) + { + g_hash_table_destroy(g_event_config_list); + g_event_config_list = NULL; + } } event_config_t *get_event_config(const char *name) { - //could g_event_config_list be null? - gpointer event_config = g_hash_table_lookup(g_event_config_list, name); - return event_config; + if (!g_event_config_list) + return NULL; + return g_hash_table_lookup(g_event_config_list, name); } -- cgit From abb11fca1bcd7932d14c911d63fb7c6c347dcbcd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 14:07:33 +0100 Subject: make fork_execv_on_steroids capable of setting env vars too Before, it could only unset them. Signed-off-by: Denys Vlasenko --- src/lib/run_event.c | 14 +++++++++----- src/lib/spawn.c | 12 +++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/lib') diff --git a/src/lib/run_event.c b/src/lib/run_event.c index a2bbc76b..3d2b3a22 100644 --- a/src/lib/run_event.c +++ b/src/lib/run_event.c @@ -245,18 +245,19 @@ int spawn_next_command(struct run_event_state *state, VERB1 log("Executing '%s'", cmd); /* Export some useful environment variables for children */ + char *env_vec[3]; /* Just exporting dump_dir_name isn't always ok: it can be "." * and some children want to cd to other directory but still * be able to find dump directory by using $DUMP_DIR... */ char *full_name = realpath(dump_dir_name, NULL); - setenv("DUMP_DIR", (full_name ? full_name : dump_dir_name), 1); + env_vec[0] = xasprintf("DUMP_DIR=%s", (full_name ? full_name : dump_dir_name)); free(full_name); - setenv("EVENT", event, 1); -//FIXME: set vars in the child, not here! Need to improve fork_execv_on_steroids... + env_vec[1] = xasprintf("EVENT=%s", event); + env_vec[2] = NULL; char *argv[4]; - argv[0] = (char*)"/bin/sh"; + argv[0] = (char*)"/bin/sh"; // TODO: honor $SHELL? argv[1] = (char*)"-c"; argv[2] = cmd; argv[3] = NULL; @@ -266,12 +267,15 @@ int spawn_next_command(struct run_event_state *state, EXECFLG_INPUT_NUL + EXECFLG_OUTPUT + EXECFLG_ERR2OUT, argv, pipefds, - /* unsetenv_vec: */ NULL, + /* env_vec: */ env_vec, /* dir: */ dump_dir_name, /* uid(unused): */ 0 ); state->command_out_fd = pipefds[0]; + free(env_vec[0]); + free(env_vec[1]); + state->commands = g_list_remove(state->commands, cmd); return 0; diff --git a/src/lib/spawn.c b/src/lib/spawn.c index f6b7263c..188b63bd 100644 --- a/src/lib/spawn.c +++ b/src/lib/spawn.c @@ -32,7 +32,7 @@ static char *concat_str_vector(char **strings) pid_t fork_execv_on_steroids(int flags, char **argv, int *pipefds, - char **unsetenv_vec, + char **env_vec, const char *dir, uid_t uid) { @@ -69,9 +69,11 @@ pid_t fork_execv_on_steroids(int flags, xsetreuid(uid, uid); } - if (unsetenv_vec) { - while (*unsetenv_vec) - unsetenv(*unsetenv_vec++); + if (env_vec) { + /* Note: we use the glibc extension that putenv("var") + * *unsets* $var if "var" string has no '=' */ + while (*env_vec) + putenv(*env_vec++); } /* Play with stdio descriptors */ @@ -134,7 +136,7 @@ char *run_in_shell_and_save_output(int flags, const char *argv[] = { "/bin/sh", "-c", cmd, NULL }; int pipeout[2]; pid_t child = fork_execv_on_steroids(flags, (char **)argv, pipeout, - /*unsetenv_vec:*/ NULL, dir, /*uid (unused):*/ 0); + /*env_vec:*/ NULL, dir, /*uid (unused):*/ 0); size_t pos = 0; char *result = NULL; -- cgit From 02ba31ab300c06461d444f53139dd3712700abf5 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 8 Mar 2011 14:13:51 +0100 Subject: silence the output --- src/lib/event_xml_parser.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index 7b9edc4f..ee22102e 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -2,6 +2,7 @@ #include #include #include +#include "abrtlib.h" #include "event_config.h" #define EVENT_ELEMENT "event" @@ -42,12 +43,13 @@ void start_element(GMarkupParseContext *context, in_option = 1; event_option_t *option = (event_option_t *)malloc(sizeof(event_option_t)); //we need to prepend, so ui->options always points to the last created option + VERB2 log("adding option\n"); ui->options = g_list_prepend(ui->options, option); int i; for(i = 0; attribute_names[i] != NULL; ++i) { - //g_print("attr: %s:%s\n", attribute_names[i], attribute_values[i]); + VERB2 log("attr: %s:%s\n", attribute_names[i], attribute_values[i]); if(strcmp(attribute_names[i], "name") == 0) option->name = strdup(attribute_values[i]); if(strcmp(attribute_names[i], "type") == 0) @@ -107,12 +109,12 @@ void text(GMarkupParseContext *context, event_option_t *option = (event_option_t *)((ui->options)->data); if(strcmp(inner_element, LABEL_ELEMENT) == 0) { - //g_print("\tnew label: \t\t%s\n", _text); + VERB2 log("\tnew label: \t\t%s\n", _text); option->label = _text; } if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) { - //g_print("\ttooltip: \t\t%s\n", _text); + VERB2 log("\ttooltip: \t\t%s\n", _text); option->description = _text; } } @@ -144,7 +146,7 @@ void passthrough(GMarkupParseContext *context, gpointer user_data, GError **error) { - g_print("passthrough\n"); + VERB2 log("passthrough\n"); } // Called on error, including one set by other -- cgit From f6ac33ecf6635bbb34e2da196f0cab6f92724907 Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 8 Mar 2011 14:52:25 +0100 Subject: event_xml_parser: minor fixes based on review from Denys --- src/lib/event_xml_parser.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index ee22102e..6f23cfb3 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -15,7 +15,7 @@ int in_option = 0; -static const char *option_types[] = +static const char *const option_types[] = { "text", "bool", @@ -25,7 +25,7 @@ static const char *option_types[] = }; // Called for open tags -void start_element(GMarkupParseContext *context, +static void start_element(GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, @@ -43,7 +43,7 @@ void start_element(GMarkupParseContext *context, in_option = 1; event_option_t *option = (event_option_t *)malloc(sizeof(event_option_t)); //we need to prepend, so ui->options always points to the last created option - VERB2 log("adding option\n"); + VERB2 log("adding option"); ui->options = g_list_prepend(ui->options, option); int i; @@ -66,14 +66,13 @@ void start_element(GMarkupParseContext *context, else { g_print("error, option nested in option!\n"); - exit(-127); } } } // Called for close tags -void end_element(GMarkupParseContext *context, +static void end_element(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error) @@ -93,7 +92,7 @@ void end_element(GMarkupParseContext *context, // Called for character data // text is not nul-terminated -void text(GMarkupParseContext *context, +static void text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, @@ -109,12 +108,12 @@ void text(GMarkupParseContext *context, event_option_t *option = (event_option_t *)((ui->options)->data); if(strcmp(inner_element, LABEL_ELEMENT) == 0) { - VERB2 log("\tnew label: \t\t%s\n", _text); + VERB2 log("\tnew label: \t\t%s", _text); option->label = _text; } if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) { - VERB2 log("\ttooltip: \t\t%s\n", _text); + VERB2 log("\ttooltip: \t\t%s", _text); option->description = _text; } } @@ -123,12 +122,12 @@ void text(GMarkupParseContext *context, /* we're not in option, so the description is for the event */ if(strcmp(inner_element, ACTION_ELEMENT) == 0) { - //g_print("\taction description: \t%s\n", _text); + VERB2 log("\taction description: \t%s", _text); ui->action = _text; } if(strcmp(inner_element, NAME_ELEMENT) == 0) { - //g_print("\tevent name: \t\t%s\n", _text); + VERB2 log("\tevent name: \t\t%s", _text); ui->name = _text; } } @@ -140,18 +139,18 @@ void text(GMarkupParseContext *context, // position, but are not otherwise interpretable. At the moment // this includes comments and processing instructions. // text is not nul-terminated -void passthrough(GMarkupParseContext *context, +static void passthrough(GMarkupParseContext *context, const gchar *passthrough_text, gsize text_len, gpointer user_data, GError **error) { - VERB2 log("passthrough\n"); + VERB2 log("passthrough"); } // Called on error, including one set by other // methods in the vtable. The GError should not be freed. -void error(GMarkupParseContext *context, +static void error(GMarkupParseContext *context, GError *error, gpointer user_data) { @@ -178,11 +177,11 @@ void load_event_description_from_file(event_config_t *event_config, const char* event_config, NULL); FILE* fin = fopen(filename, "r"); size_t read_bytes = 0; - char buff[1024] = {'\0'}; + char buff[1024]; while((read_bytes = fread(buff, 1, 1024, fin))) { g_markup_parse_context_parse(context, buff, read_bytes, NULL); } fclose(fin); - free(context); + g_markup_parse_context_free(context); } -- cgit From a6ee8958dbe6f45f95fca4fa2ea1490c7035be65 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 8 Mar 2011 16:23:31 +0100 Subject: implement load_event_config_data. Untested. Signed-off-by: Denys Vlasenko --- src/lib/Makefile.am | 13 ++++-- src/lib/event_config.c | 82 ++++++++++++++++++++++++++++++++++---- src/lib/event_xml_parser.c | 98 ++++++++++++++++++++++++---------------------- 3 files changed, 136 insertions(+), 57 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 4f800a0e..863a0448 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -49,12 +49,13 @@ libreport_la_SOURCES = \ libreport_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -DLOCALSTATEDIR='"$(localstatedir)"' \ + -DVAR_RUN=\"$(VAR_RUN)\" \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ - -DLOCALSTATEDIR='"$(localstatedir)"' \ -DCONF_DIR=\"$(CONF_DIR)\" \ - -DVAR_RUN=\"$(VAR_RUN)\" \ + -DEVENTS_DIR=\"$(EVENTS_DIR)\" \ $(GLIB_CFLAGS) \ -D_GNU_SOURCE libreport_la_LDFLAGS = \ @@ -66,11 +67,13 @@ libabrt_dbus_la_SOURCES = \ abrt_dbus.c abrt_dbus.h libabrt_dbus_la_CPPFLAGS = \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -DLOCALSTATEDIR='"$(localstatedir)"' \ + -DVAR_RUN=\"$(VAR_RUN)\" \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ -DCONF_DIR=\"$(CONF_DIR)\" \ - -DVAR_RUN=\"$(VAR_RUN)\" \ + -DEVENTS_DIR=\"$(EVENTS_DIR)\" \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ -Wall -Werror \ @@ -87,11 +90,13 @@ libabrt_web_la_SOURCES = \ libabrt_web_la_CPPFLAGS = \ -Wall -Werror \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ + -DLOCALSTATEDIR='"$(localstatedir)"' \ + -DVAR_RUN=\"$(VAR_RUN)\" \ -DDEBUG_DUMPS_DIR=\"$(DEBUG_DUMPS_DIR)\" \ -DPLUGINS_LIB_DIR=\"$(PLUGINS_LIB_DIR)\" \ -DPLUGINS_CONF_DIR=\"$(PLUGINS_CONF_DIR)\" \ -DCONF_DIR=\"$(CONF_DIR)\" \ - -DVAR_RUN=\"$(VAR_RUN)\" \ + -DEVENTS_DIR=\"$(EVENTS_DIR)\" \ $(GLIB_CFLAGS) \ $(CURL_CFLAGS) \ $(LIBXML_CFLAGS) \ diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 3eebb197..18019178 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -1,17 +1,85 @@ -#include "event_config.h" +#include "abrtlib.h" GHashTable *g_event_config_list; +event_option_t *new_event_option(void) +{ + return xzalloc(sizeof(event_option_t)); +} + +event_config_t *new_event_config(void) +{ + return xzalloc(sizeof(event_config_t)); +} + +void free_event_option(event_option_t *p) +{ + if (!p) + return; + free(p->name); + free(p->value); + free(p->label); + free(p->description); + free(p->allowed_value); + free(p); +} + +void free_event_config(event_config_t *p) +{ + if (!p) + return; + free(p->name); + free(p->title); + free(p->action); + for (GList *opt = p->options; opt; opt = opt->next) + free_event_option(opt->data); + g_list_free(p->options); + free(p); +} + + // (Re)loads data from /etc/abrt/events/*.{conf,xml} void load_event_config_data(void) { free_event_config_data(); - /* for each xml file call load_event_description_from_file */ - /* for each conf file call load_even_options_value_from_file? - * - we don't have this - * - should re-use the event_config structure created when parsing xml - if exists - * - or should this one be called first? - */ + + DIR *dir = opendir(EVENTS_DIR); + if (!dir) + return; + + if (!g_event_config_list) + g_event_config_list = g_hash_table_new_full( + /*hash_func*/ g_str_hash, + /*key_equal_func:*/ g_str_equal, + /*key_destroy_func:*/ free, + /*value_destroy_func:*/ (GDestroyNotify) free_event_config + ); + + struct dirent *dent; + while ((dent = readdir(dir)) != NULL) + { + char *ext = strrchr(dent->d_name, '.'); + if (!ext) + continue; + ext++; + bool conf = strcmp(ext, "conf") == 0; + bool xml = strcmp(ext, "xml") == 0; + if (!conf && !xml) + continue; + + event_config_t *event_config = new_event_config(); + + char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); + if (xml) + load_event_description_from_file(event_config, fullname); +// if (conf) +// load_event_values_from_file(event_config, fullname); + + free(fullname); + + *ext = '\0'; + g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); + } } /* Frees all loaded data */ diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index 6f23cfb3..5126022e 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -1,7 +1,3 @@ -//#include -#include -#include -#include #include "abrtlib.h" #include "event_config.h" @@ -13,7 +9,7 @@ #define ACTION_ELEMENT "action" #define NAME_ELEMENT "name" -int in_option = 0; +static int in_option = 0; //FIXME static const char *const option_types[] = { @@ -34,30 +30,33 @@ static void start_element(GMarkupParseContext *context, { //g_print("start: %s\n", element_name); - event_config_t *ui = (event_config_t *)user_data; + event_config_t *ui = user_data; - if(strcmp(element_name, OPTION_ELEMENT) == 0) + if (strcmp(element_name, OPTION_ELEMENT) == 0) { - if(in_option == 0) + if (in_option == 0) { in_option = 1; - event_option_t *option = (event_option_t *)malloc(sizeof(event_option_t)); + event_option_t *option = xzalloc(sizeof(*option)); //we need to prepend, so ui->options always points to the last created option VERB2 log("adding option"); ui->options = g_list_prepend(ui->options, option); int i; - for(i = 0; attribute_names[i] != NULL; ++i) + for (i = 0; attribute_names[i] != NULL; ++i) { - VERB2 log("attr: %s:%s\n", attribute_names[i], attribute_values[i]); - if(strcmp(attribute_names[i], "name") == 0) - option->name = strdup(attribute_values[i]); - if(strcmp(attribute_names[i], "type") == 0) + VERB2 log("attr: %s:%s", attribute_names[i], attribute_values[i]); + if (strcmp(attribute_names[i], "name") == 0) { - option_type_t type = 0; - for(type = OPTION_TYPE_TEXT; type < OPTION_TYPE_INVALID; ++type) + free(option->name); + option->name = xstrdup(attribute_values[i]); + } + else if (strcmp(attribute_names[i], "type") == 0) + { + option_type_t type; + for (type = OPTION_TYPE_TEXT; type < OPTION_TYPE_INVALID; ++type) { - if(strcmp(option_types[type], attribute_values[i]) == 0) + if (strcmp(option_types[type], attribute_values[i]) == 0) option->type = type; } } @@ -65,74 +64,79 @@ static void start_element(GMarkupParseContext *context, } else { - g_print("error, option nested in option!\n"); + error_msg("error, option nested in option"); } } } - // Called for close tags +// Called for close tags static void end_element(GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error) { - event_config_t *ui = (event_config_t *)user_data; - if(strcmp(element_name, OPTION_ELEMENT) == 0) + event_config_t *ui = user_data; + if (strcmp(element_name, OPTION_ELEMENT) == 0) { in_option = 0; } - if(strcmp(element_name, EVENT_ELEMENT) == 0) + if (strcmp(element_name, EVENT_ELEMENT) == 0) { - //we need to revers the list, because we we're prepending + //we need to reverse the list, because we we're prepending ui->options = g_list_reverse(ui->options); in_option = 0; } } - // Called for character data - // text is not nul-terminated +// Called for character data +// text is not nul-terminated static void text(GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error) { - event_config_t *ui = (event_config_t *)user_data; + event_config_t *ui = user_data; const gchar * inner_element = g_markup_parse_context_get_element(context); - char *_text = (char *)malloc(text_len+1); - strncpy(_text, text, text_len); - _text[text_len] = '\0'; - if(in_option == 1) + char *_text = xstrndup(text, text_len); + if (in_option == 1) { - event_option_t *option = (event_option_t *)((ui->options)->data); - if(strcmp(inner_element, LABEL_ELEMENT) == 0) + event_option_t *option = ui->options->data; + if (strcmp(inner_element, LABEL_ELEMENT) == 0) { - VERB2 log("\tnew label: \t\t%s", _text); + VERB2 log("new label:'%s'", _text); + free(option->label); option->label = _text; + return; } - if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) + if (strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) { - VERB2 log("\ttooltip: \t\t%s", _text); + VERB2 log("tooltip:'%s'", _text); + free(option->description); option->description = _text; + return; } } else { /* we're not in option, so the description is for the event */ - if(strcmp(inner_element, ACTION_ELEMENT) == 0) + if (strcmp(inner_element, ACTION_ELEMENT) == 0) { - VERB2 log("\taction description: \t%s", _text); + VERB2 log("action description:'%s'", _text); + free(ui->action); ui->action = _text; + return; } - if(strcmp(inner_element, NAME_ELEMENT) == 0) + if (strcmp(inner_element, NAME_ELEMENT) == 0) { - VERB2 log("\tevent name: \t\t%s", _text); + VERB2 log("event name:'%s'", _text); + free(ui->name); ui->name = _text; + return; } } - //will be freed when the event_option is freed - //free(_text); + free(_text); } // Called for strings that should be re-saved verbatim in this same @@ -154,12 +158,12 @@ static void error(GMarkupParseContext *context, GError *error, gpointer user_data) { - g_print("error\n"); + error_msg("error in XML parsing"); } /* this function takes 2 parameters - * ui -> pointer to event_config_t - * filename -> filename to read + * ui -> pointer to event_config_t + * filename -> filename to read * event_config_t contains list of options, which is malloced by hits function * and must be freed by the caller */ @@ -174,14 +178,16 @@ void load_event_description_from_file(event_config_t *event_config, const char* parser.error = &error; GMarkupParseContext *context = g_markup_parse_context_new( &parser, G_MARKUP_TREAT_CDATA_AS_TEXT, - event_config, NULL); + event_config, /*GDestroyNotify:*/ NULL); + FILE* fin = fopen(filename, "r"); size_t read_bytes = 0; char buff[1024]; - while((read_bytes = fread(buff, 1, 1024, fin))) + while ((read_bytes = fread(buff, 1, 1024, fin))) { g_markup_parse_context_parse(context, buff, read_bytes, NULL); } fclose(fin); + g_markup_parse_context_free(context); } -- cgit From e2fdf6c58eba440770624d13e25a63c3d77040db Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Tue, 8 Mar 2011 21:31:45 +0100 Subject: added event description support into xml parser - so event now has: action: description of what will happen when this event is used - the main purpose is for the event selector in wizard description: description of the event --- src/lib/event_config.c | 6 ++++-- src/lib/event_xml_parser.c | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 18019178..30335b84 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -31,6 +31,7 @@ void free_event_config(event_config_t *p) free(p->name); free(p->title); free(p->action); + free(p->description); for (GList *opt = p->options; opt; opt = opt->next) free_event_option(opt->data); g_list_free(p->options); @@ -42,7 +43,6 @@ void free_event_config(event_config_t *p) void load_event_config_data(void) { free_event_config_data(); - DIR *dir = opendir(EVENTS_DIR); if (!dir) return; @@ -72,12 +72,14 @@ void load_event_config_data(void) char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); if (xml) load_event_description_from_file(event_config, fullname); + // if (conf) // load_event_values_from_file(event_config, fullname); free(fullname); - *ext = '\0'; + //we did ext++ so we need ext-- to point to '.' + *(--ext) = '\0'; g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); } } diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index 5126022e..a0e6c3c4 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -135,8 +135,13 @@ static void text(GMarkupParseContext *context, ui->name = _text; return; } + if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) + { + VERB2 log("event description:'%s'", _text); + free(ui->description); + ui->description = _text; + } } - free(_text); } // Called for strings that should be re-saved verbatim in this same @@ -181,13 +186,16 @@ void load_event_description_from_file(event_config_t *event_config, const char* event_config, /*GDestroyNotify:*/ NULL); FILE* fin = fopen(filename, "r"); - size_t read_bytes = 0; - char buff[1024]; - while ((read_bytes = fread(buff, 1, 1024, fin))) + if(fin != NULL) { - g_markup_parse_context_parse(context, buff, read_bytes, NULL); + size_t read_bytes = 0; + char buff[1024]; + while ((read_bytes = fread(buff, 1, 1024, fin))) + { + g_markup_parse_context_parse(context, buff, read_bytes, NULL); + } + fclose(fin); } - fclose(fin); g_markup_parse_context_free(context); } -- cgit From 97db1f93f59091fc85624b618e7cec1ac3d48169 Mon Sep 17 00:00:00 2001 From: Nikola Pajkovsky Date: Wed, 9 Mar 2011 12:31:03 +0100 Subject: view details in extrenal editor for multiline non-binary files Signed-off-by: Nikola Pajkovsky --- src/lib/crash_data.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/crash_data.c b/src/lib/crash_data.c index 63b0a7a5..7f23c52f 100644 --- a/src/lib/crash_data.c +++ b/src/lib/crash_data.c @@ -233,10 +233,21 @@ void load_crash_data_from_dump_dir(crash_data_t *crash_data, struct dump_dir *dd content = dd_load_text(dd, short_name); } + int flags = 0; + + if (editable) + flags |= CD_FLAG_TXT | CD_FLAG_ISEDITABLE; + else + flags |= CD_FLAG_TXT | CD_FLAG_ISNOTEDITABLE; + + int oneline = strchr(content, '\n') == NULL; + if (oneline) + flags |= CD_FLAG_ONELINE; + add_to_crash_data_ext(crash_data, short_name, content, - (editable ? CD_FLAG_TXT + CD_FLAG_ISEDITABLE : CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE) + flags ); free(short_name); free(full_name); -- cgit From 93b9b18b5096c7591c02036e1c908f3bcbb09f29 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 9 Mar 2011 14:12:09 +0100 Subject: add -Wwrite-strings everywhere Signed-off-by: Denys Vlasenko --- src/lib/Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 863a0448..36fe7b4b 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -47,7 +47,7 @@ libreport_la_SOURCES = \ event_xml_parser.c \ event_config.c libreport_la_CPPFLAGS = \ - -Wall -Werror \ + -Wall -Wwrite-strings -Werror \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -DLOCALSTATEDIR='"$(localstatedir)"' \ -DVAR_RUN=\"$(VAR_RUN)\" \ @@ -76,7 +76,7 @@ libabrt_dbus_la_CPPFLAGS = \ -DEVENTS_DIR=\"$(EVENTS_DIR)\" \ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ - -Wall -Werror \ + -Wall -Wwrite-strings -Werror \ -D_GNU_SOURCE libabrt_dbus_la_LDFLAGS = \ -version-info 0:1:0 @@ -88,7 +88,7 @@ libabrt_web_la_SOURCES = \ abrt_curl.h abrt_curl.c \ abrt_xmlrpc.h abrt_xmlrpc.cpp libabrt_web_la_CPPFLAGS = \ - -Wall -Werror \ + -Wall -Wwrite-strings -Werror \ -I$(srcdir)/../include/report -I$(srcdir)/../include \ -DLOCALSTATEDIR='"$(localstatedir)"' \ -DVAR_RUN=\"$(VAR_RUN)\" \ -- cgit From 12afc6905e943f8f358a6e7adcbc7f06ae665787 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 9 Mar 2011 15:04:04 +0100 Subject: fix a leak in event_xml_parser.c; simplify load_conf_file() a bit Signed-off-by: Denys Vlasenko --- src/lib/event_xml_parser.c | 8 ++++--- src/lib/load_plugin_settings.c | 52 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 29 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index a0e6c3c4..5f1974fd 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -135,13 +135,15 @@ static void text(GMarkupParseContext *context, ui->name = _text; return; } - if(strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) + if (strcmp(inner_element, DESCRIPTION_ELEMENT) == 0) { VERB2 log("event description:'%s'", _text); free(ui->description); ui->description = _text; + return; } } + free(_text); } // Called for strings that should be re-saved verbatim in this same @@ -186,11 +188,11 @@ void load_event_description_from_file(event_config_t *event_config, const char* event_config, /*GDestroyNotify:*/ NULL); FILE* fin = fopen(filename, "r"); - if(fin != NULL) + if (fin != NULL) { size_t read_bytes = 0; char buff[1024]; - while ((read_bytes = fread(buff, 1, 1024, fin))) + while ((read_bytes = fread(buff, 1, 1024, fin)) != 0) { g_markup_parse_context_parse(context, buff, read_bytes, NULL); } diff --git a/src/lib/load_plugin_settings.c b/src/lib/load_plugin_settings.c index 1e6b31e7..1b6086f9 100644 --- a/src/lib/load_plugin_settings.c +++ b/src/lib/load_plugin_settings.c @@ -34,47 +34,47 @@ bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWith char *line; while ((line = xmalloc_fgetline(fp)) != NULL) { - unsigned ii; - bool valid = false; bool in_quote = false; /* We are reusing line buffer to form temporary * "key\0value\0..." in its beginning */ - char *key = line; - char *value = line; - char *cur = line; - - for (ii = 0; line[ii] != '\0'; ii++) + char *value = NULL; + char *src; + char *dst; + for (src = dst = line; *src; src++) { - if (line[ii] == '"') + char c = *src; + if (c == '"') { in_quote = !in_quote; } - if (isspace(line[ii]) && !in_quote) - { - continue; - } - if (line[ii] == '#' && !in_quote && cur == line) - { - break; - } - if (line[ii] == '=' && !in_quote) + if (!in_quote) { - valid = true; - *cur++ = '\0'; /* terminate key */ - value = cur; /* remember where value starts */ - continue; + if (isspace(c)) + { + continue; + } + if (c == '#' && dst == line) + { + break; + } + if (c == '=') + { + *dst++ = '\0'; /* terminate key */ + value = dst; /* remember where value starts */ + continue; + } } - *cur++ = line[ii]; /* store next key or value char */ + *dst++ = c; /* store next key or value char */ } - *cur++ = '\0'; /* terminate value */ + *dst = '\0'; /* terminate value */ /* Skip broken or empty lines. */ - if (!valid) + if (!value) goto free_line; /* Skip lines with empty key. */ - if (key[0] == '\0') + if (line[0] == '\0') goto free_line; if (skipKeysWithoutValue && value[0] == '\0') @@ -84,7 +84,7 @@ bool load_conf_file(const char *pPath, map_string_h *settings, bool skipKeysWith if (in_quote) goto free_line; - g_hash_table_replace(settings, xstrdup(key), xstrdup(value)); + g_hash_table_replace(settings, xstrdup(line), xstrdup(value)); free_line: free(line); } -- cgit From ce92e8a6d7e4a4faaf4f3238ff14d6dc4d597846 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 9 Mar 2011 15:07:27 +0100 Subject: add parsing of /etc/abrt/events/*.conf files. Not tested. Signed-off-by: Denys Vlasenko --- src/lib/event_config.c | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 30335b84..6700695e 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -61,9 +61,8 @@ void load_event_config_data(void) char *ext = strrchr(dent->d_name, '.'); if (!ext) continue; - ext++; - bool conf = strcmp(ext, "conf") == 0; - bool xml = strcmp(ext, "xml") == 0; + bool conf = strcmp(ext + 1, "conf") == 0; + bool xml = strcmp(ext + 1, "xml") == 0; if (!conf && !xml) continue; @@ -72,14 +71,41 @@ void load_event_config_data(void) char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); if (xml) load_event_description_from_file(event_config, fullname); - -// if (conf) -// load_event_values_from_file(event_config, fullname); - + if (conf) + { + map_string_h *keys_and_values = new_map_string(); + + load_conf_file(fullname, keys_and_values, /*skipKeysWithoutValue:*/ false); + + /* Insert or replace every key/value from keys_and_values to event_config->option */ + GHashTableIter iter; + char *name; + char *value; + g_hash_table_iter_init(&iter, keys_and_values); + while (g_hash_table_iter_next(&iter, (void**)&name, (void**)&value)) + { + event_option_t *opt; + GList *elem = g_list_find(event_config->options, name); + if (elem) + { + opt = elem->data; + free(opt->value); + } + else + { + opt = new_event_option(); + opt->name = xstrdup(name); + } + opt->value = xstrdup(value); + if (!elem) + event_config->options = g_list_append(event_config->options, opt); + } + + free_map_string(keys_and_values); + } free(fullname); - //we did ext++ so we need ext-- to point to '.' - *(--ext) = '\0'; + *ext = '\0'; g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); } } -- cgit From 1a55a94467587abb920dc37e38f339997374e8cc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 9 Mar 2011 15:13:36 +0100 Subject: fix to parsing of /etc/abrt/events/*.conf files Signed-off-by: Denys Vlasenko --- src/lib/event_config.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 6700695e..4f8e8679 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -66,9 +66,13 @@ void load_event_config_data(void) if (!conf && !xml) continue; - event_config_t *event_config = new_event_config(); - char *fullname = concat_path_file(EVENTS_DIR, dent->d_name); + + *ext = '\0'; + event_config_t *event_config = get_event_config(dent->d_name); + if (!event_config) + event_config = new_event_config(); + if (xml) load_event_description_from_file(event_config, fullname); if (conf) @@ -103,9 +107,9 @@ void load_event_config_data(void) free_map_string(keys_and_values); } + free(fullname); - *ext = '\0'; g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); } } -- cgit From 4db62cf9807f4ec11a7c8c8c91875080c90f0ec1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 9 Mar 2011 16:43:27 +0100 Subject: gui-wizard-gtk: add load_event_config_data() to wizard Signed-off-by: Denys Vlasenko --- src/lib/event_config.c | 7 +++++-- src/lib/event_xml_parser.c | 2 +- src/lib/run_event.c | 32 ++++++++++++++++---------------- 3 files changed, 22 insertions(+), 19 deletions(-) (limited to 'src/lib') diff --git a/src/lib/event_config.c b/src/lib/event_config.c index 4f8e8679..a79ee40c 100644 --- a/src/lib/event_config.c +++ b/src/lib/event_config.c @@ -43,6 +43,7 @@ void free_event_config(event_config_t *p) void load_event_config_data(void) { free_event_config_data(); + DIR *dir = opendir(EVENTS_DIR); if (!dir) return; @@ -70,7 +71,8 @@ void load_event_config_data(void) *ext = '\0'; event_config_t *event_config = get_event_config(dent->d_name); - if (!event_config) + bool new_config = (!event_config); + if (new_config) event_config = new_event_config(); if (xml) @@ -110,7 +112,8 @@ void load_event_config_data(void) free(fullname); - g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); + if (new_config) + g_hash_table_replace(g_event_config_list, xstrdup(dent->d_name), event_config); } } diff --git a/src/lib/event_xml_parser.c b/src/lib/event_xml_parser.c index 5f1974fd..be4a9e09 100644 --- a/src/lib/event_xml_parser.c +++ b/src/lib/event_xml_parser.c @@ -37,7 +37,7 @@ static void start_element(GMarkupParseContext *context, if (in_option == 0) { in_option = 1; - event_option_t *option = xzalloc(sizeof(*option)); + event_option_t *option = new_event_option(); //we need to prepend, so ui->options always points to the last created option VERB2 log("adding option"); ui->options = g_list_prepend(ui->options, option); diff --git a/src/lib/run_event.c b/src/lib/run_event.c index 3d2b3a22..45facffd 100644 --- a/src/lib/run_event.c +++ b/src/lib/run_event.c @@ -93,7 +93,7 @@ static GList *load_event_config(GList *list, if (*p == '\0' || *p == '#') goto next_line; /* empty or comment line, skip */ - VERB3 log("%s: line '%s'", __func__, p); + //VERB3 log("%s: line '%s'", __func__, p); if (strncmp(p, "include", strlen("include")) == 0 && isblank(p[strlen("include")])) { @@ -117,15 +117,15 @@ static GList *load_event_config(GList *list, glob_t globbuf; memset(&globbuf, 0, sizeof(globbuf)); - VERB3 log("%s: globbing '%s'", __func__, name_to_glob); + //VERB3 log("%s: globbing '%s'", __func__, name_to_glob); glob(name_to_glob, 0, NULL, &globbuf); free(name_to_glob); char **name = globbuf.gl_pathv; if (name) while (*name) { - VERB3 log("%s: recursing into '%s'", __func__, *name); + //VERB3 log("%s: recursing into '%s'", __func__, *name); list = load_event_config(list, dump_dir_name, event, *name); - VERB3 log("%s: returned from '%s'", __func__, *name); + //VERB3 log("%s: returned from '%s'", __func__, *name); name++; } globfree(&globbuf); @@ -174,10 +174,10 @@ static GList *load_event_config(GList *list, /* Does VAL match? */ if (strcmp(real_val, line_val) != 0) { - VERB3 log("var '%s': '%.*s'!='%s', skipping line", - p, - (int)(strchrnul(real_val, '\n') - real_val), real_val, - line_val); + //VERB3 log("var '%s': '%.*s'!='%s', skipping line", + // p, + // (int)(strchrnul(real_val, '\n') - real_val), real_val, + // line_val); free(malloced_val); goto next_line; /* no */ } @@ -400,7 +400,7 @@ static int list_possible_events_helper(struct strbuf *result, if (*p == '\0' || *p == '#') goto next_line; /* empty or comment line, skip */ - VERB3 log("%s: line '%s'", __func__, p); + //VERB3 log("%s: line '%s'", __func__, p); if (strncmp(p, "include", strlen("include")) == 0 && isblank(p[strlen("include")])) { @@ -424,15 +424,15 @@ static int list_possible_events_helper(struct strbuf *result, glob_t globbuf; memset(&globbuf, 0, sizeof(globbuf)); - VERB3 log("%s: globbing '%s'", __func__, name_to_glob); + //VERB3 log("%s: globbing '%s'", __func__, name_to_glob); glob(name_to_glob, 0, NULL, &globbuf); free(name_to_glob); char **name = globbuf.gl_pathv; if (name) while (*name) { - VERB3 log("%s: recursing into '%s'", __func__, *name); + //VERB3 log("%s: recursing into '%s'", __func__, *name); error = list_possible_events_helper(result, dd, dump_dir_name, pfx, *name); - VERB3 log("%s: returned from '%s'", __func__, *name); + //VERB3 log("%s: returned from '%s'", __func__, *name); if (error) break; name++; @@ -484,10 +484,10 @@ static int list_possible_events_helper(struct strbuf *result, /* Does VAL match? */ if (strcmp(real_val, line_val) != 0) { - VERB3 log("var '%s': '%.*s'!='%s', skipping line", - p, - (int)(strchrnul(real_val, '\n') - real_val), real_val, - line_val); + //VERB3 log("var '%s': '%.*s'!='%s', skipping line", + // p, + // (int)(strchrnul(real_val, '\n') - real_val), real_val, + // line_val); free(real_val); goto next_line; /* no */ } -- cgit