app_dial.c File Reference

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

#include "asterisk.h"
#include <sys/time.h>
#include <sys/signal.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.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_engine.h"
#include "asterisk/manager.h"
#include "asterisk/privacy.h"
#include "asterisk/stringfields.h"
#include "asterisk/global_datastores.h"
#include "asterisk/dsp.h"
#include "asterisk/aoc.h"
#include "asterisk/ccss.h"
#include "asterisk/indications.h"
#include "asterisk/framehook.h"
#include "asterisk/dial.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/bridge_after.h"
#include "asterisk/features_config.h"

Include dependency graph for app_dial.c:

Go to the source code of this file.

Data Structures

struct  cause_args
struct  chanlist
 List of channel drivers. More...
struct  dial_head
struct  privacy_args

Defines

#define AST_MAX_WATCHERS   256
#define CAN_EARLY_BRIDGE(flags, chan, peer)
#define DIAL_CALLERID_ABSENT   (1LLU << 33)
#define DIAL_NOFORWARDHTML   (1LLU << 32)
#define DIAL_STILLGOING   (1LLU << 31)
#define OPT_CALLEE_GO_ON   (1LLU << 36)
#define OPT_CALLER_ANSWER   (1LLU << 40)
#define OPT_CANCEL_ELSEWHERE   (1LLU << 34)
#define OPT_CANCEL_TIMEOUT   (1LLU << 37)
#define OPT_FORCE_CID_PRES   (1LLU << 39)
#define OPT_FORCE_CID_TAG   (1LLU << 38)
#define OPT_PEER_H   (1LLU << 35)
#define OPT_PREDIAL_CALLEE   (1LLU << 41)
#define OPT_PREDIAL_CALLER   (1LLU << 42)
#define OPT_RING_WITH_EARLY_MEDIA   (1LLU << 43)

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_ORIGINAL_CLID = (1 << 8), OPT_DURATION_LIMIT = (1 << 9), OPT_MUSICBACK = (1 << 10), OPT_CALLEE_MACRO = (1 << 11),
  OPT_SCREEN_NOINTRO = (1 << 12), OPT_SCREEN_NOCALLERID = (1 << 13), OPT_IGNORE_CONNECTEDLINE = (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),
  OPT_CALLEE_GOSUB = (1 << 28), OPT_CALLEE_MIXMONITOR = (1 << 29), OPT_CALLER_MIXMONITOR = (1 << 30)
}
enum  {
  OPT_ARG_ANNOUNCE = 0, OPT_ARG_SENDDTMF, OPT_ARG_GOTO, OPT_ARG_DURATION_LIMIT,
  OPT_ARG_MUSICBACK, OPT_ARG_CALLEE_MACRO, OPT_ARG_RINGBACK, OPT_ARG_CALLEE_GOSUB,
  OPT_ARG_CALLEE_GO_ON, OPT_ARG_PRIVACY, OPT_ARG_DURATION_STOP, OPT_ARG_OPERMODE,
  OPT_ARG_SCREEN_NOINTRO, OPT_ARG_ORIGINAL_CLID, OPT_ARG_FORCECLID, OPT_ARG_FORCE_CID_TAG,
  OPT_ARG_FORCE_CID_PRES, OPT_ARG_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLER, OPT_ARG_ARRAY_SIZE
}

Functions

