[svn-commits] junky: branch junky/cli-tls r200036 - /team/junky/cli-tls/main/pbx.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 10 21:23:45 CDT 2009


Author: junky
Date: Wed Jun 10 21:23:37 2009
New Revision: 200036

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=200036
Log:
this add the CLI commands:
core show filters
core add filter x
core remove filter x

Also, it move the TLS in the pbx_thread() instead of pbx_start(), which fix the cleanup functions.




Modified:
    team/junky/cli-tls/main/pbx.c

Modified: team/junky/cli-tls/main/pbx.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/junky/cli-tls/main/pbx.c?view=diff&rev=200036&r1=200035&r2=200036
==============================================================================
--- team/junky/cli-tls/main/pbx.c (original)
+++ team/junky/cli-tls/main/pbx.c Wed Jun 10 21:23:37 2009
@@ -782,7 +782,9 @@
 AST_THREADSTORAGE_CUSTOM(logger_channel, NULL, logger_channel_cleanup);
 
 /* List of channels used for filtering */
-AST_LIST_HEAD_NOLOCK(ast_channels, ast_channel);
+//AST_LIST_HEAD_NOLOCK(ast_channels, ast_channel);
+AST_LIST_HEAD_NOLOCK_STATIC(ast_channels, ast_channel);
+AST_LIST_HEAD_NOLOCK_STATIC(ast_cli_filters, ast_channel);
 
 struct ast_logger_channels {
         struct ast_channels list;
@@ -3131,6 +3133,115 @@
 	.read = acf_exception_read,
 };
 
+
+static char *handle_show_filters(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	struct ast_channel *c;
+        int count = 0;
+	//struct ast_logger_channels *channels = NULL;
+
+        switch (cmd) {
+        case CLI_INIT:
+                e->command = "core show filters";
+                e->usage =
+                        "Usage: core show filters\n"
+                        "       List All CLI filters\n";
+                return NULL;
+        case CLI_GENERATE:
+                return NULL;
+        }
+
+        if (a->argc != 3) {
+                return CLI_SHOWUSAGE;
+        }
+
+        ast_cli(a->fd, "CLI Filters:\n--------------------------------------------------------------------------------\n");
+
+        AST_LIST_TRAVERSE(&ast_cli_filters, c, chan_list) {
+	//AST_LIST_TRAVERSE(&channels->list, c, chan_list) {
+        	ast_cli(a->fd, "AYYY name=%s\n", c->name);
+		count++;
+        }
+
+        ast_cli(a->fd, "%d active CLI filters.\n", count);
+
+        return CLI_SUCCESS;
+}
+
+static char *handle_add_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	char *str = "SIP/10";	
+
+	struct ast_channel *c = ast_channel_alloc(0, 0, 0, 0, "", "", "", 0, "%s", str);
+	if ( c ) {
+		ast_log(LOG_WARNING, "new chan created. name=[%s]", c->name);
+	}
+
+        switch (cmd) {
+        case CLI_INIT:
+                e->command = "core add filter";
+                e->usage =
+                        "Usage: core add filter\n"
+                        "       Add a new CLI filter\n";
+                return NULL;
+        case CLI_GENERATE:
+                return NULL;
+        }
+
+        if (a->argc != 4) {
+                return CLI_SHOWUSAGE;
+        }
+
+	AST_RWLIST_INSERT_HEAD(&ast_cli_filters, c, chan_list);
+
+        ast_cli(a->fd, "%s sucessfully added to CLI filters.\n", str);
+
+        return CLI_SUCCESS;
+}
+
+
+static char *handle_remove_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+        struct ast_channel *c;
+	char *str = "SIP/10";
+
+        switch (cmd) {
+        case CLI_INIT:
+                e->command = "core remove filter";
+                e->usage =
+                        "Usage: core show filters\n"
+                        "       List All CLI filters\n";
+                return NULL;
+        case CLI_GENERATE:
+                return NULL;
+        }
+
+        if (a->argc != 4) {
+                return CLI_SHOWUSAGE;
+        }
+
+
+	if (!(c = ast_channel_get_by_name(str))) {
+		ast_cli(a->fd, "%s is not an active CLI filter\n", str);
+		return CLI_SUCCESS;
+	} else {
+		ast_cli(a->fd, "ive to remove %s from the list\n", str);
+	                AST_LIST_TRAVERSE_SAFE_BEGIN(&ast_cli_filters, c, chan_list) {
+                        	if (!strcmp(c->name, str)) {
+                                	AST_LIST_REMOVE_CURRENT(chan_list);
+                                	break;
+                        	}
+			AST_LIST_TRAVERSE_SAFE_END;
+                }
+
+	}
+
+
+        return CLI_SUCCESS;
+}
+
+
+
 static char *handle_show_functions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_custom_function *acf;
@@ -4886,6 +4997,16 @@
 	   PBX has finished running on the channel
 	 */
 	struct ast_channel *c = data;
+	struct ast_logger_channels *channels;
+
+	ast_log(LOG_WARNING, "New thread started. (channel name=%s)\n", c->name);
+	if ((channels = ast_threadstorage_get(&logger_channel, sizeof(*c)))) {
+		ast_log(LOG_WARNING, "Adding channel(%s) to channels_list\n", c->name);
+		AST_LIST_INSERT_HEAD(&channels->list, c, chan_list);
+		AST_RWLIST_INSERT_HEAD(&ast_channels, c, chan_list);	
+	} else {
+		ast_log(LOG_WARNING, "obj already exists\n");
+	}
 
 	__ast_pbx_run(c, NULL);
 	decrease_call_count();
@@ -4898,7 +5019,6 @@
 enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
 {
 	pthread_t t;
-	struct ast_logger_channels *channels;
 
 	if (!c) {
 		ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
@@ -4913,14 +5033,6 @@
 		ast_log(LOG_WARNING, "Failed to create new channel thread\n");
 		decrease_call_count();
 		return AST_PBX_FAILED;
-	}
-
-	ast_log(LOG_WARNING, "New thread started. (channel name=%s)\n", c->name);
-	if ((channels = ast_threadstorage_get(&logger_channel, sizeof(*c)))) {
-		ast_log(LOG_WARNING, "Adding channel(%s) to channels_list\n", c->name);
-		AST_LIST_INSERT_HEAD(&channels->list, c, chan_list);	
-	} else {
-		ast_log(LOG_WARNING, "obj already exists\n");
 	}
 
 	return AST_PBX_SUCCESS;
@@ -6647,6 +6759,9 @@
 	AST_CLI_DEFINE(handle_debug_dialplan, "Show fast extension pattern matching data structures"),
 	AST_CLI_DEFINE(handle_unset_extenpatternmatchnew, "Use the Old extension pattern matching algorithm."),
 	AST_CLI_DEFINE(handle_set_extenpatternmatchnew, "Use the New extension pattern matching algorithm."),
+	AST_CLI_DEFINE(handle_show_filters, "Show CLI filters"),
+	AST_CLI_DEFINE(handle_add_filter, "Add CLI filter"),
+	AST_CLI_DEFINE(handle_remove_filter, "Remove CLI filter"),
 };
 
 static void unreference_cached_app(struct ast_app *app)
@@ -9912,3 +10027,4 @@
 	ast_log(LOG_WARNING, "logger_channel_cleanup is called.\n");
 }
 
+




More information about the svn-commits mailing list