diff --git a/conf/sip_profiles/default.xml b/conf/sip_profiles/default.xml index 03d458c180..5a8bdb44e5 100644 --- a/conf/sip_profiles/default.xml +++ b/conf/sip_profiles/default.xml @@ -100,6 +100,9 @@ + + + diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index ce688e170f..15a94b1248 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -112,6 +112,11 @@ struct sip_alias_node { typedef struct sip_alias_node sip_alias_node_t; +typedef enum { + MFLAG_REFER = (1 << 0), + MFLAG_REGISTER = (1 << 1) +} MFLAGS; + typedef enum { PFLAG_AUTH_CALLS = (1 << 0), PFLAG_BLIND_REG = (1 << 1), @@ -269,6 +274,7 @@ struct sofia_profile { int dtmf_duration; unsigned int flags; unsigned int pflags; + unsigned int mflags; unsigned int ndlb; uint32_t max_calls; uint32_t nonce_ttl; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c2c7a4656d..d8f3e8abee 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -537,8 +537,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void NUTAG_APPL_METHOD("INFO"), NUTAG_AUTOANSWER(0), NUTAG_AUTOALERT(0), - NUTAG_ALLOW("REGISTER"), - NUTAG_ALLOW("REFER"), + TAG_IF((profile->mflags & MFLAG_REGISTER), NUTAG_ALLOW("REGISTER")), + TAG_IF((profile->mflags & MFLAG_REFER), NUTAG_ALLOW("REFER")), NUTAG_ALLOW("INFO"), NUTAG_ALLOW("NOTIFY"), NUTAG_ALLOW_EVENTS("talk"), @@ -565,16 +565,16 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void NUTAG_URL(node->url), TAG_END()); /* Last tag should always finish the sequence */ nua_set_params(node->nua, - NUTAG_APPL_METHOD("OPTIONS"), - NUTAG_EARLY_MEDIA(1), - NUTAG_AUTOANSWER(0), - NUTAG_AUTOALERT(0), - NUTAG_ALLOW("REGISTER"), - NUTAG_ALLOW("REFER"), - NUTAG_ALLOW("INFO"), - TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")), - TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)), - SIPTAG_SUPPORTED_STR("100rel, precondition"), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END()); + NUTAG_APPL_METHOD("OPTIONS"), + NUTAG_EARLY_MEDIA(1), + NUTAG_AUTOANSWER(0), + NUTAG_AUTOALERT(0), + TAG_IF((profile->mflags & MFLAG_REGISTER), NUTAG_ALLOW("REGISTER")), + TAG_IF((profile->mflags & MFLAG_REFER), NUTAG_ALLOW("REFER")), + NUTAG_ALLOW("INFO"), + TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("PUBLISH")), + TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)), + SIPTAG_SUPPORTED_STR("100rel, precondition"), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END()); } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "activated db for %s\n", profile->name); @@ -1007,7 +1007,8 @@ switch_status_t config_sofia(int reload, char *profile_name) switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool); profile->dtmf_duration = 100; profile->tls_version = 0; - + profile->mflags = MFLAG_REFER | MFLAG_REGISTER; + for (param = switch_xml_child(settings, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -1045,6 +1046,8 @@ switch_status_t config_sofia(int reload, char *profile_name) profile->record_template = switch_core_strdup(profile->pool, val);; } else if (!strcasecmp(var, "inbound-no-media") && switch_true(val)) { switch_set_flag(profile, TFLAG_INB_NOMEDIA); + } else if (!strcasecmp(var, "inbound-bypass-media") && switch_true(val)) { + switch_set_flag(profile, TFLAG_INB_NOMEDIA); } else if (!strcasecmp(var, "inbound-late-negotiation") && switch_true(val)) { switch_set_flag(profile, TFLAG_LATE_NEGOTIATION); } else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) { @@ -1114,6 +1117,10 @@ switch_status_t config_sofia(int reload, char *profile_name) if (v >= 0) { profile->rtp_hold_timeout_sec = v; } + } else if (!strcasecmp(var, "disable-transfer") && switch_true(val)) { + profile->mflags &= ~MFLAG_REFER; + } else if (!strcasecmp(var, "disable-register") && switch_true(val)) { + profile->mflags &= ~MFLAG_REGISTER; } else if (!strcasecmp(var, "manage-presence")) { if (switch_true(val)) { profile->pflags |= PFLAG_PRESENCE; @@ -1974,6 +1981,11 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t char *full_ref_by = NULL; char *full_ref_to = NULL; + if (profile->mflags & MFLAG_REFER) { + nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END()); + goto done; + } + if (!sip->sip_cseq || !(etmp = switch_mprintf("refer;id=%u", sip->sip_cseq->cs_seq))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n"); goto done; diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index b33cdf2b22..075c08a7ec 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -637,6 +637,11 @@ void sofia_reg_handle_sip_i_register(nua_t * nua, sofia_profile_t *profile, nua_ { char key[128] = ""; switch_event_t *v_event = NULL; + + if (profile->mflags & MFLAG_REFER) { + nua_respond(nh, SIP_403_FORBIDDEN, NUTAG_WITH_THIS(nua), TAG_END()); + goto end; + } if (!sip || !sip->sip_request || !sip->sip_request->rq_method_name) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received an invalid packet!\n");