make capath+cafile static as they are
This commit is contained in:
@@ -300,18 +300,22 @@ SSLSocket* SSLSocket::connect(const string& host, const uint16_t& port, bool htt
|
||||
}
|
||||
|
||||
bool HttpClient::s_initialized = false;
|
||||
const char* HttpClient::s_caFile = nullptr;
|
||||
const char* HttpClient::s_caPath = nullptr;
|
||||
|
||||
void HttpClient::initialize() {
|
||||
void HttpClient::initialize(const char* caFile, const char* caPath) {
|
||||
if (s_initialized) {
|
||||
return;
|
||||
}
|
||||
s_initialized = true;
|
||||
s_caFile = caFile;
|
||||
s_caPath = caPath;
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
signal(SIGPIPE, SIG_IGN); // needed to avoid SIGPIPE when writing to a closed pipe
|
||||
}
|
||||
#else // HAVE_SSL
|
||||
void HttpClient::initialize() {
|
||||
void HttpClient::initialize(const char* caFile, const char* caPath) {
|
||||
// empty
|
||||
}
|
||||
#endif // HAVE_SSL
|
||||
@@ -369,7 +373,7 @@ bool HttpClient::connect(const string& host, const uint16_t port, bool https, co
|
||||
initialize();
|
||||
disconnect();
|
||||
#ifdef HAVE_SSL
|
||||
m_socket = SSLSocket::connect(host, port, https, timeout, m_caFile, m_caPath);
|
||||
m_socket = SSLSocket::connect(host, port, https, timeout, s_caFile, s_caPath);
|
||||
m_https = https;
|
||||
#else
|
||||
if (https) {
|
||||
@@ -393,7 +397,7 @@ bool HttpClient::reconnect() {
|
||||
return false;
|
||||
}
|
||||
#ifdef HAVE_SSL
|
||||
m_socket = SSLSocket::connect(m_host, m_port, m_https, m_timeout, m_caFile, m_caPath);
|
||||
m_socket = SSLSocket::connect(m_host, m_port, m_https, m_timeout, s_caFile, s_caPath);
|
||||
#else
|
||||
m_socket = TCPSocket::connect(m_host, m_port, m_timeout);
|
||||
#endif
|
||||
|
||||
@@ -118,20 +118,12 @@ class HttpClient {
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
* @param caFile the CA file to use (uses defaults if neither caFile nor caPath are set), or "#" for insecure.
|
||||
* @param caPath the path with CA files to use (uses defaults if neither caFile nor caPath are set).
|
||||
* @param init whether to immediately initialize the library (instead of during connect()).
|
||||
*/
|
||||
explicit HttpClient(const char* caFile = nullptr, const char* caPath = nullptr, bool init = true) :
|
||||
HttpClient() :
|
||||
#ifdef HAVE_SSL
|
||||
m_https(false),
|
||||
m_caFile(caFile),
|
||||
m_caPath(caPath),
|
||||
#endif
|
||||
m_socket(nullptr), m_port(0), m_timeout(0), m_bufferSize(0), m_buffer(nullptr) {
|
||||
if (init) {
|
||||
initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,9 +138,11 @@ class HttpClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize HttpClient.
|
||||
* Initialize the underlying SSL library.
|
||||
* @param caFile the CA file to use (uses defaults if neither caFile nor caPath are set), or "#" for insecure.
|
||||
* @param caPath the path with CA files to use (uses defaults if neither caFile nor caPath are set).
|
||||
*/
|
||||
static void initialize();
|
||||
static void initialize(const char* caFile = nullptr, const char* caPath = nullptr);
|
||||
|
||||
/**
|
||||
* Parse an HTTP URL.
|
||||
@@ -238,10 +232,10 @@ class HttpClient {
|
||||
bool m_https;
|
||||
|
||||
/** the CA file to use. */
|
||||
const char* m_caFile;
|
||||
static const char* s_caFile;
|
||||
|
||||
/** the path with CA files to use. */
|
||||
const char* m_caPath;
|
||||
static const char* s_caPath;
|
||||
#endif
|
||||
|
||||
/** the currently connected socket. */
|
||||
|
||||
Reference in New Issue
Block a user