diff options
-rw-r--r-- | config.c | 25 | ||||
-rw-r--r-- | include/asterisk/config.h | 4 | ||||
-rw-r--r-- | manager.c | 13 |
3 files changed, 26 insertions, 16 deletions
@@ -323,9 +323,10 @@ struct ast_config *ast_config_new(void) return config; } -int ast_variable_delete(struct ast_category *category, char *variable) +int ast_variable_delete(struct ast_category *category, char *variable, char *match) { - struct ast_variable *cur, *prev=NULL; + struct ast_variable *cur, *prev=NULL, *curn; + int res = -1; cur = category->root; while (cur) { if (cur->name == variable) { @@ -349,7 +350,8 @@ int ast_variable_delete(struct ast_category *category, char *variable) 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 @@ int ast_variable_delete(struct ast_category *category, char *variable) } cur->next = NULL; ast_variables_destroy(cur); - return 0; - } - prev = cur; - cur = cur->next; + res = 0; + } else + prev = cur; + + cur = curn; } - return -1; + return res; } -int ast_variable_update(struct ast_category *category, char *variable, char *value) +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 @@ int ast_variable_update(struct ast_category *category, char *variable, char *val while (cur) { if (cur->name == variable) { newer->next = cur->next; + newer->object = cur->object; if (prev) prev->next = newer; else @@ -396,8 +400,9 @@ int ast_variable_update(struct ast_category *category, char *variable, char *val 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 diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 7c3d75b44..43e1d7480 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -182,8 +182,8 @@ void ast_category_rename(struct ast_category *cat, const char *name); 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); @@ -906,7 +906,7 @@ static void handle_updates(struct mansession *s, struct message *m, struct ast_c { 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 @@ static void handle_updates(struct mansession *s, struct message *m, struct ast_c 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 @@ static void handle_updates(struct mansession *s, struct message *m, struct ast_c 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 @@ static char mandescr_updateconfig[] = " 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) { |