]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Show source of configuration keys
authorRobert Ancell <robert.ancell@canonical.com>
Fri, 22 Aug 2014 09:01:20 +0000 (21:01 +1200)
committerRobert Ancell <robert.ancell@canonical.com>
Fri, 22 Aug 2014 09:01:20 +0000 (21:01 +1200)
common/configuration.c
common/configuration.h
src/lightdm.c
src/seat-unity.c
src/seat-xlocal.c

index 6ae57579a8fe3fb901a05f74b6cec9dcf0e94865..cd57d9b0b54a146b1865d645d18e582698f9945f 100644 (file)
 
 struct ConfigurationPrivate
 {
+    gchar *dir;
     GKeyFile *key_file;
+    GList *sources;
+    GHashTable *key_sources;
 };
 
 G_DEFINE_TYPE (Configuration, config, G_TYPE_OBJECT);
@@ -34,9 +37,12 @@ gboolean
 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))
     {
@@ -53,14 +59,17 @@ config_load_from_file (Configuration *config, const gchar *path, GError **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);
@@ -159,7 +168,7 @@ load_config_directories (const gchar * const *dirs, GList **messages)
 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;
@@ -169,18 +178,15 @@ config_load_from_standard_locations (Configuration *config, const gchar *config_
 
     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);
@@ -206,6 +212,12 @@ config_load_from_standard_locations (Configuration *config, const gchar *config_
     return success;
 }
 
+const gchar *
+config_get_directory (Configuration *config)
+{
+    return config->priv->dir;
+}
+
 gchar **
 config_get_groups (Configuration *config)
 {
@@ -224,6 +236,25 @@ config_has_key (Configuration *config, const gchar *section, const gchar *key)
     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)
 {
@@ -276,7 +307,8 @@ static void
 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
@@ -286,7 +318,10 @@ config_finalize (GObject *object)
 
     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);  
 }
index b689398e269a965db9e636272d56ddf88d478cc9..5f3004ccb348c2bd0206c0455a02807390453345 100644 (file)
@@ -40,12 +40,18 @@ gboolean config_load_from_file (Configuration *config, const gchar *path, GError
 
 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);
index 6a17ac252fb3a4f265eae861ff7c2c9fd91f6626..e03335f3d35cc54232f47ea5894ecf7d6f669815 100644 (file)
@@ -906,14 +906,12 @@ bus_acquired_cb (GDBusConnection *connection,
         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);
@@ -1064,12 +1062,35 @@ main (int argc, char **argv)
     /* 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++)
         {
@@ -1078,15 +1099,18 @@ main (int argc, char **argv)
 
             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);
             }
 
@@ -1094,6 +1118,20 @@ main (int argc, char **argv)
         }
         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;
     }
 
index 45985bb6dfee655808367ced0ae03ce56ec852bc..98a0fa33653ac0e89efdda32b7eae80951763cf5 100644 (file)
@@ -96,14 +96,12 @@ compositor_ready_cb (UnitySystemCompositor *compositor, SeatUnity *seat)
         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);
index b6e8d0e69e7486d36db71e29eef4cf115dfc3198..ea38dd3486a8af42dbd8e978cbd8b9e4890fd84e 100644 (file)
@@ -79,14 +79,12 @@ seat_xlocal_start (Seat *seat)
         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);