[asterisk-commits] rmudgett: trunk r332941 - in /trunk: ./ main/config.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 22 16:25:15 CDT 2011


Author: rmudgett
Date: Mon Aug 22 16:25:11 2011
New Revision: 332941

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=332941
Log:
Merged revisions 332940 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/10

................
  r332940 | rmudgett | 2011-08-22 16:23:40 -0500 (Mon, 22 Aug 2011) | 14 lines
  
  Merged revisions 332939 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.8
  
  ........
    r332939 | rmudgett | 2011-08-22 16:22:24 -0500 (Mon, 22 Aug 2011) | 7 lines
    
    Minor code optimizations.
    
    * Simplify ast_category_browse() logic for easier understanding.
    
    * Remove dead code in ast_variable_delete() and simplify some of its
    logic.
  ........
................

Modified:
    trunk/   (props changed)
    trunk/main/config.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: trunk/main/config.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/config.c?view=diff&rev=332941&r1=332940&r2=332941
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Mon Aug 22 16:25:11 2011
@@ -619,22 +619,36 @@
 
 char *ast_category_browse(struct ast_config *config, const char *prev)
 {	
-	struct ast_category *cat = NULL;
-
-	if (prev && config->last_browse && (config->last_browse->name == prev))
+	struct ast_category *cat;
+
+	if (!prev) {
+		/* First time browse. */
+		cat = config->root;
+	} else if (config->last_browse && (config->last_browse->name == prev)) {
+		/* Simple last browse found. */
 		cat = config->last_browse->next;
-	else if (!prev && config->root)
-		cat = config->root;
-	else if (prev) {
+	} else {
+		/*
+		 * Config changed since last browse.
+		 *
+		 * First try cheap last browse search. (Rebrowsing a different
+		 * previous category?)
+		 */
 		for (cat = config->root; cat; cat = cat->next) {
 			if (cat->name == prev) {
+				/* Found it. */
 				cat = cat->next;
 				break;
 			}
 		}
 		if (!cat) {
+			/*
+			 * Have to do it the hard way. (Last category was deleted and
+			 * re-added?)
+			 */
 			for (cat = config->root; cat; cat = cat->next) {
 				if (!strcasecmp(cat->name, prev)) {
+					/* Found it. */
 					cat = cat->next;
 					break;
 				}
@@ -690,11 +704,27 @@
 {
 	struct ast_variable *cur, *prev=NULL, *curn;
 	int res = -1;
-	int lineno = 0;
-
+	int num_item = 0;
+	int req_item;
+
+	req_item = -1;
+	if (!ast_strlen_zero(line)) {
+		/* Requesting to delete by item number. */
+		if (sscanf(line, "%30d", &req_item) != 1
+			|| req_item < 0) {
+			/* Invalid item number to delete. */
+			return -1;
+		}
+	}
+
+	prev = NULL;
 	cur = category->root;
 	while (cur) {
-		if (cur->name == variable) {
+		curn = cur->next;
+		/* Delete by item number or by variable name with optional value. */
+		if ((0 <= req_item && num_item == req_item)
+			|| (req_item < 0 && !strcasecmp(cur->name, variable)
+				&& (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
 			if (prev) {
 				prev->next = cur->next;
 				if (cur == category->last)
@@ -704,36 +734,13 @@
 				if (cur == category->last)
 					category->last = NULL;
 			}
-			cur->next = NULL;
-			ast_variables_destroy(cur);
-			return 0;
-		}
-		prev = cur;
-		cur = cur->next;
-	}
-
-	prev = NULL;
-	cur = category->root;
-	while (cur) {
-		curn = cur->next;
-		if ((!ast_strlen_zero(line) && lineno == atoi(line)) || (ast_strlen_zero(line) && !strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
-			if (prev) {
-				prev->next = cur->next;
-				if (cur == category->last)
-					category->last = prev;
-			} else {
-				category->root = cur->next;
-				if (cur == category->last)
-					category->last = NULL;
-			}
-			cur->next = NULL;
-			ast_variables_destroy(cur);
+			ast_variable_destroy(cur);
 			res = 0;
 		} else
 			prev = cur;
 
 		cur = curn;
-		lineno++;
+		++num_item;
 	}
 	return res;
 }
@@ -2198,7 +2205,7 @@
 }
 
 /*! \brief Check if there's any realtime engines loaded */
-int ast_realtime_enabled()
+int ast_realtime_enabled(void)
 {
 	return config_maps ? 1 : 0;
 }
@@ -2680,7 +2687,7 @@
 	AST_CLI_DEFINE(handle_cli_config_list, "Show all files that have loaded a configuration file"),
 };
 
-int register_config_cli() 
+int register_config_cli(void)
 {
 	ast_cli_register_multiple(cli_config, ARRAY_LEN(cli_config));
 	return 0;




More information about the asterisk-commits mailing list