static void __reg_module (void)
static void __unreg_module (void)
static void chanlist_free (struct chanlist *outgoing)
static int detect_disconnect (struct ast_channel *chan, char code, struct ast_str **featurecode)
static int dial_exec (struct ast_channel *chan, const char *data)
static int dial_exec_full (struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
static int dial_handle_playtones (struct ast_channel *chan, const char *data)
static void do_forward (struct chanlist *o, struct cause_args *num, struct ast_flags64 *peerflags, int single, int caller_entertained, int *to, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
static void end_bridge_callback (void *data)
static void end_bridge_callback_data_fixup (struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
static const char * get_cid_name (char *name, int namelen, struct ast_channel *chan)
static void handle_cause (int cause, struct cause_args *num)
static void hanguptree (struct dial_head *out_chans, struct ast_channel *exception, int answered_elsewhere)
static int load_module (void)
static int onedigit_goto (struct ast_channel *chan, const char *context, char exten, int pri)
static void publish_dial_end_event (struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
static int retrydial_exec (struct ast_channel *chan, const char *data)
static void setup_peer_after_bridge_goto (struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
static int setup_privacy_args (struct privacy_args *pa, struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
 returns 1 if successful, 0 or <0 if the caller should 'goto out'
static int unload_module (void)
static int valid_priv_reply (struct ast_flags64 *opts, int res)
static struct ast_channelwait_for_answer (struct ast_channel *in, struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags, char *opt_args[], struct privacy_args *pa, const struct cause_args *num_in, int *result, char *dtmf_progress, const int ignore_cc, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Dialing Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static const char app [] = "Dial"
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_app_option dial_exec_options [128] = { [ 'A' ] = { .flag = OPT_ANNOUNCE , .arg_index = OPT_ARG_ANNOUNCE + 1 }, [ 'a' ] = { .flag = (1LLU << 40) }, [ 'b' ] = { .flag = (1LLU << 41) , .arg_index = OPT_ARG_PREDIAL_CALLEE + 1 }, [ 'B' ] = { .flag = (1LLU << 42) , .arg_index = OPT_ARG_PREDIAL_CALLER + 1 }, [ 'C' ] = { .flag = OPT_RESETCDR }, [ 'c' ] = { .flag = (1LLU << 34) }, [ 'd' ] = { .flag = OPT_DTMF_EXIT }, [ 'D' ] = { .flag = OPT_SENDDTMF , .arg_index = OPT_ARG_SENDDTMF + 1 }, [ 'e' ] = { .flag = (1LLU << 35) }, [ 'f' ] = { .flag = OPT_FORCECLID , .arg_index = OPT_ARG_FORCECLID + 1 }, [ 'F' ] = { .flag = (1LLU << 36) , .arg_index = OPT_ARG_CALLEE_GO_ON + 1 }, [ 'g' ] = { .flag = OPT_GO_ON }, [ 'G' ] = { .flag = OPT_GOTO , .arg_index = OPT_ARG_GOTO + 1 }, [ 'h' ] = { .flag = OPT_CALLEE_HANGUP }, [ 'H' ] = { .flag = OPT_CALLER_HANGUP }, [ 'i' ] = { .flag = OPT_IGNORE_FORWARDING }, [ 'I' ] = { .flag = OPT_IGNORE_CONNECTEDLINE }, [ 'k' ] = { .flag = OPT_CALLEE_PARK }, [ 'K' ] = { .flag = OPT_CALLER_PARK }, [ 'L' ] = { .flag = OPT_DURATION_LIMIT , .arg_index = OPT_ARG_DURATION_LIMIT + 1 }, [ 'm' ] = { .flag = OPT_MUSICBACK , .arg_index = OPT_ARG_MUSICBACK + 1 }, [ 'M' ] = { .flag = OPT_CALLEE_MACRO , .arg_index = OPT_ARG_CALLEE_MACRO + 1 }, [ 'n' ] = { .flag = OPT_SCREEN_NOINTRO , .arg_index = OPT_ARG_SCREEN_NOINTRO + 1 }, [ 'N' ] = { .flag = OPT_SCREEN_NOCALLERID }, [ 'o' ] = { .flag = OPT_ORIGINAL_CLID , .arg_index = OPT_ARG_ORIGINAL_CLID + 1 }, [ 'O' ] = { .flag = OPT_OPERMODE , .arg_index = OPT_ARG_OPERMODE + 1 }, [ 'p' ] = { .flag = OPT_SCREENING }, [ 'P' ] = { .flag = OPT_PRIVACY , .arg_index = OPT_ARG_PRIVACY + 1 }, [ 'r' ] = { .flag = OPT_RINGBACK , .arg_index = OPT_ARG_RINGBACK + 1 }, [ 'R' ] = { .flag = (1LLU << 43) }, [ 'S' ] = { .flag = OPT_DURATION_STOP , .arg_index = OPT_ARG_DURATION_STOP + 1 }, [ 's' ] = { .flag = (1LLU << 38) , .arg_index = OPT_ARG_FORCE_CID_TAG + 1 }, [ 't' ] = { .flag = OPT_CALLEE_TRANSFER }, [ 'T' ] = { .flag = OPT_CALLER_TRANSFER }, [ 'u' ] = { .flag = (1LLU << 39) , .arg_index = OPT_ARG_FORCE_CID_PRES + 1 }, [ 'U' ] = { .flag = OPT_CALLEE_GOSUB , .arg_index = OPT_ARG_CALLEE_GOSUB + 1 }, [ 'w' ] = { .flag = OPT_CALLEE_MONITOR }, [ 'W' ] = { .flag = OPT_CALLER_MONITOR }, [ 'x' ] = { .flag = OPT_CALLEE_MIXMONITOR }, [ 'X' ] = { .flag = OPT_CALLER_MIXMONITOR }, [ 'z' ] = { .flag = (1LLU << 37) }, }
static const char rapp [] = "RetryDial"


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_WATCHERS   256

Definition at line 746 of file app_dial.c.

Referenced by monitor_dial(), and wait_for_answer().

#define CAN_EARLY_BRIDGE ( flags,
chan,
peer   ) 

Definition at line 688 of file app_dial.c.

Referenced by dial_exec_full(), do_forward(), and wait_for_answer().

#define DIAL_CALLERID_ABSENT   (1LLU << 33)

Definition at line 608 of file app_dial.c.

Referenced by dial_exec_full(), do_forward(), and wait_for_answer().

#define DIAL_NOFORWARDHTML   (1LLU << 32)

Definition at line 607 of file app_dial.c.

Referenced by dial_exec_full(), and wait_for_answer().

#define DIAL_STILLGOING   (1LLU << 31)

Definition at line 606 of file app_dial.c.

Referenced by dial_exec_full(), do_forward(), and wait_for_answer().

#define OPT_CALLEE_GO_ON   (1LLU << 36)

Definition at line 611 of file app_dial.c.

Referenced by bridge_exec(), and setup_peer_after_bridge_goto().

#define OPT_CALLER_ANSWER   (1LLU << 40)

Definition at line 615 of file app_dial.c.

Referenced by dial_exec_full().

#define OPT_CANCEL_ELSEWHERE   (1LLU << 34)

Definition at line 609 of file app_dial.c.

Referenced by dial_exec_full().

#define OPT_CANCEL_TIMEOUT   (1LLU << 37)

Definition at line 612 of file app_dial.c.

Referenced by dial_exec_full(), and do_forward().

#define OPT_FORCE_CID_PRES   (1LLU << 39)

Definition at line 614 of file app_dial.c.

Referenced by dial_exec_full().

#define OPT_FORCE_CID_TAG   (1LLU << 38)

Definition at line 613 of file app_dial.c.

Referenced by dial_exec_full().

#define OPT_PEER_H   (1LLU << 35)

Definition at line 610 of file app_dial.c.

Referenced by setup_peer_after_bridge_goto().

#define OPT_PREDIAL_CALLEE   (1LLU << 41)

Definition at line 616 of file app_dial.c.

Referenced by dial_exec_full().

#define OPT_PREDIAL_CALLER   (1LLU << 42)

Definition at line 617 of file app_dial.c.

Referenced by dial_exec_full().

#define OPT_RING_WITH_EARLY_MEDIA   (1LLU << 43)

Definition at line 618 of file app_dial.c.

Referenced by dial_exec_full().


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_ORIGINAL_CLID 
OPT_DURATION_LIMIT 
OPT_MUSICBACK 
OPT_CALLEE_MACRO 
OPT_SCREEN_NOINTRO 
OPT_SCREEN_NOCALLERID 
OPT_IGNORE_CONNECTEDLINE 
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 
OPT_CALLEE_GOSUB 
OPT_CALLEE_MIXMONITOR 
OPT_CALLER_MIXMONITOR 

Definition at line 571 of file app_dial.c.

00571      {
00572    OPT_ANNOUNCE =          (1 << 0),
00573    OPT_RESETCDR =          (1 << 1),
00574    OPT_DTMF_EXIT =         (1 << 2),
00575    OPT_SENDDTMF =          (1 << 3),
00576    OPT_FORCECLID =         (1 << 4),
00577    OPT_GO_ON =             (1 << 5),
00578    OPT_CALLEE_HANGUP =     (1 << 6),
00579    OPT_CALLER_HANGUP =     (1 << 7),
00580    OPT_ORIGINAL_CLID =     (1 << 8),
00581    OPT_DURATION_LIMIT =    (1 << 9),
00582    OPT_MUSICBACK =         (1 << 10),
00583    OPT_CALLEE_MACRO =      (1 << 11),
00584    OPT_SCREEN_NOINTRO =    (1 << 12),
00585    OPT_SCREEN_NOCALLERID = (1 << 13),
00586    OPT_IGNORE_CONNECTEDLINE = (1 << 14),
00587    OPT_SCREENING =         (1 << 15),
00588    OPT_PRIVACY =           (1 << 16),
00589    OPT_RINGBACK =          (1 << 17),
00590    OPT_DURATION_STOP =     (1 << 18),
00591    OPT_CALLEE_TRANSFER =   (1 << 19),
00592    OPT_CALLER_TRANSFER =   (1 << 20),
00593    OPT_CALLEE_MONITOR =    (1 << 21),
00594    OPT_CALLER_MONITOR =    (1 << 22),
00595    OPT_GOTO =              (1 << 23),
00596    OPT_OPERMODE =          (1 << 24),
00597    OPT_CALLEE_PARK =       (1 << 25),
00598    OPT_CALLER_PARK =       (1 << 26),
00599    OPT_IGNORE_FORWARDING = (1 << 27),
00600    OPT_CALLEE_GOSUB =      (1 << 28),
00601    OPT_CALLEE_MIXMONITOR = (1 << 29),
00602    OPT_CALLER_MIXMONITOR = (1 << 30),
00603 };

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_RINGBACK 
OPT_ARG_CALLEE_GOSUB 
OPT_ARG_CALLEE_GO_ON 
OPT_ARG_PRIVACY 
OPT_ARG_DURATION_STOP 
OPT_ARG_OPERMODE 
OPT_ARG_SCREEN_NOINTRO 
OPT_ARG_ORIGINAL_CLID 
OPT_ARG_FORCECLID 
OPT_ARG_FORCE_CID_TAG 
OPT_ARG_FORCE_CID_PRES 
OPT_ARG_PREDIAL_CALLEE 
OPT_ARG_PREDIAL_CALLER 
OPT_ARG_ARRAY_SIZE 

Definition at line 620 of file app_dial.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 3264 of file app_dial.c.

static void __unreg_module ( void   )  [static]

Definition at line 3264 of file app_dial.c.

static void chanlist_free ( struct chanlist outgoing  )  [static]

Definition at line 721 of file app_dial.c.

References ast_aoc_destroy_decoded(), ast_free, and ast_party_connected_line_free().

Referenced by dial_exec_full(), and hanguptree().

00722 {
00723    ast_party_connected_line_free(&outgoing->connected);
00724    ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
00725    ast_free(outgoing);
00726 }

static int detect_disconnect ( struct ast_channel chan,
char  code,
struct ast_str **  featurecode 
) [static]

Definition at line 1678 of file app_dial.c.

References AST_FEATURE_MAX_LEN, ast_get_builtin_feature(), ast_str_append(), ast_str_buffer(), ast_str_reset(), and ast_str_strlen().

Referenced by wait_for_answer().

01679 {
01680    char disconnect_code[AST_FEATURE_MAX_LEN];
01681    int res;
01682 
01683    ast_str_append(featurecode, 1, "%c", code);
01684 
01685    res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
01686    if (res) {
01687       ast_str_reset(*featurecode);
01688       return 0;
01689    }
01690 
01691    if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
01692       /* Could be a partial match, anyway */
01693       if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
01694          ast_str_reset(*featurecode);
01695       }
01696       return 0;
01697    }
01698 
01699    if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
01700       ast_str_reset(*featurecode);
01701       return 0;
01702    }
01703 
01704    return 1;
01705 }

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

Definition at line 3127 of file app_dial.c.

References dial_exec_full(), and NULL.

Referenced by load_module().

03128 {
03129    struct ast_flags64 peerflags;
03130 
03131    memset(&peerflags, 0, sizeof(peerflags));
03132 
03133    return dial_exec_full(chan, data, &peerflags, NULL);
03134 }

static int dial_exec_full ( struct ast_channel chan,
const char *  data,
struct ast_flags64 peerflags,
int *  continue_exec 
) [static]

< TRUE if force CallerID on call forward only. Legacy behaviour.

Forced CallerID party information to send.

Note:
This will not have any malloced strings so do not free it.
Stored CallerID information if needed.

Note:
If OPT_ORIGINAL_CLID set then this is the o option CallerID. Otherwise it is the dialplan extension and hint name.

This will not have any malloced strings so do not free it.

CallerID party information to store.
Note:
This will not have any malloced strings so do not free it.

Definition at line 2043 of file app_dial.c.

References args, ast_answer(), AST_APP_ARG, ast_app_exec_macro(), ast_app_exec_sub(), ast_app_expand_sub_args(), ast_app_group_set_channel(), ast_app_parse_options64(), ast_asprintf, ast_autoservice_chan_hangup_peer(), ast_autoservice_start(), ast_autoservice_stop(), ast_bridge_call(), ast_bridge_setup_after_goto(), ast_bridge_timelimit(), ast_call(), ast_callerid_parse(), ast_calloc, ast_cause2str(), AST_CAUSE_ANSWERED_ELSEWHERE, AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, ast_cc_busy_interface(), ast_cc_call_failed(), ast_cc_call_init(), ast_cc_callback(), ast_cc_extension_monitor_add_dialstring(), ast_cdr_reset(), ast_channel_adsicpe_set(), ast_channel_appl_set(), ast_channel_caller(), ast_channel_connected(), ast_channel_context(), ast_channel_context_set(), ast_channel_data_set(), ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_inherit(), ast_channel_datastore_remove(), ast_channel_dialed(), ast_channel_early_bridge(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_get_device_name(), ast_channel_hangupcause(), ast_channel_hangupcause_set(), ast_channel_inherit_variables(), ast_channel_language(), ast_channel_lock, ast_channel_lock_both, ast_channel_macrocontext(), ast_channel_macroexten(), ast_channel_make_compatible(), ast_channel_musicclass(), ast_channel_name(), AST_CHANNEL_NAME, ast_channel_nativeformats(), ast_channel_priority(), ast_channel_priority_set(), ast_channel_publish_dial(), ast_channel_publish_snapshot(), ast_channel_redirecting(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_sched(), ast_channel_sendurl(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_setoption(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_stream(), ast_channel_supports_html(), ast_channel_timingfunc(), ast_channel_transfercapability(), ast_channel_transfercapability_set(), ast_channel_unlock, ast_channel_visible_indication_set(), ast_channel_whentohangup(), ast_channel_whentohangup_set(), ast_check_hangup(), ast_clear_flag, ast_connected_line_copy_from_caller(), AST_CONTROL_HANGUP, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, ast_copy_flags64, ast_copy_string(), ast_datastore_alloc, ast_datastore_free(), ast_deactivate_generator(), ast_debug, AST_DECLARE_APP_ARGS, AST_DIGIT_ANY, ast_dtmf_stream(), ast_exists_extension(), AST_FEATURE_AUTOMIXMON, AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, ast_filedelete(), ast_fileexists(), AST_FLAG_END_DTMF_ONLY, AST_FLAG_OUTGOING, AST_FRAME_CONTROL, AST_FRAME_DTMF_END, ast_free, ast_frfree, ast_hangup(), ast_ignore_cc(), ast_indicate(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD, AST_LIST_HEAD_INIT, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log, AST_MAX_EXTENSION, ast_moh_start(), ast_moh_stop(), AST_OPTION_OPRMODE, ast_parse_caller_presentation(), ast_parseable_goto(), ast_party_caller_set_init(), ast_party_connected_line_copy(), ast_party_connected_line_set_init(), ast_party_id_init(), ast_party_id_set_init(), ast_party_redirecting_copy(), AST_PBX_INCOMPLETE, ast_pbx_start(), ast_pre_call(), AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, AST_PRIVACY_UNKNOWN, ast_read(), ast_replace_subargument_delimiter(), ast_request(), ast_rtp_instance_early_bridge_make_compatible(), ast_sched_runq(), ast_sched_wait(), ast_senddigit(), ast_set2_flag64, ast_set_flag, ast_set_flag64, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero, ast_test_flag64, ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_verb, ast_waitfor_n(), CAN_EARLY_BRIDGE, chanlist::chan, chanlist_free(), chanlist::connected, ast_datastore::data, DATASTORE_INHERIT_FOREVER, di, DIAL_CALLERID_ABSENT, dial_exec_options, dial_handle_playtones(), DIAL_NOFORWARDHTML, DIAL_STILLGOING, dialed_interface_info, digit, end_bridge_callback(), ast_bridge_config::end_bridge_callback, ast_bridge_config::end_bridge_callback_data, end_bridge_callback_data_fixup(), ast_bridge_config::end_bridge_callback_data_fixup, ast_bridge_config::end_sound, ast_bridge_config::features_callee, ast_bridge_config::features_caller, ast_flags64::flags, ast_frame::frametype, get_cid_name(), handle_cause(), hanguptree(), ast_party_connected_line::id, ast_party_caller::id, ast_datastore::inheritance, ast_frame_subclass::integer, ast_dialed_interface::interface, chanlist::interface, chanlist::list, LOG_ERROR, LOG_NOTICE, LOG_WARNING, oprmode::mode, name, ast_party_id::name, NULL, chanlist::number, ast_party_id::number, OPT_ANNOUNCE, OPT_ARG_ANNOUNCE, OPT_ARG_ARRAY_SIZE, OPT_ARG_CALLEE_GOSUB, OPT_ARG_CALLEE_MACRO, OPT_ARG_DURATION_LIMIT, OPT_ARG_DURATION_STOP, OPT_ARG_FORCE_CID_PRES, OPT_ARG_FORCE_CID_TAG, OPT_ARG_FORCECLID, OPT_ARG_GOTO, OPT_ARG_OPERMODE, OPT_ARG_ORIGINAL_CLID, OPT_ARG_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLER, OPT_ARG_PRIVACY, OPT_ARG_RINGBACK, OPT_ARG_SCREEN_NOINTRO, OPT_ARG_SENDDTMF, OPT_CALLEE_GOSUB, OPT_CALLEE_HANGUP, OPT_CALLEE_MACRO, OPT_CALLEE_MIXMONITOR, OPT_CALLEE_MONITOR, OPT_CALLEE_PARK, OPT_CALLEE_TRANSFER, OPT_CALLER_ANSWER, OPT_CALLER_HANGUP, OPT_CALLER_MIXMONITOR, OPT_CALLER_MONITOR, OPT_CALLER_PARK, OPT_CALLER_TRANSFER, OPT_CANCEL_ELSEWHERE, OPT_CANCEL_TIMEOUT, OPT_DTMF_EXIT, OPT_DURATION_LIMIT, OPT_DURATION_STOP, OPT_FORCE_CID_PRES, OPT_FORCE_CID_TAG, OPT_FORCECLID, OPT_GO_ON, OPT_GOTO, OPT_IGNORE_CONNECTEDLINE, OPT_IGNORE_FORWARDING, OPT_MUSICBACK, OPT_OPERMODE, OPT_ORIGINAL_CLID, OPT_PREDIAL_CALLEE, OPT_PREDIAL_CALLER, OPT_PRIVACY, OPT_RESETCDR, OPT_RING_WITH_EARLY_MEDIA, OPT_RINGBACK, OPT_SCREEN_NOINTRO, OPT_SCREENING, OPT_SENDDTMF, out, parse(), pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), oprmode::peer, ast_party_number::presentation, privacy_args::privdb_val, privacy_args::privintro, result, S_COR, S_OR, privacy_args::sentringing, setup_peer_after_bridge_goto(), setup_privacy_args(), ast_bridge_config::start_sound, privacy_args::status, ast_party_subaddress::str, ast_party_name::str, ast_party_number::str, strsep(), chanlist::stuff, ast_party_id::subaddress, ast_frame::subclass, ast_party_id::tag, chanlist::tech, timeout, tmp(), ast_party_dialed::transit_network_select, url, ast_party_number::valid, ast_party_name::valid, wait_for_answer(), and ast_bridge_config::warning_sound.

Referenced by dial_exec(), and retrydial_exec().

02044 {
02045    int res = -1; /* default: error */
02046    char *rest, *cur; /* scan the list of destinations */
02047    struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
02048    struct chanlist *outgoing;
02049    struct chanlist *tmp;
02050    struct ast_channel *peer;
02051    int to; /* timeout */
02052    struct cause_args num = { chan, 0, 0, 0 };
02053    int cause;
02054 
02055    struct ast_bridge_config config = { { 0, } };
02056    struct timeval calldurationlimit = { 0, };
02057    char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
02058    struct privacy_args pa = {
02059       .sentringing = 0,
02060       .privdb_val = 0,
02061       .status = "INVALIDARGS",
02062    };
02063    int sentringing = 0, moh = 0;
02064    const char *outbound_group = NULL;
02065    int result = 0;
02066    char *parse;
02067    int opermode = 0;
02068    int delprivintro = 0;
02069    AST_DECLARE_APP_ARGS(args,
02070       AST_APP_ARG(peers);
02071       AST_APP_ARG(timeout);
02072       AST_APP_ARG(options);
02073       AST_APP_ARG(url);
02074    );
02075    struct ast_flags64 opts = { 0, };
02076    char *opt_args[OPT_ARG_ARRAY_SIZE];
02077    struct ast_datastore *datastore = NULL;
02078    int fulldial = 0, num_dialed = 0;
02079    int ignore_cc = 0;
02080    char device_name[AST_CHANNEL_NAME];
02081    char forced_clid_name[AST_MAX_EXTENSION];
02082    char stored_clid_name[AST_MAX_EXTENSION];
02083    int force_forwards_only;   /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
02084    /*!
02085     * \brief Forced CallerID party information to send.
02086     * \note This will not have any malloced strings so do not free it.
02087     */
02088    struct ast_party_id forced_clid;
02089    /*!
02090     * \brief Stored CallerID information if needed.
02091     *
02092     * \note If OPT_ORIGINAL_CLID set then this is the o option
02093     * CallerID.  Otherwise it is the dialplan extension and hint
02094     * name.
02095     *
02096     * \note This will not have any malloced strings so do not free it.
02097     */
02098    struct ast_party_id stored_clid;
02099    /*!
02100     * \brief CallerID party information to store.
02101     * \note This will not have any malloced strings so do not free it.
02102     */
02103    struct ast_party_caller caller;
02104 
02105    /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
02106    ast_channel_lock(chan);
02107    ast_channel_stage_snapshot(chan);
02108    pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
02109    pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
02110    pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
02111    pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
02112    pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
02113    ast_channel_stage_snapshot_done(chan);
02114    ast_channel_unlock(chan);
02115 
02116    if (ast_strlen_zero(data)) {
02117       ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
02118       pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02119       return -1;
02120    }
02121 
02122    parse = ast_strdupa(data);
02123 
02124    AST_STANDARD_APP_ARGS(args, parse);
02125 
02126    if (!ast_strlen_zero(args.options) &&
02127       ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
02128       pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02129       goto done;
02130    }
02131 
02132    if (ast_strlen_zero(args.peers)) {
02133       ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
02134       pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02135       goto done;
02136    }
02137 
02138    if (ast_cc_call_init(chan, &ignore_cc)) {
02139       goto done;
02140    }
02141 
02142    if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
02143       delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
02144 
02145       if (delprivintro < 0 || delprivintro > 1) {
02146          ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
02147          delprivintro = 0;
02148       }
02149    }
02150 
02151    if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
02152       opt_args[OPT_ARG_RINGBACK] = NULL;
02153    }
02154 
02155    if (ast_test_flag64(&opts, OPT_OPERMODE)) {
02156       opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
02157       ast_verb(3, "Setting operator services mode to %d.\n", opermode);
02158    }
02159 
02160    if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
02161       calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
02162       if (!calldurationlimit.tv_sec) {
02163          ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
02164          pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02165          goto done;
02166       }
02167       ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
02168    }
02169 
02170    if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
02171       dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
02172       dtmfcalled = strsep(&dtmf_progress, ":");
02173       dtmfcalling = strsep(&dtmf_progress, ":");
02174    }
02175 
02176    if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
02177       if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
02178          goto done;
02179    }
02180 
02181    /* Setup the forced CallerID information to send if used. */
02182    ast_party_id_init(&forced_clid);
02183    force_forwards_only = 0;
02184    if (ast_test_flag64(&opts, OPT_FORCECLID)) {
02185       if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
02186          ast_channel_lock(chan);
02187          forced_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
02188          ast_channel_unlock(chan);
02189          forced_clid_name[0] = '\0';
02190          forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
02191             sizeof(forced_clid_name), chan);
02192          force_forwards_only = 1;
02193       } else {
02194          /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
02195          ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
02196             &forced_clid.number.str);
02197       }
02198       if (!ast_strlen_zero(forced_clid.name.str)) {
02199          forced_clid.name.valid = 1;
02200       }
02201       if (!ast_strlen_zero(forced_clid.number.str)) {
02202          forced_clid.number.valid = 1;
02203       }
02204    }
02205    if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG)
02206       && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
02207       forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
02208    }
02209    forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
02210    if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES)
02211       && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
02212       int pres;
02213 
02214       pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
02215       if (0 <= pres) {
02216          forced_clid.number.presentation = pres;
02217       }
02218    }
02219 
02220    /* Setup the stored CallerID information if needed. */
02221    ast_party_id_init(&stored_clid);
02222    if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
02223       if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
02224          ast_channel_lock(chan);
02225          ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
02226          if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
02227             stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
02228          }
02229          if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
02230             stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
02231          }
02232          if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
02233             stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
02234          }
02235          if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
02236             stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
02237          }
02238          ast_channel_unlock(chan);
02239       } else {
02240          /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
02241          ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
02242             &stored_clid.number.str);
02243          if (!ast_strlen_zero(stored_clid.name.str)) {
02244             stored_clid.name.valid = 1;
02245          }
02246          if (!ast_strlen_zero(stored_clid.number.str)) {
02247             stored_clid.number.valid = 1;
02248          }
02249       }
02250    } else {
02251       /*
02252        * In case the new channel has no preset CallerID number by the
02253        * channel driver, setup the dialplan extension and hint name.
02254        */
02255       stored_clid_name[0] = '\0';
02256       stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
02257          sizeof(stored_clid_name), chan);
02258       if (ast_strlen_zero(stored_clid.name.str)) {
02259          stored_clid.name.str = NULL;
02260       } else {
02261          stored_clid.name.valid = 1;
02262       }
02263       ast_channel_lock(chan);
02264       stored_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
02265       stored_clid.number.valid = 1;
02266       ast_channel_unlock(chan);
02267    }
02268 
02269    if (ast_test_flag64(&opts, OPT_RESETCDR)) {
02270       ast_cdr_reset(ast_channel_name(chan), 0);
02271    }
02272    if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
02273       opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan));
02274 
02275    if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
02276       res = setup_privacy_args(&pa, &opts, opt_args, chan);
02277       if (res <= 0)
02278          goto out;
02279       res = -1; /* reset default */
02280    }
02281 
02282    if (continue_exec)
02283       *continue_exec = 0;
02284 
02285    /* If a channel group has been specified, get it for use when we create peer channels */
02286 
02287    ast_channel_lock(chan);
02288    if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
02289       outbound_group = ast_strdupa(outbound_group);
02290       pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
02291    } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
02292       outbound_group = ast_strdupa(outbound_group);
02293    }
02294    ast_channel_unlock(chan);
02295 
02296    /* Set per dial instance flags.  These flags are also passed back to RetryDial. */
02297    ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID
02298       | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_CANCEL_TIMEOUT
02299       | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
02300 
02301    /* PREDIAL: Run gosub on the caller's channel */
02302    if (ast_test_flag64(&opts, OPT_PREDIAL_CALLER)
02303       && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
02304       ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
02305       ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
02306    }
02307 
02308    /* loop through the list of dial destinations */
02309    rest = args.peers;
02310    while ((cur = strsep(&rest, "&")) ) {
02311       struct ast_channel *tc; /* channel for this destination */
02312       /* Get a technology/resource pair */
02313       char *number = cur;
02314       char *tech = strsep(&number, "/");
02315       size_t tech_len;
02316       size_t number_len;
02317       /* find if we already dialed this interface */
02318       struct ast_dialed_interface *di;
02319       AST_LIST_HEAD(,ast_dialed_interface) *dialed_interfaces;
02320 
02321       num_dialed++;
02322       if (ast_strlen_zero(number)) {
02323          ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
02324          goto out;
02325       }
02326 
02327       tech_len = strlen(tech) + 1;
02328       number_len = strlen(number) + 1;
02329       tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
02330       if (!tmp) {
02331          goto out;
02332       }
02333 
02334       /* Save tech, number, and interface. */
02335       cur = tmp->stuff;
02336       strcpy(cur, tech);
02337       tmp->tech = cur;
02338       cur += tech_len;
02339       strcpy(cur, tech);
02340       cur[tech_len - 1] = '/';
02341       tmp->interface = cur;
02342       cur += tech_len;
02343       strcpy(cur, number);
02344       tmp->number = cur;
02345 
02346       if (opts.flags) {
02347          /* Set per outgoing call leg options. */
02348          ast_copy_flags64(tmp, &opts,
02349             OPT_CANCEL_ELSEWHERE |
02350             OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
02351             OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
02352             OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
02353             OPT_CALLEE_PARK | OPT_CALLER_PARK |
02354             OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
02355             OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID | OPT_IGNORE_CONNECTEDLINE |
02356             OPT_RING_WITH_EARLY_MEDIA);
02357          ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
02358       }
02359 
02360       /* Request the peer */
02361 
02362       ast_channel_lock(chan);
02363       datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL);
02364       /*
02365        * Seed the chanlist's connected line information with previously
02366        * acquired connected line info from the incoming channel.  The
02367        * previously acquired connected line info could have been set
02368        * through the CONNECTED_LINE dialplan function.
02369        */
02370       ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan));
02371       ast_channel_unlock(chan);
02372 
02373       if (datastore)
02374          dialed_interfaces = datastore->data;
02375       else {
02376          if (!(datastore = ast_datastore_alloc(&dialed_interface_info, NULL))) {
02377             ast_log(LOG_WARNING, "Unable to create channel datastore for dialed interfaces. Aborting!\n");
02378             chanlist_free(tmp);
02379             goto out;
02380          }
02381          datastore->inheritance = DATASTORE_INHERIT_FOREVER;
02382 
02383          if (!(dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces)))) {
02384             ast_datastore_free(datastore);
02385             chanlist_free(tmp);
02386             goto out;
02387          }
02388 
02389          datastore->data = dialed_interfaces;
02390          AST_LIST_HEAD_INIT(dialed_interfaces);
02391 
02392          ast_channel_lock(chan);
02393          ast_channel_datastore_add(chan, datastore);
02394          ast_channel_unlock(chan);
02395       }
02396 
02397       AST_LIST_LOCK(dialed_interfaces);
02398       AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
02399          if (!strcasecmp(di->interface, tmp->interface)) {
02400             ast_log(LOG_WARNING, "Skipping dialing interface '%s' again since it has already been dialed\n",
02401                di->interface);
02402             break;
02403          }
02404       }
02405       AST_LIST_UNLOCK(dialed_interfaces);
02406       if (di) {
02407          fulldial++;
02408          chanlist_free(tmp);
02409          continue;
02410       }
02411 
02412       /* It is always ok to dial a Local interface.  We only keep track of
02413        * which "real" interfaces have been dialed.  The Local channel will
02414        * inherit this list so that if it ends up dialing a real interface,
02415        * it won't call one that has already been called. */
02416       if (strcasecmp(tmp->tech, "Local")) {
02417          if (!(di = ast_calloc(1, sizeof(*di) + strlen(tmp->interface)))) {
02418             chanlist_free(tmp);
02419             goto out;
02420          }
02421          strcpy(di->interface, tmp->interface);
02422 
02423          AST_LIST_LOCK(dialed_interfaces);
02424          AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
02425          AST_LIST_UNLOCK(dialed_interfaces);
02426       }
02427 
02428       tc = ast_request(tmp->tech, ast_channel_nativeformats(chan), NULL, chan, tmp->number, &cause);
02429       if (!tc) {
02430          /* If we can't, just go on to the next call */
02431          ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
02432             tmp->tech, cause, ast_cause2str(cause));
02433          handle_cause(cause, &num);
02434          if (!rest) {
02435             /* we are on the last destination */
02436             ast_channel_hangupcause_set(chan, cause);
02437          }
02438          if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
02439             if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
02440                ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, "");
02441             }
02442          }
02443          chanlist_free(tmp);
02444          continue;
02445       }
02446 
02447       ast_channel_lock(tc);
02448       ast_channel_stage_snapshot(tc);
02449       ast_channel_unlock(tc);
02450 
02451       ast_channel_get_device_name(tc, device_name, sizeof(device_name));
02452       if (!ignore_cc) {
02453          ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
02454       }
02455 
02456       ast_channel_lock_both(tc, chan);
02457       pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
02458 
02459       /* Setup outgoing SDP to match incoming one */
02460       if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
02461          /* We are on the only destination. */
02462          ast_rtp_instance_early_bridge_make_compatible(tc, chan);
02463       }
02464 
02465       /* Inherit specially named variables from parent channel */
02466       ast_channel_inherit_variables(chan, tc);
02467       ast_channel_datastore_inherit(chan, tc);
02468 
02469       ast_channel_appl_set(tc, "AppDial");
02470       ast_channel_data_set(tc, "(Outgoing Line)");
02471       ast_channel_publish_snapshot(tc);
02472 
02473       memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
02474 
02475       /* Determine CallerID to store in outgoing channel. */
02476       ast_party_caller_set_init(&caller, ast_channel_caller(tc));
02477       if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
02478          caller.id = stored_clid;
02479          ast_channel_set_caller_event(tc, &caller, NULL);
02480          ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
02481       } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
02482          ast_channel_caller(tc)->id.number.str, NULL))) {
02483          /*
02484           * The new channel has no preset CallerID number by the channel
02485           * driver.  Use the dialplan extension and hint name.
02486           */
02487          caller.id = stored_clid;
02488          if (!caller.id.name.valid
02489             && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
02490                ast_channel_connected(chan)->id.name.str, NULL))) {
02491             /*
02492              * No hint name available.  We have a connected name supplied by
02493              * the dialplan we can use instead.
02494              */
02495             caller.id.name.valid = 1;
02496             caller.id.name = ast_channel_connected(chan)->id.name;
02497          }
02498          ast_channel_set_caller_event(tc, &caller, NULL);
02499          ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
02500       } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
02501          NULL))) {
02502          /* The new channel has no preset CallerID name by the channel driver. */
02503          if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
02504             ast_channel_connected(chan)->id.name.str, NULL))) {
02505             /*
02506              * We have a connected name supplied by the dialplan we can
02507              * use instead.
02508              */
02509             caller.id.name.valid = 1;
02510             caller.id.name = ast_channel_connected(chan)->id.name;
02511             ast_channel_set_caller_event(tc, &caller, NULL);
02512          }
02513       }
02514 
02515       /* Determine CallerID for outgoing channel to send. */
02516       if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
02517          struct ast_party_connected_line connected;
02518 
02519          ast_party_connected_line_set_init(&connected, ast_channel_connected(tc));
02520          connected.id = forced_clid;
02521          ast_channel_set_connected_line(tc, &connected, NULL);
02522       } else {
02523          ast_connected_line_copy_from_caller(ast_channel_connected(tc), ast_channel_caller(chan));
02524       }
02525 
02526       ast_party_redirecting_copy(ast_channel_redirecting(tc), ast_channel_redirecting(chan));
02527 
02528       ast_channel_dialed(tc)->transit_network_select = ast_channel_dialed(chan)->transit_network_select;
02529 
02530       ast_channel_req_accountcodes(tc, chan, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
02531       if (ast_strlen_zero(ast_channel_musicclass(tc))) {
02532          ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
02533       }
02534 
02535       /* Pass ADSI CPE and transfer capability */
02536       ast_channel_adsicpe_set(tc, ast_channel_adsicpe(chan));
02537       ast_channel_transfercapability_set(tc, ast_channel_transfercapability(chan));
02538 
02539       /* If we have an outbound group, set this peer channel to it */
02540       if (outbound_group)
02541          ast_app_group_set_channel(tc, outbound_group);
02542       /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
02543       if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE)
02544          ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
02545 
02546       /* Check if we're forced by configuration */
02547       if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
02548           ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
02549 
02550 
02551       /* Inherit context and extension */
02552       ast_channel_dialcontext_set(tc, ast_strlen_zero(ast_channel_macrocontext(chan)) ? ast_channel_context(chan) : ast_channel_macrocontext(chan));
02553       if (!ast_strlen_zero(ast_channel_macroexten(chan)))
02554          ast_channel_exten_set(tc, ast_channel_macroexten(chan));
02555       else
02556          ast_channel_exten_set(tc, ast_channel_exten(chan));
02557 
02558       ast_channel_stage_snapshot_done(tc);
02559 
02560       ast_channel_unlock(tc);
02561       ast_channel_unlock(chan);
02562 
02563       /* Put channel in the list of outgoing thingies. */
02564       tmp->chan = tc;
02565       AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
02566    }
02567 
02568    /*
02569     * PREDIAL: Run gosub on all of the callee channels
02570     *
02571     * We run the callee predial before ast_call() in case the user
02572     * wishes to do something on the newly created channels before
02573     * the channel does anything important.
02574     *
02575     * Inside the target gosub we will be able to do something with
02576     * the newly created channel name ie: now the calling channel
02577     * can know what channel will be used to call the destination
02578     * ex: now we will know that SIP/abc-123 is calling SIP/def-124
02579     */
02580    if (ast_test_flag64(&opts, OPT_PREDIAL_CALLEE)
02581       && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])
02582       && !AST_LIST_EMPTY(&out_chans)) {
02583       const char *predial_callee;
02584 
02585       ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
02586       predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
02587       if (predial_callee) {
02588          ast_autoservice_start(chan);
02589          AST_LIST_TRAVERSE(&out_chans, tmp, node) {
02590             ast_pre_call(tmp->chan, predial_callee);
02591          }
02592          ast_autoservice_stop(chan);
02593          ast_free((char *) predial_callee);
02594       }
02595    }
02596 
02597    /* Start all outgoing calls */
02598    AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
02599       res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
02600       ast_channel_lock(chan);
02601 
02602       /* check the results of ast_call */
02603       if (res) {
02604          /* Again, keep going even if there's an error */
02605          ast_debug(1, "ast call on peer returned %d\n", res);
02606          ast_verb(3, "Couldn't call %s\n", tmp->interface);
02607          if (ast_channel_hangupcause(tmp->chan)) {
02608             ast_channel_hangupcause_set(chan, ast_channel_hangupcause(tmp->chan));
02609          }
02610          ast_channel_unlock(chan);
02611          ast_cc_call_failed(chan, tmp->chan, tmp->interface);
02612          ast_hangup(tmp->chan);
02613          tmp->chan = NULL;
02614          AST_LIST_REMOVE_CURRENT(node);
02615          chanlist_free(tmp);
02616          continue;
02617       }
02618 
02619       ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
02620       ast_channel_unlock(chan);
02621 
02622       ast_verb(3, "Called %s\n", tmp->interface);
02623       ast_set_flag64(tmp, DIAL_STILLGOING);
02624 
02625       /* If this line is up, don't try anybody else */
02626       if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
02627          break;
02628       }
02629    }
02630    AST_LIST_TRAVERSE_SAFE_END;
02631 
02632    if (ast_strlen_zero(args.timeout)) {
02633       to = -1;
02634    } else {
02635       to = atoi(args.timeout);
02636       if (to > 0)
02637          to *= 1000;
02638       else {
02639          ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
02640          to = -1;
02641       }
02642    }
02643 
02644    outgoing = AST_LIST_FIRST(&out_chans);
02645    if (!outgoing) {
02646       strcpy(pa.status, "CHANUNAVAIL");
02647       if (fulldial == num_dialed) {
02648          res = -1;
02649          goto out;
02650       }
02651    } else {
02652       /* Our status will at least be NOANSWER */
02653       strcpy(pa.status, "NOANSWER");
02654       if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
02655          moh = 1;
02656          if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
02657             char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
02658             ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
02659             ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
02660             ast_channel_musicclass_set(chan, original_moh);
02661          } else {
02662             ast_moh_start(chan, NULL, NULL);
02663          }
02664          ast_indicate(chan, AST_CONTROL_PROGRESS);
02665       } else if (ast_test_flag64(outgoing, OPT_RINGBACK) || ast_test_flag64(outgoing, OPT_RING_WITH_EARLY_MEDIA)) {
02666          if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
02667             if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
02668                ast_indicate(chan, AST_CONTROL_RINGING);
02669                sentringing++;
02670             } else {
02671                ast_indicate(chan, AST_CONTROL_PROGRESS);
02672             }
02673          } else {
02674             ast_indicate(chan, AST_CONTROL_RINGING);
02675             sentringing++;
02676          }
02677       }
02678    }
02679 
02680    peer = wait_for_answer(chan, &out_chans, &to, peerflags, opt_args, &pa, &num, &result,
02681       dtmf_progress, ignore_cc, &forced_clid, &stored_clid);
02682 
02683    /* The ast_channel_datastore_remove() function could fail here if the
02684     * datastore was moved to another channel during a masquerade. If this is
02685     * the case, don't free the datastore here because later, when the channel
02686     * to which the datastore was moved hangs up, it will attempt to free this
02687     * datastore again, causing a crash
02688     */
02689    ast_channel_lock(chan);
02690    datastore = ast_channel_datastore_find(chan, &dialed_interface_info, NULL); /* make sure we weren't cleaned up already */
02691    if (datastore && !ast_channel_datastore_remove(chan, datastore)) {
02692       ast_datastore_free(datastore);
02693    }
02694    ast_channel_unlock(chan);
02695    if (!peer) {
02696       if (result) {
02697          res = result;
02698       } else if (to) { /* Musta gotten hung up */
02699          res = -1;
02700       } else { /* Nobody answered, next please? */
02701          res = 0;
02702       }
02703    } else {
02704       const char *number;
02705       int dial_end_raised = 0;
02706 
02707       if (ast_test_flag64(&opts, OPT_CALLER_ANSWER))
02708          ast_answer(chan);
02709 
02710       strcpy(pa.status, "ANSWER");
02711       ast_channel_stage_snapshot(chan);
02712       pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
02713       /* Ah ha!  Someone answered within the desired timeframe.  Of course after this
02714          we will always return with -1 so that it is hung up properly after the
02715          conversation.  */
02716       hanguptree(&out_chans, peer, 1);
02717       /* If appropriate, log that we have a destination channel and set the answer time */
02718       if (ast_channel_name(peer))
02719          pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", ast_channel_name(peer));
02720 
02721       ast_channel_lock(peer);
02722       number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
02723       if (ast_strlen_zero(number)) {
02724          number = NULL;
02725       } else {
02726          number = ast_strdupa(number);
02727       }
02728       ast_channel_unlock(peer);
02729       ast_channel_lock(chan);
02730       pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
02731       ast_channel_stage_snapshot_done(chan);
02732       ast_channel_unlock(chan);
02733 
02734       if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
02735          ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
02736          ast_channel_sendurl( peer, args.url );
02737       }
02738       if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
02739          if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
02740             ast_channel_publish_dial(chan, peer, NULL, pa.status);
02741             res = 0;
02742             goto out;
02743          }
02744       }
02745       if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
02746          res = 0;
02747       } else {
02748          int digit = 0;
02749          struct ast_channel *chans[2];
02750          struct ast_channel *active_chan;
02751 
02752          chans[0] = chan;
02753          chans[1] = peer;
02754 
02755          /* we need to stream the announcment while monitoring the caller for a hangup */
02756 
02757          /* stream the file */
02758          res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
02759          if (res) {
02760             res = 0;
02761             ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
02762          }
02763 
02764          ast_set_flag(ast_channel_flags(peer), AST_FLAG_END_DTMF_ONLY);
02765          while (ast_channel_stream(peer)) {
02766             int ms;
02767 
02768             ms = ast_sched_wait(ast_channel_sched(peer));
02769 
02770             if (ms < 0 && !ast_channel_timingfunc(peer)) {
02771                ast_stopstream(peer);
02772                break;
02773             }
02774             if (ms < 0)
02775                ms = 1000;
02776 
02777             active_chan = ast_waitfor_n(chans, 2, &ms);
02778             if (active_chan) {
02779                struct ast_frame *fr = ast_read(active_chan);
02780                if (!fr) {
02781                   ast_autoservice_chan_hangup_peer(chan, peer);
02782                   res = -1;
02783                   goto done;
02784                }
02785                switch(fr->frametype) {
02786                   case AST_FRAME_DTMF_END:
02787                      digit = fr->subclass.integer;
02788                      if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
02789                         ast_stopstream(peer);
02790                         res = ast_senddigit(chan, digit, 0);
02791                      }
02792                      break;
02793                   case AST_FRAME_CONTROL:
02794                      switch (fr->subclass.integer) {
02795                         case AST_CONTROL_HANGUP:
02796                            ast_frfree(fr);
02797                            ast_autoservice_chan_hangup_peer(chan, peer);
02798                            res = -1;
02799                            goto done;
02800                         default:
02801                            break;
02802                      }
02803                      break;
02804                   default:
02805                      /* Ignore all others */
02806                      break;
02807                }
02808                ast_frfree(fr);
02809             }
02810             ast_sched_runq(ast_channel_sched(peer));
02811          }
02812          ast_clear_flag(ast_channel_flags(peer), AST_FLAG_END_DTMF_ONLY);
02813       }
02814 
02815       if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
02816          /* chan and peer are going into the PBX; as such neither are considered
02817           * outgoing channels any longer */
02818          ast_clear_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
02819 
02820          ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
02821          ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
02822          /* peer goes to the same context and extension as chan, so just copy info from chan*/
02823          ast_channel_lock(peer);
02824          ast_channel_stage_snapshot(peer);
02825          ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
02826          ast_channel_context_set(peer, ast_channel_context(chan));
02827          ast_channel_exten_set(peer, ast_channel_exten(chan));
02828          ast_channel_priority_set(peer, ast_channel_priority(chan) + 2);
02829          ast_channel_stage_snapshot_done(peer);
02830          ast_channel_unlock(peer);
02831          if (ast_pbx_start(peer)) {
02832             ast_autoservice_chan_hangup_peer(chan, peer);
02833          }
02834          hanguptree(&out_chans, NULL, ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0);
02835          if (continue_exec)
02836             *continue_exec = 1;
02837          res = 0;
02838          ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
02839          goto done;
02840       }
02841 
02842       if (ast_test_flag64(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
02843          const char *macro_result_peer;
02844          int macro_res;
02845 
02846          /* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
02847          ast_channel_lock_both(chan, peer);
02848          ast_channel_context_set(peer, ast_channel_context(chan));
02849          ast_channel_exten_set(peer, ast_channel_exten(chan));
02850          ast_channel_unlock(peer);
02851          ast_channel_unlock(chan);
02852          ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
02853          macro_res = ast_app_exec_macro(chan, peer, opt_args[OPT_ARG_CALLEE_MACRO]);
02854 
02855          ast_channel_lock(peer);
02856 
02857          if (!macro_res && (macro_result_peer = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
02858             char *macro_result = ast_strdupa(macro_result_peer);
02859             char *macro_transfer_dest;
02860 
02861             ast_channel_unlock(peer);
02862 
02863             if (!strcasecmp(macro_result, "BUSY")) {
02864                ast_copy_string(pa.status, macro_result, sizeof(pa.status));
02865                ast_set_flag64(peerflags, OPT_GO_ON);
02866                macro_res = -1;
02867             } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
02868                ast_copy_string(pa.status, macro_result, sizeof(pa.status));
02869                ast_set_flag64(peerflags, OPT_GO_ON);
02870                macro_res = -1;
02871             } else if (!strcasecmp(macro_result, "CONTINUE")) {
02872                /* hangup peer and keep chan alive assuming the macro has changed
02873                   the context / exten / priority or perhaps
02874                   the next priority in the current exten is desired.
02875                */
02876                ast_set_flag64(peerflags, OPT_GO_ON);
02877                macro_res = -1;
02878             } else if (!strcasecmp(macro_result, "ABORT")) {
02879                /* Hangup both ends unless the caller has the g flag */
02880                macro_res = -1;
02881             } else if (!strncasecmp(macro_result, "GOTO:", 5)) {
02882                macro_transfer_dest = macro_result + 5;
02883                macro_res = -1;
02884                /* perform a transfer to a new extension */
02885                if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
02886                   ast_replace_subargument_delimiter(macro_transfer_dest);
02887                }
02888                if (!ast_parseable_goto(chan, macro_transfer_dest)) {
02889                   ast_set_flag64(peerflags, OPT_GO_ON);
02890                }
02891             }
02892             if (macro_res && !dial_end_raised) {
02893                ast_channel_publish_dial(chan, peer, NULL, macro_result);
02894                dial_end_raised = 1;
02895             }
02896          } else {
02897             ast_channel_unlock(peer);
02898          }
02899          res = macro_res;
02900       }
02901 
02902       if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
02903          const char *gosub_result_peer;
02904          char *gosub_argstart;
02905          char *gosub_args = NULL;
02906          int gosub_res = -1;
02907 
02908          ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
02909          gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
02910          if (gosub_argstart) {
02911             const char *what_is_s = "s";
02912             *gosub_argstart = 0;
02913             if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
02914                 ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
02915                what_is_s = "~~s~~";
02916             }
02917             if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
02918                gosub_args = NULL;
02919             }
02920             *gosub_argstart = ',';
02921          } else {
02922             const char *what_is_s = "s";
02923             if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) &&
02924                 ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) {
02925                what_is_s = "~~s~~";
02926             }
02927             if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
02928                gosub_args = NULL;
02929             }
02930          }
02931          if (gosub_args) {
02932             gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
02933             ast_free(gosub_args);
02934          } else {
02935             ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
02936          }
02937 
02938          ast_channel_lock_both(chan, peer);
02939 
02940          if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
02941             char *gosub_transfer_dest;
02942             char *gosub_result = ast_strdupa(gosub_result_peer);
02943             const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
02944 
02945             /* Inherit return value from the peer, so it can be used in the master */
02946             if (gosub_retval) {
02947                pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
02948             }
02949 
02950             ast_channel_unlock(peer);
02951             ast_channel_unlock(chan);
02952 
02953             if (!strcasecmp(gosub_result, "BUSY")) {
02954                ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
02955                ast_set_flag64(peerflags, OPT_GO_ON);
02956                gosub_res = -1;
02957             } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
02958                ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
02959                ast_set_flag64(peerflags, OPT_GO_ON);
02960                gosub_res = -1;
02961             } else if (!strcasecmp(gosub_result, "CONTINUE")) {
02962                /* Hangup peer and continue with the next extension priority. */
02963                ast_set_flag64(peerflags, OPT_GO_ON);
02964                gosub_res = -1;
02965             } else if (!strcasecmp(gosub_result, "ABORT")) {
02966                /* Hangup both ends unless the caller has the g flag */
02967                gosub_res = -1;
02968             } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
02969                gosub_transfer_dest = gosub_result + 5;
02970                gosub_res = -1;
02971                /* perform a transfer to a new extension */
02972                if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
02973                   ast_replace_subargument_delimiter(gosub_transfer_dest);
02974                }
02975                if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
02976                   ast_set_flag64(peerflags, OPT_GO_ON);
02977                }
02978             }
02979             if (gosub_res) {
02980                res = gosub_res;
02981                if (!dial_end_raised) {
02982                   ast_channel_publish_dial(chan, peer, NULL, gosub_result);
02983                   dial_end_raised = 1;
02984                }
02985             }
02986          } else {
02987             ast_channel_unlock(peer);
02988             ast_channel_unlock(chan);
02989          }
02990       }
02991 
02992       if (!res) {
02993 
02994          /* None of the Dial options changed our status; inform
02995           * everyone that this channel answered
02996           */
02997          if (!dial_end_raised) {
02998             ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
02999             dial_end_raised = 1;
03000          }
03001 
03002          if (!ast_tvzero(calldurationlimit)) {
03003             struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
03004             ast_channel_lock(peer);
03005             ast_channel_whentohangup_set(peer, &whentohangup);
03006             ast_channel_unlock(peer);
03007          }
03008          if (!ast_strlen_zero(dtmfcalled)) {
03009             ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
03010             res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
03011          }
03012          if (!ast_strlen_zero(dtmfcalling)) {
03013             ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
03014             res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
03015          }
03016       }
03017 
03018       if (res) { /* some error */
03019          if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
03020             ast_channel_hangupcause_set(chan, ast_channel_hangupcause(peer));
03021          }
03022          setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
03023          if (ast_bridge_setup_after_goto(peer)
03024             || ast_pbx_start(peer)) {
03025             ast_autoservice_chan_hangup_peer(chan, peer);
03026          }
03027          res = -1;
03028       } else {
03029          if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
03030             ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
03031          if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
03032             ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
03033          if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
03034             ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
03035          if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
03036             ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
03037          if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
03038             ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
03039          if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
03040             ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
03041          if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
03042             ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
03043          if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
03044             ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
03045          if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
03046             ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
03047          if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
03048             ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
03049 
03050          config.end_bridge_callback = end_bridge_callback;
03051          config.end_bridge_callback_data = chan;
03052          config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
03053 
03054          if (moh) {
03055             moh = 0;
03056             ast_moh_stop(chan);
03057          } else if (sentringing) {
03058             sentringing = 0;
03059             ast_indicate(chan, -1);
03060          }
03061          /* Be sure no generators are left on it and reset the visible indication */
03062          ast_deactivate_generator(chan);
03063          ast_channel_visible_indication_set(chan, 0);
03064          /* Make sure channels are compatible */
03065          res = ast_channel_make_compatible(chan, peer);
03066          if (res < 0) {
03067             ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", ast_channel_name(chan), ast_channel_name(peer));
03068             ast_autoservice_chan_hangup_peer(chan, peer);
03069             res = -1;
03070             goto done;
03071          }
03072          if (opermode) {
03073             struct oprmode oprmode;
03074 
03075             oprmode.peer = peer;
03076             oprmode.mode = opermode;
03077 
03078             ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
03079          }
03080          setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
03081          res = ast_bridge_call(chan, peer, &config);
03082       }
03083    }
03084 out:
03085    if (moh) {
03086       moh = 0;
03087       ast_moh_stop(chan);
03088    } else if (sentringing) {
03089       sentringing = 0;
03090       ast_indicate(chan, -1);
03091    }
03092 
03093    if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
03094       ast_filedelete(pa.privintro, NULL);
03095       if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
03096          ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
03097       } else {
03098          ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
03099       }
03100    }
03101 
03102    ast_channel_early_bridge(chan, NULL);
03103    hanguptree(&out_chans, NULL, ast_channel_hangupcause(chan)==AST_CAUSE_ANSWERED_ELSEWHERE || ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE) ? 1 : 0 ); /* forward 'answered elsewhere' if we received it */
03104    pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
03105    ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
03106 
03107    if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
03108       if (!ast_tvzero(calldurationlimit))
03109          memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
03110       res = 0;
03111    }
03112 
03113 done:
03114    if (config.warning_sound) {
03115       ast_free((char *)config.warning_sound);
03116    }
03117    if (config.end_sound) {
03118       ast_free((char *)config.end_sound);
03119    }
03120    if (config.start_sound) {
03121       ast_free((char *)config.start_sound);
03122    }
03123    ast_ignore_cc(chan);
03124    return res;
03125 }

