SNode.C
Loading...
Searching...
No Matches
Connect.cpp
Go to the documentation of this file.
1
/*
2
* SNode.C - a slim toolkit for network communication
3
* Copyright (C) Volker Christian <me@vchrist.at>
4
* 2020, 2021, 2022, 2023, 2024, 2025
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published
8
* by the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#
include
"iot/mqtt/server/packets/Connect.h"
21
22
#
include
"iot/mqtt/server/Mqtt.h"
23
24
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
25
26
#
include
"utils/Uuid.h"
27
28
#
include
<
string
>
29
30
#
endif
// DOXYGEN_SHOULD_SKIP_THIS
31
32
namespace
iot::mqtt::server::
packets
{
33
34
Connect
::
Connect
(
uint32_t
remainingLength
,
uint8_t
flags
)
35
:
iot
::
mqtt
::
server
::
ControlPacketDeserializer
(
remainingLength
,
flags
,
MQTT_CONNECT_FLAGS
) {
36
this
->
flags
=
flags
;
37
}
38
39
std
::
size_t
Connect
::
deserializeVP
(
iot
::
mqtt
::
MqttContext
*
mqttContext
) {
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) {
92
clientId
=
utils
::
Uuid
::
getUuid
();
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
}
142
143
void
Connect
::
deliverPacket
(
iot
::
mqtt
::
server
::
Mqtt
*
mqtt
) {
144
mqtt
->
printVP
(*
this
);
145
mqtt
->
_onConnect
(*
this
);
146
}
147
148
bool
Connect
::
isFakedClientId
()
const
{
149
return
fakedClientId
;
150
}
151
152
}
// namespace iot::mqtt::server::packets
MQTT_CONNECT_FLAGS
#define MQTT_CONNECT_FLAGS
Definition
ControlPacket.h:49
iot::mqtt::server::packets
Definition
Connect.cpp:32
iot
mqtt
server
packets
Connect.cpp
Generated on Mon Feb 10 2025 20:21:13 for SNode.C by
1.11.0