Skip to content

Commit 0aed3ce

Browse files
committed
Fixed project for MSVS. Renamed classes and namespace of protocol
1 parent d238258 commit 0aed3ce

23 files changed

+173
-174
lines changed

projects/msvs/httpserverapp.vcxproj

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
</ItemGroup>
2121
<ItemGroup>
2222
<ClCompile Include="..\..\src\application\Test.cpp" />
23-
<ClCompile Include="..\..\src\client\protocol\ClientHttp1.cpp" />
24-
<ClCompile Include="..\..\src\client\protocol\ClientHttp2.cpp" />
25-
<ClCompile Include="..\..\src\client\protocol\ClientProtocol.cpp" />
26-
<ClCompile Include="..\..\src\client\protocol\WebSocket.cpp" />
27-
<ClCompile Include="..\..\src\client\Request.cpp" />
28-
<ClCompile Include="..\..\src\client\Response.cpp" />
2923
<ClCompile Include="..\..\src\Init.cpp" />
3024
<ClCompile Include="..\..\src\Main.cpp" />
25+
<ClCompile Include="..\..\src\server\protocol\ServerHttp1.cpp" />
26+
<ClCompile Include="..\..\src\server\protocol\ServerHttp2.cpp" />
27+
<ClCompile Include="..\..\src\server\protocol\ServerProtocol.cpp" />
28+
<ClCompile Include="..\..\src\server\Request.cpp" />
29+
<ClCompile Include="..\..\src\server\Response.cpp" />
3130
<ClCompile Include="..\..\src\socket\Adapter.cpp" />
3231
<ClCompile Include="..\..\src\socket\AdapterDefault.cpp" />
3332
<ClCompile Include="..\..\src\socket\AdapterTls.cpp" />
@@ -42,14 +41,13 @@
4241
</ItemGroup>
4342
<ItemGroup>
4443
<ClInclude Include="..\..\src\application\Test.h" />
45-
<ClInclude Include="..\..\src\client\protocol\ClientHttp1.h" />
46-
<ClInclude Include="..\..\src\client\protocol\ClientHttp2.h" />
47-
<ClInclude Include="..\..\src\client\protocol\ClientProtocol.h" />
48-
<ClInclude Include="..\..\src\client\protocol\WebSocket.h" />
49-
<ClInclude Include="..\..\src\client\Request.h" />
50-
<ClInclude Include="..\..\src\client\Response.h" />
5144
<ClInclude Include="..\..\src\Init.h" />
5245
<ClInclude Include="..\..\src\Main.h" />
46+
<ClInclude Include="..\..\src\server\protocol\ServerHttp1.h" />
47+
<ClInclude Include="..\..\src\server\protocol\ServerHttp2.h" />
48+
<ClInclude Include="..\..\src\server\protocol\ServerProtocol.h" />
49+
<ClInclude Include="..\..\src\server\Request.h" />
50+
<ClInclude Include="..\..\src\server\Response.h" />
5351
<ClInclude Include="..\..\src\socket\Adapter.h" />
5452
<ClInclude Include="..\..\src\socket\AdapterDefault.h" />
5553
<ClInclude Include="..\..\src\socket\AdapterTls.h" />

