~ubuntu-branches/ubuntu/precise/kde-runtime/precise-updates

« back to all changes in this revision

Viewing changes to nepomuk/services/storage/lib/resourcewatcher.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-11-20 15:46:42 UTC
  • mfrom: (18.1.5 precise-proposed)
  • Revision ID: package-import@ubuntu.com-20141120154642-hyesdbuvsk78ihtz
Tags: 4:4.8.5-0ubuntu0.3
* SECURITY UPDATE: Insufficient Input Validation By IO Slaves and
  Webkit Part
 - Add upstream_CVE-2014-8600.diff to escape protocol twice: once
   for i18n, and once for HTML
 - https://www.kde.org/info/security/advisory-20141113-1.txt
 - CVE-2014-8600
 - LP: #1393479

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    This file is part of the Nepomuk KDE project.
3
3
    Copyright (C) 2011  Vishesh Handa <handa.vish@gmail.com>
4
 
    Copyright (C) 2011 Sebastian Trueg <trueg@kde.org>
 
4
    Copyright (C) 2011-2012 Sebastian Trueg <trueg@kde.org>
5
5
 
6
6
    This library is free software; you can redistribute it and/or
7
7
    modify it under the terms of the GNU Lesser General Public
25
25
 
26
26
#include <QtDBus/QDBusObjectPath>
27
27
 
28
 
#include <Nepomuk/Resource>
 
28
#include <nepomuk/resource.h>
29
29
 
30
30
#include <KUrl>
 
31
#include <KDebug>
31
32
 
32
33
namespace {
33
 
QList<QUrl> convertUris(const QStringList& uris) {
34
 
    QList<QUrl> us;
35
 
    foreach(const QString& uri, uris) {
36
 
        us << KUrl(uri);
37
 
    }
38
 
    return us;
39
 
}
 
34
    QString convertUri(const QUrl& uri) {
 
35
        return KUrl(uri).url();
 
36
    }
 
37
 
 
38
    QStringList convertUris(const QList<QUrl>& uris) {
 
39
        QStringList cs;
 
40
        foreach(const QUrl& uri, uris) {
 
41
            cs << convertUri(uri);
 
42
        }
 
43
        return cs;
 
44
    }
 
45
 
 
46
    QList<QUrl> convertUris(const QStringList& uris) {
 
47
        QList<QUrl> us;
 
48
        foreach(const QString& uri, uris) {
 
49
            us << KUrl(uri);
 
50
        }
 
51
        return us;
 
52
    }
40
53
}
41
54
 
42
55
class Nepomuk::ResourceWatcher::Private {
43
56
public:
44
 
    QList<Types::Class> m_types;
45
 
    QList<Nepomuk::Resource> m_resources;
46
 
    QList<Types::Property> m_properties;
 
57
    QList<QUrl> m_types;
 
58
    QList<QUrl> m_resources;
 
59
    QList<QUrl> m_properties;
47
60
 
48
61
    org::kde::nepomuk::ResourceWatcherConnection * m_connectionInterface;
49
62
    org::kde::nepomuk::ResourceWatcher * m_watchManagerInterface;
 
63
 
 
64
    QDBusServiceWatcher* m_rwServiceWatcher;
50
65
};
51
66
 
52
67
Nepomuk::ResourceWatcher::ResourceWatcher(QObject* parent)
58
73
                                                      "/resourcewatcher",
59
74
                                                      QDBusConnection::sessionBus() );
60
75
    d->m_connectionInterface = 0;
 
76
    d->m_rwServiceWatcher = 0;
61
77
}
62
78
 
63
79
Nepomuk::ResourceWatcher::~ResourceWatcher()
68
84
 
