Wed Jan 8 2020 09:50:23

Asterisk developer's documentation


Module: Dial plan applications

Applications support the dialplan. They register dynamically with. More...

Files

file  app_adsiprog.c
 Program Asterisk ADSI Scripts into phone.
 
file  app_alarmreceiver.c
 Central Station Alarm receiver for Ademco Contact ID.
 
file  app_authenticate.c
 Execute arbitrary authenticate commands.
 
file  app_cdr.c
 Applications connected with CDR engine.
 
file  app_celgenuserevent.c
 Generate User-Defined CEL event.
 
file  app_chanisavail.c
 Check if Channel is Available.
 
file  app_channelredirect.c
 ChannelRedirect application.
 
file  app_chanspy.c
 ChanSpy: Listen in on any channel.
 
file  app_confbridge.c
 Conference Bridge application.
 
file  app_controlplayback.c
 Trivial application to control playback of a sound file.
 
file  app_dahdibarge.c
 DAHDI Barge support.
 
file  app_dahdiras.c
 Execute an ISDN RAS.
 
file  app_db.c
 Database access functions.
 
file  app_dial.c
 dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
 
file  app_dictate.c
 Virtual Dictation Machine Application For Asterisk.
 
file  app_directed_pickup.c
 Directed Call Pickup Support.
 
file  app_directory.c
 Provide a directory of extensions.
 
file  app_disa.c
 DISA – Direct Inward System Access Application.
 
file  app_dumpchan.c
 Application to dump channel variables.
 
file  app_echo.c
 Echo application – play back what you hear to evaluate latency.
 
file  app_exec.c
 Exec application.
 
file  app_externalivr.c
 External IVR application interface.
 
file  app_festival.c
 Connect to festival.
 
file  app_flash.c
 App to flash a DAHDI trunk.
 
file  app_followme.c
 Find-Me Follow-Me application.
 
file  app_forkcdr.c
 Fork CDR application.
 
file  app_getcpeid.c
 Get ADSI CPE ID.
 
file  app_ices.c
 Stream to an icecast server via ICES (see contrib/asterisk-ices.xml)
 
file  app_image.c
 App to transmit an image.
 
file  app_ivrdemo.c
 IVR Demo application.
 
file  app_jack.c
 Jack Application.
 
file  app_macro.c
 Dial plan macro Implementation.
 
file  app_meetme.c
 Meet me conference bridge and Shared Line Appearances.
 
file  app_milliwatt.c
 Digital Milliwatt Test.
 
file  app_minivm.c
 MiniVoiceMail - A Minimal Voicemail System for Asterisk.
 
file  app_mixmonitor.c
 MixMonitor() - Record a call and mix the audio during the recording.
 
file  app_morsecode.c
 Morsecode application.
 
file  app_mp3.c
 Silly application to play an MP3 file – uses mpg123.
 
file  app_nbscat.c
 Silly application to play an NBScat file – uses nbscat8k.
 
file  app_originate.c
 Originate application.
 
file  app_osplookup.c
 Open Settlement Protocol (OSP) Applications.
 
file  app_page.c
 page() - Paging application
 
file  app_parkandannounce.c
 ParkAndAnnounce application for Asterisk.
 
file  app_playback.c
 Trivial application to playback a sound file.
 
file  app_playtones.c
 Playtones application.
 
file  app_privacy.c
 Block all calls without Caller*ID, require phone # to be entered.
 
file  app_queue.c
 True call queues with optional send URL on answer.
 
file  app_read.c
 Trivial application to read a variable.
 
file  app_readexten.c
 Trivial application to read an extension into a variable.
 
file  app_readfile.c
 ReadFile application – Reads in a File for you.
 
file  app_record.c
 Trivial application to record a sound file.
 
file  app_saycounted.c
 Applications to decline words according to current language.
 
file  app_sayunixtime.c
 SayUnixTime application.
 
file  app_senddtmf.c
 App to send DTMF digits.
 
file  app_sendtext.c
 App to transmit a text message.
 
file  app_setcallerid.c
 App to set callerid presentation.
 
file  app_skel.c
 Skeleton application.
 
file  app_sms.c
 SMS application - ETSI ES 201 912 protocol 1 implementation.
 
file  app_softhangup.c
 SoftHangup application.
 
