diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2023-01-09 08:51:00 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 08:51:00 +0700 |
commit | 967208aa05307a04cf70e544a4e353899f347fb6 (patch) | |
tree | a436eabb7e09e280ec1a1f93feeb70dc9257e814 /aclk | |
parent | badd17fb4eec602244d4c343dd25cc00ad182686 (diff) |
MQTT5 Topic Alias (#14148)
* bump websockets
* add new files to makefile
* set topic aliases for used topics
Diffstat (limited to 'aclk')
-rw-r--r-- | aclk/aclk.c | 4 | ||||
-rw-r--r-- | aclk/aclk_util.c | 18 | ||||
-rw-r--r-- | aclk/aclk_util.h | 4 |
3 files changed, 26 insertions, 0 deletions
diff --git a/aclk/aclk.c b/aclk/aclk.c index c3d0fc891e..5afbba274e 100644 --- a/aclk/aclk.c +++ b/aclk/aclk.c @@ -385,6 +385,10 @@ static inline void mqtt_connected_actions(mqtt_wss_client client) aclk_rcvd_cloud_msgs = 0; aclk_connection_counter++; + aclk_topic_cache_iter_t iter = ACLK_TOPIC_CACHE_ITER_T_INITIALIZER; + while ((topic = (char*)aclk_topic_cache_iterate(&iter)) != NULL) + mqtt_wss_set_topic_alias(client, topic); + aclk_send_agent_connection_update(client, 1); } diff --git a/aclk/aclk_util.c b/aclk/aclk_util.c index 27d536e75e..ebf428ff9f 100644 --- a/aclk/aclk_util.c +++ b/aclk/aclk_util.c @@ -308,6 +308,24 @@ const char *aclk_get_topic(enum aclk_topics topic) } /* + * Allows iterating all topics in topic cache without + * having to resort to callbacks. + */ + +const char *aclk_topic_cache_iterate(aclk_topic_cache_iter_t *iter) +{ + if (!aclk_topic_cache) { + error("Topic cache not initialized when %s was called.", __FUNCTION__); + return NULL; + } + + if (*iter >= aclk_topic_cache_items) + return NULL; + + return aclk_topic_cache[(*iter)++]->topic; +} + +/* * TBEB with randomness * * @param reset 1 - to reset the delay, diff --git a/aclk/aclk_util.h b/aclk/aclk_util.h index 6a9acbc6ae..76dc8cad98 100644 --- a/aclk/aclk_util.h +++ b/aclk/aclk_util.h @@ -93,9 +93,13 @@ enum aclk_topics { ACLK_TOPICID_CTXS_UPDATED = 20 }; +typedef size_t aclk_topic_cache_iter_t; +#define ACLK_TOPIC_CACHE_ITER_T_INITIALIZER (0) + const char *aclk_get_topic(enum aclk_topics topic); int aclk_generate_topic_cache(struct json_object *json); void free_topic_cache(void); +const char *aclk_topic_cache_iterate(aclk_topic_cache_iter_t *iter); // TODO // aclk_topics_reload //when claim id changes |