Simplify function calls.

pull/2558/merge
Roger A. Light 3 years ago
parent b11b0b206c
commit afc575aa1c

@ -114,14 +114,13 @@ int retain__store(const char *topic, struct mosquitto_base_msg *base_msg, char *
return 0; return 0;
} }
int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root) int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options)
{ {
UNUSED(context); UNUSED(context);
UNUSED(sub); UNUSED(sub);
UNUSED(qos); UNUSED(qos);
UNUSED(identifier); UNUSED(identifier);
UNUSED(options); UNUSED(options);
UNUSED(root);
return 0; return 0;
} }

@ -495,8 +495,8 @@ int bridge__connect(struct mosquitto *context)
cur_topic->local_topic, cur_topic->local_topic,
qos, qos,
0, 0,
MQTT_SUB_OPT_NO_LOCAL | MQTT_SUB_OPT_RETAIN_AS_PUBLISHED, MQTT_SUB_OPT_NO_LOCAL | MQTT_SUB_OPT_RETAIN_AS_PUBLISHED
&db.subs) > 0){ ) > 0){
return 1; return 1;
} }

@ -194,7 +194,7 @@ int handle__subscribe(struct mosquitto *context)
} }
if(allowed){ if(allowed){
rc2 = sub__add(context, sub, qos, subscription_identifier, subscription_options, &db.subs); rc2 = sub__add(context, sub, qos, subscription_identifier, subscription_options);
if(rc2 > 0){ if(rc2 > 0){
mosquitto__FREE(sub); mosquitto__FREE(sub);
return rc2; return rc2;

@ -129,7 +129,7 @@ int handle__unsubscribe(struct mosquitto *context)
log__printf(NULL, MOSQ_LOG_DEBUG, "\t%s", sub); log__printf(NULL, MOSQ_LOG_DEBUG, "\t%s", sub);
if(allowed){ if(allowed){
rc = sub__remove(context, sub, db.subs, &reason); rc = sub__remove(context, sub, &reason);
plugin__handle_unsubscribe(context, sub, properties); plugin__handle_unsubscribe(context, sub, properties);
plugin_persist__handle_subscription_delete(context, sub); plugin_persist__handle_subscription_delete(context, sub);
}else{ }else{

@ -757,9 +757,9 @@ void db__expire_all_messages(struct mosquitto *context);
/* ============================================================ /* ============================================================
* Subscription functions * Subscription functions
* ============================================================ */ * ============================================================ */
int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root); int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options);
struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent, struct mosquitto__subhier **sibling, const char *topic, uint16_t len); 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, struct mosquitto__subhier *root, uint8_t *reason); int sub__remove(struct mosquitto *context, const char *sub, uint8_t *reason);
void sub__tree_print(struct mosquitto__subhier *root, int level); void sub__tree_print(struct mosquitto__subhier *root, int level);
int sub__clean_session(struct mosquitto *context); int sub__clean_session(struct mosquitto *context);
int sub__messages_queue(const char *source_id, const char *topic, uint8_t qos, int retain, struct mosquitto_base_msg **base_msg); int sub__messages_queue(const char *source_id, const char *topic, uint8_t qos, int retain, struct mosquitto_base_msg **base_msg);

@ -548,7 +548,7 @@ static int persist__restore_sub(const char *client_id, const char *sub, uint8_t
context = persist__find_or_add_context(client_id, 0); context = persist__find_or_add_context(client_id, 0);
if(!context) return 1; if(!context) return 1;
return sub__add(context, sub, qos, identifier, options, &db.subs); return sub__add(context, sub, qos, identifier, options);
} }
#endif #endif

@ -384,7 +384,7 @@ static void check_subscription_acls(struct mosquitto *context)
MOSQ_ACL_SUBSCRIBE); MOSQ_ACL_SUBSCRIBE);
if(rc != MOSQ_ERR_SUCCESS){ if(rc != MOSQ_ERR_SUCCESS){
sub__remove(context, context->subs[i]->topic_filter, db.subs, &reason); sub__remove(context, context->subs[i]->topic_filter, &reason);
} }
} }
} }
@ -718,7 +718,7 @@ BROKER_EXPORT int mosquitto_subscription_add(const char *client_id, const char *
HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context); HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context);
if(context){ if(context){
return sub__add(context, topic, subscription_options&0x03, subscription_identifier, subscription_options, &db.subs); return sub__add(context, topic, subscription_options&0x03, subscription_identifier, subscription_options);
}else{ }else{
return MOSQ_ERR_NOT_FOUND; return MOSQ_ERR_NOT_FOUND;
} }
@ -737,7 +737,7 @@ BROKER_EXPORT int mosquitto_subscription_delete(const char *client_id, const cha
HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context); HASH_FIND(hh_id, db.contexts_by_id, client_id, strlen(client_id), context);
if(context){ if(context){
return sub__remove(context, topic, db.subs, &reason); return sub__remove(context, topic, &reason);
}else{ }else{
return MOSQ_ERR_NOT_FOUND; return MOSQ_ERR_NOT_FOUND;
} }