projects/msvs/httpserverapp.vcxproj.filters

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,22 @@
5454
<ClCompile Include="..\..\src\socket\Socket.cpp">
5555
<Filter>Source Files</Filter>
5656
</ClCompile>
57-
<ClCompile Include="..\..\src\client\Request.cpp">
58-
<Filter>Source Files</Filter>
59-
</ClCompile>
60-
<ClCompile Include="..\..\src\client\Response.cpp">
57+
<ClCompile Include="..\..\src\application\Test.cpp">
6158
<Filter>Source Files</Filter>
6259
</ClCompile>
63-
<ClCompile Include="..\..\src\client\protocol\ClientHttp1.cpp">
60+
<ClCompile Include="..\..\src\server\Request.cpp">
6461
<Filter>Source Files</Filter>
6562
</ClCompile>
66-
<ClCompile Include="..\..\src\client\protocol\ClientHttp2.cpp">
63+
<ClCompile Include="..\..\src\server\Response.cpp">
6764
<Filter>Source Files</Filter>
6865
</ClCompile>
69-
<ClCompile Include="..\..\src\client\protocol\ClientProtocol.cpp">
66+
<ClCompile Include="..\..\src\server\protocol\ServerHttp1.cpp">
7067
<Filter>Source Files</Filter>
7168
</ClCompile>
72-
<ClCompile Include="..\..\src\application\Test.cpp">
69+
<ClCompile Include="..\..\src\server\protocol\ServerHttp2.cpp">
7370
<Filter>Source Files</Filter>
7471
</ClCompile>
75-
<ClCompile Include="..\..\src\client\protocol\WebSocket.cpp">
72+
<ClCompile Include="..\..\src\server\protocol\ServerProtocol.cpp">
7673
<Filter>Source Files</Filter>
7774
</ClCompile>
7875
</ItemGroup>
@@ -128,25 +125,22 @@
128125
<ClInclude Include="..\..\src\socket\Socket.h">
129126
<Filter>Header Files</Filter>
130127
</ClInclude>
131-
<ClInclude Include="..\..\src\client\Request.h">
132-
<Filter>Header Files</Filter>
133-
</ClInclude>
134-
<ClInclude Include="..\..\src\client\Response.h">
128+
<ClInclude Include="..\..\src\application\Test.h">
135129
<Filter>Header Files</Filter>
136130
</ClInclude>
137-
<ClInclude Include="..\..\src\client\protocol\ClientHttp1.h">
131+
<ClInclude Include="..\..\src\server\Request.h">
138132
<Filter>Header Files</Filter>
139133
</ClInclude>
140-
<ClInclude Include="..\..\src\client\protocol\ClientHttp2.h">
134+
<ClInclude Include="..\..\src\server\Response.h">
141135
<Filter>Header Files</Filter>
142136
</ClInclude>
143-
<ClInclude Include="..\..\src\client\protocol\ClientProtocol.h">
137+
<ClInclude Include="..\..\src\server\protocol\ServerHttp1.h">
144138
<Filter>Header Files</Filter>
145139
</ClInclude>
146-
<ClInclude Include="..\..\src\application\Test.h">
140+
<ClInclude Include="..\..\src\server\protocol\ServerHttp2.h">
147141
<Filter>Header Files</Filter>
148142
</ClInclude>
149-
<ClInclude Include="..\..\src\client\protocol\WebSocket.h">
143+
<ClInclude Include="..\..\src\server\protocol\ServerProtocol.h">
150144
<Filter>Header Files</Filter>
151145
</ClInclude>
152146
</ItemGroup>

projects/msvs/httpserverapp.vcxproj.user

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory>
1313
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
1414
</PropertyGroup>
15+
<PropertyGroup>
16+
<ShowAllFiles>true</ShowAllFiles>
17+
</PropertyGroup>
1518
</Project>

src/Init.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include "transfer/http2/Http2.h"
88
#include "utils/Utils.h"
99

10-
#include "server/protocol/ClientHttp1.h"
11-
#include "server/protocol/ClientHttp2.h"
10+
#include "server/protocol/ServerHttp1.h"
11+
#include "server/protocol/ServerHttp2.h"
1212

1313
#include <locale>
1414
#include <codecvt>
@@ -98,14 +98,14 @@ static void getIncomingVars(std::unordered_multimap<std::string, std::string> &p
9898
}
9999
}
100100

