1
0
mirror of https://github.com/eclipse/paho.mqtt.cpp.git synced 2025-05-09 11:21:24 +08:00

Added SSL callback to sample app

This commit is contained in:
fpagliughi 2020-12-06 16:32:43 -05:00
parent f57c54f8d4
commit 2237a03fee
3 changed files with 7 additions and 5 deletions

View File

@ -52,13 +52,13 @@ public:
using unique_ptr_t = std::unique_ptr<ssl_options>;
/** Handler type for error message callbacks */
using error_handler = std::function<void(const ssl_options&, const string& errMsg)>;
using error_handler = std::function<void(const string& errMsg)>;
/**
* 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<unsigned(const ssl_options&, const string& hint,
using psk_handler = std::function<unsigned(const string& hint,
char *identity, size_t max_identity_len,
unsigned char *psk, size_t max_psk_len)>;

View File

@ -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);

View File

@ -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));
}
}