Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
Data Structures | Functions | Variables
pbx_app.c File Reference

Custom function management routines. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/strings.h"
#include "asterisk/term.h"
#include "asterisk/utils.h"
#include "asterisk/xmldoc.h"
#include "pbx_private.h"
Include dependency graph for pbx_app.c:

Go to the source code of this file.

Data Structures

struct  apps
 Registered applications container. More...
 
struct  ast_app
 ast_app: A registered application More...
 

Functions

const char * app_name (struct ast_app *app)
 
char * ast_complete_applications (const char *line, const char *word, int state)
 Command completion for the list of installed applications.
 
int ast_pbx_exec_application (struct ast_channel *chan, const char *app_name, const char *app_args)
 Execute an application.
 
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.
 
int ast_unregister_application (const char *app)
 Unregister an application.
 
static char * handle_show_application (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 'show application' CLI command implementation function...
 
static char * handle_show_applications (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
int load_pbx_app (void)
 
int pbx_exec (struct ast_channel *c, struct ast_app *app, const char *data)
 Execute an application.
 
struct ast_apppbx_findapp (const char *app)
 Look up an application.
 
static struct ast_apppbx_findapp_nolock (const char *name)
 
static void print_app_docs (struct ast_app *aa, int fd)
 
static void unload_pbx_app (void)
 

Variables

static struct ast_cli_entry app_cli []
 
static struct apps apps = AST_RWLIST_HEAD_INIT_VALUE
 

Detailed Description

Custom function management routines.

Author
Corey Farrell git@c.nosp@m.fwar.nosp@m.e.com

Definition in file pbx_app.c.

Function Documentation

◆ app_name()

const char * app_name ( struct ast_app app)

pbx_app.c functions needed by pbx.c

Definition at line 475 of file pbx_app.c.

476{
477 return app->name;
478}
static const char app[]

References app.

Referenced by __stasis_app_register(), app_exec(), app_handle_subscriptions(), app_subscribe(), app_unsubscribe(), application_tuple_alloc(), ari_conf_get_owc_for_app(), ari_websocket_process_request(), ari_websocket_send_event(), ast_ari_callback(), ast_ari_close_per_call_websocket(), ast_ari_create_per_call_websocket(), ast_bridge_channel_queue_app(), ast_bridge_channel_run_app(), ast_bridge_channel_write_app(), ast_json_dialplan_cep_app(), ast_pbx_exec_application(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), bridge_stasis_run_cb(), device_state_subscription_create(), device_to_json_cb(), dynamic_dtmf_hook_add(), find_app_by_name(), handle_exec(), is_app_subscribed(), lua_pbx_exec(), lua_pbx_findapp(), messaging_app_subscribe_endpoint(), messaging_app_unsubscribe_endpoint(), payload_helper_app(), pbx_extension_helper(), run_app_helper(), send_rest_response(), session_find_by_app(), session_register_apps(), session_send_app_event(), session_send_or_queue(), session_unregister_app_cb(), stasis_app_control_move(), stasis_app_event_allowed(), stasis_app_exec(), stasis_app_get_debug_by_name(), stasis_app_message_handler(), stasis_app_register(), stasis_app_register_all(), stasis_app_send(), stasis_app_set_debug_by_name(), stasis_app_set_global_debug(), stasis_app_subscribe(), stasis_app_subscribe_channel(), stasis_app_to_json(), stasis_app_unregister(), stasis_app_unsubscribe(), and stasis_app_user_event().

◆ ast_complete_applications()

char * ast_complete_applications ( const char *  line,
const char *  word,
int  state 
)

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.

Definition at line 441 of file pbx_app.c.

442{
443 struct ast_app *app;
444 int which = 0;
445 int cmp;
446 char *ret = NULL;
447 size_t wordlen = strlen(word);
448
451 cmp = strncasecmp(word, app->name, wordlen);
452 if (cmp < 0) {
453 /* No more matches. */
454 break;
455 } else if (!cmp) {
456 /* Found match. */
457 if (state != -1) {
458 if (++which <= state) {
459 /* Not enough matches. */
460 continue;
461 }
462 ret = ast_strdup(app->name);
463 break;
464 }
466 break;
467 }
468 }
469 }
471
472 return ret;
473}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition main/cli.c:2845
short word
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_TRAVERSE
#define NULL
Definition resample.c:96
Registered applications container.
Definition pbx_app.c:69
ast_app: A registered application
Definition pbx_app.c:45
struct ast_app::@406 list

