make capath+cafile static as they are
This commit is contained in:
+2
-1
@@ -882,6 +882,7 @@ int main(int argc, char* argv[], char* envp[]) {
|
|||||||
const string lang = MappedFileReader::normalizeLanguage(
|
const string lang = MappedFileReader::normalizeLanguage(
|
||||||
s_opt.preferLanguage == nullptr || !s_opt.preferLanguage[0] ? "" : s_opt.preferLanguage);
|
s_opt.preferLanguage == nullptr || !s_opt.preferLanguage[0] ? "" : s_opt.preferLanguage);
|
||||||
string configLocalPrefix, configUriPrefix;
|
string configLocalPrefix, configUriPrefix;
|
||||||
|
HttpClient::initialize(s_opt.caFile, s_opt.caPath);
|
||||||
HttpClient* configHttpClient = nullptr;
|
HttpClient* configHttpClient = nullptr;
|
||||||
if (s_configPath.find("://") == string::npos) {
|
if (s_configPath.find("://") == string::npos) {
|
||||||
configLocalPrefix = s_configPath;
|
configLocalPrefix = s_configPath;
|
||||||
@@ -909,7 +910,7 @@ int main(int argc, char* argv[], char* envp[]) {
|
|||||||
logWrite(lf_main, ll_error, "invalid configPath URL"); // force logging on exit
|
logWrite(lf_main, ll_error, "invalid configPath URL"); // force logging on exit
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
configHttpClient = new HttpClient(s_opt.caFile, s_opt.caPath);
|
configHttpClient = new HttpClient();
|
||||||
if (
|
if (
|
||||||
// check with low timeout of 1 second initially:
|
// check with low timeout of 1 second initially:
|
||||||
!configHttpClient->connect(configHost, configPort, proto == "https", PACKAGE_NAME "/" PACKAGE_VERSION, 1)
|
!configHttpClient->connect(configHost, configPort, proto == "https", PACKAGE_NAME "/" PACKAGE_VERSION, 1)
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ MainLoop::MainLoop(const struct options& opt, Device *device, MessageMap* messag
|
|||||||
: Thread(), m_device(device), m_reconnectCount(0), m_userList(opt.accessLevel), m_messages(messages),
|
: Thread(), m_device(device), m_reconnectCount(0), m_userList(opt.accessLevel), m_messages(messages),
|
||||||
m_scanHelper(scanHelper), m_address(opt.address), m_scanConfig(opt.scanConfig),
|
m_scanHelper(scanHelper), m_address(opt.address), m_scanConfig(opt.scanConfig),
|
||||||
m_initialScan(opt.readOnly ? ESC : opt.initialScan), m_polling(opt.pollInterval > 0), m_enableHex(opt.enableHex),
|
m_initialScan(opt.readOnly ? ESC : opt.initialScan), m_polling(opt.pollInterval > 0), m_enableHex(opt.enableHex),
|
||||||
m_shutdown(false), m_runUpdateCheck(opt.updateCheck), m_httpClient(opt.caFile, opt.caPath) {
|
m_shutdown(false), m_runUpdateCheck(opt.updateCheck), m_httpClient() {
|
||||||
m_device->setListener(this);
|
m_device->setListener(this);
|
||||||
// open Device
|
// open Device
|
||||||
result_t result = m_device->open();
|
result_t result = m_device->open();
|
||||||
|
|||||||
@@ -300,18 +300,22 @@ SSLSocket* SSLSocket::connect(const string& host, const uint16_t& port, bool htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool HttpClient::s_initialized = false;
|
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) {
|
if (s_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_initialized = true;
|
s_initialized = true;
|
||||||
|
s_caFile = caFile;
|
||||||
|
s_caPath = caPath;
|
||||||
SSL_library_init();
|
SSL_library_init();
|
||||||
SSL_load_error_strings();
|
SSL_load_error_strings();
|
||||||
signal(SIGPIPE, SIG_IGN); // needed to avoid SIGPIPE when writing to a closed pipe
|
signal(SIGPIPE, SIG_IGN); // needed to avoid SIGPIPE when writing to a closed pipe
|
||||||
}
|
}
|
||||||
#else // HAVE_SSL
|
#else // HAVE_SSL
|
||||||
void HttpClient::initialize() {
|
void HttpClient::initialize(const char* caFile, const char* caPath) {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
#endif // HAVE_SSL
|
#endif // HAVE_SSL
|
||||||
@@ -369,7 +373,7 @@ bool HttpClient::connect(const string& host, const uint16_t port, bool https, co
|
|||||||
initialize();
|
initialize();
|
||||||
disconnect();
|
disconnect();
|
||||||
#ifdef HAVE_SSL
|
#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;
|
m_https = https;
|
||||||
#else
|
#else
|
||||||
if (https) {
|
if (https) {
|
||||||
@@ -393,7 +397,7 @@ bool HttpClient::reconnect() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_SSL
|
#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
|
#else
|
||||||
m_socket = TCPSocket::connect(m_host, m_port, m_timeout);
|
m_socket = TCPSocket::connect(m_host, m_port, m_timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -118,20 +118,12 @@ class HttpClient {
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* 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
|
#ifdef HAVE_SSL
|
||||||
m_https(false),
|
m_https(false),
|
||||||
m_caFile(caFile),
|
|
||||||
m_caPath(caPath),
|
|
||||||
#endif
|
#endif
|
||||||
m_socket(nullptr), m_port(0), m_timeout(0), m_bufferSize(0), m_buffer(nullptr) {
|
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.
|
* Parse an HTTP URL.
|
||||||
@@ -238,10 +232,10 @@ class HttpClient {
|
|||||||
bool m_https;
|
bool m_https;
|
||||||
|
|
||||||
/** the CA file to use. */
|
/** the CA file to use. */
|
||||||
const char* m_caFile;
|
static const char* s_caFile;
|
||||||
|
|
||||||
/** the path with CA files to use. */
|
/** the path with CA files to use. */
|
||||||
const char* m_caPath;
|
static const char* s_caPath;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** the currently connected socket. */
|
/** the currently connected socket. */
|
||||||
|
|||||||
Reference in New Issue
Block a user