struct ConfigurationPrivate
{
+ gchar *dir;
GKeyFile *key_file;
+ GList *sources;
+ GHashTable *key_sources;
};
G_DEFINE_TYPE (Configuration, config, G_TYPE_OBJECT);
config_load_from_file (Configuration *config, const gchar *path, GError **error)
{
GKeyFile *key_file;
- gchar **groups;
+ gchar *source_path, **groups;
int i;
+ source_path = g_strdup (path);
+ config->priv->sources = g_list_append (config->priv->sources, source_path);
+
key_file = g_key_file_new ();
if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, error))
{
keys = g_key_file_get_keys (key_file, groups[i], NULL, error);
if (!keys)
break;
-
+
for (j = 0; keys[j]; j++)
{
- gchar *value;
+ gchar *value, *k;
value = g_key_file_get_value (key_file, groups[i], keys[j], NULL);
g_key_file_set_value (config->priv->key_file, groups[i], keys[j], value);
g_free (value);
+
+ k = g_strdup_printf ("%s]%s", groups[i], keys[j]);
+ g_hash_table_insert (config->priv->key_sources, k, source_path);
}
g_strfreev (keys);
gboolean
config_load_from_standard_locations (Configuration *config, const gchar *config_path, GList **messages)
{
- gchar *config_dir, *config_d_dir = NULL;
+ gchar *config_d_dir = NULL;
gboolean explicit_config = FALSE;
gboolean success = TRUE;
GError *error = NULL;
if (config_path)
{
- config_dir = g_path_get_basename (config_path);
- config_dir = path_make_absolute (config_dir);
+ config->priv->dir = path_make_absolute (g_path_get_basename (config_path));
explicit_config = TRUE;
}
else
{
- config_dir = g_strdup (CONFIG_DIR);
- config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
- config_path = g_build_filename (config_dir, "lightdm.conf", NULL);
+ config->priv->dir = g_strdup (CONFIG_DIR);
+ config_d_dir = g_build_filename (config->priv->dir, "lightdm.conf.d", NULL);
+ config_path = g_build_filename (config->priv->dir, "lightdm.conf", NULL);
}
- config_set_string (config, "LightDM", "config-directory", config_dir);
- g_free (config_dir);
if (config_d_dir)
load_config_directory (config_d_dir, messages);
return success;
}
+const gchar *
+config_get_directory (Configuration *config)
+{
+ return config->priv->dir;
+}
+
gchar **
config_get_groups (Configuration *config)
{
return g_key_file_has_key (config->priv->key_file, section, key, NULL);
}
+GList *
+config_get_sources (Configuration *config)
+{
+ return config->priv->sources;
+}
+
+const gchar *
+config_get_source (Configuration *config, const gchar *section, const gchar *key)
+{
+ gchar *k;
+ const gchar *source;
+
+ k = g_strdup_printf ("%s]%s", section, key);
+ source = g_hash_table_lookup (config->priv->key_sources, k);
+ g_free (k);
+
+ return source;
+}
+
void
config_set_string (Configuration *config, const gchar *section, const gchar *key, const gchar *value)
{
config_init (Configuration *config)
{
config->priv = G_TYPE_INSTANCE_GET_PRIVATE (config, CONFIGURATION_TYPE, ConfigurationPrivate);
- config->priv->key_file = g_key_file_new ();
+ config->priv->key_file = g_key_file_new ();
+ config->priv->key_sources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
}
static void
self = CONFIGURATION (object);
+ g_free (self->priv->dir);
g_key_file_free (self->priv->key_file);
+ g_list_free_full (self->priv->sources, g_free);
+ g_hash_table_destroy (self->priv->key_sources);
G_OBJECT_CLASS (config_parent_class)->finalize (object);
}
gboolean config_load_from_standard_locations (Configuration *config, const gchar *config_path, GList **messages);
+const gchar *config_get_directory (Configuration *config);
+
gchar **config_get_groups (Configuration *config);
gchar **config_get_keys (Configuration *config, const gchar *group_name);
gboolean config_has_key (Configuration *config, const gchar *section, const gchar *key);
+GList *config_get_sources (Configuration *config);
+
+const gchar *config_get_source (Configuration *config, const gchar *section, const gchar *key);
+
void config_set_string (Configuration *config, const gchar *section, const gchar *key, const gchar *value);
gchar *config_get_string (Configuration *config, const gchar *section, const gchar *key);
key_name = config_get_string (config_get_instance (), "XDMCPServer", "key");
if (key_name)
{
- gchar *dir, *path;
+ gchar *path;
GKeyFile *keys;
gboolean result;
GError *error = NULL;
- dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
- path = g_build_filename (dir, "keys.conf", NULL);
- g_free (dir);
+ path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
keys = g_key_file_new ();
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
/* Show combined configuration if user requested it */
if (show_config)
{
- gchar **groups;
+ GList *sources, *link;
+ gchar **groups, *last_source, *empty_source;
+ GHashTable *source_ids;
int i;
if (!config_load_from_standard_locations (config_get_instance (), config_path, NULL))
return EXIT_FAILURE;
+ /* Number sources */
+ sources = config_get_sources (config_get_instance ());
+ source_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ last_source = "";
+ for (i = 0, link = sources; link; i++, link = link->next)
+ {
+ gchar *path, *id;
+
+ path = link->data;
+ if (i < 26)
+ id = g_strdup_printf ("%c", 'A' + i);
+ else
+ id = g_strdup_printf ("%d", i);
+ g_hash_table_insert (source_ids, g_strdup (path), id);
+ last_source = id;
+ }
+ empty_source = g_strdup (last_source);
+ for (i = 0; empty_source[i] != '\0'; i++)
+ empty_source[i] = ' ';
+
+ /* Print out keys */
groups = config_get_groups (config_get_instance ());
for (i = 0; groups[i]; i++)
{
if (i != 0)
g_printerr ("\n");
- g_printerr ("[%s]\n", groups[i]);
+ g_printerr ("%s [%s]\n", empty_source, groups[i]);
keys = config_get_keys (config_get_instance (), groups[i]);
for (j = 0; keys[j]; j++)
{
+ const gchar *source, *id;
gchar *value;
+ source = config_get_source (config_get_instance (), groups[i], keys[j]);
+ id = source ? g_hash_table_lookup (source_ids, source) : empty_source;
value = config_get_string (config_get_instance (), groups[i], keys[j]);
- g_printerr ("%s=%s\n", keys[j], value);
+ g_printerr ("%s %s=%s\n", id, keys[j], value);
g_free (value);
}
}
g_strfreev (groups);
+ /* Show mapping from source number to path */
+ g_printerr ("\n");
+ g_printerr ("Sources:\n");
+ for (link = sources; link; link = link->next)
+ {
+ const gchar *path = link->data;
+ const gchar *source;
+
+ source = g_hash_table_lookup (source_ids, path);
+ g_printerr ("%s %s\n", source, path);
+ }
+
+ g_hash_table_destroy (source_ids);
+
return EXIT_SUCCESS;
}
key_name = seat_get_string_property (SEAT (seat), "xdmcp-key");
if (key_name)
{
- gchar *dir, *path;
+ gchar *path;
GKeyFile *keys;
gboolean result;
GError *error = NULL;
- dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
- path = g_build_filename (dir, "keys.conf", NULL);
- g_free (dir);
+ path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
keys = g_key_file_new ();
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
key_name = seat_get_string_property (seat, "xdmcp-key");
if (key_name)
{
- gchar *dir, *path;
+ gchar *path;
GKeyFile *keys;
gboolean result;
GError *error = NULL;
- dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
- path = g_build_filename (dir, "keys.conf", NULL);
- g_free (dir);
+ path = g_build_filename (config_get_directory (config_get_instance ()), "keys.conf", NULL);
keys = g_key_file_new ();
result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);