file  app_speech_utils.c
 Speech Recognition Utility Applications.
 
file  app_stack.c
 Stack applications Gosub, Return, etc.
 
file  app_system.c
 Execute arbitrary system commands.
 
file  app_talkdetect.c
 Playback a file with audio detect.
 
file  app_test.c
 Applications to test connection and produce report in text file.
 
file  app_transfer.c
 Transfer a caller.
 
file  app_url.c
 App to transmit a URL.
 
file  app_userevent.c
 UserEvent application – send manager event.
 
file  app_verbose.c
 Verbose logging application.
 
file  app_voicemail.c
 Comedian Mail - Voicemail System.
 
file  app_voicemail_imapstorage.c
 Comedian Mail - Voicemail System.
 
file  app_voicemail_odbcstorage.c
 Comedian Mail - Voicemail System.
 
file  app_waitforring.c
 Wait for Ring Application.
 
file  app_waitforsilence.c
 Wait for Silence.
 
file  app_waituntil.c
 Sleep until the given epoch.
 
file  app_while.c
 While Loop Implementation.
 
file  app_zapateller.c
 Playback the special information tone to get rid of telemarketers.
 
 
file  res_fax.c
 Generic FAX Resource for FAX technology resource modules.
 
file  res_realtime.c
 RealTime CLI.
 

Functions

static int iax2_prov_app (struct ast_channel *chan, const char *data)
 
static int pbx_builtin_answer (struct ast_channel *, const char *)
 
static int pbx_builtin_background (struct ast_channel *, const char *)
 
static int pbx_builtin_busy (struct ast_channel *, const char *)
 
static int pbx_builtin_congestion (struct ast_channel *, const char *)
 
static int pbx_builtin_execiftime (struct ast_channel *, const char *)
 
static int pbx_builtin_goto (struct ast_channel *, const char *)
 
static int pbx_builtin_gotoiftime (struct ast_channel *, const char *)
 
static int pbx_builtin_hangup (struct ast_channel *, const char *)
 
static int pbx_builtin_proceeding (struct ast_channel *, const char *)
 
static int pbx_builtin_progress (struct ast_channel *, const char *)
 
static int pbx_builtin_resetcdr (struct ast_channel *, const char *)
 
static int pbx_builtin_ringing (struct ast_channel *, const char *)
 
static int pbx_builtin_setamaflags (struct ast_channel *, const char *)
 
static int pbx_builtin_wait (struct ast_channel *, const char *)
 
static int pbx_builtin_waitexten (struct ast_channel *, const char *)
 

Detailed Description

Applications support the dialplan. They register dynamically with.

Asterisk Dial Plan Applications

See Also
ast_register_application() and unregister with
ast_unregister_application()
See also

Function Documentation

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

iax2provision

Definition at line 12137 of file chan_iax2.c.

