~ubuntu-branches/ubuntu/trusty/digikam/trusty

« back to all changes in this revision

Viewing changes to extra/kipi-plugins/dlnaexport/extra/hupnp/src/devicehosting/hddoc_parser_p.h

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-11-26 18:24:20 UTC
  • mfrom: (1.9.1) (3.1.23 experimental)
  • Revision ID: package-import@ubuntu.com-20121126182420-qoy6z0nx4ai0wzcl
Tags: 4:3.0.0~beta3-0ubuntu1
* New upstream release
  - Add build-deps :  libhupnp-dev, libqtgstreamer-dev, libmagickcore-dev
* Merge from debian, remaining changes:
  - Make sure libqt4-opengl-dev, libgl1-mesa-dev and libglu1-mesa-dev only
    install on i386,amd64 and powerpc
  - Depend on libtiff-dev instead of libtiff4-dev
  - Drop digikam breaks/replaces kipi-plugins-common since we're past the
    LTS release now
  - digikam to recommend mplayerthumbs | ffmpegthumbs. We currently only
    have latter in the archives, even though former is also supposed to
    be part of kdemultimedia. (LP: #890059)
  - kipi-plugins to recommend www-browser rather than konqueror directly
    since 2.8 no direct usage of konqueror is present in the flickr
    plugin anymore (LP: #1011211)
  - Keep kubuntu_mysqld_executable_name.diff
  - Don't install libkipi translations
  - Keep deps on libcv-dev, libcvaux-dev
  - Keep split packaging of libraries
  - Replace icons from KDE 3 time in debian/xpm.d/*.xpm with the new
    versions (LP: #658047)
* Update debian/not-installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2010, 2011 Tuomo Penttinen, all rights reserved.
 
3
 *
 
4
 *  Author: Tuomo Penttinen <tp@herqq.org>
 
5
 *
 
6
 *  This file is part of Herqq UPnP (HUPnP) library.
 
7
 *
 
8
 *  Herqq UPnP is free software: you can redistribute it and/or modify
 
9
 *  it under the terms of the GNU Lesser General Public License as published by
 
10
 *  the Free Software Foundation, either version 3 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  Herqq UPnP is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
16
 *  GNU Lesser General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU Lesser General Public License
 
19
 *  along with Herqq UPnP. If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
#ifndef HDDOC_PARSER_P_H_
 
23
#define HDDOC_PARSER_P_H_
 
24
 
 
25
//
 
26
// !! Warning !!
 
27
//
 
28
// This file is not part of public API and it should
 
29
// never be included in client code. The contents of this file may
 
30
// change or the file may be removed without of notice.
 
31
//
 
32
 
 
33
#include "../general/hupnp_defs.h"
 
34
#include "../general/hupnp_fwd.h"
 
35
#include "../general/hupnp_global.h"
 
36
#include "../dataelements/hserviceid.h"
 
37
#include "../dataelements/hactioninfo.h"
 
38
#include "../dataelements/hserviceinfo.h"
 
39
#include "../dataelements/hstatevariableinfo.h"
 
40
 
 
41
#include "../devicemodel/hactionarguments.h"
 
42
#include "../devicemodel/hactions_setupdata.h"
 
43
 
 
44
#include <QtCore/QUrl>
 
45
#include <QtCore/QSet>
 
46
#include <QtCore/QList>
 
47
#include <QtCore/QString>
 
48
 
 
49
class QDomElement;
 
50
class QDomDocument;
 
51
 
 
52
namespace Herqq
 
53
{
 
54
 
 
55
namespace Upnp
 
56
{
 
57
 
 
58
//
 
59
//
 
60
//
 
61
enum DocumentErrorTypes
 
62
{
 
63
    NoError,
 
64
    InvalidDeviceDescriptionError,
 
65
    InvalidServiceDescriptionError
 
66
};
 
67
 
 
68
//
 
69
// The class that creates the HUPnP's device model from description files
 
70
//
 
71
class HDocParser
 
72
{
 
73
H_DISABLE_COPY(HDocParser)
 
74
 
 
75
private:
 
76
 
 
77
    QList<QUrl> parseIconList(
 
78
        const QDomElement& iconListElement);
 
79
 
 
80
    bool parseActionArguments(
 
81
        const QDomElement& argListElement,
 
82
        const QHash<QString, HStateVariableInfo>&,
 
83
        QVector<HActionArgument>* inArgs,
 
84
        QVector<HActionArgument>* outArgs,
 
85
        bool* hasRetVal);
 
86
 
 
87
    HStateVariableInfo parseStateVariableInfo_str(
 
88
        const QString& name,
 
89
        const QVariant& defValue,
 
90
        const QDomElement& svElement,
 
91
        HStateVariableInfo::EventingType,
 
92
        HInclusionRequirement);
 
93
 
 
94
    HStateVariableInfo parseStateVariableInfo_numeric(
 
95
        const QString& name,
 
96
        const QVariant& defValue,
 
97
        const QDomElement& svElement,
 
98
        HStateVariableInfo::EventingType,
 
99
        HInclusionRequirement,
 
100
        HUpnpDataTypes::DataType dataTypeEnumValue);
 
101
 
 
102
private:
 
103
 
 
104
    const QByteArray m_loggingIdentifier;
 
105
    HValidityCheckLevel m_cLevel;
 
106
    QString m_lastErrorDescription;
 
107
    DocumentErrorTypes m_lastError;
 
108
 
 
109
public:
 
110
 
 
111
    HDocParser(const QByteArray& loggingIdentifier, HValidityCheckLevel);
 
112
 
 
113
    inline QString lastErrorDescription() const { return m_lastErrorDescription; }
 
114
    inline DocumentErrorTypes lastError() const { return m_lastError; }
 
115
 
 
116
    bool parseRoot(const QString& doc, QDomDocument*, QDomElement*);
 
117
    qint32 readConfigId(const QDomElement&);
 
118
    bool parseDeviceInfo(const QDomElement&, HDeviceInfo*);
 
119
    bool parseServiceInfo(const QDomElement& serviceDefinition, HServiceInfo*);
 
120
 
 
121
    bool parseServiceDescription(
 
122
        const QString& docStr,
 
123
        QDomDocument* doc,
 
124
        QDomElement* stateVarElement,
 
125
        QDomElement* actionElement);
 
126
 
 
127
    bool parseStateVariable(
 
128
        const QDomElement& stateVariableElement,
 
129
        HStateVariableInfo*);
 
130
 
 
131
    bool parseActionInfo(
 
132
        const QDomElement& actionElement,
 
133
        const QHash<QString, HStateVariableInfo>&,
 
134
        HActionInfo*);
 
135
 
 
136
    bool verifySpecVersion(const QDomElement&, QString* err = 0);
 
137
};
 
138
 
 
139
//
 
140
//
 
141
//
 
142
class HDeviceValidator
 
143
{
 
144
private:
 
145
 
 
146
    QString m_lastErrorDescription;
 
147
    DocumentErrorTypes m_lastError;
 
148
 
 
149
public:
 
150
 
 
151
    inline QString lastErrorDescription() const { return m_lastErrorDescription; }
 
152
    inline DocumentErrorTypes lastError() const { return m_lastError; }
 
153
 
 
154
    template<typename Device, typename Service>
 
155
    bool validateRootDevice(Device* device)
 
156
    {
 
157
        class DeviceValidator
 
158
        {
 
159
        private:
 
160
 
 
161
            QSet<QString> eventUrls;
 
162
            QSet<QString> controlUrls;
 
163
            QSet<QString> scpdUrls;
 
164
            QSet<QString> iconUrls;
 
165
            QSet<HServiceId> serviceIds;
 
166
 
 
167
        public:
 
168
 
 
169
            QString m_lastErrorDescription;
 
170
            DocumentErrorTypes m_lastError;
 
171
 
 
172
            bool validateIcons(Device* device)
 
173
            {
 
174
                QList<QUrl> icons = device->info().icons();
 
175
 
 
176
                for (qint32 i = 0; i < icons.size(); ++i)
 
177
                {
 
178
                    QString iconUrl = icons.at(i).toString();
 
179
 
 
180
                    if (iconUrls.contains(iconUrl))
 
181
                    {
 
182
                        m_lastError = InvalidDeviceDescriptionError;
 
183
                        m_lastErrorDescription = QString(
 
184
                            "Multiple icons have the same URL [%1] within a device tree. "
 
185
                            "Icon URLs MUST be unique within a device tree.").arg(
 
186
                                iconUrl);
 
187
 
 
188
                        return false;
 
189
                    }
 
190
                    else
 
191
                    {
 
192
                        iconUrls.insert(iconUrl);
 
193
                    }
 
194
                }
 
195
 
 
196
                return true;
 
197
            }
 
198
 
 
199
            bool validateService(Service* service)
 
200
            {
 
201
                const HServiceId& serviceId = service->info().serviceId();
 
202
 
 
203
                if (serviceIds.contains(serviceId))
 
204
                {
 
205
                    m_lastError = InvalidDeviceDescriptionError;
 
206
                    m_lastErrorDescription = QString(
 
207
                        "ServiceId [%1] encountered more than once. "
 
208
                        "ServiceIDs MUST be unique within a device tree.").arg(
 
209
                            serviceId.toString());
 
210
 
 
211
                    return false;
 
212
                }
 
213
                else
 
214
                {
 
215
                    serviceIds.insert(serviceId);
 
216
                }
 
217
 
 
218
                QString eventUrl = service->info().eventSubUrl().toString();
 
219
                if (!eventUrl.isEmpty())
 
220
                {
 
221
                    if (eventUrls.contains(eventUrl))
 
222
                    {
 
223
                        m_lastError = InvalidDeviceDescriptionError;
 
224
                        m_lastErrorDescription = QString(
 
225
                            "EventSubUrl [%1] encountered more than once."
 
226
                            "EventSubUrls MUST be unique within a device tree.").arg(eventUrl);
 
227
 
 
228
                        return false;
 
229
                    }
 
230
                    else
 
231
                    {
 
232
                        eventUrls.insert(eventUrl);
 
233
                    }
 
234
                }
 
235
 
 
236
                QString scpdUrl = service->info().scpdUrl().toString();
 
237
                if (scpdUrls.contains(scpdUrl))
 
238
                {
 
239
                    m_lastError = InvalidDeviceDescriptionError;
 
240
                    m_lastErrorDescription = QString(
 
241
                        "ScpdUrl [%1] encountered more than once."
 
242
                        "ScpdUrls MUST be unique within a device tree.").arg(eventUrl);
 
243
 
 
244
                    return false;
 
245
                }
 
246
                else
 
247
                {
 
248
                    scpdUrls.insert(eventUrl);
 
249
                }
 
250
 
 
251
                QString controlUrl = service->info().controlUrl().toString();
 
252
                if (controlUrls.contains(controlUrl))
 
253
                {
 
254
                    m_lastError = InvalidDeviceDescriptionError;
 
255
                    m_lastErrorDescription = QString(
 
256
                        "ControlUrl [%1] encountered more than once. "
 
257
                        "ControlUrls MUST be unique within a device tree.").arg(controlUrl);
 
258
 
 
259
                    return false;
 
260
                }
 
261
                else
 
262
                {
 
263
                    controlUrls.insert(controlUrl);
 
264
                }
 
265
 
 
266
                return true;
 
267
            }
 
268
 
 
269
            bool validateDevice(Device* device)
 
270
            {
 
271
                if (!validateIcons(device))
 
272
                {
 
273
                    return false;
 
274
                }
 
275
 
 
276
                QList<Service*> services = device->services();
 
277
                for(qint32 i = 0; i < services.size(); ++i)
 
278
                {
 
279
                    Service* service = services[i];
 
280
                    if (!validateService(service))
 
281
                    {
 
282
                        return false;
 
283
                    }
 
284
                }
 
285
 
 
286
                QList<Device*> devices = device->embeddedDevices();
 
287
                for(qint32 i = 0; i < devices.size(); ++i)
 
288
                {
 
289
                    if (!validateDevice(devices[i]))
 
290
                    {
 
291
                        return false;
 
292
                    }
 
293
                }
 
294
 
 
295
                return true;
 
296
            }
 
297
        };
 
298
 
 
299
        DeviceValidator validator;
 
300
        if (!validator.validateDevice(device))
 
301
        {
 
302
            m_lastError = validator.m_lastError;
 
303
            m_lastErrorDescription = validator.m_lastErrorDescription;
 
304
            return false;
 
305
        }
 
306
 
 
307
        return true;
 
308
    }
 
309
 
 
310
    bool validate(const HStateVariableInfo& setupInfo,
 
311
                  const HStateVariableInfo&)
 
312
    {
 
313
        if (!setupInfo.isValid())
 
314
        {
 
315
            // The setup information was not defined, which means that no
 
316
            // further validation should be run.
 
317
            return true;
 
318
        }
 
319
 
 
320
        return true;
 
321
    }
 
322
 
 
323
    bool validate(const HActionSetup& setupInfo, const HActionInfo& createdInfo)
 
324
    {
 
325
        if (!setupInfo.isValid())
 
326
        {
 
327
            // The setup information was not defined, which means that no
 
328
            // further validation should be run.
 
329
            return true;
 
330
        }
 
331
 
 
332
        bool b = true;
 
333
 
 
334
        // the setup info does not necessarily contain information about the
 
335
        // action arguments, which is fine and it just means that the arguments
 
336
        // should not be validated.
 
337
 
 
338
        if (!setupInfo.inputArguments().isEmpty())
 
339
        {
 
340
            b = setupInfo.inputArguments() != createdInfo.inputArguments();
 
341
        }
 
342
 
 
343
        if (!b)
 
344
        {
 
345
            m_lastError = InvalidServiceDescriptionError;
 
346
            m_lastErrorDescription =
 
347
                "Invalid input arguments provided. Remember to check the "
 
348
                "order in which they are defined.";
 
349
 
 
350
            return false;
 
351
        }
 
352
 
 
353
        if (!setupInfo.outputArguments().isEmpty())
 
354
        {
 
355
            b = setupInfo.outputArguments() != createdInfo.outputArguments();
 
356
        }
 
357
 
 
358
        if (!b)
 
359
        {
 
360
            m_lastError = InvalidServiceDescriptionError;
 
361
            m_lastErrorDescription =
 
362
                "Invalid output arguments provided. Remember to check the "
 
363
                "order in which they are defined.";
 
364
        }
 
365
 
 
366
        return b;
 
367
    }
 
368
};
 
369
 
 
370
}
 
371
}
 
372
 
 
373
#endif /* HDDOC_PARSER_P_H_ */