[asterisk-commits] junky: branch junky/cli-tls r201821 - /team/junky/cli-tls/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 18 17:07:47 CDT 2009


Author: junky
Date: Thu Jun 18 17:07:44 2009
New Revision: 201821

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=201821
Log:
replace the ast_channel by a new struct ast_cli_filter
that struct is used for cli filter (entered in the CLI).
name is used for what the user enters ex. SIP/10-
type is for future possibility to add filter by chan->cid->cid_num, chan->name, etc.


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=201821&r1=201820&r2=201821
==============================================================================
--- team/junky/cli-tls/main/pbx.c (original)
+++ team/junky/cli-tls/main/pbx.c Thu Jun 18 17:07:44 2009
@@ -792,8 +792,18 @@
        AST_LIST_ENTRY(logger_filter_list_item) next;
 };
 
+
+/* Structure for the cli filter */
+struct ast_cli_filter {
+	char *name; 					/*!< Name of the filter */
+	int type;					/*!< Type of the filter currently, only 0 is used */
+	AST_DECLARE_STRING_FIELDS(
+                AST_STRING_FIELD(name2); 
+	);
+	AST_LIST_ENTRY(ast_cli_filter) filter_list;	/*!< pointer to the next element */
+};
 /* List used to store all cli filters entered by the user */
-AST_LIST_HEAD_NOLOCK_STATIC(ast_cli_filters, ast_channel);
+AST_LIST_HEAD_NOLOCK_STATIC(ast_cli_filters, ast_cli_filter);
 
 
 /*!
@@ -3141,7 +3151,7 @@
 
 static char *handle_show_filters(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct ast_channel *c;
+	struct ast_cli_filter *c;
         int count = 0;
 
         switch (cmd) {
@@ -3161,8 +3171,8 @@
 
         ast_cli(a->fd, "Active CLI Filters:\n---------------------------------------------------------------------\n");
 
-        AST_LIST_TRAVERSE(&ast_cli_filters, c, chan_list) {
-        	ast_cli(a->fd, "%s\n", c->name);
+        AST_LIST_TRAVERSE(&ast_cli_filters, c, filter_list) {
+        	ast_cli(a->fd, "%s\t%d\t\n", c->name, c->type);
 		count++;
         }
 
@@ -3173,7 +3183,7 @@
 
 static char *handle_add_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct ast_channel *c = NULL;
+	struct ast_cli_filter *c = NULL;
 
         switch (cmd) {
         case CLI_INIT:
@@ -3190,16 +3200,20 @@
                 return CLI_SHOWUSAGE;
         }
 
-	c = ast_channel_alloc(0, 0, 0, 0, "", "", "", 0, "%s", a->argv[3]);
+	//TODO use ast_filter_alloc(name,type) instead
+	c = ast_malloc(sizeof(*c));
 	if ( !c ) {
 		ast_log(LOG_WARNING, "cant allocate enough memory\n");
 		return CLI_FAILURE;
 	}
+	c->name = ast_strdup(a->argv[3]);
+	c->type = 1;
+	//ast_copy_string((char *)c->name2, a->argv[3], sizeof(c->name2));
 
 	/* TODO search it that filter already exists */
-	AST_RWLIST_INSERT_HEAD(&ast_cli_filters, c, chan_list);
-
-        ast_cli(a->fd, "%s sucessfully added to CLI filters.\n", a->argv[3]);
+	AST_RWLIST_INSERT_HEAD(&ast_cli_filters, c, filter_list);
+
+        ast_cli(a->fd, "%s sucessfully added to CLI filters.\n", c->name);
 
         return CLI_SUCCESS;
 }
@@ -3207,7 +3221,7 @@
 
 static char *handle_remove_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-        struct ast_channel *c;
+        struct ast_cli_filter *c;
 
         switch (cmd) {
         case CLI_INIT:
@@ -3223,24 +3237,26 @@
         if (a->argc != 4) {
                 return CLI_SHOWUSAGE;
         }
-
-	if (!(c = ast_channel_get_by_name(a->argv[3]))) {
+ 	
+	/* TODO write ast_filter_get_by_name(name )*/
+	if (0) {
 		ast_cli(a->fd, "%s is not an active CLI filter\n", a->argv[3]);
 		return CLI_SUCCESS;
 	} else {
 		ast_cli(a->fd, "ive to remove %s from the list\n", a->argv[3]);
-	                AST_LIST_TRAVERSE_SAFE_BEGIN(&ast_cli_filters, c, chan_list) {
+			
+	                AST_LIST_TRAVERSE_SAFE_BEGIN(&ast_cli_filters, c, filter_list) {
                         	if (!strcmp(c->name, a->argv[3])) {
-                                	AST_LIST_REMOVE_CURRENT(chan_list);
+                                	AST_LIST_REMOVE_CURRENT(filter_list);
 					ast_cli(a->fd, "%s has been sucessfully removed from CLI filter list.\n", a->argv[3]);
+					/* TODO when you destroy c, you must ast_free(c->name), since I ast_strdup it */
                                 	break;
                         	}
 			AST_LIST_TRAVERSE_SAFE_END;
-			ast_cli(a->fd,"%s cant be removed.", a->argv[3]);
-                }
-
-	}
-
+                }	
+	}
+
+	//ast_cli(a->fd,"%s cant be removed.", a->argv[3]);
         return CLI_SUCCESS;
 }
 
@@ -5018,7 +5034,7 @@
 	if ((filter = ast_threadstorage_get(&filter_channels, 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);	
+		//AST_RWLIST_INSERT_HEAD(&ast_channels, filter, next);	
 	} else {
 		ast_log(LOG_WARNING, "obj already exists\n");
 	}




More information about the asterisk-commits mailing list