diff options
author | Allison Lortie <allison@humber.desrt.ca> | 2017-01-18 10:23:41 -0500 |
---|---|---|
committer | Allison Lortie <allison@humber.desrt.ca> | 2017-01-18 10:23:41 -0500 |
commit | f1e62228aa0faeeb405901f4e6aa41dd3595ec93 (patch) | |
tree | 521fe63541ee0aee9774e2cc9d3bf9dc1fd5b360 /gvdb/gvdb-builder.c | |
parent | dd0b0d22d812b6a081ada59c7f636b8130ab2f11 (diff) | |
download | dconf-f1e62228aa0faeeb405901f4e6aa41dd3595ec93.tar.gz |
more proxy changes wipwip/proxy
Diffstat (limited to 'gvdb/gvdb-builder.c')
-rw-r--r-- | gvdb/gvdb-builder.c | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/gvdb/gvdb-builder.c b/gvdb/gvdb-builder.c index 90ea50b..fd37cd0 100644 --- a/gvdb/gvdb-builder.c +++ b/gvdb/gvdb-builder.c @@ -96,21 +96,85 @@ djb_hash (const gchar *key) return hash_value; } +/* /a/b/ → /a/ + * /a/b → /a/ + * / → NULL + */ +static gchar * +gvdb_get_parent_name (const gchar *path, + gchar separator) +{ + gsize len; + + len = strlen (path); + if (len == 1) + return NULL; + + /* '/path/name/' → '/path/name' */ + if (path[len - 1] == separator) + len--; + + /* '/path/name' → '/path/' */ + while (path[len - 1] != separator) + len--; + + return g_strndup (path, len); +} + +static void +gvdb_hash_table_setup_item_parent (GHashTable *table, + GvdbItem *item, + gchar separator) +{ + GvdbItem *parent; + gchar *parent_name; + + parent_name = gvdb_get_parent_name (item->key, separator); + if (parent_name == NULL) + /* root node */ + return; + + parent = g_hash_table_lookup (table, parent_name); + + if (parent == NULL) + { + parent = gvdb_hash_table_insert (table, parent_name); + gvdb_hash_table_setup_item_parent (table, parent, separator); + } + + gvdb_item_set_parent (item, parent); + + g_free (parent_name); +} + GvdbItem * -gvdb_hash_table_insert (GHashTable *table, - const gchar *key) +gvdb_hash_table_insert_path (GHashTable *table, + const gchar *key, + gchar separator) { GvdbItem *item; + g_assert (!separator || key[0] == separator); + item = g_slice_new0 (GvdbItem); item->key = g_strdup (key); item->hash_value = djb_hash (key); g_hash_table_insert (table, g_strdup (key), item); + if (separator) + gvdb_hash_table_setup_item_parent (table, item, separator); + return item; } +GvdbItem * +gvdb_hash_table_insert (GHashTable *table, + const gchar *key) +{ + return gvdb_hash_table_insert_path (table, key, '\0'); +} + void gvdb_hash_table_insert_string (GHashTable *table, const gchar *key, |