Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to QXmppServer to route a stanza to a specific resource #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/server/QXmppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class QXmppServerPrivate
public:
QXmppServerPrivate(QXmppServer *qq);
void loadExtensions(QXmppServer *server);
bool routeData(const QString &to, const QByteArray &data);
bool routeData(const QString &to, const QByteArray &data, const QString& resource);
void startExtensions();
void stopExtensions();

Expand Down Expand Up @@ -125,7 +125,7 @@ QXmppServerPrivate::QXmppServerPrivate(QXmppServer *qq)
/// \param data
///

bool QXmppServerPrivate::routeData(const QString &to, const QByteArray &data)
bool QXmppServerPrivate::routeData(const QString &to, const QByteArray &data, const QString& resource)
{
// refuse to route packets to empty destination, own domain or sub-domains
const QString toDomain = QXmppUtils::jidToDomain(to);
Expand All @@ -136,7 +136,17 @@ bool QXmppServerPrivate::routeData(const QString &to, const QByteArray &data)

// look for a client connection
QList<QXmppIncomingClient*> found;
if (QXmppUtils::jidToResource(to).isEmpty()) {
// issue#7: Is a specific destination resource requested?
if (!resource.isEmpty()){
if (QXmppUtils::jidToResource(to).isEmpty()) {
QXmppIncomingClient *conn = incomingClientsByJid.value(to + "/" + resource);
if (conn)
found << conn;
} else {
// refuse to route to a specific resource if stanza is for a full JID already
return false;
}
} else if (QXmppUtils::jidToResource(to).isEmpty()) {
foreach (QXmppIncomingClient *conn, incomingClientsByBareJid.value(to))
found << conn;
} else {
Expand Down Expand Up @@ -635,8 +645,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 +656,23 @@ bool QXmppServer::sendElement(const QDomElement &element)
helperToXmlAddDomElement(&xmlStream, element, omitNamespaces);

// route data
return d->routeData(element.attribute("to"), data);
return d->routeData(element.attribute("to"), data, resource);
}

/// 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);
return d->routeData(packet.to(), data, resource);
}

/// 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