summaryrefslogtreecommitdiff
path: root/pbx
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2007-10-11 19:03:06 +0000
committerRussell Bryant <russell@russellbryant.com>2007-10-11 19:03:06 +0000
commite97a723cf1710d0c40bcbe7ac53fc943abedd2c4 (patch)
tree44dcb2c14abed6932db4f248b17626a01a38f59b /pbx
parent8a52c889883f2013e377d87389f07aec5b781122 (diff)
Merge a ton of NEW_CLI conversions. Thanks to everyone that helped out! :)
(closes issue #10724) Reported by: eliel Patches: chan_skinny.c.patch uploaded by eliel (license 64) chan_oss.c.patch uploaded by eliel (license 64) chan_mgcp.c.patch2 uploaded by eliel (license 64) pbx_config.c.patch uploaded by seanbright (license 71) iax2-provision.c.patch uploaded by eliel (license 64) chan_gtalk.c.patch uploaded by eliel (license 64) pbx_ael.c.patch uploaded by seanbright (license 71) file.c.patch uploaded by seanbright (license 71) image.c.patch uploaded by seanbright (license 71) cli.c.patch uploaded by moy (license 222) astobj2.c.patch uploaded by moy (license 222) asterisk.c.patch uploaded by moy (license 222) res_limit.c.patch uploaded by seanbright (license 71) res_convert.c.patch uploaded by seanbright (license 71) res_crypto.c.patch uploaded by seanbright (license 71) app_osplookup.c.patch uploaded by seanbright (license 71) app_rpt.c.patch uploaded by seanbright (license 71) app_mixmonitor.c.patch uploaded by seanbright (license 71) channel.c.patch uploaded by seanbright (license 71) translate.c.patch uploaded by seanbright (license 71) udptl.c.patch uploaded by seanbright (license 71) threadstorage.c.patch uploaded by seanbright (license 71) db.c.patch uploaded by seanbright (license 71) cdr.c.patch uploaded by moy (license 222) pbd_dundi.c.patch uploaded by moy (license 222) app_osplookup-rev83558.patch uploaded by moy (license 222) res_clioriginate.c.patch uploaded by moy (license 222) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@85460 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'pbx')
-rw-r--r--pbx/pbx_ael.c93
-rw-r--r--pbx/pbx_config.c597
-rw-r--r--pbx/pbx_dundi.c577
3 files changed, 673 insertions, 594 deletions
diff --git a/pbx/pbx_ael.c b/pbx/pbx_ael.c
index 68902a073..f5a54f0bf 100644
--- a/pbx/pbx_ael.c
+++ b/pbx/pbx_ael.c
@@ -948,65 +948,62 @@ static int pbx_load_module(void)
}
/* CLI interface */
-static int ael2_debug_read(int fd, int argc, char *argv[])
+static char *handle_cli_ael_debug_multiple(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- aeldebug |= DEBUG_READ;
- return 0;
-}
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ael debug [read|tokens|macros|contexts|off]";
+ e->usage =
+ "Usage: ael debug [read|tokens|macros|contexts|off]\n"
+ " Enable AEL read, token, macro, or context debugging,\n"
+ " or disable all AEL debugging messages. Note: this\n"
+ " currently does nothing.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
-static int ael2_debug_tokens(int fd, int argc, char *argv[])
-{
- aeldebug |= DEBUG_TOKENS;
- return 0;
-}
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
+
+ if (!strcasecmp(a->argv[2], "read"))
+ aeldebug |= DEBUG_READ;
+ else if (!strcasecmp(a->argv[2], "tokens"))
+ aeldebug |= DEBUG_TOKENS;
+ else if (!strcasecmp(a->argv[2], "macros"))
+ aeldebug |= DEBUG_MACROS;
+ else if (!strcasecmp(a->argv[2], "contexts"))
+ aeldebug |= DEBUG_CONTEXTS;
+ else if (!strcasecmp(a->argv[2], "off"))
+ aeldebug = 0;
+ else
+ return CLI_SHOWUSAGE;
-static int ael2_debug_macros(int fd, int argc, char *argv[])
-{
- aeldebug |= DEBUG_MACROS;
- return 0;
+ return CLI_SUCCESS;
}
-static int ael2_debug_contexts(int fd, int argc, char *argv[])
+static char *handle_cli_ael_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- aeldebug |= DEBUG_CONTEXTS;
- return 0;
-}
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "ael reload";
+ e->usage =
+ "Usage: ael reload\n"
+ " Reloads AEL configuration.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
-static int ael2_no_debug(int fd, int argc, char *argv[])
-{
- aeldebug = 0;
- return 0;
-}
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
-static int ael2_reload(int fd, int argc, char *argv[])
-{
- return (pbx_load_module());
+ return (pbx_load_module() ? CLI_FAILURE : CLI_SUCCESS);
}
-static struct ast_cli_entry cli_ael_no_debug = {
- { "ael", "no", "debug", NULL },
- ael2_no_debug, NULL,
- NULL };
-
static struct ast_cli_entry cli_ael[] = {
- { { "ael", "reload", NULL },
- ael2_reload, "Reload AEL configuration" },
-
- { { "ael", "debug", "read", NULL },
- ael2_debug_read, "Enable AEL read debug (does nothing)" },
-
- { { "ael", "debug", "tokens", NULL },
- ael2_debug_tokens, "Enable AEL tokens debug (does nothing)" },
-
- { { "ael", "debug", "macros", NULL },
- ael2_debug_macros, "Enable AEL macros debug (does nothing)" },
-
- { { "ael", "debug", "contexts", NULL },
- ael2_debug_contexts, "Enable AEL contexts debug (does nothing)" },
-
- { { "ael", "nodebug", NULL },
- ael2_no_debug, "Disable AEL debug messages",
- NULL, NULL, &cli_ael_no_debug },
+ NEW_CLI(handle_cli_ael_reload, "Reload AEL configuration"),
+ NEW_CLI(handle_cli_ael_debug_multiple, "Enable AEL debugging flags")
};
static int unload_module(void)
diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c
index 449bf3583..4c7c42ae2 100644
--- a/pbx/pbx_config.c
+++ b/pbx/pbx_config.c
@@ -56,56 +56,14 @@ AST_MUTEX_DEFINE_STATIC(save_dialplan_lock);
static struct ast_context *local_contexts = NULL;
/*
- * Help for commands provided by this module ...
+ * Prototypes for our completion functions
*/
-static char context_add_extension_help[] =
-"Usage: dialplan add extension <exten>,<priority>,<app>,<app-data>\n"
-" into <context> [replace]\n\n"
-" This command will add new extension into <context>. If there is an\n"
-" existence of extension with the same priority and last 'replace'\n"
-" arguments is given here we simply replace this extension.\n"
-"\n"
-"Example: dialplan add extension 6123,1,Dial,IAX/216.207.245.56/6123 into local\n"
-" Now, you can dial 6123 and talk to Markster :)\n";
-
-static char context_remove_extension_help[] =
-"Usage: dialplan remove extension exten@context [priority]\n"
-" Remove an extension from a given context. If a priority\n"
-" is given, only that specific priority from the given extension\n"
-" will be removed.\n";
-
-static char context_add_ignorepat_help[] =
-"Usage: dialplan add ignorepat <pattern> into <context>\n"
-" This command adds a new ignore pattern into context <context>\n"
-"\n"
-"Example: dialplan add ignorepat _3XX into local\n";
-
-static char context_remove_ignorepat_help[] =
-"Usage: dialplan remove ignorepat <pattern> from <context>\n"
-" This command removes an ignore pattern from context <context>\n"
-"\n"
-"Example: dialplan remove ignorepat _3XX from local\n";
-
-static char context_add_include_help[] =
-"Usage: dialplan add include <context> into <context>\n"
-" Include a context in another context.\n";
-
-static char context_remove_include_help[] =
-"Usage: dialplan remove include <context> from <context>\n"
-" Remove an included context from another context.\n";
-
-static char save_dialplan_help[] =
-"Usage: dialplan save [/path/to/extension/file]\n"
-" Save dialplan created by pbx_config module.\n"
-"\n"
-"Example: dialplan save (/etc/asterisk/extensions.conf)\n"
-" dialplan save /home/markster (/home/markster/extensions.conf)\n";
-
-static char reload_extensions_help[] =
-"Usage: dialplan reload\n"
-" reload extensions.conf without reloading any other modules\n"
-" This command does not delete global variables unless\n"
-" clearglobalvars is set to yes in extensions.conf\n";
+static char *complete_dialplan_remove_include(struct ast_cli_args *);
+static char *complete_dialplan_add_include(struct ast_cli_args *);
+static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *);
+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 *);
/*
* Implementation of functions provided by this module
@@ -114,23 +72,31 @@ static char reload_extensions_help[] =
/*!
* REMOVE INCLUDE command stuff
*/
-static int handle_context_remove_include(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_remove_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 6)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan remove include";
+ e->usage =
+ "Usage: dialplan remove include <context> from <context>\n"
+ " Remove an included context from another context.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_dialplan_remove_include(a);
+ }
- if (strcmp(argv[4], "into"))
- return RESULT_SHOWUSAGE;
+ if (strcmp(a->argv[4], "from"))
+ return CLI_SHOWUSAGE;
- if (!ast_context_remove_include(argv[5], argv[3], registrar)) {
- ast_cli(fd, "We are not including '%s' into '%s' now\n",
- argv[3], argv[5]);
- return RESULT_SUCCESS;
+ if (!ast_context_remove_include(a->argv[5], a->argv[3], registrar)) {
+ ast_cli(a->fd, "We are not including '%s' into '%s' now\n",
+ a->argv[3], a->argv[5]);
+ return CLI_SUCCESS;
}
- ast_cli(fd, "Failed to remove '%s' include from '%s' context\n",
- argv[3], argv[5]);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Failed to remove '%s' include from '%s' context\n",
+ a->argv[3], a->argv[5]);
+ return CLI_FAILURE;
}
/*! \brief return true if 'name' is included by context c */
@@ -208,15 +174,14 @@ static int split_ec(const char *src, char **ext, char ** const ctx)
}
/* _X_ is the string we need to complete */
-static char *complete_context_remove_include(const char *line, const char *word,
- int pos, int state)
+static char *complete_dialplan_remove_include(struct ast_cli_args *a)
{
int which = 0;
char *res = NULL;
- int len = strlen(word); /* how many bytes to match */
+ int len = strlen(a->word); /* how many bytes to match */
struct ast_context *c = NULL;
- if (pos == 3) { /* "dialplan remove include _X_" */
+ if (a->pos == 3) { /* "dialplan remove include _X_" */
if (ast_wrlock_contexts()) {
ast_log(LOG_ERROR, "Failed to lock context list\n");
return NULL;
@@ -233,7 +198,7 @@ static char *complete_context_remove_include(const char *line, const char *word,
struct ast_context *nc = NULL;
int already_served = 0;
- if (!partial_match(i_name, word, len))
+ if (!partial_match(i_name, a->word, len))
continue; /* not matched */
/* check if this include is already served or not */
@@ -244,7 +209,7 @@ static char *complete_context_remove_include(const char *line, const char *word,
while ( (nc = ast_walk_contexts(nc)) && nc != c && !already_served)
already_served = lookup_ci(nc, i_name);
- if (!already_served && ++which > state)
+ if (!already_served && ++which > a->n)
res = strdup(i_name);
}
ast_unlock_context(c);
@@ -252,15 +217,15 @@ static char *complete_context_remove_include(const char *line, const char *word,
ast_unlock_contexts();
return res;
- } else if (pos == 4) { /* "dialplan remove include CTX _X_" */
+ } else if (a->pos == 4) { /* "dialplan remove include CTX _X_" */
/*
* complete as 'from', but only if previous context is really
* included somewhere
*/
char *context, *dupline;
- const char *s = skip_words(line, 3); /* skip 'dialplan' 'remove' 'include' */
+ const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
- if (state > 0)
+ if (a->n > 0)
return NULL;
context = dupline = strdup(s);
if (!dupline) {
@@ -284,12 +249,12 @@ static char *complete_context_remove_include(const char *line, const char *word,
ast_log(LOG_WARNING, "%s not included anywhere\n", context);
free(context);
return res;
- } else if (pos == 5) { /* "dialplan remove include CTX from _X_" */
+ } else if (a->pos == 5) { /* "dialplan remove include CTX from _X_" */
/*
* Context from which we removing include ...
*/
char *context, *dupline, *from;
- const char *s = skip_words(line, 3); /* skip 'dialplan' 'remove' 'include' */
+ const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'include' */
context = dupline = strdup(s);
if (!dupline) {
ast_log(LOG_ERROR, "Out of free memory\n");
@@ -315,10 +280,10 @@ static char *complete_context_remove_include(const char *line, const char *word,
c = NULL;
while ( !res && (c = ast_walk_contexts(c))) {
const char *c_name = ast_get_context_name(c);
- if (!partial_match(c_name, word, len)) /* not a good target */
+ if (!partial_match(c_name, a->word, len)) /* not a good target */
continue;
/* walk through all includes and check if it is our context */
- if (lookup_ci(c, context) && ++which > state)
+ if (lookup_ci(c, context) && ++which > a->n)
res = strdup(c_name);
}
ast_unlock_contexts();
@@ -332,19 +297,33 @@ static char *complete_context_remove_include(const char *line, const char *word,
/*!
* REMOVE EXTENSION command stuff
*/
-static int handle_context_remove_extension(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_remove_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int removing_priority = 0;
char *exten, *context;
- int ret = RESULT_FAILURE;
+ char *ret = CLI_FAILURE;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan remove extension";
+ e->usage =
+ "Usage: dialplan remove extension exten@context [priority]\n"
+ " Remove an extension from a given context. If a priority\n"
+ " is given, only that specific priority from the given extension\n"
+ " will be removed.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_dialplan_remove_extension(a);
+ }
- if (argc != 5 && argc != 4) return RESULT_SHOWUSAGE;
+ if (a->argc != 5 && a->argc != 4)
+ return CLI_SHOWUSAGE;
/*
* Priority input checking ...
*/
- if (argc == 5) {
- char *c = argv[4];
+ if (a->argc == 5) {
+ char *c = a->argv[4];
/* check for digits in whole parameter for right priority ...
* why? because atoi (strtol) returns 0 if any characters in
@@ -356,16 +335,16 @@ static int handle_context_remove_extension(int fd, int argc, char *argv[])
while (*c && isdigit(*c))
c++;
if (*c) { /* non-digit in string */
- ast_cli(fd, "Invalid priority '%s'\n", argv[4]);
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Invalid priority '%s'\n", a->argv[4]);
+ return CLI_FAILURE;
}
- removing_priority = atoi(argv[4]);
+ removing_priority = atoi(a->argv[4]);
}
if (removing_priority == 0) {
- ast_cli(fd, "If you want to remove whole extension, please " \
+ ast_cli(a->fd, "If you want to remove whole extension, please " \
"omit priority argument\n");
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
}
@@ -373,27 +352,27 @@ static int handle_context_remove_extension(int fd, int argc, char *argv[])
/*
* Format exten@context checking ...
*/
- if (split_ec(argv[3], &exten, &context))
- return RESULT_FAILURE; /* XXX malloc failure */
+ if (split_ec(a->argv[3], &exten, &context))
+ return CLI_FAILURE; /* XXX malloc failure */
if ((!strlen(exten)) || (!(strlen(context)))) {
- ast_cli(fd, "Missing extension or context name in third argument '%s'\n",
- argv[3]);
+ ast_cli(a->fd, "Missing extension or context name in third argument '%s'\n",
+ a->argv[3]);
free(exten);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
if (!ast_context_remove_extension(context, exten, removing_priority, registrar)) {
if (!removing_priority)
- ast_cli(fd, "Whole extension %s@%s removed\n",
+ ast_cli(a->fd, "Whole extension %s@%s removed\n",
exten, context);
else
- ast_cli(fd, "Extension %s@%s with priority %d removed\n",
+ ast_cli(a->fd, "Extension %s@%s with priority %d removed\n",
exten, context, removing_priority);
- ret = RESULT_SUCCESS;
+ ret = CLI_SUCCESS;
} else {
- ast_cli(fd, "Failed to remove extension %s@%s\n", exten, context);
- ret = RESULT_FAILURE;
+ ast_cli(a->fd, "Failed to remove extension %s@%s\n", exten, context);
+ ret = CLI_FAILURE;
}
free(exten);
return ret;
@@ -446,8 +425,7 @@ static int fix_complete_args(const char *line, char **word, int *pos)
}
#endif /* BROKEN_READLINE */
-static char *complete_context_remove_extension(const char *line, const char *word, int pos,
- int state)
+static char *complete_dialplan_remove_extension(struct ast_cli_args *a)
{
char *ret = NULL;
int which = 0;
@@ -458,20 +436,20 @@ static char *complete_context_remove_extension(const char *line, const char *wor
* Fix arguments, *word is a new allocated structure, REMEMBER to
* free *word when you want to return from this function ...
*/
- if (fix_complete_args(line, &word2, &pos)) {
+ if (fix_complete_args(a->line, &word2, &a->pos)) {
ast_log(LOG_ERROR, "Out of free memory\n");
return NULL;
}
- word = word2;
+ a->word = word2;
#endif
- if (pos == 3) { /* 'dialplan remove extension _X_' (exten@context ... */
+ if (a->pos == 3) { /* 'dialplan remove extension _X_' (exten@context ... */
struct ast_context *c = NULL;
char *context = NULL, *exten = NULL;
int le = 0; /* length of extension */
int lc = 0; /* length of context */
- lc = split_ec(word, &exten, &context);
+ lc = split_ec(a->word, &exten, &context);
#ifdef BROKEN_READLINE
free(word2);
#endif
@@ -492,7 +470,7 @@ static char *complete_context_remove_extension(const char *line, const char *wor
if (!partial_match(ast_get_context_name(c), context, lc))
continue; /* context not matched */
while ( (e = ast_walk_context_extensions(c, e)) ) { /* try to complete extensions ... */
- if ( partial_match(ast_get_extension_name(e), exten, le) && ++which > state) { /* n-th match */
+ if ( partial_match(ast_get_extension_name(e), exten, le) && ++which > a->n) { /* n-th match */
/* If there is an extension then return exten@context. XXX otherwise ? */
if (exten)
asprintf(&ret, "%s@%s", ast_get_extension_name(e), ast_get_context_name(c));
@@ -507,11 +485,11 @@ static char *complete_context_remove_extension(const char *line, const char *wor
error2:
if (exten)
free(exten);
- } else if (pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
+ } else if (a->pos == 4) { /* 'dialplan remove extension EXT _X_' (priority) */
char *exten = NULL, *context, *p;
struct ast_context *c;
int le, lc, len;
- const char *s = skip_words(line, 3); /* skip 'dialplan' 'remove' 'extension' */
+ const char *s = skip_words(a->line, 3); /* skip 'dialplan' 'remove' 'extension' */
int i = split_ec(s, &exten, &context); /* parse ext@context */
if (i) /* error */
@@ -522,7 +500,7 @@ static char *complete_context_remove_extension(const char *line, const char *wor
*p = '\0';
le = strlen(exten);
lc = strlen(context);
- len = strlen(word);
+ len = strlen(a->word);
if (le == 0 || lc == 0)
goto error3;
@@ -550,7 +528,7 @@ static char *complete_context_remove_extension(const char *line, const char *wor
priority = NULL;
while ( !ret && (priority = ast_walk_extension_priorities(e, priority)) ) {
snprintf(buffer, sizeof(buffer), "%u", ast_get_extension_priority(priority));
- if (partial_match(buffer, word, len) && ++which > state) /* n-th match */
+ if (partial_match(buffer, a->word, len) && ++which > a->n) /* n-th match */
ret = strdup(buffer);
}
break;
@@ -571,76 +549,86 @@ static char *complete_context_remove_extension(const char *line, const char *wor
/*!
* Include context ...
*/
-static int handle_context_add_include(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_add_include(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 6) /* dialplan add include CTX in CTX */
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan add include";
+ e->usage =
+ "Usage: dialplan add include <context> into <context>\n"
+ " Include a context in another context.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_dialplan_add_include(a);
+ }
+
+ if (a->argc != 6) /* dialplan add include CTX in CTX */
+ return CLI_SHOWUSAGE;
/* fifth arg must be 'into' ... */
- if (strcmp(argv[4], "into"))
- return RESULT_SHOWUSAGE;
+ if (strcmp(a->argv[4], "into"))
+ return CLI_SHOWUSAGE;
- if (ast_context_add_include(argv[5], argv[3], registrar)) {
+ if (ast_context_add_include(a->argv[5], a->argv[3], registrar)) {
switch (errno) {
case ENOMEM:
- ast_cli(fd, "Out of memory for context addition\n");
+ ast_cli(a->fd, "Out of memory for context addition\n");
break;
case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please try again later\n");
+ ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
break;
case EEXIST:
- ast_cli(fd, "Context '%s' already included in '%s' context\n",
- argv[3], argv[5]);
+ ast_cli(a->fd, "Context '%s' already included in '%s' context\n",
+ a->argv[3], a->argv[5]);
break;
case ENOENT:
case EINVAL:
- ast_cli(fd, "There is no existence of context '%s'\n",
- errno == ENOENT ? argv[5] : argv[3]);
+ ast_cli(a->fd, "There is no existence of context '%s'\n",
+ errno == ENOENT ? a->argv[5] : a->argv[3]);
break;
default:
- ast_cli(fd, "Failed to include '%s' in '%s' context\n",
- argv[3], argv[5]);
+ ast_cli(a->fd, "Failed to include '%s' in '%s' context\n",
+ a->argv[3], a->argv[5]);
break;
}
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
/* show some info ... */
- ast_cli(fd, "Context '%s' included in '%s' context\n",
- argv[3], argv[5]);
+ ast_cli(a->fd, "Context '%s' included in '%s' context\n",
+ a->argv[3], a->argv[5]);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static char *complete_context_add_include(const char *line, const char *word, int pos,
- int state)
+static char *complete_dialplan_add_include(struct ast_cli_args *a)
{
struct ast_context *c;
int which = 0;
char *ret = NULL;
- int len = strlen(word);
+ int len = strlen(a->word);
- if (pos == 3) { /* 'dialplan add include _X_' (context) ... */
+ if (a->pos == 3) { /* 'dialplan add include _X_' (context) ... */
if (ast_rdlock_contexts()) {
ast_log(LOG_ERROR, "Failed to lock context list\n");
return NULL;
}
for (c = NULL; !ret && (c = ast_walk_contexts(c)); )
- if (partial_match(ast_get_context_name(c), word, len) && ++which > state)
+ if (partial_match(ast_get_context_name(c), a->word, len) && ++which > a->n)
ret = strdup(ast_get_context_name(c));
ast_unlock_contexts();
return ret;
- } else if (pos == 4) { /* dialplan add include CTX _X_ */
+ } else if (a->pos == 4) { /* dialplan add include CTX _X_ */
/* complete as 'into' if context exists or we are unable to check */
char *context, *dupline;
struct ast_context *c;
- const char *s = skip_words(line, 3); /* should not fail */
+ const char *s = skip_words(a->line, 3); /* should not fail */
- if (state != 0) /* only once */
+ if (a->n != 0) /* only once */
return NULL;
/* parse context from line ... */
@@ -664,9 +652,9 @@ static char *complete_context_add_include(const char *line, const char *word, in
}
free(context);
return ret;
- } else if (pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
+ } else if (a->pos == 5) { /* 'dialplan add include CTX into _X_' (dst context) */
char *context, *dupline, *into;
- const char *s = skip_words(line, 3); /* should not fail */
+ const char *s = skip_words(a->line, 3); /* should not fail */
context = dupline = strdup(s);
if (!dupline) {
ast_log(LOG_ERROR, "Out of free memory\n");
@@ -694,9 +682,9 @@ static char *complete_context_add_include(const char *line, const char *word, in
for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
if (!strcmp(context, ast_get_context_name(c)))
continue; /* skip ourselves */
- if (partial_match(ast_get_context_name(c), word, len) &&
+ if (partial_match(ast_get_context_name(c), a->word, len) &&
!lookup_ci(c, context) /* not included yet */ &&
- ++which > state)
+ ++which > a->n)
ret = strdup(ast_get_context_name(c));
}
} else {
@@ -714,7 +702,7 @@ static char *complete_context_add_include(const char *line, const char *word, in
/*!
* \brief 'save dialplan' CLI command implementation functions ...
*/
-static int handle_save_dialplan(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char filename[256];
struct ast_context *c;
@@ -723,32 +711,45 @@ static int handle_save_dialplan(int fd, int argc, char *argv[])
int incomplete = 0; /* incomplete config write? */
FILE *output;
struct ast_flags config_flags = { 0 };
-
const char *base, *slash, *file;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan save";
+ e->usage =
+ "Usage: dialplan save [/path/to/extension/file]\n"
+ " Save dialplan created by pbx_config module.\n"
+ "\n"
+ "Example: dialplan save (/etc/asterisk/extensions.conf)\n"
+ " dialplan save /home/markster (/home/markster/extensions.conf)\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
if (! (static_config && !write_protect_config)) {
- ast_cli(fd,
+ ast_cli(a->fd,
"I can't save dialplan now, see '%s' example file.\n",
config);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- if (argc != 2 && argc != 3)
- return RESULT_SHOWUSAGE;
+ if (a->argc != 2 && a->argc != 3)
+ return CLI_SHOWUSAGE;
if (ast_mutex_lock(&save_dialplan_lock)) {
- ast_cli(fd,
+ ast_cli(a->fd,
"Failed to lock dialplan saving (another proccess saving?)\n");
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
/* XXX the code here is quite loose, a pathname with .conf in it
* is assumed to be a complete pathname
*/
- if (argc == 3) { /* have config path. Look for *.conf */
- base = argv[2];
- if (!strstr(argv[2], ".conf")) { /*no, this is assumed to be a pathname */
+ if (a->argc == 3) { /* have config path. Look for *.conf */
+ base = a->argv[2];
+ if (!strstr(a->argv[2], ".conf")) { /*no, this is assumed to be a pathname */
/* if filename ends with '/', do not add one */
- slash = (*(argv[2] + strlen(argv[2]) -1) == '/') ? "/" : "";
+ slash = (*(a->argv[2] + strlen(a->argv[2]) -1) == '/') ? "/" : "";
file = config; /* default: 'extensions.conf' */
} else { /* yes, complete file name */
slash = "";
@@ -766,20 +767,20 @@ static int handle_save_dialplan(int fd, int argc, char *argv[])
/* try to lock contexts list */
if (ast_rdlock_contexts()) {
- ast_cli(fd, "Failed to lock contexts list\n");
+ ast_cli(a->fd, "Failed to lock contexts list\n");
ast_mutex_unlock(&save_dialplan_lock);
ast_config_destroy(cfg);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
/* create new file ... */
if (!(output = fopen(filename, "wt"))) {
- ast_cli(fd, "Failed to create file '%s'\n",
+ ast_cli(a->fd, "Failed to create file '%s'\n",
filename);
ast_unlock_contexts();
ast_mutex_unlock(&save_dialplan_lock);
ast_config_destroy(cfg);
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
/* fireout general info */
@@ -845,7 +846,7 @@ static int handle_save_dialplan(int fd, int argc, char *argv[])
PUT_CTX_HDR;
- if (ast_get_extension_priority(p)==PRIORITY_HINT) { /* easy */
+ if (ast_get_extension_priority(p) == PRIORITY_HINT) { /* easy */
fprintf(output, "exten => %s,hint,%s\n",
ast_get_extension_name(p),
ast_get_extension_app(p));
@@ -914,19 +915,19 @@ static int handle_save_dialplan(int fd, int argc, char *argv[])
fclose(output);
if (incomplete) {
- ast_cli(fd, "Saved dialplan is incomplete\n");
- return RESULT_FAILURE;
+ ast_cli(a->fd, "Saved dialplan is incomplete\n");
+ return CLI_FAILURE;
}
- ast_cli(fd, "Dialplan successfully saved into '%s'\n",
+ ast_cli(a->fd, "Dialplan successfully saved into '%s'\n",
filename);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/*!
* \brief ADD EXTENSION command stuff
*/
-static int handle_context_add_extension(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_add_extension(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char *whole_exten;
char *exten, *prior;
@@ -934,16 +935,35 @@ static int handle_context_add_extension(int fd, int argc, char *argv[])
char *cidmatch, *app, *app_data;
char *start, *end;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan add extension";
+ e->usage =
+ "Usage: dialplan add extension <exten>,<priority>,<app>,<app-data>\n"
+ " into <context> [replace]\n\n"
+ " This command will add new extension into <context>. If there is an\n"
+ " existence of extension with the same priority and last 'replace'\n"
+ " arguments is given here we simply replace this extension.\n"
+ "\n"
+ "Example: dialplan add extension 6123,1,Dial,IAX/216.207.245.56/6123 into local\n"
+ " Now, you can dial 6123 and talk to Markster :)\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_dialplan_add_extension(a);
+ }
+
/* check for arguments at first */
- if (argc != 6 && argc != 7)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[4], "into"))
- return RESULT_SHOWUSAGE;
- if (argc == 7) if (strcmp(argv[6], "replace")) return RESULT_SHOWUSAGE;
+ if (a->argc != 6 && a->argc != 7)
+ return CLI_SHOWUSAGE;
+ if (strcmp(a->argv[4], "into"))
+ return CLI_SHOWUSAGE;
+ if (a->argc == 7)
+ if (strcmp(a->argv[6], "replace"))
+ return CLI_SHOWUSAGE;
/* XXX overwrite argv[3] */
- whole_exten = argv[3];
- exten = strsep(&whole_exten,",");
+ whole_exten = a->argv[3];
+ exten = strsep(&whole_exten,",");
if (strchr(exten, '/')) {
cidmatch = exten;
strsep(&cidmatch,"/");
@@ -956,7 +976,7 @@ static int handle_context_add_extension(int fd, int argc, char *argv[])
iprior = PRIORITY_HINT;
} else {
if (sscanf(prior, "%d", &iprior) != 1) {
- ast_cli(fd, "'%s' is not a valid priority\n", prior);
+ ast_cli(a->fd, "'%s' is not a valid priority\n", prior);
prior = NULL;
}
}
@@ -977,58 +997,58 @@ static int handle_context_add_extension(int fd, int argc, char *argv[])
}
if (!exten || !prior || !app || (!app_data && iprior != PRIORITY_HINT))
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
if (!app_data)
app_data="";
- if (ast_add_extension(argv[5], argc == 7 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
+ if (ast_add_extension(a->argv[5], a->argc == 7 ? 1 : 0, exten, iprior, NULL, cidmatch, app,
(void *)strdup(app_data), free, registrar)) {
switch (errno) {
case ENOMEM:
- ast_cli(fd, "Out of free memory\n");
+ ast_cli(a->fd, "Out of free memory\n");
break;
case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please try again later\n");
+ ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
break;
case ENOENT:
- ast_cli(fd, "No existence of '%s' context\n", argv[5]);
+ ast_cli(a->fd, "No existence of '%s' context\n", a->argv[5]);
break;
case EEXIST:
- ast_cli(fd, "Extension %s@%s with priority %s already exists\n",
- exten, argv[5], prior);
+ ast_cli(a->fd, "Extension %s@%s with priority %s already exists\n",
+ exten, a->argv[5], prior);
break;
default:
- ast_cli(fd, "Failed to add '%s,%s,%s,%s' extension into '%s' context\n",
- exten, prior, app, app_data, argv[5]);
+ ast_cli(a->fd, "Failed to add '%s,%s,%s,%s' extension into '%s' context\n",
+ exten, prior, app, app_data, a->argv[5]);
break;
}
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- if (argc == 7)
- ast_cli(fd, "Extension %s@%s (%s) replace by '%s,%s,%s,%s'\n",
- exten, argv[5], prior, exten, prior, app, app_data);
+ if (a->argc == 7)
+ ast_cli(a->fd, "Extension %s@%s (%s) replace by '%s,%s,%s,%s'\n",
+ exten, a->argv[5], prior, exten, prior, app, app_data);
else
- ast_cli(fd, "Extension '%s,%s,%s,%s' added into '%s' context\n",
- exten, prior, app, app_data, argv[5]);
+ ast_cli(a->fd, "Extension '%s,%s,%s,%s' added into '%s' context\n",
+ exten, prior, app, app_data, a->argv[5]);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
/*! dialplan add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local */
-static char *complete_context_add_extension(const char *line, const char *word, int pos, int state)
+static char *complete_dialplan_add_extension(struct ast_cli_args *a)
{
int which = 0;
- if (pos == 4) { /* complete 'into' word ... */
- return (state == 0) ? strdup("into") : NULL;
- } else if (pos == 5) { /* complete context */
+ if (a->pos == 4) { /* complete 'into' word ... */
+ return (a->n == 0) ? strdup("into") : NULL;
+ } else if (a->pos == 5) { /* complete context */
struct ast_context *c = NULL;
- int len = strlen(word);
+ int len = strlen(a->word);
char *res = NULL;
/* try to lock contexts list ... */
@@ -1039,12 +1059,12 @@ static char *complete_context_add_extension(const char *line, const char *word,
/* walk through all contexts */
while ( !res && (c = ast_walk_contexts(c)) )
- if (partial_match(ast_get_context_name(c), word, len) && ++which > state)
+ 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;
- } else if (pos == 6) {
- return state == 0 ? strdup("replace") : NULL;
+ } else if (a->pos == 6) {
+ return a->n == 0 ? strdup("replace") : NULL;
}
return NULL;
}
@@ -1052,60 +1072,74 @@ static char *complete_context_add_extension(const char *line, const char *word,
/*!
* IGNOREPAT CLI stuff
*/
-static int handle_context_add_ignorepat(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_add_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 6)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[4], "into"))
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan add ignorepat";
+ e->usage =
+ "Usage: dialplan add ignorepat <pattern> into <context>\n"
+ " This command adds a new ignore pattern into context <context>\n"
+ "\n"
+ "Example: dialplan add ignorepat _3XX into local\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_dialplan_add_ignorepat(a);
+ }
+
+ if (a->argc != 6)
+ return CLI_SHOWUSAGE;
+
+ if (strcmp(a->argv[4], "into"))
+ return CLI_SHOWUSAGE;
- if (ast_context_add_ignorepat(argv[5], argv[3], registrar)) {
+ if (ast_context_add_ignorepat(a->argv[5], a->argv[3], registrar)) {
switch (errno) {
case ENOMEM:
- ast_cli(fd, "Out of free memory\n");
+ ast_cli(a->fd, "Out of free memory\n");
break;
case ENOENT:
- ast_cli(fd, "There is no existence of '%s' context\n", argv[5]);
+ ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
break;
case EEXIST:
- ast_cli(fd, "Ignore pattern '%s' already included in '%s' context\n",
- argv[3], argv[5]);
+ ast_cli(a->fd, "Ignore pattern '%s' already included in '%s' context\n",
+ a->argv[3], a->argv[5]);
break;
case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please, try again later\n");
+ ast_cli(a->fd, "Failed to lock context(s) list, please, try again later\n");
break;
default:
- ast_cli(fd, "Failed to add ingore pattern '%s' into '%s' context\n",
- argv[3], argv[5]);
+ ast_cli(a->fd, "Failed to add ingore pattern '%s' into '%s' context\n",
+ a->argv[3], a->argv[5]);
break;
}
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- ast_cli(fd, "Ignore pattern '%s' added into '%s' context\n",
- argv[3], argv[5]);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Ignore pattern '%s' added into '%s' context\n",
+ a->argv[3], a->argv[5]);
+
+ return CLI_SUCCESS;
}
-static char *complete_context_add_ignorepat(const char *line, const char *word,
- int pos, int state)
+static char *complete_dialplan_add_ignorepat(struct ast_cli_args *a)
{
- if (pos == 4)
- return state == 0 ? strdup("into") : NULL;
- else if (pos == 5) {
+ if (a->pos == 4)
+ return a->n == 0 ? strdup("into") : NULL;
+ else if (a->pos == 5) {
struct ast_context *c;
int which = 0;
char *dupline, *ignorepat = NULL;
const char *s;
char *ret = NULL;
- int len = strlen(word);
+ int len = strlen(a->word);
/* XXX skip first three words 'dialplan' 'add' 'ignorepat' */
- s = skip_words(line, 3);
+ s = skip_words(a->line, 3);
if (s == NULL)
return NULL;
dupline = strdup(s);
@@ -1123,11 +1157,11 @@ static char *complete_context_add_ignorepat(const char *line, const char *word,
for (c = NULL; !ret && (c = ast_walk_contexts(c));) {
int found = 0;
- if (!partial_match(ast_get_context_name(c), word, len))
+ if (!partial_match(ast_get_context_name(c), a->word, len))
continue; /* not mine */
if (ignorepat) /* there must be one, right ? */
found = lookup_c_ip(c, ignorepat);
- if (!found && ++which > state)
+ if (!found && ++which > a->n)
ret = strdup(ast_get_context_name(c));
}
@@ -1140,49 +1174,63 @@ static char *complete_context_add_ignorepat(const char *line, const char *word,
return NULL;
}
-static int handle_context_remove_ignorepat(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_remove_ignorepat(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 6)
- return RESULT_SHOWUSAGE;
- if (strcmp(argv[4], "from"))
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan remove ignorepat";
+ e->usage =
+ "Usage: dialplan remove ignorepat <pattern> from <context>\n"
+ " This command removes an ignore pattern from context <context>\n"
+ "\n"
+ "Example: dialplan remove ignorepat _3XX from local\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_dialplan_remove_ignorepat(a);
+ }
+
+ if (a->argc != 6)
+ return CLI_SHOWUSAGE;
+
+ if (strcmp(a->argv[4], "from"))
+ return CLI_SHOWUSAGE;
- if (ast_context_remove_ignorepat(argv[5], argv[3], registrar)) {
+ if (ast_context_remove_ignorepat(a->argv[5], a->argv[3], registrar)) {
switch (errno) {
case EBUSY:
- ast_cli(fd, "Failed to lock context(s) list, please try again later\n");
+ ast_cli(a->fd, "Failed to lock context(s) list, please try again later\n");
break;
case ENOENT:
- ast_cli(fd, "There is no existence of '%s' context\n", argv[5]);
+ ast_cli(a->fd, "There is no existence of '%s' context\n", a->argv[5]);
break;
case EINVAL:
- ast_cli(fd, "There is no existence of '%s' ignore pattern in '%s' context\n",
- argv[3], argv[5]);
+ ast_cli(a->fd, "There is no existence of '%s' ignore pattern in '%s' context\n",
+ a->argv[3], a->argv[5]);
break;
default:
- ast_cli(fd, "Failed to remove ignore pattern '%s' from '%s' context\n", argv[3], argv[5]);
+ ast_cli(a->fd, "Failed to remove ignore pattern '%s' from '%s' context\n",
+ a->argv[3], a->argv[5]);
break;
}
- return RESULT_FAILURE;
+ return CLI_FAILURE;
}
- ast_cli(fd, "Ignore pattern '%s' removed from '%s' context\n",
- argv[3], argv[5]);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Ignore pattern '%s' removed from '%s' context\n",
+ a->argv[3], a->argv[5]);
+ return CLI_SUCCESS;
}
-static char *complete_context_remove_ignorepat(const char *line, const char *word,
- int pos, int state)
+static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a)
{
struct ast_context *c;
int which = 0;
char *ret = NULL;
- if (pos == 3) {
- int len = strlen(word);
+ if (a->pos == 3) {
+ int len = strlen(a->word);
if (ast_rdlock_contexts()) {
ast_log(LOG_WARNING, "Failed to lock contexts list\n");
return NULL;
@@ -1195,7 +1243,7 @@ static char *complete_context_remove_ignorepat(const char *line, const char *wor
continue;
for (ip = NULL; !ret && (ip = ast_walk_context_ignorepats(c, ip));) {
- if (partial_match(ast_get_ignorepat_name(ip), word, len) && ++which > state) {
+ if (partial_match(ast_get_ignorepat_name(ip), a->word, len) && ++which > a->n) {
/* n-th match */
struct ast_context *cw = NULL;
int found = 0;
@@ -1211,13 +1259,13 @@ static char *complete_context_remove_ignorepat(const char *line, const char *wor
}
ast_unlock_contexts();
return ret;
- } else if (pos == 4) {
- return state == 0 ? strdup("from") : NULL;
- } else if (pos == 5) { /* XXX check this */
+ } else if (a->pos == 4) {
+ return a->n == 0 ? strdup("from") : NULL;
+ } else if (a->pos == 5) { /* XXX check this */
char *dupline, *duplinet, *ignorepat;
- int len = strlen(word);
+ int len = strlen(a->word);
- dupline = strdup(line);
+ dupline = strdup(a->line);
if (!dupline) {
ast_log(LOG_WARNING, "Out of free memory\n");
return NULL;
@@ -1242,9 +1290,9 @@ static char *complete_context_remove_ignorepat(const char *line, const char *wor
for (c = NULL; !ret && (c = ast_walk_contexts(c)); ) {
if (ast_rdlock_context(c)) /* fail, skip it */
continue;
- if (!partial_match(ast_get_context_name(c), word, len))
+ if (!partial_match(ast_get_context_name(c), a->word, len))
continue;
- if (lookup_c_ip(c, ignorepat) && ++which > state)
+ if (lookup_c_ip(c, ignorepat) && ++which > a->n)
ret = strdup(ast_get_context_name(c));
ast_unlock_context(c);
}
@@ -1258,54 +1306,47 @@ static char *complete_context_remove_ignorepat(const char *line, const char *wor
static int pbx_load_module(void);
-static int handle_reload_extensions(int fd, int argc, char *argv[])
+static char *handle_cli_dialplan_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dialplan reload";
+ e->usage =
+ "Usage: dialplan reload\n"
+ " Reload extensions.conf without reloading any other\n"
+ " modules. This command does not delete global variables\n"
+ " unless clearglobalvars is set to yes in extensions.conf\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
+
if (clearglobalvars_config)
pbx_builtin_clear_globals();
+
pbx_load_module();
- return RESULT_SUCCESS;
+
+ return CLI_SUCCESS;
}
/*!
* CLI entries for commands provided by this module
*/
static struct ast_cli_entry cli_pbx_config[] = {
- { { "dialplan", "add", "extension", NULL },
- handle_context_add_extension, "Add new extension into context",
- context_add_extension_help, complete_context_add_extension },
-
- { { "dialplan", "remove", "extension", NULL },
- handle_context_remove_extension, "Remove a specified extension",
- context_remove_extension_help, complete_context_remove_extension },
-
- { { "dialplan", "add", "ignorepat", NULL },
- handle_context_add_ignorepat, "Add new ignore pattern",
- context_add_ignorepat_help, complete_context_add_ignorepat },
-
- { { "dialplan", "remove", "ignorepat", NULL },
- handle_context_remove_ignorepat, "Remove ignore pattern from context",
- context_remove_ignorepat_help, complete_context_remove_ignorepat },
-
- { { "dialplan", "add", "include", NULL },
- handle_context_add_include, "Include context in other context",
- context_add_include_help, complete_context_add_include },
-
- { { "dialplan", "remove", "include", NULL },
- handle_context_remove_include, "Remove a specified include from context",
- context_remove_include_help, complete_context_remove_include },
-
- { { "dialplan", "reload", NULL },
- handle_reload_extensions, "Reload extensions and *only* extensions",
- reload_extensions_help },
+ NEW_CLI(handle_cli_dialplan_add_extension, "Add new extension into context"),
+ NEW_CLI(handle_cli_dialplan_remove_extension, "Remove a specified extension"),
+ NEW_CLI(handle_cli_dialplan_add_ignorepat, "Add new ignore pattern"),
+ NEW_CLI(handle_cli_dialplan_remove_ignorepat, "Remove ignore pattern from context"),
+ NEW_CLI(handle_cli_dialplan_add_include, "Include context in other context"),
+ NEW_CLI(handle_cli_dialplan_remove_include, "Remove a specified include from context"),
+ NEW_CLI(handle_cli_dialplan_reload, "Reload extensions and *only* extensions")
};
-
-static struct ast_cli_entry cli_dialplan_save = {
- { "dialplan", "save", NULL },
- handle_save_dialplan, "Save dialplan",
- save_dialplan_help };
+static struct ast_cli_entry cli_dialplan_save =
+ NEW_CLI(handle_cli_dialplan_save, "Save dialplan");
/*!
* Standard module functions ...
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index d33e7c757..c2851eef2 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -2227,34 +2227,67 @@ static int start_network_thread(void)
return 0;
}
-static int dundi_do_debug(int fd, int argc, char *argv[])
+static char *dundi_do_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 2)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi debug";
+ e->usage =
+ "Usage: dundi debug\n"
+ " Enables dumping of DUNDi packets for debugging purposes\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 2)
+ return CLI_SHOWUSAGE;
dundidebug = 1;
- ast_cli(fd, "DUNDi Debugging Enabled\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi Debugging Enabled\n");
+ return CLI_SUCCESS;
}
-static int dundi_do_store_history(int fd, int argc, char *argv[])
+static char *dundi_do_store_history(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi store history";
+ e->usage =
+ "Usage: dundi store history\n"
+ " Enables storing of DUNDi requests and times for debugging\n"
+ "purposes\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
global_storehistory = 1;
- ast_cli(fd, "DUNDi History Storage Enabled\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi History Storage Enabled\n");
+ return CLI_SUCCESS;
}
-static int dundi_flush(int fd, int argc, char *argv[])
+static char *dundi_flush(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int stats = 0;
- if ((argc < 2) || (argc > 3))
- return RESULT_SHOWUSAGE;
- if (argc > 2) {
- if (!strcasecmp(argv[2], "stats"))
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi flush [stats]";
+ e->usage =
+ "Usage: dundi flush [stats]\n"
+ " Flushes DUNDi answer cache, used primarily for debug. If\n"
+ "'stats' is present, clears timer statistics instead of normal\n"
+ "operation.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if ((a->argc < 2) || (a->argc > 3))
+ return CLI_SHOWUSAGE;
+ if (a->argc > 2) {
+ if (!strcasecmp(a->argv[2], "stats"))
stats = 1;
else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
}
if (stats) {
/* Flush statistics */
@@ -2273,27 +2306,48 @@ static int dundi_flush(int fd, int argc, char *argv[])
AST_LIST_UNLOCK(&peers);
} else {
ast_db_deltree("dundi/cache", NULL);
- ast_cli(fd, "DUNDi Cache Flushed\n");
+ ast_cli(a->fd, "DUNDi Cache Flushed\n");
}
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int dundi_no_debug(int fd, int argc, char *argv[])
+static char *dundi_no_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi no debug";
+ e->usage =
+ "Usage: dundi no debug\n"
+ " Disables dumping of DUNDi packets for debugging purposes\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
dundidebug = 0;
- ast_cli(fd, "DUNDi Debugging Disabled\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi Debugging Disabled\n");
+ return CLI_SUCCESS;
}
-static int dundi_no_store_history(int fd, int argc, char *argv[])
+static char *dundi_no_store_history(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
- if (argc != 4)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi no store history";
+ e->usage =
+ "Usage: dundi no store history\n"
+ " Disables storing of DUNDi requests and times for debugging\n"
+ "purposes\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 4)
+ return CLI_SHOWUSAGE;
global_storehistory = 0;
- ast_cli(fd, "DUNDi History Storage Disabled\n");
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi History Storage Disabled\n");
+ return CLI_SUCCESS;
}
static char *model2str(int model)
@@ -2330,11 +2384,6 @@ static char *complete_peer_helper(const char *line, const char *word, int pos, i
return ret;
}
-static char *complete_peer_4(const char *line, const char *word, int pos, int state)
-{
- return complete_peer_helper(line, word, pos, state, 3);
-}
-
static int rescomp(const void *a, const void *b)
{
const struct dundi_result *resa, *resb;
@@ -2352,7 +2401,7 @@ static void sort_results(struct dundi_result *results, int count)
qsort(results, count, sizeof(results[0]), rescomp);
}
-static int dundi_do_lookup(int fd, int argc, char *argv[])
+static char *dundi_do_lookup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int res;
char tmp[256];
@@ -2362,15 +2411,28 @@ static int dundi_do_lookup(int fd, int argc, char *argv[])
int bypass = 0;
struct dundi_result dr[MAX_RESULTS];
struct timeval start;
- if ((argc < 3) || (argc > 4))
- return RESULT_SHOWUSAGE;
- if (argc > 3) {
- if (!strcasecmp(argv[3], "bypass"))
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi lookup";
+ e->usage =
+ "Usage: dundi lookup <number>[@context] [bypass]\n"
+ " Lookup the given number within the given DUNDi context\n"
+ "(or e164 if none is specified). Bypasses cache if 'bypass'\n"
+ "keyword is specified.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if ((a->argc < 3) || (a->argc > 4))
+ return CLI_SHOWUSAGE;
+ if (a->argc > 3) {
+ if (!strcasecmp(a->argv[3], "bypass"))
bypass=1;
else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
}
- ast_copy_string(tmp, argv[2], sizeof(tmp));
+ ast_copy_string(tmp, a->argv[2], sizeof(tmp));
context = strchr(tmp, '@');
if (context) {
*context = '\0';
@@ -2380,28 +2442,40 @@ static int dundi_do_lookup(int fd, int argc, char *argv[])
res = dundi_lookup(dr, MAX_RESULTS, NULL, context, tmp, bypass);
if (res < 0)
- ast_cli(fd, "DUNDi lookup returned error.\n");
+ ast_cli(a->fd, "DUNDi lookup returned error.\n");
else if (!res)
- ast_cli(fd, "DUNDi lookup returned no results.\n");
+ ast_cli(a->fd, "DUNDi lookup returned no results.\n");
else
sort_results(dr, res);
for (x=0;x<res;x++) {
- ast_cli(fd, "%3d. %5d %s/%s (%s)\n", x + 1, dr[x].weight, dr[x].tech, dr[x].dest, dundi_flags2str(fs, sizeof(fs), dr[x].flags));
- ast_cli(fd, " from %s, expires in %d s\n", dr[x].eid_str, dr[x].expiration);
+ ast_cli(a->fd, "%3d. %5d %s/%s (%s)\n", x + 1, dr[x].weight, dr[x].tech, dr[x].dest, dundi_flags2str(fs, sizeof(fs), dr[x].flags));
+ ast_cli(a->fd, " from %s, expires in %d s\n", dr[x].eid_str, dr[x].expiration);
}
- ast_cli(fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
+ return CLI_SUCCESS;
}
-static int dundi_do_precache(int fd, int argc, char *argv[])
+static char *dundi_do_precache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int res;
char tmp[256];
char *context;
struct timeval start;
- if ((argc < 3) || (argc > 3))
- return RESULT_SHOWUSAGE;
- ast_copy_string(tmp, argv[2], sizeof(tmp));
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi precache";
+ e->usage =
+ "Usage: dundi precache <number>[@context]\n"
+ " Lookup the given number within the given DUNDi context\n"
+ "(or e164 if none is specified) and precaches the results to any\n"
+ "upstream DUNDi push servers.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if ((a->argc < 3) || (a->argc > 3))
+ return CLI_SHOWUSAGE;
+ ast_copy_string(tmp, a->argv[2], sizeof(tmp));
context = strchr(tmp, '@');
if (context) {
*context = '\0';
@@ -2411,27 +2485,39 @@ static int dundi_do_precache(int fd, int argc, char *argv[])
res = dundi_precache(context, tmp);
if (res < 0)
- ast_cli(fd, "DUNDi precache returned error.\n");
+ ast_cli(a->fd, "DUNDi precache returned error.\n");
else if (!res)
- ast_cli(fd, "DUNDi precache returned no error.\n");
- ast_cli(fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi precache returned no error.\n");
+ ast_cli(a->fd, "DUNDi lookup completed in %d ms\n", ast_tvdiff_ms(ast_tvnow(), start));
+ return CLI_SUCCESS;
}
-static int dundi_do_query(int fd, int argc, char *argv[])
+static char *dundi_do_query(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int res;
char tmp[256];
char *context;
dundi_eid eid;
struct dundi_entity_info dei;
- if ((argc < 3) || (argc > 3))
- return RESULT_SHOWUSAGE;
- if (dundi_str_to_eid(&eid, argv[2])) {
- ast_cli(fd, "'%s' is not a valid EID!\n", argv[2]);
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi query";
+ e->usage =
+ "Usage: dundi query <entity>[@context]\n"
+ " Attempts to retrieve contact information for a specific\n"
+ "DUNDi entity identifier (EID) within a given DUNDi context (or\n"
+ "e164 if none is specified).\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
}
- ast_copy_string(tmp, argv[2], sizeof(tmp));
+ if ((a->argc < 3) || (a->argc > 3))
+ return CLI_SHOWUSAGE;
+ if (dundi_str_to_eid(&eid, a->argv[2])) {
+ ast_cli(a->fd, "'%s' is not a valid EID!\n", a->argv[2]);
+ return CLI_SHOWUSAGE;
+ }
+ ast_copy_string(tmp, a->argv[2], sizeof(tmp));
context = strchr(tmp, '@');
if (context) {
*context = '\0';
@@ -2439,36 +2525,45 @@ static int dundi_do_query(int fd, int argc, char *argv[])
}
res = dundi_query_eid(&dei, context, eid);
if (res < 0)
- ast_cli(fd, "DUNDi Query EID returned error.\n");
+ ast_cli(a->fd, "DUNDi Query EID returned error.\n");
else if (!res)
- ast_cli(fd, "DUNDi Query EID returned no results.\n");
+ ast_cli(a->fd, "DUNDi Query EID returned no results.\n");
else {
- ast_cli(fd, "DUNDi Query EID succeeded:\n");
- ast_cli(fd, "Department: %s\n", dei.orgunit);
- ast_cli(fd, "Organization: %s\n", dei.org);
- ast_cli(fd, "City/Locality: %s\n", dei.locality);
- ast_cli(fd, "State/Province: %s\n", dei.stateprov);
- ast_cli(fd, "Country: %s\n", dei.country);
- ast_cli(fd, "E-mail: %s\n", dei.email);
- ast_cli(fd, "Phone: %s\n", dei.phone);
- ast_cli(fd, "IP Address: %s\n", dei.ipaddr);
- }
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "DUNDi Query EID succeeded:\n");
+ ast_cli(a->fd, "Department: %s\n", dei.orgunit);
+ ast_cli(a->fd, "Organization: %s\n", dei.org);
+ ast_cli(a->fd, "City/Locality: %s\n", dei.locality);
+ ast_cli(a->fd, "State/Province: %s\n", dei.stateprov);
+ ast_cli(a->fd, "Country: %s\n", dei.country);
+ ast_cli(a->fd, "E-mail: %s\n", dei.email);
+ ast_cli(a->fd, "Phone: %s\n", dei.phone);
+ ast_cli(a->fd, "IP Address: %s\n", dei.ipaddr);
+ }
+ return CLI_SUCCESS;
}
-static int dundi_show_peer(int fd, int argc, char *argv[])
+static char *dundi_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct dundi_peer *peer;
struct permission *p;
char *order;
char eid_str[20];
int x, cnt;
-
- if (argc != 4)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show peer";
+ e->usage =
+ "Usage: dundi show peer [peer]\n"
+ " Provide a detailed description of a specifid DUNDi peer.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return complete_peer_helper(a->line, a->word, a->pos, a->n, 3);
+ }
+ if (a->argc != 4)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
AST_LIST_TRAVERSE(&peers, peer, list) {
- if (!strcasecmp(dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), argv[3]))
+ if (!strcasecmp(dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid), a->argv[3]))
break;
}
if (peer) {
@@ -2488,39 +2583,39 @@ static int dundi_show_peer(int fd, int argc, char *argv[])
default:
order = "Unknown";
}
- ast_cli(fd, "Peer: %s\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
- ast_cli(fd, "Model: %s\n", model2str(peer->model));
- ast_cli(fd, "Host: %s\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "<Unspecified>");
- ast_cli(fd, "Dynamic: %s\n", peer->dynamic ? "yes" : "no");
- ast_cli(fd, "Reg: %s\n", peer->registerid < 0 ? "No" : "Yes");
- ast_cli(fd, "In Key: %s\n", ast_strlen_zero(peer->inkey) ? "<None>" : peer->inkey);
- ast_cli(fd, "Out Key: %s\n", ast_strlen_zero(peer->outkey) ? "<None>" : peer->outkey);
+ ast_cli(a->fd, "Peer: %s\n", dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid));
+ ast_cli(a->fd, "Model: %s\n", model2str(peer->model));
+ ast_cli(a->fd, "Host: %s\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "<Unspecified>");
+ ast_cli(a->fd, "Dynamic: %s\n", peer->dynamic ? "yes" : "no");
+ ast_cli(a->fd, "Reg: %s\n", peer->registerid < 0 ? "No" : "Yes");
+ ast_cli(a->fd, "In Key: %s\n", ast_strlen_zero(peer->inkey) ? "<None>" : peer->inkey);
+ ast_cli(a->fd, "Out Key: %s\n", ast_strlen_zero(peer->outkey) ? "<None>" : peer->outkey);
if (!AST_LIST_EMPTY(&peer->include))
- ast_cli(fd, "Include logic%s:\n", peer->model & DUNDI_MODEL_OUTBOUND ? "" : " (IGNORED)");
+ ast_cli(a->fd, "Include logic%s:\n", peer->model & DUNDI_MODEL_OUTBOUND ? "" : " (IGNORED)");
AST_LIST_TRAVERSE(&peer->include, p, list)
- ast_cli(fd, "-- %s %s\n", p->allow ? "include" : "do not include", p->name);
+ ast_cli(a->fd, "-- %s %s\n", p->allow ? "include" : "do not include", p->name);
if (!AST_LIST_EMPTY(&peer->permit))
- ast_cli(fd, "Query logic%s:\n", peer->model & DUNDI_MODEL_INBOUND ? "" : " (IGNORED)");
+ ast_cli(a->fd, "Query logic%s:\n", peer->model & DUNDI_MODEL_INBOUND ? "" : " (IGNORED)");
AST_LIST_TRAVERSE(&peer->permit, p, list)
- ast_cli(fd, "-- %s %s\n", p->allow ? "permit" : "deny", p->name);
+ ast_cli(a->fd, "-- %s %s\n", p->allow ? "permit" : "deny", p->name);
cnt = 0;
for (x = 0;x < DUNDI_TIMING_HISTORY; x++) {
if (peer->lookups[x]) {
if (!cnt)
- ast_cli(fd, "Last few query times:\n");
- ast_cli(fd, "-- %d. %s (%d ms)\n", x + 1, peer->lookups[x], peer->lookuptimes[x]);
+ ast_cli(a->fd, "Last few query times:\n");
+ ast_cli(a->fd, "-- %d. %s (%d ms)\n", x + 1, peer->lookups[x], peer->lookuptimes[x]);
cnt++;
}
}
if (cnt)
- ast_cli(fd, "Average query time: %d ms\n", peer->avgms);
+ ast_cli(a->fd, "Average query time: %d ms\n", peer->avgms);
} else
- ast_cli(fd, "No such peer '%s'\n", argv[3]);
+ ast_cli(a->fd, "No such peer '%s'\n", a->argv[3]);
AST_LIST_UNLOCK(&peers);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
}
-static int dundi_show_peers(int fd, int argc, char *argv[])
+static char *dundi_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT2 "%-20.20s %-15.15s %-10.10s %-8.8s %-15.15s\n"
#define FORMAT "%-20.20s %-15.15s %s %-10.10s %-8.8s %-15.15s\n"
@@ -2532,17 +2627,28 @@ static int dundi_show_peers(int fd, int argc, char *argv[])
int offline_peers = 0;
int unmonitored_peers = 0;
int total_peers = 0;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show peers [registered|include|exclude|begin]";
+ e->usage =
+ "Usage: dundi show peers [registered|include|exclude|begin]\n"
+ " Lists all known DUNDi peers.\n"
+ " If 'registered' is present, only registered peers are shown.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
- if ((argc != 3) && (argc != 4) && (argc != 5))
- return RESULT_SHOWUSAGE;
- if ((argc == 4)) {
- if (!strcasecmp(argv[3], "registered")) {
+ if ((a->argc != 3) && (a->argc != 4) && (a->argc != 5))
+ return CLI_SHOWUSAGE;
+ if ((a->argc == 4)) {
+ if (!strcasecmp(a->argv[3], "registered")) {
registeredonly = 1;
} else
- return RESULT_SHOWUSAGE;
+ return CLI_SHOWUSAGE;
}
AST_LIST_LOCK(&peers);
- ast_cli(fd, FORMAT2, "EID", "Host", "Model", "AvgTime", "Status");
+ ast_cli(a->fd, FORMAT2, "EID", "Host", "Model", "AvgTime", "Status");
AST_LIST_TRAVERSE(&peers, peer, list) {
char status[20];
int print_line = -1;
@@ -2579,12 +2685,12 @@ static int dundi_show_peers(int fd, int argc, char *argv[])
peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : "(S)", model2str(peer->model), avgms, status);
- if (argc == 5) {
- if (!strcasecmp(argv[3],"include") && strstr(srch,argv[4])) {
+ if (a->argc == 5) {
+ if (!strcasecmp(a->argv[3],"include") && strstr(srch,a->argv[4])) {
print_line = -1;
- } else if (!strcasecmp(argv[3],"exclude") && !strstr(srch,argv[4])) {
+ } else if (!strcasecmp(a->argv[3],"exclude") && !strstr(srch,a->argv[4])) {
print_line = 1;
- } else if (!strcasecmp(argv[3],"begin") && !strncasecmp(srch,argv[4],strlen(argv[4]))) {
+ } else if (!strcasecmp(a->argv[3],"begin") && !strncasecmp(srch,a->argv[4],strlen(a->argv[4]))) {
print_line = -1;
} else {
print_line = 0;
@@ -2592,106 +2698,155 @@ static int dundi_show_peers(int fd, int argc, char *argv[])
}
if (print_line) {
- ast_cli(fd, FORMAT, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
+ ast_cli(a->fd, FORMAT, dundi_eid_to_str(eid_str, sizeof(eid_str), &peer->eid),
peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)",
peer->dynamic ? "(D)" : "(S)", model2str(peer->model), avgms, status);
}
}
- ast_cli(fd, "%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
+ ast_cli(a->fd, "%d dundi peers [%d online, %d offline, %d unmonitored]\n", total_peers, online_peers, offline_peers, unmonitored_peers);
AST_LIST_UNLOCK(&peers);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
-static int dundi_show_trans(int fd, int argc, char *argv[])
+static char *dundi_show_trans(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT2 "%-22.22s %-5.5s %-5.5s %-3.3s %-3.3s %-3.3s\n"
#define FORMAT "%-16.16s:%5d %-5.5d %-5.5d %-3.3d %-3.3d %-3.3d\n"
struct dundi_transaction *trans;
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show trans";
+ e->usage =
+ "Usage: dundi show trans\n"
+ " Lists all known DUNDi transactions.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
- ast_cli(fd, FORMAT2, "Remote", "Src", "Dst", "Tx", "Rx", "Ack");
+ ast_cli(a->fd, FORMAT2, "Remote", "Src", "Dst", "Tx", "Rx", "Ack");
AST_LIST_TRAVERSE(&alltrans, trans, all) {
- ast_cli(fd, FORMAT, ast_inet_ntoa(trans->addr.sin_addr),
+ ast_cli(a->fd, FORMAT, ast_inet_ntoa(trans->addr.sin_addr),
ntohs(trans->addr.sin_port), trans->strans, trans->dtrans, trans->oseqno, trans->iseqno, trans->aseqno);
}
AST_LIST_UNLOCK(&peers);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
-static int dundi_show_entityid(int fd, int argc, char *argv[])
+static char *dundi_show_entityid(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
char eid_str[20];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show entityid";
+ e->usage =
+ "Usage: dundi show entityid\n"
+ " Displays the global entityid for this host.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
dundi_eid_to_str(eid_str, sizeof(eid_str), &global_eid);
AST_LIST_UNLOCK(&peers);
- ast_cli(fd, "Global EID for this system is '%s'\n", eid_str);
- return RESULT_SUCCESS;
+ ast_cli(a->fd, "Global EID for this system is '%s'\n", eid_str);
+ return CLI_SUCCESS;
}
-static int dundi_show_requests(int fd, int argc, char *argv[])
+static char *dundi_show_requests(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT2 "%-15s %-15s %-15s %-3.3s %-3.3s\n"
#define FORMAT "%-15s %-15s %-15s %-3.3d %-3.3d\n"
struct dundi_request *req;
char eidstr[20];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show requests";
+ e->usage =
+ "Usage: dundi show requests\n"
+ " Lists all known pending DUNDi requests.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
- ast_cli(fd, FORMAT2, "Number", "Context", "Root", "Max", "Rsp");
+ ast_cli(a->fd, FORMAT2, "Number", "Context", "Root", "Max", "Rsp");
AST_LIST_TRAVERSE(&requests, req, list) {
- ast_cli(fd, FORMAT, req->number, req->dcontext,
+ ast_cli(a->fd, FORMAT, req->number, req->dcontext,
dundi_eid_zero(&req->root_eid) ? "<unspecified>" : dundi_eid_to_str(eidstr, sizeof(eidstr), &req->root_eid), req->maxcount, req->respcount);
}
AST_LIST_UNLOCK(&peers);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
/* Grok-a-dial DUNDi */
-static int dundi_show_mappings(int fd, int argc, char *argv[])
+static char *dundi_show_mappings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT2 "%-12.12s %-7.7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
#define FORMAT "%-12.12s %-7s %-12.12s %-10.10s %-5.5s %-25.25s\n"
struct dundi_mapping *map;
char fs[256];
char weight[8];
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show mappings";
+ e->usage =
+ "Usage: dundi show mappings\n"
+ " Lists all known DUNDi mappings.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
AST_LIST_LOCK(&peers);
- ast_cli(fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
+ ast_cli(a->fd, FORMAT2, "DUNDi Cntxt", "Weight", "Local Cntxt", "Options", "Tech", "Destination");
AST_LIST_TRAVERSE(&mappings, map, list) {
snprintf(weight, sizeof(weight), "%d", get_mapping_weight(map));
- ast_cli(fd, FORMAT, map->dcontext, weight,
+ ast_cli(a->fd, FORMAT, map->dcontext, weight,
ast_strlen_zero(map->lcontext) ? "<none>" : map->lcontext,
dundi_flags2str(fs, sizeof(fs), map->options), tech2str(map->tech), map->dest);
}
AST_LIST_UNLOCK(&peers);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
-static int dundi_show_precache(int fd, int argc, char *argv[])
+static char *dundi_show_precache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
#define FORMAT2 "%-12.12s %-12.12s %-10.10s\n"
#define FORMAT "%-12.12s %-12.12s %02d:%02d:%02d\n"
struct dundi_precache_queue *qe;
int h,m,s;
time_t now;
-
- if (argc != 3)
- return RESULT_SHOWUSAGE;
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "dundi show precache";
+ e->usage =
+ "Usage: dundi show precache\n"
+ " Lists all known DUNDi scheduled precache updates.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ if (a->argc != 3)
+ return CLI_SHOWUSAGE;
time(&now);
- ast_cli(fd, FORMAT2, "Number", "Context", "Expiration");
+ ast_cli(a->fd, FORMAT2, "Number", "Context", "Expiration");
AST_LIST_LOCK(&pcq);
AST_LIST_TRAVERSE(&pcq, qe, list) {
s = qe->expiration - now;
@@ -2699,145 +2854,31 @@ static int dundi_show_precache(int fd, int argc, char *argv[])
s = s % 3600;
m = s / 60;
s = s % 60;
- ast_cli(fd, FORMAT, qe->number, qe->context, h,m,s);
+ ast_cli(a->fd, FORMAT, qe->number, qe->context, h,m,s);
}
AST_LIST_UNLOCK(&pcq);
- return RESULT_SUCCESS;
+ return CLI_SUCCESS;
#undef FORMAT
#undef FORMAT2
}
-static const char debug_usage[] =
-"Usage: dundi debug\n"
-" Enables dumping of DUNDi packets for debugging purposes\n";
-
-static const char no_debug_usage[] =
-"Usage: dundi no debug\n"
-" Disables dumping of DUNDi packets for debugging purposes\n";
-
-static const char store_history_usage[] =
-"Usage: dundi store history\n"
-" Enables storing of DUNDi requests and times for debugging\n"
-"purposes\n";
-
-static const char no_store_history_usage[] =
-"Usage: dundi no store history\n"
-" Disables storing of DUNDi requests and times for debugging\n"
-"purposes\n";
-
-static const char show_peers_usage[] =
-"Usage: dundi show peers\n"
-" Lists all known DUNDi peers.\n";
-
-static const char show_trans_usage[] =
-"Usage: dundi show trans\n"
-" Lists all known DUNDi transactions.\n";
-
-static const char show_mappings_usage[] =
-"Usage: dundi show mappings\n"
-" Lists all known DUNDi mappings.\n";
-
-static const char show_precache_usage[] =
-"Usage: dundi show precache\n"
-" Lists all known DUNDi scheduled precache updates.\n";
-
-static const char show_entityid_usage[] =
-"Usage: dundi show entityid\n"
-" Displays the global entityid for this host.\n";
-
-static const char show_peer_usage[] =
-"Usage: dundi show peer [peer]\n"
-" Provide a detailed description of a specifid DUNDi peer.\n";
-
-static const char show_requests_usage[] =
-"Usage: dundi show requests\n"
-" Lists all known pending DUNDi requests.\n";
-
-static const char lookup_usage[] =
-"Usage: dundi lookup <number>[@context] [bypass]\n"
-" Lookup the given number within the given DUNDi context\n"
-"(or e164 if none is specified). Bypasses cache if 'bypass'\n"
-"keyword is specified.\n";
-
-static const char precache_usage[] =
-"Usage: dundi precache <number>[@context]\n"
-" Lookup the given number within the given DUNDi context\n"
-"(or e164 if none is specified) and precaches the results to any\n"
-"upstream DUNDi push servers.\n";
-
-static const char query_usage[] =
-"Usage: dundi query <entity>[@context]\n"
-" Attempts to retrieve contact information for a specific\n"
-"DUNDi entity identifier (EID) within a given DUNDi context (or\n"
-"e164 if none is specified).\n";
-
-static const char flush_usage[] =
-"Usage: dundi flush [stats]\n"
-" Flushes DUNDi answer cache, used primarily for debug. If\n"
-"'stats' is present, clears timer statistics instead of normal\n"
-"operation.\n";
-
static struct ast_cli_entry cli_dundi[] = {
- { { "dundi", "debug", NULL },
- dundi_do_debug, "Enable DUNDi debugging",
- debug_usage },
-
- { { "dundi", "store", "history", NULL },
- dundi_do_store_history, "Enable DUNDi historic records",
- store_history_usage },
-
- { { "dundi", "no", "store", "history", NULL },
- dundi_no_store_history, "Disable DUNDi historic records",
- no_store_history_usage },
-
- { { "dundi", "flush", NULL },
- dundi_flush, "Flush DUNDi cache",
- flush_usage },
-
- { { "dundi", "no", "debug", NULL },
- dundi_no_debug, "Disable DUNDi debugging",
- no_debug_usage },
-
- { { "dundi", "show", "peers", NULL },
- dundi_show_peers, "Show defined DUNDi peers",
- show_peers_usage },
-
- { { "dundi", "show", "trans", NULL },
- dundi_show_trans, "Show active DUNDi transactions",
- show_trans_usage },
-
- { { "dundi", "show", "entityid", NULL },
- dundi_show_entityid, "Display Global Entity ID",
- show_entityid_usage },
-
- { { "dundi", "show", "mappings", NULL },
- dundi_show_mappings, "Show DUNDi mappings",
- show_mappings_usage },
-
- { { "dundi", "show", "precache", NULL },
- dundi_show_precache, "Show DUNDi precache",
- show_precache_usage },
-
- { { "dundi", "show", "requests", NULL },
- dundi_show_requests, "Show DUNDi requests",
- show_requests_usage },
-
- { { "dundi", "show", "peer", NULL },
- dundi_show_peer, "Show info on a specific DUNDi peer",
- show_peer_usage, complete_peer_4 },
-
- { { "dundi", "lookup", NULL },
- dundi_do_lookup, "Lookup a number in DUNDi",
- lookup_usage },
-
- { { "dundi", "precache", NULL },
- dundi_do_precache, "Precache a number in DUNDi",
- precache_usage },
-
- { { "dundi", "query", NULL },
- dundi_do_query, "Query a DUNDi EID",
- query_usage },
+ NEW_CLI(dundi_do_debug, "Enable DUNDi debugging"),
+ NEW_CLI(dundi_no_debug, "Disable DUNDi debugging"),
+ NEW_CLI(dundi_do_store_history, "Enable DUNDi historic records"),
+ NEW_CLI(dundi_no_store_history, "Disable DUNDi historic records"),
+ NEW_CLI(dundi_flush, "Flush DUNDi cache"),
+ NEW_CLI(dundi_show_peers, "Show defined DUNDi peers"),
+ NEW_CLI(dundi_show_trans, "Show active DUNDi transactions"),
+ NEW_CLI(dundi_show_entityid, "Display Global Entity ID"),
+ NEW_CLI(dundi_show_mappings, "Show DUNDi mappings"),
+ NEW_CLI(dundi_show_precache, "Show DUNDi precache"),
+ NEW_CLI(dundi_show_requests, "Show DUNDi requests"),
+ NEW_CLI(dundi_show_peer, "Show info on a specific DUNDi peer"),
+ NEW_CLI(dundi_do_precache, "Precache a number in DUNDi"),
+ NEW_CLI(dundi_do_lookup, "Lookup a number in DUNDi"),
+ NEW_CLI(dundi_do_query, "Query a DUNDi EID"),
};
static struct dundi_transaction *create_transaction(struct dundi_peer *p)