Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.279 diff -u -r1.279 chan_sip.c --- channels/chan_sip.c 14 Jan 2004 06:10:53 -0000 1.279 +++ channels/chan_sip.c 19 Jan 2004 02:35:57 -0000 @@ -354,6 +354,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 @@ -4621,6 +4622,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 = @@ -4638,7 +4643,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; @@ -6441,52 +6448,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; @@ -6549,10 +6510,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(); @@ -6565,9 +6532,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; @@ -6581,6 +6605,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);