summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2010-12-07 01:06:33 -0500
committerRyan Lortie <desrt@desrt.ca>2010-12-07 01:36:09 -0500
commit814c0fcaafd42c622634c7b6a34c126210b17fc2 (patch)
treef0d1299c8caa049264b17d2b790f31c5c914c2b5
parente5e491c96946ec6ff6809e4b2b757b1f2d497867 (diff)
downloaddconf-814c0fcaafd42c622634c7b6a34c126210b17fc2.tar.gz
Pass name_length to walk close function
For efficiency and safety. This way we don't need to scan backwards for the path separator (trusting that we will find it properly).
-rw-r--r--gvdb-reader.c29
-rw-r--r--gvdb-reader.h3
2 files changed, 30 insertions, 2 deletions
diff --git a/gvdb-reader.c b/gvdb-reader.c
index fb23393..f49ff4e 100644
--- a/gvdb-reader.c
+++ b/gvdb-reader.c
@@ -574,6 +574,30 @@ gvdb_table_is_valid (GvdbTable *table)
return !!*table->data;
}
+/**
+ * gvdb_table_walk:
+ * @table: a #GvdbTable
+ * @key: a key corresponding to a list
+ * @open_func: the #GvdbWalkOpenFunc
+ * @value_func: the #GvdbWalkValueFunc
+ * @close_func: the #GvdbWalkCloseFunc
+ * @user_data: data to pass to the callbacks
+ *
+ * Looks up the list at @key and iterate over the items in it.
+ *
+ * First, @open_func is called to signal that we are starting to iterate over
+ * the list. Then the list is iterated. When all items in the list have been
+ * iterated over, the @close_func is called.
+ *
+ * When iterating, if a given item in the list is a value then @value_func is
+ * called.
+ *
+ * If a given item in the list is itself a list then @open_func is called. If
+ * that function returns %TRUE then the walk begins iterating the items in the
+ * sublist, until there are no more items, at which point a matching
+ * @close_func call is made. If @open_func returns %FALSE then no iteration of
+ * the sublist occurs and no corresponding @close_func call is made.
+ **/
void
gvdb_table_walk (GvdbTable *table,
const gchar *key,
@@ -585,16 +609,18 @@ gvdb_table_walk (GvdbTable *table,
const struct gvdb_hash_item *item;
const guint32_le *pointers[64];
const guint32_le *enders[64];
+ gsize name_lengths[64];
gint index = 0;
item = gvdb_table_lookup (table, key, 'L');
+ name_lengths[0] = 0;
pointers[0] = NULL;
enders[0] = NULL;
goto start_here;
while (index)
{
- close_func (user_data);
+ close_func (name_lengths[index], user_data);
index--;
while (pointers[index] < enders[index])
@@ -621,6 +647,7 @@ gvdb_table_walk (GvdbTable *table,
&pointers[index],
&length);
enders[index] = pointers[index] + length;
+ name_lengths[index] = name_len;
}
}
else if (item->type == 'v')
diff --git a/gvdb-reader.h b/gvdb-reader.h
index 9f302c0..e75c69c 100644
--- a/gvdb-reader.h
+++ b/gvdb-reader.h
@@ -62,7 +62,8 @@ typedef void (*GvdbWalkValueFunc) (const g
typedef gboolean (*GvdbWalkOpenFunc) (const gchar *name,
gsize name_len,
gpointer user_data);
-typedef void (*GvdbWalkCloseFunc) (gpointer user_data);
+typedef void (*GvdbWalkCloseFunc) (gsize name_len,
+ gpointer user_data);
void gvdb_table_walk (GvdbTable *table,
const gchar *key,