Commit dec5bcc5 authored by Alessio Netti's avatar Alessio Netti
Browse files

Minor improvements to parsing of MQTT CONNECT messages

parent 28944306
......@@ -208,19 +208,23 @@ ssize_t SimpleMQTTMessage::receiveMessage(void* buf, size_t len)
// Message is malformed, break out
if(remainingLength < 12) {
break;
state = Error;
} else {
ssize_t idLen = ntohs(((uint16_t *) data)[0]);
data += 2;
// Leveraging the topic field to store also the client ID on CONNECT messages
if (idLen > 0) {
topic = string(data, idLen);
data += idLen;
} else {
topic = "";
}
// We store the rest of the CONNECT payload in its raw form
payloadPtr = (void *) data;
payloadLength = remainingLength - ((uint8_t *) payloadPtr - (uint8_t *) remainingRaw);
}
ssize_t idLen = ntohs(((uint16_t*) data)[0]);
data+= 2;
// Leveraging the topic field to store also the client ID on CONNECT messages
topic = string(data, idLen);
data+= idLen;
// We store the rest of the CONNECT payload in its raw form
payloadPtr = (void*) data;
payloadLength = remainingLength - ((uint8_t*)payloadPtr - (uint8_t*)remainingRaw);
break;
}
case MQTT_PUBREL: {
......
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