~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

« back to all changes in this revision

Viewing changes to protocols/jabber/jabberclient.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:22:39 UTC
  • Revision ID: package-import@ubuntu.com-20130621022239-63l3zc8p0nf26pt6
Tags: upstream-4.10.80
ImportĀ upstreamĀ versionĀ 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/***************************************************************************
 
3
                jabberclient.h - Generic Jabber Client Class
 
4
                             -------------------
 
5
    begin                : Sat May 25 2005
 
6
    copyright            : (C) 2005 by Till Gerken <till@tantalo.net>
 
7
                           (C) 2006 by MichaĆ«l Larouche <larouche@kde.org>
 
8
 
 
9
    Copyright 2006 by Tommi Rantala <tommi.rantala@cs.helsinki.fi>
 
10
 
 
11
                           Kopete (C) 2001-2006 Kopete developers
 
12
                           <kopete-devel@kde.org>.
 
13
 ***************************************************************************/
 
14
 
 
15
/***************************************************************************
 
16
 *                                                                         *
 
17
 *   This program is free software; you can redistribute it and/or modify  *
 
18
 *   it under the terms of the GNU General Public License as published by  *
 
19
 *   the Free Software Foundation; either version 2 of the License, or     *
 
20
 *   (at your option) any later version.                                   *
 
21
 *                                                                         *
 
22
 ***************************************************************************/
 
23
 
 
24
#ifndef JABBERCLIENT_H
 
25
#define JABBERCLIENT_H
 
26
 
 
27
#include <qobject.h>
 
28
 
 
29
// include these because of namespace reasons
 
30
#include <im.h>
 
31
#include <xmpp.h>
 
32
#include <s5b.h>
 
33
 
 
34
#include <QtCrypto>
 
35
 
 
36
#include <kopete_export.h>
 
37
 
 
38
using namespace XMPP;
 
39
 
 
40
namespace XMPP { class PrivacyManager; }
 
41
 
 
42
/**
 
43
 * This class provides an interface to the Iris subsystem. The goal is to
 
44
 * abstract the Iris layer and manage it via a single, simple to use class.
 
45
 * By default, @ref JabberClient will attempt to establish a connection
 
46
 * using XMPP 1.0. This means that apart from the JID and password, no
 
47
 * further details are necessary to connect. The server and port will be
 
48
 * determined using a SRV lookup. If TLS is possible (meaning, the TLS
 
49
 * plugin is available and the server supports TLS) it will automatically
 
50
 * be used. Otherwise, a non-encrypted connection will be established.
 
51
 * If XMPP 1.0 is not possible, the connection will fall back to the old
 
52
 * protocol. By default, this connection is not encrypted. You can, however,
 
53
 * use @ref setUseSSL to immediately attempt an SSL connection. This is
 
54
 * most useful if you want to establish an SSL connection to a non-standard
 
55
 * port, in which case you will also have to use @ref setOverrideHost. In case
 
56
 * XMPP 1.0 does not work, an automatic attempt to connect to the standard port
 
57
 * 5223 with SSL can be made with @ref setProbeSSL. If the attempt is not
 
58
 * sucessful, the connection will fall back to an unencrypted attempt
 
59
 * at port 5222.
 
60
 * @brief Provides a Jabber client
 
61
 * @author Till Gerken
 
62
 */
 
63
class JABBER_EXPORT JabberClient : public QObject
 
