Add identifiers for v5.

Clients know about v5, just need library support...
This commit is contained in:
Roger A. Light 2018-08-30 21:14:38 +01:00
parent a127c93a5a
commit 33a523eea9
10 changed files with 21 additions and 15 deletions

View File

@ -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;

View File

@ -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");

View File

@ -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

View File

@ -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;
}

View File

@ -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;

View File

@ -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 {

View File

@ -11,7 +11,7 @@
<refnamediv>
<refname>mosquitto_pub</refname>
<refpurpose>an MQTT version 3.1.1/3.1 client for publishing simple messages</refpurpose>
<refpurpose>an MQTT version 5/3.1.1/3.1 client for publishing simple messages</refpurpose>
</refnamediv>
<refsynopsisdiv>
@ -85,7 +85,7 @@
<refsect1>
<title>Description</title>
<para><command>mosquitto_pub</command> is a simple MQTT version 3.1.1
<para><command>mosquitto_pub</command> is a simple MQTT version 5/3.1.1
client that will publish a single message on a topic and
exit.</para>
</refsect1>
@ -429,7 +429,8 @@
<listitem>
<para>Specify which version of the MQTT protocol should be
used when connecting to the rmeote broker. Can be
<option>mqttv311</option> or <option>mqttv31</option>.
<option>mqttv5</option>, <option>mqttv311</option> or
<option>mqttv31</option>.
Defaults to <option>mqttv311</option>.</para>
</listitem>
</varlistentry>

View File

@ -11,7 +11,7 @@
<refnamediv>
<refname>mosquitto_sub</refname>
<refpurpose>an MQTT version 3.1.1/3.1 client for subscribing to topics</refpurpose>
<refpurpose>an MQTT version 5/3.1.1/3.1 client for subscribing to topics</refpurpose>
</refnamediv>
<refsynopsisdiv>
@ -87,7 +87,7 @@
<refsect1>
<title>Description</title>
<para><command>mosquitto_sub</command> is a simple MQTT version 3.1.1
<para><command>mosquitto_sub</command> is a simple MQTT version 5/3.1.1
client that will subscribe to topics and print the messages that
it receives.</para>
<para>In addition to subscribing to topics,
@ -525,7 +525,8 @@
<listitem>
<para>Specify which version of the MQTT protocol should be
used when connecting to the rmeote broker. Can be
<option>mqttv311</option> or <option>mqttv31</option>.
<option>mqttv5</option>, <option>mqttv311</option> or
<option>mqttv31</option>.
Defaults to <option>mqttv311</option>.</para>
</listitem>
</varlistentry>

View File

@ -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;

View File

@ -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;