Skip to content

Commit

Permalink
Also register a custom event from subscribe_event() fixup
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit f69b150)
  • Loading branch information
rvlad-patrascu committed Jun 23, 2023
1 parent a4ae802 commit 15732b3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion core_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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_rewritehost(void **param);
Expand Down Expand Up @@ -297,7 +298,7 @@ static 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},
Expand Down Expand Up @@ -536,6 +537,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;
Expand Down

0 comments on commit 15732b3

Please sign in to comment.