aboutsummaryrefslogtreecommitdiff
path: root/src/QXmppOutgoingServer.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2011-01-19 09:41:13 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2011-01-19 09:41:13 +0000
commit4ab4c9ec4152106dbd02c1b9e7899da9254f5569 (patch)
tree3db4898eea35e6d5ab5ca2e9fb494c39c1c3b6b1 /src/QXmppOutgoingServer.cpp
parent0b72b324a061e351e1c42b90db65af02a44a1da1 (diff)
downloadqxmpp-4ab4c9ec4152106dbd02c1b9e7899da9254f5569.tar.gz
cope with broken gmail.com servers which never send <stream:features>
Diffstat (limited to 'src/QXmppOutgoingServer.cpp')
-rw-r--r--src/QXmppOutgoingServer.cpp73
1 files changed, 47 insertions, 26 deletions
diff --git a/src/QXmppOutgoingServer.cpp b/src/QXmppOutgoingServer.cpp
index 3e66f5b9..035c338e 100644
--- a/src/QXmppOutgoingServer.cpp
+++ b/src/QXmppOutgoingServer.cpp
@@ -24,6 +24,7 @@
#include <QDomElement>
#include <QSslKey>
#include <QSslSocket>
+#include <QTimer>
#include "QXmppConstants.h"
#include "QXmppDialback.h"
@@ -40,6 +41,7 @@ public:
QString remoteDomain;
QString verifyId;
QString verifyKey;
+ QTimer *dialbackTimer;
bool ready;
};
@@ -53,16 +55,24 @@ QXmppOutgoingServer::QXmppOutgoingServer(const QString &domain, QObject *parent)
: QXmppStream(parent),
d(new QXmppOutgoingServerPrivate)
{
+ bool check;
+
QSslSocket *socket = new QSslSocket(this);
setSocket(socket);
+ d->dialbackTimer = new QTimer(this);
+ d->dialbackTimer->setInterval(5000);
+ d->dialbackTimer->setSingleShot(true);
+ check = connect(d->dialbackTimer, SIGNAL(timeout()),
+ this, SLOT(sendDialback()));
+ Q_ASSERT(check);
+
d->localDomain = domain;
d->ready = false;
- bool check = connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
- this, SLOT(slotSslErrors(QList<QSslError>)));
+ check = connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
+ this, SLOT(slotSslErrors(QList<QSslError>)));
Q_ASSERT(check);
- Q_UNUSED(check);
}
/// Destroys the stream.
@@ -121,7 +131,9 @@ void QXmppOutgoingServer::handleStart()
void QXmppOutgoingServer::handleStream(const QDomElement &streamElement)
{
- Q_UNUSED(streamElement);
+ // gmail.com servers are broken: they never send <stream:features>,
+ // so we schedule sending the dialback in a couple of seconds
+ d->dialbackTimer->start();
}
void QXmppOutgoingServer::handleStanza(const QDomElement &stanza)
@@ -153,27 +165,9 @@ void QXmppOutgoingServer::handleStanza(const QDomElement &stanza)
}
}
- if (!d->localStreamKey.isEmpty())
- {
- // send dialback key
- QXmppDialback dialback;
- dialback.setCommand(QXmppDialback::Result);
- dialback.setFrom(d->localDomain);
- dialback.setTo(d->remoteDomain);
- dialback.setKey(d->localStreamKey);
- sendPacket(dialback);
- }
- else if (!d->verifyId.isEmpty() && !d->verifyKey.isEmpty())
- {
- // send dialback verify
- QXmppDialback verify;
- verify.setCommand(QXmppDialback::Verify);
- verify.setId(d->verifyId);
- verify.setFrom(d->localDomain);
- verify.setTo(d->remoteDomain);
- verify.setKey(d->verifyKey);
- sendPacket(verify);
- }
+ // send dialback if needed
+ d->dialbackTimer->stop();
+ sendDialback();
}
else if (ns == ns_tls)
{
@@ -201,7 +195,7 @@ void QXmppOutgoingServer::handleStanza(const QDomElement &stanza)
{
if (response.type() == "valid")
{
- info("Outgoing stream is ready");
+ info(QString("Outgoing server stream to %1 is ready").arg(response.from()));
d->ready = true;
emit connected();
}
@@ -256,6 +250,33 @@ QString QXmppOutgoingServer::remoteDomain() const
return d->remoteDomain;
}
+void QXmppOutgoingServer::sendDialback()
+{
+ if (!d->localStreamKey.isEmpty())
+ {
+ // send dialback key
+ debug(QString("Sending dialback result to %1").arg(d->remoteDomain));
+ QXmppDialback dialback;
+ dialback.setCommand(QXmppDialback::Result);
+ dialback.setFrom(d->localDomain);
+ dialback.setTo(d->remoteDomain);
+ dialback.setKey(d->localStreamKey);
+ sendPacket(dialback);
+ }
+ else if (!d->verifyId.isEmpty() && !d->verifyKey.isEmpty())
+ {
+ // send dialback verify
+ debug(QString("Sending dialback verify to %1").arg(d->remoteDomain));
+ QXmppDialback verify;
+ verify.setCommand(QXmppDialback::Verify);
+ verify.setId(d->verifyId);
+ verify.setFrom(d->localDomain);
+ verify.setTo(d->remoteDomain);
+ verify.setKey(d->verifyKey);
+ sendPacket(verify);
+ }
+}
+
void QXmppOutgoingServer::slotSslErrors(const QList<QSslError> &errors)
{
warning("SSL errors");