diff --git a/ChangeLog.txt b/ChangeLog.txt index 4a978f30..963e67af 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -12,6 +12,7 @@ Broker: - Fix incorrect $SYS heap memory reporting when using ACLs. - Bridge config parameters couldn't contain a space, this has been fixed. Closes #150. +- Fix saving of persistence messages that start with a '/'. Closes #151. - Fix reconnecting for bridges that use TLS on Windows. Closes #154. Client library: diff --git a/src/persist.c b/src/persist.c index 176d6e81..3c37b80b 100644 --- a/src/persist.c +++ b/src/persist.c @@ -248,7 +248,7 @@ error: return 1; } -static int _db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, struct _mosquitto_subhier *node, const char *topic) +static int _db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, struct _mosquitto_subhier *node, const char *topic, int level) { struct _mosquitto_subhier *subhier; struct _mosquitto_subleaf *sub; @@ -261,7 +261,7 @@ static int _db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, struct slen = strlen(topic) + strlen(node->topic) + 2; thistopic = _mosquitto_malloc(sizeof(char)*slen); if(!thistopic) return MOSQ_ERR_NOMEM; - if(strlen(topic)){ + if(level > 1 || strlen(topic)){ snprintf(thistopic, slen, "%s/%s", topic, node->topic); }else{ snprintf(thistopic, slen, "%s", node->topic); @@ -306,7 +306,7 @@ static int _db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr, struct subhier = node->children; while(subhier){ - _db_subs_retain_write(db, db_fptr, subhier, thistopic); + _db_subs_retain_write(db, db_fptr, subhier, thistopic, level+1); subhier = subhier->next; } _mosquitto_free(thistopic); @@ -322,7 +322,7 @@ static int mqtt3_db_subs_retain_write(struct mosquitto_db *db, FILE *db_fptr) subhier = db->subs.children; while(subhier){ - _db_subs_retain_write(db, db_fptr, subhier, ""); + _db_subs_retain_write(db, db_fptr, subhier->children, "", 0); subhier = subhier->next; } diff --git a/src/subs.c b/src/subs.c index 4f64b3e5..dcf1b3af 100644 --- a/src/subs.c +++ b/src/subs.c @@ -462,12 +462,12 @@ int mqtt3_sub_add(struct mosquitto_db *db, struct mosquitto *context, const char child->subs = NULL; child->children = NULL; child->retained = NULL; - if(db->subs.children){ - child->next = db->subs.children; + if(root->children){ + child->next = root->children; }else{ child->next = NULL; } - db->subs.children = child; + root->children = child; rc = _sub_add(db, context, qos, child, tokens); }