mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 07:35:18 +00:00
Add new ast_complete_applications function so that we can use it with the
'channel originate ... application <app>' CLI command. (And yeah, I cleaned up some whitespace in res_clioriginate.c... big whoop, wanna fight about it!?) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@196758 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1199,6 +1199,14 @@ int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b);
|
||||
unsigned int ast_hashtab_hash_contexts(const void *obj);
|
||||
/*! @} */
|
||||
|
||||
/*!
|
||||
* \brief Command completion for the list of installed applications.
|
||||
*
|
||||
* This can be called from a CLI command completion function that wants to
|
||||
* complete from the list of available applications.
|
||||
*/
|
||||
char *ast_complete_applications(const char *line, const char *word, int state);
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
}
|
||||
#endif
|
||||
|
35
main/pbx.c
35
main/pbx.c
@@ -5558,9 +5558,6 @@ static char *handle_show_application(struct ast_cli_entry *e, int cmd, struct as
|
||||
{
|
||||
struct ast_app *aa;
|
||||
int app, no_registered_app = 1;
|
||||
char *ret = NULL;
|
||||
int which = 0;
|
||||
int wordlen;
|
||||
|
||||
switch (cmd) {
|
||||
case CLI_INIT:
|
||||
@@ -5575,18 +5572,7 @@ static char *handle_show_application(struct ast_cli_entry *e, int cmd, struct as
|
||||
* application at one time. You can type 'show application Dial Echo' and
|
||||
* you will see informations about these two applications ...
|
||||
*/
|
||||
wordlen = strlen(a->word);
|
||||
/* return the n-th [partial] matching entry */
|
||||
AST_RWLIST_RDLOCK(&apps);
|
||||
AST_RWLIST_TRAVERSE(&apps, aa, list) {
|
||||
if (!strncasecmp(a->word, aa->name, wordlen) && ++which > a->n) {
|
||||
ret = ast_strdup(aa->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&apps);
|
||||
|
||||
return ret;
|
||||
return ast_complete_applications(a->line, a->word, a->n);
|
||||
}
|
||||
|
||||
if (a->argc < 4) {
|
||||
@@ -9878,3 +9864,22 @@ int ast_async_parseable_goto(struct ast_channel *chan, const char *goto_string)
|
||||
{
|
||||
return pbx_parseable_goto(chan, goto_string, 1);
|
||||
}
|
||||
|
||||
char *ast_complete_applications(const char *line, const char *word, int state)
|
||||
{
|
||||
struct ast_app *app = NULL;
|
||||
int which = 0;
|
||||
char *ret = NULL;
|
||||
size_t wordlen = strlen(word);
|
||||
|
||||
AST_RWLIST_RDLOCK(&apps);
|
||||
AST_RWLIST_TRAVERSE(&apps, app, list) {
|
||||
if (!strncasecmp(word, app->name, wordlen) && ++which > state) {
|
||||
ret = ast_strdup(app->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
AST_RWLIST_UNLOCK(&apps);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@@ -118,7 +118,7 @@ static char *orig_exten(int fd, const char *chan, const char *data)
|
||||
static char *handle_orig(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||
{
|
||||
static const char * const choices[] = { "application", "extension", NULL };
|
||||
char *res;
|
||||
char *res = NULL;
|
||||
switch (cmd) {
|
||||
case CLI_INIT:
|
||||
e->command = "channel originate";
|
||||
@@ -140,14 +140,16 @@ static char *handle_orig(struct ast_cli_entry *e, int cmd, struct ast_cli_args *
|
||||
"used. If no extension is given, the 's' extension will be used.\n";
|
||||
return NULL;
|
||||
case CLI_GENERATE:
|
||||
if (a->pos != 3)
|
||||
return NULL;
|
||||
|
||||
/* ugly, can be removed when CLI entries have ast_module pointers */
|
||||
ast_module_ref(ast_module_info->self);
|
||||
if (a->pos == 3) {
|
||||
res = ast_cli_complete(a->word, choices, a->n);
|
||||
} else if (a->pos == 4) {
|
||||
if (!strcasecmp("application", a->argv[3])) {
|
||||
res = ast_complete_applications(a->line, a->word, a->n);
|
||||
}
|
||||
}
|
||||
ast_module_unref(ast_module_info->self);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user