static void _eventd_evp_global_parse(EventdPluginContext *context, GKeyFile *config_file) { gchar *avahi_name; if ( ! g_key_file_has_group(config_file, "Server") ) return; if ( libeventd_config_key_file_get_string(config_file, "Server", "AvahiName", &avahi_name) < 0 ) return; if ( avahi_name != NULL ) { g_free(context->avahi_name); context->avahi_name = avahi_name; } }
static void _eventd_libcanberra_global_parse(EventdPluginContext *context, GKeyFile *config_file) { if ( ! g_key_file_has_group(config_file, "Libcanberra") ) return; gchar * sound_theme = NULL; if ( libeventd_config_key_file_get_string(config_file, "Libcanberra", "Theme", &sound_theme) < 0 ) goto skip; /* * TODO: handle that */ skip: g_free(sound_theme); }
static void _eventd_exec_event_parse(EventdPluginContext *context, const gchar *config_id, GKeyFile *config_file) { gboolean disable; gchar *command = NULL; if ( ! g_key_file_has_group(config_file, "Exec") ) return; if ( libeventd_config_key_file_get_boolean(config_file, "Exec", "Disable", &disable) < 0 ) return; if ( ! disable ) { if ( libeventd_config_key_file_get_string(config_file, "Exec", "Command", &command) < 0 ) return; } g_hash_table_insert(context->events, g_strdup(config_id), command); }
static GKeyFile * _eventd_config_process_config_file(GHashTable *config_files, const gchar *id, GKeyFile *config_file) { gchar *parent_id; switch ( libeventd_config_key_file_get_string(config_file, "Event", "Extends", &parent_id) ) { case 1: return config_file; case -1: return NULL; case 0: break; } GError *error = NULL; if ( ! g_key_file_remove_key(config_file, "Event", "Extends", &error) ) { g_warning("Couldn't clean event file '%s': %s", id, error->message); g_clear_error(&error); goto fail; } GKeyFile *parent; parent = g_hash_table_lookup(config_files, parent_id); if ( parent == NULL ) { g_warning("Event file '%s' has no parent file '%s'", id, parent_id); goto fail; } if ( ( parent = _eventd_config_process_config_file(config_files, parent_id, parent) ) == NULL ) goto fail; GString *merged_data; gchar *data; data = g_key_file_to_data(parent, NULL, NULL); merged_data = g_string_new(data); g_free(data); data = g_key_file_to_data(config_file, NULL, NULL); g_string_append(merged_data, data); g_free(data); GKeyFile *new_config_file; new_config_file = g_key_file_new(); if ( g_key_file_load_from_data(new_config_file, merged_data->str, -1, G_KEY_FILE_NONE, &error) ) g_hash_table_insert(config_files, g_strdup(id), new_config_file); else { g_warning("Couldn't merge '%s' and '%s': %s", id, parent_id, error->message); g_clear_error(&error); g_key_file_free(new_config_file); new_config_file = NULL; } g_string_free(merged_data, TRUE); g_free(parent_id); return new_config_file; fail: g_free(parent_id); return NULL; }
static void _eventd_config_parse_event_file(EventdConfig *config, const gchar *id, GKeyFile *config_file) { gchar *category = NULL; gchar *name = NULL; #ifdef DEBUG g_debug("Parsing event '%s'", id); #endif /* DEBUG */ if ( libeventd_config_key_file_get_string(config_file, "Event", "Category", &category) != 0 ) return; if ( libeventd_config_key_file_get_string(config_file, "Event", "Name", &name) < 0 ) goto fail; EventdConfigMatch *match; match = g_new0(EventdConfigMatch, 1); match->importance = G_MAXINT64; match->id = g_strdup(id); gchar **if_data_matches; gchar **flags; gsize length; libeventd_config_key_file_get_string_list(config_file, "Event", "IfData", &match->if_data, NULL); if ( libeventd_config_key_file_get_string_list(config_file, "Event", "IfDataMatches", &if_data_matches, NULL) == 0 ) { EventdConfigDataMatch *data_match; gchar **if_data_match; GError *error = NULL; GRegex *regex; for ( if_data_match = if_data_matches ; *if_data_match != NULL ; ++if_data_match ) { gchar **if_data_matchv; if_data_matchv = g_strsplit(*if_data_match, ",", 2); if ( ( regex = g_regex_new(if_data_matchv[1], G_REGEX_OPTIMIZE, 0, &error) ) != NULL ) { data_match = g_new0(EventdConfigDataMatch, 1); data_match->data = g_strdup(if_data_matchv[0]); data_match->regex = regex; match->if_data_matches = g_list_prepend(match->if_data_matches, data_match); } g_strfreev(if_data_matchv); } g_strfreev(if_data_matches); } if ( libeventd_config_key_file_get_string_list(config_file, "Event", "OnlyIfFlags", &flags, &length) == 0 ) match->flags_whitelist = _eventd_config_parse_event_flags(flags, length); if ( libeventd_config_key_file_get_string_list(config_file, "Event", "NotIfFlags", &flags, &length) == 0 ) match->flags_blacklist = _eventd_config_parse_event_flags(flags, length); if ( ( match->if_data != NULL ) || ( match->if_data_matches != NULL ) || ( match->flags_whitelist != NULL ) || ( match->flags_blacklist != NULL ) ) match->importance = libeventd_config_key_file_get_int_with_default(config_file, "Event", "Importance", G_MAXINT64); gchar *internal_name; internal_name = _eventd_config_events_get_name(category, name); GList *list; list = g_hash_table_lookup(config->event_ids, internal_name); g_hash_table_steal(config->event_ids, internal_name); list = g_list_insert_sorted(list, match, _eventd_config_compare_matches); g_hash_table_insert(config->event_ids, internal_name, list); _eventd_config_parse_client(config, id, config_file); eventd_plugins_event_parse_all(id, config_file); fail: g_free(name); g_free(category); }