conf_config_parser.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2011, Digium, Inc.
  5. *
  6. * David Vossel <dvossel@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief ConfBridge config parser
  21. *
  22. * \author David Vossel <dvossel@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/logger.h"
  30. #include "asterisk/config.h"
  31. #include "asterisk/config_options.h"
  32. #include "include/confbridge.h"
  33. #include "asterisk/astobj2.h"
  34. #include "asterisk/cli.h"
  35. #include "asterisk/bridge_features.h"
  36. #include "asterisk/stringfields.h"
  37. #include "asterisk/pbx.h"
  38. /*** DOCUMENTATION
  39. <configInfo name="app_confbridge" language="en_US">
  40. <synopsis>Conference Bridge Application</synopsis>
  41. <configFile name="confbridge.conf">
  42. <configObject name="global">
  43. <synopsis>Unused, but reserved.</synopsis>
  44. </configObject>
  45. <configObject name="user_profile">
  46. <synopsis>A named profile to apply to specific callers.</synopsis>
  47. <description><para>Callers in a ConfBridge have a profile associated with them
  48. that determine their options. A configuration section is determined to be a
  49. user_profile when the <literal>type</literal> parameter has a value
  50. of <literal>user</literal>.
  51. </para></description>
  52. <configOption name="type">
  53. <synopsis>Define this configuration category as a user profile.</synopsis>
  54. <description><para>The type parameter determines how a context in the
  55. configuration file is interpreted.</para>
  56. <enumlist>
  57. <enum name="user"><para>Configure the context as a <replaceable>user_profile</replaceable></para></enum>
  58. <enum name="bridge"><para>Configure the context as a <replaceable>bridge_profile</replaceable></para></enum>
  59. <enum name="menu"><para>Configure the context as a <replaceable>menu</replaceable></para></enum>
  60. </enumlist>
  61. </description>
  62. </configOption>
  63. <configOption name="admin">
  64. <synopsis>Sets if the user is an admin or not</synopsis>
  65. </configOption>
  66. <configOption name="marked">
  67. <synopsis>Sets if this is a marked user or not</synopsis>
  68. </configOption>
  69. <configOption name="startmuted">
  70. <synopsis>Sets if all users should start out muted</synopsis>
  71. </configOption>
  72. <configOption name="music_on_hold_when_empty">
  73. <synopsis>Play MOH when user is alone or waiting on a marked user</synopsis>
  74. </configOption>
  75. <configOption name="quiet">
  76. <synopsis>Silence enter/leave prompts and user intros for this user</synopsis>
  77. </configOption>
  78. <configOption name="announce_user_count">
  79. <synopsis>Sets if the number of users should be announced to the user</synopsis>
  80. </configOption>
  81. <configOption name="announce_user_count_all">
  82. <synopsis>Announce user count to all the other users when this user joins</synopsis>
  83. <description><para>Sets if the number of users should be announced to all the other users
  84. in the conference when this user joins. This option can be either set to 'yes' or
  85. a number. When set to a number, the announcement will only occur once the user
  86. count is above the specified number.
  87. </para></description>
  88. </configOption>
  89. <configOption name="announce_only_user">
  90. <synopsis>Announce to a user when they join an empty conference</synopsis>
  91. </configOption>
  92. <configOption name="wait_marked">
  93. <synopsis>Sets if the user must wait for a marked user to enter before joining a conference</synopsis>
  94. </configOption>
  95. <configOption name="end_marked">
  96. <synopsis>Kick the user from the conference when the last marked user leaves</synopsis>
  97. </configOption>
  98. <configOption name="talk_detection_events">
  99. <synopsis>Set whether or not notifications of when a user begins and ends talking should be sent out as events over AMI</synopsis>
  100. </configOption>
  101. <configOption name="dtmf_passthrough">
  102. <synopsis>Sets whether or not DTMF should pass through the conference</synopsis>
  103. </configOption>
  104. <configOption name="announce_join_leave">
  105. <synopsis>Prompt user for their name when joining a conference and play it to the conference when they enter</synopsis>
  106. </configOption>
  107. <configOption name="announce_join_leave_review">
  108. <synopsis>Prompt user for their name when joining a conference and play it to the conference when they enter.
  109. The user will be asked to review the recording of their name before entering the conference.</synopsis>
  110. </configOption>
  111. <configOption name="pin">
  112. <synopsis>Sets a PIN the user must enter before joining the conference</synopsis>
  113. </configOption>
  114. <configOption name="music_on_hold_class">
  115. <synopsis>The MOH class to use for this user</synopsis>
  116. </configOption>
  117. <configOption name="announcement">
  118. <synopsis>Sound file to play to the user when they join a conference</synopsis>
  119. </configOption>
  120. <configOption name="denoise">
  121. <synopsis>Apply a denoise filter to the audio before mixing</synopsis>
  122. <description><para>Sets whether or not a denoise filter should be applied
  123. to the audio before mixing or not. Off by default. Requires
  124. <literal>codec_speex</literal> to be built and installed. Do not confuse this option
  125. with <replaceable>drop_silence</replaceable>. Denoise is useful if there is a lot of background
  126. noise for a user as it attempts to remove the noise while preserving
  127. the speech. This option does NOT remove silence from being mixed into
  128. the conference and does come at the cost of a slight performance hit.
  129. </para></description>
  130. </configOption>
  131. <configOption name="dsp_drop_silence">
  132. <synopsis>Drop what Asterisk detects as silence from audio sent to the bridge</synopsis>
  133. <description><para>
  134. This option drops what Asterisk detects as silence from
  135. entering into the bridge. Enabling this option will drastically
  136. improve performance and help remove the buildup of background
  137. noise from the conference. Highly recommended for large conferences
  138. due to its performance enhancements.
  139. </para></description>
  140. </configOption>
  141. <configOption name="dsp_silence_threshold">
  142. <synopsis>The number of milliseconds of detected silence necessary to trigger silence detection</synopsis>
  143. <description><para>
  144. The time in milliseconds of sound falling within the what
  145. the dsp has established as baseline silence before a user
  146. is considered be silent. This value affects several
  147. operations and should not be changed unless the impact
  148. on call quality is fully understood.</para>
  149. <para>What this value affects internally:</para>
  150. <para>
  151. 1. When talk detection AMI events are enabled, this value
  152. determines when the user has stopped talking after a
  153. period of talking. If this value is set too low
  154. AMI events indicating the user has stopped talking
  155. may get falsely sent out when the user briefly pauses
  156. during mid sentence.
  157. </para>
  158. <para>
  159. 2. The <replaceable>drop_silence</replaceable> option depends on this value to
  160. determine when the user's audio should begin to be
  161. dropped from the conference bridge after the user
  162. stops talking. If this value is set too low the user's
  163. audio stream may sound choppy to the other participants.
  164. This is caused by the user transitioning constantly from
  165. silence to talking during mid sentence.
  166. </para>
  167. <para>
  168. The best way to approach this option is to set it slightly above
  169. the maximum amount of ms of silence a user may generate during
  170. natural speech.
  171. </para>
  172. <para>By default this value is 2500ms. Valid values are 1 through 2^31.</para>
  173. </description>
  174. </configOption>
  175. <configOption name="dsp_talking_threshold">
  176. <synopsis>The number of milliseconds of detected non-silence necessary to triger talk detection</synopsis>
  177. <description><para>
  178. The time in milliseconds of sound above what the dsp has
  179. established as base line silence for a user before a user
  180. is considered to be talking. This value affects several
  181. operations and should not be changed unless the impact on
  182. call quality is fully understood.</para>
  183. <para>
  184. What this value affects internally:
  185. </para>
  186. <para>
  187. 1. Audio is only mixed out of a user's incoming audio stream
  188. if talking is detected. If this value is set too
  189. loose the user will hear themselves briefly each
  190. time they begin talking until the dsp has time to
  191. establish that they are in fact talking.
  192. </para>
  193. <para>
  194. 2. When talk detection AMI events are enabled, this value
  195. determines when talking has begun which results in
  196. an AMI event to fire. If this value is set too tight
  197. AMI events may be falsely triggered by variants in
  198. room noise.
  199. </para>
  200. <para>
  201. 3. The <replaceable>drop_silence</replaceable> option depends on this value to determine
  202. when the user's audio should be mixed into the bridge
  203. after periods of silence. If this value is too loose
  204. the beginning of a user's speech will get cut off as they
  205. transition from silence to talking.
  206. </para>
  207. <para>By default this value is 160 ms. Valid values are 1 through 2^31</para>
  208. </description>
  209. </configOption>
  210. <configOption name="jitterbuffer">
  211. <synopsis>Place a jitter buffer on the user's audio stream before audio mixing is performed</synopsis>
  212. <description><para>
  213. Enabling this option places a jitterbuffer on the user's audio stream
  214. before audio mixing is performed. This is highly recommended but will
  215. add a slight delay to the audio. This option is using the <literal>JITTERBUFFER</literal>
  216. dialplan function's default adaptive jitterbuffer. For a more fine tuned
  217. jitterbuffer, disable this option and use the <literal>JITTERBUFFER</literal> dialplan function
  218. on the user before entering the ConfBridge application.
  219. </para></description>
  220. </configOption>
  221. <configOption name="template">
  222. <synopsis>When using the CONFBRIDGE dialplan function, use a user profile as a template for creating a new temporary profile</synopsis>
  223. </configOption>
  224. </configObject>
  225. <configObject name="bridge_profile">
  226. <synopsis>A named profile to apply to specific bridges.</synopsis>
  227. <description><para>ConfBridge bridges have a profile associated with them
  228. that determine their options. A configuration section is determined to be a
  229. <literal>bridge_profile</literal> when the <literal>type</literal> parameter has a value
  230. of <literal>bridge</literal>.
  231. </para></description>
  232. <configOption name="type">
  233. <synopsis>Define this configuration category as a bridge profile</synopsis>
  234. <description><para>The type parameter determines how a context in the
  235. configuration file is interpreted.</para>
  236. <enumlist>
  237. <enum name="user"><para>Configure the context as a <replaceable>user_profile</replaceable></para></enum>
  238. <enum name="bridge"><para>Configure the context as a <replaceable>bridge_profile</replaceable></para></enum>
  239. <enum name="menu"><para>Configure the context as a <replaceable>menu</replaceable></para></enum>
  240. </enumlist>
  241. </description>
  242. </configOption>
  243. <configOption name="jitterbuffer">
  244. <synopsis>Place a jitter buffer on the conference's audio stream</synopsis>
  245. </configOption>
  246. <configOption name="internal_sample_rate">
  247. <synopsis>Set the internal native sample rate for mixing the conference</synopsis>
  248. <description><para>
  249. Sets the internal native sample rate the
  250. conference is mixed at. This is set to automatically
  251. adjust the sample rate to the best quality by default.
  252. Other values can be anything from 8000-192000. If a
  253. sample rate is set that Asterisk does not support, the
  254. closest sample rate Asterisk does support to the one requested
  255. will be used.
  256. </para></description>
  257. </configOption>
  258. <configOption name="language" default="en">
  259. <synopsis>The language used for announcements to the conference.</synopsis>
  260. <description><para>
  261. By default, announcements to a conference use English. Which means
  262. the prompts played to all users within the conference will be
  263. English. By changing the language of a bridge, this will change
  264. the language of the prompts played to all users.
  265. </para></description>
  266. </configOption>
  267. <configOption name="mixing_interval">
  268. <synopsis>Sets the internal mixing interval in milliseconds for the bridge</synopsis>
  269. <description><para>
  270. Sets the internal mixing interval in milliseconds for the bridge. This
  271. number reflects how tight or loose the mixing will be for the conference.
  272. In order to improve performance a larger mixing interval such as 40ms may
  273. be chosen. Using a larger mixing interval comes at the cost of introducing
  274. larger amounts of delay into the bridge. Valid values here are 10, 20, 40,
  275. or 80.
  276. </para></description>
  277. </configOption>
  278. <configOption name="record_conference">
  279. <synopsis>Record the conference starting with the first active user's entrance and ending with the last active user's exit</synopsis>
  280. <description><para>
  281. Records the conference call starting when the first user
  282. enters the room, and ending when the last user exits the room.
  283. The default recorded filename is
  284. <filename>'confbridge-${name of conference bridge}-${start time}.wav'</filename>
  285. and the default format is 8khz slinear. This file will be
  286. located in the configured monitoring directory in <filename>asterisk.conf</filename>.
  287. </para></description>
  288. </configOption>
  289. <configOption name="record_file" default="confbridge-${name of conference bridge}-${start time}.wav">
  290. <synopsis>The filename of the conference recording</synopsis>
  291. <description><para>
  292. When <replaceable>record_conference</replaceable> is set to yes, the specific name of the
  293. record file can be set using this option. Note that since multiple
  294. conferences may use the same bridge profile, this may cause issues
  295. depending on the configuration. It is recommended to only use this
  296. option dynamically with the <literal>CONFBRIDGE()</literal> dialplan function. This
  297. allows the record name to be specified and a unique name to be chosen.
  298. By default, the record_file is stored in Asterisk's spool/monitor directory
  299. with a unique filename starting with the 'confbridge' prefix.
  300. </para></description>
  301. </configOption>
  302. <configOption name="record_file_append" default="yes">
  303. <synopsis>Append to record file when starting/stopping on same conference recording</synopsis>
  304. <description><para>
  305. When <replaceable>record_file_append</replaceable> is set to yes, stopping and starting recording on a
  306. conference adds the new portion to end of current record_file. When this is
  307. set to no, a new <replaceable>record_file</replaceable> is generated every time you start then stop recording
  308. on a conference.
  309. </para></description>
  310. </configOption>
  311. <configOption name="record_file_timestamp" default="yes">
  312. <synopsis>Append the start time to the record_file name so that it is unique.</synopsis>
  313. <description><para>
  314. When <replaceable>record_file_timestamp</replaceable> is set to yes, the start time is appended to
  315. <replaceable>record_file</replaceable> so that the filename is unique. This allows you to specify
  316. a <replaceable>record_file</replaceable> but not overwrite existing recordings.
  317. </para></description>
  318. </configOption>
  319. <configOption name="record_options" default="">
  320. <synopsis>Pass additional options to MixMonitor when recording</synopsis>
  321. <description><para>
  322. Pass additional options to MixMonitor when <replaceable>record_conference</replaceable> is set to yes.
  323. See <literal>MixMonitor</literal> for available options.
  324. </para></description>
  325. </configOption>
  326. <configOption name="record_command" default="">
  327. <synopsis>Execute a command after recording ends</synopsis>
  328. <description><para>
  329. Executes the specified command when recording ends. Any strings matching <literal>^{X}</literal> will be
  330. unescaped to <variable>X</variable>. All variables will be evaluated at the time ConfBridge is called.
  331. </para></description>
  332. </configOption>
  333. <configOption name="video_mode">
  334. <synopsis>Sets how confbridge handles video distribution to the conference participants</synopsis>
  335. <description><para>
  336. Sets how confbridge handles video distribution to the conference participants.
  337. Note that participants wanting to view and be the source of a video feed
  338. <emphasis>MUST</emphasis> be sharing the same video codec. Also, using video in conjunction with
  339. with the jitterbuffer currently results in the audio being slightly out of sync
  340. with the video. This is a result of the jitterbuffer only working on the audio
  341. stream. It is recommended to disable the jitterbuffer when video is used.</para>
  342. <enumlist>
  343. <enum name="none">
  344. <para>No video sources are set by default in the conference. It is still
  345. possible for a user to be set as a video source via AMI or DTMF action
  346. at any time.</para>
  347. </enum>
  348. <enum name="follow_talker">
  349. <para>The video feed will follow whoever is talking and providing video.</para>
  350. </enum>
  351. <enum name="last_marked">
  352. <para>The last marked user to join the conference with video capabilities
  353. will be the single source of video distributed to all participants.
  354. If multiple marked users are capable of video, the last one to join
  355. is always the source, when that user leaves it goes to the one who
  356. joined before them.</para>
  357. </enum>
  358. <enum name="first_marked">
  359. <para>The first marked user to join the conference with video capabilities
  360. is the single source of video distribution among all participants. If
  361. that user leaves, the marked user to join after them becomes the source.</para>
  362. </enum>
  363. </enumlist>
  364. </description>
  365. </configOption>
  366. <configOption name="max_members">
  367. <synopsis>Limit the maximum number of participants for a single conference</synopsis>
  368. <description><para>
  369. This option limits the number of participants for a single
  370. conference to a specific number. By default conferences
  371. have no participant limit. After the limit is reached, the
  372. conference will be locked until someone leaves. Note however
  373. that an Admin user will always be alowed to join the conference
  374. regardless if this limit is reached or not.
  375. </para></description>
  376. </configOption>
  377. <configOption name="^sound_">
  378. <synopsis>Override the various conference bridge sound files</synopsis>
  379. <description><para>
  380. All sounds in the conference are customizable using the bridge profile options below.
  381. Simply state the option followed by the filename or full path of the filename after
  382. the option. Example: <literal>sound_had_joined=conf-hasjoin</literal> This will play the <literal>conf-hasjoin</literal>
  383. sound file found in the sounds directory when announcing someone's name is joining the
  384. conference.</para>
  385. <enumlist>
  386. <enum name="sound_join"><para>The sound played to everyone when someone enters the conference.</para></enum>
  387. <enum name="sound_leave"><para>The sound played to everyone when someone leaves the conference.</para></enum>
  388. <enum name="sound_has_joined"><para>The sound played before announcing someone's name has
  389. joined the conference. This is used for user intros.
  390. Example <literal>"_____ has joined the conference"</literal></para></enum>
  391. <enum name="sound_has_left"><para>The sound played when announcing someone's name has
  392. left the conference. This is used for user intros.
  393. Example <literal>"_____ has left the conference"</literal></para></enum>
  394. <enum name="sound_kicked"><para>The sound played to a user who has been kicked from the conference.</para></enum>
  395. <enum name="sound_muted"><para>The sound played when the mute option it toggled on.</para></enum>
  396. <enum name="sound_unmuted"><para>The sound played when the mute option it toggled off.</para></enum>
  397. <enum name="sound_only_person"><para>The sound played when the user is the only person in the conference.</para></enum>
  398. <enum name="sound_only_one"><para>The sound played to a user when there is only one other
  399. person is in the conference.</para></enum>
  400. <enum name="sound_there_are"><para>The sound played when announcing how many users there
  401. are in a conference.</para></enum>
  402. <enum name="sound_other_in_party"><para>This file is used in conjunction with <literal>sound_there_are</literal>
  403. when announcing how many users there are in the conference.
  404. The sounds are stringed together like this.
  405. <literal>"sound_there_are" ${number of participants} "sound_other_in_party"</literal></para></enum>
  406. <enum name="sound_place_into_conference"><para>The sound played when someone is placed into the conference
  407. after waiting for a marked user.</para></enum>
  408. <enum name="sound_wait_for_leader"><para>The sound played when a user is placed into a conference that
  409. can not start until a marked user enters.</para></enum>
  410. <enum name="sound_leader_has_left"><para>The sound played when the last marked user leaves the conference.</para></enum>
  411. <enum name="sound_get_pin"><para>The sound played when prompting for a conference pin number.</para></enum>
  412. <enum name="sound_invalid_pin"><para>The sound played when an invalid pin is entered too many times.</para></enum>
  413. <enum name="sound_locked"><para>The sound played to a user trying to join a locked conference.</para></enum>
  414. <enum name="sound_locked_now"><para>The sound played to an admin after toggling the conference to locked mode.</para></enum>
  415. <enum name="sound_unlocked_now"><para>The sound played to an admin after toggling the conference to unlocked mode.</para></enum>
  416. <enum name="sound_error_menu"><para>The sound played when an invalid menu option is entered.</para></enum>
  417. </enumlist>
  418. </description>
  419. </configOption>
  420. <configOption name="template">
  421. <synopsis>When using the CONFBRIDGE dialplan function, use a bridge profile as a template for creating a new temporary profile</synopsis>
  422. </configOption>
  423. </configObject>
  424. <configObject name="menu">
  425. <synopsis>A conference user menu</synopsis>
  426. <description>
  427. <para>Conference users, as defined by a <replaceable>conf_user</replaceable>,
  428. can have a DTMF menu assigned to their profile when they enter the
  429. <literal>ConfBridge</literal> application.</para>
  430. </description>
  431. <configOption name="type">
  432. <synopsis>Define this configuration category as a menu</synopsis>
  433. <description><para>The type parameter determines how a context in the
  434. configuration file is interpreted.</para>
  435. <enumlist>
  436. <enum name="user"><para>Configure the context as a <replaceable>user_profile</replaceable></para></enum>
  437. <enum name="bridge"><para>Configure the context as a <replaceable>bridge_profile</replaceable></para></enum>
  438. <enum name="menu"><para>Configure the context as a <replaceable>menu</replaceable></para></enum>
  439. </enumlist>
  440. </description>
  441. </configOption>
  442. <configOption name="template">
  443. <synopsis>When using the CONFBRIDGE dialplan function, use a menu profile as a template for creating a new temporary profile</synopsis>
  444. </configOption>
  445. <configOption name="^[0-9A-D*#]+$">
  446. <synopsis>DTMF sequences to assign various confbridge actions to</synopsis>
  447. <description>
  448. <para>The ConfBridge application also has the ability to apply custom DTMF menus to
  449. each channel using the application. Like the User and Bridge profiles a menu
  450. is passed in to ConfBridge as an argument in the dialplan.</para>
  451. <para>Below is a list of menu actions that can be assigned to a DTMF sequence.</para>
  452. <note><para>
  453. To have the first DTMF digit in a sequence be the '#' character, you need to
  454. escape it. If it is not escaped then normal config file processing will
  455. think it is a directive like #include. For example: The mute setting is
  456. toggled when <literal>#1</literal> is pressed.</para>
  457. <para><literal>\#1=toggle_mute</literal></para>
  458. </note>
  459. <note><para>
  460. A single DTMF sequence can have multiple actions associated with it. This is
  461. accomplished by stringing the actions together and using a <literal>,</literal> as the
  462. delimiter. Example: Both listening and talking volume is reset when <literal>5</literal> is
  463. pressed. <literal>5=reset_talking_volume, reset_listening_volume</literal></para></note>
  464. <enumlist>
  465. <enum name="playback(filename&amp;filename2&amp;...)"><para>
  466. <literal>playback</literal> will play back an audio file to a channel
  467. and then immediately return to the conference.
  468. This file can not be interupted by DTMF.
  469. Multiple files can be chained together using the
  470. <literal>&amp;</literal> character.</para></enum>
  471. <enum name="playback_and_continue(filename&amp;filename2&amp;...)"><para>
  472. <literal>playback_and_continue</literal> will
  473. play back a prompt while continuing to
  474. collect the dtmf sequence. This is useful
  475. when using a menu prompt that describes all
  476. the menu options. Note however that any DTMF
  477. during this action will terminate the prompts
  478. playback. Prompt files can be chained together
  479. using the <literal>&amp;</literal> character as a delimiter.</para></enum>
  480. <enum name="toggle_mute"><para>
  481. Toggle turning on and off mute. Mute will make the user silent
  482. to everyone else, but the user will still be able to listen in.
  483. </para></enum>
  484. <enum name="no_op"><para>
  485. This action does nothing (No Operation). Its only real purpose exists for
  486. being able to reserve a sequence in the config as a menu exit sequence.</para></enum>
  487. <enum name="decrease_listening_volume"><para>
  488. Decreases the channel's listening volume.</para></enum>
  489. <enum name="increase_listening_volume"><para>
  490. Increases the channel's listening volume.</para></enum>
  491. <enum name="reset_listening_volume"><para>
  492. Reset channel's listening volume to default level.</para></enum>
  493. <enum name="decrease_talking_volume"><para>
  494. Decreases the channel's talking volume.</para></enum>
  495. <enum name="increase_talking_volume"><para>
  496. Increases the channel's talking volume.</para></enum>
  497. <enum name="reset_talking_volume"><para>
  498. Reset channel's talking volume to default level.</para></enum>
  499. <enum name="dialplan_exec(context,exten,priority)"><para>
  500. The <literal>dialplan_exec</literal> action allows a user
  501. to escape from the conference and execute
  502. commands in the dialplan. Once the dialplan
  503. exits the user will be put back into the
  504. conference. The possibilities are endless!</para></enum>
  505. <enum name="leave_conference"><para>
  506. This action allows a user to exit the conference and continue
  507. execution in the dialplan.</para></enum>
  508. <enum name="admin_kick_last"><para>
  509. This action allows an Admin to kick the last participant from the
  510. conference. This action will only work for admins which allows
  511. a single menu to be used for both users and admins.</para></enum>
  512. <enum name="admin_toggle_conference_lock"><para>
  513. This action allows an Admin to toggle locking and
  514. unlocking the conference. Non admins can not use
  515. this action even if it is in their menu.</para></enum>
  516. <enum name="set_as_single_video_src"><para>
  517. This action allows any user to set themselves as the
  518. single video source distributed to all participants.
  519. This will make the video feed stick to them regardless
  520. of what the <literal>video_mode</literal> is set to.</para></enum>
  521. <enum name="release_as_single_video_src"><para>
  522. This action allows a user to release themselves as
  523. the video source. If <literal>video_mode</literal> is not set to <literal>none</literal>
  524. this action will result in the conference returning to
  525. whatever video mode the bridge profile is using.</para>
  526. <para>Note that this action will have no effect if the user
  527. is not currently the video source. Also, the user is
  528. not guaranteed by using this action that they will not
  529. become the video source again. The bridge will return
  530. to whatever operation the <literal>video_mode</literal> option is set to
  531. upon release of the video src.</para></enum>
  532. <enum name="admin_toggle_mute_participants"><para>
  533. This action allows an administrator to toggle the mute
  534. state for all non-admins within a conference. All
  535. admin users are unaffected by this option. Note that all
  536. users, regardless of their admin status, are notified
  537. that the conference is muted.</para></enum>
  538. <enum name="participant_count"><para>
  539. This action plays back the number of participants currently
  540. in a conference</para></enum>
  541. </enumlist>
  542. </description>
  543. </configOption>
  544. </configObject>
  545. </configFile>
  546. </configInfo>
  547. ***/
  548. struct confbridge_cfg {
  549. struct ao2_container *bridge_profiles;
  550. struct ao2_container *user_profiles;
  551. struct ao2_container *menus;
  552. };
  553. static int verify_default_profiles(void);
  554. static void *bridge_profile_alloc(const char *category);
  555. static void *bridge_profile_find(struct ao2_container *container, const char *category);
  556. static struct bridge_profile_sounds *bridge_profile_sounds_alloc(void);
  557. static void bridge_profile_destructor(void *obj)
  558. {
  559. struct bridge_profile *b_profile = obj;
  560. ao2_cleanup(b_profile->sounds);
  561. }
  562. static void *bridge_profile_alloc(const char *category)
  563. {
  564. struct bridge_profile *b_profile;
  565. if (!(b_profile = ao2_alloc(sizeof(*b_profile), bridge_profile_destructor))) {
  566. return NULL;
  567. }
  568. if (!(b_profile->sounds = bridge_profile_sounds_alloc())) {
  569. ao2_ref(b_profile, -1);
  570. return NULL;
  571. }
  572. ast_copy_string(b_profile->name, category, sizeof(b_profile->name));
  573. return b_profile;
  574. }
  575. static void *bridge_profile_find(struct ao2_container *container, const char *category)
  576. {
  577. return ao2_find(container, category, OBJ_KEY);
  578. }
  579. static struct aco_type bridge_type = {
  580. .type = ACO_ITEM,
  581. .name = "bridge_profile",
  582. .category_match = ACO_BLACKLIST,
  583. .category = "^general$",
  584. .matchfield = "type",
  585. .matchvalue = "bridge",
  586. .item_alloc = bridge_profile_alloc,
  587. .item_find = bridge_profile_find,
  588. .item_offset = offsetof(struct confbridge_cfg, bridge_profiles),
  589. };
  590. static void *user_profile_alloc(const char *category);
  591. static void *user_profile_find(struct ao2_container *container, const char *category);
  592. static void user_profile_destructor(void *obj)
  593. {
  594. return;
  595. }
  596. static void *user_profile_alloc(const char *category)
  597. {
  598. struct user_profile *u_profile;
  599. if (!(u_profile = ao2_alloc(sizeof(*u_profile), user_profile_destructor))) {
  600. return NULL;
  601. }
  602. ast_copy_string(u_profile->name, category, sizeof(u_profile->name));
  603. return u_profile;
  604. }
  605. static void *user_profile_find(struct ao2_container *container, const char *category)
  606. {
  607. return ao2_find(container, category, OBJ_KEY);
  608. }
  609. static struct aco_type user_type = {
  610. .type = ACO_ITEM,
  611. .name = "user_profile",
  612. .category_match = ACO_BLACKLIST,
  613. .category = "^general$",
  614. .matchfield = "type",
  615. .matchvalue = "user",
  616. .item_alloc = user_profile_alloc,
  617. .item_find = user_profile_find,
  618. .item_offset = offsetof(struct confbridge_cfg, user_profiles),
  619. };
  620. static void *menu_alloc(const char *category);
  621. static void *menu_find(struct ao2_container *container, const char *category);
  622. static void menu_destructor(void *obj);
  623. static void *menu_alloc(const char *category)
  624. {
  625. struct conf_menu *menu;
  626. if (!(menu = ao2_alloc(sizeof(*menu), menu_destructor))) {
  627. return NULL;
  628. }
  629. ast_copy_string(menu->name, category, sizeof(menu->name));
  630. return menu;
  631. }
  632. static void *menu_find(struct ao2_container *container, const char *category)
  633. {
  634. return ao2_find(container, category, OBJ_KEY);
  635. }
  636. static struct aco_type menu_type = {
  637. .type = ACO_ITEM,
  638. .name = "menu",
  639. .category_match = ACO_BLACKLIST,
  640. .category = "^general$",
  641. .matchfield = "type",
  642. .matchvalue = "menu",
  643. .item_alloc = menu_alloc,
  644. .item_find = menu_find,
  645. .item_offset = offsetof(struct confbridge_cfg, menus),
  646. };
  647. /* Used to pass to aco_option_register */
  648. static struct aco_type *bridge_types[] = ACO_TYPES(&bridge_type);
  649. static struct aco_type *menu_types[] = ACO_TYPES(&menu_type);
  650. static struct aco_type *user_types[] = ACO_TYPES(&user_type);
  651. /* The general category is reserved, but unused */
  652. static struct aco_type general_type = {
  653. .type = ACO_GLOBAL,
  654. .name = "global",
  655. .category_match = ACO_WHITELIST,
  656. .category = "^general$",
  657. };
  658. static struct aco_file confbridge_conf = {
  659. .filename = "confbridge.conf",
  660. .types = ACO_TYPES(&bridge_type, &user_type, &menu_type, &general_type),
  661. };
  662. static AO2_GLOBAL_OBJ_STATIC(cfg_handle);
  663. static void *confbridge_cfg_alloc(void);
  664. CONFIG_INFO_STANDARD(cfg_info, cfg_handle, confbridge_cfg_alloc,
  665. .files = ACO_FILES(&confbridge_conf),
  666. .pre_apply_config = verify_default_profiles,
  667. );
  668. /*! bridge profile container functions */
  669. static int bridge_cmp_cb(void *obj, void *arg, int flags)
  670. {
  671. const struct bridge_profile *left = obj;
  672. const struct bridge_profile *right = arg;
  673. const char *right_name = arg;
  674. int cmp;
  675. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  676. default:
  677. case OBJ_POINTER:
  678. right_name = right->name;
  679. /* Fall through */
  680. case OBJ_KEY:
  681. cmp = strcasecmp(left->name, right_name);
  682. break;
  683. case OBJ_PARTIAL_KEY:
  684. cmp = strncasecmp(left->name, right_name, strlen(right_name));
  685. break;
  686. }
  687. return cmp ? 0 : CMP_MATCH;
  688. }
  689. static int bridge_hash_cb(const void *obj, const int flags)
  690. {
  691. const struct bridge_profile *b_profile = obj;
  692. const char *name = obj;
  693. int hash;
  694. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  695. default:
  696. case OBJ_POINTER:
  697. name = b_profile->name;
  698. /* Fall through */
  699. case OBJ_KEY:
  700. hash = ast_str_case_hash(name);
  701. break;
  702. case OBJ_PARTIAL_KEY:
  703. /* Should never happen in hash callback. */
  704. ast_assert(0);
  705. hash = 0;
  706. break;
  707. }
  708. return hash;
  709. }
  710. /*! menu container functions */
  711. static int menu_cmp_cb(void *obj, void *arg, int flags)
  712. {
  713. const struct conf_menu *left = obj;
  714. const struct conf_menu *right = arg;
  715. const char *right_name = arg;
  716. int cmp;
  717. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  718. default:
  719. case OBJ_POINTER:
  720. right_name = right->name;
  721. /* Fall through */
  722. case OBJ_KEY:
  723. cmp = strcasecmp(left->name, right_name);
  724. break;
  725. case OBJ_PARTIAL_KEY:
  726. cmp = strncasecmp(left->name, right_name, strlen(right_name));
  727. break;
  728. }
  729. return cmp ? 0 : CMP_MATCH;
  730. }
  731. static int menu_hash_cb(const void *obj, const int flags)
  732. {
  733. const struct conf_menu *menu = obj;
  734. const char *name = obj;
  735. int hash;
  736. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  737. default:
  738. case OBJ_POINTER:
  739. name = menu->name;
  740. /* Fall through */
  741. case OBJ_KEY:
  742. hash = ast_str_case_hash(name);
  743. break;
  744. case OBJ_PARTIAL_KEY:
  745. /* Should never happen in hash callback. */
  746. ast_assert(0);
  747. hash = 0;
  748. break;
  749. }
  750. return hash;
  751. }
  752. static void menu_destructor(void *obj)
  753. {
  754. struct conf_menu *menu = obj;
  755. struct conf_menu_entry *entry = NULL;
  756. while ((entry = AST_LIST_REMOVE_HEAD(&menu->entries, entry))) {
  757. conf_menu_entry_destroy(entry);
  758. ast_free(entry);
  759. }
  760. }
  761. /*! User profile container functions */
  762. static int user_cmp_cb(void *obj, void *arg, int flags)
  763. {
  764. const struct user_profile *left = obj;
  765. const struct user_profile *right = arg;
  766. const char *right_name = arg;
  767. int cmp;
  768. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  769. default:
  770. case OBJ_POINTER:
  771. right_name = right->name;
  772. /* Fall through */
  773. case OBJ_KEY:
  774. cmp = strcasecmp(left->name, right_name);
  775. break;
  776. case OBJ_PARTIAL_KEY:
  777. cmp = strncasecmp(left->name, right_name, strlen(right_name));
  778. break;
  779. }
  780. return cmp ? 0 : CMP_MATCH;
  781. }
  782. static int user_hash_cb(const void *obj, const int flags)
  783. {
  784. const struct user_profile *u_profile = obj;
  785. const char *name = obj;
  786. int hash;
  787. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  788. default:
  789. case OBJ_POINTER:
  790. name = u_profile->name;
  791. /* Fall through */
  792. case OBJ_KEY:
  793. hash = ast_str_case_hash(name);
  794. break;
  795. case OBJ_PARTIAL_KEY:
  796. /* Should never happen in hash callback. */
  797. ast_assert(0);
  798. hash = 0;
  799. break;
  800. }
  801. return hash;
  802. }
  803. /*! Bridge Profile Sounds functions */
  804. static void bridge_profile_sounds_destroy_cb(void *obj)
  805. {
  806. struct bridge_profile_sounds *sounds = obj;
  807. ast_string_field_free_memory(sounds);
  808. }
  809. static struct bridge_profile_sounds *bridge_profile_sounds_alloc(void)
  810. {
  811. struct bridge_profile_sounds *sounds = ao2_alloc(sizeof(*sounds), bridge_profile_sounds_destroy_cb);
  812. if (!sounds) {
  813. return NULL;
  814. }
  815. if (ast_string_field_init(sounds, 512)) {
  816. ao2_ref(sounds, -1);
  817. return NULL;
  818. }
  819. return sounds;
  820. }
  821. static int set_sound(const char *sound_name, const char *sound_file, struct bridge_profile *b_profile)
  822. {
  823. struct bridge_profile_sounds *sounds = b_profile->sounds;
  824. if (ast_strlen_zero(sound_file)) {
  825. return -1;
  826. }
  827. if (!strcasecmp(sound_name, "sound_only_person")) {
  828. ast_string_field_set(sounds, onlyperson, sound_file);
  829. } else if (!strcasecmp(sound_name, "sound_only_one")) {
  830. ast_string_field_set(sounds, onlyone, sound_file);
  831. } else if (!strcasecmp(sound_name, "sound_has_joined")) {
  832. ast_string_field_set(sounds, hasjoin, sound_file);
  833. } else if (!strcasecmp(sound_name, "sound_has_left")) {
  834. ast_string_field_set(sounds, hasleft, sound_file);
  835. } else if (!strcasecmp(sound_name, "sound_kicked")) {
  836. ast_string_field_set(sounds, kicked, sound_file);
  837. } else if (!strcasecmp(sound_name, "sound_muted")) {
  838. ast_string_field_set(sounds, muted, sound_file);
  839. } else if (!strcasecmp(sound_name, "sound_unmuted")) {
  840. ast_string_field_set(sounds, unmuted, sound_file);
  841. } else if (!strcasecmp(sound_name, "sound_there_are")) {
  842. ast_string_field_set(sounds, thereare, sound_file);
  843. } else if (!strcasecmp(sound_name, "sound_other_in_party")) {
  844. ast_string_field_set(sounds, otherinparty, sound_file);
  845. } else if (!strcasecmp(sound_name, "sound_place_into_conference")) {
  846. static int deprecation_warning = 1;
  847. if (deprecation_warning) {
  848. ast_log(LOG_WARNING, "sound_place_into_conference is deprecated"
  849. " and unused. Use sound_begin for similar functionality.");
  850. deprecation_warning = 0;
  851. }
  852. ast_string_field_set(sounds, placeintoconf, sound_file);
  853. } else if (!strcasecmp(sound_name, "sound_wait_for_leader")) {
  854. ast_string_field_set(sounds, waitforleader, sound_file);
  855. } else if (!strcasecmp(sound_name, "sound_leader_has_left")) {
  856. ast_string_field_set(sounds, leaderhasleft, sound_file);
  857. } else if (!strcasecmp(sound_name, "sound_get_pin")) {
  858. ast_string_field_set(sounds, getpin, sound_file);
  859. } else if (!strcasecmp(sound_name, "sound_invalid_pin")) {
  860. ast_string_field_set(sounds, invalidpin, sound_file);
  861. } else if (!strcasecmp(sound_name, "sound_locked")) {
  862. ast_string_field_set(sounds, locked, sound_file);
  863. } else if (!strcasecmp(sound_name, "sound_unlocked_now")) {
  864. ast_string_field_set(sounds, unlockednow, sound_file);
  865. } else if (!strcasecmp(sound_name, "sound_locked_now")) {
  866. ast_string_field_set(sounds, lockednow, sound_file);
  867. } else if (!strcasecmp(sound_name, "sound_error_menu")) {
  868. ast_string_field_set(sounds, errormenu, sound_file);
  869. } else if (!strcasecmp(sound_name, "sound_join")) {
  870. ast_string_field_set(sounds, join, sound_file);
  871. } else if (!strcasecmp(sound_name, "sound_leave")) {
  872. ast_string_field_set(sounds, leave, sound_file);
  873. } else if (!strcasecmp(sound_name, "sound_participants_muted")) {
  874. ast_string_field_set(sounds, participantsmuted, sound_file);
  875. } else if (!strcasecmp(sound_name, "sound_participants_unmuted")) {
  876. ast_string_field_set(sounds, participantsunmuted, sound_file);
  877. } else if (!strcasecmp(sound_name, "sound_begin")) {
  878. ast_string_field_set(sounds, begin, sound_file);
  879. } else {
  880. return -1;
  881. }
  882. return 0;
  883. }
  884. /*! CONFBRIDGE dialplan function functions and channel datastore. */
  885. struct func_confbridge_data {
  886. struct bridge_profile b_profile;
  887. struct user_profile u_profile;
  888. struct conf_menu *menu;
  889. unsigned int b_usable:1; /*!< Tells if bridge profile is usable or not */
  890. unsigned int u_usable:1; /*!< Tells if user profile is usable or not */
  891. unsigned int m_usable:1; /*!< Tells if menu profile is usable or not */
  892. };
  893. static void func_confbridge_data_destructor(struct func_confbridge_data *b_data)
  894. {
  895. conf_bridge_profile_destroy(&b_data->b_profile);
  896. ao2_cleanup(b_data->menu);
  897. ast_free(b_data);
  898. }
  899. static void func_confbridge_destroy_cb(void *data)
  900. {
  901. struct func_confbridge_data *b_data = data;
  902. func_confbridge_data_destructor(b_data);
  903. };
  904. static const struct ast_datastore_info confbridge_datastore = {
  905. .type = "confbridge",
  906. .destroy = func_confbridge_destroy_cb
  907. };
  908. int func_confbridge_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)
  909. {
  910. struct ast_datastore *datastore;
  911. struct func_confbridge_data *b_data;
  912. char *parse;
  913. struct ast_variable tmpvar = { 0, };
  914. AST_DECLARE_APP_ARGS(args,
  915. AST_APP_ARG(type);
  916. AST_APP_ARG(option);
  917. );
  918. if (!chan) {
  919. ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
  920. return -1;
  921. }
  922. /* parse all the required arguments and make sure they exist. */
  923. if (ast_strlen_zero(data)) {
  924. return -1;
  925. }
  926. parse = ast_strdupa(data);
  927. AST_STANDARD_APP_ARGS(args, parse);
  928. if (ast_strlen_zero(args.type) || ast_strlen_zero(args.option)) {
  929. return -1;
  930. }
  931. ast_channel_lock(chan);
  932. datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
  933. if (!datastore) {
  934. datastore = ast_datastore_alloc(&confbridge_datastore, NULL);
  935. if (!datastore) {
  936. ast_channel_unlock(chan);
  937. return 0;
  938. }
  939. b_data = ast_calloc(1, sizeof(*b_data));
  940. if (!b_data) {
  941. ast_channel_unlock(chan);
  942. ast_datastore_free(datastore);
  943. return 0;
  944. }
  945. datastore->data = b_data;
  946. b_data->b_profile.sounds = bridge_profile_sounds_alloc();
  947. if (!b_data->b_profile.sounds) {
  948. ast_channel_unlock(chan);
  949. ast_datastore_free(datastore);
  950. return 0;
  951. }
  952. if (!(b_data->menu = menu_alloc("dialplan"))) {
  953. ast_channel_unlock(chan);
  954. ast_datastore_free(datastore);
  955. return 0;
  956. }
  957. ast_channel_datastore_add(chan, datastore);
  958. } else {
  959. b_data = datastore->data;
  960. }
  961. ast_channel_unlock(chan);
  962. /* SET(CONFBRIDGE(type,option)=value) */
  963. if (!value) {
  964. value = "";
  965. }
  966. tmpvar.name = args.option;
  967. tmpvar.value = value;
  968. tmpvar.file = "CONFBRIDGE";
  969. if (!strcasecmp(args.type, "bridge")) {
  970. if (!strcasecmp(args.option, "clear")) {
  971. b_data->b_usable = 0;
  972. conf_bridge_profile_destroy(&b_data->b_profile);
  973. memset(&b_data->b_profile, 0, sizeof(b_data->b_profile)) ;
  974. if (!(b_data->b_profile.sounds = bridge_profile_sounds_alloc())) {
  975. /* If this reallocation fails, the datastore has become unusable and must be destroyed. */
  976. ast_channel_lock(chan);
  977. ast_channel_datastore_remove(chan, datastore);
  978. ast_channel_unlock(chan);
  979. ast_datastore_free(datastore);
  980. }
  981. return 0;
  982. } else if (!aco_process_var(&bridge_type, "dialplan", &tmpvar, &b_data->b_profile)) {
  983. b_data->b_usable = 1;
  984. return 0;
  985. }
  986. } else if (!strcasecmp(args.type, "user")) {
  987. if (!strcasecmp(args.option, "clear")) {
  988. b_data->u_usable = 0;
  989. user_profile_destructor(&b_data->u_profile);
  990. memset(&b_data->u_profile, 0, sizeof(b_data->u_profile));
  991. return 0;
  992. } else if (!aco_process_var(&user_type, "dialplan", &tmpvar, &b_data->u_profile)) {
  993. b_data->u_usable = 1;
  994. return 0;
  995. }
  996. } else if (!strcasecmp(args.type, "menu")) {
  997. if (!strcasecmp(args.option, "clear")) {
  998. b_data->m_usable = 0;
  999. ao2_cleanup(b_data->menu);
  1000. if (!(b_data->menu = menu_alloc("dialplan"))) {
  1001. /* If this reallocation fails, the datastore has become unusable and must be destroyed */
  1002. ast_channel_lock(chan);
  1003. ast_channel_datastore_remove(chan, datastore);
  1004. ast_channel_unlock(chan);
  1005. ast_datastore_free(datastore);
  1006. }
  1007. return 0;
  1008. } else if (!aco_process_var(&menu_type, "dialplan", &tmpvar, b_data->menu)) {
  1009. b_data->m_usable = 1;
  1010. return 0;
  1011. }
  1012. }
  1013. ast_log(LOG_WARNING, "%s(%s,%s) cannot be set to '%s'. Invalid type, option, or value.\n",
  1014. cmd, args.type, args.option, value);
  1015. return -1;
  1016. }
  1017. static int add_action_to_menu_entry(struct conf_menu_entry *menu_entry, enum conf_menu_action_id id, char *databuf)
  1018. {
  1019. struct conf_menu_action *menu_action = ast_calloc(1, sizeof(*menu_action));
  1020. if (!menu_action) {
  1021. return -1;
  1022. }
  1023. menu_action->id = id;
  1024. switch (id) {
  1025. case MENU_ACTION_NOOP:
  1026. case MENU_ACTION_TOGGLE_MUTE:
  1027. case MENU_ACTION_INCREASE_LISTENING:
  1028. case MENU_ACTION_DECREASE_LISTENING:
  1029. case MENU_ACTION_INCREASE_TALKING:
  1030. case MENU_ACTION_DECREASE_TALKING:
  1031. case MENU_ACTION_RESET_LISTENING:
  1032. case MENU_ACTION_RESET_TALKING:
  1033. case MENU_ACTION_ADMIN_TOGGLE_LOCK:
  1034. case MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS:
  1035. case MENU_ACTION_PARTICIPANT_COUNT:
  1036. case MENU_ACTION_ADMIN_KICK_LAST:
  1037. case MENU_ACTION_LEAVE:
  1038. case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
  1039. case MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC:
  1040. break;
  1041. case MENU_ACTION_PLAYBACK:
  1042. case MENU_ACTION_PLAYBACK_AND_CONTINUE:
  1043. if (!(ast_strlen_zero(databuf))) {
  1044. ast_copy_string(menu_action->data.playback_file, databuf, sizeof(menu_action->data.playback_file));
  1045. } else {
  1046. ast_free(menu_action);
  1047. return -1;
  1048. }
  1049. break;
  1050. case MENU_ACTION_DIALPLAN_EXEC:
  1051. if (!(ast_strlen_zero(databuf))) {
  1052. AST_DECLARE_APP_ARGS(args,
  1053. AST_APP_ARG(context);
  1054. AST_APP_ARG(exten);
  1055. AST_APP_ARG(priority);
  1056. );
  1057. AST_STANDARD_APP_ARGS(args, databuf);
  1058. if (!ast_strlen_zero(args.context)) {
  1059. ast_copy_string(menu_action->data.dialplan_args.context,
  1060. args.context,
  1061. sizeof(menu_action->data.dialplan_args.context));
  1062. }
  1063. if (!ast_strlen_zero(args.exten)) {
  1064. ast_copy_string(menu_action->data.dialplan_args.exten,
  1065. args.exten,
  1066. sizeof(menu_action->data.dialplan_args.exten));
  1067. }
  1068. menu_action->data.dialplan_args.priority = 1; /* 1 by default */
  1069. if (!ast_strlen_zero(args.priority) &&
  1070. (sscanf(args.priority, "%30d", &menu_action->data.dialplan_args.priority) != 1)) {
  1071. /* invalid priority */
  1072. ast_free(menu_action);
  1073. return -1;
  1074. }
  1075. } else {
  1076. ast_free(menu_action);
  1077. return -1;
  1078. }
  1079. };
  1080. AST_LIST_INSERT_TAIL(&menu_entry->actions, menu_action, action);
  1081. return 0;
  1082. }
  1083. static int add_menu_entry(struct conf_menu *menu, const char *dtmf, const char *action_names)
  1084. {
  1085. struct conf_menu_entry *menu_entry = NULL, *cur = NULL;
  1086. int res = 0;
  1087. char *tmp_action_names = ast_strdupa(action_names);
  1088. char *action = NULL;
  1089. char *action_args;
  1090. char *tmp;
  1091. char buf[PATH_MAX];
  1092. char *delimiter = ",";
  1093. if (!(menu_entry = ast_calloc(1, sizeof(*menu_entry)))) {
  1094. return -1;
  1095. }
  1096. for (;;) {
  1097. char *comma;
  1098. char *startbrace;
  1099. char *endbrace;
  1100. unsigned int action_len;
  1101. if (ast_strlen_zero(tmp_action_names)) {
  1102. break;
  1103. }
  1104. startbrace = strchr(tmp_action_names, '(');
  1105. endbrace = strchr(tmp_action_names, ')');
  1106. comma = strchr(tmp_action_names, ',');
  1107. /* If the next action has brackets with comma delimited arguments in it,
  1108. * make the delimeter ')' instead of a comma to preserve the argments */
  1109. if (startbrace && endbrace && comma && (comma > startbrace && comma < endbrace)) {
  1110. delimiter = ")";
  1111. } else {
  1112. delimiter = ",";
  1113. }
  1114. if (!(action = strsep(&tmp_action_names, delimiter))) {
  1115. break;
  1116. }
  1117. action = ast_strip(action);
  1118. if (ast_strlen_zero(action)) {
  1119. continue;
  1120. }
  1121. action_len = strlen(action);
  1122. ast_copy_string(menu_entry->dtmf, dtmf, sizeof(menu_entry->dtmf));
  1123. if (!strcasecmp(action, "toggle_mute")) {
  1124. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_TOGGLE_MUTE, NULL);
  1125. } else if (!strcasecmp(action, "no_op")) {
  1126. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_NOOP, NULL);
  1127. } else if (!strcasecmp(action, "increase_listening_volume")) {
  1128. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_INCREASE_LISTENING, NULL);
  1129. } else if (!strcasecmp(action, "decrease_listening_volume")) {
  1130. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_DECREASE_LISTENING, NULL);
  1131. } else if (!strcasecmp(action, "increase_talking_volume")) {
  1132. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_INCREASE_TALKING, NULL);
  1133. } else if (!strcasecmp(action, "reset_listening_volume")) {
  1134. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_RESET_LISTENING, NULL);
  1135. } else if (!strcasecmp(action, "reset_talking_volume")) {
  1136. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_RESET_TALKING, NULL);
  1137. } else if (!strcasecmp(action, "decrease_talking_volume")) {
  1138. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_DECREASE_TALKING, NULL);
  1139. } else if (!strcasecmp(action, "admin_toggle_conference_lock")) {
  1140. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_TOGGLE_LOCK, NULL);
  1141. } else if (!strcasecmp(action, "admin_toggle_mute_participants")) {
  1142. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS, NULL);
  1143. } else if (!strcasecmp(action, "participant_count")) {
  1144. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_PARTICIPANT_COUNT, NULL);
  1145. } else if (!strcasecmp(action, "admin_kick_last")) {
  1146. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_ADMIN_KICK_LAST, NULL);
  1147. } else if (!strcasecmp(action, "leave_conference")) {
  1148. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_LEAVE, NULL);
  1149. } else if (!strcasecmp(action, "set_as_single_video_src")) {
  1150. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_SET_SINGLE_VIDEO_SRC, NULL);
  1151. } else if (!strcasecmp(action, "release_as_single_video_src")) {
  1152. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC, NULL);
  1153. } else if (!strncasecmp(action, "dialplan_exec(", 14)) {
  1154. ast_copy_string(buf, action, sizeof(buf));
  1155. action_args = buf;
  1156. if ((action_args = strchr(action, '('))) {
  1157. action_args++;
  1158. }
  1159. /* it is possible that this argument may or may not
  1160. * have a closing brace at this point, it all depends on if
  1161. * comma delimited arguments were provided */
  1162. if ((tmp = strchr(action, ')'))) {
  1163. *tmp = '\0';
  1164. }
  1165. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_DIALPLAN_EXEC, action_args);
  1166. } else if (action_len >= 21 && !strncasecmp(action, "playback_and_continue(", 22)) {
  1167. ast_copy_string(buf, action, sizeof(buf));
  1168. action_args = buf;
  1169. if ((action_args = strchr(action, '(')) && (tmp = strrchr(action_args, ')'))) {
  1170. *tmp = '\0';
  1171. action_args++;
  1172. }
  1173. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_PLAYBACK_AND_CONTINUE, action_args);
  1174. } else if (action_len >= 8 && !strncasecmp(action, "playback(", 9)) {
  1175. ast_copy_string(buf, action, sizeof(buf));
  1176. action_args = buf;
  1177. if ((action_args = strchr(action, '(')) && (tmp = strrchr(action_args, ')'))) {
  1178. *tmp = '\0';
  1179. action_args++;
  1180. }
  1181. res |= add_action_to_menu_entry(menu_entry, MENU_ACTION_PLAYBACK, action_args);
  1182. }
  1183. }
  1184. /* if adding any of the actions failed, bail */
  1185. if (res) {
  1186. struct conf_menu_action *menu_action;
  1187. while ((menu_action = AST_LIST_REMOVE_HEAD(&menu_entry->actions, action))) {
  1188. ast_free(menu_action);
  1189. }
  1190. ast_free(menu_entry);
  1191. return -1;
  1192. }
  1193. /* remove any list entry with an identical DTMF sequence for overrides */
  1194. AST_LIST_TRAVERSE_SAFE_BEGIN(&menu->entries, cur, entry) {
  1195. if (!strcasecmp(cur->dtmf, menu_entry->dtmf)) {
  1196. AST_LIST_REMOVE_CURRENT(entry);
  1197. ast_free(cur);
  1198. break;
  1199. }
  1200. }
  1201. AST_LIST_TRAVERSE_SAFE_END;
  1202. AST_LIST_INSERT_TAIL(&menu->entries, menu_entry, entry);
  1203. return 0;
  1204. }
  1205. static char *complete_user_profile_name(const char *line, const char *word, int pos, int state)
  1206. {
  1207. int which = 0;
  1208. char *res = NULL;
  1209. int wordlen = strlen(word);
  1210. struct ao2_iterator i;
  1211. struct user_profile *u_profile = NULL;
  1212. RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
  1213. if (!cfg) {
  1214. return NULL;
  1215. }
  1216. i = ao2_iterator_init(cfg->user_profiles, 0);
  1217. while ((u_profile = ao2_iterator_next(&i))) {
  1218. if (!strncasecmp(u_profile->name, word, wordlen) && ++which > state) {
  1219. res = ast_strdup(u_profile->name);
  1220. ao2_ref(u_profile, -1);
  1221. break;
  1222. }
  1223. ao2_ref(u_profile, -1);
  1224. }
  1225. ao2_iterator_destroy(&i);
  1226. return res;
  1227. }
  1228. static char *handle_cli_confbridge_show_user_profiles(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1229. {
  1230. struct ao2_iterator it;
  1231. struct user_profile *u_profile;
  1232. RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
  1233. switch (cmd) {
  1234. case CLI_INIT:
  1235. e->command = "confbridge show profile users";
  1236. e->usage =
  1237. "Usage confbridge show profile users\n";
  1238. return NULL;
  1239. case CLI_GENERATE:
  1240. return NULL;
  1241. }
  1242. if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
  1243. return NULL;
  1244. }
  1245. ast_cli(a->fd,"--------- User Profiles -----------\n");
  1246. ao2_lock(cfg->user_profiles);
  1247. it = ao2_iterator_init(cfg->user_profiles, 0);
  1248. while ((u_profile = ao2_iterator_next(&it))) {
  1249. ast_cli(a->fd,"%s\n", u_profile->name);
  1250. ao2_ref(u_profile, -1);
  1251. }
  1252. ao2_iterator_destroy(&it);
  1253. ao2_unlock(cfg->user_profiles);
  1254. return CLI_SUCCESS;
  1255. }
  1256. static char *handle_cli_confbridge_show_user_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1257. {
  1258. struct user_profile u_profile;
  1259. switch (cmd) {
  1260. case CLI_INIT:
  1261. e->command = "confbridge show profile user";
  1262. e->usage =
  1263. "Usage confbridge show profile user [<profile name>]\n";
  1264. return NULL;
  1265. case CLI_GENERATE:
  1266. if (a->pos == 4) {
  1267. return complete_user_profile_name(a->line, a->word, a->pos, a->n);
  1268. }
  1269. return NULL;
  1270. }
  1271. if (a->argc != 5) {
  1272. return CLI_SHOWUSAGE;
  1273. }
  1274. if (!(conf_find_user_profile(NULL, a->argv[4], &u_profile))) {
  1275. ast_cli(a->fd, "No conference user profile named '%s' found!\n", a->argv[4]);
  1276. return CLI_SUCCESS;
  1277. }
  1278. ast_cli(a->fd,"--------------------------------------------\n");
  1279. ast_cli(a->fd,"Name: %s\n",
  1280. u_profile.name);
  1281. ast_cli(a->fd,"Admin: %s\n",
  1282. u_profile.flags & USER_OPT_ADMIN ?
  1283. "true" : "false");
  1284. ast_cli(a->fd,"Marked User: %s\n",
  1285. u_profile.flags & USER_OPT_MARKEDUSER ?
  1286. "true" : "false");
  1287. ast_cli(a->fd,"Start Muted: %s\n",
  1288. u_profile.flags & USER_OPT_STARTMUTED?
  1289. "true" : "false");
  1290. ast_cli(a->fd,"MOH When Empty: %s\n",
  1291. u_profile.flags & USER_OPT_MUSICONHOLD ?
  1292. "enabled" : "disabled");
  1293. ast_cli(a->fd,"MOH Class: %s\n",
  1294. ast_strlen_zero(u_profile.moh_class) ?
  1295. "default" : u_profile.moh_class);
  1296. ast_cli(a->fd,"Announcement: %s\n",
  1297. u_profile.announcement);
  1298. ast_cli(a->fd,"Quiet: %s\n",
  1299. u_profile.flags & USER_OPT_QUIET ?
  1300. "enabled" : "disabled");
  1301. ast_cli(a->fd,"Wait Marked: %s\n",
  1302. u_profile.flags & USER_OPT_WAITMARKED ?
  1303. "enabled" : "disabled");
  1304. ast_cli(a->fd,"END Marked: %s\n",
  1305. u_profile.flags & USER_OPT_ENDMARKED ?
  1306. "enabled" : "disabled");
  1307. ast_cli(a->fd,"Drop_silence: %s\n",
  1308. u_profile.flags & USER_OPT_DROP_SILENCE ?
  1309. "enabled" : "disabled");
  1310. ast_cli(a->fd,"Silence Threshold: %ums\n",
  1311. u_profile.silence_threshold);
  1312. ast_cli(a->fd,"Talking Threshold: %ums\n",
  1313. u_profile.talking_threshold);
  1314. ast_cli(a->fd,"Denoise: %s\n",
  1315. u_profile.flags & USER_OPT_DENOISE ?
  1316. "enabled" : "disabled");
  1317. ast_cli(a->fd,"Jitterbuffer: %s\n",
  1318. u_profile.flags & USER_OPT_JITTERBUFFER ?
  1319. "enabled" : "disabled");
  1320. ast_cli(a->fd,"Talk Detect Events: %s\n",
  1321. u_profile.flags & USER_OPT_TALKER_DETECT ?
  1322. "enabled" : "disabled");
  1323. ast_cli(a->fd,"DTMF Pass Through: %s\n",
  1324. u_profile.flags & USER_OPT_DTMF_PASS ?
  1325. "enabled" : "disabled");
  1326. ast_cli(a->fd,"PIN: %s\n",
  1327. ast_strlen_zero(u_profile.pin) ?
  1328. "None" : u_profile.pin);
  1329. ast_cli(a->fd,"Announce User Count: %s\n",
  1330. u_profile.flags & USER_OPT_ANNOUNCEUSERCOUNT ?
  1331. "enabled" : "disabled");
  1332. ast_cli(a->fd,"Announce join/leave: %s\n",
  1333. u_profile.flags & (USER_OPT_ANNOUNCE_JOIN_LEAVE | USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW) ?
  1334. u_profile.flags & USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW ?
  1335. "enabled (with review)" : "enabled" : "disabled");
  1336. ast_cli(a->fd,"Announce User Count all: %s\n",
  1337. u_profile.flags & USER_OPT_ANNOUNCEUSERCOUNTALL ?
  1338. "enabled" : "disabled");
  1339. ast_cli(a->fd,"\n");
  1340. return CLI_SUCCESS;
  1341. }
  1342. static char *complete_bridge_profile_name(const char *line, const char *word, int pos, int state)
  1343. {
  1344. int which = 0;
  1345. char *res = NULL;
  1346. int wordlen = strlen(word);
  1347. struct ao2_iterator i;
  1348. struct bridge_profile *b_profile = NULL;
  1349. RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
  1350. if (!cfg) {
  1351. return NULL;
  1352. }
  1353. i = ao2_iterator_init(cfg->bridge_profiles, 0);
  1354. while ((b_profile = ao2_iterator_next(&i))) {
  1355. if (!strncasecmp(b_profile->name, word, wordlen) && ++which > state) {
  1356. res = ast_strdup(b_profile->name);
  1357. ao2_ref(b_profile, -1);
  1358. break;
  1359. }
  1360. ao2_ref(b_profile, -1);
  1361. }
  1362. ao2_iterator_destroy(&i);
  1363. return res;
  1364. }
  1365. static char *handle_cli_confbridge_show_bridge_profiles(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1366. {
  1367. struct ao2_iterator it;
  1368. struct bridge_profile *b_profile;
  1369. RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
  1370. switch (cmd) {
  1371. case CLI_INIT:
  1372. e->command = "confbridge show profile bridges";
  1373. e->usage =
  1374. "Usage confbridge show profile bridges\n";
  1375. return NULL;
  1376. case CLI_GENERATE:
  1377. return NULL;
  1378. }
  1379. if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
  1380. return NULL;
  1381. }
  1382. ast_cli(a->fd,"--------- Bridge Profiles -----------\n");
  1383. ao2_lock(cfg->bridge_profiles);
  1384. it = ao2_iterator_init(cfg->bridge_profiles, 0);
  1385. while ((b_profile = ao2_iterator_next(&it))) {
  1386. ast_cli(a->fd,"%s\n", b_profile->name);
  1387. ao2_ref(b_profile, -1);
  1388. }
  1389. ao2_iterator_destroy(&it);
  1390. ao2_unlock(cfg->bridge_profiles);
  1391. return CLI_SUCCESS;
  1392. }
  1393. static char *handle_cli_confbridge_show_bridge_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1394. {
  1395. struct bridge_profile b_profile;
  1396. char tmp[64];
  1397. switch (cmd) {
  1398. case CLI_INIT:
  1399. e->command = "confbridge show profile bridge";
  1400. e->usage =
  1401. "Usage confbridge show profile bridge <profile name>\n";
  1402. return NULL;
  1403. case CLI_GENERATE:
  1404. if (a->pos == 4) {
  1405. return complete_bridge_profile_name(a->line, a->word, a->pos, a->n);
  1406. }
  1407. return NULL;
  1408. }
  1409. if (a->argc != 5) {
  1410. return CLI_SHOWUSAGE;
  1411. }
  1412. if (!(conf_find_bridge_profile(NULL, a->argv[4], &b_profile))) {
  1413. ast_cli(a->fd, "No conference bridge profile named '%s' found!\n", a->argv[4]);
  1414. return CLI_SUCCESS;
  1415. }
  1416. ast_cli(a->fd,"--------------------------------------------\n");
  1417. ast_cli(a->fd,"Name: %s\n", b_profile.name);
  1418. ast_cli(a->fd,"Language: %s\n", b_profile.language);
  1419. if (b_profile.internal_sample_rate) {
  1420. snprintf(tmp, sizeof(tmp), "%u", b_profile.internal_sample_rate);
  1421. } else {
  1422. ast_copy_string(tmp, "auto", sizeof(tmp));
  1423. }
  1424. ast_cli(a->fd,"Internal Sample Rate: %s\n", tmp);
  1425. if (b_profile.mix_interval) {
  1426. ast_cli(a->fd,"Mixing Interval: %u\n", b_profile.mix_interval);
  1427. } else {
  1428. ast_cli(a->fd,"Mixing Interval: Default 20ms\n");
  1429. }
  1430. ast_cli(a->fd,"Record Conference: %s\n",
  1431. b_profile.flags & BRIDGE_OPT_RECORD_CONFERENCE ?
  1432. "yes" : "no");
  1433. ast_cli(a->fd,"Record File Append: %s\n",
  1434. b_profile.flags & BRIDGE_OPT_RECORD_FILE_APPEND ?
  1435. "yes" : "no");
  1436. ast_cli(a->fd,"Record File Timestamp: %s\n",
  1437. b_profile.flags & BRIDGE_OPT_RECORD_FILE_TIMESTAMP ?
  1438. "yes" : "no");
  1439. ast_cli(a->fd,"Record File: %s\n",
  1440. ast_strlen_zero(b_profile.rec_file) ? "Auto Generated" :
  1441. b_profile.rec_file);
  1442. ast_cli(a->fd,"Record Options: %s\n",
  1443. b_profile.rec_options);
  1444. ast_cli(a->fd,"Record Command: %s\n",
  1445. b_profile.rec_command);
  1446. if (b_profile.max_members) {
  1447. ast_cli(a->fd,"Max Members: %u\n", b_profile.max_members);
  1448. } else {
  1449. ast_cli(a->fd,"Max Members: No Limit\n");
  1450. }
  1451. switch (b_profile.flags
  1452. & (BRIDGE_OPT_VIDEO_SRC_LAST_MARKED | BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
  1453. | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
  1454. case BRIDGE_OPT_VIDEO_SRC_LAST_MARKED:
  1455. ast_cli(a->fd, "Video Mode: last_marked\n");
  1456. break;
  1457. case BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED:
  1458. ast_cli(a->fd, "Video Mode: first_marked\n");
  1459. break;
  1460. case BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER:
  1461. ast_cli(a->fd, "Video Mode: follow_talker\n");
  1462. break;
  1463. case 0:
  1464. ast_cli(a->fd, "Video Mode: no video\n");
  1465. break;
  1466. default:
  1467. /* Opps. We have more than one video mode flag set. */
  1468. ast_assert(0);
  1469. break;
  1470. }
  1471. ast_cli(a->fd,"sound_only_person: %s\n", conf_get_sound(CONF_SOUND_ONLY_PERSON, b_profile.sounds));
  1472. ast_cli(a->fd,"sound_only_one: %s\n", conf_get_sound(CONF_SOUND_ONLY_ONE, b_profile.sounds));
  1473. ast_cli(a->fd,"sound_has_joined: %s\n", conf_get_sound(CONF_SOUND_HAS_JOINED, b_profile.sounds));
  1474. ast_cli(a->fd,"sound_has_left: %s\n", conf_get_sound(CONF_SOUND_HAS_LEFT, b_profile.sounds));
  1475. ast_cli(a->fd,"sound_kicked: %s\n", conf_get_sound(CONF_SOUND_KICKED, b_profile.sounds));
  1476. ast_cli(a->fd,"sound_muted: %s\n", conf_get_sound(CONF_SOUND_MUTED, b_profile.sounds));
  1477. ast_cli(a->fd,"sound_unmuted: %s\n", conf_get_sound(CONF_SOUND_UNMUTED, b_profile.sounds));
  1478. ast_cli(a->fd,"sound_there_are: %s\n", conf_get_sound(CONF_SOUND_THERE_ARE, b_profile.sounds));
  1479. ast_cli(a->fd,"sound_other_in_party: %s\n", conf_get_sound(CONF_SOUND_OTHER_IN_PARTY, b_profile.sounds));
  1480. ast_cli(a->fd,"sound_place_into_conference: %s\n", conf_get_sound(CONF_SOUND_PLACE_IN_CONF, b_profile.sounds));
  1481. ast_cli(a->fd,"sound_wait_for_leader: %s\n", conf_get_sound(CONF_SOUND_WAIT_FOR_LEADER, b_profile.sounds));
  1482. ast_cli(a->fd,"sound_leader_has_left: %s\n", conf_get_sound(CONF_SOUND_LEADER_HAS_LEFT, b_profile.sounds));
  1483. ast_cli(a->fd,"sound_get_pin: %s\n", conf_get_sound(CONF_SOUND_GET_PIN, b_profile.sounds));
  1484. ast_cli(a->fd,"sound_invalid_pin: %s\n", conf_get_sound(CONF_SOUND_INVALID_PIN, b_profile.sounds));
  1485. ast_cli(a->fd,"sound_locked: %s\n", conf_get_sound(CONF_SOUND_LOCKED, b_profile.sounds));
  1486. ast_cli(a->fd,"sound_unlocked_now: %s\n", conf_get_sound(CONF_SOUND_UNLOCKED_NOW, b_profile.sounds));
  1487. ast_cli(a->fd,"sound_lockednow: %s\n", conf_get_sound(CONF_SOUND_LOCKED_NOW, b_profile.sounds));
  1488. ast_cli(a->fd,"sound_error_menu: %s\n", conf_get_sound(CONF_SOUND_ERROR_MENU, b_profile.sounds));
  1489. ast_cli(a->fd,"sound_join: %s\n", conf_get_sound(CONF_SOUND_JOIN, b_profile.sounds));
  1490. ast_cli(a->fd,"sound_leave: %s\n", conf_get_sound(CONF_SOUND_LEAVE, b_profile.sounds));
  1491. ast_cli(a->fd,"sound_participants_muted: %s\n", conf_get_sound(CONF_SOUND_PARTICIPANTS_MUTED, b_profile.sounds));
  1492. ast_cli(a->fd,"sound_participants_unmuted: %s\n", conf_get_sound(CONF_SOUND_PARTICIPANTS_UNMUTED, b_profile.sounds));
  1493. ast_cli(a->fd,"sound_begin: %s\n", conf_get_sound(CONF_SOUND_BEGIN, b_profile.sounds));
  1494. ast_cli(a->fd,"\n");
  1495. conf_bridge_profile_destroy(&b_profile);
  1496. return CLI_SUCCESS;
  1497. }
  1498. static char *complete_menu_name(const char *line, const char *word, int pos, int state)
  1499. {
  1500. int which = 0;
  1501. char *res = NULL;
  1502. int wordlen = strlen(word);
  1503. struct ao2_iterator i;
  1504. struct conf_menu *menu = NULL;
  1505. RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
  1506. if (!cfg) {
  1507. return NULL;
  1508. }
  1509. i = ao2_iterator_init(cfg->menus, 0);
  1510. while ((menu = ao2_iterator_next(&i))) {
  1511. if (!strncasecmp(menu->name, word, wordlen) && ++which > state) {
  1512. res = ast_strdup(menu->name);
  1513. ao2_ref(menu, -1);
  1514. break;
  1515. }
  1516. ao2_ref(menu, -1);
  1517. }
  1518. ao2_iterator_destroy(&i);
  1519. return res;
  1520. }
  1521. static char *handle_cli_confbridge_show_menus(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1522. {
  1523. struct ao2_iterator it;
  1524. struct conf_menu *menu;
  1525. RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
  1526. switch (cmd) {
  1527. case CLI_INIT:
  1528. e->command = "confbridge show menus";
  1529. e->usage =
  1530. "Usage confbridge show profile menus\n";
  1531. return NULL;
  1532. case CLI_GENERATE:
  1533. return NULL;
  1534. }
  1535. if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
  1536. return NULL;
  1537. }
  1538. ast_cli(a->fd,"--------- Menus -----------\n");
  1539. ao2_lock(cfg->menus);
  1540. it = ao2_iterator_init(cfg->menus, 0);
  1541. while ((menu = ao2_iterator_next(&it))) {
  1542. ast_cli(a->fd,"%s\n", menu->name);
  1543. ao2_ref(menu, -1);
  1544. }
  1545. ao2_iterator_destroy(&it);
  1546. ao2_unlock(cfg->menus);
  1547. return CLI_SUCCESS;
  1548. }
  1549. static char *handle_cli_confbridge_show_menu(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1550. {
  1551. RAII_VAR(struct conf_menu *, menu, NULL, ao2_cleanup);
  1552. RAII_VAR(struct confbridge_cfg *, cfg, NULL, ao2_cleanup);
  1553. struct conf_menu_entry *menu_entry = NULL;
  1554. struct conf_menu_action *menu_action = NULL;
  1555. switch (cmd) {
  1556. case CLI_INIT:
  1557. e->command = "confbridge show menu";
  1558. e->usage =
  1559. "Usage confbridge show menu [<menu name>]\n";
  1560. return NULL;
  1561. case CLI_GENERATE:
  1562. if (a->pos == 3) {
  1563. return complete_menu_name(a->line, a->word, a->pos, a->n);
  1564. }
  1565. return NULL;
  1566. }
  1567. if (a->argc != 4) {
  1568. return CLI_SHOWUSAGE;
  1569. }
  1570. if (!(cfg = ao2_global_obj_ref(cfg_handle))) {
  1571. return NULL;
  1572. }
  1573. if (!(menu = menu_find(cfg->menus, a->argv[3]))) {
  1574. ast_cli(a->fd, "No conference menu named '%s' found!\n", a->argv[3]);
  1575. return CLI_SUCCESS;
  1576. }
  1577. ao2_lock(menu);
  1578. ast_cli(a->fd,"Name: %s\n", menu->name);
  1579. AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
  1580. int action_num = 0;
  1581. ast_cli(a->fd, "%s=", menu_entry->dtmf);
  1582. AST_LIST_TRAVERSE(&menu_entry->actions, menu_action, action) {
  1583. if (action_num) {
  1584. ast_cli(a->fd, ", ");
  1585. }
  1586. switch (menu_action->id) {
  1587. case MENU_ACTION_TOGGLE_MUTE:
  1588. ast_cli(a->fd, "toggle_mute");
  1589. break;
  1590. case MENU_ACTION_NOOP:
  1591. ast_cli(a->fd, "no_op");
  1592. break;
  1593. case MENU_ACTION_INCREASE_LISTENING:
  1594. ast_cli(a->fd, "increase_listening_volume");
  1595. break;
  1596. case MENU_ACTION_DECREASE_LISTENING:
  1597. ast_cli(a->fd, "decrease_listening_volume");
  1598. break;
  1599. case MENU_ACTION_RESET_LISTENING:
  1600. ast_cli(a->fd, "reset_listening_volume");
  1601. break;
  1602. case MENU_ACTION_RESET_TALKING:
  1603. ast_cli(a->fd, "reset_talking_volume");
  1604. break;
  1605. case MENU_ACTION_INCREASE_TALKING:
  1606. ast_cli(a->fd, "increase_talking_volume");
  1607. break;
  1608. case MENU_ACTION_DECREASE_TALKING:
  1609. ast_cli(a->fd, "decrease_talking_volume");
  1610. break;
  1611. case MENU_ACTION_PLAYBACK:
  1612. ast_cli(a->fd, "playback(%s)", menu_action->data.playback_file);
  1613. break;
  1614. case MENU_ACTION_PLAYBACK_AND_CONTINUE:
  1615. ast_cli(a->fd, "playback_and_continue(%s)", menu_action->data.playback_file);
  1616. break;
  1617. case MENU_ACTION_DIALPLAN_EXEC:
  1618. ast_cli(a->fd, "dialplan_exec(%s,%s,%d)",
  1619. menu_action->data.dialplan_args.context,
  1620. menu_action->data.dialplan_args.exten,
  1621. menu_action->data.dialplan_args.priority);
  1622. break;
  1623. case MENU_ACTION_ADMIN_TOGGLE_LOCK:
  1624. ast_cli(a->fd, "admin_toggle_conference_lock");
  1625. break;
  1626. case MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS:
  1627. ast_cli(a->fd, "admin_toggle_mute_participants");
  1628. break;
  1629. case MENU_ACTION_PARTICIPANT_COUNT:
  1630. ast_cli(a->fd, "participant_count");
  1631. break;
  1632. case MENU_ACTION_ADMIN_KICK_LAST:
  1633. ast_cli(a->fd, "admin_kick_last");
  1634. break;
  1635. case MENU_ACTION_LEAVE:
  1636. ast_cli(a->fd, "leave_conference");
  1637. break;
  1638. case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
  1639. ast_cli(a->fd, "set_as_single_video_src");
  1640. break;
  1641. case MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC:
  1642. ast_cli(a->fd, "release_as_single_video_src");
  1643. break;
  1644. }
  1645. action_num++;
  1646. }
  1647. ast_cli(a->fd,"\n");
  1648. }
  1649. ao2_unlock(menu);
  1650. return CLI_SUCCESS;
  1651. }
  1652. static struct ast_cli_entry cli_confbridge_parser[] = {
  1653. AST_CLI_DEFINE(handle_cli_confbridge_show_user_profile, "Show a conference user profile."),
  1654. AST_CLI_DEFINE(handle_cli_confbridge_show_bridge_profile, "Show a conference bridge profile."),
  1655. AST_CLI_DEFINE(handle_cli_confbridge_show_menu, "Show a conference menu"),
  1656. AST_CLI_DEFINE(handle_cli_confbridge_show_user_profiles, "Show a list of conference user profiles."),
  1657. AST_CLI_DEFINE(handle_cli_confbridge_show_bridge_profiles, "Show a list of conference bridge profiles."),
  1658. AST_CLI_DEFINE(handle_cli_confbridge_show_menus, "Show a list of conference menus"),
  1659. };
  1660. static void confbridge_cfg_destructor(void *obj)
  1661. {
  1662. struct confbridge_cfg *cfg = obj;
  1663. ao2_cleanup(cfg->user_profiles);
  1664. ao2_cleanup(cfg->bridge_profiles);
  1665. ao2_cleanup(cfg->menus);
  1666. }
  1667. void *confbridge_cfg_alloc(void)
  1668. {
  1669. struct confbridge_cfg *cfg;
  1670. if (!(cfg = ao2_alloc(sizeof(*cfg), confbridge_cfg_destructor))) {
  1671. return NULL;
  1672. }
  1673. if (!(cfg->user_profiles = ao2_container_alloc(283, user_hash_cb, user_cmp_cb))) {
  1674. goto error;
  1675. }
  1676. if (!(cfg->bridge_profiles = ao2_container_alloc(283, bridge_hash_cb, bridge_cmp_cb))) {
  1677. goto error;
  1678. }
  1679. if (!(cfg->menus = ao2_container_alloc(283, menu_hash_cb, menu_cmp_cb))) {
  1680. goto error;
  1681. }
  1682. return cfg;
  1683. error:
  1684. ao2_ref(cfg, -1);
  1685. return NULL;
  1686. }
  1687. static int announce_user_count_all_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1688. {
  1689. struct user_profile *u_profile = obj;
  1690. if (strcasecmp(var->name, "announce_user_count_all")) {
  1691. return -1;
  1692. }
  1693. if (ast_true(var->value)) {
  1694. u_profile->flags = u_profile->flags | USER_OPT_ANNOUNCEUSERCOUNTALL;
  1695. } else if (ast_false(var->value)) {
  1696. u_profile->flags = u_profile->flags & ~USER_OPT_ANNOUNCEUSERCOUNTALL;
  1697. } else if (sscanf(var->value, "%30u", &u_profile->announce_user_count_all_after) == 1) {
  1698. u_profile->flags = u_profile->flags | USER_OPT_ANNOUNCEUSERCOUNTALL;
  1699. } else {
  1700. return -1;
  1701. }
  1702. return 0;
  1703. }
  1704. static int mix_interval_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1705. {
  1706. struct bridge_profile *b_profile = obj;
  1707. if (strcasecmp(var->name, "mixing_interval")) {
  1708. return -1;
  1709. }
  1710. if (sscanf(var->value, "%30u", &b_profile->mix_interval) != 1) {
  1711. return -1;
  1712. }
  1713. switch (b_profile->mix_interval) {
  1714. case 10:
  1715. case 20:
  1716. case 40:
  1717. case 80:
  1718. return 0;
  1719. default:
  1720. return -1;
  1721. }
  1722. }
  1723. static int video_mode_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1724. {
  1725. struct bridge_profile *b_profile = obj;
  1726. if (strcasecmp(var->name, "video_mode")) {
  1727. return -1;
  1728. }
  1729. if (!strcasecmp(var->value, "first_marked")) {
  1730. ast_set_flags_to(b_profile,
  1731. BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
  1732. | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
  1733. | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER,
  1734. BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED);
  1735. } else if (!strcasecmp(var->value, "last_marked")) {
  1736. ast_set_flags_to(b_profile,
  1737. BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
  1738. | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
  1739. | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER,
  1740. BRIDGE_OPT_VIDEO_SRC_LAST_MARKED);
  1741. } else if (!strcasecmp(var->value, "follow_talker")) {
  1742. ast_set_flags_to(b_profile,
  1743. BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
  1744. | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
  1745. | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER,
  1746. BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER);
  1747. } else if (!strcasecmp(var->value, "none")) {
  1748. ast_clear_flag(b_profile,
  1749. BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED
  1750. | BRIDGE_OPT_VIDEO_SRC_LAST_MARKED
  1751. | BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER);
  1752. } else {
  1753. return -1;
  1754. }
  1755. return 0;
  1756. }
  1757. static int user_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1758. {
  1759. struct user_profile *u_profile = obj;
  1760. return conf_find_user_profile(NULL, var->value, u_profile) ? 0 : -1;
  1761. }
  1762. static int bridge_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1763. {
  1764. struct bridge_profile *b_profile = obj;
  1765. struct bridge_profile_sounds *sounds = bridge_profile_sounds_alloc();
  1766. struct bridge_profile_sounds *oldsounds = b_profile->sounds;
  1767. if (!sounds) {
  1768. return -1;
  1769. }
  1770. if (!(conf_find_bridge_profile(NULL, var->value, b_profile))) {
  1771. ao2_ref(sounds, -1);
  1772. return -1;
  1773. }
  1774. /* Using a bridge profile as a template is a little complicated due to the sounds. Since the sounds
  1775. * structure of a dynamic profile will need to be altered, a completely new sounds structure must be
  1776. * created instead of simply holding a reference to the one built by the config file. */
  1777. ast_string_field_set(sounds, onlyperson, b_profile->sounds->onlyperson);
  1778. ast_string_field_set(sounds, onlyone, b_profile->sounds->onlyone);
  1779. ast_string_field_set(sounds, hasjoin, b_profile->sounds->hasjoin);
  1780. ast_string_field_set(sounds, hasleft, b_profile->sounds->hasleft);
  1781. ast_string_field_set(sounds, kicked, b_profile->sounds->kicked);
  1782. ast_string_field_set(sounds, muted, b_profile->sounds->muted);
  1783. ast_string_field_set(sounds, unmuted, b_profile->sounds->unmuted);
  1784. ast_string_field_set(sounds, thereare, b_profile->sounds->thereare);
  1785. ast_string_field_set(sounds, otherinparty, b_profile->sounds->otherinparty);
  1786. ast_string_field_set(sounds, placeintoconf, b_profile->sounds->placeintoconf);
  1787. ast_string_field_set(sounds, waitforleader, b_profile->sounds->waitforleader);
  1788. ast_string_field_set(sounds, leaderhasleft, b_profile->sounds->leaderhasleft);
  1789. ast_string_field_set(sounds, getpin, b_profile->sounds->getpin);
  1790. ast_string_field_set(sounds, invalidpin, b_profile->sounds->invalidpin);
  1791. ast_string_field_set(sounds, locked, b_profile->sounds->locked);
  1792. ast_string_field_set(sounds, unlockednow, b_profile->sounds->unlockednow);
  1793. ast_string_field_set(sounds, lockednow, b_profile->sounds->lockednow);
  1794. ast_string_field_set(sounds, errormenu, b_profile->sounds->errormenu);
  1795. ast_string_field_set(sounds, join, b_profile->sounds->join);
  1796. ast_string_field_set(sounds, leave, b_profile->sounds->leave);
  1797. ast_string_field_set(sounds, participantsmuted, b_profile->sounds->participantsmuted);
  1798. ast_string_field_set(sounds, participantsunmuted, b_profile->sounds->participantsunmuted);
  1799. ast_string_field_set(sounds, begin, b_profile->sounds->begin);
  1800. ao2_ref(b_profile->sounds, -1); /* sounds struct copied over to it from the template by reference only. */
  1801. ao2_ref(oldsounds, -1); /* original sounds struct we don't need anymore */
  1802. b_profile->sounds = sounds; /* the new sounds struct that is a deep copy of the one from the template. */
  1803. return 0;
  1804. }
  1805. static int copy_menu_entry(struct conf_menu_entry *dst, struct conf_menu_entry *src)
  1806. {
  1807. struct conf_menu_action *menu_action;
  1808. struct conf_menu_action *new_menu_action;
  1809. ast_copy_string(dst->dtmf, src->dtmf, sizeof(dst->dtmf));
  1810. AST_LIST_HEAD_INIT_NOLOCK(&dst->actions);
  1811. AST_LIST_TRAVERSE(&src->actions, menu_action, action) {
  1812. if (!(new_menu_action = ast_calloc(1, sizeof(*new_menu_action)))) {
  1813. return -1;
  1814. }
  1815. memcpy(new_menu_action, menu_action, sizeof(*new_menu_action));
  1816. AST_LIST_NEXT(new_menu_action, action) = NULL;
  1817. AST_LIST_INSERT_TAIL(&dst->actions, new_menu_action, action);
  1818. }
  1819. return 0;
  1820. }
  1821. static int conf_menu_profile_copy(struct conf_menu *dst, struct conf_menu *src)
  1822. {
  1823. /* Copy each menu item to the dst struct */
  1824. struct conf_menu_entry *cur;
  1825. AST_LIST_TRAVERSE(&src->entries, cur, entry) {
  1826. struct conf_menu_entry *cpy;
  1827. if (!(cpy = ast_calloc(1, sizeof(*cpy)))) {
  1828. return -1;
  1829. }
  1830. if (copy_menu_entry(cpy, cur)) {
  1831. conf_menu_entry_destroy(cpy);
  1832. ast_free(cpy);
  1833. return -1;
  1834. }
  1835. AST_LIST_INSERT_TAIL(&dst->entries, cpy, entry);
  1836. }
  1837. return 0;
  1838. }
  1839. static int menu_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1840. {
  1841. struct conf_menu *dst_menu = obj;
  1842. struct confbridge_cfg *cfg = aco_pending_config(&cfg_info);
  1843. RAII_VAR(struct conf_menu *, src_menu, NULL, ao2_cleanup);
  1844. if (!cfg) {
  1845. return 0;
  1846. }
  1847. if (!(src_menu = ao2_find(cfg->menus, var->value, OBJ_KEY))) {
  1848. return -1;
  1849. }
  1850. if (conf_menu_profile_copy(dst_menu, src_menu)) {
  1851. return -1;
  1852. }
  1853. return 0;
  1854. }
  1855. static int sound_option_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1856. {
  1857. set_sound(var->name, var->value, obj);
  1858. return 0;
  1859. }
  1860. static int menu_option_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
  1861. {
  1862. add_menu_entry(obj, var->name, var->value);
  1863. return 0;
  1864. }
  1865. static int verify_default_profiles(void)
  1866. {
  1867. RAII_VAR(struct user_profile *, user_profile, NULL, ao2_cleanup);
  1868. RAII_VAR(struct bridge_profile *, bridge_profile, NULL, ao2_cleanup);
  1869. RAII_VAR(struct conf_menu *, menu_profile, NULL, ao2_cleanup);
  1870. struct confbridge_cfg *cfg = aco_pending_config(&cfg_info);
  1871. if (!cfg) {
  1872. return 0;
  1873. }
  1874. bridge_profile = ao2_find(cfg->bridge_profiles, DEFAULT_BRIDGE_PROFILE, OBJ_KEY);
  1875. if (!bridge_profile) {
  1876. bridge_profile = bridge_profile_alloc(DEFAULT_BRIDGE_PROFILE);
  1877. if (!bridge_profile) {
  1878. return -1;
  1879. }
  1880. ast_log(AST_LOG_NOTICE, "Adding %s profile to app_confbridge\n", DEFAULT_BRIDGE_PROFILE);
  1881. aco_set_defaults(&bridge_type, DEFAULT_BRIDGE_PROFILE, bridge_profile);
  1882. ao2_link(cfg->bridge_profiles, bridge_profile);
  1883. }
  1884. user_profile = ao2_find(cfg->user_profiles, DEFAULT_USER_PROFILE, OBJ_KEY);
  1885. if (!user_profile) {
  1886. user_profile = user_profile_alloc(DEFAULT_USER_PROFILE);
  1887. if (!user_profile) {
  1888. return -1;
  1889. }
  1890. ast_log(AST_LOG_NOTICE, "Adding %s profile to app_confbridge\n", DEFAULT_USER_PROFILE);
  1891. aco_set_defaults(&user_type, DEFAULT_USER_PROFILE, user_profile);
  1892. ao2_link(cfg->user_profiles, user_profile);
  1893. }
  1894. menu_profile = ao2_find(cfg->menus, DEFAULT_MENU_PROFILE, OBJ_KEY);
  1895. if (!menu_profile) {
  1896. menu_profile = menu_alloc(DEFAULT_MENU_PROFILE);
  1897. if (!menu_profile) {
  1898. return -1;
  1899. }
  1900. ast_log(AST_LOG_NOTICE, "Adding %s menu to app_confbridge\n", DEFAULT_MENU_PROFILE);
  1901. aco_set_defaults(&menu_type, DEFAULT_MENU_PROFILE, menu_profile);
  1902. ao2_link(cfg->menus, menu_profile);
  1903. }
  1904. return 0;
  1905. }
  1906. int conf_load_config(void)
  1907. {
  1908. if (aco_info_init(&cfg_info)) {
  1909. return -1;
  1910. }
  1911. /* User options */
  1912. aco_option_register(&cfg_info, "type", ACO_EXACT, user_types, NULL, OPT_NOOP_T, 0, 0);
  1913. aco_option_register(&cfg_info, "admin", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ADMIN);
  1914. aco_option_register(&cfg_info, "marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_MARKEDUSER);
  1915. aco_option_register(&cfg_info, "startmuted", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_STARTMUTED);
  1916. aco_option_register(&cfg_info, "music_on_hold_when_empty", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_MUSICONHOLD);
  1917. aco_option_register(&cfg_info, "quiet", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_QUIET);
  1918. aco_option_register_custom(&cfg_info, "announce_user_count_all", ACO_EXACT, user_types, "no", announce_user_count_all_handler, 0);
  1919. aco_option_register(&cfg_info, "announce_user_count", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANNOUNCEUSERCOUNT);
  1920. /* Negative logic. Defaults to "yes" and evaluates with ast_false(). If !ast_false(), USER_OPT_NOONLYPERSON is cleared */
  1921. aco_option_register(&cfg_info, "announce_only_user", ACO_EXACT, user_types, "yes", OPT_BOOLFLAG_T, 0, FLDSET(struct user_profile, flags), USER_OPT_NOONLYPERSON);
  1922. aco_option_register(&cfg_info, "wait_marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_WAITMARKED);
  1923. aco_option_register(&cfg_info, "end_marked", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ENDMARKED);
  1924. aco_option_register(&cfg_info, "talk_detection_events", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_TALKER_DETECT);
  1925. aco_option_register(&cfg_info, "dtmf_passthrough", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_DTMF_PASS);
  1926. aco_option_register(&cfg_info, "announce_join_leave", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANNOUNCE_JOIN_LEAVE);
  1927. aco_option_register(&cfg_info, "announce_join_leave_review", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW);
  1928. aco_option_register(&cfg_info, "pin", ACO_EXACT, user_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct user_profile, pin));
  1929. aco_option_register(&cfg_info, "music_on_hold_class", ACO_EXACT, user_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct user_profile, moh_class));
  1930. aco_option_register(&cfg_info, "announcement", ACO_EXACT, user_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct user_profile, announcement));
  1931. aco_option_register(&cfg_info, "denoise", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_DENOISE);
  1932. aco_option_register(&cfg_info, "dsp_drop_silence", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_DROP_SILENCE);
  1933. aco_option_register(&cfg_info, "dsp_silence_threshold", ACO_EXACT, user_types, __stringify(DEFAULT_SILENCE_THRESHOLD), OPT_UINT_T, 0, FLDSET(struct user_profile, silence_threshold));
  1934. aco_option_register(&cfg_info, "dsp_talking_threshold", ACO_EXACT, user_types, __stringify(DEFAULT_TALKING_THRESHOLD), OPT_UINT_T, 0, FLDSET(struct user_profile, talking_threshold));
  1935. aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, user_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct user_profile, flags), USER_OPT_JITTERBUFFER);
  1936. /* This option should only be used with the CONFBRIDGE dialplan function */
  1937. aco_option_register_custom(&cfg_info, "template", ACO_EXACT, user_types, NULL, user_template_handler, 0);
  1938. /* XXX ASTERISK-21271 need a user supplied bridge merge_priority to merge ConfBridges (default = 1, range 1-INT_MAX) */
  1939. /* Bridge options */
  1940. aco_option_register(&cfg_info, "type", ACO_EXACT, bridge_types, NULL, OPT_NOOP_T, 0, 0);
  1941. aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), USER_OPT_JITTERBUFFER);
  1942. /* "auto" will fail to parse as a uint, but we use PARSE_DEFAULT to set the value to 0 in that case, which is the value that auto resolves to */
  1943. aco_option_register(&cfg_info, "internal_sample_rate", ACO_EXACT, bridge_types, "0", OPT_UINT_T, PARSE_DEFAULT, FLDSET(struct bridge_profile, internal_sample_rate), 0);
  1944. aco_option_register_custom(&cfg_info, "mixing_interval", ACO_EXACT, bridge_types, "20", mix_interval_handler, 0);
  1945. aco_option_register(&cfg_info, "record_conference", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_CONFERENCE);
  1946. aco_option_register_custom(&cfg_info, "video_mode", ACO_EXACT, bridge_types, NULL, video_mode_handler, 0);
  1947. aco_option_register(&cfg_info, "record_file_append", ACO_EXACT, bridge_types, "yes", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_FILE_APPEND);
  1948. aco_option_register(&cfg_info, "record_file_timestamp", ACO_EXACT, bridge_types, "yes", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_FILE_TIMESTAMP);
  1949. aco_option_register(&cfg_info, "max_members", ACO_EXACT, bridge_types, "0", OPT_UINT_T, 0, FLDSET(struct bridge_profile, max_members));
  1950. aco_option_register(&cfg_info, "record_file", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_file));
  1951. aco_option_register(&cfg_info, "record_options", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_options));
  1952. aco_option_register(&cfg_info, "record_command", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_command));
  1953. aco_option_register(&cfg_info, "language", ACO_EXACT, bridge_types, "en", OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, language));
  1954. aco_option_register_custom(&cfg_info, "^sound_", ACO_REGEX, bridge_types, NULL, sound_option_handler, 0);
  1955. /* This option should only be used with the CONFBRIDGE dialplan function */
  1956. aco_option_register_custom(&cfg_info, "template", ACO_EXACT, bridge_types, NULL, bridge_template_handler, 0);
  1957. /* Menu options */
  1958. aco_option_register(&cfg_info, "type", ACO_EXACT, menu_types, NULL, OPT_NOOP_T, 0, 0);
  1959. aco_option_register_custom(&cfg_info, "template", ACO_EXACT, menu_types, NULL, menu_template_handler, 0);
  1960. aco_option_register_custom(&cfg_info, "^[0-9A-D*#]+$", ACO_REGEX, menu_types, NULL, menu_option_handler, 0);
  1961. if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
  1962. goto error;
  1963. }
  1964. if (ast_cli_register_multiple(cli_confbridge_parser, ARRAY_LEN(cli_confbridge_parser))) {
  1965. goto error;
  1966. }
  1967. return 0;
  1968. error:
  1969. conf_destroy_config();
  1970. return -1;
  1971. }
  1972. int conf_reload_config(void)
  1973. {
  1974. if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
  1975. /* On a reload, just keep the config we already have in place. */
  1976. return -1;
  1977. }
  1978. return 0;
  1979. }
  1980. static void conf_user_profile_copy(struct user_profile *dst, struct user_profile *src)
  1981. {
  1982. *dst = *src;
  1983. }
  1984. const struct user_profile *conf_find_user_profile(struct ast_channel *chan, const char *user_profile_name, struct user_profile *result)
  1985. {
  1986. struct user_profile *tmp2;
  1987. struct ast_datastore *datastore = NULL;
  1988. struct func_confbridge_data *b_data = NULL;
  1989. RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
  1990. if (chan && ast_strlen_zero(user_profile_name)) {
  1991. ast_channel_lock(chan);
  1992. datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
  1993. ast_channel_unlock(chan);
  1994. if (datastore) {
  1995. b_data = datastore->data;
  1996. if (b_data->u_usable) {
  1997. conf_user_profile_copy(result, &b_data->u_profile);
  1998. return result;
  1999. }
  2000. }
  2001. }
  2002. if (!cfg) {
  2003. return NULL;
  2004. }
  2005. if (ast_strlen_zero(user_profile_name)) {
  2006. user_profile_name = DEFAULT_USER_PROFILE;
  2007. }
  2008. if (!(tmp2 = ao2_find(cfg->user_profiles, user_profile_name, OBJ_KEY))) {
  2009. return NULL;
  2010. }
  2011. ao2_lock(tmp2);
  2012. conf_user_profile_copy(result, tmp2);
  2013. ao2_unlock(tmp2);
  2014. ao2_ref(tmp2, -1);
  2015. return result;
  2016. }
  2017. void conf_bridge_profile_copy(struct bridge_profile *dst, struct bridge_profile *src)
  2018. {
  2019. *dst = *src;
  2020. if (src->sounds) {
  2021. ao2_ref(src->sounds, +1);
  2022. }
  2023. }
  2024. void conf_bridge_profile_destroy(struct bridge_profile *b_profile)
  2025. {
  2026. if (b_profile->sounds) {
  2027. ao2_ref(b_profile->sounds, -1);
  2028. b_profile->sounds = NULL;
  2029. }
  2030. }
  2031. const struct bridge_profile *conf_find_bridge_profile(struct ast_channel *chan, const char *bridge_profile_name, struct bridge_profile *result)
  2032. {
  2033. struct bridge_profile *tmp2;
  2034. struct ast_datastore *datastore = NULL;
  2035. struct func_confbridge_data *b_data = NULL;
  2036. RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
  2037. if (chan && ast_strlen_zero(bridge_profile_name)) {
  2038. ast_channel_lock(chan);
  2039. datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
  2040. ast_channel_unlock(chan);
  2041. if (datastore) {
  2042. b_data = datastore->data;
  2043. if (b_data->b_usable) {
  2044. conf_bridge_profile_copy(result, &b_data->b_profile);
  2045. return result;
  2046. }
  2047. }
  2048. }
  2049. if (!cfg) {
  2050. return NULL;
  2051. }
  2052. if (ast_strlen_zero(bridge_profile_name)) {
  2053. bridge_profile_name = DEFAULT_BRIDGE_PROFILE;
  2054. }
  2055. if (!(tmp2 = ao2_find(cfg->bridge_profiles, bridge_profile_name, OBJ_KEY))) {
  2056. return NULL;
  2057. }
  2058. ao2_lock(tmp2);
  2059. conf_bridge_profile_copy(result, tmp2);
  2060. ao2_unlock(tmp2);
  2061. ao2_ref(tmp2, -1);
  2062. return result;
  2063. }
  2064. struct dtmf_menu_hook_pvt {
  2065. struct confbridge_user *user;
  2066. struct conf_menu_entry menu_entry;
  2067. struct conf_menu *menu;
  2068. };
  2069. static void menu_hook_destroy(void *hook_pvt)
  2070. {
  2071. struct dtmf_menu_hook_pvt *pvt = hook_pvt;
  2072. struct conf_menu_action *action = NULL;
  2073. ao2_cleanup(pvt->menu);
  2074. while ((action = AST_LIST_REMOVE_HEAD(&pvt->menu_entry.actions, action))) {
  2075. ast_free(action);
  2076. }
  2077. ast_free(pvt);
  2078. }
  2079. static int menu_hook_callback(struct ast_bridge_channel *bridge_channel, void *hook_pvt)
  2080. {
  2081. struct dtmf_menu_hook_pvt *pvt = hook_pvt;
  2082. return conf_handle_dtmf(bridge_channel, pvt->user, &pvt->menu_entry, pvt->menu);
  2083. }
  2084. void conf_menu_entry_destroy(struct conf_menu_entry *menu_entry)
  2085. {
  2086. struct conf_menu_action *menu_action = NULL;
  2087. while ((menu_action = AST_LIST_REMOVE_HEAD(&menu_entry->actions, action))) {
  2088. ast_free(menu_action);
  2089. }
  2090. }
  2091. int conf_find_menu_entry_by_sequence(const char *dtmf_sequence, struct conf_menu *menu, struct conf_menu_entry *result)
  2092. {
  2093. struct conf_menu_entry *menu_entry = NULL;
  2094. ao2_lock(menu);
  2095. AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
  2096. if (!strcasecmp(menu_entry->dtmf, dtmf_sequence)) {
  2097. copy_menu_entry(result, menu_entry);
  2098. ao2_unlock(menu);
  2099. return 1;
  2100. }
  2101. }
  2102. ao2_unlock(menu);
  2103. return 0;
  2104. }
  2105. static int apply_menu_to_user(struct confbridge_user *user, struct conf_menu *menu)
  2106. {
  2107. struct conf_menu_entry *menu_entry;
  2108. SCOPED_AO2LOCK(menu_lock, menu);
  2109. AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
  2110. struct dtmf_menu_hook_pvt *pvt;
  2111. if (!(pvt = ast_calloc(1, sizeof(*pvt)))) {
  2112. return -1;
  2113. }
  2114. pvt->user = user;
  2115. pvt->menu = ao2_bump(menu);
  2116. if (copy_menu_entry(&pvt->menu_entry, menu_entry)) {
  2117. menu_hook_destroy(pvt);
  2118. return -1;
  2119. }
  2120. if (ast_bridge_dtmf_hook(&user->features, pvt->menu_entry.dtmf,
  2121. menu_hook_callback, pvt, menu_hook_destroy, 0)) {
  2122. menu_hook_destroy(pvt);
  2123. }
  2124. }
  2125. strcpy(user->menu_name, menu->name); /* Safe */
  2126. return 0;
  2127. }
  2128. int conf_set_menu_to_user(struct ast_channel *chan, struct confbridge_user *user, const char *menu_profile_name)
  2129. {
  2130. RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
  2131. RAII_VAR(struct conf_menu *, menu, NULL, ao2_cleanup);
  2132. if (chan && ast_strlen_zero(menu_profile_name)) {
  2133. struct ast_datastore *datastore;
  2134. struct func_confbridge_data *b_data;
  2135. ast_channel_lock(chan);
  2136. datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
  2137. ast_channel_unlock(chan);
  2138. if (datastore) {
  2139. /* If a menu exists in the CONFBRIDGE function datastore, use it. */
  2140. b_data = datastore->data;
  2141. if (b_data->m_usable) {
  2142. menu = ao2_bump(b_data->menu);
  2143. return apply_menu_to_user(user, menu);
  2144. }
  2145. }
  2146. }
  2147. /* Otherwise, we need to get whatever menu profile is specified to use (or default). */
  2148. if (!cfg) {
  2149. return -1;
  2150. }
  2151. if (ast_strlen_zero(menu_profile_name)) {
  2152. menu_profile_name = DEFAULT_MENU_PROFILE;
  2153. }
  2154. if (!(menu = ao2_find(cfg->menus, menu_profile_name, OBJ_KEY))) {
  2155. return -1;
  2156. }
  2157. return apply_menu_to_user(user, menu);
  2158. }
  2159. void conf_destroy_config(void)
  2160. {
  2161. ast_cli_unregister_multiple(cli_confbridge_parser, ARRAY_LEN(cli_confbridge_parser));
  2162. aco_info_destroy(&cfg_info);
  2163. ao2_global_obj_release(cfg_handle);
  2164. }