blob: 708ebb855a7b05c8a14ac6ec765190e7b180bb0b (
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
|
/*
Kopete Oscar Protocol
snacprotocol.cpp - reads the protocol used by Oscar for signalling stuff
Copyright (c) 2004 Matt Rogers <mattr@kde.org>
Based on code copyright (c) 2004 SUSE Linux AG <http://www.suse.com>
Kopete (c) 2002-2004 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 "snacprotocol.h"
#include <tqcstring.h>
#include <tqdatastream.h>
#include <tqobject.h>
#include <kdebug.h>
#include <stdlib.h>
#include "transfer.h"
using namespace Oscar;
SnacProtocol::SnacProtocol(TQObject *parent, const char *name)
: InputProtocolBase(parent, name)
{
}
SnacProtocol::~SnacProtocol()
{
}
Transfer* SnacProtocol::parse( const TQByteArray & packet, uint& bytes )
{
BYTE b;
WORD w;
DWORD dw;
FLAP f;
SNAC s;
SnacTransfer *st;
TQDataStream* m_din = new TQDataStream( packet, IO_ReadOnly );
//flap parsing
*m_din >> b; //this should be the start byte
//kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "start byte is " << b << endl;
*m_din >> b;
f.channel = b;
*m_din >> w;
f.sequence = w;
*m_din >> w;
f.length = w;
if ( ( f.length + 6 ) > packet.size() )
{
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "Packet not big enough to parse!" << endl;
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "packet size is " << packet.size()
<< " we need " << f.length + 6 << endl;
return 0;
}
//snac parsing
*m_din >> w;
s.family = w;
*m_din >> w;
s.subtype = w;
*m_din >> w;
s.flags = w;
*m_din >> dw;
s.id = dw;
kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "family: " << s.family
<< " subtype: " << s.subtype << " flags: " << s.flags
<< " id: " << s.id << endl;
//use pointer arithmatic to skip the flap and snac headers
//so we don't have to do double parsing in the tasks
char* charPacket = const_cast<char*>(packet.data());
char* snacData;
int snacOffset = 10; //default
if ( s.flags >= 0x8000 ) //skip the next 8 bytes, we don't care about the snac version ATM
{
//kdDebug(OSCAR_RAW_DEBUG) << k_funcinfo << "skipping snac version" << endl;
snacOffset = 18;
snacData = charPacket + 24;
}
else
{
snacOffset = 10;
snacData = charPacket + 16;
}
Buffer *snacBuffer = new Buffer( snacData, f.length - snacOffset );
st = new SnacTransfer( f, s, snacBuffer );
bytes = f.length + 6;
delete m_din;
m_din = 0;
return st;
}
#include "snacprotocol.moc"
|