app_meetme.c 247 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2007, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * SLA Implementation by:
  9. * Russell Bryant <russell@digium.com>
  10. *
  11. * See http://www.asterisk.org for more information about
  12. * the Asterisk project. Please do not directly contact
  13. * any of the maintainers of this project for assistance;
  14. * the project provides a web site, mailing lists and IRC
  15. * channels for your use.
  16. *
  17. * This program is free software, distributed under the terms of
  18. * the GNU General Public License Version 2. See the LICENSE file
  19. * at the top of the source tree.
  20. */
  21. /*! \file
  22. *
  23. * \brief Meet me conference bridge and Shared Line Appearances
  24. *
  25. * \author Mark Spencer <markster@digium.com>
  26. * \author (SLA) Russell Bryant <russell@digium.com>
  27. *
  28. * \ingroup applications
  29. */
  30. /*! \li \ref app_meetme.c uses configuration file \ref meetme.conf
  31. * \addtogroup configuration_file Configuration Files
  32. */
  33. /*!
  34. * \page meetme.conf meetme.conf
  35. * \verbinclude meetme.conf.sample
  36. */
  37. /*** MODULEINFO
  38. <depend>dahdi</depend>
  39. <defaultenabled>no</defaultenabled>
  40. <support_level>extended</support_level>
  41. <replacement>app_confbridge</replacement>
  42. ***/
  43. #include "asterisk.h"
  44. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  45. #include <dahdi/user.h>
  46. #include "asterisk/lock.h"
  47. #include "asterisk/file.h"
  48. #include "asterisk/channel.h"
  49. #include "asterisk/pbx.h"
  50. #include "asterisk/module.h"
  51. #include "asterisk/config.h"
  52. #include "asterisk/app.h"
  53. #include "asterisk/dsp.h"
  54. #include "asterisk/musiconhold.h"
  55. #include "asterisk/manager.h"
  56. #include "asterisk/cli.h"
  57. #include "asterisk/say.h"
  58. #include "asterisk/utils.h"
  59. #include "asterisk/translate.h"
  60. #include "asterisk/ulaw.h"
  61. #include "asterisk/astobj2.h"
  62. #include "asterisk/devicestate.h"
  63. #include "asterisk/dial.h"
  64. #include "asterisk/causes.h"
  65. #include "asterisk/paths.h"
  66. #include "asterisk/data.h"
  67. #include "asterisk/test.h"
  68. #include "asterisk/stasis.h"
  69. #include "asterisk/stasis_channels.h"
  70. #include "asterisk/stasis_message_router.h"
  71. #include "asterisk/json.h"
  72. #include "asterisk/format_compatibility.h"
  73. #include "enter.h"
  74. #include "leave.h"
  75. /*** DOCUMENTATION
  76. <application name="MeetMe" language="en_US">
  77. <synopsis>
  78. MeetMe conference bridge.
  79. </synopsis>
  80. <syntax>
  81. <parameter name="confno">
  82. <para>The conference number</para>
  83. </parameter>
  84. <parameter name="options">
  85. <optionlist>
  86. <option name="a">
  87. <para>Set admin mode.</para>
  88. </option>
  89. <option name="A">
  90. <para>Set marked mode.</para>
  91. </option>
  92. <option name="b">
  93. <para>Run AGI script specified in <variable>MEETME_AGI_BACKGROUND</variable>
  94. Default: <literal>conf-background.agi</literal>.</para>
  95. <note><para>This does not work with non-DAHDI channels in the same
  96. conference).</para></note>
  97. </option>
  98. <option name="c">
  99. <para>Announce user(s) count on joining a conference.</para>
  100. </option>
  101. <option name="C">
  102. <para>Continue in dialplan when kicked out of conference.</para>
  103. </option>
  104. <option name="d">
  105. <para>Dynamically add conference.</para>
  106. </option>
  107. <option name="D">
  108. <para>Dynamically add conference, prompting for a PIN.</para>
  109. </option>
  110. <option name="e">
  111. <para>Select an empty conference.</para>
  112. </option>
  113. <option name="E">
  114. <para>Select an empty pinless conference.</para>
  115. </option>
  116. <option name="F">
  117. <para>Pass DTMF through the conference.</para>
  118. </option>
  119. <option name="G">
  120. <argument name="x" required="true">
  121. <para>The file to playback</para>
  122. </argument>
  123. <para>Play an intro announcement in conference.</para>
  124. </option>
  125. <option name="i">
  126. <para>Announce user join/leave with review.</para>
  127. </option>
  128. <option name="I">
  129. <para>Announce user join/leave without review.</para>
  130. </option>
  131. <option name="k">
  132. <para>Close the conference if there's only one active participant left at exit.</para>
  133. </option>
  134. <option name="l">
  135. <para>Set listen only mode (Listen only, no talking).</para>
  136. </option>
  137. <option name="m">
  138. <para>Set initially muted.</para>
  139. </option>
  140. <option name="M" hasparams="optional">
  141. <para>Enable music on hold when the conference has a single caller. Optionally,
  142. specify a musiconhold class to use. If one is not provided, it will use the
  143. channel's currently set music class, or <literal>default</literal>.</para>
  144. <argument name="class" required="true" />
  145. </option>
  146. <option name="n">
  147. <para>Disable the denoiser. By default, if <literal>func_speex</literal> is loaded, Asterisk
  148. will apply a denoiser to channels in the MeetMe conference. However, channel
  149. drivers that present audio with a varying rate will experience degraded
  150. performance with a denoiser attached. This parameter allows a channel joining
  151. the conference to choose not to have a denoiser attached without having to
  152. unload <literal>func_speex</literal>.</para>
  153. </option>
  154. <option name="o">
  155. <para>Set talker optimization - treats talkers who aren't speaking as
  156. being muted, meaning (a) No encode is done on transmission and (b)
  157. Received audio that is not registered as talking is omitted causing no
  158. buildup in background noise.</para>
  159. </option>
  160. <option name="p" hasparams="optional">
  161. <para>Allow user to exit the conference by pressing <literal>#</literal> (default)
  162. or any of the defined keys. Dial plan execution will continue at the next
  163. priority following MeetMe. The key used is set to channel variable
  164. <variable>MEETME_EXIT_KEY</variable>.</para>
  165. <argument name="keys" required="true" />
  166. <note>
  167. <para>Option <literal>s</literal> has priority for <literal>*</literal>
  168. since it cannot change its activation code.</para>
  169. </note>
  170. </option>
  171. <option name="P">
  172. <para>Always prompt for the pin even if it is specified.</para>
  173. </option>
  174. <option name="q">
  175. <para>Quiet mode (don't play enter/leave sounds).</para>
  176. </option>
  177. <option name="r">
  178. <para>Record conference (records as <variable>MEETME_RECORDINGFILE</variable>
  179. using format <variable>MEETME_RECORDINGFORMAT</variable>. Default filename is
  180. <literal>meetme-conf-rec-${CONFNO}-${UNIQUEID}</literal> and the default format is
  181. wav.</para>
  182. </option>
  183. <option name="s">
  184. <para>Present menu (user or admin) when <literal>*</literal> is received
  185. (send to menu).</para>
  186. </option>
  187. <option name="t">
  188. <para>Set talk only mode. (Talk only, no listening).</para>
  189. </option>
  190. <option name="T">
  191. <para>Set talker detection (sent to manager interface and meetme list).</para>
  192. </option>
  193. <option name="v" hasparams="optional">
  194. <para>Announce when a user is joining or leaving the conference. Use the voicemail greeting as the announcement.
  195. If the i or I options are set, the application will fall back to them if no voicemail greeting can be found.</para>
  196. <argument name="mailbox@[context]" required="true">
  197. <para>The mailbox and voicemail context to play from. If no context provided, assumed context is default.</para>
  198. </argument>
  199. </option>
  200. <option name="w" hasparams="optional">
  201. <para>Wait until the marked user enters the conference.</para>
  202. <argument name="secs" required="true" />
  203. </option>
  204. <option name="x">
  205. <para>Leave the conference when the last marked user leaves.</para>
  206. </option>
  207. <option name="X">
  208. <para>Allow user to exit the conference by entering a valid single digit
  209. extension <variable>MEETME_EXIT_CONTEXT</variable> or the current context
  210. if that variable is not defined.</para>
  211. <note>
  212. <para>Option <literal>s</literal> has priority for <literal>*</literal>
  213. since it cannot change its activation code.</para>
  214. </note>
  215. </option>
  216. <option name="1">
  217. <para>Do not play message when first person enters</para>
  218. </option>
  219. <option name="S">
  220. <para>Kick the user <replaceable>x</replaceable> seconds <emphasis>after</emphasis> he entered into
  221. the conference.</para>
  222. <argument name="x" required="true" />
  223. </option>
  224. <option name="L" argsep=":">
  225. <para>Limit the conference to <replaceable>x</replaceable> ms. Play a warning when
  226. <replaceable>y</replaceable> ms are left. Repeat the warning every <replaceable>z</replaceable> ms.
  227. The following special variables can be used with this option:</para>
  228. <variablelist>
  229. <variable name="CONF_LIMIT_TIMEOUT_FILE">
  230. <para>File to play when time is up.</para>
  231. </variable>
  232. <variable name="CONF_LIMIT_WARNING_FILE">
  233. <para>File to play as warning if <replaceable>y</replaceable> is defined. The
  234. default is to say the time remaining.</para>
  235. </variable>
  236. </variablelist>
  237. <argument name="x" />
  238. <argument name="y" />
  239. <argument name="z" />
  240. </option>
  241. </optionlist>
  242. </parameter>
  243. <parameter name="pin" />
  244. </syntax>
  245. <description>
  246. <para>Enters the user into a specified MeetMe conference. If the <replaceable>confno</replaceable>
  247. is omitted, the user will be prompted to enter one. User can exit the conference by hangup, or
  248. if the <literal>p</literal> option is specified, by pressing <literal>#</literal>.</para>
  249. <note><para>The DAHDI kernel modules and a functional DAHDI timing source (see dahdi_test)
  250. must be present for conferencing to operate properly. In addition, the chan_dahdi channel driver
  251. must be loaded for the <literal>i</literal> and <literal>r</literal> options to operate at
  252. all.</para></note>
  253. </description>
  254. <see-also>
  255. <ref type="application">MeetMeCount</ref>
  256. <ref type="application">MeetMeAdmin</ref>
  257. <ref type="application">MeetMeChannelAdmin</ref>
  258. </see-also>
  259. </application>
  260. <application name="MeetMeCount" language="en_US">
  261. <synopsis>
  262. MeetMe participant count.
  263. </synopsis>
  264. <syntax>
  265. <parameter name="confno" required="true">
  266. <para>Conference number.</para>
  267. </parameter>
  268. <parameter name="var" />
  269. </syntax>
  270. <description>
  271. <para>Plays back the number of users in the specified MeetMe conference.
  272. If <replaceable>var</replaceable> is specified, playback will be skipped and the value
  273. will be returned in the variable. Upon application completion, MeetMeCount will hangup
  274. the channel, unless priority <literal>n+1</literal> exists, in which case priority progress will
  275. continue.</para>
  276. </description>
  277. <see-also>
  278. <ref type="application">MeetMe</ref>
  279. </see-also>
  280. </application>
  281. <application name="MeetMeAdmin" language="en_US">
  282. <synopsis>
  283. MeetMe conference administration.
  284. </synopsis>
  285. <syntax>
  286. <parameter name="confno" required="true" />
  287. <parameter name="command" required="true">
  288. <optionlist>
  289. <option name="e">
  290. <para>Eject last user that joined.</para>
  291. </option>
  292. <option name="E">
  293. <para>Extend conference end time, if scheduled.</para>
  294. </option>
  295. <option name="k">
  296. <para>Kick one user out of conference.</para>
  297. </option>
  298. <option name="K">
  299. <para>Kick all users out of conference.</para>
  300. </option>
  301. <option name="l">
  302. <para>Unlock conference.</para>
  303. </option>
  304. <option name="L">
  305. <para>Lock conference.</para>
  306. </option>
  307. <option name="m">
  308. <para>Unmute one user.</para>
  309. </option>
  310. <option name="M">
  311. <para>Mute one user.</para>
  312. </option>
  313. <option name="n">
  314. <para>Unmute all users in the conference.</para>
  315. </option>
  316. <option name="N">
  317. <para>Mute all non-admin users in the conference.</para>
  318. </option>
  319. <option name="r">
  320. <para>Reset one user's volume settings.</para>
  321. </option>
  322. <option name="R">
  323. <para>Reset all users volume settings.</para>
  324. </option>
  325. <option name="s">
  326. <para>Lower entire conference speaking volume.</para>
  327. </option>
  328. <option name="S">
  329. <para>Raise entire conference speaking volume.</para>
  330. </option>
  331. <option name="t">
  332. <para>Lower one user's talk volume.</para>
  333. </option>
  334. <option name="T">
  335. <para>Raise one user's talk volume.</para>
  336. </option>
  337. <option name="u">
  338. <para>Lower one user's listen volume.</para>
  339. </option>
  340. <option name="U">
  341. <para>Raise one user's listen volume.</para>
  342. </option>
  343. <option name="v">
  344. <para>Lower entire conference listening volume.</para>
  345. </option>
  346. <option name="V">
  347. <para>Raise entire conference listening volume.</para>
  348. </option>
  349. </optionlist>
  350. </parameter>
  351. <parameter name="user" />
  352. </syntax>
  353. <description>
  354. <para>Run admin <replaceable>command</replaceable> for conference <replaceable>confno</replaceable>.</para>
  355. <para>Will additionally set the variable <variable>MEETMEADMINSTATUS</variable> with one of
  356. the following values:</para>
  357. <variablelist>
  358. <variable name="MEETMEADMINSTATUS">
  359. <value name="NOPARSE">
  360. Invalid arguments.
  361. </value>
  362. <value name="NOTFOUND">
  363. User specified was not found.
  364. </value>
  365. <value name="FAILED">
  366. Another failure occurred.
  367. </value>
  368. <value name="OK">
  369. The operation was completed successfully.
  370. </value>
  371. </variable>
  372. </variablelist>
  373. </description>
  374. <see-also>
  375. <ref type="application">MeetMe</ref>
  376. </see-also>
  377. </application>
  378. <application name="MeetMeChannelAdmin" language="en_US">
  379. <synopsis>
  380. MeetMe conference Administration (channel specific).
  381. </synopsis>
  382. <syntax>
  383. <parameter name="channel" required="true" />
  384. <parameter name="command" required="true">
  385. <optionlist>
  386. <option name="k">
  387. <para>Kick the specified user out of the conference he is in.</para>
  388. </option>
  389. <option name="m">
  390. <para>Unmute the specified user.</para>
  391. </option>
  392. <option name="M">
  393. <para>Mute the specified user.</para>
  394. </option>
  395. </optionlist>
  396. </parameter>
  397. </syntax>
  398. <description>
  399. <para>Run admin <replaceable>command</replaceable> for a specific
  400. <replaceable>channel</replaceable> in any conference.</para>
  401. </description>
  402. </application>
  403. <application name="SLAStation" language="en_US">
  404. <synopsis>
  405. Shared Line Appearance Station.
  406. </synopsis>
  407. <syntax>
  408. <parameter name="station" required="true">
  409. <para>Station name</para>
  410. </parameter>
  411. </syntax>
  412. <description>
  413. <para>This application should be executed by an SLA station. The argument depends
  414. on how the call was initiated. If the phone was just taken off hook, then the argument
  415. <replaceable>station</replaceable> should be just the station name. If the call was
  416. initiated by pressing a line key, then the station name should be preceded by an underscore
  417. and the trunk name associated with that line button.</para>
  418. <para>For example: <literal>station1_line1</literal></para>
  419. <para>On exit, this application will set the variable <variable>SLASTATION_STATUS</variable> to
  420. one of the following values:</para>
  421. <variablelist>
  422. <variable name="SLASTATION_STATUS">
  423. <value name="FAILURE" />
  424. <value name="CONGESTION" />
  425. <value name="SUCCESS" />
  426. </variable>
  427. </variablelist>
  428. </description>
  429. </application>
  430. <application name="SLATrunk" language="en_US">
  431. <synopsis>
  432. Shared Line Appearance Trunk.
  433. </synopsis>
  434. <syntax>
  435. <parameter name="trunk" required="true">
  436. <para>Trunk name</para>
  437. </parameter>
  438. <parameter name="options">
  439. <optionlist>
  440. <option name="M" hasparams="optional">
  441. <para>Play back the specified MOH <replaceable>class</replaceable>
  442. instead of ringing</para>
  443. <argument name="class" required="true" />
  444. </option>
  445. </optionlist>
  446. </parameter>
  447. </syntax>
  448. <description>
  449. <para>This application should be executed by an SLA trunk on an inbound call. The channel calling
  450. this application should correspond to the SLA trunk with the name <replaceable>trunk</replaceable>
  451. that is being passed as an argument.</para>
  452. <para>On exit, this application will set the variable <variable>SLATRUNK_STATUS</variable> to
  453. one of the following values:</para>
  454. <variablelist>
  455. <variable name="SLATRUNK_STATUS">
  456. <value name="FAILURE" />
  457. <value name="SUCCESS" />
  458. <value name="UNANSWERED" />
  459. <value name="RINGTIMEOUT" />
  460. </variable>
  461. </variablelist>
  462. </description>
  463. </application>
  464. <function name="MEETME_INFO" language="en_US">
  465. <synopsis>
  466. Query a given conference of various properties.
  467. </synopsis>
  468. <syntax>
  469. <parameter name="keyword" required="true">
  470. <para>Options:</para>
  471. <enumlist>
  472. <enum name="lock">
  473. <para>Boolean of whether the corresponding conference is locked.</para>
  474. </enum>
  475. <enum name="parties">
  476. <para>Number of parties in a given conference</para>
  477. </enum>
  478. <enum name="activity">
  479. <para>Duration of conference in seconds.</para>
  480. </enum>
  481. <enum name="dynamic">
  482. <para>Boolean of whether the corresponding conference is dynamic.</para>
  483. </enum>
  484. </enumlist>
  485. </parameter>
  486. <parameter name="confno" required="true">
  487. <para>Conference number to retrieve information from.</para>
  488. </parameter>
  489. </syntax>
  490. <description />
  491. <see-also>
  492. <ref type="application">MeetMe</ref>
  493. <ref type="application">MeetMeCount</ref>
  494. <ref type="application">MeetMeAdmin</ref>
  495. <ref type="application">MeetMeChannelAdmin</ref>
  496. </see-also>
  497. </function>
  498. <manager name="MeetmeMute" language="en_US">
  499. <synopsis>
  500. Mute a Meetme user.
  501. </synopsis>
  502. <syntax>
  503. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  504. <parameter name="Meetme" required="true" />
  505. <parameter name="Usernum" required="true" />
  506. </syntax>
  507. <description>
  508. </description>
  509. </manager>
  510. <manager name="MeetmeUnmute" language="en_US">
  511. <synopsis>
  512. Unmute a Meetme user.
  513. </synopsis>
  514. <syntax>
  515. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  516. <parameter name="Meetme" required="true" />
  517. <parameter name="Usernum" required="true" />
  518. </syntax>
  519. <description>
  520. </description>
  521. </manager>
  522. <manager name="MeetmeList" language="en_US">
  523. <synopsis>
  524. List participants in a conference.
  525. </synopsis>
  526. <syntax>
  527. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  528. <parameter name="Conference" required="false">
  529. <para>Conference number.</para>
  530. </parameter>
  531. </syntax>
  532. <description>
  533. <para>Lists all users in a particular MeetMe conference.
  534. MeetmeList will follow as separate events, followed by a final event called
  535. MeetmeListComplete.</para>
  536. </description>
  537. </manager>
  538. <manager name="MeetmeListRooms" language="en_US">
  539. <synopsis>
  540. List active conferences.
  541. </synopsis>
  542. <syntax>
  543. <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
  544. </syntax>
  545. <description>
  546. <para>Lists data about all active conferences.
  547. MeetmeListRooms will follow as separate events, followed by a final event called
  548. MeetmeListRoomsComplete.</para>
  549. </description>
  550. </manager>
  551. <managerEvent language="en_US" name="MeetmeJoin">
  552. <managerEventInstance class="EVENT_FLAG_CALL">
  553. <synopsis>Raised when a user joins a MeetMe conference.</synopsis>
  554. <syntax>
  555. <parameter name="Meetme">
  556. <para>The identifier for the MeetMe conference.</para>
  557. </parameter>
  558. <parameter name="User">
  559. <para>The identifier of the MeetMe user who joined.</para>
  560. </parameter>
  561. <channel_snapshot/>
  562. </syntax>
  563. <see-also>
  564. <ref type="managerEvent">MeetmeLeave</ref>
  565. <ref type="application">MeetMe</ref>
  566. </see-also>
  567. </managerEventInstance>
  568. </managerEvent>
  569. <managerEvent language="en_US" name="MeetmeLeave">
  570. <managerEventInstance class="EVENT_FLAG_CALL">
  571. <synopsis>Raised when a user leaves a MeetMe conference.</synopsis>
  572. <syntax>
  573. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeJoin']/managerEventInstance/syntax/parameter)" />
  574. <channel_snapshot/>
  575. <parameter name="Duration">
  576. <para>The length of time in seconds that the Meetme user was in the conference.</para>
  577. </parameter>
  578. </syntax>
  579. <see-also>
  580. <ref type="managerEvent">MeetmeJoin</ref>
  581. </see-also>
  582. </managerEventInstance>
  583. </managerEvent>
  584. <managerEvent language="en_US" name="MeetmeEnd">
  585. <managerEventInstance class="EVENT_FLAG_CALL">
  586. <synopsis>Raised when a MeetMe conference ends.</synopsis>
  587. <syntax>
  588. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeJoin']/managerEventInstance/syntax/parameter[@name='Meetme'])" />
  589. </syntax>
  590. <see-also>
  591. <ref type="managerEvent">MeetmeJoin</ref>
  592. </see-also>
  593. </managerEventInstance>
  594. </managerEvent>
  595. <managerEvent language="en_US" name="MeetmeTalkRequest">
  596. <managerEventInstance class="EVENT_FLAG_CALL">
  597. <synopsis>Raised when a MeetMe user has started talking.</synopsis>
  598. <syntax>
  599. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeJoin']/managerEventInstance/syntax/parameter)" />
  600. <channel_snapshot/>
  601. <parameter name="Duration">
  602. <para>The length of time in seconds that the Meetme user has been in the conference at the time of this event.</para>
  603. </parameter>
  604. <parameter name="Status">
  605. <enumlist>
  606. <enum name="on"/>
  607. <enum name="off"/>
  608. </enumlist>
  609. </parameter>
  610. </syntax>
  611. </managerEventInstance>
  612. </managerEvent>
  613. <managerEvent language="en_US" name="MeetmeTalking">
  614. <managerEventInstance class="EVENT_FLAG_CALL">
  615. <synopsis>Raised when a MeetMe user begins or ends talking.</synopsis>
  616. <syntax>
  617. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeJoin']/managerEventInstance/syntax/parameter)" />
  618. <channel_snapshot/>
  619. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeTalkRequest']/managerEventInstance/syntax/parameter)" />
  620. </syntax>
  621. </managerEventInstance>
  622. </managerEvent>
  623. <managerEvent language="en_US" name="MeetmeMute">
  624. <managerEventInstance class="EVENT_FLAG_CALL">
  625. <synopsis>Raised when a MeetMe user is muted or unmuted.</synopsis>
  626. <syntax>
  627. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeJoin']/managerEventInstance/syntax/parameter)" />
  628. <channel_snapshot/>
  629. <xi:include xpointer="xpointer(/docs/managerEvent[@name='MeetmeTalkRequest']/managerEventInstance/syntax/parameter)" />
  630. </syntax>
  631. </managerEventInstance>
  632. </managerEvent>
  633. ***/
  634. #define CONFIG_FILE_NAME "meetme.conf"
  635. #define SLA_CONFIG_FILE "sla.conf"
  636. #define STR_CONCISE "concise"
  637. /*! each buffer is 20ms, so this is 640ms total */
  638. #define DEFAULT_AUDIO_BUFFERS 32
  639. /*! String format for scheduled conferences */
  640. #define DATE_FORMAT "%Y-%m-%d %H:%M:%S"
  641. enum {
  642. ADMINFLAG_MUTED = (1 << 1), /*!< User is muted */
  643. ADMINFLAG_SELFMUTED = (1 << 2), /*!< User muted self */
  644. ADMINFLAG_KICKME = (1 << 3), /*!< User has been kicked */
  645. /*! User has requested to speak */
  646. ADMINFLAG_T_REQUEST = (1 << 4),
  647. ADMINFLAG_HANGUP = (1 << 5), /*!< User will be leaving the conference */
  648. };
  649. #define MEETME_DELAYDETECTTALK 300
  650. #define MEETME_DELAYDETECTENDTALK 1000
  651. #define AST_FRAME_BITS 32
  652. enum volume_action {
  653. VOL_UP,
  654. VOL_DOWN
  655. };
  656. enum entrance_sound {
  657. ENTER,
  658. LEAVE
  659. };
  660. enum recording_state {
  661. MEETME_RECORD_OFF,
  662. MEETME_RECORD_STARTED,
  663. MEETME_RECORD_ACTIVE,
  664. MEETME_RECORD_TERMINATE
  665. };
  666. #define CONF_SIZE 320
  667. enum {
  668. /*! user has admin access on the conference */
  669. CONFFLAG_ADMIN = (1 << 0),
  670. /*! If set the user can only receive audio from the conference */
  671. CONFFLAG_MONITOR = (1 << 1),
  672. /*! If set asterisk will exit conference when key defined in p() option is pressed */
  673. CONFFLAG_KEYEXIT = (1 << 2),
  674. /*! If set asterisk will provide a menu to the user when '*' is pressed */
  675. CONFFLAG_STARMENU = (1 << 3),
  676. /*! If set the use can only send audio to the conference */
  677. CONFFLAG_TALKER = (1 << 4),
  678. /*! If set there will be no enter or leave sounds */
  679. CONFFLAG_QUIET = (1 << 5),
  680. /*! If set, when user joins the conference, they will be told the number
  681. * of users that are already in */
  682. CONFFLAG_ANNOUNCEUSERCOUNT = (1 << 6),
  683. /*! Set to run AGI Script in Background */
  684. CONFFLAG_AGI = (1 << 7),
  685. /*! Set to have music on hold when user is alone in conference */
  686. CONFFLAG_MOH = (1 << 8),
  687. /*! If set, the channel will leave the conference if all marked users leave */
  688. CONFFLAG_MARKEDEXIT = (1 << 9),
  689. /*! If set, the MeetMe will wait until a marked user enters */
  690. CONFFLAG_WAITMARKED = (1 << 10),
  691. /*! If set, the MeetMe will exit to the specified context */
  692. CONFFLAG_EXIT_CONTEXT = (1 << 11),
  693. /*! If set, the user will be marked */
  694. CONFFLAG_MARKEDUSER = (1 << 12),
  695. /*! If set, user will be ask record name on entry of conference */
  696. CONFFLAG_INTROUSER = (1 << 13),
  697. /*! If set, the MeetMe will be recorded */
  698. CONFFLAG_RECORDCONF = (1<< 14),
  699. /*! If set, the user will be monitored if the user is talking or not */
  700. CONFFLAG_MONITORTALKER = (1 << 15),
  701. CONFFLAG_DYNAMIC = (1 << 16),
  702. CONFFLAG_DYNAMICPIN = (1 << 17),
  703. CONFFLAG_EMPTY = (1 << 18),
  704. CONFFLAG_EMPTYNOPIN = (1 << 19),
  705. CONFFLAG_ALWAYSPROMPT = (1 << 20),
  706. /*! If set, treat talking users as muted users */
  707. CONFFLAG_OPTIMIZETALKER = (1 << 21),
  708. /*! If set, won't speak the extra prompt when the first person
  709. * enters the conference */
  710. CONFFLAG_NOONLYPERSON = (1 << 22),
  711. /*! If set, user will be asked to record name on entry of conference
  712. * without review */
  713. CONFFLAG_INTROUSERNOREVIEW = (1 << 23),
  714. /*! If set, the user will be initially self-muted */
  715. CONFFLAG_STARTMUTED = (1 << 24),
  716. /*! Pass DTMF through the conference */
  717. CONFFLAG_PASS_DTMF = (1 << 25),
  718. CONFFLAG_SLA_STATION = (1 << 26),
  719. CONFFLAG_SLA_TRUNK = (1 << 27),
  720. /*! If set, the user should continue in the dialplan if kicked out */
  721. CONFFLAG_KICK_CONTINUE = (1 << 28),
  722. CONFFLAG_DURATION_STOP = (1 << 29),
  723. CONFFLAG_DURATION_LIMIT = (1 << 30),
  724. };
  725. /* These flags are defined separately because we ran out of bits that an enum can be used to represent.
  726. If you add new flags, be sure to do it in the same way that these are. */
  727. /*! Do not write any audio to this channel until the state is up. */
  728. #define CONFFLAG_NO_AUDIO_UNTIL_UP (1ULL << 31)
  729. #define CONFFLAG_INTROMSG (1ULL << 32) /*!< If set play an intro announcement at start of conference */
  730. #define CONFFLAG_INTROUSER_VMREC (1ULL << 33)
  731. /*! If there's only one person left in a conference when someone leaves, kill the conference */
  732. #define CONFFLAG_KILL_LAST_MAN_STANDING (1ULL << 34)
  733. /*! If set, don't enable a denoiser for the channel */
  734. #define CONFFLAG_DONT_DENOISE (1ULL << 35)
  735. enum {
  736. OPT_ARG_WAITMARKED = 0,
  737. OPT_ARG_EXITKEYS = 1,
  738. OPT_ARG_DURATION_STOP = 2,
  739. OPT_ARG_DURATION_LIMIT = 3,
  740. OPT_ARG_MOH_CLASS = 4,
  741. OPT_ARG_INTROMSG = 5,
  742. OPT_ARG_INTROUSER_VMREC = 6,
  743. OPT_ARG_ARRAY_SIZE = 7,
  744. };
  745. AST_APP_OPTIONS(meetme_opts, BEGIN_OPTIONS
  746. AST_APP_OPTION('A', CONFFLAG_MARKEDUSER ),
  747. AST_APP_OPTION('a', CONFFLAG_ADMIN ),
  748. AST_APP_OPTION('b', CONFFLAG_AGI ),
  749. AST_APP_OPTION('c', CONFFLAG_ANNOUNCEUSERCOUNT ),
  750. AST_APP_OPTION('C', CONFFLAG_KICK_CONTINUE),
  751. AST_APP_OPTION('D', CONFFLAG_DYNAMICPIN ),
  752. AST_APP_OPTION('d', CONFFLAG_DYNAMIC ),
  753. AST_APP_OPTION('E', CONFFLAG_EMPTYNOPIN ),
  754. AST_APP_OPTION('e', CONFFLAG_EMPTY ),
  755. AST_APP_OPTION('F', CONFFLAG_PASS_DTMF ),
  756. AST_APP_OPTION_ARG('G', CONFFLAG_INTROMSG, OPT_ARG_INTROMSG ),
  757. AST_APP_OPTION_ARG('v', CONFFLAG_INTROUSER_VMREC , OPT_ARG_INTROUSER_VMREC),
  758. AST_APP_OPTION('i', CONFFLAG_INTROUSER ),
  759. AST_APP_OPTION('I', CONFFLAG_INTROUSERNOREVIEW ),
  760. AST_APP_OPTION('k', CONFFLAG_KILL_LAST_MAN_STANDING ),
  761. AST_APP_OPTION_ARG('M', CONFFLAG_MOH, OPT_ARG_MOH_CLASS ),
  762. AST_APP_OPTION('m', CONFFLAG_STARTMUTED ),
  763. AST_APP_OPTION('n', CONFFLAG_DONT_DENOISE ),
  764. AST_APP_OPTION('o', CONFFLAG_OPTIMIZETALKER ),
  765. AST_APP_OPTION('P', CONFFLAG_ALWAYSPROMPT ),
  766. AST_APP_OPTION_ARG('p', CONFFLAG_KEYEXIT, OPT_ARG_EXITKEYS ),
  767. AST_APP_OPTION('q', CONFFLAG_QUIET ),
  768. AST_APP_OPTION('r', CONFFLAG_RECORDCONF ),
  769. AST_APP_OPTION('s', CONFFLAG_STARMENU ),
  770. AST_APP_OPTION('T', CONFFLAG_MONITORTALKER ),
  771. AST_APP_OPTION('l', CONFFLAG_MONITOR ),
  772. AST_APP_OPTION('t', CONFFLAG_TALKER ),
  773. AST_APP_OPTION_ARG('w', CONFFLAG_WAITMARKED, OPT_ARG_WAITMARKED ),
  774. AST_APP_OPTION('X', CONFFLAG_EXIT_CONTEXT ),
  775. AST_APP_OPTION('x', CONFFLAG_MARKEDEXIT ),
  776. AST_APP_OPTION('1', CONFFLAG_NOONLYPERSON ),
  777. AST_APP_OPTION_ARG('S', CONFFLAG_DURATION_STOP, OPT_ARG_DURATION_STOP),
  778. AST_APP_OPTION_ARG('L', CONFFLAG_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT),
  779. END_OPTIONS );
  780. static const char * const app = "MeetMe";
  781. static const char * const app2 = "MeetMeCount";
  782. static const char * const app3 = "MeetMeAdmin";
  783. static const char * const app4 = "MeetMeChannelAdmin";
  784. static const char * const slastation_app = "SLAStation";
  785. static const char * const slatrunk_app = "SLATrunk";
  786. /* Lookup RealTime conferences based on confno and current time */
  787. static int rt_schedule;
  788. static int fuzzystart;
  789. static int earlyalert;
  790. static int endalert;
  791. static int extendby;
  792. /*! Log participant count to the RealTime backend */
  793. static int rt_log_members;
  794. #define MAX_CONFNUM 80
  795. #define MAX_PIN 80
  796. #define OPTIONS_LEN 100
  797. /* Enough space for "<conference #>,<pin>,<admin pin>" followed by a 0 byte. */
  798. #define MAX_SETTINGS (MAX_CONFNUM + MAX_PIN + MAX_PIN + 3)
  799. enum announcetypes {
  800. CONF_HASJOIN,
  801. CONF_HASLEFT
  802. };
  803. struct announce_listitem {
  804. AST_LIST_ENTRY(announce_listitem) entry;
  805. char namerecloc[PATH_MAX]; /*!< Name Recorded file Location */
  806. char language[MAX_LANGUAGE];
  807. struct ast_channel *confchan;
  808. int confusers;
  809. int vmrec;
  810. enum announcetypes announcetype;
  811. };
  812. /*! \brief The MeetMe Conference object */
  813. struct ast_conference {
  814. ast_mutex_t playlock; /*!< Conference specific lock (players) */
  815. ast_mutex_t listenlock; /*!< Conference specific lock (listeners) */
  816. char confno[MAX_CONFNUM]; /*!< Conference */
  817. struct ast_channel *chan; /*!< Announcements channel */
  818. struct ast_channel *lchan; /*!< Listen/Record channel */
  819. int fd; /*!< Announcements fd */
  820. int dahdiconf; /*!< DAHDI Conf # */
  821. int users; /*!< Number of active users */
  822. int markedusers; /*!< Number of marked users */
  823. int maxusers; /*!< Participant limit if scheduled */
  824. int endalert; /*!< When to play conf ending message */
  825. time_t start; /*!< Start time (s) */
  826. int refcount; /*!< reference count of usage */
  827. enum recording_state recording:2; /*!< recording status */
  828. unsigned int isdynamic:1; /*!< Created on the fly? */
  829. unsigned int locked:1; /*!< Is the conference locked? */
  830. unsigned int gmuted:1; /*!< Is the conference globally muted? (all non-admins) */
  831. pthread_t recordthread; /*!< thread for recording */
  832. ast_mutex_t recordthreadlock; /*!< control threads trying to start recordthread */
  833. pthread_attr_t attr; /*!< thread attribute */
  834. char *recordingfilename; /*!< Filename to record the Conference into */
  835. char *recordingformat; /*!< Format to record the Conference in */
  836. char pin[MAX_PIN]; /*!< If protected by a PIN */
  837. char pinadmin[MAX_PIN]; /*!< If protected by a admin PIN */
  838. char uniqueid[32];
  839. long endtime; /*!< When to end the conf if scheduled */
  840. const char *useropts; /*!< RealTime user flags */
  841. const char *adminopts; /*!< RealTime moderator flags */
  842. const char *bookid; /*!< RealTime conference id */
  843. struct ast_frame *transframe[32];
  844. struct ast_frame *origframe;
  845. struct ast_trans_pvt *transpath[32];
  846. struct ao2_container *usercontainer;
  847. AST_LIST_ENTRY(ast_conference) list;
  848. /* announce_thread related data */
  849. pthread_t announcethread;
  850. ast_mutex_t announcethreadlock;
  851. unsigned int announcethread_stop:1;
  852. ast_cond_t announcelist_addition;
  853. AST_LIST_HEAD_NOLOCK(, announce_listitem) announcelist;
  854. ast_mutex_t announcelistlock;
  855. };
  856. static AST_LIST_HEAD_STATIC(confs, ast_conference);
  857. static unsigned int conf_map[1024] = {0, };
  858. struct volume {
  859. int desired; /*!< Desired volume adjustment */
  860. int actual; /*!< Actual volume adjustment (for channels that can't adjust) */
  861. };
  862. /*! \brief The MeetMe User object */
  863. struct ast_conf_user {
  864. int user_no; /*!< User Number */
  865. struct ast_flags64 userflags; /*!< Flags as set in the conference */
  866. int adminflags; /*!< Flags set by the Admin */
  867. struct ast_channel *chan; /*!< Connected channel */
  868. int talking; /*!< Is user talking */
  869. int dahdichannel; /*!< Is a DAHDI channel */
  870. char usrvalue[50]; /*!< Custom User Value */
  871. char namerecloc[PATH_MAX]; /*!< Name Recorded file Location */
  872. time_t jointime; /*!< Time the user joined the conference */
  873. time_t kicktime; /*!< Time the user will be kicked from the conference */
  874. struct timeval start_time; /*!< Time the user entered into the conference */
  875. long timelimit; /*!< Time limit for the user to be in the conference L(x:y:z) */
  876. long play_warning; /*!< Play a warning when 'y' ms are left */
  877. long warning_freq; /*!< Repeat the warning every 'z' ms */
  878. const char *warning_sound; /*!< File to play as warning if 'y' is defined */
  879. const char *end_sound; /*!< File to play when time is up. */
  880. struct volume talk;
  881. struct volume listen;
  882. AST_LIST_ENTRY(ast_conf_user) list;
  883. };
  884. enum sla_which_trunk_refs {
  885. ALL_TRUNK_REFS,
  886. INACTIVE_TRUNK_REFS,
  887. };
  888. enum sla_trunk_state {
  889. SLA_TRUNK_STATE_IDLE,
  890. SLA_TRUNK_STATE_RINGING,
  891. SLA_TRUNK_STATE_UP,
  892. SLA_TRUNK_STATE_ONHOLD,
  893. SLA_TRUNK_STATE_ONHOLD_BYME,
  894. };
  895. enum sla_hold_access {
  896. /*! This means that any station can put it on hold, and any station
  897. * can retrieve the call from hold. */
  898. SLA_HOLD_OPEN,
  899. /*! This means that only the station that put the call on hold may
  900. * retrieve it from hold. */
  901. SLA_HOLD_PRIVATE,
  902. };
  903. struct sla_trunk_ref;
  904. struct sla_station {
  905. AST_RWLIST_ENTRY(sla_station) entry;
  906. AST_DECLARE_STRING_FIELDS(
  907. AST_STRING_FIELD(name);
  908. AST_STRING_FIELD(device);
  909. AST_STRING_FIELD(autocontext);
  910. );
  911. AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
  912. struct ast_dial *dial;
  913. /*! Ring timeout for this station, for any trunk. If a ring timeout
  914. * is set for a specific trunk on this station, that will take
  915. * priority over this value. */
  916. unsigned int ring_timeout;
  917. /*! Ring delay for this station, for any trunk. If a ring delay
  918. * is set for a specific trunk on this station, that will take
  919. * priority over this value. */
  920. unsigned int ring_delay;
  921. /*! This option uses the values in the sla_hold_access enum and sets the
  922. * access control type for hold on this station. */
  923. unsigned int hold_access:1;
  924. /*! Mark used during reload processing */
  925. unsigned int mark:1;
  926. };
  927. /*!
  928. * \brief A reference to a station
  929. *
  930. * This struct looks near useless at first glance. However, its existence
  931. * in the list of stations in sla_trunk means that this station references
  932. * that trunk. We use the mark to keep track of whether it needs to be
  933. * removed from the sla_trunk's list of stations during a reload.
  934. */
  935. struct sla_station_ref {
  936. AST_LIST_ENTRY(sla_station_ref) entry;
  937. struct sla_station *station;
  938. /*! Mark used during reload processing */
  939. unsigned int mark:1;
  940. };
  941. struct sla_trunk {
  942. AST_DECLARE_STRING_FIELDS(
  943. AST_STRING_FIELD(name);
  944. AST_STRING_FIELD(device);
  945. AST_STRING_FIELD(autocontext);
  946. );
  947. AST_LIST_HEAD_NOLOCK(, sla_station_ref) stations;
  948. /*! Number of stations that use this trunk */
  949. unsigned int num_stations;
  950. /*! Number of stations currently on a call with this trunk */
  951. unsigned int active_stations;
  952. /*! Number of stations that have this trunk on hold. */
  953. unsigned int hold_stations;
  954. struct ast_channel *chan;
  955. unsigned int ring_timeout;
  956. /*! If set to 1, no station will be able to join an active call with
  957. * this trunk. */
  958. unsigned int barge_disabled:1;
  959. /*! This option uses the values in the sla_hold_access enum and sets the
  960. * access control type for hold on this trunk. */
  961. unsigned int hold_access:1;
  962. /*! Whether this trunk is currently on hold, meaning that once a station
  963. * connects to it, the trunk channel needs to have UNHOLD indicated to it. */
  964. unsigned int on_hold:1;
  965. /*! Mark used during reload processing */
  966. unsigned int mark:1;
  967. };
  968. /*!
  969. * \brief A station's reference to a trunk
  970. *
  971. * An sla_station keeps a list of trunk_refs. This holds metadata about the
  972. * stations usage of the trunk.
  973. */
  974. struct sla_trunk_ref {
  975. AST_LIST_ENTRY(sla_trunk_ref) entry;
  976. struct sla_trunk *trunk;
  977. enum sla_trunk_state state;
  978. struct ast_channel *chan;
  979. /*! Ring timeout to use when this trunk is ringing on this specific
  980. * station. This takes higher priority than a ring timeout set at
  981. * the station level. */
  982. unsigned int ring_timeout;
  983. /*! Ring delay to use when this trunk is ringing on this specific
  984. * station. This takes higher priority than a ring delay set at
  985. * the station level. */
  986. unsigned int ring_delay;
  987. /*! Mark used during reload processing */
  988. unsigned int mark:1;
  989. };
  990. static struct ao2_container *sla_stations;
  991. static struct ao2_container *sla_trunks;
  992. static const char sla_registrar[] = "SLA";
  993. /*! \brief Event types that can be queued up for the SLA thread */
  994. enum sla_event_type {
  995. /*! A station has put the call on hold */
  996. SLA_EVENT_HOLD,
  997. /*! The state of a dial has changed */
  998. SLA_EVENT_DIAL_STATE,
  999. /*! The state of a ringing trunk has changed */
  1000. SLA_EVENT_RINGING_TRUNK,
  1001. };
  1002. struct sla_event {
  1003. enum sla_event_type type;
  1004. struct sla_station *station;
  1005. struct sla_trunk_ref *trunk_ref;
  1006. AST_LIST_ENTRY(sla_event) entry;
  1007. };
  1008. /*! \brief A station that failed to be dialed
  1009. * \note Only used by the SLA thread. */
  1010. struct sla_failed_station {
  1011. struct sla_station *station;
  1012. struct timeval last_try;
  1013. AST_LIST_ENTRY(sla_failed_station) entry;
  1014. };
  1015. /*! \brief A trunk that is ringing */
  1016. struct sla_ringing_trunk {
  1017. struct sla_trunk *trunk;
  1018. /*! The time that this trunk started ringing */
  1019. struct timeval ring_begin;
  1020. AST_LIST_HEAD_NOLOCK(, sla_station_ref) timed_out_stations;
  1021. AST_LIST_ENTRY(sla_ringing_trunk) entry;
  1022. };
  1023. enum sla_station_hangup {
  1024. SLA_STATION_HANGUP_NORMAL,
  1025. SLA_STATION_HANGUP_TIMEOUT,
  1026. };
  1027. /*! \brief A station that is ringing */
  1028. struct sla_ringing_station {
  1029. struct sla_station *station;
  1030. /*! The time that this station started ringing */
  1031. struct timeval ring_begin;
  1032. AST_LIST_ENTRY(sla_ringing_station) entry;
  1033. };
  1034. /*!
  1035. * \brief A structure for data used by the sla thread
  1036. */
  1037. static struct {
  1038. /*! The SLA thread ID */
  1039. pthread_t thread;
  1040. ast_cond_t cond;
  1041. ast_mutex_t lock;
  1042. AST_LIST_HEAD_NOLOCK(, sla_ringing_trunk) ringing_trunks;
  1043. AST_LIST_HEAD_NOLOCK(, sla_ringing_station) ringing_stations;
  1044. AST_LIST_HEAD_NOLOCK(, sla_failed_station) failed_stations;
  1045. AST_LIST_HEAD_NOLOCK(, sla_event) event_q;
  1046. unsigned int stop:1;
  1047. /*! Attempt to handle CallerID, even though it is known not to work
  1048. * properly in some situations. */
  1049. unsigned int attempt_callerid:1;
  1050. } sla = {
  1051. .thread = AST_PTHREADT_NULL,
  1052. };
  1053. /*! \brief The number of audio buffers to be allocated on pseudo channels
  1054. * when in a conference */
  1055. static int audio_buffers;
  1056. /*! \brief Map 'volume' levels from -5 through +5 into decibel (dB)
  1057. * settings for channel drivers.
  1058. *
  1059. * \note these are not a straight linear-to-dB
  1060. * conversion... the numbers have been modified
  1061. * to give the user a better level of adjustability.
  1062. */
  1063. static const char gain_map[] = {
  1064. -15,
  1065. -13,
  1066. -10,
  1067. -6,
  1068. 0,
  1069. 0,
  1070. 0,
  1071. 6,
  1072. 10,
  1073. 13,
  1074. 15,
  1075. };
  1076. /* Routes the various meetme message types to the meetme stasis callback function to turn them into events */
  1077. static struct stasis_message_router *meetme_event_message_router;
  1078. STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_join_type);
  1079. STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_leave_type);
  1080. STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_end_type);
  1081. STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_mute_type);
  1082. STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_talking_type);
  1083. STASIS_MESSAGE_TYPE_DEFN_LOCAL(meetme_talk_request_type);
  1084. static void meetme_stasis_cb(void *data, struct stasis_subscription *sub,
  1085. struct stasis_message *message);
  1086. static void meetme_stasis_cleanup(void)
  1087. {
  1088. if (meetme_event_message_router) {
  1089. stasis_message_router_unsubscribe(meetme_event_message_router);
  1090. meetme_event_message_router = NULL;
  1091. }
  1092. STASIS_MESSAGE_TYPE_CLEANUP(meetme_join_type);
  1093. STASIS_MESSAGE_TYPE_CLEANUP(meetme_leave_type);
  1094. STASIS_MESSAGE_TYPE_CLEANUP(meetme_end_type);
  1095. STASIS_MESSAGE_TYPE_CLEANUP(meetme_mute_type);
  1096. STASIS_MESSAGE_TYPE_CLEANUP(meetme_talking_type);
  1097. STASIS_MESSAGE_TYPE_CLEANUP(meetme_talk_request_type);
  1098. }
  1099. static int meetme_stasis_init(void)
  1100. {
  1101. STASIS_MESSAGE_TYPE_INIT(meetme_join_type);
  1102. STASIS_MESSAGE_TYPE_INIT(meetme_leave_type);
  1103. STASIS_MESSAGE_TYPE_INIT(meetme_end_type);
  1104. STASIS_MESSAGE_TYPE_INIT(meetme_mute_type);
  1105. STASIS_MESSAGE_TYPE_INIT(meetme_talking_type);
  1106. STASIS_MESSAGE_TYPE_INIT(meetme_talk_request_type);
  1107. meetme_event_message_router = stasis_message_router_create(
  1108. ast_channel_topic_all_cached());
  1109. if (!meetme_event_message_router) {
  1110. meetme_stasis_cleanup();
  1111. return -1;
  1112. }
  1113. if (stasis_message_router_add(meetme_event_message_router,
  1114. meetme_join_type(),
  1115. meetme_stasis_cb,
  1116. NULL)) {
  1117. meetme_stasis_cleanup();
  1118. return -1;
  1119. }
  1120. if (stasis_message_router_add(meetme_event_message_router,
  1121. meetme_leave_type(),
  1122. meetme_stasis_cb,
  1123. NULL)) {
  1124. meetme_stasis_cleanup();
  1125. return -1;
  1126. }
  1127. if (stasis_message_router_add(meetme_event_message_router,
  1128. meetme_end_type(),
  1129. meetme_stasis_cb,
  1130. NULL)) {
  1131. meetme_stasis_cleanup();
  1132. return -1;
  1133. }
  1134. if (stasis_message_router_add(meetme_event_message_router,
  1135. meetme_mute_type(),
  1136. meetme_stasis_cb,
  1137. NULL)) {
  1138. meetme_stasis_cleanup();
  1139. return -1;
  1140. }
  1141. if (stasis_message_router_add(meetme_event_message_router,
  1142. meetme_talking_type(),
  1143. meetme_stasis_cb,
  1144. NULL)) {
  1145. meetme_stasis_cleanup();
  1146. return -1;
  1147. }
  1148. if (stasis_message_router_add(meetme_event_message_router,
  1149. meetme_talk_request_type(),
  1150. meetme_stasis_cb,
  1151. NULL)) {
  1152. meetme_stasis_cleanup();
  1153. return -1;
  1154. }
  1155. return 0;
  1156. }
  1157. static void meetme_stasis_cb(void *data, struct stasis_subscription *sub,
  1158. struct stasis_message *message)
  1159. {
  1160. struct ast_channel_blob *channel_blob = stasis_message_data(message);
  1161. struct stasis_message_type *message_type;
  1162. const char *event;
  1163. const char *conference_num;
  1164. const char *status;
  1165. struct ast_json *json_cur;
  1166. RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
  1167. RAII_VAR(struct ast_str *, extra_text, NULL, ast_free);
  1168. if (!channel_blob) {
  1169. ast_assert(0);
  1170. return;
  1171. }
  1172. message_type = stasis_message_type(message);
  1173. if (!message_type) {
  1174. ast_assert(0);
  1175. return;
  1176. }
  1177. if (message_type == meetme_join_type()) {
  1178. event = "MeetmeJoin";
  1179. } else if (message_type == meetme_leave_type()) {
  1180. event = "MeetmeLeave";
  1181. } else if (message_type == meetme_end_type()) {
  1182. event = "MeetmeEnd";
  1183. } else if (message_type == meetme_mute_type()) {
  1184. event = "MeetmeMute";
  1185. } else if (message_type == meetme_talking_type()) {
  1186. event = "MeetmeTalking";
  1187. } else if (message_type == meetme_talk_request_type()) {
  1188. event = "MeetmeTalkRequest";
  1189. } else {
  1190. ast_assert(0);
  1191. return;
  1192. }
  1193. if (!event) {
  1194. ast_assert(0);
  1195. return;
  1196. }
  1197. conference_num = ast_json_string_get(ast_json_object_get(channel_blob->blob, "Meetme"));
  1198. if (!conference_num) {
  1199. ast_assert(0);
  1200. return;
  1201. }
  1202. status = ast_json_string_get(ast_json_object_get(channel_blob->blob, "status"));
  1203. if (status) {
  1204. ast_str_append_event_header(&extra_text, "Status", status);
  1205. }
  1206. if (channel_blob->snapshot) {
  1207. channel_text = ast_manager_build_channel_state_string(channel_blob->snapshot);
  1208. }
  1209. if ((json_cur = ast_json_object_get(channel_blob->blob, "user"))) {
  1210. int user_number = ast_json_integer_get(json_cur);
  1211. RAII_VAR(struct ast_str *, user_prop_str, ast_str_create(32), ast_free);
  1212. if (!user_prop_str) {
  1213. return;
  1214. }
  1215. ast_str_set(&user_prop_str, 0, "%d", user_number);
  1216. ast_str_append_event_header(&extra_text, "User", ast_str_buffer(user_prop_str));
  1217. if ((json_cur = ast_json_object_get(channel_blob->blob, "duration"))) {
  1218. int duration = ast_json_integer_get(json_cur);
  1219. ast_str_set(&user_prop_str, 0, "%d", duration);
  1220. ast_str_append_event_header(&extra_text, "Duration", ast_str_buffer(user_prop_str));
  1221. }
  1222. json_cur = NULL;
  1223. }
  1224. manager_event(EVENT_FLAG_CALL, event,
  1225. "Meetme: %s\r\n"
  1226. "%s"
  1227. "%s",
  1228. conference_num,
  1229. channel_text ? ast_str_buffer(channel_text) : "",
  1230. extra_text ? ast_str_buffer(extra_text) : "");
  1231. }
  1232. /*!
  1233. * \internal
  1234. * \brief Build a json object from a status value for inclusion in json extras for meetme_stasis_generate_msg
  1235. * \since 12.0.0
  1236. *
  1237. * \param on if true, then status is on. Otherwise status is off
  1238. * \retval NULL on failure to allocate the JSON blob.
  1239. * \retval pointer to the JSON blob if successful.
  1240. */
  1241. static struct ast_json *status_to_json(int on)
  1242. {
  1243. struct ast_json *json_object = ast_json_pack("{s: s}",
  1244. "status", on ? "on" : "off");
  1245. return json_object;
  1246. }
  1247. /*!
  1248. * \internal
  1249. * \brief Generate a stasis message associated with a meetme event
  1250. * \since 12.0.0
  1251. *
  1252. * \param meetme_confere The conference responsible for generating this message
  1253. * \param chan The channel involved in the message (NULL allowed)
  1254. * \param user The conference user involved in the message (NULL allowed)
  1255. * \param message_type the type the stasis message being generated
  1256. * \param extras Additional json fields desired for inclusion
  1257. */
  1258. static void meetme_stasis_generate_msg(struct ast_conference *meetme_conference, struct ast_channel *chan,
  1259. struct ast_conf_user *user, struct stasis_message_type *message_type, struct ast_json *extras)
  1260. {
  1261. RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
  1262. RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
  1263. json_object = ast_json_pack("{s: s}",
  1264. "Meetme", meetme_conference->confno);
  1265. if (!json_object) {
  1266. return;
  1267. }
  1268. if (extras) {
  1269. ast_json_object_update(json_object, extras);
  1270. }
  1271. if (user) {
  1272. struct timeval now = ast_tvnow();
  1273. long duration = (long)(now.tv_sec - user->jointime);
  1274. struct ast_json *json_user;
  1275. struct ast_json *json_user_duration;
  1276. json_user = ast_json_integer_create(user->user_no);
  1277. if (!json_user || ast_json_object_set(json_object, "user", json_user)) {
  1278. return;
  1279. }
  1280. if (duration > 0) {
  1281. json_user_duration = ast_json_integer_create(duration);
  1282. if (!json_user_duration
  1283. || ast_json_object_set(json_object, "duration", json_user_duration)) {
  1284. return;
  1285. }
  1286. }
  1287. }
  1288. if (chan) {
  1289. ast_channel_lock(chan);
  1290. }
  1291. msg = ast_channel_blob_create(chan, message_type, json_object);
  1292. if (chan) {
  1293. ast_channel_unlock(chan);
  1294. }
  1295. if (!msg) {
  1296. return;
  1297. }
  1298. stasis_publish(ast_channel_topic(chan), msg);
  1299. }
  1300. static int admin_exec(struct ast_channel *chan, const char *data);
  1301. static void *recordthread(void *args);
  1302. static const char *istalking(int x)
  1303. {
  1304. if (x > 0)
  1305. return "(talking)";
  1306. else if (x < 0)
  1307. return "(unmonitored)";
  1308. else
  1309. return "(not talking)";
  1310. }
  1311. static int careful_write(int fd, unsigned char *data, int len, int block)
  1312. {
  1313. int res;
  1314. int x;
  1315. while (len) {
  1316. if (block) {
  1317. x = DAHDI_IOMUX_WRITE | DAHDI_IOMUX_SIGEVENT;
  1318. res = ioctl(fd, DAHDI_IOMUX, &x);
  1319. } else
  1320. res = 0;
  1321. if (res >= 0)
  1322. res = write(fd, data, len);
  1323. if (res < 1) {
  1324. if (errno != EAGAIN) {
  1325. ast_log(LOG_WARNING, "Failed to write audio data to conference: %s\n", strerror(errno));
  1326. return -1;
  1327. } else
  1328. return 0;
  1329. }
  1330. len -= res;
  1331. data += res;
  1332. }
  1333. return 0;
  1334. }
  1335. static int set_talk_volume(struct ast_conf_user *user, int volume)
  1336. {
  1337. char gain_adjust;
  1338. /* attempt to make the adjustment in the channel driver;
  1339. if successful, don't adjust in the frame reading routine
  1340. */
  1341. gain_adjust = gain_map[volume + 5];
  1342. return ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
  1343. }
  1344. static int set_listen_volume(struct ast_conf_user *user, int volume)
  1345. {
  1346. char gain_adjust;
  1347. /* attempt to make the adjustment in the channel driver;
  1348. if successful, don't adjust in the frame reading routine
  1349. */
  1350. gain_adjust = gain_map[volume + 5];
  1351. return ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &gain_adjust, sizeof(gain_adjust), 0);
  1352. }
  1353. static void tweak_volume(struct volume *vol, enum volume_action action)
  1354. {
  1355. switch (action) {
  1356. case VOL_UP:
  1357. switch (vol->desired) {
  1358. case 5:
  1359. break;
  1360. case 0:
  1361. vol->desired = 2;
  1362. break;
  1363. case -2:
  1364. vol->desired = 0;
  1365. break;
  1366. default:
  1367. vol->desired++;
  1368. break;
  1369. }
  1370. break;
  1371. case VOL_DOWN:
  1372. switch (vol->desired) {
  1373. case -5:
  1374. break;
  1375. case 2:
  1376. vol->desired = 0;
  1377. break;
  1378. case 0:
  1379. vol->desired = -2;
  1380. break;
  1381. default:
  1382. vol->desired--;
  1383. break;
  1384. }
  1385. }
  1386. }
  1387. static void tweak_talk_volume(struct ast_conf_user *user, enum volume_action action)
  1388. {
  1389. tweak_volume(&user->talk, action);
  1390. /* attempt to make the adjustment in the channel driver;
  1391. if successful, don't adjust in the frame reading routine
  1392. */
  1393. if (!set_talk_volume(user, user->talk.desired))
  1394. user->talk.actual = 0;
  1395. else
  1396. user->talk.actual = user->talk.desired;
  1397. }
  1398. static void tweak_listen_volume(struct ast_conf_user *user, enum volume_action action)
  1399. {
  1400. tweak_volume(&user->listen, action);
  1401. /* attempt to make the adjustment in the channel driver;
  1402. if successful, don't adjust in the frame reading routine
  1403. */
  1404. if (!set_listen_volume(user, user->listen.desired))
  1405. user->listen.actual = 0;
  1406. else
  1407. user->listen.actual = user->listen.desired;
  1408. }
  1409. static void reset_volumes(struct ast_conf_user *user)
  1410. {
  1411. signed char zero_volume = 0;
  1412. ast_channel_setoption(user->chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
  1413. ast_channel_setoption(user->chan, AST_OPTION_RXGAIN, &zero_volume, sizeof(zero_volume), 0);
  1414. }
  1415. static void conf_play(struct ast_channel *chan, struct ast_conference *conf, enum entrance_sound sound)
  1416. {
  1417. unsigned char *data;
  1418. int len;
  1419. int res = -1;
  1420. ast_test_suite_event_notify("CONFPLAY", "Channel: %s\r\n"
  1421. "Conference: %s\r\n"
  1422. "Marked: %d",
  1423. ast_channel_name(chan),
  1424. conf->confno,
  1425. conf->markedusers);
  1426. if (!ast_check_hangup(chan))
  1427. res = ast_autoservice_start(chan);
  1428. AST_LIST_LOCK(&confs);
  1429. switch(sound) {
  1430. case ENTER:
  1431. data = enter;
  1432. len = sizeof(enter);
  1433. break;
  1434. case LEAVE:
  1435. data = leave;
  1436. len = sizeof(leave);
  1437. break;
  1438. default:
  1439. data = NULL;
  1440. len = 0;
  1441. }
  1442. if (data) {
  1443. careful_write(conf->fd, data, len, 1);
  1444. }
  1445. AST_LIST_UNLOCK(&confs);
  1446. if (!res)
  1447. ast_autoservice_stop(chan);
  1448. }
  1449. static int user_no_cmp(void *obj, void *arg, int flags)
  1450. {
  1451. struct ast_conf_user *user = obj;
  1452. int *user_no = arg;
  1453. if (user->user_no == *user_no) {
  1454. return (CMP_MATCH | CMP_STOP);
  1455. }
  1456. return 0;
  1457. }
  1458. static int user_max_cmp(void *obj, void *arg, int flags)
  1459. {
  1460. struct ast_conf_user *user = obj;
  1461. int *max_no = arg;
  1462. if (user->user_no > *max_no) {
  1463. *max_no = user->user_no;
  1464. }
  1465. return 0;
  1466. }
  1467. /*!
  1468. * \brief Find or create a conference
  1469. *
  1470. * \param confno The conference name/number
  1471. * \param pin The regular user pin
  1472. * \param pinadmin The admin pin
  1473. * \param make Make the conf if it doesn't exist
  1474. * \param dynamic Mark the newly created conference as dynamic
  1475. * \param refcount How many references to mark on the conference
  1476. * \param chan The asterisk channel
  1477. * \param test
  1478. *
  1479. * \return A pointer to the conference struct, or NULL if it wasn't found and
  1480. * make or dynamic were not set.
  1481. */
  1482. static struct ast_conference *build_conf(const char *confno, const char *pin,
  1483. const char *pinadmin, int make, int dynamic, int refcount,
  1484. const struct ast_channel *chan, struct ast_test *test)
  1485. {
  1486. struct ast_conference *cnf;
  1487. struct dahdi_confinfo dahdic = { 0, };
  1488. int confno_int = 0;
  1489. struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  1490. AST_LIST_LOCK(&confs);
  1491. AST_LIST_TRAVERSE(&confs, cnf, list) {
  1492. if (!strcmp(confno, cnf->confno))
  1493. break;
  1494. }
  1495. if (cnf || (!make && !dynamic) || !cap_slin)
  1496. goto cnfout;
  1497. ast_format_cap_append(cap_slin, ast_format_slin, 0);
  1498. /* Make a new one */
  1499. cnf = ast_calloc(1, sizeof(*cnf));
  1500. if (!cnf) {
  1501. goto cnfout;
  1502. }
  1503. cnf->usercontainer = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
  1504. NULL, user_no_cmp);
  1505. if (!cnf->usercontainer) {
  1506. goto cnfout;
  1507. }
  1508. ast_mutex_init(&cnf->playlock);
  1509. ast_mutex_init(&cnf->listenlock);
  1510. cnf->recordthread = AST_PTHREADT_NULL;
  1511. ast_mutex_init(&cnf->recordthreadlock);
  1512. cnf->announcethread = AST_PTHREADT_NULL;
  1513. ast_mutex_init(&cnf->announcethreadlock);
  1514. ast_copy_string(cnf->confno, confno, sizeof(cnf->confno));
  1515. ast_copy_string(cnf->pin, pin, sizeof(cnf->pin));
  1516. ast_copy_string(cnf->pinadmin, pinadmin, sizeof(cnf->pinadmin));
  1517. ast_copy_string(cnf->uniqueid, ast_channel_uniqueid(chan), sizeof(cnf->uniqueid));
  1518. /* Setup a new dahdi conference */
  1519. dahdic.confno = -1;
  1520. dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
  1521. cnf->fd = open("/dev/dahdi/pseudo", O_RDWR);
  1522. if (cnf->fd < 0 || ioctl(cnf->fd, DAHDI_SETCONF, &dahdic)) {
  1523. if (test) {
  1524. /* if we are creating a conference for a unit test, it is not neccesary
  1525. * to open a pseudo channel, so, if we fail continue creating
  1526. * the conference. */
  1527. ast_test_status_update(test, "Unable to open DAHDI pseudo device\n");
  1528. } else {
  1529. ast_log(LOG_WARNING, "Unable to open DAHDI pseudo device\n");
  1530. if (cnf->fd >= 0)
  1531. close(cnf->fd);
  1532. ao2_ref(cnf->usercontainer, -1);
  1533. ast_mutex_destroy(&cnf->playlock);
  1534. ast_mutex_destroy(&cnf->listenlock);
  1535. ast_mutex_destroy(&cnf->recordthreadlock);
  1536. ast_mutex_destroy(&cnf->announcethreadlock);
  1537. ast_free(cnf);
  1538. cnf = NULL;
  1539. goto cnfout;
  1540. }
  1541. }
  1542. cnf->dahdiconf = dahdic.confno;
  1543. /* Setup a new channel for playback of audio files */
  1544. cnf->chan = ast_request("DAHDI", cap_slin, NULL, chan, "pseudo", NULL);
  1545. if (cnf->chan) {
  1546. ast_set_read_format(cnf->chan, ast_format_slin);
  1547. ast_set_write_format(cnf->chan, ast_format_slin);
  1548. dahdic.chan = 0;
  1549. dahdic.confno = cnf->dahdiconf;
  1550. dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
  1551. if (ioctl(ast_channel_fd(cnf->chan, 0), DAHDI_SETCONF, &dahdic)) {
  1552. if (test) {
  1553. ast_test_status_update(test, "Error setting conference on pseudo channel\n");
  1554. }
  1555. ast_log(LOG_WARNING, "Error setting conference\n");
  1556. if (cnf->chan)
  1557. ast_hangup(cnf->chan);
  1558. else
  1559. close(cnf->fd);
  1560. ao2_ref(cnf->usercontainer, -1);
  1561. ast_mutex_destroy(&cnf->playlock);
  1562. ast_mutex_destroy(&cnf->listenlock);
  1563. ast_mutex_destroy(&cnf->recordthreadlock);
  1564. ast_mutex_destroy(&cnf->announcethreadlock);
  1565. ast_free(cnf);
  1566. cnf = NULL;
  1567. goto cnfout;
  1568. }
  1569. }
  1570. /* Fill the conference struct */
  1571. cnf->start = time(NULL);
  1572. cnf->maxusers = 0x7fffffff;
  1573. cnf->isdynamic = dynamic ? 1 : 0;
  1574. ast_verb(3, "Created MeetMe conference %d for conference '%s'\n", cnf->dahdiconf, cnf->confno);
  1575. AST_LIST_INSERT_HEAD(&confs, cnf, list);
  1576. /* Reserve conference number in map */
  1577. if ((sscanf(cnf->confno, "%30d", &confno_int) == 1) && (confno_int >= 0 && confno_int < 1024))
  1578. conf_map[confno_int] = 1;
  1579. cnfout:
  1580. ao2_cleanup(cap_slin);
  1581. if (cnf)
  1582. ast_atomic_fetchadd_int(&cnf->refcount, refcount);
  1583. AST_LIST_UNLOCK(&confs);
  1584. return cnf;
  1585. }
  1586. static char *complete_confno(const char *word, int state)
  1587. {
  1588. struct ast_conference *cnf;
  1589. char *ret = NULL;
  1590. int which = 0;
  1591. int len = strlen(word);
  1592. AST_LIST_LOCK(&confs);
  1593. AST_LIST_TRAVERSE(&confs, cnf, list) {
  1594. if (!strncmp(word, cnf->confno, len) && ++which > state) {
  1595. /* dup before releasing the lock */
  1596. ret = ast_strdup(cnf->confno);
  1597. break;
  1598. }
  1599. }
  1600. AST_LIST_UNLOCK(&confs);
  1601. return ret;
  1602. }
  1603. static char *complete_userno(struct ast_conference *cnf, const char *word, int state)
  1604. {
  1605. char usrno[50];
  1606. struct ao2_iterator iter;
  1607. struct ast_conf_user *usr;
  1608. char *ret = NULL;
  1609. int which = 0;
  1610. int len = strlen(word);
  1611. iter = ao2_iterator_init(cnf->usercontainer, 0);
  1612. for (; (usr = ao2_iterator_next(&iter)); ao2_ref(usr, -1)) {
  1613. snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
  1614. if (!strncmp(word, usrno, len) && ++which > state) {
  1615. ao2_ref(usr, -1);
  1616. ret = ast_strdup(usrno);
  1617. break;
  1618. }
  1619. }
  1620. ao2_iterator_destroy(&iter);
  1621. return ret;
  1622. }
  1623. static char *complete_meetmecmd_mute_kick(const char *line, const char *word, int pos, int state)
  1624. {
  1625. if (pos == 2) {
  1626. return complete_confno(word, state);
  1627. }
  1628. if (pos == 3) {
  1629. int len = strlen(word);
  1630. char *ret = NULL;
  1631. char *saved = NULL;
  1632. char *myline;
  1633. char *confno;
  1634. struct ast_conference *cnf;
  1635. if (!strncasecmp(word, "all", len)) {
  1636. if (state == 0) {
  1637. return ast_strdup("all");
  1638. }
  1639. --state;
  1640. }
  1641. /* Extract the confno from the command line. */
  1642. myline = ast_strdupa(line);
  1643. strtok_r(myline, " ", &saved);
  1644. strtok_r(NULL, " ", &saved);
  1645. confno = strtok_r(NULL, " ", &saved);
  1646. AST_LIST_LOCK(&confs);
  1647. AST_LIST_TRAVERSE(&confs, cnf, list) {
  1648. if (!strcmp(confno, cnf->confno)) {
  1649. ret = complete_userno(cnf, word, state);
  1650. break;
  1651. }
  1652. }
  1653. AST_LIST_UNLOCK(&confs);
  1654. return ret;
  1655. }
  1656. return NULL;
  1657. }
  1658. static char *complete_meetmecmd_lock(const char *word, int pos, int state)
  1659. {
  1660. if (pos == 2) {
  1661. return complete_confno(word, state);
  1662. }
  1663. return NULL;
  1664. }
  1665. static char *complete_meetmecmd_list(const char *line, const char *word, int pos, int state)
  1666. {
  1667. int len;
  1668. if (pos == 2) {
  1669. len = strlen(word);
  1670. if (!strncasecmp(word, STR_CONCISE, len)) {
  1671. if (state == 0) {
  1672. return ast_strdup(STR_CONCISE);
  1673. }
  1674. --state;
  1675. }
  1676. return complete_confno(word, state);
  1677. }
  1678. if (pos == 3 && state == 0) {
  1679. char *saved = NULL;
  1680. char *myline;
  1681. char *confno;
  1682. /* Extract the confno from the command line. */
  1683. myline = ast_strdupa(line);
  1684. strtok_r(myline, " ", &saved);
  1685. strtok_r(NULL, " ", &saved);
  1686. confno = strtok_r(NULL, " ", &saved);
  1687. if (!strcasecmp(confno, STR_CONCISE)) {
  1688. /* There is nothing valid in this position now. */
  1689. return NULL;
  1690. }
  1691. len = strlen(word);
  1692. if (!strncasecmp(word, STR_CONCISE, len)) {
  1693. return ast_strdup(STR_CONCISE);
  1694. }
  1695. }
  1696. return NULL;
  1697. }
  1698. static char *meetme_show_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1699. {
  1700. /* Process the command */
  1701. struct ast_conf_user *user;
  1702. struct ast_conference *cnf;
  1703. int hr, min, sec;
  1704. int total = 0;
  1705. time_t now;
  1706. #define MC_HEADER_FORMAT "%-14s %-14s %-10s %-8s %-8s %-6s\n"
  1707. #define MC_DATA_FORMAT "%-12.12s %4.4d %4.4s %02d:%02d:%02d %-8s %-6s\n"
  1708. switch (cmd) {
  1709. case CLI_INIT:
  1710. e->command = "meetme list";
  1711. e->usage =
  1712. "Usage: meetme list [<confno>] [" STR_CONCISE "]\n"
  1713. " List all conferences or a specific conference.\n";
  1714. return NULL;
  1715. case CLI_GENERATE:
  1716. return complete_meetmecmd_list(a->line, a->word, a->pos, a->n);
  1717. }
  1718. if (a->argc == 2 || (a->argc == 3 && !strcasecmp(a->argv[2], STR_CONCISE))) {
  1719. /* List all the conferences */
  1720. int concise = (a->argc == 3);
  1721. struct ast_str *marked_users;
  1722. if (!(marked_users = ast_str_create(30))) {
  1723. return CLI_FAILURE;
  1724. }
  1725. now = time(NULL);
  1726. AST_LIST_LOCK(&confs);
  1727. if (AST_LIST_EMPTY(&confs)) {
  1728. if (!concise) {
  1729. ast_cli(a->fd, "No active MeetMe conferences.\n");
  1730. }
  1731. AST_LIST_UNLOCK(&confs);
  1732. ast_free(marked_users);
  1733. return CLI_SUCCESS;
  1734. }
  1735. if (!concise) {
  1736. ast_cli(a->fd, MC_HEADER_FORMAT, "Conf Num", "Parties", "Marked", "Activity", "Creation", "Locked");
  1737. }
  1738. AST_LIST_TRAVERSE(&confs, cnf, list) {
  1739. hr = (now - cnf->start) / 3600;
  1740. min = ((now - cnf->start) % 3600) / 60;
  1741. sec = (now - cnf->start) % 60;
  1742. if (!concise) {
  1743. if (cnf->markedusers == 0) {
  1744. ast_str_set(&marked_users, 0, "N/A ");
  1745. } else {
  1746. ast_str_set(&marked_users, 0, "%4.4d", cnf->markedusers);
  1747. }
  1748. ast_cli(a->fd, MC_DATA_FORMAT, cnf->confno, cnf->users,
  1749. ast_str_buffer(marked_users), hr, min, sec,
  1750. cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
  1751. } else {
  1752. ast_cli(a->fd, "%s!%d!%d!%02d:%02d:%02d!%d!%d\n",
  1753. cnf->confno,
  1754. cnf->users,
  1755. cnf->markedusers,
  1756. hr, min, sec,
  1757. cnf->isdynamic,
  1758. cnf->locked);
  1759. }
  1760. total += cnf->users;
  1761. }
  1762. AST_LIST_UNLOCK(&confs);
  1763. if (!concise) {
  1764. ast_cli(a->fd, "* Total number of MeetMe users: %d\n", total);
  1765. }
  1766. ast_free(marked_users);
  1767. return CLI_SUCCESS;
  1768. }
  1769. if (a->argc == 3 || (a->argc == 4 && !strcasecmp(a->argv[3], STR_CONCISE))) {
  1770. struct ao2_iterator user_iter;
  1771. int concise = (a->argc == 4);
  1772. /* List all the users in a conference */
  1773. if (AST_LIST_EMPTY(&confs)) {
  1774. if (!concise) {
  1775. ast_cli(a->fd, "No active MeetMe conferences.\n");
  1776. }
  1777. return CLI_SUCCESS;
  1778. }
  1779. /* Find the right conference */
  1780. AST_LIST_LOCK(&confs);
  1781. AST_LIST_TRAVERSE(&confs, cnf, list) {
  1782. if (strcmp(cnf->confno, a->argv[2]) == 0) {
  1783. break;
  1784. }
  1785. }
  1786. if (!cnf) {
  1787. if (!concise)
  1788. ast_cli(a->fd, "No such conference: %s.\n", a->argv[2]);
  1789. AST_LIST_UNLOCK(&confs);
  1790. return CLI_SUCCESS;
  1791. }
  1792. /* Show all the users */
  1793. time(&now);
  1794. user_iter = ao2_iterator_init(cnf->usercontainer, 0);
  1795. while((user = ao2_iterator_next(&user_iter))) {
  1796. hr = (now - user->jointime) / 3600;
  1797. min = ((now - user->jointime) % 3600) / 60;
  1798. sec = (now - user->jointime) % 60;
  1799. if (!concise) {
  1800. ast_cli(a->fd, "User #: %-2.2d %12.12s %-20.20s Channel: %s %s %s %s %s %s %02d:%02d:%02d\n",
  1801. user->user_no,
  1802. S_COR(ast_channel_caller(user->chan)->id.number.valid, ast_channel_caller(user->chan)->id.number.str, "<unknown>"),
  1803. S_COR(ast_channel_caller(user->chan)->id.name.valid, ast_channel_caller(user->chan)->id.name.str, "<no name>"),
  1804. ast_channel_name(user->chan),
  1805. ast_test_flag64(&user->userflags, CONFFLAG_ADMIN) ? "(Admin)" : "",
  1806. ast_test_flag64(&user->userflags, CONFFLAG_MONITOR) ? "(Listen only)" : "",
  1807. user->adminflags & ADMINFLAG_MUTED ? "(Admin Muted)" : user->adminflags & ADMINFLAG_SELFMUTED ? "(Muted)" : "",
  1808. user->adminflags & ADMINFLAG_T_REQUEST ? "(Request to Talk)" : "",
  1809. istalking(user->talking), hr, min, sec);
  1810. } else {
  1811. ast_cli(a->fd, "%d!%s!%s!%s!%s!%s!%s!%s!%d!%02d:%02d:%02d\n",
  1812. user->user_no,
  1813. S_COR(ast_channel_caller(user->chan)->id.number.valid, ast_channel_caller(user->chan)->id.number.str, ""),
  1814. S_COR(ast_channel_caller(user->chan)->id.name.valid, ast_channel_caller(user->chan)->id.name.str, ""),
  1815. ast_channel_name(user->chan),
  1816. ast_test_flag64(&user->userflags, CONFFLAG_ADMIN) ? "1" : "",
  1817. ast_test_flag64(&user->userflags, CONFFLAG_MONITOR) ? "1" : "",
  1818. user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED) ? "1" : "",
  1819. user->adminflags & ADMINFLAG_T_REQUEST ? "1" : "",
  1820. user->talking, hr, min, sec);
  1821. }
  1822. ao2_ref(user, -1);
  1823. }
  1824. ao2_iterator_destroy(&user_iter);
  1825. if (!concise) {
  1826. ast_cli(a->fd, "%d users in that conference.\n", cnf->users);
  1827. }
  1828. AST_LIST_UNLOCK(&confs);
  1829. return CLI_SUCCESS;
  1830. }
  1831. return CLI_SHOWUSAGE;
  1832. }
  1833. static char *meetme_cmd_helper(struct ast_cli_args *a)
  1834. {
  1835. /* Process the command */
  1836. struct ast_str *cmdline;
  1837. /* Max confno length */
  1838. if (!(cmdline = ast_str_create(MAX_CONFNUM))) {
  1839. return CLI_FAILURE;
  1840. }
  1841. ast_str_set(&cmdline, 0, "%s", a->argv[2]); /* Argv 2: conference number */
  1842. if (strcasestr(a->argv[1], "lock")) {
  1843. if (strcasecmp(a->argv[1], "lock") == 0) {
  1844. /* Lock */
  1845. ast_str_append(&cmdline, 0, ",L");
  1846. } else {
  1847. /* Unlock */
  1848. ast_str_append(&cmdline, 0, ",l");
  1849. }
  1850. } else if (strcasestr(a->argv[1], "mute")) {
  1851. if (strcasecmp(a->argv[1], "mute") == 0) {
  1852. /* Mute */
  1853. if (strcasecmp(a->argv[3], "all") == 0) {
  1854. ast_str_append(&cmdline, 0, ",N");
  1855. } else {
  1856. ast_str_append(&cmdline, 0, ",M,%s", a->argv[3]);
  1857. }
  1858. } else {
  1859. /* Unmute */
  1860. if (strcasecmp(a->argv[3], "all") == 0) {
  1861. ast_str_append(&cmdline, 0, ",n");
  1862. } else {
  1863. ast_str_append(&cmdline, 0, ",m,%s", a->argv[3]);
  1864. }
  1865. }
  1866. } else if (strcasecmp(a->argv[1], "kick") == 0) {
  1867. if (strcasecmp(a->argv[3], "all") == 0) {
  1868. /* Kick all */
  1869. ast_str_append(&cmdline, 0, ",K");
  1870. } else {
  1871. /* Kick a single user */
  1872. ast_str_append(&cmdline, 0, ",k,%s", a->argv[3]);
  1873. }
  1874. } else {
  1875. /*
  1876. * Should never get here because it is already filtered by the
  1877. * callers.
  1878. */
  1879. ast_free(cmdline);
  1880. return CLI_SHOWUSAGE;
  1881. }
  1882. ast_debug(1, "Cmdline: %s\n", ast_str_buffer(cmdline));
  1883. admin_exec(NULL, ast_str_buffer(cmdline));
  1884. ast_free(cmdline);
  1885. return CLI_SUCCESS;
  1886. }
  1887. static char *meetme_lock_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1888. {
  1889. switch (cmd) {
  1890. case CLI_INIT:
  1891. e->command = "meetme {lock|unlock}";
  1892. e->usage =
  1893. "Usage: meetme lock|unlock <confno>\n"
  1894. " Lock or unlock a conference to new users.\n";
  1895. return NULL;
  1896. case CLI_GENERATE:
  1897. return complete_meetmecmd_lock(a->word, a->pos, a->n);
  1898. }
  1899. if (a->argc != 3) {
  1900. return CLI_SHOWUSAGE;
  1901. }
  1902. return meetme_cmd_helper(a);
  1903. }
  1904. static char *meetme_kick_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1905. {
  1906. switch (cmd) {
  1907. case CLI_INIT:
  1908. e->command = "meetme kick";
  1909. e->usage =
  1910. "Usage: meetme kick <confno> all|<userno>\n"
  1911. " Kick a conference or a user in a conference.\n";
  1912. return NULL;
  1913. case CLI_GENERATE:
  1914. return complete_meetmecmd_mute_kick(a->line, a->word, a->pos, a->n);
  1915. }
  1916. if (a->argc != 4) {
  1917. return CLI_SHOWUSAGE;
  1918. }
  1919. return meetme_cmd_helper(a);
  1920. }
  1921. static char *meetme_mute_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1922. {
  1923. switch (cmd) {
  1924. case CLI_INIT:
  1925. e->command = "meetme {mute|unmute}";
  1926. e->usage =
  1927. "Usage: meetme mute|unmute <confno> all|<userno>\n"
  1928. " Mute or unmute a conference or a user in a conference.\n";
  1929. return NULL;
  1930. case CLI_GENERATE:
  1931. return complete_meetmecmd_mute_kick(a->line, a->word, a->pos, a->n);
  1932. }
  1933. if (a->argc != 4) {
  1934. return CLI_SHOWUSAGE;
  1935. }
  1936. return meetme_cmd_helper(a);
  1937. }
  1938. static const char *sla_hold_str(unsigned int hold_access)
  1939. {
  1940. const char *hold = "Unknown";
  1941. switch (hold_access) {
  1942. case SLA_HOLD_OPEN:
  1943. hold = "Open";
  1944. break;
  1945. case SLA_HOLD_PRIVATE:
  1946. hold = "Private";
  1947. default:
  1948. break;
  1949. }
  1950. return hold;
  1951. }
  1952. static char *sla_show_trunks(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  1953. {
  1954. struct ao2_iterator i;
  1955. struct sla_trunk *trunk;
  1956. switch (cmd) {
  1957. case CLI_INIT:
  1958. e->command = "sla show trunks";
  1959. e->usage =
  1960. "Usage: sla show trunks\n"
  1961. " This will list all trunks defined in sla.conf\n";
  1962. return NULL;
  1963. case CLI_GENERATE:
  1964. return NULL;
  1965. }
  1966. ast_cli(a->fd, "\n"
  1967. "=============================================================\n"
  1968. "=== Configured SLA Trunks ===================================\n"
  1969. "=============================================================\n"
  1970. "===\n");
  1971. i = ao2_iterator_init(sla_trunks, 0);
  1972. for (; (trunk = ao2_iterator_next(&i)); ao2_ref(trunk, -1)) {
  1973. struct sla_station_ref *station_ref;
  1974. char ring_timeout[16] = "(none)";
  1975. ao2_lock(trunk);
  1976. if (trunk->ring_timeout) {
  1977. snprintf(ring_timeout, sizeof(ring_timeout), "%u Seconds", trunk->ring_timeout);
  1978. }
  1979. ast_cli(a->fd, "=== ---------------------------------------------------------\n"
  1980. "=== Trunk Name: %s\n"
  1981. "=== ==> Device: %s\n"
  1982. "=== ==> AutoContext: %s\n"
  1983. "=== ==> RingTimeout: %s\n"
  1984. "=== ==> BargeAllowed: %s\n"
  1985. "=== ==> HoldAccess: %s\n"
  1986. "=== ==> Stations ...\n",
  1987. trunk->name, trunk->device,
  1988. S_OR(trunk->autocontext, "(none)"),
  1989. ring_timeout,
  1990. trunk->barge_disabled ? "No" : "Yes",
  1991. sla_hold_str(trunk->hold_access));
  1992. AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
  1993. ast_cli(a->fd, "=== ==> Station name: %s\n", station_ref->station->name);
  1994. }
  1995. ast_cli(a->fd, "=== ---------------------------------------------------------\n===\n");
  1996. ao2_unlock(trunk);
  1997. }
  1998. ao2_iterator_destroy(&i);
  1999. ast_cli(a->fd, "=============================================================\n\n");
  2000. return CLI_SUCCESS;
  2001. }
  2002. static const char *trunkstate2str(enum sla_trunk_state state)
  2003. {
  2004. #define S(e) case e: return # e;
  2005. switch (state) {
  2006. S(SLA_TRUNK_STATE_IDLE)
  2007. S(SLA_TRUNK_STATE_RINGING)
  2008. S(SLA_TRUNK_STATE_UP)
  2009. S(SLA_TRUNK_STATE_ONHOLD)
  2010. S(SLA_TRUNK_STATE_ONHOLD_BYME)
  2011. }
  2012. return "Uknown State";
  2013. #undef S
  2014. }
  2015. static char *sla_show_stations(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2016. {
  2017. struct ao2_iterator i;
  2018. struct sla_station *station;
  2019. switch (cmd) {
  2020. case CLI_INIT:
  2021. e->command = "sla show stations";
  2022. e->usage =
  2023. "Usage: sla show stations\n"
  2024. " This will list all stations defined in sla.conf\n";
  2025. return NULL;
  2026. case CLI_GENERATE:
  2027. return NULL;
  2028. }
  2029. ast_cli(a->fd, "\n"
  2030. "=============================================================\n"
  2031. "=== Configured SLA Stations =================================\n"
  2032. "=============================================================\n"
  2033. "===\n");
  2034. i = ao2_iterator_init(sla_stations, 0);
  2035. for (; (station = ao2_iterator_next(&i)); ao2_ref(station, -1)) {
  2036. struct sla_trunk_ref *trunk_ref;
  2037. char ring_timeout[16] = "(none)";
  2038. char ring_delay[16] = "(none)";
  2039. ao2_lock(station);
  2040. if (station->ring_timeout) {
  2041. snprintf(ring_timeout, sizeof(ring_timeout),
  2042. "%u", station->ring_timeout);
  2043. }
  2044. if (station->ring_delay) {
  2045. snprintf(ring_delay, sizeof(ring_delay),
  2046. "%u", station->ring_delay);
  2047. }
  2048. ast_cli(a->fd, "=== ---------------------------------------------------------\n"
  2049. "=== Station Name: %s\n"
  2050. "=== ==> Device: %s\n"
  2051. "=== ==> AutoContext: %s\n"
  2052. "=== ==> RingTimeout: %s\n"
  2053. "=== ==> RingDelay: %s\n"
  2054. "=== ==> HoldAccess: %s\n"
  2055. "=== ==> Trunks ...\n",
  2056. station->name, station->device,
  2057. S_OR(station->autocontext, "(none)"),
  2058. ring_timeout, ring_delay,
  2059. sla_hold_str(station->hold_access));
  2060. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  2061. if (trunk_ref->ring_timeout) {
  2062. snprintf(ring_timeout, sizeof(ring_timeout),
  2063. "%u", trunk_ref->ring_timeout);
  2064. } else {
  2065. strcpy(ring_timeout, "(none)");
  2066. }
  2067. if (trunk_ref->ring_delay) {
  2068. snprintf(ring_delay, sizeof(ring_delay),
  2069. "%u", trunk_ref->ring_delay);
  2070. } else {
  2071. strcpy(ring_delay, "(none)");
  2072. }
  2073. ast_cli(a->fd, "=== ==> Trunk Name: %s\n"
  2074. "=== ==> State: %s\n"
  2075. "=== ==> RingTimeout: %s\n"
  2076. "=== ==> RingDelay: %s\n",
  2077. trunk_ref->trunk->name,
  2078. trunkstate2str(trunk_ref->state),
  2079. ring_timeout, ring_delay);
  2080. }
  2081. ast_cli(a->fd, "=== ---------------------------------------------------------\n"
  2082. "===\n");
  2083. ao2_unlock(station);
  2084. }
  2085. ao2_iterator_destroy(&i);
  2086. ast_cli(a->fd, "============================================================\n"
  2087. "\n");
  2088. return CLI_SUCCESS;
  2089. }
  2090. static struct ast_cli_entry cli_meetme[] = {
  2091. AST_CLI_DEFINE(meetme_kick_cmd, "Kick a conference or a user in a conference."),
  2092. AST_CLI_DEFINE(meetme_show_cmd, "List all conferences or a specific conference."),
  2093. AST_CLI_DEFINE(meetme_lock_cmd, "Lock or unlock a conference to new users."),
  2094. AST_CLI_DEFINE(meetme_mute_cmd, "Mute or unmute a conference or a user in a conference."),
  2095. AST_CLI_DEFINE(sla_show_trunks, "Show SLA Trunks"),
  2096. AST_CLI_DEFINE(sla_show_stations, "Show SLA Stations"),
  2097. };
  2098. static void conf_flush(int fd, struct ast_channel *chan)
  2099. {
  2100. int x;
  2101. /* read any frames that may be waiting on the channel
  2102. and throw them away
  2103. */
  2104. if (chan) {
  2105. struct ast_frame *f;
  2106. /* when no frames are available, this will wait
  2107. for 1 millisecond maximum
  2108. */
  2109. while (ast_waitfor(chan, 1) > 0) {
  2110. f = ast_read(chan);
  2111. if (f)
  2112. ast_frfree(f);
  2113. else /* channel was hung up or something else happened */
  2114. break;
  2115. }
  2116. }
  2117. /* flush any data sitting in the pseudo channel */
  2118. x = DAHDI_FLUSH_ALL;
  2119. if (ioctl(fd, DAHDI_FLUSH, &x))
  2120. ast_log(LOG_WARNING, "Error flushing channel\n");
  2121. }
  2122. /*! \brief Remove the conference from the list and free it.
  2123. We assume that this was called while holding conflock. */
  2124. static int conf_free(struct ast_conference *conf)
  2125. {
  2126. int x;
  2127. struct announce_listitem *item;
  2128. AST_LIST_REMOVE(&confs, conf, list);
  2129. meetme_stasis_generate_msg(conf, NULL, NULL, meetme_end_type(), NULL);
  2130. if (conf->recording == MEETME_RECORD_ACTIVE) {
  2131. conf->recording = MEETME_RECORD_TERMINATE;
  2132. AST_LIST_UNLOCK(&confs);
  2133. while (1) {
  2134. usleep(1);
  2135. AST_LIST_LOCK(&confs);
  2136. if (conf->recording == MEETME_RECORD_OFF)
  2137. break;
  2138. AST_LIST_UNLOCK(&confs);
  2139. }
  2140. }
  2141. for (x = 0; x < AST_FRAME_BITS; x++) {
  2142. if (conf->transframe[x])
  2143. ast_frfree(conf->transframe[x]);
  2144. if (conf->transpath[x])
  2145. ast_translator_free_path(conf->transpath[x]);
  2146. }
  2147. if (conf->announcethread != AST_PTHREADT_NULL) {
  2148. ast_mutex_lock(&conf->announcelistlock);
  2149. conf->announcethread_stop = 1;
  2150. ast_softhangup(conf->chan, AST_SOFTHANGUP_EXPLICIT);
  2151. ast_cond_signal(&conf->announcelist_addition);
  2152. ast_mutex_unlock(&conf->announcelistlock);
  2153. pthread_join(conf->announcethread, NULL);
  2154. while ((item = AST_LIST_REMOVE_HEAD(&conf->announcelist, entry))) {
  2155. /* If it's a voicemail greeting file we don't want to remove it */
  2156. if (!item->vmrec){
  2157. ast_filedelete(item->namerecloc, NULL);
  2158. }
  2159. ao2_ref(item, -1);
  2160. }
  2161. ast_mutex_destroy(&conf->announcelistlock);
  2162. }
  2163. if (conf->origframe)
  2164. ast_frfree(conf->origframe);
  2165. ast_hangup(conf->lchan);
  2166. ast_hangup(conf->chan);
  2167. if (conf->fd >= 0)
  2168. close(conf->fd);
  2169. if (conf->recordingfilename) {
  2170. ast_free(conf->recordingfilename);
  2171. }
  2172. if (conf->usercontainer) {
  2173. ao2_ref(conf->usercontainer, -1);
  2174. }
  2175. if (conf->recordingformat) {
  2176. ast_free(conf->recordingformat);
  2177. }
  2178. ast_mutex_destroy(&conf->playlock);
  2179. ast_mutex_destroy(&conf->listenlock);
  2180. ast_mutex_destroy(&conf->recordthreadlock);
  2181. ast_mutex_destroy(&conf->announcethreadlock);
  2182. ast_free(conf);
  2183. return 0;
  2184. }
  2185. static void conf_queue_dtmf(const struct ast_conference *conf,
  2186. const struct ast_conf_user *sender, struct ast_frame *f)
  2187. {
  2188. struct ast_conf_user *user;
  2189. struct ao2_iterator user_iter;
  2190. user_iter = ao2_iterator_init(conf->usercontainer, 0);
  2191. while ((user = ao2_iterator_next(&user_iter))) {
  2192. if (user == sender) {
  2193. ao2_ref(user, -1);
  2194. continue;
  2195. }
  2196. if (ast_write(user->chan, f) < 0)
  2197. ast_log(LOG_WARNING, "Error writing frame to channel %s\n", ast_channel_name(user->chan));
  2198. ao2_ref(user, -1);
  2199. }
  2200. ao2_iterator_destroy(&user_iter);
  2201. }
  2202. static void sla_queue_event_full(enum sla_event_type type,
  2203. struct sla_trunk_ref *trunk_ref, struct sla_station *station, int lock)
  2204. {
  2205. struct sla_event *event;
  2206. if (sla.thread == AST_PTHREADT_NULL) {
  2207. ao2_ref(station, -1);
  2208. ao2_ref(trunk_ref, -1);
  2209. return;
  2210. }
  2211. if (!(event = ast_calloc(1, sizeof(*event)))) {
  2212. ao2_ref(station, -1);
  2213. ao2_ref(trunk_ref, -1);
  2214. return;
  2215. }
  2216. event->type = type;
  2217. event->trunk_ref = trunk_ref;
  2218. event->station = station;
  2219. if (!lock) {
  2220. AST_LIST_INSERT_TAIL(&sla.event_q, event, entry);
  2221. return;
  2222. }
  2223. ast_mutex_lock(&sla.lock);
  2224. AST_LIST_INSERT_TAIL(&sla.event_q, event, entry);
  2225. ast_cond_signal(&sla.cond);
  2226. ast_mutex_unlock(&sla.lock);
  2227. }
  2228. static void sla_queue_event_nolock(enum sla_event_type type)
  2229. {
  2230. sla_queue_event_full(type, NULL, NULL, 0);
  2231. }
  2232. static void sla_queue_event(enum sla_event_type type)
  2233. {
  2234. sla_queue_event_full(type, NULL, NULL, 1);
  2235. }
  2236. /*! \brief Queue a SLA event from the conference */
  2237. static void sla_queue_event_conf(enum sla_event_type type, struct ast_channel *chan,
  2238. struct ast_conference *conf)
  2239. {
  2240. struct sla_station *station;
  2241. struct sla_trunk_ref *trunk_ref = NULL;
  2242. char *trunk_name;
  2243. struct ao2_iterator i;
  2244. trunk_name = ast_strdupa(conf->confno);
  2245. strsep(&trunk_name, "_");
  2246. if (ast_strlen_zero(trunk_name)) {
  2247. ast_log(LOG_ERROR, "Invalid conference name for SLA - '%s'!\n", conf->confno);
  2248. return;
  2249. }
  2250. i = ao2_iterator_init(sla_stations, 0);
  2251. while ((station = ao2_iterator_next(&i))) {
  2252. ao2_lock(station);
  2253. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  2254. if (trunk_ref->chan == chan && !strcmp(trunk_ref->trunk->name, trunk_name)) {
  2255. ao2_ref(trunk_ref, 1);
  2256. break;
  2257. }
  2258. }
  2259. ao2_unlock(station);
  2260. if (trunk_ref) {
  2261. /* station reference given to sla_queue_event_full() */
  2262. break;
  2263. }
  2264. ao2_ref(station, -1);
  2265. }
  2266. ao2_iterator_destroy(&i);
  2267. if (!trunk_ref) {
  2268. ast_debug(1, "Trunk not found for event!\n");
  2269. return;
  2270. }
  2271. sla_queue_event_full(type, trunk_ref, station, 1);
  2272. }
  2273. /*! \brief Decrement reference counts, as incremented by find_conf() */
  2274. static int dispose_conf(struct ast_conference *conf)
  2275. {
  2276. int res = 0;
  2277. int confno_int = 0;
  2278. AST_LIST_LOCK(&confs);
  2279. if (ast_atomic_dec_and_test(&conf->refcount)) {
  2280. /* Take the conference room number out of an inuse state */
  2281. if ((sscanf(conf->confno, "%4d", &confno_int) == 1) && (confno_int >= 0 && confno_int < 1024)) {
  2282. conf_map[confno_int] = 0;
  2283. }
  2284. conf_free(conf);
  2285. res = 1;
  2286. }
  2287. AST_LIST_UNLOCK(&confs);
  2288. return res;
  2289. }
  2290. static int rt_extend_conf(const char *confno)
  2291. {
  2292. char currenttime[32];
  2293. char endtime[32];
  2294. struct timeval now;
  2295. struct ast_tm tm;
  2296. struct ast_variable *var, *orig_var;
  2297. char bookid[51];
  2298. if (!extendby) {
  2299. return 0;
  2300. }
  2301. now = ast_tvnow();
  2302. ast_localtime(&now, &tm, NULL);
  2303. ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
  2304. var = ast_load_realtime("meetme", "confno",
  2305. confno, "startTime<= ", currenttime,
  2306. "endtime>= ", currenttime, NULL);
  2307. orig_var = var;
  2308. /* Identify the specific RealTime conference */
  2309. while (var) {
  2310. if (!strcasecmp(var->name, "bookid")) {
  2311. ast_copy_string(bookid, var->value, sizeof(bookid));
  2312. }
  2313. if (!strcasecmp(var->name, "endtime")) {
  2314. ast_copy_string(endtime, var->value, sizeof(endtime));
  2315. }
  2316. var = var->next;
  2317. }
  2318. ast_variables_destroy(orig_var);
  2319. ast_strptime(endtime, DATE_FORMAT, &tm);
  2320. now = ast_mktime(&tm, NULL);
  2321. now.tv_sec += extendby;
  2322. ast_localtime(&now, &tm, NULL);
  2323. ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
  2324. strcat(currenttime, "0"); /* Seconds needs to be 00 */
  2325. var = ast_load_realtime("meetme", "confno",
  2326. confno, "startTime<= ", currenttime,
  2327. "endtime>= ", currenttime, NULL);
  2328. /* If there is no conflict with extending the conference, update the DB */
  2329. if (!var) {
  2330. ast_debug(3, "Trying to update the endtime of Conference %s to %s\n", confno, currenttime);
  2331. ast_update_realtime("meetme", "bookid", bookid, "endtime", currenttime, NULL);
  2332. return 0;
  2333. }
  2334. ast_variables_destroy(var);
  2335. return -1;
  2336. }
  2337. static void conf_start_moh(struct ast_channel *chan, const char *musicclass)
  2338. {
  2339. char *original_moh;
  2340. ast_channel_lock(chan);
  2341. original_moh = ast_strdupa(ast_channel_musicclass(chan));
  2342. ast_channel_musicclass_set(chan, musicclass);
  2343. ast_channel_unlock(chan);
  2344. ast_moh_start(chan, original_moh, NULL);
  2345. ast_channel_lock(chan);
  2346. ast_channel_musicclass_set(chan, original_moh);
  2347. ast_channel_unlock(chan);
  2348. }
  2349. static const char *get_announce_filename(enum announcetypes type)
  2350. {
  2351. switch (type) {
  2352. case CONF_HASLEFT:
  2353. return "conf-hasleft";
  2354. break;
  2355. case CONF_HASJOIN:
  2356. return "conf-hasjoin";
  2357. break;
  2358. default:
  2359. return "";
  2360. }
  2361. }
  2362. static void *announce_thread(void *data)
  2363. {
  2364. struct announce_listitem *current;
  2365. struct ast_conference *conf = data;
  2366. int res;
  2367. char filename[PATH_MAX] = "";
  2368. AST_LIST_HEAD_NOLOCK(, announce_listitem) local_list;
  2369. AST_LIST_HEAD_INIT_NOLOCK(&local_list);
  2370. while (!conf->announcethread_stop) {
  2371. ast_mutex_lock(&conf->announcelistlock);
  2372. if (conf->announcethread_stop) {
  2373. ast_mutex_unlock(&conf->announcelistlock);
  2374. break;
  2375. }
  2376. if (AST_LIST_EMPTY(&conf->announcelist))
  2377. ast_cond_wait(&conf->announcelist_addition, &conf->announcelistlock);
  2378. AST_LIST_APPEND_LIST(&local_list, &conf->announcelist, entry);
  2379. AST_LIST_HEAD_INIT_NOLOCK(&conf->announcelist);
  2380. ast_mutex_unlock(&conf->announcelistlock);
  2381. if (conf->announcethread_stop) {
  2382. break;
  2383. }
  2384. for (res = 1; !conf->announcethread_stop && (current = AST_LIST_REMOVE_HEAD(&local_list, entry)); ao2_ref(current, -1)) {
  2385. ast_debug(1, "About to play %s\n", current->namerecloc);
  2386. if (!ast_fileexists(current->namerecloc, NULL, NULL))
  2387. continue;
  2388. if ((current->confchan) && (current->confusers > 1) && !ast_check_hangup(current->confchan)) {
  2389. if (!ast_streamfile(current->confchan, current->namerecloc, current->language))
  2390. res = ast_waitstream(current->confchan, "");
  2391. if (!res) {
  2392. ast_copy_string(filename, get_announce_filename(current->announcetype), sizeof(filename));
  2393. if (!ast_streamfile(current->confchan, filename, current->language))
  2394. ast_waitstream(current->confchan, "");
  2395. }
  2396. }
  2397. if (current->announcetype == CONF_HASLEFT && current->announcetype && !current->vmrec) {
  2398. /* only remove it if it isn't a VM recording file */
  2399. ast_filedelete(current->namerecloc, NULL);
  2400. }
  2401. }
  2402. }
  2403. /* thread marked to stop, clean up */
  2404. while ((current = AST_LIST_REMOVE_HEAD(&local_list, entry))) {
  2405. /* only delete if it's a vm rec */
  2406. if (!current->vmrec) {
  2407. ast_filedelete(current->namerecloc, NULL);
  2408. }
  2409. ao2_ref(current, -1);
  2410. }
  2411. return NULL;
  2412. }
  2413. static int can_write(struct ast_channel *chan, struct ast_flags64 *confflags)
  2414. {
  2415. if (!ast_test_flag64(confflags, CONFFLAG_NO_AUDIO_UNTIL_UP)) {
  2416. return 1;
  2417. }
  2418. return (ast_channel_state(chan) == AST_STATE_UP);
  2419. }
  2420. static void send_talking_event(struct ast_channel *chan, struct ast_conference *conf, struct ast_conf_user *user, int talking)
  2421. {
  2422. RAII_VAR(struct ast_json *, status_blob, status_to_json(talking), ast_json_unref);
  2423. meetme_stasis_generate_msg(conf, chan, user, meetme_talking_type(), status_blob);
  2424. }
  2425. static void set_user_talking(struct ast_channel *chan, struct ast_conference *conf, struct ast_conf_user *user, int talking, int monitor)
  2426. {
  2427. int last_talking = user->talking;
  2428. if (last_talking == talking)
  2429. return;
  2430. user->talking = talking;
  2431. if (monitor) {
  2432. /* Check if talking state changed. Take care of -1 which means unmonitored */
  2433. int was_talking = (last_talking > 0);
  2434. int now_talking = (talking > 0);
  2435. if (was_talking != now_talking) {
  2436. send_talking_event(chan, conf, user, now_talking);
  2437. }
  2438. }
  2439. }
  2440. static int user_set_hangup_cb(void *obj, void *check_admin_arg, int flags)
  2441. {
  2442. struct ast_conf_user *user = obj;
  2443. /* actual pointer contents of check_admin_arg is irrelevant */
  2444. if (!check_admin_arg || (check_admin_arg && !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN))) {
  2445. user->adminflags |= ADMINFLAG_HANGUP;
  2446. }
  2447. return 0;
  2448. }
  2449. static int user_set_kickme_cb(void *obj, void *check_admin_arg, int flags)
  2450. {
  2451. struct ast_conf_user *user = obj;
  2452. /* actual pointer contents of check_admin_arg is irrelevant */
  2453. if (!check_admin_arg || (check_admin_arg && !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN))) {
  2454. user->adminflags |= ADMINFLAG_KICKME;
  2455. }
  2456. return 0;
  2457. }
  2458. static int user_set_unmuted_cb(void *obj, void *check_admin_arg, int flags)
  2459. {
  2460. struct ast_conf_user *user = obj;
  2461. /* actual pointer contents of check_admin_arg is irrelevant */
  2462. if (!check_admin_arg || !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN)) {
  2463. user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
  2464. }
  2465. return 0;
  2466. }
  2467. static int user_set_muted_cb(void *obj, void *check_admin_arg, int flags)
  2468. {
  2469. struct ast_conf_user *user = obj;
  2470. /* actual pointer contents of check_admin_arg is irrelevant */
  2471. if (!check_admin_arg || !ast_test_flag64(&user->userflags, CONFFLAG_ADMIN)) {
  2472. user->adminflags |= ADMINFLAG_MUTED;
  2473. }
  2474. return 0;
  2475. }
  2476. enum menu_modes {
  2477. MENU_DISABLED = 0,
  2478. MENU_NORMAL,
  2479. MENU_ADMIN,
  2480. MENU_ADMIN_EXTENDED,
  2481. };
  2482. /*! \internal
  2483. * \brief Processes menu options for the standard menu (accessible through the 's' option for app_meetme)
  2484. *
  2485. * \param menu_mode a pointer to the currently active menu_mode.
  2486. * \param dtmf a pointer to the dtmf value currently being processed against the menu.
  2487. * \param conf the active conference for which the user has called the menu from.
  2488. * \param confflags flags used by conf for various options
  2489. * \param chan ast_channel belonging to the user who called the menu
  2490. * \param user which meetme conference user invoked the menu
  2491. */
  2492. static void meetme_menu_normal(enum menu_modes *menu_mode, int *dtmf, struct ast_conference *conf, struct ast_flags64 *confflags, struct ast_channel *chan, struct ast_conf_user *user)
  2493. {
  2494. switch (*dtmf) {
  2495. case '1': /* Un/Mute */
  2496. *menu_mode = MENU_DISABLED;
  2497. /* user can only toggle the self-muted state */
  2498. user->adminflags ^= ADMINFLAG_SELFMUTED;
  2499. /* they can't override the admin mute state */
  2500. if (ast_test_flag64(confflags, CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
  2501. if (!ast_streamfile(chan, "conf-muted", ast_channel_language(chan))) {
  2502. ast_waitstream(chan, "");
  2503. }
  2504. } else {
  2505. if (!ast_streamfile(chan, "conf-unmuted", ast_channel_language(chan))) {
  2506. ast_waitstream(chan, "");
  2507. }
  2508. }
  2509. break;
  2510. case '2':
  2511. *menu_mode = MENU_DISABLED;
  2512. if (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) {
  2513. user->adminflags |= ADMINFLAG_T_REQUEST;
  2514. }
  2515. if (user->adminflags & ADMINFLAG_T_REQUEST) {
  2516. if (!ast_streamfile(chan, "beep", ast_channel_language(chan))) {
  2517. ast_waitstream(chan, "");
  2518. }
  2519. }
  2520. break;
  2521. case '4':
  2522. tweak_listen_volume(user, VOL_DOWN);
  2523. break;
  2524. case '5':
  2525. /* Extend RT conference */
  2526. if (rt_schedule) {
  2527. rt_extend_conf(conf->confno);
  2528. }
  2529. *menu_mode = MENU_DISABLED;
  2530. break;
  2531. case '6':
  2532. tweak_listen_volume(user, VOL_UP);
  2533. break;
  2534. case '7':
  2535. tweak_talk_volume(user, VOL_DOWN);
  2536. break;
  2537. case '8':
  2538. *menu_mode = MENU_DISABLED;
  2539. break;
  2540. case '9':
  2541. tweak_talk_volume(user, VOL_UP);
  2542. break;
  2543. default:
  2544. *menu_mode = MENU_DISABLED;
  2545. if (!ast_streamfile(chan, "conf-errormenu", ast_channel_language(chan))) {
  2546. ast_waitstream(chan, "");
  2547. }
  2548. break;
  2549. }
  2550. }
  2551. /*! \internal
  2552. * \brief Processes menu options for the adminstrator menu (accessible through the 's' option for app_meetme)
  2553. *
  2554. * \param menu_mode a pointer to the currently active menu_mode.
  2555. * \param dtmf a pointer to the dtmf value currently being processed against the menu.
  2556. * \param conf the active conference for which the user has called the menu from.
  2557. * \param confflags flags used by conf for various options
  2558. * \param chan ast_channel belonging to the user who called the menu
  2559. * \param user which meetme conference user invoked the menu
  2560. */
  2561. static void meetme_menu_admin(enum menu_modes *menu_mode, int *dtmf, struct ast_conference *conf, struct ast_flags64 *confflags, struct ast_channel *chan, struct ast_conf_user *user)
  2562. {
  2563. switch(*dtmf) {
  2564. case '1': /* Un/Mute */
  2565. *menu_mode = MENU_DISABLED;
  2566. /* for admin, change both admin and use flags */
  2567. if (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) {
  2568. user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED);
  2569. } else {
  2570. user->adminflags |= (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED);
  2571. }
  2572. if (ast_test_flag64(confflags, CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
  2573. if (!ast_streamfile(chan, "conf-muted", ast_channel_language(chan))) {
  2574. ast_waitstream(chan, "");
  2575. }
  2576. } else {
  2577. if (!ast_streamfile(chan, "conf-unmuted", ast_channel_language(chan))) {
  2578. ast_waitstream(chan, "");
  2579. }
  2580. }
  2581. break;
  2582. case '2': /* Un/Lock the Conference */
  2583. *menu_mode = MENU_DISABLED;
  2584. if (conf->locked) {
  2585. conf->locked = 0;
  2586. if (!ast_streamfile(chan, "conf-unlockednow", ast_channel_language(chan))) {
  2587. ast_waitstream(chan, "");
  2588. }
  2589. } else {
  2590. conf->locked = 1;
  2591. if (!ast_streamfile(chan, "conf-lockednow", ast_channel_language(chan))) {
  2592. ast_waitstream(chan, "");
  2593. }
  2594. }
  2595. break;
  2596. case '3': /* Eject last user */
  2597. {
  2598. struct ast_conf_user *usr = NULL;
  2599. int max_no = 0;
  2600. ao2_callback(conf->usercontainer, OBJ_NODATA, user_max_cmp, &max_no);
  2601. *menu_mode = MENU_DISABLED;
  2602. usr = ao2_find(conf->usercontainer, &max_no, 0);
  2603. if ((ast_channel_name(usr->chan) == ast_channel_name(chan)) || ast_test_flag64(&usr->userflags, CONFFLAG_ADMIN)) {
  2604. if (!ast_streamfile(chan, "conf-errormenu", ast_channel_language(chan))) {
  2605. ast_waitstream(chan, "");
  2606. }
  2607. } else {
  2608. usr->adminflags |= ADMINFLAG_KICKME;
  2609. }
  2610. ao2_ref(usr, -1);
  2611. ast_stopstream(chan);
  2612. break;
  2613. }
  2614. case '4':
  2615. tweak_listen_volume(user, VOL_DOWN);
  2616. break;
  2617. case '5':
  2618. /* Extend RT conference */
  2619. if (rt_schedule) {
  2620. if (!rt_extend_conf(conf->confno)) {
  2621. if (!ast_streamfile(chan, "conf-extended", ast_channel_language(chan))) {
  2622. ast_waitstream(chan, "");
  2623. }
  2624. } else {
  2625. if (!ast_streamfile(chan, "conf-nonextended", ast_channel_language(chan))) {
  2626. ast_waitstream(chan, "");
  2627. }
  2628. }
  2629. ast_stopstream(chan);
  2630. }
  2631. *menu_mode = MENU_DISABLED;
  2632. break;
  2633. case '6':
  2634. tweak_listen_volume(user, VOL_UP);
  2635. break;
  2636. case '7':
  2637. tweak_talk_volume(user, VOL_DOWN);
  2638. break;
  2639. case '8':
  2640. if (!ast_streamfile(chan, "conf-adminmenu-menu8", ast_channel_language(chan))) {
  2641. /* If the user provides DTMF while playing the sound, we want to drop right into the extended menu function with new DTMF once we get out of here. */
  2642. *dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
  2643. ast_stopstream(chan);
  2644. }
  2645. *menu_mode = MENU_ADMIN_EXTENDED;
  2646. break;
  2647. case '9':
  2648. tweak_talk_volume(user, VOL_UP);
  2649. break;
  2650. default:
  2651. *menu_mode = MENU_DISABLED;
  2652. /* Play an error message! */
  2653. if (!ast_streamfile(chan, "conf-errormenu", ast_channel_language(chan))) {
  2654. ast_waitstream(chan, "");
  2655. }
  2656. break;
  2657. }
  2658. }
  2659. /*! \internal
  2660. * \brief Processes menu options for the extended administrator menu (accessible through option 8 on the administrator menu)
  2661. *
  2662. * \param menu_mode a pointer to the currently active menu_mode.
  2663. * \param dtmf a pointer to the dtmf value currently being processed against the menu.
  2664. * \param conf the active conference for which the user has called the menu from.
  2665. * \param confflags flags used by conf for various options
  2666. * \param chan ast_channel belonging to the user who called the menu
  2667. * \param user which meetme conference user invoked the menu
  2668. * \param recordingtmp character buffer which may hold the name of the conference recording file
  2669. */
  2670. static void meetme_menu_admin_extended(enum menu_modes *menu_mode, int *dtmf,
  2671. struct ast_conference *conf, struct ast_flags64 *confflags, struct ast_channel *chan,
  2672. struct ast_conf_user *user, char *recordingtmp, int recordingtmp_size,
  2673. struct ast_format_cap *cap_slin)
  2674. {
  2675. int keepplaying;
  2676. int playednamerec;
  2677. int res;
  2678. struct ao2_iterator user_iter;
  2679. struct ast_conf_user *usr = NULL;
  2680. switch(*dtmf) {
  2681. case '1': /* *81 Roll call */
  2682. keepplaying = 1;
  2683. playednamerec = 0;
  2684. if (conf->users == 1) {
  2685. if (keepplaying && !ast_streamfile(chan, "conf-onlyperson", ast_channel_language(chan))) {
  2686. res = ast_waitstream(chan, AST_DIGIT_ANY);
  2687. ast_stopstream(chan);
  2688. if (res > 0) {
  2689. keepplaying = 0;
  2690. }
  2691. }
  2692. } else if (conf->users == 2) {
  2693. if (keepplaying && !ast_streamfile(chan, "conf-onlyone", ast_channel_language(chan))) {
  2694. res = ast_waitstream(chan, AST_DIGIT_ANY);
  2695. ast_stopstream(chan);
  2696. if (res > 0) {
  2697. keepplaying = 0;
  2698. }
  2699. }
  2700. } else {
  2701. if (keepplaying && !ast_streamfile(chan, "conf-thereare", ast_channel_language(chan))) {
  2702. res = ast_waitstream(chan, AST_DIGIT_ANY);
  2703. ast_stopstream(chan);
  2704. if (res > 0) {
  2705. keepplaying = 0;
  2706. }
  2707. }
  2708. if (keepplaying) {
  2709. res = ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, ast_channel_language(chan), (char *) NULL);
  2710. ast_stopstream(chan);
  2711. if (res > 0) {
  2712. keepplaying = 0;
  2713. }
  2714. }
  2715. if (keepplaying && !ast_streamfile(chan, "conf-otherinparty", ast_channel_language(chan))) {
  2716. res = ast_waitstream(chan, AST_DIGIT_ANY);
  2717. ast_stopstream(chan);
  2718. if (res > 0) {
  2719. keepplaying = 0;
  2720. }
  2721. }
  2722. }
  2723. user_iter = ao2_iterator_init(conf->usercontainer, 0);
  2724. while((usr = ao2_iterator_next(&user_iter))) {
  2725. if (ast_fileexists(usr->namerecloc, NULL, NULL)) {
  2726. if (keepplaying && !ast_streamfile(chan, usr->namerecloc, ast_channel_language(chan))) {
  2727. res = ast_waitstream(chan, AST_DIGIT_ANY);
  2728. ast_stopstream(chan);
  2729. if (res > 0) {
  2730. keepplaying = 0;
  2731. }
  2732. }
  2733. playednamerec = 1;
  2734. }
  2735. ao2_ref(usr, -1);
  2736. }
  2737. ao2_iterator_destroy(&user_iter);
  2738. if (keepplaying && playednamerec && !ast_streamfile(chan, "conf-roll-callcomplete", ast_channel_language(chan))) {
  2739. res = ast_waitstream(chan, AST_DIGIT_ANY);
  2740. ast_stopstream(chan);
  2741. if (res > 0) {
  2742. keepplaying = 0;
  2743. }
  2744. }
  2745. *menu_mode = MENU_DISABLED;
  2746. break;
  2747. case '2': /* *82 Eject all non-admins */
  2748. if (conf->users == 1) {
  2749. if(!ast_streamfile(chan, "conf-errormenu", ast_channel_language(chan))) {
  2750. ast_waitstream(chan, "");
  2751. }
  2752. } else {
  2753. ao2_callback(conf->usercontainer, OBJ_NODATA, user_set_kickme_cb, &conf);
  2754. }
  2755. ast_stopstream(chan);
  2756. *menu_mode = MENU_DISABLED;
  2757. break;
  2758. case '3': /* *83 (Admin) mute/unmute all non-admins */
  2759. if(conf->gmuted) {
  2760. conf->gmuted = 0;
  2761. ao2_callback(conf->usercontainer, OBJ_NODATA, user_set_unmuted_cb, &conf);
  2762. if (!ast_streamfile(chan, "conf-now-unmuted", ast_channel_language(chan))) {
  2763. ast_waitstream(chan, "");
  2764. }
  2765. } else {
  2766. conf->gmuted = 1;
  2767. ao2_callback(conf->usercontainer, OBJ_NODATA, user_set_muted_cb, &conf);
  2768. if (!ast_streamfile(chan, "conf-now-muted", ast_channel_language(chan))) {
  2769. ast_waitstream(chan, "");
  2770. }
  2771. }
  2772. ast_stopstream(chan);
  2773. *menu_mode = MENU_DISABLED;
  2774. break;
  2775. case '4': /* *84 Record conference */
  2776. if (conf->recording != MEETME_RECORD_ACTIVE) {
  2777. ast_set_flag64(confflags, CONFFLAG_RECORDCONF);
  2778. if (!conf->recordingfilename) {
  2779. const char *var;
  2780. ast_channel_lock(chan);
  2781. if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE"))) {
  2782. conf->recordingfilename = ast_strdup(var);
  2783. }
  2784. if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT"))) {
  2785. conf->recordingformat = ast_strdup(var);
  2786. }
  2787. ast_channel_unlock(chan);
  2788. if (!conf->recordingfilename) {
  2789. snprintf(recordingtmp, recordingtmp_size, "meetme-conf-rec-%s-%s", conf->confno, ast_channel_uniqueid(chan));
  2790. conf->recordingfilename = ast_strdup(recordingtmp);
  2791. }
  2792. if (!conf->recordingformat) {
  2793. conf->recordingformat = ast_strdup("wav");
  2794. }
  2795. ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n",
  2796. conf->confno, conf->recordingfilename, conf->recordingformat);
  2797. }
  2798. ast_mutex_lock(&conf->recordthreadlock);
  2799. if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) && ((conf->lchan = ast_request("DAHDI", cap_slin, NULL, chan, "pseudo", NULL)))) {
  2800. struct dahdi_confinfo dahdic;
  2801. ast_set_read_format(conf->lchan, ast_format_slin);
  2802. ast_set_write_format(conf->lchan, ast_format_slin);
  2803. dahdic.chan = 0;
  2804. dahdic.confno = conf->dahdiconf;
  2805. dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
  2806. if (ioctl(ast_channel_fd(conf->lchan, 0), DAHDI_SETCONF, &dahdic)) {
  2807. ast_log(LOG_WARNING, "Error starting listen channel\n");
  2808. ast_hangup(conf->lchan);
  2809. conf->lchan = NULL;
  2810. } else {
  2811. ast_pthread_create_detached_background(&conf->recordthread, NULL, recordthread, conf);
  2812. }
  2813. }
  2814. ast_mutex_unlock(&conf->recordthreadlock);
  2815. if (!ast_streamfile(chan, "conf-now-recording", ast_channel_language(chan))) {
  2816. ast_waitstream(chan, "");
  2817. }
  2818. }
  2819. ast_stopstream(chan);
  2820. *menu_mode = MENU_DISABLED;
  2821. break;
  2822. case '8': /* *88 Exit the menu and return to the conference... without an error message */
  2823. ast_stopstream(chan);
  2824. *menu_mode = MENU_DISABLED;
  2825. break;
  2826. default:
  2827. if (!ast_streamfile(chan, "conf-errormenu", ast_channel_language(chan))) {
  2828. ast_waitstream(chan, "");
  2829. }
  2830. ast_stopstream(chan);
  2831. *menu_mode = MENU_DISABLED;
  2832. break;
  2833. }
  2834. }
  2835. /*! \internal
  2836. * \brief Processes menu options for the various menu types (accessible through the 's' option for app_meetme)
  2837. *
  2838. * \param menu_mode a pointer to the currently active menu_mode.
  2839. * \param dtmf a pointer to the dtmf value currently being processed against the menu.
  2840. * \param conf the active conference for which the user has called the menu from.
  2841. * \param confflags flags used by conf for various options
  2842. * \param chan ast_channel belonging to the user who called the menu
  2843. * \param user which meetme conference user invoked the menu
  2844. * \param recordingtmp character buffer which may hold the name of the conference recording file
  2845. */
  2846. static void meetme_menu(enum menu_modes *menu_mode, int *dtmf,
  2847. struct ast_conference *conf, struct ast_flags64 *confflags, struct ast_channel *chan,
  2848. struct ast_conf_user *user, char *recordingtmp, int recordingtmp_size,
  2849. struct ast_format_cap *cap_slin)
  2850. {
  2851. switch (*menu_mode) {
  2852. case MENU_DISABLED:
  2853. break;
  2854. case MENU_NORMAL:
  2855. meetme_menu_normal(menu_mode, dtmf, conf, confflags, chan, user);
  2856. break;
  2857. case MENU_ADMIN:
  2858. meetme_menu_admin(menu_mode, dtmf, conf, confflags, chan, user);
  2859. /* Admin Menu is capable of branching into another menu, in which case it will reset dtmf and change the menu mode. */
  2860. if (*menu_mode != MENU_ADMIN_EXTENDED || (*dtmf <= 0)) {
  2861. break;
  2862. }
  2863. case MENU_ADMIN_EXTENDED:
  2864. meetme_menu_admin_extended(menu_mode, dtmf, conf, confflags, chan, user,
  2865. recordingtmp, recordingtmp_size, cap_slin);
  2866. break;
  2867. }
  2868. }
  2869. static int conf_run(struct ast_channel *chan, struct ast_conference *conf, struct ast_flags64 *confflags, char *optargs[])
  2870. {
  2871. struct ast_conf_user *user = NULL;
  2872. int fd;
  2873. struct dahdi_confinfo dahdic, dahdic_empty;
  2874. struct ast_frame *f;
  2875. struct ast_channel *c;
  2876. struct ast_frame fr;
  2877. int outfd;
  2878. int ms;
  2879. int nfds;
  2880. int res;
  2881. int retrydahdi;
  2882. int origfd;
  2883. int musiconhold = 0, mohtempstopped = 0;
  2884. int firstpass = 0;
  2885. int lastmarked = 0;
  2886. int currentmarked = 0;
  2887. int ret = -1;
  2888. int x;
  2889. enum menu_modes menu_mode = MENU_DISABLED;
  2890. int talkreq_manager = 0;
  2891. int using_pseudo = 0;
  2892. int duration = 20;
  2893. int sent_event = 0;
  2894. int checked = 0;
  2895. int announcement_played = 0;
  2896. struct timeval now;
  2897. struct ast_dsp *dsp = NULL;
  2898. struct ast_app *agi_app;
  2899. char *agifile;
  2900. const char *agifiledefault = "conf-background.agi", *tmpvar;
  2901. char meetmesecs[30] = "";
  2902. char exitcontext[AST_MAX_CONTEXT] = "";
  2903. char recordingtmp[AST_MAX_EXTENSION * 2] = "";
  2904. char members[10] = "";
  2905. int dtmf = 0, opt_waitmarked_timeout = 0;
  2906. time_t timeout = 0;
  2907. struct dahdi_bufferinfo bi;
  2908. char __buf[CONF_SIZE + AST_FRIENDLY_OFFSET];
  2909. char *buf = __buf + AST_FRIENDLY_OFFSET;
  2910. char *exitkeys = NULL;
  2911. unsigned int calldurationlimit = 0;
  2912. long timelimit = 0;
  2913. long play_warning = 0;
  2914. long warning_freq = 0;
  2915. const char *warning_sound = NULL;
  2916. const char *end_sound = NULL;
  2917. char *parse;
  2918. long time_left_ms = 0;
  2919. struct timeval nexteventts = { 0, };
  2920. int to;
  2921. int setusercount = 0;
  2922. int confsilence = 0, totalsilence = 0;
  2923. char *mailbox, *context;
  2924. struct ast_format_cap *cap_slin = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
  2925. if (!cap_slin) {
  2926. goto conf_run_cleanup;
  2927. }
  2928. ast_format_cap_append(cap_slin, ast_format_slin, 0);
  2929. if (!(user = ao2_alloc(sizeof(*user), NULL))) {
  2930. goto conf_run_cleanup;
  2931. }
  2932. /* Possible timeout waiting for marked user */
  2933. if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED) &&
  2934. !ast_strlen_zero(optargs[OPT_ARG_WAITMARKED]) &&
  2935. (sscanf(optargs[OPT_ARG_WAITMARKED], "%30d", &opt_waitmarked_timeout) == 1) &&
  2936. (opt_waitmarked_timeout > 0)) {
  2937. timeout = time(NULL) + opt_waitmarked_timeout;
  2938. }
  2939. if (ast_test_flag64(confflags, CONFFLAG_DURATION_STOP) && !ast_strlen_zero(optargs[OPT_ARG_DURATION_STOP])) {
  2940. calldurationlimit = atoi(optargs[OPT_ARG_DURATION_STOP]);
  2941. ast_verb(3, "Setting call duration limit to %u seconds.\n", calldurationlimit);
  2942. }
  2943. if (ast_test_flag64(confflags, CONFFLAG_DURATION_LIMIT) && !ast_strlen_zero(optargs[OPT_ARG_DURATION_LIMIT])) {
  2944. char *limit_str, *warning_str, *warnfreq_str;
  2945. const char *var;
  2946. parse = optargs[OPT_ARG_DURATION_LIMIT];
  2947. limit_str = strsep(&parse, ":");
  2948. warning_str = strsep(&parse, ":");
  2949. warnfreq_str = parse;
  2950. timelimit = atol(limit_str);
  2951. if (warning_str)
  2952. play_warning = atol(warning_str);
  2953. if (warnfreq_str)
  2954. warning_freq = atol(warnfreq_str);
  2955. if (!timelimit) {
  2956. timelimit = play_warning = warning_freq = 0;
  2957. warning_sound = NULL;
  2958. } else if (play_warning > timelimit) {
  2959. if (!warning_freq) {
  2960. play_warning = 0;
  2961. } else {
  2962. while (play_warning > timelimit)
  2963. play_warning -= warning_freq;
  2964. if (play_warning < 1)
  2965. play_warning = warning_freq = 0;
  2966. }
  2967. }
  2968. ast_verb(3, "Setting conference duration limit to: %ldms.\n", timelimit);
  2969. if (play_warning) {
  2970. ast_verb(3, "Setting warning time to %ldms from the conference duration limit.\n", play_warning);
  2971. }
  2972. if (warning_freq) {
  2973. ast_verb(3, "Setting warning frequency to %ldms.\n", warning_freq);
  2974. }
  2975. ast_channel_lock(chan);
  2976. if ((var = pbx_builtin_getvar_helper(chan, "CONF_LIMIT_WARNING_FILE"))) {
  2977. var = ast_strdupa(var);
  2978. }
  2979. ast_channel_unlock(chan);
  2980. warning_sound = var ? var : "timeleft";
  2981. ast_channel_lock(chan);
  2982. if ((var = pbx_builtin_getvar_helper(chan, "CONF_LIMIT_TIMEOUT_FILE"))) {
  2983. var = ast_strdupa(var);
  2984. }
  2985. ast_channel_unlock(chan);
  2986. end_sound = var ? var : NULL;
  2987. /* undo effect of S(x) in case they are both used */
  2988. calldurationlimit = 0;
  2989. /* more efficient do it like S(x) does since no advanced opts */
  2990. if (!play_warning && !end_sound && timelimit) {
  2991. calldurationlimit = timelimit / 1000;
  2992. timelimit = play_warning = warning_freq = 0;
  2993. } else {
  2994. ast_debug(2, "Limit Data for this call:\n");
  2995. ast_debug(2, "- timelimit = %ld\n", timelimit);
  2996. ast_debug(2, "- play_warning = %ld\n", play_warning);
  2997. ast_debug(2, "- warning_freq = %ld\n", warning_freq);
  2998. ast_debug(2, "- warning_sound = %s\n", warning_sound ? warning_sound : "UNDEF");
  2999. ast_debug(2, "- end_sound = %s\n", end_sound ? end_sound : "UNDEF");
  3000. }
  3001. }
  3002. /* Get exit keys */
  3003. if (ast_test_flag64(confflags, CONFFLAG_KEYEXIT)) {
  3004. if (!ast_strlen_zero(optargs[OPT_ARG_EXITKEYS]))
  3005. exitkeys = ast_strdupa(optargs[OPT_ARG_EXITKEYS]);
  3006. else
  3007. exitkeys = ast_strdupa("#"); /* Default */
  3008. }
  3009. if (ast_test_flag64(confflags, CONFFLAG_RECORDCONF)) {
  3010. if (!conf->recordingfilename) {
  3011. const char *var;
  3012. ast_channel_lock(chan);
  3013. if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE"))) {
  3014. conf->recordingfilename = ast_strdup(var);
  3015. }
  3016. if ((var = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT"))) {
  3017. conf->recordingformat = ast_strdup(var);
  3018. }
  3019. ast_channel_unlock(chan);
  3020. if (!conf->recordingfilename) {
  3021. snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", conf->confno, ast_channel_uniqueid(chan));
  3022. conf->recordingfilename = ast_strdup(recordingtmp);
  3023. }
  3024. if (!conf->recordingformat) {
  3025. conf->recordingformat = ast_strdup("wav");
  3026. }
  3027. ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n",
  3028. conf->confno, conf->recordingfilename, conf->recordingformat);
  3029. }
  3030. }
  3031. ast_mutex_lock(&conf->recordthreadlock);
  3032. if ((conf->recordthread == AST_PTHREADT_NULL) && ast_test_flag64(confflags, CONFFLAG_RECORDCONF) &&
  3033. ((conf->lchan = ast_request("DAHDI", cap_slin, NULL, chan, "pseudo", NULL)))) {
  3034. ast_set_read_format(conf->lchan, ast_format_slin);
  3035. ast_set_write_format(conf->lchan, ast_format_slin);
  3036. dahdic.chan = 0;
  3037. dahdic.confno = conf->dahdiconf;
  3038. dahdic.confmode = DAHDI_CONF_CONFANN | DAHDI_CONF_CONFANNMON;
  3039. if (ioctl(ast_channel_fd(conf->lchan, 0), DAHDI_SETCONF, &dahdic)) {
  3040. ast_log(LOG_WARNING, "Error starting listen channel\n");
  3041. ast_hangup(conf->lchan);
  3042. conf->lchan = NULL;
  3043. } else {
  3044. ast_pthread_create_detached_background(&conf->recordthread, NULL, recordthread, conf);
  3045. }
  3046. }
  3047. ast_mutex_unlock(&conf->recordthreadlock);
  3048. ast_mutex_lock(&conf->announcethreadlock);
  3049. if ((conf->announcethread == AST_PTHREADT_NULL) && !ast_test_flag64(confflags, CONFFLAG_QUIET) &&
  3050. ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC)) {
  3051. ast_mutex_init(&conf->announcelistlock);
  3052. AST_LIST_HEAD_INIT_NOLOCK(&conf->announcelist);
  3053. ast_pthread_create_background(&conf->announcethread, NULL, announce_thread, conf);
  3054. }
  3055. ast_mutex_unlock(&conf->announcethreadlock);
  3056. time(&user->jointime);
  3057. user->timelimit = timelimit;
  3058. user->play_warning = play_warning;
  3059. user->warning_freq = warning_freq;
  3060. user->warning_sound = warning_sound;
  3061. user->end_sound = end_sound;
  3062. if (calldurationlimit > 0) {
  3063. time(&user->kicktime);
  3064. user->kicktime = user->kicktime + calldurationlimit;
  3065. }
  3066. if (ast_tvzero(user->start_time))
  3067. user->start_time = ast_tvnow();
  3068. time_left_ms = user->timelimit;
  3069. if (user->timelimit) {
  3070. nexteventts = ast_tvadd(user->start_time, ast_samp2tv(user->timelimit, 1000));
  3071. nexteventts = ast_tvsub(nexteventts, ast_samp2tv(user->play_warning, 1000));
  3072. }
  3073. if (conf->locked && (!ast_test_flag64(confflags, CONFFLAG_ADMIN))) {
  3074. /* Sorry, but this conference is locked! */
  3075. if (!ast_streamfile(chan, "conf-locked", ast_channel_language(chan)))
  3076. ast_waitstream(chan, "");
  3077. goto outrun;
  3078. }
  3079. ast_mutex_lock(&conf->playlock);
  3080. if (rt_schedule && conf->maxusers) {
  3081. if (conf->users >= conf->maxusers) {
  3082. /* Sorry, but this confernce has reached the participant limit! */
  3083. ast_mutex_unlock(&conf->playlock);
  3084. if (!ast_streamfile(chan, "conf-full", ast_channel_language(chan)))
  3085. ast_waitstream(chan, "");
  3086. goto outrun;
  3087. }
  3088. }
  3089. ao2_lock(conf->usercontainer);
  3090. ao2_callback(conf->usercontainer, OBJ_NODATA, user_max_cmp, &user->user_no);
  3091. user->user_no++;
  3092. ao2_link(conf->usercontainer, user);
  3093. ao2_unlock(conf->usercontainer);
  3094. user->chan = chan;
  3095. user->userflags = *confflags;
  3096. user->adminflags = ast_test_flag64(confflags, CONFFLAG_STARTMUTED) ? ADMINFLAG_SELFMUTED : 0;
  3097. user->adminflags |= (conf->gmuted) ? ADMINFLAG_MUTED : 0;
  3098. user->talking = -1;
  3099. ast_mutex_unlock(&conf->playlock);
  3100. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && (ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC))) {
  3101. char destdir[PATH_MAX];
  3102. snprintf(destdir, sizeof(destdir), "%s/meetme", ast_config_AST_SPOOL_DIR);
  3103. if (ast_mkdir(destdir, 0777) != 0) {
  3104. ast_log(LOG_WARNING, "mkdir '%s' failed: %s\n", destdir, strerror(errno));
  3105. goto outrun;
  3106. }
  3107. if (ast_test_flag64(confflags, CONFFLAG_INTROUSER_VMREC)){
  3108. context = ast_strdupa(optargs[OPT_ARG_INTROUSER_VMREC]);
  3109. mailbox = strsep(&context, "@");
  3110. if (ast_strlen_zero(mailbox)) {
  3111. /* invalid input, clear the v flag*/
  3112. ast_clear_flag64(confflags,CONFFLAG_INTROUSER_VMREC);
  3113. ast_log(LOG_WARNING,"You must specify a mailbox in the v() option\n");
  3114. } else {
  3115. if (ast_strlen_zero(context)) {
  3116. context = "default";
  3117. }
  3118. /* if there is no mailbox we don't need to do this logic */
  3119. snprintf(user->namerecloc, sizeof(user->namerecloc),
  3120. "%s/voicemail/%s/%s/greet",ast_config_AST_SPOOL_DIR,context,mailbox);
  3121. /* if the greeting doesn't exist then use the temp file method instead, clear flag v */
  3122. if (!ast_fileexists(user->namerecloc, NULL, NULL)){
  3123. snprintf(user->namerecloc, sizeof(user->namerecloc),
  3124. "%s/meetme-username-%s-%d", destdir,
  3125. conf->confno, user->user_no);
  3126. ast_clear_flag64(confflags, CONFFLAG_INTROUSER_VMREC);
  3127. }
  3128. }
  3129. } else {
  3130. snprintf(user->namerecloc, sizeof(user->namerecloc),
  3131. "%s/meetme-username-%s-%d", destdir,
  3132. conf->confno, user->user_no);
  3133. }
  3134. res = 0;
  3135. if (ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW) && !ast_fileexists(user->namerecloc, NULL, NULL))
  3136. res = ast_play_and_record(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE), 0, NULL);
  3137. else if (ast_test_flag64(confflags, CONFFLAG_INTROUSER) && !ast_fileexists(user->namerecloc, NULL, NULL))
  3138. res = ast_record_review(chan, "vm-rec-name", user->namerecloc, 10, "sln", &duration, NULL);
  3139. if (res == -1)
  3140. goto outrun;
  3141. }
  3142. ast_mutex_lock(&conf->playlock);
  3143. if (ast_test_flag64(confflags, CONFFLAG_MARKEDUSER))
  3144. conf->markedusers++;
  3145. conf->users++;
  3146. if (rt_log_members) {
  3147. /* Update table */
  3148. snprintf(members, sizeof(members), "%d", conf->users);
  3149. ast_realtime_require_field("meetme",
  3150. "confno", strlen(conf->confno) > 7 ? RQ_UINTEGER4 : strlen(conf->confno) > 4 ? RQ_UINTEGER3 : RQ_UINTEGER2, strlen(conf->confno),
  3151. "members", RQ_UINTEGER1, strlen(members),
  3152. NULL);
  3153. ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
  3154. }
  3155. setusercount = 1;
  3156. /* This device changed state now - if this is the first user */
  3157. if (conf->users == 1)
  3158. ast_devstate_changed(AST_DEVICE_INUSE, (conf->isdynamic ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), "meetme:%s", conf->confno);
  3159. ast_mutex_unlock(&conf->playlock);
  3160. /* return the unique ID of the conference */
  3161. pbx_builtin_setvar_helper(chan, "MEETMEUNIQUEID", conf->uniqueid);
  3162. if (ast_test_flag64(confflags, CONFFLAG_EXIT_CONTEXT)) {
  3163. ast_channel_lock(chan);
  3164. if ((tmpvar = pbx_builtin_getvar_helper(chan, "MEETME_EXIT_CONTEXT"))) {
  3165. ast_copy_string(exitcontext, tmpvar, sizeof(exitcontext));
  3166. } else if (!ast_strlen_zero(ast_channel_macrocontext(chan))) {
  3167. ast_copy_string(exitcontext, ast_channel_macrocontext(chan), sizeof(exitcontext));
  3168. } else {
  3169. ast_copy_string(exitcontext, ast_channel_context(chan), sizeof(exitcontext));
  3170. }
  3171. ast_channel_unlock(chan);
  3172. }
  3173. /* Play an arbitrary intro message */
  3174. if (ast_test_flag64(confflags, CONFFLAG_INTROMSG) &&
  3175. !ast_strlen_zero(optargs[OPT_ARG_INTROMSG])) {
  3176. if (!ast_streamfile(chan, optargs[OPT_ARG_INTROMSG], ast_channel_language(chan))) {
  3177. ast_waitstream(chan, "");
  3178. }
  3179. }
  3180. if (!ast_test_flag64(confflags, (CONFFLAG_QUIET | CONFFLAG_NOONLYPERSON))) {
  3181. if (conf->users == 1 && !ast_test_flag64(confflags, CONFFLAG_WAITMARKED))
  3182. if (!ast_streamfile(chan, "conf-onlyperson", ast_channel_language(chan)))
  3183. ast_waitstream(chan, "");
  3184. if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED) && conf->markedusers == 0)
  3185. if (!ast_streamfile(chan, "conf-waitforleader", ast_channel_language(chan)))
  3186. ast_waitstream(chan, "");
  3187. }
  3188. if (ast_test_flag64(confflags, CONFFLAG_ANNOUNCEUSERCOUNT) && conf->users > 1) {
  3189. int keepplaying = 1;
  3190. if (conf->users == 2) {
  3191. if (!ast_streamfile(chan, "conf-onlyone", ast_channel_language(chan))) {
  3192. res = ast_waitstream(chan, AST_DIGIT_ANY);
  3193. ast_stopstream(chan);
  3194. if (res > 0)
  3195. keepplaying = 0;
  3196. else if (res == -1)
  3197. goto outrun;
  3198. }
  3199. } else {
  3200. if (!ast_streamfile(chan, "conf-thereare", ast_channel_language(chan))) {
  3201. res = ast_waitstream(chan, AST_DIGIT_ANY);
  3202. ast_stopstream(chan);
  3203. if (res > 0)
  3204. keepplaying = 0;
  3205. else if (res == -1)
  3206. goto outrun;
  3207. }
  3208. if (keepplaying) {
  3209. res = ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, ast_channel_language(chan), (char *) NULL);
  3210. if (res > 0)
  3211. keepplaying = 0;
  3212. else if (res == -1)
  3213. goto outrun;
  3214. }
  3215. if (keepplaying && !ast_streamfile(chan, "conf-otherinparty", ast_channel_language(chan))) {
  3216. res = ast_waitstream(chan, AST_DIGIT_ANY);
  3217. ast_stopstream(chan);
  3218. if (res > 0)
  3219. keepplaying = 0;
  3220. else if (res == -1)
  3221. goto outrun;
  3222. }
  3223. }
  3224. }
  3225. if (!ast_test_flag64(confflags, CONFFLAG_NO_AUDIO_UNTIL_UP)) {
  3226. /* We're leaving this alone until the state gets changed to up */
  3227. ast_indicate(chan, -1);
  3228. }
  3229. if (ast_set_write_format(chan, ast_format_slin) < 0) {
  3230. ast_log(LOG_WARNING, "Unable to set '%s' to write linear mode\n", ast_channel_name(chan));
  3231. goto outrun;
  3232. }
  3233. if (ast_set_read_format(chan, ast_format_slin) < 0) {
  3234. ast_log(LOG_WARNING, "Unable to set '%s' to read linear mode\n", ast_channel_name(chan));
  3235. goto outrun;
  3236. }
  3237. /* Reduce background noise from each participant */
  3238. if (!ast_test_flag64(confflags, CONFFLAG_DONT_DENOISE) && ast_module_check("func_speex.so")) {
  3239. ast_func_write(chan, "DENOISE(rx)", "on");
  3240. }
  3241. retrydahdi = (strcasecmp(ast_channel_tech(chan)->type, "DAHDI") || (ast_channel_audiohooks(chan) || ast_channel_monitor(chan)) ? 1 : 0);
  3242. user->dahdichannel = !retrydahdi;
  3243. dahdiretry:
  3244. origfd = ast_channel_fd(chan, 0);
  3245. if (retrydahdi) {
  3246. /* open pseudo in non-blocking mode */
  3247. fd = open("/dev/dahdi/pseudo", O_RDWR | O_NONBLOCK);
  3248. if (fd < 0) {
  3249. ast_log(LOG_WARNING, "Unable to open DAHDI pseudo channel: %s\n", strerror(errno));
  3250. goto outrun;
  3251. }
  3252. using_pseudo = 1;
  3253. /* Setup buffering information */
  3254. memset(&bi, 0, sizeof(bi));
  3255. bi.bufsize = CONF_SIZE / 2;
  3256. bi.txbufpolicy = DAHDI_POLICY_IMMEDIATE;
  3257. bi.rxbufpolicy = DAHDI_POLICY_IMMEDIATE;
  3258. bi.numbufs = audio_buffers;
  3259. if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) {
  3260. ast_log(LOG_WARNING, "Unable to set buffering information: %s\n", strerror(errno));
  3261. close(fd);
  3262. goto outrun;
  3263. }
  3264. x = 1;
  3265. if (ioctl(fd, DAHDI_SETLINEAR, &x)) {
  3266. ast_log(LOG_WARNING, "Unable to set linear mode: %s\n", strerror(errno));
  3267. close(fd);
  3268. goto outrun;
  3269. }
  3270. nfds = 1;
  3271. } else {
  3272. /* XXX Make sure we're not running on a pseudo channel XXX */
  3273. fd = ast_channel_fd(chan, 0);
  3274. nfds = 0;
  3275. }
  3276. memset(&dahdic, 0, sizeof(dahdic));
  3277. memset(&dahdic_empty, 0, sizeof(dahdic_empty));
  3278. /* Check to see if we're in a conference... */
  3279. dahdic.chan = 0;
  3280. if (ioctl(fd, DAHDI_GETCONF, &dahdic)) {
  3281. ast_log(LOG_WARNING, "Error getting conference\n");
  3282. close(fd);
  3283. goto outrun;
  3284. }
  3285. if (dahdic.confmode) {
  3286. /* Whoa, already in a conference... Retry... */
  3287. if (!retrydahdi) {
  3288. ast_debug(1, "DAHDI channel is in a conference already, retrying with pseudo\n");
  3289. retrydahdi = 1;
  3290. goto dahdiretry;
  3291. }
  3292. }
  3293. memset(&dahdic, 0, sizeof(dahdic));
  3294. /* Add us to the conference */
  3295. dahdic.chan = 0;
  3296. dahdic.confno = conf->dahdiconf;
  3297. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && (ast_test_flag64(confflags, CONFFLAG_INTROUSER) ||
  3298. ast_test_flag64(confflags, CONFFLAG_INTROUSERNOREVIEW) || ast_test_flag64(confflags, CONFFLAG_INTROUSER_VMREC)) && conf->users > 1) {
  3299. struct announce_listitem *item;
  3300. if (!(item = ao2_alloc(sizeof(*item), NULL)))
  3301. goto outrun;
  3302. ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
  3303. ast_copy_string(item->language, ast_channel_language(chan), sizeof(item->language));
  3304. item->confchan = conf->chan;
  3305. item->confusers = conf->users;
  3306. if (ast_test_flag64(confflags, CONFFLAG_INTROUSER_VMREC)){
  3307. item->vmrec = 1;
  3308. }
  3309. item->announcetype = CONF_HASJOIN;
  3310. ast_mutex_lock(&conf->announcelistlock);
  3311. ao2_ref(item, +1); /* add one more so we can determine when announce_thread is done playing it */
  3312. AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
  3313. ast_cond_signal(&conf->announcelist_addition);
  3314. ast_mutex_unlock(&conf->announcelistlock);
  3315. while (!ast_check_hangup(conf->chan) && ao2_ref(item, 0) == 2 && !ast_safe_sleep(chan, 1000)) {
  3316. ;
  3317. }
  3318. ao2_ref(item, -1);
  3319. }
  3320. if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED) && !conf->markedusers)
  3321. dahdic.confmode = DAHDI_CONF_CONF;
  3322. else if (ast_test_flag64(confflags, CONFFLAG_MONITOR))
  3323. dahdic.confmode = DAHDI_CONF_CONFMON | DAHDI_CONF_LISTENER;
  3324. else if (ast_test_flag64(confflags, CONFFLAG_TALKER))
  3325. dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
  3326. else
  3327. dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
  3328. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3329. ast_log(LOG_WARNING, "Error setting conference\n");
  3330. close(fd);
  3331. goto outrun;
  3332. }
  3333. ast_debug(1, "Placed channel %s in DAHDI conf %d\n", ast_channel_name(chan), conf->dahdiconf);
  3334. if (!sent_event) {
  3335. meetme_stasis_generate_msg(conf, chan, user, meetme_join_type(), NULL);
  3336. sent_event = 1;
  3337. }
  3338. if (!firstpass && !ast_test_flag64(confflags, CONFFLAG_MONITOR) &&
  3339. !ast_test_flag64(confflags, CONFFLAG_ADMIN)) {
  3340. firstpass = 1;
  3341. if (!ast_test_flag64(confflags, CONFFLAG_QUIET))
  3342. if (!ast_test_flag64(confflags, CONFFLAG_WAITMARKED) || (ast_test_flag64(confflags, CONFFLAG_MARKEDUSER) &&
  3343. (conf->markedusers >= 1))) {
  3344. conf_play(chan, conf, ENTER);
  3345. }
  3346. }
  3347. conf_flush(fd, chan);
  3348. if (dsp)
  3349. ast_dsp_free(dsp);
  3350. if (!(dsp = ast_dsp_new())) {
  3351. ast_log(LOG_WARNING, "Unable to allocate DSP!\n");
  3352. res = -1;
  3353. }
  3354. if (ast_test_flag64(confflags, CONFFLAG_AGI)) {
  3355. /* Get name of AGI file to run from $(MEETME_AGI_BACKGROUND)
  3356. or use default filename of conf-background.agi */
  3357. ast_channel_lock(chan);
  3358. if ((tmpvar = pbx_builtin_getvar_helper(chan, "MEETME_AGI_BACKGROUND"))) {
  3359. agifile = ast_strdupa(tmpvar);
  3360. } else {
  3361. agifile = ast_strdupa(agifiledefault);
  3362. }
  3363. ast_channel_unlock(chan);
  3364. if (user->dahdichannel) {
  3365. /* Set CONFMUTE mode on DAHDI channel to mute DTMF tones */
  3366. x = 1;
  3367. ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
  3368. }
  3369. /* Find a pointer to the agi app and execute the script */
  3370. agi_app = pbx_findapp("agi");
  3371. if (agi_app) {
  3372. ret = pbx_exec(chan, agi_app, agifile);
  3373. } else {
  3374. ast_log(LOG_WARNING, "Could not find application (agi)\n");
  3375. ret = -2;
  3376. }
  3377. if (user->dahdichannel) {
  3378. /* Remove CONFMUTE mode on DAHDI channel */
  3379. x = 0;
  3380. ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
  3381. }
  3382. } else {
  3383. int lastusers = conf->users;
  3384. if (user->dahdichannel && ast_test_flag64(confflags, CONFFLAG_STARMENU)) {
  3385. /* Set CONFMUTE mode on DAHDI channel to mute DTMF tones when the menu is enabled */
  3386. x = 1;
  3387. ast_channel_setoption(chan, AST_OPTION_TONE_VERIFY, &x, sizeof(char), 0);
  3388. }
  3389. for (;;) {
  3390. int menu_was_active = 0;
  3391. outfd = -1;
  3392. ms = -1;
  3393. now = ast_tvnow();
  3394. if (rt_schedule && conf->endtime) {
  3395. char currenttime[32];
  3396. long localendtime = 0;
  3397. int extended = 0;
  3398. struct ast_tm tm;
  3399. struct ast_variable *var, *origvar;
  3400. struct timeval tmp;
  3401. if (now.tv_sec % 60 == 0) {
  3402. if (!checked) {
  3403. ast_localtime(&now, &tm, NULL);
  3404. ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
  3405. var = origvar = ast_load_realtime("meetme", "confno",
  3406. conf->confno, "starttime <=", currenttime,
  3407. "endtime >=", currenttime, NULL);
  3408. for ( ; var; var = var->next) {
  3409. if (!strcasecmp(var->name, "endtime")) {
  3410. struct ast_tm endtime_tm;
  3411. ast_strptime(var->value, "%Y-%m-%d %H:%M:%S", &endtime_tm);
  3412. tmp = ast_mktime(&endtime_tm, NULL);
  3413. localendtime = tmp.tv_sec;
  3414. }
  3415. }
  3416. ast_variables_destroy(origvar);
  3417. /* A conference can be extended from the
  3418. Admin/User menu or by an external source */
  3419. if (localendtime > conf->endtime){
  3420. conf->endtime = localendtime;
  3421. extended = 1;
  3422. }
  3423. if (conf->endtime && (now.tv_sec >= conf->endtime)) {
  3424. ast_verbose("Quitting time...\n");
  3425. goto outrun;
  3426. }
  3427. if (!announcement_played && conf->endalert) {
  3428. if (now.tv_sec + conf->endalert >= conf->endtime) {
  3429. if (!ast_streamfile(chan, "conf-will-end-in", ast_channel_language(chan)))
  3430. ast_waitstream(chan, "");
  3431. ast_say_digits(chan, (conf->endtime - now.tv_sec) / 60, "", ast_channel_language(chan));
  3432. if (!ast_streamfile(chan, "minutes", ast_channel_language(chan)))
  3433. ast_waitstream(chan, "");
  3434. if (musiconhold) {
  3435. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3436. }
  3437. announcement_played = 1;
  3438. }
  3439. }
  3440. if (extended) {
  3441. announcement_played = 0;
  3442. }
  3443. checked = 1;
  3444. }
  3445. } else {
  3446. checked = 0;
  3447. }
  3448. }
  3449. if (user->kicktime && (user->kicktime <= now.tv_sec)) {
  3450. if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
  3451. ret = 0;
  3452. } else {
  3453. ret = -1;
  3454. }
  3455. break;
  3456. }
  3457. to = -1;
  3458. if (user->timelimit) {
  3459. int minutes = 0, seconds = 0, remain = 0;
  3460. to = ast_tvdiff_ms(nexteventts, now);
  3461. if (to < 0) {
  3462. to = 0;
  3463. }
  3464. time_left_ms = user->timelimit - ast_tvdiff_ms(now, user->start_time);
  3465. if (time_left_ms < to) {
  3466. to = time_left_ms;
  3467. }
  3468. if (time_left_ms <= 0) {
  3469. if (user->end_sound) {
  3470. res = ast_streamfile(chan, user->end_sound, ast_channel_language(chan));
  3471. res = ast_waitstream(chan, "");
  3472. }
  3473. if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
  3474. ret = 0;
  3475. } else {
  3476. ret = -1;
  3477. }
  3478. break;
  3479. }
  3480. if (!to) {
  3481. if (time_left_ms >= 5000) {
  3482. remain = (time_left_ms + 500) / 1000;
  3483. if (remain / 60 >= 1) {
  3484. minutes = remain / 60;
  3485. seconds = remain % 60;
  3486. } else {
  3487. seconds = remain;
  3488. }
  3489. /* force the time left to round up if appropriate */
  3490. if (user->warning_sound && user->play_warning) {
  3491. if (!strcmp(user->warning_sound, "timeleft")) {
  3492. res = ast_streamfile(chan, "vm-youhave", ast_channel_language(chan));
  3493. res = ast_waitstream(chan, "");
  3494. if (minutes) {
  3495. res = ast_say_number(chan, minutes, AST_DIGIT_ANY, ast_channel_language(chan), (char *) NULL);
  3496. res = ast_streamfile(chan, "queue-minutes", ast_channel_language(chan));
  3497. res = ast_waitstream(chan, "");
  3498. }
  3499. if (seconds) {
  3500. res = ast_say_number(chan, seconds, AST_DIGIT_ANY, ast_channel_language(chan), (char *) NULL);
  3501. res = ast_streamfile(chan, "queue-seconds", ast_channel_language(chan));
  3502. res = ast_waitstream(chan, "");
  3503. }
  3504. } else {
  3505. res = ast_streamfile(chan, user->warning_sound, ast_channel_language(chan));
  3506. res = ast_waitstream(chan, "");
  3507. }
  3508. if (musiconhold) {
  3509. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3510. }
  3511. }
  3512. }
  3513. if (user->warning_freq) {
  3514. nexteventts = ast_tvadd(nexteventts, ast_samp2tv(user->warning_freq, 1000));
  3515. } else {
  3516. nexteventts = ast_tvadd(user->start_time, ast_samp2tv(user->timelimit, 1000));
  3517. }
  3518. }
  3519. }
  3520. now = ast_tvnow();
  3521. if (timeout && now.tv_sec >= timeout) {
  3522. if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
  3523. ret = 0;
  3524. } else {
  3525. ret = -1;
  3526. }
  3527. break;
  3528. }
  3529. /* if we have just exited from the menu, and the user had a channel-driver
  3530. volume adjustment, restore it
  3531. */
  3532. if (!menu_mode && menu_was_active && user->listen.desired && !user->listen.actual) {
  3533. set_talk_volume(user, user->listen.desired);
  3534. }
  3535. menu_was_active = menu_mode;
  3536. currentmarked = conf->markedusers;
  3537. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) &&
  3538. ast_test_flag64(confflags, CONFFLAG_MARKEDUSER) &&
  3539. ast_test_flag64(confflags, CONFFLAG_WAITMARKED) &&
  3540. lastmarked == 0) {
  3541. if (currentmarked == 1 && conf->users > 1) {
  3542. ast_say_number(chan, conf->users - 1, AST_DIGIT_ANY, ast_channel_language(chan), (char *) NULL);
  3543. if (conf->users - 1 == 1) {
  3544. if (!ast_streamfile(chan, "conf-userwilljoin", ast_channel_language(chan))) {
  3545. ast_waitstream(chan, "");
  3546. }
  3547. } else {
  3548. if (!ast_streamfile(chan, "conf-userswilljoin", ast_channel_language(chan))) {
  3549. ast_waitstream(chan, "");
  3550. }
  3551. }
  3552. }
  3553. if (conf->users == 1 && !ast_test_flag64(confflags, CONFFLAG_MARKEDUSER)) {
  3554. if (!ast_streamfile(chan, "conf-onlyperson", ast_channel_language(chan))) {
  3555. ast_waitstream(chan, "");
  3556. }
  3557. }
  3558. }
  3559. /* Update the struct with the actual confflags */
  3560. user->userflags = *confflags;
  3561. if (ast_test_flag64(confflags, CONFFLAG_WAITMARKED)) {
  3562. if (currentmarked == 0) {
  3563. if (lastmarked != 0) {
  3564. if (!ast_test_flag64(confflags, CONFFLAG_QUIET)) {
  3565. if (!ast_streamfile(chan, "conf-leaderhasleft", ast_channel_language(chan))) {
  3566. ast_waitstream(chan, "");
  3567. }
  3568. }
  3569. if (ast_test_flag64(confflags, CONFFLAG_MARKEDEXIT)) {
  3570. if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
  3571. ret = 0;
  3572. }
  3573. break;
  3574. } else {
  3575. dahdic.confmode = DAHDI_CONF_CONF;
  3576. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3577. ast_log(LOG_WARNING, "Error setting conference\n");
  3578. close(fd);
  3579. goto outrun;
  3580. }
  3581. }
  3582. }
  3583. if (!musiconhold && (ast_test_flag64(confflags, CONFFLAG_MOH))) {
  3584. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3585. musiconhold = 1;
  3586. }
  3587. } else if (currentmarked >= 1 && lastmarked == 0) {
  3588. /* Marked user entered, so cancel timeout */
  3589. timeout = 0;
  3590. if (ast_test_flag64(confflags, CONFFLAG_MONITOR)) {
  3591. dahdic.confmode = DAHDI_CONF_CONFMON | DAHDI_CONF_LISTENER;
  3592. } else if (ast_test_flag64(confflags, CONFFLAG_TALKER)) {
  3593. dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
  3594. } else {
  3595. dahdic.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
  3596. }
  3597. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3598. ast_log(LOG_WARNING, "Error setting conference\n");
  3599. close(fd);
  3600. goto outrun;
  3601. }
  3602. if (musiconhold && (ast_test_flag64(confflags, CONFFLAG_MOH))) {
  3603. ast_moh_stop(chan);
  3604. musiconhold = 0;
  3605. }
  3606. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) &&
  3607. !ast_test_flag64(confflags, CONFFLAG_MARKEDUSER)) {
  3608. if (!ast_streamfile(chan, "conf-placeintoconf", ast_channel_language(chan))) {
  3609. ast_waitstream(chan, "");
  3610. }
  3611. conf_play(chan, conf, ENTER);
  3612. }
  3613. }
  3614. }
  3615. /* trying to add moh for single person conf */
  3616. if (ast_test_flag64(confflags, CONFFLAG_MOH) && !ast_test_flag64(confflags, CONFFLAG_WAITMARKED)) {
  3617. if (conf->users == 1) {
  3618. if (!musiconhold) {
  3619. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3620. musiconhold = 1;
  3621. }
  3622. } else {
  3623. if (musiconhold) {
  3624. ast_moh_stop(chan);
  3625. musiconhold = 0;
  3626. }
  3627. }
  3628. }
  3629. /* Leave if the last marked user left */
  3630. if (currentmarked == 0 && lastmarked != 0 && ast_test_flag64(confflags, CONFFLAG_MARKEDEXIT)) {
  3631. if (ast_test_flag64(confflags, CONFFLAG_KICK_CONTINUE)) {
  3632. ret = 0;
  3633. } else {
  3634. ret = -1;
  3635. }
  3636. break;
  3637. }
  3638. /* Throw a TestEvent if a user exit did not cause this user to leave the conference */
  3639. if (conf->users != lastusers) {
  3640. if (conf->users < lastusers) {
  3641. ast_test_suite_event_notify("NOEXIT", "Message: CONFFLAG_MARKEDEXIT\r\nLastUsers: %d\r\nUsers: %d", lastusers, conf->users);
  3642. }
  3643. lastusers = conf->users;
  3644. }
  3645. /* Check if my modes have changed */
  3646. /* If I should be muted but am still talker, mute me */
  3647. if ((user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) && (dahdic.confmode & DAHDI_CONF_TALKER)) {
  3648. RAII_VAR(struct ast_json *, status_blob, status_to_json(1), ast_json_unref);
  3649. dahdic.confmode ^= DAHDI_CONF_TALKER;
  3650. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3651. ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
  3652. ret = -1;
  3653. break;
  3654. }
  3655. /* Indicate user is not talking anymore - change him to unmonitored state */
  3656. if (ast_test_flag64(confflags, (CONFFLAG_MONITORTALKER | CONFFLAG_OPTIMIZETALKER))) {
  3657. set_user_talking(chan, conf, user, -1, ast_test_flag64(confflags, CONFFLAG_MONITORTALKER));
  3658. }
  3659. meetme_stasis_generate_msg(conf, chan, user, meetme_mute_type(), status_blob);
  3660. }
  3661. /* If I should be un-muted but am not talker, un-mute me */
  3662. if (!(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) && !ast_test_flag64(confflags, CONFFLAG_MONITOR) && !(dahdic.confmode & DAHDI_CONF_TALKER)) {
  3663. RAII_VAR(struct ast_json *, status_blob, status_to_json(0), ast_json_unref);
  3664. dahdic.confmode |= DAHDI_CONF_TALKER;
  3665. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3666. ast_log(LOG_WARNING, "Error setting conference - Un/Mute \n");
  3667. ret = -1;
  3668. break;
  3669. }
  3670. meetme_stasis_generate_msg(conf, chan, user, meetme_mute_type(), status_blob);
  3671. }
  3672. if ((user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) &&
  3673. (user->adminflags & ADMINFLAG_T_REQUEST) && !(talkreq_manager)) {
  3674. RAII_VAR(struct ast_json *, status_blob, status_to_json(1), ast_json_unref);
  3675. talkreq_manager = 1;
  3676. meetme_stasis_generate_msg(conf, chan, user, meetme_talk_request_type(), status_blob);
  3677. }
  3678. if (!(user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) &&
  3679. !(user->adminflags & ADMINFLAG_T_REQUEST) && (talkreq_manager)) {
  3680. RAII_VAR(struct ast_json *, status_blob, status_to_json(0), ast_json_unref);
  3681. talkreq_manager = 0;
  3682. meetme_stasis_generate_msg(conf, chan, user, meetme_talk_request_type(), status_blob);
  3683. }
  3684. /* If user have been hung up, exit the conference */
  3685. if (user->adminflags & ADMINFLAG_HANGUP) {
  3686. ret = 0;
  3687. break;
  3688. }
  3689. /* If I have been kicked, exit the conference */
  3690. if (user->adminflags & ADMINFLAG_KICKME) {
  3691. /* You have been kicked. */
  3692. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) &&
  3693. !ast_streamfile(chan, "conf-kicked", ast_channel_language(chan))) {
  3694. ast_waitstream(chan, "");
  3695. }
  3696. ret = 0;
  3697. break;
  3698. }
  3699. /* Perform a hangup check here since ast_waitfor_nandfds will not always be able to get a channel after a hangup has occurred */
  3700. if (ast_check_hangup(chan)) {
  3701. break;
  3702. }
  3703. c = ast_waitfor_nandfds(&chan, 1, &fd, nfds, NULL, &outfd, &ms);
  3704. if (c) {
  3705. char dtmfstr[2] = "";
  3706. if (ast_channel_fd(c, 0) != origfd || (user->dahdichannel && (ast_channel_audiohooks(c) || ast_channel_monitor(c)))) {
  3707. if (using_pseudo) {
  3708. /* Kill old pseudo */
  3709. close(fd);
  3710. using_pseudo = 0;
  3711. }
  3712. ast_debug(1, "Ooh, something swapped out under us, starting over\n");
  3713. retrydahdi = (strcasecmp(ast_channel_tech(c)->type, "DAHDI") || (ast_channel_audiohooks(c) || ast_channel_monitor(c)) ? 1 : 0);
  3714. user->dahdichannel = !retrydahdi;
  3715. goto dahdiretry;
  3716. }
  3717. if (ast_test_flag64(confflags, CONFFLAG_MONITOR) || (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED))) {
  3718. f = ast_read_noaudio(c);
  3719. } else {
  3720. f = ast_read(c);
  3721. }
  3722. if (!f) {
  3723. break;
  3724. }
  3725. if (f->frametype == AST_FRAME_DTMF) {
  3726. dtmfstr[0] = f->subclass.integer;
  3727. dtmfstr[1] = '\0';
  3728. }
  3729. if ((f->frametype == AST_FRAME_VOICE) && (ast_format_cmp(f->subclass.format, ast_format_slin) == AST_FORMAT_CMP_EQUAL)) {
  3730. if (user->talk.actual) {
  3731. ast_frame_adjust_volume(f, user->talk.actual);
  3732. }
  3733. if (ast_test_flag64(confflags, (CONFFLAG_OPTIMIZETALKER | CONFFLAG_MONITORTALKER))) {
  3734. if (user->talking == -1) {
  3735. user->talking = 0;
  3736. }
  3737. res = ast_dsp_silence(dsp, f, &totalsilence);
  3738. if (!user->talking && totalsilence < MEETME_DELAYDETECTTALK) {
  3739. set_user_talking(chan, conf, user, 1, ast_test_flag64(confflags, CONFFLAG_MONITORTALKER));
  3740. }
  3741. if (user->talking && totalsilence > MEETME_DELAYDETECTENDTALK) {
  3742. set_user_talking(chan, conf, user, 0, ast_test_flag64(confflags, CONFFLAG_MONITORTALKER));
  3743. }
  3744. }
  3745. if (using_pseudo) {
  3746. /* Absolutely do _not_ use careful_write here...
  3747. it is important that we read data from the channel
  3748. as fast as it arrives, and feed it into the conference.
  3749. The buffering in the pseudo channel will take care of any
  3750. timing differences, unless they are so drastic as to lose
  3751. audio frames (in which case carefully writing would only
  3752. have delayed the audio even further).
  3753. */
  3754. /* As it turns out, we do want to use careful write. We just
  3755. don't want to block, but we do want to at least *try*
  3756. to write out all the samples.
  3757. */
  3758. if (user->talking || !ast_test_flag64(confflags, CONFFLAG_OPTIMIZETALKER)) {
  3759. careful_write(fd, f->data.ptr, f->datalen, 0);
  3760. }
  3761. }
  3762. } else if (((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '*') && ast_test_flag64(confflags, CONFFLAG_STARMENU)) || ((f->frametype == AST_FRAME_DTMF) && menu_mode)) {
  3763. if (ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
  3764. conf_queue_dtmf(conf, user, f);
  3765. }
  3766. /* Take out of conference */
  3767. if (ioctl(fd, DAHDI_SETCONF, &dahdic_empty)) {
  3768. ast_log(LOG_WARNING, "Error setting conference\n");
  3769. close(fd);
  3770. ast_frfree(f);
  3771. goto outrun;
  3772. }
  3773. /* if we are entering the menu, and the user has a channel-driver
  3774. volume adjustment, clear it
  3775. */
  3776. if (!menu_mode && user->talk.desired && !user->talk.actual) {
  3777. set_talk_volume(user, 0);
  3778. }
  3779. if (musiconhold) {
  3780. ast_moh_stop(chan);
  3781. } else if (!menu_mode) {
  3782. char *menu_to_play;
  3783. if (ast_test_flag64(confflags, CONFFLAG_ADMIN)) {
  3784. menu_mode = MENU_ADMIN;
  3785. menu_to_play = "conf-adminmenu-18";
  3786. } else {
  3787. menu_mode = MENU_NORMAL;
  3788. menu_to_play = "conf-usermenu-162";
  3789. }
  3790. if (!ast_streamfile(chan, menu_to_play, ast_channel_language(chan))) {
  3791. dtmf = ast_waitstream(chan, AST_DIGIT_ANY);
  3792. ast_stopstream(chan);
  3793. } else {
  3794. dtmf = 0;
  3795. }
  3796. } else {
  3797. dtmf = f->subclass.integer;
  3798. }
  3799. if (dtmf > 0) {
  3800. meetme_menu(&menu_mode, &dtmf, conf, confflags,
  3801. chan, user, recordingtmp, sizeof(recordingtmp), cap_slin);
  3802. }
  3803. if (musiconhold && !menu_mode) {
  3804. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3805. }
  3806. /* Put back into conference */
  3807. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3808. ast_log(LOG_WARNING, "Error setting conference\n");
  3809. close(fd);
  3810. ast_frfree(f);
  3811. goto outrun;
  3812. }
  3813. conf_flush(fd, chan);
  3814. /*
  3815. * Since options using DTMF could absorb DTMF meant for the
  3816. * conference menu, we have to check them after the menu.
  3817. */
  3818. } else if ((f->frametype == AST_FRAME_DTMF) && ast_test_flag64(confflags, CONFFLAG_EXIT_CONTEXT) && ast_exists_extension(chan, exitcontext, dtmfstr, 1, "")) {
  3819. if (ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
  3820. conf_queue_dtmf(conf, user, f);
  3821. }
  3822. if (!ast_goto_if_exists(chan, exitcontext, dtmfstr, 1)) {
  3823. ast_debug(1, "Got DTMF %c, goto context %s\n", dtmfstr[0], exitcontext);
  3824. ret = 0;
  3825. ast_frfree(f);
  3826. break;
  3827. } else {
  3828. ast_debug(2, "Exit by single digit did not work in meetme. Extension %s does not exist in context %s\n", dtmfstr, exitcontext);
  3829. }
  3830. } else if ((f->frametype == AST_FRAME_DTMF) && ast_test_flag64(confflags, CONFFLAG_KEYEXIT) &&
  3831. (strchr(exitkeys, f->subclass.integer))) {
  3832. pbx_builtin_setvar_helper(chan, "MEETME_EXIT_KEY", dtmfstr);
  3833. if (ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
  3834. conf_queue_dtmf(conf, user, f);
  3835. }
  3836. ret = 0;
  3837. ast_frfree(f);
  3838. break;
  3839. } else if ((f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END)
  3840. && ast_test_flag64(confflags, CONFFLAG_PASS_DTMF)) {
  3841. conf_queue_dtmf(conf, user, f);
  3842. } else if (ast_test_flag64(confflags, CONFFLAG_SLA_STATION) && f->frametype == AST_FRAME_CONTROL) {
  3843. switch (f->subclass.integer) {
  3844. case AST_CONTROL_HOLD:
  3845. sla_queue_event_conf(SLA_EVENT_HOLD, chan, conf);
  3846. break;
  3847. default:
  3848. break;
  3849. }
  3850. } else if (f->frametype == AST_FRAME_NULL) {
  3851. /* Ignore NULL frames. It is perfectly normal to get these if the person is muted. */
  3852. } else if (f->frametype == AST_FRAME_CONTROL) {
  3853. switch (f->subclass.integer) {
  3854. case AST_CONTROL_BUSY:
  3855. case AST_CONTROL_CONGESTION:
  3856. ast_frfree(f);
  3857. goto outrun;
  3858. break;
  3859. default:
  3860. ast_debug(1,
  3861. "Got ignored control frame on channel %s, f->frametype=%u,f->subclass=%d\n",
  3862. ast_channel_name(chan), f->frametype, f->subclass.integer);
  3863. }
  3864. } else {
  3865. ast_debug(1,
  3866. "Got unrecognized frame on channel %s, f->frametype=%u,f->subclass=%d\n",
  3867. ast_channel_name(chan), f->frametype, f->subclass.integer);
  3868. }
  3869. ast_frfree(f);
  3870. } else if (outfd > -1) {
  3871. res = read(outfd, buf, CONF_SIZE);
  3872. if (res > 0) {
  3873. memset(&fr, 0, sizeof(fr));
  3874. fr.frametype = AST_FRAME_VOICE;
  3875. fr.subclass.format = ast_format_slin;
  3876. fr.datalen = res;
  3877. fr.samples = res / 2;
  3878. fr.data.ptr = buf;
  3879. fr.offset = AST_FRIENDLY_OFFSET;
  3880. if (!user->listen.actual &&
  3881. (ast_test_flag64(confflags, CONFFLAG_MONITOR) ||
  3882. (user->adminflags & (ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED)) ||
  3883. (!user->talking && ast_test_flag64(confflags, CONFFLAG_OPTIMIZETALKER))
  3884. )) {
  3885. int idx;
  3886. for (idx = 0; idx < AST_FRAME_BITS; idx++) {
  3887. if (ast_format_compatibility_format2bitfield(ast_channel_rawwriteformat(chan)) & (1 << idx)) {
  3888. break;
  3889. }
  3890. }
  3891. if (idx >= AST_FRAME_BITS) {
  3892. goto bailoutandtrynormal;
  3893. }
  3894. ast_mutex_lock(&conf->listenlock);
  3895. if (!conf->transframe[idx]) {
  3896. if (conf->origframe) {
  3897. if (musiconhold
  3898. && !ast_test_flag64(confflags, CONFFLAG_WAITMARKED)
  3899. && !ast_dsp_silence(dsp, conf->origframe, &confsilence)
  3900. && confsilence < MEETME_DELAYDETECTTALK) {
  3901. ast_moh_stop(chan);
  3902. mohtempstopped = 1;
  3903. }
  3904. if (!conf->transpath[idx]) {
  3905. conf->transpath[idx] = ast_translator_build_path(ast_channel_rawwriteformat(chan), ast_format_slin);
  3906. }
  3907. if (conf->transpath[idx]) {
  3908. conf->transframe[idx] = ast_translate(conf->transpath[idx], conf->origframe, 0);
  3909. if (!conf->transframe[idx]) {
  3910. conf->transframe[idx] = &ast_null_frame;
  3911. }
  3912. }
  3913. }
  3914. }
  3915. if (conf->transframe[idx]) {
  3916. if ((conf->transframe[idx]->frametype != AST_FRAME_NULL) &&
  3917. can_write(chan, confflags)) {
  3918. struct ast_frame *cur;
  3919. /* the translator may have returned a list of frames, so
  3920. write each one onto the channel
  3921. */
  3922. for (cur = conf->transframe[idx]; cur; cur = AST_LIST_NEXT(cur, frame_list)) {
  3923. if (ast_write(chan, cur)) {
  3924. ast_log(LOG_WARNING, "Unable to write frame to channel %s\n", ast_channel_name(chan));
  3925. break;
  3926. }
  3927. }
  3928. if (musiconhold && mohtempstopped && confsilence > MEETME_DELAYDETECTENDTALK) {
  3929. mohtempstopped = 0;
  3930. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3931. }
  3932. }
  3933. } else {
  3934. ast_mutex_unlock(&conf->listenlock);
  3935. goto bailoutandtrynormal;
  3936. }
  3937. ast_mutex_unlock(&conf->listenlock);
  3938. } else {
  3939. bailoutandtrynormal:
  3940. if (musiconhold
  3941. && !ast_test_flag64(confflags, CONFFLAG_WAITMARKED)
  3942. && !ast_dsp_silence(dsp, &fr, &confsilence)
  3943. && confsilence < MEETME_DELAYDETECTTALK) {
  3944. ast_moh_stop(chan);
  3945. mohtempstopped = 1;
  3946. }
  3947. if (user->listen.actual) {
  3948. ast_frame_adjust_volume(&fr, user->listen.actual);
  3949. }
  3950. if (can_write(chan, confflags) && ast_write(chan, &fr) < 0) {
  3951. ast_log(LOG_WARNING, "Unable to write frame to channel %s\n", ast_channel_name(chan));
  3952. }
  3953. if (musiconhold && mohtempstopped && confsilence > MEETME_DELAYDETECTENDTALK) {
  3954. mohtempstopped = 0;
  3955. conf_start_moh(chan, optargs[OPT_ARG_MOH_CLASS]);
  3956. }
  3957. }
  3958. } else {
  3959. ast_log(LOG_WARNING, "Failed to read frame: %s\n", strerror(errno));
  3960. }
  3961. }
  3962. lastmarked = currentmarked;
  3963. }
  3964. }
  3965. if (musiconhold) {
  3966. ast_moh_stop(chan);
  3967. }
  3968. if (using_pseudo) {
  3969. close(fd);
  3970. } else {
  3971. /* Take out of conference */
  3972. dahdic.chan = 0;
  3973. dahdic.confno = 0;
  3974. dahdic.confmode = 0;
  3975. if (ioctl(fd, DAHDI_SETCONF, &dahdic)) {
  3976. ast_log(LOG_WARNING, "Error setting conference\n");
  3977. }
  3978. }
  3979. reset_volumes(user);
  3980. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && !ast_test_flag64(confflags, CONFFLAG_MONITOR) &&
  3981. !ast_test_flag64(confflags, CONFFLAG_ADMIN)) {
  3982. conf_play(chan, conf, LEAVE);
  3983. }
  3984. if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && ast_test_flag64(confflags, CONFFLAG_INTROUSER |CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC) && conf->users > 1) {
  3985. struct announce_listitem *item;
  3986. if (!(item = ao2_alloc(sizeof(*item), NULL)))
  3987. goto outrun;
  3988. ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
  3989. ast_copy_string(item->language, ast_channel_language(chan), sizeof(item->language));
  3990. item->confchan = conf->chan;
  3991. item->confusers = conf->users;
  3992. item->announcetype = CONF_HASLEFT;
  3993. if (ast_test_flag64(confflags, CONFFLAG_INTROUSER_VMREC)){
  3994. item->vmrec = 1;
  3995. }
  3996. ast_mutex_lock(&conf->announcelistlock);
  3997. AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
  3998. ast_cond_signal(&conf->announcelist_addition);
  3999. ast_mutex_unlock(&conf->announcelistlock);
  4000. } else if (!ast_test_flag64(confflags, CONFFLAG_QUIET) && ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW) && !ast_test_flag64(confflags, CONFFLAG_INTROUSER_VMREC) && conf->users == 1) {
  4001. /* Last person is leaving, so no reason to try and announce, but should delete the name recording */
  4002. ast_filedelete(user->namerecloc, NULL);
  4003. }
  4004. outrun:
  4005. AST_LIST_LOCK(&confs);
  4006. if (dsp) {
  4007. ast_dsp_free(dsp);
  4008. }
  4009. if (user->user_no) {
  4010. /* Only cleanup users who really joined! */
  4011. now = ast_tvnow();
  4012. if (sent_event) {
  4013. meetme_stasis_generate_msg(conf, chan, user, meetme_leave_type(), NULL);
  4014. }
  4015. if (setusercount) {
  4016. conf->users--;
  4017. if (rt_log_members) {
  4018. /* Update table */
  4019. snprintf(members, sizeof(members), "%d", conf->users);
  4020. ast_realtime_require_field("meetme",
  4021. "confno", strlen(conf->confno) > 7 ? RQ_UINTEGER4 : strlen(conf->confno) > 4 ? RQ_UINTEGER3 : RQ_UINTEGER2, strlen(conf->confno),
  4022. "members", RQ_UINTEGER1, strlen(members),
  4023. NULL);
  4024. ast_update_realtime("meetme", "confno", conf->confno, "members", members, NULL);
  4025. }
  4026. if (ast_test_flag64(confflags, CONFFLAG_MARKEDUSER)) {
  4027. conf->markedusers--;
  4028. }
  4029. }
  4030. /* Remove ourselves from the container */
  4031. ao2_unlink(conf->usercontainer, user);
  4032. /* Change any states */
  4033. if (!conf->users) {
  4034. ast_devstate_changed(AST_DEVICE_NOT_INUSE, (conf->isdynamic ? AST_DEVSTATE_NOT_CACHABLE : AST_DEVSTATE_CACHABLE), "meetme:%s", conf->confno);
  4035. }
  4036. /* This flag is meant to kill a conference with only one participant remaining. */
  4037. if (conf->users == 1 && ast_test_flag64(confflags, CONFFLAG_KILL_LAST_MAN_STANDING)) {
  4038. ao2_callback(conf->usercontainer, 0, user_set_hangup_cb, NULL);
  4039. }
  4040. /* Return the number of seconds the user was in the conf */
  4041. snprintf(meetmesecs, sizeof(meetmesecs), "%d", (int) (time(NULL) - user->jointime));
  4042. pbx_builtin_setvar_helper(chan, "MEETMESECS", meetmesecs);
  4043. /* Return the RealTime bookid for CDR linking */
  4044. if (rt_schedule) {
  4045. pbx_builtin_setvar_helper(chan, "MEETMEBOOKID", conf->bookid);
  4046. }
  4047. }
  4048. ao2_ref(user, -1);
  4049. AST_LIST_UNLOCK(&confs);
  4050. conf_run_cleanup:
  4051. ao2_cleanup(cap_slin);
  4052. return ret;
  4053. }
  4054. static struct ast_conference *find_conf_realtime(struct ast_channel *chan, char *confno, int make, int dynamic,
  4055. char *dynamic_pin, size_t pin_buf_len, int refcount, struct ast_flags64 *confflags, int *too_early, char **optargs)
  4056. {
  4057. struct ast_variable *var, *origvar;
  4058. struct ast_conference *cnf;
  4059. *too_early = 0;
  4060. /* Check first in the conference list */
  4061. AST_LIST_LOCK(&confs);
  4062. AST_LIST_TRAVERSE(&confs, cnf, list) {
  4063. if (!strcmp(confno, cnf->confno)) {
  4064. break;
  4065. }
  4066. }
  4067. if (cnf) {
  4068. cnf->refcount += refcount;
  4069. }
  4070. AST_LIST_UNLOCK(&confs);
  4071. if (!cnf) {
  4072. char *pin = NULL, *pinadmin = NULL; /* For temp use */
  4073. int maxusers = 0;
  4074. struct timeval now;
  4075. char recordingfilename[256] = "";
  4076. char recordingformat[11] = "";
  4077. char currenttime[32] = "";
  4078. char eatime[32] = "";
  4079. char bookid[51] = "";
  4080. char recordingtmp[AST_MAX_EXTENSION * 2] = "";
  4081. char useropts[OPTIONS_LEN + 1] = ""; /* Used for RealTime conferences */
  4082. char adminopts[OPTIONS_LEN + 1] = "";
  4083. struct ast_tm tm, etm;
  4084. struct timeval endtime = { .tv_sec = 0 };
  4085. const char *var2;
  4086. if (rt_schedule) {
  4087. now = ast_tvnow();
  4088. ast_localtime(&now, &tm, NULL);
  4089. ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
  4090. ast_debug(1, "Looking for conference %s that starts after %s\n", confno, currenttime);
  4091. var = ast_load_realtime("meetme", "confno",
  4092. confno, "starttime <= ", currenttime, "endtime >= ",
  4093. currenttime, NULL);
  4094. if (!var && fuzzystart) {
  4095. now = ast_tvnow();
  4096. now.tv_sec += fuzzystart;
  4097. ast_localtime(&now, &tm, NULL);
  4098. ast_strftime(currenttime, sizeof(currenttime), DATE_FORMAT, &tm);
  4099. var = ast_load_realtime("meetme", "confno",
  4100. confno, "starttime <= ", currenttime, "endtime >= ",
  4101. currenttime, NULL);
  4102. }
  4103. if (!var && earlyalert) {
  4104. now = ast_tvnow();
  4105. now.tv_sec += earlyalert;
  4106. ast_localtime(&now, &etm, NULL);
  4107. ast_strftime(eatime, sizeof(eatime), DATE_FORMAT, &etm);
  4108. var = ast_load_realtime("meetme", "confno",
  4109. confno, "starttime <= ", eatime, "endtime >= ",
  4110. currenttime, NULL);
  4111. if (var) {
  4112. *too_early = 1;
  4113. }
  4114. }
  4115. } else {
  4116. var = ast_load_realtime("meetme", "confno", confno, NULL);
  4117. }
  4118. if (!var) {
  4119. return NULL;
  4120. }
  4121. if (rt_schedule && *too_early) {
  4122. /* Announce that the caller is early and exit */
  4123. if (!ast_streamfile(chan, "conf-has-not-started", ast_channel_language(chan))) {
  4124. ast_waitstream(chan, "");
  4125. }
  4126. ast_variables_destroy(var);
  4127. return NULL;
  4128. }
  4129. for (origvar = var; var; var = var->next) {
  4130. if (!strcasecmp(var->name, "pin")) {
  4131. pin = ast_strdupa(var->value);
  4132. } else if (!strcasecmp(var->name, "adminpin")) {
  4133. pinadmin = ast_strdupa(var->value);
  4134. } else if (!strcasecmp(var->name, "bookId")) {
  4135. ast_copy_string(bookid, var->value, sizeof(bookid));
  4136. } else if (!strcasecmp(var->name, "opts")) {
  4137. ast_copy_string(useropts, var->value, sizeof(char[OPTIONS_LEN + 1]));
  4138. } else if (!strcasecmp(var->name, "maxusers")) {
  4139. maxusers = atoi(var->value);
  4140. } else if (!strcasecmp(var->name, "adminopts")) {
  4141. ast_copy_string(adminopts, var->value, sizeof(char[OPTIONS_LEN + 1]));
  4142. } else if (!strcasecmp(var->name, "recordingfilename")) {
  4143. ast_copy_string(recordingfilename, var->value, sizeof(recordingfilename));
  4144. } else if (!strcasecmp(var->name, "recordingformat")) {
  4145. ast_copy_string(recordingformat, var->value, sizeof(recordingformat));
  4146. } else if (!strcasecmp(var->name, "endtime")) {
  4147. struct ast_tm endtime_tm;
  4148. ast_strptime(var->value, "%Y-%m-%d %H:%M:%S", &endtime_tm);
  4149. endtime = ast_mktime(&endtime_tm, NULL);
  4150. }
  4151. }
  4152. ast_variables_destroy(origvar);
  4153. cnf = build_conf(confno, pin ? pin : "", pinadmin ? pinadmin : "", make, dynamic, refcount, chan, NULL);
  4154. if (cnf) {
  4155. struct ast_flags64 tmp_flags;
  4156. cnf->maxusers = maxusers;
  4157. cnf->endalert = endalert;
  4158. cnf->endtime = endtime.tv_sec;
  4159. cnf->useropts = ast_strdup(useropts);
  4160. cnf->adminopts = ast_strdup(adminopts);
  4161. cnf->bookid = ast_strdup(bookid);
  4162. if (!ast_strlen_zero(recordingfilename)) {
  4163. cnf->recordingfilename = ast_strdup(recordingfilename);
  4164. }
  4165. if (!ast_strlen_zero(recordingformat)) {
  4166. cnf->recordingformat = ast_strdup(recordingformat);
  4167. }
  4168. /* Parse the other options into confflags -- need to do this in two
  4169. * steps, because the parse_options routine zeroes the buffer. */
  4170. ast_app_parse_options64(meetme_opts, &tmp_flags, optargs, useropts);
  4171. ast_copy_flags64(confflags, &tmp_flags, tmp_flags.flags);
  4172. if (strchr(cnf->useropts, 'r')) {
  4173. if (ast_strlen_zero(recordingfilename)) { /* If the recordingfilename in the database is empty, use the channel definition or use the default. */
  4174. ast_channel_lock(chan);
  4175. if ((var2 = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFILE"))) {
  4176. ast_free(cnf->recordingfilename);
  4177. cnf->recordingfilename = ast_strdup(var2);
  4178. }
  4179. ast_channel_unlock(chan);
  4180. if (ast_strlen_zero(cnf->recordingfilename)) {
  4181. snprintf(recordingtmp, sizeof(recordingtmp), "meetme-conf-rec-%s-%s", cnf->confno, ast_channel_uniqueid(chan));
  4182. ast_free(cnf->recordingfilename);
  4183. cnf->recordingfilename = ast_strdup(recordingtmp);
  4184. }
  4185. }
  4186. if (ast_strlen_zero(cnf->recordingformat)) {/* If the recording format is empty, use the wav as default */
  4187. ast_channel_lock(chan);
  4188. if ((var2 = pbx_builtin_getvar_helper(chan, "MEETME_RECORDINGFORMAT"))) {
  4189. ast_free(cnf->recordingformat);
  4190. cnf->recordingformat = ast_strdup(var2);
  4191. }
  4192. ast_channel_unlock(chan);
  4193. if (ast_strlen_zero(cnf->recordingformat)) {
  4194. ast_free(cnf->recordingformat);
  4195. cnf->recordingformat = ast_strdup("wav");
  4196. }
  4197. }
  4198. ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n", cnf->confno, cnf->recordingfilename, cnf->recordingformat);
  4199. }
  4200. }
  4201. }
  4202. if (cnf) {
  4203. if (confflags->flags && !cnf->chan &&
  4204. !ast_test_flag64(confflags, CONFFLAG_QUIET) &&
  4205. ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC)) {
  4206. ast_log(LOG_WARNING, "No DAHDI channel available for conference, user introduction disabled (is chan_dahdi loaded?)\n");
  4207. ast_clear_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC);
  4208. }
  4209. if (confflags && !cnf->chan &&
  4210. ast_test_flag64(confflags, CONFFLAG_RECORDCONF)) {
  4211. ast_log(LOG_WARNING, "No DAHDI channel available for conference, conference recording disabled (is chan_dahdi loaded?)\n");
  4212. ast_clear_flag64(confflags, CONFFLAG_RECORDCONF);
  4213. }
  4214. }
  4215. return cnf;
  4216. }
  4217. static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, int make, int dynamic,
  4218. char *dynamic_pin, size_t pin_buf_len, int refcount, struct ast_flags64 *confflags)
  4219. {
  4220. struct ast_config *cfg;
  4221. struct ast_variable *var;
  4222. struct ast_flags config_flags = { 0 };
  4223. struct ast_conference *cnf;
  4224. AST_DECLARE_APP_ARGS(args,
  4225. AST_APP_ARG(confno);
  4226. AST_APP_ARG(pin);
  4227. AST_APP_ARG(pinadmin);
  4228. );
  4229. /* Check first in the conference list */
  4230. ast_debug(1, "The requested confno is '%s'?\n", confno);
  4231. AST_LIST_LOCK(&confs);
  4232. AST_LIST_TRAVERSE(&confs, cnf, list) {
  4233. ast_debug(3, "Does conf %s match %s?\n", confno, cnf->confno);
  4234. if (!strcmp(confno, cnf->confno))
  4235. break;
  4236. }
  4237. if (cnf) {
  4238. cnf->refcount += refcount;
  4239. }
  4240. AST_LIST_UNLOCK(&confs);
  4241. if (!cnf) {
  4242. if (dynamic) {
  4243. /* No need to parse meetme.conf */
  4244. ast_debug(1, "Building dynamic conference '%s'\n", confno);
  4245. if (dynamic_pin) {
  4246. if (dynamic_pin[0] == 'q') {
  4247. /* Query the user to enter a PIN */
  4248. if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, pin_buf_len - 1, 0) < 0)
  4249. return NULL;
  4250. }
  4251. cnf = build_conf(confno, dynamic_pin, "", make, dynamic, refcount, chan, NULL);
  4252. } else {
  4253. cnf = build_conf(confno, "", "", make, dynamic, refcount, chan, NULL);
  4254. }
  4255. } else {
  4256. /* Check the config */
  4257. cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
  4258. if (!cfg) {
  4259. ast_log(LOG_WARNING, "No %s file :(\n", CONFIG_FILE_NAME);
  4260. return NULL;
  4261. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  4262. ast_log(LOG_ERROR, "Config file " CONFIG_FILE_NAME " is in an invalid format. Aborting.\n");
  4263. return NULL;
  4264. }
  4265. for (var = ast_variable_browse(cfg, "rooms"); var; var = var->next) {
  4266. char parse[MAX_SETTINGS];
  4267. if (strcasecmp(var->name, "conf"))
  4268. continue;
  4269. ast_copy_string(parse, var->value, sizeof(parse));
  4270. AST_STANDARD_APP_ARGS(args, parse);
  4271. ast_debug(3, "Will conf %s match %s?\n", confno, args.confno);
  4272. if (!strcasecmp(args.confno, confno)) {
  4273. /* Bingo it's a valid conference */
  4274. cnf = build_conf(args.confno,
  4275. S_OR(args.pin, ""),
  4276. S_OR(args.pinadmin, ""),
  4277. make, dynamic, refcount, chan, NULL);
  4278. break;
  4279. }
  4280. }
  4281. if (!var) {
  4282. ast_debug(1, "%s isn't a valid conference\n", confno);
  4283. }
  4284. ast_config_destroy(cfg);
  4285. }
  4286. } else if (dynamic_pin) {
  4287. /* Correct for the user selecting 'D' instead of 'd' to have
  4288. someone join into a conference that has already been created
  4289. with a pin. */
  4290. if (dynamic_pin[0] == 'q') {
  4291. dynamic_pin[0] = '\0';
  4292. }
  4293. }
  4294. if (cnf) {
  4295. if (confflags && !cnf->chan &&
  4296. !ast_test_flag64(confflags, CONFFLAG_QUIET) &&
  4297. ast_test_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC)) {
  4298. ast_log(LOG_WARNING, "No DAHDI channel available for conference, user introduction disabled (is chan_dahdi loaded?)\n");
  4299. ast_clear_flag64(confflags, CONFFLAG_INTROUSER | CONFFLAG_INTROUSERNOREVIEW | CONFFLAG_INTROUSER_VMREC);
  4300. }
  4301. if (confflags && !cnf->chan &&
  4302. ast_test_flag64(confflags, CONFFLAG_RECORDCONF)) {
  4303. ast_log(LOG_WARNING, "No DAHDI channel available for conference, conference recording disabled (is chan_dahdi loaded?)\n");
  4304. ast_clear_flag64(confflags, CONFFLAG_RECORDCONF);
  4305. }
  4306. }
  4307. return cnf;
  4308. }
  4309. /*! \brief The MeetmeCount application */
  4310. static int count_exec(struct ast_channel *chan, const char *data)
  4311. {
  4312. int res = 0;
  4313. struct ast_conference *conf;
  4314. int count;
  4315. char *localdata;
  4316. char val[80] = "0";
  4317. AST_DECLARE_APP_ARGS(args,
  4318. AST_APP_ARG(confno);
  4319. AST_APP_ARG(varname);
  4320. );
  4321. if (ast_strlen_zero(data)) {
  4322. ast_log(LOG_WARNING, "MeetMeCount requires an argument (conference number)\n");
  4323. return -1;
  4324. }
  4325. localdata = ast_strdupa(data);
  4326. AST_STANDARD_APP_ARGS(args, localdata);
  4327. conf = find_conf(chan, args.confno, 0, 0, NULL, 0, 1, NULL);
  4328. if (conf) {
  4329. count = conf->users;
  4330. dispose_conf(conf);
  4331. conf = NULL;
  4332. } else
  4333. count = 0;
  4334. if (!ast_strlen_zero(args.varname)) {
  4335. /* have var so load it and exit */
  4336. snprintf(val, sizeof(val), "%d", count);
  4337. pbx_builtin_setvar_helper(chan, args.varname, val);
  4338. } else {
  4339. if (ast_channel_state(chan) != AST_STATE_UP) {
  4340. ast_answer(chan);
  4341. }
  4342. res = ast_say_number(chan, count, "", ast_channel_language(chan), (char *) NULL); /* Needs gender */
  4343. }
  4344. return res;
  4345. }
  4346. /*! \brief The meetme() application */
  4347. static int conf_exec(struct ast_channel *chan, const char *data)
  4348. {
  4349. int res = -1;
  4350. char confno[MAX_CONFNUM] = "";
  4351. int allowretry = 0;
  4352. int retrycnt = 0;
  4353. struct ast_conference *cnf = NULL;
  4354. struct ast_flags64 confflags = {0};
  4355. struct ast_flags config_flags = { 0 };
  4356. int dynamic = 0;
  4357. int empty = 0, empty_no_pin = 0;
  4358. int always_prompt = 0;
  4359. const char *notdata;
  4360. char *info, the_pin[MAX_PIN] = "";
  4361. AST_DECLARE_APP_ARGS(args,
  4362. AST_APP_ARG(confno);
  4363. AST_APP_ARG(options);
  4364. AST_APP_ARG(pin);
  4365. );
  4366. char *optargs[OPT_ARG_ARRAY_SIZE] = { NULL, };
  4367. if (ast_strlen_zero(data)) {
  4368. allowretry = 1;
  4369. notdata = "";
  4370. } else {
  4371. notdata = data;
  4372. }
  4373. if (ast_channel_state(chan) != AST_STATE_UP)
  4374. ast_answer(chan);
  4375. info = ast_strdupa(notdata);
  4376. AST_STANDARD_APP_ARGS(args, info);
  4377. if (args.confno) {
  4378. ast_copy_string(confno, args.confno, sizeof(confno));
  4379. if (ast_strlen_zero(confno)) {
  4380. allowretry = 1;
  4381. }
  4382. }
  4383. if (args.pin)
  4384. ast_copy_string(the_pin, args.pin, sizeof(the_pin));
  4385. if (args.options) {
  4386. ast_app_parse_options64(meetme_opts, &confflags, optargs, args.options);
  4387. dynamic = ast_test_flag64(&confflags, CONFFLAG_DYNAMIC | CONFFLAG_DYNAMICPIN);
  4388. if (ast_test_flag64(&confflags, CONFFLAG_DYNAMICPIN) && ast_strlen_zero(args.pin))
  4389. strcpy(the_pin, "q");
  4390. empty = ast_test_flag64(&confflags, CONFFLAG_EMPTY | CONFFLAG_EMPTYNOPIN);
  4391. empty_no_pin = ast_test_flag64(&confflags, CONFFLAG_EMPTYNOPIN);
  4392. always_prompt = ast_test_flag64(&confflags, CONFFLAG_ALWAYSPROMPT | CONFFLAG_DYNAMICPIN);
  4393. }
  4394. do {
  4395. if (retrycnt > 3)
  4396. allowretry = 0;
  4397. if (empty) {
  4398. int i;
  4399. struct ast_config *cfg;
  4400. struct ast_variable *var;
  4401. int confno_int;
  4402. /* We only need to load the config file for static and empty_no_pin (otherwise we don't care) */
  4403. if ((empty_no_pin) || (!dynamic)) {
  4404. cfg = ast_config_load(CONFIG_FILE_NAME, config_flags);
  4405. if (cfg && cfg != CONFIG_STATUS_FILEINVALID) {
  4406. var = ast_variable_browse(cfg, "rooms");
  4407. while (var) {
  4408. char parse[MAX_SETTINGS], *stringp = parse, *confno_tmp;
  4409. if (!strcasecmp(var->name, "conf")) {
  4410. int found = 0;
  4411. ast_copy_string(parse, var->value, sizeof(parse));
  4412. confno_tmp = strsep(&stringp, "|,");
  4413. if (!dynamic) {
  4414. /* For static: run through the list and see if this conference is empty */
  4415. AST_LIST_LOCK(&confs);
  4416. AST_LIST_TRAVERSE(&confs, cnf, list) {
  4417. if (!strcmp(confno_tmp, cnf->confno)) {
  4418. /* The conference exists, therefore it's not empty */
  4419. found = 1;
  4420. break;
  4421. }
  4422. }
  4423. AST_LIST_UNLOCK(&confs);
  4424. cnf = NULL;
  4425. if (!found) {
  4426. /* At this point, we have a confno_tmp (static conference) that is empty */
  4427. if ((empty_no_pin && ast_strlen_zero(stringp)) || (!empty_no_pin)) {
  4428. /* Case 1: empty_no_pin and pin is nonexistent (NULL)
  4429. * Case 2: empty_no_pin and pin is blank (but not NULL)
  4430. * Case 3: not empty_no_pin
  4431. */
  4432. ast_copy_string(confno, confno_tmp, sizeof(confno));
  4433. break;
  4434. }
  4435. }
  4436. }
  4437. }
  4438. var = var->next;
  4439. }
  4440. ast_config_destroy(cfg);
  4441. }
  4442. if (ast_strlen_zero(confno) && (cfg = ast_load_realtime_multientry("meetme", "confno LIKE", "%", SENTINEL))) {
  4443. const char *catg;
  4444. for (catg = ast_category_browse(cfg, NULL); catg; catg = ast_category_browse(cfg, catg)) {
  4445. const char *confno_tmp = ast_variable_retrieve(cfg, catg, "confno");
  4446. const char *pin_tmp = ast_variable_retrieve(cfg, catg, "pin");
  4447. if (ast_strlen_zero(confno_tmp)) {
  4448. continue;
  4449. }
  4450. if (!dynamic) {
  4451. int found = 0;
  4452. /* For static: run through the list and see if this conference is empty */
  4453. AST_LIST_LOCK(&confs);
  4454. AST_LIST_TRAVERSE(&confs, cnf, list) {
  4455. if (!strcmp(confno_tmp, cnf->confno)) {
  4456. /* The conference exists, therefore it's not empty */
  4457. found = 1;
  4458. break;
  4459. }
  4460. }
  4461. AST_LIST_UNLOCK(&confs);
  4462. if (!found) {
  4463. /* At this point, we have a confno_tmp (realtime conference) that is empty */
  4464. if ((empty_no_pin && ast_strlen_zero(pin_tmp)) || (!empty_no_pin)) {
  4465. /* Case 1: empty_no_pin and pin is nonexistent (NULL)
  4466. * Case 2: empty_no_pin and pin is blank (but not NULL)
  4467. * Case 3: not empty_no_pin
  4468. */
  4469. ast_copy_string(confno, confno_tmp, sizeof(confno));
  4470. break;
  4471. }
  4472. }
  4473. }
  4474. }
  4475. ast_config_destroy(cfg);
  4476. }
  4477. }
  4478. /* Select first conference number not in use */
  4479. if (ast_strlen_zero(confno) && dynamic) {
  4480. AST_LIST_LOCK(&confs);
  4481. for (i = 0; i < ARRAY_LEN(conf_map); i++) {
  4482. if (!conf_map[i]) {
  4483. snprintf(confno, sizeof(confno), "%d", i);
  4484. conf_map[i] = 1;
  4485. break;
  4486. }
  4487. }
  4488. AST_LIST_UNLOCK(&confs);
  4489. }
  4490. /* Not found? */
  4491. if (ast_strlen_zero(confno)) {
  4492. res = ast_streamfile(chan, "conf-noempty", ast_channel_language(chan));
  4493. ast_test_suite_event_notify("PLAYBACK", "Message: conf-noempty");
  4494. if (!res)
  4495. ast_waitstream(chan, "");
  4496. } else {
  4497. if (sscanf(confno, "%30d", &confno_int) == 1) {
  4498. if (!ast_test_flag64(&confflags, CONFFLAG_QUIET)) {
  4499. res = ast_streamfile(chan, "conf-enteringno", ast_channel_language(chan));
  4500. if (!res) {
  4501. ast_waitstream(chan, "");
  4502. res = ast_say_digits(chan, confno_int, "", ast_channel_language(chan));
  4503. }
  4504. }
  4505. } else {
  4506. ast_log(LOG_ERROR, "Could not scan confno '%s'\n", confno);
  4507. }
  4508. }
  4509. }
  4510. while (allowretry && (ast_strlen_zero(confno)) && (++retrycnt < 4)) {
  4511. /* Prompt user for conference number */
  4512. res = ast_app_getdata(chan, "conf-getconfno", confno, sizeof(confno) - 1, 0);
  4513. if (res < 0) {
  4514. /* Don't try to validate when we catch an error */
  4515. confno[0] = '\0';
  4516. allowretry = 0;
  4517. break;
  4518. }
  4519. }
  4520. if (!ast_strlen_zero(confno)) {
  4521. /* Check the validity of the conference */
  4522. cnf = find_conf(chan, confno, 1, dynamic, the_pin,
  4523. sizeof(the_pin), 1, &confflags);
  4524. if (!cnf) {
  4525. int too_early = 0;
  4526. cnf = find_conf_realtime(chan, confno, 1, dynamic,
  4527. the_pin, sizeof(the_pin), 1, &confflags, &too_early, optargs);
  4528. if (rt_schedule && too_early)
  4529. allowretry = 0;
  4530. }
  4531. if (!cnf) {
  4532. if (allowretry) {
  4533. confno[0] = '\0';
  4534. res = ast_streamfile(chan, "conf-invalid", ast_channel_language(chan));
  4535. if (!res)
  4536. ast_waitstream(chan, "");
  4537. res = -1;
  4538. }
  4539. } else {
  4540. /* Conference requires a pin for specified access level */
  4541. int req_pin = !ast_strlen_zero(cnf->pin) ||
  4542. (!ast_strlen_zero(cnf->pinadmin) &&
  4543. ast_test_flag64(&confflags, CONFFLAG_ADMIN));
  4544. /* The following logic was derived from a
  4545. * 4 variable truth table and defines which
  4546. * circumstances are not exempt from pin
  4547. * checking.
  4548. * If this needs to be modified, write the
  4549. * truth table back out from the boolean
  4550. * expression AB+A'D+C', change the erroneous
  4551. * result, and rederive the expression.
  4552. * Variables:
  4553. * A: pin provided?
  4554. * B: always prompt?
  4555. * C: dynamic?
  4556. * D: has users? */
  4557. int not_exempt = !cnf->isdynamic;
  4558. not_exempt = not_exempt || (!ast_strlen_zero(args.pin) && ast_test_flag64(&confflags, CONFFLAG_ALWAYSPROMPT));
  4559. not_exempt = not_exempt || (ast_strlen_zero(args.pin) && cnf->users);
  4560. if (req_pin && not_exempt) {
  4561. char pin[MAX_PIN] = "";
  4562. int j;
  4563. /* Allow the pin to be retried up to 3 times */
  4564. for (j = 0; j < 3; j++) {
  4565. if (*the_pin && (always_prompt == 0)) {
  4566. ast_copy_string(pin, the_pin, sizeof(pin));
  4567. res = 0;
  4568. } else {
  4569. /* Prompt user for pin if pin is required */
  4570. ast_test_suite_event_notify("PLAYBACK", "Message: conf-getpin\r\n"
  4571. "Channel: %s",
  4572. ast_channel_name(chan));
  4573. res = ast_app_getdata(chan, "conf-getpin", pin + strlen(pin), sizeof(pin) - 1 - strlen(pin), 0);
  4574. }
  4575. if (res >= 0) {
  4576. if ((!strcasecmp(pin, cnf->pin) &&
  4577. (ast_strlen_zero(cnf->pinadmin) ||
  4578. !ast_test_flag64(&confflags, CONFFLAG_ADMIN))) ||
  4579. (!ast_strlen_zero(cnf->pinadmin) &&
  4580. !strcasecmp(pin, cnf->pinadmin))) {
  4581. /* Pin correct */
  4582. allowretry = 0;
  4583. if (!ast_strlen_zero(cnf->pinadmin) && !strcasecmp(pin, cnf->pinadmin)) {
  4584. if (!ast_strlen_zero(cnf->adminopts)) {
  4585. char *opts = ast_strdupa(cnf->adminopts);
  4586. ast_app_parse_options64(meetme_opts, &confflags, optargs, opts);
  4587. }
  4588. } else {
  4589. if (!ast_strlen_zero(cnf->useropts)) {
  4590. char *opts = ast_strdupa(cnf->useropts);
  4591. ast_app_parse_options64(meetme_opts, &confflags, optargs, opts);
  4592. }
  4593. }
  4594. /* Run the conference */
  4595. ast_verb(4, "Starting recording of MeetMe Conference %s into file %s.%s.\n", cnf->confno, cnf->recordingfilename, cnf->recordingformat);
  4596. res = conf_run(chan, cnf, &confflags, optargs);
  4597. break;
  4598. } else {
  4599. /* Pin invalid */
  4600. if (!ast_streamfile(chan, "conf-invalidpin", ast_channel_language(chan))) {
  4601. res = ast_waitstream(chan, AST_DIGIT_ANY);
  4602. ast_stopstream(chan);
  4603. } else {
  4604. ast_log(LOG_WARNING, "Couldn't play invalid pin msg!\n");
  4605. break;
  4606. }
  4607. if (res < 0)
  4608. break;
  4609. pin[0] = res;
  4610. pin[1] = '\0';
  4611. res = -1;
  4612. if (allowretry)
  4613. confno[0] = '\0';
  4614. }
  4615. } else {
  4616. /* failed when getting the pin */
  4617. res = -1;
  4618. allowretry = 0;
  4619. /* see if we need to get rid of the conference */
  4620. break;
  4621. }
  4622. /* Don't retry pin with a static pin */
  4623. if (*the_pin && (always_prompt == 0)) {
  4624. break;
  4625. }
  4626. }
  4627. } else {
  4628. /* No pin required */
  4629. allowretry = 0;
  4630. /* For RealTime conferences without a pin
  4631. * should still support loading options
  4632. */
  4633. if (!ast_strlen_zero(cnf->useropts)) {
  4634. char *opts = ast_strdupa(cnf->useropts);
  4635. ast_app_parse_options64(meetme_opts, &confflags, optargs, opts);
  4636. }
  4637. /* Run the conference */
  4638. res = conf_run(chan, cnf, &confflags, optargs);
  4639. }
  4640. dispose_conf(cnf);
  4641. cnf = NULL;
  4642. }
  4643. }
  4644. } while (allowretry);
  4645. if (cnf)
  4646. dispose_conf(cnf);
  4647. return res;
  4648. }
  4649. static struct ast_conf_user *find_user(struct ast_conference *conf, const char *callerident)
  4650. {
  4651. struct ast_conf_user *user = NULL;
  4652. int cid;
  4653. if (conf && callerident && sscanf(callerident, "%30d", &cid) == 1) {
  4654. user = ao2_find(conf->usercontainer, &cid, 0);
  4655. /* reference decremented later in admin_exec */
  4656. return user;
  4657. }
  4658. return NULL;
  4659. }
  4660. static int user_listen_volup_cb(void *obj, void *unused, int flags)
  4661. {
  4662. struct ast_conf_user *user = obj;
  4663. tweak_listen_volume(user, VOL_UP);
  4664. return 0;
  4665. }
  4666. static int user_listen_voldown_cb(void *obj, void *unused, int flags)
  4667. {
  4668. struct ast_conf_user *user = obj;
  4669. tweak_listen_volume(user, VOL_DOWN);
  4670. return 0;
  4671. }
  4672. static int user_talk_volup_cb(void *obj, void *unused, int flags)
  4673. {
  4674. struct ast_conf_user *user = obj;
  4675. tweak_talk_volume(user, VOL_UP);
  4676. return 0;
  4677. }
  4678. static int user_talk_voldown_cb(void *obj, void *unused, int flags)
  4679. {
  4680. struct ast_conf_user *user = obj;
  4681. tweak_talk_volume(user, VOL_DOWN);
  4682. return 0;
  4683. }
  4684. static int user_reset_vol_cb(void *obj, void *unused, int flags)
  4685. {
  4686. struct ast_conf_user *user = obj;
  4687. reset_volumes(user);
  4688. return 0;
  4689. }
  4690. static int user_chan_cb(void *obj, void *args, int flags)
  4691. {
  4692. struct ast_conf_user *user = obj;
  4693. const char *channel = args;
  4694. if (!strcmp(ast_channel_name(user->chan), channel)) {
  4695. return (CMP_MATCH | CMP_STOP);
  4696. }
  4697. return 0;
  4698. }
  4699. /*! \brief The MeetMeadmin application
  4700. MeetMeAdmin(confno, command, caller) */
  4701. static int admin_exec(struct ast_channel *chan, const char *data) {
  4702. char *params;
  4703. struct ast_conference *cnf;
  4704. struct ast_conf_user *user = NULL;
  4705. AST_DECLARE_APP_ARGS(args,
  4706. AST_APP_ARG(confno);
  4707. AST_APP_ARG(command);
  4708. AST_APP_ARG(user);
  4709. );
  4710. int res = 0;
  4711. if (ast_strlen_zero(data)) {
  4712. ast_log(LOG_WARNING, "MeetMeAdmin requires an argument!\n");
  4713. pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", "NOPARSE");
  4714. return -1;
  4715. }
  4716. params = ast_strdupa(data);
  4717. AST_STANDARD_APP_ARGS(args, params);
  4718. if (!args.command) {
  4719. ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n");
  4720. pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", "NOPARSE");
  4721. return -1;
  4722. }
  4723. AST_LIST_LOCK(&confs);
  4724. AST_LIST_TRAVERSE(&confs, cnf, list) {
  4725. if (!strcmp(cnf->confno, args.confno))
  4726. break;
  4727. }
  4728. if (!cnf) {
  4729. ast_log(LOG_WARNING, "Conference number '%s' not found!\n", args.confno);
  4730. AST_LIST_UNLOCK(&confs);
  4731. pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", "NOTFOUND");
  4732. return 0;
  4733. }
  4734. ast_atomic_fetchadd_int(&cnf->refcount, 1);
  4735. if (args.user) {
  4736. user = find_user(cnf, args.user);
  4737. if (!user) {
  4738. ast_log(LOG_NOTICE, "Specified User not found!\n");
  4739. res = -2;
  4740. goto usernotfound;
  4741. }
  4742. } else {
  4743. /* fail for commands that require a user */
  4744. switch (*args.command) {
  4745. case 'm': /* Unmute */
  4746. case 'M': /* Mute */
  4747. case 't': /* Lower user's talk volume */
  4748. case 'T': /* Raise user's talk volume */
  4749. case 'u': /* Lower user's listen volume */
  4750. case 'U': /* Raise user's listen volume */
  4751. case 'r': /* Reset user's volume level */
  4752. case 'k': /* Kick user */
  4753. res = -2;
  4754. ast_log(LOG_NOTICE, "No user specified!\n");
  4755. goto usernotfound;
  4756. default:
  4757. break;
  4758. }
  4759. }
  4760. switch (*args.command) {
  4761. case 76: /* L: Lock */
  4762. cnf->locked = 1;
  4763. break;
  4764. case 108: /* l: Unlock */
  4765. cnf->locked = 0;
  4766. break;
  4767. case 75: /* K: kick all users */
  4768. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_set_kickme_cb, NULL);
  4769. break;
  4770. case 101: /* e: Eject last user*/
  4771. {
  4772. int max_no = 0;
  4773. RAII_VAR(struct ast_conf_user *, eject_user, NULL, ao2_cleanup);
  4774. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_max_cmp, &max_no);
  4775. eject_user = ao2_find(cnf->usercontainer, &max_no, 0);
  4776. if (!eject_user) {
  4777. res = -1;
  4778. ast_log(LOG_NOTICE, "No last user to kick!\n");
  4779. break;
  4780. }
  4781. if (!ast_test_flag64(&eject_user->userflags, CONFFLAG_ADMIN)) {
  4782. eject_user->adminflags |= ADMINFLAG_KICKME;
  4783. } else {
  4784. res = -1;
  4785. ast_log(LOG_NOTICE, "Not kicking last user, is an Admin!\n");
  4786. }
  4787. break;
  4788. }
  4789. case 77: /* M: Mute */
  4790. user->adminflags |= ADMINFLAG_MUTED;
  4791. break;
  4792. case 78: /* N: Mute all (non-admin) users */
  4793. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_set_muted_cb, &cnf);
  4794. break;
  4795. case 109: /* m: Unmute */
  4796. user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST);
  4797. break;
  4798. case 110: /* n: Unmute all users */
  4799. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_set_unmuted_cb, NULL);
  4800. break;
  4801. case 107: /* k: Kick user */
  4802. user->adminflags |= ADMINFLAG_KICKME;
  4803. break;
  4804. case 118: /* v: Lower all users listen volume */
  4805. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_listen_voldown_cb, NULL);
  4806. break;
  4807. case 86: /* V: Raise all users listen volume */
  4808. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_listen_volup_cb, NULL);
  4809. break;
  4810. case 115: /* s: Lower all users speaking volume */
  4811. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_talk_voldown_cb, NULL);
  4812. break;
  4813. case 83: /* S: Raise all users speaking volume */
  4814. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_talk_volup_cb, NULL);
  4815. break;
  4816. case 82: /* R: Reset all volume levels */
  4817. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_reset_vol_cb, NULL);
  4818. break;
  4819. case 114: /* r: Reset user's volume level */
  4820. reset_volumes(user);
  4821. break;
  4822. case 85: /* U: Raise user's listen volume */
  4823. tweak_listen_volume(user, VOL_UP);
  4824. break;
  4825. case 117: /* u: Lower user's listen volume */
  4826. tweak_listen_volume(user, VOL_DOWN);
  4827. break;
  4828. case 84: /* T: Raise user's talk volume */
  4829. tweak_talk_volume(user, VOL_UP);
  4830. break;
  4831. case 116: /* t: Lower user's talk volume */
  4832. tweak_talk_volume(user, VOL_DOWN);
  4833. break;
  4834. case 'E': /* E: Extend conference */
  4835. if (rt_extend_conf(args.confno)) {
  4836. res = -1;
  4837. }
  4838. break;
  4839. }
  4840. if (args.user) {
  4841. /* decrement reference from find_user */
  4842. ao2_ref(user, -1);
  4843. }
  4844. usernotfound:
  4845. AST_LIST_UNLOCK(&confs);
  4846. dispose_conf(cnf);
  4847. pbx_builtin_setvar_helper(chan, "MEETMEADMINSTATUS", res == -2 ? "NOTFOUND" : res ? "FAILED" : "OK");
  4848. return 0;
  4849. }
  4850. /*! \brief The MeetMeChannelAdmin application
  4851. MeetMeChannelAdmin(channel, command) */
  4852. static int channel_admin_exec(struct ast_channel *chan, const char *data) {
  4853. char *params;
  4854. struct ast_conference *conf = NULL;
  4855. struct ast_conf_user *user = NULL;
  4856. AST_DECLARE_APP_ARGS(args,
  4857. AST_APP_ARG(channel);
  4858. AST_APP_ARG(command);
  4859. );
  4860. if (ast_strlen_zero(data)) {
  4861. ast_log(LOG_WARNING, "MeetMeChannelAdmin requires two arguments!\n");
  4862. return -1;
  4863. }
  4864. params = ast_strdupa(data);
  4865. AST_STANDARD_APP_ARGS(args, params);
  4866. if (!args.channel) {
  4867. ast_log(LOG_WARNING, "MeetMeChannelAdmin requires a channel name!\n");
  4868. return -1;
  4869. }
  4870. if (!args.command) {
  4871. ast_log(LOG_WARNING, "MeetMeChannelAdmin requires a command!\n");
  4872. return -1;
  4873. }
  4874. AST_LIST_LOCK(&confs);
  4875. AST_LIST_TRAVERSE(&confs, conf, list) {
  4876. if ((user = ao2_callback(conf->usercontainer, 0, user_chan_cb, args.channel))) {
  4877. break;
  4878. }
  4879. }
  4880. if (!user) {
  4881. ast_log(LOG_NOTICE, "Specified user (%s) not found\n", args.channel);
  4882. AST_LIST_UNLOCK(&confs);
  4883. return 0;
  4884. }
  4885. /* perform the specified action */
  4886. switch (*args.command) {
  4887. case 77: /* M: Mute */
  4888. user->adminflags |= ADMINFLAG_MUTED;
  4889. break;
  4890. case 109: /* m: Unmute */
  4891. user->adminflags &= ~ADMINFLAG_MUTED;
  4892. break;
  4893. case 107: /* k: Kick user */
  4894. user->adminflags |= ADMINFLAG_KICKME;
  4895. break;
  4896. default: /* unknown command */
  4897. ast_log(LOG_WARNING, "Unknown MeetMeChannelAdmin command '%s'\n", args.command);
  4898. break;
  4899. }
  4900. ao2_ref(user, -1);
  4901. AST_LIST_UNLOCK(&confs);
  4902. return 0;
  4903. }
  4904. static int meetmemute(struct mansession *s, const struct message *m, int mute)
  4905. {
  4906. struct ast_conference *conf;
  4907. struct ast_conf_user *user;
  4908. const char *confid = astman_get_header(m, "Meetme");
  4909. char *userid = ast_strdupa(astman_get_header(m, "Usernum"));
  4910. int userno;
  4911. if (ast_strlen_zero(confid)) {
  4912. astman_send_error(s, m, "Meetme conference not specified");
  4913. return 0;
  4914. }
  4915. if (ast_strlen_zero(userid)) {
  4916. astman_send_error(s, m, "Meetme user number not specified");
  4917. return 0;
  4918. }
  4919. userno = strtoul(userid, &userid, 10);
  4920. if (*userid) {
  4921. astman_send_error(s, m, "Invalid user number");
  4922. return 0;
  4923. }
  4924. /* Look in the conference list */
  4925. AST_LIST_LOCK(&confs);
  4926. AST_LIST_TRAVERSE(&confs, conf, list) {
  4927. if (!strcmp(confid, conf->confno))
  4928. break;
  4929. }
  4930. if (!conf) {
  4931. AST_LIST_UNLOCK(&confs);
  4932. astman_send_error(s, m, "Meetme conference does not exist");
  4933. return 0;
  4934. }
  4935. user = ao2_find(conf->usercontainer, &userno, 0);
  4936. if (!user) {
  4937. AST_LIST_UNLOCK(&confs);
  4938. astman_send_error(s, m, "User number not found");
  4939. return 0;
  4940. }
  4941. if (mute)
  4942. user->adminflags |= ADMINFLAG_MUTED; /* request user muting */
  4943. else
  4944. user->adminflags &= ~(ADMINFLAG_MUTED | ADMINFLAG_SELFMUTED | ADMINFLAG_T_REQUEST); /* request user unmuting */
  4945. AST_LIST_UNLOCK(&confs);
  4946. ast_log(LOG_NOTICE, "Requested to %smute conf %s user %d userchan %s uniqueid %s\n", mute ? "" : "un", conf->confno, user->user_no, ast_channel_name(user->chan), ast_channel_uniqueid(user->chan));
  4947. ao2_ref(user, -1);
  4948. astman_send_ack(s, m, mute ? "User muted" : "User unmuted");
  4949. return 0;
  4950. }
  4951. static int action_meetmemute(struct mansession *s, const struct message *m)
  4952. {
  4953. return meetmemute(s, m, 1);
  4954. }
  4955. static int action_meetmeunmute(struct mansession *s, const struct message *m)
  4956. {
  4957. return meetmemute(s, m, 0);
  4958. }
  4959. static int action_meetmelist(struct mansession *s, const struct message *m)
  4960. {
  4961. const char *actionid = astman_get_header(m, "ActionID");
  4962. const char *conference = astman_get_header(m, "Conference");
  4963. char idText[80] = "";
  4964. struct ast_conference *cnf;
  4965. struct ast_conf_user *user;
  4966. struct ao2_iterator user_iter;
  4967. int total = 0;
  4968. if (!ast_strlen_zero(actionid))
  4969. snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
  4970. if (AST_LIST_EMPTY(&confs)) {
  4971. astman_send_error(s, m, "No active conferences.");
  4972. return 0;
  4973. }
  4974. astman_send_listack(s, m, "Meetme user list will follow", "start");
  4975. /* Find the right conference */
  4976. AST_LIST_LOCK(&confs);
  4977. AST_LIST_TRAVERSE(&confs, cnf, list) {
  4978. /* If we ask for one particular, and this isn't it, skip it */
  4979. if (!ast_strlen_zero(conference) && strcmp(cnf->confno, conference))
  4980. continue;
  4981. /* Show all the users */
  4982. user_iter = ao2_iterator_init(cnf->usercontainer, 0);
  4983. while ((user = ao2_iterator_next(&user_iter))) {
  4984. total++;
  4985. astman_append(s,
  4986. "Event: MeetmeList\r\n"
  4987. "%s"
  4988. "Conference: %s\r\n"
  4989. "UserNumber: %d\r\n"
  4990. "CallerIDNum: %s\r\n"
  4991. "CallerIDName: %s\r\n"
  4992. "ConnectedLineNum: %s\r\n"
  4993. "ConnectedLineName: %s\r\n"
  4994. "Channel: %s\r\n"
  4995. "Admin: %s\r\n"
  4996. "Role: %s\r\n"
  4997. "MarkedUser: %s\r\n"
  4998. "Muted: %s\r\n"
  4999. "Talking: %s\r\n"
  5000. "\r\n",
  5001. idText,
  5002. cnf->confno,
  5003. user->user_no,
  5004. S_COR(ast_channel_caller(user->chan)->id.number.valid, ast_channel_caller(user->chan)->id.number.str, "<unknown>"),
  5005. S_COR(ast_channel_caller(user->chan)->id.name.valid, ast_channel_caller(user->chan)->id.name.str, "<no name>"),
  5006. S_COR(ast_channel_connected(user->chan)->id.number.valid, ast_channel_connected(user->chan)->id.number.str, "<unknown>"),
  5007. S_COR(ast_channel_connected(user->chan)->id.name.valid, ast_channel_connected(user->chan)->id.name.str, "<no name>"),
  5008. ast_channel_name(user->chan),
  5009. ast_test_flag64(&user->userflags, CONFFLAG_ADMIN) ? "Yes" : "No",
  5010. ast_test_flag64(&user->userflags, CONFFLAG_MONITOR) ? "Listen only" : ast_test_flag64(&user->userflags, CONFFLAG_TALKER) ? "Talk only" : "Talk and listen",
  5011. ast_test_flag64(&user->userflags, CONFFLAG_MARKEDUSER) ? "Yes" : "No",
  5012. user->adminflags & ADMINFLAG_MUTED ? "By admin" : user->adminflags & ADMINFLAG_SELFMUTED ? "By self" : "No",
  5013. user->talking > 0 ? "Yes" : user->talking == 0 ? "No" : "Not monitored");
  5014. ao2_ref(user, -1);
  5015. }
  5016. ao2_iterator_destroy(&user_iter);
  5017. }
  5018. AST_LIST_UNLOCK(&confs);
  5019. /* Send final confirmation */
  5020. astman_send_list_complete_start(s, m, "MeetmeListComplete", total);
  5021. astman_send_list_complete_end(s);
  5022. return 0;
  5023. }
  5024. static int action_meetmelistrooms(struct mansession *s, const struct message *m)
  5025. {
  5026. const char *actionid = astman_get_header(m, "ActionID");
  5027. char idText[80] = "";
  5028. struct ast_conference *cnf;
  5029. int totalitems = 0;
  5030. int hr, min, sec;
  5031. time_t now;
  5032. char markedusers[5];
  5033. if (!ast_strlen_zero(actionid)) {
  5034. snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
  5035. }
  5036. if (AST_LIST_EMPTY(&confs)) {
  5037. astman_send_error(s, m, "No active conferences.");
  5038. return 0;
  5039. }
  5040. astman_send_listack(s, m, "Meetme conferences will follow", "start");
  5041. now = time(NULL);
  5042. /* Traverse the conference list */
  5043. AST_LIST_LOCK(&confs);
  5044. AST_LIST_TRAVERSE(&confs, cnf, list) {
  5045. totalitems++;
  5046. if (cnf->markedusers == 0) {
  5047. strcpy(markedusers, "N/A");
  5048. } else {
  5049. sprintf(markedusers, "%.4d", cnf->markedusers);
  5050. }
  5051. hr = (now - cnf->start) / 3600;
  5052. min = ((now - cnf->start) % 3600) / 60;
  5053. sec = (now - cnf->start) % 60;
  5054. astman_append(s,
  5055. "Event: MeetmeListRooms\r\n"
  5056. "%s"
  5057. "Conference: %s\r\n"
  5058. "Parties: %d\r\n"
  5059. "Marked: %s\r\n"
  5060. "Activity: %2.2d:%2.2d:%2.2d\r\n"
  5061. "Creation: %s\r\n"
  5062. "Locked: %s\r\n"
  5063. "\r\n",
  5064. idText,
  5065. cnf->confno,
  5066. cnf->users,
  5067. markedusers,
  5068. hr, min, sec,
  5069. cnf->isdynamic ? "Dynamic" : "Static",
  5070. cnf->locked ? "Yes" : "No");
  5071. }
  5072. AST_LIST_UNLOCK(&confs);
  5073. /* Send final confirmation */
  5074. astman_send_list_complete_start(s, m, "MeetmeListRoomsComplete", totalitems);
  5075. astman_send_list_complete_end(s);
  5076. return 0;
  5077. }
  5078. /*! \internal
  5079. * \brief creates directory structure and assigns absolute path from relative paths for filenames
  5080. *
  5081. * \param filename contains the absolute or relative path to the desired file
  5082. * \param buffer stores completed filename, absolutely must be a buffer of PATH_MAX length
  5083. */
  5084. static void filename_parse(char *filename, char *buffer)
  5085. {
  5086. char *slash;
  5087. if (ast_strlen_zero(filename)) {
  5088. ast_log(LOG_WARNING, "No file name was provided for a file save option.\n");
  5089. } else if (filename[0] != '/') {
  5090. snprintf(buffer, PATH_MAX, "%s/meetme/%s", ast_config_AST_SPOOL_DIR, filename);
  5091. } else {
  5092. ast_copy_string(buffer, filename, PATH_MAX);
  5093. }
  5094. slash = buffer;
  5095. if ((slash = strrchr(slash, '/'))) {
  5096. *slash = '\0';
  5097. ast_mkdir(buffer, 0777);
  5098. *slash = '/';
  5099. }
  5100. }
  5101. static void *recordthread(void *args)
  5102. {
  5103. struct ast_conference *cnf = args;
  5104. struct ast_frame *f = NULL;
  5105. int flags;
  5106. struct ast_filestream *s = NULL;
  5107. int res = 0;
  5108. int x;
  5109. const char *oldrecordingfilename = NULL;
  5110. char filename_buffer[PATH_MAX];
  5111. if (!cnf || !cnf->lchan) {
  5112. pthread_exit(0);
  5113. }
  5114. filename_buffer[0] = '\0';
  5115. filename_parse(cnf->recordingfilename, filename_buffer);
  5116. ast_stopstream(cnf->lchan);
  5117. flags = O_CREAT | O_TRUNC | O_WRONLY;
  5118. cnf->recording = MEETME_RECORD_ACTIVE;
  5119. while (ast_waitfor(cnf->lchan, -1) > -1) {
  5120. if (cnf->recording == MEETME_RECORD_TERMINATE) {
  5121. AST_LIST_LOCK(&confs);
  5122. AST_LIST_UNLOCK(&confs);
  5123. break;
  5124. }
  5125. if (!s && !(ast_strlen_zero(filename_buffer)) && (filename_buffer != oldrecordingfilename)) {
  5126. s = ast_writefile(filename_buffer, cnf->recordingformat, NULL, flags, 0, AST_FILE_MODE);
  5127. oldrecordingfilename = filename_buffer;
  5128. }
  5129. f = ast_read(cnf->lchan);
  5130. if (!f) {
  5131. res = -1;
  5132. break;
  5133. }
  5134. if (f->frametype == AST_FRAME_VOICE) {
  5135. ast_mutex_lock(&cnf->listenlock);
  5136. for (x = 0; x < AST_FRAME_BITS; x++) {
  5137. /* Free any translations that have occured */
  5138. if (cnf->transframe[x]) {
  5139. ast_frfree(cnf->transframe[x]);
  5140. cnf->transframe[x] = NULL;
  5141. }
  5142. }
  5143. if (cnf->origframe)
  5144. ast_frfree(cnf->origframe);
  5145. cnf->origframe = ast_frdup(f);
  5146. ast_mutex_unlock(&cnf->listenlock);
  5147. if (s)
  5148. res = ast_writestream(s, f);
  5149. if (res) {
  5150. ast_frfree(f);
  5151. break;
  5152. }
  5153. }
  5154. ast_frfree(f);
  5155. }
  5156. cnf->recording = MEETME_RECORD_OFF;
  5157. if (s)
  5158. ast_closestream(s);
  5159. pthread_exit(0);
  5160. }
  5161. /*! \brief Callback for devicestate providers */
  5162. static enum ast_device_state meetmestate(const char *data)
  5163. {
  5164. struct ast_conference *conf;
  5165. /* Find conference */
  5166. AST_LIST_LOCK(&confs);
  5167. AST_LIST_TRAVERSE(&confs, conf, list) {
  5168. if (!strcmp(data, conf->confno))
  5169. break;
  5170. }
  5171. AST_LIST_UNLOCK(&confs);
  5172. if (!conf)
  5173. return AST_DEVICE_INVALID;
  5174. /* SKREP to fill */
  5175. if (!conf->users)
  5176. return AST_DEVICE_NOT_INUSE;
  5177. return AST_DEVICE_INUSE;
  5178. }
  5179. static void meetme_set_defaults(void)
  5180. {
  5181. /* Scheduling support is off by default */
  5182. rt_schedule = 0;
  5183. fuzzystart = 0;
  5184. earlyalert = 0;
  5185. endalert = 0;
  5186. extendby = 0;
  5187. /* Logging of participants defaults to ON for compatibility reasons */
  5188. rt_log_members = 1;
  5189. /* Set default number of buffers to be allocated. */
  5190. audio_buffers = DEFAULT_AUDIO_BUFFERS;
  5191. }
  5192. static void load_config_meetme(int reload)
  5193. {
  5194. struct ast_config *cfg;
  5195. struct ast_flags config_flags = { 0 };
  5196. const char *val;
  5197. if (!reload) {
  5198. meetme_set_defaults();
  5199. }
  5200. if (!(cfg = ast_config_load(CONFIG_FILE_NAME, config_flags))) {
  5201. return;
  5202. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  5203. ast_log(LOG_ERROR, "Config file " CONFIG_FILE_NAME " is in an invalid format. Aborting.\n");
  5204. return;
  5205. }
  5206. if (reload) {
  5207. meetme_set_defaults();
  5208. }
  5209. if ((val = ast_variable_retrieve(cfg, "general", "audiobuffers"))) {
  5210. if ((sscanf(val, "%30d", &audio_buffers) != 1)) {
  5211. ast_log(LOG_WARNING, "audiobuffers setting must be a number, not '%s'\n", val);
  5212. audio_buffers = DEFAULT_AUDIO_BUFFERS;
  5213. } else if ((audio_buffers < DAHDI_DEFAULT_NUM_BUFS) || (audio_buffers > DAHDI_MAX_NUM_BUFS)) {
  5214. ast_log(LOG_WARNING, "audiobuffers setting must be between %d and %d\n",
  5215. DAHDI_DEFAULT_NUM_BUFS, DAHDI_MAX_NUM_BUFS);
  5216. audio_buffers = DEFAULT_AUDIO_BUFFERS;
  5217. }
  5218. if (audio_buffers != DEFAULT_AUDIO_BUFFERS)
  5219. ast_log(LOG_NOTICE, "Audio buffers per channel set to %d\n", audio_buffers);
  5220. }
  5221. if ((val = ast_variable_retrieve(cfg, "general", "schedule")))
  5222. rt_schedule = ast_true(val);
  5223. if ((val = ast_variable_retrieve(cfg, "general", "logmembercount")))
  5224. rt_log_members = ast_true(val);
  5225. if ((val = ast_variable_retrieve(cfg, "general", "fuzzystart"))) {
  5226. if ((sscanf(val, "%30d", &fuzzystart) != 1)) {
  5227. ast_log(LOG_WARNING, "fuzzystart must be a number, not '%s'\n", val);
  5228. fuzzystart = 0;
  5229. }
  5230. }
  5231. if ((val = ast_variable_retrieve(cfg, "general", "earlyalert"))) {
  5232. if ((sscanf(val, "%30d", &earlyalert) != 1)) {
  5233. ast_log(LOG_WARNING, "earlyalert must be a number, not '%s'\n", val);
  5234. earlyalert = 0;
  5235. }
  5236. }
  5237. if ((val = ast_variable_retrieve(cfg, "general", "endalert"))) {
  5238. if ((sscanf(val, "%30d", &endalert) != 1)) {
  5239. ast_log(LOG_WARNING, "endalert must be a number, not '%s'\n", val);
  5240. endalert = 0;
  5241. }
  5242. }
  5243. if ((val = ast_variable_retrieve(cfg, "general", "extendby"))) {
  5244. if ((sscanf(val, "%30d", &extendby) != 1)) {
  5245. ast_log(LOG_WARNING, "extendby must be a number, not '%s'\n", val);
  5246. extendby = 0;
  5247. }
  5248. }
  5249. ast_config_destroy(cfg);
  5250. }
  5251. /*!
  5252. * \internal
  5253. * \brief Find an SLA trunk by name
  5254. */
  5255. static struct sla_trunk *sla_find_trunk(const char *name)
  5256. {
  5257. struct sla_trunk tmp_trunk = {
  5258. .name = name,
  5259. };
  5260. return ao2_find(sla_trunks, &tmp_trunk, OBJ_POINTER);
  5261. }
  5262. /*!
  5263. * \internal
  5264. * \brief Find an SLA station by name
  5265. */
  5266. static struct sla_station *sla_find_station(const char *name)
  5267. {
  5268. struct sla_station tmp_station = {
  5269. .name = name,
  5270. };
  5271. return ao2_find(sla_stations, &tmp_station, OBJ_POINTER);
  5272. }
  5273. static int sla_check_station_hold_access(const struct sla_trunk *trunk,
  5274. const struct sla_station *station)
  5275. {
  5276. struct sla_station_ref *station_ref;
  5277. struct sla_trunk_ref *trunk_ref;
  5278. /* For each station that has this call on hold, check for private hold. */
  5279. AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
  5280. AST_LIST_TRAVERSE(&station_ref->station->trunks, trunk_ref, entry) {
  5281. if (trunk_ref->trunk != trunk || station_ref->station == station)
  5282. continue;
  5283. if (trunk_ref->state == SLA_TRUNK_STATE_ONHOLD_BYME &&
  5284. station_ref->station->hold_access == SLA_HOLD_PRIVATE)
  5285. return 1;
  5286. return 0;
  5287. }
  5288. }
  5289. return 0;
  5290. }
  5291. /*!
  5292. * \brief Find a trunk reference on a station by name
  5293. * \param station the station
  5294. * \param name the trunk's name
  5295. * \pre sla_station is locked
  5296. * \return a pointer to the station's trunk reference. If the trunk
  5297. * is not found, it is not idle and barge is disabled, or if
  5298. * it is on hold and private hold is set, then NULL will be returned.
  5299. */
  5300. static struct sla_trunk_ref *sla_find_trunk_ref_byname(const struct sla_station *station,
  5301. const char *name)
  5302. {
  5303. struct sla_trunk_ref *trunk_ref = NULL;
  5304. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  5305. if (strcasecmp(trunk_ref->trunk->name, name))
  5306. continue;
  5307. if ( (trunk_ref->trunk->barge_disabled
  5308. && trunk_ref->state == SLA_TRUNK_STATE_UP) ||
  5309. (trunk_ref->trunk->hold_stations
  5310. && trunk_ref->trunk->hold_access == SLA_HOLD_PRIVATE
  5311. && trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) ||
  5312. sla_check_station_hold_access(trunk_ref->trunk, station) )
  5313. {
  5314. trunk_ref = NULL;
  5315. }
  5316. break;
  5317. }
  5318. if (trunk_ref) {
  5319. ao2_ref(trunk_ref, 1);
  5320. }
  5321. return trunk_ref;
  5322. }
  5323. static void sla_station_ref_destructor(void *obj)
  5324. {
  5325. struct sla_station_ref *station_ref = obj;
  5326. if (station_ref->station) {
  5327. ao2_ref(station_ref->station, -1);
  5328. station_ref->station = NULL;
  5329. }
  5330. }
  5331. static struct sla_station_ref *sla_create_station_ref(struct sla_station *station)
  5332. {
  5333. struct sla_station_ref *station_ref;
  5334. if (!(station_ref = ao2_alloc(sizeof(*station_ref), sla_station_ref_destructor))) {
  5335. return NULL;
  5336. }
  5337. ao2_ref(station, 1);
  5338. station_ref->station = station;
  5339. return station_ref;
  5340. }
  5341. static struct sla_ringing_station *sla_create_ringing_station(struct sla_station *station)
  5342. {
  5343. struct sla_ringing_station *ringing_station;
  5344. if (!(ringing_station = ast_calloc(1, sizeof(*ringing_station))))
  5345. return NULL;
  5346. ao2_ref(station, 1);
  5347. ringing_station->station = station;
  5348. ringing_station->ring_begin = ast_tvnow();
  5349. return ringing_station;
  5350. }
  5351. static void sla_ringing_station_destroy(struct sla_ringing_station *ringing_station)
  5352. {
  5353. if (ringing_station->station) {
  5354. ao2_ref(ringing_station->station, -1);
  5355. ringing_station->station = NULL;
  5356. }
  5357. ast_free(ringing_station);
  5358. }
  5359. static struct sla_failed_station *sla_create_failed_station(struct sla_station *station)
  5360. {
  5361. struct sla_failed_station *failed_station;
  5362. if (!(failed_station = ast_calloc(1, sizeof(*failed_station)))) {
  5363. return NULL;
  5364. }
  5365. ao2_ref(station, 1);
  5366. failed_station->station = station;
  5367. failed_station->last_try = ast_tvnow();
  5368. return failed_station;
  5369. }
  5370. static void sla_failed_station_destroy(struct sla_failed_station *failed_station)
  5371. {
  5372. if (failed_station->station) {
  5373. ao2_ref(failed_station->station, -1);
  5374. failed_station->station = NULL;
  5375. }
  5376. ast_free(failed_station);
  5377. }
  5378. static enum ast_device_state sla_state_to_devstate(enum sla_trunk_state state)
  5379. {
  5380. switch (state) {
  5381. case SLA_TRUNK_STATE_IDLE:
  5382. return AST_DEVICE_NOT_INUSE;
  5383. case SLA_TRUNK_STATE_RINGING:
  5384. return AST_DEVICE_RINGING;
  5385. case SLA_TRUNK_STATE_UP:
  5386. return AST_DEVICE_INUSE;
  5387. case SLA_TRUNK_STATE_ONHOLD:
  5388. case SLA_TRUNK_STATE_ONHOLD_BYME:
  5389. return AST_DEVICE_ONHOLD;
  5390. }
  5391. return AST_DEVICE_UNKNOWN;
  5392. }
  5393. static void sla_change_trunk_state(const struct sla_trunk *trunk, enum sla_trunk_state state,
  5394. enum sla_which_trunk_refs inactive_only, const struct sla_trunk_ref *exclude)
  5395. {
  5396. struct sla_station *station;
  5397. struct sla_trunk_ref *trunk_ref;
  5398. struct ao2_iterator i;
  5399. i = ao2_iterator_init(sla_stations, 0);
  5400. while ((station = ao2_iterator_next(&i))) {
  5401. ao2_lock(station);
  5402. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  5403. if (trunk_ref->trunk != trunk || (inactive_only ? trunk_ref->chan : 0)
  5404. || trunk_ref == exclude) {
  5405. continue;
  5406. }
  5407. trunk_ref->state = state;
  5408. ast_devstate_changed(sla_state_to_devstate(state), AST_DEVSTATE_CACHABLE,
  5409. "SLA:%s_%s", station->name, trunk->name);
  5410. break;
  5411. }
  5412. ao2_unlock(station);
  5413. ao2_ref(station, -1);
  5414. }
  5415. ao2_iterator_destroy(&i);
  5416. }
  5417. struct run_station_args {
  5418. struct sla_station *station;
  5419. struct sla_trunk_ref *trunk_ref;
  5420. ast_mutex_t *cond_lock;
  5421. ast_cond_t *cond;
  5422. };
  5423. static void answer_trunk_chan(struct ast_channel *chan)
  5424. {
  5425. ast_answer(chan);
  5426. ast_indicate(chan, -1);
  5427. }
  5428. static void *run_station(void *data)
  5429. {
  5430. RAII_VAR(struct sla_station *, station, NULL, ao2_cleanup);
  5431. RAII_VAR(struct sla_trunk_ref *, trunk_ref, NULL, ao2_cleanup);
  5432. struct ast_str *conf_name = ast_str_create(16);
  5433. struct ast_flags64 conf_flags = { 0 };
  5434. struct ast_conference *conf;
  5435. {
  5436. struct run_station_args *args = data;
  5437. station = args->station;
  5438. trunk_ref = args->trunk_ref;
  5439. ast_mutex_lock(args->cond_lock);
  5440. ast_cond_signal(args->cond);
  5441. ast_mutex_unlock(args->cond_lock);
  5442. /* args is no longer valid here. */
  5443. }
  5444. ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1);
  5445. ast_str_set(&conf_name, 0, "SLA_%s", trunk_ref->trunk->name);
  5446. ast_set_flag64(&conf_flags,
  5447. CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
  5448. answer_trunk_chan(trunk_ref->chan);
  5449. conf = build_conf(ast_str_buffer(conf_name), "", "", 0, 0, 1, trunk_ref->chan, NULL);
  5450. if (conf) {
  5451. conf_run(trunk_ref->chan, conf, &conf_flags, NULL);
  5452. dispose_conf(conf);
  5453. conf = NULL;
  5454. }
  5455. trunk_ref->chan = NULL;
  5456. if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
  5457. trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
  5458. ast_str_append(&conf_name, 0, ",K");
  5459. admin_exec(NULL, ast_str_buffer(conf_name));
  5460. trunk_ref->trunk->hold_stations = 0;
  5461. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
  5462. }
  5463. ast_dial_join(station->dial);
  5464. ast_dial_destroy(station->dial);
  5465. station->dial = NULL;
  5466. ast_free(conf_name);
  5467. return NULL;
  5468. }
  5469. static void sla_ringing_trunk_destroy(struct sla_ringing_trunk *ringing_trunk);
  5470. static void sla_stop_ringing_trunk(struct sla_ringing_trunk *ringing_trunk)
  5471. {
  5472. char buf[80];
  5473. struct sla_station_ref *station_ref;
  5474. snprintf(buf, sizeof(buf), "SLA_%s,K", ringing_trunk->trunk->name);
  5475. admin_exec(NULL, buf);
  5476. sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
  5477. while ((station_ref = AST_LIST_REMOVE_HEAD(&ringing_trunk->timed_out_stations, entry))) {
  5478. ao2_ref(station_ref, -1);
  5479. }
  5480. sla_ringing_trunk_destroy(ringing_trunk);
  5481. }
  5482. static void sla_stop_ringing_station(struct sla_ringing_station *ringing_station,
  5483. enum sla_station_hangup hangup)
  5484. {
  5485. struct sla_ringing_trunk *ringing_trunk;
  5486. struct sla_trunk_ref *trunk_ref;
  5487. struct sla_station_ref *station_ref;
  5488. ast_dial_join(ringing_station->station->dial);
  5489. ast_dial_destroy(ringing_station->station->dial);
  5490. ringing_station->station->dial = NULL;
  5491. if (hangup == SLA_STATION_HANGUP_NORMAL)
  5492. goto done;
  5493. /* If the station is being hung up because of a timeout, then add it to the
  5494. * list of timed out stations on each of the ringing trunks. This is so
  5495. * that when doing further processing to figure out which stations should be
  5496. * ringing, which trunk to answer, determining timeouts, etc., we know which
  5497. * ringing trunks we should ignore. */
  5498. AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
  5499. AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
  5500. if (ringing_trunk->trunk == trunk_ref->trunk)
  5501. break;
  5502. }
  5503. if (!trunk_ref)
  5504. continue;
  5505. if (!(station_ref = sla_create_station_ref(ringing_station->station)))
  5506. continue;
  5507. AST_LIST_INSERT_TAIL(&ringing_trunk->timed_out_stations, station_ref, entry);
  5508. }
  5509. done:
  5510. sla_ringing_station_destroy(ringing_station);
  5511. }
  5512. static void sla_dial_state_callback(struct ast_dial *dial)
  5513. {
  5514. sla_queue_event(SLA_EVENT_DIAL_STATE);
  5515. }
  5516. /*! \brief Check to see if dialing this station already timed out for this ringing trunk
  5517. * \note Assumes sla.lock is locked
  5518. */
  5519. static int sla_check_timed_out_station(const struct sla_ringing_trunk *ringing_trunk,
  5520. const struct sla_station *station)
  5521. {
  5522. struct sla_station_ref *timed_out_station;
  5523. AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, timed_out_station, entry) {
  5524. if (station == timed_out_station->station)
  5525. return 1;
  5526. }
  5527. return 0;
  5528. }
  5529. /*! \brief Choose the highest priority ringing trunk for a station
  5530. * \param station the station
  5531. * \param rm remove the ringing trunk once selected
  5532. * \param trunk_ref a place to store the pointer to this stations reference to
  5533. * the selected trunk
  5534. * \return a pointer to the selected ringing trunk, or NULL if none found
  5535. * \note Assumes that sla.lock is locked
  5536. */
  5537. static struct sla_ringing_trunk *sla_choose_ringing_trunk(struct sla_station *station,
  5538. struct sla_trunk_ref **trunk_ref, int rm)
  5539. {
  5540. struct sla_trunk_ref *s_trunk_ref;
  5541. struct sla_ringing_trunk *ringing_trunk = NULL;
  5542. AST_LIST_TRAVERSE(&station->trunks, s_trunk_ref, entry) {
  5543. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
  5544. /* Make sure this is the trunk we're looking for */
  5545. if (s_trunk_ref->trunk != ringing_trunk->trunk)
  5546. continue;
  5547. /* This trunk on the station is ringing. But, make sure this station
  5548. * didn't already time out while this trunk was ringing. */
  5549. if (sla_check_timed_out_station(ringing_trunk, station))
  5550. continue;
  5551. if (rm)
  5552. AST_LIST_REMOVE_CURRENT(entry);
  5553. if (trunk_ref) {
  5554. ao2_ref(s_trunk_ref, 1);
  5555. *trunk_ref = s_trunk_ref;
  5556. }
  5557. break;
  5558. }
  5559. AST_LIST_TRAVERSE_SAFE_END;
  5560. if (ringing_trunk)
  5561. break;
  5562. }
  5563. return ringing_trunk;
  5564. }
  5565. static void sla_handle_dial_state_event(void)
  5566. {
  5567. struct sla_ringing_station *ringing_station;
  5568. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
  5569. RAII_VAR(struct sla_trunk_ref *, s_trunk_ref, NULL, ao2_cleanup);
  5570. struct sla_ringing_trunk *ringing_trunk = NULL;
  5571. struct run_station_args args;
  5572. enum ast_dial_result dial_res;
  5573. pthread_t dont_care;
  5574. ast_mutex_t cond_lock;
  5575. ast_cond_t cond;
  5576. switch ((dial_res = ast_dial_state(ringing_station->station->dial))) {
  5577. case AST_DIAL_RESULT_HANGUP:
  5578. case AST_DIAL_RESULT_INVALID:
  5579. case AST_DIAL_RESULT_FAILED:
  5580. case AST_DIAL_RESULT_TIMEOUT:
  5581. case AST_DIAL_RESULT_UNANSWERED:
  5582. AST_LIST_REMOVE_CURRENT(entry);
  5583. sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_NORMAL);
  5584. break;
  5585. case AST_DIAL_RESULT_ANSWERED:
  5586. AST_LIST_REMOVE_CURRENT(entry);
  5587. /* Find the appropriate trunk to answer. */
  5588. ast_mutex_lock(&sla.lock);
  5589. ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, &s_trunk_ref, 1);
  5590. ast_mutex_unlock(&sla.lock);
  5591. if (!ringing_trunk) {
  5592. /* This case happens in a bit of a race condition. If two stations answer
  5593. * the outbound call at the same time, the first one will get connected to
  5594. * the trunk. When the second one gets here, it will not see any trunks
  5595. * ringing so we have no idea what to conect it to. So, we just hang up
  5596. * on it. */
  5597. ast_debug(1, "Found no ringing trunk for station '%s' to answer!\n", ringing_station->station->name);
  5598. ast_dial_join(ringing_station->station->dial);
  5599. ast_dial_destroy(ringing_station->station->dial);
  5600. ringing_station->station->dial = NULL;
  5601. sla_ringing_station_destroy(ringing_station);
  5602. break;
  5603. }
  5604. /* Track the channel that answered this trunk */
  5605. s_trunk_ref->chan = ast_dial_answered(ringing_station->station->dial);
  5606. /* Actually answer the trunk */
  5607. answer_trunk_chan(ringing_trunk->trunk->chan);
  5608. sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
  5609. /* Now, start a thread that will connect this station to the trunk. The rest of
  5610. * the code here sets up the thread and ensures that it is able to save the arguments
  5611. * before they are no longer valid since they are allocated on the stack. */
  5612. ao2_ref(s_trunk_ref, 1);
  5613. args.trunk_ref = s_trunk_ref;
  5614. ao2_ref(ringing_station->station, 1);
  5615. args.station = ringing_station->station;
  5616. args.cond = &cond;
  5617. args.cond_lock = &cond_lock;
  5618. sla_ringing_trunk_destroy(ringing_trunk);
  5619. sla_ringing_station_destroy(ringing_station);
  5620. ast_mutex_init(&cond_lock);
  5621. ast_cond_init(&cond, NULL);
  5622. ast_mutex_lock(&cond_lock);
  5623. ast_pthread_create_detached_background(&dont_care, NULL, run_station, &args);
  5624. ast_cond_wait(&cond, &cond_lock);
  5625. ast_mutex_unlock(&cond_lock);
  5626. ast_mutex_destroy(&cond_lock);
  5627. ast_cond_destroy(&cond);
  5628. break;
  5629. case AST_DIAL_RESULT_TRYING:
  5630. case AST_DIAL_RESULT_RINGING:
  5631. case AST_DIAL_RESULT_PROGRESS:
  5632. case AST_DIAL_RESULT_PROCEEDING:
  5633. break;
  5634. }
  5635. if (dial_res == AST_DIAL_RESULT_ANSWERED) {
  5636. /* Queue up reprocessing ringing trunks, and then ringing stations again */
  5637. sla_queue_event(SLA_EVENT_RINGING_TRUNK);
  5638. sla_queue_event(SLA_EVENT_DIAL_STATE);
  5639. break;
  5640. }
  5641. }
  5642. AST_LIST_TRAVERSE_SAFE_END;
  5643. }
  5644. /*! \brief Check to see if this station is already ringing
  5645. * \note Assumes sla.lock is locked
  5646. */
  5647. static int sla_check_ringing_station(const struct sla_station *station)
  5648. {
  5649. struct sla_ringing_station *ringing_station;
  5650. AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_station, entry) {
  5651. if (station == ringing_station->station)
  5652. return 1;
  5653. }
  5654. return 0;
  5655. }
  5656. /*! \brief Check to see if this station has failed to be dialed in the past minute
  5657. * \note assumes sla.lock is locked
  5658. */
  5659. static int sla_check_failed_station(const struct sla_station *station)
  5660. {
  5661. struct sla_failed_station *failed_station;
  5662. int res = 0;
  5663. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.failed_stations, failed_station, entry) {
  5664. if (station != failed_station->station)
  5665. continue;
  5666. if (ast_tvdiff_ms(ast_tvnow(), failed_station->last_try) > 1000) {
  5667. AST_LIST_REMOVE_CURRENT(entry);
  5668. sla_failed_station_destroy(failed_station);
  5669. break;
  5670. }
  5671. res = 1;
  5672. }
  5673. AST_LIST_TRAVERSE_SAFE_END
  5674. return res;
  5675. }
  5676. /*! \brief Ring a station
  5677. * \note Assumes sla.lock is locked
  5678. */
  5679. static int sla_ring_station(struct sla_ringing_trunk *ringing_trunk, struct sla_station *station)
  5680. {
  5681. char *tech, *tech_data;
  5682. struct ast_dial *dial;
  5683. struct sla_ringing_station *ringing_station;
  5684. enum ast_dial_result res;
  5685. int caller_is_saved;
  5686. struct ast_party_caller caller;
  5687. if (!(dial = ast_dial_create()))
  5688. return -1;
  5689. ast_dial_set_state_callback(dial, sla_dial_state_callback);
  5690. tech_data = ast_strdupa(station->device);
  5691. tech = strsep(&tech_data, "/");
  5692. if (ast_dial_append(dial, tech, tech_data, NULL) == -1) {
  5693. ast_dial_destroy(dial);
  5694. return -1;
  5695. }
  5696. /* Do we need to save off the caller ID data? */
  5697. caller_is_saved = 0;
  5698. if (!sla.attempt_callerid) {
  5699. caller_is_saved = 1;
  5700. caller = *ast_channel_caller(ringing_trunk->trunk->chan);
  5701. ast_party_caller_init(ast_channel_caller(ringing_trunk->trunk->chan));
  5702. }
  5703. res = ast_dial_run(dial, ringing_trunk->trunk->chan, 1);
  5704. /* Restore saved caller ID */
  5705. if (caller_is_saved) {
  5706. ast_party_caller_free(ast_channel_caller(ringing_trunk->trunk->chan));
  5707. ast_channel_caller_set(ringing_trunk->trunk->chan, &caller);
  5708. }
  5709. if (res != AST_DIAL_RESULT_TRYING) {
  5710. struct sla_failed_station *failed_station;
  5711. ast_dial_destroy(dial);
  5712. if ((failed_station = sla_create_failed_station(station))) {
  5713. AST_LIST_INSERT_HEAD(&sla.failed_stations, failed_station, entry);
  5714. }
  5715. return -1;
  5716. }
  5717. if (!(ringing_station = sla_create_ringing_station(station))) {
  5718. ast_dial_join(dial);
  5719. ast_dial_destroy(dial);
  5720. return -1;
  5721. }
  5722. station->dial = dial;
  5723. AST_LIST_INSERT_HEAD(&sla.ringing_stations, ringing_station, entry);
  5724. return 0;
  5725. }
  5726. /*! \brief Check to see if a station is in use
  5727. */
  5728. static int sla_check_inuse_station(const struct sla_station *station)
  5729. {
  5730. struct sla_trunk_ref *trunk_ref;
  5731. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  5732. if (trunk_ref->chan)
  5733. return 1;
  5734. }
  5735. return 0;
  5736. }
  5737. static struct sla_trunk_ref *sla_find_trunk_ref(const struct sla_station *station,
  5738. const struct sla_trunk *trunk)
  5739. {
  5740. struct sla_trunk_ref *trunk_ref = NULL;
  5741. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  5742. if (trunk_ref->trunk == trunk)
  5743. break;
  5744. }
  5745. ao2_ref(trunk_ref, 1);
  5746. return trunk_ref;
  5747. }
  5748. /*! \brief Calculate the ring delay for a given ringing trunk on a station
  5749. * \param station the station
  5750. * \param ringing_trunk the trunk. If NULL, the highest priority ringing trunk will be used
  5751. * \return the number of ms left before the delay is complete, or INT_MAX if there is no delay
  5752. */
  5753. static int sla_check_station_delay(struct sla_station *station,
  5754. struct sla_ringing_trunk *ringing_trunk)
  5755. {
  5756. RAII_VAR(struct sla_trunk_ref *, trunk_ref, NULL, ao2_cleanup);
  5757. unsigned int delay = UINT_MAX;
  5758. int time_left, time_elapsed;
  5759. if (!ringing_trunk)
  5760. ringing_trunk = sla_choose_ringing_trunk(station, &trunk_ref, 0);
  5761. else
  5762. trunk_ref = sla_find_trunk_ref(station, ringing_trunk->trunk);
  5763. if (!ringing_trunk || !trunk_ref)
  5764. return delay;
  5765. /* If this station has a ring delay specific to the highest priority
  5766. * ringing trunk, use that. Otherwise, use the ring delay specified
  5767. * globally for the station. */
  5768. delay = trunk_ref->ring_delay;
  5769. if (!delay)
  5770. delay = station->ring_delay;
  5771. if (!delay)
  5772. return INT_MAX;
  5773. time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
  5774. time_left = (delay * 1000) - time_elapsed;
  5775. return time_left;
  5776. }
  5777. /*! \brief Ring stations based on current set of ringing trunks
  5778. * \note Assumes that sla.lock is locked
  5779. */
  5780. static void sla_ring_stations(void)
  5781. {
  5782. struct sla_station_ref *station_ref;
  5783. struct sla_ringing_trunk *ringing_trunk;
  5784. /* Make sure that every station that uses at least one of the ringing
  5785. * trunks, is ringing. */
  5786. AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
  5787. AST_LIST_TRAVERSE(&ringing_trunk->trunk->stations, station_ref, entry) {
  5788. int time_left;
  5789. /* Is this station already ringing? */
  5790. if (sla_check_ringing_station(station_ref->station))
  5791. continue;
  5792. /* Is this station already in a call? */
  5793. if (sla_check_inuse_station(station_ref->station))
  5794. continue;
  5795. /* Did we fail to dial this station earlier? If so, has it been
  5796. * a minute since we tried? */
  5797. if (sla_check_failed_station(station_ref->station))
  5798. continue;
  5799. /* If this station already timed out while this trunk was ringing,
  5800. * do not dial it again for this ringing trunk. */
  5801. if (sla_check_timed_out_station(ringing_trunk, station_ref->station))
  5802. continue;
  5803. /* Check for a ring delay in progress */
  5804. time_left = sla_check_station_delay(station_ref->station, ringing_trunk);
  5805. if (time_left != INT_MAX && time_left > 0)
  5806. continue;
  5807. /* It is time to make this station begin to ring. Do it! */
  5808. sla_ring_station(ringing_trunk, station_ref->station);
  5809. }
  5810. }
  5811. /* Now, all of the stations that should be ringing, are ringing. */
  5812. }
  5813. static void sla_hangup_stations(void)
  5814. {
  5815. struct sla_trunk_ref *trunk_ref;
  5816. struct sla_ringing_station *ringing_station;
  5817. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
  5818. AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
  5819. struct sla_ringing_trunk *ringing_trunk;
  5820. ast_mutex_lock(&sla.lock);
  5821. AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
  5822. if (trunk_ref->trunk == ringing_trunk->trunk)
  5823. break;
  5824. }
  5825. ast_mutex_unlock(&sla.lock);
  5826. if (ringing_trunk)
  5827. break;
  5828. }
  5829. if (!trunk_ref) {
  5830. AST_LIST_REMOVE_CURRENT(entry);
  5831. ast_dial_join(ringing_station->station->dial);
  5832. ast_dial_destroy(ringing_station->station->dial);
  5833. ringing_station->station->dial = NULL;
  5834. sla_ringing_station_destroy(ringing_station);
  5835. }
  5836. }
  5837. AST_LIST_TRAVERSE_SAFE_END
  5838. }
  5839. static void sla_handle_ringing_trunk_event(void)
  5840. {
  5841. ast_mutex_lock(&sla.lock);
  5842. sla_ring_stations();
  5843. ast_mutex_unlock(&sla.lock);
  5844. /* Find stations that shouldn't be ringing anymore. */
  5845. sla_hangup_stations();
  5846. }
  5847. static void sla_handle_hold_event(struct sla_event *event)
  5848. {
  5849. ast_atomic_fetchadd_int((int *) &event->trunk_ref->trunk->hold_stations, 1);
  5850. event->trunk_ref->state = SLA_TRUNK_STATE_ONHOLD_BYME;
  5851. ast_devstate_changed(AST_DEVICE_ONHOLD, AST_DEVSTATE_CACHABLE, "SLA:%s_%s",
  5852. event->station->name, event->trunk_ref->trunk->name);
  5853. sla_change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_ONHOLD,
  5854. INACTIVE_TRUNK_REFS, event->trunk_ref);
  5855. if (event->trunk_ref->trunk->active_stations == 1) {
  5856. /* The station putting it on hold is the only one on the call, so start
  5857. * Music on hold to the trunk. */
  5858. event->trunk_ref->trunk->on_hold = 1;
  5859. ast_indicate(event->trunk_ref->trunk->chan, AST_CONTROL_HOLD);
  5860. }
  5861. ast_softhangup(event->trunk_ref->chan, AST_SOFTHANGUP_DEV);
  5862. event->trunk_ref->chan = NULL;
  5863. }
  5864. /*! \brief Process trunk ring timeouts
  5865. * \note Called with sla.lock locked
  5866. * \return non-zero if a change to the ringing trunks was made
  5867. */
  5868. static int sla_calc_trunk_timeouts(unsigned int *timeout)
  5869. {
  5870. struct sla_ringing_trunk *ringing_trunk;
  5871. int res = 0;
  5872. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
  5873. int time_left, time_elapsed;
  5874. if (!ringing_trunk->trunk->ring_timeout)
  5875. continue;
  5876. time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
  5877. time_left = (ringing_trunk->trunk->ring_timeout * 1000) - time_elapsed;
  5878. if (time_left <= 0) {
  5879. pbx_builtin_setvar_helper(ringing_trunk->trunk->chan, "SLATRUNK_STATUS", "RINGTIMEOUT");
  5880. AST_LIST_REMOVE_CURRENT(entry);
  5881. sla_stop_ringing_trunk(ringing_trunk);
  5882. res = 1;
  5883. continue;
  5884. }
  5885. if (time_left < *timeout)
  5886. *timeout = time_left;
  5887. }
  5888. AST_LIST_TRAVERSE_SAFE_END;
  5889. return res;
  5890. }
  5891. /*! \brief Process station ring timeouts
  5892. * \note Called with sla.lock locked
  5893. * \return non-zero if a change to the ringing stations was made
  5894. */
  5895. static int sla_calc_station_timeouts(unsigned int *timeout)
  5896. {
  5897. struct sla_ringing_trunk *ringing_trunk;
  5898. struct sla_ringing_station *ringing_station;
  5899. int res = 0;
  5900. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
  5901. unsigned int ring_timeout = 0;
  5902. int time_elapsed, time_left = INT_MAX, final_trunk_time_left = INT_MIN;
  5903. struct sla_trunk_ref *trunk_ref;
  5904. /* If there are any ring timeouts specified for a specific trunk
  5905. * on the station, then use the highest per-trunk ring timeout.
  5906. * Otherwise, use the ring timeout set for the entire station. */
  5907. AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
  5908. struct sla_station_ref *station_ref;
  5909. int trunk_time_elapsed, trunk_time_left;
  5910. AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
  5911. if (ringing_trunk->trunk == trunk_ref->trunk)
  5912. break;
  5913. }
  5914. if (!ringing_trunk)
  5915. continue;
  5916. /* If there is a trunk that is ringing without a timeout, then the
  5917. * only timeout that could matter is a global station ring timeout. */
  5918. if (!trunk_ref->ring_timeout)
  5919. break;
  5920. /* This trunk on this station is ringing and has a timeout.
  5921. * However, make sure this trunk isn't still ringing from a
  5922. * previous timeout. If so, don't consider it. */
  5923. AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, station_ref, entry) {
  5924. if (station_ref->station == ringing_station->station)
  5925. break;
  5926. }
  5927. if (station_ref)
  5928. continue;
  5929. trunk_time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
  5930. trunk_time_left = (trunk_ref->ring_timeout * 1000) - trunk_time_elapsed;
  5931. if (trunk_time_left > final_trunk_time_left)
  5932. final_trunk_time_left = trunk_time_left;
  5933. }
  5934. /* No timeout was found for ringing trunks, and no timeout for the entire station */
  5935. if (final_trunk_time_left == INT_MIN && !ringing_station->station->ring_timeout)
  5936. continue;
  5937. /* Compute how much time is left for a global station timeout */
  5938. if (ringing_station->station->ring_timeout) {
  5939. ring_timeout = ringing_station->station->ring_timeout;
  5940. time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_station->ring_begin);
  5941. time_left = (ring_timeout * 1000) - time_elapsed;
  5942. }
  5943. /* If the time left based on the per-trunk timeouts is smaller than the
  5944. * global station ring timeout, use that. */
  5945. if (final_trunk_time_left > INT_MIN && final_trunk_time_left < time_left)
  5946. time_left = final_trunk_time_left;
  5947. /* If there is no time left, the station needs to stop ringing */
  5948. if (time_left <= 0) {
  5949. AST_LIST_REMOVE_CURRENT(entry);
  5950. sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_TIMEOUT);
  5951. res = 1;
  5952. continue;
  5953. }
  5954. /* There is still some time left for this station to ring, so save that
  5955. * timeout if it is the first event scheduled to occur */
  5956. if (time_left < *timeout)
  5957. *timeout = time_left;
  5958. }
  5959. AST_LIST_TRAVERSE_SAFE_END;
  5960. return res;
  5961. }
  5962. /*! \brief Calculate the ring delay for a station
  5963. * \note Assumes sla.lock is locked
  5964. */
  5965. static int sla_calc_station_delays(unsigned int *timeout)
  5966. {
  5967. struct sla_station *station;
  5968. int res = 0;
  5969. struct ao2_iterator i;
  5970. i = ao2_iterator_init(sla_stations, 0);
  5971. for (; (station = ao2_iterator_next(&i)); ao2_ref(station, -1)) {
  5972. struct sla_ringing_trunk *ringing_trunk;
  5973. int time_left;
  5974. /* Ignore stations already ringing */
  5975. if (sla_check_ringing_station(station))
  5976. continue;
  5977. /* Ignore stations already on a call */
  5978. if (sla_check_inuse_station(station))
  5979. continue;
  5980. /* Ignore stations that don't have one of their trunks ringing */
  5981. if (!(ringing_trunk = sla_choose_ringing_trunk(station, NULL, 0)))
  5982. continue;
  5983. if ((time_left = sla_check_station_delay(station, ringing_trunk)) == INT_MAX)
  5984. continue;
  5985. /* If there is no time left, then the station needs to start ringing.
  5986. * Return non-zero so that an event will be queued up an event to
  5987. * make that happen. */
  5988. if (time_left <= 0) {
  5989. res = 1;
  5990. continue;
  5991. }
  5992. if (time_left < *timeout)
  5993. *timeout = time_left;
  5994. }
  5995. ao2_iterator_destroy(&i);
  5996. return res;
  5997. }
  5998. /*! \brief Calculate the time until the next known event
  5999. * \note Called with sla.lock locked */
  6000. static int sla_process_timers(struct timespec *ts)
  6001. {
  6002. unsigned int timeout = UINT_MAX;
  6003. struct timeval wait;
  6004. unsigned int change_made = 0;
  6005. /* Check for ring timeouts on ringing trunks */
  6006. if (sla_calc_trunk_timeouts(&timeout))
  6007. change_made = 1;
  6008. /* Check for ring timeouts on ringing stations */
  6009. if (sla_calc_station_timeouts(&timeout))
  6010. change_made = 1;
  6011. /* Check for station ring delays */
  6012. if (sla_calc_station_delays(&timeout))
  6013. change_made = 1;
  6014. /* queue reprocessing of ringing trunks */
  6015. if (change_made)
  6016. sla_queue_event_nolock(SLA_EVENT_RINGING_TRUNK);
  6017. /* No timeout */
  6018. if (timeout == UINT_MAX)
  6019. return 0;
  6020. if (ts) {
  6021. wait = ast_tvadd(ast_tvnow(), ast_samp2tv(timeout, 1000));
  6022. ts->tv_sec = wait.tv_sec;
  6023. ts->tv_nsec = wait.tv_usec * 1000;
  6024. }
  6025. return 1;
  6026. }
  6027. static void sla_event_destroy(struct sla_event *event)
  6028. {
  6029. if (event->trunk_ref) {
  6030. ao2_ref(event->trunk_ref, -1);
  6031. event->trunk_ref = NULL;
  6032. }
  6033. if (event->station) {
  6034. ao2_ref(event->station, -1);
  6035. event->station = NULL;
  6036. }
  6037. ast_free(event);
  6038. }
  6039. static void *sla_thread(void *data)
  6040. {
  6041. struct sla_failed_station *failed_station;
  6042. struct sla_ringing_station *ringing_station;
  6043. ast_mutex_lock(&sla.lock);
  6044. while (!sla.stop) {
  6045. struct sla_event *event;
  6046. struct timespec ts = { 0, };
  6047. unsigned int have_timeout = 0;
  6048. if (AST_LIST_EMPTY(&sla.event_q)) {
  6049. if ((have_timeout = sla_process_timers(&ts)))
  6050. ast_cond_timedwait(&sla.cond, &sla.lock, &ts);
  6051. else
  6052. ast_cond_wait(&sla.cond, &sla.lock);
  6053. if (sla.stop)
  6054. break;
  6055. }
  6056. if (have_timeout)
  6057. sla_process_timers(NULL);
  6058. while ((event = AST_LIST_REMOVE_HEAD(&sla.event_q, entry))) {
  6059. ast_mutex_unlock(&sla.lock);
  6060. switch (event->type) {
  6061. case SLA_EVENT_HOLD:
  6062. sla_handle_hold_event(event);
  6063. break;
  6064. case SLA_EVENT_DIAL_STATE:
  6065. sla_handle_dial_state_event();
  6066. break;
  6067. case SLA_EVENT_RINGING_TRUNK:
  6068. sla_handle_ringing_trunk_event();
  6069. break;
  6070. }
  6071. sla_event_destroy(event);
  6072. ast_mutex_lock(&sla.lock);
  6073. }
  6074. }
  6075. ast_mutex_unlock(&sla.lock);
  6076. while ((ringing_station = AST_LIST_REMOVE_HEAD(&sla.ringing_stations, entry))) {
  6077. sla_ringing_station_destroy(ringing_station);
  6078. }
  6079. while ((failed_station = AST_LIST_REMOVE_HEAD(&sla.failed_stations, entry))) {
  6080. sla_failed_station_destroy(failed_station);
  6081. }
  6082. return NULL;
  6083. }
  6084. struct dial_trunk_args {
  6085. struct sla_trunk_ref *trunk_ref;
  6086. struct sla_station *station;
  6087. ast_mutex_t *cond_lock;
  6088. ast_cond_t *cond;
  6089. };
  6090. static void *dial_trunk(void *data)
  6091. {
  6092. struct dial_trunk_args *args = data;
  6093. struct ast_dial *dial;
  6094. char *tech, *tech_data;
  6095. enum ast_dial_result dial_res;
  6096. char conf_name[MAX_CONFNUM];
  6097. struct ast_conference *conf;
  6098. struct ast_flags64 conf_flags = { 0 };
  6099. RAII_VAR(struct sla_trunk_ref *, trunk_ref, args->trunk_ref, ao2_cleanup);
  6100. RAII_VAR(struct sla_station *, station, args->station, ao2_cleanup);
  6101. int caller_is_saved;
  6102. struct ast_party_caller caller;
  6103. int last_state = 0;
  6104. int current_state = 0;
  6105. if (!(dial = ast_dial_create())) {
  6106. ast_mutex_lock(args->cond_lock);
  6107. ast_cond_signal(args->cond);
  6108. ast_mutex_unlock(args->cond_lock);
  6109. return NULL;
  6110. }
  6111. tech_data = ast_strdupa(trunk_ref->trunk->device);
  6112. tech = strsep(&tech_data, "/");
  6113. if (ast_dial_append(dial, tech, tech_data, NULL) == -1) {
  6114. ast_mutex_lock(args->cond_lock);
  6115. ast_cond_signal(args->cond);
  6116. ast_mutex_unlock(args->cond_lock);
  6117. ast_dial_destroy(dial);
  6118. return NULL;
  6119. }
  6120. /* Do we need to save of the caller ID data? */
  6121. caller_is_saved = 0;
  6122. if (!sla.attempt_callerid) {
  6123. caller_is_saved = 1;
  6124. caller = *ast_channel_caller(trunk_ref->chan);
  6125. ast_party_caller_init(ast_channel_caller(trunk_ref->chan));
  6126. }
  6127. dial_res = ast_dial_run(dial, trunk_ref->chan, 1);
  6128. /* Restore saved caller ID */
  6129. if (caller_is_saved) {
  6130. ast_party_caller_free(ast_channel_caller(trunk_ref->chan));
  6131. ast_channel_caller_set(trunk_ref->chan, &caller);
  6132. }
  6133. if (dial_res != AST_DIAL_RESULT_TRYING) {
  6134. ast_mutex_lock(args->cond_lock);
  6135. ast_cond_signal(args->cond);
  6136. ast_mutex_unlock(args->cond_lock);
  6137. ast_dial_destroy(dial);
  6138. return NULL;
  6139. }
  6140. for (;;) {
  6141. unsigned int done = 0;
  6142. switch ((dial_res = ast_dial_state(dial))) {
  6143. case AST_DIAL_RESULT_ANSWERED:
  6144. trunk_ref->trunk->chan = ast_dial_answered(dial);
  6145. case AST_DIAL_RESULT_HANGUP:
  6146. case AST_DIAL_RESULT_INVALID:
  6147. case AST_DIAL_RESULT_FAILED:
  6148. case AST_DIAL_RESULT_TIMEOUT:
  6149. case AST_DIAL_RESULT_UNANSWERED:
  6150. done = 1;
  6151. break;
  6152. case AST_DIAL_RESULT_TRYING:
  6153. current_state = AST_CONTROL_PROGRESS;
  6154. break;
  6155. case AST_DIAL_RESULT_RINGING:
  6156. case AST_DIAL_RESULT_PROGRESS:
  6157. case AST_DIAL_RESULT_PROCEEDING:
  6158. current_state = AST_CONTROL_RINGING;
  6159. break;
  6160. }
  6161. if (done)
  6162. break;
  6163. /* check that SLA station that originated trunk call is still alive */
  6164. if (station && ast_device_state(station->device) == AST_DEVICE_NOT_INUSE) {
  6165. ast_debug(3, "Originating station device %s no longer active\n", station->device);
  6166. trunk_ref->trunk->chan = NULL;
  6167. break;
  6168. }
  6169. /* If trunk line state changed, send indication back to originating SLA Station channel */
  6170. if (current_state != last_state) {
  6171. ast_debug(3, "Indicating State Change %d to channel %s\n", current_state, ast_channel_name(trunk_ref->chan));
  6172. ast_indicate(trunk_ref->chan, current_state);
  6173. last_state = current_state;
  6174. }
  6175. /* avoid tight loop... sleep for 1/10th second */
  6176. ast_safe_sleep(trunk_ref->chan, 100);
  6177. }
  6178. if (!trunk_ref->trunk->chan) {
  6179. ast_mutex_lock(args->cond_lock);
  6180. ast_cond_signal(args->cond);
  6181. ast_mutex_unlock(args->cond_lock);
  6182. ast_dial_join(dial);
  6183. ast_dial_destroy(dial);
  6184. return NULL;
  6185. }
  6186. snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
  6187. ast_set_flag64(&conf_flags,
  6188. CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_MARKEDUSER |
  6189. CONFFLAG_PASS_DTMF | CONFFLAG_SLA_TRUNK);
  6190. conf = build_conf(conf_name, "", "", 1, 1, 1, trunk_ref->trunk->chan, NULL);
  6191. ast_mutex_lock(args->cond_lock);
  6192. ast_cond_signal(args->cond);
  6193. ast_mutex_unlock(args->cond_lock);
  6194. if (conf) {
  6195. conf_run(trunk_ref->trunk->chan, conf, &conf_flags, NULL);
  6196. dispose_conf(conf);
  6197. conf = NULL;
  6198. }
  6199. /* If the trunk is going away, it is definitely now IDLE. */
  6200. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
  6201. trunk_ref->trunk->chan = NULL;
  6202. trunk_ref->trunk->on_hold = 0;
  6203. ast_dial_join(dial);
  6204. ast_dial_destroy(dial);
  6205. return NULL;
  6206. }
  6207. /*!
  6208. * \brief For a given station, choose the highest priority idle trunk
  6209. * \pre sla_station is locked
  6210. */
  6211. static struct sla_trunk_ref *sla_choose_idle_trunk(const struct sla_station *station)
  6212. {
  6213. struct sla_trunk_ref *trunk_ref = NULL;
  6214. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  6215. if (trunk_ref->state == SLA_TRUNK_STATE_IDLE) {
  6216. ao2_ref(trunk_ref, 1);
  6217. break;
  6218. }
  6219. }
  6220. return trunk_ref;
  6221. }
  6222. static int sla_station_exec(struct ast_channel *chan, const char *data)
  6223. {
  6224. char *station_name, *trunk_name;
  6225. RAII_VAR(struct sla_station *, station, NULL, ao2_cleanup);
  6226. RAII_VAR(struct sla_trunk_ref *, trunk_ref, NULL, ao2_cleanup);
  6227. char conf_name[MAX_CONFNUM];
  6228. struct ast_flags64 conf_flags = { 0 };
  6229. struct ast_conference *conf;
  6230. if (ast_strlen_zero(data)) {
  6231. ast_log(LOG_WARNING, "Invalid Arguments to SLAStation!\n");
  6232. pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
  6233. return 0;
  6234. }
  6235. trunk_name = ast_strdupa(data);
  6236. station_name = strsep(&trunk_name, "_");
  6237. if (ast_strlen_zero(station_name)) {
  6238. ast_log(LOG_WARNING, "Invalid Arguments to SLAStation!\n");
  6239. pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
  6240. return 0;
  6241. }
  6242. station = sla_find_station(station_name);
  6243. if (!station) {
  6244. ast_log(LOG_WARNING, "Station '%s' not found!\n", station_name);
  6245. pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "FAILURE");
  6246. return 0;
  6247. }
  6248. ao2_lock(station);
  6249. if (!ast_strlen_zero(trunk_name)) {
  6250. trunk_ref = sla_find_trunk_ref_byname(station, trunk_name);
  6251. } else {
  6252. trunk_ref = sla_choose_idle_trunk(station);
  6253. }
  6254. ao2_unlock(station);
  6255. if (!trunk_ref) {
  6256. if (ast_strlen_zero(trunk_name))
  6257. ast_log(LOG_NOTICE, "No trunks available for call.\n");
  6258. else {
  6259. ast_log(LOG_NOTICE, "Can't join existing call on trunk "
  6260. "'%s' due to access controls.\n", trunk_name);
  6261. }
  6262. pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
  6263. return 0;
  6264. }
  6265. if (trunk_ref->state == SLA_TRUNK_STATE_ONHOLD_BYME) {
  6266. if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->hold_stations) == 1)
  6267. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
  6268. else {
  6269. trunk_ref->state = SLA_TRUNK_STATE_UP;
  6270. ast_devstate_changed(AST_DEVICE_INUSE, AST_DEVSTATE_CACHABLE,
  6271. "SLA:%s_%s", station->name, trunk_ref->trunk->name);
  6272. }
  6273. } else if (trunk_ref->state == SLA_TRUNK_STATE_RINGING) {
  6274. struct sla_ringing_trunk *ringing_trunk;
  6275. ast_mutex_lock(&sla.lock);
  6276. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
  6277. if (ringing_trunk->trunk == trunk_ref->trunk) {
  6278. AST_LIST_REMOVE_CURRENT(entry);
  6279. break;
  6280. }
  6281. }
  6282. AST_LIST_TRAVERSE_SAFE_END
  6283. ast_mutex_unlock(&sla.lock);
  6284. if (ringing_trunk) {
  6285. answer_trunk_chan(ringing_trunk->trunk->chan);
  6286. sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
  6287. sla_ringing_trunk_destroy(ringing_trunk);
  6288. /* Queue up reprocessing ringing trunks, and then ringing stations again */
  6289. sla_queue_event(SLA_EVENT_RINGING_TRUNK);
  6290. sla_queue_event(SLA_EVENT_DIAL_STATE);
  6291. }
  6292. }
  6293. trunk_ref->chan = chan;
  6294. if (!trunk_ref->trunk->chan) {
  6295. ast_mutex_t cond_lock;
  6296. ast_cond_t cond;
  6297. pthread_t dont_care;
  6298. struct dial_trunk_args args = {
  6299. .trunk_ref = trunk_ref,
  6300. .station = station,
  6301. .cond_lock = &cond_lock,
  6302. .cond = &cond,
  6303. };
  6304. ao2_ref(trunk_ref, 1);
  6305. ao2_ref(station, 1);
  6306. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
  6307. /* Create a thread to dial the trunk and dump it into the conference.
  6308. * However, we want to wait until the trunk has been dialed and the
  6309. * conference is created before continuing on here. */
  6310. ast_autoservice_start(chan);
  6311. ast_mutex_init(&cond_lock);
  6312. ast_cond_init(&cond, NULL);
  6313. ast_mutex_lock(&cond_lock);
  6314. ast_pthread_create_detached_background(&dont_care, NULL, dial_trunk, &args);
  6315. ast_cond_wait(&cond, &cond_lock);
  6316. ast_mutex_unlock(&cond_lock);
  6317. ast_mutex_destroy(&cond_lock);
  6318. ast_cond_destroy(&cond);
  6319. ast_autoservice_stop(chan);
  6320. if (!trunk_ref->trunk->chan) {
  6321. ast_debug(1, "Trunk didn't get created. chan: %lx\n", (unsigned long) trunk_ref->trunk->chan);
  6322. pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
  6323. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
  6324. trunk_ref->chan = NULL;
  6325. return 0;
  6326. }
  6327. }
  6328. if (ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1) == 0 &&
  6329. trunk_ref->trunk->on_hold) {
  6330. trunk_ref->trunk->on_hold = 0;
  6331. ast_indicate(trunk_ref->trunk->chan, AST_CONTROL_UNHOLD);
  6332. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
  6333. }
  6334. snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
  6335. ast_set_flag64(&conf_flags,
  6336. CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
  6337. ast_answer(chan);
  6338. conf = build_conf(conf_name, "", "", 0, 0, 1, chan, NULL);
  6339. if (conf) {
  6340. conf_run(chan, conf, &conf_flags, NULL);
  6341. dispose_conf(conf);
  6342. conf = NULL;
  6343. }
  6344. trunk_ref->chan = NULL;
  6345. if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
  6346. trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
  6347. strncat(conf_name, ",K", sizeof(conf_name) - strlen(conf_name) - 1);
  6348. admin_exec(NULL, conf_name);
  6349. trunk_ref->trunk->hold_stations = 0;
  6350. sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
  6351. }
  6352. pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "SUCCESS");
  6353. return 0;
  6354. }
  6355. static void sla_trunk_ref_destructor(void *obj)
  6356. {
  6357. struct sla_trunk_ref *trunk_ref = obj;
  6358. if (trunk_ref->trunk) {
  6359. ao2_ref(trunk_ref->trunk, -1);
  6360. trunk_ref->trunk = NULL;
  6361. }
  6362. }
  6363. static struct sla_trunk_ref *create_trunk_ref(struct sla_trunk *trunk)
  6364. {
  6365. struct sla_trunk_ref *trunk_ref;
  6366. if (!(trunk_ref = ao2_alloc(sizeof(*trunk_ref), sla_trunk_ref_destructor))) {
  6367. return NULL;
  6368. }
  6369. ao2_ref(trunk, 1);
  6370. trunk_ref->trunk = trunk;
  6371. return trunk_ref;
  6372. }
  6373. static struct sla_ringing_trunk *queue_ringing_trunk(struct sla_trunk *trunk)
  6374. {
  6375. struct sla_ringing_trunk *ringing_trunk;
  6376. if (!(ringing_trunk = ast_calloc(1, sizeof(*ringing_trunk)))) {
  6377. return NULL;
  6378. }
  6379. ao2_ref(trunk, 1);
  6380. ringing_trunk->trunk = trunk;
  6381. ringing_trunk->ring_begin = ast_tvnow();
  6382. sla_change_trunk_state(trunk, SLA_TRUNK_STATE_RINGING, ALL_TRUNK_REFS, NULL);
  6383. ast_mutex_lock(&sla.lock);
  6384. AST_LIST_INSERT_HEAD(&sla.ringing_trunks, ringing_trunk, entry);
  6385. ast_mutex_unlock(&sla.lock);
  6386. sla_queue_event(SLA_EVENT_RINGING_TRUNK);
  6387. return ringing_trunk;
  6388. }
  6389. static void sla_ringing_trunk_destroy(struct sla_ringing_trunk *ringing_trunk)
  6390. {
  6391. if (ringing_trunk->trunk) {
  6392. ao2_ref(ringing_trunk->trunk, -1);
  6393. ringing_trunk->trunk = NULL;
  6394. }
  6395. ast_free(ringing_trunk);
  6396. }
  6397. enum {
  6398. SLA_TRUNK_OPT_MOH = (1 << 0),
  6399. };
  6400. enum {
  6401. SLA_TRUNK_OPT_ARG_MOH_CLASS = 0,
  6402. SLA_TRUNK_OPT_ARG_ARRAY_SIZE = 1,
  6403. };
  6404. AST_APP_OPTIONS(sla_trunk_opts, BEGIN_OPTIONS
  6405. AST_APP_OPTION_ARG('M', SLA_TRUNK_OPT_MOH, SLA_TRUNK_OPT_ARG_MOH_CLASS),
  6406. END_OPTIONS );
  6407. static int sla_trunk_exec(struct ast_channel *chan, const char *data)
  6408. {
  6409. char conf_name[MAX_CONFNUM];
  6410. struct ast_conference *conf;
  6411. struct ast_flags64 conf_flags = { 0 };
  6412. RAII_VAR(struct sla_trunk *, trunk, NULL, ao2_cleanup);
  6413. struct sla_ringing_trunk *ringing_trunk;
  6414. AST_DECLARE_APP_ARGS(args,
  6415. AST_APP_ARG(trunk_name);
  6416. AST_APP_ARG(options);
  6417. );
  6418. char *opts[SLA_TRUNK_OPT_ARG_ARRAY_SIZE] = { NULL, };
  6419. struct ast_flags opt_flags = { 0 };
  6420. char *parse;
  6421. if (ast_strlen_zero(data)) {
  6422. ast_log(LOG_ERROR, "The SLATrunk application requires an argument, the trunk name\n");
  6423. return -1;
  6424. }
  6425. parse = ast_strdupa(data);
  6426. AST_STANDARD_APP_ARGS(args, parse);
  6427. if (args.argc == 2) {
  6428. if (ast_app_parse_options(sla_trunk_opts, &opt_flags, opts, args.options)) {
  6429. ast_log(LOG_ERROR, "Error parsing options for SLATrunk\n");
  6430. return -1;
  6431. }
  6432. }
  6433. trunk = sla_find_trunk(args.trunk_name);
  6434. if (!trunk) {
  6435. ast_log(LOG_ERROR, "SLA Trunk '%s' not found!\n", args.trunk_name);
  6436. pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
  6437. return 0;
  6438. }
  6439. if (trunk->chan) {
  6440. ast_log(LOG_ERROR, "Call came in on %s, but the trunk is already in use!\n",
  6441. args.trunk_name);
  6442. pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
  6443. return 0;
  6444. }
  6445. trunk->chan = chan;
  6446. if (!(ringing_trunk = queue_ringing_trunk(trunk))) {
  6447. pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
  6448. return 0;
  6449. }
  6450. snprintf(conf_name, sizeof(conf_name), "SLA_%s", args.trunk_name);
  6451. conf = build_conf(conf_name, "", "", 1, 1, 1, chan, NULL);
  6452. if (!conf) {
  6453. pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
  6454. return 0;
  6455. }
  6456. ast_set_flag64(&conf_flags,
  6457. CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_MARKEDUSER | CONFFLAG_PASS_DTMF | CONFFLAG_NO_AUDIO_UNTIL_UP);
  6458. if (ast_test_flag(&opt_flags, SLA_TRUNK_OPT_MOH)) {
  6459. ast_indicate(chan, -1);
  6460. ast_set_flag64(&conf_flags, CONFFLAG_MOH);
  6461. } else
  6462. ast_indicate(chan, AST_CONTROL_RINGING);
  6463. conf_run(chan, conf, &conf_flags, opts);
  6464. dispose_conf(conf);
  6465. conf = NULL;
  6466. trunk->chan = NULL;
  6467. trunk->on_hold = 0;
  6468. sla_change_trunk_state(trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
  6469. if (!pbx_builtin_getvar_helper(chan, "SLATRUNK_STATUS"))
  6470. pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "SUCCESS");
  6471. /* Remove the entry from the list of ringing trunks if it is still there. */
  6472. ast_mutex_lock(&sla.lock);
  6473. AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
  6474. if (ringing_trunk->trunk == trunk) {
  6475. AST_LIST_REMOVE_CURRENT(entry);
  6476. break;
  6477. }
  6478. }
  6479. AST_LIST_TRAVERSE_SAFE_END;
  6480. ast_mutex_unlock(&sla.lock);
  6481. if (ringing_trunk) {
  6482. sla_ringing_trunk_destroy(ringing_trunk);
  6483. pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "UNANSWERED");
  6484. /* Queue reprocessing of ringing trunks to make stations stop ringing
  6485. * that shouldn't be ringing after this trunk stopped. */
  6486. sla_queue_event(SLA_EVENT_RINGING_TRUNK);
  6487. }
  6488. return 0;
  6489. }
  6490. static enum ast_device_state sla_state(const char *data)
  6491. {
  6492. char *buf, *station_name, *trunk_name;
  6493. RAII_VAR(struct sla_station *, station, NULL, ao2_cleanup);
  6494. struct sla_trunk_ref *trunk_ref;
  6495. enum ast_device_state res = AST_DEVICE_INVALID;
  6496. trunk_name = buf = ast_strdupa(data);
  6497. station_name = strsep(&trunk_name, "_");
  6498. station = sla_find_station(station_name);
  6499. if (station) {
  6500. ao2_lock(station);
  6501. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  6502. if (!strcasecmp(trunk_name, trunk_ref->trunk->name)) {
  6503. res = sla_state_to_devstate(trunk_ref->state);
  6504. break;
  6505. }
  6506. }
  6507. ao2_unlock(station);
  6508. }
  6509. if (res == AST_DEVICE_INVALID) {
  6510. ast_log(LOG_ERROR, "Could not determine state for trunk %s on station %s!\n",
  6511. trunk_name, station_name);
  6512. }
  6513. return res;
  6514. }
  6515. static int sla_trunk_release_refs(void *obj, void *arg, int flags)
  6516. {
  6517. struct sla_trunk *trunk = obj;
  6518. struct sla_station_ref *station_ref;
  6519. while ((station_ref = AST_LIST_REMOVE_HEAD(&trunk->stations, entry))) {
  6520. ao2_ref(station_ref, -1);
  6521. }
  6522. return 0;
  6523. }
  6524. static int sla_station_release_refs(void *obj, void *arg, int flags)
  6525. {
  6526. struct sla_station *station = obj;
  6527. struct sla_trunk_ref *trunk_ref;
  6528. while ((trunk_ref = AST_LIST_REMOVE_HEAD(&station->trunks, entry))) {
  6529. ao2_ref(trunk_ref, -1);
  6530. }
  6531. return 0;
  6532. }
  6533. static void sla_station_destructor(void *obj)
  6534. {
  6535. struct sla_station *station = obj;
  6536. ast_debug(1, "sla_station destructor for '%s'\n", station->name);
  6537. if (!ast_strlen_zero(station->autocontext)) {
  6538. struct sla_trunk_ref *trunk_ref;
  6539. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  6540. char exten[AST_MAX_EXTENSION];
  6541. char hint[AST_MAX_APP];
  6542. snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
  6543. snprintf(hint, sizeof(hint), "SLA:%s", exten);
  6544. ast_context_remove_extension(station->autocontext, exten,
  6545. 1, sla_registrar);
  6546. ast_context_remove_extension(station->autocontext, hint,
  6547. PRIORITY_HINT, sla_registrar);
  6548. }
  6549. }
  6550. sla_station_release_refs(station, NULL, 0);
  6551. ast_string_field_free_memory(station);
  6552. }
  6553. static int sla_trunk_cmp(void *obj, void *arg, int flags)
  6554. {
  6555. struct sla_trunk *trunk = obj, *trunk2 = arg;
  6556. return !strcasecmp(trunk->name, trunk2->name) ? CMP_MATCH | CMP_STOP : 0;
  6557. }
  6558. static int sla_station_cmp(void *obj, void *arg, int flags)
  6559. {
  6560. struct sla_station *station = obj, *station2 = arg;
  6561. return !strcasecmp(station->name, station2->name) ? CMP_MATCH | CMP_STOP : 0;
  6562. }
  6563. static void sla_destroy(void)
  6564. {
  6565. if (sla.thread != AST_PTHREADT_NULL) {
  6566. ast_mutex_lock(&sla.lock);
  6567. sla.stop = 1;
  6568. ast_cond_signal(&sla.cond);
  6569. ast_mutex_unlock(&sla.lock);
  6570. pthread_join(sla.thread, NULL);
  6571. }
  6572. /* Drop any created contexts from the dialplan */
  6573. ast_context_destroy(NULL, sla_registrar);
  6574. ast_mutex_destroy(&sla.lock);
  6575. ast_cond_destroy(&sla.cond);
  6576. ao2_callback(sla_trunks, 0, sla_trunk_release_refs, NULL);
  6577. ao2_callback(sla_stations, 0, sla_station_release_refs, NULL);
  6578. ao2_ref(sla_trunks, -1);
  6579. sla_trunks = NULL;
  6580. ao2_ref(sla_stations, -1);
  6581. sla_stations = NULL;
  6582. }
  6583. static int sla_check_device(const char *device)
  6584. {
  6585. char *tech, *tech_data;
  6586. tech_data = ast_strdupa(device);
  6587. tech = strsep(&tech_data, "/");
  6588. if (ast_strlen_zero(tech) || ast_strlen_zero(tech_data))
  6589. return -1;
  6590. return 0;
  6591. }
  6592. static void sla_trunk_destructor(void *obj)
  6593. {
  6594. struct sla_trunk *trunk = obj;
  6595. ast_debug(1, "sla_trunk destructor for '%s'\n", trunk->name);
  6596. if (!ast_strlen_zero(trunk->autocontext)) {
  6597. ast_context_remove_extension(trunk->autocontext, "s", 1, sla_registrar);
  6598. }
  6599. sla_trunk_release_refs(trunk, NULL, 0);
  6600. ast_string_field_free_memory(trunk);
  6601. }
  6602. static int sla_build_trunk(struct ast_config *cfg, const char *cat)
  6603. {
  6604. RAII_VAR(struct sla_trunk *, trunk, NULL, ao2_cleanup);
  6605. struct ast_variable *var;
  6606. const char *dev;
  6607. int existing_trunk = 0;
  6608. if (!(dev = ast_variable_retrieve(cfg, cat, "device"))) {
  6609. ast_log(LOG_ERROR, "SLA Trunk '%s' defined with no device!\n", cat);
  6610. return -1;
  6611. }
  6612. if (sla_check_device(dev)) {
  6613. ast_log(LOG_ERROR, "SLA Trunk '%s' defined with invalid device '%s'!\n",
  6614. cat, dev);
  6615. return -1;
  6616. }
  6617. if ((trunk = sla_find_trunk(cat))) {
  6618. trunk->mark = 0;
  6619. existing_trunk = 1;
  6620. } else if ((trunk = ao2_alloc(sizeof(*trunk), sla_trunk_destructor))) {
  6621. if (ast_string_field_init(trunk, 32)) {
  6622. return -1;
  6623. }
  6624. ast_string_field_set(trunk, name, cat);
  6625. } else {
  6626. return -1;
  6627. }
  6628. ao2_lock(trunk);
  6629. ast_string_field_set(trunk, device, dev);
  6630. for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
  6631. if (!strcasecmp(var->name, "autocontext"))
  6632. ast_string_field_set(trunk, autocontext, var->value);
  6633. else if (!strcasecmp(var->name, "ringtimeout")) {
  6634. if (sscanf(var->value, "%30u", &trunk->ring_timeout) != 1) {
  6635. ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for trunk '%s'\n",
  6636. var->value, trunk->name);
  6637. trunk->ring_timeout = 0;
  6638. }
  6639. } else if (!strcasecmp(var->name, "barge"))
  6640. trunk->barge_disabled = ast_false(var->value);
  6641. else if (!strcasecmp(var->name, "hold")) {
  6642. if (!strcasecmp(var->value, "private"))
  6643. trunk->hold_access = SLA_HOLD_PRIVATE;
  6644. else if (!strcasecmp(var->value, "open"))
  6645. trunk->hold_access = SLA_HOLD_OPEN;
  6646. else {
  6647. ast_log(LOG_WARNING, "Invalid value '%s' for hold on trunk %s\n",
  6648. var->value, trunk->name);
  6649. }
  6650. } else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
  6651. ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
  6652. var->name, var->lineno, SLA_CONFIG_FILE);
  6653. }
  6654. }
  6655. ao2_unlock(trunk);
  6656. if (!ast_strlen_zero(trunk->autocontext)) {
  6657. if (!ast_context_find_or_create(NULL, NULL, trunk->autocontext, sla_registrar)) {
  6658. ast_log(LOG_ERROR, "Failed to automatically find or create "
  6659. "context '%s' for SLA!\n", trunk->autocontext);
  6660. return -1;
  6661. }
  6662. if (ast_add_extension(trunk->autocontext, 0 /* don't replace */, "s", 1,
  6663. NULL, NULL, slatrunk_app, ast_strdup(trunk->name), ast_free_ptr, sla_registrar)) {
  6664. ast_log(LOG_ERROR, "Failed to automatically create extension "
  6665. "for trunk '%s'!\n", trunk->name);
  6666. return -1;
  6667. }
  6668. }
  6669. if (!existing_trunk) {
  6670. ao2_link(sla_trunks, trunk);
  6671. }
  6672. return 0;
  6673. }
  6674. /*!
  6675. * \internal
  6676. * \pre station is not locked
  6677. */
  6678. static void sla_add_trunk_to_station(struct sla_station *station, struct ast_variable *var)
  6679. {
  6680. RAII_VAR(struct sla_trunk *, trunk, NULL, ao2_cleanup);
  6681. struct sla_trunk_ref *trunk_ref = NULL;
  6682. struct sla_station_ref *station_ref;
  6683. char *trunk_name, *options, *cur;
  6684. int existing_trunk_ref = 0;
  6685. int existing_station_ref = 0;
  6686. options = ast_strdupa(var->value);
  6687. trunk_name = strsep(&options, ",");
  6688. trunk = sla_find_trunk(trunk_name);
  6689. if (!trunk) {
  6690. ast_log(LOG_ERROR, "Trunk '%s' not found!\n", var->value);
  6691. return;
  6692. }
  6693. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  6694. if (trunk_ref->trunk == trunk) {
  6695. trunk_ref->mark = 0;
  6696. existing_trunk_ref = 1;
  6697. break;
  6698. }
  6699. }
  6700. if (!trunk_ref && !(trunk_ref = create_trunk_ref(trunk))) {
  6701. return;
  6702. }
  6703. trunk_ref->state = SLA_TRUNK_STATE_IDLE;
  6704. while ((cur = strsep(&options, ","))) {
  6705. char *name, *value = cur;
  6706. name = strsep(&value, "=");
  6707. if (!strcasecmp(name, "ringtimeout")) {
  6708. if (sscanf(value, "%30u", &trunk_ref->ring_timeout) != 1) {
  6709. ast_log(LOG_WARNING, "Invalid ringtimeout value '%s' for "
  6710. "trunk '%s' on station '%s'\n", value, trunk->name, station->name);
  6711. trunk_ref->ring_timeout = 0;
  6712. }
  6713. } else if (!strcasecmp(name, "ringdelay")) {
  6714. if (sscanf(value, "%30u", &trunk_ref->ring_delay) != 1) {
  6715. ast_log(LOG_WARNING, "Invalid ringdelay value '%s' for "
  6716. "trunk '%s' on station '%s'\n", value, trunk->name, station->name);
  6717. trunk_ref->ring_delay = 0;
  6718. }
  6719. } else {
  6720. ast_log(LOG_WARNING, "Invalid option '%s' for "
  6721. "trunk '%s' on station '%s'\n", name, trunk->name, station->name);
  6722. }
  6723. }
  6724. AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
  6725. if (station_ref->station == station) {
  6726. station_ref->mark = 0;
  6727. existing_station_ref = 1;
  6728. break;
  6729. }
  6730. }
  6731. if (!station_ref && !(station_ref = sla_create_station_ref(station))) {
  6732. if (!existing_trunk_ref) {
  6733. ao2_ref(trunk_ref, -1);
  6734. } else {
  6735. trunk_ref->mark = 1;
  6736. }
  6737. return;
  6738. }
  6739. if (!existing_station_ref) {
  6740. ao2_lock(trunk);
  6741. AST_LIST_INSERT_TAIL(&trunk->stations, station_ref, entry);
  6742. ast_atomic_fetchadd_int((int *) &trunk->num_stations, 1);
  6743. ao2_unlock(trunk);
  6744. }
  6745. if (!existing_trunk_ref) {
  6746. ao2_lock(station);
  6747. AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
  6748. ao2_unlock(station);
  6749. }
  6750. }
  6751. static int sla_build_station(struct ast_config *cfg, const char *cat)
  6752. {
  6753. RAII_VAR(struct sla_station *, station, NULL, ao2_cleanup);
  6754. struct ast_variable *var;
  6755. const char *dev;
  6756. int existing_station = 0;
  6757. if (!(dev = ast_variable_retrieve(cfg, cat, "device"))) {
  6758. ast_log(LOG_ERROR, "SLA Station '%s' defined with no device!\n", cat);
  6759. return -1;
  6760. }
  6761. if ((station = sla_find_station(cat))) {
  6762. station->mark = 0;
  6763. existing_station = 1;
  6764. } else if ((station = ao2_alloc(sizeof(*station), sla_station_destructor))) {
  6765. if (ast_string_field_init(station, 32)) {
  6766. return -1;
  6767. }
  6768. ast_string_field_set(station, name, cat);
  6769. } else {
  6770. return -1;
  6771. }
  6772. ao2_lock(station);
  6773. ast_string_field_set(station, device, dev);
  6774. for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
  6775. if (!strcasecmp(var->name, "trunk")) {
  6776. ao2_unlock(station);
  6777. sla_add_trunk_to_station(station, var);
  6778. ao2_lock(station);
  6779. } else if (!strcasecmp(var->name, "autocontext")) {
  6780. ast_string_field_set(station, autocontext, var->value);
  6781. } else if (!strcasecmp(var->name, "ringtimeout")) {
  6782. if (sscanf(var->value, "%30u", &station->ring_timeout) != 1) {
  6783. ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for station '%s'\n",
  6784. var->value, station->name);
  6785. station->ring_timeout = 0;
  6786. }
  6787. } else if (!strcasecmp(var->name, "ringdelay")) {
  6788. if (sscanf(var->value, "%30u", &station->ring_delay) != 1) {
  6789. ast_log(LOG_WARNING, "Invalid ringdelay '%s' specified for station '%s'\n",
  6790. var->value, station->name);
  6791. station->ring_delay = 0;
  6792. }
  6793. } else if (!strcasecmp(var->name, "hold")) {
  6794. if (!strcasecmp(var->value, "private"))
  6795. station->hold_access = SLA_HOLD_PRIVATE;
  6796. else if (!strcasecmp(var->value, "open"))
  6797. station->hold_access = SLA_HOLD_OPEN;
  6798. else {
  6799. ast_log(LOG_WARNING, "Invalid value '%s' for hold on station %s\n",
  6800. var->value, station->name);
  6801. }
  6802. } else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
  6803. ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
  6804. var->name, var->lineno, SLA_CONFIG_FILE);
  6805. }
  6806. }
  6807. ao2_unlock(station);
  6808. if (!ast_strlen_zero(station->autocontext)) {
  6809. struct sla_trunk_ref *trunk_ref;
  6810. if (!ast_context_find_or_create(NULL, NULL, station->autocontext, sla_registrar)) {
  6811. ast_log(LOG_ERROR, "Failed to automatically find or create "
  6812. "context '%s' for SLA!\n", station->autocontext);
  6813. return -1;
  6814. }
  6815. /* The extension for when the handset goes off-hook.
  6816. * exten => station1,1,SLAStation(station1) */
  6817. if (ast_add_extension(station->autocontext, 0 /* don't replace */, station->name, 1,
  6818. NULL, NULL, slastation_app, ast_strdup(station->name), ast_free_ptr, sla_registrar)) {
  6819. ast_log(LOG_ERROR, "Failed to automatically create extension "
  6820. "for trunk '%s'!\n", station->name);
  6821. return -1;
  6822. }
  6823. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  6824. char exten[AST_MAX_EXTENSION];
  6825. char hint[AST_MAX_APP];
  6826. snprintf(exten, sizeof(exten), "%s_%s", station->name, trunk_ref->trunk->name);
  6827. snprintf(hint, sizeof(hint), "SLA:%s", exten);
  6828. /* Extension for this line button
  6829. * exten => station1_line1,1,SLAStation(station1_line1) */
  6830. if (ast_add_extension(station->autocontext, 0 /* don't replace */, exten, 1,
  6831. NULL, NULL, slastation_app, ast_strdup(exten), ast_free_ptr, sla_registrar)) {
  6832. ast_log(LOG_ERROR, "Failed to automatically create extension "
  6833. "for trunk '%s'!\n", station->name);
  6834. return -1;
  6835. }
  6836. /* Hint for this line button
  6837. * exten => station1_line1,hint,SLA:station1_line1 */
  6838. if (ast_add_extension(station->autocontext, 0 /* don't replace */, exten, PRIORITY_HINT,
  6839. NULL, NULL, hint, NULL, NULL, sla_registrar)) {
  6840. ast_log(LOG_ERROR, "Failed to automatically create hint "
  6841. "for trunk '%s'!\n", station->name);
  6842. return -1;
  6843. }
  6844. }
  6845. }
  6846. if (!existing_station) {
  6847. ao2_link(sla_stations, station);
  6848. }
  6849. return 0;
  6850. }
  6851. static int sla_trunk_mark(void *obj, void *arg, int flags)
  6852. {
  6853. struct sla_trunk *trunk = obj;
  6854. struct sla_station_ref *station_ref;
  6855. ao2_lock(trunk);
  6856. trunk->mark = 1;
  6857. AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
  6858. station_ref->mark = 1;
  6859. }
  6860. ao2_unlock(trunk);
  6861. return 0;
  6862. }
  6863. static int sla_station_mark(void *obj, void *arg, int flags)
  6864. {
  6865. struct sla_station *station = obj;
  6866. struct sla_trunk_ref *trunk_ref;
  6867. ao2_lock(station);
  6868. station->mark = 1;
  6869. AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
  6870. trunk_ref->mark = 1;
  6871. }
  6872. ao2_unlock(station);
  6873. return 0;
  6874. }
  6875. static int sla_trunk_is_marked(void *obj, void *arg, int flags)
  6876. {
  6877. struct sla_trunk *trunk = obj;
  6878. ao2_lock(trunk);
  6879. if (trunk->mark) {
  6880. /* Only remove all of the station references if the trunk itself is going away */
  6881. sla_trunk_release_refs(trunk, NULL, 0);
  6882. } else {
  6883. struct sla_station_ref *station_ref;
  6884. /* Otherwise only remove references to stations no longer in the config */
  6885. AST_LIST_TRAVERSE_SAFE_BEGIN(&trunk->stations, station_ref, entry) {
  6886. if (!station_ref->mark) {
  6887. continue;
  6888. }
  6889. AST_LIST_REMOVE_CURRENT(entry);
  6890. ao2_ref(station_ref, -1);
  6891. }
  6892. AST_LIST_TRAVERSE_SAFE_END
  6893. }
  6894. ao2_unlock(trunk);
  6895. return trunk->mark ? CMP_MATCH : 0;
  6896. }
  6897. static int sla_station_is_marked(void *obj, void *arg, int flags)
  6898. {
  6899. struct sla_station *station = obj;
  6900. ao2_lock(station);
  6901. if (station->mark) {
  6902. /* Only remove all of the trunk references if the station itself is going away */
  6903. sla_station_release_refs(station, NULL, 0);
  6904. } else {
  6905. struct sla_trunk_ref *trunk_ref;
  6906. /* Otherwise only remove references to trunks no longer in the config */
  6907. AST_LIST_TRAVERSE_SAFE_BEGIN(&station->trunks, trunk_ref, entry) {
  6908. if (!trunk_ref->mark) {
  6909. continue;
  6910. }
  6911. AST_LIST_REMOVE_CURRENT(entry);
  6912. ao2_ref(trunk_ref, -1);
  6913. }
  6914. AST_LIST_TRAVERSE_SAFE_END
  6915. }
  6916. ao2_unlock(station);
  6917. return station->mark ? CMP_MATCH : 0;
  6918. }
  6919. static int sla_in_use(void)
  6920. {
  6921. return ao2_container_count(sla_trunks) || ao2_container_count(sla_stations);
  6922. }
  6923. static int sla_load_config(int reload)
  6924. {
  6925. struct ast_config *cfg;
  6926. struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
  6927. const char *cat = NULL;
  6928. int res = 0;
  6929. const char *val;
  6930. if (!reload) {
  6931. ast_mutex_init(&sla.lock);
  6932. ast_cond_init(&sla.cond, NULL);
  6933. sla_trunks = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
  6934. NULL, sla_trunk_cmp);
  6935. sla_stations = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
  6936. NULL, sla_station_cmp);
  6937. }
  6938. if (!(cfg = ast_config_load(SLA_CONFIG_FILE, config_flags))) {
  6939. return 0; /* Treat no config as normal */
  6940. } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
  6941. return 0;
  6942. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  6943. ast_log(LOG_ERROR, "Config file " SLA_CONFIG_FILE " is in an invalid format. Aborting.\n");
  6944. return 0;
  6945. }
  6946. if (reload) {
  6947. ao2_callback(sla_trunks, 0, sla_trunk_mark, NULL);
  6948. ao2_callback(sla_stations, 0, sla_station_mark, NULL);
  6949. }
  6950. if ((val = ast_variable_retrieve(cfg, "general", "attemptcallerid")))
  6951. sla.attempt_callerid = ast_true(val);
  6952. while ((cat = ast_category_browse(cfg, cat)) && !res) {
  6953. const char *type;
  6954. if (!strcasecmp(cat, "general"))
  6955. continue;
  6956. if (!(type = ast_variable_retrieve(cfg, cat, "type"))) {
  6957. ast_log(LOG_WARNING, "Invalid entry in %s defined with no type!\n",
  6958. SLA_CONFIG_FILE);
  6959. continue;
  6960. }
  6961. if (!strcasecmp(type, "trunk"))
  6962. res = sla_build_trunk(cfg, cat);
  6963. else if (!strcasecmp(type, "station"))
  6964. res = sla_build_station(cfg, cat);
  6965. else {
  6966. ast_log(LOG_WARNING, "Entry in %s defined with invalid type '%s'!\n",
  6967. SLA_CONFIG_FILE, type);
  6968. }
  6969. }
  6970. ast_config_destroy(cfg);
  6971. if (reload) {
  6972. ao2_callback(sla_trunks, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, sla_trunk_is_marked, NULL);
  6973. ao2_callback(sla_stations, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, sla_station_is_marked, NULL);
  6974. }
  6975. /* Start SLA event processing thread once SLA has been configured. */
  6976. if (sla.thread == AST_PTHREADT_NULL && sla_in_use()) {
  6977. ast_pthread_create(&sla.thread, NULL, sla_thread, NULL);
  6978. }
  6979. return res;
  6980. }
  6981. static int acf_meetme_info_eval(const char *keyword, const struct ast_conference *conf)
  6982. {
  6983. if (!strcasecmp("lock", keyword)) {
  6984. return conf->locked;
  6985. } else if (!strcasecmp("parties", keyword)) {
  6986. return conf->users;
  6987. } else if (!strcasecmp("activity", keyword)) {
  6988. time_t now;
  6989. now = time(NULL);
  6990. return (now - conf->start);
  6991. } else if (!strcasecmp("dynamic", keyword)) {
  6992. return conf->isdynamic;
  6993. } else {
  6994. return -1;
  6995. }
  6996. }
  6997. static int acf_meetme_info(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
  6998. {
  6999. struct ast_conference *conf;
  7000. char *parse;
  7001. int result = -2; /* only non-negative numbers valid, -1 is used elsewhere */
  7002. AST_DECLARE_APP_ARGS(args,
  7003. AST_APP_ARG(keyword);
  7004. AST_APP_ARG(confno);
  7005. );
  7006. if (ast_strlen_zero(data)) {
  7007. ast_log(LOG_ERROR, "Syntax: MEETME_INFO() requires two arguments\n");
  7008. return -1;
  7009. }
  7010. parse = ast_strdupa(data);
  7011. AST_STANDARD_APP_ARGS(args, parse);
  7012. if (ast_strlen_zero(args.keyword)) {
  7013. ast_log(LOG_ERROR, "Syntax: MEETME_INFO() requires a keyword\n");
  7014. return -1;
  7015. }
  7016. if (ast_strlen_zero(args.confno)) {
  7017. ast_log(LOG_ERROR, "Syntax: MEETME_INFO() requires a conference number\n");
  7018. return -1;
  7019. }
  7020. AST_LIST_LOCK(&confs);
  7021. AST_LIST_TRAVERSE(&confs, conf, list) {
  7022. if (!strcmp(args.confno, conf->confno)) {
  7023. result = acf_meetme_info_eval(args.keyword, conf);
  7024. break;
  7025. }
  7026. }
  7027. AST_LIST_UNLOCK(&confs);
  7028. if (result > -1) {
  7029. snprintf(buf, len, "%d", result);
  7030. } else if (result == -1) {
  7031. ast_log(LOG_NOTICE, "Error: invalid keyword: '%s'\n", args.keyword);
  7032. snprintf(buf, len, "0");
  7033. } else if (result == -2) {
  7034. ast_log(LOG_NOTICE, "Error: conference (%s) not found\n", args.confno);
  7035. snprintf(buf, len, "0");
  7036. }
  7037. return 0;
  7038. }
  7039. static struct ast_custom_function meetme_info_acf = {
  7040. .name = "MEETME_INFO",
  7041. .read = acf_meetme_info,
  7042. };
  7043. static int load_config(int reload)
  7044. {
  7045. load_config_meetme(reload);
  7046. return sla_load_config(reload);
  7047. }
  7048. #define MEETME_DATA_EXPORT(MEMBER) \
  7049. MEMBER(ast_conference, confno, AST_DATA_STRING) \
  7050. MEMBER(ast_conference, dahdiconf, AST_DATA_INTEGER) \
  7051. MEMBER(ast_conference, users, AST_DATA_INTEGER) \
  7052. MEMBER(ast_conference, markedusers, AST_DATA_INTEGER) \
  7053. MEMBER(ast_conference, maxusers, AST_DATA_INTEGER) \
  7054. MEMBER(ast_conference, isdynamic, AST_DATA_BOOLEAN) \
  7055. MEMBER(ast_conference, locked, AST_DATA_BOOLEAN) \
  7056. MEMBER(ast_conference, recordingfilename, AST_DATA_STRING) \
  7057. MEMBER(ast_conference, recordingformat, AST_DATA_STRING) \
  7058. MEMBER(ast_conference, pin, AST_DATA_PASSWORD) \
  7059. MEMBER(ast_conference, pinadmin, AST_DATA_PASSWORD) \
  7060. MEMBER(ast_conference, start, AST_DATA_TIMESTAMP) \
  7061. MEMBER(ast_conference, endtime, AST_DATA_TIMESTAMP)
  7062. AST_DATA_STRUCTURE(ast_conference, MEETME_DATA_EXPORT);
  7063. #define MEETME_USER_DATA_EXPORT(MEMBER) \
  7064. MEMBER(ast_conf_user, user_no, AST_DATA_INTEGER) \
  7065. MEMBER(ast_conf_user, talking, AST_DATA_BOOLEAN) \
  7066. MEMBER(ast_conf_user, dahdichannel, AST_DATA_BOOLEAN) \
  7067. MEMBER(ast_conf_user, jointime, AST_DATA_TIMESTAMP) \
  7068. MEMBER(ast_conf_user, kicktime, AST_DATA_TIMESTAMP) \
  7069. MEMBER(ast_conf_user, timelimit, AST_DATA_MILLISECONDS) \
  7070. MEMBER(ast_conf_user, play_warning, AST_DATA_MILLISECONDS) \
  7071. MEMBER(ast_conf_user, warning_freq, AST_DATA_MILLISECONDS)
  7072. AST_DATA_STRUCTURE(ast_conf_user, MEETME_USER_DATA_EXPORT);
  7073. static int user_add_provider_cb(void *obj, void *arg, int flags)
  7074. {
  7075. struct ast_data *data_meetme_user;
  7076. struct ast_data *data_meetme_user_channel;
  7077. struct ast_data *data_meetme_user_volume;
  7078. struct ast_conf_user *user = obj;
  7079. struct ast_data *data_meetme_users = arg;
  7080. data_meetme_user = ast_data_add_node(data_meetme_users, "user");
  7081. if (!data_meetme_user) {
  7082. return 0;
  7083. }
  7084. /* user structure */
  7085. ast_data_add_structure(ast_conf_user, data_meetme_user, user);
  7086. /* user's channel */
  7087. data_meetme_user_channel = ast_data_add_node(data_meetme_user, "channel");
  7088. if (!data_meetme_user_channel) {
  7089. return 0;
  7090. }
  7091. ast_channel_data_add_structure(data_meetme_user_channel, user->chan, 1);
  7092. /* volume structure */
  7093. data_meetme_user_volume = ast_data_add_node(data_meetme_user, "listen-volume");
  7094. if (!data_meetme_user_volume) {
  7095. return 0;
  7096. }
  7097. ast_data_add_int(data_meetme_user_volume, "desired", user->listen.desired);
  7098. ast_data_add_int(data_meetme_user_volume, "actual", user->listen.actual);
  7099. data_meetme_user_volume = ast_data_add_node(data_meetme_user, "talk-volume");
  7100. if (!data_meetme_user_volume) {
  7101. return 0;
  7102. }
  7103. ast_data_add_int(data_meetme_user_volume, "desired", user->talk.desired);
  7104. ast_data_add_int(data_meetme_user_volume, "actual", user->talk.actual);
  7105. return 0;
  7106. }
  7107. /*!
  7108. * \internal
  7109. * \brief Implements the meetme data provider.
  7110. */
  7111. static int meetme_data_provider_get(const struct ast_data_search *search,
  7112. struct ast_data *data_root)
  7113. {
  7114. struct ast_conference *cnf;
  7115. struct ast_data *data_meetme, *data_meetme_users;
  7116. AST_LIST_LOCK(&confs);
  7117. AST_LIST_TRAVERSE(&confs, cnf, list) {
  7118. data_meetme = ast_data_add_node(data_root, "meetme");
  7119. if (!data_meetme) {
  7120. continue;
  7121. }
  7122. ast_data_add_structure(ast_conference, data_meetme, cnf);
  7123. if (ao2_container_count(cnf->usercontainer)) {
  7124. data_meetme_users = ast_data_add_node(data_meetme, "users");
  7125. if (!data_meetme_users) {
  7126. ast_data_remove_node(data_root, data_meetme);
  7127. continue;
  7128. }
  7129. ao2_callback(cnf->usercontainer, OBJ_NODATA, user_add_provider_cb, data_meetme_users);
  7130. }
  7131. if (!ast_data_search_match(search, data_meetme)) {
  7132. ast_data_remove_node(data_root, data_meetme);
  7133. }
  7134. }
  7135. AST_LIST_UNLOCK(&confs);
  7136. return 0;
  7137. }
  7138. static const struct ast_data_handler meetme_data_provider = {
  7139. .version = AST_DATA_HANDLER_VERSION,
  7140. .get = meetme_data_provider_get
  7141. };
  7142. static const struct ast_data_entry meetme_data_providers[] = {
  7143. AST_DATA_ENTRY("asterisk/application/meetme/list", &meetme_data_provider),
  7144. };
  7145. #ifdef TEST_FRAMEWORK
  7146. AST_TEST_DEFINE(test_meetme_data_provider)
  7147. {
  7148. struct ast_channel *chan;
  7149. struct ast_conference *cnf;
  7150. struct ast_data *node;
  7151. struct ast_data_query query = {
  7152. .path = "/asterisk/application/meetme/list",
  7153. .search = "list/meetme/confno=9898"
  7154. };
  7155. switch (cmd) {
  7156. case TEST_INIT:
  7157. info->name = "meetme_get_data_test";
  7158. info->category = "/main/data/app_meetme/list/";
  7159. info->summary = "Meetme data provider unit test";
  7160. info->description =
  7161. "Tests whether the Meetme data provider implementation works as expected.";
  7162. return AST_TEST_NOT_RUN;
  7163. case TEST_EXECUTE:
  7164. break;
  7165. }
  7166. chan = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, "MeetMeTest");
  7167. if (!chan) {
  7168. ast_test_status_update(test, "Channel allocation failed\n");
  7169. return AST_TEST_FAIL;
  7170. }
  7171. ast_channel_unlock(chan);
  7172. cnf = build_conf("9898", "", "1234", 1, 1, 1, chan, test);
  7173. if (!cnf) {
  7174. ast_test_status_update(test, "Build of test conference 9898 failed\n");
  7175. ast_hangup(chan);
  7176. return AST_TEST_FAIL;
  7177. }
  7178. node = ast_data_get(&query);
  7179. if (!node) {
  7180. ast_test_status_update(test, "Data query for test conference 9898 failed\n");
  7181. dispose_conf(cnf);
  7182. ast_hangup(chan);
  7183. return AST_TEST_FAIL;
  7184. }
  7185. if (strcmp(ast_data_retrieve_string(node, "meetme/confno"), "9898")) {
  7186. ast_test_status_update(test, "Query returned the wrong conference\n");
  7187. dispose_conf(cnf);
  7188. ast_hangup(chan);
  7189. ast_data_free(node);
  7190. return AST_TEST_FAIL;
  7191. }
  7192. ast_data_free(node);
  7193. dispose_conf(cnf);
  7194. ast_hangup(chan);
  7195. return AST_TEST_PASS;
  7196. }
  7197. #endif
  7198. static int unload_module(void)
  7199. {
  7200. int res = 0;
  7201. ast_cli_unregister_multiple(cli_meetme, ARRAY_LEN(cli_meetme));
  7202. res = ast_manager_unregister("MeetmeMute");
  7203. res |= ast_manager_unregister("MeetmeUnmute");
  7204. res |= ast_manager_unregister("MeetmeList");
  7205. res |= ast_manager_unregister("MeetmeListRooms");
  7206. res |= ast_unregister_application(app4);
  7207. res |= ast_unregister_application(app3);
  7208. res |= ast_unregister_application(app2);
  7209. res |= ast_unregister_application(app);
  7210. res |= ast_unregister_application(slastation_app);
  7211. res |= ast_unregister_application(slatrunk_app);
  7212. #ifdef TEST_FRAMEWORK
  7213. AST_TEST_UNREGISTER(test_meetme_data_provider);
  7214. #endif
  7215. ast_data_unregister(NULL);
  7216. ast_devstate_prov_del("Meetme");
  7217. ast_devstate_prov_del("SLA");
  7218. sla_destroy();
  7219. res |= ast_custom_function_unregister(&meetme_info_acf);
  7220. ast_unload_realtime("meetme");
  7221. meetme_stasis_cleanup();
  7222. return res;
  7223. }
  7224. /*!
  7225. * \brief Load the module
  7226. *
  7227. * Module loading including tests for configuration or dependencies.
  7228. * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE,
  7229. * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails
  7230. * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the
  7231. * configuration file or other non-critical problem return
  7232. * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS.
  7233. */
  7234. static int load_module(void)
  7235. {
  7236. int res = 0;
  7237. res |= load_config(0);
  7238. res |= meetme_stasis_init();
  7239. ast_cli_register_multiple(cli_meetme, ARRAY_LEN(cli_meetme));
  7240. res |= ast_manager_register_xml("MeetmeMute", EVENT_FLAG_CALL, action_meetmemute);
  7241. res |= ast_manager_register_xml("MeetmeUnmute", EVENT_FLAG_CALL, action_meetmeunmute);
  7242. res |= ast_manager_register_xml("MeetmeList", EVENT_FLAG_REPORTING, action_meetmelist);
  7243. res |= ast_manager_register_xml("MeetmeListRooms", EVENT_FLAG_REPORTING, action_meetmelistrooms);
  7244. res |= ast_register_application_xml(app4, channel_admin_exec);
  7245. res |= ast_register_application_xml(app3, admin_exec);
  7246. res |= ast_register_application_xml(app2, count_exec);
  7247. res |= ast_register_application_xml(app, conf_exec);
  7248. res |= ast_register_application_xml(slastation_app, sla_station_exec);
  7249. res |= ast_register_application_xml(slatrunk_app, sla_trunk_exec);
  7250. #ifdef TEST_FRAMEWORK
  7251. AST_TEST_REGISTER(test_meetme_data_provider);
  7252. #endif
  7253. ast_data_register_multiple(meetme_data_providers, ARRAY_LEN(meetme_data_providers));
  7254. res |= ast_devstate_prov_add("Meetme", meetmestate);
  7255. res |= ast_devstate_prov_add("SLA", sla_state);
  7256. res |= ast_custom_function_register(&meetme_info_acf);
  7257. ast_realtime_require_field("meetme", "confno", RQ_UINTEGER2, 3, "members", RQ_UINTEGER1, 3, NULL);
  7258. return res;
  7259. }
  7260. static int reload(void)
  7261. {
  7262. ast_unload_realtime("meetme");
  7263. return load_config(1);
  7264. }
  7265. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "MeetMe conference bridge",
  7266. .support_level = AST_MODULE_SUPPORT_EXTENDED,
  7267. .load = load_module,
  7268. .unload = unload_module,
  7269. .reload = reload,
  7270. .load_pri = AST_MODPRI_DEVSTATE_PROVIDER,
  7271. );