mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 23:49:44 +08:00
Add MQTT version check
This commit is contained in:
parent
c7bd63ef53
commit
9b6b1a68f4
@ -1,7 +1,7 @@
|
|||||||
PROG ?= example
|
PROG ?= example
|
||||||
|
|
||||||
all: $(PROG)
|
all: $(PROG)
|
||||||
$(DEBUGGER) ./$(PROG) $(ARGS)
|
$(RUN) ./$(PROG) $(ARGS)
|
||||||
|
|
||||||
$(PROG): main.c
|
$(PROG): main.c
|
||||||
$(CC) ../../mongoose.c -I../.. -W -Wall -DMG_ENABLE_LINES=1 $(CFLAGS) -o $(PROG) main.c
|
$(CC) ../../mongoose.c -I../.. -W -Wall -DMG_ENABLE_LINES=1 $(CFLAGS) -o $(PROG) main.c
|
||||||
|
@ -27,15 +27,21 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
LOG(LL_DEBUG, ("cmd %d qos %d", mm->cmd, mm->qos));
|
LOG(LL_DEBUG, ("cmd %d qos %d", mm->cmd, mm->qos));
|
||||||
switch (mm->cmd) {
|
switch (mm->cmd) {
|
||||||
case MQTT_CMD_CONNECT: {
|
case MQTT_CMD_CONNECT: {
|
||||||
// Client connects. Return success, do not check user/password
|
// Client connects
|
||||||
uint8_t response[] = {0, 0};
|
if (mm->dgram.len < 9) {
|
||||||
mg_mqtt_send_header(c, MQTT_CMD_CONNACK, 0, sizeof(response));
|
mg_error(c, "Malformed MQTT frame");
|
||||||
mg_send(c, response, sizeof(response));
|
} else if (mm->dgram.ptr[8] != 4) {
|
||||||
|
mg_error(c, "Unsupported MQTT version %d", mm->dgram.ptr[8]);
|
||||||
|
} else {
|
||||||
|
uint8_t response[] = {0, 0};
|
||||||
|
mg_mqtt_send_header(c, MQTT_CMD_CONNACK, 0, sizeof(response));
|
||||||
|
mg_send(c, response, sizeof(response));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MQTT_CMD_SUBSCRIBE: {
|
case MQTT_CMD_SUBSCRIBE: {
|
||||||
// Client subscribes
|
// Client subscribes
|
||||||
int pos = 4; // Initial topic offset, where ID ends
|
size_t pos = 4; // Initial topic offset, where ID ends
|
||||||
uint8_t qos;
|
uint8_t qos;
|
||||||
struct mg_str topic;
|
struct mg_str topic;
|
||||||
while ((pos = mg_mqtt_next_sub(mm, &topic, &qos, pos)) > 0) {
|
while ((pos = mg_mqtt_next_sub(mm, &topic, &qos, pos)) > 0) {
|
||||||
@ -60,6 +66,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (ev == MG_EV_ACCEPT) {
|
||||||
|
// c->is_hexdumping = 1;
|
||||||
} else if (ev == MG_EV_CLOSE) {
|
} else if (ev == MG_EV_CLOSE) {
|
||||||
// Client disconnects. Remove from the subscription list
|
// Client disconnects. Remove from the subscription list
|
||||||
for (struct sub *next, *sub = s_subs; sub != NULL; sub = next) {
|
for (struct sub *next, *sub = s_subs; sub != NULL; sub = next) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user