Mon May 14 04:43:22 2007

Asterisk developer's documentation


app_dial.c File Reference

dial() & retrydial() - Trivial application to dial a channel and send an URL on answer More...

#include "asterisk.h"
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/signal.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/say.h"
#include "asterisk/config.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/callerid.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/causes.h"
#include "asterisk/rtp.h"
#include "asterisk/manager.h"
#include "asterisk/privacy.h"
#include "asterisk/stringfields.h"

Include dependency graph for app_dial.c:

Go to the source code of this file.

Data Structures

struct  dial_localuser

Defines

#define AST_MAX_FORWARDS   8
#define AST_MAX_WATCHERS   256
#define DIAL_NOFORWARDHTML   (1 << 31)
#define DIAL_STILLGOING   (1 << 30)
#define HANDLE_CAUSE(cause, chan)

Enumerations

enum  {
  OPT_ANNOUNCE = (1 << 0), OPT_RESETCDR = (1 << 1), OPT_DTMF_EXIT = (1 << 2), OPT_SENDDTMF = (1 << 3),
  OPT_FORCECLID = (1 << 4), OPT_GO_ON = (1 << 5), OPT_CALLEE_HANGUP = (1 << 6), OPT_CALLER_HANGUP = (1 << 7),
  OPT_PRIORITY_JUMP = (1 << 8), OPT_DURATION_LIMIT = (1 << 9), OPT_MUSICBACK = (1 << 10), OPT_CALLEE_MACRO = (1 << 11),
  OPT_SCREEN_NOINTRO = (1 << 12), OPT_SCREEN_NOCLID = (1 << 13), OPT_ORIGINAL_CLID = (1 << 14), OPT_SCREENING = (1 << 15),
  OPT_PRIVACY = (1 << 16), OPT_RINGBACK = (1 << 17), OPT_DURATION_STOP = (1 << 18), OPT_CALLEE_TRANSFER = (1 << 19),
  OPT_CALLER_TRANSFER = (1 << 20), OPT_CALLEE_MONITOR = (1 << 21), OPT_CALLER_MONITOR = (1 << 22), OPT_GOTO = (1 << 23),
  OPT_OPERMODE = (1 << 24), OPT_CALLEE_PARK = (1 << 25), OPT_CALLER_PARK = (1 << 26), OPT_IGNORE_FORWARDING = (1 << 27)
}
enum  {
  OPT_ARG_ANNOUNCE = 0, OPT_ARG_SENDDTMF, OPT_ARG_GOTO, OPT_ARG_DURATION_LIMIT,
  OPT_ARG_MUSICBACK, OPT_ARG_CALLEE_MACRO, OPT_ARG_PRIVACY, OPT_ARG_DURATION_STOP,
  OPT_ARG_OPERMODE, OPT_ARG_ARRAY_SIZE
}

Functions

 AST_APP_OPTIONS (dial_exec_options,{AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE), AST_APP_OPTION('C', OPT_RESETCDR), AST_APP_OPTION('d', OPT_DTMF_EXIT), AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF), AST_APP_OPTION('f', OPT_FORCECLID), AST_APP_OPTION('g', OPT_GO_ON), AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO), AST_APP_OPTION('h', OPT_CALLEE_HANGUP), AST_APP_OPTION('H', OPT_CALLER_HANGUP), AST_APP_OPTION('i', OPT_IGNORE_FORWARDING), AST_APP_OPTION('j', OPT_PRIORITY_JUMP), AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT), AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK), AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO), AST_APP_OPTION('n', OPT_SCREEN_NOINTRO), AST_APP_OPTION('N', OPT_SCREEN_NOCLID), AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE), AST_APP_OPTION('o', OPT_ORIGINAL_CLID), AST_APP_OPTION('p', OPT_SCREENING), AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY), AST_APP_OPTION('r', OPT_RINGBACK), AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP), AST_APP_OPTION('t', OPT_CALLEE_TRANSFER), AST_APP_OPTION('T', OPT_CALLER_TRANSFER), AST_APP_OPTION('w', OPT_CALLEE_MONITOR), AST_APP_OPTION('W', OPT_CALLER_MONITOR), AST_APP_OPTION('k', OPT_CALLEE_PARK), AST_APP_OPTION('K', OPT_CALLER_PARK),})
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Dialing Application")
static int dial_exec (struct ast_channel *chan, void *data)
static const char * get_cid_name (char *name, int namelen, struct ast_channel *chan)
static void hanguptree (struct dial_localuser *outgoing, struct ast_channel *exception)
static int load_module (void)
static int onedigit_goto (struct ast_channel *chan, const char *context, char exten, int pri)
static void replace_macro_delimiter (char *s)
static int retrydial_exec (struct ast_channel *chan, void *data)
static void senddialevent (struct ast_channel *src, struct ast_channel *dst)
static int unload_module (void)
static int valid_priv_reply (struct ast_flags *opts, int res)
static struct ast_channelwait_for_answer (struct ast_channel *in, struct dial_localuser *outgoing, int *to, struct ast_flags *peerflags, int *sentringing, char *status, size_t statussize, int busystart, int nochanstart, int congestionstart, int priority_jump, int *result)

