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
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 distributePublish (const iot::mqtt::packets::Publish &publish) final
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
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 72 of file Mqtt.cpp.

74 , broker(broker) {
75 }
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 77 of file Mqtt.cpp.

77 {
79
80 if (willFlag) {
82 }
83 }
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 218 of file Mqtt.cpp.

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

355 {
356 willFlag = false;
357
358 onDisconnect(disconnect);
359
361 }
virtual void onDisconnect(const iot::mqtt::packets::Disconnect &disconnect)
Definition Mqtt.cpp:215

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 349 of file Mqtt.cpp.

349 {
350 sendPingresp();
351
352 onPingreq(pingreq);
353 }
virtual void onPingreq(const iot::mqtt::packets::Pingreq &pingreq)
Definition Mqtt.cpp:212
void sendPingresp() const
Definition Mqtt.cpp:375

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 296 of file Mqtt.cpp.

296 {
297 if (Super::_onPublish(publish)) {
298 distributePublish(publish);
299 }
300 }
bool _onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:265
void distributePublish(const iot::mqtt::packets::Publish &publish) final
Definition Mqtt.cpp:197

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

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 302 of file Mqtt.cpp.

302 {
303 if (subscribe.getPacketIdentifier() == 0) {
304 LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing";
305 mqttContext->close();
306 } else {
307 LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4)
308 << subscribe.getPacketIdentifier() << std::dec;
309
310 for (const iot::mqtt::Topic& topic : subscribe.getTopics()) {
311 LOG(INFO) << connectionName << " MQTT Broker: Topic filter: '" << topic.getName()
312 << "', QoS: " << static_cast<uint16_t>(topic.getQoS());
313 }
314
315 std::list<uint8_t> returnCodes;
316 for (const iot::mqtt::Topic& topic : subscribe.getTopics()) {
317 const uint8_t returnCode = broker->subscribe(clientId, topic.getName(), topic.getQoS());
318 returnCodes.push_back(returnCode);
319 }
320
321 sendSuback(subscribe.getPacketIdentifier(), returnCodes);
322
323 onSubscribe(subscribe);
324 }
325 }
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:367
virtual void onSubscribe(const iot::mqtt::packets::Subscribe &subscribe)
Definition Mqtt.cpp:206

References iot::mqtt::Mqtt::clientId, iot::mqtt::MqttContext::close(), iot::mqtt::Mqtt::connectionName, logger::DEBUG, logger::ERROR, iot::mqtt::Topic::getName(), iot::mqtt::packets::Subscribe::getPacketIdentifier(), iot::mqtt::Topic::getQoS(), iot::mqtt::packets::Subscribe::getTopics(), logger::INFO, logger::LogMessage::LogMessage(), 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 327 of file Mqtt.cpp.

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

References iot::mqtt::Mqtt::clientId, iot::mqtt::MqttContext::close(), iot::mqtt::Mqtt::connectionName, logger::DEBUG, logger::ERROR, iot::mqtt::packets::Unsubscribe::getPacketIdentifier(), iot::mqtt::packets::Unsubscribe::getTopics(), logger::INFO, logger::LogMessage::LogMessage(), 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 90 of file Mqtt.cpp.