References app, ast_cli_completion_add(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_app::list, and NULL.

Referenced by handle_orig(), and handle_show_application().

◆ ast_pbx_exec_application()

int ast_pbx_exec_application ( struct ast_channel chan,
const char *  app_name,
const char *  app_args 
)

Execute an application.

Parameters
chanchannel to execute on
app_namename of app to execute
app_argsthe data passed into the app

This application executes an application by name on a given channel. It is a wrapper around pbx_exec that will perform variable substitution and then execute the application if it exists. If the application is not found, a warning is logged.

Return values
0success
-1failure (including application not found)

Definition at line 513 of file pbx_app.c.

514{
515 int res = -1;
516 struct ast_app *app;
517
519 if (!app) {
520 ast_log(LOG_WARNING, "Could not find application (%s)\n", app_name);
521 } else {
522 struct ast_str *substituted_args = NULL;
523
524 if (!ast_strlen_zero(app_args) && (substituted_args = ast_str_create(16))) {
525 ast_str_substitute_variables(&substituted_args, 0, chan, app_args);
526 res = pbx_exec(chan, app, ast_str_buffer(substituted_args));
527 ast_free(substituted_args);
528 } else {
529 if (!ast_strlen_zero(app_args)) {
530 ast_log(LOG_WARNING, "Could not substitute application argument variables for %s\n", app_name);
531 }
532 res = pbx_exec(chan, app, app_args);
533 }
534 /* Manually make a snapshot now, since pbx_exec won't necessarily get called again immediately. */
536 }
537 return res;
538}
#define ast_free(a)
Definition astmm.h:180
#define ast_log
Definition astobj2.c:42
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
#define LOG_WARNING
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * app_name(struct ast_app *app)
Definition pbx_app.c:475
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition pbx_app.c:483
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition pbx_app.c:93
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
Support for dynamic strings.
Definition strings.h:623

References app, app_name(), ast_channel_publish_snapshot(), ast_free, ast_log, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), ast_strlen_zero(), LOG_WARNING, NULL, pbx_exec(), and pbx_findapp().

Referenced by answer_exec_run(), conf_kick_all(), conf_run(), disa_exec(), dundi_exec(), pbx_builtin_execiftime(), run_app_helper(), and snoop_stasis_thread().

◆ ast_register_application2()

int ast_register_application2 ( const char *  app,
int(*)(struct ast_channel *, const char *)  execute,
const char *  synopsis,
const char *  description,
void *  mod 
)

Dynamically register a new dial plan application.

Register an application.

Definition at line 105 of file pbx_app.c.