Variables

static char * app = "Dial"
static char * descrip
enum { ... }  dial_exec_option_args
enum { ... }  dial_exec_option_flags
static char * rapp = "RetryDial"
static char * rdescrip
static char * rsynopsis = "Place a call, retrying on failure allowing optional exit extension."
static char * synopsis = "Place a call and connect to the current channel"


Detailed Description

dial() & retrydial() - Trivial application to dial a channel and send an URL on answer

Author:
Mark Spencer <markster@digium.com>

Definition in file app_dial.c.


Define Documentation

#define AST_MAX_FORWARDS   8

Definition at line 320 of file app_dial.c.

Referenced by wait_for_answer().

#define AST_MAX_WATCHERS   256

Definition at line 322 of file app_dial.c.

#define DIAL_NOFORWARDHTML   (1 << 31)

Definition at line 247 of file app_dial.c.

Referenced by wait_for_answer().

#define DIAL_STILLGOING   (1 << 30)

Definition at line 246 of file app_dial.c.

Referenced by wait_for_answer().

#define HANDLE_CAUSE ( cause,
chan   ) 

Definition at line 324 of file app_dial.c.

Referenced by wait_for_answer().


Enumeration Type Documentation

anonymous enum

Enumerator:
OPT_ANNOUNCE 
OPT_RESETCDR 
OPT_DTMF_EXIT 
OPT_SENDDTMF 
OPT_FORCECLID 
OPT_GO_ON 
OPT_CALLEE_HANGUP 
OPT_CALLER_HANGUP 
OPT_PRIORITY_JUMP 
OPT_DURATION_LIMIT 
OPT_MUSICBACK 
OPT_CALLEE_MACRO 
OPT_SCREEN_NOINTRO 
OPT_SCREEN_NOCLID 
OPT_ORIGINAL_CLID 
OPT_SCREENING 
OPT_PRIVACY 
OPT_RINGBACK 
OPT_DURATION_STOP 
OPT_CALLEE_TRANSFER 
OPT_CALLER_TRANSFER 
OPT_CALLEE_MONITOR 
OPT_CALLER_MONITOR 
OPT_GOTO 
OPT_OPERMODE 
OPT_CALLEE_PARK 
OPT_CALLER_PARK 
OPT_IGNORE_FORWARDING 

Definition at line 215 of file app_dial.c.

00215      {
00216    OPT_ANNOUNCE =    (1 << 0),
00217    OPT_RESETCDR =    (1 << 1),
00218    OPT_DTMF_EXIT =      (1 << 2),
00219    OPT_SENDDTMF =    (1 << 3),
00220    OPT_FORCECLID =      (1 << 4),
00221    OPT_GO_ON =    (1 << 5),
00222    OPT_CALLEE_HANGUP =  (1 << 6),
00223    OPT_CALLER_HANGUP =  (1 << 7),
00224    OPT_PRIORITY_JUMP =  (1 << 8),
00225    OPT_DURATION_LIMIT = (1 << 9),
00226    OPT_MUSICBACK =      (1 << 10),
00227    OPT_CALLEE_MACRO =   (1 << 11),
00228    OPT_SCREEN_NOINTRO = (1 << 12),
00229    OPT_SCREEN_NOCLID =  (1 << 13),
00230    OPT_ORIGINAL_CLID =  (1 << 14),
00231    OPT_SCREENING =      (1 << 15),
00232    OPT_PRIVACY =     (1 << 16),
00233    OPT_RINGBACK =    (1 << 17),
00234    OPT_DURATION_STOP =  (1 << 18),
00235    OPT_CALLEE_TRANSFER =   (1 << 19),
00236    OPT_CALLER_TRANSFER =   (1 << 20),
00237    OPT_CALLEE_MONITOR = (1 << 21),
00238    OPT_CALLER_MONITOR = (1 << 22),
00239    OPT_GOTO =     (1 << 23),
00240    OPT_OPERMODE =       (1 << 24),
00241    OPT_CALLEE_PARK = (1 << 25),
00242    OPT_CALLER_PARK = (1 << 26),
00243    OPT_IGNORE_FORWARDING = (1 << 27),
00244 } dial_exec_option_flags;

anonymous enum

Enumerator:
OPT_ARG_ANNOUNCE 
OPT_ARG_SENDDTMF 
OPT_ARG_GOTO 
OPT_ARG_DURATION_LIMIT 
OPT_ARG_MUSICBACK 
OPT_ARG_CALLEE_MACRO 
OPT_ARG_PRIVACY 
OPT_ARG_DURATION_STOP 
OPT_ARG_OPERMODE 
OPT_ARG_ARRAY_SIZE 

