[asterisk-commits] junky: branch junky/cli-tls r210231 - /team/junky/cli-tls/main/logger.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 3 20:03:41 CDT 2009


Author: junky
Date: Mon Aug  3 20:03:37 2009
New Revision: 210231

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=210231
Log:
Added support for different type of filters.
so it will be like:
core add filter keyword name
where keyword is one of the following: name,cid_num,accountcode

exemples:
core add filter name SIP/10
core add filter cid_num 5145551234
core add filter accountcode 2002


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=210231&r1=210230&r2=210231
==============================================================================
--- team/junky/cli-tls/main/logger.c (original)
+++ team/junky/cli-tls/main/logger.c Mon Aug  3 20:03:37 2009
@@ -812,27 +812,33 @@
 {
 	struct ast_cli_filter *filter = NULL;
 	struct ast_cli_filter *tmp;
+	char *keyword = NULL;
 
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "core add filter";
 		e->usage =
-			"Usage: core add filter\n"
-			"       Add a new CLI filter\n";
+			"Usage: core add filter <keyword> <name>\n"
+			"       Add a new CLI filter\n"
+			"keywords are: name, cid_num and accountcode\n";
 		return NULL;
 	case CLI_GENERATE:
 		return NULL;
 	}
 
-	if (a->argc != 4) {
+	if (a->argc != 5) {
 		return CLI_SHOWUSAGE;
 	}
 
-	tmp = ast_filter_get_by_name(a->argv[3]);
+	/*
+	TODO should deal with type here
+	*/
+	tmp = ast_filter_get_by_name(a->argv[4]);
 	if (tmp) {
-		ast_cli(a->fd, "%s already exists\n", a->argv[3]);		
+		ast_cli(a->fd, "%s already exists\n", a->argv[4]);		
 		return CLI_SUCCESS;
 	}
+	
 
 	//TODO use ast_filter_alloc(name,type) instead
 	filter = ast_malloc(sizeof(*filter));
@@ -840,8 +846,22 @@
 		ast_log(LOG_WARNING, "cant allocate enough memory\n");
 		return CLI_FAILURE;
 	}
-	filter->name = ast_strdup(a->argv[3]);
-	filter->type = 1;
+
+	keyword = ast_strdup(a->argv[3]);
+	filter->name = ast_strdup(a->argv[4]);
+
+	/* Keywords are matched with filter type here */
+	if (!strcmp(keyword,"name")) {
+		filter->type = 1;
+	} else if (!strcmp(keyword,"cid_num")) {
+		filter->type = 2;
+	} else if (!strcmp(keyword, "accountcode")) {
+		filter->type = 3;
+	} else {
+		filter->type = 1;
+	}
+
+	ast_free(keyword);
 
 	/* TODO search it that filter already exists */
 	AST_LIST_INSERT_HEAD(&ast_cli_filters, filter, filter_list);
@@ -1619,6 +1639,8 @@
 	int res = -1;
 	struct logger_filter_list_item *filter;
 	struct ast_cli_filter *c;
+	char *comparator = NULL;
+	char *comparee = NULL;
 
         if ((channels = ast_threadstorage_get(&filter_channels, sizeof(*channels)))) {
                 my_printf("chan is there!!!!!\n");
@@ -1626,11 +1648,23 @@
                 AST_LIST_TRAVERSE_SAFE_BEGIN(channels, filter, next) {
                         junky_printf("filter!!!\n");
                         if (filter->chan) {
-                               my_printf("chan is %s\n", filter->chan->name);
+				my_printf("chan is %s\n", filter->chan->name);
+
                                 AST_LIST_TRAVERSE(&ast_cli_filters, c, filter_list) {
-                                        my_printf("active cli filter:%s\n",c->name);
-
-                                        if (strncmp(filter->chan->name, c->name, strlen(c->name))) {
+					if ( c->type == 1 ) {
+						comparator = ast_strdup(filter->chan->name);
+						comparee = ast_strdup(c->name);
+					} else if (c->type == 2) {
+						comparator = ast_strdup(filter->chan->cid.cid_num);
+						comparee = ast_strdup(c->name);
+					} else if (c->type == 3) {
+						comparator = ast_strdup(filter->chan->accountcode);
+						comparee = ast_strdup(c->name);
+					}
+
+                                        my_printf("filter name=[%s] type=[%d] comparator=[%s] comparee=[%s]\n",c->name, c->type, comparator, comparee);
+
+					if (strncmp(comparator, comparee, strlen(comparee))) {
                                                 my_printf("Ignore %s, since this is not in filter list\n", filter->chan->name);
 						res=1;
                                         } else {
@@ -1638,6 +1672,8 @@
                                                 res=0;
                                                 break;
                                         }
+					ast_free(comparator);
+					ast_free(comparee);
                                 }
                         }
                 }




More information about the asterisk-commits mailing list