Asterisk - The Open Source Telephony Project GIT-master-80b953f
Loading...
Searching...
No Matches
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"
Include dependency graph for app_dial.c:

Go to the source code of this file.

Data Structures

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

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 = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
 
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 = OPT_CALLER_ANSWER }, [ 'b' ] = { .flag = OPT_PREDIAL_CALLEE , .arg_index = OPT_ARG_PREDIAL_CALLEE + 1 }, [ 'B' ] = { .flag = OPT_PREDIAL_CALLER , .arg_index = OPT_ARG_PREDIAL_CALLER + 1 }, [ 'C' ] = { .flag = OPT_RESETCDR }, [ 'c' ] = { .flag = OPT_CANCEL_ELSEWHERE }, [ 'd' ] = { .flag = OPT_DTMF_EXIT }, [ 'D' ] = { .flag = OPT_SENDDTMF , .arg_index = OPT_ARG_SENDDTMF + 1 }, [ 'E' ] = { .flag = OPT_HEARPULSING }, [ 'e' ] = { .flag = OPT_PEER_H }, [ 'f' ] = { .flag = OPT_FORCECLID , .arg_index = OPT_ARG_FORCECLID + 1 }, [ 'F' ] = { .flag = OPT_CALLEE_GO_ON , .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 = OPT_TOPOLOGY_PRESERVE }, [ '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 = OPT_HANGUPCAUSE , .arg_index = OPT_ARG_HANGUPCAUSE + 1 }, [ 'r' ] = { .flag = OPT_RINGBACK , .arg_index = OPT_ARG_RINGBACK + 1 }, [ 'R' ] = { .flag = OPT_RING_WITH_EARLY_MEDIA }, [ 'S' ] = { .flag = OPT_DURATION_STOP , .arg_index = OPT_ARG_DURATION_STOP + 1 }, [ 's' ] = { .flag = OPT_FORCE_CID_TAG , .arg_index = OPT_ARG_FORCE_CID_TAG + 1 }, [ 't' ] = { .flag = OPT_CALLEE_TRANSFER }, [ 'T' ] = { .flag = OPT_CALLER_TRANSFER }, [ 'u' ] = { .flag = OPT_FORCE_CID_PRES , .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 = OPT_CANCEL_TIMEOUT }, }
 
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.

Macro Definition Documentation

◆ AST_MAX_WATCHERS

#define AST_MAX_WATCHERS   256

Definition at line 865 of file app_dial.c.

◆ CAN_EARLY_BRIDGE

#define CAN_EARLY_BRIDGE (   flags,
  chan,
  peer 
)

Definition at line 794 of file app_dial.c.

