Skip to content

Commit

Permalink
Fix bear ssl fwd def
Browse files Browse the repository at this point in the history
  • Loading branch information
cziter15 committed Feb 15, 2025
1 parent 1b1060b commit ae5e588
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/ksf/comp/ksMqttConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ using namespace std::placeholders;

namespace ksf::comps
{
ksMqttConnector::~ksMqttConnector() = default;

ksMqttConnector::ksMqttConnector(bool sendConnectionStatus, bool usePersistentSession)
: reconnectTimer(KSF_MQTT_RECONNECT_DELAY_MS)
{
bitflags.sendConnectionStatus = sendConnectionStatus;
bitflags.usePersistentSession = usePersistentSession;
}

ksMqttConnector::~ksMqttConnector() = default;

bool ksMqttConnector::init(ksApplication* app)
{
ksMqttConfigProvider cfgProvider;
Expand All @@ -67,10 +67,9 @@ namespace ksf::comps

void ksMqttConnector::setupConnection(const std::string broker, const std::string& port, std::string login, std::string password, std::string prefix, const std::string& fingerprint)
{
/* Set up secure connection if a fingerprint is provided. */
if (!fingerprint.empty())
{
auto secureClient = std::make_unique<ksMqttConnectorNetClientSecure_t>();
auto secureClient{std::make_unique<ksMqttConnectorNetClientSecure_t>()};
certFingerprint = std::make_unique<misc::ksCertFingerprintHolder>();
if (certFingerprint->setup(secureClient.get(), fingerprint))
netClientUq = std::move(secureClient);
Expand All @@ -80,7 +79,7 @@ namespace ksf::comps
/* Whoops, it looks like fingerprint validation failed. */
if (!netClientUq)
return;

/* Set socket timeouts. */
netClientUq->setTimeout(KSF_MQTT_TIMEOUT_MS);

Expand All @@ -92,7 +91,7 @@ namespace ksf::comps
ksf::from_chars(port, portNumber);

/* Create MQTT client. */
mqttClientUq = std::make_unique<PubSubClient>(*netClientUq);
mqttClientUq = std::make_unique<PubSubClient>(*netClientUq.get());
}

void ksMqttConnector::mqttConnectedInternal()
Expand All @@ -104,8 +103,8 @@ namespace ksf::comps

void ksMqttConnector::mqttMessageInternal(const char* topic, const uint8_t* payload, uint32_t length)
{
auto handlesDeviceMessage{onDeviceMessage->isBound()};
auto handlesAnyMessage{onAnyMessage->isBound()};
bool handlesDeviceMessage{onDeviceMessage->isBound()};
bool handlesAnyMessage{onAnyMessage->isBound()};

if (!handlesDeviceMessage && !handlesAnyMessage)
return;
Expand Down Expand Up @@ -134,7 +133,8 @@ namespace ksf::comps

void ksMqttConnector::subscribe(const std::string& topic, bool skipDevicePrefix, ksMqttConnector::QosLevel qos)
{
mqttClientUq->subscribe(skipDevicePrefix ? topic.c_str() : std::string(prefix + topic).c_str(), static_cast<uint8_t>(qos));
uint8_t qosLevel{static_cast<uint8_t>(qos)};
mqttClientUq->subscribe(skipDevicePrefix ? topic.c_str() : std::string(prefix + topic).c_str(), qosLevel);
}

void ksMqttConnector::unsubscribe(const std::string& topic, bool skipDevicePrefix)
Expand Down
6 changes: 4 additions & 2 deletions src/ksf/comp/ksMqttConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
#if (defined(ESP32) && ESP_ARDUINO_VERSION_MAJOR >= 3)
#define ksMqttConnectorNetClient_t NetworkClient
#define ksMqttConnectorNetClientSecure_t NetworkClientSecure
#else
#elif defined (ESP8266)
#define ksMqttConnectorNetClient_t WiFiClient
#define ksMqttConnectorNetClientSecure_t WiFiClientSecure
#define ksMqttConnectorNetClientSecure_t BearSSL::WiFiClientSecure
#else
#error Platform not implemented.
#endif

class PubSubClient;
Expand Down
15 changes: 10 additions & 5 deletions src/ksf/misc/ksCertUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
#include <string>
#include <stdint.h>

#if (defined(ESP32) && ESP_ARDUINO_VERSION_MAJOR >= 3)
#define ksCertUtilsNetCLientSecure_t NetworkClientSecure
#else
#if defined(ESP32)
#define ksCertUtilsNetCLientSecure_t WiFiClientSecure
class ksCertUtilsNetCLientSecure_t
#elif defined(ESP8266)
namespace BearSSL
{
class WiFiClientSecure;
}
#define ksCertUtilsNetCLientSecure_t BearSSL::WiFiClientSecure
#else
#error Platform not implemented.
#endif

class ksCertUtilsNetCLientSecure_t;

namespace ksf::misc
{
/*!
Expand Down

0 comments on commit ae5e588

Please sign in to comment.