-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMain.cpp
More file actions
80 lines (58 loc) · 1.84 KB
/
Main.cpp
File metadata and controls
80 lines (58 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "Main.h"
#include "Init.h"
#include "application/Test.h"
#include "utils/Utils.h"
EXPORT bool application_init(const char *root)
{
return true;
}
EXPORT int application_call(
Transfer::app_request *request,
Transfer::app_response *response
) {
// Allocate memory on the stack
uint8_t addr[sizeof(Socket::AdapterTls)];
// Create the socket adapter
Socket::Adapter *socket_adapter = createSocketAdapter(request, addr);
HttpServer::Request proc_request;
HttpServer::Response proc_response;
if (initServerObjects(&proc_request, &proc_response, request, socket_adapter) == false) {
return EXIT_FAILURE;
}
const std::string absolute_path = proc_request.document_root + getClearPath(proc_request.path);
int result = EXIT_SUCCESS;
if (isSwitchingProtocols(proc_request, proc_response) ) {
} else if (
std::string::npos == absolute_path.find("/../") &&
System::isFileExists(absolute_path)
) {
auto it_connection = proc_request.headers.find("connection");
if (proc_request.headers.cend() != it_connection) {
proc_response.headers["connection"] = it_connection->second;
}
proc_response.headers["x-sendfile"] = absolute_path;
} else {
// Call application
result = Application::test(proc_request, proc_response);
}
destroySocketAdapter(socket_adapter);
if (proc_response.headers.size() ) {
response->data_size = Utils::getPackContainerSize(proc_response.headers);
response->response_data = new uint8_t[response->data_size];
Utils::packContainer(
reinterpret_cast<uint8_t *>(response->response_data),
proc_response.headers
);
}
freeProtocolData(&proc_response);
return result;
}
EXPORT void application_clear(void *response_data, size_t response_size)
{
if (response_data && response_size) {
delete[] reinterpret_cast<uint8_t *>(response_data);
}
}
EXPORT void application_final(const char *root)
{
}