Definition at line 249 of file app_dial.c.

00249      {
00250    OPT_ARG_ANNOUNCE = 0,
00251    OPT_ARG_SENDDTMF,
00252    OPT_ARG_GOTO,
00253    OPT_ARG_DURATION_LIMIT,
00254    OPT_ARG_MUSICBACK,
00255    OPT_ARG_CALLEE_MACRO,
00256    OPT_ARG_PRIVACY,
00257    OPT_ARG_DURATION_STOP,
00258    OPT_ARG_OPERMODE,
00259    /* note: this entry _MUST_ be the last one in the enum */
00260    OPT_ARG_ARRAY_SIZE,
00261 } dial_exec_option_args;


Function Documentation

AST_APP_OPTIONS ( dial_exec_options   ) 

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Dialing Application"   
)

static int dial_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 1694 of file app_dial.c.

Referenced by load_module().

01695 {
01696    struct ast_flags peerflags;
01697 
01698    memset(&peerflags, 0, sizeof(peerflags));
01699 
01700    return dial_exec_full(chan, data, &peerflags, NULL);
01701 }

static const char* get_cid_name ( char *  name,
int  namelen,
struct ast_channel chan 
) [static]

Definition at line 369 of file app_dial.c.

References ast_get_hint(), dial_localuser::chan, ast_channel::context, context, ast_channel::exten, exten, ast_channel::macrocontext, ast_channel::macroexten, and S_OR.

Referenced by wait_for_answer().

00370 {
00371    const char *context = S_OR(chan->macrocontext, chan->context);
00372    const char *exten = S_OR(chan->macroexten, chan->exten);
00373 
00374    return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
00375 }

static void hanguptree ( struct dial_localuser outgoing,
struct ast_channel exception 
) [static]

Definition at line 306 of file app_dial.c.

References ast_hangup(), dial_localuser::chan, free, and dial_localuser::next.

00307 {
00308    /* Hang up a tree of stuff */
00309    struct dial_localuser *oo;
00310    while (outgoing) {
00311       /* Hangup any existing lines we have open */
00312       if (outgoing->chan && (outgoing->chan != exception))
00313          ast_hangup(outgoing->chan);
00314       oo = outgoing;
00315       outgoing=outgoing->next;
00316       free(oo);
00317    }
00318 }

static int load_module ( void   )  [static]

Definition at line 1820 of file app_dial.c.

References ast_register_application(), dial_exec(), and retrydial_exec().

01821 {
01822    int res;
01823 
01824    res = ast_register_application(app, dial_exec, synopsis, descrip);
01825    res |= ast_register_application(rapp, retrydial_exec, rsynopsis, rdescrip);
01826    
01827    return res;
01828 }

static int onedigit_goto ( struct ast_channel chan,
const char *  context,
char  exten,
int  pri 
) [static]

Definition at line 350 of file app_dial.c.

References ast_goto_if_exists(), ast_strlen_zero(), dial_localuser::chan, ast_channel::context, and ast_channel::macrocontext.

Referenced by retrydial_exec(), and wait_for_answer().

