Asterisk - The Open Source Telephony Project  18.5.0
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. More...
 
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. More...
 
int ast_unregister_application (const char *app)
 Unregister an application. More...
 
static char * handle_show_application (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
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. More...
 
struct ast_apppbx_findapp (const char *app)
 Look up an application. More...
 
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 = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 

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)

◆ 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 429 of file pbx_app.c.

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

Referenced by handle_orig(), and handle_show_application().

430 {
431  struct ast_app *app;
432  int which = 0;
433  int cmp;
434  char *ret = NULL;
435  size_t wordlen = strlen(word);
436 
438  AST_RWLIST_TRAVERSE(&apps, app, list) {
439  cmp = strncasecmp(word, app->name, wordlen);
440  if (cmp < 0) {
441  /* No more matches. */
442  break;
443  } else if (!cmp) {
444  /* Found match. */
445  if (state != -1) {
446  if (++which <= state) {
447  /* Not enough matches. */
448  continue;
449  }
450  ret = ast_strdup(app->name);
451  break;
452  }
453  if (ast_cli_completion_add(ast_strdup(app->name))) {
454  break;
455  }
456  }
457  }
459 
460  return ret;
461 }
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
ast_app: A registered application
Definition: pbx_app.c:45
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2726
static const char app[]
Definition: app_mysql.c:62
short word

◆ 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 103 of file pbx_app.c.

References 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_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), COLOR_BRCYAN, COLORIZE, COLORIZE_FMT, ast_app::docsrc, ast_app::execute, LOG_WARNING, pbx_findapp_nolock(), ast_app::seealso, ast_app::syntax, and tmp().

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

