change ENABLE_TCP_SSL to just ENABLE_SSL;

pull/87/head
Bryan Biedenkapp 10 months ago
parent 59b3b915df
commit 030a09ebe9

@ -27,13 +27,13 @@ else ()
message(CHECK_PASS "no") message(CHECK_PASS "no")
endif (ENABLE_TUI_SUPPORT) endif (ENABLE_TUI_SUPPORT)
option(ENABLE_TCP_SSL "Enable TCP SSL support" off) option(ENABLE_SSL "Enable SSL support" off)
message(CHECK_START "Enable TCP SSL support") message(CHECK_START "Enable SSL support")
if (ENABLE_TCP_SSL) if (ENABLE_SSL)
message(CHECK_PASS "yes") message(CHECK_PASS "yes")
else () else ()
message(CHECK_PASS "no") message(CHECK_PASS "no")
endif (ENABLE_TCP_SSL) endif (ENABLE_SSL)
option(DISABLE_WEBSOCKETS "Disable WebSocket support" off) option(DISABLE_WEBSOCKETS "Disable WebSocket support" off)
if (DISABLE_WEBSOCKETS) if (DISABLE_WEBSOCKETS)
@ -54,8 +54,8 @@ if (COMPILE_WIN32)
# No TUI for this # No TUI for this
set(ENABLE_TUI_SUPPORT OFF) set(ENABLE_TUI_SUPPORT OFF)
message(CHECK_START "Enable TUI support - no; for simplicity WIN32 does not support TUI.") message(CHECK_START "Enable TUI support - no; for simplicity WIN32 does not support TUI.")
set(ENABLE_TCP_SSL OFF) set(ENABLE_SSL OFF)
message(CHECK_START "Enable TCP SSL support - no; for simplicity WIN32 does not support TCP SSL.") message(CHECK_START "Enable SSL support - no; for simplicity WIN32 does not support SSL.")
else() else()
set(CMAKE_C_COMPILER /usr/bin/gcc CACHE STRING "C compiler") set(CMAKE_C_COMPILER /usr/bin/gcc CACHE STRING "C compiler")
set(CMAKE_CXX_COMPILER /usr/bin/g++ CACHE STRING "C++ compiler") set(CMAKE_CXX_COMPILER /usr/bin/g++ CACHE STRING "C++ compiler")

@ -17,9 +17,9 @@ else()
set(ENABLE_SETUP_TUI off) set(ENABLE_SETUP_TUI off)
endif (ENABLE_TUI_SUPPORT) endif (ENABLE_TUI_SUPPORT)
if (ENABLE_TCP_SSL) if (ENABLE_SSL)
add_definitions(-DENABLE_TCP_SSL) add_definitions(-DENABLE_SSL)
endif (ENABLE_TCP_SSL) endif (ENABLE_SSL)
option(DISABLE_TUI_APPS "Disable extra TUI applications" off) option(DISABLE_TUI_APPS "Disable extra TUI applications" off)
if (DISABLE_TUI_APPS) if (DISABLE_TUI_APPS)
@ -172,7 +172,7 @@ if (HAVE_SENDMMSG)
endif (HAVE_SENDMMSG) endif (HAVE_SENDMMSG)
# are we enabling SSL support? # are we enabling SSL support?
if (ENABLE_TCP_SSL) if (ENABLE_SSL)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
include_directories("${OPENSSL_INCLUDE_DIR}") include_directories("${OPENSSL_INCLUDE_DIR}")
endif (ENABLE_TCP_SSL) endif (ENABLE_SSL)

@ -17,7 +17,7 @@
#if !defined(__REST_HTTP__SECURE_CLIENT_CONNECTION_H__) #if !defined(__REST_HTTP__SECURE_CLIENT_CONNECTION_H__)
#define __REST_HTTP__SECURE_CLIENT_CONNECTION_H__ #define __REST_HTTP__SECURE_CLIENT_CONNECTION_H__
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "common/Defines.h" #include "common/Defines.h"
#include "common/network/rest/http/HTTPLexer.h" #include "common/network/rest/http/HTTPLexer.h"
@ -262,6 +262,6 @@ namespace network
} // namespace rest } // namespace rest
} // namespace network } // namespace network
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#endif // __REST_HTTP__SECURE_CLIENT_CONNECTION_H__ #endif // __REST_HTTP__SECURE_CLIENT_CONNECTION_H__

