14 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
15 #include <QStringConverter>
26 #define LOC QString("SOAPClient: ")
36 QString sControlPath) :
37 m_url(
std::move(url)), m_sNamespace(
std::move(sNamespace)),
38 m_sControlPath(
std::move(sControlPath))
48 const QString &sNamespace,
49 const QString &sControlPath)
52 if (sNamespace.isEmpty())
55 LOG(VB_GENERAL, LOG_ERR,
LOC +
"Init() given blank namespace");
59 test.setPath(sControlPath);
63 LOG(VB_GENERAL, LOG_ERR,
LOC +
64 QString(
"Init() given invalid control URL %1")
65 .arg(test.toString()));
86 const QString &sName,
const QDomNode &baseNode)
const
88 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
89 QStringList parts = sName.split(
'/', QString::SkipEmptyParts);
91 QStringList parts = sName.split(
'/', Qt::SkipEmptyParts);
98 QStringList &sParts,
const QDomNode &curNode)
const
103 QString sName = sParts.front();
106 QDomNode child = curNode.namedItem(sName);
117 const QDomNode &node,
const QString &sName,
int nDefault)
const
119 QString sValue =
GetNodeValue(node, sName, QString::number(nDefault));
120 return sValue.toInt();
126 const QDomNode &node,
const QString &sName,
bool bDefault)
const
128 QString sDefault = (bDefault) ?
"true" :
"false";
130 if (sValue.isEmpty())
133 char ret = sValue[0].toLatin1();
136 case 't':
case 'T':
case 'y':
case 'Y':
case '1':
138 case 'f':
case 'F':
case 'n':
case 'N':
case '0':
148 const QDomNode &node,
const QString &sName,
const QString &sDefault)
const
154 QDomNode valNode =
FindNode(sName, node);
156 if (!valNode.isNull())
160 QDomText oText = valNode.firstChild().toText();
163 sValue = oText.nodeValue();
165 return QUrl::fromPercentEncoding(sValue.toUtf8());
199 QDomDocument xmlResult;
203 sErrDesc =
"No namespace given";
210 QHash<QByteArray, QByteArray> headers;
212 headers.insert(
"Content-Type",
"text/xml; charset=\"utf-8\"");
213 QString soapHeader = QString(
"\"%1#%2\"").arg(
m_sNamespace, sMethod);
214 headers.insert(
"SOAPACTION", soapHeader.toUtf8());
215 headers.insert(
"User-Agent",
"Mozilla/9.876 (X11; U; Linux 2.2.12-20 i686, en) "
216 "Gecko/25250101 Netscape/5.432b1");
222 QTextStream os( &aBuffer );
224 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
225 os.setCodec(
"UTF-8");
227 os.setEncoding(QStringConverter::Utf8);
230 os <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
232 " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\""
233 " xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
234 os <<
" <s:Body>\r\n";
235 os <<
" <u:" << sMethod <<
" xmlns:u=\"" <<
m_sNamespace <<
"\">\r\n";
241 for (QStringMap::iterator it = list.begin(); it != list.end(); ++it)
243 os <<
" <" << it.key() <<
">";
245 os <<
"</" << it.key() <<
">\r\n";
248 os <<
" </u:" << sMethod <<
">\r\n";
249 os <<
" </s:Body>\r\n";
250 os <<
"</s:Envelope>\r\n";
258 LOG(VB_UPNP, LOG_DEBUG,
259 QString(
"SOAPClient(%1) sending:\n %2").arg(url.toString(), aBuffer.constData()));
265 LOG(VB_GENERAL, LOG_ERR, QString(
"SOAPClient::SendSOAPRequest: request failed: %1")
266 .arg(url.toString()));
269 sXml = QString(aBuffer);
275 LOG(VB_UPNP, LOG_DEBUG,
"SOAPClient response:\n" +
276 QString(
"%1\n").arg(sXml));
285 if (!doc.setContent(sXml,
true, &sErrDesc, &ErrLineNum))
288 LOG(VB_UPNP, LOG_ERR,
289 QString(
"SendSOAPRequest(%1) - Invalid response from %2. Error %3: %4. Response: %5")
290 .arg(sMethod, url.toString(),
291 QString::number(nErrCode), sErrDesc, sXml));
299 QString sResponseName = sMethod +
"Response";
300 QDomNodeList oNodeList =
303 if (oNodeList.count() == 0)
310 doc,
"Envelope/Body/Fault/detail/UPnPResult/errorCode", 500);
312 doc,
"Envelope/Body/Fault/detail/UPnPResult/errorDescription",
"");
313 if (sErrDesc.isEmpty())
314 sErrDesc = QString(
"Unknown #%1").arg(nErrCode);
316 QDomNode oNode =
FindNode(
"Envelope/Body/Fault", doc );
318 oNode = xmlResult.importNode( oNode,
true );
319 xmlResult.appendChild( oNode );
324 QDomNode oMethod = oNodeList.item(0);
325 if (oMethod.isNull())
328 QDomNode oNode = oMethod.firstChild();
329 for (; !oNode.isNull(); oNode = oNode.nextSibling())
331 QDomElement e = oNode.toElement();
335 QString sName = e.tagName();
338 QDomText oText = oNode.firstChild().toText();
341 sValue = oText.nodeValue();
343 list.insert(QUrl::fromPercentEncoding(sName.toUtf8()),
344 QUrl::fromPercentEncoding(sValue.toUtf8()));
349 oMethod = xmlResult.importNode( oMethod.firstChild(),
true );
354 xmlResult.appendChild( oMethod );