Port things from MSN to WLM plugin:
[kdenetwork.git] / kopete / protocols / groupwise / libgroupwise / eventprotocol.cpp
blob40c90e387593dccd9b0f944eb181e8429be1709a
1 /*
2 Kopete Groupwise Protocol
3 eventprotocol.cpp - reads the protocol used by GroupWise for signalling Events
5 Copyright (c) 2004 SUSE Linux AG http://www.suse.com
7 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
9 *************************************************************************
10 * *
11 * This library is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU Lesser General Public *
13 * License as published by the Free Software Foundation; either *
14 * version 2 of the License, or (at your option) any later version. *
15 * *
16 *************************************************************************
19 #include <qbuffer.h>
21 #include "gwerror.h"
23 #include "eventtransfer.h"
24 #include "eventprotocol.h"
26 using namespace GroupWise;
28 EventProtocol::EventProtocol(QObject *parent)
29 : InputProtocolBase(parent)
33 EventProtocol::~EventProtocol()
37 Transfer * EventProtocol::parse( QByteArray & wire, uint& bytes )
39 m_bytes = 0;
40 //m_din = new QDataStream( wire, QIODevice::ReadOnly );
41 QBuffer inBuf( &wire );
42 inBuf.open( QIODevice::ReadOnly);
43 m_din.setDevice( &inBuf );
44 m_din.setByteOrder( QDataStream::LittleEndian );
45 quint32 type;
47 if ( !okToProceed() )
49 m_din.unsetDevice();
50 return 0;
52 // read the event type
53 m_din >> type;
54 m_bytes += sizeof( quint32 );
56 debug( QString( "EventProtocol::parse() Reading event of type %1" ).arg( type ) );
57 if ( type > Stop )
59 debug( QString ( "EventProtocol::parse() - found unexpected event type %1 - assuming out of sync" ).arg( type ) );
60 m_state = OutOfSync;
61 return 0;
64 // read the event source
65 QString source;
66 if ( !readString( source ) )
68 m_din.unsetDevice();
69 return 0;
72 // now create an event object
73 //HACK: lowercased DN
74 EventTransfer * tentative = new EventTransfer( type, source.toLower(), QDateTime::currentDateTime() );
76 // add any additional data depending on the type of event
77 // Note: if there are any errors in the way the data is read below, we will soon be OutOfSync
78 QString statusText;
79 QString guid;
80 quint16 status;
81 quint32 flags;
82 QString message;
84 switch ( type )
86 case StatusChange: //103 - STATUS + STATUSTEXT
87 if ( !okToProceed() )
89 m_din.unsetDevice();
90 return 0;
92 m_din >> status;
93 m_bytes += sizeof( quint16 );
94 if ( !readString( statusText ) )
96 m_din.unsetDevice();
97 return 0;
99 debug( QString( "got status: %1").arg( status ) );
100 tentative->setStatus( status );
101 debug( QString( "tentative status: %1").arg( tentative->status() ) );
102 tentative->setStatusText( statusText );
103 break;
104 case ConferenceJoined: // 106 - GUID + FLAGS
105 case ConferenceLeft: // 107
106 if ( !readString( guid ) )
108 m_din.unsetDevice();
109 return 0;
111 tentative->setGuid( guid );
112 if ( !readFlags( flags ) )
114 m_din.unsetDevice();
115 return 0;
117 tentative->setFlags( flags );
118 break;
119 case UndeliverableStatus: //102 - GUID
120 case ConferenceClosed: //105
121 case ConferenceInviteNotify://118
122 case ConferenceReject: //119
123 case UserTyping: //112
124 case UserNotTyping: //113
125 if ( !readString( guid ) )
127 m_din.unsetDevice();
128 return 0;
130 tentative->setGuid( guid );
131 break;
132 case ReceiveAutoReply: //121 - GUID + FLAGS + MESSAGE
133 case ReceiveMessage: //108
134 // guid
135 if ( !readString( guid ) )
137 m_din.unsetDevice();
138 return 0;
140 tentative->setGuid( guid );
141 // flags
142 if ( !readFlags( flags ) )
144 m_din.unsetDevice();
145 return 0;
147 tentative->setFlags( flags );
148 // message
149 if ( !readString( message ) )
151 m_din.unsetDevice();
152 return 0;
154 tentative->setMessage( message );
155 break;
156 case ConferenceInvite: //117 GUID + MESSAGE
157 // guid
158 if ( !readString( guid ) )
160 m_din.unsetDevice();
161 return 0;
163 tentative->setGuid( guid );
164 // message
165 if ( !readString( message ) )
167 m_din.unsetDevice();
168 return 0;
170 tentative->setMessage( message );
171 break;
172 case UserDisconnect: //114 (NOTHING)
173 case ServerDisconnect: //115
174 // nothing else to read
175 break;
176 case InvalidRecipient: //101
177 case ContactAdd: //104
178 case ReceiveFile: //109
179 case ConferenceRename: //116
180 // unhandled because unhandled in Gaim
181 break;
182 /* GW7 */
183 case ReceivedBroadcast: //122
184 case ReceivedSystemBroadcast: //123
185 // message
186 if ( !readString( message ) )
188 m_din.unsetDevice();
189 return 0;
191 tentative->setMessage( message );
192 break;
193 default:
194 debug( QString( "EventProtocol::parse() - found unexpected event type %1" ).arg( type ) );
195 break;
197 // if we got this far, the parse succeeded, return the Transfer
198 m_state = Success;
199 //delete m_din;
200 bytes = m_bytes;
201 m_din.unsetDevice();
202 return tentative;
205 bool EventProtocol::readFlags( quint32 &flags)
207 if ( okToProceed() )
209 m_din >> flags;
210 m_bytes += sizeof( quint32 );
211 return true;
213 return false;
216 #include "eventprotocol.moc"