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

« back to all changes in this revision

Viewing changes to iris/include/im.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
 * im.h - XMPP "IM" 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_IM_H
 
22
#define XMPP_IM_H
 
23
 
 
24
#include<qdatetime.h>
 
25
#include"xmpp.h"
 
26
 
 
27
namespace XMPP
 
28
{
 
29
        class Url
 
30
        {
 
31
        public:
 
32
                Url(const QString &url="", const QString &desc="");
 
33
                Url(const Url &);
 
34
                Url & operator=(const Url &);
 
35
                ~Url();
 
36
 
 
37
                QString url() const;
 
38
                QString desc() const;
 
39
 
 
40
                void setUrl(const QString &);
 
41
                void setDesc(const QString &);
 
42
 
 
43
        private:
 
44
                class Private;
 
45
                Private *d;
 
46
        };
 
47
 
 
48
        typedef QValueList<Url> UrlList;
 
49
        typedef QMap<QString, QString> StringMap;
 
50
        class Message
 
51
        {
 
52
        public:
 
53
                Message(const Jid &to="");
 
54
                Message(const Message &from);
 
55
                Message & operator=(const Message &from);
 
56
                ~Message();
 
57
 
 
58
                Jid to() const;
 
59
                Jid from() const;
 
60
                QString id() const;
 
61
                QString type() const;
 
62
                QString lang() const;
 
63
                QString subject(const QString &lang="") const;
 
64
                QString body(const QString &lang="") const;
 
65
                QString thread() const;
 
66
                Stanza::Error error() const;
 
67
 
 
68
                void setTo(const Jid &j);
 
69
                void setFrom(const Jid &j);
 
70
                void setId(const QString &s);
 
71
                void setType(const QString &s);
 
72
                void setLang(const QString &s);
 
73
                void setSubject(const QString &s, const QString &lang="");
 
74
                void setBody(const QString &s, const QString &lang="");
 
75
                void setThread(const QString &s);
 
76
                void setError(const Stanza::Error &err);
 
77
 
 
78
                // JEP-0091
 
79
                QDateTime timeStamp() const;
 
80
                void setTimeStamp(const QDateTime &ts);
 
81
 
 
82
                // JEP-0066
 
83
                UrlList urlList() const;
 
84
                void urlAdd(const Url &u);
 
85
                void urlsClear();
 
86
                void setUrlList(const UrlList &list);
 
87
 
 
88
                // JEP-0027
 
89
                QString xencrypted() const;
 
90
                void setXEncrypted(const QString &s);
 
91
 
 
92
                // Obsolete invitation
 
93
                QString invite() const;
 
94
                void setInvite(const QString &s);
 
95
 
 
96
                // for compatibility.  delete me later
 
97
                bool spooled() const;
 
98
                void setSpooled(bool);
 
99
                bool wasEncrypted() const;
 
100
                void setWasEncrypted(bool);
 
101
 
 
102
                Stanza toStanza(Stream *stream) const;
 
103
                bool fromStanza(const Stanza &s, int tzoffset);
 
104
 
 
105
        private:
 
106
                class Private;
 
107
                Private *d;
 
108
        };
 
109
 
 
110
        class Subscription
 
111
        {
 
112
        public:
 
113
                enum SubType { None, To, From, Both, Remove };
 
114
 
 
115
                Subscription(SubType type=None);
 
116
 
 
117
                int type() const;
 
118
 
 
119
                QString toString() const;
 
120
                bool fromString(const QString &);
 
121
 
 
122
        private:
 
123
                SubType value;
 
124
        };
 
125
 
 
126
        class Status
 
127
        {
 
128
        public:
 
129
                Status(const QString &show="", const QString &status="", int priority=0, bool available=true);
 
130
                ~Status();
 
131
 
 
132
                int priority() const;
 
133
                const QString & show() const;
 
134
                const QString & status() const;
 
135
                QDateTime timeStamp() const;
 
136
                const QString & keyID() const;
 
137
                bool isAvailable() const;
 
138
                bool isAway() const;
 
139
                bool isInvisible() const;
 
140
                bool hasError() const;
 
141
                int errorCode() const;
 
142
                const QString & errorString() const;
 
143
 
 
144
                const QString & xsigned() const;
 
145
                const QString & songTitle() const;
 
146
 
 
147
                void setPriority(int);
 
148
                void setShow(const QString &);
 
149
                void setStatus(const QString &);
 
150
                void setTimeStamp(const QDateTime &);
 
151
                void setKeyID(const QString &);
 
152
                void setIsAvailable(bool);
 
153
                void setIsInvisible(bool);
 
154
                void setError(int, const QString &);
 
155
 
 
156
                void setXSigned(const QString &);
 
157
                void setSongTitle(const QString &);
 
158
 
 
159
        private:
 
160
                int v_priority;
 
161
                QString v_show, v_status, v_key;
 
162
                QDateTime v_timeStamp;
 
163
                bool v_isAvailable;
 
164
                bool v_isInvisible;
 
165
 
 
166
                QString v_xsigned;
 
167
                // gabber song extension
 
168
                QString v_songTitle;
 
169
 
 
170
                int ecode;
 
171
                QString estr;
 
172
 
 
173
                class Private;
 
174
                Private *d;
 
175
        };
 
176
 
 
177
        class Resource
 
178
        {
 
179
        public:
 
180
                Resource(const QString &name="", const Status &s=Status());
 
181
                ~Resource();
 
182
 
 
183
                const QString & name() const;
 
184
                int priority() const;
 
185
                const Status & status() const;
 
186
 
 
187
                void setName(const QString &);
 
188
                void setStatus(const Status &);
 
189
 
 
190
        private:
 
191
                QString v_name;
 
192
                Status v_status;
 
193
 
 
194
                class ResourcePrivate *d;
 
195
        };
 
196
 
 
197
        class ResourceList : public QValueList<Resource>
 
198
        {
 
199
        public:
 
200
                ResourceList();
 
201
                ~ResourceList();
 
202
 
 
203
                ResourceList::Iterator find(const QString &);
 
204
                ResourceList::Iterator priority();
 
205
 
 
206
                ResourceList::ConstIterator find(const QString &) const;
 
207
                ResourceList::ConstIterator priority() const;
 
208
 
 
209
        private:
 
210
                class ResourceListPrivate *d;
 
211
        };
 
212
 
 
213
        class RosterItem
 
214
        {
 
215
        public:
 
216
                RosterItem(const Jid &jid="");
 
217
                virtual ~RosterItem();
 
218
 
 
219
                const Jid & jid() const;
 
220
                const QString & name() const;
 
221
                const QStringList & groups() const;
 
222
                const Subscription & subscription() const;
 
223
                const QString & ask() const;
 
224
                bool isPush() const;
 
225
                bool inGroup(const QString &) const;
 
226
 
 
227
                virtual void setJid(const Jid &);
 
228
                void setName(const QString &);
 
229
                void setGroups(const QStringList &);
 
230
                void setSubscription(const Subscription &);
 
231
                void setAsk(const QString &);
 
232
                void setIsPush(bool);
 
233
                bool addGroup(const QString &);
 
234
                bool removeGroup(const QString &);
 
235
 
 
236
                QDomElement toXml(QDomDocument *) const;
 
237
                bool fromXml(const QDomElement &);
 
238
 
 
239
        private:
 
240
                Jid v_jid;
 
241
                QString v_name;
 
242
                QStringList v_groups;
 
243
                Subscription v_subscription;
 
244
                QString v_ask;
 
245
                bool v_push;
 
246
 
 
247
                class RosterItemPrivate *d;
 
248
        };
 
249
 
 
250
        class Roster : public QValueList<RosterItem>
 
251
        {
 
252
        public:
 
253
                Roster();
 
254
                ~Roster();
 
255
 
 
256
                Roster::Iterator find(const Jid &);
 
257
                Roster::ConstIterator find(const Jid &) const;
 
258
 
 
259
        private:
 
260
                class RosterPrivate *d;
 
261
        };
 
262
 
 
263
        class Features
 
264
        {
 
265
        public:
 
266
                Features();
 
267
                Features(const QStringList &);
 
268
                Features(const QString &);
 
269
                ~Features();
 
270
 
 
271
                QStringList list() const; // actual featurelist
 
272
                void setList(const QStringList &);
 
273
 
 
274
                // features
 
275
                bool canRegister() const;
 
276
                bool canSearch() const;
 
277
                bool canGroupchat() const;
 
278
                bool canDisco() const;
 
279
                bool isGateway() const;
 
280
                bool haveVCard() const;
 
281
 
 
282
                enum FeatureID {
 
283
                        FID_Invalid = -1,
 
284
                        FID_None,
 
285
                        FID_Register,
 
286
                        FID_Search,
 
287
                        FID_Groupchat,
 
288
                        FID_Disco,
 
289
                        FID_Gateway,
 
290
                        FID_VCard,
 
291
 
 
292
                        // private Psi actions
 
293
                        FID_Add
 
294
                };
 
295
 
 
296
                // useful functions
 
297
                bool test(const QStringList &) const;
 
298
 
 
299
                QString name() const;
 
300
                static QString name(long id);
 
301
                static QString name(const QString &feature);
 
302
 
 
303
                long id() const;
 
304
                static long id(const QString &feature);
 
305
                static QString feature(long id);
 
306
 
 
307
                class FeatureName;
 
308
        private:
 
309
                QStringList _list;
 
310
        };
 
311
 
 
312
        class AgentItem
 
313
        {
 
314
        public:
 
315
                AgentItem() { }
 
316
 
 
317
                const Jid & jid() const { return v_jid; }
 
318
                const QString & name() const { return v_name; }
 
319
                const QString & category() const { return v_category; }
 
320
                const QString & type() const { return v_type; }
 
321
                const Features & features() const { return v_features; }
 
322
 
 
323
                void setJid(const Jid &j) { v_jid = j; }
 
324
                void setName(const QString &n) { v_name = n; }
 
325
                void setCategory(const QString &c) { v_category = c; }
 
326
                void setType(const QString &t) { v_type = t; }
 
327
                void setFeatures(const Features &f) { v_features = f; }
 
328
 
 
329
        private:
 
330
                Jid v_jid;
 
331
                QString v_name, v_category, v_type;
 
332
                Features v_features;
 
333
        };
 
334
 
 
335
        typedef QValueList<AgentItem> AgentList;
 
336
 
 
337
        class DiscoItem
 
338
        {
 
339
        public:
 
340
                DiscoItem();
 
341
                ~DiscoItem();
 
342
 
 
343
                const Jid &jid() const;
 
344
                const QString &node() const;
 
345
                const QString &name() const;
 
346
 
 
347
                void setJid(const Jid &);
 
348
                void setName(const QString &);
 
349
                void setNode(const QString &);
 
350
 
 
351
                enum Action {
 
352
                        None = 0,
 
353
                        Remove,
 
354
                        Update
 
355
                };
 
356
 
 
357
                Action action() const;
 
358
                void setAction(Action);
 
359
 
 
360
                const Features &features() const;
 
361
                void setFeatures(const Features &);
 
362
 
 
363
                struct Identity
 
364
                {
 
365
                        QString category;
 
366
                        QString name;
 
367
                        QString type;
 
368
                };
 
369
 
 
370
                typedef QValueList<Identity> Identities;
 
371
 
 
372
                const Identities &identities() const;
 
373
                void setIdentities(const Identities &);
 
374
 
 
375
                // some useful helper functions
 
376
                static Action string2action(QString s);
 
377
                static QString action2string(Action a);
 
378
 
 
379
                DiscoItem & operator= (const DiscoItem &);
 
380
                DiscoItem(const DiscoItem &);
 
381
 
 
382
                operator AgentItem() const { return toAgentItem(); }
 
383
                AgentItem toAgentItem() const;
 
384
                void fromAgentItem(const AgentItem &);
 
385
 
 
386
        private:
 
387
                class Private;
 
388
                Private *d;
 
389
        };
 
390
 
 
391
        typedef QValueList<DiscoItem> DiscoList;
 
392
 
 
393
        class FormField
 
394
        {
 
395
        public:
 
396
                enum { username, nick, password, name, first, last, email, address, city, state, zip, phone, url, date, misc };
 
397
                FormField(const QString &type="", const QString &value="");
 
398
                ~FormField();
 
399
 
 
400
                int type() const;
 
401
                QString fieldName() const;
 
402
                QString realName() const;
 
403
                bool isSecret() const;
 
404
                const QString & value() const;
 
405
                void setType(int);
 
406
                bool setType(const QString &);
 
407
                void setValue(const QString &);
 
408
 
 
409
        private:
 
410
                int tagNameToType(const QString &) const;
 
411
                QString typeToTagName(int) const;
 
412
 
 
413
                int v_type;
 
414
                QString v_value;
 
415
 
 
416
                class Private;
 
417
                Private *d;
 
418
        };
 
419
 
 
420
        class Form : public QValueList<FormField>
 
421
        {
 
422
        public:
 
423
                Form(const Jid &j="");
 
424
                ~Form();
 
425
 
 
426
                Jid jid() const;
 
427
                QString instructions() const;
 
428
                QString key() const;
 
429
                void setJid(const Jid &);
 
430
                void setInstructions(const QString &);
 
431
                void setKey(const QString &);
 
432
 
 
433
        private:
 
434
                Jid v_jid;
 
435
                QString v_instructions, v_key;
 
436
 
 
437
                class Private;
 
438
                Private *d;
 
439
        };
 
440
 
 
441
        class SearchResult
 
442
        {
 
443
        public:
 
444
                SearchResult(const Jid &jid="");
 
445
                ~SearchResult();
 
446
 
 
447
                const Jid & jid() const;
 
448
                const QString & nick() const;
 
449
                const QString & first() const;
 
450
                const QString & last() const;
 
451
                const QString & email() const;
 
452
 
 
453
                void setJid(const Jid &);
 
454
                void setNick(const QString &);
 
455
                void setFirst(const QString &);
 
456
                void setLast(const QString &);
 
457
                void setEmail(const QString &);
 
458
 
 
459
        private:
 
460
                Jid v_jid;
 
461
                QString v_nick, v_first, v_last, v_email;
 
462
        };
 
463
 
 
464
        class Client;
 
465
        class LiveRosterItem;
 
466
        class LiveRoster;
 
467
        class S5BManager;
 
468
        class IBBManager;
 
469
        class JidLinkManager;
 
470
        class FileTransferManager;
 
471
 
 
472
        class Task : public QObject
 
473
        {
 
474
                Q_OBJECT
 
475
        public:
 
476
                enum { ErrDisc };
 
477
                Task(Task *parent);
 
478
                Task(Client *, bool isRoot);
 
479
                virtual ~Task();
 
480
 
 
481
                Task *parent() const;
 
482
                Client *client() const;
 
483
                QDomDocument *doc() const;
 
484
                QString id() const;
 
485
 
 
486
                bool success() const;
 
487
                int statusCode() const;
 
488
                const QString & statusString() const;
 
489
 
 
490
                void go(bool autoDelete=false);
 
491
                virtual bool take(const QDomElement &);
 
492
                void safeDelete();
 
493
 
 
494
        signals:
 
495
                void finished();
 
496
 
 
497
        protected:
 
498
                virtual void onGo();
 
499
                virtual void onDisconnect();
 
500
                void send(const QDomElement &);
 
501
                void setSuccess(int code=0, const QString &str="");
 
502
                void setError(const QDomElement &);
 
503
                void setError(int code=0, const QString &str="");
 
504
                void debug(const char *, ...);
 
505
                void debug(const QString &);
 
506
                bool iqVerify(const QDomElement &x, const Jid &to, const QString &id, const QString &xmlns="");
 
507
 
 
508
        private slots:
 
509
                void clientDisconnected();
 
510
                void done();
 
511
 
 
512
        private:
 
513
                void init();
 
514
 
 
515
                class TaskPrivate;
 
516
                TaskPrivate *d;
 
517
        };
 
518
 
 
519
        class Client : public QObject
 
520
        {
 
521
                Q_OBJECT
 
522
 
 
523
        public:
 
524
                Client(QObject *parent=0);
 
525
                ~Client();
 
526
 
 
527
                bool isActive() const;
 
528
                void connectToServer(ClientStream *s, const Jid &j, bool auth=true);
 
529
                void start(const QString &host, const QString &user, const QString &pass, const QString &resource);
 
530
                void close(bool fast=false);
 
531
 
 
532
                Stream & stream();
 
533
                const LiveRoster & roster() const;
 
534
                const ResourceList & resourceList() const;
 
535
 
 
536
                void send(const QDomElement &);
 
537
                void send(const QString &);
 
538
 
 
539
                QString host() const;
 
540
                QString user() const;
 
541
                QString pass() const;
 
542
                QString resource() const;
 
543
                Jid jid() const;
 
544
 
 
545
                void rosterRequest();
 
546
                void sendMessage(const Message &);
 
547
                void sendSubscription(const Jid &, const QString &);
 
548
                void setPresence(const Status &);
 
549
 
 
550
                void debug(const QString &);
 
551
                QString genUniqueId();
 
552
                Task *rootTask();
 
553
                QDomDocument *doc() const;
 
554
 
 
555
                QString OSName() const;
 
556
                QString timeZone() const;
 
557
                int timeZoneOffset() const;
 
558
                QString clientName() const;
 
559
                QString clientVersion() const;
 
560
 
 
561
                void setOSName(const QString &);
 
562
                void setTimeZone(const QString &, int);
 
563
                void setClientName(const QString &);
 
564
                void setClientVersion(const QString &);
 
565
 
 
566
                S5BManager *s5bManager() const;
 
567
                IBBManager *ibbManager() const;
 
568
                JidLinkManager *jidLinkManager() const;
 
569
 
 
570
                void setFileTransferEnabled(bool b);
 
571
                FileTransferManager *fileTransferManager() const;
 
572
 
 
573
                bool groupChatJoin(const QString &host, const QString &room, const QString &nick);
 
574
                void groupChatSetStatus(const QString &host, const QString &room, const Status &);
 
575
                void groupChatChangeNick(const QString &host, const QString &room, const QString &nick, const Status &);
 
576
                void groupChatLeave(const QString &host, const QString &room);
 
577
 
 
578
        signals:
 
579
                void activated();
 
580
                void disconnected();
 
581
                //void authFinished(bool, int, const QString &);
 
582
                void rosterRequestFinished(bool, int, const QString &);
 
583
                void rosterItemAdded(const RosterItem &);
 
584
                void rosterItemUpdated(const RosterItem &);
 
585
                void rosterItemRemoved(const RosterItem &);
 
586
                void resourceAvailable(const Jid &, const Resource &);
 
587
                void resourceUnavailable(const Jid &, const Resource &);
 
588
                void presenceError(const Jid &, int, const QString &);
 
589
                void subscription(const Jid &, const QString &);
 
590
                void messageReceived(const Message &);
 
591
                void debugText(const QString &);
 
592
                void xmlIncoming(const QString &);
 
593
                void xmlOutgoing(const QString &);
 
594
                void groupChatJoined(const Jid &);
 
595
                void groupChatLeft(const Jid &);
 
596
                void groupChatPresence(const Jid &, const Status &);
 
597
                void groupChatError(const Jid &, int, const QString &);
 
598
 
 
599
                void incomingJidLink();
 
600
 
 
601
        private slots:
 
602
                //void streamConnected();
 
603
                //void streamHandshaken();
 
604
                //void streamError(const StreamError &);
 
605
                //void streamSSLCertificateReady(const QSSLCert &);
 
606
                //void streamCloseFinished();
 
607
                void streamError(int);
 
608
                void streamReadyRead();
 
609
                void streamIncomingXml(const QString &);
 
610
                void streamOutgoingXml(const QString &);
 
611
 
 
612
                void slotRosterRequestFinished();
 
613
 
 
614
                // basic daemons
 
615
                void ppSubscription(const Jid &, const QString &);
 
616
                void ppPresence(const Jid &, const Status &);
 
617
                void pmMessage(const Message &);
 
618
                void prRoster(const Roster &);
 
619
 
 
620
                void s5b_incomingReady();
 
621
                void ibb_incomingReady();
 
622
 
 
623
        public:
 
624
                class GroupChat;
 
625
        private:
 
626
                void cleanup();
 
627
                void distribute(const QDomElement &);
 
628
                void importRoster(const Roster &);
 
629
                void importRosterItem(const RosterItem &);
 
630
                void updateSelfPresence(const Jid &, const Status &);
 
631
                void updatePresence(LiveRosterItem *, const Jid &, const Status &);
 
632
 
 
633
                class ClientPrivate;
 
634
                ClientPrivate *d;
 
635
        };
 
636
 
 
637
        class LiveRosterItem : public RosterItem
 
638
        {
 
639
        public:
 
640
                LiveRosterItem(const Jid &j="");
 
641
                LiveRosterItem(const RosterItem &);
 
642
                ~LiveRosterItem();
 
643
 
 
644
                void setRosterItem(const RosterItem &);
 
645
 
 
646
                ResourceList & resourceList();
 
647
                ResourceList::Iterator priority();
 
648
 
 
649
                const ResourceList & resourceList() const;
 
650
                ResourceList::ConstIterator priority() const;
 
651
 
 
652
                bool isAvailable() const;
 
653
                const Status & lastUnavailableStatus() const;
 
654
                bool flagForDelete() const;
 
655
 
 
656
                void setLastUnavailableStatus(const Status &);
 
657
                void setFlagForDelete(bool);
 
658
 
 
659
        private:
 
660
                ResourceList v_resourceList;
 
661
                Status v_lastUnavailableStatus;
 
662
                bool v_flagForDelete;
 
663
 
 
664
                class LiveRosterItemPrivate;
 
665
                LiveRosterItemPrivate *d;
 
666
        };
 
667
 
 
668
        class LiveRoster : public QValueList<LiveRosterItem>
 
669
        {
 
670
        public:
 
671
                LiveRoster();
 
672
                ~LiveRoster();
 
673
 
 
674
                void flagAllForDelete();
 
675
                LiveRoster::Iterator find(const Jid &, bool compareRes=true);
 
676
                LiveRoster::ConstIterator find(const Jid &, bool compareRes=true) const;
 
677
 
 
678
        private:
 
679
                class LiveRosterPrivate;
 
680
                LiveRosterPrivate *d;
 
681
        };
 
682
}
 
683
 
 
684
#endif