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

« back to all changes in this revision

Viewing changes to iris/src/xmpp/xmpp-im/xmpp_features.cpp

  • 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_features.cpp - XMPP entity features
 
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
#include <QCoreApplication>
 
22
#include <QString>
 
23
#include <QMap>
 
24
#include <QStringList>
 
25
 
 
26
#include "xmpp_features.h"
 
27
 
 
28
using namespace XMPP;
 
29
 
 
30
Features::Features()
 
31
{
 
32
}
 
33
 
 
34
Features::Features(const QStringList &l)
 
35
{
 
36
        setList(l);
 
37
}
 
38
 
 
39
Features::Features(const QString &str)
 
40
{
 
41
        QStringList l;
 
42
        l << str;
 
43
 
 
44
        setList(l);
 
45
}
 
46
 
 
47
Features::~Features()
 
48
{
 
49
}
 
50
 
 
51
QStringList Features::list() const
 
52
{
 
53
        return _list;
 
54
}
 
55
 
 
56
void Features::setList(const QStringList &l)
 
57
{
 
58
        _list = l;
 
59
}
 
60
 
 
61
void Features::addFeature(const QString& s)
 
62
{
 
63
        _list += s;
 
64
}
 
65
 
 
66
bool Features::test(const QStringList &ns) const
 
67
{
 
68
        QStringList::ConstIterator it = ns.begin();
 
69
        for ( ; it != ns.end(); ++it) {
 
70
                if ( _list.contains( *it )) {
 
71
                        return true;
 
72
                }
 
73
        }
 
74
        return false;
 
75
}
 
76
 
 
77
#define FID_MULTICAST "http://jabber.org/protocol/address"
 
78
bool Features::canMulticast() const
 
79
{
 
80
        QStringList ns;
 
81
        ns << FID_MULTICAST;
 
82
 
 
83
        return test(ns);
 
84
}
 
85
 
 
86
#define FID_AHCOMMAND "http://jabber.org/protocol/commands"
 
87
bool Features::canCommand() const
 
88
{
 
89
        QStringList ns;
 
90
        ns << FID_AHCOMMAND;
 
91
 
 
92
        return test(ns);
 
93
}
 
94
 
 
95
#define FID_REGISTER "jabber:iq:register"
 
96
bool Features::canRegister() const
 
97
{
 
98
        QStringList ns;
 
99
        ns << FID_REGISTER;
 
100
 
 
101
        return test(ns);
 
102
}
 
103
 
 
104
#define FID_SEARCH "jabber:iq:search"
 
105
bool Features::canSearch() const
 
106
{
 
107
        QStringList ns;
 
108
        ns << FID_SEARCH;
 
109
 
 
110
        return test(ns);
 
111
}
 
112
 
 
113
#define FID_GROUPCHAT "jabber:iq:conference"
 
114
bool Features::canGroupchat() const
 
115
{
 
116
        QStringList ns;
 
117
        ns << "http://jabber.org/protocol/muc";
 
118
        ns << FID_GROUPCHAT;
 
119
 
 
120
        return test(ns);
 
121
}
 
122
 
 
123
#define FID_VOICE "http://www.google.com/xmpp/protocol/voice/v1"
 
124
bool Features::canVoice() const
 
125
{
 
126
        QStringList ns;
 
127
        ns << FID_VOICE;
 
128
 
 
129
        return test(ns);
 
130
}
 
131
 
 
132
#define FID_GATEWAY "jabber:iq:gateway"
 
133
bool Features::isGateway() const
 
134
{
 
135
        QStringList ns;
 
136
        ns << FID_GATEWAY;
 
137
 
 
138
        return test(ns);
 
139
}
 
140
 
 
141
#define FID_DISCO "http://jabber.org/protocol/disco"
 
142
bool Features::canDisco() const
 
143
{
 
144
        QStringList ns;
 
145
        ns << FID_DISCO;
 
146
        ns << "http://jabber.org/protocol/disco#info";
 
147
        ns << "http://jabber.org/protocol/disco#items";
 
148
 
 
149
        return test(ns);
 
150
}
 
151
 
 
152
#define FID_CHATSTATE "http://jabber.org/protocol/chatstates"
 
153
bool Features::canChatState() const
 
154
{
 
155
        QStringList ns;
 
156
        ns << FID_CHATSTATE;
 
157
 
 
158
        return test(ns);
 
159
}
 
