Sun Oct 16 2011 08:43:11

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_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_ael_share.c
 

Shareable AEL code -- mainly between internal and external modules.


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 11807 of file chan_iax2.c.

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

Referenced by load_module().

{
   int res;
   char *sdata;
   char *opts;
   int force =0;
   unsigned short callno = PTR_TO_CALLNO(chan->tech_pvt);
   if (ast_strlen_zero(data))
      data = "default";
   sdata = ast_strdupa(data);
   opts = strchr(sdata, '|');
   if (opts)
      *opts='\0';

   if (chan->tech != &iax2_tech) {
      ast_log(LOG_NOTICE, "Can't provision a non-IAX device!\n");
      return -1;
   } 
   if (!callno || !iaxs[callno] || !iaxs[callno]->addr.sin_addr.s_addr) {
      ast_log(LOG_NOTICE, "Can't provision something with no IP?\n");
      return -1;
   }
   res = iax2_provision(&iaxs[callno]->addr, iaxs[callno]->sockfd, NULL, sdata, force);
   ast_verb(3, "Provisioned IAXY at '%s' with '%s'= %d\n",
      ast_inet_ntoa(iaxs[callno]->addr.sin_addr),
      sdata, res);
   return res;
}
static int pbx_builtin_answer ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9170 of file pbx.c.

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

{
   int delay = 0;
   int answer_cdr = 1;
   char *parse;
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(delay);
      AST_APP_ARG(answer_cdr);
   );

   if (ast_strlen_zero(data)) {
      return __ast_answer(chan, 0, 1);
   }

   parse = ast_strdupa(data);

   AST_STANDARD_APP_ARGS(args, parse);

   if (!ast_strlen_zero(args.delay) && (chan->_state != AST_STATE_UP))
      delay = atoi(data);

   if (delay < 0) {
      delay = 0;
   }

   if (!ast_strlen_zero(args.answer_cdr) && !strcasecmp(args.answer_cdr, "nocdr")) {
      answer_cdr = 0;
   }

   return __ast_answer(chan, delay, answer_cdr);
}
static int pbx_builtin_background ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9517 of file pbx.c.

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

