diff --git a/client/client_props.c b/client/client_props.c index de9db8e3..93ce27f8 100644 --- a/client/client_props.c +++ b/client/client_props.c @@ -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: diff --git a/client/sub_client.c b/client/sub_client.c index 355d2bb1..d86f7e01 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -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; isock == 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); } diff --git a/lib/linker.version b/lib/linker.version index 83476ccc..499aa303 100644 --- a/lib/linker.version +++ b/lib/linker.version @@ -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; diff --git a/lib/mosquitto.h b/lib/mosquitto.h index fd658e4d..b5eba8af 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -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); + /* ====================================================================== * diff --git a/lib/send_mosq.h b/lib/send_mosq.h index 68d11899..094c782c 100644 --- a/lib/send_mosq.h +++ b/lib/send_mosq.h @@ -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 diff --git a/lib/send_unsubscribe.c b/lib/send_unsubscribe.c index 105a7d79..a3e75251 100644 --- a/lib/send_unsubscribe.c +++ b/lib/send_unsubscribe.c @@ -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); diff --git a/src/handle_connack.c b/src/handle_connack.c index c04625ae..038dab0e 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -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. */