104 {
105  struct ast_app *tmp;
106  struct ast_app *cur;
107  int length;
108 #ifdef AST_XML_DOCS
109  char *tmpxml;
110 #endif
111 
113  cur = pbx_findapp_nolock(app);
114  if (cur) {
115  ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
117  return -1;
118  }
119 
120  length = sizeof(*tmp) + strlen(app) + 1;
121 
122  if (!(tmp = ast_calloc(1, length))) {
124  return -1;
125  }
126 
127  if (ast_string_field_init(tmp, 128)) {
129  ast_free(tmp);
130  return -1;
131  }
132 
133  strcpy(tmp->name, app);
134  tmp->execute = execute;
135  tmp->module = mod;
136 
137 #ifdef AST_XML_DOCS
138  /* Try to lookup the docs in our XML documentation database */
140  /* load synopsis */
141  tmpxml = ast_xmldoc_build_synopsis("application", app, ast_module_name(tmp->module));
142  ast_string_field_set(tmp, synopsis, tmpxml);
143  ast_free(tmpxml);
144 
145  /* load description */
146  tmpxml = ast_xmldoc_build_description("application", app, ast_module_name(tmp->module));
147  ast_string_field_set(tmp, description, tmpxml);
148  ast_free(tmpxml);
149 
150  /* load syntax */
151  tmpxml = ast_xmldoc_build_syntax("application", app, ast_module_name(tmp->module));
152  ast_string_field_set(tmp, syntax, tmpxml);
153  ast_free(tmpxml);
154 
155  /* load arguments */
156  tmpxml = ast_xmldoc_build_arguments("application", app, ast_module_name(tmp->module));
157  ast_string_field_set(tmp, arguments, tmpxml);
158  ast_free(tmpxml);
159 
160  /* load seealso */
161  tmpxml = ast_xmldoc_build_seealso("application", app, ast_module_name(tmp->module));
162  ast_string_field_set(tmp, seealso, tmpxml);
163  ast_free(tmpxml);
164  tmp->docsrc = AST_XML_DOC;
165  } else {
166 #endif
169 #ifdef AST_XML_DOCS
170  tmp->docsrc = AST_STATIC_DOC;
171  }
172 #endif
173 
174  /* Store in alphabetical order */
175  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
176  if (strcasecmp(tmp->name, cur->name) < 0) {
178  break;
179  }
180  }
182  if (!cur)
183  AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
184 
185  ast_verb(2, "Registered application '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, tmp->name));
186 
188 
189  return 0;
190 }
static const char synopsis[]
Definition: app_mysql.c:64
int(* execute)(struct ast_channel *chan, const char *data)
Definition: pbx_app.c:46
static SQLHSTMT execute(struct odbc_obj *obj, void *data, int silent)
Common execution function for SQL queries.
Definition: func_odbc.c:454
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
Definition: xmldoc.c:2250
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
Definition: xmldoc.c:2227
char * ast_xmldoc_build_arguments(const char *type, const char *name, const char *module)
Generate the [arguments] tag based on type of node (&#39;application&#39;, &#39;function&#39; or &#39;agi&#39;) and name...
Definition: xmldoc.c:2075
#define ast_verb(level,...)
Definition: logger.h:463
#define COLOR_BRCYAN
Definition: term.h:60
#define COLORIZE(fg, bg, str)
Definition: term.h:68
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition: term.h:67
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:609
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
const ast_string_field syntax
Definition: pbx_app.c:53
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
enum ast_doc_src docsrc
Definition: pbx_app.c:55
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:1253
char * ast_xmldoc_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
Definition: xmldoc.c:1698
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
const char * ast_module_name(const struct ast_module *mod)
Get the name of a module.
Definition: loader.c:615
ast_app: A registered application
Definition: pbx_app.c:45
const ast_string_field seealso
Definition: pbx_app.c:53
static struct ast_app * pbx_findapp_nolock(const char *name)
Definition: pbx_app.c:69
static const char app[]
Definition: app_mysql.c:62
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616
const ast_string_field arguments
Definition: pbx_app.c:53
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514
const ast_string_field description
Definition: pbx_app.c:53

◆ 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 392 of file pbx_app.c.

References 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, NULL, and unreference_cached_app().

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

393 {
394  struct ast_app *cur;
395  int cmp;
396 
397  /* Anticipate need for conlock in unreference_cached_app(), in order to avoid
398  * possible deadlock with pbx_extension_helper()/pbx_findapp()
399  */
401 
403  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
404  cmp = strcasecmp(app, cur->name);
405  if (cmp > 0) {
406  continue;
407  }
408  if (!cmp) {
409  /* Found it. */
412  ast_verb(2, "Unregistered application '%s'\n", cur->name);
414  ast_free(cur);
415  break;
416  }
417  /* Not in container. */
418  cur = NULL;
419  break;
420  }
423 
425 
426  return cur ? 0 : -1;
427 }
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:8507
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:463
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:569
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
#define ast_free(a)
Definition: astmm.h:182
void unreference_cached_app(struct ast_app *app)
Definition: pbx.c:6179
ast_app: A registered application
Definition: pbx_app.c:45
static const char app[]
Definition: app_mysql.c:62
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ handle_show_application()

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

Definition at line 260 of file pbx_app.c.

References app, ast_cli_args::argc, ast_cli_args::argv, 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_cli_args::fd, ast_cli_args::line, NULL, print_app_docs(), ast_cli_entry::usage, and ast_cli_args::word.

