Showing
9 changed files
with
289 additions
and
15 deletions
Web.sln
0 → 100644
1 | + | ||
2 | +Microsoft Visual Studio Solution File, Format Version 12.00 | ||
3 | +# Visual Studio 15 | ||
4 | +VisualStudioVersion = 15.0.28010.2003 | ||
5 | +MinimumVisualStudioVersion = 10.0.40219.1 | ||
6 | +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Web", "Web\Web.vcxproj", "{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}" | ||
7 | +EndProject | ||
8 | +Global | ||
9 | + GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
10 | + Debug|x64 = Debug|x64 | ||
11 | + Debug|x86 = Debug|x86 | ||
12 | + Release|x64 = Release|x64 | ||
13 | + Release|x86 = Release|x86 | ||
14 | + EndGlobalSection | ||
15 | + GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
16 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x64.ActiveCfg = Debug|x64 | ||
17 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x64.Build.0 = Debug|x64 | ||
18 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x86.ActiveCfg = Debug|Win32 | ||
19 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x86.Build.0 = Debug|Win32 | ||
20 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x64.ActiveCfg = Release|x64 | ||
21 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x64.Build.0 = Release|x64 | ||
22 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x86.ActiveCfg = Release|Win32 | ||
23 | + {C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x86.Build.0 = Release|Win32 | ||
24 | + EndGlobalSection | ||
25 | + GlobalSection(SolutionProperties) = preSolution | ||
26 | + HideSolutionNode = FALSE | ||
27 | + EndGlobalSection | ||
28 | + GlobalSection(ExtensibilityGlobals) = postSolution | ||
29 | + SolutionGuid = {634C2117-66CB-4787-A0DB-0B4C39468EBB} | ||
30 | + EndGlobalSection | ||
31 | +EndGlobal |
Web/Web.vcxproj
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
3 | + <ItemGroup Label="ProjectConfigurations"> | ||
4 | + <ProjectConfiguration Include="Debug|Win32"> | ||
5 | + <Configuration>Debug</Configuration> | ||
6 | + <Platform>Win32</Platform> | ||
7 | + </ProjectConfiguration> | ||
8 | + <ProjectConfiguration Include="Release|Win32"> | ||
9 | + <Configuration>Release</Configuration> | ||
10 | + <Platform>Win32</Platform> | ||
11 | + </ProjectConfiguration> | ||
12 | + <ProjectConfiguration Include="Debug|x64"> | ||
13 | + <Configuration>Debug</Configuration> | ||
14 | + <Platform>x64</Platform> | ||
15 | + </ProjectConfiguration> | ||
16 | + <ProjectConfiguration Include="Release|x64"> | ||
17 | + <Configuration>Release</Configuration> | ||
18 | + <Platform>x64</Platform> | ||
19 | + </ProjectConfiguration> | ||
20 | + </ItemGroup> | ||
21 | + <PropertyGroup Label="Globals"> | ||
22 | + <VCProjectVersion>15.0</VCProjectVersion> | ||
23 | + <ProjectGuid>{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}</ProjectGuid> | ||
24 | + <RootNamespace>Web</RootNamespace> | ||
25 | + <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion> | ||
26 | + </PropertyGroup> | ||
27 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
28 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
29 | + <ConfigurationType>Application</ConfigurationType> | ||
30 | + <UseDebugLibraries>true</UseDebugLibraries> | ||
31 | + <PlatformToolset>v141</PlatformToolset> | ||
32 | + <CharacterSet>MultiByte</CharacterSet> | ||
33 | + </PropertyGroup> | ||
34 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | ||
35 | + <ConfigurationType>Application</ConfigurationType> | ||
36 | + <UseDebugLibraries>false</UseDebugLibraries> | ||
37 | + <PlatformToolset>v141</PlatformToolset> | ||
38 | + <WholeProgramOptimization>true</WholeProgramOptimization> | ||
39 | + <CharacterSet>MultiByte</CharacterSet> | ||
40 | + </PropertyGroup> | ||
41 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
42 | + <ConfigurationType>Application</ConfigurationType> | ||
43 | + <UseDebugLibraries>true</UseDebugLibraries> | ||
44 | + <PlatformToolset>v141</PlatformToolset> | ||
45 | + <CharacterSet>MultiByte</CharacterSet> | ||
46 | + </PropertyGroup> | ||
47 | + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
48 | + <ConfigurationType>Application</ConfigurationType> | ||
49 | + <UseDebugLibraries>false</UseDebugLibraries> | ||
50 | + <PlatformToolset>v141</PlatformToolset> | ||
51 | + <WholeProgramOptimization>true</WholeProgramOptimization> | ||
52 | + <CharacterSet>MultiByte</CharacterSet> | ||
53 | + </PropertyGroup> | ||
54 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> | ||
55 | + <ImportGroup Label="ExtensionSettings"> | ||
56 | + </ImportGroup> | ||
57 | + <ImportGroup Label="Shared"> | ||
58 | + </ImportGroup> | ||
59 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
60 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
61 | + </ImportGroup> | ||
62 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
63 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
64 | + </ImportGroup> | ||
65 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
66 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
67 | + </ImportGroup> | ||
68 | + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
69 | + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> | ||
70 | + </ImportGroup> | ||
71 | + <PropertyGroup Label="UserMacros" /> | ||
72 | + <PropertyGroup /> | ||
73 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
74 | + <ClCompile> | ||
75 | + <WarningLevel>Level3</WarningLevel> | ||
76 | + <Optimization>Disabled</Optimization> | ||
77 | + <SDLCheck>true</SDLCheck> | ||
78 | + <ConformanceMode>true</ConformanceMode> | ||
79 | + </ClCompile> | ||
80 | + <Link> | ||
81 | + <AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
82 | + </Link> | ||
83 | + </ItemDefinitionGroup> | ||
84 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
85 | + <ClCompile> | ||
86 | + <WarningLevel>Level3</WarningLevel> | ||
87 | + <Optimization>Disabled</Optimization> | ||
88 | + <SDLCheck>true</SDLCheck> | ||
89 | + <ConformanceMode>true</ConformanceMode> | ||
90 | + </ClCompile> | ||
91 | + </ItemDefinitionGroup> | ||
92 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | ||
93 | + <ClCompile> | ||
94 | + <WarningLevel>Level3</WarningLevel> | ||
95 | + <Optimization>MaxSpeed</Optimization> | ||
96 | + <FunctionLevelLinking>true</FunctionLevelLinking> | ||
97 | + <IntrinsicFunctions>true</IntrinsicFunctions> | ||
98 | + <SDLCheck>true</SDLCheck> | ||
99 | + <ConformanceMode>true</ConformanceMode> | ||
100 | + </ClCompile> | ||
101 | + <Link> | ||
102 | + <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
103 | + <OptimizeReferences>true</OptimizeReferences> | ||
104 | + </Link> | ||
105 | + </ItemDefinitionGroup> | ||
106 | + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
107 | + <ClCompile> | ||
108 | + <WarningLevel>Level3</WarningLevel> | ||
109 | + <Optimization>MaxSpeed</Optimization> | ||
110 | + <FunctionLevelLinking>true</FunctionLevelLinking> | ||
111 | + <IntrinsicFunctions>true</IntrinsicFunctions> | ||
112 | + <SDLCheck>true</SDLCheck> | ||
113 | + <ConformanceMode>true</ConformanceMode> | ||
114 | + </ClCompile> | ||
115 | + <Link> | ||
116 | + <EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
117 | + <OptimizeReferences>true</OptimizeReferences> | ||
118 | + </Link> | ||
119 | + </ItemDefinitionGroup> | ||
120 | + <ItemGroup> | ||
121 | + <ClCompile Include="..\base64\base64.cpp" /> | ||
122 | + <ClCompile Include="..\main.cpp" /> | ||
123 | + <ClCompile Include="..\socket\src\Socket.cpp" /> | ||
124 | + <ClCompile Include="..\stdHelpers.cpp" /> | ||
125 | + <ClCompile Include="..\UrlHelper.cpp" /> | ||
126 | + <ClCompile Include="..\webserver.cpp" /> | ||
127 | + </ItemGroup> | ||
128 | + <ItemGroup> | ||
129 | + <ClInclude Include="..\base64\base64.h" /> | ||
130 | + <ClInclude Include="..\nlohmann\json.hpp" /> | ||
131 | + <ClInclude Include="..\socket\src\Socket.h" /> | ||
132 | + <ClInclude Include="..\stdHelpers.h" /> | ||
133 | + <ClInclude Include="..\Tracer.h" /> | ||
134 | + <ClInclude Include="..\UrlHelper.h" /> | ||
135 | + <ClInclude Include="..\webserver.h" /> | ||
136 | + </ItemGroup> | ||
137 | + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
138 | + <ImportGroup Label="ExtensionTargets"> | ||
139 | + </ImportGroup> | ||
140 | +</Project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
Web/Web.vcxproj.filters
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
3 | + <ItemGroup> | ||
4 | + <Filter Include="소스 파일"> | ||
5 | + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
6 | + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
7 | + </Filter> | ||
8 | + <Filter Include="헤더 파일"> | ||
9 | + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
10 | + <Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions> | ||
11 | + </Filter> | ||
12 | + <Filter Include="리소스 파일"> | ||
13 | + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
14 | + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
15 | + </Filter> | ||
16 | + </ItemGroup> | ||
17 | + <ItemGroup> | ||
18 | + <ClCompile Include="..\main.cpp"> | ||
19 | + <Filter>소스 파일</Filter> | ||
20 | + </ClCompile> | ||
21 | + <ClCompile Include="..\socket\src\Socket.cpp"> | ||
22 | + <Filter>소스 파일</Filter> | ||
23 | + </ClCompile> | ||
24 | + <ClCompile Include="..\base64\base64.cpp"> | ||
25 | + <Filter>소스 파일</Filter> | ||
26 | + </ClCompile> | ||
27 | + <ClCompile Include="..\stdHelpers.cpp"> | ||
28 | + <Filter>소스 파일</Filter> | ||
29 | + </ClCompile> | ||
30 | + <ClCompile Include="..\UrlHelper.cpp"> | ||
31 | + <Filter>소스 파일</Filter> | ||
32 | + </ClCompile> | ||
33 | + <ClCompile Include="..\webserver.cpp"> | ||
34 | + <Filter>소스 파일</Filter> | ||
35 | + </ClCompile> | ||
36 | + </ItemGroup> | ||
37 | + <ItemGroup> | ||
38 | + <ClInclude Include="..\stdHelpers.h"> | ||
39 | + <Filter>헤더 파일</Filter> | ||
40 | + </ClInclude> | ||
41 | + <ClInclude Include="..\Tracer.h"> | ||
42 | + <Filter>헤더 파일</Filter> | ||
43 | + </ClInclude> | ||
44 | + <ClInclude Include="..\UrlHelper.h"> | ||
45 | + <Filter>헤더 파일</Filter> | ||
46 | + </ClInclude> | ||
47 | + <ClInclude Include="..\webserver.h"> | ||
48 | + <Filter>헤더 파일</Filter> | ||
49 | + </ClInclude> | ||
50 | + <ClInclude Include="..\base64\base64.h"> | ||
51 | + <Filter>헤더 파일</Filter> | ||
52 | + </ClInclude> | ||
53 | + <ClInclude Include="..\socket\src\Socket.h"> | ||
54 | + <Filter>헤더 파일</Filter> | ||
55 | + </ClInclude> | ||
56 | + <ClInclude Include="..\nlohmann\json.hpp"> | ||
57 | + <Filter>헤더 파일</Filter> | ||
58 | + </ClInclude> | ||
59 | + </ItemGroup> | ||
60 | +</Project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
Web/Web.vcxproj.user
0 → 100644
1 | #include "webserver.h" | 1 | #include "webserver.h" |
2 | -#include "Socket.h" | 2 | +#include "socket/src/Socket.h" |
3 | +#include "nlohmann/json.hpp" | ||
4 | + | ||
5 | +std::string urlDecode(std::string const &eString) { | ||
6 | + std::string ret; | ||
7 | + int j; | ||
8 | + for (int i = 0; i < int(eString.length()); i++) { | ||
9 | + if (int(eString[i]) == 37) { | ||
10 | + sscanf_s(eString.substr(i + 1, 2).c_str(), "%x", &j); | ||
11 | + const auto ch = static_cast<char>(j); | ||
12 | + ret += ch; | ||
13 | + i = i + 2; | ||
14 | + } | ||
15 | + else { | ||
16 | + ret += eString[i]; | ||
17 | + } | ||
18 | + } | ||
19 | + return (ret); | ||
20 | +} | ||
3 | 21 | ||
4 | void Request_Handler(webserver::http_request* r) { | 22 | void Request_Handler(webserver::http_request* r) { |
5 | Socket s = *(r->s_); | 23 | Socket s = *(r->s_); |
... | @@ -47,7 +65,8 @@ void Request_Handler(webserver::http_request* r) { | ... | @@ -47,7 +65,8 @@ void Request_Handler(webserver::http_request* r) { |
47 | i != r->params_.end(); | 65 | i != r->params_.end(); |
48 | i++) { | 66 | i++) { |
49 | 67 | ||
50 | - body += "<br>" + i->first + " = " + i->second; | 68 | + |
69 | + body += "<br>" + urlDecode( i->first) + " = " + i->second; | ||
51 | } | 70 | } |
52 | 71 | ||
53 | 72 | ... | ... |
nlohmann/json.hpp
0 → 100644
This diff could not be displayed because it is too large.
... | @@ -36,14 +36,14 @@ | ... | @@ -36,14 +36,14 @@ |
36 | 36 | ||
37 | 37 | ||
38 | #include "webserver.h" | 38 | #include "webserver.h" |
39 | -#include "socket.h" | 39 | +#include "socket/src/Socket.h" |
40 | #include "UrlHelper.h" | 40 | #include "UrlHelper.h" |
41 | -#include "base64.h" | 41 | +#include "base64/base64.h" |
42 | 42 | ||
43 | webserver::request_func webserver::request_func_=0; | 43 | webserver::request_func webserver::request_func_=0; |
44 | 44 | ||
45 | -unsigned webserver::Request(void* ptr_s) { | 45 | +unsigned webserver::Request(Socket* ptr_s) { |
46 | - Socket s = *(reinterpret_cast<Socket*>(ptr_s)); | 46 | + Socket s = *ptr_s; |
47 | 47 | ||
48 | std::string line = s.ReceiveLine(); | 48 | std::string line = s.ReceiveLine(); |
49 | if (line.empty()) { | 49 | if (line.empty()) { |
... | @@ -62,7 +62,7 @@ unsigned webserver::Request(void* ptr_s) { | ... | @@ -62,7 +62,7 @@ unsigned webserver::Request(void* ptr_s) { |
62 | std::string path; | 62 | std::string path; |
63 | std::map<std::string, std::string> params; | 63 | std::map<std::string, std::string> params; |
64 | 64 | ||
65 | - size_t posStartPath = line.find_first_not_of(" ",3); | 65 | + const size_t posStartPath = line.find_first_not_of(" ",3); |
66 | 66 | ||
67 | SplitGetReq(line.substr(posStartPath), path, params); | 67 | SplitGetReq(line.substr(posStartPath), path, params); |
68 | 68 | ||
... | @@ -77,12 +77,12 @@ unsigned webserver::Request(void* ptr_s) { | ... | @@ -77,12 +77,12 @@ unsigned webserver::Request(void* ptr_s) { |
77 | static const std::string accept_encoding = "Accept-Encoding: " ; | 77 | static const std::string accept_encoding = "Accept-Encoding: " ; |
78 | static const std::string user_agent = "User-Agent: " ; | 78 | static const std::string user_agent = "User-Agent: " ; |
79 | 79 | ||
80 | - while(1) { | 80 | + while(true) { |
81 | line=s.ReceiveLine(); | 81 | line=s.ReceiveLine(); |
82 | 82 | ||
83 | if (line.empty()) break; | 83 | if (line.empty()) break; |
84 | 84 | ||
85 | - unsigned int pos_cr_lf = line.find_first_of("\x0a\x0d"); | 85 | + const unsigned int pos_cr_lf = line.find_first_of("\x0a\x0d"); |
86 | if (pos_cr_lf == 0) break; | 86 | if (pos_cr_lf == 0) break; |
87 | 87 | ||
88 | line = line.substr(0,pos_cr_lf); | 88 | line = line.substr(0,pos_cr_lf); |
... | @@ -92,7 +92,7 @@ unsigned webserver::Request(void* ptr_s) { | ... | @@ -92,7 +92,7 @@ unsigned webserver::Request(void* ptr_s) { |
92 | std::string encoded = line.substr(authorization.size()); | 92 | std::string encoded = line.substr(authorization.size()); |
93 | std::string decoded = base64_decode(encoded); | 93 | std::string decoded = base64_decode(encoded); |
94 | 94 | ||
95 | - unsigned int pos_colon = decoded.find(":"); | 95 | + const unsigned int pos_colon = decoded.find(":"); |
96 | 96 | ||
97 | req.username_ = decoded.substr(0, pos_colon); | 97 | req.username_ = decoded.substr(0, pos_colon); |
98 | req.password_ = decoded.substr(pos_colon+1 ); | 98 | req.password_ = decoded.substr(pos_colon+1 ); |
... | @@ -118,11 +118,23 @@ unsigned webserver::Request(void* ptr_s) { | ... | @@ -118,11 +118,23 @@ unsigned webserver::Request(void* ptr_s) { |
118 | 118 | ||
119 | time_t ltime; | 119 | time_t ltime; |
120 | time(<ime); | 120 | time(<ime); |
121 | + | ||
122 | +#ifdef _CRT_SECURE_NO_WARNINGS | ||
121 | tm* gmt= gmtime(<ime); | 123 | tm* gmt= gmtime(<ime); |
124 | +#else | ||
125 | + tm gmt{}; | ||
126 | + gmtime_s(&gmt, <ime); | ||
127 | +#endif | ||
122 | 128 | ||
123 | static std::string const serverName = "RenesWebserver (Windows)"; | 129 | static std::string const serverName = "RenesWebserver (Windows)"; |
124 | 130 | ||
131 | +#ifdef _CRT_SECURE_NO_WARNINGS | ||
125 | char* asctime_remove_nl = asctime(gmt); | 132 | char* asctime_remove_nl = asctime(gmt); |
133 | +#else | ||
134 | + char asctime_remove_nl[26]; | ||
135 | + asctime_s(asctime_remove_nl,&gmt); | ||
136 | +#endif | ||
137 | + | ||
126 | asctime_remove_nl[24] = 0; | 138 | asctime_remove_nl[24] = 0; |
127 | 139 | ||
128 | s.SendBytes("HTTP/1.1 "); | 140 | s.SendBytes("HTTP/1.1 "); |
... | @@ -139,7 +151,7 @@ unsigned webserver::Request(void* ptr_s) { | ... | @@ -139,7 +151,7 @@ unsigned webserver::Request(void* ptr_s) { |
139 | s.SendLine(std::string("Date: ") + asctime_remove_nl + " GMT"); | 151 | s.SendLine(std::string("Date: ") + asctime_remove_nl + " GMT"); |
140 | s.SendLine(std::string("Server: ") +serverName); | 152 | s.SendLine(std::string("Server: ") +serverName); |
141 | s.SendLine("Connection: close"); | 153 | s.SendLine("Connection: close"); |
142 | - s.SendLine("Content-Type: text/html; charset=ISO-8859-1"); | 154 | + s.SendLine("Content-Type: text/html; charset=UTF-8"); |
143 | s.SendLine("Content-Length: " + str_str.str()); | 155 | s.SendLine("Content-Length: " + str_str.str()); |
144 | s.SendLine(""); | 156 | s.SendLine(""); |
145 | s.SendLine(req.answer_); | 157 | s.SendLine(req.answer_); |
... | @@ -154,11 +166,11 @@ webserver::webserver(unsigned int port_to_listen, request_func r) { | ... | @@ -154,11 +166,11 @@ webserver::webserver(unsigned int port_to_listen, request_func r) { |
154 | SocketServer in(port_to_listen,5); | 166 | SocketServer in(port_to_listen,5); |
155 | 167 | ||
156 | request_func_ = r; | 168 | request_func_ = r; |
157 | - | 169 | + std::cout<<"Listening on port "<<port_to_listen<<std::endl; |
158 | - while (1) { | 170 | + while (true) { |
159 | Socket* ptr_s=in.Accept(); | 171 | Socket* ptr_s=in.Accept(); |
160 | 172 | ||
161 | unsigned ret; | 173 | unsigned ret; |
162 | - _beginthreadex(0,0,Request,(void*) ptr_s,0,&ret); | 174 | + _beginthreadex(nullptr,0,Request, ptr_s,0,&ret); |
163 | } | 175 | } |
164 | } | 176 | } | ... | ... |
... | @@ -25,6 +25,7 @@ | ... | @@ -25,6 +25,7 @@ |
25 | 25 | ||
26 | */ | 26 | */ |
27 | 27 | ||
28 | +#pragma once | ||
28 | #include <string> | 29 | #include <string> |
29 | #include <map> | 30 | #include <map> |
30 | 31 | ||
... | @@ -70,7 +71,11 @@ class webserver { | ... | @@ -70,7 +71,11 @@ class webserver { |
70 | 71 | ||
71 | 72 | ||
72 | private: | 73 | private: |
73 | - static unsigned __stdcall Request(void*); | 74 | + static unsigned __stdcall Request(void* ptr) |
75 | + { | ||
76 | + return Request(static_cast<Socket*>(ptr)); | ||
77 | + } | ||
78 | + static unsigned __stdcall Request(Socket*); | ||
74 | static request_func request_func_; | 79 | static request_func request_func_; |
75 | }; | 80 | }; |
76 | 81 | ... | ... |
-
Please register or login to post a comment