@ -17,7 +17,7 @@
#if !defined(__REST_HTTP__SECURE_HTTP_CLIENT_H__) #if !defined(__REST_HTTP__SECURE_HTTP_CLIENT_H__)
#define __REST_HTTP__SECURE_HTTP_CLIENT_H__ #define __REST_HTTP__SECURE_HTTP_CLIENT_H__
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "common/Defines.h" #include "common/Defines.h"
#include "common/network/rest/http/SecureClientConnection.h" #include "common/network/rest/http/SecureClientConnection.h"
@ -204,6 +204,6 @@ namespace network
} // namespace rest } // namespace rest
} // namespace network } // namespace network
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#endif // __REST_HTTP__SECURE_HTTP_CLIENT_H__ #endif // __REST_HTTP__SECURE_HTTP_CLIENT_H__

@ -15,7 +15,7 @@
#if !defined(__REST_HTTP__SECURE_HTTP_SERVER_H__) #if !defined(__REST_HTTP__SECURE_HTTP_SERVER_H__)
#define __REST_HTTP__SECURE_HTTP_SERVER_H__ #define __REST_HTTP__SECURE_HTTP_SERVER_H__
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "common/Defines.h" #include "common/Defines.h"
#include "common/network/rest/http/SecureServerConnection.h" #include "common/network/rest/http/SecureServerConnection.h"
@ -186,6 +186,6 @@ namespace network
} // namespace rest } // namespace rest
} // namespace network } // namespace network
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#endif // __REST_HTTP__SECURE_HTTP_SERVER_H__ #endif // __REST_HTTP__SECURE_HTTP_SERVER_H__

@ -15,7 +15,7 @@
#if !defined(__REST_HTTP__SECURE_SERVER_CONNECTION_H__) #if !defined(__REST_HTTP__SECURE_SERVER_CONNECTION_H__)
#define __REST_HTTP__SECURE_SERVER_CONNECTION_H__ #define __REST_HTTP__SECURE_SERVER_CONNECTION_H__
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "common/Defines.h" #include "common/Defines.h"
#include "common/network/rest/http/HTTPLexer.h" #include "common/network/rest/http/HTTPLexer.h"
@ -282,6 +282,6 @@ namespace network
} // namespace rest } // namespace rest
} // namespace network } // namespace network
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#endif // __REST_HTTP__SECURE_SERVER_CONNECTION_H__ #endif // __REST_HTTP__SECURE_SERVER_CONNECTION_H__

@ -10,7 +10,7 @@
#include "common/Defines.h" #include "common/Defines.h"
#include "common/network/tcp/SecureTcpClient.h" #include "common/network/tcp/SecureTcpClient.h"
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
using namespace network::tcp; using namespace network::tcp;
@ -20,4 +20,4 @@ using namespace network::tcp;
std::string SecureTcpClient::m_sslHostname = std::string(); std::string SecureTcpClient::m_sslHostname = std::string();
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL

@ -16,7 +16,7 @@
#if !defined(__SECURE_TCP_CLIENT_H__) #if !defined(__SECURE_TCP_CLIENT_H__)
#define __SECURE_TCP_CLIENT_H__ #define __SECURE_TCP_CLIENT_H__
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "Defines.h" #include "Defines.h"
#include "common/Log.h" #include "common/Log.h"
@ -296,6 +296,6 @@ namespace network
} // namespace tcp } // namespace tcp
} // namespace network } // namespace network
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#endif // __SECURE_TCP_CLIENT_H__ #endif // __SECURE_TCP_CLIENT_H__

