]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stasis.c: Use correct topic name in stasis_topic_pool_delete_topic
authorGeorge Joseph <gjoseph@digium.com>
Thu, 2 Jan 2020 20:25:33 +0000 (13:25 -0700)
committerGeorge Joseph <gjoseph@digium.com>
Mon, 6 Jan 2020 15:52:34 +0000 (09:52 -0600)
When a topic is created for an object, its name is only
<object>:<uniqueid>
For example:
bridge:cb68b3a8-fce7-4738-8a17-d7847562f020

When a topic is added to a pool, its name has the pool's topic
name prepended.  For example:
bridge:all/bridge:cb68b3a8-fce7-4738-8a17-d7847562f020

The topic_pool_entry's name however, is only what was passed
in to stasis_topic_pool_get_topic which is
bridge:cb68b3a8-fce7-4738-8a17-d7847562f020
That's actually correct because the entry is qualified by the
pool that's in.

When you're ready to delete the entry from the pool, you retrieve
the tropic name from the object but since it now has the pool's
topic name prepended, it won't be found in the pool container.

Fix:

* Modified stasis_topic_pool_delete_topic() to skip past the
pool topic's name, if it was prepended to the topic name,
before searching the container for a pool entry.

ASTERISK-28633
Reported by: Joeran Vinzens

Change-Id: I4396aa69dd83e4ab84c5b91b39293cfdbcf483e6

include/asterisk/stasis.h
main/stasis.c

index 00b5c238c5a9a176bb1121b50da25ff56308a2ec..a92694f106f4e739787dfdc449612004a7fa715e 100644 (file)
@@ -940,7 +940,8 @@ struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool,
  * \brief Delete a topic from the topic pool
  *
  * \param pool Pool from which to delete the topic
- * \param topic_name Name of the topic to delete
+ * \param topic_name Name of the topic to delete in the form of
+ *                   <pool_topic_name>/<topic_name> or just <topic_name>
  *
  * \since 13.24
  * \since 15.6
index f6c6bfbbd46d21126982686f0effdef600034c3d..4c81675cf5fcc2f54a00d38f9688d6e906e27949 100644 (file)
@@ -1855,7 +1855,22 @@ struct stasis_topic_pool *stasis_topic_pool_create(struct stasis_topic *pooled_t
 
 void stasis_topic_pool_delete_topic(struct stasis_topic_pool *pool, const char *topic_name)
 {
-       ao2_find(pool->pool_container, topic_name, OBJ_SEARCH_KEY | OBJ_NODATA | OBJ_UNLINK);
+       /*
+        * The topic_name passed in could be a fully-qualified name like <pool_topic_name>/<topic_name>
+        * or just <topic_name>.  If it's fully qualified, we need to skip past <pool_topic_name>
+        * name and search only on <topic_name>.
+        */
+       const char *pool_topic_name = stasis_topic_name(pool->pool_topic);
+       int pool_topic_name_len = strlen(pool_topic_name);
+       const char *search_topic_name;
+
+       if (strncmp(pool_topic_name, topic_name, pool_topic_name_len) == 0) {
+               search_topic_name = topic_name + pool_topic_name_len + 1;
+       } else {
+               search_topic_name = topic_name;
+       }
+
+       ao2_find(pool->pool_container, search_topic_name, OBJ_SEARCH_KEY | OBJ_NODATA | OBJ_UNLINK);
 }
 
 struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name)