Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions | Variables
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 <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/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 "asterisk/max_forwards.h"
#include "asterisk/stream.h"

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
 

Macros

#define AST_MAX_WATCHERS   256
 
#define CAN_EARLY_BRIDGE(flags, chan, peer)
 
#define DIAL_CALLERID_ABSENT   (1LLU << 33) /* TRUE if caller id is not available for connected line. */
 
#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_HANGUPCAUSE   (1LLU << 44)
 
#define OPT_HEARPULSING   (1LLU << 45)
 
#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)
 
#define OPT_TOPOLOGY_PRESERVE   (1LLU << 46)
 

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_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_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_HANGUPCAUSE, OPT_ARG_ARRAY_SIZE
}
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 hangupcause)
 
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 set_duration_var (struct ast_channel *chan, const char *var_base, int64_t duration)
 
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 void topology_ds_destroy (void *data)
 
static int unload_module (void)
 
static void update_connected_line_from_peer (struct ast_channel *chan, struct ast_channel *peer, int is_caller)
 
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_answer, int *to_progress, struct ast_flags64 *peerflags, char *opt_args[], struct privacy_args *pa, const struct cause_args *num_in, int *result, char *dtmf_progress, char *mf_progress, char *mf_wink, char *sf_progress, char *sf_wink, const int hearpulsing, const int ignore_cc, struct ast_party_id *forced_clid, struct ast_party_id *stored_clid, struct ast_bridge_config *config)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "ccss", }
 
