[Asterisk-cvs] asterisk/channels chan_sip.c,1.280,1.281

markster at lists.digium.com markster at lists.digium.com
Fri Jan 23 09:51:34 CST 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv18615/channels

Modified Files:
	chan_sip.c 
Log Message:
Create individual sip reload command (bug #880)


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.280
retrieving revision 1.281
diff -u -d -r1.280 -r1.281
--- chan_sip.c	22 Jan 2004 16:29:02 -0000	1.280
+++ chan_sip.c	23 Jan 2004 15:43:31 -0000	1.281
@@ -368,6 +368,7 @@
 	ast_mutex_t lock;
 } peerl = { NULL, AST_MUTEX_INITIALIZER };
 
+ast_mutex_t sip_reload_lock = AST_MUTEX_INITIALIZER;
 
 #define REG_STATE_UNREGISTERED 0
 #define REG_STATE_REGSENT	   1
@@ -4760,6 +4761,10 @@
 "Usage: sip no debug\n"
 "       Disables dumping of SIP packets for debugging purposes\n";
 
+static char sip_reload_usage[] =
+"Usage: sip reload\n"
+"       Reloads SIP configuration from sip.conf\n";
+
 static struct ast_cli_entry  cli_show_users = 
 	{ { "sip", "show", "users", NULL }, sip_show_users, "Show defined SIP users", show_users_usage };
 static struct ast_cli_entry  cli_show_channels =
@@ -4777,7 +4782,6 @@
 static struct ast_cli_entry  cli_no_debug =
 	{ { "sip", "no", "debug", NULL }, sip_no_debug, "Disable SIP debugging", no_debug_usage };
 
-
 static int sip_poke_peer_s(void *data)
 {
 	struct sip_peer *peer = data;
@@ -6605,52 +6609,6 @@
 	get_codec: sip_get_codec,
 };
 
-int load_module()
-{
-	int res;
-	struct sip_peer *peer;
-	struct sip_registry *reg;
-	sched = sched_context_create();
-	if (!sched) {
-		ast_log(LOG_WARNING, "Unable to create schedule context\n");
-	}
-	io = io_context_create();
-	if (!io) {
-		ast_log(LOG_WARNING, "Unable to create I/O context\n");
-	}
-	
-	res = reload_config();
-	if (!res) {
-		/* Make sure we can register our sip channel type */
-		if (ast_channel_register_ex(type, tdesc, capability, sip_request, sip_devicestate)) {
-			ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
-			return -1;
-		}
-		ast_cli_register(&cli_show_users);
-		ast_cli_register(&cli_show_channels);
-		ast_cli_register(&cli_show_channel);
-		ast_cli_register(&cli_show_peers);
-		ast_cli_register(&cli_show_registry);
-		ast_cli_register(&cli_debug);
-		ast_cli_register(&cli_no_debug);
-		ast_cli_register(&cli_inuse_show);
-		sip_rtp.type = type;
-		ast_rtp_proto_register(&sip_rtp);
-		ast_register_application(app_dtmfmode, sip_dtmfmode, synopsis_dtmfmode, descrip_dtmfmode);
-		ast_mutex_lock(&peerl.lock);
-		for (peer = peerl.peers; peer; peer = peer->next)
-			sip_poke_peer(peer);
-
-		for (reg = registrations; reg; reg = reg->next) 
-			sip_do_register(reg);
-		ast_mutex_unlock(&peerl.lock);
-		
-		/* And start the monitor for the first time */
-		restart_monitor();
-	}
-	return res;
-}
-
 static void delete_users(void)
 {
 	struct sip_user *user, *userlast;
@@ -6713,10 +6671,16 @@
 	ast_mutex_unlock(&peerl.lock);
 }
 
-int reload(void)
+static int sip_reload(int fd, int argc, char *argv[])
 {
 	struct sip_registry *reg;
 	struct sip_peer *peer;
+
+	if (ast_mutex_trylock(&sip_reload_lock) == EBUSY) {
+		ast_verbose("Previous SIP reload not yet done\n");
+		return -1;
+	}
+
 	delete_users();
 	reload_config();
 
@@ -6729,9 +6693,66 @@
 	for (peer = peerl.peers; peer; peer = peer->next)
 		sip_poke_peer(peer);
 	ast_mutex_unlock(&peerl.lock);
+	ast_mutex_unlock(&sip_reload_lock);
+
 	return 0;
 }
 
+int reload(void)
+{
+	return sip_reload(0, 0, NULL);
+}
+
+static struct ast_cli_entry  cli_sip_reload =
+	{ { "sip", "reload", NULL }, sip_reload, "Reload SIP configuration", sip_reload_usage };
+
+int load_module()
+{
+	int res;
+	struct sip_peer *peer;
+	struct sip_registry *reg;
+	sched = sched_context_create();
+	if (!sched) {
+		ast_log(LOG_WARNING, "Unable to create schedule context\n");
+	}
+	io = io_context_create();
+	if (!io) {
+		ast_log(LOG_WARNING, "Unable to create I/O context\n");
+	}
+	
+	res = reload_config();
+	if (!res) {
+		/* Make sure we can register our sip channel type */
+		if (ast_channel_register_ex(type, tdesc, capability, sip_request, sip_devicestate)) {
+			ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
+			return -1;
+		}
+		ast_cli_register(&cli_show_users);
+		ast_cli_register(&cli_show_channels);
+		ast_cli_register(&cli_show_channel);
+		ast_cli_register(&cli_show_peers);
+		ast_cli_register(&cli_show_registry);
+		ast_cli_register(&cli_debug);
+		ast_cli_register(&cli_no_debug);
+		ast_cli_register(&cli_sip_reload);
+		ast_cli_register(&cli_inuse_show);
+		sip_rtp.type = type;
+		ast_rtp_proto_register(&sip_rtp);
+		ast_register_application(app_dtmfmode, sip_dtmfmode, synopsis_dtmfmode, descrip_dtmfmode);
+		ast_mutex_lock(&peerl.lock);
+		for (peer = peerl.peers; peer; peer = peer->next)
+			sip_poke_peer(peer);
+
+		for (reg = registrations; reg; reg = reg->next) 
+			sip_do_register(reg);
+		ast_mutex_unlock(&peerl.lock);
+		
+		/* And start the monitor for the first time */
+		restart_monitor();
+	}
+	return res;
+}
+
 int unload_module()
 {
 	struct sip_pvt *p, *pl;
@@ -6745,6 +6766,7 @@
 	ast_cli_unregister(&cli_show_registry);
 	ast_cli_unregister(&cli_debug);
 	ast_cli_unregister(&cli_no_debug);
+	ast_cli_unregister(&cli_sip_reload);
 	ast_cli_unregister(&cli_inuse_show);
 	ast_rtp_proto_unregister(&sip_rtp);
 	ast_channel_unregister(type);




More information about the svn-commits mailing list