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
25
#include<qvaluelist.h>
28
#define NS_XML "http://www.w3.org/XML/1998/namespace"
36
NNotify, // need a data send and/or recv update
40
EError, // unrecoverable error, see errorCode for details
41
ESend, // data needs to be sent, use takeOutgoingData()
42
ERecvOpen, // breakpoint after root element open tag is received
43
EPeerClosed, // root element close tag received
44
EClosed, // finished closing
48
ErrParse, // there was an error parsing the xml
52
NSend = 0x01, // need to know if data has been written
53
NRecv = 0x02 // need incoming data
57
virtual ~XmlProtocol();
61
// byte I/O for the stream
62
void addIncomingData(const QByteArray &);
63
QByteArray takeOutgoingData();
64
void outgoingDataWritten(int);
66
// advance the state machine
69
// set these before returning from a step
70
int need, event, errorCode, notify;
72
inline bool isIncoming() const { return incoming; }
73
QString xmlEncoding() const;
74
QString elementToString(const QDomElement &e, bool clip=false);
80
TransferItem(const QString &str, bool sent, bool external=false);
81
TransferItem(const QDomElement &elem, bool sent, bool external=false);
83
bool isSent; // else, received
84
bool isString; // else, is element
85
bool isExternal; // not owned by protocol
89
QValueList<TransferItem> transferItemList;
90
void setIncomingAsExternal();
93
virtual QDomElement docElement()=0;
94
virtual void handleDocOpen(const Parser::Event &pe)=0;
95
virtual bool handleError()=0;
96
virtual bool handleCloseFinished()=0;
97
virtual bool stepAdvancesParser() const=0;
98
virtual bool stepRequiresElement() const;
99
virtual bool doStep(const QDomElement &e)=0;
100
virtual void itemWritten(int id, int size);
103
virtual void stringSend(const QString &s);
104
virtual void stringRecv(const QString &s);
105
virtual void elementSend(const QDomElement &e);
106
virtual void elementRecv(const QDomElement &e);
111
int writeString(const QString &s, int id, bool external);
112
int writeElement(const QDomElement &e, int id, bool external, bool clip=false);
113
QByteArray resetStream();
116
enum { SendOpen, RecvOpen, Open, Closing };
120
enum Type { Raw, Close, Custom };
125
QDomDocument elemDoc;
127
QString tagOpen, tagClose;
134
QValueList<TrackItem> trackQueue;
137
int internalWriteData(const QByteArray &a, TrackItem::Type t, int id=-1);
138
int internalWriteString(const QString &s, TrackItem::Type t, int id=-1);
141
bool baseStep(const Parser::Event &pe);