[asterisk-commits] pari: trunk r156017 - /trunk/main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 11 17:02:44 CST 2008


Author: pari
Date: Tue Nov 11 17:02:43 2008
New Revision: 156017

URL: http://svn.digium.com/view/asterisk?view=rev&rev=156017
Log:

 Patch by Ryan Brindley -- Make sure that manager refuses any duplicate 'new category' requests in updateconfig



Modified:
    trunk/main/manager.c

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=156017&r1=156016&r2=156017
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Tue Nov 11 17:02:43 2008
@@ -81,6 +81,7 @@
 	UNSPECIFIED_CATEGORY,
 	UNSPECIFIED_ARGUMENT,
 	FAILURE_ALLOCATION,
+	FAILURE_NEWCAT,
 	FAILURE_DELCAT,
 	FAILURE_EMPTYCAT,
 	FAILURE_UPDATE,
@@ -1286,17 +1287,24 @@
 	struct ast_str *str1 = ast_str_create(16), *str2 = ast_str_create(16);
 	enum error_type result = 0;
 
-	for (x = 0; x < 100000; x++) {
+	for (x = 0; x < 100000; x++) {	//100000 = the max number of allowed updates + 1
 		unsigned int object = 0;
 
 		snprintf(hdr, sizeof(hdr), "Action-%06d", x);
 		action = astman_get_header(m, hdr);
-		if (ast_strlen_zero(action))
-			break;
+		if (ast_strlen_zero(action))		// breaks the for loop if no action header
+			break;                      	// this could cause problems if actions come in misnumbered
+
 		snprintf(hdr, sizeof(hdr), "Cat-%06d", x);
 		cat = astman_get_header(m, hdr);
+		if (ast_strlen_zero(cat)) {		//every action needs a category
+			result =  UNSPECIFIED_CATEGORY;
+			break;
+		}
+
 		snprintf(hdr, sizeof(hdr), "Var-%06d", x);
 		var = astman_get_header(m, hdr);
+
 		snprintf(hdr, sizeof(hdr), "Value-%06d", x);
 		value = astman_get_header(m, hdr);
 
@@ -1304,13 +1312,16 @@
 			object = 1;
 			value++;
 		}
+	
 		snprintf(hdr, sizeof(hdr), "Match-%06d", x);
 		match = astman_get_header(m, hdr);
+
 		snprintf(hdr, sizeof(hdr), "Line-%06d", x);
 		line = astman_get_header(m, hdr);
+
 		if (!strcasecmp(action, "newcat")) {
-			if (ast_strlen_zero(cat)) {
-				result = UNSPECIFIED_CATEGORY;
+			if (ast_category_get(cfg,cat)) {	//check to make sure the cat doesn't
+				result = FAILURE_NEWCAT;	//already exist
 				break;
 			}
 			if (!(category = ast_category_new(cat, dfn, -1))) {
@@ -1322,7 +1333,7 @@
 			} else
 				ast_category_insert(cfg, category, match);
 		} else if (!strcasecmp(action, "renamecat")) {
-			if (ast_strlen_zero(cat) || ast_strlen_zero(value)) {
+			if (ast_strlen_zero(value)) {
 				result = UNSPECIFIED_ARGUMENT;
 				break;
 			}
@@ -1332,25 +1343,17 @@
 			}
 			ast_category_rename(category, value);
 		} else if (!strcasecmp(action, "delcat")) {
-			if (ast_strlen_zero(cat)) {
-				result = UNSPECIFIED_CATEGORY;
-				break;
-			}
 			if (ast_category_delete(cfg, cat)) {
 				result = FAILURE_DELCAT;
 				break;
 			}
 		} else if (!strcasecmp(action, "emptycat")) {
-			if (ast_strlen_zero(cat)) {
-				result = UNSPECIFIED_CATEGORY;
-				break;
-			}
 			if (ast_category_empty(cfg, cat)) {
 				result = FAILURE_EMPTYCAT;
 				break;
 			}
 		} else if (!strcasecmp(action, "update")) {
-			if (ast_strlen_zero(cat) || ast_strlen_zero(var)) {
+			if (ast_strlen_zero(var)) {
 				result = UNSPECIFIED_ARGUMENT;
 				break;
 			}
@@ -1363,7 +1366,7 @@
 				break;
 			}
 		} else if (!strcasecmp(action, "delete")) {
-			if (ast_strlen_zero(cat) || (ast_strlen_zero(var) && ast_strlen_zero(line))) {
+			if ((ast_strlen_zero(var) && ast_strlen_zero(line))) {
 				result = UNSPECIFIED_ARGUMENT;
 				break;
 			}
@@ -1376,7 +1379,7 @@
 				break;
 			}
 		} else if (!strcasecmp(action, "append")) {
-			if (ast_strlen_zero(cat) || ast_strlen_zero(var)) {
+			if (ast_strlen_zero(var)) {
 				result = UNSPECIFIED_ARGUMENT;
 				break;
 			}
@@ -1392,7 +1395,7 @@
 				v->object = 1;
 			ast_variable_append(category, v);
 		} else if (!strcasecmp(action, "insert")) {
-			if (ast_strlen_zero(cat) || ast_strlen_zero(var) || ast_strlen_zero(line)) {
+			if (ast_strlen_zero(var) || ast_strlen_zero(line)) {
 				result = UNSPECIFIED_ARGUMENT;
 				break;
 			}
@@ -1481,6 +1484,9 @@
 			break;
 		case FAILURE_ALLOCATION:
 			astman_send_error(s, m, "Memory allocation failure, this should not happen");
+			break;
+		case FAILURE_NEWCAT:
+			astman_send_error(s, m, "Create category did not complete successfully");
 			break;
 		case FAILURE_DELCAT:
 			astman_send_error(s, m, "Delete category did not complete successfully");




More information about the asterisk-commits mailing list