Minor sub tree refactor

This commit is contained in:
Roger A. Light
2025-02-03 10:01:45 +00:00
parent 8e5fd81764
commit aa89eb3575
4 changed files with 25 additions and 14 deletions
+1 -11
View File
@@ -180,8 +180,6 @@ static void db__msg_remove_from_queued_stats(struct mosquitto_msg_data *msg_data
int db__open(struct mosquitto__config *config)
{
struct mosquitto__subhier *subhier;
if(!config) return MOSQ_ERR_INVAL;
db.contexts_by_id = NULL;
@@ -198,15 +196,7 @@ int db__open(struct mosquitto__config *config)
db.normal_subs = NULL;
db.shared_subs = NULL;
subhier = sub__add_hier_entry(NULL, &db.shared_subs, "", 0);
if(!subhier) return MOSQ_ERR_NOMEM;
subhier = sub__add_hier_entry(NULL, &db.normal_subs, "", 0);
if(!subhier) return MOSQ_ERR_NOMEM;
subhier = sub__add_hier_entry(NULL, &db.normal_subs, "$SYS", (uint16_t)strlen("$SYS"));
if(!subhier) return MOSQ_ERR_NOMEM;
sub__init();
retain__init();
db.config->security_options.unpwd = NULL;
+1 -1
View File
@@ -743,8 +743,8 @@ void db__check_acl_of_all_messages(struct mosquitto *context);
/* ============================================================
* Subscription functions
* ============================================================ */
int sub__init(void);
int sub__add(struct mosquitto *context, const struct mosquitto_subscription *sub);
struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent, struct mosquitto__subhier **sibling, const char *topic, uint16_t len);
int sub__remove(struct mosquitto *context, const char *sub, uint8_t *reason);
void sub__tree_print(struct mosquitto__subhier *root, int level);
int sub__clean_session(struct mosquitto *context);
+19 -2
View File
@@ -59,6 +59,8 @@ Contributors:
#include "utlist.h"
static struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent, struct mosquitto__subhier **sibling, const char *topic, uint16_t len);
static int subs__send(struct mosquitto__subleaf *leaf, const char *topic, uint8_t qos, int retain, struct mosquitto__base_msg *stored)
{
bool client_retain;
@@ -523,7 +525,7 @@ static int sub__search(struct mosquitto__subhier *subhier, char **split_topics,
}
struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent, struct mosquitto__subhier **sibling, const char *topic, uint16_t len)
static struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent, struct mosquitto__subhier **sibling, const char *topic, uint16_t len)
{
struct mosquitto__subhier *child;
@@ -536,7 +538,9 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
}
child->parent = parent;
child->topic_len = len;
strncpy(child->topic, topic, len);
if(len > 0){
strncpy(child->topic, topic, len);
}
HASH_ADD(hh, *sibling, topic, child->topic_len, child);
@@ -794,3 +798,16 @@ void sub__tree_print(struct mosquitto__subhier *root, int level)
sub__tree_print(branch->children, level+1);
}
}
int sub__init(void)
{
if(sub__add_hier_entry(NULL, &db.shared_subs, "", 0) == NULL
|| sub__add_hier_entry(NULL, &db.normal_subs, "", 0) == NULL
|| sub__add_hier_entry(NULL, &db.normal_subs, "$SYS", (uint16_t)strlen("$SYS")) == NULL
){
return MOSQ_ERR_NOMEM;
}else{
return MOSQ_ERR_SUCCESS;
}
}
+4
View File
@@ -251,3 +251,7 @@ int send__pubrel(struct mosquitto *mosq, uint16_t mid, const mosquitto_property
return MOSQ_ERR_SUCCESS;
}
int sub__init(void)
{
return MOSQ_ERR_SUCCESS;
}