MythTV master
mythhttpcommon.cpp
Go to the documentation of this file.
1// Qt
2#include <QStringList>
3
4// MythTV
6
8{
9 return std::shared_ptr<MythSharedData>(new MythSharedData(Size));
10}
11
13{
14 return std::shared_ptr<MythSharedData>(new MythSharedData(Text));
15}
16
18{
19 return std::shared_ptr<MythSharedData>(new MythSharedData(Other));
20}
21
23 : QByteArray(static_cast<int>(Size), Qt::Uninitialized)
24{
25}
26
28 : QByteArray(Text.toUtf8())
29{
30}
31
32MythSharedData::MythSharedData(const QByteArray& Other)
33 : QByteArray(Other)
34{
35}
36
38{
39 return std::shared_ptr<MythSharedString>(new MythSharedString());
40}
41
43{
44 switch (Protocol)
45 {
46 case ProtFrame: return "Default";
47 case ProtJSONRPC: return JSONRPC;
48 case ProtXMLRPC: return XMLRPC;
49 case ProtPLISTRPC: return PLISTRPC;
50 case ProtCBORRPC: return CBORRPC;
51 default: break;
52 }
53 return "noprotocol";
54}
55
57{
58 auto ParseProtocol = [](const QString& Protocol)
59 {
60 if (Protocol.contains(JSONRPC)) return ProtJSONRPC;
61 if (Protocol.contains(XMLRPC)) return ProtXMLRPC;
62 if (Protocol.contains(PLISTRPC)) return ProtPLISTRPC;
63 if (Protocol.contains(CBORRPC)) return ProtCBORRPC;
64 return ProtFrame;
65 };
66
67 auto protocols = Protocols.trimmed().toLower().split(",", Qt::SkipEmptyParts);
68
69 for (const auto & protocol : std::as_const(protocols))
70 if (auto valid = ParseProtocol(protocol); valid != ProtFrame)
71 return valid;
72
73 return ProtFrame;
74}
static QString ProtocolToString(MythSocketProtocol Protocol)
static MythSocketProtocol ProtocolFromString(const QString &Protocols)
static DataPayload CreatePayload(size_t Size)
MythSharedData(uint64_t Size)
MythSharedString()=default
static StringPayload CreateString()
#define CBORRPC
std::shared_ptr< MythSharedString > StringPayload
std::shared_ptr< MythSharedData > DataPayload
#define JSONRPC
#define PLISTRPC
MythSocketProtocol
@ ProtPLISTRPC
@ ProtCBORRPC
@ ProtXMLRPC
@ ProtFrame
@ ProtJSONRPC
#define XMLRPC