Skip to content

Commit 3f5a075

Browse files
committed
Added support of HTTPS for Windows
1 parent d41d55d commit 3f5a075

File tree

11 files changed

+90
-31
lines changed

11 files changed

+90
-31
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ Common:
1010

1111
* [gnutls](https://www.gnutls.org/)
1212

13-
Linux:
13+
Linux: `dl`, `pthread`, `gnutls`
1414

15-
* dl
16-
* pthread
15+
Windows: `ws2_32.lib`, `libgnutls.dll.a`
1716

1817
Build
1918
-----
@@ -28,6 +27,16 @@ cd build
2827
qbs build -f ./../projects/qt-creator/httpserverapp.qbs release
2928
```
3029

30+
Windows:
31+
32+
```sh
33+
git clone https://github.com/awwit/httpserverapp.git
34+
cd httpserver
35+
mkdir build
36+
cd build
37+
devenv ./../projects/msvs/httpserverapp.sln /build
38+
```
39+
3140
License
3241
=======
3342

-147 KB
Binary file not shown.

projects/msvs/httpserverapp.vcxproj

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup Label="ProjectConfigurations">
44
<ProjectConfiguration Include="Debug|Win32">
55
<Configuration>Debug</Configuration>
@@ -22,6 +22,9 @@
2222
<ClCompile Include="..\..\src\FileIncoming.cpp" />
2323
<ClCompile Include="..\..\src\Main.cpp" />
2424
<ClCompile Include="..\..\src\Socket.cpp" />
25+
<ClCompile Include="..\..\src\SocketAdapter.cpp" />
26+
<ClCompile Include="..\..\src\SocketAdapterDefault.cpp" />
27+
<ClCompile Include="..\..\src\SocketAdapterTls.cpp" />
2528
<ClCompile Include="..\..\src\System.cpp" />
2629
<ClCompile Include="..\..\src\Test.cpp" />
2730
<ClCompile Include="..\..\src\Utils.cpp" />
@@ -33,6 +36,9 @@
3336
<ClInclude Include="..\..\src\ServerRequest.h" />
3437
<ClInclude Include="..\..\src\ServerResponse.h" />
3538
<ClInclude Include="..\..\src\Socket.h" />
39+
<ClInclude Include="..\..\src\SocketAdapter.h" />
40+
<ClInclude Include="..\..\src\SocketAdapterDefault.h" />
41+
<ClInclude Include="..\..\src\SocketAdapterTls.h" />
3642
<ClInclude Include="..\..\src\System.h" />
3743
<ClInclude Include="..\..\src\Test.h" />
3844
<ClInclude Include="..\..\src\Utils.h" />
@@ -46,26 +52,26 @@
4652
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
4753
<ConfigurationType>DynamicLibrary</ConfigurationType>
4854
<UseDebugLibraries>true</UseDebugLibraries>
49-
<PlatformToolset>v120</PlatformToolset>
55+
<PlatformToolset>v140</PlatformToolset>
5056
<CharacterSet>MultiByte</CharacterSet>
5157
</PropertyGroup>
5258
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
5359
<ConfigurationType>DynamicLibrary</ConfigurationType>
5460
<UseDebugLibraries>true</UseDebugLibraries>
55-
<PlatformToolset>v120</PlatformToolset>
61+
<PlatformToolset>v140</PlatformToolset>
5662
<CharacterSet>MultiByte</CharacterSet>
5763
</PropertyGroup>
5864
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
5965
<ConfigurationType>DynamicLibrary</ConfigurationType>
6066
<UseDebugLibraries>false</UseDebugLibraries>
61-
<PlatformToolset>v120</PlatformToolset>
67+
<PlatformToolset>v140</PlatformToolset>
6268
<WholeProgramOptimization>true</WholeProgramOptimization>
6369
<CharacterSet>MultiByte</CharacterSet>
6470
</PropertyGroup>
6571
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
6672
<ConfigurationType>DynamicLibrary</ConfigurationType>
6773
<UseDebugLibraries>false</UseDebugLibraries>
68-
<PlatformToolset>v120</PlatformToolset>
74+
<PlatformToolset>v140</PlatformToolset>
6975
<WholeProgramOptimization>true</WholeProgramOptimization>
7076
<CharacterSet>MultiByte</CharacterSet>
7177
</PropertyGroup>
@@ -89,50 +95,62 @@
8995
<LinkIncremental>true</LinkIncremental>
9096
<OutDir>..\..\build\$(Platform)\$(Configuration)\</OutDir>
9197
<IntDir>..\..\build\$(Platform)\$(Configuration)\</IntDir>
98+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
99+
<LibraryPath>D:\usr\lib;$(LibraryPath)</LibraryPath>
92100
</PropertyGroup>
93101
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
94102
<LinkIncremental>true</LinkIncremental>
95103
<OutDir>..\..\build\$(Platform)\$(Configuration)\</OutDir>
96104
<IntDir>..\..\build\$(Platform)\$(Configuration)\</IntDir>
105+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
106+
<LibraryPath>D:\usr\lib64;$(LibraryPath)</LibraryPath>
97107
</PropertyGroup>
98108
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
99109
<LinkIncremental>false</LinkIncremental>
100110
<OutDir>..\..\build\$(Platform)\$(Configuration)\</OutDir>
101111
<IntDir>..\..\build\$(Platform)\$(Configuration)\</IntDir>
112+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
113+
<LibraryPath>D:\usr\lib;$(LibraryPath)</LibraryPath>
102114
</PropertyGroup>
103115
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
104116
<LinkIncremental>false</LinkIncremental>
105117
<OutDir>..\..\build\$(Platform)\$(Configuration)\</OutDir>
106118
<IntDir>..\..\build\$(Platform)\$(Configuration)\</IntDir>
119+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
120+
<LibraryPath>D:\usr\lib64;$(LibraryPath)</LibraryPath>
107121
</PropertyGroup>
108122
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
109123
<ClCompile>
110124
<PrecompiledHeader>NotUsing</PrecompiledHeader>
111125
<WarningLevel>Level3</WarningLevel>
112126
<Optimization>Disabled</Optimization>
113-
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HTTPSERVERAPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
127+
<PreprocessorDefinitions>WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
114128
<AssemblerListingLocation>$(IntDir)asm\</AssemblerListingLocation>
115129
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
116130
<MultiProcessorCompilation>true</MultiProcessorCompilation>
131+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
117132
</ClCompile>
118133
<Link>
119134
<SubSystem>Windows</SubSystem>
120135
<GenerateDebugInformation>true</GenerateDebugInformation>
136+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
121137
</Link>
122138
</ItemDefinitionGroup>
123139
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
124140
<ClCompile>
125141
<PrecompiledHeader>NotUsing</PrecompiledHeader>
126142
<WarningLevel>Level3</WarningLevel>
127143
<Optimization>Disabled</Optimization>
128-
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;HTTPSERVERAPP_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
144+
<PreprocessorDefinitions>WIN32;DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
129145
<AssemblerListingLocation>$(IntDir)asm\</AssemblerListingLocation>
130146
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
131147
<MultiProcessorCompilation>true</MultiProcessorCompilation>
148+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
132149
</ClCompile>
133150
<Link>
134151
<SubSystem>Windows</SubSystem>
135152
<GenerateDebugInformation>true</GenerateDebugInformation>
153+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
136154
</Link>
137155
</ItemDefinitionGroup>
138156
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -142,16 +160,18 @@
142160
<Optimization>MaxSpeed</Optimization>
143161
<FunctionLevelLinking>true</FunctionLevelLinking>
144162
<IntrinsicFunctions>true</IntrinsicFunctions>
145-
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
163+
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
146164
<AssemblerListingLocation>$(IntDir)asm\</AssemblerListingLocation>
147165
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
148166
<MultiProcessorCompilation>true</MultiProcessorCompilation>
167+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
149168
</ClCompile>
150169
<Link>
151170
<SubSystem>Windows</SubSystem>
152171
<GenerateDebugInformation>true</GenerateDebugInformation>
153172
<EnableCOMDATFolding>true</EnableCOMDATFolding>
154173
<OptimizeReferences>true</OptimizeReferences>
174+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
155175
</Link>
156176
</ItemDefinitionGroup>
157177
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -161,16 +181,18 @@
161181
<Optimization>MaxSpeed</Optimization>
162182
<FunctionLevelLinking>true</FunctionLevelLinking>
163183
<IntrinsicFunctions>true</IntrinsicFunctions>
164-
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
184+
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
165185
<AssemblerListingLocation>$(IntDir)asm\</AssemblerListingLocation>
166186
<ObjectFileName>$(IntDir)obj\</ObjectFileName>
167187
<MultiProcessorCompilation>true</MultiProcessorCompilation>
188+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
168189
</ClCompile>
169190
<Link>
170191
<SubSystem>Windows</SubSystem>
171192
<GenerateDebugInformation>true</GenerateDebugInformation>
172193
<EnableCOMDATFolding>true</EnableCOMDATFolding>
173194
<OptimizeReferences>true</OptimizeReferences>
195+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
174196
</Link>
175197
</ItemDefinitionGroup>
176198
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

projects/msvs/httpserverapp.vcxproj.filters

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
<ClCompile Include="..\..\src\Utils.cpp">
3434
<Filter>Source Files</Filter>
3535
</ClCompile>
36+
<ClCompile Include="..\..\src\SocketAdapter.cpp">
37+
<Filter>Source Files</Filter>
38+
</ClCompile>
39+
<ClCompile Include="..\..\src\SocketAdapterDefault.cpp">
40+
<Filter>Source Files</Filter>
41+
</ClCompile>
42+
<ClCompile Include="..\..\src\SocketAdapterTls.cpp">
43+
<Filter>Source Files</Filter>
44+
</ClCompile>
3645
</ItemGroup>
3746
<ItemGroup>
3847
<ClInclude Include="..\..\src\FileIncoming.h">
@@ -62,5 +71,14 @@
6271
<ClInclude Include="..\..\src\Utils.h">
6372
<Filter>Header Files</Filter>
6473
</ClInclude>
74+
<ClInclude Include="..\..\src\SocketAdapter.h">
75+
<Filter>Header Files</Filter>
76+
</ClInclude>
77+
<ClInclude Include="..\..\src\SocketAdapterDefault.h">
78+
<Filter>Header Files</Filter>
79+
</ClInclude>
80+
<ClInclude Include="..\..\src\SocketAdapterTls.h">
81+
<Filter>Header Files</Filter>
82+
</ClInclude>
6583
</ItemGroup>
6684
</Project>
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<PropertyGroup />
3+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4+
<LocalDebuggerCommandArguments>
5+
</LocalDebuggerCommandArguments>
6+
<LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory>
7+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
8+
</PropertyGroup>
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
10+
<LocalDebuggerCommandArguments>
11+
</LocalDebuggerCommandArguments>
12+
<LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory>
13+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
14+
</PropertyGroup>
415
</Project>

src/Socket.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ namespace HttpServer
284284

285285
while (total < length)
286286
{
287-
const long send_size = ::send(socket_handle, reinterpret_cast<const uint8_t *>(data) + total, length - total, 0);
287+
const long send_size = ::send(socket_handle, reinterpret_cast<const char *>(data) + total, length - total, 0);
288288

289289
if (send_size < 0)
290290
{
@@ -322,7 +322,7 @@ namespace HttpServer
322322
{
323323
if (1 == ::WSAPoll(&event, 1, timeout.count() ) && event.revents & POLLWRNORM)
324324
{
325-
const long send_size = ::send(socket_handle, reinterpret_cast<const uint8_t *>(data) + total, length - total, 0);
325+
const long send_size = ::send(socket_handle, reinterpret_cast<const char *>(data) + total, length - total, 0);
326326

327327
if (send_size < 0)
328328
{

src/Socket.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#pragma once
22

3-
#ifdef WIN32
4-
#include <WinSock2.h>
5-
#pragma comment(lib, "ws2_32.lib")
6-
#undef max
7-
#elif POSIX
3+
#ifdef POSIX
84
#include <sys/types.h>
95
#include <sys/socket.h>
106
#include <sys/epoll.h>
@@ -13,8 +9,6 @@
139
#include <netinet/tcp.h>
1410
#include <unistd.h>
1511
#include <fcntl.h>
16-
#else
17-
#error "Undefine platform"
1812
#endif
1913

2014
#include "System.h"

src/SocketAdapterTls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace HttpServer
7777

7878
System::native_socket_type SocketAdapterTls::get_handle() const
7979
{
80-
return reinterpret_cast<System::native_socket_type>(::gnutls_transport_get_int(this->session) );
80+
return static_cast<System::native_socket_type>(::gnutls_transport_get_int(this->session) );
8181
}
8282

8383
::gnutls_session_t SocketAdapterTls::get_tls_session() const

src/System.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace System
7272
#ifdef WIN32
7373
std::array<TCHAR, MAX_PATH + 1> buf;
7474

75-
const size_t len = ::GetTempPath(buf.size(), buf.data() );
75+
auto const len = ::GetTempPath(buf.size(), buf.data() );
7676

7777
#ifdef UNICODE
7878
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
@@ -196,9 +196,11 @@ namespace System
196196

197197
*fileSize = attrib.st_size;
198198

199-
struct ::tm *clock = ::gmtime(&(attrib.st_mtime) );
199+
struct ::tm clock = {};
200+
201+
::gmtime_r(&(attrib.st_mtime), &clock);
200202

201-
*fileTime = ::mktime(clock);
203+
*fileTime = ::mktime(&clock);
202204

203205
return true;
204206
#else

src/System.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#ifdef WIN32
4+
#include <WS2tcpip.h>
45
#include <Windows.h>
56
::TCHAR myWndClassName[];
67

0 commit comments

Comments
 (0)