SNode.C
Loading...
Searching...
No Matches
iot::mqtt::server::Mqtt Class Reference

#include <Mqtt.h>

Inheritance diagram for iot::mqtt::server::Mqtt:
Collaboration diagram for iot::mqtt::server::Mqtt:

Public Member Functions

 Mqtt (const std::string &connectionName, const std::shared_ptr< broker::Broker > &broker)
 ~Mqtt () override
void sendConnack (uint8_t returnCode, uint8_t flags) const
void sendSuback (uint16_t packetIdentifier, const std::list< uint8_t > &returnCodes) const
void sendUnsuback (uint16_t packetIdentifier) const
void sendPingresp () const
std::list< std::string > getSubscriptions () const
std::string getProtocol () const
uint8_t getLevel () const
uint8_t getConnectFlags () const
uint16_t getKeepAlive () const
std::string getClientId () const
std::string getWillTopic () const
std::string getWillMessage () const
std::string getUsername () const
std::string getPassword () const
bool getUsernameFlag () const
bool getPasswordFlag () const
bool getWillRetain () const
uint8_t getWillQoS () const
bool getWillFlag () const
bool getCleanSession () const
bool getReflect () const
Public Member Functions inherited from iot::mqtt::Mqtt
 Mqtt (const std::string &connectionName)
 Mqtt (const std::string &connectionName, const std::string &clientId)
 Mqtt (Mqtt &&)=delete
 Mqtt (const Mqtt &)=delete
Mqttoperator= (Mqtt &&)=delete
Mqttoperator= (const Mqtt &)=delete
virtual void onConnected ()
virtual void onDisconnected ()
const std::string & getConnectionName () const
const MqttContextgetMqttContext () const
void sendPublish (const std::string &topic, const std::string &message, uint8_t qoS, bool retain) const
void sendPuback (uint16_t packetIdentifier) const
void sendPubrec (uint16_t packetIdentifier) const
void sendPubrel (uint16_t packetIdentifier) const
void sendPubcomp (uint16_t packetIdentifier) const

Protected Member Functions

bool onSignal (int sig) override
Protected Member Functions inherited from iot::mqtt::Mqtt
void initSession (Session *session, utils::Timeval keepAlive)
virtual void onPublish (const iot::mqtt::packets::Publish &publish)
virtual void onPuback (const iot::mqtt::packets::Puback &puback)
virtual void onPubrec (const iot::mqtt::packets::Pubrec &pubrec)
virtual void onPubrel (const iot::mqtt::packets::Pubrel &pubrel)
virtual void onPubcomp (const iot::mqtt::packets::Pubcomp &pubcomp)
bool _onPublish (const iot::mqtt::packets::Publish &publish)
void _onPuback (const iot::mqtt::packets::Puback &puback)
void _onPubrec (const iot::mqtt::packets::Pubrec &pubrec)
void _onPubrel (const iot::mqtt::packets::Pubrel &pubrel)
void _onPubcomp (const iot::mqtt::packets::Pubcomp &pubcomp)
uint16_t getPacketIdentifier () const
void send (const iot::mqtt::ControlPacket &controlPacket) const
void printVP (const iot::mqtt::ControlPacket &packet) const
void printFixedHeader (const iot::mqtt::FixedHeader &fixedHeader) const

Protected Attributes

std::string protocol
uint8_t level = 0
uint8_t connectFlags = 0
uint16_t keepAlive = 0
std::string willTopic
std::string willMessage
std::string username
std::string password
bool usernameFlag = false
bool passwordFlag = false
bool willRetain = false
uint8_t willQoS = 0
bool willFlag = false
bool cleanSession = false
bool reflect = true
std::shared_ptr< iot::mqtt::server::broker::Brokerbroker
Protected Attributes inherited from iot::mqtt::Mqtt
std::string connectionName
std::string clientId
MqttContextmqttContext = nullptr

Private Types

using Super = iot::mqtt::Mqtt

Private Member Functions

ControlPacketDeserializercreateControlPacketDeserializer (iot::mqtt::FixedHeader &fixedHeader) const final
void deliverPacket (iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer) override
bool initSession (const utils::Timeval &keepAlive)
void releaseSession ()
virtual void onConnect (const iot::mqtt::packets::Connect &connect)
virtual void onSubscribe (const iot::mqtt::packets::Subscribe &subscribe)
virtual void onUnsubscribe (const iot::mqtt::packets::Unsubscribe &unsubscribe)
virtual void onPingreq (const iot::mqtt::packets::Pingreq &pingreq)
virtual void onDisconnect (const iot::mqtt::packets::Disconnect &disconnect)
void _onConnect (const iot::mqtt::server::packets::Connect &connect)
void _onPublish (const iot::mqtt::server::packets::Publish &publish)
void _onSubscribe (const iot::mqtt::server::packets::Subscribe &subscribe)
void _onUnsubscribe (const iot::mqtt::server::packets::Unsubscribe &unsubscribe)
void _onPingreq (const iot::mqtt::server::packets::Pingreq &pingreq)
void _onDisconnect (const iot::mqtt::server::packets::Disconnect &disconnect)
void deliverPublish (const iot::mqtt::packets::Publish &publish) final
void initSession (Session *session, utils::Timeval keepAlive)

Friends