References iax2_trunk_peer::addr, ast_inet_ntoa(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_verb, iax2_provision(), LOG_NOTICE, PTR_TO_CALLNO, iax2_trunk_peer::sockfd, ast_channel::tech, and ast_channel::tech_pvt.

Referenced by load_module().

12138 {
12139  int res;
12140  char *sdata;
12141  char *opts;
12142  int force =0;
12143  unsigned short callno = PTR_TO_CALLNO(chan->tech_pvt);
12144  if (ast_strlen_zero(data))
12145  data = "default";
12146  sdata = ast_strdupa(data);
12147  opts = strchr(sdata, '|');
12148  if (opts)
12149  *opts='\0';
12150 
12151  if (chan->tech != &iax2_tech) {
12152  ast_log(LOG_NOTICE, "Can't provision a non-IAX device!\n");
12153  return -1;
12154  }
12155  if (!callno || !iaxs[callno] || !iaxs[callno]->addr.sin_addr.s_addr) {
12156  ast_log(LOG_NOTICE, "Can't provision something with no IP?\n");
12157  return -1;
12158  }
12159  res = iax2_provision(&iaxs[callno]->addr, iaxs[callno]->sockfd, NULL, sdata, force);
12160  ast_verb(3, "Provisioned IAXY at '%s' with '%s'= %d\n",
12161  ast_inet_ntoa(iaxs[callno]->addr.sin_addr),
12162  sdata, res);
12163  return res;
12164 }
void * tech_pvt
Definition: channel.h:744
#define ast_verb(level,...)
Definition: logger.h:243
#define PTR_TO_CALLNO(a)
Definition: chan_iax2.c:242
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int iax2_provision(struct sockaddr_in *end, int sockfd, const char *dest, const char *template, int force)
Definition: chan_iax2.c:12085
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct chan_iax2_pvt * iaxs[IAX_MAX_CALLS]
an array of iax2 pvt structures
Definition: chan_iax2.c:1067
static struct ast_channel_tech iax2_tech
Definition: chan_iax2.c:1216
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:564
struct ast_channel_tech * tech
Definition: channel.h:743
static int pbx_builtin_answer ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 9964 of file pbx.c.

References __ast_answer(), ast_channel::_state, args, AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_strdupa, ast_strlen_zero(), and parse().

9965 {
9966  int delay = 0;
9967  int answer_cdr = 1;
9968  char *parse;
9970  AST_APP_ARG(delay);
9971  AST_APP_ARG(answer_cdr);
9972  );
9973 
9974  if (ast_strlen_zero(data)) {
9975  return __ast_answer(chan, 0, 1);
9976  }
9977 
9978  parse = ast_strdupa(data);
9979 
9980  AST_STANDARD_APP_ARGS(args, parse);
9981 
9982  if (!ast_strlen_zero(args.delay) && (chan->_state != AST_STATE_UP))
9983  delay = atoi(data);
9984 
9985  if (delay < 0) {
9986  delay = 0;
9987  }
9988 
9989  if (!ast_strlen_zero(args.answer_cdr) && !strcasecmp(args.answer_cdr, "nocdr")) {
9990  answer_cdr = 0;
9991  }
9992 
9993  return __ast_answer(chan, delay, answer_cdr);
9994 }
int __ast_answer(struct ast_channel *chan, unsigned int delay, int cdr_answer)
Answer a channel, with a selectable delay before returning.
Definition: channel.c:2982
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
enum ast_channel_state _state
Definition: channel.h:839
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static int pbx_builtin_background ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10320 of file pbx.c.