101-
bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *procResponse, const Transfer::app_request *request, Socket::Adapter *socket_adapter)
101+
bool initServerObjects(HttpServer::Request *procRequest, HttpServer::Response *procResponse, const Transfer::app_request *request, Socket::Adapter *socket_adapter)
102102
{
103103
const uint8_t *src = reinterpret_cast<const uint8_t *>(request->request_data);
104104

105105
size_t protocol_number;
106106
src = Utils::unpackNumber(&protocol_number, src);
107107
Transfer::ProtocolVariant protocol_variant = static_cast<Transfer::ProtocolVariant>(protocol_number);
108-
HttpClient::ClientProtocol *prot = nullptr;
108+
HttpServer::ServerProtocol *prot = nullptr;
109109

110110
std::string document_root;
111111
std::string host;
@@ -139,7 +139,7 @@ bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *p
139139

140140
getIncomingVars(params, path);
141141

142-
prot = new HttpClient::ClientHttp1(socket_adapter);
142+
prot = new HttpServer::ServerHttp1(socket_adapter);
143143

144144
break;
145145
}
@@ -192,7 +192,7 @@ bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *p
192192

193193
Http2::OutStream *stream = new Http2::OutStream(stream_id, settings, Http2::DynamicTable(settings.header_table_size, settings.max_header_list_size, std::move(dynamic_table) ), mtx);
194194

195-
prot = new HttpClient::ClientHttp2(socket_adapter, stream);
195+
prot = new HttpServer::ServerHttp2(socket_adapter, stream);
196196

197197
break;
198198
}
@@ -203,7 +203,7 @@ bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *p
203203
}
204204
}
205205