@ -17,7 +17,7 @@
#if !defined(__SECURE_TCP_SERVER_H__) #if !defined(__SECURE_TCP_SERVER_H__)
#define __SECURE_TCP_SERVER_H__ #define __SECURE_TCP_SERVER_H__
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "Defines.h" #include "Defines.h"
#include "common/network/tcp/Socket.h" #include "common/network/tcp/Socket.h"
@ -153,6 +153,6 @@ namespace network
} // namespace tcp } // namespace tcp
} // namespace network } // namespace network
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#endif // __SECURE_TCP_SERVER_H__ #endif // __SECURE_TCP_SERVER_H__

@ -12,9 +12,9 @@
#include "common/Timer.h" #include "common/Timer.h"
#include "common/Utils.h" #include "common/Utils.h"
#include "common/zlib/zlib.h" #include "common/zlib/zlib.h"
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include "xml/rapidxml.h" #include "xml/rapidxml.h"
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
#include "CryptoContainer.h" #include "CryptoContainer.h"
#include <cstdio> #include <cstdio>
@ -23,10 +23,10 @@
#include <string> #include <string>
#include <vector> #include <vector>
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
#include <openssl/bio.h> #include <openssl/bio.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
using namespace crypto; using namespace crypto;
@ -40,7 +40,7 @@ using namespace crypto;
// Global Functions // Global Functions
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
/** /**
* @brief Calculates the length of a decoded base64 string. * @brief Calculates the length of a decoded base64 string.
* @param b64input String containing the base64 encoded data. * @param b64input String containing the base64 encoded data.
@ -87,7 +87,7 @@ int base64Decode(char* b64message, uint8_t** buffer)
return decodeLen; return decodeLen;
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
/** /**
* @brief * @brief
@ -145,11 +145,11 @@ CryptoContainer::CryptoContainer(const std::string& filename, const std::string&
m_file(filename), m_file(filename),
m_password(password), m_password(password),
m_reloadTime(reloadTime), m_reloadTime(reloadTime),
#if !defined(ENABLE_TCP_SSL) #if !defined(ENABLE_SSL)
m_enabled(false), m_enabled(false),
#else #else
m_enabled(enabled), m_enabled(enabled),
#endif // !ENABLE_TCP_SSL #endif // !ENABLE_SSL
m_stop(false), m_stop(false),
m_keys() m_keys()
{ {
@ -289,7 +289,7 @@ KeyItem CryptoContainer::find(uint32_t kId)
bool CryptoContainer::load() bool CryptoContainer::load()
{ {
#if !defined(ENABLE_TCP_SSL) #if !defined(ENABLE_SSL)
return false; return false;
#else #else
if (!m_enabled) { if (!m_enabled) {
@ -571,5 +571,5 @@ bool CryptoContainer::load()
LogInfoEx(LOG_HOST, "Loaded %lu entries into crypto lookup table", size); LogInfoEx(LOG_HOST, "Loaded %lu entries into crypto lookup table", size);
return true; return true;
#endif // !ENABLE_TCP_SSL #endif // !ENABLE_SSL
} }

@ -363,9 +363,9 @@ bool HostFNE::readParams()
yaml::Node cryptoContainer = masterConf["crypto_container"]; yaml::Node cryptoContainer = masterConf["crypto_container"];
bool cryptoContainerEnabled = cryptoContainer["enable"].as<bool>(false); bool cryptoContainerEnabled = cryptoContainer["enable"].as<bool>(false);
#if !defined(ENABLE_TCP_SSL) #if !defined(ENABLE_SSL)
cryptoContainerEnabled = false; cryptoContainerEnabled = false;
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
std::string cryptoContainerEKC = cryptoContainer["file"].as<std::string>(); std::string cryptoContainerEKC = cryptoContainer["file"].as<std::string>();
std::string cryptoContainerPassword = cryptoContainer["password"].as<std::string>(); std::string cryptoContainerPassword = cryptoContainer["password"].as<std::string>();
uint32_t cryptoContainerReload = cryptoContainer["time"].as<uint32_t>(30U); uint32_t cryptoContainerReload = cryptoContainer["time"].as<uint32_t>(30U);

@ -492,10 +492,10 @@ RESTAPI::RESTAPI(const std::string& address, uint16_t port, const std::string& p
const std::string& keyFile, const std::string& certFile, bool enableSSL, HostFNE* host, bool debug) : const std::string& keyFile, const std::string& certFile, bool enableSSL, HostFNE* host, bool debug) :
m_dispatcher(debug), m_dispatcher(debug),
m_restServer(address, port, debug), m_restServer(address, port, debug),
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
m_restSecureServer(address, port, debug), m_restSecureServer(address, port, debug),
m_enableSSL(enableSSL), m_enableSSL(enableSSL),
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_random(), m_random(),
m_password(password), m_password(password),
m_passwordHash(nullptr), m_passwordHash(nullptr),
@ -529,14 +529,14 @@ RESTAPI::RESTAPI(const std::string& address, uint16_t port, const std::string& p
Utils::dump("REST Password Hash", m_passwordHash, 32U); Utils::dump("REST Password Hash", m_passwordHash, 32U);
} }
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
if (!m_restSecureServer.setCertAndKey(keyFile, certFile)) { if (!m_restSecureServer.setCertAndKey(keyFile, certFile)) {
m_enableSSL = false; m_enableSSL = false;
::LogError(LOG_REST, "failed to initialize SSL for HTTPS, disabling SSL"); ::LogError(LOG_REST, "failed to initialize SSL for HTTPS, disabling SSL");
} }
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
std::random_device rd; std::random_device rd;
std::mt19937 mt(rd()); std::mt19937 mt(rd());
@ -568,17 +568,17 @@ void RESTAPI::setNetwork(network::FNENetwork* network)
bool RESTAPI::open() bool RESTAPI::open()
{ {
initializeEndpoints(); initializeEndpoints();
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
m_restSecureServer.open(); m_restSecureServer.open();
m_restSecureServer.setHandler(m_dispatcher); m_restSecureServer.setHandler(m_dispatcher);
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_restServer.open(); m_restServer.open();
m_restServer.setHandler(m_dispatcher); m_restServer.setHandler(m_dispatcher);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
return run(); return run();
} }
@ -587,15 +587,15 @@ bool RESTAPI::open()
void RESTAPI::close() void RESTAPI::close()
{ {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
m_restSecureServer.stop(); m_restSecureServer.stop();
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_restServer.stop(); m_restServer.stop();
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
wait(); wait();
} }
@ -607,15 +607,15 @@ void RESTAPI::close()
void RESTAPI::entry() void RESTAPI::entry()
{ {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
m_restSecureServer.run(); m_restSecureServer.run();
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_restServer.run(); m_restServer.run();
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
} }
/* Helper to initialize REST API endpoints. */ /* Helper to initialize REST API endpoints. */