803 {
805 struct ast_channel *chan;
806 /*! Channel interface dialing string (is tech/number). (Stored in stuff[]) */
807 const char *interface;
808 /*! Channel technology name. (Stored in stuff[]) */
809 const char *tech;
810 /*! Channel device addressing. (Stored in stuff[]) */
811 const char *number;
812 /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
813 char *orig_chan_name;
814 uint64_t flags;
815 /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
817 /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
818 unsigned int pending_connected_update:1;
819 struct ast_aoc_decoded *aoc_s_rate_list;
820 /*! The interface, tech, and number strings are stuffed here. */
821 char stuff[0];
822};
823
825
826static void topology_ds_destroy(void *data) {
827 struct ast_stream_topology *top = data;
829}
830
831static const struct ast_datastore_info topology_ds_info = {
832 .type = "app_dial_topology_preserve",
833 .destroy = topology_ds_destroy,
834};
835
836static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode);
837
838static void chanlist_free(struct chanlist *outgoing)
839{
841 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
842 ast_free(outgoing->orig_chan_name);
844}
845
846static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
847{
848 /* Hang up a tree of stuff */
849 struct chanlist *outgoing;
850
851 while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
852 /* Hangup any existing lines we have open */
853 if (outgoing->chan && (outgoing->chan != exception)) {
854 if (hangupcause >= 0) {
855 /* This is for the channel drivers */
856 ast_channel_hangupcause_set(outgoing->chan, hangupcause);
857 }
858 ast_hangup(outgoing->chan);
859 }
861 }
862}
863
864#define AST_MAX_WATCHERS 256
865
866/*
867 * argument to handle_cause() and other functions.
868 */
869struct cause_args {
870 struct ast_channel *chan;
871 int busy;
872 int congestion;
873 int nochan;
874};
875
876static void handle_cause(int cause, struct cause_args *num)
877{
878 switch(cause) {
879 case AST_CAUSE_BUSY:
880 num->busy++;
881 break;
883 num->congestion++;
884 break;
887 num->nochan++;
888 break;
891 break;
892 default:
893 num->nochan++;
894 break;
895 }
896}
897
898static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
899{
900 char rexten[2] = { exten, '\0' };
901
902 if (context) {
903 if (!ast_goto_if_exists(chan, context, rexten, pri))
904 return 1;
905 } else {
906 if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
907 return 1;
908 }
909 return 0;
910}
911
912/* do not call with chan lock held */
913static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
914{
915 const char *context;
916 const char *exten;
917
918 ast_channel_lock(chan);
921 ast_channel_unlock(chan);
922
923 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
924}
925
926/*!
927 * helper function for wait_for_answer()
928 *
929 * \param o Outgoing call channel list.
930 * \param num Incoming call channel cause accumulation
931 * \param peerflags Dial option flags
932 * \param single TRUE if there is only one outgoing call.
933 * \param caller_entertained TRUE if the caller is being entertained by MOH or ringback.
934 * \param to Remaining call timeout time.
935 * \param forced_clid OPT_FORCECLID caller id to send
936 * \param stored_clid Caller id representing the called party if needed
937 *
938 * XXX this code is highly suspicious, as it essentially overwrites
939 * the outgoing channel without properly deleting it.
940 *
941 * \todo eventually this function should be integrated into and replaced by ast_call_forward()
942 */
943static void do_forward(struct chanlist *o, struct cause_args *num,
944 struct ast_flags64 *peerflags, int single, int caller_entertained, int *to,
945 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
946{
947 char tmpchan[256];
948 char forwarder[AST_CHANNEL_NAME];
949 struct ast_channel *original = o->chan;
950 struct ast_channel *c = o->chan; /* the winner */
951 struct ast_channel *in = num->chan; /* the input channel */
952 char *stuff;
953 const char *tech;
954 int cause;
955 struct ast_party_caller caller;
956
957 ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
958 ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
959 if ((stuff = strchr(tmpchan, '/'))) {
960 *stuff++ = '\0';
961 tech = tmpchan;
962 } else {
963 const char *forward_context;
965 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
966 if (ast_strlen_zero(forward_context)) {
967 forward_context = NULL;
968 }
969 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
971 stuff = tmpchan;
972 tech = "Local";
973 }
974 if (!strcasecmp(tech, "Local")) {
975 /*
976 * Drop the connected line update block for local channels since
977 * this is going to run dialplan and the user can change his
978 * mind about what connected line information he wants to send.
979 */
981 }
982
983 /* Before processing channel, go ahead and check for forwarding */
984 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
985 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
986 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
987 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
988 ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
989 ast_channel_call_forward(original));
990 c = o->chan = NULL;
991 cause = AST_CAUSE_BUSY;
992 } else {
993 struct ast_stream_topology *topology;
994
998
999 /* Setup parameters */
1000 c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
1001
1002 ast_stream_topology_free(topology);
1003
1004 if (c) {
1005 if (single && !caller_entertained) {
1007 }
1011 pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
1015 /* When a call is forwarded, we don't want to track new interfaces
1016 * dialed for CC purposes. Setting the done flag will ensure that
1017 * any Dial operations that happen later won't record CC interfaces.
1018 */
1019 ast_ignore_cc(o->chan);
1020 ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",
1022 } else
1024 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
1025 tech, stuff, cause);
1026 }
1027 if (!c) {
1028 ast_channel_publish_dial(in, original, stuff, "BUSY");
1030 handle_cause(cause, num);
1031 ast_hangup(original);
1032 } else {
1033 ast_channel_lock_both(c, original);
1035 ast_channel_redirecting(original));
1037 ast_channel_unlock(original);
1038
1040
1041 if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
1043 }
1044
1045 if (!ast_channel_redirecting(c)->from.number.valid
1046 || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
1047 /*
1048 * The call was not previously redirected so it is
1049 * now redirected from this number.
1050 */
1056 }
1057
1059
1060 /* Determine CallerID to store in outgoing channel. */
1062 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1063 caller.id = *stored_clid;
1066 } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
1067 ast_channel_caller(c)->id.number.str, NULL))) {
1068 /*
1069 * The new channel has no preset CallerID number by the channel
1070 * driver. Use the dialplan extension and hint name.
1071 */
1072 caller.id = *stored_clid;
1075 } else {
1077 }
1078
1079 /* Determine CallerID for outgoing channel to send. */
1082
1084 connected.id = *forced_clid;
1086 } else {
1088 }
1089
1091
1092 ast_channel_appl_set(c, "AppDial");
1093 ast_channel_data_set(c, "(Outgoing Line)");
1095
1097 if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1098 struct ast_party_redirecting redirecting;
1099
1100 /*
1101 * Redirecting updates to the caller make sense only on single
1102 * calls.
1103 *
1104 * Need to re-evalute if unlocking is still required here as macro is gone
1105 */
1106 ast_party_redirecting_init(&redirecting);
1109 if (ast_channel_redirecting_sub(c, in, &redirecting, 0)) {
1110 ast_channel_update_redirecting(in, &redirecting, NULL);
1111 }
1112 ast_party_redirecting_free(&redirecting);
1113 } else {
1115 }
1116
1117 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1118 *to = -1;
1119 }
1120
1121 if (ast_call(c, stuff, 0)) {
1122 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1123 tech, stuff);
1124 ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1126 ast_hangup(original);
1127 ast_hangup(c);
1128 c = o->chan = NULL;
1129 num->nochan++;
1130 } else {
1131 ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1132 ast_channel_call_forward(original));
1133
1135
1136 /* Hangup the original channel now, in case we needed it */
1137 ast_hangup(original);
1138 }
1139 if (single && !caller_entertained) {
1140 ast_indicate(in, -1);
1141 }
1142 }
1143}
1144
1145/* argument used for some functions. */
1146struct privacy_args {
1147 int sentringing;
1148 int privdb_val;
1149 char privcid[256];
1150 char privintro[1024];
1151 char status[256];
1152 int canceled;
1153};
1154
1155static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
1156{
1157 struct chanlist *outgoing;
1158 AST_LIST_TRAVERSE(out_chans, outgoing, node) {
1159 if (!outgoing->chan || outgoing->chan == exception) {
1160 continue;
1161 }
1163 }
1164}
1165
1166/*!
1167 * \internal
1168 * \brief Update connected line on chan from peer.
1169 * \since 13.6.0
1170 *
1171 * \param chan Channel to get connected line updated.
1172 * \param peer Channel providing connected line information.
1173 * \param is_caller Non-zero if chan is the calling channel.
1174 */
1175static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
1176{
1177 struct ast_party_connected_line connected_caller;
1178
1179 ast_party_connected_line_init(&connected_caller);
1180
1181 ast_channel_lock(peer);
1183 ast_channel_unlock(peer);
1184 connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
1185 if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)) {
1186 ast_channel_update_connected_line(chan, &connected_caller, NULL);
1187 }
1188 ast_party_connected_line_free(&connected_caller);
1189}
1190
1191/*!
1192 * \internal
1193 * \pre chan is locked
1194 */
1195static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
1196{
1197 char buf[32];
1198 char full_var_name[128];
1199
1200 snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000);
1201 pbx_builtin_setvar_helper(chan, var_base, buf);
1202
1203 snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base);
1204 snprintf(buf, sizeof(buf), "%" PRId64, duration);
1205 pbx_builtin_setvar_helper(chan, full_var_name, buf);
1206}
1207
1208static struct ast_channel *wait_for_answer(struct ast_channel *in,
1209 struct dial_head *out_chans, int *to_answer, int *to_progress, struct ast_flags64 *peerflags,
1210 char *opt_args[],
1211 struct privacy_args *pa,
1212 const struct cause_args *num_in, int *result, char *dtmf_progress,
1213 char *mf_progress, char *mf_wink,
1214 char *sf_progress, char *sf_wink,
1215 const int hearpulsing,
1216 const int ignore_cc,
1217 struct ast_party_id *forced_clid, struct ast_party_id *stored_clid,
1218 struct ast_bridge_config *config)
1219{
1220 struct cause_args num = *num_in;
1221 int prestart = num.busy + num.congestion + num.nochan;
1222 int orig_answer_to = *to_answer;
1223 int orig_progress_to = *to_progress;
1224 struct ast_channel *peer = NULL;
1225 struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
1226 /* single is set if only one destination is enabled */
1227 int single = outgoing && !AST_LIST_NEXT(outgoing, node);
1228 int caller_entertained = outgoing
1230 struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
1231 int cc_recall_core_id;
1232 int is_cc_recall;
1233 int cc_frame_received = 0;
1234 int num_ringing = 0;
1235 int sent_ring = 0;
1236 int sent_progress = 0, sent_wink = 0;
1237 struct timeval start = ast_tvnow();
1238 SCOPE_ENTER(3, "%s\n", ast_channel_name(in));
1239
1240 if (single) {
1241 /* Turn off hold music, etc */
1242 if (!caller_entertained) {
1244 /* If we are calling a single channel, and not providing ringback or music, */
1245 /* then, make them compatible for in-band tone purpose */
1246 if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
1247 /* If these channels can not be made compatible,
1248 * there is no point in continuing. The bridge
1249 * will just fail if it gets that far.
1250 */
1251 *to_answer = -1;
1252 strcpy(pa->status, "CONGESTION");
1254 SCOPE_EXIT_RTN_VALUE(NULL, "%s: can't be made compat with %s\n",
1256 }
1257 }
1258
1262 }
1263 }
1264
1265 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1266
1267 while ((*to_answer = ast_remaining_ms(start, orig_answer_to)) && (*to_progress = ast_remaining_ms(start, orig_progress_to)) && !peer) {
1268 struct chanlist *o;
1269 int pos = 0; /* how many channels do we handle */
1270 int numlines = prestart;
1271 struct ast_channel *winner;
1272 struct ast_channel *watchers[AST_MAX_WATCHERS];
1273
1274 watchers[pos++] = in;
1275 AST_LIST_TRAVERSE(out_chans, o, node) {
1276 /* Keep track of important channels */
1277 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1278 watchers[pos++] = o->chan;
1279 numlines++;
1280 }
1281 if (pos == 1) { /* only the input channel is available */
1282 if (numlines == (num.busy + num.congestion + num.nochan)) {
1283 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1284 if (num.busy)
1285 strcpy(pa->status, "BUSY");
1286 else if (num.congestion)
1287 strcpy(pa->status, "CONGESTION");
1288 else if (num.nochan)
1289 strcpy(pa->status, "CHANUNAVAIL");
1290 } else {
1291 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1292 }
1293 *to_answer = 0;
1294 if (is_cc_recall) {
1295 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1296 }
1297 SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outgoing channels available\n", ast_channel_name(in));
1298 }
1299
1300 /* If progress timeout is active, use that if it's the shorter of the 2 timeouts. */
1301 winner = ast_waitfor_n(watchers, pos, *to_progress > 0 && (*to_answer < 0 || *to_progress < *to_answer) ? to_progress : to_answer);
1302
1303 AST_LIST_TRAVERSE(out_chans, o, node) {
1304 int res = 0;
1305 struct ast_frame *f;
1306 struct ast_channel *c = o->chan;
1307
1308 if (c == NULL)
1309 continue;
1311 if (!peer) {
1312 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1313 if (o->orig_chan_name
1314 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1315 /*
1316 * The channel name changed so we must generate COLP update.
1317 * Likely because a call pickup channel masqueraded in.
1318 */
1320 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1321 if (o->pending_connected_update) {
1324 }
1325 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1327 }
1328 }
1329 if (o->aoc_s_rate_list) {
1330 size_t encoded_size;
1331 struct ast_aoc_encoded *encoded;
1332 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1333 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1334 ast_aoc_destroy_encoded(encoded);
1335 }
1336 }
1337 peer = c;
1338 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1339 ast_copy_flags64(peerflags, o,
1346 ast_channel_dialcontext_set(c, "");
1348 }
1349 continue;
1350 }
1351 if (c != winner)
1352 continue;
1353 /* here, o->chan == c == winner */
1355 pa->sentringing = 0;
1356 if (!ignore_cc && (f = ast_read(c))) {
1358 /* This channel is forwarding the call, and is capable of CC, so
1359 * be sure to add the new device interface to the list
1360 */
1362 }
1363 ast_frfree(f);
1364 }
1365
1366 if (o->pending_connected_update) {
1367 /*
1368 * Re-seed the chanlist's connected line information with
1369 * previously acquired connected line info from the incoming
1370 * channel. The previously acquired connected line info could
1371 * have been set through the CONNECTED_LINE dialplan function.
1372 */
1377 }
1378
1379 do_forward(o, &num, peerflags, single, caller_entertained, &orig_answer_to,
1380 forced_clid, stored_clid);
1381
1382 if (o->chan) {
1385 if (single
1389 }
1390 }
1391 continue;
1392 }
1393 f = ast_read(winner);
1394 if (!f) {
1397 ast_hangup(c);
1398 c = o->chan = NULL;
1401 continue;
1402 }
1403 switch (f->frametype) {
1404 case AST_FRAME_CONTROL:
1405 switch (f->subclass.integer) {
1406 case AST_CONTROL_ANSWER:
1407 /* This is our guy if someone answered. */
1408 if (!peer) {
1409 ast_trace(-1, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1410 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1411 if (o->orig_chan_name
1412 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1413 /*
1414 * The channel name changed so we must generate COLP update.
1415 * Likely because a call pickup channel masqueraded in.
1416 */
1418 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1419 if (o->pending_connected_update) {
1422 }
1423 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1425 }
1426 }
1427 if (o->aoc_s_rate_list) {
1428 size_t encoded_size;
1429 struct ast_aoc_encoded *encoded;
1430 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1431 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1432 ast_aoc_destroy_encoded(encoded);
1433 }
1434 }
1435 peer = c;
1436 /* Answer can optionally include a topology */
1437 if (f->subclass.topology) {
1438 /*
1439 * We need to bump the refcount on the topology to prevent it
1440 * from being cleaned up when the frame is cleaned up.
1441 */
1442 config->answer_topology = ao2_bump(f->subclass.topology);
1443 ast_trace(-1, "%s Found topology in frame: %p %p %s\n",
1444 ast_channel_name(peer), f, config->answer_topology,
1445 ast_str_tmp(256, ast_stream_topology_to_str(config->answer_topology, &STR_TMP)));
1446 }
1447
1448 /* Inform everyone else that they've been canceled.
1449 * The dial end event for the peer will be sent out after
1450 * other Dial options have been handled.
1451 */
1452 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1453 ast_copy_flags64(peerflags, o,
1460 ast_channel_dialcontext_set(c, "");
1462 if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
1463 /* Setup early bridge if appropriate */
1465 }
1466 }
1467 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1470 break;
1471 case AST_CONTROL_BUSY:
1472 ast_verb(3, "%s is busy\n", ast_channel_name(c));
1474 ast_channel_publish_dial(in, c, NULL, "BUSY");
1475 ast_hangup(c);
1476 c = o->chan = NULL;
1479 break;
1481 ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1483 ast_channel_publish_dial(in, c, NULL, "CONGESTION");
1484 ast_hangup(c);
1485 c = o->chan = NULL;
1488 break;
1490 /* This is a tricky area to get right when using a native
1491 * CC agent. The reason is that we do the best we can to send only a
1492 * single ringing notification to the caller.
1493 *
1494 * Call completion complicates the logic used here. CCNR is typically
1495 * offered during a ringing message. Let's say that party A calls
1496 * parties B, C, and D. B and C do not support CC requests, but D
1497 * does. If we were to receive a ringing notification from B before
1498 * the others, then we would end up sending a ringing message to
1499 * A with no CCNR offer present.
1500 *
1501 * The approach that we have taken is that if we receive a ringing
1502 * response from a party and no CCNR offer is present, we need to
1503 * wait. Specifically, we need to wait until either a) a called party
1504 * offers CCNR in its ringing response or b) all called parties have
1505 * responded in some way to our call and none offers CCNR.
1506 *
1507 * The drawback to this is that if one of the parties has a delayed
1508 * response or, god forbid, one just plain doesn't respond to our
1509 * outgoing call, then this will result in a significant delay between
1510 * when the caller places the call and hears ringback.
1511 *
1512 * Note also that if CC is disabled for this call, then it is perfectly
1513 * fine for ringing frames to get sent through.
1514 */
1515 ++num_ringing;
1516 *to_progress = -1;
1517 orig_progress_to = -1;
1518 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1519 ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1520 /* Setup early media if appropriate */
1521 if (single && !caller_entertained
1522 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1524 }
1527 pa->sentringing++;
1528 }
1529 if (!sent_ring) {
1530 struct timeval now, then;
1531 int64_t diff;
1532
1533 now = ast_tvnow();
1534
1537
1539 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1540 set_duration_var(in, "RINGTIME", diff);
1541
1544 sent_ring = 1;
1545 }
1546 }
1547 ast_channel_publish_dial(in, c, NULL, "RINGING");
1548 break;
1550 ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1551 /* Setup early media if appropriate */
1552 if (single && !caller_entertained
1553 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1555 }
1557 if (single || (!single && !pa->sentringing)) {
1559 }
1560 }
1561 *to_progress = -1;
1562 orig_progress_to = -1;
1563 if (!sent_progress) {
1564 struct timeval now, then;
1565 int64_t diff;
1566
1567 now = ast_tvnow();
1568
1571
1573 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1574 set_duration_var(in, "PROGRESSTIME", diff);
1575
1578 sent_progress = 1;
1579
1580 if (!ast_strlen_zero(mf_progress)) {
1581 ast_verb(3,
1582 "Sending MF '%s' to %s as result of "
1583 "receiving a PROGRESS message.\n",
1584 mf_progress, hearpulsing ? "parties" : "called party");
1585 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1586 (hearpulsing ? in : NULL), mf_progress, 50, 55, 120, 65, 0);
1587 }
1588 if (!ast_strlen_zero(sf_progress)) {
1589 ast_verb(3,
1590 "Sending SF '%s' to %s as result of "
1591 "receiving a PROGRESS message.\n",
1592 sf_progress, (hearpulsing ? "parties" : "called party"));
1593 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1594 (hearpulsing ? in : NULL), sf_progress, 0, 0);
1595 }
1596 if (!ast_strlen_zero(dtmf_progress)) {
1597 ast_verb(3,
1598 "Sending DTMF '%s' to the called party as result of "
1599 "receiving a PROGRESS message.\n",
1600 dtmf_progress);
1601 res |= ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1602 }
1603 if (res) {
1604 ast_log(LOG_WARNING, "Called channel %s hung up post-progress before all digits could be sent\n", ast_channel_name(c));
1605 goto wait_over;
1606 }
1607 }
1608 ast_channel_publish_dial(in, c, NULL, "PROGRESS");
1609 break;
1610 case AST_CONTROL_WINK:
1611 ast_verb(3, "%s winked, passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1612 if (!sent_wink) {
1613 sent_wink = 1;
1614 if (!ast_strlen_zero(mf_wink)) {
1615 ast_verb(3,
1616 "Sending MF '%s' to %s as result of "
1617 "receiving a WINK message.\n",
1618 mf_wink, (hearpulsing ? "parties" : "called party"));
1619 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1620 (hearpulsing ? in : NULL), mf_wink, 50, 55, 120, 65, 0);
1621 }
1622 if (!ast_strlen_zero(sf_wink)) {
1623 ast_verb(3,
1624 "Sending SF '%s' to %s as result of "
1625 "receiving a WINK message.\n",
1626 sf_wink, (hearpulsing ? "parties" : "called party"));
1627 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1628 (hearpulsing ? in : NULL), sf_wink, 0, 0);
1629 }
1630 if (res) {
1631 ast_log(LOG_WARNING, "Called channel %s hung up post-wink before all digits could be sent\n", ast_channel_name(c));
1632 goto wait_over;
1633 }
1634 }
1636 break;
1640 if (!single || caller_entertained) {
1641 break;
1642 }
1643 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1646 break;
1649 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1650 break;
1651 }
1652 if (!single) {
1654
1655 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
1662 break;
1663 }
1664 if (ast_channel_connected_line_sub(c, in, f, 1)) {
1666 }
1667 break;
1668 case AST_CONTROL_AOC:
1669 {
1670 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1671 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1673 o->aoc_s_rate_list = decoded;
1674 } else {
1675 ast_aoc_destroy_decoded(decoded);
1676 }
1677 }
1678 break;
1680 if (!single) {
1681 /*
1682 * Redirecting updates to the caller make sense only on single
1683 * calls.
1684 */
1685 break;
1686 }
1688 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1689 break;
1690 }
1691 ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
1693 if (ast_channel_redirecting_sub(c, in, f, 1)) {
1695 }
1696 pa->sentringing = 0;
1697 break;
1699 ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1700 if (single && !caller_entertained
1701 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1703 }
1706 ast_channel_publish_dial(in, c, NULL, "PROCEEDING");
1707 break;
1708 case AST_CONTROL_HOLD:
1709 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1710 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1712 break;
1713 case AST_CONTROL_UNHOLD:
1714 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1715 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1717 break;
1719 case AST_CONTROL_FLASH:
1720 /* Ignore going off hook and flash */
1721 break;
1722 case AST_CONTROL_CC:
1723 if (!ignore_cc) {
1725 cc_frame_received = 1;
1726 }
1727 break;
1730 break;
1732 if (!f->data.ptr) {
1733 ast_log(LOG_WARNING, "Got playback begin directive without filename on %s\n", ast_channel_name(c));
1734 } else {
1735 const char *filename = f->data.ptr;
1736 ast_verb(3, "Playing audio file %s on %s\n", filename, ast_channel_name(in));
1738 }
1739 break;
1740 case -1:
1741 if (single && !caller_entertained) {
1742 ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1743 ast_indicate(in, -1);
1744 pa->sentringing = 0;
1745 }
1746 break;
1747 default:
1748 ast_debug(1, "Dunno what to do with control type %d on %s\n", f->subclass.integer, ast_channel_name(in));
1749 break;
1750 }
1751 break;
1752 case AST_FRAME_VIDEO:
1753 case AST_FRAME_VOICE:
1754 case AST_FRAME_IMAGE:
1756 case AST_FRAME_DTMF_END:
1757 if (caller_entertained) {
1758 break;
1759 }
1760 *to_progress = -1;
1761 orig_progress_to = -1;
1762 /* Fall through */
1763 case AST_FRAME_TEXT:
1764 if (single && ast_write(in, f)) {
1765 ast_log(LOG_WARNING, "Unable to write frametype %u on %s\n",
1767 }
1768 break;
1769 case AST_FRAME_HTML:
1771 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1772 ast_log(LOG_WARNING, "Unable to send URL on %s\n", ast_channel_name(in));
1773 }
1774 break;
1775 default:
1776 break;
1777 }
1778 ast_frfree(f);
1779 } /* end for */
1780 if (winner == in) {
1781 struct ast_frame *f = ast_read(in);
1782 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1783 /* Got hung up */
1784 *to_answer = -1;
1785 strcpy(pa->status, "CANCEL");
1786 pa->canceled = 1;
1787 publish_dial_end_event(in, out_chans, NULL, pa->status);
1788 if (f) {
1789 if (f->data.uint32) {
1791 }
1792 ast_frfree(f);
1793 }
1794 if (is_cc_recall) {
1795 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1796 }
1797 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller hung up\n", ast_channel_name(in));
1798 }
1799
1800 /* now f is guaranteed non-NULL */
1801 if (f->frametype == AST_FRAME_DTMF) {
1802 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1803 const char *context;
1805 if ((context = pbx_builtin_getvar_helper(in, "EXITCONTEXT"))) {
1806 context = ast_strdupa(context);
1807 }
1809 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1810 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1811 *to_answer = 0;
1812 *result = f->subclass.integer;
1813 strcpy(pa->status, "CANCEL");
1814 pa->canceled = 1;
1815 publish_dial_end_event(in, out_chans, NULL, pa->status);
1816 ast_frfree(f);
1817 if (is_cc_recall) {
1818 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1819 }
1820 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller pressed %c to end call\n",
1822 }
1823 }
1824
1825 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1826 detect_disconnect(in, f->subclass.integer, &featurecode)) {
1827 ast_verb(3, "User requested call disconnect.\n");
1828 *to_answer = 0;
1829 strcpy(pa->status, "CANCEL");
1830 pa->canceled = 1;
1831 publish_dial_end_event(in, out_chans, NULL, pa->status);
1832 ast_frfree(f);
1833 if (is_cc_recall) {
1834 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1835 }
1836 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller requested disconnect\n",
1838 }
1839 }
1840
1841 /* Send the frame from the in channel to all outgoing channels. */
1842 AST_LIST_TRAVERSE(out_chans, o, node) {
1843 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1844 /* This outgoing channel has died so don't send the frame to it. */
1845 continue;
1846 }
1847 switch (f->frametype) {
1848 case AST_FRAME_HTML:
1849 /* Forward HTML stuff */
1851 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1852 ast_log(LOG_WARNING, "Unable to send URL on %s\n", ast_channel_name(o->chan));
1853 }
1854 break;
1855 case AST_FRAME_VIDEO:
1856 case AST_FRAME_VOICE:
1857 case AST_FRAME_IMAGE:
1858 if (!single || caller_entertained) {
1859 /*
1860 * We are calling multiple parties or caller is being
1861 * entertained and has thus not been made compatible.
1862 * No need to check any other called parties.
1863 */
1864 goto skip_frame;
1865 }
1866 /* Fall through */
1867 case AST_FRAME_TEXT:
1869 case AST_FRAME_DTMF_END:
1870 if (ast_write(o->chan, f)) {
1871 ast_log(LOG_WARNING, "Unable to forward frametype %u on %s\n",
1873 }
1874 break;
1875 case AST_FRAME_CONTROL:
1876 switch (f->subclass.integer) {
1877 case AST_CONTROL_HOLD:
1878 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1880 break;
1881 case AST_CONTROL_UNHOLD:
1882 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1884 break;
1885 case AST_CONTROL_FLASH:
1886 ast_verb(3, "Hook flash on %s\n", ast_channel_name(o->chan));
1888 break;
1892 if (!single || caller_entertained) {
1893 /*
1894 * We are calling multiple parties or caller is being
1895 * entertained and has thus not been made compatible.
1896 * No need to check any other called parties.
1897 */
1898 goto skip_frame;
1899 }
1900 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1903 break;
1906 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
1907 break;
1908 }
1909 if (ast_channel_connected_line_sub(in, o->chan, f, 1)) {
1911 }
1912 break;
1915 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
1916 break;
1917 }
1918 if (ast_channel_redirecting_sub(in, o->chan, f, 1)) {
1920 }
1921 break;
1922 default:
1923 /* We are not going to do anything with this frame. */
1924 goto skip_frame;
1925 }
1926 break;
1927 default:
1928 /* We are not going to do anything with this frame. */
1929 goto skip_frame;
1930 }
1931 }
1932skip_frame:;
1933 ast_frfree(f);
1934 }
1935 }
1936
1937wait_over:
1938 if (!*to_answer || ast_check_hangup(in)) {
1939 ast_verb(3, "Nobody picked up in %d ms\n", orig_answer_to);
1940 publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
1941 } else if (!*to_progress) {
1942 ast_verb(3, "No early media received in %d ms\n", orig_progress_to);
1943 publish_dial_end_event(in, out_chans, NULL, "CHANUNAVAIL");
1944 strcpy(pa->status, "CHANUNAVAIL");
1945 *to_answer = 0; /* Reset to prevent hangup */
1946 }
1947
1948 if (is_cc_recall) {
1949 ast_cc_completed(in, "Recall completed!");
1950 }
1951 SCOPE_EXIT_RTN_VALUE(peer, "%s: %s%s\n", ast_channel_name(in),
1952 peer ? "Answered by " : "No answer", peer ? ast_channel_name(peer) : "");
1953}
1954
1955static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
1956{
1957 char disconnect_code[AST_FEATURE_MAX_LEN];
1958 int res;
1959
1960 ast_str_append(featurecode, 1, "%c", code);
1961
1962 res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
1963 if (res) {
1964 ast_str_reset(*featurecode);
1965 return 0;
1966 }
1967
1968 if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
1969 /* Could be a partial match, anyway */
1970 if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
1971 ast_str_reset(*featurecode);
1972 }
1973 return 0;
1974 }
1975
1976 if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
1977 ast_str_reset(*featurecode);
1978 return 0;
1979 }
1980
1981 return 1;
1982}
1983
1984/* returns true if there is a valid privacy reply */
1985static int valid_priv_reply(struct ast_flags64 *opts, int res)
1986{
1987 if (res < '1')
1988 return 0;
1989 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1990 return 1;
1991 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1992 return 1;
1993 return 0;
1994}
1995
1996static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
1997 struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
1998{
1999
2000 int res2;
2001 int loopcount = 0;
2002
2003 /* Get the user's intro, store it in priv-callerintros/$CID,
2004 unless it is already there-- this should be done before the
2005 call is actually dialed */
2006
2007 /* all ring indications and moh for the caller has been halted as soon as the
2008 target extension was picked up. We are going to have to kill some
2009 time and make the caller believe the peer hasn't picked up yet */
2010
2012 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2013 ast_indicate(chan, -1);
2014 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2015 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2016 ast_channel_musicclass_set(chan, original_moh);
2019 pa->sentringing++;
2020 }
2021
2022 /* Start autoservice on the other chan ?? */
2023 res2 = ast_autoservice_start(chan);
2024 /* Now Stream the File */
2025 for (loopcount = 0; loopcount < 3; loopcount++) {
2026 if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
2027 break;
2028 if (!res2) /* on timeout, play the message again */
2029 res2 = ast_play_and_wait(peer, "priv-callpending");
2030 if (!valid_priv_reply(opts, res2))
2031 res2 = 0;
2032 /* priv-callpending script:
2033 "I have a caller waiting, who introduces themselves as:"
2034 */
2035 if (!res2)
2036 res2 = ast_play_and_wait(peer, pa->privintro);
2037 if (!valid_priv_reply(opts, res2))
2038 res2 = 0;
2039 /* now get input from the called party, as to their choice */
2040 if (!res2) {
2041 /* XXX can we have both, or they are mutually exclusive ? */
2042 if (ast_test_flag64(opts, OPT_PRIVACY))
2043 res2 = ast_play_and_wait(peer, "priv-callee-options");
2044 if (ast_test_flag64(opts, OPT_SCREENING))
2045 res2 = ast_play_and_wait(peer, "screen-callee-options");
2046 }
2047
2048 /*! \page DialPrivacy Dial Privacy scripts
2049 * \par priv-callee-options script:
2050 * \li Dial 1 if you wish this caller to reach you directly in the future,
2051 * and immediately connect to their incoming call.
2052 * \li Dial 2 if you wish to send this caller to voicemail now and forevermore.
2053 * \li Dial 3 to send this caller to the torture menus, now and forevermore.
2054 * \li Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
2055 * \li Dial 5 to allow this caller to come straight thru to you in the future,
2056 * but right now, just this once, send them to voicemail.
2057 *
2058 * \par screen-callee-options script:
2059 * \li Dial 1 if you wish to immediately connect to the incoming call
2060 * \li Dial 2 if you wish to send this caller to voicemail.
2061 * \li Dial 3 to send this caller to the torture menus.
2062 * \li Dial 4 to send this caller to a simple "go away" menu.
2063 */
2064 if (valid_priv_reply(opts, res2))
2065 break;
2066 /* invalid option */
2067 res2 = ast_play_and_wait(peer, "vm-sorry");
2068 }
2069
2070 if (ast_test_flag64(opts, OPT_MUSICBACK)) {
2071 ast_moh_stop(chan);
2073 ast_indicate(chan, -1);
2074 pa->sentringing = 0;
2075 }
2077 if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
2078 /* map keypresses to various things, the index is res2 - '1' */
2079 static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
2081 int i = res2 - '1';
2082 ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
2083 opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
2084 ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
2085 }
2086 switch (res2) {
2087 case '1':
2088 break;
2089 case '2':
2090 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2091 break;
2092 case '3':
2093 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2094 break;
2095 case '4':
2096 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2097 break;
2098 case '5':
2099 if (ast_test_flag64(opts, OPT_PRIVACY)) {
2100 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2101 break;
2102 }
2103 /* if not privacy, then 5 is the same as "default" case */
2104 default: /* bad input or -1 if failure to start autoservice */
2105 /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
2106 /* well, there seems basically two choices. Just patch the caller thru immediately,
2107 or,... put 'em thru to voicemail. */
2108 /* since the callee may have hung up, let's do the voicemail thing, no database decision */
2109 ast_verb(3, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
2110 /* XXX should we set status to DENY ? */
2111 /* XXX what about the privacy flags ? */
2112 break;
2113 }
2114
2115 if (res2 == '1') { /* the only case where we actually connect */
2116 /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
2117 just clog things up, and it's not useful information, not being tied to a CID */
2118 if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
2120 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2121 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2122 else
2123 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2124 }
2125 return 0; /* the good exit path */
2126 } else {
2127 return -1;
2128 }
2129}
2130
2131/*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
2132static int setup_privacy_args(struct privacy_args *pa,
2133 struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
2134{
2135 char callerid[60];
2136 int res;
2137 char *l;
2138
2139 if (ast_channel_caller(chan)->id.number.valid
2140 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2141 l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2143 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
2144 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
2145 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
2146 } else {
2147 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
2149 }
2150 } else {
2151 char *tnam, *tn2;
2152
2153 tnam = ast_strdupa(ast_channel_name(chan));
2154 /* clean the channel name so slashes don't try to end up in disk file name */
2155 for (tn2 = tnam; *tn2; tn2++) {
2156 if (*tn2 == '/') /* any other chars to be afraid of? */
2157 *tn2 = '=';
2158 }
2159 ast_verb(3, "Privacy-- callerid is empty\n");
2160
2161 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
2162 l = callerid;
2164 }
2165
2166 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
2167
2168 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
2169 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
2170 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
2172 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
2173 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
2174 }
2175
2176 if (pa->privdb_val == AST_PRIVACY_DENY) {
2177 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
2178 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2179 return 0;
2180 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
2181 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2182 return 0; /* Is this right? */
2183 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
2184 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2185 return 0; /* is this right??? */
2186 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
2187 /* Get the user's intro, store it in priv-callerintros/$CID,
2188 unless it is already there-- this should be done before the
2189 call is actually dialed */
2190
2191 /* make sure the priv-callerintros dir actually exists */
2192 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
2193 if ((res = ast_mkdir(pa->privintro, 0755))) {
2194 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
2195 return -1;
2196 }
2197
2198 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
2199 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
2200 /* the DELUX version of this code would allow this caller the
2201 option to hear and retape their previously recorded intro.
2202 */
2203 } else {
2204 int duration; /* for feedback from play_and_wait */
2205 /* the file doesn't exist yet. Let the caller submit his
2206 vocal intro for posterity */
2207 /* priv-recordintro script:
2208 "At the tone, please say your name:"
2209 */
2211 ast_answer(chan);
2212 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
2213 /* don't think we'll need a lock removed, we took care of
2214 conflicts by naming the pa.privintro file */
2215 if (res == -1) {
2216 /* Delete the file regardless since they hung up during recording */
2218 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2219 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2220 else
2221 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2222 return -1;
2223 }
2224 if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
2225 ast_waitstream(chan, "");
2226 }
2227 }
2228 return 1; /* success */
2229}
2230
2231static void end_bridge_callback(void *data)
2232{
2233 struct ast_channel *chan = data;
2234
2235 ast_channel_lock(chan);
2237 set_duration_var(chan, "ANSWEREDTIME", ast_channel_get_up_time_ms(chan));
2238 set_duration_var(chan, "DIALEDTIME", ast_channel_get_duration_ms(chan));
2240 ast_channel_unlock(chan);
2241}
2242
2243static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
2244 bconfig->end_bridge_callback_data = originator;
2245}
2246
2247static int dial_handle_playtones(struct ast_channel *chan, const char *data)
2248{
2249 struct ast_tone_zone_sound *ts = NULL;
2250 int res;
2251 const char *str = data;
2252
2253 if (ast_strlen_zero(str)) {
2254 ast_debug(1,"Nothing to play\n");
2255 return -1;
2256 }
2257
2259
2260 if (ts && ts->data[0]) {
2261 res = ast_playtones_start(chan, 0, ts->data, 0);
2262 } else {
2263 res = -1;
2264 }
2265
2266 if (ts) {
2268 }
2269
2270 if (res) {
2271 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
2272 }
2273
2274 return res;
2275}
2276
2277/*!
2278 * \internal
2279 * \brief Setup the after bridge goto location on the peer.
2280 * \since 12.0.0
2281 *
2282 * \param chan Calling channel for bridge.
2283 * \param peer Peer channel for bridge.
2284 * \param opts Dialing option flags.
2285 * \param opt_args Dialing option argument strings.
2286 */
2287static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
2288{
2289 const char *context;
2290 const char *extension;
2291 int priority;
2292
2293 if (ast_test_flag64(opts, OPT_PEER_H)) {
2294 ast_channel_lock(chan);
2296 ast_channel_unlock(chan);
2297 ast_bridge_set_after_h(peer, context);
2298 } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
2299 ast_channel_lock(chan);
2303 ast_channel_unlock(chan);
2305 opt_args[OPT_ARG_CALLEE_GO_ON]);
2306 }
2307}
2308
2309static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
2310{
2311 int res = -1; /* default: error */
2312 char *rest, *cur; /* scan the list of destinations */
2313 struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2314 struct chanlist *outgoing;
2315 struct chanlist *tmp;
2316 struct ast_channel *peer = NULL;
2317 int to_answer, to_progress; /* timeouts */
2318 struct cause_args num = { chan, 0, 0, 0 };
2319 int cause, hanguptreecause = -1;
2320
2321 struct ast_bridge_config config = { { 0, } };
2322 struct timeval calldurationlimit = { 0, };
2323 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL;
2324 char *mf_progress = NULL, *mf_wink = NULL;
2325 char *sf_progress = NULL, *sf_wink = NULL;
2326 struct privacy_args pa = {
2327 .sentringing = 0,
2328 .privdb_val = 0,
2329 .status = "INVALIDARGS",
2330 .canceled = 0,
2331 };
2332 int sentringing = 0, moh = 0;
2333 const char *outbound_group = NULL;
2334 int result = 0;
2335 char *parse;
2336 int opermode = 0;
2337 int delprivintro = 0;
2340 AST_APP_ARG(timeout);
2343 );
2344 struct ast_flags64 opts = { 0, };
2345 char *opt_args[OPT_ARG_ARRAY_SIZE];
2346 int fulldial = 0, num_dialed = 0;
2347 int ignore_cc = 0;
2348 char device_name[AST_CHANNEL_NAME];
2349 char forced_clid_name[AST_MAX_EXTENSION];
2350 char stored_clid_name[AST_MAX_EXTENSION];
2351 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2352 /*!
2353 * \brief Forced CallerID party information to send.
2354 * \note This will not have any malloced strings so do not free it.
2355 */
2356 struct ast_party_id forced_clid;
2357 /*!
2358 * \brief Stored CallerID information if needed.
2359 *
2360 * \note If OPT_ORIGINAL_CLID set then this is the o option
2361 * CallerID. Otherwise it is the dialplan extension and hint
2362 * name.
2363 *
2364 * \note This will not have any malloced strings so do not free it.
2365 */
2366 struct ast_party_id stored_clid;
2367 /*!
2368 * \brief CallerID party information to store.
2369 * \note This will not have any malloced strings so do not free it.
2370 */
2371 struct ast_party_caller caller;
2372 int max_forwards;
2373 struct ast_datastore *topology_ds = NULL;
2374 SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data);
2375
2376 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2377 ast_channel_lock(chan);
2379 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2380 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2381 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2382 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2383 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");
2384 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2385 pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");
2386 pbx_builtin_setvar_helper(chan, "RINGTIME", "");
2387 pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");
2388 pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");
2389 pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");
2392 ast_channel_unlock(chan);
2393
2394 if (max_forwards <= 0) {
2395 ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2396 ast_channel_name(chan));
2397 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2398 SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan));
2399 }
2400
2401 if (ast_check_hangup_locked(chan)) {
2402 /*
2403 * Caller hung up before we could dial. If dial is executed
2404 * within an AGI then the AGI has likely eaten all queued
2405 * frames before executing the dial in DeadAGI mode. With
2406 * the caller hung up and no pending frames from the caller's
2407 * read queue, dial would not know that the call has hung up
2408 * until a called channel answers. It is rather annoying to
2409 * whoever just answered the non-existent call.
2410 *
2411 * Dial should not continue execution in DeadAGI mode, hangup
2412 * handlers, or the h exten.
2413 */
2414 ast_verb(3, "Caller hung up before dial.\n");
2415 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
2416 SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan));
2417 }
2418
2419 parse = ast_strdupa(data ?: "");
2420
2422
2423 if (!ast_strlen_zero(args.options) &&
2424 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2425 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2426 goto done;
2427 }
2428
2429 if (ast_cc_call_init(chan, &ignore_cc)) {
2430 goto done;
2431 }
2432
2434 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2435
2436 if (delprivintro < 0 || delprivintro > 1) {
2437 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2438 delprivintro = 0;
2439 }
2440 }
2441
2442 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2443 opt_args[OPT_ARG_RINGBACK] = NULL;
2444 }
2445
2446 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2447 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2448 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2449 }
2450
2452 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2453 if (!calldurationlimit.tv_sec) {
2454 ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);
2455 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2456 goto done;
2457 }
2458 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2459 }
2460
2461 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2462 sf_wink = opt_args[OPT_ARG_SENDDTMF];
2463 dtmfcalled = strsep(&sf_wink, ":");
2464 dtmfcalling = strsep(&sf_wink, ":");
2465 dtmf_progress = strsep(&sf_wink, ":");
2466 mf_progress = strsep(&sf_wink, ":");
2467 mf_wink = strsep(&sf_wink, ":");
2468 sf_progress = strsep(&sf_wink, ":");
2469 }
2470
2472 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2473 goto done;
2474 }
2475
2476 /* Setup the forced CallerID information to send if used. */
2477 ast_party_id_init(&forced_clid);
2478 force_forwards_only = 0;
2479 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2480 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2481 ast_channel_lock(chan);
2482 forced_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2483 ast_channel_unlock(chan);
2484 forced_clid_name[0] = '\0';
2485 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2486 sizeof(forced_clid_name), chan);
2487 force_forwards_only = 1;
2488 } else {
2489 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2490 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2491 &forced_clid.number.str);
2492 }
2493 if (!ast_strlen_zero(forced_clid.name.str)) {
2494 forced_clid.name.valid = 1;
2495 }
2496 if (!ast_strlen_zero(forced_clid.number.str)) {
2497 forced_clid.number.valid = 1;
2498 }
2499 }
2501 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2502 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2503 }
2506 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2507 int pres;
2508
2510 if (0 <= pres) {
2511 forced_clid.number.presentation = pres;
2512 }
2513 }
2514
2515 /* Setup the stored CallerID information if needed. */
2516 ast_party_id_init(&stored_clid);
2517 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2518 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2519 ast_channel_lock(chan);
2520 ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2521 if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2522 stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2523 }
2524 if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2525 stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2526 }
2527 if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2528 stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2529 }
2530 if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2531 stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2532 }
2533 ast_channel_unlock(chan);
2534 } else {
2535 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2536 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2537 &stored_clid.number.str);
2538 if (!ast_strlen_zero(stored_clid.name.str)) {
2539 stored_clid.name.valid = 1;
2540 }
2541 if (!ast_strlen_zero(stored_clid.number.str)) {
2542 stored_clid.number.valid = 1;
2543 }
2544 }
2545 } else {
2546 /*
2547 * In case the new channel has no preset CallerID number by the
2548 * channel driver, setup the dialplan extension and hint name.
2549 */
2550 stored_clid_name[0] = '\0';
2551 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2552 sizeof(stored_clid_name), chan);
2553 if (ast_strlen_zero(stored_clid.name.str)) {
2554 stored_clid.name.str = NULL;
2555 } else {
2556 stored_clid.name.valid = 1;
2557 }
2558 ast_channel_lock(chan);
2559 stored_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2560 stored_clid.number.valid = 1;
2561 ast_channel_unlock(chan);
2562 }
2563
2564 if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2566 }
2569
2571 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2572 if (res <= 0)
2573 goto out;
2574 res = -1; /* reset default */
2575 }
2576
2577 if (continue_exec)
2578 *continue_exec = 0;
2579
2580 /* If a channel group has been specified, get it for use when we create peer channels */
2581
2582 ast_channel_lock(chan);
2583 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2584 outbound_group = ast_strdupa(outbound_group);
2585 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2586 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2587 outbound_group = ast_strdupa(outbound_group);
2588 }
2589 ast_channel_unlock(chan);
2590
2591 /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2595
2596 /* PREDIAL: Run gosub on the caller's channel */
2598 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2600 ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2601 }
2602
2603 /* loop through the list of dial destinations */
2604 rest = args.peers;
2605 while ((cur = strsep(&rest, "&"))) {
2606 struct ast_channel *tc; /* channel for this destination */
2607 char *number;
2608 char *tech;
2609 int i;
2610 size_t tech_len;
2611 size_t number_len;
2612 struct ast_stream_topology *topology;
2613 struct ast_stream *stream;
2614
2615 cur = ast_strip(cur);
2616 if (ast_strlen_zero(cur)) {
2617 /* No tech/resource in this position. */
2618 continue;
2619 }
2620
2621 /* Get a technology/resource pair */
2622 number = cur;
2623 tech = strsep(&number, "/");
2624
2625 num_dialed++;
2626 if (ast_strlen_zero(number)) {
2627 ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2628 goto out;
2629 }
2630
2631 tech_len = strlen(tech) + 1;
2632 number_len = strlen(number) + 1;
2633 tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2634 if (!tmp) {
2635 goto out;
2636 }
2637
2638 /* Save tech, number, and interface. */
2639 cur = tmp->stuff;
2640 strcpy(cur, tech);
2641 tmp->tech = cur;
2642 cur += tech_len;
2643 strcpy(cur, tech);
2644 cur[tech_len - 1] = '/';
2645 tmp->interface = cur;
2646 cur += tech_len;
2647 strcpy(cur, number);
2648 tmp->number = cur;
2649
2650 if (opts.flags) {
2651 /* Set per outgoing call leg options. */
2652 ast_copy_flags64(tmp, &opts,
2662 }
2663
2664 /* Request the peer */
2665
2666 ast_channel_lock(chan);
2667 /*
2668 * Seed the chanlist's connected line information with previously
2669 * acquired connected line info from the incoming channel. The
2670 * previously acquired connected line info could have been set
2671 * through the CONNECTED_LINE dialplan function.
2672 */
2674
2676 topology_ds = ast_channel_datastore_find(chan, &topology_ds_info, NULL);
2677
2678 if (!topology_ds && (topology_ds = ast_datastore_alloc(&topology_ds_info, NULL))) {
2680 ast_channel_datastore_add(chan, topology_ds);
2681 }
2682 }
2683
2684 if (topology_ds) {
2685 ao2_ref(topology_ds->data, +1);
2686 topology = topology_ds->data;
2687 } else {
2689 }
2690
2691 ast_channel_unlock(chan);
2692
2693 for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
2694 stream = ast_stream_topology_get_stream(topology, i);
2695 /* For both recvonly and sendonly the stream state reflects our state, that is we
2696 * are receiving only and we are sending only. Since we are requesting a
2697 * channel for the peer, we need to swap this to reflect what we will be doing.
2698 * That is, if we are receiving from Alice then we want to be sending to Bob,
2699 * so swap recvonly to sendonly and vice versa.
2700 */
2703 } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {
2705 }
2706 }
2707
2708 tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
2709
2710 ast_stream_topology_free(topology);
2711
2712 if (!tc) {
2713 /* If we can't, just go on to the next call */
2714 /* Failure doesn't necessarily mean user error. DAHDI channels could be busy. */
2715 ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n",
2716 tmp->tech, cause, ast_cause2str(cause));
2717 handle_cause(cause, &num);
2718 if (!rest) {
2719 /* we are on the last destination */
2720 ast_channel_hangupcause_set(chan, cause);
2721 }
2722 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2723 if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2725 }
2726 }
2727 chanlist_free(tmp);
2728 continue;
2729 }
2730
2731 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2732 if (!ignore_cc) {
2733 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2734 }
2735
2736 ast_channel_lock_both(tc, chan);
2738
2739 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2740
2741 /* Setup outgoing SDP to match incoming one */
2742 if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2743 /* We are on the only destination. */
2745 }
2746
2747 /* Inherit specially named variables from parent channel */
2751
2752 ast_channel_appl_set(tc, "AppDial");
2753 ast_channel_data_set(tc, "(Outgoing Line)");
2754
2755 memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2756
2757 /* Determine CallerID to store in outgoing channel. */
2759 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2760 caller.id = stored_clid;
2761 ast_channel_set_caller_event(tc, &caller, NULL);
2763 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2764 ast_channel_caller(tc)->id.number.str, NULL))) {
2765 /*
2766 * The new channel has no preset CallerID number by the channel
2767 * driver. Use the dialplan extension and hint name.
2768 */
2769 caller.id = stored_clid;
2770 if (!caller.id.name.valid
2771 && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2772 ast_channel_connected(chan)->id.name.str, NULL))) {
2773 /*
2774 * No hint name available. We have a connected name supplied by
2775 * the dialplan we can use instead.
2776 */
2777 caller.id.name.valid = 1;
2778 caller.id.name = ast_channel_connected(chan)->id.name;
2779 }
2780 ast_channel_set_caller_event(tc, &caller, NULL);
2782 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2783 NULL))) {
2784 /* The new channel has no preset CallerID name by the channel driver. */
2785 if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2786 ast_channel_connected(chan)->id.name.str, NULL))) {
2787 /*
2788 * We have a connected name supplied by the dialplan we can
2789 * use instead.
2790 */
2791 caller.id.name.valid = 1;
2792 caller.id.name = ast_channel_connected(chan)->id.name;
2793 ast_channel_set_caller_event(tc, &caller, NULL);
2794 }
2795 }
2796
2797 /* Determine CallerID for outgoing channel to send. */
2798 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2800
2802 connected.id = forced_clid;
2804 } else {
2806 }
2807
2809
2811
2814 ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2815 }
2816
2817 /* Pass ADSI CPE and transfer capability */
2820
2821 /* If we have an outbound group, set this peer channel to it */
2822 if (outbound_group)
2823 ast_app_group_set_channel(tc, outbound_group);
2824 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2827
2828 /* Check if we're forced by configuration */
2831
2832
2833 /* Inherit context and extension */
2834 ast_channel_dialcontext_set(tc, ast_channel_context(chan));
2836
2838
2839 /* Save the original channel name to detect call pickup masquerading in. */
2841
2843 ast_channel_unlock(chan);
2844
2845 /* Put channel in the list of outgoing thingies. */
2846 tmp->chan = tc;
2847 AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
2848 }
2849
2850 /* As long as we attempted to dial valid peers, don't throw a warning. */
2851 /* If a DAHDI peer is busy, out_chans will be empty so checking list size is misleading. */
2852 if (!num_dialed) {
2853 ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");
2854 if (continue_exec) {
2855 /* There is no point in having RetryDial try again */
2856 *continue_exec = 1;
2857 }
2858 strcpy(pa.status, "CHANUNAVAIL");
2859 res = 0;
2860 goto out;
2861 }
2862
2863 /*
2864 * PREDIAL: Run gosub on all of the callee channels
2865 *
2866 * We run the callee predial before ast_call() in case the user
2867 * wishes to do something on the newly created channels before
2868 * the channel does anything important.
2869 *
2870 * Inside the target gosub we will be able to do something with
2871 * the newly created channel name ie: now the calling channel
2872 * can know what channel will be used to call the destination
2873 * ex: now we will know that SIP/abc-123 is calling SIP/def-124
2874 */
2877 && !AST_LIST_EMPTY(&out_chans)) {
2878 const char *predial_callee;
2879
2881 predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
2882 if (predial_callee) {
2884 AST_LIST_TRAVERSE(&out_chans, tmp, node) {
2885 ast_pre_call(tmp->chan, predial_callee);
2886 }
2888 ast_free((char *) predial_callee);
2889 }
2890 }
2891
2892 /* Start all outgoing calls */
2893 AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
2894 res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
2895 ast_channel_lock(chan);
2896
2897 /* check the results of ast_call */
2898 if (res) {
2899 /* Again, keep going even if there's an error */
2900 ast_debug(1, "ast call on peer returned %d\n", res);
2901 ast_verb(3, "Couldn't call %s\n", tmp->interface);
2902 if (ast_channel_hangupcause(tmp->chan)) {
2904 }
2905 ast_channel_unlock(chan);
2906 ast_cc_call_failed(chan, tmp->chan, tmp->interface);
2907 ast_hangup(tmp->chan);
2908 tmp->chan = NULL;
2910 chanlist_free(tmp);
2911 continue;
2912 }
2913
2914 ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
2915 ast_channel_unlock(chan);
2916
2917 ast_verb(3, "Called %s\n", tmp->interface);
2919
2920 /* If this line is up, don't try anybody else */
2921 if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
2922 break;
2923 }
2924 }
2926
2927 if (ast_strlen_zero(args.timeout)) {
2928 to_answer = -1;
2929 to_progress = -1;
2930 } else {
2931 double tmp;
2932 char *anstimeout = strsep(&args.timeout, "^");
2933 if (!ast_strlen_zero(anstimeout)) {
2934 if (sscanf(anstimeout, "%30lf", &tmp) == 1 && tmp > 0) {
2935 to_answer = tmp * 1000;
2936 ast_debug(3, "Dial timeout set to %d ms\n", to_answer);
2937 } else {
2938 ast_log(LOG_WARNING, "Invalid answer timeout specified: '%s'. Setting timeout to infinite\n", anstimeout);
2939 to_answer = -1;
2940 }
2941 } else {
2942 to_answer = -1;
2943 }
2944 if (!ast_strlen_zero(args.timeout)) {
2945 if (sscanf(args.timeout, "%30lf", &tmp) == 1 && tmp > 0) {
2946 to_progress = tmp * 1000;
2947 ast_debug(3, "Dial progress timeout set to %d ms\n", to_progress);
2948 } else {
2949 ast_log(LOG_WARNING, "Invalid progress timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2950 to_progress = -1;
2951 }
2952 } else {
2953 to_progress = -1;
2954 }
2955 }
2956
2957 outgoing = AST_LIST_FIRST(&out_chans);
2958 if (!outgoing) {
2959 strcpy(pa.status, "CHANUNAVAIL");
2960 if (fulldial == num_dialed) {
2961 res = -1;
2962 goto out;
2963 }
2964 } else {
2965 /* Our status will at least be NOANSWER */
2966 strcpy(pa.status, "NOANSWER");
2968 moh = 1;
2969 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2970 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2971 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2972 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2973 ast_channel_musicclass_set(chan, original_moh);
2974 } else {
2975 ast_moh_start(chan, NULL, NULL);
2976 }
2979 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2980 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2982 sentringing++;
2983 } else {
2985 }
2986 } else {
2988 sentringing++;
2989 }
2990 }
2991 }
2992
2993 peer = wait_for_answer(chan, &out_chans, &to_answer, &to_progress, peerflags, opt_args, &pa, &num, &result,
2994 dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink,
2995 (ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
2996 ignore_cc, &forced_clid, &stored_clid, &config);
2997
2998 if (!peer) {
2999 if (result) {
3000 res = result;
3001 } else if (to_answer) { /* Musta gotten hung up */
3002 res = -1;
3003 } else { /* Nobody answered, next please? */
3004 res = 0;
3005 }
3006 } else {
3007 const char *number;
3008 const char *name;
3009 int dial_end_raised = 0;
3010 int cause = -1;
3011
3012 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
3013 ast_answer(chan);
3014 }
3015
3016 /* Ah ha! Someone answered within the desired timeframe. Of course after this
3017 we will always return with -1 so that it is hung up properly after the
3018 conversation. */
3019
3021 && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
3022 cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
3023 if (cause <= 0) {
3024 if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
3025 cause = 0;
3026 } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
3027 || cause < 0) {
3028 ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
3029 opt_args[OPT_ARG_HANGUPCAUSE]);
3030 cause = -1;
3031 }
3032 }
3033 }
3034 hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
3035
3036 /* If appropriate, log that we have a destination channel and set the answer time */
3037
3038 ast_channel_lock(peer);
3040
3041 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
3042 if (ast_strlen_zero(number)) {
3043 number = NULL;
3044 } else {
3046 }
3047 ast_channel_unlock(peer);
3048
3049 ast_channel_lock(chan);
3051
3052 strcpy(pa.status, "ANSWER");
3053 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3054
3055 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
3056 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
3057
3059 ast_channel_unlock(chan);
3060
3061 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
3062 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
3063 ast_channel_sendurl( peer, args.url );
3064 }
3066 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
3067 ast_channel_publish_dial(chan, peer, NULL, pa.status);
3068 /* hang up on the callee -- he didn't want to talk anyway! */
3070 res = 0;
3071 goto out;
3072 }
3073 }
3074 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
3075 res = 0;
3076 } else {
3077 int digit = 0;
3078 struct ast_channel *chans[2];
3079 struct ast_channel *active_chan;
3080 char *calledfile = NULL, *callerfile = NULL;
3081 int calledstream = 0, callerstream = 0;
3082
3083 chans[0] = chan;
3084 chans[1] = peer;
3085
3086 /* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
3087 callerfile = opt_args[OPT_ARG_ANNOUNCE];
3088 calledfile = strsep(&callerfile, ":");
3089
3090 /* stream the file(s) */
3091 if (!ast_strlen_zero(calledfile)) {
3092 res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
3093 if (res) {
3094 res = 0;
3095 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
3096 } else {
3097 calledstream = 1;
3098 }
3099 }
3100 if (!ast_strlen_zero(callerfile)) {
3101 res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
3102 if (res) {
3103 res = 0;
3104 ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
3105 } else {
3106 callerstream = 1;
3107 }
3108 }
3109
3110 /* can't use ast_waitstream, because we're streaming two files at once, and can't block
3111 We'll need to handle both channels at once. */
3112
3114 while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
3115 int mspeer, mschan;
3116
3117 mspeer = ast_sched_wait(ast_channel_sched(peer));
3118 mschan = ast_sched_wait(ast_channel_sched(chan));
3119
3120 if (calledstream) {
3121 if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
3122 ast_stopstream(peer);
3123 calledstream = 0;
3124 }
3125 }
3126 if (callerstream) {
3127 if (mschan < 0 && !ast_channel_timingfunc(chan)) {
3128 ast_stopstream(chan);
3129 callerstream = 0;
3130 }
3131 }
3132
3133 if (!calledstream && !callerstream) {
3134 break;
3135 }
3136
3137 if (mspeer < 0)
3138 mspeer = 1000;
3139
3140 if (mschan < 0)
3141 mschan = 1000;
3142
3143 /* wait for the lowest maximum of the two */
3144 active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
3145 if (active_chan) {
3146 struct ast_channel *other_chan;
3147 struct ast_frame *fr = ast_read(active_chan);
3148
3149 if (!fr) {
3151 res = -1;
3152 goto done;
3153 }
3154 switch (fr->frametype) {
3155 case AST_FRAME_DTMF_END:
3156 digit = fr->subclass.integer;
3157 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
3158 ast_stopstream(peer);
3159 res = ast_senddigit(chan, digit, 0);
3160 }
3161 break;
3162 case AST_FRAME_CONTROL:
3163 switch (fr->subclass.integer) {
3164 case AST_CONTROL_HANGUP:
3165 ast_frfree(fr);
3167 res = -1;
3168 goto done;
3170 /* Pass COLP update to the other channel. */
3171 if (active_chan == chan) {
3172 other_chan = peer;
3173 } else {
3174 other_chan = chan;
3175 }
3176 if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)) {
3177 ast_indicate_data(other_chan, fr->subclass.integer,
3178 fr->data.ptr, fr->datalen);
3179 }
3180 break;
3181 default:
3182 break;
3183 }
3184 break;
3185 default:
3186 /* Ignore all others */
3187 break;
3188 }
3189 ast_frfree(fr);
3190 }
3193 }
3195 }
3196
3197 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
3198 /* chan and peer are going into the PBX; as such neither are considered
3199 * outgoing channels any longer */
3201
3203 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
3204 /* peer goes to the same context and extension as chan, so just copy info from chan*/
3205 ast_channel_lock(peer);
3212 ast_channel_unlock(peer);
3213 if (ast_pbx_start(peer)) {
3215 }
3216 if (continue_exec)
3217 *continue_exec = 1;
3218 res = 0;
3219 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3220 goto done;
3221 }
3222
3224 const char *gosub_result_peer;
3225 char *gosub_argstart;
3226 char *gosub_args = NULL;
3227 int gosub_res = -1;
3228
3230 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
3231 if (gosub_argstart) {
3232 const char *what_is_s = "s";
3233 *gosub_argstart = 0;
3234 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)) &&
3235 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))) {
3236 what_is_s = "~~s~~";
3237 }
3238 if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
3239 gosub_args = NULL;
3240 }
3241 *gosub_argstart = ',';
3242 } else {
3243 const char *what_is_s = "s";
3244 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)) &&
3245 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))) {
3246 what_is_s = "~~s~~";
3247 }
3248 if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
3249 gosub_args = NULL;
3250 }
3251 }
3252 if (gosub_args) {
3253 gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
3254 ast_free(gosub_args);
3255 } else {
3256 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
3257 }
3258
3259 ast_channel_lock_both(chan, peer);
3260
3261 if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
3262 char *gosub_transfer_dest;
3263 char *gosub_result = ast_strdupa(gosub_result_peer);
3264 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
3265
3266 /* Inherit return value from the peer, so it can be used in the master */
3267 if (gosub_retval) {
3268 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
3269 }
3270
3271 ast_channel_unlock(peer);
3272 ast_channel_unlock(chan);
3273
3274 if (!strcasecmp(gosub_result, "BUSY")) {
3275 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3276 ast_set_flag64(peerflags, OPT_GO_ON);
3277 gosub_res = -1;
3278 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
3279 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3280 ast_set_flag64(peerflags, OPT_GO_ON);
3281 gosub_res = -1;
3282 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
3283 /* Hangup peer and continue with the next extension priority. */
3284 ast_set_flag64(peerflags, OPT_GO_ON);
3285 gosub_res = -1;
3286 } else if (!strcasecmp(gosub_result, "ABORT")) {
3287 /* Hangup both ends unless the caller has the g flag */
3288 gosub_res = -1;
3289 } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
3290 gosub_transfer_dest = gosub_result + 5;
3291 gosub_res = -1;
3292 /* perform a transfer to a new extension */
3293 if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
3294 ast_replace_subargument_delimiter(gosub_transfer_dest);
3295 }
3296 if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
3297 ast_set_flag64(peerflags, OPT_GO_ON);
3298 }
3299 }
3300 if (gosub_res) {
3301 res = gosub_res;
3302 if (!dial_end_raised) {
3303 ast_channel_publish_dial(chan, peer, NULL, gosub_result);
3304 dial_end_raised = 1;
3305 }
3306 }
3307 } else {
3308 ast_channel_unlock(peer);
3309 ast_channel_unlock(chan);
3310 }
3311 }
3312
3313 if (!res) {
3314
3315 /* None of the Dial options changed our status; inform
3316 * everyone that this channel answered
3317 */
3318 if (!dial_end_raised) {
3319 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3320 dial_end_raised = 1;
3321 }
3322
3323 if (!ast_tvzero(calldurationlimit)) {
3324 struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
3325 ast_channel_lock(peer);
3326 ast_channel_whentohangup_set(peer, &whentohangup);
3327 ast_channel_unlock(peer);
3328 }
3329 if (!ast_strlen_zero(dtmfcalled)) {
3330 ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
3331 res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
3332 }
3333 if (!ast_strlen_zero(dtmfcalling)) {
3334 ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
3335 res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
3336 }
3337 }
3338
3339 if (res) { /* some error */
3340 if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
3342 }
3343 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3345 || ast_pbx_start(peer)) {
3347 }
3348 res = -1;
3349 } else {
3350 if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
3351 ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
3352 if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
3353 ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
3354 if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
3355 ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
3356 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
3357 ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
3358 if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
3359 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
3360 if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
3361 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
3362 if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
3363 ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
3364 if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
3365 ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
3366 if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
3367 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
3368 if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
3369 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
3370
3371 config.end_bridge_callback = end_bridge_callback;
3372 config.end_bridge_callback_data = chan;
3373 config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
3374
3375 if (moh) {
3376 moh = 0;
3377 ast_moh_stop(chan);
3378 } else if (sentringing) {
3379 sentringing = 0;
3380 ast_indicate(chan, -1);
3381 }
3382 /* Be sure no generators are left on it and reset the visible indication */
3385 /* Make sure channels are compatible */
3386 res = ast_channel_make_compatible(chan, peer);
3387 if (res < 0) {
3388 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));
3390 res = -1;
3391 goto done;
3392 }
3393 if (opermode) {
3394 struct oprmode oprmode;
3395
3396 oprmode.peer = peer;
3397 oprmode.mode = opermode;
3398
3400 }
3401 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3402
3403 res = ast_bridge_call(chan, peer, &config);
3404 }
3405 }
3406out:
3407 if (moh) {
3408 moh = 0;
3409 ast_moh_stop(chan);
3410 } else if (sentringing) {
3411 sentringing = 0;
3412 ast_indicate(chan, -1);
3413 }
3414
3415 if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3417 if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3418 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
3419 } else {
3420 ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
3421 }
3422 }
3423
3425 /* forward 'answered elsewhere' if we received it */
3427 hanguptreecause = AST_CAUSE_ANSWERED_ELSEWHERE;
3428 } else if (pa.canceled) { /* Caller canceled */
3429 if (ast_channel_hangupcause(chan))
3430 hanguptreecause = ast_channel_hangupcause(chan);
3431 else
3432 hanguptreecause = AST_CAUSE_NORMAL_CLEARING;
3433 }
3434 hanguptree(&out_chans, NULL, hanguptreecause);
3435 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3436 ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
3437
3438 if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
3439 if (!ast_tvzero(calldurationlimit))
3440 memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
3441 res = 0;
3442 }
3443
3444done:
3445 if (config.answer_topology) {
3446 ast_trace(2, "%s Cleaning up topology: %p %s\n",
3447 peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology,
3448 ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP)));
3449
3450 /*
3451 * At this point, the channel driver that answered should have bumped the
3452 * topology refcount for itself. Here we're cleaning up the reference we added
3453 * in wait_for_answer().
3454 */
3455 ast_stream_topology_free(config.answer_topology);
3456 }
3457 if (config.warning_sound) {
3458 ast_free((char *)config.warning_sound);
3459 }
3460 if (config.end_sound) {
3461 ast_free((char *)config.end_sound);
3462 }
3463 if (config.start_sound) {
3464 ast_free((char *)config.start_sound);
3465 }
3466 ast_ignore_cc(chan);
3467 SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan));
3468}
3469
3470static int dial_exec(struct ast_channel *chan, const char *data)
3471{
3472 struct ast_flags64 peerflags;
3473
3474 memset(&peerflags, 0, sizeof(peerflags));
3475
3476 return dial_exec_full(chan, data, &peerflags, NULL);
3477}
3478
3479static int retrydial_exec(struct ast_channel *chan, const char *data)
3480{
3481 char *parse;
3482 const char *context = NULL;
3483 int sleepms = 0, loops = 0, res = -1;
3484 struct ast_flags64 peerflags = { 0, };
3486 AST_APP_ARG(announce);
3487 AST_APP_ARG(sleep);
3488 AST_APP_ARG(retries);
3489 AST_APP_ARG(dialdata);
3490 );
3491
3492 if (ast_strlen_zero(data)) {
3493 ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
3494 return -1;
3495 }
3496
3497 parse = ast_strdupa(data);
3499
3500 if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
3501 sleepms *= 1000;
3502
3503 if (!ast_strlen_zero(args.retries)) {
3504 loops = atoi(args.retries);
3505 }
3506
3507 if (!args.dialdata) {
3508 ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
3509 goto done;
3510 }
3511
3512 if (sleepms < 1000)
3513 sleepms = 10000;
3514
3515 if (!loops)
3516 loops = -1; /* run forever */
3517
3518 ast_channel_lock(chan);
3519 context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
3520 context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
3521 ast_channel_unlock(chan);
3522
3523 res = 0;
3524 while (loops) {
3525 int continue_exec;
3526
3527 ast_channel_data_set(chan, "Retrying");
3529 ast_moh_stop(chan);
3530
3531 res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
3532 if (continue_exec)
3533 break;
3534
3535 if (res == 0) {
3536 if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
3537 if (!ast_strlen_zero(args.announce)) {
3538 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3539 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3541 } else
3542 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3543 }
3544 if (!res && sleepms) {
3546 ast_moh_start(chan, NULL, NULL);
3547 res = ast_waitfordigit(chan, sleepms);
3548 }
3549 } else {
3550 if (!ast_strlen_zero(args.announce)) {
3551 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3552 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3553 res = ast_waitstream(chan, "");
3554 } else
3555 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3556 }
3557 if (sleepms) {
3559 ast_moh_start(chan, NULL, NULL);
3560 if (!res)
3561 res = ast_waitfordigit(chan, sleepms);
3562 }
3563 }
3564 }
3565
3566 if (res < 0 || res == AST_PBX_INCOMPLETE) {
3567 break;
3568 } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
3569 if (onedigit_goto(chan, context, (char) res, 1)) {
3570 res = 0;
3571 break;
3572 }
3573 }
3574 loops--;
3575 }
3576 if (loops == 0)
3577 res = 0;
3578 else if (res == 1)
3579 res = 0;
3580
3582 ast_moh_stop(chan);
3583 done:
3584 return res;
3585}
3586
3587static int unload_module(void)
3588{
3589 int res;
3590
3593
3594 return res;
3595}
3596
3597static int load_module(void)
3598{
3599 int res;
3600
3603
3604 return res;
3605}
3606
3608 .support_level = AST_MODULE_SUPPORT_CORE,
3609 .load = load_module,
3610 .unload = unload_module,
3611);
void * ast_aoc_destroy_encoded(struct ast_aoc_encoded *encoded)
free an ast_aoc_encoded object
Definition aoc.c:322
enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
get the message type, AOC-D, AOC-E, or AOC Request
Definition aoc.c:901
struct ast_aoc_decoded * ast_aoc_decode(struct ast_aoc_encoded *encoded, size_t size, struct ast_channel *chan)
decodes an encoded aoc payload.
Definition aoc.c:458
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition aoc.c:316
struct ast_aoc_encoded * ast_aoc_encode(struct ast_aoc_decoded *decoded, size_t *out_size, struct ast_channel *chan)
encodes a decoded aoc structure so it can be passed on the wire
Definition aoc.c:659
@ AST_AOC_S
Definition aoc.h:64
char digit
static void topology_ds_destroy(void *data)
Definition app_dial.c:827
#define DIAL_STILLGOING
Definition app_dial.c:707
static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
Definition app_dial.c:2310
#define OPT_PREDIAL_CALLER
Definition app_dial.c:718
#define OPT_CANCEL_ELSEWHERE
Definition app_dial.c:710
static const char * get_cid_name(char *name, int namelen, struct ast_channel *chan)
Definition app_dial.c:914
static const char app[]
Definition app_dial.c:670
static const struct ast_app_option dial_exec_options[128]
Definition app_dial.c:792
#define OPT_PEER_H
Definition app_dial.c:711
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)
Definition app_dial.c:944
#define OPT_PREDIAL_CALLEE
Definition app_dial.c:717
#define DIAL_CALLERID_ABSENT
Definition app_dial.c:709
#define OPT_FORCE_CID_PRES
Definition app_dial.c:715
static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
Definition app_dial.c:2288
#define CAN_EARLY_BRIDGE(flags, chan, peer)
Definition app_dial.c:794
#define OPT_TOPOLOGY_PRESERVE
Definition app_dial.c:722
#define OPT_RING_WITH_EARLY_MEDIA
Definition app_dial.c:719
#define OPT_FORCE_CID_TAG
Definition app_dial.c:714
#define OPT_HEARPULSING
Definition app_dial.c:721
static int dial_exec(struct ast_channel *chan, const char *data)
Definition app_dial.c:3471
#define DIAL_NOFORWARDHTML
Definition app_dial.c:708
#define AST_MAX_WATCHERS
Definition app_dial.c:865
#define OPT_CANCEL_TIMEOUT
Definition app_dial.c:713
static void chanlist_free(struct chanlist *outgoing)
Definition app_dial.c:839
static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
Definition app_dial.c:1156
static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
Definition app_dial.c:899
static const char rapp[]
Definition app_dial.c:671
static void handle_cause(int cause, struct cause_args *num)
Definition app_dial.c:877
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:2133
static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration)
Definition app_dial.c:1196
static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
Definition app_dial.c:1176
@ OPT_ARG_CALLEE_GO_ON
Definition app_dial.c:732
@ OPT_ARG_SENDDTMF
Definition app_dial.c:726
@ OPT_ARG_DURATION_STOP
Definition app_dial.c:734
@ OPT_ARG_PREDIAL_CALLEE
Definition app_dial.c:741
@ OPT_ARG_RINGBACK
Definition app_dial.c:730
@ OPT_ARG_MUSICBACK
Definition app_dial.c:729
@ OPT_ARG_CALLEE_GOSUB
Definition app_dial.c:731
@ OPT_ARG_HANGUPCAUSE
Definition app_dial.c:743
@ OPT_ARG_FORCE_CID_PRES
Definition app_dial.c:740
@ OPT_ARG_ANNOUNCE
Definition app_dial.c:725
@ OPT_ARG_GOTO
Definition app_dial.c:727
@ OPT_ARG_DURATION_LIMIT
Definition app_dial.c:728
@ OPT_ARG_ORIGINAL_CLID
Definition app_dial.c:737
@ OPT_ARG_OPERMODE
Definition app_dial.c:735
@ OPT_ARG_FORCECLID
Definition app_dial.c:738
@ OPT_ARG_PREDIAL_CALLER
Definition app_dial.c:742
@ OPT_ARG_ARRAY_SIZE
Definition app_dial.c:745
@ OPT_ARG_PRIVACY
Definition app_dial.c:733
@ OPT_ARG_SCREEN_NOINTRO
Definition app_dial.c:736
@ OPT_ARG_FORCE_CID_TAG
Definition app_dial.c:739
static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
Definition app_dial.c:1956
#define OPT_HANGUPCAUSE
Definition app_dial.c:720
static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
Definition app_dial.c:847
@ OPT_RESETCDR
Definition app_dial.c:675
@ OPT_SCREEN_NOINTRO
Definition app_dial.c:685
@ OPT_DTMF_EXIT
Definition app_dial.c:676
@ OPT_ANNOUNCE
Definition app_dial.c:674
@ OPT_CALLEE_PARK
Definition app_dial.c:698
@ OPT_DURATION_LIMIT
Definition app_dial.c:683
@ OPT_SCREEN_NOCALLERID
Definition app_dial.c:686
@ OPT_IGNORE_FORWARDING
Definition app_dial.c:700
@ OPT_OPERMODE
Definition app_dial.c:697
@ OPT_DURATION_STOP
Definition app_dial.c:691
@ OPT_GO_ON
Definition app_dial.c:679
@ OPT_RINGBACK
Definition app_dial.c:690
@ OPT_GOTO
Definition app_dial.c:696
@ OPT_IGNORE_CONNECTEDLINE
Definition app_dial.c:687
@ OPT_CALLEE_TRANSFER
Definition app_dial.c:692
@ OPT_SENDDTMF
Definition app_dial.c:677
@ OPT_CALLER_MIXMONITOR
Definition app_dial.c:703
@ OPT_CALLER_PARK
Definition app_dial.c:699
@ OPT_CALLER_MONITOR
Definition app_dial.c:695
@ OPT_CALLEE_MONITOR
Definition app_dial.c:694
@ OPT_CALLEE_GOSUB
Definition app_dial.c:701
@ OPT_CALLER_HANGUP
Definition app_dial.c:681
@ OPT_FORCECLID
Definition app_dial.c:678
@ OPT_CALLEE_HANGUP
Definition app_dial.c:680
@ OPT_SCREENING
Definition app_dial.c:688
@ OPT_MUSICBACK
Definition app_dial.c:684
@ OPT_CALLER_TRANSFER
Definition app_dial.c:693
@ OPT_CALLEE_MIXMONITOR
Definition app_dial.c:702
@ OPT_ORIGINAL_CLID
Definition app_dial.c:682
@ OPT_PRIVACY
Definition app_dial.c:689
static const struct ast_datastore_info topology_ds_info
Definition app_dial.c:832
static int load_module(void)
Definition app_dial.c:3598
static int retrydial_exec(struct ast_channel *chan, const char *data)
Definition app_dial.c:3480
static int dial_handle_playtones(struct ast_channel *chan, const char *data)
Definition app_dial.c:2248
static void end_bridge_callback(void *data)
Definition app_dial.c:2232
static int unload_module(void)
Definition app_dial.c:3588
#define OPT_CALLER_ANSWER
Definition app_dial.c:716
static struct ast_channel * wait_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)
Definition app_dial.c:1209
static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator)
Definition app_dial.c:2244
static int valid_priv_reply(struct ast_flags64 *opts, int res)
Definition app_dial.c:1986
#define OPT_CALLEE_GO_ON
Definition app_dial.c:712
jack_status_t status
Definition app_jack.c:149
const char * str
Definition app_jack.c:150
static int silencethreshold
char * strsep(char **str, const char *delims)
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_log
Definition astobj2.c:42
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
int ast_bridge_setup_after_goto(struct ast_channel *chan)
Setup any after bridge goto location to begin execution.
void ast_bridge_set_after_go_on(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *parseable_goto)
Set channel to go on in the dialplan after the bridge.
void ast_bridge_set_after_h(struct ast_channel *chan, const char *context)
Set channel to run the h exten after the bridge.
#define AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN
Definition callerid.h:440
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_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition callerid.c:1162
@ AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER
Definition callerid.h:554
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition callerid.c:1101
#define AST_CAUSE_CONGESTION
Definition causes.h:153
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition causes.h:114
#define AST_CAUSE_NO_ROUTE_DESTINATION
Definition causes.h:100
#define AST_CAUSE_UNREGISTERED
Definition causes.h:154
#define AST_CAUSE_BUSY
Definition causes.h:149
#define AST_CAUSE_NO_ANSWER
Definition causes.h:109
#define AST_CAUSE_NORMAL_CLEARING
Definition causes.h:106
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:4261
void ast_ignore_cc(struct ast_channel *chan)
Mark the channel to ignore further CC activity.
Definition ccss.c:3747
int ast_cc_is_recall(struct ast_channel *chan, int *core_id, const char *const monitor_type)
Decide if a call to a particular channel is a CC recall.
Definition ccss.c:3459
void ast_handle_cc_control_frame(struct ast_channel *inbound, struct ast_channel *outbound, void *frame_data)
Properly react to a CC control frame.
Definition ccss.c:2334
int ast_cc_completed(struct ast_channel *chan, const char *const debug,...)
Indicate recall has been acknowledged.
Definition ccss.c:3885
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:4296
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:2022
int ast_cc_call_init(struct ast_channel *chan, int *ignore_cc)
Start the CC process on a call.
Definition ccss.c:2429
int ast_cc_failed(int core_id, const char *const debug,...)
Indicate failure has occurred.
Definition ccss.c:3924
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:4311
int ast_cdr_reset(const char *channel_name, int keep_variables)
Reset the detail record.
Definition cdr.c:3746
static int priority
static int connected
Definition cdr_pgsql.c:73
static PGresult * result
Definition cel_pgsql.c:84
static const char config[]
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition channel.c:3191
int ast_str2cause(const char *name) attribute_pure
Convert the string form of a cause code to a number.
Definition channel.c:626
const char * ast_channel_name(const struct ast_channel *chan)
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void ast_channel_visible_indication_set(struct ast_channel *chan, int value)
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:10584
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
Definition channel.c:2109
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition channel.c:6496
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Clear a flag on a channel.
Definition channel.c:11122
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition channel.c:2376
void ast_party_id_init(struct ast_party_id *init)
Initialize the given party id structure.
Definition channel.c:1744
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:10422
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition channel.c:1631
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2552
@ AST_CHANNEL_REQUESTOR_BRIDGE_PEER
Definition channel.h:1525
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:8392
const char * ast_channel_musicclass(const struct ast_channel *chan)
int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen)
Sends HTML on given channel Send HTML or URL on link.
Definition channel.c:6663
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition channel.c:2059
int64_t ast_channel_get_up_time_ms(struct ast_channel *chan)
Obtain how long it has been since the channel was answered in ms.
Definition channel.c:2847
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:7424
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:3173
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition channel.c:5009
#define ast_channel_lock(chan)
Definition channel.h:2982
int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer)
Make the frame formats of two channels compatible.
Definition channel.c:6755
void ast_channel_data_set(struct ast_channel *chan, const char *value)
@ AST_FEATURE_AUTOMIXMON
Definition channel.h:1089
@ AST_FEATURE_REDIRECT
Definition channel.h:1084
@ AST_FEATURE_PARKCALL
Definition channel.h:1088
@ AST_FEATURE_AUTOMON
Definition channel.h:1087
@ AST_FEATURE_DISCONNECT
Definition channel.h:1085
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
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:2018
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update)
Set the connected line information based on another connected line source.
Definition channel.c:2041
int ast_channel_priority(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition channel.h:2989
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition channel.c:2359
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:6469
const char * ast_channel_context(const struct ast_channel *chan)
void ast_deactivate_generator(struct ast_channel *chan)
Definition channel.c:2904
int ast_check_hangup_locked(struct ast_channel *chan)
Definition channel.c:460
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition channel.c:5179
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition channel.c:4290
void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Indicate that the connected line information has changed.
Definition channel.c:9177
ast_channel_adsicpe
Definition channel.h:888
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:1986
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:1767
struct timeval ast_channel_creationtime(struct ast_channel *chan)
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:10467
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:6811
int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected)
Parse connected line indication frame data.
Definition channel.c:8869
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:6394
int ast_channel_supports_html(struct ast_channel *channel)
Checks for HTML support on a channel.
Definition channel.c:6658
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition channel.c:446
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
int ast_channel_hangupcause(const struct ast_channel *chan)
int64_t ast_channel_get_duration_ms(struct ast_channel *chan)
Obtain how long it's been, in milliseconds, since the channel was created.
Definition channel.c:2832
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
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:4688
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag)
Set a flag on a channel.
Definition channel.c:11115
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:10368
ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
#define AST_CHANNEL_NAME
Definition channel.h:173
struct timeval * ast_channel_whentohangup(struct ast_channel *chan)
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition channel.c:1678
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition channel.c:2009
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:6670
const char * ast_channel_language(const struct ast_channel *chan)
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
Definition channel.c:613
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
Definition channel.c:2166
void ast_channel_context_set(struct ast_channel *chan, const char *value)
struct ast_sched_context * ast_channel_sched(const struct ast_channel *chan)
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:8377
@ AST_FLAG_OUTGOING
Definition channel.h:1019
@ AST_FLAG_END_DTMF_ONLY
Definition channel.h:1027
@ AST_FLAG_MOH
Definition channel.h:1011
const char * ast_channel_call_forward(const struct ast_channel *chan)
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
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:6479
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:7474
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
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:2032
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer)
Put chan into autoservice while hanging up peer.
void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition channel.c:2817
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Bridge two channels together (early)
Definition channel.c:7464
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition channel.c:4310
const char * ast_channel_exten(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2983
#define AST_MAX_EXTENSION
Definition channel.h:134
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:2122
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:2390
ast_channel_state
ast_channel states
@ AST_STATE_UP
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
const char * ast_hangup_cause_to_dial_status(int hangup_cause)
Convert a hangup cause to a publishable dial status.
Definition dial.c:752
@ THRESHOLD_SILENCE
Definition dsp.h:75
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition dsp.c:2196
char buf[BUFSIZE]
Definition eagi_proxy.c:66
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:694
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,...
Definition features.c:866
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition file.c:223
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition file.c:1312
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition file.c:1148
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
Definition file.c:1160
#define AST_DIGIT_ANY
Definition file.h:48
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition file.c:1874
static const char name[]
Definition format_mp3.c:68
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_ENTER(level,...)
#define ast_trace(level,...)
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_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
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...
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
#define AST_APP_ARG(name)
Define an application argument.
int ast_sf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
Send a string of SF digits to a channel.
Definition main/app.c:1097
int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence_ms, const char *path)
Record a file based on input from a channel. Use default accept and cancel DTMF. This function will p...
Definition main/app.c:2155
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:2194
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
int ast_play_and_wait(struct ast_channel *chan, const char *fn)
Play a stream and wait for a digit, returning the digit that was pressed.
Definition main/app.c:1617
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
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
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
int ast_mf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int between, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
Send a string of MF digits to a channel.
Definition main/app.c:1113
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:3072
#define AST_FEATURE_MAX_LEN
int ast_get_builtin_feature(struct ast_channel *chan, const char *feature, char *buf, size_t len)
Get the DTMF code for a builtin feature.
#define AST_FRAME_DTMF
#define AST_OPTION_OPRMODE
#define ast_frfree(fr)
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_SRCUPDATE
@ AST_CONTROL_PROGRESS
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_UNHOLD
@ AST_CONTROL_VIDUPDATE
@ AST_CONTROL_PROCEEDING
@ AST_CONTROL_REDIRECTING
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_PLAYBACK_BEGIN
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_HANGUP
@ AST_CONTROL_CONNECTED_LINE
@ AST_CONTROL_FLASH
@ AST_CONTROL_SRCCHANGE
@ AST_CONTROL_PVT_CAUSE_CODE
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
int ast_max_forwards_get(struct ast_channel *chan)
Get the current max forwards for a particular channel.
@ AST_MODFLAG_DEFAULT
Definition module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:404
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640
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:7818
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition channel.c:7828
const char * ast_config_AST_DATA_DIR
Definition options.c:159
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
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:4211
#define AST_PBX_INCOMPLETE
Definition pbx.h:51
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.
int ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition pbx.c:8825
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition pbx.c:4744
int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
If an extension hint exists, return non-zero.
Definition pbx.c:4173
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
Definition pbx.c:8910
#define AST_PRIVACY_KILL
Definition privacy.h:32
#define AST_PRIVACY_ALLOW
Definition privacy.h:31
#define AST_PRIVACY_DENY
Definition privacy.h:30
int ast_privacy_set(char *dest, char *cid, int status)
Definition privacy.c:82
int ast_privacy_check(char *dest, char *cid)
Definition privacy.c:46
#define AST_PRIVACY_UNKNOWN
Definition privacy.h:34
#define AST_PRIVACY_TORTURE
Definition privacy.h:33
static char url[512]
static struct @521 args
#define NULL
Definition resample.c:96
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.
int ast_sched_runq(struct ast_sched_context *con)
Runs the queue.
Definition sched.c:786
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
@ AST_STREAM_STATE_RECVONLY
Set when the stream is receiving media only.
Definition stream.h:90
@ AST_STREAM_STATE_SENDONLY
Set when the stream is sending media only.
Definition stream.h:86
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state)
Set the state of a stream.
Definition stream.c:380
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:939
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:791
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition stream.c:768
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream)
Get the current state of a stream.
Definition stream.c:373
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition stream.c:746
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:670
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
#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
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
Definition strings.h:1189
#define ast_str_alloca(init_len)
Definition strings.h:848
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition strings.h:693
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
bridge configuration
Definition channel.h:1096
void * end_bridge_callback_data
Definition channel.h:1111
Main Channel structure associated with a channel.
char exten[AST_MAX_EXTENSION]
const char * data
const struct ast_channel_tech * tech
char context[AST_MAX_CONTEXT]
struct ast_flags flags
Structure for a data store type.
Definition datastore.h:31
const char * type
Definition datastore.h:32
Structure for a data store object.
Definition datastore.h:64
void * data
Definition datastore.h:66
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition utils.h:225
uint64_t flags
Definition utils.h:226
struct ast_stream_topology * topology
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
enum ast_frame_type frametype
union ast_frame::@235 data
Caller Party information.
Definition channel.h:420
Connected Line/Party information.
Definition channel.h:458
struct ast_party_id id
Connected party ID.
Definition channel.h:460
int transit_network_select
Transit Network Select.
Definition channel.h:399
Information needed to identify an endpoint in a call.
Definition channel.h:340
struct ast_party_subaddress subaddress
Subscriber subaddress.
Definition channel.h:346
char * tag
User-set "tag".
Definition channel.h:356
struct ast_party_name name
Subscriber name.
Definition channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition channel.h:344
unsigned char valid
TRUE if the name information is valid/present.
Definition channel.h:281
char * str
Subscriber name (Malloced)
Definition channel.h:266
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition channel.h:297
unsigned char valid
TRUE if the number information is valid/present.
Definition channel.h:299
char * str
Subscriber phone number (Malloced)
Definition channel.h:293
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
Definition channel.h:524
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition channel.h:529
struct ast_party_id to
Call is redirecting to a new party (Sent to the caller)
Definition channel.h:532
char * str
Malloced subaddress string.
Definition channel.h:315
Support for dynamic strings.
Definition strings.h:623
Description of a tone.
Definition indications.h:35
const char * data
Description of a tone.
Definition indications.h:52
int congestion
Definition app_dial.c:873
struct ast_channel * chan
Definition app_dial.c:871
List of channel drivers.
Definition app_dial.c:804
const char * number
Definition app_dial.c:812
const char * interface
Definition app_dial.c:808
struct ast_aoc_decoded * aoc_s_rate_list
Definition app_dial.c:820
struct ast_party_connected_line connected
Definition app_dial.c:817
char * orig_chan_name
Definition app_dial.c:814
char stuff[0]
Definition app_dial.c:822
struct ast_channel * chan
Definition app_dial.c:806
const char * tech
Definition app_dial.c:810
unsigned int pending_connected_update
Definition app_dial.c:819
Definition astman.c:88
structure to hold extensions
Channel datastore data for max forwards.
Number structure.
struct ast_channel * peer
char status[256]
Definition app_dial.c:1152
char privcid[256]
Definition app_dial.c:1150
char privintro[1024]
Definition app_dial.c:1151
int done
static struct test_options options
static struct test_val c
int ast_tvzero(const struct timeval t)
Returns true if the argument is 0,0.
Definition time.h:117
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c:2315
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition extconf.c:2280
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159
FILE * out
Definition utils/frame.c:33
FILE * in
Definition utils/frame.c:33
#define ast_test_flag(p, flag)
Definition utils.h:64
#define ast_set2_flag64(p, value, flag)
Definition utils.h:171
#define ast_test_flag64(p, flag)
Definition utils.h:140
#define ast_clear_flag64(p, flag)
Definition utils.h:154
#define ast_clear_flag(p, flag)
Definition utils.h:78
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition utils.c:2513
#define ast_copy_flags64(dest, src, flagz)
Definition utils.h:161
#define ast_set_flag64(p, flag)
Definition utils.h:147
#define ast_set_flag(p, flag)
Definition utils.h:71
void ast_replace_subargument_delimiter(char *s)
Replace '^' in a string with ','.
Definition utils.c:2377