69
85
bool Nepomuk::ResourceWatcher::start()
70
86
{
 
87
    stop();
 
88
 
71
89
    //
72
90
    // Convert to list of strings
73
91
    //
74
 
    QList<QString> uris;
75
 
    foreach( const Nepomuk::Resource & res, d->m_resources ) {
76
 
        uris << KUrl(res.resourceUri()).url();
77
 
    }
78
 
 
79
 
    QList<QString> props;
80
 
    foreach( const Types::Property & prop, d->m_properties ) {
81
 
        props << KUrl(prop.uri()).url();
82
 
    }
83
 
 
84
 
    QList<QString> types_;
85
 
    foreach( const Types::Class & cl, d->m_types ) {
86
 
        types_ << KUrl(cl.uri()).url();
87
 
    }
 
92
    QList<QString> uris = convertUris(d->m_resources);
 
93
    QList<QString> props = convertUris(d->m_properties);
 
94
    QList<QString> types_ = convertUris(d->m_types);
 
95
 
 
96
    //
 
97
    // Watch for the RW service to (re-)appear and then re-connect to make sure we always get updates
 
98
    // We create this watcher even if we fail to connect below. Thus, once the rw service comes up we
 
99
    // can re-attach.
 
100
    //
 
101
    d->m_rwServiceWatcher = new QDBusServiceWatcher(QLatin1String("org.kde.nepomuk.DataManagement"),
 
102
                                                    QDBusConnection::sessionBus());
 
103
    connect(d->m_rwServiceWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(start()));
88
104
 
89
105
    //
90
106
    // Create the dbus object to watch
96
112
        d->m_connectionInterface = new org::kde::nepomuk::ResourceWatcherConnection( "org.kde.nepomuk.DataManagement",
97
113
                                                                                     path.path(),
98
114
                                                                                     QDBusConnection::sessionBus() );
99
 
        connect( d->m_connectionInterface, SIGNAL(propertyAdded(QString,QString,QDBusVariant)),
100
 
                 this, SLOT(slotPropertyAdded(QString,QString,QDBusVariant)) );
101
 
        connect( d->m_connectionInterface, SIGNAL(propertyRemoved(QString,QString,QDBusVariant)),
102
 
                 this, SLOT(slotPropertyRemoved(QString,QString,QDBusVariant)) );
 
115
        connect( d->m_connectionInterface, SIGNAL(propertyAdded(QString,QString,QVariantList)),
 
116
                 this, SLOT(slotPropertyAdded(QString,QString,QVariantList)) );
 
117
        connect( d->m_connectionInterface, SIGNAL(propertyRemoved(QString,QString,QVariantList)),
 
118
                 this, SLOT(slotPropertyRemoved(QString,QString,QVariantList)) );
103
119
        connect( d->m_connectionInterface, SIGNAL(resourceCreated(QString,QStringList)),
104
120
                 this, SLOT(slotResourceCreated(QString,QStringList)) );
 
121
        connect( d->m_connectionInterface, SIGNAL(propertyChanged(QString,QString,QVariantList,QVariantList)),
 
122
                 this, SLOT(slotPropertyChanged(QString,QString,QVariantList,QVariantList)) );
105
123
        connect( d->m_connectionInterface, SIGNAL(resourceRemoved(QString,QStringList)),
106
124
                 this, SLOT(slotResourceRemoved(QString,QStringList)) );
107
 
        connect( d->m_connectionInterface, SIGNAL(resourceTypeAdded(QString,QString)),
108
 
                 this, SLOT(slotResourceTypeAdded(QString,QString)) );
109
 
        connect( d->m_connectionInterface, SIGNAL(resourceTypeRemoved(QString,QString)),
110
 
                 this, SLOT(slotResourceTypeRemoved(QString,QString)) );
 
125
        connect( d->m_connectionInterface, SIGNAL(resourceTypesAdded(QString,QStringList)),
 
126
                 this, SLOT(slotResourceTypesAdded(QString,QStringList)) );
 
127
        connect( d->m_connectionInterface, SIGNAL(resourceTypesRemoved(QString,QStringList)),
 
128
                 this, SLOT(slotResourceTypesRemoved(QString,QStringList)) );
111
129
        return true;
112
130
    }
113
131
    else {
122
140
        delete d->m_connectionInterface;
123
141
        d->m_connectionInterface = 0;
124
142
    }
 
143
 
 
144
    delete d->m_rwServiceWatcher;
 
145
    d->m_rwServiceWatcher = 0;
125
146
}
126
147
 
