Merge pull request #633 from frizzy/development

Fixed parsing of subscribed topics containing slashes.
This commit is contained in:
Henrik Ekblad
2016-11-04 23:31:05 +01:00
committed by GitHub
Regular → Executable
+10 -15
View File
@@ -120,40 +120,35 @@ bool protocolMQTTParse(MyMessage &message, char* topic, uint8_t* payload, unsign
uint8_t bvalue[MAX_PAYLOAD]; uint8_t bvalue[MAX_PAYLOAD];
uint8_t blen = 0; uint8_t blen = 0;
uint8_t command = 0; uint8_t command = 0;
if (topic != strstr(topic, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX)) {
for (str = strtok_r(topic, "/", &p); str && i <= 5; // Prefix doesn't match incoming topic
return false;
}
for (str = strtok_r(topic + strlen(MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) + 1, "/", &p); str && i <= 5;
str = strtok_r(NULL, "/", &p)) { str = strtok_r(NULL, "/", &p)) {
switch (i) { switch (i) {
case 0: { case 0: {
// Topic prefix
if (strcmp(str, MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) != 0) {
// Message not for us or malformed!
return false;
}
break;
}
case 1: {
// Node id // Node id
message.destination = atoi(str); message.destination = atoi(str);
break; break;
} }
case 2: { case 1: {
// Sensor id // Sensor id
message.sensor = atoi(str); message.sensor = atoi(str);
break; break;
} }
case 3: { case 2: {
// Command type // Command type
command = atoi(str); command = atoi(str);
mSetCommand(message, command); mSetCommand(message, command);
break; break;
} }
case 4: { case 3: {
// Ack flag // Ack flag
mSetRequestAck(message, atoi(str)?1:0); mSetRequestAck(message, atoi(str)?1:0);
break; break;
} }
case 5: { case 4: {
// Sub type // Sub type
message.type = atoi(str); message.type = atoi(str);
break; break;
@@ -162,7 +157,7 @@ bool protocolMQTTParse(MyMessage &message, char* topic, uint8_t* payload, unsign
i++; i++;
} }
if (i != 6) { if (i != 5) {
return false; return false;
} }