MythTV  master
mythwebsockettypes.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QStringList>
3 
4 // MythTV
6 
7 WSFrame MythWebSocketFrame::CreateFrame(const QByteArray &Header)
8 {
9  if (Header.size() != 2)
10  return nullptr;
11 
12  bool final = (Header[0] & 0x80) != 0;
13  auto code = static_cast<WSOpCode>(Header[0] & 0x0F);
14  bool masked = (Header[1] & 0x80) != 0;
15  uint64_t length = (Header[1] & 0x7F);
16  bool invalid = (Header[0] & 0x70) != 0;
17  return std::shared_ptr<MythWebSocketFrame>(new MythWebSocketFrame(invalid, code, final, masked, length));
18 }
19 
20 MythWebSocketFrame::MythWebSocketFrame(bool Invalid, WSOpCode Code, bool Final,
21  bool Masked, uint64_t Length)
22  : m_invalid(Invalid),
23  m_opCode(Code),
24  m_length(Length),
25  m_final(Final),
26  m_masked(Masked)
27 {
28 }
29 
31 {
32  switch (Code)
33  {
34  case WSOpClose: return "Close";
35  case WSOpContinuation: return "Continuation";
36  case WSOpPing: return "Ping";
37  case WSOpPong: return "Pong";
38  case WSOpBinaryFrame: return "Binary";
39  case WSOpTextFrame: return "Text";
40  default: break;
41  }
42  return "Reserved";
43 }
44 
46 {
47  switch (Protocol)
48  {
49  case ProtJSONRPC:
50  case ProtXMLRPC:
51  case ProtPLISTRPC: return WSOpTextFrame;
52  case ProtCBORRPC: return WSOpBinaryFrame;
53  default: break;
54  }
55  return WSOpBinaryFrame;
56 }
57 
59 {
60  switch (Protocol)
61  {
62  case ProtFrame: // for testing atm
63  case ProtJSONRPC: return true;
64  default: break;
65  }
66  return false;
67 }
WSOpPong
@ WSOpPong
Definition: mythwebsockettypes.h:25
WSOpBinaryFrame
@ WSOpBinaryFrame
Definition: mythwebsockettypes.h:17
WSOpContinuation
@ WSOpContinuation
Definition: mythwebsockettypes.h:15
ProtPLISTRPC
@ ProtPLISTRPC
Definition: mythhttpcommon.h:31
WSFrame
std::shared_ptr< MythWebSocketFrame > WSFrame
Definition: mythwebsockettypes.h:53
MythWS::FrameFormatForProtocol
static WSOpCode FrameFormatForProtocol(MythSocketProtocol Protocol)
Definition: mythwebsockettypes.cpp:45
MythSocketProtocol
MythSocketProtocol
Definition: mythhttpcommon.h:25
ProtCBORRPC
@ ProtCBORRPC
Definition: mythhttpcommon.h:32
WSOpPing
@ WSOpPing
Definition: mythwebsockettypes.h:24
WSOpCode
WSOpCode
Definition: mythwebsockettypes.h:13
WSOpTextFrame
@ WSOpTextFrame
Definition: mythwebsockettypes.h:16
ProtJSONRPC
@ ProtJSONRPC
Definition: mythhttpcommon.h:29
WSOpClose
@ WSOpClose
Definition: mythwebsockettypes.h:23
MythWebSocketFrame::MythWebSocketFrame
MythWebSocketFrame(bool Invalid, WSOpCode Code, bool Final, bool Masked, uint64_t Length)
Definition: mythwebsockettypes.cpp:20
ProtFrame
@ ProtFrame
Definition: mythhttpcommon.h:28
MythWS::OpCodeToString
static QString OpCodeToString(WSOpCode Code)
Definition: mythwebsockettypes.cpp:30
MythWebSocketFrame::CreateFrame
static WSFrame CreateFrame(const QByteArray &Header)
Definition: mythwebsockettypes.cpp:7
mythwebsockettypes.h
MythWS::UseRawTextForProtocol
static bool UseRawTextForProtocol(MythSocketProtocol Protocol)
Definition: mythwebsockettypes.cpp:58
ProtXMLRPC
@ ProtXMLRPC
Definition: mythhttpcommon.h:30