gdbus: Avoid blocking on worker thread in connection initialization
[platform/upstream/glib.git] / gio / gkeyfilesettingsbackend.c
index 6c11329..f61bb8b 100644 (file)
@@ -32,7 +32,6 @@
 #include "gsimplepermission.h"
 #include "gsettingsbackend.h"
 
-#include "gioalias.h"
 
 #define G_TYPE_KEYFILE_SETTINGS_BACKEND      (g_keyfile_settings_backend_get_type ())
 #define G_KEYFILE_SETTINGS_BACKEND(inst)     (G_TYPE_CHECK_INSTANCE_CAST ((inst),      \
@@ -64,6 +63,7 @@ typedef struct
   GFileMonitor      *dir_monitor;
 } GKeyfileSettingsBackend;
 
+static GType g_keyfile_settings_backend_get_type (void);
 G_DEFINE_TYPE (GKeyfileSettingsBackend,
                g_keyfile_settings_backend,
                G_TYPE_SETTINGS_BACKEND)
@@ -293,7 +293,7 @@ g_keyfile_settings_backend_check_one (gpointer key,
 }
 
 static gboolean
-g_keyfile_settings_backend_write_many (GSettingsBackend *backend,
+g_keyfile_settings_backend_write_tree (GSettingsBackend *backend,
                                        GTree            *tree,
                                        gpointer          origin_tag)
 {
@@ -339,19 +339,6 @@ g_keyfile_settings_backend_write (GSettingsBackend *backend,
 }
 
 static void
-g_keyfile_settings_backend_reset_path (GSettingsBackend *backend,
-                                       const gchar      *path,
-                                       gpointer          origin_tag)
-{
-  GKeyfileSettingsBackend *kfsb = G_KEYFILE_SETTINGS_BACKEND (backend);
-
-  if (set_to_keyfile (kfsb, path, NULL))
-    g_keyfile_settings_backend_keyfile_write (kfsb);
-
-  g_settings_backend_path_changed (backend, path, origin_tag);
-}
-
-static void
 g_keyfile_settings_backend_reset (GSettingsBackend *backend,
                                   const gchar      *key,
                                   gpointer          origin_tag)
@@ -399,12 +386,23 @@ keyfile_to_tree (GKeyfileSettingsBackend *kfsb,
       gint j;
 
       is_root_group = g_strcmp0 (kfsb->root_group, groups[i]) == 0;
+
+      /* reject group names that will form invalid key names */
+      if (!is_root_group &&
+          (g_str_has_prefix (groups[i], "/") ||
+           g_str_has_suffix (groups[i], "/") || strstr (groups[i], "//")))
+        continue;
+
       keys = g_key_file_get_keys (keyfile, groups[i], NULL, NULL);
 
       for (j = 0; keys[j]; j++)
         {
           gchar *path, *value;
 
+          /* reject key names with slashes in them */
+          if (strchr (keys[j], '/'))
+            continue;
+
           if (is_root_group)
             path = g_strdup_printf ("%s%s", kfsb->prefix, keys[j]);
           else
@@ -534,9 +532,8 @@ g_keyfile_settings_backend_class_init (GKeyfileSettingsBackendClass *class)
 
   class->read = g_keyfile_settings_backend_read;
   class->write = g_keyfile_settings_backend_write;
-  class->write_keys = g_keyfile_settings_backend_write_many;
+  class->write_tree = g_keyfile_settings_backend_write_tree;
   class->reset = g_keyfile_settings_backend_reset;
-  class->reset_path = g_keyfile_settings_backend_reset_path;
   class->get_writable = g_keyfile_settings_backend_get_writable;
   class->get_permission = g_keyfile_settings_backend_get_permission;
   /* No need to implement subscribed/unsubscribe: the only point would be to
@@ -574,7 +571,7 @@ dir_changed (GFileMonitor       *monitor,
  * @root_path: the path under which all settings keys appear
  * @root_group: (allow-none): the group name corresponding to
  *              @root_path, or %NULL
- * Returns: a keyfile-backed #GSettingsBackend
+ * @returns: (transfer full): a keyfile-backed #GSettingsBackend
  *
  * Creates a keyfile-backed #GSettingsBackend.
  *
@@ -590,10 +587,10 @@ dir_changed (GFileMonitor       *monitor,
  * "toplevel", then settings the key "/apps/example/enabled" to a value
  * of %TRUE will cause the following to appear in the keyfile:
  *
- * <programlisting>
+ * |[
  *   [toplevel]
- *   foo=true
- * </programlisting>
+ *   enabled=true
+ * ]|
  *
  * If @root_group is %NULL then it is not permitted to store keys
  * directly below the @root_path.
@@ -601,13 +598,13 @@ dir_changed (GFileMonitor       *monitor,
  * For keys not stored directly below @root_path (ie: in a sub-path),
  * the name of the subpath (with the final slash stripped) is used as
  * the name of the keyfile group.  To continue the example, if
- * were stored in "/apps/example/profiles/default/font-size" were set to
+ * "/apps/example/profiles/default/font-size" were set to
  * 12 then the following would appear in the keyfile:
  *
- * <programlisting>
+ * |[
  *   [profiles/default]
  *   font-size=12
- * </programlisting>
+ * ]|
  *
  * The backend will refuse writes (and return writability as being
  * %FALSE) for keys outside of @root_path and, in the event that
@@ -615,6 +612,11 @@ dir_changed (GFileMonitor       *monitor,
  * Writes will also be refused if the backend detects that it has the
  * inability to rewrite the keyfile (ie: the containing directory is not
  * writable).
+ *
+ * There is no checking done for your key namespace clashing with the
+ * syntax of the key file format.  For example, if you have '[' or ']'
+ * characters in your path names or '=' in your key names you may be in
+ * trouble.
  **/
 GSettingsBackend *
 g_keyfile_settings_backend_new (const gchar *filename,
@@ -661,6 +663,3 @@ g_keyfile_settings_backend_new (const gchar *filename,
 
   return G_SETTINGS_BACKEND (kfsb);
 }
-
-#define __G_KEYFILE_SETTINGS_BACKEND_C__
-#include "gioaliasdef.c"