From 2237a03feee44afad413115b8f8855ebf72f7e2c Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Sun, 6 Dec 2020 16:32:43 -0500 Subject: [PATCH] Added SSL callback to sample app --- src/mqtt/ssl_options.h | 4 ++-- src/samples/ssl_publish.cpp | 3 +++ src/ssl_options.cpp | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mqtt/ssl_options.h b/src/mqtt/ssl_options.h index 4ccb09b..00aac76 100644 --- a/src/mqtt/ssl_options.h +++ b/src/mqtt/ssl_options.h @@ -52,13 +52,13 @@ public: using unique_ptr_t = std::unique_ptr; /** Handler type for error message callbacks */ - using error_handler = std::function; + using error_handler = std::function; /** * Handler type for TLS-PSK option callback. * On success, the callback should return the length of the PSK (in * bytes). On failure, it should throw or return zero. */ - using psk_handler = std::function; diff --git a/src/samples/ssl_publish.cpp b/src/samples/ssl_publish.cpp index 388524d..95cfc73 100644 --- a/src/samples/ssl_publish.cpp +++ b/src/samples/ssl_publish.cpp @@ -119,6 +119,9 @@ int main(int argc, char* argv[]) auto sslopts = mqtt::ssl_options_builder() .trust_store(TRUST_STORE) .key_store(KEY_STORE) + .error_handler([](const std::string& msg) { + std::cerr << "SSL Error: " << msg << std::endl; + }) .finalize(); auto willmsg = mqtt::message(LWT_TOPIC, LWT_PAYLOAD, QOS, true); diff --git a/src/ssl_options.cpp b/src/ssl_options.cpp index 194b478..42f40bb 100644 --- a/src/ssl_options.cpp +++ b/src/ssl_options.cpp @@ -96,7 +96,7 @@ int ssl_options::on_error(const char *str, size_t len, void *context) auto& errHandler = opts->errHandler_; if (errHandler) - errHandler(*opts, errMsg); + errHandler(errMsg); return MQTTASYNC_SUCCESS; } @@ -119,8 +119,7 @@ unsigned ssl_options::on_psk(const char *hint, char *identity, unsigned max_iden auto& pskHandler = opts->pskHandler_; if (pskHandler) { - ret = pskHandler(*opts, hintStr, - identity, size_t(max_identity_len), + ret = pskHandler(hintStr, identity, size_t(max_identity_len), psk, size_t(max_psk_len)); } }