class iot::mqtt::server::packets::Connect
class iot::mqtt::server::packets::Subscribe
class iot::mqtt::server::packets::Unsubscribe
class iot::mqtt::server::packets::Pingreq
class iot::mqtt::server::packets::Disconnect
class iot::mqtt::server::packets::Publish
class iot::mqtt::server::packets::Pubcomp
class iot::mqtt::server::packets::Pubrec
class iot::mqtt::server::packets::Puback
class iot::mqtt::server::packets::Pubrel

Additional Inherited Members

Static Public Member Functions inherited from iot::mqtt::Mqtt
static std::string toHexString (const std::vector< char > &data)
static std::string toHexString (const std::string &data)

Detailed Description

Definition at line 87 of file Mqtt.h.

Member Typedef Documentation

◆ Super

Definition at line 89 of file Mqtt.h.

Constructor & Destructor Documentation

◆ Mqtt()

iot::mqtt::server::Mqtt::Mqtt ( const std::string & connectionName,
const std::shared_ptr< broker::Broker > & broker )
explicit

Definition at line 73 of file Mqtt.cpp.

75 , broker(broker) {
76 }
std::string connectionName
Definition Mqtt.h:144
std::shared_ptr< iot::mqtt::server::broker::Broker > broker
Definition Mqtt.h:166
iot::mqtt::Mqtt Super
Definition Mqtt.h:89

References iot::mqtt::Mqtt::Mqtt().

Here is the call graph for this function:

◆ ~Mqtt()

iot::mqtt::server::Mqtt::~Mqtt ( )
overridevirtual

Reimplemented from iot::mqtt::Mqtt.

Definition at line 78 of file Mqtt.cpp.

78 {
80
81 if (willFlag) {
83 }
84 }
std::string clientId
Definition Mqtt.h:145
std::string willMessage
Definition Mqtt.h:154
std::string willTopic
Definition Mqtt.h:153

References iot::mqtt::Mqtt::clientId, iot::mqtt::server::broker::Broker::publish(), releaseSession(), willFlag, willMessage, willQoS, willRetain, and willTopic.

Here is the call graph for this function:

Member Function Documentation

◆ _onConnect()

void iot::mqtt::server::Mqtt::_onConnect ( const iot::mqtt::server::packets::Connect & connect)
private

Definition at line 213 of file Mqtt.cpp.

213 {
214 LOG(INFO) << connectionName << " MQTT Broker: Protocol: " << connect.getProtocol();
215 LOG(INFO) << connectionName << " MQTT Broker: Version: " << static_cast<uint16_t>(connect.getLevel());
216 LOG(INFO) << connectionName << " MQTT Broker: ConnectFlags: 0x" << std::hex << std::setfill('0') << std::setw(2)
217 << static_cast<uint16_t>(connect.getConnectFlags()) << std::dec << std::setw(0);
218 LOG(INFO) << connectionName << " MQTT Broker: KeepAlive: " << connect.getKeepAlive();
219 LOG(INFO) << connectionName << " MQTT Broker: ClientID: " << connect.getClientId();
220 LOG(INFO) << connectionName << " MQTT Broker: CleanSession: " << connect.getCleanSession();
221
222 if (connect.getWillFlag()) {
223 LOG(INFO) << connectionName << " MQTT Broker: WillTopic: " << connect.getWillTopic();
224 LOG(INFO) << connectionName << " MQTT Broker: WillMessage: " << connect.getWillMessage();
225 LOG(INFO) << connectionName << " MQTT Broker: WillQoS: " << static_cast<uint16_t>(connect.getWillQoS());
226 LOG(INFO) << connectionName << " MQTT Broker: WillRetain: " << connect.getWillRetain();
227 }
228 if (connect.getUsernameFlag()) {
229 LOG(INFO) << connectionName << " MQTT Broker: Username: " << connect.getUsername();
230 }
231 if (connect.getPasswordFlag()) {
232 LOG(INFO) << connectionName << " MQTT Broker: Password: " << connect.getPassword();
233 }
234
235 if (connect.getProtocol() != "MQTT") {
236 LOG(ERROR) << connectionName << " MQTT Broker: Wrong Protocol: " << connect.getProtocol();
237 mqttContext->close();
238 } else if ((connect.getLevel()) != MQTT_VERSION_3_1_1) {
239 LOG(ERROR) << connectionName << " MQTT Broker: Wrong Protocol Level: " << MQTT_VERSION_3_1_1 << " != " << connect.getLevel();
241
242 mqttContext->close();
243 } else if (connect.isFakedClientId() && !connect.getCleanSession()) {
244 LOG(ERROR) << connectionName << " MQTT Broker: Resume session but no ClientId present";
246
247 mqttContext->close();
248 } else if (!connect.getWillFlag() && (connect.getWillQoS() != 0 || connect.getWillRetain())) {
249 LOG(ERROR) << connectionName << " MQTT Broker: WillFlag not set but WillQoS or WillRetain set";
250
251 mqttContext->close();
252 } else if (connect.getWillQoS() > 2) {
253 LOG(ERROR) << connectionName << " MQTT Broker: WillQoS larger than 2";
254
255 mqttContext->close();
256 } else if (connect.getPasswordFlag() && !connect.getUsernameFlag()) {
257 LOG(ERROR) << connectionName << " MQTT Broker: Password flag set but username flag not";
258
259 mqttContext->close();
260 } else {
261 // V-Header
262 protocol = connect.getProtocol();
263 level = connect.getLevel();
264 reflect = connect.getReflect();
265 connectFlags = connect.getConnectFlags();
266 keepAlive = connect.getKeepAlive();
267
268 // Payload
269 clientId = connect.getClientId();
270 willTopic = connect.getWillTopic();
271 willMessage = connect.getWillMessage();
272 username = connect.getUsername();
273 password = connect.getPassword();
274
275 // Derived from flags
276 usernameFlag = connect.getUsernameFlag();
277 passwordFlag = connect.getPasswordFlag();
278 willRetain = connect.getWillRetain();
279 willQoS = connect.getWillQoS();
280 willFlag = connect.getWillFlag();
281 cleanSession = connect.getCleanSession();
282
283 if (initSession(keepAlive)) {
284 onConnect(connect);
285 } else {
286 mqttContext->close();
287 }
288 }
289 }
MqttContext * mqttContext
Definition Mqtt.h:160
virtual void onConnect(const iot::mqtt::packets::Connect &connect)
Definition Mqtt.cpp:198
std::string password
Definition Mqtt.h:156
bool initSession(const utils::Timeval &keepAlive)
Definition Mqtt.cpp:147
void sendConnack(uint8_t returnCode, uint8_t flags) const
Definition Mqtt.cpp:364
std::string username
Definition Mqtt.h:155
std::string protocol
Definition Mqtt.h:148
#define MQTT_SESSION_NEW
Definition Connack.h:66
#define MQTT_CONNACK_UNACEPTABLEVERSION
Definition Connack.h:60
#define MQTT_CONNACK_IDENTIFIERREJECTED
Definition Connack.h:61
#define MQTT_VERSION_3_1_1
Definition Connect.h:60
int connect(int sockfd, const sockaddr *addr, socklen_t addrlen)
Definition socket.cpp:76

