aboutsummaryrefslogtreecommitdiff
path: root/source
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
parentc8ce37573791629d5d475e00d81c371d44d4311d (diff)
downloadqxmpp-e386059f004474d4ffa32a9573a3f36dbec4439b.tar.gz
add support for XEP-0030 : Service Discovery
Diffstat (limited to 'source')
-rw-r--r--source/QXmppConstants.cpp1
-rw-r--r--source/QXmppConstants.h1
-rw-r--r--source/QXmppDiscoveryIq.cpp123
-rw-r--r--source/QXmppDiscoveryIq.h73
-rw-r--r--source/source.pro2
5 files changed, 200 insertions, 0 deletions
diff --git a/source/QXmppConstants.cpp b/source/QXmppConstants.cpp
index 8b29b61e..ffcf0122 100644
--- a/source/QXmppConstants.cpp
+++ b/source/QXmppConstants.cpp
@@ -36,6 +36,7 @@ const char* ns_vcard = "vcard-temp";
const char* ns_auth = "jabber:iq:auth";
const char* ns_authFeature = "http://jabber.org/features/iq-auth";
const char* ns_disco_info = "http://jabber.org/protocol/disco#info";
+const char* ns_disco_items = "http://jabber.org/protocol/disco#items";
const char* ns_ibb = "http://jabber.org/protocol/ibb";
const char* ns_rpc = "jabber:iq:rpc";
const char *ns_ping = "urn:xmpp:ping";
diff --git a/source/QXmppConstants.h b/source/QXmppConstants.h
index 40bcce73..d190858a 100644
--- a/source/QXmppConstants.h
+++ b/source/QXmppConstants.h
@@ -37,6 +37,7 @@ extern const char* ns_vcard;
extern const char* ns_auth;
extern const char* ns_authFeature;
extern const char* ns_disco_info;
+extern const char* ns_disco_items;
extern const char* ns_ibb;
extern const char* ns_rpc;
extern const char* ns_ping;
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();
+}
+
diff --git a/source/QXmppDiscoveryIq.h b/source/QXmppDiscoveryIq.h
new file mode 100644
index 00000000..31c97630
--- /dev/null
+++ b/source/QXmppDiscoveryIq.h
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef QXMPPDISCOVERY_H
+#define QXMPPDISCOVERY_H
+
+#include "QXmppIq.h"
+
+#include <QMap>
+#include <QStringList>
+
+class QDomElement;
+
+class QXmppDiscoveryItem
+{
+public:
+ QStringList attributes() const;
+
+ QString attribute(const QString &name) const;
+ void setAttribute(const QString &name, const QString &value);
+
+ QString type() const;
+ void setType(const QString &type);
+
+private:
+ QMap<QString, QString> m_attributes;
+ QString m_type;
+};
+
+class QXmppDiscoveryIq : public QXmppIq
+{
+public:
+ enum QueryType {
+ InfoQuery,
+ ItemsQuery,
+ };
+
+ void toXmlElementFromChild(QXmlStreamWriter *writer) const;
+ void parse( QDomElement &element );
+ static bool isDiscoveryIq( QDomElement &element );
+
+ QList<QXmppDiscoveryItem> getItems() const;
+ void setItems(const QList<QXmppDiscoveryItem> &items);
+
+ enum QueryType getQueryType() const;
+ void setQueryType(enum QueryType type);
+
+private:
+ QList<QXmppDiscoveryItem> m_items;
+ enum QueryType m_queryType;
+};
+
+#endif
diff --git a/source/source.pro b/source/source.pro
index 0b5b00a8..82f4fd19 100644
--- a/source/source.pro
+++ b/source/source.pro
@@ -20,6 +20,7 @@ HEADERS += QXmppUtils.h \
QXmppClient.h \
QXmppConfiguration.h \
QXmppConstants.h \
+ QXmppDiscoveryIq.h \
QXmppIq.h \
QXmppMessage.h \
QXmppPacket.h \
@@ -53,6 +54,7 @@ SOURCES += QXmppUtils.cpp \
QXmppClient.cpp \
QXmppConfiguration.cpp \
QXmppConstants.cpp \
+ QXmppDiscoveryIq.cpp \
QXmppIq.cpp \
QXmppMessage.cpp \
QXmppPacket.cpp \