References ast_channel::_state, args, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_canmatch_extension(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, AST_DIGIT_ANY, AST_FLAG_DISABLE_WORKAROUNDS, ast_log(), ast_matchmore_extension(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strip(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), ast_waitstream_exten(), BACKGROUND_MATCHEXTEN, BACKGROUND_NOANSWER, background_opts, BACKGROUND_PLAYBACK, BACKGROUND_SKIP, ast_channel::caller, context, ast_channel::context, ast_channel::exten, ast_flags::flags, ast_party_caller::id, if(), ast_channel::language, LOG_WARNING, ast_channel::name, ast_party_id::number, parse(), pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), ast_channel::priority, S_COR, ast_party_number::str, strsep(), and ast_party_number::valid.

10321 {
10322  int res = 0;
10323  int mres = 0;
10324  struct ast_flags flags = {0};
10325  char *parse, exten[2] = "";
10327  AST_APP_ARG(filename);
10328  AST_APP_ARG(options);
10329  AST_APP_ARG(lang);
10331  );
10332 
10333  if (ast_strlen_zero(data)) {
10334  ast_log(LOG_WARNING, "Background requires an argument (filename)\n");
10335  return -1;
10336  }
10337 
10338  parse = ast_strdupa(data);
10339 
10340  AST_STANDARD_APP_ARGS(args, parse);
10341 
10342  if (ast_strlen_zero(args.lang))
10343  args.lang = (char *)chan->language; /* XXX this is const */
10344 
10345  if (ast_strlen_zero(args.context)) {
10346  const char *context;
10347  ast_channel_lock(chan);
10348  if ((context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"))) {
10349  args.context = ast_strdupa(context);
10350  } else {
10351  args.context = chan->context;
10352  }
10353  ast_channel_unlock(chan);
10354  }
10355 
10356  if (args.options) {
10357  if (!strcasecmp(args.options, "skip"))
10358  flags.flags = BACKGROUND_SKIP;
10359  else if (!strcasecmp(args.options, "noanswer"))
10360  flags.flags = BACKGROUND_NOANSWER;
10361  else
10362  ast_app_parse_options(background_opts, &flags, NULL, args.options);
10363  }
10364 
10365  /* Answer if need be */
10366  if (chan->_state != AST_STATE_UP) {
10367  if (ast_test_flag(&flags, BACKGROUND_SKIP)) {
10368  goto done;
10369  } else if (!ast_test_flag(&flags, BACKGROUND_NOANSWER)) {
10370  res = ast_answer(chan);
10371  }
10372  }
10373 
10374  if (!res) {
10375  char *back = ast_strip(args.filename);
10376  char *front;
10377 
10378  ast_stopstream(chan); /* Stop anything playing */
10379  /* Stream the list of files */
10380  while (!res && (front = strsep(&back, "&")) ) {
10381  if ( (res = ast_streamfile(chan, front, args.lang)) ) {
10382  ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char*)data);
10383  res = 0;
10384  mres = 1;
10385  break;
10386  }
10387  if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) {
10388  res = ast_waitstream(chan, "");
10389  } else if (ast_test_flag(&flags, BACKGROUND_MATCHEXTEN)) {
10390  res = ast_waitstream_exten(chan, args.context);
10391  } else {
10392  res = ast_waitstream(chan, AST_DIGIT_ANY);
10393  }
10394  ast_stopstream(chan);
10395  }
10396  }
10397 
10398  /*
10399  * If the single digit DTMF is an extension in the specified context, then
10400  * go there and signal no DTMF. Otherwise, we should exit with that DTMF.
10401  * If we're in Macro, we'll exit and seek that DTMF as the beginning of an
10402  * extension in the Macro's calling context. If we're not in Macro, then
10403  * we'll simply seek that extension in the calling context. Previously,
10404  * someone complained about the behavior as it related to the interior of a
10405  * Gosub routine, and the fix (#14011) inadvertently broke FreePBX
10406  * (#14940). This change should fix both of these situations, but with the
10407  * possible incompatibility that if a single digit extension does not exist
10408  * (but a longer extension COULD have matched), it would have previously
10409  * gone immediately to the "i" extension, but will now need to wait for a
10410  * timeout.
10411  *
10412  * Later, we had to add a flag to disable this workaround, because AGI
10413  * users can EXEC Background and reasonably expect that the DTMF code will
10414  * be returned (see #16434).
10415  */
10417  && (exten[0] = res)
10418  && ast_canmatch_extension(chan, args.context, exten, 1,
10419  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))
10420  && !ast_matchmore_extension(chan, args.context, exten, 1,
10421  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
10422  snprintf(chan->exten, sizeof(chan->exten), "%c", res);
10423  ast_copy_string(chan->context, args.context, sizeof(chan->context));
10424  chan->priority = 0;
10425  res = 0;
10426  }
10427 done:
10428  pbx_builtin_setvar_helper(chan, "BACKGROUNDSTATUS", mres ? "FAILED" : "SUCCESS");
10429  return res;
10430 }
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch) ...
Definition: pbx.c:5420
#define ast_channel_lock(chan)
Definition: channel.h:2466
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
char * strsep(char **str, const char *delims)
int priority
Definition: channel.h:841
#define AST_DIGIT_ANY
Definition: file.h:47
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define BACKGROUND_NOANSWER
Definition: pbx.c:840
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define LOG_WARNING
Definition: logger.h:144
#define BACKGROUND_PLAYBACK
Definition: pbx.c:842
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
unsigned int flags
Definition: utils.h:201
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
Definition: pbx.c:5415
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Definition: pbx.c:10475
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
#define BACKGROUND_SKIP
Definition: pbx.c:839
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:83
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
if(yyss+yystacksize-1<=yyssp)
Definition: ast_expr2.c:1874
Structure used to handle boolean flags.
Definition: utils.h:200
#define BACKGROUND_MATCHEXTEN
Definition: pbx.c:841
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1343
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
static struct ast_app_option background_opts[128]
Definition: pbx.c:849
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
const ast_string_field language
Definition: channel.h:787
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
int ast_waitstream_exten(struct ast_channel *c, const char *context)
Waits for a stream to stop or digit matching a valid one digit exten to be pressed.
Definition: file.c:1354
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static int pbx_builtin_busy ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 9934 of file pbx.c.

References ast_channel::_state, ast_cdr_busy(), AST_CONTROL_BUSY, ast_indicate(), ast_setstate(), AST_STATE_BUSY, AST_STATE_UP, ast_channel::cdr, and wait_for_hangup().

Referenced by __ast_pbx_run().

9935 {
9937  /* Don't change state of an UP channel, just indicate
9938  busy in audio */
9939  if (chan->_state != AST_STATE_UP) {
9941  ast_cdr_busy(chan->cdr);
9942  }
9943  wait_for_hangup(chan, data);
9944  return -1;
9945 }
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
struct ast_cdr * cdr
Definition: channel.h:766
static void wait_for_hangup(struct ast_channel *chan, const void *data)
Definition: pbx.c:9882
enum ast_channel_state _state
Definition: channel.h:839
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
void ast_cdr_busy(struct ast_cdr *cdr)
Busy a call.
Definition: cdr.c:753
static int pbx_builtin_congestion ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 9950 of file pbx.c.

References ast_channel::_state, AST_CONTROL_CONGESTION, ast_indicate(), ast_setstate(), AST_STATE_BUSY, AST_STATE_UP, and wait_for_hangup().

Referenced by __ast_pbx_run().

9951 {
9953  /* Don't change state of an UP channel, just indicate
9954  congestion in audio */
9955  if (chan->_state != AST_STATE_UP)
9957  wait_for_hangup(chan, data);
9958  return -1;
9959 }
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
static void wait_for_hangup(struct ast_channel *chan, const void *data)
Definition: pbx.c:9882
enum ast_channel_state _state
Definition: channel.h:839
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
static int pbx_builtin_execiftime ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10176 of file pbx.c.

References app, ast_build_timing(), ast_check_timing(), ast_destroy_timing(), ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_exec(), pbx_findapp(), S_OR, and strsep().

10177 {
10178  char *s, *appname;
10179  struct ast_timing timing;
10180  struct ast_app *app;
10181  static const char * const usage = "ExecIfTime requires an argument:\n <time range>,<days of week>,<days of month>,<months>[,<timezone>]?<appname>[(<appargs>)]";
10182 
10183  if (ast_strlen_zero(data)) {
10184  ast_log(LOG_WARNING, "%s\n", usage);
10185  return -1;
10186  }
10187 
10188  appname = ast_strdupa(data);
10189 
10190  s = strsep(&appname, "?"); /* Separate the timerange and application name/data */
10191  if (!appname) { /* missing application */
10192  ast_log(LOG_WARNING, "%s\n", usage);
10193  return -1;
10194  }
10195 
10196  if (!ast_build_timing(&timing, s)) {
10197  ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", s, usage);
10198  ast_destroy_timing(&timing);
10199  return -1;
10200  }
10201 
10202  if (!ast_check_timing(&timing)) { /* outside the valid time window, just return */
10203  ast_destroy_timing(&timing);
10204  return 0;
10205  }
10206  ast_destroy_timing(&timing);
10207 
10208  /* now split appname(appargs) */
10209  if ((s = strchr(appname, '('))) {
10210  char *e;
10211  *s++ = '\0';
10212  if ((e = strrchr(s, ')')))
10213  *e = '\0';
10214  else
10215  ast_log(LOG_WARNING, "Failed to find closing parenthesis\n");
10216  }
10217 
10218 
10219  if ((app = pbx_findapp(appname))) {
10220  return pbx_exec(chan, app, S_OR(s, ""));
10221  } else {
10222  ast_log(LOG_WARNING, "Cannot locate application %s\n", appname);
10223  return -1;
10224  }
10225 }
char * strsep(char **str, const char *delims)
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: pbx.c:1537
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx.c:1497
#define LOG_WARNING
Definition: logger.h:144
static const char app[]
Definition: app_adsiprog.c:49
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
int ast_check_timing(const struct ast_timing *i)
Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified...
Definition: pbx.c:8357
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_destroy_timing(struct ast_timing *i)
Deallocates memory structures associated with a timing bitmap.
Definition: pbx.c:8396
int ast_build_timing(struct ast_timing *i, const char *info)
Construct a timing bitmap, for use in time-based conditionals.
Definition: pbx.c:8314
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
ast_app: A registered application
Definition: pbx.c:971
static int pbx_builtin_goto ( struct ast_channel chan,
const char *  data 
)
static

Goto

Definition at line 10435 of file pbx.c.

