Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTTPS_BACKEND_CURL_LINKED preprocessor AND CMake option. #22

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ endif ()

### "Libraries"
add_library (https MODULE
lua/main.cpp
lua/luahttps.cpp
)

add_library (https-common STATIC
Expand Down Expand Up @@ -131,9 +131,13 @@ target_link_libraries (https https-common)

if (USE_CURL_BACKEND)
set(HTTPS_BACKEND_CURL ON)
option(HTTPS_BACKEND_CURL_LINKED "Require libcurl at load-time instead at runtime." OFF)
find_package (CURL REQUIRED)
include_directories (${CURL_INCLUDE_DIRS})
target_link_libraries (https https-curl)
if (HTTPS_BACKEND_CURL_LINKED)
target_link_libraries(https ${CURL_LIBRARIES})
endif ()
endif ()

if (USE_OPENSSL_BACKEND)
Expand Down
1 change: 1 addition & 0 deletions src/common/config-generated.h.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#cmakedefine HTTPS_BACKEND_CURL
#cmakedefine HTTPS_BACKEND_CURL_LINKED
#cmakedefine HTTPS_BACKEND_OPENSSL
#cmakedefine HTTPS_BACKEND_SCHANNEL
#cmakedefine HTTPS_BACKEND_NSURL
Expand Down
21 changes: 21 additions & 0 deletions src/generic/CurlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
#include <sstream>
#include <vector>

#ifndef HTTPS_BACKEND_CURL_LINKED
// Dynamic library loader
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#endif

typedef struct StringReader
{
const std::string *str;
size_t pos;
} StringReader;

#ifndef HTTPS_BACKEND_CURL_LINKED
template <class T>
static inline bool loadSymbol(T &var, void *handle, const char *name)
{
Expand All @@ -35,6 +38,7 @@ static inline bool loadSymbol(T &var, void *handle, const char *name)
#endif
return var != nullptr;
}
#endif

CurlClient::Curl::Curl()
: handle(nullptr)
Expand All @@ -48,6 +52,19 @@ CurlClient::Curl::Curl()
, slist_append(nullptr)
, slist_free_all(nullptr)
{
#ifdef HTTPS_BACKEND_CURL_LINKED
// Linked cURL always available.
global_cleanup = &curl_global_cleanup;
easy_init = &curl_easy_init;
easy_cleanup = &curl_easy_cleanup;
easy_setopt = &curl_easy_setopt;
easy_perform = &curl_easy_perform;
easy_getinfo = &curl_easy_getinfo;
slist_append = &curl_slist_append;
slist_free_all = &curl_slist_free_all;

curl_global_init(CURL_GLOBAL_DEFAULT);
#else
#ifdef _WIN32
handle = (void *) LoadLibraryA("libcurl.dll");
#else
Expand Down Expand Up @@ -78,6 +95,8 @@ CurlClient::Curl::Curl()
return;

global_init(CURL_GLOBAL_DEFAULT);
#endif // HTTPS_BACKEND_CURL_LINKED

loaded = true;
}

Expand All @@ -86,12 +105,14 @@ CurlClient::Curl::~Curl()
if (loaded)
global_cleanup();

#ifndef HTTPS_BACKEND_CURL_LINKED
if (handle)
#ifdef _WIN32
FreeLibrary((HMODULE) handle);
#else
dlclose(handle);
#endif
#endif
}

static char toUppercase(char c)
Expand Down
File renamed without changes.
Loading