106{
107 struct ast_app *tmp;
108 struct ast_app *cur;
109 int length;
110#ifdef AST_XML_DOCS
111 char *tmpxml;
112#endif
113
115 cur = pbx_findapp_nolock(app);
116 if (cur) {
117 ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
119 return -1;
120 }
121
122 length = sizeof(*tmp) + strlen(app) + 1;
123
124 if (!(tmp = ast_calloc(1, length))) {
126 return -1;
127 }
128
129 if (ast_string_field_init(tmp, 128)) {
131 ast_free(tmp);
132 return -1;
133 }
134
135 strcpy(tmp->name, app);
136 tmp->execute = execute;
137 tmp->module = mod;
138
139#ifdef AST_XML_DOCS
140 /* Try to lookup the docs in our XML documentation database */
142 /* load synopsis */
143 tmpxml = ast_xmldoc_build_synopsis("application", app, ast_module_name(tmp->module));
144 ast_string_field_set(tmp, synopsis, tmpxml);
145 ast_free(tmpxml);
146
147 /* load provied_by */
148 tmpxml = ast_xmldoc_build_provided_by("application", app, ast_module_name(tmp->module));
149 ast_string_field_set(tmp, provided_by, tmpxml);
150 ast_free(tmpxml);
151
152 /* load since */
153 tmpxml = ast_xmldoc_build_since("application", app, ast_module_name(tmp->module));
154 ast_string_field_set(tmp, since, tmpxml);
155 ast_free(tmpxml);
156
157 /* load description */
158 tmpxml = ast_xmldoc_build_description("application", app, ast_module_name(tmp->module));
159 ast_string_field_set(tmp, description, tmpxml);
160 ast_free(tmpxml);
161
162 /* load syntax */
163 tmpxml = ast_xmldoc_build_syntax("application", app, ast_module_name(tmp->module));
164 ast_string_field_set(tmp, syntax, tmpxml);
165 ast_free(tmpxml);
166
167 /* load arguments */
168 tmpxml = ast_xmldoc_build_arguments("application", app, ast_module_name(tmp->module));
169 ast_string_field_set(tmp, arguments, tmpxml);
170 ast_free(tmpxml);
171
172 /* load seealso */
173 tmpxml = ast_xmldoc_build_seealso("application", app, ast_module_name(tmp->module));
174 ast_string_field_set(tmp, seealso, tmpxml);
175 ast_free(tmpxml);
176 tmp->docsrc = AST_XML_DOC;
177 } else {
178#endif
181#ifdef AST_XML_DOCS
182 tmp->docsrc = AST_STATIC_DOC;
183 }
184#endif
185
186 /* Store in alphabetical order */
188 if (strcasecmp(tmp->name, cur->name) < 0) {
190 break;
191 }
192 }
194 if (!cur)
196
197 ast_verb(5, "Registered application '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, tmp->name));
198
200
201 return 0;
202}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
static char * synopsis
Definition func_enum.c:166
static SQLHSTMT execute(struct odbc_obj *obj, void *data, int silent)
Common execution function for SQL queries.
Definition func_odbc.c:485
#define ast_verb(level,...)
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_INSERT_TAIL
#define AST_RWLIST_INSERT_BEFORE_CURRENT
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
Definition loader.c:624
static struct ast_app * pbx_findapp_nolock(const char *name)
Definition pbx_app.c:71
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
const ast_string_field since
Definition pbx_app.c:55
const ast_string_field provided_by
Definition pbx_app.c:55
struct ast_module *char name[0]
Definition pbx_app.c:60
const ast_string_field description
Definition pbx_app.c:55
enum ast_doc_src docsrc
Definition pbx_app.c:57
const ast_string_field seealso
Definition pbx_app.c:55
const ast_string_field syntax
Definition pbx_app.c:55
const ast_string_field arguments
Definition pbx_app.c:55
int(* execute)(struct ast_channel *chan, const char *data)
Definition pbx_app.c:46
#define COLOR_BRCYAN
Definition term.h:63
#define COLORIZE(fg, bg, str)
Definition term.h:72
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition term.h:71
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
Definition xmldoc.c:2418
char * ast_xmldoc_build_syntax(const char *type, const char *name, const char *module)
Get the syntax for a specified application or function.
Definition xmldoc.c:1252
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.
Definition xmldoc.c:2231
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
Definition xmldoc.c:2395
char * ast_xmldoc_build_since(const char *type, const char *name, const char *module)
Parse the <since> node content.
Definition xmldoc.c:1792
@ AST_XML_DOC
Definition xmldoc.h:31
@ AST_STATIC_DOC
Definition xmldoc.h:32
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
Definition xmldoc.c:1707
char * ast_xmldoc_build_provided_by(const char *type, const char *name, const char *module)
Generate provided-by documentation from XML.
Definition xmldoc.c:1844