References cleanSession, iot::mqtt::Mqtt::clientId, iot::mqtt::MqttContext::close(), connectFlags, iot::mqtt::Mqtt::connectionName, iot::mqtt::packets::Connect::getCleanSession(), iot::mqtt::packets::Connect::getClientId(), iot::mqtt::packets::Connect::getConnectFlags(), iot::mqtt::packets::Connect::getKeepAlive(), iot::mqtt::packets::Connect::getLevel(), iot::mqtt::packets::Connect::getPassword(), iot::mqtt::packets::Connect::getPasswordFlag(), iot::mqtt::packets::Connect::getProtocol(), iot::mqtt::packets::Connect::getReflect(), iot::mqtt::packets::Connect::getUsername(), iot::mqtt::packets::Connect::getUsernameFlag(), iot::mqtt::packets::Connect::getWillFlag(), iot::mqtt::packets::Connect::getWillMessage(), iot::mqtt::packets::Connect::getWillQoS(), iot::mqtt::packets::Connect::getWillRetain(), iot::mqtt::packets::Connect::getWillTopic(), initSession(), iot::mqtt::server::packets::Connect::isFakedClientId(), keepAlive, level, iot::mqtt::Mqtt::mqttContext, onConnect(), password, passwordFlag, protocol, reflect, sendConnack(), username, usernameFlag, willFlag, willMessage, willQoS, willRetain, and willTopic.

Referenced by iot::mqtt::server::packets::Connect::deliverPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _onDisconnect()

void iot::mqtt::server::Mqtt::_onDisconnect ( const iot::mqtt::server::packets::Disconnect & disconnect)
private

Definition at line 350 of file Mqtt.cpp.

350 {
351 willFlag = false;
352
353 onDisconnect(disconnect);
354
356 }
virtual void onDisconnect(const iot::mqtt::packets::Disconnect &disconnect)
Definition Mqtt.cpp:210

References onDisconnect(), releaseSession(), and willFlag.

Referenced by iot::mqtt::server::packets::Disconnect::deliverPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _onPingreq()

void iot::mqtt::server::Mqtt::_onPingreq ( const iot::mqtt::server::packets::Pingreq & pingreq)
private

Definition at line 344 of file Mqtt.cpp.

344 {
345 sendPingresp();
346
347 onPingreq(pingreq);
348 }
virtual void onPingreq(const iot::mqtt::packets::Pingreq &pingreq)
Definition Mqtt.cpp:207
void sendPingresp() const
Definition Mqtt.cpp:376

References onPingreq(), and sendPingresp().

Referenced by iot::mqtt::server::packets::Pingreq::deliverPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _onPublish()

void iot::mqtt::server::Mqtt::_onPublish ( const iot::mqtt::server::packets::Publish & publish)
private

Definition at line 291 of file Mqtt.cpp.

291 {
292 if (Super::_onPublish(publish)) {
293 deliverPublish(publish);
294 }
295 }
bool _onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:266
void deliverPublish(const iot::mqtt::packets::Publish &publish) final
Definition Mqtt.cpp:358

References iot::mqtt::Mqtt::_onPublish(), and deliverPublish().

Referenced by iot::mqtt::server::packets::Publish::deliverPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _onSubscribe()

