From f66011240901bbbeabc599a459f734c7c494b4d6 Mon Sep 17 00:00:00 2001 From: Justin-lavelle Date: Thu, 16 Jan 2025 16:18:01 -0800 Subject: [PATCH] Add support for presence_disable_early in sofia_dialog_probe_callback Addresses scenario where a SUBSCRIBE messages triggers a presence probe while a call with the presence_disable_early variable set or on a profile with the flag PFLAG_PRESENCE_DISABLE_EARLY set is in the early state. This changes the behavior to skip the relevant channel when the profile has the flag set or the channel has the variable set, so it will not send the NOTIFY with the early state in response to the presence probe. --- src/mod/endpoints/mod_sofia/sofia_presence.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 48ad579411..6738a6f27a 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1954,6 +1954,7 @@ static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char * char *from_tag = switch_str_nil(argv[15]); char *orig_proto = switch_str_nil(argv[16]); + switch_core_session_t *session; const char *event_status = ""; char *data = NULL, *tmp; char key[256] = ""; @@ -1968,6 +1969,7 @@ static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char * int bInternal = 0; int i; int skip_proto = 0; + int skip_dialog = 0; if (mod_sofia_globals.debug_presence > 1) { for (i = 0; i < argc; i++) { @@ -1980,6 +1982,22 @@ static int sofia_dialog_probe_callback(void *pArg, int argc, char **argv, char * return 0; } + // If the dialog is in the "early" state check the presence_disable_early profile flag and channel variable. + // When presence_disable_early is set the dialog should not influence the result of the probe and resulting NOTIFY that is sent. + if (!strcasecmp(state, "early") && (session = switch_core_session_locate(uuid))) { + switch_channel_t *channel = switch_core_session_get_channel(session); + + if (sofia_test_pflag(h->profile, PFLAG_PRESENCE_DISABLE_EARLY) || + switch_true(switch_channel_get_variable(channel, "presence_disable_early"))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "sofia_dialog_probe_callback: presence_disable_early is set skipping dialog\n"); + skip_dialog = 1; + } + + switch_core_session_rwunlock(session); + + if (skip_dialog) return 0; + } + // Usually we report the dialogs FROM the probed user. The exception is when the monitored endpoint is internal, // and its presence_id is set in the dialplan. Reverse the direction if this is not a registered entity. if (!strcmp(direction, "inbound") && strcmp(user, from_user) ) {