aboutsummaryrefslogtreecommitdiff
path: root/source/QXmppSocks.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-03-05 16:00:32 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-03-05 16:00:32 +0000
commitbe9351b7e17e0f8b19386f74441c127c1b589d29 (patch)
treee41b2fa3e3b8f8872f826710e7f46dce731b64de /source/QXmppSocks.cpp
parent5dd224f861b108fe967f8dfd6b467c3a91bedae0 (diff)
downloadqxmpp-be9351b7e17e0f8b19386f74441c127c1b589d29.tar.gz
make QXmppSocksClient inherit QTcpSocket
Diffstat (limited to 'source/QXmppSocks.cpp')
-rw-r--r--source/QXmppSocks.cpp68
1 files changed, 22 insertions, 46 deletions
diff --git a/source/QXmppSocks.cpp b/source/QXmppSocks.cpp
index 079e2a4b..78d3505f 100644
--- a/source/QXmppSocks.cpp
+++ b/source/QXmppSocks.cpp
@@ -104,48 +104,36 @@ static bool parseHostAndPort(const QByteArray buffer, quint8 &type, QByteArray &
}
QXmppSocksClient::QXmppSocksClient(const QHostAddress &proxyAddress, quint16 proxyPort, QObject *parent)
- : QObject(parent),
+ : QTcpSocket(parent),
m_proxyAddress(proxyAddress),
m_proxyPort(proxyPort),
m_step(ConnectState)
{
- m_socket = new QTcpSocket(this);
- connect(m_socket, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
- connect(m_socket, SIGNAL(connected()), this, SLOT(slotConnected()));
- connect(m_socket, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
-}
-
-void QXmppSocksClient::close()
-{
- m_socket->close();
+ connect(this, SIGNAL(connected()), this, SLOT(slotConnected()));
+ connect(this, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
}
void QXmppSocksClient::connectToHost(const QString &hostName, quint16 hostPort)
{
m_hostName = hostName;
m_hostPort = hostPort;
- m_socket->connectToHost(m_proxyAddress, m_proxyPort);
+ QTcpSocket::connectToHost(m_proxyAddress, m_proxyPort);
}
-QString QXmppSocksClient::errorString() const
+void QXmppSocksClient::slotConnected()
{
- return m_socket->errorString();
-}
+ m_step == ConnectState;
-QByteArray QXmppSocksClient::readAll()
-{
- return m_socket->readAll();
-}
+ // disconnect from signal
+ disconnect(this, SIGNAL(connected()), this, SLOT(slotConnected()));
-void QXmppSocksClient::slotConnected()
-{
// send connect to server
QByteArray buffer;
buffer.resize(3);
buffer[0] = SocksVersion;
buffer[1] = 0x01; // number of methods
buffer[2] = NoAuthentication;
- m_socket->write(buffer);
+ write(buffer);
}
void QXmppSocksClient::slotReadyRead()
@@ -155,11 +143,11 @@ void QXmppSocksClient::slotReadyRead()
m_step++;
// receive connect to server response
- QByteArray buffer = m_socket->readAll();
+ QByteArray buffer = readAll();
if (buffer.size() != 2 || buffer.at(0) != SocksVersion || buffer.at(1) != NoAuthentication)
{
qWarning("QXmppSocksClient received an invalid response during handshake");
- m_socket->close();
+ close();
return;
}
@@ -172,20 +160,23 @@ void QXmppSocksClient::slotReadyRead()
DomainName,
m_hostName.toAscii(),
m_hostPort));
- m_socket->write(buffer);
+ write(buffer);
} else if (m_step == CommandState) {
m_step++;
+ // disconnect from signal
+ disconnect(this, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
+
// receive CONNECT response
- QByteArray buffer = m_socket->readAll();
+ QByteArray buffer = readAll();
if (buffer.size() < 6 ||
buffer.at(0) != SocksVersion ||
buffer.at(1) != Succeeded ||
buffer.at(2) != 0)
{
qWarning("QXmppSocksClient received an invalid response to CONNECT command");
- m_socket->close();
+ close();
return;
}
@@ -196,45 +187,30 @@ void QXmppSocksClient::slotReadyRead()
if (!parseHostAndPort(buffer.mid(3), hostType, hostName, hostPort))
{
qWarning("QXmppSocksClient could not parse type/host/port");
- m_socket->close();
+ close();
return;
}
// FIXME : what do we do with the resulting name / port?
- // from now on, forward signals
- disconnect(m_socket, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
- connect(m_socket, SIGNAL(readyRead()), this, SIGNAL(readyRead()));
-
// notify of connection
- emit connected();
-
+ emit ready();
}
}
-bool QXmppSocksClient::waitForConnected(int msecs)
+bool QXmppSocksClient::waitForReady(int msecs)
{
QEventLoop loop;
- connect(this, SIGNAL(connected()), &loop, SLOT(quit()));
connect(this, SIGNAL(disconnected()), &loop, SLOT(quit()));
+ connect(this, SIGNAL(ready()), &loop, SLOT(quit()));
QTimer::singleShot(msecs, &loop, SLOT(quit()));
loop.exec();
- if (m_step == ReadyState && m_socket->isValid())
+ if (m_step == ReadyState && isValid())
return true;
else
return false;
}
-qint64 QXmppSocksClient::write(const QByteArray &data)
-{
- return m_socket->write(data);
-}
-
-QTcpSocket *QXmppSocksClient::socket()
-{
- return m_socket;
-}
-
QXmppSocksServer::QXmppSocksServer(QObject *parent)
: QObject(parent)
{