Skip to content

Commit

Permalink
Drop requests without src (#5)
Browse files Browse the repository at this point in the history
* Drop requests without src
  • Loading branch information
iliapenev authored Jun 19, 2021
1 parent d157017 commit 20511b1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/mgos_rpc_channel_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ static void mgos_rpc_mqtt_sub_handler(struct mg_connection *nc, int ev,
return;
}
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) ev_data;

struct json_token id = JSON_INVALID_TOKEN;
struct json_token src = JSON_INVALID_TOKEN;
struct json_token method = JSON_INVALID_TOKEN;

if (json_scanf(msg->payload.p, msg->payload.len, "{id:%T src:%T method:%T}",
&id, &src, &method) < 1) {
return;
}

if (method.len > 0 && id.len > 0 && src.len == 0) {
LOG(LL_ERROR, ("Drop frame without src"));
return;
}

if (chd->sub_topic_len == msg->topic.len) {
ch->ev_handler(ch, MG_RPC_CHANNEL_FRAME_RECD, &msg->payload);
} else {
Expand Down

0 comments on commit 20511b1

Please sign in to comment.