Module: kamailio Branch: master Commit: 7337cb59ccfe7937b825384cdf862b14e1530e82 URL: https://github.com/kamailio/kamailio/commit/7337cb59ccfe7937b825384cdf862b14e1530e82
Author: Gustavo Almeida <[email protected]> Committer: GitHub <[email protected]> Date: 2025-11-17T12:05:49+01:00 dispatcher: trigger event_route blocks when old_state its not present * dispatcher: support to trigger dispatch event routes when old state its not defined * dispatcher: trigger event_routes on startup/reload only when event_callback_mode = 1 * dispatcher: update ds_event_callback_mode condition to use 2 instead of 1, as 1 is already mentioned in doc as a bypass * dispatcher: update doc --- Modified: src/modules/dispatcher/dispatch.c Modified: src/modules/dispatcher/doc/dispatcher_admin.xml --- Diff: https://github.com/kamailio/kamailio/commit/7337cb59ccfe7937b825384cdf862b14e1530e82.diff Patch: https://github.com/kamailio/kamailio/commit/7337cb59ccfe7937b825384cdf862b14e1530e82.patch --- diff --git a/src/modules/dispatcher/dispatch.c b/src/modules/dispatcher/dispatch.c index 3c40307c1fd..627f1a621d4 100644 --- a/src/modules/dispatcher/dispatch.c +++ b/src/modules/dispatcher/dispatch.c @@ -3529,17 +3529,29 @@ int ds_update_state(sip_msg_t *msg, int group, str *address, str *iuid, } } - if((ds_event_callback_mode == 0) - || ((mode & DS_STATE_MODE_FUNC) == 0)) { - if(!ds_skip_dst(old_state) - && ds_skip_dst(idx->dlist[i].flags)) { - ds_run_route(msg, address, "dispatcher:dst-down", rctx); - - } else if(ds_skip_dst(old_state) - && !ds_skip_dst(idx->dlist[i].flags)) { - ds_run_route(msg, address, "dispatcher:dst-up", rctx); + + if((mode & DS_STATE_MODE_FUNC) == 0) { + int was_down = ds_skip_dst(old_state); + int is_down = ds_skip_dst(idx->dlist[i].flags); + + if(ds_event_callback_mode == 0) { + + if(!was_down && is_down) { + ds_run_route(msg, address, "dispatcher:dst-down", rctx); + } else if(was_down && !is_down) { + ds_run_route(msg, address, "dispatcher:dst-up", rctx); + } + } else if(ds_event_callback_mode == 2) { + + if((!was_down && is_down) || (old_state == 0 && is_down)) { + ds_run_route(msg, address, "dispatcher:dst-down", rctx); + } else if((was_down && !is_down) + || (old_state == 0 && !is_down)) { + ds_run_route(msg, address, "dispatcher:dst-up", rctx); + } } } + if(idx->dlist[i].attrs.rweight > 0) ds_reinit_rweight_on_state_change( old_state, idx->dlist[i].flags, idx); diff --git a/src/modules/dispatcher/doc/dispatcher_admin.xml b/src/modules/dispatcher/doc/dispatcher_admin.xml index abc9b9ba033..5d551cdd8de 100644 --- a/src/modules/dispatcher/doc/dispatcher_admin.xml +++ b/src/modules/dispatcher/doc/dispatcher_admin.xml @@ -1080,6 +1080,9 @@ end state changes based on OPTIONS keepalives or the use of config functions to set the state (e.g., ds_mark_dst(...)). If set to 1, they are executed only on state change due to OPTIONS keepalives. + If set to 2, the event routes will always be executed when a state + change occurs, even if no previous state exists (for example, on + startup or reload). </para> <para> Note that event routes are not executed on RPC commands setting _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
