~ubuntu-branches/ubuntu/hoary/psi/hoary

« back to all changes in this revision

Viewing changes to iris/xmpp-core/xmlprotocol.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xmlprotocol.h - state machine for 'jabber-like' protocols
 
3
 * Copyright (C) 2004  Justin Karneges
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef XMLPROTOCOL_H
 
22
#define XMLPROTOCOL_H
 
23
 
 
24
#include<qdom.h>
 
25
#include<qvaluelist.h>
 
26
#include"parser.h"
 
27
 
 
28
#define NS_XML "http://www.w3.org/XML/1998/namespace"
 
29
 
 
30
namespace XMPP
 
31
{
 
32
        class XmlProtocol
 
33
        {
 
34
        public:
 
35
                enum Need {
 
36
                        NNotify,      // need a data send and/or recv update
 
37
                        NCustom = 10
 
38
                };
 
39
                enum Event {
 
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
 
45
                        ECustom = 10
 
46
                };
 
47
                enum Error {
 
48
                        ErrParse,     // there was an error parsing the xml
 
49
                        ErrCustom = 10
 
50
                };
 
51
                enum Notify {
 
52
                        NSend = 0x01, // need to know if data has been written
 
53
                        NRecv = 0x02  // need incoming data
 
54
                };
 
55
 
 
56
                XmlProtocol();
 
57
                virtual ~XmlProtocol();
 
58
 
 
59
                virtual void reset();
 
60
 
 
61
                // byte I/O for the stream
 
62
                void addIncomingData(const QByteArray &);
 
63
                QByteArray takeOutgoingData();
 
64
                void outgoingDataWritten(int);
 
65
 
 
66
                // advance the state machine
 
67
                bool processStep();
 
68
 
 
69
                // set these before returning from a step
 
70
                int need, event, errorCode, notify;
 
71
 
 
72
                inline bool isIncoming() const { return incoming; }
 
73
                QString xmlEncoding() const;
 
74
                QString elementToString(const QDomElement &e, bool clip=false);
 
75
 
 
76
                class TransferItem
 
77
                {
 
78
                public:
 
79
                        TransferItem();
 
80
                        TransferItem(const QString &str, bool sent, bool external=false);
 
81
                        TransferItem(const QDomElement &elem, bool sent, bool external=false);
 
82
 
 
83
                        bool isSent; // else, received
 
84
                        bool isString; // else, is element
 
85
                        bool isExternal; // not owned by protocol
 
86
                        QString str;
 
87
                        QDomElement elem;
 
88
                };
 
89
                QValueList<TransferItem> transferItemList;
 
90
                void setIncomingAsExternal();
 
91
 
 
92
        protected:
 
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);
 
101
 
 
102
                // 'debug'
 
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);
 
107
 
 
108
                void startConnect();
 
109
                void startAccept();
 
110
                bool close();
 
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();
 
114
 
 
115
        private:
 
116
                enum { SendOpen, RecvOpen, Open, Closing };
 
117
                class TrackItem
 
118
                {
 
119
                public:
 
120
                        enum Type { Raw, Close, Custom };
 
121
                        int type, id, size;
 
122
                };
 
123
 
 
124
                bool incoming;
 
125
                QDomDocument elemDoc;
 
126
                QDomElement elem;
 
127
                QString tagOpen, tagClose;
 
128
                int state;
 
129
                bool peerClosed;
 
130
                bool closeWritten;
 
131
 
 
132
                Parser xml;
 
133
                QByteArray outData;
 
134
                QValueList<TrackItem> trackQueue;
 
135
 
 
136
                void init();
 
137
                int internalWriteData(const QByteArray &a, TrackItem::Type t, int id=-1);
 
138
                int internalWriteString(const QString &s, TrackItem::Type t, int id=-1);
 
139
                void sendTagOpen();
 
140
                void sendTagClose();
 
141
                bool baseStep(const Parser::Event &pe);
 
142
        };
 
143
}
 
144
 
 
145
#endif