~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * xmpp.h - XMPP "core" library API
 
3
 * Copyright (C) 2003  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 XMPP_H
 
22
#define XMPP_H
 
23
 
 
24
#include <QPair>
 
25
#include <qobject.h>
 
26
#include <qstring.h>
 
27
#include <qhostaddress.h>
 
28
#include <qstring.h>
 
29
#include <qxml.h>
 
30
#include <qdom.h>
 
31
 
 
32
#include "xmpp/jid/jid.h"
 
33
#include "xmpp_stanza.h"
 
34
#include "xmpp_stream.h"
 
35
#include "xmpp_clientstream.h"
 
36
 
 
37
namespace QCA
 
38
{
 
39
        class TLS;
 
40
};
 
41
 
 
42
#ifndef CS_XMPP
 
43
class ByteStream;
 
44
#endif
 
45
 
 
46
#include <QtCrypto> // For QCA::SASL::Params
 
47
 
 
48
namespace XMPP
 
49
{
 
50
        // CS_IMPORT_BEGIN cutestuff/bytestream.h
 
51
#ifdef CS_XMPP
 
52
        class ByteStream;
 
53
#endif
 
54
        // CS_IMPORT_END
 
55
 
 
56
        class Debug
 
57
        {
 
58
        public:
 
59
                virtual ~Debug();
 
60
 
 
61
                virtual void msg(const QString &)=0;
 
62
                virtual void outgoingTag(const QString &)=0;
 
63
                virtual void incomingTag(const QString &)=0;
 
64
                virtual void outgoingXml(const QDomElement &)=0;
 
65
                virtual void incomingXml(const QDomElement &)=0;
 
66
        };
 
67
 
 
68
        void setDebug(Debug *);
 
69
 
 
70
        class Connector : public QObject
 
71
        {
 
72
                Q_OBJECT
 
73
        public:
 
74
                Connector(QObject *parent=0);
 
75
                virtual ~Connector();
 
76
 
 
77
                virtual void connectToServer(const QString &server)=0;
 
78
                virtual ByteStream *stream() const=0;
 
79
                virtual void done()=0;
 
80
 
 
81
                bool useSSL() const;
 
82
                bool havePeerAddress() const;
 
83
                QHostAddress peerAddress() const;
 
84
                quint16 peerPort() const;
 
85
 
 
86
                virtual QString host() const;
 
87
 
 
88
        signals:
 
89
                void connected();
 
90
                void error();
 
91
 
 
92
        protected:
 
93
                void setUseSSL(bool b);
 
94
                void setPeerAddressNone();
 
95
                void setPeerAddress(const QHostAddress &addr, quint16 port);
 
96
 
 
97
        private:
 
98
                bool ssl;
 
99
                bool haveaddr;
 
100
                QHostAddress addr;
 
101
                quint16 port;
 
102
        };
 
103
 
 
104
        class AdvancedConnector : public Connector
 
105
        {
 
106
                Q_OBJECT
 
107
        public:
 
108
                enum Error { ErrConnectionRefused, ErrHostNotFound, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth, ErrStream };
 
109
                AdvancedConnector(QObject *parent=0);
 
110
                virtual ~AdvancedConnector();
 
111
 
 
112
                class Proxy
 
113
                {
 
114
                public:
 
115
                        enum { None, HttpConnect, HttpPoll, Socks };
 
116
                        Proxy();
 
117
                        ~Proxy();
 
118
 
 
119
                        int type() const;
 
120
                        QString host() const;
 
121
                        quint16 port() const;
 
122
                        QString url() const;
 
123
                        QString user() const;
 
124
                        QString pass() const;
 
125
                        int pollInterval() const;
 
126
 
 
127
                        void setHttpConnect(const QString &host, quint16 port);
 
128
                        void setHttpPoll(const QString &host, quint16 port, const QString &url);
 
129
                        void setSocks(const QString &host, quint16 port);
 
130
                        void setUserPass(const QString &user, const QString &pass);
 
131
                        void setPollInterval(int secs);
 
132
 
 
133
                private:
 
134
                        int t;
 
135
                        QString v_host, v_url;
 
136
                        quint16 v_port;
 
137
                        QString v_user, v_pass;
 
138
                        int v_poll;
 
139
                };
 
140
 
 
141
                void setProxy(const Proxy &proxy);
 
142
                void setOptHostPort(const QString &host, quint16 port);
 
143
                void setOptHostsPort(const QStringList &hosts, quint16 port);
 
144
                void setOptProbe(bool);
 
145
                void setOptSSL(bool);
 
146
 
 
147
                void changePollInterval(int secs);
 
148
 
 
149
                void connectToServer(const QString &server);
 
150
                ByteStream *stream() const;
 
151
                void done();
 
152
 
 
153
                int errorCode() const;
 
154
 
 
155
                virtual QString host() const;
 
156
 
 
157
        signals:
 
158
                void srvLookup(const QString &server);
 
159
                void srvResult(bool success);
 
160
                void httpSyncStarted();
 
161
                void httpSyncFinished();
 
162
 
 
163
        private slots:
 
164
                void dns_done();
 
165
                void srv_done();
 
166
                void bs_connected();
 
167
                void bs_error(int);
 
168
                void http_syncStarted();
 
169
                void http_syncFinished();
 
170
                void t_timeout();
 
171
 
 
172
        private:
 
173
                class Private;
 
174
                Private *d;
 
175
 
 
176
                void cleanup();
 
177
                void do_resolve();
 
178
                void do_connect();
 
179
                void tryNextSrv();
 
180
        };
 
181
 
 
182
        class TLSHandler : public QObject
 
183
        {
 
184
                Q_OBJECT
 
185
        public:
 
186
                TLSHandler(QObject *parent=0);
 
187
                virtual ~TLSHandler();
 
188
 
 
189
                virtual void reset()=0;
 
190
                virtual void startClient(const QString &host)=0;
 
191
                virtual void write(const QByteArray &a)=0;
 
192
                virtual void writeIncoming(const QByteArray &a)=0;
 
193
 
 
194
        signals:
 
195
                void success();
 
196
                void fail();
 
197
                void closed();
 
198
                void readyRead(const QByteArray &a);
 
199
                void readyReadOutgoing(const QByteArray &a, int plainBytes);
 
200
        };
 
201
 
 
202
        class QCATLSHandler : public TLSHandler
 
203
        {
 
204
                Q_OBJECT
 
205
        public:
 
206
                QCATLSHandler(QCA::TLS *parent);
 
207
                ~QCATLSHandler();
 
208
 
 
209
                QCA::TLS *tls() const;
 
210
                int tlsError() const;
 
211
 
 
212
                void setXMPPCertCheck(bool enable);
 
213
                bool XMPPCertCheck();
 
214
                bool certMatchesHostname();
 
215
 
 
216
                void reset();
 
217
                void startClient(const QString &host);
 
218
                void write(const QByteArray &a);
 
219
                void writeIncoming(const QByteArray &a);
 
220
 
 
221
        signals:
 
222
                void tlsHandshaken();
 
223
 
 
224
        public slots:
 
225
                void continueAfterHandshake();
 
226
 
 
227
        private slots:
 
228
                void tls_handshaken();
 
229
                void tls_readyRead();
 
230
                void tls_readyReadOutgoing();
 
231
                void tls_closed();
 
232
                void tls_error();
 
233
 
 
234
        private:
 
235
                class Private;
 
236
                Private *d;
 
237
        };
 
238
};
 
239
 
 
240
#endif