[svn-commits] oej: branch oej/midcomstuff r53714 - in /team/oej/midcomstuff: channels/ incl...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Feb 9 09:14:39 MST 2007


Author: oej
Date: Fri Feb  9 10:14:38 2007
New Revision: 53714

URL: http://svn.digium.com/view/asterisk?view=rev&rev=53714
Log:
Adding a hook in rtp.c so that the midcom module registers to the core
and the SIP module checks whether or not we have midcom loaded.

Also, add a notifier so that RTP.c can notify SIP if the netsec
module is unloaded by force.

Thirdly, add a shutdown mode in res_netsec, so that no new calls will be handled
by the midcom device during shutdown.

Modified:
    team/oej/midcomstuff/channels/chan_sip.c
    team/oej/midcomstuff/include/asterisk/rtp.h
    team/oej/midcomstuff/main/rtp.c
    team/oej/midcomstuff/res/res_netsec.c

Modified: team/oej/midcomstuff/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/midcomstuff/channels/chan_sip.c?view=diff&rev=53714&r1=53713&r2=53714
==============================================================================
--- team/oej/midcomstuff/channels/chan_sip.c (original)
+++ team/oej/midcomstuff/channels/chan_sip.c Fri Feb  9 10:14:38 2007
@@ -1551,7 +1551,8 @@
 static void sip_get_capability_helper(void *p, int *codec, int *dtmf_payload);
 static void sip_softhangup_helper(void *p);
 
-extern struct ast_sip_hook_cb *midcom_cb;
+/*! Hook for midcom */
+struct ast_sip_hook_cb *midcom_cb = NULL;
 #endif
 
 /*! \brief Definition of this channel for PBX channel registration */
@@ -1751,6 +1752,16 @@
 	struct sip_pvt *dialog = (struct sip_pvt *) p;
 	if (dialog && (dialog->owner))
 		ast_softhangup(dialog->owner, AST_SOFTHANGUP_APPUNLOAD);
+}
+
+/*! \brief Activate or deactivate midcom */
+static int sip_midcom_notify(int state)
+{
+	if (!state)
+		midcom_cb = NULL;
+	else
+		midcom_cb = (struct ast_sip_hook_cb *) midcom_gethook(&sip_midcom_notify);
+	return TRUE;
 }
 #endif
 
@@ -17533,6 +17544,7 @@
 
 #ifdef SIP_MIDCOM
 	/* Register the sip helper functions */
+	sip_midcom_notify(TRUE);
 	if (midcom_cb)
 		 midcom_cb->ast_sip_helper_register(&sip_helper);
 #endif

Modified: team/oej/midcomstuff/include/asterisk/rtp.h
URL: http://svn.digium.com/view/asterisk/team/oej/midcomstuff/include/asterisk/rtp.h?view=diff&rev=53714&r1=53713&r2=53714
==============================================================================
--- team/oej/midcomstuff/include/asterisk/rtp.h (original)
+++ team/oej/midcomstuff/include/asterisk/rtp.h Fri Feb  9 10:14:38 2007
@@ -238,6 +238,12 @@
 /* \brief Put RTP timeout timers on hold during another transaction, like T.38 */
 void ast_rtp_set_rtptimers_onhold(struct ast_rtp *rtp);
 
+/*! \brief Midcom stub function to register midcom module */
+void midcom_register(void (* const midcom_gethook)(void));
+
+/*! \brief Get midcom hook to enable midcom support in channel module */
+void *midcom_gethook(int (* midcom_notify)(int));
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/oej/midcomstuff/main/rtp.c
URL: http://svn.digium.com/view/asterisk/team/oej/midcomstuff/main/rtp.c?view=diff&rev=53714&r1=53713&r2=53714
==============================================================================
--- team/oej/midcomstuff/main/rtp.c (original)
+++ team/oej/midcomstuff/main/rtp.c Fri Feb  9 10:14:38 2007
@@ -3658,3 +3658,29 @@
 	ast_rtp_reload();
 }
 
+/*! Hook to function that returns an ast_sip_hook_cb (res_netsec.h) to
+   connect to the netsec midcom support module */
+void *midcom_init;
+
+/*! Pointer back to the channel to notify about unload of midcom 
+	\note This will need to be a list when we have multiple channel clients
+*/
+int (* midcom_client_notify)(int);
+
+/*! Register midcom module */ 
+void midcom_register(void (* const midcom_hook)(void))
+{
+	midcom_init = (void *) midcom_hook;
+	if (midcom_client_notify)
+		(midcom_client_notify)(midcom_init ? 1 : 0);
+}
+
+/*! Get hook to midcom module 
+	Needs a callback module to the channel that gets the hook,
+	so we can alert of changes.
+*/
+void *midcom_gethook(int (* midcom_notify)(int))
+{
+	midcom_client_notify = midcom_notify;
+	return midcom_init;
+}

Modified: team/oej/midcomstuff/res/res_netsec.c
URL: http://svn.digium.com/view/asterisk/team/oej/midcomstuff/res/res_netsec.c?view=diff&rev=53714&r1=53713&r2=53714
==============================================================================
--- team/oej/midcomstuff/res/res_netsec.c (original)
+++ team/oej/midcomstuff/res/res_netsec.c Fri Feb  9 10:14:38 2007
@@ -111,8 +111,16 @@
 #define MIDCOM_NO_INIT   0x2
 #define MIDCOM_NO_TIMER  0x4
 
