summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-05 08:45:53 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-07-05 08:45:53 +0000
commit5527e01e0675fbb06b632ccdae423756fbff622b (patch)
treec2dd1a478a7789d3b01e77fdf31f9011a96a81c5 /kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp
parent1fc8db48741fae272e2d29078b266a3d0f2e2dd1 (diff)
downloadtdenetwork-5527e01e0675fbb06b632ccdae423756fbff622b.tar.gz
tdenetwork-5527e01e0675fbb06b632ccdae423756fbff622b.zip
Many fixes to the Yahoo protocol, courtesy of Serghei Amelian
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1146108 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp')
-rw-r--r--kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp109
1 files changed, 59 insertions, 50 deletions
diff --git a/kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp b/kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp
index b05cb16d..2c73ef2b 100644
--- a/kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp
+++ b/kopete/protocols/yahoo/libkyahoo/coreprotocol.cpp
@@ -1,14 +1,14 @@
/*
Kopete Yahoo Protocol
-
+
Copyright (c) 2004 Duncan Mac-Vicar P. <duncan@kde.org>
-
- Based on code
+
+ Based on code
Copyright (c) 2004 SuSE Linux AG <http://www.suse.com>
- Copyright (C) 2003 Justin Karneges
-
+ Copyright (C) 2003 Justin Karneges <justin@affinix.com>
+
Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
-
+
*************************************************************************
* *
* This library is free software; you can redistribute it and/or *
@@ -26,7 +26,6 @@
#include <qdatetime.h>
#include <qtextstream.h>
-
#include <kdebug.h>
#include <kurl.h>
@@ -39,7 +38,7 @@ CoreProtocol::CoreProtocol() : QObject()
m_YMSGProtocol = new YMSGProtocol( this, "ymsgprotocol" );
}
-CoreProtocol::~CoreProtocol()
+CoreProtocol::~CoreProtocol()
{
}
@@ -52,60 +51,63 @@ void CoreProtocol::addIncomingData( const QByteArray & incomingBytes )
{
// store locally
int oldsize = m_in.size();
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << incomingBytes.size() << " bytes. already had " << oldsize << " bytes" << endl;
-
+ kdDebug(YAHOO_RAW_DEBUG) << incomingBytes.size() << " bytes. already had " << oldsize << " bytes" << endl;
+
m_in.resize( oldsize + incomingBytes.size() );
memcpy( m_in.data() + oldsize, incomingBytes.data(), incomingBytes.size() );
-
+
m_state = Available;
// convert every event in the chunk to a Transfer, signalling it back to the clientstream
-
+
int parsedBytes = 0;
int transferCount = 0;
// while there is data left in the input buffer, and we are able to parse something out of it
-
+
while ( m_in.size() && ( parsedBytes = wireToTransfer(m_in) ) )
{
transferCount++;
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " parsed transfer " << transferCount << " in chunk of "<< parsedBytes << " bytes" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " parsed transfer " << transferCount << " in chunk of "<< parsedBytes << " bytes" << endl;
int size = m_in.size();
if ( parsedBytes < size )
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " more data in chunk! ( I have parsed " << parsedBytes << " and total data of " << size << ")" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " more data in chunk! ( I have parsed " << parsedBytes << " and total data of " << size << ")" << endl;
+ // remove parsed bytes from the buffer
+ //m_in.remove( 0, parsedBytes );
+
// copy the unparsed bytes into a new qbytearray and replace m_in with that
- QByteArray remainder( size - parsedBytes );
- memcpy( remainder.data(), m_in.data() + parsedBytes, remainder.size() );
- m_in = remainder;
+ QByteArray remainder( size - parsedBytes );
+ memcpy( remainder.data(), m_in.data() + parsedBytes, remainder.size() );
+ m_in = remainder;
}
else
m_in.truncate( 0 );
}
if ( m_state == NeedMore )
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " message was incomplete, waiting for more..." << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " message was incomplete, waiting for more..." << endl;
/*
if ( m_eventProtocol->state() == EventProtocol::OutOfSync )
- {
+ {
qDebug( " - protocol thinks it's out of sync, discarding the rest of the buffer and hoping the server regains sync soon..." );
m_in.truncate( 0 );
}
*/
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " done processing chunk" << endl;
-
+ kdDebug(YAHOO_RAW_DEBUG) << " done processing chunk" << endl;
+
}
Transfer* CoreProtocol::incomingTransfer()
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl;
+ kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl;
if ( m_state == Available )
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " - got a transfer" << endl;
+// kdDebug(YAHOO_RAW_DEBUG) << " - got a transfer";
m_state = NoData;
return m_inTransfer;
m_inTransfer = 0;
}
else
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " no milk today" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " no milk today" << endl;
return 0;
}
}
@@ -113,7 +115,7 @@ Transfer* CoreProtocol::incomingTransfer()
void cp_dump( const QByteArray &bytes )
{
#ifdef YAHOO_COREPROTOCOL_DEBUG
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " contains " << bytes.count() << " bytes" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " contains " << bytes.count() << " bytes" << endl;
for ( uint i = 0; i < bytes.count(); ++i )
{
printf( "%02x ", bytes[ i ] );
@@ -126,20 +128,20 @@ void cp_dump( const QByteArray &bytes )
void CoreProtocol::outgoingTransfer( Transfer* outgoing )
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl;
+ kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl;
if ( outgoing->type() == Transfer::YMSGTransfer )
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " got YMSGTransfer" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " got YMSGTransfer" << endl;
YMSGTransfer *yt = (YMSGTransfer *) outgoing;
QByteArray bytesOut = yt->serialize();
-
- //QTextStream dout( bytesOut, IO_WriteOnly );
+
+ //QTextStream dout( bytesOut, QIODevice::WriteOnly );
//dout.setEncoding( QTextStream::Latin1 );
//dout.setByteOrder( QDataStream::LittleEndian );
//dout << bytesOut;
- //kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " " << bytesOut << endl;
+ //kdDebug(YAHOO_RAW_DEBUG) << " " << bytesOut;
emit outgoingData( bytesOut );
- // now convert
+ // now convert
//fieldsToWire( fields );
}
delete outgoing;
@@ -149,53 +151,60 @@ void CoreProtocol::outgoingTransfer( Transfer* outgoing )
int CoreProtocol::wireToTransfer( const QByteArray& wire )
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << endl;
+ kdDebug(YAHOO_GEN_DEBUG) << k_funcinfo << endl;
// processing incoming data and reassembling it into transfers
// may be an event or a response
-
+
uint bytesParsed = 0;
-
+
if ( wire.size() < 20 ) // minimal value of a YMSG header
{
m_state = NeedMore;
return bytesParsed;
}
-
- QDataStream din( wire, IO_ReadOnly );
-
+
+ QByteArray tempWire = wire;
+ QDataStream din( tempWire, IO_ReadOnly );
+
// look at first four bytes and decide what to do with the chunk
if ( okToProceed( din ) )
{
if ( (wire[0] == 'Y') && (wire[1] == 'M') && (wire[2] == 'S') && (wire[3] == 'G'))
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " - looks like a valid YMSG packet" << endl;
- Transfer *t = m_YMSGProtocol->parse( wire, bytesParsed );
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " - YMSG Protocol parsed " << bytesParsed << " bytes" << endl;
+// kdDebug(YAHOO_RAW_DEBUG) << " - looks like a valid YMSG packet";
+ YMSGTransfer *t = static_cast<YMSGTransfer *>(m_YMSGProtocol->parse( wire, bytesParsed ));
+// kdDebug(YAHOO_RAW_DEBUG) << " - YMSG Protocol parsed " << bytesParsed << " bytes";
if ( t )
{
+ if( wire.size() < t->packetLength() )
+ {
+ m_state = NeedMore;
+ delete t;
+ return 0;
+ }
m_inTransfer = t;
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " - got a valid packet " << endl;
-
+// kdDebug(YAHOO_RAW_DEBUG) << " - got a valid packet ";
+
m_state = Available;
emit incomingData();
}
else
bytesParsed = 0;
}
- else
- {
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " - not a valid YMSG packet. Trying to recover: " << wire << endl;
+ else
+ {
+ kdDebug(YAHOO_RAW_DEBUG) << " - not a valid YMSG packet. Trying to recover." << endl;
QTextStream s( wire, IO_ReadOnly );
QString remaining = s.read();
int pos = remaining.find( "YMSG", bytesParsed );
if( pos >= 0 )
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Recover successful." << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << "Recover successful." << endl;
bytesParsed += pos;
}
else
{
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Recover failed. Dump it!" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << "Recover failed. Dump it!" << endl;
bytesParsed = wire.size();
}
}
@@ -208,7 +217,7 @@ void CoreProtocol::reset()
m_in.resize( 0 );
}
-void CoreProtocol::slotOutgoingData( const QCString &out )
+void CoreProtocol::slotOutgoingData( const QByteArray &out )
{
qDebug( "%s", out.data() );
}
@@ -218,7 +227,7 @@ bool CoreProtocol::okToProceed( QDataStream &din)
if ( din.atEnd() )
{
m_state = NeedMore;
- kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << " saved message prematurely" << endl;
+ kdDebug(YAHOO_RAW_DEBUG) << " saved message prematurely" << endl;
return false;
}
else