channel.h 171 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2006, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief General Asterisk PBX channel definitions.
  20. * \par See also:
  21. * \arg \ref Def_Channel
  22. * \arg \ref channel_drivers
  23. */
  24. /*! \page Def_Channel Asterisk Channels
  25. \par What is a Channel?
  26. A phone call through Asterisk consists of an incoming
  27. connection and an outbound connection. Each call comes
  28. in through a channel driver that supports one technology,
  29. like SIP, DAHDI, IAX2 etc.
  30. \par
  31. Each channel driver, technology, has it's own private
  32. channel or dialog structure, that is technology-dependent.
  33. Each private structure is "owned" by a generic Asterisk
  34. channel structure, defined in channel.h and handled by
  35. channel.c .
  36. \par Call scenario
  37. This happens when an incoming call arrives to Asterisk
  38. -# Call arrives on a channel driver interface
  39. -# Channel driver creates a PBX channel and starts a
  40. pbx thread on the channel
  41. -# The dial plan is executed
  42. -# At this point at least two things can happen:
  43. -# The call is answered by Asterisk and
  44. Asterisk plays a media stream or reads media
  45. -# The dial plan forces Asterisk to create an outbound
  46. call somewhere with the dial (see \ref app_dial.c)
  47. application
  48. .
  49. \par Bridging channels
  50. If Asterisk dials out this happens:
  51. -# Dial creates an outbound PBX channel and asks one of the
  52. channel drivers to create a call
  53. -# When the call is answered, Asterisk bridges the media streams
  54. so the caller on the first channel can speak with the callee
  55. on the second, outbound channel
  56. -# In some cases where we have the same technology on both
  57. channels and compatible codecs, a native bridge is used.
  58. In a native bridge, the channel driver handles forwarding
  59. of incoming audio to the outbound stream internally, without
  60. sending audio frames through the PBX.
  61. -# In SIP, theres an "external native bridge" where Asterisk
  62. redirects the endpoint, so audio flows directly between the
  63. caller's phone and the callee's phone. Signalling stays in
  64. Asterisk in order to be able to provide a proper CDR record
  65. for the call.
  66. \par Masquerading channels
  67. In some cases, a channel can masquerade itself into another
  68. channel. This happens frequently in call transfers, where
  69. a new channel takes over a channel that is already involved
  70. in a call. The new channel sneaks in and takes over the bridge
  71. and the old channel, now a zombie, is hung up.
  72. \par Reference
  73. \arg channel.c - generic functions
  74. \arg channel.h - declarations of functions, flags and structures
  75. \arg translate.h - Transcoding support functions
  76. \arg \ref channel_drivers - Implemented channel drivers
  77. \arg \ref Def_Frame Asterisk Multimedia Frames
  78. \arg \ref Def_Bridge
  79. */
  80. /*! \page Def_Bridge Asterisk Channel Bridges
  81. In Asterisk, there's several media bridges.
  82. The Core bridge handles two channels (a "phone call") and bridge
  83. them together.
  84. The conference bridge (meetme) handles several channels simultaneously
  85. with the support of an external timer (DAHDI timer). This is used
  86. not only by the Conference application (meetme) but also by the
  87. page application and the SLA system introduced in 1.4.
  88. The conference bridge does not handle video.
  89. When two channels of the same type connect, the channel driver
  90. or the media subsystem used by the channel driver (i.e. RTP)
  91. can create a native bridge without sending media through the
  92. core.
  93. Native bridging can be disabled by a number of reasons,
  94. like DTMF being needed by the core or codecs being incompatible
  95. so a transcoding module is needed.
  96. References:
  97. \li \see ast_channel_early_bridge()
  98. \li \see ast_channel_bridge()
  99. \li \see app_meetme.c
  100. \li \ref AstRTPbridge
  101. \li \see ast_rtp_bridge()
  102. \li \ref Def_Channel
  103. */
  104. /*! \page AstFileDesc File descriptors
  105. Asterisk File descriptors are connected to each channel (see \ref Def_Channel)
  106. in the \ref ast_channel structure.
  107. */
  108. #ifndef _ASTERISK_CHANNEL_H
  109. #define _ASTERISK_CHANNEL_H
  110. #include "asterisk/alertpipe.h"
  111. #include "asterisk/abstract_jb.h"
  112. #include "asterisk/astobj2.h"
  113. #include "asterisk/poll-compat.h"
  114. #if defined(__cplusplus) || defined(c_plusplus)
  115. extern "C" {
  116. #endif
  117. #define AST_MAX_EXTENSION 80 /*!< Max length of an extension */
  118. #define AST_MAX_CONTEXT 80 /*!< Max length of a context */
  119. /*!
  120. * Max length of a channel uniqueid reported to the outside world.
  121. *
  122. * \details
  123. * 149 = 127 (max systemname) + "-" + 10 (epoch timestamp)
  124. * + "." + 10 (monotonically incrementing integer).
  125. *
  126. * \note If this value is ever changed, MAX_CHANNEL_ID should
  127. * be updated in rtp_engine.h.
  128. */
  129. #define AST_MAX_PUBLIC_UNIQUEID 149
  130. /*!
  131. * Maximum size of an internal Asterisk channel unique ID.
  132. *
  133. * \details
  134. * Add two for the Local;2 channel to append a ';2' if needed
  135. * plus nul terminator.
  136. *
  137. * \note If this value is ever changed, MAX_CHANNEL_ID should
  138. * be updated in rtp_engine.h.
  139. */
  140. #define AST_MAX_UNIQUEID (AST_MAX_PUBLIC_UNIQUEID + 2 + 1)
  141. #define AST_MAX_ACCOUNT_CODE 20 /*!< Max length of an account code */
  142. #define AST_CHANNEL_NAME 80 /*!< Max length of an ast_channel name */
  143. #define MAX_LANGUAGE 40 /*!< Max length of the language setting */
  144. #define MAX_MUSICCLASS 80 /*!< Max length of the music class setting */
  145. #define AST_MAX_USER_FIELD 256 /*!< Max length of the channel user field */
  146. #include "asterisk/frame.h"
  147. #include "asterisk/chanvars.h"
  148. #include "asterisk/config.h"
  149. #include "asterisk/lock.h"
  150. #include "asterisk/cdr.h"
  151. #include "asterisk/utils.h"
  152. #include "asterisk/linkedlists.h"
  153. #include "asterisk/stringfields.h"
  154. #include "asterisk/datastore.h"
  155. #include "asterisk/data.h"
  156. #include "asterisk/channelstate.h"
  157. #include "asterisk/ccss.h"
  158. #include "asterisk/framehook.h"
  159. #include "asterisk/stasis.h"
  160. #include "asterisk/endpoints.h"
  161. #define DATASTORE_INHERIT_FOREVER INT_MAX
  162. #define AST_MAX_FDS 11
  163. /*
  164. * We have AST_MAX_FDS file descriptors in a channel.
  165. * Some of them have a fixed use:
  166. */
  167. #define AST_ALERT_FD (AST_MAX_FDS-1) /*!< used for alertpipe */
  168. #define AST_TIMING_FD (AST_MAX_FDS-2) /*!< used for timingfd */
  169. #define AST_AGENT_FD (AST_MAX_FDS-3) /*!< used by agents for pass through */
  170. #define AST_GENERATOR_FD (AST_MAX_FDS-4) /*!< used by generator */
  171. #define AST_JITTERBUFFER_FD (AST_MAX_FDS-5) /*!< used by generator */
  172. enum ast_bridge_result {
  173. AST_BRIDGE_COMPLETE = 0,
  174. AST_BRIDGE_FAILED = -1,
  175. AST_BRIDGE_FAILED_NOWARN = -2,
  176. AST_BRIDGE_RETRY = -3,
  177. };
  178. typedef unsigned long long ast_group_t;
  179. /*! \todo Add an explanation of an Asterisk generator
  180. */
  181. struct ast_generator {
  182. void *(*alloc)(struct ast_channel *chan, void *params);
  183. /*! Channel is locked during this function callback. */
  184. void (*release)(struct ast_channel *chan, void *data);
  185. /*! This function gets called with the channel unlocked, but is called in
  186. * the context of the channel thread so we know the channel is not going
  187. * to disappear. This callback is responsible for locking the channel as
  188. * necessary. */
  189. int (*generate)(struct ast_channel *chan, void *data, int len, int samples);
  190. /*! This gets called when DTMF_END frames are read from the channel */
  191. void (*digit)(struct ast_channel *chan, char digit);
  192. /*! This gets called when the write format on a channel is changed while
  193. * generating. The channel is locked during this callback. */
  194. void (*write_format_change)(struct ast_channel *chan, void *data);
  195. };
  196. /*! Party name character set enumeration values (values from Q.SIG) */
  197. enum AST_PARTY_CHAR_SET {
  198. AST_PARTY_CHAR_SET_UNKNOWN = 0,
  199. AST_PARTY_CHAR_SET_ISO8859_1 = 1,
  200. AST_PARTY_CHAR_SET_WITHDRAWN = 2,/* ITU withdrew this enum value. */
  201. AST_PARTY_CHAR_SET_ISO8859_2 = 3,
  202. AST_PARTY_CHAR_SET_ISO8859_3 = 4,
  203. AST_PARTY_CHAR_SET_ISO8859_4 = 5,
  204. AST_PARTY_CHAR_SET_ISO8859_5 = 6,
  205. AST_PARTY_CHAR_SET_ISO8859_7 = 7,
  206. AST_PARTY_CHAR_SET_ISO10646_BMPSTRING = 8,
  207. AST_PARTY_CHAR_SET_ISO10646_UTF_8STRING = 9,
  208. };
  209. /*!
  210. * \since 1.8
  211. * \brief Information needed to specify a name in a call.
  212. * \note All string fields here are malloc'ed, so they need to be
  213. * freed when the structure is deleted.
  214. * \note NULL and "" must be considered equivalent.
  215. */
  216. struct ast_party_name {
  217. /*! \brief Subscriber name (Malloced) */
  218. char *str;
  219. /*!
  220. * \brief Character set the name is using.
  221. * \see enum AST_PARTY_CHAR_SET
  222. * \note
  223. * Set to AST_PARTY_CHAR_SET_ISO8859_1 if unsure what to use.
  224. * \todo Start using the party name character set value. Not currently used.
  225. */
  226. int char_set;
  227. /*!
  228. * \brief Q.931 encoded presentation-indicator encoded field
  229. * \note Must tolerate the Q.931 screening-indicator field values being present.
  230. */
  231. int presentation;
  232. /*! \brief TRUE if the name information is valid/present */
  233. unsigned char valid;
  234. };
  235. /*!
  236. * \since 1.8
  237. * \brief Information needed to specify a number in a call.
  238. * \note All string fields here are malloc'ed, so they need to be
  239. * freed when the structure is deleted.
  240. * \note NULL and "" must be considered equivalent.
  241. */
  242. struct ast_party_number {
  243. /*! \brief Subscriber phone number (Malloced) */
  244. char *str;
  245. /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
  246. int plan;
  247. /*! \brief Q.931 presentation-indicator and screening-indicator encoded fields */
  248. int presentation;
  249. /*! \brief TRUE if the number information is valid/present */
  250. unsigned char valid;
  251. };
  252. /*!
  253. * \since 1.8
  254. * \brief Information needed to specify a subaddress in a call.
  255. * \note All string fields here are malloc'ed, so they need to be
  256. * freed when the structure is deleted.
  257. * \note NULL and "" must be considered equivalent.
  258. */
  259. struct ast_party_subaddress {
  260. /*!
  261. * \brief Malloced subaddress string.
  262. * \note If the subaddress type is user specified then the subaddress is
  263. * a string of ASCII hex because the actual subaddress is likely BCD encoded.
  264. */
  265. char *str;
  266. /*!
  267. * \brief Q.931 subaddress type.
  268. * \details
  269. * nsap(0),
  270. * user_specified(2)
  271. */
  272. int type;
  273. /*!
  274. * \brief TRUE if odd number of address signals
  275. * \note The odd/even indicator is used when the type of subaddress is
  276. * user_specified and the coding is BCD.
  277. */
  278. unsigned char odd_even_indicator;
  279. /*! \brief TRUE if the subaddress information is valid/present */
  280. unsigned char valid;
  281. };
  282. /*!
  283. * \since 1.8
  284. * \brief Information needed to identify an endpoint in a call.
  285. * \note All string fields here are malloc'ed, so they need to be
  286. * freed when the structure is deleted.
  287. * \note NULL and "" must be considered equivalent.
  288. */
  289. struct ast_party_id {
  290. /*! \brief Subscriber name */
  291. struct ast_party_name name;
  292. /*! \brief Subscriber phone number */
  293. struct ast_party_number number;
  294. /*! \brief Subscriber subaddress. */
  295. struct ast_party_subaddress subaddress;
  296. /*!
  297. * \brief User-set "tag"
  298. * \details
  299. * A user-settable field used to help associate some extrinsic information
  300. * about the channel or user of the channel to the party ID. This information
  301. * is normally not transmitted over the wire and so is only useful within an
  302. * Asterisk environment.
  303. */
  304. char *tag;
  305. };
  306. /*!
  307. * \since 1.8
  308. * \brief Indicate what information in ast_party_id should be set.
  309. */
  310. struct ast_set_party_id {
  311. /*! TRUE if the ast_party_name information should be set. */
  312. unsigned char name;
  313. /*! TRUE if the ast_party_number information should be set. */
  314. unsigned char number;
  315. /*! TRUE if the ast_party_subaddress information should be set. */
  316. unsigned char subaddress;
  317. };
  318. /*!
  319. * \since 1.8
  320. * \brief Dialed/Called Party information.
  321. * \note Dialed Number Identifier (DNID)
  322. * \note All string fields here are malloc'ed, so they need to be
  323. * freed when the structure is deleted.
  324. * \note NULL and "" must be considered equivalent.
  325. */
  326. struct ast_party_dialed {
  327. /*!
  328. * \brief Dialed/Called number
  329. * \note Done this way in case we ever really need to use ast_party_number.
  330. * We currently do not need all of the ast_party_number fields.
  331. */
  332. struct {
  333. /*! \brief Subscriber phone number (Malloced) */
  334. char *str;
  335. /*! \brief Q.931 Type-Of-Number and Numbering-Plan encoded fields */
  336. int plan;
  337. } number;
  338. /*! \brief Dialed/Called subaddress */
  339. struct ast_party_subaddress subaddress;
  340. /*!
  341. * \brief Transit Network Select
  342. * \note Currently this value is just passed around the system.
  343. * You can read it and set it but it is never used for anything.
  344. */
  345. int transit_network_select;
  346. };
  347. /*!
  348. * \since 1.8
  349. * \brief Caller Party information.
  350. * \note All string fields here are malloc'ed, so they need to be
  351. * freed when the structure is deleted.
  352. * \note NULL and "" must be considered equivalent.
  353. *
  354. * \note SIP and IAX2 has UTF8 encoded Unicode Caller ID names.
  355. * In some cases, we also have an alternative (RPID) E.164 number that can
  356. * be used as Caller ID on numeric E.164 phone networks (DAHDI or SIP/IAX2 to
  357. * PSTN gateway).
  358. *
  359. * \todo Implement settings for transliteration between UTF8 Caller ID names in
  360. * to ASCII Caller ID's (DAHDI). Östen Åsklund might be transliterated into
  361. * Osten Asklund or Oesten Aasklund depending upon language and person...
  362. * We need automatic routines for incoming calls and static settings for
  363. * our own accounts.
  364. */
  365. struct ast_party_caller {
  366. /*! \brief Caller party ID */
  367. struct ast_party_id id;
  368. /*!
  369. * \brief Automatic Number Identification (ANI)
  370. * \note The name subcomponent is only likely to be used by SIP.
  371. * \note The subaddress subcomponent is not likely to be used.
  372. */
  373. struct ast_party_id ani;
  374. /*! \brief Private caller party ID */
  375. struct ast_party_id priv;
  376. /*! \brief Automatic Number Identification 2 (Info Digits) */
  377. int ani2;
  378. };
  379. /*!
  380. * \since 1.8
  381. * \brief Indicate what information in ast_party_caller should be set.
  382. */
  383. struct ast_set_party_caller {
  384. /*! What caller id information to set. */
  385. struct ast_set_party_id id;
  386. /*! What ANI id information to set. */
  387. struct ast_set_party_id ani;
  388. /*! What private caller id information to set. */
  389. struct ast_set_party_id priv;
  390. };
  391. /*!
  392. * \since 1.8
  393. * \brief Connected Line/Party information.
  394. * \note All string fields here are malloc'ed, so they need to be
  395. * freed when the structure is deleted.
  396. * \note NULL and "" must be considered equivalent.
  397. */
  398. struct ast_party_connected_line {
  399. /*! \brief Connected party ID */
  400. struct ast_party_id id;
  401. /*!
  402. * \brief Automatic Number Identification (ANI)
  403. * \note Not really part of connected line data but needed to
  404. * save the corresponding caller id value.
  405. */
  406. struct ast_party_id ani;
  407. /*! \brief Private connected party ID */
  408. struct ast_party_id priv;
  409. /*!
  410. * \brief Automatic Number Identification 2 (Info Digits)
  411. * \note Not really part of connected line data but needed to
  412. * save the corresponding caller id value.
  413. */
  414. int ani2;
  415. /*!
  416. * \brief Information about the source of an update.
  417. * \note enum AST_CONNECTED_LINE_UPDATE_SOURCE values
  418. * for Normal-Answer and Call-transfer.
  419. */
  420. int source;
  421. };
  422. /*!
  423. * \since 1.8
  424. * \brief Indicate what information in ast_party_connected_line should be set.
  425. */
  426. struct ast_set_party_connected_line {
  427. /*! What connected line id information to set. */
  428. struct ast_set_party_id id;
  429. /*! What ANI id information to set. */
  430. struct ast_set_party_id ani;
  431. /*! What private connected line id information to set. */
  432. struct ast_set_party_id priv;
  433. };
  434. /*!
  435. * \brief Redirecting reason information
  436. */
  437. struct ast_party_redirecting_reason {
  438. /*! \brief a string value for the redirecting reason
  439. *
  440. * Useful for cases where an endpoint has specified a redirecting reason
  441. * that does not correspond to an enum AST_REDIRECTING_REASON
  442. */
  443. char *str;
  444. /*! \brief enum AST_REDIRECTING_REASON value for redirection */
  445. int code;
  446. };
  447. /*!
  448. * \since 1.8
  449. * \brief Redirecting Line information.
  450. * RDNIS (Redirecting Directory Number Information Service)
  451. * Where a call diversion or transfer was invoked.
  452. * \note All string fields here are malloc'ed, so they need to be
  453. * freed when the structure is deleted.
  454. * \note NULL and "" must be considered equivalent.
  455. */
  456. struct ast_party_redirecting {
  457. /*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) */
  458. struct ast_party_id orig;
  459. /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) */
  460. struct ast_party_id from;
  461. /*! \brief Call is redirecting to a new party (Sent to the caller) */
  462. struct ast_party_id to;
  463. /*! \brief Who originally redirected the call (Sent to the party the call is redirected toward) - private representation */
  464. struct ast_party_id priv_orig;
  465. /*! \brief Who is redirecting the call (Sent to the party the call is redirected toward) - private representation */
  466. struct ast_party_id priv_from;
  467. /*! \brief Call is redirecting to a new party (Sent to the caller) - private representation */
  468. struct ast_party_id priv_to;
  469. /*! \brief Reason for the redirection */
  470. struct ast_party_redirecting_reason reason;
  471. /*! \brief Reason for the redirection by the original party */
  472. struct ast_party_redirecting_reason orig_reason;
  473. /*! \brief Number of times the call was redirected */
  474. int count;
  475. };
  476. /*!
  477. * \since 1.8
  478. * \brief Indicate what information in ast_party_redirecting should be set.
  479. */
  480. struct ast_set_party_redirecting {
  481. /*! What redirecting-orig id information to set. */
  482. struct ast_set_party_id orig;
  483. /*! What redirecting-from id information to set. */
  484. struct ast_set_party_id from;
  485. /*! What redirecting-to id information to set. */
  486. struct ast_set_party_id to;
  487. /*! What private redirecting-orig id information to set. */
  488. struct ast_set_party_id priv_orig;
  489. /*! What private redirecting-from id information to set. */
  490. struct ast_set_party_id priv_from;
  491. /*! What private redirecting-to id information to set. */
  492. struct ast_set_party_id priv_to;
  493. };
  494. /*!
  495. * \brief Typedef for a custom read function
  496. * \note data should be treated as const char *.
  497. */
  498. typedef int (*ast_acf_read_fn_t)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
  499. /*!
  500. * \brief Typedef for a custom read2 function
  501. * \note data should be treated as const char *.
  502. */
  503. typedef int (*ast_acf_read2_fn_t)(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **str, ssize_t len);
  504. /*!
  505. * \brief Typedef for a custom write function
  506. * \note data should be treated as const char *.
  507. */
  508. typedef int (*ast_acf_write_fn_t)(struct ast_channel *chan, const char *function, char *data, const char *value);
  509. /*! \brief Structure to handle passing func_channel_write info to channels via setoption */
  510. typedef struct {
  511. /*! \brief ast_chan_write_info_t version. Must be incremented if structure is changed */
  512. #define AST_CHAN_WRITE_INFO_T_VERSION 1
  513. uint32_t version;
  514. ast_acf_write_fn_t write_fn;
  515. struct ast_channel *chan;
  516. const char *function;
  517. char *data;
  518. const char *value;
  519. } ast_chan_write_info_t;
  520. /*!
  521. * \brief Structure to pass both assignedid values to channel drivers
  522. * \note The second value is used only by core_unreal (LOCAL)
  523. */
  524. struct ast_assigned_ids {
  525. const char *uniqueid;
  526. const char *uniqueid2;
  527. };
  528. /*!
  529. * \brief Forward declaration
  530. */
  531. struct ast_msg_data;
  532. /*!
  533. * \brief
  534. * Structure to describe a channel "technology", ie a channel driver
  535. * See for examples:
  536. * \arg chan_iax2.c - The Inter-Asterisk exchange protocol
  537. * \arg chan_sip.c - The SIP channel driver
  538. * \arg chan_dahdi.c - PSTN connectivity (TDM, PRI, T1/E1, FXO, FXS)
  539. *
  540. * \details
  541. * If you develop your own channel driver, this is where you
  542. * tell the PBX at registration of your driver what properties
  543. * this driver supports and where different callbacks are
  544. * implemented.
  545. */
  546. struct ast_channel_tech {
  547. const char * const type;
  548. const char * const description;
  549. struct ast_format_cap *capabilities; /*!< format capabilities this channel can handle */
  550. int properties; /*!< Technology Properties */
  551. /*!
  552. * \brief Requester - to set up call data structures (pvt's)
  553. *
  554. * \param type type of channel to request
  555. * \param cap Format capabilities for requested channel
  556. * \param assignedid Unique ID string to assign to channel
  557. * \param requestor channel asking for data
  558. * \param addr destination of the call
  559. * \param cause Cause of failure
  560. *
  561. * \details
  562. * Request a channel of a given type, with addr as optional information used
  563. * by the low level module
  564. *
  565. * \retval NULL failure
  566. * \retval non-NULL channel on success
  567. */
  568. struct ast_channel *(* const requester)(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);
  569. int (* const devicestate)(const char *device_number); /*!< Devicestate call back */
  570. /*!
  571. * \brief Start sending a literal DTMF digit
  572. *
  573. * \note The channel is not locked when this function gets called.
  574. */
  575. int (* const send_digit_begin)(struct ast_channel *chan, char digit);
  576. /*!
  577. * \brief Stop sending a literal DTMF digit
  578. *
  579. * \note The channel is not locked when this function gets called.
  580. */
  581. int (* const send_digit_end)(struct ast_channel *chan, char digit, unsigned int duration);
  582. /*!
  583. * \brief Make a call
  584. * \note The channel is locked when called.
  585. * \param chan which channel to make the call on
  586. * \param addr destination of the call
  587. * \param timeout time to wait on for connect (Doesn't seem to be used.)
  588. * \retval 0 on success
  589. * \retval -1 on failure
  590. */
  591. int (* const call)(struct ast_channel *chan, const char *addr, int timeout);
  592. /*! \brief Hangup (and possibly destroy) the channel */
  593. int (* const hangup)(struct ast_channel *chan);
  594. /*! \brief Answer the channel */
  595. int (* const answer)(struct ast_channel *chan);
  596. /*! \brief Read a frame, in standard format (see frame.h) */
  597. struct ast_frame * (* const read)(struct ast_channel *chan);
  598. /*! \brief Write a frame, in standard format (see frame.h) */
  599. int (* const write)(struct ast_channel *chan, struct ast_frame *frame);
  600. /*! \brief Display or transmit text */
  601. int (* const send_text)(struct ast_channel *chan, const char *text);
  602. /*! \brief Display or send an image */
  603. int (* const send_image)(struct ast_channel *chan, struct ast_frame *frame);
  604. /*! \brief Send HTML data */
  605. int (* const send_html)(struct ast_channel *chan, int subclass, const char *data, int len);
  606. /*! \brief Handle an exception, reading a frame */
  607. struct ast_frame * (* const exception)(struct ast_channel *chan);
  608. /*! \brief Bridge two channels of the same type together (early) */
  609. enum ast_bridge_result (* const early_bridge)(struct ast_channel *c0, struct ast_channel *c1);
  610. /*! \brief Indicate a particular condition (e.g. AST_CONTROL_BUSY or AST_CONTROL_RINGING or AST_CONTROL_CONGESTION */
  611. int (* const indicate)(struct ast_channel *c, int condition, const void *data, size_t datalen);
  612. /*! \brief Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links */
  613. int (* const fixup)(struct ast_channel *oldchan, struct ast_channel *newchan);
  614. /*! \brief Set a given option. Called with chan locked */
  615. int (* const setoption)(struct ast_channel *chan, int option, void *data, int datalen);
  616. /*! \brief Query a given option. Called with chan locked */
  617. int (* const queryoption)(struct ast_channel *chan, int option, void *data, int *datalen);
  618. /*! \brief Blind transfer other side (see app_transfer.c and ast_transfer() */
  619. int (* const transfer)(struct ast_channel *chan, const char *newdest);
  620. /*! \brief Write a frame, in standard format */
  621. int (* const write_video)(struct ast_channel *chan, struct ast_frame *frame);
  622. /*! \brief Write a text frame, in standard format */
  623. int (* const write_text)(struct ast_channel *chan, struct ast_frame *frame);
  624. /*!
  625. * \brief Provide additional read items for CHANNEL() dialplan function
  626. * \note data should be treated as a const char *.
  627. */
  628. int (* func_channel_read)(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
  629. /*!
  630. * \brief Provide additional write items for CHANNEL() dialplan function
  631. * \note data should be treated as a const char *.
  632. */
  633. int (* func_channel_write)(struct ast_channel *chan, const char *function, char *data, const char *value);
  634. /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */
  635. const char * (* get_pvt_uniqueid)(struct ast_channel *chan);
  636. /*! \brief Call a function with cc parameters as a function parameter
  637. *
  638. * \details
  639. * This is a highly specialized callback that is not likely to be needed in many
  640. * channel drivers. When dealing with a busy channel, for instance, most channel
  641. * drivers will successfully return a channel to the requester. Once called, the channel
  642. * can then queue a busy frame when it receives an appropriate message from the far end.
  643. * In such a case, the channel driver has the opportunity to also queue a CC frame.
  644. * The parameters for the CC channel can be retrieved from the channel structure.
  645. *
  646. * For other channel drivers, notably those that deal with "dumb" phones, the channel
  647. * driver will not return a channel when one is requested. In such a scenario, there is never
  648. * an opportunity for the channel driver to queue a CC frame since the channel is never
  649. * called. Furthermore, it is not possible to retrieve the CC configuration parameters
  650. * for the desired channel because no channel is ever allocated or returned to the
  651. * requester. In such a case, call completion may still be a viable option. What we do is
  652. * pass the same string that the requester used originally to request the channel to the
  653. * channel driver. The channel driver can then find any potential channels/devices that
  654. * match the input and return call the designated callback with the device's call completion
  655. * parameters as a parameter.
  656. */
  657. int (* cc_callback)(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
  658. /*!
  659. * \brief Execute a Gosub call on the channel in a technology specific way before a call is placed.
  660. * \since 11.0
  661. *
  662. * \param chan Channel to execute Gosub in a tech specific way.
  663. * \param sub_args Gosub application parameter string.
  664. *
  665. * \note The chan is locked before calling.
  666. *
  667. * \retval 0 on success.
  668. * \retval -1 on error.
  669. */
  670. int (*pre_call)(struct ast_channel *chan, const char *sub_args);
  671. /*! \brief Display or transmit text with data*/
  672. int (* const send_text_data)(struct ast_channel *chan, struct ast_msg_data *data);
  673. };
  674. /*! Kill the channel channel driver technology descriptor. */
  675. extern const struct ast_channel_tech ast_kill_tech;
  676. struct ast_epoll_data;
  677. /*!
  678. * The high bit of the frame count is used as a debug marker, so
  679. * increments of the counters must be done with care.
  680. * Please use c->fin = FRAMECOUNT_INC(c->fin) and the same for c->fout.
  681. */
  682. #define DEBUGCHAN_FLAG 0x80000000
  683. /* XXX not ideal to evaluate x twice... */
  684. #define FRAMECOUNT_INC(x) ( ((x) & DEBUGCHAN_FLAG) | (((x)+1) & ~DEBUGCHAN_FLAG) )
  685. /*!
  686. * The current value of the debug flags is stored in the two
  687. * variables global_fin and global_fout (declared in main/channel.c)
  688. */
  689. extern unsigned long global_fin, global_fout;
  690. enum ast_channel_adsicpe {
  691. AST_ADSI_UNKNOWN,
  692. AST_ADSI_AVAILABLE,
  693. AST_ADSI_UNAVAILABLE,
  694. AST_ADSI_OFFHOOKONLY,
  695. };
  696. /*!
  697. * \brief Possible T38 states on channels
  698. */
  699. enum ast_t38_state {
  700. T38_STATE_UNAVAILABLE, /*!< T38 is unavailable on this channel or disabled by configuration */
  701. T38_STATE_UNKNOWN, /*!< The channel supports T38 but the current status is unknown */
  702. T38_STATE_NEGOTIATING, /*!< T38 is being negotiated */
  703. T38_STATE_REJECTED, /*!< Remote side has rejected our offer */
  704. T38_STATE_NEGOTIATED, /*!< T38 established */
  705. };
  706. /*! Hangup handler instance node. */
  707. struct ast_hangup_handler {
  708. /*! Next hangup handler node. */
  709. AST_LIST_ENTRY(ast_hangup_handler) node;
  710. /*! Hangup handler arg string passed to the Gosub application */
  711. char args[0];
  712. };
  713. AST_LIST_HEAD_NOLOCK(ast_hangup_handler_list, ast_hangup_handler);
  714. AST_LIST_HEAD_NOLOCK(ast_datastore_list, ast_datastore);
  715. AST_LIST_HEAD_NOLOCK(ast_autochan_list, ast_autochan);
  716. AST_LIST_HEAD_NOLOCK(ast_readq_list, ast_frame);
  717. typedef int(*ast_timing_func_t)(const void *data);
  718. /*!
  719. * \page AstChannel ast_channel locking and reference tracking
  720. *
  721. * \par Creating Channels
  722. * A channel is allocated using the ast_channel_alloc() function. When created, it is
  723. * automatically inserted into the main channels hash table that keeps track of all
  724. * active channels in the system. The hash key is based on the channel name. Because
  725. * of this, if you want to change the name, you _must_ use ast_change_name(), not change
  726. * the name field directly. When ast_channel_alloc() returns a channel pointer, you now
  727. * hold both a reference to that channel and a lock on the channel. Once the channel has
  728. * been set up the lock can be released. In most cases the reference is given to ast_pbx_run().
  729. *
  730. * \par Channel Locking
  731. * There is a lock associated with every ast_channel. It is allocated internally via astobj2.
  732. * To lock or unlock a channel, you must use the ast_channel_lock() wrappers.
  733. *
  734. * Previously, before ast_channel was converted to astobj2, the channel lock was used in some
  735. * additional ways that are no longer necessary. Before, the only way to ensure that a channel
  736. * did not disappear out from under you if you were working with a channel outside of the channel
  737. * thread that owns it, was to hold the channel lock. Now, that is no longer necessary.
  738. * You simply must hold a reference to the channel to ensure it does not go away.
  739. *
  740. * The channel must be locked if you need to ensure that data that you reading from the channel
  741. * does not change while you access it. Further, you must hold the channel lock if you are
  742. * making a non-atomic change to channel data.
  743. *
  744. * \par Channel References
  745. * There are multiple ways to get a reference to a channel. The first is that you hold a reference
  746. * to a channel after creating it. The other ways involve using the channel search or the channel
  747. * traversal APIs. These functions are the ast_channel_get_*() functions or ast_channel_iterator_*()
  748. * functions. Once a reference is retrieved by one of these methods, you know that the channel will
  749. * not go away. So, the channel should only get locked as needed for data access or modification.
  750. * But, make sure that the reference gets released when you are done with it!
  751. *
  752. * There are different things you can do when you are done with a reference to a channel. The first
  753. * is to simply release the reference using ast_channel_unref(). The other option is to call
  754. * ast_channel_release(). This function is generally used where ast_channel_free() was used in
  755. * the past. The release function releases a reference as well as ensures that the channel is no
  756. * longer in the global channels container. That way, the channel will get destroyed as soon as any
  757. * other pending references get released.
  758. *
  759. * \par Exceptions to the rules
  760. * Even though ast_channel is reference counted, there are some places where pointers to an ast_channel
  761. * get stored, but the reference count does not reflect it. The reason is mostly historical.
  762. * The only places where this happens should be places where because of how the code works, we
  763. * _know_ that the pointer to the channel will get removed before the channel goes away. The main
  764. * example of this is in channel drivers. Channel drivers generally store a pointer to their owner
  765. * ast_channel in their technology specific pvt struct. In this case, the channel drivers _know_
  766. * that this pointer to the channel will be removed in time, because the channel's hangup callback
  767. * gets called before the channel goes away.
  768. */
  769. struct ast_channel;
  770. /*! \brief ast_channel_tech Properties */
  771. enum {
  772. /*!
  773. * \brief Channels have this property if they can accept input with jitter;
  774. * i.e. most VoIP channels
  775. */
  776. AST_CHAN_TP_WANTSJITTER = (1 << 0),
  777. /*!
  778. * \brief Channels have this property if they can create jitter;
  779. * i.e. most VoIP channels
  780. */
  781. AST_CHAN_TP_CREATESJITTER = (1 << 1),
  782. /*!
  783. * \brief Channels with this particular technology are an implementation detail of
  784. * Asterisk and should generally not be exposed or manipulated by the outside
  785. * world
  786. */
  787. AST_CHAN_TP_INTERNAL = (1 << 2),
  788. /*!
  789. * \brief Channels have this property if they implement send_text_data
  790. */
  791. AST_CHAN_TP_SEND_TEXT_DATA = (1 << 3),
  792. };
  793. /*! \brief ast_channel flags */
  794. enum {
  795. /*! Queue incoming DTMF, to be released when this flag is turned off */
  796. AST_FLAG_DEFER_DTMF = (1 << 1),
  797. /*! write should be interrupt generator */
  798. AST_FLAG_WRITE_INT = (1 << 2),
  799. /*! a thread is blocking on this channel */
  800. AST_FLAG_BLOCKING = (1 << 3),
  801. /*! This is a zombie channel */
  802. AST_FLAG_ZOMBIE = (1 << 4),
  803. /*! There is an exception pending */
  804. AST_FLAG_EXCEPTION = (1 << 5),
  805. /*! Listening to moh XXX anthm promises me this will disappear XXX */
  806. AST_FLAG_MOH = (1 << 6),
  807. /*! This channel is spying on another channel */
  808. AST_FLAG_SPYING = (1 << 7),
  809. /*! the channel is in an auto-incrementing dialplan processor,
  810. * so when ->priority is set, it will get incremented before
  811. * finding the next priority to run */
  812. AST_FLAG_IN_AUTOLOOP = (1 << 9),
  813. /*! This is an outgoing call */
  814. AST_FLAG_OUTGOING = (1 << 10),
  815. /*! A DTMF_BEGIN frame has been read from this channel, but not yet an END */
  816. AST_FLAG_IN_DTMF = (1 << 12),
  817. /*! A DTMF_END was received when not IN_DTMF, so the length of the digit is
  818. * currently being emulated */
  819. AST_FLAG_EMULATE_DTMF = (1 << 13),
  820. /*! This is set to tell the channel not to generate DTMF begin frames, and
  821. * to instead only generate END frames. */
  822. AST_FLAG_END_DTMF_ONLY = (1 << 14),
  823. /* OBSOLETED in favor of AST_CAUSE_ANSWERED_ELSEWHERE
  824. * Flag to show channels that this call is hangup due to the fact that the call
  825. * was indeed answered, but in another channel */
  826. /* AST_FLAG_ANSWERED_ELSEWHERE = (1 << 15), */
  827. /*! This flag indicates that on a masquerade, an active stream should not
  828. * be carried over */
  829. AST_FLAG_MASQ_NOSTREAM = (1 << 16),
  830. /*! This flag indicates that the hangup exten was run when the bridge terminated,
  831. * a message aimed at preventing a subsequent hangup exten being run at the pbx_run
  832. * level */
  833. AST_FLAG_BRIDGE_HANGUP_RUN = (1 << 17),
  834. /*! Disable certain workarounds. This reintroduces certain bugs, but allows
  835. * some non-traditional dialplans (like AGI) to continue to function.
  836. */
  837. AST_FLAG_DISABLE_WORKAROUNDS = (1 << 20),
  838. /*!
  839. * Disable device state event caching. This allows channel
  840. * drivers to selectively prevent device state events from being
  841. * cached by certain channels such as anonymous calls which have
  842. * no persistent represenatation that can be tracked.
  843. */
  844. AST_FLAG_DISABLE_DEVSTATE_CACHE = (1 << 21),
  845. /*!
  846. * This flag indicates that a dual channel redirect is in
  847. * progress. The bridge needs to wait until the flag is cleared
  848. * to continue.
  849. */
  850. AST_FLAG_BRIDGE_DUAL_REDIRECT_WAIT = (1 << 22),
  851. /*!
  852. * This flag indicates that the channel was originated.
  853. */
  854. AST_FLAG_ORIGINATED = (1 << 23),
  855. /*!
  856. * The channel is well and truly dead. Once this is set and published, no further
  857. * actions should be taken upon the channel, and no further publications should
  858. * occur.
  859. */
  860. AST_FLAG_DEAD = (1 << 24),
  861. /*!
  862. * Channel snapshot should not be published, it is being staged for an explicit
  863. * publish.
  864. */
  865. AST_FLAG_SNAPSHOT_STAGE = (1 << 25),
  866. /*!
  867. * The data on chan->timingdata is an astobj2 object.
  868. */
  869. AST_FLAG_TIMINGDATA_IS_AO2_OBJ = (1 << 26),
  870. /*!
  871. * The channel is executing a subroutine or macro
  872. */
  873. AST_FLAG_SUBROUTINE_EXEC = (1 << 27),
  874. };
  875. /*! \brief ast_bridge_config flags */
  876. enum {
  877. AST_FEATURE_PLAY_WARNING = (1 << 0),
  878. AST_FEATURE_REDIRECT = (1 << 1),
  879. AST_FEATURE_DISCONNECT = (1 << 2),
  880. AST_FEATURE_ATXFER = (1 << 3),
  881. AST_FEATURE_AUTOMON = (1 << 4),
  882. AST_FEATURE_PARKCALL = (1 << 5),
  883. AST_FEATURE_AUTOMIXMON = (1 << 6),
  884. };
  885. #define AST_FEATURE_DTMF_MASK (AST_FEATURE_REDIRECT | AST_FEATURE_DISCONNECT |\
  886. AST_FEATURE_ATXFER | AST_FEATURE_AUTOMON | AST_FEATURE_PARKCALL | AST_FEATURE_AUTOMIXMON)
  887. /*! \brief bridge configuration */
  888. struct ast_bridge_config {
  889. struct ast_flags features_caller;
  890. struct ast_flags features_callee;
  891. struct timeval start_time;
  892. struct timeval nexteventts;
  893. struct timeval feature_start_time;
  894. long feature_timer;
  895. long timelimit;
  896. long play_warning;
  897. long warning_freq;
  898. const char *warning_sound;
  899. const char *end_sound;
  900. const char *start_sound;
  901. unsigned int flags;
  902. void (* end_bridge_callback)(void *); /*!< A callback that is called after a bridge attempt */
  903. void *end_bridge_callback_data; /*!< Data passed to the callback */
  904. /*! If the end_bridge_callback_data refers to a channel which no longer is going to
  905. * exist when the end_bridge_callback is called, then it needs to be fixed up properly
  906. */
  907. void (*end_bridge_callback_data_fixup)(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator);
  908. };
  909. struct chanmon;
  910. struct outgoing_helper {
  911. const char *context;
  912. const char *exten;
  913. int priority;
  914. int connect_on_early_media; /* If set, treat session progress as answer */
  915. const char *cid_num;
  916. const char *cid_name;
  917. const char *account;
  918. struct ast_variable *vars;
  919. struct ast_channel *parent_channel;
  920. };
  921. enum {
  922. /*!
  923. * Soft hangup requested by device or other internal reason.
  924. * Actual hangup needed.
  925. */
  926. AST_SOFTHANGUP_DEV = (1 << 0),
  927. /*!
  928. * Used to break the normal frame flow so an async goto can be
  929. * done instead of actually hanging up.
  930. */
  931. AST_SOFTHANGUP_ASYNCGOTO = (1 << 1),
  932. /*!
  933. * Soft hangup requested by system shutdown. Actual hangup
  934. * needed.
  935. */
  936. AST_SOFTHANGUP_SHUTDOWN = (1 << 2),
  937. /*!
  938. * Used to break the normal frame flow after a timeout so an
  939. * implicit async goto can be done to the 'T' exten if it exists
  940. * instead of actually hanging up. If the exten does not exist
  941. * then actually hangup.
  942. */
  943. AST_SOFTHANGUP_TIMEOUT = (1 << 3),
  944. /*!
  945. * Soft hangup requested by application/channel-driver being
  946. * unloaded. Actual hangup needed.
  947. */
  948. AST_SOFTHANGUP_APPUNLOAD = (1 << 4),
  949. /*!
  950. * Soft hangup requested by non-associated party. Actual hangup
  951. * needed.
  952. */
  953. AST_SOFTHANGUP_EXPLICIT = (1 << 5),
  954. /*!
  955. * Used to indicate that the channel is currently executing hangup
  956. * logic in the dialplan. The channel has been hungup when this is
  957. * set.
  958. */
  959. AST_SOFTHANGUP_HANGUP_EXEC = (1 << 7),
  960. /*!
  961. * \brief All softhangup flags.
  962. *
  963. * This can be used as an argument to ast_channel_clear_softhangup()
  964. * to clear all softhangup flags from a channel.
  965. */
  966. AST_SOFTHANGUP_ALL = (0xFFFFFFFF)
  967. };
  968. /*! \brief Channel reload reasons for manager events at load or reload of configuration */
  969. enum channelreloadreason {
  970. CHANNEL_MODULE_LOAD,
  971. CHANNEL_MODULE_RELOAD,
  972. CHANNEL_CLI_RELOAD,
  973. CHANNEL_MANAGER_RELOAD,
  974. CHANNEL_ACL_RELOAD,
  975. };
  976. /*!
  977. * \brief Channel AMA Flags
  978. */
  979. enum ama_flags {
  980. AST_AMA_NONE = 0,
  981. AST_AMA_OMIT,
  982. AST_AMA_BILLING,
  983. AST_AMA_DOCUMENTATION,
  984. };
  985. /*!
  986. * \note None of the datastore API calls lock the ast_channel they are using.
  987. * So, the channel should be locked before calling the functions that
  988. * take a channel argument.
  989. */
  990. /*!
  991. * \brief Create a channel data store object
  992. * \deprecated You should use the ast_datastore_alloc() generic function instead.
  993. * \version 1.6.1 deprecated
  994. */
  995. struct ast_datastore *ast_channel_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
  996. __attribute__((deprecated));
  997. /*!
  998. * \brief Free a channel data store object
  999. * \deprecated You should use the ast_datastore_free() generic function instead.
  1000. * \version 1.6.1 deprecated
  1001. */
  1002. int ast_channel_datastore_free(struct ast_datastore *datastore)
  1003. __attribute__((deprecated));
  1004. /*! \brief Inherit datastores from a parent to a child. */
  1005. int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to);
  1006. /*!
  1007. * \brief Add a datastore to a channel
  1008. *
  1009. * \note The channel should be locked before calling this function.
  1010. *
  1011. * \retval 0 success
  1012. * \retval non-zero failure
  1013. */
  1014. int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore);
  1015. /*!
  1016. * \brief Remove a datastore from a channel
  1017. *
  1018. * \note The channel should be locked before calling this function.
  1019. *
  1020. * \retval 0 success
  1021. * \retval non-zero failure
  1022. */
  1023. int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore);
  1024. /*!
  1025. * \brief Find a datastore on a channel
  1026. *
  1027. * \note The channel should be locked before calling this function.
  1028. *
  1029. * \note The datastore returned from this function must not be used if the
  1030. * reference to the channel is released.
  1031. *
  1032. * \retval pointer to the datastore if found
  1033. * \retval NULL if not found
  1034. */
  1035. struct ast_datastore *ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid);
  1036. /*!
  1037. * \brief Create a channel structure
  1038. * \since 1.8
  1039. *
  1040. * \retval NULL failure
  1041. * \retval non-NULL successfully allocated channel
  1042. *
  1043. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1044. * \note By default, new channels are set to the "s" extension
  1045. * and "default" context.
  1046. * \note Since 12.0.0 this function returns with the newly created channel locked.
  1047. */
  1048. struct ast_channel * __attribute__((format(printf, 15, 16)))
  1049. __ast_channel_alloc(int needqueue, int state, const char *cid_num,
  1050. const char *cid_name, const char *acctcode,
  1051. const char *exten, const char *context, const struct ast_assigned_ids *assignedids,
  1052. const struct ast_channel *requestor, enum ama_flags amaflag,
  1053. struct ast_endpoint *endpoint,
  1054. const char *file, int line, const char *function,
  1055. const char *name_fmt, ...);
  1056. /*!
  1057. * \brief Create a channel structure
  1058. *
  1059. * \retval NULL failure
  1060. * \retval non-NULL successfully allocated channel
  1061. *
  1062. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1063. * \note By default, new channels are set to the "s" extension
  1064. * and "default" context.
  1065. * \note Since 12.0.0 this function returns with the newly created channel locked.
  1066. */
  1067. #define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, ...) \
  1068. __ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, NULL, \
  1069. __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
  1070. #define ast_channel_alloc_with_endpoint(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag, endpoint, ...) \
  1071. __ast_channel_alloc((needqueue), (state), (cid_num), (cid_name), (acctcode), (exten), (context), (assignedids), (requestor), (amaflag), (endpoint), \
  1072. __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
  1073. #if defined(REF_DEBUG) || defined(__AST_DEBUG_MALLOC)
  1074. /*!
  1075. * \brief Create a fake channel structure
  1076. *
  1077. * \retval NULL failure
  1078. * \retval non-NULL successfully allocated channel
  1079. *
  1080. * \note This function should ONLY be used to create a fake channel
  1081. * that can then be populated with data for use in variable
  1082. * substitution when a real channel does not exist.
  1083. *
  1084. * \note The created dummy channel should be destroyed by
  1085. * ast_channel_unref(). Using ast_channel_release() needlessly
  1086. * grabs the channel container lock and can cause a deadlock as
  1087. * a result. Also grabbing the channel container lock reduces
  1088. * system performance.
  1089. */
  1090. #define ast_dummy_channel_alloc() __ast_dummy_channel_alloc(__FILE__, __LINE__, __PRETTY_FUNCTION__)
  1091. struct ast_channel *__ast_dummy_channel_alloc(const char *file, int line, const char *function);
  1092. #else
  1093. /*!
  1094. * \brief Create a fake channel structure
  1095. *
  1096. * \retval NULL failure
  1097. * \retval non-NULL successfully allocated channel
  1098. *
  1099. * \note This function should ONLY be used to create a fake channel
  1100. * that can then be populated with data for use in variable
  1101. * substitution when a real channel does not exist.
  1102. *
  1103. * \note The created dummy channel should be destroyed by
  1104. * ast_channel_unref(). Using ast_channel_release() needlessly
  1105. * grabs the channel container lock and can cause a deadlock as
  1106. * a result. Also grabbing the channel container lock reduces
  1107. * system performance.
  1108. */
  1109. struct ast_channel *ast_dummy_channel_alloc(void);
  1110. #endif
  1111. /*!
  1112. * \brief Queue one or more frames to a channel's frame queue
  1113. *
  1114. * \param chan the channel to queue the frame(s) on
  1115. * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
  1116. * by this function. It is the responsibility of the caller to handle
  1117. * freeing the memory associated with the frame(s) being passed if
  1118. * necessary.
  1119. *
  1120. * \retval 0 success
  1121. * \retval non-zero failure
  1122. */
  1123. int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f);
  1124. /*!
  1125. * \brief Queue one or more frames to the head of a channel's frame queue
  1126. *
  1127. * \param chan the channel to queue the frame(s) on
  1128. * \param f the frame(s) to queue. Note that the frame(s) will be duplicated
  1129. * by this function. It is the responsibility of the caller to handle
  1130. * freeing the memory associated with the frame(s) being passed if
  1131. * necessary.
  1132. *
  1133. * \retval 0 success
  1134. * \retval non-zero failure
  1135. */
  1136. int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f);
  1137. /*!
  1138. * \brief Queue a hangup frame
  1139. *
  1140. * \note The channel does not need to be locked before calling this function.
  1141. */
  1142. int ast_queue_hangup(struct ast_channel *chan);
  1143. /*!
  1144. * \brief Queue a hangup frame with hangupcause set
  1145. *
  1146. * \note The channel does not need to be locked before calling this function.
  1147. * \param[in] chan channel to queue frame onto
  1148. * \param[in] cause the hangup cause
  1149. * \return 0 on success, -1 on error
  1150. * \since 1.6.1
  1151. */
  1152. int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause);
  1153. /*!
  1154. * \brief Queue a hold frame
  1155. *
  1156. * \param chan channel to queue frame onto
  1157. * \param musicclass The suggested musicclass for the other end to use
  1158. *
  1159. * \note The channel does not need to be locked before calling this function.
  1160. *
  1161. * \retval zero on success
  1162. * \retval non-zero on failure
  1163. */
  1164. int ast_queue_hold(struct ast_channel *chan, const char *musicclass);
  1165. /*!
  1166. * \brief Queue an unhold frame
  1167. *
  1168. * \param chan channel to queue frame onto
  1169. *
  1170. * \note The channel does not need to be locked before calling this function.
  1171. *
  1172. * \retval zero on success
  1173. * \retval non-zero on failure
  1174. */
  1175. int ast_queue_unhold(struct ast_channel *chan);
  1176. /*!
  1177. * \brief Queue a control frame without payload
  1178. *
  1179. * \param chan channel to queue frame onto
  1180. * \param control type of control frame
  1181. *
  1182. * \note The channel does not need to be locked before calling this function.
  1183. *
  1184. * \retval zero on success
  1185. * \retval non-zero on failure
  1186. */
  1187. int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control);
  1188. /*!
  1189. * \brief Queue a control frame with payload
  1190. *
  1191. * \param chan channel to queue frame onto
  1192. * \param control type of control frame
  1193. * \param data pointer to payload data to be included in frame
  1194. * \param datalen number of bytes of payload data
  1195. *
  1196. * \retval 0 success
  1197. * \retval non-zero failure
  1198. *
  1199. * \details
  1200. * The supplied payload data is copied into the frame, so the caller's copy
  1201. * is not modified nor freed, and the resulting frame will retain a copy of
  1202. * the data even if the caller frees their local copy.
  1203. *
  1204. * \note This method should be treated as a 'network transport'; in other
  1205. * words, your frames may be transferred across an IAX2 channel to another
  1206. * system, which may be a different endianness than yours. Because of this,
  1207. * you should ensure that either your frames will never be expected to work
  1208. * across systems, or that you always put your payload data into 'network byte
  1209. * order' before calling this function.
  1210. *
  1211. * \note The channel does not need to be locked before calling this function.
  1212. */
  1213. int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control,
  1214. const void *data, size_t datalen);
  1215. /*!
  1216. * \brief Change channel name
  1217. *
  1218. * \pre Absolutely all channels _MUST_ be unlocked before calling this function.
  1219. *
  1220. * \param chan the channel to change the name of
  1221. * \param newname the name to change to
  1222. *
  1223. * \return nothing
  1224. *
  1225. * \note this function must _NEVER_ be used when any channels are locked
  1226. * regardless if it is the channel who's name is being changed or not because
  1227. * it invalidates our channel container locking order... lock container first,
  1228. * then the individual channels, never the other way around.
  1229. */
  1230. void ast_change_name(struct ast_channel *chan, const char *newname);
  1231. /*!
  1232. * \brief Unlink and release reference to a channel
  1233. *
  1234. * This function will unlink the channel from the global channels container
  1235. * if it is still there and also release the current reference to the channel.
  1236. *
  1237. * \return NULL, convenient for clearing invalid pointers
  1238. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1239. *
  1240. * \since 1.8
  1241. */
  1242. struct ast_channel *ast_channel_release(struct ast_channel *chan);
  1243. /*!
  1244. * \brief Requests a channel
  1245. *
  1246. * \param type type of channel to request
  1247. * \param request_cap Format capabilities for requested channel
  1248. * \param assignedids Unique ID to create channel with
  1249. * \param requestor channel asking for data
  1250. * \param addr destination of the call
  1251. * \param cause Cause of failure
  1252. *
  1253. * \details
  1254. * Request a channel of a given type, with addr as optional information used
  1255. * by the low level module
  1256. *
  1257. * \retval NULL failure
  1258. * \retval non-NULL channel on success
  1259. */
  1260. struct ast_channel *ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause);
  1261. enum ast_channel_requestor_relationship {
  1262. /*! The requestor is the future bridge peer of the channel. */
  1263. AST_CHANNEL_REQUESTOR_BRIDGE_PEER,
  1264. /*! The requestor is to be replaced by the channel. */
  1265. AST_CHANNEL_REQUESTOR_REPLACEMENT,
  1266. };
  1267. /*!
  1268. * \brief Setup new channel accountcodes from the requestor channel after ast_request().
  1269. * \since 13.0.0
  1270. *
  1271. * \param chan New channel to get accountcodes setup.
  1272. * \param requestor Requesting channel to get accountcodes from.
  1273. * \param relationship What the new channel was created for.
  1274. *
  1275. * \pre The chan and requestor channels are already locked.
  1276. *
  1277. * \note Pre-existing accountcodes on chan will be overwritten.
  1278. *
  1279. * \return Nothing
  1280. */
  1281. void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship);
  1282. /*!
  1283. * \brief Setup new channel accountcodes from the requestor channel after ast_request().
  1284. * \since 13.0.0
  1285. *
  1286. * \param chan New channel to get accountcodes setup.
  1287. * \param requestor Requesting channel to get accountcodes from.
  1288. * \param relationship What the new channel was created for.
  1289. *
  1290. * \pre The chan and requestor channels are already locked.
  1291. *
  1292. * \note Pre-existing accountcodes on chan will not be overwritten.
  1293. *
  1294. * \return Nothing
  1295. */
  1296. void ast_channel_req_accountcodes_precious(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship);
  1297. /*!
  1298. * \brief Request a channel of a given type, with data as optional information used
  1299. * by the low level module and attempt to place a call on it
  1300. *
  1301. * \param type type of channel to request
  1302. * \param cap format capabilities for requested channel
  1303. * \param assignedids Unique Id to assign to channel
  1304. * \param requestor channel asking for data
  1305. * \param addr destination of the call
  1306. * \param timeout maximum amount of time to wait for an answer
  1307. * \param reason why unsuccessful (if unsuccessful)
  1308. * \param cid_num Caller-ID Number
  1309. * \param cid_name Caller-ID Name (ascii)
  1310. *
  1311. * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
  1312. * to know if the call was answered or not.
  1313. */
  1314. struct ast_channel *ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr,
  1315. int timeout, int *reason, const char *cid_num, const char *cid_name);
  1316. /*!
  1317. * \brief Request a channel of a given type, with data as optional information used
  1318. * by the low level module and attempt to place a call on it
  1319. * \param type type of channel to request
  1320. * \param cap format capabilities for requested channel
  1321. * \param assignedids Unique Id to assign to channel
  1322. * \param requestor channel requesting data
  1323. * \param addr destination of the call
  1324. * \param timeout maximum amount of time to wait for an answer
  1325. * \param reason why unsuccessful (if unsuccessful)
  1326. * \param cid_num Caller-ID Number
  1327. * \param cid_name Caller-ID Name (ascii)
  1328. * \param oh Outgoing helper
  1329. * \return Returns an ast_channel on success or no answer, NULL on failure. Check the value of chan->_state
  1330. * to know if the call was answered or not.
  1331. */
  1332. struct ast_channel *__ast_request_and_dial(const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr,
  1333. int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh);
  1334. /*!
  1335. * \brief Forwards a call to a new channel specified by the original channel's call_forward str. If possible, the new forwarded channel is created and returned while the original one is terminated.
  1336. * \param caller in channel that requested orig
  1337. * \param orig channel being replaced by the call forward channel
  1338. * \param timeout maximum amount of time to wait for setup of new forward channel
  1339. * \param cap format capabilities for requested channel
  1340. * \param oh outgoing helper used with original channel
  1341. * \param outstate reason why unsuccessful (if uncuccessful)
  1342. * \return Returns the forwarded call's ast_channel on success or NULL on failure
  1343. */
  1344. struct ast_channel *ast_call_forward(struct ast_channel *caller, struct ast_channel *orig, int *timeout, struct ast_format_cap *cap, struct outgoing_helper *oh, int *outstate);
  1345. /*!
  1346. * \brief Register a channel technology (a new channel driver)
  1347. * Called by a channel module to register the kind of channels it supports.
  1348. * \param tech Structure defining channel technology or "type"
  1349. * \return Returns 0 on success, -1 on failure.
  1350. */
  1351. int ast_channel_register(const struct ast_channel_tech *tech);
  1352. /*!
  1353. * \brief Unregister a channel technology
  1354. * \param tech Structure defining channel technology or "type" that was previously registered
  1355. * \return No return value.
  1356. */
  1357. void ast_channel_unregister(const struct ast_channel_tech *tech);
  1358. /*!
  1359. * \brief Get a channel technology structure by name
  1360. * \param name name of technology to find
  1361. * \return a pointer to the structure, or NULL if no matching technology found
  1362. */
  1363. const struct ast_channel_tech *ast_get_channel_tech(const char *name);
  1364. /*!
  1365. * \brief Hang up a channel
  1366. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1367. * \note This function performs a hard hangup on a channel. Unlike the soft-hangup, this function
  1368. * performs all stream stopping, etc, on the channel that needs to end.
  1369. * chan is no longer valid after this call.
  1370. * \param chan channel to hang up (NULL tolerant)
  1371. * \return Nothing
  1372. */
  1373. void ast_hangup(struct ast_channel *chan);
  1374. /*!
  1375. * \brief Soft hangup all active channels.
  1376. * \since 13.3.0
  1377. *
  1378. * \return Nothing
  1379. */
  1380. void ast_softhangup_all(void);
  1381. /*!
  1382. * \brief Softly hangup up a channel
  1383. *
  1384. * \param chan channel to be soft-hung-up
  1385. * \param reason an AST_SOFTHANGUP_* reason code
  1386. *
  1387. * \details
  1388. * Call the protocol layer, but don't destroy the channel structure
  1389. * (use this if you are trying to
  1390. * safely hangup a channel managed by another thread.
  1391. *
  1392. * \note The channel passed to this function does not need to be locked.
  1393. *
  1394. * \return Returns 0 regardless
  1395. */
  1396. int ast_softhangup(struct ast_channel *chan, int reason);
  1397. /*!
  1398. * \brief Softly hangup up a channel (no channel lock)
  1399. * \param chan channel to be soft-hung-up
  1400. * \param reason an AST_SOFTHANGUP_* reason code
  1401. */
  1402. int ast_softhangup_nolock(struct ast_channel *chan, int reason);
  1403. /*!
  1404. * \brief Clear a set of softhangup flags from a channel
  1405. *
  1406. * Never clear a softhangup flag from a channel directly. Instead,
  1407. * use this function. This ensures that all aspects of the softhangup
  1408. * process are aborted.
  1409. *
  1410. * \param chan the channel to clear the flag on
  1411. * \param flag the flag or flags to clear
  1412. *
  1413. * \return Nothing.
  1414. */
  1415. void ast_channel_clear_softhangup(struct ast_channel *chan, int flag);
  1416. /*!
  1417. * \brief Set the source of the hangup in this channel and it's bridge
  1418. *
  1419. * \param chan channel to set the field on
  1420. * \param source a string describing the source of the hangup for this channel
  1421. * \param force
  1422. *
  1423. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1424. *
  1425. * \since 1.8
  1426. *
  1427. * Hangupsource is generally the channel name that caused the bridge to be
  1428. * hung up, but it can also be other things such as "dialplan/agi"
  1429. * This can then be logged in the CDR or CEL
  1430. */
  1431. void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force);
  1432. /*! \brief Check to see if a channel is needing hang up
  1433. * \param chan channel on which to check for hang up
  1434. * This function determines if the channel is being requested to be hung up.
  1435. * \return Returns 0 if not, or 1 if hang up is requested (including time-out).
  1436. */
  1437. int ast_check_hangup(struct ast_channel *chan);
  1438. int ast_check_hangup_locked(struct ast_channel *chan);
  1439. /*! \brief This function will check if the bridge needs to be re-evaluated due to
  1440. * external changes.
  1441. *
  1442. * \param chan Channel on which to check the unbridge_eval flag
  1443. *
  1444. * \return Returns 0 if the flag is down or 1 if the flag is up.
  1445. */
  1446. int ast_channel_unbridged(struct ast_channel *chan);
  1447. /*! \brief ast_channel_unbridged variant. Use this if the channel
  1448. * is already locked prior to calling.
  1449. *
  1450. * \param chan Channel on which to check the unbridge flag
  1451. *
  1452. * \return Returns 0 if the flag is down or 1 if the flag is up.
  1453. */
  1454. int ast_channel_unbridged_nolock(struct ast_channel *chan);
  1455. /*! \brief Sets the unbridged flag and queues a NULL frame on the channel to trigger
  1456. * a check by bridge_channel_wait
  1457. *
  1458. * \param chan Which channel is having its unbridged value set
  1459. * \param value What the unbridge value is being set to
  1460. */
  1461. void ast_channel_set_unbridged(struct ast_channel *chan, int value);
  1462. /*! \brief Variant of ast_channel_set_unbridged. Use this if the channel
  1463. * is already locked prior to calling.
  1464. *
  1465. * \param chan Which channel is having its unbridged value set
  1466. * \param value What the unbridge value is being set to
  1467. */
  1468. void ast_channel_set_unbridged_nolock(struct ast_channel *chan, int value);
  1469. /*!
  1470. * \brief This function will check if T.38 is active on the channel.
  1471. *
  1472. * \param chan Channel on which to check the unbridge_eval flag
  1473. *
  1474. * \return Returns 0 if the flag is down or 1 if the flag is up.
  1475. */
  1476. int ast_channel_is_t38_active(struct ast_channel *chan);
  1477. /*!
  1478. * \brief ast_channel_is_t38_active variant. Use this if the channel
  1479. * is already locked prior to calling.
  1480. *
  1481. * \param chan Channel on which to check the is_t38_active flag
  1482. *
  1483. * \return Returns 0 if the flag is down or 1 if the flag is up.
  1484. */
  1485. int ast_channel_is_t38_active_nolock(struct ast_channel *chan);
  1486. /*!
  1487. * \brief Sets the is_t38_active flag
  1488. *
  1489. * \param chan Which channel is having its is_t38_active value set
  1490. * \param is_t38_active Non-zero if T.38 is active
  1491. */
  1492. void ast_channel_set_is_t38_active(struct ast_channel *chan, int is_t38_active);
  1493. /*!
  1494. * \brief Variant of ast_channel_set_is_t38_active. Use this if the channel
  1495. * is already locked prior to calling.
  1496. *
  1497. * \param chan Which channel is having its is_t38_active value set
  1498. * \param is_t38_active Non-zero if T.38 is active
  1499. */
  1500. void ast_channel_set_is_t38_active_nolock(struct ast_channel *chan, int is_t38_active);
  1501. /*!
  1502. * \brief Lock the given channel, then request softhangup on the channel with the given causecode
  1503. * \param chan channel on which to hang up
  1504. * \param causecode cause code to use (Zero if don't use cause code)
  1505. * \return Nothing
  1506. */
  1507. void ast_channel_softhangup_withcause_locked(struct ast_channel *chan, int causecode);
  1508. /*!
  1509. * \brief Compare a offset with the settings of when to hang a channel up
  1510. * \param chan channel on which to check for hang up
  1511. * \param offset offset in seconds from current time
  1512. * \return 1, 0, or -1
  1513. * \details
  1514. * This function compares a offset from current time with the absolute time
  1515. * out on a channel (when to hang up). If the absolute time out on a channel
  1516. * is earlier than current time plus the offset, it returns 1, if the two
  1517. * time values are equal, it return 0, otherwise, it return -1.
  1518. * \sa ast_channel_cmpwhentohangup_tv()
  1519. * \version 1.6.1 deprecated function (only had seconds precision)
  1520. */
  1521. int ast_channel_cmpwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
  1522. /*!
  1523. * \brief Compare a offset with the settings of when to hang a channel up
  1524. * \param chan channel on which to check for hangup
  1525. * \param offset offset in seconds and microseconds from current time
  1526. * \return 1, 0, or -1
  1527. * This function compares a offset from current time with the absolute time
  1528. * out on a channel (when to hang up). If the absolute time out on a channel
  1529. * is earlier than current time plus the offset, it returns 1, if the two
  1530. * time values are equal, it return 0, otherwise, it return -1.
  1531. * \since 1.6.1
  1532. */
  1533. int ast_channel_cmpwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
  1534. /*!
  1535. * \brief Set when to hang a channel up
  1536. *
  1537. * \param chan channel on which to check for hang up
  1538. * \param offset offset in seconds relative to the current time of when to hang up
  1539. *
  1540. * \details
  1541. * This function sets the absolute time out on a channel (when to hang up).
  1542. *
  1543. * \pre chan is locked
  1544. *
  1545. * \return Nothing
  1546. * \sa ast_channel_setwhentohangup_tv()
  1547. * \version 1.6.1 deprecated function (only had seconds precision)
  1548. */
  1549. void ast_channel_setwhentohangup(struct ast_channel *chan, time_t offset) __attribute__((deprecated));
  1550. /*!
  1551. * \brief Set when to hang a channel up
  1552. *
  1553. * \param chan channel on which to check for hang up
  1554. * \param offset offset in seconds and useconds relative to the current time of when to hang up
  1555. *
  1556. * This function sets the absolute time out on a channel (when to hang up).
  1557. *
  1558. * \pre chan is locked
  1559. *
  1560. * \return Nothing
  1561. * \since 1.6.1
  1562. */
  1563. void ast_channel_setwhentohangup_tv(struct ast_channel *chan, struct timeval offset);
  1564. /*!
  1565. * \brief Answer a channel
  1566. *
  1567. * \param chan channel to answer
  1568. *
  1569. * \details
  1570. * This function answers a channel and handles all necessary call
  1571. * setup functions.
  1572. *
  1573. * \note The channel passed does not need to be locked, but is locked
  1574. * by the function when needed.
  1575. *
  1576. * \note This function will wait up to 500 milliseconds for media to
  1577. * arrive on the channel before returning to the caller, so that the
  1578. * caller can properly assume the channel is 'ready' for media flow.
  1579. *
  1580. * \retval 0 on success
  1581. * \retval non-zero on failure
  1582. */
  1583. int ast_answer(struct ast_channel *chan);
  1584. /*!
  1585. * \brief Answer a channel, if it's not already answered.
  1586. *
  1587. * \param chan channel to answer
  1588. *
  1589. * \details See ast_answer()
  1590. *
  1591. * \retval 0 on success
  1592. * \retval non-zero on failure
  1593. */
  1594. int ast_auto_answer(struct ast_channel *chan);
  1595. /*!
  1596. * \brief Answer a channel
  1597. *
  1598. * \param chan channel to answer
  1599. *
  1600. * This function answers a channel and handles all necessary call
  1601. * setup functions.
  1602. *
  1603. * \note The channel passed does not need to be locked, but is locked
  1604. * by the function when needed.
  1605. *
  1606. * \note Unlike ast_answer(), this function will not wait for media
  1607. * flow to begin. The caller should be careful before sending media
  1608. * to the channel before incoming media arrives, as the outgoing
  1609. * media may be lost.
  1610. *
  1611. * \retval 0 on success
  1612. * \retval non-zero on failure
  1613. */
  1614. int ast_raw_answer(struct ast_channel *chan);
  1615. /*!
  1616. * \brief Answer a channel, with a selectable delay before returning
  1617. *
  1618. * \param chan channel to answer
  1619. * \param delay maximum amount of time to wait for incoming media
  1620. *
  1621. * This function answers a channel and handles all necessary call
  1622. * setup functions.
  1623. *
  1624. * \note The channel passed does not need to be locked, but is locked
  1625. * by the function when needed.
  1626. *
  1627. * \note This function will wait up to 'delay' milliseconds for media to
  1628. * arrive on the channel before returning to the caller, so that the
  1629. * caller can properly assume the channel is 'ready' for media flow. If
  1630. * 'delay' is less than 500, the function will wait up to 500 milliseconds.
  1631. *
  1632. * \retval 0 on success
  1633. * \retval non-zero on failure
  1634. */
  1635. int __ast_answer(struct ast_channel *chan, unsigned int delay);
  1636. /*!
  1637. * \brief Execute a Gosub call on the channel before a call is placed.
  1638. * \since 11.0
  1639. *
  1640. * \details
  1641. * This is called between ast_request() and ast_call() to
  1642. * execute a predial routine on the newly created channel.
  1643. *
  1644. * \param chan Channel to execute Gosub.
  1645. * \param sub_args Gosub application parameter string.
  1646. *
  1647. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1648. *
  1649. * \retval 0 on success.
  1650. * \retval -1 on error.
  1651. */
  1652. int ast_pre_call(struct ast_channel *chan, const char *sub_args);
  1653. /*!
  1654. * \brief Make a call
  1655. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1656. * \param chan which channel to make the call on
  1657. * \param addr destination of the call
  1658. * \param timeout time to wait on for connect (Doesn't seem to be used.)
  1659. * \details
  1660. * Place a call, take no longer than timeout ms.
  1661. * \retval 0 on success
  1662. * \retval -1 on failure
  1663. */
  1664. int ast_call(struct ast_channel *chan, const char *addr, int timeout);
  1665. /*!
  1666. * \brief Indicates condition of channel
  1667. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1668. * \note Indicate a condition such as AST_CONTROL_BUSY, AST_CONTROL_RINGING, or AST_CONTROL_CONGESTION on a channel
  1669. * \param chan channel to change the indication
  1670. * \param condition which condition to indicate on the channel
  1671. * \return Returns 0 on success, -1 on failure
  1672. */
  1673. int ast_indicate(struct ast_channel *chan, int condition);
  1674. /*!
  1675. * \brief Indicates condition of channel, with payload
  1676. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1677. * \note Indicate a condition such as AST_CONTROL_HOLD with payload being music on hold class
  1678. * \param chan channel to change the indication
  1679. * \param condition which condition to indicate on the channel
  1680. * \param data pointer to payload data
  1681. * \param datalen size of payload data
  1682. * \return Returns 0 on success, -1 on failure
  1683. */
  1684. int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen);
  1685. /* Misc stuff ------------------------------------------------ */
  1686. /*!
  1687. * \brief Wait for input on a channel
  1688. * \param chan channel to wait on
  1689. * \param ms length of time to wait on the channel
  1690. * \details
  1691. * Wait for input on a channel for a given # of milliseconds (<0 for indefinite).
  1692. * \retval < 0 on failure
  1693. * \retval 0 if nothing ever arrived
  1694. * \retval the # of ms remaining otherwise
  1695. */
  1696. int ast_waitfor(struct ast_channel *chan, int ms);
  1697. /*!
  1698. * \brief Should we keep this frame for later?
  1699. *
  1700. * There are functions such as ast_safe_sleep which will
  1701. * service a channel to ensure that it does not have a
  1702. * large backlog of queued frames. When this happens,
  1703. * we want to hold on to specific frame types and just drop
  1704. * others. This function will tell if the frame we just
  1705. * read should be held onto.
  1706. *
  1707. * \param frame The frame we just read
  1708. * \retval 1 frame should be kept
  1709. * \retval 0 frame should be dropped
  1710. */
  1711. int ast_is_deferrable_frame(const struct ast_frame *frame);
  1712. /*!
  1713. * \brief Wait for a specified amount of time, looking for hangups
  1714. * \param chan channel to wait for
  1715. * \param ms length of time in milliseconds to sleep. This should never be less than zero.
  1716. * \details
  1717. * Waits for a specified amount of time, servicing the channel as required.
  1718. * \return returns -1 on hangup, otherwise 0.
  1719. */
  1720. int ast_safe_sleep(struct ast_channel *chan, int ms);
  1721. /*!
  1722. * \brief Wait for a specified amount of time, looking for hangups and a condition argument
  1723. * \param chan channel to wait for
  1724. * \param ms length of time in milliseconds to sleep.
  1725. * \param cond a function pointer for testing continue condition
  1726. * \param data argument to be passed to the condition test function
  1727. * \return returns -1 on hangup, otherwise 0.
  1728. * \details
  1729. * Waits for a specified amount of time, servicing the channel as required. If cond
  1730. * returns 0, this function returns.
  1731. */
  1732. int ast_safe_sleep_conditional(struct ast_channel *chan, int ms, int (*cond)(void*), void *data );
  1733. /*!
  1734. * \brief Waits for activity on a group of channels
  1735. * \param chan an array of pointers to channels
  1736. * \param n number of channels that are to be waited upon
  1737. * \param fds an array of fds to wait upon
  1738. * \param nfds the number of fds to wait upon
  1739. * \param exception exception flag
  1740. * \param outfd fd that had activity on it
  1741. * \param ms how long the wait was
  1742. * \details
  1743. * Big momma function here. Wait for activity on any of the n channels, or any of the nfds
  1744. * file descriptors.
  1745. * \return Returns the channel with activity, or NULL on error or if an FD
  1746. * came first. If the FD came first, it will be returned in outfd, otherwise, outfd
  1747. * will be -1
  1748. */
  1749. struct ast_channel *ast_waitfor_nandfds(struct ast_channel **chan, int n,
  1750. int *fds, int nfds, int *exception, int *outfd, int *ms);
  1751. /*!
  1752. * \brief Waits for input on a group of channels
  1753. * Wait for input on an array of channels for a given # of milliseconds.
  1754. * \return Return channel with activity, or NULL if none has activity.
  1755. * \param chan an array of pointers to channels
  1756. * \param n number of channels that are to be waited upon
  1757. * \param ms time "ms" is modified in-place, if applicable
  1758. */
  1759. struct ast_channel *ast_waitfor_n(struct ast_channel **chan, int n, int *ms);
  1760. /*!
  1761. * \brief Waits for input on an fd
  1762. * \note This version works on fd's only. Be careful with it.
  1763. */
  1764. int ast_waitfor_n_fd(int *fds, int n, int *ms, int *exception);
  1765. /*!
  1766. * \brief Reads a frame
  1767. * \param chan channel to read a frame from
  1768. * \return Returns a frame, or NULL on error. If it returns NULL, you
  1769. * best just stop reading frames and assume the channel has been
  1770. * disconnected.
  1771. */
  1772. struct ast_frame *ast_read(struct ast_channel *chan);
  1773. /*!
  1774. * \brief Reads a frame, returning AST_FRAME_NULL frame if audio.
  1775. * \param chan channel to read a frame from
  1776. * \return Returns a frame, or NULL on error. If it returns NULL, you
  1777. * best just stop reading frames and assume the channel has been
  1778. * disconnected.
  1779. * \note Audio is replaced with AST_FRAME_NULL to avoid
  1780. * transcode when the resulting audio is not necessary.
  1781. */
  1782. struct ast_frame *ast_read_noaudio(struct ast_channel *chan);
  1783. /*!
  1784. * \brief Write a frame to a channel
  1785. * This function writes the given frame to the indicated channel.
  1786. * \param chan destination channel of the frame
  1787. * \param frame frame that will be written
  1788. * \return It returns 0 on success, -1 on failure.
  1789. */
  1790. int ast_write(struct ast_channel *chan, struct ast_frame *frame);
  1791. /*!
  1792. * \brief Write video frame to a channel
  1793. * This function writes the given frame to the indicated channel.
  1794. * \param chan destination channel of the frame
  1795. * \param frame frame that will be written
  1796. * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
  1797. */
  1798. int ast_write_video(struct ast_channel *chan, struct ast_frame *frame);
  1799. /*!
  1800. * \brief Write text frame to a channel
  1801. * This function writes the given frame to the indicated channel.
  1802. * \param chan destination channel of the frame
  1803. * \param frame frame that will be written
  1804. * \return It returns 1 on success, 0 if not implemented, and -1 on failure.
  1805. */
  1806. int ast_write_text(struct ast_channel *chan, struct ast_frame *frame);
  1807. /*! \brief Send empty audio to prime a channel driver */
  1808. int ast_prod(struct ast_channel *chan);
  1809. /*!
  1810. * \brief Set specific read path on channel.
  1811. * \since 13.4.0
  1812. *
  1813. * \param chan Channel to setup read path.
  1814. * \param raw_format Format to expect from the channel driver.
  1815. * \param core_format What the core wants to read.
  1816. *
  1817. * \pre chan is locked
  1818. *
  1819. * \retval 0 on success.
  1820. * \retval -1 on error.
  1821. */
  1822. int ast_set_read_format_path(struct ast_channel *chan, struct ast_format *raw_format, struct ast_format *core_format);
  1823. /*!
  1824. * \brief Set specific write path on channel.
  1825. * \since 13.13.0
  1826. *
  1827. * \param chan Channel to setup write path.
  1828. * \param core_format What the core wants to write.
  1829. * \param raw_format Raw write format.
  1830. *
  1831. * \pre chan is locked
  1832. *
  1833. * \retval 0 on success.
  1834. * \retval -1 on error.
  1835. */
  1836. int ast_set_write_format_path(struct ast_channel *chan, struct ast_format *core_format, struct ast_format *raw_format);
  1837. /*!
  1838. * \brief Sets read format on channel chan from capabilities
  1839. * Set read format for channel to whichever component of "format" is best.
  1840. * \param chan channel to change
  1841. * \param formats new formats to pick from for reading
  1842. * \return Returns 0 on success, -1 on failure
  1843. */
  1844. int ast_set_read_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
  1845. /*!
  1846. * \brief Sets read format on channel chan
  1847. * \param chan channel to change
  1848. * \param format format to set for reading
  1849. * \return Returns 0 on success, -1 on failure
  1850. */
  1851. int ast_set_read_format(struct ast_channel *chan, struct ast_format *format);
  1852. /*!
  1853. * \brief Sets write format on channel chan
  1854. * Set write format for channel to whichever component of "format" is best.
  1855. * \param chan channel to change
  1856. * \param formats new formats to pick from for writing
  1857. * \return Returns 0 on success, -1 on failure
  1858. */
  1859. int ast_set_write_format_from_cap(struct ast_channel *chan, struct ast_format_cap *formats);
  1860. /*!
  1861. * \brief Sets write format on channel chan
  1862. * \param chan channel to change
  1863. * \param format format to set for writing
  1864. * \return Returns 0 on success, -1 on failure
  1865. */
  1866. int ast_set_write_format(struct ast_channel *chan, struct ast_format *format);
  1867. /*!
  1868. * \brief Sends text to a channel
  1869. *
  1870. * \param chan channel to act upon
  1871. * \param text string of text to send on the channel
  1872. *
  1873. * \details
  1874. * Write text to a display on a channel
  1875. *
  1876. * \note The channel does not need to be locked before calling this function.
  1877. *
  1878. * \retval 0 on success
  1879. * \retval -1 on failure
  1880. */
  1881. int ast_sendtext(struct ast_channel *chan, const char *text);
  1882. /*!
  1883. * \brief Sends text to a channel in an ast_msg_data structure wrapper with ast_sendtext as fallback
  1884. * \since 13.22.0
  1885. * \since 15.5.0
  1886. *
  1887. * \param chan channel to act upon
  1888. * \param msg ast_msg_data structure
  1889. *
  1890. * \details
  1891. * Write text to a display on a channel. If the channel driver doesn't support the
  1892. * send_text_data callback. then the original send_text callback will be used if
  1893. * available.
  1894. *
  1895. * \note The channel does not need to be locked before calling this function.
  1896. *
  1897. * \retval 0 on success
  1898. * \retval -1 on failure
  1899. */
  1900. int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg);
  1901. /*!
  1902. * \brief Receives a text character from a channel
  1903. * \param chan channel to act upon
  1904. * \param timeout timeout in milliseconds (0 for infinite wait)
  1905. * \details
  1906. * Read a char of text from a channel
  1907. * \return 0 on success, -1 on failure
  1908. */
  1909. int ast_recvchar(struct ast_channel *chan, int timeout);
  1910. /*!
  1911. * \brief Send a DTMF digit to a channel.
  1912. *
  1913. * \param chan channel to act upon
  1914. * \param digit the DTMF digit to send, encoded in ASCII
  1915. * \param duration the duration of the digit ending in ms
  1916. *
  1917. * \pre This must only be called by the channel's media handler thread.
  1918. *
  1919. * \return 0 on success, -1 on failure
  1920. */
  1921. int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration);
  1922. /*!
  1923. * \brief Send a DTMF digit to a channel from an external thread.
  1924. *
  1925. * \param chan channel to act upon
  1926. * \param digit the DTMF digit to send, encoded in ASCII
  1927. * \param duration the duration of the digit ending in ms
  1928. *
  1929. * \pre This must only be called by threads that are not the channel's
  1930. * media handler thread.
  1931. *
  1932. * \return 0 on success, -1 on failure
  1933. */
  1934. int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration);
  1935. /*!
  1936. * \brief Send a DTMF digit to a channel.
  1937. * \param chan channel to act upon
  1938. * \param digit the DTMF digit to send, encoded in ASCII
  1939. * \return 0 on success, -1 on failure
  1940. */
  1941. int ast_senddigit_begin(struct ast_channel *chan, char digit);
  1942. /*!
  1943. * \brief Send a DTMF digit to a channel.
  1944. * \param chan channel to act upon
  1945. * \param digit the DTMF digit to send, encoded in ASCII
  1946. * \param duration the duration of the digit ending in ms
  1947. * \return Returns 0 on success, -1 on failure
  1948. */
  1949. int ast_senddigit_end(struct ast_channel *chan, char digit, unsigned int duration);
  1950. /*!
  1951. * \brief Receives a text string from a channel
  1952. * Read a string of text from a channel
  1953. * \param chan channel to act upon
  1954. * \param timeout timeout in milliseconds (0 for infinite wait)
  1955. * \return the received text, or NULL to signify failure.
  1956. */
  1957. char *ast_recvtext(struct ast_channel *chan, int timeout);
  1958. /*!
  1959. * \brief Waits for a digit
  1960. * \param c channel to wait for a digit on
  1961. * \param ms how many milliseconds to wait (<0 for indefinite).
  1962. * \return Returns <0 on error, 0 on no entry, and the digit on success.
  1963. */
  1964. int ast_waitfordigit(struct ast_channel *c, int ms);
  1965. /*!
  1966. * \brief Wait for a digit
  1967. * Same as ast_waitfordigit() with audio fd for outputting read audio and ctrlfd to monitor for reading.
  1968. * \param c channel to wait for a digit on
  1969. * \param ms how many milliseconds to wait (<0 for indefinite).
  1970. * \param audiofd audio file descriptor to write to if audio frames are received
  1971. * \param ctrlfd control file descriptor to monitor for reading
  1972. * \return Returns 1 if ctrlfd becomes available
  1973. */
  1974. int ast_waitfordigit_full(struct ast_channel *c, int ms, int audiofd, int ctrlfd);
  1975. /*!
  1976. * \brief Reads multiple digits
  1977. * \param c channel to read from
  1978. * \param s string to read in to. Must be at least the size of your length
  1979. * \param len how many digits to read (maximum)
  1980. * \param timeout how long to timeout between digits
  1981. * \param rtimeout timeout to wait on the first digit
  1982. * \param enders digits to end the string
  1983. * \details
  1984. * Read in a digit string "s", max length "len", maximum timeout between
  1985. * digits "timeout" (-1 for none), terminated by anything in "enders". Give them rtimeout
  1986. * for the first digit.
  1987. * \return Returns 0 on normal return, or 1 on a timeout. In the case of
  1988. * a timeout, any digits that were read before the timeout will still be available in s.
  1989. * RETURNS 2 in full version when ctrlfd is available, NOT 1
  1990. */
  1991. int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders);
  1992. int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd);
  1993. /*! \brief Report DTMF on channel 0 */
  1994. #define AST_BRIDGE_DTMF_CHANNEL_0 (1 << 0)
  1995. /*! \brief Report DTMF on channel 1 */
  1996. #define AST_BRIDGE_DTMF_CHANNEL_1 (1 << 1)
  1997. /*!
  1998. * \brief Make the frame formats of two channels compatible.
  1999. *
  2000. * \param chan First channel to make compatible. Should be the calling party.
  2001. * \param peer Other channel to make compatible. Should be the called party.
  2002. *
  2003. * \note Absolutely _NO_ channel locks should be held before calling this function.
  2004. *
  2005. * \details
  2006. * Set two channels to compatible frame formats in both
  2007. * directions. The path from peer to chan is made compatible
  2008. * first to allow for in-band audio in case the other direction
  2009. * cannot be made compatible.
  2010. *
  2011. * \retval 0 on success.
  2012. * \retval -1 on error.
  2013. */
  2014. int ast_channel_make_compatible(struct ast_channel *chan, struct ast_channel *peer);
  2015. /*!
  2016. * \brief Bridge two channels together (early)
  2017. * \param c0 first channel to bridge
  2018. * \param c1 second channel to bridge
  2019. * \details
  2020. * Bridge two channels (c0 and c1) together early. This implies either side may not be answered yet.
  2021. * \return Returns 0 on success and -1 if it could not be done
  2022. */
  2023. int ast_channel_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
  2024. /*!
  2025. * \brief Gives the string form of a given cause code.
  2026. *
  2027. * \param state cause to get the description of
  2028. * \return the text form of the binary cause code given
  2029. */
  2030. const char *ast_cause2str(int state) attribute_pure;
  2031. /*!
  2032. * \brief Convert the string form of a cause code to a number
  2033. *
  2034. * \param name string form of the cause
  2035. * \return the cause code
  2036. */
  2037. int ast_str2cause(const char *name) attribute_pure;
  2038. /*!
  2039. * \brief Gives the string form of a given channel state
  2040. *
  2041. * \param ast_channel_state state to get the name of
  2042. * \return the text form of the binary state given
  2043. */
  2044. const char *ast_state2str(enum ast_channel_state);
  2045. /*!
  2046. * \brief Gives the string form of a given transfer capability
  2047. *
  2048. * \param transfercapability transfer capability to get the name of
  2049. * \return the text form of the binary transfer capability
  2050. */
  2051. char *ast_transfercapability2str(int transfercapability) attribute_const;
  2052. /*
  2053. * Options: Some low-level drivers may implement "options" allowing fine tuning of the
  2054. * low level channel. See frame.h for options. Note that many channel drivers may support
  2055. * none or a subset of those features, and you should not count on this if you want your
  2056. * asterisk application to be portable. They're mainly useful for tweaking performance
  2057. */
  2058. /*!
  2059. * \brief Sets an option on a channel
  2060. *
  2061. * \param channel channel to set options on
  2062. * \param option option to change
  2063. * \param data data specific to option
  2064. * \param datalen length of the data
  2065. * \param block blocking or not
  2066. * \details
  2067. * Set an option on a channel (see frame.h), optionally blocking awaiting the reply
  2068. * \return 0 on success and -1 on failure
  2069. */
  2070. int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block);
  2071. /*!
  2072. * \brief Checks the value of an option
  2073. *
  2074. * Query the value of an option
  2075. * Works similarly to setoption except only reads the options.
  2076. */
  2077. int ast_channel_queryoption(struct ast_channel *channel, int option, void *data, int *datalen, int block);
  2078. /*!
  2079. * \brief Checks for HTML support on a channel
  2080. * \return 0 if channel does not support HTML or non-zero if it does
  2081. */
  2082. int ast_channel_supports_html(struct ast_channel *channel);
  2083. /*!
  2084. * \brief Sends HTML on given channel
  2085. * Send HTML or URL on link.
  2086. * \return 0 on success or -1 on failure
  2087. */
  2088. int ast_channel_sendhtml(struct ast_channel *channel, int subclass, const char *data, int datalen);
  2089. /*!
  2090. * \brief Sends a URL on a given link
  2091. * Send URL on link.
  2092. * \return 0 on success or -1 on failure
  2093. */
  2094. int ast_channel_sendurl(struct ast_channel *channel, const char *url);
  2095. /*!
  2096. * \brief Defers DTMF so that you only read things like hangups and audio.
  2097. * \return non-zero if channel was already DTMF-deferred or
  2098. * 0 if channel is just now being DTMF-deferred
  2099. */
  2100. int ast_channel_defer_dtmf(struct ast_channel *chan);
  2101. /*! Undo defer. ast_read will return any DTMF characters that were queued */
  2102. void ast_channel_undefer_dtmf(struct ast_channel *chan);
  2103. /*! \return number of channels available for lookup */
  2104. int ast_active_channels(void);
  2105. /*! \return the number of channels not yet destroyed */
  2106. int ast_undestroyed_channels(void);
  2107. /*! Activate a given generator */
  2108. int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params);
  2109. /*! Deactivate an active generator */
  2110. void ast_deactivate_generator(struct ast_channel *chan);
  2111. /*!
  2112. * \since 12
  2113. * \brief Obtain how long the channel since the channel was created
  2114. *
  2115. * \param chan The channel object
  2116. *
  2117. * \retval 0 if the time value cannot be computed (or you called this really fast)
  2118. * \retval The number of seconds the channel has been up
  2119. */
  2120. int ast_channel_get_duration(struct ast_channel *chan);
  2121. /*!
  2122. * \since 12
  2123. * \brief Obtain how long it has been since the channel was answered
  2124. *
  2125. * \param chan The channel object
  2126. *
  2127. * \retval 0 if the channel isn't answered (or you called this really fast)
  2128. * \retval The number of seconds the channel has been up
  2129. */
  2130. int ast_channel_get_up_time(struct ast_channel *chan);
  2131. /*!
  2132. * \brief Set caller ID number, name and ANI and generate AMI event.
  2133. *
  2134. * \note Use ast_channel_set_caller() and ast_channel_set_caller_event() instead.
  2135. * \note The channel does not need to be locked before calling this function.
  2136. */
  2137. void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani);
  2138. /*!
  2139. * \brief Set the caller id information in the Asterisk channel
  2140. * \since 1.8
  2141. *
  2142. * \param chan Asterisk channel to set caller id information
  2143. * \param caller Caller id information
  2144. * \param update What caller information to update. NULL if all.
  2145. *
  2146. * \return Nothing
  2147. *
  2148. * \note The channel does not need to be locked before calling this function.
  2149. */
  2150. void ast_channel_set_caller(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
  2151. /*!
  2152. * \brief Set the caller id information in the Asterisk channel and generate an AMI event
  2153. * if the caller id name or number changed.
  2154. * \since 1.8
  2155. *
  2156. * \param chan Asterisk channel to set caller id information
  2157. * \param caller Caller id information
  2158. * \param update What caller information to update. NULL if all.
  2159. *
  2160. * \return Nothing
  2161. *
  2162. * \note The channel does not need to be locked before calling this function.
  2163. */
  2164. void ast_channel_set_caller_event(struct ast_channel *chan, const struct ast_party_caller *caller, const struct ast_set_party_caller *update);
  2165. /*! Set the file descriptor on the channel */
  2166. void ast_channel_set_fd(struct ast_channel *chan, int which, int fd);
  2167. /*! Add a channel to an optimized waitfor */
  2168. void ast_poll_channel_add(struct ast_channel *chan0, struct ast_channel *chan1);
  2169. /*! Delete a channel from an optimized waitfor */
  2170. void ast_poll_channel_del(struct ast_channel *chan0, struct ast_channel *chan1);
  2171. /*! Start a tone going */
  2172. int ast_tonepair_start(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
  2173. /*! Stop a tone from playing */
  2174. void ast_tonepair_stop(struct ast_channel *chan);
  2175. /*! Play a tone pair for a given amount of time */
  2176. int ast_tonepair(struct ast_channel *chan, int freq1, int freq2, int duration, int vol);
  2177. /*!
  2178. * \brief Automatically service a channel for us...
  2179. *
  2180. * \retval 0 success
  2181. * \retval -1 failure, or the channel is already being autoserviced
  2182. */
  2183. int ast_autoservice_start(struct ast_channel *chan);
  2184. /*!
  2185. * \brief Stop servicing a channel for us...
  2186. *
  2187. * \note if chan is locked prior to calling ast_autoservice_stop, it
  2188. * is likely that there will be a deadlock between the thread that calls
  2189. * ast_autoservice_stop and the autoservice thread. It is important
  2190. * that chan is not locked prior to this call
  2191. *
  2192. * \param chan
  2193. * \retval 0 success
  2194. * \retval -1 error, or the channel has been hungup
  2195. */
  2196. int ast_autoservice_stop(struct ast_channel *chan);
  2197. /*!
  2198. * \brief Put chan into autoservice while hanging up peer.
  2199. * \since 11.0
  2200. *
  2201. * \param chan Chan to put into autoservice.
  2202. * \param peer Chan to run hangup handlers and hangup.
  2203. *
  2204. * \return Nothing
  2205. */
  2206. void ast_autoservice_chan_hangup_peer(struct ast_channel *chan, struct ast_channel *peer);
  2207. /*!
  2208. * \brief Ignore certain frame types
  2209. * \note Normally, we cache DTMF, IMAGE, HTML, TEXT, and CONTROL frames
  2210. * while a channel is in autoservice and queue them up when taken out of
  2211. * autoservice. When this is not desireable, this API may be used to
  2212. * cause the channel to ignore those frametypes after the channel is put
  2213. * into autoservice, but before autoservice is stopped.
  2214. * \retval 0 success
  2215. * \retval -1 channel is not in autoservice
  2216. */
  2217. int ast_autoservice_ignore(struct ast_channel *chan, enum ast_frame_type ftype);
  2218. /*!
  2219. * \brief Enable or disable timer ticks for a channel
  2220. *
  2221. * \param c channel
  2222. * \param rate number of timer ticks per second
  2223. * \param func callback function
  2224. * \param data
  2225. *
  2226. * \details
  2227. * If timers are supported, force a scheduled expiration on the
  2228. * timer fd, at which point we call the callback function / data
  2229. *
  2230. * \note Call this function with a rate of 0 to turn off the timer ticks
  2231. *
  2232. * \version 1.6.1 changed samples parameter to rate, accomodates new timing methods
  2233. */
  2234. int ast_settimeout(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data);
  2235. int ast_settimeout_full(struct ast_channel *c, unsigned int rate, int (*func)(const void *data), void *data, unsigned int is_ao2_obj);
  2236. /*!
  2237. * \brief Transfer a channel (if supported).
  2238. * \retval -1 on error
  2239. * \retval 0 if not supported
  2240. * \retval 1 if supported and requested
  2241. * \param chan current channel
  2242. * \param dest destination extension for transfer
  2243. */
  2244. int ast_transfer(struct ast_channel *chan, char *dest);
  2245. /*!
  2246. * \brief Inherits channel variable from parent to child channel
  2247. * \param parent Parent channel
  2248. * \param child Child channel
  2249. *
  2250. * \details
  2251. * Scans all channel variables in the parent channel, looking for those
  2252. * that should be copied into the child channel.
  2253. * Variables whose names begin with a single '_' are copied into the
  2254. * child channel with the prefix removed.
  2255. * Variables whose names begin with '__' are copied into the child
  2256. * channel with their names unchanged.
  2257. */
  2258. void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child);
  2259. /*!
  2260. * \brief adds a list of channel variables to a channel
  2261. * \param chan the channel
  2262. * \param vars a linked list of variables
  2263. *
  2264. * \pre chan is locked
  2265. *
  2266. * \details
  2267. * Variable names can be for a regular channel variable or a dialplan function
  2268. * that has the ability to be written to.
  2269. */
  2270. void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars);
  2271. /*!
  2272. * \brief An opaque 'object' structure use by silence generators on channels.
  2273. */
  2274. struct ast_silence_generator;
  2275. /*!
  2276. * \brief Starts a silence generator on the given channel.
  2277. * \param chan The channel to generate silence on
  2278. * \return An ast_silence_generator pointer, or NULL if an error occurs
  2279. *
  2280. * \details
  2281. * This function will cause SLINEAR silence to be generated on the supplied
  2282. * channel until it is disabled; if the channel cannot be put into SLINEAR
  2283. * mode then the function will fail.
  2284. *
  2285. * \note
  2286. * The pointer returned by this function must be preserved and passed to
  2287. * ast_channel_stop_silence_generator when you wish to stop the silence
  2288. * generation.
  2289. */
  2290. struct ast_silence_generator *ast_channel_start_silence_generator(struct ast_channel *chan);
  2291. /*!
  2292. * \brief Stops a previously-started silence generator on the given channel.
  2293. * \param chan The channel to operate on
  2294. * \param state The ast_silence_generator pointer return by a previous call to
  2295. * ast_channel_start_silence_generator.
  2296. * \return nothing
  2297. *
  2298. * \details
  2299. * This function will stop the operating silence generator and return the channel
  2300. * to its previous write format.
  2301. */
  2302. void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state);
  2303. /*!
  2304. * \brief Determine which channel has an older linkedid
  2305. * \param a First channel
  2306. * \param b Second channel
  2307. * \return Returns an ast_channel structure that has oldest linkedid
  2308. */
  2309. struct ast_channel *ast_channel_internal_oldest_linkedid(struct ast_channel *a, struct ast_channel *b);
  2310. /*!
  2311. * \brief Copy the full linkedid channel id structure from one channel to another
  2312. * \param dest Destination to copy linkedid to
  2313. * \param source Source channel to copy linkedid from
  2314. * \return void
  2315. */
  2316. void ast_channel_internal_copy_linkedid(struct ast_channel *dest, struct ast_channel *source);
  2317. /*!
  2318. * \brief Swap uniqueid and linkedid beteween two channels
  2319. * \param a First channel
  2320. * \param b Second channel
  2321. * \return void
  2322. *
  2323. * \note
  2324. * This is used in masquerade to exchange identities
  2325. */
  2326. void ast_channel_internal_swap_uniqueid_and_linkedid(struct ast_channel *a, struct ast_channel *b);
  2327. /*!
  2328. * \brief Swap topics beteween two channels
  2329. * \param a First channel
  2330. * \param b Second channel
  2331. * \return void
  2332. *
  2333. * \note
  2334. * This is used in masquerade to exchange topics for message routing
  2335. */
  2336. void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b);
  2337. /*!
  2338. * \brief Swap endpoint_forward and endpoint_cache_forward between two channels
  2339. * \param a First channel
  2340. * \param b Second channel
  2341. * \return void
  2342. *
  2343. * \note
  2344. * This is used in masquerade to exchange endpoint details if one of the two or both
  2345. * the channels were created with endpoint
  2346. */
  2347. void ast_channel_internal_swap_endpoint_forward_and_endpoint_cache_forward(struct ast_channel *a, struct ast_channel *b);
  2348. /*!
  2349. * \brief Set uniqueid and linkedid string value only (not time)
  2350. * \param chan The channel to set the uniqueid to
  2351. * \param uniqueid The uniqueid to set
  2352. * \param linkedid The linkedid to set
  2353. * \return void
  2354. *
  2355. * \note
  2356. * This is used only by ast_cel_fabricate_channel_from_event()
  2357. * to create a temporary fake channel - time values are invalid
  2358. */
  2359. void ast_channel_internal_set_fake_ids(struct ast_channel *chan, const char *uniqueid, const char *linkedid);
  2360. /* Misc. functions below */
  2361. /*!
  2362. * \brief if fd is a valid descriptor, set *pfd with the descriptor
  2363. * \return Return 1 (not -1!) if added, 0 otherwise (so we can add the
  2364. * return value to the index into the array)
  2365. */
  2366. static inline int ast_add_fd(struct pollfd *pfd, int fd)
  2367. {
  2368. pfd->fd = fd;
  2369. pfd->events = POLLIN | POLLPRI;
  2370. return fd >= 0;
  2371. }
  2372. /*! \brief Helper function for migrating select to poll */
  2373. static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *start)
  2374. {
  2375. int x;
  2376. int dummy = 0;
  2377. if (fd < 0)
  2378. return 0;
  2379. if (!start)
  2380. start = &dummy;
  2381. for (x = *start; x < maximum; x++)
  2382. if (pfds[x].fd == fd) {
  2383. if (x == *start)
  2384. (*start)++;
  2385. return pfds[x].revents;
  2386. }
  2387. return 0;
  2388. }
  2389. /*!
  2390. * \brief Retrieves the current T38 state of a channel
  2391. *
  2392. * \note Absolutely _NO_ channel locks should be held before calling this function.
  2393. */
  2394. static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan)
  2395. {
  2396. enum ast_t38_state state = T38_STATE_UNAVAILABLE;
  2397. int datalen = sizeof(state);
  2398. ast_channel_queryoption(chan, AST_OPTION_T38_STATE, &state, &datalen, 0);
  2399. return state;
  2400. }
  2401. /*!
  2402. * \brief Set the blocking indication on the channel.
  2403. *
  2404. * \details
  2405. * Indicate that the thread handling the channel is about to do a blocking
  2406. * operation to wait for media on the channel. (poll, read, or write)
  2407. *
  2408. * Masquerading and ast_queue_frame() use this indication to wake up the thread.
  2409. *
  2410. * \pre The channel needs to be locked
  2411. */
  2412. #define CHECK_BLOCKING(c) \
  2413. do { \
  2414. if (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING)) { \
  2415. /* This should not happen as there should only be one thread handling a channel's media at a time. */ \
  2416. ast_log(LOG_DEBUG, "Thread LWP %d is blocking '%s', already blocked by thread LWP %d in procedure %s\n", \
  2417. ast_get_tid(), ast_channel_name(c), \
  2418. ast_channel_blocker_tid(c), ast_channel_blockproc(c)); \
  2419. ast_assert(0); \
  2420. } \
  2421. ast_channel_blocker_tid_set((c), ast_get_tid()); \
  2422. ast_channel_blocker_set((c), pthread_self()); \
  2423. ast_channel_blockproc_set((c), __PRETTY_FUNCTION__); \
  2424. ast_set_flag(ast_channel_flags(c), AST_FLAG_BLOCKING); \
  2425. } while (0)
  2426. ast_group_t ast_get_group(const char *s);
  2427. /*! \brief Print call and pickup groups into buffer */
  2428. char *ast_print_group(char *buf, int buflen, ast_group_t group);
  2429. /*! \brief Opaque struct holding a namedgroups set, i.e. a set of group names */
  2430. struct ast_namedgroups;
  2431. /*! \brief Create an ast_namedgroups set with group names from comma separated string */
  2432. struct ast_namedgroups *ast_get_namedgroups(const char *s);
  2433. struct ast_namedgroups *ast_unref_namedgroups(struct ast_namedgroups *groups);
  2434. struct ast_namedgroups *ast_ref_namedgroups(struct ast_namedgroups *groups);
  2435. /*! \brief Return TRUE if group a and b contain at least one common groupname */
  2436. int ast_namedgroups_intersect(struct ast_namedgroups *a, struct ast_namedgroups *b);
  2437. /*! \brief Print named call groups and named pickup groups */
  2438. char *ast_print_namedgroups(struct ast_str **buf, struct ast_namedgroups *groups);
  2439. /*!
  2440. * \brief Convert enum channelreloadreason to text string for manager event
  2441. * \param reason The reason for reload (manager, cli, start etc)
  2442. */
  2443. const char *channelreloadreason2txt(enum channelreloadreason reason);
  2444. /*! \brief return an ast_variable list of channeltypes */
  2445. struct ast_variable *ast_channeltype_list(void);
  2446. /*!
  2447. * \brief return an english explanation of the code returned thru __ast_request_and_dial's 'outstate' argument
  2448. * \param reason The integer argument, usually taken from AST_CONTROL_ macros
  2449. * \return char pointer explaining the code
  2450. */
  2451. const char *ast_channel_reason2str(int reason);
  2452. /*! \brief channel group info */
  2453. struct ast_group_info {
  2454. struct ast_channel *chan;
  2455. char *category;
  2456. char *group;
  2457. AST_LIST_ENTRY(ast_group_info) group_list;
  2458. };
  2459. #define ast_channel_lock(chan) ao2_lock(chan)
  2460. #define ast_channel_unlock(chan) ao2_unlock(chan)
  2461. #define ast_channel_trylock(chan) ao2_trylock(chan)
  2462. /*!
  2463. * \brief Lock two channels.
  2464. */
  2465. #define ast_channel_lock_both(chan1, chan2) do { \
  2466. ast_channel_lock(chan1); \
  2467. while (ast_channel_trylock(chan2)) { \
  2468. ast_channel_unlock(chan1); \
  2469. sched_yield(); \
  2470. ast_channel_lock(chan1); \
  2471. } \
  2472. } while (0)
  2473. /*!
  2474. * \brief Increase channel reference count
  2475. *
  2476. * \param c the channel
  2477. *
  2478. * \retval c always
  2479. *
  2480. * \since 1.8
  2481. */
  2482. #define ast_channel_ref(c) ({ ao2_ref(c, +1); (c); })
  2483. /*!
  2484. * \brief Decrease channel reference count
  2485. *
  2486. * \param c the channel
  2487. *
  2488. * \retval NULL always
  2489. *
  2490. * \since 1.8
  2491. */
  2492. #define ast_channel_unref(c) ({ ao2_ref(c, -1); (struct ast_channel *) (NULL); })
  2493. /*!
  2494. * \brief Cleanup a channel reference
  2495. *
  2496. * \param c the channel (NULL tolerant)
  2497. *
  2498. * \retval NULL always
  2499. *
  2500. * \since 12.0.0
  2501. */
  2502. #define ast_channel_cleanup(c) ({ ao2_cleanup(c); (struct ast_channel *) (NULL); })
  2503. /*! Channel Iterating @{ */
  2504. /*!
  2505. * \brief A channel iterator
  2506. *
  2507. * This is an opaque type.
  2508. */
  2509. struct ast_channel_iterator;
  2510. /*!
  2511. * \brief Destroy a channel iterator
  2512. *
  2513. * \param i the itereator to destroy
  2514. *
  2515. * \details
  2516. * This function is used to destroy a channel iterator that was retrieved by
  2517. * using one of the channel_iterator_xxx_new() functions.
  2518. *
  2519. * \return NULL, for convenience to clear out the pointer to the iterator that
  2520. * was just destroyed.
  2521. *
  2522. * \since 1.8
  2523. */
  2524. struct ast_channel_iterator *ast_channel_iterator_destroy(struct ast_channel_iterator *i);
  2525. /*!
  2526. * \brief Create a new channel iterator based on extension
  2527. *
  2528. * \param exten The extension that channels must be in
  2529. * \param context The context that channels must be in
  2530. *
  2531. * \details
  2532. * After creating an iterator using this function, the ast_channel_iterator_next()
  2533. * function can be used to iterate through all channels that are currently
  2534. * in the specified context and extension.
  2535. *
  2536. * \note You must call ast_channel_iterator_destroy() when done.
  2537. *
  2538. * \retval NULL on failure
  2539. * \retval a new channel iterator based on the specified parameters
  2540. *
  2541. * \since 1.8
  2542. */
  2543. struct ast_channel_iterator *ast_channel_iterator_by_exten_new(const char *exten, const char *context);
  2544. /*!
  2545. * \brief Create a new channel iterator based on name
  2546. *
  2547. * \param name channel name or channel uniqueid to match
  2548. * \param name_len number of characters in the channel name to match on. This
  2549. * would be used to match based on name prefix. If matching on the full
  2550. * channel name is desired, then this parameter should be 0.
  2551. *
  2552. * \details
  2553. * After creating an iterator using this function, the ast_channel_iterator_next()
  2554. * function can be used to iterate through all channels that exist that have
  2555. * the specified name or name prefix.
  2556. *
  2557. * \note You must call ast_channel_iterator_destroy() when done.
  2558. *
  2559. * \retval NULL on failure
  2560. * \retval a new channel iterator based on the specified parameters
  2561. *
  2562. * \since 1.8
  2563. */
  2564. struct ast_channel_iterator *ast_channel_iterator_by_name_new(const char *name, size_t name_len);
  2565. /*!
  2566. * \brief Create a new channel iterator
  2567. *
  2568. * \details
  2569. * After creating an iterator using this function, the ast_channel_iterator_next()
  2570. * function can be used to iterate through all channels that exist.
  2571. *
  2572. * \note You must call ast_channel_iterator_destroy() when done.
  2573. *
  2574. * \retval NULL on failure
  2575. * \retval a new channel iterator
  2576. *
  2577. * \since 1.8
  2578. */
  2579. struct ast_channel_iterator *ast_channel_iterator_all_new(void);
  2580. /*!
  2581. * \brief Get the next channel for a channel iterator
  2582. *
  2583. * \param i the channel iterator that was created using one of the
  2584. * channel_iterator_xxx_new() functions.
  2585. *
  2586. * \details
  2587. * This function should be used to iterate through all channels that match a
  2588. * specified set of parameters that were provided when the iterator was created.
  2589. *
  2590. * \retval the next channel that matches the parameters used when the iterator
  2591. * was created.
  2592. * \retval NULL, if no more channels match the iterator parameters.
  2593. *
  2594. * \since 1.8
  2595. */
  2596. struct ast_channel *ast_channel_iterator_next(struct ast_channel_iterator *i);
  2597. /*! @} End channel iterator definitions. */
  2598. /*!
  2599. * \brief Call a function with every active channel
  2600. *
  2601. * \details
  2602. * This function executes a callback one time for each active channel on the
  2603. * system. The channel is provided as an argument to the function.
  2604. *
  2605. * \note Absolutely _NO_ channel locks should be held before calling this function.
  2606. * \since 1.8
  2607. */
  2608. struct ast_channel *ast_channel_callback(ao2_callback_data_fn *cb_fn, void *arg,
  2609. void *data, int ao2_flags);
  2610. /*! @{ Channel search functions */
  2611. /*!
  2612. * \brief Find a channel by name
  2613. *
  2614. * \param name the name or uniqueid of the channel to search for
  2615. *
  2616. * \details
  2617. * Find a channel that has the same name as the provided argument.
  2618. *
  2619. * \retval a channel with the name specified by the argument
  2620. * \retval NULL if no channel was found
  2621. *
  2622. * \since 1.8
  2623. */
  2624. struct ast_channel *ast_channel_get_by_name(const char *name);
  2625. /*!
  2626. * \brief Find a channel by a name prefix
  2627. *
  2628. * \param name The channel name or uniqueid prefix to search for
  2629. * \param name_len Only search for up to this many characters from the name
  2630. *
  2631. * \details
  2632. * Find a channel that has the same name prefix as specified by the arguments.
  2633. *
  2634. * \retval a channel with the name prefix specified by the arguments
  2635. * \retval NULL if no channel was found
  2636. *
  2637. * \since 1.8
  2638. */
  2639. struct ast_channel *ast_channel_get_by_name_prefix(const char *name, size_t name_len);
  2640. /*!
  2641. * \brief Find a channel by extension and context
  2642. *
  2643. * \param exten the extension to search for
  2644. * \param context the context to search for
  2645. *
  2646. * \details
  2647. * Return a channel that is currently at the specified extension and context.
  2648. *
  2649. * \retval a channel that is at the specified extension and context
  2650. * \retval NULL if no channel was found
  2651. *
  2652. * \since 1.8
  2653. */
  2654. struct ast_channel *ast_channel_get_by_exten(const char *exten, const char *context);
  2655. /*! @} End channel search functions. */
  2656. /*!
  2657. * \brief Initialize the given name structure.
  2658. * \since 1.8
  2659. *
  2660. * \param init Name structure to initialize.
  2661. *
  2662. * \return Nothing
  2663. */
  2664. void ast_party_name_init(struct ast_party_name *init);
  2665. /*!
  2666. * \brief Copy the source party name information to the destination party name.
  2667. * \since 1.8
  2668. *
  2669. * \param dest Destination party name
  2670. * \param src Source party name
  2671. *
  2672. * \return Nothing
  2673. */
  2674. void ast_party_name_copy(struct ast_party_name *dest, const struct ast_party_name *src);
  2675. /*!
  2676. * \brief Initialize the given party name structure using the given guide
  2677. * for a set update operation.
  2678. * \since 1.8
  2679. *
  2680. * \details
  2681. * The initialization is needed to allow a set operation to know if a
  2682. * value needs to be updated. Simple integers need the guide's original
  2683. * value in case the set operation is not trying to set a new value.
  2684. * String values are simply set to NULL pointers if they are not going
  2685. * to be updated.
  2686. *
  2687. * \param init Party name structure to initialize.
  2688. * \param guide Source party name to use as a guide in initializing.
  2689. *
  2690. * \return Nothing
  2691. */
  2692. void ast_party_name_set_init(struct ast_party_name *init, const struct ast_party_name *guide);
  2693. /*!
  2694. * \brief Set the source party name information into the destination party name.
  2695. * \since 1.8
  2696. *
  2697. * \param dest The name one wishes to update
  2698. * \param src The new name values to update the dest
  2699. *
  2700. * \return Nothing
  2701. */
  2702. void ast_party_name_set(struct ast_party_name *dest, const struct ast_party_name *src);
  2703. /*!
  2704. * \brief Destroy the party name contents
  2705. * \since 1.8
  2706. *
  2707. * \param doomed The party name to destroy.
  2708. *
  2709. * \return Nothing
  2710. */
  2711. void ast_party_name_free(struct ast_party_name *doomed);
  2712. /*!
  2713. * \brief Initialize the given number structure.
  2714. * \since 1.8
  2715. *
  2716. * \param init Number structure to initialize.
  2717. *
  2718. * \return Nothing
  2719. */
  2720. void ast_party_number_init(struct ast_party_number *init);
  2721. /*!
  2722. * \brief Copy the source party number information to the destination party number.
  2723. * \since 1.8
  2724. *
  2725. * \param dest Destination party number
  2726. * \param src Source party number
  2727. *
  2728. * \return Nothing
  2729. */
  2730. void ast_party_number_copy(struct ast_party_number *dest, const struct ast_party_number *src);
  2731. /*!
  2732. * \brief Initialize the given party number structure using the given guide
  2733. * for a set update operation.
  2734. * \since 1.8
  2735. *
  2736. * \details
  2737. * The initialization is needed to allow a set operation to know if a
  2738. * value needs to be updated. Simple integers need the guide's original
  2739. * value in case the set operation is not trying to set a new value.
  2740. * String values are simply set to NULL pointers if they are not going
  2741. * to be updated.
  2742. *
  2743. * \param init Party number structure to initialize.
  2744. * \param guide Source party number to use as a guide in initializing.
  2745. *
  2746. * \return Nothing
  2747. */
  2748. void ast_party_number_set_init(struct ast_party_number *init, const struct ast_party_number *guide);
  2749. /*!
  2750. * \brief Set the source party number information into the destination party number.
  2751. * \since 1.8
  2752. *
  2753. * \param dest The number one wishes to update
  2754. * \param src The new number values to update the dest
  2755. *
  2756. * \return Nothing
  2757. */
  2758. void ast_party_number_set(struct ast_party_number *dest, const struct ast_party_number *src);
  2759. /*!
  2760. * \brief Destroy the party number contents
  2761. * \since 1.8
  2762. *
  2763. * \param doomed The party number to destroy.
  2764. *
  2765. * \return Nothing
  2766. */
  2767. void ast_party_number_free(struct ast_party_number *doomed);
  2768. /*!
  2769. * \since 1.8
  2770. * \brief Initialize the given subaddress structure.
  2771. *
  2772. * \param init Subaddress structure to initialize.
  2773. *
  2774. * \return Nothing
  2775. */
  2776. void ast_party_subaddress_init(struct ast_party_subaddress *init);
  2777. /*!
  2778. * \since 1.8
  2779. * \brief Copy the source party subaddress information to the destination party subaddress.
  2780. *
  2781. * \param dest Destination party subaddress
  2782. * \param src Source party subaddress
  2783. *
  2784. * \return Nothing
  2785. */
  2786. void ast_party_subaddress_copy(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
  2787. /*!
  2788. * \since 1.8
  2789. * \brief Initialize the given party subaddress structure using the given guide
  2790. * for a set update operation.
  2791. *
  2792. * \details
  2793. * The initialization is needed to allow a set operation to know if a
  2794. * value needs to be updated. Simple integers need the guide's original
  2795. * value in case the set operation is not trying to set a new value.
  2796. * String values are simply set to NULL pointers if they are not going
  2797. * to be updated.
  2798. *
  2799. * \param init Party subaddress structure to initialize.
  2800. * \param guide Source party subaddress to use as a guide in initializing.
  2801. *
  2802. * \return Nothing
  2803. */
  2804. void ast_party_subaddress_set_init(struct ast_party_subaddress *init, const struct ast_party_subaddress *guide);
  2805. /*!
  2806. * \since 1.8
  2807. * \brief Set the source party subaddress information into the destination party subaddress.
  2808. *
  2809. * \param dest The subaddress one wishes to update
  2810. * \param src The new subaddress values to update the dest
  2811. *
  2812. * \return Nothing
  2813. */
  2814. void ast_party_subaddress_set(struct ast_party_subaddress *dest, const struct ast_party_subaddress *src);
  2815. /*!
  2816. * \since 1.8
  2817. * \brief Destroy the party subaddress contents
  2818. *
  2819. * \param doomed The party subaddress to destroy.
  2820. *
  2821. * \return Nothing
  2822. */
  2823. void ast_party_subaddress_free(struct ast_party_subaddress *doomed);
  2824. /*!
  2825. * \brief Set the update marker to update all information of a corresponding party id.
  2826. * \since 11.0
  2827. *
  2828. * \param update_id The update marker for a corresponding party id.
  2829. *
  2830. * \return Nothing
  2831. */
  2832. void ast_set_party_id_all(struct ast_set_party_id *update_id);
  2833. /*!
  2834. * \brief Initialize the given party id structure.
  2835. * \since 1.8
  2836. *
  2837. * \param init Party id structure to initialize.
  2838. *
  2839. * \return Nothing
  2840. */
  2841. void ast_party_id_init(struct ast_party_id *init);
  2842. /*!
  2843. * \brief Copy the source party id information to the destination party id.
  2844. * \since 1.8
  2845. *
  2846. * \param dest Destination party id
  2847. * \param src Source party id
  2848. *
  2849. * \return Nothing
  2850. */
  2851. void ast_party_id_copy(struct ast_party_id *dest, const struct ast_party_id *src);
  2852. /*!
  2853. * \brief Initialize the given party id structure using the given guide
  2854. * for a set update operation.
  2855. * \since 1.8
  2856. *
  2857. * \details
  2858. * The initialization is needed to allow a set operation to know if a
  2859. * value needs to be updated. Simple integers need the guide's original
  2860. * value in case the set operation is not trying to set a new value.
  2861. * String values are simply set to NULL pointers if they are not going
  2862. * to be updated.
  2863. *
  2864. * \param init Party id structure to initialize.
  2865. * \param guide Source party id to use as a guide in initializing.
  2866. *
  2867. * \return Nothing
  2868. */
  2869. void ast_party_id_set_init(struct ast_party_id *init, const struct ast_party_id *guide);
  2870. /*!
  2871. * \brief Set the source party id information into the destination party id.
  2872. * \since 1.8
  2873. *
  2874. * \param dest The id one wishes to update
  2875. * \param src The new id values to update the dest
  2876. * \param update What id information to update. NULL if all.
  2877. *
  2878. * \return Nothing
  2879. */
  2880. void ast_party_id_set(struct ast_party_id *dest, const struct ast_party_id *src, const struct ast_set_party_id *update);
  2881. /*!
  2882. * \brief Destroy the party id contents
  2883. * \since 1.8
  2884. *
  2885. * \param doomed The party id to destroy.
  2886. *
  2887. * \return Nothing
  2888. */
  2889. void ast_party_id_free(struct ast_party_id *doomed);
  2890. /*!
  2891. * \brief Determine the overall presentation value for the given party.
  2892. * \since 1.8
  2893. *
  2894. * \param id Party to determine the overall presentation value.
  2895. *
  2896. * \return Overall presentation value for the given party.
  2897. */
  2898. int ast_party_id_presentation(const struct ast_party_id *id);
  2899. /*!
  2900. * \brief Invalidate all components of the given party id.
  2901. * \since 11.0
  2902. *
  2903. * \param id The party id to invalidate.
  2904. *
  2905. * \return Nothing
  2906. */
  2907. void ast_party_id_invalidate(struct ast_party_id *id);
  2908. /*!
  2909. * \brief Destroy and initialize the given party id structure.
  2910. * \since 11.0
  2911. *
  2912. * \param id The party id to reset.
  2913. *
  2914. * \return Nothing
  2915. */
  2916. void ast_party_id_reset(struct ast_party_id *id);
  2917. /*!
  2918. * \brief Merge a given party id into another given party id.
  2919. * \since 11.0
  2920. *
  2921. * \details
  2922. * This function will generate an effective party id.
  2923. *
  2924. * Each party id component of the party id 'base' is overwritten
  2925. * by components of the party id 'overlay' if the overlay
  2926. * component is marked as valid. However the component 'tag' of
  2927. * the base party id remains untouched.
  2928. *
  2929. * \param base The party id which is merged.
  2930. * \param overlay The party id which is used to merge into.
  2931. *
  2932. * \return The merged party id as a struct, not as a pointer.
  2933. * \note The merged party id returned is a shallow copy and must not be freed.
  2934. */
  2935. struct ast_party_id ast_party_id_merge(struct ast_party_id *base, struct ast_party_id *overlay);
  2936. /*!
  2937. * \brief Copy a merge of a given party id into another given party id to a given destination party id.
  2938. * \since 11.0
  2939. *
  2940. * \details
  2941. * Each party id component of the party id 'base' is overwritten by components
  2942. * of the party id 'overlay' if the 'overlay' component is marked as valid.
  2943. * However the component 'tag' of the 'base' party id remains untouched.
  2944. * The result is copied into the given party id 'dest'.
  2945. *
  2946. * \note The resulting merged party id is a real copy and has to be freed.
  2947. *
  2948. * \param dest The resulting merged party id.
  2949. * \param base The party id which is merged.
  2950. * \param overlay The party id which is used to merge into.
  2951. *
  2952. * \return Nothing
  2953. */
  2954. void ast_party_id_merge_copy(struct ast_party_id *dest, struct ast_party_id *base, struct ast_party_id *overlay);
  2955. /*!
  2956. * \brief Initialize the given dialed structure.
  2957. * \since 1.8
  2958. *
  2959. * \param init Dialed structure to initialize.
  2960. *
  2961. * \return Nothing
  2962. */
  2963. void ast_party_dialed_init(struct ast_party_dialed *init);
  2964. /*!
  2965. * \brief Copy the source dialed party information to the destination dialed party.
  2966. * \since 1.8
  2967. *
  2968. * \param dest Destination dialed party
  2969. * \param src Source dialed party
  2970. *
  2971. * \return Nothing
  2972. */
  2973. void ast_party_dialed_copy(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
  2974. /*!
  2975. * \brief Initialize the given dialed structure using the given
  2976. * guide for a set update operation.
  2977. * \since 1.8
  2978. *
  2979. * \details
  2980. * The initialization is needed to allow a set operation to know if a
  2981. * value needs to be updated. Simple integers need the guide's original
  2982. * value in case the set operation is not trying to set a new value.
  2983. * String values are simply set to NULL pointers if they are not going
  2984. * to be updated.
  2985. *
  2986. * \param init Caller structure to initialize.
  2987. * \param guide Source dialed to use as a guide in initializing.
  2988. *
  2989. * \return Nothing
  2990. */
  2991. void ast_party_dialed_set_init(struct ast_party_dialed *init, const struct ast_party_dialed *guide);
  2992. /*!
  2993. * \brief Set the dialed information based on another dialed source
  2994. * \since 1.8
  2995. *
  2996. * This is similar to ast_party_dialed_copy, except that NULL values for
  2997. * strings in the src parameter indicate not to update the corresponding dest values.
  2998. *
  2999. * \param dest The dialed one wishes to update
  3000. * \param src The new dialed values to update the dest
  3001. *
  3002. * \return Nada
  3003. */
  3004. void ast_party_dialed_set(struct ast_party_dialed *dest, const struct ast_party_dialed *src);
  3005. /*!
  3006. * \brief Destroy the dialed party contents
  3007. * \since 1.8
  3008. *
  3009. * \param doomed The dialed party to destroy.
  3010. *
  3011. * \return Nothing
  3012. */
  3013. void ast_party_dialed_free(struct ast_party_dialed *doomed);
  3014. /*!
  3015. * \since 1.8
  3016. * \brief Initialize the given caller structure.
  3017. *
  3018. * \param init Caller structure to initialize.
  3019. *
  3020. * \return Nothing
  3021. */
  3022. void ast_party_caller_init(struct ast_party_caller *init);
  3023. /*!
  3024. * \since 1.8
  3025. * \brief Copy the source caller information to the destination caller.
  3026. *
  3027. * \param dest Destination caller
  3028. * \param src Source caller
  3029. *
  3030. * \return Nothing
  3031. */
  3032. void ast_party_caller_copy(struct ast_party_caller *dest, const struct ast_party_caller *src);
  3033. /*!
  3034. * \brief Initialize the given caller structure using the given
  3035. * guide for a set update operation.
  3036. * \since 1.8
  3037. *
  3038. * \details
  3039. * The initialization is needed to allow a set operation to know if a
  3040. * value needs to be updated. Simple integers need the guide's original
  3041. * value in case the set operation is not trying to set a new value.
  3042. * String values are simply set to NULL pointers if they are not going
  3043. * to be updated.
  3044. *
  3045. * \param init Caller structure to initialize.
  3046. * \param guide Source caller to use as a guide in initializing.
  3047. *
  3048. * \return Nothing
  3049. */
  3050. void ast_party_caller_set_init(struct ast_party_caller *init, const struct ast_party_caller *guide);
  3051. /*!
  3052. * \brief Set the caller information based on another caller source
  3053. * \since 1.8
  3054. *
  3055. * This is similar to ast_party_caller_copy, except that NULL values for
  3056. * strings in the src parameter indicate not to update the corresponding dest values.
  3057. *
  3058. * \param dest The caller one wishes to update
  3059. * \param src The new caller values to update the dest
  3060. * \param update What caller information to update. NULL if all.
  3061. *
  3062. * \return Nada
  3063. */
  3064. void ast_party_caller_set(struct ast_party_caller *dest, const struct ast_party_caller *src, const struct ast_set_party_caller *update);
  3065. /*!
  3066. * \brief Destroy the caller party contents
  3067. * \since 1.8
  3068. *
  3069. * \param doomed The caller party to destroy.
  3070. *
  3071. * \return Nothing
  3072. */
  3073. void ast_party_caller_free(struct ast_party_caller *doomed);
  3074. /*!
  3075. * \since 1.8
  3076. * \brief Initialize the given connected line structure.
  3077. *
  3078. * \param init Connected line structure to initialize.
  3079. *
  3080. * \return Nothing
  3081. */
  3082. void ast_party_connected_line_init(struct ast_party_connected_line *init);
  3083. /*!
  3084. * \since 1.8
  3085. * \brief Copy the source connected line information to the destination connected line.
  3086. *
  3087. * \param dest Destination connected line
  3088. * \param src Source connected line
  3089. *
  3090. * \return Nothing
  3091. */
  3092. void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src);
  3093. /*!
  3094. * \since 1.8
  3095. * \brief Initialize the given connected line structure using the given
  3096. * guide for a set update operation.
  3097. *
  3098. * \details
  3099. * The initialization is needed to allow a set operation to know if a
  3100. * value needs to be updated. Simple integers need the guide's original
  3101. * value in case the set operation is not trying to set a new value.
  3102. * String values are simply set to NULL pointers if they are not going
  3103. * to be updated.
  3104. *
  3105. * \param init Connected line structure to initialize.
  3106. * \param guide Source connected line to use as a guide in initializing.
  3107. *
  3108. * \return Nothing
  3109. */
  3110. void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide);
  3111. /*!
  3112. * \since 1.8
  3113. * \brief Set the connected line information based on another connected line source
  3114. *
  3115. * This is similar to ast_party_connected_line_copy, except that NULL values for
  3116. * strings in the src parameter indicate not to update the corresponding dest values.
  3117. *
  3118. * \param dest The connected line one wishes to update
  3119. * \param src The new connected line values to update the dest
  3120. * \param update What connected line information to update. NULL if all.
  3121. *
  3122. * \return Nothing
  3123. */
  3124. void ast_party_connected_line_set(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src, const struct ast_set_party_connected_line *update);
  3125. /*!
  3126. * \since 1.8
  3127. * \brief Collect the caller party information into a connected line structure.
  3128. *
  3129. * \param connected Collected caller information for the connected line
  3130. * \param caller Caller information.
  3131. *
  3132. * \return Nothing
  3133. *
  3134. * \warning This is a shallow copy.
  3135. * \warning DO NOT call ast_party_connected_line_free() on the filled in
  3136. * connected line structure!
  3137. */
  3138. void ast_party_connected_line_collect_caller(struct ast_party_connected_line *connected, struct ast_party_caller *caller);
  3139. /*!
  3140. * \since 1.8
  3141. * \brief Destroy the connected line information contents
  3142. *
  3143. * \param doomed The connected line information to destroy.
  3144. *
  3145. * \return Nothing
  3146. */
  3147. void ast_party_connected_line_free(struct ast_party_connected_line *doomed);
  3148. /*!
  3149. * \brief Initialize the given redirecting reason structure
  3150. *
  3151. * \param init Redirecting reason structure to initialize
  3152. *
  3153. * \return Nothing
  3154. */
  3155. void ast_party_redirecting_reason_init(struct ast_party_redirecting_reason *init);
  3156. /*!
  3157. * \brief Copy the source redirecting reason information to the destination redirecting reason.
  3158. *
  3159. * \param dest Destination redirecting reason
  3160. * \param src Source redirecting reason
  3161. *
  3162. * \return Nothing
  3163. */
  3164. void ast_party_redirecting_reason_copy(struct ast_party_redirecting_reason *dest,
  3165. const struct ast_party_redirecting_reason *src);
  3166. /*!
  3167. * \brief Initialize the given redirecting reason structure using the given guide
  3168. * for a set update operation.
  3169. *
  3170. * \details
  3171. * The initialization is needed to allow a set operation to know if a
  3172. * value needs to be updated. Simple integers need the guide's original
  3173. * value in case the set operation is not trying to set a new value.
  3174. * String values are simply set to NULL pointers if they are not going
  3175. * to be updated.
  3176. *
  3177. * \param init Redirecting reason structure to initialize.
  3178. * \param guide Source redirecting reason to use as a guide in initializing.
  3179. *
  3180. * \return Nothing
  3181. */
  3182. void ast_party_redirecting_reason_set_init(struct ast_party_redirecting_reason *init,
  3183. const struct ast_party_redirecting_reason *guide);
  3184. /*!
  3185. * \brief Set the redirecting reason information based on another redirecting reason source
  3186. *
  3187. * This is similar to ast_party_redirecting_reason_copy, except that NULL values for
  3188. * strings in the src parameter indicate not to update the corresponding dest values.
  3189. *
  3190. * \param dest The redirecting reason one wishes to update
  3191. * \param src The new redirecting reason values to update the dest
  3192. *
  3193. * \return Nothing
  3194. */
  3195. void ast_party_redirecting_reason_set(struct ast_party_redirecting_reason *dest,
  3196. const struct ast_party_redirecting_reason *src);
  3197. /*!
  3198. * \brief Destroy the redirecting reason contents
  3199. *
  3200. * \param doomed The redirecting reason to destroy.
  3201. *
  3202. * \return Nothing
  3203. */
  3204. void ast_party_redirecting_reason_free(struct ast_party_redirecting_reason *doomed);
  3205. /*!
  3206. * \brief Initialize the given redirecting structure.
  3207. * \since 1.8
  3208. *
  3209. * \param init Redirecting structure to initialize.
  3210. *
  3211. * \return Nothing
  3212. */
  3213. void ast_party_redirecting_init(struct ast_party_redirecting *init);
  3214. /*!
  3215. * \since 1.8
  3216. * \brief Copy the source redirecting information to the destination redirecting.
  3217. *
  3218. * \param dest Destination redirecting
  3219. * \param src Source redirecting
  3220. *
  3221. * \return Nothing
  3222. */
  3223. void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src);
  3224. /*!
  3225. * \since 1.8
  3226. * \brief Initialize the given redirecting id structure using the given guide
  3227. * for a set update operation.
  3228. *
  3229. * \details
  3230. * The initialization is needed to allow a set operation to know if a
  3231. * value needs to be updated. Simple integers need the guide's original
  3232. * value in case the set operation is not trying to set a new value.
  3233. * String values are simply set to NULL pointers if they are not going
  3234. * to be updated.
  3235. *
  3236. * \param init Redirecting id structure to initialize.
  3237. * \param guide Source redirecting id to use as a guide in initializing.
  3238. *
  3239. * \return Nothing
  3240. */
  3241. void ast_party_redirecting_set_init(struct ast_party_redirecting *init, const struct ast_party_redirecting *guide);
  3242. /*!
  3243. * \brief Set the redirecting information based on another redirecting source
  3244. * \since 1.8
  3245. *
  3246. * This is similar to ast_party_redirecting_copy, except that NULL values for
  3247. * strings in the src parameter indicate not to update the corresponding dest values.
  3248. *
  3249. * \param dest The redirecting one wishes to update
  3250. * \param src The new redirecting values to update the dest
  3251. * \param update What redirecting information to update. NULL if all.
  3252. *
  3253. * \return Nothing
  3254. */
  3255. void ast_party_redirecting_set(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src, const struct ast_set_party_redirecting *update);
  3256. /*!
  3257. * \since 1.8
  3258. * \brief Destroy the redirecting information contents
  3259. *
  3260. * \param doomed The redirecting information to destroy.
  3261. *
  3262. * \return Nothing
  3263. */
  3264. void ast_party_redirecting_free(struct ast_party_redirecting *doomed);
  3265. /*!
  3266. * \since 1.8
  3267. * \brief Copy the caller information to the connected line information.
  3268. *
  3269. * \param dest Destination connected line information
  3270. * \param src Source caller information
  3271. *
  3272. * \return Nothing
  3273. *
  3274. * \note Assumes locks are already acquired
  3275. */
  3276. void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src);
  3277. /*!
  3278. * \since 1.8
  3279. * \brief Copy the connected line information to the caller information.
  3280. *
  3281. * \param dest Destination caller information
  3282. * \param src Source connected line information
  3283. *
  3284. * \return Nothing
  3285. *
  3286. * \note Assumes locks are already acquired
  3287. */
  3288. void ast_connected_line_copy_to_caller(struct ast_party_caller *dest, const struct ast_party_connected_line *src);
  3289. /*!
  3290. * \since 1.8
  3291. * \brief Set the connected line information in the Asterisk channel
  3292. *
  3293. * \param chan Asterisk channel to set connected line information
  3294. * \param connected Connected line information
  3295. * \param update What connected line information to update. NULL if all.
  3296. *
  3297. * \return Nothing
  3298. *
  3299. * \note The channel does not need to be locked before calling this function.
  3300. */
  3301. void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
  3302. /*!
  3303. * \since 1.8
  3304. * \brief Build the connected line information data frame.
  3305. *
  3306. * \param data Buffer to fill with the frame data
  3307. * \param datalen Size of the buffer to fill
  3308. * \param connected Connected line information
  3309. * \param update What connected line information to build. NULL if all.
  3310. *
  3311. * \retval -1 if error
  3312. * \retval Amount of data buffer used
  3313. */
  3314. int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
  3315. /*!
  3316. * \since 1.8
  3317. * \brief Parse connected line indication frame data
  3318. *
  3319. * \param data Buffer with the frame data to parse
  3320. * \param datalen Size of the buffer
  3321. * \param connected Extracted connected line information
  3322. *
  3323. * \retval 0 on success.
  3324. * \retval -1 on error.
  3325. *
  3326. * \note The filled in connected line structure needs to be initialized by
  3327. * ast_party_connected_line_set_init() before calling. If defaults are not
  3328. * required use ast_party_connected_line_init().
  3329. * \note The filled in connected line structure needs to be destroyed by
  3330. * ast_party_connected_line_free() when it is no longer needed.
  3331. */
  3332. int ast_connected_line_parse_data(const unsigned char *data, size_t datalen, struct ast_party_connected_line *connected);
  3333. /*!
  3334. * \since 1.8
  3335. * \brief Indicate that the connected line information has changed
  3336. *
  3337. * \param chan Asterisk channel to indicate connected line information
  3338. * \param connected Connected line information
  3339. * \param update What connected line information to update. NULL if all.
  3340. *
  3341. * \return Nothing
  3342. */
  3343. void ast_channel_update_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
  3344. /*!
  3345. * \since 1.8
  3346. * \brief Queue a connected line update frame on a channel
  3347. *
  3348. * \param chan Asterisk channel to indicate connected line information
  3349. * \param connected Connected line information
  3350. * \param update What connected line information to update. NULL if all.
  3351. *
  3352. * \return Nothing
  3353. */
  3354. void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
  3355. /*!
  3356. * \since 1.8
  3357. * \brief Set the redirecting id information in the Asterisk channel
  3358. *
  3359. * \param chan Asterisk channel to set redirecting id information
  3360. * \param redirecting Redirecting id information
  3361. * \param update What redirecting information to update. NULL if all.
  3362. *
  3363. * \return Nothing
  3364. *
  3365. * \note The channel does not need to be locked before calling this function.
  3366. */
  3367. void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
  3368. /*!
  3369. * \since 1.8
  3370. * \brief Build the redirecting id data frame.
  3371. *
  3372. * \param data Buffer to fill with the frame data
  3373. * \param datalen Size of the buffer to fill
  3374. * \param redirecting Redirecting id information
  3375. * \param update What redirecting information to build. NULL if all.
  3376. *
  3377. * \retval -1 if error
  3378. * \retval Amount of data buffer used
  3379. */
  3380. int ast_redirecting_build_data(unsigned char *data, size_t datalen, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
  3381. /*!
  3382. * \since 1.8
  3383. * \brief Parse redirecting indication frame data
  3384. *
  3385. * \param data Buffer with the frame data to parse
  3386. * \param datalen Size of the buffer
  3387. * \param redirecting Extracted redirecting id information
  3388. *
  3389. * \retval 0 on success.
  3390. * \retval -1 on error.
  3391. *
  3392. * \note The filled in id structure needs to be initialized by
  3393. * ast_party_redirecting_set_init() before calling.
  3394. * \note The filled in id structure needs to be destroyed by
  3395. * ast_party_redirecting_free() when it is no longer needed.
  3396. */
  3397. int ast_redirecting_parse_data(const unsigned char *data, size_t datalen, struct ast_party_redirecting *redirecting);
  3398. /*!
  3399. * \since 1.8
  3400. * \brief Indicate that the redirecting id has changed
  3401. *
  3402. * \param chan Asterisk channel to indicate redirecting id information
  3403. * \param redirecting Redirecting id information
  3404. * \param update What redirecting information to update. NULL if all.
  3405. *
  3406. * \return Nothing
  3407. */
  3408. void ast_channel_update_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
  3409. /*!
  3410. * \since 1.8
  3411. * \brief Queue a redirecting update frame on a channel
  3412. *
  3413. * \param chan Asterisk channel to indicate redirecting id information
  3414. * \param redirecting Redirecting id information
  3415. * \param update What redirecting information to update. NULL if all.
  3416. *
  3417. * \return Nothing
  3418. */
  3419. void ast_channel_queue_redirecting_update(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
  3420. /*!
  3421. * \since 1.8
  3422. * \brief Run a connected line interception macro and update a channel's connected line
  3423. * information
  3424. * \deprecated You should use the ast_channel_connected_line_sub() function instead.
  3425. *
  3426. * Whenever we want to update a channel's connected line information, we may need to run
  3427. * a macro so that an administrator can manipulate the information before sending it
  3428. * out. This function both runs the macro and sends the update to the channel.
  3429. *
  3430. * \param autoservice_chan Channel to place into autoservice while the macro is running.
  3431. * It is perfectly safe for this to be NULL
  3432. * \param macro_chan The channel to run the macro on. Also the channel from which we
  3433. * determine which macro we need to run.
  3434. * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
  3435. * AST_CONTROL_CONNECTED_LINE
  3436. * \param is_caller If true, then run CONNECTED_LINE_CALLER_SEND_MACRO with arguments from
  3437. * CONNECTED_LINE_CALLER_SEND_MACRO_ARGS, otherwise run CONNECTED_LINE_CALLEE_SEND_MACRO
  3438. * with arguments from CONNECTED_LINE_CALLEE_SEND_MACRO_ARGS
  3439. * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
  3440. * ast_party_connected_line pointer.
  3441. * \retval 0 Success
  3442. * \retval -1 Either the macro does not exist, or there was an error while attempting to
  3443. * run the macro
  3444. *
  3445. * \todo Have multiple return codes based on the MACRO_RESULT
  3446. * \todo Make constants so that caller and frame can be more expressive than just '1' and
  3447. * '0'
  3448. */
  3449. int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int frame);
  3450. /*!
  3451. * \since 11
  3452. * \brief Run a connected line interception subroutine and update a channel's connected line
  3453. * information
  3454. *
  3455. * Whenever we want to update a channel's connected line information, we may need to run
  3456. * a subroutine so that an administrator can manipulate the information before sending it
  3457. * out. This function both runs the subroutine specified by CONNECTED_LINE_SEND_SUB and
  3458. * sends the update to the channel.
  3459. *
  3460. * \param autoservice_chan Channel to place into autoservice while the sub is running.
  3461. * It is perfectly safe for this to be NULL
  3462. * \param sub_chan The channel to run the subroutine on. Also the channel from which we
  3463. * determine which subroutine we need to run.
  3464. * \param connected_info Either an ast_party_connected_line or ast_frame pointer of type
  3465. * AST_CONTROL_CONNECTED_LINE
  3466. * \param frame If true, then connected_info is an ast_frame pointer, otherwise it is an
  3467. * ast_party_connected_line pointer.
  3468. * \retval 0 Success
  3469. * \retval -1 Either the subroutine does not exist, or there was an error while attempting to
  3470. * run the subroutine
  3471. */
  3472. int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame);
  3473. /*!
  3474. * \brief Insert into an astdata tree, the channel structure.
  3475. * \param[in] tree The ast data tree.
  3476. * \param[in] chan The channel structure to add to tree.
  3477. * \param[in] add_bridged Add the bridged channel to the structure.
  3478. * \retval <0 on error.
  3479. * \retval 0 on success.
  3480. */
  3481. int ast_channel_data_add_structure(struct ast_data *tree, struct ast_channel *chan, int add_bridged);
  3482. /*!
  3483. * \brief Compare to channel structures using the data api.
  3484. * \param[in] tree The search tree generated by the data api.
  3485. * \param[in] chan The channel to compare.
  3486. * \param[in] structure_name The name of the node of the channel structure.
  3487. * \retval 0 The structure matches.
  3488. * \retval 1 The structure doesn't matches.
  3489. */
  3490. int ast_channel_data_cmp_structure(const struct ast_data_search *tree, struct ast_channel *chan,
  3491. const char *structure_name);
  3492. /*!
  3493. * \since 1.8
  3494. * \brief Run a redirecting interception macro and update a channel's redirecting information
  3495. * \deprecated You should use the ast_channel_redirecting_sub() function instead.
  3496. *
  3497. * \details
  3498. * Whenever we want to update a channel's redirecting information, we may need to run
  3499. * a macro so that an administrator can manipulate the information before sending it
  3500. * out. This function both runs the macro and sends the update to the channel.
  3501. *
  3502. * \param autoservice_chan Channel to place into autoservice while the macro is running.
  3503. * It is perfectly safe for this to be NULL
  3504. * \param macro_chan The channel to run the macro on. Also the channel from which we
  3505. * determine which macro we need to run.
  3506. * \param redirecting_info Either an ast_party_redirecting or ast_frame pointer of type
  3507. * AST_CONTROL_REDIRECTING
  3508. * \param is_caller If true, then run REDIRECTING_CALLER_SEND_MACRO with arguments from
  3509. * REDIRECTING_CALLER_SEND_MACRO_ARGS, otherwise run REDIRECTING_CALLEE_SEND_MACRO with
  3510. * arguments from REDIRECTING_CALLEE_SEND_MACRO_ARGS
  3511. * \param is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an
  3512. * ast_party_redirecting pointer.
  3513. *
  3514. * \retval 0 Success
  3515. * \retval -1 Either the macro does not exist, or there was an error while attempting to
  3516. * run the macro
  3517. *
  3518. * \todo Have multiple return codes based on the MACRO_RESULT
  3519. * \todo Make constants so that caller and frame can be more expressive than just '1' and
  3520. * '0'
  3521. */
  3522. int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame);
  3523. /*!
  3524. * \since 11
  3525. * \brief Run a redirecting interception subroutine and update a channel's redirecting information
  3526. *
  3527. * \details
  3528. * Whenever we want to update a channel's redirecting information, we may need to run
  3529. * a subroutine so that an administrator can manipulate the information before sending it
  3530. * out. This function both runs the subroutine specified by REDIRECTING_SEND_SUB and
  3531. * sends the update to the channel.
  3532. *
  3533. * \param autoservice_chan Channel to place into autoservice while the subroutine is running.
  3534. * It is perfectly safe for this to be NULL
  3535. * \param sub_chan The channel to run the subroutine on. Also the channel from which we
  3536. * determine which subroutine we need to run.
  3537. * \param redirecting_info Either an ast_party_redirecting or ast_frame pointer of type
  3538. * AST_CONTROL_REDIRECTING
  3539. * \param is_frame If true, then redirecting_info is an ast_frame pointer, otherwise it is an
  3540. * ast_party_redirecting pointer.
  3541. *
  3542. * \retval 0 Success
  3543. * \retval -1 Either the subroutine does not exist, or there was an error while attempting to
  3544. * run the subroutine
  3545. */
  3546. int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame);
  3547. #include "asterisk/ccss.h"
  3548. /*!
  3549. * \since 1.8
  3550. * \brief Set up datastore with CCSS parameters for a channel
  3551. *
  3552. * \note
  3553. * If base_params is NULL, the channel will get the default
  3554. * values for all CCSS parameters.
  3555. *
  3556. * \details
  3557. * This function makes use of datastore operations on the channel, so
  3558. * it is important to lock the channel before calling this function.
  3559. *
  3560. * \param chan The channel to create the datastore on
  3561. * \param base_params CCSS parameters we wish to copy into the channel
  3562. * \retval 0 Success
  3563. * \retval -1 Failure
  3564. */
  3565. int ast_channel_cc_params_init(struct ast_channel *chan,
  3566. const struct ast_cc_config_params *base_params);
  3567. /*!
  3568. * \since 1.8
  3569. * \brief Get the CCSS parameters from a channel
  3570. *
  3571. * \details
  3572. * This function makes use of datastore operations on the channel, so
  3573. * it is important to lock the channel before calling this function.
  3574. *
  3575. * \param chan Channel to retrieve parameters from
  3576. * \retval NULL Failure
  3577. * \retval non-NULL The parameters desired
  3578. */
  3579. struct ast_cc_config_params *ast_channel_get_cc_config_params(struct ast_channel *chan);
  3580. /*!
  3581. * \since 1.8
  3582. * \brief Get a device name given its channel structure
  3583. *
  3584. * \details
  3585. * A common practice in Asterisk is to determine the device being talked
  3586. * to by dissecting the channel name. For certain channel types, this is not
  3587. * accurate. For instance, an ISDN channel is named based on what B channel is
  3588. * used, not the device being communicated with.
  3589. *
  3590. * This function interfaces with a channel tech's queryoption callback to
  3591. * retrieve the name of the device being communicated with. If the channel does not
  3592. * implement this specific option, then the traditional method of using the channel
  3593. * name is used instead.
  3594. *
  3595. * \param chan The channel to retrieve the information from
  3596. * \param[out] device_name The buffer to place the device's name into
  3597. * \param name_buffer_length The allocated space for the device_name
  3598. * \return 0 always
  3599. */
  3600. int ast_channel_get_device_name(struct ast_channel *chan, char *device_name, size_t name_buffer_length);
  3601. /*!
  3602. * \since 1.8
  3603. * \brief Find the appropriate CC agent type to use given a channel
  3604. *
  3605. * \details
  3606. * During call completion, we will need to create a call completion agent structure. To
  3607. * figure out the type of agent to construct, we need to ask the channel driver for the
  3608. * appropriate type.
  3609. *
  3610. * Prior to adding this function, the call completion core attempted to figure this
  3611. * out for itself by stripping the technology off the channel's name. However, in the
  3612. * case of chan_dahdi, there are multiple agent types registered, and so simply searching
  3613. * for an agent type called "DAHDI" is not possible. In a case where multiple agent types
  3614. * are defined, the channel driver must have a queryoption callback defined in its
  3615. * channel_tech, and the queryoption callback must handle AST_OPTION_CC_AGENT_TYPE
  3616. *
  3617. * If a channel driver does not have a queryoption callback or if the queryoption callback
  3618. * does not handle AST_OPTION_CC_AGENT_TYPE, then the old behavior of using the technology
  3619. * portion of the channel name is used instead. This is perfectly suitable for channel drivers
  3620. * whose channel technologies are a one-to-one match with the agent types defined within.
  3621. *
  3622. * Note that this function is only called when the agent policy on a given channel is set
  3623. * to "native." Generic agents' type can be determined automatically by the core.
  3624. *
  3625. * \param chan The channel for which we wish to retrieve the agent type
  3626. * \param[out] agent_type The type of agent the channel driver wants us to use
  3627. * \param size The size of the buffer to write to
  3628. */
  3629. int ast_channel_get_cc_agent_type(struct ast_channel *chan, char *agent_type, size_t size);
  3630. #if defined(__cplusplus) || defined(c_plusplus)
  3631. }
  3632. #endif
  3633. /*!
  3634. * \brief Remove a channel from the global channels container
  3635. *
  3636. * \param chan channel to remove
  3637. *
  3638. * In a case where it is desired that a channel not be available in any lookups
  3639. * in the global channels conatiner, use this function.
  3640. */
  3641. void ast_channel_unlink(struct ast_channel *chan);
  3642. /*!
  3643. * \brief Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash
  3644. * on the given channel
  3645. *
  3646. * \param chan channel on which to set the cause information
  3647. * \param cause_code ast_control_pvt_cause_code structure containing cause information
  3648. * \param datalen total length of the structure since it may vary
  3649. */
  3650. void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen);
  3651. /*!
  3652. * \since 12
  3653. * \brief Convert a string to a detail record AMA flag
  3654. *
  3655. * \param flag string form of flag
  3656. *
  3657. * \retval the enum (integer) form of the flag
  3658. */
  3659. enum ama_flags ast_channel_string2amaflag(const char *flag);
  3660. /*!
  3661. * \since 12
  3662. * \brief Convert the enum representation of an AMA flag to a string representation
  3663. *
  3664. * \param flags integer flag
  3665. *
  3666. * \retval A string representation of the flag
  3667. */
  3668. const char *ast_channel_amaflags2string(enum ama_flags flags);
  3669. enum AST_MONITORING_STATE {
  3670. AST_MONITOR_RUNNING,
  3671. AST_MONITOR_PAUSED
  3672. };
  3673. /*! Responsible for channel monitoring data */
  3674. struct ast_channel_monitor {
  3675. struct ast_filestream *read_stream;
  3676. struct ast_filestream *write_stream;
  3677. char read_filename[FILENAME_MAX];
  3678. char write_filename[FILENAME_MAX];
  3679. char filename_base[FILENAME_MAX];
  3680. char beep_id[64];
  3681. int filename_changed;
  3682. char *format;
  3683. int joinfiles;
  3684. enum AST_MONITORING_STATE state;
  3685. int (*stop)(struct ast_channel *chan, int need_lock);
  3686. };
  3687. /* ACCESSOR FUNTIONS */
  3688. /*! \brief Set the channel name */
  3689. void ast_channel_name_set(struct ast_channel *chan, const char *name);
  3690. #define DECLARE_STRINGFIELD_SETTERS_FOR(field) \
  3691. void ast_channel_##field##_set(struct ast_channel *chan, const char *field); \
  3692. void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) __attribute__((format(printf, 2, 0))); \
  3693. void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) __attribute__((format(printf, 2, 3)))
  3694. /*!
  3695. * The following string fields result in channel snapshot creation and
  3696. * should have the channel locked when called:
  3697. *
  3698. * \li language
  3699. * \li accountcode
  3700. * \li peeraccount
  3701. * \li linkedid
  3702. */
  3703. DECLARE_STRINGFIELD_SETTERS_FOR(name);
  3704. DECLARE_STRINGFIELD_SETTERS_FOR(language);
  3705. DECLARE_STRINGFIELD_SETTERS_FOR(musicclass);
  3706. DECLARE_STRINGFIELD_SETTERS_FOR(latest_musicclass);
  3707. DECLARE_STRINGFIELD_SETTERS_FOR(accountcode);
  3708. DECLARE_STRINGFIELD_SETTERS_FOR(peeraccount);
  3709. DECLARE_STRINGFIELD_SETTERS_FOR(userfield);
  3710. DECLARE_STRINGFIELD_SETTERS_FOR(call_forward);
  3711. DECLARE_STRINGFIELD_SETTERS_FOR(uniqueid);
  3712. DECLARE_STRINGFIELD_SETTERS_FOR(linkedid);
  3713. DECLARE_STRINGFIELD_SETTERS_FOR(parkinglot);
  3714. DECLARE_STRINGFIELD_SETTERS_FOR(hangupsource);
  3715. DECLARE_STRINGFIELD_SETTERS_FOR(dialcontext);
  3716. const char *ast_channel_name(const struct ast_channel *chan);
  3717. const char *ast_channel_language(const struct ast_channel *chan);
  3718. const char *ast_channel_musicclass(const struct ast_channel *chan);
  3719. const char *ast_channel_latest_musicclass(const struct ast_channel *chan);
  3720. const char *ast_channel_accountcode(const struct ast_channel *chan);
  3721. const char *ast_channel_peeraccount(const struct ast_channel *chan);
  3722. const char *ast_channel_userfield(const struct ast_channel *chan);
  3723. const char *ast_channel_call_forward(const struct ast_channel *chan);
  3724. const char *ast_channel_uniqueid(const struct ast_channel *chan);
  3725. const char *ast_channel_linkedid(const struct ast_channel *chan);
  3726. const char *ast_channel_parkinglot(const struct ast_channel *chan);
  3727. const char *ast_channel_hangupsource(const struct ast_channel *chan);
  3728. const char *ast_channel_dialcontext(const struct ast_channel *chan);
  3729. const char *ast_channel_appl(const struct ast_channel *chan);
  3730. void ast_channel_appl_set(struct ast_channel *chan, const char *value);
  3731. const char *ast_channel_blockproc(const struct ast_channel *chan);
  3732. void ast_channel_blockproc_set(struct ast_channel *chan, const char *value);
  3733. const char *ast_channel_data(const struct ast_channel *chan);
  3734. void ast_channel_data_set(struct ast_channel *chan, const char *value);
  3735. const char *ast_channel_context(const struct ast_channel *chan);
  3736. void ast_channel_context_set(struct ast_channel *chan, const char *value);
  3737. const char *ast_channel_exten(const struct ast_channel *chan);
  3738. void ast_channel_exten_set(struct ast_channel *chan, const char *value);
  3739. const char *ast_channel_macrocontext(const struct ast_channel *chan);
  3740. void ast_channel_macrocontext_set(struct ast_channel *chan, const char *value);
  3741. const char *ast_channel_macroexten(const struct ast_channel *chan);
  3742. void ast_channel_macroexten_set(struct ast_channel *chan, const char *value);
  3743. char ast_channel_dtmf_digit_to_emulate(const struct ast_channel *chan);
  3744. void ast_channel_dtmf_digit_to_emulate_set(struct ast_channel *chan, char value);
  3745. char ast_channel_sending_dtmf_digit(const struct ast_channel *chan);
  3746. void ast_channel_sending_dtmf_digit_set(struct ast_channel *chan, char value);
  3747. struct timeval ast_channel_sending_dtmf_tv(const struct ast_channel *chan);
  3748. void ast_channel_sending_dtmf_tv_set(struct ast_channel *chan, struct timeval value);
  3749. enum ama_flags ast_channel_amaflags(const struct ast_channel *chan);
  3750. /*!
  3751. * \pre chan is locked
  3752. */
  3753. void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value);
  3754. int ast_channel_epfd(const struct ast_channel *chan);
  3755. void ast_channel_epfd_set(struct ast_channel *chan, int value);
  3756. int ast_channel_fdno(const struct ast_channel *chan);
  3757. void ast_channel_fdno_set(struct ast_channel *chan, int value);
  3758. int ast_channel_hangupcause(const struct ast_channel *chan);
  3759. void ast_channel_hangupcause_set(struct ast_channel *chan, int value);
  3760. int ast_channel_macropriority(const struct ast_channel *chan);
  3761. void ast_channel_macropriority_set(struct ast_channel *chan, int value);
  3762. int ast_channel_priority(const struct ast_channel *chan);
  3763. void ast_channel_priority_set(struct ast_channel *chan, int value);
  3764. int ast_channel_rings(const struct ast_channel *chan);
  3765. void ast_channel_rings_set(struct ast_channel *chan, int value);
  3766. int ast_channel_streamid(const struct ast_channel *chan);
  3767. void ast_channel_streamid_set(struct ast_channel *chan, int value);
  3768. int ast_channel_timingfd(const struct ast_channel *chan);
  3769. void ast_channel_timingfd_set(struct ast_channel *chan, int value);
  3770. int ast_channel_visible_indication(const struct ast_channel *chan);
  3771. void ast_channel_visible_indication_set(struct ast_channel *chan, int value);
  3772. int ast_channel_hold_state(const struct ast_channel *chan);
  3773. void ast_channel_hold_state_set(struct ast_channel *chan, int value);
  3774. int ast_channel_vstreamid(const struct ast_channel *chan);
  3775. void ast_channel_vstreamid_set(struct ast_channel *chan, int value);
  3776. unsigned short ast_channel_transfercapability(const struct ast_channel *chan);
  3777. void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value);
  3778. unsigned int ast_channel_emulate_dtmf_duration(const struct ast_channel *chan);
  3779. void ast_channel_emulate_dtmf_duration_set(struct ast_channel *chan, unsigned int value);
  3780. unsigned int ast_channel_fin(const struct ast_channel *chan);
  3781. void ast_channel_fin_set(struct ast_channel *chan, unsigned int value);
  3782. unsigned int ast_channel_fout(const struct ast_channel *chan);
  3783. void ast_channel_fout_set(struct ast_channel *chan, unsigned int value);
  3784. unsigned long ast_channel_insmpl(const struct ast_channel *chan);
  3785. void ast_channel_insmpl_set(struct ast_channel *chan, unsigned long value);
  3786. unsigned long ast_channel_outsmpl(const struct ast_channel *chan);
  3787. void ast_channel_outsmpl_set(struct ast_channel *chan, unsigned long value);
  3788. void *ast_channel_generatordata(const struct ast_channel *chan);
  3789. void ast_channel_generatordata_set(struct ast_channel *chan, void *value);
  3790. void *ast_channel_music_state(const struct ast_channel *chan);
  3791. void ast_channel_music_state_set(struct ast_channel *chan, void *value);
  3792. void *ast_channel_tech_pvt(const struct ast_channel *chan);
  3793. void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value);
  3794. void *ast_channel_timingdata(const struct ast_channel *chan);
  3795. void ast_channel_timingdata_set(struct ast_channel *chan, void *value);
  3796. struct ast_audiohook_list *ast_channel_audiohooks(const struct ast_channel *chan);
  3797. void ast_channel_audiohooks_set(struct ast_channel *chan, struct ast_audiohook_list *value);
  3798. struct ast_cdr *ast_channel_cdr(const struct ast_channel *chan);
  3799. void ast_channel_cdr_set(struct ast_channel *chan, struct ast_cdr *value);
  3800. struct ast_channel *ast_channel__bridge(const struct ast_channel *chan);
  3801. void ast_channel__bridge_set(struct ast_channel *chan, struct ast_channel *value);
  3802. struct ast_channel *ast_channel_masq(const struct ast_channel *chan);
  3803. void ast_channel_masq_set(struct ast_channel *chan, struct ast_channel *value);
  3804. struct ast_channel *ast_channel_masqr(const struct ast_channel *chan);
  3805. void ast_channel_masqr_set(struct ast_channel *chan, struct ast_channel *value);
  3806. struct ast_channel_monitor *ast_channel_monitor(const struct ast_channel *chan);
  3807. void ast_channel_monitor_set(struct ast_channel *chan, struct ast_channel_monitor *value);
  3808. struct ast_filestream *ast_channel_stream(const struct ast_channel *chan);
  3809. void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value);
  3810. struct ast_filestream *ast_channel_vstream(const struct ast_channel *chan);
  3811. void ast_channel_vstream_set(struct ast_channel *chan, struct ast_filestream *value);
  3812. struct ast_format_cap *ast_channel_nativeformats(const struct ast_channel *chan);
  3813. void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value);
  3814. struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan);
  3815. void ast_channel_framehooks_set(struct ast_channel *chan, struct ast_framehook_list *value);
  3816. struct ast_generator *ast_channel_generator(const struct ast_channel *chan);
  3817. void ast_channel_generator_set(struct ast_channel *chan, struct ast_generator *value);
  3818. struct ast_pbx *ast_channel_pbx(const struct ast_channel *chan);
  3819. void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value);
  3820. struct ast_sched_context *ast_channel_sched(const struct ast_channel *chan);
  3821. void ast_channel_sched_set(struct ast_channel *chan, struct ast_sched_context *value);
  3822. struct ast_timer *ast_channel_timer(const struct ast_channel *chan);
  3823. void ast_channel_timer_set(struct ast_channel *chan, struct ast_timer *value);
  3824. struct ast_tone_zone *ast_channel_zone(const struct ast_channel *chan);
  3825. void ast_channel_zone_set(struct ast_channel *chan, struct ast_tone_zone *value);
  3826. struct ast_trans_pvt *ast_channel_readtrans(const struct ast_channel *chan);
  3827. void ast_channel_readtrans_set(struct ast_channel *chan, struct ast_trans_pvt *value);
  3828. struct ast_trans_pvt *ast_channel_writetrans(const struct ast_channel *chan);
  3829. void ast_channel_writetrans_set(struct ast_channel *chan, struct ast_trans_pvt *value);
  3830. const struct ast_channel_tech *ast_channel_tech(const struct ast_channel *chan);
  3831. void ast_channel_tech_set(struct ast_channel *chan, const struct ast_channel_tech *value);
  3832. enum ast_channel_adsicpe ast_channel_adsicpe(const struct ast_channel *chan);
  3833. void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value);
  3834. enum ast_channel_state ast_channel_state(const struct ast_channel *chan);
  3835. struct ast_callid *ast_channel_callid(const struct ast_channel *chan);
  3836. /*!
  3837. * \pre chan is locked
  3838. */
  3839. void ast_channel_callid_set(struct ast_channel *chan, struct ast_callid *value);
  3840. /* XXX Internal use only, make sure to move later */
  3841. void ast_channel_state_set(struct ast_channel *chan, enum ast_channel_state);
  3842. void ast_channel_softhangup_internal_flag_set(struct ast_channel *chan, int value);
  3843. void ast_channel_softhangup_internal_flag_add(struct ast_channel *chan, int value);
  3844. void ast_channel_softhangup_internal_flag_clear(struct ast_channel *chan, int value);
  3845. void ast_channel_callid_cleanup(struct ast_channel *chan);
  3846. int ast_channel_softhangup_internal_flag(struct ast_channel *chan);
  3847. /* Format getters */
  3848. struct ast_format *ast_channel_oldwriteformat(struct ast_channel *chan);
  3849. struct ast_format *ast_channel_rawreadformat(struct ast_channel *chan);
  3850. struct ast_format *ast_channel_rawwriteformat(struct ast_channel *chan);
  3851. struct ast_format *ast_channel_readformat(struct ast_channel *chan);
  3852. struct ast_format *ast_channel_writeformat(struct ast_channel *chan);
  3853. /* Format setters - all of these functions will increment the reference count of the format passed in */
  3854. void ast_channel_set_oldwriteformat(struct ast_channel *chan, struct ast_format *format);
  3855. void ast_channel_set_rawreadformat(struct ast_channel *chan, struct ast_format *format);
  3856. void ast_channel_set_rawwriteformat(struct ast_channel *chan, struct ast_format *format);
  3857. void ast_channel_set_readformat(struct ast_channel *chan, struct ast_format *format);
  3858. void ast_channel_set_writeformat(struct ast_channel *chan, struct ast_format *format);
  3859. /* Other struct getters */
  3860. struct ast_frame *ast_channel_dtmff(struct ast_channel *chan);
  3861. struct ast_jb *ast_channel_jb(struct ast_channel *chan);
  3862. struct ast_party_caller *ast_channel_caller(struct ast_channel *chan);
  3863. struct ast_party_connected_line *ast_channel_connected(struct ast_channel *chan);
  3864. struct ast_party_connected_line *ast_channel_connected_indicated(struct ast_channel *chan);
  3865. struct ast_party_id ast_channel_connected_effective_id(struct ast_channel *chan);
  3866. struct ast_party_dialed *ast_channel_dialed(struct ast_channel *chan);
  3867. struct ast_party_redirecting *ast_channel_redirecting(struct ast_channel *chan);
  3868. struct ast_party_id ast_channel_redirecting_effective_orig(struct ast_channel *chan);
  3869. struct ast_party_id ast_channel_redirecting_effective_from(struct ast_channel *chan);
  3870. struct ast_party_id ast_channel_redirecting_effective_to(struct ast_channel *chan);
  3871. struct timeval *ast_channel_dtmf_tv(struct ast_channel *chan);
  3872. struct timeval *ast_channel_whentohangup(struct ast_channel *chan);
  3873. struct varshead *ast_channel_varshead(struct ast_channel *chan);
  3874. void ast_channel_dtmff_set(struct ast_channel *chan, struct ast_frame *value);
  3875. void ast_channel_jb_set(struct ast_channel *chan, struct ast_jb *value);
  3876. void ast_channel_caller_set(struct ast_channel *chan, struct ast_party_caller *value);
  3877. void ast_channel_connected_set(struct ast_channel *chan, struct ast_party_connected_line *value);
  3878. void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value);
  3879. void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value);
  3880. void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value);
  3881. /*!
  3882. * \pre chan is locked
  3883. */
  3884. void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value);
  3885. void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value);
  3886. struct timeval ast_channel_creationtime(struct ast_channel *chan);
  3887. void ast_channel_creationtime_set(struct ast_channel *chan, struct timeval *value);
  3888. struct timeval ast_channel_answertime(struct ast_channel *chan);
  3889. void ast_channel_answertime_set(struct ast_channel *chan, struct timeval *value);
  3890. /* List getters */
  3891. struct ast_hangup_handler_list *ast_channel_hangup_handlers(struct ast_channel *chan);
  3892. struct ast_datastore_list *ast_channel_datastores(struct ast_channel *chan);
  3893. struct ast_autochan_list *ast_channel_autochans(struct ast_channel *chan);
  3894. struct ast_readq_list *ast_channel_readq(struct ast_channel *chan);
  3895. /* Typedef accessors */
  3896. ast_group_t ast_channel_callgroup(const struct ast_channel *chan);
  3897. /*!
  3898. * \pre chan is locked
  3899. */
  3900. void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value);
  3901. ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan);
  3902. /*!
  3903. * \pre chan is locked
  3904. */
  3905. void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value);
  3906. struct ast_namedgroups *ast_channel_named_callgroups(const struct ast_channel *chan);
  3907. void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value);
  3908. struct ast_namedgroups *ast_channel_named_pickupgroups(const struct ast_channel *chan);
  3909. void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_namedgroups *value);
  3910. /* Alertpipe accessors--the "internal" functions for channel.c use only */
  3911. int ast_channel_alert_write(struct ast_channel *chan);
  3912. int ast_channel_alert_writable(struct ast_channel *chan);
  3913. ast_alert_status_t ast_channel_internal_alert_flush(struct ast_channel *chan);
  3914. ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan);
  3915. int ast_channel_internal_alert_readable(struct ast_channel *chan);
  3916. void ast_channel_internal_alertpipe_clear(struct ast_channel *chan);
  3917. void ast_channel_internal_alertpipe_close(struct ast_channel *chan);
  3918. int ast_channel_internal_alert_readfd(struct ast_channel *chan);
  3919. int ast_channel_internal_alertpipe_init(struct ast_channel *chan);
  3920. /*! \brief Swap the interal alertpipe between two channels
  3921. * \note Handle all of the necessary locking before calling this
  3922. */
  3923. void ast_channel_internal_alertpipe_swap(struct ast_channel *chan1, struct ast_channel *chan2);
  3924. /* file descriptor array accessors */
  3925. void ast_channel_internal_fd_clear(struct ast_channel *chan, int which);
  3926. void ast_channel_internal_fd_clear_all(struct ast_channel *chan);
  3927. void ast_channel_internal_fd_set(struct ast_channel *chan, int which, int value);
  3928. int ast_channel_fd(const struct ast_channel *chan, int which);
  3929. int ast_channel_fd_isset(const struct ast_channel *chan, int which);
  3930. /* epoll data internal accessors */
  3931. #ifdef HAVE_EPOLL
  3932. struct ast_epoll_data *ast_channel_internal_epfd_data(const struct ast_channel *chan, int which);
  3933. void ast_channel_internal_epfd_data_set(struct ast_channel *chan, int which , struct ast_epoll_data *value);
  3934. #endif
  3935. pthread_t ast_channel_blocker(const struct ast_channel *chan);
  3936. void ast_channel_blocker_set(struct ast_channel *chan, pthread_t value);
  3937. int ast_channel_blocker_tid(const struct ast_channel *chan);
  3938. void ast_channel_blocker_tid_set(struct ast_channel *chan, int tid);
  3939. ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan);
  3940. void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value);
  3941. struct ast_bridge *ast_channel_internal_bridge(const struct ast_channel *chan);
  3942. /*!
  3943. * \pre chan is locked
  3944. */
  3945. void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value);
  3946. struct ast_bridge_channel *ast_channel_internal_bridge_channel(const struct ast_channel *chan);
  3947. void ast_channel_internal_bridge_channel_set(struct ast_channel *chan, struct ast_bridge_channel *value);
  3948. struct ast_channel *ast_channel_internal_bridged_channel(const struct ast_channel *chan);
  3949. void ast_channel_internal_bridged_channel_set(struct ast_channel *chan, struct ast_channel *value);
  3950. /*!
  3951. * \since 11
  3952. * \brief Retrieve a comma-separated list of channels for which dialed cause information is available
  3953. *
  3954. * \details
  3955. * This function makes use of datastore operations on the channel, so
  3956. * it is important to lock the channel before calling this function.
  3957. *
  3958. * \param chan The channel from which to retrieve information
  3959. * \retval NULL on allocation failure
  3960. * \retval Pointer to an ast_str object containing the desired information which must be freed
  3961. */
  3962. struct ast_str *ast_channel_dialed_causes_channels(const struct ast_channel *chan);
  3963. /*!
  3964. * \since 11
  3965. * \brief Retrieve a ref-counted cause code information structure
  3966. *
  3967. * \details
  3968. * This function makes use of datastore operations on the channel, so
  3969. * it is important to lock the channel before calling this function.
  3970. * This function increases the ref count of the returned object, so the
  3971. * calling function must decrease the reference count when it is finished
  3972. * with the object.
  3973. *
  3974. * \param chan The channel from which to retrieve information
  3975. * \param chan_name The name of the channel about which to retrieve information
  3976. * \retval NULL on search failure
  3977. * \retval Pointer to a ref-counted ast_control_pvt_cause_code object containing the desired information
  3978. */
  3979. struct ast_control_pvt_cause_code *ast_channel_dialed_causes_find(const struct ast_channel *chan, const char *chan_name);
  3980. /*!
  3981. * \since 11
  3982. * \brief Add cause code information to the channel
  3983. *
  3984. * \details
  3985. * This function makes use of datastore operations on the channel, so
  3986. * it is important to lock the channel before calling this function.
  3987. * The passed in data is copied and so is still owned by the caller.
  3988. *
  3989. * \param chan The channel on which to add information
  3990. * \param cause_code The cause information to be added to the channel
  3991. * \param datalen The total length of the structure since its length is variable
  3992. * \retval 0 on success
  3993. * \retval -1 on error
  3994. */
  3995. int ast_channel_dialed_causes_add(const struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen);
  3996. /*!
  3997. * \since 11
  3998. * \brief Clear all cause information from the channel
  3999. *
  4000. * \details
  4001. * This function makes use of datastore operations on the channel, so
  4002. * it is important to lock the channel before calling this function.
  4003. *
  4004. * \param chan The channel from which to clear information
  4005. */
  4006. void ast_channel_dialed_causes_clear(const struct ast_channel *chan);
  4007. struct ast_flags *ast_channel_flags(struct ast_channel *chan);
  4008. /*!
  4009. * \since 13.17.0
  4010. * \brief Set a flag on a channel
  4011. *
  4012. * \param chan The channel to set the flag on
  4013. * \param flag The flag to set
  4014. *
  4015. * \note This will lock the channel internally. If the channel is already
  4016. * locked it is still safe to call.
  4017. */
  4018. void ast_channel_set_flag(struct ast_channel *chan, unsigned int flag);
  4019. /*!
  4020. * \since 13.17.0
  4021. * \param Clear a flag on a channel
  4022. *
  4023. * \param chan The channel to clear the flag from
  4024. * \param flag The flag to clear
  4025. *
  4026. * \note This will lock the channel internally. If the channel is already
  4027. * locked it is still safe to call.
  4028. */
  4029. void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag);
  4030. /*!
  4031. * \since 12.4.0
  4032. * \brief Return whether or not any manager variables have been set
  4033. *
  4034. * \retval 0 if no manager variables are expected
  4035. * \retval 1 if manager variables are expected
  4036. */
  4037. int ast_channel_has_manager_vars(void);
  4038. /*!
  4039. * \since 12
  4040. * \brief Sets the variables to be stored in the \a manager_vars field of all
  4041. * snapshots.
  4042. * \param varc Number of variable names.
  4043. * \param vars Array of variable names.
  4044. */
  4045. void ast_channel_set_manager_vars(size_t varc, char **vars);
  4046. /*!
  4047. * \since 12
  4048. * \brief Gets the variables for a given channel, as specified by ast_channel_set_manager_vars().
  4049. *
  4050. * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
  4051. *
  4052. * \param chan Channel to get variables for.
  4053. * \return List of channel variables.
  4054. * \return \c NULL on error
  4055. */
  4056. struct varshead *ast_channel_get_manager_vars(struct ast_channel *chan);
  4057. /*!
  4058. * \since 12
  4059. * \brief Gets the variables for a given channel, as set using pbx_builtin_setvar_helper().
  4060. *
  4061. * The returned variable list is an AO2 object, so ao2_cleanup() to free it.
  4062. *
  4063. * \param chan Channel to get variables for
  4064. * \return List of channel variables.
  4065. * \return \c NULL on error
  4066. */
  4067. struct varshead *ast_channel_get_vars(struct ast_channel *chan);
  4068. /*!
  4069. * \since 12
  4070. * \brief A topic which publishes the events for a particular channel.
  4071. *
  4072. * If the given \a chan is \c NULL, ast_channel_topic_all() is returned.
  4073. *
  4074. * \param chan Channel, or \c NULL.
  4075. *
  4076. * \retval Topic for channel's events.
  4077. * \retval ast_channel_topic_all() if \a chan is \c NULL.
  4078. */
  4079. struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
  4080. /*!
  4081. * \since 12
  4082. * \brief A topic which publishes the events for a particular channel.
  4083. *
  4084. * \ref ast_channel_snapshot messages are replaced with \ref stasis_cache_update
  4085. *
  4086. * If the given \a chan is \c NULL, ast_channel_topic_all_cached() is returned.
  4087. *
  4088. * \param chan Channel, or \c NULL.
  4089. *
  4090. * \retval Topic for channel's events.
  4091. * \retval ast_channel_topic_all() if \a chan is \c NULL.
  4092. */
  4093. struct stasis_topic *ast_channel_topic_cached(struct ast_channel *chan);
  4094. /*!
  4095. * \brief Get the bridge associated with a channel
  4096. * \since 12.0.0
  4097. *
  4098. * \param chan The channel whose bridge we want
  4099. *
  4100. * \details
  4101. * The bridge returned has its reference count incremented. Use
  4102. * ao2_cleanup() or ao2_ref() in order to decrement the
  4103. * reference count when you are finished with the bridge.
  4104. *
  4105. * \note This function expects the channel to be locked prior to
  4106. * being called and will not grab the channel lock.
  4107. *
  4108. * \retval NULL No bridge present on the channel
  4109. * \retval non-NULL The bridge the channel is in
  4110. */
  4111. struct ast_bridge *ast_channel_get_bridge(const struct ast_channel *chan);
  4112. /*!
  4113. * \brief Determine if a channel is in a bridge
  4114. * \since 12.0.0
  4115. *
  4116. * \param chan The channel to test
  4117. *
  4118. * \note This function expects the channel to be locked prior to
  4119. * being called and will not grab the channel lock.
  4120. *
  4121. * \retval 0 The channel is not bridged
  4122. * \retval non-zero The channel is bridged
  4123. */
  4124. int ast_channel_is_bridged(const struct ast_channel *chan);
  4125. /*!
  4126. * \brief Determine if a channel is leaving a bridge, but \em not hung up
  4127. * \since 12.4.0
  4128. *
  4129. * \param chan The channel to test
  4130. *
  4131. * \note If a channel is hung up, it is implicitly leaving any bridge it
  4132. * may be in. This function is used to test if a channel is leaving a bridge
  4133. * but may survive the experience, if it has a place to go to (dialplan or
  4134. * otherwise)
  4135. *
  4136. * \retval 0 The channel is not leaving the bridge or is hung up
  4137. * \retval non-zero The channel is leaving the bridge
  4138. */
  4139. int ast_channel_is_leaving_bridge(struct ast_channel *chan);
  4140. /*!
  4141. * \brief Get the channel's bridge peer only if the bridge is two-party.
  4142. * \since 12.0.0
  4143. *
  4144. * \param chan Channel desiring the bridge peer channel.
  4145. *
  4146. * \note The returned peer channel is the current peer in the
  4147. * bridge when called.
  4148. *
  4149. * \note Absolutely _NO_ channel locks should be held when calling this function.
  4150. *
  4151. * \retval NULL Channel not in a bridge or the bridge is not two-party.
  4152. * \retval non-NULL Reffed peer channel at time of calling.
  4153. */
  4154. struct ast_channel *ast_channel_bridge_peer(struct ast_channel *chan);
  4155. /*!
  4156. * \brief Get a reference to the channel's bridge pointer.
  4157. * \since 12.0.0
  4158. *
  4159. * \param chan The channel whose bridge channel is desired
  4160. *
  4161. * \note This increases the reference count of the bridge_channel.
  4162. * Use ao2_ref() or ao2_cleanup() to decrement the refcount when
  4163. * you are finished with it.
  4164. *
  4165. * \note It is expected that the channel is locked prior to
  4166. * placing this call.
  4167. *
  4168. * \retval NULL The channel has no bridge_channel
  4169. * \retval non-NULL A reference to the bridge_channel
  4170. */
  4171. struct ast_bridge_channel *ast_channel_get_bridge_channel(struct ast_channel *chan);
  4172. /*!
  4173. * \since 12
  4174. * \brief Gain control of a channel in the system
  4175. *
  4176. * The intention of this function is to take a channel that currently
  4177. * is running in one thread and gain control of it in the current thread.
  4178. * This can be used to redirect a channel to a different place in the dialplan,
  4179. * for instance.
  4180. *
  4181. * \note This function is NOT intended to be used on bridged channels. If you
  4182. * need to control a bridged channel, you can set a callback to be called
  4183. * once the channel exits the bridge, and run your controlling logic in that
  4184. * callback
  4185. *
  4186. * XXX Put name of callback-setting function in above paragraph once it is written
  4187. *
  4188. * \note When this function returns successfully, the yankee channel is in a state where
  4189. * it cannot be used any further. Always use the returned channel instead.
  4190. *
  4191. * \note absolutely _NO_ channel locks should be held before calling this function.
  4192. *
  4193. * \note The dialplan location on the returned channel is where the channel
  4194. * should be started in the dialplan if it is returned to it.
  4195. *
  4196. * \param yankee The channel to gain control of
  4197. * \retval NULL Could not gain control of the channel
  4198. * \retval non-NULL The channel
  4199. */
  4200. struct ast_channel *ast_channel_yank(struct ast_channel *yankee);
  4201. /*!
  4202. * \since 12
  4203. * \brief Move a channel from its current location to a new location
  4204. *
  4205. * The intention of this function is to have the destination channel
  4206. * take on the identity of the source channel.
  4207. *
  4208. * \note This function is NOT intended to be used on bridged channels. If you
  4209. * wish to move an unbridged channel into the place of a bridged channel, then
  4210. * use ast_bridge_join() or ast_bridge_impart(). If you wish to move a bridged
  4211. * channel into the place of another bridged channel, then use ast_bridge_move().
  4212. *
  4213. * \note When this function returns succesfully, the source channel is in a
  4214. * state where its continued use is unreliable.
  4215. *
  4216. * \note absolutely _NO_ channel locks should be held before calling this function.
  4217. *
  4218. * \param dest The place to move the source channel
  4219. * \param source The channel to move
  4220. * \retval 0 Success
  4221. * \retval non-zero Failure
  4222. */
  4223. int ast_channel_move(struct ast_channel *dest, struct ast_channel *source);
  4224. /*!
  4225. * \since 12
  4226. * \brief Forward channel stasis messages to the given endpoint
  4227. *
  4228. * \param chan The channel to forward from
  4229. * \param endpoint The endpoint to forward to
  4230. *
  4231. * \retval 0 Success
  4232. * \retval non-zero Failure
  4233. */
  4234. int ast_channel_forward_endpoint(struct ast_channel *chan, struct ast_endpoint *endpoint);
  4235. /*!
  4236. * \brief Return the oldest linkedid between two channels.
  4237. *
  4238. * A channel linkedid is derived from the channel uniqueid which is formed like this:
  4239. * [systemname-]ctime.seq
  4240. *
  4241. * The systemname, and the dash are optional, followed by the epoch time followed by an
  4242. * integer sequence. Note that this is not a decimal number, since 1.2 is less than 1.11
  4243. * in uniqueid land.
  4244. *
  4245. * To compare two uniqueids, we parse out the integer values of the time and the sequence
  4246. * numbers and compare them, with time trumping sequence.
  4247. *
  4248. * \param a The linkedid value of the first channel to compare
  4249. * \param b The linkedid value of the second channel to compare
  4250. *
  4251. * \retval NULL on failure
  4252. * \retval The oldest linkedid value
  4253. * \since 12.0.0
  4254. */
  4255. const char *ast_channel_oldest_linkedid(const char *a, const char *b);
  4256. /*!
  4257. * \brief Check if the channel has active audiohooks, active framehooks, or a monitor.
  4258. * \since 12.0.0
  4259. *
  4260. * \param chan The channel to check.
  4261. *
  4262. * \retval non-zero if channel has active audiohooks, framehooks, or monitor.
  4263. */
  4264. int ast_channel_has_audio_frame_or_monitor(struct ast_channel *chan);
  4265. /*!
  4266. * \brief Check if the channel has any active hooks that require audio.
  4267. * \since 12.3.0
  4268. *
  4269. * \param chan The channel to check.
  4270. *
  4271. * \retval non-zero if channel has active audiohooks, audio framehooks, or monitor.
  4272. */
  4273. int ast_channel_has_hook_requiring_audio(struct ast_channel *chan);
  4274. /*!
  4275. * \brief Removes the trailing identifiers from a channel name string
  4276. * \since 12.0.0
  4277. *
  4278. * \param channel_name string that you wish to turn into a dial string.
  4279. * This string will be edited in place.
  4280. */
  4281. void ast_channel_name_to_dial_string(char *channel_name);
  4282. #define AST_MUTE_DIRECTION_READ (1 << 0)
  4283. #define AST_MUTE_DIRECTION_WRITE (1 << 1)
  4284. /*!
  4285. * \brief Suppress passing of a frame type on a channel
  4286. *
  4287. * \note The channel should be locked before calling this function.
  4288. *
  4289. * \param chan The channel to suppress
  4290. * \param direction The direction in which to suppress
  4291. * \param frametype The type of frame (AST_FRAME_VOICE, etc) to suppress
  4292. *
  4293. * \retval 0 Success
  4294. * \retval -1 Failure
  4295. */
  4296. int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype);
  4297. /*!
  4298. * \brief Stop suppressing of a frame type on a channel
  4299. *
  4300. * \note The channel should be locked before calling this function.
  4301. *
  4302. * \param chan The channel to stop suppressing
  4303. * \param direction The direction in which to stop suppressing
  4304. * \param frametype The type of frame (AST_FRAME_VOICE, etc) to stop suppressing
  4305. *
  4306. * \retval 0 Success
  4307. * \retval -1 Failure
  4308. */
  4309. int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype);
  4310. /*!
  4311. * \brief Simulate a DTMF end on a broken bridge channel.
  4312. *
  4313. * \param chan Channel sending DTMF that has not ended.
  4314. * \param digit DTMF digit to stop.
  4315. * \param start DTMF digit start time.
  4316. * \param why Reason bridge broken.
  4317. *
  4318. * \return Nothing
  4319. */
  4320. void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why);
  4321. struct ast_bridge_features;
  4322. /*!
  4323. * \brief Gets the channel-attached features a channel has access to upon being bridged.
  4324. *
  4325. * \note The channel must be locked when calling this function.
  4326. *
  4327. * \param chan Which channel to get features for
  4328. *
  4329. * \retval non-NULL The features currently set for this channel
  4330. * \retval NULL if the features have not been set
  4331. */
  4332. struct ast_bridge_features *ast_channel_feature_hooks_get(struct ast_channel *chan);
  4333. /*!
  4334. * \brief Appends to the channel-attached features a channel has access to upon being bridged.
  4335. *
  4336. * \note The channel must be locked when calling this function.
  4337. *
  4338. * \param chan Which channel to set features for
  4339. * \param features The feature set to append to the channel's features
  4340. *
  4341. * \retval 0 on success
  4342. * \retval -1 on failure
  4343. */
  4344. int ast_channel_feature_hooks_append(struct ast_channel *chan, struct ast_bridge_features *features);
  4345. /*!
  4346. * \brief Sets the channel-attached features a channel has access to upon being bridged.
  4347. *
  4348. * \note The channel must be locked when calling this function.
  4349. *
  4350. * \param chan Which channel to set features for
  4351. * \param features The feature set with which to replace the channel's features
  4352. *
  4353. * \retval 0 on success
  4354. * \retval -1 on failure
  4355. */
  4356. int ast_channel_feature_hooks_replace(struct ast_channel *chan, struct ast_bridge_features *features);
  4357. enum ast_channel_error {
  4358. /* Unable to determine what error occurred. */
  4359. AST_CHANNEL_ERROR_UNKNOWN,
  4360. /* Channel with this ID already exists */
  4361. AST_CHANNEL_ERROR_ID_EXISTS,
  4362. };
  4363. /*!
  4364. * \brief Get error code for latest channel operation.
  4365. */
  4366. enum ast_channel_error ast_channel_errno(void);
  4367. /*!
  4368. * \brief Am I currently running an intercept dialplan routine.
  4369. * \since 13.14.0
  4370. *
  4371. * \details
  4372. * A dialplan intercept routine is equivalent to an interrupt
  4373. * routine. As such, the routine must be done quickly and you
  4374. * do not have access to the media stream. These restrictions
  4375. * are necessary because the media stream is the responsibility
  4376. * of some other code and interfering with or delaying that
  4377. * processing is bad.
  4378. *
  4379. * \retval 0 Not in an intercept routine.
  4380. * \retval 1 In an intercept routine.
  4381. */
  4382. int ast_channel_get_intercept_mode(void);
  4383. #endif /* _ASTERISK_CHANNEL_H */