pbx_builtins.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2015 Fairview 5 Engineering, LLC
  5. *
  6. * George Joseph <george.joseph@fairview5.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 Core PBX builtin routines.
  21. *
  22. * \author George Joseph <george.joseph@fairview5.com>
  23. */
  24. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_REGISTER_FILE()
  29. #include "asterisk/_private.h"
  30. #include "asterisk/pbx.h"
  31. #include "asterisk/causes.h"
  32. #include "asterisk/indications.h"
  33. #include "asterisk/stasis_channels.h"
  34. #include "asterisk/say.h"
  35. #include "asterisk/app.h"
  36. #include "asterisk/module.h"
  37. #include "pbx_private.h"
  38. /*** DOCUMENTATION
  39. <application name="Answer" language="en_US">
  40. <synopsis>
  41. Answer a channel if ringing.
  42. </synopsis>
  43. <syntax>
  44. <parameter name="delay">
  45. <para>Asterisk will wait this number of milliseconds before returning to
  46. the dialplan after answering the call.</para>
  47. </parameter>
  48. </syntax>
  49. <description>
  50. <para>If the call has not been answered, this application will
  51. answer it. Otherwise, it has no effect on the call.</para>
  52. </description>
  53. <see-also>
  54. <ref type="application">Hangup</ref>
  55. </see-also>
  56. </application>
  57. <application name="BackGround" language="en_US">
  58. <synopsis>
  59. Play an audio file while waiting for digits of an extension to go to.
  60. </synopsis>
  61. <syntax>
  62. <parameter name="filenames" required="true" argsep="&amp;">
  63. <argument name="filename1" required="true" />
  64. <argument name="filename2" multiple="true" />
  65. </parameter>
  66. <parameter name="options">
  67. <optionlist>
  68. <option name="s">
  69. <para>Causes the playback of the message to be skipped
  70. if the channel is not in the <literal>up</literal> state (i.e. it
  71. hasn't been answered yet). If this happens, the
  72. application will return immediately.</para>
  73. </option>
  74. <option name="n">
  75. <para>Don't answer the channel before playing the files.</para>
  76. </option>
  77. <option name="m">
  78. <para>Only break if a digit hit matches a one digit
  79. extension in the destination context.</para>
  80. </option>
  81. </optionlist>
  82. </parameter>
  83. <parameter name="langoverride">
  84. <para>Explicitly specifies which language to attempt to use for the requested sound files.</para>
  85. </parameter>
  86. <parameter name="context">
  87. <para>This is the dialplan context that this application will use when exiting
  88. to a dialed extension.</para>
  89. </parameter>
  90. </syntax>
  91. <description>
  92. <para>This application will play the given list of files <emphasis>(do not put extension)</emphasis>
  93. while waiting for an extension to be dialed by the calling channel. To continue waiting
  94. for digits after this application has finished playing files, the <literal>WaitExten</literal>
  95. application should be used.</para>
  96. <para>If one of the requested sound files does not exist, call processing will be terminated.</para>
  97. <para>This application sets the following channel variable upon completion:</para>
  98. <variablelist>
  99. <variable name="BACKGROUNDSTATUS">
  100. <para>The status of the background attempt as a text string.</para>
  101. <value name="SUCCESS" />
  102. <value name="FAILED" />
  103. </variable>
  104. </variablelist>
  105. </description>
  106. <see-also>
  107. <ref type="application">ControlPlayback</ref>
  108. <ref type="application">WaitExten</ref>
  109. <ref type="application">BackgroundDetect</ref>
  110. <ref type="function">TIMEOUT</ref>
  111. </see-also>
  112. </application>
  113. <application name="Busy" language="en_US">
  114. <synopsis>
  115. Indicate the Busy condition.
  116. </synopsis>
  117. <syntax>
  118. <parameter name="timeout">
  119. <para>If specified, the calling channel will be hung up after the specified number of seconds.
  120. Otherwise, this application will wait until the calling channel hangs up.</para>
  121. </parameter>
  122. </syntax>
  123. <description>
  124. <para>This application will indicate the busy condition to the calling channel.</para>
  125. </description>
  126. <see-also>
  127. <ref type="application">Congestion</ref>
  128. <ref type="application">Progress</ref>
  129. <ref type="application">Playtones</ref>
  130. <ref type="application">Hangup</ref>
  131. </see-also>
  132. </application>
  133. <application name="Congestion" language="en_US">
  134. <synopsis>
  135. Indicate the Congestion condition.
  136. </synopsis>
  137. <syntax>
  138. <parameter name="timeout">
  139. <para>If specified, the calling channel will be hung up after the specified number of seconds.
  140. Otherwise, this application will wait until the calling channel hangs up.</para>
  141. </parameter>
  142. </syntax>
  143. <description>
  144. <para>This application will indicate the congestion condition to the calling channel.</para>
  145. </description>
  146. <see-also>
  147. <ref type="application">Busy</ref>
  148. <ref type="application">Progress</ref>
  149. <ref type="application">Playtones</ref>
  150. <ref type="application">Hangup</ref>
  151. </see-also>
  152. </application>
  153. <application name="ExecIfTime" language="en_US">
  154. <synopsis>
  155. Conditional application execution based on the current time.
  156. </synopsis>
  157. <syntax argsep="?">
  158. <parameter name="day_condition" required="true">
  159. <argument name="times" required="true" />
  160. <argument name="weekdays" required="true" />
  161. <argument name="mdays" required="true" />
  162. <argument name="months" required="true" />
  163. <argument name="timezone" required="false" />
  164. </parameter>
  165. <parameter name="appname" required="true" hasparams="optional">
  166. <argument name="appargs" required="true" />
  167. </parameter>
  168. </syntax>
  169. <description>
  170. <para>This application will execute the specified dialplan application, with optional
  171. arguments, if the current time matches the given time specification.</para>
  172. </description>
  173. <see-also>
  174. <ref type="application">Exec</ref>
  175. <ref type="application">ExecIf</ref>
  176. <ref type="application">TryExec</ref>
  177. <ref type="application">GotoIfTime</ref>
  178. </see-also>
  179. </application>
  180. <application name="Goto" language="en_US">
  181. <synopsis>
  182. Jump to a particular priority, extension, or context.
  183. </synopsis>
  184. <syntax>
  185. <parameter name="context" />
  186. <parameter name="extensions" />
  187. <parameter name="priority" required="true" />
  188. </syntax>
  189. <description>
  190. <para>This application will set the current context, extension, and priority in the channel structure.
  191. After it completes, the pbx engine will continue dialplan execution at the specified location.
  192. If no specific <replaceable>extension</replaceable>, or <replaceable>extension</replaceable> and
  193. <replaceable>context</replaceable>, are specified, then this application will
  194. just set the specified <replaceable>priority</replaceable> of the current extension.</para>
  195. <para>At least a <replaceable>priority</replaceable> is required as an argument, or the goto will
  196. return a <literal>-1</literal>, and the channel and call will be terminated.</para>
  197. <para>If the location that is put into the channel information is bogus, and asterisk cannot
  198. find that location in the dialplan, then the execution engine will try to find and execute the code in
  199. the <literal>i</literal> (invalid) extension in the current context. If that does not exist, it will try to execute the
  200. <literal>h</literal> extension. If neither the <literal>h</literal> nor <literal>i</literal> extensions
  201. have been defined, the channel is hung up, and the execution of instructions on the channel is terminated.
  202. What this means is that, for example, you specify a context that does not exist, then
  203. it will not be possible to find the <literal>h</literal> or <literal>i</literal> extensions,
  204. and the call will terminate!</para>
  205. </description>
  206. <see-also>
  207. <ref type="application">GotoIf</ref>
  208. <ref type="application">GotoIfTime</ref>
  209. <ref type="application">Gosub</ref>
  210. <ref type="application">Macro</ref>
  211. </see-also>
  212. </application>
  213. <application name="GotoIf" language="en_US">
  214. <synopsis>
  215. Conditional goto.
  216. </synopsis>
  217. <syntax argsep="?">
  218. <parameter name="condition" required="true" />
  219. <parameter name="destination" required="true" argsep=":">
  220. <argument name="labeliftrue">
  221. <para>Continue at <replaceable>labeliftrue</replaceable> if the condition is true.
  222. Takes the form similar to Goto() of [[context,]extension,]priority.</para>
  223. </argument>
  224. <argument name="labeliffalse">
  225. <para>Continue at <replaceable>labeliffalse</replaceable> if the condition is false.
  226. Takes the form similar to Goto() of [[context,]extension,]priority.</para>
  227. </argument>
  228. </parameter>
  229. </syntax>
  230. <description>
  231. <para>This application will set the current context, extension, and priority in the channel structure
  232. based on the evaluation of the given condition. After this application completes, the
  233. pbx engine will continue dialplan execution at the specified location in the dialplan.
  234. The labels are specified with the same syntax as used within the Goto application.
  235. If the label chosen by the condition is omitted, no jump is performed, and the execution passes to the
  236. next instruction. If the target location is bogus, and does not exist, the execution engine will try
  237. to find and execute the code in the <literal>i</literal> (invalid) extension in the current context.
  238. If that does not exist, it will try to execute the <literal>h</literal> extension.
  239. If neither the <literal>h</literal> nor <literal>i</literal> extensions have been defined,
  240. the channel is hung up, and the execution of instructions on the channel is terminated.
  241. Remember that this command can set the current context, and if the context specified
  242. does not exist, then it will not be able to find any 'h' or 'i' extensions there, and
  243. the channel and call will both be terminated!.</para>
  244. </description>
  245. <see-also>
  246. <ref type="application">Goto</ref>
  247. <ref type="application">GotoIfTime</ref>
  248. <ref type="application">GosubIf</ref>
  249. <ref type="application">MacroIf</ref>
  250. </see-also>
  251. </application>
  252. <application name="GotoIfTime" language="en_US">
  253. <synopsis>
  254. Conditional Goto based on the current time.
  255. </synopsis>
  256. <syntax argsep="?">
  257. <parameter name="condition" required="true">
  258. <argument name="times" required="true" />
  259. <argument name="weekdays" required="true" />
  260. <argument name="mdays" required="true" />
  261. <argument name="months" required="true" />
  262. <argument name="timezone" required="false" />
  263. </parameter>
  264. <parameter name="destination" required="true" argsep=":">
  265. <argument name="labeliftrue">
  266. <para>Continue at <replaceable>labeliftrue</replaceable> if the condition is true.
  267. Takes the form similar to Goto() of [[context,]extension,]priority.</para>
  268. </argument>
  269. <argument name="labeliffalse">
  270. <para>Continue at <replaceable>labeliffalse</replaceable> if the condition is false.
  271. Takes the form similar to Goto() of [[context,]extension,]priority.</para>
  272. </argument>
  273. </parameter>
  274. </syntax>
  275. <description>
  276. <para>This application will set the context, extension, and priority in the channel structure
  277. based on the evaluation of the given time specification. After this application completes,
  278. the pbx engine will continue dialplan execution at the specified location in the dialplan.
  279. If the current time is within the given time specification, the channel will continue at
  280. <replaceable>labeliftrue</replaceable>. Otherwise the channel will continue at <replaceable>labeliffalse</replaceable>.
  281. If the label chosen by the condition is omitted, no jump is performed, and execution passes to the next
  282. instruction. If the target jump location is bogus, the same actions would be taken as for <literal>Goto</literal>.
  283. Further information on the time specification can be found in examples
  284. illustrating how to do time-based context includes in the dialplan.</para>
  285. </description>
  286. <see-also>
  287. <ref type="application">GotoIf</ref>
  288. <ref type="application">Goto</ref>
  289. <ref type="function">IFTIME</ref>
  290. <ref type="function">TESTTIME</ref>
  291. </see-also>
  292. </application>
  293. <application name="ImportVar" language="en_US">
  294. <synopsis>
  295. Import a variable from a channel into a new variable.
  296. </synopsis>
  297. <syntax argsep="=">
  298. <parameter name="newvar" required="true" />
  299. <parameter name="vardata" required="true">
  300. <argument name="channelname" required="true" />
  301. <argument name="variable" required="true" />
  302. </parameter>
  303. </syntax>
  304. <description>
  305. <para>This application imports a <replaceable>variable</replaceable> from the specified
  306. <replaceable>channel</replaceable> (as opposed to the current one) and stores it as a variable
  307. (<replaceable>newvar</replaceable>) in the current channel (the channel that is calling this
  308. application). Variables created by this application have the same inheritance properties as those
  309. created with the <literal>Set</literal> application.</para>
  310. </description>
  311. <see-also>
  312. <ref type="application">Set</ref>
  313. </see-also>
  314. </application>
  315. <application name="Hangup" language="en_US">
  316. <synopsis>
  317. Hang up the calling channel.
  318. </synopsis>
  319. <syntax>
  320. <parameter name="causecode">
  321. <para>If a <replaceable>causecode</replaceable> is given the channel's
  322. hangup cause will be set to the given value.</para>
  323. </parameter>
  324. </syntax>
  325. <description>
  326. <para>This application will hang up the calling channel.</para>
  327. </description>
  328. <see-also>
  329. <ref type="application">Answer</ref>
  330. <ref type="application">Busy</ref>
  331. <ref type="application">Congestion</ref>
  332. </see-also>
  333. </application>
  334. <application name="Incomplete" language="en_US">
  335. <synopsis>
  336. Returns AST_PBX_INCOMPLETE value.
  337. </synopsis>
  338. <syntax>
  339. <parameter name="n">
  340. <para>If specified, then Incomplete will not attempt to answer the channel first.</para>
  341. <note><para>Most channel types need to be in Answer state in order to receive DTMF.</para></note>
  342. </parameter>
  343. </syntax>
  344. <description>
  345. <para>Signals the PBX routines that the previous matched extension is incomplete
  346. and that further input should be allowed before matching can be considered
  347. to be complete. Can be used within a pattern match when certain criteria warrants
  348. a longer match.</para>
  349. </description>
  350. </application>
  351. <application name="NoOp" language="en_US">
  352. <synopsis>
  353. Do Nothing (No Operation).
  354. </synopsis>
  355. <syntax>
  356. <parameter name="text">
  357. <para>Any text provided can be viewed at the Asterisk CLI.</para>
  358. </parameter>
  359. </syntax>
  360. <description>
  361. <para>This application does nothing. However, it is useful for debugging purposes.</para>
  362. <para>This method can be used to see the evaluations of variables or functions without having any effect.</para>
  363. </description>
  364. <see-also>
  365. <ref type="application">Verbose</ref>
  366. <ref type="application">Log</ref>
  367. </see-also>
  368. </application>
  369. <application name="Proceeding" language="en_US">
  370. <synopsis>
  371. Indicate proceeding.
  372. </synopsis>
  373. <syntax />
  374. <description>
  375. <para>This application will request that a proceeding message be provided to the calling channel.</para>
  376. </description>
  377. </application>
  378. <application name="Progress" language="en_US">
  379. <synopsis>
  380. Indicate progress.
  381. </synopsis>
  382. <syntax />
  383. <description>
  384. <para>This application will request that in-band progress information be provided to the calling channel.</para>
  385. </description>
  386. <see-also>
  387. <ref type="application">Busy</ref>
  388. <ref type="application">Congestion</ref>
  389. <ref type="application">Ringing</ref>
  390. <ref type="application">Playtones</ref>
  391. </see-also>
  392. </application>
  393. <application name="RaiseException" language="en_US">
  394. <synopsis>
  395. Handle an exceptional condition.
  396. </synopsis>
  397. <syntax>
  398. <parameter name="reason" required="true" />
  399. </syntax>
  400. <description>
  401. <para>This application will jump to the <literal>e</literal> extension in the current context, setting the
  402. dialplan function EXCEPTION(). If the <literal>e</literal> extension does not exist, the call will hangup.</para>
  403. </description>
  404. <see-also>
  405. <ref type="function">Exception</ref>
  406. </see-also>
  407. </application>
  408. <application name="Ringing" language="en_US">
  409. <synopsis>
  410. Indicate ringing tone.
  411. </synopsis>
  412. <syntax />
  413. <description>
  414. <para>This application will request that the channel indicate a ringing tone to the user.</para>
  415. </description>
  416. <see-also>
  417. <ref type="application">Busy</ref>
  418. <ref type="application">Congestion</ref>
  419. <ref type="application">Progress</ref>
  420. <ref type="application">Playtones</ref>
  421. </see-also>
  422. </application>
  423. <application name="SayAlpha" language="en_US">
  424. <synopsis>
  425. Say Alpha.
  426. </synopsis>
  427. <syntax>
  428. <parameter name="string" required="true" />
  429. </syntax>
  430. <description>
  431. <para>This application will play the sounds that correspond to the letters
  432. of the given <replaceable>string</replaceable>. If the channel variable
  433. <variable>SAY_DTMF_INTERRUPT</variable> is set to 'true' (case insensitive),
  434. then this application will react to DTMF in the same way as
  435. <literal>Background</literal>.</para>
  436. </description>
  437. <see-also>
  438. <ref type="application">SayDigits</ref>
  439. <ref type="application">SayNumber</ref>
  440. <ref type="application">SayPhonetic</ref>
  441. <ref type="function">CHANNEL</ref>
  442. </see-also>
  443. </application>
  444. <application name="SayAlphaCase" language="en_US">
  445. <synopsis>
  446. Say Alpha.
  447. </synopsis>
  448. <syntax>
  449. <parameter name="casetype" required="true" >
  450. <enumlist>
  451. <enum name="a">
  452. <para>Case sensitive (all) pronunciation.
  453. (Ex: SayAlphaCase(a,aBc); - lowercase a uppercase b lowercase c).</para>
  454. </enum>
  455. <enum name="l">
  456. <para>Case sensitive (lower) pronunciation.
  457. (Ex: SayAlphaCase(l,aBc); - lowercase a b lowercase c).</para>
  458. </enum>
  459. <enum name="n">
  460. <para>Case insensitive pronunciation. Equivalent to SayAlpha.
  461. (Ex: SayAlphaCase(n,aBc) - a b c).</para>
  462. </enum>
  463. <enum name="u">
  464. <para>Case sensitive (upper) pronunciation.
  465. (Ex: SayAlphaCase(u,aBc); - a uppercase b c).</para>
  466. </enum>
  467. </enumlist>
  468. </parameter>
  469. <parameter name="string" required="true" />
  470. </syntax>
  471. <description>
  472. <para>This application will play the sounds that correspond to the letters of the
  473. given <replaceable>string</replaceable>. Optionally, a <replaceable>casetype</replaceable> may be
  474. specified. This will be used for case-insensitive or case-sensitive pronunciations. If the channel
  475. variable <variable>SAY_DTMF_INTERRUPT</variable> is set to 'true' (case insensitive), then this
  476. application will react to DTMF in the same way as <literal>Background</literal>.</para>
  477. </description>
  478. <see-also>
  479. <ref type="application">SayDigits</ref>
  480. <ref type="application">SayNumber</ref>
  481. <ref type="application">SayPhonetic</ref>
  482. <ref type="application">SayAlpha</ref>
  483. <ref type="function">CHANNEL</ref>
  484. </see-also>
  485. </application>
  486. <application name="SayDigits" language="en_US">
  487. <synopsis>
  488. Say Digits.
  489. </synopsis>
  490. <syntax>
  491. <parameter name="digits" required="true" />
  492. </syntax>
  493. <description>
  494. <para>This application will play the sounds that correspond to the digits of
  495. the given number. This will use the language that is currently set for the channel.
  496. If the channel variable <variable>SAY_DTMF_INTERRUPT</variable> is set to 'true'
  497. (case insensitive), then this application will react to DTMF in the same way as
  498. <literal>Background</literal>.</para>
  499. </description>
  500. <see-also>
  501. <ref type="application">SayAlpha</ref>
  502. <ref type="application">SayNumber</ref>
  503. <ref type="application">SayPhonetic</ref>
  504. <ref type="function">CHANNEL</ref>
  505. </see-also>
  506. </application>
  507. <application name="SayNumber" language="en_US">
  508. <synopsis>
  509. Say Number.
  510. </synopsis>
  511. <syntax>
  512. <parameter name="digits" required="true" />
  513. <parameter name="gender" />
  514. </syntax>
  515. <description>
  516. <para>This application will play the sounds that correspond to the given
  517. <replaceable>digits</replaceable>. Optionally, a <replaceable>gender</replaceable> may be
  518. specified. This will use the language that is currently set for the channel. See the CHANNEL()
  519. function for more information on setting the language for the channel. If the channel variable
  520. <variable>SAY_DTMF_INTERRUPT</variable> is set to 'true' (case insensitive), then this
  521. application will react to DTMF in the same way as <literal>Background</literal>.</para>
  522. </description>
  523. <see-also>
  524. <ref type="application">SayAlpha</ref>
  525. <ref type="application">SayDigits</ref>
  526. <ref type="application">SayPhonetic</ref>
  527. <ref type="function">CHANNEL</ref>
  528. </see-also>
  529. </application>
  530. <application name="SayPhonetic" language="en_US">
  531. <synopsis>
  532. Say Phonetic.
  533. </synopsis>
  534. <syntax>
  535. <parameter name="string" required="true" />
  536. </syntax>
  537. <description>
  538. <para>This application will play the sounds from the phonetic alphabet that correspond to the
  539. letters in the given <replaceable>string</replaceable>. If the channel variable
  540. <variable>SAY_DTMF_INTERRUPT</variable> is set to 'true' (case insensitive), then this
  541. application will react to DTMF in the same way as <literal>Background</literal>.</para>
  542. </description>
  543. <see-also>
  544. <ref type="application">SayAlpha</ref>
  545. <ref type="application">SayDigits</ref>
  546. <ref type="application">SayNumber</ref>
  547. </see-also>
  548. </application>
  549. <application name="SetAMAFlags" language="en_US">
  550. <synopsis>
  551. Set the AMA Flags.
  552. </synopsis>
  553. <syntax>
  554. <parameter name="flag" />
  555. </syntax>
  556. <description>
  557. <para>This application will set the channel's AMA Flags for billing purposes.</para>
  558. <warning><para>This application is deprecated. Please use the CHANNEL function instead.</para></warning>
  559. </description>
  560. <see-also>
  561. <ref type="function">CDR</ref>
  562. <ref type="function">CHANNEL</ref>
  563. </see-also>
  564. </application>
  565. <application name="Wait" language="en_US">
  566. <synopsis>
  567. Waits for some time.
  568. </synopsis>
  569. <syntax>
  570. <parameter name="seconds" required="true">
  571. <para>Can be passed with fractions of a second. For example, <literal>1.5</literal> will ask the
  572. application to wait for 1.5 seconds.</para>
  573. </parameter>
  574. </syntax>
  575. <description>
  576. <para>This application waits for a specified number of <replaceable>seconds</replaceable>.</para>
  577. </description>
  578. </application>
  579. <application name="WaitExten" language="en_US">
  580. <synopsis>
  581. Waits for an extension to be entered.
  582. </synopsis>
  583. <syntax>
  584. <parameter name="seconds">
  585. <para>Can be passed with fractions of a second. For example, <literal>1.5</literal> will ask the
  586. application to wait for 1.5 seconds.</para>
  587. </parameter>
  588. <parameter name="options">
  589. <optionlist>
  590. <option name="m">
  591. <para>Provide music on hold to the caller while waiting for an extension.</para>
  592. <argument name="x">
  593. <para>Specify the class for music on hold. <emphasis>CHANNEL(musicclass) will
  594. be used instead if set</emphasis></para>
  595. </argument>
  596. </option>
  597. </optionlist>
  598. </parameter>
  599. </syntax>
  600. <description>
  601. <para>This application waits for the user to enter a new extension for a specified number
  602. of <replaceable>seconds</replaceable>.</para>
  603. <xi:include xpointer="xpointer(/docs/application[@name='Macro']/description/warning[2])" />
  604. </description>
  605. <see-also>
  606. <ref type="application">Background</ref>
  607. <ref type="function">TIMEOUT</ref>
  608. </see-also>
  609. </application>
  610. ***/
  611. #define BACKGROUND_SKIP (1 << 0)
  612. #define BACKGROUND_NOANSWER (1 << 1)
  613. #define BACKGROUND_MATCHEXTEN (1 << 2)
  614. #define BACKGROUND_PLAYBACK (1 << 3)
  615. AST_APP_OPTIONS(background_opts, {
  616. AST_APP_OPTION('s', BACKGROUND_SKIP),
  617. AST_APP_OPTION('n', BACKGROUND_NOANSWER),
  618. AST_APP_OPTION('m', BACKGROUND_MATCHEXTEN),
  619. AST_APP_OPTION('p', BACKGROUND_PLAYBACK),
  620. });
  621. #define WAITEXTEN_MOH (1 << 0)
  622. #define WAITEXTEN_DIALTONE (1 << 1)
  623. AST_APP_OPTIONS(waitexten_opts, {
  624. AST_APP_OPTION_ARG('m', WAITEXTEN_MOH, 0),
  625. AST_APP_OPTION_ARG('d', WAITEXTEN_DIALTONE, 0),
  626. });
  627. int pbx_builtin_raise_exception(struct ast_channel *chan, const char *reason)
  628. {
  629. /* Priority will become 1, next time through the AUTOLOOP */
  630. return raise_exception(chan, reason, 0);
  631. }
  632. /*!
  633. * \ingroup applications
  634. */
  635. static int pbx_builtin_proceeding(struct ast_channel *chan, const char *data)
  636. {
  637. ast_indicate(chan, AST_CONTROL_PROCEEDING);
  638. return 0;
  639. }
  640. /*!
  641. * \ingroup applications
  642. */
  643. static int pbx_builtin_progress(struct ast_channel *chan, const char *data)
  644. {
  645. ast_indicate(chan, AST_CONTROL_PROGRESS);
  646. return 0;
  647. }
  648. /*!
  649. * \ingroup applications
  650. */
  651. static int pbx_builtin_ringing(struct ast_channel *chan, const char *data)
  652. {
  653. ast_indicate(chan, AST_CONTROL_RINGING);
  654. return 0;
  655. }
  656. /*!
  657. * \ingroup applications
  658. */
  659. int indicate_busy(struct ast_channel *chan, const char *data)
  660. {
  661. ast_indicate(chan, AST_CONTROL_BUSY);
  662. /* Don't change state of an UP channel, just indicate
  663. busy in audio */
  664. ast_channel_lock(chan);
  665. if (ast_channel_state(chan) != AST_STATE_UP) {
  666. ast_channel_hangupcause_set(chan, AST_CAUSE_BUSY);
  667. ast_setstate(chan, AST_STATE_BUSY);
  668. }
  669. ast_channel_unlock(chan);
  670. wait_for_hangup(chan, data);
  671. return -1;
  672. }
  673. /*!
  674. * \ingroup applications
  675. */
  676. int indicate_congestion(struct ast_channel *chan, const char *data)
  677. {
  678. ast_indicate(chan, AST_CONTROL_CONGESTION);
  679. /* Don't change state of an UP channel, just indicate
  680. congestion in audio */
  681. ast_channel_lock(chan);
  682. if (ast_channel_state(chan) != AST_STATE_UP) {
  683. ast_channel_hangupcause_set(chan, AST_CAUSE_CONGESTION);
  684. ast_setstate(chan, AST_STATE_BUSY);
  685. }
  686. ast_channel_unlock(chan);
  687. wait_for_hangup(chan, data);
  688. return -1;
  689. }
  690. /*!
  691. * \ingroup applications
  692. */
  693. static int pbx_builtin_answer(struct ast_channel *chan, const char *data)
  694. {
  695. int delay = 0;
  696. char *parse;
  697. AST_DECLARE_APP_ARGS(args,
  698. AST_APP_ARG(delay);
  699. AST_APP_ARG(answer_cdr);
  700. );
  701. if (ast_strlen_zero(data)) {
  702. return __ast_answer(chan, 0);
  703. }
  704. parse = ast_strdupa(data);
  705. AST_STANDARD_APP_ARGS(args, parse);
  706. if (!ast_strlen_zero(args.delay) && (ast_channel_state(chan) != AST_STATE_UP))
  707. delay = atoi(data);
  708. if (delay < 0) {
  709. delay = 0;
  710. }
  711. if (!ast_strlen_zero(args.answer_cdr) && !strcasecmp(args.answer_cdr, "nocdr")) {
  712. ast_log(AST_LOG_WARNING, "The nocdr option for the Answer application has been removed and is no longer supported.\n");
  713. }
  714. return __ast_answer(chan, delay);
  715. }
  716. static int pbx_builtin_incomplete(struct ast_channel *chan, const char *data)
  717. {
  718. const char *options = data;
  719. int answer = 1;
  720. /* Some channels can receive DTMF in unanswered state; some cannot */
  721. if (!ast_strlen_zero(options) && strchr(options, 'n')) {
  722. answer = 0;
  723. }
  724. /* If the channel is hungup, stop waiting */
  725. if (ast_check_hangup(chan)) {
  726. return -1;
  727. } else if (ast_channel_state(chan) != AST_STATE_UP && answer) {
  728. __ast_answer(chan, 0);
  729. }
  730. ast_indicate(chan, AST_CONTROL_INCOMPLETE);
  731. return AST_PBX_INCOMPLETE;
  732. }
  733. /*!
  734. * \ingroup applications
  735. */
  736. static int pbx_builtin_setamaflags(struct ast_channel *chan, const char *data)
  737. {
  738. ast_log(AST_LOG_WARNING, "The SetAMAFlags application is deprecated. Please use the CHANNEL function instead.\n");
  739. if (ast_strlen_zero(data)) {
  740. ast_log(AST_LOG_WARNING, "No parameter passed to SetAMAFlags\n");
  741. return 0;
  742. }
  743. /* Copy the AMA Flags as specified */
  744. ast_channel_lock(chan);
  745. if (isdigit(data[0])) {
  746. int amaflags;
  747. if (sscanf(data, "%30d", &amaflags) != 1) {
  748. ast_log(AST_LOG_WARNING, "Unable to set AMA flags on channel %s\n", ast_channel_name(chan));
  749. ast_channel_unlock(chan);
  750. return 0;
  751. }
  752. ast_channel_amaflags_set(chan, amaflags);
  753. } else {
  754. ast_channel_amaflags_set(chan, ast_channel_string2amaflag(data));
  755. }
  756. ast_channel_unlock(chan);
  757. return 0;
  758. }
  759. /*!
  760. * \ingroup applications
  761. */
  762. static int pbx_builtin_hangup(struct ast_channel *chan, const char *data)
  763. {
  764. int cause;
  765. ast_set_hangupsource(chan, "dialplan/builtin", 0);
  766. if (!ast_strlen_zero(data)) {
  767. cause = ast_str2cause(data);
  768. if (cause <= 0) {
  769. if (sscanf(data, "%30d", &cause) != 1 || cause <= 0) {
  770. ast_log(LOG_WARNING, "Invalid cause given to Hangup(): \"%s\"\n", data);
  771. cause = 0;
  772. }
  773. }
  774. } else {
  775. cause = 0;
  776. }
  777. ast_channel_lock(chan);
  778. if (cause <= 0) {
  779. cause = ast_channel_hangupcause(chan);
  780. if (cause <= 0) {
  781. cause = AST_CAUSE_NORMAL_CLEARING;
  782. }
  783. }
  784. ast_channel_hangupcause_set(chan, cause);
  785. ast_softhangup_nolock(chan, AST_SOFTHANGUP_EXPLICIT);
  786. ast_channel_unlock(chan);
  787. return -1;
  788. }
  789. /*! Goto
  790. * \ingroup applications
  791. */
  792. static int pbx_builtin_goto(struct ast_channel *chan, const char *data)
  793. {
  794. int res = ast_parseable_goto(chan, data);
  795. if (!res)
  796. ast_verb(3, "Goto (%s,%s,%d)\n", ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan) + 1);
  797. return res;
  798. }
  799. /*!
  800. * \ingroup applications
  801. */
  802. static int pbx_builtin_gotoiftime(struct ast_channel *chan, const char *data)
  803. {
  804. char *s, *ts, *branch1, *branch2, *branch;
  805. struct ast_timing timing;
  806. const char *ctime;
  807. struct timeval tv = ast_tvnow();
  808. long timesecs;
  809. if (!chan) {
  810. ast_log(LOG_WARNING, "GotoIfTime requires a channel on which to operate\n");
  811. return -1;
  812. }
  813. if (ast_strlen_zero(data)) {
  814. ast_log(LOG_WARNING, "GotoIfTime requires an argument:\n <time range>,<days of week>,<days of month>,<months>[,<timezone>]?'labeliftrue':'labeliffalse'\n");
  815. return -1;
  816. }
  817. ts = s = ast_strdupa(data);
  818. ast_channel_lock(chan);
  819. if ((ctime = pbx_builtin_getvar_helper(chan, "TESTTIME")) && sscanf(ctime, "%ld", &timesecs) == 1) {
  820. tv.tv_sec = timesecs;
  821. } else if (ctime) {
  822. ast_log(LOG_WARNING, "Using current time to evaluate\n");
  823. /* Reset when unparseable */
  824. pbx_builtin_setvar_helper(chan, "TESTTIME", NULL);
  825. }
  826. ast_channel_unlock(chan);
  827. /* Separate the Goto path */
  828. strsep(&ts, "?");
  829. branch1 = strsep(&ts,":");
  830. branch2 = strsep(&ts,"");
  831. /* struct ast_include include contained garbage here, fixed by zeroing it on get_timerange */
  832. if (ast_build_timing(&timing, s) && ast_check_timing2(&timing, tv)) {
  833. branch = branch1;
  834. } else {
  835. branch = branch2;
  836. }
  837. ast_destroy_timing(&timing);
  838. if (ast_strlen_zero(branch)) {
  839. ast_debug(1, "Not taking any branch\n");
  840. return 0;
  841. }
  842. return pbx_builtin_goto(chan, branch);
  843. }
  844. /*!
  845. * \ingroup applications
  846. */
  847. static int pbx_builtin_execiftime(struct ast_channel *chan, const char *data)
  848. {
  849. char *s, *appname;
  850. struct ast_timing timing;
  851. struct ast_app *app;
  852. static const char * const usage = "ExecIfTime requires an argument:\n <time range>,<days of week>,<days of month>,<months>[,<timezone>]?<appname>[(<appargs>)]";
  853. if (ast_strlen_zero(data)) {
  854. ast_log(LOG_WARNING, "%s\n", usage);
  855. return -1;
  856. }
  857. appname = ast_strdupa(data);
  858. s = strsep(&appname, "?"); /* Separate the timerange and application name/data */
  859. if (!appname) { /* missing application */
  860. ast_log(LOG_WARNING, "%s\n", usage);
  861. return -1;
  862. }
  863. if (!ast_build_timing(&timing, s)) {
  864. ast_log(LOG_WARNING, "Invalid Time Spec: %s\nCorrect usage: %s\n", s, usage);
  865. ast_destroy_timing(&timing);
  866. return -1;
  867. }
  868. if (!ast_check_timing(&timing)) { /* outside the valid time window, just return */
  869. ast_destroy_timing(&timing);
  870. return 0;
  871. }
  872. ast_destroy_timing(&timing);
  873. /* now split appname(appargs) */
  874. if ((s = strchr(appname, '('))) {
  875. char *e;
  876. *s++ = '\0';
  877. if ((e = strrchr(s, ')')))
  878. *e = '\0';
  879. else
  880. ast_log(LOG_WARNING, "Failed to find closing parenthesis\n");
  881. }
  882. if ((app = pbx_findapp(appname))) {
  883. return pbx_exec(chan, app, S_OR(s, ""));
  884. } else {
  885. ast_log(LOG_WARNING, "Cannot locate application %s\n", appname);
  886. return -1;
  887. }
  888. }
  889. /*!
  890. * \ingroup applications
  891. */
  892. static int pbx_builtin_wait(struct ast_channel *chan, const char *data)
  893. {
  894. int ms;
  895. /* Wait for "n" seconds */
  896. if (!ast_app_parse_timelen(data, &ms, TIMELEN_SECONDS) && ms > 0) {
  897. return ast_safe_sleep(chan, ms);
  898. }
  899. return 0;
  900. }
  901. /*!
  902. * \ingroup applications
  903. */
  904. static int pbx_builtin_waitexten(struct ast_channel *chan, const char *data)
  905. {
  906. int ms, res;
  907. struct ast_flags flags = {0};
  908. char *opts[1] = { NULL };
  909. char *parse;
  910. AST_DECLARE_APP_ARGS(args,
  911. AST_APP_ARG(timeout);
  912. AST_APP_ARG(options);
  913. );
  914. if (!ast_strlen_zero(data)) {
  915. parse = ast_strdupa(data);
  916. AST_STANDARD_APP_ARGS(args, parse);
  917. } else
  918. memset(&args, 0, sizeof(args));
  919. if (args.options)
  920. ast_app_parse_options(waitexten_opts, &flags, opts, args.options);
  921. if (ast_test_flag(&flags, WAITEXTEN_MOH) && !opts[0] ) {
  922. ast_log(LOG_WARNING, "The 'm' option has been specified for WaitExten without a class.\n");
  923. } else if (ast_test_flag(&flags, WAITEXTEN_MOH)) {
  924. ast_indicate_data(chan, AST_CONTROL_HOLD, S_OR(opts[0], NULL),
  925. !ast_strlen_zero(opts[0]) ? strlen(opts[0]) + 1 : 0);
  926. } else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE)) {
  927. struct ast_tone_zone_sound *ts = ast_get_indication_tone(ast_channel_zone(chan), "dial");
  928. if (ts) {
  929. ast_playtones_start(chan, 0, ts->data, 0);
  930. ts = ast_tone_zone_sound_unref(ts);
  931. } else {
  932. ast_tonepair_start(chan, 350, 440, 0, 0);
  933. }
  934. }
  935. /* Wait for "n" seconds */
  936. if (!ast_app_parse_timelen(args.timeout, &ms, TIMELEN_SECONDS) && ms > 0) {
  937. /* Yay! */
  938. } else if (ast_channel_pbx(chan)) {
  939. ms = ast_channel_pbx(chan)->rtimeoutms;
  940. } else {
  941. ms = 10000;
  942. }
  943. res = ast_waitfordigit(chan, ms);
  944. if (!res) {
  945. if (ast_check_hangup(chan)) {
  946. /* Call is hungup for some reason. */
  947. res = -1;
  948. } else if (ast_exists_extension(chan, ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan) + 1,
  949. S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
  950. ast_verb(3, "Timeout on %s, continuing...\n", ast_channel_name(chan));
  951. } else if (ast_exists_extension(chan, ast_channel_context(chan), "t", 1,
  952. S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
  953. ast_verb(3, "Timeout on %s, going to 't'\n", ast_channel_name(chan));
  954. set_ext_pri(chan, "t", 0); /* 0 will become 1, next time through the loop */
  955. } else if (ast_exists_extension(chan, ast_channel_context(chan), "e", 1,
  956. S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
  957. raise_exception(chan, "RESPONSETIMEOUT", 0); /* 0 will become 1, next time through the loop */
  958. } else {
  959. ast_log(LOG_WARNING, "Timeout but no rule 't' or 'e' in context '%s'\n",
  960. ast_channel_context(chan));
  961. res = -1;
  962. }
  963. }
  964. if (ast_test_flag(&flags, WAITEXTEN_MOH))
  965. ast_indicate(chan, AST_CONTROL_UNHOLD);
  966. else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE))
  967. ast_playtones_stop(chan);
  968. return res;
  969. }
  970. /*!
  971. * \ingroup applications
  972. */
  973. static int pbx_builtin_background(struct ast_channel *chan, const char *data)
  974. {
  975. int res = 0;
  976. int mres = 0;
  977. struct ast_flags flags = {0};
  978. char *parse, exten[2] = "";
  979. AST_DECLARE_APP_ARGS(args,
  980. AST_APP_ARG(filename);
  981. AST_APP_ARG(options);
  982. AST_APP_ARG(lang);
  983. AST_APP_ARG(context);
  984. );
  985. if (ast_strlen_zero(data)) {
  986. ast_log(LOG_WARNING, "Background requires an argument (filename)\n");
  987. return -1;
  988. }
  989. parse = ast_strdupa(data);
  990. AST_STANDARD_APP_ARGS(args, parse);
  991. if (ast_strlen_zero(args.lang))
  992. args.lang = (char *)ast_channel_language(chan); /* XXX this is const */
  993. if (ast_strlen_zero(args.context)) {
  994. const char *context;
  995. ast_channel_lock(chan);
  996. if ((context = pbx_builtin_getvar_helper(chan, "MACRO_CONTEXT"))) {
  997. args.context = ast_strdupa(context);
  998. } else {
  999. args.context = ast_strdupa(ast_channel_context(chan));
  1000. }
  1001. ast_channel_unlock(chan);
  1002. }
  1003. if (args.options) {
  1004. if (!strcasecmp(args.options, "skip"))
  1005. flags.flags = BACKGROUND_SKIP;
  1006. else if (!strcasecmp(args.options, "noanswer"))
  1007. flags.flags = BACKGROUND_NOANSWER;
  1008. else
  1009. ast_app_parse_options(background_opts, &flags, NULL, args.options);
  1010. }
  1011. /* Answer if need be */
  1012. if (ast_channel_state(chan) != AST_STATE_UP) {
  1013. if (ast_test_flag(&flags, BACKGROUND_SKIP)) {
  1014. goto done;
  1015. } else if (!ast_test_flag(&flags, BACKGROUND_NOANSWER)) {
  1016. res = ast_answer(chan);
  1017. }
  1018. }
  1019. if (!res) {
  1020. char *back = ast_strip(args.filename);
  1021. char *front;
  1022. ast_stopstream(chan); /* Stop anything playing */
  1023. /* Stream the list of files */
  1024. while (!res && (front = strsep(&back, "&")) ) {
  1025. if ( (res = ast_streamfile(chan, front, args.lang)) ) {
  1026. ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", ast_channel_name(chan), (char*)data);
  1027. res = 0;
  1028. mres = 1;
  1029. break;
  1030. }
  1031. if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) {
  1032. res = ast_waitstream(chan, "");
  1033. } else if (ast_test_flag(&flags, BACKGROUND_MATCHEXTEN)) {
  1034. res = ast_waitstream_exten(chan, args.context);
  1035. } else {
  1036. res = ast_waitstream(chan, AST_DIGIT_ANY);
  1037. }
  1038. ast_stopstream(chan);
  1039. }
  1040. }
  1041. /* If ast_waitstream didn't give us back a digit, there is nothing else to do */
  1042. if (res <= 0) {
  1043. goto done;
  1044. }
  1045. exten[0] = res;
  1046. /*
  1047. * If the single digit DTMF is an extension in the specified context, then
  1048. * go there and signal no DTMF. Otherwise, we should exit with that DTMF.
  1049. * If we're in Macro, we'll exit and seek that DTMF as the beginning of an
  1050. * extension in the Macro's calling context. If we're not in Macro, then
  1051. * we'll simply seek that extension in the calling context. Previously,
  1052. * someone complained about the behavior as it related to the interior of a
  1053. * Gosub routine, and the fix (#14011) inadvertently broke FreePBX
  1054. * (#14940). This change should fix both of these situations, but with the
  1055. * possible incompatibility that if a single digit extension does not exist
  1056. * (but a longer extension COULD have matched), it would have previously
  1057. * gone immediately to the "i" extension, but will now need to wait for a
  1058. * timeout.
  1059. *
  1060. * Later, we had to add a flag to disable this workaround, because AGI
  1061. * users can EXEC Background and reasonably expect that the DTMF code will
  1062. * be returned (see #16434).
  1063. */
  1064. if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS)
  1065. && ast_canmatch_extension(chan, args.context, exten, 1,
  1066. S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))
  1067. && !ast_matchmore_extension(chan, args.context, exten, 1,
  1068. S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
  1069. char buf[2] = { 0, };
  1070. snprintf(buf, sizeof(buf), "%c", res);
  1071. ast_channel_exten_set(chan, buf);
  1072. ast_channel_context_set(chan, args.context);
  1073. ast_channel_priority_set(chan, 0);
  1074. res = 0;
  1075. }
  1076. done:
  1077. pbx_builtin_setvar_helper(chan, "BACKGROUNDSTATUS", mres ? "FAILED" : "SUCCESS");
  1078. return res;
  1079. }
  1080. static int pbx_builtin_noop(struct ast_channel *chan, const char *data)
  1081. {
  1082. return 0;
  1083. }
  1084. static int pbx_builtin_gotoif(struct ast_channel *chan, const char *data)
  1085. {
  1086. char *condition, *branch1, *branch2, *branch;
  1087. char *stringp;
  1088. if (ast_strlen_zero(data)) {
  1089. ast_log(LOG_WARNING, "Ignoring, since there is no variable to check\n");
  1090. return 0;
  1091. }
  1092. stringp = ast_strdupa(data);
  1093. condition = strsep(&stringp,"?");
  1094. branch1 = strsep(&stringp,":");
  1095. branch2 = strsep(&stringp,"");
  1096. branch = pbx_checkcondition(condition) ? branch1 : branch2;
  1097. if (ast_strlen_zero(branch)) {
  1098. ast_debug(1, "Not taking any branch\n");
  1099. return 0;
  1100. }
  1101. return pbx_builtin_goto(chan, branch);
  1102. }
  1103. static int pbx_builtin_saynumber(struct ast_channel *chan, const char *data)
  1104. {
  1105. char tmp[256];
  1106. char *number = tmp;
  1107. int number_val;
  1108. char *options;
  1109. int res;
  1110. int interrupt = 0;
  1111. const char *interrupt_string;
  1112. ast_channel_lock(chan);
  1113. interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
  1114. if (ast_true(interrupt_string)) {
  1115. interrupt = 1;
  1116. }
  1117. ast_channel_unlock(chan);
  1118. if (ast_strlen_zero(data)) {
  1119. ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
  1120. return -1;
  1121. }
  1122. ast_copy_string(tmp, data, sizeof(tmp));
  1123. strsep(&number, ",");
  1124. if (sscanf(tmp, "%d", &number_val) != 1) {
  1125. ast_log(LOG_WARNING, "argument '%s' to SayNumber could not be parsed as a number.\n", tmp);
  1126. return 0;
  1127. }
  1128. options = strsep(&number, ",");
  1129. if (options) {
  1130. if ( strcasecmp(options, "f") && strcasecmp(options, "m") &&
  1131. strcasecmp(options, "c") && strcasecmp(options, "n") ) {
  1132. ast_log(LOG_WARNING, "SayNumber gender option is either 'f', 'm', 'c' or 'n'\n");
  1133. return -1;
  1134. }
  1135. }
  1136. res = ast_say_number(chan, number_val, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), options);
  1137. if (res < 0) {
  1138. ast_log(LOG_WARNING, "We were unable to say the number %s, is it too large?\n", tmp);
  1139. }
  1140. return interrupt ? res : 0;
  1141. }
  1142. static int pbx_builtin_saydigits(struct ast_channel *chan, const char *data)
  1143. {
  1144. int res = 0;
  1145. int interrupt = 0;
  1146. const char *interrupt_string;
  1147. ast_channel_lock(chan);
  1148. interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
  1149. if (ast_true(interrupt_string)) {
  1150. interrupt = 1;
  1151. }
  1152. ast_channel_unlock(chan);
  1153. if (data) {
  1154. res = ast_say_digit_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan));
  1155. }
  1156. return res;
  1157. }
  1158. static int pbx_builtin_saycharacters_case(struct ast_channel *chan, const char *data)
  1159. {
  1160. int res = 0;
  1161. int sensitivity = 0;
  1162. char *parse;
  1163. int interrupt = 0;
  1164. const char *interrupt_string;
  1165. AST_DECLARE_APP_ARGS(args,
  1166. AST_APP_ARG(options);
  1167. AST_APP_ARG(characters);
  1168. );
  1169. ast_channel_lock(chan);
  1170. interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
  1171. if (ast_true(interrupt_string)) {
  1172. interrupt = 1;
  1173. }
  1174. ast_channel_unlock(chan);
  1175. if (ast_strlen_zero(data)) {
  1176. ast_log(LOG_WARNING, "SayAlphaCase requires two arguments (options, characters)\n");
  1177. return 0;
  1178. }
  1179. parse = ast_strdupa(data);
  1180. AST_STANDARD_APP_ARGS(args, parse);
  1181. if (!args.options || strlen(args.options) != 1) {
  1182. ast_log(LOG_WARNING, "SayAlphaCase options are mutually exclusive and required\n");
  1183. return 0;
  1184. }
  1185. switch (args.options[0]) {
  1186. case 'a':
  1187. sensitivity = AST_SAY_CASE_ALL;
  1188. break;
  1189. case 'l':
  1190. sensitivity = AST_SAY_CASE_LOWER;
  1191. break;
  1192. case 'n':
  1193. sensitivity = AST_SAY_CASE_NONE;
  1194. break;
  1195. case 'u':
  1196. sensitivity = AST_SAY_CASE_UPPER;
  1197. break;
  1198. default:
  1199. ast_log(LOG_WARNING, "Invalid option: '%s'\n", args.options);
  1200. return 0;
  1201. }
  1202. res = ast_say_character_str(chan, args.characters, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), sensitivity);
  1203. return res;
  1204. }
  1205. static int pbx_builtin_saycharacters(struct ast_channel *chan, const char *data)
  1206. {
  1207. int res = 0;
  1208. int interrupt = 0;
  1209. const char *interrupt_string;
  1210. ast_channel_lock(chan);
  1211. interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
  1212. if (ast_true(interrupt_string)) {
  1213. interrupt = 1;
  1214. }
  1215. ast_channel_unlock(chan);
  1216. if (data) {
  1217. res = ast_say_character_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), AST_SAY_CASE_NONE);
  1218. }
  1219. return res;
  1220. }
  1221. static int pbx_builtin_sayphonetic(struct ast_channel *chan, const char *data)
  1222. {
  1223. int res = 0;
  1224. int interrupt = 0;
  1225. const char *interrupt_string;
  1226. ast_channel_lock(chan);
  1227. interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
  1228. if (ast_true(interrupt_string)) {
  1229. interrupt = 1;
  1230. }
  1231. ast_channel_unlock(chan);
  1232. if (data)
  1233. res = ast_say_phonetic_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan));
  1234. return res;
  1235. }
  1236. static int pbx_builtin_importvar(struct ast_channel *chan, const char *data)
  1237. {
  1238. char *name;
  1239. char *value;
  1240. char *channel;
  1241. char tmp[VAR_BUF_SIZE];
  1242. static int deprecation_warning = 0;
  1243. if (ast_strlen_zero(data)) {
  1244. ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
  1245. return 0;
  1246. }
  1247. tmp[0] = 0;
  1248. if (!deprecation_warning) {
  1249. ast_log(LOG_WARNING, "ImportVar is deprecated. Please use Set(varname=${IMPORT(channel,variable)}) instead.\n");
  1250. deprecation_warning = 1;
  1251. }
  1252. value = ast_strdupa(data);
  1253. name = strsep(&value,"=");
  1254. channel = strsep(&value,",");
  1255. if (channel && value && name) { /*! \todo XXX should do !ast_strlen_zero(..) of the args ? */
  1256. struct ast_channel *chan2 = ast_channel_get_by_name(channel);
  1257. if (chan2) {
  1258. char *s = ast_alloca(strlen(value) + 4);
  1259. sprintf(s, "${%s}", value);
  1260. pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
  1261. chan2 = ast_channel_unref(chan2);
  1262. }
  1263. pbx_builtin_setvar_helper(chan, name, tmp);
  1264. }
  1265. return(0);
  1266. }
  1267. /*! \brief Declaration of builtin applications */
  1268. struct pbx_builtin {
  1269. char name[AST_MAX_APP];
  1270. int (*execute)(struct ast_channel *chan, const char *data);
  1271. } builtins[] =
  1272. {
  1273. /* These applications are built into the PBX core and do not
  1274. need separate modules */
  1275. { "Answer", pbx_builtin_answer },
  1276. { "BackGround", pbx_builtin_background },
  1277. { "Busy", indicate_busy },
  1278. { "Congestion", indicate_congestion },
  1279. { "ExecIfTime", pbx_builtin_execiftime },
  1280. { "Goto", pbx_builtin_goto },
  1281. { "GotoIf", pbx_builtin_gotoif },
  1282. { "GotoIfTime", pbx_builtin_gotoiftime },
  1283. { "ImportVar", pbx_builtin_importvar },
  1284. { "Hangup", pbx_builtin_hangup },
  1285. { "Incomplete", pbx_builtin_incomplete },
  1286. { "NoOp", pbx_builtin_noop },
  1287. { "Proceeding", pbx_builtin_proceeding },
  1288. { "Progress", pbx_builtin_progress },
  1289. { "RaiseException", pbx_builtin_raise_exception },
  1290. { "Ringing", pbx_builtin_ringing },
  1291. { "SayAlpha", pbx_builtin_saycharacters },
  1292. { "SayAlphaCase", pbx_builtin_saycharacters_case },
  1293. { "SayDigits", pbx_builtin_saydigits },
  1294. { "SayNumber", pbx_builtin_saynumber },
  1295. { "SayPhonetic", pbx_builtin_sayphonetic },
  1296. { "SetAMAFlags", pbx_builtin_setamaflags },
  1297. { "Wait", pbx_builtin_wait },
  1298. { "WaitExten", pbx_builtin_waitexten }
  1299. };
  1300. static void unload_pbx_builtins(void)
  1301. {
  1302. int x;
  1303. /* Unregister builtin applications */
  1304. for (x = 0; x < ARRAY_LEN(builtins); x++) {
  1305. ast_unregister_application(builtins[x].name);
  1306. }
  1307. }
  1308. int load_pbx_builtins(void)
  1309. {
  1310. int x;
  1311. /* Register builtin applications */
  1312. for (x = 0; x < ARRAY_LEN(builtins); x++) {
  1313. if (ast_register_application2(builtins[x].name, builtins[x].execute, NULL, NULL, NULL)) {
  1314. ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
  1315. return -1;
  1316. }
  1317. }
  1318. ast_register_cleanup(unload_pbx_builtins);
  1319. return 0;
  1320. }