◆ DIAL_CALLERID_ABSENT

#define DIAL_CALLERID_ABSENT   (1LLU << 33) /* TRUE if caller id is not available for connected line. */

Definition at line 709 of file app_dial.c.

◆ DIAL_NOFORWARDHTML

#define DIAL_NOFORWARDHTML   (1LLU << 32)

Definition at line 708 of file app_dial.c.

◆ DIAL_STILLGOING

#define DIAL_STILLGOING   (1LLU << 31)

Definition at line 707 of file app_dial.c.

◆ OPT_CALLEE_GO_ON

#define OPT_CALLEE_GO_ON   (1LLU << 36)

Definition at line 712 of file app_dial.c.

◆ OPT_CALLER_ANSWER

#define OPT_CALLER_ANSWER   (1LLU << 40)

Definition at line 716 of file app_dial.c.

◆ OPT_CANCEL_ELSEWHERE

#define OPT_CANCEL_ELSEWHERE   (1LLU << 34)

Definition at line 710 of file app_dial.c.

◆ OPT_CANCEL_TIMEOUT

#define OPT_CANCEL_TIMEOUT   (1LLU << 37)

Definition at line 713 of file app_dial.c.

◆ OPT_FORCE_CID_PRES

#define OPT_FORCE_CID_PRES   (1LLU << 39)

