[asterisk-commits] jpeeler: branch jpeeler/manager-configactions r102857 - /team/jpeeler/manager...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 7 12:59:12 CST 2008


Author: jpeeler
Date: Thu Feb  7 12:59:12 2008
New Revision: 102857

URL: http://svn.digium.com/view/asterisk?view=rev&rev=102857
Log:
updateconfig actions return exact error codes indicating success or which action failed

Modified:
    team/jpeeler/manager-configactions/main/manager.c

Modified: team/jpeeler/manager-configactions/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/manager-configactions/main/manager.c?view=diff&rev=102857&r1=102856&r2=102857
==============================================================================
--- team/jpeeler/manager-configactions/main/manager.c (original)
+++ team/jpeeler/manager-configactions/main/manager.c Thu Feb  7 12:59:12 2008
@@ -75,6 +75,21 @@
 #include "asterisk/version.h"
 #include "asterisk/term.h"
 #include "asterisk/astobj2.h"
+
+enum
+{
+	UNKNOWN_ACTION,
+	UNKNOWN_CATEGORY,
+	UNSPECIFIED_CATEGORY,
+	UNSPECIFIED_ARGUMENT,
+	FAILURE_ALLOCATION,
+	FAILURE_DELCAT,
+	FAILURE_EMPTYCAT,
+	FAILURE_UPDATE,
+	FAILURE_DELETE,
+	FAILURE_APPEND
+};
+
 
 /*!
  * Linked list of events.
@@ -1248,61 +1263,63 @@
 		snprintf(hdr, sizeof(hdr), "Line-%06d", x);
 		line = astman_get_header(m, hdr);
 		if (!strcasecmp(action, "newcat")) {
-			if (!ast_strlen_zero(cat)) {
-				category = ast_category_new(cat, dfn, 99999);
-				if (category) {
-					ast_category_append(cfg, category);
-				}
-			} else
-				return -2;
+			if (ast_strlen_zero(cat))
+				return UNSPECIFIED_CATEGORY;
+			if (!(category = ast_category_new(cat, dfn, 99999)))
+				return FAILURE_ALLOCATION;
+			ast_category_append(cfg, category);
 		} else if (!strcasecmp(action, "renamecat")) {
-			if (!ast_strlen_zero(cat) && !ast_strlen_zero(value)) {
-				category = ast_category_get(cfg, cat);
-				if (category)
-					ast_category_rename(category, value);
-			} else 
-				return -3;
+			if (ast_strlen_zero(cat) || ast_strlen_zero(value))
+				return UNSPECIFIED_ARGUMENT;
+			if (!(category = ast_category_get(cfg, cat)))
+				return UNKNOWN_CATEGORY;
+			ast_category_rename(category, value);
 		} else if (!strcasecmp(action, "delcat")) {
-			if (!ast_strlen_zero(cat))
-				ast_category_delete(cfg, cat);
-			else
-				return -2;
+			if (ast_strlen_zero(cat))
+				return UNSPECIFIED_CATEGORY;
+			if (ast_category_delete(cfg, cat))
+				return FAILURE_DELCAT;
 		} else if (!strcasecmp(action, "emptycat")) {
-			if (!ast_strlen_zero(cat))
-				ast_category_empty(cfg, cat);
-			else
-				return -2;
+			if (ast_strlen_zero(cat))
+				return UNSPECIFIED_CATEGORY;
+			if (ast_category_empty(cfg, cat))
+				return FAILURE_EMPTYCAT;
 		} else if (!strcasecmp(action, "update")) {
-			if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
-				ast_variable_update(category, var, value, match, object);
-			else
-				return -3;
+			if (ast_strlen_zero(cat) || ast_strlen_zero(var))
+				return UNSPECIFIED_ARGUMENT;
+			if (!(category = ast_category_get(cfg,cat)))
+				return UNKNOWN_CATEGORY;
+			if (ast_variable_update(category, var, value, match, object))
+				return FAILURE_UPDATE;
 		} else if (!strcasecmp(action, "delete")) {
-			if (!ast_strlen_zero(cat) && (!ast_strlen_zero(var) || !ast_strlen_zero(line)) && (category = ast_category_get(cfg, cat)))
-				ast_variable_delete(category, var, match, line);
-			else
-				return -3;
+			if (ast_strlen_zero(cat) || (ast_strlen_zero(var) && ast_strlen_zero(line)))
+				return UNSPECIFIED_ARGUMENT;
+			if (!(category = ast_category_get(cfg, cat)))
+				return UNKNOWN_CATEGORY;
+			if (ast_variable_delete(category, var, match, line))
+				return FAILURE_DELETE;
 		} else if (!strcasecmp(action, "append")) {
-			if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) &&
-				(category = ast_category_get(cfg, cat)) &&
-				(v = ast_variable_new(var, value, dfn))) {
-				if (object || (match && !strcasecmp(match, "object")))
-					v->object = 1;
-				ast_variable_append(category, v);
-			}
-			else
-				return -3;
+			if (ast_strlen_zero(cat) || ast_strlen_zero(var))
+				return UNSPECIFIED_ARGUMENT;
+			if (!(category = ast_category_get(cfg, cat)))
+				return UNKNOWN_CATEGORY;	
+			if (!(v = ast_variable_new(var, value, dfn)))
+				return FAILURE_ALLOCATION;
+			if (object || (match && !strcasecmp(match, "object")))
+				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) &&
-				(category = ast_category_get(cfg, cat)) &&
-				(v = ast_variable_new(var, value, dfn)))
-				ast_variable_insert(category, v, line);
-			else
-				return -3;
+			if (ast_strlen_zero(cat) || ast_strlen_zero(var) || ast_strlen_zero(line))
+				return UNSPECIFIED_ARGUMENT;
+			if (!(category = ast_category_get(cfg, cat)))
+				return UNKNOWN_CATEGORY;
+			if (!(v = ast_variable_new(var, value, dfn)))
+				return FAILURE_ALLOCATION;
+			ast_variable_insert(category, v, line);
 		}
 		else {
 			ast_log(LOG_WARNING, "Action-%06d: %s not handled\n", x, action);
-			return -1;
+			return UNKNOWN_ACTION;
 		}
 	}
 	return 0;
@@ -1319,7 +1336,8 @@
 "   Cat-XXXXXX:    Category to operate on\n"
 "   Var-XXXXXX:    Variable to work on\n"
 "   Value-XXXXXX:  Value to work on\n"
-"   Match-XXXXXX:  Extra match required to match line\n";
+"   Match-XXXXXX:  Extra match required to match line\n"
+"   Line-XXXXXX:   Line in category to operate on (used with delete and insert actions)\n";
 
 static int action_updateconfig(struct mansession *s, const struct message *m)
 {
@@ -1356,11 +1374,35 @@
 		}
 	} else {
 		switch(result) {
-			case -1: astman_send_error(s, m, "Unknown action command");
+		case UNKNOWN_ACTION:
+			astman_send_error(s, m, "Unknown action command");
 			break;
-			case -2: astman_send_error(s, m, "Category not specified");
+		case UNKNOWN_CATEGORY:
+			astman_send_error(s, m, "Given category does not exist");
 			break;
-			case -3: astman_send_error(s, m, "Problem with category, value, or line (if required)");
+		case UNSPECIFIED_CATEGORY:
+			astman_send_error(s, m, "Category not specified");
+			break;
+		case UNSPECIFIED_ARGUMENT:
+			astman_send_error(s, m, "Problem with category, value, or line (if required)");
+			break;
+		case FAILURE_ALLOCATION:
+			astman_send_error(s, m, "Memory allocation failure, this should not happen");
+			break;
+		case FAILURE_DELCAT:
+			astman_send_error(s, m, "Delete category did not complete successfully");
+			break;
+		case FAILURE_EMPTYCAT:
+			astman_send_error(s, m, "Empty category did not complete successfully");
+			break;
+		case FAILURE_UPDATE:
+			astman_send_error(s, m, "Update did not complete successfully");
+			break;
+		case FAILURE_DELETE:
+			astman_send_error(s, m, "Delete did not complete successfully");
+			break;
+		case FAILURE_APPEND:
+			astman_send_error(s, m, "Append did not complete successfully");
 			break;
 		}
 	}




More information about the asterisk-commits mailing list