diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-07-31 19:48:06 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-07-31 19:48:06 +0000 |
commit | 47c8a359c5276062c4bc17f0e82410f29081b502 (patch) | |
tree | 2d54a5f60a5b74067632f9ef6df58c2bc38155e6 /kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp | |
parent | 6f82532777a35e0e60bbd2b290b2e93e646f349b (diff) | |
download | tdenetwork-47c8a359c5276062c4bc17f0e82410f29081b502.tar.gz tdenetwork-47c8a359c5276062c4bc17f0e82410f29081b502.zip |
Trinity Qt initial conversion
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1157648 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp')
-rw-r--r-- | kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp | 234 |
1 files changed, 117 insertions, 117 deletions
diff --git a/kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp b/kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp index 2f3ca5a8..59504170 100644 --- a/kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp +++ b/kopete/protocols/jabber/libiris/cutestuff/network/socks.cpp @@ -20,13 +20,13 @@ #include"socks.h" -#include<qhostaddress.h> -#include<qstringlist.h> -#include<qptrlist.h> -#include<qtimer.h> -#include<qguardedptr.h> -#include<qsocketdevice.h> -#include<qsocketnotifier.h> +#include<tqhostaddress.h> +#include<tqstringlist.h> +#include<tqptrlist.h> +#include<tqtimer.h> +#include<tqguardedptr.h> +#include<tqsocketdevice.h> +#include<tqsocketnotifier.h> #ifdef Q_OS_UNIX #include<sys/types.h> @@ -49,20 +49,20 @@ //---------------------------------------------------------------------------- // SocksUDP //---------------------------------------------------------------------------- -static QByteArray sp_create_udp(const QString &host, Q_UINT16 port, const QByteArray &buf) +static TQByteArray sp_create_udp(const TQString &host, Q_UINT16 port, const TQByteArray &buf) { // detect for IP addresses - //QHostAddress addr; + //TQHostAddress addr; //if(addr.setAddress(host)) // return sp_set_request(addr, port, cmd1); - QCString h = host.utf8(); + TQCString h = host.utf8(); h.truncate(255); - h = QString::fromUtf8(h).utf8(); // delete any partial characters? + h = TQString::fromUtf8(h).utf8(); // delete any partial characters? int hlen = h.length(); int at = 0; - QByteArray a(4); + TQByteArray a(4); a[at++] = 0x00; // reserved a[at++] = 0x00; // reserved a[at++] = 0x00; // frag @@ -88,19 +88,19 @@ static QByteArray sp_create_udp(const QString &host, Q_UINT16 port, const QByteA struct SPS_UDP { - QString host; + TQString host; Q_UINT16 port; - QByteArray data; + TQByteArray data; }; -static int sp_read_udp(QByteArray *from, SPS_UDP *s) +static int sp_read_udp(TQByteArray *from, SPS_UDP *s) { int full_len = 4; if((int)from->size() < full_len) return 0; - QString host; - QHostAddress addr; + TQString host; + TQHostAddress addr; unsigned char atype = from->at(3); if(atype == 0x01) { @@ -120,9 +120,9 @@ static int sp_read_udp(QByteArray *from, SPS_UDP *s) full_len += host_len; if((int)from->size() < full_len) return 0; - QCString cs(host_len+1); + TQCString cs(host_len+1); memcpy(cs.data(), from->data() + 5, host_len); - host = QString::fromLatin1(cs); + host = TQString::fromLatin1(cs); } else if(atype == 0x04) { full_len += 16; @@ -152,24 +152,24 @@ static int sp_read_udp(QByteArray *from, SPS_UDP *s) class SocksUDP::Private { public: - QSocketDevice *sd; - QSocketNotifier *sn; + TQSocketDevice *sd; + TQSocketNotifier *sn; SocksClient *sc; - QHostAddress routeAddr; + TQHostAddress routeAddr; int routePort; - QString host; + TQString host; int port; }; -SocksUDP::SocksUDP(SocksClient *sc, const QString &host, int port, const QHostAddress &routeAddr, int routePort) -:QObject(sc) +SocksUDP::SocksUDP(SocksClient *sc, const TQString &host, int port, const TQHostAddress &routeAddr, int routePort) +:TQObject(sc) { d = new Private; d->sc = sc; - d->sd = new QSocketDevice(QSocketDevice::Datagram); + d->sd = new TQSocketDevice(TQSocketDevice::Datagram); d->sd->setBlocking(false); - d->sn = new QSocketNotifier(d->sd->socket(), QSocketNotifier::Read); - connect(d->sn, SIGNAL(activated(int)), SLOT(sn_activated(int))); + d->sn = new TQSocketNotifier(d->sd->socket(), TQSocketNotifier::Read); + connect(d->sn, TQT_SIGNAL(activated(int)), TQT_SLOT(sn_activated(int))); d->host = host; d->port = port; d->routeAddr = routeAddr; @@ -183,15 +183,15 @@ SocksUDP::~SocksUDP() delete d; } -void SocksUDP::change(const QString &host, int port) +void SocksUDP::change(const TQString &host, int port) { d->host = host; d->port = port; } -void SocksUDP::write(const QByteArray &data) +void SocksUDP::write(const TQByteArray &data) { - QByteArray buf = sp_create_udp(d->host, d->port, data); + TQByteArray buf = sp_create_udp(d->host, d->port, data); d->sd->setBlocking(true); d->sd->writeBlock(buf.data(), buf.size(), d->routeAddr, d->routePort); d->sd->setBlocking(false); @@ -199,7 +199,7 @@ void SocksUDP::write(const QByteArray &data) void SocksUDP::sn_activated(int) { - QByteArray buf(8192); + TQByteArray buf(8192); int actual = d->sd->readBlock(buf.data(), buf.size()); buf.resize(actual); packetReady(buf); @@ -222,9 +222,9 @@ void SocksUDP::sn_activated(int) // SPSS = socks packet server struct // Version -static QByteArray spc_set_version() +static TQByteArray spc_set_version() { - QByteArray ver(4); + TQByteArray ver(4); ver[0] = 0x05; // socks version 5 ver[1] = 0x02; // number of methods ver[2] = 0x00; // no-auth @@ -232,9 +232,9 @@ static QByteArray spc_set_version() return ver; } -static QByteArray sps_set_version(int method) +static TQByteArray sps_set_version(int method) { - QByteArray ver(2); + TQByteArray ver(2); ver[0] = 0x05; ver[1] = method; return ver; @@ -243,10 +243,10 @@ static QByteArray sps_set_version(int method) struct SPCS_VERSION { unsigned char version; - QByteArray methodList; + TQByteArray methodList; }; -static int spc_get_version(QByteArray *from, SPCS_VERSION *s) +static int spc_get_version(TQByteArray *from, SPCS_VERSION *s) { if(from->size() < 1) return 0; @@ -259,7 +259,7 @@ static int spc_get_version(QByteArray *from, SPCS_VERSION *s) return -1; if(from->size() < 2 + num) return 0; - QByteArray a = ByteStream::takeArray(from, 2+num); + TQByteArray a = ByteStream::takeArray(from, 2+num); s->version = a[0]; s->methodList.resize(num); memcpy(s->methodList.data(), a.data() + 2, num); @@ -272,18 +272,18 @@ struct SPSS_VERSION unsigned char method; }; -static int sps_get_version(QByteArray *from, SPSS_VERSION *s) +static int sps_get_version(TQByteArray *from, SPSS_VERSION *s) { if(from->size() < 2) return 0; - QByteArray a = ByteStream::takeArray(from, 2); + TQByteArray a = ByteStream::takeArray(from, 2); s->version = a[0]; s->method = a[1]; return 1; } // authUsername -static QByteArray spc_set_authUsername(const QCString &user, const QCString &pass) +static TQByteArray spc_set_authUsername(const TQCString &user, const TQCString &pass) { int len1 = user.length(); int len2 = pass.length(); @@ -291,7 +291,7 @@ static QByteArray spc_set_authUsername(const QCString &user, const QCString &pas len1 = 255; if(len2 > 255) len2 = 255; - QByteArray a(1+1+len1+1+len2); + TQByteArray a(1+1+len1+1+len2); a[0] = 0x01; // username auth version 1 a[1] = len1; memcpy(a.data() + 2, user.data(), len1); @@ -300,9 +300,9 @@ static QByteArray spc_set_authUsername(const QCString &user, const QCString &pas return a; } -static QByteArray sps_set_authUsername(bool success) +static TQByteArray sps_set_authUsername(bool success) { - QByteArray a(2); + TQByteArray a(2); a[0] = 0x01; a[1] = success ? 0x00 : 0xff; return a; @@ -310,10 +310,10 @@ static QByteArray sps_set_authUsername(bool success) struct SPCS_AUTHUSERNAME { - QString user, pass; + TQString user, pass; }; -static int spc_get_authUsername(QByteArray *from, SPCS_AUTHUSERNAME *s) +static int spc_get_authUsername(TQByteArray *from, SPCS_AUTHUSERNAME *s) { if(from->size() < 1) return 0; @@ -328,15 +328,15 @@ static int spc_get_authUsername(QByteArray *from, SPCS_AUTHUSERNAME *s) unsigned char plen = from->at(ulen+2); if((int)from->size() < ulen + plen + 3) return 0; - QByteArray a = ByteStream::takeArray(from, ulen + plen + 3); + TQByteArray a = ByteStream::takeArray(from, ulen + plen + 3); - QCString user, pass; + TQCString user, pass; user.resize(ulen+1); pass.resize(plen+1); memcpy(user.data(), a.data()+2, ulen); memcpy(pass.data(), a.data()+ulen+3, plen); - s->user = QString::fromUtf8(user); - s->pass = QString::fromUtf8(pass); + s->user = TQString::fromUtf8(user); + s->pass = TQString::fromUtf8(pass); return 1; } @@ -346,21 +346,21 @@ struct SPSS_AUTHUSERNAME bool success; }; -static int sps_get_authUsername(QByteArray *from, SPSS_AUTHUSERNAME *s) +static int sps_get_authUsername(TQByteArray *from, SPSS_AUTHUSERNAME *s) { if(from->size() < 2) return 0; - QByteArray a = ByteStream::takeArray(from, 2); + TQByteArray a = ByteStream::takeArray(from, 2); s->version = a[0]; s->success = a[1] == 0 ? true: false; return 1; } // connectRequest -static QByteArray sp_set_request(const QHostAddress &addr, unsigned short port, unsigned char cmd1) +static TQByteArray sp_set_request(const TQHostAddress &addr, unsigned short port, unsigned char cmd1) { int at = 0; - QByteArray a(4); + TQByteArray a(4); a[at++] = 0x05; // socks version 5 a[at++] = cmd1; a[at++] = 0x00; // reserved @@ -374,11 +374,11 @@ static QByteArray sp_set_request(const QHostAddress &addr, unsigned short port, else { a[at++] = 0x04; Q_UINT8 a6[16]; - QStringList s6 = QStringList::split(':', addr.toString(), true); + TQStringList s6 = TQStringList::split(':', addr.toString(), true); int at = 0; Q_UINT16 c; bool ok; - for(QStringList::ConstIterator it = s6.begin(); it != s6.end(); ++it) { + for(TQStringList::ConstIterator it = s6.begin(); it != s6.end(); ++it) { c = (*it).toInt(&ok, 16); a6[at++] = (c >> 8); a6[at++] = c & 0xff; @@ -396,20 +396,20 @@ static QByteArray sp_set_request(const QHostAddress &addr, unsigned short port, return a; } -static QByteArray sp_set_request(const QString &host, Q_UINT16 port, unsigned char cmd1) +static TQByteArray sp_set_request(const TQString &host, Q_UINT16 port, unsigned char cmd1) { // detect for IP addresses - QHostAddress addr; + TQHostAddress addr; if(addr.setAddress(host)) return sp_set_request(addr, port, cmd1); - QCString h = host.utf8(); + TQCString h = host.utf8(); h.truncate(255); - h = QString::fromUtf8(h).utf8(); // delete any partial characters? + h = TQString::fromUtf8(h).utf8(); // delete any partial characters? int hlen = h.length(); int at = 0; - QByteArray a(4); + TQByteArray a(4); a[at++] = 0x05; // socks version 5 a[at++] = cmd1; a[at++] = 0x00; // reserved @@ -434,19 +434,19 @@ struct SPS_CONNREQ unsigned char version; unsigned char cmd; int address_type; - QString host; - QHostAddress addr; + TQString host; + TQHostAddress addr; Q_UINT16 port; }; -static int sp_get_request(QByteArray *from, SPS_CONNREQ *s) +static int sp_get_request(TQByteArray *from, SPS_CONNREQ *s) { int full_len = 4; if((int)from->size() < full_len) return 0; - QString host; - QHostAddress addr; + TQString host; + TQHostAddress addr; unsigned char atype = from->at(3); if(atype == 0x01) { @@ -465,9 +465,9 @@ static int sp_get_request(QByteArray *from, SPS_CONNREQ *s) full_len += host_len; if((int)from->size() < full_len) return 0; - QCString cs(host_len+1); + TQCString cs(host_len+1); memcpy(cs.data(), from->data() + 5, host_len); - host = QString::fromLatin1(cs); + host = TQString::fromLatin1(cs); } else if(atype == 0x04) { full_len += 16; @@ -482,7 +482,7 @@ static int sp_get_request(QByteArray *from, SPS_CONNREQ *s) if((int)from->size() < full_len) return 0; - QByteArray a = ByteStream::takeArray(from, full_len); + TQByteArray a = ByteStream::takeArray(from, full_len); Q_UINT16 p; memcpy(&p, a.data() + full_len - 2, 2); @@ -505,29 +505,29 @@ public: Private() {} BSocket sock; - QString host; + TQString host; int port; - QString user, pass; - QString real_host; + TQString user, pass; + TQString real_host; int real_port; - QByteArray recvBuf; + TQByteArray recvBuf; bool active; int step; int authMethod; bool incoming, waiting; - QString rhost; + TQString rhost; int rport; int pending; bool udp; - QString udpAddr; + TQString udpAddr; int udpPort; }; -SocksClient::SocksClient(QObject *parent) +SocksClient::SocksClient(TQObject *parent) :ByteStream(parent) { init(); @@ -535,7 +535,7 @@ SocksClient::SocksClient(QObject *parent) d->incoming = false; } -SocksClient::SocksClient(int s, QObject *parent) +SocksClient::SocksClient(int s, TQObject *parent) :ByteStream(parent) { init(); @@ -548,12 +548,12 @@ SocksClient::SocksClient(int s, QObject *parent) void SocksClient::init() { d = new Private; - connect(&d->sock, SIGNAL(connected()), SLOT(sock_connected())); - connect(&d->sock, SIGNAL(connectionClosed()), SLOT(sock_connectionClosed())); - connect(&d->sock, SIGNAL(delayedCloseFinished()), SLOT(sock_delayedCloseFinished())); - connect(&d->sock, SIGNAL(readyRead()), SLOT(sock_readyRead())); - connect(&d->sock, SIGNAL(bytesWritten(int)), SLOT(sock_bytesWritten(int))); - connect(&d->sock, SIGNAL(error(int)), SLOT(sock_error(int))); + connect(&d->sock, TQT_SIGNAL(connected()), TQT_SLOT(sock_connected())); + connect(&d->sock, TQT_SIGNAL(connectionClosed()), TQT_SLOT(sock_connectionClosed())); + connect(&d->sock, TQT_SIGNAL(delayedCloseFinished()), TQT_SLOT(sock_delayedCloseFinished())); + connect(&d->sock, TQT_SIGNAL(readyRead()), TQT_SLOT(sock_readyRead())); + connect(&d->sock, TQT_SIGNAL(bytesWritten(int)), TQT_SLOT(sock_bytesWritten(int))); + connect(&d->sock, TQT_SIGNAL(error(int)), TQT_SLOT(sock_error(int))); reset(true); } @@ -582,13 +582,13 @@ bool SocksClient::isIncoming() const return d->incoming; } -void SocksClient::setAuth(const QString &user, const QString &pass) +void SocksClient::setAuth(const TQString &user, const TQString &pass) { d->user = user; d->pass = pass; } -void SocksClient::connectToHost(const QString &proxyHost, int proxyPort, const QString &host, int port, bool udpMode) +void SocksClient::connectToHost(const TQString &proxyHost, int proxyPort, const TQString &host, int port, bool udpMode) { reset(true); @@ -620,19 +620,19 @@ void SocksClient::close() reset(); } -void SocksClient::writeData(const QByteArray &buf) +void SocksClient::writeData(const TQByteArray &buf) { d->pending += buf.size(); d->sock.write(buf); } -void SocksClient::write(const QByteArray &buf) +void SocksClient::write(const TQByteArray &buf) { if(d->active && !d->udp) d->sock.write(buf); } -QByteArray SocksClient::read(int bytes) +TQByteArray SocksClient::read(int bytes) { return ByteStream::read(bytes); } @@ -681,7 +681,7 @@ void SocksClient::sock_delayedCloseFinished() void SocksClient::sock_readyRead() { - QByteArray block = d->sock.read(); + TQByteArray block = d->sock.read(); if(!d->active) { if(d->incoming) @@ -697,7 +697,7 @@ void SocksClient::sock_readyRead() } } -void SocksClient::processOutgoing(const QByteArray &block) +void SocksClient::processOutgoing(const TQByteArray &block) { #ifdef PROX_DEBUG // show hex @@ -726,7 +726,7 @@ void SocksClient::processOutgoing(const QByteArray &block) return; } - QString str; + TQString str; if(s.method == 0x00) { str = "None"; d->authMethod = AuthNone; @@ -818,7 +818,7 @@ void SocksClient::processOutgoing(const QByteArray &block) d->active = true; - QGuardedPtr<QObject> self = this; + TQGuardedPtr<TQObject> self = this; connected(); if(!self) return; @@ -839,11 +839,11 @@ void SocksClient::do_request() #endif d->step = StepRequest; int cmd = d->udp ? REQ_UDPASSOCIATE : REQ_CONNECT; - QByteArray buf; + TQByteArray buf; if(!d->real_host.isEmpty()) buf = sp_set_request(d->real_host, d->real_port, cmd); else - buf = sp_set_request(QHostAddress(), 0, cmd); + buf = sp_set_request(TQHostAddress(), 0, cmd); writeData(buf); } @@ -886,7 +886,7 @@ void SocksClient::serve() continueIncoming(); } -void SocksClient::processIncoming(const QByteArray &block) +void SocksClient::processIncoming(const TQByteArray &block) { #ifdef PROX_DEBUG // show hex @@ -1045,7 +1045,7 @@ void SocksClient::grantConnect() } } -void SocksClient::grantUDPAssociate(const QString &relayHost, int relayPort) +void SocksClient::grantUDPAssociate(const TQString &relayHost, int relayPort) { if(d->step != StepRequest || !d->waiting) return; @@ -1063,7 +1063,7 @@ void SocksClient::grantUDPAssociate(const QString &relayHost, int relayPort) d->recvBuf.resize(0); } -QHostAddress SocksClient::peerAddress() const +TQHostAddress SocksClient::peerAddress() const { return d->sock.peerAddress(); } @@ -1073,7 +1073,7 @@ Q_UINT16 SocksClient::peerPort() const return d->sock.peerPort(); } -QString SocksClient::udpAddress() const +TQString SocksClient::udpAddress() const { return d->udpAddr; } @@ -1083,7 +1083,7 @@ Q_UINT16 SocksClient::udpPort() const return d->udpPort; } -SocksUDP *SocksClient::createUDP(const QString &host, int port, const QHostAddress &routeAddr, int routePort) +SocksUDP *SocksClient::createUDP(const TQString &host, int port, const TQHostAddress &routeAddr, int routePort) { return new SocksUDP(this, host, port, routeAddr, routePort); } @@ -1097,18 +1097,18 @@ public: Private() {} ServSock serv; - QPtrList<SocksClient> incomingConns; - QSocketDevice *sd; - QSocketNotifier *sn; + TQPtrList<SocksClient> incomingConns; + TQSocketDevice *sd; + TQSocketNotifier *sn; }; -SocksServer::SocksServer(QObject *parent) -:QObject(parent) +SocksServer::SocksServer(TQObject *parent) +:TQObject(parent) { d = new Private; d->sd = 0; d->sn = 0; - connect(&d->serv, SIGNAL(connectionReady(int)), SLOT(connectionReady(int))); + connect(&d->serv, TQT_SIGNAL(connectionReady(int)), TQT_SLOT(connectionReady(int))); } SocksServer::~SocksServer() @@ -1130,16 +1130,16 @@ bool SocksServer::listen(Q_UINT16 port, bool udp) if(!d->serv.listen(port)) return false; if(udp) { - d->sd = new QSocketDevice(QSocketDevice::Datagram); + d->sd = new TQSocketDevice(TQSocketDevice::Datagram); d->sd->setBlocking(false); - if(!d->sd->bind(QHostAddress(), port)) { + if(!d->sd->bind(TQHostAddress(), port)) { delete d->sd; d->sd = 0; d->serv.stop(); return false; } - d->sn = new QSocketNotifier(d->sd->socket(), QSocketNotifier::Read); - connect(d->sn, SIGNAL(activated(int)), SLOT(sn_activated(int))); + d->sn = new TQSocketNotifier(d->sd->socket(), TQSocketNotifier::Read); + connect(d->sn, TQT_SIGNAL(activated(int)), TQT_SLOT(sn_activated(int))); } return true; } @@ -1158,7 +1158,7 @@ int SocksServer::port() const return d->serv.port(); } -QHostAddress SocksServer::address() const +TQHostAddress SocksServer::address() const { return d->serv.address(); } @@ -1172,15 +1172,15 @@ SocksClient *SocksServer::takeIncoming() d->incomingConns.removeRef(c); // we don't care about errors anymore - disconnect(c, SIGNAL(error(int)), this, SLOT(connectionError())); + disconnect(c, TQT_SIGNAL(error(int)), this, TQT_SLOT(connectionError())); // don't serve the connection until the event loop, to give the caller a chance to map signals - QTimer::singleShot(0, c, SLOT(serve())); + TQTimer::singleShot(0, c, TQT_SLOT(serve())); return c; } -void SocksServer::writeUDP(const QHostAddress &addr, int port, const QByteArray &data) +void SocksServer::writeUDP(const TQHostAddress &addr, int port, const TQByteArray &data) { if(d->sd) { d->sd->setBlocking(true); @@ -1192,7 +1192,7 @@ void SocksServer::writeUDP(const QHostAddress &addr, int port, const QByteArray void SocksServer::connectionReady(int s) { SocksClient *c = new SocksClient(s, this); - connect(c, SIGNAL(error(int)), this, SLOT(connectionError())); + connect(c, TQT_SIGNAL(error(int)), this, TQT_SLOT(connectionError())); d->incomingConns.append(c); incomingReady(); } @@ -1206,10 +1206,10 @@ void SocksServer::connectionError() void SocksServer::sn_activated(int) { - QByteArray buf(8192); + TQByteArray buf(8192); int actual = d->sd->readBlock(buf.data(), buf.size()); buf.resize(actual); - QHostAddress pa = d->sd->peerAddress(); + TQHostAddress pa = d->sd->peerAddress(); int pp = d->sd->peerPort(); SPS_UDP s; int r = sp_read_udp(&buf, &s); |