~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to src/jabber.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2002-04-19 02:28:44 UTC
  • Revision ID: james.westby@ubuntu.com-20020419022844-za7xgai5qyfd9xv6
Tags: upstream-0.8.5
ImportĀ upstreamĀ versionĀ 0.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
** jabber.h - communicates with the Jabber network
 
3
** Copyright (C) 2001, 2002  Justin Karneges
 
4
**
 
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.
 
9
**
 
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.
 
14
**
 
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.
 
18
**
 
19
****************************************************************************/
 
20
 
 
21
#ifndef JABBER_H
 
22
#define JABBER_H
 
23
 
 
24
#include<qstring.h>
 
25
#include<qobject.h>
 
26
#include<qxml.h>
 
27
#include<qptrlist.h>
 
28
#include<qdatetime.h>
 
29
#include<qcstring.h>
 
30
 
 
31
#include"jabstream.h"
 
32
#include"jabcommon.h"
 
33
#include"jabio.h"
 
34
#include"jabtasks.h"
 
35
 
 
36
 
 
37
#define JABERR_CONNECT     0
 
38
#define JABERR_AUTH        1
 
39
#define JABERR_CREATE      2
 
40
#define JABERR_DISCONNECT  3
 
41
#define JABERR_UNDO        4
 
42
 
 
43
#define JABERR_SERVICES    5
 
44
#define JABERR_REGFORM     6
 
45
#define JABERR_BROWSE      7
 
46
 
 
47
 
 
48
#define JABCONN_LOGIN      0
 
49
#define JABCONN_REGISTER   1
 
50
#define JABCONN_UNREGISTER 2
 
51
 
 
52
 
 
53
// for signaling updates
 
54
struct JabUpdate
 
55
{
 
56
        QString str;
 
57
        int queuePending;
 
58
};
 
59
 
 
60
// for signaling errors
 
61
struct JabError
 
62
{
 
63
        int type;
 
64
        QString msg;
 
65
};
 
66
 
 
67
 
 
68
/****************************************************************************
 
69
  Jabber - handles a Jabber session
 
70
 
 
71
  HOWTO:
 
72
 
 
73
    Jabber serv;
 
74
    serv.setHost("jabber.org", 5222");
 
75
    serv.setAccount("Joe", "Password", "Resource");
 
76
    serv.login(STATUS_ONLINE);
 
77
 
 
78
  The class communicates back to you via signals.
 
79
 
 
80
  All Jabber tasks are carried out via JabTasks.  Some tasks are handled
 
81
  internally, like messaging.  Other tasks are your responsibility.  See
 
82
  JabIO to learn how tasks work.
 
83
 
 
84
****************************************************************************/
 
85
class Jabber : public QObject
 
