summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--externals/CMakeLists.txt25
m---------externals/libressl0
-rw-r--r--externals/lurlparser/CMakeLists.txt8
-rw-r--r--externals/lurlparser/LUrlParser.cpp265
-rw-r--r--externals/lurlparser/LUrlParser.h78
-rw-r--r--externals/lurlparser/README.md19
-rw-r--r--src/web_service/CMakeLists.txt2
-rw-r--r--src/web_service/web_backend.cpp20
9 files changed, 18 insertions, 401 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e9502a97..366e86b7d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,8 @@ option(ENABLE_VULKAN "Enables Vulkan backend" ON)
30 30
31option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF) 31option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence" OFF)
32 32
33option(USE_SYSTEM_SSL "Use system provided SSL library" OFF)
34
33# Default to a Release build 35# Default to a Release build
34get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) 36get_property(IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
35if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE) 37if (NOT IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt
index e01ff6930..b8114f42b 100644
--- a/externals/CMakeLists.txt
+++ b/externals/CMakeLists.txt
@@ -73,17 +73,20 @@ if (NOT LIBZIP_FOUND)
73endif() 73endif()
74 74
75if (ENABLE_WEB_SERVICE) 75if (ENABLE_WEB_SERVICE)
76 # LibreSSL 76 if (USE_SYSTEM_SSL)
77 set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "") 77 find_package(OpenSSL 1.1 REQUIRED)
78 add_subdirectory(libressl EXCLUDE_FROM_ALL) 78 set(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
79 target_include_directories(ssl INTERFACE ./libressl/include) 79 else()
80 target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP) 80 # LibreSSL
81 get_directory_property(OPENSSL_LIBRARIES 81 set(LIBRESSL_SKIP_INSTALL ON CACHE BOOL "")
82 DIRECTORY libressl 82 set(OPENSSLDIR "/etc/ssl/")
83 DEFINITION OPENSSL_LIBS) 83 add_subdirectory(libressl EXCLUDE_FROM_ALL)
84 84 target_include_directories(ssl INTERFACE ./libressl/include)
85 # lurlparser 85 target_compile_definitions(ssl PRIVATE -DHAVE_INET_NTOP)
86 add_subdirectory(lurlparser EXCLUDE_FROM_ALL) 86 get_directory_property(OPENSSL_LIBRARIES
87 DIRECTORY libressl
88 DEFINITION OPENSSL_LIBS)
89 endif()
87 90
88 # httplib 91 # httplib
89 add_library(httplib INTERFACE) 92 add_library(httplib INTERFACE)
diff --git a/externals/libressl b/externals/libressl
Subproject 7d01cb01cb1a926ecb4c9c98b107ef3c26f59df Subproject 8289d0d07de6553bf4b900bf60e808ea3f7f59d
diff --git a/externals/lurlparser/CMakeLists.txt b/externals/lurlparser/CMakeLists.txt
deleted file mode 100644
index 45046ffd3..000000000
--- a/externals/lurlparser/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
1add_library(lurlparser
2 LUrlParser.cpp
3 LUrlParser.h
4)
5
6create_target_directory_groups(lurlparser)
7
8target_include_directories(lurlparser INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/externals/lurlparser/LUrlParser.cpp b/externals/lurlparser/LUrlParser.cpp
deleted file mode 100644
index 9c134e330..000000000
--- a/externals/lurlparser/LUrlParser.cpp
+++ /dev/null
@@ -1,265 +0,0 @@
1/*
2 * Lightweight URL & URI parser (RFC 1738, RFC 3986)
3 * https://github.com/corporateshark/LUrlParser
4 *
5 * The MIT License (MIT)
6 *
7 * Copyright (C) 2015 Sergey Kosarevsky (sk@linderdaum.com)
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#include "LUrlParser.h"
29
30#include <algorithm>
31#include <cstring>
32#include <stdlib.h>
33
34// check if the scheme name is valid
35static bool IsSchemeValid( const std::string& SchemeName )
36{
37 for ( auto c : SchemeName )
38 {
39 if ( !isalpha( c ) && c != '+' && c != '-' && c != '.' ) return false;
40 }
41
42 return true;
43}
44
45bool LUrlParser::clParseURL::GetPort( int* OutPort ) const
46{
47 if ( !IsValid() ) { return false; }
48
49 int Port = atoi( m_Port.c_str() );
50
51 if ( Port <= 0 || Port > 65535 ) { return false; }
52
53 if ( OutPort ) { *OutPort = Port; }
54
55 return true;
56}
57
58// based on RFC 1738 and RFC 3986
59LUrlParser::clParseURL LUrlParser::clParseURL::ParseURL( const std::string& URL )
60{
61 LUrlParser::clParseURL Result;
62
63 const char* CurrentString = URL.c_str();
64
65 /*
66 * <scheme>:<scheme-specific-part>
67 * <scheme> := [a-z\+\-\.]+
68 * For resiliency, programs interpreting URLs should treat upper case letters as equivalent to lower case in scheme names
69 */
70
71 // try to read scheme
72 {
73 const char* LocalString = strchr( CurrentString, ':' );
74
75 if ( !LocalString )
76 {
77 return clParseURL( LUrlParserError_NoUrlCharacter );
78 }
79
80 // save the scheme name
81 Result.m_Scheme = std::string( CurrentString, LocalString - CurrentString );
82
83 if ( !IsSchemeValid( Result.m_Scheme ) )
84 {
85 return clParseURL( LUrlParserError_InvalidSchemeName );
86 }
87
88 // scheme should be lowercase
89 std::transform( Result.m_Scheme.begin(), Result.m_Scheme.end(), Result.m_Scheme.begin(), ::tolower );
90
91 // skip ':'
92 CurrentString = LocalString+1;
93 }
94
95 /*
96 * //<user>:<password>@<host>:<port>/<url-path>
97 * any ":", "@" and "/" must be normalized
98 */
99
100 // skip "//"
101 if ( *CurrentString++ != '/' ) return clParseURL( LUrlParserError_NoDoubleSlash );
102 if ( *CurrentString++ != '/' ) return clParseURL( LUrlParserError_NoDoubleSlash );
103
104 // check if the user name and password are specified
105 bool bHasUserName = false;
106
107 const char* LocalString = CurrentString;
108
109 while ( *LocalString )
110 {
111 if ( *LocalString == '@' )
112 {
113 // user name and password are specified
114 bHasUserName = true;
115 break;
116 }
117 else if ( *LocalString == '/' )
118 {
119 // end of <host>:<port> specification
120 bHasUserName = false;
121 break;
122 }
123
124 LocalString++;
125 }
126
127 // user name and password
128 LocalString = CurrentString;
129
130 if ( bHasUserName )
131 {
132 // read user name
133 while ( *LocalString && *LocalString != ':' && *LocalString != '@' ) LocalString++;
134
135 Result.m_UserName = std::string( CurrentString, LocalString - CurrentString );
136
137 // proceed with the current pointer
138 CurrentString = LocalString;
139
140 if ( *CurrentString == ':' )
141 {
142 // skip ':'
143 CurrentString++;
144
145 // read password
146 LocalString = CurrentString;
147
148 while ( *LocalString && *LocalString != '@' ) LocalString++;
149
150 Result.m_Password = std::string( CurrentString, LocalString - CurrentString );
151
152 CurrentString = LocalString;
153 }
154
155 // skip '@'
156 if ( *CurrentString != '@' )
157 {
158 return clParseURL( LUrlParserError_NoAtSign );
159 }
160
161 CurrentString++;
162 }
163
164 bool bHasBracket = ( *CurrentString == '[' );
165
166 // go ahead, read the host name
167 LocalString = CurrentString;
168
169 while ( *LocalString )
170 {
171 if ( bHasBracket && *LocalString == ']' )
172 {
173 // end of IPv6 address
174 LocalString++;
175 break;
176 }
177 else if ( !bHasBracket && ( *LocalString == ':' || *LocalString == '/' ) )
178 {
179 // port number is specified
180 break;
181 }
182
183 LocalString++;
184 }
185
186 Result.m_Host = std::string( CurrentString, LocalString - CurrentString );
187
188 CurrentString = LocalString;
189
190 // is port number specified?
191 if ( *CurrentString == ':' )
192 {
193 CurrentString++;
194
195 // read port number
196 LocalString = CurrentString;
197
198 while ( *LocalString && *LocalString != '/' ) LocalString++;
199
200 Result.m_Port = std::string( CurrentString, LocalString - CurrentString );
201
202 CurrentString = LocalString;
203 }
204
205 // end of string
206 if ( !*CurrentString )
207 {
208 Result.m_ErrorCode = LUrlParserError_Ok;
209
210 return Result;
211 }
212
213 // skip '/'
214 if ( *CurrentString != '/' )
215 {
216 return clParseURL( LUrlParserError_NoSlash );
217 }
218
219 CurrentString++;
220
221 // parse the path
222 LocalString = CurrentString;
223
224 while ( *LocalString && *LocalString != '#' && *LocalString != '?' ) LocalString++;
225
226 Result.m_Path = std::string( CurrentString, LocalString - CurrentString );
227
228 CurrentString = LocalString;
229
230 // check for query
231 if ( *CurrentString == '?' )
232 {
233 // skip '?'
234 CurrentString++;
235
236 // read query
237 LocalString = CurrentString;
238
239 while ( *LocalString && *LocalString != '#' ) LocalString++;
240
241 Result.m_Query = std::string( CurrentString, LocalString - CurrentString );
242
243 CurrentString = LocalString;
244 }
245
246 // check for fragment
247 if ( *CurrentString == '#' )
248 {
249 // skip '#'
250 CurrentString++;
251
252 // read fragment
253 LocalString = CurrentString;
254
255 while ( *LocalString ) LocalString++;
256
257 Result.m_Fragment = std::string( CurrentString, LocalString - CurrentString );
258
259 CurrentString = LocalString;
260 }
261
262 Result.m_ErrorCode = LUrlParserError_Ok;
263
264 return Result;
265}
diff --git a/externals/lurlparser/LUrlParser.h b/externals/lurlparser/LUrlParser.h
deleted file mode 100644
index 25d210981..000000000
--- a/externals/lurlparser/LUrlParser.h
+++ /dev/null
@@ -1,78 +0,0 @@
1/*
2 * Lightweight URL & URI parser (RFC 1738, RFC 3986)
3 * https://github.com/corporateshark/LUrlParser
4 *
5 * The MIT License (MIT)
6 *
7 * Copyright (C) 2015 Sergey Kosarevsky (sk@linderdaum.com)
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#pragma once
29
30#include <string>
31
32namespace LUrlParser
33{
34enum LUrlParserError
35{
36 LUrlParserError_Ok = 0,
37 LUrlParserError_Uninitialized = 1,
38 LUrlParserError_NoUrlCharacter = 2,
39 LUrlParserError_InvalidSchemeName = 3,
40 LUrlParserError_NoDoubleSlash = 4,
41 LUrlParserError_NoAtSign = 5,
42 LUrlParserError_UnexpectedEndOfLine = 6,
43 LUrlParserError_NoSlash = 7,
44};
45
46class clParseURL
47{
48public:
49 LUrlParserError m_ErrorCode;
50 std::string m_Scheme;
51 std::string m_Host;
52 std::string m_Port;
53 std::string m_Path;
54 std::string m_Query;
55 std::string m_Fragment;
56 std::string m_UserName;
57 std::string m_Password;
58
59 clParseURL()
60 : m_ErrorCode( LUrlParserError_Uninitialized )
61 {}
62
63 /// return 'true' if the parsing was successful
64 bool IsValid() const { return m_ErrorCode == LUrlParserError_Ok; }
65
66 /// helper to convert the port number to int, return 'true' if the port is valid (within the 0..65535 range)
67 bool GetPort( int* OutPort ) const;
68
69 /// parse the URL
70 static clParseURL ParseURL( const std::string& URL );
71
72private:
73 explicit clParseURL( LUrlParserError ErrorCode )
74 : m_ErrorCode( ErrorCode )
75 {}
76};
77
78} // namespace LUrlParser
diff --git a/externals/lurlparser/README.md b/externals/lurlparser/README.md
deleted file mode 100644
index be7f0135a..000000000
--- a/externals/lurlparser/README.md
+++ /dev/null
@@ -1,19 +0,0 @@
1From https://github.com/corporateshark/LUrlParser/commit/455d5e2d27e3946f11ad0328fee9ee2628e6a8e2
2
3MIT License
4
5===
6
7Lightweight URL & URI parser (RFC 1738, RFC 3986)
8
9(C) Sergey Kosarevsky, 2015
10
11@corporateshark sk@linderdaum.com
12
13http://www.linderdaum.com
14
15http://blog.linderdaum.com
16
17=============================
18
19A tiny and lightweight URL & URI parser (RFC 1738, RFC 3986) written in C++.
diff --git a/src/web_service/CMakeLists.txt b/src/web_service/CMakeLists.txt
index 7e484b906..ae85a72ea 100644
--- a/src/web_service/CMakeLists.txt
+++ b/src/web_service/CMakeLists.txt
@@ -9,4 +9,4 @@ add_library(web_service STATIC
9) 9)
10 10
11create_target_directory_groups(web_service) 11create_target_directory_groups(web_service)
12target_link_libraries(web_service PRIVATE common nlohmann_json::nlohmann_json httplib lurlparser) 12target_link_libraries(web_service PRIVATE common nlohmann_json::nlohmann_json httplib)
diff --git a/src/web_service/web_backend.cpp b/src/web_service/web_backend.cpp
index 534960d09..c56cd7c71 100644
--- a/src/web_service/web_backend.cpp
+++ b/src/web_service/web_backend.cpp
@@ -7,7 +7,6 @@
7#include <mutex> 7#include <mutex>
8#include <string> 8#include <string>
9 9
10#include <LUrlParser.h>
11#include <fmt/format.h> 10#include <fmt/format.h>
12#include <httplib.h> 11#include <httplib.h>
13 12
@@ -19,9 +18,6 @@ namespace WebService {
19 18
20constexpr std::array<const char, 1> API_VERSION{'1'}; 19constexpr std::array<const char, 1> API_VERSION{'1'};
21 20
22constexpr int HTTP_PORT = 80;
23constexpr int HTTPS_PORT = 443;
24
25constexpr std::size_t TIMEOUT_SECONDS = 30; 21constexpr std::size_t TIMEOUT_SECONDS = 30;
26 22
27struct Client::Impl { 23struct Client::Impl {
@@ -67,21 +63,7 @@ struct Client::Impl {
67 const std::string& jwt = "", const std::string& username = "", 63 const std::string& jwt = "", const std::string& username = "",
68 const std::string& token = "") { 64 const std::string& token = "") {
69 if (cli == nullptr) { 65 if (cli == nullptr) {
70 const auto parsedUrl = LUrlParser::clParseURL::ParseURL(host); 66 cli = std::make_unique<httplib::Client>(host.c_str());
71 int port{};
72 if (parsedUrl.m_Scheme == "http") {
73 if (!parsedUrl.GetPort(&port)) {
74 port = HTTP_PORT;
75 }
76 } else if (parsedUrl.m_Scheme == "https") {
77 if (!parsedUrl.GetPort(&port)) {
78 port = HTTPS_PORT;
79 }
80 } else {
81 LOG_ERROR(WebService, "Bad URL scheme {}", parsedUrl.m_Scheme);
82 return WebResult{WebResult::Code::InvalidURL, "Bad URL scheme", ""};
83 }
84 cli = std::make_unique<httplib::Client>(parsedUrl.m_Host.c_str(), port);
85 } 67 }
86 cli->set_connection_timeout(TIMEOUT_SECONDS); 68 cli->set_connection_timeout(TIMEOUT_SECONDS);
87 cli->set_read_timeout(TIMEOUT_SECONDS); 69 cli->set_read_timeout(TIMEOUT_SECONDS);