MythTV  master
mythhttpcommon.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QStringList>
3 
4 // MythTV
5 #include "http/mythhttpcommon.h"
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 
27 MythSharedData::MythSharedData(const QString& Text)
28  : QByteArray(Text.toUtf8())
29 {
30 }
31 
32 MythSharedData::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 }
StringPayload
std::shared_ptr< MythSharedString > StringPayload
Definition: mythhttpcommon.h:56
CBORRPC
#define CBORRPC
Definition: mythhttpcommon.h:23
MythSharedString::CreateString
static StringPayload CreateString()
Definition: mythhttpcommon.cpp:37
ProtPLISTRPC
@ ProtPLISTRPC
Definition: mythhttpcommon.h:31
MythHTTPWS::ProtocolFromString
static MythSocketProtocol ProtocolFromString(const QString &Protocols)
Definition: mythhttpcommon.cpp:56
JSONRPC
#define JSONRPC
Definition: mythhttpcommon.h:20
MythSharedString::MythSharedString
MythSharedString()=default
mythhttpcommon.h
MythSocketProtocol
MythSocketProtocol
Definition: mythhttpcommon.h:25
ProtCBORRPC
@ ProtCBORRPC
Definition: mythhttpcommon.h:32
MythHTTPWS::ProtocolToString
static QString ProtocolToString(MythSocketProtocol Protocol)
Definition: mythhttpcommon.cpp:42
DataPayload
std::shared_ptr< MythSharedData > DataPayload
Definition: mythhttpcommon.h:36
MythSharedData::MythSharedData
MythSharedData(uint64_t Size)
Definition: mythhttpcommon.cpp:22
MythSharedData::CreatePayload
static DataPayload CreatePayload(size_t Size)
Definition: mythhttpcommon.cpp:7
PLISTRPC
#define PLISTRPC
Definition: mythhttpcommon.h:22
ProtJSONRPC
@ ProtJSONRPC
Definition: mythhttpcommon.h:29
ProtFrame
@ ProtFrame
Definition: mythhttpcommon.h:28
XMLRPC
#define XMLRPC
Definition: mythhttpcommon.h:21
ProtXMLRPC
@ ProtXMLRPC
Definition: mythhttpcommon.h:30