Skip to content

Commit

Permalink
Enable handling of SOAP message bodies.
Browse files Browse the repository at this point in the history
Any function which is expected to be called via
this method, needs to explicitly allow POST
method, otherwise a "405 Method Not Allowed" will
be the result.
  • Loading branch information
stuarta committed Jun 22, 2021
1 parent cff3f63 commit 8ee629f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
57 changes: 57 additions & 0 deletions mythtv/libs/libmythbase/http/mythhttpencoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "http/mythhttpresponse.h"
#include "http/mythhttpencoding.h"

// Qt
#include <QDomDocument>

#define LOC QString("HTTPEnc: ")

/*! \brief Parse the incoming HTTP 'Accept' header and return an ordered list of preferences.
Expand Down Expand Up @@ -92,6 +95,9 @@ void MythHTTPEncoding::GetContentType(MythHTTPRequest* Request)
Request->m_content->m_mimeType = mime;
if (mime.Name() == "application/x-www-form-urlencoded")
GetURLEncodedParameters(Request);
if (mime.Name() == "text/xml" || mime.Name() == "application/xml")
GetXMLEncodedParameters(Request);

}
}

Expand Down Expand Up @@ -128,6 +134,57 @@ void MythHTTPEncoding::GetURLEncodedParameters(MythHTTPRequest* Request)
}
}

void MythHTTPEncoding::GetXMLEncodedParameters(MythHTTPRequest* Request)
{
LOG(VB_HTTP, LOG_DEBUG, "Inspecting XML payload");
if (!Request || !Request->m_content.get())
return;

auto payload = QDomDocument();
QString err_msg;
int err_line, err_col;
if (!payload.setContent(static_cast<QByteArray>(Request->m_content->constData()),
true, &err_msg, &err_line, &err_col))
{
LOG(VB_HTTP, LOG_WARNING, "Unable to parse XML request body");
LOG(VB_HTTP, LOG_WARNING, QString("- Error at line %1, column %2, msg: %3")
.arg(err_line).arg(err_col).arg(err_msg));
return;
}
QString doc_name = payload.documentElement().nodeName();
if (doc_name.compare("soapenv:envelope", Qt::CaseInsensitive) == 0)
{
LOG(VB_HTTP, LOG_DEBUG, "Found SOAP XML message envelope");
auto doc_body = payload.documentElement().namedItem("Body");
if (doc_body.isNull() || !doc_body.hasChildNodes()) // None or empty body
{
LOG(VB_HTTP, LOG_DEBUG, "Missing or empty SOAP body");
return;
}
auto body_contents = doc_body.firstChild();
if (body_contents.prefix() == "myt")
{
// Requested method should be the localname
Request->m_fileName = body_contents.localName();
LOG(VB_HTTP, LOG_DEBUG, QString("Found method call (%1)").arg(body_contents.localName()));
if (body_contents.hasChildNodes()) // params for the method
{
for (QDomNode node = body_contents.firstChild(); !node.isNull(); node = node.nextSibling())
{
QString name = node.localName();
QString value = node.toElement().text();
if (!name.isEmpty())
{
// TODO: html decode entities if required
Request->m_queries.insert(name.trimmed(), value);
LOG(VB_HTTP, LOG_DEBUG, QString("Found URL param (%1=%2)").arg(name).arg(value));
}
}
}
}
}
}

/*! \brief Return a QMimeType that represents Content.
*/
MythMimeType MythHTTPEncoding::GetMimeType(HTTPVariant Content)
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythbase/http/mythhttpencoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MythHTTPEncoding

protected:
static void GetURLEncodedParameters(MythHTTPRequest* Request);
static void GetXMLEncodedParameters(MythHTTPRequest* Request);
};

#endif
1 change: 1 addition & 0 deletions mythtv/libs/libmythbase/libmythbase.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ TARGET = mythbase-$$LIBVERSION
CONFIG += thread dll
target.path = $${LIBDIR}
INSTALLS = target
QT += xml

QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2)

Expand Down

0 comments on commit 8ee629f

Please sign in to comment.