261 {
262  struct ast_app *aa;
263  int app, no_registered_app = 1;
264 
265  switch (cmd) {
266  case CLI_INIT:
267  e->command = "core show application";
268  e->usage =
269  "Usage: core show application <application> [<application> [<application> [...]]]\n"
270  " Describes a particular application.\n";
271  return NULL;
272  case CLI_GENERATE:
273  /*
274  * There is a possibility to show informations about more than one
275  * application at one time. You can type 'show application Dial Echo' and
276  * you will see informations about these two applications ...
277  */
278  return ast_complete_applications(a->line, a->word, -1);
279  }
280 
281  if (a->argc < 4) {
282  return CLI_SHOWUSAGE;
283  }
284 
286  AST_RWLIST_TRAVERSE(&apps, aa, list) {
287  /* Check for each app that was supplied as an argument */
288  for (app = 3; app < a->argc; app++) {
289  if (strcasecmp(aa->name, a->argv[app])) {
290  continue;
291  }
292 
293  /* We found it! */
294  no_registered_app = 0;
295 
296  print_app_docs(aa, a->fd);
297  }
298  }
300 
301  /* we found at least one app? no? */
302  if (no_registered_app) {
303  ast_cli(a->fd, "Your application(s) is (are) not registered\n");
304  return CLI_FAILURE;
305  }
306 
307  return CLI_SUCCESS;
308 }
Registered applications container.
Definition: pbx_app.c:67
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const char * line
Definition: cli.h:162
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
char * ast_complete_applications(const char *line, const char *word, int state)
Command completion for the list of installed applications.
Definition: pbx_app.c:429
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
ast_app: A registered application
Definition: pbx_app.c:45
static void print_app_docs(struct ast_app *aa, int fd)
Definition: pbx_app.c:192
static const char app[]
Definition: app_mysql.c:62

◆ handle_show_applications()

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

Definition at line 310 of file pbx_app.c.

References ast_cli_args::argc, ast_cli_args::argv, 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_cli_args::fd, NULL, strcasestr(), ast_app::synopsis, and ast_cli_entry::usage.

311 {
312  struct ast_app *aa;
313  int like = 0, describing = 0;
314  int total_match = 0; /* Number of matches in like clause */
315  int total_apps = 0; /* Number of apps registered */
316 
317  switch (cmd) {
318  case CLI_INIT:
319  e->command = "core show applications [like|describing]";
320  e->usage =
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";
325  return NULL;
326  case CLI_GENERATE:
327  return NULL;
328  }
329 
331 
332  if (AST_RWLIST_EMPTY(&apps)) {
333  ast_cli(a->fd, "There are no registered applications\n");
335  return CLI_SUCCESS;
336  }
337 
338  /* core list applications like <keyword> */
339  if ((a->argc == 5) && (!strcmp(a->argv[3], "like"))) {
340  like = 1;
341  } else if ((a->argc > 4) && (!strcmp(a->argv[3], "describing"))) {
342  describing = 1;
343  }
344 
345  /* core list applications describing <keyword1> [<keyword2>] [...] */
346  if ((!like) && (!describing)) {
347  ast_cli(a->fd, " -= Registered Asterisk Applications =-\n");
348  } else {
349  ast_cli(a->fd, " -= Matching Asterisk Applications =-\n");
350  }
351 
352  AST_RWLIST_TRAVERSE(&apps, aa, list) {
353  int printapp = 0;
354  total_apps++;
355  if (like) {
356  if (strcasestr(aa->name, a->argv[4])) {
357  printapp = 1;
358  total_match++;
359  }
360  } else if (describing) {
361  if (aa->description) {
362  /* Match all words on command line */
363  int i;
364  printapp = 1;
365  for (i = 4; i < a->argc; i++) {
366  if (!strcasestr(aa->description, a->argv[i])) {
367  printapp = 0;
368  } else {
369  total_match++;
370  }
371  }
372  }
373  } else {
374  printapp = 1;
375  }
376 
377  if (printapp) {
378  ast_cli(a->fd," %20s: %s\n", aa->name, aa->synopsis ? aa->synopsis : "<Synopsis not available>");
379  }
380  }
381  if ((!like) && (!describing)) {
382  ast_cli(a->fd, " -= %d Applications Registered =-\n",total_apps);
383  } else {
384  ast_cli(a->fd, " -= %d Applications Matching =-\n",total_match);
385  }
386 
388 
389  return CLI_SUCCESS;
390 }
Registered applications container.
Definition: pbx_app.c:67
const int argc
Definition: cli.h:160
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
const ast_string_field synopsis
Definition: pbx_app.c:53
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
const char *const * argv
Definition: cli.h:161
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
char * strcasestr(const char *, const char *)
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
ast_app: A registered application
Definition: pbx_app.c:45
const ast_string_field description
Definition: pbx_app.c:53

◆ load_pbx_app()

int load_pbx_app ( void  )

