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

#include <Connect.h>

Inheritance diagram for iot::mqtt::server::packets::Connect:
Collaboration diagram for iot::mqtt::server::packets::Connect:

Public Member Functions

 Connect (uint32_t remainingLength, uint8_t flags)
 
bool isFakedClientId () const
 
- Public Member Functions inherited from iot::mqtt::packets::Connect
 Connect ()
 
 Connect (const std::string &clientId, uint16_t keepAlive, bool cleanSession, const std::string &willTopic, const std::string &willMessage, uint8_t willQoS, bool willRetain, const std::string &username, const std::string &password, bool loopPrevention)
 
std::string getProtocol () const
 
uint8_t getLevel () const
 
uint8_t getConnectFlags () const
 
uint16_t getKeepAlive () const
 
std::string getClientId () const
 
bool getUsernameFlag () const
 
bool getPasswordFlag () const
 
bool getWillRetain () const
 
uint8_t getWillQoS () const
 
bool getWillFlag () const
 
bool getCleanSession () const
 
bool getReflect () const
 
std::string getWillTopic () const
 
std::string getWillMessage () const
 
std::string getUsername () const
 
std::string getPassword () const
 
- Public Member Functions inherited from iot::mqtt::ControlPacket
 ControlPacket (uint8_t type, const std::string &name)
 
 ControlPacket (const ControlPacket &)=default
 
 ControlPacket (ControlPacket &&)=default
 
virtual ~ControlPacket ()
 
ControlPacketoperator= (const ControlPacket &)=default
 
ControlPacketoperator= (ControlPacket &&)=default
 
std::vector< char > serialize () const
 
const std::string & getName () const
 
uint8_t getType () const
 
uint8_t getFlags () const
 
- Public Member Functions inherited from iot::mqtt::server::ControlPacketDeserializer
 ~ControlPacketDeserializer () override
 
- Public Member Functions inherited from iot::mqtt::ControlPacketDeserializer
 ControlPacketDeserializer ()=default
 
 ControlPacketDeserializer (uint32_t remainingLength, uint8_t flags, uint8_t mustFlags)
 
ControlPacketDeserializeroperator= (const ControlPacketDeserializer &)=default
 
std::size_t deserialize (iot::mqtt::MqttContext *mqttContext)
 
uint32_t getRemainingLength () const
 
bool isComplete () const
 
bool isError () const
 
std::size_t getConsumed () const
 

Private Member Functions

std::size_t deserializeVP (iot::mqtt::MqttContext *mqttContext) override
 
void deliverPacket (iot::mqtt::server::Mqtt *mqtt) override
 

Private Attributes

int state = 0
 
bool fakedClientId = false
 

Additional Inherited Members

- Protected Attributes inherited from iot::mqtt::packets::Connect
iot::mqtt::types::String protocol
 
iot::mqtt::types::UInt8 level
 
iot::mqtt::types::UInt8 connectFlags
 
iot::mqtt::types::UInt16 keepAlive
 
iot::mqtt::types::String clientId
 
iot::mqtt::types::String willTopic
 
iot::mqtt::types::String willMessage
 
iot::mqtt::types::String username
 
iot::mqtt::types::String password
 
bool usernameFlag = false
 
bool passwordFlag = false
 
bool willRetain = false
 
uint8_t willQoS = 0
 
bool willFlag = false
 
bool cleanSession = false
 
bool reflect = true
 
bool reserved = false
 
- Protected Attributes inherited from iot::mqtt::ControlPacket
uint8_t flags = 0
 
- Protected Attributes inherited from iot::mqtt::ControlPacketDeserializer
bool complete = false
 
bool error = false
 
uint32_t remainingLength = 0
 
std::size_t consumed = 0
 

Detailed Description

Definition at line 56 of file Connect.h.

Constructor & Destructor Documentation

◆ Connect()

iot::mqtt::server::packets::Connect::Connect ( uint32_t  remainingLength,
uint8_t  flags 
)

Definition at line 56 of file Connect.cpp.

References iot::mqtt::ControlPacket::flags.

Referenced by iot::mqtt::server::Mqtt::createControlPacketDeserializer().

Here is the caller graph for this function:

Member Function Documentation

◆ deliverPacket()

void iot::mqtt::server::packets::Connect::deliverPacket ( iot::mqtt::server::Mqtt mqtt)
overrideprivatevirtual

Implements iot::mqtt::server::ControlPacketDeserializer.

Definition at line 165 of file Connect.cpp.

165 {
166 mqtt->printVP(*this);
167 mqtt->_onConnect(*this);
168 }
void printVP(const iot::mqtt::ControlPacket &packet) const
Definition Mqtt.cpp:368
void _onConnect(const iot::mqtt::server::packets::Connect &connect)
Definition Mqtt.cpp:221

References iot::mqtt::server::Mqtt::_onConnect(), and iot::mqtt::Mqtt::printVP().

Here is the call graph for this function:

◆ deserializeVP()

std::size_t iot::mqtt::server::packets::Connect::deserializeVP ( iot::mqtt::MqttContext mqttContext)
overrideprivatevirtual

Implements iot::mqtt::ControlPacketDeserializer.

Definition at line 61 of file Connect.cpp.

