MythTV  master
mythhttpsocket.h
Go to the documentation of this file.
1 #ifndef MYTHHTTPSOCKET_H
2 #define MYTHHTTPSOCKET_H
3 // Qt
4 #include <QObject>
5 #include <QTimer>
6 #include <QAbstractSocket>
7 #include <QElapsedTimer>
8 
9 // MythTV
12 
13 class QTcpSocket;
14 class QSslSocket;
15 class MythWebSocket;
16 class MythWebSocketEvent;
17 
18 class MythHTTPSocket : public QObject
19 {
20  Q_OBJECT
21 
22  signals:
23  void Finish();
24  void UpdateServices(const HTTPServices& Services);
25  void ThreadUpgraded(QThread* Thread);
26 
27  public slots:
28  void PathsChanged (const QStringList& Paths);
29  void HandlersChanged (const HTTPHandlers& Handlers);
30  void ServicesChanged (const HTTPServices& Services);
31  void HostsChanged (const QStringList& Hosts);
32  void OriginsChanged (const QStringList& Origins);
33  void NewTextMessage (const StringPayload& Text);
34  void NewRawTextMessage(const DataPayloads& Payloads);
35  static void NewBinaryMessage (const DataPayloads& Payloads);
36 
37  public:
38  explicit MythHTTPSocket(qintptr Socket, bool SSL, MythHTTPConfig Config);
39  ~MythHTTPSocket() override;
40  void Respond(const HTTPResponse& Response);
41  static void RespondDirect(qintptr Socket, const HTTPResponse& Response, const MythHTTPConfig& Config);
42 
43  protected slots:
44  void Disconnected();
45  void Timeout();
46  void Read();
47  void Stop();
48  void Write(int64_t Written = 0);
49  void Error(QAbstractSocket::SocketError Error);
50 
51  private:
52  Q_DISABLE_COPY(MythHTTPSocket)
53  void SetupWebSocket();
54 
55  qintptr m_socketFD { 0 };
58  bool m_stopping { false };
59  QTcpSocket* m_socket { nullptr };
60  MythWebSocket* m_websocket { nullptr };
61  QString m_peer;
62  QTimer m_timer;
65  int64_t m_totalToSend { 0 };
66  int64_t m_totalWritten { 0 };
67  int64_t m_totalSent { 0 };
68  QElapsedTimer m_writeTime;
69  HTTPData m_writeBuffer { nullptr };
72  // WebSockets only
73  bool m_testSocket { false };
75 };
76 
77 #endif
MythHTTPParser
Definition: mythhttpparser.h:9
MythHTTPSocket::m_config
MythHTTPConfig m_config
Definition: mythhttpsocket.h:56
MythHTTPSocket::Read
void Read()
Read data from the socket which is parsed by MythHTTPParser.
Definition: mythhttpsocket.cpp:209
StringPayload
std::shared_ptr< MythSharedString > StringPayload
Definition: mythhttpcommon.h:56
MythHTTPSocket::m_writeTime
QElapsedTimer m_writeTime
Definition: mythhttpsocket.h:68
MythHTTPSocket::Finish
void Finish()
ProtHTTP
@ ProtHTTP
Definition: mythhttpcommon.h:27
MythHTTPSocket::ServicesChanged
void ServicesChanged(const HTTPServices &Services)
Definition: mythhttpsocket.cpp:119
MythHTTPSocket::m_totalSent
int64_t m_totalSent
Definition: mythhttpsocket.h:67
MythHTTPSocket::ThreadUpgraded
void ThreadUpgraded(QThread *Thread)
MythHTTPSocket::Error
void Error(QAbstractSocket::SocketError Error)
Definition: mythhttpsocket.cpp:150
MythHTTPSocket::NewTextMessage
void NewTextMessage(const StringPayload &Text)
Definition: mythhttpsocket.cpp:635
MythHTTPSocket::m_websocket
MythWebSocket * m_websocket
Definition: mythhttpsocket.h:60
MythHTTPSocket::m_timer
QTimer m_timer
Definition: mythhttpsocket.h:62
mythhttpparser.h
MythHTTPSocket::m_writeBuffer
HTTPData m_writeBuffer
Definition: mythhttpsocket.h:69
MythHTTPSocket::Write
void Write(int64_t Written=0)
Definition: mythhttpsocket.cpp:433
MythHTTPSocket::m_websocketevent
MythWebSocketEvent * m_websocketevent
Definition: mythhttpsocket.h:74
MythHTTPSocket::UpdateServices
void UpdateServices(const HTTPServices &Services)
MythHTTPSocket::m_totalWritten
int64_t m_totalWritten
Definition: mythhttpsocket.h:66
HTTPData
std::shared_ptr< MythHTTPData > HTTPData
Definition: mythhttptypes.h:36
MythSocketProtocol
MythSocketProtocol
Definition: mythhttpcommon.h:25
MythHTTPSocket::PathsChanged
void PathsChanged(const QStringList &Paths)
Update our list of recognised file paths.
Definition: mythhttpsocket.cpp:109
MythHTTPSocket::m_testSocket
bool m_testSocket
Definition: mythhttpsocket.h:73
MythHTTPSocket::NewBinaryMessage
static void NewBinaryMessage(const DataPayloads &Payloads)
Definition: mythhttpsocket.cpp:649
MythHTTPSocket::m_socket
QTcpSocket * m_socket
Definition: mythhttpsocket.h:59
MythHTTPSocket::m_socketFD
qintptr m_socketFD
Definition: mythhttpsocket.h:55
HTTPConnectionClose
@ HTTPConnectionClose
Definition: mythhttptypes.h:129
MythHTTPSocket::Disconnected
void Disconnected()
The socket was disconnected.
Definition: mythhttpsocket.cpp:145
MythHTTPSocket::m_protocol
MythSocketProtocol m_protocol
Definition: mythhttpsocket.h:71
mythhttptypes.h
MythHTTPSocket::HostsChanged
void HostsChanged(const QStringList &Hosts)
Definition: mythhttpsocket.cpp:135
MythHTTPSocket::RespondDirect
static void RespondDirect(qintptr Socket, const HTTPResponse &Response, const MythHTTPConfig &Config)
Send an (error) response directly without creating a thread.
Definition: mythhttpsocket.cpp:418
HTTPResponse
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:39
MythHTTPSocket::m_activeServices
HTTPServicePtrs m_activeServices
Definition: mythhttpsocket.h:57
MythHTTPSocket::m_queue
HTTPQueue m_queue
Definition: mythhttpsocket.h:64
MythWebSocketEvent
Definition: mythwebsocketevent.h:6
MythHTTPSocket::MythHTTPSocket
MythHTTPSocket(qintptr Socket, bool SSL, MythHTTPConfig Config)
Definition: mythhttpsocket.cpp:28
MythHTTPSocket::m_nextConnection
MythHTTPConnection m_nextConnection
Definition: mythhttpsocket.h:70
MythHTTPSocket::m_stopping
bool m_stopping
Definition: mythhttpsocket.h:58
MythHTTPSocket
Definition: mythhttpsocket.h:18
MythHTTPSocket::Respond
void Respond(const HTTPResponse &Response)
Send response to client.
Definition: mythhttpsocket.cpp:358
HTTPQueue
std::deque< HTTPVariant > HTTPQueue
Definition: mythhttptypes.h:42
MythHTTPSocket::m_totalToSend
int64_t m_totalToSend
Definition: mythhttpsocket.h:65
MythHTTPSocket::OriginsChanged
void OriginsChanged(const QStringList &Origins)
Update the list of allowed Origins.
Definition: mythhttpsocket.cpp:130
MythHTTPSocket::SetupWebSocket
void SetupWebSocket()
Transition socket to a WebSocket.
Definition: mythhttpsocket.cpp:595
HTTPServices
std::vector< HTTPService > HTTPServices
Definition: mythhttptypes.h:54
MythHTTPSocket::~MythHTTPSocket
~MythHTTPSocket() override
Definition: mythhttpsocket.cpp:95
MythHTTPConfig
Definition: mythhttptypes.h:60
MythHTTPSocket::m_parser
MythHTTPParser m_parser
Definition: mythhttpsocket.h:63
MythHTTPSocket::NewRawTextMessage
void NewRawTextMessage(const DataPayloads &Payloads)
Definition: mythhttpsocket.cpp:642
HTTPServicePtrs
std::vector< HTTPServicePtr > HTTPServicePtrs
Definition: mythhttptypes.h:51
MythHTTPSocket::Stop
void Stop()
Close the socket and quit the thread.
Definition: mythhttpsocket.cpp:189
MythWebSocket
An implementation of the WebSocket protocol...
Definition: mythwebsocket.h:20
MythHTTPSocket::HandlersChanged
void HandlersChanged(const HTTPHandlers &Handlers)
Definition: mythhttpsocket.cpp:114
MythHTTPSocket::m_peer
QString m_peer
Definition: mythhttpsocket.h:61
HTTPHandlers
std::vector< HTTPHandler > HTTPHandlers
Definition: mythhttptypes.h:47
MythHTTPSocket::Timeout
void Timeout()
Close the socket after a period of inactivity.
Definition: mythhttpsocket.cpp:160
DataPayloads
std::vector< DataPayload > DataPayloads
Definition: mythhttpcommon.h:37
MythHTTPConnection
MythHTTPConnection
Definition: mythhttptypes.h:127