Skip to content

Commit c07fb1a

Browse files
authored
Merge pull request #3 from slime73/cleanup
Some cleanup to make it easier to build within other codebases.
2 parents 6b3da2d + f9f9277 commit c07fb1a

21 files changed

+231
-147
lines changed

Android.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ LOCAL_ARM_NEON := true
1111

1212
LOCAL_C_INCLUDES := \
1313
${LOCAL_PATH}/src \
14-
${LOCAL_PATH}/src/android \
15-
${LOCAL_PATH}/src/android/ndk-build
14+
${LOCAL_PATH}/src/android
1615

1716
LOCAL_SRC_FILES := \
1817
src/lua/main.cpp \
18+
src/common/HTTPS.cpp \
1919
src/common/HTTPRequest.cpp \
2020
src/common/HTTPSClient.cpp \
2121
src/common/PlaintextConnection.cpp \

license.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2019-2021 LOVE Development Team
1+
Copyright (c) 2019-2022 LOVE Development Team
22

33
This software is provided 'as-is', without any express or implied
44
warranty. In no event will the authors be held liable for any damages

src/CMakeLists.txt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ cmake_minimum_required (VERSION 3.13)
22

33
### Basic compilation settings
44
set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
5-
add_definitions (-DNOMINMAX)
65

76
include_directories (
87
${CMAKE_CURRENT_SOURCE_DIR}
98
${CMAKE_CURRENT_BINARY_DIR}
109
)
1110

1211
### Compiler-specific flags
13-
if (MSVC)
14-
set (DLLEXPORT "__declspec(dllexport)")
15-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
16-
set (DLLEXPORT "__attribute__((visibility(\"default\")))")
12+
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
1713
add_compile_options ("-fvisibility=hidden")
1814
add_link_options ("-fvisibility=hidden")
1915
endif ()
@@ -24,6 +20,7 @@ add_library (https MODULE
2420
)
2521

2622
add_library (https-common STATIC
23+
common/HTTPS.cpp
2724
common/HTTPRequest.cpp
2825
common/HTTPSClient.cpp
2926
common/PlaintextConnection.cpp
@@ -42,7 +39,7 @@ add_library (https-schannel STATIC EXCLUDE_FROM_ALL
4239
)
4340

4441
add_library (https-nsurl STATIC EXCLUDE_FROM_ALL
45-
macos/NSURLClient.mm
42+
apple/NSURLClient.mm
4643
)
4744

4845
add_library (https-android STATIC EXCLUDE_FROM_ALL
@@ -54,31 +51,31 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
5451
option (USE_CURL_BACKEND "Use the libcurl backend" ON)
5552
option (USE_OPENSSL_BACKEND "Use the openssl backend" ON)
5653
option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
57-
option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
54+
option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" OFF)
5855
option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
5956

6057
option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
6158
elseif (WIN32)
6259
option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
6360
option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
6461
option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" ON)
65-
option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
62+
option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" OFF)
6663
option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
6764

6865
option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" ON)
6966
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
7067
option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
7168
option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
7269
option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
73-
option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" ON)
70+
option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" ON)
7471
option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" OFF)
7572

7673
option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
7774
elseif (ANDROID)
7875
option (USE_CURL_BACKEND "Use the libcurl backend" OFF)
7976
option (USE_OPENSSL_BACKEND "Use the openssl backend" OFF)
8077
option (USE_SCHANNEL_BACKEND "Use the schannel backend (windows-only)" OFF)
81-
option (USE_NSURL_BACKEND "Use the NSUrl backend (macos-only)" OFF)
78+
option (USE_NSURL_BACKEND "Use the NSUrl backend (apple-only)" OFF)
8279
option (USE_ANDROID_BACKEND "Use the Android Java backend (Android-only)" ON)
8380

8481
option (USE_WINSOCK "Use winsock instead of BSD sockets (windows-only)" OFF)
@@ -95,22 +92,26 @@ include_directories (${LUA_INCLUDE_DIR})
9592
target_link_libraries (https ${LUA_LIBRARIES})
9693

9794
if (USE_CURL_BACKEND)
95+
set(HTTPS_BACKEND_CURL ON)
9896
find_package (CURL REQUIRED)
9997
include_directories (${CURL_INCLUDE_DIR})
10098
target_link_libraries (https https-curl ${CURL_LIBRARIES})
10199
endif ()
102100

103101
if (USE_OPENSSL_BACKEND)
102+
set(HTTPS_BACKEND_OPENSSL ON)
104103
find_package (OpenSSL REQUIRED)
105104
include_directories (${OPENSSL_INCLUDE_DIR})
106105
target_link_libraries (https https-openssl ${OPENSSL_LIBRARIES})
107106
endif ()
108107

109108
if (USE_SCHANNEL_BACKEND)
109+
set(HTTPS_BACKEND_SCHANNEL ON)
110110
target_link_libraries (https https-schannel ws2_32 secur32)
111111
endif ()
112112

113113
if (USE_NSURL_BACKEND)
114+
set(HTTPS_BACKEND_NSURL ON)
114115
set_target_properties(
115116
https-nsurl
116117
PROPERTIES
@@ -122,12 +123,18 @@ if (USE_NSURL_BACKEND)
122123
endif ()
123124

124125
if (USE_ANDROID_BACKEND)
126+
set(HTTPS_BACKEND_ANDROID ON)
125127
target_link_libraries (https https-android)
126128
message(STATUS "Ensure to add the Java files to your project too!")
127129
endif ()
128130

129-
### Generate config.h
131+
if (USE_WINSOCK)
132+
set(HTTPS_USE_WINSOCK ON)
133+
endif ()
134+
135+
### Generate config-generated.h
136+
add_compile_definitions(HTTPS_HAVE_CONFIG_GENERATED_H)
130137
configure_file (
131-
common/config.h.in
132-
common/config.h
138+
common/config-generated.h.in
139+
common/config-generated.h
133140
)

src/android/AndroidClient.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "AndroidClient.h"
22

3-
#ifdef USE_ANDROID_BACKEND
3+
#ifdef HTTPS_BACKEND_ANDROID
44

55
#include <sstream>
66
#include <type_traits>
@@ -209,4 +209,4 @@ jclass AndroidClient::getHTTPSClass() const
209209
return httpsClass;
210210
}
211211

212-
#endif
212+
#endif // HTTPS_BACKEND_ANDROID

src/android/AndroidClient.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3-
#include "common/config.h"
3+
#include "../common/config.h"
44

5-
#ifdef USE_ANDROID_BACKEND
5+
#ifdef HTTPS_BACKEND_ANDROID
66

77
#include <jni.h>
88

9-
#include "common/HTTPSClient.h"
9+
#include "../common/HTTPSClient.h"
1010

1111
class AndroidClient: public HTTPSClient
1212
{

src/android/ndk-build/common/config.h

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#pragma once
22

3-
#include "common/HTTPSClient.h"
3+
#include "../common/config.h"
4+
5+
#ifdef HTTPS_BACKEND_NSURL
6+
7+
#include "../common/HTTPSClient.h"
48

59
class NSURLClient : public HTTPSClient
610
{
711
public:
812
virtual bool valid() const override;
913
virtual HTTPSClient::Reply request(const HTTPSClient::Request &req) override;
1014
};
15+
16+
#endif // HTTPS_BACKEND_NSURL

src/macos/NSURLClient.mm renamed to src/apple/NSURLClient.mm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#import <Foundation/Foundation.h>
2-
31
#include "NSURLClient.h"
42

3+
#ifdef HTTPS_BACKEND_NSURL
4+
5+
#import <Foundation/Foundation.h>
6+
57
#if ! __has_feature(objc_arc)
68
#error "ARC is off"
79
#endif
@@ -81,4 +83,6 @@
8183
}
8284

8385
return reply;
84-
} }
86+
}}
87+
88+
#endif // HTTPS_BACKEND_NSURL

