summaryrefslogtreecommitdiff
path: root/main/cel.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-11-15 14:37:20 +0000
committerKinsey Moore <kmoore@digium.com>2013-11-15 14:37:20 +0000
commit50afe6b9dd65a4294c63a8556ab3efbd202ee465 (patch)
tree28ee5a1f7196374da68b3ce475af742f7dda9f46 /main/cel.c
parent9cea557f6c3b036ef58c0be3f2136554ae5f9560 (diff)
CEL: Fix crash when using CELGenUserEvent
This fixes a crash when CELGenUserEvent is called from the dialplan while CEL is disabled. Currently, CEL does not create its topics and forwards if it is not enabled and external entities may depend on these topics blindly since they should always be available. This patch breaks up route creation and topic/forward creation such that the CEL topics and forwards will always exist while the router and its associated routes will be torn down and recreated as necessary. (closes issue ASTERISK-22799) Review: https://reviewboard.asterisk.org/r/3010/ Reported by: Matt Jordan ........ Merged revisions 402838 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@402839 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/cel.c')
-rw-r--r--main/cel.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/main/cel.c b/main/cel.c
index 79752aaaa..db51361e9 100644
--- a/main/cel.c
+++ b/main/cel.c
@@ -1363,11 +1363,14 @@ static void cel_local_cb(
cel_report_event(localone, AST_CEL_LOCAL_OPTIMIZE, NULL, extra, NULL);
}
-static void destroy_subscriptions(void)
+static void destroy_routes(void)
{
stasis_message_router_unsubscribe_and_join(cel_state_router);
cel_state_router = NULL;
+}
+static void destroy_subscriptions(void)
+{
ao2_cleanup(cel_aggregation_topic);
cel_aggregation_topic = NULL;
ao2_cleanup(cel_topic);
@@ -1381,6 +1384,7 @@ static void destroy_subscriptions(void)
static void ast_cel_engine_term(void)
{
+ destroy_routes();
destroy_subscriptions();
aco_info_destroy(&cel_cfg_info);
@@ -1400,8 +1404,6 @@ static void ast_cel_engine_term(void)
*/
static int create_subscriptions(void)
{
- int ret = 0;
-
cel_aggregation_topic = stasis_topic_create("cel_aggregation_topic");
if (!cel_aggregation_topic) {
return -1;
@@ -1440,6 +1442,16 @@ static int create_subscriptions(void)
return -1;
}
+ return 0;
+}
+
+/*!
+ * \brief Create the Stasis message router and routes for CEL
+ */
+static int create_routes(void)
+{
+ int ret = 0;
+
cel_state_router = stasis_message_router_create(cel_aggregation_topic);
if (!cel_state_router) {
return -1;
@@ -1550,7 +1562,11 @@ int ast_cel_engine_init(void)
}
}
- if (ast_cel_check_enabled() && create_subscriptions()) {
+ if (create_subscriptions()) {
+ return -1;
+ }
+
+ if (ast_cel_check_enabled() && create_routes()) {
return -1;
}
@@ -1570,11 +1586,11 @@ static int do_reload(void)
is_enabled = ast_cel_check_enabled();
if (!was_enabled && is_enabled) {
- if (create_subscriptions()) {
+ if (create_routes()) {
return -1;
}
} else if (was_enabled && !is_enabled) {
- destroy_subscriptions();
+ destroy_routes();
}
ast_verb(3, "CEL logging %sabled.\n", is_enabled ? "en" : "dis");
@@ -1636,9 +1652,9 @@ void ast_cel_set_config(struct ast_cel_general_config *config)
is_enabled = ast_cel_check_enabled();
if (!was_enabled && is_enabled) {
- create_subscriptions();
+ create_routes();
} else if (was_enabled && !is_enabled) {
- destroy_subscriptions();
+ destroy_routes();
}
}
}