Exemplo n.º 1
0
void
eventd_config_parse(EventdConfig *config, gboolean system_mode)
{
    _eventd_config_clean(config);

    config->loaded = TRUE;

    _eventd_config_defaults(config);

    GHashTable *action_files;
    GHashTable *event_files;

    action_files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_key_file_free);
    event_files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_key_file_free);

    gchar **dirs, **dir;
    dirs = evhelpers_dirs_get_config("EVENTD_CONFIG_DIR", system_mode, NULL);
    for ( dir = dirs ; *dir != NULL ; ++dir )
    {
        _eventd_config_load_dir(config, action_files, event_files, *dir);
        g_free(*dir);
    }
    g_free(dirs);
    if ( g_file_test(config->arg_dir, G_FILE_TEST_IS_DIR) )
        _eventd_config_load_dir(config, action_files, event_files, config->arg_dir);

    /*
     * We check the env early, and skip the configuration if found
     * so here, we can override it safely
     */
    if ( config->gnutls_priorities != NULL )
        g_setenv("G_TLS_GNUTLS_PRIORITY", config->gnutls_priorities, TRUE);

    GHashTableIter iter;
    gchar *id;
    GKeyFile *config_file;

    g_hash_table_iter_init(&iter, event_files);
    while ( g_hash_table_iter_next(&iter, (gpointer *)&id, (gpointer *)&config_file) )
    {
        if ( ( config_file = _eventd_config_process_config_file(event_files, id, config_file) ) != NULL )
            eventd_events_parse(config->events, config_file);
    }
    g_hash_table_unref(event_files);

    g_hash_table_iter_init(&iter, action_files);
    while ( g_hash_table_iter_next(&iter, (gpointer *)&id, (gpointer *)&config_file) )
    {
        if ( ( config_file = _eventd_config_process_config_file(action_files, id, config_file) ) != NULL )
            eventd_actions_parse(config->actions, config_file, id);
    }
    g_hash_table_unref(action_files);

    eventd_actions_link_actions(config->actions);
    eventd_events_link_actions(config->events, config->actions);
}
Exemplo n.º 2
0
void
eventd_config_parse(EventdConfig *config)
{
    _eventd_config_clean(config);

    config->loaded = TRUE;

    _eventd_config_defaults(config);
    eventd_plugins_config_init_all();

    GHashTable *config_files;

    config_files = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_key_file_free);

    _eventd_config_load_dir(config, config_files, DATADIR G_DIR_SEPARATOR_S PACKAGE_NAME);
    _eventd_config_load_dir(config, config_files, SYSCONFDIR G_DIR_SEPARATOR_S PACKAGE_NAME);

    gchar *user_config_dir;
    user_config_dir = g_build_filename(g_get_user_config_dir(), PACKAGE_NAME, NULL);
    _eventd_config_load_dir(config, config_files, user_config_dir);
    g_free(user_config_dir);

    const gchar *env_config_dir;
    env_config_dir = g_getenv("EVENTD_CONFIG_DIR");
    if ( env_config_dir != NULL )
        _eventd_config_load_dir(config, config_files, env_config_dir);

    GHashTableIter iter;
    gchar *id;
    GKeyFile *config_file;
    g_hash_table_iter_init(&iter, config_files);
    while ( g_hash_table_iter_next(&iter, (gpointer *)&id, (gpointer *)&config_file) )
    {
        if ( ( config_file = _eventd_config_process_config_file(config_files, id, config_file) ) != NULL )
            _eventd_config_parse_event_file(config, id, config_file);
    }
    g_hash_table_unref(config_files);
}
Exemplo n.º 3
0
Arquivo: config.c Projeto: worr/eventd
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;
}