61 {
62 std::size_t consumed = 0;
63
64 switch (state) {
65 case 0: // V-Header
66 consumed += protocol.deserialize(mqttContext);
67 if (!protocol.isComplete()) {
68 break;
69 }
70
71 state++;
72 [[fallthrough]];
73 case 1:
74 consumed += level.deserialize(mqttContext);
75 if (!level.isComplete()) {
76 break;
77 }
78 reflect = (level & 0x80) == 0; // msb in level == 1 -> do not reflect message to origin (try_private in mosquitto)
79 level = level & ~0x80;
80
81 state++;
82 [[fallthrough]];
83 case 2:
84 consumed += connectFlags.deserialize(mqttContext);
85 if (!connectFlags.isComplete()) {
86 break;
87 }
88
89 reserved = (connectFlags & 0x01) != 0;
90 cleanSession = (connectFlags & 0x02) != 0;
91 willFlag = (connectFlags & 0x04) != 0;
92 willQoS = (connectFlags & 0x18) >> 3;
93 willRetain = (connectFlags & 0x20) != 0;
94 passwordFlag = (connectFlags & 0x40) != 0;
95 usernameFlag = (connectFlags & 0x80) != 0;
96
97 state++;
98 [[fallthrough]];
99 case 3:
100 consumed += keepAlive.deserialize(mqttContext);
101 if (!keepAlive.isComplete()) {
102 break;
103 }
104
105 state++;
106 [[fallthrough]];
107 case 4: // Payload
108 consumed += clientId.deserialize(mqttContext);
109 if (!clientId.isComplete()) {
110 break;
111 }
112
113 if (clientId.size() == 0) {
115 fakedClientId = true;
116 }
117
118 state++;
119 [[fallthrough]];
120 case 5:
121 if (willFlag) {
122 consumed += willTopic.deserialize(mqttContext);
123 if (!willTopic.isComplete()) {
124 break;
125 }
126 }
127
128 state++;
129 [[fallthrough]];
130 case 6:
131 if (willFlag) {
132 consumed += willMessage.deserialize(mqttContext);
133 if (!willMessage.isComplete()) {
134 break;
135 }
136 }
137
138 state++;
139 [[fallthrough]];
140 case 7:
141 if (usernameFlag) {
142 consumed += username.deserialize(mqttContext);
143 if (!username.isComplete()) {
144 break;
145 }
146 }
147
148 state++;
149 [[fallthrough]];
150 case 8:
151 if (passwordFlag) {
152 consumed += password.deserialize(mqttContext);
153 if (!password.isComplete()) {
154 break;
155 }
156 }
157
158 complete = true;
159 break;
160 }
161
162 return consumed;
163 }
iot::mqtt::types::String willMessage
Definition Connect.h:108
iot::mqtt::types::String protocol
Definition Connect.h:102
iot::mqtt::types::String willTopic
Definition Connect.h:107
iot::mqtt::types::UInt8 connectFlags
Definition Connect.h:104
iot::mqtt::types::String username
Definition Connect.h:109
iot::mqtt::types::UInt8 level
Definition Connect.h:103
iot::mqtt::types::String clientId
Definition Connect.h:106
iot::mqtt::types::String password
Definition Connect.h:110
iot::mqtt::types::UInt16 keepAlive
Definition Connect.h:105
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
Definition String.cpp:67
virtual std::size_t deserialize(iot::mqtt::MqttContext *mqttContext)
Definition TypeBase.hpp:59
static std::string getUuid()
Definition Uuid.cpp:52

References iot::mqtt::packets::Connect::cleanSession, iot::mqtt::packets::Connect::clientId, iot::mqtt::ControlPacketDeserializer::complete, iot::mqtt::packets::Connect::connectFlags, iot::mqtt::types::TypeBase< ValueTypeT >::deserialize(), iot::mqtt::types::String::deserialize(), fakedClientId, utils::Uuid::getUuid(), iot::mqtt::types::TypeBase< ValueTypeT >::isComplete(), iot::mqtt::packets::Connect::keepAlive, iot::mqtt::packets::Connect::level, iot::mqtt::types::String::operator=(), iot::mqtt::types::UInt8::operator=(), iot::mqtt::packets::Connect::password, iot::mqtt::packets::Connect::passwordFlag, iot::mqtt::packets::Connect::protocol, iot::mqtt::packets::Connect::reflect, iot::mqtt::packets::Connect::reserved, iot::mqtt::types::TypeBase< ValueTypeT >::size(), state, iot::mqtt::packets::Connect::username, iot::mqtt::packets::Connect::usernameFlag, iot::mqtt::packets::Connect::willFlag, iot::mqtt::packets::Connect::willMessage, iot::mqtt::packets::Connect::willQoS, iot::mqtt::packets::Connect::willRetain, and iot::mqtt::packets::Connect::willTopic.

Here is the call graph for this function:

◆ isFakedClientId()

bool iot::mqtt::server::packets::Connect::isFakedClientId ( ) const

Definition at line 170 of file Connect.cpp.

170 {
171 return fakedClientId;
172 }

References fakedClientId.

Referenced by iot::mqtt::server::Mqtt::_onConnect().

Here is the caller graph for this function:

Member Data Documentation

◆ fakedClientId

bool iot::mqtt::server::packets::Connect::fakedClientId = false
private

Definition at line 70 of file Connect.h.

Referenced by deserializeVP(), and isFakedClientId().

◆ state

int iot::mqtt::server::packets::Connect::state = 0
private

Definition at line 68 of file Connect.h.

Referenced by deserializeVP().


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