2
* xmpp.h - XMPP "core" library API
3
* Copyright (C) 2003 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
26
#include<qhostaddress.h>
43
// CS_IMPORT_BEGIN cutestuff/bytestream.h
54
virtual void msg(const QString &)=0;
55
virtual void outgoingTag(const QString &)=0;
56
virtual void incomingTag(const QString &)=0;
57
virtual void outgoingXml(const QDomElement &)=0;
58
virtual void incomingXml(const QDomElement &)=0;
61
void setDebug(Debug *);
63
class Connector : public QObject
67
Connector(QObject *parent=0);
70
virtual void connectToServer(const QString &server)=0;
71
virtual ByteStream *stream() const=0;
72
virtual void done()=0;
75
bool havePeerAddress() const;
76
QHostAddress peerAddress() const;
77
Q_UINT16 peerPort() const;
84
void setUseSSL(bool b);
85
void setPeerAddressNone();
86
void setPeerAddress(const QHostAddress &addr, Q_UINT16 port);
95
class AdvancedConnector : public Connector
99
enum Error { ErrConnectionRefused, ErrHostNotFound, ErrProxyConnect, ErrProxyNeg, ErrProxyAuth, ErrStream };
100
AdvancedConnector(QObject *parent=0);
101
virtual ~AdvancedConnector();
106
enum { None, HttpConnect, HttpPoll, Socks };
111
QString host() const;
112
Q_UINT16 port() const;
114
QString user() const;
115
QString pass() const;
116
int pollInterval() const;
118
void setHttpConnect(const QString &host, Q_UINT16 port);
119
void setHttpPoll(const QString &host, Q_UINT16 port, const QString &url);
120
void setSocks(const QString &host, Q_UINT16 port);
121
void setUserPass(const QString &user, const QString &pass);
122
void setPollInterval(int secs);
126
QString v_host, v_url;
128
QString v_user, v_pass;
132
void setProxy(const Proxy &proxy);
133
void setOptHostPort(const QString &host, Q_UINT16 port);
134
void setOptProbe(bool);
135
void setOptSSL(bool);
137
void changePollInterval(int secs);
139
void connectToServer(const QString &server);
140
ByteStream *stream() const;
143
int errorCode() const;
146
void srvLookup(const QString &server);
147
void srvResult(bool success);
148
void httpSyncStarted();
149
void httpSyncFinished();
156
void http_syncStarted();
157
void http_syncFinished();
169
class TLSHandler : public QObject
173
TLSHandler(QObject *parent=0);
174
virtual ~TLSHandler();
176
virtual void reset()=0;
177
virtual void startClient(const QString &host)=0;
178
virtual void write(const QByteArray &a)=0;
179
virtual void writeIncoming(const QByteArray &a)=0;
185
void readyRead(const QByteArray &a);
186
void readyReadOutgoing(const QByteArray &a, int plainBytes);
189
class QCATLSHandler : public TLSHandler
193
QCATLSHandler(QCA::TLS *parent);
196
QCA::TLS *tls() const;
197
int tlsError() const;
200
void startClient(const QString &host);
201
void write(const QByteArray &a);
202
void writeIncoming(const QByteArray &a);
205
void tlsHandshaken();
208
void continueAfterHandshake();
211
void tls_handshaken();
212
void tls_readyRead();
213
void tls_readyReadOutgoing(int);
228
Jid(const QString &s);
230
Jid & operator=(const QString &s);
231
Jid & operator=(const char *s);
233
void set(const QString &s);
234
void set(const QString &domain, const QString &node, const QString &resource="");
236
void setDomain(const QString &s);
237
void setNode(const QString &s);
238
void setResource(const QString &s);
240
const QString & domain() const { return d; }
241
const QString & node() const { return n; }
242
const QString & resource() const { return r; }
243
const QString & bare() const { return b; }
244
const QString & full() const { return f; }
246
Jid withNode(const QString &s) const;
247
Jid withResource(const QString &s) const;
249
bool isValid() const;
250
bool isEmpty() const;
251
bool compare(const Jid &a, bool compareRes=true) const;
253
static bool validDomain(const QString &s, QString *norm=0);
254
static bool validNode(const QString &s, QString *norm=0);
255
static bool validResource(const QString &s, QString *norm=0);
257
// TODO: kill these later
258
const QString & host() const { return d; }
259
const QString & user() const { return n; }
260
const QString & userHost() const { return b; }
266
QString f, b, d, n, r;
274
enum Kind { Message, Presence, IQ };
275
enum ErrorType { Cancel, Continue, Modify, Auth, Wait };
280
FeatureNotImplemented,
287
RecipientUnavailable,
288
RegistrationRequired,
293
SubscriptionRequired,
299
Stanza(const Stanza &from);
300
Stanza & operator=(const Stanza &from);
306
Error(int type=Cancel, int condition=UndefinedCondition, const QString &text="", const QDomElement &appSpec=QDomElement());
316
QDomElement element() const;
317
QString toString() const;
319
QDomDocument & doc() const;
320
QString baseNS() const;
321
QDomElement createElement(const QString &ns, const QString &tagName);
322
QDomElement createTextElement(const QString &ns, const QString &tagName, const QString &text);
323
void appendChild(const QDomElement &e);
326
void setKind(Kind k);
331
QString type() const;
332
QString lang() const;
334
void setTo(const Jid &j);
335
void setFrom(const Jid &j);
336
void setId(const QString &id);
337
void setType(const QString &type);
338
void setLang(const QString &lang);
341
void setError(const Error &err);
346
Stanza(Stream *s, Kind k, const Jid &to, const QString &type, const QString &id);
347
Stanza(Stream *s, const QDomElement &e);
353
class Stream : public QObject
357
enum Error { ErrParse, ErrProtocol, ErrStream, ErrCustom = 10 };
370
Stream(QObject *parent=0);
373
virtual QDomDocument & doc() const=0;
374
virtual QString baseNS() const=0;
375
virtual bool old() const=0;
377
virtual void close()=0;
378
virtual bool stanzaAvailable() const=0;
379
virtual Stanza read()=0;
380
virtual void write(const Stanza &s)=0;
382
virtual int errorCondition() const=0;
383
virtual QString errorText() const=0;
384
virtual QDomElement errorAppSpec() const=0;
386
Stanza createStanza(Stanza::Kind k, const Jid &to="", const QString &type="", const QString &id="");
387
Stanza createStanza(const QDomElement &e);
389
static QString xmlToString(const QDomElement &e, bool clip=false);
392
void connectionClosed();
393
void delayedCloseFinished();
395
void stanzaWritten();
399
class ClientStream : public Stream
404
ErrConnection = ErrCustom, // Connection error, ask Connector-subclass what's up
405
ErrNeg, // Negotiation error, see condition
406
ErrTLS, // TLS error, see condition
407
ErrAuth, // Auth error, see condition
408
ErrSecurityLayer, // broken SASL security layer
409
ErrBind // Resource binding error
412
WarnOldVersion, // server uses older XMPP/Jabber "0.9" protocol
413
WarnNoTLS // there is no chance for TLS at this point
416
HostGone, // host no longer hosted
417
HostUnknown, // unknown host
418
RemoteConnectionFailed, // unable to connect to a required remote resource
419
SeeOtherHost, // a 'redirect', see errorText() for other host
420
UnsupportedVersion // unsupported XMPP version
423
TLSStart, // server rejected STARTTLS
424
TLSFail // TLS failed, ask TLSHandler-subclass what's up
431
GenericAuthError, // all-purpose "can't login" error
432
NoMech, // No appropriate auth mech available
433
BadProto, // Bad SASL auth protocol
434
BadServ, // Server failed mutual auth
435
EncryptionRequired, // can't use mech without TLS
436
InvalidAuthzid, // bad input JID
437
InvalidMech, // bad mechanism
438
InvalidRealm, // bad realm
439
MechTooWeak, // can't use mech with this authzid
440
NotAuthorized, // bad user, bad password, bad creditials
441
TemporaryAuthFailure // please try again later!
444
BindNotAllowed, // not allowed to bind a resource
445
BindConflict // resource in-use
448
ClientStream(Connector *conn, TLSHandler *tlsHandler=0, QObject *parent=0);
449
ClientStream(const QString &host, const QString &defRealm, ByteStream *bs, QCA::TLS *tls=0, QObject *parent=0); // server
453
void connectToServer(const Jid &jid, bool auth=true);
454
void accept(); // server
455
bool isActive() const;
456
bool isAuthenticated() const;
459
void setUsername(const QString &s);
460
void setPassword(const QString &s);
461
void setRealm(const QString &s);
462
void continueAfterParams();
465
QString saslMechanism() const;
469
void setResourceBinding(bool);
471
// security options (old protocol only uses the first !)
472
void setAllowPlain(bool);
473
void setRequireMutualAuth(bool);
474
void setSSFRange(int low, int high);
475
void setOldOnly(bool);
476
void setSASLMechanism(const QString &s);
477
void setLocalAddr(const QHostAddress &addr, Q_UINT16 port);
480
QDomDocument & doc() const;
481
QString baseNS() const;
485
bool stanzaAvailable() const;
487
void write(const Stanza &s);
489
int errorCondition() const;
490
QString errorText() const;
491
QDomElement errorAppSpec() const;
494
void writeDirect(const QString &s);
495
void setNoopTime(int mills);
499
void securityLayerActivated(int);
500
void needAuthParams(bool user, bool pass, bool realm);
501
void authenticated();
503
void incomingXml(const QString &s);
504
void outgoingXml(const QString &s);
507
void continueAfterWarning();
513
void bs_connectionClosed();
514
void bs_delayedCloseFinished();
515
void bs_error(int); // server only
518
void ss_bytesWritten(int);
519
void ss_tlsHandshaken();
523
void sasl_clientFirstStep(const QString &mech, const QByteArray *clientInit);
524
void sasl_nextStep(const QByteArray &stepData);
525
void sasl_needParams(bool user, bool authzid, bool pass, bool realm);
526
void sasl_authCheck(const QString &user, const QString &authzid);
527
void sasl_authenticated();
528
void sasl_error(int);
537
void reset(bool all=false);
539
int convertedSASLCond() const;
542
void srvProcessNext();