127
148
void Nepomuk::ResourceWatcher::addProperty(const Nepomuk::Types::Property& property)
128
149
{
129
 
    d->m_properties << property;
 
150
    d->m_properties << property.uri();
 
151
    if(d->m_connectionInterface) {
 
152
        d->m_connectionInterface->addProperty(convertUri(property.uri()));
 
153
    }
130
154
}
131
155
 
132
156
void Nepomuk::ResourceWatcher::addResource(const Nepomuk::Resource& res)
133
157
{
134
 
    d->m_resources << res;
 
158
    d->m_resources << res.resourceUri();
 
159
    if(d->m_connectionInterface) {
 
160
        d->m_connectionInterface->addResource(convertUri(res.resourceUri()));
 
161
    }
135
162
}
136
163
 
137
164
void Nepomuk::ResourceWatcher::addType(const Nepomuk::Types::Class& type)
138
165
{
139
 
    d->m_types << type;
 
166
    d->m_types << type.uri();
 
167
    if(d->m_connectionInterface) {
 
168
        d->m_connectionInterface->addType(convertUri(type.uri()));
 
169
    }
 
170
}
 
171
 
 
172
void Nepomuk::ResourceWatcher::removeProperty(const Nepomuk::Types::Property& property)
 
173
{
 
174
    d->m_properties.removeAll(property.uri());
 
175
    if(d->m_connectionInterface) {
 
176
        d->m_connectionInterface->removeProperty(convertUri(property.uri()));
 
177
    }
 
178
}
 
179
 
 
180
void Nepomuk::ResourceWatcher::removeResource(const Nepomuk::Resource& res)
 
181
{
 
182
    d->m_resources.removeAll(res.resourceUri());
 
183
    if(d->m_connectionInterface) {
 
184
        d->m_connectionInterface->removeResource(convertUri(res.resourceUri()));
 
185
    }
 
186
}
 
187
 
 
188
void Nepomuk::ResourceWatcher::removeType(const Nepomuk::Types::Class& type)
 
189
{
 
190
    d->m_types.removeAll(type.uri());
 
191
    if(d->m_connectionInterface) {
 
192
        d->m_connectionInterface->removeType(convertUri(type.uri()));
 
193
    }
140
194
}
141
195
 
142
196
QList< Nepomuk::Types::Property > Nepomuk::ResourceWatcher::properties() const
143
197
{
144
 
    return d->m_properties;
 
198
    QList< Nepomuk::Types::Property > props;
 
199
    foreach(const QUrl& uri, d->m_properties)
 
200
        props << Types::Property(uri);
 
201
    return props;
145
202
}
146
203
 
147
204
QList<Nepomuk::Resource> Nepomuk::ResourceWatcher::resources() const
148
205
{
149
 
    return d->m_resources;
 
206
    QList<Nepomuk::Resource> resources;
 
207
    foreach(const QUrl& uri, d->m_resources)
 
208
        resources << Resource::fromResourceUri(uri);
 
209
    return resources;
150
210
}
151
211
 
152
212
QList< Nepomuk::Types::Class > Nepomuk::ResourceWatcher::types() const
153
213
{
154
 
    return d->m_types;
 
214
    QList<Nepomuk::Types::Class> types;
 
215
    foreach(const QUrl& uri, d->m_types)
 
216
        types << Types::Class(uri);
 
217
    return types;
155
218
}
156
219
 
157
220
void Nepomuk::ResourceWatcher::setProperties(const QList< Nepomuk::Types::Property >& properties_)
158
221
{
159
 
    d->m_properties = properties_;
 
222
    d->m_properties.clear();
 
223
    foreach(const Nepomuk::Types::Property& p, properties_) {
 
224
        d->m_properties << p.uri();
 
225
    }
 
226
 
 
227
    if(d->m_connectionInterface) {
 
228
        d->m_connectionInterface->setProperties(convertUris(d->m_properties));
 
229
    }
160
230
}
161
231
 
