From f69b150c8090adb86f2fcaadd56873f61cdb7097 Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Thu, 22 Jun 2023 19:46:34 +0300 Subject: [PATCH] Also register a custom event from subscribe_event() fixup This will permit raising an event from MI with an event subscribtion done in startup_route without the need to define an event_route for this event or using a raise() in the script. --- core_cmds.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core_cmds.c b/core_cmds.c index 7a6878f47b4..5aaedc21eaa 100644 --- a/core_cmds.c +++ b/core_cmds.c @@ -57,6 +57,7 @@ static int fixup_check_wrvar(void** param); static int fixup_avp_list(void** param); static int fixup_check_avp(void** param); static int fixup_event_name(void** param); +static int fixup_event_name_subs(void** param); static int fixup_format_string(void** param); static int fixup_nt_string(void** param); static int fixup_nt_str(void** param); @@ -313,7 +314,7 @@ const cmd_export_t core_cmds[]={ {CMD_PARAM_VAR|CMD_PARAM_OPT, fixup_check_avp, 0}, {0,0,0}}, ALL_ROUTES}, {"subscribe_event", (cmd_function)w_subscribe_event, { - {CMD_PARAM_STR, 0, 0}, + {CMD_PARAM_STR, fixup_event_name_subs, 0}, {CMD_PARAM_STR, 0, 0}, {CMD_PARAM_INT|CMD_PARAM_OPT, 0, 0}, {0,0,0}}, ALL_ROUTES}, @@ -583,6 +584,23 @@ static int fixup_event_name(void** param) return 0; } +static int fixup_event_name_subs(void** param) +{ + str *s = (str*)*param; + event_id_t ev_id; + + ev_id = evi_get_id(s); + if (ev_id == EVI_ERROR) { + ev_id = evi_publish_event(*s); + if (ev_id == EVI_ERROR) { + LM_ERR("cannot subscribe event\n"); + return E_UNSPEC; + } + } + + return 0; +} + static int fixup_format_string(void** param) { str *s = (str*)*param;