References app, ast_app::arguments, ast_calloc, ast_free, ast_log, ast_module_name(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_verb, AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_provided_by(), ast_xmldoc_build_seealso(), ast_xmldoc_build_since(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), COLOR_BRCYAN, COLORIZE, COLORIZE_FMT, ast_app::description, ast_app::docsrc, execute(), ast_app::execute, ast_app::list, LOG_WARNING, ast_app::name, pbx_findapp_nolock(), ast_app::provided_by, ast_app::seealso, ast_app::since, synopsis, and ast_app::syntax.

Referenced by ast_msg_init(), load_module(), load_module(), load_pbx_builtins(), and load_pbx_variables().

◆ ast_unregister_application()

int ast_unregister_application ( const char *  app)

Unregister an application.

Parameters
appname of the application (does not have to be the same string as the one that was registered)

This unregisters an application from Asterisk's internal application list.

Return values
0success
-1failure

Definition at line 404 of file pbx_app.c.

405{
406 struct ast_app *cur;
407 int cmp;
408
409 /* Anticipate need for conlock in unreference_cached_app(), in order to avoid
410 * possible deadlock with pbx_extension_helper()/pbx_findapp()
411 */
413
416 cmp = strcasecmp(app, cur->name);
417 if (cmp > 0) {
418 continue;
419 }
420 if (!cmp) {
421 /* Found it. */
424 ast_verb(5, "Unregistered application '%s'\n", cur->name);
426 ast_free(cur);
427 break;
428 }
429 /* Not in container. */
430 cur = NULL;
431 break;
432 }
435
437
438 return cur ? 0 : -1;
439}
#define AST_RWLIST_REMOVE_CURRENT
void unreference_cached_app(struct ast_app *app)
Definition pbx.c:6166
int ast_rdlock_contexts(void)
Read locks the context list.
Definition pbx.c:8512
int ast_unlock_contexts(void)
Unlocks contexts.
Definition pbx.c:8517
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object

References app, ast_free, ast_rdlock_contexts(), AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_unlock_contexts(), ast_verb, ast_app::list, ast_app::name, NULL, and unreference_cached_app().

Referenced by __unload_module(), __unload_module(), load_module(), load_module(), load_module(), load_module(), message_shutdown(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_parking_applications(), unload_pbx_builtins(), and unload_pbx_variables().

◆ handle_show_application()

static char * handle_show_application ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

'show application' CLI command implementation function...

Definition at line 272 of file pbx_app.c.

273{
274 struct ast_app *aa;
275 int app, no_registered_app = 1;
276
277 switch (cmd) {
278 case CLI_INIT:
279 e->command = "core show application";
280 e->usage =
281 "Usage: core show application <application> [<application> [<application> [...]]]\n"
282 " Describes a particular application.\n";
283 return NULL;
284 case CLI_GENERATE:
285 /*
286 * There is a possibility to show information about more than one
287 * application at one time. You can type 'show application Dial Echo' and
288 * you will see information about these two applications ...
289 */
290 return ast_complete_applications(a->line, a->word, -1);
291 }
292
293 if (a->argc < 4) {
294 return CLI_SHOWUSAGE;
295 }
296
299 /* Check for each app that was supplied as an argument */
300 for (app = 3; app < a->argc; app++) {
301 if (strcasecmp(aa->name, a->argv[app])) {
302 continue;
303 }
304
305 /* We found it! */
306 no_registered_app = 0;
307
308 print_app_docs(aa, a->fd);
309 }
310 }
312
313 /* we found at least one app? no? */
314 if (no_registered_app) {
315 ast_cli(a->fd, "Your application(s) is (are) not registered\n");
316 return CLI_FAILURE;
317 }
318
319 return CLI_SUCCESS;
320}
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
#define CLI_FAILURE
Definition cli.h:46
char * ast_complete_applications(const char *line, const char *word, int state)
Command completion for the list of installed applications.
Definition pbx_app.c:441
static void print_app_docs(struct ast_app *aa, int fd)
Definition pbx_app.c:204
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
static struct test_val a

