summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-31 19:48:06 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-31 19:48:06 +0000
commit47c8a359c5276062c4bc17f0e82410f29081b502 (patch)
tree2d54a5f60a5b74067632f9ef6df58c2bc38155e6 /kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp
parent6f82532777a35e0e60bbd2b290b2e93e646f349b (diff)
downloadtdenetwork-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/httppoll.cpp')
-rw-r--r--kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp158
1 files changed, 79 insertions, 79 deletions
diff --git a/kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp b/kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp
index 605d44e9..3a182457 100644
--- a/kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp
+++ b/kopete/protocols/jabber/libiris/cutestuff/network/httppoll.cpp
@@ -20,10 +20,10 @@
#include"httppoll.h"
-#include<qstringlist.h>
-#include<qurl.h>
-#include<qtimer.h>
-#include<qguardedptr.h>
+#include<tqstringlist.h>
+#include<tqurl.h>
+#include<tqtimer.h>
+#include<tqguardedptr.h>
#include<qca.h>
#include<stdlib.h>
#include"bsocket.h"
@@ -37,9 +37,9 @@
// CS_NAMESPACE_BEGIN
-static QByteArray randomArray(int size)
+static TQByteArray randomArray(int size)
{
- QByteArray a(size);
+ TQByteArray a(size);
for(int n = 0; n < size; ++n)
a[n] = (char)(256.0*rand()/(RAND_MAX+1.0));
return a;
@@ -48,12 +48,12 @@ static QByteArray randomArray(int size)
//----------------------------------------------------------------------------
// HttpPoll
//----------------------------------------------------------------------------
-static QString hpk(int n, const QString &s)
+static TQString hpk(int n, const TQString &s)
{
if(n == 0)
return s;
else
- return Base64::arrayToString( QCA::SHA1::hash( QCString(hpk(n - 1, s).latin1()) ) );
+ return Base64::arrayToString( QCA::SHA1::hash( TQCString(hpk(n - 1, s).latin1()) ) );
}
class HttpPoll::Private
@@ -62,37 +62,37 @@ public:
Private() {}
HttpProxyPost http;
- QString host;
+ TQString host;
int port;
- QString user, pass;
- QString url;
+ TQString user, pass;
+ TQString url;
bool use_proxy;
- QByteArray out;
+ TQByteArray out;
int state;
bool closing;
- QString ident;
+ TQString ident;
- QTimer *t;
+ TQTimer *t;
- QString key[POLL_KEYS];
+ TQString key[POLL_KEYS];
int key_n;
int polltime;
};
-HttpPoll::HttpPoll(QObject *parent)
+HttpPoll::HttpPoll(TQObject *parent)
:ByteStream(parent)
{
d = new Private;
d->polltime = 30;
d->t = new QTimer;
- connect(d->t, SIGNAL(timeout()), SLOT(do_sync()));
+ connect(d->t, TQT_SIGNAL(timeout()), TQT_SLOT(do_sync()));
- connect(&d->http, SIGNAL(result()), SLOT(http_result()));
- connect(&d->http, SIGNAL(error(int)), SLOT(http_error(int)));
+ connect(&d->http, TQT_SIGNAL(result()), TQT_SLOT(http_result()));
+ connect(&d->http, TQT_SIGNAL(error(int)), TQT_SLOT(http_error(int)));
reset(true);
}
@@ -117,18 +117,18 @@ void HttpPoll::reset(bool clear)
d->t->stop();
}
-void HttpPoll::setAuth(const QString &user, const QString &pass)
+void HttpPoll::setAuth(const TQString &user, const TQString &pass)
{
d->user = user;
d->pass = pass;
}
-void HttpPoll::connectToUrl(const QString &url)
+void HttpPoll::connectToUrl(const TQString &url)
{
connectToHost("", 0, url);
}
-void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QString &url)
+void HttpPoll::connectToHost(const TQString &proxyHost, int proxyPort, const TQString &url)
{
reset(true);
@@ -140,7 +140,7 @@ void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QStr
d->use_proxy = true;
}
else {
- QUrl u = url;
+ TQUrl u = url;
d->host = u.host();
if(u.hasPort())
d->port = u.port();
@@ -152,7 +152,7 @@ void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QStr
resetKey();
bool last;
- QString key = getKey(&last);
+ TQString key = getKey(&last);
#ifdef PROX_DEBUG
fprintf(stderr, "HttpPoll: Connecting to %s:%d [%s]", d->host.latin1(), d->port, d->url.latin1());
@@ -161,19 +161,19 @@ void HttpPoll::connectToHost(const QString &proxyHost, int proxyPort, const QStr
else
fprintf(stderr, ", auth {%s,%s}\n", d->user.latin1(), d->pass.latin1());
#endif
- QGuardedPtr<QObject> self = this;
+ TQGuardedPtr<TQObject> self = this;
syncStarted();
if(!self)
return;
d->state = 1;
d->http.setAuth(d->user, d->pass);
- d->http.post(d->host, d->port, d->url, makePacket("0", key, "", QByteArray()), d->use_proxy);
+ d->http.post(d->host, d->port, d->url, makePacket("0", key, "", TQByteArray()), d->use_proxy);
}
-QByteArray HttpPoll::makePacket(const QString &ident, const QString &key, const QString &newkey, const QByteArray &block)
+TQByteArray HttpPoll::makePacket(const TQString &ident, const TQString &key, const TQString &newkey, const TQByteArray &block)
{
- QString str = ident;
+ TQString str = ident;
if(!key.isEmpty()) {
str += ';';
str += key;
@@ -183,10 +183,10 @@ QByteArray HttpPoll::makePacket(const QString &ident, const QString &key, const
str += newkey;
}
str += ',';
- QCString cs = str.latin1();
+ TQCString cs = str.latin1();
int len = cs.length();
- QByteArray a(len + block.size());
+ TQByteArray a(len + block.size());
memcpy(a.data(), cs.data(), len);
memcpy(a.data() + len, block.data(), block.size());
return a;
@@ -221,14 +221,14 @@ void HttpPoll::close()
void HttpPoll::http_result()
{
// check for death :)
- QGuardedPtr<QObject> self = this;
+ TQGuardedPtr<TQObject> self = this;
syncFinished();
if(!self)
return;
// get id and packet
- QString id;
- QString cookie = d->http.getHeader("Set-Cookie");
+ TQString id;
+ TQString cookie = d->http.getHeader("Set-Cookie");
int n = cookie.find("ID=");
if(n == -1) {
reset();
@@ -241,7 +241,7 @@ void HttpPoll::http_result()
id = cookie.mid(n, n2-n);
else
id = cookie.mid(n);
- QByteArray block = d->http.body();
+ TQByteArray block = d->http.body();
// session error?
if(id.right(2) == ":0") {
@@ -337,14 +337,14 @@ void HttpPoll::do_sync()
d->out = takeWrite(0, false);
bool last;
- QString key = getKey(&last);
- QString newkey;
+ TQString key = getKey(&last);
+ TQString newkey;
if(last) {
resetKey();
newkey = getKey(&last);
}
- QGuardedPtr<QObject> self = this;
+ TQGuardedPtr<TQObject> self = this;
syncStarted();
if(!self)
return;
@@ -357,15 +357,15 @@ void HttpPoll::resetKey()
#ifdef PROX_DEBUG
fprintf(stderr, "HttpPoll: reset key!\n");
#endif
- QByteArray a = randomArray(64);
- QString str = QString::fromLatin1(a.data(), a.size());
+ TQByteArray a = randomArray(64);
+ TQString str = TQString::fromLatin1(a.data(), a.size());
d->key_n = POLL_KEYS;
for(int n = 0; n < POLL_KEYS; ++n)
d->key[n] = hpk(n+1, str);
}
-const QString & HttpPoll::getKey(bool *last)
+const TQString & HttpPoll::getKey(bool *last)
{
*last = false;
--(d->key_n);
@@ -378,20 +378,20 @@ const QString & HttpPoll::getKey(bool *last)
//----------------------------------------------------------------------------
// HttpProxyPost
//----------------------------------------------------------------------------
-static QString extractLine(QByteArray *buf, bool *found)
+static TQString extractLine(TQByteArray *buf, bool *found)
{
// scan for newline
int n;
for(n = 0; n < (int)buf->size()-1; ++n) {
if(buf->at(n) == '\r' && buf->at(n+1) == '\n') {
- QCString cstr;
+ TQCString cstr;
cstr.resize(n+1);
memcpy(cstr.data(), buf->data(), n);
n += 2; // hack off CR/LF
memmove(buf->data(), buf->data() + n, buf->size() - n);
buf->resize(buf->size() - n);
- QString s = QString::fromUtf8(cstr);
+ TQString s = TQString::fromUtf8(cstr);
if(found)
*found = true;
@@ -404,7 +404,7 @@ static QString extractLine(QByteArray *buf, bool *found)
return "";
}
-static bool extractMainHeader(const QString &line, QString *proto, int *code, QString *msg)
+static bool extractMainHeader(const TQString &line, TQString *proto, int *code, TQString *msg)
{
int n = line.find(' ');
if(n == -1)
@@ -429,23 +429,23 @@ public:
Private() {}
BSocket sock;
- QByteArray postdata, recvBuf, body;
- QString url;
- QString user, pass;
+ TQByteArray postdata, recvBuf, body;
+ TQString url;
+ TQString user, pass;
bool inHeader;
- QStringList headerLines;
+ TQStringList headerLines;
bool asProxy;
- QString host;
+ TQString host;
};
-HttpProxyPost::HttpProxyPost(QObject *parent)
-:QObject(parent)
+HttpProxyPost::HttpProxyPost(TQObject *parent)
+:TQObject(parent)
{
d = new Private;
- connect(&d->sock, SIGNAL(connected()), SLOT(sock_connected()));
- connect(&d->sock, SIGNAL(connectionClosed()), SLOT(sock_connectionClosed()));
- connect(&d->sock, SIGNAL(readyRead()), SLOT(sock_readyRead()));
- 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(readyRead()), TQT_SLOT(sock_readyRead()));
+ connect(&d->sock, TQT_SIGNAL(error(int)), TQT_SLOT(sock_error(int)));
reset(true);
}
@@ -464,7 +464,7 @@ void HttpProxyPost::reset(bool clear)
d->body.resize(0);
}
-void HttpProxyPost::setAuth(const QString &user, const QString &pass)
+void HttpProxyPost::setAuth(const TQString &user, const TQString &pass)
{
d->user = user;
d->pass = pass;
@@ -475,7 +475,7 @@ bool HttpProxyPost::isActive() const
return (d->sock.state() == BSocket::Idle ? false: true);
}
-void HttpProxyPost::post(const QString &proxyHost, int proxyPort, const QString &url, const QByteArray &data, bool asProxy)
+void HttpProxyPost::post(const TQString &proxyHost, int proxyPort, const TQString &url, const TQByteArray &data, bool asProxy)
{
reset(true);
@@ -499,19 +499,19 @@ void HttpProxyPost::stop()
reset();
}
-QByteArray HttpProxyPost::body() const
+TQByteArray HttpProxyPost::body() const
{
return d->body;
}
-QString HttpProxyPost::getHeader(const QString &var) const
+TQString HttpProxyPost::getHeader(const TQString &var) const
{
- for(QStringList::ConstIterator it = d->headerLines.begin(); it != d->headerLines.end(); ++it) {
- const QString &s = *it;
+ for(TQStringList::ConstIterator it = d->headerLines.begin(); it != d->headerLines.end(); ++it) {
+ const TQString &s = *it;
int n = s.find(": ");
if(n == -1)
continue;
- QString v = s.mid(0, n);
+ TQString v = s.mid(0, n);
if(v == var)
return s.mid(n+2);
}
@@ -526,30 +526,30 @@ void HttpProxyPost::sock_connected()
d->inHeader = true;
d->headerLines.clear();
- QUrl u = d->url;
+ TQUrl u = d->url;
// connected, now send the request
- QString s;
- s += QString("POST ") + d->url + " HTTP/1.0\r\n";
+ TQString s;
+ s += TQString("POST ") + d->url + " HTTP/1.0\r\n";
if(d->asProxy) {
if(!d->user.isEmpty()) {
- QString str = d->user + ':' + d->pass;
- s += QString("Proxy-Authorization: Basic ") + Base64::encodeString(str) + "\r\n";
+ TQString str = d->user + ':' + d->pass;
+ s += TQString("Proxy-Authorization: Basic ") + Base64::encodeString(str) + "\r\n";
}
s += "Proxy-Connection: Keep-Alive\r\n";
s += "Pragma: no-cache\r\n";
- s += QString("Host: ") + u.host() + "\r\n";
+ s += TQString("Host: ") + u.host() + "\r\n";
}
else {
- s += QString("Host: ") + d->host + "\r\n";
+ s += TQString("Host: ") + d->host + "\r\n";
}
s += "Content-Type: application/x-www-form-urlencoded\r\n";
- s += QString("Content-Length: ") + QString::number(d->postdata.size()) + "\r\n";
+ s += TQString("Content-Length: ") + TQString::number(d->postdata.size()) + "\r\n";
s += "\r\n";
// write request
- QCString cs = s.utf8();
- QByteArray block(cs.length());
+ TQCString cs = s.utf8();
+ TQByteArray block(cs.length());
memcpy(block.data(), cs.data(), block.size());
d->sock.write(block);
@@ -566,14 +566,14 @@ void HttpProxyPost::sock_connectionClosed()
void HttpProxyPost::sock_readyRead()
{
- QByteArray block = d->sock.read();
+ TQByteArray block = d->sock.read();
ByteStream::appendArray(&d->recvBuf, block);
if(d->inHeader) {
// grab available lines
while(1) {
bool found;
- QString line = extractLine(&d->recvBuf, &found);
+ TQString line = extractLine(&d->recvBuf, &found);
if(!found)
break;
if(line.isEmpty()) {
@@ -585,12 +585,12 @@ void HttpProxyPost::sock_readyRead()
// done with grabbing the header?
if(!d->inHeader) {
- QString str = d->headerLines.first();
+ TQString str = d->headerLines.first();
d->headerLines.remove(d->headerLines.begin());
- QString proto;
+ TQString proto;
int code;
- QString msg;
+ TQString msg;
if(!extractMainHeader(str, &proto, &code, &msg)) {
#ifdef PROX_DEBUG
fprintf(stderr, "HttpProxyPost: invalid header!\n");
@@ -602,7 +602,7 @@ void HttpProxyPost::sock_readyRead()
else {
#ifdef PROX_DEBUG
fprintf(stderr, "HttpProxyPost: header proto=[%s] code=[%d] msg=[%s]\n", proto.latin1(), code, msg.latin1());
- for(QStringList::ConstIterator it = d->headerLines.begin(); it != d->headerLines.end(); ++it)
+ for(TQStringList::ConstIterator it = d->headerLines.begin(); it != d->headerLines.end(); ++it)
fprintf(stderr, "HttpProxyPost: * [%s]\n", (*it).latin1());
#endif
}
@@ -614,7 +614,7 @@ void HttpProxyPost::sock_readyRead()
}
else {
int err;
- QString errStr;
+ TQString errStr;
if(code == 407) { // Authentication failed
err = ErrProxyAuth;
errStr = tr("Authentication failed");