{
   int res = 0;
   int mres = 0;
   struct ast_flags flags = {0};
   char *parse, exten[2] = "";
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(filename);
      AST_APP_ARG(options);
      AST_APP_ARG(lang);
      AST_APP_ARG(context);
   );

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "Background requires an argument (filename)\n");
      return -1;
   }

   parse = ast_strdupa(data);

   AST_STANDARD_APP_ARGS(args, parse);

   if (ast_strlen_zero(args.lang))
      args.lang = (char *)chan->language; /* XXX this is const */

   if (ast_strlen_zero(args.context)) {
      const char *context;
      ast_channel_lock(chan);
      if ((context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"))) {
         args.context = ast_strdupa(context);
      } else {
         args.context = chan->context;
      }
      ast_channel_unlock(chan);
   }

   if (args.options) {
      if (!strcasecmp(args.options, "skip"))
         flags.flags = BACKGROUND_SKIP;
      else if (!strcasecmp(args.options, "noanswer"))
         flags.flags = BACKGROUND_NOANSWER;
      else
         ast_app_parse_options(background_opts, &flags, NULL, args.options);
   }

   /* Answer if need be */
   if (chan->_state != AST_STATE_UP) {
      if (ast_test_flag(&flags, BACKGROUND_SKIP)) {
         goto done;
      } else if (!ast_test_flag(&flags, BACKGROUND_NOANSWER)) {
         res = ast_answer(chan);
      }
   }

   if (!res) {
      char *back = ast_strip(args.filename);
      char *front;

      ast_stopstream(chan);      /* Stop anything playing */
      /* Stream the list of files */
      while (!res && (front = strsep(&back, "&")) ) {
         if ( (res = ast_streamfile(chan, front, args.lang)) ) {
            ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char*)data);
            res = 0;
            mres = 1;
            break;
         }
         if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) {
            res = ast_waitstream(chan, "");
         } else if (ast_test_flag(&flags, BACKGROUND_MATCHEXTEN)) {
            res = ast_waitstream_exten(chan, args.context);
         } else {
            res = ast_waitstream(chan, AST_DIGIT_ANY);
         }
         ast_stopstream(chan);
      }
   }

   /*
    * If the single digit DTMF is an extension in the specified context, then
    * go there and signal no DTMF.  Otherwise, we should exit with that DTMF.
    * If we're in Macro, we'll exit and seek that DTMF as the beginning of an
    * extension in the Macro's calling context.  If we're not in Macro, then
    * we'll simply seek that extension in the calling context.  Previously,
    * someone complained about the behavior as it related to the interior of a
    * Gosub routine, and the fix (#14011) inadvertently broke FreePBX
    * (#14940).  This change should fix both of these situations, but with the
    * possible incompatibility that if a single digit extension does not exist
    * (but a longer extension COULD have matched), it would have previously
    * gone immediately to the "i" extension, but will now need to wait for a
    * timeout.
    *
    * Later, we had to add a flag to disable this workaround, because AGI
    * users can EXEC Background and reasonably expect that the DTMF code will
    * be returned (see #16434).
    */
   if (!ast_test_flag(chan, AST_FLAG_DISABLE_WORKAROUNDS)
      && (exten[0] = res)
      && ast_canmatch_extension(chan, args.context, exten, 1,
         S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))
      && !ast_matchmore_extension(chan, args.context, exten, 1,
         S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
      snprintf(chan->exten, sizeof(chan->exten), "%c", res);
      ast_copy_string(chan->context, args.context, sizeof(chan->context));
      chan->priority = 0;
      res = 0;
   }
done:
   pbx_builtin_setvar_helper(chan, "BACKGROUNDSTATUS", mres ? "FAILED" : "SUCCESS");
   return res;
}
static int pbx_builtin_busy ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9140 of file pbx.c.

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

Referenced by __ast_pbx_run().

{
   ast_indicate(chan, AST_CONTROL_BUSY);
   /* Don't change state of an UP channel, just indicate
      busy in audio */
   if (chan->_state != AST_STATE_UP) {
      ast_setstate(chan, AST_STATE_BUSY);
      ast_cdr_busy(chan->cdr);
   }
   wait_for_hangup(chan, data);
   return -1;
}
static int pbx_builtin_congestion ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9156 of file pbx.c.

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

Referenced by __ast_pbx_run().

{
   ast_indicate(chan, AST_CONTROL_CONGESTION);
   /* Don't change state of an UP channel, just indicate
      congestion in audio */
   if (chan->_state != AST_STATE_UP)
      ast_setstate(chan, AST_STATE_BUSY);
   wait_for_hangup(chan, data);
   return -1;
}
static int pbx_builtin_execiftime ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9374 of file pbx.c.

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

{
   char *s, *appname;
   struct ast_timing timing;
   struct ast_app *app;
   static const char * const usage = "ExecIfTime requires an argument:\n  <time range>,<days of week>,<days of month>,<months>[,<timezone>]?<appname>[(<appargs>)]";

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "%s\n", usage);
      return -1;
   }

   appname = ast_strdupa(data);

   s = strsep(&appname, "?"); /* Separate the timerange and application name/data */
   if (!appname) {   /* missing application */
      ast_log(LOG_WARNING, "%s\n", usage);
      return -1;
   }

   if (!ast_build_timing(&timing, s)) {
      ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", s, usage);
      ast_destroy_timing(&timing);
      return -1;
   }

   if (!ast_check_timing(&timing))  { /* outside the valid time window, just return */
      ast_destroy_timing(&timing);
      return 0;
   }
   ast_destroy_timing(&timing);

   /* now split appname(appargs) */
   if ((s = strchr(appname, '('))) {
      char *e;
      *s++ = '\0';
      if ((e = strrchr(s, ')')))
         *e = '\0';
      else
         ast_log(LOG_WARNING, "Failed to find closing parenthesis\n");
   }


   if ((app = pbx_findapp(appname))) {
      return pbx_exec(chan, app, S_OR(s, ""));
   } else {
      ast_log(LOG_WARNING, "Cannot locate application %s\n", appname);
      return -1;
   }
}
static int pbx_builtin_goto ( struct ast_channel chan,
const char *  data 
) [static]

