From ff676811d3a97310a2b4c72ed1c925ab313c7907 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 4 Sep 2019 15:56:13 +0100 Subject: [PATCH] Client no longer generates random client ids for v3.1.1 clients These are now expected to be generated on the broker. This matches the behaviour for v5 clients. Closes #291. --- ChangeLog.txt | 5 +++++ lib/connect.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f580c42d..d58fd4f0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,11 @@ Broker: then try "nobody" instead. This reduces the burden on users installing Mosquitto themselves. +Client library: +- Client no longer generates random client ids for v3.1.1 clients, these are + now expected to be generated on the broker. This matches the behaviour for + v5 clients. Closes #291. + Clients: - Add timeout return code (27) for `mosquitto_sub -W ` and `mosquitto_rr -W `. Closes #275. diff --git a/lib/connect.c b/lib/connect.c index 8559cd72..60672d9c 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -44,7 +44,8 @@ static int mosquitto__connect_init(struct mosquitto *mosq, const char *host, int if(!mosq) return MOSQ_ERR_INVAL; if(!host || port <= 0) return MOSQ_ERR_INVAL; - if(mosq->id == NULL && (mosq->protocol == mosq_p_mqtt31 || mosq->protocol == mosq_p_mqtt311)){ + /* Only MQTT v3.1 requires a client id to be sent */ + if(mosq->id == NULL && (mosq->protocol == mosq_p_mqtt31)){ mosq->id = (char *)mosquitto__calloc(24, sizeof(char)); if(!mosq->id){ return MOSQ_ERR_NOMEM;