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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 10 10:50:08 CDT 2009


Author: junky
Date: Fri Jul 10 10:50:05 2009
New Revision: 205774

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=205774
Log:
merge 2 traversal loop to is_string_match_cli_filters()
fix indentations
standardize pointer to ast_cli_filter to be named filter.
remove useless code on cleanup functions



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=205774&r1=205773&r2=205774
==============================================================================
--- team/junky/cli-tls/main/logger.c (original)
+++ team/junky/cli-tls/main/logger.c Fri Jul 10 10:50:05 2009
@@ -208,6 +208,7 @@
 
 struct ast_channels *channels;
 static void filter_channel_cleanup(void *data);
+int is_string_match_cli_filters(void);
 
 AST_THREADSTORAGE_CUSTOM(filter_channels, NULL, filter_channel_cleanup);
 
@@ -215,16 +216,16 @@
 AST_LIST_HEAD_NOLOCK(ast_channels, logger_filter_list_item);
 
 struct logger_filter_list_item {
-        struct ast_channel *chan;
-        AST_LIST_ENTRY(logger_filter_list_item) next;
+	struct ast_channel *chan;
+	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_LIST_ENTRY(ast_cli_filter) filter_list;     /*!< pointer to the next element */
+	char *name;					/*!< Name of the filter */
+	int type;					/*!< Type of the filter currently, only 0 is used */
+	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_cli_filter);
@@ -770,112 +771,111 @@
 
 static char *handle_show_filters(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-        struct ast_cli_filter *filter;
-        int count = 0;
-
-        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;
-        }
+	struct ast_cli_filter *filter;
+	int count = 0;
+
+	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, "Active CLI Filters:\n---------------------------------------------------------------------\n");
 
-        AST_LIST_TRAVERSE(&ast_cli_filters, filter, filter_list) {
-                ast_cli(a->fd, "%s\t%d\t\n", filter->name, filter->type);
-                count++;
-        }
-
-        ast_cli(a->fd, "%d active CLI filters.\n", count);
-
-        return CLI_SUCCESS;
+	AST_LIST_TRAVERSE(&ast_cli_filters, filter, filter_list) {
+		ast_cli(a->fd, "%s\t%d\t\n", filter->name, filter->type);
+		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)
 {
-        struct ast_cli_filter *c = NULL;
-
-        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;
-        }
-
-        //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;
-
-        /* TODO search it that filter already exists */
-        AST_LIST_INSERT_HEAD(&ast_cli_filters, c, filter_list);
-
-        ast_cli(a->fd, "%s sucessfully added to CLI filters.\n", c->name);
-
-        return CLI_SUCCESS;
+	struct ast_cli_filter *filter = NULL;
+
+	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;
+	}
+
+	//TODO use ast_filter_alloc(name,type) instead
+	filter = ast_malloc(sizeof(*filter));
+	if ( !filter ) {
+		ast_log(LOG_WARNING, "cant allocate enough memory\n");
+		return CLI_FAILURE;
+	}
+	filter->name = ast_strdup(a->argv[3]);
+	filter->type = 1;
+
+	/* TODO search it that filter already exists */
+	AST_LIST_INSERT_HEAD(&ast_cli_filters, filter, filter_list);
+
+	ast_cli(a->fd, "%s sucessfully added to CLI filters.\n", filter->name);
+
+	return CLI_SUCCESS;
 }
 
 static char *handle_remove_filter(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-        struct ast_cli_filter *c;
-
-        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;
-        }
+	struct ast_cli_filter *filter;
+
+	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;
+	}
 
         /* 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, filter_list) {
-                        if (!strcmp(c->name, a->argv[3])) {
-                                AST_LIST_REMOVE_CURRENT(filter_list);
-                                        ast_cli(a->fd, "%s has been sucessfully removed from CLI filter list.\n", a->argv[3]);
-                                        ast_free(c->name); /* since I ast_strdup it */
-                                        ast_free(c);
-                                        break;
-                        }
-                        AST_LIST_TRAVERSE_SAFE_END;
-                }
-        }
-
-        //ast_cli(a->fd,"%s cant be removed.", a->argv[3]);
-        return CLI_SUCCESS;
+	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, filter, filter_list) {
+			if (!strcmp(filter->name, a->argv[3])) {
+				AST_LIST_REMOVE_CURRENT(filter_list);
+					ast_cli(a->fd, "%s has been sucessfully removed from CLI filter list.\n", a->argv[3]);
+					ast_free(filter->name); /* since I ast_strdup it */
+					ast_free(filter);
+					break;
+			}
+			AST_LIST_TRAVERSE_SAFE_END;
+		}
+	}
+
+	return CLI_SUCCESS;
 }
 
 
@@ -1141,10 +1141,6 @@
 	int res = 0;
 	va_list ap;
 	char datestring[256];
-	struct logger_filter_list_item *filter;
-	struct ast_cli_filter *c;
-	int skip=0;
-
 
 	if (!(buf = ast_str_thread_get(&log_buf, LOG_BUF_INIT_SIZE)))
 		return;