@ -559,7 +559,7 @@ struct mosquitto__subhier *sub__add_hier_entry(struct mosquitto__subhier *parent
} }
int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root) int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options)
{ {
int rc = 0; int rc = 0;
struct mosquitto__subhier *subhier; struct mosquitto__subhier *subhier;
@ -568,8 +568,6 @@ int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t i
char **topics; char **topics;
size_t topiclen; size_t topiclen;
assert(root);
assert(*root);
assert(sub); assert(sub);
rc = sub__topic_tokenise(sub, &local_sub, &topics, &sharename); rc = sub__topic_tokenise(sub, &local_sub, &topics, &sharename);
@ -581,9 +579,9 @@ int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t i
mosquitto__FREE(topics); mosquitto__FREE(topics);
return MOSQ_ERR_INVAL; return MOSQ_ERR_INVAL;
} }
HASH_FIND(hh, *root, topics[0], topiclen, subhier); HASH_FIND(hh, db.subs, topics[0], topiclen, subhier);
if(!subhier){ if(!subhier){
subhier = sub__add_hier_entry(NULL, root, topics[0], (uint16_t)topiclen); subhier = sub__add_hier_entry(NULL, &db.subs, topics[0], (uint16_t)topiclen);
if(!subhier){ if(!subhier){
mosquitto__FREE(local_sub); mosquitto__FREE(local_sub);
mosquitto__FREE(topics); mosquitto__FREE(topics);
@ -600,7 +598,7 @@ int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t i
return rc; return rc;
} }
int sub__remove(struct mosquitto *context, const char *sub, struct mosquitto__subhier *root, uint8_t *reason) int sub__remove(struct mosquitto *context, const char *sub, uint8_t *reason)
{ {
int rc = 0; int rc = 0;
struct mosquitto__subhier *subhier; struct mosquitto__subhier *subhier;
@ -608,13 +606,12 @@ int sub__remove(struct mosquitto *context, const char *sub, struct mosquitto__su
char *local_sub = NULL; char *local_sub = NULL;
char **topics = NULL; char **topics = NULL;
assert(root);
assert(sub); assert(sub);
rc = sub__topic_tokenise(sub, &local_sub, &topics, &sharename); rc = sub__topic_tokenise(sub, &local_sub, &topics, &sharename);
if(rc) return rc; if(rc) return rc;
HASH_FIND(hh, root, topics[0], strlen(topics[0]), subhier); HASH_FIND(hh, db.subs, topics[0], strlen(topics[0]), subhier);
if(subhier){ if(subhier){
*reason = MQTT_RC_NO_SUBSCRIPTION_EXISTED; *reason = MQTT_RC_NO_SUBSCRIPTION_EXISTED;
rc = sub__remove_recurse(context, subhier, topics, reason, sharename); rc = sub__remove_recurse(context, subhier, topics, reason, sharename);

@ -152,11 +152,10 @@ int acl__find_acls(struct mosquitto *context)
} }
int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options, struct mosquitto__subhier **root) int sub__add(struct mosquitto *context, const char *sub, uint8_t qos, uint32_t identifier, int options)
{ {
UNUSED(context); UNUSED(context);
UNUSED(options); UNUSED(options);
UNUSED(root);
last_sub = strdup(sub); last_sub = strdup(sub);
last_qos = qos; last_qos = qos;

@ -58,7 +58,7 @@ static void TEST_sub_add_single(void)
db__open(&config); db__open(&config);
rc = sub__add(&context, "a/b/c/d/e", 0, 0, 0, &db.subs); rc = sub__add(&context, "a/b/c/d/e", 0, 0, 0);
CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS); CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS);
CU_ASSERT_PTR_NOT_NULL(db.subs); CU_ASSERT_PTR_NOT_NULL(db.subs);
if(db.subs){ if(db.subs){

Loading…
Cancel
Save