[telepathy-gabble/master] util.c: add lm_message_node_get_attribute_with_namespace
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Thu Jul 23 08:49:13 PDT 2009
---
src/util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
src/util.h | 5 ++++-
2 files changed, 48 insertions(+), 1 deletions(-)
diff --git a/src/util.c b/src/util.c
index 7cf253e..25b35be 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1011,3 +1011,47 @@ gabble_signal_connect_weak (gpointer instance,
g_object_weak_ref (instance_obj, instance_destroyed_cb, ctx);
g_object_weak_ref (user_data, user_data_destroyed_cb, ctx);
}
+
+typedef struct {
+ gchar *key;
+ gchar *value;
+} Attribute;
+
+const gchar *
+lm_message_node_get_attribute_with_namespace (LmMessageNode *node,
+ const gchar *attribute,
+ const gchar *ns)
+{
+ GSList *l;
+ const gchar *result = NULL;
+
+ g_return_val_if_fail (node != NULL, NULL);
+ g_return_val_if_fail (attribute != NULL, NULL);
+ g_return_val_if_fail (ns != NULL, NULL);
+
+ for (l = node->attributes; l != NULL && result == NULL; l = g_slist_next (l))
+ {
+ /* This is NOT part of loudmouth API; it depends LM internals */
+ Attribute *attr = (Attribute *) l->data;
+ gchar **pair;
+
+ pair = g_strsplit (attr->key, ":", 2);
+
+ if (tp_strdiff (pair[1], attribute))
+ /* no prefix (pair[1] == NULL) or the local-name is not the
+ * attribute we are looking for */
+ goto next_attribute;
+
+ if (tp_strdiff (find_namespace_of_prefix (node, pair[0]), ns))
+ /* wrong namespace */
+ goto next_attribute;
+
+ result = attr->value;
+
+next_attribute:
+ g_strfreev (pair);
+ continue;
+ }
+
+ return result;
+}
diff --git a/src/util.h b/src/util.h
index 7760b7e..7e7138a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -82,11 +82,14 @@ const gchar * lm_message_node_get_name (LmMessageNode *node);
LmMessageNode * lm_message_node_get_child_any_ns (LmMessageNode *node,
const gchar *name);
-
LmMessage *
lm_iq_message_make_result (LmMessage *iq_message);
void gabble_signal_connect_weak (gpointer instance, const gchar *detailed_signal,
GCallback c_handler, GObject *user_data);
+const gchar * lm_message_node_get_attribute_with_namespace (LmMessageNode *node,
+ const gchar *attribute,
+ const gchar *ns);
+
#endif /* __GABBLE_UTIL_H__ */
--
1.5.6.5
More information about the telepathy-commits
mailing list