86
{
 
87
        Q_OBJECT
 
88
 
 
89
public:
 
90
        Jabber();
 
91
        ~Jabber();
 
92
 
 
93
        void setHost(const QString &xhost, int xport);
 
94
        void setAccount(const QString &xuser, const QString &xpass, const QString &xresource);
 
95
 
 
96
        JabRosterEntry *userEntry() { return &me; }
 
97
 
 
98
        bool isActive() { return v_isActive; }
 
99
        bool isConnected() { return stream.isConnected(); }
 
100
        int status() { return v_status; }
 
101
 
 
102
        void setNoop(int);
 
103
 
 
104
        bool isSSLSupported() { return stream.isSSLSupported(); }
 
105
        bool isSSLEnabled() { return stream.isSSLEnabled(); }
 
106
        void setSSLEnabled(bool use) { stream.setSSLEnabled(use); }
 
107
 
 
108
        void login(int status, const QString &statusStr, int priority, bool plain=FALSE);
 
109
        void accRegister();
 
110
        void accUnregister();
 
111
        void disc(bool fast=FALSE);
 
112
 
 
113
        void sendMessage(const JabMessage &);
 
114
        void setRoster(const QString &jid, const QString &nick, const QString &group);
 
115
        void setPresence(int status, const QString &statusStr, int priority);
 
116
 
 
117
        void subscribe(const QString &to);
 
118
        void subscribed(const QString &to);
 
119
        void unsubscribe(const QString &to);
 
120
        void unsubscribed(const QString &to);
 
121
 
 
122
        void cancelTransaction(const QString &id);
 
123
        JabTask *ioUser() { return userTask; }
 
124
 
 
125
        void insertXml(const QString &);
 
126
        void agentSetStatus(const QString &jid, int x);
 
127
 
 
128
        JabRosterEntry *findByJid(const QString &);
 
129
 
 
130
        void setOfflineEnabled(bool);
 
131
        void setCurrentRoster(JabRoster *);
 
132
        JabRoster *getCurrentRoster();
 
133
        void setOLR(const QString &);
 
134
        QString getOLR();
 
135
        JabUpdate getJU();
 
136
 
 
137
        void reset();
 
138
 
 
139
signals:
 
140
        void connected();
 
141
        void disconnected();
 
142
 
 
143
        // FIXME: these 2 should not pass pointers
 
144
        void statusUpdate(JabUpdate *);
 
145
        void error(JabError *);
 
146
 
 
147
        void messageReceived(const JabMessage &);
 
148
 
 
149
        void resourceAvailable(const Jid &, const JabResource &);
 
150
        void resourceUnavailable(const Jid &);
 
151
 
 
152
        void contactChanged(JabRosterEntry *);
 
153
        void contactNew(JabRosterEntry *);
 
154
        void contactRemove(JabRosterEntry *);
 
155
 
 
156
        void authRequest(const Jid &from);
 
157
        void authGrant(const Jid &from);
 
158
        void authRemove(const Jid &from);
 
159
 
 
160
        void accRegisterFinished(bool success, const QString &errMsg);
 
161
 
 
162
private slots:
 
163
        void streamConnected();
 
164
        void streamError(int);
 
165
        void receivePacket(const QDomElement &);
 
166
        void doError();
 
167
        void ioDone(JabTask *);
 
168
        void ioOutgoingPacket(const QDomElement &);
 
169
 
 
170
        void ioAuth();
 
171
        void ioPresence(int status, const QString &statusString);
 
172
        void ioReceiveRoster(JabRoster &r);
 
173
        void pushRoster(JabRoster &r);
 
174
        void pushSubscription(const Jid &, int);
 
175
        void pushPresence(const JT_PushPresence::Info &);
 
176
        void pushMessage(const JabMessage &);
 
177
 
 
178
        void doUpdate();
 
179
 
 
180
private:
 
181
        bool sock_isConnected;
 
182
        QString host;
 
183
        int port;
 
184
        int v_status;
 
185
        bool v_isActive, v_isConnected, v_offlineEnabled;
 
186
        QString user, pass, resource;
 
187
        bool usePlain;
 
188
 
 
189
        int connType;
 
190
 
 
191
        JabStream stream;
 
192
        JabIO io;
 
193
        JabRoster roster;
 
194
        JabError err;
 
195
        JabRosterEntry me;
 
196
 
 
197
        JT_Queue *queue;
 
198
        JabTask *userTask;
 
199
 
 
200
        // initial login
 
201
        int i_status, i_priority;
 
202
        QString i_statusString;
 
203
 
 
204
        void conn();
 
205
        void remove(const QString &);
 
206
 
 
207
        void processRosterEntryRecv(const JabRosterEntry &);
 
208
 
 
209
        QCString encodeXML(const QString &);
 
210
        void send(const QString &);
 
211
        void cleanup(bool fast=FALSE);
 
212
 
 
213
        void delayedError();
 
214
        JabUpdate makeUpdate();
 
215
        int notSpecial();
 
216
};
 
217
 
 
218
 
 
219
class SHA1
 
220
{
 
221
public:
 
222
        SHA1();
 
223
        static QString digest(QString in);
 
224
 
 
225
private:
 
226
        struct SHA1_CONTEXT
 
227
        {
 
228
                Q_UINT32 state[5];
 
229
                Q_UINT32 count[2];
 
230
                unsigned char buffer[64];
 
231
        };
 
232
 
 
233
        typedef union {
 
234
                unsigned char c[64];
 
235
                Q_UINT32 l[16];
 
236
        } CHAR64LONG16;
 
237
 
 
238
        void transform(Q_UINT32 state[5], unsigned char buffer[64]);
 
239
        void init(SHA1_CONTEXT* context);
 
240
        void update(SHA1_CONTEXT* context, unsigned char* data, Q_UINT32 len);
 
241
        void final(unsigned char digest[20], SHA1_CONTEXT* context);
 
242
 
 
243
        unsigned long blk0(Q_UINT32 i);
 
244
        bool bigEndian;
 
245
 
 
246
        CHAR64LONG16* block;
 
247
};
 
248
 
 
249
 
 
250
#endif