static const char app [] = "Dial"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const 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 << 45) }, [ '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 }, [ 'j' ] = { .flag = (1LLU << 46) }, [ '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 }, [ '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 }, [ 'Q' ] = { .flag = (1LLU << 44) , .arg_index = OPT_ARG_HANGUPCAUSE + 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"
 
static const struct ast_datastore_info topology_ds_info
 

Detailed Description

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

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_dial.c.

Function Documentation

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 2297 of file app_dial.c.

References ast_bridge_config::answer_topology, ao2_ref, ast_answer(), AST_APP_ARG, 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_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_clear_flag(), ast_channel_connected_line_sub(), ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_inherit(), ast_channel_early_bridge(), ast_channel_get_device_name(), ast_channel_get_stream_topology(), ast_channel_inherit_variables(), ast_channel_lock_both, ast_channel_make_compatible(), AST_CHANNEL_NAME, ast_channel_publish_dial(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_sendurl(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_set_flag(), ast_channel_setoption(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_supports_html(), ast_channel_whentohangup_set(), ast_check_hangup(), ast_connected_line_copy_from_caller(), AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, ast_copy_string(), ast_deactivate_generator(), ast_debug, AST_DECLARE_APP_ARGS, ast_dtmf_stream(), ast_exists_extension(), ast_filedelete(), ast_fileexists(), AST_FLAG_END_DTMF_ONLY, AST_FLAG_OUTGOING, AST_FRAME_CONTROL, AST_FRAME_DTMF_END, ast_hangup(), ast_ignore_cc(), ast_indicate(), ast_indicate_data(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_MAX_EXTENSION, ast_moh_start(), ast_moh_stop(), 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_read(), ast_replace_subargument_delimiter(), ast_request_with_stream_topology(), ast_rtp_instance_early_bridge_make_compatible(), ast_sched_runq(), ast_sched_wait(), ast_senddigit(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_str2cause(), ast_str_tmp, ast_strdup, ast_strdupa, ast_stream_get_state(), ast_stream_set_state(), AST_STREAM_STATE_RECVONLY, AST_STREAM_STATE_SENDONLY, ast_stream_topology_clone(), ast_stream_topology_free(), ast_stream_topology_get_count(), ast_stream_topology_get_stream(), ast_stream_topology_to_str(), ast_streamfile(), ast_strip(), ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_waitfor_n(), chanlist::connected, ast_datastore::data, ast_frame::data, ast_frame::datalen, ast_bridge_config::end_bridge_callback, ast_bridge_config::end_bridge_callback_data, ast_bridge_config::end_bridge_callback_data_fixup, ast_frame::frametype, ast_party_caller::id, ast_party_connected_line::id, ast_frame_subclass::integer, chanlist::interface, ast_party_id::name, ast_party_id::number, chanlist::number, chanlist::orig_chan_name, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), ast_party_number::presentation, S_COR, setup_privacy_args(), ast_party_name::str, ast_party_number::str, ast_party_subaddress::str, chanlist::stuff, ast_party_id::subaddress, ast_frame::subclass, ast_party_id::tag, ast_channel::tech, chanlist::tech, ast_party_dialed::transit_network_select, ast_party_name::valid, ast_party_number::valid, and wait_for_answer().

2298 {
2299  int res = -1; /* default: error */
2300  char *rest, *cur; /* scan the list of destinations */
2301  struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2302  struct chanlist *outgoing;
2303  struct chanlist *tmp;
2304  struct ast_channel *peer = NULL;
2305  int to_answer, to_progress; /* timeouts */
2306  struct cause_args num = { chan, 0, 0, 0 };
2307  int cause, hanguptreecause = -1;
2308 
2309  struct ast_bridge_config config = { { 0, } };
2310  struct timeval calldurationlimit = { 0, };
2311  char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL;
2312  char *mf_progress = NULL, *mf_wink = NULL;
2313  char *sf_progress = NULL, *sf_wink = NULL;
2314  struct privacy_args pa = {
2315  .sentringing = 0,
2316  .privdb_val = 0,
2317  .status = "INVALIDARGS",
2318  .canceled = 0,
2319  };
2320  int sentringing = 0, moh = 0;
2321  const char *outbound_group = NULL;
2322  int result = 0;
2323  char *parse;
2324  int opermode = 0;
2325  int delprivintro = 0;
2326  AST_DECLARE_APP_ARGS(args,
2327  AST_APP_ARG(peers);
2328  AST_APP_ARG(timeout);
2329  AST_APP_ARG(options);
2330  AST_APP_ARG(url);
2331  );
2332  struct ast_flags64 opts = { 0, };
2333  char *opt_args[OPT_ARG_ARRAY_SIZE];
2334  int fulldial = 0, num_dialed = 0;
2335  int ignore_cc = 0;
2336  char device_name[AST_CHANNEL_NAME];
2337  char forced_clid_name[AST_MAX_EXTENSION];
2338  char stored_clid_name[AST_MAX_EXTENSION];
2339  int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2340  /*!
2341  * \brief Forced CallerID party information to send.
2342  * \note This will not have any malloced strings so do not free it.
2343  */
2344  struct ast_party_id forced_clid;
2345  /*!
2346  * \brief Stored CallerID information if needed.
2347  *
2348  * \note If OPT_ORIGINAL_CLID set then this is the o option
2349  * CallerID. Otherwise it is the dialplan extension and hint
2350  * name.
2351  *
2352  * \note This will not have any malloced strings so do not free it.
2353  */
2354  struct ast_party_id stored_clid;
2355  /*!
2356  * \brief CallerID party information to store.
2357  * \note This will not have any malloced strings so do not free it.
2358  */
2359  struct ast_party_caller caller;
2360  int max_forwards;
2361  struct ast_datastore *topology_ds = NULL;
2362  SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data);
2363 
2364  /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2365  ast_channel_lock(chan);
2367  pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2368  pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2369  pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2370  pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2371  pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");
2372  pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2373  pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");
2374  pbx_builtin_setvar_helper(chan, "RINGTIME", "");
2375  pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");
2376  pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");
2377  pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");
2379  max_forwards = ast_max_forwards_get(chan);
2380  ast_channel_unlock(chan);
2381 
2382  if (max_forwards <= 0) {
2383  ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2384  ast_channel_name(chan));
2385  pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2386  SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan));
2387  }
2388 
2389  if (ast_check_hangup_locked(chan)) {
2390  /*
2391  * Caller hung up before we could dial. If dial is executed
2392  * within an AGI then the AGI has likely eaten all queued
2393  * frames before executing the dial in DeadAGI mode. With
2394  * the caller hung up and no pending frames from the caller's
2395  * read queue, dial would not know that the call has hung up
2396  * until a called channel answers. It is rather annoying to
2397  * whoever just answered the non-existent call.
2398  *
2399  * Dial should not continue execution in DeadAGI mode, hangup
2400  * handlers, or the h exten.
2401  */
2402  ast_verb(3, "Caller hung up before dial.\n");
2403  pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
2404  SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan));
2405  }
2406 
2407  parse = ast_strdupa(data ?: "");
2408 
2409  AST_STANDARD_APP_ARGS(args, parse);
2410 
2411  if (!ast_strlen_zero(args.options) &&
2412  ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2413  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2414  goto done;
2415  }
2416 
2417  if (ast_cc_call_init(chan, &ignore_cc)) {
2418  goto done;
2419  }
2420 
2421  if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
2422  delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2423 
2424  if (delprivintro < 0 || delprivintro > 1) {
2425  ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2426  delprivintro = 0;
2427  }
2428  }
2429 
2430  if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2431  opt_args[OPT_ARG_RINGBACK] = NULL;
2432  }
2433 
2434  if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2435  opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2436  ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2437  }
2438 
2439  if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
2440  calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2441  if (!calldurationlimit.tv_sec) {
2442  ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);
2443  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2444  goto done;
2445  }
2446  ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2447  }
2448 
2449  if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2450  sf_wink = opt_args[OPT_ARG_SENDDTMF];
2451  dtmfcalled = strsep(&sf_wink, ":");
2452  dtmfcalling = strsep(&sf_wink, ":");
2453  dtmf_progress = strsep(&sf_wink, ":");
2454  mf_progress = strsep(&sf_wink, ":");
2455  mf_wink = strsep(&sf_wink, ":");
2456  sf_progress = strsep(&sf_wink, ":");
2457  }
2458 
2459  if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
2460  if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2461  goto done;
2462  }
2463 
2464  /* Setup the forced CallerID information to send if used. */
2465  ast_party_id_init(&forced_clid);
2466  force_forwards_only = 0;
2467  if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2468  if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2469  ast_channel_lock(chan);
2470  forced_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2471  ast_channel_unlock(chan);
2472  forced_clid_name[0] = '\0';
2473  forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2474  sizeof(forced_clid_name), chan);
2475  force_forwards_only = 1;
2476  } else {
2477  /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2478  ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2479  &forced_clid.number.str);
2480  }
2481  if (!ast_strlen_zero(forced_clid.name.str)) {
2482  forced_clid.name.valid = 1;
2483  }
2484  if (!ast_strlen_zero(forced_clid.number.str)) {
2485  forced_clid.number.valid = 1;
2486  }
2487  }
2488  if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG)
2489  && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2490  forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2491  }
2492  forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
2493  if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES)
2494  && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2495  int pres;
2496 
2497  pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
2498  if (0 <= pres) {
2499  forced_clid.number.presentation = pres;
2500  }
2501  }
2502 
2503  /* Setup the stored CallerID information if needed. */
2504  ast_party_id_init(&stored_clid);
2505  if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2506  if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2507  ast_channel_lock(chan);
2508  ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2509  if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2510  stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2511  }
2512  if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2513  stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2514  }
2515  if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2516  stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2517  }
2518  if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2519  stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2520  }
2521  ast_channel_unlock(chan);
2522  } else {
2523  /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2524  ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2525  &stored_clid.number.str);
2526  if (!ast_strlen_zero(stored_clid.name.str)) {
2527  stored_clid.name.valid = 1;
2528  }
2529  if (!ast_strlen_zero(stored_clid.number.str)) {
2530  stored_clid.number.valid = 1;
2531  }
2532  }
2533  } else {
2534  /*
2535  * In case the new channel has no preset CallerID number by the
2536  * channel driver, setup the dialplan extension and hint name.
2537  */
2538  stored_clid_name[0] = '\0';
2539  stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2540  sizeof(stored_clid_name), chan);
2541  if (ast_strlen_zero(stored_clid.name.str)) {
2542  stored_clid.name.str = NULL;
2543  } else {
2544  stored_clid.name.valid = 1;
2545  }
2546  ast_channel_lock(chan);
2547  stored_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2548  stored_clid.number.valid = 1;
2549  ast_channel_unlock(chan);
2550  }
2551 
2552  if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2553  ast_cdr_reset(ast_channel_name(chan), 0);
2554  }
2555  if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
2556  opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan));
2557 
2558  if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
2559  res = setup_privacy_args(&pa, &opts, opt_args, chan);
2560  if (res <= 0)
2561  goto out;
2562  res = -1; /* reset default */
2563  }
2564 
2565  if (continue_exec)
2566  *continue_exec = 0;
2567 
2568  /* If a channel group has been specified, get it for use when we create peer channels */
2569 
2570  ast_channel_lock(chan);
2571  if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2572  outbound_group = ast_strdupa(outbound_group);
2573  pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2574  } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2575  outbound_group = ast_strdupa(outbound_group);
2576  }
2577  ast_channel_unlock(chan);
2578 
2579  /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2580  ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID
2581  | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_CANCEL_TIMEOUT
2582  | OPT_ANNOUNCE | OPT_CALLEE_GOSUB | OPT_FORCECLID);
2583 
2584  /* PREDIAL: Run gosub on the caller's channel */
2585  if (ast_test_flag64(&opts, OPT_PREDIAL_CALLER)
2586  && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2587  ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
2588  ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2589  }
2590 
2591  /* loop through the list of dial destinations */
2592  rest = args.peers;
2593  while ((cur = strsep(&rest, "&"))) {
2594  struct ast_channel *tc; /* channel for this destination */
2595  char *number;
2596  char *tech;
2597  int i;
2598  size_t tech_len;
2599  size_t number_len;
2600  struct ast_stream_topology *topology;
2601  struct ast_stream *stream;
2602 
2603  cur = ast_strip(cur);
2604  if (ast_strlen_zero(cur)) {
2605  /* No tech/resource in this position. */
2606  continue;
2607  }
2608 
2609  /* Get a technology/resource pair */
2610  number = cur;
2611  tech = strsep(&number, "/");
2612 
2613  num_dialed++;
2614  if (ast_strlen_zero(number)) {
2615  ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2616  goto out;
2617  }
2618 
2619  tech_len = strlen(tech) + 1;
2620  number_len = strlen(number) + 1;
2621  tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2622  if (!tmp) {
2623  goto out;
2624  }
2625 
2626  /* Save tech, number, and interface. */
2627  cur = tmp->stuff;
2628  strcpy(cur, tech);
2629  tmp->tech = cur;
2630  cur += tech_len;
2631  strcpy(cur, tech);
2632  cur[tech_len - 1] = '/';
2633  tmp->interface = cur;
2634  cur += tech_len;
2635  strcpy(cur, number);
2636  tmp->number = cur;
2637 
2638  if (opts.flags) {
2639  /* Set per outgoing call leg options. */
2640  ast_copy_flags64(tmp, &opts,
2641  OPT_CANCEL_ELSEWHERE |
2642  OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
2643  OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
2644  OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
2645  OPT_CALLEE_PARK | OPT_CALLER_PARK |
2646  OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
2647  OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID | OPT_IGNORE_CONNECTEDLINE |
2648  OPT_RING_WITH_EARLY_MEDIA);
2649  ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
2650  }
2651 
2652  /* Request the peer */
2653 
2654  ast_channel_lock(chan);
2655  /*
2656  * Seed the chanlist's connected line information with previously
2657  * acquired connected line info from the incoming channel. The
2658  * previously acquired connected line info could have been set
2659  * through the CONNECTED_LINE dialplan function.
2660  */
2661  ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan));
2662 
2663  if (ast_test_flag64(&opts, OPT_TOPOLOGY_PRESERVE)) {
2664  topology_ds = ast_channel_datastore_find(chan, &topology_ds_info, NULL);
2665 
2666  if (!topology_ds && (topology_ds = ast_datastore_alloc(&topology_ds_info, NULL))) {
2668  ast_channel_datastore_add(chan, topology_ds);
2669  }
2670  }
2671 
2672  if (topology_ds) {
2673  ao2_ref(topology_ds->data, +1);
2674  topology = topology_ds->data;
2675  } else {
2677  }
2678 
2679  ast_channel_unlock(chan);
2680 
2681  for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
2682  stream = ast_stream_topology_get_stream(topology, i);
2683  /* For both recvonly and sendonly the stream state reflects our state, that is we
2684  * are receiving only and we are sending only. Since we are requesting a
2685  * channel for the peer, we need to swap this to reflect what we will be doing.
2686  * That is, if we are receiving from Alice then we want to be sending to Bob,
2687  * so swap recvonly to sendonly and vice versa.
2688  */
2691  } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {
2693  }
2694  }
2695 
2696  tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
2697 
2698  ast_stream_topology_free(topology);
2699 
2700  if (!tc) {
2701  /* If we can't, just go on to the next call */
2702  /* Failure doesn't necessarily mean user error. DAHDI channels could be busy. */
2703  ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n",
2704  tmp->tech, cause, ast_cause2str(cause));
2705  handle_cause(cause, &num);
2706  if (!rest) {
2707  /* we are on the last destination */
2708  ast_channel_hangupcause_set(chan, cause);
2709  }
2710  if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2711  if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2713  }
2714  }
2715  chanlist_free(tmp);
2716  continue;
2717  }
2718 
2719  ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2720  if (!ignore_cc) {
2721  ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2722  }
2723 
2724  ast_channel_lock_both(tc, chan);
2726 
2727  pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2728 
2729  /* Setup outgoing SDP to match incoming one */
2730  if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2731  /* We are on the only destination. */
2733  }
2734 
2735  /* Inherit specially named variables from parent channel */
2738  ast_max_forwards_decrement(tc);
2739 
2740  ast_channel_appl_set(tc, "AppDial");
2741  ast_channel_data_set(tc, "(Outgoing Line)");
2742 
2743  memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2744 
2745  /* Determine CallerID to store in outgoing channel. */
2746  ast_party_caller_set_init(&caller, ast_channel_caller(tc));
2747  if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2748  caller.id = stored_clid;
2749  ast_channel_set_caller_event(tc, &caller, NULL);
2750  ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2751  } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2752  ast_channel_caller(tc)->id.number.str, NULL))) {
2753  /*
2754  * The new channel has no preset CallerID number by the channel
2755  * driver. Use the dialplan extension and hint name.
2756  */
2757  caller.id = stored_clid;
2758  if (!caller.id.name.valid
2759  && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2760  ast_channel_connected(chan)->id.name.str, NULL))) {
2761  /*
2762  * No hint name available. We have a connected name supplied by
2763  * the dialplan we can use instead.
2764  */
2765  caller.id.name.valid = 1;
2766  caller.id.name = ast_channel_connected(chan)->id.name;
2767  }
2768  ast_channel_set_caller_event(tc, &caller, NULL);
2769  ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
2770  } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2771  NULL))) {
2772  /* The new channel has no preset CallerID name by the channel driver. */
2773  if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2774  ast_channel_connected(chan)->id.name.str, NULL))) {
2775  /*
2776  * We have a connected name supplied by the dialplan we can
2777  * use instead.
2778  */
2779  caller.id.name.valid = 1;
2780  caller.id.name = ast_channel_connected(chan)->id.name;
2781  ast_channel_set_caller_event(tc, &caller, NULL);
2782  }
2783  }
2784 
2785  /* Determine CallerID for outgoing channel to send. */
2786  if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2787  struct ast_party_connected_line connected;
2788 
2789  ast_party_connected_line_set_init(&connected, ast_channel_connected(tc));
2790  connected.id = forced_clid;
2791  ast_channel_set_connected_line(tc, &connected, NULL);
2792  } else {
2793  ast_connected_line_copy_from_caller(ast_channel_connected(tc), ast_channel_caller(chan));
2794  }
2795 
2796  ast_party_redirecting_copy(ast_channel_redirecting(tc), ast_channel_redirecting(chan));
2797 
2798  ast_channel_dialed(tc)->transit_network_select = ast_channel_dialed(chan)->transit_network_select;
2799 
2801  if (ast_strlen_zero(ast_channel_musicclass(tc))) {
2802  ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2803  }
2804 
2805  /* Pass ADSI CPE and transfer capability */
2806  ast_channel_adsicpe_set(tc, ast_channel_adsicpe(chan));
2807  ast_channel_transfercapability_set(tc, ast_channel_transfercapability(chan));
2808 
2809  /* If we have an outbound group, set this peer channel to it */
2810  if (outbound_group)
2811  ast_app_group_set_channel(tc, outbound_group);
2812  /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2813  if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE)
2814  ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
2815 
2816  /* Check if we're forced by configuration */
2817  if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
2818  ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
2819 
2820 
2821  /* Inherit context and extension */
2822  ast_channel_dialcontext_set(tc, ast_channel_context(chan));
2823  ast_channel_exten_set(tc, ast_channel_exten(chan));
2824 
2826 
2827  /* Save the original channel name to detect call pickup masquerading in. */
2828  tmp->orig_chan_name = ast_strdup(ast_channel_name(tc));
2829 
2830  ast_channel_unlock(tc);
2831  ast_channel_unlock(chan);
2832 
2833  /* Put channel in the list of outgoing thingies. */
2834  tmp->chan = tc;
2835  AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
2836  }
2837 
2838  /* As long as we attempted to dial valid peers, don't throw a warning. */
2839  /* If a DAHDI peer is busy, out_chans will be empty so checking list size is misleading. */
2840  if (!num_dialed) {
2841  ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");
2842  if (continue_exec) {
2843  /* There is no point in having RetryDial try again */
2844  *continue_exec = 1;
2845  }
2846  strcpy(pa.status, "CHANUNAVAIL");
2847  res = 0;
2848  goto out;
2849  }
2850 
2851  /*
2852  * PREDIAL: Run gosub on all of the callee channels
2853  *
2854  * We run the callee predial before ast_call() in case the user
2855  * wishes to do something on the newly created channels before
2856  * the channel does anything important.
2857  *
2858  * Inside the target gosub we will be able to do something with
2859  * the newly created channel name ie: now the calling channel
2860  * can know what channel will be used to call the destination
2861  * ex: now we will know that SIP/abc-123 is calling SIP/def-124
2862  */
2863  if (ast_test_flag64(&opts, OPT_PREDIAL_CALLEE)
2864  && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])
2865  && !AST_LIST_EMPTY(&out_chans)) {
2866  const char *predial_callee;
2867 
2868  ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
2869  predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
2870  if (predial_callee) {
2871  ast_autoservice_start(chan);
2872  AST_LIST_TRAVERSE(&out_chans, tmp, node) {
2873  ast_pre_call(tmp->chan, predial_callee);
2874  }
2875  ast_autoservice_stop(chan);
2876  ast_free((char *) predial_callee);
2877  }
2878  }
2879 
2880  /* Start all outgoing calls */
2881  AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
2882  res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
2883  ast_channel_lock(chan);
2884 
2885  /* check the results of ast_call */
2886  if (res) {
2887  /* Again, keep going even if there's an error */
2888  ast_debug(1, "ast call on peer returned %d\n", res);
2889  ast_verb(3, "Couldn't call %s\n", tmp->interface);
2890  if (ast_channel_hangupcause(tmp->chan)) {
2891  ast_channel_hangupcause_set(chan, ast_channel_hangupcause(tmp->chan));
2892  }
2893  ast_channel_unlock(chan);
2894  ast_cc_call_failed(chan, tmp->chan, tmp->interface);
2895  ast_hangup(tmp->chan);
2896  tmp->chan = NULL;
2898  chanlist_free(tmp);
2899  continue;
2900  }
2901 
2902  ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
2903  ast_channel_unlock(chan);
2904 
2905  ast_verb(3, "Called %s\n", tmp->interface);
2906  ast_set_flag64(tmp, DIAL_STILLGOING);
2907 
2908  /* If this line is up, don't try anybody else */
2909  if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
2910  break;
2911  }
2912  }
2914 
2915  if (ast_strlen_zero(args.timeout)) {
2916  to_answer = -1;
2917  to_progress = -1;
2918  } else {
2919  char *anstimeout = strsep(&args.timeout, "^");
2920  if (!ast_strlen_zero(anstimeout)) {
2921  to_answer = atoi(anstimeout);
2922  if (to_answer > 0) {
2923  to_answer *= 1000;
2924  } else {
2925  ast_log(LOG_WARNING, "Invalid answer timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2926  to_answer = -1;
2927  }
2928  } else {
2929  to_answer = -1;
2930  }
2931  if (!ast_strlen_zero(args.timeout)) {
2932  to_progress = atoi(args.timeout);
2933  if (to_progress > 0) {
2934  to_progress *= 1000;
2935  } else {
2936  ast_log(LOG_WARNING, "Invalid progress timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2937  to_progress = -1;
2938  }
2939  } else {
2940  to_progress = -1;
2941  }
2942  }
2943 
2944  outgoing = AST_LIST_FIRST(&out_chans);
2945  if (!outgoing) {
2946  strcpy(pa.status, "CHANUNAVAIL");
2947  if (fulldial == num_dialed) {
2948  res = -1;
2949  goto out;
2950  }
2951  } else {
2952  /* Our status will at least be NOANSWER */
2953  strcpy(pa.status, "NOANSWER");
2954  if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
2955  moh = 1;
2956  if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2957  char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2958  ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2959  ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2960  ast_channel_musicclass_set(chan, original_moh);
2961  } else {
2962  ast_moh_start(chan, NULL, NULL);
2963  }
2965  } else if (ast_test_flag64(outgoing, OPT_RINGBACK) || ast_test_flag64(outgoing, OPT_RING_WITH_EARLY_MEDIA)) {
2966  if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2967  if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2969  sentringing++;
2970  } else {
2972  }
2973  } else {
2975  sentringing++;
2976  }
2977  }
2978  }
2979 
2980  peer = wait_for_answer(chan, &out_chans, &to_answer, &to_progress, peerflags, opt_args, &pa, &num, &result,
2981  dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink,
2982  (ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
2983  ignore_cc, &forced_clid, &stored_clid, &config);
2984 
2985  if (!peer) {
2986  if (result) {
2987  res = result;
2988  } else if (to_answer) { /* Musta gotten hung up */
2989  res = -1;
2990  } else { /* Nobody answered, next please? */
2991  res = 0;
2992  }
2993  } else {
2994  const char *number;
2995  const char *name;
2996  int dial_end_raised = 0;
2997  int cause = -1;
2998 
2999  if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
3000  ast_answer(chan);
3001  }
3002 
3003  /* Ah ha! Someone answered within the desired timeframe. Of course after this
3004  we will always return with -1 so that it is hung up properly after the
3005  conversation. */
3006 
3007  if (ast_test_flag64(&opts, OPT_HANGUPCAUSE)
3008  && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
3009  cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
3010  if (cause <= 0) {
3011  if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
3012  cause = 0;
3013  } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
3014  || cause < 0) {
3015  ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
3016  opt_args[OPT_ARG_HANGUPCAUSE]);
3017  cause = -1;
3018  }
3019  }
3020  }
3021  hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
3022 
3023  /* If appropriate, log that we have a destination channel and set the answer time */
3024 
3025  ast_channel_lock(peer);
3026  name = ast_strdupa(ast_channel_name(peer));
3027 
3028  number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
3029  if (ast_strlen_zero(number)) {
3030  number = NULL;
3031  } else {
3032  number = ast_strdupa(number);
3033  }
3034  ast_channel_unlock(peer);
3035 
3036  ast_channel_lock(chan);
3038 
3039  strcpy(pa.status, "ANSWER");
3040  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3041 
3042  pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
3043  pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
3044 
3046  ast_channel_unlock(chan);
3047 
3048  if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
3049  ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
3050  ast_channel_sendurl( peer, args.url );
3051  }
3052  if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
3053  if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
3054  ast_channel_publish_dial(chan, peer, NULL, pa.status);
3055  /* hang up on the callee -- he didn't want to talk anyway! */
3057  res = 0;
3058  goto out;
3059  }
3060  }
3061  if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
3062  res = 0;
3063  } else {
3064  int digit = 0;
3065  struct ast_channel *chans[2];
3066  struct ast_channel *active_chan;
3067  char *calledfile = NULL, *callerfile = NULL;
3068  int calledstream = 0, callerstream = 0;
3069 
3070  chans[0] = chan;
3071  chans[1] = peer;
3072 
3073  /* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
3074  callerfile = opt_args[OPT_ARG_ANNOUNCE];
3075  calledfile = strsep(&callerfile, ":");
3076 
3077  /* stream the file(s) */
3078  if (!ast_strlen_zero(calledfile)) {
3079  res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
3080  if (res) {
3081  res = 0;
3082  ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
3083  } else {
3084  calledstream = 1;
3085  }
3086  }
3087  if (!ast_strlen_zero(callerfile)) {
3088  res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
3089  if (res) {
3090  res = 0;
3091  ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
3092  } else {
3093  callerstream = 1;
3094  }
3095  }
3096 
3097  /* can't use ast_waitstream, because we're streaming two files at once, and can't block
3098  We'll need to handle both channels at once. */
3099 
3101  while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
3102  int mspeer, mschan;
3103 
3104  mspeer = ast_sched_wait(ast_channel_sched(peer));
3105  mschan = ast_sched_wait(ast_channel_sched(chan));
3106 
3107  if (calledstream) {
3108  if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
3109  ast_stopstream(peer);
3110  calledstream = 0;
3111  }
3112  }
3113  if (callerstream) {
3114  if (mschan < 0 && !ast_channel_timingfunc(chan)) {
3115  ast_stopstream(chan);
3116  callerstream = 0;
3117  }
3118  }
3119 
3120  if (!calledstream && !callerstream) {
3121  break;
3122  }
3123 
3124  if (mspeer < 0)
3125  mspeer = 1000;
3126 
3127  if (mschan < 0)
3128  mschan = 1000;
3129 
3130  /* wait for the lowest maximum of the two */
3131  active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
3132  if (active_chan) {
3133  struct ast_channel *other_chan;
3134  struct ast_frame *fr = ast_read(active_chan);
3135 
3136  if (!fr) {
3138  res = -1;
3139  goto done;
3140  }
3141  switch (fr->frametype) {
3142  case AST_FRAME_DTMF_END:
3143  digit = fr->subclass.integer;
3144  if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
3145  ast_stopstream(peer);
3146  res = ast_senddigit(chan, digit, 0);
3147  }
3148  break;
3149  case AST_FRAME_CONTROL:
3150  switch (fr->subclass.integer) {
3151  case AST_CONTROL_HANGUP:
3152  ast_frfree(fr);
3154  res = -1;
3155  goto done;
3157  /* Pass COLP update to the other channel. */
3158  if (active_chan == chan) {
3159  other_chan = peer;
3160  } else {
3161  other_chan = chan;
3162  }
3163  if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)) {
3164  ast_indicate_data(other_chan, fr->subclass.integer,
3165  fr->data.ptr, fr->datalen);
3166  }
3167  break;
3168  default:
3169  break;
3170  }
3171  break;
3172  default:
3173  /* Ignore all others */
3174  break;
3175  }
3176  ast_frfree(fr);
3177  }
3178  ast_sched_runq(ast_channel_sched(peer));
3179  ast_sched_runq(ast_channel_sched(chan));
3180  }
3182  }
3183 
3184  if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
3185  /* chan and peer are going into the PBX; as such neither are considered
3186  * outgoing channels any longer */
3188 
3189  ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
3190  ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
3191  /* peer goes to the same context and extension as chan, so just copy info from chan*/
3192  ast_channel_lock(peer);
3194  ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
3195  ast_channel_context_set(peer, ast_channel_context(chan));
3196  ast_channel_exten_set(peer, ast_channel_exten(chan));
3197  ast_channel_priority_set(peer, ast_channel_priority(chan) + 2);
3199  ast_channel_unlock(peer);
3200  if (ast_pbx_start(peer)) {
3202  }
3203  if (continue_exec)
3204  *continue_exec = 1;
3205  res = 0;
3206  ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3207  goto done;
3208  }
3209 
3210  if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
3211  const char *gosub_result_peer;
3212  char *gosub_argstart;
3213  char *gosub_args = NULL;
3214  int gosub_res = -1;
3215 
3216  ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
3217  gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
3218  if (gosub_argstart) {
3219  const char *what_is_s = "s";
3220  *gosub_argstart = 0;
3221  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)) &&
3222  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))) {
3223  what_is_s = "~~s~~";
3224  }
3225  if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
3226  gosub_args = NULL;
3227  }
3228  *gosub_argstart = ',';
3229  } else {
3230  const char *what_is_s = "s";
3231  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)) &&
3232  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))) {
3233  what_is_s = "~~s~~";
3234  }
3235  if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
3236  gosub_args = NULL;
3237  }
3238  }
3239  if (gosub_args) {
3240  gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
3241  ast_free(gosub_args);
3242  } else {
3243  ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
3244  }
3245 
3246  ast_channel_lock_both(chan, peer);
3247 
3248  if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
3249  char *gosub_transfer_dest;
3250  char *gosub_result = ast_strdupa(gosub_result_peer);
3251  const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
3252 
3253  /* Inherit return value from the peer, so it can be used in the master */
3254  if (gosub_retval) {
3255  pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
3256  }
3257 
3258  ast_channel_unlock(peer);
3259  ast_channel_unlock(chan);
3260 
3261  if (!strcasecmp(gosub_result, "BUSY")) {
3262  ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3263  ast_set_flag64(peerflags, OPT_GO_ON);
3264  gosub_res = -1;
3265  } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
3266  ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3267  ast_set_flag64(peerflags, OPT_GO_ON);
3268  gosub_res = -1;
3269  } else if (!strcasecmp(gosub_result, "CONTINUE")) {
3270  /* Hangup peer and continue with the next extension priority. */
3271  ast_set_flag64(peerflags, OPT_GO_ON);
3272  gosub_res = -1;
3273  } else if (!strcasecmp(gosub_result, "ABORT")) {
3274  /* Hangup both ends unless the caller has the g flag */
3275  gosub_res = -1;
3276  } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
3277  gosub_transfer_dest = gosub_result + 5;
3278  gosub_res = -1;
3279  /* perform a transfer to a new extension */
3280  if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
3281  ast_replace_subargument_delimiter(gosub_transfer_dest);
3282  }
3283  if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
3284  ast_set_flag64(peerflags, OPT_GO_ON);
3285  }
3286  }
3287  if (gosub_res) {
3288  res = gosub_res;
3289  if (!dial_end_raised) {
3290  ast_channel_publish_dial(chan, peer, NULL, gosub_result);
3291  dial_end_raised = 1;
3292  }
3293  }
3294  } else {
3295  ast_channel_unlock(peer);
3296  ast_channel_unlock(chan);
3297  }
3298  }
3299 
3300  if (!res) {
3301 
3302  /* None of the Dial options changed our status; inform
3303  * everyone that this channel answered
3304  */
3305  if (!dial_end_raised) {
3306  ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3307  dial_end_raised = 1;
3308  }
3309 
3310  if (!ast_tvzero(calldurationlimit)) {
3311  struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
3312  ast_channel_lock(peer);
3313  ast_channel_whentohangup_set(peer, &whentohangup);
3314  ast_channel_unlock(peer);
3315  }
3316  if (!ast_strlen_zero(dtmfcalled)) {
3317  ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
3318  res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
3319  }
3320  if (!ast_strlen_zero(dtmfcalling)) {
3321  ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
3322  res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
3323  }
3324  }
3325 
3326  if (res) { /* some error */
3327  if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
3328  ast_channel_hangupcause_set(chan, ast_channel_hangupcause(peer));
3329  }
3330  setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3331  if (ast_bridge_setup_after_goto(peer)
3332  || ast_pbx_start(peer)) {
3334  }
3335  res = -1;
3336  } else {
3337  if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
3338  ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
3339  if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
3340  ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
3341  if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
3342  ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
3343  if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
3344  ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
3345  if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
3346  ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
3347  if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
3348  ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
3349  if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
3350  ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
3351  if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
3352  ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
3353  if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
3354  ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
3355  if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
3356  ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
3357 
3358  config.end_bridge_callback = end_bridge_callback;
3359  config.end_bridge_callback_data = chan;
3360  config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
3361 
3362  if (moh) {
3363  moh = 0;
3364  ast_moh_stop(chan);
3365  } else if (sentringing) {
3366  sentringing = 0;
3367  ast_indicate(chan, -1);
3368  }
3369  /* Be sure no generators are left on it and reset the visible indication */
3371  ast_channel_visible_indication_set(chan, 0);
3372  /* Make sure channels are compatible */
3373  res = ast_channel_make_compatible(chan, peer);
3374  if (res < 0) {
3375  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));
3377  res = -1;
3378  goto done;
3379  }
3380  if (opermode) {
3381  struct oprmode oprmode;
3382 
3383  oprmode.peer = peer;
3384  oprmode.mode = opermode;
3385 
3386  ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
3387  }
3388  setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3389 
3390  res = ast_bridge_call(chan, peer, &config);
3391  }
3392  }
3393 out:
3394  if (moh) {
3395  moh = 0;
3396  ast_moh_stop(chan);
3397  } else if (sentringing) {
3398  sentringing = 0;
3399  ast_indicate(chan, -1);
3400  }
3401 
3402  if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3403  ast_filedelete(pa.privintro, NULL);
3404  if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3405  ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
3406  } else {
3407  ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
3408  }
3409  }
3410 
3411  ast_channel_early_bridge(chan, NULL);
3412  /* forward 'answered elsewhere' if we received it */
3413  if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE || ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE)) {
3414  hanguptreecause = AST_CAUSE_ANSWERED_ELSEWHERE;
3415  } else if (pa.canceled) { /* Caller canceled */
3416  if (ast_channel_hangupcause(chan))
3417  hanguptreecause = ast_channel_hangupcause(chan);
3418  else
3419  hanguptreecause = AST_CAUSE_NORMAL_CLEARING;
3420  }
3421  hanguptree(&out_chans, NULL, hanguptreecause);
3422  pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3423  ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
3424 
3425  if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
3426  if (!ast_tvzero(calldurationlimit))
3427  memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
3428  res = 0;
3429  }
3430 
3431 done:
3432  if (config.answer_topology) {
3433  ast_trace(2, "%s Cleaning up topology: %p %s\n",
3434  peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology,
3435  ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP)));
3436 
3437  /*
3438  * At this point, the channel driver that answered should have bumped the
3439  * topology refcount for itself. Here we're cleaning up the reference we added
3440  * in wait_for_answer().
3441  */
3443  }
3444  if (config.warning_sound) {
3445  ast_free((char *)config.warning_sound);
3446  }
3447  if (config.end_sound) {
3448  ast_free((char *)config.end_sound);
3449  }
3450  if (config.start_sound) {
3451  ast_free((char *)config.start_sound);
3452  }
3453  ast_ignore_cc(chan);
3454  SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan));
3455 }
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
Definition: main/app.c:1127
struct ast_channel * ast_waitfor_n(struct ast_channel **chan, int n, int *ms)
Waits for input on a group of channels Wait for input on an array of channels for a given # of millis...
Definition: channel.c:3157
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels together (early)
Definition: channel.c:7412
Information needed to identify an endpoint in a call.
Definition: channel.h:338
Main Channel structure associated with a channel.
Definition: test_heap.c:38
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1293
char stuff[0]
Definition: app_dial.c:815
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name...
Definition: channel.c:7372
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
const char * tech
Definition: app_dial.c:803
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
Definition: sched.c:786
struct ast_stream_topology * answer_topology
Definition: channel.h:1099
struct ast_party_id id
Connected party ID.
Definition: channel.h:458
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:278
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation...
Definition: channel.c:2045
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4277
struct ast_party_name name
Subscriber name.
Definition: channel.h:340
void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition: channel.c:6623
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:4708
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6461
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition: time.h:117
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition: channel.c:11034
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4257
ast_channel_state
ast_channel states
Definition: channelstate.h:35
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4653
int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config)
Bridge a call, optionally allowing redirection.
Definition: features.c:685
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
Definition: channel.c:612
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
Structure for a data store object.
Definition: datastore.h:64
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int position)
Get a specific stream from the topology.
Definition: stream.c:788
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4974
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
Definition: file.c:1141
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7422
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition: utils.h:204
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7776
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
void ast_cc_call_failed(struct ast_channel *incoming, struct ast_channel *outgoing, const char *const dialstring)
Make CCBS available in the case that ast_call fails.
Definition: ccss.c:4164
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
Number structure.
Definition: app_followme.c:154
const struct ast_channel_tech * tech
static struct callattempt * wait_for_answer(struct queue_ent *qe, struct callattempt *outgoing, int *to, char *digit, int prebusies, int caller_disconnect, int forwardsallowed)
Wait for a member to answer the call.
Definition: app_queue.c:5205
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2368
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'
Definition: app_dial.c:2120
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
Definition: strings.h:1189
void ast_replace_subargument_delimiter(char *s)
Replace '^' in a string with ','.
Definition: utils.c:2343
void ast_cc_extension_monitor_add_dialstring(struct ast_channel *incoming, const char *const dialstring, const char *const device_name)
Add a child dialstring to an extension monitor.
Definition: ccss.c:1983
const char * interface
Definition: app_dial.c:801
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition: channel.c:6720
const char * ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf)
Get a string representing the topology for debugging/display purposes.
Definition: stream.c:936
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition: pbx.c:8866
#define AST_MAX_EXTENSION
Definition: channel.h:134
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
bridge configuration
Definition: channel.h:1076
void * end_bridge_callback_data
Definition: channel.h:1091
Caller Party information.
Definition: channel.h:418
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
void(* end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition: channel.h:1095
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition: cdr.c:3660
List of channel drivers.
Definition: app_dial.c:797
struct ast_channel * ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel (specifying stream topology)
Definition: channel.c:6359
#define ast_debug(level,...)
Log a DEBUG message.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4175
int ast_pre_call(struct ast_channel *chan, const char *sub_args)
Execute a Gosub call on the channel before a call is placed.
Definition: channel.c:6444
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6434
int ast_parse_caller_presentation(const char *data)
Convert caller ID text code to value (used in config file parsing)
Definition: callerid.c:1343
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3071
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
struct ast_party_connected_line connected
Definition: app_dial.c:810
int ast_cc_callback(struct ast_channel *inbound, const char *const tech, const char *const dest, ast_cc_callback_fn callback)
Run a callback for potential matching destinations.
Definition: ccss.c:4209
int ast_cc_call_init(struct ast_channel *chan, int *ignore_cc)
Start the CC process on a call.
Definition: ccss.c:2386
#define AST_PBX_INCOMPLETE
Definition: pbx.h:51
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
Initialize the given caller structure using the given guide for a set update operation.
Definition: channel.c:1999
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
Definition: channel.c:11027
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame)
Run a connected line interception subroutine and update a channel's connected line information...
Definition: channel.c:10338
Channel datastore data for max forwards.
Definition: max_forwards.c:29
const char * number
Definition: app_dial.c:805
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282
Connected Line/Party information.
Definition: channel.h:456
void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide)
Initialize the given party id structure using the given guide for a set update operation.
Definition: channel.c:1780
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7766
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
int ast_channel_sendurl(struct ast_channel *channel, const char *url)
Sends a URL on a given link Send URL on link.
Definition: channel.c:6635
Set when the stream is sending media only.
Definition: stream.h:86
union ast_frame::@224 data
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6771
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define AST_CHANNEL_NAME
Definition: channel.h:171
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2541
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state)
Set the state of a stream.
Definition: stream.c:380
void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer)
Put chan into autoservice while hanging up peer.
Definition: autoservice.c:342
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition: channel.c:1757
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition: stream.c:765
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
Definition: linkedlists.h:252
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
Definition: stream.c:667
void ast_cc_busy_interface(struct ast_channel *inbound, struct ast_cc_config_params *cc_params, const char *monitor_type, const char *const device_name, const char *const dialstring, void *private_data)
Callback made from ast_cc_callback for certain channel types.
Definition: ccss.c:4197
Definition: astman.c:88
void(* end_bridge_callback)(void *)
Definition: channel.h:1090
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
void ast_ignore_cc(struct ast_channel *chan)
Mark the channel to ignore further CC activity.
Definition: ccss.c:3685
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2893
void * data
Definition: datastore.h:66
int transit_network_select
Transit Network Select.
Definition: channel.h:397
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2031
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8293
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition: file.c:1129
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2805
int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result
Determines number of seconds until the next outstanding event to take place.
Definition: sched.c:433
int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length)
Get a device name given its channel structure.
Definition: channel.c:10496
Data structure associated with a single frame of data.
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:297
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
enum ast_frame_type frametype
int ast_str2cause(const char *name) attribute_pure
Convert the string form of a cause code to a number.
Definition: channel.c:625
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src)
Make two channels compatible for early bridging.
Definition: rtp_engine.c:2375
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2385
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
int ast_bridge_setup_after_goto(struct ast_channel *chan)
Setup any after bridge goto location to begin execution.
Definition: bridge_after.c:435
Set when the stream is receiving media only.
Definition: stream.h:90
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Set the connected line information in the Asterisk channel.
Definition: channel.c:8308
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream)
Get the current state of a stream.
Definition: stream.c:373
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
Set the group for a channel, splitting the provided data into group and category, if specified...
Definition: main/app.c:2193
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2135
#define AST_APP_ARG(name)
Define an application argument.
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1162
int ast_bridge_timelimit(struct ast_channel *chan, struct ast_bridge_config *config, char *parse, struct timeval *calldurationlimit)
parse L option and read associated channel variables to set warning, warning frequency, and timelimit
Definition: features.c:857
char * orig_chan_name
Definition: app_dial.c:807
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
oOutgoing call channel list.
numIncoming call channel cause accumulation
peerflagsDial option flags
singleTRUE if there is only one outgoing call.
caller_entertainedTRUE if the caller is being entertained by MOH or ringback.
toRemaining call timeout time.
forced_clidOPT_FORCECLID caller id to send
stored_clidCaller 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 integrated into and replaced by ast_call_forward()

Definition at line 937 of file app_dial.c.

References ast_call(), ast_channel_datastore_inherit(), ast_channel_get_stream_topology(), ast_channel_inherit_variables(), ast_channel_lock_both, ast_channel_make_compatible(), AST_CHANNEL_NAME, ast_channel_publish_dial(), ast_channel_publish_dial_forward(), ast_channel_publish_snapshot(), ast_channel_redirecting_sub(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_set_caller_event(), ast_channel_update_redirecting(), ast_connected_line_copy_from_caller(), ast_copy_string(), ast_hangup(), ast_ignore_cc(), ast_indicate(), 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_with_stream_topology(), ast_rtp_instance_early_bridge_make_compatible(), ast_strdup, ast_stream_topology_clone(), ast_stream_topology_free(), ast_party_redirecting::from, ast_party_caller::id, ast_party_connected_line::id, ast_party_id::number, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), S_COR, ast_party_number::str, ast_channel::tech, ast_party_dialed::transit_network_select, and ast_party_number::valid.

940 {
941  char tmpchan[256];
942  char forwarder[AST_CHANNEL_NAME];
943  struct ast_channel *original = o->chan;
944  struct ast_channel *c = o->chan; /* the winner */
945  struct ast_channel *in = num->chan; /* the input channel */
946  char *stuff;
947  char *tech;
948  int cause;
949  struct ast_party_caller caller;
950 
951  ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
952  ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
953  if ((stuff = strchr(tmpchan, '/'))) {
954  *stuff++ = '\0';
955  tech = tmpchan;
956  } else {
957  const char *forward_context;
958  ast_channel_lock(c);
959  forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
960  if (ast_strlen_zero(forward_context)) {
961  forward_context = NULL;
962  }
963  snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
964  ast_channel_unlock(c);
965  stuff = tmpchan;
966  tech = "Local";
967  }
968  if (!strcasecmp(tech, "Local")) {
969  /*
970  * Drop the connected line update block for local channels since
971  * this is going to run dialplan and the user can change his
972  * mind about what connected line information he wants to send.
973  */
974  ast_clear_flag64(o, OPT_IGNORE_CONNECTEDLINE);
975  }
976 
977  /* Before processing channel, go ahead and check for forwarding */
978  ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
979  /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
980  if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
981  ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
982  ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
983  ast_channel_call_forward(original));
984  c = o->chan = NULL;
985  cause = AST_CAUSE_BUSY;
986  } else {
987  struct ast_stream_topology *topology;
988 
989  ast_channel_lock(in);
991  ast_channel_unlock(in);
992 
993  /* Setup parameters */
994  c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
995 
996  ast_stream_topology_free(topology);
997 
998  if (c) {
999  if (single && !caller_entertained) {
1000  ast_channel_make_compatible(in, o->chan);
1001  }
1002  ast_channel_lock_both(in, o->chan);
1003  ast_channel_inherit_variables(in, o->chan);
1004  ast_channel_datastore_inherit(in, o->chan);
1005  pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
1006  ast_max_forwards_decrement(o->chan);
1007  ast_channel_unlock(in);
1008  ast_channel_unlock(o->chan);
1009  /* When a call is forwarded, we don't want to track new interfaces
1010  * dialed for CC purposes. Setting the done flag will ensure that
1011  * any Dial operations that happen later won't record CC interfaces.
1012  */
1013  ast_ignore_cc(o->chan);
1014  ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",
1015  ast_channel_name(o->chan));
1016  } else
1017  ast_log(LOG_NOTICE,
1018  "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
1019  tech, stuff, cause);
1020  }
1021  if (!c) {
1022  ast_channel_publish_dial(in, original, stuff, "BUSY");
1023  ast_clear_flag64(o, DIAL_STILLGOING);
1024  handle_cause(cause, num);
1025  ast_hangup(original);
1026  } else {
1027  ast_channel_lock_both(c, original);
1028  ast_party_redirecting_copy(ast_channel_redirecting(c),
1029  ast_channel_redirecting(original));
1030  ast_channel_unlock(c);
1031  ast_channel_unlock(original);
1032 
1033  ast_channel_lock_both(c, in);
1034 
1035  if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
1037  }
1038 
1039  if (!ast_channel_redirecting(c)->from.number.valid
1040  || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
1041  /*
1042  * The call was not previously redirected so it is
1043  * now redirected from this number.
1044  */
1045  ast_party_number_free(&ast_channel_redirecting(c)->from.number);
1046  ast_party_number_init(&ast_channel_redirecting(c)->from.number);
1047  ast_channel_redirecting(c)->from.number.valid = 1;
1048  ast_channel_redirecting(c)->from.number.str =
1049  ast_strdup(ast_channel_exten(in));
1050  }
1051 
1052  ast_channel_dialed(c)->transit_network_select = ast_channel_dialed(in)->transit_network_select;
1053 
1054  /* Determine CallerID to store in outgoing channel. */
1055  ast_party_caller_set_init(&caller, ast_channel_caller(c));
1056  if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1057  caller.id = *stored_clid;
1058  ast_channel_set_caller_event(c, &caller, NULL);
1059  ast_set_flag64(o, DIAL_CALLERID_ABSENT);
1060  } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
1061  ast_channel_caller(c)->id.number.str, NULL))) {
1062  /*
1063  * The new channel has no preset CallerID number by the channel
1064  * driver. Use the dialplan extension and hint name.
1065  */
1066  caller.id = *stored_clid;
1067  ast_channel_set_caller_event(c, &caller, NULL);
1068  ast_set_flag64(o, DIAL_CALLERID_ABSENT);
1069  } else {
1070  ast_clear_flag64(o, DIAL_CALLERID_ABSENT);
1071  }
1072 
1073  /* Determine CallerID for outgoing channel to send. */
1074  if (ast_test_flag64(o, OPT_FORCECLID)) {
1075  struct ast_party_connected_line connected;
1076 
1077  ast_party_connected_line_init(&connected);
1078  connected.id = *forced_clid;
1079  ast_party_connected_line_copy(ast_channel_connected(c), &connected);
1080  } else {
1081  ast_connected_line_copy_from_caller(ast_channel_connected(c), ast_channel_caller(in));
1082  }
1083 
1085 
1086  ast_channel_appl_set(c, "AppDial");
1087  ast_channel_data_set(c, "(Outgoing Line)");
1089 
1090  ast_channel_unlock(in);
1091  if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1092  struct ast_party_redirecting redirecting;
1093 
1094  /*
1095  * Redirecting updates to the caller make sense only on single
1096  * calls.
1097  *
1098  * Need to re-evalute if unlocking is still required here as macro is gone
1099  */
1100  ast_party_redirecting_init(&redirecting);
1101  ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(c));
1102  ast_channel_unlock(c);
1103  if (ast_channel_redirecting_sub(c, in, &redirecting, 0)) {
1104  ast_channel_update_redirecting(in, &redirecting, NULL);
1105  }
1106  ast_party_redirecting_free(&redirecting);
1107  } else {
1108  ast_channel_unlock(c);
1109  }
1110 
1111  if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1112  *to = -1;
1113  }
1114 
1115  if (ast_call(c, stuff, 0)) {
1116  ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1117  tech, stuff);
1118  ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1119  ast_clear_flag64(o, DIAL_STILLGOING);
1120  ast_hangup(original);
1121  ast_hangup(c);
1122  c = o->chan = NULL;
1123  num->nochan++;
1124  } else {
1125  ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1126  ast_channel_call_forward(original));
1127 
1128  ast_channel_publish_dial(in, c, stuff, NULL);
1129 
1130  /* Hangup the original channel now, in case we needed it */
1131  ast_hangup(original);
1132  }
1133  if (single && !caller_entertained) {
1134  ast_indicate(in, -1);
1135  }
1136  }
1137 }
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2022
Main Channel structure associated with a channel.
char * str
Subscriber phone number (Malloced)
Definition: channel.h:291
void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update)
Set the caller id information in the Asterisk channel and generate an AMI event if the caller id name...
Definition: channel.c:7372
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4277
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: channel.h:527
void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Indicate that the redirecting id has changed.
Definition: channel.c:10284
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6461
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Number structure.
Definition: app_followme.c:154
const struct ast_channel_tech * tech
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2368
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition: channel.c:6720
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
Run a redirecting interception subroutine and update a channel's redirecting information.
Definition: channel.c:10383
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1644
Caller Party information.
Definition: channel.h:418
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
struct ast_channel * ast_request_with_stream_topology(const char *type, struct ast_stream_topology *topology, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel (specifying stream topology)
Definition: channel.c:6359
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6434
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:1691
void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide)
Initialize the given caller structure using the given guide for a set update operation.
Definition: channel.c:1999
Connected Line/Party information.
Definition: channel.h:456
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition: channel.h:522
void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6771
#define AST_CHANNEL_NAME
Definition: channel.h:171
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2541
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
Definition: stream.c:667
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
void ast_ignore_cc(struct ast_channel *chan)
Mark the channel to ignore further CC activity.
Definition: ccss.c:3685
int transit_network_select
Transit Network Select.
Definition: channel.h:397
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition: channel.c:2179
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2031
struct ast_party_id to
Call is redirecting to a new party (Sent to the caller)
Definition: channel.h:530
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8293
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition: channel.c:2122
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src)
Make two channels compatible for early bridging.
Definition: rtp_engine.c:2375
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:297
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2135
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:342

Variable Documentation

const struct ast_datastore_info topology_ds_info
static
Initial value:
= {
.type = "app_dial_topology_preserve",
.destroy = topology_ds_destroy,
}

Definition at line 825 of file app_dial.c.