Goto

Definition at line 9632 of file pbx.c.

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

Referenced by pbx_builtin_gotoiftime(), and pbx_builtin_gotoif().

{
   int res = ast_parseable_goto(chan, data);
   if (!res)
      ast_verb(3, "Goto (%s,%s,%d)\n", chan->context, chan->exten, chan->priority + 1);
   return res;
}
static int pbx_builtin_gotoiftime ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9324 of file pbx.c.

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

{
   char *s, *ts, *branch1, *branch2, *branch;
   struct ast_timing timing;
   const char *ctime;
   struct timeval tv = ast_tvnow();
   long timesecs;

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "GotoIfTime requires an argument:\n  <time range>,<days of week>,<days of month>,<months>[,<timezone>]?'labeliftrue':'labeliffalse'\n");
      return -1;
   }

   ts = s = ast_strdupa(data);

   if (chan) {
      ast_channel_lock(chan);
      if ((ctime = pbx_builtin_getvar_helper(chan, "TESTTIME")) && sscanf(ctime, "%ld", &timesecs) == 1) {
         tv.tv_sec = timesecs;
      } else if (ctime) {
         ast_log(LOG_WARNING, "Using current time to evaluate\n");
         /* Reset when unparseable */
         pbx_builtin_setvar_helper(chan, "TESTTIME", NULL);
      }
      ast_channel_unlock(chan);
   }
   /* Separate the Goto path */
   strsep(&ts, "?");
   branch1 = strsep(&ts,":");
   branch2 = strsep(&ts,"");

   /* struct ast_include include contained garbage here, fixed by zeroing it on get_timerange */
   if (ast_build_timing(&timing, s) && ast_check_timing2(&timing, tv)) {
      branch = branch1;
   } else {
      branch = branch2;
   }
   ast_destroy_timing(&timing);

   if (ast_strlen_zero(branch)) {
      ast_debug(1, "Not taking any branch\n");
      return 0;
   }

   return pbx_builtin_goto(chan, branch);
}
static int pbx_builtin_hangup ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9260 of file pbx.c.

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

{
   ast_set_hangupsource(chan, "dialplan/builtin", 0);

   if (!ast_strlen_zero(data)) {
      int cause;
      char *endptr;

      if ((cause = ast_str2cause(data)) > -1) {
         chan->hangupcause = cause;
         return -1;
      }

      cause = strtol((const char *) data, &endptr, 10);
      if (cause != 0 || (data != endptr)) {
         chan->hangupcause = cause;
         return -1;
      }

      ast_log(LOG_WARNING, "Invalid cause given to Hangup(): \"%s\"\n", (char *) data);
   }

   if (!chan->hangupcause) {
      chan->hangupcause = AST_CAUSE_NORMAL_CLEARING;
   }

   return -1;
}
static int pbx_builtin_proceeding ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9113 of file pbx.c.

References ast_indicate(), and AST_CONTROL_PROCEEDING.

{
   ast_indicate(chan, AST_CONTROL_PROCEEDING);
   return 0;
}
static int pbx_builtin_progress ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9122 of file pbx.c.

References ast_indicate(), and AST_CONTROL_PROGRESS.

{
   ast_indicate(chan, AST_CONTROL_PROGRESS);
   return 0;
}
static int pbx_builtin_resetcdr ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9232 of file pbx.c.

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

