diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-02-08 12:51:15 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-02-08 12:51:15 +0000 |
| commit | deb9d6cb53057ca8b90d10d6a3bdc5dcfd1b3ee4 (patch) | |
| tree | d956bad28e28aadc3c83dbf88b3eddb5e1d9a9f4 /src/QXmppPubSubIq.cpp | |
| parent | e8a1ad0cc608f12874ba4bafbd8282fa537ec9fb (diff) | |
| download | qxmpp-deb9d6cb53057ca8b90d10d6a3bdc5dcfd1b3ee4.tar.gz | |
move files common to client/server into "base"
Diffstat (limited to 'src/QXmppPubSubIq.cpp')
| -rw-r--r-- | src/QXmppPubSubIq.cpp | 253 |
1 files changed, 0 insertions, 253 deletions
diff --git a/src/QXmppPubSubIq.cpp b/src/QXmppPubSubIq.cpp deleted file mode 100644 index 1ad1c39d..00000000 --- a/src/QXmppPubSubIq.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (C) 2008-2011 The QXmpp developers - * - * 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 <QDomElement> - -#include "QXmppConstants.h" -#include "QXmppPubSubIq.h" -#include "QXmppUtils.h" - -static const char *ns_pubsub = "http://jabber.org/protocol/pubsub"; - -static const char *pubsub_queries[] = { - "affiliations", - "default", - "items", - "publish", - "retract", - "subscribe", - "subscription", - "subscriptions", - "unsubscribe", -}; - -/// Returns the ID of the PubSub item. -/// - -QString QXmppPubSubItem::id() const -{ - return m_id; -} - -/// Sets the ID of the PubSub item. -/// -/// \param id - -void QXmppPubSubItem::setId(const QString &id) -{ - m_id = id; -} - -/// Returns the contents of the PubSub item. -/// - -QXmppElement QXmppPubSubItem::contents() const -{ - return m_contents; -} - -/// Sets the contents of the PubSub item. -/// -/// \param contents - -void QXmppPubSubItem::setContents(const QXmppElement &contents) -{ - m_contents = contents; -} - -void QXmppPubSubItem::parse(const QDomElement &element) -{ - m_id = element.attribute("id"); - m_contents = QXmppElement(element.firstChildElement()); -} - -void QXmppPubSubItem::toXml(QXmlStreamWriter *writer) const -{ - writer->writeStartElement("item"); - helperToXmlAddAttribute(writer, "id", m_id); - m_contents.toXml(writer); - writer->writeEndElement(); -} - -/// Returns the PubSub queryType for this IQ. -/// - -QXmppPubSubIq::QueryType QXmppPubSubIq::queryType() const -{ - return m_queryType; -} - -/// Sets the PubSub queryType for this IQ. -/// -/// \param queryType - -void QXmppPubSubIq::setQueryType(QXmppPubSubIq::QueryType queryType) -{ - m_queryType = queryType; -} - -/// Returns the JID being queried. -/// - -QString QXmppPubSubIq::queryJid() const -{ - return m_queryJid; -} - -/// Sets the JID being queried. -/// -/// \param queryJid - -void QXmppPubSubIq::setQueryJid(const QString &queryJid) -{ - m_queryJid = queryJid; -} - -/// Returns the node being queried. -/// - -QString QXmppPubSubIq::queryNode() const -{ - return m_queryNode; -} - -/// Sets the node being queried. -/// -/// \param queryNode - -void QXmppPubSubIq::setQueryNode(const QString &queryNode) -{ - m_queryNode = queryNode; -} - -/// Returns the subscription ID. -/// - -QString QXmppPubSubIq::subscriptionId() const -{ - return m_subscriptionId; -} - -/// Sets the subscription ID. -/// -/// \param subscriptionId - -void QXmppPubSubIq::setSubscriptionId(const QString &subscriptionId) -{ - m_subscriptionId = subscriptionId; -} - -/// Returns the IQ's items. -/// - -QList<QXmppPubSubItem> QXmppPubSubIq::items() const -{ - return m_items; -} - -/// Sets the IQ's items. -/// -/// \param items - -void QXmppPubSubIq::setItems(const QList<QXmppPubSubItem> &items) -{ - m_items = items; -} - -bool QXmppPubSubIq::isPubSubIq(const QDomElement &element) -{ - const QDomElement pubSubElement = element.firstChildElement("pubsub"); - return pubSubElement.namespaceURI() == ns_pubsub; -} - -void QXmppPubSubIq::parseElementFromChild(const QDomElement &element) -{ - const QDomElement pubSubElement = element.firstChildElement("pubsub"); - - const QDomElement queryElement = pubSubElement.firstChildElement(); - - // determine query type - const QString tagName = queryElement.tagName(); - for (int i = ItemsQuery; i <= SubscriptionsQuery; i++) - { - if (tagName == pubsub_queries[i]) - { - m_queryType = static_cast<QueryType>(i); - break; - } - } - m_queryJid = queryElement.attribute("jid"); - m_queryNode = queryElement.attribute("node"); - - // parse contents - QDomElement childElement; - switch (m_queryType) - { - case QXmppPubSubIq::ItemsQuery: - case QXmppPubSubIq::PublishQuery: - childElement = queryElement.firstChildElement("item"); - while (!childElement.isNull()) - { - QXmppPubSubItem item; - item.parse(childElement); - m_items << item; - childElement = childElement.nextSiblingElement("item"); - } - break; - case QXmppPubSubIq::SubscriptionQuery: - m_subscriptionId = queryElement.attribute("subid"); - m_subscriptionType = queryElement.attribute("subscription"); - break; - default: - break; - } -} - -void QXmppPubSubIq::toXmlElementFromChild(QXmlStreamWriter *writer) const -{ - writer->writeStartElement("pubsub"); - writer->writeAttribute("xmlns", ns_pubsub); - - // write query type - writer->writeStartElement(pubsub_queries[m_queryType]); - helperToXmlAddAttribute(writer, "jid", m_queryJid); - helperToXmlAddAttribute(writer, "node", m_queryNode); - - // write contents - switch (m_queryType) - { - case QXmppPubSubIq::ItemsQuery: - case QXmppPubSubIq::PublishQuery: - foreach (const QXmppPubSubItem &item, m_items) - item.toXml(writer); - break; - case QXmppPubSubIq::SubscriptionQuery: - helperToXmlAddAttribute(writer, "subid", m_subscriptionId); - helperToXmlAddAttribute(writer, "subscription", m_subscriptionType); - break; - default: - break; - } - writer->writeEndElement(); - writer->writeEndElement(); -} |
