diff --git a/CHANGES b/CHANGES index 78d5e6b97bb08e86aafea5ea55d46248585b571b..7d0b954a85268bf24fc5f91803cd9f1f36c3fa95 100644 --- a/CHANGES +++ b/CHANGES @@ -200,6 +200,13 @@ Queue --- Functionality changes from Asterisk 13.6.0 to Asterisk 13.7.0 ------------ ------------------------------------------------------------------------------ +chan_sip +------------------ + * The websockets_enabled option has been added to the general section of + sip.conf. The option is enabled by default to match the previous behavior. + The option should be disabled when using res_pjsip_transport_websockets to + ensure chan_sip will not conflict with PJSIP websockets. + Dialplan Functions ------------------ * The HOLD_INTERCEPT dialplan function now actually exists in the source tree. diff --git a/channels/chan_sip.c b/channels/chan_sip.c index f0d4de53d6188caafccb7e098e94949a42ec66fb..0fd9f7d18953c1d0a82ee17fdd245e4b706d36df 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -31265,6 +31265,7 @@ static int reload_config(enum channelreloadreason reason) int bindport = 0; int acl_change_subscription_needed = 0; int min_subexpiry_set = 0, max_subexpiry_set = 0; + int websocket_was_enabled = sip_cfg.websocket_enabled; run_start = time(0); ast_unload_realtime("sipregs"); @@ -32068,6 +32069,8 @@ static int reload_config(enum channelreloadreason reason) ast_log(LOG_WARNING, "'%s' is not a valid websocket_write_timeout value at line %d. Using default '%d'.\n", v->value, v->lineno, AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT); sip_cfg.websocket_write_timeout = AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT; } + } else if (!strcasecmp(v->name, "websocket_enabled")) { + sip_cfg.websocket_enabled = ast_true(v->value); } } @@ -32413,6 +32416,15 @@ static int reload_config(enum channelreloadreason reason) notify_types = NULL; } + /* If the module is loading it's not time to enable websockets yet. */ + if (reason != CHANNEL_MODULE_LOAD && websocket_was_enabled != sip_cfg.websocket_enabled) { + if (sip_cfg.websocket_enabled) { + ast_websocket_add_protocol("sip", sip_websocket_callback); + } else { + ast_websocket_remove_protocol("sip", sip_websocket_callback); + } + } + run_end = time(0); ast_debug(4, "SIP reload_config done...Runtime= %d sec\n", (int)(run_end-run_start)); @@ -34594,7 +34606,9 @@ static int load_module(void) sip_register_tests(); network_change_stasis_subscribe(); - ast_websocket_add_protocol("sip", sip_websocket_callback); + if (sip_cfg.websocket_enabled) { + ast_websocket_add_protocol("sip", sip_websocket_callback); + } return AST_MODULE_LOAD_SUCCESS; } @@ -34609,7 +34623,9 @@ static int unload_module(void) ast_sip_api_provider_unregister(); - ast_websocket_remove_protocol("sip", sip_websocket_callback); + if (sip_cfg.websocket_enabled) { + ast_websocket_remove_protocol("sip", sip_websocket_callback); + } network_change_stasis_unsubscribe(); acl_change_event_stasis_unsubscribe(); diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h index 771ed22b41cce738588f473fb4bd29fc0a92092a..87b59f661555f74a6aafe5a209201a765c150192 100644 --- a/channels/sip/include/sip.h +++ b/channels/sip/include/sip.h @@ -774,6 +774,7 @@ struct sip_settings { int tcp_enabled; int default_max_forwards; /*!< Default max forwards (SIP Anti-loop) */ int websocket_write_timeout; /*!< Socket write timeout for websocket transports, in ms */ + int websocket_enabled; /*!< Are websockets enabled? */ }; struct ast_websocket; diff --git a/configs/samples/sip.conf.sample b/configs/samples/sip.conf.sample index 4d06243888b1dd535fb633facbb94c652e131112..0fc5af2ea6354e99b92f9421aabf9d0da45c12da 100644 --- a/configs/samples/sip.conf.sample +++ b/configs/samples/sip.conf.sample @@ -232,6 +232,10 @@ tcpbindaddr=0.0.0.0 ; IP address for TCP server to bind to (0.0.0.0 ; unauthenticated sessions that will be allowed ; to connect at any given time. (default: 100) +;websocket_enabled = true ; Set to false to prevent chan_sip from listening to websockets. This + ; is neeeded when using chan_sip and res_pjsip_transport_websockets on + ; the same system. + ;websocket_write_timeout = 100 ; Default write timeout to set on websocket transports. ; This value may need to be adjusted for connections where ; Asterisk must write a substantial amount of data and the