Asterisk - The Open Source Telephony Project GIT-master-a358458
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 703 of file pbx_builtins.c.

◆ BACKGROUND_NOANSWER

#define BACKGROUND_NOANSWER   (1 << 1)

Definition at line 702 of file pbx_builtins.c.

◆ BACKGROUND_PLAYBACK

#define BACKGROUND_PLAYBACK   (1 << 3)

Definition at line 704 of file pbx_builtins.c.

◆ BACKGROUND_SKIP

#define BACKGROUND_SKIP   (1 << 0)

Definition at line 701 of file pbx_builtins.c.

◆ WAITEXTEN_DIALTONE

#define WAITEXTEN_DIALTONE   (1 << 1)

Definition at line 714 of file pbx_builtins.c.

◆ WAITEXTEN_MOH

#define WAITEXTEN_MOH   (1 << 0)

Definition at line 713 of file pbx_builtins.c.

Function Documentation

◆ load_pbx_builtins()

int load_pbx_builtins ( void  )

Provided by pbx_builtins.c

Definition at line 1506 of file pbx_builtins.c.

1507{
1508 int x;
1509
1510 /* Register builtin applications */
1511 for (x = 0; x < ARRAY_LEN(builtins); x++) {
1513 ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
1514 return -1;
1515 }
1516 }
1517
1519
1520 return 0;
1521}
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:471
#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:103
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 1245 of file pbx_builtins.c.

1246{
1247 char *condition, *branch1, *branch2, *branch;
1248 char *stringp;
1249
1250 if (ast_strlen_zero(data)) {
1251 ast_log(LOG_WARNING, "Ignoring, since there is no variable to check\n");
1252 return 0;
1253 }
1254
1255 stringp = ast_strdupa(data);
1256 condition = strsep(&stringp,"?");
1257 branch1 = strsep(&stringp,":");
1258 branch2 = strsep(&stringp,"");
1259 branch = pbx_checkcondition(condition) ? branch1 : branch2;
1260
1261 if (ast_strlen_zero(branch)) {
1262 ast_debug(1, "Not taking any branch\n");
1263 return 0;
1264 }
1265
1266 return pbx_builtin_goto(chan, branch);
1267}
#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:884
char * strsep(char **str, const char *delims)
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
int pbx_checkcondition(const char *condition)
Evaluate a condition.
Definition: pbx.c:8282
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 824 of file pbx_builtins.c.

825{
826 const char *options = data;
827 int answer = 1;
828
829 /* Some channels can receive DTMF in unanswered state; some cannot */
830 if (!ast_strlen_zero(options) && strchr(options, 'n')) {
831 answer = 0;
832 }
833
834 /* If the channel is hungup, stop waiting */
835 if (ast_check_hangup(chan)) {
836 return -1;
837 } else if (ast_channel_state(chan) != AST_STATE_UP && answer) {
838 __ast_answer(chan, 0);
839 }
840
842
843 return AST_PBX_INCOMPLETE;
844}
static int answer(void *data)
Definition: chan_pjsip.c:683
int __ast_answer(struct ast_channel *chan, unsigned int delay)
Answer a channel, with a selectable delay before returning.
Definition: channel.c:2695
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:4277
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 1240 of file pbx_builtins.c.

1241{
1242 return 0;
1243}

◆ pbx_builtin_raise_exception()

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

Definition at line 721 of file pbx_builtins.c.

722{
723 /* Priority will become 1, next time through the AUTOLOOP */
724 return raise_exception(chan, reason, 0);
725}
int raise_exception(struct ast_channel *chan, const char *reason, int priority)
Definition: pbx.c:2806

References raise_exception().

◆ pbx_builtin_saycharacters()

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

Definition at line 1438 of file pbx_builtins.c.

1439{
1440 int res = 0;
1441
1442 if (data) {
1444 }
1445
1446 return res;
1447}
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:8271
@ 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 1391 of file pbx_builtins.c.

1392{
1393 int res = 0;
1394 int sensitivity = 0;
1395 char *parse;
1396
1399 AST_APP_ARG(characters);
1400 );
1401
1402 if (ast_strlen_zero(data)) {
1403 ast_log(LOG_WARNING, "SayAlphaCase requires two arguments (options, characters)\n");
1404 return 0;
1405 }
1406
1407 parse = ast_strdupa(data);
1409
1410 if (!args.options || strlen(args.options) != 1) {
1411 ast_log(LOG_WARNING, "SayAlphaCase options are mutually exclusive and required\n");
1412 return 0;
1413 }
1414
1415 switch (args.options[0]) {
1416 case 'a':
1417 sensitivity = AST_SAY_CASE_ALL;
1418 break;
1419 case 'l':
1420 sensitivity = AST_SAY_CASE_LOWER;
1421 break;
1422 case 'n':
1423 sensitivity = AST_SAY_CASE_NONE;
1424 break;
1425 case 'u':
1426 sensitivity = AST_SAY_CASE_UPPER;
1427 break;
1428 default:
1429 ast_log(LOG_WARNING, "Invalid option: '%s'\n", args.options);
1430 return 0;
1431 }
1432
1433 res = ast_say_character_str(chan, args.characters, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan), sensitivity);
1434
1435 return res;
1436}
#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 1369 of file pbx_builtins.c.

