mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-03 13:28:44 +00:00
Move mg_mqtt_next-* to the example, and some nits
This commit is contained in:
1 parent
ffa033cca9
commit
c7b9ca68c2
10 files changed
+45
-150
No files matched your search
-26
@@ -185,32 +185,6 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
|
||||
return MQTT_OK;
|
||||
}
|
||||
|
||||
static size_t mg_mqtt_next_topic(struct mg_mqtt_message *msg,
|
||||
struct mg_str *topic, uint8_t *qos,
|
||||
size_t pos) {
|
||||
unsigned char *buf = (unsigned char *) msg->dgram.ptr + pos;
|
||||
size_t new_pos;
|
||||
if (pos >= msg->dgram.len) return 0;
|
||||
|
||||
topic->len = (size_t) (((unsigned) buf[0]) << 8 | buf[1]);
|
||||
topic->ptr = (char *) buf + 2;
|
||||
new_pos = pos + 2 + topic->len + (qos == NULL ? 0 : 1);
|
||||
if ((size_t) new_pos > msg->dgram.len) return 0;
|
||||
if (qos != NULL) *qos = buf[2 + topic->len];
|
||||
return new_pos;
|
||||
}
|
||||
|
||||
size_t mg_mqtt_next_sub(struct mg_mqtt_message *msg, struct mg_str *topic,
|
||||
uint8_t *qos, size_t pos) {
|
||||
uint8_t tmp;
|
||||
return mg_mqtt_next_topic(msg, topic, qos == NULL ? &tmp : qos, pos);
|
||||
}
|
||||
|
||||
size_t mg_mqtt_next_unsub(struct mg_mqtt_message *msg, struct mg_str *topic,
|
||||
size_t pos) {
|
||||
return mg_mqtt_next_topic(msg, topic, NULL, pos);
|
||||
}
|
||||
|
||||
static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
if (ev == MG_EV_READ) {
|
||||
|
||||
Reference in new issue
Block a user