Skip to content

Commit 3b2117c

Browse files
committed
Push application in to github
1 parent 778bcd9 commit 3b2117c

24 files changed

Lines changed: 1130 additions & 0 deletions

httpserverapp.sln

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{2857B73E-F847-4B02-9238-064979017E93}") = "httpserverapp", "httpserverapp\httpserverapp.cproj", "{4C15CBD7-D1C0-4869-AEE1-14CB41328514}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|Any CPU = Debug|Any CPU
9+
Release|Any CPU = Release|Any CPU
10+
EndGlobalSection
11+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
12+
{4C15CBD7-D1C0-4869-AEE1-14CB41328514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13+
{4C15CBD7-D1C0-4869-AEE1-14CB41328514}.Debug|Any CPU.Build.0 = Debug|Any CPU
14+
{4C15CBD7-D1C0-4869-AEE1-14CB41328514}.Release|Any CPU.ActiveCfg = Release|Any CPU
15+
{4C15CBD7-D1C0-4869-AEE1-14CB41328514}.Release|Any CPU.Build.0 = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(MonoDevelopProperties) = preSolution
18+
StartupItem = httpserverapp\httpserverapp.cproj
19+
EndGlobalSection
20+
EndGlobal

httpserverapp.userprefs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Properties>
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="httpserverapp/Main.cpp">
4+
<Files>
5+
<File FileName="httpserverapp/Main.h" Line="1" Column="1" />
6+
<File FileName="httpserverapp/Main.cpp" Line="49" Column="56" />
7+
<File FileName="httpserverapp/ServerRequest.h" Line="1" Column="1" />
8+
<File FileName="httpserverapp/ServerResponse.h" Line="1" Column="1" />
9+
<File FileName="httpserverapp/Utils.h" Line="1" Column="1" />
10+
<File FileName="httpserverapp/Test.h" Line="1" Column="1" />
11+
<File FileName="httpserverapp/Test.cpp" Line="1" Column="1" />
12+
<File FileName="httpserverapp/Socket.h" Line="1" Column="1" />
13+
<File FileName="httpserverapp/Utils.cpp" Line="1" Column="1" />
14+
<File FileName="httpserverapp/Socket.cpp" Line="1" Column="1" />
15+
<File FileName="httpserverapp/System.h" Line="1" Column="1" />
16+
<File FileName="httpserverapp/RawData.h" Line="1" Column="1" />
17+
<File FileName="httpserverapp/System.cpp" Line="1" Column="1" />
18+
</Files>
19+
</MonoDevelop.Ide.Workbench>
20+
<MonoDevelop.Ide.DebuggingService.Breakpoints>
21+
<BreakpointStore />
22+
</MonoDevelop.Ide.DebuggingService.Breakpoints>
23+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
24+
</Properties>

httpserverapp/FileIncoming.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
#include "FileIncoming.h"
3+
4+
#include <fstream>
5+
6+
namespace HttpServer
7+
{
8+
FileIncoming::FileIncoming(const std::string &fileName, const std::string &fileType, const size_t fileSize)
9+
{
10+
file_name = fileName;
11+
file_type = fileType;
12+
file_size = fileSize;
13+
}
14+
15+
FileIncoming::~FileIncoming()
16+
{
17+
18+
}
19+
20+
bool FileIncoming::isExists() const
21+
{
22+
std::ifstream file(file_name);
23+
24+
bool is_exists = file.good();
25+
26+
file.close();
27+
28+
return is_exists;
29+
}
30+
};

httpserverapp/FileIncoming.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
namespace HttpServer
6+
{
7+
class FileIncoming
8+
{
9+
protected:
10+
std::string file_name;
11+
std::string file_type;
12+
size_t file_size;
13+
14+
private:
15+
FileIncoming();
16+
17+
public:
18+
FileIncoming(const std::string &, const std::string &, const size_t);
19+
~FileIncoming();
20+
21+
inline std::string getName() const
22+
{
23+
return file_name;
24+
}
25+
26+
inline std::string getType() const
27+
{
28+
return file_type;
29+
}
30+
31+
inline size_t getSize() const
32+
{
33+
return file_size;
34+
}
35+
36+
bool isExists() const;
37+
};
38+
};

httpserverapp/Main.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
#include "Main.h"
3+
4+
#include "Test.h"
5+
6+
#include <fstream>
7+
8+
DLLEXPORT bool application_init()
9+
{
10+
return true;
11+
}
12+
13+
DLLEXPORT int application_call(HttpServer::server_request *request, HttpServer::server_response *response)
14+
{
15+
std::unordered_multimap<std::string, std::string> params;
16+
std::unordered_map<std::string, std::string> headers;
17+
std::unordered_multimap<std::string, std::string> data;
18+
std::unordered_multimap<std::string, HttpServer::FileIncoming> files;
19+
20+
Utils::rawPairsToStlUnorderedMultimap(params, request->params, request->params_count);
21+
Utils::rawPairsToStlUnorderedMap(headers, request->headers, request->headers_count);
22+
Utils::rawPairsToStlUnorderedMultimap(data, request->data, request->data_count);
23+
Utils::rawFilesInfoToFilesIncoming(files, request->files, request->files_count);
24+
25+
HttpServer::ServerRequest proc_request {
26+
HttpServer::Socket(request->socket),
27+
std::string(request->method),
28+
std::string(request->uri_reference),
29+
std::string(request->document_root),
30+
params,
31+
headers,
32+
data,
33+
files
34+
};
35+
36+
HttpServer::ServerResponse proc_response {
37+
HttpServer::Socket(request->socket),
38+
std::map<std::string, std::string>()
39+
};
40+
41+
std::string absolute_path = proc_request.document_root + proc_request.uri_reference;
42+
43+
int result = EXIT_SUCCESS;
44+
45+
std::ifstream file(absolute_path);
46+
47+
if (file)
48+
{
49+
// proc_response.headers["Connection"] = "Keep-Alive";
50+
proc_response.headers["X-Sendfile"] = absolute_path;
51+
}
52+
else
53+
{
54+
result = test(proc_request, proc_response);
55+
}
56+
57+
file.close();
58+
59+
if (proc_response.headers.size() )
60+
{
61+
Utils::raw_pair *headers;
62+
Utils::stlMapToRawPairs(&headers, proc_response.headers);
63+
64+
response->headers_count = proc_response.headers.size();
65+
response->headers = headers;
66+
}
67+
68+
return result;
69+
}
70+
71+
DLLEXPORT void application_final()
72+
{
73+
74+
}

httpserverapp/Main.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include "ServerRequest.h"
4+
#include "ServerResponse.h"
5+
#include "FileIncoming.h"
6+
#include "Utils.h"
7+
8+
#include <string>
9+
#include <unordered_map>
10+
#include <map>
11+
12+
#ifdef WIN32
13+
#define DLLEXPORT extern "C" __declspec(dllexport)
14+
#else
15+
#define DLLEXPORT extern "C"
16+
#endif

httpserverapp/RawData.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
3+
#include <cstddef>
4+
5+
namespace Utils
6+
{
7+
struct raw_pair
8+
{
9+
char *key;
10+
char *value;
11+
};
12+
13+
struct raw_fileinfo
14+
{
15+
char *key;
16+
char *file_name;
17+
char *file_type;
18+
size_t file_size;
19+
};
20+
};

httpserverapp/ResourceAbstract.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "ResourceAbstract.h"
2+
3+
#include "ResourceMethodAbstract.h"
4+
#include "ResourceMethodOptions.h"
5+
6+
namespace HttpServer
7+
{
8+
ResourceAbstract::ResourceAbstract()
9+
{
10+
addMethod(new ResourceMethodOptions() );
11+
}
12+
13+
ResourceAbstract::~ResourceAbstract()
14+
{
15+
for (auto &method : methods)
16+
{
17+
delete method.second;
18+
}
19+
20+
for (auto &resource : resources)
21+
{
22+
delete resource.second;
23+
}
24+
}
25+
26+
void ResourceAbstract::addMethod(ResourceMethodAbstract *method)
27+
{
28+
methods.emplace(method->getName(), method);
29+
}
30+
31+
void ResourceAbstract::addResource(ResourceAbstract *resource)
32+
{
33+
resources.emplace(resource->getName(), resource);
34+
}
35+
};

httpserverapp/ResourceAbstract.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include <unordered_map>
4+
5+
namespace HttpServer
6+
{
7+
class ResourceMethodAbstract;
8+
9+
class ResourceAbstract
10+
{
11+
protected:
12+
std::string resource_name;
13+
14+
public:
15+
std::unordered_map<std::string, ResourceMethodAbstract *> methods;
16+
17+
std::unordered_map<std::string, ResourceAbstract *> resources;
18+
19+
private:
20+
void addMethod(ResourceMethodAbstract *);
21+
void addResource(ResourceAbstract *);
22+
23+
public:
24+
ResourceAbstract();
25+
~ResourceAbstract();
26+
27+
inline std::string getName() const
28+
{
29+
return resource_name;
30+
}
31+
};
32+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "ServerRequest.h"
4+
#include "ServerResponse.h"
5+
#include "ResourceAbstract.h"
6+
7+
#include <string>
8+
9+
namespace HttpServer
10+
{
11+
class ResourceMethodAbstract
12+
{
13+
protected:
14+
std::string resource_method_name;
15+
16+
public:
17+
inline std::string getName() const
18+
{
19+
return resource_method_name;
20+
}
21+
22+
virtual void execute(ResourceAbstract *, ServerRequest &, ServerResponse &) = 0;
23+
};
24+
};

0 commit comments

Comments
 (0)