Definition at line 715 of file app_dial.c.

◆ OPT_FORCE_CID_TAG

#define OPT_FORCE_CID_TAG   (1LLU << 38)

Definition at line 714 of file app_dial.c.

◆ OPT_HANGUPCAUSE

#define OPT_HANGUPCAUSE   (1LLU << 44)

Definition at line 720 of file app_dial.c.

◆ OPT_HEARPULSING

#define OPT_HEARPULSING   (1LLU << 45)

Definition at line 721 of file app_dial.c.

◆ OPT_PEER_H

#define OPT_PEER_H   (1LLU << 35)

Definition at line 711 of file app_dial.c.

◆ OPT_PREDIAL_CALLEE

#define OPT_PREDIAL_CALLEE   (1LLU << 41)

Definition at line 717 of file app_dial.c.

◆ OPT_PREDIAL_CALLER

#define OPT_PREDIAL_CALLER   (1LLU << 42)

Definition at line 718 of file app_dial.c.

◆ OPT_RING_WITH_EARLY_MEDIA

#define OPT_RING_WITH_EARLY_MEDIA   (1LLU << 43)

Definition at line 719 of file app_dial.c.

◆ OPT_TOPOLOGY_PRESERVE

#define OPT_TOPOLOGY_PRESERVE   (1LLU << 46)

