12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804 |
- /*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 1999 - 2007, Digium, Inc.
- *
- * Mark Spencer <markster@digium.com>
- *
- * SLA Implementation by:
- * Russell Bryant <russell@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
- /*! \file
- *
- * \brief Meet me conference bridge and Shared Line Appearances
- *
- * \author Mark Spencer <markster@digium.com>
- * \author (SLA) Russell Bryant <russell@digium.com>
- *
- * \ingroup applications
- */
- /*** MODULEINFO
- <depend>dahdi</depend>
- ***/
- #include "asterisk.h"
- ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
- #include <sys/ioctl.h>
- #include <dahdi/user.h>
- #include "asterisk/lock.h"
- #include "asterisk/file.h"
- #include "asterisk/channel.h"
- #include "asterisk/pbx.h"
- #include "asterisk/module.h"
- #include "asterisk/config.h"
- #include "asterisk/app.h"
- #include "asterisk/dsp.h"
- #include "asterisk/musiconhold.h"
- #include "asterisk/manager.h"
- #include "asterisk/cli.h"
- #include "asterisk/say.h"
- #include "asterisk/utils.h"
- #include "asterisk/translate.h"
- #include "asterisk/ulaw.h"
- #include "asterisk/astobj.h"
- #include "asterisk/astobj2.h"
- #include "asterisk/devicestate.h"
- #include "asterisk/dial.h"
- #include "asterisk/causes.h"
- #include "asterisk/paths.h"
- #include "enter.h"
- #include "leave.h"
- #define CONFIG_FILE_NAME "meetme.conf"
- #define SLA_CONFIG_FILE "sla.conf"
- /*! each buffer is 20ms, so this is 640ms total */
- #define DEFAULT_AUDIO_BUFFERS 32
- /*! String format for scheduled conferences */
- #define DATE_FORMAT "%Y-%m-%d %H:%M:%S"
- enum {
- ADMINFLAG_MUTED = (1 << 1), /*!< User is muted */
- ADMINFLAG_SELFMUTED = (1 << 2), /*!< User muted self */
- ADMINFLAG_KICKME = (1 << 3), /*!< User has been kicked */
- /*! User has requested to speak */
- ADMINFLAG_T_REQUEST = (1 << 4),
- };
- #define MEETME_DELAYDETECTTALK 300
- #define MEETME_DELAYDETECTENDTALK 1000
- #define AST_FRAME_BITS 32
- enum volume_action {
- VOL_UP,
- VOL_DOWN
- };
- enum entrance_sound {
- ENTER,
- LEAVE
- };
- enum recording_state {
- MEETME_RECORD_OFF,
- MEETME_RECORD_STARTED,
- MEETME_RECORD_ACTIVE,
- MEETME_RECORD_TERMINATE
- };
- #define CONF_SIZE 320
- enum {
- /*! user has admin access on the conference */
- CONFFLAG_ADMIN = (1 << 0),
- /*! If set the user can only receive audio from the conference */
- CONFFLAG_MONITOR = (1 << 1),
- /*! If set asterisk will exit conference when key defined in p() option is pressed */
- CONFFLAG_KEYEXIT = (1 << 2),
- /*! If set asterisk will provide a menu to the user when '*' is pressed */
- CONFFLAG_STARMENU = (1 << 3),
- /*! If set the use can only send audio to the conference */
- CONFFLAG_TALKER = (1 << 4),
- /*! If set there will be no enter or leave sounds */
- CONFFLAG_QUIET = (1 << 5),
- /*! If set, when user joins the conference, they will be told the number
- * of users that are already in */
- CONFFLAG_ANNOUNCEUSERCOUNT = (1 << 6),
- /*! Set to run AGI Script in Background */
- CONFFLAG_AGI = (1 << 7),
- /*! Set to have music on hold when user is alone in conference */
- CONFFLAG_MOH = (1 << 8),
- /*! If set the MeetMe will return if all marked with this flag left */
- CONFFLAG_MARKEDEXIT = (1 << 9),
- /*! If set, the MeetMe will wait until a marked user enters */
- CONFFLAG_WAITMARKED = (1 << 10),
- /*! If set, the MeetMe will exit to the specified context */
- CONFFLAG_EXIT_CONTEXT = (1 << 11),
- /*! If set, the user will be marked */
- CONFFLAG_MARKEDUSER = (1 << 12),
- /*! If set, user will be ask record name on entry of conference */
- CONFFLAG_INTROUSER = (1 << 13),
- /*! If set, the MeetMe will be recorded */
- CONFFLAG_RECORDCONF = (1<< 14),
- /*! If set, the user will be monitored if the user is talking or not */
- CONFFLAG_MONITORTALKER = (1 << 15),
- CONFFLAG_DYNAMIC = (1 << 16),
- CONFFLAG_DYNAMICPIN = (1 << 17),
- CONFFLAG_EMPTY = (1 << 18),
- CONFFLAG_EMPTYNOPIN = (1 << 19),
- CONFFLAG_ALWAYSPROMPT = (1 << 20),
- /*! If set, treat talking users as muted users */
- CONFFLAG_OPTIMIZETALKER = (1 << 21),
- /*! If set, won't speak the extra prompt when the first person
- * enters the conference */
- CONFFLAG_NOONLYPERSON = (1 << 22),
- /*! If set, user will be asked to record name on entry of conference
- * without review */
- CONFFLAG_INTROUSERNOREVIEW = (1 << 23),
- /*! If set, the user will be initially self-muted */
- CONFFLAG_STARTMUTED = (1 << 24),
- /*! Pass DTMF through the conference */
- CONFFLAG_PASS_DTMF = (1 << 25),
- CONFFLAG_SLA_STATION = (1 << 26),
- CONFFLAG_SLA_TRUNK = (1 << 27),
- /*! If set, the user should continue in the dialplan if kicked out */
- CONFFLAG_KICK_CONTINUE = (1 << 28),
- CONFFLAG_DURATION_STOP = (1 << 29),
- CONFFLAG_DURATION_LIMIT = (1 << 30),
- /*! Do not write any audio to this channel until the state is up. */
- CONFFLAG_NO_AUDIO_UNTIL_UP = (1 << 31),
- };
- enum {
- OPT_ARG_WAITMARKED = 0,
- OPT_ARG_EXITKEYS = 1,
- OPT_ARG_DURATION_STOP = 2,
- OPT_ARG_DURATION_LIMIT = 3,
- OPT_ARG_MOH_CLASS = 4,
- OPT_ARG_ARRAY_SIZE = 5,
- };
- AST_APP_OPTIONS(meetme_opts, BEGIN_OPTIONS
- AST_APP_OPTION('A', CONFFLAG_MARKEDUSER ),
- AST_APP_OPTION('a', CONFFLAG_ADMIN ),
- AST_APP_OPTION('b', CONFFLAG_AGI ),
- AST_APP_OPTION('c', CONFFLAG_ANNOUNCEUSERCOUNT ),
- AST_APP_OPTION('C', CONFFLAG_KICK_CONTINUE),
- AST_APP_OPTION('D', CONFFLAG_DYNAMICPIN ),
- AST_APP_OPTION('d', CONFFLAG_DYNAMIC ),
- AST_APP_OPTION('E', CONFFLAG_EMPTYNOPIN ),
- AST_APP_OPTION('e', CONFFLAG_EMPTY ),
- AST_APP_OPTION('F', CONFFLAG_PASS_DTMF ),
- AST_APP_OPTION('i', CONFFLAG_INTROUSER ),
- AST_APP_OPTION('I', CONFFLAG_INTROUSERNOREVIEW ),
- AST_APP_OPTION_ARG('M', CONFFLAG_MOH, OPT_ARG_MOH_CLASS ),
- AST_APP_OPTION('m', CONFFLAG_STARTMUTED ),
- AST_APP_OPTION('o', CONFFLAG_OPTIMIZETALKER ),
- AST_APP_OPTION('P', CONFFLAG_ALWAYSPROMPT ),
- AST_APP_OPTION_ARG('p', CONFFLAG_KEYEXIT, OPT_ARG_EXITKEYS ),
- AST_APP_OPTION('q', CONFFLAG_QUIET ),
- AST_APP_OPTION('r', CONFFLAG_RECORDCONF ),
- AST_APP_OPTION('s', CONFFLAG_STARMENU ),
- AST_APP_OPTION('T', CONFFLAG_MONITORTALKER ),
- AST_APP_OPTION('l', CONFFLAG_MONITOR ),
- AST_APP_OPTION('t', CONFFLAG_TALKER ),
- AST_APP_OPTION_ARG('w', CONFFLAG_WAITMARKED, OPT_ARG_WAITMARKED ),
- AST_APP_OPTION('X', CONFFLAG_EXIT_CONTEXT ),
- AST_APP_OPTION('x', CONFFLAG_MARKEDEXIT ),
- AST_APP_OPTION('1', CONFFLAG_NOONLYPERSON ),
- AST_APP_OPTION_ARG('S', CONFFLAG_DURATION_STOP, OPT_ARG_DURATION_STOP),
- AST_APP_OPTION_ARG('L', CONFFLAG_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
- END_OPTIONS );
- static const char *app = "MeetMe";
- static const char *app2 = "MeetMeCount";
- static const char *app3 = "MeetMeAdmin";
- static const char *app4 = "MeetMeChannelAdmin";
- static const char *slastation_app = "SLAStation";
- static const char *slatrunk_app = "SLATrunk";
- static const char *synopsis = "MeetMe conference bridge";
- static const char *synopsis2 = "MeetMe participant count";
- static const char *synopsis3 = "MeetMe conference Administration";
- static const char *synopsis4 = "MeetMe conference Administration (channel specific)";
- static const char *slastation_synopsis = "Shared Line Appearance Station";
- static const char *slatrunk_synopsis = "Shared Line Appearance Trunk";
- /* Lookup RealTime conferences based on confno and current time */
- static int rt_schedule;
- static int fuzzystart;
- static int earlyalert;
- static int endalert;
- /* Log participant count to the RealTime backend */
- static int rt_log_members;
- static const char *descrip =
- " MeetMe([confno][,[options][,pin]]): Enters the user into a specified MeetMe\n"
- "conference. If the conference number is omitted, the user will be prompted\n"
- "to enter one. User can exit the conference by hangup, or if the 'p' option\n"
- "is specified, by pressing '#'.\n"
- "Please note: The DAHDI kernel modules and at least one hardware driver (or dahdi_dummy)\n"
- " must be present for conferencing to operate properly. In addition, the chan_dahdi\n"
- " channel driver must be loaded for the 'i' and 'r' options to operate at all.\n\n"
- "The option string may contain zero or more of the following characters:\n"
- " 'a' -- set admin mode\n"
- " 'A' -- set marked mode\n"
- " 'b' -- run AGI script specified in ${MEETME_AGI_BACKGROUND}\n"
- " Default: conf-background.agi (Note: This does not work with\n"
- " non-DAHDI channels in the same conference)\n"
- " 'c' -- announce user(s) count on joining a conference\n"
- " 'C' -- continue in dialplan when kicked out of conference\n"
- " 'd' -- dynamically add conference\n"
- " 'D' -- dynamically add conference, prompting for a PIN\n"
- " 'e' -- select an empty conference\n"
- " 'E' -- select an empty pinless conference\n"
- " 'F' -- Pass DTMF through the conference.\n"
- " 'i' -- announce user join/leave with review\n"
- " 'I' -- announce user join/leave without review\n"
- " 'l' -- set listen only mode (Listen only, no talking)\n"
- " 'm' -- set initially muted\n"
- " 'M[(<class>)]'\n"
- " -- enable music on hold when the conference has a single caller.\n"
- " Optionally, specify a musiconhold class to use. If one is not\n"
- " provided, it will use the channel's currently set music class,\n"
- " or \"default\".\n"
- " 'o' -- set talker optimization - treats talkers who aren't speaking as\n"
- " being muted, meaning (a) No encode is done on transmission and\n"
- " (b) Received audio that is not registered as talking is omitted\n"
- " causing no buildup in background noise\n"
- " 'p[(<keys>)]'\n"
- " -- allow user to exit the conference by pressing '#' (default)\n"
- " or any of the defined keys. If keys contain '*' this will override\n"
- " option 's'. The key used is set to channel variable MEETME_EXIT_KEY.\n"
- " 'P' -- always prompt for the pin even if it is specified\n"
- " 'q' -- quiet mode (don't play enter/leave sounds)\n"
- " 'r' -- Record conference (records as ${MEETME_RECORDINGFILE}\n"
- " using format ${MEETME_RECORDINGFORMAT}). Default filename is\n"
- " meetme-conf-rec-${CONFNO}-${UNIQUEID} and the default format is\n"
- " wav.\n"
- " 's' -- Present menu (user or admin) when '*' is received ('send' to menu)\n"
- " 't' -- set talk only mode. (Talk only, no listening)\n"
- " 'T' -- set talker detection (sent to manager interface and meetme list)\n"
- " 'w[(<secs>)]'\n"
- " -- wait until the marked user enters the conference\n"
- " 'x' -- close the conference when last marked user exits\n"
- " 'X' -- allow user to exit the conference by entering a valid single\n"
- " digit extension ${MEETME_EXIT_CONTEXT} or the current context\n"
- " if that variable is not defined.\n"
- " '1' -- do not play message when first person enters\n"
- " 'S(x)' -- Kick the user 'x' seconds *after* he entered into the conference.\n"
- " 'L(x[:y][:z])' - Limit the conference to 'x' ms. Play a warning when 'y' ms are\n"
- " left. Repeat the warning every 'z' ms. The following special\n"
- " variables can be used with this option:\n"
- " * CONF_LIMIT_TIMEOUT_FILE File to play when time is up.\n"
- " * CONF_LIMIT_WARNING_FILE File to play as warning if 'y' is defined.\n"
- " The default is to say the time remaining.\n"
- "";
- static const char *descrip2 =
- " MeetMeCount(confno[,var]): Plays back the number of users in the specified\n"
- "MeetMe conference. If var is specified, playback will be skipped and the value\n"
- "will be returned in the variable. Upon app completion, MeetMeCount will hangup\n"
- "the channel, unless priority n+1 exists, in which case priority progress will\n"
- "continue.\n"
- "";
- static const char *descrip3 =
- " MeetMeAdmin(confno,command[,user]): Run admin command for conference\n"
- " 'e' -- Eject last user that joined\n"
- " 'k' -- Kick one user out of conference\n"
- " 'K' -- Kick all users out of conference\n"
- " 'l' -- Unlock conference\n"
- " 'L' -- Lock conference\n"
- " 'm' -- Unmute one user\n"
- " 'M' -- Mute one user\n"
- " 'n' -- Unmute all users in the conference\n"
- " 'N' -- Mute all non-admin users in the conference\n"
- " 'r' -- Reset one user's volume settings\n"
- " 'R' -- Reset all users volume settings\n"
- " 's' -- Lower entire conference speaking volume\n"
- " 'S' -- Raise entire conference speaking volume\n"
- " 't' -- Lower one user's talk volume\n"
- " 'T' -- Raise one user's talk volume\n"
- " 'u' -- Lower one user's listen volume\n"
- " 'U' -- Raise one user's listen volume\n"
- " 'v' -- Lower entire conference listening volume\n"
- " 'V' -- Raise entire conference listening volume\n"
- "";
- static const char *descrip4 =
- " MeetMeChannelAdmin(channel,command): Run admin command for a specific\n"
- "channel in any coference.\n"
- " 'k' -- Kick the specified user out of the conference he is in\n"
- " 'm' -- Unmute the specified user\n"
- " 'M' -- Mute the specified user\n"
- "";
- static const char *slastation_desc =
- " SLAStation(<station name>):\n"
- "This application should be executed by an SLA station. The argument depends\n"
- "on how the call was initiated. If the phone was just taken off hook, then\n"
- "the argument \"station\" should be just the station name. If the call was\n"
- "initiated by pressing a line key, then the station name should be preceded\n"
- "by an underscore and the trunk name associated with that line button.\n"
- "For example: \"station1_line1\"."
- " On exit, this application will set the variable SLASTATION_STATUS to\n"
- "one of the following values:\n"
- " FAILURE | CONGESTION | SUCCESS\n"
- "";
- static const char *slatrunk_desc =
- " SLATrunk(<trunk name>[,options]):\n"
- "This application should be executed by an SLA trunk on an inbound call.\n"
- "The channel calling this application should correspond to the SLA trunk\n"
- "with the name \"trunk\" that is being passed as an argument.\n"
- " On exit, this application will set the variable SLATRUNK_STATUS to\n"
- "one of the following values:\n"
- " FAILURE | SUCCESS | UNANSWERED | RINGTIMEOUT\n"
- " The available options are:\n"
- " M[(<class>)] - Play back the specified MOH class instead of ringing\n"
- "";
- #define MAX_CONFNUM 80
- #define MAX_PIN 80
- /* Enough space for "<conference #>,<pin>,<admin pin>" followed by a 0 byte. */
- #define MAX_SETTINGS (MAX_CONFNUM + MAX_PIN + MAX_PIN + 3)
- enum announcetypes {
- CONF_HASJOIN,
- CONF_HASLEFT
- };
- struct announce_listitem {
- AST_LIST_ENTRY(announce_listitem) entry;
- char namerecloc[PATH_MAX]; /*!< Name Recorded file Location */
- char language[MAX_LANGUAGE];
- struct ast_channel *confchan;
- int confusers;
- enum announcetypes announcetype;
- };
- /*! \brief The MeetMe Conference object */
- struct ast_conference {
- ast_mutex_t playlock; /*!< Conference specific lock (players) */
- ast_mutex_t listenlock; /*!< Conference specific lock (listeners) */
- char confno[MAX_CONFNUM]; /*!< Conference */
- struct ast_channel *chan; /*!< Announcements channel */
- struct ast_channel *lchan; /*!< Listen/Record channel */
- int fd; /*!< Announcements fd */
- int dahdiconf; /*!< DAHDI Conf # */
- int users; /*!< Number of active users */
- int markedusers; /*!< Number of marked users */
- int maxusers; /*!< Participant limit if scheduled */
- int endalert; /*!< When to play conf ending message */
- time_t start; /*!< Start time (s) */
- int refcount; /*!< reference count of usage */
- enum recording_state recording:2; /*!< recording status */
- unsigned int isdynamic:1; /*!< Created on the fly? */
- unsigned int locked:1; /*!< Is the conference locked? */
- pthread_t recordthread; /*!< thread for recording */
- ast_mutex_t recordthreadlock; /*!< control threads trying to start recordthread */
- pthread_attr_t attr; /*!< thread attribute */
- const char *recordingfilename; /*!< Filename to record the Conference into */
- const char *recordingformat; /*!< Format to record the Conference in */
- char pin[MAX_PIN]; /*!< If protected by a PIN */
- char pinadmin[MAX_PIN]; /*!< If protected by a admin PIN */
- char uniqueid[32];
- long endtime; /*!< When to end the conf if scheduled */
- struct ast_frame *transframe[32];
- struct ast_frame *origframe;
- struct ast_trans_pvt *transpath[32];
- AST_LIST_HEAD_NOLOCK(, ast_conf_user) userlist;
- AST_LIST_ENTRY(ast_conference) list;
- /* announce_thread related data */
- pthread_t announcethread;
- ast_mutex_t announcethreadlock;
- unsigned int announcethread_stop:1;
- ast_cond_t announcelist_addition;
- AST_LIST_HEAD_NOLOCK(, announce_listitem) announcelist;
- ast_mutex_t announcelistlock;
- };
- static AST_LIST_HEAD_STATIC(confs, ast_conference);
- static unsigned int conf_map[1024] = {0, };
- struct volume {
- int desired; /*!< Desired volume adjustment */
- int actual; /*!< Actual volume adjustment (for channels that can't adjust) */
- };
- /*! \brief The MeetMe User object */
- struct ast_conf_user {
- int user_no; /*!< User Number */
- int userflags; /*!< Flags as set in the conference */
- int adminflags; /*!< Flags set by the Admin */
- struct ast_channel *chan; /*!< Connected channel */
- int talking; /*!< Is user talking */
- int dahdichannel; /*!< Is a DAHDI channel */
- char usrvalue[50]; /*!< Custom User Value */
- char namerecloc[PATH_MAX]; /*!< Name Recorded file Location */
- time_t jointime; /*!< Time the user joined the conference */
- time_t kicktime; /*!< Time the user will be kicked from the conference */
- struct timeval start_time; /*!< Time the user entered into the conference */
- long timelimit; /*!< Time limit for the user to be in the conference L(x:y:z) */
- long play_warning; /*!< Play a warning when 'y' ms are left */
- long warning_freq; /*!< Repeat the warning every 'z' ms */
- const char *warning_sound; /*!< File to play as warning if 'y' is defined */
- const char *end_sound; /*!< File to play when time is up. */
- struct volume talk;
- struct volume listen;
- AST_LIST_ENTRY(ast_conf_user) list;
- };
- enum sla_which_trunk_refs {
- ALL_TRUNK_REFS,
- INACTIVE_TRUNK_REFS,
- };
- enum sla_trunk_state {
- SLA_TRUNK_STATE_IDLE,
- SLA_TRUNK_STATE_RINGING,
- SLA_TRUNK_STATE_UP,
- SLA_TRUNK_STATE_ONHOLD,
- SLA_TRUNK_STATE_ONHOLD_BYME,
- };
- enum sla_hold_access {
- /*! This means that any station can put it on hold, and any station
- * can retrieve the call from hold. */
- SLA_HOLD_OPEN,
- /*! This means that only the station that put the call on hold may
- * retrieve it from hold. */
- SLA_HOLD_PRIVATE,
- };
- struct sla_trunk_ref;
- struct sla_station {
- AST_RWLIST_ENTRY(sla_station) entry;
- AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(name);
- AST_STRING_FIELD(device);
- AST_STRING_FIELD(autocontext);
- );
- AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
- struct ast_dial *dial;
- /*! Ring timeout for this station, for any trunk. If a ring timeout
- * is set for a specific trunk on this station, that will take
- * priority over this value. */
- unsigned int ring_timeout;
- /*! Ring delay for this station, for any trunk. If a ring delay
- * is set for a specific trunk on this station, that will take
- * priority over this value. */
- unsigned int ring_delay;
- /*! This option uses the values in the sla_hold_access enum and sets the
- * access control type for hold on this station. */
- unsigned int hold_access:1;
- /*! Use count for inside sla_station_exec */
- unsigned int ref_count;
- };
- struct sla_station_ref {
- AST_LIST_ENTRY(sla_station_ref) entry;
- struct sla_station *station;
- };
- struct sla_trunk {
- AST_RWLIST_ENTRY(sla_trunk) entry;
- AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(name);
- AST_STRING_FIELD(device);
- AST_STRING_FIELD(autocontext);
- );
- AST_LIST_HEAD_NOLOCK(, sla_station_ref) stations;
- /*! Number of stations that use this trunk */
- unsigned int num_stations;
- /*! Number of stations currently on a call with this trunk */
- unsigned int active_stations;
- /*! Number of stations that have this trunk on hold. */
- unsigned int hold_stations;
- struct ast_channel *chan;
- unsigned int ring_timeout;
- /*! If set to 1, no station will be able to join an active call with
- * this trunk. */
- unsigned int barge_disabled:1;
- /*! This option uses the values in the sla_hold_access enum and sets the
- * access control type for hold on this trunk. */
- unsigned int hold_access:1;
- /*! Whether this trunk is currently on hold, meaning that once a station
- * connects to it, the trunk channel needs to have UNHOLD indicated to it. */
- unsigned int on_hold:1;
- /*! Use count for inside sla_trunk_exec */
- unsigned int ref_count;
- };
- struct sla_trunk_ref {
- AST_LIST_ENTRY(sla_trunk_ref) entry;
- struct sla_trunk *trunk;
- enum sla_trunk_state state;
- struct ast_channel *chan;
- /*! Ring timeout to use when this trunk is ringing on this specific
- * station. This takes higher priority than a ring timeout set at
- * the station level. */
- unsigned int ring_timeout;
- /*! Ring delay to use when this trunk is ringing on this specific
- * station. This takes higher priority than a ring delay set at
- * the station level. */
- unsigned int ring_delay;
- };
- static AST_RWLIST_HEAD_STATIC(sla_stations, sla_station);
- static AST_RWLIST_HEAD_STATIC(sla_trunks, sla_trunk);
- static const char sla_registrar[] = "SLA";
- /*! \brief Event types that can be queued up for the SLA thread */
- enum sla_event_type {
- /*! A station has put the call on hold */
- SLA_EVENT_HOLD,
- /*! The state of a dial has changed */
- SLA_EVENT_DIAL_STATE,
- /*! The state of a ringing trunk has changed */
- SLA_EVENT_RINGING_TRUNK,
- /*! A reload of configuration has been requested */
- SLA_EVENT_RELOAD,
- /*! Poke the SLA thread so it can check if it can perform a reload */
- SLA_EVENT_CHECK_RELOAD,
- };
- struct sla_event {
- enum sla_event_type type;
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref;
- AST_LIST_ENTRY(sla_event) entry;
- };
- /*! \brief A station that failed to be dialed
- * \note Only used by the SLA thread. */
- struct sla_failed_station {
- struct sla_station *station;
- struct timeval last_try;
- AST_LIST_ENTRY(sla_failed_station) entry;
- };
- /*! \brief A trunk that is ringing */
- struct sla_ringing_trunk {
- struct sla_trunk *trunk;
- /*! The time that this trunk started ringing */
- struct timeval ring_begin;
- AST_LIST_HEAD_NOLOCK(, sla_station_ref) timed_out_stations;
- AST_LIST_ENTRY(sla_ringing_trunk) entry;
- };
- enum sla_station_hangup {
- SLA_STATION_HANGUP_NORMAL,
- SLA_STATION_HANGUP_TIMEOUT,
- };
- /*! \brief A station that is ringing */
- struct sla_ringing_station {
- struct sla_station *station;
- /*! The time that this station started ringing */
- struct timeval ring_begin;
- AST_LIST_ENTRY(sla_ringing_station) entry;
- };
- /*!
- * \brief A structure for data used by the sla thread
- */
- static struct {
- /*! The SLA thread ID */
- pthread_t thread;
- ast_cond_t cond;
- ast_mutex_t lock;
- AST_LIST_HEAD_NOLOCK(, sla_ringing_trunk) ringing_trunks;
- AST_LIST_HEAD_NOLOCK(, sla_ringing_station) ringing_stations;
- AST_LIST_HEAD_NOLOCK(, sla_failed_station) failed_stations;
- AST_LIST_HEAD_NOLOCK(, sla_event) event_q;
- unsigned int stop:1;
- /*! Attempt to handle CallerID, even though it is known not to work
- * properly in some situations. */
- unsigned int attempt_callerid:1;
- /*! A reload has been requested */
- unsigned int reload:1;
- } sla = {
- .thread = AST_PTHREADT_NULL,
- };
- /*! The number of audio buffers to be allocated on pseudo channels
- * when in a conference */
- static int audio_buffers;
- /*! Map 'volume' levels from -5 through +5 into
- * decibel (dB) settings for channel drivers
- * Note: these are not a straight linear-to-dB
- * conversion... the numbers have been modified
- * to give the user a better level of adjustability
- */
- static char const gain_map[] = {
- -15,
- -13,
- -10,
- -6,
- 0,
- 0,
- 0,
- 6,
- 10,
- 13,
- 15,
- };
- static int admin_exec(struct ast_channel *chan, void *data);
- static void *recordthread(void *args);
- static char *istalking(int x)
- {
- if (x > 0)
- return "(talking)";
- else if (x < 0)
- return "(unmonitored)";
- else
- return "(not talking)";
- }
- static int careful_write(int fd, unsigned char *data, int len, int block)
- {
- int res;
- int x;
- while (len) {
- if (block) {
- x = DAHDI_IOMUX_WRITE | DAHDI_IOMUX_SIGEVENT;
- res = ioctl(fd, DAHDI_IOMUX, &x);
- } else
- res = 0;
- if (res >= 0)
- res = write(fd, data, len);
- if (res < 1) {
- if (errno != EAGAIN) {
- ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
- return -1;
- } else
- return 0;
- }
- len -= res;
- data += res;
- }
- return 0;
- }
- static int set_talk_volume(struct ast_conf_user *user, int volume)
- {
- char gain_adjust;
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- gain_adjust = gain_map[volume + 5];
- return ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
- }
- static int set_listen_volume(struct ast_conf_user *user, int volume)
- {
- char gain_adjust;
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- gain_adjust = gain_map[volume + 5];
- return ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
- }
- static void tweak_volume(struct volume *vol, enum volume_action action)
- {
- switch (action) {
- case VOL_UP:
- switch (vol->desired) {
- case 5:
- break;
- case 0:
- vol->desired = 2;
- break;
- case -2:
- vol->desired = 0;
- break;
- default:
- vol->desired++;
- break;
- }
- break;
- case VOL_DOWN:
- switch (vol->desired) {
- case -5:
- break;
- case 2:
- vol->desired = 0;
- break;
- case 0:
- vol->desired = -2;
- break;
- default:
- vol->desired--;
- break;
- }
- }
- }
- static void tweak_talk_volume(struct ast_conf_user *user, enum volume_action action)
- {
- tweak_volume(&user->talk, action);
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- if (!set_talk_volume(user, user->talk.desired))
- user->talk.actual = 0;
- else
- user->talk.actual = user->talk.desired;
- }
- static void tweak_listen_volume(struct ast_conf_user *user, enum volume_action action)
- {
- tweak_volume(&user->listen, action);
- /* attempt to make the adjustment in the channel driver;
- if successful, don't adjust in the frame reading routine
- */
- if (!set_listen_volume(user, user->listen.desired))
- user->listen.actual = 0;
- else
- user->listen.actual = user->listen.desired;
- }
- static void reset_volumes(struct ast_conf_user *user)
- {
- signed char zero_volume = 0;
- ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
- ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &zero_volume, sizeof(zero_volume), 0);
- }
- static void conf_play(struct ast_channel *chan, struct ast_conference *conf, enum entrance_sound sound)
- {
- unsigned char *data;
- int len;
- int res = -1;
- if (!ast_check_hangup(chan))
- res = ast_autoservice_start(chan);
- AST_LIST_LOCK(&confs);
- switch(sound) {
- case ENTER:
- data = enter;
- len = sizeof(enter);
- break;
- case LEAVE:
- data = leave;
- len = sizeof(leave);
- break;
- default:
- data = NULL;
- len = 0;
- }
- if (data) {
- careful_write(conf->fd, data, len, 1);
- }
- AST_LIST_UNLOCK(&confs);
- if (!res)
- ast_autoservice_stop(chan);
- }
- /*!
- * \brief Find or create a conference
- *
- * \param confno The conference name/number
- * \param pin The regular user pin
- * \param pinadmin The admin pin
- * \param make Make the conf if it doesn't exist
- * \param dynamic Mark the newly created conference as dynamic
- * \param refcount How many references to mark on the conference
- * \param chan The asterisk channel
- *
- * \return A pointer to the conference struct, or NULL if it wasn't found and
- * make or dynamic were not set.
- */
- static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin, int make, int dynamic, int refcount, const struct ast_channel *chan)
- {
- struct ast_conference *cnf;
- struct dahdi_confinfo dahdic = { 0, };
- int confno_int = 0;
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
- if (cnf || (!make && !dynamic))
- goto cnfout;
- /* Make a new one */
- if (!(cnf = ast_calloc(1, sizeof(*cnf))))
- goto cnfout;
- ast_mutex_init(&cnf->playlock);
- ast_mutex_init(&cnf->listenlock);
- cnf->recordthread = AST_PTHREADT_NULL;
- ast_mutex_init(&cnf->recordthreadlock);
- cnf->announcethread = AST_PTHREADT_NULL;
- ast_mutex_init(&cnf->announcethreadlock);
- ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
- ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
- ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
- ast_copy_string(cnf->uniqueid, chan->uniqueid, sizeof(cnf->uniqueid));
- /* Setup a new dahdi conference */
- dahdic.confno = -1;
- dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
- cnf->fd = open("/dev/dahdi/pseudo", O_RDWR);
- if (cnf->fd < 0 || ioctl(cnf->fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Unable to open pseudo device\n");
- if (cnf->fd >= 0)
- close(cnf->fd);
- ast_free(cnf);
- cnf = NULL;
- goto cnfout;
- }
- cnf->dahdiconf = dahdic.confno;
- /* Setup a new channel for playback of audio files */
- cnf->chan = ast_request("DAHDI", AST_FORMAT_SLINEAR, "pseudo", NULL);
- if (cnf->chan) {
- ast_set_read_format(cnf->chan, AST_FORMAT_SLINEAR);
- ast_set_write_format(cnf->chan, AST_FORMAT_SLINEAR);
- dahdic.chan = 0;
- dahdic.confno = cnf->dahdiconf;
- dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
- if (ioctl(cnf->chan->fds[0], DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- if (cnf->chan)
- ast_hangup(cnf->chan);
- else
- close(cnf->fd);
- ast_free(cnf);
- cnf = NULL;
- goto cnfout;
- }
- }
- /* Fill the conference struct */
- cnf->start = time(NULL);
- cnf->maxusers = 0x7fffffff;
- cnf->isdynamic = dynamic ? 1 : 0;
- ast_verb(3, "Created MeetMe conference %d for conference '%s'\n", cnf->dahdiconf, cnf->confno);
- AST_LIST_INSERT_HEAD(&confs, cnf, list);
- /* Reserve conference number in map */
- if ((sscanf(cnf->confno, "%30d", &confno_int) == 1) && (confno_int >= 0 && confno_int < 1024))
- conf_map[confno_int] = 1;
-
- cnfout:
- if (cnf)
- ast_atomic_fetchadd_int(&cnf->refcount, refcount);
- AST_LIST_UNLOCK(&confs);
- return cnf;
- }
- static char *complete_meetmecmd(const char *line, const char *word, int pos, int state)
- {
- static char *cmds[] = {"concise", "lock", "unlock", "mute", "unmute", "kick", "list", NULL};
- int len = strlen(word);
- int which = 0;
- struct ast_conference *cnf = NULL;
- struct ast_conf_user *usr = NULL;
- char *confno = NULL;
- char usrno[50] = "";
- char *myline, *ret = NULL;
-
- if (pos == 1) { /* Command */
- return ast_cli_complete(word, cmds, state);
- } else if (pos == 2) { /* Conference Number */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strncasecmp(word, cnf->confno, len) && ++which > state) {
- ret = cnf->confno;
- break;
- }
- }
- ret = ast_strdup(ret); /* dup before releasing the lock */
- AST_LIST_UNLOCK(&confs);
- return ret;
- } else if (pos == 3) {
- /* User Number || Conf Command option*/
- if (strstr(line, "mute") || strstr(line, "kick")) {
- if (state == 0 && (strstr(line, "kick") || strstr(line, "mute")) && !strncasecmp(word, "all", len))
- return ast_strdup("all");
- which++;
- AST_LIST_LOCK(&confs);
- /* TODO: Find the conf number from the cmdline (ignore spaces) <- test this and make it fail-safe! */
- myline = ast_strdupa(line);
- if (strsep(&myline, " ") && strsep(&myline, " ") && !confno) {
- while((confno = strsep(&myline, " ")) && (strcmp(confno, " ") == 0))
- ;
- }
-
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
- if (cnf) {
- /* Search for the user */
- AST_LIST_TRAVERSE(&cnf->userlist, usr, list) {
- snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
- if (!strncasecmp(word, usrno, len) && ++which > state)
- break;
- }
- }
- AST_LIST_UNLOCK(&confs);
- return usr ? ast_strdup(usrno) : NULL;
- } else if (strstr(line, "list") && (state == 0))
- return ast_strdup("concise");
- }
- return NULL;
- }
- static char *meetme_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- /* Process the command */
- struct ast_conference *cnf;
- struct ast_conf_user *user;
- int hr, min, sec;
- int i = 0, total = 0;
- time_t now;
- char cmdline[1024] = "";
- #define MC_HEADER_FORMAT "%-14s %-14s %-10s %-8s %-8s %-6s\n"
- #define MC_DATA_FORMAT "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s %-6s\n"
- switch (cmd) {
- case CLI_INIT:
- e->command = "meetme";
- e->usage =
- "Usage: meetme (un)lock|(un)mute|kick|list [concise] <confno> <usernumber>\n"
- " Executes a command for the conference or on a conferee\n";
- return NULL;
- case CLI_GENERATE:
- return complete_meetmecmd(a->line, a->word, a->pos, a->n);
- }
- if (a->argc > 8)
- ast_cli(a->fd, "Invalid Arguments.\n");
- /* Check for length so no buffer will overflow... */
- for (i = 0; i < a->argc; i++) {
- if (strlen(a->argv[i]) > 100)
- ast_cli(a->fd, "Invalid Arguments.\n");
- }
- if (a->argc == 1 || (a->argc == 2 && !strcasecmp(a->argv[1], "concise"))) {
- /* 'MeetMe': List all the conferences */
- int concise = (a->argc == 2 && !strcasecmp(a->argv[1], "concise"));
- now = time(NULL);
- AST_LIST_LOCK(&confs);
- if (AST_LIST_EMPTY(&confs)) {
- if (!concise)
- ast_cli(a->fd, "No active MeetMe conferences.\n");
- AST_LIST_UNLOCK(&confs);
- return CLI_SUCCESS;
- }
- if (!concise)
- ast_cli(a->fd, MC_HEADER_FORMAT, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (cnf->markedusers == 0)
- strcpy(cmdline, "N/A ");
- else
- snprintf(cmdline, sizeof(cmdline), "%4.4d", cnf->markedusers);
- hr = (now - cnf->start) / 3600;
- min = ((now - cnf->start) % 3600) / 60;
- sec = (now - cnf->start) % 60;
- if (!concise)
- ast_cli(a->fd, MC_DATA_FORMAT, cnf->confno, cnf->users, cmdline, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
- else {
- ast_cli(a->fd, "%s!%d!%d!%02d:%02d:%02d!%d!%d\n",
- cnf->confno,
- cnf->users,
- cnf->markedusers,
- hr, min, sec,
- cnf->isdynamic,
- cnf->locked);
- }
- total += cnf->users;
- }
- AST_LIST_UNLOCK(&confs);
- if (!concise)
- ast_cli(a->fd, "* Total number of MeetMe users: %d\n", total);
- return CLI_SUCCESS;
- }
- if (a->argc < 3)
- return CLI_SHOWUSAGE;
- ast_copy_string(cmdline, a->argv[2], sizeof(cmdline)); /* Argv 2: conference number */
- if (strstr(a->argv[1], "lock")) {
- if (strcmp(a->argv[1], "lock") == 0) {
- /* Lock */
- strncat(cmdline, ",L", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- /* Unlock */
- strncat(cmdline, ",l", sizeof(cmdline) - strlen(cmdline) - 1);
- }
- } else if (strstr(a->argv[1], "mute")) {
- if (a->argc < 4)
- return CLI_SHOWUSAGE;
- if (strcmp(a->argv[1], "mute") == 0) {
- /* Mute */
- if (strcmp(a->argv[3], "all") == 0) {
- strncat(cmdline, ",N", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- strncat(cmdline, ",M,", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
- }
- } else {
- /* Unmute */
- if (strcmp(a->argv[3], "all") == 0) {
- strncat(cmdline, ",n", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- strncat(cmdline, ",m,", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
- }
- }
- } else if (strcmp(a->argv[1], "kick") == 0) {
- if (a->argc < 4)
- return CLI_SHOWUSAGE;
- if (strcmp(a->argv[3], "all") == 0) {
- /* Kick all */
- strncat(cmdline, ",K", sizeof(cmdline) - strlen(cmdline) - 1);
- } else {
- /* Kick a single user */
- strncat(cmdline, ",k,", sizeof(cmdline) - strlen(cmdline) - 1);
- strncat(cmdline, a->argv[3], sizeof(cmdline) - strlen(cmdline) - 1);
- }
- } else if (strcmp(a->argv[1], "list") == 0) {
- int concise = (a->argc == 4 && (!strcasecmp(a->argv[3], "concise")));
- /* List all the users in a conference */
- if (AST_LIST_EMPTY(&confs)) {
- if (!concise)
- ast_cli(a->fd, "No active conferences.\n");
- return CLI_SUCCESS;
- }
- /* Find the right conference */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (strcmp(cnf->confno, a->argv[2]) == 0)
- break;
- }
- if (!cnf) {
- if (!concise)
- ast_cli(a->fd, "No such conference: %s.\n", a->argv[2]);
- AST_LIST_UNLOCK(&confs);
- return CLI_SUCCESS;
- }
- /* Show all the users */
- time(&now);
- AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
- hr = (now - user->jointime) / 3600;
- min = ((now - user->jointime) % 3600) / 60;
- sec = (now - user->jointime) % 60;
- if (!concise)
- ast_cli(a->fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %s %02d:%02d:%02d\n",
- user->user_no,
- S_OR(user->chan->cid.cid_num, "<unknown>"),
- S_OR(user->chan->cid.cid_name, "<no name>"),
- user->chan->name,
- user->userflags & CONFFLAG_ADMIN ? "(Admin)" : "",
- user->userflags & CONFFLAG_MONITOR ? "(Listen only)" : "",
- user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
- user->adminflags & ADMINFLAG_T_REQUEST ? "(Request to Talk)" : "",
- istalking(user->talking), hr, min, sec);
- else
- ast_cli(a->fd, "%d!%s!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
- user->user_no,
- S_OR(user->chan->cid.cid_num, ""),
- S_OR(user->chan->cid.cid_name, ""),
- user->chan->name,
- user->userflags & CONFFLAG_ADMIN ? "1" : "",
- user->userflags & CONFFLAG_MONITOR ? "1" : "",
- user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED) ? "1" : "",
- user->adminflags & ADMINFLAG_T_REQUEST ? "1" : "",
- user->talking, hr, min, sec);
-
- }
- if (!concise)
- ast_cli(a->fd, "%d users in that conference.\n", cnf->users);
- AST_LIST_UNLOCK(&confs);
- return CLI_SUCCESS;
- } else
- return CLI_SHOWUSAGE;
- ast_debug(1, "Cmdline: %s\n", cmdline);
- admin_exec(NULL, cmdline);
- return CLI_SUCCESS;
- }
- static const char *sla_hold_str(unsigned int hold_access)
- {
- const char *hold = "Unknown";
- switch (hold_access) {
- case SLA_HOLD_OPEN:
- hold = "Open";
- break;
- case SLA_HOLD_PRIVATE:
- hold = "Private";
- default:
- break;
- }
- return hold;
- }
- static char *sla_show_trunks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- const struct sla_trunk *trunk;
- switch (cmd) {
- case CLI_INIT:
- e->command = "sla show trunks";
- e->usage =
- "Usage: sla show trunks\n"
- " This will list all trunks defined in sla.conf\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- ast_cli(a->fd, "\n"
- "=============================================================\n"
- "=== Configured SLA Trunks ===================================\n"
- "=============================================================\n"
- "===\n");
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
- struct sla_station_ref *station_ref;
- char ring_timeout[16] = "(none)";
- if (trunk->ring_timeout)
- snprintf(ring_timeout, sizeof(ring_timeout), "%u Seconds", trunk->ring_timeout);
- ast_cli(a->fd, "=== ---------------------------------------------------------\n"
- "=== Trunk Name: %s\n"
- "=== ==> Device: %s\n"
- "=== ==> AutoContext: %s\n"
- "=== ==> RingTimeout: %s\n"
- "=== ==> BargeAllowed: %s\n"
- "=== ==> HoldAccess: %s\n"
- "=== ==> Stations ...\n",
- trunk->name, trunk->device,
- S_OR(trunk->autocontext, "(none)"),
- ring_timeout,
- trunk->barge_disabled ? "No" : "Yes",
- sla_hold_str(trunk->hold_access));
- AST_RWLIST_RDLOCK(&sla_stations);
- AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry)
- ast_cli(a->fd, "=== ==> Station name: %s\n", station_ref->station->name);
- AST_RWLIST_UNLOCK(&sla_stations);
- ast_cli(a->fd, "=== ---------------------------------------------------------\n===\n");
- }
- AST_RWLIST_UNLOCK(&sla_trunks);
- ast_cli(a->fd, "=============================================================\n\n");
- return CLI_SUCCESS;
- }
- static const char *trunkstate2str(enum sla_trunk_state state)
- {
- #define S(e) case e: return # e;
- switch (state) {
- S(SLA_TRUNK_STATE_IDLE)
- S(SLA_TRUNK_STATE_RINGING)
- S(SLA_TRUNK_STATE_UP)
- S(SLA_TRUNK_STATE_ONHOLD)
- S(SLA_TRUNK_STATE_ONHOLD_BYME)
- }
- return "Uknown State";
- #undef S
- }
- static char *sla_show_stations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- const struct sla_station *station;
- switch (cmd) {
- case CLI_INIT:
- e->command = "sla show stations";
- e->usage =
- "Usage: sla show stations\n"
- " This will list all stations defined in sla.conf\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- ast_cli(a->fd, "\n"
- "=============================================================\n"
- "=== Configured SLA Stations =================================\n"
- "=============================================================\n"
- "===\n");
- AST_RWLIST_RDLOCK(&sla_stations);
- AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
- struct sla_trunk_ref *trunk_ref;
- char ring_timeout[16] = "(none)";
- char ring_delay[16] = "(none)";
- if (station->ring_timeout) {
- snprintf(ring_timeout, sizeof(ring_timeout),
- "%u", station->ring_timeout);
- }
- if (station->ring_delay) {
- snprintf(ring_delay, sizeof(ring_delay),
- "%u", station->ring_delay);
- }
- ast_cli(a->fd, "=== ---------------------------------------------------------\n"
- "=== Station Name: %s\n"
- "=== ==> Device: %s\n"
- "=== ==> AutoContext: %s\n"
- "=== ==> RingTimeout: %s\n"
- "=== ==> RingDelay: %s\n"
- "=== ==> HoldAccess: %s\n"
- "=== ==> Trunks ...\n",
- station->name, station->device,
- S_OR(station->autocontext, "(none)"),
- ring_timeout, ring_delay,
- sla_hold_str(station->hold_access));
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (trunk_ref->ring_timeout) {
- snprintf(ring_timeout, sizeof(ring_timeout),
- "%u", trunk_ref->ring_timeout);
- } else
- strcpy(ring_timeout, "(none)");
- if (trunk_ref->ring_delay) {
- snprintf(ring_delay, sizeof(ring_delay),
- "%u", trunk_ref->ring_delay);
- } else
- strcpy(ring_delay, "(none)");
- ast_cli(a->fd, "=== ==> Trunk Name: %s\n"
- "=== ==> State: %s\n"
- "=== ==> RingTimeout: %s\n"
- "=== ==> RingDelay: %s\n",
- trunk_ref->trunk->name,
- trunkstate2str(trunk_ref->state),
- ring_timeout, ring_delay);
- }
- AST_RWLIST_UNLOCK(&sla_trunks);
- ast_cli(a->fd, "=== ---------------------------------------------------------\n"
- "===\n");
- }
- AST_RWLIST_UNLOCK(&sla_stations);
- ast_cli(a->fd, "============================================================\n"
- "\n");
- return CLI_SUCCESS;
- }
- static struct ast_cli_entry cli_meetme[] = {
- AST_CLI_DEFINE(meetme_cmd, "Execute a command on a conference or conferee"),
- AST_CLI_DEFINE(sla_show_trunks, "Show SLA Trunks"),
- AST_CLI_DEFINE(sla_show_stations, "Show SLA Stations"),
- };
- static void conf_flush(int fd, struct ast_channel *chan)
- {
- int x;
- /* read any frames that may be waiting on the channel
- and throw them away
- */
- if (chan) {
- struct ast_frame *f;
- /* when no frames are available, this will wait
- for 1 millisecond maximum
- */
- while (ast_waitfor(chan, 1)) {
- f = ast_read(chan);
- if (f)
- ast_frfree(f);
- else /* channel was hung up or something else happened */
- break;
- }
- }
- /* flush any data sitting in the pseudo channel */
- x = DAHDI_FLUSH_ALL;
- if (ioctl(fd, DAHDI_FLUSH, &x))
- ast_log(LOG_WARNING, "Error flushing channel\n");
- }
- /* Remove the conference from the list and free it.
- We assume that this was called while holding conflock. */
- static int conf_free(struct ast_conference *conf)
- {
- int x;
- struct announce_listitem *item;
-
- AST_LIST_REMOVE(&confs, conf, list);
- manager_event(EVENT_FLAG_CALL, "MeetmeEnd", "Meetme: %s\r\n", conf->confno);
- if (conf->recording == MEETME_RECORD_ACTIVE) {
- conf->recording = MEETME_RECORD_TERMINATE;
- AST_LIST_UNLOCK(&confs);
- while (1) {
- usleep(1);
- AST_LIST_LOCK(&confs);
- if (conf->recording == MEETME_RECORD_OFF)
- break;
- AST_LIST_UNLOCK(&confs);
- }
- }
- for (x = 0; x < AST_FRAME_BITS; x++) {
- if (conf->transframe[x])
- ast_frfree(conf->transframe[x]);
- if (conf->transpath[x])
- ast_translator_free_path(conf->transpath[x]);
- }
- if (conf->announcethread != AST_PTHREADT_NULL) {
- ast_mutex_lock(&conf->announcelistlock);
- conf->announcethread_stop = 1;
- ast_softhangup(conf->chan, AST_SOFTHANGUP_EXPLICIT);
- ast_cond_signal(&conf->announcelist_addition);
- ast_mutex_unlock(&conf->announcelistlock);
- pthread_join(conf->announcethread, NULL);
-
- while ((item = AST_LIST_REMOVE_HEAD(&conf->announcelist, entry))) {
- ast_filedelete(item->namerecloc, NULL);
- ao2_ref(item, -1);
- }
- ast_mutex_destroy(&conf->announcelistlock);
- }
- if (conf->origframe)
- ast_frfree(conf->origframe);
- if (conf->lchan)
- ast_hangup(conf->lchan);
- if (conf->chan)
- ast_hangup(conf->chan);
- if (conf->fd >= 0)
- close(conf->fd);
- ast_mutex_destroy(&conf->playlock);
- ast_mutex_destroy(&conf->listenlock);
- ast_mutex_destroy(&conf->recordthreadlock);
- ast_mutex_destroy(&conf->announcethreadlock);
- ast_free(conf);
- return 0;
- }
- static void conf_queue_dtmf(const struct ast_conference *conf,
- const struct ast_conf_user *sender, struct ast_frame *f)
- {
- struct ast_conf_user *user;
- AST_LIST_TRAVERSE(&conf->userlist, user, list) {
- if (user == sender)
- continue;
- if (ast_write(user->chan, f) < 0)
- ast_log(LOG_WARNING, "Error writing frame to channel %s\n", user->chan->name);
- }
- }
- static void sla_queue_event_full(enum sla_event_type type,
- struct sla_trunk_ref *trunk_ref, struct sla_station *station, int lock)
- {
- struct sla_event *event;
- if (sla.thread == AST_PTHREADT_NULL) {
- return;
- }
- if (!(event = ast_calloc(1, sizeof(*event))))
- return;
- event->type = type;
- event->trunk_ref = trunk_ref;
- event->station = station;
- if (!lock) {
- AST_LIST_INSERT_TAIL(&sla.event_q, event, entry);
- return;
- }
- ast_mutex_lock(&sla.lock);
- AST_LIST_INSERT_TAIL(&sla.event_q, event, entry);
- ast_cond_signal(&sla.cond);
- ast_mutex_unlock(&sla.lock);
- }
- static void sla_queue_event_nolock(enum sla_event_type type)
- {
- sla_queue_event_full(type, NULL, NULL, 0);
- }
- static void sla_queue_event(enum sla_event_type type)
- {
- sla_queue_event_full(type, NULL, NULL, 1);
- }
- /*! \brief Queue a SLA event from the conference */
- static void sla_queue_event_conf(enum sla_event_type type, struct ast_channel *chan,
- struct ast_conference *conf)
- {
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref = NULL;
- char *trunk_name;
- trunk_name = ast_strdupa(conf->confno);
- strsep(&trunk_name, "_");
- if (ast_strlen_zero(trunk_name)) {
- ast_log(LOG_ERROR, "Invalid conference name for SLA - '%s'!\n", conf->confno);
- return;
- }
- AST_RWLIST_RDLOCK(&sla_stations);
- AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (trunk_ref->chan == chan && !strcmp(trunk_ref->trunk->name, trunk_name))
- break;
- }
- if (trunk_ref)
- break;
- }
- AST_RWLIST_UNLOCK(&sla_stations);
- if (!trunk_ref) {
- ast_debug(1, "Trunk not found for event!\n");
- return;
- }
- sla_queue_event_full(type, trunk_ref, station, 1);
- }
- /* Decrement reference counts, as incremented by find_conf() */
- static int dispose_conf(struct ast_conference *conf)
- {
- int res = 0;
- int confno_int = 0;
- AST_LIST_LOCK(&confs);
- if (ast_atomic_dec_and_test(&conf->refcount)) {
- /* Take the conference room number out of an inuse state */
- if ((sscanf(conf->confno, "%4d", &confno_int) == 1) && (confno_int >= 0 && confno_int < 1024))
- conf_map[confno_int] = 0;
- conf_free(conf);
- res = 1;
- }
- AST_LIST_UNLOCK(&confs);
- return res;
- }
- static void conf_start_moh(struct ast_channel *chan, const char *musicclass)
- {
- char *original_moh;
- ast_channel_lock(chan);
- original_moh = ast_strdupa(chan->musicclass);
- ast_string_field_set(chan, musicclass, musicclass);
- ast_channel_unlock(chan);
- ast_moh_start(chan, original_moh, NULL);
- ast_channel_lock(chan);
- ast_string_field_set(chan, musicclass, original_moh);
- ast_channel_unlock(chan);
- }
- static const char *get_announce_filename(enum announcetypes type)
- {
- switch (type) {
- case CONF_HASLEFT:
- return "conf-hasleft";
- break;
- case CONF_HASJOIN:
- return "conf-hasjoin";
- break;
- default:
- return "";
- }
- }
- static void *announce_thread(void *data)
- {
- struct announce_listitem *current;
- struct ast_conference *conf = data;
- int res = 0;
- char filename[PATH_MAX] = "";
- AST_LIST_HEAD_NOLOCK(, announce_listitem) local_list;
- AST_LIST_HEAD_INIT_NOLOCK(&local_list);
- while (!conf->announcethread_stop) {
- ast_mutex_lock(&conf->announcelistlock);
- if (conf->announcethread_stop) {
- ast_mutex_unlock(&conf->announcelistlock);
- break;
- }
- if (AST_LIST_EMPTY(&conf->announcelist))
- ast_cond_wait(&conf->announcelist_addition, &conf->announcelistlock);
- AST_LIST_APPEND_LIST(&local_list, &conf->announcelist, entry);
- AST_LIST_HEAD_INIT_NOLOCK(&conf->announcelist);
- ast_mutex_unlock(&conf->announcelistlock);
- if (conf->announcethread_stop) {
- break;
- }
- for (res = 1; !conf->announcethread_stop && (current = AST_LIST_REMOVE_HEAD(&local_list, entry)); ao2_ref(current, -1)) {
- ast_log(LOG_DEBUG, "About to play %s\n", current->namerecloc);
- if (!ast_fileexists(current->namerecloc, NULL, NULL))
- continue;
- if ((current->confchan) && (current->confusers > 1) && !ast_check_hangup(current->confchan)) {
- if (!ast_streamfile(current->confchan, current->namerecloc, current->language))
- res = ast_waitstream(current->confchan, "");
- if (!res) {
- ast_copy_string(filename, get_announce_filename(current->announcetype), sizeof(filename));
- if (!ast_streamfile(current->confchan, filename, current->language))
- ast_waitstream(current->confchan, "");
- }
- }
- if (current->announcetype == CONF_HASLEFT) {
- ast_filedelete(current->namerecloc, NULL);
- }
- }
- }
- /* thread marked to stop, clean up */
- while ((current = AST_LIST_REMOVE_HEAD(&local_list, entry))) {
- ast_filedelete(current->namerecloc, NULL);
- ao2_ref(current, -1);
- }
- return NULL;
- }
- static int can_write(struct ast_channel *chan, int confflags)
- {
- if (!(confflags & CONFFLAG_NO_AUDIO_UNTIL_UP)) {
- return 1;
- }
- return (chan->_state == AST_STATE_UP);
- }
- static void send_talking_event(struct ast_channel *chan, struct ast_conference *conf, struct ast_conf_user *user, int talking)
- {
- manager_event(EVENT_FLAG_CALL, "MeetmeTalking",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n"
- "Status: %s\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no, talking ? "on" : "off");
- }
- static void set_user_talking(struct ast_channel *chan, struct ast_conference *conf, struct ast_conf_user *user, int talking, int monitor)
- {
- int last_talking = user->talking;
- if (last_talking == talking)
- return;
- user->talking = talking;
- if (monitor) {
- /* Check if talking state changed. Take care of -1 which means unmonitored */
- int was_talking = (last_talking > 0);
- int now_talking = (talking > 0);
- if (was_talking != now_talking) {
- send_talking_event(chan, conf, user, now_talking);
- }
- }
- }
- static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int confflags, char *optargs[])
- {
- struct ast_conf_user *user = NULL;
- struct ast_conf_user *usr = NULL;
- int fd;
- struct dahdi_confinfo dahdic, dahdic_empty;
- struct ast_frame *f;
- struct ast_channel *c;
- struct ast_frame fr;
- int outfd;
- int ms;
- int nfds;
- int res;
- int retrydahdi;
- int origfd;
- int musiconhold = 0, mohtempstopped = 0;
- int firstpass = 0;
- int lastmarked = 0;
- int currentmarked = 0;
- int ret = -1;
- int x;
- int menu_active = 0;
- int talkreq_manager = 0;
- int using_pseudo = 0;
- int duration = 20;
- int hr, min, sec;
- int sent_event = 0;
- int checked = 0;
- int announcement_played = 0;
- struct timeval now;
- struct ast_dsp *dsp = NULL;
- struct ast_app *app;
- const char *agifile;
- const char *agifiledefault = "conf-background.agi";
- char meetmesecs[30] = "";
- char exitcontext[AST_MAX_CONTEXT] = "";
- char recordingtmp[AST_MAX_EXTENSION] = "";
- char members[10] = "";
- int dtmf, opt_waitmarked_timeout = 0;
- time_t timeout = 0;
- struct dahdi_bufferinfo bi;
- char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
- char *buf = __buf + AST_FRIENDLY_OFFSET;
- char *exitkeys = NULL;
- unsigned int calldurationlimit = 0;
- long timelimit = 0;
- long play_warning = 0;
- long warning_freq = 0;
- const char *warning_sound = NULL;
- const char *end_sound = NULL;
- char *parse;
- long time_left_ms = 0;
- struct timeval nexteventts = { 0, };
- int to;
- int setusercount = 0;
- int confsilence = 0, totalsilence = 0;
- if (!(user = ast_calloc(1, sizeof(*user))))
- return ret;
- /* Possible timeout waiting for marked user */
- if ((confflags & CONFFLAG_WAITMARKED) &&
- !ast_strlen_zero(optargs[OPT_ARG_WAITMARKED]) &&
- (sscanf(optargs[OPT_ARG_WAITMARKED], "%30d", &opt_waitmarked_timeout) == 1) &&
- (opt_waitmarked_timeout > 0)) {
- timeout = time(NULL) + opt_waitmarked_timeout;
- }
-
- if ((confflags & CONFFLAG_DURATION_STOP) && !ast_strlen_zero(optargs[OPT_ARG_DURATION_STOP])) {
- calldurationlimit = atoi(optargs[OPT_ARG_DURATION_STOP]);
- ast_verb(3, "Setting call duration limit to %d seconds.\n", calldurationlimit);
- }
-
- if ((confflags & CONFFLAG_DURATION_LIMIT) && !ast_strlen_zero(optargs[OPT_ARG_DURATION_LIMIT])) {
- char *limit_str, *warning_str, *warnfreq_str;
- const char *var;
-
- parse = optargs[OPT_ARG_DURATION_LIMIT];
- limit_str = strsep(&parse, ":");
- warning_str = strsep(&parse, ":");
- warnfreq_str = parse;
-
- timelimit = atol(limit_str);
- if (warning_str)
- play_warning = atol(warning_str);
- if (warnfreq_str)
- warning_freq = atol(warnfreq_str);
-
- if (!timelimit) {
- timelimit = play_warning = warning_freq = 0;
- warning_sound = NULL;
- } else if (play_warning > timelimit) {
- if (!warning_freq) {
- play_warning = 0;
- } else {
- while (play_warning > timelimit)
- play_warning -= warning_freq;
- if (play_warning < 1)
- play_warning = warning_freq = 0;
- }
- }
-
- var = pbx_builtin_getvar_helper(chan, "CONF_LIMIT_WARNING_FILE");
- warning_sound = var ? var : "timeleft";
-
- var = pbx_builtin_getvar_helper(chan, "CONF_LIMIT_TIMEOUT_FILE");
- end_sound = var ? var : NULL;
-
- /* undo effect of S(x) in case they are both used */
- calldurationlimit = 0;
- /* more efficient do it like S(x) does since no advanced opts */
- if (!play_warning && !end_sound && timelimit) {
- calldurationlimit = timelimit / 1000;
- timelimit = play_warning = warning_freq = 0;
- } else {
- ast_debug(2, "Limit Data for this call:\n");
- ast_debug(2, "- timelimit = %ld\n", timelimit);
- ast_debug(2, "- play_warning = %ld\n", play_warning);
- ast_debug(2, "- warning_freq = %ld\n", warning_freq);
- ast_debug(2, "- warning_sound = %s\n", warning_sound ? warning_sound : "UNDEF");
- ast_debug(2, "- end_sound = %s\n", end_sound ? end_sound : "UNDEF");
- }
- }
- /* Get exit keys */
- if ((confflags & CONFFLAG_KEYEXIT)) {
- if (!ast_strlen_zero(optargs[OPT_ARG_EXITKEYS]))
- exitkeys = ast_strdupa(optargs[OPT_ARG_EXITKEYS]);
- else
- exitkeys = ast_strdupa("#"); /* Default */
- }
-
- if (confflags & CONFFLAG_RECORDCONF) {
- if (!conf->recordingfilename) {
- conf->recordingfilename = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE");
- if (!conf->recordingfilename) {
- snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", conf->confno, chan->uniqueid);
- conf->recordingfilename = ast_strdupa(recordingtmp);
- }
- conf->recordingformat = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT");
- if (!conf->recordingformat) {
- ast_copy_string(recordingtmp, "wav", sizeof(recordingtmp));
- conf->recordingformat = ast_strdupa(recordingtmp);
- }
- ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n",
- conf->confno, conf->recordingfilename, conf->recordingformat);
- }
- }
- ast_mutex_lock(&conf->recordthreadlock);
- if ((conf->recordthread == AST_PTHREADT_NULL) && (confflags & CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", AST_FORMAT_SLINEAR, "pseudo", NULL)))) {
- ast_set_read_format(conf->lchan, AST_FORMAT_SLINEAR);
- ast_set_write_format(conf->lchan, AST_FORMAT_SLINEAR);
- dahdic.chan = 0;
- dahdic.confno = conf->dahdiconf;
- dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
- if (ioctl(conf->lchan->fds[0], DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error starting listen channel\n");
- ast_hangup(conf->lchan);
- conf->lchan = NULL;
- } else {
- ast_pthread_create_detached_background(&conf->recordthread, NULL, recordthread, conf);
- }
- }
- ast_mutex_unlock(&conf->recordthreadlock);
- ast_mutex_lock(&conf->announcethreadlock);
- if ((conf->announcethread == AST_PTHREADT_NULL) && !(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW))) {
- ast_mutex_init(&conf->announcelistlock);
- AST_LIST_HEAD_INIT_NOLOCK(&conf->announcelist);
- ast_pthread_create_background(&conf->announcethread, NULL, announce_thread, conf);
- }
- ast_mutex_unlock(&conf->announcethreadlock);
- time(&user->jointime);
-
- user->timelimit = timelimit;
- user->play_warning = play_warning;
- user->warning_freq = warning_freq;
- user->warning_sound = warning_sound;
- user->end_sound = end_sound;
-
- if (calldurationlimit > 0) {
- time(&user->kicktime);
- user->kicktime = user->kicktime + calldurationlimit;
- }
-
- if (ast_tvzero(user->start_time))
- user->start_time = ast_tvnow();
- time_left_ms = user->timelimit;
-
- if (user->timelimit) {
- nexteventts = ast_tvadd(user->start_time, ast_samp2tv(user->timelimit, 1000));
- nexteventts = ast_tvsub(nexteventts, ast_samp2tv(user->play_warning, 1000));
- }
- if (conf->locked && (!(confflags & CONFFLAG_ADMIN))) {
- /* Sorry, but this conference is locked! */
- if (!ast_streamfile(chan, "conf-locked", chan->language))
- ast_waitstream(chan, "");
- goto outrun;
- }
- ast_mutex_lock(&conf->playlock);
- if (AST_LIST_EMPTY(&conf->userlist))
- user->user_no = 1;
- else
- user->user_no = AST_LIST_LAST(&conf->userlist)->user_no + 1;
- if (rt_schedule && conf->maxusers)
- if (conf->users >= conf->maxusers) {
- /* Sorry, but this confernce has reached the participant limit! */
- if (!ast_streamfile(chan, "conf-full", chan->language))
- ast_waitstream(chan, "");
- ast_mutex_unlock(&conf->playlock);
- user->user_no = 0;
- goto outrun;
- }
- AST_LIST_INSERT_TAIL(&conf->userlist, user, list);
- user->chan = chan;
- user->userflags = confflags;
- user->adminflags = (confflags & CONFFLAG_STARTMUTED) ? ADMINFLAG_SELFMUTED : 0;
- user->talking = -1;
- ast_mutex_unlock(&conf->playlock);
- if (!(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW))) {
- char destdir[PATH_MAX];
- snprintf(destdir, sizeof(destdir), "%s/meetme", ast_config_AST_SPOOL_DIR);
- if (ast_mkdir(destdir, 0777) != 0) {
- ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", destdir, strerror(errno));
- goto outrun;
- }
- snprintf(user->namerecloc, sizeof(user->namerecloc),
- "%s/meetme-username-%s-%d", destdir,
- conf->confno, user->user_no);
- if (confflags & CONFFLAG_INTROUSERNOREVIEW)
- res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, 128, 0, NULL);
- else
- res = ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
- if (res == -1)
- goto outrun;
- }
- ast_mutex_lock(&conf->playlock);
- if (confflags & CONFFLAG_MARKEDUSER)
- conf->markedusers++;
- conf->users++;
- if (rt_log_members) {
- /* Update table */
- snprintf(members, sizeof(members), "%d", conf->users);
- ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
- }
- setusercount = 1;
- /* This device changed state now - if this is the first user */
- if (conf->users == 1)
- ast_devstate_changed(AST_DEVICE_INUSE, "meetme:%s", conf->confno);
- ast_mutex_unlock(&conf->playlock);
- /* return the unique ID of the conference */
- pbx_builtin_setvar_helper(chan, "MEETMEUNIQUEID", conf->uniqueid);
- if (confflags & CONFFLAG_EXIT_CONTEXT) {
- if ((agifile = pbx_builtin_getvar_helper(chan, "MEETME_EXIT_CONTEXT")))
- ast_copy_string(exitcontext, agifile, sizeof(exitcontext));
- else if (!ast_strlen_zero(chan->macrocontext))
- ast_copy_string(exitcontext, chan->macrocontext, sizeof(exitcontext));
- else
- ast_copy_string(exitcontext, chan->context, sizeof(exitcontext));
- }
- if (!(confflags & (CONFFLAG_QUIET | CONFFLAG_NOONLYPERSON))) {
- if (conf->users == 1 && !(confflags & CONFFLAG_WAITMARKED))
- if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
- ast_waitstream(chan, "");
- if ((confflags & CONFFLAG_WAITMARKED) && conf->markedusers == 0)
- if (!ast_streamfile(chan, "conf-waitforleader", chan->language))
- ast_waitstream(chan, "");
- }
- if (!(confflags & CONFFLAG_QUIET) && (confflags & CONFFLAG_ANNOUNCEUSERCOUNT) && conf->users > 1) {
- int keepplaying = 1;
- if (conf->users == 2) {
- if (!ast_streamfile(chan, "conf-onlyone", chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- if (res > 0)
- keepplaying = 0;
- else if (res == -1)
- goto outrun;
- }
- } else {
- if (!ast_streamfile(chan, "conf-thereare", chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- if (res > 0)
- keepplaying = 0;
- else if (res == -1)
- goto outrun;
- }
- if (keepplaying) {
- res = ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
- if (res > 0)
- keepplaying = 0;
- else if (res == -1)
- goto outrun;
- }
- if (keepplaying && !ast_streamfile(chan, "conf-otherinparty", chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- if (res > 0)
- keepplaying = 0;
- else if (res == -1)
- goto outrun;
- }
- }
- }
- if (!(confflags & CONFFLAG_NO_AUDIO_UNTIL_UP)) {
- /* We're leaving this alone until the state gets changed to up */
- ast_indicate(chan, -1);
- }
- if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", chan->name);
- goto outrun;
- }
- if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", chan->name);
- goto outrun;
- }
- retrydahdi = (strcasecmp(chan->tech->type, "DAHDI") || (chan->audiohooks || chan->monitor) ? 1 : 0);
- user->dahdichannel = !retrydahdi;
- dahdiretry:
- origfd = chan->fds[0];
- if (retrydahdi) {
- /* open pseudo in non-blocking mode */
- fd = open("/dev/dahdi/pseudo", O_RDWR | O_NONBLOCK);
- if (fd < 0) {
- ast_log(LOG_WARNING, "Unable to open pseudo channel: %s\n", strerror(errno));
- goto outrun;
- }
- using_pseudo = 1;
- /* Setup buffering information */
- memset(&bi, 0, sizeof(bi));
- bi.bufsize = CONF_SIZE / 2;
- bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
- bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
- bi.numbufs = audio_buffers;
- if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) {
- ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- x = 1;
- if (ioctl(fd, DAHDI_SETLINEAR, &x)) {
- ast_log(LOG_WARNING, "Unable to set linear mode: %s\n", strerror(errno));
- close(fd);
- goto outrun;
- }
- nfds = 1;
- } else {
- /* XXX Make sure we're not running on a pseudo channel XXX */
- fd = chan->fds[0];
- nfds = 0;
- }
- memset(&dahdic, 0, sizeof(dahdic));
- memset(&dahdic_empty, 0, sizeof(dahdic_empty));
- /* Check to see if we're in a conference... */
- dahdic.chan = 0;
- if (ioctl(fd, DAHDI_GETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error getting conference\n");
- close(fd);
- goto outrun;
- }
- if (dahdic.confmode) {
- /* Whoa, already in a conference... Retry... */
- if (!retrydahdi) {
- ast_debug(1, "DAHDI channel is in a conference already, retrying with pseudo\n");
- retrydahdi = 1;
- goto dahdiretry;
- }
- }
- memset(&dahdic, 0, sizeof(dahdic));
- /* Add us to the conference */
- dahdic.chan = 0;
- dahdic.confno = conf->dahdiconf;
- if (!(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW)) && conf->users > 1) {
- struct announce_listitem *item;
- if (!(item = ao2_alloc(sizeof(*item), NULL)))
- return -1;
- ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
- ast_copy_string(item->language, chan->language, sizeof(item->language));
- item->confchan = conf->chan;
- item->confusers = conf->users;
- item->announcetype = CONF_HASJOIN;
- ast_mutex_lock(&conf->announcelistlock);
- ao2_ref(item, +1); /* add one more so we can determine when announce_thread is done playing it */
- AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
- ast_cond_signal(&conf->announcelist_addition);
- ast_mutex_unlock(&conf->announcelistlock);
- while (!ast_check_hangup(conf->chan) && ao2_ref(item, 0) == 2 && !ast_safe_sleep(chan, 1000)) {
- ;
- }
- ao2_ref(item, -1);
- }
- if (confflags & CONFFLAG_WAITMARKED && !conf->markedusers)
- dahdic.confmode = DAHDI_CONF_CONF;
- else if (confflags & CONFFLAG_MONITOR)
- dahdic.confmode = DAHDI_CONF_CONFMON | DAHDI_CONF_LISTENER;
- else if (confflags & CONFFLAG_TALKER)
- dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
- else
- dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- ast_debug(1, "Placed channel %s in DAHDI conf %d\n", chan->name, conf->dahdiconf);
- if (!sent_event) {
- manager_event(EVENT_FLAG_CALL, "MeetmeJoin",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n"
- "CallerIDnum: %s\r\n"
- "CallerIDname: %s\r\n",
- chan->name, chan->uniqueid, conf->confno,
- user->user_no,
- S_OR(user->chan->cid.cid_num, "<unknown>"),
- S_OR(user->chan->cid.cid_name, "<unknown>")
- );
- sent_event = 1;
- }
- if (!firstpass && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN)) {
- firstpass = 1;
- if (!(confflags & CONFFLAG_QUIET))
- if (!(confflags & CONFFLAG_WAITMARKED) || ((confflags & CONFFLAG_MARKEDUSER) && (conf->markedusers >= 1)))
- conf_play(chan, conf, ENTER);
- }
- conf_flush(fd, chan);
- if (!(dsp = ast_dsp_new())) {
- ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
- res = -1;
- }
- if (confflags & CONFFLAG_AGI) {
- /* Get name of AGI file to run from $(MEETME_AGI_BACKGROUND)
- or use default filename of conf-background.agi */
- agifile = pbx_builtin_getvar_helper(chan, "MEETME_AGI_BACKGROUND");
- if (!agifile)
- agifile = agifiledefault;
- if (user->dahdichannel) {
- /* Set CONFMUTE mode on DAHDI channel to mute DTMF tones */
- x = 1;
- ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
- }
- /* Find a pointer to the agi app and execute the script */
- app = pbx_findapp("agi");
- if (app) {
- char *s = ast_strdupa(agifile);
- ret = pbx_exec(chan, app, s);
- } else {
- ast_log(LOG_WARNING, "Could not find application (agi)\n");
- ret = -2;
- }
- if (user->dahdichannel) {
- /* Remove CONFMUTE mode on DAHDI channel */
- x = 0;
- ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
- }
- } else {
- if (user->dahdichannel && (confflags & CONFFLAG_STARMENU)) {
- /* Set CONFMUTE mode on DAHDI channel to mute DTMF tones when the menu is enabled */
- x = 1;
- ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
- }
- for (;;) {
- int menu_was_active = 0;
- outfd = -1;
- ms = -1;
- now = ast_tvnow();
- if (rt_schedule) {
- if (now.tv_sec % 60 == 0) {
- if (!checked) {
- if (now.tv_sec > conf->endtime) {
- ast_verbose("Quitting time...\n");
- goto outrun;
- }
- if (!announcement_played && conf->endalert) {
- if (now.tv_sec + conf->endalert > conf->endtime) {
- if (!ast_streamfile(chan, "conf-will-end-in", chan->language))
- ast_waitstream(chan, "");
- ast_say_digits(chan, (now.tv_sec + conf->endalert - conf->endtime) / 60, "", chan->language);
- if (!ast_streamfile(chan, "minutes", chan->language))
- ast_waitstream(chan, "");
- announcement_played = 1;
- }
- }
- checked = 1;
-
- }
- } else {
- checked = 0;
- }
- }
- if (user->kicktime && (user->kicktime <= now.tv_sec))
- break;
-
- to = -1;
- if (user->timelimit) {
- int minutes = 0, seconds = 0, remain = 0;
-
- to = ast_tvdiff_ms(nexteventts, now);
- if (to < 0)
- to = 0;
- time_left_ms = user->timelimit - ast_tvdiff_ms(now, user->start_time);
- if (time_left_ms < to)
- to = time_left_ms;
-
- if (time_left_ms <= 0) {
- if (user->end_sound) {
- res = ast_streamfile(chan, user->end_sound, chan->language);
- res = ast_waitstream(chan, "");
- }
- break;
- }
-
- if (!to) {
- if (time_left_ms >= 5000) {
-
- remain = (time_left_ms + 500) / 1000;
- if (remain / 60 >= 1) {
- minutes = remain / 60;
- seconds = remain % 60;
- } else {
- seconds = remain;
- }
-
- /* force the time left to round up if appropriate */
- if (user->warning_sound && user->play_warning) {
- if (!strcmp(user->warning_sound, "timeleft")) {
-
- res = ast_streamfile(chan, "vm-youhave", chan->language);
- res = ast_waitstream(chan, "");
- if (minutes) {
- res = ast_say_number(chan, minutes, AST_DIGIT_ANY, chan->language, (char *) NULL);
- res = ast_streamfile(chan, "queue-minutes", chan->language);
- res = ast_waitstream(chan, "");
- }
- if (seconds) {
- res = ast_say_number(chan, seconds, AST_DIGIT_ANY, chan->language, (char *) NULL);
- res = ast_streamfile(chan, "queue-seconds", chan->language);
- res = ast_waitstream(chan, "");
- }
- } else {
- res = ast_streamfile(chan, user->warning_sound, chan->language);
- res = ast_waitstream(chan, "");
- }
- }
- }
- if (user->warning_freq)
- nexteventts = ast_tvadd(nexteventts, ast_samp2tv(user->warning_freq, 1000));
- else
- nexteventts = ast_tvadd(user->start_time, ast_samp2tv(user->timelimit, 1000));
- }
- }
- now = ast_tvnow();
- if (timeout && now.tv_sec >= timeout)
- break;
- /* if we have just exited from the menu, and the user had a channel-driver
- volume adjustment, restore it
- */
- if (!menu_active && menu_was_active && user->listen.desired && !user->listen.actual)
- set_talk_volume(user, user->listen.desired);
- menu_was_active = menu_active;
- currentmarked = conf->markedusers;
- if (!(confflags & CONFFLAG_QUIET) &&
- (confflags & CONFFLAG_MARKEDUSER) &&
- (confflags & CONFFLAG_WAITMARKED) &&
- lastmarked == 0) {
- if (currentmarked == 1 && conf->users > 1) {
- ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, chan->language, (char *) NULL);
- if (conf->users - 1 == 1) {
- if (!ast_streamfile(chan, "conf-userwilljoin", chan->language))
- ast_waitstream(chan, "");
- } else {
- if (!ast_streamfile(chan, "conf-userswilljoin", chan->language))
- ast_waitstream(chan, "");
- }
- }
- if (conf->users == 1 && ! (confflags & CONFFLAG_MARKEDUSER))
- if (!ast_streamfile(chan, "conf-onlyperson", chan->language))
- ast_waitstream(chan, "");
- }
- /* Update the struct with the actual confflags */
- user->userflags = confflags;
- if (confflags & CONFFLAG_WAITMARKED) {
- if (currentmarked == 0) {
- if (lastmarked != 0) {
- if (!(confflags & CONFFLAG_QUIET))
- if (!ast_streamfile(chan, "conf-leaderhasleft", chan->language))
- ast_waitstream(chan, "");
- if (confflags & CONFFLAG_MARKEDEXIT) {
- if (confflags & CONFFLAG_KICK_CONTINUE)
- ret = 0;
- break;
- } else {
- dahdic.confmode = DAHDI_CONF_CONF;
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- }
- }
- if (!musiconhold && (confflags & CONFFLAG_MOH)) {
- conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
- musiconhold = 1;
- }
- } else if (currentmarked >= 1 && lastmarked == 0) {
- /* Marked user entered, so cancel timeout */
- timeout = 0;
- if (confflags & CONFFLAG_MONITOR)
- dahdic.confmode = DAHDI_CONF_CONFMON | DAHDI_CONF_LISTENER;
- else if (confflags & CONFFLAG_TALKER)
- dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
- else
- dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- goto outrun;
- }
- if (musiconhold && (confflags & CONFFLAG_MOH)) {
- ast_moh_stop(chan);
- musiconhold = 0;
- }
- if (!(confflags & CONFFLAG_QUIET) && !(confflags & CONFFLAG_MARKEDUSER)) {
- if (!ast_streamfile(chan, "conf-placeintoconf", chan->language))
- ast_waitstream(chan, "");
- conf_play(chan, conf, ENTER);
- }
- }
- }
- /* trying to add moh for single person conf */
- if ((confflags & CONFFLAG_MOH) && !(confflags & CONFFLAG_WAITMARKED)) {
- if (conf->users == 1) {
- if (!musiconhold) {
- conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
- musiconhold = 1;
- }
- } else {
- if (musiconhold) {
- ast_moh_stop(chan);
- musiconhold = 0;
- }
- }
- }
-
- /* Leave if the last marked user left */
- if (currentmarked == 0 && lastmarked != 0 && (confflags & CONFFLAG_MARKEDEXIT)) {
- if (confflags & CONFFLAG_KICK_CONTINUE)
- ret = 0;
- else
- ret = -1;
- break;
- }
-
- /* Check if my modes have changed */
- /* If I should be muted but am still talker, mute me */
- if ((user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) && (dahdic.confmode & DAHDI_CONF_TALKER)) {
- dahdic.confmode ^= DAHDI_CONF_TALKER;
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- /* Indicate user is not talking anymore - change him to unmonitored state */
- if ((confflags & (CONFFLAG_MONITORTALKER | CONFFLAG_OPTIMIZETALKER))) {
- set_user_talking(chan, conf, user, -1, confflags & CONFFLAG_MONITORTALKER);
- }
- manager_event(EVENT_FLAG_CALL, "MeetmeMute",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %i\r\n"
- "Status: on\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- }
- /* If I should be un-muted but am not talker, un-mute me */
- if (!(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) && !(confflags & CONFFLAG_MONITOR) && !(dahdic.confmode & DAHDI_CONF_TALKER)) {
- dahdic.confmode |= DAHDI_CONF_TALKER;
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
- ret = -1;
- break;
- }
- manager_event(EVENT_FLAG_CALL, "MeetmeMute",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %i\r\n"
- "Status: off\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- }
-
- if ((user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) &&
- (user->adminflags & ADMINFLAG_T_REQUEST) && !(talkreq_manager)) {
- talkreq_manager = 1;
- manager_event(EVENT_FLAG_CALL, "MeetmeTalkRequest",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %i\r\n"
- "Status: on\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- }
-
- if (!(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) &&
- !(user->adminflags & ADMINFLAG_T_REQUEST) && (talkreq_manager)) {
- talkreq_manager = 0;
- manager_event(EVENT_FLAG_CALL, "MeetmeTalkRequest",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %i\r\n"
- "Status: off\r\n",
- chan->name, chan->uniqueid, conf->confno, user->user_no);
- }
-
- /* If I have been kicked, exit the conference */
- if (user->adminflags & ADMINFLAG_KICKME) {
- /* You have been kicked. */
- if (!(confflags & CONFFLAG_QUIET) &&
- !ast_streamfile(chan, "conf-kicked", chan->language)) {
- ast_waitstream(chan, "");
- }
- ret = 0;
- break;
- }
- /* Perform an extra hangup check just in case */
- if (ast_check_hangup(chan))
- break;
- c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
- if (c) {
- char dtmfstr[2] = "";
- if (c->fds[0] != origfd || (user->dahdichannel && (c->audiohooks || c->monitor))) {
- if (using_pseudo) {
- /* Kill old pseudo */
- close(fd);
- using_pseudo = 0;
- }
- ast_debug(1, "Ooh, something swapped out under us, starting over\n");
- retrydahdi = (strcasecmp(c->tech->type, "DAHDI") || (c->audiohooks || c->monitor) ? 1 : 0);
- user->dahdichannel = !retrydahdi;
- goto dahdiretry;
- }
- if ((confflags & CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)))
- f = ast_read_noaudio(c);
- else
- f = ast_read(c);
- if (!f)
- break;
- if (f->frametype == AST_FRAME_DTMF) {
- dtmfstr[0] = f->subclass;
- dtmfstr[1] = '\0';
- }
- if ((f->frametype == AST_FRAME_VOICE) && (f->subclass == AST_FORMAT_SLINEAR)) {
- if (user->talk.actual)
- ast_frame_adjust_volume(f, user->talk.actual);
- if (confflags & (CONFFLAG_OPTIMIZETALKER | CONFFLAG_MONITORTALKER)) {
- if (user->talking == -1)
- user->talking = 0;
- res = ast_dsp_silence(dsp, f, &totalsilence);
- if (totalsilence < MEETME_DELAYDETECTTALK) {
- set_user_talking(chan, conf, user, 1, confflags & CONFFLAG_MONITORTALKER);
- }
- if (totalsilence > MEETME_DELAYDETECTENDTALK) {
- set_user_talking(chan, conf, user, 0, confflags & CONFFLAG_MONITORTALKER);
- }
- }
- if (using_pseudo) {
- /* Absolutely do _not_ use careful_write here...
- it is important that we read data from the channel
- as fast as it arrives, and feed it into the conference.
- The buffering in the pseudo channel will take care of any
- timing differences, unless they are so drastic as to lose
- audio frames (in which case carefully writing would only
- have delayed the audio even further).
- */
- /* As it turns out, we do want to use careful write. We just
- don't want to block, but we do want to at least *try*
- to write out all the samples.
- */
- if (user->talking || !(confflags & CONFFLAG_OPTIMIZETALKER)) {
- careful_write(fd, f->data, f->datalen, 0);
- }
- }
- } else if (((f->frametype == AST_FRAME_DTMF) && (f->subclass == '*') && (confflags & CONFFLAG_STARMENU)) || ((f->frametype == AST_FRAME_DTMF) && menu_active)) {
- if (confflags & CONFFLAG_PASS_DTMF)
- conf_queue_dtmf(conf, user, f);
- if (ioctl(fd, DAHDI_SETCONF, &dahdic_empty)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- ast_frfree(f);
- goto outrun;
- }
- /* if we are entering the menu, and the user has a channel-driver
- volume adjustment, clear it
- */
- if (!menu_active && user->talk.desired && !user->talk.actual)
- set_talk_volume(user, 0);
- if (musiconhold) {
- ast_moh_stop(chan);
- }
- if ((confflags & CONFFLAG_ADMIN)) {
- /* Admin menu */
- if (!menu_active) {
- menu_active = 1;
- /* Record this sound! */
- if (!ast_streamfile(chan, "conf-adminmenu", chan->language)) {
- dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- } else
- dtmf = 0;
- } else
- dtmf = f->subclass;
- if (dtmf) {
- switch(dtmf) {
- case '1': /* Un/Mute */
- menu_active = 0;
- /* for admin, change both admin and use flags */
- if (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))
- user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED);
- else
- user->adminflags |= (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED);
- if ((confflags & CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
- if (!ast_streamfile(chan, "conf-muted", chan->language))
- ast_waitstream(chan, "");
- } else {
- if (!ast_streamfile(chan, "conf-unmuted", chan->language))
- ast_waitstream(chan, "");
- }
- break;
- case '2': /* Un/Lock the Conference */
- menu_active = 0;
- if (conf->locked) {
- conf->locked = 0;
- if (!ast_streamfile(chan, "conf-unlockednow", chan->language))
- ast_waitstream(chan, "");
- } else {
- conf->locked = 1;
- if (!ast_streamfile(chan, "conf-lockednow", chan->language))
- ast_waitstream(chan, "");
- }
- break;
- case '3': /* Eject last user */
- menu_active = 0;
- usr = AST_LIST_LAST(&conf->userlist);
- if ((usr->chan->name == chan->name)||(usr->userflags & CONFFLAG_ADMIN)) {
- if (!ast_streamfile(chan, "conf-errormenu", chan->language))
- ast_waitstream(chan, "");
- } else
- usr->adminflags |= ADMINFLAG_KICKME;
- ast_stopstream(chan);
- break;
- case '4':
- tweak_listen_volume(user, VOL_DOWN);
- break;
- case '6':
- tweak_listen_volume(user, VOL_UP);
- break;
- case '7':
- tweak_talk_volume(user, VOL_DOWN);
- break;
- case '8':
- menu_active = 0;
- break;
- case '9':
- tweak_talk_volume(user, VOL_UP);
- break;
- default:
- menu_active = 0;
- /* Play an error message! */
- if (!ast_streamfile(chan, "conf-errormenu", chan->language))
- ast_waitstream(chan, "");
- break;
- }
- }
- } else {
- /* User menu */
- if (!menu_active) {
- menu_active = 1;
- if (!ast_streamfile(chan, "conf-usermenu", chan->language)) {
- dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- } else
- dtmf = 0;
- } else
- dtmf = f->subclass;
- if (dtmf) {
- switch(dtmf) {
- case '1': /* Un/Mute */
- menu_active = 0;
- /* user can only toggle the self-muted state */
- user->adminflags ^= ADMINFLAG_SELFMUTED;
- /* they can't override the admin mute state */
- if ((confflags & CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
- if (!ast_streamfile(chan, "conf-muted", chan->language))
- ast_waitstream(chan, "");
- } else {
- if (!ast_streamfile(chan, "conf-unmuted", chan->language))
- ast_waitstream(chan, "");
- }
- break;
- case '2':
- menu_active = 0;
- if (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))
- user->adminflags |= ADMINFLAG_T_REQUEST;
-
- if (user->adminflags & ADMINFLAG_T_REQUEST)
- if (!ast_streamfile(chan, "beep", chan->language))
- ast_waitstream(chan, "");
- break;
- case '4':
- tweak_listen_volume(user, VOL_DOWN);
- break;
- case '6':
- tweak_listen_volume(user, VOL_UP);
- break;
- case '7':
- tweak_talk_volume(user, VOL_DOWN);
- break;
- case '8':
- menu_active = 0;
- break;
- case '9':
- tweak_talk_volume(user, VOL_UP);
- break;
- default:
- menu_active = 0;
- if (!ast_streamfile(chan, "conf-errormenu", chan->language))
- ast_waitstream(chan, "");
- break;
- }
- }
- }
- if (musiconhold)
- conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- close(fd);
- ast_frfree(f);
- goto outrun;
- }
- conf_flush(fd, chan);
- /* Since this option could absorb dtmf meant for the previous (menu), we have to check this one last */
- } else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_EXIT_CONTEXT) && ast_exists_extension(chan, exitcontext, dtmfstr, 1, "")) {
- if (confflags & CONFFLAG_PASS_DTMF)
- conf_queue_dtmf(conf, user, f);
- if (!ast_goto_if_exists(chan, exitcontext, dtmfstr, 1)) {
- ast_debug(1, "Got DTMF %c, goto context %s\n", dtmfstr[0], exitcontext);
- ret = 0;
- ast_frfree(f);
- break;
- } else {
- ast_debug(2, "Exit by single digit did not work in meetme. Extension %s does not exist in context %s\n", dtmfstr, exitcontext);
- }
- } else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_KEYEXIT) && (strchr(exitkeys, f->subclass))) {
- pbx_builtin_setvar_helper(chan, "MEETME_EXIT_KEY", dtmfstr);
-
- if (confflags & CONFFLAG_PASS_DTMF)
- conf_queue_dtmf(conf, user, f);
- ret = 0;
- ast_frfree(f);
- break;
- } else if ((f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END)
- && confflags & CONFFLAG_PASS_DTMF) {
- conf_queue_dtmf(conf, user, f);
- } else if ((confflags & CONFFLAG_SLA_STATION) && f->frametype == AST_FRAME_CONTROL) {
- switch (f->subclass) {
- case AST_CONTROL_HOLD:
- sla_queue_event_conf(SLA_EVENT_HOLD, chan, conf);
- break;
- default:
- break;
- }
- } else if (f->frametype == AST_FRAME_NULL) {
- /* Ignore NULL frames. It is perfectly normal to get these if the person is muted. */
- } else {
- ast_debug(1,
- "Got unrecognized frame on channel %s, f->frametype=%d,f->subclass=%d\n",
- chan->name, f->frametype, f->subclass);
- }
- ast_frfree(f);
- } else if (outfd > -1) {
- res = read(outfd, buf, CONF_SIZE);
- if (res > 0) {
- memset(&fr, 0, sizeof(fr));
- fr.frametype = AST_FRAME_VOICE;
- fr.subclass = AST_FORMAT_SLINEAR;
- fr.datalen = res;
- fr.samples = res / 2;
- fr.data = buf;
- fr.offset = AST_FRIENDLY_OFFSET;
- if (!user->listen.actual &&
- ((confflags & CONFFLAG_MONITOR) ||
- (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) ||
- (!user->talking && (confflags & CONFFLAG_OPTIMIZETALKER))
- )) {
- int index;
- for (index = 0; index < AST_FRAME_BITS; index++)
- if (chan->rawwriteformat & (1 << index))
- break;
- if (index >= AST_FRAME_BITS)
- goto bailoutandtrynormal;
- ast_mutex_lock(&conf->listenlock);
- if (!conf->transframe[index]) {
- if (conf->origframe) {
- if (musiconhold && !ast_dsp_silence(dsp, conf->origframe, &confsilence) && confsilence < MEETME_DELAYDETECTTALK) {
- ast_moh_stop(chan);
- mohtempstopped = 1;
- }
- if (!conf->transpath[index])
- conf->transpath[index] = ast_translator_build_path((1 << index), AST_FORMAT_SLINEAR);
- if (conf->transpath[index]) {
- conf->transframe[index] = ast_translate(conf->transpath[index], conf->origframe, 0);
- if (!conf->transframe[index])
- conf->transframe[index] = &ast_null_frame;
- }
- }
- }
- if (conf->transframe[index]) {
- if ((conf->transframe[index]->frametype != AST_FRAME_NULL) &&
- can_write(chan, confflags)) {
- struct ast_frame *cur;
- /* the translator may have returned a list of frames, so
- write each one onto the channel
- */
- for (cur = conf->transframe[index]; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
- if (ast_write(chan, cur)) {
- ast_log(LOG_WARNING, "Unable to write frame to channel %s\n", chan->name);
- break;
- }
- }
- if (musiconhold && mohtempstopped && confsilence > MEETME_DELAYDETECTENDTALK) {
- mohtempstopped = 0;
- ast_moh_start(chan, NULL, NULL);
- }
- }
- } else {
- ast_mutex_unlock(&conf->listenlock);
- goto bailoutandtrynormal;
- }
- ast_mutex_unlock(&conf->listenlock);
- } else {
- bailoutandtrynormal:
- if (musiconhold && !ast_dsp_silence(dsp, &fr, &confsilence) && confsilence < MEETME_DELAYDETECTTALK) {
- ast_moh_stop(chan);
- mohtempstopped = 1;
- }
- if (user->listen.actual)
- ast_frame_adjust_volume(&fr, user->listen.actual);
- if (can_write(chan, confflags) && ast_write(chan, &fr) < 0) {
- ast_log(LOG_WARNING, "Unable to write frame to channel %s\n", chan->name);
- }
- if (musiconhold && mohtempstopped && confsilence > MEETME_DELAYDETECTENDTALK) {
- mohtempstopped = 0;
- ast_moh_start(chan, NULL, NULL);
- }
- }
- } else
- ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
- }
- lastmarked = currentmarked;
- }
- }
- if (musiconhold)
- ast_moh_stop(chan);
-
- if (using_pseudo)
- close(fd);
- else {
- /* Take out of conference */
- dahdic.chan = 0;
- dahdic.confno = 0;
- dahdic.confmode = 0;
- if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
- ast_log(LOG_WARNING, "Error setting conference\n");
- }
- }
- reset_volumes(user);
- if (!(confflags & CONFFLAG_QUIET) && !(confflags & CONFFLAG_MONITOR) && !(confflags & CONFFLAG_ADMIN))
- conf_play(chan, conf, LEAVE);
- if (!(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW)) && conf->users > 1) {
- struct announce_listitem *item;
- if (!(item = ao2_alloc(sizeof(*item), NULL)))
- return -1;
- ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
- ast_copy_string(item->language, chan->language, sizeof(item->language));
- item->confchan = conf->chan;
- item->confusers = conf->users;
- item->announcetype = CONF_HASLEFT;
- ast_mutex_lock(&conf->announcelistlock);
- AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
- ast_cond_signal(&conf->announcelist_addition);
- ast_mutex_unlock(&conf->announcelistlock);
- } else if (!(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW)) && conf->users == 1) {
- /* Last person is leaving, so no reason to try and announce, but should delete the name recording */
- ast_filedelete(user->namerecloc, NULL);
- }
- outrun:
- AST_LIST_LOCK(&confs);
- if (dsp)
- ast_dsp_free(dsp);
-
- if (user->user_no) { /* Only cleanup users who really joined! */
- now = ast_tvnow();
- hr = (now.tv_sec - user->jointime) / 3600;
- min = ((now.tv_sec - user->jointime) % 3600) / 60;
- sec = (now.tv_sec - user->jointime) % 60;
- if (sent_event) {
- manager_event(EVENT_FLAG_CALL, "MeetmeLeave",
- "Channel: %s\r\n"
- "Uniqueid: %s\r\n"
- "Meetme: %s\r\n"
- "Usernum: %d\r\n"
- "CallerIDNum: %s\r\n"
- "CallerIDName: %s\r\n"
- "Duration: %ld\r\n",
- chan->name, chan->uniqueid, conf->confno,
- user->user_no,
- S_OR(user->chan->cid.cid_num, "<unknown>"),
- S_OR(user->chan->cid.cid_name, "<unknown>"),
- (long)(now.tv_sec - user->jointime));
- }
- if (setusercount) {
- conf->users--;
- if (rt_log_members) {
- /* Update table */
- snprintf(members, sizeof(members), "%d", conf->users);
- ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
- }
- if (confflags & CONFFLAG_MARKEDUSER)
- conf->markedusers--;
- }
- /* Remove ourselves from the list */
- AST_LIST_REMOVE(&conf->userlist, user, list);
- /* Change any states */
- if (!conf->users)
- ast_devstate_changed(AST_DEVICE_NOT_INUSE, "meetme:%s", conf->confno);
-
- /* Return the number of seconds the user was in the conf */
- snprintf(meetmesecs, sizeof(meetmesecs), "%d", (int) (time(NULL) - user->jointime));
- pbx_builtin_setvar_helper(chan, "MEETMESECS", meetmesecs);
- }
- ast_free(user);
- AST_LIST_UNLOCK(&confs);
- return ret;
- }
- static struct ast_conference *find_conf_realtime(struct ast_channel *chan, char *confno, int make, int dynamic,
- char *dynamic_pin, size_t pin_buf_len, int refcount, struct ast_flags *confflags,
- char *optargs[], int *too_early)
- {
- struct ast_variable *var;
- struct ast_conference *cnf;
- *too_early = 0;
- /* Check first in the conference list */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strcmp(confno, cnf->confno))
- break;
- }
- if (cnf) {
- cnf->refcount += refcount;
- }
- AST_LIST_UNLOCK(&confs);
- if (!cnf) {
- char *pin = NULL, *pinadmin = NULL; /* For temp use */
- int maxusers = 0;
- struct timeval now;
- char currenttime[19] = "";
- char eatime[19] = "";
- char useropts[32] = "";
- char adminopts[32] = "";
- struct ast_tm tm, etm;
- struct timeval endtime = { .tv_sec = 0 };
- if (rt_schedule) {
- now = ast_tvnow();
- ast_localtime(&now, &tm, NULL);
- ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
- ast_debug(1, "Looking for conference %s that starts after %s\n", confno, eatime);
- var = ast_load_realtime("meetme", "confno",
- confno, "starttime <= ", currenttime, "endtime >= ",
- currenttime, NULL);
- if (!var && fuzzystart) {
- now = ast_tvnow();
- now.tv_sec += fuzzystart;
- ast_localtime(&now, &tm, NULL);
- ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
- var = ast_load_realtime("meetme", "confno",
- confno, "starttime <= ", currenttime, "endtime >= ",
- currenttime, NULL);
- }
- if (!var && earlyalert) {
- now = ast_tvnow();
- now.tv_sec += earlyalert;
- ast_localtime(&now, &etm, NULL);
- ast_strftime(eatime, sizeof(eatime), DATE_FORMAT, &etm);
- var = ast_load_realtime("meetme", "confno",
- confno, "starttime <= ", eatime, "endtime >= ",
- currenttime, NULL);
- if (var)
- *too_early = 1;
- }
- } else
- var = ast_load_realtime("meetme", "confno", confno, NULL);
- if (!var)
- return NULL;
- if (rt_schedule && *too_early) {
- /* Announce that the caller is early and exit */
- if (!ast_streamfile(chan, "conf-has-not-started", chan->language))
- ast_waitstream(chan, "");
- ast_variables_destroy(var);
- return NULL;
- }
- while (var) {
- if (!strcasecmp(var->name, "pin")) {
- pin = ast_strdupa(var->value);
- } else if (!strcasecmp(var->name, "adminpin")) {
- pinadmin = ast_strdupa(var->value);
- } else if (!strcasecmp(var->name, "opts")) {
- ast_copy_string(useropts, var->value, sizeof(useropts));
- } else if (!strcasecmp(var->name, "maxusers")) {
- maxusers = atoi(var->value);
- } else if (!strcasecmp(var->name, "adminopts")) {
- ast_copy_string(adminopts, var->value, sizeof(adminopts));
- } else if (!strcasecmp(var->name, "endtime")) {
- union {
- struct ast_tm atm;
- struct tm tm;
- } t = { { 0, }, };
- strptime(var->value, "%Y-%m-%d %H:%M:%S", &t.tm);
- /* strptime does not determine if a time is
- * in DST or not. Set tm_isdst to -1 to
- * allow ast_mktime to adjust for DST
- * if needed */
- t.tm.tm_isdst = -1;
- endtime = ast_mktime(&t.atm, NULL);
- }
- var = var->next;
- }
- ast_variables_destroy(var);
- cnf = build_conf(confno, pin ? pin : "", pinadmin ? pinadmin : "", make, dynamic, refcount, chan);
- if (cnf) {
- cnf->maxusers = maxusers;
- cnf->endalert = endalert;
- cnf->endtime = endtime.tv_sec;
- }
- }
- if (cnf) {
- if (confflags && !cnf->chan &&
- !ast_test_flag(confflags, CONFFLAG_QUIET) &&
- ast_test_flag(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW)) {
- ast_log(LOG_WARNING, "No DAHDI channel available for conference, user introduction disabled (is chan_dahdi loaded?)\n");
- ast_clear_flag(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW);
- }
-
- if (confflags && !cnf->chan &&
- ast_test_flag(confflags, CONFFLAG_RECORDCONF)) {
- ast_log(LOG_WARNING, "No DAHDI channel available for conference, conference recording disabled (is chan_dahdi loaded?)\n");
- ast_clear_flag(confflags, CONFFLAG_RECORDCONF);
- }
- }
- return cnf;
- }
- static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, int make, int dynamic,
- char *dynamic_pin, size_t pin_buf_len, int refcount, struct ast_flags *confflags)
- {
- struct ast_config *cfg;
- struct ast_variable *var;
- struct ast_flags config_flags = { 0 };
- struct ast_conference *cnf;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(confno);
- AST_APP_ARG(pin);
- AST_APP_ARG(pinadmin);
- );
- /* Check first in the conference list */
- ast_debug(1, "The requested confno is '%s'?\n", confno);
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- ast_debug(3, "Does conf %s match %s?\n", confno, cnf->confno);
- if (!strcmp(confno, cnf->confno))
- break;
- }
- if (cnf) {
- cnf->refcount += refcount;
- }
- AST_LIST_UNLOCK(&confs);
- if (!cnf) {
- if (dynamic) {
- /* No need to parse meetme.conf */
- ast_debug(1, "Building dynamic conference '%s'\n", confno);
- if (dynamic_pin) {
- if (dynamic_pin[0] == 'q') {
- /* Query the user to enter a PIN */
- if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, pin_buf_len - 1, 0) < 0)
- return NULL;
- }
- cnf = build_conf(confno, dynamic_pin, "", make, dynamic, refcount, chan);
- } else {
- cnf = build_conf(confno, "", "", make, dynamic, refcount, chan);
- }
- } else {
- /* Check the config */
- cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
- if (!cfg) {
- ast_log(LOG_WARNING, "No %s file :(\n", CONFIG_FILE_NAME);
- return NULL;
- }
- for (var = ast_variable_browse(cfg, "rooms"); var; var = var->next) {
- char parse[MAX_SETTINGS];
- if (strcasecmp(var->name, "conf"))
- continue;
- ast_copy_string(parse, var->value, sizeof(parse));
- AST_STANDARD_APP_ARGS(args, parse);
- ast_debug(3, "Will conf %s match %s?\n", confno, args.confno);
- if (!strcasecmp(args.confno, confno)) {
- /* Bingo it's a valid conference */
- cnf = build_conf(args.confno,
- S_OR(args.pin, ""),
- S_OR(args.pinadmin, ""),
- make, dynamic, refcount, chan);
- break;
- }
- }
- if (!var) {
- ast_debug(1, "%s isn't a valid conference\n", confno);
- }
- ast_config_destroy(cfg);
- }
- } else if (dynamic_pin) {
- /* Correct for the user selecting 'D' instead of 'd' to have
- someone join into a conference that has already been created
- with a pin. */
- if (dynamic_pin[0] == 'q')
- dynamic_pin[0] = '\0';
- }
- if (cnf) {
- if (confflags && !cnf->chan &&
- !ast_test_flag(confflags, CONFFLAG_QUIET) &&
- ast_test_flag(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW)) {
- ast_log(LOG_WARNING, "No DAHDI channel available for conference, user introduction disabled (is chan_dahdi loaded?)\n");
- ast_clear_flag(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW);
- }
-
- if (confflags && !cnf->chan &&
- ast_test_flag(confflags, CONFFLAG_RECORDCONF)) {
- ast_log(LOG_WARNING, "No DAHDI channel available for conference, conference recording disabled (is chan_dahdi loaded?)\n");
- ast_clear_flag(confflags, CONFFLAG_RECORDCONF);
- }
- }
- return cnf;
- }
- /*! \brief The MeetmeCount application */
- static int count_exec(struct ast_channel *chan, void *data)
- {
- int res = 0;
- struct ast_conference *conf;
- int count;
- char *localdata;
- char val[80] = "0";
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(confno);
- AST_APP_ARG(varname);
- );
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "MeetMeCount requires an argument (conference number)\n");
- return -1;
- }
-
- if (!(localdata = ast_strdupa(data)))
- return -1;
- AST_STANDARD_APP_ARGS(args, localdata);
-
- conf = find_conf(chan, args.confno, 0, 0, NULL, 0, 1, NULL);
- if (conf) {
- count = conf->users;
- dispose_conf(conf);
- conf = NULL;
- } else
- count = 0;
- if (!ast_strlen_zero(args.varname)) {
- /* have var so load it and exit */
- snprintf(val, sizeof(val), "%d", count);
- pbx_builtin_setvar_helper(chan, args.varname, val);
- } else {
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
- res = ast_say_number(chan, count, "", chan->language, (char *) NULL); /* Needs gender */
- }
- return res;
- }
- /*! \brief The meetme() application */
- static int conf_exec(struct ast_channel *chan, void *data)
- {
- int res = -1;
- char confno[MAX_CONFNUM] = "";
- int allowretry = 0;
- int retrycnt = 0;
- struct ast_conference *cnf = NULL;
- struct ast_flags confflags = {0}, config_flags = { 0 };
- int dynamic = 0;
- int empty = 0, empty_no_pin = 0;
- int always_prompt = 0;
- char *notdata, *info, the_pin[MAX_PIN] = "";
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(confno);
- AST_APP_ARG(options);
- AST_APP_ARG(pin);
- );
- char *optargs[OPT_ARG_ARRAY_SIZE] = { NULL, };
- if (ast_strlen_zero(data)) {
- allowretry = 1;
- notdata = "";
- } else {
- notdata = data;
- }
-
- if (chan->_state != AST_STATE_UP)
- ast_answer(chan);
- info = ast_strdupa(notdata);
- AST_STANDARD_APP_ARGS(args, info);
- if (args.confno) {
- ast_copy_string(confno, args.confno, sizeof(confno));
- if (ast_strlen_zero(confno)) {
- allowretry = 1;
- }
- }
-
- if (args.pin)
- ast_copy_string(the_pin, args.pin, sizeof(the_pin));
- if (args.options) {
- ast_app_parse_options(meetme_opts, &confflags, optargs, args.options);
- dynamic = ast_test_flag(&confflags, CONFFLAG_DYNAMIC | CONFFLAG_DYNAMICPIN);
- if (ast_test_flag(&confflags, CONFFLAG_DYNAMICPIN) && !args.pin)
- strcpy(the_pin, "q");
- empty = ast_test_flag(&confflags, CONFFLAG_EMPTY | CONFFLAG_EMPTYNOPIN);
- empty_no_pin = ast_test_flag(&confflags, CONFFLAG_EMPTYNOPIN);
- always_prompt = ast_test_flag(&confflags, CONFFLAG_ALWAYSPROMPT | CONFFLAG_DYNAMICPIN);
- }
- do {
- if (retrycnt > 3)
- allowretry = 0;
- if (empty) {
- int i;
- struct ast_config *cfg;
- struct ast_variable *var;
- int confno_int;
- /* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */
- if ((empty_no_pin) || (!dynamic)) {
- cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
- if (cfg) {
- var = ast_variable_browse(cfg, "rooms");
- while (var) {
- char parse[MAX_SETTINGS], *stringp = parse, *confno_tmp;
- if (!strcasecmp(var->name, "conf")) {
- int found = 0;
- ast_copy_string(parse, var->value, sizeof(parse));
- confno_tmp = strsep(&stringp, "|,");
- if (!dynamic) {
- /* For static: run through the list and see if this conference is empty */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strcmp(confno_tmp, cnf->confno)) {
- /* The conference exists, therefore it's not empty */
- found = 1;
- break;
- }
- }
- AST_LIST_UNLOCK(&confs);
- if (!found) {
- /* At this point, we have a confno_tmp (static conference) that is empty */
- if ((empty_no_pin && ast_strlen_zero(stringp)) || (!empty_no_pin)) {
- /* Case 1: empty_no_pin and pin is nonexistent (NULL)
- * Case 2: empty_no_pin and pin is blank (but not NULL)
- * Case 3: not empty_no_pin
- */
- ast_copy_string(confno, confno_tmp, sizeof(confno));
- break;
- /* XXX the map is not complete (but we do have a confno) */
- }
- }
- }
- }
- var = var->next;
- }
- ast_config_destroy(cfg);
- }
- }
- /* Select first conference number not in use */
- if (ast_strlen_zero(confno) && dynamic) {
- AST_LIST_LOCK(&confs);
- for (i = 0; i < ARRAY_LEN(conf_map); i++) {
- if (!conf_map[i]) {
- snprintf(confno, sizeof(confno), "%d", i);
- conf_map[i] = 1;
- break;
- }
- }
- AST_LIST_UNLOCK(&confs);
- }
- /* Not found? */
- if (ast_strlen_zero(confno)) {
- res = ast_streamfile(chan, "conf-noempty", chan->language);
- if (!res)
- ast_waitstream(chan, "");
- } else {
- if (sscanf(confno, "%30d", &confno_int) == 1) {
- if (!ast_test_flag(&confflags, CONFFLAG_QUIET)) {
- res = ast_streamfile(chan, "conf-enteringno", chan->language);
- if (!res) {
- ast_waitstream(chan, "");
- res = ast_say_digits(chan, confno_int, "", chan->language);
- }
- }
- } else {
- ast_log(LOG_ERROR, "Could not scan confno '%s'\n", confno);
- }
- }
- }
- while (allowretry && (ast_strlen_zero(confno)) && (++retrycnt < 4)) {
- /* Prompt user for conference number */
- res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0);
- if (res < 0) {
- /* Don't try to validate when we catch an error */
- confno[0] = '\0';
- allowretry = 0;
- break;
- }
- }
- if (!ast_strlen_zero(confno)) {
- /* Check the validity of the conference */
- cnf = find_conf(chan, confno, 1, dynamic, the_pin,
- sizeof(the_pin), 1, &confflags);
- if (!cnf) {
- int too_early = 0;
- cnf = find_conf_realtime(chan, confno, 1, dynamic,
- the_pin, sizeof(the_pin), 1, &confflags, optargs, &too_early);
- if (rt_schedule && too_early)
- allowretry = 0;
- }
- if (!cnf) {
- if (allowretry) {
- confno[0] = '\0';
- res = ast_streamfile(chan, "conf-invalid", chan->language);
- if (!res)
- ast_waitstream(chan, "");
- res = -1;
- }
- } else {
- if ((!ast_strlen_zero(cnf->pin) &&
- !ast_test_flag(&confflags, CONFFLAG_ADMIN)) ||
- (!ast_strlen_zero(cnf->pinadmin) &&
- ast_test_flag(&confflags, CONFFLAG_ADMIN))) {
- char pin[MAX_PIN] = "";
- int j;
- /* Allow the pin to be retried up to 3 times */
- for (j = 0; j < 3; j++) {
- if (*the_pin && (always_prompt == 0)) {
- ast_copy_string(pin, the_pin, sizeof(pin));
- res = 0;
- } else {
- /* Prompt user for pin if pin is required */
- res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
- }
- if (res >= 0) {
- if (!strcasecmp(pin, cnf->pin) ||
- (!ast_strlen_zero(cnf->pinadmin) &&
- !strcasecmp(pin, cnf->pinadmin))) {
- /* Pin correct */
- allowretry = 0;
- if (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin))
- ast_set_flag(&confflags, CONFFLAG_ADMIN);
- /* Run the conference */
- res = conf_run(chan, cnf, confflags.flags, optargs);
- break;
- } else {
- /* Pin invalid */
- if (!ast_streamfile(chan, "conf-invalidpin", chan->language)) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- }
- else {
- ast_log(LOG_WARNING, "Couldn't play invalid pin msg!\n");
- break;
- }
- if (res < 0)
- break;
- pin[0] = res;
- pin[1] = '\0';
- res = -1;
- if (allowretry)
- confno[0] = '\0';
- }
- } else {
- /* failed when getting the pin */
- res = -1;
- allowretry = 0;
- /* see if we need to get rid of the conference */
- break;
- }
- /* Don't retry pin with a static pin */
- if (*the_pin && (always_prompt == 0)) {
- break;
- }
- }
- } else {
- /* No pin required */
- allowretry = 0;
- /* Run the conference */
- res = conf_run(chan, cnf, confflags.flags, optargs);
- }
- dispose_conf(cnf);
- cnf = NULL;
- }
- }
- } while (allowretry);
- if (cnf)
- dispose_conf(cnf);
-
- return res;
- }
- static struct ast_conf_user *find_user(struct ast_conference *conf, char *callerident)
- {
- struct ast_conf_user *user = NULL;
- int cid;
-
- sscanf(callerident, "%30i", &cid);
- if (conf && callerident) {
- AST_LIST_TRAVERSE(&conf->userlist, user, list) {
- if (cid == user->user_no)
- return user;
- }
- }
- return NULL;
- }
- /*! \brief The MeetMeadmin application */
- /* MeetMeAdmin(confno, command, caller) */
- static int admin_exec(struct ast_channel *chan, void *data) {
- char *params;
- struct ast_conference *cnf;
- struct ast_conf_user *user = NULL;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(confno);
- AST_APP_ARG(command);
- AST_APP_ARG(user);
- );
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "MeetMeAdmin requires an argument!\n");
- return -1;
- }
- params = ast_strdupa(data);
- AST_STANDARD_APP_ARGS(args, params);
- if (!args.command) {
- ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n");
- return -1;
- }
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strcmp(cnf->confno, args.confno))
- break;
- }
- if (!cnf) {
- ast_log(LOG_WARNING, "Conference number '%s' not found!\n", args.confno);
- AST_LIST_UNLOCK(&confs);
- return 0;
- }
- ast_atomic_fetchadd_int(&cnf->refcount, 1);
- if (args.user)
- user = find_user(cnf, args.user);
- switch (*args.command) {
- case 76: /* L: Lock */
- cnf->locked = 1;
- break;
- case 108: /* l: Unlock */
- cnf->locked = 0;
- break;
- case 75: /* K: kick all users */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- user->adminflags |= ADMINFLAG_KICKME;
- break;
- case 101: /* e: Eject last user*/
- user = AST_LIST_LAST(&cnf->userlist);
- if (!(user->userflags & CONFFLAG_ADMIN))
- user->adminflags |= ADMINFLAG_KICKME;
- else
- ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
- break;
- case 77: /* M: Mute */
- if (user) {
- user->adminflags |= ADMINFLAG_MUTED;
- } else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 78: /* N: Mute all (non-admin) users */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
- if (!(user->userflags & CONFFLAG_ADMIN))
- user->adminflags |= ADMINFLAG_MUTED;
- }
- break;
- case 109: /* m: Unmute */
- if (user) {
- user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
- } else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 110: /* n: Unmute all users */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
- break;
- case 107: /* k: Kick user */
- if (user)
- user->adminflags |= ADMINFLAG_KICKME;
- else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 118: /* v: Lower all users listen volume */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- tweak_listen_volume(user, VOL_DOWN);
- break;
- case 86: /* V: Raise all users listen volume */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- tweak_listen_volume(user, VOL_UP);
- break;
- case 115: /* s: Lower all users speaking volume */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- tweak_talk_volume(user, VOL_DOWN);
- break;
- case 83: /* S: Raise all users speaking volume */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- tweak_talk_volume(user, VOL_UP);
- break;
- case 82: /* R: Reset all volume levels */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list)
- reset_volumes(user);
- break;
- case 114: /* r: Reset user's volume level */
- if (user)
- reset_volumes(user);
- else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 85: /* U: Raise user's listen volume */
- if (user)
- tweak_listen_volume(user, VOL_UP);
- else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 117: /* u: Lower user's listen volume */
- if (user)
- tweak_listen_volume(user, VOL_DOWN);
- else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 84: /* T: Raise user's talk volume */
- if (user)
- tweak_talk_volume(user, VOL_UP);
- else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- case 116: /* t: Lower user's talk volume */
- if (user)
- tweak_talk_volume(user, VOL_DOWN);
- else
- ast_log(LOG_NOTICE, "Specified User not found!\n");
- break;
- }
- AST_LIST_UNLOCK(&confs);
- dispose_conf(cnf);
-
- return 0;
- }
- /*--- channel_admin_exec: The MeetMeChannelAdmin application */
- /* MeetMeChannelAdmin(channel, command) */
- static int channel_admin_exec(struct ast_channel *chan, void *data) {
- char *params;
- struct ast_conference *conf = NULL;
- struct ast_conf_user *user = NULL;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(channel);
- AST_APP_ARG(command);
- );
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "MeetMeChannelAdmin requires two arguments!\n");
- return -1;
- }
-
- params = ast_strdupa(data);
- AST_STANDARD_APP_ARGS(args, params);
- if (!args.channel) {
- ast_log(LOG_WARNING, "MeetMeChannelAdmin requires a channel name!\n");
- return -1;
- }
- if (!args.command) {
- ast_log(LOG_WARNING, "MeetMeChannelAdmin requires a command!\n");
- return -1;
- }
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, conf, list) {
- AST_LIST_TRAVERSE(&conf->userlist, user, list) {
- if (!strcmp(user->chan->name, args.channel))
- break;
- }
- }
-
- if (!user) {
- ast_log(LOG_NOTICE, "Specified user (%s) not found\n", args.channel);
- AST_LIST_UNLOCK(&confs);
- return 0;
- }
-
- /* perform the specified action */
- switch (*args.command) {
- case 77: /* M: Mute */
- user->adminflags |= ADMINFLAG_MUTED;
- break;
- case 109: /* m: Unmute */
- user->adminflags &= ~ADMINFLAG_MUTED;
- break;
- case 107: /* k: Kick user */
- user->adminflags |= ADMINFLAG_KICKME;
- break;
- default: /* unknown command */
- ast_log(LOG_WARNING, "Unknown MeetMeChannelAdmin command '%s'\n", args.command);
- break;
- }
- AST_LIST_UNLOCK(&confs);
-
- return 0;
- }
- static int meetmemute(struct mansession *s, const struct message *m, int mute)
- {
- struct ast_conference *conf;
- struct ast_conf_user *user;
- const char *confid = astman_get_header(m, "Meetme");
- char *userid = ast_strdupa(astman_get_header(m, "Usernum"));
- int userno;
- if (ast_strlen_zero(confid)) {
- astman_send_error(s, m, "Meetme conference not specified");
- return 0;
- }
- if (ast_strlen_zero(userid)) {
- astman_send_error(s, m, "Meetme user number not specified");
- return 0;
- }
- userno = strtoul(userid, &userid, 10);
- if (*userid) {
- astman_send_error(s, m, "Invalid user number");
- return 0;
- }
- /* Look in the conference list */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, conf, list) {
- if (!strcmp(confid, conf->confno))
- break;
- }
- if (!conf) {
- AST_LIST_UNLOCK(&confs);
- astman_send_error(s, m, "Meetme conference does not exist");
- return 0;
- }
- AST_LIST_TRAVERSE(&conf->userlist, user, list)
- if (user->user_no == userno)
- break;
- if (!user) {
- AST_LIST_UNLOCK(&confs);
- astman_send_error(s, m, "User number not found");
- return 0;
- }
- if (mute)
- user->adminflags |= ADMINFLAG_MUTED; /* request user muting */
- else
- user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST); /* request user unmuting */
- AST_LIST_UNLOCK(&confs);
- ast_log(LOG_NOTICE, "Requested to %smute conf %s user %d userchan %s uniqueid %s\n", mute ? "" : "un", conf->confno, user->user_no, user->chan->name, user->chan->uniqueid);
- astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
- return 0;
- }
- static int action_meetmemute(struct mansession *s, const struct message *m)
- {
- return meetmemute(s, m, 1);
- }
- static int action_meetmeunmute(struct mansession *s, const struct message *m)
- {
- return meetmemute(s, m, 0);
- }
- static char mandescr_meetmelist[] =
- "Description: Lists all users in a particular MeetMe conference.\n"
- "MeetmeList will follow as separate events, followed by a final event called\n"
- "MeetmeListComplete.\n"
- "Variables:\n"
- " *ActionId: <id>\n"
- " *Conference: <confno>\n";
- static int action_meetmelist(struct mansession *s, const struct message *m)
- {
- const char *actionid = astman_get_header(m, "ActionID");
- const char *conference = astman_get_header(m, "Conference");
- char idText[80] = "";
- struct ast_conference *cnf;
- struct ast_conf_user *user;
- int total = 0;
- if (!ast_strlen_zero(actionid))
- snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
- if (AST_LIST_EMPTY(&confs)) {
- astman_send_error(s, m, "No active conferences.");
- return 0;
- }
- astman_send_listack(s, m, "Meetme user list will follow", "start");
- /* Find the right conference */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, cnf, list) {
- /* If we ask for one particular, and this isn't it, skip it */
- if (!ast_strlen_zero(conference) && strcmp(cnf->confno, conference))
- continue;
- /* Show all the users */
- AST_LIST_TRAVERSE(&cnf->userlist, user, list) {
- total++;
- astman_append(s,
- "Event: MeetmeList\r\n"
- "%s"
- "Conference: %s\r\n"
- "UserNumber: %d\r\n"
- "CallerIDNum: %s\r\n"
- "CallerIDName: %s\r\n"
- "Channel: %s\r\n"
- "Admin: %s\r\n"
- "Role: %s\r\n"
- "MarkedUser: %s\r\n"
- "Muted: %s\r\n"
- "Talking: %s\r\n"
- "\r\n",
- idText,
- cnf->confno,
- user->user_no,
- S_OR(user->chan->cid.cid_num, "<unknown>"),
- S_OR(user->chan->cid.cid_name, "<no name>"),
- user->chan->name,
- user->userflags & CONFFLAG_ADMIN ? "Yes" : "No",
- user->userflags & CONFFLAG_MONITOR ? "Listen only" : user->userflags & CONFFLAG_TALKER ? "Talk only" : "Talk and listen",
- user->userflags & CONFFLAG_MARKEDUSER ? "Yes" : "No",
- user->adminflags & ADMINFLAG_MUTED ? "By admin" : user->adminflags & ADMINFLAG_SELFMUTED ? "By self" : "No",
- user->talking > 0 ? "Yes" : user->talking == 0 ? "No" : "Not monitored");
- }
- }
- AST_LIST_UNLOCK(&confs);
- /* Send final confirmation */
- astman_append(s,
- "Event: MeetmeListComplete\r\n"
- "EventList: Complete\r\n"
- "ListItems: %d\r\n"
- "%s"
- "\r\n", total, idText);
- return 0;
- }
- static void *recordthread(void *args)
- {
- struct ast_conference *cnf = args;
- struct ast_frame *f = NULL;
- int flags;
- struct ast_filestream *s = NULL;
- int res = 0;
- int x;
- const char *oldrecordingfilename = NULL;
- if (!cnf || !cnf->lchan) {
- pthread_exit(0);
- }
- ast_stopstream(cnf->lchan);
- flags = O_CREAT | O_TRUNC | O_WRONLY;
- cnf->recording = MEETME_RECORD_ACTIVE;
- while (ast_waitfor(cnf->lchan, -1) > -1) {
- if (cnf->recording == MEETME_RECORD_TERMINATE) {
- AST_LIST_LOCK(&confs);
- AST_LIST_UNLOCK(&confs);
- break;
- }
- if (!s && cnf->recordingfilename && (cnf->recordingfilename != oldrecordingfilename)) {
- s = ast_writefile(cnf->recordingfilename, cnf->recordingformat, NULL, flags, 0, AST_FILE_MODE);
- oldrecordingfilename = cnf->recordingfilename;
- }
-
- f = ast_read(cnf->lchan);
- if (!f) {
- res = -1;
- break;
- }
- if (f->frametype == AST_FRAME_VOICE) {
- ast_mutex_lock(&cnf->listenlock);
- for (x = 0; x < AST_FRAME_BITS; x++) {
- /* Free any translations that have occured */
- if (cnf->transframe[x]) {
- ast_frfree(cnf->transframe[x]);
- cnf->transframe[x] = NULL;
- }
- }
- if (cnf->origframe)
- ast_frfree(cnf->origframe);
- cnf->origframe = ast_frdup(f);
- ast_mutex_unlock(&cnf->listenlock);
- if (s)
- res = ast_writestream(s, f);
- if (res) {
- ast_frfree(f);
- break;
- }
- }
- ast_frfree(f);
- }
- cnf->recording = MEETME_RECORD_OFF;
- if (s)
- ast_closestream(s);
-
- pthread_exit(0);
- }
- /*! \brief Callback for devicestate providers */
- static enum ast_device_state meetmestate(const char *data)
- {
- struct ast_conference *conf;
- /* Find conference */
- AST_LIST_LOCK(&confs);
- AST_LIST_TRAVERSE(&confs, conf, list) {
- if (!strcmp(data, conf->confno))
- break;
- }
- AST_LIST_UNLOCK(&confs);
- if (!conf)
- return AST_DEVICE_INVALID;
- /* SKREP to fill */
- if (!conf->users)
- return AST_DEVICE_NOT_INUSE;
- return AST_DEVICE_INUSE;
- }
- static void load_config_meetme(void)
- {
- struct ast_config *cfg;
- struct ast_flags config_flags = { 0 };
- const char *val;
- if (!(cfg = ast_config_load(CONFIG_FILE_NAME, config_flags)))
- return;
- audio_buffers = DEFAULT_AUDIO_BUFFERS;
- /* Scheduling support is off by default */
- rt_schedule = 0;
- fuzzystart = 0;
- earlyalert = 0;
- endalert = 0;
- /* Logging of participants defaults to ON for compatibility reasons */
- rt_log_members = 1;
- if ((val = ast_variable_retrieve(cfg, "general", "audiobuffers"))) {
- if ((sscanf(val, "%30d", &audio_buffers) != 1)) {
- ast_log(LOG_WARNING, "audiobuffers setting must be a number, not '%s'\n", val);
- audio_buffers = DEFAULT_AUDIO_BUFFERS;
- } else if ((audio_buffers < DAHDI_DEFAULT_NUM_BUFS) || (audio_buffers > DAHDI_MAX_NUM_BUFS)) {
- ast_log(LOG_WARNING, "audiobuffers setting must be between %d and %d\n",
- DAHDI_DEFAULT_NUM_BUFS, DAHDI_MAX_NUM_BUFS);
- audio_buffers = DEFAULT_AUDIO_BUFFERS;
- }
- if (audio_buffers != DEFAULT_AUDIO_BUFFERS)
- ast_log(LOG_NOTICE, "Audio buffers per channel set to %d\n", audio_buffers);
- }
- if ((val = ast_variable_retrieve(cfg, "general", "schedule")))
- rt_schedule = ast_true(val);
- if ((val = ast_variable_retrieve(cfg, "general", "logmembercount")))
- rt_log_members = ast_true(val);
- if ((val = ast_variable_retrieve(cfg, "general", "fuzzystart"))) {
- if ((sscanf(val, "%30d", &fuzzystart) != 1)) {
- ast_log(LOG_WARNING, "fuzzystart must be a number, not '%s'\n", val);
- fuzzystart = 0;
- }
- }
- if ((val = ast_variable_retrieve(cfg, "general", "earlyalert"))) {
- if ((sscanf(val, "%30d", &earlyalert) != 1)) {
- ast_log(LOG_WARNING, "earlyalert must be a number, not '%s'\n", val);
- earlyalert = 0;
- }
- }
- if ((val = ast_variable_retrieve(cfg, "general", "endalert"))) {
- if ((sscanf(val, "%30d", &endalert) != 1)) {
- ast_log(LOG_WARNING, "endalert must be a number, not '%s'\n", val);
- endalert = 0;
- }
- }
- ast_config_destroy(cfg);
- }
- /*! \brief Find an SLA trunk by name
- * \note This must be called with the sla_trunks container locked
- */
- static struct sla_trunk *sla_find_trunk(const char *name)
- {
- struct sla_trunk *trunk = NULL;
- AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
- if (!strcasecmp(trunk->name, name))
- break;
- }
- return trunk;
- }
- /*! \brief Find an SLA station by name
- * \note This must be called with the sla_stations container locked
- */
- static struct sla_station *sla_find_station(const char *name)
- {
- struct sla_station *station = NULL;
- AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
- if (!strcasecmp(station->name, name))
- break;
- }
- return station;
- }
- static int sla_check_station_hold_access(const struct sla_trunk *trunk,
- const struct sla_station *station)
- {
- struct sla_station_ref *station_ref;
- struct sla_trunk_ref *trunk_ref;
- /* For each station that has this call on hold, check for private hold. */
- AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
- AST_LIST_TRAVERSE(&station_ref->station->trunks, trunk_ref, entry) {
- if (trunk_ref->trunk != trunk || station_ref->station == station)
- continue;
- if (trunk_ref->state == SLA_TRUNK_STATE_ONHOLD_BYME &&
- station_ref->station->hold_access == SLA_HOLD_PRIVATE)
- return 1;
- return 0;
- }
- }
- return 0;
- }
- /*! \brief Find a trunk reference on a station by name
- * \param station the station
- * \param name the trunk's name
- * \return a pointer to the station's trunk reference. If the trunk
- * is not found, it is not idle and barge is disabled, or if
- * it is on hold and private hold is set, then NULL will be returned.
- */
- static struct sla_trunk_ref *sla_find_trunk_ref_byname(const struct sla_station *station,
- const char *name)
- {
- struct sla_trunk_ref *trunk_ref = NULL;
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (strcasecmp(trunk_ref->trunk->name, name))
- continue;
- if ( (trunk_ref->trunk->barge_disabled
- && trunk_ref->state == SLA_TRUNK_STATE_UP) ||
- (trunk_ref->trunk->hold_stations
- && trunk_ref->trunk->hold_access == SLA_HOLD_PRIVATE
- && trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) ||
- sla_check_station_hold_access(trunk_ref->trunk, station) )
- {
- trunk_ref = NULL;
- }
- break;
- }
- return trunk_ref;
- }
- static struct sla_station_ref *sla_create_station_ref(struct sla_station *station)
- {
- struct sla_station_ref *station_ref;
- if (!(station_ref = ast_calloc(1, sizeof(*station_ref))))
- return NULL;
- station_ref->station = station;
- return station_ref;
- }
- static struct sla_ringing_station *sla_create_ringing_station(struct sla_station *station)
- {
- struct sla_ringing_station *ringing_station;
- if (!(ringing_station = ast_calloc(1, sizeof(*ringing_station))))
- return NULL;
- ringing_station->station = station;
- ringing_station->ring_begin = ast_tvnow();
- return ringing_station;
- }
- static enum ast_device_state sla_state_to_devstate(enum sla_trunk_state state)
- {
- switch (state) {
- case SLA_TRUNK_STATE_IDLE:
- return AST_DEVICE_NOT_INUSE;
- case SLA_TRUNK_STATE_RINGING:
- return AST_DEVICE_RINGING;
- case SLA_TRUNK_STATE_UP:
- return AST_DEVICE_INUSE;
- case SLA_TRUNK_STATE_ONHOLD:
- case SLA_TRUNK_STATE_ONHOLD_BYME:
- return AST_DEVICE_ONHOLD;
- }
- return AST_DEVICE_UNKNOWN;
- }
- static void sla_change_trunk_state(const struct sla_trunk *trunk, enum sla_trunk_state state,
- enum sla_which_trunk_refs inactive_only, const struct sla_trunk_ref *exclude)
- {
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref;
- AST_LIST_TRAVERSE(&sla_stations, station, entry) {
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (trunk_ref->trunk != trunk || (inactive_only ? trunk_ref->chan : 0)
- || trunk_ref == exclude)
- continue;
- trunk_ref->state = state;
- ast_devstate_changed(sla_state_to_devstate(state),
- "SLA:%s_%s", station->name, trunk->name);
- break;
- }
- }
- }
- struct run_station_args {
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref;
- ast_mutex_t *cond_lock;
- ast_cond_t *cond;
- };
- static void answer_trunk_chan(struct ast_channel *chan)
- {
- ast_answer(chan);
- ast_indicate(chan, -1);
- }
- static void *run_station(void *data)
- {
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref;
- char conf_name[MAX_CONFNUM];
- struct ast_flags conf_flags = { 0 };
- struct ast_conference *conf;
- {
- struct run_station_args *args = data;
- station = args->station;
- trunk_ref = args->trunk_ref;
- ast_mutex_lock(args->cond_lock);
- ast_cond_signal(args->cond);
- ast_mutex_unlock(args->cond_lock);
- /* args is no longer valid here. */
- }
- ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1);
- snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
- ast_set_flag(&conf_flags,
- CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
- answer_trunk_chan(trunk_ref->chan);
- conf = build_conf(conf_name, "", "", 0, 0, 1, trunk_ref->chan);
- if (conf) {
- conf_run(trunk_ref->chan, conf, conf_flags.flags, NULL);
- dispose_conf(conf);
- conf = NULL;
- }
- trunk_ref->chan = NULL;
- if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
- trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
- strncat(conf_name, ",K", sizeof(conf_name) - strlen(conf_name) - 1);
- admin_exec(NULL, conf_name);
- trunk_ref->trunk->hold_stations = 0;
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
- }
- ast_dial_join(station->dial);
- ast_dial_destroy(station->dial);
- station->dial = NULL;
- return NULL;
- }
- static void sla_stop_ringing_trunk(struct sla_ringing_trunk *ringing_trunk)
- {
- char buf[80];
- struct sla_station_ref *station_ref;
- snprintf(buf, sizeof(buf), "SLA_%s,K", ringing_trunk->trunk->name);
- admin_exec(NULL, buf);
- sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
- while ((station_ref = AST_LIST_REMOVE_HEAD(&ringing_trunk->timed_out_stations, entry)))
- ast_free(station_ref);
- ast_free(ringing_trunk);
- }
- static void sla_stop_ringing_station(struct sla_ringing_station *ringing_station,
- enum sla_station_hangup hangup)
- {
- struct sla_ringing_trunk *ringing_trunk;
- struct sla_trunk_ref *trunk_ref;
- struct sla_station_ref *station_ref;
- ast_dial_join(ringing_station->station->dial);
- ast_dial_destroy(ringing_station->station->dial);
- ringing_station->station->dial = NULL;
- if (hangup == SLA_STATION_HANGUP_NORMAL)
- goto done;
- /* If the station is being hung up because of a timeout, then add it to the
- * list of timed out stations on each of the ringing trunks. This is so
- * that when doing further processing to figure out which stations should be
- * ringing, which trunk to answer, determining timeouts, etc., we know which
- * ringing trunks we should ignore. */
- AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
- AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
- if (ringing_trunk->trunk == trunk_ref->trunk)
- break;
- }
- if (!trunk_ref)
- continue;
- if (!(station_ref = sla_create_station_ref(ringing_station->station)))
- continue;
- AST_LIST_INSERT_TAIL(&ringing_trunk->timed_out_stations, station_ref, entry);
- }
- done:
- ast_free(ringing_station);
- }
- static void sla_dial_state_callback(struct ast_dial *dial)
- {
- sla_queue_event(SLA_EVENT_DIAL_STATE);
- }
- /*! \brief Check to see if dialing this station already timed out for this ringing trunk
- * \note Assumes sla.lock is locked
- */
- static int sla_check_timed_out_station(const struct sla_ringing_trunk *ringing_trunk,
- const struct sla_station *station)
- {
- struct sla_station_ref *timed_out_station;
- AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, timed_out_station, entry) {
- if (station == timed_out_station->station)
- return 1;
- }
- return 0;
- }
- /*! \brief Choose the highest priority ringing trunk for a station
- * \param station the station
- * \param remove remove the ringing trunk once selected
- * \param trunk_ref a place to store the pointer to this stations reference to
- * the selected trunk
- * \return a pointer to the selected ringing trunk, or NULL if none found
- * \note Assumes that sla.lock is locked
- */
- static struct sla_ringing_trunk *sla_choose_ringing_trunk(struct sla_station *station,
- struct sla_trunk_ref **trunk_ref, int remove)
- {
- struct sla_trunk_ref *s_trunk_ref;
- struct sla_ringing_trunk *ringing_trunk = NULL;
- AST_LIST_TRAVERSE(&station->trunks, s_trunk_ref, entry) {
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
- /* Make sure this is the trunk we're looking for */
- if (s_trunk_ref->trunk != ringing_trunk->trunk)
- continue;
- /* This trunk on the station is ringing. But, make sure this station
- * didn't already time out while this trunk was ringing. */
- if (sla_check_timed_out_station(ringing_trunk, station))
- continue;
- if (remove)
- AST_LIST_REMOVE_CURRENT(entry);
- if (trunk_ref)
- *trunk_ref = s_trunk_ref;
- break;
- }
- AST_LIST_TRAVERSE_SAFE_END;
-
- if (ringing_trunk)
- break;
- }
- return ringing_trunk;
- }
- static void sla_handle_dial_state_event(void)
- {
- struct sla_ringing_station *ringing_station;
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
- struct sla_trunk_ref *s_trunk_ref = NULL;
- struct sla_ringing_trunk *ringing_trunk = NULL;
- struct run_station_args args;
- enum ast_dial_result dial_res;
- pthread_t dont_care;
- ast_mutex_t cond_lock;
- ast_cond_t cond;
- switch ((dial_res = ast_dial_state(ringing_station->station->dial))) {
- case AST_DIAL_RESULT_HANGUP:
- case AST_DIAL_RESULT_INVALID:
- case AST_DIAL_RESULT_FAILED:
- case AST_DIAL_RESULT_TIMEOUT:
- case AST_DIAL_RESULT_UNANSWERED:
- AST_LIST_REMOVE_CURRENT(entry);
- sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_NORMAL);
- break;
- case AST_DIAL_RESULT_ANSWERED:
- AST_LIST_REMOVE_CURRENT(entry);
- /* Find the appropriate trunk to answer. */
- ast_mutex_lock(&sla.lock);
- ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, &s_trunk_ref, 1);
- ast_mutex_unlock(&sla.lock);
- if (!ringing_trunk) {
- ast_debug(1, "Found no ringing trunk for station '%s' to answer!\n", ringing_station->station->name);
- break;
- }
- /* Track the channel that answered this trunk */
- s_trunk_ref->chan = ast_dial_answered(ringing_station->station->dial);
- /* Actually answer the trunk */
- answer_trunk_chan(ringing_trunk->trunk->chan);
- sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
- /* Now, start a thread that will connect this station to the trunk. The rest of
- * the code here sets up the thread and ensures that it is able to save the arguments
- * before they are no longer valid since they are allocated on the stack. */
- args.trunk_ref = s_trunk_ref;
- args.station = ringing_station->station;
- args.cond = &cond;
- args.cond_lock = &cond_lock;
- ast_free(ringing_trunk);
- ast_free(ringing_station);
- ast_mutex_init(&cond_lock);
- ast_cond_init(&cond, NULL);
- ast_mutex_lock(&cond_lock);
- ast_pthread_create_detached_background(&dont_care, NULL, run_station, &args);
- ast_cond_wait(&cond, &cond_lock);
- ast_mutex_unlock(&cond_lock);
- ast_mutex_destroy(&cond_lock);
- ast_cond_destroy(&cond);
- break;
- case AST_DIAL_RESULT_TRYING:
- case AST_DIAL_RESULT_RINGING:
- case AST_DIAL_RESULT_PROGRESS:
- case AST_DIAL_RESULT_PROCEEDING:
- break;
- }
- if (dial_res == AST_DIAL_RESULT_ANSWERED) {
- /* Queue up reprocessing ringing trunks, and then ringing stations again */
- sla_queue_event(SLA_EVENT_RINGING_TRUNK);
- sla_queue_event(SLA_EVENT_DIAL_STATE);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
- }
- /*! \brief Check to see if this station is already ringing
- * \note Assumes sla.lock is locked
- */
- static int sla_check_ringing_station(const struct sla_station *station)
- {
- struct sla_ringing_station *ringing_station;
- AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_station, entry) {
- if (station == ringing_station->station)
- return 1;
- }
- return 0;
- }
- /*! \brief Check to see if this station has failed to be dialed in the past minute
- * \note assumes sla.lock is locked
- */
- static int sla_check_failed_station(const struct sla_station *station)
- {
- struct sla_failed_station *failed_station;
- int res = 0;
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.failed_stations, failed_station, entry) {
- if (station != failed_station->station)
- continue;
- if (ast_tvdiff_ms(ast_tvnow(), failed_station->last_try) > 1000) {
- AST_LIST_REMOVE_CURRENT(entry);
- ast_free(failed_station);
- break;
- }
- res = 1;
- }
- AST_LIST_TRAVERSE_SAFE_END
- return res;
- }
- /*! \brief Ring a station
- * \note Assumes sla.lock is locked
- */
- static int sla_ring_station(struct sla_ringing_trunk *ringing_trunk, struct sla_station *station)
- {
- char *tech, *tech_data;
- struct ast_dial *dial;
- struct sla_ringing_station *ringing_station;
- const char *cid_name = NULL, *cid_num = NULL;
- enum ast_dial_result res;
- if (!(dial = ast_dial_create()))
- return -1;
- ast_dial_set_state_callback(dial, sla_dial_state_callback);
- tech_data = ast_strdupa(station->device);
- tech = strsep(&tech_data, "/");
- if (ast_dial_append(dial, tech, tech_data) == -1) {
- ast_dial_destroy(dial);
- return -1;
- }
- if (!sla.attempt_callerid && !ast_strlen_zero(ringing_trunk->trunk->chan->cid.cid_name)) {
- cid_name = ast_strdupa(ringing_trunk->trunk->chan->cid.cid_name);
- ast_free(ringing_trunk->trunk->chan->cid.cid_name);
- ringing_trunk->trunk->chan->cid.cid_name = NULL;
- }
- if (!sla.attempt_callerid && !ast_strlen_zero(ringing_trunk->trunk->chan->cid.cid_num)) {
- cid_num = ast_strdupa(ringing_trunk->trunk->chan->cid.cid_num);
- ast_free(ringing_trunk->trunk->chan->cid.cid_num);
- ringing_trunk->trunk->chan->cid.cid_num = NULL;
- }
- res = ast_dial_run(dial, ringing_trunk->trunk->chan, 1);
-
- if (cid_name)
- ringing_trunk->trunk->chan->cid.cid_name = ast_strdup(cid_name);
- if (cid_num)
- ringing_trunk->trunk->chan->cid.cid_num = ast_strdup(cid_num);
-
- if (res != AST_DIAL_RESULT_TRYING) {
- struct sla_failed_station *failed_station;
- ast_dial_destroy(dial);
- if (!(failed_station = ast_calloc(1, sizeof(*failed_station))))
- return -1;
- failed_station->station = station;
- failed_station->last_try = ast_tvnow();
- AST_LIST_INSERT_HEAD(&sla.failed_stations, failed_station, entry);
- return -1;
- }
- if (!(ringing_station = sla_create_ringing_station(station))) {
- ast_dial_join(dial);
- ast_dial_destroy(dial);
- return -1;
- }
- station->dial = dial;
- AST_LIST_INSERT_HEAD(&sla.ringing_stations, ringing_station, entry);
- return 0;
- }
- /*! \brief Check to see if a station is in use
- */
- static int sla_check_inuse_station(const struct sla_station *station)
- {
- struct sla_trunk_ref *trunk_ref;
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (trunk_ref->chan)
- return 1;
- }
- return 0;
- }
- static struct sla_trunk_ref *sla_find_trunk_ref(const struct sla_station *station,
- const struct sla_trunk *trunk)
- {
- struct sla_trunk_ref *trunk_ref = NULL;
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (trunk_ref->trunk == trunk)
- break;
- }
- return trunk_ref;
- }
- /*! \brief Calculate the ring delay for a given ringing trunk on a station
- * \param station the station
- * \param ringing_trunk the trunk. If NULL, the highest priority ringing trunk will be used
- * \return the number of ms left before the delay is complete, or INT_MAX if there is no delay
- */
- static int sla_check_station_delay(struct sla_station *station,
- struct sla_ringing_trunk *ringing_trunk)
- {
- struct sla_trunk_ref *trunk_ref;
- unsigned int delay = UINT_MAX;
- int time_left, time_elapsed;
- if (!ringing_trunk)
- ringing_trunk = sla_choose_ringing_trunk(station, &trunk_ref, 0);
- else
- trunk_ref = sla_find_trunk_ref(station, ringing_trunk->trunk);
- if (!ringing_trunk || !trunk_ref)
- return delay;
- /* If this station has a ring delay specific to the highest priority
- * ringing trunk, use that. Otherwise, use the ring delay specified
- * globally for the station. */
- delay = trunk_ref->ring_delay;
- if (!delay)
- delay = station->ring_delay;
- if (!delay)
- return INT_MAX;
- time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
- time_left = (delay * 1000) - time_elapsed;
- return time_left;
- }
- /*! \brief Ring stations based on current set of ringing trunks
- * \note Assumes that sla.lock is locked
- */
- static void sla_ring_stations(void)
- {
- struct sla_station_ref *station_ref;
- struct sla_ringing_trunk *ringing_trunk;
- /* Make sure that every station that uses at least one of the ringing
- * trunks, is ringing. */
- AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
- AST_LIST_TRAVERSE(&ringing_trunk->trunk->stations, station_ref, entry) {
- int time_left;
- /* Is this station already ringing? */
- if (sla_check_ringing_station(station_ref->station))
- continue;
- /* Is this station already in a call? */
- if (sla_check_inuse_station(station_ref->station))
- continue;
- /* Did we fail to dial this station earlier? If so, has it been
- * a minute since we tried? */
- if (sla_check_failed_station(station_ref->station))
- continue;
- /* If this station already timed out while this trunk was ringing,
- * do not dial it again for this ringing trunk. */
- if (sla_check_timed_out_station(ringing_trunk, station_ref->station))
- continue;
- /* Check for a ring delay in progress */
- time_left = sla_check_station_delay(station_ref->station, ringing_trunk);
- if (time_left != INT_MAX && time_left > 0)
- continue;
- /* It is time to make this station begin to ring. Do it! */
- sla_ring_station(ringing_trunk, station_ref->station);
- }
- }
- /* Now, all of the stations that should be ringing, are ringing. */
- }
- static void sla_hangup_stations(void)
- {
- struct sla_trunk_ref *trunk_ref;
- struct sla_ringing_station *ringing_station;
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
- AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
- struct sla_ringing_trunk *ringing_trunk;
- ast_mutex_lock(&sla.lock);
- AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
- if (trunk_ref->trunk == ringing_trunk->trunk)
- break;
- }
- ast_mutex_unlock(&sla.lock);
- if (ringing_trunk)
- break;
- }
- if (!trunk_ref) {
- AST_LIST_REMOVE_CURRENT(entry);
- ast_dial_join(ringing_station->station->dial);
- ast_dial_destroy(ringing_station->station->dial);
- ringing_station->station->dial = NULL;
- ast_free(ringing_station);
- }
- }
- AST_LIST_TRAVERSE_SAFE_END
- }
- static void sla_handle_ringing_trunk_event(void)
- {
- ast_mutex_lock(&sla.lock);
- sla_ring_stations();
- ast_mutex_unlock(&sla.lock);
- /* Find stations that shouldn't be ringing anymore. */
- sla_hangup_stations();
- }
- static void sla_handle_hold_event(struct sla_event *event)
- {
- ast_atomic_fetchadd_int((int *) &event->trunk_ref->trunk->hold_stations, 1);
- event->trunk_ref->state = SLA_TRUNK_STATE_ONHOLD_BYME;
- ast_devstate_changed(AST_DEVICE_ONHOLD, "SLA:%s_%s",
- event->station->name, event->trunk_ref->trunk->name);
- sla_change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_ONHOLD,
- INACTIVE_TRUNK_REFS, event->trunk_ref);
- if (event->trunk_ref->trunk->active_stations == 1) {
- /* The station putting it on hold is the only one on the call, so start
- * Music on hold to the trunk. */
- event->trunk_ref->trunk->on_hold = 1;
- ast_indicate(event->trunk_ref->trunk->chan, AST_CONTROL_HOLD);
- }
- ast_softhangup(event->trunk_ref->chan, AST_SOFTHANGUP_DEV);
- event->trunk_ref->chan = NULL;
- }
- /*! \brief Process trunk ring timeouts
- * \note Called with sla.lock locked
- * \return non-zero if a change to the ringing trunks was made
- */
- static int sla_calc_trunk_timeouts(unsigned int *timeout)
- {
- struct sla_ringing_trunk *ringing_trunk;
- int res = 0;
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
- int time_left, time_elapsed;
- if (!ringing_trunk->trunk->ring_timeout)
- continue;
- time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
- time_left = (ringing_trunk->trunk->ring_timeout * 1000) - time_elapsed;
- if (time_left <= 0) {
- pbx_builtin_setvar_helper(ringing_trunk->trunk->chan, "SLATRUNK_STATUS", "RINGTIMEOUT");
- AST_LIST_REMOVE_CURRENT(entry);
- sla_stop_ringing_trunk(ringing_trunk);
- res = 1;
- continue;
- }
- if (time_left < *timeout)
- *timeout = time_left;
- }
- AST_LIST_TRAVERSE_SAFE_END;
- return res;
- }
- /*! \brief Process station ring timeouts
- * \note Called with sla.lock locked
- * \return non-zero if a change to the ringing stations was made
- */
- static int sla_calc_station_timeouts(unsigned int *timeout)
- {
- struct sla_ringing_trunk *ringing_trunk;
- struct sla_ringing_station *ringing_station;
- int res = 0;
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
- unsigned int ring_timeout = 0;
- int time_elapsed, time_left = INT_MAX, final_trunk_time_left = INT_MIN;
- struct sla_trunk_ref *trunk_ref;
- /* If there are any ring timeouts specified for a specific trunk
- * on the station, then use the highest per-trunk ring timeout.
- * Otherwise, use the ring timeout set for the entire station. */
- AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
- struct sla_station_ref *station_ref;
- int trunk_time_elapsed, trunk_time_left;
- AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
- if (ringing_trunk->trunk == trunk_ref->trunk)
- break;
- }
- if (!ringing_trunk)
- continue;
- /* If there is a trunk that is ringing without a timeout, then the
- * only timeout that could matter is a global station ring timeout. */
- if (!trunk_ref->ring_timeout)
- break;
- /* This trunk on this station is ringing and has a timeout.
- * However, make sure this trunk isn't still ringing from a
- * previous timeout. If so, don't consider it. */
- AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, station_ref, entry) {
- if (station_ref->station == ringing_station->station)
- break;
- }
- if (station_ref)
- continue;
- trunk_time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
- trunk_time_left = (trunk_ref->ring_timeout * 1000) - trunk_time_elapsed;
- if (trunk_time_left > final_trunk_time_left)
- final_trunk_time_left = trunk_time_left;
- }
- /* No timeout was found for ringing trunks, and no timeout for the entire station */
- if (final_trunk_time_left == INT_MIN && !ringing_station->station->ring_timeout)
- continue;
- /* Compute how much time is left for a global station timeout */
- if (ringing_station->station->ring_timeout) {
- ring_timeout = ringing_station->station->ring_timeout;
- time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_station->ring_begin);
- time_left = (ring_timeout * 1000) - time_elapsed;
- }
- /* If the time left based on the per-trunk timeouts is smaller than the
- * global station ring timeout, use that. */
- if (final_trunk_time_left > INT_MIN && final_trunk_time_left < time_left)
- time_left = final_trunk_time_left;
- /* If there is no time left, the station needs to stop ringing */
- if (time_left <= 0) {
- AST_LIST_REMOVE_CURRENT(entry);
- sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_TIMEOUT);
- res = 1;
- continue;
- }
- /* There is still some time left for this station to ring, so save that
- * timeout if it is the first event scheduled to occur */
- if (time_left < *timeout)
- *timeout = time_left;
- }
- AST_LIST_TRAVERSE_SAFE_END;
- return res;
- }
- /*! \brief Calculate the ring delay for a station
- * \note Assumes sla.lock is locked
- */
- static int sla_calc_station_delays(unsigned int *timeout)
- {
- struct sla_station *station;
- int res = 0;
- AST_LIST_TRAVERSE(&sla_stations, station, entry) {
- struct sla_ringing_trunk *ringing_trunk;
- int time_left;
- /* Ignore stations already ringing */
- if (sla_check_ringing_station(station))
- continue;
- /* Ignore stations already on a call */
- if (sla_check_inuse_station(station))
- continue;
- /* Ignore stations that don't have one of their trunks ringing */
- if (!(ringing_trunk = sla_choose_ringing_trunk(station, NULL, 0)))
- continue;
- if ((time_left = sla_check_station_delay(station, ringing_trunk)) == INT_MAX)
- continue;
- /* If there is no time left, then the station needs to start ringing.
- * Return non-zero so that an event will be queued up an event to
- * make that happen. */
- if (time_left <= 0) {
- res = 1;
- continue;
- }
- if (time_left < *timeout)
- *timeout = time_left;
- }
- return res;
- }
- /*! \brief Calculate the time until the next known event
- * \note Called with sla.lock locked */
- static int sla_process_timers(struct timespec *ts)
- {
- unsigned int timeout = UINT_MAX;
- struct timeval tv;
- unsigned int change_made = 0;
- /* Check for ring timeouts on ringing trunks */
- if (sla_calc_trunk_timeouts(&timeout))
- change_made = 1;
- /* Check for ring timeouts on ringing stations */
- if (sla_calc_station_timeouts(&timeout))
- change_made = 1;
- /* Check for station ring delays */
- if (sla_calc_station_delays(&timeout))
- change_made = 1;
- /* queue reprocessing of ringing trunks */
- if (change_made)
- sla_queue_event_nolock(SLA_EVENT_RINGING_TRUNK);
- /* No timeout */
- if (timeout == UINT_MAX)
- return 0;
- if (ts) {
- tv = ast_tvadd(ast_tvnow(), ast_samp2tv(timeout, 1000));
- ts->tv_sec = tv.tv_sec;
- ts->tv_nsec = tv.tv_usec * 1000;
- }
- return 1;
- }
- static int sla_load_config(int reload);
- /*! \brief Check if we can do a reload of SLA, and do it if we can */
- static void sla_check_reload(void)
- {
- struct sla_station *station;
- struct sla_trunk *trunk;
- ast_mutex_lock(&sla.lock);
- if (!AST_LIST_EMPTY(&sla.event_q) || !AST_LIST_EMPTY(&sla.ringing_trunks)
- || !AST_LIST_EMPTY(&sla.ringing_stations)) {
- ast_mutex_unlock(&sla.lock);
- return;
- }
- AST_RWLIST_RDLOCK(&sla_stations);
- AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
- if (station->ref_count)
- break;
- }
- AST_RWLIST_UNLOCK(&sla_stations);
- if (station) {
- ast_mutex_unlock(&sla.lock);
- return;
- }
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
- if (trunk->ref_count)
- break;
- }
- AST_RWLIST_UNLOCK(&sla_trunks);
- if (trunk) {
- ast_mutex_unlock(&sla.lock);
- return;
- }
- /* yay */
- sla_load_config(1);
- sla.reload = 0;
- ast_mutex_unlock(&sla.lock);
- }
- static void *sla_thread(void *data)
- {
- struct sla_failed_station *failed_station;
- struct sla_ringing_station *ringing_station;
- ast_mutex_lock(&sla.lock);
- while (!sla.stop) {
- struct sla_event *event;
- struct timespec ts = { 0, };
- unsigned int have_timeout = 0;
- if (AST_LIST_EMPTY(&sla.event_q)) {
- if ((have_timeout = sla_process_timers(&ts)))
- ast_cond_timedwait(&sla.cond, &sla.lock, &ts);
- else
- ast_cond_wait(&sla.cond, &sla.lock);
- if (sla.stop)
- break;
- }
- if (have_timeout)
- sla_process_timers(NULL);
- while ((event = AST_LIST_REMOVE_HEAD(&sla.event_q, entry))) {
- ast_mutex_unlock(&sla.lock);
- switch (event->type) {
- case SLA_EVENT_HOLD:
- sla_handle_hold_event(event);
- break;
- case SLA_EVENT_DIAL_STATE:
- sla_handle_dial_state_event();
- break;
- case SLA_EVENT_RINGING_TRUNK:
- sla_handle_ringing_trunk_event();
- break;
- case SLA_EVENT_RELOAD:
- sla.reload = 1;
- case SLA_EVENT_CHECK_RELOAD:
- break;
- }
- ast_free(event);
- ast_mutex_lock(&sla.lock);
- }
- if (sla.reload)
- sla_check_reload();
- }
- ast_mutex_unlock(&sla.lock);
- while ((ringing_station = AST_LIST_REMOVE_HEAD(&sla.ringing_stations, entry)))
- ast_free(ringing_station);
- while ((failed_station = AST_LIST_REMOVE_HEAD(&sla.failed_stations, entry)))
- ast_free(failed_station);
- return NULL;
- }
- struct dial_trunk_args {
- struct sla_trunk_ref *trunk_ref;
- struct sla_station *station;
- ast_mutex_t *cond_lock;
- ast_cond_t *cond;
- };
- static void *dial_trunk(void *data)
- {
- struct dial_trunk_args *args = data;
- struct ast_dial *dial;
- char *tech, *tech_data;
- enum ast_dial_result dial_res;
- char conf_name[MAX_CONFNUM];
- struct ast_conference *conf;
- struct ast_flags conf_flags = { 0 };
- struct sla_trunk_ref *trunk_ref = args->trunk_ref;
- const char *cid_name = NULL, *cid_num = NULL;
- if (!(dial = ast_dial_create())) {
- ast_mutex_lock(args->cond_lock);
- ast_cond_signal(args->cond);
- ast_mutex_unlock(args->cond_lock);
- return NULL;
- }
- tech_data = ast_strdupa(trunk_ref->trunk->device);
- tech = strsep(&tech_data, "/");
- if (ast_dial_append(dial, tech, tech_data) == -1) {
- ast_mutex_lock(args->cond_lock);
- ast_cond_signal(args->cond);
- ast_mutex_unlock(args->cond_lock);
- ast_dial_destroy(dial);
- return NULL;
- }
- if (!sla.attempt_callerid && !ast_strlen_zero(trunk_ref->chan->cid.cid_name)) {
- cid_name = ast_strdupa(trunk_ref->chan->cid.cid_name);
- ast_free(trunk_ref->chan->cid.cid_name);
- trunk_ref->chan->cid.cid_name = NULL;
- }
- if (!sla.attempt_callerid && !ast_strlen_zero(trunk_ref->chan->cid.cid_num)) {
- cid_num = ast_strdupa(trunk_ref->chan->cid.cid_num);
- ast_free(trunk_ref->chan->cid.cid_num);
- trunk_ref->chan->cid.cid_num = NULL;
- }
- dial_res = ast_dial_run(dial, trunk_ref->chan, 1);
- if (cid_name)
- trunk_ref->chan->cid.cid_name = ast_strdup(cid_name);
- if (cid_num)
- trunk_ref->chan->cid.cid_num = ast_strdup(cid_num);
- if (dial_res != AST_DIAL_RESULT_TRYING) {
- ast_mutex_lock(args->cond_lock);
- ast_cond_signal(args->cond);
- ast_mutex_unlock(args->cond_lock);
- ast_dial_destroy(dial);
- return NULL;
- }
- for (;;) {
- unsigned int done = 0;
- switch ((dial_res = ast_dial_state(dial))) {
- case AST_DIAL_RESULT_ANSWERED:
- trunk_ref->trunk->chan = ast_dial_answered(dial);
- case AST_DIAL_RESULT_HANGUP:
- case AST_DIAL_RESULT_INVALID:
- case AST_DIAL_RESULT_FAILED:
- case AST_DIAL_RESULT_TIMEOUT:
- case AST_DIAL_RESULT_UNANSWERED:
- done = 1;
- case AST_DIAL_RESULT_TRYING:
- case AST_DIAL_RESULT_RINGING:
- case AST_DIAL_RESULT_PROGRESS:
- case AST_DIAL_RESULT_PROCEEDING:
- break;
- }
- if (done)
- break;
- }
- if (!trunk_ref->trunk->chan) {
- ast_mutex_lock(args->cond_lock);
- ast_cond_signal(args->cond);
- ast_mutex_unlock(args->cond_lock);
- ast_dial_join(dial);
- ast_dial_destroy(dial);
- return NULL;
- }
- snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
- ast_set_flag(&conf_flags,
- CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_MARKEDUSER |
- CONFFLAG_PASS_DTMF | CONFFLAG_SLA_TRUNK);
- conf = build_conf(conf_name, "", "", 1, 1, 1, trunk_ref->trunk->chan);
- ast_mutex_lock(args->cond_lock);
- ast_cond_signal(args->cond);
- ast_mutex_unlock(args->cond_lock);
- if (conf) {
- conf_run(trunk_ref->trunk->chan, conf, conf_flags.flags, NULL);
- dispose_conf(conf);
- conf = NULL;
- }
- /* If the trunk is going away, it is definitely now IDLE. */
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
- trunk_ref->trunk->chan = NULL;
- trunk_ref->trunk->on_hold = 0;
- ast_dial_join(dial);
- ast_dial_destroy(dial);
- return NULL;
- }
- /*! \brief For a given station, choose the highest priority idle trunk
- */
- static struct sla_trunk_ref *sla_choose_idle_trunk(const struct sla_station *station)
- {
- struct sla_trunk_ref *trunk_ref = NULL;
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (trunk_ref->state == SLA_TRUNK_STATE_IDLE)
- break;
- }
- return trunk_ref;
- }
- static int sla_station_exec(struct ast_channel *chan, void *data)
- {
- char *station_name, *trunk_name;
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref = NULL;
- char conf_name[MAX_CONFNUM];
- struct ast_flags conf_flags = { 0 };
- struct ast_conference *conf;
- if (ast_strlen_zero(data)) {
- ast_log(LOG_WARNING, "Invalid Arguments to SLAStation!\n");
- pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
- return 0;
- }
- trunk_name = ast_strdupa(data);
- station_name = strsep(&trunk_name, "_");
- if (ast_strlen_zero(station_name)) {
- ast_log(LOG_WARNING, "Invalid Arguments to SLAStation!\n");
- pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
- return 0;
- }
- AST_RWLIST_RDLOCK(&sla_stations);
- station = sla_find_station(station_name);
- if (station)
- ast_atomic_fetchadd_int((int *) &station->ref_count, 1);
- AST_RWLIST_UNLOCK(&sla_stations);
- if (!station) {
- ast_log(LOG_WARNING, "Station '%s' not found!\n", station_name);
- pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- AST_RWLIST_RDLOCK(&sla_trunks);
- if (!ast_strlen_zero(trunk_name)) {
- trunk_ref = sla_find_trunk_ref_byname(station, trunk_name);
- } else
- trunk_ref = sla_choose_idle_trunk(station);
- AST_RWLIST_UNLOCK(&sla_trunks);
- if (!trunk_ref) {
- if (ast_strlen_zero(trunk_name))
- ast_log(LOG_NOTICE, "No trunks available for call.\n");
- else {
- ast_log(LOG_NOTICE, "Can't join existing call on trunk "
- "'%s' due to access controls.\n", trunk_name);
- }
- pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
- ast_atomic_fetchadd_int((int *) &station->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- if (trunk_ref->state == SLA_TRUNK_STATE_ONHOLD_BYME) {
- if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->hold_stations) == 1)
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
- else {
- trunk_ref->state = SLA_TRUNK_STATE_UP;
- ast_devstate_changed(AST_DEVICE_INUSE,
- "SLA:%s_%s", station->name, trunk_ref->trunk->name);
- }
- } else if (trunk_ref->state == SLA_TRUNK_STATE_RINGING) {
- struct sla_ringing_trunk *ringing_trunk;
- ast_mutex_lock(&sla.lock);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
- if (ringing_trunk->trunk == trunk_ref->trunk) {
- AST_LIST_REMOVE_CURRENT(entry);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END
- ast_mutex_unlock(&sla.lock);
- if (ringing_trunk) {
- answer_trunk_chan(ringing_trunk->trunk->chan);
- sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
- free(ringing_trunk);
- /* Queue up reprocessing ringing trunks, and then ringing stations again */
- sla_queue_event(SLA_EVENT_RINGING_TRUNK);
- sla_queue_event(SLA_EVENT_DIAL_STATE);
- }
- }
- trunk_ref->chan = chan;
- if (!trunk_ref->trunk->chan) {
- ast_mutex_t cond_lock;
- ast_cond_t cond;
- pthread_t dont_care;
- struct dial_trunk_args args = {
- .trunk_ref = trunk_ref,
- .station = station,
- .cond_lock = &cond_lock,
- .cond = &cond,
- };
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
- /* Create a thread to dial the trunk and dump it into the conference.
- * However, we want to wait until the trunk has been dialed and the
- * conference is created before continuing on here. */
- ast_autoservice_start(chan);
- ast_mutex_init(&cond_lock);
- ast_cond_init(&cond, NULL);
- ast_mutex_lock(&cond_lock);
- ast_pthread_create_detached_background(&dont_care, NULL, dial_trunk, &args);
- ast_cond_wait(&cond, &cond_lock);
- ast_mutex_unlock(&cond_lock);
- ast_mutex_destroy(&cond_lock);
- ast_cond_destroy(&cond);
- ast_autoservice_stop(chan);
- if (!trunk_ref->trunk->chan) {
- ast_debug(1, "Trunk didn't get created. chan: %lx\n", (long) trunk_ref->trunk->chan);
- pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
- trunk_ref->chan = NULL;
- ast_atomic_fetchadd_int((int *) &station->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- }
- if (ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1) == 0 &&
- trunk_ref->trunk->on_hold) {
- trunk_ref->trunk->on_hold = 0;
- ast_indicate(trunk_ref->trunk->chan, AST_CONTROL_UNHOLD);
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
- }
- snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
- ast_set_flag(&conf_flags,
- CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
- ast_answer(chan);
- conf = build_conf(conf_name, "", "", 0, 0, 1, chan);
- if (conf) {
- conf_run(chan, conf, conf_flags.flags, NULL);
- dispose_conf(conf);
- conf = NULL;
- }
- trunk_ref->chan = NULL;
- if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
- trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
- strncat(conf_name, ",K", sizeof(conf_name) - strlen(conf_name) - 1);
- admin_exec(NULL, conf_name);
- trunk_ref->trunk->hold_stations = 0;
- sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
- }
-
- pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "SUCCESS");
- ast_atomic_fetchadd_int((int *) &station->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- static struct sla_trunk_ref *create_trunk_ref(struct sla_trunk *trunk)
- {
- struct sla_trunk_ref *trunk_ref;
- if (!(trunk_ref = ast_calloc(1, sizeof(*trunk_ref))))
- return NULL;
- trunk_ref->trunk = trunk;
- return trunk_ref;
- }
- static struct sla_ringing_trunk *queue_ringing_trunk(struct sla_trunk *trunk)
- {
- struct sla_ringing_trunk *ringing_trunk;
- if (!(ringing_trunk = ast_calloc(1, sizeof(*ringing_trunk))))
- return NULL;
-
- ringing_trunk->trunk = trunk;
- ringing_trunk->ring_begin = ast_tvnow();
- sla_change_trunk_state(trunk, SLA_TRUNK_STATE_RINGING, ALL_TRUNK_REFS, NULL);
- ast_mutex_lock(&sla.lock);
- AST_LIST_INSERT_HEAD(&sla.ringing_trunks, ringing_trunk, entry);
- ast_mutex_unlock(&sla.lock);
- sla_queue_event(SLA_EVENT_RINGING_TRUNK);
- return ringing_trunk;
- }
- enum {
- SLA_TRUNK_OPT_MOH = (1 << 0),
- };
- enum {
- SLA_TRUNK_OPT_ARG_MOH_CLASS = 0,
- SLA_TRUNK_OPT_ARG_ARRAY_SIZE = 1,
- };
- AST_APP_OPTIONS(sla_trunk_opts, BEGIN_OPTIONS
- AST_APP_OPTION_ARG('M', SLA_TRUNK_OPT_MOH, SLA_TRUNK_OPT_ARG_MOH_CLASS),
- END_OPTIONS );
- static int sla_trunk_exec(struct ast_channel *chan, void *data)
- {
- char conf_name[MAX_CONFNUM];
- struct ast_conference *conf;
- struct ast_flags conf_flags = { 0 };
- struct sla_trunk *trunk;
- struct sla_ringing_trunk *ringing_trunk;
- AST_DECLARE_APP_ARGS(args,
- AST_APP_ARG(trunk_name);
- AST_APP_ARG(options);
- );
- char *opts[SLA_TRUNK_OPT_ARG_ARRAY_SIZE] = { NULL, };
- char *conf_opt_args[OPT_ARG_ARRAY_SIZE] = { NULL, };
- struct ast_flags opt_flags = { 0 };
- char *parse;
- if (ast_strlen_zero(data)) {
- ast_log(LOG_ERROR, "The SLATrunk application requires an argument, the trunk name\n");
- return -1;
- }
- parse = ast_strdupa(data);
- AST_STANDARD_APP_ARGS(args, parse);
- if (args.argc == 2) {
- if (ast_app_parse_options(sla_trunk_opts, &opt_flags, opts, args.options)) {
- ast_log(LOG_ERROR, "Error parsing options for SLATrunk\n");
- return -1;
- }
- }
- AST_RWLIST_RDLOCK(&sla_trunks);
- trunk = sla_find_trunk(args.trunk_name);
- if (trunk)
- ast_atomic_fetchadd_int((int *) &trunk->ref_count, 1);
- AST_RWLIST_UNLOCK(&sla_trunks);
- if (!trunk) {
- ast_log(LOG_ERROR, "SLA Trunk '%s' not found!\n", args.trunk_name);
- pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- if (trunk->chan) {
- ast_log(LOG_ERROR, "Call came in on %s, but the trunk is already in use!\n",
- args.trunk_name);
- pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
- ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- trunk->chan = chan;
- if (!(ringing_trunk = queue_ringing_trunk(trunk))) {
- pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
- ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- snprintf(conf_name, sizeof(conf_name), "SLA_%s", args.trunk_name);
- conf = build_conf(conf_name, "", "", 1, 1, 1, chan);
- if (!conf) {
- pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
- ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- ast_set_flag(&conf_flags,
- CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_MARKEDUSER | CONFFLAG_PASS_DTMF | CONFFLAG_NO_AUDIO_UNTIL_UP);
- if (ast_test_flag(&opt_flags, SLA_TRUNK_OPT_MOH)) {
- ast_indicate(chan, -1);
- ast_set_flag(&conf_flags, CONFFLAG_MOH);
- conf_opt_args[OPT_ARG_MOH_CLASS] = opts[SLA_TRUNK_OPT_ARG_MOH_CLASS];
- } else
- ast_indicate(chan, AST_CONTROL_RINGING);
- conf_run(chan, conf, conf_flags.flags, opts);
- dispose_conf(conf);
- conf = NULL;
- trunk->chan = NULL;
- trunk->on_hold = 0;
- sla_change_trunk_state(trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
- if (!pbx_builtin_getvar_helper(chan, "SLATRUNK_STATUS"))
- pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "SUCCESS");
- /* Remove the entry from the list of ringing trunks if it is still there. */
- ast_mutex_lock(&sla.lock);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
- if (ringing_trunk->trunk == trunk) {
- AST_LIST_REMOVE_CURRENT(entry);
- break;
- }
- }
- AST_LIST_TRAVERSE_SAFE_END;
- ast_mutex_unlock(&sla.lock);
- if (ringing_trunk) {
- ast_free(ringing_trunk);
- pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "UNANSWERED");
- /* Queue reprocessing of ringing trunks to make stations stop ringing
- * that shouldn't be ringing after this trunk stopped. */
- sla_queue_event(SLA_EVENT_RINGING_TRUNK);
- }
- ast_atomic_fetchadd_int((int *) &trunk->ref_count, -1);
- sla_queue_event(SLA_EVENT_CHECK_RELOAD);
- return 0;
- }
- static enum ast_device_state sla_state(const char *data)
- {
- char *buf, *station_name, *trunk_name;
- struct sla_station *station;
- struct sla_trunk_ref *trunk_ref;
- enum ast_device_state res = AST_DEVICE_INVALID;
- trunk_name = buf = ast_strdupa(data);
- station_name = strsep(&trunk_name, "_");
- AST_RWLIST_RDLOCK(&sla_stations);
- AST_LIST_TRAVERSE(&sla_stations, station, entry) {
- if (strcasecmp(station_name, station->name))
- continue;
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- if (!strcasecmp(trunk_name, trunk_ref->trunk->name))
- break;
- }
- if (!trunk_ref) {
- AST_RWLIST_UNLOCK(&sla_trunks);
- break;
- }
- res = sla_state_to_devstate(trunk_ref->state);
- AST_RWLIST_UNLOCK(&sla_trunks);
- }
- AST_RWLIST_UNLOCK(&sla_stations);
- if (res == AST_DEVICE_INVALID) {
- ast_log(LOG_ERROR, "Could not determine state for trunk %s on station %s!\n",
- trunk_name, station_name);
- }
- return res;
- }
- static void destroy_trunk(struct sla_trunk *trunk)
- {
- struct sla_station_ref *station_ref;
- if (!ast_strlen_zero(trunk->autocontext))
- ast_context_remove_extension(trunk->autocontext, "s", 1, sla_registrar);
- while ((station_ref = AST_LIST_REMOVE_HEAD(&trunk->stations, entry)))
- ast_free(station_ref);
- ast_string_field_free_memory(trunk);
- ast_free(trunk);
- }
- static void destroy_station(struct sla_station *station)
- {
- struct sla_trunk_ref *trunk_ref;
- if (!ast_strlen_zero(station->autocontext)) {
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- char exten[AST_MAX_EXTENSION];
- char hint[AST_MAX_APP];
- snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
- snprintf(hint, sizeof(hint), "SLA:%s", exten);
- ast_context_remove_extension(station->autocontext, exten,
- 1, sla_registrar);
- ast_context_remove_extension(station->autocontext, hint,
- PRIORITY_HINT, sla_registrar);
- }
- AST_RWLIST_UNLOCK(&sla_trunks);
- }
- while ((trunk_ref = AST_LIST_REMOVE_HEAD(&station->trunks, entry)))
- ast_free(trunk_ref);
- ast_string_field_free_memory(station);
- ast_free(station);
- }
- static void sla_destroy(void)
- {
- struct sla_trunk *trunk;
- struct sla_station *station;
- AST_RWLIST_WRLOCK(&sla_trunks);
- while ((trunk = AST_RWLIST_REMOVE_HEAD(&sla_trunks, entry)))
- destroy_trunk(trunk);
- AST_RWLIST_UNLOCK(&sla_trunks);
- AST_RWLIST_WRLOCK(&sla_stations);
- while ((station = AST_RWLIST_REMOVE_HEAD(&sla_stations, entry)))
- destroy_station(station);
- AST_RWLIST_UNLOCK(&sla_stations);
- if (sla.thread != AST_PTHREADT_NULL) {
- ast_mutex_lock(&sla.lock);
- sla.stop = 1;
- ast_cond_signal(&sla.cond);
- ast_mutex_unlock(&sla.lock);
- pthread_join(sla.thread, NULL);
- }
- /* Drop any created contexts from the dialplan */
- ast_context_destroy(NULL, sla_registrar);
- ast_mutex_destroy(&sla.lock);
- ast_cond_destroy(&sla.cond);
- }
- static int sla_check_device(const char *device)
- {
- char *tech, *tech_data;
- tech_data = ast_strdupa(device);
- tech = strsep(&tech_data, "/");
- if (ast_strlen_zero(tech) || ast_strlen_zero(tech_data))
- return -1;
- return 0;
- }
- static int sla_build_trunk(struct ast_config *cfg, const char *cat)
- {
- struct sla_trunk *trunk;
- struct ast_variable *var;
- const char *dev;
- if (!(dev = ast_variable_retrieve(cfg, cat, "device"))) {
- ast_log(LOG_ERROR, "SLA Trunk '%s' defined with no device!\n", cat);
- return -1;
- }
- if (sla_check_device(dev)) {
- ast_log(LOG_ERROR, "SLA Trunk '%s' define with invalid device '%s'!\n",
- cat, dev);
- return -1;
- }
- if (!(trunk = ast_calloc(1, sizeof(*trunk))))
- return -1;
- if (ast_string_field_init(trunk, 32)) {
- ast_free(trunk);
- return -1;
- }
- ast_string_field_set(trunk, name, cat);
- ast_string_field_set(trunk, device, dev);
- for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
- if (!strcasecmp(var->name, "autocontext"))
- ast_string_field_set(trunk, autocontext, var->value);
- else if (!strcasecmp(var->name, "ringtimeout")) {
- if (sscanf(var->value, "%30u", &trunk->ring_timeout) != 1) {
- ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for trunk '%s'\n",
- var->value, trunk->name);
- trunk->ring_timeout = 0;
- }
- } else if (!strcasecmp(var->name, "barge"))
- trunk->barge_disabled = ast_false(var->value);
- else if (!strcasecmp(var->name, "hold")) {
- if (!strcasecmp(var->value, "private"))
- trunk->hold_access = SLA_HOLD_PRIVATE;
- else if (!strcasecmp(var->value, "open"))
- trunk->hold_access = SLA_HOLD_OPEN;
- else {
- ast_log(LOG_WARNING, "Invalid value '%s' for hold on trunk %s\n",
- var->value, trunk->name);
- }
- } else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
- ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
- var->name, var->lineno, SLA_CONFIG_FILE);
- }
- }
- if (!ast_strlen_zero(trunk->autocontext)) {
- struct ast_context *context;
- context = ast_context_find_or_create(NULL, NULL, trunk->autocontext, sla_registrar);
- if (!context) {
- ast_log(LOG_ERROR, "Failed to automatically find or create "
- "context '%s' for SLA!\n", trunk->autocontext);
- destroy_trunk(trunk);
- return -1;
- }
- if (ast_add_extension2(context, 0 /* don't replace */, "s", 1,
- NULL, NULL, slatrunk_app, ast_strdup(trunk->name), ast_free_ptr, sla_registrar)) {
- ast_log(LOG_ERROR, "Failed to automatically create extension "
- "for trunk '%s'!\n", trunk->name);
- destroy_trunk(trunk);
- return -1;
- }
- }
- AST_RWLIST_WRLOCK(&sla_trunks);
- AST_RWLIST_INSERT_TAIL(&sla_trunks, trunk, entry);
- AST_RWLIST_UNLOCK(&sla_trunks);
- return 0;
- }
- static void sla_add_trunk_to_station(struct sla_station *station, struct ast_variable *var)
- {
- struct sla_trunk *trunk;
- struct sla_trunk_ref *trunk_ref;
- struct sla_station_ref *station_ref;
- char *trunk_name, *options, *cur;
- options = ast_strdupa(var->value);
- trunk_name = strsep(&options, ",");
-
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
- if (!strcasecmp(trunk->name, trunk_name))
- break;
- }
- AST_RWLIST_UNLOCK(&sla_trunks);
- if (!trunk) {
- ast_log(LOG_ERROR, "Trunk '%s' not found!\n", var->value);
- return;
- }
- if (!(trunk_ref = create_trunk_ref(trunk)))
- return;
- trunk_ref->state = SLA_TRUNK_STATE_IDLE;
- while ((cur = strsep(&options, ","))) {
- char *name, *value = cur;
- name = strsep(&value, "=");
- if (!strcasecmp(name, "ringtimeout")) {
- if (sscanf(value, "%30u", &trunk_ref->ring_timeout) != 1) {
- ast_log(LOG_WARNING, "Invalid ringtimeout value '%s' for "
- "trunk '%s' on station '%s'\n", value, trunk->name, station->name);
- trunk_ref->ring_timeout = 0;
- }
- } else if (!strcasecmp(name, "ringdelay")) {
- if (sscanf(value, "%30u", &trunk_ref->ring_delay) != 1) {
- ast_log(LOG_WARNING, "Invalid ringdelay value '%s' for "
- "trunk '%s' on station '%s'\n", value, trunk->name, station->name);
- trunk_ref->ring_delay = 0;
- }
- } else {
- ast_log(LOG_WARNING, "Invalid option '%s' for "
- "trunk '%s' on station '%s'\n", name, trunk->name, station->name);
- }
- }
- if (!(station_ref = sla_create_station_ref(station))) {
- ast_free(trunk_ref);
- return;
- }
- ast_atomic_fetchadd_int((int *) &trunk->num_stations, 1);
- AST_RWLIST_WRLOCK(&sla_trunks);
- AST_LIST_INSERT_TAIL(&trunk->stations, station_ref, entry);
- AST_RWLIST_UNLOCK(&sla_trunks);
- AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
- }
- static int sla_build_station(struct ast_config *cfg, const char *cat)
- {
- struct sla_station *station;
- struct ast_variable *var;
- const char *dev;
- if (!(dev = ast_variable_retrieve(cfg, cat, "device"))) {
- ast_log(LOG_ERROR, "SLA Station '%s' defined with no device!\n", cat);
- return -1;
- }
- if (!(station = ast_calloc(1, sizeof(*station))))
- return -1;
- if (ast_string_field_init(station, 32)) {
- ast_free(station);
- return -1;
- }
- ast_string_field_set(station, name, cat);
- ast_string_field_set(station, device, dev);
- for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
- if (!strcasecmp(var->name, "trunk"))
- sla_add_trunk_to_station(station, var);
- else if (!strcasecmp(var->name, "autocontext"))
- ast_string_field_set(station, autocontext, var->value);
- else if (!strcasecmp(var->name, "ringtimeout")) {
- if (sscanf(var->value, "%30u", &station->ring_timeout) != 1) {
- ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for station '%s'\n",
- var->value, station->name);
- station->ring_timeout = 0;
- }
- } else if (!strcasecmp(var->name, "ringdelay")) {
- if (sscanf(var->value, "%30u", &station->ring_delay) != 1) {
- ast_log(LOG_WARNING, "Invalid ringdelay '%s' specified for station '%s'\n",
- var->value, station->name);
- station->ring_delay = 0;
- }
- } else if (!strcasecmp(var->name, "hold")) {
- if (!strcasecmp(var->value, "private"))
- station->hold_access = SLA_HOLD_PRIVATE;
- else if (!strcasecmp(var->value, "open"))
- station->hold_access = SLA_HOLD_OPEN;
- else {
- ast_log(LOG_WARNING, "Invalid value '%s' for hold on station %s\n",
- var->value, station->name);
- }
- } else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
- ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
- var->name, var->lineno, SLA_CONFIG_FILE);
- }
- }
- if (!ast_strlen_zero(station->autocontext)) {
- struct ast_context *context;
- struct sla_trunk_ref *trunk_ref;
- context = ast_context_find_or_create(NULL, NULL, station->autocontext, sla_registrar);
- if (!context) {
- ast_log(LOG_ERROR, "Failed to automatically find or create "
- "context '%s' for SLA!\n", station->autocontext);
- destroy_station(station);
- return -1;
- }
- /* The extension for when the handset goes off-hook.
- * exten => station1,1,SLAStation(station1) */
- if (ast_add_extension2(context, 0 /* don't replace */, station->name, 1,
- NULL, NULL, slastation_app, ast_strdup(station->name), ast_free_ptr, sla_registrar)) {
- ast_log(LOG_ERROR, "Failed to automatically create extension "
- "for trunk '%s'!\n", station->name);
- destroy_station(station);
- return -1;
- }
- AST_RWLIST_RDLOCK(&sla_trunks);
- AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
- char exten[AST_MAX_EXTENSION];
- char hint[AST_MAX_APP];
- snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
- snprintf(hint, sizeof(hint), "SLA:%s", exten);
- /* Extension for this line button
- * exten => station1_line1,1,SLAStation(station1_line1) */
- if (ast_add_extension2(context, 0 /* don't replace */, exten, 1,
- NULL, NULL, slastation_app, ast_strdup(exten), ast_free_ptr, sla_registrar)) {
- ast_log(LOG_ERROR, "Failed to automatically create extension "
- "for trunk '%s'!\n", station->name);
- destroy_station(station);
- return -1;
- }
- /* Hint for this line button
- * exten => station1_line1,hint,SLA:station1_line1 */
- if (ast_add_extension2(context, 0 /* don't replace */, exten, PRIORITY_HINT,
- NULL, NULL, hint, NULL, NULL, sla_registrar)) {
- ast_log(LOG_ERROR, "Failed to automatically create hint "
- "for trunk '%s'!\n", station->name);
- destroy_station(station);
- return -1;
- }
- }
- AST_RWLIST_UNLOCK(&sla_trunks);
- }
- AST_RWLIST_WRLOCK(&sla_stations);
- AST_RWLIST_INSERT_TAIL(&sla_stations, station, entry);
- AST_RWLIST_UNLOCK(&sla_stations);
- return 0;
- }
- static int sla_load_config(int reload)
- {
- struct ast_config *cfg;
- struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
- const char *cat = NULL;
- int res = 0;
- const char *val;
- if (!reload) {
- ast_mutex_init(&sla.lock);
- ast_cond_init(&sla.cond, NULL);
- }
- if (!(cfg = ast_config_load(SLA_CONFIG_FILE, config_flags)))
- return 0; /* Treat no config as normal */
- else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
- return 0;
- if ((val = ast_variable_retrieve(cfg, "general", "attemptcallerid")))
- sla.attempt_callerid = ast_true(val);
- while ((cat = ast_category_browse(cfg, cat)) && !res) {
- const char *type;
- if (!strcasecmp(cat, "general"))
- continue;
- if (!(type = ast_variable_retrieve(cfg, cat, "type"))) {
- ast_log(LOG_WARNING, "Invalid entry in %s defined with no type!\n",
- SLA_CONFIG_FILE);
- continue;
- }
- if (!strcasecmp(type, "trunk"))
- res = sla_build_trunk(cfg, cat);
- else if (!strcasecmp(type, "station"))
- res = sla_build_station(cfg, cat);
- else {
- ast_log(LOG_WARNING, "Entry in %s defined with invalid type '%s'!\n",
- SLA_CONFIG_FILE, type);
- }
- }
- ast_config_destroy(cfg);
- if (!reload && (!AST_LIST_EMPTY(&sla_stations) || !AST_LIST_EMPTY(&sla_stations)))
- ast_pthread_create(&sla.thread, NULL, sla_thread, NULL);
- return res;
- }
- static int load_config(int reload)
- {
- load_config_meetme();
- if (reload) {
- sla_queue_event(SLA_EVENT_RELOAD);
- ast_log(LOG_NOTICE, "A reload of the SLA configuration has been requested "
- "and will be completed when the system is idle.\n");
- return 0;
- }
-
- return sla_load_config(0);
- }
- static int unload_module(void)
- {
- int res = 0;
-
- ast_cli_unregister_multiple(cli_meetme, ARRAY_LEN(cli_meetme));
- res = ast_manager_unregister("MeetmeMute");
- res |= ast_manager_unregister("MeetmeUnmute");
- res |= ast_manager_unregister("MeetmeList");
- res |= ast_unregister_application(app4);
- res |= ast_unregister_application(app3);
- res |= ast_unregister_application(app2);
- res |= ast_unregister_application(app);
- res |= ast_unregister_application(slastation_app);
- res |= ast_unregister_application(slatrunk_app);
- ast_devstate_prov_del("Meetme");
- ast_devstate_prov_del("SLA");
-
- sla_destroy();
- return res;
- }
- static int load_module(void)
- {
- int res = 0;
- res |= load_config(0);
- ast_cli_register_multiple(cli_meetme, ARRAY_LEN(cli_meetme));
- res |= ast_manager_register("MeetmeMute", EVENT_FLAG_CALL,
- action_meetmemute, "Mute a Meetme user");
- res |= ast_manager_register("MeetmeUnmute", EVENT_FLAG_CALL,
- action_meetmeunmute, "Unmute a Meetme user");
- res |= ast_manager_register2("MeetmeList", EVENT_FLAG_REPORTING,
- action_meetmelist, "List participants in a conference", mandescr_meetmelist);
- res |= ast_register_application(app4, channel_admin_exec, synopsis4, descrip4);
- res |= ast_register_application(app3, admin_exec, synopsis3, descrip3);
- res |= ast_register_application(app2, count_exec, synopsis2, descrip2);
- res |= ast_register_application(app, conf_exec, synopsis, descrip);
- res |= ast_register_application(slastation_app, sla_station_exec,
- slastation_synopsis, slastation_desc);
- res |= ast_register_application(slatrunk_app, sla_trunk_exec,
- slatrunk_synopsis, slatrunk_desc);
- res |= ast_devstate_prov_add("Meetme", meetmestate);
- res |= ast_devstate_prov_add("SLA", sla_state);
- return res;
- }
- static int reload(void)
- {
- return load_config(1);
- }
- AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "MeetMe conference bridge",
- .load = load_module,
- .unload = unload_module,
- .reload = reload,
- );
|