Skip to content

Commit 5f0fc3f

Browse files
committed
Added support of HTTPS for Windows
1 parent 668a827 commit 5f0fc3f

File tree

12 files changed

+104
-46
lines changed

12 files changed

+104
-46
lines changed

README.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ httpserver
44
Http server is written on C++14 language.
55

66
Dynamic libraries act as applications for the server
7-
(* .so - linux, * .dll - windows).
7+
(\*.so - linux, \*.dll - windows).
88
Library connection takes place in the configuration file
9-
[samples/apps.conf] [samples/apps.conf]
9+
[samples/apps.conf](samples/apps.conf)
1010
by using the parameter `server_module`.
1111

1212
Sample application code: https://github.com/awwit/httpserverapp
@@ -30,38 +30,51 @@ Common:
3030

3131
* [gnutls](https://www.gnutls.org/)
3232

33-
Linux:
33+
Linux: `dl`, `pthread`, `gnutls`
3434

35-
* dl
36-
* pthread
35+
Windows: `ws2_32.lib`, `libgnutls.dll.a`
3736

3837
Build
3938
-----
4039

4140
Linux:
4241

43-
git clone https://github.com/awwit/httpserver.git
44-
cd httpserver
45-
mkdir build
46-
cd build
47-
qbs build -f ./../projects/qt-creator/httpserver.qbs release
42+
```sh
43+
git clone https://github.com/awwit/httpserver.git
44+
cd httpserver
45+
mkdir build
46+
cd build
47+
qbs build -f ./../projects/qt-creator/httpserver.qbs release
48+
```
49+
50+
Windows:
51+
52+
```sh
53+
git clone https://github.com/awwit/httpserver.git
54+
cd httpserver
55+
mkdir build
56+
cd build
57+
devenv ./../projects/msvs/httpserver.sln /build
58+
```
4859

4960
Server start
5061
------------
5162

52-
./httpserver --start
63+
```sh
64+
./httpserver --start
65+
```
5366

5467
Configuration files must be located in the working (current) directory.
5568

5669
Server configuration
5770
--------------------
5871

5972
Server (and its applications) setting is made using config-files.
60-
Examples of settings are located in the folder [samples][samples/].
73+
Examples of settings are located in the folder [samples](samples/).
6174

6275
License
6376
=======
6477

6578
The source codes are licensed under the
6679
[AGPL](http://www.gnu.org/licenses/agpl.html),
67-
the full text of the license is located in the [LICENSE][LICENSE] file.
80+
the full text of the license is located in the [LICENSE](LICENSE) file.

projects/msvs/httpserver.v12.suo

-155 KB
Binary file not shown.

projects/msvs/httpserver.vcxproj

Lines changed: 31 additions & 13 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="4.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|x64">
55
<Configuration>Debug</Configuration>
@@ -32,6 +32,9 @@
3232
<ClCompile Include="..\..\src\ServerApplicationsTree.cpp" />
3333
<ClCompile Include="..\..\src\SignalHandlers.cpp" />
3434
<ClCompile Include="..\..\src\Socket.cpp" />
35+
<ClCompile Include="..\..\src\SocketAdapter.cpp" />
36+
<ClCompile Include="..\..\src\SocketAdapterDefault.cpp" />
37+
<ClCompile Include="..\..\src\SocketAdapterTls.cpp" />
3538
<ClCompile Include="..\..\src\SocketList.cpp" />
3639
<ClCompile Include="..\..\src\System.cpp" />
3740
<ClCompile Include="..\..\src\Utils.cpp" />
@@ -56,6 +59,9 @@
5659
<ClInclude Include="..\..\src\ServerResponse.h" />
5760
<ClInclude Include="..\..\src\SignalHandlers.h" />
5861
<ClInclude Include="..\..\src\Socket.h" />
62+
<ClInclude Include="..\..\src\SocketAdapter.h" />
63+
<ClInclude Include="..\..\src\SocketAdapterDefault.h" />
64+
<ClInclude Include="..\..\src\SocketAdapterTls.h" />
5965
<ClInclude Include="..\..\src\SocketList.h" />
6066
<ClInclude Include="..\..\src\System.h" />
6167
<ClInclude Include="..\..\src\Utils.h" />
@@ -72,7 +78,7 @@
7278
<CharacterSet>MultiByte</CharacterSet>
7379
<ConfigurationType>Application</ConfigurationType>
7480
<IntermediateDirectory>release\</IntermediateDirectory>
75-
<PlatformToolset>v120</PlatformToolset>
81+
<PlatformToolset>v140</PlatformToolset>
7682
<WholeProgramOptimization>true</WholeProgramOptimization>
7783
</PropertyGroup>
7884
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@@ -81,7 +87,7 @@
8187
<CharacterSet>MultiByte</CharacterSet>
8288
<ConfigurationType>Application</ConfigurationType>
8389
<IntermediateDirectory>release\</IntermediateDirectory>
84-
<PlatformToolset>v120</PlatformToolset>
90+
<PlatformToolset>v140</PlatformToolset>
8591
<WholeProgramOptimization>true</WholeProgramOptimization>
8692
</PropertyGroup>
8793
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -90,15 +96,15 @@
9096
<CharacterSet>MultiByte</CharacterSet>
9197
<ConfigurationType>Application</ConfigurationType>
9298
<IntermediateDirectory>debug\</IntermediateDirectory>
93-
<PlatformToolset>v120</PlatformToolset>
99+
<PlatformToolset>v140</PlatformToolset>
94100
</PropertyGroup>
95101
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
96102
<OutputDirectory>debug\</OutputDirectory>
97103
<ATLMinimizesCRunTimeLibraryUsage>false</ATLMinimizesCRunTimeLibraryUsage>
98104
<CharacterSet>MultiByte</CharacterSet>
99105
<ConfigurationType>Application</ConfigurationType>
100106
<IntermediateDirectory>debug\</IntermediateDirectory>
101-
<PlatformToolset>v120</PlatformToolset>
107+
<PlatformToolset>v140</PlatformToolset>
102108
</PropertyGroup>
103109
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
104110
<ImportGroup Label="ExtensionSettings" />
@@ -130,15 +136,27 @@
130136
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
131137
<OutDir>..\..\build\$(Platform)\$(Configuration)\</OutDir>
132138
<IntDir>..\..\build\$(Platform)\$(Configuration)\</IntDir>
139+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
140+
<LibraryPath>D:\usr\lib64;$(LibraryPath)</LibraryPath>
133141
</PropertyGroup>
134142
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
135143
<OutDir>..\..\build\$(Platform)\$(Configuration)\</OutDir>
136144
<IntDir>..\..\build\$(Platform)\$(Configuration)\</IntDir>
145+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
146+
<LibraryPath>D:\usr\lib64;$(LibraryPath)</LibraryPath>
147+
</PropertyGroup>
148+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
149+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
150+
<LibraryPath>D:\usr\lib;$(LibraryPath)</LibraryPath>
151+
</PropertyGroup>
152+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
153+
<IncludePath>D:\usr\include;$(IncludePath)</IncludePath>
154+
<LibraryPath>D:\usr\lib;$(LibraryPath)</LibraryPath>
137155
</PropertyGroup>
138156
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
139157
<ClCompile>
140158
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
141-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
159+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
142160
<AssemblerListingLocation>$(OutDir)asm\</AssemblerListingLocation>
143161
<BrowseInformation>false</BrowseInformation>
144162
<ExceptionHandling>Sync</ExceptionHandling>
@@ -154,7 +172,7 @@
154172
<MultiProcessorCompilation>true</MultiProcessorCompilation>
155173
</ClCompile>
156174
<Link>
157-
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
175+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
158176
<AdditionalOptions>"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)</AdditionalOptions>
159177
<DataExecutionPrevention>true</DataExecutionPrevention>
160178
<GenerateDebugInformation>false</GenerateDebugInformation>
@@ -177,7 +195,7 @@
177195
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
178196
<ClCompile>
179197
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
180-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
198+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
181199
<AssemblerListingLocation>$(OutDir)asm\</AssemblerListingLocation>
182200
<BrowseInformation>false</BrowseInformation>
183201
<ExceptionHandling>Sync</ExceptionHandling>
@@ -193,7 +211,7 @@
193211
<MultiProcessorCompilation>true</MultiProcessorCompilation>
194212
</ClCompile>
195213
<Link>
196-
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
214+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
197215
<AdditionalOptions>"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)</AdditionalOptions>
198216
<DataExecutionPrevention>true</DataExecutionPrevention>
199217
<GenerateDebugInformation>false</GenerateDebugInformation>
@@ -216,7 +234,7 @@
216234
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
217235
<ClCompile>
218236
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
219-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
237+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
220238
<AssemblerListingLocation>$(OutDir)asm\</AssemblerListingLocation>
221239
<BrowseInformation>false</BrowseInformation>
222240
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -233,7 +251,7 @@
233251
<MultiProcessorCompilation>true</MultiProcessorCompilation>
234252
</ClCompile>
235253
<Link>
236-
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
254+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
237255
<AdditionalOptions>"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)</AdditionalOptions>
238256
<DataExecutionPrevention>true</DataExecutionPrevention>
239257
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -255,7 +273,6 @@
255273
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
256274
<ClCompile>
257275
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
258-
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
259276
<AssemblerListingLocation>$(OutDir)asm\</AssemblerListingLocation>
260277
<BrowseInformation>false</BrowseInformation>
261278
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
@@ -270,9 +287,10 @@
270287
<WarningLevel>Level3</WarningLevel>
271288
<Optimization>Disabled</Optimization>
272289
<MultiProcessorCompilation>true</MultiProcessorCompilation>
290+
<AdditionalOptions>-Dssize_t=long %(AdditionalOptions)</AdditionalOptions>
273291
</ClCompile>
274292
<Link>
275-
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
293+
<AdditionalDependencies>ws2_32.lib;libgnutls.dll.a;%(AdditionalDependencies)</AdditionalDependencies>
276294
<AdditionalOptions>"/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions)</AdditionalOptions>
277295
<DataExecutionPrevention>true</DataExecutionPrevention>
278296
<GenerateDebugInformation>true</GenerateDebugInformation>

projects/msvs/httpserver.vcxproj.filters

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@
6767
<ClCompile Include="..\..\src\SignalHandlers.cpp">
6868
<Filter>Source Files</Filter>
6969
</ClCompile>
70+
<ClCompile Include="..\..\src\SocketAdapter.cpp">
71+
<Filter>Source Files</Filter>
72+
</ClCompile>
73+
<ClCompile Include="..\..\src\SocketAdapterDefault.cpp">
74+
<Filter>Source Files</Filter>
75+
</ClCompile>
76+
<ClCompile Include="..\..\src\SocketAdapterTls.cpp">
77+
<Filter>Source Files</Filter>
78+
</ClCompile>
7079
</ItemGroup>
7180
<ItemGroup>
7281
<ClInclude Include="..\..\src\ConfigParser.h">
@@ -135,5 +144,14 @@
135144
<ClInclude Include="..\..\src\SignalHandlers.h">
136145
<Filter>Header Files</Filter>
137146
</ClInclude>
147+
<ClInclude Include="..\..\src\SocketAdapter.h">
148+
<Filter>Header Files</Filter>
149+
</ClInclude>
150+
<ClInclude Include="..\..\src\SocketAdapterDefault.h">
151+
<Filter>Header Files</Filter>
152+
</ClInclude>
153+
<ClInclude Include="..\..\src\SocketAdapterTls.h">
154+
<Filter>Header Files</Filter>
155+
</ClInclude>
138156
</ItemGroup>
139157
</Project>

projects/msvs/httpserver.vcxproj.user

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,14 @@
33
<PropertyGroup>
44
<ShowAllFiles>false</ShowAllFiles>
55
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7+
<LocalDebuggerCommandArguments>--start</LocalDebuggerCommandArguments>
8+
<LocalDebuggerWorkingDirectory>D:\httpserver\debug</LocalDebuggerWorkingDirectory>
9+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
10+
</PropertyGroup>
11+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
12+
<LocalDebuggerCommandArguments>--start</LocalDebuggerCommandArguments>
13+
<LocalDebuggerWorkingDirectory>D:\httpserver\debug</LocalDebuggerWorkingDirectory>
14+
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
15+
</PropertyGroup>
616
</Project>

src/ConfigParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ namespace HttpServer
283283
std::string module_update = app.cend() != it_module_update ? it_module_update->second : "";
284284

285285
// Calculate module index
286-
size_t module_index = std::numeric_limits<size_t>::max();
286+
size_t module_index = ~0;
287287

288288
for (size_t i = 0; i < modules.size(); ++i)
289289
{
@@ -294,7 +294,7 @@ namespace HttpServer
294294
}
295295
}
296296

297-
if (std::numeric_limits<size_t>::max() == module_index)
297+
if (module_index == ~0)
298298
{
299299
module_index = modules.size();
300300
modules.emplace_back(std::move(module) );

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

0 commit comments

Comments
 (0)