static int dial_handle_playtones ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 1979 of file app_dial.c.

References ast_channel_zone(), ast_debug, ast_get_indication_tone(), ast_log, ast_playtones_start(), ast_strlen_zero, ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, LOG_WARNING, NULL, and str.

Referenced by dial_exec_full().

01980 {
01981    struct ast_tone_zone_sound *ts = NULL;
01982    int res;
01983    const char *str = data;
01984 
01985    if (ast_strlen_zero(str)) {
01986       ast_debug(1,"Nothing to play\n");
01987       return -1;
01988    }
01989 
01990    ts = ast_get_indication_tone(ast_channel_zone(chan), str);
01991 
01992    if (ts && ts->data[0]) {
01993       res = ast_playtones_start(chan, 0, ts->data, 0);
01994    } else {
01995       res = -1;
01996    }
01997 
01998    if (ts) {
01999       ts = ast_tone_zone_sound_unref(ts);
02000    }
02001 
02002    if (res) {
02003       ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
02004    }
02005 
02006    return res;
02007 }

static void do_forward ( struct chanlist o,
struct cause_args num,
struct ast_flags64 peerflags,
int  single,
int  caller_entertained,
int *  to,
struct ast_party_id forced_clid,
struct ast_party_id stored_clid 
) [static]

helper function for wait_for_answer()

Parameters:
o Outgoing call channel list.
num Incoming call channel cause accumulation
peerflags Dial option flags
single TRUE if there is only one outgoing call.
caller_entertained TRUE if the caller is being entertained by MOH or ringback.
to Remaining call timeout time.
forced_clid OPT_FORCECLID caller id to send
stored_clid Caller id representing the called party if needed
XXX this code is highly suspicious, as it essentially overwrites the outgoing channel without properly deleting it.

Todo:
eventually this function should be intergrated into and replaced by ast_call_forward()

Definition at line 829 of file app_dial.c.

References ast_call(), AST_CAUSE_BUSY, ast_channel_appl_set(), ast_channel_call_forward(), ast_channel_caller(), ast_channel_connected(), ast_channel_context(), ast_channel_data_set(), ast_channel_datastore_inherit(), ast_channel_dialed(), ast_channel_exten(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_lock_both, ast_channel_macroexten(), ast_channel_make_compatible(), ast_channel_name(), ast_channel_nativeformats(), ast_channel_publish_dial(), ast_channel_publish_dial_forward(), ast_channel_publish_snapshot(), ast_channel_redirecting(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_set_caller_event(), ast_channel_unlock, ast_channel_update_redirecting(), ast_clear_flag64, ast_connected_line_copy_from_caller(), ast_copy_string(), ast_hangup(), ast_ignore_cc(), ast_indicate(), ast_log, ast_party_caller_set_init(), ast_party_connected_line_copy(), ast_party_connected_line_init(), ast_party_number_free(), ast_party_number_init(), ast_party_redirecting_copy(), ast_party_redirecting_free(), ast_party_redirecting_init(), ast_request(), ast_rtp_instance_early_bridge_make_compatible(), ast_set_flag64, ast_strdup, ast_strlen_zero, ast_test_flag64, ast_verb, c, CAN_EARLY_BRIDGE, cause_args::chan, chanlist::chan, DIAL_CALLERID_ABSENT, DIAL_STILLGOING, ast_party_redirecting::from, handle_cause(), ast_party_connected_line::id, ast_party_caller::id, in, LOG_NOTICE, cause_args::nochan, NULL, ast_party_id::number, OPT_CANCEL_TIMEOUT, OPT_FORCECLID, OPT_IGNORE_CONNECTEDLINE, OPT_IGNORE_FORWARDING, OPT_ORIGINAL_CLID, pbx_builtin_getvar_helper(), S_COR, S_OR, ast_party_number::str, chanlist::stuff, chanlist::tech, ast_party_dialed::transit_network_select, and ast_party_number::valid.

Referenced by wait_for_answer().

00832 {
00833    char tmpchan[256];
00834    struct ast_channel *original = o->chan;
00835    struct ast_channel *c = o->chan; /* the winner */
00836    struct ast_channel *in = num->chan; /* the input channel */
00837    char *stuff;
00838    char *tech;
00839    int cause;
00840    struct ast_party_caller caller;
00841 
00842    ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
00843    if ((stuff = strchr(tmpchan, '/'))) {
00844       *stuff++ = '\0';
00845       tech = tmpchan;
00846    } else {
00847       const char *forward_context;
00848       ast_channel_lock(c);
00849       forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
00850       if (ast_strlen_zero(forward_context)) {
00851          forward_context = NULL;
00852       }
00853       snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
00854       ast_channel_unlock(c);
00855       stuff = tmpchan;
00856       tech = "Local";
00857    }
00858    if (!strcasecmp(tech, "Local")) {
00859       /*
00860        * Drop the connected line update block for local channels since
00861        * this is going to run dialplan and the user can change his
00862        * mind about what connected line information he wants to send.
00863        */
00864       ast_clear_flag64(o, OPT_IGNORE_CONNECTEDLINE);
00865    }
00866 
00867    /* Before processing channel, go ahead and check for forwarding */
00868    ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
00869    /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
00870    if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
00871       ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
00872       c = o->chan = NULL;
00873       cause = AST_CAUSE_BUSY;
00874    } else {
00875       /* Setup parameters */
00876       c = o->chan = ast_request(tech, ast_channel_nativeformats(in), NULL, in, stuff, &cause);
00877       if (c) {
00878          if (single && !caller_entertained) {
00879             ast_channel_make_compatible(in, o->chan);
00880          }
00881          ast_channel_lock_both(in, o->chan);
00882          ast_channel_inherit_variables(in, o->chan);
00883          ast_channel_datastore_inherit(in, o->chan);
00884          ast_channel_unlock(in);
00885          ast_channel_unlock(o->chan);
00886          /* When a call is forwarded, we don't want to track new interfaces
00887           * dialed for CC purposes. Setting the done flag will ensure that
00888           * any Dial operations that happen later won't record CC interfaces.
00889           */
00890          ast_ignore_cc(o->chan);
00891          ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", ast_channel_name(o->chan));
00892       } else
00893          ast_log(LOG_NOTICE,
00894             "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
00895             tech, stuff, cause);
00896    }
00897    if (!c) {
00898       ast_channel_publish_dial(in, original, stuff, "BUSY");
00899       ast_clear_flag64(o, DIAL_STILLGOING);
00900       handle_cause(cause, num);
00901       ast_hangup(original);
00902    } else {
00903       ast_channel_lock_both(c, original);
00904       ast_party_redirecting_copy(ast_channel_redirecting(c),
00905          ast_channel_redirecting(original));
00906       ast_channel_unlock(c);
00907       ast_channel_unlock(original);
00908 
00909       ast_channel_lock_both(c, in);
00910 
00911       if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
00912          ast_rtp_instance_early_bridge_make_compatible(c, in);
00913       }
00914 
00915       if (!ast_channel_redirecting(c)->from.number.valid
00916          || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
00917          /*
00918           * The call was not previously redirected so it is
00919           * now redirected from this number.
00920           */
00921          ast_party_number_free(&ast_channel_redirecting(c)->from.number);
00922          ast_party_number_init(&ast_channel_redirecting(c)->from.number);
00923          ast_channel_redirecting(c)->from.number.valid = 1;
00924          ast_channel_redirecting(c)->from.number.str =
00925             ast_strdup(S_OR(ast_channel_macroexten(in), ast_channel_exten(in)));
00926       }
00927 
00928       ast_channel_dialed(c)->transit_network_select = ast_channel_dialed(in)->transit_network_select;
00929 
00930       /* Determine CallerID to store in outgoing channel. */
00931       ast_party_caller_set_init(&caller, ast_channel_caller(c));
00932       if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
00933          caller.id = *stored_clid;
00934          ast_channel_set_caller_event(c, &caller, NULL);
00935          ast_set_flag64(o, DIAL_CALLERID_ABSENT);
00936       } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
00937          ast_channel_caller(c)->id.number.str, NULL))) {
00938          /*
00939           * The new channel has no preset CallerID number by the channel
00940           * driver.  Use the dialplan extension and hint name.
00941           */
00942          caller.id = *stored_clid;
00943          ast_channel_set_caller_event(c, &caller, NULL);
00944          ast_set_flag64(o, DIAL_CALLERID_ABSENT);
00945       } else {
00946          ast_clear_flag64(o, DIAL_CALLERID_ABSENT);
00947       }
00948 
00949       /* Determine CallerID for outgoing channel to send. */
00950       if (ast_test_flag64(o, OPT_FORCECLID)) {
00951          struct ast_party_connected_line connected;
00952 
00953          ast_party_connected_line_init(&connected);
00954          connected.id = *forced_clid;
00955          ast_party_connected_line_copy(ast_channel_connected(c), &connected);
00956       } else {
00957          ast_connected_line_copy_from_caller(ast_channel_connected(c), ast_channel_caller(in));
00958       }
00959 
00960       ast_channel_req_accountcodes(c, in, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
00961 
00962       ast_channel_appl_set(c, "AppDial");
00963       ast_channel_data_set(c, "(Outgoing Line)");
00964       ast_channel_publish_snapshot(c);
00965 
00966       ast_channel_unlock(in);
00967       if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
00968          struct ast_party_redirecting redirecting;
00969 
00970          /*
00971           * Redirecting updates to the caller make sense only on single
00972           * calls.
00973           *
00974           * We must unlock c before calling
00975           * ast_channel_redirecting_macro, because we put c into
00976           * autoservice there.  That is pretty much a guaranteed
00977           * deadlock.  This is why the handling of c's lock may seem a
00978           * bit unusual here.
00979           */
00980          ast_party_redirecting_init(&redirecting);
00981          ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(c));
00982          ast_channel_unlock(c);
00983          if (ast_channel_redirecting_sub(c, in, &redirecting, 0) &&
00984             ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
00985             ast_channel_update_redirecting(in, &redirecting, NULL);
00986          }
00987          ast_party_redirecting_free(&redirecting);
00988       } else {
00989          ast_channel_unlock(c);
00990       }
00991 
00992       if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
00993          *to = -1;
00994       }
00995 
00996       if (ast_call(c, stuff, 0)) {
00997          ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
00998             tech, stuff);
00999          ast_channel_publish_dial(in, original, stuff, "CONGESTION");
01000          ast_clear_flag64(o, DIAL_STILLGOING);
01001          ast_hangup(original);
01002          ast_hangup(c);
01003          c = o->chan = NULL;
01004          num->nochan++;
01005       } else {
01006          ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
01007             ast_channel_call_forward(original));
01008 
01009          ast_channel_publish_dial(in, c, stuff, NULL);
01010 
01011          /* Hangup the original channel now, in case we needed it */
01012          ast_hangup(original);
01013       }
01014       if (single && !caller_entertained) {
01015          ast_indicate(in, -1);
01016       }
01017    }
01018 }

static void end_bridge_callback ( void *  data  )  [static]

Definition at line 1957 of file app_dial.c.

References ast_channel_get_duration(), ast_channel_get_up_time(), ast_channel_lock, ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_unlock, buf, end, and pbx_builtin_setvar_helper().

Referenced by app_exec(), dial_exec_full(), and try_calling().

01958 {
01959    char buf[80];
01960    time_t end;
01961    struct ast_channel *chan = data;
01962 
01963    time(&end);
01964 
01965    ast_channel_lock(chan);
01966    ast_channel_stage_snapshot(chan);
01967    snprintf(buf, sizeof(buf), "%d", ast_channel_get_up_time(chan));
01968    pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
01969    snprintf(buf, sizeof(buf), "%d", ast_channel_get_duration(chan));
01970    pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
01971    ast_channel_stage_snapshot_done(chan);
01972    ast_channel_unlock(chan);
01973 }

static void end_bridge_callback_data_fixup ( struct ast_bridge_config bconfig,
struct ast_channel originator,
struct ast_channel terminator 
) [static]

Definition at line 1975 of file app_dial.c.

References ast_bridge_config::end_bridge_callback_data.

Referenced by app_exec(), dial_exec_full(), and try_calling().

01975                                                                                                                                               {
01976    bconfig->end_bridge_callback_data = originator;
01977 }

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

Definition at line 799 of file app_dial.c.

References ast_channel_context(), ast_channel_exten(), ast_channel_lock, ast_channel_macrocontext(), ast_channel_macroexten(), ast_channel_unlock, ast_get_hint(), ast_strdupa, context, exten, NULL, and S_OR.

Referenced by dial_exec_full().

00800 {
00801    const char *context;
00802    const char *exten;
00803 
00804    ast_channel_lock(chan);
00805    context = ast_strdupa(S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)));
00806    exten = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
00807    ast_channel_unlock(chan);
00808 
00809    return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
00810 }

static void handle_cause ( int  cause,
struct cause_args num 
) [static]

Definition at line 758 of file app_dial.c.

References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NORMAL_CLEARING, AST_CAUSE_UNREGISTERED, cause_args::busy, cause_args::congestion, and cause_args::nochan.

Referenced by __ast_request_and_dial(), ast_call_forward(), dial_exec_full(), do_forward(), and wait_for_answer().

