sptk2 logo
SPTK Home Page
WSWebSocketsProtocol.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include "WSProtocol.h"
30#include <sptk5/cnet>
31
32namespace sptk {
33
36
40class SP_EXPORT WSWebSocketsMessage
41{
42public:
43 enum class OpCode : uint8_t
44 {
45 CONTINUATION = 0,
46 TEXT = 1,
47 BINARY = 2,
48 CONNECTION_CLOSE = 8,
49 PING1 = 9,
50 PING2 = 10
51 };
52
55
57 [[nodiscard]] const Buffer& payload() const;
58
61 void decode(const char* incomingData);
62
68 static void encode(const String& payload, OpCode opcode, bool finalMessage, Buffer& output);
69
71 OpCode opcode() const;
72
74 void opcode(OpCode code);
75
77 uint32_t statusCode() const;
78
80 bool isFinal() const;
81
82private:
83 OpCode m_opcode {0};
84 uint32_t m_status {0};
85 Buffer m_payload;
86 bool m_finalMessage {true};
87};
88
94class SP_EXPORT WSWebSocketsProtocol : public WSProtocol
95{
96public:
100 WSWebSocketsProtocol(TCPSocket* socket, const HttpHeaders& headers);
101
106
107 void replyCloseConnectionRequest(uint16_t statusCode, const String& closeReason);
108};
109
111{
112public:
113 const std::map<String, String> m_headers;
114 String m_data;
115};
116
118{
119public:
120 WSNotificationManager() = default;
121
122private:
123 Strings m_queues;
124};
125
126} // namespace sptk
Definition: Buffer.h:51
Definition: RequestInfo.h:42
Definition: String.h:49
Definition: Strings.h:52
Definition: TCPSocket.h:165
Definition: WSWebSocketsProtocol.h:118
Definition: WSWebSocketsProtocol.h:111
Abstract base class for different protocols used in Web Service servers.
Definition: WSProtocol.h:40
Definition: WSWebSocketsProtocol.h:41
Definition: WSWebSocketsProtocol.h:95
RequestInfo process() override
bool isFinal() const
'message is final' flag
void decode(const char *incomingData)
const Buffer & payload() const
Return message payload buffer.
OpCode opcode() const
Get operation code.
void opcode(OpCode code)
Set operation code.
static void encode(const String &payload, OpCode opcode, bool finalMessage, Buffer &output)
WSWebSocketsMessage()=default
Default constructor.
WSWebSocketsProtocol(TCPSocket *socket, const HttpHeaders &headers)
uint32_t statusCode() const
Operation status code.

Fri Oct 14 2022 09:58:32: SPTK 5.4.1