2
* xmlprotocol.h - state machine for 'jabber-like' protocols
3
* Copyright (C) 2004 Justin Karneges
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
#define NS_XML "http://www.w3.org/XML/1998/namespace"
33
class XmlProtocol : public QObject
37
NNotify, // need a data send and/or recv update
41
EError, // unrecoverable error, see errorCode for details
42
ESend, // data needs to be sent, use takeOutgoingData()
43
ERecvOpen, // breakpoint after root element open tag is received
44
EPeerClosed, // root element close tag received
45
EClosed, // finished closing
49
ErrParse, // there was an error parsing the xml
53
NSend = 0x01, // need to know if data has been written
54
NRecv = 0x02 // need incoming data
58
virtual ~XmlProtocol();
62
// byte I/O for the stream
63
void addIncomingData(const QByteArray &);
64
QByteArray takeOutgoingData();
65
void outgoingDataWritten(int);
67
// advance the state machine
70
// set these before returning from a step
71
int need, event, errorCode, notify;
73
inline bool isIncoming() const { return incoming; }
74
QString xmlEncoding() const;
75
QString elementToString(const QDomElement &e, bool clip=false);
81
TransferItem(const QString &str, bool sent, bool external=false);
82
TransferItem(const QDomElement &elem, bool sent, bool external=false);
84
bool isSent; // else, received
85
bool isString; // else, is element
86
bool isExternal; // not owned by protocol
90
QList<TransferItem> transferItemList;
91
void setIncomingAsExternal();
94
virtual QDomElement docElement()=0;
95
virtual void handleDocOpen(const Parser::Event &pe)=0;
96
virtual bool handleError()=0;
97
virtual bool handleCloseFinished()=0;
98
virtual bool stepAdvancesParser() const=0;
99
virtual bool stepRequiresElement() const;
100
virtual bool doStep(const QDomElement &e)=0;
101
virtual void itemWritten(int id, int size);
104
virtual void stringSend(const QString &s);
105
virtual void stringRecv(const QString &s);
106
virtual void elementSend(const QDomElement &e);
107
virtual void elementRecv(const QDomElement &e);
112
int writeString(const QString &s, int id, bool external);
113
int writeElement(const QDomElement &e, int id, bool external, bool clip=false);
114
QByteArray resetStream();
117
enum { SendOpen, RecvOpen, Open, Closing };
121
enum Type { Raw, Close, Custom };
126
QDomDocument elemDoc;
128
QString tagOpen, tagClose;
135
QList<TrackItem> trackQueue;
138
int internalWriteData(const QByteArray &a, TrackItem::Type t, int id=-1);
139
int internalWriteString(const QString &s, TrackItem::Type t, int id=-1);
142
bool baseStep(const Parser::Event &pe);