90 {
91 iot::mqtt::ControlPacketDeserializer* controlPacketDeserializer = nullptr; // NOLINT
92
93 switch (fixedHeader.getType()) {
94 case MQTT_CONNECT:
96 new iot::mqtt::server::packets::Connect(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
97 break;
98 case MQTT_PUBLISH:
100 new iot::mqtt::server::packets::Publish(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
101 break;
102 case MQTT_PUBACK:
104 new iot::mqtt::server::packets::Puback(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
105 break;
106 case MQTT_PUBREC:
108 new iot::mqtt::server::packets::Pubrec(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
109 break;
110 case MQTT_PUBREL:
112 new iot::mqtt::server::packets::Pubrel(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
113 break;
114 case MQTT_PUBCOMP:
116 new iot::mqtt::server::packets::Pubcomp(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
117 break;
118 case MQTT_SUBSCRIBE:
120 new iot::mqtt::server::packets::Subscribe(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
121 break;
122 case MQTT_UNSUBSCRIBE:
124 new iot::mqtt::server::packets::Unsubscribe(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
125 break;
126 case MQTT_PINGREQ:
128 new iot::mqtt::server::packets::Pingreq(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
129 break;
130 case MQTT_DISCONNECT:
132 new iot::mqtt::server::packets::Disconnect(fixedHeader.getRemainingLength(), fixedHeader.getFlags());
133 break;
134 default:
136 break;
137 }
138
140 }
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 142 of file Mqtt.cpp.

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

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

Here is the call graph for this function:

◆ distributePublish()

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

Implements iot::mqtt::Mqtt.

Definition at line 197 of file Mqtt.cpp.

197 {
198 broker->publish(clientId, publish.getTopic(), publish.getMessage(), publish.getQoS(), publish.getRetain());
199
200 onPublish(publish);
201 }
virtual void onPublish(const iot::mqtt::packets::Publish &publish)
Definition Mqtt.cpp:250
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 439 of file Mqtt.cpp.

439 {
440 return cleanSession;
441 }

References cleanSession.

◆ getClientId()

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

Definition at line 399 of file Mqtt.cpp.

399 {
400 return clientId;
401 }

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 391 of file Mqtt.cpp.

391 {
392 return connectFlags;
393 }

References connectFlags.

◆ getKeepAlive()

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

Definition at line 395 of file Mqtt.cpp.

395 {
396 return keepAlive;
397 }

References keepAlive.

◆ getLevel()

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

Definition at line 387 of file Mqtt.cpp.

387 {
388 return level;
389 }

References level.

◆ getPassword()

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

Definition at line 415 of file Mqtt.cpp.

415 {
416 return password;
417 }

References password.

◆ getPasswordFlag()

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

Definition at line 423 of file Mqtt.cpp.

423 {
424 return passwordFlag;
425 }

References passwordFlag.

◆ getProtocol()

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

Definition at line 383 of file Mqtt.cpp.

383 {
384 return protocol;
385 }

References protocol.

◆ getReflect()

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

Definition at line 443 of file Mqtt.cpp.

443 {
444 return reflect;
445 }

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
private

Definition at line 379 of file Mqtt.cpp.

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

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 411 of file Mqtt.cpp.

411 {
412 return username;
413 }

References username.

◆ getUsernameFlag()

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

Definition at line 419 of file Mqtt.cpp.

419 {
420 return usernameFlag;
421 }

References usernameFlag.

◆ getWillFlag()

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

Definition at line 435 of file Mqtt.cpp.

435 {
436 return willFlag;
437 }

References willFlag.

◆ getWillMessage()

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

Definition at line 407 of file Mqtt.cpp.

407 {
408 return willMessage;
409 }

References willMessage.

◆ getWillQoS()

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

Definition at line 431 of file Mqtt.cpp.

431 {
432 return willQoS;
433 }

References willQoS.

◆ getWillRetain()

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

Definition at line 427 of file Mqtt.cpp.

427 {
428 return willRetain;
429 }

References willRetain.

◆ getWillTopic()

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

Definition at line 403 of file Mqtt.cpp.

403 {
404 return willTopic;
405 }

References willTopic.

◆ initSession() [1/2]

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

Definition at line 146 of file Mqtt.cpp.

146 {
147 bool success = true;
148
149 if (broker->hasActiveSession(clientId)) {
150 LOG(ERROR) << connectionName << " MQTT Broker: Existing session found for ClientId = " << clientId;
151 LOG(ERROR) << connectionName << " MQTT Broker: closing";
153
154 willFlag = false;
155 success = false;
156 } else if (broker->hasRetainedSession(clientId)) {
157 LOG(INFO) << connectionName << " MQTT Broker: Retained session found for ClientId = " << clientId;
158 if (cleanSession) {
159 LOG(DEBUG) << connectionName << " New SessionId = " << this;
161
162 broker->unsubscribe(clientId);
163 initSession(broker->newSession(clientId, this), keepAlive);
164 } else {
165 LOG(DEBUG) << connectionName << " Renew SessionId = " << this;
167
168 initSession(broker->renewSession(clientId, this), keepAlive);
169 broker->restartSession(clientId);
170 }
171 } else {
172 LOG(INFO) << connectionName << " MQTT Broker: No session found for ClientId = " << clientId;
173 LOG(INFO) << connectionName << " MQTT Broker: new SessionId = " << this;
174
176
177 initSession(broker->newSession(clientId, this), keepAlive);
178 }
179
180 return success;
181 }
#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, logger::DEBUG, logger::ERROR, iot::mqtt::server::broker::Broker::hasActiveSession(), iot::mqtt::server::broker::Broker::hasRetainedSession(), logger::INFO, iot::mqtt::Mqtt::initSession(), logger::LogMessage::LogMessage(), 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.

173 {
174 this->session = session;
175
176 for (const auto& [packetIdentifier, publish] : session->outgoingPublishMap) {
177 LOG(INFO) << connectionName << " MQTT: PUBLISH Resend";
178
179 send(publish);
180 }
181
182 for (const uint16_t packetIdentifier : session->pubrelPacketIdentifierSet) {
183 LOG(INFO) << connectionName << " MQTT: PUBREL Resend";
184
185 sendPubrel(packetIdentifier);
186 }
187
188 if (keepAlive > 0) {
189 keepAlive *= 1.5;
190
191 LOG(INFO) << connectionName << " MQTT: Keep alive initialized with: " << keepAlive;
192
194 [this, keepAlive]() {
195 LOG(ERROR) << connectionName << " MQTT: Keep-alive timer expired. Interval was: " << keepAlive;
196 mqttContext->close();
197 },
198 keepAlive);
199 }
200
201 mqttContext->getSocketConnection()->setTimeout(0);
202 }
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:242
Session * session
Definition Mqtt.h:157
void send(const iot::mqtt::ControlPacket &controlPacket) const
Definition Mqtt.cpp:204

◆ onConnect()

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

Definition at line 203 of file Mqtt.cpp.

203 {
204 }

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 215 of file Mqtt.cpp.

215 {
216 }

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 212 of file Mqtt.cpp.

212 {
213 }

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 85 of file Mqtt.cpp.

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

References willFlag.

◆ onSubscribe()

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

Definition at line 206 of file Mqtt.cpp.

206 {
207 }

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 209 of file Mqtt.cpp.

209 {
210 }

Referenced by _onUnsubscribe().

Here is the caller graph for this function:

◆ releaseSession()

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

Definition at line 183 of file Mqtt.cpp.

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

References cleanSession, iot::mqtt::Mqtt::clientId, iot::mqtt::Mqtt::connectionName, logger::DEBUG, iot::mqtt::server::broker::Broker::deleteSession(), iot::mqtt::server::broker::Broker::isActiveSession(), logger::LogMessage::LogMessage(), 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
private

Definition at line 363 of file Mqtt.cpp.

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

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
private

Definition at line 375 of file Mqtt.cpp.

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

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
private

Definition at line 367 of file Mqtt.cpp.

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

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
private

Definition at line 371 of file Mqtt.cpp.

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

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: