[svn-commits] dvossel: branch dvossel/stun_monitor r281725 - /team/dvossel/stun_monitor/cha...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 11 10:19:29 CDT 2010


Author: dvossel
Date: Wed Aug 11 10:19:25 2010
New Revision: 281725

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281725
Log:
iax outbound registrations now renew on network change event

Modified:
    team/dvossel/stun_monitor/channels/chan_iax2.c
    team/dvossel/stun_monitor/channels/chan_sip.c

Modified: team/dvossel/stun_monitor/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/channels/chan_iax2.c?view=diff&rev=281725&r1=281724&r2=281725
==============================================================================
--- team/dvossel/stun_monitor/channels/chan_iax2.c (original)
+++ team/dvossel/stun_monitor/channels/chan_iax2.c Wed Aug 11 10:19:25 2010
@@ -268,6 +268,8 @@
 static char language[MAX_LANGUAGE] = "";
 static char regcontext[AST_MAX_CONTEXT] = "";
 
+static struct ast_event_sub *network_change_event_subscription = NULL; /*!< subscription id for network change events */
+
 static int maxauthreq = 3;
 static int max_retries = 4;
 static int ping_time = 21;
@@ -1201,6 +1203,7 @@
 static struct callno_entry *get_unused_callno(int trunk, int validated);
 static int replace_callno(const void *obj);
 static void sched_delay_remove(struct sockaddr_in *sin, struct callno_entry *callno_entry);
+static void network_change_event_cb(const struct ast_event *, void *);
 
 static const struct ast_channel_tech iax2_tech = {
 	.type = "IAX2",
@@ -1236,6 +1239,36 @@
 	 * is time to send MWI, since it is only sent with a REGACK. */
 }
 
+static inline void network_change_event_subscribe(void)
+{
+	if (!network_change_event_subscription) {
+		network_change_event_subscription = ast_event_subscribe(AST_EVENT_NETWORK_CHANGE,
+			network_change_event_cb,
+			"SIP Network Change ",
+			NULL);
+	}
+}
+
+static inline void network_change_event_unsubscribe(void)
+{
+	if (network_change_event_subscription) {
+		network_change_event_subscription = ast_event_unsubscribe(network_change_event_subscription);
+	}
+}
+
+static void network_change_event_cb(const struct ast_event *event, void *userdata)
+{
+	struct iax2_registry *reg;
+	if (option_debug) {
+		ast_log(LOG_DEBUG, "IAX, got a network change event, renewing all IAX registrations.\n");
+	}
+	AST_LIST_LOCK(&registrations);
+	AST_LIST_TRAVERSE(&registrations, reg, entry)
+		iax2_do_register(reg);
+	AST_LIST_UNLOCK(&registrations);
+}
+
+
 /*! \brief Send manager event at call setup to link between Asterisk channel name
 	and IAX2 call identifiers */
 static void iax2_ami_channelupdate(struct chan_iax2_pvt *pvt) 
@@ -1245,7 +1278,6 @@
 		pvt->owner ? pvt->owner->name : "",
 		pvt->callno, pvt->peercallno, pvt->peer ? pvt->peer : "");
 }
-
 
 static struct ast_datastore_info iax2_variable_datastore_info = {
 	.type = "IAX2_VARIABLE",
@@ -13097,6 +13129,14 @@
 			if (add_calltoken_ignore(v->value)) {
 				ast_log(LOG_WARNING, "Invalid calltokenoptional address range - '%s' line %d\n", v->value, v->lineno);
 			}
+		} else if (!strcasecmp(v->name, "subscribe_network_change_event")) {
+			if (ast_true(v->value)) {
+				network_change_event_subscribe();
+			} else if (ast_false(v->value)) {
+				network_change_event_unsubscribe();
+			} else {
+				ast_log(LOG_WARNING, "subscribe_network_change_event value %s is not valid at line %d.\n", v->value, v->lineno);
+			}
 		} else if (!strcasecmp(v->name, "shrinkcallerid")) {
 			if (ast_true(v->value)) {
 				ast_set_flag64((&globalflags), IAX_SHRINKCALLERID);
@@ -14050,6 +14090,8 @@
 	struct ast_context *con;
 	int x;
 
+	network_change_event_unsubscribe();
+
 	ast_manager_unregister("IAXpeers");
 	ast_manager_unregister("IAXpeerlist");
 	ast_manager_unregister("IAXnetstats");
@@ -14530,6 +14572,8 @@
 
 	ast_realtime_require_field("iaxpeers", "name", RQ_CHAR, 10, "ipaddr", RQ_CHAR, 15, "port", RQ_UINTEGER2, 5, "regseconds", RQ_UINTEGER2, 6, SENTINEL);
 
+	network_change_event_subscribe();
+
 	return AST_MODULE_LOAD_SUCCESS;
 }
 

Modified: team/dvossel/stun_monitor/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/channels/chan_sip.c?view=diff&rev=281725&r1=281724&r2=281725
==============================================================================
--- team/dvossel/stun_monitor/channels/chan_sip.c (original)
+++ team/dvossel/stun_monitor/channels/chan_sip.c Wed Aug 11 10:19:25 2010
@@ -762,7 +762,7 @@
 static struct ast_flags global_flags[3] = {{0}};  /*!< global SIP_ flags */
 static int global_t38_maxdatagram;                /*!< global T.38 FaxMaxDatagram override */
 
-static struct ast_event_sub *network_change_event_subscription = NULL;     /*!< subscription id for network change events */
+static struct ast_event_sub *network_change_event_subscription = NULL; /*!< subscription id for network change events */
 
 static char used_context[AST_MAX_CONTEXT];        /*!< name of automatically created context for unloading */
 
@@ -28405,6 +28405,8 @@
 	struct ast_context *con;
 	struct ao2_iterator i;
 
+	network_change_event_unsubscribe();
+
 	ast_sched_dump(sched);
 	
 	/* First, take us out of the channel type list */
@@ -28535,7 +28537,6 @@
 	ast_cc_agent_unregister(&sip_cc_agent_callbacks);
 
 	sip_reqresp_parser_exit();
-	network_change_event_unsubscribe();
 	sip_unregister_tests();
 
 	return 0;




More information about the svn-commits mailing list