160
 
 
161
#define FID_VCARD "vcard-temp"
 
162
bool Features::haveVCard() const
 
163
{
 
164
        QStringList ns;
 
165
        ns << FID_VCARD;
 
166
 
 
167
        return test(ns);
 
168
}
 
169
 
 
170
// custom Psi acitons
 
171
#define FID_ADD "psi:add"
 
172
 
 
173
class Features::FeatureName : public QObject
 
174
{
 
175
        Q_OBJECT
 
176
 
 
177
public:
 
178
        FeatureName()
 
179
        : QObject(QCoreApplication::instance())
 
180
        {
 
181
                id2s[FID_Invalid]       = tr("ERROR: Incorrect usage of Features class");
 
182
                id2s[FID_None]          = tr("None");
 
183
                id2s[FID_Register]      = tr("Register");
 
184
                id2s[FID_Search]        = tr("Search");
 
185
                id2s[FID_Groupchat]     = tr("Groupchat");
 
186
                id2s[FID_Gateway]       = tr("Gateway");
 
187
                id2s[FID_Disco]         = tr("Service Discovery");
 
188
                id2s[FID_VCard]         = tr("VCard");
 
189
                id2s[FID_AHCommand]     = tr("Execute command");
 
190
 
 
191
                // custom Psi actions
 
192
                id2s[FID_Add]           = tr("Add to roster");
 
193
 
 
194
                // compute reverse map
 
195
                //QMap<QString, long>::Iterator it = id2s.begin();
 
196
                //for ( ; it != id2s.end(); ++it)
 
197
                //      s2id[it.data()] = it.key();
 
198
 
 
199
                id2f[FID_Register]      = FID_REGISTER;
 
200
                id2f[FID_Search]        = FID_SEARCH;
 
201
                id2f[FID_Groupchat]     = FID_GROUPCHAT;
 
202
                id2f[FID_Gateway]       = FID_GATEWAY;
 
203
                id2f[FID_Disco]         = FID_DISCO;
 
204
                id2f[FID_VCard]         = FID_VCARD;
 
205
                id2f[FID_AHCommand]     = FID_AHCOMMAND;
 
206
 
 
207
                // custom Psi actions
 
208
                id2f[FID_Add]           = FID_ADD;
 
209
        }
 
210
 
 
211
        //QMap<QString, long> s2id;
 
212
        QMap<long, QString> id2s;
 
213
        QMap<long, QString> id2f;
 
214
};
 
215
 
 
216
static Features::FeatureName *featureName = 0;
 
217
 
 
218
long Features::id() const
 
219
{
 
220
        if ( _list.count() > 1 )
 
221
                return FID_Invalid;
 
222
        else if ( canRegister() )
 
223
                return FID_Register;
 
224
        else if ( canSearch() )
 
225
                return FID_Search;
 
226
        else if ( canGroupchat() )
 
227
                return FID_Groupchat;
 
228
        else if ( isGateway() )
 
229
                return FID_Gateway;
 
230
        else if ( canDisco() )
 
231
                return FID_Disco;
 
232
        else if ( haveVCard() )
 
233
                return FID_VCard;
 
234
        else if ( canCommand() )
 
235
                return FID_AHCommand;
 
236
        else if ( test(QStringList(FID_ADD)) )
 
237
                return FID_Add;
 
238
 
 
239
        return FID_None;
 
240
}
 
241
 
 
242
long Features::id(const QString &feature)
 
243
{
 
244
        Features f(feature);
 
245
        return f.id();
 
246
}
 
247
 
 
248
QString Features::feature(long id)
 
249
{
 
250
        if ( !featureName )
 
251
                featureName = new FeatureName();
 
252
 
 
253
        return featureName->id2f[id];
 
254
}
 
255
 
 
256
QString Features::name(long id)
 
257
{
 
258
        if ( !featureName )
 
259
                featureName = new FeatureName();
 
260
 
 
261
        return featureName->id2s[id];
 
262
}
 
263
 
 
264
QString Features::name() const
 
265
{
 
266
        return name(id());
 
267
}
 
268
 
 
269
QString Features::name(const QString &feature)
 
270
{
 
271
        Features f(feature);
 
272
        return f.name(f.id());
 
273
}
 
274
 
 
275
#include "xmpp_features.moc"