00759 {
00760    switch(cause) {
00761    case AST_CAUSE_BUSY:
00762       num->busy++;
00763       break;
00764    case AST_CAUSE_CONGESTION:
00765       num->congestion++;
00766       break;
00767    case AST_CAUSE_NO_ROUTE_DESTINATION:
00768    case AST_CAUSE_UNREGISTERED:
00769       num->nochan++;
00770       break;
00771    case AST_CAUSE_NO_ANSWER:
00772    case AST_CAUSE_NORMAL_CLEARING:
00773       break;
00774    default:
00775       num->nochan++;
00776       break;
00777    }
00778 }

static void hanguptree ( struct dial_head out_chans,
struct ast_channel exception,
int  answered_elsewhere 
) [static]

Definition at line 728 of file app_dial.c.

References AST_CAUSE_ANSWERED_ELSEWHERE, ast_channel_hangupcause_set(), ast_hangup(), AST_LIST_REMOVE_HEAD, chanlist::chan, and chanlist_free().

Referenced by dial_exec_full().

00729 {
00730    /* Hang up a tree of stuff */
00731    struct chanlist *outgoing;
00732 
00733    while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
00734       /* Hangup any existing lines we have open */
00735       if (outgoing->chan && (outgoing->chan != exception)) {
00736          if (answered_elsewhere) {
00737             /* This is for the channel drivers */
00738             ast_channel_hangupcause_set(outgoing->chan, AST_CAUSE_ANSWERED_ELSEWHERE);
00739          }
00740          ast_hangup(outgoing->chan);
00741       }
00742       chanlist_free(outgoing);
00743    }
00744 }

static int load_module ( void   )  [static]

Definition at line 3254 of file app_dial.c.

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

03255 {
03256    int res;
03257 
03258    res = ast_register_application_xml(app, dial_exec);
03259    res |= ast_register_application_xml(rapp, retrydial_exec);
03260 
03261    return res;
03262 }

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

Definition at line 780 of file app_dial.c.

References ast_channel_context(), ast_channel_macrocontext(), ast_goto_if_exists(), and ast_strlen_zero.

Referenced by retrydial_exec(), and wait_for_answer().

00781 {
00782    char rexten[2] = { exten, '\0' };
00783 
00784    if (context) {
00785       if (!ast_goto_if_exists(chan, context, rexten, pri))
00786          return 1;
00787    } else {
00788       if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
00789          return 1;
00790       else if (!ast_strlen_zero(ast_channel_macrocontext(chan))) {
00791          if (!ast_goto_if_exists(chan, ast_channel_macrocontext(chan), rexten, pri))
00792             return 1;
00793       }
00794    }
00795    return 0;
00796 }

static void publish_dial_end_event ( struct ast_channel in,
struct dial_head out_chans,
struct ast_channel exception,
const char *  status 
) [static]

Definition at line 1029 of file app_dial.c.

References ast_channel_publish_dial(), AST_LIST_TRAVERSE, chanlist::chan, and NULL.

Referenced by ring_entry(), wait_for_answer(), and wait_for_winner().

01030 {
01031    struct chanlist *outgoing;
01032    AST_LIST_TRAVERSE(out_chans, outgoing, node) {
01033       if (!outgoing->chan || outgoing->chan == exception) {
01034          continue;
01035       }
01036       ast_channel_publish_dial(in, outgoing->chan, NULL, status);
01037    }
01038 }

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

Definition at line 3136 of file app_dial.c.

References args, AST_APP_ARG, ast_channel_data_set(), ast_channel_flags(), ast_channel_language(), ast_channel_lock, ast_channel_unlock, AST_DECLARE_APP_ARGS, AST_DIGIT_ANY, ast_fileexists(), AST_FLAG_MOH, ast_log, ast_moh_start(), ast_moh_stop(), AST_PBX_INCOMPLETE, AST_STANDARD_APP_ARGS, ast_strdupa, ast_streamfile(), ast_strlen_zero, ast_test_flag, ast_test_flag64, ast_waitfordigit(), ast_waitstream(), context, dial_exec_full(), LOG_ERROR, LOG_WARNING, NULL, onedigit_goto(), OPT_DTMF_EXIT, parse(), and pbx_builtin_getvar_helper().

Referenced by load_module().

03137 {
03138    char *parse;
03139    const char *context = NULL;
03140    int sleepms = 0, loops = 0, res = -1;
03141    struct ast_flags64 peerflags = { 0, };
03142    AST_DECLARE_APP_ARGS(args,
03143       AST_APP_ARG(announce);
03144       AST_APP_ARG(sleep);
03145       AST_APP_ARG(retries);
03146       AST_APP_ARG(dialdata);
03147    );
03148 
03149    if (ast_strlen_zero(data)) {
03150       ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
03151       return -1;
03152    }
03153 
03154    parse = ast_strdupa(data);
03155    AST_STANDARD_APP_ARGS(args, parse);
03156 
03157    if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
03158       sleepms *= 1000;
03159 
03160    if (!ast_strlen_zero(args.retries)) {
03161       loops = atoi(args.retries);
03162    }
03163 
03164    if (!args.dialdata) {
03165       ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
03166       goto done;
03167    }
03168 
03169    if (sleepms < 1000)
03170       sleepms = 10000;
03171 
03172    if (!loops)
03173       loops = -1; /* run forever */
03174 
03175    ast_channel_lock(chan);
03176    context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
03177    context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
03178    ast_channel_unlock(chan);
03179 
03180    res = 0;
03181    while (loops) {
03182       int continue_exec;
03183 
03184       ast_channel_data_set(chan, "Retrying");
03185       if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
03186          ast_moh_stop(chan);
03187 
03188       res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
03189       if (continue_exec)
03190          break;
03191 
03192       if (res == 0) {
03193          if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
03194             if (!ast_strlen_zero(args.announce)) {
03195                if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
03196                   if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
03197                      ast_waitstream(chan, AST_DIGIT_ANY);
03198                } else
03199                   ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
03200             }
03201             if (!res && sleepms) {
03202                if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
03203                   ast_moh_start(chan, NULL, NULL);
03204                res = ast_waitfordigit(chan, sleepms);
03205             }
03206          } else {
03207             if (!ast_strlen_zero(args.announce)) {
03208                if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
03209                   if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
03210                      res = ast_waitstream(chan, "");
03211                } else
03212                   ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
03213             }
03214             if (sleepms) {
03215                if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
03216                   ast_moh_start(chan, NULL, NULL);
03217                if (!res)
03218                   res = ast_waitfordigit(chan, sleepms);
03219             }
03220          }
03221       }
03222 
03223       if (res < 0 || res == AST_PBX_INCOMPLETE) {
03224          break;
03225       } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
03226          if (onedigit_goto(chan, context, (char) res, 1)) {
03227             res = 0;
03228             break;
03229          }
03230       }
03231       loops--;
03232    }
03233    if (loops == 0)
03234       res = 0;
03235    else if (res == 1)
03236       res = 0;
03237 
03238    if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
03239       ast_moh_stop(chan);
03240  done:
03241    return res;
03242 }

static void setup_peer_after_bridge_goto ( struct ast_channel chan,
struct ast_channel peer,
struct ast_flags64 opts,
char *  opt_args[] 
) [static]

Definition at line 2021 of file app_dial.c.

References ast_bridge_set_after_go_on(), ast_bridge_set_after_h(), ast_channel_context(), ast_channel_exten(), ast_channel_lock, ast_channel_priority(), ast_channel_unlock, ast_strdupa, ast_test_flag64, context, OPT_ARG_CALLEE_GO_ON, OPT_CALLEE_GO_ON, and OPT_PEER_H.

Referenced by dial_exec_full(), and try_calling().

02022 {
02023    const char *context;
02024    const char *extension;
02025    int priority;
02026 
02027    if (ast_test_flag64(opts, OPT_PEER_H)) {
02028       ast_channel_lock(chan);
02029       context = ast_strdupa(ast_channel_context(chan));
02030       ast_channel_unlock(chan);
02031       ast_bridge_set_after_h(peer, context);
02032    } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
02033       ast_channel_lock(chan);
02034       context = ast_strdupa(ast_channel_context(chan));
02035       extension = ast_strdupa(ast_channel_exten(chan));
02036       priority = ast_channel_priority(chan);
02037       ast_channel_unlock(chan);
02038       ast_bridge_set_after_go_on(peer, context, extension, priority,
02039          opt_args[OPT_ARG_CALLEE_GO_ON]);
02040    }
02041 }

static int setup_privacy_args ( struct privacy_args pa,
struct ast_flags64 opts,
char *  opt_args[],
struct ast_channel chan 
) [static]

returns 1 if successful, 0 or <0 if the caller should 'goto out'

Definition at line 1856 of file app_dial.c.

References ast_answer(), ast_channel_caller(), ast_channel_exten(), ast_channel_language(), ast_channel_name(), ast_config_AST_DATA_DIR, ast_copy_string(), ast_dsp_get_threshold_from_settings(), ast_filedelete(), ast_fileexists(), ast_log, ast_mkdir(), ast_play_and_record(), AST_PRIVACY_ALLOW, ast_privacy_check(), AST_PRIVACY_DENY, AST_PRIVACY_KILL, AST_PRIVACY_TORTURE, AST_PRIVACY_UNKNOWN, ast_shrink_phone_number(), ast_strdupa, ast_streamfile(), ast_strlen_zero, ast_test_flag64, ast_verb, ast_waitstream(), LOG_NOTICE, LOG_WARNING, NULL, OPT_ARG_PRIVACY, OPT_PRIVACY, OPT_SCREEN_NOCALLERID, privacy_args::privcid, privacy_args::privdb_val, privacy_args::privintro, silencethreshold, privacy_args::status, and THRESHOLD_SILENCE.

Referenced by dial_exec_full().

01858 {
01859    char callerid[60];
01860    int res;
01861    char *l;
01862 
01863    if (ast_channel_caller(chan)->id.number.valid
01864       && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
01865       l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
01866       ast_shrink_phone_number(l);
01867       if (ast_test_flag64(opts, OPT_PRIVACY) ) {
01868          ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
01869          pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
01870       } else {
01871          ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
01872          pa->privdb_val = AST_PRIVACY_UNKNOWN;
01873       }
01874    } else {
01875       char *tnam, *tn2;
01876 
01877       tnam = ast_strdupa(ast_channel_name(chan));
01878       /* clean the channel name so slashes don't try to end up in disk file name */
01879       for (tn2 = tnam; *tn2; tn2++) {
01880          if (*tn2 == '/')  /* any other chars to be afraid of? */
01881             *tn2 = '=';
01882       }
01883       ast_verb(3, "Privacy-- callerid is empty\n");
01884 
01885       snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
01886       l = callerid;
01887       pa->privdb_val = AST_PRIVACY_UNKNOWN;
01888    }
01889 
01890    ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
01891 
01892    if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
01893       /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
01894       ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
01895       pa->privdb_val = AST_PRIVACY_ALLOW;
01896    } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
01897       ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
01898    }
01899 
01900    if (pa->privdb_val == AST_PRIVACY_DENY) {
01901       ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
01902       ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
01903       return 0;
01904    } else if (pa->privdb_val == AST_PRIVACY_KILL) {
01905       ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
01906       return 0; /* Is this right? */
01907    } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
01908       ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
01909       return 0; /* is this right??? */
01910    } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
01911       /* Get the user's intro, store it in priv-callerintros/$CID,
01912          unless it is already there-- this should be done before the
01913          call is actually dialed  */
01914 
01915       /* make sure the priv-callerintros dir actually exists */
01916       snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
01917       if ((res = ast_mkdir(pa->privintro, 0755))) {
01918          ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
01919          return -1;
01920       }
01921 
01922       snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
01923       if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
01924          /* the DELUX version of this code would allow this caller the
01925             option to hear and retape their previously recorded intro.
01926          */
01927       } else {
01928          int duration; /* for feedback from play_and_wait */
01929          /* the file doesn't exist yet. Let the caller submit his
01930             vocal intro for posterity */
01931          /* priv-recordintro script:
01932 
01933             "At the tone, please say your name:"
01934 
01935          */
01936          int silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
01937          ast_answer(chan);
01938          res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0);  /* NOTE: I've reduced the total time to 4 sec */
01939                            /* don't think we'll need a lock removed, we took care of
01940                               conflicts by naming the pa.privintro file */
01941          if (res == -1) {
01942             /* Delete the file regardless since they hung up during recording */
01943             ast_filedelete(pa->privintro, NULL);
01944             if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
01945                ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
01946             else
01947                ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
01948             return -1;
01949          }
01950          if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
01951             ast_waitstream(chan, "");
01952       }
01953    }
01954    return 1; /* success */
01955 }

static int unload_module ( void   )  [static]

Definition at line 3244 of file app_dial.c.

References ast_unregister_application().

03245 {
03246    int res;
03247 
03248    res = ast_unregister_application(app);
03249    res |= ast_unregister_application(rapp);
03250 
03251    return res;
03252 }

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

Definition at line 1708 of file app_dial.c.

References ast_test_flag64, OPT_PRIVACY, and OPT_SCREENING.

01709 {
01710    if (res < '1')
01711       return 0;
01712    if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
01713       return 1;
01714    if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
01715       return 1;
01716    return 0;
01717 }

static struct ast_channel* wait_for_answer ( struct ast_channel in,
struct dial_head out_chans,
int *  to,
struct ast_flags64 peerflags,
char *  opt_args[],
struct privacy_args pa,
const struct cause_args num_in,
int *  result,
char *  dtmf_progress,
const int  ignore_cc,
struct ast_party_id forced_clid,
struct ast_party_id stored_clid 
) [static, read]

Definition at line 1040 of file app_dial.c.

