1
/****************************************************************************
2
** jabstream.h - handles a Jabber XML stream
3
** Copyright (C) 2001, 2002 Justin Karneges
5
** This program is free software; you can redistribute it and/or
6
** modify it under the terms of the GNU General Public License
7
** as published by the Free Software Foundation; either version 2
8
** of the License, or (at your option) any later version.
10
** This program 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
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
19
****************************************************************************/
35
#define JABSTREAM_ERR_DNS 0
36
#define JABSTREAM_ERR_CONNREFUSED 1
37
#define JABSTREAM_ERR_CONNTIMEOUT 2
38
#define JABSTREAM_ERR_DISC 3
39
#define JABSTREAM_ERR_SOCKET 4
40
#define JABSTREAM_ERR_HANDSHAKE 5
43
/****************************************************************************
46
This class handles a Jabber XML stream. It collects XML data into
47
QDomElements and signals the chunks back to the caller. There is no
48
actual Jabber logic in this class. It simply takes care of XML and
54
stream.connectToHost("jabber.org", 5222");
56
The class communicates back to you via signals:
58
connected() - connection success
59
error(int) - connection/stream error
60
packetReady(const QDomElement &) - new XML chunk ready
62
****************************************************************************/
64
class JabXmlHandler : public QObject, public QXmlDefaultHandler
68
JabXmlHandler(QDomDocument *);
70
// Xml functions (reimplemented)
72
bool startElement(const QString &, const QString &, const QString &, const QXmlAttributes &);
73
bool endElement(const QString &, const QString &, const QString &);
74
bool characters(const QString &);
76
QString toLower(QString s);
79
void packetReady(const QDomElement &);
80
void handshake(bool, const QString &);
83
QString indent, characterData;
86
QDomElement chunk, current;
90
class JabStream : public QObject
97
void connectToHost(const QString &host, int port);
99
bool isConnected() { return v_isHandShaken; }
100
QString id() { return v_id; }
104
bool isSSLSupported();
105
bool isSSLEnabled() { return use_ssl; }
106
void setSSLEnabled(bool);
108
static QCString encodeXML(QString);
109
static QCString elemToString(const QDomElement &);
114
void receivePacket(const QDomElement &);
117
void sendPacket(const QDomElement &);
118
void sendString(const QCString &);
122
void sock_connected();
123
void sock_disconnected();
124
void sock_readyRead();
125
void sock_error(int);
128
void ssl_outgoingReady();
129
void ssl_readyRead();
132
// delayed functions so we can "get out" of a QSocket slot before continuing
133
void delayedProcessError();
134
void delayedProcessReceived();
135
void delayedProcessHandShake();
137
// prevent NAT/connection timeouts
140
// JabXmlHandler slots
141
void packetReady(const QDomElement &);
142
void handshake(bool, const QString &);
148
QXmlInputSource *src;
149
QXmlSimpleReader *reader;
150
JabXmlHandler *handler;
153
bool v_isConnected, v_isHandShaken, first_time;
163
QPtrQueue<QDomElement> in;
165
void processIncomingData(const QByteArray &);