Skip to content
Snippets Groups Projects
Commit 2b48e8b0 authored by Sergey Lyubka's avatar Sergey Lyubka
Browse files

Send suback

parent a7afea09
No related branches found
No related tags found
No related merge requests found
...@@ -42,8 +42,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { ...@@ -42,8 +42,9 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
case MQTT_CMD_SUBSCRIBE: { case MQTT_CMD_SUBSCRIBE: {
// Client subscribes // Client subscribes
size_t pos = 4; // Initial topic offset, where ID ends size_t pos = 4; // Initial topic offset, where ID ends
uint8_t qos; uint8_t qos, resp[256];
struct mg_str topic; struct mg_str topic;
int num_topics = 0;
while ((pos = mg_mqtt_next_sub(mm, &topic, &qos, pos)) > 0) { while ((pos = mg_mqtt_next_sub(mm, &topic, &qos, pos)) > 0) {
struct sub *sub = calloc(1, sizeof(*sub)); struct sub *sub = calloc(1, sizeof(*sub));
sub->c = c; sub->c = c;
...@@ -52,7 +53,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { ...@@ -52,7 +53,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
LIST_ADD_HEAD(struct sub, &s_subs, sub); LIST_ADD_HEAD(struct sub, &s_subs, sub);
LOG(LL_INFO, LOG(LL_INFO,
("SUB %p [%.*s]", c->fd, (int) sub->topic.len, sub->topic.ptr)); ("SUB %p [%.*s]", c->fd, (int) sub->topic.len, sub->topic.ptr));
resp[num_topics++] = qos;
} }
mg_mqtt_send_header(c, MQTT_CMD_SUBACK, 0, num_topics + 2);
uint16_t id = mg_htons(mm->id);
mg_send(c, &id, 2);
mg_send(c, resp, num_topics);
break; break;
} }
case MQTT_CMD_PUBLISH: { case MQTT_CMD_PUBLISH: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment