[asterisk-commits] seanbright: trunk r196758 - in /trunk: include/asterisk/ main/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue May 26 09:36:27 CDT 2009
Author: seanbright
Date: Tue May 26 09:36:11 2009
New Revision: 196758
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=196758
Log:
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!?)
Modified:
trunk/include/asterisk/pbx.h
trunk/main/pbx.c
trunk/res/res_clioriginate.c
Modified: trunk/include/asterisk/pbx.h
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/include/asterisk/pbx.h?view=diff&rev=196758&r1=196757&r2=196758
==============================================================================
--- trunk/include/asterisk/pbx.h (original)
+++ trunk/include/asterisk/pbx.h Tue May 26 09:36:11 2009
@@ -1199,6 +1199,14 @@
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
Modified: trunk/main/pbx.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/main/pbx.c?view=diff&rev=196758&r1=196757&r2=196758
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Tue May 26 09:36:11 2009
@@ -5558,9 +5558,6 @@
{
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 @@
* 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 @@
{
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;
+}
Modified: trunk/res/res_clioriginate.c
URL: http://svn.asterisk.org/svn-view/asterisk/trunk/res/res_clioriginate.c?view=diff&rev=196758&r1=196757&r2=196758
==============================================================================
--- trunk/res/res_clioriginate.c (original)
+++ trunk/res/res_clioriginate.c Tue May 26 09:36:11 2009
@@ -16,12 +16,12 @@
* at the top of the source tree.
*/
-/*!
+/*!
* \file
* \author Russell Bryant <russell at digium.com>
*
* \brief Originate calls via the CLI
- *
+ *
*/
#include "asterisk.h"
@@ -52,12 +52,12 @@
char *chantech;
char *chandata;
int reason = 0;
-
+
if (ast_strlen_zero(app))
return CLI_SHOWUSAGE;
chandata = ast_strdupa(chan);
-
+
chantech = strsep(&chandata, "/");
if (!chandata) {
ast_cli(fd, "*** No data provided after channel type! ***\n");
@@ -86,7 +86,7 @@
int reason = 0;
chandata = ast_strdupa(chan);
-
+
chantech = strsep(&chandata, "/");
if (!chandata) {
ast_cli(fd, "*** No data provided after channel type! ***\n");
@@ -102,7 +102,7 @@
exten = "s";
if (ast_strlen_zero(context))
context = "default";
-
+
ast_pbx_outgoing_exten(chantech, AST_FORMAT_SLINEAR, chandata, TIMEOUT * 1000, context, exten, 1, &reason, 0, NULL, NULL, NULL, NULL, NULL);
return CLI_SUCCESS;
@@ -118,11 +118,11 @@
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";
- e->usage =
+ e->usage =
" There are two ways to use this command. A call can be originated between a\n"
"channel and a specific application, or between a channel and an extension in\n"
"the dialplan. This is similar to call files or the manager originate action.\n"
@@ -140,14 +140,16 @@
"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);
- res = ast_cli_complete(a->word, choices, a->n);
+ 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;
}
@@ -158,7 +160,7 @@
ast_module_ref(ast_module_info->self);
if (!strcasecmp("application", a->argv[3])) {
- res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);
+ res = orig_app(a->fd, a->argv[2], a->argv[4], a->argv[5]);
} else if (!strcasecmp("extension", a->argv[3])) {
res = orig_exten(a->fd, a->argv[2], a->argv[4]);
} else {
More information about the asterisk-commits
mailing list