Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
a447ae5e
Commit
a447ae5e
authored
Dec 13, 2016
by
Sergey Lyubka
Committed by
Cesanta Bot
Dec 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MQTT parsing fix
PUBLISHED_FROM=41f43cb0e707259740de3346308f746c2a3778fd
parent
54ad1e4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
18 deletions
+21
-18
mqtt_client.c
examples/mqtt_client/mqtt_client.c
+10
-12
mongoose.c
mongoose.c
+11
-6
No files found.
examples/mqtt_client/mqtt_client.c
View file @
a447ae5e
...
...
@@ -20,8 +20,8 @@
static
const
char
*
s_address
=
"localhost:1883"
;
static
const
char
*
s_user_name
=
NULL
;
static
const
char
*
s_password
=
NULL
;
st
ruct
mg_mqtt_topic_expression
topic_expressions
[]
=
{{
"/stuff"
,
0
}
};
static
const
char
*
s_topic
=
"/stuff"
;
st
atic
struct
mg_mqtt_topic_expression
s_topic_expr
=
{
NULL
,
0
};
static
void
ev_handler
(
struct
mg_connection
*
nc
,
int
ev
,
void
*
p
)
{
struct
mg_mqtt_message
*
msg
=
(
struct
mg_mqtt_message
*
)
p
;
...
...
@@ -48,10 +48,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
printf
(
"Got mqtt connection error: %d
\n
"
,
msg
->
connack_ret_code
);
exit
(
1
);
}
printf
(
"Subscribing to '/stuff'
\n
"
);
mg_mqtt_subscribe
(
nc
,
topic_expressions
,
sizeof
(
topic_expressions
)
/
sizeof
(
*
topic_expressions
),
42
);
s_topic_expr
.
topic
=
s_topic
;
printf
(
"Subscribing to '%s'
\n
"
,
s_topic
);
mg_mqtt_subscribe
(
nc
,
&
s_topic_expr
,
1
,
42
);
break
;
case
MG_EV_MQTT_PUBACK
:
printf
(
"Message publishing acknowledged (msg_id: %d)
\n
"
,
msg
->
message_id
);
...
...
@@ -89,14 +88,13 @@ int main(int argc, char **argv) {
/* Parse command line arguments */
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
strcmp
(
argv
[
i
],
"-h"
)
==
0
)
{
s_address
=
argv
[
i
+
1
];
i
++
;
s_address
=
argv
[
++
i
];
}
else
if
(
strcmp
(
argv
[
i
],
"-u"
)
==
0
)
{
s_user_name
=
argv
[
i
+
1
];
i
++
;
s_user_name
=
argv
[
++
i
];
}
else
if
(
strcmp
(
argv
[
i
],
"-t"
)
==
0
)
{
s_topic
=
argv
[
++
i
];
}
else
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
)
{
s_password
=
argv
[
i
+
1
];
i
++
;
s_password
=
argv
[
++
i
];
}
}
...
...
mongoose.c
View file @
a447ae5e
...
...
@@ -9541,10 +9541,15 @@ void mg_basic_auth_header(const char *user, const char *pass,
/* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/mqtt.h" */
static
uint16_t
getu16
(
const
char
*
p
)
{
const
uint8_t
*
up
=
(
const
uint8_t
*
)
p
;
return
(
up
[
0
]
<<
8
)
+
up
[
1
];
}
static
const
char
*
scanto
(
const
char
*
p
,
struct
mg_str
*
s
)
{
s
->
len
=
ntohs
(
*
(
uint16_t
*
)
p
);
s
->
len
=
getu16
(
p
);
s
->
p
=
p
+
2
;
return
p
+
2
+
s
->
len
;
return
s
->
p
+
s
->
len
;
}
MG_INTERNAL
int
parse_mqtt
(
struct
mbuf
*
io
,
struct
mg_mqtt_message
*
mm
)
{
...
...
@@ -9575,7 +9580,7 @@ MG_INTERNAL int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
p
=
scanto
(
p
,
&
mm
->
protocol_name
);
mm
->
protocol_version
=
*
(
uint8_t
*
)
p
++
;
mm
->
connect_flags
=
*
(
uint8_t
*
)
p
++
;
mm
->
keep_alive_timer
=
ntohs
(
*
(
uint16_t
*
)
p
);
mm
->
keep_alive_timer
=
getu16
(
p
);
p
+=
2
;
if
(
p
<
end
)
p
=
scanto
(
p
,
&
mm
->
client_id
);
if
(
p
<
end
&&
(
mm
->
connect_flags
&
MG_MQTT_HAS_WILL
))
...
...
@@ -9606,11 +9611,11 @@ MG_INTERNAL int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
case
MG_MQTT_CMD_PUBREL
:
case
MG_MQTT_CMD_PUBCOMP
:
case
MG_MQTT_CMD_SUBACK
:
mm
->
message_id
=
ntohs
(
*
(
uint16_t
*
)
p
);
mm
->
message_id
=
getu16
(
p
);
break
;
case
MG_MQTT_CMD_PUBLISH
:
{
if
(
MG_MQTT_GET_QOS
(
header
)
>
0
)
{
mm
->
message_id
=
ntohs
(
*
(
uint16_t
*
)
io
->
buf
);
mm
->
message_id
=
getu16
(
p
);
p
+=
2
;
}
p
=
scanto
(
p
,
&
mm
->
topic
);
...
...
@@ -9620,7 +9625,7 @@ MG_INTERNAL int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
break
;
}
case
MG_MQTT_CMD_SUBSCRIBE
:
mm
->
message_id
=
ntohs
(
*
(
uint16_t
*
)
p
);
mm
->
message_id
=
getu16
(
p
);
p
+=
2
;
/*
* topic expressions are left in the payload and can be parsed with
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment