diff --git a/src/subs.c b/src/subs.c index 6194059f..9b5f0800 100644 --- a/src/subs.c +++ b/src/subs.c @@ -229,6 +229,19 @@ static int _sub_add(struct mosquitto_db *db, struct mosquitto *context, int qos, leaf = subhier->subs; last_leaf = NULL; while(leaf){ + if(leaf->context && leaf->context->id && !strcmp(leaf->context->id, context->id)){ + /* Client making a second subscription to same topic. Only + * need to update QoS. Return -1 to indicate this to the + * calling function. */ + leaf->qos = qos; + if(context->protocol == mosq_p_mqtt31){ + return -1; + }else{ + /* mqttv311 requires retained messages are resent on + * resubscribe. */ + return 0; + } + } last_leaf = leaf; leaf = leaf->next; }