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 *************************************************************************
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. *
16 *************************************************************************
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
)
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
);
52 // read the event type
54 m_bytes
+= sizeof( quint32
);
56 debug( QString( "EventProtocol::parse() Reading event of type %1" ).arg( type
) );
59 debug( QString ( "EventProtocol::parse() - found unexpected event type %1 - assuming out of sync" ).arg( type
) );
64 // read the event source
66 if ( !readString( source
) )
72 // now create an event object
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
86 case StatusChange
: //103 - STATUS + STATUSTEXT
93 m_bytes
+= sizeof( quint16
);
94 if ( !readString( statusText
) )
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
);
104 case ConferenceJoined
: // 106 - GUID + FLAGS
105 case ConferenceLeft
: // 107
106 if ( !readString( guid
) )
111 tentative
->setGuid( guid
);
112 if ( !readFlags( flags
) )
117 tentative
->setFlags( flags
);
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
) )
130 tentative
->setGuid( guid
);
132 case ReceiveAutoReply
: //121 - GUID + FLAGS + MESSAGE
133 case ReceiveMessage
: //108
135 if ( !readString( guid
) )
140 tentative
->setGuid( guid
);
142 if ( !readFlags( flags
) )
147 tentative
->setFlags( flags
);
149 if ( !readString( message
) )
154 tentative
->setMessage( message
);
156 case ConferenceInvite
: //117 GUID + MESSAGE
158 if ( !readString( guid
) )
163 tentative
->setGuid( guid
);
165 if ( !readString( message
) )
170 tentative
->setMessage( message
);
172 case UserDisconnect
: //114 (NOTHING)
173 case ServerDisconnect
: //115
174 // nothing else to read
176 case InvalidRecipient
: //101
177 case ContactAdd
: //104
178 case ReceiveFile
: //109
179 case ConferenceRename
: //116
180 // unhandled because unhandled in Gaim
183 case ReceivedBroadcast
: //122
184 case ReceivedSystemBroadcast
: //123
186 if ( !readString( message
) )
191 tentative
->setMessage( message
);
194 debug( QString( "EventProtocol::parse() - found unexpected event type %1" ).arg( type
) );
197 // if we got this far, the parse succeeded, return the Transfer
205 bool EventProtocol::readFlags( quint32
&flags
)
210 m_bytes
+= sizeof( quint32
);
216 #include "eventprotocol.moc"