From 33a523eea9a8b56a92722b29401ff94caf955337 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 30 Aug 2018 21:14:38 +0100 Subject: [PATCH] Add identifiers for v5. Clients know about v5, just need library support... --- client/client_shared.c | 2 ++ client/pub_client.c | 2 +- client/sub_client.c | 2 +- lib/handle_pubrel.c | 2 +- lib/mosquitto.h | 1 + lib/mosquitto_internal.h | 3 ++- man/mosquitto_pub.1.xml | 7 ++++--- man/mosquitto_sub.1.xml | 7 ++++--- src/handle_subscribe.c | 6 +++--- src/handle_unsubscribe.c | 4 ++-- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/client_shared.c b/client/client_shared.c index d5d37256..8622cbca 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -655,6 +655,8 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c cfg->protocol_version = MQTT_PROTOCOL_V31; }else if(!strcmp(argv[i+1], "mqttv311")){ cfg->protocol_version = MQTT_PROTOCOL_V311; + }else if(!strcmp(argv[i+1], "mqttv5")){ + cfg->protocol_version = MQTT_PROTOCOL_V5; }else{ fprintf(stderr, "Error: Invalid protocol version argument given.\n\n"); return 1; diff --git a/client/pub_client.c b/client/pub_client.c index 8c729b87..9fb38889 100644 --- a/client/pub_client.c +++ b/client/pub_client.c @@ -257,7 +257,7 @@ void print_usage(void) printf(" -t : mqtt topic to publish to.\n"); printf(" -u : provide a username\n"); printf(" -V : specify the version of the MQTT protocol to use when connecting.\n"); - printf(" Can be mqttv31 or mqttv311. Defaults to mqttv311.\n"); + printf(" Can be mqttv5, mqttv311 or mqttv31. Defaults to mqttv311.\n"); printf(" --help : display this message.\n"); printf(" --quiet : don't print error messages.\n"); printf(" --will-payload : payload for the client Will, which is sent by the broker in case of\n"); diff --git a/client/sub_client.c b/client/sub_client.c index 3d91ed0f..e1180447 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -190,7 +190,7 @@ void print_usage(void) printf(" -U : unsubscribe from a topic. May be repeated.\n"); printf(" -v : print published messages verbosely.\n"); printf(" -V : specify the version of the MQTT protocol to use when connecting.\n"); - printf(" Can be mqttv31 or mqttv311. Defaults to mqttv311.\n"); + printf(" Can be mqttv5, mqttv311 or mqttv31. Defaults to mqttv311.\n"); #ifndef WIN32 printf(" -W : Specifies a timeout in seconds how long to process incoming MQTT messages.\n"); #endif diff --git a/lib/handle_pubrel.c b/lib/handle_pubrel.c index 7c1f137c..4e4bf048 100644 --- a/lib/handle_pubrel.c +++ b/lib/handle_pubrel.c @@ -45,7 +45,7 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq) int rc; assert(mosq); - if(mosq->protocol == mosq_p_mqtt311){ + if(mosq->protocol != mosq_p_mqtt31){ if((mosq->in_packet.command&0x0F) != 0x02){ return MOSQ_ERR_PROTOCOL; } diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 5baa2f15..938382c3 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -101,6 +101,7 @@ enum mosq_opt_t { #define MQTT_PROTOCOL_V31 3 #define MQTT_PROTOCOL_V311 4 +#define MQTT_PROTOCOL_V5 5 struct mosquitto_message{ int mid; diff --git a/lib/mosquitto_internal.h b/lib/mosquitto_internal.h index de82ec3d..d416eccb 100644 --- a/lib/mosquitto_internal.h +++ b/lib/mosquitto_internal.h @@ -115,7 +115,8 @@ enum mosquitto__protocol { mosq_p_invalid = 0, mosq_p_mqtt31 = 1, mosq_p_mqtt311 = 2, - mosq_p_mqtts = 3 + mosq_p_mqtts = 3, + mosq_p_mqtt5 = 4, }; enum mosquitto__threaded_state { diff --git a/man/mosquitto_pub.1.xml b/man/mosquitto_pub.1.xml index ab221c7d..0d6fc314 100644 --- a/man/mosquitto_pub.1.xml +++ b/man/mosquitto_pub.1.xml @@ -11,7 +11,7 @@ mosquitto_pub - an MQTT version 3.1.1/3.1 client for publishing simple messages + an MQTT version 5/3.1.1/3.1 client for publishing simple messages @@ -85,7 +85,7 @@ Description - mosquitto_pub is a simple MQTT version 3.1.1 + mosquitto_pub is a simple MQTT version 5/3.1.1 client that will publish a single message on a topic and exit. @@ -429,7 +429,8 @@ Specify which version of the MQTT protocol should be used when connecting to the rmeote broker. Can be - or . + , or + . Defaults to . diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index 01f9c979..1b83ac81 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -11,7 +11,7 @@ mosquitto_sub - an MQTT version 3.1.1/3.1 client for subscribing to topics + an MQTT version 5/3.1.1/3.1 client for subscribing to topics @@ -87,7 +87,7 @@ Description - mosquitto_sub is a simple MQTT version 3.1.1 + mosquitto_sub is a simple MQTT version 5/3.1.1 client that will subscribe to topics and print the messages that it receives. In addition to subscribing to topics, @@ -525,7 +525,8 @@ Specify which version of the MQTT protocol should be used when connecting to the rmeote broker. Can be - or . + , or + . Defaults to . diff --git a/src/handle_subscribe.c b/src/handle_subscribe.c index 3b2e2591..6f3286e1 100644 --- a/src/handle_subscribe.c +++ b/src/handle_subscribe.c @@ -42,7 +42,7 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) log__printf(NULL, MOSQ_LOG_DEBUG, "Received SUBSCRIBE from %s", context->id); /* FIXME - plenty of potential for memory leaks here */ - if(context->protocol == mosq_p_mqtt311){ + if(context->protocol != mosq_p_mqtt31){ if((context->in_packet.command&0x0F) != 0x02){ return MOSQ_ERR_PROTOCOL; } @@ -111,7 +111,7 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) } log__printf(NULL, MOSQ_LOG_DEBUG, "\t%s (QoS %d)", sub, qos); - if(context->protocol == mosq_p_mqtt311){ + if(context->protocol != mosq_p_mqtt31){ rc = mosquitto_acl_check(db, context, sub, 0, NULL, qos, false, MOSQ_ACL_SUBSCRIBE); switch(rc){ case MOSQ_ERR_SUCCESS: @@ -149,7 +149,7 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) } } - if(context->protocol == mosq_p_mqtt311){ + if(context->protocol != mosq_p_mqtt31){ if(payloadlen == 0){ /* No subscriptions specified, protocol error. */ return MOSQ_ERR_PROTOCOL; diff --git a/src/handle_unsubscribe.c b/src/handle_unsubscribe.c index 76b263ff..4a5bf680 100644 --- a/src/handle_unsubscribe.c +++ b/src/handle_unsubscribe.c @@ -40,14 +40,14 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context) if(!context) return MOSQ_ERR_INVAL; log__printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBSCRIBE from %s", context->id); - if(context->protocol == mosq_p_mqtt311){ + if(context->protocol != mosq_p_mqtt31){ if((context->in_packet.command&0x0F) != 0x02){ return MOSQ_ERR_PROTOCOL; } } if(packet__read_uint16(&context->in_packet, &mid)) return 1; - if(context->protocol == mosq_p_mqtt311){ + if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){ if(context->in_packet.pos == context->in_packet.remaining_length){ /* No topic specified, protocol error. */ return MOSQ_ERR_PROTOCOL;