Add identifiers for v5.

Clients know about v5, just need library support...
pull/1022/head
Roger A. Light 7 years ago
parent a127c93a5a
commit 33a523eea9

@ -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; cfg->protocol_version = MQTT_PROTOCOL_V31;
}else if(!strcmp(argv[i+1], "mqttv311")){ }else if(!strcmp(argv[i+1], "mqttv311")){
cfg->protocol_version = MQTT_PROTOCOL_V311; cfg->protocol_version = MQTT_PROTOCOL_V311;
}else if(!strcmp(argv[i+1], "mqttv5")){
cfg->protocol_version = MQTT_PROTOCOL_V5;
}else{ }else{
fprintf(stderr, "Error: Invalid protocol version argument given.\n\n"); fprintf(stderr, "Error: Invalid protocol version argument given.\n\n");
return 1; return 1;

@ -257,7 +257,7 @@ void print_usage(void)
printf(" -t : mqtt topic to publish to.\n"); printf(" -t : mqtt topic to publish to.\n");
printf(" -u : provide a username\n"); printf(" -u : provide a username\n");
printf(" -V : specify the version of the MQTT protocol to use when connecting.\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(" --help : display this message.\n");
printf(" --quiet : don't print error messages.\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"); printf(" --will-payload : payload for the client Will, which is sent by the broker in case of\n");

@ -190,7 +190,7 @@ void print_usage(void)
printf(" -U : unsubscribe from a topic. May be repeated.\n"); printf(" -U : unsubscribe from a topic. May be repeated.\n");
printf(" -v : print published messages verbosely.\n"); printf(" -v : print published messages verbosely.\n");
printf(" -V : specify the version of the MQTT protocol to use when connecting.\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 #ifndef WIN32
printf(" -W : Specifies a timeout in seconds how long to process incoming MQTT messages.\n"); printf(" -W : Specifies a timeout in seconds how long to process incoming MQTT messages.\n");
#endif #endif

@ -45,7 +45,7 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
int rc; int rc;
assert(mosq); assert(mosq);
if(mosq->protocol == mosq_p_mqtt311){ if(mosq->protocol != mosq_p_mqtt31){
if((mosq->in_packet.command&0x0F) != 0x02){ if((mosq->in_packet.command&0x0F) != 0x02){
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;
} }

@ -101,6 +101,7 @@ enum mosq_opt_t {
#define MQTT_PROTOCOL_V31 3 #define MQTT_PROTOCOL_V31 3
#define MQTT_PROTOCOL_V311 4 #define MQTT_PROTOCOL_V311 4
#define MQTT_PROTOCOL_V5 5
struct mosquitto_message{ struct mosquitto_message{
int mid; int mid;

@ -115,7 +115,8 @@ enum mosquitto__protocol {
mosq_p_invalid = 0, mosq_p_invalid = 0,
mosq_p_mqtt31 = 1, mosq_p_mqtt31 = 1,
mosq_p_mqtt311 = 2, mosq_p_mqtt311 = 2,
mosq_p_mqtts = 3 mosq_p_mqtts = 3,
mosq_p_mqtt5 = 4,
}; };
enum mosquitto__threaded_state { enum mosquitto__threaded_state {

@ -11,7 +11,7 @@
<refnamediv> <refnamediv>
<refname>mosquitto_pub</refname> <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> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
@ -85,7 +85,7 @@
<refsect1> <refsect1>
<title>Description</title> <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 client that will publish a single message on a topic and
exit.</para> exit.</para>
</refsect1> </refsect1>
@ -429,7 +429,8 @@
<listitem> <listitem>
<para>Specify which version of the MQTT protocol should be <para>Specify which version of the MQTT protocol should be
used when connecting to the rmeote broker. Can 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> Defaults to <option>mqttv311</option>.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

@ -11,7 +11,7 @@
<refnamediv> <refnamediv>
<refname>mosquitto_sub</refname> <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> </refnamediv>
<refsynopsisdiv> <refsynopsisdiv>
@ -87,7 +87,7 @@
<refsect1> <refsect1>
<title>Description</title> <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 client that will subscribe to topics and print the messages that
it receives.</para> it receives.</para>
<para>In addition to subscribing to topics, <para>In addition to subscribing to topics,
@ -525,7 +525,8 @@
<listitem> <listitem>
<para>Specify which version of the MQTT protocol should be <para>Specify which version of the MQTT protocol should be
used when connecting to the rmeote broker. Can 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> Defaults to <option>mqttv311</option>.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

@ -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); log__printf(NULL, MOSQ_LOG_DEBUG, "Received SUBSCRIBE from %s", context->id);
/* FIXME - plenty of potential for memory leaks here */ /* 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){ if((context->in_packet.command&0x0F) != 0x02){
return MOSQ_ERR_PROTOCOL; 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); 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); rc = mosquitto_acl_check(db, context, sub, 0, NULL, qos, false, MOSQ_ACL_SUBSCRIBE);
switch(rc){ switch(rc){
case MOSQ_ERR_SUCCESS: 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){ if(payloadlen == 0){
/* No subscriptions specified, protocol error. */ /* No subscriptions specified, protocol error. */
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;

@ -40,14 +40,14 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
if(!context) return MOSQ_ERR_INVAL; if(!context) return MOSQ_ERR_INVAL;
log__printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBSCRIBE from %s", context->id); 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){ if((context->in_packet.command&0x0F) != 0x02){
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;
} }
} }
if(packet__read_uint16(&context->in_packet, &mid)) return 1; 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){ if(context->in_packet.pos == context->in_packet.remaining_length){
/* No topic specified, protocol error. */ /* No topic specified, protocol error. */
return MOSQ_ERR_PROTOCOL; return MOSQ_ERR_PROTOCOL;

Loading…
Cancel
Save