blob: b6ff646d46b78aabf4522306fe820143cfde3ed4 (
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
|
/*
Kopete Groupwise Protocol
eventprotocol.cpp - reads the protocol used by GroupWise for signalling Events
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 <tqbuffer.h>
#include "gwerror.h"
#include "eventtransfer.h"
#include "eventprotocol.h"
using namespace GroupWise;
EventProtocol::EventProtocol(TQObject *parent, const char *name)
: InputProtocolBase(parent, name)
{
}
EventProtocol::~EventProtocol()
{
}
Transfer * EventProtocol::parse( const TQByteArray & wire, uint& bytes )
{
m_bytes = 0;
//m_din = new TQDataStream( wire, IO_ReadOnly );
TQBuffer inBuf( wire );
inBuf.open( IO_ReadOnly);
m_din.setDevice( &inBuf );
m_din.setByteOrder( TQDataStream::LittleEndian );
TQ_UINT32 type;
if ( !okToProceed() )
{
m_din.unsetDevice();
return 0;
}
// read the event type
m_din >> type;
m_bytes += sizeof( TQ_UINT32 );
debug( TQString( "EventProtocol::parse() Reading event of type %1" ).tqarg( type ) );
if ( type > Stop )
{
debug( TQString ( "EventProtocol::parse() - found unexpected event type %1 - assuming out of sync" ).tqarg( type ) );
m_state = OutOfSync;
return 0;
}
// read the event source
TQString source;
if ( !readString( source ) )
{
m_din.unsetDevice();
return 0;
}
// now create an event object
//HACK: lowercased DN
EventTransfer * tentative = new EventTransfer( type, source.lower(), TQDateTime::tqcurrentDateTime() );
// add any additional data depending on the type of event
// Note: if there are any errors in the way the data is read below, we will soon be OutOfSync
TQString statusText;
TQString guid;
TQ_UINT16 status;
TQ_UINT32 flags;
TQString message;
switch ( type )
{
case StatusChange: //103 - STATUS + STATUSTEXT
if ( !okToProceed() )
{
m_din.unsetDevice();
return 0;
}
m_din >> status;
m_bytes += sizeof( TQ_UINT16 );
if ( !readString( statusText ) )
{
m_din.unsetDevice();
return 0;
}
debug( TQString( "got status: %1").tqarg( status ) );
tentative->settqStatus( status );
debug( TQString( "tentative status: %1").tqarg( tentative->status() ) );
tentative->setStatusText( statusText );
break;
case ConferenceJoined: // 106 - GUID + FLAGS
case ConferenceLeft: // 107
if ( !readString( guid ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setGuid( guid );
if ( !readFlags( flags ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setFlags( flags );
break;
case UndeliverabletqStatus: //102 - GUID
case ConferenceClosed: //105
case ConferenceInviteNotify://118
case ConferenceReject: //119
case UserTyping: //112
case UserNotTyping: //113
if ( !readString( guid ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setGuid( guid );
break;
case ReceiveAutoReply: //121 - GUID + FLAGS + MESSAGE
case ReceiveMessage: //108
// guid
if ( !readString( guid ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setGuid( guid );
// flags
if ( !readFlags( flags ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setFlags( flags );
// message
if ( !readString( message ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setMessage( message );
break;
case ConferenceInvite: //117 GUID + MESSAGE
// guid
if ( !readString( guid ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setGuid( guid );
// message
if ( !readString( message ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setMessage( message );
break;
case UserDisconnect: //114 (NOTHING)
case ServerDisconnect: //115
// nothing else to read
break;
case InvalidRecipient: //101
case ContactAdd: //104
case ReceiveFile: //109
case ConferenceRename: //116
// unhandled because unhandled in Gaim
break;
/* GW7 */
case ReceivedBroadcast: //122
case ReceivedSystemBroadcast: //123
// message
if ( !readString( message ) )
{
m_din.unsetDevice();
return 0;
}
tentative->setMessage( message );
break;
default:
debug( TQString( "EventProtocol::parse() - found unexpected event type %1" ).tqarg( type ) );
break;
}
// if we got this far, the parse succeeded, return the Transfer
m_state = Success;
//delete m_din;
bytes = m_bytes;
m_din.unsetDevice();
return tentative;
}
bool EventProtocol::readFlags( TQ_UINT32 &flags)
{
if ( okToProceed() )
{
m_din >> flags;
m_bytes += sizeof( TQ_UINT32 );
return true;
}
return false;
}
#include "eventprotocol.moc"
|