aboutsummaryrefslogtreecommitdiff
path: root/src/QXmppServer.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-24 08:25:29 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-24 08:25:29 +0000
commit096ee16c2548cbbfb4c633d02ab7c38831e69a66 (patch)
tree14f60ba6f7a443cb1b24c0b4e3130c8a6aa5aa56 /src/QXmppServer.cpp
parentd442a5e56492ec65b95ed159c429f3facd1ec3dc (diff)
downloadqxmpp-096ee16c2548cbbfb4c633d02ab7c38831e69a66.tar.gz
refactor element handling
Diffstat (limited to 'src/QXmppServer.cpp')
-rw-r--r--src/QXmppServer.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/QXmppServer.cpp b/src/QXmppServer.cpp
index 660ea3b2..a8915d22 100644
--- a/src/QXmppServer.cpp
+++ b/src/QXmppServer.cpp
@@ -39,7 +39,7 @@ public:
QXmppServerPrivate();
QString domain;
- QMap<QString, QSet<QString> > subscribers;
+ QMap<QString, QStringList> subscribers;
QXmppLogger *logger;
QXmppPasswordChecker *passwordChecker;
@@ -278,29 +278,44 @@ QList<QXmppStream*> QXmppServer::getStreams(const QString &to)
void QXmppServer::handleStanza(QXmppStream *stream, const QDomElement &element)
{
const QString to = element.attribute("to");
- if (!to.isEmpty() && to != d->domain)
+
+ // presence handling
+ if (element.tagName() == "presence")
{
- // presence handling
- if (element.tagName() == "presence")
+ if (to.isEmpty() || to == d->domain)
{
+ // presence to the local domain, broadcast it to subscribers
+ if (element.attribute("type").isEmpty() || element.attribute("type") == "unavailable")
+ {
+ const QString from = element.attribute("from");
+ foreach (QString subscriber, subscribers(from))
+ {
+ QDomElement changed(element);
+ changed.setAttribute("to", subscriber);
+ sendElement(changed);
+
+ }
+ }
+ } else {
QXmppPresence presence;
presence.parse(element);
const QString from = presence.from();
- QSet<QString> subscribers = d->subscribers.value(from);
+ QStringList subscribers = d->subscribers.value(from);
if (presence.type() == QXmppPresence::Available)
{
- //qDebug() << to << "is subscribed to" << stream->jid();
- subscribers.insert(to);
+ subscribers.append(to);
d->subscribers[from] = subscribers;
} else if (presence.type() == QXmppPresence::Unavailable) {
- //qDebug() << to << "is unsubscribed from" << stream->jid();
- subscribers.remove(to);
+ subscribers.removeAll(to);
d->subscribers[from] = subscribers;
}
}
+ }
- // route element or reply on behalf of missing peer
+ // route element or reply on behalf of missing peer
+ if (!to.isEmpty() && to != d->domain)
+ {
if (!sendElement(element) && element.tagName() == "iq")
{
QXmppIq request;
@@ -317,6 +332,11 @@ void QXmppServer::handleStanza(QXmppStream *stream, const QDomElement &element)
}
}
+QStringList QXmppServer::subscribers(const QString &jid)
+{
+ return d->subscribers.value(jid);
+}
+
/// Route an XMPP stanza.
///
/// \param element