[telepathy-gabble/master] add loudmouth/lm-message-node.[ch]

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 11 07:56:11 PDT 2009


---
 lib/loudmouth/lm-message-node.c |  172 +++++++++++++++++++++++++++++++++++++++
 lib/loudmouth/lm-message-node.h |   62 ++++++++++++++
 2 files changed, 234 insertions(+), 0 deletions(-)
 create mode 100644 lib/loudmouth/lm-message-node.c
 create mode 100644 lib/loudmouth/lm-message-node.h

diff --git a/lib/loudmouth/lm-message-node.c b/lib/loudmouth/lm-message-node.c
new file mode 100644
index 0000000..697aa27
--- /dev/null
+++ b/lib/loudmouth/lm-message-node.c
@@ -0,0 +1,172 @@
+/*
+ * lm-message-node.c - Loudmouth-Wocky compatibility layer
+ * Copyright (C) 2009 Collabora Ltd.
+ * @author Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "lm-message-node.h"
+
+#include <wocky/wocky-utils.h>
+
+static gboolean
+copy_attribute (const gchar *key,
+    const gchar *value,
+    const gchar *ns,
+    gpointer user_data)
+{
+  WockyXmppNode *copy = (WockyXmppNode *) user_data;
+
+  wocky_xmpp_node_set_attribute_ns (copy, key, value, ns);
+  return TRUE;
+}
+
+static WockyXmppNode *
+copy_node (WockyXmppNode *node)
+{
+  WockyXmppNode *copy;
+  GSList *l;
+
+  copy = wocky_xmpp_node_new (node->name);
+  wocky_xmpp_node_set_content (copy, node->content);
+  wocky_xmpp_node_set_language (copy, wocky_xmpp_node_get_language (node));
+  wocky_xmpp_node_set_ns (copy, wocky_xmpp_node_get_ns (node));
+
+  wocky_xmpp_node_each_attribute (node, copy_attribute, copy);
+
+  for (l = node->children; l != NULL; l = g_slist_next (l))
+    {
+      WockyXmppNode *child = l->data;
+
+      copy->children = g_slist_prepend (copy->children, copy_node (child));
+    }
+  copy->children = g_slist_reverse (copy->children);
+
+  return copy;
+}
+
+LmMessageNode *
+lm_message_node_ref (LmMessageNode *node)
+{
+  /* WockyXmppNode are not ref counted. Return a copy of the node */
+  return copy_node (node);
+}
+
+void
+lm_message_node_unref (LmMessageNode *node)
+{
+  wocky_xmpp_node_free (node);
+}
+
+void
+lm_message_node_set_attribute (LmMessageNode *node,
+    const gchar *name,
+    const gchar *value)
+{
+  if (!wocky_strdiff (name, "xmlns"))
+    wocky_xmpp_node_set_ns (node, value);
+  else
+    wocky_xmpp_node_set_attribute (node, name, value);
+}
+
+const gchar *
+lm_message_node_get_attribute (LmMessageNode *node,
+    const gchar *name)
+{
+  if (!wocky_strdiff (name, "xmlns"))
+    return wocky_xmpp_node_get_ns (node);
+
+  return wocky_xmpp_node_get_attribute (node, name);
+}
+
+void
+lm_message_node_set_attributes (LmMessageNode *node,
+    const gchar *name,
+    ...)
+{
+  va_list args;
+
+  g_return_if_fail (node != NULL);
+
+  va_start (args, name);
+  while (name != NULL)
+    {
+      const gchar *value;
+      value = (const gchar *) va_arg (args, gchar *);
+
+      lm_message_node_set_attribute (node, name, value);
+
+      name = (const gchar *) va_arg (args, gchar *);
+    }
+  va_end (args);
+}
+
+LmMessageNode *
+lm_message_node_add_child (LmMessageNode *node,
+    const gchar *name,
+    const gchar *value)
+{
+  return wocky_xmpp_node_add_child_with_content (node, name, value);
+}
+
+LmMessageNode *
+lm_message_node_get_child (LmMessageNode *node,
+    const gchar *child_name)
+{
+  return wocky_xmpp_node_get_child (node, child_name);
+}
+
+LmMessageNode *
+lm_message_node_find_child (LmMessageNode *node,
+    const gchar *child_name)
+{
+  WockyXmppNode *found;
+  GSList *l;
+
+  found = wocky_xmpp_node_get_child (node, child_name);
+  if (found != NULL)
+    return found;
+
+  for (l = node->children; l != NULL; l = g_slist_next (l))
+    {
+      WockyXmppNode *child = l->data;
+
+      found = lm_message_node_find_child (child, child_name);
+      if (found != NULL)
+        return found;
+    }
+
+  return NULL;
+}
+
+const gchar *
+lm_message_node_get_value (LmMessageNode *node)
+{
+  return node->content;
+}
+
+void
+lm_message_node_set_value (LmMessageNode *node,
+    const gchar *value)
+{
+  wocky_xmpp_node_set_content (node, value);
+}
+
+gchar *
+lm_message_node_to_string (LmMessageNode *node)
+{
+  return wocky_xmpp_node_to_string (node);
+}
diff --git a/lib/loudmouth/lm-message-node.h b/lib/loudmouth/lm-message-node.h
new file mode 100644
index 0000000..79e61ac
--- /dev/null
+++ b/lib/loudmouth/lm-message-node.h
@@ -0,0 +1,62 @@
+/*
+ * lm-message-node.h - Loudmouth-Wocky compatibility layer
+ * Copyright (C) 2009 Collabora Ltd.
+ * @author Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __LM_MESSAGE_NODE_H__
+#define __LM_MESSAGE_NODE_H__
+
+#include <wocky/wocky-xmpp-node.h>
+
+G_BEGIN_DECLS
+
+typedef WockyXmppNode LmMessageNode;
+
+LmMessageNode * lm_message_node_ref (LmMessageNode *node)
+  G_GNUC_WARN_UNUSED_RESULT;
+void lm_message_node_unref (LmMessageNode *node);
+
+void lm_message_node_set_attribute (LmMessageNode *node,
+    const gchar *name,
+    const gchar *value);
+
+const gchar * lm_message_node_get_attribute (LmMessageNode *node,
+    const gchar *name);
+
+void lm_message_node_set_attributes (LmMessageNode *node,
+    const gchar *name,
+    ...);
+
+LmMessageNode * lm_message_node_add_child (LmMessageNode *node,
+    const gchar *name,
+    const gchar *value);
+
+LmMessageNode * lm_message_node_get_child (LmMessageNode *node,
+    const gchar *child_name);
+
+LmMessageNode * lm_message_node_find_child (LmMessageNode *node,
+    const gchar *child_name);
+
+const gchar * lm_message_node_get_value (LmMessageNode *node);
+
+void lm_message_node_set_value (LmMessageNode *node,
+    const gchar *value);
+
+gchar * lm_message_node_to_string (LmMessageNode *node);
+
+#endif /* #ifndef __LM_MESSAGE_NODE_H__ */
-- 
1.5.6.5




More information about the telepathy-commits mailing list