summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/yahoo/libkyahoo/ymsgprotocol.cpp
blob: d7a13b85974872a70df07506ee2c4795a770cd0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/*
    Kopete Yahoo Protocol

    Copyright (c) 2004 Duncan Mac-Vicar Prett <duncan@kde.org>

    Copyright (c) 2005 André Duffeck <duffeck@kde.org>
    Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

//#include <TQDataStream>
//#include <TQMap>
//#include <TQObject>
//#include <TQStringList>

//#include <tqcstring.h>
#include <tqdatastream.h>
#include <tqmap.h>
#include <tqobject.h>
#include <tqstringlist.h>


#include <kdebug.h>

#include "ymsgprotocol.h"
#include "ymsgtransfer.h"
#include "yahootypes.h"

using namespace Yahoo;

YMSGProtocol::YMSGProtocol(TQObject *parent, const char *name)
 : InputProtocolBase(parent, name)
{
}

YMSGProtocol::~YMSGProtocol()
{
}

Transfer* YMSGProtocol::parse( const TQByteArray & packet, uint& bytes )
{
	/*
	<------- 4B -------><------- 4B -------><---2B--->
	+-------------------+-------------------+---------+
	|   Y   M   S   G   |      version      | pkt_len |
	+---------+---------+---------+---------+---------+
	| service |      status       |    session_id     |
	+---------+-------------------+-------------------+
	|                                                 |
	:                    D A T A                      :
	/                   0 - 65535*                   |
	+-------------------------------------------------+
	*/
	kdDebug(YAHOO_RAW_DEBUG) << packet << endl;

	int pos = 0;
	int len = 0;

	Yahoo::tqStatus status = Yahoo::StatusAvailable;
	Yahoo::Service service = Yahoo::ServiceAuth;
	int statusnum = 0;
	int sessionid = 0;
	int servicenum;
	int version1, version2;

	TQMap<TQString, TQString> params;

	// Skip the YMSG header
	pos += 4;

	// Skip the version
	version1 = yahoo_get16(packet.data() + pos);
	pos += 2;
	version2 = yahoo_get16(packet.data() + pos);
	pos += 2;
	kdDebug(YAHOO_RAW_DEBUG) << " - parsed packet version " << version1 << " " << version2 << endl;

	len = yahoo_get16(packet.data() + pos);
	pos += 2;
	kdDebug(YAHOO_RAW_DEBUG) << " - parsed packet len " << len << endl;

	servicenum = yahoo_get16(packet.data() + pos);
	pos += 2;

	switch (servicenum)
	{
		// TODO add remamining services
		case (Yahoo::ServiceAuth) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceAuth " << servicenum << endl;
			service = Yahoo::ServiceAuth;
		break;
		case (Yahoo::ServiceAuthResp) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceAuthResp " << servicenum << endl;
			service = Yahoo::ServiceAuthResp;
		break;
		case (Yahoo::ServiceVerify) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceVerify " << servicenum << endl;
			service = Yahoo::ServiceVerify;
		break;
		case (Yahoo::ServiceList) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceList " << servicenum << endl;
			service = Yahoo::ServiceList;
		break;
		case (Yahoo::ServiceLogon) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceLogon " << servicenum << endl;
			service = Yahoo::ServiceLogon;
		break;
		case (Yahoo::ServicePing) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePing " << servicenum << endl;
			service = Yahoo::ServicePing;
		break;
		case (Yahoo::ServiceNewMail) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceNewMail " << servicenum << endl;
			service = Yahoo::ServiceNewMail;
		break;
		case (Yahoo::ServiceLogoff) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceLogoff " << servicenum << endl;
			service = Yahoo::ServiceLogoff;
		break;
		case (Yahoo::ServiceIsAway) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceIsAway " << servicenum << endl;
			service = Yahoo::ServiceIsAway;
		break;
		case (Yahoo::ServiceIsBack) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceIsBack " << servicenum << endl;
			service = Yahoo::ServiceIsBack;
		break;
		case (Yahoo::ServiceGameLogon) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceGameLogon " << servicenum << endl;
			service = Yahoo::ServiceGameLogon;
		break;
		case (Yahoo::ServiceGameLogoff) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceGameLogoff " << servicenum << endl;
			service = Yahoo::ServiceGameLogoff;
		break;
		case (Yahoo::ServiceIdAct) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceIdAct " << servicenum << endl;
			service = Yahoo::ServiceIdAct;
		break;
		case (Yahoo::ServiceIddeAct) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceIddeAct " << servicenum << endl;
			service = Yahoo::ServiceIddeAct;
		break;
		case (Yahoo::ServicetqStatus) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicetqStatus " << servicenum << endl;
			service = Yahoo::ServicetqStatus;
		break;
		case (Yahoo::ServiceMessage) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceMessage " << servicenum << endl;
			service = Yahoo::ServiceMessage;
		break;
		case (Yahoo::ServiceNotify) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceNotify " << servicenum << endl;
			service = Yahoo::ServiceNotify;
		break;
		case (Yahoo::ServiceBuddyAdd) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceBuddyAdd " << servicenum << endl;
			service = Yahoo::ServiceBuddyAdd;
		break;
        	case (Yahoo::ServiceBuddyRemove) :
	                kdDebug(YAHOO_RAW_DEBUG) << "Parsed packet service -  This means ServiceBuddyRemove " << servicenum << endl;
	                service = Yahoo::ServiceBuddyRemove;
	        break;
        	case (Yahoo::ServiceBuddyChangeGroup) :
	                kdDebug(YAHOO_RAW_DEBUG) << "Parsed packet service -  This means ServiceBuddyChangeGroup " << servicenum << endl;
	                service = Yahoo::ServiceBuddyChangeGroup;
	        break;
		case (Yahoo::ServicePictureChecksum) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePictureChecksum " << servicenum << endl;
			service = Yahoo::ServicePictureChecksum;
		break;
		case (Yahoo::ServicePicturetqStatus) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePicturetqStatus " << servicenum << endl;
			service = Yahoo::ServicePicturetqStatus;
		break;
		case (Yahoo::ServicePicture) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePicture " << servicenum << endl;
			service = Yahoo::ServicePicture;
		break;
		case (Yahoo::ServiceStealthOnline) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceStealthOnline " << servicenum << endl;
			service = Yahoo::ServiceStealthOnline;
		break;
		case (Yahoo::ServiceStealthOffline) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceStealthOffline " << servicenum << endl;
			service = Yahoo::ServiceStealthOffline;
		break;
		case (Yahoo::ServicePictureUpload) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePictureUpload " << servicenum << endl;
			service = Yahoo::ServicePictureUpload;
		break;
		case (Yahoo::ServiceWebcam) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceWebcam " << servicenum << endl;
			service = Yahoo::ServiceWebcam;
		break;
		case (Yahoo::ServiceConfInvite) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceConfInvite " << servicenum << endl;
			service = Yahoo::ServiceConfInvite;
		break;
		case (Yahoo::ServiceConfLogon) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceConfLogon " << servicenum << endl;
			service = Yahoo::ServiceConfLogon;
		break;
		case (Yahoo::ServiceConfDecline) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceConfDecline " << servicenum << endl;
			service = Yahoo::ServiceConfDecline;
		break;
		case (Yahoo::ServiceConfLogoff) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceConfLogoff " << servicenum << endl;
			service = Yahoo::ServiceConfLogoff;
		break;
		case (Yahoo::ServiceConfAddInvite) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceConfAddInvite " << servicenum << endl;
			service = Yahoo::ServiceConfAddInvite;
		break;
		case (Yahoo::ServiceConfMsg) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceConfMsg " << servicenum << endl;
			service = Yahoo::ServiceConfMsg;
		break;
		case (Yahoo::ServiceAuthorization) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceAuthorization " << servicenum << endl;
			service = Yahoo::ServiceAuthorization;
		break;
		case (Yahoo::ServiceContactDetails) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceContactDetails " << servicenum << endl;
			service = Yahoo::ServiceContactDetails;
		break;
		case (Yahoo::ServiceFileTransfer) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceFileTransfer " << servicenum << endl;
			service = Yahoo::ServiceFileTransfer;
		break;
		case (Yahoo::ServiceFileTransfer7) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceFileTransfer7 " << servicenum << endl;
			service = Yahoo::ServiceFileTransfer7;
		break;
		case (Yahoo::ServiceFileTransfer7Info) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceFileTransfer7Info " << servicenum << endl;
			service = Yahoo::ServiceFileTransfer7Info;
		break;
		case (Yahoo::ServiceFileTransfer7Accept) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceFileTransfer7Accept " << servicenum << endl;
			service = Yahoo::ServiceFileTransfer7Accept;
		break;
		case (Yahoo::ServicePeerToPeer) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePeerToPeer " << servicenum << endl;
			service = Yahoo::ServicePeerToPeer;
		break;
		case (Yahoo::ServiceChatOnline) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatOnline " << servicenum << endl;
			service = Yahoo::ServiceChatOnline;
		break;
		case (Yahoo::ServiceChatGoto) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatGoto " << servicenum << endl;
			service = Yahoo::ServiceChatGoto;
		break;
		case (Yahoo::ServiceChatJoin) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatJoin " << servicenum << endl;
			service = Yahoo::ServiceChatJoin;
		break;
		case (Yahoo::ServiceChatleave) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatleave " << servicenum << endl;
			service = Yahoo::ServiceChatleave;
		break;
		case (Yahoo::ServiceChatExit) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatExit " << servicenum << endl;
			service = Yahoo::ServiceChatExit;
		break;
		case (Yahoo::ServiceChatLogout) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatLogout " << servicenum << endl;
			service = Yahoo::ServiceChatLogout;
		break;
		case (Yahoo::ServiceChatPing) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServicePeerToPeer " << servicenum << endl;
			service = Yahoo::ServiceChatPing;
		break;
		case (Yahoo::ServiceChatLogon) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatLogon " << servicenum << endl;
			service = Yahoo::ServiceChatLogon;
		break;
		case (Yahoo::ServiceChatLogoff) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatLogoff " << servicenum << endl;
			service = Yahoo::ServiceChatLogoff;
		break;
		case (Yahoo::ServiceChatMsg) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceChatMsg " << servicenum << endl;
			service = Yahoo::ServiceChatMsg;
		break;
		case (Yahoo::ServiceComment) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceComment " << servicenum << endl;
			service = Yahoo::ServiceComment;
		break;
		case (Yahoo::ServiceBuddytqStatus) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceBuddytqStatus " << servicenum << endl;
			service = Yahoo::ServiceBuddytqStatus;
		break;
		case (Yahoo::ServiceBuddyList) :
			kdDebug(YAHOO_RAW_DEBUG) << " Parsed packet service -  This means ServiceBuddyList " << servicenum << endl;
			service = Yahoo::ServiceBuddyList;
		break;
		/*
		ServiceIdle, // 5 (placemarker)
		ServiceMailStat,
		ServiceUserStat, // 0xa
		ServiceChatInvite,
		ServiceCalendar,
		ServiceNewPersonalMail,
		ServiceNewContact,
		ServiceAddIdent, // 0x10
		ServiceAddIgnore,
		ServiceGotGroupRename, // < 1, 36(old), 37(new)
		ServiceSysMessage = 0x14,
		ServicePassThrough2 = 0x16,
		ServiceGameMsg = 0x2a,
		ServiceFileTransfer = 0x46,
		ServiceVoiceChat = 0x4A,
		ServiceVerify = 76,
		ServiceP2PFileXfer,
		ServiceRemBuddy,
		ServiceIgnoreContact,	// > 1, 7, 13 < 1, 66, 13, 0
		ServiceRejectContact,
		ServiceGroupRename = 0x89, // > 1, 65(new), 66(0), 67(old)
		ServicePictureUpdate = 0xc1,
		ServiceVisibility = 0xc5,	// YMSG13, key 13: 2 = invisible, 1 = visible
		ServicetqStatus = 0xc6,		// YMSG13
		*/

		default:
			kdDebug(YAHOO_RAW_DEBUG) << "  Parsed packet service -  This means an unknown service " << servicenum << endl;
		break;
	}

	statusnum = yahoo_get32(packet.data() + pos);
	pos += 4;

	switch (statusnum)
	{
		// TODO add remaining status
		case (Yahoo::StatusAvailable) :
			status = Yahoo::StatusAvailable;
		break;
		case (Yahoo::StatusBRB) :
			status = Yahoo::StatusBRB;
		break;
		case (Yahoo::StatusDisconnected) :
			status = Yahoo::StatusDisconnected;
		break;
		/*StatusBusy
		StatusNotAtHome
		StatusNotAtDesk
		StatusNotInOffice
		StatusOnPhone
		StatusOnVacation
		StatusOutToLunch
		StatusSteppedOut
		StatusInvisible
		StatusCustom
		StatusIdle
		StatusOffline
		StatusNotify*/
		default:
			kdDebug(YAHOO_RAW_DEBUG) << " - unknown status " << statusnum << endl;
		break;
	}

	sessionid = yahoo_get32(packet.data() + pos);
	kdDebug(YAHOO_RAW_DEBUG) << "  Parsed session id: " << (void *)sessionid << endl;
	pos += 4;

	kdDebug(YAHOO_RAW_DEBUG) << " Setting incoming transfer basic information." << endl;
	YMSGTransfer *t = new YMSGTransfer();
	t->setService(service);
	t->setId(sessionid);
	t->settqStatus(status);
	t->setPacketLength(len);

        TQString d = TQString::fromAscii( packet.data() + pos, packet.size() - pos );
        TQStringList list = TQStringList::split( "\xc0\x80", d );
        for( int i = 0; i+1 < list.size() && pos+1 < len+20; i += 2 ) {
                TQString key = list[i];
                TQString value = TQString::fromUtf8( list[i+1].ascii() );
                pos += key.utf8().length() + value.utf8().length() + 4;
                t->setParam( TQString(key).toInt(), value.utf8() );
                kdDebug(YAHOO_RAW_DEBUG) << k_funcinfo << "Key: " << key << " Value: " << value << endl;
        }

        while( pos < packet.size() && packet.data()[pos] == '\x00' )
                pos++;

// 	kdDebug(YAHOO_RAW_DEBUG) << " Returning transfer";
	// tell them we have parsed offset bytes

	bytes = pos;
	return t;
}

#include "ymsgprotocol.moc"