Go to the documentation of this file.
14 #define LOC QString("HTTPService: ")
17 : m_name(MetaService->m_name),
18 m_staticMetaService(MetaService)
29 QString& method =
Request->m_fileName;
34 if (method ==
"wsdl") {
38 if ( method ==
"xsd" )
41 if (
Request->m_queries.contains(
"type" ))
47 if ( method ==
"version" )
62 LOG(VB_HTTP, LOG_DEBUG,
LOC + QString(
"Looking for method '%1'").arg(method));
66 if (path == method) { handler = handle;
break; }
68 if (handler ==
nullptr)
72 LOG(VB_HTTP, LOG_DEBUG,
LOC +
"Failed to find method");
77 if (handler->m_protected)
79 LOG(VB_HTTP, LOG_INFO,
LOC +
"Authentication required for this call");
83 if (handler->m_types.empty())
87 Request->m_allowed = handler->m_requestTypes;
94 size_t typecount = std::min(handler->m_types.size(),
static_cast<size_t>(100));
99 std::array<void*, 100> param {
nullptr};
100 std::array<int, 100>
types { 0 };
103 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
104 param[0] = handler->m_types[0] == 0 ? nullptr : QMetaType::create(handler->m_types[0]);
106 param[0] = handler->m_types[0] == 0 ? nullptr : QMetaType(handler->m_types[0]).create();
108 types[0] = handler->m_types[0];
114 while (count < typecount)
116 auto name = handler->m_names[count];
117 auto value =
Request->m_queries.value(name.toLower(),
"");
118 auto type = handler->m_types[count];
123 error = QString(
"Unknown parameter type '%1'").arg(name);
127 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
128 auto * newparam = QMetaType::create(
type);
130 auto * newparam = QMetaType(
type).create();
137 if (count == typecount)
140 QVariant returnvalue;
142 if (qt_metacall(QMetaObject::InvokeMetaMethod, handler->m_index, param.data()) >= 0)
143 LOG(VB_GENERAL, LOG_ERR,
"qt_metacall error");
150 catch( QString &msg ) {
151 LOG(VB_GENERAL, LOG_ERR,
"Service Exception: " + msg);
159 if (!returnvalue.isValid())
164 else if (returnvalue.canConvert<QFileInfo>())
168 auto info = returnvalue.value<QFileInfo>();
169 QString
file =
info.absoluteFilePath();
170 if (
file.size() == 0)
172 LOG(VB_HTTP, LOG_WARNING,
LOC + QString(
"Invalid request for unknown file"));
179 if (!httpfile->open(QIODevice::ReadOnly))
181 LOG(VB_GENERAL, LOG_WARNING,
LOC + QString(
"Failed to open '%1'").arg(
file));
187 httpfile->m_lastModified =
info.lastModified();
189 LOG(VB_HTTP, LOG_DEBUG,
LOC + QString(
"Last modified: %2")
205 if (returnvalue.canConvert<QObject*>())
207 LOG(VB_HTTP, LOG_DEBUG,
LOC +
"Deleting object");
208 auto *
object = returnvalue.value<QObject*>();
215 for (
size_t i = 0; i < typecount; ++i)
217 if ((param[i] !=
nullptr) && (
types[i] != 0))
219 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
220 QMetaType::destroy(
types[i], param[i]);
222 QMetaType(
types[i]).destroy(param[i]);
228 if (count != typecount)
QString toString(const QDateTime &raw_dt, uint format)
Returns formatted string representing the time.
HTTPResponse GetWSDL(const HTTPRequest2 &Request)
static void error(const char *str,...)
static HTTPResponse FileResponse(const HTTPRequest2 &Request, const HTTPFile &File)
static HTTPResponse DataResponse(const HTTPRequest2 &Request, const HTTPData &Data)
static HTTPFile Create(const QString &ShortName, const QString &FullName)
static QString GetHeader(const HTTPHeaders &Headers, const QString &Value, const QString &Default="")
@ kOverrideUTC
Present date/time in UTC.
static HTTPData Serialise(const QString &Name, const QVariant &Value, const QStringList &Accept)
Serialise the given data with an encoding suggested by Accept.
static const struct wl_interface * types[]
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
virtual HTTPResponse HTTPRequest(const HTTPRequest2 &Request)
Respond to a valid HTTPRequest.
std::shared_ptr< MythHTTPData > HTTPData
static HTTPResponse HandleOptions(const HTTPRequest2 &Request)
MythHTTPMetaService * m_staticMetaService
HTTPResponse GetXSD(const HTTPRequest2 &pRequest, QString sTypeName)
static HTTPResponse ErrorResponse(MythHTTPStatus Status, const QString &ServerName)
static HTTPResponse RedirectionResponse(const HTTPRequest2 &Request, const QString &Redirect)
std::shared_ptr< MythHTTPResponse > HTTPResponse
@ kRFC822
HTTP Date format.
std::shared_ptr< MythHTTPRequest > HTTPRequest2
static QStringList GetMimeTypes(const QString &Accept)
std::shared_ptr< MythHTTPFile > HTTPFile
MythHTTPService(MythHTTPMetaService *MetaService)