[asterisk-commits] markster: trunk r38489 - in /trunk: config.c include/asterisk/config.h manager.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Jul 29 15:02:37 MST 2006


Author: markster
Date: Sat Jul 29 17:02:37 2006
New Revision: 38489

URL: http://svn.digium.com/view/asterisk?rev=38489&view=rev
Log:
Allow updates to match specific lines, allow specification of object or 
no when appending.

Modified:
    trunk/config.c
    trunk/include/asterisk/config.h
    trunk/manager.c

Modified: trunk/config.c
URL: http://svn.digium.com/view/asterisk/trunk/config.c?rev=38489&r1=38488&r2=38489&view=diff
==============================================================================
--- trunk/config.c (original)
+++ trunk/config.c Sat Jul 29 17:02:37 2006
@@ -323,9 +323,10 @@
 	return config;
 }
 
-int ast_variable_delete(struct ast_category *category, char *variable)
-{
-	struct ast_variable *cur, *prev=NULL;
+int ast_variable_delete(struct ast_category *category, char *variable, char *match)
+{
+	struct ast_variable *cur, *prev=NULL, *curn;
+	int res = -1;
 	cur = category->root;
 	while (cur) {
 		if (cur->name == variable) {
@@ -349,7 +350,8 @@
 	prev = NULL;
 	cur = category->root;
 	while (cur) {
-		if (!strcasecmp(cur->name, variable)) {
+		curn = cur->next;
+		if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
 			if (prev) {
 				prev->next = cur->next;
 				if (cur == category->last)
@@ -361,15 +363,16 @@
 			}
 			cur->next = NULL;
 			ast_variables_destroy(cur);
-			return 0;
-		}
-		prev = cur;
-		cur = cur->next;
-	}
-	return -1;
-}
-
-int ast_variable_update(struct ast_category *category, char *variable, char *value)
+			res = 0;
+		} else
+			prev = cur;
+
+		cur = curn;
+	}
+	return res;
+}
+
+int ast_variable_update(struct ast_category *category, char *variable, char *value, char *match)
 {
 	struct ast_variable *cur, *prev=NULL, *newer;
 	newer = ast_variable_new(variable, value);
@@ -379,6 +382,7 @@
 	while (cur) {
 		if (cur->name == variable) {
 			newer->next = cur->next;
+			newer->object = cur->object;
 			if (prev)
 				prev->next = newer;
 			else
@@ -396,8 +400,9 @@
 	prev = NULL;
 	cur = category->root;
 	while (cur) {
-		if (!strcasecmp(cur->name, variable)) {
+		if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
 			newer->next = cur->next;
+			newer->object = cur->object;
 			if (prev)
 				prev->next = newer;
 			else

Modified: trunk/include/asterisk/config.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/config.h?rev=38489&r1=38488&r2=38489&view=diff
==============================================================================
--- trunk/include/asterisk/config.h (original)
+++ trunk/include/asterisk/config.h Sat Jul 29 17:02:37 2006
@@ -182,8 +182,8 @@
 
 struct ast_variable *ast_variable_new(const char *name, const char *value);
 void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
-int ast_variable_delete(struct ast_category *category, char *variable);
-int ast_variable_update(struct ast_category *category, char *variable, char *value);
+int ast_variable_delete(struct ast_category *category, char *variable, char *match);
+int ast_variable_update(struct ast_category *category, char *variable, char *value, char *match);
 
 int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
 

Modified: trunk/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/manager.c?rev=38489&r1=38488&r2=38489&view=diff
==============================================================================
--- trunk/manager.c (original)
+++ trunk/manager.c Sat Jul 29 17:02:37 2006
@@ -906,7 +906,7 @@
 {
 	int x;
 	char hdr[40];
-	char *action, *cat, *var, *value;
+	char *action, *cat, *var, *value, *match;
 	struct ast_category *category;
 	struct ast_variable *v;
 	
@@ -921,6 +921,8 @@
 		var = astman_get_header(m, hdr);
 		snprintf(hdr, sizeof(hdr), "Value-%06d", x);
 		value = astman_get_header(m, hdr);
+		snprintf(hdr, sizeof(hdr), "Match-%06d", x);
+		match = astman_get_header(m, hdr);
 		if (!strcasecmp(action, "newcat")) {
 			if (!ast_strlen_zero(cat)) {
 				category = ast_category_new(cat);
@@ -939,14 +941,16 @@
 				ast_category_delete(cfg, cat);
 		} 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);
+				ast_variable_update(category, var, value, match);
 		} else if (!strcasecmp(action, "delete")) {
 			if (!ast_strlen_zero(cat) && !ast_strlen_zero(var) && (category = ast_category_get(cfg, cat)))
-				ast_variable_delete(category, var);
+				ast_variable_delete(category, var, match);
 		} 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))){
+				if (match && !strcasecmp(match, "object"))
+					v->object = 1;
 				ast_variable_append(category, v);
 			}
 		}
@@ -962,7 +966,8 @@
 "   Action-XXXXXX: Action to Take (NewCat,RenameCat,DelCat,Update,Delete,Append)\n"
 "   Cat-XXXXXX:    Category to operate on\n"
 "   Var-XXXXXX:    Variable to work on\n"
-"   Value-XXXXXX:  Value to work on\n";
+"   Value-XXXXXX:  Value to work on\n"
+"   Match-XXXXXX:  Extra match required to match line\n";
 
 static int action_updateconfig(struct mansession *s, struct message *m)
 {



More information about the asterisk-commits mailing list