2
Kopete Groupwise Protocol
3
inputprotocolbase.cpp - Ancestor of all protocols used for reading GroupWise input
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
*************************************************************************
19
#include "inputprotocolbase.h"
21
#include <QDataStream>
23
InputProtocolBase::InputProtocolBase(QObject *parent)
31
InputProtocolBase::~InputProtocolBase()
35
uint InputProtocolBase::state() const
40
bool InputProtocolBase::readString( QString &message )
44
if ( !safeReadBytes( rawData, len ) )
46
message = QString::fromUtf8( rawData.data(), len - 1 );
51
bool InputProtocolBase::okToProceed()
58
qDebug( "InputProtocol::okToProceed() - Server message ended prematurely!" );
66
bool InputProtocolBase::safeReadBytes( QByteArray& data, uint & len )
68
// read the length of the bytes
73
m_bytes += sizeof( quint32 );
76
//qDebug( "EventProtocol::safeReadBytes() - expecting %i bytes", val );
83
// if the server splits packets here we are in trouble,
84
// as there is no way to see how much data was actually read
85
m_din->readRawData( temp.data(), val );
86
// the rest of the string will be filled with FF,
87
// so look for that in the last position instead of \0
88
// this caused a crash - guessing that temp.length() is set to the number of bytes actually read...
89
// if ( (quint8)( * ( temp.data() + ( temp.length() - 1 ) ) ) == 0xFF )
90
if ( (uint)temp.length() < ( val - 1 ) )
92
qDebug( "InputProtocol::safeReadBytes() - string broke, giving up, only got: %i bytes out of %i", temp.length(), val );
103
#include "inputprotocolbase.moc"