app_confbridge.c 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2007-2008, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. * David Vossel <dvossel@digium.com>
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. /*! \file
  20. *
  21. * \brief Conference Bridge application
  22. *
  23. * \author\verbatim Joshua Colp <jcolp@digium.com> \endverbatim
  24. * \author\verbatim David Vossel <dvossel@digium.com> \endverbatim
  25. *
  26. * This is a conference bridge application utilizing the bridging core.
  27. * \ingroup applications
  28. */
  29. /*! \li \ref app_confbridge.c uses the configuration file \ref confbridge.conf
  30. * \addtogroup configuration_file Configuration Files
  31. */
  32. /*!
  33. * \page confbridge.conf confbridge.conf
  34. * \verbinclude confbridge.conf.sample
  35. */
  36. /*** MODULEINFO
  37. <support_level>core</support_level>
  38. ***/
  39. #include "asterisk.h"
  40. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  41. #include <stdio.h>
  42. #include <stdlib.h>
  43. #include <unistd.h>
  44. #include <string.h>
  45. #include <signal.h>
  46. #include "asterisk/cli.h"
  47. #include "asterisk/file.h"
  48. #include "asterisk/channel.h"
  49. #include "asterisk/pbx.h"
  50. #include "asterisk/pbx.h"
  51. #include "asterisk/module.h"
  52. #include "asterisk/lock.h"
  53. #include "asterisk/bridge.h"
  54. #include "asterisk/musiconhold.h"
  55. #include "asterisk/say.h"
  56. #include "asterisk/audiohook.h"
  57. #include "asterisk/astobj2.h"
  58. #include "confbridge/include/confbridge.h"
  59. #include "asterisk/paths.h"
  60. #include "asterisk/manager.h"
  61. #include "asterisk/test.h"
  62. #include "asterisk/stasis.h"
  63. #include "asterisk/stasis_bridges.h"
  64. #include "asterisk/json.h"
  65. #include "asterisk/format_cache.h"
  66. /*** DOCUMENTATION
  67. <application name="ConfBridge" language="en_US">
  68. <synopsis>
  69. Conference bridge application.
  70. </synopsis>
  71. <syntax>
  72. <parameter name="conference" required="true">
  73. <para>Name of the conference bridge. You are not limited to just
  74. numbers.</para>
  75. </parameter>
  76. <parameter name="bridge_profile">
  77. <para>The bridge profile name from confbridge.conf. When left blank,
  78. a dynamically built bridge profile created by the CONFBRIDGE dialplan
  79. function is searched for on the channel and used. If no dynamic
  80. profile is present, the 'default_bridge' profile found in
  81. confbridge.conf is used. </para>
  82. <para>It is important to note that while user profiles may be unique
  83. for each participant, mixing bridge profiles on a single conference
  84. is _NOT_ recommended and will produce undefined results.</para>
  85. </parameter>
  86. <parameter name="user_profile">
  87. <para>The user profile name from confbridge.conf. When left blank,
  88. a dynamically built user profile created by the CONFBRIDGE dialplan
  89. function is searched for on the channel and used. If no dynamic
  90. profile is present, the 'default_user' profile found in
  91. confbridge.conf is used.</para>
  92. </parameter>
  93. <parameter name="menu">
  94. <para>The name of the DTMF menu in confbridge.conf to be applied to
  95. this channel. When left blank, a dynamically built menu profile
  96. created by the CONFBRIDGE dialplan function is searched for on
  97. the channel and used. If no dynamic profile is present, the
  98. 'default_menu' profile found in confbridge.conf is used.</para>
  99. </parameter>
  100. </syntax>
  101. <description>
  102. <para>Enters the user into a specified conference bridge. The user can
  103. exit the conference by hangup or DTMF menu option.</para>
  104. <para>This application sets the following channel variable upon completion:</para>
  105. <variablelist>
  106. <variable name="CONFBRIDGE_RESULT">
  107. <value name="FAILED">The channel encountered an error and could not enter the conference.</value>
  108. <value name="HANGUP">The channel exited the conference by hanging up.</value>
  109. <value name="KICKED">The channel was kicked from the conference.</value>
  110. <value name="ENDMARKED">The channel left the conference as a result of the last marked user leaving.</value>
  111. <value name="DTMF">The channel pressed a DTMF sequence to exit the conference.</value>
  112. </variable>
  113. </variablelist>
  114. </description>
  115. <see-also>
  116. <ref type="application">ConfBridge</ref>
  117. <ref type="function">CONFBRIDGE</ref>
  118. <ref type="function">CONFBRIDGE_INFO</ref>
  119. </see-also>
  120. </application>
  121. <function name="CONFBRIDGE" language="en_US">
  122. <synopsis>
  123. Set a custom dynamic bridge, user, or menu profile on a channel for the ConfBridge application using the same options defined in confbridge.conf.
  124. </synopsis>
  125. <syntax>
  126. <parameter name="type" required="true">
  127. <para>Type refers to which type of profile the option belongs too. Type can be <literal>bridge</literal>, <literal>user</literal>, or
  128. <literal>menu</literal>.</para>
  129. </parameter>
  130. <parameter name="option" required="true">
  131. <para>Option refers to <filename>confbridge.conf</filename> option that is being set dynamically on this channel, or
  132. <literal>clear</literal> to remove already applied options from the channel.</para>
  133. </parameter>
  134. </syntax>
  135. <description>
  136. <para>---- Example 1 ----</para>
  137. <para>In this example the custom set user profile on this channel will automatically be used by the ConfBridge app.</para>
  138. <para>exten => 1,1,Answer() </para>
  139. <para>exten => 1,n,Set(CONFBRIDGE(user,announce_join_leave)=yes)</para>
  140. <para>exten => 1,n,Set(CONFBRIDGE(user,startmuted)=yes)</para>
  141. <para>exten => 1,n,ConfBridge(1) </para>
  142. <para>---- Example 2 ----</para>
  143. <para>This example shows how to use a predefined user or bridge profile in confbridge.conf as a template for a dynamic profile. Here we make a admin/marked user out of the default_user profile that is already defined in confbridge.conf.</para>
  144. <para>exten => 1,1,Answer() </para>
  145. <para>exten => 1,n,Set(CONFBRIDGE(user,template)=default_user)</para>
  146. <para>exten => 1,n,Set(CONFBRIDGE(user,admin)=yes)</para>
  147. <para>exten => 1,n,Set(CONFBRIDGE(user,marked)=yes)</para>
  148. <para>exten => 1,n,ConfBridge(1)</para>
  149. </description>
  150. </function>
  151. <function name="CONFBRIDGE_INFO" language="en_US">
  152. <synopsis>
  153. Get information about a ConfBridge conference.
  154. </synopsis>
  155. <syntax>
  156. <parameter name="type" required="true">
  157. <para>Type can be <literal>parties</literal>, <literal>admins</literal>, <literal>marked</literal>, or <literal>locked</literal>.</para>
  158. </parameter>
  159. <parameter name="conf" required="true">
  160. <para>Conf refers to the name of the conference being referenced.</para>
  161. </parameter>
  162. </syntax>
  163. <description>
  164. <para>This function returns a non-negative integer for valid conference identifiers (0 or 1 for <literal>locked</literal>) and "" for invalid conference identifiers.</para>
  165. </description>
  166. </function>
  167. <manager name="ConfbridgeList" language="en_US">
  168. <synopsis>
  169. List participants in a conference.
  170. </synopsis>
  171. <syntax>
  172. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  173. <parameter name="Conference" required="true">
  174. <para>Conference number.</para>
  175. </parameter>
  176. </syntax>
  177. <description>
  178. <para>Lists all users in a particular ConfBridge conference.
  179. ConfbridgeList will follow as separate events, followed by a final event called
  180. ConfbridgeListComplete.</para>
  181. </description>
  182. </manager>
  183. <manager name="ConfbridgeListRooms" language="en_US">
  184. <synopsis>
  185. List active conferences.
  186. </synopsis>
  187. <syntax>
  188. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  189. </syntax>
  190. <description>
  191. <para>Lists data about all active conferences.
  192. ConfbridgeListRooms will follow as separate events, followed by a final event called
  193. ConfbridgeListRoomsComplete.</para>
  194. </description>
  195. </manager>
  196. <manager name="ConfbridgeMute" language="en_US">
  197. <synopsis>
  198. Mute a Confbridge user.
  199. </synopsis>
  200. <syntax>
  201. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  202. <parameter name="Conference" required="true" />
  203. <parameter name="Channel" required="true">
  204. <para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
  205. <para>If this parameter is "all", all channels will be muted.</para>
  206. <para>If this parameter is "participants", all non-admin channels will be muted.</para>
  207. </parameter>
  208. </syntax>
  209. <description>
  210. </description>
  211. </manager>
  212. <manager name="ConfbridgeUnmute" language="en_US">
  213. <synopsis>
  214. Unmute a Confbridge user.
  215. </synopsis>
  216. <syntax>
  217. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  218. <parameter name="Conference" required="true" />
  219. <parameter name="Channel" required="true">
  220. <para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
  221. <para>If this parameter is "all", all channels will be unmuted.</para>
  222. <para>If this parameter is "participants", all non-admin channels will be unmuted.</para>
  223. </parameter>
  224. </syntax>
  225. <description>
  226. </description>
  227. </manager>
  228. <manager name="ConfbridgeKick" language="en_US">
  229. <synopsis>
  230. Kick a Confbridge user.
  231. </synopsis>
  232. <syntax>
  233. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  234. <parameter name="Conference" required="true" />
  235. <parameter name="Channel" required="true" >
  236. <para>If this parameter is "all", all channels will be kicked from the conference.</para>
  237. <para>If this parameter is "participants", all non-admin channels will be kicked from the conference.</para>
  238. </parameter>
  239. </syntax>
  240. <description>
  241. </description>
  242. </manager>
  243. <manager name="ConfbridgeLock" language="en_US">
  244. <synopsis>
  245. Lock a Confbridge conference.
  246. </synopsis>
  247. <syntax>
  248. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  249. <parameter name="Conference" required="true" />
  250. </syntax>
  251. <description>
  252. </description>
  253. </manager>
  254. <manager name="ConfbridgeUnlock" language="en_US">
  255. <synopsis>
  256. Unlock a Confbridge conference.
  257. </synopsis>
  258. <syntax>
  259. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  260. <parameter name="Conference" required="true" />
  261. </syntax>
  262. <description>
  263. </description>
  264. </manager>
  265. <manager name="ConfbridgeStartRecord" language="en_US">
  266. <synopsis>
  267. Start recording a Confbridge conference.
  268. </synopsis>
  269. <syntax>
  270. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  271. <parameter name="Conference" required="true" />
  272. <parameter name="RecordFile" required="false" />
  273. </syntax>
  274. <description>
  275. <para>Start recording a conference. If recording is already present an error will be returned. If RecordFile is not provided, the default record file specified in the conference's bridge profile will be used, if that is not present either a file will automatically be generated in the monitor directory.</para>
  276. </description>
  277. </manager>
  278. <manager name="ConfbridgeStopRecord" language="en_US">
  279. <synopsis>
  280. Stop recording a Confbridge conference.
  281. </synopsis>
  282. <syntax>
  283. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  284. <parameter name="Conference" required="true" />
  285. </syntax>
  286. <description>
  287. </description>
  288. </manager>
  289. <manager name="ConfbridgeSetSingleVideoSrc" language="en_US">
  290. <synopsis>
  291. Set a conference user as the single video source distributed to all other participants.
  292. </synopsis>
  293. <syntax>
  294. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  295. <parameter name="Conference" required="true" />
  296. <parameter name="Channel" required="true">
  297. <para>If this parameter is not a complete channel name, the first channel with this prefix will be used.</para>
  298. </parameter>
  299. </syntax>
  300. <description>
  301. </description>
  302. </manager>
  303. ***/
  304. /*!
  305. * \par Playing back a file to a channel in a conference
  306. * You might notice in this application that while playing a sound file
  307. * to a channel the actual conference bridge lock is not held. This is done so
  308. * that other channels are not blocked from interacting with the conference bridge.
  309. * Unfortunately because of this it is possible for things to change after the sound file
  310. * is done being played. Data must therefore be checked after reacquiring the conference
  311. * bridge lock if it is important.
  312. */
  313. static const char app[] = "ConfBridge";
  314. /*! Number of buckets our conference bridges container can have */
  315. #define CONFERENCE_BRIDGE_BUCKETS 53
  316. /*! Initial recording filename space. */
  317. #define RECORD_FILENAME_INITIAL_SPACE 128
  318. /*! \brief Container to hold all conference bridges in progress */
  319. struct ao2_container *conference_bridges;
  320. static void leave_conference(struct confbridge_user *user);
  321. static int play_sound_number(struct confbridge_conference *conference, int say_number);
  322. static int execute_menu_entry(struct confbridge_conference *conference,
  323. struct confbridge_user *user,
  324. struct ast_bridge_channel *bridge_channel,
  325. struct conf_menu_entry *menu_entry,
  326. struct conf_menu *menu);
  327. /*! \brief Hashing function used for conference bridges container */
  328. static int conference_bridge_hash_cb(const void *obj, const int flags)
  329. {
  330. const struct confbridge_conference *conference = obj;
  331. const char *name = obj;
  332. int hash;
  333. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  334. default:
  335. case OBJ_POINTER:
  336. name = conference->name;
  337. /* Fall through */
  338. case OBJ_KEY:
  339. hash = ast_str_case_hash(name);
  340. break;
  341. case OBJ_PARTIAL_KEY:
  342. /* Should never happen in hash callback. */
  343. ast_assert(0);
  344. hash = 0;
  345. break;
  346. }
  347. return hash;
  348. }
  349. /*! \brief Comparison function used for conference bridges container */
  350. static int conference_bridge_cmp_cb(void *obj, void *arg, int flags)
  351. {
  352. const struct confbridge_conference *left = obj;
  353. const struct confbridge_conference *right = arg;
  354. const char *right_name = arg;
  355. int cmp;
  356. switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
  357. default:
  358. case OBJ_POINTER:
  359. right_name = right->name;
  360. /* Fall through */
  361. case OBJ_KEY:
  362. cmp = strcasecmp(left->name, right_name);
  363. break;
  364. case OBJ_PARTIAL_KEY:
  365. cmp = strncasecmp(left->name, right_name, strlen(right_name));
  366. break;
  367. }
  368. return cmp ? 0 : CMP_MATCH;
  369. }
  370. const char *conf_get_sound(enum conf_sounds sound, struct bridge_profile_sounds *custom_sounds)
  371. {
  372. switch (sound) {
  373. case CONF_SOUND_HAS_JOINED:
  374. return S_OR(custom_sounds->hasjoin, "conf-hasjoin");
  375. case CONF_SOUND_HAS_LEFT:
  376. return S_OR(custom_sounds->hasleft, "conf-hasleft");
  377. case CONF_SOUND_KICKED:
  378. return S_OR(custom_sounds->kicked, "conf-kicked");
  379. case CONF_SOUND_MUTED:
  380. return S_OR(custom_sounds->muted, "conf-muted");
  381. case CONF_SOUND_UNMUTED:
  382. return S_OR(custom_sounds->unmuted, "conf-unmuted");
  383. case CONF_SOUND_ONLY_ONE:
  384. return S_OR(custom_sounds->onlyone, "conf-onlyone");
  385. case CONF_SOUND_THERE_ARE:
  386. return S_OR(custom_sounds->thereare, "conf-thereare");
  387. case CONF_SOUND_OTHER_IN_PARTY:
  388. return S_OR(custom_sounds->otherinparty, "conf-otherinparty");
  389. case CONF_SOUND_PLACE_IN_CONF:
  390. return S_OR(custom_sounds->placeintoconf, "conf-placeintoconf");
  391. case CONF_SOUND_WAIT_FOR_LEADER:
  392. return S_OR(custom_sounds->waitforleader, "conf-waitforleader");
  393. case CONF_SOUND_LEADER_HAS_LEFT:
  394. return S_OR(custom_sounds->leaderhasleft, "conf-leaderhasleft");
  395. case CONF_SOUND_GET_PIN:
  396. return S_OR(custom_sounds->getpin, "conf-getpin");
  397. case CONF_SOUND_INVALID_PIN:
  398. return S_OR(custom_sounds->invalidpin, "conf-invalidpin");
  399. case CONF_SOUND_ONLY_PERSON:
  400. return S_OR(custom_sounds->onlyperson, "conf-onlyperson");
  401. case CONF_SOUND_LOCKED:
  402. return S_OR(custom_sounds->locked, "conf-locked");
  403. case CONF_SOUND_LOCKED_NOW:
  404. return S_OR(custom_sounds->lockednow, "conf-lockednow");
  405. case CONF_SOUND_UNLOCKED_NOW:
  406. return S_OR(custom_sounds->unlockednow, "conf-unlockednow");
  407. case CONF_SOUND_ERROR_MENU:
  408. return S_OR(custom_sounds->errormenu, "conf-errormenu");
  409. case CONF_SOUND_JOIN:
  410. return S_OR(custom_sounds->join, "confbridge-join");
  411. case CONF_SOUND_LEAVE:
  412. return S_OR(custom_sounds->leave, "confbridge-leave");
  413. case CONF_SOUND_PARTICIPANTS_MUTED:
  414. return S_OR(custom_sounds->participantsmuted, "conf-now-muted");
  415. case CONF_SOUND_PARTICIPANTS_UNMUTED:
  416. return S_OR(custom_sounds->participantsunmuted, "conf-now-unmuted");
  417. case CONF_SOUND_BEGIN:
  418. return S_OR(custom_sounds->begin, "confbridge-conf-begin");
  419. }
  420. return "";
  421. }
  422. static void send_conf_stasis(struct confbridge_conference *conference, struct ast_channel *chan,
  423. struct stasis_message_type *type, struct ast_json *extras, int channel_topic)
  424. {
  425. RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
  426. RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
  427. json_object = ast_json_pack("{s: s}",
  428. "conference", conference->name);
  429. if (!json_object) {
  430. return;
  431. }
  432. if (extras) {
  433. ast_json_object_update(json_object, extras);
  434. }
  435. ast_bridge_lock(conference->bridge);
  436. msg = ast_bridge_blob_create(type,
  437. conference->bridge,
  438. chan,
  439. json_object);
  440. ast_bridge_unlock(conference->bridge);
  441. if (!msg) {
  442. return;
  443. }
  444. if (channel_topic) {
  445. stasis_publish(ast_channel_topic(chan), msg);
  446. } else {
  447. stasis_publish(ast_bridge_topic(conference->bridge), msg);
  448. }
  449. }
  450. static void send_conf_start_event(struct confbridge_conference *conference)
  451. {
  452. send_conf_stasis(conference, NULL, confbridge_start_type(), NULL, 0);
  453. }
  454. static void send_conf_end_event(struct confbridge_conference *conference)
  455. {
  456. send_conf_stasis(conference, NULL, confbridge_end_type(), NULL, 0);
  457. }
  458. static void send_join_event(struct confbridge_user *user, struct confbridge_conference *conference)
  459. {
  460. struct ast_json *json_object;
  461. json_object = ast_json_pack("{s: b}",
  462. "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
  463. );
  464. if (!json_object) {
  465. return;
  466. }
  467. send_conf_stasis(conference, user->chan, confbridge_join_type(), json_object, 0);
  468. ast_json_unref(json_object);
  469. }
  470. static void send_leave_event(struct confbridge_user *user, struct confbridge_conference *conference)
  471. {
  472. struct ast_json *json_object;
  473. json_object = ast_json_pack("{s: b}",
  474. "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
  475. );
  476. if (!json_object) {
  477. return;
  478. }
  479. send_conf_stasis(conference, user->chan, confbridge_leave_type(), json_object, 0);
  480. ast_json_unref(json_object);
  481. }
  482. static void send_start_record_event(struct confbridge_conference *conference)
  483. {
  484. send_conf_stasis(conference, NULL, confbridge_start_record_type(), NULL, 0);
  485. }
  486. static void send_stop_record_event(struct confbridge_conference *conference)
  487. {
  488. send_conf_stasis(conference, NULL, confbridge_stop_record_type(), NULL, 0);
  489. }
  490. static void send_mute_event(struct confbridge_user *user, struct confbridge_conference *conference)
  491. {
  492. struct ast_json *json_object;
  493. json_object = ast_json_pack("{s: b}",
  494. "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
  495. );
  496. if (!json_object) {
  497. return;
  498. }
  499. send_conf_stasis(conference, user->chan, confbridge_mute_type(), json_object, 1);
  500. ast_json_unref(json_object);
  501. }
  502. static void send_unmute_event(struct confbridge_user *user, struct confbridge_conference *conference)
  503. {
  504. struct ast_json *json_object;
  505. json_object = ast_json_pack("{s: b}",
  506. "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN)
  507. );
  508. if (!json_object) {
  509. return;
  510. }
  511. send_conf_stasis(conference, user->chan, confbridge_unmute_type(), json_object, 1);
  512. ast_json_unref(json_object);
  513. }
  514. static void set_rec_filename(struct confbridge_conference *conference, struct ast_str **filename, int is_new)
  515. {
  516. char *rec_file = conference->b_profile.rec_file;
  517. char *ext;
  518. time_t now;
  519. if (ast_str_strlen(*filename)
  520. && ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_APPEND)
  521. && !is_new) {
  522. return;
  523. }
  524. time(&now);
  525. ast_str_reset(*filename);
  526. if (ast_strlen_zero(rec_file)) {
  527. ast_str_set(filename, 0, "confbridge-%s-%u.wav", conference->name,
  528. (unsigned int) now);
  529. } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_TIMESTAMP)) {
  530. /* insert time before file extension */
  531. ext = strrchr(rec_file, '.');
  532. if (ext) {
  533. ast_str_set_substr(filename, 0, rec_file, ext - rec_file);
  534. ast_str_append(filename, 0, "-%u%s", (unsigned int) now, ext);
  535. } else {
  536. ast_str_set(filename, 0, "%s-%u", rec_file, (unsigned int) now);
  537. }
  538. } else {
  539. ast_str_set(filename, 0, "%s", rec_file);
  540. }
  541. ast_str_append(filename, 0, ",%s%s,%s",
  542. ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_FILE_APPEND) ? "a" : "",
  543. conference->b_profile.rec_options,
  544. conference->b_profile.rec_command);
  545. }
  546. static int is_new_rec_file(const char *rec_file, struct ast_str **orig_rec_file)
  547. {
  548. if (!ast_strlen_zero(rec_file)) {
  549. if (!*orig_rec_file) {
  550. *orig_rec_file = ast_str_create(RECORD_FILENAME_INITIAL_SPACE);
  551. }
  552. if (*orig_rec_file
  553. && strcmp(ast_str_buffer(*orig_rec_file), rec_file)) {
  554. ast_str_set(orig_rec_file, 0, "%s", rec_file);
  555. return 1;
  556. }
  557. }
  558. return 0;
  559. }
  560. /*!
  561. * \internal
  562. * \brief Returns whether or not conference is being recorded.
  563. *
  564. * \param conference The bridge to check for recording
  565. *
  566. * \note Must be called with the conference locked
  567. *
  568. * \retval 1, conference is recording.
  569. * \retval 0, conference is NOT recording.
  570. */
  571. static int conf_is_recording(struct confbridge_conference *conference)
  572. {
  573. return conference->record_chan != NULL;
  574. }
  575. /*!
  576. * \internal
  577. * \brief Stop recording a conference bridge
  578. *
  579. * \param conference The conference bridge on which to stop the recording
  580. *
  581. * \note Must be called with the conference locked
  582. *
  583. * \retval -1 Failure
  584. * \retval 0 Success
  585. */
  586. static int conf_stop_record(struct confbridge_conference *conference)
  587. {
  588. struct ast_channel *chan;
  589. struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
  590. if (!conf_is_recording(conference)) {
  591. return -1;
  592. }
  593. /* Remove the recording channel from the conference bridge. */
  594. chan = conference->record_chan;
  595. conference->record_chan = NULL;
  596. ast_queue_frame(chan, &f);
  597. ast_channel_unref(chan);
  598. ast_test_suite_event_notify("CONF_STOP_RECORD", "Message: stopped conference recording channel\r\nConference: %s", conference->b_profile.name);
  599. send_stop_record_event(conference);
  600. return 0;
  601. }
  602. /*!
  603. * \internal
  604. * \brief Start recording the conference
  605. *
  606. * \param conference The conference bridge to start recording
  607. *
  608. * \note Must be called with the conference locked
  609. *
  610. * \retval 0 success
  611. * \retval non-zero failure
  612. */
  613. static int conf_start_record(struct confbridge_conference *conference)
  614. {
  615. struct ast_app *mixmonapp;
  616. struct ast_channel *chan;
  617. struct ast_format_cap *cap;
  618. struct ast_bridge_features *features;
  619. if (conf_is_recording(conference)) {
  620. return -1;
  621. }
  622. mixmonapp = pbx_findapp("MixMonitor");
  623. if (!mixmonapp) {
  624. ast_log(LOG_WARNING, "Cannot record ConfBridge, MixMonitor app is not installed\n");
  625. return -1;
  626. }
  627. features = ast_bridge_features_new();
  628. if (!features) {
  629. return -1;
  630. }
  631. ast_set_flag(&features->feature_flags, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE);
  632. cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  633. if (!cap) {
  634. ast_bridge_features_destroy(features);
  635. return -1;
  636. }
  637. ast_format_cap_append(cap, ast_format_slin, 0);
  638. /* Create the recording channel. */
  639. chan = ast_request("CBRec", cap, NULL, NULL, conference->name, NULL);
  640. ao2_ref(cap, -1);
  641. if (!chan) {
  642. ast_bridge_features_destroy(features);
  643. return -1;
  644. }
  645. /* Start recording. */
  646. set_rec_filename(conference, &conference->record_filename,
  647. is_new_rec_file(conference->b_profile.rec_file, &conference->orig_rec_file));
  648. ast_answer(chan);
  649. pbx_exec(chan, mixmonapp, ast_str_buffer(conference->record_filename));
  650. /* Put the channel into the conference bridge. */
  651. ast_channel_ref(chan);
  652. conference->record_chan = chan;
  653. if (ast_bridge_impart(conference->bridge, chan, NULL, features,
  654. AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
  655. ast_hangup(chan);
  656. ast_channel_unref(chan);
  657. conference->record_chan = NULL;
  658. return -1;
  659. }
  660. ast_test_suite_event_notify("CONF_START_RECORD", "Message: started conference recording channel\r\nConference: %s", conference->b_profile.name);
  661. send_start_record_event(conference);
  662. return 0;
  663. }
  664. /* \brief Playback the given filename and monitor for any dtmf interrupts.
  665. *
  666. * This function is used to playback sound files on a given channel and optionally
  667. * allow dtmf interrupts to occur.
  668. *
  669. * If the optional bridge_channel parameter is given then sound file playback
  670. * is played on that channel and dtmf interruptions are allowed. However, if
  671. * bridge_channel is not set then the channel parameter is expected to be set
  672. * instead and non interruptible playback is played on that channel.
  673. *
  674. * \param bridge_channel Bridge channel to play file on
  675. * \param channel Optional channel to play file on if bridge_channel not given
  676. * \param filename The file name to playback
  677. *
  678. * \retval -1 failure during playback, 0 on file was fully played, 1 on dtmf interrupt.
  679. */
  680. static int play_file(struct ast_bridge_channel *bridge_channel, struct ast_channel *channel,
  681. const char *filename)
  682. {
  683. struct ast_channel *chan;
  684. const char *stop_digits;
  685. int digit;
  686. if (bridge_channel) {
  687. chan = bridge_channel->chan;
  688. stop_digits = AST_DIGIT_ANY;
  689. } else {
  690. chan = channel;
  691. stop_digits = AST_DIGIT_NONE;
  692. }
  693. digit = ast_stream_and_wait(chan, filename, stop_digits);
  694. if (digit < 0) {
  695. ast_log(LOG_WARNING, "Failed to playback file '%s' to channel\n", filename);
  696. return -1;
  697. }
  698. if (digit > 0) {
  699. ast_stopstream(bridge_channel->chan);
  700. ast_bridge_channel_feature_digit_add(bridge_channel, digit);
  701. return 1;
  702. }
  703. return 0;
  704. }
  705. /*!
  706. * \internal
  707. * \brief Complain if the given sound file does not exist.
  708. *
  709. * \param filename Sound file to check if exists.
  710. *
  711. * \retval non-zero if the file exists.
  712. */
  713. static int sound_file_exists(const char *filename)
  714. {
  715. if (ast_fileexists(filename, NULL, NULL)) {
  716. return -1;
  717. }
  718. ast_log(LOG_WARNING, "File %s does not exist in any format\n", filename);
  719. return 0;
  720. }
  721. /*!
  722. * \brief Announce number of users in the conference bridge to the caller
  723. *
  724. * \param conference Conference bridge to peek at
  725. * \param user Optional Caller
  726. * \param bridge_channel The bridged channel involved
  727. *
  728. * \note if caller is NULL, the announcment will be sent to all participants in the conference.
  729. * \return Returns 0 on success, -1 if the user hung up
  730. */
  731. static int announce_user_count(struct confbridge_conference *conference, struct confbridge_user *user,
  732. struct ast_bridge_channel *bridge_channel)
  733. {
  734. const char *other_in_party = conf_get_sound(CONF_SOUND_OTHER_IN_PARTY, conference->b_profile.sounds);
  735. const char *only_one = conf_get_sound(CONF_SOUND_ONLY_ONE, conference->b_profile.sounds);
  736. const char *there_are = conf_get_sound(CONF_SOUND_THERE_ARE, conference->b_profile.sounds);
  737. if (conference->activeusers <= 1) {
  738. /* Awww we are the only person in the conference bridge OR we only have waitmarked users */
  739. return 0;
  740. } else if (conference->activeusers == 2) {
  741. if (user) {
  742. /* Eep, there is one other person */
  743. if (play_file(bridge_channel, user->chan, only_one) < 0) {
  744. return -1;
  745. }
  746. } else {
  747. play_sound_file(conference, only_one);
  748. }
  749. } else {
  750. /* Alas multiple others in here */
  751. if (user) {
  752. if (ast_stream_and_wait(user->chan,
  753. there_are,
  754. "")) {
  755. return -1;
  756. }
  757. if (ast_say_number(user->chan, conference->activeusers - 1, "", ast_channel_language(user->chan), NULL)) {
  758. return -1;
  759. }
  760. if (play_file(bridge_channel, user->chan, other_in_party) < 0) {
  761. return -1;
  762. }
  763. } else if (sound_file_exists(there_are) && sound_file_exists(other_in_party)) {
  764. play_sound_file(conference, there_are);
  765. play_sound_number(conference, conference->activeusers - 1);
  766. play_sound_file(conference, other_in_party);
  767. }
  768. }
  769. return 0;
  770. }
  771. /*!
  772. * \brief Play back an audio file to a channel
  773. *
  774. * \param user User to play audio prompt to
  775. * \param filename Prompt to play
  776. *
  777. * \return Returns 0 on success, -1 if the user hung up
  778. * \note Generally this should be called when the conference is unlocked to avoid blocking
  779. * the entire conference while the sound is played. But don't unlock the conference bridge
  780. * in the middle of a state transition.
  781. */
  782. static int play_prompt_to_user(struct confbridge_user *user, const char *filename)
  783. {
  784. return ast_stream_and_wait(user->chan, filename, "");
  785. }
  786. static void handle_video_on_join(struct confbridge_conference *conference, struct ast_channel *chan, int marked)
  787. {
  788. /* Right now, only marked users are automatically set as the single src of video.*/
  789. if (!marked) {
  790. return;
  791. }
  792. if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED)) {
  793. int set = 1;
  794. struct confbridge_user *user = NULL;
  795. ao2_lock(conference);
  796. /* see if anyone is already the video src */
  797. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  798. if (user->chan == chan) {
  799. continue;
  800. }
  801. if (ast_bridge_is_video_src(conference->bridge, user->chan)) {
  802. set = 0;
  803. break;
  804. }
  805. }
  806. ao2_unlock(conference);
  807. if (set) {
  808. ast_bridge_set_single_src_video_mode(conference->bridge, chan);
  809. }
  810. } else if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED)) {
  811. /* we joined and are video capable, we override anyone else that may have already been the video feed */
  812. ast_bridge_set_single_src_video_mode(conference->bridge, chan);
  813. }
  814. }
  815. static void handle_video_on_exit(struct confbridge_conference *conference, struct ast_channel *chan)
  816. {
  817. struct confbridge_user *user = NULL;
  818. /* if this isn't a video source, nothing to update */
  819. if (!ast_bridge_is_video_src(conference->bridge, chan)) {
  820. return;
  821. }
  822. ast_bridge_remove_video_src(conference->bridge, chan);
  823. /* If in follow talker mode, make sure to restore this mode on the
  824. * bridge when a source is removed. It is possible this channel was
  825. * only set temporarily as a video source by an AMI or DTMF action. */
  826. if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
  827. ast_bridge_set_talker_src_video_mode(conference->bridge);
  828. }
  829. /* if the video_mode isn't set to automatically pick the video source, do nothing on exit. */
  830. if (!ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FIRST_MARKED) &&
  831. !ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_LAST_MARKED)) {
  832. return;
  833. }
  834. /* Make the next available marked user the video src. */
  835. ao2_lock(conference);
  836. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  837. if (user->chan == chan) {
  838. continue;
  839. }
  840. if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
  841. ast_bridge_set_single_src_video_mode(conference->bridge, user->chan);
  842. break;
  843. }
  844. }
  845. ao2_unlock(conference);
  846. }
  847. /*!
  848. * \brief Destroy a conference bridge
  849. *
  850. * \param obj The conference bridge object
  851. *
  852. * \return Returns nothing
  853. */
  854. static void destroy_conference_bridge(void *obj)
  855. {
  856. struct confbridge_conference *conference = obj;
  857. ast_debug(1, "Destroying conference bridge '%s'\n", conference->name);
  858. if (conference->playback_chan) {
  859. conf_announce_channel_depart(conference->playback_chan);
  860. ast_hangup(conference->playback_chan);
  861. conference->playback_chan = NULL;
  862. }
  863. /* Destroying a conference bridge is simple, all we have to do is destroy the bridging object */
  864. if (conference->bridge) {
  865. ast_bridge_destroy(conference->bridge, 0);
  866. conference->bridge = NULL;
  867. }
  868. ast_channel_cleanup(conference->record_chan);
  869. ast_free(conference->orig_rec_file);
  870. ast_free(conference->record_filename);
  871. conf_bridge_profile_destroy(&conference->b_profile);
  872. ast_mutex_destroy(&conference->playback_lock);
  873. }
  874. /*! \brief Call the proper join event handler for the user for the conference bridge's current state
  875. * \internal
  876. * \param user The conference bridge user that is joining
  877. * \retval 0 success
  878. * \retval -1 failure
  879. */
  880. static int handle_conf_user_join(struct confbridge_user *user)
  881. {
  882. conference_event_fn handler;
  883. if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
  884. handler = user->conference->state->join_marked;
  885. } else if (ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)) {
  886. handler = user->conference->state->join_waitmarked;
  887. } else {
  888. handler = user->conference->state->join_unmarked;
  889. }
  890. ast_assert(handler != NULL);
  891. if (!handler) {
  892. conf_invalid_event_fn(user);
  893. return -1;
  894. }
  895. handler(user);
  896. return 0;
  897. }
  898. /*! \brief Call the proper leave event handler for the user for the conference bridge's current state
  899. * \internal
  900. * \param user The conference bridge user that is leaving
  901. * \retval 0 success
  902. * \retval -1 failure
  903. */
  904. static int handle_conf_user_leave(struct confbridge_user *user)
  905. {
  906. conference_event_fn handler;
  907. if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
  908. handler = user->conference->state->leave_marked;
  909. } else if (ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)) {
  910. handler = user->conference->state->leave_waitmarked;
  911. } else {
  912. handler = user->conference->state->leave_unmarked;
  913. }
  914. ast_assert(handler != NULL);
  915. if (!handler) {
  916. /* This should never happen. If it does, though, it is bad. The user will not have been removed
  917. * from the appropriate list, so counts will be off and stuff. The conference won't be torn down, etc.
  918. * Shouldn't happen, though. */
  919. conf_invalid_event_fn(user);
  920. return -1;
  921. }
  922. handler(user);
  923. return 0;
  924. }
  925. void conf_update_user_mute(struct confbridge_user *user)
  926. {
  927. int mute_user;
  928. int mute_system;
  929. int mute_effective;
  930. /* User level mute request. */
  931. mute_user = user->muted;
  932. /* System level mute request. */
  933. mute_system = user->playing_moh
  934. /*
  935. * Do not allow waitmarked users to talk to anyone unless there
  936. * is a marked user present.
  937. */
  938. || (!user->conference->markedusers
  939. && ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED));
  940. mute_effective = mute_user || mute_system;
  941. ast_debug(1, "User %s is %s: user:%d system:%d.\n",
  942. ast_channel_name(user->chan), mute_effective ? "muted" : "unmuted",
  943. mute_user, mute_system);
  944. user->features.mute = mute_effective;
  945. ast_test_suite_event_notify("CONF_MUTE_UPDATE",
  946. "Mode: %s\r\n"
  947. "Conference: %s\r\n"
  948. "Channel: %s",
  949. mute_effective ? "muted" : "unmuted",
  950. user->b_profile.name,
  951. ast_channel_name(user->chan));
  952. }
  953. void conf_moh_stop(struct confbridge_user *user)
  954. {
  955. user->playing_moh = 0;
  956. if (!user->suspended_moh) {
  957. int in_bridge;
  958. /*
  959. * Locking the ast_bridge here is the only way to hold off the
  960. * call to ast_bridge_join() in confbridge_exec() from
  961. * interfering with the bridge and MOH operations here.
  962. */
  963. ast_bridge_lock(user->conference->bridge);
  964. /*
  965. * Temporarily suspend the user from the bridge so we have
  966. * control to stop MOH if needed.
  967. */
  968. in_bridge = !ast_bridge_suspend(user->conference->bridge, user->chan);
  969. ast_moh_stop(user->chan);
  970. if (in_bridge) {
  971. ast_bridge_unsuspend(user->conference->bridge, user->chan);
  972. }
  973. ast_bridge_unlock(user->conference->bridge);
  974. }
  975. }
  976. void conf_moh_start(struct confbridge_user *user)
  977. {
  978. user->playing_moh = 1;
  979. if (!user->suspended_moh) {
  980. int in_bridge;
  981. /*
  982. * Locking the ast_bridge here is the only way to hold off the
  983. * call to ast_bridge_join() in confbridge_exec() from
  984. * interfering with the bridge and MOH operations here.
  985. */
  986. ast_bridge_lock(user->conference->bridge);
  987. /*
  988. * Temporarily suspend the user from the bridge so we have
  989. * control to start MOH if needed.
  990. */
  991. in_bridge = !ast_bridge_suspend(user->conference->bridge, user->chan);
  992. ast_moh_start(user->chan, user->u_profile.moh_class, NULL);
  993. if (in_bridge) {
  994. ast_bridge_unsuspend(user->conference->bridge, user->chan);
  995. }
  996. ast_bridge_unlock(user->conference->bridge);
  997. }
  998. }
  999. /*!
  1000. * \internal
  1001. * \brief Unsuspend MOH for the conference user.
  1002. *
  1003. * \param user Conference user to unsuspend MOH on.
  1004. *
  1005. * \return Nothing
  1006. */
  1007. static void conf_moh_unsuspend(struct confbridge_user *user)
  1008. {
  1009. ao2_lock(user->conference);
  1010. if (--user->suspended_moh == 0 && user->playing_moh) {
  1011. ast_moh_start(user->chan, user->u_profile.moh_class, NULL);
  1012. }
  1013. ao2_unlock(user->conference);
  1014. }
  1015. /*!
  1016. * \internal
  1017. * \brief Suspend MOH for the conference user.
  1018. *
  1019. * \param user Conference user to suspend MOH on.
  1020. *
  1021. * \return Nothing
  1022. */
  1023. static void conf_moh_suspend(struct confbridge_user *user)
  1024. {
  1025. ao2_lock(user->conference);
  1026. if (user->suspended_moh++ == 0 && user->playing_moh) {
  1027. ast_moh_stop(user->chan);
  1028. }
  1029. ao2_unlock(user->conference);
  1030. }
  1031. int conf_handle_inactive_waitmarked(struct confbridge_user *user)
  1032. {
  1033. /* If we have not been quieted play back that they are waiting for the leader */
  1034. if (!ast_test_flag(&user->u_profile, USER_OPT_QUIET) && play_prompt_to_user(user,
  1035. conf_get_sound(CONF_SOUND_WAIT_FOR_LEADER, user->b_profile.sounds))) {
  1036. /* user hungup while the sound was playing */
  1037. return -1;
  1038. }
  1039. return 0;
  1040. }
  1041. int conf_handle_only_unmarked(struct confbridge_user *user)
  1042. {
  1043. /* If audio prompts have not been quieted or this prompt quieted play it on out */
  1044. if (!ast_test_flag(&user->u_profile, USER_OPT_QUIET | USER_OPT_NOONLYPERSON)) {
  1045. if (play_prompt_to_user(user,
  1046. conf_get_sound(CONF_SOUND_ONLY_PERSON, user->b_profile.sounds))) {
  1047. /* user hungup while the sound was playing */
  1048. return -1;
  1049. }
  1050. }
  1051. return 0;
  1052. }
  1053. int conf_add_post_join_action(struct confbridge_user *user, int (*func)(struct confbridge_user *user))
  1054. {
  1055. struct post_join_action *action;
  1056. if (!(action = ast_calloc(1, sizeof(*action)))) {
  1057. return -1;
  1058. }
  1059. action->func = func;
  1060. AST_LIST_INSERT_TAIL(&user->post_join_list, action, list);
  1061. return 0;
  1062. }
  1063. void conf_handle_first_join(struct confbridge_conference *conference)
  1064. {
  1065. ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE, "confbridge:%s", conference->name);
  1066. }
  1067. void conf_handle_second_active(struct confbridge_conference *conference)
  1068. {
  1069. /* If we are the second participant we may need to stop music on hold on the first */
  1070. struct confbridge_user *first_user = AST_LIST_FIRST(&conference->active_list);
  1071. if (ast_test_flag(&first_user->u_profile, USER_OPT_MUSICONHOLD)) {
  1072. conf_moh_stop(first_user);
  1073. }
  1074. conf_update_user_mute(first_user);
  1075. }
  1076. void conf_ended(struct confbridge_conference *conference)
  1077. {
  1078. /* Called with a reference to conference */
  1079. ao2_unlink(conference_bridges, conference);
  1080. send_conf_end_event(conference);
  1081. ao2_lock(conference);
  1082. conf_stop_record(conference);
  1083. ao2_unlock(conference);
  1084. }
  1085. /*!
  1086. * \brief Join a conference bridge
  1087. *
  1088. * \param conference_name The conference name
  1089. * \param user Conference bridge user structure
  1090. *
  1091. * \return A pointer to the conference bridge struct, or NULL if the conference room wasn't found.
  1092. */
  1093. static struct confbridge_conference *join_conference_bridge(const char *conference_name, struct confbridge_user *user)
  1094. {
  1095. struct confbridge_conference *conference;
  1096. struct post_join_action *action;
  1097. int max_members_reached = 0;
  1098. /* We explictly lock the conference bridges container ourselves so that other callers can not create duplicate conferences at the same */
  1099. ao2_lock(conference_bridges);
  1100. ast_debug(1, "Trying to find conference bridge '%s'\n", conference_name);
  1101. /* Attempt to find an existing conference bridge */
  1102. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  1103. if (conference && conference->b_profile.max_members) {
  1104. max_members_reached = conference->b_profile.max_members > conference->activeusers ? 0 : 1;
  1105. }
  1106. /* When finding a conference bridge that already exists make sure that it is not locked, and if so that we are not an admin */
  1107. if (conference && (max_members_reached || conference->locked) && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
  1108. ao2_unlock(conference_bridges);
  1109. ao2_ref(conference, -1);
  1110. ast_debug(1, "Conference '%s' is locked and caller is not an admin\n", conference_name);
  1111. ast_stream_and_wait(user->chan,
  1112. conf_get_sound(CONF_SOUND_LOCKED, user->b_profile.sounds),
  1113. "");
  1114. return NULL;
  1115. }
  1116. /* If no conference bridge was found see if we can create one */
  1117. if (!conference) {
  1118. /* Try to allocate memory for a new conference bridge, if we fail... this won't end well. */
  1119. if (!(conference = ao2_alloc(sizeof(*conference), destroy_conference_bridge))) {
  1120. ao2_unlock(conference_bridges);
  1121. ast_log(LOG_ERROR, "Conference '%s' could not be created.\n", conference_name);
  1122. return NULL;
  1123. }
  1124. /* Setup lock for playback channel */
  1125. ast_mutex_init(&conference->playback_lock);
  1126. /* Setup for the record channel */
  1127. conference->record_filename = ast_str_create(RECORD_FILENAME_INITIAL_SPACE);
  1128. if (!conference->record_filename) {
  1129. ao2_ref(conference, -1);
  1130. ao2_unlock(conference_bridges);
  1131. return NULL;
  1132. }
  1133. /* Setup conference bridge parameters */
  1134. ast_copy_string(conference->name, conference_name, sizeof(conference->name));
  1135. conf_bridge_profile_copy(&conference->b_profile, &user->b_profile);
  1136. /* Create an actual bridge that will do the audio mixing */
  1137. conference->bridge = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_MULTIMIX,
  1138. AST_BRIDGE_FLAG_MASQUERADE_ONLY | AST_BRIDGE_FLAG_TRANSFER_BRIDGE_ONLY,
  1139. app, conference_name, NULL);
  1140. if (!conference->bridge) {
  1141. ao2_ref(conference, -1);
  1142. conference = NULL;
  1143. ao2_unlock(conference_bridges);
  1144. ast_log(LOG_ERROR, "Conference '%s' mixing bridge could not be created.\n", conference_name);
  1145. return NULL;
  1146. }
  1147. /* Set the internal sample rate on the bridge from the bridge profile */
  1148. ast_bridge_set_internal_sample_rate(conference->bridge, conference->b_profile.internal_sample_rate);
  1149. /* Set the internal mixing interval on the bridge from the bridge profile */
  1150. ast_bridge_set_mixing_interval(conference->bridge, conference->b_profile.mix_interval);
  1151. if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_VIDEO_SRC_FOLLOW_TALKER)) {
  1152. ast_bridge_set_talker_src_video_mode(conference->bridge);
  1153. }
  1154. /* Link it into the conference bridges container */
  1155. if (!ao2_link(conference_bridges, conference)) {
  1156. ao2_ref(conference, -1);
  1157. conference = NULL;
  1158. ao2_unlock(conference_bridges);
  1159. ast_log(LOG_ERROR,
  1160. "Conference '%s' could not be added to the conferences list.\n", conference_name);
  1161. return NULL;
  1162. }
  1163. /* Set the initial state to EMPTY */
  1164. conference->state = CONF_STATE_EMPTY;
  1165. if (ast_test_flag(&conference->b_profile, BRIDGE_OPT_RECORD_CONFERENCE)) {
  1166. ao2_lock(conference);
  1167. conf_start_record(conference);
  1168. ao2_unlock(conference);
  1169. }
  1170. send_conf_start_event(conference);
  1171. ast_debug(1, "Created conference '%s' and linked to container.\n", conference_name);
  1172. }
  1173. ao2_unlock(conference_bridges);
  1174. /* Setup conference bridge user parameters */
  1175. user->conference = conference;
  1176. ao2_lock(conference);
  1177. /*
  1178. * Suspend any MOH until the user actually joins the bridge of
  1179. * the conference. This way any pre-join file playback does not
  1180. * need to worry about MOH.
  1181. */
  1182. user->suspended_moh = 1;
  1183. if (handle_conf_user_join(user)) {
  1184. /* Invalid event, nothing was done, so we don't want to process a leave. */
  1185. ao2_unlock(conference);
  1186. ao2_ref(conference, -1);
  1187. return NULL;
  1188. }
  1189. if (ast_check_hangup(user->chan)) {
  1190. ao2_unlock(conference);
  1191. leave_conference(user);
  1192. return NULL;
  1193. }
  1194. ao2_unlock(conference);
  1195. /* If an announcement is to be played play it */
  1196. if (!ast_strlen_zero(user->u_profile.announcement)) {
  1197. if (play_prompt_to_user(user,
  1198. user->u_profile.announcement)) {
  1199. leave_conference(user);
  1200. return NULL;
  1201. }
  1202. }
  1203. /* Announce number of users if need be */
  1204. if (ast_test_flag(&user->u_profile, USER_OPT_ANNOUNCEUSERCOUNT)) {
  1205. if (announce_user_count(conference, user, NULL)) {
  1206. leave_conference(user);
  1207. return NULL;
  1208. }
  1209. }
  1210. if (ast_test_flag(&user->u_profile, USER_OPT_ANNOUNCEUSERCOUNTALL) &&
  1211. (conference->activeusers > user->u_profile.announce_user_count_all_after)) {
  1212. int user_count_res;
  1213. /*
  1214. * We have to autoservice the new user because he has not quite
  1215. * joined the conference yet.
  1216. */
  1217. ast_autoservice_start(user->chan);
  1218. user_count_res = announce_user_count(conference, NULL, NULL);
  1219. ast_autoservice_stop(user->chan);
  1220. if (user_count_res) {
  1221. leave_conference(user);
  1222. return NULL;
  1223. }
  1224. }
  1225. /* Handle post-join actions */
  1226. while ((action = AST_LIST_REMOVE_HEAD(&user->post_join_list, list))) {
  1227. action->func(user);
  1228. ast_free(action);
  1229. }
  1230. return conference;
  1231. }
  1232. /*!
  1233. * \brief Leave a conference
  1234. *
  1235. * \param user The conference user
  1236. */
  1237. static void leave_conference(struct confbridge_user *user)
  1238. {
  1239. struct post_join_action *action;
  1240. ao2_lock(user->conference);
  1241. handle_conf_user_leave(user);
  1242. ao2_unlock(user->conference);
  1243. /* Discard any post-join actions */
  1244. while ((action = AST_LIST_REMOVE_HEAD(&user->post_join_list, list))) {
  1245. ast_free(action);
  1246. }
  1247. /* Done mucking with the conference, huzzah */
  1248. ao2_ref(user->conference, -1);
  1249. user->conference = NULL;
  1250. }
  1251. /*!
  1252. * \internal
  1253. * \brief Allocate playback channel for a conference.
  1254. * \pre expects conference to be locked before calling this function
  1255. */
  1256. static int alloc_playback_chan(struct confbridge_conference *conference)
  1257. {
  1258. struct ast_format_cap *cap;
  1259. cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  1260. if (!cap) {
  1261. return -1;
  1262. }
  1263. ast_format_cap_append(cap, ast_format_slin, 0);
  1264. conference->playback_chan = ast_request("CBAnn", cap, NULL, NULL,
  1265. conference->name, NULL);
  1266. ao2_ref(cap, -1);
  1267. if (!conference->playback_chan) {
  1268. return -1;
  1269. }
  1270. /* To make sure playback_chan has the same language of that profile */
  1271. ast_channel_lock(conference->playback_chan);
  1272. ast_channel_language_set(conference->playback_chan, conference->b_profile.language);
  1273. ast_channel_unlock(conference->playback_chan);
  1274. ast_debug(1, "Created announcer channel '%s' to conference bridge '%s'\n",
  1275. ast_channel_name(conference->playback_chan), conference->name);
  1276. return 0;
  1277. }
  1278. static int play_sound_helper(struct confbridge_conference *conference, const char *filename, int say_number)
  1279. {
  1280. /* Do not waste resources trying to play files that do not exist */
  1281. if (!ast_strlen_zero(filename) && !sound_file_exists(filename)) {
  1282. return 0;
  1283. }
  1284. ast_mutex_lock(&conference->playback_lock);
  1285. if (!conference->playback_chan && alloc_playback_chan(conference)) {
  1286. ast_mutex_unlock(&conference->playback_lock);
  1287. return -1;
  1288. }
  1289. if (conf_announce_channel_push(conference->playback_chan)) {
  1290. ast_mutex_unlock(&conference->playback_lock);
  1291. return -1;
  1292. }
  1293. /* The channel is all under our control, in goes the prompt */
  1294. if (!ast_strlen_zero(filename)) {
  1295. ast_stream_and_wait(conference->playback_chan, filename, "");
  1296. } else if (say_number >= 0) {
  1297. ast_say_number(conference->playback_chan, say_number, "",
  1298. ast_channel_language(conference->playback_chan), NULL);
  1299. }
  1300. ast_debug(1, "Departing announcer channel '%s' from conference bridge '%s'\n",
  1301. ast_channel_name(conference->playback_chan), conference->name);
  1302. conf_announce_channel_depart(conference->playback_chan);
  1303. ast_mutex_unlock(&conference->playback_lock);
  1304. return 0;
  1305. }
  1306. int play_sound_file(struct confbridge_conference *conference, const char *filename)
  1307. {
  1308. return play_sound_helper(conference, filename, -1);
  1309. }
  1310. /*!
  1311. * \brief Play number into the conference bridge
  1312. *
  1313. * \param conference The conference bridge to say the number into
  1314. * \param say_number number to say
  1315. *
  1316. * \retval 0 success
  1317. * \retval -1 failure
  1318. */
  1319. static int play_sound_number(struct confbridge_conference *conference, int say_number)
  1320. {
  1321. return play_sound_helper(conference, NULL, say_number);
  1322. }
  1323. static int conf_handle_talker_cb(struct ast_bridge_channel *bridge_channel, void *hook_pvt, int talking)
  1324. {
  1325. const struct confbridge_user *user = hook_pvt;
  1326. RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
  1327. struct ast_json *talking_extras;
  1328. conference = ao2_find(conference_bridges, user->conference->name, OBJ_KEY);
  1329. if (!conference) {
  1330. /* Remove the hook since the conference does not exist. */
  1331. return -1;
  1332. }
  1333. talking_extras = ast_json_pack("{s: s, s: b}",
  1334. "talking_status", talking ? "on" : "off",
  1335. "admin", ast_test_flag(&user->u_profile, USER_OPT_ADMIN));
  1336. if (!talking_extras) {
  1337. return 0;
  1338. }
  1339. send_conf_stasis(conference, bridge_channel->chan, confbridge_talking_type(), talking_extras, 0);
  1340. ast_json_unref(talking_extras);
  1341. return 0;
  1342. }
  1343. static int conf_get_pin(struct ast_channel *chan, struct confbridge_user *user)
  1344. {
  1345. char pin_guess[MAX_PIN+1] = { 0, };
  1346. const char *pin = user->u_profile.pin;
  1347. char *tmp = pin_guess;
  1348. int i, res;
  1349. unsigned int len = MAX_PIN ;
  1350. /* give them three tries to get the pin right */
  1351. for (i = 0; i < 3; i++) {
  1352. if (ast_app_getdata(chan,
  1353. conf_get_sound(CONF_SOUND_GET_PIN, user->b_profile.sounds),
  1354. tmp, len, 0) >= 0) {
  1355. if (!strcasecmp(pin, pin_guess)) {
  1356. return 0;
  1357. }
  1358. }
  1359. ast_streamfile(chan,
  1360. conf_get_sound(CONF_SOUND_INVALID_PIN, user->b_profile.sounds),
  1361. ast_channel_language(chan));
  1362. res = ast_waitstream(chan, AST_DIGIT_ANY);
  1363. if (res > 0) {
  1364. /* Account for digit already read during ivalid pin playback
  1365. * resetting pin buf. */
  1366. pin_guess[0] = res;
  1367. pin_guess[1] = '\0';
  1368. tmp = pin_guess + 1;
  1369. len = MAX_PIN - 1;
  1370. } else {
  1371. /* reset pin buf as empty buffer. */
  1372. tmp = pin_guess;
  1373. len = MAX_PIN;
  1374. }
  1375. }
  1376. return -1;
  1377. }
  1378. static int conf_rec_name(struct confbridge_user *user, const char *conf_name)
  1379. {
  1380. char destdir[PATH_MAX];
  1381. int res;
  1382. int duration = 20;
  1383. snprintf(destdir, sizeof(destdir), "%s/confbridge", ast_config_AST_SPOOL_DIR);
  1384. if (ast_mkdir(destdir, 0777) != 0) {
  1385. ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", destdir, strerror(errno));
  1386. return -1;
  1387. }
  1388. snprintf(user->name_rec_location, sizeof(user->name_rec_location),
  1389. "%s/confbridge-name-%s-%s", destdir,
  1390. conf_name, ast_channel_uniqueid(user->chan));
  1391. if (!(ast_test_flag(&user->u_profile, USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW))) {
  1392. res = ast_play_and_record(user->chan,
  1393. "vm-rec-name",
  1394. user->name_rec_location,
  1395. 10,
  1396. "sln",
  1397. &duration,
  1398. NULL,
  1399. ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE),
  1400. 0,
  1401. NULL);
  1402. } else {
  1403. res = ast_record_review(user->chan,
  1404. "vm-rec-name",
  1405. user->name_rec_location,
  1406. 10,
  1407. "sln",
  1408. &duration,
  1409. NULL);
  1410. }
  1411. if (res == -1) {
  1412. user->name_rec_location[0] = '\0';
  1413. return -1;
  1414. }
  1415. return 0;
  1416. }
  1417. /*! \brief The ConfBridge application */
  1418. static int confbridge_exec(struct ast_channel *chan, const char *data)
  1419. {
  1420. int res = 0, volume_adjustments[2];
  1421. int quiet = 0;
  1422. char *parse;
  1423. const char *b_profile_name = NULL;
  1424. const char *u_profile_name = NULL;
  1425. const char *menu_profile_name = NULL;
  1426. struct confbridge_conference *conference = NULL;
  1427. struct confbridge_user user = {
  1428. .chan = chan,
  1429. .tech_args.talking_threshold = DEFAULT_TALKING_THRESHOLD,
  1430. .tech_args.silence_threshold = DEFAULT_SILENCE_THRESHOLD,
  1431. .tech_args.drop_silence = 0,
  1432. };
  1433. AST_DECLARE_APP_ARGS(args,
  1434. AST_APP_ARG(conf_name);
  1435. AST_APP_ARG(b_profile_name);
  1436. AST_APP_ARG(u_profile_name);
  1437. AST_APP_ARG(menu_profile_name);
  1438. );
  1439. if (ast_channel_state(chan) != AST_STATE_UP) {
  1440. ast_answer(chan);
  1441. }
  1442. if (ast_bridge_features_init(&user.features)) {
  1443. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1444. res = -1;
  1445. goto confbridge_cleanup;
  1446. }
  1447. /* We need to make a copy of the input string if we are going to modify it! */
  1448. parse = ast_strdupa(data);
  1449. AST_STANDARD_APP_ARGS(args, parse);
  1450. if (ast_strlen_zero(args.conf_name)) {
  1451. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1452. ast_log(LOG_WARNING, "%s requires an argument (conference name[,options])\n", app);
  1453. res = -1;
  1454. goto confbridge_cleanup;
  1455. }
  1456. if (strlen(args.conf_name) >= MAX_CONF_NAME) {
  1457. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1458. ast_log(LOG_WARNING, "%s does not accept conference names longer than %d\n", app, MAX_CONF_NAME - 1);
  1459. res = -1;
  1460. goto confbridge_cleanup;
  1461. }
  1462. /* bridge profile name */
  1463. if (args.argc > 1 && !ast_strlen_zero(args.b_profile_name)) {
  1464. b_profile_name = args.b_profile_name;
  1465. }
  1466. if (!conf_find_bridge_profile(chan, b_profile_name, &user.b_profile)) {
  1467. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1468. ast_log(LOG_WARNING, "Conference bridge profile %s does not exist\n", b_profile_name ?
  1469. b_profile_name : DEFAULT_BRIDGE_PROFILE);
  1470. res = -1;
  1471. goto confbridge_cleanup;
  1472. }
  1473. /* user profile name */
  1474. if (args.argc > 2 && !ast_strlen_zero(args.u_profile_name)) {
  1475. u_profile_name = args.u_profile_name;
  1476. }
  1477. if (!conf_find_user_profile(chan, u_profile_name, &user.u_profile)) {
  1478. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1479. ast_log(LOG_WARNING, "Conference user profile %s does not exist\n", u_profile_name ?
  1480. u_profile_name : DEFAULT_USER_PROFILE);
  1481. res = -1;
  1482. goto confbridge_cleanup;
  1483. }
  1484. quiet = ast_test_flag(&user.u_profile, USER_OPT_QUIET);
  1485. /* ask for a PIN immediately after finding user profile. This has to be
  1486. * prompted for requardless of quiet setting. */
  1487. if (!ast_strlen_zero(user.u_profile.pin)) {
  1488. if (conf_get_pin(chan, &user)) {
  1489. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1490. res = -1; /* invalid PIN */
  1491. goto confbridge_cleanup;
  1492. }
  1493. }
  1494. /* See if we need them to record a intro name */
  1495. if (!quiet &&
  1496. (ast_test_flag(&user.u_profile, USER_OPT_ANNOUNCE_JOIN_LEAVE) ||
  1497. (ast_test_flag(&user.u_profile, USER_OPT_ANNOUNCE_JOIN_LEAVE_REVIEW)))) {
  1498. conf_rec_name(&user, args.conf_name);
  1499. }
  1500. /* menu name */
  1501. if (args.argc > 3 && !ast_strlen_zero(args.menu_profile_name)) {
  1502. menu_profile_name = args.menu_profile_name;
  1503. }
  1504. if (conf_set_menu_to_user(chan, &user, menu_profile_name)) {
  1505. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1506. ast_log(LOG_WARNING, "Conference menu profile %s does not exist\n", menu_profile_name ?
  1507. menu_profile_name : DEFAULT_MENU_PROFILE);
  1508. res = -1;
  1509. goto confbridge_cleanup;
  1510. }
  1511. /* Set if DTMF should pass through for this user or not */
  1512. if (ast_test_flag(&user.u_profile, USER_OPT_DTMF_PASS)) {
  1513. user.features.dtmf_passthrough = 1;
  1514. } else {
  1515. user.features.dtmf_passthrough = 0;
  1516. }
  1517. /* Set dsp threshold values if present */
  1518. if (user.u_profile.talking_threshold) {
  1519. user.tech_args.talking_threshold = user.u_profile.talking_threshold;
  1520. }
  1521. if (user.u_profile.silence_threshold) {
  1522. user.tech_args.silence_threshold = user.u_profile.silence_threshold;
  1523. }
  1524. /* Set a talker indicate call back if talking detection is requested */
  1525. if (ast_test_flag(&user.u_profile, USER_OPT_TALKER_DETECT)) {
  1526. if (ast_bridge_talk_detector_hook(&user.features, conf_handle_talker_cb,
  1527. &user, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL)) {
  1528. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1529. res = -1;
  1530. goto confbridge_cleanup;
  1531. }
  1532. }
  1533. /* If the caller should be joined already muted, set the flag before we join. */
  1534. if (ast_test_flag(&user.u_profile, USER_OPT_STARTMUTED)) {
  1535. /* Set user level mute request. */
  1536. user.muted = 1;
  1537. }
  1538. /* Look for a conference bridge matching the provided name */
  1539. if (!(conference = join_conference_bridge(args.conf_name, &user))) {
  1540. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "FAILED");
  1541. res = -1;
  1542. goto confbridge_cleanup;
  1543. }
  1544. /* Keep a copy of volume adjustments so we can restore them later if need be */
  1545. volume_adjustments[0] = ast_audiohook_volume_get(chan, AST_AUDIOHOOK_DIRECTION_READ);
  1546. volume_adjustments[1] = ast_audiohook_volume_get(chan, AST_AUDIOHOOK_DIRECTION_WRITE);
  1547. if (ast_test_flag(&user.u_profile, USER_OPT_DROP_SILENCE)) {
  1548. user.tech_args.drop_silence = 1;
  1549. }
  1550. if (ast_test_flag(&user.u_profile, USER_OPT_JITTERBUFFER)) {
  1551. char *func_jb;
  1552. if ((func_jb = ast_module_helper("", "func_jitterbuffer", 0, 0, 0, 0))) {
  1553. ast_free(func_jb);
  1554. ast_func_write(chan, "JITTERBUFFER(adaptive)", "default");
  1555. }
  1556. }
  1557. if (ast_test_flag(&user.u_profile, USER_OPT_DENOISE)) {
  1558. char *mod_speex;
  1559. /* Reduce background noise from each participant */
  1560. if ((mod_speex = ast_module_helper("", "codec_speex", 0, 0, 0, 0))) {
  1561. ast_free(mod_speex);
  1562. ast_func_write(chan, "DENOISE(rx)", "on");
  1563. }
  1564. }
  1565. /* if this user has a intro, play it before entering */
  1566. if (!ast_strlen_zero(user.name_rec_location)) {
  1567. ast_autoservice_start(chan);
  1568. play_sound_file(conference, user.name_rec_location);
  1569. play_sound_file(conference,
  1570. conf_get_sound(CONF_SOUND_HAS_JOINED, user.b_profile.sounds));
  1571. ast_autoservice_stop(chan);
  1572. }
  1573. /* Play the Join sound to both the conference and the user entering. */
  1574. if (!quiet) {
  1575. const char *join_sound = conf_get_sound(CONF_SOUND_JOIN, user.b_profile.sounds);
  1576. ast_stream_and_wait(chan, join_sound, "");
  1577. ast_autoservice_start(chan);
  1578. play_sound_file(conference, join_sound);
  1579. ast_autoservice_stop(chan);
  1580. }
  1581. /* See if we need to automatically set this user as a video source or not */
  1582. handle_video_on_join(conference, user.chan, ast_test_flag(&user.u_profile, USER_OPT_MARKEDUSER));
  1583. conf_moh_unsuspend(&user);
  1584. /* Join our conference bridge for real */
  1585. send_join_event(&user, conference);
  1586. ast_bridge_join(conference->bridge,
  1587. chan,
  1588. NULL,
  1589. &user.features,
  1590. &user.tech_args,
  1591. 0);
  1592. if (!user.kicked && ast_check_hangup(chan)) {
  1593. pbx_builtin_setvar_helper(chan, "CONFBRIDGE_RESULT", "HANGUP");
  1594. }
  1595. send_leave_event(&user, conference);
  1596. /* if we're shutting down, don't attempt to do further processing */
  1597. if (ast_shutting_down()) {
  1598. /*
  1599. * Not taking any new calls at this time. We cannot create
  1600. * the announcer channel if this is the first channel into
  1601. * the conference and we certainly cannot create any
  1602. * recording channel.
  1603. */
  1604. leave_conference(&user);
  1605. conference = NULL;
  1606. goto confbridge_cleanup;
  1607. }
  1608. /* If this user was a video source, we need to clean up and possibly pick a new source. */
  1609. handle_video_on_exit(conference, user.chan);
  1610. /* if this user has a intro, play it when leaving */
  1611. if (!quiet && !ast_strlen_zero(user.name_rec_location)) {
  1612. ast_autoservice_start(chan);
  1613. play_sound_file(conference, user.name_rec_location);
  1614. play_sound_file(conference,
  1615. conf_get_sound(CONF_SOUND_HAS_LEFT, user.b_profile.sounds));
  1616. ast_autoservice_stop(chan);
  1617. }
  1618. /* play the leave sound */
  1619. if (!quiet) {
  1620. const char *leave_sound = conf_get_sound(CONF_SOUND_LEAVE, user.b_profile.sounds);
  1621. ast_autoservice_start(chan);
  1622. play_sound_file(conference, leave_sound);
  1623. ast_autoservice_stop(chan);
  1624. }
  1625. /* Easy as pie, depart this channel from the conference bridge */
  1626. leave_conference(&user);
  1627. conference = NULL;
  1628. /* If the user was kicked from the conference play back the audio prompt for it */
  1629. if (!quiet && user.kicked) {
  1630. res = ast_stream_and_wait(chan,
  1631. conf_get_sound(CONF_SOUND_KICKED, user.b_profile.sounds),
  1632. "");
  1633. }
  1634. /* Restore volume adjustments to previous values in case they were changed */
  1635. if (volume_adjustments[0]) {
  1636. ast_audiohook_volume_set(chan, AST_AUDIOHOOK_DIRECTION_READ, volume_adjustments[0]);
  1637. }
  1638. if (volume_adjustments[1]) {
  1639. ast_audiohook_volume_set(chan, AST_AUDIOHOOK_DIRECTION_WRITE, volume_adjustments[1]);
  1640. }
  1641. if (!ast_strlen_zero(user.name_rec_location)) {
  1642. ast_filedelete(user.name_rec_location, NULL);
  1643. }
  1644. confbridge_cleanup:
  1645. ast_bridge_features_cleanup(&user.features);
  1646. conf_bridge_profile_destroy(&user.b_profile);
  1647. return res;
  1648. }
  1649. static int action_toggle_mute(struct confbridge_conference *conference,
  1650. struct confbridge_user *user,
  1651. struct ast_bridge_channel *bridge_channel)
  1652. {
  1653. int mute;
  1654. /* Toggle user level mute request. */
  1655. mute = !user->muted;
  1656. user->muted = mute;
  1657. conf_update_user_mute(user);
  1658. ast_test_suite_event_notify("CONF_MUTE",
  1659. "Message: participant %s %s\r\n"
  1660. "Conference: %s\r\n"
  1661. "Channel: %s",
  1662. ast_channel_name(user->chan),
  1663. mute ? "muted" : "unmuted",
  1664. user->b_profile.name,
  1665. ast_channel_name(user->chan));
  1666. if (mute) {
  1667. send_mute_event(user, conference);
  1668. } else {
  1669. send_unmute_event(user, conference);
  1670. }
  1671. return play_file(bridge_channel, NULL, (mute ?
  1672. conf_get_sound(CONF_SOUND_MUTED, user->b_profile.sounds) :
  1673. conf_get_sound(CONF_SOUND_UNMUTED, user->b_profile.sounds))) < 0;
  1674. }
  1675. static int action_toggle_mute_participants(struct confbridge_conference *conference, struct confbridge_user *user)
  1676. {
  1677. struct confbridge_user *cur_user = NULL;
  1678. const char *sound_to_play;
  1679. int mute;
  1680. ao2_lock(conference);
  1681. /* Toggle bridge level mute request. */
  1682. mute = !conference->muted;
  1683. conference->muted = mute;
  1684. AST_LIST_TRAVERSE(&conference->active_list, cur_user, list) {
  1685. if (!ast_test_flag(&cur_user->u_profile, USER_OPT_ADMIN)) {
  1686. /* Set user level to bridge level mute request. */
  1687. cur_user->muted = mute;
  1688. conf_update_user_mute(cur_user);
  1689. }
  1690. }
  1691. ao2_unlock(conference);
  1692. sound_to_play = conf_get_sound((mute ? CONF_SOUND_PARTICIPANTS_MUTED : CONF_SOUND_PARTICIPANTS_UNMUTED),
  1693. user->b_profile.sounds);
  1694. /* The host needs to hear it seperately, as they don't get the audio from play_sound_helper */
  1695. ast_stream_and_wait(user->chan, sound_to_play, "");
  1696. /* Announce to the group that all participants are muted */
  1697. ast_autoservice_start(user->chan);
  1698. play_sound_helper(conference, sound_to_play, 0);
  1699. ast_autoservice_stop(user->chan);
  1700. return 0;
  1701. }
  1702. static int action_playback(struct ast_bridge_channel *bridge_channel, const char *playback_file)
  1703. {
  1704. char *file_copy = ast_strdupa(playback_file);
  1705. char *file = NULL;
  1706. while ((file = strsep(&file_copy, "&"))) {
  1707. if (ast_stream_and_wait(bridge_channel->chan, file, "")) {
  1708. ast_log(LOG_WARNING, "Failed to playback file %s to channel\n", file);
  1709. return -1;
  1710. }
  1711. }
  1712. return 0;
  1713. }
  1714. static int action_playback_and_continue(struct confbridge_conference *conference,
  1715. struct confbridge_user *user,
  1716. struct ast_bridge_channel *bridge_channel,
  1717. struct conf_menu *menu,
  1718. const char *playback_file,
  1719. const char *cur_dtmf,
  1720. int *stop_prompts)
  1721. {
  1722. int i;
  1723. int digit = 0;
  1724. char dtmf[MAXIMUM_DTMF_FEATURE_STRING];
  1725. struct conf_menu_entry new_menu_entry = { { 0, }, };
  1726. char *file_copy = ast_strdupa(playback_file);
  1727. char *file = NULL;
  1728. while ((file = strsep(&file_copy, "&"))) {
  1729. if (ast_streamfile(bridge_channel->chan, file, ast_channel_language(bridge_channel->chan))) {
  1730. ast_log(LOG_WARNING, "Failed to playback file %s to channel\n", file);
  1731. return -1;
  1732. }
  1733. /* now wait for more digits. */
  1734. if (!(digit = ast_waitstream(bridge_channel->chan, AST_DIGIT_ANY))) {
  1735. /* streaming finished and no DTMF was entered */
  1736. continue;
  1737. } else if (digit == -1) {
  1738. /* error */
  1739. return -1;
  1740. } else {
  1741. break; /* dtmf was entered */
  1742. }
  1743. }
  1744. if (!digit) {
  1745. /* streaming finished on all files and no DTMF was entered */
  1746. return -1;
  1747. }
  1748. ast_stopstream(bridge_channel->chan);
  1749. /* If we get here, then DTMF has been entered, This means no
  1750. * additional prompts should be played for this menu entry */
  1751. *stop_prompts = 1;
  1752. /* If a digit was pressed during the payback, update
  1753. * the dtmf string and look for a new menu entry in the
  1754. * menu structure */
  1755. ast_copy_string(dtmf, cur_dtmf, sizeof(dtmf));
  1756. for (i = 0; i < (MAXIMUM_DTMF_FEATURE_STRING - 1); i++) {
  1757. dtmf[i] = cur_dtmf[i];
  1758. if (!dtmf[i]) {
  1759. dtmf[i] = (char) digit;
  1760. dtmf[i + 1] = '\0';
  1761. i = -1;
  1762. break;
  1763. }
  1764. }
  1765. /* If i is not -1 then the new dtmf digit was _NOT_ added to the string.
  1766. * If this is the case, no new DTMF sequence should be looked for. */
  1767. if (i != -1) {
  1768. return 0;
  1769. }
  1770. if (conf_find_menu_entry_by_sequence(dtmf, menu, &new_menu_entry)) {
  1771. execute_menu_entry(conference,
  1772. user,
  1773. bridge_channel,
  1774. &new_menu_entry, menu);
  1775. conf_menu_entry_destroy(&new_menu_entry);
  1776. }
  1777. return 0;
  1778. }
  1779. static int action_kick_last(struct confbridge_conference *conference,
  1780. struct ast_bridge_channel *bridge_channel,
  1781. struct confbridge_user *user)
  1782. {
  1783. struct confbridge_user *last_user = NULL;
  1784. int isadmin = ast_test_flag(&user->u_profile, USER_OPT_ADMIN);
  1785. if (!isadmin) {
  1786. play_file(bridge_channel, NULL,
  1787. conf_get_sound(CONF_SOUND_ERROR_MENU, user->b_profile.sounds));
  1788. ast_log(LOG_WARNING, "Only admin users can use the kick_last menu action. Channel %s of conf %s is not an admin.\n",
  1789. ast_channel_name(bridge_channel->chan),
  1790. conference->name);
  1791. return -1;
  1792. }
  1793. ao2_lock(conference);
  1794. if (((last_user = AST_LIST_LAST(&conference->active_list)) == user)
  1795. || (ast_test_flag(&last_user->u_profile, USER_OPT_ADMIN))) {
  1796. ao2_unlock(conference);
  1797. play_file(bridge_channel, NULL,
  1798. conf_get_sound(CONF_SOUND_ERROR_MENU, user->b_profile.sounds));
  1799. } else if (last_user && !last_user->kicked) {
  1800. last_user->kicked = 1;
  1801. pbx_builtin_setvar_helper(last_user->chan, "CONFBRIDGE_RESULT", "KICKED");
  1802. ast_bridge_remove(conference->bridge, last_user->chan);
  1803. ao2_unlock(conference);
  1804. }
  1805. return 0;
  1806. }
  1807. static int action_dialplan_exec(struct ast_bridge_channel *bridge_channel, struct conf_menu_action *menu_action)
  1808. {
  1809. struct ast_pbx_args args;
  1810. struct ast_pbx *pbx;
  1811. char *exten;
  1812. char *context;
  1813. int priority;
  1814. int res;
  1815. memset(&args, 0, sizeof(args));
  1816. args.no_hangup_chan = 1;
  1817. ast_channel_lock(bridge_channel->chan);
  1818. /*save off*/
  1819. exten = ast_strdupa(ast_channel_exten(bridge_channel->chan));
  1820. context = ast_strdupa(ast_channel_context(bridge_channel->chan));
  1821. priority = ast_channel_priority(bridge_channel->chan);
  1822. pbx = ast_channel_pbx(bridge_channel->chan);
  1823. ast_channel_pbx_set(bridge_channel->chan, NULL);
  1824. /*set new*/
  1825. ast_channel_exten_set(bridge_channel->chan, menu_action->data.dialplan_args.exten);
  1826. ast_channel_context_set(bridge_channel->chan, menu_action->data.dialplan_args.context);
  1827. ast_channel_priority_set(bridge_channel->chan, menu_action->data.dialplan_args.priority);
  1828. ast_channel_unlock(bridge_channel->chan);
  1829. /*execute*/
  1830. res = ast_pbx_run_args(bridge_channel->chan, &args);
  1831. /*restore*/
  1832. ast_channel_lock(bridge_channel->chan);
  1833. ast_channel_exten_set(bridge_channel->chan, exten);
  1834. ast_channel_context_set(bridge_channel->chan, context);
  1835. ast_channel_priority_set(bridge_channel->chan, priority);
  1836. ast_channel_pbx_set(bridge_channel->chan, pbx);
  1837. ast_channel_unlock(bridge_channel->chan);
  1838. return res;
  1839. }
  1840. static int execute_menu_entry(struct confbridge_conference *conference,
  1841. struct confbridge_user *user,
  1842. struct ast_bridge_channel *bridge_channel,
  1843. struct conf_menu_entry *menu_entry,
  1844. struct conf_menu *menu)
  1845. {
  1846. struct conf_menu_action *menu_action;
  1847. int isadmin = ast_test_flag(&user->u_profile, USER_OPT_ADMIN);
  1848. int stop_prompts = 0;
  1849. int res = 0;
  1850. AST_LIST_TRAVERSE(&menu_entry->actions, menu_action, action) {
  1851. switch (menu_action->id) {
  1852. case MENU_ACTION_TOGGLE_MUTE:
  1853. res |= action_toggle_mute(conference, user, bridge_channel);
  1854. break;
  1855. case MENU_ACTION_ADMIN_TOGGLE_MUTE_PARTICIPANTS:
  1856. if (!isadmin) {
  1857. break;
  1858. }
  1859. action_toggle_mute_participants(conference, user);
  1860. break;
  1861. case MENU_ACTION_PARTICIPANT_COUNT:
  1862. announce_user_count(conference, user, bridge_channel);
  1863. break;
  1864. case MENU_ACTION_PLAYBACK:
  1865. if (!stop_prompts) {
  1866. res |= action_playback(bridge_channel, menu_action->data.playback_file);
  1867. ast_test_suite_event_notify("CONF_MENU_PLAYBACK",
  1868. "Message: %s\r\nChannel: %s",
  1869. menu_action->data.playback_file, ast_channel_name(bridge_channel->chan));
  1870. }
  1871. break;
  1872. case MENU_ACTION_RESET_LISTENING:
  1873. ast_audiohook_volume_set(user->chan, AST_AUDIOHOOK_DIRECTION_WRITE, 0);
  1874. break;
  1875. case MENU_ACTION_RESET_TALKING:
  1876. ast_audiohook_volume_set(user->chan, AST_AUDIOHOOK_DIRECTION_READ, 0);
  1877. break;
  1878. case MENU_ACTION_INCREASE_LISTENING:
  1879. ast_audiohook_volume_adjust(user->chan,
  1880. AST_AUDIOHOOK_DIRECTION_WRITE, 1);
  1881. break;
  1882. case MENU_ACTION_DECREASE_LISTENING:
  1883. ast_audiohook_volume_adjust(user->chan,
  1884. AST_AUDIOHOOK_DIRECTION_WRITE, -1);
  1885. break;
  1886. case MENU_ACTION_INCREASE_TALKING:
  1887. ast_audiohook_volume_adjust(user->chan,
  1888. AST_AUDIOHOOK_DIRECTION_READ, 1);
  1889. break;
  1890. case MENU_ACTION_DECREASE_TALKING:
  1891. ast_audiohook_volume_adjust(user->chan,
  1892. AST_AUDIOHOOK_DIRECTION_READ, -1);
  1893. break;
  1894. case MENU_ACTION_PLAYBACK_AND_CONTINUE:
  1895. if (!(stop_prompts)) {
  1896. res |= action_playback_and_continue(conference,
  1897. user,
  1898. bridge_channel,
  1899. menu,
  1900. menu_action->data.playback_file,
  1901. menu_entry->dtmf,
  1902. &stop_prompts);
  1903. }
  1904. break;
  1905. case MENU_ACTION_DIALPLAN_EXEC:
  1906. res |= action_dialplan_exec(bridge_channel, menu_action);
  1907. break;
  1908. case MENU_ACTION_ADMIN_TOGGLE_LOCK:
  1909. if (!isadmin) {
  1910. break;
  1911. }
  1912. conference->locked = (!conference->locked ? 1 : 0);
  1913. res |= play_file(bridge_channel, NULL,
  1914. (conference->locked ?
  1915. conf_get_sound(CONF_SOUND_LOCKED_NOW, user->b_profile.sounds) :
  1916. conf_get_sound(CONF_SOUND_UNLOCKED_NOW, user->b_profile.sounds))) < 0;
  1917. break;
  1918. case MENU_ACTION_ADMIN_KICK_LAST:
  1919. res |= action_kick_last(conference, bridge_channel, user);
  1920. break;
  1921. case MENU_ACTION_LEAVE:
  1922. pbx_builtin_setvar_helper(bridge_channel->chan, "CONFBRIDGE_RESULT", "DTMF");
  1923. ao2_lock(conference);
  1924. ast_bridge_remove(conference->bridge, bridge_channel->chan);
  1925. ast_test_suite_event_notify("CONF_MENU_LEAVE",
  1926. "Channel: %s",
  1927. ast_channel_name(bridge_channel->chan));
  1928. ao2_unlock(conference);
  1929. break;
  1930. case MENU_ACTION_NOOP:
  1931. break;
  1932. case MENU_ACTION_SET_SINGLE_VIDEO_SRC:
  1933. ao2_lock(conference);
  1934. ast_bridge_set_single_src_video_mode(conference->bridge, bridge_channel->chan);
  1935. ao2_unlock(conference);
  1936. break;
  1937. case MENU_ACTION_RELEASE_SINGLE_VIDEO_SRC:
  1938. handle_video_on_exit(conference, bridge_channel->chan);
  1939. break;
  1940. }
  1941. }
  1942. return res;
  1943. }
  1944. int conf_handle_dtmf(struct ast_bridge_channel *bridge_channel,
  1945. struct confbridge_user *user,
  1946. struct conf_menu_entry *menu_entry,
  1947. struct conf_menu *menu)
  1948. {
  1949. /* See if music on hold is playing */
  1950. conf_moh_suspend(user);
  1951. /* execute the list of actions associated with this menu entry */
  1952. execute_menu_entry(user->conference, user, bridge_channel, menu_entry, menu);
  1953. /* See if music on hold needs to be started back up again */
  1954. conf_moh_unsuspend(user);
  1955. return 0;
  1956. }
  1957. static int kick_conference_participant(struct confbridge_conference *conference,
  1958. const char *channel)
  1959. {
  1960. int res = -1;
  1961. int match;
  1962. struct confbridge_user *user = NULL;
  1963. int all = !strcasecmp("all", channel);
  1964. int participants = !strcasecmp("participants", channel);
  1965. SCOPED_AO2LOCK(bridge_lock, conference);
  1966. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  1967. if (user->kicked) {
  1968. continue;
  1969. }
  1970. match = !strcasecmp(channel, ast_channel_name(user->chan));
  1971. if (match || all
  1972. || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
  1973. user->kicked = 1;
  1974. pbx_builtin_setvar_helper(user->chan, "CONFBRIDGE_RESULT", "KICKED");
  1975. ast_bridge_remove(conference->bridge, user->chan);
  1976. res = 0;
  1977. if (match) {
  1978. return res;
  1979. }
  1980. }
  1981. }
  1982. AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
  1983. if (user->kicked) {
  1984. continue;
  1985. }
  1986. match = !strcasecmp(channel, ast_channel_name(user->chan));
  1987. if (match || all
  1988. || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
  1989. user->kicked = 1;
  1990. pbx_builtin_setvar_helper(user->chan, "CONFBRIDGE_RESULT", "KICKED");
  1991. ast_bridge_remove(conference->bridge, user->chan);
  1992. res = 0;
  1993. if (match) {
  1994. return res;
  1995. }
  1996. }
  1997. }
  1998. return res;
  1999. }
  2000. static char *complete_confbridge_name(const char *line, const char *word, int pos, int state)
  2001. {
  2002. int which = 0;
  2003. struct confbridge_conference *conference;
  2004. char *res = NULL;
  2005. int wordlen = strlen(word);
  2006. struct ao2_iterator iter;
  2007. iter = ao2_iterator_init(conference_bridges, 0);
  2008. while ((conference = ao2_iterator_next(&iter))) {
  2009. if (!strncasecmp(conference->name, word, wordlen) && ++which > state) {
  2010. res = ast_strdup(conference->name);
  2011. ao2_ref(conference, -1);
  2012. break;
  2013. }
  2014. ao2_ref(conference, -1);
  2015. }
  2016. ao2_iterator_destroy(&iter);
  2017. return res;
  2018. }
  2019. static char *complete_confbridge_participant(const char *conference_name, const char *line, const char *word, int pos, int state)
  2020. {
  2021. int which = 0;
  2022. RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
  2023. struct confbridge_user *user;
  2024. char *res = NULL;
  2025. int wordlen = strlen(word);
  2026. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2027. if (!conference) {
  2028. return NULL;
  2029. }
  2030. if (!strncasecmp("all", word, wordlen) && ++which > state) {
  2031. return ast_strdup("all");
  2032. }
  2033. if (!strncasecmp("participants", word, wordlen) && ++which > state) {
  2034. return ast_strdup("participants");
  2035. }
  2036. {
  2037. SCOPED_AO2LOCK(bridge_lock, conference);
  2038. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2039. if (!strncasecmp(ast_channel_name(user->chan), word, wordlen) && ++which > state) {
  2040. res = ast_strdup(ast_channel_name(user->chan));
  2041. return res;
  2042. }
  2043. }
  2044. AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
  2045. if (!strncasecmp(ast_channel_name(user->chan), word, wordlen) && ++which > state) {
  2046. res = ast_strdup(ast_channel_name(user->chan));
  2047. return res;
  2048. }
  2049. }
  2050. }
  2051. return NULL;
  2052. }
  2053. static char *handle_cli_confbridge_kick(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2054. {
  2055. struct confbridge_conference *conference;
  2056. int not_found;
  2057. switch (cmd) {
  2058. case CLI_INIT:
  2059. e->command = "confbridge kick";
  2060. e->usage =
  2061. "Usage: confbridge kick <conference> <channel>\n"
  2062. " Kicks a channel out of the conference bridge.\n"
  2063. " (all to kick everyone, participants to kick non-admins).\n";
  2064. return NULL;
  2065. case CLI_GENERATE:
  2066. if (a->pos == 2) {
  2067. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2068. }
  2069. if (a->pos == 3) {
  2070. return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
  2071. }
  2072. return NULL;
  2073. }
  2074. if (a->argc != 4) {
  2075. return CLI_SHOWUSAGE;
  2076. }
  2077. conference = ao2_find(conference_bridges, a->argv[2], OBJ_KEY);
  2078. if (!conference) {
  2079. ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
  2080. return CLI_SUCCESS;
  2081. }
  2082. not_found = kick_conference_participant(conference, a->argv[3]);
  2083. ao2_ref(conference, -1);
  2084. if (not_found) {
  2085. if (!strcasecmp("all", a->argv[3]) || !strcasecmp("participants", a->argv[3])) {
  2086. ast_cli(a->fd, "No participants found!\n");
  2087. } else {
  2088. ast_cli(a->fd, "No participant named '%s' found!\n", a->argv[3]);
  2089. }
  2090. return CLI_SUCCESS;
  2091. }
  2092. ast_cli(a->fd, "Kicked '%s' out of conference '%s'\n", a->argv[3], a->argv[2]);
  2093. return CLI_SUCCESS;
  2094. }
  2095. static void handle_cli_confbridge_list_item(struct ast_cli_args *a, struct confbridge_user *user, int waiting)
  2096. {
  2097. char flag_str[6 + 1];/* Max flags + terminator */
  2098. int pos = 0;
  2099. /* Build flags column string. */
  2100. if (ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
  2101. flag_str[pos++] = 'A';
  2102. }
  2103. if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
  2104. flag_str[pos++] = 'M';
  2105. }
  2106. if (ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED)) {
  2107. flag_str[pos++] = 'W';
  2108. }
  2109. if (ast_test_flag(&user->u_profile, USER_OPT_ENDMARKED)) {
  2110. flag_str[pos++] = 'E';
  2111. }
  2112. if (user->muted) {
  2113. flag_str[pos++] = 'm';
  2114. }
  2115. if (waiting) {
  2116. flag_str[pos++] = 'w';
  2117. }
  2118. flag_str[pos] = '\0';
  2119. ast_cli(a->fd, "%-30s %-6s %-16s %-16s %-16s %s\n",
  2120. ast_channel_name(user->chan),
  2121. flag_str,
  2122. user->u_profile.name,
  2123. user->b_profile.name,
  2124. user->menu_name,
  2125. S_COR(ast_channel_caller(user->chan)->id.number.valid,
  2126. ast_channel_caller(user->chan)->id.number.str, "<unknown>"));
  2127. }
  2128. static char *handle_cli_confbridge_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2129. {
  2130. struct confbridge_conference *conference;
  2131. switch (cmd) {
  2132. case CLI_INIT:
  2133. e->command = "confbridge list";
  2134. e->usage =
  2135. "Usage: confbridge list [<name>]\n"
  2136. " Lists all currently active conference bridges or a specific conference bridge.\n"
  2137. "\n"
  2138. " When a conference bridge name is provided, flags may be shown for users. Below\n"
  2139. " are the flags and what they represent.\n"
  2140. "\n"
  2141. " Flags:\n"
  2142. " A - The user is an admin\n"
  2143. " M - The user is a marked user\n"
  2144. " W - The user must wait for a marked user to join\n"
  2145. " E - The user will be kicked after the last marked user leaves the conference\n"
  2146. " m - The user is muted\n"
  2147. " w - The user is waiting for a marked user to join\n";
  2148. return NULL;
  2149. case CLI_GENERATE:
  2150. if (a->pos == 2) {
  2151. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2152. }
  2153. return NULL;
  2154. }
  2155. if (a->argc == 2) {
  2156. struct ao2_iterator iter;
  2157. ast_cli(a->fd, "Conference Bridge Name Users Marked Locked?\n");
  2158. ast_cli(a->fd, "================================ ====== ====== ========\n");
  2159. iter = ao2_iterator_init(conference_bridges, 0);
  2160. while ((conference = ao2_iterator_next(&iter))) {
  2161. ast_cli(a->fd, "%-32s %6u %6u %s\n", conference->name, conference->activeusers + conference->waitingusers, conference->markedusers, (conference->locked ? "locked" : "unlocked"));
  2162. ao2_ref(conference, -1);
  2163. }
  2164. ao2_iterator_destroy(&iter);
  2165. return CLI_SUCCESS;
  2166. }
  2167. if (a->argc == 3) {
  2168. struct confbridge_user *user;
  2169. conference = ao2_find(conference_bridges, a->argv[2], OBJ_KEY);
  2170. if (!conference) {
  2171. ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
  2172. return CLI_SUCCESS;
  2173. }
  2174. ast_cli(a->fd, "Channel Flags User Profile Bridge Profile Menu CallerID\n");
  2175. ast_cli(a->fd, "============================== ====== ================ ================ ================ ================\n");
  2176. ao2_lock(conference);
  2177. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2178. handle_cli_confbridge_list_item(a, user, 0);
  2179. }
  2180. AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
  2181. handle_cli_confbridge_list_item(a, user, 1);
  2182. }
  2183. ao2_unlock(conference);
  2184. ao2_ref(conference, -1);
  2185. return CLI_SUCCESS;
  2186. }
  2187. return CLI_SHOWUSAGE;
  2188. }
  2189. /* \internal
  2190. * \brief finds a conference by name and locks/unlocks.
  2191. *
  2192. * \retval 0 success
  2193. * \retval -1 conference not found
  2194. */
  2195. static int generic_lock_unlock_helper(int lock, const char *conference_name)
  2196. {
  2197. struct confbridge_conference *conference;
  2198. int res = 0;
  2199. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2200. if (!conference) {
  2201. return -1;
  2202. }
  2203. ao2_lock(conference);
  2204. conference->locked = lock;
  2205. ast_test_suite_event_notify("CONF_LOCK", "Message: conference %s\r\nConference: %s", conference->locked ? "locked" : "unlocked", conference->b_profile.name);
  2206. ao2_unlock(conference);
  2207. ao2_ref(conference, -1);
  2208. return res;
  2209. }
  2210. /* \internal
  2211. * \brief Mute/unmute a single user.
  2212. */
  2213. static void generic_mute_unmute_user(struct confbridge_conference *conference, struct confbridge_user *user, int mute)
  2214. {
  2215. /* Set user level mute request. */
  2216. user->muted = mute ? 1 : 0;
  2217. conf_update_user_mute(user);
  2218. ast_test_suite_event_notify("CONF_MUTE",
  2219. "Message: participant %s %s\r\n"
  2220. "Conference: %s\r\n"
  2221. "Channel: %s",
  2222. ast_channel_name(user->chan),
  2223. mute ? "muted" : "unmuted",
  2224. conference->b_profile.name,
  2225. ast_channel_name(user->chan));
  2226. if (mute) {
  2227. send_mute_event(user, conference);
  2228. } else {
  2229. send_unmute_event(user, conference);
  2230. }
  2231. }
  2232. /* \internal
  2233. * \brief finds a conference user by channel name and mutes/unmutes them.
  2234. *
  2235. * \retval 0 success
  2236. * \retval -1 conference not found
  2237. * \retval -2 user not found
  2238. */
  2239. static int generic_mute_unmute_helper(int mute, const char *conference_name,
  2240. const char *chan_name)
  2241. {
  2242. RAII_VAR(struct confbridge_conference *, conference, NULL, ao2_cleanup);
  2243. struct confbridge_user *user;
  2244. int all = !strcasecmp("all", chan_name);
  2245. int participants = !strcasecmp("participants", chan_name);
  2246. int res = -2;
  2247. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2248. if (!conference) {
  2249. return -1;
  2250. }
  2251. {
  2252. SCOPED_AO2LOCK(bridge_lock, conference);
  2253. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2254. int match = !strncasecmp(chan_name, ast_channel_name(user->chan),
  2255. strlen(chan_name));
  2256. if (match || all
  2257. || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
  2258. generic_mute_unmute_user(conference, user, mute);
  2259. res = 0;
  2260. if (match) {
  2261. return res;
  2262. }
  2263. }
  2264. }
  2265. AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
  2266. int match = !strncasecmp(chan_name, ast_channel_name(user->chan),
  2267. strlen(chan_name));
  2268. if (match || all
  2269. || (participants && !ast_test_flag(&user->u_profile, USER_OPT_ADMIN))) {
  2270. generic_mute_unmute_user(conference, user, mute);
  2271. res = 0;
  2272. if (match) {
  2273. return res;
  2274. }
  2275. }
  2276. }
  2277. }
  2278. return res;
  2279. }
  2280. static int cli_mute_unmute_helper(int mute, struct ast_cli_args *a)
  2281. {
  2282. int res = generic_mute_unmute_helper(mute, a->argv[2], a->argv[3]);
  2283. if (res == -1) {
  2284. ast_cli(a->fd, "No conference bridge named '%s' found!\n", a->argv[2]);
  2285. return -1;
  2286. } else if (res == -2) {
  2287. if (!strcasecmp("all", a->argv[3]) || !strcasecmp("participants", a->argv[3])) {
  2288. ast_cli(a->fd, "No participants found in conference %s\n", a->argv[2]);
  2289. } else {
  2290. ast_cli(a->fd, "No channel named '%s' found in conference %s\n", a->argv[3], a->argv[2]);
  2291. }
  2292. return -1;
  2293. }
  2294. ast_cli(a->fd, "%s %s from confbridge %s\n", mute ? "Muting" : "Unmuting", a->argv[3], a->argv[2]);
  2295. return 0;
  2296. }
  2297. static char *handle_cli_confbridge_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2298. {
  2299. switch (cmd) {
  2300. case CLI_INIT:
  2301. e->command = "confbridge mute";
  2302. e->usage =
  2303. "Usage: confbridge mute <conference> <channel>\n"
  2304. " Mute a channel in a conference.\n"
  2305. " (all to mute everyone, participants to mute non-admins)\n"
  2306. " If the specified channel is a prefix,\n"
  2307. " the action will be taken on the first\n"
  2308. " matching channel.\n";
  2309. return NULL;
  2310. case CLI_GENERATE:
  2311. if (a->pos == 2) {
  2312. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2313. }
  2314. if (a->pos == 3) {
  2315. return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
  2316. }
  2317. return NULL;
  2318. }
  2319. if (a->argc != 4) {
  2320. return CLI_SHOWUSAGE;
  2321. }
  2322. cli_mute_unmute_helper(1, a);
  2323. return CLI_SUCCESS;
  2324. }
  2325. static char *handle_cli_confbridge_unmute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2326. {
  2327. switch (cmd) {
  2328. case CLI_INIT:
  2329. e->command = "confbridge unmute";
  2330. e->usage =
  2331. "Usage: confbridge unmute <conference> <channel>\n"
  2332. " Unmute a channel in a conference.\n"
  2333. " (all to unmute everyone, participants to unmute non-admins)\n"
  2334. " If the specified channel is a prefix,\n"
  2335. " the action will be taken on the first\n"
  2336. " matching channel.\n";
  2337. return NULL;
  2338. case CLI_GENERATE:
  2339. if (a->pos == 2) {
  2340. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2341. }
  2342. if (a->pos == 3) {
  2343. return complete_confbridge_participant(a->argv[2], a->line, a->word, a->pos, a->n);
  2344. }
  2345. return NULL;
  2346. }
  2347. if (a->argc != 4) {
  2348. return CLI_SHOWUSAGE;
  2349. }
  2350. cli_mute_unmute_helper(0, a);
  2351. return CLI_SUCCESS;
  2352. }
  2353. static char *handle_cli_confbridge_lock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2354. {
  2355. switch (cmd) {
  2356. case CLI_INIT:
  2357. e->command = "confbridge lock";
  2358. e->usage =
  2359. "Usage: confbridge lock <conference>\n"
  2360. " Lock a conference. While locked, no new non-admins\n"
  2361. " may join the conference.\n";
  2362. return NULL;
  2363. case CLI_GENERATE:
  2364. if (a->pos == 2) {
  2365. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2366. }
  2367. return NULL;
  2368. }
  2369. if (a->argc != 3) {
  2370. return CLI_SHOWUSAGE;
  2371. }
  2372. if (generic_lock_unlock_helper(1, a->argv[2])) {
  2373. ast_cli(a->fd, "Conference %s is not found\n", a->argv[2]);
  2374. } else {
  2375. ast_cli(a->fd, "Conference %s is locked.\n", a->argv[2]);
  2376. }
  2377. return CLI_SUCCESS;
  2378. }
  2379. static char *handle_cli_confbridge_unlock(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2380. {
  2381. switch (cmd) {
  2382. case CLI_INIT:
  2383. e->command = "confbridge unlock";
  2384. e->usage =
  2385. "Usage: confbridge unlock <conference>\n"
  2386. " Unlock a previously locked conference.\n";
  2387. return NULL;
  2388. case CLI_GENERATE:
  2389. if (a->pos == 2) {
  2390. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2391. }
  2392. return NULL;
  2393. }
  2394. if (a->argc != 3) {
  2395. return CLI_SHOWUSAGE;
  2396. }
  2397. if (generic_lock_unlock_helper(0, a->argv[2])) {
  2398. ast_cli(a->fd, "Conference %s is not found\n", a->argv[2]);
  2399. } else {
  2400. ast_cli(a->fd, "Conference %s is unlocked.\n", a->argv[2]);
  2401. }
  2402. return CLI_SUCCESS;
  2403. }
  2404. static char *handle_cli_confbridge_start_record(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2405. {
  2406. const char *rec_file = NULL;
  2407. struct confbridge_conference *conference;
  2408. switch (cmd) {
  2409. case CLI_INIT:
  2410. e->command = "confbridge record start";
  2411. e->usage =
  2412. "Usage: confbridge record start <conference> <file>\n"
  2413. " <file> is optional, Otherwise the bridge profile\n"
  2414. " record file will be used. If the bridge profile\n"
  2415. " has no record file specified, a file will automatically\n"
  2416. " be generated in the monitor directory\n";
  2417. return NULL;
  2418. case CLI_GENERATE:
  2419. if (a->pos == 3) {
  2420. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2421. }
  2422. return NULL;
  2423. }
  2424. if (a->argc < 4) {
  2425. return CLI_SHOWUSAGE;
  2426. }
  2427. if (a->argc == 5) {
  2428. rec_file = a->argv[4];
  2429. }
  2430. conference = ao2_find(conference_bridges, a->argv[3], OBJ_KEY);
  2431. if (!conference) {
  2432. ast_cli(a->fd, "Conference not found.\n");
  2433. return CLI_FAILURE;
  2434. }
  2435. ao2_lock(conference);
  2436. if (conf_is_recording(conference)) {
  2437. ast_cli(a->fd, "Conference is already being recorded.\n");
  2438. ao2_unlock(conference);
  2439. ao2_ref(conference, -1);
  2440. return CLI_SUCCESS;
  2441. }
  2442. if (!ast_strlen_zero(rec_file)) {
  2443. ast_copy_string(conference->b_profile.rec_file, rec_file, sizeof(conference->b_profile.rec_file));
  2444. }
  2445. if (conf_start_record(conference)) {
  2446. ast_cli(a->fd, "Could not start recording due to internal error.\n");
  2447. ao2_unlock(conference);
  2448. ao2_ref(conference, -1);
  2449. return CLI_FAILURE;
  2450. }
  2451. ao2_unlock(conference);
  2452. ast_cli(a->fd, "Recording started\n");
  2453. ao2_ref(conference, -1);
  2454. return CLI_SUCCESS;
  2455. }
  2456. static char *handle_cli_confbridge_stop_record(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2457. {
  2458. struct confbridge_conference *conference;
  2459. int ret;
  2460. switch (cmd) {
  2461. case CLI_INIT:
  2462. e->command = "confbridge record stop";
  2463. e->usage =
  2464. "Usage: confbridge record stop <conference>\n"
  2465. " Stop a previously started recording.\n";
  2466. return NULL;
  2467. case CLI_GENERATE:
  2468. if (a->pos == 3) {
  2469. return complete_confbridge_name(a->line, a->word, a->pos, a->n);
  2470. }
  2471. return NULL;
  2472. }
  2473. if (a->argc != 4) {
  2474. return CLI_SHOWUSAGE;
  2475. }
  2476. conference = ao2_find(conference_bridges, a->argv[3], OBJ_KEY);
  2477. if (!conference) {
  2478. ast_cli(a->fd, "Conference not found.\n");
  2479. return CLI_SUCCESS;
  2480. }
  2481. ao2_lock(conference);
  2482. ret = conf_stop_record(conference);
  2483. ao2_unlock(conference);
  2484. ast_cli(a->fd, "Recording %sstopped.\n", ret ? "could not be " : "");
  2485. ao2_ref(conference, -1);
  2486. return CLI_SUCCESS;
  2487. }
  2488. static struct ast_cli_entry cli_confbridge[] = {
  2489. AST_CLI_DEFINE(handle_cli_confbridge_list, "List conference bridges and participants."),
  2490. AST_CLI_DEFINE(handle_cli_confbridge_kick, "Kick participants out of conference bridges."),
  2491. AST_CLI_DEFINE(handle_cli_confbridge_mute, "Mute participants."),
  2492. AST_CLI_DEFINE(handle_cli_confbridge_unmute, "Unmute participants."),
  2493. AST_CLI_DEFINE(handle_cli_confbridge_lock, "Lock a conference."),
  2494. AST_CLI_DEFINE(handle_cli_confbridge_unlock, "Unlock a conference."),
  2495. AST_CLI_DEFINE(handle_cli_confbridge_start_record, "Start recording a conference"),
  2496. AST_CLI_DEFINE(handle_cli_confbridge_stop_record, "Stop recording a conference."),
  2497. };
  2498. static struct ast_custom_function confbridge_function = {
  2499. .name = "CONFBRIDGE",
  2500. .write = func_confbridge_helper,
  2501. };
  2502. static int func_confbridge_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len);
  2503. static struct ast_custom_function confbridge_info_function = {
  2504. .name = "CONFBRIDGE_INFO",
  2505. .read = func_confbridge_info,
  2506. };
  2507. static void action_confbridgelist_item(struct mansession *s, const char *id_text, struct confbridge_conference *conference, struct confbridge_user *user, int waiting)
  2508. {
  2509. astman_append(s,
  2510. "Event: ConfbridgeList\r\n"
  2511. "%s"
  2512. "Conference: %s\r\n"
  2513. "CallerIDNum: %s\r\n"
  2514. "CallerIDName: %s\r\n"
  2515. "Channel: %s\r\n"
  2516. "Admin: %s\r\n"
  2517. "MarkedUser: %s\r\n"
  2518. "WaitMarked: %s\r\n"
  2519. "EndMarked: %s\r\n"
  2520. "Waiting: %s\r\n"
  2521. "Muted: %s\r\n"
  2522. "AnsweredTime: %d\r\n"
  2523. "\r\n",
  2524. id_text,
  2525. conference->name,
  2526. S_COR(ast_channel_caller(user->chan)->id.number.valid, ast_channel_caller(user->chan)->id.number.str, "<unknown>"),
  2527. S_COR(ast_channel_caller(user->chan)->id.name.valid, ast_channel_caller(user->chan)->id.name.str, "<no name>"),
  2528. ast_channel_name(user->chan),
  2529. ast_test_flag(&user->u_profile, USER_OPT_ADMIN) ? "Yes" : "No",
  2530. ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER) ? "Yes" : "No",
  2531. ast_test_flag(&user->u_profile, USER_OPT_WAITMARKED) ? "Yes" : "No",
  2532. ast_test_flag(&user->u_profile, USER_OPT_ENDMARKED) ? "Yes" : "No",
  2533. waiting ? "Yes" : "No",
  2534. user->muted ? "Yes" : "No",
  2535. ast_channel_get_up_time(user->chan));
  2536. }
  2537. static int action_confbridgelist(struct mansession *s, const struct message *m)
  2538. {
  2539. const char *actionid = astman_get_header(m, "ActionID");
  2540. const char *conference_name = astman_get_header(m, "Conference");
  2541. struct confbridge_user *user;
  2542. struct confbridge_conference *conference;
  2543. char id_text[80];
  2544. int total = 0;
  2545. id_text[0] = '\0';
  2546. if (!ast_strlen_zero(actionid)) {
  2547. snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", actionid);
  2548. }
  2549. if (ast_strlen_zero(conference_name)) {
  2550. astman_send_error(s, m, "No Conference name provided.");
  2551. return 0;
  2552. }
  2553. if (!ao2_container_count(conference_bridges)) {
  2554. astman_send_error(s, m, "No active conferences.");
  2555. return 0;
  2556. }
  2557. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2558. if (!conference) {
  2559. astman_send_error(s, m, "No Conference by that name found.");
  2560. return 0;
  2561. }
  2562. astman_send_listack(s, m, "Confbridge user list will follow", "start");
  2563. ao2_lock(conference);
  2564. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2565. total++;
  2566. action_confbridgelist_item(s, id_text, conference, user, 0);
  2567. }
  2568. AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
  2569. total++;
  2570. action_confbridgelist_item(s, id_text, conference, user, 1);
  2571. }
  2572. ao2_unlock(conference);
  2573. ao2_ref(conference, -1);
  2574. astman_send_list_complete_start(s, m, "ConfbridgeListComplete", total);
  2575. astman_send_list_complete_end(s);
  2576. return 0;
  2577. }
  2578. static int action_confbridgelistrooms(struct mansession *s, const struct message *m)
  2579. {
  2580. const char *actionid = astman_get_header(m, "ActionID");
  2581. struct confbridge_conference *conference;
  2582. struct ao2_iterator iter;
  2583. char id_text[512] = "";
  2584. int totalitems = 0;
  2585. if (!ast_strlen_zero(actionid)) {
  2586. snprintf(id_text, sizeof(id_text), "ActionID: %s\r\n", actionid);
  2587. }
  2588. if (!ao2_container_count(conference_bridges)) {
  2589. astman_send_error(s, m, "No active conferences.");
  2590. return 0;
  2591. }
  2592. astman_send_listack(s, m, "Confbridge conferences will follow", "start");
  2593. /* Traverse the conference list */
  2594. iter = ao2_iterator_init(conference_bridges, 0);
  2595. while ((conference = ao2_iterator_next(&iter))) {
  2596. totalitems++;
  2597. ao2_lock(conference);
  2598. astman_append(s,
  2599. "Event: ConfbridgeListRooms\r\n"
  2600. "%s"
  2601. "Conference: %s\r\n"
  2602. "Parties: %u\r\n"
  2603. "Marked: %u\r\n"
  2604. "Locked: %s\r\n"
  2605. "\r\n",
  2606. id_text,
  2607. conference->name,
  2608. conference->activeusers + conference->waitingusers,
  2609. conference->markedusers,
  2610. conference->locked ? "Yes" : "No");
  2611. ao2_unlock(conference);
  2612. ao2_ref(conference, -1);
  2613. }
  2614. ao2_iterator_destroy(&iter);
  2615. /* Send final confirmation */
  2616. astman_send_list_complete_start(s, m, "ConfbridgeListRoomsComplete", totalitems);
  2617. astman_send_list_complete_end(s);
  2618. return 0;
  2619. }
  2620. static int action_mute_unmute_helper(struct mansession *s, const struct message *m, int mute)
  2621. {
  2622. const char *conference_name = astman_get_header(m, "Conference");
  2623. const char *channel_name = astman_get_header(m, "Channel");
  2624. int res = 0;
  2625. if (ast_strlen_zero(conference_name)) {
  2626. astman_send_error(s, m, "No Conference name provided.");
  2627. return 0;
  2628. }
  2629. if (ast_strlen_zero(channel_name)) {
  2630. astman_send_error(s, m, "No channel name provided.");
  2631. return 0;
  2632. }
  2633. if (!ao2_container_count(conference_bridges)) {
  2634. astman_send_error(s, m, "No active conferences.");
  2635. return 0;
  2636. }
  2637. res = generic_mute_unmute_helper(mute, conference_name, channel_name);
  2638. if (res == -1) {
  2639. astman_send_error(s, m, "No Conference by that name found.");
  2640. return 0;
  2641. } else if (res == -2) {
  2642. astman_send_error(s, m, "No Channel by that name found in Conference.");
  2643. return 0;
  2644. }
  2645. astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
  2646. return 0;
  2647. }
  2648. static int action_confbridgeunmute(struct mansession *s, const struct message *m)
  2649. {
  2650. return action_mute_unmute_helper(s, m, 0);
  2651. }
  2652. static int action_confbridgemute(struct mansession *s, const struct message *m)
  2653. {
  2654. return action_mute_unmute_helper(s, m, 1);
  2655. }
  2656. static int action_lock_unlock_helper(struct mansession *s, const struct message *m, int lock)
  2657. {
  2658. const char *conference_name = astman_get_header(m, "Conference");
  2659. int res = 0;
  2660. if (ast_strlen_zero(conference_name)) {
  2661. astman_send_error(s, m, "No Conference name provided.");
  2662. return 0;
  2663. }
  2664. if (!ao2_container_count(conference_bridges)) {
  2665. astman_send_error(s, m, "No active conferences.");
  2666. return 0;
  2667. }
  2668. if ((res = generic_lock_unlock_helper(lock, conference_name))) {
  2669. astman_send_error(s, m, "No Conference by that name found.");
  2670. return 0;
  2671. }
  2672. astman_send_ack(s, m, lock ? "Conference locked" : "Conference unlocked");
  2673. return 0;
  2674. }
  2675. static int action_confbridgeunlock(struct mansession *s, const struct message *m)
  2676. {
  2677. return action_lock_unlock_helper(s, m, 0);
  2678. }
  2679. static int action_confbridgelock(struct mansession *s, const struct message *m)
  2680. {
  2681. return action_lock_unlock_helper(s, m, 1);
  2682. }
  2683. static int action_confbridgekick(struct mansession *s, const struct message *m)
  2684. {
  2685. const char *conference_name = astman_get_header(m, "Conference");
  2686. const char *channel = astman_get_header(m, "Channel");
  2687. struct confbridge_conference *conference;
  2688. int found;
  2689. if (ast_strlen_zero(conference_name)) {
  2690. astman_send_error(s, m, "No Conference name provided.");
  2691. return 0;
  2692. }
  2693. if (!ao2_container_count(conference_bridges)) {
  2694. astman_send_error(s, m, "No active conferences.");
  2695. return 0;
  2696. }
  2697. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2698. if (!conference) {
  2699. astman_send_error(s, m, "No Conference by that name found.");
  2700. return 0;
  2701. }
  2702. found = !kick_conference_participant(conference, channel);
  2703. ao2_ref(conference, -1);
  2704. if (found) {
  2705. astman_send_ack(s, m, !strcmp("all", channel) ? "All participants kicked" : "User kicked");
  2706. } else {
  2707. astman_send_error(s, m, "No Channel by that name found in Conference.");
  2708. }
  2709. return 0;
  2710. }
  2711. static int action_confbridgestartrecord(struct mansession *s, const struct message *m)
  2712. {
  2713. const char *conference_name = astman_get_header(m, "Conference");
  2714. const char *recordfile = astman_get_header(m, "RecordFile");
  2715. struct confbridge_conference *conference;
  2716. if (ast_strlen_zero(conference_name)) {
  2717. astman_send_error(s, m, "No Conference name provided.");
  2718. return 0;
  2719. }
  2720. if (!ao2_container_count(conference_bridges)) {
  2721. astman_send_error(s, m, "No active conferences.");
  2722. return 0;
  2723. }
  2724. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2725. if (!conference) {
  2726. astman_send_error(s, m, "No Conference by that name found.");
  2727. return 0;
  2728. }
  2729. ao2_lock(conference);
  2730. if (conf_is_recording(conference)) {
  2731. astman_send_error(s, m, "Conference is already being recorded.");
  2732. ao2_unlock(conference);
  2733. ao2_ref(conference, -1);
  2734. return 0;
  2735. }
  2736. if (!ast_strlen_zero(recordfile)) {
  2737. ast_copy_string(conference->b_profile.rec_file, recordfile, sizeof(conference->b_profile.rec_file));
  2738. }
  2739. if (conf_start_record(conference)) {
  2740. astman_send_error(s, m, "Internal error starting conference recording.");
  2741. ao2_unlock(conference);
  2742. ao2_ref(conference, -1);
  2743. return 0;
  2744. }
  2745. ao2_unlock(conference);
  2746. ao2_ref(conference, -1);
  2747. astman_send_ack(s, m, "Conference Recording Started.");
  2748. return 0;
  2749. }
  2750. static int action_confbridgestoprecord(struct mansession *s, const struct message *m)
  2751. {
  2752. const char *conference_name = astman_get_header(m, "Conference");
  2753. struct confbridge_conference *conference;
  2754. if (ast_strlen_zero(conference_name)) {
  2755. astman_send_error(s, m, "No Conference name provided.");
  2756. return 0;
  2757. }
  2758. if (!ao2_container_count(conference_bridges)) {
  2759. astman_send_error(s, m, "No active conferences.");
  2760. return 0;
  2761. }
  2762. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2763. if (!conference) {
  2764. astman_send_error(s, m, "No Conference by that name found.");
  2765. return 0;
  2766. }
  2767. ao2_lock(conference);
  2768. if (conf_stop_record(conference)) {
  2769. ao2_unlock(conference);
  2770. astman_send_error(s, m, "Internal error while stopping recording.");
  2771. ao2_ref(conference, -1);
  2772. return 0;
  2773. }
  2774. ao2_unlock(conference);
  2775. ao2_ref(conference, -1);
  2776. astman_send_ack(s, m, "Conference Recording Stopped.");
  2777. return 0;
  2778. }
  2779. static int action_confbridgesetsinglevideosrc(struct mansession *s, const struct message *m)
  2780. {
  2781. const char *conference_name = astman_get_header(m, "Conference");
  2782. const char *channel = astman_get_header(m, "Channel");
  2783. struct confbridge_user *user;
  2784. struct confbridge_conference *conference;
  2785. if (ast_strlen_zero(conference_name)) {
  2786. astman_send_error(s, m, "No Conference name provided.");
  2787. return 0;
  2788. }
  2789. if (ast_strlen_zero(channel)) {
  2790. astman_send_error(s, m, "No channel name provided.");
  2791. return 0;
  2792. }
  2793. if (!ao2_container_count(conference_bridges)) {
  2794. astman_send_error(s, m, "No active conferences.");
  2795. return 0;
  2796. }
  2797. conference = ao2_find(conference_bridges, conference_name, OBJ_KEY);
  2798. if (!conference) {
  2799. astman_send_error(s, m, "No Conference by that name found.");
  2800. return 0;
  2801. }
  2802. /* find channel and set as video src. */
  2803. ao2_lock(conference);
  2804. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2805. if (!strncmp(channel, ast_channel_name(user->chan), strlen(channel))) {
  2806. ast_bridge_set_single_src_video_mode(conference->bridge, user->chan);
  2807. break;
  2808. }
  2809. }
  2810. ao2_unlock(conference);
  2811. ao2_ref(conference, -1);
  2812. /* do not access user after conference unlock. We are just
  2813. * using this check to see if it was found or not */
  2814. if (!user) {
  2815. astman_send_error(s, m, "No channel by that name found in conference.");
  2816. return 0;
  2817. }
  2818. astman_send_ack(s, m, "Conference single video source set.");
  2819. return 0;
  2820. }
  2821. static int func_confbridge_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
  2822. {
  2823. char *parse;
  2824. struct confbridge_conference *conference;
  2825. struct confbridge_user *user;
  2826. int count = 0;
  2827. AST_DECLARE_APP_ARGS(args,
  2828. AST_APP_ARG(type);
  2829. AST_APP_ARG(confno);
  2830. );
  2831. /* parse all the required arguments and make sure they exist. */
  2832. if (ast_strlen_zero(data)) {
  2833. return -1;
  2834. }
  2835. parse = ast_strdupa(data);
  2836. AST_STANDARD_APP_ARGS(args, parse);
  2837. if (ast_strlen_zero(args.confno) || ast_strlen_zero(args.type)) {
  2838. return -1;
  2839. }
  2840. conference = ao2_find(conference_bridges, args.confno, OBJ_KEY);
  2841. if (!conference) {
  2842. snprintf(buf, len, "0");
  2843. return 0;
  2844. }
  2845. /* get the correct count for the type requested */
  2846. ao2_lock(conference);
  2847. if (!strncasecmp(args.type, "parties", 7)) {
  2848. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2849. count++;
  2850. }
  2851. AST_LIST_TRAVERSE(&conference->waiting_list, user, list) {
  2852. count++;
  2853. }
  2854. } else if (!strncasecmp(args.type, "admins", 6)) {
  2855. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2856. if (ast_test_flag(&user->u_profile, USER_OPT_ADMIN)) {
  2857. count++;
  2858. }
  2859. }
  2860. } else if (!strncasecmp(args.type, "marked", 6)) {
  2861. AST_LIST_TRAVERSE(&conference->active_list, user, list) {
  2862. if (ast_test_flag(&user->u_profile, USER_OPT_MARKEDUSER)) {
  2863. count++;
  2864. }
  2865. }
  2866. } else if (!strncasecmp(args.type, "locked", 6)) {
  2867. count = conference->locked;
  2868. } else {
  2869. ast_log(LOG_ERROR, "Invalid keyword '%s' passed to CONFBRIDGE_INFO. Should be one of: "
  2870. "parties, admins, marked, or locked.\n", args.type);
  2871. }
  2872. snprintf(buf, len, "%d", count);
  2873. ao2_unlock(conference);
  2874. ao2_ref(conference, -1);
  2875. return 0;
  2876. }
  2877. void conf_add_user_active(struct confbridge_conference *conference, struct confbridge_user *user)
  2878. {
  2879. AST_LIST_INSERT_TAIL(&conference->active_list, user, list);
  2880. conference->activeusers++;
  2881. }
  2882. void conf_add_user_marked(struct confbridge_conference *conference, struct confbridge_user *user)
  2883. {
  2884. AST_LIST_INSERT_TAIL(&conference->active_list, user, list);
  2885. conference->activeusers++;
  2886. conference->markedusers++;
  2887. }
  2888. void conf_add_user_waiting(struct confbridge_conference *conference, struct confbridge_user *user)
  2889. {
  2890. AST_LIST_INSERT_TAIL(&conference->waiting_list, user, list);
  2891. conference->waitingusers++;
  2892. }
  2893. void conf_remove_user_active(struct confbridge_conference *conference, struct confbridge_user *user)
  2894. {
  2895. AST_LIST_REMOVE(&conference->active_list, user, list);
  2896. conference->activeusers--;
  2897. }
  2898. void conf_remove_user_marked(struct confbridge_conference *conference, struct confbridge_user *user)
  2899. {
  2900. AST_LIST_REMOVE(&conference->active_list, user, list);
  2901. conference->activeusers--;
  2902. conference->markedusers--;
  2903. }
  2904. void conf_mute_only_active(struct confbridge_conference *conference)
  2905. {
  2906. struct confbridge_user *only_user = AST_LIST_FIRST(&conference->active_list);
  2907. /* Turn on MOH if the single participant is set up for it */
  2908. if (ast_test_flag(&only_user->u_profile, USER_OPT_MUSICONHOLD)) {
  2909. conf_moh_start(only_user);
  2910. }
  2911. conf_update_user_mute(only_user);
  2912. }
  2913. void conf_remove_user_waiting(struct confbridge_conference *conference, struct confbridge_user *user)
  2914. {
  2915. AST_LIST_REMOVE(&conference->waiting_list, user, list);
  2916. conference->waitingusers--;
  2917. }
  2918. /*!
  2919. * \internal
  2920. * \brief Unregister a ConfBridge channel technology.
  2921. * \since 12.0.0
  2922. *
  2923. * \param tech What to unregister.
  2924. *
  2925. * \return Nothing
  2926. */
  2927. static void unregister_channel_tech(struct ast_channel_tech *tech)
  2928. {
  2929. ast_channel_unregister(tech);
  2930. ao2_cleanup(tech->capabilities);
  2931. }
  2932. /*!
  2933. * \internal
  2934. * \brief Register a ConfBridge channel technology.
  2935. * \since 12.0.0
  2936. *
  2937. * \param tech What to register.
  2938. *
  2939. * \retval 0 on success.
  2940. * \retval -1 on error.
  2941. */
  2942. static int register_channel_tech(struct ast_channel_tech *tech)
  2943. {
  2944. tech->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  2945. if (!tech->capabilities) {
  2946. return -1;
  2947. }
  2948. ast_format_cap_append_by_type(tech->capabilities, AST_MEDIA_TYPE_UNKNOWN);
  2949. if (ast_channel_register(tech)) {
  2950. ast_log(LOG_ERROR, "Unable to register channel technology %s(%s).\n",
  2951. tech->type, tech->description);
  2952. return -1;
  2953. }
  2954. return 0;
  2955. }
  2956. /*! \brief Called when module is being unloaded */
  2957. static int unload_module(void)
  2958. {
  2959. ast_unregister_application(app);
  2960. ast_custom_function_unregister(&confbridge_function);
  2961. ast_custom_function_unregister(&confbridge_info_function);
  2962. ast_cli_unregister_multiple(cli_confbridge, ARRAY_LEN(cli_confbridge));
  2963. ast_manager_unregister("ConfbridgeList");
  2964. ast_manager_unregister("ConfbridgeListRooms");
  2965. ast_manager_unregister("ConfbridgeMute");
  2966. ast_manager_unregister("ConfbridgeUnmute");
  2967. ast_manager_unregister("ConfbridgeKick");
  2968. ast_manager_unregister("ConfbridgeUnlock");
  2969. ast_manager_unregister("ConfbridgeLock");
  2970. ast_manager_unregister("ConfbridgeStartRecord");
  2971. ast_manager_unregister("ConfbridgeStopRecord");
  2972. ast_manager_unregister("ConfbridgeSetSingleVideoSrc");
  2973. /* Unsubscribe from stasis confbridge message type and clean it up. */
  2974. manager_confbridge_shutdown();
  2975. /* Get rid of the conference bridges container. Since we only allow dynamic ones none will be active. */
  2976. ao2_cleanup(conference_bridges);
  2977. conference_bridges = NULL;
  2978. conf_destroy_config();
  2979. unregister_channel_tech(conf_announce_get_tech());
  2980. unregister_channel_tech(conf_record_get_tech());
  2981. return 0;
  2982. }
  2983. /*!
  2984. * \brief Load the module
  2985. *
  2986. * Module loading including tests for configuration or dependencies.
  2987. * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
  2988. * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
  2989. * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
  2990. * configuration file or other non-critical problem return
  2991. * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
  2992. */
  2993. static int load_module(void)
  2994. {
  2995. int res = 0;
  2996. if (conf_load_config()) {
  2997. ast_log(LOG_ERROR, "Unable to load config. Not loading module.\n");
  2998. return AST_MODULE_LOAD_DECLINE;
  2999. }
  3000. if (register_channel_tech(conf_record_get_tech())
  3001. || register_channel_tech(conf_announce_get_tech())) {
  3002. unload_module();
  3003. return AST_MODULE_LOAD_FAILURE;
  3004. }
  3005. /* Create a container to hold the conference bridges */
  3006. conference_bridges = ao2_container_alloc(CONFERENCE_BRIDGE_BUCKETS,
  3007. conference_bridge_hash_cb, conference_bridge_cmp_cb);
  3008. if (!conference_bridges) {
  3009. unload_module();
  3010. return AST_MODULE_LOAD_FAILURE;
  3011. }
  3012. /* Setup manager stasis subscriptions */
  3013. res |= manager_confbridge_init();
  3014. res |= ast_register_application_xml(app, confbridge_exec);
  3015. res |= ast_custom_function_register_escalating(&confbridge_function, AST_CFE_WRITE);
  3016. res |= ast_custom_function_register(&confbridge_info_function);
  3017. res |= ast_cli_register_multiple(cli_confbridge, ARRAY_LEN(cli_confbridge));
  3018. res |= ast_manager_register_xml("ConfbridgeList", EVENT_FLAG_REPORTING, action_confbridgelist);
  3019. res |= ast_manager_register_xml("ConfbridgeListRooms", EVENT_FLAG_REPORTING, action_confbridgelistrooms);
  3020. res |= ast_manager_register_xml("ConfbridgeMute", EVENT_FLAG_CALL, action_confbridgemute);
  3021. res |= ast_manager_register_xml("ConfbridgeUnmute", EVENT_FLAG_CALL, action_confbridgeunmute);
  3022. res |= ast_manager_register_xml("ConfbridgeKick", EVENT_FLAG_CALL, action_confbridgekick);
  3023. res |= ast_manager_register_xml("ConfbridgeUnlock", EVENT_FLAG_CALL, action_confbridgeunlock);
  3024. res |= ast_manager_register_xml("ConfbridgeLock", EVENT_FLAG_CALL, action_confbridgelock);
  3025. res |= ast_manager_register_xml("ConfbridgeStartRecord", EVENT_FLAG_SYSTEM, action_confbridgestartrecord);
  3026. res |= ast_manager_register_xml("ConfbridgeStopRecord", EVENT_FLAG_SYSTEM, action_confbridgestoprecord);
  3027. res |= ast_manager_register_xml("ConfbridgeSetSingleVideoSrc", EVENT_FLAG_CALL, action_confbridgesetsinglevideosrc);
  3028. if (res) {
  3029. unload_module();
  3030. return AST_MODULE_LOAD_FAILURE;
  3031. }
  3032. return AST_MODULE_LOAD_SUCCESS;
  3033. }
  3034. static int reload(void)
  3035. {
  3036. return conf_reload_config();
  3037. }
  3038. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Conference Bridge Application",
  3039. .support_level = AST_MODULE_SUPPORT_CORE,
  3040. .load = load_module,
  3041. .unload = unload_module,
  3042. .reload = reload,
  3043. .load_pri = AST_MODPRI_DEVSTATE_PROVIDER,
  3044. );