Commit a43709b4 authored by Marko Mikulicic's avatar Marko Mikulicic

Fix MQTT parsing of nullary commands

Closes cesanta/smart.js#619
Also http://forum.cesanta.com/index.php?p=/discussion/35/mixing-up-http-and-mqtt&#

PUBLISHED_FROM=ee040880b75048192c111c602610460071f33066
parent e95c0749
......@@ -118,6 +118,11 @@ struct ctl_msg {
char message[MG_CTL_MSG_MESSAGE_SIZE];
};
#ifndef MG_DISABLE_MQTT
struct mg_mqtt_message;
MG_INTERNAL int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm);
#endif
/* Forward declarations for testing. */
extern void *(*test_malloc)(size_t size);
extern void *(*test_calloc)(size_t count, size_t size);
......@@ -8245,7 +8250,7 @@ int mg_rpc_parse_reply(const char *buf, int len, struct json_token *toks,
/* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/mqtt.h" */
static int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
MG_INTERNAL int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
uint8_t header;
int cmd;
size_t len = 0;
......@@ -8262,7 +8267,7 @@ static int parse_mqtt(struct mbuf *io, struct mg_mqtt_message *mm) {
len += (*vlen & 127) << 7 * (vlen - &io->buf[1]);
} while ((*vlen++ & 128) != 0 && ((size_t)(vlen - io->buf) <= io->len));
if (io->len < (size_t)(len - 1)) return -1;
if (len != 0 && io->len < (size_t)(len - 1)) return -1;
mbuf_remove(io, 1 + (vlen - &io->buf[1]));
mm->cmd = cmd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment