Stasis: Fix unsafe use of stasis_unsubscribe in modules.
[asterisk/asterisk.git] / res / res_stasis_device_state.c
index e6d3391..7f7c513 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+ASTERISK_REGISTER_FILE()
 
 #include "asterisk/astdb.h"
 #include "asterisk/astobj2.h"
@@ -39,7 +39,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 /*! Scheme for custom device states */
 #define DEVICE_STATE_SCHEME_STASIS "Stasis:"
 /*! Scheme for device state subscriptions */
-#define DEVICE_STATE_SCHEME_SUB "device_state:"
+#define DEVICE_STATE_SCHEME_SUB "deviceState:"
 
 /*! Number of hash buckets for device state subscriptions */
 #define DEVICE_STATE_BUCKETS 37
@@ -105,7 +105,7 @@ static int device_state_subscriptions_cmp(void *obj, void *arg, int flags)
 static void device_state_subscription_destroy(void *obj)
 {
        struct device_state_subscription *sub = obj;
-       sub->sub = stasis_unsubscribe(sub->sub);
+       sub->sub = stasis_unsubscribe_and_join(sub->sub);
        ast_string_field_free_memory(sub);
 }
 
@@ -326,11 +326,11 @@ static int subscribe_device_state(struct stasis_app *app, void *obj)
        ast_debug(3, "Subscribing to device %s", sub->device_name);
 
        if (is_subscribed_device_state(app, sub->device_name)) {
-               ast_log(LOG_WARNING, "Already subscribed to %s\n", sub->device_name);
-               return -1;
+               ast_debug(3, "App %s is already subscribed to %s\n", stasis_app_name(app), sub->device_name);
+               return 0;
        }
 
-       if (!(sub->sub = stasis_subscribe(
+       if (!(sub->sub = stasis_subscribe_pool(
                        ast_device_state_topic(sub->device_name),
                        device_state_cb, sub))) {
                ast_log(LOG_ERROR, "Unable to subscribe to device %s\n",
@@ -411,6 +411,8 @@ static int unload_module(void)
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application device state support",
+       .support_level = AST_MODULE_SUPPORT_CORE,
        .load = load_module,
        .unload = unload_module,
-       .nonoptreq = "res_stasis");
+       .nonoptreq = "res_stasis"
+);