Permalink
Browse files

Fix saving of persistence messages that start with a '/'.

Closes #151. Thanks to Andrew Chambers.

Signed-off-by: Roger A. Light <roger@atchoo.org>
  • Loading branch information...
1 parent 3048c5b commit 57da5867037062d06db4aa7032ce00b5eb9ca1f0 @ralight ralight committed May 14, 2016
Showing with 8 additions and 7 deletions.
  1. +1 −0 ChangeLog.txt
  2. +4 −4 src/persist.c
  3. +3 −3 src/subs.c
View
@@ -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:
View
@@ -248,7 +248,7 @@ static int mqtt3_db_client_write(struct mosquitto_db *db, FILE *db_fptr)
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;
}
View
@@ -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);
}

0 comments on commit 57da586

Please sign in to comment.