[asterisk-commits] russell: branch russell/sla_rewrite r51462 - /team/russell/sla_rewrite/apps/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jan 22 15:59:13 MST 2007


Author: russell
Date: Mon Jan 22 16:59:12 2007
New Revision: 51462

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51462
Log:
Implement the autocontext option for stations.  The automatic dialplan
configuration for SLA is done now ...

Modified:
    team/russell/sla_rewrite/apps/app_meetme.c

Modified: team/russell/sla_rewrite/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/russell/sla_rewrite/apps/app_meetme.c?view=diff&rev=51462&r1=51461&r2=51462
==============================================================================
--- team/russell/sla_rewrite/apps/app_meetme.c (original)
+++ team/russell/sla_rewrite/apps/app_meetme.c Mon Jan 22 16:59:12 2007
@@ -2731,6 +2731,19 @@
 {
 	struct sla_trunk_ref *trunk_ref;
 
+	if (!ast_strlen_zero(station->autocontext)) {
+		AST_RWLIST_RDLOCK(&sla_trunks);
+		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
+			char exten[AST_MAX_EXTENSION];
+			snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
+			ast_context_remove_extension(station->autocontext, exten, 
+				1, sla_registrar);
+			ast_context_remove_extension(station->autocontext, exten, 
+				PRIORITY_HINT, sla_registrar);
+		}
+		AST_RWLIST_UNLOCK(&sla_trunks);
+	}
+
 	while ((trunk_ref = AST_LIST_REMOVE_HEAD(&station->trunks, entry)))
 		free(trunk_ref);
 
@@ -2794,7 +2807,7 @@
 			return -1;
 		}
 		if (ast_add_extension2(context, 0 /* don't replace */, "s", 1,
-			NULL, NULL, slatrunk_app, (void *) trunk->name, NULL, sla_registrar)) {
+			NULL, NULL, slatrunk_app, ast_strdup(trunk->name), ast_free, sla_registrar)) {
 			ast_log(LOG_ERROR, "Failed to automatically create extension "
 				"for trunk '%s'!\n", trunk->name);
 			destroy_trunk(trunk);
@@ -2856,6 +2869,51 @@
 		}
 	}
 
+	if (!ast_strlen_zero(station->autocontext)) {
+		struct ast_context *context;
+		struct sla_trunk_ref *trunk_ref;
+		context = ast_context_find_or_create(NULL, station->autocontext, sla_registrar);
+		if (!context) {
+			ast_log(LOG_ERROR, "Failed to automatically find or create "
+				"context '%s' for SLA!\n", station->autocontext);
+			destroy_station(station);
+			return -1;
+		}
+		/* The extension for when the handset goes off-hook.
+		 * exten => station1,1,SLAStation(station1) */
+		if (ast_add_extension2(context, 0 /* don't replace */, station->name, 1,
+			NULL, NULL, slastation_app, ast_strdup(station->name), ast_free, sla_registrar)) {
+			ast_log(LOG_ERROR, "Failed to automatically create extension "
+				"for trunk '%s'!\n", station->name);
+			destroy_station(station);
+			return -1;
+		}
+		AST_RWLIST_RDLOCK(&sla_trunks);
+		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
+			char exten[AST_MAX_EXTENSION];
+			snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
+			/* Extension for this line button 
+			 * exten => station1_line1,1,SLAStation(station1_line1) */
+			if (ast_add_extension2(context, 0 /* don't replace */, exten, 1,
+				NULL, NULL, slastation_app, ast_strdup(exten), ast_free, sla_registrar)) {
+				ast_log(LOG_ERROR, "Failed to automatically create extension "
+					"for trunk '%s'!\n", station->name);
+				destroy_station(station);
+				return -1;
+			}
+			/* Hint for this line button 
+			 * exten => station1_line1,hint,SLA:station1_line1 */
+			if (ast_add_extension2(context, 0 /* don't replace */, exten, PRIORITY_HINT,
+				NULL, NULL, slastation_app, ast_strdup(exten), ast_free, sla_registrar)) {
+				ast_log(LOG_ERROR, "Failed to automatically create hint "
+					"for trunk '%s'!\n", station->name);
+				destroy_station(station);
+				return -1;
+			}
+		}
+		AST_RWLIST_UNLOCK(&sla_trunks);
+	}
+
 	AST_RWLIST_WRLOCK(&sla_stations);
 	AST_RWLIST_INSERT_HEAD(&sla_stations, station, entry);
 	AST_RWLIST_UNLOCK(&sla_stations);
@@ -2897,10 +2955,15 @@
 	return res;
 }
 
-static int load_config(void)
-{
+static int load_config(int reload)
+{
+	int res = 0;
+
 	load_config_meetme();
-	return load_config_sla();
+	if (!reload)
+		res = load_config_sla();
+
+	return res;
 }
 
 static int unload_module(void)
@@ -2946,14 +3009,14 @@
 	res |= ast_devstate_prov_add("Meetme", meetmestate);
 	res |= ast_devstate_prov_add("SLA", sla_state);
 
-	load_config();
+	res |= load_config(0);
+
 	return res;
 }
 
 static int reload(void)
 {
-	destroy_sla();
-	return load_config();
+	return load_config(1);
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "MeetMe conference bridge",



More information about the asterisk-commits mailing list