References chanlist::aoc_s_rate_list, ast_aoc_decode(), ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), ast_aoc_encode(), ast_aoc_get_msg_type(), AST_AOC_S, AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NORMAL_CLEARING, ast_cc_completed(), ast_cc_failed(), ast_cc_is_recall(), ast_channel_call_forward(), ast_channel_caller(), ast_channel_connected(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_early_bridge(), ast_channel_exten_set(), ast_channel_hangupcause(), ast_channel_hangupcause_set(), ast_channel_lock, ast_channel_make_compatible(), ast_channel_name(), ast_channel_publish_dial(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_channel_sendhtml(), ast_channel_unlock, ast_channel_update_connected_line(), ast_check_hangup(), ast_clear_flag64, ast_connected_line_copy_from_caller(), ast_connected_line_parse_data(), AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_copy_flags64, ast_deactivate_generator(), ast_debug, ast_dtmf_stream(), AST_FEATURE_MAX_LEN, 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_handle_cc_control_frame(), ast_hangup(), ast_hangup_cause_to_dial_status(), ast_indicate(), ast_indicate_data(), AST_LIST_FIRST, AST_LIST_NEXT, AST_LIST_TRAVERSE, ast_log, AST_MAX_WATCHERS, ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_party_connected_line_set(), ast_party_connected_line_set_init(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_remaining_ms(), AST_STATE_UP, ast_str_alloca, ast_strlen_zero, ast_test_flag64, ast_tvnow(), ast_verb, ast_waitfor_n(), ast_write(), cause_args::busy, c, CAN_EARLY_BRIDGE, chanlist::chan, cause_args::congestion, chanlist::connected, context, ast_frame::data, ast_frame::datalen, detect_disconnect(), DIAL_CALLERID_ABSENT, DIAL_NOFORWARDHTML, DIAL_STILLGOING, do_forward(), f, ast_frame::frametype, handle_cause(), ast_frame_subclass::integer, LOG_WARNING, ast_channel::name, cause_args::nochan, NULL, onedigit_goto(), OPT_ARG_RINGBACK, OPT_CALLEE_HANGUP, OPT_CALLEE_MIXMONITOR, OPT_CALLEE_MONITOR, OPT_CALLEE_PARK, OPT_CALLEE_TRANSFER, OPT_CALLER_HANGUP, OPT_CALLER_MIXMONITOR, OPT_CALLER_MONITOR, OPT_CALLER_PARK, OPT_CALLER_TRANSFER, OPT_DTMF_EXIT, OPT_IGNORE_CONNECTEDLINE, OPT_MUSICBACK, OPT_RINGBACK, pbx_builtin_getvar_helper(), chanlist::pending_connected_update, ast_frame::ptr, publish_dial_end_event(), privacy_args::sentringing, ast_party_connected_line::source, privacy_args::status, ast_frame::subclass, and ast_frame::uint32.

Referenced by dial_exec_full(), and try_calling().

01047 {
01048    struct cause_args num = *num_in;
01049    int prestart = num.busy + num.congestion + num.nochan;
01050    int orig = *to;
01051    struct ast_channel *peer = NULL;
01052 #ifdef HAVE_EPOLL
01053    struct chanlist *epollo;
01054 #endif
01055    struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
01056    /* single is set if only one destination is enabled */
01057    int single = outgoing && !AST_LIST_NEXT(outgoing, node);
01058    int caller_entertained = outgoing
01059       && ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
01060    struct ast_party_connected_line connected_caller;
01061    struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
01062    int cc_recall_core_id;
01063    int is_cc_recall;
01064    int cc_frame_received = 0;
01065    int num_ringing = 0;
01066    struct timeval start = ast_tvnow();
01067 
01068    ast_party_connected_line_init(&connected_caller);
01069    if (single) {
01070       /* Turn off hold music, etc */
01071       if (!caller_entertained) {
01072          ast_deactivate_generator(in);
01073          /* If we are calling a single channel, and not providing ringback or music, */
01074          /* then, make them compatible for in-band tone purpose */
01075          if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
01076             /* If these channels can not be made compatible,
01077              * there is no point in continuing.  The bridge
01078              * will just fail if it gets that far.
01079              */
01080             *to = -1;
01081             strcpy(pa->status, "CONGESTION");
01082             ast_channel_publish_dial(in, outgoing->chan, NULL, pa->status);
01083             return NULL;
01084          }
01085       }
01086 
01087       if (!ast_test_flag64(outgoing, OPT_IGNORE_CONNECTEDLINE)
01088          && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
01089          ast_channel_lock(outgoing->chan);
01090          ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(outgoing->chan));
01091          ast_channel_unlock(outgoing->chan);
01092          connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
01093          if (ast_channel_connected_line_sub(outgoing->chan, in, &connected_caller, 0) &&
01094             ast_channel_connected_line_macro(outgoing->chan, in, &connected_caller, 1, 0)) {
01095             ast_channel_update_connected_line(in, &connected_caller, NULL);
01096          }
01097          ast_party_connected_line_free(&connected_caller);
01098       }
01099    }
01100 
01101    is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
01102 
01103 #ifdef HAVE_EPOLL
01104    AST_LIST_TRAVERSE(out_chans, epollo, node) {
01105       ast_poll_channel_add(in, epollo->chan);
01106    }
01107 #endif
01108 
01109    while ((*to = ast_remaining_ms(start, orig)) && !peer) {
01110       struct chanlist *o;
01111       int pos = 0; /* how many channels do we handle */
01112       int numlines = prestart;
01113       struct ast_channel *winner;
01114       struct ast_channel *watchers[AST_MAX_WATCHERS];
01115 
01116       watchers[pos++] = in;
01117       AST_LIST_TRAVERSE(out_chans, o, node) {
01118          /* Keep track of important channels */
01119          if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
01120             watchers[pos++] = o->chan;
01121          numlines++;
01122       }
01123       if (pos == 1) { /* only the input channel is available */
01124          if (numlines == (num.busy + num.congestion + num.nochan)) {
01125             ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
01126             if (num.busy)
01127                strcpy(pa->status, "BUSY");
01128             else if (num.congestion)
01129                strcpy(pa->status, "CONGESTION");
01130             else if (num.nochan)
01131                strcpy(pa->status, "CHANUNAVAIL");
01132          } else {
01133             ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
01134          }
01135          *to = 0;
01136          if (is_cc_recall) {
01137             ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
01138          }
01139          return NULL;
01140       }
01141       winner = ast_waitfor_n(watchers, pos, to);
01142       AST_LIST_TRAVERSE(out_chans, o, node) {
01143          struct ast_frame *f;
01144          struct ast_channel *c = o->chan;
01145 
01146          if (c == NULL)
01147             continue;
01148          if (ast_test_flag64(o, DIAL_STILLGOING) && ast_channel_state(c) == AST_STATE_UP) {
01149             if (!peer) {
01150                ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
01151                if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
01152                   if (o->pending_connected_update) {
01153                      if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
01154                         ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
01155                         ast_channel_update_connected_line(in, &o->connected, NULL);
01156                      }
01157                   } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
01158                      ast_channel_lock(c);
01159                      ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(c));
01160                      ast_channel_unlock(c);
01161                      connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
01162                      if (ast_channel_connected_line_sub(c, in, &connected_caller, 0) &&
01163                         ast_channel_connected_line_macro(c, in, &connected_caller, 1, 0)) {
01164                         ast_channel_update_connected_line(in, &connected_caller, NULL);
01165                      }
01166                      ast_party_connected_line_free(&connected_caller);
01167                   }
01168                }
01169                if (o->aoc_s_rate_list) {
01170                   size_t encoded_size;
01171                   struct ast_aoc_encoded *encoded;
01172                   if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
01173                      ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
01174                      ast_aoc_destroy_encoded(encoded);
01175                   }
01176                }
01177                peer = c;
01178                ast_copy_flags64(peerflags, o,
01179                   OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
01180                   OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
01181                   OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
01182                   OPT_CALLEE_PARK | OPT_CALLER_PARK |
01183                   OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
01184                   DIAL_NOFORWARDHTML);
01185                ast_channel_dialcontext_set(c, "");
01186                ast_channel_exten_set(c, "");
01187             }
01188             continue;
01189          }
01190          if (c != winner)
01191             continue;
01192          /* here, o->chan == c == winner */
01193          if (!ast_strlen_zero(ast_channel_call_forward(c))) {
01194             pa->sentringing = 0;
01195             if (!ignore_cc && (f = ast_read(c))) {
01196                if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
01197                   /* This channel is forwarding the call, and is capable of CC, so
01198                    * be sure to add the new device interface to the list
01199                    */
01200                   ast_handle_cc_control_frame(in, c, f->data.ptr);
01201                }
01202                ast_frfree(f);
01203             }
01204 
01205             if (o->pending_connected_update) {
01206                /*
01207                 * Re-seed the chanlist's connected line information with
01208                 * previously acquired connected line info from the incoming
01209                 * channel.  The previously acquired connected line info could
01210                 * have been set through the CONNECTED_LINE dialplan function.
01211                 */
01212                o->pending_connected_update = 0;
01213                ast_channel_lock(in);
01214                ast_party_connected_line_copy(&o->connected, ast_channel_connected(in));
01215                ast_channel_unlock(in);
01216             }
01217 
01218             do_forward(o, &num, peerflags, single, caller_entertained, &orig,
01219                forced_clid, stored_clid);
01220 
01221             if (single && o->chan
01222                && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)
01223                && !ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
01224                ast_channel_lock(o->chan);
01225                ast_connected_line_copy_from_caller(&connected_caller,
01226                   ast_channel_caller(o->chan));
01227                ast_channel_unlock(o->chan);
01228                connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
01229                if (ast_channel_connected_line_sub(o->chan, in, &connected_caller, 0) &&
01230                   ast_channel_connected_line_macro(o->chan, in, &connected_caller, 1, 0)) {
01231                   ast_channel_update_connected_line(in, &connected_caller, NULL);
01232                }
01233                ast_party_connected_line_free(&connected_caller);
01234             }
01235             continue;
01236          }
01237          f = ast_read(winner);
01238          if (!f) {
01239             ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
01240 #ifdef HAVE_EPOLL
01241             ast_poll_channel_del(in, c);
01242 #endif
01243             ast_channel_publish_dial(in, c, NULL, ast_hangup_cause_to_dial_status(ast_channel_hangupcause(c)));
01244             ast_hangup(c);
01245             c = o->chan = NULL;
01246             ast_clear_flag64(o, DIAL_STILLGOING);
01247             handle_cause(ast_channel_hangupcause(in), &num);
01248             continue;
01249          }
01250          switch (f->frametype) {
01251          case AST_FRAME_CONTROL:
01252             switch (f->subclass.integer) {
01253             case AST_CONTROL_ANSWER:
01254                /* This is our guy if someone answered. */
01255                if (!peer) {
01256                   ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
01257                   if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
01258                      if (o->pending_connected_update) {
01259                         if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
01260                            ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
01261                            ast_channel_update_connected_line(in, &o->connected, NULL);
01262                         }
01263                      } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
01264                         ast_channel_lock(c);
01265                         ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(c));
01266                         ast_channel_unlock(c);
01267                         connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
01268                         if (ast_channel_connected_line_sub(c, in, &connected_caller, 0) &&
01269                            ast_channel_connected_line_macro(c, in, &connected_caller, 1, 0)) {
01270                            ast_channel_update_connected_line(in, &connected_caller, NULL);
01271                         }
01272                         ast_party_connected_line_free(&connected_caller);
01273                      }
01274                   }
01275                   if (o->aoc_s_rate_list) {
01276                      size_t encoded_size;
01277                      struct ast_aoc_encoded *encoded;
01278                      if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
01279                         ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
01280                         ast_aoc_destroy_encoded(encoded);
01281                      }
01282                   }
01283                   peer = c;
01284                   /* Inform everyone else that they've been canceled.
01285                    * The dial end event for the peer will be sent out after
01286                    * other Dial options have been handled.
01287                    */
01288                   publish_dial_end_event(in, out_chans, peer, "CANCEL");
01289                   ast_copy_flags64(peerflags, o,
01290                      OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
01291                      OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
01292                      OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
01293                      OPT_CALLEE_PARK | OPT_CALLER_PARK |
01294                      OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
01295                      DIAL_NOFORWARDHTML);
01296                   ast_channel_dialcontext_set(c, "");
01297                   ast_channel_exten_set(c, "");
01298                   if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
01299                      /* Setup early bridge if appropriate */
01300                      ast_channel_early_bridge(in, peer);
01301                   }
01302                }
01303                /* If call has been answered, then the eventual hangup is likely to be normal hangup */
01304                ast_channel_hangupcause_set(in, AST_CAUSE_NORMAL_CLEARING);
01305                ast_channel_hangupcause_set(c, AST_CAUSE_NORMAL_CLEARING);
01306                break;
01307             case AST_CONTROL_BUSY:
01308                ast_verb(3, "%s is busy\n", ast_channel_name(c));
01309                ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
01310                ast_channel_publish_dial(in, c, NULL, "BUSY");
01311                ast_hangup(c);
01312                c = o->chan = NULL;
01313                ast_clear_flag64(o, DIAL_STILLGOING);
01314                handle_cause(AST_CAUSE_BUSY, &num);
01315                break;
01316             case AST_CONTROL_CONGESTION:
01317                ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
01318                ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
01319                ast_channel_publish_dial(in, c, NULL, "CONGESTION");
01320                ast_hangup(c);
01321                c = o->chan = NULL;
01322                ast_clear_flag64(o, DIAL_STILLGOING);
01323                handle_cause(AST_CAUSE_CONGESTION, &num);
01324                break;
01325             case AST_CONTROL_RINGING:
01326                /* This is a tricky area to get right when using a native
01327                 * CC agent. The reason is that we do the best we can to send only a
01328                 * single ringing notification to the caller.
01329                 *
01330                 * Call completion complicates the logic used here. CCNR is typically
01331                 * offered during a ringing message. Let's say that party A calls
01332                 * parties B, C, and D. B and C do not support CC requests, but D
01333                 * does. If we were to receive a ringing notification from B before
01334                 * the others, then we would end up sending a ringing message to
01335                 * A with no CCNR offer present.
01336                 *
01337                 * The approach that we have taken is that if we receive a ringing
01338                 * response from a party and no CCNR offer is present, we need to
01339                 * wait. Specifically, we need to wait until either a) a called party
01340                 * offers CCNR in its ringing response or b) all called parties have
01341                 * responded in some way to our call and none offers CCNR.
01342                 *
01343                 * The drawback to this is that if one of the parties has a delayed
01344                 * response or, god forbid, one just plain doesn't respond to our
01345                 * outgoing call, then this will result in a significant delay between
01346                 * when the caller places the call and hears ringback.
01347                 *
01348                 * Note also that if CC is disabled for this call, then it is perfectly
01349                 * fine for ringing frames to get sent through.
01350                 */
01351                ++num_ringing;
01352                if (ignore_cc || cc_frame_received || num_ringing == numlines) {
01353                   ast_verb(3, "%s is ringing\n", ast_channel_name(c));
01354                   /* Setup early media if appropriate */
01355                   if (single && !caller_entertained
01356                      && CAN_EARLY_BRIDGE(peerflags, in, c)) {
01357                      ast_channel_early_bridge(in, c);
01358                   }
01359                   if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
01360                      ast_indicate(in, AST_CONTROL_RINGING);
01361                      pa->sentringing++;
01362                   }
01363                }
01364                break;
01365             case AST_CONTROL_PROGRESS:
01366                ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
01367                /* Setup early media if appropriate */
01368                if (single && !caller_entertained
01369                   && CAN_EARLY_BRIDGE(peerflags, in, c)) {
01370                   ast_channel_early_bridge(in, c);
01371                }
01372                if (!ast_test_flag64(outgoing, OPT_RINGBACK)) {
01373                   if (single || (!single && !pa->sentringing)) {
01374                      ast_indicate(in, AST_CONTROL_PROGRESS);
01375                   }
01376                }
01377                if (!ast_strlen_zero(dtmf_progress)) {
01378                   ast_verb(3,
01379                      "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n",
01380                      dtmf_progress);
01381                   ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
01382                }
01383                break;
01384             case AST_CONTROL_VIDUPDATE:
01385             case AST_CONTROL_SRCUPDATE:
01386             case AST_CONTROL_SRCCHANGE:
01387                if (!single || caller_entertained) {
01388                   break;
01389                }
01390                ast_verb(3, "%s requested media update control %d, passing it to %s\n",
01391                   ast_channel_name(c), f->subclass.integer, ast_channel_name(in));
01392                ast_indicate(in, f->subclass.integer);
01393                break;
01394             case AST_CONTROL_CONNECTED_LINE:
01395                if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
01396                   ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
01397                   break;
01398                }
01399                if (!single) {
01400                   struct ast_party_connected_line connected;
01401 
01402                   ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
01403                      ast_channel_name(c), ast_channel_name(in));
01404                   ast_party_connected_line_set_init(&connected, &o->connected);
01405                   ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
01406                   ast_party_connected_line_set(&o->connected, &connected, NULL);
01407                   ast_party_connected_line_free(&connected);
01408                   o->pending_connected_update = 1;
01409                   break;
01410                }
01411                if (ast_channel_connected_line_sub(c, in, f, 1) &&
01412                   ast_channel_connected_line_macro(c, in, f, 1, 1)) {
01413                   ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
01414                }
01415                break;
01416             case AST_CONTROL_AOC:
01417                {
01418                   struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
01419                   if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
01420                      ast_aoc_destroy_decoded(o->aoc_s_rate_list);
01421                      o->aoc_s_rate_list = decoded;
01422                   } else {
01423                      ast_aoc_destroy_decoded(decoded);
01424                   }
01425                }
01426                break;
01427             case AST_CONTROL_REDIRECTING:
01428                if (!single) {
01429                   /*
01430                    * Redirecting updates to the caller make sense only on single
01431                    * calls.
01432                    */
01433                   break;
01434                }
01435                if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
01436                   ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
01437                   break;
01438                }
01439                ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
01440                   ast_channel_name(c), ast_channel_name(in));
01441                if (ast_channel_redirecting_sub(c, in, f, 1) &&
01442                   ast_channel_redirecting_macro(c, in, f, 1, 1)) {
01443                   ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
01444                }
01445                pa->sentringing = 0;
01446                break;
01447             case AST_CONTROL_PROCEEDING:
01448                ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
01449                if (single && !caller_entertained
01450                   && CAN_EARLY_BRIDGE(peerflags, in, c)) {
01451                   ast_channel_early_bridge(in, c);
01452                }
01453                if (!ast_test_flag64(outgoing, OPT_RINGBACK))
01454                   ast_indicate(in, AST_CONTROL_PROCEEDING);
01455                break;
01456             case AST_CONTROL_HOLD:
01457                /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
01458                ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
01459                ast_indicate_data(in, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
01460                break;
01461             case AST_CONTROL_UNHOLD:
01462                /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
01463                ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
01464                ast_indicate(in, AST_CONTROL_UNHOLD);
01465                break;
01466             case AST_CONTROL_OFFHOOK:
01467             case AST_CONTROL_FLASH:
01468                /* Ignore going off hook and flash */
01469                break;
01470             case AST_CONTROL_CC:
01471                if (!ignore_cc) {
01472                   ast_handle_cc_control_frame(in, c, f->data.ptr);
01473                   cc_frame_received = 1;
01474                }
01475                break;
01476             case AST_CONTROL_PVT_CAUSE_CODE:
01477                ast_indicate_data(in, AST_CONTROL_PVT_CAUSE_CODE, f->data.ptr, f->datalen);
01478                break;
01479             case -1:
01480                if (single && !caller_entertained) {
01481                   ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
01482                   ast_indicate(in, -1);
01483                   pa->sentringing = 0;
01484                }
01485                break;
01486             default:
01487                ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
01488                break;
01489             }
01490             break;
01491          case AST_FRAME_VOICE:
01492          case AST_FRAME_IMAGE:
01493             if (caller_entertained) {
01494                break;
01495             }
01496             /* Fall through */
01497          case AST_FRAME_TEXT:
01498             if (single && ast_write(in, f)) {
01499                ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
01500                   f->frametype);
01501             }
01502             break;
01503          case AST_FRAME_HTML:
01504             if (single && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)
01505                && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
01506                ast_log(LOG_WARNING, "Unable to send URL\n");
01507             }
01508             break;
01509          default:
01510             break;
01511          }
01512          ast_frfree(f);
01513       } /* end for */
01514       if (winner == in) {
01515          struct ast_frame *f = ast_read(in);
01516 #if 0
01517          if (f && (f->frametype != AST_FRAME_VOICE))
01518             printf("Frame type: %d, %d\n", f->frametype, f->subclass);
01519          else if (!f || (f->frametype != AST_FRAME_VOICE))
01520             printf("Hangup received on %s\n", in->name);
01521 #endif
01522          if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
01523             /* Got hung up */
01524             *to = -1;
01525             strcpy(pa->status, "CANCEL");
01526             publish_dial_end_event(in, out_chans, NULL, pa->status);
01527             if (f) {
01528                if (f->data.uint32) {
01529                   ast_channel_hangupcause_set(in, f->data.uint32);
01530                }
01531                ast_frfree(f);
01532             }
01533             if (is_cc_recall) {
01534                ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
01535             }
01536             return NULL;
01537          }
01538 
01539          /* now f is guaranteed non-NULL */
01540          if (f->frametype == AST_FRAME_DTMF) {
01541             if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
01542                const char *context;
01543                ast_channel_lock(in);
01544                context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
01545                if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
01546                   ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
01547                   *to = 0;
01548                   *result = f->subclass.integer;
01549                   strcpy(pa->status, "CANCEL");
01550                   publish_dial_end_event(in, out_chans, NULL, pa->status);
01551                   ast_frfree(f);
01552                   ast_channel_unlock(in);
01553                   if (is_cc_recall) {
01554                      ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
01555                   }
01556                   return NULL;
01557                }
01558                ast_channel_unlock(in);
01559             }
01560 
01561             if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
01562                detect_disconnect(in, f->subclass.integer, &featurecode)) {
01563                ast_verb(3, "User requested call disconnect.\n");
01564                *to = 0;
01565                strcpy(pa->status, "CANCEL");
01566                publish_dial_end_event(in, out_chans, NULL, pa->status);
01567                ast_frfree(f);
01568                if (is_cc_recall) {
01569                   ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
01570                }
01571                return NULL;
01572             }
01573          }
01574 
01575          /* Send the frame from the in channel to all outgoing channels. */
01576          AST_LIST_TRAVERSE(out_chans, o, node) {
01577             if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
01578                /* This outgoing channel has died so don't send the frame to it. */
01579                continue;
01580             }
01581             switch (f->frametype) {
01582             case AST_FRAME_HTML:
01583                /* Forward HTML stuff */
01584                if (!ast_test_flag64(o, DIAL_NOFORWARDHTML)
01585                   && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
01586                   ast_log(LOG_WARNING, "Unable to send URL\n");
01587                }
01588                break;
01589             case AST_FRAME_VOICE:
01590             case AST_FRAME_IMAGE:
01591                if (!single || caller_entertained) {
01592                   /*
01593                    * We are calling multiple parties or caller is being
01594                    * entertained and has thus not been made compatible.
01595                    * No need to check any other called parties.
01596                    */
01597                   goto skip_frame;
01598                }
01599                /* Fall through */
01600             case AST_FRAME_TEXT:
01601             case AST_FRAME_DTMF_BEGIN:
01602             case AST_FRAME_DTMF_END:
01603                if (ast_write(o->chan, f)) {
01604                   ast_log(LOG_WARNING, "Unable to forward frametype: %u\n",
01605                      f->frametype);
01606                }
01607                break;
01608             case AST_FRAME_CONTROL:
01609                switch (f->subclass.integer) {
01610                case AST_CONTROL_HOLD:
01611                   ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
01612                   ast_indicate_data(o->chan, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
01613                   break;
01614                case AST_CONTROL_UNHOLD:
01615                   ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
01616                   ast_indicate(o->chan, AST_CONTROL_UNHOLD);
01617                   break;
01618                case AST_CONTROL_VIDUPDATE:
01619                case AST_CONTROL_SRCUPDATE:
01620                case AST_CONTROL_SRCCHANGE:
01621                   if (!single || caller_entertained) {
01622                      /*
01623                       * We are calling multiple parties or caller is being
01624                       * entertained and has thus not been made compatible.
01625                       * No need to check any other called parties.
01626                       */
01627                      goto skip_frame;
01628                   }
01629                   ast_verb(3, "%s requested media update control %d, passing it to %s\n",
01630                      ast_channel_name(in), f->subclass.integer, ast_channel_name(o->chan));
01631                   ast_indicate(o->chan, f->subclass.integer);
01632                   break;
01633                case AST_CONTROL_CONNECTED_LINE:
01634                   if (ast_channel_connected_line_sub(in, o->chan, f, 1) &&
01635                      ast_channel_connected_line_macro(in, o->chan, f, 0, 1)) {
01636                      ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
01637                   }
01638                   break;
01639                case AST_CONTROL_REDIRECTING:
01640                   if (ast_channel_redirecting_sub(in, o->chan, f, 1) &&
01641                      ast_channel_redirecting_macro(in, o->chan, f, 0, 1)) {
01642                      ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
01643                   }
01644                   break;
01645                default:
01646                   /* We are not going to do anything with this frame. */
01647                   goto skip_frame;
01648                }
01649                break;
01650             default:
01651                /* We are not going to do anything with this frame. */
01652                goto skip_frame;
01653             }
01654          }
01655 skip_frame:;
01656          ast_frfree(f);
01657       }
01658    }
01659 
01660    if (!*to || ast_check_hangup(in)) {
01661       ast_verb(3, "Nobody picked up in %d ms\n", orig);
01662       publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
01663    }
01664 
01665 #ifdef HAVE_EPOLL
01666    AST_LIST_TRAVERSE(out_chans, epollo, node) {
01667       if (epollo->chan)
01668          ast_poll_channel_del(in, epollo->chan);
01669    }
01670 #endif
01671 
01672    if (is_cc_recall) {
01673       ast_cc_completed(in, "Recall completed!");
01674    }
01675    return peer;
01676 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Dialing Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 3264 of file app_dial.c.

