1- #ifdef _WIN32
2- #define NOMINMAX
3- #define WIN32_LEAN_AND_MEAN
4- #endif
5-
61#include " CurlClient.h"
72
83#ifdef HTTPS_BACKEND_CURL
127#include < sstream>
138#include < vector>
149
15- // Dynamic library loader
16- #ifdef _WIN32
17- #include < windows.h>
18- #else
19- #include < dlfcn.h>
20- #endif
21-
2210typedef struct StringReader
2311{
2412 const std::string *str;
2513 size_t pos;
2614} StringReader;
2715
28- template <class T >
29- static inline bool loadSymbol (T &var, void *handle, const char *name)
30- {
31- #ifdef _WIN32
32- var = (T) GetProcAddress ((HMODULE) handle, name);
33- #else
34- var = (T) dlsym (handle, name);
35- #endif
36- return var != nullptr ;
37- }
38-
3916CurlClient::Curl::Curl ()
4017: handle(nullptr )
4118, loaded(false )
@@ -48,33 +25,35 @@ CurlClient::Curl::Curl()
4825, slist_append(nullptr )
4926, slist_free_all(nullptr )
5027{
28+ using namespace LibraryLoader ;
29+
5130#ifdef _WIN32
52- handle = ( void *) LoadLibraryA (" libcurl.dll" );
31+ handle = OpenLibrary (" libcurl.dll" );
5332#else
54- handle = dlopen (" libcurl.so.4" , RTLD_LAZY );
33+ handle = OpenLibrary (" libcurl.so.4" );
5534#endif
5635 if (!handle)
5736 return ;
5837
5938 // Load symbols
6039 decltype (&curl_global_init) global_init = nullptr ;
61- if (!loadSymbol (global_init, handle, " curl_global_init" ))
40+ if (!LoadSymbol (global_init, handle, " curl_global_init" ))
6241 return ;
63- if (!loadSymbol (global_cleanup, handle, " curl_global_cleanup" ))
42+ if (!LoadSymbol (global_cleanup, handle, " curl_global_cleanup" ))
6443 return ;
65- if (!loadSymbol (easy_init, handle, " curl_easy_init" ))
44+ if (!LoadSymbol (easy_init, handle, " curl_easy_init" ))
6645 return ;
67- if (!loadSymbol (easy_cleanup, handle, " curl_easy_cleanup" ))
46+ if (!LoadSymbol (easy_cleanup, handle, " curl_easy_cleanup" ))
6847 return ;
69- if (!loadSymbol (easy_setopt, handle, " curl_easy_setopt" ))
48+ if (!LoadSymbol (easy_setopt, handle, " curl_easy_setopt" ))
7049 return ;
71- if (!loadSymbol (easy_perform, handle, " curl_easy_perform" ))
50+ if (!LoadSymbol (easy_perform, handle, " curl_easy_perform" ))
7251 return ;
73- if (!loadSymbol (easy_getinfo, handle, " curl_easy_getinfo" ))
52+ if (!LoadSymbol (easy_getinfo, handle, " curl_easy_getinfo" ))
7453 return ;
75- if (!loadSymbol (slist_append, handle, " curl_slist_append" ))
54+ if (!LoadSymbol (slist_append, handle, " curl_slist_append" ))
7655 return ;
77- if (!loadSymbol (slist_free_all, handle, " curl_slist_free_all" ))
56+ if (!LoadSymbol (slist_free_all, handle, " curl_slist_free_all" ))
7857 return ;
7958
8059 global_init (CURL_GLOBAL_DEFAULT);
@@ -87,11 +66,7 @@ CurlClient::Curl::~Curl()
8766 global_cleanup ();
8867
8968 if (handle)
90- #ifdef _WIN32
91- FreeLibrary ((HMODULE) handle);
92- #else
93- dlclose (handle);
94- #endif
69+ LibraryLoader::CloseLibrary (handle);
9570}
9671
9772static char toUppercase (char c)
0 commit comments