64
{
 
65
 
 
66
Q_OBJECT
 
67
 
 
68
public:
 
69
        /**
 
70
         * Error codes indicating problems during operation.
 
71
         */
 
72
        enum ErrorCode
 
73
        {
 
74
                Ok,                                     /** No error. */
 
75
                InvalidPassword,        /** Password used to connect to the server was incorrect. */
 
76
                AlreadyConnected,       /** A new connection was attempted while the previous one hasn't been closed. */
 
77
                NoTLS,                          /** Use of TLS has been forced (see @ref forceTLS) but TLS is not available, either server- or client-side. */
 
78
                InvalidPasswordForMUC = 401,    /** A password is require to enter on this Multi-User Chat */
 
79
                NicknameConflict = 409,         /** There is already someone with that nick connected to the Multi-User Chat */
 
80
                BannedFromThisMUC = 403,        /** You can't join this Multi-User Chat because you were bannished */
 
81
                MaxUsersReachedForThisMuc = 503 /** You can't join this Multi-User Chat because it is full */
 
82
        };
 
83
 
 
84
        JabberClient();
 
85
        ~JabberClient();
 
86
 
 
87
        /**
 
88
         * Connect to a Jabber server.
 
89
         * @param jid JID to connect to.
 
90
         * @param password Password to authenticate with.
 
91
         * @param auth True if authentication should be done, false if not.
 
92
         */
 
93
        ErrorCode connect ( const XMPP::Jid &jid, const QString &password, bool auth = true );
 
94
 
 
95
        /**
 
96
         * Disconnect from Jabber server.
 
97
         */
 
98
        void disconnect ();
 
99
        
 
100
        /**
 
101
         * Disconnect from Jabber server with reason
 
102
         * @param reason The reason for disconnecting
 
103
         */
 
104
        void disconnect (XMPP::Status &reason);
 
105
 
 
106
        /**
 
107
         * Returns if this instance is connected to a server.
 
108
         */
 
109
        bool isConnected () const;
 
110
 
 
111
        /**
 
112
         * Returns the JID associated with this instance.
 
113
         */
 
114
        XMPP::Jid jid () const;
 
115
 
 
116
        /**
 
117
         * Set flag to ignore TLS warnings. If TLS
 
118
         * warnings are not ignored, the class will emit
 
119
         * @ref tlsWarning and wait for the user to
 
120
         * call @ref continueAfterTLSWarning or
 
121
         * @ref disconnect. Default is false.
 
122
         */
 
123
        void setIgnoreTLSWarnings ( bool flag );
 
124
        /**
 
125
         * Return if TLS warnings are being ignored.
 
126
         */
 
127
        bool ignoreTLSWarnings ();
 
128
 
 
129
        /**
 
130
         * Continue after a @ref tlsWarning signal.
 
131
         */
 
132
        void continueAfterTLSWarning ();
 
133
 
 
134
        /**
 
135
         * Set the port on which the S5B server should listen.
 
136
         * This is only taken into account if @ref setFileTransfersEnabled
 
137
         * is set to true.
 
138
         * @return True if port could be bound, false if not.
 
139
         */
 
140
        bool setS5BServerPort ( int port );
 
141
        /**
 
142
         * Returns the port the S5B server listens on.
 
143
         */
 
144
        int s5bServerPort () const;
 
145
 
 
146
        /**
 
147
         * Force the use of TLS. If TLS connections are forced,
 
148
         * unencrypted connections will not be established.
 
149
         * Default is false.
 
150
         */
 
151
        void setForceTLS ( bool flag );
 
152
        /**
 
153
         * Returns if TLS connections are forced.
 
154
         */
 
155
        bool forceTLS () const;
 
156
        
 
157
        /**
 
158
         * Force direct SSL connection, also for the
 
159
         * handshake. This is only useful if you know
 
160
         * the server supports it or you want to use
 
161
         * a non-standard port, in which case @ref setOverrideHost
 
162
         * will be useful. Default is false.
 
163
         */
 
164
        void setUseSSL ( bool flag );
 
165
        /**
 
166
         * Returns if an SSL connection attempt should be made.
 
167
         */
 
168
        bool useSSL () const;
 
169
 
 
170
        /**
 
171
         * Use only the old protocol (pre-XMPP 1.0). This should only
 
172
         * be used with servers not supporting XMPP 1.0 or with servers
 
173
         * that have a broken login procedure. Default is false. If
 
174
         * a connection attempt is not possible, Iris will automatically
 
175
         * fall back to the old protocol.
 
176
         */
 
177
        void setUseXMPP09 ( bool flag );
 
178
        /**
 
179
         * Returns if the old protocol should be used.
 
180
         */
 
181
        bool useXMPP09 () const;
 
182
 
 
183
        /**
 
184
         * Probe port 5223 if an SSL connection is possible. If
 
185
         * a connection is not possible, an unencrypted connection
 
186
         * will be attempted at port 5222. This is only meaningful
 
187
         * if @ref useXMPP09 is true. Default is false.
 
188
         */
 
189
        void setProbeSSL ( bool flag );
 
190
        /**
 
191
         * Returns if SSL support will be probed.
 
192
         */
 
193
        bool probeSSL () const;
 
194
 
 
195
        /**
 
196
         * Override the name and port of the server to connect to.
 
197
         * This only has an effect if the old protocol (@ref useXMPP09)
 
198
         * has been enabled. Default is false.
 
199
         */
 
200
        void setOverrideHost ( bool flag, const QString &server = "", int port = 5222 );
 
201
        /**
 
202
         * Returns if the server name and port are overridden.
 
203
         */
 
204
        bool overrideHost () const;
 
205
 
 
206
        /**
 
207
         * Allow the transmission of a plain text password. If digested
 
208
         * passwords are supported by the server, they will still be preferred.
 
209
         * Defaults to true.
 
210
         */
 
211
        void setAllowPlainTextPassword ( bool flag );
 
212
        /**
 
213
         * Returns if plain text passwords are allowed.
 
214
         */
 
215
        bool allowPlainTextPassword () const;
 
216
 
 
217
        /**
 
218
         * Enable file transfers. Default is false.
 
219
         * @param flag Whether to enable file transfers.
 
220
         * @param localAddress Local address to receive file transfers at. Will be determined automatically if not specified.
 
221
         */
 
222
        void setFileTransfersEnabled ( bool flag, const QString &localAddress = QString() );
 
223
 
 
224
        /**
 
225
         * Returns the address of the local interface.
 
226
         */
 
227
        QString localAddress () const;
 
228
 
 
229
        /**
 
230
         * Returns if file transfers are enabled.
 
231
         */
 
232
        bool fileTransfersEnabled () const;
 
233
 
 
234
        /**
 
235
         * Set client name.
 
236
         */
 
237
        void setClientName ( const QString &clientName );
 
238
        /**
 
239
         * Return client name.
 
240
         */
 
241
        QString clientName () const;
 
242
 
 
243
        /**
 
244
         * Set client version.
 
245
         */
 
246
        void setClientVersion ( const QString &clientVersion );
 
247
        /**
 
248
         * Return client version.
 
249
         */
 
250
        QString clientVersion () const;
 
251
 
 
252
        /**
 
253
         * Set operating system name.
 
254
         */
 
255
        void setOSName ( const QString &osName );
 
256
        /**
 
257
         * Return operating system name.
 
258
         */
 
259
        QString osName () const;
 
260
 
 
261
        /**
 
262
         * Set the caps(JEP-0115: Entity capabilities) node name.
 
263
         * @param node Node name.
 
264
         */
 
265
        void setCapsNode( const QString &capsNode );
 
266
        /**
 
267
         * Return the caps node name for this client.
 
268
         * @return the caps node name.
 
269
         */
 
270
        QString capsNode() const;
 
271
        
 
272
        /**
 
273
         * Set the caps(JEP-0115: Entity capabilities) node version.
 
274
         * @param capsVersion the node version.
 
275
         */
 
276
        void setCapsVersion( const QString &capsVersion );
 
277
        /**
 
278
         * Return the caps version for this client.
 
279
         * @return the caps version.
 
280
         */
 
281
        QString capsVersion() const;
 
282
 
 
283
        /**
 
284
         * Return the caps extension list for this client.
 
285
         * @return A string containing all extensions separated by space.
 
286
         */
 
287
        QString capsExt() const;
 
288
 
 
289
        /**
 
290
         * Set the disco Identity information for this client.
 
291
         * Create a Disco identity like this:
 
292
         * @code
 
293
         * DiscoItem::Identity identity;
 
294
         * identity.category = "client";
 
295
         * identity.type = "pc";
 
296
         * identity.name = "Kopete";
 
297
         * @endcode
 
298
         *
 
299
         * @param identity DiscoItem::Identity for the client.
 
300
         */
 
301
        void setDiscoIdentity(DiscoItem::Identity identity);
 
302
        /**
 
303
         * Get the disco Identity information for this client.
 
304
         * @return the DiscoItem::Identity for this client.
 
305
         */
 
306
        DiscoItem::Identity discoIdentity() const;
 
307
 
 
308
        /**
 
309
         * Set timezone information. Default is UTC.
 
310
         */
 
311
        void setTimeZone ( const QString &timeZoneName, int timeZoneOffset );
 
312
        /**
 
313
         * Return timezone name.
 
314
         */
 
315
        QString timeZoneName () const;
 
316
        /**
 
317
         * Return timezone offset.
 
318
         */
 
319
        int timeZoneOffset () const;
 
320
 
 
321
        /**
 
322
         * This method can be used to implement a penalty
 
323
         * system when a lot of queries need to be sent to the
 
324
         * server. Using the time returned by this method,
 
325
         * the caller can determine a delay until the next
 
326
         * operation in the queue can be carried out.
 
327
         * @brief Return current penalty time in seconds.
 
328
         */
 
329
        int getPenaltyTime ();
 
330
 
 
331
        /**
 
332
         * Return the XMPP client instance.
 
333
         */
 
334
        XMPP::Client *client () const;
 
335
 
 
336
        /**
 
337
         * Return client stream instance.
 
338
         */
 
339
        XMPP::ClientStream *clientStream () const;
 
340
 
 
341
        /**
 
342
         * Return client connector instance.
 
343
         */
 
344
        XMPP::AdvancedConnector *clientConnector () const;
 
345
 
 
346
        /**
 
347
         * Get the root task for this connection.
 
348
         * You need this instance for every task
 
349
         * you want to start.
 
350
         */
 
351
        XMPP::Task *rootTask () const;
 
352
 
 
353
        /**
 
354
         * Returns the file transfer manager
 
355
         * instance that deals with current file
 
356
         * transfers.
 
357
         */
 
358
        XMPP::FileTransferManager *fileTransferManager () const;
 
359
        
 
360
        /**
 
361
         * Returns the privacy lists manager
 
362
         */
 
363
        PrivacyManager *privacyManager () const;
 
364
 
 
365
        /**
 
366
         * Join a groupchat.
 
367
         * @param host Node to join the room at.
 
368
         * @param room Name of room to join.
 
369
         * @param nick Nick name you want to join with.
 
370
         */
 
371
        void joinGroupChat ( const QString &host, const QString &room, const QString &nick );
 
372
 
 
373
        /**
 
374
         * Join a groupchat that require a password.
 
375
         * @param host Node to join the room at.
 
376
         * @param room Name of room to join.
 
377
         * @param nick Nick name you want to join with.
 
378
         * @param password The password to join the room.
 
379
         */
 
380
        void joinGroupChat ( const QString &host, const QString &room, const QString &nick, const QString &password );
 
381
 
 
382
        /**
 
383
         * Leave a groupchat.
 
384
         * @param host Node to leave room at.
 
385
         * @param room Name of room to leave.
 
386
         */
 
387
        void leaveGroupChat ( const QString &host, const QString &room );
 
388
        
 
389
        /**
 
390
         * change the status of a groupchat
 
391
         */
 
392
        void setGroupChatStatus(const QString &host, const QString &room, const XMPP::Status &);
 
393
        /**
 
394
         * change the nick in a groupchat
 
395
         */
 
396
        void changeGroupChatNick(const QString &host, const QString &room, const QString &nick, const XMPP::Status &status =XMPP::Status());
 
397
 
 
398
        /**
 
399
         * Send a message.
 
400
         */
 
401
        void sendMessage ( const XMPP::Message &message );
 
402
 
 
403
        /**
 
404
         * Send raw packet to the server.
 
405
         */
 
406
        void send ( const QString &packet );
 
407
 
 
408
        /**
 
409
         * Request the roster from the Jabber server.
 
410
         */
 
411
        void requestRoster ();
 
412
 
 
413
signals:
 
414
        /**
 
415
         * Connected successfully.
 
416
         */
 
417
        void connected ();
 
418
 
 
419
        /**
 
420
         * Client stream authenticated. This
 
421
         * signal is emitted when the socket
 
422
         * connection has been successfully
 
423
         * established, before sending the login
 
424
         * packet.
 
425
         */
 
426
        void csAuthenticated ();
 
427
 
 
428
        /**
 
429
         * Client stream error.
 
430
         */
 
431
        void csError ( int error );
 
432
 
 
433
        /**
 
434
         * Client stream was disconnected.
 
435
         */
 
436
        void csDisconnected ();
 
437
 
 
438
        /**
 
439
         * TLS problem encountered.
 
440
         */
 
441
        void tlsWarning ( QCA::TLS::IdentityResult, QCA::Validity );
 
442
 
 
443
        /**
 
444
         * A new file transfer needs to be handled.
 
445
         * The file transfer can be dealt with by
 
446
         * querying the file transfer manager from
 
447
         * @ref client.
 
448
         */
 
449
        void incomingFileTransfer ();
 
450
 
 
451
        /**
 
452
         * Fatal error has been encountered,
 
453
         * further operations are not possible.
 
454
         */
 
455
        void error ( JabberClient::ErrorCode code );
 
456
 
 
457
        /**
 
458
         * Roster has been transmitted and processed.
 
459
         */
 
460
        void rosterRequestFinished ( bool success );
 
461
 
 
462
        /**
 
463
         * A new contact appeared on the roster.
 
464
         */
 
465
        void newContact ( const XMPP::RosterItem &item );
 
466
 
 
467
        /**
 
468
         * A contact has been removed from the roster.
 
469
         */
 
470
        void contactDeleted ( const XMPP::RosterItem &item );
 
471
 
 
472
        /**
 
473
         * A roster item has changed.
 
474
         */
 
475
        void contactUpdated ( const XMPP::RosterItem &item );
 
476
 
 
477
        /**
 
478
         * New resource is available for a contact.
 
479
         */
 
480
        void resourceAvailable ( const XMPP::Jid &jid, const XMPP::Resource &resource );
 
481
 
 
482
        /**
 
483
         * An existing resource has been removed.
 
484
         */
 
485
        void resourceUnavailable ( const XMPP::Jid &jid, const XMPP::Resource &resource );
 
486
 
 
487
        /**
 
488
         * A new message has been received.
 
489
         */
 
490
        void messageReceived ( const XMPP::Message &message );
 
491
 
 
492
        /**
 
493
         * Group chat has been joined.
 
494
         */
 
495
        void groupChatJoined ( const XMPP::Jid &jid );
 
496
 
 
497
        /**
 
498
         * Group chat has been left.
 
499
         */
 
500
        void groupChatLeft ( const XMPP::Jid &jid );
 
501
 
 
502
        /**
 
503
         * A presence to a groupchat has been signalled.
 
504
         */
 
505
        void groupChatPresence ( const XMPP::Jid &jid, const XMPP::Status &status );
 
506
 
 
507
        /**
 
508
         * An error was encountered joining or processing a groupchat.
 
509
         */
 
510
        void groupChatError ( const XMPP::Jid &jid, int error, const QString &reason );
 
511
 
 
512
        /**
 
513
         * New subscription request.
 
514
         */
 
515
        void subscription ( const XMPP::Jid &jid, const QString &type );
 
516
        
 
517
        /**
 
518
         * Dispatches a debug message. Debug messages
 
519
         * include incoming and outgoing XML packets
 
520
         * as well as internal status messages.
 
521
         */
 
522
        void debugMessage ( const QString &message );
 
523
        void incomingXML (const QString &msg);
 
524
        void outgoingXML (const QString &msg);
 
525
 
 
526
private:
 
527
        class Private;
 
528
        Private * const d;
 
529
 
 
530
        /**
 
531
         * Delete all member classes and reset the class to a predefined state.
 
532
         */
 
533
        void cleanUp ();
 
534
 
 
535
        /** 
 
536
         * Return current instance of the S5B server.
 
537
         */
 
538
        XMPP::S5BServer *s5bServer ();
 
539
        /** 
 
540
         * Add an address that the S5B server should handle.
 
541
         */
 
542
        void addS5BServerAddress ( const QString &address );
 
543
        /** 
 
544
         * Remove an address that the S5B server currently handles.
 
545
         */
 
546
        void removeS5BServerAddress ( const QString &address );
 
547
 
 
548
private slots:
 
549
        /* S5B server object has been destroyed. */
 
550
        void slotS5BServerGone ();
 
551
 
 
552
        /* update the penalty timer */
 
553
        void slotUpdatePenaltyTime ();
 
554
 
 
555
        /* Login if the connection was OK. */
 
556
        void slotCSNeedAuthParams (bool user, bool pass, bool realm);
 
557
 
 
558
        /* Called from Psi: tells us when we're logged in OK. */
 
559
        void slotCSAuthenticated ();
 
560
 
 
561
        /* Called from Psi: tells us when we've been disconnected from the server. */
 
562
        void slotCSDisconnected ();
 
563
 
 
564
        /* Called from Psi: alerts us to a protocol warning. */
 
565
        void slotCSWarning (int);
 
566
 
 
567
        /* Called from Psi: alerts us to a protocol error. */
 
568
        void slotCSError (int);
 
569
 
 
570
        /* Called from Psi: tells us when we're connected. */
 
571
        void slotCSConnected ();
 
572
 
 
573
        /* Called from Psi: report certificate status */
 
574
        void slotTLSHandshaken ();
 
575
 
 
576
        /* Called from Psi: roster request finished */
 
577
        void slotRosterRequestFinished ( bool success, int statusCode, const QString &statusString );
 
578
 
 
579
        /* Called from Psi: incoming file transfer */
 
580
        void slotIncomingFileTransfer ();
 
581
 
 
582
        /* A new item appeared in our roster */
 
583
        void slotNewContact (const RosterItem &);
 
584
 
 
585
        /* An item has been deleted from our roster. */
 
586
        void slotContactDeleted (const RosterItem &);
 
587
 
 
588
        /* Update a contact's details. */
 
589
        void slotContactUpdated (const RosterItem &);
 
590
 
 
591
        /* Someone on our contact list had (another) resource come online. */
 
592
        void slotResourceAvailable (const Jid &, const Resource &);
 
593
 
 
594
        /* Someone on our contact list had a resource go offline. */
 
595
        void slotResourceUnavailable (const Jid &, const Resource &);
 
596
 
 
597
        /* Incoming message. */
 
598
        void slotReceivedMessage (const Message &);
 
599
        
 
600
        /* Called from Psi: debug messages from the backend. */
 
601
        void slotPsiDebug (const QString & msg);
 
602
        void slotIncomingXML (const QString &msg);
 
603
        void slotOutgoingXML (const QString &msg);
 
604
 
 
605
        /* Slots for handling groupchats. */
 
606
        void slotGroupChatJoined (const Jid & jid);
 
607
        void slotGroupChatLeft (const Jid & jid);
 
608
        void slotGroupChatPresence (const Jid & jid, const Status & status);
 
609
        void slotGroupChatError (const Jid & jid, int error, const QString & reason);
 
610
 
 
611
        /* Incoming subscription request. */
 
612
        void slotSubscription (const Jid & jid, const QString & type);
 
613
        
 
614
        /* the session task is finished */
 
615
        void slotSessionStarted();
 
616
 
 
617
};
 
618
 
 
619
#endif