mirror of
https://github.com/eclipse/paho.mqtt.cpp.git
synced 2025-05-09 19:31:22 +08:00
Added SSL callback to sample app
This commit is contained in:
parent
f57c54f8d4
commit
2237a03fee
@ -52,13 +52,13 @@ public:
|
|||||||
using unique_ptr_t = std::unique_ptr<ssl_options>;
|
using unique_ptr_t = std::unique_ptr<ssl_options>;
|
||||||
|
|
||||||
/** Handler type for error message callbacks */
|
/** 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.
|
* Handler type for TLS-PSK option callback.
|
||||||
* On success, the callback should return the length of the PSK (in
|
* On success, the callback should return the length of the PSK (in
|
||||||
* bytes). On failure, it should throw or return zero.
|
* 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,
|
char *identity, size_t max_identity_len,
|
||||||
unsigned char *psk, size_t max_psk_len)>;
|
unsigned char *psk, size_t max_psk_len)>;
|
||||||
|
|
||||||
|
@ -119,6 +119,9 @@ int main(int argc, char* argv[])
|
|||||||
auto sslopts = mqtt::ssl_options_builder()
|
auto sslopts = mqtt::ssl_options_builder()
|
||||||
.trust_store(TRUST_STORE)
|
.trust_store(TRUST_STORE)
|
||||||
.key_store(KEY_STORE)
|
.key_store(KEY_STORE)
|
||||||
|
.error_handler([](const std::string& msg) {
|
||||||
|
std::cerr << "SSL Error: " << msg << std::endl;
|
||||||
|
})
|
||||||
.finalize();
|
.finalize();
|
||||||
|
|
||||||
auto willmsg = mqtt::message(LWT_TOPIC, LWT_PAYLOAD, QOS, true);
|
auto willmsg = mqtt::message(LWT_TOPIC, LWT_PAYLOAD, QOS, true);
|
||||||
|
@ -96,7 +96,7 @@ int ssl_options::on_error(const char *str, size_t len, void *context)
|
|||||||
auto& errHandler = opts->errHandler_;
|
auto& errHandler = opts->errHandler_;
|
||||||
|
|
||||||
if (errHandler)
|
if (errHandler)
|
||||||
errHandler(*opts, errMsg);
|
errHandler(errMsg);
|
||||||
|
|
||||||
return MQTTASYNC_SUCCESS;
|
return MQTTASYNC_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -119,8 +119,7 @@ unsigned ssl_options::on_psk(const char *hint, char *identity, unsigned max_iden
|
|||||||
auto& pskHandler = opts->pskHandler_;
|
auto& pskHandler = opts->pskHandler_;
|
||||||
|
|
||||||
if (pskHandler) {
|
if (pskHandler) {
|
||||||
ret = pskHandler(*opts, hintStr,
|
ret = pskHandler(hintStr, identity, size_t(max_identity_len),
|
||||||
identity, size_t(max_identity_len),
|
|
||||||
psk, size_t(max_psk_len));
|
psk, size_t(max_psk_len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user