Initialize variable
[glib.git] / gio / gsettingsschema.c
blobf1274a3699e8f9bdaa7adaaa1cda779c5bd06fd5
1 /*
2 * Copyright © 2010 Codethink Limited
3 * Copyright © 2011 Canonical Limited
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "config.h"
21 #include "gsettingsschema-internal.h"
22 #include "gsettings.h"
24 #include "gvdb/gvdb-reader.h"
25 #include "strinfo.c"
27 #include <glibintl.h>
28 #include <locale.h>
29 #include <string.h>
31 /**
32 * SECTION:gsettingsschema
33 * @short_description: Introspecting and controlling the loading
34 * of GSettings schemas
35 * @include: gio/gio.h
37 * The #GSettingsSchemaSource and #GSettingsSchema APIs provide a
38 * mechanism for advanced control over the loading of schemas and a
39 * mechanism for introspecting their content.
41 * Plugin loading systems that wish to provide plugins a way to access
42 * settings face the problem of how to make the schemas for these
43 * settings visible to GSettings. Typically, a plugin will want to ship
44 * the schema along with itself and it won't be installed into the
45 * standard system directories for schemas.
47 * #GSettingsSchemaSource provides a mechanism for dealing with this by
48 * allowing the creation of a new 'schema source' from which schemas can
49 * be acquired. This schema source can then become part of the metadata
50 * associated with the plugin and queried whenever the plugin requires
51 * access to some settings.
53 * Consider the following example:
55 * |[<!-- language="C" -->
56 * typedef struct
57 * {
58 * ...
59 * GSettingsSchemaSource *schema_source;
60 * ...
61 * } Plugin;
63 * Plugin *
64 * initialise_plugin (const gchar *dir)
65 * {
66 * Plugin *plugin;
68 * ...
70 * plugin->schema_source =
71 * g_settings_schema_source_new_from_directory (dir,
72 * g_settings_schema_source_get_default (), FALSE, NULL);
74 * ...
76 * return plugin;
77 * }
79 * ...
81 * GSettings *
82 * plugin_get_settings (Plugin *plugin,
83 * const gchar *schema_id)
84 * {
85 * GSettingsSchema *schema;
87 * if (schema_id == NULL)
88 * schema_id = plugin->identifier;
90 * schema = g_settings_schema_source_lookup (plugin->schema_source,
91 * schema_id, FALSE);
93 * if (schema == NULL)
94 * {
95 * ... disable the plugin or abort, etc ...
96 * }
98 * return g_settings_new_full (schema, NULL, NULL);
99 * }
100 * ]|
102 * The code above shows how hooks should be added to the code that
103 * initialises (or enables) the plugin to create the schema source and
104 * how an API can be added to the plugin system to provide a convenient
105 * way for the plugin to access its settings, using the schemas that it
106 * ships.
108 * From the standpoint of the plugin, it would need to ensure that it
109 * ships a gschemas.compiled file as part of itself, and then simply do
110 * the following:
112 * |[<!-- language="C" -->
114 * GSettings *settings;
115 * gint some_value;
117 * settings = plugin_get_settings (self, NULL);
118 * some_value = g_settings_get_int (settings, "some-value");
119 * ...
121 * ]|
123 * It's also possible that the plugin system expects the schema source
124 * files (ie: .gschema.xml files) instead of a gschemas.compiled file.
125 * In that case, the plugin loading system must compile the schemas for
126 * itself before attempting to create the settings source.
128 * Since: 2.32
132 * GSettingsSchemaKey:
134 * #GSettingsSchemaKey is an opaque data structure and can only be accessed
135 * using the following functions.
139 * GSettingsSchema:
141 * This is an opaque structure type. You may not access it directly.
143 * Since: 2.32
145 struct _GSettingsSchema
147 GSettingsSchemaSource *source;
148 const gchar *gettext_domain;
149 const gchar *path;
150 GQuark *items;
151 gint n_items;
152 GvdbTable *table;
153 gchar *id;
155 GSettingsSchema *extends;
157 gint ref_count;
161 * G_TYPE_SETTINGS_SCHEMA_SOURCE:
163 * A boxed #GType corresponding to #GSettingsSchemaSource.
165 * Since: 2.32
167 G_DEFINE_BOXED_TYPE (GSettingsSchemaSource, g_settings_schema_source, g_settings_schema_source_ref, g_settings_schema_source_unref)
170 * G_TYPE_SETTINGS_SCHEMA:
172 * A boxed #GType corresponding to #GSettingsSchema.
174 * Since: 2.32
176 G_DEFINE_BOXED_TYPE (GSettingsSchema, g_settings_schema, g_settings_schema_ref, g_settings_schema_unref)
179 * GSettingsSchemaSource:
181 * This is an opaque structure type. You may not access it directly.
183 * Since: 2.32
185 struct _GSettingsSchemaSource
187 GSettingsSchemaSource *parent;
188 gchar *directory;
189 GvdbTable *table;
190 GHashTable **text_tables;
192 gint ref_count;
195 static GSettingsSchemaSource *schema_sources;
198 * g_settings_schema_source_ref:
199 * @source: a #GSettingsSchemaSource
201 * Increase the reference count of @source, returning a new reference.
203 * Returns: a new reference to @source
205 * Since: 2.32
207 GSettingsSchemaSource *
208 g_settings_schema_source_ref (GSettingsSchemaSource *source)
210 g_atomic_int_inc (&source->ref_count);
212 return source;
216 * g_settings_schema_source_unref:
217 * @source: a #GSettingsSchemaSource
219 * Decrease the reference count of @source, possibly freeing it.
221 * Since: 2.32
223 void
224 g_settings_schema_source_unref (GSettingsSchemaSource *source)
226 if (g_atomic_int_dec_and_test (&source->ref_count))
228 if (source == schema_sources)
229 g_error ("g_settings_schema_source_unref() called too many times on the default schema source");
231 if (source->parent)
232 g_settings_schema_source_unref (source->parent);
233 gvdb_table_unref (source->table);
234 g_free (source->directory);
236 if (source->text_tables)
238 g_hash_table_unref (source->text_tables[0]);
239 g_hash_table_unref (source->text_tables[1]);
240 g_free (source->text_tables);
243 g_slice_free (GSettingsSchemaSource, source);
248 * g_settings_schema_source_new_from_directory:
249 * @directory: (type filename): the filename of a directory
250 * @parent: (nullable): a #GSettingsSchemaSource, or %NULL
251 * @trusted: %TRUE, if the directory is trusted
252 * @error: a pointer to a #GError pointer set to %NULL, or %NULL
254 * Attempts to create a new schema source corresponding to the contents
255 * of the given directory.
257 * This function is not required for normal uses of #GSettings but it
258 * may be useful to authors of plugin management systems.
260 * The directory should contain a file called `gschemas.compiled` as
261 * produced by the [glib-compile-schemas][glib-compile-schemas] tool.
263 * If @trusted is %TRUE then `gschemas.compiled` is trusted not to be
264 * corrupted. This assumption has a performance advantage, but can result
265 * in crashes or inconsistent behaviour in the case of a corrupted file.
266 * Generally, you should set @trusted to %TRUE for files installed by the
267 * system and to %FALSE for files in the home directory.
269 * If @parent is non-%NULL then there are two effects.
271 * First, if g_settings_schema_source_lookup() is called with the
272 * @recursive flag set to %TRUE and the schema can not be found in the
273 * source, the lookup will recurse to the parent.
275 * Second, any references to other schemas specified within this
276 * source (ie: `child` or `extends`) references may be resolved
277 * from the @parent.
279 * For this second reason, except in very unusual situations, the
280 * @parent should probably be given as the default schema source, as
281 * returned by g_settings_schema_source_get_default().
283 * Since: 2.32
285 GSettingsSchemaSource *
286 g_settings_schema_source_new_from_directory (const gchar *directory,
287 GSettingsSchemaSource *parent,
288 gboolean trusted,
289 GError **error)
291 GSettingsSchemaSource *source;
292 GvdbTable *table;
293 gchar *filename;
295 filename = g_build_filename (directory, "gschemas.compiled", NULL);
296 table = gvdb_table_new (filename, trusted, error);
297 g_free (filename);
299 if (table == NULL)
300 return NULL;
302 source = g_slice_new (GSettingsSchemaSource);
303 source->directory = g_strdup (directory);
304 source->parent = parent ? g_settings_schema_source_ref (parent) : NULL;
305 source->text_tables = NULL;
306 source->table = table;
307 source->ref_count = 1;
309 return source;
312 static void
313 try_prepend_dir (const gchar *directory)
315 GSettingsSchemaSource *source;
317 source = g_settings_schema_source_new_from_directory (directory, schema_sources, TRUE, NULL);
319 /* If we successfully created it then prepend it to the global list */
320 if (source != NULL)
321 schema_sources = source;
324 static void
325 try_prepend_data_dir (const gchar *directory)
327 gchar *dirname = g_build_filename (directory, "glib-2.0", "schemas", NULL);
328 try_prepend_dir (dirname);
329 g_free (dirname);
332 static void
333 initialise_schema_sources (void)
335 static gsize initialised;
337 /* need a separate variable because 'schema_sources' may legitimately
338 * be null if we have zero valid schema sources
340 if G_UNLIKELY (g_once_init_enter (&initialised))
342 const gchar * const *dirs;
343 const gchar *path;
344 gint i;
346 /* iterate in reverse: count up, then count down */
347 dirs = g_get_system_data_dirs ();
348 for (i = 0; dirs[i]; i++);
350 while (i--)
351 try_prepend_data_dir (dirs[i]);
353 try_prepend_data_dir (g_get_user_data_dir ());
355 if ((path = g_getenv ("GSETTINGS_SCHEMA_DIR")) != NULL)
356 try_prepend_dir (path);
358 g_once_init_leave (&initialised, TRUE);
363 * g_settings_schema_source_get_default:
365 * Gets the default system schema source.
367 * This function is not required for normal uses of #GSettings but it
368 * may be useful to authors of plugin management systems or to those who
369 * want to introspect the content of schemas.
371 * If no schemas are installed, %NULL will be returned.
373 * The returned source may actually consist of multiple schema sources
374 * from different directories, depending on which directories were given
375 * in `XDG_DATA_DIRS` and `GSETTINGS_SCHEMA_DIR`. For this reason, all
376 * lookups performed against the default source should probably be done
377 * recursively.
379 * Returns: (transfer none) (nullable): the default schema source
381 * Since: 2.32
383 GSettingsSchemaSource *
384 g_settings_schema_source_get_default (void)
386 initialise_schema_sources ();
388 return schema_sources;
392 * g_settings_schema_source_lookup:
393 * @source: a #GSettingsSchemaSource
394 * @schema_id: a schema ID
395 * @recursive: %TRUE if the lookup should be recursive
397 * Looks up a schema with the identifier @schema_id in @source.
399 * This function is not required for normal uses of #GSettings but it
400 * may be useful to authors of plugin management systems or to those who
401 * want to introspect the content of schemas.
403 * If the schema isn't found directly in @source and @recursive is %TRUE
404 * then the parent sources will also be checked.
406 * If the schema isn't found, %NULL is returned.
408 * Returns: (nullable) (transfer full): a new #GSettingsSchema
410 * Since: 2.32
412 GSettingsSchema *
413 g_settings_schema_source_lookup (GSettingsSchemaSource *source,
414 const gchar *schema_id,
415 gboolean recursive)
417 GSettingsSchema *schema;
418 GvdbTable *table;
419 const gchar *extends;
421 g_return_val_if_fail (source != NULL, NULL);
422 g_return_val_if_fail (schema_id != NULL, NULL);
424 table = gvdb_table_get_table (source->table, schema_id);
426 if (table == NULL && recursive)
427 for (source = source->parent; source; source = source->parent)
428 if ((table = gvdb_table_get_table (source->table, schema_id)))
429 break;
431 if (table == NULL)
432 return NULL;
434 schema = g_slice_new0 (GSettingsSchema);
435 schema->source = g_settings_schema_source_ref (source);
436 schema->ref_count = 1;
437 schema->id = g_strdup (schema_id);
438 schema->table = table;
439 schema->path = g_settings_schema_get_string (schema, ".path");
440 schema->gettext_domain = g_settings_schema_get_string (schema, ".gettext-domain");
442 if (schema->gettext_domain)
443 bind_textdomain_codeset (schema->gettext_domain, "UTF-8");
445 extends = g_settings_schema_get_string (schema, ".extends");
446 if (extends)
448 schema->extends = g_settings_schema_source_lookup (source, extends, TRUE);
449 if (schema->extends == NULL)
450 g_warning ("Schema '%s' extends schema '%s' but we could not find it", schema_id, extends);
453 return schema;
456 typedef struct
458 GHashTable *summaries;
459 GHashTable *descriptions;
460 GSList *gettext_domain;
461 GSList *schema_id;
462 GSList *key_name;
463 GString *string;
464 } TextTableParseInfo;
466 static const gchar *
467 get_attribute_value (GSList *list)
469 GSList *node;
471 for (node = list; node; node = node->next)
472 if (node->data)
473 return node->data;
475 return NULL;
478 static void
479 pop_attribute_value (GSList **list)
481 gchar *top;
483 top = (*list)->data;
484 *list = g_slist_remove (*list, top);
486 g_free (top);
489 static void
490 push_attribute_value (GSList **list,
491 const gchar *value)
493 *list = g_slist_prepend (*list, g_strdup (value));
496 static void
497 start_element (GMarkupParseContext *context,
498 const gchar *element_name,
499 const gchar **attribute_names,
500 const gchar **attribute_values,
501 gpointer user_data,
502 GError **error)
504 TextTableParseInfo *info = user_data;
505 const gchar *gettext_domain = NULL;
506 const gchar *schema_id = NULL;
507 const gchar *key_name = NULL;
508 gint i;
510 for (i = 0; attribute_names[i]; i++)
512 if (g_str_equal (attribute_names[i], "gettext-domain"))
513 gettext_domain = attribute_values[i];
514 else if (g_str_equal (attribute_names[i], "id"))
515 schema_id = attribute_values[i];
516 else if (g_str_equal (attribute_names[i], "name"))
517 key_name = attribute_values[i];
520 push_attribute_value (&info->gettext_domain, gettext_domain);
521 push_attribute_value (&info->schema_id, schema_id);
522 push_attribute_value (&info->key_name, key_name);
524 if (info->string)
526 g_string_free (info->string, TRUE);
527 info->string = NULL;
530 if (g_str_equal (element_name, "summary") || g_str_equal (element_name, "description"))
531 info->string = g_string_new (NULL);
534 static gchar *
535 normalise_whitespace (const gchar *orig)
537 /* We normalise by the same rules as in intltool:
539 * sub cleanup {
540 * s/^\s+//;
541 * s/\s+$//;
542 * s/\s+/ /g;
543 * return $_;
546 * $message = join "\n\n", map &cleanup, split/\n\s*\n+/, $message;
548 * Where \s is an ascii space character.
550 * We aim for ease of implementation over efficiency -- this code is
551 * not run in normal applications.
553 static GRegex *cleanup[3];
554 static GRegex *splitter;
555 gchar **lines;
556 gchar *result;
557 gint i;
559 if (g_once_init_enter (&splitter))
561 GRegex *s;
563 cleanup[0] = g_regex_new ("^\\s+", 0, 0, 0);
564 cleanup[1] = g_regex_new ("\\s+$", 0, 0, 0);
565 cleanup[2] = g_regex_new ("\\s+", 0, 0, 0);
566 s = g_regex_new ("\\n\\s*\\n+", 0, 0, 0);
568 g_once_init_leave (&splitter, s);
571 lines = g_regex_split (splitter, orig, 0);
572 for (i = 0; lines[i]; i++)
574 gchar *a, *b, *c;
576 a = g_regex_replace_literal (cleanup[0], lines[i], -1, 0, "", 0, 0);
577 b = g_regex_replace_literal (cleanup[1], a, -1, 0, "", 0, 0);
578 c = g_regex_replace_literal (cleanup[2], b, -1, 0, " ", 0, 0);
579 g_free (lines[i]);
580 g_free (a);
581 g_free (b);
582 lines[i] = c;
585 result = g_strjoinv ("\n\n", lines);
586 g_strfreev (lines);
588 return result;
591 static void
592 end_element (GMarkupParseContext *context,
593 const gchar *element_name,
594 gpointer user_data,
595 GError **error)
597 TextTableParseInfo *info = user_data;
599 pop_attribute_value (&info->gettext_domain);
600 pop_attribute_value (&info->schema_id);
601 pop_attribute_value (&info->key_name);
603 if (info->string)
605 GHashTable *source_table = NULL;
606 const gchar *gettext_domain;
607 const gchar *schema_id;
608 const gchar *key_name;
610 gettext_domain = get_attribute_value (info->gettext_domain);
611 schema_id = get_attribute_value (info->schema_id);
612 key_name = get_attribute_value (info->key_name);
614 if (g_str_equal (element_name, "summary"))
615 source_table = info->summaries;
616 else if (g_str_equal (element_name, "description"))
617 source_table = info->descriptions;
619 if (source_table && schema_id && key_name)
621 GHashTable *schema_table;
622 gchar *normalised;
624 schema_table = g_hash_table_lookup (source_table, schema_id);
626 if (schema_table == NULL)
628 schema_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
629 g_hash_table_insert (source_table, g_strdup (schema_id), schema_table);
632 normalised = normalise_whitespace (info->string->str);
634 if (gettext_domain && normalised[0])
636 gchar *translated;
638 translated = g_strdup (g_dgettext (gettext_domain, normalised));
639 g_free (normalised);
640 normalised = translated;
643 g_hash_table_insert (schema_table, g_strdup (key_name), normalised);
646 g_string_free (info->string, TRUE);
647 info->string = NULL;
651 static void
652 text (GMarkupParseContext *context,
653 const gchar *text,
654 gsize text_len,
655 gpointer user_data,
656 GError **error)
658 TextTableParseInfo *info = user_data;
660 if (info->string)
661 g_string_append_len (info->string, text, text_len);
664 static void
665 parse_into_text_tables (const gchar *directory,
666 GHashTable *summaries,
667 GHashTable *descriptions)
669 GMarkupParser parser = { start_element, end_element, text };
670 TextTableParseInfo info = { summaries, descriptions };
671 const gchar *basename;
672 GDir *dir;
674 dir = g_dir_open (directory, 0, NULL);
675 while ((basename = g_dir_read_name (dir)))
677 gchar *filename;
678 gchar *contents;
679 gsize size;
681 filename = g_build_filename (directory, basename, NULL);
682 if (g_file_get_contents (filename, &contents, &size, NULL))
684 GMarkupParseContext *context;
686 context = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &info, NULL);
687 /* Ignore errors here, this is best effort only. */
688 if (g_markup_parse_context_parse (context, contents, size, NULL))
689 (void) g_markup_parse_context_end_parse (context, NULL);
690 g_markup_parse_context_free (context);
692 /* Clean up dangling stuff in case there was an error. */
693 g_slist_free_full (info.gettext_domain, g_free);
694 g_slist_free_full (info.schema_id, g_free);
695 g_slist_free_full (info.key_name, g_free);
697 info.gettext_domain = NULL;
698 info.schema_id = NULL;
699 info.key_name = NULL;
701 if (info.string)
703 g_string_free (info.string, TRUE);
704 info.string = NULL;
707 g_free (contents);
710 g_free (filename);
713 g_dir_close (dir);
716 static GHashTable **
717 g_settings_schema_source_get_text_tables (GSettingsSchemaSource *source)
719 if (g_once_init_enter (&source->text_tables))
721 GHashTable **text_tables;
723 text_tables = g_new (GHashTable *, 2);
724 text_tables[0] = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref);
725 text_tables[1] = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_unref);
727 if (source->directory)
728 parse_into_text_tables (source->directory, text_tables[0], text_tables[1]);
730 g_once_init_leave (&source->text_tables, text_tables);
733 return source->text_tables;
737 * g_settings_schema_source_list_schemas:
738 * @source: a #GSettingsSchemaSource
739 * @recursive: if we should recurse
740 * @non_relocatable: (out) (transfer full) (array zero-terminated=1): the
741 * list of non-relocatable schemas
742 * @relocatable: (out) (transfer full) (array zero-terminated=1): the list
743 * of relocatable schemas
745 * Lists the schemas in a given source.
747 * If @recursive is %TRUE then include parent sources. If %FALSE then
748 * only include the schemas from one source (ie: one directory). You
749 * probably want %TRUE.
751 * Non-relocatable schemas are those for which you can call
752 * g_settings_new(). Relocatable schemas are those for which you must
753 * use g_settings_new_with_path().
755 * Do not call this function from normal programs. This is designed for
756 * use by database editors, commandline tools, etc.
758 * Since: 2.40
760 void
761 g_settings_schema_source_list_schemas (GSettingsSchemaSource *source,
762 gboolean recursive,
763 gchar ***non_relocatable,
764 gchar ***relocatable)
766 GHashTable *single, *reloc;
767 GSettingsSchemaSource *s;
769 /* We use hash tables to avoid duplicate listings for schemas that
770 * appear in more than one file.
772 single = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
773 reloc = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
775 for (s = source; s; s = s->parent)
777 gchar **list;
778 gint i;
780 list = gvdb_table_list (s->table, "");
782 /* empty schema cache file? */
783 if (list == NULL)
784 continue;
786 for (i = 0; list[i]; i++)
788 if (!g_hash_table_contains (single, list[i]) &&
789 !g_hash_table_contains (reloc, list[i]))
791 gchar *schema;
792 GvdbTable *table;
794 schema = g_strdup (list[i]);
796 table = gvdb_table_get_table (s->table, list[i]);
797 g_assert (table != NULL);
799 if (gvdb_table_has_value (table, ".path"))
800 g_hash_table_add (single, schema);
801 else
802 g_hash_table_add (reloc, schema);
804 gvdb_table_unref (table);
808 g_strfreev (list);
810 /* Only the first source if recursive not requested */
811 if (!recursive)
812 break;
815 if (non_relocatable)
817 *non_relocatable = (gchar **) g_hash_table_get_keys_as_array (single, NULL);
818 g_hash_table_steal_all (single);
821 if (relocatable)
823 *relocatable = (gchar **) g_hash_table_get_keys_as_array (reloc, NULL);
824 g_hash_table_steal_all (reloc);
827 g_hash_table_unref (single);
828 g_hash_table_unref (reloc);
831 static gchar **non_relocatable_schema_list;
832 static gchar **relocatable_schema_list;
833 static gsize schema_lists_initialised;
835 static void
836 ensure_schema_lists (void)
838 if (g_once_init_enter (&schema_lists_initialised))
840 initialise_schema_sources ();
842 g_settings_schema_source_list_schemas (schema_sources, TRUE,
843 &non_relocatable_schema_list,
844 &relocatable_schema_list);
846 g_once_init_leave (&schema_lists_initialised, TRUE);
851 * g_settings_list_schemas:
853 * Deprecated.
855 * Returns: (element-type utf8) (transfer none): a list of #GSettings
856 * schemas that are available. The list must not be modified or
857 * freed.
859 * Since: 2.26
861 * Deprecated: 2.40: Use g_settings_schema_source_list_schemas() instead.
862 * If you used g_settings_list_schemas() to check for the presence of
863 * a particular schema, use g_settings_schema_source_lookup() instead
864 * of your whole loop.
866 const gchar * const *
867 g_settings_list_schemas (void)
869 ensure_schema_lists ();
871 return (const gchar **) non_relocatable_schema_list;
875 * g_settings_list_relocatable_schemas:
877 * Deprecated.
879 * Returns: (element-type utf8) (transfer none): a list of relocatable
880 * #GSettings schemas that are available. The list must not be
881 * modified or freed.
883 * Since: 2.28
885 * Deprecated: 2.40: Use g_settings_schema_source_list_schemas() instead
887 const gchar * const *
888 g_settings_list_relocatable_schemas (void)
890 ensure_schema_lists ();
892 return (const gchar **) relocatable_schema_list;
896 * g_settings_schema_ref:
897 * @schema: a #GSettingsSchema
899 * Increase the reference count of @schema, returning a new reference.
901 * Returns: a new reference to @schema
903 * Since: 2.32
905 GSettingsSchema *
906 g_settings_schema_ref (GSettingsSchema *schema)
908 g_atomic_int_inc (&schema->ref_count);
910 return schema;
914 * g_settings_schema_unref:
915 * @schema: a #GSettingsSchema
917 * Decrease the reference count of @schema, possibly freeing it.
919 * Since: 2.32
921 void
922 g_settings_schema_unref (GSettingsSchema *schema)
924 if (g_atomic_int_dec_and_test (&schema->ref_count))
926 if (schema->extends)
927 g_settings_schema_unref (schema->extends);
929 g_settings_schema_source_unref (schema->source);
930 gvdb_table_unref (schema->table);
931 g_free (schema->items);
932 g_free (schema->id);
934 g_slice_free (GSettingsSchema, schema);
938 const gchar *
939 g_settings_schema_get_string (GSettingsSchema *schema,
940 const gchar *key)
942 const gchar *result = NULL;
943 GVariant *value;
945 if ((value = gvdb_table_get_raw_value (schema->table, key)))
947 result = g_variant_get_string (value, NULL);
948 g_variant_unref (value);
951 return result;
954 GVariantIter *
955 g_settings_schema_get_value (GSettingsSchema *schema,
956 const gchar *key)
958 GSettingsSchema *s = schema;
959 GVariantIter *iter;
960 GVariant *value = NULL;
962 g_return_val_if_fail (schema != NULL, NULL);
964 for (s = schema; s; s = s->extends)
965 if ((value = gvdb_table_get_raw_value (s->table, key)))
966 break;
968 if G_UNLIKELY (value == NULL || !g_variant_is_of_type (value, G_VARIANT_TYPE_TUPLE))
969 g_error ("Settings schema '%s' does not contain a key named '%s'", schema->id, key);
971 iter = g_variant_iter_new (value);
972 g_variant_unref (value);
974 return iter;
978 * g_settings_schema_get_path:
979 * @schema: a #GSettingsSchema
981 * Gets the path associated with @schema, or %NULL.
983 * Schemas may be single-instance or relocatable. Single-instance
984 * schemas correspond to exactly one set of keys in the backend
985 * database: those located at the path returned by this function.
987 * Relocatable schemas can be referenced by other schemas and can
988 * threfore describe multiple sets of keys at different locations. For
989 * relocatable schemas, this function will return %NULL.
991 * Returns: (transfer none): the path of the schema, or %NULL
993 * Since: 2.32
995 const gchar *
996 g_settings_schema_get_path (GSettingsSchema *schema)
998 return schema->path;
1001 const gchar *
1002 g_settings_schema_get_gettext_domain (GSettingsSchema *schema)
1004 return schema->gettext_domain;
1008 * g_settings_schema_has_key:
1009 * @schema: a #GSettingsSchema
1010 * @name: the name of a key
1012 * Checks if @schema has a key named @name.
1014 * Returns: %TRUE if such a key exists
1016 * Since: 2.40
1018 gboolean
1019 g_settings_schema_has_key (GSettingsSchema *schema,
1020 const gchar *key)
1022 return gvdb_table_has_value (schema->table, key);
1026 * g_settings_schema_list_children:
1027 * @schema: a #GSettingsSchema
1029 * Gets the list of children in @schema.
1031 * You should free the return value with g_strfreev() when you are done
1032 * with it.
1034 * Returns: (transfer full) (element-type utf8): a list of the children on @settings
1036 * Since: 2.44
1038 gchar **
1039 g_settings_schema_list_children (GSettingsSchema *schema)
1041 const GQuark *keys;
1042 gchar **strv;
1043 gint n_keys;
1044 gint i, j;
1046 g_return_val_if_fail (schema != NULL, NULL);
1048 keys = g_settings_schema_list (schema, &n_keys);
1049 strv = g_new (gchar *, n_keys + 1);
1050 for (i = j = 0; i < n_keys; i++)
1052 const gchar *key = g_quark_to_string (keys[i]);
1054 if (g_str_has_suffix (key, "/"))
1056 gint length = strlen (key);
1058 strv[j] = g_memdup (key, length);
1059 strv[j][length - 1] = '\0';
1060 j++;
1063 strv[j] = NULL;
1065 return strv;
1069 * g_settings_schema_list_keys:
1070 * @schema: a #GSettingsSchema
1072 * Introspects the list of keys on @schema.
1074 * You should probably not be calling this function from "normal" code
1075 * (since you should already know what keys are in your schema). This
1076 * function is intended for introspection reasons.
1078 * Returns: (transfer full) (element-type utf8): a list of the keys on
1079 * @schema
1081 * Since: 2.46
1083 gchar **
1084 g_settings_schema_list_keys (GSettingsSchema *schema)
1086 const GQuark *keys;
1087 gchar **strv;
1088 gint n_keys;
1089 gint i, j;
1091 g_return_val_if_fail (schema != NULL, NULL);
1093 keys = g_settings_schema_list (schema, &n_keys);
1094 strv = g_new (gchar *, n_keys + 1);
1095 for (i = j = 0; i < n_keys; i++)
1097 const gchar *key = g_quark_to_string (keys[i]);
1099 if (!g_str_has_suffix (key, "/"))
1100 strv[j++] = g_strdup (key);
1102 strv[j] = NULL;
1104 return strv;
1107 const GQuark *
1108 g_settings_schema_list (GSettingsSchema *schema,
1109 gint *n_items)
1111 if (schema->items == NULL)
1113 GSettingsSchema *s;
1114 GHashTableIter iter;
1115 GHashTable *items;
1116 gpointer name;
1117 gint len;
1118 gint i;
1120 items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
1122 for (s = schema; s; s = s->extends)
1124 gchar **list;
1126 list = gvdb_table_list (s->table, "");
1128 if (list)
1130 for (i = 0; list[i]; i++)
1131 g_hash_table_add (items, list[i]); /* transfer ownership */
1133 g_free (list); /* free container only */
1137 /* Do a first pass to eliminate child items that do not map to
1138 * valid schemas (ie: ones that would crash us if we actually
1139 * tried to create them).
1141 g_hash_table_iter_init (&iter, items);
1142 while (g_hash_table_iter_next (&iter, &name, NULL))
1143 if (g_str_has_suffix (name, "/"))
1145 GSettingsSchemaSource *source;
1146 GVariant *child_schema;
1147 GvdbTable *child_table;
1149 child_schema = gvdb_table_get_raw_value (schema->table, name);
1150 if (!child_schema)
1151 continue;
1153 child_table = NULL;
1155 for (source = schema->source; source; source = source->parent)
1156 if ((child_table = gvdb_table_get_table (source->table, g_variant_get_string (child_schema, NULL))))
1157 break;
1159 g_variant_unref (child_schema);
1161 /* Schema is not found -> remove it from the list */
1162 if (child_table == NULL)
1164 g_hash_table_iter_remove (&iter);
1165 continue;
1168 /* Make sure the schema is relocatable or at the
1169 * expected path
1171 if (gvdb_table_has_value (child_table, ".path"))
1173 GVariant *path;
1174 gchar *expected;
1175 gboolean same;
1177 path = gvdb_table_get_raw_value (child_table, ".path");
1178 expected = g_strconcat (schema->path, name, NULL);
1179 same = g_str_equal (expected, g_variant_get_string (path, NULL));
1180 g_variant_unref (path);
1181 g_free (expected);
1183 /* Schema is non-relocatable and did not have the
1184 * expected path -> remove it from the list
1186 if (!same)
1187 g_hash_table_iter_remove (&iter);
1190 gvdb_table_unref (child_table);
1193 /* Now create the list */
1194 len = g_hash_table_size (items);
1195 schema->items = g_new (GQuark, len);
1196 i = 0;
1197 g_hash_table_iter_init (&iter, items);
1199 while (g_hash_table_iter_next (&iter, &name, NULL))
1200 schema->items[i++] = g_quark_from_string (name);
1201 schema->n_items = i;
1202 g_assert (i == len);
1204 g_hash_table_unref (items);
1207 *n_items = schema->n_items;
1208 return schema->items;
1212 * g_settings_schema_get_id:
1213 * @schema: a #GSettingsSchema
1215 * Get the ID of @schema.
1217 * Returns: (transfer none): the ID
1219 const gchar *
1220 g_settings_schema_get_id (GSettingsSchema *schema)
1222 return schema->id;
1225 static inline void
1226 endian_fixup (GVariant **value)
1228 #if G_BYTE_ORDER == G_BIG_ENDIAN
1229 GVariant *tmp;
1231 tmp = g_variant_byteswap (*value);
1232 g_variant_unref (*value);
1233 *value = tmp;
1234 #endif
1237 void
1238 g_settings_schema_key_init (GSettingsSchemaKey *key,
1239 GSettingsSchema *schema,
1240 const gchar *name)
1242 GVariantIter *iter;
1243 GVariant *data;
1244 guchar code;
1246 memset (key, 0, sizeof *key);
1248 iter = g_settings_schema_get_value (schema, name);
1250 key->schema = g_settings_schema_ref (schema);
1251 key->default_value = g_variant_iter_next_value (iter);
1252 endian_fixup (&key->default_value);
1253 key->type = g_variant_get_type (key->default_value);
1254 key->name = g_intern_string (name);
1256 while (g_variant_iter_next (iter, "(y*)", &code, &data))
1258 switch (code)
1260 case 'l':
1261 /* translation requested */
1262 g_variant_get (data, "(y&s)", &key->lc_char, &key->unparsed);
1263 break;
1265 case 'e':
1266 /* enumerated types... */
1267 key->is_enum = TRUE;
1268 goto choice;
1270 case 'f':
1271 /* flags... */
1272 key->is_flags = TRUE;
1273 goto choice;
1275 choice: case 'c':
1276 /* ..., choices, aliases */
1277 key->strinfo = g_variant_get_fixed_array (data, &key->strinfo_length, sizeof (guint32));
1278 break;
1280 case 'r':
1281 g_variant_get (data, "(**)", &key->minimum, &key->maximum);
1282 endian_fixup (&key->minimum);
1283 endian_fixup (&key->maximum);
1284 break;
1286 default:
1287 g_warning ("unknown schema extension '%c'", code);
1288 break;
1291 g_variant_unref (data);
1294 g_variant_iter_free (iter);
1297 void
1298 g_settings_schema_key_clear (GSettingsSchemaKey *key)
1300 if (key->minimum)
1301 g_variant_unref (key->minimum);
1303 if (key->maximum)
1304 g_variant_unref (key->maximum);
1306 g_variant_unref (key->default_value);
1308 g_settings_schema_unref (key->schema);
1311 gboolean
1312 g_settings_schema_key_type_check (GSettingsSchemaKey *key,
1313 GVariant *value)
1315 g_return_val_if_fail (value != NULL, FALSE);
1317 return g_variant_is_of_type (value, key->type);
1320 GVariant *
1321 g_settings_schema_key_range_fixup (GSettingsSchemaKey *key,
1322 GVariant *value)
1324 const gchar *target;
1326 if (g_settings_schema_key_range_check (key, value))
1327 return g_variant_ref (value);
1329 if (key->strinfo == NULL)
1330 return NULL;
1332 if (g_variant_is_container (value))
1334 GVariantBuilder builder;
1335 GVariantIter iter;
1336 GVariant *child;
1338 g_variant_iter_init (&iter, value);
1339 g_variant_builder_init (&builder, g_variant_get_type (value));
1341 while ((child = g_variant_iter_next_value (&iter)))
1343 GVariant *fixed;
1345 fixed = g_settings_schema_key_range_fixup (key, child);
1346 g_variant_unref (child);
1348 if (fixed == NULL)
1350 g_variant_builder_clear (&builder);
1351 return NULL;
1354 g_variant_builder_add_value (&builder, fixed);
1355 g_variant_unref (fixed);
1358 return g_variant_ref_sink (g_variant_builder_end (&builder));
1361 target = strinfo_string_from_alias (key->strinfo, key->strinfo_length,
1362 g_variant_get_string (value, NULL));
1363 return target ? g_variant_ref_sink (g_variant_new_string (target)) : NULL;
1366 GVariant *
1367 g_settings_schema_key_get_translated_default (GSettingsSchemaKey *key)
1369 const gchar *translated;
1370 GError *error = NULL;
1371 const gchar *domain;
1372 GVariant *value;
1374 domain = g_settings_schema_get_gettext_domain (key->schema);
1376 if (key->lc_char == '\0')
1377 /* translation not requested for this key */
1378 return NULL;
1380 if (key->lc_char == 't')
1381 translated = g_dcgettext (domain, key->unparsed, LC_TIME);
1382 else
1383 translated = g_dgettext (domain, key->unparsed);
1385 if (translated == key->unparsed)
1386 /* the default value was not translated */
1387 return NULL;
1389 /* try to parse the translation of the unparsed default */
1390 value = g_variant_parse (key->type, translated, NULL, NULL, &error);
1392 if (value == NULL)
1394 g_warning ("Failed to parse translated string '%s' for "
1395 "key '%s' in schema '%s': %s", translated, key->name,
1396 g_settings_schema_get_id (key->schema), error->message);
1397 g_warning ("Using untranslated default instead.");
1398 g_error_free (error);
1401 else if (!g_settings_schema_key_range_check (key, value))
1403 g_warning ("Translated default '%s' for key '%s' in schema '%s' "
1404 "is outside of valid range", key->unparsed, key->name,
1405 g_settings_schema_get_id (key->schema));
1406 g_variant_unref (value);
1407 value = NULL;
1410 return value;
1413 gint
1414 g_settings_schema_key_to_enum (GSettingsSchemaKey *key,
1415 GVariant *value)
1417 gboolean it_worked;
1418 guint result;
1420 it_worked = strinfo_enum_from_string (key->strinfo, key->strinfo_length,
1421 g_variant_get_string (value, NULL),
1422 &result);
1424 /* 'value' can only come from the backend after being filtered for validity,
1425 * from the translation after being filtered for validity, or from the schema
1426 * itself (which the schema compiler checks for validity). If this assertion
1427 * fails then it's really a bug in GSettings or the schema compiler...
1429 g_assert (it_worked);
1431 return result;
1434 GVariant *
1435 g_settings_schema_key_from_enum (GSettingsSchemaKey *key,
1436 gint value)
1438 const gchar *string;
1440 string = strinfo_string_from_enum (key->strinfo, key->strinfo_length, value);
1442 if (string == NULL)
1443 return NULL;
1445 return g_variant_new_string (string);
1448 guint
1449 g_settings_schema_key_to_flags (GSettingsSchemaKey *key,
1450 GVariant *value)
1452 GVariantIter iter;
1453 const gchar *flag;
1454 guint result;
1456 result = 0;
1457 g_variant_iter_init (&iter, value);
1458 while (g_variant_iter_next (&iter, "&s", &flag))
1460 gboolean it_worked;
1461 guint flag_value;
1463 it_worked = strinfo_enum_from_string (key->strinfo, key->strinfo_length, flag, &flag_value);
1464 /* as in g_settings_to_enum() */
1465 g_assert (it_worked);
1467 result |= flag_value;
1470 return result;
1473 GVariant *
1474 g_settings_schema_key_from_flags (GSettingsSchemaKey *key,
1475 guint value)
1477 GVariantBuilder builder;
1478 gint i;
1480 g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
1482 for (i = 0; i < 32; i++)
1483 if (value & (1u << i))
1485 const gchar *string;
1487 string = strinfo_string_from_enum (key->strinfo, key->strinfo_length, 1u << i);
1489 if (string == NULL)
1491 g_variant_builder_clear (&builder);
1492 return NULL;
1495 g_variant_builder_add (&builder, "s", string);
1498 return g_variant_builder_end (&builder);
1501 G_DEFINE_BOXED_TYPE (GSettingsSchemaKey, g_settings_schema_key, g_settings_schema_key_ref, g_settings_schema_key_unref)
1504 * g_settings_schema_key_ref:
1505 * @key: a #GSettingsSchemaKey
1507 * Increase the reference count of @key, returning a new reference.
1509 * Returns: a new reference to @key
1511 * Since: 2.40
1513 GSettingsSchemaKey *
1514 g_settings_schema_key_ref (GSettingsSchemaKey *key)
1516 g_return_val_if_fail (key != NULL, NULL);
1518 g_atomic_int_inc (&key->ref_count);
1520 return key;
1524 * g_settings_schema_key_unref:
1525 * @key: a #GSettingsSchemaKey
1527 * Decrease the reference count of @key, possibly freeing it.
1529 * Since: 2.40
1531 void
1532 g_settings_schema_key_unref (GSettingsSchemaKey *key)
1534 g_return_if_fail (key != NULL);
1536 if (g_atomic_int_dec_and_test (&key->ref_count))
1538 g_settings_schema_key_clear (key);
1540 g_slice_free (GSettingsSchemaKey, key);
1545 * g_settings_schema_get_key:
1546 * @schema: a #GSettingsSchema
1547 * @name: the name of a key
1549 * Gets the key named @name from @schema.
1551 * It is a programmer error to request a key that does not exist. See
1552 * g_settings_schema_list_keys().
1554 * Returns: (transfer full): the #GSettingsSchemaKey for @name
1556 * Since: 2.40
1558 GSettingsSchemaKey *
1559 g_settings_schema_get_key (GSettingsSchema *schema,
1560 const gchar *name)
1562 GSettingsSchemaKey *key;
1564 g_return_val_if_fail (schema != NULL, NULL);
1565 g_return_val_if_fail (name != NULL, NULL);
1567 key = g_slice_new (GSettingsSchemaKey);
1568 g_settings_schema_key_init (key, schema, name);
1569 key->ref_count = 1;
1571 return key;
1575 * g_settings_schema_key_get_name:
1576 * @key: a #GSettingsSchemaKey
1578 * Gets the name of @key.
1580 * Returns: the name of @key.
1582 * Since: 2.44
1584 const gchar *
1585 g_settings_schema_key_get_name (GSettingsSchemaKey *key)
1587 g_return_val_if_fail (key != NULL, NULL);
1589 return key->name;
1593 * g_settings_schema_key_get_summary:
1594 * @key: a #GSettingsSchemaKey
1596 * Gets the summary for @key.
1598 * If no summary has been provided in the schema for @key, returns
1599 * %NULL.
1601 * The summary is a short description of the purpose of the key; usually
1602 * one short sentence. Summaries can be translated and the value
1603 * returned from this function is is the current locale.
1605 * This function is slow. The summary and description information for
1606 * the schemas is not stored in the compiled schema database so this
1607 * function has to parse all of the source XML files in the schema
1608 * directory.
1610 * Returns: the summary for @key, or %NULL
1612 * Since: 2.34
1614 const gchar *
1615 g_settings_schema_key_get_summary (GSettingsSchemaKey *key)
1617 GHashTable **text_tables;
1618 GHashTable *summaries;
1620 text_tables = g_settings_schema_source_get_text_tables (key->schema->source);
1621 summaries = g_hash_table_lookup (text_tables[0], key->schema->id);
1623 return summaries ? g_hash_table_lookup (summaries, key->name) : NULL;
1627 * g_settings_schema_key_get_description:
1628 * @key: a #GSettingsSchemaKey
1630 * Gets the description for @key.
1632 * If no description has been provided in the schema for @key, returns
1633 * %NULL.
1635 * The description can be one sentence to several paragraphs in length.
1636 * Paragraphs are delimited with a double newline. Descriptions can be
1637 * translated and the value returned from this function is is the
1638 * current locale.
1640 * This function is slow. The summary and description information for
1641 * the schemas is not stored in the compiled schema database so this
1642 * function has to parse all of the source XML files in the schema
1643 * directory.
1645 * Returns: the description for @key, or %NULL
1647 * Since: 2.34
1649 const gchar *
1650 g_settings_schema_key_get_description (GSettingsSchemaKey *key)
1652 GHashTable **text_tables;
1653 GHashTable *descriptions;
1655 text_tables = g_settings_schema_source_get_text_tables (key->schema->source);
1656 descriptions = g_hash_table_lookup (text_tables[1], key->schema->id);
1658 return descriptions ? g_hash_table_lookup (descriptions, key->name) : NULL;
1662 * g_settings_schema_key_get_value_type:
1663 * @key: a #GSettingsSchemaKey
1665 * Gets the #GVariantType of @key.
1667 * Returns: (transfer none): the type of @key
1669 * Since: 2.40
1671 const GVariantType *
1672 g_settings_schema_key_get_value_type (GSettingsSchemaKey *key)
1674 g_return_val_if_fail (key, NULL);
1676 return key->type;
1680 * g_settings_schema_key_get_default_value:
1681 * @key: a #GSettingsSchemaKey
1683 * Gets the default value for @key.
1685 * Note that this is the default value according to the schema. System
1686 * administrator defaults and lockdown are not visible via this API.
1688 * Returns: (transfer full): the default value for the key
1690 * Since: 2.40
1692 GVariant *
1693 g_settings_schema_key_get_default_value (GSettingsSchemaKey *key)
1695 GVariant *value;
1697 g_return_val_if_fail (key, NULL);
1699 value = g_settings_schema_key_get_translated_default (key);
1701 if (!value)
1702 value = g_variant_ref (key->default_value);
1704 return value;
1708 * g_settings_schema_key_get_range:
1709 * @key: a #GSettingsSchemaKey
1711 * Queries the range of a key.
1713 * This function will return a #GVariant that fully describes the range
1714 * of values that are valid for @key.
1716 * The type of #GVariant returned is `(sv)`. The string describes
1717 * the type of range restriction in effect. The type and meaning of
1718 * the value contained in the variant depends on the string.
1720 * If the string is `'type'` then the variant contains an empty array.
1721 * The element type of that empty array is the expected type of value
1722 * and all values of that type are valid.
1724 * If the string is `'enum'` then the variant contains an array
1725 * enumerating the possible values. Each item in the array is
1726 * a possible valid value and no other values are valid.
1728 * If the string is `'flags'` then the variant contains an array. Each
1729 * item in the array is a value that may appear zero or one times in an
1730 * array to be used as the value for this key. For example, if the
1731 * variant contained the array `['x', 'y']` then the valid values for
1732 * the key would be `[]`, `['x']`, `['y']`, `['x', 'y']` and
1733 * `['y', 'x']`.
1735 * Finally, if the string is `'range'` then the variant contains a pair
1736 * of like-typed values -- the minimum and maximum permissible values
1737 * for this key.
1739 * This information should not be used by normal programs. It is
1740 * considered to be a hint for introspection purposes. Normal programs
1741 * should already know what is permitted by their own schema. The
1742 * format may change in any way in the future -- but particularly, new
1743 * forms may be added to the possibilities described above.
1745 * You should free the returned value with g_variant_unref() when it is
1746 * no longer needed.
1748 * Returns: (transfer full): a #GVariant describing the range
1750 * Since: 2.40
1752 GVariant *
1753 g_settings_schema_key_get_range (GSettingsSchemaKey *key)
1755 const gchar *type;
1756 GVariant *range;
1758 if (key->minimum)
1760 range = g_variant_new ("(**)", key->minimum, key->maximum);
1761 type = "range";
1763 else if (key->strinfo)
1765 range = strinfo_enumerate (key->strinfo, key->strinfo_length);
1766 type = key->is_flags ? "flags" : "enum";
1768 else
1770 range = g_variant_new_array (key->type, NULL, 0);
1771 type = "type";
1774 return g_variant_ref_sink (g_variant_new ("(sv)", type, range));
1778 * g_settings_schema_key_range_check:
1779 * @key: a #GSettingsSchemaKey
1780 * @value: the value to check
1782 * Checks if the given @value is of the correct type and within the
1783 * permitted range for @key.
1785 * It is a programmer error if @value is not of the correct type -- you
1786 * must check for this first.
1788 * Returns: %TRUE if @value is valid for @key
1790 * Since: 2.40
1792 gboolean
1793 g_settings_schema_key_range_check (GSettingsSchemaKey *key,
1794 GVariant *value)
1796 if (key->minimum == NULL && key->strinfo == NULL)
1797 return TRUE;
1799 if (g_variant_is_container (value))
1801 gboolean ok = TRUE;
1802 GVariantIter iter;
1803 GVariant *child;
1805 g_variant_iter_init (&iter, value);
1806 while (ok && (child = g_variant_iter_next_value (&iter)))
1808 ok = g_settings_schema_key_range_check (key, child);
1809 g_variant_unref (child);
1812 return ok;
1815 if (key->minimum)
1817 return g_variant_compare (key->minimum, value) <= 0 &&
1818 g_variant_compare (value, key->maximum) <= 0;
1821 return strinfo_is_string_valid (key->strinfo, key->strinfo_length,
1822 g_variant_get_string (value, NULL));