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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jan 22 10:37:08 MST 2007


Author: russell
Date: Mon Jan 22 11:37:07 2007
New Revision: 51404

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51404
Log:
Add "sla show (trunks|stations)" CLI commands

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=51404&r1=51403&r2=51404
==============================================================================
--- team/russell/sla_rewrite/apps/app_meetme.c (original)
+++ team/russell/sla_rewrite/apps/app_meetme.c Mon Jan 22 11:37:07 2007
@@ -323,16 +323,23 @@
 struct sla_trunk {
 	AST_RWLIST_ENTRY(sla_trunk) entry;
 	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(name);
 		AST_STRING_FIELD(device);
 	);
 };
 
+struct sla_trunk_ref {
+	struct sla_trunk *trunk;
+	AST_LIST_ENTRY(sla_trunk_ref) entry;
+};
+
 struct sla_station {
 	AST_RWLIST_ENTRY(sla_station) entry;
 	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(name);	
 		AST_STRING_FIELD(device);	
 	);
-	AST_LIST_HEAD_NOLOCK(, sla_trunk) trunks;
+	AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
 };
 
 static AST_RWLIST_HEAD_STATIC(sla_stations, sla_station);
@@ -818,10 +825,69 @@
 "Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
 "       Executes a command for the conference or on a conferee\n";
 
+static int sla_show_trunks(int fd, int argc, char **argv)
+{
+	const struct sla_trunk *trunk;
+
+	ast_cli(fd, "--- Configured SLA Trunks -----------------------------------\n"
+	            "-------------------------------------------------------------\n\n");
+	AST_RWLIST_RDLOCK(&sla_trunks);
+	AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
+		ast_cli(fd, "--- Trunk Name: %s\n"
+		            "--- ==> Device: %s\n\n", 
+					trunk->name, trunk->device);
+	}
+	AST_RWLIST_UNLOCK(&sla_trunks);
+	ast_cli(fd, "-------------------------------------------------------------\n");
+
+	return RESULT_SUCCESS;
+}
+
+static const char sla_show_trunks_usage[] =
+"Usage: sla show trunks\n"
+"       This will list all trunks defined in sla.conf\n";
+
+static int sla_show_stations(int fd, int argc, char **argv)
+{
+	const struct sla_station *station;
+
+	ast_cli(fd, "--- Configured SLA Stations ---------------------------------\n"
+	            "-------------------------------------------------------------\n\n");
+	AST_RWLIST_RDLOCK(&sla_stations);
+	AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
+		struct sla_trunk_ref *trunk_ref;
+		ast_cli(fd, "--- Station Name: %s\n"
+		            "--- ==> Device:   %s\n"
+					"--- ==> Trunks ...\n",
+					station->name, station->device);
+		AST_RWLIST_RDLOCK(&sla_trunks);
+		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry)
+			ast_cli(fd, "--- =====> Trunk Name: %s\n", trunk_ref->trunk->name);
+		AST_RWLIST_UNLOCK(&sla_trunks);
+		ast_cli(fd, "\n");
+	}
+	AST_RWLIST_UNLOCK(&sla_stations);
+	ast_cli(fd, "-------------------------------------------------------------\n");
+
+	return RESULT_SUCCESS;
+}
+
+static const char sla_show_stations_usage[] =
+"Usage: sla show stations\n"
+"       This will list all stations defined in sla.conf\n";
+
 static struct ast_cli_entry cli_meetme[] = {
 	{ { "meetme", NULL, NULL },
 	meetme_cmd, "Execute a command on a conference or conferee",
 	meetme_usage, complete_meetmecmd },
+
+	{ { "sla", "show", "trunks", NULL },
+	sla_show_trunks, "Show SLA Trunks",
+	sla_show_trunks_usage, NULL },
+
+	{ { "sla", "show", "stations", NULL },
+	sla_show_stations, "Show SLA Stations",
+	sla_show_stations_usage, NULL },
 };
 
 static void conf_flush(int fd, struct ast_channel *chan)
@@ -2631,7 +2697,12 @@
 
 	if (!(trunk = ast_calloc(1, sizeof(*trunk))))
 		return -1;
-
+	if (ast_string_field_init(trunk, 32)) {
+		free(trunk);
+		return -1;
+	}
+
+	ast_string_field_set(trunk, name, cat);
 	ast_string_field_set(trunk, device, dev);
 
 	AST_RWLIST_WRLOCK(&sla_trunks);
@@ -2654,15 +2725,21 @@
 
 	if (!(station = ast_calloc(1, sizeof(*station))))
 		return -1;
-
+	if (ast_string_field_init(station, 32)) {
+		free(station);
+		return -1;
+	}
+
+	ast_string_field_set(station, name, cat);
 	ast_string_field_set(station, device, dev);
 
 	for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
 		if (!strcasecmp(var->name, "trunk")) {
 			struct sla_trunk *trunk;
+			struct sla_trunk_ref *trunk_ref;
 			AST_RWLIST_RDLOCK(&sla_trunks);
 			AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
-				if (!strcasecmp(trunk->device, var->value))
+				if (!strcasecmp(trunk->name, var->value))
 					break;
 			}
 			AST_RWLIST_UNLOCK(&sla_trunks);
@@ -2670,7 +2747,10 @@
 				ast_log(LOG_ERROR, "Trunk '%s' not found!\n", var->value);
 				continue;
 			}
-			AST_LIST_INSERT_TAIL(&station->trunks, trunk, entry);
+			if (!(trunk_ref = ast_calloc(1, sizeof(*trunk_ref))))
+				continue;
+			trunk_ref->trunk = trunk;
+			AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
 		} else {
 			ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
 				var->name, var->lineno, SLA_CONFIG_FILE);
@@ -2732,6 +2812,9 @@
 
 	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);
 	}



More information about the asterisk-commits mailing list