From e3ad153ce46c38b642d289a92172f2968d6302c6 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Thu, 17 Dec 2020 22:09:05 +0100 Subject: [PATCH] Will stuff in connect --- client.cpp | 8 ++++++++ client.h | 6 ++++++ mqttpacket.cpp | 7 +++++++ 3 files changed, 21 insertions(+), 0 deletions(-) diff --git a/client.cpp b/client.cpp index 00611c2..0b2231d 100644 --- a/client.cpp +++ b/client.cpp @@ -241,6 +241,14 @@ void Client::setClientProperties(const std::string &clientId, const std::string this->keepalive = keepalive; } +void Client::setWill(const std::string &topic, const std::string &payload, bool retain, char qos) +{ + this->will_topic = topic; + this->will_payload = payload; + this->will_retain = retain; + this->will_qos = qos; +} + diff --git a/client.h b/client.h index 01d3996..379caf4 100644 --- a/client.h +++ b/client.h @@ -41,6 +41,11 @@ class Client std::string username; uint16_t keepalive = 0; + std::string will_topic; + std::string will_payload; + bool will_retain = false; + char will_qos = 0; + ThreadData_p threadData; std::mutex writeBufMutex; @@ -108,6 +113,7 @@ public: bool readFdIntoBuffer(); bool bufferToMqttPackets(std::vector &packetQueueIn, Client_p &sender); void setClientProperties(const std::string &clientId, const std::string username, bool connectPacketSeen, uint16_t keepalive); + void setWill(const std::string &topic, const std::string &payload, bool retain, char qos); void setAuthenticated(bool value) { authenticated = value;} bool getAuthenticated() { return authenticated; } bool hasConnectPacketSeen() { return connectPacketSeen; } diff --git a/mqttpacket.cpp b/mqttpacket.cpp index ff3fdc8..df0ffd9 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -133,10 +133,16 @@ void MqttPacket::handleConnect() std::string username; std::string password; + std::string will_topic; + std::string will_payload; if (will_flag) { + uint16_t will_topic_length = readTwoBytesToUInt16(); + will_topic = std::string(readBytes(will_topic_length), will_topic_length); + uint16_t will_payload_length = readTwoBytesToUInt16(); + will_payload = std::string(readBytes(will_payload_length), will_payload_length); } if (user_name_flag) { @@ -152,6 +158,7 @@ void MqttPacket::handleConnect() // TODO: validate UTF8 encoded username/password. sender->setClientProperties(client_id, username, true, keep_alive); + sender->setWill(will_topic, will_payload, will_retain, will_qos); sender->setAuthenticated(true); std::cout << "Connect: " << sender->repr() << std::endl; -- libgit2 0.21.4