Пример #1
0
static NProplist*
n_core_load_params (NCore *core, const char *plugin_name)
{
    g_assert (core != NULL);
    g_assert (plugin_name != NULL);

    NProplist  *proplist  = NULL;
    GKeyFile   *keyfile   = NULL;
    gchar      *filename  = NULL;
    gchar      *full_path = NULL;
    gchar     **keys      = NULL;
    gchar     **iter      = NULL;
    GError     *error     = NULL;
    gchar      *value     = NULL;

    filename  = g_strdup_printf ("%s.ini", plugin_name);
    full_path = g_build_filename (core->conf_path, PLUGIN_CONF_PATH, filename, NULL);
    keyfile   = g_key_file_new ();

    if (!g_key_file_load_from_file (keyfile, full_path, G_KEY_FILE_NONE, &error)) {
        if (error->code & G_KEY_FILE_ERROR_NOT_FOUND) {
            N_WARNING (LOG_CAT "problem with configuration file '%s': %s",
                filename, error->message);
        }

        goto done;
    }

    keys = g_key_file_get_keys (keyfile, plugin_name, NULL, NULL);
    if (!keys) {
        N_WARNING (LOG_CAT "no group '%s' within configuration file '%s'",
            plugin_name, filename);
        goto done;
    }

    proplist = n_proplist_new ();
    for (iter = keys; *iter; ++iter) {
        if ((value = g_key_file_get_string (keyfile, plugin_name, *iter, NULL)) == NULL)
            continue;

        N_DEBUG (LOG_CAT "+ plugin parameter: %s = %s", *iter, value);
        n_proplist_set_string (proplist, *iter, value);
        g_free (value);
    }

    g_strfreev (keys);

done:
    if (error)
        g_error_free (error);

    if (keyfile)
        g_key_file_free (keyfile);

    g_free          (full_path);
    g_free          (filename);

    return proplist;
}
Пример #2
0
/* Read and create proplist from a custom file */
static NProplist* ffm_read_props(const char *file_name)
{
	NProplist  *proplist  = NULL;
	GKeyFile   *keyfile   = NULL;
	gchar     **keys      = NULL;
	gchar     **iter      = NULL;
	GError     *error     = NULL;
	gchar      *value     = NULL;

	if (!file_name) {
		N_DEBUG (LOG_CAT "NULL file_name parameter, cannot read props");
		return NULL;
	}
	keyfile   = g_key_file_new ();

	N_DEBUG (LOG_CAT "Loading properties from file \"%s\"", file_name);

	if (!g_key_file_load_from_file (keyfile, file_name, G_KEY_FILE_NONE,
								&error)) {
		N_WARNING (LOG_CAT "problem with configuration file"
				" '%s': %s", file_name, error->message);
		goto done;
	}

	keys = g_key_file_get_keys (keyfile, FFM_PLUGIN_NAME, NULL, NULL);
	if (!keys) {
		N_WARNING (LOG_CAT "no group '%s' within configuration file "
				"'%s'", FFM_PLUGIN_NAME, file_name);
		goto done;
	}

	proplist = n_proplist_new ();

	for (iter = keys; *iter; ++iter) {
		if ((value = g_key_file_get_string (keyfile,
					FFM_PLUGIN_NAME, *iter, NULL)) == NULL)
			continue;

		N_DEBUG (LOG_CAT "+ plugin parameter: %s = %s", *iter, value);
		n_proplist_set_string (proplist, *iter, value);
		g_free (value);
	}
	g_strfreev (keys);

done:
	if (error)
		g_error_free (error);

	if (keyfile)
		g_key_file_free (keyfile);

	return proplist;
}