References a, app, ast_cli(), ast_complete_applications(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_app::list, ast_app::name, NULL, print_app_docs(), and ast_cli_entry::usage.

◆ handle_show_applications()

static char * handle_show_applications ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 322 of file pbx_app.c.

323{
324 struct ast_app *aa;
325 int like = 0, describing = 0;
326 int total_match = 0; /* Number of matches in like clause */
327 int total_apps = 0; /* Number of apps registered */
328
329 switch (cmd) {
330 case CLI_INIT:
331 e->command = "core show applications [like|describing]";
332 e->usage =
333 "Usage: core show applications [{like|describing} <text>]\n"
334 " List applications which are currently available.\n"
335 " If 'like', <text> will be a substring of the app name\n"
336 " If 'describing', <text> will be a substring of the description\n";
337 return NULL;
338 case CLI_GENERATE:
339 return NULL;
340 }
341
343
344 if (AST_RWLIST_EMPTY(&apps)) {
345 ast_cli(a->fd, "There are no registered applications\n");
347 return CLI_SUCCESS;
348 }
349
350 /* core list applications like <keyword> */
351 if ((a->argc == 5) && (!strcmp(a->argv[3], "like"))) {
352 like = 1;
353 } else if ((a->argc > 4) && (!strcmp(a->argv[3], "describing"))) {
354 describing = 1;
355 }
356
357 /* core list applications describing <keyword1> [<keyword2>] [...] */
358 if ((!like) && (!describing)) {
359 ast_cli(a->fd, " -= Registered Asterisk Applications =-\n");
360 } else {
361 ast_cli(a->fd, " -= Matching Asterisk Applications =-\n");
362 }
363
365 int printapp = 0;
366 total_apps++;
367 if (like) {
368 if (strcasestr(aa->name, a->argv[4])) {
369 printapp = 1;
370 total_match++;
371 }
372 } else if (describing) {
373 if (aa->description) {
374 /* Match all words on command line */
375 int i;
376 printapp = 1;
377 for (i = 4; i < a->argc; i++) {
378 if (!strcasestr(aa->description, a->argv[i])) {
379 printapp = 0;
380 } else {
381 total_match++;
382 }
383 }
384 }
385 } else {
386 printapp = 1;
387 }
388
389 if (printapp) {
390 ast_cli(a->fd," %20s: %s\n", aa->name, aa->synopsis ? aa->synopsis : "<Synopsis not available>");
391 }
392 }
393 if ((!like) && (!describing)) {
394 ast_cli(a->fd, " -= %d Applications Registered =-\n",total_apps);
395 } else {
396 ast_cli(a->fd, " -= %d Applications Matching =-\n",total_match);
397 }
398
400
401 return CLI_SUCCESS;
402}
char * strcasestr(const char *, const char *)
#define AST_RWLIST_EMPTY
const ast_string_field synopsis
Definition pbx_app.c:55

References a, ast_cli(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_app::description, ast_app::list, ast_app::name, NULL, strcasestr(), ast_app::synopsis, and ast_cli_entry::usage.

◆ load_pbx_app()

int load_pbx_app ( void  )

Provided by pbx_app.c

Definition at line 550 of file pbx_app.c.

551{
554
555 return 0;
556}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
static struct ast_cli_entry app_cli[]
Definition pbx_app.c:540
static void unload_pbx_app(void)
Definition pbx_app.c:545
#define ARRAY_LEN(a)
Definition utils.h:706

References app_cli, ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), and unload_pbx_app().

Referenced by asterisk_daemon().

◆ pbx_exec()

int pbx_exec ( struct ast_channel c,
struct ast_app app,
const char *  data 
)

Execute an application.

Note
This function is special. It saves the stack so that no matter how many times it is called, it returns to the same place
Parameters
cChannel
appApplication
dataData for execution

Definition at line 483 of file pbx_app.c.