Definition at line 722 of file app_dial.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPT_ANNOUNCE 
OPT_RESETCDR 
OPT_DTMF_EXIT 
OPT_SENDDTMF 
OPT_FORCECLID 
OPT_GO_ON 
OPT_CALLEE_HANGUP 
OPT_CALLER_HANGUP 
OPT_ORIGINAL_CLID 
OPT_DURATION_LIMIT 
OPT_MUSICBACK 
OPT_SCREEN_NOINTRO 
OPT_SCREEN_NOCALLERID 
OPT_IGNORE_CONNECTEDLINE 
OPT_SCREENING 
OPT_PRIVACY 
OPT_RINGBACK 
OPT_DURATION_STOP 
OPT_CALLEE_TRANSFER 
OPT_CALLER_TRANSFER 
OPT_CALLEE_MONITOR 
OPT_CALLER_MONITOR 
OPT_GOTO 
OPT_OPERMODE 
OPT_CALLEE_PARK 
OPT_CALLER_PARK 
OPT_IGNORE_FORWARDING 
OPT_CALLEE_GOSUB 
OPT_CALLEE_MIXMONITOR 
OPT_CALLER_MIXMONITOR 

Definition at line 673 of file app_dial.c.

673 {
674 OPT_ANNOUNCE = (1 << 0),
675 OPT_RESETCDR = (1 << 1),
676 OPT_DTMF_EXIT = (1 << 2),
677 OPT_SENDDTMF = (1 << 3),
678 OPT_FORCECLID = (1 << 4),
679 OPT_GO_ON = (1 << 5),
680 OPT_CALLEE_HANGUP = (1 << 6),
681 OPT_CALLER_HANGUP = (1 << 7),
682 OPT_ORIGINAL_CLID = (1 << 8),
683 OPT_DURATION_LIMIT = (1 << 9),
684 OPT_MUSICBACK = (1 << 10),
685 OPT_SCREEN_NOINTRO = (1 << 12),
686 OPT_SCREEN_NOCALLERID = (1 << 13),
687 OPT_IGNORE_CONNECTEDLINE = (1 << 14),
688 OPT_SCREENING = (1 << 15),
689 OPT_PRIVACY = (1 << 16),
690 OPT_RINGBACK = (1 << 17),
691 OPT_DURATION_STOP = (1 << 18),
692 OPT_CALLEE_TRANSFER = (1 << 19),
693 OPT_CALLER_TRANSFER = (1 << 20),
694 OPT_CALLEE_MONITOR = (1 << 21),
695 OPT_CALLER_MONITOR = (1 << 22),
696 OPT_GOTO = (1 << 23),
697 OPT_OPERMODE = (1 << 24),
698 OPT_CALLEE_PARK = (1 << 25),
699 OPT_CALLER_PARK = (1 << 26),
700 OPT_IGNORE_FORWARDING = (1 << 27),
701 OPT_CALLEE_GOSUB = (1 << 28),
702 OPT_CALLEE_MIXMONITOR = (1 << 29),
703 OPT_CALLER_MIXMONITOR = (1 << 30),
704};

◆ anonymous enum

anonymous enum
Enumerator
OPT_ARG_ANNOUNCE 
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 

Definition at line 724 of file app_dial.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 3612 of file app_dial.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 3612 of file app_dial.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 3612 of file app_dial.c.

◆ chanlist_free()

static void chanlist_free ( struct chanlist outgoing)
static

Definition at line 839 of file app_dial.c.

840{
842 ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
843 ast_free(outgoing->orig_chan_name);
845}

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

Referenced by dial_exec_full(), and hanguptree().

◆ detect_disconnect()

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

Definition at line 1956 of file app_dial.c.

1957{
1958 char disconnect_code[AST_FEATURE_MAX_LEN];
1959 int res;
1960
1961 ast_str_append(featurecode, 1, "%c", code);
1962
1963 res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
1964 if (res) {
1965 ast_str_reset(*featurecode);
1966 return 0;
1967 }
1968
1969 if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
1970 /* Could be a partial match, anyway */
1971 if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
1972 ast_str_reset(*featurecode);
1973 }
1974 return 0;
1975 }
1976
1977 if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
1978 ast_str_reset(*featurecode);
1979 return 0;
1980 }
1981
1982 return 1;
1983}

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

Referenced by wait_for_answer().

◆ dial_exec()

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

Definition at line 3471 of file app_dial.c.

3472{
3473 struct ast_flags64 peerflags;
3474
3475 memset(&peerflags, 0, sizeof(peerflags));
3476
3477 return dial_exec_full(chan, data, &peerflags, NULL);
3478}

References dial_exec_full(), and NULL.

Referenced by load_module().

◆ dial_exec_full()

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

