diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-08-02 17:14:02 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2012-08-02 17:14:02 +0200 |
| commit | db134ac8c8238f57ba710562e37f6cda99017db0 (patch) | |
| tree | 61765942b7bd7ddafdefea5b4bfcc144ce270994 /src/client/QXmppOutgoingClient.cpp | |
| parent | 850266b13913af89d60e20c1e5ded394fd9df384 (diff) | |
keep track of the host we connect to
Diffstat (limited to 'src/client/QXmppOutgoingClient.cpp')
| -rw-r--r-- | src/client/QXmppOutgoingClient.cpp | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index e86a819e..1d8b4f60 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -57,7 +57,8 @@ class QXmppOutgoingClientPrivate { public: - QXmppOutgoingClientPrivate(); + QXmppOutgoingClientPrivate(QXmppOutgoingClient *q); + void connectToHost(const QString &host, quint16 port); // This object provides the configuration // required for connecting to the XMPP server. @@ -66,6 +67,8 @@ public: // DNS QDnsLookup dns; + QString usedHost; + quint16 usedPort; // Stream QString streamId; @@ -85,12 +88,33 @@ public: // Timers QTimer *pingTimer; QTimer *timeoutTimer; + +private: + QXmppOutgoingClient *q; }; -QXmppOutgoingClientPrivate::QXmppOutgoingClientPrivate() +QXmppOutgoingClientPrivate::QXmppOutgoingClientPrivate(QXmppOutgoingClient *qq) : sessionAvailable(false) , saslClient(0) + , q(qq) +{ +} + +void QXmppOutgoingClientPrivate::connectToHost(const QString &host, quint16 port) { + q->info(QString("Connecting to %1:%2").arg(host, QString::number(port))); + + // override CA certificates if requested + if (!config.caCertificates().isEmpty()) + q->socket()->setCaCertificates(config.caCertificates()); + + // respect proxy + q->socket()->setProxy(config.networkProxy()); + + // connect to host and make a note of used host/port + q->socket()->connectToHost(host, port); + usedHost = host; + usedPort = port; } /// Constructs an outgoing client stream. @@ -99,7 +123,7 @@ QXmppOutgoingClientPrivate::QXmppOutgoingClientPrivate() QXmppOutgoingClient::QXmppOutgoingClient(QObject *parent) : QXmppStream(parent), - d(new QXmppOutgoingClientPrivate) + d(new QXmppOutgoingClientPrivate(this)) { bool check; Q_UNUSED(check); @@ -160,19 +184,9 @@ QXmppConfiguration& QXmppOutgoingClient::configuration() void QXmppOutgoingClient::connectToHost() { - const QString host = configuration().host(); - const quint16 port = configuration().port(); - - // override CA certificates if requested - if (!configuration().caCertificates().isEmpty()) { - socket()->setCaCertificates(configuration().caCertificates()); - } - // if an explicit host was provided, connect to it - if (!host.isEmpty() && port) { - info(QString("Connecting to %1:%2").arg(host, QString::number(port))); - socket()->setProxy(configuration().networkProxy()); - socket()->connectToHost(host, port); + if (!d->config.host().isEmpty() && d->config.port()) { + d->connectToHost(d->config.host(), d->config.port()); return; } @@ -186,26 +200,18 @@ void QXmppOutgoingClient::connectToHost() void QXmppOutgoingClient::_q_dnsLookupFinished() { - QString host; - quint16 port; - if (d->dns.error() == QDnsLookup::NoError && !d->dns.serviceRecords().isEmpty()) { // take the first returned record - host = d->dns.serviceRecords().first().target(); - port = d->dns.serviceRecords().first().port(); + d->connectToHost( + d->dns.serviceRecords().first().target(), + d->dns.serviceRecords().first().port()); } else { // as a fallback, use domain as the host name warning(QString("Lookup for domain %1 failed: %2") .arg(d->dns.name(), d->dns.errorString())); - host = configuration().domain(); - port = configuration().port(); + d->connectToHost(d->config.domain(), d->config.port()); } - - // connect to server - info(QString("Connecting to %1:%2").arg(host, QString::number(port))); - socket()->setProxy(configuration().networkProxy()); - socket()->connectToHost(host, port); } /// Returns true if the socket is connected and a session has been started. @@ -367,7 +373,7 @@ void QXmppOutgoingClient::handleStanza(const QDomElement &nodeRecv) return; } info(QString("SASL mechanism '%1' selected").arg(d->saslClient->mechanism())); - d->saslClient->setHost(configuration().host()); + d->saslClient->setHost(d->usedHost); d->saslClient->setServiceType("xmpp"); if (d->saslClient->mechanism() == "X-FACEBOOK-PLATFORM") { d->saslClient->setUsername(configuration().facebookAppId()); |
