3
Handles logging into to the Yahoo service
5
Copyright (c) 2004 Duncan Mac-Vicar P. <duncan@kde.org>
7
Copyright (c) 2005 André Duffeck <duffeck@kde.org>
9
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
11
*************************************************************************
13
* This library is free software; you can redistribute it and/or *
14
* modify it under the terms of the GNU Lesser General Public *
15
* License as published by the Free Software Foundation; either *
16
* version 2 of the License, or (at your option) any later version. *
18
*************************************************************************
23
#include "ymsgtransfer.h"
24
#include "yahootypes.h"
27
#include <qdatastream.h>
30
#include <qstringlist.h>
33
using namespace Yahoo;
35
class YMSGTransferPrivate
41
Yahoo::Service service;
48
YMSGTransfer::YMSGTransfer()
50
d = new YMSGTransferPrivate;
53
d-> status = Yahoo::StatusAvailable;
56
YMSGTransfer::YMSGTransfer(Yahoo::Service service)
58
d = new YMSGTransferPrivate;
62
d->status = Yahoo::StatusAvailable;
65
YMSGTransfer::YMSGTransfer(Yahoo::Service service, Yahoo::Status status)
67
d = new YMSGTransferPrivate;
74
YMSGTransfer::~YMSGTransfer()
79
Transfer::TransferType YMSGTransfer::type()
81
return Transfer::YMSGTransfer;
84
bool YMSGTransfer::isValid() const
89
Yahoo::Service YMSGTransfer::service() const
94
void YMSGTransfer::setService(Yahoo::Service service)
99
Yahoo::Status YMSGTransfer::status() const
104
void YMSGTransfer::setStatus(Yahoo::Status status)
109
unsigned int YMSGTransfer::id() const
114
void YMSGTransfer::setId(unsigned int id)
119
int YMSGTransfer::packetLength() const
121
return d->packetLength;
124
void YMSGTransfer::setPacketLength(int len)
126
d->packetLength = len;
129
ParamList YMSGTransfer::paramList() const
134
int YMSGTransfer::paramCount( int index ) const
137
for (ParamList::ConstIterator it = d->data.constBegin(); it != d->data.constEnd(); ++it)
139
if( (*it).first == index )
146
QByteArray YMSGTransfer::nthParam( int index, int occurrence ) const
149
for (ParamList::ConstIterator it = d->data.constBegin(); it != d->data.constEnd(); ++it)
151
if( (*it).first == index && cnt++ == occurrence)
157
QByteArray YMSGTransfer::nthParamSeparated( int index, int occurrence, int separator ) const
161
for (ParamList::ConstIterator it = d->data.constBegin(); it != d->data.constEnd(); ++it)
163
if( (*it).first == separator )
165
if( (*it).first == index && cnt == occurrence)
171
QByteArray YMSGTransfer::firstParam( int index ) const
173
for (ParamList::ConstIterator it = d->data.constBegin(); it != d->data.constEnd(); ++it)
175
if( (*it).first == index )
181
void YMSGTransfer::setParam(int index, const QByteArray &data)
183
d->data.append( Param( index, data ) );
186
void YMSGTransfer::setParam( int index, int data )
188
d->data.append( Param( index, QString::number( data ).toLocal8Bit() ) );
191
int YMSGTransfer::length() const
194
for (ParamList::ConstIterator it = d->data.constBegin(); it != d->data.constEnd(); ++it)
196
len += QString::number( (*it).first ).length();
198
len += (*it).second.length();
205
QByteArray YMSGTransfer::serialize() const
208
<------- 4B -------><------- 4B -------><---2B--->
209
+-------------------+-------------------+---------+
210
| Y M S G | version | pkt_len |
211
+---------+---------+---------+---------+---------+
212
| service | status | session_id |
213
+---------+-------------------+-------------------+
217
+-------------------------------------------------+
222
QDataStream stream( &buffer, QIODevice::WriteOnly );
224
stream << (qint8)'Y' << (qint8)'M' << (qint8)'S' << (qint8)'G';
225
if( d->service == Yahoo::ServicePictureUpload )
226
stream << (qint16)0x0f00;
228
stream << (qint16)0x000f;
229
stream << (qint16)0x0000;
230
if( d->service == Yahoo::ServicePictureUpload ||
231
d->service == Yahoo::ServiceFileTransfer )
232
stream << (qint16)(length()+4);
234
stream << (qint16)length();
235
stream << (qint16)d->service;
236
stream << (qint32)d->status;
237
stream << (qint32)d->id;
238
for (ParamList::ConstIterator it = d->data.constBegin(); it != d->data.constEnd(); ++it)
240
kDebug(YAHOO_RAW_DEBUG) << " Serializing key " << (*it).first << " value " << (*it).second;
241
stream.writeRawData ( QString::number( (*it).first ).toLocal8Bit(), QString::number( (*it).first ).length() );
242
stream << (qint8)0xc0 << (qint8)0x80;
243
stream.writeRawData( (*it).second, (*it).second.length() );
244
stream << (qint8)0xc0 << (qint8)0x80;
246
kDebug(YAHOO_RAW_DEBUG) << " pos=" << pos << " (packet size)" << buffer;