References ast_parseable_goto(), ast_verb, ast_channel::context, ast_channel::exten, and ast_channel::priority.

Referenced by pbx_builtin_gotoif(), and pbx_builtin_gotoiftime().

10436 {
10437  int res = ast_parseable_goto(chan, data);
10438  if (!res)
10439  ast_verb(3, "Goto (%s,%s,%d)\n", chan->context, chan->exten, chan->priority + 1);
10440  return res;
10441 }
int priority
Definition: channel.h:841
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define ast_verb(level,...)
Definition: logger.h:243
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:11326
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
static int pbx_builtin_gotoiftime ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10122 of file pbx.c.

References ast_build_timing(), ast_channel_lock, ast_channel_unlock, ast_check_timing2(), ast_debug, ast_destroy_timing(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_tvnow(), LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_goto(), pbx_builtin_setvar_helper(), and strsep().

10123 {
10124  char *s, *ts, *branch1, *branch2, *branch;
10125  struct ast_timing timing;
10126  const char *ctime;
10127  struct timeval tv = ast_tvnow();
10128  long timesecs;
10129 
10130  if (!chan) {
10131  ast_log(LOG_WARNING, "GotoIfTime requires a channel on which to operate\n");
10132  return -1;
10133  }
10134 
10135  if (ast_strlen_zero(data)) {
10136  ast_log(LOG_WARNING, "GotoIfTime requires an argument:\n <time range>,<days of week>,<days of month>,<months>[,<timezone>]?'labeliftrue':'labeliffalse'\n");
10137  return -1;
10138  }
10139 
10140  ts = s = ast_strdupa(data);
10141 
10142  ast_channel_lock(chan);
10143  if ((ctime = pbx_builtin_getvar_helper(chan, "TESTTIME")) && sscanf(ctime, "%ld", &timesecs) == 1) {
10144  tv.tv_sec = timesecs;
10145  } else if (ctime) {
10146  ast_log(LOG_WARNING, "Using current time to evaluate\n");
10147  /* Reset when unparseable */
10148  pbx_builtin_setvar_helper(chan, "TESTTIME", NULL);
10149  }
10150  ast_channel_unlock(chan);
10151 
10152  /* Separate the Goto path */
10153  strsep(&ts, "?");
10154  branch1 = strsep(&ts,":");
10155  branch2 = strsep(&ts,"");
10156 
10157  /* struct ast_include include contained garbage here, fixed by zeroing it on get_timerange */
10158  if (ast_build_timing(&timing, s) && ast_check_timing2(&timing, tv)) {
10159  branch = branch1;
10160  } else {
10161  branch = branch2;
10162  }
10163  ast_destroy_timing(&timing);
10164 
10165  if (ast_strlen_zero(branch)) {
10166  ast_debug(1, "Not taking any branch\n");
10167  return 0;
10168  }
10169 
10170  return pbx_builtin_goto(chan, branch);
10171 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
int ast_check_timing2(const struct ast_timing *i, const struct timeval tv)
Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified...
Definition: pbx.c:8362
char * strsep(char **str, const char *delims)
#define LOG_WARNING
Definition: logger.h:144
static int pbx_builtin_goto(struct ast_channel *, const char *)
Definition: pbx.c:10435
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Definition: pbx.c:10475
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_destroy_timing(struct ast_timing *i)
Deallocates memory structures associated with a timing bitmap.
Definition: pbx.c:8396
#define ast_channel_unlock(chan)
Definition: channel.h:2467
int ast_build_timing(struct ast_timing *i, const char *info)
Construct a timing bitmap, for use in time-based conditionals.
Definition: pbx.c:8314
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
struct timeval tv
static int pbx_builtin_hangup ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10058 of file pbx.c.

References AST_CAUSE_NORMAL_CLEARING, ast_log(), ast_set_hangupsource(), ast_str2cause(), ast_strlen_zero(), ast_channel::hangupcause, and LOG_WARNING.

10059 {
10060  ast_set_hangupsource(chan, "dialplan/builtin", 0);
10061 
10062  if (!ast_strlen_zero(data)) {
10063  int cause;
10064  char *endptr;
10065 
10066  if ((cause = ast_str2cause(data)) > -1) {
10067  chan->hangupcause = cause;
10068  return -1;
10069  }
10070 
10071  cause = strtol((const char *) data, &endptr, 10);
10072  if (cause != 0 || (data != endptr)) {
10073  chan->hangupcause = cause;
10074  return -1;
10075  }
10076 
10077  ast_log(LOG_WARNING, "Invalid cause given to Hangup(): \"%s\"\n", (char *) data);
10078  }
10079 
10080  if (!chan->hangupcause) {
10082  }
10083 
10084  return -1;
10085 }
#define LOG_WARNING
Definition: logger.h:144
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it&#39;s bridge.
Definition: channel.c:2769
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int hangupcause
Definition: channel.h:849
int ast_str2cause(const char *name) attribute_pure
Convert the string form of a cause code to a number.
Definition: channel.c:993
static int pbx_builtin_proceeding ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 9907 of file pbx.c.

References AST_CONTROL_PROCEEDING, and ast_indicate().

9908 {
9910  return 0;
9911 }
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
static int pbx_builtin_progress ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 9916 of file pbx.c.

References AST_CONTROL_PROGRESS, and ast_indicate().

9917 {
9919  return 0;
9920 }
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
static int pbx_builtin_resetcdr ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10028 of file pbx.c.

References args, ast_app_parse_options(), ast_cdr_reset(), ast_strdupa, ast_strlen_zero(), ast_channel::cdr, and resetcdr_opts.

10029 {
10030  char *args;
10031  struct ast_flags flags = { 0 };
10032 
10033  if (!ast_strlen_zero(data)) {
10034  args = ast_strdupa(data);
10035  ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
10036  }
10037 
10038  ast_cdr_reset(chan->cdr, &flags);
10039 
10040  return 0;
10041 }
void ast_cdr_reset(struct ast_cdr *cdr, struct ast_flags *flags)
Reset the detail record, optionally posting it first.
Definition: cdr.c:1149
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
unsigned int flags
Definition: utils.h:201
struct ast_cdr * cdr
Definition: channel.h:766
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
Structure used to handle boolean flags.
Definition: utils.h:200
static struct ast_app_option resetcdr_opts[128]
Definition: pbx.c:10023
static int pbx_builtin_ringing ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 9925 of file pbx.c.

References AST_CONTROL_RINGING, and ast_indicate().

9926 {
9928  return 0;
9929 }
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
static int pbx_builtin_setamaflags ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10046 of file pbx.c.

References ast_cdr_setamaflags(), ast_channel_lock, and ast_channel_unlock.

10047 {
10048  /* Copy the AMA Flags as specified */
10049  ast_channel_lock(chan);
10050  ast_cdr_setamaflags(chan, data ? data : "");
10051  ast_channel_unlock(chan);
10052  return 0;
10053 }
int ast_cdr_setamaflags(struct ast_channel *chan, const char *amaflags)
Set AMA flags for channel.
Definition: cdr.c:1042
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static int pbx_builtin_wait ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10230 of file pbx.c.

References ast_app_parse_timelen(), ast_safe_sleep(), and TIMELEN_SECONDS.

10231 {
10232  int ms;
10233 
10234  /* Wait for "n" seconds */
10235  if (!ast_app_parse_timelen(data, &ms, TIMELEN_SECONDS) && ms > 0) {
10236  return ast_safe_sleep(chan, ms);
10237  }
10238  return 0;
10239 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
Definition: app.c:2311
static int pbx_builtin_waitexten ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 10244 of file pbx.c.

References args, AST_APP_ARG, ast_app_parse_options(), ast_app_parse_timelen(), ast_check_hangup(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_get_indication_tone(), ast_indicate(), ast_indicate_data(), ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_tone_zone_sound_unref(), ast_tonepair_start(), ast_verb, ast_waitfordigit(), ast_channel::caller, ast_channel::context, ast_tone_zone_sound::data, ast_channel::exten, ast_party_caller::id, LOG_WARNING, ast_channel::name, ast_party_id::number, parse(), ast_channel::pbx, ast_channel::priority, raise_exception(), ast_pbx::rtimeoutms, S_COR, S_OR, set_ext_pri(), ast_party_number::str, TIMELEN_SECONDS, ast_party_number::valid, WAITEXTEN_DIALTONE, WAITEXTEN_MOH, waitexten_opts, and ast_channel::zone.

10245 {
10246  int ms, res;
10247  struct ast_flags flags = {0};
10248  char *opts[1] = { NULL };
10249  char *parse;
10251  AST_APP_ARG(timeout);
10252  AST_APP_ARG(options);
10253  );
10254 
10255  if (!ast_strlen_zero(data)) {
10256  parse = ast_strdupa(data);
10257  AST_STANDARD_APP_ARGS(args, parse);
10258  } else
10259  memset(&args, 0, sizeof(args));
10260 
10261  if (args.options)
10262  ast_app_parse_options(waitexten_opts, &flags, opts, args.options);
10263 
10264  if (ast_test_flag(&flags, WAITEXTEN_MOH) && !opts[0] ) {
10265  ast_log(LOG_WARNING, "The 'm' option has been specified for WaitExten without a class.\n");
10266  } else if (ast_test_flag(&flags, WAITEXTEN_MOH)) {
10267  ast_indicate_data(chan, AST_CONTROL_HOLD, S_OR(opts[0], NULL),
10268  !ast_strlen_zero(opts[0]) ? strlen(opts[0]) + 1 : 0);
10269  } else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE)) {
10270  struct ast_tone_zone_sound *ts = ast_get_indication_tone(chan->zone, "dial");
10271  if (ts) {
10272  ast_playtones_start(chan, 0, ts->data, 0);
10273  ts = ast_tone_zone_sound_unref(ts);
10274  } else {
10275  ast_tonepair_start(chan, 350, 440, 0, 0);
10276  }
10277  }
10278  /* Wait for "n" seconds */
10279  if (!ast_app_parse_timelen(args.timeout, &ms, TIMELEN_SECONDS) && ms > 0) {
10280  /* Yay! */
10281  } else if (chan->pbx) {
10282  ms = chan->pbx->rtimeoutms;
10283  } else {
10284  ms = 10000;
10285  }
10286 
10287  res = ast_waitfordigit(chan, ms);
10288  if (!res) {
10289  if (ast_check_hangup(chan)) {
10290  /* Call is hungup for some reason. */
10291  res = -1;
10292  } else if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1,
10293  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
10294  ast_verb(3, "Timeout on %s, continuing...\n", chan->name);
10295  } else if (ast_exists_extension(chan, chan->context, "t", 1,
10296  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
10297  ast_verb(3, "Timeout on %s, going to 't'\n", chan->name);
10298  set_ext_pri(chan, "t", 0); /* 0 will become 1, next time through the loop */
10299  } else if (ast_exists_extension(chan, chan->context, "e", 1,
10300  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
10301  raise_exception(chan, "RESPONSETIMEOUT", 0); /* 0 will become 1, next time through the loop */
10302  } else {
10303  ast_log(LOG_WARNING, "Timeout but no rule 't' or 'e' in context '%s'\n",
10304  chan->context);
10305  res = -1;
10306  }
10307  }
10308 
10309  if (ast_test_flag(&flags, WAITEXTEN_MOH))
10311  else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE))
10312  ast_playtones_stop(chan);
10313 
10314  return res;
10315 }
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
struct ast_tone_zone * zone
Definition: channel.h:767
int priority
Definition: channel.h:841
#define ast_test_flag(p, flag)
Definition: utils.h:63
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
#define WAITEXTEN_MOH
Definition: pbx.c:851
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
Definition: app.c:2311
#define LOG_WARNING
Definition: logger.h:144
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
unsigned int flags
Definition: utils.h:201
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4447
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:411
#define ast_verb(level,...)
Definition: logger.h:243
static struct ast_app_option waitexten_opts[128]
Definition: pbx.c:857
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
static int raise_exception(struct ast_channel *chan, const char *reason, int priority)
Definition: pbx.c:3594
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:83
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:226
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:5400
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:806
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
Description of a tone.
Definition: indications.h:36
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:473
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
Structure used to handle boolean flags.
Definition: utils.h:200
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:319
#define WAITEXTEN_DIALTONE
Definition: pbx.c:852
int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol)
Definition: channel.c:7951
const char * data
Description of a tone.
Definition: indications.h:53
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static void set_ext_pri(struct ast_channel *c, const char *exten, int pri)
Definition: pbx.c:5431
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
struct ast_pbx * pbx
Definition: channel.h:761
int rtimeoutms
Definition: pbx.h:181
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292