1370{
1371 int res = 0;
1372
1373 if (data) {
1374 res = ast_say_digit_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
1375 }
1376
1377 return res;
1378}
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:8259

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 1380 of file pbx_builtins.c.

1381{
1382 int res = 0;
1383
1384 if (data) {
1385 res = ast_say_money_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
1386 }
1387
1388 return res;
1389}
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:8265

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 1291 of file pbx_builtins.c.

1292{
1293 char tmp[256];
1294 char *number = tmp;
1295 int number_val;
1296 char *options;
1297 int res;
1298 int interrupt = permit_dtmf_interrupt(chan);
1299
1300 if (ast_strlen_zero(data)) {
1301 ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
1302 return -1;
1303 }
1304 ast_copy_string(tmp, data, sizeof(tmp));
1305 strsep(&number, ",");
1306
1307 if (ast_str_to_int(tmp, &number_val)) {
1308 ast_log(LOG_WARNING, "argument '%s' to SayNumber could not be parsed as a number.\n", tmp);
1309 return 0;
1310 }
1311
1312 options = strsep(&number, ",");
1313 if (options) {
1314 if ( strcasecmp(options, "f") && strcasecmp(options, "m") &&
1315 strcasecmp(options, "c") && strcasecmp(options, "n") ) {
1316 ast_log(LOG_WARNING, "SayNumber gender option is either 'f', 'm', 'c' or 'n'\n");
1317 return -1;
1318 }
1319 }
1320
1321 res = ast_say_number(chan, number_val, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), options);
1322
1323 if (res < 0 && !ast_check_hangup_locked(chan)) {
1324 ast_log(LOG_WARNING, "We were unable to say the number %s, is it too large?\n", tmp);
1325 }
1326
1327 return interrupt ? res : 0;
1328}
static int tmp()
Definition: bt_open.c:389
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:8235
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:154

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(), strsep(), and tmp().

◆ pbx_builtin_sayordinal()

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

Definition at line 1330 of file pbx_builtins.c.

1331{
1332 char tmp[256];
1333 char *number = tmp;
1334 int number_val;
1335 char *options;
1336 int res;
1337 int interrupt = permit_dtmf_interrupt(chan);
1338
1339 if (ast_strlen_zero(data)) {
1340 ast_log(LOG_WARNING, "SayOrdinal requires an argument (number)\n");
1341 return -1;
1342 }
1343 ast_copy_string(tmp, data, sizeof(tmp));
1344 strsep(&number, ",");
1345
1346 if (ast_str_to_int(tmp, &number_val)) {
1347 ast_log(LOG_WARNING, "argument '%s' to SayOrdinal could not be parsed as a number.\n", tmp);
1348 return 0;
1349 }
1350
1351 options = strsep(&number, ",");
1352 if (options) {
1353 if ( strcasecmp(options, "f") && strcasecmp(options, "m") &&
1354 strcasecmp(options, "c") && strcasecmp(options, "n") ) {
1355 ast_log(LOG_WARNING, "SayOrdinal gender option is either 'f', 'm', 'c' or 'n'\n");
1356 return -1;
1357 }
1358 }
1359
1360 res = ast_say_ordinal(chan, number_val, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), options);
1361
1362 if (res < 0 && !ast_check_hangup_locked(chan)) {
1363 ast_log(LOG_WARNING, "We were unable to say the number %s, is it too large?\n", tmp);
1364 }
1365
1366 return interrupt ? res : 0;
1367}
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:8241

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(), strsep(), and tmp().

◆ pbx_builtin_sayphonetic()

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

Definition at line 1449 of file pbx_builtins.c.

1450{
1451 int res = 0;
1452
1453 if (data) {
1455 }
1456
1457 return res;
1458}
int ast_say_phonetic_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
Definition: channel.c:8277

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 1280 of file pbx_builtins.c.

1281{
1282 int interrupt;
1283
1284 ast_channel_lock(chan);
1285 interrupt = ast_true(pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT"));
1286 ast_channel_unlock(chan);
1287
1288 return interrupt;
1289}
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_unlock(chan)
Definition: channel.h:2923
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 1496 of file pbx_builtins.c.

1497{
1498 int x;
1499
1500 /* Unregister builtin applications */
1501 for (x = 0; x < ARRAY_LEN(builtins); x++) {
1503 }
1504}
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 711 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 719 of file pbx_builtins.c.

Referenced by pbx_builtin_waitexten().