Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.906 diff -u -r1.906 chan_sip.c --- channels/chan_sip.c 31 Oct 2005 23:38:40 -0000 1.906 +++ channels/chan_sip.c 14 Nov 2005 08:48:44 -0000 @@ -23,9 +23,11 @@ * Implementation of RFC 3261 - without S/MIME, TCP and TLS support * Configuration file \link Config_sip sip.conf \endlink * + * * \todo SIP over TCP * \todo SIP over TLS * \todo Better support of forking + * \ingroup channel_drivers */ @@ -155,6 +157,13 @@ bad things will happen. */ +enum channelreloadreason { + CHANNEL_MODULE_LOAD, + CHANNEL_MODULE_RELOAD, + CHANNEL_CLI_RELOAD, + CHANNEL_MANAGER_RELOAD, +}; + enum subscriptiontype { NONE = 0, TIMEOUT, @@ -793,6 +802,7 @@ AST_MUTEX_DEFINE_STATIC(sip_reload_lock); static int sip_reloading = 0; +static enum channelreloadreason sip_reloadreason; /* States for outbound registrations (with register= lines in sip.conf */ #define REG_STATE_UNREGISTERED 0 @@ -894,7 +904,7 @@ static int update_call_counter(struct sip_pvt *fup, int event); static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime); static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime); -static int sip_do_reload(void); +static int sip_do_reload(enum channelreloadreason reason); static int expire_register(void *data); static int callevents = 0; @@ -942,6 +952,19 @@ .bridge = ast_rtp_bridge, .send_text = sip_sendtext, }; +const char *channelreloadreason2txt(enum channelreloadreason reason) { + switch (reason) { + case CHANNEL_MODULE_LOAD: return "LOAD (Channel module load)"; + break; + case CHANNEL_MODULE_RELOAD: return "RELOAD (Channel module reload)"; + break; + case CHANNEL_CLI_RELOAD: return "CLIRELOAD (Channel module reload by CLI command)"; + break; + default: return "MANAGERRELOAD (Channel module reload by manager)"; + break; + } +}; + /*! \brief find_sip_method: Find SIP method from header * Strictly speaking, SIP methods are case SENSITIVE, but we don't check @@ -7377,7 +7400,8 @@ static int _sip_show_peers(int fd, int *total, struct mansession *s, struct message *m, int argc, char *argv[]); -/*! \brief manager_sip_show_peers: Show SIP peers in the manager API ---*/ +/*! \brief manager_sip_show_peers: Show SIP peers in the manager API +\amicommands SIPpeers Lists SIP peers */ /* Inspired from chan_iax2 */ static int manager_sip_show_peers( struct mansession *s, struct message *m ) { @@ -9143,6 +9167,7 @@ } +/*! \ingroup functions */ static struct ast_custom_function sip_header_function = { .name = "SIP_HEADER", .synopsis = "Gets or sets the specified SIP header", @@ -9164,6 +9189,7 @@ return buf; } +/*! \ingroup functions */ static struct ast_custom_function checksipdomain_function = { .name = "CHECKSIPDOMAIN", .synopsis = "Checks if domain is a local domain", @@ -9248,7 +9274,8 @@ return ret; } -/* Structure to declare a dialplan function: SIPPEER */ +/*! \brief Structure to declare a dialplan function: SIPPEER + \ingroup functions */ struct ast_custom_function sippeer_function = { .name = "SIPPEER", .synopsis = "Gets SIP peer information", @@ -9324,7 +9351,8 @@ return buf; } -/* Structure to declare a dialplan function: SIPCHANINFO */ +/* Structure to declare a dialplan function: SIPCHANINFO + \ingroup functions */ static struct ast_custom_function sipchaninfo_function = { .name = "SIPCHANINFO", .synopsis = "Gets the specified SIP parameter from the current channel", @@ -11156,7 +11184,7 @@ if (reloading) { if (option_verbose > 0) ast_verbose(VERBOSE_PREFIX_1 "Reloading SIP\n"); - sip_do_reload(); + sip_do_reload(sip_reloadreason); } /* Check for interfaces needing to be killed */ ast_mutex_lock(&iflock); @@ -12192,7 +12220,7 @@ change configuration data at restart, not at reload. SIP debug and recordhistory state will not change */ -static int reload_config(void) +static int reload_config(enum channelreloadreason reason) { struct ast_config *cfg; struct ast_variable *v; @@ -12207,6 +12235,7 @@ struct ast_flags dummy; int auto_sip_domains = 0; struct sockaddr_in old_bindaddr = bindaddr; + int registry_count = 0, peer_count = 0, user_count = 0; cfg = ast_config_load(config); @@ -12434,7 +12463,8 @@ else add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, context ? ast_strip(context) : ""); } else if (!strcasecmp(v->name, "register")) { - sip_register(v->value, v->lineno); + if (sip_register(v->value, v->lineno) == 0) + registry_count++; } else if (!strcasecmp(v->name, "tos")) { if (ast_str2tos(v->value, &tos)) ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno); @@ -12488,6 +12518,7 @@ if (user) { ASTOBJ_CONTAINER_LINK(&userl,user); ASTOBJ_UNREF(user, sip_destroy_user); + user_count++; } } if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) { @@ -12495,6 +12526,7 @@ if (peer) { ASTOBJ_CONTAINER_LINK(&peerl,peer); ASTOBJ_UNREF(peer, sip_destroy_peer); + peer_count++; } } else if (strcasecmp(utype, "user")) { ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf"); @@ -12584,6 +12616,9 @@ ast_config_destroy(notify_types); notify_types = ast_config_load(notify_config); + /* Done, tell the manager */ + manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "Channel: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\nUser_Count: %d\r\n\r\n", channelreloadreason2txt(reason), registry_count, peer_count, user_count); + return 0; } @@ -12934,7 +12969,7 @@ } /*! \brief sip_do_reload: Reload module */ -static int sip_do_reload(void) +static int sip_do_reload(enum channelreloadreason reason) { clear_realm_authentication(authl); clear_sip_domains(); @@ -12943,7 +12978,7 @@ ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user); ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); ASTOBJ_CONTAINER_MARKALL(&peerl); - reload_config(); + reload_config(reason); /* Prune peers who still are supposed to be deleted */ ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, sip_destroy_peer); @@ -12960,8 +12995,13 @@ ast_mutex_lock(&sip_reload_lock); if (sip_reloading) { ast_verbose("Previous SIP reload not yet done\n"); - } else + } else { sip_reloading = 1; + if (fd) + sip_reloadreason = CHANNEL_CLI_RELOAD; + else + sip_reloadreason = CHANNEL_MODULE_RELOAD; + } ast_mutex_unlock(&sip_reload_lock); restart_monitor(); @@ -13020,8 +13060,8 @@ if (!io) { ast_log(LOG_WARNING, "Unable to create I/O context\n"); } - - reload_config(); /* Load the configuration from sip.conf */ + sip_reloadreason = CHANNEL_MODULE_LOAD; + reload_config(sip_reloadreason); /* Load the configuration from sip.conf */ /* Make sure we can register our sip channel type */ if (ast_channel_register(&sip_tech)) {