[asterisk-commits] oej: branch oej/pine-brutal-sip-experiments-1.4 r300156 - in /team/oej/pine-b...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 3 14:33:47 UTC 2011


Author: oej
Date: Mon Jan  3 08:33:43 2011
New Revision: 300156

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=300156
Log:
Brutal code to be able to load multiple SIP channels in a running asterisk system.

Modified:
    team/oej/pine-brutal-sip-experiments-1.4/channels/chan_sip.c
    team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/channel.h
    team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/module.h
    team/oej/pine-brutal-sip-experiments-1.4/main/loader.c

Modified: team/oej/pine-brutal-sip-experiments-1.4/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-brutal-sip-experiments-1.4/channels/chan_sip.c?view=diff&rev=300156&r1=300155&r2=300156
==============================================================================
--- team/oej/pine-brutal-sip-experiments-1.4/channels/chan_sip.c (original)
+++ team/oej/pine-brutal-sip-experiments-1.4/channels/chan_sip.c Mon Jan  3 08:33:43 2011
@@ -1702,6 +1702,24 @@
 	.func_channel_read = acf_channel_read,
 };
 
+/*! \brief SIP tech for dynamic channel loading. */
+static struct ast_channel_tech *dynamic_sip_tech;
+
+struct sip_chan_types {
+	const char const *type;
+} dynamic_channel_types[10] = {
+	{ "SIP00", },
+	{ "SIP01", },
+	{ "SIP02", },
+	{ "SIP03", },
+	{ "SIP04", },
+	{ "SIP05", },
+	{ "SIP06", },
+	{ "SIP07", },
+	{ "SIP08", },
+	{ "SIP09", },
+};
+
 /**--- some list management macros. **/
  
 #define UNLINK(element, head, prev) do {	\
@@ -1726,6 +1744,15 @@
 	get_udptl_info: sip_get_udptl_peer,
 	set_udptl_peer: sip_set_udptl_peer,
 };
+
+/*! \brief return TRUE if the tech is our own tech */
+static int check_if_sip_tech(const struct ast_channel_tech *tech)
+{
+	if (tech != &sip_tech && tech != &sip_tech_info) {
+		return FALSE;
+	}
+	return TRUE;
+}
 
 /*! \brief Convert transfer status to string */
 static char *referstatus2str(enum referstatus rstatus)
@@ -12871,7 +12898,7 @@
 	}
 
 	ast_channel_lock(chan);
