#include "qtsoap.h"
#include <QtCore/QSet>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
namespace {
QString localName(const QString &tagName)
{
int pos;
if ((pos = tagName.indexOf(':')))
return tagName.right(tagName.length() - pos - 1);
return tagName;
}
QString prefix(const QString &tagName)
{
int pos;
if ((pos = tagName.indexOf(':')))
return tagName.left(pos);
return tagName;
}
}
QtSoapQName::QtSoapQName(const QString &name, const QString &uri)
: n(name), nuri(uri)
{
}
QtSoapQName::~QtSoapQName()
{
}
QString QtSoapQName::name() const
{
return n;
}
QString QtSoapQName::uri() const
{
return nuri;
}
QtSoapQName &QtSoapQName::operator =(const QString &s)
{
n = s;
nuri = "";
return *this;
}
bool operator ==(const QtSoapQName &s1, const QtSoapQName &s2)
{
if (s2.uri() == "")
return s1.name().toLower() == s2.name().toLower();
return s1.name().toLower() == s2.name().toLower()
&& s1.uri().toLower() == s2.uri().toLower();
}
bool operator <(const QtSoapQName &s1, const QtSoapQName &s2)
{
if (s2.uri() == "")
return s1.name().toLower() < s2.name().toLower();
return (s1.uri().toLower()+s1.name().toLower()) < (s2.uri().toLower()+s2.name().toLower());
}
QtSoapType::QtSoapType()
{
t = Other;
errorStr = "Unknown error";
}
QtSoapType::QtSoapType(const QtSoapQName &name, Type type)
: t(type), n(name)
{
errorStr = "Unknown error";
}
QtSoapType::QtSoapType(const QtSoapType ©)
: t(copy.t), errorStr(copy.errorStr), i(copy.i),
n(copy.n), u(copy.u), h(copy.h)
{
}
QtSoapType::~QtSoapType()
{
}
void QtSoapType::clear()
{
}
QtSoapType &QtSoapType::operator =(const QtSoapType ©)
{
t = copy.t;
errorStr = copy.errorStr;
i = copy.i;
n = copy.n;
u = copy.u;
h = copy.h;
return *this;
}
bool QtSoapType::isValid() const
{
return false;
}
QString QtSoapType::typeToName(QtSoapType::Type t)
{
switch (t) {
case Duration: return "duration";
case DateTime: return "dateTime";
case Time: return "time";
case Date: return "date";
case GYearMonth: return "gYearMonth";
case GYear: return "gYear";
case GMonthDay: return "gMonthDay";
case GDay: return "gDay";
case GMonth: return "gMonth";
case Boolean: return "boolean";
case Base64Binary: return "base64Binary";
case HexBinary: return "hexBinary";
case Float: return "float";
case Double: return "double";
case AnyURI: return "anyURI";
case QName: return "QName";
case NOTATION: return "NOTATION";
case String: return "string";
case NormalizedString: return "normalizedString";
case Token: return "token";
case Language: return "language";
case Name: return "name";
case NMTOKEN: return "NMToken";
case NCName: return "NCName";
case ID: return "ID";
case IDREF: return "IDREF";
case ENTITY: return "ENTITY";
case Decimal: return "decimal";
case Integer: return "integer";
case NonPositiveInteger: return "nonPositiveInteger";
case NegativeInteger: return "negativeInteger";
case Long: return "long";
case Int: return "int";
case Short: return "short";
case Byte: return "byte";
case NonNegativeInteger: return "nonNegativeInteger";
case UnsignedLong: return "unsignedLong";
case PositiveInteger: return "positiveInteger";
case UnsignedInt: return "unsignedInt";
case UnsignedShort: return "unsignedShort";
case UnsignedByte: return "unsignedByte";
case Array: return "array";
case Struct: return "struct";
default: return "other";
}
}
QtSoapType::Type QtSoapType::nameToType(const QString &name)
{
const QString type = name.trimmed().toLower();
if (type == "string")
return String;
else if (type == "normalizedstring")
return NormalizedString;
else if (type == "token")
return Token;
else if (type == "language")
return Language;
else if (type == "name")
return Name;
else if (type == "ncname")
return NCName;
else if (type == "nmtoken")
return NMTOKEN;
else if (type == "id")
return ID;
else if (type == "idref")
return IDREF;
else if (type == "entity")
return ENTITY;
else if (type == "base64binary")
return Base64Binary;
else if (type == "hexBinary")
return HexBinary;
else if (type == "anyuri")
return AnyURI;
else if (type == "qname")
return QName;
else if (type == "notation")
return NOTATION;
else if (type == "duration")
return Duration;
else if (type == "datetime")
return DateTime;
else if (type == "time")
return Time;
else if (type == "date")
return Date;
else if (type == "gyearmonth")
return GYearMonth;
else if (type == "gyear")
return GYear;
else if (type == "gmonthday")
return GMonthDay;
else if (type == "gday")
return GDay;
else if (type == "gmonth")
return GMonth;
else if (type == "decimal")
return Decimal;
else if (type == "integer")
return Integer;
else if (type == "nonPositiveinteger")
return NonPositiveInteger;
else if (type == "negativeinteger")
return NegativeInteger;
else if (type == "long")
return Long;
else if (type == "int")
return Int;
else if (type == "short")
return Short;
else if (type == "byte")
return Byte;
else if (type == "nonnegativeinteger")
return NonNegativeInteger;
else if (type == "unsignedlong")
return UnsignedLong;
else if (type == "unsignedint")
return UnsignedInt;
else if (type == "unsignedshort")
return UnsignedShort;
else if (type == "unsignedbyte")
return UnsignedByte;
else if (type == "positiveinteger")
return PositiveInteger;
else if (type == "float")
return Float;
else if (type == "double")
return Double;
else if (type == "boolean")
return Boolean;
else
return Other;
}
QString QtSoapType::toString() const
{
return QString::null;
}
int QtSoapType::toInt() const
{
return 0;
}
bool QtSoapType::toBool() const
{
return false;
}
QDomElement QtSoapType::toDomElement(QDomDocument document) const
{
Q_UNUSED(document);
return QDomElement();
}
QString QtSoapType::typeName() const
{
return QtSoapType::typeToName(type());
}
QtSoapType::Type QtSoapType::type() const
{
return t;
}
QtSoapQName QtSoapType::name() const
{
return n;
}
QString QtSoapType::id() const
{
return i;
}
QString QtSoapType::href() const
{
return h;
}
void QtSoapType::setName(const QtSoapQName &name)
{
this->n = name;
}
void QtSoapType::setId(const QString &i)
{
this->i = i;
}
void QtSoapType::setHref(const QString &h)
{
this->h = h;
}
QVariant QtSoapType::value() const
{
return QVariant();
}
QString QtSoapType::errorString() const
{
return errorStr;
}
int QtSoapType::count() const
{
return 0;
}
QtSoapType &QtSoapType::operator [](int )
{
static QtSoapType NIL;
return NIL;
}
QtSoapType &QtSoapType::operator [](const QtSoapQName & )
{
static QtSoapType NIL;
return NIL;
}
QtSoapType &QtSoapType::operator [](const QString & )
{
static QtSoapType NIL;
return NIL;
}
const QtSoapType &QtSoapType::operator [](int ) const
{
static QtSoapType NIL;
return NIL;
}
const QtSoapType &QtSoapType::operator [](const QtSoapQName & ) const
{
static QtSoapType NIL;
return NIL;
}
const QtSoapType &QtSoapType::operator [](const QString & ) const
{
static QtSoapType NIL;
return NIL;
}
bool QtSoapType::parse(QDomNode )
{
return false;
}
QtSoapArray::QtSoapArray()
: QtSoapType(QtSoapQName(), Array), arrayType(Other), order(1)
{
lastIndex = 0;
siz0 = 0;
siz1 = 0;
siz2 = 0;
siz3 = 0;
siz4 = 0;
}
QtSoapArray::QtSoapArray(const QtSoapQName &name, QtSoapType::Type type, int size0,
int size1, int size2, int size3, int size4)
: QtSoapType(name, Array), lastIndex(0), arrayType(type),
siz0(size0), siz1(size1), siz2(size2), siz3(size3),
siz4(size4)
{
if (size4 != -1) order = 5;
else if (size3 != -1) order = 4;
else if (size2 != -1) order = 3;
else if (size1 != -1) order = 2;
else order = 1;
}
QtSoapArray::QtSoapArray(const QtSoapArray ©)
: QtSoapType(copy)
{
*this = copy;
}
QtSoapArray::~QtSoapArray()
{
}
void QtSoapArray::clear()
{
array.clear();
lastIndex = 0;
arrayType = Other;
siz0 = siz1 = siz2 = siz3 = siz4 = 0;
order = -1;
}
QtSoapArray &QtSoapArray::operator = (const QtSoapArray ©)
{
if (this == ©)
return *this;
t = copy.t;
errorStr = copy.errorStr;
i = copy.i;
n = copy.n;
u = copy.u;
h = copy.h;
lastIndex = copy.lastIndex;
order = copy.order;
siz0 = copy.siz0;
siz1 = copy.siz1;
siz2 = copy.siz2;
siz3 = copy.siz3;
siz4 = copy.siz4;
array = copy.array;
return *this;
}
void QtSoapArray::append(QtSoapType *item)
{
if (order != 1) {
qWarning("Attempted to insert item at position (%i) in %i-dimensional QtSoapArray.",
lastIndex, order);
return;
}
if (array.count() == 0) {
array.insert(0, item);
} else {
array.insert(lastIndex + 1, item);
++lastIndex;
}
}
void QtSoapArray::insert(int pos, QtSoapType *item)
{
if (arrayType == Other)
arrayType = item->type();
if (item->type() != arrayType) {
qWarning("Attempted to insert item of type \"%s\" in QtSoapArray of type \"%s\".",
item->typeName().toLatin1().constData(), QtSoapType::typeToName(arrayType).toLatin1().constData());
return;
}
if (order == -1)
order = 1;
else if (order == 1 && pos > lastIndex)
lastIndex = pos;
array.insert(pos, item);
}
void QtSoapArray::insert(int pos0, int pos1, QtSoapType *item)
{
if (order != 2) {
qWarning("Attempted to insert item at position (%i, %i)"
" in %i-dimensional QtSoapArray.",
pos0, pos1, order);
return;
}
if (pos0 < 0 || pos0 >= siz0 || pos1 < 0 || pos1 >= siz1) {
qWarning("Attempted to insert item at position (%i, %i)"
" when range of QtSoapArray is (0..%i, 0..%i)",
pos0, pos1, siz0 - 1, siz1 - 1);
return;
}
insert((pos0 * siz1) + pos1, item);
}
void QtSoapArray::insert(int pos0, int pos1, int pos2, QtSoapType *item)
{
if (order != 3) {
qWarning("Attempted to insert item at position (%i, %i, %i)"
" in %i-dimensional QtSoapArray.",
pos0, pos1, pos2, order);
return;
}
if (pos0 < 0 || pos0 >= siz0 || pos1 < 0 || pos1 >= siz1 || pos2 < 0 || pos2 >= siz2) {
qWarning("Attempted to insert item at position (%i, %i, %i)"
" when range of QtSoapArray is (0..%i, 0..%i, 0..%i)",
pos0, pos1, pos2, siz0 - 1, siz1 - 1, siz2 - 1);
return;
}
insert((pos0 * siz2 * siz1) + (pos1 * siz2) + pos2, item);
}
void QtSoapArray::insert(int pos0, int pos1, int pos2, int pos3, QtSoapType *item)
{
if (order != 4) {
qWarning("Attempted to insert item at position (%i, %i, %i, %i)"
" in %i-dimensional QtSoapArray.",
pos0, pos1, pos2, pos3, order);
return;
}
insert((pos0 * siz3 * siz2 * siz1)
+ (pos1 * siz3 * siz2)
+ (pos2 * siz3)
+ pos3,
item);
}
void QtSoapArray::insert(int pos0, int pos1, int pos2, int pos3, int pos4,
QtSoapType *item)
{
if (order != 5) {
qWarning("Attempted to insert item at position (%i, %i, %i, %i, %i)"
" in %i-dimensional QtSoapArray.",
pos0, pos1, pos2, pos3, pos4, order);
return;
}
insert((pos0 * siz4 * siz3 * siz2 * siz1)
+ (pos1 * siz4 * siz3 * siz2)
+ (pos2 * siz4 * siz3)
+ (pos3 * siz4)
+ pos4,
item);
}
QString QtSoapArray::arraySizeString() const
{
QString arraySize = "[";
if (siz0 != -1) {
arraySize += QString::number(siz0);
if (order > 1) arraySize += "," + QString::number(siz1);
if (order > 2) arraySize += "," + QString::number(siz2);
if (order > 3) arraySize += "," + QString::number(siz3);
if (order > 4) arraySize += "," + QString::number(siz4);
}
arraySize += "]";
return arraySize;
}
QString QtSoapArray::arrayTypeString() const
{
if (arrayType != Array)
return QtSoapType::typeToName(arrayType);
QString atString;
QtSoapArray *ar = const_cast<QtSoapArray *>(this);
do {
if (ar->count() == 0)
break;
atString += ar->arraySizeString();
QtSoapArrayIterator it(*const_cast<QtSoapArray *>(this));
if (it.data()->type() != Array)
break;
ar = (QtSoapArray *)it.data();
} while (ar);
QtSoapArrayIterator it(*const_cast<QtSoapArray *>(this));
if (ar->count() == 0)
atString = QtSoapSimpleType::typeToName(Int) + atString;
else
atString = it.data()->typeName() + atString;
return atString;
}
QDomElement QtSoapArray::toDomElement(QDomDocument doc) const
{
QString prefix = QtSoapNamespaces::instance().prefixFor(n.uri());
QDomElement a = n.uri() == ""
? doc.createElement( n.name())
: doc.createElementNS(n.uri(), prefix + ":" + n.name());
QString schemaprefix = QtSoapNamespaces::instance().prefixFor(XML_SCHEMA_INSTANCE);
a.setAttributeNS(XML_SCHEMA_INSTANCE, schemaprefix + ":type", "xsd:Array");
QString encprefix = QtSoapNamespaces::instance().prefixFor(SOAPv11_ENCODING);
a.setAttributeNS(SOAPv11_ENCODING, encprefix + ":arrayType", "xsd:" + arrayTypeString());
for (QtSoapArrayIterator i(*const_cast<QtSoapArray *>(this)); !i.atEnd(); ++i) {
QDomElement item = i.data()->toDomElement(doc);
item.setTagName("item");
int pos0, pos1, pos2, pos3, pos4;
i.pos(&pos0, &pos1, &pos2, &pos3, &pos4);
QString position = "[" + QString::number(pos0);
if (order > 1) position += "," + QString::number(pos1);
if (order > 2) position += "," + QString::number(pos2);
if (order > 3) position += "," + QString::number(pos3);
if (order > 4) position += "," + QString::number(pos4);
position += "]";
QString envprefix = QtSoapNamespaces::instance().prefixFor(SOAPv11_ENVELOPE);
item.setAttributeNS(SOAPv11_ENVELOPE, envprefix + ":position", position);
a.appendChild(item);
}
return a;
}
bool QtSoapArray::isValid() const
{
return true;
}
bool QtSoapArray::parse(QDomNode node)
{
if (node.isNull() || !node.isElement())
return false;
QDomElement e = node.toElement();
QDomAttr typeattr = e.attributeNode("type");
if (!typeattr.isNull() && (localName(typeattr.value()).toLower() != "array"))
return false;
QDomNodeList children = e.childNodes();
int c = children.count();
array.clear();
int pos = 0;
for (int i = 0; i < c; ++i) {
QDomNode n = children.item(i);
if (n.isComment())
continue;
if (!n.isElement()){
return false;
}
QDomElement elem = n.toElement();
QtSmartPtr<QtSoapType> type = QtSoapTypeFactory::instance().soapType(elem);
if (!type.ptr()) {
return false;
}
QDomAttr posattr = elem.attributeNode("position");
if (!posattr.isNull())
pos = posattr.value().toInt();
array.insert(pos, type);
++pos;
}
setName(QtSoapQName(localName(e.tagName()), e.namespaceURI()));
return true;
}
int QtSoapArray::count() const
{
return array.count();
}
QtSoapType &QtSoapArray::operator [](int pos)
{
return at(pos);
}
QtSoapType &QtSoapArray::operator [](const QString &s)
{
return QtSoapType::operator[](s);
}
QtSoapType &QtSoapArray::operator [](const QtSoapQName &s)
{
return QtSoapType::operator[](s);
}
const QtSoapType &QtSoapArray::operator [] (int pos) const
{
return at(pos);
}
const QtSoapType &QtSoapArray::operator [](const QString &s) const
{
return QtSoapType::operator[](s);
}
const QtSoapType &QtSoapArray::operator [](const QtSoapQName &s) const
{
return QtSoapType::operator[](s);
}
QtSoapType &QtSoapArray::at(int pos)
{
static QtSoapType NIL;
if (array.find(pos) != array.end())
return *array[pos];
else
return NIL;
}
QtSoapType &QtSoapArray::at(int pos0, int pos1)
{
return at(pos0 * siz1 + pos1);
}
QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2)
{
return at((pos0 * siz2 * siz1) + (pos1 * siz2) + pos2);
}
QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3)
{
return at((pos0 * siz3 * siz2 * siz1)
+ (pos1 * siz3 * siz2)
+ (pos2 * siz3)
+ pos3);
}
QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3, int pos4)
{
return at((pos0 * siz4 * siz3 * siz2 * siz1)
+ (pos1 * siz4 * siz3 * siz2)
+ (pos2 * siz4 * siz3)
+ (pos3 * siz4)
+ pos4);
}
const QtSoapType &QtSoapArray::at(int pos) const
{
static QtSoapType NIL;
if (array.find(pos) != array.end())
return *array[pos];
else
return NIL;
}
const QtSoapType &QtSoapArray::at(int pos0, int pos1) const
{
return at(pos0 * siz1 + pos1);
}
const QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2) const
{
return at((pos0 * siz2 * siz1) + (pos1 * siz2) + pos2);
}
const QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3) const
{
return at((pos0 * siz3 * siz2 * siz1)
+ (pos1 * siz3 * siz2)
+ (pos2 * siz3)
+ pos3);
}
const QtSoapType &QtSoapArray::at(int pos0, int pos1, int pos2, int pos3, int pos4) const
{
return at((pos0 * siz4 * siz3 * siz2 * siz1)
+ (pos1 * siz4 * siz3 * siz2)
+ (pos2 * siz4 * siz3)
+ (pos3 * siz4)
+ pos4);
}
QtSoapArrayIterator::QtSoapArrayIterator(QtSoapArray &array)
: it(array.array.begin()), arr(&array)
{
}
QtSoapArrayIterator::QtSoapArrayIterator(const QtSoapArrayIterator ©)
: it(copy.it), arr(copy.arr)
{
}
bool QtSoapArrayIterator::atEnd() const
{
return (it == arr->array.end());
}
QtSoapArrayIterator &QtSoapArrayIterator::operator =(const QtSoapArrayIterator ©)
{
it = copy.it;
arr = copy.arr;
return *this;
}
QtSoapArrayIterator::~QtSoapArrayIterator()
{
}
int QtSoapArrayIterator::pos() const
{
return it.key();
}
void QtSoapArrayIterator::pos(int *pos0, int *pos1, int *pos2,
int *pos3, int *pos4) const
{
const int key = it.key();
switch (arr->order) {
case 1:
if (pos0) *pos0 = key;
break;
case 2: {
const int tmp = key / arr->siz1;
if (pos0) *pos0 = tmp;
if (pos1) *pos1 = key - (tmp * arr->siz1);
}
break;
case 3: {
const int tmp0 = key / (arr->siz2 * arr->siz1);
const int tmp1 = key - (tmp0 * (arr->siz2 * arr->siz1));
const int tmp2 = tmp1 / arr->siz2;
if (pos0) *pos0 = tmp0;
if (pos1) *pos1 = tmp2;
if (pos2) *pos2 = tmp1 - (tmp2 * arr->siz2);
}
break;
case 4: {
const int tmp0 = key / (arr->siz3 * arr->siz2 * arr->siz1);
const int tmp1 = key - (tmp0 * (arr->siz3 * arr->siz2 * arr->siz1));
const int tmp2 = tmp1 / (arr->siz3 * arr->siz2);
const int tmp3 = tmp1 - (tmp2 * (arr->siz3 * arr->siz2));
const int tmp4 = tmp3 / arr->siz3;
const int tmp5 = tmp3 - (tmp4 * arr->siz3);
if (pos0) *pos0 = tmp0;
if (pos1) *pos1 = tmp2;
if (pos2) *pos2 = tmp4;
if (pos3) *pos3 = tmp5;
}
break;
case 5: {
const int tmp0 = key / (arr->siz4 * arr->siz3 * arr->siz2 * arr->siz1);
const int tmp1 = key - (tmp0 * (arr->siz4 * arr->siz3 * arr->siz2 * arr->siz1));
const int tmp2 = tmp1 / (arr->siz4 * arr->siz3 * arr->siz2);
const int tmp3 = tmp1 - (tmp2 * (arr->siz4 * arr->siz3 * arr->siz2));
const int tmp4 = tmp3 / (arr->siz4 * arr->siz3);
const int tmp5 = tmp3 - (tmp4 * arr->siz4 * arr->siz3);
const int tmp6 = tmp5 / arr->siz3;
const int tmp7 = tmp5 - (tmp6 * arr->siz3);
if (pos0) *pos0 = tmp0;
if (pos1) *pos1 = tmp2;
if (pos2) *pos2 = tmp4;
if (pos3) *pos3 = tmp6;
if (pos4) *pos4 = tmp7;
}
break;
default:
break;
}
}
QtSoapType *QtSoapArrayIterator::data()
{
if (it == arr->array.end())
return 0;
return it.value().ptr();
}
const QtSoapType *QtSoapArrayIterator::current() const
{
if (it == arr->array.end())
return 0;
return it.value().ptr();
}
void QtSoapArrayIterator::operator ++()
{
++it;
}
bool QtSoapArrayIterator::operator != (const QtSoapArrayIterator &j) const
{
return it != j.it;
}
bool QtSoapArrayIterator::operator == (const QtSoapArrayIterator &j) const
{
return it == j.it;
}
QtSoapStruct::QtSoapStruct()
: QtSoapType(QtSoapQName(), Struct)
{
}
QtSoapStruct::QtSoapStruct(const QtSoapQName &name)
: QtSoapType(name, Struct)
{
}
QtSoapStruct::QtSoapStruct(const QtSoapStruct ©)
: QtSoapType(copy)
{
*this = copy;
}
QtSoapStruct::~QtSoapStruct()
{
}
void QtSoapStruct::clear()
{
dict.clear();
}
QtSoapStruct &QtSoapStruct::operator =(const QtSoapStruct ©)
{
if (this == ©)
return *this;
t = copy.t;
errorStr = copy.errorStr;
i = copy.i;
n = copy.n;
u = copy.u;
h = copy.h;
i = copy.i;
dict = copy.dict;
return *this;
}
void QtSoapStruct::insert(QtSoapType *item)
{
dict.append(item);
}
QDomElement QtSoapStruct::toDomElement(QDomDocument doc) const
{
QString prefix = QtSoapNamespaces::instance().prefixFor(n.uri());
QDomElement a = n.uri() == ""
? doc.createElement(n.name())
: doc.createElementNS(n.uri(), prefix + ":" + n.name());
for (QtSoapStructIterator i(*const_cast<QtSoapStruct *>(this)); i.data(); ++i)
a.appendChild(i.data()->toDomElement(doc));
return a;
}
bool QtSoapStruct::isValid() const
{
return true;
}
bool QtSoapStruct::parse(QDomNode node)
{
if (node.isNull() || !node.isElement())
return false;
QDomElement e = node.toElement();
QDomNodeList children = e.childNodes();
int c = children.count();
dict.clear();
for (int i = 0; i < c; ++i) {
QDomNode n = children.item(i);
if (n.isComment())
continue;
if (!n.isElement()){
errorStr = "In the struct element " + e.tagName();
errorStr += ", the " + QString::number(i) + "th child ";
errorStr += "is not an element.";
return false;
}
QtSmartPtr<QtSoapType> type = QtSoapTypeFactory::instance().soapType(n.toElement());
if (!type.ptr()) {
errorStr = "In the struct element " + e.tagName();
errorStr += ", child #" + QString::number(i) + ", ";
errorStr += n.toElement().tagName() + ", was not recognized as a SOAP type.";
return false;
}
dict.append(type);
}
setName(QtSoapQName(localName(e.tagName()), e.namespaceURI()));
return true;
}
int QtSoapStruct::count() const
{
return dict.count();
}
QtSoapType &QtSoapStruct::operator [](const QtSoapQName &key)
{
return at(key);
}
const QtSoapType &QtSoapStruct::operator [](const QtSoapQName &key) const
{
return at(key);
}
QtSoapType &QtSoapStruct::operator [](const QString &key)
{
return at(QtSoapQName(key, ""));
}
const QtSoapType &QtSoapStruct::operator [](const QString &key) const
{
return at(QtSoapQName(key, ""));
}
QtSoapType &QtSoapStruct::operator [](int i)
{
static QtSoapType NIL;
if (i < 0 || i >= dict.count())
return NIL;
return *dict[i].ptr();
}
const QtSoapType &QtSoapStruct::operator [](int i) const
{
static QtSoapType NIL;
if (i < 0 || i >= dict.count())
return NIL;
return *dict[i].ptr();
}
QtSoapType &QtSoapStruct::at(const QtSoapQName &key)
{
static QtSoapType NIL;
QListIterator<QtSmartPtr<QtSoapType> > it(dict);
while (it.hasNext()) {
QtSoapType *ret = it.next().ptr();
if (ret->name() == key)
return *ret;
}
return NIL;
}
const QtSoapType &QtSoapStruct::at(const QtSoapQName &key) const
{
static QtSoapType NIL;
for (QtSoapStructIterator i(*const_cast<QtSoapStruct *>(this)); i.current(); ++i)
if (i.key() == key)
return *i.current();
return NIL;
}
QtSoapStructIterator::QtSoapStructIterator(QtSoapStruct &s) : it(s.dict.begin()), itEnd(s.dict.end())
{
}
QtSoapStructIterator::~QtSoapStructIterator()
{
}
QtSoapQName QtSoapStructIterator::key() const
{
if (it == itEnd)
return QtSoapQName();
return (*it)->name();
}
QtSoapType *QtSoapStructIterator::data()
{
if (it == itEnd)
return 0;
return it->ptr();
}
const QtSoapType *QtSoapStructIterator::current() const
{
if (it == itEnd)
return 0;
return it->ptr();
}
void QtSoapStructIterator::operator ++()
{
if (it == itEnd)
return;
++it;
}
bool QtSoapStructIterator::operator !=(const QtSoapStructIterator &j) const
{
return it != j.it;
}
bool QtSoapStructIterator::operator ==(const QtSoapStructIterator &j) const
{
return it == j.it;
}
QtSoapSimpleType::QtSoapSimpleType()
{
}
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name)
: QtSoapType(name)
{
}
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name, int n)
: QtSoapType(name, Int), v(QVariant(n))
{
}
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name, bool n, int)
: QtSoapType(name, Boolean), v(QVariant(n))
{
}
QtSoapSimpleType::QtSoapSimpleType(const QtSoapQName &name, const QString &n)
: QtSoapType(name, String), v(QVariant(n))
{
}
QtSoapSimpleType::QtSoapSimpleType(const QtSoapSimpleType ©)
: QtSoapType(copy), v(copy.v)
{
}
QtSoapSimpleType::~QtSoapSimpleType()
{
}
void QtSoapSimpleType::clear()
{
v.clear();
}
QDomElement QtSoapSimpleType::toDomElement(QDomDocument doc) const
{
QString prefix = QtSoapNamespaces::instance().prefixFor(n.uri());
QDomElement a = n.uri() == ""
? doc.createElement(n.name())
: doc.createElementNS(n.uri(), prefix + ":" + n.name());
QString schemaprefix = QtSoapNamespaces::instance().prefixFor(XML_SCHEMA_INSTANCE);
a.setAttributeNS(XML_SCHEMA_INSTANCE, schemaprefix + ":type", "xsd:" + typeName());
a.appendChild(doc.createTextNode(v.toString()));
return a;
}
bool QtSoapSimpleType::isValid() const
{
return true;
}
QtSoapSimpleType &QtSoapSimpleType::operator =(const QtSoapSimpleType ©)
{
t = copy.t;
errorStr = copy.errorStr;
i = copy.i;
n = copy.n;
u = copy.u;
h = copy.h;
v = copy.v;
return *this;
}
bool QtSoapSimpleType::parse(QDomNode node)
{
if (node.isNull() || !node.isElement())
return false;
QDomElement e = node.toElement();
QDomAttr typeattr = e.attributeNode("type");
QString type = typeattr.isNull() ? QString("string") : localName(typeattr.value()).toLower();
t = QtSoapType::nameToType(type);
switch (t) {
case Duration:
case DateTime:
case Time:
case Date:
case GYearMonth:
case GYear:
case GMonthDay:
case GDay:
case GMonth:
case Base64Binary:
case HexBinary:
case AnyURI:
case QName:
case NOTATION:
case String:
case NormalizedString:
case Token:
case Language:
case Name:
case NMTOKEN:
case NCName:
case ID:
case IDREF:
case ENTITY:
v = QVariant(e.text());
break;
case Float:
v = QVariant(e.text().toFloat());
break;
case Double:
v = QVariant(e.text().toDouble());
break;
case Decimal:
case Integer:
case NonPositiveInteger:
case NegativeInteger:
case Long:
case Int:
case Short:
case Byte:
case NonNegativeInteger:
case UnsignedLong:
case PositiveInteger:
case UnsignedInt:
case UnsignedShort:
case UnsignedByte:
if (e.text() == "" || (e.text() != "" && (e.text()[0].isNumber() || e.text()[0] == '-')))
v = QVariant(e.text().toInt());
else {
errorStr = "Type error at element \"" + e.tagName() + "\"";
return false;
}
break;
case Boolean: {
QString val = e.text().trimmed().toLower();
if (val == "false")
v = QVariant(false);
else if (val == "true")
v = QVariant(true);
}
break;
default:
v = e.text();
break;
}
setName(QtSoapQName(localName(e.tagName()), e.namespaceURI()));
return true;
}
QString QtSoapSimpleType::toString() const
{
return v.toString();
}
int QtSoapSimpleType::toInt() const
{
return v.toInt();
}
bool QtSoapSimpleType::toBool() const
{
return v.toBool();
}
QVariant QtSoapSimpleType::value() const
{
return v;
}
QtSoapMessage::QtSoapMessage()
: type(OtherType), envelope(QtSoapQName("Envelope", SOAPv11_ENVELOPE))
{
init();
}
QtSoapMessage::QtSoapMessage(const QtSoapMessage ©)
: type(copy.type), envelope(copy.envelope), m(copy.m), margs(copy.margs),
errorStr(copy.errorStr)
{
init();
}
QtSoapMessage::~QtSoapMessage()
{
}
void QtSoapMessage::init()
{
QtSoapNamespaces::instance().registerNamespace("SOAP-ENV", SOAPv11_ENVELOPE);
QtSoapNamespaces::instance().registerNamespace("SOAP-ENC", SOAPv11_ENCODING);
QtSoapNamespaces::instance().registerNamespace("xsi", XML_SCHEMA_INSTANCE);
QtSoapNamespaces::instance().registerNamespace("xsd", XML_SCHEMA);
}
void QtSoapMessage::clear()
{
type = OtherType;
envelope.clear();
m = QtSoapQName();
margs.clear();
errorStr = "Unknown error";
}
QtSoapMessage &QtSoapMessage::operator =(const QtSoapMessage ©)
{
envelope = copy.envelope;
m = copy.m;
margs = copy.margs;
errorStr = copy.errorStr;
return *this;
}
bool QtSoapMessage::setContent(QDomDocument &d)
{
if (isValidSoapMessage(d)) {
clear();
QDomNode node = d.firstChild();
if (!node.isElement())
node = node.nextSibling();
if (envelope.parse(node))
return true;
}
return false;
}
bool QtSoapMessage::setContent(const QByteArray &buffer)
{
int errorLine, errorColumn;
QString errorMsg;
QDomDocument doc;
if (!doc.setContent(buffer, true, &errorMsg,
&errorLine, &errorColumn)) {
QString s;
s.sprintf("%s at line %i, column %i", errorMsg.toLatin1().constData(),
errorLine, errorColumn);
setFaultCode(VersionMismatch);
setFaultString("XML parse error");
addFaultDetail(new QtSoapSimpleType(QtSoapQName("ParseError"), s));
return false;
}
if (!isValidSoapMessage(doc))
return false;
QDomNode node = doc.firstChild();
if (!node.isElement())
node = node.nextSibling();
bool res = envelope.parse(node);
if (!res)
qDebug("QtSoapMessage::setContent(), parsing failed: %s", envelope.errorString().toLatin1().constData());
return res;
}
bool QtSoapMessage::isValidSoapMessage(const QDomDocument &candidate)
{
QDomNode tmp = candidate.firstChild();
if (tmp.isNull())
return false;
if (tmp.isProcessingInstruction()) {
tmp = tmp.nextSibling();
if (tmp.isNull() || !tmp.isElement())
return false;
}
QDomElement tmpe = tmp.toElement();
if (localName(tmpe.tagName()).toUpper() != "ENVELOPE") {
setFaultCode(VersionMismatch);
setFaultString("SOAP structure invalid");
addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "root element \"" + tmpe.localName()
+ "\"/\"" + tmpe.tagName() + "\" is not envelope"));
return false;
}
tmp = tmp.firstChild();
if (tmp.isNull() || !tmp.isElement()) {
setFaultCode(VersionMismatch);
setFaultString("SOAP structure invalid");
addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "mandatory body element missing"));
return false;
}
QDomElement tmpe2 = tmp.toElement();
bool foundHeader = false;
if (localName(tmpe2.tagName()).toUpper() == "HEADER") {
foundHeader = true;
tmp = tmp.nextSibling();
}
if (!foundHeader && (tmp.isNull() || !tmp.isElement())) {
setFaultCode(VersionMismatch);
setFaultString("SOAP structure invalid");
addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "mandatory body element missing"));
return false;
}
QDomElement tmpe3 = tmp.toElement();
if (localName(tmpe3.tagName()).toUpper() != "BODY") {
setFaultCode(VersionMismatch);
setFaultString("SOAP structure invalid");
addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "mandatory body element missing"));
return false;
}
if (tmpe.namespaceURI() != SOAPv11_ENVELOPE) {
setFaultCode(VersionMismatch);
setFaultString("SOAP structure invalid");
addFaultDetail(new QtSoapSimpleType(QtSoapQName("extra"), "Unsupported namespace for envelope element"));
return false;
}
return true;
}
QString QtSoapMessage::toXmlString(int indent) const
{
QDomImplementation impl;
QDomDocument doc = impl.createDocument(QString(), QString("placeholder"),
QDomDocumentType());
doc.removeChild(doc.firstChild());
doc.appendChild(envelope.toDomElement(doc));
QDomElement env = doc.firstChild().toElement();
env.setAttribute(QtSoapNamespaces::instance().prefixFor(SOAPv11_ENVELOPE)
+ ":" + "encodingStyle",
SOAPv11_ENCODING);
env.setAttribute("xmlns:" + QtSoapNamespaces::instance().prefixFor(XML_SCHEMA),
XML_SCHEMA);
return doc.toString(indent);
}
QString QtSoapMessage::errorString() const
{
return errorStr;
}
void QtSoapMessage::addBodyItem(QtSoapType *item)
{
body().insert(item);
}
void QtSoapMessage::addHeaderItem(QtSoapType *item)
{
QtSoapType &headerTmp = envelope[QtSoapQName("Header", SOAPv11_ENVELOPE)];
if (!headerTmp.isValid())
envelope.insert(new QtSoapStruct(QtSoapQName("Header", SOAPv11_ENVELOPE)));
QtSoapStruct &header = (QtSoapStruct &)envelope[QtSoapQName("Header", SOAPv11_ENVELOPE)];
header.insert(item);
}
const QtSoapType &QtSoapMessage::returnValue() const
{
static QtSoapType NIL;
const QtSoapType &meth = method();
if (!meth.isValid() || meth.type() != QtSoapType::Struct)
return NIL;
QtSoapStruct &m = (QtSoapStruct &) meth;
if (m.count() == 0)
return NIL;
QtSoapStructIterator mi(m);
return *mi.data();
}
const QtSoapType &QtSoapMessage::faultDetail() const
{
return body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)][QtSoapQName("Detail")];
}
const QtSoapType &QtSoapMessage::faultString() const
{
return body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)][QtSoapQName("Faultstring")];
}
bool QtSoapMessage::isFault() const
{
return faultCode() != Other;
}
QtSoapMessage::FaultCode QtSoapMessage::faultCode() const
{
QtSoapType &code = body()[QtSoapQName("Fault")][QtSoapQName("Faultcode")];
if (!code.isValid() || (code.type() != QtSoapType::String
&& code.type() != QtSoapType::QName))
return Other;
QtSoapSimpleType &fcode = (QtSoapSimpleType &)code;
QString fcodestr = fcode.value().toString();
int pos;
if ((pos = fcodestr.indexOf('.')) != -1)
fcodestr.truncate(pos);
if (localName(fcodestr.toLower()) == "versionmismatch")
return VersionMismatch;
if (localName(fcodestr.toLower()) == "mustunderstand")
return MustUnderstand;
if (localName(fcodestr.toLower()) == "client")
return Client;
if (localName(fcodestr.toLower()) == "server")
return Server;
return Other;
}
QtSoapStruct &QtSoapMessage::body() const
{
const QtSoapQName bodyName("Body", SOAPv11_ENVELOPE);
QtSoapType &bodyTmp = envelope[bodyName];
if (!bodyTmp.isValid())
envelope.insert(new QtSoapStruct(bodyName));
return (QtSoapStruct &)envelope[bodyName];
}
QtSoapStruct &QtSoapMessage::header() const
{
const QtSoapQName headerName("Header", SOAPv11_ENVELOPE);
QtSoapType &headerTmp = envelope[headerName];
if (!headerTmp.isValid())
envelope.insert(new QtSoapStruct(headerName));
return (QtSoapStruct &)envelope[headerName];
}
void QtSoapMessage::setFaultCode(FaultCode code)
{
if (type != Fault && type != OtherType) {
clear();
type = Fault;
}
if (!body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)].isValid())
addBodyItem(new QtSoapStruct(QtSoapQName("Fault", SOAPv11_ENVELOPE)));
QString codeStr;
switch (code) {
case VersionMismatch:
codeStr = "SOAP-ENV:VersionMismatch";
break;
case MustUnderstand:
codeStr = "SOAP-ENV:MustUnderstand";
break;
case Client:
codeStr = "SOAP-ENV:Client";
break;
case Server:
codeStr = "SOAP-ENV:Server";
break;
case Other:
codeStr = "Other";
break;
}
QtSoapType &node = body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)];
QtSoapStruct &fault = reinterpret_cast<QtSoapStruct &>(node);
fault.insert(new QtSoapSimpleType(QtSoapQName("Faultcode"), codeStr));
}
void QtSoapMessage::setFaultString(const QString &s)
{
if (type != Fault && type != OtherType) {
clear();
type = Fault;
}
if (!body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)].isValid())
addBodyItem(new QtSoapStruct(QtSoapQName("Fault", SOAPv11_ENVELOPE)));
QtSoapType &node = body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)];
QtSoapStruct &fault = reinterpret_cast<QtSoapStruct &>(node);
fault.insert(new QtSoapSimpleType(QtSoapQName("Faultstring"), s));
}
void QtSoapMessage::addFaultDetail(QtSoapType *detail)
{
if (type != Fault && type != OtherType) {
clear();
type = Fault;
}
if (!body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)].isValid())
addBodyItem(new QtSoapStruct(QtSoapQName("Fault", SOAPv11_ENVELOPE)));
QtSoapType &node = body()[QtSoapQName("Fault", SOAPv11_ENVELOPE)];
QtSoapStruct &fault = reinterpret_cast<QtSoapStruct &>(node);
if (!fault[QtSoapQName("Faultdetail", SOAPv11_ENVELOPE)].isValid())
fault.insert(new QtSoapStruct(QtSoapQName("Faultdetail", SOAPv11_ENVELOPE)));
QtSoapType &node2 = fault[QtSoapQName("Faultdetail", SOAPv11_ENVELOPE)];
QtSoapStruct &fdetail = reinterpret_cast<QtSoapStruct &>(node2);
fdetail.insert(detail);
}
const QtSoapType &QtSoapMessage::method() const
{
static QtSoapType NIL;
if (body().count() == 0)
return NIL;
QtSoapStructIterator it(body());
return *it.data();
}
void QtSoapMessage::setMethod(const QtSoapQName &meth)
{
if (type != MethodRequest && type != OtherType) {
clear();
type = MethodRequest;
}
addBodyItem(new QtSoapStruct(meth));
}
void QtSoapMessage::setMethod(const QString &name, const QString &uri)
{
setMethod(QtSoapQName(name, uri));
}
void QtSoapMessage::addMethodArgument(QtSoapType *arg)
{
if (body().count() == 0) {
qWarning("Attempted to add argument (%s:%s) without first setting method",
arg->name().uri().toLatin1().constData(), arg->name().name().toLatin1().constData());
return;
}
QtSoapStructIterator it(body());
QtSoapType &node = *it.data();
QtSoapStruct &meth = static_cast<QtSoapStruct &>(node);
meth.insert(arg);
}
void QtSoapMessage::addMethodArgument(const QString &name, const QString &uri, const QString &value)
{
addMethodArgument(new QtSoapSimpleType(QtSoapQName(name, uri), value));
}
void QtSoapMessage::addMethodArgument(const QString &name, const QString &uri, bool value, int dummy)
{
addMethodArgument(new QtSoapSimpleType(QtSoapQName(name, uri), value, dummy));
}
void QtSoapMessage::addMethodArgument(const QString &name, const QString &uri, int value)
{
addMethodArgument(new QtSoapSimpleType(QtSoapQName(name, uri), value));
}
QtSoapTypeFactory::QtSoapTypeFactory()
{
QtSoapTypeConstructor<QtSoapStruct> *structConstructor = new QtSoapTypeConstructor<QtSoapStruct>();
deleteList.append(structConstructor);
QtSoapTypeConstructor<QtSoapArray> *arrayConstructor = new QtSoapTypeConstructor<QtSoapArray>();
deleteList.append(arrayConstructor);
QtSoapTypeConstructor<QtSoapSimpleType> *basicTypeConstructor = new QtSoapTypeConstructor<QtSoapSimpleType>();
deleteList.append(basicTypeConstructor);
registerHandler("struct", structConstructor);
registerHandler("array", arrayConstructor);
registerHandler("string", basicTypeConstructor);
registerHandler("normalizedstring", basicTypeConstructor);
registerHandler("token", basicTypeConstructor);
registerHandler("language", basicTypeConstructor);
registerHandler("name", basicTypeConstructor);
registerHandler("ncname", basicTypeConstructor);
registerHandler("id", basicTypeConstructor);
registerHandler("idref", basicTypeConstructor);
registerHandler("entity", basicTypeConstructor);
registerHandler("nmtoken", basicTypeConstructor);
registerHandler("nmtokens", basicTypeConstructor);
registerHandler("boolean", basicTypeConstructor);
registerHandler("decimal", basicTypeConstructor);
registerHandler("integer", basicTypeConstructor);
registerHandler("nonpositiveinteger", basicTypeConstructor);
registerHandler("negativeinteger", basicTypeConstructor);
registerHandler("int", basicTypeConstructor);
registerHandler("long", basicTypeConstructor);
registerHandler("short", basicTypeConstructor);
registerHandler("byte", basicTypeConstructor);
registerHandler("nonnegativeinteger", basicTypeConstructor);
registerHandler("unsignedlong", basicTypeConstructor);
registerHandler("unsignedint", basicTypeConstructor);
registerHandler("unsignedshort", basicTypeConstructor);
registerHandler("unsignedbyte", basicTypeConstructor);
registerHandler("positiveinteger", basicTypeConstructor);
registerHandler("float", basicTypeConstructor);
registerHandler("double", basicTypeConstructor);
registerHandler("other", structConstructor);
}
QtSoapTypeFactory::~QtSoapTypeFactory()
{
QLinkedList<QtSoapTypeConstructorBase*>::ConstIterator it = deleteList.begin();
while (it != deleteList.end()) {
delete *it;
++it;
}
}
QtSoapTypeFactory &QtSoapTypeFactory::instance()
{
static QtSoapTypeFactory factory;
return factory;
}
bool QtSoapTypeFactory::registerHandler(const QString &name, QtSoapTypeConstructorBase *handler)
{
if (typeHandlers.find(name) != typeHandlers.end()) {
errorStr = "A handler for " + name + " is already registered.";
return false;
}
typeHandlers.insert(name, handler);
return true;
}
QtSmartPtr<QtSoapType> QtSoapTypeFactory::soapType(QDomNode node) const
{
if (node.isNull() || !node.isElement())
return QtSmartPtr<QtSoapType>();
QDomElement elem = node.toElement();
QDomAttr attr = elem.attributeNode("type");
QtSoapTypeConstructorBase *constructor = 0;
if (!attr.isNull()) {
QHash<QString, QtSoapTypeConstructorBase *>::ConstIterator it;
it = typeHandlers.find(localName(attr.value().toLower()));
if (it != typeHandlers.end())
constructor = *it;
}
if (attr.isNull() || !constructor) {
QHash<QString, QtSoapTypeConstructorBase *>::ConstIterator it;
if (node.firstChild().isElement()) {
if (localName(node.nodeName().toLower()) == "array") {
it = typeHandlers.find("array");
} else
it = typeHandlers.find("struct");
} else
it = typeHandlers.find("string");
if (it != typeHandlers.end())
constructor = *it;
}
if (!constructor) {
return QtSmartPtr<QtSoapType>();
}
QtSoapType *type = constructor->createObject(node);
if (!type)
errorStr = constructor->errorString();
return QtSmartPtr<QtSoapType>(type);
}
QString QtSoapTypeFactory::errorString() const
{
return errorStr;
}
QtSoapHttpTransport::QtSoapHttpTransport(QObject *parent)
: QObject(parent), networkMgr(this)
{
bool ok = connect(&networkMgr, SIGNAL(finished(QNetworkReply *)),
SLOT(readResponse(QNetworkReply *)));
Q_ASSERT(ok);
Q_UNUSED(ok);
}
QtSoapHttpTransport::~QtSoapHttpTransport()
{
}
void QtSoapHttpTransport::setHost(const QString &host, int port)
{
setHost(host, false, port);
}
void QtSoapHttpTransport::setHost(const QString &host, bool useSecureHTTP, int port)
{
url.setHost(host);
url.setScheme(useSecureHTTP ? QLatin1String("https") : QLatin1String("http"));
if (port)
url.setPort(port);
else
url.setPort(useSecureHTTP ? 443 : 80);
}
void QtSoapHttpTransport::setAction(const QString &action)
{
soapAction = action;
}
void QtSoapHttpTransport::submitRequest(QtSoapMessage &request, const QString &path)
{
QNetworkRequest networkReq;
networkReq.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml;charset=utf-8"));
networkReq.setRawHeader("SOAPAction", soapAction.toAscii());
url.setPath(path);
networkReq.setUrl(url);
soapResponse.clear();
networkRep = networkMgr.post(networkReq, request.toXmlString().toUtf8().constData());
}
const QtSoapMessage &QtSoapHttpTransport::getResponse() const
{
return soapResponse;
}
QNetworkAccessManager *QtSoapHttpTransport::networkAccessManager()
{
return &networkMgr;
}
QNetworkReply *QtSoapHttpTransport::networkReply()
{
return networkRep;
}
void QtSoapHttpTransport::readResponse(QNetworkReply *reply)
{
networkRep = reply;
switch (reply->error()) {
case QNetworkReply::NoError:
case QNetworkReply::ContentAccessDenied:
case QNetworkReply::ContentOperationNotPermittedError:
case QNetworkReply::ContentNotFoundError:
case QNetworkReply::UnknownContentError:
{
soapResponse.setContent(reply->readAll());
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (httpStatus != 200 && httpStatus != 100) {
if (soapResponse.faultCode() == QtSoapMessage::Other)
soapResponse.setFaultCode(QtSoapMessage::Client);
}
}
break;
default:
{
soapResponse.setFaultCode(QtSoapMessage::Client);
soapResponse.setFaultString(QString("Network transport error (%1): %2").arg(reply->error()).arg(reply->errorString()));
}
break;
}
emit responseReady();
emit responseReady(soapResponse);
reply->deleteLater();
}
QtSoapNamespaces &QtSoapNamespaces::instance()
{
static QtSoapNamespaces ns;
return ns;
}
QtSoapNamespaces::QtSoapNamespaces()
{
}
void QtSoapNamespaces::registerNamespace(const QString &prefix, const QString &uri)
{
namespaces.insert(uri, prefix);
}
QString QtSoapNamespaces::prefixFor(const QString &uri)
{
return namespaces.value(uri);
}