src/common/HTTPS.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "HTTPS.h"
2+
#include "config.h"
3+
#include "ConnectionClient.h"
4+
5+
#include <stdexcept>
6+
7+
#ifdef HTTPS_BACKEND_CURL
8+
# include "../generic/CurlClient.h"
9+
#endif
10+
#ifdef HTTPS_BACKEND_OPENSSL
11+
# include "../generic/OpenSSLConnection.h"
12+
#endif
13+
#ifdef HTTPS_BACKEND_SCHANNEL
14+
# include "../windows/SChannelConnection.h"
15+
#endif
16+
#ifdef HTTPS_BACKEND_NSURL
17+
# include "../apple/NSURLClient.h"
18+
#endif
19+
#ifdef HTTPS_BACKEND_ANDROID
20+
# include "../android/AndroidClient.h"
21+
#endif
22+
23+
#ifdef HTTPS_BACKEND_CURL
24+
static CurlClient curlclient;
25+
#endif
26+
#ifdef HTTPS_BACKEND_OPENSSL
27+
static ConnectionClient<OpenSSLConnection> opensslclient;
28+
#endif
29+
#ifdef HTTPS_BACKEND_SCHANNEL
30+
static ConnectionClient<SChannelConnection> schannelclient;
31+
#endif
32+
#ifdef HTTPS_BACKEND_NSURL
33+
static NSURLClient nsurlclient;
34+
#endif
35+
#ifdef HTTPS_BACKEND_ANDROID
36+
static AndroidClient androidclient;
37+
#endif
38+
39+
static HTTPSClient *clients[] = {
40+
#ifdef HTTPS_BACKEND_CURL
41+
&curlclient,
42+
#endif
43+
#ifdef HTTPS_BACKEND_OPENSSL
44+
&opensslclient,
45+
#endif
46+
#ifdef HTTPS_BACKEND_SCHANNEL
47+
&schannelclient,
48+
#endif
49+
#ifdef HTTPS_BACKEND_NSURL
50+
&nsurlclient,
51+
#endif
52+
#ifdef HTTPS_BACKEND_ANDROID
53+
&androidclient,
54+
#endif
55+
nullptr,
56+
};
57+
58+
HTTPSClient::Reply request(const HTTPSClient::Request &req)
59+
{
60+
for (size_t i = 0; clients[i]; ++i)
61+
{
62+
HTTPSClient &client = *clients[i];
63+
64+
if (client.valid())
65+
return client.request(req);
66+
}
67+
68+
throw std::runtime_error("No applicable HTTPS implementation found");
69+
}

src/common/HTTPS.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include "HTTPSClient.h"
4+
5+
HTTPSClient::Reply request(const HTTPSClient::Request &req);

0 commit comments

Comments
 (0)