@ -93,10 +93,10 @@ private:
typedef network::rest::http::HTTPPayload HTTPPayload; typedef network::rest::http::HTTPPayload HTTPPayload;
RESTDispatcherType m_dispatcher; RESTDispatcherType m_dispatcher;
network::rest::http::HTTPServer<RESTDispatcherType> m_restServer; network::rest::http::HTTPServer<RESTDispatcherType> m_restServer;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
network::rest::http::SecureHTTPServer<RESTDispatcherType> m_restSecureServer; network::rest::http::SecureHTTPServer<RESTDispatcherType> m_restSecureServer;
bool m_enableSSL; bool m_enableSSL;
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
std::mt19937 m_random; std::mt19937 m_random;

@ -140,10 +140,10 @@ RESTAPI::RESTAPI(const std::string& address, uint16_t port, const std::string& p
const std::string& keyFile, const std::string& certFile, bool enableSSL, Host* host, bool debug) : const std::string& keyFile, const std::string& certFile, bool enableSSL, Host* host, bool debug) :
m_dispatcher(debug), m_dispatcher(debug),
m_restServer(address, port, debug), m_restServer(address, port, debug),
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
m_restSecureServer(address, port, debug), m_restSecureServer(address, port, debug),
m_enableSSL(enableSSL), m_enableSSL(enableSSL),
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_random(), m_random(),
m_p25MFId(P25DEF::MFG_STANDARD), m_p25MFId(P25DEF::MFG_STANDARD),
m_password(password), m_password(password),
@ -179,14 +179,14 @@ RESTAPI::RESTAPI(const std::string& address, uint16_t port, const std::string& p
Utils::dump("REST Password Hash", m_passwordHash, 32U); Utils::dump("REST Password Hash", m_passwordHash, 32U);
} }
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
if (!m_restSecureServer.setCertAndKey(keyFile, certFile)) { if (!m_restSecureServer.setCertAndKey(keyFile, certFile)) {
m_enableSSL = false; m_enableSSL = false;
::LogError(LOG_REST, "failed to initialize SSL for HTTPS, disabling SSL"); ::LogError(LOG_REST, "failed to initialize SSL for HTTPS, disabling SSL");
} }
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
std::random_device rd; std::random_device rd;
std::mt19937 mt(rd()); std::mt19937 mt(rd());
@ -219,17 +219,17 @@ void RESTAPI::setProtocols(dmr::Control* dmr, p25::Control* p25, nxdn::Control*
bool RESTAPI::open() bool RESTAPI::open()
{ {
initializeEndpoints(); initializeEndpoints();
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
m_restSecureServer.open(); m_restSecureServer.open();
m_restSecureServer.setHandler(m_dispatcher); m_restSecureServer.setHandler(m_dispatcher);
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_restServer.open(); m_restServer.open();
m_restServer.setHandler(m_dispatcher); m_restServer.setHandler(m_dispatcher);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
return run(); return run();
} }
@ -238,15 +238,15 @@ bool RESTAPI::open()
void RESTAPI::close() void RESTAPI::close()
{ {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
m_restSecureServer.stop(); m_restSecureServer.stop();
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_restServer.stop(); m_restServer.stop();
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
wait(); wait();
} }
@ -258,15 +258,15 @@ void RESTAPI::close()
void RESTAPI::entry() void RESTAPI::entry()
{ {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
m_restSecureServer.run(); m_restSecureServer.run();
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
m_restServer.run(); m_restServer.run();
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
} }
/* Helper to initialize REST API endpoints. */ /* Helper to initialize REST API endpoints. */

@ -96,10 +96,10 @@ private:
typedef network::rest::http::HTTPPayload HTTPPayload; typedef network::rest::http::HTTPPayload HTTPPayload;
RESTDispatcherType m_dispatcher; RESTDispatcherType m_dispatcher;
network::rest::http::HTTPServer<RESTDispatcherType> m_restServer; network::rest::http::HTTPServer<RESTDispatcherType> m_restServer;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
network::rest::http::SecureHTTPServer<RESTDispatcherType> m_restSecureServer; network::rest::http::SecureHTTPServer<RESTDispatcherType> m_restSecureServer;
bool m_enableSSL; bool m_enableSSL;
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
std::mt19937 m_random; std::mt19937 m_random;

@ -152,13 +152,13 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
typedef network::rest::BasicRequestDispatcher<network::rest::http::HTTPPayload, network::rest::http::HTTPPayload> RESTDispatcherType; typedef network::rest::BasicRequestDispatcher<network::rest::http::HTTPPayload, network::rest::http::HTTPPayload> RESTDispatcherType;
RESTDispatcherType m_dispatcher(RESTClient::responseHandler); RESTDispatcherType m_dispatcher(RESTClient::responseHandler);
HTTPClient<RESTDispatcherType>* client = nullptr; HTTPClient<RESTDispatcherType>* client = nullptr;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
SecureHTTPClient<RESTDispatcherType>* sslClient = nullptr; SecureHTTPClient<RESTDispatcherType>* sslClient = nullptr;
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
try { try {
// setup HTTP client for authentication payload // setup HTTP client for authentication payload
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient = new SecureHTTPClient<RESTDispatcherType>(address, port); sslClient = new SecureHTTPClient<RESTDispatcherType>(address, port);
if (!sslClient->open()) { if (!sslClient->open()) {
@ -167,16 +167,16 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
} }
sslClient->setHandler(m_dispatcher); sslClient->setHandler(m_dispatcher);
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client = new HTTPClient<RESTDispatcherType>(address, port); client = new HTTPClient<RESTDispatcherType>(address, port);
if (!client->open()) { if (!client->open()) {
delete client; delete client;
return ERRNO_SOCK_OPEN; return ERRNO_SOCK_OPEN;
} }
client->setHandler(m_dispatcher); client->setHandler(m_dispatcher);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
// generate password SHA hash // generate password SHA hash
size_t size = password.size(); size_t size = password.size();
@ -207,29 +207,29 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
HTTPPayload httpPayload = HTTPPayload::requestPayload(HTTP_PUT, "/auth"); HTTPPayload httpPayload = HTTPPayload::requestPayload(HTTP_PUT, "/auth");
httpPayload.payload(request); httpPayload.payload(request);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->request(httpPayload); sslClient->request(httpPayload);
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->request(httpPayload); client->request(httpPayload);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
// wait for response and parse // wait for response and parse
if (wait()) { if (wait()) {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->close(); sslClient->close();
delete sslClient; delete sslClient;
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->close(); client->close();
delete client; delete client;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
return ERRNO_API_CALL_TIMEOUT; return ERRNO_API_CALL_TIMEOUT;
} }
@ -244,34 +244,34 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
token = rsp["token"].get<std::string>(); token = rsp["token"].get<std::string>();
} }
else { else {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->close(); sslClient->close();
delete sslClient; delete sslClient;
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->close(); client->close();
delete client; delete client;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
return ERRNO_BAD_AUTH_RESPONSE; return ERRNO_BAD_AUTH_RESPONSE;
} }
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->close(); sslClient->close();
delete sslClient; delete sslClient;
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->close(); client->close();
delete client; delete client;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
// reset the HTTP client and setup for actual payload request // reset the HTTP client and setup for actual payload request
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient = new SecureHTTPClient<RESTDispatcherType>(address, port); sslClient = new SecureHTTPClient<RESTDispatcherType>(address, port);
if (!sslClient->open()) { if (!sslClient->open()) {
@ -280,44 +280,44 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
} }
sslClient->setHandler(m_dispatcher); sslClient->setHandler(m_dispatcher);
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client = new HTTPClient<RESTDispatcherType>(address, port); client = new HTTPClient<RESTDispatcherType>(address, port);
if (!client->open()) { if (!client->open()) {
delete client; delete client;
return ERRNO_SOCK_OPEN; return ERRNO_SOCK_OPEN;
} }
client->setHandler(m_dispatcher); client->setHandler(m_dispatcher);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
// send actual API request // send actual API request
httpPayload = HTTPPayload::requestPayload(method, endpoint); httpPayload = HTTPPayload::requestPayload(method, endpoint);
httpPayload.headers.add("X-DVM-Auth-Token", token); httpPayload.headers.add("X-DVM-Auth-Token", token);
httpPayload.payload(payload); httpPayload.payload(payload);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->request(httpPayload); sslClient->request(httpPayload);
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->request(httpPayload); client->request(httpPayload);
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
// wait for response and parse // wait for response and parse
if (wait()) { if (wait()) {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->close(); sslClient->close();
delete sslClient; delete sslClient;
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->close(); client->close();
delete client; delete client;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
return ERRNO_API_CALL_TIMEOUT; return ERRNO_API_CALL_TIMEOUT;
} }
@ -339,32 +339,32 @@ int RESTClient::send(const std::string& address, uint32_t port, const std::strin
} }
} }
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
sslClient->close(); sslClient->close();
delete sslClient; delete sslClient;
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
client->close(); client->close();
delete client; delete client;
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
} }
catch (std::exception&) { catch (std::exception&) {
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
if (m_enableSSL) { if (m_enableSSL) {
if (sslClient != nullptr) { if (sslClient != nullptr) {
delete sslClient; delete sslClient;
} }
} else { } else {
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
if (client != nullptr) { if (client != nullptr) {
delete client; delete client;
} }
#if defined(ENABLE_TCP_SSL) #if defined(ENABLE_SSL)
} }
#endif // ENABLE_TCP_SSL #endif // ENABLE_SSL
return ERRNO_INTERNAL_ERROR; return ERRNO_INTERNAL_ERROR;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.