aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-12-06 09:22:06 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-12-06 09:22:06 +0000
commitfab2e18c6451705be9fb784a248260d304f621c7 (patch)
treeecbcdcb6821e0001f9003ab07a6b80907fcdd7e1 /src
parente207ab2c6fbdf046129978d812936af9d34c302f (diff)
downloadqxmpp-fab2e18c6451705be9fb784a248260d304f621c7.tar.gz
rework QXmppStunMessage::peekType to return magic cookie
Diffstat (limited to 'src')
-rw-r--r--src/QXmppStun.cpp8
-rw-r--r--src/QXmppStun.h2
2 files changed, 5 insertions, 5 deletions
diff --git a/src/QXmppStun.cpp b/src/QXmppStun.cpp
index 0c2443db..5bebb379 100644
--- a/src/QXmppStun.cpp
+++ b/src/QXmppStun.cpp
@@ -661,7 +661,7 @@ QByteArray QXmppStunMessage::encode(const QString &password, bool addFingerprint
///
/// \param buffer
-quint16 QXmppStunMessage::peekType(const QByteArray &buffer, QByteArray &id)
+quint16 QXmppStunMessage::peekType(const QByteArray &buffer, quint32 &cookie, QByteArray &id)
{
if (buffer.size() < STUN_HEADER)
return 0;
@@ -670,7 +670,6 @@ quint16 QXmppStunMessage::peekType(const QByteArray &buffer, QByteArray &id)
QDataStream stream(buffer);
quint16 type;
quint16 length;
- quint32 cookie;
stream >> type;
stream >> length;
stream >> cookie;
@@ -1033,9 +1032,10 @@ void QXmppIceComponent::readyRead()
socket->readDatagram(buffer.data(), buffer.size(), &remoteHost, &remotePort);
// if this is not a STUN message, emit it
+ quint32 messageCookie;
QByteArray messageId;
- quint16 messageType = QXmppStunMessage::peekType(buffer, messageId);
- if (!messageType)
+ quint16 messageType = QXmppStunMessage::peekType(buffer, messageCookie, messageId);
+ if (!messageType || messageCookie != STUN_MAGIC)
{
// use this as an opportunity to flag a potential pair
if (!m_fallbackPair) {
diff --git a/src/QXmppStun.h b/src/QXmppStun.h
index 8e70cf9a..71081b26 100644
--- a/src/QXmppStun.h
+++ b/src/QXmppStun.h
@@ -77,7 +77,7 @@ public:
QByteArray encode(const QString &password = QString(), bool addFingerprint = true) const;
bool decode(const QByteArray &buffer, const QString &password = QString(), QStringList *errors = 0);
QString toString() const;
- static quint16 peekType(const QByteArray &buffer, QByteArray &id);
+ static quint16 peekType(const QByteArray &buffer, quint32 &cookie, QByteArray &id);
// attributes
int errorCode;