[svn-commits] junky: branch junky/cli-tls r205844 - /team/junky/cli-tls/main/logger.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jul 10 11:54:31 CDT 2009


Author: junky
Date: Fri Jul 10 11:54:28 2009
New Revision: 205844

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205844
Log:
create ast_filter_get_by_name() which is used for verification before adding and removing filters

reverse order of the two AST_LIST_TRAVERSE in is_string_match_cli_filters() to get the higher loop outside.
This way is for future work to quickly know with the counter if theres any filters active.



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

Modified: team/junky/cli-tls/main/logger.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/junky/cli-tls/main/logger.c?view=diff&rev=205844&r1=205843&r2=205844
==============================================================================
--- team/junky/cli-tls/main/logger.c (original)
+++ team/junky/cli-tls/main/logger.c Fri Jul 10 11:54:28 2009
@@ -207,8 +207,11 @@
 #define LOG_BUF_INIT_SIZE       256
 
 struct ast_channels *channels;
+
+/* Prototype */
 static void filter_channel_cleanup(void *data);
 int is_string_match_cli_filters(void);
+struct ast_cli_filter *ast_filter_get_by_name(const char *name);
 
 AST_THREADSTORAGE_CUSTOM(filter_channels, NULL, filter_channel_cleanup);
 
@@ -804,6 +807,7 @@
 static char *handle_add_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_cli_filter *filter = NULL;
+	struct ast_cli_filter *tmp;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -820,6 +824,12 @@
 		return CLI_SHOWUSAGE;
 	}
 
+	tmp = ast_filter_get_by_name(a->argv[3]);
+	if (tmp) {
+		ast_cli(a->fd, "%s already exists\n", a->argv[3]);		
+		return CLI_SUCCESS;
+	}
+
 	//TODO use ast_filter_alloc(name,type) instead
 	filter = ast_malloc(sizeof(*filter));
 	if ( !filter ) {
@@ -840,6 +850,7 @@
 static char *handle_remove_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_cli_filter *filter;
+	struct ast_cli_filter *tmp;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -856,8 +867,8 @@
 		return CLI_SHOWUSAGE;
 	}
 
-        /* TODO write ast_filter_get_by_name(name )*/
-	if (0) {
+	tmp = ast_filter_get_by_name(a->argv[3]);
+	if (!tmp) {
 		ast_cli(a->fd, "%s is not an active CLI filter\n", a->argv[3]);
 		return CLI_SUCCESS;
 	} else {
@@ -1349,11 +1360,6 @@
                 printf("No skip!\n");
         }
 
-
-
-
-
-	
 	/* Add to the list and poke the thread if possible */
 	if (logthread != AST_PTHREADT_NULL) {
 		AST_LIST_LOCK(&logmsgs);
@@ -1566,11 +1572,14 @@
 	int res = 0;
 	struct logger_filter_list_item *filter;
 	struct ast_cli_filter *c;
-
-	if ((channels = ast_threadstorage_get(&filter_channels, sizeof(*channels)))) {
-		AST_LIST_TRAVERSE_SAFE_BEGIN(channels, filter, next) {
-			if (filter->chan) {
-				AST_LIST_TRAVERSE(&ast_cli_filters, c, filter_list) {
+	int count = 0;
+
+	channels = ast_threadstorage_get(&filter_channels, sizeof(*channels));
+	AST_LIST_TRAVERSE(&ast_cli_filters, c, filter_list) {
+		if (channels) {
+			AST_LIST_TRAVERSE_SAFE_BEGIN(channels, filter, next) {
+                        	if (filter->chan) {
+
 					if (strncmp(filter->chan->name, c->name, strlen(c->name))) {
 						printf("Ignore %s, since this is not in filter list\n", filter->chan->name);
 						res=1;
@@ -1581,8 +1590,30 @@
 					}
 				}
 			}
-		}
-		AST_LIST_TRAVERSE_SAFE_END;
-	}
+			AST_LIST_TRAVERSE_SAFE_END;
+		}
+		/* Allow the break the outter loop, since the inner loop asked it */
+		if (!res) {
+			break;
+		} 
+		count++;
+	}
+
+	//printf("I return %d\n",res);
 	return res;
 }
+
+/* Function which return a pointer to the filter for a specific name
+ * Returns NULL if no filters matches
+ */
+struct ast_cli_filter *ast_filter_get_by_name(const char *name) {
+	struct ast_cli_filter *filter;
+
+        AST_LIST_TRAVERSE(&ast_cli_filters, filter, filter_list) {
+		if (!strcmp(filter->name,name)) {
+			return filter;
+		}
+
+	}
+	return NULL;
+}




More information about the svn-commits mailing list