const char app[] = "Dial" [static]

Definition at line 568 of file app_dial.c.

Definition at line 3264 of file app_dial.c.

struct ast_app_option dial_exec_options[128] = { [ 'A' ] = { .flag = OPT_ANNOUNCE , .arg_index = OPT_ARG_ANNOUNCE + 1 }, [ 'a' ] = { .flag = (1LLU << 40) }, [ 'b' ] = { .flag = (1LLU << 41) , .arg_index = OPT_ARG_PREDIAL_CALLEE + 1 }, [ 'B' ] = { .flag = (1LLU << 42) , .arg_index = OPT_ARG_PREDIAL_CALLER + 1 }, [ 'C' ] = { .flag = OPT_RESETCDR }, [ 'c' ] = { .flag = (1LLU << 34) }, [ 'd' ] = { .flag = OPT_DTMF_EXIT }, [ 'D' ] = { .flag = OPT_SENDDTMF , .arg_index = OPT_ARG_SENDDTMF + 1 }, [ 'e' ] = { .flag = (1LLU << 35) }, [ 'f' ] = { .flag = OPT_FORCECLID , .arg_index = OPT_ARG_FORCECLID + 1 }, [ 'F' ] = { .flag = (1LLU << 36) , .arg_index = OPT_ARG_CALLEE_GO_ON + 1 }, [ 'g' ] = { .flag = OPT_GO_ON }, [ 'G' ] = { .flag = OPT_GOTO , .arg_index = OPT_ARG_GOTO + 1 }, [ 'h' ] = { .flag = OPT_CALLEE_HANGUP }, [ 'H' ] = { .flag = OPT_CALLER_HANGUP }, [ 'i' ] = { .flag = OPT_IGNORE_FORWARDING }, [ 'I' ] = { .flag = OPT_IGNORE_CONNECTEDLINE }, [ 'k' ] = { .flag = OPT_CALLEE_PARK }, [ 'K' ] = { .flag = OPT_CALLER_PARK }, [ 'L' ] = { .flag = OPT_DURATION_LIMIT , .arg_index = OPT_ARG_DURATION_LIMIT + 1 }, [ 'm' ] = { .flag = OPT_MUSICBACK , .arg_index = OPT_ARG_MUSICBACK + 1 }, [ 'M' ] = { .flag = OPT_CALLEE_MACRO , .arg_index = OPT_ARG_CALLEE_MACRO + 1 }, [ 'n' ] = { .flag = OPT_SCREEN_NOINTRO , .arg_index = OPT_ARG_SCREEN_NOINTRO + 1 }, [ 'N' ] = { .flag = OPT_SCREEN_NOCALLERID }, [ 'o' ] = { .flag = OPT_ORIGINAL_CLID , .arg_index = OPT_ARG_ORIGINAL_CLID + 1 }, [ 'O' ] = { .flag = OPT_OPERMODE , .arg_index = OPT_ARG_OPERMODE + 1 }, [ 'p' ] = { .flag = OPT_SCREENING }, [ 'P' ] = { .flag = OPT_PRIVACY , .arg_index = OPT_ARG_PRIVACY + 1 }, [ 'r' ] = { .flag = OPT_RINGBACK , .arg_index = OPT_ARG_RINGBACK + 1 }, [ 'R' ] = { .flag = (1LLU << 43) }, [ 'S' ] = { .flag = OPT_DURATION_STOP , .arg_index = OPT_ARG_DURATION_STOP + 1 }, [ 's' ] = { .flag = (1LLU << 38) , .arg_index = OPT_ARG_FORCE_CID_TAG + 1 }, [ 't' ] = { .flag = OPT_CALLEE_TRANSFER }, [ 'T' ] = { .flag = OPT_CALLER_TRANSFER }, [ 'u' ] = { .flag = (1LLU << 39) , .arg_index = OPT_ARG_FORCE_CID_PRES + 1 }, [ 'U' ] = { .flag = OPT_CALLEE_GOSUB , .arg_index = OPT_ARG_CALLEE_GOSUB + 1 }, [ 'w' ] = { .flag = OPT_CALLEE_MONITOR }, [ 'W' ] = { .flag = OPT_CALLER_MONITOR }, [ 'x' ] = { .flag = OPT_CALLEE_MIXMONITOR }, [ 'X' ] = { .flag = OPT_CALLER_MIXMONITOR }, [ 'z' ] = { .flag = (1LLU << 37) }, } [static]

Definition at line 686 of file app_dial.c.

Referenced by dial_exec_full().

const char rapp[] = "RetryDial" [static]

Definition at line 569 of file app_dial.c.


Generated on Thu Apr 16 06:28:24 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6