mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-09-20 17:26:14 +02:00
Add API for dconf's sake.
This commit is contained in:
parent
daa1a73c75
commit
5215d4b6d3
@ -430,7 +430,7 @@ file_builder_add_hash (FileBuilder *fb,
|
|||||||
|
|
||||||
if (item->child != NULL)
|
if (item->child != NULL)
|
||||||
{
|
{
|
||||||
guint32 children = 0;
|
guint32 children = 0, i = 0;
|
||||||
guint32_le *offsets;
|
guint32_le *offsets;
|
||||||
GvdbItem *child;
|
GvdbItem *child;
|
||||||
|
|
||||||
@ -444,9 +444,9 @@ file_builder_add_hash (FileBuilder *fb,
|
|||||||
entry->type = 'L';
|
entry->type = 'L';
|
||||||
|
|
||||||
for (child = item->child; child; child = child->sibling)
|
for (child = item->child; child; child = child->sibling)
|
||||||
offsets[--children] = child->assigned_index;
|
offsets[i++] = child->assigned_index;
|
||||||
|
|
||||||
g_assert (children == 0);
|
g_assert (children == i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item->table != NULL)
|
if (item->table != NULL)
|
||||||
|
151
gvdb-reader.c
151
gvdb-reader.c
@ -283,6 +283,37 @@ gvdb_table_lookup (GvdbTable *file,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct gvdb_hash_item *
|
||||||
|
gvdb_table_get_item (GvdbTable *table,
|
||||||
|
guint32_le item_no)
|
||||||
|
{
|
||||||
|
guint32 item_no_native = guint32_from_le (item_no);
|
||||||
|
|
||||||
|
if G_LIKELY (item_no_native < table->n_hash_items)
|
||||||
|
return table->hash_items + item_no_native;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gvdb_table_list_from_item (GvdbTable *table,
|
||||||
|
const struct gvdb_hash_item *item,
|
||||||
|
const guint32_le **list,
|
||||||
|
guint *length)
|
||||||
|
{
|
||||||
|
gsize size;
|
||||||
|
|
||||||
|
*list = gvdb_table_dereference (table, &item->value.pointer, 4, &size);
|
||||||
|
|
||||||
|
if G_LIKELY (*list == NULL || size % 4)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
*length = size / 4;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gvdb_table_list:
|
* gvdb_table_list:
|
||||||
* @file: a #GvdbTable
|
* @file: a #GvdbTable
|
||||||
@ -308,21 +339,17 @@ gvdb_table_list (GvdbTable *file,
|
|||||||
const struct gvdb_hash_item *item;
|
const struct gvdb_hash_item *item;
|
||||||
const guint32_le *list;
|
const guint32_le *list;
|
||||||
gchar **strv;
|
gchar **strv;
|
||||||
gsize size;
|
guint length;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
if ((item = gvdb_table_lookup (file, key, 'L')) == NULL)
|
if ((item = gvdb_table_lookup (file, key, 'L')) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
list = gvdb_table_dereference (file, &item->value.pointer, 4, &size);
|
if (!gvdb_table_list_from_item (file, item, &list, &length))
|
||||||
|
|
||||||
if G_UNLIKELY (list == NULL || size % 4)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
size /= 4;
|
strv = g_new (gchar *, length + 1);
|
||||||
|
for (i = 0; i < length; i++)
|
||||||
strv = g_new (gchar *, size + 1);
|
|
||||||
for (i = 0; i < size; i++)
|
|
||||||
{
|
{
|
||||||
guint32 itemno = guint32_from_le (list[i]);
|
guint32 itemno = guint32_from_le (list[i]);
|
||||||
|
|
||||||
@ -368,6 +395,29 @@ gvdb_table_has_value (GvdbTable *file,
|
|||||||
return gvdb_table_lookup (file, key, 'v') != NULL;
|
return gvdb_table_lookup (file, key, 'v') != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GVariant *
|
||||||
|
gvdb_table_value_from_item (GvdbTable *table,
|
||||||
|
const struct gvdb_hash_item *item)
|
||||||
|
{
|
||||||
|
GVariant *variant, *value;
|
||||||
|
gconstpointer data;
|
||||||
|
gsize size;
|
||||||
|
|
||||||
|
data = gvdb_table_dereference (table, &item->value.pointer, 8, &size);
|
||||||
|
|
||||||
|
if G_UNLIKELY (data == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
variant = g_variant_new_from_data (G_VARIANT_TYPE_VARIANT,
|
||||||
|
data, size, table->trusted,
|
||||||
|
(GDestroyNotify) g_mapped_file_unref,
|
||||||
|
g_mapped_file_ref (table->mapped));
|
||||||
|
value = g_variant_get_variant (variant);
|
||||||
|
g_variant_unref (variant);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gvdb_table_get_value:
|
* gvdb_table_get_value:
|
||||||
* @file: a #GvdbTable
|
* @file: a #GvdbTable
|
||||||
@ -394,27 +444,18 @@ gvdb_table_get_value (GvdbTable *file,
|
|||||||
GVariant **options)
|
GVariant **options)
|
||||||
{
|
{
|
||||||
const struct gvdb_hash_item *item;
|
const struct gvdb_hash_item *item;
|
||||||
GVariant *variant, *value;
|
GVariant *value;
|
||||||
gconstpointer data;
|
|
||||||
gsize size;
|
|
||||||
|
|
||||||
if ((item = gvdb_table_lookup (file, key, 'v')) == NULL)
|
if ((item = gvdb_table_lookup (file, key, 'v')) == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data = gvdb_table_dereference (file, &item->value.pointer, 8, &size);
|
value = gvdb_table_value_from_item (file, item);
|
||||||
|
|
||||||
if G_UNLIKELY (data == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
variant = g_variant_new_from_data (G_VARIANT_TYPE_VARIANT,
|
|
||||||
data, size, file->trusted,
|
|
||||||
(GDestroyNotify) g_mapped_file_unref,
|
|
||||||
g_mapped_file_ref (file->mapped));
|
|
||||||
value = g_variant_get_variant (variant);
|
|
||||||
g_variant_unref (variant);
|
|
||||||
|
|
||||||
if (options != NULL)
|
if (options != NULL)
|
||||||
{
|
{
|
||||||
|
gconstpointer data;
|
||||||
|
gsize size;
|
||||||
|
|
||||||
data = gvdb_table_dereference (file, &item->options, 8, &size);
|
data = gvdb_table_dereference (file, &item->options, 8, &size);
|
||||||
|
|
||||||
if (data != NULL && size > 0)
|
if (data != NULL && size > 0)
|
||||||
@ -508,3 +549,69 @@ gvdb_table_unref (GvdbTable *file)
|
|||||||
g_slice_free (GvdbTable, file);
|
g_slice_free (GvdbTable, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gvdb_table_walk (GvdbTable *table,
|
||||||
|
const gchar *key,
|
||||||
|
GvdbWalkOpenFunc open_func,
|
||||||
|
GvdbWalkValueFunc value_func,
|
||||||
|
GvdbWalkCloseFunc close_func,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
const struct gvdb_hash_item *item;
|
||||||
|
const guint32_le *pointers[64];
|
||||||
|
const guint32_le *enders[64];
|
||||||
|
gint index = 0;
|
||||||
|
|
||||||
|
item = gvdb_table_lookup (table, key, 'L');
|
||||||
|
pointers[0] = NULL;
|
||||||
|
enders[0] = NULL;
|
||||||
|
goto start_here;
|
||||||
|
|
||||||
|
while (index)
|
||||||
|
{
|
||||||
|
close_func (user_data);
|
||||||
|
index--;
|
||||||
|
|
||||||
|
while (pointers[index] < enders[index])
|
||||||
|
{
|
||||||
|
const gchar *name;
|
||||||
|
gsize name_len;
|
||||||
|
|
||||||
|
item = gvdb_table_get_item (table, *pointers[index]++);
|
||||||
|
start_here:
|
||||||
|
|
||||||
|
if (item != NULL &&
|
||||||
|
(name = gvdb_table_item_get_key (table, item, &name_len)))
|
||||||
|
{
|
||||||
|
if (item->type == 'L')
|
||||||
|
{
|
||||||
|
if (open_func (name, name_len, user_data))
|
||||||
|
{
|
||||||
|
guint length;
|
||||||
|
|
||||||
|
index++;
|
||||||
|
g_assert (index < 64);
|
||||||
|
|
||||||
|
gvdb_table_list_from_item (table, item,
|
||||||
|
&pointers[index],
|
||||||
|
&length);
|
||||||
|
enders[index] = pointers[index] + length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (item->type == 'v')
|
||||||
|
{
|
||||||
|
GVariant *value;
|
||||||
|
|
||||||
|
value = gvdb_table_value_from_item (table, item);
|
||||||
|
|
||||||
|
if (value != NULL)
|
||||||
|
{
|
||||||
|
value_func (name, name_len, value, user_data);
|
||||||
|
g_variant_unref (value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -50,5 +50,21 @@ G_GNUC_INTERNAL
|
|||||||
gboolean gvdb_table_has_value (GvdbTable *table,
|
gboolean gvdb_table_has_value (GvdbTable *table,
|
||||||
const gchar *key);
|
const gchar *key);
|
||||||
|
|
||||||
|
typedef void (*GvdbWalkValueFunc) (const gchar *name,
|
||||||
|
gsize name_len,
|
||||||
|
GVariant *value,
|
||||||
|
gpointer user_data);
|
||||||
|
typedef gboolean (*GvdbWalkOpenFunc) (const gchar *name,
|
||||||
|
gsize name_len,
|
||||||
|
gpointer user_data);
|
||||||
|
typedef void (*GvdbWalkCloseFunc) (gpointer user_data);
|
||||||
|
|
||||||
|
void gvdb_table_walk (GvdbTable *table,
|
||||||
|
const gchar *key,
|
||||||
|
GvdbWalkOpenFunc open_func,
|
||||||
|
GvdbWalkValueFunc value_func,
|
||||||
|
GvdbWalkCloseFunc close_func,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __gvdb_reader_h__ */
|
#endif /* __gvdb_reader_h__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user