-	if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) {
+	if (!check_if_sip_tech(chan->tech)) {
 		ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
 		ast_channel_unlock(chan);
 		return -1;
@@ -13050,7 +13077,7 @@
 	}
 
 	ast_channel_lock(chan);
-	if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) {
+	if (!check_if_sip_tech(chan->tech)) {
 		ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n");
 		ast_channel_unlock(chan);
 		return -1;
@@ -13360,7 +13387,7 @@
 				ast_log(LOG_WARNING, "Ooooh.. no tech!  That's REALLY bad\n");
 				break;
 			}
-			if (bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) {
+			if (check_if_sip_tech(bridgepeer->tech)) {
 				bridgepvt = (struct sip_pvt*)(bridgepeer->tech_pvt);
 				if (bridgepvt->udptl) {
 					if (p->t38.state == T38_PEER_REINVITE) {
@@ -13493,7 +13520,7 @@
 
 			if (p->owner && (p->owner->_state == AST_STATE_UP) && (bridgepeer = ast_bridged_channel(p->owner))) { /* if this is a re-invite */
 				struct sip_pvt *bridgepvt = NULL;
-				if (bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) {
+				if (check_if_sip_tech(bridgepeer->tech)) {
 					bridgepvt = (struct sip_pvt*)(bridgepeer->tech_pvt);
 					if (bridgepvt->udptl) {
 						sip_handle_t38_reinvite(bridgepeer, p, 0);
@@ -15687,7 +15714,7 @@
 				if ((bridgepeer = ast_bridged_channel(p->owner))) {
 					/* We have a bridge, and this is re-invite to switchover to T38 so we send re-invite with T38 SDP, to other side of bridge*/
 					/*! XXX: we should also check here does the other side supports t38 at all !!! XXX */
-					if (bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) {
+					if (check_if_sip_tech(bridgepeer->tech)) {
 						bridgepvt = (struct sip_pvt*)bridgepeer->tech_pvt;
 						if (bridgepvt->t38.state == T38_DISABLED) {
 							if (bridgepvt->udptl) { /* If everything is OK with other side's udptl struct */
@@ -16294,7 +16321,7 @@
 	AST_STANDARD_APP_ARGS(args, parse);
 
 	/* Sanity check */
-	if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) {
+	if (!check_if_sip_tech(chan->tech)) {
 		ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname);
 		return 0;
 	}
@@ -18729,7 +18756,13 @@
 	unsigned int temp_tos = 0;
 	struct ast_flags debugflag = {0};
 
-	cfg = ast_config_load(config);
+	if (dynamic_sip_tech) {
+		char configfile[SIPBUFSIZE];
+		snprintf(configfile, sizeof(configfile), "%s.%s", config, dynamic_sip_tech->type);
+		cfg = ast_config_load(configfile);
+	} else {
+		cfg = ast_config_load(config);
+	}
 
 	/* We *must* have a config file otherwise stop immediately */
 	if (!cfg) {
@@ -19635,7 +19668,7 @@
 		return 0;
 	}
 	ast_channel_lock(chan);
-	if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) {
+	if (!check_if_sip_tech(chan->tech)) {
 		ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n");
 		ast_channel_unlock(chan);
 		return 0;
@@ -19994,6 +20027,15 @@
 /*! \brief PBX load module - initialization */
 static int load_module(void)
 {
+	ast_log(LOG_DEBUG, "***** HEY YOU DEBUGGER: %s \n", ast_module_name(ast_module_info->self));
+	if (strcasecmp(ast_module_name(ast_module_info->self), "chan_sip.so")) {
+		ast_log(LOG_DEBUG, "*** We're not who we are supposed to be.\n");
+		dynamic_sip_tech = ast_calloc(1, sizeof(struct ast_channel_tech));
+		memcpy(dynamic_sip_tech, &sip_tech, sizeof(struct ast_channel_tech));
+		dynamic_sip_tech->type = "SIP00";
+	} else {
+		dynamic_sip_tech = NULL;
+	}
 	ASTOBJ_CONTAINER_INIT(&userl);	/* User object list */
 	ASTOBJ_CONTAINER_INIT(&peerl);	/* Peer object list */
 	ASTOBJ_CONTAINER_INIT(&regl);	/* Registry object list */
@@ -20015,7 +20057,7 @@
 		return AST_MODULE_LOAD_DECLINE;
 
 	/* Make sure we can register our sip channel type */
-	if (ast_channel_register(&sip_tech)) {
+	if (ast_channel_register(dynamic_sip_tech ? dynamic_sip_tech : &sip_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
 		io_context_destroy(io);
 		sched_context_destroy(sched);

Modified: team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/channel.h?view=diff&rev=300156&r1=300155&r2=300156
==============================================================================
--- team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/channel.h (original)
+++ team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/channel.h Mon Jan  3 08:33:43 2011
@@ -225,7 +225,8 @@
 	implemented.
 */
 struct ast_channel_tech {
-	const char * const type;
+	//const char * const type;
+	const char * type;
 	const char * const description;
 
 	int capabilities;		/*!< Bitmap of formats this channel can handle */

Modified: team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/module.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/module.h?view=diff&rev=300156&r1=300155&r2=300156
==============================================================================
--- team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/module.h (original)
+++ team/oej/pine-brutal-sip-experiments-1.4/include/asterisk/module.h Mon Jan  3 08:33:43 2011
@@ -231,6 +231,7 @@
 
 struct ast_module *ast_module_ref(struct ast_module *);
 void ast_module_unref(struct ast_module *);
+const char *ast_module_name(struct ast_module *mod);
 
 #if defined(__cplusplus) || defined(c_plusplus)
 #define AST_MODULE_INFO(keystr, flags_to_set, desc, load_func, unload_func, reload_func)	\

Modified: team/oej/pine-brutal-sip-experiments-1.4/main/loader.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pine-brutal-sip-experiments-1.4/main/loader.c?view=diff&rev=300156&r1=300155&r2=300156
==============================================================================
--- team/oej/pine-brutal-sip-experiments-1.4/main/loader.c (original)
+++ team/oej/pine-brutal-sip-experiments-1.4/main/loader.c Mon Jan  3 08:33:43 2011
@@ -1096,6 +1096,14 @@
 	return cur ? 0 : -1;
 }
 
+const char *ast_module_name(struct ast_module *mod)
+{
+	if (!mod) {
+		return NULL;
+	}
+	return mod->resource;
+}
+
 struct ast_module *ast_module_ref(struct ast_module *mod)
 {
 	ast_atomic_fetchadd_int(&mod->usecount, +1);




More information about the asterisk-commits mailing list