206-
*procRequest = HttpClient::Request {
206+
*procRequest = HttpServer::Request {
207207
prot,
208208
std::move(document_root),
209209
std::move(host),
@@ -217,7 +217,7 @@ bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *p
217217
protocol_variant
218218
};
219219

220-
*procResponse = HttpClient::Response {
220+
*procResponse = HttpServer::Response {
221221
prot,
222222
protocol_variant,
223223
std::unordered_map<std::string, std::string>(),
@@ -227,14 +227,14 @@ bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *p
227227
return success;
228228
}
229229

230-
void freeProtocolData(HttpClient::Response *response)
230+
void freeProtocolData(HttpServer::Response *response)
231231
{
232232
if (response) {
233233
delete response->prot;
234234
}
235235
}
236236

237-
bool isSwitchingProtocols(const HttpClient::Request &request, HttpClient::Response &response)
237+
bool isSwitchingProtocols(const HttpServer::Request &request, HttpServer::Response &response)
238238
{
239239
// Check for https is not set
240240
if (request.prot->getSocket()->get_tls_session() != 0) {

src/Init.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void destroySocketAdapter(Socket::Adapter *adapter);
1010

1111
std::string getClearPath(const std::string &path);
1212

13-
bool initServerObjects(HttpClient::Request *procRequest, HttpClient::Response *procResponse, const Transfer::app_request *request, Socket::Adapter *socket_adapter);
14-
void freeProtocolData(HttpClient::Response *response);
13+
bool initServerObjects(HttpServer::Request *procRequest, HttpServer::Response *procResponse, const Transfer::app_request *request, Socket::Adapter *socket_adapter);
14+
void freeProtocolData(HttpServer::Response *response);
1515

16-
bool isSwitchingProtocols(const HttpClient::Request &request, HttpClient::Response &response);
16+
bool isSwitchingProtocols(const HttpServer::Request &request, HttpServer::Response &response);

src/Main.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
#include "Main.h"
33
#include "Init.h"
44

@@ -19,10 +19,10 @@ EXPORT int application_call(Transfer::app_request *request, Transfer::app_respon
1919
// Create the socket adapter
2020
Socket::Adapter *socket_adapter = createSocketAdapter(request, addr);
2121

22-
HttpClient::Request proc_request;
23-
HttpClient::Response proc_response;
22+
HttpServer::Request proc_request;
23+
HttpServer::Response proc_response;
2424

25-
if (false == initServerObjects(&proc_request, &proc_response, request, socket_adapter) == false) {
25+
if (initServerObjects(&proc_request, &proc_response, request, socket_adapter) == false) {
2626
return EXIT_FAILURE;
2727
}
2828

@@ -38,8 +38,7 @@ EXPORT int application_call(Transfer::app_request *request, Transfer::app_respon
3838
{
3939
auto it_connection = proc_request.headers.find("connection");
4040

41-
if (proc_request.headers.cend() != it_connection)
42-
{
41+
if (proc_request.headers.cend() != it_connection) {
4342
proc_response.headers["connection"] = it_connection->second;
4443
}
4544

src/application/Test.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Application
77
{
8-
bool test(HttpClient::Request &request, HttpClient::Response &response)
8+
bool test(HttpServer::Request &request, HttpServer::Response &response)
99
{
1010
// Output incoming headers
1111

@@ -135,10 +135,8 @@ namespace Application
135135

136136
const std::chrono::milliseconds timeout(5000);
137137

138-
if (response.sendHeaders(additional, timeout, s.empty() ) )
139-
{
140-
if (false == s.empty() )
141-
{
138+
if (response.sendHeaders(additional, timeout, s.empty() ) ) {
139+
if (s.empty() == false) {
142140
response.sendData(s.data(), s.size(), timeout, true);
143141
}
144142
}

src/application/Test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
namespace Application
77
{
8-
bool test(HttpClient::Request &, HttpClient::Response &);
8+
bool test(HttpServer::Request &, HttpServer::Response &);
99
}

src/server/Request.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "Request.h"
33

4-
namespace HttpClient
4+
namespace HttpServer
55
{
66
std::string Request::getHeader(const std::string &key) const {
77
auto it = headers.find(key);
@@ -38,6 +38,36 @@ namespace HttpClient
3838
return arr;
3939
}
4040

41+
bool Request::isFileExists(const std::string &key) const {
42+
return this->files.cend() != this->files.find(key);
43+
}
44+
45+
Transfer::FileIncoming Request::getFile(const std::string &key) const {
46+
auto const it = this->files.find(key);
47+
return this->files.end() != it ? it->second : Transfer::FileIncoming();
48+
}
49+
50+
std::vector<Transfer::FileIncoming> Request::getFilesAsArray(const std::string &key) const
51+
{
52+
std::vector<Transfer::FileIncoming> arr;
53+
54+
const size_t count = this->files.count(key);
55+
56+
if (count) {
57+
auto const range = this->files.equal_range(key);
58+
59+
arr.resize(count);
60+
61+
size_t i = 0;
62+
63+
for (auto it = range.first; it != range.second; ++it) {
64+
arr[i++] = it->second;
65+
}
66+
}
67+
68+
return arr;
69+
}
70+
4171
std::string Request::getCookieAsString(const std::string &cookieName) const {
4272
auto it = cookies.find(cookieName);
4373
return cookies.end() != it ? it->second : std::string();

src/server/Request.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#pragma once
1+
#pragma once
22

3-
#include "protocol/ClientProtocol.h"
3+
#include "protocol/ServerProtocol.h"
44
#include "../transfer/FileIncoming.h"
55
#include "../transfer/ProtocolVariant.h"
66

77
#include <unordered_map>
88

9-
namespace HttpClient
9+
namespace HttpServer
1010
{
1111
/**
1212
* Структура запроса (входные данные)
@@ -23,7 +23,7 @@ namespace HttpClient
2323
*/
2424
struct Request
2525
{
26-
ClientProtocol *prot;
26+
ServerProtocol *prot;
2727
std::string document_root;
2828
std::string host;
2929
std::string path;
@@ -45,6 +45,12 @@ namespace HttpClient
4545

4646
std::vector<std::string> getDataAsArray(const std::string &key) const;
4747

48+
bool isFileExists(const std::string &key) const;
49+
50+
Transfer::FileIncoming getFile(const std::string &key) const;
51+
52+
std::vector<Transfer::FileIncoming> getFilesAsArray(const std::string &key) const;
53+
4854
std::string getCookieAsString(const std::string &cookieName) const;
4955
};
5056
}

0 commit comments

Comments
 (0)