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 #if defined(WITH_CURL_OPENSSL) && OPENSSL_API_COMPAT < 0x10100000L
71 ::openssl::init_ssl();
74 bool fe_inits_ssl(boost::optional
<const fe_map_t
&> m
, long& curl_global_flags
){
76 for (const auto& kv
: *m
){
77 if (kv
.first
== "beast"){
79 kv
.second
->get_val("ssl_certificate","", &cert
);
81 /* TODO this flag is no op for curl > 7.57 */
82 curl_global_flags
&= ~CURL_GLOBAL_SSL
;
90 #endif // WITH_CURL_OPENSSL
92 std::once_flag curl_init_flag
;
94 void setup_curl(boost::optional
<const fe_map_t
&> m
) {
95 long curl_global_flags
= CURL_GLOBAL_ALL
;
97 #if defined(WITH_CURL_OPENSSL) && OPENSSL_API_COMPAT < 0x10100000L
98 if (!fe_inits_ssl(m
, curl_global_flags
))
102 std::call_once(curl_init_flag
, curl_global_init
, curl_global_flags
);
103 rgw_setup_saved_curl_handles();
106 void cleanup_curl() {
107 rgw_release_all_curl_handles();
108 curl_global_cleanup();
111 } /* namespace curl */
112 } /* namespace rgw */