@@ -1183,34 +1179,8 @@
 	/* If filters are enabled
 	   ignore if the string doesnt match these filters
 	*/
-	
-        if ((channels = ast_threadstorage_get(&filter_channels, sizeof(*channels)))) {
-		printf("chan is there!!!!!\n");
-
-		AST_LIST_TRAVERSE_SAFE_BEGIN(channels, filter, next) {
-                        printf("filter!!!\n");
-                        if (filter->chan) {
-                               printf("chan is %s\n", filter->chan->name);
-				AST_LIST_TRAVERSE(&ast_cli_filters, c, filter_list) {
-					printf("active cli filter:%s\n",c->name);
-
-					if (strncmp(filter->chan->name, c->name, strlen(c->name))) {	
-						printf("Ignore %s, since this is not in filter list\n", filter->chan->name);
-						skip=1;
-					//	break; //no break to traverse the list of cli filters 
-					} else {
-						printf("%s match my filter, so continue\n", filter->chan->name);
-						skip=0;
-						break;
-					}
-				}
-                        }
-                }
-                AST_LIST_TRAVERSE_SAFE_END;
-
-	}
-
-	if (skip) {
+
+	if (is_string_match_cli_filters()) {
 		printf("skip!\n");
 		return;
 	} else {
@@ -1333,10 +1303,6 @@
 	struct logmsg *logmsg = NULL;
 	struct ast_str *buf = NULL;
 	int res = 0;
-	struct logger_filter_list_item *filter;
-        struct ast_cli_filter *c;
-        int skip=0;
-
 
 	if (!(buf = ast_str_thread_get(&verbose_buf, VERBOSE_BUF_INIT_SIZE)))
 		return;
@@ -1376,33 +1342,7 @@
 	/* Set type */
 	logmsg->type = LOGMSG_VERBOSE;
 
-        if ((channels = ast_threadstorage_get(&filter_channels, sizeof(*channels)))) {
-                printf("chan is there!!!!!\n");
-
-                AST_LIST_TRAVERSE_SAFE_BEGIN(channels, filter, next) {
-                        printf("filter!!!\n");
-                        if (filter->chan) {
-                               printf("chan is %s\n", filter->chan->name);
-                                AST_LIST_TRAVERSE(&ast_cli_filters, c, filter_list) {
-                                        printf("active cli filter:%s\n",c->name);
-
-                                        if (strncmp(filter->chan->name, c->name, strlen(c->name))) {
-                                                printf("Ignore %s, since this is not in filter list\n", filter->chan->name);
-                                                skip=1;
-                                        //      break; //no break to traverse the list of cli filters
-                                        } else {
-                                                printf("%s match my filter, so continue\n", filter->chan->name);
-                                                skip=0;
-                                                break;
-                                        }
-                                }
-                        }
-                }
-                AST_LIST_TRAVERSE_SAFE_END;
-
-        }
-
-        if (skip) {
+        if (is_string_match_cli_filters()) {
                 printf("skip!\n");
                 return;
         } else {
@@ -1612,30 +1552,8 @@
                         ast_log(LOG_WARNING, "chan is there \n");
                 }
         }
-        //filter = ast_malloc(sizeof(*filter));
-
-        /*
-        if ((filter = ast_threadstorage_get(&filter_channels, sizeof(*filter)))) {
-                ast_log(LOG_WARNING, "ive to remove \n");
-        }
-
-
-        if ((channels = ast_threadstorage_get(&filter_channels, sizeof(*filter)))) {
-                ast_log(LOG_WARNING, "filter is there\n");
-                //AST_LIST_TRAVERSE_SAFE_BEGIN(&filter->list, chan, chan_list) {
-                AST_LIST_TRAVERSE_SAFE_BEGIN(channels, fi, next) {
-                        ast_log(LOG_WARNING, "filter!!!\n");
-                        if (fi->chan) {
-                                ast_log(LOG_WARNING, "chan is %s\n", fi->chan->name);
-                        }
-                }
-                AST_LIST_TRAVERSE_SAFE_END;
-        }
-
-
-        */
-
-        while ((filter = AST_LIST_REMOVE_HEAD(channels, next))) {
+        
+	while ((filter = AST_LIST_REMOVE_HEAD(channels, next))) {
                 ast_log(LOG_WARNING, "filter will be removed.\n");
                 if ( filter->chan) {
                         ast_log(LOG_WARNING, "chan is there(%s) \n", filter->chan->name);
@@ -1644,3 +1562,27 @@
         }
 }
 
+int is_string_match_cli_filters(void) {
+	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) {
+					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;
+					} else {
+						printf("%s match my filter, so continue\n", filter->chan->name);
+						res=0;
+						break;
+					}
+				}
+			}
+		}
+		AST_LIST_TRAVERSE_SAFE_END;
+	}
+	return res;
+}




More information about the asterisk-commits mailing list