37 #include "asterisk/stasis_channels.h"
69 static struct ast_app *pbx_findapp_nolock(const
char *name)
74 AST_RWLIST_TRAVERSE(&apps, cur, list) {
75 cmp = strcasecmp(name, cur->name);
96 ret = pbx_findapp_nolock(app);
113 cur = pbx_findapp_nolock(app);
115 ast_log(LOG_WARNING,
"Already have an application '%s'\n", app);
120 length =
sizeof(*tmp) + strlen(app) + 1;
133 strcpy(tmp->name, app);
134 tmp->execute = execute;
139 if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
175 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
apps, cur, list) {
176 if (strcasecmp(tmp->name, cur->name) < 0) {
177 AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list);
181 AST_RWLIST_TRAVERSE_SAFE_END;
183 AST_RWLIST_INSERT_TAIL(&
apps, tmp, list);
185 ast_verb(5,
"Registered application '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, tmp->name));
192 static void print_app_docs(
struct ast_app *aa,
int fd)
201 if (!synopsis || !description || !arguments || !seealso) {
205 "%s -= Info about application '%s' =- %s\n\n"
217 COLORIZE(COLOR_MAGENTA, 0,
"[Synopsis]"), synopsis,
218 COLORIZE(COLOR_MAGENTA, 0,
"[Description]"), description,
219 COLORIZE(COLOR_MAGENTA, 0,
"[Syntax]"),
221 COLORIZE(COLOR_MAGENTA, 0,
"[Arguments]"), arguments,
222 COLORIZE(COLOR_MAGENTA, 0,
"[See Also]"), seealso);
225 ast_free(description);
232 "%s -= Info about application '%s' =- %s\n\n"
244 COLORIZE(COLOR_MAGENTA, 0,
"[Synopsis]"),
245 COLORIZE(COLOR_CYAN, 0,
S_OR(aa->
synopsis,
"Not available")),
246 COLORIZE(COLOR_MAGENTA, 0,
"[Description]"),
248 COLORIZE(COLOR_MAGENTA, 0,
"[Syntax]"),
249 COLORIZE(COLOR_CYAN, 0,
S_OR(aa->
syntax,
"Not available")),
250 COLORIZE(COLOR_MAGENTA, 0,
"[Arguments]"),
251 COLORIZE(COLOR_CYAN, 0,
S_OR(aa->
arguments,
"Not available")),
252 COLORIZE(COLOR_MAGENTA, 0,
"[See Also]"),
253 COLORIZE(COLOR_CYAN, 0,
S_OR(aa->
seealso,
"Not available")));
263 int app, no_registered_app = 1;
267 e->
command =
"core show application";
269 "Usage: core show application <application> [<application> [<application> [...]]]\n"
270 " Describes a particular application.\n";
282 return CLI_SHOWUSAGE;
286 AST_RWLIST_TRAVERSE(&
apps, aa, list) {
288 for (app = 3; app < a->argc; app++) {
289 if (strcasecmp(aa->name, a->argv[app])) {
294 no_registered_app = 0;
296 print_app_docs(aa, a->fd);
302 if (no_registered_app) {
303 ast_cli(a->fd,
"Your application(s) is (are) not registered\n");
313 int like = 0, describing = 0;
319 e->
command =
"core show applications [like|describing]";
321 "Usage: core show applications [{like|describing} <text>]\n"
322 " List applications which are currently available.\n"
323 " If 'like', <text> will be a substring of the app name\n"
324 " If 'describing', <text> will be a substring of the description\n";
332 if (AST_RWLIST_EMPTY(&
apps)) {
333 ast_cli(a->fd,
"There are no registered applications\n");
339 if ((a->argc == 5) && (!strcmp(a->argv[3],
"like"))) {
341 }
else if ((a->argc > 4) && (!strcmp(a->argv[3],
"describing"))) {
346 if ((!like) && (!describing)) {
347 ast_cli(a->fd,
" -= Registered Asterisk Applications =-\n");
349 ast_cli(a->fd,
" -= Matching Asterisk Applications =-\n");
352 AST_RWLIST_TRAVERSE(&
apps, aa, list) {
356 if (strcasestr(aa->name, a->argv[4])) {
360 }
else if (describing) {
365 for (i = 4; i < a->argc; i++) {
378 ast_cli(a->fd,
" %20s: %s\n", aa->name, aa->
synopsis ? aa->
synopsis :
"<Synopsis not available>");
381 if ((!like) && (!describing)) {
382 ast_cli(a->fd,
" -= %d Applications Registered =-\n",total_apps);
384 ast_cli(a->fd,
" -= %d Applications Matching =-\n",total_match);
403 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
apps, cur, list) {
404 cmp = strcasecmp(app, cur->name);
411 AST_RWLIST_REMOVE_CURRENT(list);
412 ast_verb(5,
"Unregistered application '%s'\n", cur->name);
421 AST_RWLIST_TRAVERSE_SAFE_END;
435 size_t wordlen = strlen(word);
438 AST_RWLIST_TRAVERSE(&
apps, app, list) {
439 cmp = strncasecmp(word, app->name, wordlen);
446 if (++which <= state) {
477 const char *saved_c_appl;
478 const char *saved_c_data;
481 saved_c_appl= ast_channel_appl(c);
482 saved_c_data= ast_channel_data(c);
485 ast_channel_appl_set(c, app->name);
486 ast_channel_data_set(c, data);
488 ast_channel_unlock(c);
491 u = __ast_module_user_add(app->module, c);
492 res = app->execute(c,
S_OR(data,
""));
493 if (app->module && u)
494 __ast_module_user_remove(app->module, u);
496 ast_channel_appl_set(c, saved_c_appl);
497 ast_channel_data_set(c, saved_c_data);
508 ast_log(LOG_WARNING,
"Could not find application (%s)\n", app_name);
510 struct ast_str *substituted_args = NULL;
512 if (!ast_strlen_zero(app_args) && (substituted_args =
ast_str_create(16))) {
515 ast_free(substituted_args);
517 if (!ast_strlen_zero(app_args)) {
518 ast_log(LOG_WARNING,
"Could not substitute application argument variables for %s\n", app_name);
520 res =
pbx_exec(chan, app, app_args);
529 AST_CLI_DEFINE(handle_show_applications,
"Shows registered dialplan applications"),
533 static void unload_pbx_app(
void)
const ast_string_field description
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
Private include file for pbx.
String manipulation functions.
const ast_string_field synopsis
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Registered applications container.
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
descriptor for a cli entry.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
int ast_pbx_exec_application(struct ast_channel *chan, const char *app_name, const char *app_args)
Execute an application.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
int ast_rdlock_contexts(void)
Read locks the context list.
static char * handle_show_application(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
'show application' CLI command implementation function...
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define ast_strdup(str)
A wrapper for strdup()
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
char * ast_xmldoc_build_arguments(const char *type, const char *name, const char *module)
Generate the [arguments] tag based on type of node ('application', 'function' or 'agi') and name...
ast_doc_src
From where the documentation come from, this structure is useful for use it inside application/functi...
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_STRING_FIELD(name)
Declare a string field.
int ast_register_application2(const char *app, int(*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod)
Dynamically register a new dial plan application.
char * ast_complete_applications(const char *line, const char *word, int state)
Command completion for the list of installed applications.
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
A set of macros to manage forward-linked lists.
Core PBX routines and definitions.
Support for dynamic strings.
const ast_string_field syntax
int ast_unlock_contexts(void)
Unlocks contexts.
const ast_string_field name
const char * app_name(struct ast_app *app)
#define ast_calloc(num, len)
A wrapper for calloc()
const char * ast_term_reset(void)
Returns the terminal reset code.
Asterisk XML Documentation API.
Prototypes for public functions only of internal interest,.
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
char * ast_xmldoc_build_syntax(const char *type, const char *name, const char *module)
Get the syntax for a specified application or function.
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the node content.
void unreference_cached_app(struct ast_app *app)
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
Standard Command Line Interface.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
ast_app: A registered application
const ast_string_field seealso
Handy terminal functions for vt* terms.
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Asterisk module definitions.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
struct ast_app * pbx_findapp(const char *app)
Look up an application.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
const ast_string_field arguments
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
int ast_unregister_application(const char *app)
Unregister an application.