[svn-commits] russell: branch russell/sla_rewrite r51460 - /team/russell/sla_rewrite/apps/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Jan 22 14:54:18 MST 2007


Author: russell
Date: Mon Jan 22 15:54:17 2007
New Revision: 51460

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51460
Log:
- Start supporting module reload for SLA configuration
- Implement the "autocontext" option for trunks

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=51460&r1=51459&r2=51460
==============================================================================
--- team/russell/sla_rewrite/apps/app_meetme.c (original)
+++ team/russell/sla_rewrite/apps/app_meetme.c Mon Jan 22 15:54:17 2007
@@ -356,6 +356,8 @@
 
 static AST_RWLIST_HEAD_STATIC(sla_stations, sla_station);
 static AST_RWLIST_HEAD_STATIC(sla_trunks, sla_trunk);
+
+static const char sla_registrar[] = "SLA";
 
 /*! The number of audio buffers to be allocated on pseudo channels
  *  when in a conference */
@@ -2675,21 +2677,6 @@
 	return AST_DEVICE_INUSE;
 }
 
-static int slastation_exec(struct ast_channel *chan, void *data)
-{
-	return 0;
-}
-
-static int slatrunk_exec(struct ast_channel *chan, void *data)
-{
-	return 0;
-}
-
-static int sla_state(const char *data)
-{
-	return AST_DEVICE_INUSE;
-}
-
 static void load_config_meetme(void)
 {
 	struct ast_config *cfg;
@@ -2716,6 +2703,57 @@
 	ast_config_destroy(cfg);
 }
 
+static int slastation_exec(struct ast_channel *chan, void *data)
+{
+	return 0;
+}
+
+static int slatrunk_exec(struct ast_channel *chan, void *data)
+{
+	return 0;
+}
+
+static int sla_state(const char *data)
+{
+	return AST_DEVICE_INUSE;
+}
+
+static void destroy_trunk(struct sla_trunk *trunk)
+{
+	if (!ast_strlen_zero(trunk->autocontext))
+		ast_context_remove_extension(trunk->autocontext, "s", 1, sla_registrar);
+
+	ast_string_field_free_all(trunk);
+	free(trunk);
+}
+
+static void destroy_station(struct sla_station *station)
+{
+	struct sla_trunk_ref *trunk_ref;
+
+	while ((trunk_ref = AST_LIST_REMOVE_HEAD(&station->trunks, entry)))
+		free(trunk_ref);
+
+	ast_string_field_free_all(station);
+	free(station);
+}
+
+static void destroy_sla(void)
+{
+	struct sla_trunk *trunk;
+	struct sla_station *station;
+
+	AST_RWLIST_WRLOCK(&sla_trunks);
+	while ((trunk = AST_RWLIST_REMOVE_HEAD(&sla_trunks, entry)))
+		destroy_trunk(trunk);
+	AST_RWLIST_UNLOCK(&sla_trunks);
+
+	AST_RWLIST_WRLOCK(&sla_stations);
+	while ((station = AST_RWLIST_REMOVE_HEAD(&sla_stations, entry)))
+		destroy_station(station);
+	AST_RWLIST_UNLOCK(&sla_stations);
+}
+
 static int build_trunk(struct ast_config *cfg, const char *cat)
 {
 	struct sla_trunk *trunk;
@@ -2740,9 +2778,27 @@
 	for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
 		if (!strcasecmp(var->name, "autocontext"))
 			ast_string_field_set(trunk, autocontext, var->value);
-		else {
+		else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
 			ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
 				var->name, var->lineno, SLA_CONFIG_FILE);
+		}
+	}
+
+	if (!ast_strlen_zero(trunk->autocontext)) {
+		struct ast_context *context;
+		context = ast_context_find_or_create(NULL, trunk->autocontext, sla_registrar);
+		if (!context) {
+			ast_log(LOG_ERROR, "Failed to automatically find or create "
+				"context '%s' for SLA!\n", trunk->autocontext);
+			destroy_trunk(trunk);
+			return -1;
+		}
+		if (ast_add_extension2(context, 0 /* don't replace */, "s", 1,
+			NULL, NULL, slatrunk_app, (void *) trunk->name, NULL, sla_registrar)) {
+			ast_log(LOG_ERROR, "Failed to automatically create extension "
+				"for trunk '%s'!\n", trunk->name);
+			destroy_trunk(trunk);
+			return -1;
 		}
 	}
 
@@ -2794,7 +2850,7 @@
 			AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
 		} else if (!strcasecmp(var->name, "autocontext")) {
 			ast_string_field_set(station, autocontext, var->value);
-		} else {
+		} else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
 			ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
 				var->name, var->lineno, SLA_CONFIG_FILE);
 		}
@@ -2839,29 +2895,6 @@
 	ast_config_destroy(cfg);
 
 	return res;
-}
-
-static void destroy_sla(void)
-{
-	struct sla_trunk *trunk;
-	struct sla_station *station;
-
-	AST_RWLIST_WRLOCK(&sla_trunks);
-	while ((trunk = AST_RWLIST_REMOVE_HEAD(&sla_trunks, entry))) {
-		ast_string_field_free_all(trunk);
-		free(trunk);
-	}
-	AST_RWLIST_UNLOCK(&sla_trunks);
-
-	AST_RWLIST_WRLOCK(&sla_stations);
-	while ((station = AST_RWLIST_REMOVE_HEAD(&sla_stations, entry))) {
-		struct sla_trunk_ref *trunk_ref;
-		while ((trunk_ref = AST_LIST_REMOVE_HEAD(&station->trunks, entry)))
-			free(trunk_ref);
-		ast_string_field_free_all(station);
-		free(station);
-	}
-	AST_RWLIST_UNLOCK(&sla_stations);
 }
 
 static int load_config(void)
@@ -2919,9 +2952,8 @@
 
 static int reload(void)
 {
-	load_config();
-
-	return 0;
+	destroy_sla();
+	return load_config();
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "MeetMe conference bridge",



More information about the svn-commits mailing list