sptk2 logo
SPTK Home Page
WSConnection.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 "WSServices.h"
30#include <sptk5/wsdl/WSRequest.h>
31#include <sptk5/wsdl/protocol/WSStaticHttpProtocol.h>
32#include <sptk5/wsdl/protocol/WSWebServiceProtocol.h>
33#include <sptk5/wsdl/protocol/WSWebSocketsProtocol.h>
34
35namespace sptk {
36
37class SP_EXPORT WSConnection
38 : public ServerConnection
39{
40public:
41 class Paths
42 {
43 public:
44 String htmlIndexPage;
45 String wsRequestPage;
46 String staticFilesDirectory;
47
48 Paths(String htmlIndexPage, String wsRequestPage, String staticFilesDirectory)
49 : htmlIndexPage(std::move(htmlIndexPage))
50 , wsRequestPage(std::move(wsRequestPage))
51 , staticFilesDirectory(std::move(staticFilesDirectory))
52 {
53 }
54
55 Paths(const Paths& other) = default;
56 };
57
58 struct Options {
59 Paths paths;
60 bool encrypted {false};
61 bool allowCors {false};
62 bool keepAlive {false};
63 bool suppressHttpStatus {false};
64 LogDetails logDetails;
65
66 Options(const Paths& paths, bool encrypted = false)
67 : paths(paths)
68 , encrypted(encrypted)
69 {
70 }
71 };
72
81 WSConnection(TCPServer& server, SOCKET connectionSocket, const sockaddr_in* connectionAddress, WSServices& services,
82 LogEngine& logEngine, const Options& options);
83
87 ~WSConnection() override = default;
88
92 void run() override;
93
94private:
95 WSServices& m_services;
96 Logger m_logger;
97 Options m_options;
98
99 void respondToOptions(const HttpHeaders& headers) const;
100
101 bool handleHttpProtocol(const String& requestType, URL& url, String& protocolName, HttpHeaders& headers) const;
102
103 static bool reviewHeaders(const String& requestType, HttpHeaders& headers);
104
105 void logConnectionDetails(const StopWatch& requestStopWatch, const HttpReader& httpReader,
106 const RequestInfo& requestInfo);
107
108 void processSingleConnection(bool& done);
109};
110
114class SP_EXPORT WSSSLConnection
115 : public WSConnection
116{
117public:
127 WSSSLConnection(TCPServer& server, SOCKET connectionSocket, const sockaddr_in* addr, WSServices& services,
128 LogEngine& logEngine, const Options& options);
129
133 ~WSSSLConnection() override = default;
134};
135
136} // namespace sptk
Definition: HttpReader.h:49
Definition: TCPServer.h:53
Definition: LogEngine.h:60
A log that sends all the log messages into another log.
Definition: Logger.h:53
Definition: RequestInfo.h:42
Definition: ServerConnection.h:56
Definition: StopWatch.h:37
Definition: String.h:49
Definition: TCPServer.h:133
Definition: URL.h:34
Definition: WSConnection.h:42
Definition: WSConnection.h:39
~WSConnection() override=default
WSConnection(TCPServer &server, SOCKET connectionSocket, const sockaddr_in *connectionAddress, WSServices &services, LogEngine &logEngine, const Options &options)
void run() override
Definition: WSConnection.h:116
~WSSSLConnection() override=default
WSSSLConnection(TCPServer &server, SOCKET connectionSocket, const sockaddr_in *addr, WSServices &services, LogEngine &logEngine, const Options &options)
Definition: WSServices.h:37
Definition: WSConnection.h:58

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