[Asterisk-code-review] chan sip: Allow websockets to be disabled. (asterisk[13])

Corey Farrell asteriskteam at digium.com
Mon Nov 2 20:34:27 CST 2015


Corey Farrell has uploaded a new change for review.

  https://gerrit.asterisk.org/1553

Change subject: chan_sip: Allow websockets to be disabled.
......................................................................

chan_sip: Allow websockets to be disabled.

This patch adds a new setting "websockets_enabled" to sip.conf.
Setting this to false allows chan_sip to be used without causing
conflicts with res_pjsip_transport_websocket.

ASTERISK-24106 #close
Reported by: Andrew Nagy

Change-Id: I04fe8c4f2d57b2d7375e0e25826c91a72e93bea7
---
M channels/chan_sip.c
M channels/sip/include/sip.h
M configs/samples/sip.conf.sample
3 files changed, 23 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/53/1553/1

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index f282966..acb7d53 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -31261,6 +31261,7 @@
 	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");
@@ -32047,6 +32048,8 @@
 				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);
 		}
 	}
 
@@ -32390,6 +32393,15 @@
 	if ((notify_types = ast_config_load(notify_config, config_flags)) == CONFIG_STATUS_FILEINVALID) {
 		ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed.\n", notify_config);
 		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);
@@ -34573,7 +34585,9 @@
 	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;
 }
@@ -34588,7 +34602,9 @@
 
 	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 3ed3e8a..82f208c 100644
--- a/channels/sip/include/sip.h
+++ b/channels/sip/include/sip.h
@@ -774,6 +774,7 @@
 	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 44d2d43..a24ab30 100644
--- a/configs/samples/sip.conf.sample
+++ b/configs/samples/sip.conf.sample
@@ -229,6 +229,10 @@
 				; 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

-- 
To view, visit https://gerrit.asterisk.org/1553
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I04fe8c4f2d57b2d7375e0e25826c91a72e93bea7
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Corey Farrell <git at cfware.com>



More information about the asterisk-code-review mailing list