Commit e3ad153ce46c38b642d289a92172f2968d6302c6

Authored by Wiebe Cazemier
1 parent 21bf9bf5

Will stuff in connect

client.cpp
... ... @@ -241,6 +241,14 @@ void Client::setClientProperties(const std::string &clientId, const std::string
241 241 this->keepalive = keepalive;
242 242 }
243 243  
  244 +void Client::setWill(const std::string &topic, const std::string &payload, bool retain, char qos)
  245 +{
  246 + this->will_topic = topic;
  247 + this->will_payload = payload;
  248 + this->will_retain = retain;
  249 + this->will_qos = qos;
  250 +}
  251 +
244 252  
245 253  
246 254  
... ...
client.h
... ... @@ -41,6 +41,11 @@ class Client
41 41 std::string username;
42 42 uint16_t keepalive = 0;
43 43  
  44 + std::string will_topic;
  45 + std::string will_payload;
  46 + bool will_retain = false;
  47 + char will_qos = 0;
  48 +
44 49 ThreadData_p threadData;
45 50 std::mutex writeBufMutex;
46 51  
... ... @@ -108,6 +113,7 @@ public:
108 113 bool readFdIntoBuffer();
109 114 bool bufferToMqttPackets(std::vector<MqttPacket> &packetQueueIn, Client_p &sender);
110 115 void setClientProperties(const std::string &clientId, const std::string username, bool connectPacketSeen, uint16_t keepalive);
  116 + void setWill(const std::string &topic, const std::string &payload, bool retain, char qos);
111 117 void setAuthenticated(bool value) { authenticated = value;}
112 118 bool getAuthenticated() { return authenticated; }
113 119 bool hasConnectPacketSeen() { return connectPacketSeen; }
... ...
mqttpacket.cpp
... ... @@ -133,10 +133,16 @@ void MqttPacket::handleConnect()
133 133  
134 134 std::string username;
135 135 std::string password;
  136 + std::string will_topic;
  137 + std::string will_payload;
136 138  
137 139 if (will_flag)
138 140 {
  141 + uint16_t will_topic_length = readTwoBytesToUInt16();
  142 + will_topic = std::string(readBytes(will_topic_length), will_topic_length);
139 143  
  144 + uint16_t will_payload_length = readTwoBytesToUInt16();
  145 + will_payload = std::string(readBytes(will_payload_length), will_payload_length);
140 146 }
141 147 if (user_name_flag)
142 148 {
... ... @@ -152,6 +158,7 @@ void MqttPacket::handleConnect()
152 158 // TODO: validate UTF8 encoded username/password.
153 159  
154 160 sender->setClientProperties(client_id, username, true, keep_alive);
  161 + sender->setWill(will_topic, will_payload, will_retain, will_qos);
155 162 sender->setAuthenticated(true);
156 163  
157 164 std::cout << "Connect: " << sender->repr() << std::endl;
... ...