김민수

Initial commit

*.swp
*.o
WebServer.exe
/.vs/Web/v15
/Debug
/Web/Debug
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Web", "Web\Web.vcxproj", "{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x64.ActiveCfg = Debug|x64
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x64.Build.0 = Debug|x64
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x86.ActiveCfg = Debug|Win32
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Debug|x86.Build.0 = Debug|Win32
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x64.ActiveCfg = Release|x64
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x64.Build.0 = Release|x64
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x86.ActiveCfg = Release|Win32
{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {634C2117-66CB-4787-A0DB-0B4C39468EBB}
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{C5BB1A73-D2D1-4ECA-A57E-9FB64796750E}</ProjectGuid>
<RootNamespace>Web</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<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>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\base64\base64.cpp" />
<ClCompile Include="..\main.cpp" />
<ClCompile Include="..\socket\src\Socket.cpp" />
<ClCompile Include="..\stdHelpers.cpp" />
<ClCompile Include="..\UrlHelper.cpp" />
<ClCompile Include="..\webserver.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\base64\base64.h" />
<ClInclude Include="..\nlohmann\json.hpp" />
<ClInclude Include="..\socket\src\Socket.h" />
<ClInclude Include="..\stdHelpers.h" />
<ClInclude Include="..\Tracer.h" />
<ClInclude Include="..\UrlHelper.h" />
<ClInclude Include="..\webserver.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="소스 파일">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="헤더 파일">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="리소스 파일">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="..\socket\src\Socket.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="..\base64\base64.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="..\stdHelpers.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="..\UrlHelper.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
<ClCompile Include="..\webserver.cpp">
<Filter>소스 파일</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\stdHelpers.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="..\Tracer.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="..\UrlHelper.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="..\webserver.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="..\base64\base64.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="..\socket\src\Socket.h">
<Filter>헤더 파일</Filter>
</ClInclude>
<ClInclude Include="..\nlohmann\json.hpp">
<Filter>헤더 파일</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
\ No newline at end of file
#include "webserver.h"
#include "Socket.h"
#include "socket/src/Socket.h"
#include "nlohmann/json.hpp"
std::string urlDecode(std::string const &eString) {
std::string ret;
int j;
for (int i = 0; i < int(eString.length()); i++) {
if (int(eString[i]) == 37) {
sscanf_s(eString.substr(i + 1, 2).c_str(), "%x", &j);
const auto ch = static_cast<char>(j);
ret += ch;
i = i + 2;
}
else {
ret += eString[i];
}
}
return (ret);
}
void Request_Handler(webserver::http_request* r) {
Socket s = *(r->s_);
......@@ -46,8 +64,9 @@ void Request_Handler(webserver::http_request* r) {
for (std::map<std::string, std::string>::const_iterator i = r->params_.begin();
i != r->params_.end();
i++) {
body += "<br>" + i->first + " = " + i->second;
body += "<br>" + urlDecode( i->first) + " = " + i->second;
}
......
This diff could not be displayed because it is too large.
......@@ -36,14 +36,14 @@
#include "webserver.h"
#include "socket.h"
#include "socket/src/Socket.h"
#include "UrlHelper.h"
#include "base64.h"
#include "base64/base64.h"
webserver::request_func webserver::request_func_=0;
unsigned webserver::Request(void* ptr_s) {
Socket s = *(reinterpret_cast<Socket*>(ptr_s));
unsigned webserver::Request(Socket* ptr_s) {
Socket s = *ptr_s;
std::string line = s.ReceiveLine();
if (line.empty()) {
......@@ -62,7 +62,7 @@ unsigned webserver::Request(void* ptr_s) {
std::string path;
std::map<std::string, std::string> params;
size_t posStartPath = line.find_first_not_of(" ",3);
const size_t posStartPath = line.find_first_not_of(" ",3);
SplitGetReq(line.substr(posStartPath), path, params);
......@@ -77,12 +77,12 @@ unsigned webserver::Request(void* ptr_s) {
static const std::string accept_encoding = "Accept-Encoding: " ;
static const std::string user_agent = "User-Agent: " ;
while(1) {
while(true) {
line=s.ReceiveLine();
if (line.empty()) break;
unsigned int pos_cr_lf = line.find_first_of("\x0a\x0d");
const unsigned int pos_cr_lf = line.find_first_of("\x0a\x0d");
if (pos_cr_lf == 0) break;
line = line.substr(0,pos_cr_lf);
......@@ -92,7 +92,7 @@ unsigned webserver::Request(void* ptr_s) {
std::string encoded = line.substr(authorization.size());
std::string decoded = base64_decode(encoded);
unsigned int pos_colon = decoded.find(":");
const unsigned int pos_colon = decoded.find(":");
req.username_ = decoded.substr(0, pos_colon);
req.password_ = decoded.substr(pos_colon+1 );
......@@ -118,11 +118,23 @@ unsigned webserver::Request(void* ptr_s) {
time_t ltime;
time(&ltime);
#ifdef _CRT_SECURE_NO_WARNINGS
tm* gmt= gmtime(&ltime);
#else
tm gmt{};
gmtime_s(&gmt, &ltime);
#endif
static std::string const serverName = "RenesWebserver (Windows)";
#ifdef _CRT_SECURE_NO_WARNINGS
char* asctime_remove_nl = asctime(gmt);
#else
char asctime_remove_nl[26];
asctime_s(asctime_remove_nl,&gmt);
#endif
asctime_remove_nl[24] = 0;
s.SendBytes("HTTP/1.1 ");
......@@ -139,7 +151,7 @@ unsigned webserver::Request(void* ptr_s) {
s.SendLine(std::string("Date: ") + asctime_remove_nl + " GMT");
s.SendLine(std::string("Server: ") +serverName);
s.SendLine("Connection: close");
s.SendLine("Content-Type: text/html; charset=ISO-8859-1");
s.SendLine("Content-Type: text/html; charset=UTF-8");
s.SendLine("Content-Length: " + str_str.str());
s.SendLine("");
s.SendLine(req.answer_);
......@@ -154,11 +166,11 @@ webserver::webserver(unsigned int port_to_listen, request_func r) {
SocketServer in(port_to_listen,5);
request_func_ = r;
while (1) {
std::cout<<"Listening on port "<<port_to_listen<<std::endl;
while (true) {
Socket* ptr_s=in.Accept();
unsigned ret;
_beginthreadex(0,0,Request,(void*) ptr_s,0,&ret);
_beginthreadex(nullptr,0,Request, ptr_s,0,&ret);
}
}
......
......@@ -25,6 +25,7 @@
*/
#pragma once
#include <string>
#include <map>
......@@ -70,7 +71,11 @@ class webserver {
private:
static unsigned __stdcall Request(void*);
static unsigned __stdcall Request(void* ptr)
{
return Request(static_cast<Socket*>(ptr));
}
static unsigned __stdcall Request(Socket*);
static request_func request_func_;
};
......