summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/msn/msnsocket.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/msn/msnsocket.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/msn/msnsocket.cpp')
-rw-r--r--kopete/protocols/msn/msnsocket.cpp170
1 files changed, 85 insertions, 85 deletions
diff --git a/kopete/protocols/msn/msnsocket.cpp b/kopete/protocols/msn/msnsocket.cpp
index a650cd83..0aaad25c 100644
--- a/kopete/protocols/msn/msnsocket.cpp
+++ b/kopete/protocols/msn/msnsocket.cpp
@@ -23,8 +23,8 @@
#include "msnsocket.h"
//#include "msnprotocol.h"
-#include <qregexp.h>
-#include <qtimer.h>
+#include <tqregexp.h>
+#include <tqtimer.h>
#include <kdebug.h>
#include <kconfig.h>
@@ -42,19 +42,19 @@ using namespace KNetwork;
class MimeMessage
{
public:
- MimeMessage(const QString &msg) : message(msg) {}
+ MimeMessage(const TQString &msg) : message(msg) {}
- QString getValue(const QString &key)
+ TQString getValue(const TQString &key)
{
- QRegExp rx(key+": ([^\r\n]+)");
+ TQRegExp rx(key+": ([^\r\n]+)");
rx.search(message);
return rx.cap(1);
}
private:
- QString message;
+ TQString message;
};
-MSNSocket::MSNSocket(QObject* parent) : QObject (parent)
+MSNSocket::MSNSocket(TQObject* parent) : TQObject (parent)
{
m_onlineStatus = Disconnected;
m_socket = 0L;
@@ -73,7 +73,7 @@ MSNSocket::~MSNSocket()
m_socket->deleteLater();
}
-void MSNSocket::connect( const QString &server, uint port )
+void MSNSocket::connect( const TQString &server, uint port )
{
if ( m_onlineStatus == Connected || m_onlineStatus == Connecting )
{
@@ -101,7 +101,7 @@ void MSNSocket::connect( const QString &server, uint port )
m_port = port;
if(!m_useHttp)
- m_socket = new KBufferedSocket( server, QString::number(port) );
+ m_socket = new KBufferedSocket( server, TQString::number(port) );
else {
m_socket = new KBufferedSocket( m_gateway, "80" );
}
@@ -112,20 +112,20 @@ void MSNSocket::connect( const QString &server, uint port )
// non-empty, so disable it until we have actual data in the queue
m_socket->enableWrite( false );
- QObject::connect( m_socket, SIGNAL( readyRead() ), this, SLOT( slotDataReceived() ) );
- QObject::connect( m_socket, SIGNAL( readyWrite() ), this, SLOT( slotReadyWrite() ) );
- QObject::connect( m_socket, SIGNAL( hostFound() ), this, SLOT( slotHostFound() ) );
- QObject::connect( m_socket, SIGNAL( connected( const KResolverEntry&) ), this, SLOT( slotConnectionSuccess() ) );
- QObject::connect( m_socket, SIGNAL( gotError( int ) ), this, SLOT( slotSocketError( int ) ) );
- QObject::connect( m_socket, SIGNAL( closed( ) ), this, SLOT( slotSocketClosed( ) ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( readyRead() ), this, TQT_SLOT( slotDataReceived() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( readyWrite() ), this, TQT_SLOT( slotReadyWrite() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( hostFound() ), this, TQT_SLOT( slotHostFound() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( connected( const KResolverEntry&) ), this, TQT_SLOT( slotConnectionSuccess() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( gotError( int ) ), this, TQT_SLOT( slotSocketError( int ) ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( closed( ) ), this, TQT_SLOT( slotSocketClosed( ) ) );
if(m_useHttp)
{
if(m_timer == 0L)
{
- m_timer = new QTimer(this, "Http poll timer");
+ m_timer = new TQTimer(this, "Http poll timer");
// Connect the slot HttpPoll with the timer timeout signal.
- QObject::connect(m_timer, SIGNAL(timeout()), this, SLOT(slotHttpPoll()));
+ TQObject::connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotHttpPoll()));
}
}
@@ -181,7 +181,7 @@ void MSNSocket::slotSocketError( int error )
return;
//we only care about fatal error
- QString errormsg = i18n( "There was an error while connecting to the MSN server.\nError message:\n" );
+ TQString errormsg = i18n( "There was an error while connecting to the MSN server.\nError message:\n" );
if ( error == KSocketBase::LookupFailure )
errormsg += i18n( "Unable to lookup %1" ).arg( m_socket->peerResolver().nodeName() );
else
@@ -212,7 +212,7 @@ void MSNSocket::slotDataReceived()
}
// incoming data, plus an extra char where we pretend a NUL is so the conversion
- // to QCString doesn't go over the end of the allocated memory.
+ // to TQCString doesn't go over the end of the allocated memory.
char *buffer = new char[ avail + 1 ];
int ret = m_socket->readBlock( buffer, avail );
@@ -240,16 +240,16 @@ void MSNSocket::slotDataReceived()
}
- QString rawData;
+ TQString rawData;
if(m_useHttp)
{
bool error = false;
- QByteArray bytes;
+ TQByteArray bytes;
// Check if all data has arrived.
- rawData = QString(QCString(buffer, avail + 1));
- bool headers = (rawData.find(QRegExp("HTTP/\\d\\.\\d (\\d+) ([^\r\n]+)")) != -1);
+ rawData = TQString(TQCString(buffer, avail + 1));
+ bool headers = (rawData.find(TQRegExp("HTTP/\\d\\.\\d (\\d+) ([^\r\n]+)")) != -1);
if(headers)
{
@@ -258,7 +258,7 @@ void MSNSocket::slotDataReceived()
if((endOfHeaders + 4) == avail)
{
// Only the response headers data is included.
- QRegExp re("Content-Length: ([^\r\n]+)");
+ TQRegExp re("Content-Length: ([^\r\n]+)");
if(re.search(rawData) != -1)
{
bool valid;
@@ -312,9 +312,9 @@ void MSNSocket::slotDataReceived()
{
// If we received a valid response, read the required headers.
// Retrieve the X-MSN-Messenger header.
- QString header = response.getHeaders()->getValue("X-MSN-Messenger");
+ TQString header = response.getHeaders()->getValue("X-MSN-Messenger");
- QStringList parts = QStringList::split(";", header.replace(" ", ""));
+ TQStringList parts = TQStringList::split(";", header.replace(" ", ""));
if(!header.isNull() && (parts.count() >= 2))
{
if(parts[0].find("SessionID", 0) != -1)
@@ -361,7 +361,7 @@ void MSNSocket::slotDataReceived()
if(valid && (length > 0))
{
// Otherwise, if the content length is greater than zero, get the web response stream.
- QDataStream *stream = response.getResponseStream();
+ TQDataStream *stream = response.getResponseStream();
buffer = new char[length];
// Read the web response content.
stream->readRawBytes(buffer, length);
@@ -390,8 +390,8 @@ void MSNSocket::slotDataReceived()
// all MSN commands start with one or more uppercase characters.
// For now just check the first three chars, let's see how accurate it is.
// Additionally, if we receive an MSN-P2P packet, strip off anything after the P2P header.
- rawData = QString( QCString( buffer, ((!m_useHttp)? avail : ret) + 1 ) ).stripWhiteSpace().replace(
- QRegExp( "(P2P-Dest:.[a-zA-Z@.]*).*" ), "\\1\n\n(Stripped binary data)" );
+ rawData = TQString( TQCString( buffer, ((!m_useHttp)? avail : ret) + 1 ) ).stripWhiteSpace().replace(
+ TQRegExp( "(P2P-Dest:.[a-zA-Z@.]*).*" ), "\\1\n\n(Stripped binary data)" );
bool isBinary = false;
for ( uint i = 0; i < 3 ; ++i )
@@ -429,7 +429,7 @@ void MSNSocket::slotReadLine()
if ( m_buffer.size() >= 3 && ( m_buffer.data()[ 0 ] == '\0' || m_buffer.data()[ 0 ]== '\1' ) )
{
bytesReceived( m_buffer.take( 3 ) );
- QTimer::singleShot( 0, this, SLOT( slotReadLine() ) );
+ TQTimer::singleShot( 0, this, TQT_SLOT( slotReadLine() ) );
return;
}
@@ -445,13 +445,13 @@ void MSNSocket::slotReadLine()
if ( index != -1 )
{
- QString command = QString::fromUtf8( m_buffer.take( index + 2 ), index );
+ TQString command = TQString::fromUtf8( m_buffer.take( index + 2 ), index );
command.replace( "\r\n", "" );
//kdDebug( 14141 ) << k_funcinfo << command << endl;
// Don't block the GUI while parsing data, only do a single line!
// (Done before parseLine() to prevent a potential crash)
- QTimer::singleShot( 0, this, SLOT( slotReadLine() ) );
+ TQTimer::singleShot( 0, this, TQT_SLOT( slotReadLine() ) );
parseLine( command );
// WARNING: At this point 'this' can be deleted (when disconnecting)
@@ -489,7 +489,7 @@ bool MSNSocket::pollReadBlock()
return true;
}
- QByteArray block = m_buffer.take( m_waitBlockSize );
+ TQByteArray block = m_buffer.take( m_waitBlockSize );
//kdDebug( 14140 ) << k_funcinfo << "Successfully read block of size " << m_waitBlockSize << endl;
@@ -499,10 +499,10 @@ bool MSNSocket::pollReadBlock()
return false;
}
-void MSNSocket::parseLine( const QString &str )
+void MSNSocket::parseLine( const TQString &str )
{
- QString cmd = str.section( ' ', 0, 0 );
- QString data = str.section( ' ', 2 ).replace( "\r\n" , "" );
+ TQString cmd = str.section( ' ', 0, 0 );
+ TQString data = str.section( ' ', 2 ).replace( "\r\n" , "" );
bool isNum;
uint id = str.section( ' ', 1, 1 ).toUInt( &isNum );
@@ -529,7 +529,7 @@ void MSNSocket::parseLine( const QString &str )
void MSNSocket::handleError( uint code, uint /* id */ )
{
kdDebug(14140) << k_funcinfo << endl;
- QString msg;
+ TQString msg;
ErrorType type = ErrorServerError;
switch ( code )
{
@@ -605,7 +605,7 @@ void MSNSocket::handleError( uint code, uint /* id */ )
return;
}
-int MSNSocket::sendCommand( const QString &cmd, const QString &args, bool addId, const QByteArray &body, bool binary )
+int MSNSocket::sendCommand( const TQString &cmd, const TQString &args, bool addId, const TQByteArray &body, bool binary )
{
if ( !m_socket )
{
@@ -613,22 +613,22 @@ int MSNSocket::sendCommand( const QString &cmd, const QString &args, bool addId,
return -1;
}
- QCString data = cmd.utf8();
+ TQCString data = cmd.utf8();
if ( addId )
- data += " " + QString::number( m_id ).utf8();
+ data += " " + TQString::number( m_id ).utf8();
if ( !args.isEmpty() )
data += " " + args.utf8();
// Add length in bytes, not characters
if ( !body.isEmpty() )
- data += " " + QString::number( body.size() - (binary ? 0 : 1 ) ).utf8();
+ data += " " + TQString::number( body.size() - (binary ? 0 : 1 ) ).utf8();
data += "\r\n";
// the command will be sent in slotReadyWrite
- QByteArray bytes;
+ TQByteArray bytes;
const uint length = data.length();
bytes.duplicate(data.data(), length);
if(!body.isEmpty())
@@ -657,7 +657,7 @@ void MSNSocket::slotReadyWrite()
if ( !m_sendQueue.isEmpty() )
{
// If the command queue is not empty, retrieve the first command.
- QValueList<QByteArray>::Iterator it = m_sendQueue.begin();
+ TQValueList<TQByteArray>::Iterator it = m_sendQueue.begin();
if(m_useHttp)
{
@@ -668,8 +668,8 @@ void MSNSocket::slotReadyWrite()
// Temporarily disable http polling.
m_bCanPoll = false;
// Set the host to the msn gateway by default.
- QString host = m_gateway;
- QString query; // Web request query string.
+ TQString host = m_gateway;
+ TQString query; // Web request query string.
if(m_bIsFirstInTransaction)
{
@@ -689,11 +689,11 @@ void MSNSocket::slotReadyWrite()
}
// Create the web request headers.
- QString s = makeHttpRequestString(host, query, (*it).size());
+ TQString s = makeHttpRequestString(host, query, (*it).size());
uint length = s.length();
// Create the web request bytes.
- QByteArray bytes(length + (*it).size());
+ TQByteArray bytes(length + (*it).size());
// Copy the request headers into the request bytes.
for(uint i=0; i < length; i++)
@@ -702,7 +702,7 @@ void MSNSocket::slotReadyWrite()
for(uint i=0; i < (*it).size(); i++)
bytes[length + i] = (*it)[i];
- kdDebug( 14141 ) << k_funcinfo << "Sending http command: " << QString(*it).stripWhiteSpace() << endl;
+ kdDebug( 14141 ) << k_funcinfo << "Sending http command: " << TQString(*it).stripWhiteSpace() << endl;
// Write the request bytes to the socket.
m_socket->writeBlock(bytes.data(), bytes.size());
@@ -725,8 +725,8 @@ void MSNSocket::slotReadyWrite()
// Simple check to avoid dumping the binary data from the icons and emoticons to kdDebug:
// When sending an MSN-P2P packet, strip off anything after the P2P header.
- QString debugData = QString( *it ).stripWhiteSpace().replace(
- QRegExp( "(P2P-Dest:.[a-zA-Z@.]*).*" ), "\\1\n\n(Stripped binary data)" );
+ TQString debugData = TQString( *it ).stripWhiteSpace().replace(
+ TQRegExp( "(P2P-Dest:.[a-zA-Z@.]*).*" ), "\\1\n\n(Stripped binary data)" );
kdDebug( 14141 ) << k_funcinfo << "Sending command: " << debugData << endl;
m_socket->writeBlock( *it, ( *it ).size() );
@@ -750,14 +750,14 @@ void MSNSocket::slotReadyWrite()
}
}
-QString MSNSocket::escape( const QString &str )
+TQString MSNSocket::escape( const TQString &str )
{
//return ( KURL::encode_string( str, 106 ) );
//It's not needed to encode everything. The official msn client only encode spaces and %
//If we encode more, the size can be longer than excepted.
int old_length= str.length();
- QChar *new_segment = new QChar[ old_length * 3 + 1 ];
+ TQChar *new_segment = new QChar[ old_length * 3 + 1 ];
int new_length = 0;
for ( int i = 0; i < old_length; i++ )
@@ -780,20 +780,20 @@ QString MSNSocket::escape( const QString &str )
new_segment[ new_length++ ] = str[i];
}
- QString result = QString(new_segment, new_length);
+ TQString result = TQString(new_segment, new_length);
delete [] new_segment;
return result;
}
-QString MSNSocket::unescape( const QString &str )
+TQString MSNSocket::unescape( const TQString &str )
{
- QString str2 = KURL::decode_string( str, 106 );
+ TQString str2 = KURL::decode_string( str, 106 );
//remove msn+ colors code
- str2 = str2.replace( QRegExp("[\\x1-\\x8]"), "" ); // old msn+ colors
+ str2 = str2.replace( TQRegExp("[\\x1-\\x8]"), "" ); // old msn+ colors
// added by kaoul <erwin.kwolek at gmail.com>
- str2 = str2.replace( QRegExp("\\xB7[&@\'#0]"),""); // dot ...
- str2 = str2.replace( QRegExp("\\xB7\\$,?\\d{1,2}"),""); // dot dollar (comma)? 0-99
+ str2 = str2.replace( TQRegExp("\\xB7[&@\'#0]"),""); // dot ...
+ str2 = str2.replace( TQRegExp("\\xB7\\$,?\\d{1,2}"),""); // dot dollar (comma)? 0-99
return str2;
}
@@ -847,7 +847,7 @@ void MSNSocket::slotHttpPoll()
}
// Create the http request headers.
- const QCString headers = makeHttpRequestString(m_gwip, "Action=poll&SessionID=" + m_sessionId, 0).utf8();
+ const TQCString headers = makeHttpRequestString(m_gwip, "Action=poll&SessionID=" + m_sessionId, 0).utf8();
m_socket->writeBlock(headers, headers.length());
// Wait for the response.
m_pending = true;
@@ -856,12 +856,12 @@ void MSNSocket::slotHttpPoll()
// Used in MSNFileTransferSocket
// FIXME: Why is this here if it's only used for file transfer? - Martijn
-void MSNSocket::bytesReceived( const QByteArray & /* data */ )
+void MSNSocket::bytesReceived( const TQByteArray & /* data */ )
{
kdWarning( 14140 ) << k_funcinfo << "Unknown bytes were received" << endl;
}
-void MSNSocket::sendBytes( const QByteArray &data )
+void MSNSocket::sendBytes( const TQByteArray &data )
{
if ( !m_socket )
{
@@ -879,13 +879,13 @@ bool MSNSocket::setUseHttpMethod( bool useHttp )
return true;
if( useHttp ) {
- QString s = QString( this->className() ).lower();
+ TQString s = TQString( this->className() ).lower();
if( s == "msnnotifysocket" )
m_type = "NS";
else if( s == "msnswitchboardsocket" )
m_type = "SB";
else
- m_type = QString::null;
+ m_type = TQString::null;
if( m_type.isNull() )
return false;
@@ -938,23 +938,23 @@ bool MSNSocket::accept( KServerSocket *server )
m_socket->enableRead( true );
m_socket->enableWrite( true );
- QObject::connect( m_socket, SIGNAL( readyRead() ), this, SLOT( slotDataReceived() ) );
- QObject::connect( m_socket, SIGNAL( readyWrite() ), this, SLOT( slotReadyWrite() ) );
- QObject::connect( m_socket, SIGNAL( closed() ), this, SLOT( slotSocketClosed() ) );
- QObject::connect( m_socket, SIGNAL( gotError( int ) ), this, SLOT( slotSocketError( int ) ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( readyRead() ), this, TQT_SLOT( slotDataReceived() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( readyWrite() ), this, TQT_SLOT( slotReadyWrite() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( closed() ), this, TQT_SLOT( slotSocketClosed() ) );
+ TQObject::connect( m_socket, TQT_SIGNAL( gotError( int ) ), this, TQT_SLOT( slotSocketError( int ) ) );
doneConnect();
return true;
}
-QString MSNSocket::getLocalIP()
+TQString MSNSocket::getLocalIP()
{
if ( !m_socket )
- return QString::null;
+ return TQString::null;
const KSocketAddress address = m_socket->localAddress();
- QString ip = address.nodeName();
+ TQString ip = address.nodeName();
kdDebug( 14140 ) << k_funcinfo << "IP: " << ip <<endl;
//delete address;
@@ -962,7 +962,7 @@ QString MSNSocket::getLocalIP()
}
MSNSocket::Buffer::Buffer( unsigned int sz )
-: QByteArray( sz )
+: TQByteArray( sz )
{
}
@@ -982,15 +982,15 @@ void MSNSocket::Buffer::add( char *str, unsigned int sz )
delete[] b;
}
-QByteArray MSNSocket::Buffer::take( unsigned blockSize )
+TQByteArray MSNSocket::Buffer::take( unsigned blockSize )
{
if ( size() < blockSize )
{
kdWarning( 14140 ) << k_funcinfo << "Buffer size " << size() << " < asked size " << blockSize << "!" << endl;
- return QByteArray();
+ return TQByteArray();
}
- QByteArray rep( blockSize );
+ TQByteArray rep( blockSize );
for( uint i = 0; i < blockSize; i++ )
rep[ i ] = data()[ i ];
@@ -1003,9 +1003,9 @@ QByteArray MSNSocket::Buffer::take( unsigned blockSize )
return rep;
}
-QString MSNSocket::makeHttpRequestString(const QString& host, const QString& query, uint contentLength)
+TQString MSNSocket::makeHttpRequestString(const TQString& host, const TQString& query, uint contentLength)
{
- QString s(
+ TQString s(
"POST http://" + host + "/gateway/gateway.dll?" + query + " HTTP/1.1\r\n" +
"Accept: */*\r\n" +
"Accept-Language: en-us\r\n" +
@@ -1015,22 +1015,22 @@ QString MSNSocket::makeHttpRequestString(const QString& host, const QString& que
"Connection: Keep-Alive\r\n" +
"Pragma: no-cache\r\n" +
"Content-Type: application/x-msn-messenger\r\n" +
- "Content-Length: " + QString::number(contentLength) + "\r\n" +
+ "Content-Length: " + TQString::number(contentLength) + "\r\n" +
"\r\n");
return s;
}
-MSNSocket::WebResponse::WebResponse(const QByteArray& bytes)
+MSNSocket::WebResponse::WebResponse(const TQByteArray& bytes)
{
m_statusCode = 0;
m_stream = 0;
int headerEnd;
- QString header;
- QString data(QCString(bytes, bytes.size() + 1));
+ TQString header;
+ TQString data(TQCString(bytes, bytes.size() + 1));
// Parse the HTTP status header
- QRegExp re("HTTP/\\d\\.\\d (\\d+) ([^\r\n]+)");
+ TQRegExp re("HTTP/\\d\\.\\d (\\d+) ([^\r\n]+)");
headerEnd = data.find("\r\n");
header = data.left( (headerEnd == -1) ? 20 : headerEnd );
@@ -1055,11 +1055,11 @@ MSNSocket::WebResponse::WebResponse(const QByteArray& bytes)
// copy the web response content bytes.
int offset = bytes.size() - length;
- QByteArray content(length);
+ TQByteArray content(length);
for(int i=0; i < length; i++)
content[i] = bytes[offset + i];
// Create the web response stream from the response content bytes.
- m_stream = new QDataStream(content, IO_ReadOnly);
+ m_stream = new TQDataStream(content, IO_ReadOnly);
}
}
}
@@ -1077,7 +1077,7 @@ MimeMessage* MSNSocket::WebResponse::getHeaders()
return m_headers;
}
-QDataStream* MSNSocket::WebResponse::getResponseStream()
+TQDataStream* MSNSocket::WebResponse::getResponseStream()
{
return m_stream;
}
@@ -1087,7 +1087,7 @@ int MSNSocket::WebResponse::getStatusCode()
return m_statusCode;
}
-QString MSNSocket::WebResponse::getStatusDescription()
+TQString MSNSocket::WebResponse::getStatusDescription()
{
return m_statusDescription;
}