func_callerid.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999-2010, Digium, Inc.
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*! \file
  17. *
  18. * \brief Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting)
  19. *
  20. * \ingroup functions
  21. *
  22. * See Also:
  23. * \arg \ref AstCREDITS
  24. */
  25. /*** MODULEINFO
  26. <support_level>core</support_level>
  27. ***/
  28. #include "asterisk.h"
  29. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  30. #include "asterisk/module.h"
  31. #include "asterisk/channel.h"
  32. #include "asterisk/pbx.h"
  33. #include "asterisk/utils.h"
  34. #include "asterisk/app.h"
  35. #include "asterisk/callerid.h"
  36. /*
  37. * The CALLERID(pres) datatype is shorthand for getting/setting the
  38. * combined value of name-pres and num-pres. Some channel drivers
  39. * don't make a distinction, so it makes sense to only use one property
  40. * to get/set it. The same applies to CONNECTEDLINE(pres),
  41. * REDIRECTING(orig-pres), REDIRECTING(from-pres) and REDIRECTING(to-pres).
  42. *
  43. * Do not document the CALLERID(ton) datatype.
  44. * It is an alias for num-plan.
  45. *
  46. * Do not document the CALLERID(ANI-subaddr-...) datatype.
  47. * This is not used.
  48. *
  49. * Do not document the CONNECTEDLINE(source) datatype.
  50. * It has turned out to not be needed. The source value is really
  51. * only useful as a possible tracing aid.
  52. *
  53. * Do not document the CONNECTEDLINE(ton) datatype.
  54. * It is an alias for num-plan.
  55. *
  56. * Do not document the REDIRECTING(pres) datatype.
  57. * It has turned out that the from-pres and to-pres values must be kept
  58. * separate. They represent two different parties and there is a case when
  59. * they are active at the same time. The plain pres option will simply
  60. * live on as a historical relic.
  61. *
  62. * Do not document the REDIRECTING(orig-ton), REDIRECTING(from-ton),
  63. * or REDIRECTING(to-ton) datatypes.
  64. * They are aliases for orig-num-plan, from-num-plan, and to-num-plan
  65. * respectively.
  66. */
  67. /*** DOCUMENTATION
  68. <function name="CALLERID" language="en_US">
  69. <synopsis>
  70. Gets or sets Caller*ID data on the channel.
  71. </synopsis>
  72. <syntax>
  73. <parameter name="datatype" required="true">
  74. <para>The allowable datatypes are:</para>
  75. <enumlist>
  76. <enum name = "all" />
  77. <enum name = "name" />
  78. <enum name = "name-valid" />
  79. <enum name = "name-charset" />
  80. <enum name = "name-pres" />
  81. <enum name = "num" />
  82. <enum name = "num-valid" />
  83. <enum name = "num-plan" />
  84. <enum name = "num-pres" />
  85. <enum name = "pres" />
  86. <enum name = "subaddr" />
  87. <enum name = "subaddr-valid" />
  88. <enum name = "subaddr-type" />
  89. <enum name = "subaddr-odd" />
  90. <enum name = "tag" />
  91. <enum name = "priv-all" />
  92. <enum name = "priv-name" />
  93. <enum name = "priv-name-valid" />
  94. <enum name = "priv-name-charset" />
  95. <enum name = "priv-name-pres" />
  96. <enum name = "priv-num" />
  97. <enum name = "priv-num-valid" />
  98. <enum name = "priv-num-plan" />
  99. <enum name = "priv-num-pres" />
  100. <enum name = "priv-subaddr" />
  101. <enum name = "priv-subaddr-valid" />
  102. <enum name = "priv-subaddr-type" />
  103. <enum name = "priv-subaddr-odd" />
  104. <enum name = "priv-tag" />
  105. <enum name = "ANI-all" />
  106. <enum name = "ANI-name" />
  107. <enum name = "ANI-name-valid" />
  108. <enum name = "ANI-name-charset" />
  109. <enum name = "ANI-name-pres" />
  110. <enum name = "ANI-num" />
  111. <enum name = "ANI-num-valid" />
  112. <enum name = "ANI-num-plan" />
  113. <enum name = "ANI-num-pres" />
  114. <enum name = "ANI-tag" />
  115. <enum name = "RDNIS" />
  116. <enum name = "DNID" />
  117. <enum name = "dnid-num-plan" />
  118. <enum name = "dnid-subaddr" />
  119. <enum name = "dnid-subaddr-valid" />
  120. <enum name = "dnid-subaddr-type" />
  121. <enum name = "dnid-subaddr-odd" />
  122. </enumlist>
  123. </parameter>
  124. <parameter name="CID">
  125. <para>Optional Caller*ID to parse instead of using the Caller*ID from the
  126. channel. This parameter is only optional when reading the Caller*ID.</para>
  127. </parameter>
  128. </syntax>
  129. <description>
  130. <para>Gets or sets Caller*ID data on the channel. Uses channel callerid by
  131. default or optional callerid, if specified.</para>
  132. <para>The <replaceable>pres</replaceable> field gets/sets a combined value
  133. for <replaceable>name-pres</replaceable> and
  134. <replaceable>num-pres</replaceable>.</para>
  135. <para>The allowable values for the <replaceable>name-charset</replaceable>
  136. field are the following:</para>
  137. <enumlist>
  138. <enum name = "unknown"><para>Unknown</para></enum>
  139. <enum name = "iso8859-1"><para>ISO8859-1</para></enum>
  140. <enum name = "withdrawn"><para>Withdrawn</para></enum>
  141. <enum name = "iso8859-2"><para>ISO8859-2</para></enum>
  142. <enum name = "iso8859-3"><para>ISO8859-3</para></enum>
  143. <enum name = "iso8859-4"><para>ISO8859-4</para></enum>
  144. <enum name = "iso8859-5"><para>ISO8859-5</para></enum>
  145. <enum name = "iso8859-7"><para>ISO8859-7</para></enum>
  146. <enum name = "bmp"><para>ISO10646 Bmp String</para></enum>
  147. <enum name = "utf8"><para>ISO10646 UTF-8 String</para></enum>
  148. </enumlist>
  149. </description>
  150. </function>
  151. <function name="CALLERPRES" language="en_US">
  152. <synopsis>
  153. Gets or sets Caller*ID presentation on the channel.
  154. </synopsis>
  155. <syntax />
  156. <description>
  157. <para>Gets or sets Caller*ID presentation on the channel.
  158. This function is deprecated in favor of CALLERID(num-pres)
  159. and CALLERID(name-pres) or CALLERID(pres) to get/set both
  160. at once.
  161. The following values are valid:</para>
  162. <enumlist>
  163. <enum name="allowed_not_screened">
  164. <para>Presentation Allowed, Not Screened.</para>
  165. </enum>
  166. <enum name="allowed_passed_screen">
  167. <para>Presentation Allowed, Passed Screen.</para>
  168. </enum>
  169. <enum name="allowed_failed_screen">
  170. <para>Presentation Allowed, Failed Screen.</para>
  171. </enum>
  172. <enum name="allowed">
  173. <para>Presentation Allowed, Network Number.</para>
  174. </enum>
  175. <enum name="prohib_not_screened">
  176. <para>Presentation Prohibited, Not Screened.</para>
  177. </enum>
  178. <enum name="prohib_passed_screen">
  179. <para>Presentation Prohibited, Passed Screen.</para>
  180. </enum>
  181. <enum name="prohib_failed_screen">
  182. <para>Presentation Prohibited, Failed Screen.</para>
  183. </enum>
  184. <enum name="prohib">
  185. <para>Presentation Prohibited, Network Number.</para>
  186. </enum>
  187. <enum name="unavailable">
  188. <para>Number Unavailable.</para>
  189. </enum>
  190. </enumlist>
  191. </description>
  192. </function>
  193. <function name="CONNECTEDLINE" language="en_US">
  194. <synopsis>
  195. Gets or sets Connected Line data on the channel.
  196. </synopsis>
  197. <syntax>
  198. <parameter name="datatype" required="true">
  199. <para>The allowable datatypes are:</para>
  200. <enumlist>
  201. <enum name = "all" />
  202. <enum name = "name" />
  203. <enum name = "name-valid" />
  204. <enum name = "name-charset" />
  205. <enum name = "name-pres" />
  206. <enum name = "num" />
  207. <enum name = "num-valid" />
  208. <enum name = "num-plan" />
  209. <enum name = "num-pres" />
  210. <enum name = "pres" />
  211. <enum name = "subaddr" />
  212. <enum name = "subaddr-valid" />
  213. <enum name = "subaddr-type" />
  214. <enum name = "subaddr-odd" />
  215. <enum name = "tag" />
  216. <enum name = "priv-all" />
  217. <enum name = "priv-name" />
  218. <enum name = "priv-name-valid" />
  219. <enum name = "priv-name-charset" />
  220. <enum name = "priv-name-pres" />
  221. <enum name = "priv-num" />
  222. <enum name = "priv-num-valid" />
  223. <enum name = "priv-num-plan" />
  224. <enum name = "priv-num-pres" />
  225. <enum name = "priv-subaddr" />
  226. <enum name = "priv-subaddr-valid" />
  227. <enum name = "priv-subaddr-type" />
  228. <enum name = "priv-subaddr-odd" />
  229. <enum name = "priv-tag" />
  230. </enumlist>
  231. </parameter>
  232. <parameter name="i">
  233. <para>If set, this will prevent the channel from sending out protocol
  234. messages because of the value being set</para>
  235. </parameter>
  236. </syntax>
  237. <description>
  238. <para>Gets or sets Connected Line data on the channel.</para>
  239. <para>The <replaceable>pres</replaceable> field gets/sets a combined value
  240. for <replaceable>name-pres</replaceable> and
  241. <replaceable>num-pres</replaceable>.</para>
  242. <para>The allowable values for the <replaceable>name-charset</replaceable>
  243. field are the following:</para>
  244. <enumlist>
  245. <enum name = "unknown"><para>Unknown</para></enum>
  246. <enum name = "iso8859-1"><para>ISO8859-1</para></enum>
  247. <enum name = "withdrawn"><para>Withdrawn</para></enum>
  248. <enum name = "iso8859-2"><para>ISO8859-2</para></enum>
  249. <enum name = "iso8859-3"><para>ISO8859-3</para></enum>
  250. <enum name = "iso8859-4"><para>ISO8859-4</para></enum>
  251. <enum name = "iso8859-5"><para>ISO8859-5</para></enum>
  252. <enum name = "iso8859-7"><para>ISO8859-7</para></enum>
  253. <enum name = "bmp"><para>ISO10646 Bmp String</para></enum>
  254. <enum name = "utf8"><para>ISO10646 UTF-8 String</para></enum>
  255. </enumlist>
  256. </description>
  257. </function>
  258. <function name="REDIRECTING" language="en_US">
  259. <synopsis>
  260. Gets or sets Redirecting data on the channel.
  261. </synopsis>
  262. <syntax>
  263. <parameter name="datatype" required="true">
  264. <para>The allowable datatypes are:</para>
  265. <enumlist>
  266. <enum name = "orig-all" />
  267. <enum name = "orig-name" />
  268. <enum name = "orig-name-valid" />
  269. <enum name = "orig-name-charset" />
  270. <enum name = "orig-name-pres" />
  271. <enum name = "orig-num" />
  272. <enum name = "orig-num-valid" />
  273. <enum name = "orig-num-plan" />
  274. <enum name = "orig-num-pres" />
  275. <enum name = "orig-pres" />
  276. <enum name = "orig-subaddr" />
  277. <enum name = "orig-subaddr-valid" />
  278. <enum name = "orig-subaddr-type" />
  279. <enum name = "orig-subaddr-odd" />
  280. <enum name = "orig-tag" />
  281. <enum name = "orig-reason" />
  282. <enum name = "from-all" />
  283. <enum name = "from-name" />
  284. <enum name = "from-name-valid" />
  285. <enum name = "from-name-charset" />
  286. <enum name = "from-name-pres" />
  287. <enum name = "from-num" />
  288. <enum name = "from-num-valid" />
  289. <enum name = "from-num-plan" />
  290. <enum name = "from-num-pres" />
  291. <enum name = "from-pres" />
  292. <enum name = "from-subaddr" />
  293. <enum name = "from-subaddr-valid" />
  294. <enum name = "from-subaddr-type" />
  295. <enum name = "from-subaddr-odd" />
  296. <enum name = "from-tag" />
  297. <enum name = "to-all" />
  298. <enum name = "to-name" />
  299. <enum name = "to-name-valid" />
  300. <enum name = "to-name-charset" />
  301. <enum name = "to-name-pres" />
  302. <enum name = "to-num" />
  303. <enum name = "to-num-valid" />
  304. <enum name = "to-num-plan" />
  305. <enum name = "to-num-pres" />
  306. <enum name = "to-pres" />
  307. <enum name = "to-subaddr" />
  308. <enum name = "to-subaddr-valid" />
  309. <enum name = "to-subaddr-type" />
  310. <enum name = "to-subaddr-odd" />
  311. <enum name = "to-tag" />
  312. <enum name = "priv-orig-all" />
  313. <enum name = "priv-orig-name" />
  314. <enum name = "priv-orig-name-valid" />
  315. <enum name = "priv-orig-name-charset" />
  316. <enum name = "priv-orig-name-pres" />
  317. <enum name = "priv-orig-num" />
  318. <enum name = "priv-orig-num-valid" />
  319. <enum name = "priv-orig-num-plan" />
  320. <enum name = "priv-orig-num-pres" />
  321. <enum name = "priv-orig-subaddr" />
  322. <enum name = "priv-orig-subaddr-valid" />
  323. <enum name = "priv-orig-subaddr-type" />
  324. <enum name = "priv-orig-subaddr-odd" />
  325. <enum name = "priv-orig-tag" />
  326. <enum name = "priv-from-all" />
  327. <enum name = "priv-from-name" />
  328. <enum name = "priv-from-name-valid" />
  329. <enum name = "priv-from-name-charset" />
  330. <enum name = "priv-from-name-pres" />
  331. <enum name = "priv-from-num" />
  332. <enum name = "priv-from-num-valid" />
  333. <enum name = "priv-from-num-plan" />
  334. <enum name = "priv-from-num-pres" />
  335. <enum name = "priv-from-subaddr" />
  336. <enum name = "priv-from-subaddr-valid" />
  337. <enum name = "priv-from-subaddr-type" />
  338. <enum name = "priv-from-subaddr-odd" />
  339. <enum name = "priv-from-tag" />
  340. <enum name = "priv-to-all" />
  341. <enum name = "priv-to-name" />
  342. <enum name = "priv-to-name-valid" />
  343. <enum name = "priv-to-name-charset" />
  344. <enum name = "priv-to-name-pres" />
  345. <enum name = "priv-to-num" />
  346. <enum name = "priv-to-num-valid" />
  347. <enum name = "priv-to-num-plan" />
  348. <enum name = "priv-to-num-pres" />
  349. <enum name = "priv-to-subaddr" />
  350. <enum name = "priv-to-subaddr-valid" />
  351. <enum name = "priv-to-subaddr-type" />
  352. <enum name = "priv-to-subaddr-odd" />
  353. <enum name = "priv-to-tag" />
  354. <enum name = "reason" />
  355. <enum name = "count" />
  356. </enumlist>
  357. </parameter>
  358. <parameter name="i">
  359. <para>If set, this will prevent the channel from sending out protocol
  360. messages because of the value being set</para>
  361. </parameter>
  362. </syntax>
  363. <description>
  364. <para>Gets or sets Redirecting data on the channel.</para>
  365. <para>The <replaceable>orig-pres</replaceable>,
  366. <replaceable>from-pres</replaceable> and <replaceable>to-pres</replaceable>
  367. fields get/set a combined value for the corresponding
  368. <replaceable>...-name-pres</replaceable> and <replaceable>...-num-pres</replaceable>
  369. fields.</para>
  370. <para>The recognized values for the <replaceable>reason</replaceable>
  371. and <replaceable>orig-reason</replaceable> fields are the following:</para>
  372. <enumlist>
  373. <enum name = "away"><para>Callee is Away</para></enum>
  374. <enum name = "cf_dte"><para>Call Forwarding By The Called DTE</para></enum>
  375. <enum name = "cfb"><para>Call Forwarding Busy</para></enum>
  376. <enum name = "cfnr"><para>Call Forwarding No Reply</para></enum>
  377. <enum name = "cfu"><para>Call Forwarding Unconditional</para></enum>
  378. <enum name = "deflection"><para>Call Deflection</para></enum>
  379. <enum name = "dnd"><para>Do Not Disturb</para></enum>
  380. <enum name = "follow_me"><para>Follow Me</para></enum>
  381. <enum name = "out_of_order"><para>Called DTE Out-Of-Order</para></enum>
  382. <enum name = "send_to_vm"><para>Send the call to voicemail</para></enum>
  383. <enum name = "time_of_day"><para>Time of Day</para></enum>
  384. <enum name = "unavailable"><para>Callee is Unavailable</para></enum>
  385. <enum name = "unknown"><para>Unknown</para></enum>
  386. </enumlist>
  387. <note><para>You can set a user defined reason string that SIP can
  388. send/receive instead. The user defined reason string my need to be
  389. quoted depending upon SIP or the peer's requirements. These strings
  390. are treated as unknown by the non-SIP channel drivers.</para></note>
  391. <para>The allowable values for the <replaceable>xxx-name-charset</replaceable>
  392. field are the following:</para>
  393. <enumlist>
  394. <enum name = "unknown"><para>Unknown</para></enum>
  395. <enum name = "iso8859-1"><para>ISO8859-1</para></enum>
  396. <enum name = "withdrawn"><para>Withdrawn</para></enum>
  397. <enum name = "iso8859-2"><para>ISO8859-2</para></enum>
  398. <enum name = "iso8859-3"><para>ISO8859-3</para></enum>
  399. <enum name = "iso8859-4"><para>ISO8859-4</para></enum>
  400. <enum name = "iso8859-5"><para>ISO8859-5</para></enum>
  401. <enum name = "iso8859-7"><para>ISO8859-7</para></enum>
  402. <enum name = "bmp"><para>ISO10646 Bmp String</para></enum>
  403. <enum name = "utf8"><para>ISO10646 UTF-8 String</para></enum>
  404. </enumlist>
  405. </description>
  406. </function>
  407. ***/
  408. enum ID_FIELD_STATUS {
  409. ID_FIELD_VALID,
  410. ID_FIELD_INVALID,
  411. ID_FIELD_UNKNOWN
  412. };
  413. AST_DEFINE_APP_ARGS_TYPE(ast_party_func_args,
  414. AST_APP_ARG(member); /*!< Member name */
  415. AST_APP_ARG(opts); /*!< Options token */
  416. AST_APP_ARG(other); /*!< Any remining unused arguments */
  417. );
  418. AST_DEFINE_APP_ARGS_TYPE(ast_party_members,
  419. AST_APP_ARG(subnames[10]); /*!< Option member subnames */
  420. );
  421. enum CONNECTED_LINE_OPT_FLAGS {
  422. CONNECTED_LINE_OPT_INHIBIT = (1 << 0),
  423. };
  424. enum CONNECTED_LINE_OPT_ARGS {
  425. CONNECTED_LINE_OPT_DUMMY, /*!< Delete this if CONNECTED_LINE ever gets an option with parameters. */
  426. /*! \note This entry _MUST_ be the last one in the enum */
  427. CONNECTED_LINE_OPT_ARG_ARRAY_SIZE
  428. };
  429. AST_APP_OPTIONS(connectedline_opts, BEGIN_OPTIONS
  430. AST_APP_OPTION('i', CONNECTED_LINE_OPT_INHIBIT),
  431. END_OPTIONS);
  432. enum REDIRECTING_OPT_FLAGS {
  433. REDIRECTING_OPT_INHIBIT = (1 << 0),
  434. };
  435. enum REDIRECTING_OPT_ARGS {
  436. REDIRECTING_OPT_DUMMY, /*!< Delete this if REDIRECTING ever gets an option with parameters. */
  437. /*! \note This entry _MUST_ be the last one in the enum */
  438. REDIRECTING_OPT_ARG_ARRAY_SIZE
  439. };
  440. AST_APP_OPTIONS(redirecting_opts, BEGIN_OPTIONS
  441. AST_APP_OPTION('i', REDIRECTING_OPT_INHIBIT),
  442. END_OPTIONS);
  443. /*!
  444. * \internal
  445. * \brief Read values from the party name struct.
  446. * \since 1.8
  447. *
  448. * \param buf Buffer to fill with read value.
  449. * \param len Length of the buffer.
  450. * \param argc Number of party member subnames.
  451. * \param argv Party member subnames given.
  452. * \param name Party name to get values from.
  453. *
  454. * \retval ID_FIELD_VALID on success.
  455. * \retval ID_FIELD_UNKNOWN on unknown field name.
  456. */
  457. static enum ID_FIELD_STATUS party_name_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_name *name)
  458. {
  459. enum ID_FIELD_STATUS status;
  460. status = ID_FIELD_VALID;
  461. if (argc == 0) {
  462. /* We want the name string */
  463. if (name->valid && name->str) {
  464. ast_copy_string(buf, name->str, len);
  465. }
  466. } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
  467. snprintf(buf, len, "%d", name->valid);
  468. } else if (argc == 1 && !strcasecmp("charset", argv[0])) {
  469. ast_copy_string(buf, ast_party_name_charset_str(name->char_set), len);
  470. } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
  471. /* Accept pres[entation] */
  472. ast_copy_string(buf, ast_named_caller_presentation(name->presentation), len);
  473. } else {
  474. status = ID_FIELD_UNKNOWN;
  475. }
  476. return status;
  477. }
  478. /*!
  479. * \internal
  480. * \brief Read values from the party number struct.
  481. * \since 1.8
  482. *
  483. * \param buf Buffer to fill with read value.
  484. * \param len Length of the buffer.
  485. * \param argc Number of party member subnames.
  486. * \param argv Party member subnames given.
  487. * \param number Party number to get values from.
  488. *
  489. * \retval ID_FIELD_VALID on success.
  490. * \retval ID_FIELD_UNKNOWN on unknown field name.
  491. */
  492. static enum ID_FIELD_STATUS party_number_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_number *number)
  493. {
  494. enum ID_FIELD_STATUS status;
  495. status = ID_FIELD_VALID;
  496. if (argc == 0) {
  497. /* We want the number string */
  498. if (number->valid && number->str) {
  499. ast_copy_string(buf, number->str, len);
  500. }
  501. } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
  502. snprintf(buf, len, "%d", number->valid);
  503. } else if (argc == 1 && !strcasecmp("plan", argv[0])) {
  504. snprintf(buf, len, "%d", number->plan);
  505. } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
  506. /* Accept pres[entation] */
  507. ast_copy_string(buf, ast_named_caller_presentation(number->presentation), len);
  508. } else {
  509. status = ID_FIELD_UNKNOWN;
  510. }
  511. return status;
  512. }
  513. /*!
  514. * \internal
  515. * \brief Read values from the party subaddress struct.
  516. * \since 1.8
  517. *
  518. * \param buf Buffer to fill with read value.
  519. * \param len Length of the buffer.
  520. * \param argc Number of party member subnames.
  521. * \param argv Party member subnames given.
  522. * \param subaddress Party subaddress to get values from.
  523. *
  524. * \retval ID_FIELD_VALID on success.
  525. * \retval ID_FIELD_UNKNOWN on unknown field name.
  526. */
  527. static enum ID_FIELD_STATUS party_subaddress_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_subaddress *subaddress)
  528. {
  529. enum ID_FIELD_STATUS status;
  530. status = ID_FIELD_VALID;
  531. if (argc == 0) {
  532. /* We want the subaddress string */
  533. if (subaddress->str) {
  534. ast_copy_string(buf, subaddress->str, len);
  535. }
  536. } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
  537. snprintf(buf, len, "%d", subaddress->valid);
  538. } else if (argc == 1 && !strcasecmp("type", argv[0])) {
  539. snprintf(buf, len, "%d", subaddress->type);
  540. } else if (argc == 1 && !strcasecmp("odd", argv[0])) {
  541. snprintf(buf, len, "%d", subaddress->odd_even_indicator);
  542. } else {
  543. status = ID_FIELD_UNKNOWN;
  544. }
  545. return status;
  546. }
  547. /*!
  548. * \internal
  549. * \brief Read values from the party id struct.
  550. * \since 1.8
  551. *
  552. * \param buf Buffer to fill with read value.
  553. * \param len Length of the buffer.
  554. * \param argc Number of party member subnames.
  555. * \param argv Party member subnames given.
  556. * \param id Party id to get values from.
  557. *
  558. * \retval ID_FIELD_VALID on success.
  559. * \retval ID_FIELD_UNKNOWN on unknown field name.
  560. */
  561. static enum ID_FIELD_STATUS party_id_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_id *id)
  562. {
  563. enum ID_FIELD_STATUS status;
  564. if (argc == 0) {
  565. /* Must have at least one subname. */
  566. return ID_FIELD_UNKNOWN;
  567. }
  568. status = ID_FIELD_VALID;
  569. if (argc == 1 && !strcasecmp("all", argv[0])) {
  570. snprintf(buf, len, "\"%s\" <%s>",
  571. S_COR(id->name.valid, id->name.str, ""),
  572. S_COR(id->number.valid, id->number.str, ""));
  573. } else if (!strcasecmp("name", argv[0])) {
  574. status = party_name_read(buf, len, argc - 1, argv + 1, &id->name);
  575. } else if (!strncasecmp("num", argv[0], 3)) {
  576. /* Accept num[ber] */
  577. status = party_number_read(buf, len, argc - 1, argv + 1, &id->number);
  578. } else if (!strncasecmp("subaddr", argv[0], 7)) {
  579. /* Accept subaddr[ess] */
  580. status = party_subaddress_read(buf, len, argc - 1, argv + 1, &id->subaddress);
  581. } else if (argc == 1 && !strcasecmp("tag", argv[0])) {
  582. if (id->tag) {
  583. ast_copy_string(buf, id->tag, len);
  584. }
  585. } else if (argc == 1 && !strcasecmp("ton", argv[0])) {
  586. /* ton is an alias for num-plan */
  587. snprintf(buf, len, "%d", id->number.plan);
  588. } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
  589. /*
  590. * Accept pres[entation]
  591. * This is the combined name/number presentation.
  592. */
  593. ast_copy_string(buf,
  594. ast_named_caller_presentation(ast_party_id_presentation(id)), len);
  595. } else {
  596. status = ID_FIELD_UNKNOWN;
  597. }
  598. return status;
  599. }
  600. /*!
  601. * \internal
  602. * \brief Write new values to the party name struct
  603. * \since 1.8
  604. *
  605. * \param name Party name struct to write values
  606. * \param argc Number of party member subnames.
  607. * \param argv Party member subnames given.
  608. * \param value Value to assign to the party name.
  609. *
  610. * \retval ID_FIELD_VALID on success.
  611. * \retval ID_FIELD_INVALID on error with field value.
  612. * \retval ID_FIELD_UNKNOWN on unknown field name.
  613. */
  614. static enum ID_FIELD_STATUS party_name_write(struct ast_party_name *name, int argc, char *argv[], const char *value)
  615. {
  616. char *val;
  617. enum ID_FIELD_STATUS status;
  618. status = ID_FIELD_VALID;
  619. if (argc == 0) {
  620. /* We are setting the name string */
  621. name->valid = 1;
  622. name->str = ast_strdup(value);
  623. ast_trim_blanks(name->str);
  624. } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
  625. name->valid = atoi(value) ? 1 : 0;
  626. } else if (argc == 1 && !strcasecmp("charset", argv[0])) {
  627. int char_set;
  628. val = ast_strdupa(value);
  629. ast_trim_blanks(val);
  630. if (('0' <= val[0]) && (val[0] <= '9')) {
  631. char_set = atoi(val);
  632. } else {
  633. char_set = ast_party_name_charset_parse(val);
  634. }
  635. if (char_set < 0) {
  636. ast_log(LOG_ERROR,
  637. "Unknown name char-set '%s', value unchanged\n", val);
  638. status = ID_FIELD_INVALID;
  639. } else {
  640. name->char_set = char_set;
  641. }
  642. } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
  643. int pres;
  644. /* Accept pres[entation] */
  645. val = ast_strdupa(value);
  646. ast_trim_blanks(val);
  647. if (('0' <= val[0]) && (val[0] <= '9')) {
  648. pres = atoi(val);
  649. } else {
  650. pres = ast_parse_caller_presentation(val);
  651. }
  652. if (pres < 0) {
  653. ast_log(LOG_ERROR,
  654. "Unknown name presentation '%s', value unchanged\n", val);
  655. status = ID_FIELD_INVALID;
  656. } else {
  657. name->presentation = pres;
  658. }
  659. } else {
  660. status = ID_FIELD_UNKNOWN;
  661. }
  662. return status;
  663. }
  664. /*!
  665. * \internal
  666. * \brief Write new values to the party number struct
  667. * \since 1.8
  668. *
  669. * \param number Party number struct to write values
  670. * \param argc Number of party member subnames.
  671. * \param argv Party member subnames given.
  672. * \param value Value to assign to the party number.
  673. *
  674. * \retval ID_FIELD_VALID on success.
  675. * \retval ID_FIELD_INVALID on error with field value.
  676. * \retval ID_FIELD_UNKNOWN on unknown field name.
  677. */
  678. static enum ID_FIELD_STATUS party_number_write(struct ast_party_number *number, int argc, char *argv[], const char *value)
  679. {
  680. char *val;
  681. enum ID_FIELD_STATUS status;
  682. status = ID_FIELD_VALID;
  683. if (argc == 0) {
  684. /* We are setting the number string */
  685. number->valid = 1;
  686. number->str = ast_strdup(value);
  687. ast_trim_blanks(number->str);
  688. } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
  689. number->valid = atoi(value) ? 1 : 0;
  690. } else if (argc == 1 && !strcasecmp("plan", argv[0])) {
  691. val = ast_strdupa(value);
  692. ast_trim_blanks(val);
  693. if (('0' <= val[0]) && (val[0] <= '9')) {
  694. number->plan = atoi(val);
  695. } else {
  696. ast_log(LOG_ERROR,
  697. "Unknown type-of-number/numbering-plan '%s', value unchanged\n", val);
  698. status = ID_FIELD_INVALID;
  699. }
  700. } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
  701. int pres;
  702. /* Accept pres[entation] */
  703. val = ast_strdupa(value);
  704. ast_trim_blanks(val);
  705. if (('0' <= val[0]) && (val[0] <= '9')) {
  706. pres = atoi(val);
  707. } else {
  708. pres = ast_parse_caller_presentation(val);
  709. }
  710. if (pres < 0) {
  711. ast_log(LOG_ERROR,
  712. "Unknown number presentation '%s', value unchanged\n", val);
  713. status = ID_FIELD_INVALID;
  714. } else {
  715. number->presentation = pres;
  716. }
  717. } else {
  718. status = ID_FIELD_UNKNOWN;
  719. }
  720. return status;
  721. }
  722. /*!
  723. * \internal
  724. * \brief Write new values to the party subaddress struct
  725. * \since 1.8
  726. *
  727. * \param subaddress Party subaddress struct to write values
  728. * \param argc Number of party member subnames.
  729. * \param argv Party member subnames given.
  730. * \param value Value to assign to the party subaddress.
  731. *
  732. * \retval ID_FIELD_VALID on success.
  733. * \retval ID_FIELD_INVALID on error with field value.
  734. * \retval ID_FIELD_UNKNOWN on unknown field name.
  735. */
  736. static enum ID_FIELD_STATUS party_subaddress_write(struct ast_party_subaddress *subaddress, int argc, char *argv[], const char *value)
  737. {
  738. enum ID_FIELD_STATUS status;
  739. status = ID_FIELD_VALID;
  740. if (argc == 0) {
  741. /* We are setting the subaddress string */
  742. subaddress->str = ast_strdup(value);
  743. ast_trim_blanks(subaddress->str);
  744. } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
  745. subaddress->valid = atoi(value) ? 1 : 0;
  746. } else if (argc == 1 && !strcasecmp("type", argv[0])) {
  747. subaddress->type = atoi(value) ? 2 : 0;
  748. } else if (argc == 1 && !strcasecmp("odd", argv[0])) {
  749. subaddress->odd_even_indicator = atoi(value) ? 1 : 0;
  750. } else {
  751. status = ID_FIELD_UNKNOWN;
  752. }
  753. return status;
  754. }
  755. /*!
  756. * \internal
  757. * \brief Write new values to the party id struct
  758. * \since 1.8
  759. *
  760. * \param id Party ID struct to write values
  761. * \param argc Number of party member subnames.
  762. * \param argv Party member subnames given.
  763. * \param value Value to assign to the party id.
  764. *
  765. * \retval ID_FIELD_VALID on success.
  766. * \retval ID_FIELD_INVALID on error with field value.
  767. * \retval ID_FIELD_UNKNOWN on unknown field name.
  768. */
  769. static enum ID_FIELD_STATUS party_id_write(struct ast_party_id *id, int argc, char *argv[], const char *value)
  770. {
  771. char *val;
  772. enum ID_FIELD_STATUS status;
  773. if (argc == 0) {
  774. /* Must have at least one subname. */
  775. return ID_FIELD_UNKNOWN;
  776. }
  777. status = ID_FIELD_VALID;
  778. if (argc == 1 && !strcasecmp("all", argv[0])) {
  779. char name[256];
  780. char num[256];
  781. ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
  782. id->name.valid = 1;
  783. id->name.str = ast_strdup(name);
  784. if (!id->name.str) {
  785. return ID_FIELD_INVALID;
  786. }
  787. id->number.valid = 1;
  788. id->number.str = ast_strdup(num);
  789. if (!id->number.str) {
  790. return ID_FIELD_INVALID;
  791. }
  792. } else if (!strcasecmp("name", argv[0])) {
  793. status = party_name_write(&id->name, argc - 1, argv + 1, value);
  794. } else if (!strncasecmp("num", argv[0], 3)) {
  795. /* Accept num[ber] */
  796. status = party_number_write(&id->number, argc - 1, argv + 1, value);
  797. } else if (!strncasecmp("subaddr", argv[0], 7)) {
  798. /* Accept subaddr[ess] */
  799. status = party_subaddress_write(&id->subaddress, argc - 1, argv + 1, value);
  800. } else if (argc == 1 && !strcasecmp("tag", argv[0])) {
  801. id->tag = ast_strdup(value);
  802. ast_trim_blanks(id->tag);
  803. } else if (argc == 1 && !strcasecmp("ton", argv[0])) {
  804. /* ton is an alias for num-plan */
  805. argv[0] = "plan";
  806. status = party_number_write(&id->number, argc, argv, value);
  807. } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
  808. int pres;
  809. /*
  810. * Accept pres[entation]
  811. * This is the combined name/number presentation.
  812. */
  813. val = ast_strdupa(value);
  814. ast_trim_blanks(val);
  815. if (('0' <= val[0]) && (val[0] <= '9')) {
  816. pres = atoi(val);
  817. } else {
  818. pres = ast_parse_caller_presentation(val);
  819. }
  820. if (pres < 0) {
  821. ast_log(LOG_ERROR,
  822. "Unknown combined presentation '%s', value unchanged\n", val);
  823. status = ID_FIELD_INVALID;
  824. } else {
  825. id->name.presentation = pres;
  826. id->number.presentation = pres;
  827. }
  828. } else {
  829. status = ID_FIELD_UNKNOWN;
  830. }
  831. return status;
  832. }
  833. /*! TRUE if we have already notified about CALLERPRES being deprecated. */
  834. static int callerpres_deprecate_notify;
  835. /*!
  836. * \internal
  837. * \brief Read values from the caller-id presentation information struct.
  838. *
  839. * \param chan Asterisk channel to read
  840. * \param cmd Not used
  841. * \param data Caller-id presentation function datatype string
  842. * \param buf Buffer to fill with read value.
  843. * \param len Length of the buffer
  844. *
  845. * \retval 0 on success.
  846. * \retval -1 on error.
  847. */
  848. static int callerpres_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
  849. {
  850. if (!chan) {
  851. ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
  852. return -1;
  853. }
  854. if (!callerpres_deprecate_notify) {
  855. callerpres_deprecate_notify = 1;
  856. ast_log(LOG_WARNING, "CALLERPRES is deprecated."
  857. " Use CALLERID(name-pres) or CALLERID(num-pres) instead.\n");
  858. }
  859. ast_copy_string(buf,
  860. ast_named_caller_presentation(ast_party_id_presentation(&ast_channel_caller(chan)->id)), len);
  861. return 0;
  862. }
  863. /*!
  864. * \internal
  865. * \brief Write new values to the caller-id presentation information struct.
  866. *
  867. * \param chan Asterisk channel to update
  868. * \param cmd Not used
  869. * \param data Caller-id presentation function datatype string
  870. * \param value Value to assign to the caller-id presentation information struct.
  871. *
  872. * \retval 0 on success.
  873. * \retval -1 on error.
  874. */
  875. static int callerpres_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
  876. {
  877. int pres;
  878. if (!chan) {
  879. ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
  880. return -1;
  881. }
  882. if (!callerpres_deprecate_notify) {
  883. callerpres_deprecate_notify = 1;
  884. ast_log(LOG_WARNING, "CALLERPRES is deprecated."
  885. " Use CALLERID(name-pres) or CALLERID(num-pres) instead.\n");
  886. }
  887. pres = ast_parse_caller_presentation(value);
  888. if (pres < 0) {
  889. ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
  890. } else {
  891. ast_channel_caller(chan)->id.name.presentation = pres;
  892. ast_channel_caller(chan)->id.number.presentation = pres;
  893. }
  894. return 0;
  895. }
  896. /*!
  897. * \internal
  898. * \brief Read values from the caller-id information struct.
  899. *
  900. * \param chan Asterisk channel to read
  901. * \param cmd Not used
  902. * \param data Caller-id function datatype string
  903. * \param buf Buffer to fill with read value.
  904. * \param len Length of the buffer
  905. *
  906. * \retval 0 on success.
  907. * \retval -1 on error.
  908. */
  909. static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
  910. {
  911. char *parms;
  912. struct ast_party_members member = { 0, };
  913. AST_DECLARE_APP_ARGS(args,
  914. AST_APP_ARG(member); /*!< Member name */
  915. AST_APP_ARG(cid); /*!< Optional caller id to parse instead of from the channel. */
  916. );
  917. /* Ensure that the buffer is empty */
  918. *buf = 0;
  919. if (!chan) {
  920. return -1;
  921. }
  922. parms = ast_strdupa(data);
  923. AST_STANDARD_APP_ARGS(args, parms);
  924. if (args.argc == 0) {
  925. /* Must have at least one argument. */
  926. return -1;
  927. }
  928. AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
  929. if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
  930. /* Too few or too many subnames */
  931. return -1;
  932. }
  933. if (args.argc == 2) {
  934. char name[80];
  935. char num[80];
  936. ast_callerid_split(args.cid, name, sizeof(name), num, sizeof(num));
  937. if (member.argc == 1 && !strcasecmp("all", member.argv[0])) {
  938. snprintf(buf, len, "\"%s\" <%s>", name, num);
  939. } else if (member.argc == 1 && !strcasecmp("name", member.argv[0])) {
  940. ast_copy_string(buf, name, len);
  941. } else if (member.argc == 1 && !strncasecmp("num", member.argv[0], 3)) {
  942. /* Accept num[ber] */
  943. ast_copy_string(buf, num, len);
  944. } else {
  945. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  946. }
  947. } else {
  948. enum ID_FIELD_STATUS status;
  949. ast_channel_lock(chan);
  950. if (member.argc == 1 && !strcasecmp("rdnis", member.argv[0])) {
  951. if (ast_channel_redirecting(chan)->from.number.valid
  952. && ast_channel_redirecting(chan)->from.number.str) {
  953. ast_copy_string(buf, ast_channel_redirecting(chan)->from.number.str, len);
  954. }
  955. } else if (!strcasecmp("dnid", member.argv[0])) {
  956. if (member.argc == 1) {
  957. /* Setup as if user had given dnid-num instead. */
  958. member.argc = 2;
  959. member.argv[1] = "num";
  960. }
  961. if (!strncasecmp("num", member.argv[1], 3)) {
  962. /*
  963. * Accept num[ber]
  964. * dnid-num...
  965. */
  966. if (member.argc == 2) {
  967. /* dnid-num */
  968. if (ast_channel_dialed(chan)->number.str) {
  969. ast_copy_string(buf, ast_channel_dialed(chan)->number.str, len);
  970. }
  971. } else if (member.argc == 3 && !strcasecmp("plan", member.argv[2])) {
  972. /* dnid-num-plan */
  973. snprintf(buf, len, "%d", ast_channel_dialed(chan)->number.plan);
  974. } else {
  975. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  976. }
  977. } else if (!strncasecmp("subaddr", member.argv[1], 7)) {
  978. /*
  979. * Accept subaddr[ess]
  980. * dnid-subaddr...
  981. */
  982. status = party_subaddress_read(buf, len, member.argc - 2, member.argv + 2,
  983. &ast_channel_dialed(chan)->subaddress);
  984. switch (status) {
  985. case ID_FIELD_VALID:
  986. case ID_FIELD_INVALID:
  987. break;
  988. default:
  989. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  990. break;
  991. }
  992. } else {
  993. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  994. }
  995. } else if (member.argc == 1 && !strcasecmp("ani2", member.argv[0])) {
  996. snprintf(buf, len, "%d", ast_channel_caller(chan)->ani2);
  997. } else if (!strcasecmp("ani", member.argv[0])) {
  998. if (member.argc == 1) {
  999. /* Setup as if user had given ani-num instead. */
  1000. member.argc = 2;
  1001. member.argv[1] = "num";
  1002. }
  1003. status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
  1004. &ast_channel_caller(chan)->ani);
  1005. switch (status) {
  1006. case ID_FIELD_VALID:
  1007. case ID_FIELD_INVALID:
  1008. break;
  1009. default:
  1010. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1011. break;
  1012. }
  1013. } else if (!strcasecmp("priv", member.argv[0])) {
  1014. status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
  1015. &ast_channel_caller(chan)->priv);
  1016. switch (status) {
  1017. case ID_FIELD_VALID:
  1018. case ID_FIELD_INVALID:
  1019. break;
  1020. default:
  1021. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1022. break;
  1023. }
  1024. } else {
  1025. status = party_id_read(buf, len, member.argc, member.argv, &ast_channel_caller(chan)->id);
  1026. switch (status) {
  1027. case ID_FIELD_VALID:
  1028. case ID_FIELD_INVALID:
  1029. break;
  1030. default:
  1031. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1032. break;
  1033. }
  1034. }
  1035. ast_channel_unlock(chan);
  1036. }
  1037. return 0;
  1038. }
  1039. /*!
  1040. * \internal
  1041. * \brief Write new values to the caller-id information struct.
  1042. *
  1043. * \param chan Asterisk channel to update
  1044. * \param cmd Not used
  1045. * \param data Caller-id function datatype string
  1046. * \param value Value to assign to the caller-id information struct.
  1047. *
  1048. * \retval 0 on success.
  1049. * \retval -1 on error.
  1050. */
  1051. static int callerid_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
  1052. {
  1053. struct ast_party_caller caller;
  1054. struct ast_party_dialed dialed;
  1055. enum ID_FIELD_STATUS status;
  1056. char *val;
  1057. char *parms;
  1058. struct ast_party_func_args args = { 0, };
  1059. struct ast_party_members member = { 0, };
  1060. if (!value || !chan) {
  1061. return -1;
  1062. }
  1063. parms = ast_strdupa(data);
  1064. AST_STANDARD_APP_ARGS(args, parms);
  1065. if (args.argc == 0) {
  1066. /* Must have at least one argument. */
  1067. return -1;
  1068. }
  1069. AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
  1070. if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
  1071. /* Too few or too many subnames */
  1072. return -1;
  1073. }
  1074. value = ast_skip_blanks(value);
  1075. ast_channel_lock(chan);
  1076. if (member.argc == 1 && !strcasecmp("rdnis", member.argv[0])) {
  1077. ast_channel_redirecting(chan)->from.number.valid = 1;
  1078. ast_free(ast_channel_redirecting(chan)->from.number.str);
  1079. ast_channel_redirecting(chan)->from.number.str = ast_strdup(value);
  1080. } else if (!strcasecmp("dnid", member.argv[0])) {
  1081. ast_party_dialed_set_init(&dialed, ast_channel_dialed(chan));
  1082. if (member.argc == 1) {
  1083. /* Setup as if user had given dnid-num instead. */
  1084. member.argc = 2;
  1085. member.argv[1] = "num";
  1086. }
  1087. if (!strncasecmp("num", member.argv[1], 3)) {
  1088. /*
  1089. * Accept num[ber]
  1090. * dnid-num...
  1091. */
  1092. if (member.argc == 2) {
  1093. /* dnid-num */
  1094. dialed.number.str = ast_strdup(value);
  1095. ast_trim_blanks(dialed.number.str);
  1096. ast_party_dialed_set(ast_channel_dialed(chan), &dialed);
  1097. } else if (member.argc == 3 && !strcasecmp("plan", member.argv[2])) {
  1098. /* dnid-num-plan */
  1099. val = ast_strdupa(value);
  1100. ast_trim_blanks(val);
  1101. if (('0' <= val[0]) && (val[0] <= '9')) {
  1102. ast_channel_dialed(chan)->number.plan = atoi(val);
  1103. } else {
  1104. ast_log(LOG_ERROR,
  1105. "Unknown type-of-number/numbering-plan '%s', value unchanged\n", val);
  1106. }
  1107. } else {
  1108. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1109. }
  1110. } else if (!strncasecmp("subaddr", member.argv[1], 7)) {
  1111. /*
  1112. * Accept subaddr[ess]
  1113. * dnid-subaddr...
  1114. */
  1115. status = party_subaddress_write(&dialed.subaddress, member.argc - 2,
  1116. member.argv + 2, value);
  1117. switch (status) {
  1118. case ID_FIELD_VALID:
  1119. ast_party_dialed_set(ast_channel_dialed(chan), &dialed);
  1120. break;
  1121. case ID_FIELD_INVALID:
  1122. break;
  1123. default:
  1124. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1125. break;
  1126. }
  1127. } else {
  1128. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1129. }
  1130. ast_party_dialed_free(&dialed);
  1131. } else if (member.argc == 1 && !strcasecmp("ani2", member.argv[0])) {
  1132. val = ast_strdupa(value);
  1133. ast_trim_blanks(val);
  1134. if (('0' <= val[0]) && (val[0] <= '9')) {
  1135. ast_channel_caller(chan)->ani2 = atoi(val);
  1136. } else {
  1137. ast_log(LOG_ERROR, "Unknown callerid ani2 '%s', value unchanged\n", val);
  1138. }
  1139. } else if (!strcasecmp("ani", member.argv[0])) {
  1140. ast_party_caller_set_init(&caller, ast_channel_caller(chan));
  1141. if (member.argc == 1) {
  1142. /* Setup as if user had given ani-num instead. */
  1143. member.argc = 2;
  1144. member.argv[1] = "num";
  1145. }
  1146. status = party_id_write(&caller.ani, member.argc - 1, member.argv + 1, value);
  1147. switch (status) {
  1148. case ID_FIELD_VALID:
  1149. ast_party_caller_set(ast_channel_caller(chan), &caller, NULL);
  1150. break;
  1151. case ID_FIELD_INVALID:
  1152. break;
  1153. default:
  1154. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1155. break;
  1156. }
  1157. ast_party_caller_free(&caller);
  1158. } else if (!strcasecmp("priv", member.argv[0])) {
  1159. ast_party_caller_set_init(&caller, ast_channel_caller(chan));
  1160. status = party_id_write(&caller.priv, member.argc - 1, member.argv + 1, value);
  1161. switch (status) {
  1162. case ID_FIELD_VALID:
  1163. ast_party_caller_set(ast_channel_caller(chan), &caller, NULL);
  1164. break;
  1165. case ID_FIELD_INVALID:
  1166. break;
  1167. default:
  1168. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1169. break;
  1170. }
  1171. ast_party_caller_free(&caller);
  1172. } else {
  1173. ast_party_caller_set_init(&caller, ast_channel_caller(chan));
  1174. status = party_id_write(&caller.id, member.argc, member.argv, value);
  1175. switch (status) {
  1176. case ID_FIELD_VALID:
  1177. ast_channel_set_caller_event(chan, &caller, NULL);
  1178. break;
  1179. case ID_FIELD_INVALID:
  1180. break;
  1181. default:
  1182. ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
  1183. break;
  1184. }
  1185. ast_party_caller_free(&caller);
  1186. }
  1187. ast_channel_unlock(chan);
  1188. return 0;
  1189. }
  1190. /*!
  1191. * \internal
  1192. * \brief Read values from the connected line information struct.
  1193. *
  1194. * \param chan Asterisk channel to read
  1195. * \param cmd Not used
  1196. * \param data Connected line function datatype string
  1197. * \param buf Buffer to fill with read value.
  1198. * \param len Length of the buffer
  1199. *
  1200. * \retval 0 on success.
  1201. * \retval -1 on error.
  1202. */
  1203. static int connectedline_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
  1204. {
  1205. struct ast_party_members member = { 0, };
  1206. char *read_what;
  1207. enum ID_FIELD_STATUS status;
  1208. /* Ensure that the buffer is empty */
  1209. *buf = 0;
  1210. if (!chan) {
  1211. return -1;
  1212. }
  1213. read_what = ast_strdupa(data);
  1214. AST_NONSTANDARD_APP_ARGS(member, read_what, '-');
  1215. if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
  1216. /* Too few or too many subnames */
  1217. return -1;
  1218. }
  1219. ast_channel_lock(chan);
  1220. if (member.argc == 1 && !strcasecmp("source", member.argv[0])) {
  1221. ast_copy_string(buf, ast_connected_line_source_name(ast_channel_connected(chan)->source), len);
  1222. } else if (!strcasecmp("priv", member.argv[0])) {
  1223. status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
  1224. &ast_channel_connected(chan)->priv);
  1225. switch (status) {
  1226. case ID_FIELD_VALID:
  1227. case ID_FIELD_INVALID:
  1228. break;
  1229. default:
  1230. ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
  1231. break;
  1232. }
  1233. } else {
  1234. status = party_id_read(buf, len, member.argc, member.argv, &ast_channel_connected(chan)->id);
  1235. switch (status) {
  1236. case ID_FIELD_VALID:
  1237. case ID_FIELD_INVALID:
  1238. break;
  1239. default:
  1240. ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
  1241. break;
  1242. }
  1243. }
  1244. ast_channel_unlock(chan);
  1245. return 0;
  1246. }
  1247. /*!
  1248. * \internal
  1249. * \brief Write new values to the connected line information struct.
  1250. *
  1251. * \param chan Asterisk channel to update
  1252. * \param cmd Not used
  1253. * \param data Connected line function datatype string
  1254. * \param value Value to assign to the connected line information struct.
  1255. *
  1256. * \retval 0 on success.
  1257. * \retval -1 on error.
  1258. */
  1259. static int connectedline_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
  1260. {
  1261. struct ast_party_connected_line connected;
  1262. char *val;
  1263. char *parms;
  1264. void (*set_it)(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
  1265. struct ast_party_func_args args = { 0, };
  1266. struct ast_party_members member = { 0, };
  1267. struct ast_flags opts;
  1268. char *opt_args[CONNECTED_LINE_OPT_ARG_ARRAY_SIZE];
  1269. enum ID_FIELD_STATUS status;
  1270. if (!value || !chan) {
  1271. return -1;
  1272. }
  1273. parms = ast_strdupa(data);
  1274. AST_STANDARD_APP_ARGS(args, parms);
  1275. if (args.argc == 0) {
  1276. /* Must have at least one argument. */
  1277. return -1;
  1278. }
  1279. AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
  1280. if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
  1281. /* Too few or too many subnames */
  1282. return -1;
  1283. }
  1284. if (ast_app_parse_options(connectedline_opts, &opts, opt_args, args.opts)) {
  1285. /* General invalid option syntax. */
  1286. return -1;
  1287. }
  1288. /* Determine if the update indication inhibit option is present */
  1289. if (ast_test_flag(&opts, CONNECTED_LINE_OPT_INHIBIT)) {
  1290. set_it = ast_channel_set_connected_line;
  1291. } else {
  1292. set_it = ast_channel_update_connected_line;
  1293. }
  1294. ast_channel_lock(chan);
  1295. ast_party_connected_line_set_init(&connected, ast_channel_connected(chan));
  1296. ast_channel_unlock(chan);
  1297. value = ast_skip_blanks(value);
  1298. if (member.argc == 1 && !strcasecmp("source", member.argv[0])) {
  1299. int source;
  1300. val = ast_strdupa(value);
  1301. ast_trim_blanks(val);
  1302. if (('0' <= val[0]) && (val[0] <= '9')) {
  1303. source = atoi(val);
  1304. } else {
  1305. source = ast_connected_line_source_parse(val);
  1306. }
  1307. if (source < 0) {
  1308. ast_log(LOG_ERROR, "Unknown connectedline source '%s', value unchanged\n", val);
  1309. } else {
  1310. connected.source = source;
  1311. set_it(chan, &connected, NULL);
  1312. }
  1313. } else if (!strcasecmp("priv", member.argv[0])) {
  1314. status = party_id_write(&connected.priv, member.argc - 1, member.argv + 1, value);
  1315. switch (status) {
  1316. case ID_FIELD_VALID:
  1317. set_it(chan, &connected, NULL);
  1318. break;
  1319. case ID_FIELD_INVALID:
  1320. break;
  1321. default:
  1322. ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
  1323. break;
  1324. }
  1325. ast_party_connected_line_free(&connected);
  1326. } else {
  1327. status = party_id_write(&connected.id, member.argc, member.argv, value);
  1328. switch (status) {
  1329. case ID_FIELD_VALID:
  1330. set_it(chan, &connected, NULL);
  1331. break;
  1332. case ID_FIELD_INVALID:
  1333. break;
  1334. default:
  1335. ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
  1336. break;
  1337. }
  1338. ast_party_connected_line_free(&connected);
  1339. }
  1340. return 0;
  1341. }
  1342. /*!
  1343. * \internal
  1344. * \brief Read values from the redirecting information struct.
  1345. *
  1346. * \param chan Asterisk channel to read
  1347. * \param cmd Not used
  1348. * \param data Redirecting function datatype string
  1349. * \param buf Buffer to fill with read value.
  1350. * \param len Length of the buffer
  1351. *
  1352. * \retval 0 on success.
  1353. * \retval -1 on error.
  1354. */
  1355. static int redirecting_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
  1356. {
  1357. struct ast_party_members member = { 0, };
  1358. char *read_what;
  1359. const struct ast_party_redirecting *ast_redirecting;
  1360. enum ID_FIELD_STATUS status;
  1361. /* Ensure that the buffer is empty */
  1362. *buf = 0;
  1363. if (!chan) {
  1364. return -1;
  1365. }
  1366. read_what = ast_strdupa(data);
  1367. AST_NONSTANDARD_APP_ARGS(member, read_what, '-');
  1368. if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
  1369. /* Too few or too many subnames */
  1370. return -1;
  1371. }
  1372. ast_channel_lock(chan);
  1373. ast_redirecting = ast_channel_redirecting(chan);
  1374. if (!strcasecmp("orig", member.argv[0])) {
  1375. if (member.argc == 2 && !strcasecmp("reason", member.argv[1])) {
  1376. ast_copy_string(buf,
  1377. ast_redirecting_reason_name(&ast_redirecting->orig_reason), len);
  1378. } else {
  1379. status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
  1380. &ast_redirecting->orig);
  1381. switch (status) {
  1382. case ID_FIELD_VALID:
  1383. case ID_FIELD_INVALID:
  1384. break;
  1385. default:
  1386. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1387. break;
  1388. }
  1389. }
  1390. } else if (!strcasecmp("from", member.argv[0])) {
  1391. status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
  1392. &ast_redirecting->from);
  1393. switch (status) {
  1394. case ID_FIELD_VALID:
  1395. case ID_FIELD_INVALID:
  1396. break;
  1397. default:
  1398. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1399. break;
  1400. }
  1401. } else if (!strcasecmp("to", member.argv[0])) {
  1402. status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
  1403. &ast_redirecting->to);
  1404. switch (status) {
  1405. case ID_FIELD_VALID:
  1406. case ID_FIELD_INVALID:
  1407. break;
  1408. default:
  1409. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1410. break;
  1411. }
  1412. } else if (member.argc == 1 && !strncasecmp("pres", member.argv[0], 4)) {
  1413. /*
  1414. * Accept pres[entation]
  1415. * This is the combined from name/number presentation.
  1416. */
  1417. ast_copy_string(buf,
  1418. ast_named_caller_presentation(
  1419. ast_party_id_presentation(&ast_redirecting->from)), len);
  1420. } else if (member.argc == 1 && !strcasecmp("reason", member.argv[0])) {
  1421. ast_copy_string(buf, ast_redirecting_reason_name(&ast_redirecting->reason), len);
  1422. } else if (member.argc == 1 && !strcasecmp("count", member.argv[0])) {
  1423. snprintf(buf, len, "%d", ast_redirecting->count);
  1424. } else if (1 < member.argc && !strcasecmp("priv", member.argv[0])) {
  1425. if (!strcasecmp("orig", member.argv[1])) {
  1426. status = party_id_read(buf, len, member.argc - 2, member.argv + 2,
  1427. &ast_redirecting->priv_orig);
  1428. switch (status) {
  1429. case ID_FIELD_VALID:
  1430. case ID_FIELD_INVALID:
  1431. break;
  1432. default:
  1433. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1434. break;
  1435. }
  1436. } else if (!strcasecmp("from", member.argv[1])) {
  1437. status = party_id_read(buf, len, member.argc - 2, member.argv + 2,
  1438. &ast_redirecting->priv_from);
  1439. switch (status) {
  1440. case ID_FIELD_VALID:
  1441. case ID_FIELD_INVALID:
  1442. break;
  1443. default:
  1444. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1445. break;
  1446. }
  1447. } else if (!strcasecmp("to", member.argv[1])) {
  1448. status = party_id_read(buf, len, member.argc - 2, member.argv + 2,
  1449. &ast_redirecting->priv_to);
  1450. switch (status) {
  1451. case ID_FIELD_VALID:
  1452. case ID_FIELD_INVALID:
  1453. break;
  1454. default:
  1455. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1456. break;
  1457. }
  1458. } else {
  1459. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1460. }
  1461. } else {
  1462. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1463. }
  1464. ast_channel_unlock(chan);
  1465. return 0;
  1466. }
  1467. /*!
  1468. * \internal
  1469. * \brief Write new values to the redirecting information struct.
  1470. *
  1471. * \param chan Asterisk channel to update
  1472. * \param cmd Not used
  1473. * \param data Redirecting function datatype string
  1474. * \param value Value to assign to the redirecting information struct.
  1475. *
  1476. * \retval 0 on success.
  1477. * \retval -1 on error.
  1478. */
  1479. static int redirecting_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
  1480. {
  1481. struct ast_party_redirecting redirecting;
  1482. enum ID_FIELD_STATUS status;
  1483. char *val;
  1484. char *parms;
  1485. void (*set_it)(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
  1486. struct ast_party_func_args args = { 0, };
  1487. struct ast_party_members member = { 0, };
  1488. struct ast_flags opts;
  1489. char *opt_args[REDIRECTING_OPT_ARG_ARRAY_SIZE];
  1490. if (!value || !chan) {
  1491. return -1;
  1492. }
  1493. parms = ast_strdupa(data);
  1494. AST_STANDARD_APP_ARGS(args, parms);
  1495. if (args.argc == 0) {
  1496. /* Must have at least one argument. */
  1497. return -1;
  1498. }
  1499. AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
  1500. if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
  1501. /* Too few or too many subnames */
  1502. return -1;
  1503. }
  1504. if (ast_app_parse_options(redirecting_opts, &opts, opt_args, args.opts)) {
  1505. /* General invalid option syntax. */
  1506. return -1;
  1507. }
  1508. /* Determine if the update indication inhibit option is present */
  1509. if (ast_test_flag(&opts, REDIRECTING_OPT_INHIBIT)) {
  1510. set_it = ast_channel_set_redirecting;
  1511. } else {
  1512. set_it = ast_channel_update_redirecting;
  1513. }
  1514. ast_channel_lock(chan);
  1515. ast_party_redirecting_set_init(&redirecting, ast_channel_redirecting(chan));
  1516. ast_channel_unlock(chan);
  1517. value = ast_skip_blanks(value);
  1518. if (!strcasecmp("orig", member.argv[0])) {
  1519. if (member.argc == 2 && !strcasecmp("reason", member.argv[1])) {
  1520. int reason;
  1521. val = ast_strdupa(value);
  1522. ast_trim_blanks(val);
  1523. if (('0' <= val[0]) && (val[0] <= '9')) {
  1524. reason = atoi(val);
  1525. } else {
  1526. reason = ast_redirecting_reason_parse(val);
  1527. }
  1528. if (reason < 0) {
  1529. /* The argument passed into the function does not correspond to a pre-defined
  1530. * reason, so we can just set the reason string to what was given and set the
  1531. * code to be unknown
  1532. */
  1533. redirecting.orig_reason.code = AST_REDIRECTING_REASON_UNKNOWN;
  1534. redirecting.orig_reason.str = val;
  1535. set_it(chan, &redirecting, NULL);
  1536. } else {
  1537. redirecting.orig_reason.code = reason;
  1538. redirecting.orig_reason.str = "";
  1539. set_it(chan, &redirecting, NULL);
  1540. }
  1541. } else {
  1542. status = party_id_write(&redirecting.orig, member.argc - 1, member.argv + 1,
  1543. value);
  1544. switch (status) {
  1545. case ID_FIELD_VALID:
  1546. set_it(chan, &redirecting, NULL);
  1547. break;
  1548. case ID_FIELD_INVALID:
  1549. break;
  1550. default:
  1551. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1552. break;
  1553. }
  1554. ast_party_redirecting_free(&redirecting);
  1555. }
  1556. } else if (!strcasecmp("from", member.argv[0])) {
  1557. status = party_id_write(&redirecting.from, member.argc - 1, member.argv + 1,
  1558. value);
  1559. switch (status) {
  1560. case ID_FIELD_VALID:
  1561. set_it(chan, &redirecting, NULL);
  1562. break;
  1563. case ID_FIELD_INVALID:
  1564. break;
  1565. default:
  1566. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1567. break;
  1568. }
  1569. ast_party_redirecting_free(&redirecting);
  1570. } else if (!strcasecmp("to", member.argv[0])) {
  1571. status = party_id_write(&redirecting.to, member.argc - 1, member.argv + 1, value);
  1572. switch (status) {
  1573. case ID_FIELD_VALID:
  1574. set_it(chan, &redirecting, NULL);
  1575. break;
  1576. case ID_FIELD_INVALID:
  1577. break;
  1578. default:
  1579. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1580. break;
  1581. }
  1582. ast_party_redirecting_free(&redirecting);
  1583. } else if (member.argc == 1 && !strncasecmp("pres", member.argv[0], 4)) {
  1584. int pres;
  1585. val = ast_strdupa(value);
  1586. ast_trim_blanks(val);
  1587. if (('0' <= val[0]) && (val[0] <= '9')) {
  1588. pres = atoi(val);
  1589. } else {
  1590. pres = ast_parse_caller_presentation(val);
  1591. }
  1592. if (pres < 0) {
  1593. ast_log(LOG_ERROR,
  1594. "Unknown redirecting combined presentation '%s', value unchanged\n", val);
  1595. } else {
  1596. redirecting.from.name.presentation = pres;
  1597. redirecting.from.number.presentation = pres;
  1598. redirecting.to.name.presentation = pres;
  1599. redirecting.to.number.presentation = pres;
  1600. set_it(chan, &redirecting, NULL);
  1601. }
  1602. } else if (member.argc == 1 && !strcasecmp("reason", member.argv[0])) {
  1603. int reason;
  1604. val = ast_strdupa(value);
  1605. ast_trim_blanks(val);
  1606. if (('0' <= val[0]) && (val[0] <= '9')) {
  1607. reason = atoi(val);
  1608. } else {
  1609. reason = ast_redirecting_reason_parse(val);
  1610. }
  1611. if (reason < 0) {
  1612. /* The argument passed into the function does not correspond to a pre-defined
  1613. * reason, so we can just set the reason string to what was given and set the
  1614. * code to be unknown
  1615. */
  1616. redirecting.reason.code = AST_REDIRECTING_REASON_UNKNOWN;
  1617. redirecting.reason.str = val;
  1618. set_it(chan, &redirecting, NULL);
  1619. } else {
  1620. redirecting.reason.code = reason;
  1621. redirecting.reason.str = "";
  1622. set_it(chan, &redirecting, NULL);
  1623. }
  1624. } else if (member.argc == 1 && !strcasecmp("count", member.argv[0])) {
  1625. val = ast_strdupa(value);
  1626. ast_trim_blanks(val);
  1627. if (('0' <= val[0]) && (val[0] <= '9')) {
  1628. redirecting.count = atoi(val);
  1629. set_it(chan, &redirecting, NULL);
  1630. } else {
  1631. ast_log(LOG_ERROR, "Unknown redirecting count '%s', value unchanged\n", val);
  1632. }
  1633. } else if (1 < member.argc && !strcasecmp("priv", member.argv[0])) {
  1634. if (!strcasecmp("orig", member.argv[1])) {
  1635. status = party_id_write(&redirecting.priv_orig, member.argc - 2, member.argv + 2,
  1636. value);
  1637. switch (status) {
  1638. case ID_FIELD_VALID:
  1639. set_it(chan, &redirecting, NULL);
  1640. break;
  1641. case ID_FIELD_INVALID:
  1642. break;
  1643. default:
  1644. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1645. break;
  1646. }
  1647. ast_party_redirecting_free(&redirecting);
  1648. } else if (!strcasecmp("from", member.argv[1])) {
  1649. status = party_id_write(&redirecting.priv_from, member.argc - 2, member.argv + 2,
  1650. value);
  1651. switch (status) {
  1652. case ID_FIELD_VALID:
  1653. set_it(chan, &redirecting, NULL);
  1654. break;
  1655. case ID_FIELD_INVALID:
  1656. break;
  1657. default:
  1658. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1659. break;
  1660. }
  1661. ast_party_redirecting_free(&redirecting);
  1662. } else if (!strcasecmp("to", member.argv[1])) {
  1663. status = party_id_write(&redirecting.priv_to, member.argc - 2, member.argv + 2, value);
  1664. switch (status) {
  1665. case ID_FIELD_VALID:
  1666. set_it(chan, &redirecting, NULL);
  1667. break;
  1668. case ID_FIELD_INVALID:
  1669. break;
  1670. default:
  1671. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1672. break;
  1673. }
  1674. ast_party_redirecting_free(&redirecting);
  1675. } else {
  1676. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1677. }
  1678. } else {
  1679. ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
  1680. }
  1681. return 0;
  1682. }
  1683. static struct ast_custom_function callerid_function = {
  1684. .name = "CALLERID",
  1685. .read = callerid_read,
  1686. .read_max = 256,
  1687. .write = callerid_write,
  1688. };
  1689. static struct ast_custom_function callerpres_function = {
  1690. .name = "CALLERPRES",
  1691. .read = callerpres_read,
  1692. .read_max = 50,
  1693. .write = callerpres_write,
  1694. };
  1695. static struct ast_custom_function connectedline_function = {
  1696. .name = "CONNECTEDLINE",
  1697. .read = connectedline_read,
  1698. .write = connectedline_write,
  1699. };
  1700. static struct ast_custom_function redirecting_function = {
  1701. .name = "REDIRECTING",
  1702. .read = redirecting_read,
  1703. .write = redirecting_write,
  1704. };
  1705. /*!
  1706. * \internal
  1707. * \brief Unload the function module
  1708. *
  1709. * \retval 0 on success.
  1710. * \retval -1 on error.
  1711. */
  1712. static int unload_module(void)
  1713. {
  1714. int res;
  1715. res = ast_custom_function_unregister(&callerpres_function);
  1716. res |= ast_custom_function_unregister(&callerid_function);
  1717. res |= ast_custom_function_unregister(&connectedline_function);
  1718. res |= ast_custom_function_unregister(&redirecting_function);
  1719. return res;
  1720. }
  1721. /*!
  1722. * \internal
  1723. * \brief Load and initialize the function module.
  1724. *
  1725. * \retval AST_MODULE_LOAD_SUCCESS on success.
  1726. * \retval AST_MODULE_LOAD_DECLINE on error.
  1727. */
  1728. static int load_module(void)
  1729. {
  1730. int res;
  1731. res = ast_custom_function_register(&callerpres_function);
  1732. res |= ast_custom_function_register(&callerid_function);
  1733. res |= ast_custom_function_register(&connectedline_function);
  1734. res |= ast_custom_function_register(&redirecting_function);
  1735. return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
  1736. }
  1737. /* Do not wrap the following line. */
  1738. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting)");