Client+library support for unsubscribe properties.

pull/1022/head
Roger A. Light 7 years ago
parent 49a8642986
commit de3a9af1f7

@ -128,7 +128,7 @@ int cfg_parse_property(struct mosq_config *cfg, int argc, char *argv[], int *idx
break;
case CMD_UNSUBSCRIBE:
proplist = &cfg->subscribe_props;
proplist = &cfg->unsubscribe_props;
break;
case CMD_DISCONNECT:

@ -92,7 +92,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.subscribe_props);
for(i=0; i<cfg.unsub_topic_count; i++){
mosquitto_unsubscribe(mosq, NULL, cfg.unsub_topics[i]);
mosquitto_unsubscribe_with_properties(mosq, NULL, cfg.unsub_topics[i], cfg.unsubscribe_props);
}
}else{
if(result && !cfg.quiet){

@ -137,6 +137,11 @@ int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count
int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub)
{
return mosquitto_unsubscribe_with_properties(mosq, mid, sub, NULL);
}
int mosquitto_unsubscribe_with_properties(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties)
{
if(!mosq) return MOSQ_ERR_INVAL;
if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN;
@ -144,6 +149,6 @@ int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub)
if(mosquitto_sub_topic_check(sub)) return MOSQ_ERR_INVAL;
if(mosquitto_validate_utf8(sub, strlen(sub))) return MOSQ_ERR_MALFORMED_UTF8;
return send__unsubscribe(mosq, mid, sub);
return send__unsubscribe(mosq, mid, sub, properties);
}

@ -109,5 +109,7 @@ MOSQ_1.6 {
mosquitto_string_to_command;
mosquitto_string_to_property_info;
mosquitto_subscribe_multiple;
mosquitto_subscribe_with_properties;
mosquitto_unsubscribe_with_properties;
mosquitto_will_set_with_properties;
} MOSQ_1.5;

@ -892,6 +892,30 @@ int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count
*/
libmosq_EXPORT int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub);
/*
* Function: mosquitto_unsubscribe_with_properties
*
* Unsubscribe from a topic, with attached MQTT properties.
*
* Parameters:
* mosq - a valid mosquitto instance.
* mid - a pointer to an int. If not NULL, the function will set this to
* the message id of this particular message. This can be then used
* with the unsubscribe callback to determine when the message has been
* sent.
* sub - the unsubscription pattern.
* properties - a valid mosquitto_property list, or NULL. Only used with MQTT
* v5 clients.
*
* Returns:
* MOSQ_ERR_SUCCESS - on success.
* MOSQ_ERR_INVAL - if the input parameters were invalid.
* MOSQ_ERR_NOMEM - if an out of memory condition occurred.
* MOSQ_ERR_NO_CONN - if the client isn't connected to a broker.
* MOSQ_ERR_MALFORMED_UTF8 - if the topic is not valid UTF-8
*/
libmosq_EXPORT int mosquitto_unsubscribe_with_properties(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties);
/* ======================================================================
*

@ -33,6 +33,6 @@ int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint3
int send__pubrec(struct mosquitto *mosq, uint16_t mid);
int send__pubrel(struct mosquitto *mosq, uint16_t mid);
int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, int topic_qos, const struct mqtt5__property *properties);
int send__unsubscribe(struct mosquitto *mosq, int *mid, const char *topic);
int send__unsubscribe(struct mosquitto *mosq, int *mid, const char *topic, const mosquitto_property *properties);
#endif

@ -29,17 +29,17 @@ Contributors:
#include "mqtt_protocol.h"
#include "packet_mosq.h"
#include "property_mosq.h"
#include "send_mosq.h"
#include "util_mosq.h"
int send__unsubscribe(struct mosquitto *mosq, int *mid, const char *topic)
int send__unsubscribe(struct mosquitto *mosq, int *mid, const char *topic, const mosquitto_property *properties)
{
/* FIXME - only deals with a single topic */
struct mosquitto__packet *packet = NULL;
uint32_t packetlen;
uint16_t local_mid;
int rc;
struct mqtt5__property *properties = NULL;
int proplen, varbytes;
assert(mosq);

@ -91,7 +91,7 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
}
}else{
if(context->bridge->attempt_unsubscribe){
if(send__unsubscribe(context, NULL, context->bridge->topics[i].remote_topic)){
if(send__unsubscribe(context, NULL, context->bridge->topics[i].remote_topic, NULL)){
/* direction = inwards only. This means we should not be subscribed
* to the topic. It is possible that we used to be subscribed to
* this topic so unsubscribe. */

Loading…
Cancel
Save