-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from bartbes/selectable_library_loaders
Selectable library loaders, including link-time
- Loading branch information
Showing
12 changed files
with
251 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
namespace LibraryLoader | ||
{ | ||
using handle = void; | ||
using function = void(); | ||
|
||
handle *OpenLibrary(const char *name); | ||
void CloseLibrary(handle *handle); | ||
handle* GetCurrentProcessHandle(); | ||
|
||
function *GetFunction(handle *handle, const char *name); | ||
|
||
template<class T> | ||
inline bool LoadSymbol(T& var, handle *handle, const char *name) | ||
{ | ||
var = reinterpret_cast<T>(GetFunction(handle, name)); | ||
return var != nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "../common/config.h" | ||
#include "../common/LibraryLoader.h" | ||
|
||
#ifdef HTTPS_LIBRARY_LOADER_LINKTIME | ||
|
||
#include <cstring> | ||
|
||
#ifdef HTTPS_BACKEND_CURL | ||
#include <curl/curl.h> | ||
|
||
static char CurlHandle; | ||
#endif | ||
|
||
#if defined(HTTPS_BACKEND_OPENSSL) || defined(HTTPS_BACKEND_ANDROID) | ||
# error "Selected backends that are not compatible with this loader" | ||
#endif | ||
|
||
namespace LibraryLoader | ||
{ | ||
handle *OpenLibrary(const char *name) | ||
{ | ||
#ifdef HTTPS_BACKEND_CURL | ||
if (strstr(name, "libcurl") == name) | ||
return reinterpret_cast<handle *>(&CurlHandle); | ||
#endif | ||
return nullptr; | ||
} | ||
|
||
void CloseLibrary(handle *) | ||
{ | ||
} | ||
|
||
handle* GetCurrentProcessHandle() | ||
{ | ||
return nullptr; | ||
} | ||
|
||
function *GetFunction(handle *handle, const char *name) | ||
{ | ||
#define RETURN_MATCHING_FUNCTION(func) \ | ||
if (strcmp(name, #func) == 0) \ | ||
return reinterpret_cast<function *>(&func); | ||
|
||
#ifdef HTTPS_BACKEND_CURL | ||
if (handle == &CurlHandle) | ||
{ | ||
RETURN_MATCHING_FUNCTION(curl_global_init); | ||
RETURN_MATCHING_FUNCTION(curl_global_cleanup); | ||
RETURN_MATCHING_FUNCTION(curl_easy_init); | ||
RETURN_MATCHING_FUNCTION(curl_easy_cleanup); | ||
RETURN_MATCHING_FUNCTION(curl_easy_setopt); | ||
RETURN_MATCHING_FUNCTION(curl_easy_perform); | ||
RETURN_MATCHING_FUNCTION(curl_easy_getinfo); | ||
RETURN_MATCHING_FUNCTION(curl_slist_append); | ||
RETURN_MATCHING_FUNCTION(curl_slist_free_all); | ||
} | ||
#endif | ||
|
||
#undef RETURN_MATCHING_FUNCTION | ||
|
||
return nullptr; | ||
} | ||
} | ||
|
||
#endif // HTTPS_LIBRARY_LOADER_LINKTIME | ||
|
Oops, something went wrong.