void iot::mqtt::server::Mqtt::_onSubscribe ( const iot::mqtt::server::packets::Subscribe & subscribe)
private

Definition at line 297 of file Mqtt.cpp.

297 {
298 if (subscribe.getPacketIdentifier() == 0) {
299 LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing";
300 mqttContext->close();
301 } else {
302 LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4)
303 << subscribe.getPacketIdentifier() << std::dec;
304
305 for (const iot::mqtt::Topic& topic : subscribe.getTopics()) {
306 LOG(INFO) << connectionName << " MQTT Broker: Topic filter: '" << topic.getName()
307 << "', QoS: " << static_cast<uint16_t>(topic.getQoS());
308 }
309
310 std::list<uint8_t> returnCodes;
311 for (const iot::mqtt::Topic& topic : subscribe.getTopics()) {
312 const uint8_t returnCode = broker->subscribe(clientId, topic.getName(), topic.getQoS());
313 returnCodes.push_back(returnCode);
314 }
315
316 sendSuback(subscribe.getPacketIdentifier(), returnCodes);
317
318 onSubscribe(subscribe);
319 }
320 }
const std::list< iot::mqtt::Topic > & getTopics() const
Definition Subscribe.cpp:86
uint16_t getPacketIdentifier() const
Definition Subscribe.cpp:82
void sendSuback(uint16_t packetIdentifier, const std::list< uint8_t > &returnCodes) const
Definition Mqtt.cpp:368
virtual void onSubscribe(const iot::mqtt::packets::Subscribe &subscribe)
Definition Mqtt.cpp:201

References iot::mqtt::Mqtt::clientId, iot::mqtt::MqttContext::close(), iot::mqtt::Mqtt::connectionName, iot::mqtt::Topic::getName(), iot::mqtt::packets::Subscribe::getPacketIdentifier(), iot::mqtt::Topic::getQoS(), iot::mqtt::packets::Subscribe::getTopics(), iot::mqtt::Mqtt::mqttContext, onSubscribe(), sendSuback(), and iot::mqtt::server::broker::Broker::subscribe().

Referenced by iot::mqtt::server::packets::Subscribe::deliverPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _onUnsubscribe()

void iot::mqtt::server::Mqtt::_onUnsubscribe ( const iot::mqtt::server::packets::Unsubscribe & unsubscribe)
private

Definition at line 322 of file Mqtt.cpp.

322 {
323 if (unsubscribe.getPacketIdentifier() == 0) {
324 LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing";
325 mqttContext->close();
326 } else {
327 LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4)
328 << unsubscribe.getPacketIdentifier() << std::dec;
329
330 for (const std::string& topic : unsubscribe.getTopics()) {
331 LOG(INFO) << connectionName << " MQTT Broker: Topic: " << topic;
332 }
333
334 for (const std::string& topic : unsubscribe.getTopics()) {
335 broker->unsubscribe(clientId, topic);
336 }
337
338 sendUnsuback(unsubscribe.getPacketIdentifier());
339
340 onUnsubscribe(unsubscribe);
341 }
342 }
uint16_t getPacketIdentifier() const
const std::list< std::string > & getTopics() const
virtual void onUnsubscribe(const iot::mqtt::packets::Unsubscribe &unsubscribe)
Definition Mqtt.cpp:204
void sendUnsuback(uint16_t packetIdentifier) const
Definition Mqtt.cpp:372

References iot::mqtt::Mqtt::clientId, iot::mqtt::MqttContext::close(), iot::mqtt::Mqtt::connectionName, iot::mqtt::packets::Unsubscribe::getPacketIdentifier(), iot::mqtt::packets::Unsubscribe::getTopics(), iot::mqtt::Mqtt::mqttContext, onUnsubscribe(), sendUnsuback(), and iot::mqtt::server::broker::Broker::unsubscribe().

Referenced by iot::mqtt::server::packets::Unsubscribe::deliverPacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createControlPacketDeserializer()

iot::mqtt::ControlPacketDeserializer * iot::mqtt::server::Mqtt::createControlPacketDeserializer ( iot::mqtt::FixedHeader & fixedHeader) const
finalprivatevirtual

Implements iot::mqtt::Mqtt.

Definition at line 91 of file Mqtt.cpp.

