16#define LOC QString("HTTPService: ")
19 : m_name(MetaService->m_name),
20 m_staticMetaService(MetaService)
31 QString& method =
Request->m_fileName;
36 if (method ==
"wsdl") {
40 if ( method ==
"xsd" )
43 if (
Request->m_queries.contains(
"type" ))
49 if ( method ==
"version" )
64 LOG(VB_HTTP, LOG_DEBUG,
LOC + QString(
"Looking for method '%1'").arg(method));
68 if (path == method) { handler = handle;
break; }
70 if (handler ==
nullptr)
74 LOG(VB_HTTP, LOG_DEBUG,
LOC +
"Failed to find method");
79 if (handler->m_protected)
81 LOG(VB_HTTP, LOG_INFO,
LOC +
"Authentication required for this call");
88 if (authReqOption ==
"REMOTE") {
92 else if (authReqOption ==
"ALL") {
96 if (authorization.isEmpty())
97 authorization =
Request->m_queries.value(
"authorization",{});
100 if ( ! (
Request->m_path ==
"/Myth/"
101 && (method ==
"LoginUser" || method ==
"GetConnectionInfo")) )
103 if (!authorization.isEmpty() || authReq)
107 QString
error(
" Invalid authorization token");
116 if (handler->m_types.empty())
120 Request->m_allowed = handler->m_requestTypes;
127 size_t typecount = std::min(handler->m_types.size(),
static_cast<size_t>(100));
132 std::array<void*, 100> param {
nullptr};
133 std::array<int, 100>
types { 0 };
136#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
137 param[0] = handler->m_types[0] == 0 ? nullptr : QMetaType::create(handler->m_types[0]);
139 param[0] = handler->m_types[0] == 0 ? nullptr : QMetaType(handler->m_types[0]).create();
141 types[0] = handler->m_types[0];
147 while (count < typecount)
149 auto name = handler->m_names[count];
150 auto value =
Request->m_queries.value(name.toLower(),
"");
151 auto type = handler->m_types[count];
156 error = QString(
"Unknown parameter type '%1'").arg(name);
160#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
161 auto * newparam = QMetaType::create(
type);
163 auto * newparam = QMetaType(
type).create();
170 if (count == typecount)
173 QVariant returnvalue;
175 if (qt_metacall(QMetaObject::InvokeMetaMethod, handler->m_index, param.data()) >= 0)
176 LOG(VB_GENERAL, LOG_ERR,
"qt_metacall error");
183 catch( QString &msg ) {
184 LOG(VB_GENERAL, LOG_ERR,
"Service Exception: " + msg);
185 if (msg.startsWith(
"Forbidden:"))
195 if (!returnvalue.isValid())
200 else if (returnvalue.canConvert<QFileInfo>())
204 auto info = returnvalue.value<QFileInfo>();
205 QString
file =
info.absoluteFilePath();
206 if (
file.size() == 0)
208 LOG(VB_HTTP, LOG_WARNING,
LOC + QString(
"Invalid request for unknown file"));
215 if (!httpfile->open(QIODevice::ReadOnly))
217 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Failed to open '%1'").arg(
file));
223 httpfile->m_lastModified =
info.lastModified();
225 LOG(VB_HTTP, LOG_DEBUG,
LOC + QString(
"Last modified: %2")
241 if (returnvalue.canConvert<QObject*>())
243 LOG(VB_HTTP, LOG_DEBUG,
LOC +
"Deleting object");
244 auto *
object = returnvalue.value<QObject*>();
251 for (
size_t i = 0; i < typecount; ++i)
253 if ((param[i] !=
nullptr) && (
types[i] != 0))
255#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
256 QMetaType::destroy(
types[i], param[i]);
258 QMetaType(
types[i]).destroy(param[i]);
264 if (count != typecount)
bool IsLocalSubnet(const QHostAddress &peer, bool log)
Check if peer is on local subnet.
MythSessionManager * GetSessionManager(void)
QString GetSetting(const QString &key, const QString &defaultval="")
static QStringList GetMimeTypes(const QString &Accept)
static HTTPFile Create(const QString &ShortName, const QString &FullName)
static HTTPResponse RedirectionResponse(const HTTPRequest2 &Request, const QString &Redirect)
static HTTPResponse FileResponse(const HTTPRequest2 &Request, const HTTPFile &File)
static HTTPResponse HandleOptions(const HTTPRequest2 &Request)
static HTTPResponse ErrorResponse(MythHTTPStatus Status, const QString &ServerName)
static HTTPResponse DataResponse(const HTTPRequest2 &Request, const HTTPData &Data)
virtual HTTPResponse HTTPRequest(const HTTPRequest2 &Request)
Respond to a valid HTTPRequest.
MythHTTPMetaService * m_staticMetaService
MythHTTPService(MythHTTPMetaService *MetaService)
static QString GetHeader(const HTTPHeaders &Headers, const QString &Value, const QString &Default="")
static HTTPData Serialise(const QString &Name, const QVariant &Value, const QStringList &Accept)
Serialise the given data with an encoding suggested by Accept.
We use digest authentication because it protects the password over unprotected networks.
bool IsValidSession(const QString &sessionToken)
Check if the session token is valid.
HTTPResponse GetWSDL(const HTTPRequest2 &Request)
HTTPResponse GetXSD(const HTTPRequest2 &pRequest, QString sTypeName)
static const struct wl_interface * types[]
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
std::shared_ptr< MythHTTPFile > HTTPFile
std::shared_ptr< MythHTTPRequest > HTTPRequest2
std::shared_ptr< MythHTTPResponse > HTTPResponse
std::shared_ptr< MythHTTPData > HTTPData
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
@ kOverrideUTC
Present date/time in UTC.
@ kRFC822
HTTP Date format.