1
- #ifdef _WIN32
2
- #define NOMINMAX
3
- #define WIN32_LEAN_AND_MEAN
4
- #endif
5
-
6
1
#include " CurlClient.h"
7
2
8
3
#ifdef HTTPS_BACKEND_CURL
12
7
#include < sstream>
13
8
#include < vector>
14
9
15
- // Dynamic library loader
16
- #ifdef _WIN32
17
- #include < windows.h>
18
- #else
19
- #include < dlfcn.h>
20
- #endif
21
-
22
10
typedef struct StringReader
23
11
{
24
12
const std::string *str;
25
13
size_t pos;
26
14
} StringReader;
27
15
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
-
39
16
CurlClient::Curl::Curl ()
40
17
: handle(nullptr )
41
18
, loaded(false )
@@ -48,33 +25,35 @@ CurlClient::Curl::Curl()
48
25
, slist_append(nullptr )
49
26
, slist_free_all(nullptr )
50
27
{
28
+ using namespace LibraryLoader ;
29
+
51
30
#ifdef _WIN32
52
- handle = ( void *) LoadLibraryA (" libcurl.dll" );
31
+ handle = OpenLibrary (" libcurl.dll" );
53
32
#else
54
- handle = dlopen (" libcurl.so.4" , RTLD_LAZY );
33
+ handle = OpenLibrary (" libcurl.so.4" );
55
34
#endif
56
35
if (!handle)
57
36
return ;
58
37
59
38
// Load symbols
60
39
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" ))
62
41
return ;
63
- if (!loadSymbol (global_cleanup, handle, " curl_global_cleanup" ))
42
+ if (!LoadSymbol (global_cleanup, handle, " curl_global_cleanup" ))
64
43
return ;
65
- if (!loadSymbol (easy_init, handle, " curl_easy_init" ))
44
+ if (!LoadSymbol (easy_init, handle, " curl_easy_init" ))
66
45
return ;
67
- if (!loadSymbol (easy_cleanup, handle, " curl_easy_cleanup" ))
46
+ if (!LoadSymbol (easy_cleanup, handle, " curl_easy_cleanup" ))
68
47
return ;
69
- if (!loadSymbol (easy_setopt, handle, " curl_easy_setopt" ))
48
+ if (!LoadSymbol (easy_setopt, handle, " curl_easy_setopt" ))
70
49
return ;
71
- if (!loadSymbol (easy_perform, handle, " curl_easy_perform" ))
50
+ if (!LoadSymbol (easy_perform, handle, " curl_easy_perform" ))
72
51
return ;
73
- if (!loadSymbol (easy_getinfo, handle, " curl_easy_getinfo" ))
52
+ if (!LoadSymbol (easy_getinfo, handle, " curl_easy_getinfo" ))
74
53
return ;
75
- if (!loadSymbol (slist_append, handle, " curl_slist_append" ))
54
+ if (!LoadSymbol (slist_append, handle, " curl_slist_append" ))
76
55
return ;
77
- if (!loadSymbol (slist_free_all, handle, " curl_slist_free_all" ))
56
+ if (!LoadSymbol (slist_free_all, handle, " curl_slist_free_all" ))
78
57
return ;
79
58
80
59
global_init (CURL_GLOBAL_DEFAULT);
@@ -87,11 +66,7 @@ CurlClient::Curl::~Curl()
87
66
global_cleanup ();
88
67
89
68
if (handle)
90
- #ifdef _WIN32
91
- FreeLibrary ((HMODULE) handle);
92
- #else
93
- dlclose (handle);
94
- #endif
69
+ LibraryLoader::CloseLibrary (handle);
95
70
}
96
71
97
72
static char toUppercase (char c)
0 commit comments