Asterisk - The Open Source Telephony Project GIT-master-8924258
Data Structures | Macros | Functions | Variables
pbx_builtins.c File Reference

Core PBX builtin routines. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/pbx.h"
#include "asterisk/causes.h"
#include "asterisk/indications.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/say.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/conversions.h"
#include "pbx_private.h"
Include dependency graph for pbx_builtins.c:

Go to the source code of this file.

Data Structures

struct  pbx_builtin
 Declaration of builtin applications. More...
 

Macros

#define BACKGROUND_MATCHEXTEN   (1 << 2)
 
#define BACKGROUND_NOANSWER   (1 << 1)
 
#define BACKGROUND_PLAYBACK   (1 << 3)
 
#define BACKGROUND_SKIP   (1 << 0)
 
#define WAITEXTEN_DIALTONE   (1 << 1)
 
#define WAITEXTEN_MOH   (1 << 0)
 

Functions

int indicate_busy (struct ast_channel *chan, const char *data)
 
int indicate_congestion (struct ast_channel *chan, const char *data)
 
int load_pbx_builtins (void)
 
static int pbx_builtin_answer (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_background (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_execiftime (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_goto (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_gotoif (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_gotoiftime (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_hangup (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_incomplete (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_noop (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_proceeding (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_progress (struct ast_channel *chan, const char *data)
 
int pbx_builtin_raise_exception (struct ast_channel *chan, const char *reason)
 
static int pbx_builtin_ringing (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_saycharacters (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_saycharacters_case (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_saydigits (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_saymoney (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_saynumber (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_sayordinal (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_sayphonetic (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_wait (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_waitdigit (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_waitexten (struct ast_channel *chan, const char *data)
 
static int permit_dtmf_interrupt (struct ast_channel *chan)
 Determine if DTMF interruption was requested. More...
 
static void unload_pbx_builtins (void)
 

Variables

static const struct ast_app_option background_opts [128] = { [ 's' ] = { .flag = (1 << 0) }, [ 'n' ] = { .flag = (1 << 1) }, [ 'm' ] = { .flag = (1 << 2) }, [ 'p' ] = { .flag = (1 << 3) }, }
 
struct pbx_builtin builtins []
 
static const struct ast_app_option waitexten_opts [128] = { [ 'm' ] = { .flag = (1 << 0) , .arg_index = 0 + 1 }, [ 'd' ] = { .flag = (1 << 1) , .arg_index = 0 + 1 }, }
 

Detailed Description

Core PBX builtin routines.

Author
George Joseph georg.nosp@m.e.jo.nosp@m.seph@.nosp@m.fair.nosp@m.view5.nosp@m..com

Definition in file pbx_builtins.c.

Macro Definition Documentation

◆ BACKGROUND_MATCHEXTEN

#define BACKGROUND_MATCHEXTEN   (1 << 2)

Definition at line 780 of file pbx_builtins.c.

◆ BACKGROUND_NOANSWER

#define BACKGROUND_NOANSWER   (1 << 1)

Definition at line 779 of file pbx_builtins.c.

◆ BACKGROUND_PLAYBACK

#define BACKGROUND_PLAYBACK   (1 << 3)

Definition at line 781 of file pbx_builtins.c.

◆ BACKGROUND_SKIP

#define BACKGROUND_SKIP   (1 << 0)

Definition at line 778 of file pbx_builtins.c.

◆ WAITEXTEN_DIALTONE

#define WAITEXTEN_DIALTONE   (1 << 1)

Definition at line 791 of file pbx_builtins.c.

◆ WAITEXTEN_MOH

#define WAITEXTEN_MOH   (1 << 0)

Definition at line 790 of file pbx_builtins.c.

Function Documentation

◆ load_pbx_builtins()

int load_pbx_builtins ( void  )

Provided by pbx_builtins.c

Definition at line 1583 of file pbx_builtins.c.

1584{
1585 int x;
1586
1587 /* Register builtin applications */
1588 for (x = 0; x < ARRAY_LEN(builtins); x++) {
1590 ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
1591 return -1;
1592 }
1593 }
1594
1596
1597 return 0;
1598}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define ast_log
Definition: astobj2.c:42
static const char name[]
Definition: format_mp3.c:68
static SQLHSTMT execute(struct odbc_obj *obj, void *data, int silent)
Common execution function for SQL queries.
Definition: func_odbc.c:485
#define LOG_ERROR
int ast_register_application2(const char *app, int(*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod)
Register an application.
Definition: pbx_app.c:104
struct pbx_builtin builtins[]
static void unload_pbx_builtins(void)
#define NULL
Definition: resample.c:96
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_log, ast_register_application2(), ast_register_cleanup(), builtins, execute(), LOG_ERROR, name, NULL, unload_pbx_builtins(), and ast_channel::x.

Referenced by asterisk_daemon().

◆ pbx_builtin_gotoif()

static int pbx_builtin_gotoif ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1322 of file pbx_builtins.c.

1323{
1324 char *condition, *branch1, *branch2, *branch;
1325 char *stringp;
1326
1327 if (ast_strlen_zero(data)) {
1328 ast_log(LOG_WARNING, "Ignoring, since there is no variable to check\n");
1329 return 0;
1330 }
1331
1332 stringp = ast_strdupa(data);
1333 condition = strsep(&stringp,"?");
1334 branch1 = strsep(&stringp,":");
1335 branch2 = strsep(&stringp,"");
1336 branch = pbx_checkcondition(condition) ? branch1 : branch2;
1337
1338 if (ast_strlen_zero(branch)) {
1339 ast_debug(1, "Not taking any branch\n");
1340 return 0;
1341 }
1342
1343 return pbx_builtin_goto(chan, branch);
1344}
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
static int pbx_builtin_goto(struct ast_channel *chan, const char *data)
Definition: pbx_builtins.c:961
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
int pbx_checkcondition(const char *condition)
Evaluate a condition.
Definition: pbx.c:8297
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_debug, ast_log, ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_builtin_goto(), pbx_checkcondition(), and strsep().

◆ pbx_builtin_incomplete()

static int pbx_builtin_incomplete ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 901 of file pbx_builtins.c.

902{
903 const char *options = data;
904 int answer = 1;
905
906 /* Some channels can receive DTMF in unanswered state; some cannot */
907 if (!ast_strlen_zero(options) && strchr(options, 'n')) {
908 answer = 0;
909 }
910
911 /* If the channel is hungup, stop waiting */
912 if (ast_check_hangup(chan)) {
913 return -1;
914 } else if (ast_channel_state(chan) != AST_STATE_UP && answer) {
915 __ast_answer(chan, 0);
916 }
917
919
920 return AST_PBX_INCOMPLETE;
921}
static int answer(void *data)
Definition: chan_pjsip.c:687
int __ast_answer(struct ast_channel *chan, unsigned int delay)
Answer a channel, with a selectable delay before returning.
Definition: channel.c:2724
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4294
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
@ AST_CONTROL_INCOMPLETE
#define AST_PBX_INCOMPLETE
Definition: pbx.h:51
static struct test_options options

References __ast_answer(), answer(), ast_check_hangup(), AST_CONTROL_INCOMPLETE, ast_indicate(), AST_PBX_INCOMPLETE, AST_STATE_UP, ast_strlen_zero(), and options.

◆ pbx_builtin_noop()

static int pbx_builtin_noop ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1317 of file pbx_builtins.c.

1318{
1319 return 0;
1320}

◆ pbx_builtin_raise_exception()

int pbx_builtin_raise_exception ( struct ast_channel chan,
const char *  reason 
)

Definition at line 798 of file pbx_builtins.c.

799{
800 /* Priority will become 1, next time through the AUTOLOOP */
801 return raise_exception(chan, reason, 0);
802}
int raise_exception(struct ast_channel *chan, const char *reason, int priority)
Definition: pbx.c:2821

References raise_exception().

◆ pbx_builtin_saycharacters()

static int pbx_builtin_saycharacters ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1515 of file pbx_builtins.c.

1516{
1517 int res = 0;
1518
1519 if (data) {
1521 }
1522
1523 return res;
1524}
const char * ast_channel_language(const struct ast_channel *chan)
#define AST_DIGIT_ANY
Definition: file.h:48
static int permit_dtmf_interrupt(struct ast_channel *chan)
Determine if DTMF interruption was requested.
int ast_say_character_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang, enum ast_say_case_sensitivity sensitivity)
function to pronounce character and phonetic strings
Definition: channel.c:8297
@ AST_SAY_CASE_NONE
Definition: say.h:182

References ast_channel_language(), AST_DIGIT_ANY, AST_SAY_CASE_NONE, ast_say_character_str(), and permit_dtmf_interrupt().

◆ pbx_builtin_saycharacters_case()

static int pbx_builtin_saycharacters_case ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1468 of file pbx_builtins.c.

1469{
1470 int res = 0;
1471 int sensitivity = 0;
1472 char *parse;
1473
1476 AST_APP_ARG(characters);
1477 );
1478
1479 if (ast_strlen_zero(data)) {
1480 ast_log(LOG_WARNING, "SayAlphaCase requires two arguments (options, characters)\n");
1481 return 0;
1482 }
1483
1484 parse = ast_strdupa(data);
1486
1487 if (!args.options || strlen(args.options) != 1) {
1488 ast_log(LOG_WARNING, "SayAlphaCase options are mutually exclusive and required\n");
1489 return 0;
1490 }
1491
1492 switch (args.options[0]) {
1493 case 'a':
1494 sensitivity = AST_SAY_CASE_ALL;
1495 break;
1496 case 'l':
1497 sensitivity = AST_SAY_CASE_LOWER;
1498 break;
1499 case 'n':
1500 sensitivity = AST_SAY_CASE_NONE;
1501 break;
1502 case 'u':
1503 sensitivity = AST_SAY_CASE_UPPER;
1504 break;
1505 default:
1506 ast_log(LOG_WARNING, "Invalid option: '%s'\n", args.options);
1507 return 0;
1508 }
1509
1510 res = ast_say_character_str(chan, args.characters, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan), sensitivity);
1511
1512 return res;
1513}
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
@ AST_SAY_CASE_LOWER
Definition: say.h:183
@ AST_SAY_CASE_ALL
Definition: say.h:185
@ AST_SAY_CASE_UPPER
Definition: say.h:184
const char * args

References args, AST_APP_ARG, ast_channel_language(), AST_DECLARE_APP_ARGS, AST_DIGIT_ANY, ast_log, AST_SAY_CASE_ALL, AST_SAY_CASE_LOWER, AST_SAY_CASE_NONE, AST_SAY_CASE_UPPER, ast_say_character_str(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), LOG_WARNING, options, and permit_dtmf_interrupt().

◆ pbx_builtin_saydigits()

static int pbx_builtin_saydigits ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1446 of file pbx_builtins.c.

1447{
1448 int res = 0;
1449
1450 if (data) {
1451 res = ast_say_digit_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
1452 }
1453
1454 return res;
1455}
int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
says digits of a string
Definition: channel.c:8285

References ast_channel_language(), AST_DIGIT_ANY, ast_say_digit_str(), and permit_dtmf_interrupt().

◆ pbx_builtin_saymoney()

static int pbx_builtin_saymoney ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1457 of file pbx_builtins.c.

1458{
1459 int res = 0;
1460
1461 if (data) {
1462 res = ast_say_money_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
1463 }
1464
1465 return res;
1466}
int ast_say_money_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
function to pronounce monetary amounts
Definition: channel.c:8291

References ast_channel_language(), AST_DIGIT_ANY, ast_say_money_str(), and permit_dtmf_interrupt().

◆ pbx_builtin_saynumber()

static int pbx_builtin_saynumber ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1368 of file pbx_builtins.c.

1369{
1370 char tmp[256];
1371 char *number = tmp;
1372 int number_val;
1373 char *options;
1374 int res;
1375 int interrupt = permit_dtmf_interrupt(chan);
1376
1377 if (ast_strlen_zero(data)) {
1378 ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
1379 return -1;
1380 }
1381 ast_copy_string(tmp, data, sizeof(tmp));
1382 strsep(&number, ",");
1383
1384 if (ast_str_to_int(tmp, &number_val)) {
1385 ast_log(LOG_WARNING, "argument '%s' to SayNumber could not be parsed as a number.\n", tmp);
1386 return 0;
1387 }
1388
1389 options = strsep(&number, ",");
1390 if (options) {
1391 if ( strcasecmp(options, "f") && strcasecmp(options, "m") &&
1392 strcasecmp(options, "c") && strcasecmp(options, "n") ) {
1393 ast_log(LOG_WARNING, "SayNumber gender option is either 'f', 'm', 'c' or 'n'\n");
1394 return -1;
1395 }
1396 }
1397
1398 res = ast_say_number(chan, number_val, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), options);
1399
1400 if (res < 0 && !ast_check_hangup_locked(chan)) {
1401 ast_log(LOG_WARNING, "We were unable to say the number %s, is it too large?\n", tmp);
1402 }
1403
1404 return interrupt ? res : 0;
1405}
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:459
int ast_str_to_int(const char *str, int *res)
Convert the given string to a signed integer.
Definition: conversions.c:44
int ast_say_number(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says a number
Definition: channel.c:8261
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Number structure.
Definition: app_followme.c:157

References ast_channel_language(), ast_check_hangup_locked(), ast_copy_string(), AST_DIGIT_ANY, ast_log, ast_say_number(), ast_str_to_int(), ast_strlen_zero(), LOG_WARNING, options, permit_dtmf_interrupt(), and strsep().

◆ pbx_builtin_sayordinal()

static int pbx_builtin_sayordinal ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1407 of file pbx_builtins.c.

1408{
1409 char tmp[256];
1410 char *number = tmp;
1411 int number_val;
1412 char *options;
1413 int res;
1414 int interrupt = permit_dtmf_interrupt(chan);
1415
1416 if (ast_strlen_zero(data)) {
1417 ast_log(LOG_WARNING, "SayOrdinal requires an argument (number)\n");
1418 return -1;
1419 }
1420 ast_copy_string(tmp, data, sizeof(tmp));
1421 strsep(&number, ",");
1422
1423 if (ast_str_to_int(tmp, &number_val)) {
1424 ast_log(LOG_WARNING, "argument '%s' to SayOrdinal could not be parsed as a number.\n", tmp);
1425 return 0;
1426 }
1427
1428 options = strsep(&number, ",");
1429 if (options) {
1430 if ( strcasecmp(options, "f") && strcasecmp(options, "m") &&
1431 strcasecmp(options, "c") && strcasecmp(options, "n") ) {
1432 ast_log(LOG_WARNING, "SayOrdinal gender option is either 'f', 'm', 'c' or 'n'\n");
1433 return -1;
1434 }
1435 }
1436
1437 res = ast_say_ordinal(chan, number_val, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), options);
1438
1439 if (res < 0 && !ast_check_hangup_locked(chan)) {
1440 ast_log(LOG_WARNING, "We were unable to say the number %s, is it too large?\n", tmp);
1441 }
1442
1443 return interrupt ? res : 0;
1444}
int ast_say_ordinal(struct ast_channel *chan, int num, const char *ints, const char *lang, const char *options)
says an ordinal number
Definition: channel.c:8267

References ast_channel_language(), ast_check_hangup_locked(), ast_copy_string(), AST_DIGIT_ANY, ast_log, ast_say_ordinal(), ast_str_to_int(), ast_strlen_zero(), LOG_WARNING, options, permit_dtmf_interrupt(), and strsep().

◆ pbx_builtin_sayphonetic()

static int pbx_builtin_sayphonetic ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 1526 of file pbx_builtins.c.

1527{
1528 int res = 0;
1529
1530 if (data) {
1532 }
1533
1534 return res;
1535}
int ast_say_phonetic_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
Definition: channel.c:8303

References ast_channel_language(), AST_DIGIT_ANY, ast_say_phonetic_str(), and permit_dtmf_interrupt().

◆ permit_dtmf_interrupt()

static int permit_dtmf_interrupt ( struct ast_channel chan)
static

Determine if DTMF interruption was requested.

If the SAY_DTMF_INTERRUPT channel variable is truthy, the caller has requested DTMF interruption be enabled.

Parameters
chanthe channel to examine
Return values
-1if DTMF interruption was requested
0if DTMF interruption was not requested

Definition at line 1357 of file pbx_builtins.c.

1358{
1359 int interrupt;
1360
1361 ast_channel_lock(chan);
1362 interrupt = ast_true(pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT"));
1363 ast_channel_unlock(chan);
1364
1365 return interrupt;
1366}
#define ast_channel_lock(chan)
Definition: channel.h:2970
#define ast_channel_unlock(chan)
Definition: channel.h:2971
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199

References ast_channel_lock, ast_channel_unlock, ast_true(), and pbx_builtin_getvar_helper().

Referenced by pbx_builtin_saycharacters(), pbx_builtin_saycharacters_case(), pbx_builtin_saydigits(), pbx_builtin_saymoney(), pbx_builtin_saynumber(), pbx_builtin_sayordinal(), and pbx_builtin_sayphonetic().

◆ unload_pbx_builtins()

static void unload_pbx_builtins ( void  )
static

Definition at line 1573 of file pbx_builtins.c.

1574{
1575 int x;
1576
1577 /* Unregister builtin applications */
1578 for (x = 0; x < ARRAY_LEN(builtins); x++) {
1580 }
1581}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References ARRAY_LEN, ast_unregister_application(), builtins, name, and ast_channel::x.

Referenced by load_pbx_builtins().

Variable Documentation

◆ background_opts

const struct ast_app_option background_opts[128] = { [ 's' ] = { .flag = (1 << 0) }, [ 'n' ] = { .flag = (1 << 1) }, [ 'm' ] = { .flag = (1 << 2) }, [ 'p' ] = { .flag = (1 << 3) }, }
static

Definition at line 788 of file pbx_builtins.c.

Referenced by pbx_builtin_background().

◆ builtins

struct pbx_builtin builtins[]

◆ waitexten_opts

const struct ast_app_option waitexten_opts[128] = { [ 'm' ] = { .flag = (1 << 0) , .arg_index = 0 + 1 }, [ 'd' ] = { .flag = (1 << 1) , .arg_index = 0 + 1 }, }
static

Definition at line 796 of file pbx_builtins.c.

Referenced by pbx_builtin_waitexten().