1
/****************************************************************************
3
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** Contact: Nokia Corporation (qt-info@nokia.com)
6
** This file is part of a Qt Solutions component.
9
** Licensees holding valid Qt Commercial licenses may use this file in
10
** accordance with the Qt Solutions Commercial License Agreement provided
11
** with the Software or, alternatively, in accordance with the terms
12
** contained in a written agreement between you and Nokia.
14
** GNU Lesser General Public License Usage
15
** Alternatively, this file may be used under the terms of the GNU Lesser
16
** General Public License version 2.1 as published by the Free Software
17
** Foundation and appearing in the file LICENSE.LGPL included in the
18
** packaging of this file. Please review the following information to
19
** ensure the GNU Lesser General Public License version 2.1 requirements
20
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22
** In addition, as a special exception, Nokia gives you certain
23
** additional rights. These rights are described in the Nokia Qt LGPL
24
** Exception version 1.1, included in the file LGPL_EXCEPTION.txt in this
27
** GNU General Public License Usage
28
** Alternatively, this file may be used under the terms of the GNU
29
** General Public License version 3.0 as published by the Free Software
30
** Foundation and appearing in the file LICENSE.GPL included in the
31
** packaging of this file. Please review the following information to
32
** ensure the GNU General Public License version 3.0 requirements will be
33
** met: http://www.gnu.org/copyleft/gpl.html.
35
** Please note Third Party Software included with Qt Solutions may impose
36
** additional restrictions and it is the user's responsibility to ensure
37
** that they have met the licensing requirements of the GPL, LGPL, or Qt
38
** Solutions Commercial license and the relevant license of the Third
39
** Party Software they are using.
41
** If you are unsure which license is appropriate for your use, please
42
** contact Nokia at qt-info@nokia.com.
44
****************************************************************************/
49
#include <QtCore/QString>
50
#include <QtCore/QVariant>
51
#include <QtXml/QtXml>
52
#include <QtNetwork/QNetworkAccessManager>
53
#include <QtCore/QUrl>
54
#include <QtCore/QHash>
55
#include <QtCore/QLinkedList>
56
#include <QtCore/QPointer>
57
#include <QtCore/QScopedPointer>
60
# if !defined(QT_QTSOAP_EXPORT) && !defined(QT_QTSOAP_IMPORT)
61
# define QT_QTSOAP_EXPORT
62
# elif defined(QT_QTSOAP_IMPORT)
63
# if defined(QT_QTSOAP_EXPORT)
64
# undef QT_QTSOAP_EXPORT
66
# define QT_QTSOAP_EXPORT __declspec(dllimport)
67
# elif defined(QT_QTSOAP_EXPORT)
68
# undef QT_QTSOAP_EXPORT
69
# define QT_QTSOAP_EXPORT __declspec(dllexport)
72
# define QT_QTSOAP_EXPORT
75
#define SOAPv11_ENVELOPE "http://schemas.xmlsoap.org/soap/envelope/"
76
#define SOAPv11_ENCODING "http://schemas.xmlsoap.org/soap/encoding/"
77
#define SOAPv11_ACTORNEXT "http://schemas.xmlsoap.org/soap/actor/next"
79
#define XML_SCHEMA "http://www.w3.org/1999/XMLSchema"
80
#define XML_SCHEMA_INSTANCE "http://www.w3.org/1999/XMLSchema-instance"
81
#define XML_NAMESPACE "http://www.w3.org/XML/1998/namespace"
87
inline QtSmartPtr(T *data = 0)
94
inline QtSmartPtr(const QtSmartPtr ©)
107
else if ((*r) != 0 && --(*r) == 0) {
113
inline QtSmartPtr &operator =(const QtSmartPtr ©)
120
else if ((*r) != 0 && --(*r) == 0) {
130
inline T &operator *() const
135
inline T *operator ->() const
140
inline T *ptr() const
145
inline T &ref() const
150
inline T *releasedPtr() const
156
inline bool isNull() const
166
class QT_QTSOAP_EXPORT QtSoapQName
169
QtSoapQName(const QString &name = QString::null, const QString &uri = QString::null);
172
QtSoapQName &operator =(const QString &s);
174
QString name() const;
182
bool operator ==(const QtSoapQName &n1, const QtSoapQName &n2);
183
bool operator <(const QtSoapQName &n1, const QtSoapQName &n2);
185
class QT_QTSOAP_EXPORT QtSoapType
189
Duration, DateTime, Time, Date, GYearMonth, GYear, GMonthDay,
190
GDay, GMonth, Boolean, Base64Binary, HexBinary, Float, Double,
191
AnyURI, QName, NOTATION, String, NormalizedString, Token, Language,
192
Name, NMTOKEN, NCName, ID, IDREF, ENTITY, Decimal, Integer,
193
NonPositiveInteger, NegativeInteger, Long, Int, Short,
194
Byte, NonNegativeInteger, UnsignedLong, PositiveInteger,
195
UnsignedInt, UnsignedShort, UnsignedByte,
200
QtSoapType(const QtSoapQName &name, Type t = Other);
201
QtSoapType(const QtSoapType ©);
202
QtSoapType &operator =(const QtSoapType ©);
203
virtual ~QtSoapType();
205
virtual void clear();
207
virtual bool parse(QDomNode);
208
virtual bool isValid() const;
210
virtual int count() const;
211
virtual QVariant value() const;
213
virtual QtSoapType &operator [](int);
214
virtual QtSoapType &operator [](const QtSoapQName &s);
215
virtual QtSoapType &operator [](const QString &name);
217
virtual const QtSoapType &operator [](int) const;
218
virtual const QtSoapType &operator [](const QtSoapQName &s) const;
219
virtual const QtSoapType &operator [](const QString &name) const;
221
virtual QDomElement toDomElement(QDomDocument) const;
223
virtual Type type() const;
224
virtual QString id() const;
225
virtual QString href() const;
226
virtual QString typeName() const;
227
virtual QtSoapQName name() const;
229
virtual QString toString() const;
230
virtual int toInt() const;
231
virtual bool toBool() const;
233
void setName(const QtSoapQName &);
234
void setId(const QString &);
235
void setHref(const QString &);
237
QString errorString() const;
239
static QString typeToName(QtSoapType::Type t);
240
static Type nameToType(const QString &);
251
class QtSoapArrayIterator;
253
class QT_QTSOAP_EXPORT QtSoapArray : public QtSoapType
257
QtSoapArray(const QtSoapQName &name, QtSoapType::Type type = Other,
258
int size0 = -1, int size1 = -1, int size2 = -1, int size3 = -1, int size4 = -1);
259
QtSoapArray(const QtSoapArray ©);
260
QtSoapArray &operator = (const QtSoapArray ©);
265
bool parse(QDomNode node);
266
bool isValid() const;
270
QtSoapType &at(int pos0);
271
QtSoapType &at(int pos0, int pos1);
272
QtSoapType &at(int pos0, int pos1, int pos2);
273
QtSoapType &at(int pos0, int pos1, int pos2, int pos3);
274
QtSoapType &at(int pos0, int pos1, int pos2, int pos3, int pos4);
275
QtSoapType &operator [](int i);
276
QtSoapType &operator [](const QString &);
277
QtSoapType &operator [](const QtSoapQName &);
279
const QtSoapType &at(int pos) const;
280
const QtSoapType &at(int pos0, int pos1) const;
281
const QtSoapType &at(int pos0, int pos1, int pos2) const;
282
const QtSoapType &at(int pos0, int pos1, int pos2, int pos3) const;
283
const QtSoapType &at(int pos0, int pos1, int pos2, int pos3, int pos4) const;
284
const QtSoapType &operator [](int i) const;
285
const QtSoapType &operator [](const QString &) const;
286
const QtSoapType &operator [](const QtSoapQName &) const;
288
void append(QtSoapType *item);
289
void insert(int pos0, QtSoapType *item);
290
void insert(int pos0,int pos1, QtSoapType *item);
291
void insert(int pos0,int pos1,int pos2, QtSoapType *item);
292
void insert(int pos0,int pos1,int pos2,int pos3, QtSoapType *item);
293
void insert(int pos0,int pos1,int pos2,int pos3,int pos4, QtSoapType *item);
295
QDomElement toDomElement(QDomDocument doc) const;
297
friend class QtSoapArrayIterator;
300
QString arraySizeString() const;
301
QString arrayTypeString() const;
303
QHash<int, QtSmartPtr<QtSoapType> > array;
309
int siz0, siz1, siz2, siz3, siz4;
312
class QT_QTSOAP_EXPORT QtSoapArrayIterator
315
QtSoapArrayIterator(QtSoapArray &);
316
QtSoapArrayIterator(const QtSoapArrayIterator ©);
317
QtSoapArrayIterator &operator =(const QtSoapArrayIterator &j);
318
~QtSoapArrayIterator();
321
void pos(int *pos0, int *pos1 = 0, int *pos2 = 0, int *pos3 = 0, int *pos4 = 0) const;
324
const QtSoapType *current() const;
327
bool operator !=(const QtSoapArrayIterator &j) const;
328
bool operator ==(const QtSoapArrayIterator &j) const;
333
QHash<int, QtSmartPtr<QtSoapType> >::Iterator it;
337
class QtSoapStructIterator;
339
class QT_QTSOAP_EXPORT QtSoapStruct : public QtSoapType
343
QtSoapStruct(const QtSoapQName &name);
344
QtSoapStruct(const QtSoapStruct ©);
345
QtSoapStruct &operator =(const QtSoapStruct ©);
350
bool parse(QDomNode node);
351
bool isValid() const;
355
QtSoapType &at(const QtSoapQName &key);
356
const QtSoapType &at(const QtSoapQName &key) const;
358
QtSoapType &operator [](int);
359
QtSoapType &operator [](const QtSoapQName &key);
360
QtSoapType &operator [](const QString &key);
362
const QtSoapType &operator [](int) const;
363
const QtSoapType &operator [](const QtSoapQName &key) const;
364
const QtSoapType &operator [](const QString &key) const;
366
void insert(QtSoapType *item);
368
QDomElement toDomElement(QDomDocument doc) const;
370
friend class QtSoapStructIterator;
373
QList<QtSmartPtr<QtSoapType> > dict;
376
class QT_QTSOAP_EXPORT QtSoapStructIterator
379
QtSoapStructIterator(QtSoapStruct &);
380
~QtSoapStructIterator();
382
QtSoapQName key() const;
384
const QtSoapType *current() const;
387
bool operator !=(const QtSoapStructIterator &j) const;
388
bool operator ==(const QtSoapStructIterator &j) const;
391
QList<QtSmartPtr<QtSoapType> >::Iterator it;
392
QList<QtSmartPtr<QtSoapType> >::Iterator itEnd;
395
class QT_QTSOAP_EXPORT QtSoapSimpleType : public QtSoapType
399
QtSoapSimpleType(const QtSoapQName &name);
400
QtSoapSimpleType(const QtSoapQName &name, int n);
401
QtSoapSimpleType(const QtSoapQName &name, bool n, int dummy);
402
QtSoapSimpleType(const QtSoapQName &name, const QString &n);
403
QtSoapSimpleType(const QtSoapSimpleType ©);
404
QtSoapSimpleType &operator =(const QtSoapSimpleType ©);
409
bool parse(QDomNode node);
410
bool isValid() const;
412
QString toString() const;
415
QVariant value() const;
417
QDomElement toDomElement(QDomDocument doc) const;
423
class QT_QTSOAP_EXPORT QtSoapMessage
425
friend class QtSoapHttpServer;
429
QtSoapMessage(const QtSoapMessage ©);
432
QtSoapMessage &operator =(const QtSoapMessage ©);
434
bool setContent(const QByteArray &buffer);
435
bool setContent(QDomDocument &d);
437
void addBodyItem(QtSoapType *);
438
void addHeaderItem(QtSoapType *);
440
// Method and response
441
const QtSoapType &method() const;
442
const QtSoapType &returnValue() const;
443
void setMethod(const QtSoapQName &);
444
void setMethod(const QString &name, const QString &url = QString::null);
445
void addMethodArgument(QtSoapType *);
446
void addMethodArgument(const QString &uri, const QString &name, const QString &value);
447
void addMethodArgument(const QString &uri, const QString &name, bool value, int dummy);
448
void addMethodArgument(const QString &uri, const QString &name, int value);
459
bool isFault() const;
460
FaultCode faultCode() const;
461
const QtSoapType &faultString() const;
462
const QtSoapType &faultDetail() const;
463
void setFaultCode(FaultCode code);
464
void setFaultString(const QString &fstring);
465
void addFaultDetail(QtSoapType *detail);
469
QString toXmlString(int indent = 0) const;
472
QString errorString() const;
482
bool isValidSoapMessage(const QDomDocument &candidate);
484
QtSoapStruct &body() const;
485
QtSoapStruct &header() const;
492
mutable QtSoapStruct envelope;
500
class QT_QTSOAP_EXPORT QtSoapTypeConstructorBase
503
inline QtSoapTypeConstructorBase()
507
virtual inline ~QtSoapTypeConstructorBase()
511
virtual QtSoapType *createObject(QDomNode) = 0;
513
virtual QString errorString() const = 0;
517
class QT_QTSOAP_EXPORT QtSoapTypeConstructor : public QtSoapTypeConstructorBase
520
QtSoapTypeConstructor()
524
QtSoapType *createObject(QDomNode node)
527
if (t->parse(node)) {
530
errorStr = t->errorString();
536
QString errorString() const
542
mutable QString errorStr;
545
class QT_QTSOAP_EXPORT QtSoapTypeFactory
550
static QScopedPointer<QtSoapTypeFactory> s_instance;
551
static QMutex s_initMutex;
554
~QtSoapTypeFactory();
556
static QtSoapTypeFactory &instance();
558
bool registerHandler(const QString &name, QtSoapTypeConstructorBase *handler);
560
QtSmartPtr<QtSoapType> soapType(QDomNode node) const;
562
QString errorString() const;
565
mutable QString errorStr;
566
QHash<QString, QtSoapTypeConstructorBase *> typeHandlers;
567
QLinkedList<QtSoapTypeConstructorBase*> deleteList;
570
class QT_QTSOAP_EXPORT QtSoapNamespaces
573
void registerNamespace(const QString &prefix, const QString &uri);
574
QString prefixFor(const QString &ns);
576
static QtSoapNamespaces &instance();
579
static QScopedPointer<QtSoapNamespaces> s_instance;
580
static QMutex s_initMutex;
582
QMap<QString, QString> namespaces;
583
mutable QMutex namespacesMutex;
588
class QT_QTSOAP_EXPORT QtSoapHttpTransport : public QObject
593
QtSoapHttpTransport(QObject *parent = 0);
594
~QtSoapHttpTransport();
596
void setHost(const QString &host, bool useSecureHTTP = false, int port = 0);
597
void setHost(const QString &host, int port); //obsolete
598
void setAction(const QString &action);
599
void submitRequest(QtSoapMessage &request, const QString &path);
600
const QtSoapMessage &getResponse() const;
602
QNetworkAccessManager *networkAccessManager();
603
QNetworkReply *networkReply();
606
void responseReady();
607
void responseReady(const QtSoapMessage &response);
610
void readResponse(QNetworkReply *reply);
613
QNetworkAccessManager networkMgr;
614
QPointer<QNetworkReply> networkRep;
617
QtSoapMessage soapResponse;