diff options
author | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2010-04-19 15:39:23 +0100 |
---|---|---|
committer | Sjoerd Simons <sjoerd.simons@collabora.co.uk> | 2010-04-20 12:19:57 +0100 |
commit | 969a12f4e13a46f0ccef3f125232811a32b94aa0 (patch) | |
tree | e3bf5d900b0bc23e42745e09cada0c63b12911cf | |
parent | 4f0b7b2163b1b0e9666189ad9cddc90d52cba96b (diff) |
Require nodes to always have a namespace
-rw-r--r-- | wocky/wocky-node.c | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/wocky/wocky-node.c b/wocky/wocky-node.c index 7c241e9..043f18a 100644 --- a/wocky/wocky-node.c +++ b/wocky/wocky-node.c @@ -61,9 +61,28 @@ static NSPrefix default_attr_ns_prefixes[] = static GHashTable *user_ns_prefixes = NULL; static GHashTable *default_ns_prefixes = NULL; +static WockyNode * +wocky_node_new_fallback_ns (const char *name, + const gchar *ns, + GQuark parent_ns) +{ + WockyNode *result; + + g_return_val_if_fail (name != NULL, NULL); + g_return_val_if_fail (ns != NULL || parent_ns != 0, NULL); + + result = g_slice_new0 (WockyNode); + + result->name = g_strdup (name); + result->ns = (ns != NULL) ? g_quark_from_string (ns) : parent_ns; + + return result; +} + /** * wocky_node_new: - * @name: the node's name + * @name: the node's name (may not be NULL) + * @ns: the nodes namespace (may not be NULL) * * Convenience function which creates a #WockyNode and sets its * name to @name. @@ -73,12 +92,9 @@ static GHashTable *default_ns_prefixes = NULL; WockyNode * wocky_node_new (const char *name, const gchar *ns) { - WockyNode *result = g_slice_new0 (WockyNode); - - result->name = g_strdup (name); - result->ns = g_quark_from_string (ns); + g_return_val_if_fail (ns != NULL, NULL); - return result; + return wocky_node_new_fallback_ns (name, ns, 0); } static void @@ -686,10 +702,7 @@ WockyNode * wocky_node_add_child_with_content_ns (WockyNode *node, const gchar *name, const gchar *content, const gchar *ns) { - WockyNode *result = wocky_node_new (name, ns); - - if (result->ns == 0) - result->ns = node->ns; + WockyNode *result = wocky_node_new_fallback_ns (name, ns, node->ns); wocky_node_set_content (result, content); |