2311{
2312 int res = -1; /* default: error */
2313 char *rest, *cur; /* scan the list of destinations */
2314 struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
2315 struct chanlist *outgoing;
2316 struct chanlist *tmp;
2317 struct ast_channel *peer = NULL;
2318 int to_answer, to_progress; /* timeouts */
2319 struct cause_args num = { chan, 0, 0, 0 };
2320 int cause, hanguptreecause = -1;
2321
2322 struct ast_bridge_config config = { { 0, } };
2323 struct timeval calldurationlimit = { 0, };
2324 char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL;
2325 char *mf_progress = NULL, *mf_wink = NULL;
2326 char *sf_progress = NULL, *sf_wink = NULL;
2327 struct privacy_args pa = {
2328 .sentringing = 0,
2329 .privdb_val = 0,
2330 .status = "INVALIDARGS",
2331 .canceled = 0,
2332 };
2333 int sentringing = 0, moh = 0;
2334 const char *outbound_group = NULL;
2335 int result = 0;
2336 char *parse;
2337 int opermode = 0;
2338 int delprivintro = 0;
2341 AST_APP_ARG(timeout);
2344 );
2345 struct ast_flags64 opts = { 0, };
2346 char *opt_args[OPT_ARG_ARRAY_SIZE];
2347 int fulldial = 0, num_dialed = 0;
2348 int ignore_cc = 0;
2349 char device_name[AST_CHANNEL_NAME];
2350 char forced_clid_name[AST_MAX_EXTENSION];
2351 char stored_clid_name[AST_MAX_EXTENSION];
2352 int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
2353 /*!
2354 * \brief Forced CallerID party information to send.
2355 * \note This will not have any malloced strings so do not free it.
2356 */
2357 struct ast_party_id forced_clid;
2358 /*!
2359 * \brief Stored CallerID information if needed.
2360 *
2361 * \note If OPT_ORIGINAL_CLID set then this is the o option
2362 * CallerID. Otherwise it is the dialplan extension and hint
2363 * name.
2364 *
2365 * \note This will not have any malloced strings so do not free it.
2366 */
2367 struct ast_party_id stored_clid;
2368 /*!
2369 * \brief CallerID party information to store.
2370 * \note This will not have any malloced strings so do not free it.
2371 */
2372 struct ast_party_caller caller;
2373 int max_forwards;
2374 struct ast_datastore *topology_ds = NULL;
2375 SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data);
2376
2377 /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
2378 ast_channel_lock(chan);
2380 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
2381 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
2382 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
2383 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
2384 pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", "");
2385 pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
2386 pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", "");
2387 pbx_builtin_setvar_helper(chan, "RINGTIME", "");
2388 pbx_builtin_setvar_helper(chan, "RINGTIME_MS", "");
2389 pbx_builtin_setvar_helper(chan, "PROGRESSTIME", "");
2390 pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", "");
2393 ast_channel_unlock(chan);
2394
2395 if (max_forwards <= 0) {
2396 ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
2397 ast_channel_name(chan));
2398 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
2399 SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan));
2400 }
2401
2402 if (ast_check_hangup_locked(chan)) {
2403 /*
2404 * Caller hung up before we could dial. If dial is executed
2405 * within an AGI then the AGI has likely eaten all queued
2406 * frames before executing the dial in DeadAGI mode. With
2407 * the caller hung up and no pending frames from the caller's
2408 * read queue, dial would not know that the call has hung up
2409 * until a called channel answers. It is rather annoying to
2410 * whoever just answered the non-existent call.
2411 *
2412 * Dial should not continue execution in DeadAGI mode, hangup
2413 * handlers, or the h exten.
2414 */
2415 ast_verb(3, "Caller hung up before dial.\n");
2416 pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
2417 SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan));
2418 }
2419
2420 parse = ast_strdupa(data ?: "");
2421
2423
2424 if (!ast_strlen_zero(args.options) &&
2425 ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
2426 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2427 goto done;
2428 }
2429
2430 if (ast_cc_call_init(chan, &ignore_cc)) {
2431 goto done;
2432 }
2433
2435 delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
2436
2437 if (delprivintro < 0 || delprivintro > 1) {
2438 ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
2439 delprivintro = 0;
2440 }
2441 }
2442
2443 if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
2444 opt_args[OPT_ARG_RINGBACK] = NULL;
2445 }
2446
2447 if (ast_test_flag64(&opts, OPT_OPERMODE)) {
2448 opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
2449 ast_verb(3, "Setting operator services mode to %d.\n", opermode);
2450 }
2451
2453 calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
2454 if (!calldurationlimit.tv_sec) {
2455 ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]);
2456 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
2457 goto done;
2458 }
2459 ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
2460 }
2461
2462 if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
2463 sf_wink = opt_args[OPT_ARG_SENDDTMF];
2464 dtmfcalled = strsep(&sf_wink, ":");
2465 dtmfcalling = strsep(&sf_wink, ":");
2466 dtmf_progress = strsep(&sf_wink, ":");
2467 mf_progress = strsep(&sf_wink, ":");
2468 mf_wink = strsep(&sf_wink, ":");
2469 sf_progress = strsep(&sf_wink, ":");
2470 }
2471
2473 if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
2474 goto done;
2475 }
2476
2477 /* Setup the forced CallerID information to send if used. */
2478 ast_party_id_init(&forced_clid);
2479 force_forwards_only = 0;
2480 if (ast_test_flag64(&opts, OPT_FORCECLID)) {
2481 if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
2482 ast_channel_lock(chan);
2483 forced_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2484 ast_channel_unlock(chan);
2485 forced_clid_name[0] = '\0';
2486 forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
2487 sizeof(forced_clid_name), chan);
2488 force_forwards_only = 1;
2489 } else {
2490 /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
2491 ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
2492 &forced_clid.number.str);
2493 }
2494 if (!ast_strlen_zero(forced_clid.name.str)) {
2495 forced_clid.name.valid = 1;
2496 }
2497 if (!ast_strlen_zero(forced_clid.number.str)) {
2498 forced_clid.number.valid = 1;
2499 }
2500 }
2502 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
2503 forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
2504 }
2505 forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
2507 && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
2508 int pres;
2509
2511 if (0 <= pres) {
2512 forced_clid.number.presentation = pres;
2513 }
2514 }
2515
2516 /* Setup the stored CallerID information if needed. */
2517 ast_party_id_init(&stored_clid);
2518 if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
2519 if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
2520 ast_channel_lock(chan);
2521 ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
2522 if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
2523 stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
2524 }
2525 if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2526 stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2527 }
2528 if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
2529 stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
2530 }
2531 if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
2532 stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
2533 }
2534 ast_channel_unlock(chan);
2535 } else {
2536 /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
2537 ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
2538 &stored_clid.number.str);
2539 if (!ast_strlen_zero(stored_clid.name.str)) {
2540 stored_clid.name.valid = 1;
2541 }
2542 if (!ast_strlen_zero(stored_clid.number.str)) {
2543 stored_clid.number.valid = 1;
2544 }
2545 }
2546 } else {
2547 /*
2548 * In case the new channel has no preset CallerID number by the
2549 * channel driver, setup the dialplan extension and hint name.
2550 */
2551 stored_clid_name[0] = '\0';
2552 stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
2553 sizeof(stored_clid_name), chan);
2554 if (ast_strlen_zero(stored_clid.name.str)) {
2555 stored_clid.name.str = NULL;
2556 } else {
2557 stored_clid.name.valid = 1;
2558 }
2559 ast_channel_lock(chan);
2560 stored_clid.number.str = ast_strdupa(ast_channel_exten(chan));
2561 stored_clid.number.valid = 1;
2562 ast_channel_unlock(chan);
2563 }
2564
2565 if (ast_test_flag64(&opts, OPT_RESETCDR)) {
2567 }
2570
2572 res = setup_privacy_args(&pa, &opts, opt_args, chan);
2573 if (res <= 0)
2574 goto out;
2575 res = -1; /* reset default */
2576 }
2577
2578 if (continue_exec)
2579 *continue_exec = 0;
2580
2581 /* If a channel group has been specified, get it for use when we create peer channels */
2582
2583 ast_channel_lock(chan);
2584 if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
2585 outbound_group = ast_strdupa(outbound_group);
2586 pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
2587 } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
2588 outbound_group = ast_strdupa(outbound_group);
2589 }
2590 ast_channel_unlock(chan);
2591
2592 /* Set per dial instance flags. These flags are also passed back to RetryDial. */
2596
2597 /* PREDIAL: Run gosub on the caller's channel */
2599 && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
2601 ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
2602 }
2603
2604 /* loop through the list of dial destinations */
2605 rest = args.peers;
2606 while ((cur = strsep(&rest, "&"))) {
2607 struct ast_channel *tc; /* channel for this destination */
2608 char *number;
2609 char *tech;
2610 int i;
2611 size_t tech_len;
2612 size_t number_len;
2613 struct ast_stream_topology *topology;
2614 struct ast_stream *stream;
2615
2616 cur = ast_strip(cur);
2617 if (ast_strlen_zero(cur)) {
2618 /* No tech/resource in this position. */
2619 continue;
2620 }
2621
2622 /* Get a technology/resource pair */
2623 number = cur;
2624 tech = strsep(&number, "/");
2625
2626 num_dialed++;
2627 if (ast_strlen_zero(number)) {
2628 ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
2629 goto out;
2630 }
2631
2632 tech_len = strlen(tech) + 1;
2633 number_len = strlen(number) + 1;
2634 tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
2635 if (!tmp) {
2636 goto out;
2637 }
2638
2639 /* Save tech, number, and interface. */
2640 cur = tmp->stuff;
2641 strcpy(cur, tech);
2642 tmp->tech = cur;
2643 cur += tech_len;
2644 strcpy(cur, tech);
2645 cur[tech_len - 1] = '/';
2646 tmp->interface = cur;
2647 cur += tech_len;
2648 strcpy(cur, number);
2649 tmp->number = cur;
2650
2651 if (opts.flags) {
2652 /* Set per outgoing call leg options. */
2653 ast_copy_flags64(tmp, &opts,
2663 }
2664
2665 /* Request the peer */
2666
2667 ast_channel_lock(chan);
2668 /*
2669 * Seed the chanlist's connected line information with previously
2670 * acquired connected line info from the incoming channel. The
2671 * previously acquired connected line info could have been set
2672 * through the CONNECTED_LINE dialplan function.
2673 */
2675
2677 topology_ds = ast_channel_datastore_find(chan, &topology_ds_info, NULL);
2678
2679 if (!topology_ds && (topology_ds = ast_datastore_alloc(&topology_ds_info, NULL))) {
2681 ast_channel_datastore_add(chan, topology_ds);
2682 }
2683 }
2684
2685 if (topology_ds) {
2686 ao2_ref(topology_ds->data, +1);
2687 topology = topology_ds->data;
2688 } else {
2690 }
2691
2692 ast_channel_unlock(chan);
2693
2694 for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
2695 stream = ast_stream_topology_get_stream(topology, i);
2696 /* For both recvonly and sendonly the stream state reflects our state, that is we
2697 * are receiving only and we are sending only. Since we are requesting a
2698 * channel for the peer, we need to swap this to reflect what we will be doing.
2699 * That is, if we are receiving from Alice then we want to be sending to Bob,
2700 * so swap recvonly to sendonly and vice versa.
2701 */
2704 } else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) {
2706 }
2707 }
2708
2709 tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause);
2710
2711 ast_stream_topology_free(topology);
2712
2713 if (!tc) {
2714 /* If we can't, just go on to the next call */
2715 /* Failure doesn't necessarily mean user error. DAHDI channels could be busy. */
2716 ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n",
2717 tmp->tech, cause, ast_cause2str(cause));
2718 handle_cause(cause, &num);
2719 if (!rest) {
2720 /* we are on the last destination */
2721 ast_channel_hangupcause_set(chan, cause);
2722 }
2723 if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
2724 if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
2726 }
2727 }
2728 chanlist_free(tmp);
2729 continue;
2730 }
2731
2732 ast_channel_get_device_name(tc, device_name, sizeof(device_name));
2733 if (!ignore_cc) {
2734 ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
2735 }
2736
2737 ast_channel_lock_both(tc, chan);
2739
2740 pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
2741
2742 /* Setup outgoing SDP to match incoming one */
2743 if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
2744 /* We are on the only destination. */
2746 }
2747
2748 /* Inherit specially named variables from parent channel */
2752
2753 ast_channel_appl_set(tc, "AppDial");
2754 ast_channel_data_set(tc, "(Outgoing Line)");
2755
2756 memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
2757
2758 /* Determine CallerID to store in outgoing channel. */
2760 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
2761 caller.id = stored_clid;
2762 ast_channel_set_caller_event(tc, &caller, NULL);
2764 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
2765 ast_channel_caller(tc)->id.number.str, NULL))) {
2766 /*
2767 * The new channel has no preset CallerID number by the channel
2768 * driver. Use the dialplan extension and hint name.
2769 */
2770 caller.id = stored_clid;
2771 if (!caller.id.name.valid
2772 && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2773 ast_channel_connected(chan)->id.name.str, NULL))) {
2774 /*
2775 * No hint name available. We have a connected name supplied by
2776 * the dialplan we can use instead.
2777 */
2778 caller.id.name.valid = 1;
2779 caller.id.name = ast_channel_connected(chan)->id.name;
2780 }
2781 ast_channel_set_caller_event(tc, &caller, NULL);
2783 } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
2784 NULL))) {
2785 /* The new channel has no preset CallerID name by the channel driver. */
2786 if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
2787 ast_channel_connected(chan)->id.name.str, NULL))) {
2788 /*
2789 * We have a connected name supplied by the dialplan we can
2790 * use instead.
2791 */
2792 caller.id.name.valid = 1;
2793 caller.id.name = ast_channel_connected(chan)->id.name;
2794 ast_channel_set_caller_event(tc, &caller, NULL);
2795 }
2796 }
2797
2798 /* Determine CallerID for outgoing channel to send. */
2799 if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
2801
2803 connected.id = forced_clid;
2805 } else {
2807 }
2808
2810
2812
2815 ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
2816 }
2817
2818 /* Pass ADSI CPE and transfer capability */
2821
2822 /* If we have an outbound group, set this peer channel to it */
2823 if (outbound_group)
2824 ast_app_group_set_channel(tc, outbound_group);
2825 /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
2828
2829 /* Check if we're forced by configuration */
2832
2833
2834 /* Inherit context and extension */
2835 ast_channel_dialcontext_set(tc, ast_channel_context(chan));
2837
2839
2840 /* Save the original channel name to detect call pickup masquerading in. */
2842
2844 ast_channel_unlock(chan);
2845
2846 /* Put channel in the list of outgoing thingies. */
2847 tmp->chan = tc;
2848 AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
2849 }
2850
2851 /* As long as we attempted to dial valid peers, don't throw a warning. */
2852 /* If a DAHDI peer is busy, out_chans will be empty so checking list size is misleading. */
2853 if (!num_dialed) {
2854 ast_verb(3, "No devices or endpoints to dial (technology/resource)\n");
2855 if (continue_exec) {
2856 /* There is no point in having RetryDial try again */
2857 *continue_exec = 1;
2858 }
2859 strcpy(pa.status, "CHANUNAVAIL");
2860 res = 0;
2861 goto out;
2862 }
2863
2864 /*
2865 * PREDIAL: Run gosub on all of the callee channels
2866 *
2867 * We run the callee predial before ast_call() in case the user
2868 * wishes to do something on the newly created channels before
2869 * the channel does anything important.
2870 *
2871 * Inside the target gosub we will be able to do something with
2872 * the newly created channel name ie: now the calling channel
2873 * can know what channel will be used to call the destination
2874 * ex: now we will know that SIP/abc-123 is calling SIP/def-124
2875 */
2878 && !AST_LIST_EMPTY(&out_chans)) {
2879 const char *predial_callee;
2880
2882 predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
2883 if (predial_callee) {
2885 AST_LIST_TRAVERSE(&out_chans, tmp, node) {
2886 ast_pre_call(tmp->chan, predial_callee);
2887 }
2889 ast_free((char *) predial_callee);
2890 }
2891 }
2892
2893 /* Start all outgoing calls */
2894 AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
2895 res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
2896 ast_channel_lock(chan);
2897
2898 /* check the results of ast_call */
2899 if (res) {
2900 /* Again, keep going even if there's an error */
2901 ast_debug(1, "ast call on peer returned %d\n", res);
2902 ast_verb(3, "Couldn't call %s\n", tmp->interface);
2903 if (ast_channel_hangupcause(tmp->chan)) {
2905 }
2906 ast_channel_unlock(chan);
2907 ast_cc_call_failed(chan, tmp->chan, tmp->interface);
2908 ast_hangup(tmp->chan);
2909 tmp->chan = NULL;
2911 chanlist_free(tmp);
2912 continue;
2913 }
2914
2915 ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
2916 ast_channel_unlock(chan);
2917
2918 ast_verb(3, "Called %s\n", tmp->interface);
2920
2921 /* If this line is up, don't try anybody else */
2922 if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
2923 break;
2924 }
2925 }
2927
2928 if (ast_strlen_zero(args.timeout)) {
2929 to_answer = -1;
2930 to_progress = -1;
2931 } else {
2932 double tmp;
2933 char *anstimeout = strsep(&args.timeout, "^");
2934 if (!ast_strlen_zero(anstimeout)) {
2935 if (sscanf(anstimeout, "%30lf", &tmp) == 1 && tmp > 0) {
2936 to_answer = tmp * 1000;
2937 ast_debug(3, "Dial timeout set to %d ms\n", to_answer);
2938 } else {
2939 ast_log(LOG_WARNING, "Invalid answer timeout specified: '%s'. Setting timeout to infinite\n", anstimeout);
2940 to_answer = -1;
2941 }
2942 } else {
2943 to_answer = -1;
2944 }
2945 if (!ast_strlen_zero(args.timeout)) {
2946 if (sscanf(args.timeout, "%30lf", &tmp) == 1 && tmp > 0) {
2947 to_progress = tmp * 1000;
2948 ast_debug(3, "Dial progress timeout set to %d ms\n", to_progress);
2949 } else {
2950 ast_log(LOG_WARNING, "Invalid progress timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
2951 to_progress = -1;
2952 }
2953 } else {
2954 to_progress = -1;
2955 }
2956 }
2957
2958 outgoing = AST_LIST_FIRST(&out_chans);
2959 if (!outgoing) {
2960 strcpy(pa.status, "CHANUNAVAIL");
2961 if (fulldial == num_dialed) {
2962 res = -1;
2963 goto out;
2964 }
2965 } else {
2966 /* Our status will at least be NOANSWER */
2967 strcpy(pa.status, "NOANSWER");
2969 moh = 1;
2970 if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
2971 char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
2972 ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
2973 ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
2974 ast_channel_musicclass_set(chan, original_moh);
2975 } else {
2976 ast_moh_start(chan, NULL, NULL);
2977 }
2980 if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
2981 if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
2983 sentringing++;
2984 } else {
2986 }
2987 } else {
2989 sentringing++;
2990 }
2991 }
2992 }
2993
2994 peer = wait_for_answer(chan, &out_chans, &to_answer, &to_progress, peerflags, opt_args, &pa, &num, &result,
2995 dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink,
2996 (ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0),
2997 ignore_cc, &forced_clid, &stored_clid, &config);
2998
2999 if (!peer) {
3000 if (result) {
3001 res = result;
3002 } else if (to_answer) { /* Musta gotten hung up */
3003 res = -1;
3004 } else { /* Nobody answered, next please? */
3005 res = 0;
3006 }
3007 } else {
3008 const char *number;
3009 const char *name;
3010 int dial_end_raised = 0;
3011 int cause = -1;
3012
3013 if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
3014 ast_answer(chan);
3015 }
3016
3017 /* Ah ha! Someone answered within the desired timeframe. Of course after this
3018 we will always return with -1 so that it is hung up properly after the
3019 conversation. */
3020
3022 && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
3023 cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
3024 if (cause <= 0) {
3025 if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
3026 cause = 0;
3027 } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
3028 || cause < 0) {
3029 ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
3030 opt_args[OPT_ARG_HANGUPCAUSE]);
3031 cause = -1;
3032 }
3033 }
3034 }
3035 hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
3036
3037 /* If appropriate, log that we have a destination channel and set the answer time */
3038
3039 ast_channel_lock(peer);
3041
3042 number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
3043 if (ast_strlen_zero(number)) {
3044 number = NULL;
3045 } else {
3047 }
3048 ast_channel_unlock(peer);
3049
3050 ast_channel_lock(chan);
3052
3053 strcpy(pa.status, "ANSWER");
3054 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3055
3056 pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
3057 pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
3058
3060 ast_channel_unlock(chan);
3061
3062 if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
3063 ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
3064 ast_channel_sendurl( peer, args.url );
3065 }
3067 if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
3068 ast_channel_publish_dial(chan, peer, NULL, pa.status);
3069 /* hang up on the callee -- he didn't want to talk anyway! */
3071 res = 0;
3072 goto out;
3073 }
3074 }
3075 if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
3076 res = 0;
3077 } else {
3078 int digit = 0;
3079 struct ast_channel *chans[2];
3080 struct ast_channel *active_chan;
3081 char *calledfile = NULL, *callerfile = NULL;
3082 int calledstream = 0, callerstream = 0;
3083
3084 chans[0] = chan;
3085 chans[1] = peer;
3086
3087 /* we need to stream the announcement(s) when the OPT_ARG_ANNOUNCE (-A) is set */
3088 callerfile = opt_args[OPT_ARG_ANNOUNCE];
3089 calledfile = strsep(&callerfile, ":");
3090
3091 /* stream the file(s) */
3092 if (!ast_strlen_zero(calledfile)) {
3093 res = ast_streamfile(peer, calledfile, ast_channel_language(peer));
3094 if (res) {
3095 res = 0;
3096 ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile);
3097 } else {
3098 calledstream = 1;
3099 }
3100 }
3101 if (!ast_strlen_zero(callerfile)) {
3102 res = ast_streamfile(chan, callerfile, ast_channel_language(chan));
3103 if (res) {
3104 res = 0;
3105 ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile);
3106 } else {
3107 callerstream = 1;
3108 }
3109 }
3110
3111 /* can't use ast_waitstream, because we're streaming two files at once, and can't block
3112 We'll need to handle both channels at once. */
3113
3115 while (ast_channel_stream(peer) || ast_channel_stream(chan)) {
3116 int mspeer, mschan;
3117
3118 mspeer = ast_sched_wait(ast_channel_sched(peer));
3119 mschan = ast_sched_wait(ast_channel_sched(chan));
3120
3121 if (calledstream) {
3122 if (mspeer < 0 && !ast_channel_timingfunc(peer)) {
3123 ast_stopstream(peer);
3124 calledstream = 0;
3125 }
3126 }
3127 if (callerstream) {
3128 if (mschan < 0 && !ast_channel_timingfunc(chan)) {
3129 ast_stopstream(chan);
3130 callerstream = 0;
3131 }
3132 }
3133
3134 if (!calledstream && !callerstream) {
3135 break;
3136 }
3137
3138 if (mspeer < 0)
3139 mspeer = 1000;
3140
3141 if (mschan < 0)
3142 mschan = 1000;
3143
3144 /* wait for the lowest maximum of the two */
3145 active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer));
3146 if (active_chan) {
3147 struct ast_channel *other_chan;
3148 struct ast_frame *fr = ast_read(active_chan);
3149
3150 if (!fr) {
3152 res = -1;
3153 goto done;
3154 }
3155 switch (fr->frametype) {
3156 case AST_FRAME_DTMF_END:
3157 digit = fr->subclass.integer;
3158 if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
3159 ast_stopstream(peer);
3160 res = ast_senddigit(chan, digit, 0);
3161 }
3162 break;
3163 case AST_FRAME_CONTROL:
3164 switch (fr->subclass.integer) {
3165 case AST_CONTROL_HANGUP:
3166 ast_frfree(fr);
3168 res = -1;
3169 goto done;
3171 /* Pass COLP update to the other channel. */
3172 if (active_chan == chan) {
3173 other_chan = peer;
3174 } else {
3175 other_chan = chan;
3176 }
3177 if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)) {
3178 ast_indicate_data(other_chan, fr->subclass.integer,
3179 fr->data.ptr, fr->datalen);
3180 }
3181 break;
3182 default:
3183 break;
3184 }
3185 break;
3186 default:
3187 /* Ignore all others */
3188 break;
3189 }
3190 ast_frfree(fr);
3191 }
3194 }
3196 }
3197
3198 if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
3199 /* chan and peer are going into the PBX; as such neither are considered
3200 * outgoing channels any longer */
3202
3204 ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
3205 /* peer goes to the same context and extension as chan, so just copy info from chan*/
3206 ast_channel_lock(peer);
3213 ast_channel_unlock(peer);
3214 if (ast_pbx_start(peer)) {
3216 }
3217 if (continue_exec)
3218 *continue_exec = 1;
3219 res = 0;
3220 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3221 goto done;
3222 }
3223
3225 const char *gosub_result_peer;
3226 char *gosub_argstart;
3227 char *gosub_args = NULL;
3228 int gosub_res = -1;
3229
3231 gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
3232 if (gosub_argstart) {
3233 const char *what_is_s = "s";
3234 *gosub_argstart = 0;
3235 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)) &&
3236 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))) {
3237 what_is_s = "~~s~~";
3238 }
3239 if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
3240 gosub_args = NULL;
3241 }
3242 *gosub_argstart = ',';
3243 } else {
3244 const char *what_is_s = "s";
3245 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)) &&
3246 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))) {
3247 what_is_s = "~~s~~";
3248 }
3249 if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
3250 gosub_args = NULL;
3251 }
3252 }
3253 if (gosub_args) {
3254 gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
3255 ast_free(gosub_args);
3256 } else {
3257 ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
3258 }
3259
3260 ast_channel_lock_both(chan, peer);
3261
3262 if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
3263 char *gosub_transfer_dest;
3264 char *gosub_result = ast_strdupa(gosub_result_peer);
3265 const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
3266
3267 /* Inherit return value from the peer, so it can be used in the master */
3268 if (gosub_retval) {
3269 pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
3270 }
3271
3272 ast_channel_unlock(peer);
3273 ast_channel_unlock(chan);
3274
3275 if (!strcasecmp(gosub_result, "BUSY")) {
3276 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3277 ast_set_flag64(peerflags, OPT_GO_ON);
3278 gosub_res = -1;
3279 } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
3280 ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
3281 ast_set_flag64(peerflags, OPT_GO_ON);
3282 gosub_res = -1;
3283 } else if (!strcasecmp(gosub_result, "CONTINUE")) {
3284 /* Hangup peer and continue with the next extension priority. */
3285 ast_set_flag64(peerflags, OPT_GO_ON);
3286 gosub_res = -1;
3287 } else if (!strcasecmp(gosub_result, "ABORT")) {
3288 /* Hangup both ends unless the caller has the g flag */
3289 gosub_res = -1;
3290 } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
3291 gosub_transfer_dest = gosub_result + 5;
3292 gosub_res = -1;
3293 /* perform a transfer to a new extension */
3294 if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
3295 ast_replace_subargument_delimiter(gosub_transfer_dest);
3296 }
3297 if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
3298 ast_set_flag64(peerflags, OPT_GO_ON);
3299 }
3300 }
3301 if (gosub_res) {
3302 res = gosub_res;
3303 if (!dial_end_raised) {
3304 ast_channel_publish_dial(chan, peer, NULL, gosub_result);
3305 dial_end_raised = 1;
3306 }
3307 }
3308 } else {
3309 ast_channel_unlock(peer);
3310 ast_channel_unlock(chan);
3311 }
3312 }
3313
3314 if (!res) {
3315
3316 /* None of the Dial options changed our status; inform
3317 * everyone that this channel answered
3318 */
3319 if (!dial_end_raised) {
3320 ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
3321 dial_end_raised = 1;
3322 }
3323
3324 if (!ast_tvzero(calldurationlimit)) {
3325 struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
3326 ast_channel_lock(peer);
3327 ast_channel_whentohangup_set(peer, &whentohangup);
3328 ast_channel_unlock(peer);
3329 }
3330 if (!ast_strlen_zero(dtmfcalled)) {
3331 ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
3332 res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
3333 }
3334 if (!ast_strlen_zero(dtmfcalling)) {
3335 ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
3336 res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
3337 }
3338 }
3339
3340 if (res) { /* some error */
3341 if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
3343 }
3344 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3346 || ast_pbx_start(peer)) {
3348 }
3349 res = -1;
3350 } else {
3351 if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
3352 ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
3353 if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
3354 ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
3355 if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
3356 ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
3357 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
3358 ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
3359 if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
3360 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
3361 if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
3362 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
3363 if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
3364 ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
3365 if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
3366 ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
3367 if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
3368 ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
3369 if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
3370 ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
3371
3372 config.end_bridge_callback = end_bridge_callback;
3373 config.end_bridge_callback_data = chan;
3374 config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
3375
3376 if (moh) {
3377 moh = 0;
3378 ast_moh_stop(chan);
3379 } else if (sentringing) {
3380 sentringing = 0;
3381 ast_indicate(chan, -1);
3382 }
3383 /* Be sure no generators are left on it and reset the visible indication */
3386 /* Make sure channels are compatible */
3387 res = ast_channel_make_compatible(chan, peer);
3388 if (res < 0) {
3389 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));
3391 res = -1;
3392 goto done;
3393 }
3394 if (opermode) {
3395 struct oprmode oprmode;
3396
3397 oprmode.peer = peer;
3398 oprmode.mode = opermode;
3399
3401 }
3402 setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
3403
3404 res = ast_bridge_call(chan, peer, &config);
3405 }
3406 }
3407out:
3408 if (moh) {
3409 moh = 0;
3410 ast_moh_stop(chan);
3411 } else if (sentringing) {
3412 sentringing = 0;
3413 ast_indicate(chan, -1);
3414 }
3415
3416 if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3418 if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
3419 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
3420 } else {
3421 ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
3422 }
3423 }
3424
3426 /* forward 'answered elsewhere' if we received it */
3428 hanguptreecause = AST_CAUSE_ANSWERED_ELSEWHERE;
3429 } else if (pa.canceled) { /* Caller canceled */
3430 if (ast_channel_hangupcause(chan))
3431 hanguptreecause = ast_channel_hangupcause(chan);
3432 else
3433 hanguptreecause = AST_CAUSE_NORMAL_CLEARING;
3434 }
3435 hanguptree(&out_chans, NULL, hanguptreecause);
3436 pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
3437 ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
3438
3439 if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
3440 if (!ast_tvzero(calldurationlimit))
3441 memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
3442 res = 0;
3443 }
3444
3445done:
3446 if (config.answer_topology) {
3447 ast_trace(2, "%s Cleaning up topology: %p %s\n",
3448 peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology,
3449 ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP)));
3450
3451 /*
3452 * At this point, the channel driver that answered should have bumped the
3453 * topology refcount for itself. Here we're cleaning up the reference we added
3454 * in wait_for_answer().
3455 */
3456 ast_stream_topology_free(config.answer_topology);
3457 }
3458 if (config.warning_sound) {
3459 ast_free((char *)config.warning_sound);
3460 }
3461 if (config.end_sound) {
3462 ast_free((char *)config.end_sound);
3463 }
3464 if (config.start_sound) {
3465 ast_free((char *)config.start_sound);
3466 }
3467 ast_ignore_cc(chan);
3468 SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan));
3469}