162
232
void Nepomuk::ResourceWatcher::setResources(const QList< Nepomuk::Resource >& resources_)
163
233
{
164
 
    d->m_resources = resources_;
 
234
    d->m_resources.clear();
 
235
    foreach(const Nepomuk::Resource& res, resources_) {
 
236
        d->m_resources << res.resourceUri();
 
237
    }
 
238
 
 
239
    if(d->m_connectionInterface) {
 
240
        d->m_connectionInterface->setResources(convertUris(d->m_resources));
 
241
    }
165
242
}
166
243
 
167
244
void Nepomuk::ResourceWatcher::setTypes(const QList< Nepomuk::Types::Class >& types_)
168
245
{
169
 
    d->m_types = types_;
 
246
    d->m_types.clear();
 
247
    foreach(const Nepomuk::Types::Class& t, types_) {
 
248
        d->m_types << t.uri();
 
249
    }
 
250
 
 
251
    if(d->m_connectionInterface) {
 
252
        d->m_connectionInterface->setTypes(convertUris(d->m_types));
 
253
    }
170
254
}
171
255
 
172
256
void Nepomuk::ResourceWatcher::slotResourceCreated(const QString &res, const QStringList &types)
179
263
    emit resourceRemoved(KUrl(res), convertUris(types));
180
264
}
181
265
 
182
 
void Nepomuk::ResourceWatcher::slotResourceTypeAdded(const QString &res, const QString &type)
183
 
{
184
 
    emit resourceTypeAdded(KUrl(res), KUrl(type));
185
 
}
186
 
 
187
 
void Nepomuk::ResourceWatcher::slotResourceTypeRemoved(const QString &res, const QString &type)
188
 
{
189
 
    emit resourceTypeRemoved(KUrl(res), KUrl(type));
190
 
}
191
 
 
192
 
void Nepomuk::ResourceWatcher::slotPropertyAdded(const QString& res, const QString& prop, const QDBusVariant& object)
193
 
{
194
 
    emit propertyAdded( Resource::fromResourceUri(KUrl(res)), Types::Property( KUrl(prop) ), object.variant() );
195
 
}
196
 
 
197
 
void Nepomuk::ResourceWatcher::slotPropertyRemoved(const QString& res, const QString& prop, const QDBusVariant& object)
198
 
{
199
 
    emit propertyRemoved( Resource::fromResourceUri(KUrl(res)), Types::Property( KUrl(prop) ), object.variant() );
 
266
void Nepomuk::ResourceWatcher::slotResourceTypesAdded(const QString &res, const QStringList &types)
 
267
{
 
268
    foreach(const QString& type, types) {
 
269
        emit resourceTypeAdded(KUrl(res), KUrl(type));
 
270
    }
 
271
}
 
272
 
 
273
void Nepomuk::ResourceWatcher::slotResourceTypesRemoved(const QString &res, const QStringList &types)
 
274
{
 
275
    foreach(const QString& type, types) {
 
276
        emit resourceTypeRemoved(KUrl(res), KUrl(type));
 
277
    }
 
278
}
 
279
 
 
280
void Nepomuk::ResourceWatcher::slotPropertyAdded(const QString& res, const QString& prop, const QVariantList &objects)
 
281
{
 
282
    foreach(const QVariant& v, objects) {
 
283
        emit propertyAdded( Resource::fromResourceUri(KUrl(res)), Types::Property( KUrl(prop) ), v );
 
284
    }
 
285
}
 
286
 
 
287
void Nepomuk::ResourceWatcher::slotPropertyRemoved(const QString& res, const QString& prop, const QVariantList &objects)
 
288
{
 
289
    foreach(const QVariant& v, objects) {
 
290
        emit propertyRemoved( Resource::fromResourceUri(KUrl(res)), Types::Property( KUrl(prop) ), v );
 
291
    }
 
292
}
 
293
 
 
294
void Nepomuk::ResourceWatcher::slotPropertyChanged(const QString& res, const QString& prop, const QVariantList& oldObjs, const QVariantList& newObjs)
 
295
{
 
296
    emit propertyChanged( Resource::fromResourceUri(KUrl(res)), Types::Property( KUrl(prop) ),
 
297
                          oldObjs, newObjs );
200
298
}
201
299
 
202
300
#include "resourcewatcher.moc"