aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppDiscoveryIq.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-02-11 07:51:06 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-02-11 07:51:06 +0000
commite386059f004474d4ffa32a9573a3f36dbec4439b (patch)
tree1d734bbbf62ac4182e20a036fa43eaf0b7b7cebb /source/QXmppDiscoveryIq.cpp
parentc8ce37573791629d5d475e00d81c371d44d4311d (diff)
downloadqxmpp-e386059f004474d4ffa32a9573a3f36dbec4439b.tar.gz
add support for XEP-0030 : Service Discovery
Diffstat (limited to 'source/QXmppDiscoveryIq.cpp')
-rw-r--r--source/QXmppDiscoveryIq.cpp123
1 files changed, 123 insertions, 0 deletions
diff --git a/source/QXmppDiscoveryIq.cpp b/source/QXmppDiscoveryIq.cpp
new file mode 100644
index 00000000..b5cb8d93
--- /dev/null
+++ b/source/QXmppDiscoveryIq.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2010 Bolloré telecom
+ *
+ * Author:
+ * Jeremy Lainé
+ *
+ * Source:
+ * http://code.google.com/p/qxmpp
+ *
+ * This file is a part of QXmpp library.
+ *
+ * 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.
+ *
+ */
+
+#include "QXmppConstants.h"
+#include "QXmppDiscoveryIq.h"
+#include "QXmppUtils.h"
+
+#include <QDomElement>
+
+QStringList QXmppDiscoveryItem::attributes() const
+{
+ return m_attributes.keys();
+}
+
+QString QXmppDiscoveryItem::attribute(const QString &name) const
+{
+ return m_attributes.value(name);
+}
+
+void QXmppDiscoveryItem::setAttribute(const QString &name, const QString &value)
+{
+ m_attributes.insert(name, value);
+}
+
+QString QXmppDiscoveryItem::type() const
+{
+ return m_type;
+}
+
+void QXmppDiscoveryItem::setType(const QString &type)
+{
+ m_type = type;
+}
+
+QList<QXmppDiscoveryItem> QXmppDiscoveryIq::getItems() const
+{
+ return m_items;
+}
+
+void QXmppDiscoveryIq::setItems(const QList<QXmppDiscoveryItem> &items)
+{
+ m_items = items;
+}
+
+enum QXmppDiscoveryIq::QueryType QXmppDiscoveryIq::getQueryType() const
+{
+ return m_queryType;
+}
+
+void QXmppDiscoveryIq::setQueryType(enum QXmppDiscoveryIq::QueryType type)
+{
+ m_queryType = type;
+}
+
+bool QXmppDiscoveryIq::isDiscoveryIq( QDomElement &element )
+{
+ QDomElement queryElement = element.firstChildElement("query");
+ return (queryElement.namespaceURI() == ns_disco_info ||
+ queryElement.namespaceURI() == ns_disco_items);
+}
+
+void QXmppDiscoveryIq::parse( QDomElement &element )
+{
+ setFrom(element.attribute("from"));
+ setTo(element.attribute("to"));
+ setTypeFromStr(element.attribute("type"));
+ QDomElement queryElement = element.firstChildElement("query");
+ if (queryElement.namespaceURI() == ns_disco_items)
+ m_queryType = ItemsQuery;
+ else
+ m_queryType = InfoQuery;
+
+ QDomElement itemElement = queryElement.firstChildElement();
+ while (!itemElement.isNull())
+ {
+ QXmppDiscoveryItem item;
+ item.setType(itemElement.tagName());
+ QDomNamedNodeMap attributes = itemElement.attributes();
+ for (int i = 0; i < attributes.size(); i++)
+ {
+ QDomAttr attr = attributes.item(i).toAttr();
+ item.setAttribute(attr.name(), attr.value());
+ }
+ m_items.append(item);
+ itemElement = itemElement.nextSiblingElement();
+ }
+}
+
+void QXmppDiscoveryIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
+{
+ writer->writeStartElement("query");
+ helperToXmlAddAttribute(writer, "xmlns",
+ m_queryType == InfoQuery ? ns_disco_info : ns_disco_items);
+ foreach (const QXmppDiscoveryItem &item, m_items)
+ {
+ writer->writeStartElement(item.type());
+ foreach (const QString &attr, item.attributes())
+ helperToXmlAddAttribute(writer, attr, item.attribute(attr));
+ writer->writeEndElement();
+ }
+ writer->writeEndElement();
+}
+