Add `mosquitto_client_protocol_version()` function.

This can be used by plugins to determine which version of MQTT a client
has connected with.
pull/1753/head
Roger A. Light 5 years ago
parent abc191ad00
commit f46187d5e5

@ -14,6 +14,8 @@ Broker:
Closes #1735.
- Add `mosquitto_plugin_publish()` function, which can be used by plugins to
publish messages.
- Add `mosquitto_client_protocol_version()` function which can be used by
plugins to determine which version of MQTT a client has connected with.
Client library:
- Client no longer generates random client ids for v3.1.1 clients, these are

@ -5,6 +5,7 @@ _mosquitto_client_id
_mosquitto_client_keepalive
_mosquitto_client_certificate
_mosquitto_client_protocol
_mosquitto_client_protocol_version
_mosquitto_client_sub_count
_mosquitto_client_username
_mosquitto_set_username

@ -5,6 +5,7 @@
mosquitto_client_id;
mosquitto_client_keepalive;
mosquitto_client_protocol;
mosquitto_client_protocol_version;
mosquitto_client_sub_count;
mosquitto_client_username;
mosquitto_log_printf;

@ -131,6 +131,18 @@ void *mosquitto_client_certificate(const struct mosquitto *client);
int mosquitto_client_protocol(const struct mosquitto *client);
/*
* Function: mosquitto_client_protocol_version
*
* Retrieve the MQTT protocol version with which the client has connected. Can be one of:
*
* 3 - for MQTT v3 / v3.1
* 4 - for MQTT v3.1.1
* 5 - for MQTT v5
*/
int mosquitto_client_protocol_version(const struct mosquitto *client);
/*
* Function: mosquitto_client_sub_count
*

@ -77,6 +77,21 @@ int mosquitto_client_protocol(const struct mosquitto *client)
}
int mosquitto_client_protocol_version(const struct mosquitto *client)
{
switch(client->protocol){
case mosq_p_mqtt31:
return 3;
case mosq_p_mqtt311:
return 4;
case mosq_p_mqtt5:
return 5;
default:
return 0;
}
}
int mosquitto_client_sub_count(const struct mosquitto *client)
{
return client->sub_count;

Loading…
Cancel
Save