+static int shutdown_proceeding;
 static int usecnt = 0;
 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
+
+#ifndef TRUE
+	#define TRUE 1
+#endif
+#ifndef FALSE
+	#define FALSE 0
+#endif
 
 typedef enum {
 
@@ -308,7 +316,7 @@
 	 { { "netsec", "show", "version", NULL }, midcom_show_version, "Display the current version of the res_netsec module", show_version_usage }
 };
 
-/*--- midcom_sip: Interface structure with callbacks used to connect to sip module --*/
+/*! \brief  midcom_sip: Interface structure with callbacks used to connect to sip module --*/
 static struct ast_sip_hook_cb sip_hook = {
 	handle_request_invite_hook: midcom_handle_request_invite_hook,
 	handle_response_invite_hook: midcom_handle_response_invite_hook,
@@ -338,6 +346,7 @@
 
 static int load_module(void)
 {
+	shutdown_proceeding = FALSE;
 	midcom_enabled = 0;
 	midcom_err_state = 0;
 	if (midcom_config_reload()) {
@@ -358,7 +367,7 @@
 	}
 
 	/* Register the sip hook functions */
-	midcom_cb = &sip_hook;
+	midcom_register((void *) &sip_hook);
 
 	/* Register all CLI functions for midcom */
 	ast_cli_register_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
@@ -374,6 +383,7 @@
 	struct midcom_rule *r;
 	struct connection *c, *tconn;
 
+	shutdown_proceeding = TRUE;
 	r = midcom_rule_head;
 	if (r) {
 		 if (!ast_mutex_lock(&netsec_lock)) {
@@ -409,8 +419,9 @@
 	}
 
 	ast_mutex_destroy(&netsec_lock);
+
 	/* Unregister the sip hook functions */
-	midcom_cb = NULL;
+	midcom_register(NULL);
 
 	ast_cli_unregister_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0])); 
 	mc_close();
@@ -422,12 +433,11 @@
 
 
 
-/*--- midcom_enable_firewall: Turn on Midcom firewall (CLI command) */
+/*! \brief  midcom_enable_firewall: Turn on Midcom firewall (CLI command) */
 static int midcom_enable_firewall(int fd, int argc, char *argv[])
 {
 	int oldflag = midcom_enabled;
-	if(midcom_err_state)
-	{ 
+	if(midcom_err_state) { 
 		  ast_cli(fd, "Can not enable firewall. Module in inconsistent state. Run status command for more information\n");
 		  return RESULT_FAILURE;
 	} 
@@ -441,7 +451,7 @@
 	return RESULT_SUCCESS;
 }
 
-/*--- midcom_disable_firewall: Turn off Midcom firewall (CLI command) */
+/*! \brief  midcom_disable_firewall: Turn off Midcom firewall (CLI command) */
 static int midcom_disable_firewall(int fd, int argc, char *argv[])
 {
 	if (argc != 3)
@@ -451,7 +461,7 @@
 	return RESULT_SUCCESS;
 }
 
-/*--- midcom_show_firewall: Show Midcom firewall rules (CLI command) */
+/*! \brief  midcom_show_firewall: Show Midcom firewall rules (CLI command) */
 static int midcom_show_firewall(int fd, int argc, char *argv[])
 {
 	regex_t regexbuf;
@@ -619,7 +629,7 @@
 }
 
 
-/*--- midcom_show_version: Show the current version of Midcom module */
+/*! \brief  midcom_show_version: Show the current version of Midcom module */
 static int midcom_show_version(int fd, int argc, char *argv[])
 {
 
@@ -630,7 +640,7 @@
 }
 
 
-/*--- midcom_enable_debug: Enable debug prints on the Midcom module */
+/*! \brief  midcom_enable_debug: Enable debug prints on the Midcom module */
 static int midcom_enable_debug(int fd, int argc, char *argv[])
 {
 
@@ -642,7 +652,7 @@
 }
 
 
-/*--- midcom_disable_debug: Disable debug prints on the Midcom module */
+/*! \brief  midcom_disable_debug: Disable debug prints on the Midcom module */
 static int midcom_disable_debug(int fd, int argc, char *argv[])
 {
 
@@ -822,6 +832,9 @@
 {
 	struct midcom_rule *r = NULL;
 
+	if (shutdown_proceeding)
+		return 0;
+
 	if (!midcom_enabled) {
 		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
 		if (option_verbose > 1)
@@ -883,6 +896,9 @@
 static int midcom_transmit_response_with_sdp_hook(void *p)
 {
 	struct midcom_rule *r = NULL;
+
+	if (shutdown_proceeding)
+		return 0;
 
 	if (!midcom_enabled) {
 		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
@@ -946,6 +962,9 @@
 	int ret = 0;
 	struct midcom_rule *r = NULL;
 
+	if (shutdown_proceeding)
+		return 0;
+
 	if (!midcom_enabled) {
 		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
 		if (option_verbose > 1)
@@ -985,6 +1004,10 @@
 	struct connection *conn=NULL;
 	int lifetime;
 	int first_phone = 0;
+
+	if (shutdown_proceeding)
+		return 0;
+
 	if (option_debug)
 		ast_log(LOG_DEBUG, "MIDCOM :: We are here!\n");
 



More information about the svn-commits mailing list