summaryrefslogtreecommitdiff
path: root/lib/mqtt.h
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-04-16 13:20:52 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-04-20 08:09:33 +0200
commit5811beba391baefad41cd6f8f4fa4e3862098813 (patch)
tree572fc2d609408300d6d4946476d5f2f41d09e96e /lib/mqtt.h
parentd1a2816b4128faa8ebc50ce93285c7364652856e (diff)
downloadcurl-5811beba391baefad41cd6f8f4fa4e3862098813.tar.gz
mqtt: improve the state machine
To handle PUBLISH before SUBACK and more. Updated the existing tests and added three new ones. Reported-by: Christoph Krey Bug: https://curl.haxx.se/mail/lib-2020-04/0021.html Closes #5246
Diffstat (limited to 'lib/mqtt.h')
-rw-r--r--lib/mqtt.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/mqtt.h b/lib/mqtt.h
index b5e447be5..155fbd60a 100644
--- a/lib/mqtt.h
+++ b/lib/mqtt.h
@@ -26,13 +26,22 @@
extern const struct Curl_handler Curl_handler_mqtt;
#endif
+enum mqttstate {
+ MQTT_FIRST, /* 0 */
+ MQTT_REMAINING_LENGTH, /* 1 */
+ MQTT_CONNACK, /* 2 */
+ MQTT_SUBACK, /* 3 */
+ MQTT_SUBACK_COMING, /* 4 - the SUBACK remainder */
+ MQTT_PUBWAIT, /* 5 - wait for publish */
+ MQTT_PUB_REMAIN, /* 6 - wait for the remainder of the publish */
+
+ MQTT_NOSTATE = 99 /* never an actual state */
+};
+
struct mqtt_conn {
- enum {
- MQTT_CONNACK,
- MQTT_SUBACK,
- MQTT_SUBWAIT, /* wait for subscribe response */
- MQTT_SUB_REMAIN /* wait for the remainder of the subscribe response */
- } state;
+ enum mqttstate state;
+ enum mqttstate nextstate; /* switch to this after remaining length is
+ done */
unsigned int packetid;
};
@@ -41,9 +50,10 @@ struct MQTT {
char *sendleftovers;
size_t nsend; /* size of sendleftovers */
- /* when receving a PUBLISH */
+ /* when receving */
size_t npacket; /* byte counter */
unsigned char firstbyte;
+ size_t remaining_length;
};
#endif /* HEADER_CURL_MQTT_H */