app_dial.c 124 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2012, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. *
  24. * \ingroup applications
  25. */
  26. /*** MODULEINFO
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include <sys/time.h>
  32. #include <sys/signal.h>
  33. #include <sys/stat.h>
  34. #include <netinet/in.h>
  35. #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
  36. #include "asterisk/lock.h"
  37. #include "asterisk/file.h"
  38. #include "asterisk/channel.h"
  39. #include "asterisk/pbx.h"
  40. #include "asterisk/module.h"
  41. #include "asterisk/translate.h"
  42. #include "asterisk/say.h"
  43. #include "asterisk/config.h"
  44. #include "asterisk/features.h"
  45. #include "asterisk/musiconhold.h"
  46. #include "asterisk/callerid.h"
  47. #include "asterisk/utils.h"
  48. #include "asterisk/app.h"
  49. #include "asterisk/causes.h"
  50. #include "asterisk/rtp_engine.h"
  51. #include "asterisk/manager.h"
  52. #include "asterisk/privacy.h"
  53. #include "asterisk/stringfields.h"
  54. #include "asterisk/dsp.h"
  55. #include "asterisk/aoc.h"
  56. #include "asterisk/ccss.h"
  57. #include "asterisk/indications.h"
  58. #include "asterisk/framehook.h"
  59. #include "asterisk/dial.h"
  60. #include "asterisk/stasis_channels.h"
  61. #include "asterisk/bridge_after.h"
  62. #include "asterisk/features_config.h"
  63. #include "asterisk/max_forwards.h"
  64. /*** DOCUMENTATION
  65. <application name="Dial" language="en_US">
  66. <synopsis>
  67. Attempt to connect to another device or endpoint and bridge the call.
  68. </synopsis>
  69. <syntax>
  70. <parameter name="Technology/Resource" required="true" argsep="&amp;">
  71. <argument name="Technology/Resource" required="true">
  72. <para>Specification of the device(s) to dial. These must be in the format of
  73. <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
  74. represents a particular channel driver, and <replaceable>Resource</replaceable>
  75. represents a resource available to that particular channel driver.</para>
  76. </argument>
  77. <argument name="Technology2/Resource2" required="false" multiple="true">
  78. <para>Optional extra devices to dial in parallel</para>
  79. <para>If you need more than one enter them as
  80. Technology2/Resource2&amp;Technology3/Resource3&amp;.....</para>
  81. </argument>
  82. </parameter>
  83. <parameter name="timeout" required="false">
  84. <para>Specifies the number of seconds we attempt to dial the specified devices.</para>
  85. <para>If not specified, this defaults to 136 years.</para>
  86. </parameter>
  87. <parameter name="options" required="false">
  88. <optionlist>
  89. <option name="A">
  90. <argument name="x" required="true">
  91. <para>The file to play to the called party</para>
  92. </argument>
  93. <para>Play an announcement to the called party, where <replaceable>x</replaceable> is the prompt to be played</para>
  94. </option>
  95. <option name="a">
  96. <para>Immediately answer the calling channel when the called channel answers in
  97. all cases. Normally, the calling channel is answered when the called channel
  98. answers, but when options such as <literal>A()</literal> and
  99. <literal>M()</literal> are used, the calling channel is
  100. not answered until all actions on the called channel (such as playing an
  101. announcement) are completed. This option can be used to answer the calling
  102. channel before doing anything on the called channel. You will rarely need to use
  103. this option, the default behavior is adequate in most cases.</para>
  104. </option>
  105. <option name="b" argsep="^">
  106. <para>Before initiating an outgoing call, <literal>Gosub</literal> to the specified
  107. location using the newly created channel. The <literal>Gosub</literal> will be
  108. executed for each destination channel.</para>
  109. <argument name="context" required="false" />
  110. <argument name="exten" required="false" />
  111. <argument name="priority" required="true" hasparams="optional" argsep="^">
  112. <argument name="arg1" multiple="true" required="true" />
  113. <argument name="argN" />
  114. </argument>
  115. </option>
  116. <option name="B" argsep="^">
  117. <para>Before initiating the outgoing call(s), <literal>Gosub</literal> to the
  118. specified location using the current channel.</para>
  119. <argument name="context" required="false" />
  120. <argument name="exten" required="false" />
  121. <argument name="priority" required="true" hasparams="optional" argsep="^">
  122. <argument name="arg1" multiple="true" required="true" />
  123. <argument name="argN" />
  124. </argument>
  125. </option>
  126. <option name="C">
  127. <para>Reset the call detail record (CDR) for this call.</para>
  128. </option>
  129. <option name="c">
  130. <para>If the Dial() application cancels this call, always set
  131. <variable>HANGUPCAUSE</variable> to 'answered elsewhere'</para>
  132. </option>
  133. <option name="d">
  134. <para>Allow the calling user to dial a 1 digit extension while waiting for
  135. a call to be answered. Exit to that extension if it exists in the
  136. current context, or the context defined in the <variable>EXITCONTEXT</variable> variable,
  137. if it exists.</para>
  138. <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
  139. connected. If you wish to use this option with these phones, you
  140. can use the <literal>Answer</literal> application before dialing.</para>
  141. </option>
  142. <option name="D" argsep=":">
  143. <argument name="called" />
  144. <argument name="calling" />
  145. <argument name="progress" />
  146. <para>Send the specified DTMF strings <emphasis>after</emphasis> the called
  147. party has answered, but before the call gets bridged. The
  148. <replaceable>called</replaceable> DTMF string is sent to the called party, and the
  149. <replaceable>calling</replaceable> DTMF string is sent to the calling party. Both arguments
  150. can be used alone. If <replaceable>progress</replaceable> is specified, its DTMF is sent
  151. to the called party immediately after receiving a <literal>PROGRESS</literal> message.</para>
  152. <para>See <literal>SendDTMF</literal> for valid digits.</para>
  153. </option>
  154. <option name="e">
  155. <para>Execute the <literal>h</literal> extension for peer after the call ends</para>
  156. </option>
  157. <option name="f">
  158. <argument name="x" required="false" />
  159. <para>If <replaceable>x</replaceable> is not provided, force the CallerID sent on a call-forward or
  160. deflection to the dialplan extension of this <literal>Dial()</literal> using a dialplan <literal>hint</literal>.
  161. For example, some PSTNs do not allow CallerID to be set to anything
  162. other than the numbers assigned to you.
  163. If <replaceable>x</replaceable> is provided, force the CallerID sent to <replaceable>x</replaceable>.</para>
  164. </option>
  165. <option name="F" argsep="^">
  166. <argument name="context" required="false" />
  167. <argument name="exten" required="false" />
  168. <argument name="priority" required="true" />
  169. <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party
  170. to the specified destination and <emphasis>start</emphasis> execution at that location.</para>
  171. <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
  172. prefixed with one or two underbars ('_').</para>
  173. </option>
  174. <option name="F">
  175. <para>When the caller hangs up, transfer the <emphasis>called</emphasis> party to the next priority of the current extension
  176. and <emphasis>start</emphasis> execution at that location.</para>
  177. <para>NOTE: Any channel variables you want the called channel to inherit from the caller channel must be
  178. prefixed with one or two underbars ('_').</para>
  179. <para>NOTE: Using this option from a Macro() or GoSub() might not make sense as there would be no return points.</para>
  180. </option>
  181. <option name="g">
  182. <para>Proceed with dialplan execution at the next priority in the current extension if the
  183. destination channel hangs up.</para>
  184. </option>
  185. <option name="G" argsep="^">
  186. <argument name="context" required="false" />
  187. <argument name="exten" required="false" />
  188. <argument name="priority" required="true" />
  189. <para>If the call is answered, transfer the calling party to
  190. the specified <replaceable>priority</replaceable> and the called party to the specified
  191. <replaceable>priority</replaceable> plus one.</para>
  192. <para>NOTE: You cannot use any additional action post answer options in conjunction with this option.</para>
  193. </option>
  194. <option name="h">
  195. <para>Allow the called party to hang up by sending the DTMF sequence
  196. defined for disconnect in <filename>features.conf</filename>.</para>
  197. </option>
  198. <option name="H">
  199. <para>Allow the calling party to hang up by sending the DTMF sequence
  200. defined for disconnect in <filename>features.conf</filename>.</para>
  201. <para>NOTE: Many SIP and ISDN phones cannot send DTMF digits until the call is
  202. connected. If you wish to allow DTMF disconnect before the dialed
  203. party answers with these phones, you can use the <literal>Answer</literal>
  204. application before dialing.</para>
  205. </option>
  206. <option name="i">
  207. <para>Asterisk will ignore any forwarding requests it may receive on this dial attempt.</para>
  208. </option>
  209. <option name="I">
  210. <para>Asterisk will ignore any connected line update requests or any redirecting party
  211. update requests it may receive on this dial attempt.</para>
  212. </option>
  213. <option name="k">
  214. <para>Allow the called party to enable parking of the call by sending
  215. the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
  216. </option>
  217. <option name="K">
  218. <para>Allow the calling party to enable parking of the call by sending
  219. the DTMF sequence defined for call parking in <filename>features.conf</filename>.</para>
  220. </option>
  221. <option name="L" argsep=":">
  222. <argument name="x" required="true">
  223. <para>Maximum call time, in milliseconds</para>
  224. </argument>
  225. <argument name="y">
  226. <para>Warning time, in milliseconds</para>
  227. </argument>
  228. <argument name="z">
  229. <para>Repeat time, in milliseconds</para>
  230. </argument>
  231. <para>Limit the call to <replaceable>x</replaceable> milliseconds. Play a warning when <replaceable>y</replaceable> milliseconds are
  232. left. Repeat the warning every <replaceable>z</replaceable> milliseconds until time expires.</para>
  233. <para>This option is affected by the following variables:</para>
  234. <variablelist>
  235. <variable name="LIMIT_PLAYAUDIO_CALLER">
  236. <value name="yes" default="true" />
  237. <value name="no" />
  238. <para>If set, this variable causes Asterisk to play the prompts to the caller.</para>
  239. </variable>
  240. <variable name="LIMIT_PLAYAUDIO_CALLEE">
  241. <value name="yes" />
  242. <value name="no" default="true"/>
  243. <para>If set, this variable causes Asterisk to play the prompts to the callee.</para>
  244. </variable>
  245. <variable name="LIMIT_TIMEOUT_FILE">
  246. <value name="filename"/>
  247. <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the timeout is reached.
  248. If not set, the time remaining will be announced.</para>
  249. </variable>
  250. <variable name="LIMIT_CONNECT_FILE">
  251. <value name="filename"/>
  252. <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play when the call begins.
  253. If not set, the time remaining will be announced.</para>
  254. </variable>
  255. <variable name="LIMIT_WARNING_FILE">
  256. <value name="filename"/>
  257. <para>If specified, <replaceable>filename</replaceable> specifies the sound prompt to play as
  258. a warning when time <replaceable>x</replaceable> is reached. If not set, the time remaining will be announced.</para>
  259. </variable>
  260. </variablelist>
  261. </option>
  262. <option name="m">
  263. <argument name="class" required="false"/>
  264. <para>Provide hold music to the calling party until a requested
  265. channel answers. A specific music on hold <replaceable>class</replaceable>
  266. (as defined in <filename>musiconhold.conf</filename>) can be specified.</para>
  267. </option>
  268. <option name="M" argsep="^">
  269. <argument name="macro" required="true">
  270. <para>Name of the macro that should be executed.</para>
  271. </argument>
  272. <argument name="arg" multiple="true">
  273. <para>Macro arguments</para>
  274. </argument>
  275. <para>Execute the specified <replaceable>macro</replaceable> for the <emphasis>called</emphasis> channel
  276. before connecting to the calling channel. Arguments can be specified to the Macro
  277. using <literal>^</literal> as a delimiter. The macro can set the variable
  278. <variable>MACRO_RESULT</variable> to specify the following actions after the macro is
  279. finished executing:</para>
  280. <variablelist>
  281. <variable name="MACRO_RESULT">
  282. <para>If set, this action will be taken after the macro finished executing.</para>
  283. <value name="ABORT">
  284. Hangup both legs of the call
  285. </value>
  286. <value name="CONGESTION">
  287. Behave as if line congestion was encountered
  288. </value>
  289. <value name="BUSY">
  290. Behave as if a busy signal was encountered
  291. </value>
  292. <value name="CONTINUE">
  293. Hangup the called party and allow the calling party to continue dialplan execution at the next priority
  294. </value>
  295. <value name="GOTO:[[&lt;context&gt;^]&lt;exten&gt;^]&lt;priority&gt;">
  296. Transfer the call to the specified destination.
  297. </value>
  298. </variable>
  299. </variablelist>
  300. <para>NOTE: You cannot use any additional action post answer options in conjunction
  301. with this option. Also, pbx services are run on the peer (called) channel,
  302. so you will not be able to set timeouts via the <literal>TIMEOUT()</literal> function in this macro.</para>
  303. <para>WARNING: Be aware of the limitations that macros have, specifically with regards to use of
  304. the <literal>WaitExten</literal> application. For more information, see the documentation for
  305. <literal>Macro()</literal>.</para>
  306. </option>
  307. <option name="n">
  308. <argument name="delete">
  309. <para>With <replaceable>delete</replaceable> either not specified or set to <literal>0</literal>,
  310. the recorded introduction will not be deleted if the caller hangs up while the remote party has not
  311. yet answered.</para>
  312. <para>With <replaceable>delete</replaceable> set to <literal>1</literal>, the introduction will
  313. always be deleted.</para>
  314. </argument>
  315. <para>This option is a modifier for the call screening/privacy mode. (See the
  316. <literal>p</literal> and <literal>P</literal> options.) It specifies
  317. that no introductions are to be saved in the <directory>priv-callerintros</directory>
  318. directory.</para>
  319. </option>
  320. <option name="N">
  321. <para>This option is a modifier for the call screening/privacy mode. It specifies
  322. that if CallerID is present, do not screen the call.</para>
  323. </option>
  324. <option name="o">
  325. <argument name="x" required="false" />
  326. <para>If <replaceable>x</replaceable> is not provided, specify that the CallerID that was present on the
  327. <emphasis>calling</emphasis> channel be stored as the CallerID on the <emphasis>called</emphasis> channel.
  328. This was the behavior of Asterisk 1.0 and earlier.
  329. If <replaceable>x</replaceable> is provided, specify the CallerID stored on the <emphasis>called</emphasis> channel.
  330. Note that <literal>o(${CALLERID(all)})</literal> is similar to option <literal>o</literal> without the parameter.</para>
  331. </option>
  332. <option name="O">
  333. <argument name="mode">
  334. <para>With <replaceable>mode</replaceable> either not specified or set to <literal>1</literal>,
  335. the originator hanging up will cause the phone to ring back immediately.</para>
  336. <para>With <replaceable>mode</replaceable> set to <literal>2</literal>, when the operator
  337. flashes the trunk, it will ring their phone back.</para>
  338. </argument>
  339. <para>Enables <emphasis>operator services</emphasis> mode. This option only
  340. works when bridging a DAHDI channel to another DAHDI channel
  341. only. if specified on non-DAHDI interfaces, it will be ignored.
  342. When the destination answers (presumably an operator services
  343. station), the originator no longer has control of their line.
  344. They may hang up, but the switch will not release their line
  345. until the destination party (the operator) hangs up.</para>
  346. </option>
  347. <option name="p">
  348. <para>This option enables screening mode. This is basically Privacy mode
  349. without memory.</para>
  350. </option>
  351. <option name="P">
  352. <argument name="x" />
  353. <para>Enable privacy mode. Use <replaceable>x</replaceable> as the family/key in the AstDB database if
  354. it is provided. The current extension is used if a database family/key is not specified.</para>
  355. </option>
  356. <option name="Q">
  357. <argument name="cause" required="true"/>
  358. <para>Specify the Q.850/Q.931 <replaceable>cause</replaceable> to send on
  359. unanswered channels when another channel answers the call.
  360. As with <literal>Hangup()</literal>, <replaceable>cause</replaceable>
  361. can be a numeric cause code or a name such as
  362. <literal>NO_ANSWER</literal>,
  363. <literal>USER_BUSY</literal>,
  364. <literal>CALL_REJECTED</literal> or
  365. <literal>ANSWERED_ELSEWHERE</literal> (the default if Q isn't specified).
  366. You can also specify <literal>0</literal> or <literal>NONE</literal>
  367. to send no cause. See the <filename>causes.h</filename> file for the
  368. full list of valid causes and names.
  369. </para>
  370. <para>NOTE: chan_sip does not support setting the cause on a CANCEL to anything
  371. other than ANSWERED_ELSEWHERE.</para>
  372. </option>
  373. <option name="r">
  374. <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing. Pass no audio to the calling
  375. party until the called channel has answered.</para>
  376. <argument name="tone" required="false">
  377. <para>Indicate progress to calling party. Send audio 'tone' from the <filename>indications.conf</filename> tonezone currently in use.</para>
  378. </argument>
  379. </option>
  380. <option name="R">
  381. <para>Default: Indicate ringing to the calling party, even if the called party isn't actually ringing.
  382. Allow interruption of the ringback if early media is received on the channel.</para>
  383. </option>
  384. <option name="S">
  385. <argument name="x" required="true" />
  386. <para>Hang up the call <replaceable>x</replaceable> seconds <emphasis>after</emphasis> the called party has
  387. answered the call.</para>
  388. </option>
  389. <option name="s">
  390. <argument name="x" required="true" />
  391. <para>Force the outgoing CallerID tag parameter to be set to the string <replaceable>x</replaceable>.</para>
  392. <para>Works with the <literal>f</literal> option.</para>
  393. </option>
  394. <option name="t">
  395. <para>Allow the called party to transfer the calling party by sending the
  396. DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
  397. transfers initiated by other methods.</para>
  398. </option>
  399. <option name="T">
  400. <para>Allow the calling party to transfer the called party by sending the
  401. DTMF sequence defined in <filename>features.conf</filename>. This setting does not perform policy enforcement on
  402. transfers initiated by other methods.</para>
  403. </option>
  404. <option name="U" argsep="^">
  405. <argument name="x" required="true">
  406. <para>Name of the subroutine context to execute via <literal>Gosub</literal>.
  407. The subroutine execution starts in the named context at the s exten and priority 1.</para>
  408. </argument>
  409. <argument name="arg" multiple="true" required="false">
  410. <para>Arguments for the <literal>Gosub</literal> routine</para>
  411. </argument>
  412. <para>Execute via <literal>Gosub</literal> the routine <replaceable>x</replaceable> for the <emphasis>called</emphasis> channel before connecting
  413. to the calling channel. Arguments can be specified to the <literal>Gosub</literal>
  414. using <literal>^</literal> as a delimiter. The <literal>Gosub</literal> routine can set the variable
  415. <variable>GOSUB_RESULT</variable> to specify the following actions after the <literal>Gosub</literal> returns.</para>
  416. <variablelist>
  417. <variable name="GOSUB_RESULT">
  418. <value name="ABORT">
  419. Hangup both legs of the call.
  420. </value>
  421. <value name="CONGESTION">
  422. Behave as if line congestion was encountered.
  423. </value>
  424. <value name="BUSY">
  425. Behave as if a busy signal was encountered.
  426. </value>
  427. <value name="CONTINUE">
  428. Hangup the called party and allow the calling party
  429. to continue dialplan execution at the next priority.
  430. </value>
  431. <value name="GOTO:[[&lt;context&gt;^]&lt;exten&gt;^]&lt;priority&gt;">
  432. Transfer the call to the specified destination.
  433. </value>
  434. </variable>
  435. </variablelist>
  436. <para>NOTE: You cannot use any additional action post answer options in conjunction
  437. with this option. Also, pbx services are run on the <emphasis>called</emphasis> channel,
  438. so you will not be able to set timeouts via the <literal>TIMEOUT()</literal> function in this routine.</para>
  439. </option>
  440. <option name="u">
  441. <argument name = "x" required="true">
  442. <para>Force the outgoing callerid presentation indicator parameter to be set
  443. to one of the values passed in <replaceable>x</replaceable>:
  444. <literal>allowed_not_screened</literal>
  445. <literal>allowed_passed_screen</literal>
  446. <literal>allowed_failed_screen</literal>
  447. <literal>allowed</literal>
  448. <literal>prohib_not_screened</literal>
  449. <literal>prohib_passed_screen</literal>
  450. <literal>prohib_failed_screen</literal>
  451. <literal>prohib</literal>
  452. <literal>unavailable</literal></para>
  453. </argument>
  454. <para>Works with the <literal>f</literal> option.</para>
  455. </option>
  456. <option name="w">
  457. <para>Allow the called party to enable recording of the call by sending
  458. the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
  459. </option>
  460. <option name="W">
  461. <para>Allow the calling party to enable recording of the call by sending
  462. the DTMF sequence defined for one-touch recording in <filename>features.conf</filename>.</para>
  463. </option>
  464. <option name="x">
  465. <para>Allow the called party to enable recording of the call by sending
  466. the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
  467. </option>
  468. <option name="X">
  469. <para>Allow the calling party to enable recording of the call by sending
  470. the DTMF sequence defined for one-touch automixmonitor in <filename>features.conf</filename>.</para>
  471. </option>
  472. <option name="z">
  473. <para>On a call forward, cancel any dial timeout which has been set for this call.</para>
  474. </option>
  475. </optionlist>
  476. </parameter>
  477. <parameter name="URL">
  478. <para>The optional URL will be sent to the called party if the channel driver supports it.</para>
  479. </parameter>
  480. </syntax>
  481. <description>
  482. <para>This application will place calls to one or more specified channels. As soon
  483. as one of the requested channels answers, the originating channel will be
  484. answered, if it has not already been answered. These two channels will then
  485. be active in a bridged call. All other channels that were requested will then
  486. be hung up.</para>
  487. <para>Unless there is a timeout specified, the Dial application will wait
  488. indefinitely until one of the called channels answers, the user hangs up, or
  489. if all of the called channels are busy or unavailable. Dialplan execution will
  490. continue if no requested channels can be called, or if the timeout expires.
  491. This application will report normal termination if the originating channel
  492. hangs up, or if the call is bridged and either of the parties in the bridge
  493. ends the call.</para>
  494. <para>If the <variable>OUTBOUND_GROUP</variable> variable is set, all peer channels created by this
  495. application will be put into that group (as in <literal>Set(GROUP()=...</literal>).
  496. If the <variable>OUTBOUND_GROUP_ONCE</variable> variable is set, all peer channels created by this
  497. application will be put into that group (as in <literal>Set(GROUP()=...</literal>). Unlike <variable>OUTBOUND_GROUP</variable>,
  498. however, the variable will be unset after use.</para>
  499. <example title="Dial with 30 second timeout">
  500. same => n,Dial(PJSIP/alice,30)
  501. </example>
  502. <example title="Parallel dial with 45 second timeout">
  503. same => n,Dial(PJSIP/alice&amp;PJIP/bob,45)
  504. </example>
  505. <example title="Dial with 'g' continuation option">
  506. same => n,Dial(PJSIP/alice,,g)
  507. same => n,Log(NOTICE, Alice call result: ${DIALSTATUS})
  508. </example>
  509. <example title="Dial with transfer/recording features for calling party">
  510. same => n,Dial(PJSIP/alice,,TX)
  511. </example>
  512. <example title="Dial with call length limit">
  513. same => n,Dial(PJSIP/alice,,L(60000:30000:10000))
  514. </example>
  515. <example title="Dial alice and bob and send NO_ANSWER to bob instead of ANSWERED_ELSEWHERE when alice answers">
  516. same => n,Dial(PJSIP/alice&amp;PJSIP/bob,,Q(NO_ANSWER))
  517. </example>
  518. <example title="Dial with pre-dial subroutines">
  519. [default]
  520. exten => callee_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
  521. same => n,Log(NOTICE, I'm called on channel ${CHANNEL} prior to it starting the dial attempt)
  522. same => n,Return()
  523. exten => called_channel,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
  524. same => n,Log(NOTICE, I'm called on outbound channel ${CHANNEL} prior to it being used to dial someone)
  525. same => n,Return()
  526. exten => _X.,1,NoOp()
  527. same => n,Dial(PJSIP/alice,,b(default^called_channel^1(my_gosub_arg1^my_gosub_arg2))B(default^callee_channel^1(my_gosub_arg1^my_gosub_arg2)))
  528. same => n,Hangup()
  529. </example>
  530. <example title="Dial with post-answer subroutine executed on outbound channel">
  531. [my_gosub_routine]
  532. exten => s,1,NoOp(ARG1=${ARG1} ARG2=${ARG2})
  533. same => n,Playback(hello)
  534. same => n,Return()
  535. [default]
  536. exten => _X.,1,NoOp()
  537. same => n,Dial(PJSIP/alice,,U(my_gosub_routine^my_gosub_arg1^my_gosub_arg2))
  538. same => n,Hangup()
  539. </example>
  540. <example title="Dial into ConfBridge using 'G' option">
  541. same => n,Dial(PJSIP/alice,,G(jump_to_here))
  542. same => n(jump_to_here),Goto(confbridge)
  543. same => n,Goto(confbridge)
  544. same => n(confbridge),ConfBridge(${EXTEN})
  545. </example>
  546. <para>This application sets the following channel variables:</para>
  547. <variablelist>
  548. <variable name="DIALEDTIME">
  549. <para>This is the time from dialing a channel until when it is disconnected.</para>
  550. </variable>
  551. <variable name="ANSWEREDTIME">
  552. <para>This is the amount of time for actual call.</para>
  553. </variable>
  554. <variable name="DIALEDPEERNAME">
  555. <para>The name of the outbound channel that answered the call.</para>
  556. </variable>
  557. <variable name="DIALEDPEERNUMBER">
  558. <para>The number that was dialed for the answered outbound channel.</para>
  559. </variable>
  560. <variable name="FORWARDERNAME">
  561. <para>If a call forward occurred, the name of the forwarded channel.</para>
  562. </variable>
  563. <variable name="DIALSTATUS">
  564. <para>This is the status of the call</para>
  565. <value name="CHANUNAVAIL" />
  566. <value name="CONGESTION" />
  567. <value name="NOANSWER" />
  568. <value name="BUSY" />
  569. <value name="ANSWER" />
  570. <value name="CANCEL" />
  571. <value name="DONTCALL">
  572. For the Privacy and Screening Modes.
  573. Will be set if the called party chooses to send the calling party to the 'Go Away' script.
  574. </value>
  575. <value name="TORTURE">
  576. For the Privacy and Screening Modes.
  577. Will be set if the called party chooses to send the calling party to the 'torture' script.
  578. </value>
  579. <value name="INVALIDARGS" />
  580. </variable>
  581. </variablelist>
  582. </description>
  583. <see-also>
  584. <ref type="application">RetryDial</ref>
  585. <ref type="application">SendDTMF</ref>
  586. <ref type="application">Gosub</ref>
  587. <ref type="application">Macro</ref>
  588. </see-also>
  589. </application>
  590. <application name="RetryDial" language="en_US">
  591. <synopsis>
  592. Place a call, retrying on failure allowing an optional exit extension.
  593. </synopsis>
  594. <syntax>
  595. <parameter name="announce" required="true">
  596. <para>Filename of sound that will be played when no channel can be reached</para>
  597. </parameter>
  598. <parameter name="sleep" required="true">
  599. <para>Number of seconds to wait after a dial attempt failed before a new attempt is made</para>
  600. </parameter>
  601. <parameter name="retries" required="true">
  602. <para>Number of retries</para>
  603. <para>When this is reached flow will continue at the next priority in the dialplan</para>
  604. </parameter>
  605. <parameter name="dialargs" required="true">
  606. <para>Same format as arguments provided to the Dial application</para>
  607. </parameter>
  608. </syntax>
  609. <description>
  610. <para>This application will attempt to place a call using the normal Dial application.
  611. If no channel can be reached, the <replaceable>announce</replaceable> file will be played.
  612. Then, it will wait <replaceable>sleep</replaceable> number of seconds before retrying the call.
  613. After <replaceable>retries</replaceable> number of attempts, the calling channel will continue at the next priority in the dialplan.
  614. If the <replaceable>retries</replaceable> setting is set to 0, this application will retry endlessly.
  615. While waiting to retry a call, a 1 digit extension may be dialed. If that
  616. extension exists in either the context defined in <variable>EXITCONTEXT</variable> or the current
  617. one, The call will jump to that extension immediately.
  618. The <replaceable>dialargs</replaceable> are specified in the same format that arguments are provided
  619. to the Dial application.</para>
  620. </description>
  621. <see-also>
  622. <ref type="application">Dial</ref>
  623. </see-also>
  624. </application>
  625. ***/
  626. static const char app[] = "Dial";
  627. static const char rapp[] = "RetryDial";
  628. enum {
  629. OPT_ANNOUNCE = (1 << 0),
  630. OPT_RESETCDR = (1 << 1),
  631. OPT_DTMF_EXIT = (1 << 2),
  632. OPT_SENDDTMF = (1 << 3),
  633. OPT_FORCECLID = (1 << 4),
  634. OPT_GO_ON = (1 << 5),
  635. OPT_CALLEE_HANGUP = (1 << 6),
  636. OPT_CALLER_HANGUP = (1 << 7),
  637. OPT_ORIGINAL_CLID = (1 << 8),
  638. OPT_DURATION_LIMIT = (1 << 9),
  639. OPT_MUSICBACK = (1 << 10),
  640. OPT_CALLEE_MACRO = (1 << 11),
  641. OPT_SCREEN_NOINTRO = (1 << 12),
  642. OPT_SCREEN_NOCALLERID = (1 << 13),
  643. OPT_IGNORE_CONNECTEDLINE = (1 << 14),
  644. OPT_SCREENING = (1 << 15),
  645. OPT_PRIVACY = (1 << 16),
  646. OPT_RINGBACK = (1 << 17),
  647. OPT_DURATION_STOP = (1 << 18),
  648. OPT_CALLEE_TRANSFER = (1 << 19),
  649. OPT_CALLER_TRANSFER = (1 << 20),
  650. OPT_CALLEE_MONITOR = (1 << 21),
  651. OPT_CALLER_MONITOR = (1 << 22),
  652. OPT_GOTO = (1 << 23),
  653. OPT_OPERMODE = (1 << 24),
  654. OPT_CALLEE_PARK = (1 << 25),
  655. OPT_CALLER_PARK = (1 << 26),
  656. OPT_IGNORE_FORWARDING = (1 << 27),
  657. OPT_CALLEE_GOSUB = (1 << 28),
  658. OPT_CALLEE_MIXMONITOR = (1 << 29),
  659. OPT_CALLER_MIXMONITOR = (1 << 30),
  660. };
  661. /* flags are now 64 bits, so keep it up! */
  662. #define DIAL_STILLGOING (1LLU << 31)
  663. #define DIAL_NOFORWARDHTML (1LLU << 32)
  664. #define DIAL_CALLERID_ABSENT (1LLU << 33) /* TRUE if caller id is not available for connected line. */
  665. #define OPT_CANCEL_ELSEWHERE (1LLU << 34)
  666. #define OPT_PEER_H (1LLU << 35)
  667. #define OPT_CALLEE_GO_ON (1LLU << 36)
  668. #define OPT_CANCEL_TIMEOUT (1LLU << 37)
  669. #define OPT_FORCE_CID_TAG (1LLU << 38)
  670. #define OPT_FORCE_CID_PRES (1LLU << 39)
  671. #define OPT_CALLER_ANSWER (1LLU << 40)
  672. #define OPT_PREDIAL_CALLEE (1LLU << 41)
  673. #define OPT_PREDIAL_CALLER (1LLU << 42)
  674. #define OPT_RING_WITH_EARLY_MEDIA (1LLU << 43)
  675. #define OPT_HANGUPCAUSE (1LLU << 44)
  676. enum {
  677. OPT_ARG_ANNOUNCE = 0,
  678. OPT_ARG_SENDDTMF,
  679. OPT_ARG_GOTO,
  680. OPT_ARG_DURATION_LIMIT,
  681. OPT_ARG_MUSICBACK,
  682. OPT_ARG_CALLEE_MACRO,
  683. OPT_ARG_RINGBACK,
  684. OPT_ARG_CALLEE_GOSUB,
  685. OPT_ARG_CALLEE_GO_ON,
  686. OPT_ARG_PRIVACY,
  687. OPT_ARG_DURATION_STOP,
  688. OPT_ARG_OPERMODE,
  689. OPT_ARG_SCREEN_NOINTRO,
  690. OPT_ARG_ORIGINAL_CLID,
  691. OPT_ARG_FORCECLID,
  692. OPT_ARG_FORCE_CID_TAG,
  693. OPT_ARG_FORCE_CID_PRES,
  694. OPT_ARG_PREDIAL_CALLEE,
  695. OPT_ARG_PREDIAL_CALLER,
  696. OPT_ARG_HANGUPCAUSE,
  697. /* note: this entry _MUST_ be the last one in the enum */
  698. OPT_ARG_ARRAY_SIZE
  699. };
  700. AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS
  701. AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE),
  702. AST_APP_OPTION('a', OPT_CALLER_ANSWER),
  703. AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE),
  704. AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER),
  705. AST_APP_OPTION('C', OPT_RESETCDR),
  706. AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE),
  707. AST_APP_OPTION('d', OPT_DTMF_EXIT),
  708. AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF),
  709. AST_APP_OPTION('e', OPT_PEER_H),
  710. AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID),
  711. AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON),
  712. AST_APP_OPTION('g', OPT_GO_ON),
  713. AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO),
  714. AST_APP_OPTION('h', OPT_CALLEE_HANGUP),
  715. AST_APP_OPTION('H', OPT_CALLER_HANGUP),
  716. AST_APP_OPTION('i', OPT_IGNORE_FORWARDING),
  717. AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE),
  718. AST_APP_OPTION('k', OPT_CALLEE_PARK),
  719. AST_APP_OPTION('K', OPT_CALLER_PARK),
  720. AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
  721. AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK),
  722. AST_APP_OPTION_ARG('M', OPT_CALLEE_MACRO, OPT_ARG_CALLEE_MACRO),
  723. AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO),
  724. AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID),
  725. AST_APP_OPTION_ARG('o', OPT_ORIGINAL_CLID, OPT_ARG_ORIGINAL_CLID),
  726. AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE),
  727. AST_APP_OPTION('p', OPT_SCREENING),
  728. AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY),
  729. AST_APP_OPTION_ARG('Q', OPT_HANGUPCAUSE, OPT_ARG_HANGUPCAUSE),
  730. AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK),
  731. AST_APP_OPTION('R', OPT_RING_WITH_EARLY_MEDIA),
  732. AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP),
  733. AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG),
  734. AST_APP_OPTION('t', OPT_CALLEE_TRANSFER),
  735. AST_APP_OPTION('T', OPT_CALLER_TRANSFER),
  736. AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES),
  737. AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB),
  738. AST_APP_OPTION('w', OPT_CALLEE_MONITOR),
  739. AST_APP_OPTION('W', OPT_CALLER_MONITOR),
  740. AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR),
  741. AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR),
  742. AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT),
  743. END_OPTIONS );
  744. #define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \
  745. OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \
  746. OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \
  747. OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB) && \
  748. !ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \
  749. ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer)))
  750. /*
  751. * The list of active channels
  752. */
  753. struct chanlist {
  754. AST_LIST_ENTRY(chanlist) node;
  755. struct ast_channel *chan;
  756. /*! Channel interface dialing string (is tech/number). (Stored in stuff[]) */
  757. const char *interface;
  758. /*! Channel technology name. (Stored in stuff[]) */
  759. const char *tech;
  760. /*! Channel device addressing. (Stored in stuff[]) */
  761. const char *number;
  762. /*! Original channel name. Must be freed. Could be NULL if allocation failed. */
  763. char *orig_chan_name;
  764. uint64_t flags;
  765. /*! Saved connected party info from an AST_CONTROL_CONNECTED_LINE. */
  766. struct ast_party_connected_line connected;
  767. /*! TRUE if an AST_CONTROL_CONNECTED_LINE update was saved to the connected element. */
  768. unsigned int pending_connected_update:1;
  769. struct ast_aoc_decoded *aoc_s_rate_list;
  770. /*! The interface, tech, and number strings are stuffed here. */
  771. char stuff[0];
  772. };
  773. AST_LIST_HEAD_NOLOCK(dial_head, chanlist);
  774. static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode);
  775. static void chanlist_free(struct chanlist *outgoing)
  776. {
  777. ast_party_connected_line_free(&outgoing->connected);
  778. ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list);
  779. ast_free(outgoing->orig_chan_name);
  780. ast_free(outgoing);
  781. }
  782. static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause)
  783. {
  784. /* Hang up a tree of stuff */
  785. struct chanlist *outgoing;
  786. while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) {
  787. /* Hangup any existing lines we have open */
  788. if (outgoing->chan && (outgoing->chan != exception)) {
  789. if (hangupcause >= 0) {
  790. /* This is for the channel drivers */
  791. ast_channel_hangupcause_set(outgoing->chan, hangupcause);
  792. }
  793. ast_hangup(outgoing->chan);
  794. }
  795. chanlist_free(outgoing);
  796. }
  797. }
  798. #define AST_MAX_WATCHERS 256
  799. /*
  800. * argument to handle_cause() and other functions.
  801. */
  802. struct cause_args {
  803. struct ast_channel *chan;
  804. int busy;
  805. int congestion;
  806. int nochan;
  807. };
  808. static void handle_cause(int cause, struct cause_args *num)
  809. {
  810. switch(cause) {
  811. case AST_CAUSE_BUSY:
  812. num->busy++;
  813. break;
  814. case AST_CAUSE_CONGESTION:
  815. num->congestion++;
  816. break;
  817. case AST_CAUSE_NO_ROUTE_DESTINATION:
  818. case AST_CAUSE_UNREGISTERED:
  819. num->nochan++;
  820. break;
  821. case AST_CAUSE_NO_ANSWER:
  822. case AST_CAUSE_NORMAL_CLEARING:
  823. break;
  824. default:
  825. num->nochan++;
  826. break;
  827. }
  828. }
  829. static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
  830. {
  831. char rexten[2] = { exten, '\0' };
  832. if (context) {
  833. if (!ast_goto_if_exists(chan, context, rexten, pri))
  834. return 1;
  835. } else {
  836. if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri))
  837. return 1;
  838. else if (!ast_strlen_zero(ast_channel_macrocontext(chan))) {
  839. if (!ast_goto_if_exists(chan, ast_channel_macrocontext(chan), rexten, pri))
  840. return 1;
  841. }
  842. }
  843. return 0;
  844. }
  845. /* do not call with chan lock held */
  846. static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan)
  847. {
  848. const char *context;
  849. const char *exten;
  850. ast_channel_lock(chan);
  851. context = ast_strdupa(S_OR(ast_channel_macrocontext(chan), ast_channel_context(chan)));
  852. exten = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
  853. ast_channel_unlock(chan);
  854. return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : "";
  855. }
  856. /*!
  857. * helper function for wait_for_answer()
  858. *
  859. * \param o Outgoing call channel list.
  860. * \param num Incoming call channel cause accumulation
  861. * \param peerflags Dial option flags
  862. * \param single TRUE if there is only one outgoing call.
  863. * \param caller_entertained TRUE if the caller is being entertained by MOH or ringback.
  864. * \param to Remaining call timeout time.
  865. * \param forced_clid OPT_FORCECLID caller id to send
  866. * \param stored_clid Caller id representing the called party if needed
  867. *
  868. * XXX this code is highly suspicious, as it essentially overwrites
  869. * the outgoing channel without properly deleting it.
  870. *
  871. * \todo eventually this function should be intergrated into and replaced by ast_call_forward()
  872. */
  873. static void do_forward(struct chanlist *o, struct cause_args *num,
  874. struct ast_flags64 *peerflags, int single, int caller_entertained, int *to,
  875. struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
  876. {
  877. char tmpchan[256];
  878. char forwarder[AST_CHANNEL_NAME];
  879. struct ast_channel *original = o->chan;
  880. struct ast_channel *c = o->chan; /* the winner */
  881. struct ast_channel *in = num->chan; /* the input channel */
  882. char *stuff;
  883. char *tech;
  884. int cause;
  885. struct ast_party_caller caller;
  886. ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder));
  887. ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan));
  888. if ((stuff = strchr(tmpchan, '/'))) {
  889. *stuff++ = '\0';
  890. tech = tmpchan;
  891. } else {
  892. const char *forward_context;
  893. ast_channel_lock(c);
  894. forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT");
  895. if (ast_strlen_zero(forward_context)) {
  896. forward_context = NULL;
  897. }
  898. snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c));
  899. ast_channel_unlock(c);
  900. stuff = tmpchan;
  901. tech = "Local";
  902. }
  903. if (!strcasecmp(tech, "Local")) {
  904. /*
  905. * Drop the connected line update block for local channels since
  906. * this is going to run dialplan and the user can change his
  907. * mind about what connected line information he wants to send.
  908. */
  909. ast_clear_flag64(o, OPT_IGNORE_CONNECTEDLINE);
  910. }
  911. /* Before processing channel, go ahead and check for forwarding */
  912. ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c));
  913. /* If we have been told to ignore forwards, just set this channel to null and continue processing extensions normally */
  914. if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) {
  915. ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff);
  916. c = o->chan = NULL;
  917. cause = AST_CAUSE_BUSY;
  918. } else {
  919. struct ast_format_cap *nativeformats;
  920. ast_channel_lock(in);
  921. nativeformats = ao2_bump(ast_channel_nativeformats(in));
  922. ast_channel_unlock(in);
  923. /* Setup parameters */
  924. c = o->chan = ast_request(tech, nativeformats, NULL, in, stuff, &cause);
  925. ao2_cleanup(nativeformats);
  926. if (c) {
  927. if (single && !caller_entertained) {
  928. ast_channel_make_compatible(in, o->chan);
  929. }
  930. ast_channel_lock_both(in, o->chan);
  931. ast_channel_inherit_variables(in, o->chan);
  932. ast_channel_datastore_inherit(in, o->chan);
  933. pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder);
  934. ast_max_forwards_decrement(o->chan);
  935. ast_channel_unlock(in);
  936. ast_channel_unlock(o->chan);
  937. /* When a call is forwarded, we don't want to track new interfaces
  938. * dialed for CC purposes. Setting the done flag will ensure that
  939. * any Dial operations that happen later won't record CC interfaces.
  940. */
  941. ast_ignore_cc(o->chan);
  942. ast_log(LOG_NOTICE, "Not accepting call completion offers from call-forward recipient %s\n", ast_channel_name(o->chan));
  943. } else
  944. ast_log(LOG_NOTICE,
  945. "Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n",
  946. tech, stuff, cause);
  947. }
  948. if (!c) {
  949. ast_channel_publish_dial(in, original, stuff, "BUSY");
  950. ast_clear_flag64(o, DIAL_STILLGOING);
  951. handle_cause(cause, num);
  952. ast_hangup(original);
  953. } else {
  954. ast_channel_lock_both(c, original);
  955. ast_party_redirecting_copy(ast_channel_redirecting(c),
  956. ast_channel_redirecting(original));
  957. ast_channel_unlock(c);
  958. ast_channel_unlock(original);
  959. ast_channel_lock_both(c, in);
  960. if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) {
  961. ast_rtp_instance_early_bridge_make_compatible(c, in);
  962. }
  963. if (!ast_channel_redirecting(c)->from.number.valid
  964. || ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) {
  965. /*
  966. * The call was not previously redirected so it is
  967. * now redirected from this number.
  968. */
  969. ast_party_number_free(&ast_channel_redirecting(c)->from.number);
  970. ast_party_number_init(&ast_channel_redirecting(c)->from.number);
  971. ast_channel_redirecting(c)->from.number.valid = 1;
  972. ast_channel_redirecting(c)->from.number.str =
  973. ast_strdup(S_OR(ast_channel_macroexten(in), ast_channel_exten(in)));
  974. }
  975. ast_channel_dialed(c)->transit_network_select = ast_channel_dialed(in)->transit_network_select;
  976. /* Determine CallerID to store in outgoing channel. */
  977. ast_party_caller_set_init(&caller, ast_channel_caller(c));
  978. if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
  979. caller.id = *stored_clid;
  980. ast_channel_set_caller_event(c, &caller, NULL);
  981. ast_set_flag64(o, DIAL_CALLERID_ABSENT);
  982. } else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid,
  983. ast_channel_caller(c)->id.number.str, NULL))) {
  984. /*
  985. * The new channel has no preset CallerID number by the channel
  986. * driver. Use the dialplan extension and hint name.
  987. */
  988. caller.id = *stored_clid;
  989. ast_channel_set_caller_event(c, &caller, NULL);
  990. ast_set_flag64(o, DIAL_CALLERID_ABSENT);
  991. } else {
  992. ast_clear_flag64(o, DIAL_CALLERID_ABSENT);
  993. }
  994. /* Determine CallerID for outgoing channel to send. */
  995. if (ast_test_flag64(o, OPT_FORCECLID)) {
  996. struct ast_party_connected_line connected;
  997. ast_party_connected_line_init(&connected);
  998. connected.id = *forced_clid;
  999. ast_party_connected_line_copy(ast_channel_connected(c), &connected);
  1000. } else {
  1001. ast_connected_line_copy_from_caller(ast_channel_connected(c), ast_channel_caller(in));
  1002. }
  1003. ast_channel_req_accountcodes(c, in, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
  1004. ast_channel_appl_set(c, "AppDial");
  1005. ast_channel_data_set(c, "(Outgoing Line)");
  1006. ast_channel_publish_snapshot(c);
  1007. ast_channel_unlock(in);
  1008. if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1009. struct ast_party_redirecting redirecting;
  1010. /*
  1011. * Redirecting updates to the caller make sense only on single
  1012. * calls.
  1013. *
  1014. * We must unlock c before calling
  1015. * ast_channel_redirecting_macro, because we put c into
  1016. * autoservice there. That is pretty much a guaranteed
  1017. * deadlock. This is why the handling of c's lock may seem a
  1018. * bit unusual here.
  1019. */
  1020. ast_party_redirecting_init(&redirecting);
  1021. ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(c));
  1022. ast_channel_unlock(c);
  1023. if (ast_channel_redirecting_sub(c, in, &redirecting, 0) &&
  1024. ast_channel_redirecting_macro(c, in, &redirecting, 1, 0)) {
  1025. ast_channel_update_redirecting(in, &redirecting, NULL);
  1026. }
  1027. ast_party_redirecting_free(&redirecting);
  1028. } else {
  1029. ast_channel_unlock(c);
  1030. }
  1031. if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) {
  1032. *to = -1;
  1033. }
  1034. if (ast_call(c, stuff, 0)) {
  1035. ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n",
  1036. tech, stuff);
  1037. ast_channel_publish_dial(in, original, stuff, "CONGESTION");
  1038. ast_clear_flag64(o, DIAL_STILLGOING);
  1039. ast_hangup(original);
  1040. ast_hangup(c);
  1041. c = o->chan = NULL;
  1042. num->nochan++;
  1043. } else {
  1044. ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL",
  1045. ast_channel_call_forward(original));
  1046. ast_channel_publish_dial(in, c, stuff, NULL);
  1047. /* Hangup the original channel now, in case we needed it */
  1048. ast_hangup(original);
  1049. }
  1050. if (single && !caller_entertained) {
  1051. ast_indicate(in, -1);
  1052. }
  1053. }
  1054. }
  1055. /* argument used for some functions. */
  1056. struct privacy_args {
  1057. int sentringing;
  1058. int privdb_val;
  1059. char privcid[256];
  1060. char privintro[1024];
  1061. char status[256];
  1062. };
  1063. static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status)
  1064. {
  1065. struct chanlist *outgoing;
  1066. AST_LIST_TRAVERSE(out_chans, outgoing, node) {
  1067. if (!outgoing->chan || outgoing->chan == exception) {
  1068. continue;
  1069. }
  1070. ast_channel_publish_dial(in, outgoing->chan, NULL, status);
  1071. }
  1072. }
  1073. /*!
  1074. * \internal
  1075. * \brief Update connected line on chan from peer.
  1076. * \since 13.6.0
  1077. *
  1078. * \param chan Channel to get connected line updated.
  1079. * \param peer Channel providing connected line information.
  1080. * \param is_caller Non-zero if chan is the calling channel.
  1081. *
  1082. * \return Nothing
  1083. */
  1084. static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller)
  1085. {
  1086. struct ast_party_connected_line connected_caller;
  1087. ast_party_connected_line_init(&connected_caller);
  1088. ast_channel_lock(peer);
  1089. ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(peer));
  1090. ast_channel_unlock(peer);
  1091. connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
  1092. if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)
  1093. && ast_channel_connected_line_macro(peer, chan, &connected_caller, is_caller, 0)) {
  1094. ast_channel_update_connected_line(chan, &connected_caller, NULL);
  1095. }
  1096. ast_party_connected_line_free(&connected_caller);
  1097. }
  1098. static struct ast_channel *wait_for_answer(struct ast_channel *in,
  1099. struct dial_head *out_chans, int *to, struct ast_flags64 *peerflags,
  1100. char *opt_args[],
  1101. struct privacy_args *pa,
  1102. const struct cause_args *num_in, int *result, char *dtmf_progress,
  1103. const int ignore_cc,
  1104. struct ast_party_id *forced_clid, struct ast_party_id *stored_clid)
  1105. {
  1106. struct cause_args num = *num_in;
  1107. int prestart = num.busy + num.congestion + num.nochan;
  1108. int orig = *to;
  1109. struct ast_channel *peer = NULL;
  1110. #ifdef HAVE_EPOLL
  1111. struct chanlist *epollo;
  1112. #endif
  1113. struct chanlist *outgoing = AST_LIST_FIRST(out_chans);
  1114. /* single is set if only one destination is enabled */
  1115. int single = outgoing && !AST_LIST_NEXT(outgoing, node);
  1116. int caller_entertained = outgoing
  1117. && ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
  1118. struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1);
  1119. int cc_recall_core_id;
  1120. int is_cc_recall;
  1121. int cc_frame_received = 0;
  1122. int num_ringing = 0;
  1123. struct timeval start = ast_tvnow();
  1124. if (single) {
  1125. /* Turn off hold music, etc */
  1126. if (!caller_entertained) {
  1127. ast_deactivate_generator(in);
  1128. /* If we are calling a single channel, and not providing ringback or music, */
  1129. /* then, make them compatible for in-band tone purpose */
  1130. if (ast_channel_make_compatible(in, outgoing->chan) < 0) {
  1131. /* If these channels can not be made compatible,
  1132. * there is no point in continuing. The bridge
  1133. * will just fail if it gets that far.
  1134. */
  1135. *to = -1;
  1136. strcpy(pa->status, "CONGESTION");
  1137. ast_channel_publish_dial(in, outgoing->chan, NULL, pa->status);
  1138. return NULL;
  1139. }
  1140. }
  1141. if (!ast_test_flag64(outgoing, OPT_IGNORE_CONNECTEDLINE)
  1142. && !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) {
  1143. update_connected_line_from_peer(in, outgoing->chan, 1);
  1144. }
  1145. }
  1146. is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL);
  1147. #ifdef HAVE_EPOLL
  1148. AST_LIST_TRAVERSE(out_chans, epollo, node) {
  1149. ast_poll_channel_add(in, epollo->chan);
  1150. }
  1151. #endif
  1152. while ((*to = ast_remaining_ms(start, orig)) && !peer) {
  1153. struct chanlist *o;
  1154. int pos = 0; /* how many channels do we handle */
  1155. int numlines = prestart;
  1156. struct ast_channel *winner;
  1157. struct ast_channel *watchers[AST_MAX_WATCHERS];
  1158. watchers[pos++] = in;
  1159. AST_LIST_TRAVERSE(out_chans, o, node) {
  1160. /* Keep track of important channels */
  1161. if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan)
  1162. watchers[pos++] = o->chan;
  1163. numlines++;
  1164. }
  1165. if (pos == 1) { /* only the input channel is available */
  1166. if (numlines == (num.busy + num.congestion + num.nochan)) {
  1167. ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
  1168. if (num.busy)
  1169. strcpy(pa->status, "BUSY");
  1170. else if (num.congestion)
  1171. strcpy(pa->status, "CONGESTION");
  1172. else if (num.nochan)
  1173. strcpy(pa->status, "CHANUNAVAIL");
  1174. } else {
  1175. ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
  1176. }
  1177. *to = 0;
  1178. if (is_cc_recall) {
  1179. ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad");
  1180. }
  1181. return NULL;
  1182. }
  1183. winner = ast_waitfor_n(watchers, pos, to);
  1184. AST_LIST_TRAVERSE(out_chans, o, node) {
  1185. struct ast_frame *f;
  1186. struct ast_channel *c = o->chan;
  1187. if (c == NULL)
  1188. continue;
  1189. if (ast_test_flag64(o, DIAL_STILLGOING) && ast_channel_state(c) == AST_STATE_UP) {
  1190. if (!peer) {
  1191. ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
  1192. if (o->orig_chan_name
  1193. && strcmp(o->orig_chan_name, ast_channel_name(c))) {
  1194. /*
  1195. * The channel name changed so we must generate COLP update.
  1196. * Likely because a call pickup channel masqueraded in.
  1197. */
  1198. update_connected_line_from_peer(in, c, 1);
  1199. } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1200. if (o->pending_connected_update) {
  1201. if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
  1202. ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
  1203. ast_channel_update_connected_line(in, &o->connected, NULL);
  1204. }
  1205. } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
  1206. update_connected_line_from_peer(in, c, 1);
  1207. }
  1208. }
  1209. if (o->aoc_s_rate_list) {
  1210. size_t encoded_size;
  1211. struct ast_aoc_encoded *encoded;
  1212. if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
  1213. ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
  1214. ast_aoc_destroy_encoded(encoded);
  1215. }
  1216. }
  1217. peer = c;
  1218. publish_dial_end_event(in, out_chans, peer, "CANCEL");
  1219. ast_copy_flags64(peerflags, o,
  1220. OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
  1221. OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
  1222. OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
  1223. OPT_CALLEE_PARK | OPT_CALLER_PARK |
  1224. OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
  1225. DIAL_NOFORWARDHTML);
  1226. ast_channel_dialcontext_set(c, "");
  1227. ast_channel_exten_set(c, "");
  1228. }
  1229. continue;
  1230. }
  1231. if (c != winner)
  1232. continue;
  1233. /* here, o->chan == c == winner */
  1234. if (!ast_strlen_zero(ast_channel_call_forward(c))) {
  1235. pa->sentringing = 0;
  1236. if (!ignore_cc && (f = ast_read(c))) {
  1237. if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) {
  1238. /* This channel is forwarding the call, and is capable of CC, so
  1239. * be sure to add the new device interface to the list
  1240. */
  1241. ast_handle_cc_control_frame(in, c, f->data.ptr);
  1242. }
  1243. ast_frfree(f);
  1244. }
  1245. if (o->pending_connected_update) {
  1246. /*
  1247. * Re-seed the chanlist's connected line information with
  1248. * previously acquired connected line info from the incoming
  1249. * channel. The previously acquired connected line info could
  1250. * have been set through the CONNECTED_LINE dialplan function.
  1251. */
  1252. o->pending_connected_update = 0;
  1253. ast_channel_lock(in);
  1254. ast_party_connected_line_copy(&o->connected, ast_channel_connected(in));
  1255. ast_channel_unlock(in);
  1256. }
  1257. do_forward(o, &num, peerflags, single, caller_entertained, &orig,
  1258. forced_clid, stored_clid);
  1259. if (o->chan) {
  1260. ast_free(o->orig_chan_name);
  1261. o->orig_chan_name = ast_strdup(ast_channel_name(o->chan));
  1262. if (single
  1263. && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)
  1264. && !ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
  1265. update_connected_line_from_peer(in, o->chan, 1);
  1266. }
  1267. }
  1268. continue;
  1269. }
  1270. f = ast_read(winner);
  1271. if (!f) {
  1272. ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
  1273. #ifdef HAVE_EPOLL
  1274. ast_poll_channel_del(in, c);
  1275. #endif
  1276. ast_channel_publish_dial(in, c, NULL, ast_hangup_cause_to_dial_status(ast_channel_hangupcause(c)));
  1277. ast_hangup(c);
  1278. c = o->chan = NULL;
  1279. ast_clear_flag64(o, DIAL_STILLGOING);
  1280. handle_cause(ast_channel_hangupcause(in), &num);
  1281. continue;
  1282. }
  1283. switch (f->frametype) {
  1284. case AST_FRAME_CONTROL:
  1285. switch (f->subclass.integer) {
  1286. case AST_CONTROL_ANSWER:
  1287. /* This is our guy if someone answered. */
  1288. if (!peer) {
  1289. ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in));
  1290. if (o->orig_chan_name
  1291. && strcmp(o->orig_chan_name, ast_channel_name(c))) {
  1292. /*
  1293. * The channel name changed so we must generate COLP update.
  1294. * Likely because a call pickup channel masqueraded in.
  1295. */
  1296. update_connected_line_from_peer(in, c, 1);
  1297. } else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1298. if (o->pending_connected_update) {
  1299. if (ast_channel_connected_line_sub(c, in, &o->connected, 0) &&
  1300. ast_channel_connected_line_macro(c, in, &o->connected, 1, 0)) {
  1301. ast_channel_update_connected_line(in, &o->connected, NULL);
  1302. }
  1303. } else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) {
  1304. update_connected_line_from_peer(in, c, 1);
  1305. }
  1306. }
  1307. if (o->aoc_s_rate_list) {
  1308. size_t encoded_size;
  1309. struct ast_aoc_encoded *encoded;
  1310. if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) {
  1311. ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size);
  1312. ast_aoc_destroy_encoded(encoded);
  1313. }
  1314. }
  1315. peer = c;
  1316. /* Inform everyone else that they've been canceled.
  1317. * The dial end event for the peer will be sent out after
  1318. * other Dial options have been handled.
  1319. */
  1320. publish_dial_end_event(in, out_chans, peer, "CANCEL");
  1321. ast_copy_flags64(peerflags, o,
  1322. OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
  1323. OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
  1324. OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
  1325. OPT_CALLEE_PARK | OPT_CALLER_PARK |
  1326. OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
  1327. DIAL_NOFORWARDHTML);
  1328. ast_channel_dialcontext_set(c, "");
  1329. ast_channel_exten_set(c, "");
  1330. if (CAN_EARLY_BRIDGE(peerflags, in, peer)) {
  1331. /* Setup early bridge if appropriate */
  1332. ast_channel_early_bridge(in, peer);
  1333. }
  1334. }
  1335. /* If call has been answered, then the eventual hangup is likely to be normal hangup */
  1336. ast_channel_hangupcause_set(in, AST_CAUSE_NORMAL_CLEARING);
  1337. ast_channel_hangupcause_set(c, AST_CAUSE_NORMAL_CLEARING);
  1338. break;
  1339. case AST_CONTROL_BUSY:
  1340. ast_verb(3, "%s is busy\n", ast_channel_name(c));
  1341. ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
  1342. ast_channel_publish_dial(in, c, NULL, "BUSY");
  1343. ast_hangup(c);
  1344. c = o->chan = NULL;
  1345. ast_clear_flag64(o, DIAL_STILLGOING);
  1346. handle_cause(AST_CAUSE_BUSY, &num);
  1347. break;
  1348. case AST_CONTROL_CONGESTION:
  1349. ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c));
  1350. ast_channel_hangupcause_set(in, ast_channel_hangupcause(c));
  1351. ast_channel_publish_dial(in, c, NULL, "CONGESTION");
  1352. ast_hangup(c);
  1353. c = o->chan = NULL;
  1354. ast_clear_flag64(o, DIAL_STILLGOING);
  1355. handle_cause(AST_CAUSE_CONGESTION, &num);
  1356. break;
  1357. case AST_CONTROL_RINGING:
  1358. /* This is a tricky area to get right when using a native
  1359. * CC agent. The reason is that we do the best we can to send only a
  1360. * single ringing notification to the caller.
  1361. *
  1362. * Call completion complicates the logic used here. CCNR is typically
  1363. * offered during a ringing message. Let's say that party A calls
  1364. * parties B, C, and D. B and C do not support CC requests, but D
  1365. * does. If we were to receive a ringing notification from B before
  1366. * the others, then we would end up sending a ringing message to
  1367. * A with no CCNR offer present.
  1368. *
  1369. * The approach that we have taken is that if we receive a ringing
  1370. * response from a party and no CCNR offer is present, we need to
  1371. * wait. Specifically, we need to wait until either a) a called party
  1372. * offers CCNR in its ringing response or b) all called parties have
  1373. * responded in some way to our call and none offers CCNR.
  1374. *
  1375. * The drawback to this is that if one of the parties has a delayed
  1376. * response or, god forbid, one just plain doesn't respond to our
  1377. * outgoing call, then this will result in a significant delay between
  1378. * when the caller places the call and hears ringback.
  1379. *
  1380. * Note also that if CC is disabled for this call, then it is perfectly
  1381. * fine for ringing frames to get sent through.
  1382. */
  1383. ++num_ringing;
  1384. if (ignore_cc || cc_frame_received || num_ringing == numlines) {
  1385. ast_verb(3, "%s is ringing\n", ast_channel_name(c));
  1386. /* Setup early media if appropriate */
  1387. if (single && !caller_entertained
  1388. && CAN_EARLY_BRIDGE(peerflags, in, c)) {
  1389. ast_channel_early_bridge(in, c);
  1390. }
  1391. if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
  1392. ast_indicate(in, AST_CONTROL_RINGING);
  1393. pa->sentringing++;
  1394. }
  1395. }
  1396. break;
  1397. case AST_CONTROL_PROGRESS:
  1398. ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
  1399. /* Setup early media if appropriate */
  1400. if (single && !caller_entertained
  1401. && CAN_EARLY_BRIDGE(peerflags, in, c)) {
  1402. ast_channel_early_bridge(in, c);
  1403. }
  1404. if (!ast_test_flag64(outgoing, OPT_RINGBACK)) {
  1405. if (single || (!single && !pa->sentringing)) {
  1406. ast_indicate(in, AST_CONTROL_PROGRESS);
  1407. }
  1408. }
  1409. if (!ast_strlen_zero(dtmf_progress)) {
  1410. ast_verb(3,
  1411. "Sending DTMF '%s' to the called party as result of receiving a PROGRESS message.\n",
  1412. dtmf_progress);
  1413. ast_dtmf_stream(c, in, dtmf_progress, 250, 0);
  1414. }
  1415. break;
  1416. case AST_CONTROL_VIDUPDATE:
  1417. case AST_CONTROL_SRCUPDATE:
  1418. case AST_CONTROL_SRCCHANGE:
  1419. if (!single || caller_entertained) {
  1420. break;
  1421. }
  1422. ast_verb(3, "%s requested media update control %d, passing it to %s\n",
  1423. ast_channel_name(c), f->subclass.integer, ast_channel_name(in));
  1424. ast_indicate(in, f->subclass.integer);
  1425. break;
  1426. case AST_CONTROL_CONNECTED_LINE:
  1427. if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1428. ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in));
  1429. break;
  1430. }
  1431. if (!single) {
  1432. struct ast_party_connected_line connected;
  1433. ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n",
  1434. ast_channel_name(c), ast_channel_name(in));
  1435. ast_party_connected_line_set_init(&connected, &o->connected);
  1436. ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected);
  1437. ast_party_connected_line_set(&o->connected, &connected, NULL);
  1438. ast_party_connected_line_free(&connected);
  1439. o->pending_connected_update = 1;
  1440. break;
  1441. }
  1442. if (ast_channel_connected_line_sub(c, in, f, 1) &&
  1443. ast_channel_connected_line_macro(c, in, f, 1, 1)) {
  1444. ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen);
  1445. }
  1446. break;
  1447. case AST_CONTROL_AOC:
  1448. {
  1449. struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan);
  1450. if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) {
  1451. ast_aoc_destroy_decoded(o->aoc_s_rate_list);
  1452. o->aoc_s_rate_list = decoded;
  1453. } else {
  1454. ast_aoc_destroy_decoded(decoded);
  1455. }
  1456. }
  1457. break;
  1458. case AST_CONTROL_REDIRECTING:
  1459. if (!single) {
  1460. /*
  1461. * Redirecting updates to the caller make sense only on single
  1462. * calls.
  1463. */
  1464. break;
  1465. }
  1466. if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1467. ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in));
  1468. break;
  1469. }
  1470. ast_verb(3, "%s redirecting info has changed, passing it to %s\n",
  1471. ast_channel_name(c), ast_channel_name(in));
  1472. if (ast_channel_redirecting_sub(c, in, f, 1) &&
  1473. ast_channel_redirecting_macro(c, in, f, 1, 1)) {
  1474. ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen);
  1475. }
  1476. pa->sentringing = 0;
  1477. break;
  1478. case AST_CONTROL_PROCEEDING:
  1479. ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in));
  1480. if (single && !caller_entertained
  1481. && CAN_EARLY_BRIDGE(peerflags, in, c)) {
  1482. ast_channel_early_bridge(in, c);
  1483. }
  1484. if (!ast_test_flag64(outgoing, OPT_RINGBACK))
  1485. ast_indicate(in, AST_CONTROL_PROCEEDING);
  1486. break;
  1487. case AST_CONTROL_HOLD:
  1488. /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
  1489. ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c));
  1490. ast_indicate_data(in, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
  1491. break;
  1492. case AST_CONTROL_UNHOLD:
  1493. /* XXX this should be saved like AST_CONTROL_CONNECTED_LINE for !single || caller_entertained */
  1494. ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c));
  1495. ast_indicate(in, AST_CONTROL_UNHOLD);
  1496. break;
  1497. case AST_CONTROL_OFFHOOK:
  1498. case AST_CONTROL_FLASH:
  1499. /* Ignore going off hook and flash */
  1500. break;
  1501. case AST_CONTROL_CC:
  1502. if (!ignore_cc) {
  1503. ast_handle_cc_control_frame(in, c, f->data.ptr);
  1504. cc_frame_received = 1;
  1505. }
  1506. break;
  1507. case AST_CONTROL_PVT_CAUSE_CODE:
  1508. ast_indicate_data(in, AST_CONTROL_PVT_CAUSE_CODE, f->data.ptr, f->datalen);
  1509. break;
  1510. case -1:
  1511. if (single && !caller_entertained) {
  1512. ast_verb(3, "%s stopped sounds\n", ast_channel_name(c));
  1513. ast_indicate(in, -1);
  1514. pa->sentringing = 0;
  1515. }
  1516. break;
  1517. default:
  1518. ast_debug(1, "Dunno what to do with control type %d\n", f->subclass.integer);
  1519. break;
  1520. }
  1521. break;
  1522. case AST_FRAME_VIDEO:
  1523. case AST_FRAME_VOICE:
  1524. case AST_FRAME_IMAGE:
  1525. if (caller_entertained) {
  1526. break;
  1527. }
  1528. /* Fall through */
  1529. case AST_FRAME_TEXT:
  1530. if (single && ast_write(in, f)) {
  1531. ast_log(LOG_WARNING, "Unable to write frametype: %u\n",
  1532. f->frametype);
  1533. }
  1534. break;
  1535. case AST_FRAME_HTML:
  1536. if (single && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML)
  1537. && ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
  1538. ast_log(LOG_WARNING, "Unable to send URL\n");
  1539. }
  1540. break;
  1541. default:
  1542. break;
  1543. }
  1544. ast_frfree(f);
  1545. } /* end for */
  1546. if (winner == in) {
  1547. struct ast_frame *f = ast_read(in);
  1548. #if 0
  1549. if (f && (f->frametype != AST_FRAME_VOICE))
  1550. printf("Frame type: %d, %d\n", f->frametype, f->subclass);
  1551. else if (!f || (f->frametype != AST_FRAME_VOICE))
  1552. printf("Hangup received on %s\n", in->name);
  1553. #endif
  1554. if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) {
  1555. /* Got hung up */
  1556. *to = -1;
  1557. strcpy(pa->status, "CANCEL");
  1558. publish_dial_end_event(in, out_chans, NULL, pa->status);
  1559. if (f) {
  1560. if (f->data.uint32) {
  1561. ast_channel_hangupcause_set(in, f->data.uint32);
  1562. }
  1563. ast_frfree(f);
  1564. }
  1565. if (is_cc_recall) {
  1566. ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)");
  1567. }
  1568. return NULL;
  1569. }
  1570. /* now f is guaranteed non-NULL */
  1571. if (f->frametype == AST_FRAME_DTMF) {
  1572. if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) {
  1573. const char *context;
  1574. ast_channel_lock(in);
  1575. context = pbx_builtin_getvar_helper(in, "EXITCONTEXT");
  1576. if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) {
  1577. ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer);
  1578. *to = 0;
  1579. *result = f->subclass.integer;
  1580. strcpy(pa->status, "CANCEL");
  1581. publish_dial_end_event(in, out_chans, NULL, pa->status);
  1582. ast_frfree(f);
  1583. ast_channel_unlock(in);
  1584. if (is_cc_recall) {
  1585. ast_cc_completed(in, "CC completed, but the caller used DTMF to exit");
  1586. }
  1587. return NULL;
  1588. }
  1589. ast_channel_unlock(in);
  1590. }
  1591. if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) &&
  1592. detect_disconnect(in, f->subclass.integer, &featurecode)) {
  1593. ast_verb(3, "User requested call disconnect.\n");
  1594. *to = 0;
  1595. strcpy(pa->status, "CANCEL");
  1596. publish_dial_end_event(in, out_chans, NULL, pa->status);
  1597. ast_frfree(f);
  1598. if (is_cc_recall) {
  1599. ast_cc_completed(in, "CC completed, but the caller hung up with DTMF");
  1600. }
  1601. return NULL;
  1602. }
  1603. }
  1604. /* Send the frame from the in channel to all outgoing channels. */
  1605. AST_LIST_TRAVERSE(out_chans, o, node) {
  1606. if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) {
  1607. /* This outgoing channel has died so don't send the frame to it. */
  1608. continue;
  1609. }
  1610. switch (f->frametype) {
  1611. case AST_FRAME_HTML:
  1612. /* Forward HTML stuff */
  1613. if (!ast_test_flag64(o, DIAL_NOFORWARDHTML)
  1614. && ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) {
  1615. ast_log(LOG_WARNING, "Unable to send URL\n");
  1616. }
  1617. break;
  1618. case AST_FRAME_VIDEO:
  1619. case AST_FRAME_VOICE:
  1620. case AST_FRAME_IMAGE:
  1621. if (!single || caller_entertained) {
  1622. /*
  1623. * We are calling multiple parties or caller is being
  1624. * entertained and has thus not been made compatible.
  1625. * No need to check any other called parties.
  1626. */
  1627. goto skip_frame;
  1628. }
  1629. /* Fall through */
  1630. case AST_FRAME_TEXT:
  1631. case AST_FRAME_DTMF_BEGIN:
  1632. case AST_FRAME_DTMF_END:
  1633. if (ast_write(o->chan, f)) {
  1634. ast_log(LOG_WARNING, "Unable to forward frametype: %u\n",
  1635. f->frametype);
  1636. }
  1637. break;
  1638. case AST_FRAME_CONTROL:
  1639. switch (f->subclass.integer) {
  1640. case AST_CONTROL_HOLD:
  1641. ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan));
  1642. ast_indicate_data(o->chan, AST_CONTROL_HOLD, f->data.ptr, f->datalen);
  1643. break;
  1644. case AST_CONTROL_UNHOLD:
  1645. ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan));
  1646. ast_indicate(o->chan, AST_CONTROL_UNHOLD);
  1647. break;
  1648. case AST_CONTROL_VIDUPDATE:
  1649. case AST_CONTROL_SRCUPDATE:
  1650. case AST_CONTROL_SRCCHANGE:
  1651. if (!single || caller_entertained) {
  1652. /*
  1653. * We are calling multiple parties or caller is being
  1654. * entertained and has thus not been made compatible.
  1655. * No need to check any other called parties.
  1656. */
  1657. goto skip_frame;
  1658. }
  1659. ast_verb(3, "%s requested media update control %d, passing it to %s\n",
  1660. ast_channel_name(in), f->subclass.integer, ast_channel_name(o->chan));
  1661. ast_indicate(o->chan, f->subclass.integer);
  1662. break;
  1663. case AST_CONTROL_CONNECTED_LINE:
  1664. if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1665. ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan));
  1666. break;
  1667. }
  1668. if (ast_channel_connected_line_sub(in, o->chan, f, 1) &&
  1669. ast_channel_connected_line_macro(in, o->chan, f, 0, 1)) {
  1670. ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
  1671. }
  1672. break;
  1673. case AST_CONTROL_REDIRECTING:
  1674. if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) {
  1675. ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan));
  1676. break;
  1677. }
  1678. if (ast_channel_redirecting_sub(in, o->chan, f, 1) &&
  1679. ast_channel_redirecting_macro(in, o->chan, f, 0, 1)) {
  1680. ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen);
  1681. }
  1682. break;
  1683. default:
  1684. /* We are not going to do anything with this frame. */
  1685. goto skip_frame;
  1686. }
  1687. break;
  1688. default:
  1689. /* We are not going to do anything with this frame. */
  1690. goto skip_frame;
  1691. }
  1692. }
  1693. skip_frame:;
  1694. ast_frfree(f);
  1695. }
  1696. }
  1697. if (!*to || ast_check_hangup(in)) {
  1698. ast_verb(3, "Nobody picked up in %d ms\n", orig);
  1699. publish_dial_end_event(in, out_chans, NULL, "NOANSWER");
  1700. }
  1701. #ifdef HAVE_EPOLL
  1702. AST_LIST_TRAVERSE(out_chans, epollo, node) {
  1703. if (epollo->chan)
  1704. ast_poll_channel_del(in, epollo->chan);
  1705. }
  1706. #endif
  1707. if (is_cc_recall) {
  1708. ast_cc_completed(in, "Recall completed!");
  1709. }
  1710. return peer;
  1711. }
  1712. static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode)
  1713. {
  1714. char disconnect_code[AST_FEATURE_MAX_LEN];
  1715. int res;
  1716. ast_str_append(featurecode, 1, "%c", code);
  1717. res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code));
  1718. if (res) {
  1719. ast_str_reset(*featurecode);
  1720. return 0;
  1721. }
  1722. if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) {
  1723. /* Could be a partial match, anyway */
  1724. if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) {
  1725. ast_str_reset(*featurecode);
  1726. }
  1727. return 0;
  1728. }
  1729. if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) {
  1730. ast_str_reset(*featurecode);
  1731. return 0;
  1732. }
  1733. return 1;
  1734. }
  1735. /* returns true if there is a valid privacy reply */
  1736. static int valid_priv_reply(struct ast_flags64 *opts, int res)
  1737. {
  1738. if (res < '1')
  1739. return 0;
  1740. if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5')
  1741. return 1;
  1742. if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4')
  1743. return 1;
  1744. return 0;
  1745. }
  1746. static int do_privacy(struct ast_channel *chan, struct ast_channel *peer,
  1747. struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa)
  1748. {
  1749. int res2;
  1750. int loopcount = 0;
  1751. /* Get the user's intro, store it in priv-callerintros/$CID,
  1752. unless it is already there-- this should be done before the
  1753. call is actually dialed */
  1754. /* all ring indications and moh for the caller has been halted as soon as the
  1755. target extension was picked up. We are going to have to kill some
  1756. time and make the caller believe the peer hasn't picked up yet */
  1757. if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
  1758. char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
  1759. ast_indicate(chan, -1);
  1760. ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
  1761. ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
  1762. ast_channel_musicclass_set(chan, original_moh);
  1763. } else if (ast_test_flag64(opts, OPT_RINGBACK) || ast_test_flag64(opts, OPT_RING_WITH_EARLY_MEDIA)) {
  1764. ast_indicate(chan, AST_CONTROL_RINGING);
  1765. pa->sentringing++;
  1766. }
  1767. /* Start autoservice on the other chan ?? */
  1768. res2 = ast_autoservice_start(chan);
  1769. /* Now Stream the File */
  1770. for (loopcount = 0; loopcount < 3; loopcount++) {
  1771. if (res2 && loopcount == 0) /* error in ast_autoservice_start() */
  1772. break;
  1773. if (!res2) /* on timeout, play the message again */
  1774. res2 = ast_play_and_wait(peer, "priv-callpending");
  1775. if (!valid_priv_reply(opts, res2))
  1776. res2 = 0;
  1777. /* priv-callpending script:
  1778. "I have a caller waiting, who introduces themselves as:"
  1779. */
  1780. if (!res2)
  1781. res2 = ast_play_and_wait(peer, pa->privintro);
  1782. if (!valid_priv_reply(opts, res2))
  1783. res2 = 0;
  1784. /* now get input from the called party, as to their choice */
  1785. if (!res2) {
  1786. /* XXX can we have both, or they are mutually exclusive ? */
  1787. if (ast_test_flag64(opts, OPT_PRIVACY))
  1788. res2 = ast_play_and_wait(peer, "priv-callee-options");
  1789. if (ast_test_flag64(opts, OPT_SCREENING))
  1790. res2 = ast_play_and_wait(peer, "screen-callee-options");
  1791. }
  1792. /*! \page DialPrivacy Dial Privacy scripts
  1793. * \par priv-callee-options script:
  1794. * \li Dial 1 if you wish this caller to reach you directly in the future,
  1795. * and immediately connect to their incoming call.
  1796. * \li Dial 2 if you wish to send this caller to voicemail now and forevermore.
  1797. * \li Dial 3 to send this caller to the torture menus, now and forevermore.
  1798. * \li Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
  1799. * \li Dial 5 to allow this caller to come straight thru to you in the future,
  1800. * but right now, just this once, send them to voicemail.
  1801. *
  1802. * \par screen-callee-options script:
  1803. * \li Dial 1 if you wish to immediately connect to the incoming call
  1804. * \li Dial 2 if you wish to send this caller to voicemail.
  1805. * \li Dial 3 to send this caller to the torture menus.
  1806. * \li Dial 4 to send this caller to a simple "go away" menu.
  1807. */
  1808. if (valid_priv_reply(opts, res2))
  1809. break;
  1810. /* invalid option */
  1811. res2 = ast_play_and_wait(peer, "vm-sorry");
  1812. }
  1813. if (ast_test_flag64(opts, OPT_MUSICBACK)) {
  1814. ast_moh_stop(chan);
  1815. } else if (ast_test_flag64(opts, OPT_RINGBACK) || ast_test_flag64(opts, OPT_RING_WITH_EARLY_MEDIA)) {
  1816. ast_indicate(chan, -1);
  1817. pa->sentringing = 0;
  1818. }
  1819. ast_autoservice_stop(chan);
  1820. if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) {
  1821. /* map keypresses to various things, the index is res2 - '1' */
  1822. static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" };
  1823. static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW};
  1824. int i = res2 - '1';
  1825. ast_verb(3, "--Set privacy database entry %s/%s to %s\n",
  1826. opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]);
  1827. ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]);
  1828. }
  1829. switch (res2) {
  1830. case '1':
  1831. break;
  1832. case '2':
  1833. ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
  1834. break;
  1835. case '3':
  1836. ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
  1837. break;
  1838. case '4':
  1839. ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
  1840. break;
  1841. case '5':
  1842. if (ast_test_flag64(opts, OPT_PRIVACY)) {
  1843. ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
  1844. break;
  1845. }
  1846. /* if not privacy, then 5 is the same as "default" case */
  1847. default: /* bad input or -1 if failure to start autoservice */
  1848. /* well, if the user messes up, ... he had his chance... What Is The Best Thing To Do? */
  1849. /* well, there seems basically two choices. Just patch the caller thru immediately,
  1850. or,... put 'em thru to voicemail. */
  1851. /* since the callee may have hung up, let's do the voicemail thing, no database decision */
  1852. ast_log(LOG_NOTICE, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n");
  1853. /* XXX should we set status to DENY ? */
  1854. /* XXX what about the privacy flags ? */
  1855. break;
  1856. }
  1857. if (res2 == '1') { /* the only case where we actually connect */
  1858. /* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
  1859. just clog things up, and it's not useful information, not being tied to a CID */
  1860. if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) {
  1861. ast_filedelete(pa->privintro, NULL);
  1862. if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
  1863. ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
  1864. else
  1865. ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
  1866. }
  1867. return 0; /* the good exit path */
  1868. } else {
  1869. return -1;
  1870. }
  1871. }
  1872. /*! \brief returns 1 if successful, 0 or <0 if the caller should 'goto out' */
  1873. static int setup_privacy_args(struct privacy_args *pa,
  1874. struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan)
  1875. {
  1876. char callerid[60];
  1877. int res;
  1878. char *l;
  1879. if (ast_channel_caller(chan)->id.number.valid
  1880. && !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
  1881. l = ast_strdupa(ast_channel_caller(chan)->id.number.str);
  1882. ast_shrink_phone_number(l);
  1883. if (ast_test_flag64(opts, OPT_PRIVACY) ) {
  1884. ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l);
  1885. pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l);
  1886. } else {
  1887. ast_verb(3, "Privacy Screening, clid is '%s'\n", l);
  1888. pa->privdb_val = AST_PRIVACY_UNKNOWN;
  1889. }
  1890. } else {
  1891. char *tnam, *tn2;
  1892. tnam = ast_strdupa(ast_channel_name(chan));
  1893. /* clean the channel name so slashes don't try to end up in disk file name */
  1894. for (tn2 = tnam; *tn2; tn2++) {
  1895. if (*tn2 == '/') /* any other chars to be afraid of? */
  1896. *tn2 = '=';
  1897. }
  1898. ast_verb(3, "Privacy-- callerid is empty\n");
  1899. snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam);
  1900. l = callerid;
  1901. pa->privdb_val = AST_PRIVACY_UNKNOWN;
  1902. }
  1903. ast_copy_string(pa->privcid, l, sizeof(pa->privcid));
  1904. if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) {
  1905. /* if callerid is set and OPT_SCREEN_NOCALLERID is set also */
  1906. ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid);
  1907. pa->privdb_val = AST_PRIVACY_ALLOW;
  1908. } else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) {
  1909. ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val);
  1910. }
  1911. if (pa->privdb_val == AST_PRIVACY_DENY) {
  1912. ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n");
  1913. ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status));
  1914. return 0;
  1915. } else if (pa->privdb_val == AST_PRIVACY_KILL) {
  1916. ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status));
  1917. return 0; /* Is this right? */
  1918. } else if (pa->privdb_val == AST_PRIVACY_TORTURE) {
  1919. ast_copy_string(pa->status, "TORTURE", sizeof(pa->status));
  1920. return 0; /* is this right??? */
  1921. } else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) {
  1922. /* Get the user's intro, store it in priv-callerintros/$CID,
  1923. unless it is already there-- this should be done before the
  1924. call is actually dialed */
  1925. /* make sure the priv-callerintros dir actually exists */
  1926. snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR);
  1927. if ((res = ast_mkdir(pa->privintro, 0755))) {
  1928. ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res));
  1929. return -1;
  1930. }
  1931. snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid);
  1932. if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) {
  1933. /* the DELUX version of this code would allow this caller the
  1934. option to hear and retape their previously recorded intro.
  1935. */
  1936. } else {
  1937. int duration; /* for feedback from play_and_wait */
  1938. /* the file doesn't exist yet. Let the caller submit his
  1939. vocal intro for posterity */
  1940. /* priv-recordintro script:
  1941. "At the tone, please say your name:"
  1942. */
  1943. int silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
  1944. ast_answer(chan);
  1945. 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 */
  1946. /* don't think we'll need a lock removed, we took care of
  1947. conflicts by naming the pa.privintro file */
  1948. if (res == -1) {
  1949. /* Delete the file regardless since they hung up during recording */
  1950. ast_filedelete(pa->privintro, NULL);
  1951. if (ast_fileexists(pa->privintro, NULL, NULL) > 0)
  1952. ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro);
  1953. else
  1954. ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro);
  1955. return -1;
  1956. }
  1957. if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) )
  1958. ast_waitstream(chan, "");
  1959. }
  1960. }
  1961. return 1; /* success */
  1962. }
  1963. static void end_bridge_callback(void *data)
  1964. {
  1965. char buf[80];
  1966. time_t end;
  1967. struct ast_channel *chan = data;
  1968. time(&end);
  1969. ast_channel_lock(chan);
  1970. ast_channel_stage_snapshot(chan);
  1971. snprintf(buf, sizeof(buf), "%d", ast_channel_get_up_time(chan));
  1972. pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", buf);
  1973. snprintf(buf, sizeof(buf), "%d", ast_channel_get_duration(chan));
  1974. pbx_builtin_setvar_helper(chan, "DIALEDTIME", buf);
  1975. ast_channel_stage_snapshot_done(chan);
  1976. ast_channel_unlock(chan);
  1977. }
  1978. static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) {
  1979. bconfig->end_bridge_callback_data = originator;
  1980. }
  1981. static int dial_handle_playtones(struct ast_channel *chan, const char *data)
  1982. {
  1983. struct ast_tone_zone_sound *ts = NULL;
  1984. int res;
  1985. const char *str = data;
  1986. if (ast_strlen_zero(str)) {
  1987. ast_debug(1,"Nothing to play\n");
  1988. return -1;
  1989. }
  1990. ts = ast_get_indication_tone(ast_channel_zone(chan), str);
  1991. if (ts && ts->data[0]) {
  1992. res = ast_playtones_start(chan, 0, ts->data, 0);
  1993. } else {
  1994. res = -1;
  1995. }
  1996. if (ts) {
  1997. ts = ast_tone_zone_sound_unref(ts);
  1998. }
  1999. if (res) {
  2000. ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str);
  2001. }
  2002. return res;
  2003. }
  2004. /*!
  2005. * \internal
  2006. * \brief Setup the after bridge goto location on the peer.
  2007. * \since 12.0.0
  2008. *
  2009. * \param chan Calling channel for bridge.
  2010. * \param peer Peer channel for bridge.
  2011. * \param opts Dialing option flags.
  2012. * \param opt_args Dialing option argument strings.
  2013. *
  2014. * \return Nothing
  2015. */
  2016. static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[])
  2017. {
  2018. const char *context;
  2019. const char *extension;
  2020. int priority;
  2021. if (ast_test_flag64(opts, OPT_PEER_H)) {
  2022. ast_channel_lock(chan);
  2023. context = ast_strdupa(ast_channel_context(chan));
  2024. ast_channel_unlock(chan);
  2025. ast_bridge_set_after_h(peer, context);
  2026. } else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) {
  2027. ast_channel_lock(chan);
  2028. context = ast_strdupa(ast_channel_context(chan));
  2029. extension = ast_strdupa(ast_channel_exten(chan));
  2030. priority = ast_channel_priority(chan);
  2031. ast_channel_unlock(chan);
  2032. ast_bridge_set_after_go_on(peer, context, extension, priority,
  2033. opt_args[OPT_ARG_CALLEE_GO_ON]);
  2034. }
  2035. }
  2036. static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec)
  2037. {
  2038. int res = -1; /* default: error */
  2039. char *rest, *cur; /* scan the list of destinations */
  2040. struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; /* list of destinations */
  2041. struct chanlist *outgoing;
  2042. struct chanlist *tmp;
  2043. struct ast_channel *peer;
  2044. int to; /* timeout */
  2045. struct cause_args num = { chan, 0, 0, 0 };
  2046. int cause;
  2047. struct ast_bridge_config config = { { 0, } };
  2048. struct timeval calldurationlimit = { 0, };
  2049. char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress=NULL;
  2050. struct privacy_args pa = {
  2051. .sentringing = 0,
  2052. .privdb_val = 0,
  2053. .status = "INVALIDARGS",
  2054. };
  2055. int sentringing = 0, moh = 0;
  2056. const char *outbound_group = NULL;
  2057. int result = 0;
  2058. char *parse;
  2059. int opermode = 0;
  2060. int delprivintro = 0;
  2061. AST_DECLARE_APP_ARGS(args,
  2062. AST_APP_ARG(peers);
  2063. AST_APP_ARG(timeout);
  2064. AST_APP_ARG(options);
  2065. AST_APP_ARG(url);
  2066. );
  2067. struct ast_flags64 opts = { 0, };
  2068. char *opt_args[OPT_ARG_ARRAY_SIZE];
  2069. int fulldial = 0, num_dialed = 0;
  2070. int ignore_cc = 0;
  2071. char device_name[AST_CHANNEL_NAME];
  2072. char forced_clid_name[AST_MAX_EXTENSION];
  2073. char stored_clid_name[AST_MAX_EXTENSION];
  2074. int force_forwards_only; /*!< TRUE if force CallerID on call forward only. Legacy behaviour.*/
  2075. /*!
  2076. * \brief Forced CallerID party information to send.
  2077. * \note This will not have any malloced strings so do not free it.
  2078. */
  2079. struct ast_party_id forced_clid;
  2080. /*!
  2081. * \brief Stored CallerID information if needed.
  2082. *
  2083. * \note If OPT_ORIGINAL_CLID set then this is the o option
  2084. * CallerID. Otherwise it is the dialplan extension and hint
  2085. * name.
  2086. *
  2087. * \note This will not have any malloced strings so do not free it.
  2088. */
  2089. struct ast_party_id stored_clid;
  2090. /*!
  2091. * \brief CallerID party information to store.
  2092. * \note This will not have any malloced strings so do not free it.
  2093. */
  2094. struct ast_party_caller caller;
  2095. int max_forwards;
  2096. /* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
  2097. ast_channel_lock(chan);
  2098. ast_channel_stage_snapshot(chan);
  2099. pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
  2100. pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
  2101. pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", "");
  2102. pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
  2103. pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
  2104. ast_channel_stage_snapshot_done(chan);
  2105. max_forwards = ast_max_forwards_get(chan);
  2106. ast_channel_unlock(chan);
  2107. if (max_forwards <= 0) {
  2108. ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n",
  2109. ast_channel_name(chan));
  2110. pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY");
  2111. return -1;
  2112. }
  2113. if (ast_strlen_zero(data)) {
  2114. ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
  2115. pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
  2116. return -1;
  2117. }
  2118. if (ast_check_hangup_locked(chan)) {
  2119. /*
  2120. * Caller hung up before we could dial. If dial is executed
  2121. * within an AGI then the AGI has likely eaten all queued
  2122. * frames before executing the dial in DeadAGI mode. With
  2123. * the caller hung up and no pending frames from the caller's
  2124. * read queue, dial would not know that the call has hung up
  2125. * until a called channel answers. It is rather annoying to
  2126. * whoever just answered the non-existent call.
  2127. *
  2128. * Dial should not continue execution in DeadAGI mode, hangup
  2129. * handlers, or the h exten.
  2130. */
  2131. ast_verb(3, "Caller hung up before dial.\n");
  2132. pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL");
  2133. return -1;
  2134. }
  2135. parse = ast_strdupa(data);
  2136. AST_STANDARD_APP_ARGS(args, parse);
  2137. if (!ast_strlen_zero(args.options) &&
  2138. ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) {
  2139. pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
  2140. goto done;
  2141. }
  2142. if (ast_strlen_zero(args.peers)) {
  2143. ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
  2144. pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
  2145. goto done;
  2146. }
  2147. if (ast_cc_call_init(chan, &ignore_cc)) {
  2148. goto done;
  2149. }
  2150. if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) {
  2151. delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]);
  2152. if (delprivintro < 0 || delprivintro > 1) {
  2153. ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro);
  2154. delprivintro = 0;
  2155. }
  2156. }
  2157. if (!ast_test_flag64(&opts, OPT_RINGBACK)) {
  2158. opt_args[OPT_ARG_RINGBACK] = NULL;
  2159. }
  2160. if (ast_test_flag64(&opts, OPT_OPERMODE)) {
  2161. opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]);
  2162. ast_verb(3, "Setting operator services mode to %d.\n", opermode);
  2163. }
  2164. if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
  2165. calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]);
  2166. if (!calldurationlimit.tv_sec) {
  2167. ast_log(LOG_WARNING, "Dial does not accept S(%s), hanging up.\n", opt_args[OPT_ARG_DURATION_STOP]);
  2168. pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
  2169. goto done;
  2170. }
  2171. ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0);
  2172. }
  2173. if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) {
  2174. dtmf_progress = opt_args[OPT_ARG_SENDDTMF];
  2175. dtmfcalled = strsep(&dtmf_progress, ":");
  2176. dtmfcalling = strsep(&dtmf_progress, ":");
  2177. }
  2178. if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) {
  2179. if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit))
  2180. goto done;
  2181. }
  2182. /* Setup the forced CallerID information to send if used. */
  2183. ast_party_id_init(&forced_clid);
  2184. force_forwards_only = 0;
  2185. if (ast_test_flag64(&opts, OPT_FORCECLID)) {
  2186. if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) {
  2187. ast_channel_lock(chan);
  2188. forced_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
  2189. ast_channel_unlock(chan);
  2190. forced_clid_name[0] = '\0';
  2191. forced_clid.name.str = (char *) get_cid_name(forced_clid_name,
  2192. sizeof(forced_clid_name), chan);
  2193. force_forwards_only = 1;
  2194. } else {
  2195. /* Note: The opt_args[OPT_ARG_FORCECLID] string value is altered here. */
  2196. ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str,
  2197. &forced_clid.number.str);
  2198. }
  2199. if (!ast_strlen_zero(forced_clid.name.str)) {
  2200. forced_clid.name.valid = 1;
  2201. }
  2202. if (!ast_strlen_zero(forced_clid.number.str)) {
  2203. forced_clid.number.valid = 1;
  2204. }
  2205. }
  2206. if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG)
  2207. && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) {
  2208. forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG];
  2209. }
  2210. forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN;
  2211. if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES)
  2212. && !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) {
  2213. int pres;
  2214. pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]);
  2215. if (0 <= pres) {
  2216. forced_clid.number.presentation = pres;
  2217. }
  2218. }
  2219. /* Setup the stored CallerID information if needed. */
  2220. ast_party_id_init(&stored_clid);
  2221. if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) {
  2222. if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) {
  2223. ast_channel_lock(chan);
  2224. ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id);
  2225. if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) {
  2226. stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str);
  2227. }
  2228. if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) {
  2229. stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str);
  2230. }
  2231. if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) {
  2232. stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str);
  2233. }
  2234. if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) {
  2235. stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag);
  2236. }
  2237. ast_channel_unlock(chan);
  2238. } else {
  2239. /* Note: The opt_args[OPT_ARG_ORIGINAL_CLID] string value is altered here. */
  2240. ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str,
  2241. &stored_clid.number.str);
  2242. if (!ast_strlen_zero(stored_clid.name.str)) {
  2243. stored_clid.name.valid = 1;
  2244. }
  2245. if (!ast_strlen_zero(stored_clid.number.str)) {
  2246. stored_clid.number.valid = 1;
  2247. }
  2248. }
  2249. } else {
  2250. /*
  2251. * In case the new channel has no preset CallerID number by the
  2252. * channel driver, setup the dialplan extension and hint name.
  2253. */
  2254. stored_clid_name[0] = '\0';
  2255. stored_clid.name.str = (char *) get_cid_name(stored_clid_name,
  2256. sizeof(stored_clid_name), chan);
  2257. if (ast_strlen_zero(stored_clid.name.str)) {
  2258. stored_clid.name.str = NULL;
  2259. } else {
  2260. stored_clid.name.valid = 1;
  2261. }
  2262. ast_channel_lock(chan);
  2263. stored_clid.number.str = ast_strdupa(S_OR(ast_channel_macroexten(chan), ast_channel_exten(chan)));
  2264. stored_clid.number.valid = 1;
  2265. ast_channel_unlock(chan);
  2266. }
  2267. if (ast_test_flag64(&opts, OPT_RESETCDR)) {
  2268. ast_cdr_reset(ast_channel_name(chan), 0);
  2269. }
  2270. if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY]))
  2271. opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan));
  2272. if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) {
  2273. res = setup_privacy_args(&pa, &opts, opt_args, chan);
  2274. if (res <= 0)
  2275. goto out;
  2276. res = -1; /* reset default */
  2277. }
  2278. if (continue_exec)
  2279. *continue_exec = 0;
  2280. /* If a channel group has been specified, get it for use when we create peer channels */
  2281. ast_channel_lock(chan);
  2282. if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) {
  2283. outbound_group = ast_strdupa(outbound_group);
  2284. pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL);
  2285. } else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) {
  2286. outbound_group = ast_strdupa(outbound_group);
  2287. }
  2288. ast_channel_unlock(chan);
  2289. /* Set per dial instance flags. These flags are also passed back to RetryDial. */
  2290. ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID
  2291. | OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_CANCEL_TIMEOUT
  2292. | OPT_ANNOUNCE | OPT_CALLEE_MACRO | OPT_CALLEE_GOSUB | OPT_FORCECLID);
  2293. /* PREDIAL: Run gosub on the caller's channel */
  2294. if (ast_test_flag64(&opts, OPT_PREDIAL_CALLER)
  2295. && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) {
  2296. ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]);
  2297. ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0);
  2298. }
  2299. /* loop through the list of dial destinations */
  2300. rest = args.peers;
  2301. while ((cur = strsep(&rest, "&")) ) {
  2302. struct ast_channel *tc; /* channel for this destination */
  2303. /* Get a technology/resource pair */
  2304. char *number = cur;
  2305. char *tech = strsep(&number, "/");
  2306. size_t tech_len;
  2307. size_t number_len;
  2308. struct ast_format_cap *nativeformats;
  2309. num_dialed++;
  2310. if (ast_strlen_zero(number)) {
  2311. ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n");
  2312. goto out;
  2313. }
  2314. tech_len = strlen(tech) + 1;
  2315. number_len = strlen(number) + 1;
  2316. tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len);
  2317. if (!tmp) {
  2318. goto out;
  2319. }
  2320. /* Save tech, number, and interface. */
  2321. cur = tmp->stuff;
  2322. strcpy(cur, tech);
  2323. tmp->tech = cur;
  2324. cur += tech_len;
  2325. strcpy(cur, tech);
  2326. cur[tech_len - 1] = '/';
  2327. tmp->interface = cur;
  2328. cur += tech_len;
  2329. strcpy(cur, number);
  2330. tmp->number = cur;
  2331. if (opts.flags) {
  2332. /* Set per outgoing call leg options. */
  2333. ast_copy_flags64(tmp, &opts,
  2334. OPT_CANCEL_ELSEWHERE |
  2335. OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER |
  2336. OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP |
  2337. OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
  2338. OPT_CALLEE_PARK | OPT_CALLER_PARK |
  2339. OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR |
  2340. OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID | OPT_IGNORE_CONNECTEDLINE |
  2341. OPT_RING_WITH_EARLY_MEDIA);
  2342. ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML);
  2343. }
  2344. /* Request the peer */
  2345. ast_channel_lock(chan);
  2346. /*
  2347. * Seed the chanlist's connected line information with previously
  2348. * acquired connected line info from the incoming channel. The
  2349. * previously acquired connected line info could have been set
  2350. * through the CONNECTED_LINE dialplan function.
  2351. */
  2352. ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan));
  2353. nativeformats = ao2_bump(ast_channel_nativeformats(chan));
  2354. ast_channel_unlock(chan);
  2355. tc = ast_request(tmp->tech, nativeformats, NULL, chan, tmp->number, &cause);
  2356. ao2_cleanup(nativeformats);
  2357. if (!tc) {
  2358. /* If we can't, just go on to the next call */
  2359. ast_log(LOG_WARNING, "Unable to create channel of type '%s' (cause %d - %s)\n",
  2360. tmp->tech, cause, ast_cause2str(cause));
  2361. handle_cause(cause, &num);
  2362. if (!rest) {
  2363. /* we are on the last destination */
  2364. ast_channel_hangupcause_set(chan, cause);
  2365. }
  2366. if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) {
  2367. if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) {
  2368. ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, "");
  2369. }
  2370. }
  2371. chanlist_free(tmp);
  2372. continue;
  2373. }
  2374. ast_channel_get_device_name(tc, device_name, sizeof(device_name));
  2375. if (!ignore_cc) {
  2376. ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
  2377. }
  2378. ast_channel_lock_both(tc, chan);
  2379. ast_channel_stage_snapshot(tc);
  2380. pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
  2381. /* Setup outgoing SDP to match incoming one */
  2382. if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
  2383. /* We are on the only destination. */
  2384. ast_rtp_instance_early_bridge_make_compatible(tc, chan);
  2385. }
  2386. /* Inherit specially named variables from parent channel */
  2387. ast_channel_inherit_variables(chan, tc);
  2388. ast_channel_datastore_inherit(chan, tc);
  2389. ast_max_forwards_decrement(tc);
  2390. ast_channel_appl_set(tc, "AppDial");
  2391. ast_channel_data_set(tc, "(Outgoing Line)");
  2392. memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc)));
  2393. /* Determine CallerID to store in outgoing channel. */
  2394. ast_party_caller_set_init(&caller, ast_channel_caller(tc));
  2395. if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) {
  2396. caller.id = stored_clid;
  2397. ast_channel_set_caller_event(tc, &caller, NULL);
  2398. ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
  2399. } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid,
  2400. ast_channel_caller(tc)->id.number.str, NULL))) {
  2401. /*
  2402. * The new channel has no preset CallerID number by the channel
  2403. * driver. Use the dialplan extension and hint name.
  2404. */
  2405. caller.id = stored_clid;
  2406. if (!caller.id.name.valid
  2407. && !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
  2408. ast_channel_connected(chan)->id.name.str, NULL))) {
  2409. /*
  2410. * No hint name available. We have a connected name supplied by
  2411. * the dialplan we can use instead.
  2412. */
  2413. caller.id.name.valid = 1;
  2414. caller.id.name = ast_channel_connected(chan)->id.name;
  2415. }
  2416. ast_channel_set_caller_event(tc, &caller, NULL);
  2417. ast_set_flag64(tmp, DIAL_CALLERID_ABSENT);
  2418. } else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str,
  2419. NULL))) {
  2420. /* The new channel has no preset CallerID name by the channel driver. */
  2421. if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid,
  2422. ast_channel_connected(chan)->id.name.str, NULL))) {
  2423. /*
  2424. * We have a connected name supplied by the dialplan we can
  2425. * use instead.
  2426. */
  2427. caller.id.name.valid = 1;
  2428. caller.id.name = ast_channel_connected(chan)->id.name;
  2429. ast_channel_set_caller_event(tc, &caller, NULL);
  2430. }
  2431. }
  2432. /* Determine CallerID for outgoing channel to send. */
  2433. if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) {
  2434. struct ast_party_connected_line connected;
  2435. ast_party_connected_line_set_init(&connected, ast_channel_connected(tc));
  2436. connected.id = forced_clid;
  2437. ast_channel_set_connected_line(tc, &connected, NULL);
  2438. } else {
  2439. ast_connected_line_copy_from_caller(ast_channel_connected(tc), ast_channel_caller(chan));
  2440. }
  2441. ast_party_redirecting_copy(ast_channel_redirecting(tc), ast_channel_redirecting(chan));
  2442. ast_channel_dialed(tc)->transit_network_select = ast_channel_dialed(chan)->transit_network_select;
  2443. ast_channel_req_accountcodes(tc, chan, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
  2444. if (ast_strlen_zero(ast_channel_musicclass(tc))) {
  2445. ast_channel_musicclass_set(tc, ast_channel_musicclass(chan));
  2446. }
  2447. /* Pass ADSI CPE and transfer capability */
  2448. ast_channel_adsicpe_set(tc, ast_channel_adsicpe(chan));
  2449. ast_channel_transfercapability_set(tc, ast_channel_transfercapability(chan));
  2450. /* If we have an outbound group, set this peer channel to it */
  2451. if (outbound_group)
  2452. ast_app_group_set_channel(tc, outbound_group);
  2453. /* If the calling channel has the ANSWERED_ELSEWHERE flag set, inherit it. This is to support local channels */
  2454. if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE)
  2455. ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
  2456. /* Check if we're forced by configuration */
  2457. if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE))
  2458. ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE);
  2459. /* Inherit context and extension */
  2460. ast_channel_dialcontext_set(tc, ast_strlen_zero(ast_channel_macrocontext(chan)) ? ast_channel_context(chan) : ast_channel_macrocontext(chan));
  2461. if (!ast_strlen_zero(ast_channel_macroexten(chan)))
  2462. ast_channel_exten_set(tc, ast_channel_macroexten(chan));
  2463. else
  2464. ast_channel_exten_set(tc, ast_channel_exten(chan));
  2465. ast_channel_stage_snapshot_done(tc);
  2466. /* Save the original channel name to detect call pickup masquerading in. */
  2467. tmp->orig_chan_name = ast_strdup(ast_channel_name(tc));
  2468. ast_channel_unlock(tc);
  2469. ast_channel_unlock(chan);
  2470. /* Put channel in the list of outgoing thingies. */
  2471. tmp->chan = tc;
  2472. AST_LIST_INSERT_TAIL(&out_chans, tmp, node);
  2473. }
  2474. /*
  2475. * PREDIAL: Run gosub on all of the callee channels
  2476. *
  2477. * We run the callee predial before ast_call() in case the user
  2478. * wishes to do something on the newly created channels before
  2479. * the channel does anything important.
  2480. *
  2481. * Inside the target gosub we will be able to do something with
  2482. * the newly created channel name ie: now the calling channel
  2483. * can know what channel will be used to call the destination
  2484. * ex: now we will know that SIP/abc-123 is calling SIP/def-124
  2485. */
  2486. if (ast_test_flag64(&opts, OPT_PREDIAL_CALLEE)
  2487. && !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE])
  2488. && !AST_LIST_EMPTY(&out_chans)) {
  2489. const char *predial_callee;
  2490. ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]);
  2491. predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]);
  2492. if (predial_callee) {
  2493. ast_autoservice_start(chan);
  2494. AST_LIST_TRAVERSE(&out_chans, tmp, node) {
  2495. ast_pre_call(tmp->chan, predial_callee);
  2496. }
  2497. ast_autoservice_stop(chan);
  2498. ast_free((char *) predial_callee);
  2499. }
  2500. }
  2501. /* Start all outgoing calls */
  2502. AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) {
  2503. res = ast_call(tmp->chan, tmp->number, 0); /* Place the call, but don't wait on the answer */
  2504. ast_channel_lock(chan);
  2505. /* check the results of ast_call */
  2506. if (res) {
  2507. /* Again, keep going even if there's an error */
  2508. ast_debug(1, "ast call on peer returned %d\n", res);
  2509. ast_verb(3, "Couldn't call %s\n", tmp->interface);
  2510. if (ast_channel_hangupcause(tmp->chan)) {
  2511. ast_channel_hangupcause_set(chan, ast_channel_hangupcause(tmp->chan));
  2512. }
  2513. ast_channel_unlock(chan);
  2514. ast_cc_call_failed(chan, tmp->chan, tmp->interface);
  2515. ast_hangup(tmp->chan);
  2516. tmp->chan = NULL;
  2517. AST_LIST_REMOVE_CURRENT(node);
  2518. chanlist_free(tmp);
  2519. continue;
  2520. }
  2521. ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL);
  2522. ast_channel_unlock(chan);
  2523. ast_verb(3, "Called %s\n", tmp->interface);
  2524. ast_set_flag64(tmp, DIAL_STILLGOING);
  2525. /* If this line is up, don't try anybody else */
  2526. if (ast_channel_state(tmp->chan) == AST_STATE_UP) {
  2527. break;
  2528. }
  2529. }
  2530. AST_LIST_TRAVERSE_SAFE_END;
  2531. if (ast_strlen_zero(args.timeout)) {
  2532. to = -1;
  2533. } else {
  2534. to = atoi(args.timeout);
  2535. if (to > 0)
  2536. to *= 1000;
  2537. else {
  2538. ast_log(LOG_WARNING, "Invalid timeout specified: '%s'. Setting timeout to infinite\n", args.timeout);
  2539. to = -1;
  2540. }
  2541. }
  2542. outgoing = AST_LIST_FIRST(&out_chans);
  2543. if (!outgoing) {
  2544. strcpy(pa.status, "CHANUNAVAIL");
  2545. if (fulldial == num_dialed) {
  2546. res = -1;
  2547. goto out;
  2548. }
  2549. } else {
  2550. /* Our status will at least be NOANSWER */
  2551. strcpy(pa.status, "NOANSWER");
  2552. if (ast_test_flag64(outgoing, OPT_MUSICBACK)) {
  2553. moh = 1;
  2554. if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) {
  2555. char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
  2556. ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]);
  2557. ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL);
  2558. ast_channel_musicclass_set(chan, original_moh);
  2559. } else {
  2560. ast_moh_start(chan, NULL, NULL);
  2561. }
  2562. ast_indicate(chan, AST_CONTROL_PROGRESS);
  2563. } else if (ast_test_flag64(outgoing, OPT_RINGBACK) || ast_test_flag64(outgoing, OPT_RING_WITH_EARLY_MEDIA)) {
  2564. if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) {
  2565. if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){
  2566. ast_indicate(chan, AST_CONTROL_RINGING);
  2567. sentringing++;
  2568. } else {
  2569. ast_indicate(chan, AST_CONTROL_PROGRESS);
  2570. }
  2571. } else {
  2572. ast_indicate(chan, AST_CONTROL_RINGING);
  2573. sentringing++;
  2574. }
  2575. }
  2576. }
  2577. peer = wait_for_answer(chan, &out_chans, &to, peerflags, opt_args, &pa, &num, &result,
  2578. dtmf_progress, ignore_cc, &forced_clid, &stored_clid);
  2579. if (!peer) {
  2580. if (result) {
  2581. res = result;
  2582. } else if (to) { /* Musta gotten hung up */
  2583. res = -1;
  2584. } else { /* Nobody answered, next please? */
  2585. res = 0;
  2586. }
  2587. } else {
  2588. const char *number;
  2589. const char *name;
  2590. int dial_end_raised = 0;
  2591. int cause = -1;
  2592. if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) {
  2593. ast_answer(chan);
  2594. }
  2595. /* Ah ha! Someone answered within the desired timeframe. Of course after this
  2596. we will always return with -1 so that it is hung up properly after the
  2597. conversation. */
  2598. if (ast_test_flag64(&opts, OPT_HANGUPCAUSE)
  2599. && !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) {
  2600. cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]);
  2601. if (cause <= 0) {
  2602. if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) {
  2603. cause = 0;
  2604. } else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1
  2605. || cause < 0) {
  2606. ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n",
  2607. opt_args[OPT_ARG_HANGUPCAUSE]);
  2608. cause = -1;
  2609. }
  2610. }
  2611. }
  2612. hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE);
  2613. /* If appropriate, log that we have a destination channel and set the answer time */
  2614. ast_channel_lock(peer);
  2615. name = ast_strdupa(ast_channel_name(peer));
  2616. number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER");
  2617. if (ast_strlen_zero(number)) {
  2618. number = NULL;
  2619. } else {
  2620. number = ast_strdupa(number);
  2621. }
  2622. ast_channel_unlock(peer);
  2623. ast_channel_lock(chan);
  2624. ast_channel_stage_snapshot(chan);
  2625. strcpy(pa.status, "ANSWER");
  2626. pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
  2627. pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name);
  2628. pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
  2629. ast_channel_stage_snapshot_done(chan);
  2630. ast_channel_unlock(chan);
  2631. if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
  2632. ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
  2633. ast_channel_sendurl( peer, args.url );
  2634. }
  2635. if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) {
  2636. if (do_privacy(chan, peer, &opts, opt_args, &pa)) {
  2637. ast_channel_publish_dial(chan, peer, NULL, pa.status);
  2638. /* hang up on the callee -- he didn't want to talk anyway! */
  2639. ast_autoservice_chan_hangup_peer(chan, peer);
  2640. res = 0;
  2641. goto out;
  2642. }
  2643. }
  2644. if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) {
  2645. res = 0;
  2646. } else {
  2647. int digit = 0;
  2648. struct ast_channel *chans[2];
  2649. struct ast_channel *active_chan;
  2650. chans[0] = chan;
  2651. chans[1] = peer;
  2652. /* we need to stream the announcement to the called party when the OPT_ARG_ANNOUNCE (-A) is setted */
  2653. /* stream the file */
  2654. res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], ast_channel_language(peer));
  2655. if (res) {
  2656. res = 0;
  2657. ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", opt_args[OPT_ARG_ANNOUNCE]);
  2658. }
  2659. ast_channel_set_flag(peer, AST_FLAG_END_DTMF_ONLY);
  2660. while (ast_channel_stream(peer)) {
  2661. int ms;
  2662. ms = ast_sched_wait(ast_channel_sched(peer));
  2663. if (ms < 0 && !ast_channel_timingfunc(peer)) {
  2664. ast_stopstream(peer);
  2665. break;
  2666. }
  2667. if (ms < 0)
  2668. ms = 1000;
  2669. active_chan = ast_waitfor_n(chans, 2, &ms);
  2670. if (active_chan) {
  2671. struct ast_channel *other_chan;
  2672. struct ast_frame *fr = ast_read(active_chan);
  2673. if (!fr) {
  2674. ast_autoservice_chan_hangup_peer(chan, peer);
  2675. res = -1;
  2676. goto done;
  2677. }
  2678. switch (fr->frametype) {
  2679. case AST_FRAME_DTMF_END:
  2680. digit = fr->subclass.integer;
  2681. if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) {
  2682. ast_stopstream(peer);
  2683. res = ast_senddigit(chan, digit, 0);
  2684. }
  2685. break;
  2686. case AST_FRAME_CONTROL:
  2687. switch (fr->subclass.integer) {
  2688. case AST_CONTROL_HANGUP:
  2689. ast_frfree(fr);
  2690. ast_autoservice_chan_hangup_peer(chan, peer);
  2691. res = -1;
  2692. goto done;
  2693. case AST_CONTROL_CONNECTED_LINE:
  2694. /* Pass COLP update to the other channel. */
  2695. if (active_chan == chan) {
  2696. other_chan = peer;
  2697. } else {
  2698. other_chan = chan;
  2699. }
  2700. if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)
  2701. && ast_channel_connected_line_macro(active_chan,
  2702. other_chan, fr, other_chan == chan, 1)) {
  2703. ast_indicate_data(other_chan, fr->subclass.integer,
  2704. fr->data.ptr, fr->datalen);
  2705. }
  2706. break;
  2707. default:
  2708. break;
  2709. }
  2710. break;
  2711. default:
  2712. /* Ignore all others */
  2713. break;
  2714. }
  2715. ast_frfree(fr);
  2716. }
  2717. ast_sched_runq(ast_channel_sched(peer));
  2718. }
  2719. ast_channel_clear_flag(peer, AST_FLAG_END_DTMF_ONLY);
  2720. }
  2721. if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) {
  2722. /* chan and peer are going into the PBX; as such neither are considered
  2723. * outgoing channels any longer */
  2724. ast_channel_clear_flag(chan, AST_FLAG_OUTGOING);
  2725. ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
  2726. ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
  2727. /* peer goes to the same context and extension as chan, so just copy info from chan*/
  2728. ast_channel_lock(peer);
  2729. ast_channel_stage_snapshot(peer);
  2730. ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
  2731. ast_channel_context_set(peer, ast_channel_context(chan));
  2732. ast_channel_exten_set(peer, ast_channel_exten(chan));
  2733. ast_channel_priority_set(peer, ast_channel_priority(chan) + 2);
  2734. ast_channel_stage_snapshot_done(peer);
  2735. ast_channel_unlock(peer);
  2736. if (ast_pbx_start(peer)) {
  2737. ast_autoservice_chan_hangup_peer(chan, peer);
  2738. }
  2739. if (continue_exec)
  2740. *continue_exec = 1;
  2741. res = 0;
  2742. ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
  2743. goto done;
  2744. }
  2745. if (ast_test_flag64(&opts, OPT_CALLEE_MACRO) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_MACRO])) {
  2746. const char *macro_result_peer;
  2747. int macro_res;
  2748. /* Set peer->exten and peer->context so that MACRO_EXTEN and MACRO_CONTEXT get set */
  2749. ast_channel_lock_both(chan, peer);
  2750. ast_channel_context_set(peer, ast_channel_context(chan));
  2751. ast_channel_exten_set(peer, ast_channel_exten(chan));
  2752. ast_channel_unlock(peer);
  2753. ast_channel_unlock(chan);
  2754. ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_MACRO]);
  2755. macro_res = ast_app_exec_macro(chan, peer, opt_args[OPT_ARG_CALLEE_MACRO]);
  2756. ast_channel_lock(peer);
  2757. if (!macro_res && (macro_result_peer = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
  2758. char *macro_result = ast_strdupa(macro_result_peer);
  2759. char *macro_transfer_dest;
  2760. ast_channel_unlock(peer);
  2761. if (!strcasecmp(macro_result, "BUSY")) {
  2762. ast_copy_string(pa.status, macro_result, sizeof(pa.status));
  2763. ast_set_flag64(peerflags, OPT_GO_ON);
  2764. macro_res = -1;
  2765. } else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
  2766. ast_copy_string(pa.status, macro_result, sizeof(pa.status));
  2767. ast_set_flag64(peerflags, OPT_GO_ON);
  2768. macro_res = -1;
  2769. } else if (!strcasecmp(macro_result, "CONTINUE")) {
  2770. /* hangup peer and keep chan alive assuming the macro has changed
  2771. the context / exten / priority or perhaps
  2772. the next priority in the current exten is desired.
  2773. */
  2774. ast_set_flag64(peerflags, OPT_GO_ON);
  2775. macro_res = -1;
  2776. } else if (!strcasecmp(macro_result, "ABORT")) {
  2777. /* Hangup both ends unless the caller has the g flag */
  2778. macro_res = -1;
  2779. } else if (!strncasecmp(macro_result, "GOTO:", 5)) {
  2780. macro_transfer_dest = macro_result + 5;
  2781. macro_res = -1;
  2782. /* perform a transfer to a new extension */
  2783. if (strchr(macro_transfer_dest, '^')) { /* context^exten^priority*/
  2784. ast_replace_subargument_delimiter(macro_transfer_dest);
  2785. }
  2786. if (!ast_parseable_goto(chan, macro_transfer_dest)) {
  2787. ast_set_flag64(peerflags, OPT_GO_ON);
  2788. }
  2789. }
  2790. if (macro_res && !dial_end_raised) {
  2791. ast_channel_publish_dial(chan, peer, NULL, macro_result);
  2792. dial_end_raised = 1;
  2793. }
  2794. } else {
  2795. ast_channel_unlock(peer);
  2796. }
  2797. res = macro_res;
  2798. }
  2799. if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) {
  2800. const char *gosub_result_peer;
  2801. char *gosub_argstart;
  2802. char *gosub_args = NULL;
  2803. int gosub_res = -1;
  2804. ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]);
  2805. gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ',');
  2806. if (gosub_argstart) {
  2807. const char *what_is_s = "s";
  2808. *gosub_argstart = 0;
  2809. 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)) &&
  2810. 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))) {
  2811. what_is_s = "~~s~~";
  2812. }
  2813. if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) {
  2814. gosub_args = NULL;
  2815. }
  2816. *gosub_argstart = ',';
  2817. } else {
  2818. const char *what_is_s = "s";
  2819. 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)) &&
  2820. 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))) {
  2821. what_is_s = "~~s~~";
  2822. }
  2823. if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) {
  2824. gosub_args = NULL;
  2825. }
  2826. }
  2827. if (gosub_args) {
  2828. gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0);
  2829. ast_free(gosub_args);
  2830. } else {
  2831. ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n");
  2832. }
  2833. ast_channel_lock_both(chan, peer);
  2834. if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) {
  2835. char *gosub_transfer_dest;
  2836. char *gosub_result = ast_strdupa(gosub_result_peer);
  2837. const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL");
  2838. /* Inherit return value from the peer, so it can be used in the master */
  2839. if (gosub_retval) {
  2840. pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval);
  2841. }
  2842. ast_channel_unlock(peer);
  2843. ast_channel_unlock(chan);
  2844. if (!strcasecmp(gosub_result, "BUSY")) {
  2845. ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
  2846. ast_set_flag64(peerflags, OPT_GO_ON);
  2847. gosub_res = -1;
  2848. } else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) {
  2849. ast_copy_string(pa.status, gosub_result, sizeof(pa.status));
  2850. ast_set_flag64(peerflags, OPT_GO_ON);
  2851. gosub_res = -1;
  2852. } else if (!strcasecmp(gosub_result, "CONTINUE")) {
  2853. /* Hangup peer and continue with the next extension priority. */
  2854. ast_set_flag64(peerflags, OPT_GO_ON);
  2855. gosub_res = -1;
  2856. } else if (!strcasecmp(gosub_result, "ABORT")) {
  2857. /* Hangup both ends unless the caller has the g flag */
  2858. gosub_res = -1;
  2859. } else if (!strncasecmp(gosub_result, "GOTO:", 5)) {
  2860. gosub_transfer_dest = gosub_result + 5;
  2861. gosub_res = -1;
  2862. /* perform a transfer to a new extension */
  2863. if (strchr(gosub_transfer_dest, '^')) { /* context^exten^priority*/
  2864. ast_replace_subargument_delimiter(gosub_transfer_dest);
  2865. }
  2866. if (!ast_parseable_goto(chan, gosub_transfer_dest)) {
  2867. ast_set_flag64(peerflags, OPT_GO_ON);
  2868. }
  2869. }
  2870. if (gosub_res) {
  2871. res = gosub_res;
  2872. if (!dial_end_raised) {
  2873. ast_channel_publish_dial(chan, peer, NULL, gosub_result);
  2874. dial_end_raised = 1;
  2875. }
  2876. }
  2877. } else {
  2878. ast_channel_unlock(peer);
  2879. ast_channel_unlock(chan);
  2880. }
  2881. }
  2882. if (!res) {
  2883. /* None of the Dial options changed our status; inform
  2884. * everyone that this channel answered
  2885. */
  2886. if (!dial_end_raised) {
  2887. ast_channel_publish_dial(chan, peer, NULL, "ANSWER");
  2888. dial_end_raised = 1;
  2889. }
  2890. if (!ast_tvzero(calldurationlimit)) {
  2891. struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
  2892. ast_channel_lock(peer);
  2893. ast_channel_whentohangup_set(peer, &whentohangup);
  2894. ast_channel_unlock(peer);
  2895. }
  2896. if (!ast_strlen_zero(dtmfcalled)) {
  2897. ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);
  2898. res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0);
  2899. }
  2900. if (!ast_strlen_zero(dtmfcalling)) {
  2901. ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling);
  2902. res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0);
  2903. }
  2904. }
  2905. if (res) { /* some error */
  2906. if (!ast_check_hangup(chan) && ast_check_hangup(peer)) {
  2907. ast_channel_hangupcause_set(chan, ast_channel_hangupcause(peer));
  2908. }
  2909. setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
  2910. if (ast_bridge_setup_after_goto(peer)
  2911. || ast_pbx_start(peer)) {
  2912. ast_autoservice_chan_hangup_peer(chan, peer);
  2913. }
  2914. res = -1;
  2915. } else {
  2916. if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER))
  2917. ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT);
  2918. if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER))
  2919. ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT);
  2920. if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP))
  2921. ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT);
  2922. if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP))
  2923. ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
  2924. if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR))
  2925. ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
  2926. if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR))
  2927. ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
  2928. if (ast_test_flag64(peerflags, OPT_CALLEE_PARK))
  2929. ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
  2930. if (ast_test_flag64(peerflags, OPT_CALLER_PARK))
  2931. ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL);
  2932. if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR))
  2933. ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON);
  2934. if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR))
  2935. ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON);
  2936. config.end_bridge_callback = end_bridge_callback;
  2937. config.end_bridge_callback_data = chan;
  2938. config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup;
  2939. if (moh) {
  2940. moh = 0;
  2941. ast_moh_stop(chan);
  2942. } else if (sentringing) {
  2943. sentringing = 0;
  2944. ast_indicate(chan, -1);
  2945. }
  2946. /* Be sure no generators are left on it and reset the visible indication */
  2947. ast_deactivate_generator(chan);
  2948. ast_channel_visible_indication_set(chan, 0);
  2949. /* Make sure channels are compatible */
  2950. res = ast_channel_make_compatible(chan, peer);
  2951. if (res < 0) {
  2952. 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));
  2953. ast_autoservice_chan_hangup_peer(chan, peer);
  2954. res = -1;
  2955. goto done;
  2956. }
  2957. if (opermode) {
  2958. struct oprmode oprmode;
  2959. oprmode.peer = peer;
  2960. oprmode.mode = opermode;
  2961. ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0);
  2962. }
  2963. setup_peer_after_bridge_goto(chan, peer, &opts, opt_args);
  2964. res = ast_bridge_call(chan, peer, &config);
  2965. }
  2966. }
  2967. out:
  2968. if (moh) {
  2969. moh = 0;
  2970. ast_moh_stop(chan);
  2971. } else if (sentringing) {
  2972. sentringing = 0;
  2973. ast_indicate(chan, -1);
  2974. }
  2975. if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) {
  2976. ast_filedelete(pa.privintro, NULL);
  2977. if (ast_fileexists(pa.privintro, NULL, NULL) > 0) {
  2978. ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro);
  2979. } else {
  2980. ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro);
  2981. }
  2982. }
  2983. ast_channel_early_bridge(chan, NULL);
  2984. /* forward 'answered elsewhere' if we received it */
  2985. hanguptree(&out_chans, NULL,
  2986. ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE
  2987. || ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE)
  2988. ? AST_CAUSE_ANSWERED_ELSEWHERE : -1);
  2989. pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status);
  2990. ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status);
  2991. if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) {
  2992. if (!ast_tvzero(calldurationlimit))
  2993. memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan)));
  2994. res = 0;
  2995. }
  2996. done:
  2997. if (config.warning_sound) {
  2998. ast_free((char *)config.warning_sound);
  2999. }
  3000. if (config.end_sound) {
  3001. ast_free((char *)config.end_sound);
  3002. }
  3003. if (config.start_sound) {
  3004. ast_free((char *)config.start_sound);
  3005. }
  3006. ast_ignore_cc(chan);
  3007. return res;
  3008. }
  3009. static int dial_exec(struct ast_channel *chan, const char *data)
  3010. {
  3011. struct ast_flags64 peerflags;
  3012. memset(&peerflags, 0, sizeof(peerflags));
  3013. return dial_exec_full(chan, data, &peerflags, NULL);
  3014. }
  3015. static int retrydial_exec(struct ast_channel *chan, const char *data)
  3016. {
  3017. char *parse;
  3018. const char *context = NULL;
  3019. int sleepms = 0, loops = 0, res = -1;
  3020. struct ast_flags64 peerflags = { 0, };
  3021. AST_DECLARE_APP_ARGS(args,
  3022. AST_APP_ARG(announce);
  3023. AST_APP_ARG(sleep);
  3024. AST_APP_ARG(retries);
  3025. AST_APP_ARG(dialdata);
  3026. );
  3027. if (ast_strlen_zero(data)) {
  3028. ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
  3029. return -1;
  3030. }
  3031. parse = ast_strdupa(data);
  3032. AST_STANDARD_APP_ARGS(args, parse);
  3033. if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep)))
  3034. sleepms *= 1000;
  3035. if (!ast_strlen_zero(args.retries)) {
  3036. loops = atoi(args.retries);
  3037. }
  3038. if (!args.dialdata) {
  3039. ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp);
  3040. goto done;
  3041. }
  3042. if (sleepms < 1000)
  3043. sleepms = 10000;
  3044. if (!loops)
  3045. loops = -1; /* run forever */
  3046. ast_channel_lock(chan);
  3047. context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
  3048. context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL;
  3049. ast_channel_unlock(chan);
  3050. res = 0;
  3051. while (loops) {
  3052. int continue_exec;
  3053. ast_channel_data_set(chan, "Retrying");
  3054. if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
  3055. ast_moh_stop(chan);
  3056. res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec);
  3057. if (continue_exec)
  3058. break;
  3059. if (res == 0) {
  3060. if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) {
  3061. if (!ast_strlen_zero(args.announce)) {
  3062. if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
  3063. if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
  3064. ast_waitstream(chan, AST_DIGIT_ANY);
  3065. } else
  3066. ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
  3067. }
  3068. if (!res && sleepms) {
  3069. if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
  3070. ast_moh_start(chan, NULL, NULL);
  3071. res = ast_waitfordigit(chan, sleepms);
  3072. }
  3073. } else {
  3074. if (!ast_strlen_zero(args.announce)) {
  3075. if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) {
  3076. if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan))))
  3077. res = ast_waitstream(chan, "");
  3078. } else
  3079. ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce);
  3080. }
  3081. if (sleepms) {
  3082. if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
  3083. ast_moh_start(chan, NULL, NULL);
  3084. if (!res)
  3085. res = ast_waitfordigit(chan, sleepms);
  3086. }
  3087. }
  3088. }
  3089. if (res < 0 || res == AST_PBX_INCOMPLETE) {
  3090. break;
  3091. } else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */
  3092. if (onedigit_goto(chan, context, (char) res, 1)) {
  3093. res = 0;
  3094. break;
  3095. }
  3096. }
  3097. loops--;
  3098. }
  3099. if (loops == 0)
  3100. res = 0;
  3101. else if (res == 1)
  3102. res = 0;
  3103. if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH))
  3104. ast_moh_stop(chan);
  3105. done:
  3106. return res;
  3107. }
  3108. static int unload_module(void)
  3109. {
  3110. int res;
  3111. res = ast_unregister_application(app);
  3112. res |= ast_unregister_application(rapp);
  3113. return res;
  3114. }
  3115. static int load_module(void)
  3116. {
  3117. int res;
  3118. res = ast_register_application_xml(app, dial_exec);
  3119. res |= ast_register_application_xml(rapp, retrydial_exec);
  3120. return res;
  3121. }
  3122. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Dialing Application");