References ao2_ref, args, 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_CAUSE_ANSWERED_ELSEWHERE, AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NORMAL_CLEARING, ast_cc_busy_interface(), ast_cc_call_failed(), ast_cc_call_init(), ast_cc_callback(), ast_cc_extension_monitor_add_dialstring(), ast_cdr_reset(), ast_channel_adsicpe_set(), ast_channel_appl_set(), ast_channel_caller(), ast_channel_clear_flag(), ast_channel_connected(), ast_channel_connected_line_sub(), ast_channel_context(), ast_channel_context_set(), ast_channel_data_set(), ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_datastore_inherit(), ast_channel_dialed(), ast_channel_early_bridge(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_get_device_name(), ast_channel_get_stream_topology(), ast_channel_hangupcause(), ast_channel_hangupcause_set(), ast_channel_inherit_variables(), ast_channel_language(), ast_channel_lock, ast_channel_lock_both, ast_channel_make_compatible(), ast_channel_musicclass(), AST_CHANNEL_NAME, ast_channel_name(), ast_channel_priority(), ast_channel_priority_set(), ast_channel_publish_dial(), ast_channel_redirecting(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_sched(), ast_channel_sendurl(), ast_channel_set_caller_event(), ast_channel_set_connected_line(), ast_channel_set_flag(), ast_channel_setoption(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_stream(), ast_channel_supports_html(), ast_channel_timingfunc(), ast_channel_transfercapability(), ast_channel_transfercapability_set(), ast_channel_unlock, ast_channel_visible_indication_set(), ast_channel_whentohangup(), ast_channel_whentohangup_set(), ast_check_hangup(), ast_check_hangup_locked(), ast_clear_flag, ast_connected_line_copy_from_caller(), AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HANGUP, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, ast_copy_flags64, ast_copy_string(), ast_datastore_alloc, ast_deactivate_generator(), ast_debug, AST_DECLARE_APP_ARGS, AST_DIGIT_ANY, ast_dtmf_stream(), ast_exists_extension(), AST_FEATURE_AUTOMIXMON, AST_FEATURE_AUTOMON, AST_FEATURE_DISCONNECT, AST_FEATURE_PARKCALL, AST_FEATURE_REDIRECT, ast_filedelete(), ast_fileexists(), AST_FLAG_END_DTMF_ONLY, AST_FLAG_OUTGOING, AST_FRAME_CONTROL, AST_FRAME_DTMF_END, ast_free, ast_frfree, ast_hangup(), ast_ignore_cc(), ast_indicate(), ast_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_log, AST_MAX_EXTENSION, ast_max_forwards_decrement(), ast_max_forwards_get(), ast_moh_start(), ast_moh_stop(), AST_OPTION_OPRMODE, ast_parse_caller_presentation(), ast_parseable_goto(), ast_party_caller_set_init(), ast_party_connected_line_copy(), ast_party_connected_line_set_init(), ast_party_id_init(), ast_party_id_set_init(), ast_party_redirecting_copy(), AST_PBX_INCOMPLETE, ast_pbx_start(), ast_pre_call(), AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, AST_PRIVACY_UNKNOWN, ast_read(), ast_replace_subargument_delimiter(), ast_request_with_stream_topology(), ast_rtp_instance_early_bridge_make_compatible(), ast_sched_runq(), ast_sched_wait(), ast_senddigit(), ast_set2_flag64, ast_set_flag, ast_set_flag64, AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_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_strlen_zero(), ast_test_flag64, ast_trace, ast_tvadd(), ast_tvnow(), ast_tvzero(), ast_verb, ast_waitfor_n(), CAN_EARLY_BRIDGE, privacy_args::canceled, chanlist::chan, cause_args::chan, chanlist_free(), config, chanlist::connected, connected, ast_datastore::data, ast_frame::data, ast_frame::datalen, DIAL_CALLERID_ABSENT, dial_exec_options, dial_handle_playtones(), DIAL_NOFORWARDHTML, DIAL_STILLGOING, digit, done, end_bridge_callback(), end_bridge_callback_data_fixup(), ast_flags64::flags, ast_frame::frametype, get_cid_name(), handle_cause(), hanguptree(), ast_party_caller::id, ast_party_connected_line::id, ast_frame_subclass::integer, chanlist::interface, LOG_ERROR, LOG_NOTICE, LOG_WARNING, oprmode::mode, name, ast_party_id::name, NULL, chanlist::number, ast_party_id::number, OPT_ANNOUNCE, OPT_ARG_ANNOUNCE, OPT_ARG_ARRAY_SIZE, OPT_ARG_CALLEE_GOSUB, OPT_ARG_DURATION_LIMIT, OPT_ARG_DURATION_STOP, OPT_ARG_FORCE_CID_PRES, OPT_ARG_FORCE_CID_TAG, OPT_ARG_FORCECLID, OPT_ARG_GOTO, OPT_ARG_HANGUPCAUSE, OPT_ARG_MUSICBACK, OPT_ARG_OPERMODE, OPT_ARG_ORIGINAL_CLID, OPT_ARG_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLER, OPT_ARG_PRIVACY, OPT_ARG_RINGBACK, OPT_ARG_SCREEN_NOINTRO, OPT_ARG_SENDDTMF, OPT_CALLEE_GOSUB, OPT_CALLEE_HANGUP, OPT_CALLEE_MIXMONITOR, OPT_CALLEE_MONITOR, OPT_CALLEE_PARK, OPT_CALLEE_TRANSFER, OPT_CALLER_ANSWER, OPT_CALLER_HANGUP, OPT_CALLER_MIXMONITOR, OPT_CALLER_MONITOR, OPT_CALLER_PARK, OPT_CALLER_TRANSFER, OPT_CANCEL_ELSEWHERE, OPT_CANCEL_TIMEOUT, OPT_DTMF_EXIT, OPT_DURATION_LIMIT, OPT_DURATION_STOP, OPT_FORCE_CID_PRES, OPT_FORCE_CID_TAG, OPT_FORCECLID, OPT_GO_ON, OPT_GOTO, OPT_HANGUPCAUSE, OPT_HEARPULSING, OPT_IGNORE_CONNECTEDLINE, OPT_IGNORE_FORWARDING, OPT_MUSICBACK, OPT_OPERMODE, OPT_ORIGINAL_CLID, OPT_PREDIAL_CALLEE, OPT_PREDIAL_CALLER, OPT_PRIVACY, OPT_RESETCDR, OPT_RING_WITH_EARLY_MEDIA, OPT_RINGBACK, OPT_SCREEN_NOINTRO, OPT_SCREENING, OPT_SENDDTMF, OPT_TOPOLOGY_PRESERVE, options, chanlist::orig_chan_name, out, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), oprmode::peer, ast_party_number::presentation, privacy_args::privdb_val, privacy_args::privintro, ast_frame::ptr, result, S_COR, SCOPE_ENTER, SCOPE_EXIT_RTN_VALUE, privacy_args::sentringing, setup_peer_after_bridge_goto(), setup_privacy_args(), privacy_args::status, ast_party_name::str, ast_party_number::str, ast_party_subaddress::str, strsep(), chanlist::stuff, ast_party_id::subaddress, ast_frame::subclass, ast_party_id::tag, chanlist::tech, ast_channel::tech, topology_ds_info, ast_party_dialed::transit_network_select, url, ast_party_name::valid, ast_party_number::valid, and wait_for_answer().

Referenced by dial_exec(), and retrydial_exec().

◆ dial_handle_playtones()

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

Definition at line 2248 of file app_dial.c.

2249{
2250 struct ast_tone_zone_sound *ts = NULL;
2251 int res;
2252 const char *str = data;
2253
2254 if (ast_strlen_zero(str)) {
2255 ast_debug(1,"Nothing to play\n");
2256 return -1;
2257 }
2258
2260
2261 if (ts && ts->data[0]) {
2262 res = ast_playtones_start(chan, 0, ts->data, 0);
2263 } else {
2264 res = -1;
2265 }
2266
2267 if (ts) {
2269 }
2270
2271 if (res) {
2272 ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
2273 }
2274
2275 return res;
2276}

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

Referenced by dial_exec_full().

◆ do_forward()

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

947{
948 char tmpchan[256];
949 char forwarder[AST_CHANNEL_NAME];
950 struct ast_channel *original = o->chan;
951 struct ast_channel *c = o->chan; /* the winner */
952 struct ast_channel *in = num->chan; /* the input channel */
953 char *stuff;
954 const char *tech;
955 int cause;
956 struct ast_party_caller caller;
957
958 ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
959 ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
960 if ((stuff = strchr(tmpchan, '/'))) {
961 *stuff++ = '\0';
962 tech = tmpchan;
963 } else {
964 const char *forward_context;
966 forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
967 if (ast_strlen_zero(forward_context)) {
968 forward_context = NULL;
969 }
970 snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
972 stuff = tmpchan;
973 tech = "Local";
974 }
975 if (!strcasecmp(tech, "Local")) {
976 /*
977 * Drop the connected line update block for local channels since
978 * this is going to run dialplan and the user can change his
979 * mind about what connected line information he wants to send.
980 */
982 }
983
984 /* Before processing channel, go ahead and check for forwarding */
985 ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
986 /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
987 if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
988 ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
989 ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL",
990 ast_channel_call_forward(original));
991 c = o->chan = NULL;
992 cause = AST_CAUSE_BUSY;
993 } else {
994 struct ast_stream_topology *topology;
995
999
1000 /* Setup parameters */
1001 c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause);
1002
1003 ast_stream_topology_free(topology);
1004
1005 if (c) {
1006 if (single && !caller_entertained) {
1008 }
1012 pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
1016 /* When a call is forwarded, we don't want to track new interfaces
1017 * dialed for CC purposes. Setting the done flag will ensure that
1018 * any Dial operations that happen later won't record CC interfaces.
1019 */
1020 ast_ignore_cc(o->chan);
1021 ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n",
1023 } else
1025 "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
1026 tech, stuff, cause);
1027 }
1028 if (!c) {
1029 ast_channel_publish_dial(in, original, stuff, "BUSY");
1031 handle_cause(cause, num);
1032 ast_hangup(original);
1033 } else {
1034 ast_channel_lock_both(c, original);
1036 ast_channel_redirecting(original));
1038 ast_channel_unlock(original);
1039
1041
1042 if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
1044 }
1045
1046 if (!ast_channel_redirecting(c)->from.number.valid
1047 || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
1048 /*
1049 * The call was not previously redirected so it is
1050 * now redirected from this number.
1051 */
1057 }
1058
1060
1061 /* Determine CallerID to store in outgoing channel. */
1063 if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
1064 caller.id = *stored_clid;
1067 } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
1068 ast_channel_caller(c)->id.number.str, NULL))) {
1069 /*
1070 * The new channel has no preset CallerID number by the channel
1071 * driver. Use the dialplan extension and hint name.
1072 */
1073 caller.id = *stored_clid;
1076 } else {
1078 }
1079
1080 /* Determine CallerID for outgoing channel to send. */
1083
1085 connected.id = *forced_clid;
1087 } else {
1089 }
1090
1092
1093 ast_channel_appl_set(c, "AppDial");
1094 ast_channel_data_set(c, "(Outgoing Line)");
1096
1098 if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1099 struct ast_party_redirecting redirecting;
1100
1101 /*
1102 * Redirecting updates to the caller make sense only on single
1103 * calls.
1104 *
1105 * Need to re-evalute if unlocking is still required here as macro is gone
1106 */
1107 ast_party_redirecting_init(&redirecting);
1110 if (ast_channel_redirecting_sub(c, in, &redirecting, 0)) {
1111 ast_channel_update_redirecting(in, &redirecting, NULL);
1112 }
1113 ast_party_redirecting_free(&redirecting);
1114 } else {
1116 }
1117
1118 if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
1119 *to = -1;
1120 }
1121
1122 if (ast_call(c, stuff, 0)) {
1123 ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
1124 tech, stuff);
1125 ast_channel_publish_dial(in, original, stuff, "CONGESTION");
1127 ast_hangup(original);
1128 ast_hangup(c);
1129 c = o->chan = NULL;
1130 num->nochan++;
1131 } else {
1132 ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
1133 ast_channel_call_forward(original));
1134
1136
1137 /* Hangup the original channel now, in case we needed it */
1138 ast_hangup(original);
1139 }
1140 if (single && !caller_entertained) {
1141 ast_indicate(in, -1);
1142 }
1143 }
1144}

References ast_call(), AST_CAUSE_BUSY, ast_channel_appl_set(), ast_channel_call_forward(), ast_channel_caller(), ast_channel_connected(), ast_channel_context(), ast_channel_data_set(), ast_channel_datastore_inherit(), ast_channel_dialed(), ast_channel_exten(), ast_channel_get_stream_topology(), ast_channel_inherit_variables(), ast_channel_lock, ast_channel_lock_both, ast_channel_make_compatible(), AST_CHANNEL_NAME, ast_channel_name(), ast_channel_publish_dial(), ast_channel_publish_dial_forward(), ast_channel_publish_snapshot(), ast_channel_redirecting(), ast_channel_redirecting_sub(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_set_caller_event(), ast_channel_unlock, ast_channel_update_redirecting(), ast_clear_flag64, ast_connected_line_copy_from_caller(), ast_copy_string(), ast_hangup(), ast_ignore_cc(), ast_indicate(), ast_log, ast_max_forwards_decrement(), 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_set_flag64, ast_strdup, ast_stream_topology_clone(), ast_stream_topology_free(), ast_strlen_zero(), ast_test_flag64, ast_verb, c, CAN_EARLY_BRIDGE, chanlist::chan, cause_args::chan, connected, DIAL_CALLERID_ABSENT, DIAL_STILLGOING, ast_party_redirecting::from, handle_cause(), ast_party_caller::id, in, LOG_NOTICE, cause_args::nochan, NULL, ast_party_id::number, OPT_CANCEL_TIMEOUT, OPT_FORCECLID, OPT_IGNORE_CONNECTEDLINE, OPT_IGNORE_FORWARDING, OPT_ORIGINAL_CLID, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), S_COR, ast_party_number::str, ast_channel::tech, ast_party_redirecting::to, ast_party_dialed::transit_network_select, and ast_party_number::valid.

Referenced by wait_for_answer().

◆ end_bridge_callback()

static void end_bridge_callback ( void *  data)
static

◆ end_bridge_callback_data_fixup()

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

Definition at line 2244 of file app_dial.c.

2244 {
2245 bconfig->end_bridge_callback_data = originator;
2246}

References ast_bridge_config::end_bridge_callback_data.

Referenced by dial_exec_full().

◆ get_cid_name()

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

Definition at line 914 of file app_dial.c.

915{
916 const char *context;
917 const char *exten;
918
919 ast_channel_lock(chan);
921 exten = ast_strdupa(ast_channel_exten(chan));
922 ast_channel_unlock(chan);
923
924 return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
925}

References ast_channel_context(), ast_channel_exten(), ast_channel_lock, ast_channel_unlock, ast_get_hint(), ast_strdupa, ast_channel::context, ast_channel::exten, name, and NULL.

Referenced by dial_exec_full().

◆ handle_cause()

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

Definition at line 877 of file app_dial.c.

878{
879 switch(cause) {
880 case AST_CAUSE_BUSY:
881 num->busy++;
882 break;
884 num->congestion++;
885 break;
888 num->nochan++;
889 break;
892 break;
893 default:
894 num->nochan++;
895 break;
896 }
897}

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

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

◆ hanguptree()

static void hanguptree ( struct dial_head out_chans,
struct ast_channel exception,
int  hangupcause 
)
static

Definition at line 847 of file app_dial.c.

848{
849 /* Hang up a tree of stuff */
850 struct chanlist *outgoing;
851
852 while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
853 /* Hangup any existing lines we have open */
854 if (outgoing->chan && (outgoing->chan != exception)) {
855 if (hangupcause >= 0) {
856 /* This is for the channel drivers */
857 ast_channel_hangupcause_set(outgoing->chan, hangupcause);
858 }
859 ast_hangup(outgoing->chan);
860 }
862 }
863}

References ast_channel_hangupcause_set(), ast_hangup(), AST_LIST_REMOVE_HEAD, and chanlist_free().

Referenced by dial_exec_full().

◆ load_module()

static int load_module ( void  )
static

Definition at line 3598 of file app_dial.c.

3599{
3600 int res;
3601
3604
3605 return res;
3606}

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

◆ onedigit_goto()

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

Definition at line 899 of file app_dial.c.

900{
901 char rexten[2] = { exten, '\0' };
902
903 if (context) {
904 if (!ast_goto_if_exists(chan, context, rexten, pri))
905 return 1;
906 } else {
907 if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
908 return 1;
909 }
910 return 0;
911}

References ast_channel_context(), ast_goto_if_exists(), ast_channel::context, and ast_channel::exten.

Referenced by retrydial_exec(), and wait_for_answer().

◆ publish_dial_end_event()

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

Definition at line 1156 of file app_dial.c.

1157{
1158 struct chanlist *outgoing;
1159 AST_LIST_TRAVERSE(out_chans, outgoing, node) {
1160 if (!outgoing->chan || outgoing->chan == exception) {
1161 continue;
1162 }
1164 }
1165}

References ast_channel_publish_dial(), AST_LIST_TRAVERSE, in, NULL, and status.

Referenced by wait_for_answer().

◆ retrydial_exec()

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

Definition at line 3480 of file app_dial.c.

3481{
3482 char *parse;
3483 const char *context = NULL;
3484 int sleepms = 0, loops = 0, res = -1;
3485 struct ast_flags64 peerflags = { 0, };
3487 AST_APP_ARG(announce);
3488 AST_APP_ARG(sleep);
3489 AST_APP_ARG(retries);
3490 AST_APP_ARG(dialdata);
3491 );
3492
3493 if (ast_strlen_zero(data)) {
3494 ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
3495 return -1;
3496 }
3497
3498 parse = ast_strdupa(data);
3500
3501 if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
3502 sleepms *= 1000;
3503
3504 if (!ast_strlen_zero(args.retries)) {
3505 loops = atoi(args.retries);
3506 }
3507
3508 if (!args.dialdata) {
3509 ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
3510 goto done;
3511 }
3512
3513 if (sleepms < 1000)
3514 sleepms = 10000;
3515
3516 if (!loops)
3517 loops = -1; /* run forever */
3518
3519 ast_channel_lock(chan);
3520 context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
3521 context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
3522 ast_channel_unlock(chan);
3523
3524 res = 0;
3525 while (loops) {
3526 int continue_exec;
3527
3528 ast_channel_data_set(chan, "Retrying");
3530 ast_moh_stop(chan);
3531
3532 res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
3533 if (continue_exec)
3534 break;
3535
3536 if (res == 0) {
3537 if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
3538 if (!ast_strlen_zero(args.announce)) {
3539 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3540 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3542 } else
3543 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3544 }
3545 if (!res && sleepms) {
3547 ast_moh_start(chan, NULL, NULL);
3548 res = ast_waitfordigit(chan, sleepms);
3549 }
3550 } else {
3551 if (!ast_strlen_zero(args.announce)) {
3552 if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
3553 if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
3554 res = ast_waitstream(chan, "");
3555 } else
3556 ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
3557 }
3558 if (sleepms) {
3560 ast_moh_start(chan, NULL, NULL);
3561 if (!res)
3562 res = ast_waitfordigit(chan, sleepms);
3563 }
3564 }
3565 }
3566
3567 if (res < 0 || res == AST_PBX_INCOMPLETE) {
3568 break;
3569 } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
3570 if (onedigit_goto(chan, context, (char) res, 1)) {
3571 res = 0;
3572 break;
3573 }
3574 }
3575 loops--;
3576 }
3577 if (loops == 0)
3578 res = 0;
3579 else if (res == 1)
3580 res = 0;
3581
3583 ast_moh_stop(chan);
3584 done:
3585 return res;
3586}

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

Referenced by load_module().

◆ set_duration_var()

static void set_duration_var ( struct ast_channel chan,
const char *  var_base,
int64_t  duration 
)
static

Definition at line 1196 of file app_dial.c.

1197{
1198 char buf[32];
1199 char full_var_name[128];
1200
1201 snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000);
1202 pbx_builtin_setvar_helper(chan, var_base, buf);
1203
1204 snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base);
1205 snprintf(buf, sizeof(buf), "%" PRId64, duration);
1206 pbx_builtin_setvar_helper(chan, full_var_name, buf);
1207}

References buf, and pbx_builtin_setvar_helper().

Referenced by end_bridge_callback(), and wait_for_answer().

◆ setup_peer_after_bridge_goto()

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

◆ setup_privacy_args()

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

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

Definition at line 2133 of file app_dial.c.

2135{
2136 char callerid[60];
2137 int res;
2138 char *l;
2139
2140 if (ast_channel_caller(chan)->id.number.valid
2141 && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
2142 l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
2144 if (ast_test_flag64(opts, OPT_PRIVACY) ) {
2145 ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
2146 pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
2147 } else {
2148 ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
2150 }
2151 } else {
2152 char *tnam, *tn2;
2153
2154 tnam = ast_strdupa(ast_channel_name(chan));
2155 /* clean the channel name so slashes don't try to end up in disk file name */
2156 for (tn2 = tnam; *tn2; tn2++) {
2157 if (*tn2 == '/') /* any other chars to be afraid of? */
2158 *tn2 = '=';
2159 }
2160 ast_verb(3, "Privacy-- callerid is empty\n");
2161
2162 snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
2163 l = callerid;
2165 }
2166
2167 ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
2168
2169 if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
2170 /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
2171 ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
2173 } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
2174 ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
2175 }
2176
2177 if (pa->privdb_val == AST_PRIVACY_DENY) {
2178 ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
2179 ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
2180 return 0;
2181 } else if (pa->privdb_val == AST_PRIVACY_KILL) {
2182 ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
2183 return 0; /* Is this right? */
2184 } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
2185 ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
2186 return 0; /* is this right??? */
2187 } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
2188 /* Get the user's intro, store it in priv-callerintros/$CID,
2189 unless it is already there-- this should be done before the
2190 call is actually dialed */
2191
2192 /* make sure the priv-callerintros dir actually exists */
2193 snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
2194 if ((res = ast_mkdir(pa->privintro, 0755))) {
2195 ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
2196 return -1;
2197 }
2198
2199 snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
2200 if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
2201 /* the DELUX version of this code would allow this caller the
2202 option to hear and retape their previously recorded intro.
2203 */
2204 } else {
2205 int duration; /* for feedback from play_and_wait */
2206 /* the file doesn't exist yet. Let the caller submit his
2207 vocal intro for posterity */
2208 /* priv-recordintro script:
2209 "At the tone, please say your name:"
2210 */
2212 ast_answer(chan);
2213 res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0); /* NOTE: I've reduced the total time to 4 sec */
2214 /* don't think we'll need a lock removed, we took care of
2215 conflicts by naming the pa.privintro file */
2216 if (res == -1) {
2217 /* Delete the file regardless since they hung up during recording */
2219 if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
2220 ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
2221 else
2222 ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
2223 return -1;
2224 }
2225 if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
2226 ast_waitstream(chan, "");
2227 }
2228 }
2229 return 1; /* success */
2230}

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

Referenced by dial_exec_full().

◆ topology_ds_destroy()

static void topology_ds_destroy ( void *  data)
static

Definition at line 827 of file app_dial.c.

827 {
828 struct ast_stream_topology *top = data;
830}

References ast_stream_topology_free().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 3588 of file app_dial.c.

3589{
3590 int res;
3591
3594
3595 return res;
3596}

References app, ast_unregister_application(), and rapp.

◆ update_connected_line_from_peer()

static void update_connected_line_from_peer ( struct ast_channel chan,
struct ast_channel peer,
int  is_caller 
)
static

◆ valid_priv_reply()

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

Definition at line 1986 of file app_dial.c.

1987{
1988 if (res < '1')
1989 return 0;
1990 if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
1991 return 1;
1992 if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
1993 return 1;
1994 return 0;
1995}

References ast_test_flag64, OPT_PRIVACY, and OPT_SCREENING.

◆ wait_for_answer()

static struct ast_channel * wait_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 
)
static

Definition at line 1209 of file app_dial.c.

