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 34 of file Connect.h.

Constructor & Destructor Documentation

◆ Connect()

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

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 143 of file Connect.cpp.

143 {
144 mqtt->printVP(*this);
145 mqtt->_onConnect(*this);
146 }
void printVP(const iot::mqtt::ControlPacket &packet) const
Definition Mqtt.cpp:346
void _onConnect(const iot::mqtt::server::packets::Connect &connect)
Definition Mqtt.cpp:191

◆ deserializeVP()

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

Implements iot::mqtt::ControlPacketDeserializer.

Definition at line 39 of file Connect.cpp.

39 {
40 std::size_t consumed = 0;
41
42 switch (state) {
43 case 0: // V-Header
44 consumed += protocol.deserialize(mqttContext);
45 if (!protocol.isComplete()) {
46 break;
47 }
48
49 state++;
50 [[fallthrough]];
51 case 1:
52 consumed += level.deserialize(mqttContext);
53 if (!level.isComplete()) {
54 break;
55 }
56 reflect = (level & 0x80) == 0; // msb in level == 1 -> do not reflect message to origin (try_private in mosquitto)
57 level = level & ~0x80;
58
59 state++;
60 [[fallthrough]];
61 case 2:
62 consumed += connectFlags.deserialize(mqttContext);
63 if (!connectFlags.isComplete()) {
64 break;
65 }
66
67 reserved = (connectFlags & 0x01) != 0;
68 cleanSession = (connectFlags & 0x02) != 0;
69 willFlag = (connectFlags & 0x04) != 0;
70 willQoS = (connectFlags & 0x18) >> 3;
71 willRetain = (connectFlags & 0x20) != 0;
72 passwordFlag = (connectFlags & 0x40) != 0;
73 usernameFlag = (connectFlags & 0x80) != 0;
74
75 state++;
76 [[fallthrough]];
77 case 3:
78 consumed += keepAlive.deserialize(mqttContext);
79 if (!keepAlive.isComplete()) {
80 break;
81 }
82
83 state++;
84 [[fallthrough]];
85 case 4: // Payload
86 consumed += clientId.deserialize(mqttContext);
87 if (!clientId.isComplete()) {
88 break;
89 }
90
91 if (clientId.size() == 0) {
93 fakedClientId = true;
94 }
95
96 state++;
97 [[fallthrough]];
98 case 5:
99 if (willFlag) {
100 consumed += willTopic.deserialize(mqttContext);
101 if (!willTopic.isComplete()) {
102 break;
103 }
104 }
105
106 state++;
107 [[fallthrough]];
108 case 6:
109 if (willFlag) {
110 consumed += willMessage.deserialize(mqttContext);
111 if (!willMessage.isComplete()) {
112 break;
113 }
114 }
115
116 state++;
117 [[fallthrough]];
118 case 7:
119 if (usernameFlag) {
120 consumed += username.deserialize(mqttContext);
121 if (!username.isComplete()) {
122 break;
123 }
124 }
125
126 state++;
127 [[fallthrough]];
128 case 8:
129 if (passwordFlag) {
130 consumed += password.deserialize(mqttContext);
131 if (!password.isComplete()) {
132 break;
133 }
134 }
135
136 complete = true;
137 break;
138 }
139
140 return consumed;
141 }
iot::mqtt::types::String willMessage
Definition Connect.h:86
iot::mqtt::types::String protocol
Definition Connect.h:80
iot::mqtt::types::String willTopic
Definition Connect.h:85
iot::mqtt::types::UInt8 connectFlags
Definition Connect.h:82
iot::mqtt::types::String username
Definition Connect.h:87
iot::mqtt::types::UInt8 level
Definition Connect.h:81
iot::mqtt::types::String clientId
Definition Connect.h:84
iot::mqtt::types::String password
Definition Connect.h:88
iot::mqtt::types::UInt16 keepAlive
Definition Connect.h:83
std::size_t deserialize(iot::mqtt::MqttContext *mqttContext) override
Definition String.cpp:45
virtual std::size_t deserialize(iot::mqtt::MqttContext *mqttContext)
Definition TypeBase.hpp:37
static std::string getUuid()
Definition Uuid.cpp:30

◆ isFakedClientId()

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

Definition at line 148 of file Connect.cpp.

148 {
149 return fakedClientId;
150 }

Member Data Documentation

◆ fakedClientId

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

Definition at line 48 of file Connect.h.

◆ state

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

Definition at line 46 of file Connect.h.


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