diff options
-rw-r--r-- | include/asterisk/config.h | 5 | ||||
-rw-r--r-- | main/config.c | 16 | ||||
-rw-r--r-- | main/manager.c | 6 |
3 files changed, 19 insertions, 8 deletions
diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 2579ef279..541fea4ff 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -675,8 +675,11 @@ void ast_category_append(struct ast_config *config, struct ast_category *cat); * \details * This function is used to insert a new category above another category * matching the match parameter. + * + * \retval 0 if succeeded + * \retval -1 if NULL parameters or match category was not found */ -void ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match); +int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match); int ast_category_delete(struct ast_config *cfg, const char *category); /*! diff --git a/main/config.c b/main/config.c index 622d6ed76..55c40a955 100644 --- a/main/config.c +++ b/main/config.c @@ -783,24 +783,28 @@ void ast_category_append(struct ast_config *config, struct ast_category *categor config->current = category; } -void ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match) +int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match) { struct ast_category *cur_category; - if (!cat || !match) - return; + if (!config || !cat || !match) { + return -1; + } if (!strcasecmp(config->root->name, match)) { cat->next = config->root; config->root = cat; - return; + return 0; } - for (cur_category = config->root; cur_category; cur_category = cur_category->next) { + for (cur_category = config->root; cur_category && cur_category->next; + cur_category = cur_category->next) { if (!strcasecmp(cur_category->next->name, match)) { cat->next = cur_category->next; cur_category->next = cat; - break; + return 0; } } + + return -1; } static void ast_destroy_template_list(struct ast_category *cat) diff --git a/main/manager.c b/main/manager.c index 84dfcbb9b..953116609 100644 --- a/main/manager.c +++ b/main/manager.c @@ -3313,7 +3313,11 @@ static enum error_type handle_updates(struct mansession *s, const struct message if (ast_strlen_zero(match)) { ast_category_append(cfg, category); } else { - ast_category_insert(cfg, category, match); + if (ast_category_insert(cfg, category, match)) { + result = FAILURE_NEWCAT; + ast_category_destroy(category); + break; + } } } else if (!strcasecmp(action, "renamecat")) { if (ast_strlen_zero(value)) { |