Provided by pbx_app.c

Definition at line 511 of file pbx_app.c.

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

Referenced by asterisk_daemon().

512 {
515 
516  return 0;
517 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#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:501
static void unload_pbx_app(void)
Definition: pbx_app.c:506
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19

◆ pbx_exec()

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

Execute an application.

Parameters
cchannel to execute on
appwhich app to execute
datathe data passed into the app

This application executes an application on a given channel. It saves the stack and executes the given application passing in the given data.

Return values
0success
-1failure
Parameters
cChannel
appApplication
dataData for execution

Definition at line 471 of file pbx_app.c.

References __ast_module_user_add(), __ast_module_user_remove(), ast_channel_appl(), ast_channel_appl_set(), ast_channel_data(), ast_channel_data_set(), ast_channel_lock, ast_channel_publish_snapshot(), ast_channel_unlock, ast_app::execute, NULL, and S_OR.

Referenced by aelsub_exec(), answer_exec_run(), ari_channel_thread(), ari_originate_dial(), ast_app_exec_macro(), AST_TEST_DEFINE(), bridge_check_monitor(), bridge_stasis_run_cb(), conf_run(), conf_start_record(), disa_exec(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), forward_message(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), pbx_outgoing_exec(), realtime_exec(), run_app_helper(), snoop_stasis_thread(), try_calling(), and tryexec_exec().

474 {
475  int res;
476  struct ast_module_user *u = NULL;
477  const char *saved_c_appl;
478  const char *saved_c_data;
479 
480  /* save channel values */
481  saved_c_appl= ast_channel_appl(c);
482  saved_c_data= ast_channel_data(c);
483 
484  ast_channel_lock(c);
485  ast_channel_appl_set(c, app->name);
486  ast_channel_data_set(c, data);
489 
490  if (app->module)
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);
495  /* restore channel values */
496  ast_channel_appl_set(c, saved_c_appl);
497  ast_channel_data_set(c, saved_c_data);
498  return res;
499 }
int(* execute)(struct ast_channel *chan, const char *data)
Definition: pbx_app.c:46
#define ast_channel_lock(chan)
Definition: channel.h:2945
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:826
#define NULL
Definition: resample.c:96
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:800
const char * ast_channel_appl(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * ast_channel_data(const struct ast_channel *chan)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_channel_data_set(struct ast_channel *chan, const char *value)

◆ 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 91 of file pbx_app.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and pbx_findapp_nolock().

92 {
93  struct ast_app *ret;
94 
96  ret = pbx_findapp_nolock(app);
98 
99  return ret;
100 }
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
ast_app: A registered application
Definition: pbx_app.c:45
static struct ast_app * pbx_findapp_nolock(const char *name)
Definition: pbx_app.c:69
static const char app[]
Definition: app_mysql.c:62

◆ pbx_findapp_nolock()

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

Definition at line 69 of file pbx_app.c.

References AST_RWLIST_TRAVERSE, and NULL.

Referenced by ast_register_application2(), and pbx_findapp().

70 {
71  struct ast_app *cur;
72  int cmp;
73 
74  AST_RWLIST_TRAVERSE(&apps, cur, list) {
75  cmp = strcasecmp(name, cur->name);
76  if (cmp > 0) {
77  continue;
78  }
79  if (!cmp) {
80  /* Found it. */
81  break;
82  }
83  /* Not in container. */
84  cur = NULL;
85  break;
86  }
87 
88  return cur;
89 }
Registered applications container.
Definition: pbx_app.c:67
#define NULL
Definition: resample.c:96
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static const char name[]
Definition: cdr_mysql.c:74
ast_app: A registered application
Definition: pbx_app.c:45

◆ print_app_docs()

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

Definition at line 192 of file pbx_app.c.

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

Referenced by handle_show_application().

193 {
194 #ifdef AST_XML_DOCS
195  char *synopsis = NULL, *description = NULL, *arguments = NULL, *seealso = NULL;
196  if (aa->docsrc == AST_XML_DOC) {
197  synopsis = ast_xmldoc_printable(S_OR(aa->synopsis, "Not available"), 1);
198  description = ast_xmldoc_printable(S_OR(aa->description, "Not available"), 1);
199  arguments = ast_xmldoc_printable(S_OR(aa->arguments, "Not available"), 1);
200  seealso = ast_xmldoc_printable(S_OR(aa->seealso, "Not available"), 1);
201  if (!synopsis || !description || !arguments || !seealso) {
202  goto free_docs;
203  }
204  ast_cli(fd, "\n"
205  "%s -= Info about application '%s' =- %s\n\n"
206  COLORIZE_FMT "\n"
207  "%s\n\n"
208  COLORIZE_FMT "\n"
209  "%s\n\n"
210  COLORIZE_FMT "\n"
211  "%s%s%s\n\n"
212  COLORIZE_FMT "\n"
213  "%s\n\n"
214  COLORIZE_FMT "\n"
215  "%s\n",
217  COLORIZE(COLOR_MAGENTA, 0, "[Synopsis]"), synopsis,
218  COLORIZE(COLOR_MAGENTA, 0, "[Description]"), description,
219  COLORIZE(COLOR_MAGENTA, 0, "[Syntax]"),
220  ast_term_color(COLOR_CYAN, 0), S_OR(aa->syntax, "Not available"), ast_term_reset(),
221  COLORIZE(COLOR_MAGENTA, 0, "[Arguments]"), arguments,
222  COLORIZE(COLOR_MAGENTA, 0, "[See Also]"), seealso);
223 free_docs:
224  ast_free(synopsis);
225  ast_free(description);
226  ast_free(arguments);
227  ast_free(seealso);
228  } else
229 #endif
230  {
231  ast_cli(fd, "\n"
232  "%s -= Info about application '%s' =- %s\n\n"
233  COLORIZE_FMT "\n"
234  COLORIZE_FMT "\n\n"
235  COLORIZE_FMT "\n"
236  COLORIZE_FMT "\n\n"
237  COLORIZE_FMT "\n"
238  COLORIZE_FMT "\n\n"
239  COLORIZE_FMT "\n"
240  COLORIZE_FMT "\n\n"
241  COLORIZE_FMT "\n"
242  COLORIZE_FMT "\n",
244  COLORIZE(COLOR_MAGENTA, 0, "[Synopsis]"),
245  COLORIZE(COLOR_CYAN, 0, S_OR(aa->synopsis, "Not available")),
246  COLORIZE(COLOR_MAGENTA, 0, "[Description]"),
247  COLORIZE(COLOR_CYAN, 0, S_OR(aa->description, "Not available")),
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")));
254  }
255 }
static const char synopsis[]
Definition: app_mysql.c:64
#define COLOR_CYAN
Definition: term.h:59
const ast_string_field synopsis
Definition: pbx_app.c:53
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define COLORIZE(fg, bg, str)
Definition: term.h:68
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition: term.h:67
const ast_string_field syntax
Definition: pbx_app.c:53
#define ast_free(a)
Definition: astmm.h:182
enum ast_doc_src docsrc
Definition: pbx_app.c:55
const char * ast_term_reset(void)
Returns the terminal reset code.
Definition: term.c:306
const char * ast_term_color(int fgcolor, int bgcolor)
Return a color sequence string.
Definition: term.c:290
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
Definition: xmldoc.c:242
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
const ast_string_field seealso
Definition: pbx_app.c:53
#define COLOR_MAGENTA
Definition: term.h:57
const ast_string_field arguments
Definition: pbx_app.c:53
const ast_string_field description
Definition: pbx_app.c:53

◆ unload_pbx_app()

static void unload_pbx_app ( void  )
static

Definition at line 506 of file pbx_app.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by load_pbx_app().

507 {
509 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry app_cli[]
Definition: pbx_app.c:501

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)
Definition: pbx_app.c:260
static char * handle_show_applications(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pbx_app.c:310

Definition at line 501 of file pbx_app.c.

◆ apps

struct apps apps = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static