486{
487 int res;
488 struct ast_module_user *u = NULL;
489 const char *saved_c_appl;
490 const char *saved_c_data;
491
492 /* save channel values */
493 saved_c_appl= ast_channel_appl(c);
494 saved_c_data= ast_channel_data(c);
495
498 ast_channel_data_set(c, data);
501
502 if (app->module)
503 u = __ast_module_user_add(app->module, c);
504 res = app->execute(c, S_OR(data, ""));
505 if (app->module && u)
506 __ast_module_user_remove(app->module, u);
507 /* restore channel values */
508 ast_channel_appl_set(c, saved_c_appl);
509 ast_channel_data_set(c, saved_c_data);
510 return res;
511}
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
const char * ast_channel_data(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition channel.h:2982
void ast_channel_data_set(struct ast_channel *chan, const char *value)
const char * ast_channel_appl(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2983
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition loader.c:809
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition loader.c:835
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
const char * name
static struct test_val c

References __ast_module_user_add(), __ast_module_user_remove(), app, ast_channel_appl(), ast_channel_appl_set(), ast_channel_data(), ast_channel_data_set(), ast_channel_lock, ast_channel_publish_snapshot(), ast_channel_unlock, c, test_val::name, NULL, and S_OR.

Referenced by aelsub_exec(), ari_channel_thread(), ari_originate_dial(), ast_pbx_exec_application(), AST_TEST_DEFINE(), bridge_stasis_run_cb(), conf_run(), conf_start_record(), exec_exec(), execif_exec(), forward_message(), handle_exec(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_extension_helper(), pbx_outgoing_exec(), realtime_exec(), try_calling(), and tryexec_exec().

◆ pbx_findapp()

struct ast_app * pbx_findapp ( const char *  app)

Look up an application.

Parameters
appname of the app

This function searches for the ast_app structure within the apps that are registered for the one with the name you passed in.

Returns
the ast_app structure that matches on success, or NULL on failure

Definition at line 93 of file pbx_app.c.

94{
95 struct ast_app *ret;
96
100
101 return ret;
102}

References app, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and pbx_findapp_nolock().

Referenced by ast_pbx_exec_application().

◆ pbx_findapp_nolock()

static struct ast_app * pbx_findapp_nolock ( const char *  name)
static

Definition at line 71 of file pbx_app.c.

72{
73 struct ast_app *cur;
74 int cmp;
75
77 cmp = strcasecmp(name, cur->name);
78 if (cmp > 0) {
79 continue;
80 }
81 if (!cmp) {
82 /* Found it. */
83 break;
84 }
85 /* Not in container. */
86 cur = NULL;
87 break;
88 }
89
90 return cur;
91}
static const char name[]
Definition format_mp3.c:68

References AST_RWLIST_TRAVERSE, ast_app::list, ast_app::name, name, and NULL.

Referenced by ast_register_application2(), and pbx_findapp().

◆ print_app_docs()

static void print_app_docs ( struct ast_app aa,
int  fd 
)
static

Definition at line 204 of file pbx_app.c.

205{
206 char *synopsis = NULL, *provided_by = NULL, *since = NULL, *description = NULL, *syntax = NULL, *arguments = NULL, *seealso = NULL;
207
208#ifdef AST_XML_DOCS
209 if (aa->docsrc == AST_XML_DOC) {
210 synopsis = ast_xmldoc_printable(S_OR(aa->synopsis, "Not available"), 1);
211 provided_by = ast_xmldoc_printable(S_OR(aa->provided_by, "Not available"), 1);
212 since = ast_xmldoc_printable(S_OR(aa->since, "Not available"), 1);
213 description = ast_xmldoc_printable(S_OR(aa->description, "Not available"), 1);
214 syntax = ast_xmldoc_printable(S_OR(aa->syntax, "Not available"), 1);
215 arguments = ast_xmldoc_printable(S_OR(aa->arguments, "Not available"), 1);
216 seealso = ast_xmldoc_printable(S_OR(aa->seealso, "Not available"), 1);
217 } else
218#endif
219 {
220 synopsis = ast_strdup(S_OR(aa->synopsis, "Not Available"));
221 provided_by = ast_strdup(S_OR(aa->provided_by, "Not Available"));
222 since = ast_strdup(S_OR(aa->since, "Not Available"));
223 description = ast_strdup(S_OR(aa->description, "Not Available"));
224 syntax = ast_strdup(S_OR(aa->syntax, "Not Available"));
225 arguments = ast_strdup(S_OR(aa->arguments, "Not Available"));
226 seealso = ast_strdup(S_OR(aa->seealso, "Not Available"));
227 }
228 /* check allocated memory. */
229 if (!synopsis || !provided_by || !since || !description || !syntax || !arguments || !seealso) {
230 goto free_docs;
231 }
232
233 ast_cli(fd, "\n"
234 "%s -= Info about Application '%s' =- %s\n\n"
235 COLORIZE_FMT "\n"
236 "%s\n\n"
237 COLORIZE_FMT "\n"
238 "%s\n\n"
239 COLORIZE_FMT "\n"
240 "%s\n\n"
241 COLORIZE_FMT "\n"
242 "%s\n\n"
243 COLORIZE_FMT "\n"
244 "%s\n\n"
245 COLORIZE_FMT "\n"
246 "%s\n\n"
247 COLORIZE_FMT "\n"
248 "%s\n\n",
250 COLORIZE(COLOR_MAGENTA, 0, "[Synopsis]"), synopsis,
251 COLORIZE(COLOR_MAGENTA, 0, "[Provided By]"), provided_by,
252 COLORIZE(COLOR_MAGENTA, 0, "[Since]"), since,
253 COLORIZE(COLOR_MAGENTA, 0, "[Description]"), description,
254 COLORIZE(COLOR_MAGENTA, 0, "[Syntax]"), syntax,
255 COLORIZE(COLOR_MAGENTA, 0, "[Arguments]"), arguments,
256 COLORIZE(COLOR_MAGENTA, 0, "[See Also]"), seealso
257 );
258
259free_docs:
261 ast_free(provided_by);
262 ast_free(since);
263 ast_free(description);
264 ast_free(syntax);
265 ast_free(arguments);
266 ast_free(seealso);
267}
const char * ast_term_reset(void)
Returns the terminal reset code.
Definition term.c:357
#define COLOR_MAGENTA
Definition term.h:60
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
Definition term.c:341
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
Definition xmldoc.c:241

References ast_app::arguments, ast_cli(), ast_free, ast_strdup, ast_term_color(), ast_term_reset(), AST_XML_DOC, ast_xmldoc_printable(), COLOR_MAGENTA, COLORIZE, COLORIZE_FMT, ast_app::description, ast_app::docsrc, ast_app::name, NULL, ast_app::provided_by, S_OR, ast_app::seealso, ast_app::since, synopsis, ast_app::synopsis, and ast_app::syntax.

Referenced by handle_show_application().

◆ unload_pbx_app()

static void unload_pbx_app ( void  )
static

Definition at line 545 of file pbx_app.c.

546{
548}
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408

References app_cli, ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by load_pbx_app().

Variable Documentation

◆ app_cli

struct ast_cli_entry app_cli[]
static
Initial value:
= {
{ .handler = handle_show_applications , .summary = "Shows registered dialplan applications" ,},
{ .handler = handle_show_application , .summary = "Describe a specific dialplan application" ,},
}
static char * handle_show_application(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
'show application' CLI command implementation function...
Definition pbx_app.c:272
static char * handle_show_applications(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition pbx_app.c:322

Definition at line 540 of file pbx_app.c.

540 {
541 AST_CLI_DEFINE(handle_show_applications, "Shows registered dialplan applications"),
542 AST_CLI_DEFINE(handle_show_application, "Describe a specific dialplan application"),
543};
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197

Referenced by load_pbx_app(), and unload_pbx_app().

◆ apps