diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-29 15:47:37 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-08-29 15:47:37 +0000 |
| commit | 317ab669fae2801c2ff8cb771690c408ab6112af (patch) | |
| tree | 4c075a637a2e60067ad8355fa42b13627bedfab2 /src | |
| parent | c4ccfbf5795d7cdc37fb32ebdd145ae0e68b5b77 (diff) | |
| download | qxmpp-317ab669fae2801c2ff8cb771690c408ab6112af.tar.gz | |
if no explicit host/port are given, use DNS SRV lookup
Diffstat (limited to 'src')
| -rw-r--r-- | src/QXmppIncomingServer.cpp | 2 | ||||
| -rw-r--r-- | src/QXmppOutgoingClient.cpp | 28 | ||||
| -rw-r--r-- | src/QXmppOutgoingServer.cpp | 27 | ||||
| -rw-r--r-- | src/QXmppOutgoingServer.h | 1 | ||||
| -rw-r--r-- | src/QXmppServer.cpp | 2 |
5 files changed, 52 insertions, 8 deletions
diff --git a/src/QXmppIncomingServer.cpp b/src/QXmppIncomingServer.cpp index c7f2fca8..14a92e17 100644 --- a/src/QXmppIncomingServer.cpp +++ b/src/QXmppIncomingServer.cpp @@ -129,8 +129,6 @@ void QXmppIncomingServer::handleStanza(const QDomElement &stanza) stream->setLogger(logger()); stream->setObjectName("S2S-dialback-" + domain); stream->configuration().setDomain(domain); - stream->configuration().setHost(domain); - stream->configuration().setPort(5269); bool check = connect(stream, SIGNAL(dialbackResponseReceived(QXmppDialback)), this, SLOT(slotDialbackResponseReceived(QXmppDialback))); Q_ASSERT(check); diff --git a/src/QXmppOutgoingClient.cpp b/src/QXmppOutgoingClient.cpp index f7fc8bc3..3f9bedde 100644 --- a/src/QXmppOutgoingClient.cpp +++ b/src/QXmppOutgoingClient.cpp @@ -32,6 +32,7 @@ #include "QXmppPacket.h" #include "QXmppPresence.h" #include "QXmppOutgoingClient.h" +#include "QXmppServiceInfo.h" #include "QXmppStreamFeatures.h" #include "QXmppNonSASLAuth.h" #include "QXmppSaslAuth.h" @@ -152,12 +153,31 @@ QXmppConfiguration& QXmppOutgoingClient::configuration() void QXmppOutgoingClient::connectToHost() { - info(QString("Connecting to: %1:%2").arg(configuration(). - host()).arg(configuration().port())); + const QString domain = configuration().domain(); + QString host = configuration().host(); + quint16 port = configuration().port(); + // if we do not have no explicit host was provided, look it up + if (host.isEmpty() || !port) + { + debug(QString("Looking up server for domain %1").arg(domain)); + QXmppServiceInfo serviceInfo = QXmppServiceInfo::fromName("_xmpp-client._tcp." + domain); + if (!serviceInfo.records().isEmpty()) + { + // take the first returned record + host = serviceInfo.records().first().hostName(); + port = serviceInfo.records().first().port(); + } else { + // as a fallback, use domain as the host name + warning(QString("Lookup for domain %1 failed: %2").arg(domain, serviceInfo.errorString())); + host = domain; + } + } + + // connect to server + info(QString("Connecting to %1:%2").arg(host, QString::number(port))); socket()->setProxy(configuration().networkProxy()); - socket()->connectToHost(configuration().host(), - configuration().port()); + socket()->connectToHost(host, port); } /// Returns true if the socket is connected and a session has been started. diff --git a/src/QXmppOutgoingServer.cpp b/src/QXmppOutgoingServer.cpp index c3790cd0..d88299d2 100644 --- a/src/QXmppOutgoingServer.cpp +++ b/src/QXmppOutgoingServer.cpp @@ -28,6 +28,7 @@ #include "QXmppConstants.h" #include "QXmppDialback.h" #include "QXmppOutgoingServer.h" +#include "QXmppServiceInfo.h" #include "QXmppStreamFeatures.h" #include "QXmppUtils.h" @@ -65,6 +66,32 @@ QXmppOutgoingServer::~QXmppOutgoingServer() delete d; } +void QXmppOutgoingServer::connectToHost() +{ + const QString domain = configuration().domain(); + QString host; + quint16 port; + + // lookup server for domain + debug(QString("Looking up server for domain %1").arg(domain)); + QXmppServiceInfo serviceInfo = QXmppServiceInfo::fromName("_xmpp-server._tcp." + domain); + if (!serviceInfo.records().isEmpty()) + { + // take the first returned record + host = serviceInfo.records().first().hostName(); + port = serviceInfo.records().first().port(); + } else { + // as a fallback, use domain as the host name + warning(QString("Lookup for domain %1 failed: %2").arg(domain, serviceInfo.errorString())); + host = domain; + port = 5269; + } + + // connect to server + info(QString("Connecting to %1:%2").arg(host, QString::number(port))); + socket()->connectToHost(host, port); +} + void QXmppOutgoingServer::handleStart() { QString data = QString("<?xml version='1.0'?><stream:stream" diff --git a/src/QXmppOutgoingServer.h b/src/QXmppOutgoingServer.h index 2a2e2b8b..9e56c6b9 100644 --- a/src/QXmppOutgoingServer.h +++ b/src/QXmppOutgoingServer.h @@ -42,6 +42,7 @@ public: QXmppOutgoingServer(const QString &domain, QObject *parent); ~QXmppOutgoingServer(); + void connectToHost(); bool isConnected() const; QString localStreamKey() const; diff --git a/src/QXmppServer.cpp b/src/QXmppServer.cpp index 40ebe57f..db91118a 100644 --- a/src/QXmppServer.cpp +++ b/src/QXmppServer.cpp @@ -362,8 +362,6 @@ QXmppOutgoingServer* QXmppServer::connectToDomain(const QString &domain) stream->setLocalStreamKey(generateStanzaHash().toAscii()); stream->setLogger(d->logger); stream->configuration().setDomain(domain); - stream->configuration().setHost(domain); - stream->configuration().setPort(5269); bool check = connect(stream, SIGNAL(connected()), this, SLOT(slotStreamConnected())); |