1220{
1221 struct cause_args num = *num_in;
1222 int prestart = num.busy + num.congestion + num.nochan;
1223 int orig_answer_to = *to_answer;
1224 int orig_progress_to = *to_progress;
1225 struct ast_channel *peer = NULL;
1226 struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
1227 /* single is set if only one destination is enabled */
1228 int single = outgoing && !AST_LIST_NEXT(outgoing, node);
1229 int caller_entertained = outgoing
1231 struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
1232 int cc_recall_core_id;
1233 int is_cc_recall;
1234 int cc_frame_received = 0;
1235 int num_ringing = 0;
1236 int sent_ring = 0;
1237 int sent_progress = 0, sent_wink = 0;
1238 struct timeval start = ast_tvnow();
1239 SCOPE_ENTER(3, "%s\n", ast_channel_name(in));
1240
1241 if (single) {
1242 /* Turn off hold music, etc */
1243 if (!caller_entertained) {
1245 /* If we are calling a single channel, and not providing ringback or music, */
1246 /* then, make them compatible for in-band tone purpose */
1247 if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
1248 /* If these channels can not be made compatible,
1249 * there is no point in continuing. The bridge
1250 * will just fail if it gets that far.
1251 */
1252 *to_answer = -1;
1253 strcpy(pa->status, "CONGESTION");
1255 SCOPE_EXIT_RTN_VALUE(NULL, "%s: can't be made compat with %s\n",
1257 }
1258 }
1259
1263 }
1264 }
1265
1266 is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
1267
1268 while ((*to_answer = ast_remaining_ms(start, orig_answer_to)) && (*to_progress = ast_remaining_ms(start, orig_progress_to)) && !peer) {
1269 struct chanlist *o;
1270 int pos = 0; /* how many channels do we handle */
1271 int numlines = prestart;
1272 struct ast_channel *winner;
1273 struct ast_channel *watchers[AST_MAX_WATCHERS];
1274
1275 watchers[pos++] = in;
1276 AST_LIST_TRAVERSE(out_chans, o, node) {
1277 /* Keep track of important channels */
1278 if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
1279 watchers[pos++] = o->chan;
1280 numlines++;
1281 }
1282 if (pos == 1) { /* only the input channel is available */
1283 if (numlines == (num.busy + num.congestion + num.nochan)) {
1284 ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1285 if (num.busy)
1286 strcpy(pa->status, "BUSY");
1287 else if (num.congestion)
1288 strcpy(pa->status, "CONGESTION");
1289 else if (num.nochan)
1290 strcpy(pa->status, "CHANUNAVAIL");
1291 } else {
1292 ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
1293 }
1294 *to_answer = 0;
1295 if (is_cc_recall) {
1296 ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
1297 }
1298 SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outgoing channels available\n", ast_channel_name(in));
1299 }
1300
1301 /* If progress timeout is active, use that if it's the shorter of the 2 timeouts. */
1302 winner = ast_waitfor_n(watchers, pos, *to_progress > 0 && (*to_answer < 0 || *to_progress < *to_answer) ? to_progress : to_answer);
1303
1304 AST_LIST_TRAVERSE(out_chans, o, node) {
1305 int res = 0;
1306 struct ast_frame *f;
1307 struct ast_channel *c = o->chan;
1308
1309 if (c == NULL)
1310 continue;
1312 if (!peer) {
1313 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1314 if (o->orig_chan_name
1315 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1316 /*
1317 * The channel name changed so we must generate COLP update.
1318 * Likely because a call pickup channel masqueraded in.
1319 */
1321 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1322 if (o->pending_connected_update) {
1325 }
1326 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1328 }
1329 }
1330 if (o->aoc_s_rate_list) {
1331 size_t encoded_size;
1332 struct ast_aoc_encoded *encoded;
1333 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1334 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1335 ast_aoc_destroy_encoded(encoded);
1336 }
1337 }
1338 peer = c;
1339 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1340 ast_copy_flags64(peerflags, o,
1347 ast_channel_dialcontext_set(c, "");
1349 }
1350 continue;
1351 }
1352 if (c != winner)
1353 continue;
1354 /* here, o->chan == c == winner */
1356 pa->sentringing = 0;
1357 if (!ignore_cc && (f = ast_read(c))) {
1359 /* This channel is forwarding the call, and is capable of CC, so
1360 * be sure to add the new device interface to the list
1361 */
1363 }
1364 ast_frfree(f);
1365 }
1366
1367 if (o->pending_connected_update) {
1368 /*
1369 * Re-seed the chanlist's connected line information with
1370 * previously acquired connected line info from the incoming
1371 * channel. The previously acquired connected line info could
1372 * have been set through the CONNECTED_LINE dialplan function.
1373 */
1378 }
1379
1380 do_forward(o, &num, peerflags, single, caller_entertained, &orig_answer_to,
1381 forced_clid, stored_clid);
1382
1383 if (o->chan) {
1386 if (single
1390 }
1391 }
1392 continue;
1393 }
1394 f = ast_read(winner);
1395 if (!f) {
1398 ast_hangup(c);
1399 c = o->chan = NULL;
1402 continue;
1403 }
1404 switch (f->frametype) {
1405 case AST_FRAME_CONTROL:
1406 switch (f->subclass.integer) {
1407 case AST_CONTROL_ANSWER:
1408 /* This is our guy if someone answered. */
1409 if (!peer) {
1410 ast_trace(-1, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1411 ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
1412 if (o->orig_chan_name
1413 && strcmp(o->orig_chan_name, ast_channel_name(c))) {
1414 /*
1415 * The channel name changed so we must generate COLP update.
1416 * Likely because a call pickup channel masqueraded in.
1417 */
1419 } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
1420 if (o->pending_connected_update) {
1423 }
1424 } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
1426 }
1427 }
1428 if (o->aoc_s_rate_list) {
1429 size_t encoded_size;
1430 struct ast_aoc_encoded *encoded;
1431 if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
1432 ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
1433 ast_aoc_destroy_encoded(encoded);
1434 }
1435 }
1436 peer = c;
1437 /* Answer can optionally include a topology */
1438 if (f->subclass.topology) {
1439 /*
1440 * We need to bump the refcount on the topology to prevent it
1441 * from being cleaned up when the frame is cleaned up.
1442 */
1443 config->answer_topology = ao2_bump(f->subclass.topology);
1444 ast_trace(-1, "%s Found topology in frame: %p %p %s\n",
1445 ast_channel_name(peer), f, config->answer_topology,
1446 ast_str_tmp(256, ast_stream_topology_to_str(config->answer_topology, &STR_TMP)));
1447 }
1448
1449 /* Inform everyone else that they've been canceled.
1450 * The dial end event for the peer will be sent out after
1451 * other Dial options have been handled.
1452 */
1453 publish_dial_end_event(in, out_chans, peer, "CANCEL");
1454 ast_copy_flags64(peerflags, o,
1461 ast_channel_dialcontext_set(c, "");
1463 if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
1464 /* Setup early bridge if appropriate */
1466 }
1467 }
1468 /* If call has been answered, then the eventual hangup is likely to be normal hangup */
1471 break;
1472 case AST_CONTROL_BUSY:
1473 ast_verb(3, "%s is busy\n", ast_channel_name(c));
1475 ast_channel_publish_dial(in, c, NULL, "BUSY");
1476 ast_hangup(c);
1477 c = o->chan = NULL;
1480 break;
1482 ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
1484 ast_channel_publish_dial(in, c, NULL, "CONGESTION");
1485 ast_hangup(c);
1486 c = o->chan = NULL;
1489 break;
1491 /* This is a tricky area to get right when using a native
1492 * CC agent. The reason is that we do the best we can to send only a
1493 * single ringing notification to the caller.
1494 *
1495 * Call completion complicates the logic used here. CCNR is typically
1496 * offered during a ringing message. Let's say that party A calls
1497 * parties B, C, and D. B and C do not support CC requests, but D
1498 * does. If we were to receive a ringing notification from B before
1499 * the others, then we would end up sending a ringing message to
1500 * A with no CCNR offer present.
1501 *
1502 * The approach that we have taken is that if we receive a ringing
1503 * response from a party and no CCNR offer is present, we need to
1504 * wait. Specifically, we need to wait until either a) a called party
1505 * offers CCNR in its ringing response or b) all called parties have
1506 * responded in some way to our call and none offers CCNR.
1507 *
1508 * The drawback to this is that if one of the parties has a delayed
1509 * response or, god forbid, one just plain doesn't respond to our
1510 * outgoing call, then this will result in a significant delay between
1511 * when the caller places the call and hears ringback.
1512 *
1513 * Note also that if CC is disabled for this call, then it is perfectly
1514 * fine for ringing frames to get sent through.
1515 */
1516 ++num_ringing;
1517 *to_progress = -1;
1518 orig_progress_to = -1;
1519 if (ignore_cc || cc_frame_received || num_ringing == numlines) {
1520 ast_verb(3, "%s is ringing\n", ast_channel_name(c));
1521 /* Setup early media if appropriate */
1522 if (single && !caller_entertained
1523 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1525 }
1528 pa->sentringing++;
1529 }
1530 if (!sent_ring) {
1531 struct timeval now, then;
1532 int64_t diff;
1533
1534 now = ast_tvnow();
1535
1538
1540 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1541 set_duration_var(in, "RINGTIME", diff);
1542
1545 sent_ring = 1;
1546 }
1547 }
1548 ast_channel_publish_dial(in, c, NULL, "RINGING");
1549 break;
1551 ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1552 /* Setup early media if appropriate */
1553 if (single && !caller_entertained
1554 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1556 }
1558 if (single || (!single && !pa->sentringing)) {
1560 }
1561 }
1562 *to_progress = -1;
1563 orig_progress_to = -1;
1564 if (!sent_progress) {
1565 struct timeval now, then;
1566 int64_t diff;
1567
1568 now = ast_tvnow();
1569
1572
1574 diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then);
1575 set_duration_var(in, "PROGRESSTIME", diff);
1576
1579 sent_progress = 1;
1580
1581 if (!ast_strlen_zero(mf_progress)) {
1582 ast_verb(3,
1583 "Sending MF '%s' to %s as result of "
1584 "receiving a PROGRESS message.\n",
1585 mf_progress, hearpulsing ? "parties" : "called party");
1586 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1587 (hearpulsing ? in : NULL), mf_progress, 50, 55, 120, 65, 0);
1588 }
1589 if (!ast_strlen_zero(sf_progress)) {
1590 ast_verb(3,
1591 "Sending SF '%s' to %s as result of "
1592 "receiving a PROGRESS message.\n",
1593 sf_progress, (hearpulsing ? "parties" : "called party"));
1594 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1595 (hearpulsing ? in : NULL), sf_progress, 0, 0);
1596 }
1597 if (!ast_strlen_zero(dtmf_progress)) {
1598 ast_verb(3,
1599 "Sending DTMF '%s' to the called party as result of "
1600 "receiving a PROGRESS message.\n",
1601 dtmf_progress);
1602 res |= ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
1603 }
1604 if (res) {
1605 ast_log(LOG_WARNING, "Called channel %s hung up post-progress before all digits could be sent\n", ast_channel_name(c));
1606 goto wait_over;
1607 }
1608 }
1609 ast_channel_publish_dial(in, c, NULL, "PROGRESS");
1610 break;
1611 case AST_CONTROL_WINK:
1612 ast_verb(3, "%s winked, passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1613 if (!sent_wink) {
1614 sent_wink = 1;
1615 if (!ast_strlen_zero(mf_wink)) {
1616 ast_verb(3,
1617 "Sending MF '%s' to %s as result of "
1618 "receiving a WINK message.\n",
1619 mf_wink, (hearpulsing ? "parties" : "called party"));
1620 res |= ast_mf_stream(c, (hearpulsing ? NULL : in),
1621 (hearpulsing ? in : NULL), mf_wink, 50, 55, 120, 65, 0);
1622 }
1623 if (!ast_strlen_zero(sf_wink)) {
1624 ast_verb(3,
1625 "Sending SF '%s' to %s as result of "
1626 "receiving a WINK message.\n",
1627 sf_wink, (hearpulsing ? "parties" : "called party"));
1628 res |= ast_sf_stream(c, (hearpulsing ? NULL : in),
1629 (hearpulsing ? in : NULL), sf_wink, 0, 0);
1630 }
1631 if (res) {
1632 ast_log(LOG_WARNING, "Called channel %s hung up post-wink before all digits could be sent\n", ast_channel_name(c));
1633 goto wait_over;
1634 }
1635 }
1637 break;
1641 if (!single || caller_entertained) {
1642 break;
1643 }
1644 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1647 break;
1650 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
1651 break;
1652 }
1653 if (!single) {
1655
1656 ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
1663 break;
1664 }
1665 if (ast_channel_connected_line_sub(c, in, f, 1)) {
1667 }
1668 break;
1669 case AST_CONTROL_AOC:
1670 {
1671 struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
1672 if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
1674 o->aoc_s_rate_list = decoded;
1675 } else {
1676 ast_aoc_destroy_decoded(decoded);
1677 }
1678 }
1679 break;
1681 if (!single) {
1682 /*
1683 * Redirecting updates to the caller make sense only on single
1684 * calls.
1685 */
1686 break;
1687 }
1689 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
1690 break;
1691 }
1692 ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
1694 if (ast_channel_redirecting_sub(c, in, f, 1)) {
1696 }
1697 pa->sentringing = 0;
1698 break;
1700 ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
1701 if (single && !caller_entertained
1702 && CAN_EARLY_BRIDGE(peerflags, in, c)) {
1704 }
1707 ast_channel_publish_dial(in, c, NULL, "PROCEEDING");
1708 break;
1709 case AST_CONTROL_HOLD:
1710 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1711 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
1713 break;
1714 case AST_CONTROL_UNHOLD:
1715 /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
1716 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
1718 break;
1720 case AST_CONTROL_FLASH:
1721 /* Ignore going off hook and flash */
1722 break;
1723 case AST_CONTROL_CC:
1724 if (!ignore_cc) {
1726 cc_frame_received = 1;
1727 }
1728 break;
1731 break;
1733 if (!f->data.ptr) {
1734 ast_log(LOG_WARNING, "Got playback begin directive without filename on %s\n", ast_channel_name(c));
1735 } else {
1736 const char *filename = f->data.ptr;
1737 ast_verb(3, "Playing audio file %s on %s\n", filename, ast_channel_name(in));
1739 }
1740 break;
1741 case -1:
1742 if (single && !caller_entertained) {
1743 ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
1744 ast_indicate(in, -1);
1745 pa->sentringing = 0;
1746 }
1747 break;
1748 default:
1749 ast_debug(1, "Dunno what to do with control type %d on %s\n", f->subclass.integer, ast_channel_name(in));
1750 break;
1751 }
1752 break;
1753 case AST_FRAME_VIDEO:
1754 case AST_FRAME_VOICE:
1755 case AST_FRAME_IMAGE:
1757 case AST_FRAME_DTMF_END:
1758 if (caller_entertained) {
1759 break;
1760 }
1761 *to_progress = -1;
1762 orig_progress_to = -1;
1763 /* Fall through */
1764 case AST_FRAME_TEXT:
1765 if (single && ast_write(in, f)) {
1766 ast_log(LOG_WARNING, "Unable to write frametype %u on %s\n",
1768 }
1769 break;
1770 case AST_FRAME_HTML:
1772 && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1773 ast_log(LOG_WARNING, "Unable to send URL on %s\n", ast_channel_name(in));
1774 }
1775 break;
1776 default:
1777 break;
1778 }
1779 ast_frfree(f);
1780 } /* end for */
1781 if (winner == in) {
1782 struct ast_frame *f = ast_read(in);
1783 if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
1784 /* Got hung up */
1785 *to_answer = -1;
1786 strcpy(pa->status, "CANCEL");
1787 pa->canceled = 1;
1788 publish_dial_end_event(in, out_chans, NULL, pa->status);
1789 if (f) {
1790 if (f->data.uint32) {
1792 }
1793 ast_frfree(f);
1794 }
1795 if (is_cc_recall) {
1796 ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
1797 }
1798 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller hung up\n", ast_channel_name(in));
1799 }
1800
1801 /* now f is guaranteed non-NULL */
1802 if (f->frametype == AST_FRAME_DTMF) {
1803 if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
1804 const char *context;
1806 if ((context = pbx_builtin_getvar_helper(in, "EXITCONTEXT"))) {
1807 context = ast_strdupa(context);
1808 }
1810 if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
1811 ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
1812 *to_answer = 0;
1813 *result = f->subclass.integer;
1814 strcpy(pa->status, "CANCEL");
1815 pa->canceled = 1;
1816 publish_dial_end_event(in, out_chans, NULL, pa->status);
1817 ast_frfree(f);
1818 if (is_cc_recall) {
1819 ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
1820 }
1821 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller pressed %c to end call\n",
1823 }
1824 }
1825
1826 if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
1827 detect_disconnect(in, f->subclass.integer, &featurecode)) {
1828 ast_verb(3, "User requested call disconnect.\n");
1829 *to_answer = 0;
1830 strcpy(pa->status, "CANCEL");
1831 pa->canceled = 1;
1832 publish_dial_end_event(in, out_chans, NULL, pa->status);
1833 ast_frfree(f);
1834 if (is_cc_recall) {
1835 ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
1836 }
1837 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller requested disconnect\n",
1839 }
1840 }
1841
1842 /* Send the frame from the in channel to all outgoing channels. */
1843 AST_LIST_TRAVERSE(out_chans, o, node) {
1844 if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
1845 /* This outgoing channel has died so don't send the frame to it. */
1846 continue;
1847 }
1848 switch (f->frametype) {
1849 case AST_FRAME_HTML:
1850 /* Forward HTML stuff */
1852 && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
1853 ast_log(LOG_WARNING, "Unable to send URL on %s\n", ast_channel_name(o->chan));
1854 }
1855 break;
1856 case AST_FRAME_VIDEO:
1857 case AST_FRAME_VOICE:
1858 case AST_FRAME_IMAGE:
1859 if (!single || caller_entertained) {
1860 /*
1861 * We are calling multiple parties or caller is being
1862 * entertained and has thus not been made compatible.
1863 * No need to check any other called parties.
1864 */
1865 goto skip_frame;
1866 }
1867 /* Fall through */
1868 case AST_FRAME_TEXT:
1870 case AST_FRAME_DTMF_END:
1871 if (ast_write(o->chan, f)) {
1872 ast_log(LOG_WARNING, "Unable to forward frametype %u on %s\n",
1874 }
1875 break;
1876 case AST_FRAME_CONTROL:
1877 switch (f->subclass.integer) {
1878 case AST_CONTROL_HOLD:
1879 ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
1881 break;
1882 case AST_CONTROL_UNHOLD:
1883 ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
1885 break;
1886 case AST_CONTROL_FLASH:
1887 ast_verb(3, "Hook flash on %s\n", ast_channel_name(o->chan));
1889 break;
1893 if (!single || caller_entertained) {
1894 /*
1895 * We are calling multiple parties or caller is being
1896 * entertained and has thus not been made compatible.
1897 * No need to check any other called parties.
1898 */
1899 goto skip_frame;
1900 }
1901 ast_verb(3, "%s requested media update control %d, passing it to %s\n",
1904 break;
1907 ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
1908 break;
1909 }
1910 if (ast_channel_connected_line_sub(in, o->chan, f, 1)) {
1912 }
1913 break;
1916 ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
1917 break;
1918 }
1919 if (ast_channel_redirecting_sub(in, o->chan, f, 1)) {
1921 }
1922 break;
1923 default:
1924 /* We are not going to do anything with this frame. */
1925 goto skip_frame;
1926 }
1927 break;
1928 default:
1929 /* We are not going to do anything with this frame. */
1930 goto skip_frame;
1931 }
1932 }
1933skip_frame:;
1934 ast_frfree(f);
1935 }
1936 }
1937
1938wait_over:
1939 if (!*to_answer || ast_check_hangup(in)) {
1940 ast_verb(3, "Nobody picked up in %d ms\n", orig_answer_to);
1941 publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
1942 } else if (!*to_progress) {
1943 ast_verb(3, "No early media received in %d ms\n", orig_progress_to);
1944 publish_dial_end_event(in, out_chans, NULL, "CHANUNAVAIL");
1945 strcpy(pa->status, "CHANUNAVAIL");
1946 *to_answer = 0; /* Reset to prevent hangup */
1947 }
1948
1949 if (is_cc_recall) {
1950 ast_cc_completed(in, "Recall completed!");
1951 }
1952 SCOPE_EXIT_RTN_VALUE(peer, "%s: %s%s\n", ast_channel_name(in),
1953 peer ? "Answered by " : "No answer", peer ? ast_channel_name(peer) : "");
1954}

References ao2_bump, chanlist::aoc_s_rate_list, ast_aoc_decode(), ast_aoc_destroy_decoded(), ast_aoc_destroy_encoded(), ast_aoc_encode(), ast_aoc_get_msg_type(), AST_AOC_S, AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NORMAL_CLEARING, ast_cc_completed(), ast_cc_failed(), ast_cc_is_recall(), ast_channel_call_forward(), ast_channel_connected(), ast_channel_connected_line_sub(), ast_channel_creationtime(), ast_channel_early_bridge(), ast_channel_exten_set(), ast_channel_hangupcause(), ast_channel_hangupcause_set(), ast_channel_language(), ast_channel_lock, ast_channel_make_compatible(), ast_channel_name(), ast_channel_publish_dial(), ast_channel_redirecting_sub(), ast_channel_sendhtml(), ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_unlock, ast_channel_update_connected_line(), ast_check_hangup(), ast_clear_flag64, ast_connected_line_parse_data(), AST_CONTROL_ANSWER, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CC, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_PLAYBACK_BEGIN, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, AST_CONTROL_WINK, ast_copy_flags64, ast_deactivate_generator(), ast_debug, ast_dtmf_stream(), AST_FEATURE_MAX_LEN, AST_FRAME_CONTROL, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_free, ast_frfree, ast_handle_cc_control_frame(), ast_hangup(), ast_hangup_cause_to_dial_status(), ast_indicate(), ast_indicate_data(), AST_LIST_FIRST, AST_LIST_NEXT, AST_LIST_TRAVERSE, ast_log, AST_MAX_WATCHERS, ast_mf_stream(), ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_set(), ast_party_connected_line_set_init(), ast_read(), ast_remaining_ms(), ast_sf_stream(), AST_STATE_UP, ast_str_alloca, ast_str_tmp, ast_strdup, ast_strdupa, ast_stream_topology_to_str(), ast_streamfile(), ast_strlen_zero(), ast_test_flag64, ast_trace, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_verb, ast_waitfor_n(), ast_write(), cause_args::busy, c, CAN_EARLY_BRIDGE, privacy_args::canceled, chanlist::chan, config, cause_args::congestion, chanlist::connected, connected, ast_frame::data, ast_frame::datalen, detect_disconnect(), DIAL_CALLERID_ABSENT, DIAL_NOFORWARDHTML, DIAL_STILLGOING, do_forward(), ast_frame::frametype, handle_cause(), in, ast_frame_subclass::integer, LOG_WARNING, cause_args::nochan, NULL, onedigit_goto(), OPT_ARG_RINGBACK, OPT_CALLEE_HANGUP, OPT_CALLEE_MIXMONITOR, OPT_CALLEE_MONITOR, OPT_CALLEE_PARK, OPT_CALLEE_TRANSFER, OPT_CALLER_HANGUP, OPT_CALLER_MIXMONITOR, OPT_CALLER_MONITOR, OPT_CALLER_PARK, OPT_CALLER_TRANSFER, OPT_DTMF_EXIT, OPT_IGNORE_CONNECTEDLINE, OPT_MUSICBACK, OPT_RINGBACK, chanlist::orig_chan_name, pbx_builtin_getvar_helper(), chanlist::pending_connected_update, ast_frame::ptr, publish_dial_end_event(), result, SCOPE_ENTER, SCOPE_EXIT_RTN_VALUE, privacy_args::sentringing, set_duration_var(), privacy_args::status, ast_frame::subclass, ast_frame_subclass::topology, ast_frame::uint32, and update_connected_line_from_peer().

Referenced by dial_exec_full().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Dialing Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, }
static

Definition at line 3612 of file app_dial.c.

◆ app

const char app[] = "Dial"
static

Definition at line 670 of file app_dial.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 3612 of file app_dial.c.

◆ dial_exec_options

const struct ast_app_option dial_exec_options[128] = { [ 'A' ] = { .flag = OPT_ANNOUNCE , .arg_index = OPT_ARG_ANNOUNCE + 1 }, [ 'a' ] = { .flag = OPT_CALLER_ANSWER }, [ 'b' ] = { .flag = OPT_PREDIAL_CALLEE , .arg_index = OPT_ARG_PREDIAL_CALLEE + 1 }, [ 'B' ] = { .flag = OPT_PREDIAL_CALLER , .arg_index = OPT_ARG_PREDIAL_CALLER + 1 }, [ 'C' ] = { .flag = OPT_RESETCDR }, [ 'c' ] = { .flag = OPT_CANCEL_ELSEWHERE }, [ 'd' ] = { .flag = OPT_DTMF_EXIT }, [ 'D' ] = { .flag = OPT_SENDDTMF , .arg_index = OPT_ARG_SENDDTMF + 1 }, [ 'E' ] = { .flag = OPT_HEARPULSING }, [ 'e' ] = { .flag = OPT_PEER_H }, [ 'f' ] = { .flag = OPT_FORCECLID , .arg_index = OPT_ARG_FORCECLID + 1 }, [ 'F' ] = { .flag = OPT_CALLEE_GO_ON , .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 = OPT_TOPOLOGY_PRESERVE }, [ '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 = OPT_HANGUPCAUSE , .arg_index = OPT_ARG_HANGUPCAUSE + 1 }, [ 'r' ] = { .flag = OPT_RINGBACK , .arg_index = OPT_ARG_RINGBACK + 1 }, [ 'R' ] = { .flag = OPT_RING_WITH_EARLY_MEDIA }, [ 'S' ] = { .flag = OPT_DURATION_STOP , .arg_index = OPT_ARG_DURATION_STOP + 1 }, [ 's' ] = { .flag = OPT_FORCE_CID_TAG , .arg_index = OPT_ARG_FORCE_CID_TAG + 1 }, [ 't' ] = { .flag = OPT_CALLEE_TRANSFER }, [ 'T' ] = { .flag = OPT_CALLER_TRANSFER }, [ 'u' ] = { .flag = OPT_FORCE_CID_PRES , .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 = OPT_CANCEL_TIMEOUT }, }
static

Definition at line 792 of file app_dial.c.

Referenced by dial_exec_full().

◆ rapp

const char rapp[] = "RetryDial"
static

Definition at line 671 of file app_dial.c.

Referenced by load_module(), retrydial_exec(), and unload_module().

◆ topology_ds_info

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

Definition at line 832 of file app_dial.c.

832 {
833 .type = "app_dial_topology_preserve",
834 .destroy = topology_ds_destroy,
835};

Referenced by dial_exec_full().