Skip to content

Commit

Permalink
Handle HTTP parameter type std::chrono::seconds
Browse files Browse the repository at this point in the history
The timeout/duration value in MythFrontendService::SendNotification
is expressed as a number of seconds. This number used to be passed as
an integer but this has been changed to std::chrono::seconds in 2021.
In the processing of HTTP SendNotification messages the
std::chrono::seconds parameter type is not recognized, leading to
an uninitialized value used as timeout value.
This is fixed by checking for QMetaType "std::chrono::string" and
copying the parameter accordingly.
There is now also a warning given if a QMetaType is passed
that is not recognized and that cannot be handled.
  • Loading branch information
kmdewaal committed May 11, 2024
1 parent d38347e commit bfd71da
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions mythtv/libs/libmythbase/http/mythhttpmetamethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ HTTPMethodPtr MythHTTPMetaMethod::Create(int Index, QMetaMethod &Method, int Req
*/
void* MythHTTPMetaMethod::CreateParameter(void* Parameter, int Type, const QString& Value)
{
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QByteArray typeName = QMetaType::typeName(Type);
#else
QByteArray typeName = QMetaType(Type).name();
#endif

// Enum types
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
auto typeflags = QMetaType::typeFlags(Type);
Expand All @@ -141,14 +147,9 @@ void* MythHTTPMetaMethod::CreateParameter(void* Parameter, int Type, const QStri
// QMetaEnum::keyToValue will return -1 for an unrecognised enumerant, so
// default to -1 for all error cases
int value = -1;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QByteArray type = QMetaType::typeName(Type);
#else
QByteArray type = QMetaType(Type).name();
#endif
if (int index = type.lastIndexOf("::" ); index > -1)
if (int index = typeName.lastIndexOf("::" ); index > -1)
{
QString enumname = type.mid(index + 2);
QString enumname = typeName.mid(index + 2);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const auto * metaobject = QMetaType::metaObjectForType(Type);
#else
Expand All @@ -168,6 +169,13 @@ void* MythHTTPMetaMethod::CreateParameter(void* Parameter, int Type, const QStri
return Parameter;
}

// Handle parameters of type std::chrono::seconds
if (typeName == "std::chrono::seconds")
{
*(static_cast<std::chrono::seconds*>(Parameter)) = std::chrono::seconds(Value.toInt());
return Parameter;
}

switch (Type)
{
case QMetaType::QVariant : *(static_cast<QVariant *>(Parameter)) = QVariant(Value); break;
Expand Down Expand Up @@ -196,7 +204,9 @@ void* MythHTTPMetaMethod::CreateParameter(void* Parameter, int Type, const QStri
*(static_cast<QDateTime*>(Parameter)) = dt;
break;
}
default: break;
default:
LOG(VB_GENERAL, LOG_WARNING, LOC + QString("Unknown QMetaType:%1 %2").arg(Type).arg(QString(typeName)));
break;
}
return Parameter;
}
Expand Down

0 comments on commit bfd71da

Please sign in to comment.