91 {
92 iot::mqtt::ControlPacketDeserializer* controlPacketDeserializer = nullptr; // NOLINT
93
94 switch (fixedHeader.getType()) {
95 case MQTT_CONNECT:
97 new iot::mqtt::server::packets::Connect(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
98 break;
99 case MQTT_PUBLISH:
101 new iot::mqtt::server::packets::Publish(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
102 break;
103 case MQTT_PUBACK:
105 new iot::mqtt::server::packets::Puback(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
106 break;
107 case MQTT_PUBREC:
109 new iot::mqtt::server::packets::Pubrec(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
110 break;
111 case MQTT_PUBREL:
113 new iot::mqtt::server::packets::Pubrel(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
114 break;
115 case MQTT_PUBCOMP:
117 new iot::mqtt::server::packets::Pubcomp(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
118 break;
119 case MQTT_SUBSCRIBE:
121 new iot::mqtt::server::packets::Subscribe(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
122 break;
123 case MQTT_UNSUBSCRIBE:
125 new iot::mqtt::server::packets::Unsubscribe(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
126 break;
127 case MQTT_PINGREQ:
129 new iot::mqtt::server::packets::Pingreq(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
130 break;
131 case MQTT_DISCONNECT:
133 new iot::mqtt::server::packets::Disconnect(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
134 break;
135 default:
137 break;
138 }
139
141 }
iot::mqtt::FixedHeader fixedHeader
Definition Mqtt.h:148
iot::mqtt::ControlPacketDeserializer * controlPacketDeserializer
Definition Mqtt.h:149
friend class iot::mqtt::server::packets::Puback
Definition Mqtt.h:176
friend class iot::mqtt::server::packets::Pingreq
Definition Mqtt.h:171
friend class iot::mqtt::server::packets::Publish
Definition Mqtt.h:173
friend class iot::mqtt::server::packets::Pubrel
Definition Mqtt.h:177
friend class iot::mqtt::server::packets::Disconnect
Definition Mqtt.h:172
friend class iot::mqtt::server::packets::Unsubscribe
Definition Mqtt.h:170
friend class iot::mqtt::server::packets::Subscribe
Definition Mqtt.h:169
friend class iot::mqtt::server::packets::Pubcomp
Definition Mqtt.h:174
friend class iot::mqtt::server::packets::Connect
Definition Mqtt.h:168
friend class iot::mqtt::server::packets::Pubrec
Definition Mqtt.h:175
#define MQTT_CONNECT
Definition Connect.h:58
#define MQTT_DISCONNECT
Definition Disconnect.h:55
#define MQTT_PINGREQ
Definition Pingreq.h:55
#define MQTT_PUBACK
Definition Puback.h:57
#define MQTT_PUBCOMP
Definition Pubcomp.h:57
#define MQTT_PUBLISH
Definition Publish.h:58
#define MQTT_PUBREC
Definition Pubrec.h:57
#define MQTT_PUBREL
Definition Pubrel.h:57
#define MQTT_SUBSCRIBE
Definition Subscribe.h:59
#define MQTT_UNSUBSCRIBE
Definition Unsubscribe.h:59

References iot::mqtt::server::packets::Connect::Connect(), iot::mqtt::server::packets::Disconnect::Disconnect(), iot::mqtt::FixedHeader::getFlags(), iot::mqtt::FixedHeader::getRemainingLength(), iot::mqtt::FixedHeader::getType(), iot::mqtt::server::packets::Pingreq::Pingreq(), iot::mqtt::server::packets::Puback::Puback(), iot::mqtt::server::packets::Pubcomp::Pubcomp(), iot::mqtt::server::packets::Publish::Publish(), iot::mqtt::server::packets::Pubrec::Pubrec(), iot::mqtt::server::packets::Pubrel::Pubrel(), iot::mqtt::server::packets::Subscribe::Subscribe(), and iot::mqtt::server::packets::Unsubscribe::Unsubscribe().

Here is the call graph for this function:

◆ deliverPacket()

void iot::mqtt::server::Mqtt::deliverPacket ( iot::mqtt::ControlPacketDeserializer * controlPacketDeserializer)
overrideprivatevirtual

Implements iot::mqtt::Mqtt.

Definition at line 143 of file Mqtt.cpp.

143 {
144 static_cast<iot::mqtt::server::ControlPacketDeserializer*>(controlPacketDeserializer)->deliverPacket(this); // NOLINT
145 }
void deliverPacket(iot::mqtt::ControlPacketDeserializer *controlPacketDeserializer) override
Definition Mqtt.cpp:143

References iot::mqtt::server::ControlPacketDeserializer::deliverPacket().

Here is the call graph for this function:

◆ deliverPublish()

void iot::mqtt::server::Mqtt::deliverPublish ( const iot::mqtt::packets::Publish & publish)
finalprivatevirtual

Implements iot::mqtt::Mqtt.

Definition at line 358 of file Mqtt.cpp.

358 {
359 broker->publish(clientId, publish.getTopic(), publish.getMessage(), publish.getQoS(), publish.getRetain());
360
361 onPublish(publish);
362 }
virtual void onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:251
uint8_t getQoS() const
Definition Publish.cpp:85
std::string getTopic() const
Definition Publish.cpp:93
std::string getMessage() const
Definition Publish.cpp:97

References iot::mqtt::Mqtt::clientId, iot::mqtt::packets::Publish::getMessage(), iot::mqtt::packets::Publish::getQoS(), iot::mqtt::packets::Publish::getRetain(), iot::mqtt::packets::Publish::getTopic(), iot::mqtt::Mqtt::onPublish(), and iot::mqtt::server::broker::Broker::publish().

Referenced by _onPublish().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCleanSession()

bool iot::mqtt::server::Mqtt::getCleanSession ( ) const

Definition at line 440 of file Mqtt.cpp.

440 {
441 return cleanSession;
442 }

References cleanSession.

◆ getClientId()

std::string iot::mqtt::server::Mqtt::getClientId ( ) const

Definition at line 400 of file Mqtt.cpp.

400 {
401 return clientId;
402 }

References iot::mqtt::Mqtt::clientId.

Referenced by iot::mqtt::server::broker::Session::sendPublish().

Here is the caller graph for this function:

◆ getConnectFlags()

uint8_t iot::mqtt::server::Mqtt::getConnectFlags ( ) const

Definition at line 392 of file Mqtt.cpp.

392 {
393 return connectFlags;
394 }

References connectFlags.

◆ getKeepAlive()

uint16_t iot::mqtt::server::Mqtt::getKeepAlive ( ) const

Definition at line 396 of file Mqtt.cpp.

396 {
397 return keepAlive;
398 }

References keepAlive.

◆ getLevel()

uint8_t iot::mqtt::server::Mqtt::getLevel ( ) const

Definition at line 388 of file Mqtt.cpp.

388 {
389 return level;
390 }

References level.

◆ getPassword()

std::string iot::mqtt::server::Mqtt::getPassword ( ) const

Definition at line 416 of file Mqtt.cpp.

416 {
417 return password;
418 }

References password.

◆ getPasswordFlag()

bool iot::mqtt::server::Mqtt::getPasswordFlag ( ) const

Definition at line 424 of file Mqtt.cpp.

424 {
425 return passwordFlag;
426 }

References passwordFlag.

◆ getProtocol()

std::string iot::mqtt::server::Mqtt::getProtocol ( ) const

Definition at line 384 of file Mqtt.cpp.

384 {
385 return protocol;
386 }

References protocol.

◆ getReflect()

bool iot::mqtt::server::Mqtt::getReflect ( ) const

Definition at line 444 of file Mqtt.cpp.

444 {
445 return reflect;
446 }

References reflect.

Referenced by iot::mqtt::server::broker::Session::sendPublish().

Here is the caller graph for this function:

◆ getSubscriptions()

std::list< std::string > iot::mqtt::server::Mqtt::getSubscriptions ( ) const

Definition at line 380 of file Mqtt.cpp.

380 {
381 return broker->getSubscriptions(clientId);
382 }

References iot::mqtt::Mqtt::clientId, and iot::mqtt::server::broker::Broker::getSubscriptions().

Here is the call graph for this function:

◆ getUsername()

std::string iot::mqtt::server::Mqtt::getUsername ( ) const

Definition at line 412 of file Mqtt.cpp.

412 {
413 return username;
414 }

References username.

◆ getUsernameFlag()

bool iot::mqtt::server::Mqtt::getUsernameFlag ( ) const

Definition at line 420 of file Mqtt.cpp.

420 {
421 return usernameFlag;
422 }

References usernameFlag.

◆ getWillFlag()

bool iot::mqtt::server::Mqtt::getWillFlag ( ) const

Definition at line 436 of file Mqtt.cpp.

436 {
437 return willFlag;
438 }

References willFlag.

◆ getWillMessage()

std::string iot::mqtt::server::Mqtt::getWillMessage ( ) const

Definition at line 408 of file Mqtt.cpp.

408 {
409 return willMessage;
410 }

References willMessage.

◆ getWillQoS()

uint8_t iot::mqtt::server::Mqtt::getWillQoS ( ) const

Definition at line 432 of file Mqtt.cpp.

432 {
433 return willQoS;
434 }

References willQoS.

◆ getWillRetain()

bool iot::mqtt::server::Mqtt::getWillRetain ( ) const

Definition at line 428 of file Mqtt.cpp.

428 {
429 return willRetain;
430 }

References willRetain.

◆ getWillTopic()

std::string iot::mqtt::server::Mqtt::getWillTopic ( ) const

Definition at line 404 of file Mqtt.cpp.

404 {
405 return willTopic;
406 }

References willTopic.

◆ initSession() [1/2]

bool iot::mqtt::server::Mqtt::initSession ( const utils::Timeval & keepAlive)
private

Definition at line 147 of file Mqtt.cpp.

147 {
148 bool success = true;
149
150 if (broker->hasActiveSession(clientId)) {
151 LOG(ERROR) << connectionName << " MQTT Broker: Existing session found for ClientId = " << clientId;
152 LOG(ERROR) << connectionName << " MQTT Broker: closing";
154
155 willFlag = false;
156 success = false;
157 } else if (broker->hasRetainedSession(clientId)) {
158 LOG(INFO) << connectionName << " MQTT Broker: Retained session found for ClientId = " << clientId;
159 if (cleanSession) {
160 LOG(DEBUG) << connectionName << " New SessionId = " << this;
162
163 broker->unsubscribe(clientId);
164 initSession(broker->newSession(clientId, this), keepAlive);
165 } else {
166 LOG(DEBUG) << connectionName << " Renew SessionId = " << this;
168
169 initSession(broker->renewSession(clientId, this), keepAlive);
170 broker->restartSession(clientId);
171 }
172 } else {
173 LOG(INFO) << connectionName << " MQTT Broker: No session found for ClientId = " << clientId;
174 LOG(INFO) << connectionName << " MQTT Broker: new SessionId = " << this;
175
177
178 initSession(broker->newSession(clientId, this), keepAlive);
179 }
180
181 return success;
182 }
#define MQTT_CONNACK_ACCEPT
Definition Connack.h:59
#define MQTT_SESSION_PRESENT
Definition Connack.h:67

References cleanSession, iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, iot::mqtt::server::broker::Broker::hasActiveSession(), iot::mqtt::server::broker::Broker::hasRetainedSession(), iot::mqtt::Mqtt::initSession(), iot::mqtt::server::broker::Broker::newSession(), iot::mqtt::server::broker::Broker::renewSession(), iot::mqtt::server::broker::Broker::restartSession(), sendConnack(), iot::mqtt::server::broker::Broker::unsubscribe(), and willFlag.

Referenced by _onConnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initSession() [2/2]

void iot::mqtt::Mqtt::initSession ( Session * session,
utils::Timeval keepAlive )
private

Definition at line 105 of file Mqtt.cpp.

174 {
175 this->session = session;
176
177 for (const auto& [packetIdentifier, publish] : session->outgoingPublishMap) {
178 LOG(INFO) << connectionName << " MQTT: PUBLISH Resend";
179
180 send(publish);
181 }
182
183 for (const uint16_t packetIdentifier : session->pubrelPacketIdentifierSet) {
184 LOG(INFO) << connectionName << " MQTT: PUBREL Resend";
185
186 sendPubrel(packetIdentifier);
187 }
188
189 if (keepAlive > 0) {
190 keepAlive *= 1.5;
191
192 LOG(INFO) << connectionName << " MQTT: Keep alive initialized with: " << keepAlive;
193
195 [this, keepAlive]() {
196 LOG(ERROR) << connectionName << " MQTT: Keep-alive timer expired. Interval was: " << keepAlive;
197 mqttContext->close();
198 },
199 keepAlive);
200 }
201
202 mqttContext->getSocketConnection()->setTimeout(0);
203 }
static Timer singleshotTimer(const std::function< void()> &dispatcher, const utils::Timeval &timeout)
Definition Timer.cpp:57
core::timer::Timer keepAliveTimer
Definition Mqtt.h:153
void sendPubrel(uint16_t packetIdentifier) const
Definition Mqtt.cpp:243
Session * session
Definition Mqtt.h:157
void send(const iot::mqtt::ControlPacket &controlPacket) const
Definition Mqtt.cpp:205

◆ onConnect()

void iot::mqtt::server::Mqtt::onConnect ( const iot::mqtt::packets::Connect & connect)
privatevirtual

Definition at line 198 of file Mqtt.cpp.

198 {
199 }

Referenced by _onConnect().

Here is the caller graph for this function:

◆ onDisconnect()

void iot::mqtt::server::Mqtt::onDisconnect ( const iot::mqtt::packets::Disconnect & disconnect)
privatevirtual

Definition at line 210 of file Mqtt.cpp.

210 {
211 }

Referenced by _onDisconnect().

Here is the caller graph for this function:

◆ onPingreq()

void iot::mqtt::server::Mqtt::onPingreq ( const iot::mqtt::packets::Pingreq & pingreq)
privatevirtual

Definition at line 207 of file Mqtt.cpp.

207 {
208 }

Referenced by _onPingreq().

Here is the caller graph for this function:

◆ onSignal()

bool iot::mqtt::server::Mqtt::onSignal ( int sig)
overrideprotectedvirtual

Implements iot::mqtt::Mqtt.

Definition at line 86 of file Mqtt.cpp.

86 {
87 willFlag = false;
88 return true;
89 }

References willFlag.

◆ onSubscribe()

void iot::mqtt::server::Mqtt::onSubscribe ( const iot::mqtt::packets::Subscribe & subscribe)
privatevirtual

Definition at line 201 of file Mqtt.cpp.

201 {
202 }

Referenced by _onSubscribe().

Here is the caller graph for this function:

◆ onUnsubscribe()

void iot::mqtt::server::Mqtt::onUnsubscribe ( const iot::mqtt::packets::Unsubscribe & unsubscribe)
privatevirtual

Definition at line 204 of file Mqtt.cpp.

204 {
205 }

Referenced by _onUnsubscribe().

Here is the caller graph for this function:

◆ releaseSession()

void iot::mqtt::server::Mqtt::releaseSession ( )
private

Definition at line 184 of file Mqtt.cpp.

184 {
185 if (broker->isActiveSession(clientId, this)) {
186 if (cleanSession) {
187 LOG(DEBUG) << connectionName << " MQTT Broker: Delete session for ClientId = " << clientId;
188 LOG(DEBUG) << connectionName << " MQTT Broker: SessionId = " << this;
189 broker->deleteSession(clientId);
190 } else {
191 LOG(DEBUG) << connectionName << " MQTT Broker: Retain session for ClientId = " << clientId;
192 LOG(DEBUG) << connectionName << " MQTT Broker: SessionId = " << this;
193 broker->retainSession(clientId);
194 }
195 }
196 }

References cleanSession, iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, iot::mqtt::server::broker::Broker::deleteSession(), iot::mqtt::server::broker::Broker::isActiveSession(), and iot::mqtt::server::broker::Broker::retainSession().

Referenced by _onDisconnect(), and ~Mqtt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendConnack()

void iot::mqtt::server::Mqtt::sendConnack ( uint8_t returnCode,
uint8_t flags ) const

Definition at line 364 of file Mqtt.cpp.

364 { // Server
365 send(iot::mqtt::packets::Connack(returnCode, flags));
366 }

References iot::mqtt::packets::Connack::Connack(), and iot::mqtt::Mqtt::send().

Referenced by _onConnect(), and initSession().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendPingresp()

void iot::mqtt::server::Mqtt::sendPingresp ( ) const

Definition at line 376 of file Mqtt.cpp.

376 { // Server
377 send(iot::mqtt::packets::Pingresp());
378 }

References iot::mqtt::packets::Pingresp::Pingresp(), and iot::mqtt::Mqtt::send().

Referenced by _onPingreq().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendSuback()

void iot::mqtt::server::Mqtt::sendSuback ( uint16_t packetIdentifier,
const std::list< uint8_t > & returnCodes ) const

Definition at line 368 of file Mqtt.cpp.

368 { // Server
369 send(iot::mqtt::packets::Suback(packetIdentifier, returnCodes));
370 }

References iot::mqtt::Mqtt::send(), and iot::mqtt::packets::Suback::Suback().

Referenced by _onSubscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendUnsuback()

void iot::mqtt::server::Mqtt::sendUnsuback ( uint16_t packetIdentifier) const

Definition at line 372 of file Mqtt.cpp.

372 { // Server
373 send(iot::mqtt::packets::Unsuback(packetIdentifier));
374 }

References iot::mqtt::Mqtt::send(), and iot::mqtt::packets::Unsuback::Unsuback().

Referenced by _onUnsubscribe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ iot::mqtt::server::packets::Connect

Definition at line 168 of file Mqtt.h.

◆ iot::mqtt::server::packets::Disconnect

Definition at line 172 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pingreq

Definition at line 171 of file Mqtt.h.

◆ iot::mqtt::server::packets::Puback

Definition at line 176 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pubcomp

Definition at line 174 of file Mqtt.h.

◆ iot::mqtt::server::packets::Publish

Definition at line 173 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pubrec

Definition at line 175 of file Mqtt.h.

◆ iot::mqtt::server::packets::Pubrel

Definition at line 177 of file Mqtt.h.

◆ iot::mqtt::server::packets::Subscribe

Definition at line 169 of file Mqtt.h.

◆ iot::mqtt::server::packets::Unsubscribe

Definition at line 170 of file Mqtt.h.

Member Data Documentation

◆ broker

std::shared_ptr<iot::mqtt::server::broker::Broker> iot::mqtt::server::Mqtt::broker
protected

Definition at line 166 of file Mqtt.h.

◆ cleanSession

bool iot::mqtt::server::Mqtt::cleanSession = false
protected

Definition at line 163 of file Mqtt.h.

Referenced by _onConnect(), getCleanSession(), initSession(), and releaseSession().

◆ connectFlags

uint8_t iot::mqtt::server::Mqtt::connectFlags = 0
protected

Definition at line 150 of file Mqtt.h.

Referenced by _onConnect(), and getConnectFlags().

◆ keepAlive

uint16_t iot::mqtt::server::Mqtt::keepAlive = 0
protected

Definition at line 151 of file Mqtt.h.

Referenced by _onConnect(), and getKeepAlive().

◆ level

uint8_t iot::mqtt::server::Mqtt::level = 0
protected

Definition at line 149 of file Mqtt.h.

Referenced by _onConnect(), and getLevel().

◆ password

std::string iot::mqtt::server::Mqtt::password
protected

Definition at line 156 of file Mqtt.h.

Referenced by _onConnect(), and getPassword().

◆ passwordFlag

bool iot::mqtt::server::Mqtt::passwordFlag = false
protected

Definition at line 159 of file Mqtt.h.

Referenced by _onConnect(), and getPasswordFlag().

◆ protocol

std::string iot::mqtt::server::Mqtt::protocol
protected

Definition at line 148 of file Mqtt.h.

Referenced by _onConnect(), and getProtocol().

◆ reflect

bool iot::mqtt::server::Mqtt::reflect = true
protected

Definition at line 164 of file Mqtt.h.

Referenced by _onConnect(), and getReflect().

◆ username

std::string iot::mqtt::server::Mqtt::username
protected

Definition at line 155 of file Mqtt.h.

Referenced by _onConnect(), and getUsername().

◆ usernameFlag

bool iot::mqtt::server::Mqtt::usernameFlag = false
protected

Definition at line 158 of file Mqtt.h.

Referenced by _onConnect(), and getUsernameFlag().

◆ willFlag

bool iot::mqtt::server::Mqtt::willFlag = false
protected

Definition at line 162 of file Mqtt.h.

Referenced by _onConnect(), _onDisconnect(), getWillFlag(), initSession(), onSignal(), and ~Mqtt().

◆ willMessage

std::string iot::mqtt::server::Mqtt::willMessage
protected

Definition at line 154 of file Mqtt.h.

Referenced by _onConnect(), getWillMessage(), and ~Mqtt().

◆ willQoS

uint8_t iot::mqtt::server::Mqtt::willQoS = 0
protected

Definition at line 161 of file Mqtt.h.

Referenced by _onConnect(), getWillQoS(), and ~Mqtt().

◆ willRetain

bool iot::mqtt::server::Mqtt::willRetain = false
protected

Definition at line 160 of file Mqtt.h.

Referenced by _onConnect(), getWillRetain(), and ~Mqtt().

◆ willTopic

std::string iot::mqtt::server::Mqtt::willTopic
protected

Definition at line 153 of file Mqtt.h.

Referenced by _onConnect(), getWillTopic(), and ~Mqtt().


The documentation for this class was generated from the following files: