Skip to content

Commit

Permalink
Added possibility to QXmppServer to route a stanza to a specific reso…
Browse files Browse the repository at this point in the history
…urce without the need to add the resource to the stanza's JID. Closes qxmpp-project#7
  • Loading branch information
servonic committed Jan 5, 2016
1 parent 3b444f1 commit 1741dcf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/server/QXmppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,9 @@ bool QXmppServer::listenForServers(const QHostAddress &address, quint16 port)
/// Route an XMPP stanza.
///
/// \param element
/// \param recipient

bool QXmppServer::sendElement(const QDomElement &element)
bool QXmppServer::sendElement(const QDomElement &element, const QString& resource)
{
// serialize data
QByteArray data;
Expand All @@ -645,22 +646,33 @@ bool QXmppServer::sendElement(const QDomElement &element)
helperToXmlAddDomElement(&xmlStream, element, omitNamespaces);

// route data
return d->routeData(element.attribute("to"), data);
if (!resource.isEmpty()) {
// ... to explicitly specified resource. Override original resource from "to" (if any)
return d->routeData(QXmppUtils::jidToBareJid(element.attribute("to")) + "/" + resource, data);
} else {
return d->routeData(element.attribute("to"), data);
}
}

/// Route an XMPP packet.
///
/// \param packet
/// \param recipient

bool QXmppServer::sendPacket(const QXmppStanza &packet)
bool QXmppServer::sendPacket(const QXmppStanza &packet, const QString& resource)
{
// serialize data
QByteArray data;
QXmlStreamWriter xmlStream(&data);
packet.toXml(&xmlStream);

// route data
return d->routeData(packet.to(), data);
if (!resource.isEmpty()) {
// ... to explicitly specified resource. Override original resource from "to" (if any)
return d->routeData(QXmppUtils::jidToBareJid(packet.to()) + "/" + resource, data);
} else {
return d->routeData(packet.to(), data);
}
}

/// Add a new incoming client \a stream.
Expand Down
4 changes: 2 additions & 2 deletions src/server/QXmppServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class QXMPP_EXPORT QXmppServer : public QXmppLoggable
bool listenForClients(const QHostAddress &address = QHostAddress::Any, quint16 port = 5222);
bool listenForServers(const QHostAddress &address = QHostAddress::Any, quint16 port = 5269);

bool sendElement(const QDomElement &element);
bool sendPacket(const QXmppStanza &stanza);
bool sendElement(const QDomElement &element, const QString& resource = QString());
bool sendPacket(const QXmppStanza &stanza, const QString& resource = QString());

void addIncomingClient(QXmppIncomingClient *stream);

Expand Down

0 comments on commit 1741dcf

Please sign in to comment.