1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include "rgw_http_client_curl.h"
9 #include "rgw_common.h"
10 #define dout_context g_ceph_context
11 #define dout_subsys ceph_subsys_rgw
13 #ifdef WITH_CURL_OPENSSL
14 #include <openssl/crypto.h>
17 #if defined(WITH_CURL_OPENSSL) && OPENSSL_API_COMPAT < 0x10100000L
22 std::vector
<std::mutex
> locks
;
24 explicit RGWSSLSetup(int n
) : locks (n
){}
26 void set_lock(int id
){
29 } catch (std::out_of_range
& e
) {
30 dout(0) << __func__
<< " failed to set locks" << dendl
;
34 void clear_lock(int id
){
36 locks
.at(id
).unlock();
37 } catch (std::out_of_range
& e
) {
38 dout(0) << __func__
<< " failed to unlock" << dendl
;
44 void rgw_ssl_locking_callback(int mode
, int id
, const char *file
, int line
)
46 static RGWSSLSetup
locks(CRYPTO_num_locks());
47 if (mode
& CRYPTO_LOCK
)
53 unsigned long rgw_ssl_thread_id_callback(){
54 return (unsigned long)pthread_self();
58 CRYPTO_set_id_callback((unsigned long (*) ()) rgw_ssl_thread_id_callback
);
59 CRYPTO_set_locking_callback(rgw_ssl_locking_callback
);
62 } /* namespace openssl */
63 #endif // WITH_CURL_OPENSSL
69 static void check_curl()
71 #ifndef HAVE_CURL_MULTI_WAIT
72 derr
<< "WARNING: libcurl doesn't support curl_multi_wait()" << dendl
;
73 derr
<< "WARNING: cross zone / region transfer performance may be affected" << dendl
;
77 #if defined(WITH_CURL_OPENSSL) && OPENSSL_API_COMPAT < 0x10100000L
79 ::openssl::init_ssl();
82 bool fe_inits_ssl(boost::optional
<const fe_map_t
&> m
, long& curl_global_flags
){
84 for (const auto& kv
: *m
){
85 if (kv
.first
== "beast"){
87 kv
.second
->get_val("ssl_certificate","", &cert
);
89 /* TODO this flag is no op for curl > 7.57 */
90 curl_global_flags
&= ~CURL_GLOBAL_SSL
;
98 #endif // WITH_CURL_OPENSSL
100 std::once_flag curl_init_flag
;
102 void setup_curl(boost::optional
<const fe_map_t
&> m
) {
105 long curl_global_flags
= CURL_GLOBAL_ALL
;
107 #if defined(WITH_CURL_OPENSSL) && OPENSSL_API_COMPAT < 0x10100000L
108 if (!fe_inits_ssl(m
, curl_global_flags
))
112 std::call_once(curl_init_flag
, curl_global_init
, curl_global_flags
);
113 rgw_setup_saved_curl_handles();
116 void cleanup_curl() {
117 rgw_release_all_curl_handles();
118 curl_global_cleanup();
121 } /* namespace curl */
122 } /* namespace rgw */