--- pbx/pbx_config.c.orig 2012-02-02 11:49:19.920686402 +0400 +++ pbx/pbx_config.c 2012-02-02 14:14:54.887684109 +0400 @@ -66,12 +66,51 @@ static char *complete_dialplan_add_ignorepat(struct ast_cli_args *); static char *complete_dialplan_remove_extension(struct ast_cli_args *); static char *complete_dialplan_add_extension(struct ast_cli_args *); +static char *complete_dialplan_remove_context(struct ast_cli_args *); /* * Implementation of functions provided by this module */ /*! + * * REMOVE context command stuff + */ + +static char *handle_cli_dialplan_remove_context(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + + switch (cmd) { + case CLI_INIT: + e->command = "dialplan remove context"; + e->usage = + "Usage: dialplan remove context \n" + " Removes all extensions from a specified context.\n"; + return NULL; + case CLI_GENERATE: + return complete_dialplan_remove_context(a); + } + + if (a->argc != 4) + return CLI_SHOWUSAGE; + + struct ast_context *con = ast_context_find(a->argv[3]); + + if (!con) { + ast_cli(a->fd, "There is no such context as '%s'\n", + a->argv[3]); + return CLI_SUCCESS; + } else { + ast_context_destroy(con, registrar); + ast_cli(a->fd, "Removing context '%s'\n", + a->argv[3]); + return CLI_SUCCESS; + } + + ast_cli(a->fd, "Failed to remove context '%s'\n", + a->argv[3]); + return CLI_FAILURE; +} +/*! * REMOVE INCLUDE command stuff */ static char *handle_cli_dialplan_remove_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) @@ -1023,6 +1062,31 @@ return CLI_SUCCESS; } +static char *complete_dialplan_remove_context(struct ast_cli_args *a) +{ + int which = 0; + + if (a->pos == 3) { /* complete context */ + struct ast_context *c = NULL; + int len = strlen(a->word); + char *res = NULL; + + /* try to lock contexts list ... */ + if (ast_rdlock_contexts()) { + ast_log(LOG_WARNING, "Failed to lock contexts list\n"); + return NULL; + } + + /* walk through all contexts */ + while ( !res && (c = ast_walk_contexts(c)) ) + if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n) + res = strdup(ast_get_context_name(c)); + ast_unlock_contexts(); + return res; + } + return NULL; +} + /*! dialplan add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local */ static char *complete_dialplan_add_extension(struct ast_cli_args *a) { @@ -1321,6 +1385,7 @@ static struct ast_cli_entry cli_pbx_config[] = { AST_CLI_DEFINE(handle_cli_dialplan_add_extension, "Add new extension into context"), AST_CLI_DEFINE(handle_cli_dialplan_remove_extension, "Remove a specified extension"), + AST_CLI_DEFINE(handle_cli_dialplan_remove_context, "Remove a specified context"), AST_CLI_DEFINE(handle_cli_dialplan_add_ignorepat, "Add new ignore pattern"), AST_CLI_DEFINE(handle_cli_dialplan_remove_ignorepat, "Remove ignore pattern from context"), AST_CLI_DEFINE(handle_cli_dialplan_add_include, "Include context in other context"),