12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466 |
- /*
- * Copyright (C) 2004-2005 by Objective Systems, Inc.
- *
- * This software is furnished under an open source license and may be
- * used and copied only in accordance with the terms of this license.
- * The text of the license may generally be found in the root
- * directory of this installation in the COPYING file. It
- * can also be viewed online at the following URL:
- *
- * http://www.obj-sys.com/open/license.html
- *
- * Any redistributions of this file including modified versions must
- * maintain this copyright notice.
- *
- *****************************************************************************/
- /* Reworked version I, Nov-2009, by Alexandr Anikin, may@telecom-service.ru */
- /*** MODULEINFO
- <defaultenabled>no</defaultenabled>
- <support_level>extended</support_level>
- ***/
- #include "chan_ooh323.h"
- #include <math.h>
- #define FORMAT_STRING_SIZE 512
- /* Defaults */
- #define DEFAULT_CONTEXT "default"
- #define DEFAULT_H323ID "Asterisk PBX"
- #define DEFAULT_LOGFILE "/var/log/asterisk/h323_log"
- #define DEFAULT_H323ACCNT "ast_h323"
- /* Flags */
- #define H323_SILENCESUPPRESSION (1<<0)
- #define H323_GKROUTED (1<<1)
- #define H323_TUNNELING (1<<2)
- #define H323_FASTSTART (1<<3)
- #define H323_OUTGOING (1<<4)
- #define H323_ALREADYGONE (1<<5)
- #define H323_NEEDDESTROY (1<<6)
- #define H323_DISABLEGK (1<<7)
- #define H323_NEEDSTART (1<<8)
- #define MAXT30 240
- #define T38TOAUDIOTIMEOUT 30
- #define T38_DISABLED 0
- #define T38_ENABLED 1
- #define T38_FAXGW 1
- /* Channel description */
- static const char type[] = "OOH323";
- static const char tdesc[] = "Objective Systems H323 Channel Driver";
- static const char config[] = "ooh323.conf";
- struct ast_module *myself;
- static struct ast_jb_conf default_jbconf =
- {
- .flags = 0,
- .max_size = -1,
- .resync_threshold = -1,
- .impl = ""
- };
- static struct ast_jb_conf global_jbconf;
- /* Channel Definition */
- static struct ast_channel *ooh323_request(const char *type, format_t format,
- const struct ast_channel *requestor, void *data, int *cause);
- static int ooh323_digit_begin(struct ast_channel *ast, char digit);
- static int ooh323_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
- static int ooh323_call(struct ast_channel *ast, char *dest, int timeout);
- static int ooh323_hangup(struct ast_channel *ast);
- static int ooh323_answer(struct ast_channel *ast);
- static struct ast_frame *ooh323_read(struct ast_channel *ast);
- static int ooh323_write(struct ast_channel *ast, struct ast_frame *f);
- static int ooh323_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
- static int ooh323_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
- static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
- static enum ast_rtp_glue_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
- static enum ast_rtp_glue_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
- static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp,
- struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active);
- static struct ast_udptl *ooh323_get_udptl_peer(struct ast_channel *chan);
- static int ooh323_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl);
- static void print_codec_to_cli(int fd, struct ast_codec_pref *pref);
- struct ooh323_peer *find_friend(const char *name, int port);
- static const struct ast_channel_tech ooh323_tech = {
- .type = type,
- .description = tdesc,
- .capabilities = -1,
- .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
- .requester = ooh323_request,
- .send_digit_begin = ooh323_digit_begin,
- .send_digit_end = ooh323_digit_end,
- .call = ooh323_call,
- .hangup = ooh323_hangup,
- .answer = ooh323_answer,
- .read = ooh323_read,
- .write = ooh323_write,
- .exception = ooh323_read,
- .indicate = ooh323_indicate,
- .fixup = ooh323_fixup,
- .send_html = 0,
- .queryoption = ooh323_queryoption,
- .bridge = ast_rtp_instance_bridge, /* XXX chan unlocked ? */
- .early_bridge = ast_rtp_instance_early_bridge,
- };
- static struct ast_rtp_glue ooh323_rtp = {
- .type = type,
- .get_rtp_info = ooh323_get_rtp_peer,
- .get_vrtp_info = ooh323_get_vrtp_peer,
- .update_peer = ooh323_set_rtp_peer,
- };
- static struct ast_udptl_protocol ooh323_udptl = {
- type: "H323",
- get_udptl_info: ooh323_get_udptl_peer,
- set_udptl_peer: ooh323_set_udptl_peer,
- };
- struct ooh323_user;
- /* H.323 channel private structure */
- static struct ooh323_pvt {
- ast_mutex_t lock; /* Channel private lock */
- struct ast_rtp_instance *rtp;
- struct ast_rtp_instance *vrtp; /* Placeholder for now */
- int t38support; /* T.38 mode - disable, transparent, faxgw */
- int rtptimeout;
- struct ast_udptl *udptl;
- int faxmode;
- int t38_tx_enable;
- int t38_init;
- struct sockaddr_in udptlredirip;
- time_t lastTxT38;
- int chmodepend;
- struct ast_channel *owner; /* Master Channel */
- union {
- char *user; /* cooperating user/peer */
- char *peer;
- } neighbor;
- time_t lastrtptx;
- time_t lastrtprx;
- unsigned int flags;
- unsigned int call_reference;
- char *callToken;
- char *username;
- char *host;
- char *callerid_name;
- char *callerid_num;
- char caller_h323id[AST_MAX_EXTENSION];
- char caller_dialedDigits[AST_MAX_EXTENSION];
- char caller_email[AST_MAX_EXTENSION];
- char caller_url[256];
- char callee_h323id[AST_MAX_EXTENSION];
- char callee_dialedDigits[AST_MAX_EXTENSION];
- char callee_email[AST_MAX_EXTENSION];
- char callee_url[AST_MAX_EXTENSION];
-
- int port;
- format_t readformat; /* negotiated read format */
- format_t writeformat; /* negotiated write format */
- format_t capability;
- struct ast_codec_pref prefs;
- int dtmfmode;
- int dtmfcodec;
- char exten[AST_MAX_EXTENSION]; /* Requested extension */
- char context[AST_MAX_EXTENSION]; /* Context where to start */
- char accountcode[256]; /* Account code */
- int nat;
- int amaflags;
- int progsent; /* progress is sent */
- int alertsent; /* alerting is sent */
- int g729onlyA; /* G.729 only A */
- struct ast_dsp *vad;
- struct OOH323Regex *rtpmask; /* rtp ip regexp */
- char rtpmaskstr[120];
- int rtdrcount, rtdrinterval; /* roundtripdelayreq */
- int faststart, h245tunneling; /* faststart & h245 tunneling */
- struct ooh323_pvt *next; /* Next entity */
- } *iflist = NULL;
- /* Protect the channel/interface list (ooh323_pvt) */
- AST_MUTEX_DEFINE_STATIC(iflock);
- /* Profile of H.323 user registered with PBX*/
- struct ooh323_user{
- ast_mutex_t lock;
- char name[256];
- char context[AST_MAX_EXTENSION];
- int incominglimit;
- unsigned inUse;
- char accountcode[20];
- int amaflags;
- format_t capability;
- struct ast_codec_pref prefs;
- int dtmfmode;
- int dtmfcodec;
- int t38support;
- int rtptimeout;
- int mUseIP; /* Use IP address or H323-ID to search user */
- char mIP[20];
- struct OOH323Regex *rtpmask;
- char rtpmaskstr[120];
- int rtdrcount, rtdrinterval;
- int faststart, h245tunneling;
- int g729onlyA;
- struct ooh323_user *next;
- };
- /* Profile of valid asterisk peers */
- struct ooh323_peer{
- ast_mutex_t lock;
- char name[256];
- unsigned outgoinglimit;
- unsigned outUse;
- format_t capability;
- struct ast_codec_pref prefs;
- char accountcode[20];
- int amaflags;
- int dtmfmode;
- int dtmfcodec;
- int t38support;
- int mFriend; /* indicates defined as friend */
- char ip[20];
- int port;
- char *h323id; /* H323-ID alias, which asterisk will register with gk to reach this peer*/
- char *email; /* Email alias, which asterisk will register with gk to reach this peer*/
- char *url; /* url alias, which asterisk will register with gk to reach this peer*/
- char *e164; /* e164 alias, which asterisk will register with gk to reach this peer*/
- int rtptimeout;
- struct OOH323Regex *rtpmask;
- char rtpmaskstr[120];
- int rtdrcount,rtdrinterval;
- int faststart, h245tunneling;
- int g729onlyA;
- struct ooh323_peer *next;
- };
- /* List of H.323 users known to PBX */
- static struct ast_user_list {
- struct ooh323_user *users;
- ast_mutex_t lock;
- } userl;
- static struct ast_peer_list {
- struct ooh323_peer *peers;
- ast_mutex_t lock;
- } peerl;
- /* Mutex to protect H.323 reload process */
- static int h323_reloading = 0;
- AST_MUTEX_DEFINE_STATIC(h323_reload_lock);
- /* Mutex to protect usage counter */
- static int usecnt = 0;
- AST_MUTEX_DEFINE_STATIC(usecnt_lock);
- AST_MUTEX_DEFINE_STATIC(ooh323c_cmd_lock);
- static long callnumber = 0;
- AST_MUTEX_DEFINE_STATIC(ooh323c_cn_lock);
- /* stack callbacks */
- int onAlerting(ooCallData *call);
- int onProgress(ooCallData *call);
- int onNewCallCreated(ooCallData *call);
- int onOutgoingCall(ooCallData *call);
- int onCallEstablished(ooCallData *call);
- int onCallCleared(ooCallData *call);
- void onModeChanged(ooCallData *call, int t38mode);
- static char gLogFile[256] = DEFAULT_LOGFILE;
- static int gPort = 1720;
- static char gIP[20];
- static char gCallerID[AST_MAX_EXTENSION] = "";
- static struct ooAliases *gAliasList;
- static format_t gCapability = AST_FORMAT_ULAW;
- static struct ast_codec_pref gPrefs;
- static int gDTMFMode = H323_DTMF_RFC2833;
- static int gDTMFCodec = 101;
- static int gT38Support = T38_FAXGW;
- static char gGatekeeper[100];
- static enum RasGatekeeperMode gRasGkMode = RasNoGatekeeper;
- static int gIsGateway = 0;
- static int gFastStart = 1;
- static int gTunneling = 1;
- static int gBeMaster = 0;
- static int gMediaWaitForConnect = 0;
- static int gTOS = 0;
- static int gRTPTimeout = 60;
- static int g729onlyA = 0;
- static char gAccountcode[80] = DEFAULT_H323ACCNT;
- static int gAMAFLAGS;
- static char gContext[AST_MAX_EXTENSION] = DEFAULT_CONTEXT;
- static int gIncomingLimit = 1024;
- static int gOutgoingLimit = 1024;
- OOBOOL gH323Debug = FALSE;
- static int gTRCLVL = OOTRCLVLERR;
- static int gRTDRCount = 0, gRTDRInterval = 0;
- static int t35countrycode = 0;
- static int t35extensions = 0;
- static int manufacturer = 0;
- static char vendor[AST_MAX_EXTENSION] = "";
- static char version[AST_MAX_EXTENSION] = "";
- static struct ooh323_config
- {
- int mTCPPortStart;
- int mTCPPortEnd;
- } ooconfig;
- /** Asterisk RTP stuff*/
- static struct sched_context *sched;
- static struct io_context *io;
- /* Protect the monitoring thread, so only one process can kill or start it,
- and not when it's doing something critical. */
- AST_MUTEX_DEFINE_STATIC(monlock);
- /* This is the thread for the monitor which checks for input on the channels
- which are not currently in use. */
- static pthread_t monitor_thread = AST_PTHREADT_NULL;
- static struct ast_channel *ooh323_new(struct ooh323_pvt *i, int state,
- const char *host, int capability, const char *linkedid)
- {
- struct ast_channel *ch = NULL;
- int fmt = 0;
- if (gH323Debug)
- ast_verbose("--- ooh323_new - %s, %d\n", host, capability);
- /* Don't hold a h323 pvt lock while we allocate a channel */
- ast_mutex_unlock(&i->lock);
- ast_mutex_lock(&ooh323c_cn_lock);
- ch = ast_channel_alloc(1, state, i->callerid_num, i->callerid_name,
- i->accountcode, i->exten, i->context, linkedid, i->amaflags,
- "OOH323/%s-%ld", host, callnumber);
- callnumber++;
- ast_mutex_unlock(&ooh323c_cn_lock);
-
- ast_mutex_lock(&i->lock);
- if (ch) {
- ast_channel_lock(ch);
- ch->tech = &ooh323_tech;
- if (capability)
- fmt = ast_best_codec(capability);
- if (!fmt)
- fmt = ast_codec_pref_index(&i->prefs, 0);
- ch->nativeformats = ch->rawwriteformat = ch->rawreadformat = fmt;
- ast_channel_set_fd(ch, 0, ast_rtp_instance_fd(i->rtp, 0));
- ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(i->rtp, 1));
- ast_channel_set_fd(ch, 5, ast_udptl_fd(i->udptl));
- ast_jb_configure(ch, &global_jbconf);
- if (state == AST_STATE_RING)
- ch->rings = 1;
- ch->adsicpe = AST_ADSI_UNAVAILABLE;
- ast_set_write_format(ch, fmt);
- ast_set_read_format(ch, fmt);
- ch->tech_pvt = i;
- i->owner = ch;
- ast_module_ref(myself);
- /* Allocate dsp for in-band DTMF support */
- if (i->dtmfmode & H323_DTMF_INBAND) {
- i->vad = ast_dsp_new();
- ast_dsp_set_features(i->vad, DSP_FEATURE_DIGIT_DETECT);
- ast_dsp_set_features(i->vad,
- DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_FAX_DETECT);
- ast_dsp_set_faxmode(i->vad,
- DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED);
- if (i->dtmfmode & H323_DTMF_INBANDRELAX)
- ast_dsp_set_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
- }
- ast_mutex_lock(&usecnt_lock);
- usecnt++;
- ast_mutex_unlock(&usecnt_lock);
- /* Notify the module monitors that use count for resource has changed*/
- ast_update_use_count();
- ast_copy_string(ch->context, i->context, sizeof(ch->context));
- ast_copy_string(ch->exten, i->exten, sizeof(ch->exten));
- ch->priority = 1;
- if(!ast_test_flag(i, H323_OUTGOING)) {
-
- if (!ast_strlen_zero(i->caller_h323id)) {
- pbx_builtin_setvar_helper(ch, "_CALLER_H323ID", i->caller_h323id);
- }
- if (!ast_strlen_zero(i->caller_dialedDigits)) {
- pbx_builtin_setvar_helper(ch, "_CALLER_H323DIALEDDIGITS",
- i->caller_dialedDigits);
- }
- if (!ast_strlen_zero(i->caller_email)) {
- pbx_builtin_setvar_helper(ch, "_CALLER_H323EMAIL",
- i->caller_email);
- }
- if (!ast_strlen_zero(i->caller_url)) {
- pbx_builtin_setvar_helper(ch, "_CALLER_H323URL", i->caller_url);
- }
- }
- if (!ast_strlen_zero(i->accountcode))
- ast_string_field_set(ch, accountcode, i->accountcode);
-
- if (i->amaflags)
- ch->amaflags = i->amaflags;
- ast_setstate(ch, state);
- if (state != AST_STATE_DOWN) {
- if (ast_pbx_start(ch)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name);
- ast_channel_unlock(ch);
- ast_hangup(ch);
- ch = NULL;
- }
- }
- if (ch) {
- manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate",
- "Channel: %s\r\nChanneltype: %s\r\n"
- "CallRef: %d\r\n", ch->name, "OOH323", i->call_reference);
- }
- } else
- ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
- if(ch) ast_channel_unlock(ch);
- if (gH323Debug)
- ast_verbose("+++ h323_new\n");
- return ch;
- }
- static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
- {
- struct ooh323_pvt *pvt = NULL;
- struct sockaddr_in ouraddr;
- struct ast_sockaddr tmp;
- struct in_addr ipAddr;
- if (gH323Debug)
- ast_verbose("--- ooh323_alloc\n");
- if (!(pvt = ast_calloc(1, sizeof(*pvt)))) {
- ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
- return NULL;
- }
- ast_mutex_init(&pvt->lock);
- ast_mutex_lock(&pvt->lock);
- if (!inet_aton(gIP, &ipAddr)) {
- ast_log(LOG_ERROR, "Invalid OOH323 driver ip address\n");
- ast_mutex_unlock(&pvt->lock);
- ast_mutex_destroy(&pvt->lock);
- ast_free(pvt);
- return NULL;
- }
- ouraddr.sin_family = AF_INET;
- ouraddr.sin_addr = ipAddr;
- ast_sockaddr_from_sin(&tmp, &ouraddr);
- if (!(pvt->rtp = ast_rtp_instance_new("asterisk", sched, &tmp, NULL))) {
- ast_log(LOG_WARNING, "Unable to create RTP session: %s\n",
- strerror(errno));
- ast_mutex_unlock(&pvt->lock);
- ast_mutex_destroy(&pvt->lock);
- ast_free(pvt);
- return NULL;
- }
-
- ast_rtp_instance_set_qos(pvt->rtp, gTOS, 0, "ooh323-rtp");
- if (!(pvt->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &tmp))) {
- ast_log(LOG_WARNING, "Unable to create UDPTL session: %s\n",
- strerror(errno));
- ast_mutex_unlock(&pvt->lock);
- ast_mutex_destroy(&pvt->lock);
- ast_free(pvt);
- return NULL;
- }
- ast_udptl_set_error_correction_scheme(pvt->udptl, UDPTL_ERROR_CORRECTION_NONE);
- ast_udptl_set_far_max_datagram(pvt->udptl, 144);
- pvt->faxmode = 0;
- pvt->t38support = gT38Support;
- pvt->rtptimeout = gRTPTimeout;
- pvt->rtdrinterval = gRTDRInterval;
- pvt->rtdrcount = gRTDRCount;
- pvt->g729onlyA = g729onlyA;
- pvt->call_reference = callref;
- if (callToken)
- pvt->callToken = strdup(callToken);
- /* whether to use gk for this call */
- if (gRasGkMode == RasNoGatekeeper)
- OO_SETFLAG(pvt->flags, H323_DISABLEGK);
- pvt->dtmfmode = gDTMFMode;
- pvt->dtmfcodec = gDTMFCodec;
- ast_copy_string(pvt->context, gContext, sizeof(pvt->context));
- ast_copy_string(pvt->accountcode, gAccountcode, sizeof(pvt->accountcode));
- pvt->amaflags = gAMAFLAGS;
- pvt->capability = gCapability;
- memcpy(&pvt->prefs, &gPrefs, sizeof(pvt->prefs));
- ast_mutex_unlock(&pvt->lock);
- /* Add to interface list */
- ast_mutex_lock(&iflock);
- pvt->next = iflist;
- iflist = pvt;
- ast_mutex_unlock(&iflock);
- if (gH323Debug)
- ast_verbose("+++ ooh323_alloc\n");
- return pvt;
- }
- /*
- Possible data values - peername, exten/peername, exten@ip
- */
- static struct ast_channel *ooh323_request(const char *type, format_t format,
- const struct ast_channel *requestor, void *data, int *cause)
- {
- struct ast_channel *chan = NULL;
- struct ooh323_pvt *p = NULL;
- struct ooh323_peer *peer = NULL;
- char *dest = NULL;
- char *ext = NULL;
- char tmp[256];
- char formats[FORMAT_STRING_SIZE];
- int port = 0;
- if (gH323Debug)
- ast_verbose("--- ooh323_request - data %s format %s\n", (char*)data,
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,format));
- format &= AST_FORMAT_AUDIO_MASK;
- if (!format) {
- ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%lld'\n", (long long) format);
- return NULL;
- }
- p = ooh323_alloc(0,0); /* Initial callRef is zero */
- if (!p) {
- ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", (char*)data);
- return NULL;
- }
- ast_mutex_lock(&p->lock);
- /* This is an outgoing call, since ooh323_request is called */
- ast_set_flag(p, H323_OUTGOING);
- ast_copy_string(tmp, data, sizeof(tmp));
- dest = strchr(tmp, '/');
- if (dest) {
- *dest = '\0';
- dest++;
- ext = dest;
- dest = tmp;
- } else if ((dest = strchr(tmp, '@'))) {
- *dest = '\0';
- dest++;
- ext = tmp;
- } else {
- dest = tmp;
- ext = NULL;
- }
- #if 0
- if ((sport = strchr(dest, ':'))) {
- *sport = '\0';
- sport++;
- port = atoi(sport);
- }
- #endif
- if (dest) {
- peer = find_peer(dest, port);
- } else{
- ast_mutex_lock(&iflock);
- ast_mutex_unlock(&p->lock);
- ooh323_destroy(p);
- ast_mutex_unlock(&iflock);
- ast_log(LOG_ERROR, "Destination format is not supported\n");
- return NULL;
- }
- if (peer) {
- p->username = strdup(peer->name);
- p->host = strdup(peer->ip);
- p->port = peer->port;
- /* Disable gk as we are going to call a known peer*/
- /* OO_SETFLAG(p->flags, H323_DISABLEGK); */
- if (ext)
- ast_copy_string(p->exten, ext, sizeof(p->exten));
- p->capability = peer->capability;
- memcpy(&p->prefs, &peer->prefs, sizeof(struct ast_codec_pref));
- p->g729onlyA = peer->g729onlyA;
- p->dtmfmode |= peer->dtmfmode;
- p->dtmfcodec = peer->dtmfcodec;
- p->t38support = peer->t38support;
- p->rtptimeout = peer->rtptimeout;
- p->faststart = peer->faststart;
- p->h245tunneling = peer->h245tunneling;
- if (peer->rtpmask && peer->rtpmaskstr[0]) {
- p->rtpmask = peer->rtpmask;
- ast_copy_string(p->rtpmaskstr, peer->rtpmaskstr, sizeof(p->rtpmaskstr));
- }
- if (peer->rtdrinterval) {
- p->rtdrinterval = peer->rtdrinterval;
- p->rtdrcount = peer->rtdrcount;
- }
- ast_copy_string(p->accountcode, peer->accountcode, sizeof(p->accountcode));
- p->amaflags = peer->amaflags;
- } else {
- if (gRasGkMode == RasNoGatekeeper) {
- /* no gk and no peer */
- ast_log(LOG_ERROR, "Call to undefined peer %s", dest);
- ast_mutex_lock(&iflock);
- ast_mutex_unlock(&p->lock);
- ooh323_destroy(p);
- ast_mutex_unlock(&iflock);
- return NULL;
- }
- p->g729onlyA = g729onlyA;
- p->dtmfmode = gDTMFMode;
- p->dtmfcodec = gDTMFCodec;
- p->t38support = gT38Support;
- p->rtptimeout = gRTPTimeout;
- p->capability = gCapability;
- p->rtdrinterval = gRTDRInterval;
- p->rtdrcount = gRTDRCount;
- p->faststart = gFastStart;
- p->h245tunneling = gTunneling;
- memcpy(&p->prefs, &gPrefs, sizeof(struct ast_codec_pref));
- p->username = strdup(dest);
- p->host = strdup(dest);
- if (port > 0) {
- p->port = port;
- }
- if (ext) {
- ast_copy_string(p->exten, ext, sizeof(p->exten));
- }
- }
- chan = ooh323_new(p, AST_STATE_DOWN, p->username, format,
- requestor ? requestor->linkedid : NULL);
-
- ast_mutex_unlock(&p->lock);
- if (!chan) {
- ast_mutex_lock(&iflock);
- ooh323_destroy(p);
- ast_mutex_unlock(&iflock);
- } else {
- ast_mutex_lock(&p->lock);
- p->callToken = (char*)ast_malloc(AST_MAX_EXTENSION);
- if(!p->callToken) {
- ast_mutex_unlock(&p->lock);
- ast_mutex_lock(&iflock);
- ooh323_destroy(p);
- ast_mutex_unlock(&iflock);
- ast_log(LOG_ERROR, "Failed to allocate memory for callToken\n");
- return NULL;
- }
- ast_mutex_unlock(&p->lock);
- ast_mutex_lock(&ooh323c_cmd_lock);
- ooMakeCall(data, p->callToken, AST_MAX_EXTENSION, NULL);
- ast_mutex_unlock(&ooh323c_cmd_lock);
- }
- restart_monitor();
- if (gH323Debug)
- ast_verbose("+++ ooh323_request\n");
- return chan;
- }
- static struct ooh323_pvt* find_call(ooCallData *call)
- {
- struct ooh323_pvt *p;
- if (gH323Debug)
- ast_verbose("--- find_call\n");
- ast_mutex_lock(&iflock);
- for (p = iflist; p; p = p->next) {
- if (p->callToken && !strcmp(p->callToken, call->callToken)) {
- break;
- }
- }
- ast_mutex_unlock(&iflock);
- if (gH323Debug)
- ast_verbose("+++ find_call\n");
- return p;
- }
- struct ooh323_user *find_user(const char * name, const char* ip)
- {
- struct ooh323_user *user;
- if (gH323Debug)
- ast_verbose("--- find_user: %s, %s\n",name,ip);
- ast_mutex_lock(&userl.lock);
- for (user = userl.users; user; user = user->next) {
- if (ip && user->mUseIP && !strcmp(user->mIP, ip)) {
- break;
- }
- if (name && !strcmp(user->name, name)) {
- break;
- }
- }
- ast_mutex_unlock(&userl.lock);
- if (gH323Debug)
- ast_verbose("+++ find_user\n");
- return user;
- }
- struct ooh323_peer *find_friend(const char *name, int port)
- {
- struct ooh323_peer *peer;
- if (gH323Debug)
- ast_verbose("--- find_friend \"%s\"\n", name);
- ast_mutex_lock(&peerl.lock);
- for (peer = peerl.peers; peer; peer = peer->next) {
- if (gH323Debug) {
- ast_verbose(" comparing with \"%s\"\n", peer->ip);
- }
- if (!strcmp(peer->ip, name)) {
- if (port <= 0 || (port > 0 && peer->port == port)) {
- break;
- }
- }
- }
- ast_mutex_unlock(&peerl.lock);
- if (gH323Debug) {
- if (peer) {
- ast_verbose(" found matching friend\n");
- }
- ast_verbose("+++ find_friend \"%s\"\n", name);
- }
- return peer;
- }
- struct ooh323_peer *find_peer(const char * name, int port)
- {
- struct ooh323_peer *peer;
- if (gH323Debug)
- ast_verbose("--- find_peer \"%s\"\n", name);
- ast_mutex_lock(&peerl.lock);
- for (peer = peerl.peers; peer; peer = peer->next) {
- if (gH323Debug) {
- ast_verbose(" comparing with \"%s\"\n", peer->ip);
- }
- if (!strcasecmp(peer->name, name))
- break;
- if (peer->h323id && !strcasecmp(peer->h323id, name))
- break;
- if (peer->e164 && !strcasecmp(peer->e164, name))
- break;
- /*
- if (!strcmp(peer->ip, name)) {
- if (port > 0 && peer->port == port) { break; }
- else if (port <= 0) { break; }
- }
- */
- }
- ast_mutex_unlock(&peerl.lock);
- if (gH323Debug) {
- if (peer) {
- ast_verbose(" found matching peer\n");
- }
- ast_verbose("+++ find_peer \"%s\"\n", name);
- }
- return peer;
- }
- static int ooh323_digit_begin(struct ast_channel *chan, char digit)
- {
- char dtmf[2];
- struct ooh323_pvt *p = (struct ooh323_pvt *) chan->tech_pvt;
- int res = 0;
-
- if (gH323Debug)
- ast_verbose("--- ooh323_digit_begin\n");
- if (!p) {
- ast_log(LOG_ERROR, "No private structure for call\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- if (digit == 'e' && !p->faxmode && p->t38support != T38_DISABLED) {
- if (!p->chmodepend) {
- if (gH323Debug)
- ast_verbose("request to change %s to t.38 because fax cng\n",
- p->callToken);
- p->chmodepend = 1;
- ooRequestChangeMode(p->callToken, 1);
- }
- } else if (p->rtp && ((p->dtmfmode & H323_DTMF_RFC2833) || (p->dtmfmode & H323_DTMF_CISCO))) {
- ast_rtp_instance_dtmf_begin(p->rtp, digit);
- } else if (((p->dtmfmode & H323_DTMF_Q931) ||
- (p->dtmfmode & H323_DTMF_H245ALPHANUMERIC) ||
- (p->dtmfmode & H323_DTMF_H245SIGNAL))) {
- dtmf[0] = digit;
- dtmf[1] = '\0';
- ooSendDTMFDigit(p->callToken, dtmf);
- } else if (p->dtmfmode & H323_DTMF_INBAND) {
- res = -1; // tell Asterisk to generate inband indications
- }
- ast_mutex_unlock(&p->lock);
- if (gH323Debug) {
- ast_verbose("+++ ooh323_digit_begin %d\n", res);
- }
- return res;
- }
- static int ooh323_digit_end(struct ast_channel *chan, char digit, unsigned int duration)
- {
- struct ooh323_pvt *p = (struct ooh323_pvt *) chan->tech_pvt;
- int res = 0;
- if (gH323Debug)
- ast_verbose("--- ooh323_digit_end\n");
- if (!p) {
- ast_log(LOG_ERROR, "No private structure for call\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- if (p->rtp && ((p->dtmfmode & H323_DTMF_RFC2833) || (p->dtmfmode & H323_DTMF_CISCO)) ) {
- ast_rtp_instance_dtmf_end(p->rtp, digit);
- } else if(p->dtmfmode & H323_DTMF_INBAND) {
- res = -1; // tell Asterisk to stop inband indications
- }
- ast_mutex_unlock(&p->lock);
- if (gH323Debug) {
- ast_verbose("+++ ooh323_digit_end, res = %d\n", res);
- }
- return res;
- }
- static int ooh323_call(struct ast_channel *ast, char *dest, int timeout)
- {
- struct ooh323_pvt *p = ast->tech_pvt;
- char destination[256];
- int res=0, i;
- const char *val = NULL;
- ooCallOptions opts = {
- .fastStart = TRUE,
- .tunneling = TRUE,
- .disableGk = TRUE,
- .callMode = OO_CALLMODE_AUDIOCALL,
- .transfercap = 0
- };
- if (gH323Debug)
- ast_verbose("--- ooh323_call- %s\n", dest);
- if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
- ast_log(LOG_WARNING, "ooh323_call called on %s, neither down nor "
- "reserved\n", ast->name);
- return -1;
- }
- ast_mutex_lock(&p->lock);
- ast_set_flag(p, H323_OUTGOING);
- if (ast->connected.id.number.valid && ast->connected.id.number.str) {
- free(p->callerid_num);
- p->callerid_num = strdup(ast->connected.id.number.str);
- }
- if (ast->connected.id.name.valid && ast->connected.id.name.str) {
- free(p->callerid_name);
- p->callerid_name = strdup(ast->connected.id.name.str);
- } else if (ast->connected.id.number.valid && ast->connected.id.number.str) {
- free(p->callerid_name);
- p->callerid_name = strdup(ast->connected.id.number.str);
- } else {
- ast->connected.id.name.valid = 1;
- free(ast->connected.id.name.str);
- ast->connected.id.name.str = strdup(gCallerID);
- free(p->callerid_name);
- p->callerid_name = strdup(ast->connected.id.name.str);
- }
- /* Retrieve vars */
- if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323ID"))) {
- ast_copy_string(p->caller_h323id, val, sizeof(p->caller_h323id));
- }
-
- if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323DIALEDDIGITS"))) {
- ast_copy_string(p->caller_dialedDigits, val, sizeof(p->caller_dialedDigits));
- if(!p->callerid_num)
- p->callerid_num = strdup(val);
- }
- if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323EMAIL"))) {
- ast_copy_string(p->caller_email, val, sizeof(p->caller_email));
- }
- if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323URL"))) {
- ast_copy_string(p->caller_url, val, sizeof(p->caller_url));
- }
- if (p->host && p->port != 0)
- snprintf(destination, sizeof(destination), "%s:%d", p->host, p->port);
- else if (p->host)
- snprintf(destination, sizeof(destination), "%s", p->host);
- else
- ast_copy_string(destination, dest, sizeof(destination));
- destination[sizeof(destination)-1]='\0';
- opts.transfercap = ast->transfercapability;
- opts.fastStart = p->faststart;
- opts.tunneling = p->h245tunneling;
- for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
- if(OO_TESTFLAG(p->flags, H323_DISABLEGK)) {
- res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, &opts);
- } else {
- res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, NULL);
- }
- ast_mutex_unlock(&p->lock);
- if (res != OO_OK) {
- ast_log(LOG_ERROR, "Failed to make call\n");
- return -1; /* ToDO: cleanup */
- }
- if (gH323Debug)
- ast_verbose("+++ ooh323_call\n");
- return 0;
- }
- static int ooh323_hangup(struct ast_channel *ast)
- {
- struct ooh323_pvt *p = ast->tech_pvt;
- int q931cause = AST_CAUSE_NORMAL_CLEARING;
- if (gH323Debug)
- ast_verbose("--- ooh323_hangup\n");
- if (p) {
- ast_mutex_lock(&p->lock);
- if (ast->hangupcause) {
- q931cause = ast->hangupcause;
- } else {
- const char *cause = pbx_builtin_getvar_helper(ast, "DIALSTATUS");
- if (cause) {
- if (!strcmp(cause, "CONGESTION")) {
- q931cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
- } else if (!strcmp(cause, "BUSY")) {
- q931cause = AST_CAUSE_USER_BUSY;
- } else if (!strcmp(cause, "CHANISUNVAIL")) {
- q931cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
- } else if (!strcmp(cause, "NOANSWER")) {
- q931cause = AST_CAUSE_NO_ANSWER;
- } else if (!strcmp(cause, "CANCEL")) {
- q931cause = AST_CAUSE_CALL_REJECTED;
- }
- }
- }
- if (gH323Debug)
- ast_verbose(" hanging %s with cause: %d\n", p->username, q931cause);
- ast->tech_pvt = NULL;
- if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ooHangCall(p->callToken,
- ooh323_convert_hangupcause_asteriskToH323(q931cause), q931cause);
- ast_set_flag(p, H323_ALREADYGONE);
- /* ast_mutex_unlock(&p->lock); */
- } else
- ast_set_flag(p, H323_NEEDDESTROY);
- /* detach channel here */
- if (p->owner) {
- p->owner->tech_pvt = NULL;
- p->owner = NULL;
- ast_module_unref(myself);
- }
- ast_mutex_unlock(&p->lock);
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- /* Notify the module monitors that use count for resource has changed */
- ast_update_use_count();
-
- } else {
- ast_debug(1, "No call to hangup\n" );
- }
-
- if (gH323Debug)
- ast_verbose("+++ ooh323_hangup\n");
- return 0;
- }
- static int ooh323_answer(struct ast_channel *ast)
- {
- struct ooh323_pvt *p = ast->tech_pvt;
- char *callToken = (char *)NULL;
- if (gH323Debug)
- ast_verbose("--- ooh323_answer\n");
- if (p) {
- ast_mutex_lock(&p->lock);
- callToken = (p->callToken ? strdup(p->callToken) : NULL);
- if (ast->_state != AST_STATE_UP) {
- ast_channel_lock(ast);
- if (!p->alertsent) {
- if (gH323Debug) {
- ast_debug(1, "Sending forced ringback for %s, res = %d\n",
- callToken, ooManualRingback(callToken));
- } else {
- ooManualRingback(callToken);
- }
- p->alertsent = 1;
- }
- ast_setstate(ast, AST_STATE_UP);
- if (option_debug)
- ast_debug(1, "ooh323_answer(%s)\n", ast->name);
- ast_channel_unlock(ast);
- ooAnswerCall(p->callToken);
- }
- if (callToken) {
- free(callToken);
- }
- ast_mutex_unlock(&p->lock);
- }
- if (gH323Debug)
- ast_verbose("+++ ooh323_answer\n");
- return 0;
- }
- static struct ast_frame *ooh323_read(struct ast_channel *ast)
- {
- struct ast_frame *fr;
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
- struct ooh323_pvt *p = ast->tech_pvt;
- if (!p) return &null_frame;
- ast_mutex_lock(&p->lock);
- if (p->rtp)
- fr = ooh323_rtp_read(ast, p);
- else
- fr = &null_frame;
- /* time(&p->lastrtprx); */
- ast_mutex_unlock(&p->lock);
- return fr;
- }
- static int ooh323_write(struct ast_channel *ast, struct ast_frame *f)
- {
- struct ooh323_pvt *p = ast->tech_pvt;
- int res = 0;
- char buf[256];
- if (p) {
- ast_mutex_lock(&p->lock);
- if (f->frametype == AST_FRAME_MODEM) {
- ast_debug(1, "Send UDPTL %d/%d len %d for %s\n",
- f->frametype, f->subclass.integer, f->datalen, ast->name);
- if (p->udptl)
- res = ast_udptl_write(p->udptl, f);
- ast_mutex_unlock(&p->lock);
- return res;
- }
-
- if (f->frametype == AST_FRAME_VOICE) {
- /* sending progress for first */
- if (!ast_test_flag(p, H323_OUTGOING) && !p->progsent &&
- p->callToken) {
- ooManualProgress(p->callToken);
- p->progsent = 1;
- }
- if (!(f->subclass.codec & ast->nativeformats)) {
- if (ast->nativeformats != 0) {
- ast_log(LOG_WARNING,
- "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
- ast_getformatname(f->subclass.codec),
- ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
- ast_getformatname(ast->readformat),
- ast_getformatname(ast->writeformat));
- ast_set_write_format(ast, f->subclass.codec);
- } else {
- /* ast_set_write_format(ast, f->subclass);
- ast->nativeformats = f->subclass; */
- }
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- if (p->rtp)
- res = ast_rtp_instance_write(p->rtp, f);
- ast_mutex_unlock(&p->lock);
- } else if (f->frametype == AST_FRAME_IMAGE) {
- ast_mutex_unlock(&p->lock);
- return 0;
- } else {
- ast_log(LOG_WARNING, "Can't send %d type frames with OOH323 write\n",
- f->frametype);
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- }
- return res;
- }
- static int ooh323_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
- {
- struct ooh323_pvt *p = (struct ooh323_pvt *) ast->tech_pvt;
- char *callToken = (char *)NULL;
- int res = -1;
- if (!p) return -1;
- ast_mutex_lock(&p->lock);
- callToken = (p->callToken ? strdup(p->callToken) : NULL);
- ast_mutex_unlock(&p->lock);
- if (!callToken) {
- if (gH323Debug)
- ast_verbose(" ooh323_indicate - No callToken\n");
- return -1;
- }
- if (gH323Debug)
- ast_verbose("----- ooh323_indicate %d on call %s\n", condition, callToken);
-
- ast_mutex_lock(&p->lock);
- switch (condition) {
- case AST_CONTROL_INCOMPLETE:
- /* While h323 does support overlapped dialing, this channel driver does not
- * at this time. Treat a response of Incomplete as if it were congestion.
- */
- case AST_CONTROL_CONGESTION:
- if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED, AST_CAUSE_SWITCH_CONGESTION);
- ast_set_flag(p, H323_ALREADYGONE);
- }
- break;
- case AST_CONTROL_BUSY:
- if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ooHangCall(callToken, OO_REASON_LOCAL_BUSY, AST_CAUSE_USER_BUSY);
- ast_set_flag(p, H323_ALREADYGONE);
- }
- break;
- case AST_CONTROL_HOLD:
- ast_moh_start(ast, data, NULL);
- break;
- case AST_CONTROL_UNHOLD:
- ast_moh_stop(ast);
- break;
- case AST_CONTROL_PROGRESS:
- if (ast->_state != AST_STATE_UP) {
- if (!p->progsent) {
- if (gH323Debug)
- ast_log(LOG_DEBUG,"Sending manual progress for %s, res = %d\n", callToken,
- ooManualProgress(callToken));
- else
- ooManualProgress(callToken);
- p->progsent = 1;
- }
- }
- break;
- case AST_CONTROL_RINGING:
- if (ast->_state == AST_STATE_RING || ast->_state == AST_STATE_RINGING) {
- if (!p->alertsent) {
- if (gH323Debug) {
- ast_debug(1, "Sending manual ringback for %s, res = %d\n",
- callToken,
- ooManualRingback(callToken));
- } else {
- ooManualRingback(callToken);
- }
- p->alertsent = 1;
- }
- }
- break;
- case AST_CONTROL_SRCUPDATE:
- if (p->rtp) {
- ast_rtp_instance_update_source(p->rtp);
- }
- break;
- case AST_CONTROL_SRCCHANGE:
- if (p->rtp) {
- ast_rtp_instance_change_source(p->rtp);
- }
- break;
- case AST_CONTROL_CONNECTED_LINE:
- if (!ast->connected.id.name.valid
- || ast_strlen_zero(ast->connected.id.name.str)) {
- break;
- }
- if (gH323Debug)
- ast_log(LOG_DEBUG, "Sending connected line info for %s (%s)\n",
- callToken, ast->connected.id.name.str);
- ooSetANI(callToken, ast->connected.id.name.str);
- break;
- case AST_CONTROL_T38_PARAMETERS:
- if (p->t38support != T38_ENABLED) {
- struct ast_control_t38_parameters parameters = { .request_response = 0 };
- parameters.request_response = AST_T38_REFUSED;
- ast_queue_control_data(ast, AST_CONTROL_T38_PARAMETERS,
- ¶meters, sizeof(parameters));
- break;
- }
- if (datalen != sizeof(struct ast_control_t38_parameters)) {
- ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38. "
- "Expected %d, got %d\n",
- (int)sizeof(enum ast_control_t38), (int)datalen);
- } else {
- const struct ast_control_t38_parameters *parameters = data;
- enum ast_control_t38 message = parameters->request_response;
- switch (message) {
- case AST_T38_REQUEST_NEGOTIATE:
- if (!p->chmodepend && !p->faxmode) {
- ooRequestChangeMode(p->callToken, 1);
- p->chmodepend = 1;
- res = 0;
- }
- break;
- case AST_T38_REQUEST_TERMINATE:
- if (!p->chmodepend && p->faxmode) {
- ooRequestChangeMode(p->callToken, 0);
- p->chmodepend = 1;
- res = 0;
- }
- break;
- default:
- ;
- }
- }
- break;
- case AST_CONTROL_PROCEEDING:
- case -1:
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to indicate condition %d on %s\n",
- condition, callToken);
- }
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("++++ ooh323_indicate %d on %s\n", condition, callToken);
- free(callToken);
- return res;
- }
- static int ooh323_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
- {
- struct ooh323_pvt *p = (struct ooh323_pvt *) ast->tech_pvt;
- int res = -1;
- enum ast_t38_state state = T38_STATE_UNAVAILABLE;
- char* cp;
- if (!p) return -1;
- ast_mutex_lock(&p->lock);
- if (gH323Debug)
- ast_verbose("----- ooh323_queryoption %d on channel %s\n", option, ast->name);
-
- switch (option) {
- case AST_OPTION_T38_STATE:
- if (*datalen != sizeof(enum ast_t38_state)) {
- ast_log(LOG_ERROR, "Invalid datalen for AST_OPTION_T38_STATE option."
- " Expected %d, got %d\n", (int)sizeof(enum ast_t38_state), *datalen);
- break;
- }
- if (p->t38support != T38_DISABLED)
- state = T38_STATE_UNKNOWN;
- if (p->faxmode)
- state = (p->chmodepend) ? T38_STATE_UNKNOWN : T38_STATE_NEGOTIATED;
- else if (p->chmodepend)
- state = T38_STATE_NEGOTIATING;
- *((enum ast_t38_state *) data) = state;
- res = 0;
- break;
- case AST_OPTION_DIGIT_DETECT:
- cp = (char *) data;
- *cp = p->vad ? 1 : 0;
- ast_debug(1, "Reporting digit detection %sabled on %s\n",
- *cp ? "en" : "dis", ast->name);
- res = 0;
- break;
- default: ;
- }
- if (gH323Debug)
- ast_verbose("+++++ ooh323_queryoption %d on channel %s\n", option, ast->name);
-
- ast_mutex_unlock(&p->lock);
- return res;
- }
- static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
- {
- struct ooh323_pvt *p = newchan->tech_pvt;
- if (!p) return -1;
- if (gH323Debug)
- ast_verbose("--- ooh323c ooh323_fixup\n");
- ast_mutex_lock(&p->lock);
- if (p->owner != oldchan) {
- ast_log(LOG_WARNING, "Old channel wasn't %p but was %p\n", oldchan, p->owner);
- ast_mutex_unlock(&p->lock);
- return -1;
- }
- if (p->owner == oldchan) {
- p->owner = newchan;
- } else {
- p->owner = oldchan;
- }
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("+++ ooh323c ooh323_fixup \n");
- return 0;
- }
- void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
- {
- struct ooh323_pvt *p = NULL;
- char formats[FORMAT_STRING_SIZE];
- if (gH323Debug)
- ast_verbose("--- ooh323_update_writeformat %s/%d\n",
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt), txframes);
-
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
- return;
- }
- ast_mutex_lock(&p->lock);
- p->writeformat = fmt;
- if (p->owner) {
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- if (gH323Debug)
- ast_verbose("Writeformat before update %s/%s\n",
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->writeformat),
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->nativeformats));
- if (txframes)
- ast_codec_pref_setsize(&p->prefs, fmt, txframes);
- ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
- if (p->dtmfmode & H323_DTMF_RFC2833 && p->dtmfcodec) {
- ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
- p->rtp, p->dtmfcodec, "audio", "telephone-event", 0);
- }
- if (p->dtmfmode & H323_DTMF_CISCO && p->dtmfcodec) {
- ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
- p->rtp, p->dtmfcodec, "audio", "cisco-telephone-event", 0);
- }
- p->owner->nativeformats = fmt;
- ast_set_write_format(p->owner, p->owner->writeformat);
- ast_set_read_format(p->owner, p->owner->readformat);
- ast_channel_unlock(p->owner);
- } else
- ast_log(LOG_ERROR, "No owner found\n");
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("+++ ooh323_update_writeformat\n");
- }
- void ooh323_set_read_format(ooCallData *call, int fmt)
- {
- struct ooh323_pvt *p = NULL;
- char formats[FORMAT_STRING_SIZE];
- if (gH323Debug)
- ast_verbose("--- ooh323_update_readformat %s\n",
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt));
-
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
- return;
- }
- ast_mutex_lock(&p->lock);
- p->readformat = fmt;
- if (p->owner) {
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- if (gH323Debug)
- ast_verbose("Readformat before update %s\n",
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->readformat));
- p->owner->nativeformats = fmt;
- ast_set_read_format(p->owner, p->owner->readformat);
- ast_channel_unlock(p->owner);
- } else
- ast_log(LOG_ERROR, "No owner found\n");
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("+++ ooh323_update_readformat\n");
- }
- int onAlerting(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- struct ast_channel *c = NULL;
- if (gH323Debug)
- ast_verbose("--- onAlerting %s\n", call->callToken);
- p = find_call(call);
- if(!p) {
- ast_log(LOG_ERROR, "No matching call found\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return 0;
- }
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return 0;
- }
- c = p->owner;
- if (call->remoteDisplayName) {
- struct ast_party_connected_line connected;
- struct ast_set_party_connected_line update_connected;
- memset(&update_connected, 0, sizeof(update_connected));
- update_connected.id.name = 1;
- ast_party_connected_line_init(&connected);
- connected.id.name.valid = 1;
- connected.id.name.str = (char *) call->remoteDisplayName;
- connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
- ast_channel_queue_connected_line_update(c, &connected, &update_connected);
- }
- if (c->_state != AST_STATE_UP)
- ast_setstate(c, AST_STATE_RINGING);
- ast_queue_control(c, AST_CONTROL_RINGING);
- ast_channel_unlock(c);
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("+++ onAlerting %s\n", call->callToken);
- return OO_OK;
- }
- int onProgress(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- struct ast_channel *c = NULL;
- if (gH323Debug)
- ast_verbose("--- onProgress %s\n", call->callToken);
- p = find_call(call);
- if(!p) {
- ast_log(LOG_ERROR, "No matching call found\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return 0;
- }
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return 0;
- }
- c = p->owner;
- if (call->remoteDisplayName) {
- struct ast_party_connected_line connected;
- struct ast_set_party_connected_line update_connected;
- memset(&update_connected, 0, sizeof(update_connected));
- update_connected.id.name = 1;
- ast_party_connected_line_init(&connected);
- connected.id.name.valid = 1;
- connected.id.name.str = (char *) call->remoteDisplayName;
- connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
- ast_channel_queue_connected_line_update(c, &connected, &update_connected);
- }
- if (c->_state != AST_STATE_UP)
- ast_setstate(c, AST_STATE_RINGING);
- ast_queue_control(c, AST_CONTROL_PROGRESS);
- ast_channel_unlock(c);
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("+++ onProgress %s\n", call->callToken);
- return OO_OK;
- }
- /**
- * Callback for sending digits from H.323 up to asterisk
- *
- */
- int ooh323_onReceivedDigit(OOH323CallData *call, const char *digit)
- {
- struct ooh323_pvt *p = NULL;
- struct ast_frame f;
- int res;
- ast_debug(1, "Received Digit: %c\n", digit[0]);
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Failed to find a matching call.\n");
- return -1;
- }
- if (!p->owner) {
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- memset(&f, 0, sizeof(f));
- f.frametype = AST_FRAME_DTMF;
- f.subclass.integer = digit[0];
- f.datalen = 0;
- f.samples = 800;
- f.offset = 0;
- f.data.ptr = NULL;
- f.mallocd = 0;
- f.src = "SEND_DIGIT";
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return 0;
- }
- res = ast_queue_frame(p->owner, &f);
- ast_channel_unlock(p->owner);
- ast_mutex_unlock(&p->lock);
- return res;
- }
- int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
- {
- struct ooh323_pvt *p = NULL;
- struct ooh323_user *user = NULL;
- struct ast_channel *c = NULL;
- ooAliases *alias = NULL;
- char *at = NULL;
- char number [OO_MAX_NUMBER_LENGTH];
- if (gH323Debug)
- ast_verbose("--- ooh323_onReceivedSetup %s\n", call->callToken);
- if (!(p = ooh323_alloc(call->callReference, call->callToken))) {
- ast_log(LOG_ERROR, "Failed to create a new call.\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- ast_clear_flag(p, H323_OUTGOING);
-
- if (call->remoteDisplayName) {
- p->callerid_name = strdup(call->remoteDisplayName);
- }
- if (ooCallGetCallingPartyNumber(call, number, OO_MAX_NUMBER_LENGTH) == OO_OK) {
- p->callerid_num = strdup(number);
- }
- if (call->remoteAliases) {
- for (alias = call->remoteAliases; alias; alias = alias->next) {
- if (alias->type == T_H225AliasAddress_h323_ID) {
- if (!p->callerid_name) {
- p->callerid_name = strdup(alias->value);
- }
- ast_copy_string(p->caller_h323id, alias->value, sizeof(p->caller_h323id));
- }
- else if(alias->type == T_H225AliasAddress_dialedDigits)
- {
- if(!p->callerid_num)
- p->callerid_num = strdup(alias->value);
- ast_copy_string(p->caller_dialedDigits, alias->value,
- sizeof(p->caller_dialedDigits));
- }
- else if(alias->type == T_H225AliasAddress_email_ID)
- {
- ast_copy_string(p->caller_email, alias->value, sizeof(p->caller_email));
- }
- else if(alias->type == T_H225AliasAddress_url_ID)
- {
- ast_copy_string(p->caller_url, alias->value, sizeof(p->caller_url));
- }
- }
- }
- number[0] = '\0';
- if(ooCallGetCalledPartyNumber(call, number, OO_MAX_NUMBER_LENGTH)== OO_OK) {
- strncpy(p->exten, number, sizeof(p->exten)-1);
- } else {
- update_our_aliases(call, p);
- if (!ast_strlen_zero(p->callee_dialedDigits)) {
- ast_copy_string(p->exten, p->callee_dialedDigits, sizeof(p->exten));
- } else if(!ast_strlen_zero(p->callee_h323id)) {
- ast_copy_string(p->exten, p->callee_h323id, sizeof(p->exten));
- } else if(!ast_strlen_zero(p->callee_email)) {
- ast_copy_string(p->exten, p->callee_email, sizeof(p->exten));
- if ((at = strchr(p->exten, '@'))) {
- *at = '\0';
- }
- }
- }
- /* if no extension found, set to default 's' */
- if (ast_strlen_zero(p->exten)) {
- p->exten[0]='s';
- p->exten[1]='\0';
- }
- user = find_user(p->callerid_name, call->remoteIP);
- if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) {
- ast_mutex_lock(&user->lock);
- p->username = strdup(user->name);
- p->neighbor.user = user->mUseIP ? ast_strdup(user->mIP) :
- ast_strdup(user->name);
- ast_copy_string(p->context, user->context, sizeof(p->context));
- ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
- p->amaflags = user->amaflags;
- p->capability = user->capability;
- p->g729onlyA = user->g729onlyA;
- memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
- p->dtmfmode |= user->dtmfmode;
- p->dtmfcodec = user->dtmfcodec;
- p->t38support = user->t38support;
- p->rtptimeout = user->rtptimeout;
- p->h245tunneling = user->h245tunneling;
- p->faststart = user->faststart;
- if (p->faststart)
- OO_SETFLAG(call->flags, OO_M_FASTSTART);
- else
- OO_CLRFLAG(call->flags, OO_M_FASTSTART);
- /* if we disable h245tun for this user then we clear flag */
- /* in any other case we don't must touch this */
- /* ie if we receive setup without h245tun but enabled
- we can't enable it per call */
- if (!p->h245tunneling)
- OO_CLRFLAG(call->flags, OO_M_TUNNELING);
- if (user->rtpmask && user->rtpmaskstr[0]) {
- p->rtpmask = user->rtpmask;
- ast_copy_string(p->rtpmaskstr, user->rtpmaskstr,
- sizeof(p->rtpmaskstr));
- }
- if (user->rtdrcount > 0 && user->rtdrinterval > 0) {
- p->rtdrcount = user->rtdrcount;
- p->rtdrinterval = user->rtdrinterval;
- }
- if (user->incominglimit) user->inUse++;
- ast_mutex_unlock(&user->lock);
- } else {
- if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) {
- p->username = strdup(call->remoteIP);
- } else {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Unacceptable ip %s\n", call->remoteIP);
- if (!user)
- ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_CALL_REJECTED), AST_CAUSE_CALL_REJECTED);
- else
- ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_NORMAL_CIRCUIT_CONGESTION), AST_CAUSE_NORMAL_CIRCUIT_CONGESTION);
- ast_set_flag(p, H323_NEEDDESTROY);
- return -1;
- }
- }
- ooh323c_set_capability_for_call(call, &p->prefs, p->capability, p->dtmfmode, p->dtmfcodec,
- p->t38support, p->g729onlyA);
- configure_local_rtp(p, call);
- /* Incoming call */
- c = ooh323_new(p, AST_STATE_RING, p->username, 0, NULL);
- if(!c) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Could not create ast_channel\n");
- return -1;
- }
- ast_mutex_unlock(&p->lock);
- if (gH323Debug)
- ast_verbose("+++ ooh323_onReceivedSetup - Determined context %s, "
- "extension %s\n", p->context, p->exten);
- return OO_OK;
- }
- int onOutgoingCall(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- int i = 0;
- if (gH323Debug)
- ast_verbose("--- onOutgoingCall %lx: %s\n", (long unsigned int) call, call->callToken);
- if (!strcmp(call->callType, "outgoing")) {
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Failed to find a matching call.\n");
- return -1;
- }
- ast_mutex_lock(&p->lock);
- if (!ast_strlen_zero(p->callerid_name)) {
- ooCallSetCallerId(call, p->callerid_name);
- }
- if (!ast_strlen_zero(p->callerid_num)) {
- i = 0;
- while (*(p->callerid_num + i) != '\0') {
- if(!isdigit(*(p->callerid_num+i))) { break; }
- i++;
- }
- if(*(p->callerid_num+i) == '\0')
- ooCallSetCallingPartyNumber(call, p->callerid_num);
- else {
- if(!p->callerid_name)
- ooCallSetCallerId(call, p->callerid_num);
- }
- }
-
- if (!ast_strlen_zero(p->caller_h323id))
- ooCallAddAliasH323ID(call, p->caller_h323id);
- if (!ast_strlen_zero(p->caller_dialedDigits)) {
- if (gH323Debug) {
- ast_verbose("Setting dialed digits %s\n", p->caller_dialedDigits);
- }
- ooCallAddAliasDialedDigits(call, p->caller_dialedDigits);
- } else if (!ast_strlen_zero(p->callerid_num)) {
- if (ooIsDailedDigit(p->callerid_num)) {
- if (gH323Debug) {
- ast_verbose("setting callid number %s\n", p->callerid_num);
- }
- ooCallAddAliasDialedDigits(call, p->callerid_num);
- } else if (ast_strlen_zero(p->caller_h323id)) {
- ooCallAddAliasH323ID(call, p->callerid_num);
- }
- }
- if (p->rtpmask && p->rtpmaskstr[0]) {
- call->rtpMask = p->rtpmask;
- ast_mutex_lock(&call->rtpMask->lock);
- call->rtpMask->inuse++;
- ast_mutex_unlock(&call->rtpMask->lock);
- ast_copy_string(call->rtpMaskStr, p->rtpmaskstr, sizeof(call->rtpMaskStr));
- }
- ast_mutex_unlock(&p->lock);
- }
- if (gH323Debug)
- ast_verbose("+++ onOutgoingCall %s\n", call->callToken);
- return OO_OK;
- }
- int onNewCallCreated(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- int i = 0;
- if (gH323Debug)
- ast_verbose("--- onNewCallCreated %lx: %s\n", (long unsigned int) call, call->callToken);
- ast_mutex_lock(&call->Lock);
- if (ooh323c_start_call_thread(call)) {
- ast_log(LOG_ERROR,"Failed to create call thread.\n");
- ast_mutex_unlock(&call->Lock);
- return -1;
- }
- if (!strcmp(call->callType, "outgoing")) {
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Failed to find a matching call.\n");
- ast_mutex_unlock(&call->Lock);
- return -1;
- }
- ast_mutex_lock(&p->lock);
- if (!ast_strlen_zero(p->callerid_name)) {
- ooCallSetCallerId(call, p->callerid_name);
- }
- if (!ast_strlen_zero(p->callerid_num)) {
- i = 0;
- while (*(p->callerid_num + i) != '\0') {
- if(!isdigit(*(p->callerid_num+i))) { break; }
- i++;
- }
- if(*(p->callerid_num+i) == '\0')
- ooCallSetCallingPartyNumber(call, p->callerid_num);
- else {
- if(ast_strlen_zero(p->callerid_name))
- ooCallSetCallerId(call, p->callerid_num);
- }
- }
-
- if (!ast_strlen_zero(p->caller_h323id))
- ooCallAddAliasH323ID(call, p->caller_h323id);
- if (!ast_strlen_zero(p->caller_dialedDigits)) {
- if (gH323Debug) {
- ast_verbose("Setting dialed digits %s\n", p->caller_dialedDigits);
- }
- ooCallAddAliasDialedDigits(call, p->caller_dialedDigits);
- } else if (!ast_strlen_zero(p->callerid_num)) {
- if (ooIsDailedDigit(p->callerid_num)) {
- if (gH323Debug) {
- ast_verbose("setting callid number %s\n", p->callerid_num);
- }
- ooCallAddAliasDialedDigits(call, p->callerid_num);
- } else if (ast_strlen_zero(p->caller_h323id)) {
- ooCallAddAliasH323ID(call, p->callerid_num);
- }
- }
-
- if (!ast_strlen_zero(p->exten)) {
- if (ooIsDailedDigit(p->exten)) {
- ooCallSetCalledPartyNumber(call, p->exten);
- ooCallAddRemoteAliasDialedDigits(call, p->exten);
- } else {
- ooCallAddRemoteAliasH323ID(call, p->exten);
- }
- }
- if (gH323Debug) {
- char prefsBuf[256];
- ast_codec_pref_string(&p->prefs, prefsBuf, sizeof(prefsBuf));
- ast_verbose(" Outgoing call %s(%s) - Codec prefs - %s\n",
- p->username?p->username:"NULL", call->callToken, prefsBuf);
- }
- ooh323c_set_capability_for_call(call, &p->prefs, p->capability,
- p->dtmfmode, p->dtmfcodec, p->t38support, p->g729onlyA);
- configure_local_rtp(p, call);
- ast_mutex_unlock(&p->lock);
- }
- ast_mutex_unlock(&call->Lock);
- if (gH323Debug)
- ast_verbose("+++ onNewCallCreated %s\n", call->callToken);
- return OO_OK;
- }
- int onCallEstablished(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- if (gH323Debug)
- ast_verbose("--- onCallEstablished %s\n", call->callToken);
- if (!(p = find_call(call))) {
- ast_log(LOG_ERROR, "Failed to find a matching call.\n");
- return -1;
- }
- if(ast_test_flag(p, H323_OUTGOING)) {
- ast_mutex_lock(&p->lock);
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return -1;
- }
-
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (p->owner) {
- struct ast_channel* c = p->owner;
- if (call->remoteDisplayName) {
- struct ast_party_connected_line connected;
- struct ast_set_party_connected_line update_connected;
- memset(&update_connected, 0, sizeof(update_connected));
- update_connected.id.name = 1;
- ast_party_connected_line_init(&connected);
- connected.id.name.valid = 1;
- connected.id.name.str = (char *) call->remoteDisplayName;
- connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
- ast_channel_queue_connected_line_update(c, &connected, &update_connected);
- }
- ast_queue_control(c, AST_CONTROL_ANSWER);
- ast_channel_unlock(p->owner);
- manager_event(EVENT_FLAG_SYSTEM,"ChannelUpdate","Channel: %s\r\nChanneltype: %s\r\n"
- "CallRef: %d\r\n", c->name, "OOH323", p->call_reference);
- }
- ast_mutex_unlock(&p->lock);
- }
- if (gH323Debug)
- ast_verbose("+++ onCallEstablished %s\n", call->callToken);
- return OO_OK;
- }
- int onCallCleared(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- int ownerLock = 0;
- if (gH323Debug)
- ast_verbose("--- onCallCleared %s \n", call->callToken);
- if ((p = find_call(call))) {
- ast_mutex_lock(&p->lock);
-
- while (p->owner) {
- if (ast_channel_trylock(p->owner)) {
- ooTrace(OOTRCLVLINFO, "Failed to grab lock, trying again\n");
- ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- } else {
- ownerLock = 1; break;
- }
- }
- if (ownerLock) {
- if (!ast_test_flag(p, H323_ALREADYGONE)) {
- ast_set_flag(p, H323_ALREADYGONE);
- p->owner->hangupcause = call->q931cause;
- p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
- ast_queue_hangup_with_cause(p->owner,call->q931cause);
- }
- }
- if(p->owner) {
- p->owner->tech_pvt = NULL;
- ast_channel_unlock(p->owner);
- p->owner = NULL;
- ast_module_unref(myself);
- }
- ast_set_flag(p, H323_NEEDDESTROY);
- ooh323c_stop_call_thread(call);
- ast_mutex_unlock(&p->lock);
- ast_mutex_lock(&usecnt_lock);
- usecnt--;
- ast_mutex_unlock(&usecnt_lock);
- }
- if (gH323Debug)
- ast_verbose("+++ onCallCleared\n");
- return OO_OK;
- }
- /* static void ooh323_delete_user(struct ooh323_user *user)
- {
- struct ooh323_user *prev = NULL, *cur = NULL;
- if (gH323Debug)
- ast_verbose("--- ooh323_delete_user\n");
- if (user) {
- cur = userl.users;
- ast_mutex_lock(&userl.lock);
- while (cur) {
- if (cur == user) break;
- prev = cur;
- cur = cur->next;
- }
- if (cur) {
- if (prev)
- prev->next = cur->next;
- else
- userl.users = cur->next;
- }
- ast_mutex_unlock(&userl.lock);
- free(user);
- }
- if (gH323Debug)
- ast_verbose("+++ ooh323_delete_user\n");
- } */
- void ooh323_delete_peer(struct ooh323_peer *peer)
- {
- struct ooh323_peer *prev = NULL, *cur = NULL;
- if (gH323Debug)
- ast_verbose("--- ooh323_delete_peer\n");
- if (peer) {
- cur = peerl.peers;
- ast_mutex_lock(&peerl.lock);
- while(cur) {
- if(cur==peer) break;
- prev = cur;
- cur = cur->next;
- }
- if (cur) {
- if(prev)
- prev->next = cur->next;
- else
- peerl.peers = cur->next;
- }
- ast_mutex_unlock(&peerl.lock);
- if(peer->h323id) free(peer->h323id);
- if(peer->email) free(peer->email);
- if(peer->url) free(peer->url);
- if(peer->e164) free(peer->e164);
- free(peer);
- }
- if (gH323Debug)
- ast_verbose("+++ ooh323_delete_peer\n");
- }
- static struct ooh323_user *build_user(const char *name, struct ast_variable *v)
- {
- struct ooh323_user *user = NULL;
- if (gH323Debug)
- ast_verbose("--- build_user\n");
- user = ast_calloc(1,sizeof(struct ooh323_user));
- if (user) {
- memset(user, 0, sizeof(struct ooh323_user));
- ast_mutex_init(&user->lock);
- ast_copy_string(user->name, name, sizeof(user->name));
- user->capability = gCapability;
- memcpy(&user->prefs, &gPrefs, sizeof(user->prefs));
- user->rtptimeout = gRTPTimeout;
- user->dtmfmode = gDTMFMode;
- user->dtmfcodec = gDTMFCodec;
- user->t38support = gT38Support;
- user->faststart = gFastStart;
- user->h245tunneling = gTunneling;
- user->g729onlyA = g729onlyA;
- /* set default context */
- ast_copy_string(user->context, gContext, sizeof(user->context));
- ast_copy_string(user->accountcode, gAccountcode, sizeof(user->accountcode));
- user->amaflags = gAMAFLAGS;
- while (v) {
- if (!strcasecmp(v->name, "context")) {
- ast_copy_string(user->context, v->value, sizeof(user->context));
- } else if (!strcasecmp(v->name, "incominglimit")) {
- user->incominglimit = atoi(v->value);
- if (user->incominglimit < 0)
- user->incominglimit = 0;
- } else if (!strcasecmp(v->name, "accountcode")) {
- strncpy(user->accountcode, v->value,
- sizeof(user->accountcode)-1);
- } else if (!strcasecmp(v->name, "roundtrip")) {
- sscanf(v->value, "%d,%d", &user->rtdrcount, &user->rtdrinterval);
- } else if (!strcasecmp(v->name, "faststart")) {
- user->faststart = ast_true(v->value);
- } else if (!strcasecmp(v->name, "h245tunneling")) {
- user->h245tunneling = ast_true(v->value);
- } else if (!strcasecmp(v->name, "g729onlyA")) {
- user->g729onlyA = ast_true(v->value);
- } else if (!strcasecmp(v->name, "rtptimeout")) {
- user->rtptimeout = atoi(v->value);
- if (user->rtptimeout < 0)
- user->rtptimeout = gRTPTimeout;
- } else if (!strcasecmp(v->name, "rtpmask")) {
- if ((user->rtpmask = malloc(sizeof(struct OOH323Regex))) &&
- (regcomp(&user->rtpmask->regex, v->value, REG_EXTENDED)
- == 0)) {
- ast_mutex_init(&user->rtpmask->lock);
- user->rtpmask->inuse = 1;
- ast_copy_string(user->rtpmaskstr, v->value,
- sizeof(user->rtpmaskstr));
- } else user->rtpmask = NULL;
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&user->prefs,
- &user->capability, v->value, 0);
- } else if (!strcasecmp(v->name, "allow")) {
- const char* tcodecs = v->value;
- if (!strcasecmp(v->value, "all")) {
- tcodecs = "ulaw,alaw,g729,g723,gsm";
- }
- ast_parse_allow_disallow(&user->prefs,
- &user->capability, tcodecs, 1);
- } else if (!strcasecmp(v->name, "amaflags")) {
- user->amaflags = ast_cdr_amaflags2int(v->value);
- } else if (!strcasecmp(v->name, "ip")) {
- strncpy(user->mIP, v->value, sizeof(user->mIP)-1);
- user->mUseIP = 1;
- } else if (!strcasecmp(v->name, "host")) {
- strncpy(user->mIP, v->value, sizeof(user->mIP)-1);
- user->mUseIP = 1;
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- if (!strcasecmp(v->value, "rfc2833"))
- user->dtmfmode = H323_DTMF_RFC2833;
- if (!strcasecmp(v->value, "cisco"))
- user->dtmfmode = H323_DTMF_CISCO;
- else if (!strcasecmp(v->value, "q931keypad"))
- user->dtmfmode = H323_DTMF_Q931;
- else if (!strcasecmp(v->value, "h245alphanumeric"))
- user->dtmfmode = H323_DTMF_H245ALPHANUMERIC;
- else if (!strcasecmp(v->value, "h245signal"))
- user->dtmfmode = H323_DTMF_H245SIGNAL;
- else if (!strcasecmp(v->value, "inband"))
- user->dtmfmode = H323_DTMF_INBAND;
- } else if (!strcasecmp(v->name, "relaxdtmf")) {
- user->dtmfmode |= ast_true(v->value) ? H323_DTMF_INBANDRELAX : 0;
- } else if (!strcasecmp(v->name, "dtmfcodec") && atoi(v->value)) {
- user->dtmfcodec = atoi(v->value);
- } else if (!strcasecmp(v->name, "t38support")) {
- if (!strcasecmp(v->value, "disabled"))
- user->t38support = T38_DISABLED;
- if (!strcasecmp(v->value, "no"))
- user->t38support = T38_DISABLED;
- else if (!strcasecmp(v->value, "faxgw"))
- user->t38support = T38_FAXGW;
- else if (!strcasecmp(v->value, "yes"))
- user->t38support = T38_ENABLED;
- }
- v = v->next;
- }
- }
- if (gH323Debug)
- ast_verbose("+++ build_user\n");
- return user;
- }
- static struct ooh323_peer *build_peer(const char *name, struct ast_variable *v, int friend_type)
- {
- struct ooh323_peer *peer = NULL;
- if (gH323Debug)
- ast_verbose("--- build_peer\n");
- peer = ast_calloc(1, sizeof(*peer));
- if (peer) {
- memset(peer, 0, sizeof(struct ooh323_peer));
- ast_mutex_init(&peer->lock);
- ast_copy_string(peer->name, name, sizeof(peer->name));
- peer->capability = gCapability;
- memcpy(&peer->prefs, &gPrefs, sizeof(peer->prefs));
- peer->rtptimeout = gRTPTimeout;
- ast_copy_string(peer->accountcode, gAccountcode, sizeof(peer->accountcode));
- peer->amaflags = gAMAFLAGS;
- peer->dtmfmode = gDTMFMode;
- peer->dtmfcodec = gDTMFCodec;
- peer->t38support = gT38Support;
- peer->faststart = gFastStart;
- peer->h245tunneling = gTunneling;
- peer->g729onlyA = g729onlyA;
- peer->port = 1720;
- if (0 == friend_type) {
- peer->mFriend = 1;
- }
- while (v) {
- if (!strcasecmp(v->name, "h323id")) {
- if (!(peer->h323id = ast_strdup(v->value))) {
- ast_log(LOG_ERROR, "Could not allocate memory for h323id of "
- "peer %s\n", name);
- ooh323_delete_peer(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "e164")) {
- if (!(peer->e164 = ast_strdup(v->value))) {
- ast_log(LOG_ERROR, "Could not allocate memory for e164 of "
- "peer %s\n", name);
- ooh323_delete_peer(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "email")) {
- if (!(peer->email = ast_strdup(v->value))) {
- ast_log(LOG_ERROR, "Could not allocate memory for email of "
- "peer %s\n", name);
- ooh323_delete_peer(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "url")) {
- if (!(peer->url = ast_strdup(v->value))) {
- ast_log(LOG_ERROR, "Could not allocate memory for h323id of "
- "peer %s\n", name);
- ooh323_delete_peer(peer);
- return NULL;
- }
- } else if (!strcasecmp(v->name, "port")) {
- peer->port = atoi(v->value);
- } else if (!strcasecmp(v->name, "ip")) {
- ast_copy_string(peer->ip, v->value, sizeof(peer->ip));
- } else if (!strcasecmp(v->name, "host")) {
- ast_copy_string(peer->ip, v->value, sizeof(peer->ip));
- } else if (!strcasecmp(v->name, "outgoinglimit")) {
- peer->outgoinglimit = atoi(v->value);
- if (peer->outgoinglimit < 0)
- peer->outgoinglimit = 0;
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(peer->accountcode, v->value, sizeof(peer->accountcode));
- } else if (!strcasecmp(v->name, "faststart")) {
- peer->faststart = ast_true(v->value);
- } else if (!strcasecmp(v->name, "h245tunneling")) {
- peer->h245tunneling = ast_true(v->value);
- } else if (!strcasecmp(v->name, "g729onlyA")) {
- peer->g729onlyA = ast_true(v->value);
- } else if (!strcasecmp(v->name, "rtptimeout")) {
- peer->rtptimeout = atoi(v->value);
- if(peer->rtptimeout < 0)
- peer->rtptimeout = gRTPTimeout;
- } else if (!strcasecmp(v->name, "rtpmask")) {
- if ((peer->rtpmask = malloc(sizeof(struct OOH323Regex))) &&
- (regcomp(&peer->rtpmask->regex, v->value, REG_EXTENDED)
- == 0)) {
- ast_mutex_init(&peer->rtpmask->lock);
- peer->rtpmask->inuse = 1;
- ast_copy_string(peer->rtpmaskstr, v->value,
- sizeof(peer->rtpmaskstr));
- } else peer->rtpmask = NULL;
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&peer->prefs, &peer->capability,
- v->value, 0);
- } else if (!strcasecmp(v->name, "allow")) {
- const char* tcodecs = v->value;
- if (!strcasecmp(v->value, "all")) {
- tcodecs = "ulaw,alaw,g729,g723,gsm";
- }
- ast_parse_allow_disallow(&peer->prefs, &peer->capability,
- tcodecs, 1);
- } else if (!strcasecmp(v->name, "amaflags")) {
- peer->amaflags = ast_cdr_amaflags2int(v->value);
- } else if (!strcasecmp(v->name, "roundtrip")) {
- sscanf(v->value, "%d,%d", &peer->rtdrcount, &peer->rtdrinterval);
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- if (!strcasecmp(v->value, "rfc2833"))
- peer->dtmfmode = H323_DTMF_RFC2833;
- if (!strcasecmp(v->value, "cisco"))
- peer->dtmfmode = H323_DTMF_CISCO;
- else if (!strcasecmp(v->value, "q931keypad"))
- peer->dtmfmode = H323_DTMF_Q931;
- else if (!strcasecmp(v->value, "h245alphanumeric"))
- peer->dtmfmode = H323_DTMF_H245ALPHANUMERIC;
- else if (!strcasecmp(v->value, "h245signal"))
- peer->dtmfmode = H323_DTMF_H245SIGNAL;
- else if (!strcasecmp(v->value, "inband"))
- peer->dtmfmode = H323_DTMF_INBAND;
- } else if (!strcasecmp(v->name, "relaxdtmf")) {
- peer->dtmfmode |= ast_true(v->value) ? H323_DTMF_INBANDRELAX : 0;
- } else if (!strcasecmp(v->name, "dtmfcodec") && atoi(v->value)) {
- peer->dtmfcodec = atoi(v->value);
- } else if (!strcasecmp(v->name, "t38support")) {
- if (!strcasecmp(v->value, "disabled"))
- peer->t38support = T38_DISABLED;
- if (!strcasecmp(v->value, "no"))
- peer->t38support = T38_DISABLED;
- else if (!strcasecmp(v->value, "faxgw"))
- peer->t38support = T38_FAXGW;
- else if (!strcasecmp(v->value, "yes"))
- peer->t38support = T38_ENABLED;
- }
- v = v->next;
- }
- }
- if (gH323Debug)
- ast_verbose("+++ build_peer\n");
- return peer;
- }
- static int ooh323_do_reload(void)
- {
- if (gH323Debug) {
- ast_verbose("--- ooh323_do_reload\n");
- }
- reload_config(1);
- if (gH323Debug) {
- ast_verbose("+++ ooh323_do_reload\n");
- }
- return 0;
- }
- /*--- h323_reload: Force reload of module from cli ---*/
- char *handle_cli_ooh323_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 reload";
- e->usage =
- "Usage: ooh323 reload\n"
- " Reload OOH323 config.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc != 2)
- return CLI_SHOWUSAGE;
- if (gH323Debug)
- ast_verbose("--- ooh323_reload\n");
- ast_mutex_lock(&h323_reload_lock);
- if (h323_reloading) {
- ast_verbose("Previous OOH323 reload not yet done\n");
- } else {
- h323_reloading = 1;
- }
- ast_mutex_unlock(&h323_reload_lock);
- restart_monitor();
- if (gH323Debug)
- ast_verbose("+++ ooh323_reload\n");
- return 0;
- }
- int reload_config(int reload)
- {
- int format;
- struct ooAliases *pNewAlias = NULL, *cur, *prev;
- struct ast_config *cfg;
- struct ast_variable *v;
- struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
- struct ooh323_user *user = NULL;
- struct ooh323_peer *peer = NULL;
- char *cat;
- const char *utype;
- if (gH323Debug)
- ast_verbose("--- reload_config\n");
- cfg = ast_config_load((char*)config, config_flags);
- /* We *must* have a config file otherwise stop immediately */
- if (!cfg) {
- ast_log(LOG_NOTICE, "Unable to load config %s, OOH323 disabled\n", config);
- return 1;
- } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
- return RESULT_SUCCESS;
- if (reload) {
- delete_users();
- delete_peers();
- if (gH323Debug) {
- ast_verbose(" reload_config - Freeing up alias list\n");
- }
- cur = gAliasList;
- while (cur) {
- prev = cur;
- cur = cur->next;
- free(prev->value);
- free(prev);
- }
- gAliasList = NULL;
- }
- /* Inintialize everything to default */
- strcpy(gLogFile, DEFAULT_LOGFILE);
- gPort = 1720;
- gIP[0] = '\0';
- strcpy(gCallerID, DEFAULT_H323ID);
- gCapability = AST_FORMAT_ALAW;
- memset(&gPrefs, 0, sizeof(struct ast_codec_pref));
- gDTMFMode = H323_DTMF_RFC2833;
- gDTMFCodec = 101;
- gT38Support = T38_FAXGW;
- gTRCLVL = OOTRCLVLERR;
- gRasGkMode = RasNoGatekeeper;
- gGatekeeper[0] = '\0';
- gRTPTimeout = 60;
- gRTDRInterval = 0;
- gRTDRCount = 0;
- strcpy(gAccountcode, DEFAULT_H323ACCNT);
- gFastStart = 1;
- gTunneling = 1;
- gTOS = 0;
- strcpy(gContext, DEFAULT_CONTEXT);
- gAliasList = NULL;
- gMediaWaitForConnect = 0;
- ooconfig.mTCPPortStart = 12030;
- ooconfig.mTCPPortEnd = 12230;
- memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
- v = ast_variable_browse(cfg, "general");
- while (v) {
- if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
- v = v->next;
- continue;
- }
-
- if (!strcasecmp(v->name, "port")) {
- gPort = (int)strtol(v->value, NULL, 10);
- } else if (!strcasecmp(v->name, "bindaddr")) {
- ast_copy_string(gIP, v->value, sizeof(gIP));
- } else if (!strcasecmp(v->name, "h225portrange")) {
- char* endlimit = 0;
- char temp[512];
- ast_copy_string(temp, v->value, sizeof(temp));
- endlimit = strchr(temp, ',');
- if (endlimit) {
- *endlimit = '\0';
- endlimit++;
- ooconfig.mTCPPortStart = atoi(temp);
- ooconfig.mTCPPortEnd = atoi(endlimit);
- } else {
- ast_log(LOG_ERROR, "h225portrange: Invalid format, separate port range with \",\"\n");
- }
- } else if (!strcasecmp(v->name, "gateway")) {
- gIsGateway = ast_true(v->value);
- } else if (!strcasecmp(v->name, "faststart")) {
- gFastStart = ast_true(v->value);
- if (gFastStart)
- ooH323EpEnableFastStart();
- else
- ooH323EpDisableFastStart();
- } else if (!strcasecmp(v->name, "mediawaitforconnect")) {
- gMediaWaitForConnect = ast_true(v->value);
- if (gMediaWaitForConnect)
- ooH323EpEnableMediaWaitForConnect();
- else
- ooH323EpDisableMediaWaitForConnect();
- } else if (!strcasecmp(v->name, "h245tunneling")) {
- gTunneling = ast_true(v->value);
- if (gTunneling)
- ooH323EpEnableH245Tunneling();
- else
- ooH323EpDisableH245Tunneling();
- } else if (!strcasecmp(v->name, "g729onlyA")) {
- g729onlyA = ast_true(v->value);
- } else if (!strcasecmp(v->name, "roundtrip")) {
- sscanf(v->value, "%d,%d", &gRTDRCount, &gRTDRInterval);
- } else if (!strcasecmp(v->name, "trybemaster")) {
- gBeMaster = ast_true(v->value);
- if (gBeMaster)
- ooH323EpTryBeMaster(1);
- else
- ooH323EpTryBeMaster(0);
- } else if (!strcasecmp(v->name, "h323id")) {
- pNewAlias = malloc(sizeof(struct ooAliases));
- if (!pNewAlias) {
- ast_log(LOG_ERROR, "Failed to allocate memory for h323id alias\n");
- return 1;
- }
- if (gAliasList == NULL) { /* first h323id - set as callerid if callerid is not set */
- ast_copy_string(gCallerID, v->value, sizeof(gCallerID));
- }
- pNewAlias->type = T_H225AliasAddress_h323_ID;
- pNewAlias->value = strdup(v->value);
- pNewAlias->next = gAliasList;
- gAliasList = pNewAlias;
- pNewAlias = NULL;
- } else if (!strcasecmp(v->name, "e164")) {
- pNewAlias = malloc(sizeof(struct ooAliases));
- if (!pNewAlias) {
- ast_log(LOG_ERROR, "Failed to allocate memory for e164 alias\n");
- return 1;
- }
- pNewAlias->type = T_H225AliasAddress_dialedDigits;
- pNewAlias->value = strdup(v->value);
- pNewAlias->next = gAliasList;
- gAliasList = pNewAlias;
- pNewAlias = NULL;
- } else if (!strcasecmp(v->name, "email")) {
- pNewAlias = malloc(sizeof(struct ooAliases));
- if (!pNewAlias) {
- ast_log(LOG_ERROR, "Failed to allocate memory for email alias\n");
- return 1;
- }
- pNewAlias->type = T_H225AliasAddress_email_ID;
- pNewAlias->value = strdup(v->value);
- pNewAlias->next = gAliasList;
- gAliasList = pNewAlias;
- pNewAlias = NULL;
- } else if (!strcasecmp(v->name, "t35country")) {
- t35countrycode = atoi(v->value);
- } else if (!strcasecmp(v->name, "t35extensions")) {
- t35extensions = atoi(v->value);
- } else if (!strcasecmp(v->name, "manufacturer")) {
- manufacturer = atoi(v->value);
- } else if (!strcasecmp(v->name, "vendorid")) {
- ast_copy_string(vendor, v->value, sizeof(vendor));
- } else if (!strcasecmp(v->name, "versionid")) {
- ast_copy_string(version, v->value, sizeof(version));
- } else if (!strcasecmp(v->name, "callerid")) {
- ast_copy_string(gCallerID, v->value, sizeof(gCallerID));
- } else if (!strcasecmp(v->name, "incominglimit")) {
- gIncomingLimit = atoi(v->value);
- } else if (!strcasecmp(v->name, "outgoinglimit")) {
- gOutgoingLimit = atoi(v->value);
- } else if (!strcasecmp(v->name, "gatekeeper")) {
- if (!strcasecmp(v->value, "DISABLE")) {
- gRasGkMode = RasNoGatekeeper;
- } else if (!strcasecmp(v->value, "DISCOVER")) {
- gRasGkMode = RasDiscoverGatekeeper;
- } else {
- gRasGkMode = RasUseSpecificGatekeeper;
- strncpy(gGatekeeper, v->value, sizeof(gGatekeeper)-1);
- }
- } else if (!strcasecmp(v->name, "logfile")) {
- strncpy(gLogFile, v->value, sizeof(gLogFile)-1);
- } else if (!strcasecmp(v->name, "context")) {
- strncpy(gContext, v->value, sizeof(gContext)-1);
- ast_verbose(VERBOSE_PREFIX_3 " == Setting default context to %s\n",
- gContext);
- } else if (!strcasecmp(v->name, "rtptimeout")) {
- gRTPTimeout = atoi(v->value);
- if (gRTPTimeout <= 0)
- gRTPTimeout = 60;
- } else if (!strcasecmp(v->name, "tos")) {
- if (sscanf(v->value, "%30i", &format) == 1)
- gTOS = format & 0xff;
- else if (!strcasecmp(v->value, "lowdelay"))
- gTOS = IPTOS_LOWDELAY;
- else if (!strcasecmp(v->value, "throughput"))
- gTOS = IPTOS_THROUGHPUT;
- else if (!strcasecmp(v->value, "reliability"))
- gTOS = IPTOS_RELIABILITY;
- else if (!strcasecmp(v->value, "mincost"))
- gTOS = IPTOS_MINCOST;
- else if (!strcasecmp(v->value, "none"))
- gTOS = 0;
- else
- ast_log(LOG_WARNING, "Invalid tos value at line %d, should be "
- "'lowdelay', 'throughput', 'reliability', "
- "'mincost', or 'none'\n", v->lineno);
- } else if (!strcasecmp(v->name, "amaflags")) {
- gAMAFLAGS = ast_cdr_amaflags2int(v->value);
- } else if (!strcasecmp(v->name, "accountcode")) {
- ast_copy_string(gAccountcode, v->value, sizeof(gAccountcode));
- } else if (!strcasecmp(v->name, "disallow")) {
- ast_parse_allow_disallow(&gPrefs, &gCapability, v->value, 0);
- } else if (!strcasecmp(v->name, "allow")) {
- const char* tcodecs = v->value;
- if (!strcasecmp(v->value, "all")) {
- tcodecs = "ulaw,alaw,g729,g723,gsm";
- }
- ast_parse_allow_disallow(&gPrefs, &gCapability, tcodecs, 1);
- } else if (!strcasecmp(v->name, "dtmfmode")) {
- if (!strcasecmp(v->value, "inband"))
- gDTMFMode = H323_DTMF_INBAND;
- else if (!strcasecmp(v->value, "rfc2833"))
- gDTMFMode = H323_DTMF_RFC2833;
- else if (!strcasecmp(v->value, "cisco"))
- gDTMFMode = H323_DTMF_CISCO;
- else if (!strcasecmp(v->value, "q931keypad"))
- gDTMFMode = H323_DTMF_Q931;
- else if (!strcasecmp(v->value, "h245alphanumeric"))
- gDTMFMode = H323_DTMF_H245ALPHANUMERIC;
- else if (!strcasecmp(v->value, "h245signal"))
- gDTMFMode = H323_DTMF_H245SIGNAL;
- else {
- ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n",
- v->value);
- gDTMFMode = H323_DTMF_RFC2833;
- }
- } else if (!strcasecmp(v->name, "relaxdtmf")) {
- gDTMFMode |= ast_true(v->value) ? H323_DTMF_INBANDRELAX : 0;
- } else if (!strcasecmp(v->name, "dtmfcodec") && atoi(v->value)) {
- gDTMFCodec = atoi(v->value);
- } else if (!strcasecmp(v->name, "t38support")) {
- if (!strcasecmp(v->value, "disabled"))
- gT38Support = T38_DISABLED;
- if (!strcasecmp(v->value, "no"))
- gT38Support = T38_DISABLED;
- else if (!strcasecmp(v->value, "faxgw"))
- gT38Support = T38_FAXGW;
- else if (!strcasecmp(v->value, "yes"))
- gT38Support = T38_ENABLED;
- } else if (!strcasecmp(v->name, "tracelevel")) {
- gTRCLVL = atoi(v->value);
- ooH323EpSetTraceLevel(gTRCLVL);
- }
- v = v->next;
- }
-
- for (cat = ast_category_browse(cfg, NULL); cat; cat = ast_category_browse(cfg, cat)) {
- if (strcasecmp(cat, "general")) {
- int friend_type = 0;
- utype = ast_variable_retrieve(cfg, cat, "type");
- if (utype) {
- friend_type = strcasecmp(utype, "friend");
- if (!strcmp(utype, "user") || 0 == friend_type) {
- user = build_user(cat, ast_variable_browse(cfg, cat));
- if (user) {
- ast_mutex_lock(&userl.lock);
- user->next = userl.users;
- userl.users = user;
- ast_mutex_unlock(&userl.lock);
- } else {
- ast_log(LOG_WARNING, "Failed to build user %s\n", cat);
- }
- }
- if (!strcasecmp(utype, "peer") || 0 == friend_type) {
- peer = build_peer(cat, ast_variable_browse(cfg, cat), friend_type);
- if (peer) {
- ast_mutex_lock(&peerl.lock);
- peer->next = peerl.peers;
- peerl.peers = peer;
- ast_mutex_unlock(&peerl.lock);
- } else {
- ast_log(LOG_WARNING, "Failed to build peer %s\n", cat);
- }
- }
- }
- }
- }
- ast_config_destroy(cfg);
- /* Determine ip address if neccessary */
- if (ast_strlen_zero(gIP)) {
- ooGetLocalIPAddress(gIP);
- if (!strcmp(gIP, "127.0.0.1")) {
- ast_log(LOG_NOTICE, "Failed to determine local ip address. Please "
- "specify it in ooh323.conf. OOH323 Disabled\n");
- return 1;
- }
- }
- if (gH323Debug)
- ast_verbose("+++ reload_config\n");
- return 0;
- }
- static char *handle_cli_ooh323_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- char ip_port[30];
- struct ooh323_peer *prev = NULL, *peer = NULL;
-
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 show peer";
- e->usage =
- "Usage: ooh323 show peer <name>\n"
- " List details of specific OOH323 peer.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc != 4)
- return CLI_SHOWUSAGE;
-
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
- while (peer) {
- ast_mutex_lock(&peer->lock);
- if(!strcmp(peer->name, a->argv[3]))
- break;
- else {
- prev = peer;
- peer = peer->next;
- ast_mutex_unlock(&prev->lock);
- }
- }
- if (peer) {
- sprintf(ip_port, "%s:%d", peer->ip, peer->port);
- ast_cli(a->fd, "%-15.15s%s\n", "Name: ", peer->name);
- ast_cli(a->fd, "%s:%s,%s\n", "FastStart/H.245 Tunneling", peer->faststart?"yes":"no",
- peer->h245tunneling?"yes":"no");
- ast_cli(a->fd, "%-15.15s%s", "Format Prefs: ", "(");
- print_codec_to_cli(a->fd, &peer->prefs);
- ast_cli(a->fd, ")\n");
- ast_cli(a->fd, "%-15.15s", "DTMF Mode: ");
- if (peer->dtmfmode & H323_DTMF_CISCO) {
- ast_cli(a->fd, "%s\n", "cisco");
- ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", peer->dtmfcodec);
- } else if (peer->dtmfmode & H323_DTMF_RFC2833) {
- ast_cli(a->fd, "%s\n", "rfc2833");
- ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", peer->dtmfcodec);
- } else if (peer->dtmfmode & H323_DTMF_Q931)
- ast_cli(a->fd, "%s\n", "q931keypad");
- else if (peer->dtmfmode & H323_DTMF_H245ALPHANUMERIC)
- ast_cli(a->fd, "%s\n", "h245alphanumeric");
- else if (peer->dtmfmode & H323_DTMF_H245SIGNAL)
- ast_cli(a->fd, "%s\n", "h245signal");
- else if (peer->dtmfmode & H323_DTMF_INBAND && peer->dtmfmode & H323_DTMF_INBANDRELAX)
- ast_cli(a->fd, "%s\n", "inband-relaxed");
- else if (peer->dtmfmode & H323_DTMF_INBAND)
- ast_cli(a->fd, "%s\n", "inband");
- else
- ast_cli(a->fd, "%s\n", "unknown");
- ast_cli(a->fd,"%-15s", "T.38 Mode: ");
- if (peer->t38support == T38_DISABLED)
- ast_cli(a->fd, "%s\n", "disabled");
- else if (peer->t38support == T38_FAXGW)
- ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
- ast_cli(a->fd, "%-15.15s%s\n", "AccountCode: ", peer->accountcode);
- ast_cli(a->fd, "%-15.15s%s\n", "AMA flags: ",
- ast_cdr_flags2str(peer->amaflags));
- ast_cli(a->fd, "%-15.15s%s\n", "IP:Port: ", ip_port);
- ast_cli(a->fd, "%-15.15s%d\n", "OutgoingLimit: ", peer->outgoinglimit);
- ast_cli(a->fd, "%-15.15s%d\n", "rtptimeout: ", peer->rtptimeout);
- if (peer->rtpmaskstr[0])
- ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", peer->rtpmaskstr);
- if (peer->rtdrcount && peer->rtdrinterval)
- ast_cli(a->fd, "%-15.15s%d,%d\n", "RoundTrip: ", peer->rtdrcount, peer->rtdrinterval);
- ast_mutex_unlock(&peer->lock);
- } else {
- ast_cli(a->fd, "Peer %s not found\n", a->argv[3]);
- ast_cli(a->fd, "\n");
- }
- ast_mutex_unlock(&peerl.lock);
- return CLI_SUCCESS;
- }
- static char *handle_cli_ooh323_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- struct ooh323_peer *prev = NULL, *peer = NULL;
- char formats[FORMAT_STRING_SIZE];
- char ip_port[30];
- #define FORMAT "%-15.15s %-15.15s %-23.23s %-s\n"
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 show peers";
- e->usage =
- "Usage: ooh323 show peers\n"
- " Lists all known OOH323 peers.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc != 3)
- return CLI_SHOWUSAGE;
- ast_cli(a->fd, FORMAT, "Name", "Accountcode", "ip:port", "Formats");
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
- while (peer) {
- ast_mutex_lock(&peer->lock);
- snprintf(ip_port, sizeof(ip_port), "%s:%d", peer->ip, peer->port);
- ast_cli(a->fd, FORMAT, peer->name,
- peer->accountcode,
- ip_port,
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,peer->capability));
- prev = peer;
- peer = peer->next;
- ast_mutex_unlock(&prev->lock);
- }
- ast_mutex_unlock(&peerl.lock);
- #undef FORMAT
- return CLI_SUCCESS;
- }
- /*! \brief Print codec list from preference to CLI/manager */
- static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
- {
- int x, codec;
- for (x = 0; x < 32; x++) {
- codec = ast_codec_pref_index(pref, x);
- if (!codec)
- break;
- ast_cli(fd, "%s", ast_getformatname(codec));
- ast_cli(fd, ":%d", pref->framing[x]);
- if (x < 31 && ast_codec_pref_index(pref, x + 1))
- ast_cli(fd, ",");
- }
- if (!x)
- ast_cli(fd, "none");
- }
- static char *handle_cli_ooh323_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- struct ooh323_user *prev = NULL, *user = NULL;
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 show user";
- e->usage =
- "Usage: ooh323 show user <name>\n"
- " List details of specific OOH323 user.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc != 4)
- return CLI_SHOWUSAGE;
- ast_mutex_lock(&userl.lock);
- user = userl.users;
- while (user) {
- ast_mutex_lock(&user->lock);
- if(!strcmp(user->name, a->argv[3])) {
- break;
- } else {
- prev = user;
- user = user->next;
- ast_mutex_unlock(&prev->lock);
- }
- }
- if (user) {
- ast_cli(a->fd, "%-15.15s%s\n", "Name: ", user->name);
- ast_cli(a->fd, "%s:%s,%s\n", "FastStart/H.245 Tunneling", user->faststart?"yes":"no",
- user->h245tunneling?"yes":"no");
- ast_cli(a->fd, "%-15.15s%s", "Format Prefs: ", "(");
- print_codec_to_cli(a->fd, &user->prefs);
- ast_cli(a->fd, ")\n");
- ast_cli(a->fd, "%-15.15s", "DTMF Mode: ");
- if (user->dtmfmode & H323_DTMF_CISCO) {
- ast_cli(a->fd, "%s\n", "cisco");
- ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", user->dtmfcodec);
- } else if (user->dtmfmode & H323_DTMF_RFC2833) {
- ast_cli(a->fd, "%s\n", "rfc2833");
- ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", user->dtmfcodec);
- } else if (user->dtmfmode & H323_DTMF_Q931)
- ast_cli(a->fd, "%s\n", "q931keypad");
- else if (user->dtmfmode & H323_DTMF_H245ALPHANUMERIC)
- ast_cli(a->fd, "%s\n", "h245alphanumeric");
- else if (user->dtmfmode & H323_DTMF_H245SIGNAL)
- ast_cli(a->fd, "%s\n", "h245signal");
- else if (user->dtmfmode & H323_DTMF_INBAND && user->dtmfmode & H323_DTMF_INBANDRELAX)
- ast_cli(a->fd, "%s\n", "inband-relaxed");
- else if (user->dtmfmode & H323_DTMF_INBAND)
- ast_cli(a->fd, "%s\n", "inband");
- else
- ast_cli(a->fd, "%s\n", "unknown");
- ast_cli(a->fd,"%-15s", "T.38 Mode: ");
- if (user->t38support == T38_DISABLED)
- ast_cli(a->fd, "%s\n", "disabled");
- else if (user->t38support == T38_FAXGW)
- ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
- ast_cli(a->fd, "%-15.15s%s\n", "AccountCode: ", user->accountcode);
- ast_cli(a->fd, "%-15.15s%s\n", "AMA flags: ",
- ast_cdr_flags2str(user->amaflags));
- ast_cli(a->fd, "%-15.15s%s\n", "Context: ", user->context);
- ast_cli(a->fd, "%-15.15s%d\n", "IncomingLimit: ", user->incominglimit);
- ast_cli(a->fd, "%-15.15s%d\n", "InUse: ", user->inUse);
- ast_cli(a->fd, "%-15.15s%d\n", "rtptimeout: ", user->rtptimeout);
- if (user->rtpmaskstr[0])
- ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", user->rtpmaskstr);
- ast_mutex_unlock(&user->lock);
- if (user->rtdrcount && user->rtdrinterval)
- ast_cli(a->fd, "%-15.15s%d,%d\n", "RoundTrip: ", user->rtdrcount, user->rtdrinterval);
- } else {
- ast_cli(a->fd, "User %s not found\n", a->argv[3]);
- ast_cli(a->fd, "\n");
- }
- ast_mutex_unlock(&userl.lock);
- return CLI_SUCCESS;
- }
- static char *handle_cli_ooh323_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- struct ooh323_user *prev = NULL, *user = NULL;
- char formats[FORMAT_STRING_SIZE];
- #define FORMAT1 "%-15.15s %-15.15s %-15.15s %-s\n"
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 show users";
- e->usage =
- "Usage: ooh323 show users \n"
- " Lists all known OOH323 users.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc != 3)
- return CLI_SHOWUSAGE;
- ast_cli(a->fd, FORMAT1, "Username", "Accountcode", "Context", "Formats");
- ast_mutex_lock(&userl.lock);
- user = userl.users;
- while(user)
- {
- ast_mutex_lock(&user->lock);
- ast_cli(a->fd, FORMAT1, user->name,
- user->accountcode, user->context,
- ast_getformatname_multiple(formats, FORMAT_STRING_SIZE, user->capability));
- prev = user;
- user = user->next;
- ast_mutex_unlock(&prev->lock);
- }
- ast_mutex_unlock(&userl.lock);
- #undef FORMAT1
- return RESULT_SUCCESS;
- }
- static char *handle_cli_ooh323_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 set debug [off]";
- e->usage =
- "Usage: ooh323 set debug [off]\n"
- " Enables/Disables debugging of OOH323 channel driver\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc < 3 || a->argc > 4)
- return CLI_SHOWUSAGE;
- if (a->argc == 4 && strcasecmp(a->argv[3], "off"))
- return CLI_SHOWUSAGE;
- gH323Debug = (a->argc == 4) ? FALSE : TRUE;
- ast_cli(a->fd, "OOH323 Debugging %s\n", gH323Debug ? "Enabled" : "Disabled");
- return CLI_SUCCESS;
- }
- #if 0
- static int ooh323_show_channels(int fd, int argc, char *argv[])
- {
- return RESULT_SUCCESS;
- }
- #endif
- static char *handle_cli_ooh323_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
- {
- char value[FORMAT_STRING_SIZE];
- ooAliases *pAlias = NULL, *pAliasNext = NULL;;
- switch (cmd) {
- case CLI_INIT:
- e->command = "ooh323 show config";
- e->usage =
- "Usage: ooh323 show config\n"
- " Shows global configuration of H.323 channel driver\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc != 3)
- return CLI_SHOWUSAGE;
- ast_cli(a->fd, "\nObjective Open H.323 Channel Driver's Config:\n");
- snprintf(value, sizeof(value), "%s:%d", gIP, gPort);
- ast_cli(a->fd, "%-20s%s\n", "IP:Port: ", value);
- ast_cli(a->fd, "%-20s%d-%d\n", "H.225 port range: ",
- ooconfig.mTCPPortStart, ooconfig.mTCPPortEnd);
- ast_cli(a->fd, "%-20s%s\n", "FastStart", gFastStart?"yes":"no");
- ast_cli(a->fd, "%-20s%s\n", "Tunneling", gTunneling?"yes":"no");
- ast_cli(a->fd, "%-20s%s\n", "CallerId", gCallerID);
- ast_cli(a->fd, "%-20s%s\n", "MediaWaitForConnect",
- gMediaWaitForConnect?"yes":"no");
- #if (0)
- extern OOH323EndPoint gH323ep;
- ast_cli(a->fd, "%-20s%s\n", "FASTSTART",
- (OO_TESTFLAG(gH323ep.flags, OO_M_FASTSTART) != 0) ? "yes" : "no");
- ast_cli(a->fd, "%-20s%s\n", "TUNNELING",
- (OO_TESTFLAG(gH323ep.flags, OO_M_TUNNELING) != 0) ? "yes" : "no");
- ast_cli(a->fd, "%-20s%s\n", "MEDIAWAITFORCONN",
- (OO_TESTFLAG(gH323ep.flags, OO_M_MEDIAWAITFORCONN) != 0) ? "yes" : "no");
- #endif
- if (gRasGkMode == RasNoGatekeeper)
- snprintf(value, sizeof(value), "%s", "No Gatekeeper");
- else if (gRasGkMode == RasDiscoverGatekeeper)
- snprintf(value, sizeof(value), "%s", "Discover");
- else
- snprintf(value, sizeof(value), "%s", gGatekeeper);
- ast_cli(a->fd, "%-20s%s\n", "Gatekeeper:", value);
- ast_cli(a->fd, "%-20s%s\n", "H.323 LogFile:", gLogFile);
- ast_cli(a->fd, "%-20s%s\n", "Context:", gContext);
-
- ast_cli(a->fd, "%-20s%s\n", "Capability:",
- ast_getformatname_multiple(value,FORMAT_STRING_SIZE,gCapability));
- ast_cli(a->fd, "%-20s", "DTMF Mode: ");
- if (gDTMFMode & H323_DTMF_CISCO) {
- ast_cli(a->fd, "%s\n", "cisco");
- ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", gDTMFCodec);
- } else if (gDTMFMode & H323_DTMF_RFC2833) {
- ast_cli(a->fd, "%s\n", "rfc2833");
- ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", gDTMFCodec);
- } else if (gDTMFMode & H323_DTMF_Q931)
- ast_cli(a->fd, "%s\n", "q931keypad");
- else if (gDTMFMode & H323_DTMF_H245ALPHANUMERIC)
- ast_cli(a->fd, "%s\n", "h245alphanumeric");
- else if (gDTMFMode & H323_DTMF_H245SIGNAL)
- ast_cli(a->fd, "%s\n", "h245signal");
- else if (gDTMFMode & H323_DTMF_INBAND && gDTMFMode & H323_DTMF_INBANDRELAX)
- ast_cli(a->fd, "%s\n", "inband-relaxed");
- else if (gDTMFMode & H323_DTMF_INBAND)
- ast_cli(a->fd, "%s\n", "inband");
- else
- ast_cli(a->fd, "%s\n", "unknown");
- ast_cli(a->fd,"%-20s", "T.38 Mode: ");
- if (gT38Support == T38_DISABLED)
- ast_cli(a->fd, "%s\n", "disabled");
- else if (gT38Support == T38_FAXGW)
- ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
- if (gRTDRCount && gRTDRInterval)
- ast_cli(a->fd, "%-15.15s%d,%d\n", "RoundTrip: ", gRTDRCount, gRTDRInterval);
- ast_cli(a->fd, "%-20s%ld\n", "Call counter: ", callnumber);
- ast_cli(a->fd, "%-20s%s\n", "AccountCode: ", gAccountcode);
- ast_cli(a->fd, "%-20s%s\n", "AMA flags: ", ast_cdr_flags2str(gAMAFLAGS));
- pAlias = gAliasList;
- if(pAlias) {
- ast_cli(a->fd, "%-20s\n", "Aliases: ");
- }
- while (pAlias) {
- pAliasNext = pAlias->next;
- if (pAliasNext) {
- ast_cli(a->fd,"\t%-30s\t%-30s\n",pAlias->value, pAliasNext->value);
- pAlias = pAliasNext->next;
- }
- else{
- ast_cli(a->fd,"\t%-30s\n",pAlias->value);
- pAlias = pAlias->next;
- }
- }
- return CLI_SUCCESS;
- }
- static struct ast_cli_entry cli_ooh323[] = {
- AST_CLI_DEFINE(handle_cli_ooh323_set_debug, "Enable/Disable OOH323 debugging"),
- AST_CLI_DEFINE(handle_cli_ooh323_show_config, "Show details on global configuration of H.323 channel driver"),
- AST_CLI_DEFINE(handle_cli_ooh323_show_peer, "Show details on specific OOH323 peer"),
- AST_CLI_DEFINE(handle_cli_ooh323_show_peers, "Show defined OOH323 peers"),
- AST_CLI_DEFINE(handle_cli_ooh323_show_user, "Show details on specific OOH323 user"),
- AST_CLI_DEFINE(handle_cli_ooh323_show_users, "Show defined OOH323 users"),
- AST_CLI_DEFINE(handle_cli_ooh323_reload, "reload ooh323 config")
- };
- static int load_module(void)
- {
- int res;
- struct ooAliases * pNewAlias = NULL;
- struct ooh323_peer *peer = NULL;
- OOH225MsgCallbacks h225Callbacks = {0, 0, 0, 0};
- OOH323CALLBACKS h323Callbacks = {
- .onNewCallCreated = onNewCallCreated,
- .onAlerting = onAlerting,
- .onProgress = onProgress,
- .onIncomingCall = NULL,
- .onOutgoingCall = onOutgoingCall,
- .onCallEstablished = onCallEstablished,
- .onCallCleared = onCallCleared,
- .openLogicalChannels = NULL,
- .onReceivedDTMF = ooh323_onReceivedDigit,
- .onModeChanged = onModeChanged
- };
- myself = ast_module_info->self;
- h225Callbacks.onReceivedSetup = &ooh323_onReceivedSetup;
- userl.users = NULL;
- ast_mutex_init(&userl.lock);
- peerl.peers = NULL;
- ast_mutex_init(&peerl.lock);
-
- #if 0
- ast_register_atexit(&ast_ooh323c_exit);
- #endif
- if (!(sched = sched_context_create())) {
- ast_log(LOG_WARNING, "Unable to create schedule context\n");
- }
- if (!(io = io_context_create())) {
- ast_log(LOG_WARNING, "Unable to create I/O context\n");
- }
- if (!(res = reload_config(0))) {
- /* Make sure we can register our OOH323 channel type */
- if (ast_channel_register(&ooh323_tech)) {
- ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
- return 0;
- }
- ast_rtp_glue_register(&ooh323_rtp);
- ast_udptl_proto_register(&ooh323_udptl);
- ast_cli_register_multiple(cli_ooh323, sizeof(cli_ooh323) / sizeof(struct ast_cli_entry));
- /* fire up the H.323 Endpoint */
- if (OO_OK != ooH323EpInitialize(OO_CALLMODE_AUDIOCALL, gLogFile)) {
- ast_log(LOG_ERROR, "Failed to initialize OOH323 endpoint-"
- "OOH323 Disabled\n");
- return 1;
- }
- if (gIsGateway)
- ooH323EpSetAsGateway();
- ooH323EpSetVersionInfo(t35countrycode, t35extensions, manufacturer,
- vendor, version);
- ooH323EpDisableAutoAnswer();
- ooH323EpSetH225MsgCallbacks(h225Callbacks);
- ooH323EpSetTraceLevel(gTRCLVL);
- ooH323EpSetLocalAddress(gIP, gPort);
- ooH323EpSetCallerID(gCallerID);
-
- if(ooH323EpSetTCPPortRange(ooconfig.mTCPPortStart,
- ooconfig.mTCPPortEnd) == OO_FAILED) {
- ast_log(LOG_ERROR, "h225portrange: Failed to set range\n");
- }
- /* Set aliases if any */
- for (pNewAlias = gAliasList; pNewAlias; pNewAlias = pNewAlias->next) {
- switch (pNewAlias->type) {
- case T_H225AliasAddress_h323_ID:
- ooH323EpAddAliasH323ID(pNewAlias->value);
- break;
- case T_H225AliasAddress_dialedDigits:
- ooH323EpAddAliasDialedDigits(pNewAlias->value);
- break;
- case T_H225AliasAddress_email_ID:
- ooH323EpAddAliasEmailID(pNewAlias->value);
- break;
- default:
- ;
- }
- }
- ast_mutex_lock(&peerl.lock);
- peer = peerl.peers;
- while (peer) {
- if(peer->h323id) ooH323EpAddAliasH323ID(peer->h323id);
- if(peer->email) ooH323EpAddAliasEmailID(peer->email);
- if(peer->e164) ooH323EpAddAliasDialedDigits(peer->e164);
- if(peer->url) ooH323EpAddAliasURLID(peer->url);
- peer = peer->next;
- }
- ast_mutex_unlock(&peerl.lock);
-
- if (gMediaWaitForConnect)
- ooH323EpEnableMediaWaitForConnect();
- else
- ooH323EpDisableMediaWaitForConnect();
- /* Fast start and tunneling options */
- if (gFastStart)
- ooH323EpEnableFastStart();
- else
- ooH323EpDisableFastStart();
- if (!gTunneling)
- ooH323EpDisableH245Tunneling();
- if (gBeMaster)
- ooH323EpTryBeMaster(1);
- ooH323EpEnableManualRingback();
- /* Gatekeeper */
- if (gRasGkMode == RasUseSpecificGatekeeper)
- ooGkClientInit(gRasGkMode, gGatekeeper, 0);
- else if (gRasGkMode == RasDiscoverGatekeeper)
- ooGkClientInit(gRasGkMode, 0, 0);
- /* Register callbacks */
- ooH323EpSetH323Callbacks(h323Callbacks);
- /* Add endpoint capabilities */
- if (ooh323c_set_capability(&gPrefs, gCapability, gDTMFMode, gDTMFCodec) < 0) {
- ast_log(LOG_ERROR, "Capabilities failure for OOH323. OOH323 Disabled.\n");
- return 1;
- }
-
- /* Create H.323 listener */
- if (ooCreateH323Listener() != OO_OK) {
- ast_log(LOG_ERROR, "OOH323 Listener Creation failure. "
- "OOH323 DISABLED\n");
-
- ooH323EpDestroy();
- return 1;
- }
- if (ooh323c_start_stack_thread() < 0) {
- ast_log(LOG_ERROR, "Failed to start OOH323 stack thread. "
- "OOH323 DISABLED\n");
- ooH323EpDestroy();
- return 1;
- }
- /* And start the monitor for the first time */
- restart_monitor();
- }
- return 0;
- }
- static void *do_monitor(void *data)
- {
- int res;
- int reloading;
- struct ooh323_pvt *h323 = NULL;
- time_t t;
- for (;;) {
- struct ooh323_pvt *h323_next;
- /* Check for a reload request */
- ast_mutex_lock(&h323_reload_lock);
- reloading = h323_reloading;
- h323_reloading = 0;
- ast_mutex_unlock(&h323_reload_lock);
- if (reloading) {
- ast_verb(1, "Reloading H.323\n");
- ooh323_do_reload();
- }
- /* Check for interfaces needing to be killed */
- ast_mutex_lock(&iflock);
- time(&t);
- h323 = iflist;
- while (h323) {
- h323_next = h323->next;
- /* TODO: Need to add rtptimeout keepalive support */
- if (ast_test_flag(h323, H323_NEEDDESTROY)) {
- ooh323_destroy (h323);
- } /* else if (ast_test_flag(h323, H323_NEEDSTART) && h323->owner) {
- ast_channel_lock(h323->owner);
- if (ast_pbx_start(h323->owner)) {
- ast_log(LOG_WARNING, "Unable to start PBX on %s\n", h323->owner->name);
- ast_channel_unlock(h323->owner);
- ast_hangup(h323->owner);
- }
- ast_channel_unlock(h323->owner);
- ast_clear_flag(h323, H323_NEEDSTART);
- } */
- h323 = h323_next;
- }
- ast_mutex_unlock(&iflock);
- pthread_testcancel();
- /* Wait for sched or io */
- res = ast_sched_wait(sched);
- if ((res < 0) || (res > 1000)) {
- res = 1000;
- }
- res = ast_io_wait(io, res);
- pthread_testcancel();
- ast_mutex_lock(&monlock);
- if (res >= 0) {
- ast_sched_runq(sched);
- }
- ast_mutex_unlock(&monlock);
- }
- /* Never reached */
- return NULL;
- }
- int restart_monitor(void)
- {
- pthread_attr_t attr;
- /* If we're supposed to be stopped -- stay stopped */
- if (monitor_thread == AST_PTHREADT_STOP)
- return 0;
- if (ast_mutex_lock(&monlock)) {
- ast_log(LOG_WARNING, "Unable to lock monitor\n");
- return -1;
- }
- if (monitor_thread == pthread_self()) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_WARNING, "Cannot kill myself\n");
- return -1;
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- /* Wake up the thread */
- pthread_kill(monitor_thread, SIGURG);
- } else {
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- /* Start a new monitor */
- if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
- ast_mutex_unlock(&monlock);
- ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
- return -1;
- }
- }
- ast_mutex_unlock(&monlock);
- return 0;
- }
- int ooh323_destroy(struct ooh323_pvt *p)
- {
- /* NOTE: Assumes iflock already acquired */
- struct ooh323_pvt *prev = NULL, *cur = NULL;
- struct ooh323_user *user = NULL;
- if (gH323Debug) {
- ast_verbose("--- ooh323_destroy \n");
- if (p)
- ast_verbose(" Destroying %s\n", p->username);
- }
- cur = iflist;
- while (cur) {
- if (cur == p) { break; }
- prev = cur;
- cur = cur->next;
- }
- if (cur) {
- ast_mutex_lock(&cur->lock);
- if (prev)
- prev->next = cur->next;
- else
- iflist = cur->next;
- if (cur->callToken) {
- if (gH323Debug)
- ast_verbose(" Destroying %s\n", cur->callToken);
- ast_free(cur->callToken);
- cur->callToken = 0;
- }
- if (cur->username) {
- free(cur->username);
- cur->username = 0;
- }
- if (cur->host) {
- free(cur->host);
- cur->host = 0;
- }
- if (cur->callerid_name) {
- free(cur->callerid_name);
- cur->callerid_name = 0;
- }
-
- if (cur->callerid_num) {
- free(cur->callerid_num);
- cur->callerid_num = 0;
- }
- if (cur->rtp) {
- ast_rtp_instance_destroy(cur->rtp);
- cur->rtp = NULL;
- }
- if (cur->udptl) {
- ast_udptl_destroy(cur->udptl);
- cur->udptl = NULL;
- }
-
- /* Unlink us from the owner if we have one */
- if (cur->owner) {
- while(ast_channel_trylock(cur->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&cur->lock);
- }
- ast_debug(1, "Detaching from %s\n", cur->owner->name);
- cur->owner->tech_pvt = NULL;
- ast_channel_unlock(cur->owner);
- cur->owner = NULL;
- ast_module_unref(myself);
- }
-
- if (cur->vad) {
- ast_dsp_free(cur->vad);
- cur->vad = NULL;
- }
- /* decrement user/peer count */
- if(!ast_test_flag(cur, H323_OUTGOING)) {
- if (cur->neighbor.user) {
- user = find_user(p->callerid_name, cur->neighbor.user);
- if(user && user->inUse > 0) {
- ast_mutex_lock(&user->lock);
- user->inUse--;
- ast_mutex_unlock(&user->lock);
- }
- free(cur->neighbor.user);
- }
- } else {
- /* outgoing limit decrement here !!! */
- }
- ast_mutex_unlock(&cur->lock);
- ast_mutex_destroy(&cur->lock);
- ast_free(cur);
- }
- if (gH323Debug)
- ast_verbose("+++ ooh323_destroy\n");
- return 0;
- }
- int delete_peers()
- {
- struct ooh323_peer *cur = NULL, *prev = NULL;
- ast_mutex_lock(&peerl.lock);
- cur = peerl.peers;
- while (cur) {
- prev = cur;
- cur = cur->next;
- ast_mutex_destroy(&prev->lock);
- if(prev->h323id) free(prev->h323id);
- if(prev->email) free(prev->email);
- if(prev->url) free(prev->url);
- if(prev->e164) free(prev->e164);
- if(prev->rtpmask) {
- ast_mutex_lock(&prev->rtpmask->lock);
- prev->rtpmask->inuse--;
- ast_mutex_unlock(&prev->rtpmask->lock);
- if (prev->rtpmask->inuse == 0) {
- regfree(&prev->rtpmask->regex);
- ast_mutex_destroy(&prev->rtpmask->lock);
- free(prev->rtpmask);
- }
- }
- free(prev);
- if (cur == peerl.peers) {
- break;
- }
- }
- peerl.peers = NULL;
- ast_mutex_unlock(&peerl.lock);
- return 0;
- }
- int delete_users()
- {
- struct ooh323_user *cur = NULL, *prev = NULL;
- ast_mutex_lock(&userl.lock);
- cur = userl.users;
- while (cur) {
- prev = cur;
- cur = cur->next;
- ast_mutex_destroy(&prev->lock);
- if(prev->rtpmask) {
- ast_mutex_lock(&prev->rtpmask->lock);
- prev->rtpmask->inuse--;
- ast_mutex_unlock(&prev->rtpmask->lock);
- if (prev->rtpmask->inuse == 0) {
- regfree(&prev->rtpmask->regex);
- ast_mutex_destroy(&prev->rtpmask->lock);
- free(prev->rtpmask);
- }
- }
- free(prev);
- if (cur == userl.users) {
- break;
- }
- }
- userl.users = NULL;
- ast_mutex_unlock(&userl.lock);
- return 0;
- }
-
- static int unload_module(void)
- {
- struct ooh323_pvt *p;
- struct ooAliases *cur = NULL, *prev = NULL;
- if (gH323Debug) {
- ast_verbose("--- ooh323 unload_module \n");
- }
- /* First, take us out of the channel loop */
- ast_cli_unregister_multiple(cli_ooh323, sizeof(cli_ooh323) / sizeof(struct ast_cli_entry));
- ast_rtp_glue_unregister(&ooh323_rtp);
- ast_udptl_proto_unregister(&ooh323_udptl);
- ast_channel_unregister(&ooh323_tech);
- #if 0
- ast_unregister_atexit(&ast_ooh323c_exit);
- #endif
- if (gH323Debug) {
- ast_verbose(" unload_module - hanging up all interfaces\n");
- }
- if (!ast_mutex_lock(&iflock)) {
- /* Hangup all interfaces if they have an owner */
- p = iflist;
- while (p) {
- if (p->owner) {
- ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- }
- p = p->next;
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
- if (gH323Debug) {
- ast_verbose(" unload_module - stopping monitor thread\n");
- }
- if (monitor_thread != AST_PTHREADT_NULL) {
- if (!ast_mutex_lock(&monlock)) {
- if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
- pthread_cancel(monitor_thread);
- pthread_kill(monitor_thread, SIGURG);
- pthread_join(monitor_thread, NULL);
- }
- monitor_thread = AST_PTHREADT_STOP;
- ast_mutex_unlock(&monlock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the monitor\n");
- return -1;
- }
- }
- if (gH323Debug) {
- ast_verbose(" unload_module - stopping stack thread\n");
- }
- ooh323c_stop_stack_thread();
- if (gH323Debug) {
- ast_verbose(" unload_module - freeing up memory used by interfaces\n");
- }
- if (!ast_mutex_lock(&iflock)) {
- struct ooh323_pvt *pl;
- /* Destroy all the interfaces and free their memory */
- p = iflist;
- while (p) {
- pl = p;
- p = p->next;
- /* Free associated memory */
- ooh323_destroy(pl);
- }
- iflist = NULL;
- ast_mutex_unlock(&iflock);
- } else {
- ast_log(LOG_WARNING, "Unable to lock the interface list\n");
- return -1;
- }
-
- if (gH323Debug) {
- ast_verbose(" unload_module - deleting users\n");
- }
- delete_users();
- if (gH323Debug) {
- ast_verbose(" unload_module - deleting peers\n");
- }
- delete_peers();
- if (gH323Debug) {
- ast_verbose(" unload_module - Freeing up alias list\n");
- }
- cur = gAliasList;
- while (cur) {
- prev = cur;
- cur = cur->next;
- free(prev->value);
- free(prev);
- }
- gAliasList = NULL;
- if (gH323Debug) {
- ast_verbose(" unload_module- destroying OOH323 endpoint \n");
- }
- ooH323EpDestroy();
- if (gH323Debug) {
- ast_verbose("+++ ooh323 unload_module \n");
- }
- return 0;
- }
- static enum ast_rtp_glue_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp)
- {
- struct ooh323_pvt *p = NULL;
- enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
- if (!(p = (struct ooh323_pvt *) chan->tech_pvt))
- return AST_RTP_GLUE_RESULT_FORBID;
- if (!(p->rtp)) {
- return AST_RTP_GLUE_RESULT_FORBID;
- }
- *rtp = p->rtp ? ao2_ref(p->rtp, +1), p->rtp : NULL;
- res = AST_RTP_GLUE_RESULT_LOCAL;
- if (ast_test_flag(&global_jbconf, AST_JB_FORCED)) {
- res = AST_RTP_GLUE_RESULT_FORBID;
- }
- return res;
- }
- static enum ast_rtp_glue_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp)
- {
- struct ooh323_pvt *p = NULL;
- enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
- if (!(p = (struct ooh323_pvt *) chan->tech_pvt))
- return AST_RTP_GLUE_RESULT_FORBID;
- if (!(p->rtp)) {
- return AST_RTP_GLUE_RESULT_FORBID;
- }
- *rtp = p->vrtp ? ao2_ref(p->vrtp, +1), p->vrtp : NULL;
- res = AST_RTP_GLUE_RESULT_LOCAL;
- return res;
- }
- int ooh323_update_capPrefsOrderForCall
- (ooCallData *call, struct ast_codec_pref *prefs)
- {
- int i = 0;
- int codec = ast_codec_pref_index(prefs, i);
- ooResetCapPrefs(call);
- while (codec) {
- ooAppendCapToCapPrefs(call, ooh323_convertAsteriskCapToH323Cap(codec));
- codec = ast_codec_pref_index(prefs, ++i);
- }
- return 0;
- }
- int ooh323_convertAsteriskCapToH323Cap(format_t cap)
- {
- char formats[FORMAT_STRING_SIZE];
- switch (cap) {
- case AST_FORMAT_ULAW:
- return OO_G711ULAW64K;
- case AST_FORMAT_ALAW:
- return OO_G711ALAW64K;
- case AST_FORMAT_GSM:
- return OO_GSMFULLRATE;
- #ifdef AST_FORMAT_AMRNB
- case AST_FORMAT_AMRNB:
- return OO_AMRNB;
- #endif
- #ifdef AST_FORMAT_SPEEX
- case AST_FORMAT_SPEEX:
- return OO_SPEEX;
- #endif
- case AST_FORMAT_G729A:
- return OO_G729A;
- case AST_FORMAT_G726:
- return OO_G726;
- case AST_FORMAT_G726_AAL2:
- return OO_G726AAL2;
- case AST_FORMAT_G723_1:
- return OO_G7231;
- case AST_FORMAT_H263:
- return OO_H263VIDEO;
- default:
- ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n",
- ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
- return -1;
- }
- }
- static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp,
- struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
- {
- /* XXX Deal with Video */
- struct ooh323_pvt *p;
- struct sockaddr_in them;
- struct sockaddr_in us;
- struct ast_sockaddr tmp;
- if (gH323Debug)
- ast_verbose("--- ooh323_set_peer - %s\n", chan->name);
- if (!rtp) {
- return 0;
- }
- p = (struct ooh323_pvt *) chan->tech_pvt;
- if (!p) {
- ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
- return -1;
- }
- ast_rtp_instance_get_remote_address(rtp, &tmp);
- ast_sockaddr_to_sin(&tmp, &them);
- ast_rtp_instance_get_local_address(rtp, &tmp);
- ast_sockaddr_to_sin(&tmp, &us);
- return 0;
- }
- int configure_local_rtp(struct ooh323_pvt *p, ooCallData *call)
- {
- struct sockaddr_in us;
- struct ast_sockaddr tmp;
- ooMediaInfo mediaInfo;
- int x;
- format_t format = 0;
- if (gH323Debug)
- ast_verbose("--- configure_local_rtp\n");
- if (p->rtp) {
- ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
- if (p->dtmfmode & H323_DTMF_RFC2833 && p->dtmfcodec) {
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1);
- ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
- p->rtp, p->dtmfcodec, "audio", "telephone-event", 0);
- }
- if (p->dtmfmode & H323_DTMF_CISCO && p->dtmfcodec) {
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1);
- ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
- p->rtp, p->dtmfcodec, "audio", "cisco-telephone-event", 0);
- }
- /* figure out our local RTP port and tell the H.323 stack about it*/
- ast_rtp_instance_get_local_address(p->rtp, &tmp);
- ast_sockaddr_to_sin(&tmp, &us);
- if (p->rtptimeout) {
- ast_rtp_instance_set_timeout(p->rtp, p->rtptimeout);
- }
- ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1);
-
- }
- if (p->rtdrcount) {
- if (gH323Debug)
- ast_verbose("Setup RTDR info: %d, %d\n", p->rtdrinterval, p->rtdrcount);
- call->rtdrInterval = p->rtdrinterval;
- call->rtdrCount = p->rtdrcount;
- }
- ast_copy_string(mediaInfo.lMediaIP, ast_inet_ntoa(us.sin_addr), sizeof(mediaInfo.lMediaIP));
- mediaInfo.lMediaPort = ntohs(us.sin_port);
- mediaInfo.lMediaCntrlPort = mediaInfo.lMediaPort +1;
- for (x = 0; 0 != (format = ast_codec_pref_index(&p->prefs, x)); x++) {
- strcpy(mediaInfo.dir, "transmit");
- mediaInfo.cap = ooh323_convertAsteriskCapToH323Cap(format);
- ooAddMediaInfo(call, mediaInfo);
- strcpy(mediaInfo.dir, "receive");
- ooAddMediaInfo(call, mediaInfo);
- if (mediaInfo.cap == OO_G729A) {
- strcpy(mediaInfo.dir, "transmit");
- mediaInfo.cap = OO_G729;
- ooAddMediaInfo(call, mediaInfo);
- strcpy(mediaInfo.dir, "receive");
- ooAddMediaInfo(call, mediaInfo);
- strcpy(mediaInfo.dir, "transmit");
- mediaInfo.cap = OO_G729B;
- ooAddMediaInfo(call, mediaInfo);
- strcpy(mediaInfo.dir, "receive");
- ooAddMediaInfo(call, mediaInfo);
- }
- }
- if (p->udptl) {
- struct ast_sockaddr us_tmp;
- ast_sockaddr_from_sin(&us_tmp, &us);
- ast_udptl_get_us(p->udptl, &us_tmp);
- ast_sockaddr_to_sin(&us_tmp, &us);
- }
- ast_copy_string(mediaInfo.lMediaIP, ast_inet_ntoa(us.sin_addr), sizeof(mediaInfo.lMediaIP));
- mediaInfo.lMediaPort = ntohs(us.sin_port);
- mediaInfo.lMediaCntrlPort = mediaInfo.lMediaPort +1;
- mediaInfo.cap = OO_T38;
- strcpy(mediaInfo.dir, "transmit");
- ooAddMediaInfo(call, mediaInfo);
- strcpy(mediaInfo.dir, "receive");
- ooAddMediaInfo(call, mediaInfo);
- if (gH323Debug)
- ast_verbose("+++ configure_local_rtp\n");
- return 1;
- }
- void setup_rtp_connection(ooCallData *call, const char *remoteIp,
- int remotePort)
- {
- struct ooh323_pvt *p = NULL;
- struct sockaddr_in them;
- struct ast_sockaddr tmp;
- if (gH323Debug)
- ast_verbose("--- setup_rtp_connection %s:%d\n", remoteIp, remotePort);
- /* Find the call or allocate a private structure if call not found */
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Something is wrong: rtp\n");
- return;
- }
- them.sin_family = AF_INET;
- them.sin_addr.s_addr = inet_addr(remoteIp); /* only works for IPv4 */
- them.sin_port = htons(remotePort);
- ast_sockaddr_from_sin(&tmp, &them);
- ast_rtp_instance_set_remote_address(p->rtp, &tmp);
- if (p->writeformat & AST_FORMAT_G726_AAL2)
- ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, 2,
- "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
- if(gH323Debug)
- ast_verbose("+++ setup_rtp_connection\n");
- return;
- }
- void close_rtp_connection(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- if(gH323Debug)
- ast_verbose("--- close_rtp_connection\n");
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Couldn't find matching call to close rtp "
- "connection\n");
- return;
- }
- ast_mutex_lock(&p->lock);
- if (p->rtp) {
- ast_rtp_instance_stop(p->rtp);
- }
- ast_mutex_unlock(&p->lock);
- if(gH323Debug)
- ast_verbose("+++ close_rtp_connection\n");
- return;
- }
- /*
- udptl handling functions
- */
- static struct ast_udptl *ooh323_get_udptl_peer(struct ast_channel *chan)
- {
- struct ooh323_pvt *p;
- struct ast_udptl *udptl = NULL;
- p = chan->tech_pvt;
- if (!p)
- return NULL;
- ast_mutex_lock(&p->lock);
- if (p->udptl)
- udptl = p->udptl;
- ast_mutex_unlock(&p->lock);
- return udptl;
- }
- static int ooh323_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl)
- {
- struct ooh323_pvt *p;
- p = chan->tech_pvt;
- if (!p)
- return -1;
- ast_mutex_lock(&p->lock);
- if (udptl) {
- struct ast_sockaddr udptl_addr;
- ast_udptl_get_peer(udptl, &udptl_addr);
- ast_sockaddr_to_sin(&udptl_addr, &p->udptlredirip);
- } else
- memset(&p->udptlredirip, 0, sizeof(p->udptlredirip));
- ast_mutex_unlock(&p->lock);
- return 0;
- }
- void setup_udptl_connection(ooCallData *call, const char *remoteIp,
- int remotePort)
- {
- struct ooh323_pvt *p = NULL;
- struct sockaddr_in them;
- struct ast_sockaddr them_addr;
- if (gH323Debug)
- ast_verbose("--- setup_udptl_connection\n");
- /* Find the call or allocate a private structure if call not found */
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Something is wrong: rtp\n");
- return;
- }
- ast_mutex_lock(&p->lock);
- if (p->owner) {
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- } else {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- them.sin_family = AF_INET;
- them.sin_addr.s_addr = inet_addr(remoteIp); /* only works for IPv4 */
- them.sin_port = htons(remotePort);
- ast_sockaddr_from_sin(&them_addr, &them);
- ast_udptl_set_peer(p->udptl, &them_addr);
- ast_udptl_set_tag(p->udptl, "%s", p->owner->name);
- p->t38_tx_enable = 1;
- p->lastTxT38 = time(NULL);
- if (p->t38support == T38_ENABLED) {
- struct ast_control_t38_parameters parameters = { .request_response = 0 };
- parameters.request_response = AST_T38_NEGOTIATED;
- parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);
- parameters.rate = AST_T38_RATE_14400;
- ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, ¶meters, sizeof(parameters));
- }
- if (gH323Debug)
- ast_debug(1, "Receiving UDPTL %s:%d\n", ast_inet_ntoa(them.sin_addr),
- ntohs(them.sin_port));
- ast_channel_unlock(p->owner);
- ast_mutex_unlock(&p->lock);
- if(gH323Debug)
- ast_verbose("+++ setup_udptl_connection\n");
- return;
- }
- void close_udptl_connection(ooCallData *call)
- {
- struct ooh323_pvt *p = NULL;
- if(gH323Debug)
- ast_verbose("--- close_udptl_connection\n");
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "Couldn't find matching call to close udptl "
- "connection\n");
- return;
- }
- ast_mutex_lock(&p->lock);
- if (p->owner) {
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- } else {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- p->t38_tx_enable = 0;
- if (p->t38support == T38_ENABLED) {
- struct ast_control_t38_parameters parameters = { .request_response = 0 };
- parameters.request_response = AST_T38_TERMINATED;
- ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, ¶meters, sizeof(parameters));
- }
- ast_channel_unlock(p->owner);
- ast_mutex_unlock(&p->lock);
- if(gH323Debug)
- ast_verbose("+++ close_udptl_connection\n");
- return;
- }
- /* end of udptl handling */
- int update_our_aliases(ooCallData *call, struct ooh323_pvt *p)
- {
- int updated = -1;
- ooAliases *psAlias = NULL;
-
- if (!call->ourAliases)
- return updated;
- for (psAlias = call->ourAliases; psAlias; psAlias = psAlias->next) {
- if (psAlias->type == T_H225AliasAddress_h323_ID) {
- ast_copy_string(p->callee_h323id, psAlias->value, sizeof(p->callee_h323id));
- updated = 1;
- }
- if (psAlias->type == T_H225AliasAddress_dialedDigits) {
- ast_copy_string(p->callee_dialedDigits, psAlias->value,
- sizeof(p->callee_dialedDigits));
- updated = 1;
- }
- if (psAlias->type == T_H225AliasAddress_url_ID) {
- ast_copy_string(p->callee_url, psAlias->value, sizeof(p->callee_url));
- updated = 1;
- }
- if (psAlias->type == T_H225AliasAddress_email_ID) {
- ast_copy_string(p->callee_email, psAlias->value, sizeof(p->callee_email));
- updated = 1;
- }
- }
- return updated;
- }
- struct ast_frame *ooh323_rtp_read(struct ast_channel *ast, struct ooh323_pvt *p)
- {
- /* Retrieve audio/etc from channel. Assumes p->lock is already held. */
- struct ast_frame *f;
- static struct ast_frame null_frame = { AST_FRAME_NULL, };
- switch (ast->fdno) {
- case 0:
- f = ast_rtp_instance_read(p->rtp, 0); /* RTP Audio */
- break;
- case 1:
- f = ast_rtp_instance_read(p->rtp, 1); /* RTCP Control Channel */
- break;
- case 2:
- f = ast_rtp_instance_read(p->vrtp, 0); /* RTP Video */
- break;
- case 3:
- f = ast_rtp_instance_read(p->vrtp, 1); /* RTCP Control Channel for video */
- break;
- case 5:
- f = ast_udptl_read(p->udptl); /* UDPTL t.38 data */
- if (gH323Debug) ast_debug(1, "Got UDPTL %d/%d len %d for %s\n",
- f->frametype, f->subclass.integer, f->datalen, ast->name);
- break;
- default:
- f = &null_frame;
- }
- if (f && p->owner) {
- /* We already hold the channel lock */
- if (f->frametype == AST_FRAME_VOICE && !p->faxmode) {
- if (f->subclass.codec != p->owner->nativeformats) {
- ast_debug(1, "Oooh, voice format changed to %s\n", ast_getformatname(f->subclass.codec));
- p->owner->nativeformats = f->subclass.codec;
- ast_set_read_format(p->owner, p->owner->readformat);
- ast_set_write_format(p->owner, p->owner->writeformat);
- }
- if ((p->dtmfmode & H323_DTMF_INBAND) && p->vad &&
- (f->subclass.codec == AST_FORMAT_SLINEAR || f->subclass.codec == AST_FORMAT_ALAW ||
- f->subclass.codec == AST_FORMAT_ULAW)) {
- f = ast_dsp_process(p->owner, p->vad, f);
- if (f && (f->frametype == AST_FRAME_DTMF))
- ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer);
- }
- }
- }
- return f;
- }
- void onModeChanged(ooCallData *call, int t38mode) {
- struct ooh323_pvt *p;
- p = find_call(call);
- if (!p) {
- ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
- return;
- }
- ast_mutex_lock(&p->lock);
- if (gH323Debug)
- ast_debug(1, "change mode to %d for %s\n", t38mode, call->callToken);
- if (t38mode == p->faxmode) {
- if (gH323Debug)
- ast_debug(1, "mode for %s is already %d\n", call->callToken,
- t38mode);
- ast_mutex_unlock(&p->lock);
- return;
- }
- if (p->owner) {
- while (p->owner && ast_channel_trylock(p->owner)) {
- ast_debug(1,"Failed to grab lock, trying again\n");
- DEADLOCK_AVOIDANCE(&p->lock);
- }
- if (!p->owner) {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- } else {
- ast_mutex_unlock(&p->lock);
- ast_log(LOG_ERROR, "Channel has no owner\n");
- return;
- }
- if (t38mode) {
- if (p->t38support == T38_ENABLED) {
- /* AST_T38_CONTROL mode */
- struct ast_control_t38_parameters parameters = { .request_response = 0 };
- parameters.request_response = AST_T38_REQUEST_NEGOTIATE;
- if (call->T38FarMaxDatagram) {
- ast_udptl_set_far_max_datagram(p->udptl, call->T38FarMaxDatagram);
- } else {
- ast_udptl_set_far_max_datagram(p->udptl, 144);
- }
- if (call->T38Version) {
- parameters.version = call->T38Version;
- }
- parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);
- parameters.rate = AST_T38_RATE_14400;
- ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS,
- ¶meters, sizeof(parameters));
- p->faxmode = 1;
- }
- } else {
- if (p->t38support == T38_ENABLED) {
- struct ast_control_t38_parameters parameters = { .request_response = 0 };
- parameters.request_response = AST_T38_REQUEST_TERMINATE;
- parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);
- parameters.rate = AST_T38_RATE_14400;
- ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS,
- ¶meters, sizeof(parameters));
- }
- p->faxmode = 0;
- p->t38_init = 0;
- }
- p->chmodepend = 0;
- ast_channel_unlock(p->owner);
- ast_mutex_unlock(&p->lock);
- }
- int ooh323_convert_hangupcause_asteriskToH323(int cause)
- {
- switch (cause) {
- case AST_CAUSE_CALL_REJECTED:
- return OO_REASON_REMOTE_REJECTED;
- case AST_CAUSE_UNALLOCATED:
- return OO_REASON_NOUSER;
- case AST_CAUSE_BUSY:
- return OO_REASON_REMOTE_BUSY;
- case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL:
- return OO_REASON_NOCOMMON_CAPABILITIES;
- case AST_CAUSE_CONGESTION:
- return OO_REASON_REMOTE_BUSY;
- case AST_CAUSE_NO_ANSWER:
- return OO_REASON_REMOTE_NOANSWER;
- case AST_CAUSE_NORMAL:
- return OO_REASON_REMOTE_CLEARED;
- case AST_CAUSE_FAILURE:
- default:
- return OO_REASON_UNKNOWN;
- }
- return 0;
- }
- int ooh323_convert_hangupcause_h323ToAsterisk(int cause)
- {
- switch (cause) {
- case OO_REASON_REMOTE_REJECTED:
- return AST_CAUSE_CALL_REJECTED;
- case OO_REASON_NOUSER:
- return AST_CAUSE_UNALLOCATED;
- case OO_REASON_REMOTE_BUSY:
- case OO_REASON_LOCAL_BUSY:
- return AST_CAUSE_BUSY;
- case OO_REASON_NOCOMMON_CAPABILITIES: /* No codecs approved */
- return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
- case OO_REASON_REMOTE_CONGESTED:
- case OO_REASON_LOCAL_CONGESTED:
- return AST_CAUSE_CONGESTION;
- case OO_REASON_REMOTE_NOANSWER:
- return AST_CAUSE_NO_ANSWER;
- case OO_REASON_UNKNOWN:
- case OO_REASON_INVALIDMESSAGE:
- case OO_REASON_TRANSPORTFAILURE:
- return AST_CAUSE_FAILURE;
- case OO_REASON_REMOTE_CLEARED:
- return AST_CAUSE_NORMAL;
- default:
- return AST_CAUSE_NORMAL;
- }
- /* Never reached */
- return 0;
- }
- #if 0
- void ast_ooh323c_exit()
- {
- ooGkClientDestroy();
- }
- #endif
- AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Objective Systems H323 Channel");
|