{
   char *args;
   struct ast_flags flags = { 0 };

   if (!ast_strlen_zero(data)) {
      args = ast_strdupa(data);
      ast_app_parse_options(resetcdr_opts, &flags, NULL, args);
   }

   ast_cdr_reset(chan->cdr, &flags);

   return 0;
}
static int pbx_builtin_ringing ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9131 of file pbx.c.

References ast_indicate(), and AST_CONTROL_RINGING.

{
   ast_indicate(chan, AST_CONTROL_RINGING);
   return 0;
}
static int pbx_builtin_setamaflags ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9250 of file pbx.c.

References ast_cdr_setamaflags().

{
   /* Copy the AMA Flags as specified */
   ast_cdr_setamaflags(chan, data ? data : "");
   return 0;
}
static int pbx_builtin_wait ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9428 of file pbx.c.

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

{
   int ms;

   /* Wait for "n" seconds */
   if (!ast_app_parse_timelen(data, &ms, TIMELEN_SECONDS) && ms > 0) {
      return ast_safe_sleep(chan, ms);
   }
   return 0;
}
static int pbx_builtin_waitexten ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 9442 of file pbx.c.

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

{
   int ms, res;
   struct ast_flags flags = {0};
   char *opts[1] = { NULL };
   char *parse;
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(timeout);
      AST_APP_ARG(options);
   );

   if (!ast_strlen_zero(data)) {
      parse = ast_strdupa(data);
      AST_STANDARD_APP_ARGS(args, parse);
   } else
      memset(&args, 0, sizeof(args));

   if (args.options)
      ast_app_parse_options(waitexten_opts, &flags, opts, args.options);

   if (ast_test_flag(&flags, WAITEXTEN_MOH) && !opts[0] ) {
      ast_log(LOG_WARNING, "The 'm' option has been specified for WaitExten without a class.\n"); 
   } else if (ast_test_flag(&flags, WAITEXTEN_MOH)) {
      ast_indicate_data(chan, AST_CONTROL_HOLD, S_OR(opts[0], NULL), strlen(opts[0]));
   } else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE)) {
      struct ast_tone_zone_sound *ts = ast_get_indication_tone(chan->zone, "dial");
      if (ts) {
         ast_playtones_start(chan, 0, ts->data, 0);
         ts = ast_tone_zone_sound_unref(ts);
      } else {
         ast_tonepair_start(chan, 350, 440, 0, 0);
      }
   }
   /* Wait for "n" seconds */
   if (!ast_app_parse_timelen(args.timeout, &ms, TIMELEN_SECONDS) && ms > 0) {
      /* Yay! */
   } else if (chan->pbx) {
      ms = chan->pbx->rtimeoutms;
   } else {
      ms = 10000;
   }

   res = ast_waitfordigit(chan, ms);
   if (!res) {
      if (ast_check_hangup(chan)) {
         /* Call is hungup for some reason. */
         res = -1;
      } else if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1,
         S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
         ast_verb(3, "Timeout on %s, continuing...\n", chan->name);
      } else if (ast_exists_extension(chan, chan->context, "t", 1,
         S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
         ast_verb(3, "Timeout on %s, going to 't'\n", chan->name);
         set_ext_pri(chan, "t", 0); /* 0 will become 1, next time through the loop */
      } else if (ast_exists_extension(chan, chan->context, "e", 1,
         S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
         raise_exception(chan, "RESPONSETIMEOUT", 0); /* 0 will become 1, next time through the loop */
      } else {
         ast_log(LOG_WARNING, "Timeout but no rule 't' or 'e' in context '%s'\n",
            chan->context);
         res = -1;
      }
   }

   if (ast_test_flag(&flags, WAITEXTEN_MOH))
      ast_indicate(chan, AST_CONTROL_UNHOLD);
   else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE))
      ast_playtones_stop(chan);

   return res;
}