00351 {
00352    char rexten[2] = { exten, '\0' };
00353 
00354    if (context) {
00355       if (!ast_goto_if_exists(chan, context, rexten, pri))
00356          return 1;
00357    } else {
00358       if (!ast_goto_if_exists(chan, chan->context, rexten, pri))
00359          return 1;
00360       else if (!ast_strlen_zero(chan->macrocontext)) {
00361          if (!ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
00362             return 1;
00363       }
00364    }
00365    return 0;
00366 }

static void replace_macro_delimiter ( char *  s  )  [static]

Definition at line 757 of file app_dial.c.

00758 {
00759    for (; *s; s++)
00760       if (*s == '^')
00761          *s = '|';
00762 }

static int retrydial_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 1703 of file app_dial.c.

References AST_DIGIT_ANY, AST_FLAG_MOH, ast_log(), ast_module_user_add, ast_module_user_remove, ast_moh_start(), ast_moh_stop(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitfordigit(), ast_waitstream(), context, ast_channel::data, LOG_ERROR, LOG_WARNING, onedigit_goto(), OPT_DTMF_EXIT, and pbx_builtin_getvar_helper().

Referenced by load_module().

01704 {
01705    char *announce = NULL, *dialdata = NULL;
01706    const char *context = NULL;
01707    int sleep = 0, loops = 0, res = -1;
01708    struct ast_module_user *u;
01709    struct ast_flags peerflags;
01710    
01711    if (ast_strlen_zero(data)) {
01712       ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
01713       return -1;
01714    }  
01715 
01716    u = ast_module_user_add(chan);
01717 
01718    announce = ast_strdupa(data);
01719 
01720    memset(&peerflags, 0, sizeof(peerflags));
01721 
01722    if ((dialdata = strchr(announce, '|'))) {
01723       *dialdata++ = '\0';
01724       if ((sleep = atoi(dialdata))) {
01725          sleep *= 1000;
01726       } else {
01727          ast_log(LOG_ERROR, "%s requires the numerical argument <sleep>\n",rapp);
01728          goto done;
01729       }
01730       if ((dialdata = strchr(dialdata, '|'))) {
01731          *dialdata++ = '\0';
01732          if (!(loops = atoi(dialdata))) {
01733             ast_log(LOG_ERROR, "%s requires the numerical argument <loops>\n",rapp);
01734             goto done;
01735          }
01736       }
01737    }
01738    
01739    if ((dialdata = strchr(dialdata, '|'))) {
01740       *dialdata++ = '\0';
01741    } else {
01742       ast_log(LOG_ERROR, "%s requires more arguments\n",rapp);
01743       goto done;
01744    }
01745       
01746    if (sleep < 1000)
01747       sleep = 10000;
01748 
01749    if (!loops)
01750       loops = -1; /* run forever */
01751    
01752    context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
01753 
01754    res = 0;
01755    while (loops) {
01756       int continue_exec;
01757 
01758       chan->data = "Retrying";
01759       if (ast_test_flag(chan, AST_FLAG_MOH))
01760          ast_moh_stop(chan);
01761 
01762       res = dial_exec_full(chan, dialdata, &peerflags, &continue_exec);
01763       if (continue_exec)
01764          break;
01765       if (res == 0) {
01766          if (ast_test_flag(&peerflags, OPT_DTMF_EXIT)) {
01767             if (!(res = ast_streamfile(chan, announce, chan->language)))
01768                res = ast_waitstream(chan, AST_DIGIT_ANY);
01769             if (!res && sleep) {
01770                if (!ast_test_flag(chan, AST_FLAG_MOH))
01771                   ast_moh_start(chan, NULL, NULL);
01772                res = ast_waitfordigit(chan, sleep);
01773             }
01774          } else {
01775             if (!(res = ast_streamfile(chan, announce, chan->language)))
01776                res = ast_waitstream(chan, "");
01777             if (sleep) {
01778                if (!ast_test_flag(chan, AST_FLAG_MOH))
01779                   ast_moh_start(chan, NULL, NULL);
01780                if (!res) 
01781                   res = ast_waitfordigit(chan, sleep);
01782             }
01783          }
01784       }
01785 
01786       if (res < 0)
01787          break;
01788       else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
01789          if (onedigit_goto(chan, context, (char) res, 1)) {
01790             res = 0;
01791             break;
01792          }
01793       }
01794       loops--;
01795    }
01796    if (loops == 0)
01797       res = 0;
01798    else if (res == 1)
01799       res = 0;
01800 
01801    if (ast_test_flag(chan, AST_FLAG_MOH))
01802       ast_moh_stop(chan);
01803  done:
01804    ast_module_user_remove(u);
01805    return res;
01806 }

static void senddialevent ( struct ast_channel src,
struct ast_channel dst 
) [static]

Definition at line 377 of file app_dial.c.

References ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, EVENT_FLAG_CALL, manager_event(), and S_OR.

Referenced by wait_for_answer().

00378 {
00379    /* XXX do we need also CallerIDnum ? */
00380    manager_event(EVENT_FLAG_CALL, "Dial", 
00381             "Source: %s\r\n"
00382             "Destination: %s\r\n"
00383             "CallerID: %s\r\n"
00384             "CallerIDName: %s\r\n"
00385             "SrcUniqueID: %s\r\n"
00386             "DestUniqueID: %s\r\n",
00387             src->name, dst->name, S_OR(src->cid.cid_num, "<unknown>"),
00388             S_OR(src->cid.cid_name, "<unknown>"), src->uniqueid,
00389             dst->uniqueid);
00390 }

static int unload_module ( void   )  [static]

Definition at line 1808 of file app_dial.c.

References ast_module_user_hangup_all, and ast_unregister_application().

01809 {
01810    int res;
01811 
01812    res = ast_unregister_application(app);
01813    res |= ast_unregister_application(rapp);
01814 
01815    ast_module_user_hangup_all();
01816    
01817    return res;
01818 }

static int valid_priv_reply ( struct ast_flags opts,
int  res 
) [static]

Definition at line 766 of file app_dial.c.

References ast_test_flag, OPT_PRIVACY, and OPT_SCREENING.

00767 {
00768    if (res < '1')
00769       return 0;
00770    if (ast_test_flag(opts, OPT_PRIVACY) && res <= '5')
00771       return 1;
00772    if (ast_test_flag(opts, OPT_SCREENING) && res <= '4')
00773       return 1;
00774    return 0;
00775 }

static struct ast_channel* wait_for_answer ( struct ast_channel in,
struct dial_localuser outgoing,
int *  to,
struct ast_flags peerflags,
int *  sentringing,
char *  status,
size_t  statussize,
int  busystart,
int  nochanstart,
int  congestionstart,
int  priority_jump,
int *  result 
) [static]

Definition at line 392 of file app_dial.c.

References ast_channel::_state, accountcode, ast_call(), AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NORMAL_CLEARING, ast_channel_inherit_variables(), ast_channel_make_compatible(), ast_channel_sendhtml(), ast_clear_flag, AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_flags, ast_deactivate_generator(), AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_TEXT, AST_FRAME_VOICE, ast_frfree(), ast_goto_if_exists(), ast_hangup(), ast_indicate(), ast_indicate_data(), ast_log(), AST_MAX_EXTENSION, AST_MAX_FORWARDS, AST_MAX_WATCHERS, ast_opt_priority_jumping, ast_read(), ast_request(), ast_rtp_early_bridge(), ast_rtp_make_compatible(), ast_set_callerid(), AST_STATE_UP, ast_strdup, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose(), ast_waitfor_n(), ast_write(), ast_channel::cdrflags, dial_localuser::chan, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, ast_callerid::cid_num, context, ast_channel::context, DIAL_NOFORWARDHTML, DIAL_STILLGOING, ast_channel::dialcontext, ast_channel::exten, f, dial_localuser::forwards, free, get_cid_name(), HANDLE_CAUSE, ast_channel::hangupcause, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, ast_channel::macroexten, ast_channel::nativeformats, dial_localuser::next, onedigit_goto(), OPT_CALLEE_HANGUP, OPT_CALLEE_MONITOR, OPT_CALLEE_PARK, OPT_CALLEE_TRANSFER, OPT_CALLER_HANGUP, OPT_CALLER_MONITOR, OPT_CALLER_PARK, OPT_CALLER_TRANSFER, OPT_DTMF_EXIT, OPT_FORCECLID, OPT_IGNORE_FORWARDING, OPT_MUSICBACK, OPT_ORIGINAL_CLID, OPT_RINGBACK, option_debug, option_verbose, pbx_builtin_getvar_helper(), S_OR, senddialevent(), ast_channel::tech, VERBOSE_PREFIX_2, and VERBOSE_PREFIX_3.

Referenced by try_calling().

00393 {
00394    int numbusy = busystart;
00395    int numcongestion = congestionstart;
00396    int numnochan = nochanstart;
00397    int prestart = busystart + congestionstart + nochanstart;
00398    int orig = *to;
00399    struct ast_channel *peer = NULL;
00400    /* single is set if only one destination is enabled */
00401    int single = outgoing && !outgoing->next && !ast_test_flag(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
00402    
00403    if (single) {
00404       /* Turn off hold music, etc */
00405       ast_deactivate_generator(in);
00406       /* If we are calling a single channel, make them compatible for in-band tone purpose */
00407       ast_channel_make_compatible(outgoing->chan, in);
00408    }
00409    
00410    
00411    while (*to && !peer) {
00412       struct dial_localuser *o;
00413       int pos = 0;   /* how many channels do we handle */
00414       int numlines = prestart;
00415       struct ast_channel *winner;
00416       struct ast_channel *watchers[AST_MAX_WATCHERS];
00417 
00418       watchers[pos++] = in;
00419       for (o = outgoing; o; o = o->next) {
00420          /* Keep track of important channels */
00421          if (ast_test_flag(o, DIAL_STILLGOING) && o->chan)
00422             watchers[pos++] = o->chan;
00423          numlines++;
00424       }
00425       if (pos == 1) {   /* only the input channel is available */
00426          if (numlines == (numbusy + numcongestion + numnochan)) {
00427             if (option_verbose > 2)
00428                ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
00429             if (numbusy)
00430                strcpy(status, "BUSY"); 
00431             else if (numcongestion)
00432                strcpy(status, "CONGESTION");
00433             else if (numnochan)
00434                strcpy(status, "CHANUNAVAIL");
00435             if (ast_opt_priority_jumping || priority_jump)
00436                ast_goto_if_exists(in, in->context, in->exten, in->priority + 101);
00437          } else {
00438             if (option_verbose > 2)
00439                ast_verbose(VERBOSE_PREFIX_3 "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, numbusy, numcongestion, numnochan);
00440          }
00441          *to = 0;
00442          return NULL;
00443       }
00444       winner = ast_waitfor_n(watchers, pos, to);
00445       for (o = outgoing; o; o = o->next) {
00446          struct ast_frame *f;
00447          struct ast_channel *c = o->chan;
00448 
00449          if (c == NULL)
00450             continue;
00451          if (ast_test_flag(o, DIAL_STILLGOING) && c->_state == AST_STATE_UP) {
00452             if (!peer) {
00453                if (option_verbose > 2)
00454                   ast_verbose(VERBOSE_PREFIX_3 "%s answered %s\n", c->name, in->name);
00455                peer = c;
00456                ast_copy_flags(peerflags, o,
00457                          OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
00458                          OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
00459                          OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
00460                          OPT_CALLEE_PARK | OPT_CALLER_PARK |
00461                          DIAL_NOFORWARDHTML);
00462                ast_copy_string(c->dialcontext, "", sizeof(c->dialcontext));
00463                ast_copy_string(c->exten, "", sizeof(c->exten));
00464             }
00465             continue;
00466          }
00467          if (c != winner)
00468             continue;
00469          if (!ast_strlen_zero(c->call_forward)) {
00470             char tmpchan[256];
00471             char *stuff;
00472             char *tech;
00473             int cause;
00474 
00475             ast_copy_string(tmpchan, c->call_forward, sizeof(tmpchan));
00476             if ((stuff = strchr(tmpchan, '/'))) {
00477                *stuff++ = '\0';
00478                tech = tmpchan;
00479             } else {
00480                const char *forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
00481                snprintf(tmpchan, sizeof(tmpchan), "%s@%s", c->call_forward, forward_context ? forward_context : c->context);
00482                stuff = tmpchan;
00483                tech = "Local";
00484             }
00485             /* Before processing channel, go ahead and check for forwarding */
00486             o->forwards++;
00487             if (o->forwards < AST_MAX_FORWARDS) {
00488                if (option_verbose > 2)
00489                   ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, c->name);
00490                /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
00491                if (ast_test_flag(peerflags, OPT_IGNORE_FORWARDING)) {
00492                   if (option_verbose > 2)
00493                      ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' prevented.\n", in->name, tech, stuff);
00494                   c = o->chan = NULL;
00495                   cause = AST_CAUSE_BUSY;
00496                } else {
00497                   /* Setup parameters */
00498                   if ((c = o->chan = ast_request(tech, in->nativeformats, stuff, &cause))) {
00499                      if (single)
00500                         ast_channel_make_compatible(o->chan, in);
00501                      ast_channel_inherit_variables(in, o->chan);
00502                   } else
00503                      ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
00504                }
00505             } else {
00506                if (option_verbose > 2)
00507                   ast_verbose(VERBOSE_PREFIX_3 "Too many forwards from %s\n", c->name);
00508                cause = AST_CAUSE_CONGESTION;
00509                c = o->chan = NULL;
00510             }
00511             if (!c) {
00512                ast_clear_flag(o, DIAL_STILLGOING); 
00513                HANDLE_CAUSE(cause, in);
00514             } else {
00515                ast_rtp_make_compatible(c, in, single);
00516                if (c->cid.cid_num)
00517                   free(c->cid.cid_num);
00518                c->cid.cid_num = NULL;
00519                if (c->cid.cid_name)
00520                   free(c->cid.cid_name);
00521                c->cid.cid_name = NULL;
00522 
00523                if (ast_test_flag(o, OPT_FORCECLID)) {
00524                   c->cid.cid_num = ast_strdup(S_OR(in->macroexten, in->exten));
00525                   ast_string_field_set(c, accountcode, winner->accountcode);
00526                   c->cdrflags = winner->cdrflags;
00527                } else {
00528                   c->cid.cid_num = ast_strdup(in->cid.cid_num);
00529                   c->cid.cid_name = ast_strdup(in->cid.cid_name);
00530                   ast_string_field_set(c, accountcode, in->accountcode);
00531                   c->cdrflags = in->cdrflags;
00532                }
00533 
00534                if (in->cid.cid_ani) {
00535                   if (c->cid.cid_ani)
00536                      free(c->cid.cid_ani);
00537                   c->cid.cid_ani = ast_strdup(in->cid.cid_ani);
00538                }
00539                if (c->cid.cid_rdnis) 
00540                   free(c->cid.cid_rdnis);
00541                c->cid.cid_rdnis = ast_strdup(S_OR(in->macroexten, in->exten));
00542                if (ast_call(c, tmpchan, 0)) {
00543                   ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
00544                   ast_clear_flag(o, DIAL_STILLGOING); 
00545                   ast_hangup(c);
00546                   c = o->chan = NULL;
00547                   numnochan++;
00548                } else {
00549                   senddialevent(in, c);
00550                   /* After calling, set callerid to extension */
00551                   if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID)) {
00552                      char cidname[AST_MAX_EXTENSION];
00553                      ast_set_callerid(c, S_OR(in->macroexten, in->exten), get_cid_name(cidname, sizeof(cidname), in), NULL);
00554                   }
00555                }
00556             }
00557             /* Hangup the original channel now, in case we needed it */
00558             ast_hangup(winner);
00559             continue;
00560          }
00561          f = ast_read(winner);
00562          if (!f) {
00563             in->hangupcause = c->hangupcause;
00564             ast_hangup(c);
00565             c = o->chan = NULL;
00566             ast_clear_flag(o, DIAL_STILLGOING);
00567             HANDLE_CAUSE(in->hangupcause, in);
00568             continue;
00569          }
00570          if (f->frametype == AST_FRAME_CONTROL) {
00571             switch(f->subclass) {
00572             case AST_CONTROL_ANSWER:
00573                /* This is our guy if someone answered. */
00574                if (!peer) {
00575                   if (option_verbose > 2)
00576                      ast_verbose( VERBOSE_PREFIX_3 "%s answered %s\n", c->name, in->name);
00577                   peer = c;
00578                   ast_copy_flags(peerflags, o,
00579                             OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
00580                             OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
00581                             OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
00582                             OPT_CALLEE_PARK | OPT_CALLER_PARK |
00583                             DIAL_NOFORWARDHTML);
00584                   ast_copy_string(c->dialcontext, "", sizeof(c->dialcontext));
00585                   ast_copy_string(c->exten, "", sizeof(c->exten));
00586                   /* Setup RTP early bridge if appropriate */
00587                   ast_rtp_early_bridge(in, peer);
00588                }
00589                /* If call has been answered, then the eventual hangup is likely to be normal hangup */
00590                in->hangupcause = AST_CAUSE_NORMAL_CLEARING;
00591                c->hangupcause = AST_CAUSE_NORMAL_CLEARING;
00592                break;
00593             case AST_CONTROL_BUSY:
00594                if (option_verbose > 2)
00595                   ast_verbose(VERBOSE_PREFIX_3 "%s is busy\n", c->name);
00596                in->hangupcause = c->hangupcause;
00597                ast_hangup(c);
00598                c = o->chan = NULL;
00599                ast_clear_flag(o, DIAL_STILLGOING); 
00600                HANDLE_CAUSE(AST_CAUSE_BUSY, in);
00601                break;
00602             case AST_CONTROL_CONGESTION:
00603                if (option_verbose > 2)
00604                   ast_verbose(VERBOSE_PREFIX_3 "%s is circuit-busy\n", c->name);
00605                in->hangupcause = c->hangupcause;
00606                ast_hangup(c);
00607                c = o->chan = NULL;
00608                ast_clear_flag(o, DIAL_STILLGOING);
00609                HANDLE_CAUSE(AST_CAUSE_CONGESTION, in);
00610                break;
00611             case AST_CONTROL_RINGING:
00612                if (option_verbose > 2)
00613                   ast_verbose(VERBOSE_PREFIX_3 "%s is ringing\n", c->name);
00614                /* Setup early media if appropriate */
00615                if (single)
00616                   ast_rtp_early_bridge(in, c);
00617                if (!(*sentringing) && !ast_test_flag(outgoing, OPT_MUSICBACK)) {
00618                   ast_indicate(in, AST_CONTROL_RINGING);
00619                   (*sentringing)++;
00620                }
00621                break;
00622             case AST_CONTROL_PROGRESS:
00623                if (option_verbose > 2)
00624                   ast_verbose (VERBOSE_PREFIX_3 "%s is making progress passing it to %s\n", c->name, in->name);
00625                /* Setup early media if appropriate */
00626                if (single)
00627                   ast_rtp_early_bridge(in, c);
00628                if (!ast_test_flag(outgoing, OPT_RINGBACK))
00629                   ast_indicate(in, AST_CONTROL_PROGRESS);
00630                break;
00631             case AST_CONTROL_VIDUPDATE:
00632                if (option_verbose > 2)
00633                   ast_verbose (VERBOSE_PREFIX_3 "%s requested a video update, passing it to %s\n", c->name, in->name);
00634                ast_indicate(in, AST_CONTROL_VIDUPDATE);
00635                break;
00636             case AST_CONTROL_PROCEEDING:
00637                if (option_verbose > 2)
00638                   ast_verbose (VERBOSE_PREFIX_3 "%s is proceeding passing it to %s\n", c->name, in->name);
00639                if (single)
00640                   ast_rtp_early_bridge(in, c);
00641                if (!ast_test_flag(outgoing, OPT_RINGBACK))
00642                   ast_indicate(in, AST_CONTROL_PROCEEDING);
00643                break;
00644             case AST_CONTROL_HOLD:
00645                if (option_verbose > 2)
00646                   ast_verbose(VERBOSE_PREFIX_3 "Call on %s placed on hold\n", c->name);
00647                ast_indicate(in, AST_CONTROL_HOLD);
00648                break;
00649             case AST_CONTROL_UNHOLD:
00650                if (option_verbose > 2)
00651                   ast_verbose(VERBOSE_PREFIX_3 "Call on %s left from hold\n", c->name);
00652                ast_indicate(in, AST_CONTROL_UNHOLD);
00653                break;
00654             case AST_CONTROL_OFFHOOK:
00655             case AST_CONTROL_FLASH:
00656                /* Ignore going off hook and flash */
00657                break;
00658             case -1:
00659                if (!ast_test_flag(outgoing, OPT_RINGBACK | OPT_MUSICBACK)) {
00660                   if (option_verbose > 2)
00661                      ast_verbose(VERBOSE_PREFIX_3 "%s stopped sounds\n", c->name);
00662                   ast_indicate(in, -1);
00663                   (*sentringing) = 0;
00664                }
00665                break;
00666             default:
00667                if (option_debug)
00668                   ast_log(LOG_DEBUG, "Dunno what to do with control type %d\n", f->subclass);
00669             }
00670          } else if (single) {
00671             /* XXX are we sure the logic is correct ? or we should just switch on f->frametype ? */
00672             if (f->frametype == AST_FRAME_VOICE && !ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
00673                if (ast_write(in, f)) 
00674                   ast_log(LOG_WARNING, "Unable to forward voice frame\n");
00675             } else if (f->frametype == AST_FRAME_IMAGE && !ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
00676                if (ast_write(in, f))
00677                   ast_log(LOG_WARNING, "Unable to forward image\n");
00678             } else if (f->frametype == AST_FRAME_TEXT && !ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
00679                if (ast_write(in, f))
00680                   ast_log(LOG_WARNING, "Unable to send text\n");
00681             } else if (f->frametype == AST_FRAME_HTML && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML)) {
00682                if (ast_channel_sendhtml(in, f->subclass, f->data, f->datalen) == -1)
00683                   ast_log(LOG_WARNING, "Unable to send URL\n");
00684             }
00685          }
00686          ast_frfree(f);
00687       } /* end for */
00688       if (winner == in) {
00689          struct ast_frame *f = ast_read(in);
00690 #if 0
00691          if (f && (f->frametype != AST_FRAME_VOICE))
00692             printf("Frame type: %d, %d\n", f->frametype, f->subclass);
00693          else if (!f || (f->frametype != AST_FRAME_VOICE))
00694             printf("Hangup received on %s\n", in->name);
00695 #endif
00696          if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP))) {
00697             /* Got hung up */
00698             *to = -1;
00699             strcpy(status, "CANCEL");
00700             if (f)
00701                ast_frfree(f);
00702             return NULL;
00703          }
00704 
00705          if (f && (f->frametype == AST_FRAME_DTMF)) {
00706             if (ast_test_flag(peerflags, OPT_DTMF_EXIT)) {
00707                const char *context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
00708                if (onedigit_goto(in, context, (char) f->subclass, 1)) {
00709                   if (option_verbose > 2)
00710                      ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
00711                   *to=0;
00712                   *result = f->subclass;
00713                   strcpy(status, "CANCEL");
00714                   ast_frfree(f);
00715                   return NULL;
00716                }
00717             }
00718 
00719             if (ast_test_flag(peerflags, OPT_CALLER_HANGUP) && 
00720                     (f->subclass == '*')) { /* hmm it it not guaranteed to be '*' anymore. */
00721                if (option_verbose > 2)
00722                   ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
00723                *to=0;
00724                strcpy(status, "CANCEL");
00725                ast_frfree(f);
00726                return NULL;
00727             }
00728          }
00729 
00730          /* Forward HTML stuff */
00731          if (single && f && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML)) 
00732             if(ast_channel_sendhtml(outgoing->chan, f->subclass, f->data, f->datalen) == -1)
00733                ast_log(LOG_WARNING, "Unable to send URL\n");
00734          
00735 
00736          if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF_BEGIN) || (f->frametype == AST_FRAME_DTMF_END)))  {
00737             if (ast_write(outgoing->chan, f))
00738                ast_log(LOG_WARNING, "Unable to forward voice or dtmf\n");
00739          }
00740          if (single && (f->frametype == AST_FRAME_CONTROL) && 
00741             ((f->subclass == AST_CONTROL_HOLD) || 
00742              (f->subclass == AST_CONTROL_UNHOLD) || 
00743              (f->subclass == AST_CONTROL_VIDUPDATE))) {
00744             if (option_verbose > 2)
00745                ast_verbose(VERBOSE_PREFIX_3 "%s requested special control %d, passing it to %s\n", in->name, f->subclass, outgoing->chan->name);
00746             ast_indicate_data(outgoing->chan, f->subclass, f->data, f->datalen);
00747          }
00748          ast_frfree(f);
00749       }
00750       if (!*to && (option_verbose > 2))
00751          ast_verbose(VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
00752    }
00753 
00754    return peer;
00755 }


Variable Documentation

char* app = "Dial" [static]

Definition at line 64 of file app_dial.c.

char* descrip [static]

Definition at line 68 of file app_dial.c.

enum { ... } dial_exec_option_args

enum { ... } dial_exec_option_flags

char* rapp = "RetryDial" [static]

Definition at line 200 of file app_dial.c.

char* rdescrip [static]

Definition at line 202 of file app_dial.c.

char* rsynopsis = "Place a call, retrying on failure allowing optional exit extension." [static]

Definition at line 201 of file app_dial.c.

char* synopsis = "Place a call and connect to the current channel" [static]

Definition at line 66 of file app_dial.c.


Generated on Mon May 14 04:43:24 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1