From 15de49cab1500ca35950bd32d1ea150dcb59ae13 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 11 Nov 2023 10:19:03 +0100 Subject: [PATCH] fix non-ssl build --- src/ebusd/main.cpp | 6 +++++- src/ebusd/main.h | 3 ++- src/ebusd/main_args.cpp | 10 ++++++---- src/ebusd/mainloop.cpp | 4 ++-- src/lib/utils/httpclient.cpp | 12 ++++++------ src/lib/utils/httpclient.h | 6 +++--- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 871fd24a..576c9fb4 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -263,7 +263,11 @@ int main(int argc, char* argv[], char* envp[]) { const string lang = MappedFileReader::normalizeLanguage( s_opt.preferLanguage == nullptr || !s_opt.preferLanguage[0] ? "" : s_opt.preferLanguage); string configLocalPrefix, configUriPrefix; +#ifdef HAVE_SSL HttpClient::initialize(s_opt.caFile, s_opt.caPath); +#else // HAVE_SSL + HttpClient::initialize(nullptr, nullptr); +#endif // HAVE_SSL HttpClient* configHttpClient = nullptr; string configPath = s_opt.configPath; if (configPath.find("://") == string::npos) { @@ -288,7 +292,7 @@ int main(int argc, char* argv[], char* envp[]) { logWrite(lf_main, ll_error, "invalid configPath URL (HTTPS not supported)"); // force logging on exit return EINVAL; } -#endif +#endif // HAVE_SSL logWrite(lf_main, ll_error, "invalid configPath URL"); // force logging on exit return EINVAL; } diff --git a/src/ebusd/main.h b/src/ebusd/main.h index d29e6582..c8cdca63 100755 --- a/src/ebusd/main.h +++ b/src/ebusd/main.h @@ -63,9 +63,10 @@ typedef struct options { bool injectMessages; //!< inject remaining arguments as already seen messages bool stopAfterInject; //!< only inject messages once, then stop int injectCount; //!< number of message arguments to inject, or 0 +#ifdef HAVE_SSL const char* caFile; //!< the CA file to use (uses defaults if neither caFile nor caPath are set), or "#" for insecure const char* caPath; //!< the path with CA files to use (uses defaults if neither caFile nor caPath are set) - +#endif // HAVE_SSL symbol_t address; //!< own bus address [31] bool answer; //!< answer to requests from other masters unsigned int acquireTimeout; //!< bus acquisition timeout in ms [10] diff --git a/src/ebusd/main_args.cpp b/src/ebusd/main_args.cpp index 61d39b0b..b270207e 100755 --- a/src/ebusd/main_args.cpp +++ b/src/ebusd/main_args.cpp @@ -32,9 +32,9 @@ namespace ebusd { /** the default path of the configuration files. */ #ifdef HAVE_SSL #define CONFIG_PATH "https" CONFIG_PATH_SUFFIX -#else +#else // HAVE_SSL #define CONFIG_PATH "http" CONFIG_PATH_SUFFIX -#endif +#endif // HAVE_SSL /** the default program options. */ static const options_t s_default_opt = { @@ -57,9 +57,10 @@ static const options_t s_default_opt = { .injectMessages = false, .stopAfterInject = false, .injectCount = 0, +#ifdef HAVE_SSL .caFile = nullptr, .caPath = nullptr, - +#endif // HAVE_SSL .address = 0x31, .answer = false, .acquireTimeout = 10, @@ -345,13 +346,14 @@ static int parse_opt(int key, char *arg, const argParseOpt *parseOpt, struct opt opt->injectMessages = true; opt->stopAfterInject = arg && strcmp("stop", arg) == 0; break; +#ifdef HAVE_SSL case O_CAFILE: // --cafile=FILE opt->caFile = arg; break; case O_CAPATH: // --capath=PATH opt->caPath = arg; break; - +#endif // HAVE_SSL // eBUS options: case 'a': // --address=31 { diff --git a/src/ebusd/mainloop.cpp b/src/ebusd/mainloop.cpp index aafb7491..f8351d7b 100644 --- a/src/ebusd/mainloop.cpp +++ b/src/ebusd/mainloop.cpp @@ -298,9 +298,9 @@ void MainLoop::run() { if (!m_httpClient.connect("upd.ebusd.eu", #ifdef HAVE_SSL 443, true, -#else +#else // HAVE_SSL 80, false, -#endif +#endif // HAVE_SSL PACKAGE_NAME "/" PACKAGE_VERSION)) { logError(lf_main, "update check connect error"); nextCheckRun = now + CHECK_INITIAL_DELAY; diff --git a/src/lib/utils/httpclient.cpp b/src/lib/utils/httpclient.cpp index bbdc71c4..8a369c93 100755 --- a/src/lib/utils/httpclient.cpp +++ b/src/lib/utils/httpclient.cpp @@ -344,11 +344,11 @@ bool HttpClient::parseUrl(const string& url, string* proto, string* host, uint16 if (!isSsl && *proto != "http") { return false; } -#else +#else // HAVE_SSL if (*proto != "http") { return false; } -#endif +#endif // HAVE_SSL size_t pos = url.find('/', hostPos); if (pos == hostPos) { return false; @@ -387,12 +387,12 @@ bool HttpClient::connect(const string& host, const uint16_t port, bool https, co #ifdef HAVE_SSL m_socket = SSLSocket::connect(host, port, https, timeout, s_caFile, s_caPath); m_https = https; -#else +#else // HAVE_SSL if (https) { return false; } m_socket = TCPSocket::connect(host, port, timeout); -#endif +#endif // HAVE_SSL if (!m_socket) { return false; } @@ -410,9 +410,9 @@ bool HttpClient::reconnect() { } #ifdef HAVE_SSL m_socket = SSLSocket::connect(m_host, m_port, m_https, m_timeout, s_caFile, s_caPath); -#else +#else // HAVE_SSL m_socket = TCPSocket::connect(m_host, m_port, m_timeout); -#endif +#endif // HAVE_SSL if (!m_socket) { return false; } diff --git a/src/lib/utils/httpclient.h b/src/lib/utils/httpclient.h index 28a4afb0..f5645eac 100755 --- a/src/lib/utils/httpclient.h +++ b/src/lib/utils/httpclient.h @@ -32,7 +32,7 @@ # include # include # include -#endif +#endif // HAVE_SSL /** typedef for referencing @a sockaddr_in within namespace. */ typedef struct sockaddr_in socketaddress; @@ -122,7 +122,7 @@ class HttpClient { HttpClient() : #ifdef HAVE_SSL m_https(false), -#endif +#endif // HAVE_SSL m_socket(nullptr), m_port(0), m_timeout(0), m_bufferSize(0), m_buffer(nullptr) { } @@ -250,7 +250,7 @@ class HttpClient { /** the path with CA files to use. */ static const char* s_caPath; -#endif +#endif // HAVE_SSL /** the currently connected socket. */ SocketClass* m_socket;