45 static int cli_chan = 0;
58 e->
command =
"dialplan exec application";
60 "Usage: dialplan exec application <appname> [<args>]\n"
61 " Execute a single dialplan application call for\n"
62 " testing. A mock channel is used to execute\n"
63 " the application, so it may not make\n"
64 " sense to use all applications, and only\n"
65 " global variables should be used.\n"
66 " The ulaw, alaw, and h264 codecs are available.\n";
72 if (a->argc != e->
args + 1 && a->argc != e->
args + 2) {
76 app_name = (
char *) a->argv[3];
77 app_args = a->argc == e->
args + 2 ? (
char *) a->argv[4] : NULL;
85 ast_log(LOG_WARNING,
"Could not allocate an empty format capabilities structure\n");
90 ast_log(LOG_WARNING,
"Failed to append a ulaw format to capabilities for channel nativeformats\n");
95 ast_log(LOG_WARNING,
"Failed to append an alaw format to capabilities for channel nativeformats\n");
100 ast_log(LOG_WARNING,
"Failed to append an h264 format to capabilities for channel nativeformats\n");
104 c =
ast_channel_alloc(0,
AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0,
"CLIExec/%d", ++cli_chan);
106 ast_cli(a->fd,
"Unable to allocate mock channel for application execution.\n");
109 ast_channel_tech_set(c, &mock_channel_tech);
110 ast_channel_nativeformats_set(c, caps);
115 ast_channel_unlock(c);
119 ast_log(LOG_WARNING,
"Could not find application (%s)\n", app_name);
125 if (substituted_args) {
127 ast_cli(a->fd,
"Executing: %s(%s)\n", app_name,
ast_str_buffer(substituted_args));
129 ast_free(substituted_args);
131 ast_log(LOG_WARNING,
"Could not substitute application argument variables for %s\n", app_name);
132 ast_cli(a->fd,
"Executing: %s(%s)\n", app_name, app_args);
139 ast_cli(a->fd,
"Return Value: %s (%d)\n", ret ?
"Failure" :
"Success", ret);
145 AST_CLI_DEFINE(
handle_exec,
"Execute a dialplan application"),
148 static int unload_module(
void)
153 static int load_module(
void)
160 AST_MODULE_INFO_STANDARD_EXTENDED(
ASTERISK_GPL_KEY,
"Simple dialplan execution from the CLI");
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
descriptor for a cli entry.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
int args
This gets set in ast_cli_register()
General Asterisk PBX channel definitions.
Asterisk internal frame definitions.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Core PBX routines and definitions.
Support for dynamic strings.
const char * app_name(struct ast_app *app)
static char * handle_exec(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
CLI support for executing application.
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Module has failed to load, may be in an inconsistent state.
Standard Command Line Interface.
ast_app: A registered application
struct ast_app * pbx_findapp(const char *app)
Look up an application.
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.