12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814 |
- /*
- * JsSIP v3.3.11
- * the Javascript SIP library
- * Copyright: 2012-2019 JosĂŠ Luis MillĂĄn <jmillan@aliax.net> (https://github.com/jmillan)
- * Homepage: https://jssip.net
- * License: MIT
- */
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.JsSIP = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
- "use strict";
- var Utils = require('./Utils');
- var JsSIP_C = require('./Constants');
- var Grammar = require('./Grammar');
- var URI = require('./URI');
- var Socket = require('./Socket');
- var Exceptions = require('./Exceptions'); // Default settings.
- exports.settings = {
- // SIP authentication.
- authorization_user: null,
- password: null,
- realm: null,
- ha1: null,
- // SIP account.
- display_name: null,
- uri: null,
- contact_uri: null,
- // SIP instance id (GRUU).
- instance_id: null,
- // Preloaded SIP Route header field.
- use_preloaded_route: false,
- // Session parameters.
- session_timers: true,
- session_timers_refresh_method: JsSIP_C.UPDATE,
- no_answer_timeout: 60,
- // Registration parameters.
- register: true,
- register_expires: 600,
- registrar_server: null,
- // Connection options.
- sockets: null,
- connection_recovery_max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL,
- connection_recovery_min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL,
- /*
- * Host address.
- * Value to be set in Via sent_by and host part of Contact FQDN.
- */
- via_host: "".concat(Utils.createRandomToken(12), ".invalid")
- }; // Configuration checks.
- var checks = {
- mandatory: {
- sockets: function sockets(_sockets2) {
- /* Allow defining sockets parameter as:
- * Socket: socket
- * Array of Socket: [socket1, socket2]
- * Array of Objects: [{socket: socket1, weight:1}, {socket: Socket2, weight:0}]
- * Array of Objects and Socket: [{socket: socket1}, socket2]
- */
- var _sockets = [];
- if (Socket.isSocket(_sockets2)) {
- _sockets.push({
- socket: _sockets2
- });
- } else if (Array.isArray(_sockets2) && _sockets2.length) {
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = _sockets2[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var socket = _step.value;
- if (Object.prototype.hasOwnProperty.call(socket, 'socket') && Socket.isSocket(socket.socket)) {
- _sockets.push(socket);
- } else if (Socket.isSocket(socket)) {
- _sockets.push({
- socket: socket
- });
- }
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- } else {
- return;
- }
- return _sockets;
- },
- uri: function uri(_uri) {
- if (!/^sip:/i.test(_uri)) {
- _uri = "".concat(JsSIP_C.SIP, ":").concat(_uri);
- }
- var parsed = URI.parse(_uri);
- if (!parsed) {
- return;
- } else if (!parsed.user) {
- return;
- } else {
- return parsed;
- }
- }
- },
- optional: {
- authorization_user: function authorization_user(_authorization_user) {
- if (Grammar.parse("\"".concat(_authorization_user, "\""), 'quoted_string') === -1) {
- return;
- } else {
- return _authorization_user;
- }
- },
- user_agent: function user_agent(_user_agent) {
- if (typeof _user_agent === 'string') {
- return _user_agent;
- }
- },
- connection_recovery_max_interval: function connection_recovery_max_interval(_connection_recovery_max_interval) {
- if (Utils.isDecimal(_connection_recovery_max_interval)) {
- var value = Number(_connection_recovery_max_interval);
- if (value > 0) {
- return value;
- }
- }
- },
- connection_recovery_min_interval: function connection_recovery_min_interval(_connection_recovery_min_interval) {
- if (Utils.isDecimal(_connection_recovery_min_interval)) {
- var value = Number(_connection_recovery_min_interval);
- if (value > 0) {
- return value;
- }
- }
- },
- contact_uri: function contact_uri(_contact_uri) {
- if (typeof _contact_uri === 'string') {
- var uri = Grammar.parse(_contact_uri, 'SIP_URI');
- if (uri !== -1) {
- return uri;
- }
- }
- },
- display_name: function display_name(_display_name) {
- return _display_name;
- },
- instance_id: function instance_id(_instance_id) {
- if (/^uuid:/i.test(_instance_id)) {
- _instance_id = _instance_id.substr(5);
- }
- if (Grammar.parse(_instance_id, 'uuid') === -1) {
- return;
- } else {
- return _instance_id;
- }
- },
- no_answer_timeout: function no_answer_timeout(_no_answer_timeout) {
- if (Utils.isDecimal(_no_answer_timeout)) {
- var value = Number(_no_answer_timeout);
- if (value > 0) {
- return value;
- }
- }
- },
- session_timers: function session_timers(_session_timers) {
- if (typeof _session_timers === 'boolean') {
- return _session_timers;
- }
- },
- session_timers_refresh_method: function session_timers_refresh_method(method) {
- if (typeof method === 'string') {
- method = method.toUpperCase();
- if (method === JsSIP_C.INVITE || method === JsSIP_C.UPDATE) {
- return method;
- }
- }
- },
- password: function password(_password) {
- return String(_password);
- },
- realm: function realm(_realm) {
- return String(_realm);
- },
- ha1: function ha1(_ha) {
- return String(_ha);
- },
- register: function register(_register) {
- if (typeof _register === 'boolean') {
- return _register;
- }
- },
- register_expires: function register_expires(_register_expires) {
- if (Utils.isDecimal(_register_expires)) {
- var value = Number(_register_expires);
- if (value > 0) {
- return value;
- }
- }
- },
- registrar_server: function registrar_server(_registrar_server) {
- if (!/^sip:/i.test(_registrar_server)) {
- _registrar_server = "".concat(JsSIP_C.SIP, ":").concat(_registrar_server);
- }
- var parsed = URI.parse(_registrar_server);
- if (!parsed) {
- return;
- } else if (parsed.user) {
- return;
- } else {
- return parsed;
- }
- },
- use_preloaded_route: function use_preloaded_route(_use_preloaded_route) {
- if (typeof _use_preloaded_route === 'boolean') {
- return _use_preloaded_route;
- }
- }
- }
- };
- exports.load = function (dst, src) {
- // Check Mandatory parameters.
- for (var parameter in checks.mandatory) {
- if (!src.hasOwnProperty(parameter)) {
- throw new Exceptions.ConfigurationError(parameter);
- } else {
- var value = src[parameter];
- var checked_value = checks.mandatory[parameter](value);
- if (checked_value !== undefined) {
- dst[parameter] = checked_value;
- } else {
- throw new Exceptions.ConfigurationError(parameter, value);
- }
- }
- } // Check Optional parameters.
- for (var _parameter in checks.optional) {
- if (src.hasOwnProperty(_parameter)) {
- var _value = src[_parameter];
- /* If the parameter value is null, empty string, undefined, empty array
- * or it's a number with NaN value, then apply its default value.
- */
- if (Utils.isEmpty(_value)) {
- continue;
- }
- var _checked_value = checks.optional[_parameter](_value);
- if (_checked_value !== undefined) {
- dst[_parameter] = _checked_value;
- } else {
- throw new Exceptions.ConfigurationError(_parameter, _value);
- }
- }
- }
- };
- },{"./Constants":2,"./Exceptions":6,"./Grammar":7,"./Socket":20,"./URI":25,"./Utils":26}],2:[function(require,module,exports){
- "use strict";
- var pkg = require('../package.json');
- module.exports = {
- USER_AGENT: "".concat(pkg.title, " ").concat(pkg.version),
- // SIP scheme.
- SIP: 'sip',
- SIPS: 'sips',
- // End and Failure causes.
- causes: {
- // Generic error causes.
- CONNECTION_ERROR: 'Connection Error',
- REQUEST_TIMEOUT: 'Request Timeout',
- SIP_FAILURE_CODE: 'SIP Failure Code',
- INTERNAL_ERROR: 'Internal Error',
- // SIP error causes.
- BUSY: 'Busy',
- REJECTED: 'Rejected',
- REDIRECTED: 'Redirected',
- UNAVAILABLE: 'Unavailable',
- NOT_FOUND: 'Not Found',
- ADDRESS_INCOMPLETE: 'Address Incomplete',
- INCOMPATIBLE_SDP: 'Incompatible SDP',
- MISSING_SDP: 'Missing SDP',
- AUTHENTICATION_ERROR: 'Authentication Error',
- // Session error causes.
- BYE: 'Terminated',
- WEBRTC_ERROR: 'WebRTC Error',
- CANCELED: 'Canceled',
- NO_ANSWER: 'No Answer',
- EXPIRES: 'Expires',
- NO_ACK: 'No ACK',
- DIALOG_ERROR: 'Dialog Error',
- USER_DENIED_MEDIA_ACCESS: 'User Denied Media Access',
- BAD_MEDIA_DESCRIPTION: 'Bad Media Description',
- RTP_TIMEOUT: 'RTP Timeout'
- },
- SIP_ERROR_CAUSES: {
- REDIRECTED: [300, 301, 302, 305, 380],
- BUSY: [486, 600],
- REJECTED: [403, 603],
- NOT_FOUND: [404, 604],
- UNAVAILABLE: [480, 410, 408, 430],
- ADDRESS_INCOMPLETE: [484, 424],
- INCOMPATIBLE_SDP: [488, 606],
- AUTHENTICATION_ERROR: [401, 407]
- },
- // SIP Methods.
- ACK: 'ACK',
- BYE: 'BYE',
- CANCEL: 'CANCEL',
- INFO: 'INFO',
- INVITE: 'INVITE',
- MESSAGE: 'MESSAGE',
- NOTIFY: 'NOTIFY',
- OPTIONS: 'OPTIONS',
- REGISTER: 'REGISTER',
- REFER: 'REFER',
- UPDATE: 'UPDATE',
- SUBSCRIBE: 'SUBSCRIBE',
- /* SIP Response Reasons
- * DOC: https://www.iana.org/assignments/sip-parameters
- * Copied from https://github.com/versatica/OverSIP/blob/master/lib/oversip/sip/constants.rb#L7
- */
- REASON_PHRASE: {
- 100: 'Trying',
- 180: 'Ringing',
- 181: 'Call Is Being Forwarded',
- 182: 'Queued',
- 183: 'Session Progress',
- 199: 'Early Dialog Terminated',
- // draft-ietf-sipcore-199
- 200: 'OK',
- 202: 'Accepted',
- // RFC 3265
- 204: 'No Notification',
- // RFC 5839
- 300: 'Multiple Choices',
- 301: 'Moved Permanently',
- 302: 'Moved Temporarily',
- 305: 'Use Proxy',
- 380: 'Alternative Service',
- 400: 'Bad Request',
- 401: 'Unauthorized',
- 402: 'Payment Required',
- 403: 'Forbidden',
- 404: 'Not Found',
- 405: 'Method Not Allowed',
- 406: 'Not Acceptable',
- 407: 'Proxy Authentication Required',
- 408: 'Request Timeout',
- 410: 'Gone',
- 412: 'Conditional Request Failed',
- // RFC 3903
- 413: 'Request Entity Too Large',
- 414: 'Request-URI Too Long',
- 415: 'Unsupported Media Type',
- 416: 'Unsupported URI Scheme',
- 417: 'Unknown Resource-Priority',
- // RFC 4412
- 420: 'Bad Extension',
- 421: 'Extension Required',
- 422: 'Session Interval Too Small',
- // RFC 4028
- 423: 'Interval Too Brief',
- 424: 'Bad Location Information',
- // RFC 6442
- 428: 'Use Identity Header',
- // RFC 4474
- 429: 'Provide Referrer Identity',
- // RFC 3892
- 430: 'Flow Failed',
- // RFC 5626
- 433: 'Anonymity Disallowed',
- // RFC 5079
- 436: 'Bad Identity-Info',
- // RFC 4474
- 437: 'Unsupported Certificate',
- // RFC 4744
- 438: 'Invalid Identity Header',
- // RFC 4744
- 439: 'First Hop Lacks Outbound Support',
- // RFC 5626
- 440: 'Max-Breadth Exceeded',
- // RFC 5393
- 469: 'Bad Info Package',
- // draft-ietf-sipcore-info-events
- 470: 'Consent Needed',
- // RFC 5360
- 478: 'Unresolvable Destination',
- // Custom code copied from Kamailio.
- 480: 'Temporarily Unavailable',
- 481: 'Call/Transaction Does Not Exist',
- 482: 'Loop Detected',
- 483: 'Too Many Hops',
- 484: 'Address Incomplete',
- 485: 'Ambiguous',
- 486: 'Busy Here',
- 487: 'Request Terminated',
- 488: 'Not Acceptable Here',
- 489: 'Bad Event',
- // RFC 3265
- 491: 'Request Pending',
- 493: 'Undecipherable',
- 494: 'Security Agreement Required',
- // RFC 3329
- 500: 'JsSIP Internal Error',
- 501: 'Not Implemented',
- 502: 'Bad Gateway',
- 503: 'Service Unavailable',
- 504: 'Server Time-out',
- 505: 'Version Not Supported',
- 513: 'Message Too Large',
- 580: 'Precondition Failure',
- // RFC 3312
- 600: 'Busy Everywhere',
- 603: 'Decline',
- 604: 'Does Not Exist Anywhere',
- 606: 'Not Acceptable'
- },
- ALLOWED_METHODS: 'INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY',
- ACCEPTED_BODY_TYPES: 'application/sdp, application/dtmf-relay',
- MAX_FORWARDS: 69,
- SESSION_EXPIRES: 90,
- MIN_SESSION_EXPIRES: 60,
- CONNECTION_RECOVERY_MAX_INTERVAL: 30,
- CONNECTION_RECOVERY_MIN_INTERVAL: 2
- };
- },{"../package.json":38}],3:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var SIPMessage = require('./SIPMessage');
- var JsSIP_C = require('./Constants');
- var Transactions = require('./Transactions');
- var Dialog_RequestSender = require('./Dialog/RequestSender');
- var Utils = require('./Utils');
- var debug = require('debug')('JsSIP:Dialog');
- var C = {
- // Dialog states.
- STATUS_EARLY: 1,
- STATUS_CONFIRMED: 2
- }; // RFC 3261 12.1.
- module.exports =
- /*#__PURE__*/
- function () {
- _createClass(Dialog, null, [{
- key: "C",
- // Expose C object.
- get: function get() {
- return C;
- }
- }]);
- function Dialog(owner, message, type) {
- var state = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : C.STATUS_CONFIRMED;
- _classCallCheck(this, Dialog);
- this._owner = owner;
- this._ua = owner._ua;
- this._uac_pending_reply = false;
- this._uas_pending_reply = false;
- if (!message.hasHeader('contact')) {
- return {
- error: 'unable to create a Dialog without Contact header field'
- };
- }
- if (message instanceof SIPMessage.IncomingResponse) {
- state = message.status_code < 200 ? C.STATUS_EARLY : C.STATUS_CONFIRMED;
- }
- var contact = message.parseHeader('contact'); // RFC 3261 12.1.1.
- if (type === 'UAS') {
- this._id = {
- call_id: message.call_id,
- local_tag: message.to_tag,
- remote_tag: message.from_tag,
- toString: function toString() {
- return this.call_id + this.local_tag + this.remote_tag;
- }
- };
- this._state = state;
- this._remote_seqnum = message.cseq;
- this._local_uri = message.parseHeader('to').uri;
- this._remote_uri = message.parseHeader('from').uri;
- this._remote_target = contact.uri;
- this._route_set = message.getHeaders('record-route');
- this._ack_seqnum = this._remote_seqnum;
- } // RFC 3261 12.1.2.
- else if (type === 'UAC') {
- this._id = {
- call_id: message.call_id,
- local_tag: message.from_tag,
- remote_tag: message.to_tag,
- toString: function toString() {
- return this.call_id + this.local_tag + this.remote_tag;
- }
- };
- this._state = state;
- this._local_seqnum = message.cseq;
- this._local_uri = message.parseHeader('from').uri;
- this._remote_uri = message.parseHeader('to').uri;
- this._remote_target = contact.uri;
- this._route_set = message.getHeaders('record-route').reverse();
- this._ack_seqnum = null;
- }
- this._ua.newDialog(this);
- debug("new ".concat(type, " dialog created with status ").concat(this._state === C.STATUS_EARLY ? 'EARLY' : 'CONFIRMED'));
- }
- _createClass(Dialog, [{
- key: "update",
- value: function update(message, type) {
- this._state = C.STATUS_CONFIRMED;
- debug("dialog ".concat(this._id.toString(), " changed to CONFIRMED state"));
- if (type === 'UAC') {
- // RFC 3261 13.2.2.4.
- this._route_set = message.getHeaders('record-route').reverse();
- }
- }
- }, {
- key: "terminate",
- value: function terminate() {
- debug("dialog ".concat(this._id.toString(), " deleted"));
- this._ua.destroyDialog(this);
- }
- }, {
- key: "sendRequest",
- value: function sendRequest(method) {
- var _this = this;
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var eventHandlers = options.eventHandlers || {};
- var body = options.body || null;
- var request = this._createRequest(method, extraHeaders, body); // Increase the local CSeq on authentication.
- eventHandlers.onAuthenticated = function () {
- _this._local_seqnum += 1;
- };
- var request_sender = new Dialog_RequestSender(this, request, eventHandlers);
- request_sender.send(); // Return the instance of OutgoingRequest.
- return request;
- }
- }, {
- key: "receiveRequest",
- value: function receiveRequest(request) {
- // Check in-dialog request.
- if (!this._checkInDialogRequest(request)) {
- return;
- } // ACK received. Cleanup this._ack_seqnum.
- if (request.method === JsSIP_C.ACK && this._ack_seqnum !== null) {
- this._ack_seqnum = null;
- } // INVITE received. Set this._ack_seqnum.
- else if (request.method === JsSIP_C.INVITE) {
- this._ack_seqnum = request.cseq;
- }
- this._owner.receiveRequest(request);
- } // RFC 3261 12.2.1.1.
- }, {
- key: "_createRequest",
- value: function _createRequest(method, extraHeaders, body) {
- extraHeaders = Utils.cloneArray(extraHeaders);
- if (!this._local_seqnum) {
- this._local_seqnum = Math.floor(Math.random() * 10000);
- }
- var cseq = method === JsSIP_C.CANCEL || method === JsSIP_C.ACK ? this._local_seqnum : this._local_seqnum += 1;
- var request = new SIPMessage.OutgoingRequest(method, this._remote_target, this._ua, {
- 'cseq': cseq,
- 'call_id': this._id.call_id,
- 'from_uri': this._local_uri,
- 'from_tag': this._id.local_tag,
- 'to_uri': this._remote_uri,
- 'to_tag': this._id.remote_tag,
- 'route_set': this._route_set
- }, extraHeaders, body);
- return request;
- } // RFC 3261 12.2.2.
- }, {
- key: "_checkInDialogRequest",
- value: function _checkInDialogRequest(request) {
- var _this2 = this;
- if (!this._remote_seqnum) {
- this._remote_seqnum = request.cseq;
- } else if (request.cseq < this._remote_seqnum) {
- if (request.method === JsSIP_C.ACK) {
- // We are not expecting any ACK with lower seqnum than the current one.
- // Or this is not the ACK we are waiting for.
- if (this._ack_seqnum === null || request.cseq !== this._ack_seqnum) {
- return false;
- }
- } else {
- request.reply(500);
- return false;
- }
- } else if (request.cseq > this._remote_seqnum) {
- this._remote_seqnum = request.cseq;
- } // RFC3261 14.2 Modifying an Existing Session -UAS BEHAVIOR-.
- if (request.method === JsSIP_C.INVITE || request.method === JsSIP_C.UPDATE && request.body) {
- if (this._uac_pending_reply === true) {
- request.reply(491);
- } else if (this._uas_pending_reply === true) {
- var retryAfter = (Math.random() * 10 | 0) + 1;
- request.reply(500, null, ["Retry-After:".concat(retryAfter)]);
- return false;
- } else {
- this._uas_pending_reply = true;
- var stateChanged = function stateChanged() {
- if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED || request.server_transaction.state === Transactions.C.STATUS_COMPLETED || request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
- request.server_transaction.removeListener('stateChanged', stateChanged);
- _this2._uas_pending_reply = false;
- }
- };
- request.server_transaction.on('stateChanged', stateChanged);
- } // RFC3261 12.2.2 Replace the dialog`s remote target URI if the request is accepted.
- if (request.hasHeader('contact')) {
- request.server_transaction.on('stateChanged', function () {
- if (request.server_transaction.state === Transactions.C.STATUS_ACCEPTED) {
- _this2._remote_target = request.parseHeader('contact').uri;
- }
- });
- }
- } else if (request.method === JsSIP_C.NOTIFY) {
- // RFC6665 3.2 Replace the dialog`s remote target URI if the request is accepted.
- if (request.hasHeader('contact')) {
- request.server_transaction.on('stateChanged', function () {
- if (request.server_transaction.state === Transactions.C.STATUS_COMPLETED) {
- _this2._remote_target = request.parseHeader('contact').uri;
- }
- });
- }
- }
- return true;
- }
- }, {
- key: "id",
- get: function get() {
- return this._id;
- }
- }, {
- key: "local_seqnum",
- get: function get() {
- return this._local_seqnum;
- },
- set: function set(num) {
- this._local_seqnum = num;
- }
- }, {
- key: "owner",
- get: function get() {
- return this._owner;
- }
- }, {
- key: "uac_pending_reply",
- get: function get() {
- return this._uac_pending_reply;
- },
- set: function set(pending) {
- this._uac_pending_reply = pending;
- }
- }, {
- key: "uas_pending_reply",
- get: function get() {
- return this._uas_pending_reply;
- }
- }]);
- return Dialog;
- }();
- },{"./Constants":2,"./Dialog/RequestSender":4,"./SIPMessage":19,"./Transactions":22,"./Utils":26,"debug":30}],4:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var JsSIP_C = require('../Constants');
- var Transactions = require('../Transactions');
- var RTCSession = require('../RTCSession');
- var RequestSender = require('../RequestSender'); // Default event handlers.
- var EventHandlers = {
- onRequestTimeout: function onRequestTimeout() {},
- onTransportError: function onTransportError() {},
- onSuccessResponse: function onSuccessResponse() {},
- onErrorResponse: function onErrorResponse() {},
- onAuthenticated: function onAuthenticated() {},
- onDialogError: function onDialogError() {}
- };
- module.exports =
- /*#__PURE__*/
- function () {
- function DialogRequestSender(dialog, request, eventHandlers) {
- _classCallCheck(this, DialogRequestSender);
- this._dialog = dialog;
- this._ua = dialog._ua;
- this._request = request;
- this._eventHandlers = eventHandlers; // RFC3261 14.1 Modifying an Existing Session. UAC Behavior.
- this._reattempt = false;
- this._reattemptTimer = null; // Define the undefined handlers.
- for (var handler in EventHandlers) {
- if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
- if (!this._eventHandlers[handler]) {
- this._eventHandlers[handler] = EventHandlers[handler];
- }
- }
- }
- }
- _createClass(DialogRequestSender, [{
- key: "send",
- value: function send() {
- var _this = this;
- var request_sender = new RequestSender(this._ua, this._request, {
- onRequestTimeout: function onRequestTimeout() {
- _this._eventHandlers.onRequestTimeout();
- },
- onTransportError: function onTransportError() {
- _this._eventHandlers.onTransportError();
- },
- onAuthenticated: function onAuthenticated(request) {
- _this._eventHandlers.onAuthenticated(request);
- },
- onReceiveResponse: function onReceiveResponse(response) {
- _this._receiveResponse(response);
- }
- });
- request_sender.send(); // RFC3261 14.2 Modifying an Existing Session -UAC BEHAVIOR-.
- if ((this._request.method === JsSIP_C.INVITE || this._request.method === JsSIP_C.UPDATE && this._request.body) && request_sender.clientTransaction.state !== Transactions.C.STATUS_TERMINATED) {
- this._dialog.uac_pending_reply = true;
- var stateChanged = function stateChanged() {
- if (request_sender.clientTransaction.state === Transactions.C.STATUS_ACCEPTED || request_sender.clientTransaction.state === Transactions.C.STATUS_COMPLETED || request_sender.clientTransaction.state === Transactions.C.STATUS_TERMINATED) {
- request_sender.clientTransaction.removeListener('stateChanged', stateChanged);
- _this._dialog.uac_pending_reply = false;
- }
- };
- request_sender.clientTransaction.on('stateChanged', stateChanged);
- }
- }
- }, {
- key: "_receiveResponse",
- value: function _receiveResponse(response) {
- var _this2 = this;
- // RFC3261 12.2.1.2 408 or 481 is received for a request within a dialog.
- if (response.status_code === 408 || response.status_code === 481) {
- this._eventHandlers.onDialogError(response);
- } else if (response.method === JsSIP_C.INVITE && response.status_code === 491) {
- if (this._reattempt) {
- if (response.status_code >= 200 && response.status_code < 300) {
- this._eventHandlers.onSuccessResponse(response);
- } else if (response.status_code >= 300) {
- this._eventHandlers.onErrorResponse(response);
- }
- } else {
- this._request.cseq.value = this._dialog.local_seqnum += 1;
- this._reattemptTimer = setTimeout(function () {
- // TODO: look at dialog state instead.
- if (_this2._dialog.owner.status !== RTCSession.C.STATUS_TERMINATED) {
- _this2._reattempt = true;
- _this2._request_sender.send();
- }
- }, 1000);
- }
- } else if (response.status_code >= 200 && response.status_code < 300) {
- this._eventHandlers.onSuccessResponse(response);
- } else if (response.status_code >= 300) {
- this._eventHandlers.onErrorResponse(response);
- }
- }
- }, {
- key: "request",
- get: function get() {
- return this._request;
- }
- }]);
- return DialogRequestSender;
- }();
- },{"../Constants":2,"../RTCSession":12,"../RequestSender":18,"../Transactions":22}],5:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var Utils = require('./Utils');
- var debug = require('debug')('JsSIP:DigestAuthentication');
- var debugerror = require('debug')('JsSIP:ERROR:DigestAuthentication');
- debugerror.log = console.warn.bind(console);
- module.exports =
- /*#__PURE__*/
- function () {
- function DigestAuthentication(credentials) {
- _classCallCheck(this, DigestAuthentication);
- this._credentials = credentials;
- this._cnonce = null;
- this._nc = 0;
- this._ncHex = '00000000';
- this._algorithm = null;
- this._realm = null;
- this._nonce = null;
- this._opaque = null;
- this._stale = null;
- this._qop = null;
- this._method = null;
- this._uri = null;
- this._ha1 = null;
- this._response = null;
- }
- _createClass(DigestAuthentication, [{
- key: "get",
- value: function get(parameter) {
- switch (parameter) {
- case 'realm':
- return this._realm;
- case 'ha1':
- return this._ha1;
- default:
- debugerror('get() | cannot get "%s" parameter', parameter);
- return undefined;
- }
- }
- /**
- * Performs Digest authentication given a SIP request and the challenge
- * received in a response to that request.
- * Returns true if auth was successfully generated, false otherwise.
- */
- }, {
- key: "authenticate",
- value: function authenticate(_ref, challenge)
- /* test interface */
- {
- var method = _ref.method,
- ruri = _ref.ruri,
- body = _ref.body;
- var cnonce = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
- this._algorithm = challenge.algorithm;
- this._realm = challenge.realm;
- this._nonce = challenge.nonce;
- this._opaque = challenge.opaque;
- this._stale = challenge.stale;
- if (this._algorithm) {
- if (this._algorithm !== 'MD5') {
- debugerror('authenticate() | challenge with Digest algorithm different than "MD5", authentication aborted');
- return false;
- }
- } else {
- this._algorithm = 'MD5';
- }
- if (!this._nonce) {
- debugerror('authenticate() | challenge without Digest nonce, authentication aborted');
- return false;
- }
- if (!this._realm) {
- debugerror('authenticate() | challenge without Digest realm, authentication aborted');
- return false;
- } // If no plain SIP password is provided.
- if (!this._credentials.password) {
- // If ha1 is not provided we cannot authenticate.
- if (!this._credentials.ha1) {
- debugerror('authenticate() | no plain SIP password nor ha1 provided, authentication aborted');
- return false;
- } // If the realm does not match the stored realm we cannot authenticate.
- if (this._credentials.realm !== this._realm) {
- debugerror('authenticate() | no plain SIP password, and stored `realm` does not match the given `realm`, cannot authenticate [stored:"%s", given:"%s"]', this._credentials.realm, this._realm);
- return false;
- }
- } // 'qop' can contain a list of values (Array). Let's choose just one.
- if (challenge.qop) {
- if (challenge.qop.indexOf('auth-int') > -1) {
- this._qop = 'auth-int';
- } else if (challenge.qop.indexOf('auth') > -1) {
- this._qop = 'auth';
- } else {
- // Otherwise 'qop' is present but does not contain 'auth' or 'auth-int', so abort here.
- debugerror('authenticate() | challenge without Digest qop different than "auth" or "auth-int", authentication aborted');
- return false;
- }
- } else {
- this._qop = null;
- } // Fill other attributes.
- this._method = method;
- this._uri = ruri;
- this._cnonce = cnonce || Utils.createRandomToken(12);
- this._nc += 1;
- var hex = Number(this._nc).toString(16);
- this._ncHex = '00000000'.substr(0, 8 - hex.length) + hex; // Nc-value = 8LHEX. Max value = 'FFFFFFFF'.
- if (this._nc === 4294967296) {
- this._nc = 1;
- this._ncHex = '00000001';
- } // Calculate the Digest "response" value.
- // If we have plain SIP password then regenerate ha1.
- if (this._credentials.password) {
- // HA1 = MD5(A1) = MD5(username:realm:password).
- this._ha1 = Utils.calculateMD5("".concat(this._credentials.username, ":").concat(this._realm, ":").concat(this._credentials.password));
- } // Otherwise reuse the stored ha1.
- else {
- this._ha1 = this._credentials.ha1;
- }
- var a2;
- var ha2;
- if (this._qop === 'auth') {
- // HA2 = MD5(A2) = MD5(method:digestURI).
- a2 = "".concat(this._method, ":").concat(this._uri);
- ha2 = Utils.calculateMD5(a2);
- debug('authenticate() | using qop=auth [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
- this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth:").concat(ha2));
- } else if (this._qop === 'auth-int') {
- // HA2 = MD5(A2) = MD5(method:digestURI:MD5(entityBody)).
- a2 = "".concat(this._method, ":").concat(this._uri, ":").concat(Utils.calculateMD5(body ? body : ''));
- ha2 = Utils.calculateMD5(a2);
- debug('authenticate() | using qop=auth-int [a2:"%s"]', a2); // Response = MD5(HA1:nonce:nonceCount:credentialsNonce:qop:HA2).
- this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(this._ncHex, ":").concat(this._cnonce, ":auth-int:").concat(ha2));
- } else if (this._qop === null) {
- // HA2 = MD5(A2) = MD5(method:digestURI).
- a2 = "".concat(this._method, ":").concat(this._uri);
- ha2 = Utils.calculateMD5(a2);
- debug('authenticate() | using qop=null [a2:"%s"]', a2); // Response = MD5(HA1:nonce:HA2).
- this._response = Utils.calculateMD5("".concat(this._ha1, ":").concat(this._nonce, ":").concat(ha2));
- }
- debug('authenticate() | response generated');
- return true;
- }
- /**
- * Return the Proxy-Authorization or WWW-Authorization header value.
- */
- }, {
- key: "toString",
- value: function toString() {
- var auth_params = [];
- if (!this._response) {
- throw new Error('response field does not exist, cannot generate Authorization header');
- }
- auth_params.push("algorithm=".concat(this._algorithm));
- auth_params.push("username=\"".concat(this._credentials.username, "\""));
- auth_params.push("realm=\"".concat(this._realm, "\""));
- auth_params.push("nonce=\"".concat(this._nonce, "\""));
- auth_params.push("uri=\"".concat(this._uri, "\""));
- auth_params.push("response=\"".concat(this._response, "\""));
- if (this._opaque) {
- auth_params.push("opaque=\"".concat(this._opaque, "\""));
- }
- if (this._qop) {
- auth_params.push("qop=".concat(this._qop));
- auth_params.push("cnonce=\"".concat(this._cnonce, "\""));
- auth_params.push("nc=".concat(this._ncHex));
- }
- return "Digest ".concat(auth_params.join(', '));
- }
- }]);
- return DigestAuthentication;
- }();
- },{"./Utils":26,"debug":30}],6:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
- function isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
- function _construct(Parent, args, Class) { if (isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- var ConfigurationError =
- /*#__PURE__*/
- function (_Error) {
- _inherits(ConfigurationError, _Error);
- function ConfigurationError(parameter, value) {
- var _this;
- _classCallCheck(this, ConfigurationError);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(ConfigurationError).call(this));
- _this.code = 1;
- _this.name = 'CONFIGURATION_ERROR';
- _this.parameter = parameter;
- _this.value = value;
- _this.message = !_this.value ? "Missing parameter: ".concat(_this.parameter) : "Invalid value ".concat(JSON.stringify(_this.value), " for parameter \"").concat(_this.parameter, "\"");
- return _this;
- }
- return ConfigurationError;
- }(_wrapNativeSuper(Error));
- var InvalidStateError =
- /*#__PURE__*/
- function (_Error2) {
- _inherits(InvalidStateError, _Error2);
- function InvalidStateError(status) {
- var _this2;
- _classCallCheck(this, InvalidStateError);
- _this2 = _possibleConstructorReturn(this, _getPrototypeOf(InvalidStateError).call(this));
- _this2.code = 2;
- _this2.name = 'INVALID_STATE_ERROR';
- _this2.status = status;
- _this2.message = "Invalid status: ".concat(status);
- return _this2;
- }
- return InvalidStateError;
- }(_wrapNativeSuper(Error));
- var NotSupportedError =
- /*#__PURE__*/
- function (_Error3) {
- _inherits(NotSupportedError, _Error3);
- function NotSupportedError(message) {
- var _this3;
- _classCallCheck(this, NotSupportedError);
- _this3 = _possibleConstructorReturn(this, _getPrototypeOf(NotSupportedError).call(this));
- _this3.code = 3;
- _this3.name = 'NOT_SUPPORTED_ERROR';
- _this3.message = message;
- return _this3;
- }
- return NotSupportedError;
- }(_wrapNativeSuper(Error));
- var NotReadyError =
- /*#__PURE__*/
- function (_Error4) {
- _inherits(NotReadyError, _Error4);
- function NotReadyError(message) {
- var _this4;
- _classCallCheck(this, NotReadyError);
- _this4 = _possibleConstructorReturn(this, _getPrototypeOf(NotReadyError).call(this));
- _this4.code = 4;
- _this4.name = 'NOT_READY_ERROR';
- _this4.message = message;
- return _this4;
- }
- return NotReadyError;
- }(_wrapNativeSuper(Error));
- module.exports = {
- ConfigurationError: ConfigurationError,
- InvalidStateError: InvalidStateError,
- NotSupportedError: NotSupportedError,
- NotReadyError: NotReadyError
- };
- },{}],7:[function(require,module,exports){
- "use strict";
- module.exports = function () {
- /*
- * Generated by PEG.js 0.7.0.
- *
- * http://pegjs.majda.cz/
- */
- function quote(s) {
- /*
- * ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
- * string literal except for the closing quote character, backslash,
- * carriage return, line separator, paragraph separator, and line feed.
- * Any character may appear in the form of an escape sequence.
- *
- * For portability, we also escape escape all control and non-ASCII
- * characters. Note that "\0" and "\v" escape sequences are not used
- * because JSHint does not like the first and IE the second.
- */
- return '"' + s.replace(/\\/g, '\\\\') // backslash
- .replace(/"/g, '\\"') // closing quote character
- .replace(/\x08/g, '\\b') // backspace
- .replace(/\t/g, '\\t') // horizontal tab
- .replace(/\n/g, '\\n') // line feed
- .replace(/\f/g, '\\f') // form feed
- .replace(/\r/g, '\\r') // carriage return
- .replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g, escape) + '"';
- }
- var result = {
- /*
- * Parses the input with a generated parser. If the parsing is successfull,
- * returns a value explicitly or implicitly specified by the grammar from
- * which the parser was generated (see |PEG.buildParser|). If the parsing is
- * unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
- */
- parse: function parse(input, startRule) {
- var parseFunctions = {
- "CRLF": parse_CRLF,
- "DIGIT": parse_DIGIT,
- "ALPHA": parse_ALPHA,
- "HEXDIG": parse_HEXDIG,
- "WSP": parse_WSP,
- "OCTET": parse_OCTET,
- "DQUOTE": parse_DQUOTE,
- "SP": parse_SP,
- "HTAB": parse_HTAB,
- "alphanum": parse_alphanum,
- "reserved": parse_reserved,
- "unreserved": parse_unreserved,
- "mark": parse_mark,
- "escaped": parse_escaped,
- "LWS": parse_LWS,
- "SWS": parse_SWS,
- "HCOLON": parse_HCOLON,
- "TEXT_UTF8_TRIM": parse_TEXT_UTF8_TRIM,
- "TEXT_UTF8char": parse_TEXT_UTF8char,
- "UTF8_NONASCII": parse_UTF8_NONASCII,
- "UTF8_CONT": parse_UTF8_CONT,
- "LHEX": parse_LHEX,
- "token": parse_token,
- "token_nodot": parse_token_nodot,
- "separators": parse_separators,
- "word": parse_word,
- "STAR": parse_STAR,
- "SLASH": parse_SLASH,
- "EQUAL": parse_EQUAL,
- "LPAREN": parse_LPAREN,
- "RPAREN": parse_RPAREN,
- "RAQUOT": parse_RAQUOT,
- "LAQUOT": parse_LAQUOT,
- "COMMA": parse_COMMA,
- "SEMI": parse_SEMI,
- "COLON": parse_COLON,
- "LDQUOT": parse_LDQUOT,
- "RDQUOT": parse_RDQUOT,
- "comment": parse_comment,
- "ctext": parse_ctext,
- "quoted_string": parse_quoted_string,
- "quoted_string_clean": parse_quoted_string_clean,
- "qdtext": parse_qdtext,
- "quoted_pair": parse_quoted_pair,
- "SIP_URI_noparams": parse_SIP_URI_noparams,
- "SIP_URI": parse_SIP_URI,
- "uri_scheme": parse_uri_scheme,
- "uri_scheme_sips": parse_uri_scheme_sips,
- "uri_scheme_sip": parse_uri_scheme_sip,
- "userinfo": parse_userinfo,
- "user": parse_user,
- "user_unreserved": parse_user_unreserved,
- "password": parse_password,
- "hostport": parse_hostport,
- "host": parse_host,
- "hostname": parse_hostname,
- "domainlabel": parse_domainlabel,
- "toplabel": parse_toplabel,
- "IPv6reference": parse_IPv6reference,
- "IPv6address": parse_IPv6address,
- "h16": parse_h16,
- "ls32": parse_ls32,
- "IPv4address": parse_IPv4address,
- "dec_octet": parse_dec_octet,
- "port": parse_port,
- "uri_parameters": parse_uri_parameters,
- "uri_parameter": parse_uri_parameter,
- "transport_param": parse_transport_param,
- "user_param": parse_user_param,
- "method_param": parse_method_param,
- "ttl_param": parse_ttl_param,
- "maddr_param": parse_maddr_param,
- "lr_param": parse_lr_param,
- "other_param": parse_other_param,
- "pname": parse_pname,
- "pvalue": parse_pvalue,
- "paramchar": parse_paramchar,
- "param_unreserved": parse_param_unreserved,
- "headers": parse_headers,
- "header": parse_header,
- "hname": parse_hname,
- "hvalue": parse_hvalue,
- "hnv_unreserved": parse_hnv_unreserved,
- "Request_Response": parse_Request_Response,
- "Request_Line": parse_Request_Line,
- "Request_URI": parse_Request_URI,
- "absoluteURI": parse_absoluteURI,
- "hier_part": parse_hier_part,
- "net_path": parse_net_path,
- "abs_path": parse_abs_path,
- "opaque_part": parse_opaque_part,
- "uric": parse_uric,
- "uric_no_slash": parse_uric_no_slash,
- "path_segments": parse_path_segments,
- "segment": parse_segment,
- "param": parse_param,
- "pchar": parse_pchar,
- "scheme": parse_scheme,
- "authority": parse_authority,
- "srvr": parse_srvr,
- "reg_name": parse_reg_name,
- "query": parse_query,
- "SIP_Version": parse_SIP_Version,
- "INVITEm": parse_INVITEm,
- "ACKm": parse_ACKm,
- "OPTIONSm": parse_OPTIONSm,
- "BYEm": parse_BYEm,
- "CANCELm": parse_CANCELm,
- "REGISTERm": parse_REGISTERm,
- "SUBSCRIBEm": parse_SUBSCRIBEm,
- "NOTIFYm": parse_NOTIFYm,
- "REFERm": parse_REFERm,
- "Method": parse_Method,
- "Status_Line": parse_Status_Line,
- "Status_Code": parse_Status_Code,
- "extension_code": parse_extension_code,
- "Reason_Phrase": parse_Reason_Phrase,
- "Allow_Events": parse_Allow_Events,
- "Call_ID": parse_Call_ID,
- "Contact": parse_Contact,
- "contact_param": parse_contact_param,
- "name_addr": parse_name_addr,
- "display_name": parse_display_name,
- "contact_params": parse_contact_params,
- "c_p_q": parse_c_p_q,
- "c_p_expires": parse_c_p_expires,
- "delta_seconds": parse_delta_seconds,
- "qvalue": parse_qvalue,
- "generic_param": parse_generic_param,
- "gen_value": parse_gen_value,
- "Content_Disposition": parse_Content_Disposition,
- "disp_type": parse_disp_type,
- "disp_param": parse_disp_param,
- "handling_param": parse_handling_param,
- "Content_Encoding": parse_Content_Encoding,
- "Content_Length": parse_Content_Length,
- "Content_Type": parse_Content_Type,
- "media_type": parse_media_type,
- "m_type": parse_m_type,
- "discrete_type": parse_discrete_type,
- "composite_type": parse_composite_type,
- "extension_token": parse_extension_token,
- "x_token": parse_x_token,
- "m_subtype": parse_m_subtype,
- "m_parameter": parse_m_parameter,
- "m_value": parse_m_value,
- "CSeq": parse_CSeq,
- "CSeq_value": parse_CSeq_value,
- "Expires": parse_Expires,
- "Event": parse_Event,
- "event_type": parse_event_type,
- "From": parse_From,
- "from_param": parse_from_param,
- "tag_param": parse_tag_param,
- "Max_Forwards": parse_Max_Forwards,
- "Min_Expires": parse_Min_Expires,
- "Name_Addr_Header": parse_Name_Addr_Header,
- "Proxy_Authenticate": parse_Proxy_Authenticate,
- "challenge": parse_challenge,
- "other_challenge": parse_other_challenge,
- "auth_param": parse_auth_param,
- "digest_cln": parse_digest_cln,
- "realm": parse_realm,
- "realm_value": parse_realm_value,
- "domain": parse_domain,
- "URI": parse_URI,
- "nonce": parse_nonce,
- "nonce_value": parse_nonce_value,
- "opaque": parse_opaque,
- "stale": parse_stale,
- "algorithm": parse_algorithm,
- "qop_options": parse_qop_options,
- "qop_value": parse_qop_value,
- "Proxy_Require": parse_Proxy_Require,
- "Record_Route": parse_Record_Route,
- "rec_route": parse_rec_route,
- "Reason": parse_Reason,
- "reason_param": parse_reason_param,
- "reason_cause": parse_reason_cause,
- "Require": parse_Require,
- "Route": parse_Route,
- "route_param": parse_route_param,
- "Subscription_State": parse_Subscription_State,
- "substate_value": parse_substate_value,
- "subexp_params": parse_subexp_params,
- "event_reason_value": parse_event_reason_value,
- "Subject": parse_Subject,
- "Supported": parse_Supported,
- "To": parse_To,
- "to_param": parse_to_param,
- "Via": parse_Via,
- "via_param": parse_via_param,
- "via_params": parse_via_params,
- "via_ttl": parse_via_ttl,
- "via_maddr": parse_via_maddr,
- "via_received": parse_via_received,
- "via_branch": parse_via_branch,
- "response_port": parse_response_port,
- "sent_protocol": parse_sent_protocol,
- "protocol_name": parse_protocol_name,
- "transport": parse_transport,
- "sent_by": parse_sent_by,
- "via_host": parse_via_host,
- "via_port": parse_via_port,
- "ttl": parse_ttl,
- "WWW_Authenticate": parse_WWW_Authenticate,
- "Session_Expires": parse_Session_Expires,
- "s_e_expires": parse_s_e_expires,
- "s_e_params": parse_s_e_params,
- "s_e_refresher": parse_s_e_refresher,
- "extension_header": parse_extension_header,
- "header_value": parse_header_value,
- "message_body": parse_message_body,
- "uuid_URI": parse_uuid_URI,
- "uuid": parse_uuid,
- "hex4": parse_hex4,
- "hex8": parse_hex8,
- "hex12": parse_hex12,
- "Refer_To": parse_Refer_To,
- "Replaces": parse_Replaces,
- "call_id": parse_call_id,
- "replaces_param": parse_replaces_param,
- "to_tag": parse_to_tag,
- "from_tag": parse_from_tag,
- "early_flag": parse_early_flag
- };
- if (startRule !== undefined) {
- if (parseFunctions[startRule] === undefined) {
- throw new Error("Invalid rule name: " + quote(startRule) + ".");
- }
- } else {
- startRule = "CRLF";
- }
- var pos = 0;
- var reportFailures = 0;
- var rightmostFailuresPos = 0;
- var rightmostFailuresExpected = [];
- function padLeft(input, padding, length) {
- var result = input;
- var padLength = length - input.length;
- for (var i = 0; i < padLength; i++) {
- result = padding + result;
- }
- return result;
- }
- function escape(ch) {
- var charCode = ch.charCodeAt(0);
- var escapeChar;
- var length;
- if (charCode <= 0xFF) {
- escapeChar = 'x';
- length = 2;
- } else {
- escapeChar = 'u';
- length = 4;
- }
- return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
- }
- function matchFailed(failure) {
- if (pos < rightmostFailuresPos) {
- return;
- }
- if (pos > rightmostFailuresPos) {
- rightmostFailuresPos = pos;
- rightmostFailuresExpected = [];
- }
- rightmostFailuresExpected.push(failure);
- }
- function parse_CRLF() {
- var result0;
- if (input.substr(pos, 2) === "\r\n") {
- result0 = "\r\n";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\r\\n\"");
- }
- }
- return result0;
- }
- function parse_DIGIT() {
- var result0;
- if (/^[0-9]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[0-9]");
- }
- }
- return result0;
- }
- function parse_ALPHA() {
- var result0;
- if (/^[a-zA-Z]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[a-zA-Z]");
- }
- }
- return result0;
- }
- function parse_HEXDIG() {
- var result0;
- if (/^[0-9a-fA-F]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[0-9a-fA-F]");
- }
- }
- return result0;
- }
- function parse_WSP() {
- var result0;
- result0 = parse_SP();
- if (result0 === null) {
- result0 = parse_HTAB();
- }
- return result0;
- }
- function parse_OCTET() {
- var result0;
- if (/^[\0-\xFF]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[\\0-\\xFF]");
- }
- }
- return result0;
- }
- function parse_DQUOTE() {
- var result0;
- if (/^["]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[\"]");
- }
- }
- return result0;
- }
- function parse_SP() {
- var result0;
- if (input.charCodeAt(pos) === 32) {
- result0 = " ";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\" \"");
- }
- }
- return result0;
- }
- function parse_HTAB() {
- var result0;
- if (input.charCodeAt(pos) === 9) {
- result0 = "\t";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\t\"");
- }
- }
- return result0;
- }
- function parse_alphanum() {
- var result0;
- if (/^[a-zA-Z0-9]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[a-zA-Z0-9]");
- }
- }
- return result0;
- }
- function parse_reserved() {
- var result0;
- if (input.charCodeAt(pos) === 59) {
- result0 = ";";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 47) {
- result0 = "/";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 63) {
- result0 = "?";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 58) {
- result0 = ":";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 64) {
- result0 = "@";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 38) {
- result0 = "&";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 61) {
- result0 = "=";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 43) {
- result0 = "+";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 36) {
- result0 = "$";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 44) {
- result0 = ",";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_unreserved() {
- var result0;
- result0 = parse_alphanum();
- if (result0 === null) {
- result0 = parse_mark();
- }
- return result0;
- }
- function parse_mark() {
- var result0;
- if (input.charCodeAt(pos) === 45) {
- result0 = "-";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 95) {
- result0 = "_";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 46) {
- result0 = ".";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 33) {
- result0 = "!";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 126) {
- result0 = "~";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 42) {
- result0 = "*";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 39) {
- result0 = "'";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 40) {
- result0 = "(";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"(\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 41) {
- result0 = ")";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\")\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_escaped() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.charCodeAt(pos) === 37) {
- result0 = "%";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_HEXDIG();
- if (result1 !== null) {
- result2 = parse_HEXDIG();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, escaped) {
- return escaped.join('');
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_LWS() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- pos2 = pos;
- result0 = [];
- result1 = parse_WSP();
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_WSP();
- }
- if (result0 !== null) {
- result1 = parse_CRLF();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos2;
- }
- } else {
- result0 = null;
- pos = pos2;
- }
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result2 = parse_WSP();
- if (result2 !== null) {
- result1 = [];
- while (result2 !== null) {
- result1.push(result2);
- result2 = parse_WSP();
- }
- } else {
- result1 = null;
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return " ";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_SWS() {
- var result0;
- result0 = parse_LWS();
- result0 = result0 !== null ? result0 : "";
- return result0;
- }
- function parse_HCOLON() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = [];
- result1 = parse_SP();
- if (result1 === null) {
- result1 = parse_HTAB();
- }
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_SP();
- if (result1 === null) {
- result1 = parse_HTAB();
- }
- }
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return ':';
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_TEXT_UTF8_TRIM() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result1 = parse_TEXT_UTF8char();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_TEXT_UTF8char();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = [];
- result3 = parse_LWS();
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_LWS();
- }
- if (result2 !== null) {
- result3 = parse_TEXT_UTF8char();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = [];
- result3 = parse_LWS();
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_LWS();
- }
- if (result2 !== null) {
- result3 = parse_TEXT_UTF8char();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_TEXT_UTF8char() {
- var result0;
- if (/^[!-~]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[!-~]");
- }
- }
- if (result0 === null) {
- result0 = parse_UTF8_NONASCII();
- }
- return result0;
- }
- function parse_UTF8_NONASCII() {
- var result0;
- if (/^[\x80-\uFFFF]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[\\x80-\\uFFFF]");
- }
- }
- return result0;
- }
- function parse_UTF8_CONT() {
- var result0;
- if (/^[\x80-\xBF]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[\\x80-\\xBF]");
- }
- }
- return result0;
- }
- function parse_LHEX() {
- var result0;
- result0 = parse_DIGIT();
- if (result0 === null) {
- if (/^[a-f]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[a-f]");
- }
- }
- }
- return result0;
- }
- function parse_token() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_alphanum();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 46) {
- result1 = ".";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 33) {
- result1 = "!";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 37) {
- result1 = "%";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 95) {
- result1 = "_";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 96) {
- result1 = "`";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"`\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 39) {
- result1 = "'";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 126) {
- result1 = "~";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_alphanum();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 46) {
- result1 = ".";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 33) {
- result1 = "!";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 37) {
- result1 = "%";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 95) {
- result1 = "_";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 96) {
- result1 = "`";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"`\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 39) {
- result1 = "'";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 126) {
- result1 = "~";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_token_nodot() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_alphanum();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 33) {
- result1 = "!";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 37) {
- result1 = "%";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 95) {
- result1 = "_";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 96) {
- result1 = "`";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"`\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 39) {
- result1 = "'";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 126) {
- result1 = "~";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_alphanum();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 33) {
- result1 = "!";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 37) {
- result1 = "%";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 95) {
- result1 = "_";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 96) {
- result1 = "`";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"`\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 39) {
- result1 = "'";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 126) {
- result1 = "~";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_separators() {
- var result0;
- if (input.charCodeAt(pos) === 40) {
- result0 = "(";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"(\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 41) {
- result0 = ")";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\")\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 60) {
- result0 = "<";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"<\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 62) {
- result0 = ">";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\">\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 64) {
- result0 = "@";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 44) {
- result0 = ",";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 59) {
- result0 = ";";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 58) {
- result0 = ":";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 92) {
- result0 = "\\";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\\\\"");
- }
- }
- if (result0 === null) {
- result0 = parse_DQUOTE();
- if (result0 === null) {
- if (input.charCodeAt(pos) === 47) {
- result0 = "/";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 91) {
- result0 = "[";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"[\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 93) {
- result0 = "]";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"]\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 63) {
- result0 = "?";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 61) {
- result0 = "=";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 123) {
- result0 = "{";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"{\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 125) {
- result0 = "}";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"}\"");
- }
- }
- if (result0 === null) {
- result0 = parse_SP();
- if (result0 === null) {
- result0 = parse_HTAB();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_word() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_alphanum();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 46) {
- result1 = ".";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 33) {
- result1 = "!";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 37) {
- result1 = "%";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 95) {
- result1 = "_";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 96) {
- result1 = "`";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"`\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 39) {
- result1 = "'";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 126) {
- result1 = "~";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 40) {
- result1 = "(";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"(\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 41) {
- result1 = ")";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\")\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 60) {
- result1 = "<";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"<\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 62) {
- result1 = ">";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\">\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 92) {
- result1 = "\\";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\\\\"");
- }
- }
- if (result1 === null) {
- result1 = parse_DQUOTE();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 47) {
- result1 = "/";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 91) {
- result1 = "[";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"[\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 93) {
- result1 = "]";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"]\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 63) {
- result1 = "?";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 123) {
- result1 = "{";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"{\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 125) {
- result1 = "}";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"}\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_alphanum();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 46) {
- result1 = ".";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 33) {
- result1 = "!";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 37) {
- result1 = "%";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"%\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 95) {
- result1 = "_";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 96) {
- result1 = "`";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"`\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 39) {
- result1 = "'";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"'\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 126) {
- result1 = "~";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"~\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 40) {
- result1 = "(";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"(\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 41) {
- result1 = ")";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\")\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 60) {
- result1 = "<";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"<\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 62) {
- result1 = ">";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\">\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 92) {
- result1 = "\\";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\\\\"");
- }
- }
- if (result1 === null) {
- result1 = parse_DQUOTE();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 47) {
- result1 = "/";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 91) {
- result1 = "[";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"[\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 93) {
- result1 = "]";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"]\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 63) {
- result1 = "?";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 123) {
- result1 = "{";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"{\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 125) {
- result1 = "}";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"}\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_STAR() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 42) {
- result1 = "*";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"*\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "*";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_SLASH() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 47) {
- result1 = "/";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "/";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_EQUAL() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "=";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_LPAREN() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 40) {
- result1 = "(";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"(\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "(";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_RPAREN() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 41) {
- result1 = ")";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\")\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return ")";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_RAQUOT() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.charCodeAt(pos) === 62) {
- result0 = ">";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\">\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_SWS();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return ">";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_LAQUOT() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 60) {
- result1 = "<";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"<\"");
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "<";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_COMMA() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 44) {
- result1 = ",";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return ",";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_SEMI() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 59) {
- result1 = ";";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return ";";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_COLON() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_SWS();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return ":";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_LDQUOT() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- result1 = parse_DQUOTE();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "\"";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_RDQUOT() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_DQUOTE();
- if (result0 !== null) {
- result1 = parse_SWS();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return "\"";
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_comment() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_LPAREN();
- if (result0 !== null) {
- result1 = [];
- result2 = parse_ctext();
- if (result2 === null) {
- result2 = parse_quoted_pair();
- if (result2 === null) {
- result2 = parse_comment();
- }
- }
- while (result2 !== null) {
- result1.push(result2);
- result2 = parse_ctext();
- if (result2 === null) {
- result2 = parse_quoted_pair();
- if (result2 === null) {
- result2 = parse_comment();
- }
- }
- }
- if (result1 !== null) {
- result2 = parse_RPAREN();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_ctext() {
- var result0;
- if (/^[!-']/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[!-']");
- }
- }
- if (result0 === null) {
- if (/^[*-[]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[*-[]");
- }
- }
- if (result0 === null) {
- if (/^[\]-~]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[\\]-~]");
- }
- }
- if (result0 === null) {
- result0 = parse_UTF8_NONASCII();
- if (result0 === null) {
- result0 = parse_LWS();
- }
- }
- }
- }
- return result0;
- }
- function parse_quoted_string() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- result1 = parse_DQUOTE();
- if (result1 !== null) {
- result2 = [];
- result3 = parse_qdtext();
- if (result3 === null) {
- result3 = parse_quoted_pair();
- }
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_qdtext();
- if (result3 === null) {
- result3 = parse_quoted_pair();
- }
- }
- if (result2 !== null) {
- result3 = parse_DQUOTE();
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_quoted_string_clean() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SWS();
- if (result0 !== null) {
- result1 = parse_DQUOTE();
- if (result1 !== null) {
- result2 = [];
- result3 = parse_qdtext();
- if (result3 === null) {
- result3 = parse_quoted_pair();
- }
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_qdtext();
- if (result3 === null) {
- result3 = parse_quoted_pair();
- }
- }
- if (result2 !== null) {
- result3 = parse_DQUOTE();
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var trimmed = input.substring(pos, offset).trim();
- return trimmed.substring(1, trimmed.length - 1) // remove outer quotes
- .replace(/\\([\x00-\x09\x0b-\x0c\x0e-\x7f])/g, '$1');
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_qdtext() {
- var result0;
- result0 = parse_LWS();
- if (result0 === null) {
- if (input.charCodeAt(pos) === 33) {
- result0 = "!";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"!\"");
- }
- }
- if (result0 === null) {
- if (/^[#-[]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[#-[]");
- }
- }
- if (result0 === null) {
- if (/^[\]-~]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[\\]-~]");
- }
- }
- if (result0 === null) {
- result0 = parse_UTF8_NONASCII();
- }
- }
- }
- }
- return result0;
- }
- function parse_quoted_pair() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- if (input.charCodeAt(pos) === 92) {
- result0 = "\\";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"\\\\\"");
- }
- }
- if (result0 !== null) {
- if (/^[\0-\t]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[\\0-\\t]");
- }
- }
- if (result1 === null) {
- if (/^[\x0B-\f]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[\\x0B-\\f]");
- }
- }
- if (result1 === null) {
- if (/^[\x0E-]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[\\x0E-]");
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_SIP_URI_noparams() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_uri_scheme();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_userinfo();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result3 = parse_hostport();
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- try {
- data.uri = new URI(data.scheme, data.user, data.host, data.port);
- delete data.scheme;
- delete data.user;
- delete data.host;
- delete data.host_type;
- delete data.port;
- } catch (e) {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_SIP_URI() {
- var result0, result1, result2, result3, result4, result5;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_uri_scheme();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_userinfo();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result3 = parse_hostport();
- if (result3 !== null) {
- result4 = parse_uri_parameters();
- if (result4 !== null) {
- result5 = parse_headers();
- result5 = result5 !== null ? result5 : "";
- if (result5 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var header;
- try {
- data.uri = new URI(data.scheme, data.user, data.host, data.port, data.uri_params, data.uri_headers);
- delete data.scheme;
- delete data.user;
- delete data.host;
- delete data.host_type;
- delete data.port;
- delete data.uri_params;
- if (startRule === 'SIP_URI') {
- data = data.uri;
- }
- } catch (e) {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_uri_scheme() {
- var result0;
- result0 = parse_uri_scheme_sips();
- if (result0 === null) {
- result0 = parse_uri_scheme_sip();
- }
- return result0;
- }
- function parse_uri_scheme_sips() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 4).toLowerCase() === "sips") {
- result0 = input.substr(pos, 4);
- pos += 4;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"sips\"");
- }
- }
- if (result0 !== null) {
- result0 = function (offset, scheme) {
- data.scheme = scheme.toLowerCase();
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_uri_scheme_sip() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 3).toLowerCase() === "sip") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"sip\"");
- }
- }
- if (result0 !== null) {
- result0 = function (offset, scheme) {
- data.scheme = scheme.toLowerCase();
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_userinfo() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_user();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_password();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 64) {
- result2 = "@";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.user = decodeURIComponent(input.substring(pos - 1, offset));
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_user() {
- var result0, result1;
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- result1 = parse_user_unreserved();
- }
- }
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- result1 = parse_user_unreserved();
- }
- }
- }
- } else {
- result0 = null;
- }
- return result0;
- }
- function parse_user_unreserved() {
- var result0;
- if (input.charCodeAt(pos) === 38) {
- result0 = "&";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 61) {
- result0 = "=";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 43) {
- result0 = "+";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 36) {
- result0 = "$";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 44) {
- result0 = ",";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 59) {
- result0 = ";";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 63) {
- result0 = "?";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 47) {
- result0 = "/";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_password() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result0 = [];
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 38) {
- result1 = "&";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 36) {
- result1 = "$";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 44) {
- result1 = ",";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- }
- }
- }
- }
- }
- }
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 38) {
- result1 = "&";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 36) {
- result1 = "$";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 44) {
- result1 = ",";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.password = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_hostport() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_host();
- if (result0 !== null) {
- pos1 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_port();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos1;
- }
- } else {
- result1 = null;
- pos = pos1;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_host() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_hostname();
- if (result0 === null) {
- result0 = parse_IPv4address();
- if (result0 === null) {
- result0 = parse_IPv6reference();
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.host = input.substring(pos, offset).toLowerCase();
- return data.host;
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_hostname() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = [];
- pos2 = pos;
- result1 = parse_domainlabel();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- while (result1 !== null) {
- result0.push(result1);
- pos2 = pos;
- result1 = parse_domainlabel();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- }
- if (result0 !== null) {
- result1 = parse_toplabel();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.host_type = 'domain';
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_domainlabel() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_alphanum();
- if (result0 !== null) {
- result1 = [];
- result2 = parse_alphanum();
- if (result2 === null) {
- if (input.charCodeAt(pos) === 45) {
- result2 = "-";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 95) {
- result2 = "_";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- }
- }
- while (result2 !== null) {
- result1.push(result2);
- result2 = parse_alphanum();
- if (result2 === null) {
- if (input.charCodeAt(pos) === 45) {
- result2 = "-";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 95) {
- result2 = "_";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_toplabel() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_ALPHA();
- if (result0 !== null) {
- result1 = [];
- result2 = parse_alphanum();
- if (result2 === null) {
- if (input.charCodeAt(pos) === 45) {
- result2 = "-";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 95) {
- result2 = "_";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- }
- }
- while (result2 !== null) {
- result1.push(result2);
- result2 = parse_alphanum();
- if (result2 === null) {
- if (input.charCodeAt(pos) === 45) {
- result2 = "-";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 95) {
- result2 = "_";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"_\"");
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_IPv6reference() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.charCodeAt(pos) === 91) {
- result0 = "[";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"[\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_IPv6address();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 93) {
- result2 = "]";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"]\"");
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.host_type = 'IPv6';
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_IPv6address() {
- var result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result3 = ":";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result5 = ":";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_h16();
- if (result6 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result7 = ":";
- pos++;
- } else {
- result7 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result7 !== null) {
- result8 = parse_h16();
- if (result8 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result9 = ":";
- pos++;
- } else {
- result9 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result9 !== null) {
- result10 = parse_h16();
- if (result10 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result11 = ":";
- pos++;
- } else {
- result11 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result11 !== null) {
- result12 = parse_ls32();
- if (result12 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11, result12];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_h16();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result6 = ":";
- pos++;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_h16();
- if (result7 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result8 = ":";
- pos++;
- } else {
- result8 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result8 !== null) {
- result9 = parse_h16();
- if (result9 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result10 = ":";
- pos++;
- } else {
- result10 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result10 !== null) {
- result11 = parse_ls32();
- if (result11 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10, result11];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_h16();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result6 = ":";
- pos++;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_h16();
- if (result7 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result8 = ":";
- pos++;
- } else {
- result8 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result8 !== null) {
- result9 = parse_ls32();
- if (result9 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_h16();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result6 = ":";
- pos++;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_ls32();
- if (result7 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_h16();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_ls32();
- if (result5 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_h16();
- if (result1 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_ls32();
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_ls32();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- if (input.substr(pos, 2) === "::") {
- result0 = "::";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_h16();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- if (input.substr(pos, 2) === "::") {
- result1 = "::";
- pos += 2;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result3 = ":";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result5 = ":";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_h16();
- if (result6 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result7 = ":";
- pos++;
- } else {
- result7 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result7 !== null) {
- result8 = parse_h16();
- if (result8 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result9 = ":";
- pos++;
- } else {
- result9 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result9 !== null) {
- result10 = parse_ls32();
- if (result10 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9, result10];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- if (input.substr(pos, 2) === "::") {
- result2 = "::";
- pos += 2;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result6 = ":";
- pos++;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_h16();
- if (result7 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result8 = ":";
- pos++;
- } else {
- result8 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result8 !== null) {
- result9 = parse_ls32();
- if (result9 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8, result9];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- if (input.substr(pos, 2) === "::") {
- result3 = "::";
- pos += 2;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result5 = ":";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_h16();
- if (result6 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result7 = ":";
- pos++;
- } else {
- result7 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result7 !== null) {
- result8 = parse_ls32();
- if (result8 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result3 = ":";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos2;
- }
- } else {
- result3 = null;
- pos = pos2;
- }
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- if (input.substr(pos, 2) === "::") {
- result4 = "::";
- pos += 2;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result6 = ":";
- pos++;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_ls32();
- if (result7 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result3 = ":";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos2;
- }
- } else {
- result3 = null;
- pos = pos2;
- }
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos2;
- }
- } else {
- result4 = null;
- pos = pos2;
- }
- result4 = result4 !== null ? result4 : "";
- if (result4 !== null) {
- if (input.substr(pos, 2) === "::") {
- result5 = "::";
- pos += 2;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_ls32();
- if (result6 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result3 = ":";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos2;
- }
- } else {
- result3 = null;
- pos = pos2;
- }
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos2;
- }
- } else {
- result4 = null;
- pos = pos2;
- }
- result4 = result4 !== null ? result4 : "";
- if (result4 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result5 = ":";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_h16();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos2;
- }
- } else {
- result5 = null;
- pos = pos2;
- }
- result5 = result5 !== null ? result5 : "";
- if (result5 !== null) {
- if (input.substr(pos, 2) === "::") {
- result6 = "::";
- pos += 2;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_h16();
- if (result7 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result2 = ":";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_h16();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result3 = ":";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_h16();
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos2;
- }
- } else {
- result3 = null;
- pos = pos2;
- }
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result4 = ":";
- pos++;
- } else {
- result4 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result4 !== null) {
- result5 = parse_h16();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos2;
- }
- } else {
- result4 = null;
- pos = pos2;
- }
- result4 = result4 !== null ? result4 : "";
- if (result4 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result5 = ":";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_h16();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos2;
- }
- } else {
- result5 = null;
- pos = pos2;
- }
- result5 = result5 !== null ? result5 : "";
- if (result5 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 58) {
- result6 = ":";
- pos++;
- } else {
- result6 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result6 !== null) {
- result7 = parse_h16();
- if (result7 !== null) {
- result6 = [result6, result7];
- } else {
- result6 = null;
- pos = pos2;
- }
- } else {
- result6 = null;
- pos = pos2;
- }
- result6 = result6 !== null ? result6 : "";
- if (result6 !== null) {
- if (input.substr(pos, 2) === "::") {
- result7 = "::";
- pos += 2;
- } else {
- result7 = null;
- if (reportFailures === 0) {
- matchFailed("\"::\"");
- }
- }
- if (result7 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.host_type = 'IPv6';
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_h16() {
- var result0, result1, result2, result3;
- var pos0;
- pos0 = pos;
- result0 = parse_HEXDIG();
- if (result0 !== null) {
- result1 = parse_HEXDIG();
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result2 = parse_HEXDIG();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result3 = parse_HEXDIG();
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_ls32() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_h16();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_h16();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- if (result0 === null) {
- result0 = parse_IPv4address();
- }
- return result0;
- }
- function parse_IPv4address() {
- var result0, result1, result2, result3, result4, result5, result6;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_dec_octet();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result1 = ".";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_dec_octet();
- if (result2 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result3 = ".";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_dec_octet();
- if (result4 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result5 = ".";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_dec_octet();
- if (result6 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.host_type = 'IPv4';
- return input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_dec_octet() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 2) === "25") {
- result0 = "25";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"25\"");
- }
- }
- if (result0 !== null) {
- if (/^[0-5]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[0-5]");
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- if (result0 === null) {
- pos0 = pos;
- if (input.charCodeAt(pos) === 50) {
- result0 = "2";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"2\"");
- }
- }
- if (result0 !== null) {
- if (/^[0-4]/.test(input.charAt(pos))) {
- result1 = input.charAt(pos);
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("[0-4]");
- }
- }
- if (result1 !== null) {
- result2 = parse_DIGIT();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- if (result0 === null) {
- pos0 = pos;
- if (input.charCodeAt(pos) === 49) {
- result0 = "1";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"1\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result2 = parse_DIGIT();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- if (result0 === null) {
- pos0 = pos;
- if (/^[1-9]/.test(input.charAt(pos))) {
- result0 = input.charAt(pos);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("[1-9]");
- }
- }
- if (result0 !== null) {
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- if (result0 === null) {
- result0 = parse_DIGIT();
- }
- }
- }
- }
- return result0;
- }
- function parse_port() {
- var result0, result1, result2, result3, result4;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_DIGIT();
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result1 = parse_DIGIT();
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result2 = parse_DIGIT();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result3 = parse_DIGIT();
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- result4 = parse_DIGIT();
- result4 = result4 !== null ? result4 : "";
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, port) {
- port = parseInt(port.join(''));
- data.port = port;
- return port;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_uri_parameters() {
- var result0, result1, result2;
- var pos0;
- result0 = [];
- pos0 = pos;
- if (input.charCodeAt(pos) === 59) {
- result1 = ";";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_uri_parameter();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos0;
- }
- } else {
- result1 = null;
- pos = pos0;
- }
- while (result1 !== null) {
- result0.push(result1);
- pos0 = pos;
- if (input.charCodeAt(pos) === 59) {
- result1 = ";";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_uri_parameter();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos0;
- }
- } else {
- result1 = null;
- pos = pos0;
- }
- }
- return result0;
- }
- function parse_uri_parameter() {
- var result0;
- result0 = parse_transport_param();
- if (result0 === null) {
- result0 = parse_user_param();
- if (result0 === null) {
- result0 = parse_method_param();
- if (result0 === null) {
- result0 = parse_ttl_param();
- if (result0 === null) {
- result0 = parse_maddr_param();
- if (result0 === null) {
- result0 = parse_lr_param();
- if (result0 === null) {
- result0 = parse_other_param();
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_transport_param() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 10).toLowerCase() === "transport=") {
- result0 = input.substr(pos, 10);
- pos += 10;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"transport=\"");
- }
- }
- if (result0 !== null) {
- if (input.substr(pos, 3).toLowerCase() === "udp") {
- result1 = input.substr(pos, 3);
- pos += 3;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"udp\"");
- }
- }
- if (result1 === null) {
- if (input.substr(pos, 3).toLowerCase() === "tcp") {
- result1 = input.substr(pos, 3);
- pos += 3;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"tcp\"");
- }
- }
- if (result1 === null) {
- if (input.substr(pos, 4).toLowerCase() === "sctp") {
- result1 = input.substr(pos, 4);
- pos += 4;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"sctp\"");
- }
- }
- if (result1 === null) {
- if (input.substr(pos, 3).toLowerCase() === "tls") {
- result1 = input.substr(pos, 3);
- pos += 3;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"tls\"");
- }
- }
- if (result1 === null) {
- result1 = parse_token();
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, transport) {
- if (!data.uri_params) data.uri_params = {};
- data.uri_params['transport'] = transport.toLowerCase();
- }(pos0, result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_user_param() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 5).toLowerCase() === "user=") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"user=\"");
- }
- }
- if (result0 !== null) {
- if (input.substr(pos, 5).toLowerCase() === "phone") {
- result1 = input.substr(pos, 5);
- pos += 5;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"phone\"");
- }
- }
- if (result1 === null) {
- if (input.substr(pos, 2).toLowerCase() === "ip") {
- result1 = input.substr(pos, 2);
- pos += 2;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"ip\"");
- }
- }
- if (result1 === null) {
- result1 = parse_token();
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, user) {
- if (!data.uri_params) data.uri_params = {};
- data.uri_params['user'] = user.toLowerCase();
- }(pos0, result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_method_param() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 7).toLowerCase() === "method=") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"method=\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_Method();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, method) {
- if (!data.uri_params) data.uri_params = {};
- data.uri_params['method'] = method;
- }(pos0, result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_ttl_param() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 4).toLowerCase() === "ttl=") {
- result0 = input.substr(pos, 4);
- pos += 4;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"ttl=\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_ttl();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, ttl) {
- if (!data.params) data.params = {};
- data.params['ttl'] = ttl;
- }(pos0, result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_maddr_param() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 6).toLowerCase() === "maddr=") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"maddr=\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_host();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, maddr) {
- if (!data.uri_params) data.uri_params = {};
- data.uri_params['maddr'] = maddr;
- }(pos0, result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_lr_param() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 2).toLowerCase() === "lr") {
- result0 = input.substr(pos, 2);
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"lr\"");
- }
- }
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- if (!data.uri_params) data.uri_params = {};
- data.uri_params['lr'] = undefined;
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_other_param() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_pname();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_pvalue();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, param, value) {
- if (!data.uri_params) data.uri_params = {};
- if (typeof value === 'undefined') {
- value = undefined;
- } else {
- value = value[1];
- }
- data.uri_params[param.toLowerCase()] = value;
- }(pos0, result0[0], result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_pname() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_paramchar();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_paramchar();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset, pname) {
- return pname.join('');
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_pvalue() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_paramchar();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_paramchar();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset, pvalue) {
- return pvalue.join('');
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_paramchar() {
- var result0;
- result0 = parse_param_unreserved();
- if (result0 === null) {
- result0 = parse_unreserved();
- if (result0 === null) {
- result0 = parse_escaped();
- }
- }
- return result0;
- }
- function parse_param_unreserved() {
- var result0;
- if (input.charCodeAt(pos) === 91) {
- result0 = "[";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"[\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 93) {
- result0 = "]";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"]\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 47) {
- result0 = "/";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 58) {
- result0 = ":";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 38) {
- result0 = "&";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 43) {
- result0 = "+";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 36) {
- result0 = "$";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_headers() {
- var result0, result1, result2, result3, result4;
- var pos0, pos1;
- pos0 = pos;
- if (input.charCodeAt(pos) === 63) {
- result0 = "?";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_header();
- if (result1 !== null) {
- result2 = [];
- pos1 = pos;
- if (input.charCodeAt(pos) === 38) {
- result3 = "&";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_header();
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos1;
- }
- } else {
- result3 = null;
- pos = pos1;
- }
- while (result3 !== null) {
- result2.push(result3);
- pos1 = pos;
- if (input.charCodeAt(pos) === 38) {
- result3 = "&";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_header();
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos1;
- }
- } else {
- result3 = null;
- pos = pos1;
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_header() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_hname();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_hvalue();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, hname, hvalue) {
- hname = hname.join('').toLowerCase();
- hvalue = hvalue.join('');
- if (!data.uri_headers) data.uri_headers = {};
- if (!data.uri_headers[hname]) {
- data.uri_headers[hname] = [hvalue];
- } else {
- data.uri_headers[hname].push(hvalue);
- }
- }(pos0, result0[0], result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_hname() {
- var result0, result1;
- result1 = parse_hnv_unreserved();
- if (result1 === null) {
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- }
- }
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_hnv_unreserved();
- if (result1 === null) {
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- }
- }
- }
- } else {
- result0 = null;
- }
- return result0;
- }
- function parse_hvalue() {
- var result0, result1;
- result0 = [];
- result1 = parse_hnv_unreserved();
- if (result1 === null) {
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- }
- }
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_hnv_unreserved();
- if (result1 === null) {
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- }
- }
- }
- return result0;
- }
- function parse_hnv_unreserved() {
- var result0;
- if (input.charCodeAt(pos) === 91) {
- result0 = "[";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"[\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 93) {
- result0 = "]";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"]\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 47) {
- result0 = "/";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 63) {
- result0 = "?";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 58) {
- result0 = ":";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 43) {
- result0 = "+";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 36) {
- result0 = "$";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_Request_Response() {
- var result0;
- result0 = parse_Status_Line();
- if (result0 === null) {
- result0 = parse_Request_Line();
- }
- return result0;
- }
- function parse_Request_Line() {
- var result0, result1, result2, result3, result4;
- var pos0;
- pos0 = pos;
- result0 = parse_Method();
- if (result0 !== null) {
- result1 = parse_SP();
- if (result1 !== null) {
- result2 = parse_Request_URI();
- if (result2 !== null) {
- result3 = parse_SP();
- if (result3 !== null) {
- result4 = parse_SIP_Version();
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Request_URI() {
- var result0;
- result0 = parse_SIP_URI();
- if (result0 === null) {
- result0 = parse_absoluteURI();
- }
- return result0;
- }
- function parse_absoluteURI() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_scheme();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_hier_part();
- if (result2 === null) {
- result2 = parse_opaque_part();
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_hier_part() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_net_path();
- if (result0 === null) {
- result0 = parse_abs_path();
- }
- if (result0 !== null) {
- pos1 = pos;
- if (input.charCodeAt(pos) === 63) {
- result1 = "?";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_query();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos1;
- }
- } else {
- result1 = null;
- pos = pos1;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_net_path() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 2) === "//") {
- result0 = "//";
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"//\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_authority();
- if (result1 !== null) {
- result2 = parse_abs_path();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_abs_path() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- if (input.charCodeAt(pos) === 47) {
- result0 = "/";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_path_segments();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_opaque_part() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_uric_no_slash();
- if (result0 !== null) {
- result1 = [];
- result2 = parse_uric();
- while (result2 !== null) {
- result1.push(result2);
- result2 = parse_uric();
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_uric() {
- var result0;
- result0 = parse_reserved();
- if (result0 === null) {
- result0 = parse_unreserved();
- if (result0 === null) {
- result0 = parse_escaped();
- }
- }
- return result0;
- }
- function parse_uric_no_slash() {
- var result0;
- result0 = parse_unreserved();
- if (result0 === null) {
- result0 = parse_escaped();
- if (result0 === null) {
- if (input.charCodeAt(pos) === 59) {
- result0 = ";";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 63) {
- result0 = "?";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"?\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 58) {
- result0 = ":";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 64) {
- result0 = "@";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 38) {
- result0 = "&";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 61) {
- result0 = "=";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 43) {
- result0 = "+";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 36) {
- result0 = "$";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 44) {
- result0 = ",";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_path_segments() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_segment();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- if (input.charCodeAt(pos) === 47) {
- result2 = "/";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_segment();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- if (input.charCodeAt(pos) === 47) {
- result2 = "/";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_segment();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_segment() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = [];
- result1 = parse_pchar();
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_pchar();
- }
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- if (input.charCodeAt(pos) === 59) {
- result2 = ";";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- if (input.charCodeAt(pos) === 59) {
- result2 = ";";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_param() {
- var result0, result1;
- result0 = [];
- result1 = parse_pchar();
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_pchar();
- }
- return result0;
- }
- function parse_pchar() {
- var result0;
- result0 = parse_unreserved();
- if (result0 === null) {
- result0 = parse_escaped();
- if (result0 === null) {
- if (input.charCodeAt(pos) === 58) {
- result0 = ":";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 64) {
- result0 = "@";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 38) {
- result0 = "&";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 61) {
- result0 = "=";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 43) {
- result0 = "+";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 36) {
- result0 = "$";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result0 === null) {
- if (input.charCodeAt(pos) === 44) {
- result0 = ",";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_scheme() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_ALPHA();
- if (result0 !== null) {
- result1 = [];
- result2 = parse_ALPHA();
- if (result2 === null) {
- result2 = parse_DIGIT();
- if (result2 === null) {
- if (input.charCodeAt(pos) === 43) {
- result2 = "+";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 45) {
- result2 = "-";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- }
- }
- }
- }
- while (result2 !== null) {
- result1.push(result2);
- result2 = parse_ALPHA();
- if (result2 === null) {
- result2 = parse_DIGIT();
- if (result2 === null) {
- if (input.charCodeAt(pos) === 43) {
- result2 = "+";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 45) {
- result2 = "-";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result2 === null) {
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.scheme = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_authority() {
- var result0;
- result0 = parse_srvr();
- if (result0 === null) {
- result0 = parse_reg_name();
- }
- return result0;
- }
- function parse_srvr() {
- var result0, result1;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_userinfo();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 64) {
- result1 = "@";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result1 = parse_hostport();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- result0 = result0 !== null ? result0 : "";
- return result0;
- }
- function parse_reg_name() {
- var result0, result1;
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 36) {
- result1 = "$";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 44) {
- result1 = ",";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 59) {
- result1 = ";";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 64) {
- result1 = "@";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 38) {
- result1 = "&";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- if (input.charCodeAt(pos) === 36) {
- result1 = "$";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"$\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 44) {
- result1 = ",";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 59) {
- result1 = ";";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\";\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 58) {
- result1 = ":";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\":\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 64) {
- result1 = "@";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 38) {
- result1 = "&";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"&\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 61) {
- result1 = "=";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"=\"");
- }
- }
- if (result1 === null) {
- if (input.charCodeAt(pos) === 43) {
- result1 = "+";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"+\"");
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- } else {
- result0 = null;
- }
- return result0;
- }
- function parse_query() {
- var result0, result1;
- result0 = [];
- result1 = parse_uric();
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_uric();
- }
- return result0;
- }
- function parse_SIP_Version() {
- var result0, result1, result2, result3, result4, result5;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 3).toLowerCase() === "sip") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"SIP\"");
- }
- }
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 47) {
- result1 = "/";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"/\"");
- }
- }
- if (result1 !== null) {
- result3 = parse_DIGIT();
- if (result3 !== null) {
- result2 = [];
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_DIGIT();
- }
- } else {
- result2 = null;
- }
- if (result2 !== null) {
- if (input.charCodeAt(pos) === 46) {
- result3 = ".";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result3 !== null) {
- result5 = parse_DIGIT();
- if (result5 !== null) {
- result4 = [];
- while (result5 !== null) {
- result4.push(result5);
- result5 = parse_DIGIT();
- }
- } else {
- result4 = null;
- }
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.sip_version = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_INVITEm() {
- var result0;
- if (input.substr(pos, 6) === "INVITE") {
- result0 = "INVITE";
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"INVITE\"");
- }
- }
- return result0;
- }
- function parse_ACKm() {
- var result0;
- if (input.substr(pos, 3) === "ACK") {
- result0 = "ACK";
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"ACK\"");
- }
- }
- return result0;
- }
- function parse_OPTIONSm() {
- var result0;
- if (input.substr(pos, 7) === "OPTIONS") {
- result0 = "OPTIONS";
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"OPTIONS\"");
- }
- }
- return result0;
- }
- function parse_BYEm() {
- var result0;
- if (input.substr(pos, 3) === "BYE") {
- result0 = "BYE";
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"BYE\"");
- }
- }
- return result0;
- }
- function parse_CANCELm() {
- var result0;
- if (input.substr(pos, 6) === "CANCEL") {
- result0 = "CANCEL";
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"CANCEL\"");
- }
- }
- return result0;
- }
- function parse_REGISTERm() {
- var result0;
- if (input.substr(pos, 8) === "REGISTER") {
- result0 = "REGISTER";
- pos += 8;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"REGISTER\"");
- }
- }
- return result0;
- }
- function parse_SUBSCRIBEm() {
- var result0;
- if (input.substr(pos, 9) === "SUBSCRIBE") {
- result0 = "SUBSCRIBE";
- pos += 9;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"SUBSCRIBE\"");
- }
- }
- return result0;
- }
- function parse_NOTIFYm() {
- var result0;
- if (input.substr(pos, 6) === "NOTIFY") {
- result0 = "NOTIFY";
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"NOTIFY\"");
- }
- }
- return result0;
- }
- function parse_REFERm() {
- var result0;
- if (input.substr(pos, 5) === "REFER") {
- result0 = "REFER";
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"REFER\"");
- }
- }
- return result0;
- }
- function parse_Method() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_INVITEm();
- if (result0 === null) {
- result0 = parse_ACKm();
- if (result0 === null) {
- result0 = parse_OPTIONSm();
- if (result0 === null) {
- result0 = parse_BYEm();
- if (result0 === null) {
- result0 = parse_CANCELm();
- if (result0 === null) {
- result0 = parse_REGISTERm();
- if (result0 === null) {
- result0 = parse_SUBSCRIBEm();
- if (result0 === null) {
- result0 = parse_NOTIFYm();
- if (result0 === null) {
- result0 = parse_REFERm();
- if (result0 === null) {
- result0 = parse_token();
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.method = input.substring(pos, offset);
- return data.method;
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Status_Line() {
- var result0, result1, result2, result3, result4;
- var pos0;
- pos0 = pos;
- result0 = parse_SIP_Version();
- if (result0 !== null) {
- result1 = parse_SP();
- if (result1 !== null) {
- result2 = parse_Status_Code();
- if (result2 !== null) {
- result3 = parse_SP();
- if (result3 !== null) {
- result4 = parse_Reason_Phrase();
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Status_Code() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_extension_code();
- if (result0 !== null) {
- result0 = function (offset, status_code) {
- data.status_code = parseInt(status_code.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_extension_code() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_DIGIT();
- if (result0 !== null) {
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result2 = parse_DIGIT();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Reason_Phrase() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result0 = [];
- result1 = parse_reserved();
- if (result1 === null) {
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- result1 = parse_UTF8_NONASCII();
- if (result1 === null) {
- result1 = parse_UTF8_CONT();
- if (result1 === null) {
- result1 = parse_SP();
- if (result1 === null) {
- result1 = parse_HTAB();
- }
- }
- }
- }
- }
- }
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_reserved();
- if (result1 === null) {
- result1 = parse_unreserved();
- if (result1 === null) {
- result1 = parse_escaped();
- if (result1 === null) {
- result1 = parse_UTF8_NONASCII();
- if (result1 === null) {
- result1 = parse_UTF8_CONT();
- if (result1 === null) {
- result1 = parse_SP();
- if (result1 === null) {
- result1 = parse_HTAB();
- }
- }
- }
- }
- }
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.reason_phrase = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Allow_Events() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_event_type();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_event_type();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_event_type();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Call_ID() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_word();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 64) {
- result1 = "@";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_word();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Contact() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- result0 = parse_STAR();
- if (result0 === null) {
- pos1 = pos;
- result0 = parse_contact_param();
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_contact_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_contact_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var idx, length;
- length = data.multi_header.length;
- for (idx = 0; idx < length; idx++) {
- if (data.multi_header[idx].parsed === null) {
- data = null;
- break;
- }
- }
- if (data !== null) {
- data = data.multi_header;
- } else {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_contact_param() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SIP_URI_noparams();
- if (result0 === null) {
- result0 = parse_name_addr();
- }
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_contact_params();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_contact_params();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var header;
- if (!data.multi_header) data.multi_header = [];
- try {
- header = new NameAddrHeader(data.uri, data.display_name, data.params);
- delete data.uri;
- delete data.display_name;
- delete data.params;
- } catch (e) {
- header = null;
- }
- data.multi_header.push({
- 'possition': pos,
- 'offset': offset,
- 'parsed': header
- });
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_name_addr() {
- var result0, result1, result2, result3;
- var pos0;
- pos0 = pos;
- result0 = parse_display_name();
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result1 = parse_LAQUOT();
- if (result1 !== null) {
- result2 = parse_SIP_URI();
- if (result2 !== null) {
- result3 = parse_RAQUOT();
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_display_name() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_LWS();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_LWS();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 === null) {
- result0 = parse_quoted_string_clean();
- }
- if (result0 !== null) {
- result0 = function (offset, display_name) {
- if (typeof display_name === 'string') {
- // quoted_string_clean
- data.display_name = display_name;
- } else {
- // token ( LWS token )*
- data.display_name = display_name[1].reduce(function (acc, cur) {
- return acc + cur[0] + cur[1];
- }, display_name[0]);
- }
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_contact_params() {
- var result0;
- result0 = parse_c_p_q();
- if (result0 === null) {
- result0 = parse_c_p_expires();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- }
- return result0;
- }
- function parse_c_p_q() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 1).toLowerCase() === "q") {
- result0 = input.substr(pos, 1);
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"q\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_qvalue();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, q) {
- if (!data.params) data.params = {};
- data.params['q'] = q;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_c_p_expires() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 7).toLowerCase() === "expires") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"expires\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_delta_seconds();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, expires) {
- if (!data.params) data.params = {};
- data.params['expires'] = expires;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_delta_seconds() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_DIGIT();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset, delta_seconds) {
- return parseInt(delta_seconds.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_qvalue() {
- var result0, result1, result2, result3, result4;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- if (input.charCodeAt(pos) === 48) {
- result0 = "0";
- pos++;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"0\"");
- }
- }
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 46) {
- result1 = ".";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_DIGIT();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result3 = parse_DIGIT();
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- result4 = parse_DIGIT();
- result4 = result4 !== null ? result4 : "";
- if (result4 !== null) {
- result1 = [result1, result2, result3, result4];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- return parseFloat(input.substring(pos, offset));
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_generic_param() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- pos2 = pos;
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_gen_value();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, param, value) {
- if (!data.params) data.params = {};
- if (typeof value === 'undefined') {
- value = undefined;
- } else {
- value = value[1];
- }
- data.params[param.toLowerCase()] = value;
- }(pos0, result0[0], result0[1]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_gen_value() {
- var result0;
- result0 = parse_token();
- if (result0 === null) {
- result0 = parse_host();
- if (result0 === null) {
- result0 = parse_quoted_string();
- }
- }
- return result0;
- }
- function parse_Content_Disposition() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_disp_type();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_disp_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_disp_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_disp_type() {
- var result0;
- if (input.substr(pos, 6).toLowerCase() === "render") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"render\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 7).toLowerCase() === "session") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"session\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 4).toLowerCase() === "icon") {
- result0 = input.substr(pos, 4);
- pos += 4;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"icon\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 5).toLowerCase() === "alert") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"alert\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- }
- }
- }
- return result0;
- }
- function parse_disp_param() {
- var result0;
- result0 = parse_handling_param();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- return result0;
- }
- function parse_handling_param() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 8).toLowerCase() === "handling") {
- result0 = input.substr(pos, 8);
- pos += 8;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"handling\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- if (input.substr(pos, 8).toLowerCase() === "optional") {
- result2 = input.substr(pos, 8);
- pos += 8;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"optional\"");
- }
- }
- if (result2 === null) {
- if (input.substr(pos, 8).toLowerCase() === "required") {
- result2 = input.substr(pos, 8);
- pos += 8;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"required\"");
- }
- }
- if (result2 === null) {
- result2 = parse_token();
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Content_Encoding() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Content_Length() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_DIGIT();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset, length) {
- data = parseInt(length.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Content_Type() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_media_type();
- if (result0 !== null) {
- result0 = function (offset) {
- data = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_media_type() {
- var result0, result1, result2, result3, result4, result5;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_m_type();
- if (result0 !== null) {
- result1 = parse_SLASH();
- if (result1 !== null) {
- result2 = parse_m_subtype();
- if (result2 !== null) {
- result3 = [];
- pos1 = pos;
- result4 = parse_SEMI();
- if (result4 !== null) {
- result5 = parse_m_parameter();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- while (result4 !== null) {
- result3.push(result4);
- pos1 = pos;
- result4 = parse_SEMI();
- if (result4 !== null) {
- result5 = parse_m_parameter();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- }
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_m_type() {
- var result0;
- result0 = parse_discrete_type();
- if (result0 === null) {
- result0 = parse_composite_type();
- }
- return result0;
- }
- function parse_discrete_type() {
- var result0;
- if (input.substr(pos, 4).toLowerCase() === "text") {
- result0 = input.substr(pos, 4);
- pos += 4;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"text\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 5).toLowerCase() === "image") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"image\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 5).toLowerCase() === "audio") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"audio\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 5).toLowerCase() === "video") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"video\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 11).toLowerCase() === "application") {
- result0 = input.substr(pos, 11);
- pos += 11;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"application\"");
- }
- }
- if (result0 === null) {
- result0 = parse_extension_token();
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_composite_type() {
- var result0;
- if (input.substr(pos, 7).toLowerCase() === "message") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"message\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 9).toLowerCase() === "multipart") {
- result0 = input.substr(pos, 9);
- pos += 9;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"multipart\"");
- }
- }
- if (result0 === null) {
- result0 = parse_extension_token();
- }
- }
- return result0;
- }
- function parse_extension_token() {
- var result0;
- result0 = parse_token();
- if (result0 === null) {
- result0 = parse_x_token();
- }
- return result0;
- }
- function parse_x_token() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 2).toLowerCase() === "x-") {
- result0 = input.substr(pos, 2);
- pos += 2;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"x-\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_token();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_m_subtype() {
- var result0;
- result0 = parse_extension_token();
- if (result0 === null) {
- result0 = parse_token();
- }
- return result0;
- }
- function parse_m_parameter() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_m_value();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_m_value() {
- var result0;
- result0 = parse_token();
- if (result0 === null) {
- result0 = parse_quoted_string();
- }
- return result0;
- }
- function parse_CSeq() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_CSeq_value();
- if (result0 !== null) {
- result1 = parse_LWS();
- if (result1 !== null) {
- result2 = parse_Method();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_CSeq_value() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_DIGIT();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset, cseq_value) {
- data.value = parseInt(cseq_value.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Expires() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_delta_seconds();
- if (result0 !== null) {
- result0 = function (offset, expires) {
- data = expires;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Event() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_event_type();
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, event_type) {
- data.event = event_type.join('').toLowerCase();
- }(pos0, result0[0]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_event_type() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_token_nodot();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_token_nodot();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- if (input.charCodeAt(pos) === 46) {
- result2 = ".";
- pos++;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\".\"");
- }
- }
- if (result2 !== null) {
- result3 = parse_token_nodot();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_From() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SIP_URI_noparams();
- if (result0 === null) {
- result0 = parse_name_addr();
- }
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_from_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_from_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var tag = data.tag;
- try {
- data = new NameAddrHeader(data.uri, data.display_name, data.params);
- if (tag) {
- data.setParam('tag', tag);
- }
- } catch (e) {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_from_param() {
- var result0;
- result0 = parse_tag_param();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- return result0;
- }
- function parse_tag_param() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 3).toLowerCase() === "tag") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"tag\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, tag) {
- data.tag = tag;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Max_Forwards() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result1 = parse_DIGIT();
- if (result1 !== null) {
- result0 = [];
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_DIGIT();
- }
- } else {
- result0 = null;
- }
- if (result0 !== null) {
- result0 = function (offset, forwards) {
- data = parseInt(forwards.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Min_Expires() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_delta_seconds();
- if (result0 !== null) {
- result0 = function (offset, min_expires) {
- data = min_expires;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Name_Addr_Header() {
- var result0, result1, result2, result3, result4, result5, result6;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = [];
- result1 = parse_display_name();
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_display_name();
- }
- if (result0 !== null) {
- result1 = parse_LAQUOT();
- if (result1 !== null) {
- result2 = parse_SIP_URI();
- if (result2 !== null) {
- result3 = parse_RAQUOT();
- if (result3 !== null) {
- result4 = [];
- pos2 = pos;
- result5 = parse_SEMI();
- if (result5 !== null) {
- result6 = parse_generic_param();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos2;
- }
- } else {
- result5 = null;
- pos = pos2;
- }
- while (result5 !== null) {
- result4.push(result5);
- pos2 = pos;
- result5 = parse_SEMI();
- if (result5 !== null) {
- result6 = parse_generic_param();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos2;
- }
- } else {
- result5 = null;
- pos = pos2;
- }
- }
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- try {
- data = new NameAddrHeader(data.uri, data.display_name, data.params);
- } catch (e) {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Proxy_Authenticate() {
- var result0;
- result0 = parse_challenge();
- return result0;
- }
- function parse_challenge() {
- var result0, result1, result2, result3, result4, result5;
- var pos0, pos1;
- pos0 = pos;
- if (input.substr(pos, 6).toLowerCase() === "digest") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"Digest\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_LWS();
- if (result1 !== null) {
- result2 = parse_digest_cln();
- if (result2 !== null) {
- result3 = [];
- pos1 = pos;
- result4 = parse_COMMA();
- if (result4 !== null) {
- result5 = parse_digest_cln();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- while (result4 !== null) {
- result3.push(result4);
- pos1 = pos;
- result4 = parse_COMMA();
- if (result4 !== null) {
- result5 = parse_digest_cln();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- }
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- if (result0 === null) {
- result0 = parse_other_challenge();
- }
- return result0;
- }
- function parse_other_challenge() {
- var result0, result1, result2, result3, result4, result5;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = parse_LWS();
- if (result1 !== null) {
- result2 = parse_auth_param();
- if (result2 !== null) {
- result3 = [];
- pos1 = pos;
- result4 = parse_COMMA();
- if (result4 !== null) {
- result5 = parse_auth_param();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- while (result4 !== null) {
- result3.push(result4);
- pos1 = pos;
- result4 = parse_COMMA();
- if (result4 !== null) {
- result5 = parse_auth_param();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- }
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_auth_param() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 === null) {
- result2 = parse_quoted_string();
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_digest_cln() {
- var result0;
- result0 = parse_realm();
- if (result0 === null) {
- result0 = parse_domain();
- if (result0 === null) {
- result0 = parse_nonce();
- if (result0 === null) {
- result0 = parse_opaque();
- if (result0 === null) {
- result0 = parse_stale();
- if (result0 === null) {
- result0 = parse_algorithm();
- if (result0 === null) {
- result0 = parse_qop_options();
- if (result0 === null) {
- result0 = parse_auth_param();
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_realm() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 5).toLowerCase() === "realm") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"realm\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_realm_value();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_realm_value() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_quoted_string_clean();
- if (result0 !== null) {
- result0 = function (offset, realm) {
- data.realm = realm;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_domain() {
- var result0, result1, result2, result3, result4, result5, result6;
- var pos0, pos1;
- pos0 = pos;
- if (input.substr(pos, 6).toLowerCase() === "domain") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"domain\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_LDQUOT();
- if (result2 !== null) {
- result3 = parse_URI();
- if (result3 !== null) {
- result4 = [];
- pos1 = pos;
- result6 = parse_SP();
- if (result6 !== null) {
- result5 = [];
- while (result6 !== null) {
- result5.push(result6);
- result6 = parse_SP();
- }
- } else {
- result5 = null;
- }
- if (result5 !== null) {
- result6 = parse_URI();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos1;
- }
- } else {
- result5 = null;
- pos = pos1;
- }
- while (result5 !== null) {
- result4.push(result5);
- pos1 = pos;
- result6 = parse_SP();
- if (result6 !== null) {
- result5 = [];
- while (result6 !== null) {
- result5.push(result6);
- result6 = parse_SP();
- }
- } else {
- result5 = null;
- }
- if (result5 !== null) {
- result6 = parse_URI();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos1;
- }
- } else {
- result5 = null;
- pos = pos1;
- }
- }
- if (result4 !== null) {
- result5 = parse_RDQUOT();
- if (result5 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_URI() {
- var result0;
- result0 = parse_absoluteURI();
- if (result0 === null) {
- result0 = parse_abs_path();
- }
- return result0;
- }
- function parse_nonce() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 5).toLowerCase() === "nonce") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"nonce\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_nonce_value();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_nonce_value() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_quoted_string_clean();
- if (result0 !== null) {
- result0 = function (offset, nonce) {
- data.nonce = nonce;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_opaque() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 6).toLowerCase() === "opaque") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"opaque\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_quoted_string_clean();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, opaque) {
- data.opaque = opaque;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_stale() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- if (input.substr(pos, 5).toLowerCase() === "stale") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"stale\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- pos1 = pos;
- if (input.substr(pos, 4).toLowerCase() === "true") {
- result2 = input.substr(pos, 4);
- pos += 4;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"true\"");
- }
- }
- if (result2 !== null) {
- result2 = function (offset) {
- data.stale = true;
- }(pos1);
- }
- if (result2 === null) {
- pos = pos1;
- }
- if (result2 === null) {
- pos1 = pos;
- if (input.substr(pos, 5).toLowerCase() === "false") {
- result2 = input.substr(pos, 5);
- pos += 5;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"false\"");
- }
- }
- if (result2 !== null) {
- result2 = function (offset) {
- data.stale = false;
- }(pos1);
- }
- if (result2 === null) {
- pos = pos1;
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_algorithm() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 9).toLowerCase() === "algorithm") {
- result0 = input.substr(pos, 9);
- pos += 9;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"algorithm\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- if (input.substr(pos, 3).toLowerCase() === "md5") {
- result2 = input.substr(pos, 3);
- pos += 3;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"MD5\"");
- }
- }
- if (result2 === null) {
- if (input.substr(pos, 8).toLowerCase() === "md5-sess") {
- result2 = input.substr(pos, 8);
- pos += 8;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"MD5-sess\"");
- }
- }
- if (result2 === null) {
- result2 = parse_token();
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, algorithm) {
- data.algorithm = algorithm.toUpperCase();
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_qop_options() {
- var result0, result1, result2, result3, result4, result5, result6;
- var pos0, pos1, pos2;
- pos0 = pos;
- if (input.substr(pos, 3).toLowerCase() === "qop") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"qop\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_LDQUOT();
- if (result2 !== null) {
- pos1 = pos;
- result3 = parse_qop_value();
- if (result3 !== null) {
- result4 = [];
- pos2 = pos;
- if (input.charCodeAt(pos) === 44) {
- result5 = ",";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_qop_value();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos2;
- }
- } else {
- result5 = null;
- pos = pos2;
- }
- while (result5 !== null) {
- result4.push(result5);
- pos2 = pos;
- if (input.charCodeAt(pos) === 44) {
- result5 = ",";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\",\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_qop_value();
- if (result6 !== null) {
- result5 = [result5, result6];
- } else {
- result5 = null;
- pos = pos2;
- }
- } else {
- result5 = null;
- pos = pos2;
- }
- }
- if (result4 !== null) {
- result3 = [result3, result4];
- } else {
- result3 = null;
- pos = pos1;
- }
- } else {
- result3 = null;
- pos = pos1;
- }
- if (result3 !== null) {
- result4 = parse_RDQUOT();
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_qop_value() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 8).toLowerCase() === "auth-int") {
- result0 = input.substr(pos, 8);
- pos += 8;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"auth-int\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 4).toLowerCase() === "auth") {
- result0 = input.substr(pos, 4);
- pos += 4;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"auth\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- }
- if (result0 !== null) {
- result0 = function (offset, qop_value) {
- data.qop || (data.qop = []);
- data.qop.push(qop_value.toLowerCase());
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Proxy_Require() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Record_Route() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_rec_route();
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_rec_route();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_rec_route();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var idx, length;
- length = data.multi_header.length;
- for (idx = 0; idx < length; idx++) {
- if (data.multi_header[idx].parsed === null) {
- data = null;
- break;
- }
- }
- if (data !== null) {
- data = data.multi_header;
- } else {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_rec_route() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_name_addr();
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var header;
- if (!data.multi_header) data.multi_header = [];
- try {
- header = new NameAddrHeader(data.uri, data.display_name, data.params);
- delete data.uri;
- delete data.display_name;
- delete data.params;
- } catch (e) {
- header = null;
- }
- data.multi_header.push({
- 'possition': pos,
- 'offset': offset,
- 'parsed': header
- });
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Reason() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 3).toLowerCase() === "sip") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"SIP\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_reason_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_reason_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, protocol) {
- data.protocol = protocol.toLowerCase();
- if (!data.params) data.params = {};
- if (data.params.text && data.params.text[0] === '"') {
- var text = data.params.text;
- data.text = text.substring(1, text.length - 1);
- delete data.params.text;
- }
- }(pos0, result0[0]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_reason_param() {
- var result0;
- result0 = parse_reason_cause();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- return result0;
- }
- function parse_reason_cause() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 5).toLowerCase() === "cause") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"cause\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result3 = parse_DIGIT();
- if (result3 !== null) {
- result2 = [];
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_DIGIT();
- }
- } else {
- result2 = null;
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, cause) {
- data.cause = parseInt(cause.join(''));
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Require() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Route() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_route_param();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_route_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_route_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_route_param() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_name_addr();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Subscription_State() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_substate_value();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_subexp_params();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_subexp_params();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_substate_value() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 6).toLowerCase() === "active") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"active\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 7).toLowerCase() === "pending") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"pending\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 10).toLowerCase() === "terminated") {
- result0 = input.substr(pos, 10);
- pos += 10;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"terminated\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.state = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_subexp_params() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 6).toLowerCase() === "reason") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"reason\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_event_reason_value();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, reason) {
- if (typeof reason !== 'undefined') data.reason = reason;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- if (result0 === null) {
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 7).toLowerCase() === "expires") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"expires\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_delta_seconds();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, expires) {
- if (typeof expires !== 'undefined') data.expires = expires;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- if (result0 === null) {
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 11).toLowerCase() === "retry_after") {
- result0 = input.substr(pos, 11);
- pos += 11;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"retry_after\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_delta_seconds();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, retry_after) {
- if (typeof retry_after !== 'undefined') data.retry_after = retry_after;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- }
- }
- return result0;
- }
- function parse_event_reason_value() {
- var result0;
- if (input.substr(pos, 11).toLowerCase() === "deactivated") {
- result0 = input.substr(pos, 11);
- pos += 11;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"deactivated\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 9).toLowerCase() === "probation") {
- result0 = input.substr(pos, 9);
- pos += 9;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"probation\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 8).toLowerCase() === "rejected") {
- result0 = input.substr(pos, 8);
- pos += 8;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"rejected\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 7).toLowerCase() === "timeout") {
- result0 = input.substr(pos, 7);
- pos += 7;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"timeout\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 6).toLowerCase() === "giveup") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"giveup\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 10).toLowerCase() === "noresource") {
- result0 = input.substr(pos, 10);
- pos += 10;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"noresource\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 9).toLowerCase() === "invariant") {
- result0 = input.substr(pos, 9);
- pos += 9;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"invariant\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- }
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_Subject() {
- var result0;
- result0 = parse_TEXT_UTF8_TRIM();
- result0 = result0 !== null ? result0 : "";
- return result0;
- }
- function parse_Supported() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_token();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- result0 = result0 !== null ? result0 : "";
- return result0;
- }
- function parse_To() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SIP_URI_noparams();
- if (result0 === null) {
- result0 = parse_name_addr();
- }
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_to_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_to_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- var tag = data.tag;
- try {
- data = new NameAddrHeader(data.uri, data.display_name, data.params);
- if (tag) {
- data.setParam('tag', tag);
- }
- } catch (e) {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_to_param() {
- var result0;
- result0 = parse_tag_param();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- return result0;
- }
- function parse_Via() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_via_param();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_via_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_COMMA();
- if (result2 !== null) {
- result3 = parse_via_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_via_param() {
- var result0, result1, result2, result3, result4, result5;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_sent_protocol();
- if (result0 !== null) {
- result1 = parse_LWS();
- if (result1 !== null) {
- result2 = parse_sent_by();
- if (result2 !== null) {
- result3 = [];
- pos1 = pos;
- result4 = parse_SEMI();
- if (result4 !== null) {
- result5 = parse_via_params();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- while (result4 !== null) {
- result3.push(result4);
- pos1 = pos;
- result4 = parse_SEMI();
- if (result4 !== null) {
- result5 = parse_via_params();
- if (result5 !== null) {
- result4 = [result4, result5];
- } else {
- result4 = null;
- pos = pos1;
- }
- } else {
- result4 = null;
- pos = pos1;
- }
- }
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_via_params() {
- var result0;
- result0 = parse_via_ttl();
- if (result0 === null) {
- result0 = parse_via_maddr();
- if (result0 === null) {
- result0 = parse_via_received();
- if (result0 === null) {
- result0 = parse_via_branch();
- if (result0 === null) {
- result0 = parse_response_port();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- }
- }
- }
- }
- return result0;
- }
- function parse_via_ttl() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 3).toLowerCase() === "ttl") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"ttl\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_ttl();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, via_ttl_value) {
- data.ttl = via_ttl_value;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_via_maddr() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 5).toLowerCase() === "maddr") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"maddr\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_host();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, via_maddr) {
- data.maddr = via_maddr;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_via_received() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 8).toLowerCase() === "received") {
- result0 = input.substr(pos, 8);
- pos += 8;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"received\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_IPv4address();
- if (result2 === null) {
- result2 = parse_IPv6address();
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, via_received) {
- data.received = via_received;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_via_branch() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 6).toLowerCase() === "branch") {
- result0 = input.substr(pos, 6);
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"branch\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, via_branch) {
- data.branch = via_branch;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_response_port() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 5).toLowerCase() === "rport") {
- result0 = input.substr(pos, 5);
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"rport\"");
- }
- }
- if (result0 !== null) {
- pos2 = pos;
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = [];
- result3 = parse_DIGIT();
- while (result3 !== null) {
- result2.push(result3);
- result3 = parse_DIGIT();
- }
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- if (typeof response_port !== 'undefined') data.rport = response_port.join('');
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_sent_protocol() {
- var result0, result1, result2, result3, result4;
- var pos0;
- pos0 = pos;
- result0 = parse_protocol_name();
- if (result0 !== null) {
- result1 = parse_SLASH();
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 !== null) {
- result3 = parse_SLASH();
- if (result3 !== null) {
- result4 = parse_transport();
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_protocol_name() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 3).toLowerCase() === "sip") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"SIP\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- if (result0 !== null) {
- result0 = function (offset, via_protocol) {
- data.protocol = via_protocol;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_transport() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 3).toLowerCase() === "udp") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"UDP\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 3).toLowerCase() === "tcp") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"TCP\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 3).toLowerCase() === "tls") {
- result0 = input.substr(pos, 3);
- pos += 3;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"TLS\"");
- }
- }
- if (result0 === null) {
- if (input.substr(pos, 4).toLowerCase() === "sctp") {
- result0 = input.substr(pos, 4);
- pos += 4;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"SCTP\"");
- }
- }
- if (result0 === null) {
- result0 = parse_token();
- }
- }
- }
- }
- if (result0 !== null) {
- result0 = function (offset, via_transport) {
- data.transport = via_transport;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_sent_by() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_via_host();
- if (result0 !== null) {
- pos1 = pos;
- result1 = parse_COLON();
- if (result1 !== null) {
- result2 = parse_via_port();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos1;
- }
- } else {
- result1 = null;
- pos = pos1;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_via_host() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_IPv4address();
- if (result0 === null) {
- result0 = parse_IPv6reference();
- if (result0 === null) {
- result0 = parse_hostname();
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.host = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_via_port() {
- var result0, result1, result2, result3, result4;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_DIGIT();
- result0 = result0 !== null ? result0 : "";
- if (result0 !== null) {
- result1 = parse_DIGIT();
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result2 = parse_DIGIT();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result3 = parse_DIGIT();
- result3 = result3 !== null ? result3 : "";
- if (result3 !== null) {
- result4 = parse_DIGIT();
- result4 = result4 !== null ? result4 : "";
- if (result4 !== null) {
- result0 = [result0, result1, result2, result3, result4];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, via_sent_by_port) {
- data.port = parseInt(via_sent_by_port.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_ttl() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_DIGIT();
- if (result0 !== null) {
- result1 = parse_DIGIT();
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result2 = parse_DIGIT();
- result2 = result2 !== null ? result2 : "";
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, ttl) {
- return parseInt(ttl.join(''));
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_WWW_Authenticate() {
- var result0;
- result0 = parse_challenge();
- return result0;
- }
- function parse_Session_Expires() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_s_e_expires();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_s_e_params();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_s_e_params();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_s_e_expires() {
- var result0;
- var pos0;
- pos0 = pos;
- result0 = parse_delta_seconds();
- if (result0 !== null) {
- result0 = function (offset, expires) {
- data.expires = expires;
- }(pos0, result0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_s_e_params() {
- var result0;
- result0 = parse_s_e_refresher();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- return result0;
- }
- function parse_s_e_refresher() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 9).toLowerCase() === "refresher") {
- result0 = input.substr(pos, 9);
- pos += 9;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"refresher\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- if (input.substr(pos, 3).toLowerCase() === "uac") {
- result2 = input.substr(pos, 3);
- pos += 3;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"uac\"");
- }
- }
- if (result2 === null) {
- if (input.substr(pos, 3).toLowerCase() === "uas") {
- result2 = input.substr(pos, 3);
- pos += 3;
- } else {
- result2 = null;
- if (reportFailures === 0) {
- matchFailed("\"uas\"");
- }
- }
- }
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, s_e_refresher_value) {
- data.refresher = s_e_refresher_value.toLowerCase();
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_extension_header() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_token();
- if (result0 !== null) {
- result1 = parse_HCOLON();
- if (result1 !== null) {
- result2 = parse_header_value();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_header_value() {
- var result0, result1;
- result0 = [];
- result1 = parse_TEXT_UTF8char();
- if (result1 === null) {
- result1 = parse_UTF8_CONT();
- if (result1 === null) {
- result1 = parse_LWS();
- }
- }
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_TEXT_UTF8char();
- if (result1 === null) {
- result1 = parse_UTF8_CONT();
- if (result1 === null) {
- result1 = parse_LWS();
- }
- }
- }
- return result0;
- }
- function parse_message_body() {
- var result0, result1;
- result0 = [];
- result1 = parse_OCTET();
- while (result1 !== null) {
- result0.push(result1);
- result1 = parse_OCTET();
- }
- return result0;
- }
- function parse_uuid_URI() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 5) === "uuid:") {
- result0 = "uuid:";
- pos += 5;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"uuid:\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_uuid();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_uuid() {
- var result0, result1, result2, result3, result4, result5, result6, result7, result8;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_hex8();
- if (result0 !== null) {
- if (input.charCodeAt(pos) === 45) {
- result1 = "-";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_hex4();
- if (result2 !== null) {
- if (input.charCodeAt(pos) === 45) {
- result3 = "-";
- pos++;
- } else {
- result3 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result3 !== null) {
- result4 = parse_hex4();
- if (result4 !== null) {
- if (input.charCodeAt(pos) === 45) {
- result5 = "-";
- pos++;
- } else {
- result5 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result5 !== null) {
- result6 = parse_hex4();
- if (result6 !== null) {
- if (input.charCodeAt(pos) === 45) {
- result7 = "-";
- pos++;
- } else {
- result7 = null;
- if (reportFailures === 0) {
- matchFailed("\"-\"");
- }
- }
- if (result7 !== null) {
- result8 = parse_hex12();
- if (result8 !== null) {
- result0 = [result0, result1, result2, result3, result4, result5, result6, result7, result8];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, uuid) {
- data = input.substring(pos + 5, offset);
- }(pos0, result0[0]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_hex4() {
- var result0, result1, result2, result3;
- var pos0;
- pos0 = pos;
- result0 = parse_HEXDIG();
- if (result0 !== null) {
- result1 = parse_HEXDIG();
- if (result1 !== null) {
- result2 = parse_HEXDIG();
- if (result2 !== null) {
- result3 = parse_HEXDIG();
- if (result3 !== null) {
- result0 = [result0, result1, result2, result3];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_hex8() {
- var result0, result1;
- var pos0;
- pos0 = pos;
- result0 = parse_hex4();
- if (result0 !== null) {
- result1 = parse_hex4();
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_hex12() {
- var result0, result1, result2;
- var pos0;
- pos0 = pos;
- result0 = parse_hex4();
- if (result0 !== null) {
- result1 = parse_hex4();
- if (result1 !== null) {
- result2 = parse_hex4();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_Refer_To() {
- var result0, result1, result2, result3;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_SIP_URI_noparams();
- if (result0 === null) {
- result0 = parse_name_addr();
- }
- if (result0 !== null) {
- result1 = [];
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos2 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_generic_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos2;
- }
- } else {
- result2 = null;
- pos = pos2;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- try {
- data = new NameAddrHeader(data.uri, data.display_name, data.params);
- } catch (e) {
- data = -1;
- }
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_Replaces() {
- var result0, result1, result2, result3;
- var pos0, pos1;
- pos0 = pos;
- result0 = parse_call_id();
- if (result0 !== null) {
- result1 = [];
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_replaces_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- while (result2 !== null) {
- result1.push(result2);
- pos1 = pos;
- result2 = parse_SEMI();
- if (result2 !== null) {
- result3 = parse_replaces_param();
- if (result3 !== null) {
- result2 = [result2, result3];
- } else {
- result2 = null;
- pos = pos1;
- }
- } else {
- result2 = null;
- pos = pos1;
- }
- }
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos0;
- }
- } else {
- result0 = null;
- pos = pos0;
- }
- return result0;
- }
- function parse_call_id() {
- var result0, result1, result2;
- var pos0, pos1, pos2;
- pos0 = pos;
- pos1 = pos;
- result0 = parse_word();
- if (result0 !== null) {
- pos2 = pos;
- if (input.charCodeAt(pos) === 64) {
- result1 = "@";
- pos++;
- } else {
- result1 = null;
- if (reportFailures === 0) {
- matchFailed("\"@\"");
- }
- }
- if (result1 !== null) {
- result2 = parse_word();
- if (result2 !== null) {
- result1 = [result1, result2];
- } else {
- result1 = null;
- pos = pos2;
- }
- } else {
- result1 = null;
- pos = pos2;
- }
- result1 = result1 !== null ? result1 : "";
- if (result1 !== null) {
- result0 = [result0, result1];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.call_id = input.substring(pos, offset);
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_replaces_param() {
- var result0;
- result0 = parse_to_tag();
- if (result0 === null) {
- result0 = parse_from_tag();
- if (result0 === null) {
- result0 = parse_early_flag();
- if (result0 === null) {
- result0 = parse_generic_param();
- }
- }
- }
- return result0;
- }
- function parse_to_tag() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 6) === "to-tag") {
- result0 = "to-tag";
- pos += 6;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"to-tag\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, to_tag) {
- data.to_tag = to_tag;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_from_tag() {
- var result0, result1, result2;
- var pos0, pos1;
- pos0 = pos;
- pos1 = pos;
- if (input.substr(pos, 8) === "from-tag") {
- result0 = "from-tag";
- pos += 8;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"from-tag\"");
- }
- }
- if (result0 !== null) {
- result1 = parse_EQUAL();
- if (result1 !== null) {
- result2 = parse_token();
- if (result2 !== null) {
- result0 = [result0, result1, result2];
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- } else {
- result0 = null;
- pos = pos1;
- }
- if (result0 !== null) {
- result0 = function (offset, from_tag) {
- data.from_tag = from_tag;
- }(pos0, result0[2]);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function parse_early_flag() {
- var result0;
- var pos0;
- pos0 = pos;
- if (input.substr(pos, 10) === "early-only") {
- result0 = "early-only";
- pos += 10;
- } else {
- result0 = null;
- if (reportFailures === 0) {
- matchFailed("\"early-only\"");
- }
- }
- if (result0 !== null) {
- result0 = function (offset) {
- data.early_only = true;
- }(pos0);
- }
- if (result0 === null) {
- pos = pos0;
- }
- return result0;
- }
- function cleanupExpected(expected) {
- expected.sort();
- var lastExpected = null;
- var cleanExpected = [];
- for (var i = 0; i < expected.length; i++) {
- if (expected[i] !== lastExpected) {
- cleanExpected.push(expected[i]);
- lastExpected = expected[i];
- }
- }
- return cleanExpected;
- }
- function computeErrorPosition() {
- /*
- * The first idea was to use |String.split| to break the input up to the
- * error position along newlines and derive the line and column from
- * there. However IE's |split| implementation is so broken that it was
- * enough to prevent it.
- */
- var line = 1;
- var column = 1;
- var seenCR = false;
- for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
- var ch = input.charAt(i);
- if (ch === "\n") {
- if (!seenCR) {
- line++;
- }
- column = 1;
- seenCR = false;
- } else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
- line++;
- column = 1;
- seenCR = true;
- } else {
- column++;
- seenCR = false;
- }
- }
- return {
- line: line,
- column: column
- };
- }
- var URI = require('./URI');
- var NameAddrHeader = require('./NameAddrHeader');
- var data = {};
- var result = parseFunctions[startRule]();
- /*
- * The parser is now in one of the following three states:
- *
- * 1. The parser successfully parsed the whole input.
- *
- * - |result !== null|
- * - |pos === input.length|
- * - |rightmostFailuresExpected| may or may not contain something
- *
- * 2. The parser successfully parsed only a part of the input.
- *
- * - |result !== null|
- * - |pos < input.length|
- * - |rightmostFailuresExpected| may or may not contain something
- *
- * 3. The parser did not successfully parse any part of the input.
- *
- * - |result === null|
- * - |pos === 0|
- * - |rightmostFailuresExpected| contains at least one failure
- *
- * All code following this comment (including called functions) must
- * handle these states.
- */
- if (result === null || pos !== input.length) {
- var offset = Math.max(pos, rightmostFailuresPos);
- var found = offset < input.length ? input.charAt(offset) : null;
- var errorPosition = computeErrorPosition();
- new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
- return -1;
- }
- return data;
- },
- /* Returns the parser source code. */
- toSource: function toSource() {
- return this._source;
- }
- };
- /* Thrown when a parser encounters a syntax error. */
- result.SyntaxError = function (expected, found, offset, line, column) {
- function buildMessage(expected, found) {
- var expectedHumanized, foundHumanized;
- switch (expected.length) {
- case 0:
- expectedHumanized = "end of input";
- break;
- case 1:
- expectedHumanized = expected[0];
- break;
- default:
- expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
- }
- foundHumanized = found ? quote(found) : "end of input";
- return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
- }
- this.name = "SyntaxError";
- this.expected = expected;
- this.found = found;
- this.message = buildMessage(expected, found);
- this.offset = offset;
- this.line = line;
- this.column = column;
- };
- result.SyntaxError.prototype = Error.prototype;
- return result;
- }();
- },{"./NameAddrHeader":10,"./URI":25}],8:[function(require,module,exports){
- "use strict";
- var pkg = require('../package.json');
- var C = require('./Constants');
- var Exceptions = require('./Exceptions');
- var Utils = require('./Utils');
- var UA = require('./UA');
- var URI = require('./URI');
- var NameAddrHeader = require('./NameAddrHeader');
- var Grammar = require('./Grammar');
- var WebSocketInterface = require('./WebSocketInterface');
- var debug = require('debug')('JsSIP');
- debug('version %s', pkg.version);
- /**
- * Expose the JsSIP module.
- */
- module.exports = {
- C: C,
- Exceptions: Exceptions,
- Utils: Utils,
- UA: UA,
- URI: URI,
- NameAddrHeader: NameAddrHeader,
- WebSocketInterface: WebSocketInterface,
- Grammar: Grammar,
- // Expose the debug module.
- debug: require('debug'),
- get name() {
- return pkg.title;
- },
- get version() {
- return pkg.version;
- }
- };
- },{"../package.json":38,"./Constants":2,"./Exceptions":6,"./Grammar":7,"./NameAddrHeader":10,"./UA":24,"./URI":25,"./Utils":26,"./WebSocketInterface":27,"debug":30}],9:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- var EventEmitter = require('events').EventEmitter;
- var JsSIP_C = require('./Constants');
- var SIPMessage = require('./SIPMessage');
- var Utils = require('./Utils');
- var RequestSender = require('./RequestSender');
- var Exceptions = require('./Exceptions');
- var debug = require('debug')('JsSIP:Message');
- module.exports =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(Message, _EventEmitter);
- function Message(ua) {
- var _this;
- _classCallCheck(this, Message);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Message).call(this));
- _this._ua = ua;
- _this._request = null;
- _this._closed = false;
- _this._direction = null;
- _this._local_identity = null;
- _this._remote_identity = null; // Whether an incoming message has been replied.
- _this._is_replied = false; // Custom message empty object for high level use.
- _this._data = {};
- return _this;
- }
- _createClass(Message, [{
- key: "send",
- value: function send(target, body) {
- var _this2 = this;
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
- var originalTarget = target;
- if (target === undefined || body === undefined) {
- throw new TypeError('Not enough arguments');
- } // Check target validity.
- target = this._ua.normalizeTarget(target);
- if (!target) {
- throw new TypeError("Invalid target: ".concat(originalTarget));
- } // Get call options.
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var eventHandlers = options.eventHandlers || {};
- var contentType = options.contentType || 'text/plain'; // Set event handlers.
- for (var event in eventHandlers) {
- if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
- this.on(event, eventHandlers[event]);
- }
- }
- extraHeaders.push("Content-Type: ".concat(contentType));
- this._request = new SIPMessage.OutgoingRequest(JsSIP_C.MESSAGE, target, this._ua, null, extraHeaders);
- if (body) {
- this._request.body = body;
- }
- var request_sender = new RequestSender(this._ua, this._request, {
- onRequestTimeout: function onRequestTimeout() {
- _this2._onRequestTimeout();
- },
- onTransportError: function onTransportError() {
- _this2._onTransportError();
- },
- onReceiveResponse: function onReceiveResponse(response) {
- _this2._receiveResponse(response);
- }
- });
- this._newMessage('local', this._request);
- request_sender.send();
- }
- }, {
- key: "init_incoming",
- value: function init_incoming(request) {
- this._request = request;
- this._newMessage('remote', request); // Reply with a 200 OK if the user didn't reply.
- if (!this._is_replied) {
- this._is_replied = true;
- request.reply(200);
- }
- this._close();
- }
- /**
- * Accept the incoming Message
- * Only valid for incoming Messages
- */
- }, {
- key: "accept",
- value: function accept() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var body = options.body;
- if (this._direction !== 'incoming') {
- throw new Exceptions.NotSupportedError('"accept" not supported for outgoing Message');
- }
- if (this._is_replied) {
- throw new Error('incoming Message already replied');
- }
- this._is_replied = true;
- this._request.reply(200, null, extraHeaders, body);
- }
- /**
- * Reject the incoming Message
- * Only valid for incoming Messages
- */
- }, {
- key: "reject",
- value: function reject() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var status_code = options.status_code || 480;
- var reason_phrase = options.reason_phrase;
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var body = options.body;
- if (this._direction !== 'incoming') {
- throw new Exceptions.NotSupportedError('"reject" not supported for outgoing Message');
- }
- if (this._is_replied) {
- throw new Error('incoming Message already replied');
- }
- if (status_code < 300 || status_code >= 700) {
- throw new TypeError("Invalid status_code: ".concat(status_code));
- }
- this._is_replied = true;
- this._request.reply(status_code, reason_phrase, extraHeaders, body);
- }
- }, {
- key: "_receiveResponse",
- value: function _receiveResponse(response) {
- if (this._closed) {
- return;
- }
- switch (true) {
- case /^1[0-9]{2}$/.test(response.status_code):
- // Ignore provisional responses.
- break;
- case /^2[0-9]{2}$/.test(response.status_code):
- this._succeeded('remote', response);
- break;
- default:
- {
- var cause = Utils.sipErrorCause(response.status_code);
- this._failed('remote', response, cause);
- break;
- }
- }
- }
- }, {
- key: "_onRequestTimeout",
- value: function _onRequestTimeout() {
- if (this._closed) {
- return;
- }
- this._failed('system', null, JsSIP_C.causes.REQUEST_TIMEOUT);
- }
- }, {
- key: "_onTransportError",
- value: function _onTransportError() {
- if (this._closed) {
- return;
- }
- this._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
- }
- }, {
- key: "_close",
- value: function _close() {
- this._closed = true;
- this._ua.destroyMessage(this);
- }
- /**
- * Internal Callbacks
- */
- }, {
- key: "_newMessage",
- value: function _newMessage(originator, request) {
- if (originator === 'remote') {
- this._direction = 'incoming';
- this._local_identity = request.to;
- this._remote_identity = request.from;
- } else if (originator === 'local') {
- this._direction = 'outgoing';
- this._local_identity = request.from;
- this._remote_identity = request.to;
- }
- this._ua.newMessage(this, {
- originator: originator,
- message: this,
- request: request
- });
- }
- }, {
- key: "_failed",
- value: function _failed(originator, response, cause) {
- debug('MESSAGE failed');
- this._close();
- debug('emit "failed"');
- this.emit('failed', {
- originator: originator,
- response: response || null,
- cause: cause
- });
- }
- }, {
- key: "_succeeded",
- value: function _succeeded(originator, response) {
- debug('MESSAGE succeeded');
- this._close();
- debug('emit "succeeded"');
- this.emit('succeeded', {
- originator: originator,
- response: response
- });
- }
- }, {
- key: "direction",
- get: function get() {
- return this._direction;
- }
- }, {
- key: "local_identity",
- get: function get() {
- return this._local_identity;
- }
- }, {
- key: "remote_identity",
- get: function get() {
- return this._remote_identity;
- }
- }]);
- return Message;
- }(EventEmitter);
- },{"./Constants":2,"./Exceptions":6,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30,"events":29}],10:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var URI = require('./URI');
- var Grammar = require('./Grammar');
- module.exports =
- /*#__PURE__*/
- function () {
- _createClass(NameAddrHeader, null, [{
- key: "parse",
- /**
- * Parse the given string and returns a NameAddrHeader instance or undefined if
- * it is an invalid NameAddrHeader.
- */
- value: function parse(name_addr_header) {
- name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');
- if (name_addr_header !== -1) {
- return name_addr_header;
- } else {
- return undefined;
- }
- }
- }]);
- function NameAddrHeader(uri, display_name, parameters) {
- _classCallCheck(this, NameAddrHeader);
- // Checks.
- if (!uri || !(uri instanceof URI)) {
- throw new TypeError('missing or invalid "uri" parameter');
- } // Initialize parameters.
- this._uri = uri;
- this._parameters = {};
- this.display_name = display_name;
- for (var param in parameters) {
- if (Object.prototype.hasOwnProperty.call(parameters, param)) {
- this.setParam(param, parameters[param]);
- }
- }
- }
- _createClass(NameAddrHeader, [{
- key: "setParam",
- value: function setParam(key, value) {
- if (key) {
- this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
- }
- }
- }, {
- key: "getParam",
- value: function getParam(key) {
- if (key) {
- return this._parameters[key.toLowerCase()];
- }
- }
- }, {
- key: "hasParam",
- value: function hasParam(key) {
- if (key) {
- return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
- }
- }
- }, {
- key: "deleteParam",
- value: function deleteParam(parameter) {
- parameter = parameter.toLowerCase();
- if (this._parameters.hasOwnProperty(parameter)) {
- var value = this._parameters[parameter];
- delete this._parameters[parameter];
- return value;
- }
- }
- }, {
- key: "clearParams",
- value: function clearParams() {
- this._parameters = {};
- }
- }, {
- key: "clone",
- value: function clone() {
- return new NameAddrHeader(this._uri.clone(), this._display_name, JSON.parse(JSON.stringify(this._parameters)));
- }
- }, {
- key: "_quote",
- value: function _quote(str) {
- return str.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
- }
- }, {
- key: "toString",
- value: function toString() {
- var body = this._display_name ? "\"".concat(this._quote(this._display_name), "\" ") : '';
- body += "<".concat(this._uri.toString(), ">");
- for (var parameter in this._parameters) {
- if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
- body += ";".concat(parameter);
- if (this._parameters[parameter] !== null) {
- body += "=".concat(this._parameters[parameter]);
- }
- }
- }
- return body;
- }
- }, {
- key: "uri",
- get: function get() {
- return this._uri;
- }
- }, {
- key: "display_name",
- get: function get() {
- return this._display_name;
- },
- set: function set(value) {
- this._display_name = value === 0 ? '0' : value;
- }
- }]);
- return NameAddrHeader;
- }();
- },{"./Grammar":7,"./URI":25}],11:[function(require,module,exports){
- "use strict";
- var Grammar = require('./Grammar');
- var SIPMessage = require('./SIPMessage');
- var debugerror = require('debug')('JsSIP:ERROR:Parser');
- debugerror.log = console.warn.bind(console);
- /**
- * Parse SIP Message
- */
- exports.parseMessage = function (data, ua) {
- var message;
- var bodyStart;
- var headerEnd = data.indexOf('\r\n');
- if (headerEnd === -1) {
- debugerror('parseMessage() | no CRLF found, not a SIP message');
- return;
- } // Parse first line. Check if it is a Request or a Reply.
- var firstLine = data.substring(0, headerEnd);
- var parsed = Grammar.parse(firstLine, 'Request_Response');
- if (parsed === -1) {
- debugerror("parseMessage() | error parsing first line of SIP message: \"".concat(firstLine, "\""));
- return;
- } else if (!parsed.status_code) {
- message = new SIPMessage.IncomingRequest(ua);
- message.method = parsed.method;
- message.ruri = parsed.uri;
- } else {
- message = new SIPMessage.IncomingResponse();
- message.status_code = parsed.status_code;
- message.reason_phrase = parsed.reason_phrase;
- }
- message.data = data;
- var headerStart = headerEnd + 2;
- /* Loop over every line in data. Detect the end of each header and parse
- * it or simply add to the headers collection.
- */
- while (true) {
- headerEnd = getHeader(data, headerStart); // The SIP message has normally finished.
- if (headerEnd === -2) {
- bodyStart = headerStart + 2;
- break;
- } // Data.indexOf returned -1 due to a malformed message.
- else if (headerEnd === -1) {
- debugerror('parseMessage() | malformed message');
- return;
- }
- parsed = parseHeader(message, data, headerStart, headerEnd);
- if (parsed !== true) {
- debugerror('parseMessage() |', parsed.error);
- return;
- }
- headerStart = headerEnd + 2;
- }
- /* RFC3261 18.3.
- * If there are additional bytes in the transport packet
- * beyond the end of the body, they MUST be discarded.
- */
- if (message.hasHeader('content-length')) {
- var contentLength = message.getHeader('content-length');
- message.body = data.substr(bodyStart, contentLength);
- } else {
- message.body = data.substring(bodyStart);
- }
- return message;
- };
- /**
- * Extract and parse every header of a SIP message.
- */
- function getHeader(data, headerStart) {
- // 'start' position of the header.
- var start = headerStart; // 'end' position of the header.
- var end = 0; // 'partial end' position of the header.
- var partialEnd = 0; // End of message.
- if (data.substring(start, start + 2).match(/(^\r\n)/)) {
- return -2;
- }
- while (end === 0) {
- // Partial End of Header.
- partialEnd = data.indexOf('\r\n', start); // 'indexOf' returns -1 if the value to be found never occurs.
- if (partialEnd === -1) {
- return partialEnd;
- }
- if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/)) {
- // Not the end of the message. Continue from the next position.
- start = partialEnd + 2;
- } else {
- end = partialEnd;
- }
- }
- return end;
- }
- function parseHeader(message, data, headerStart, headerEnd) {
- var parsed;
- var hcolonIndex = data.indexOf(':', headerStart);
- var headerName = data.substring(headerStart, hcolonIndex).trim();
- var headerValue = data.substring(hcolonIndex + 1, headerEnd).trim(); // If header-field is well-known, parse it.
- switch (headerName.toLowerCase()) {
- case 'via':
- case 'v':
- message.addHeader('via', headerValue);
- if (message.getHeaders('via').length === 1) {
- parsed = message.parseHeader('Via');
- if (parsed) {
- message.via = parsed;
- message.via_branch = parsed.branch;
- }
- } else {
- parsed = 0;
- }
- break;
- case 'from':
- case 'f':
- message.setHeader('from', headerValue);
- parsed = message.parseHeader('from');
- if (parsed) {
- message.from = parsed;
- message.from_tag = parsed.getParam('tag');
- }
- break;
- case 'to':
- case 't':
- message.setHeader('to', headerValue);
- parsed = message.parseHeader('to');
- if (parsed) {
- message.to = parsed;
- message.to_tag = parsed.getParam('tag');
- }
- break;
- case 'record-route':
- parsed = Grammar.parse(headerValue, 'Record_Route');
- if (parsed === -1) {
- parsed = undefined;
- } else {
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = parsed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var header = _step.value;
- message.addHeader('record-route', headerValue.substring(header.possition, header.offset));
- message.headers['Record-Route'][message.getHeaders('record-route').length - 1].parsed = header.parsed;
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- }
- break;
- case 'call-id':
- case 'i':
- message.setHeader('call-id', headerValue);
- parsed = message.parseHeader('call-id');
- if (parsed) {
- message.call_id = headerValue;
- }
- break;
- case 'contact':
- case 'm':
- parsed = Grammar.parse(headerValue, 'Contact');
- if (parsed === -1) {
- parsed = undefined;
- } else {
- var _iteratorNormalCompletion2 = true;
- var _didIteratorError2 = false;
- var _iteratorError2 = undefined;
- try {
- for (var _iterator2 = parsed[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
- var _header = _step2.value;
- message.addHeader('contact', headerValue.substring(_header.possition, _header.offset));
- message.headers.Contact[message.getHeaders('contact').length - 1].parsed = _header.parsed;
- }
- } catch (err) {
- _didIteratorError2 = true;
- _iteratorError2 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
- _iterator2.return();
- }
- } finally {
- if (_didIteratorError2) {
- throw _iteratorError2;
- }
- }
- }
- }
- break;
- case 'content-length':
- case 'l':
- message.setHeader('content-length', headerValue);
- parsed = message.parseHeader('content-length');
- break;
- case 'content-type':
- case 'c':
- message.setHeader('content-type', headerValue);
- parsed = message.parseHeader('content-type');
- break;
- case 'cseq':
- message.setHeader('cseq', headerValue);
- parsed = message.parseHeader('cseq');
- if (parsed) {
- message.cseq = parsed.value;
- }
- if (message instanceof SIPMessage.IncomingResponse) {
- message.method = parsed.method;
- }
- break;
- case 'max-forwards':
- message.setHeader('max-forwards', headerValue);
- parsed = message.parseHeader('max-forwards');
- break;
- case 'www-authenticate':
- message.setHeader('www-authenticate', headerValue);
- parsed = message.parseHeader('www-authenticate');
- break;
- case 'proxy-authenticate':
- message.setHeader('proxy-authenticate', headerValue);
- parsed = message.parseHeader('proxy-authenticate');
- break;
- case 'session-expires':
- case 'x':
- message.setHeader('session-expires', headerValue);
- parsed = message.parseHeader('session-expires');
- if (parsed) {
- message.session_expires = parsed.expires;
- message.session_expires_refresher = parsed.refresher;
- }
- break;
- case 'refer-to':
- case 'r':
- message.setHeader('refer-to', headerValue);
- parsed = message.parseHeader('refer-to');
- if (parsed) {
- message.refer_to = parsed;
- }
- break;
- case 'replaces':
- message.setHeader('replaces', headerValue);
- parsed = message.parseHeader('replaces');
- if (parsed) {
- message.replaces = parsed;
- }
- break;
- case 'event':
- case 'o':
- message.setHeader('event', headerValue);
- parsed = message.parseHeader('event');
- if (parsed) {
- message.event = parsed;
- }
- break;
- default:
- // Do not parse this header.
- message.addHeader(headerName, headerValue);
- parsed = 0;
- }
- if (parsed === undefined) {
- return {
- error: "error parsing header \"".concat(headerName, "\"")
- };
- } else {
- return true;
- }
- }
- },{"./Grammar":7,"./SIPMessage":19,"debug":30}],12:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- /* globals RTCPeerConnection: false, RTCSessionDescription: false */
- var EventEmitter = require('events').EventEmitter;
- var sdp_transform = require('sdp-transform');
- var JsSIP_C = require('./Constants');
- var Exceptions = require('./Exceptions');
- var Transactions = require('./Transactions');
- var Utils = require('./Utils');
- var Timers = require('./Timers');
- var SIPMessage = require('./SIPMessage');
- var Dialog = require('./Dialog');
- var RequestSender = require('./RequestSender');
- var RTCSession_DTMF = require('./RTCSession/DTMF');
- var RTCSession_Info = require('./RTCSession/Info');
- var RTCSession_ReferNotifier = require('./RTCSession/ReferNotifier');
- var RTCSession_ReferSubscriber = require('./RTCSession/ReferSubscriber');
- var URI = require('./URI');
- var debug = require('debug')('JsSIP:RTCSession');
- var debugerror = require('debug')('JsSIP:ERROR:RTCSession');
- debugerror.log = console.warn.bind(console);
- var C = {
- // RTCSession states.
- STATUS_NULL: 0,
- STATUS_INVITE_SENT: 1,
- STATUS_1XX_RECEIVED: 2,
- STATUS_INVITE_RECEIVED: 3,
- STATUS_WAITING_FOR_ANSWER: 4,
- STATUS_ANSWERED: 5,
- STATUS_WAITING_FOR_ACK: 6,
- STATUS_CANCELED: 7,
- STATUS_TERMINATED: 8,
- STATUS_CONFIRMED: 9
- };
- /**
- * Local variables.
- */
- var holdMediaTypes = ['audio', 'video'];
- module.exports =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(RTCSession, _EventEmitter);
- _createClass(RTCSession, null, [{
- key: "C",
- /**
- * Expose C object.
- */
- get: function get() {
- return C;
- }
- }]);
- function RTCSession(ua) {
- var _this;
- _classCallCheck(this, RTCSession);
- debug('new');
- _this = _possibleConstructorReturn(this, _getPrototypeOf(RTCSession).call(this));
- _this._id = null;
- _this._ua = ua;
- _this._status = C.STATUS_NULL;
- _this._dialog = null;
- _this._earlyDialogs = {};
- _this._contact = null;
- _this._from_tag = null;
- _this._to_tag = null; // The RTCPeerConnection instance (public attribute).
- _this._connection = null; // Prevent races on serial PeerConnction operations.
- _this._connectionPromiseQueue = Promise.resolve(); // Incoming/Outgoing request being currently processed.
- _this._request = null; // Cancel state for initial outgoing request.
- _this._is_canceled = false;
- _this._cancel_reason = ''; // RTCSession confirmation flag.
- _this._is_confirmed = false; // Is late SDP being negotiated.
- _this._late_sdp = false; // Default rtcOfferConstraints and rtcAnswerConstrainsts (passed in connect() or answer()).
- _this._rtcOfferConstraints = null;
- _this._rtcAnswerConstraints = null; // Local MediaStream.
- _this._localMediaStream = null;
- _this._localMediaStreamLocallyGenerated = false; // Flag to indicate PeerConnection ready for new actions.
- _this._rtcReady = true; // SIP Timers.
- _this._timers = {
- ackTimer: null,
- expiresTimer: null,
- invite2xxTimer: null,
- userNoAnswerTimer: null
- }; // Session info.
- _this._direction = null;
- _this._local_identity = null;
- _this._remote_identity = null;
- _this._start_time = null;
- _this._end_time = null;
- _this._tones = null; // Mute/Hold state.
- _this._audioMuted = false;
- _this._videoMuted = false;
- _this._localHold = false;
- _this._remoteHold = false; // Session Timers (RFC 4028).
- _this._sessionTimers = {
- enabled: _this._ua.configuration.session_timers,
- refreshMethod: _this._ua.configuration.session_timers_refresh_method,
- defaultExpires: JsSIP_C.SESSION_EXPIRES,
- currentExpires: null,
- running: false,
- refresher: false,
- timer: null // A setTimeout.
- }; // Map of ReferSubscriber instances indexed by the REFER's CSeq number.
- _this._referSubscribers = {}; // Custom session empty object for high level use.
- _this._data = {};
- return _this;
- }
- /**
- * User API
- */
- // Expose RTCSession constants as a property of the RTCSession instance.
- _createClass(RTCSession, [{
- key: "isInProgress",
- value: function isInProgress() {
- switch (this._status) {
- case C.STATUS_NULL:
- case C.STATUS_INVITE_SENT:
- case C.STATUS_1XX_RECEIVED:
- case C.STATUS_INVITE_RECEIVED:
- case C.STATUS_WAITING_FOR_ANSWER:
- return true;
- default:
- return false;
- }
- }
- }, {
- key: "isEstablished",
- value: function isEstablished() {
- switch (this._status) {
- case C.STATUS_ANSWERED:
- case C.STATUS_WAITING_FOR_ACK:
- case C.STATUS_CONFIRMED:
- return true;
- default:
- return false;
- }
- }
- }, {
- key: "isEnded",
- value: function isEnded() {
- switch (this._status) {
- case C.STATUS_CANCELED:
- case C.STATUS_TERMINATED:
- return true;
- default:
- return false;
- }
- }
- }, {
- key: "isMuted",
- value: function isMuted() {
- return {
- audio: this._audioMuted,
- video: this._videoMuted
- };
- }
- }, {
- key: "isOnHold",
- value: function isOnHold() {
- return {
- local: this._localHold,
- remote: this._remoteHold
- };
- }
- }, {
- key: "connect",
- value: function connect(target) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var initCallback = arguments.length > 2 ? arguments[2] : undefined;
- debug('connect()');
- var originalTarget = target;
- var eventHandlers = options.eventHandlers || {};
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var mediaConstraints = options.mediaConstraints || {
- audio: true,
- video: true
- };
- var mediaStream = options.mediaStream || null;
- var pcConfig = options.pcConfig || {
- iceServers: []
- };
- var rtcConstraints = options.rtcConstraints || null;
- var rtcOfferConstraints = options.rtcOfferConstraints || null;
- this._rtcOfferConstraints = rtcOfferConstraints;
- this._rtcAnswerConstraints = options.rtcAnswerConstraints || null;
- this._data = options.data || this._data; // Check target.
- if (target === undefined) {
- throw new TypeError('Not enough arguments');
- } // Check Session Status.
- if (this._status !== C.STATUS_NULL) {
- throw new Exceptions.InvalidStateError(this._status);
- } // Check WebRTC support.
- if (!window.RTCPeerConnection) {
- throw new Exceptions.NotSupportedError('WebRTC not supported');
- } // Check target validity.
- target = this._ua.normalizeTarget(target);
- if (!target) {
- throw new TypeError("Invalid target: ".concat(originalTarget));
- } // Session Timers.
- if (this._sessionTimers.enabled) {
- if (Utils.isDecimal(options.sessionTimersExpires)) {
- if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
- this._sessionTimers.defaultExpires = options.sessionTimersExpires;
- } else {
- this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
- }
- }
- } // Set event handlers.
- for (var event in eventHandlers) {
- if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
- this.on(event, eventHandlers[event]);
- }
- } // Session parameter initialization.
- this._from_tag = Utils.newTag(); // Set anonymous property.
- var anonymous = options.anonymous || false;
- var requestParams = {
- from_tag: this._from_tag
- };
- this._contact = this._ua.contact.toString({
- anonymous: anonymous,
- outbound: true
- });
- if (anonymous) {
- requestParams.from_display_name = 'Anonymous';
- requestParams.from_uri = new URI('sip', 'anonymous', 'anonymous.invalid');
- extraHeaders.push("P-Preferred-Identity: ".concat(this._ua.configuration.uri.toString()));
- extraHeaders.push('Privacy: id');
- }
- extraHeaders.push("Contact: ".concat(this._contact));
- extraHeaders.push('Content-Type: application/sdp');
- if (this._sessionTimers.enabled) {
- extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.defaultExpires));
- }
- this._request = new SIPMessage.InitialOutgoingInviteRequest(target, this._ua, requestParams, extraHeaders);
- this._id = this._request.call_id + this._from_tag; // Create a new RTCPeerConnection instance.
- this._createRTCConnection(pcConfig, rtcConstraints); // Set internal properties.
- this._direction = 'outgoing';
- this._local_identity = this._request.from;
- this._remote_identity = this._request.to; // User explicitly provided a newRTCSession callback for this session.
- if (initCallback) {
- initCallback(this);
- }
- this._newRTCSession('local', this._request);
- this._sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream);
- }
- }, {
- key: "init_incoming",
- value: function init_incoming(request, initCallback) {
- var _this2 = this;
- debug('init_incoming()');
- var expires;
- var contentType = request.getHeader('Content-Type'); // Check body and content type.
- if (request.body && contentType !== 'application/sdp') {
- request.reply(415);
- return;
- } // Session parameter initialization.
- this._status = C.STATUS_INVITE_RECEIVED;
- this._from_tag = request.from_tag;
- this._id = request.call_id + this._from_tag;
- this._request = request;
- this._contact = this._ua.contact.toString(); // Get the Expires header value if exists.
- if (request.hasHeader('expires')) {
- expires = request.getHeader('expires') * 1000;
- }
- /* Set the to_tag before
- * replying a response code that will create a dialog.
- */
- request.to_tag = Utils.newTag(); // An error on dialog creation will fire 'failed' event.
- if (!this._createDialog(request, 'UAS', true)) {
- request.reply(500, 'Missing Contact header field');
- return;
- }
- if (request.body) {
- this._late_sdp = false;
- } else {
- this._late_sdp = true;
- }
- this._status = C.STATUS_WAITING_FOR_ANSWER; // Set userNoAnswerTimer.
- this._timers.userNoAnswerTimer = setTimeout(function () {
- request.reply(408);
- _this2._failed('local', null, JsSIP_C.causes.NO_ANSWER);
- }, this._ua.configuration.no_answer_timeout);
- /* Set expiresTimer
- * RFC3261 13.3.1
- */
- if (expires) {
- this._timers.expiresTimer = setTimeout(function () {
- if (_this2._status === C.STATUS_WAITING_FOR_ANSWER) {
- request.reply(487);
- _this2._failed('system', null, JsSIP_C.causes.EXPIRES);
- }
- }, expires);
- } // Set internal properties.
- this._direction = 'incoming';
- this._local_identity = request.to;
- this._remote_identity = request.from; // A init callback was specifically defined.
- if (initCallback) {
- initCallback(this);
- } // Fire 'newRTCSession' event.
- this._newRTCSession('remote', request); // The user may have rejected the call in the 'newRTCSession' event.
- if (this._status === C.STATUS_TERMINATED) {
- return;
- } // Reply 180.
- request.reply(180, null, ["Contact: ".concat(this._contact)]); // Fire 'progress' event.
- // TODO: Document that 'response' field in 'progress' event is null for incoming calls.
- this._progress('local', null);
- }
- /**
- * Answer the call.
- */
- }, {
- key: "answer",
- value: function answer() {
- var _this3 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- debug('answer()');
- var request = this._request;
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var mediaConstraints = options.mediaConstraints || {};
- var mediaStream = options.mediaStream || null;
- var pcConfig = options.pcConfig || {
- iceServers: []
- };
- var rtcConstraints = options.rtcConstraints || null;
- var rtcAnswerConstraints = options.rtcAnswerConstraints || null;
- var tracks;
- var peerHasAudioLine = false;
- var peerHasVideoLine = false;
- var peerOffersFullAudio = false;
- var peerOffersFullVideo = false;
- this._rtcAnswerConstraints = rtcAnswerConstraints;
- this._rtcOfferConstraints = options.rtcOfferConstraints || null;
- this._data = options.data || this._data; // Check Session Direction and Status.
- if (this._direction !== 'incoming') {
- throw new Exceptions.NotSupportedError('"answer" not supported for outgoing RTCSession');
- } // Check Session status.
- if (this._status !== C.STATUS_WAITING_FOR_ANSWER) {
- throw new Exceptions.InvalidStateError(this._status);
- } // Session Timers.
- if (this._sessionTimers.enabled) {
- if (Utils.isDecimal(options.sessionTimersExpires)) {
- if (options.sessionTimersExpires >= JsSIP_C.MIN_SESSION_EXPIRES) {
- this._sessionTimers.defaultExpires = options.sessionTimersExpires;
- } else {
- this._sessionTimers.defaultExpires = JsSIP_C.SESSION_EXPIRES;
- }
- }
- }
- this._status = C.STATUS_ANSWERED; // An error on dialog creation will fire 'failed' event.
- if (!this._createDialog(request, 'UAS')) {
- request.reply(500, 'Error creating dialog');
- return;
- }
- clearTimeout(this._timers.userNoAnswerTimer);
- extraHeaders.unshift("Contact: ".concat(this._contact)); // Determine incoming media from incoming SDP offer (if any).
- var sdp = request.parseSDP(); // Make sure sdp.media is an array, not the case if there is only one media.
- if (!Array.isArray(sdp.media)) {
- sdp.media = [sdp.media];
- } // Go through all medias in SDP to find offered capabilities to answer with.
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = sdp.media[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var m = _step.value;
- if (m.type === 'audio') {
- peerHasAudioLine = true;
- if (!m.direction || m.direction === 'sendrecv') {
- peerOffersFullAudio = true;
- }
- }
- if (m.type === 'video') {
- peerHasVideoLine = true;
- if (!m.direction || m.direction === 'sendrecv') {
- peerOffersFullVideo = true;
- }
- }
- } // Remove audio from mediaStream if suggested by mediaConstraints.
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- if (mediaStream && mediaConstraints.audio === false) {
- tracks = mediaStream.getAudioTracks();
- var _iteratorNormalCompletion2 = true;
- var _didIteratorError2 = false;
- var _iteratorError2 = undefined;
- try {
- for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
- var track = _step2.value;
- mediaStream.removeTrack(track);
- }
- } catch (err) {
- _didIteratorError2 = true;
- _iteratorError2 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
- _iterator2.return();
- }
- } finally {
- if (_didIteratorError2) {
- throw _iteratorError2;
- }
- }
- }
- } // Remove video from mediaStream if suggested by mediaConstraints.
- if (mediaStream && mediaConstraints.video === false) {
- tracks = mediaStream.getVideoTracks();
- var _iteratorNormalCompletion3 = true;
- var _didIteratorError3 = false;
- var _iteratorError3 = undefined;
- try {
- for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
- var _track = _step3.value;
- mediaStream.removeTrack(_track);
- }
- } catch (err) {
- _didIteratorError3 = true;
- _iteratorError3 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
- _iterator3.return();
- }
- } finally {
- if (_didIteratorError3) {
- throw _iteratorError3;
- }
- }
- }
- } // Set audio constraints based on incoming stream if not supplied.
- if (!mediaStream && mediaConstraints.audio === undefined) {
- mediaConstraints.audio = peerOffersFullAudio;
- } // Set video constraints based on incoming stream if not supplied.
- if (!mediaStream && mediaConstraints.video === undefined) {
- mediaConstraints.video = peerOffersFullVideo;
- } // Don't ask for audio if the incoming offer has no audio section.
- if (!mediaStream && !peerHasAudioLine) {
- mediaConstraints.audio = false;
- } // Don't ask for video if the incoming offer has no video section.
- if (!mediaStream && !peerHasVideoLine) {
- mediaConstraints.video = false;
- } // Create a new RTCPeerConnection instance.
- // TODO: This may throw an error, should react.
- this._createRTCConnection(pcConfig, rtcConstraints);
- Promise.resolve() // Handle local MediaStream.
- .then(function () {
- // A local MediaStream is given, use it.
- if (mediaStream) {
- return mediaStream;
- } // Audio and/or video requested, prompt getUserMedia.
- else if (mediaConstraints.audio || mediaConstraints.video) {
- _this3._localMediaStreamLocallyGenerated = true;
- return navigator.mediaDevices.getUserMedia(mediaConstraints).catch(function (error) {
- if (_this3._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- request.reply(480);
- _this3._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
- debugerror('emit "getusermediafailed" [error:%o]', error);
- _this3.emit('getusermediafailed', error);
- throw new Error('getUserMedia() failed');
- });
- }
- }) // Attach MediaStream to RTCPeerconnection.
- .then(function (stream) {
- if (_this3._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- _this3._localMediaStream = stream;
- if (stream) {
- stream.getTracks().forEach(function (track) {
- _this3._connection.addTrack(track, stream);
- });
- }
- }) // Set remote description.
- .then(function () {
- if (_this3._late_sdp) {
- return;
- }
- var e = {
- originator: 'remote',
- type: 'offer',
- sdp: request.body
- };
- debug('emit "sdp"');
- _this3.emit('sdp', e);
- var offer = new RTCSessionDescription({
- type: 'offer',
- sdp: e.sdp
- });
- _this3._connectionPromiseQueue = _this3._connectionPromiseQueue.then(function () {
- return _this3._connection.setRemoteDescription(offer);
- }).catch(function (error) {
- request.reply(488);
- _this3._failed('system', null, JsSIP_C.causes.WEBRTC_ERROR);
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this3.emit('peerconnection:setremotedescriptionfailed', error);
- throw new Error('peerconnection.setRemoteDescription() failed');
- });
- return _this3._connectionPromiseQueue;
- }) // Create local description.
- .then(function () {
- if (_this3._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- } // TODO: Is this event already useful?
- _this3._connecting(request);
- if (!_this3._late_sdp) {
- return _this3._createLocalDescription('answer', rtcAnswerConstraints).catch(function () {
- request.reply(500);
- throw new Error('_createLocalDescription() failed');
- });
- } else {
- return _this3._createLocalDescription('offer', _this3._rtcOfferConstraints).catch(function () {
- request.reply(500);
- throw new Error('_createLocalDescription() failed');
- });
- }
- }) // Send reply.
- .then(function (desc) {
- if (_this3._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- _this3._handleSessionTimersInIncomingRequest(request, extraHeaders);
- request.reply(200, null, extraHeaders, desc, function () {
- _this3._status = C.STATUS_WAITING_FOR_ACK;
- _this3._setInvite2xxTimer(request, desc);
- _this3._setACKTimer();
- _this3._accepted('local');
- }, function () {
- _this3._failed('system', null, JsSIP_C.causes.CONNECTION_ERROR);
- });
- }).catch(function (error) {
- if (_this3._status === C.STATUS_TERMINATED) {
- return;
- }
- debugerror(error);
- });
- }
- /**
- * Terminate the call.
- */
- }, {
- key: "terminate",
- value: function terminate() {
- var _this4 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- debug('terminate()');
- var cause = options.cause || JsSIP_C.causes.BYE;
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var body = options.body;
- var cancel_reason;
- var status_code = options.status_code;
- var reason_phrase = options.reason_phrase; // Check Session Status.
- if (this._status === C.STATUS_TERMINATED) {
- throw new Exceptions.InvalidStateError(this._status);
- }
- switch (this._status) {
- // - UAC -
- case C.STATUS_NULL:
- case C.STATUS_INVITE_SENT:
- case C.STATUS_1XX_RECEIVED:
- debug('canceling session');
- if (status_code && (status_code < 200 || status_code >= 700)) {
- throw new TypeError("Invalid status_code: ".concat(status_code));
- } else if (status_code) {
- reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
- cancel_reason = "SIP ;cause=".concat(status_code, " ;text=\"").concat(reason_phrase, "\"");
- } // Check Session Status.
- if (this._status === C.STATUS_NULL || this._status === C.STATUS_INVITE_SENT) {
- this._is_canceled = true;
- this._cancel_reason = cancel_reason;
- } else if (this._status === C.STATUS_1XX_RECEIVED) {
- this._request.cancel(cancel_reason);
- }
- this._status = C.STATUS_CANCELED;
- this._failed('local', null, JsSIP_C.causes.CANCELED);
- break;
- // - UAS -
- case C.STATUS_WAITING_FOR_ANSWER:
- case C.STATUS_ANSWERED:
- debug('rejecting session');
- status_code = status_code || 480;
- if (status_code < 300 || status_code >= 700) {
- throw new TypeError("Invalid status_code: ".concat(status_code));
- }
- this._request.reply(status_code, reason_phrase, extraHeaders, body);
- this._failed('local', null, JsSIP_C.causes.REJECTED);
- break;
- case C.STATUS_WAITING_FOR_ACK:
- case C.STATUS_CONFIRMED:
- debug('terminating session');
- reason_phrase = options.reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
- if (status_code && (status_code < 200 || status_code >= 700)) {
- throw new TypeError("Invalid status_code: ".concat(status_code));
- } else if (status_code) {
- extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
- }
- /* RFC 3261 section 15 (Terminating a session):
- *
- * "...the callee's UA MUST NOT send a BYE on a confirmed dialog
- * until it has received an ACK for its 2xx response or until the server
- * transaction times out."
- */
- if (this._status === C.STATUS_WAITING_FOR_ACK && this._direction === 'incoming' && this._request.server_transaction.state !== Transactions.C.STATUS_TERMINATED) {
- // Save the dialog for later restoration.
- var dialog = this._dialog; // Send the BYE as soon as the ACK is received...
- this.receiveRequest = function (_ref) {
- var method = _ref.method;
- if (method === JsSIP_C.ACK) {
- _this4.sendRequest(JsSIP_C.BYE, {
- extraHeaders: extraHeaders,
- body: body
- });
- dialog.terminate();
- }
- }; // .., or when the INVITE transaction times out
- this._request.server_transaction.on('stateChanged', function () {
- if (_this4._request.server_transaction.state === Transactions.C.STATUS_TERMINATED) {
- _this4.sendRequest(JsSIP_C.BYE, {
- extraHeaders: extraHeaders,
- body: body
- });
- dialog.terminate();
- }
- });
- this._ended('local', null, cause); // Restore the dialog into 'this' in order to be able to send the in-dialog BYE :-).
- this._dialog = dialog; // Restore the dialog into 'ua' so the ACK can reach 'this' session.
- this._ua.newDialog(dialog);
- } else {
- this.sendRequest(JsSIP_C.BYE, {
- extraHeaders: extraHeaders,
- body: body
- });
- this._ended('local', null, cause);
- }
- }
- }
- }, {
- key: "sendDTMF",
- value: function sendDTMF(tones) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- debug('sendDTMF() | tones: %s', tones);
- var position = 0;
- var duration = options.duration || null;
- var interToneGap = options.interToneGap || null;
- if (tones === undefined) {
- throw new TypeError('Not enough arguments');
- } // Check Session Status.
- if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
- throw new Exceptions.InvalidStateError(this._status);
- } // Convert to string.
- if (typeof tones === 'number') {
- tones = tones.toString();
- } // Check tones.
- if (!tones || typeof tones !== 'string' || !tones.match(/^[0-9A-DR#*,]+$/i)) {
- throw new TypeError("Invalid tones: ".concat(tones));
- } // Check duration.
- if (duration && !Utils.isDecimal(duration)) {
- throw new TypeError("Invalid tone duration: ".concat(duration));
- } else if (!duration) {
- duration = RTCSession_DTMF.C.DEFAULT_DURATION;
- } else if (duration < RTCSession_DTMF.C.MIN_DURATION) {
- debug("\"duration\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_DURATION, " milliseconds"));
- duration = RTCSession_DTMF.C.MIN_DURATION;
- } else if (duration > RTCSession_DTMF.C.MAX_DURATION) {
- debug("\"duration\" value is greater than the maximum allowed, setting it to ".concat(RTCSession_DTMF.C.MAX_DURATION, " milliseconds"));
- duration = RTCSession_DTMF.C.MAX_DURATION;
- } else {
- duration = Math.abs(duration);
- }
- options.duration = duration; // Check interToneGap.
- if (interToneGap && !Utils.isDecimal(interToneGap)) {
- throw new TypeError("Invalid interToneGap: ".concat(interToneGap));
- } else if (!interToneGap) {
- interToneGap = RTCSession_DTMF.C.DEFAULT_INTER_TONE_GAP;
- } else if (interToneGap < RTCSession_DTMF.C.MIN_INTER_TONE_GAP) {
- debug("\"interToneGap\" value is lower than the minimum allowed, setting it to ".concat(RTCSession_DTMF.C.MIN_INTER_TONE_GAP, " milliseconds"));
- interToneGap = RTCSession_DTMF.C.MIN_INTER_TONE_GAP;
- } else {
- interToneGap = Math.abs(interToneGap);
- }
- if (this._tones) {
- // Tones are already queued, just add to the queue.
- this._tones += tones;
- return;
- }
- this._tones = tones; // Send the first tone.
- _sendDTMF.call(this);
- function _sendDTMF() {
- var _this5 = this;
- var timeout;
- if (this._status === C.STATUS_TERMINATED || !this._tones || position >= this._tones.length) {
- // Stop sending DTMF.
- this._tones = null;
- return;
- }
- var tone = this._tones[position];
- position += 1;
- if (tone === ',') {
- timeout = 2000;
- } else {
- var dtmf = new RTCSession_DTMF(this);
- options.eventHandlers = {
- onFailed: function onFailed() {
- _this5._tones = null;
- }
- };
- dtmf.send(tone, options);
- timeout = duration + interToneGap;
- } // Set timeout for the next tone.
- setTimeout(_sendDTMF.bind(this), timeout);
- }
- }
- }, {
- key: "sendInfo",
- value: function sendInfo(contentType, body) {
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
- debug('sendInfo()'); // Check Session Status.
- if (this._status !== C.STATUS_CONFIRMED && this._status !== C.STATUS_WAITING_FOR_ACK) {
- throw new Exceptions.InvalidStateError(this._status);
- }
- var info = new RTCSession_Info(this);
- info.send(contentType, body, options);
- }
- /**
- * Mute
- */
- }, {
- key: "mute",
- value: function mute() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
- audio: true,
- video: false
- };
- debug('mute()');
- var audioMuted = false,
- videoMuted = false;
- if (this._audioMuted === false && options.audio) {
- audioMuted = true;
- this._audioMuted = true;
- this._toggleMuteAudio(true);
- }
- if (this._videoMuted === false && options.video) {
- videoMuted = true;
- this._videoMuted = true;
- this._toggleMuteVideo(true);
- }
- if (audioMuted === true || videoMuted === true) {
- this._onmute({
- audio: audioMuted,
- video: videoMuted
- });
- }
- }
- /**
- * Unmute
- */
- }, {
- key: "unmute",
- value: function unmute() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
- audio: true,
- video: true
- };
- debug('unmute()');
- var audioUnMuted = false,
- videoUnMuted = false;
- if (this._audioMuted === true && options.audio) {
- audioUnMuted = true;
- this._audioMuted = false;
- if (this._localHold === false) {
- this._toggleMuteAudio(false);
- }
- }
- if (this._videoMuted === true && options.video) {
- videoUnMuted = true;
- this._videoMuted = false;
- if (this._localHold === false) {
- this._toggleMuteVideo(false);
- }
- }
- if (audioUnMuted === true || videoUnMuted === true) {
- this._onunmute({
- audio: audioUnMuted,
- video: videoUnMuted
- });
- }
- }
- /**
- * Hold
- */
- }, {
- key: "hold",
- value: function hold() {
- var _this6 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var done = arguments.length > 1 ? arguments[1] : undefined;
- debug('hold()');
- if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- if (this._localHold === true) {
- return false;
- }
- if (!this._isReadyToReOffer()) {
- return false;
- }
- this._localHold = true;
- this._onhold('local');
- var eventHandlers = {
- succeeded: function succeeded() {
- if (done) {
- done();
- }
- },
- failed: function failed() {
- _this6.terminate({
- cause: JsSIP_C.causes.WEBRTC_ERROR,
- status_code: 500,
- reason_phrase: 'Hold Failed'
- });
- }
- };
- if (options.useUpdate) {
- this._sendUpdate({
- sdpOffer: true,
- eventHandlers: eventHandlers,
- extraHeaders: options.extraHeaders
- });
- } else {
- this._sendReinvite({
- eventHandlers: eventHandlers,
- extraHeaders: options.extraHeaders
- });
- }
- return true;
- }
- }, {
- key: "unhold",
- value: function unhold() {
- var _this7 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var done = arguments.length > 1 ? arguments[1] : undefined;
- debug('unhold()');
- if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- if (this._localHold === false) {
- return false;
- }
- if (!this._isReadyToReOffer()) {
- return false;
- }
- this._localHold = false;
- this._onunhold('local');
- var eventHandlers = {
- succeeded: function succeeded() {
- if (done) {
- done();
- }
- },
- failed: function failed() {
- _this7.terminate({
- cause: JsSIP_C.causes.WEBRTC_ERROR,
- status_code: 500,
- reason_phrase: 'Unhold Failed'
- });
- }
- };
- if (options.useUpdate) {
- this._sendUpdate({
- sdpOffer: true,
- eventHandlers: eventHandlers,
- extraHeaders: options.extraHeaders
- });
- } else {
- this._sendReinvite({
- eventHandlers: eventHandlers,
- extraHeaders: options.extraHeaders
- });
- }
- return true;
- }
- }, {
- key: "renegotiate",
- value: function renegotiate() {
- var _this8 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var done = arguments.length > 1 ? arguments[1] : undefined;
- debug('renegotiate()');
- var rtcOfferConstraints = options.rtcOfferConstraints || null;
- if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- if (!this._isReadyToReOffer()) {
- return false;
- }
- var eventHandlers = {
- succeeded: function succeeded() {
- if (done) {
- done();
- }
- },
- failed: function failed() {
- _this8.terminate({
- cause: JsSIP_C.causes.WEBRTC_ERROR,
- status_code: 500,
- reason_phrase: 'Media Renegotiation Failed'
- });
- }
- };
- this._setLocalMediaStatus();
- if (options.useUpdate) {
- this._sendUpdate({
- sdpOffer: true,
- eventHandlers: eventHandlers,
- rtcOfferConstraints: rtcOfferConstraints,
- extraHeaders: options.extraHeaders
- });
- } else {
- this._sendReinvite({
- eventHandlers: eventHandlers,
- rtcOfferConstraints: rtcOfferConstraints,
- extraHeaders: options.extraHeaders
- });
- }
- return true;
- }
- /**
- * Refer
- */
- }, {
- key: "refer",
- value: function refer(target, options) {
- var _this9 = this;
- debug('refer()');
- var originalTarget = target;
- if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
- return false;
- } // Check target validity.
- target = this._ua.normalizeTarget(target);
- if (!target) {
- throw new TypeError("Invalid target: ".concat(originalTarget));
- }
- var referSubscriber = new RTCSession_ReferSubscriber(this);
- referSubscriber.sendRefer(target, options); // Store in the map.
- var id = referSubscriber.id;
- this._referSubscribers[id] = referSubscriber; // Listen for ending events so we can remove it from the map.
- referSubscriber.on('requestFailed', function () {
- delete _this9._referSubscribers[id];
- });
- referSubscriber.on('accepted', function () {
- delete _this9._referSubscribers[id];
- });
- referSubscriber.on('failed', function () {
- delete _this9._referSubscribers[id];
- });
- return referSubscriber;
- }
- /**
- * Send a generic in-dialog Request
- */
- }, {
- key: "sendRequest",
- value: function sendRequest(method, options) {
- debug('sendRequest()');
- return this._dialog.sendRequest(method, options);
- }
- /**
- * In dialog Request Reception
- */
- }, {
- key: "receiveRequest",
- value: function receiveRequest(request) {
- var _this10 = this;
- debug('receiveRequest()');
- if (request.method === JsSIP_C.CANCEL) {
- /* RFC3261 15 States that a UAS may have accepted an invitation while a CANCEL
- * was in progress and that the UAC MAY continue with the session established by
- * any 2xx response, or MAY terminate with BYE. JsSIP does continue with the
- * established session. So the CANCEL is processed only if the session is not yet
- * established.
- */
- /*
- * Terminate the whole session in case the user didn't accept (or yet send the answer)
- * nor reject the request opening the session.
- */
- if (this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED) {
- this._status = C.STATUS_CANCELED;
- this._request.reply(487);
- this._failed('remote', request, JsSIP_C.causes.CANCELED);
- }
- } else {
- // Requests arriving here are in-dialog requests.
- switch (request.method) {
- case JsSIP_C.ACK:
- if (this._status !== C.STATUS_WAITING_FOR_ACK) {
- return;
- } // Update signaling status.
- this._status = C.STATUS_CONFIRMED;
- clearTimeout(this._timers.ackTimer);
- clearTimeout(this._timers.invite2xxTimer);
- if (this._late_sdp) {
- if (!request.body) {
- this.terminate({
- cause: JsSIP_C.causes.MISSING_SDP,
- status_code: 400
- });
- break;
- }
- var e = {
- originator: 'remote',
- type: 'answer',
- sdp: request.body
- };
- debug('emit "sdp"');
- this.emit('sdp', e);
- var answer = new RTCSessionDescription({
- type: 'answer',
- sdp: e.sdp
- });
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this10._connection.setRemoteDescription(answer);
- }).then(function () {
- if (!_this10._is_confirmed) {
- _this10._confirmed('remote', request);
- }
- }).catch(function (error) {
- _this10.terminate({
- cause: JsSIP_C.causes.BAD_MEDIA_DESCRIPTION,
- status_code: 488
- });
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this10.emit('peerconnection:setremotedescriptionfailed', error);
- });
- } else if (!this._is_confirmed) {
- this._confirmed('remote', request);
- }
- break;
- case JsSIP_C.BYE:
- if (this._status === C.STATUS_CONFIRMED || this._status === C.STATUS_WAITING_FOR_ACK) {
- request.reply(200);
- this._ended('remote', request, JsSIP_C.causes.BYE);
- } else if (this._status === C.STATUS_INVITE_RECEIVED) {
- request.reply(200);
- this._request.reply(487, 'BYE Received');
- this._ended('remote', request, JsSIP_C.causes.BYE);
- } else {
- request.reply(403, 'Wrong Status');
- }
- break;
- case JsSIP_C.INVITE:
- if (this._status === C.STATUS_CONFIRMED) {
- if (request.hasHeader('replaces')) {
- this._receiveReplaces(request);
- } else {
- this._receiveReinvite(request);
- }
- } else {
- request.reply(403, 'Wrong Status');
- }
- break;
- case JsSIP_C.INFO:
- if (this._status === C.STATUS_1XX_RECEIVED || this._status === C.STATUS_WAITING_FOR_ANSWER || this._status === C.STATUS_ANSWERED || this._status === C.STATUS_WAITING_FOR_ACK || this._status === C.STATUS_CONFIRMED) {
- var contentType = request.getHeader('content-type');
- if (contentType && contentType.match(/^application\/dtmf-relay/i)) {
- new RTCSession_DTMF(this).init_incoming(request);
- } else if (contentType !== undefined) {
- new RTCSession_Info(this).init_incoming(request);
- } else {
- request.reply(415);
- }
- } else {
- request.reply(403, 'Wrong Status');
- }
- break;
- case JsSIP_C.UPDATE:
- if (this._status === C.STATUS_CONFIRMED) {
- this._receiveUpdate(request);
- } else {
- request.reply(403, 'Wrong Status');
- }
- break;
- case JsSIP_C.REFER:
- if (this._status === C.STATUS_CONFIRMED) {
- this._receiveRefer(request);
- } else {
- request.reply(403, 'Wrong Status');
- }
- break;
- case JsSIP_C.NOTIFY:
- if (this._status === C.STATUS_CONFIRMED) {
- this._receiveNotify(request);
- } else {
- request.reply(403, 'Wrong Status');
- }
- break;
- default:
- request.reply(501);
- }
- }
- }
- /**
- * Session Callbacks
- */
- }, {
- key: "onTransportError",
- value: function onTransportError() {
- debugerror('onTransportError()');
- if (this._status !== C.STATUS_TERMINATED) {
- this.terminate({
- status_code: 500,
- reason_phrase: JsSIP_C.causes.CONNECTION_ERROR,
- cause: JsSIP_C.causes.CONNECTION_ERROR
- });
- }
- }
- }, {
- key: "onRequestTimeout",
- value: function onRequestTimeout() {
- debugerror('onRequestTimeout()');
- if (this._status !== C.STATUS_TERMINATED) {
- this.terminate({
- status_code: 408,
- reason_phrase: JsSIP_C.causes.REQUEST_TIMEOUT,
- cause: JsSIP_C.causes.REQUEST_TIMEOUT
- });
- }
- }
- }, {
- key: "onDialogError",
- value: function onDialogError() {
- debugerror('onDialogError()');
- if (this._status !== C.STATUS_TERMINATED) {
- this.terminate({
- status_code: 500,
- reason_phrase: JsSIP_C.causes.DIALOG_ERROR,
- cause: JsSIP_C.causes.DIALOG_ERROR
- });
- }
- } // Called from DTMF handler.
- }, {
- key: "newDTMF",
- value: function newDTMF(data) {
- debug('newDTMF()');
- this.emit('newDTMF', data);
- } // Called from Info handler.
- }, {
- key: "newInfo",
- value: function newInfo(data) {
- debug('newInfo()');
- this.emit('newInfo', data);
- }
- /**
- * Check if RTCSession is ready for an outgoing re-INVITE or UPDATE with SDP.
- */
- }, {
- key: "_isReadyToReOffer",
- value: function _isReadyToReOffer() {
- if (!this._rtcReady) {
- debug('_isReadyToReOffer() | internal WebRTC status not ready');
- return false;
- } // No established yet.
- if (!this._dialog) {
- debug('_isReadyToReOffer() | session not established yet');
- return false;
- } // Another INVITE transaction is in progress.
- if (this._dialog.uac_pending_reply === true || this._dialog.uas_pending_reply === true) {
- debug('_isReadyToReOffer() | there is another INVITE/UPDATE transaction in progress');
- return false;
- }
- return true;
- }
- }, {
- key: "_close",
- value: function _close() {
- debug('close()');
- if (this._status === C.STATUS_TERMINATED) {
- return;
- }
- this._status = C.STATUS_TERMINATED; // Terminate RTC.
- if (this._connection) {
- try {
- this._connection.close();
- } catch (error) {
- debugerror('close() | error closing the RTCPeerConnection: %o', error);
- }
- } // Close local MediaStream if it was not given by the user.
- if (this._localMediaStream && this._localMediaStreamLocallyGenerated) {
- debug('close() | closing local MediaStream');
- Utils.closeMediaStream(this._localMediaStream);
- } // Terminate signaling.
- // Clear SIP timers.
- for (var timer in this._timers) {
- if (Object.prototype.hasOwnProperty.call(this._timers, timer)) {
- clearTimeout(this._timers[timer]);
- }
- } // Clear Session Timers.
- clearTimeout(this._sessionTimers.timer); // Terminate confirmed dialog.
- if (this._dialog) {
- this._dialog.terminate();
- delete this._dialog;
- } // Terminate early dialogs.
- for (var dialog in this._earlyDialogs) {
- if (Object.prototype.hasOwnProperty.call(this._earlyDialogs, dialog)) {
- this._earlyDialogs[dialog].terminate();
- delete this._earlyDialogs[dialog];
- }
- } // Terminate REFER subscribers.
- for (var subscriber in this._referSubscribers) {
- if (Object.prototype.hasOwnProperty.call(this._referSubscribers, subscriber)) {
- delete this._referSubscribers[subscriber];
- }
- }
- this._ua.destroyRTCSession(this);
- }
- /**
- * Private API.
- */
- /**
- * RFC3261 13.3.1.4
- * Response retransmissions cannot be accomplished by transaction layer
- * since it is destroyed when receiving the first 2xx answer
- */
- }, {
- key: "_setInvite2xxTimer",
- value: function _setInvite2xxTimer(request, body) {
- var timeout = Timers.T1;
- function invite2xxRetransmission() {
- if (this._status !== C.STATUS_WAITING_FOR_ACK) {
- return;
- }
- request.reply(200, null, ["Contact: ".concat(this._contact)], body);
- if (timeout < Timers.T2) {
- timeout = timeout * 2;
- if (timeout > Timers.T2) {
- timeout = Timers.T2;
- }
- }
- this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
- }
- this._timers.invite2xxTimer = setTimeout(invite2xxRetransmission.bind(this), timeout);
- }
- /**
- * RFC3261 14.2
- * If a UAS generates a 2xx response and never receives an ACK,
- * it SHOULD generate a BYE to terminate the dialog.
- */
- }, {
- key: "_setACKTimer",
- value: function _setACKTimer() {
- var _this11 = this;
- this._timers.ackTimer = setTimeout(function () {
- if (_this11._status === C.STATUS_WAITING_FOR_ACK) {
- debug('no ACK received, terminating the session');
- clearTimeout(_this11._timers.invite2xxTimer);
- _this11.sendRequest(JsSIP_C.BYE);
- _this11._ended('remote', null, JsSIP_C.causes.NO_ACK);
- }
- }, Timers.TIMER_H);
- }
- }, {
- key: "_createRTCConnection",
- value: function _createRTCConnection(pcConfig, rtcConstraints) {
- var _this12 = this;
- this._connection = new RTCPeerConnection(pcConfig, rtcConstraints);
- this._connection.addEventListener('iceconnectionstatechange', function () {
- var state = _this12._connection.iceConnectionState; // TODO: Do more with different states.
- if (state === 'failed') {
- _this12.terminate({
- cause: JsSIP_C.causes.RTP_TIMEOUT,
- status_code: 408,
- reason_phrase: JsSIP_C.causes.RTP_TIMEOUT
- });
- }
- });
- debug('emit "peerconnection"');
- this.emit('peerconnection', {
- peerconnection: this._connection
- });
- }
- }, {
- key: "_createLocalDescription",
- value: function _createLocalDescription(type, constraints) {
- var _this13 = this;
- debug('createLocalDescription()');
- if (type !== 'offer' && type !== 'answer') throw new Error("createLocalDescription() | invalid type \"".concat(type, "\""));
- var connection = this._connection;
- this._rtcReady = false;
- return Promise.resolve() // Create Offer or Answer.
- .then(function () {
- if (type === 'offer') {
- return connection.createOffer(constraints).catch(function (error) {
- debugerror('emit "peerconnection:createofferfailed" [error:%o]', error);
- _this13.emit('peerconnection:createofferfailed', error);
- return Promise.reject(error);
- });
- } else {
- return connection.createAnswer(constraints).catch(function (error) {
- debugerror('emit "peerconnection:createanswerfailed" [error:%o]', error);
- _this13.emit('peerconnection:createanswerfailed', error);
- return Promise.reject(error);
- });
- }
- }) // Set local description.
- .then(function (desc) {
- return connection.setLocalDescription(desc).catch(function (error) {
- _this13._rtcReady = true;
- debugerror('emit "peerconnection:setlocaldescriptionfailed" [error:%o]', error);
- _this13.emit('peerconnection:setlocaldescriptionfailed', error);
- return Promise.reject(error);
- });
- }).then(function () {
- // Resolve right away if 'pc.iceGatheringState' is 'complete'.
- if (connection.iceGatheringState === 'complete') {
- _this13._rtcReady = true;
- var e = {
- originator: 'local',
- type: type,
- sdp: connection.localDescription.sdp
- };
- debug('emit "sdp"');
- _this13.emit('sdp', e);
- return Promise.resolve(e.sdp);
- } // Add 'pc.onicencandidate' event handler to resolve on last candidate.
- return new Promise(function (resolve) {
- var finished = false;
- var iceCandidateListener;
- var iceGatheringStateListener;
- var ready = function ready() {
- connection.removeEventListener('icecandidate', iceCandidateListener);
- connection.removeEventListener('icegatheringstatechange', iceGatheringStateListener);
- finished = true;
- _this13._rtcReady = true;
- var e = {
- originator: 'local',
- type: type,
- sdp: connection.localDescription.sdp
- };
- debug('emit "sdp"');
- _this13.emit('sdp', e);
- resolve(e.sdp);
- };
- connection.addEventListener('icecandidate', iceCandidateListener = function iceCandidateListener(event) {
- var candidate = event.candidate;
- if (candidate) {
- _this13.emit('icecandidate', {
- candidate: candidate,
- ready: ready
- });
- } else if (!finished) {
- ready();
- }
- });
- connection.addEventListener('icegatheringstatechange', iceGatheringStateListener = function iceGatheringStateListener() {
- if (connection.iceGatheringState === 'complete' && !finished) {
- ready();
- }
- });
- });
- });
- }
- /**
- * Dialog Management
- */
- }, {
- key: "_createDialog",
- value: function _createDialog(message, type, early) {
- var local_tag = type === 'UAS' ? message.to_tag : message.from_tag;
- var remote_tag = type === 'UAS' ? message.from_tag : message.to_tag;
- var id = message.call_id + local_tag + remote_tag;
- var early_dialog = this._earlyDialogs[id]; // Early Dialog.
- if (early) {
- if (early_dialog) {
- return true;
- } else {
- early_dialog = new Dialog(this, message, type, Dialog.C.STATUS_EARLY); // Dialog has been successfully created.
- if (early_dialog.error) {
- debug(early_dialog.error);
- this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
- return false;
- } else {
- this._earlyDialogs[id] = early_dialog;
- return true;
- }
- }
- } // Confirmed Dialog.
- else {
- this._from_tag = message.from_tag;
- this._to_tag = message.to_tag; // In case the dialog is in _early_ state, update it.
- if (early_dialog) {
- early_dialog.update(message, type);
- this._dialog = early_dialog;
- delete this._earlyDialogs[id];
- return true;
- } // Otherwise, create a _confirmed_ dialog.
- var dialog = new Dialog(this, message, type);
- if (dialog.error) {
- debug(dialog.error);
- this._failed('remote', message, JsSIP_C.causes.INTERNAL_ERROR);
- return false;
- } else {
- this._dialog = dialog;
- return true;
- }
- }
- }
- /**
- * In dialog INVITE Reception
- */
- }, {
- key: "_receiveReinvite",
- value: function _receiveReinvite(request) {
- var _this14 = this;
- debug('receiveReinvite()');
- var contentType = request.getHeader('Content-Type');
- var data = {
- request: request,
- callback: undefined,
- reject: reject.bind(this)
- };
- var rejected = false;
- function reject() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- rejected = true;
- var status_code = options.status_code || 403;
- var reason_phrase = options.reason_phrase || '';
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- if (this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- if (status_code < 300 || status_code >= 700) {
- throw new TypeError("Invalid status_code: ".concat(status_code));
- }
- request.reply(status_code, reason_phrase, extraHeaders);
- } // Emit 'reinvite'.
- this.emit('reinvite', data);
- if (rejected) {
- return;
- }
- this._late_sdp = false; // Request without SDP.
- if (!request.body) {
- this._late_sdp = true;
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this14._createLocalDescription('offer', _this14._rtcOfferConstraints);
- }).then(function (sdp) {
- sendAnswer.call(_this14, sdp);
- }).catch(function () {
- request.reply(500);
- });
- return;
- } // Request with SDP.
- if (contentType !== 'application/sdp') {
- debug('invalid Content-Type');
- request.reply(415);
- return;
- }
- this._processInDialogSdpOffer(request) // Send answer.
- .then(function (desc) {
- if (_this14._status === C.STATUS_TERMINATED) {
- return;
- }
- sendAnswer.call(_this14, desc);
- }).catch(function (error) {
- debugerror(error);
- });
- function sendAnswer(desc) {
- var _this15 = this;
- var extraHeaders = ["Contact: ".concat(this._contact)];
- this._handleSessionTimersInIncomingRequest(request, extraHeaders);
- if (this._late_sdp) {
- desc = this._mangleOffer(desc);
- }
- request.reply(200, null, extraHeaders, desc, function () {
- _this15._status = C.STATUS_WAITING_FOR_ACK;
- _this15._setInvite2xxTimer(request, desc);
- _this15._setACKTimer();
- }); // If callback is given execute it.
- if (typeof data.callback === 'function') {
- data.callback();
- }
- }
- }
- /**
- * In dialog UPDATE Reception
- */
- }, {
- key: "_receiveUpdate",
- value: function _receiveUpdate(request) {
- var _this16 = this;
- debug('receiveUpdate()');
- var contentType = request.getHeader('Content-Type');
- var data = {
- request: request,
- callback: undefined,
- reject: reject.bind(this)
- };
- var rejected = false;
- function reject() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- rejected = true;
- var status_code = options.status_code || 403;
- var reason_phrase = options.reason_phrase || '';
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- if (this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- if (status_code < 300 || status_code >= 700) {
- throw new TypeError("Invalid status_code: ".concat(status_code));
- }
- request.reply(status_code, reason_phrase, extraHeaders);
- } // Emit 'update'.
- this.emit('update', data);
- if (rejected) {
- return;
- }
- if (!request.body) {
- sendAnswer.call(this, null);
- return;
- }
- if (contentType !== 'application/sdp') {
- debug('invalid Content-Type');
- request.reply(415);
- return;
- }
- this._processInDialogSdpOffer(request) // Send answer.
- .then(function (desc) {
- if (_this16._status === C.STATUS_TERMINATED) {
- return;
- }
- sendAnswer.call(_this16, desc);
- }).catch(function (error) {
- debugerror(error);
- });
- function sendAnswer(desc) {
- var extraHeaders = ["Contact: ".concat(this._contact)];
- this._handleSessionTimersInIncomingRequest(request, extraHeaders);
- request.reply(200, null, extraHeaders, desc); // If callback is given execute it.
- if (typeof data.callback === 'function') {
- data.callback();
- }
- }
- }
- }, {
- key: "_processInDialogSdpOffer",
- value: function _processInDialogSdpOffer(request) {
- var _this17 = this;
- debug('_processInDialogSdpOffer()');
- var sdp = request.parseSDP();
- var hold = false;
- var _iteratorNormalCompletion4 = true;
- var _didIteratorError4 = false;
- var _iteratorError4 = undefined;
- try {
- for (var _iterator4 = sdp.media[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
- var m = _step4.value;
- if (holdMediaTypes.indexOf(m.type) === -1) {
- continue;
- }
- var direction = m.direction || sdp.direction || 'sendrecv';
- if (direction === 'sendonly' || direction === 'inactive') {
- hold = true;
- } // If at least one of the streams is active don't emit 'hold'.
- else {
- hold = false;
- break;
- }
- }
- } catch (err) {
- _didIteratorError4 = true;
- _iteratorError4 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
- _iterator4.return();
- }
- } finally {
- if (_didIteratorError4) {
- throw _iteratorError4;
- }
- }
- }
- var e = {
- originator: 'remote',
- type: 'offer',
- sdp: request.body
- };
- debug('emit "sdp"');
- this.emit('sdp', e);
- var offer = new RTCSessionDescription({
- type: 'offer',
- sdp: e.sdp
- });
- this._connectionPromiseQueue = this._connectionPromiseQueue // Set remote description.
- .then(function () {
- if (_this17._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- return _this17._connection.setRemoteDescription(offer).catch(function (error) {
- request.reply(488);
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this17.emit('peerconnection:setremotedescriptionfailed', error);
- throw new Error('peerconnection.setRemoteDescription() failed');
- });
- }).then(function () {
- if (_this17._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- if (_this17._remoteHold === true && hold === false) {
- _this17._remoteHold = false;
- _this17._onunhold('remote');
- } else if (_this17._remoteHold === false && hold === true) {
- _this17._remoteHold = true;
- _this17._onhold('remote');
- }
- }) // Create local description.
- .then(function () {
- if (_this17._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- return _this17._createLocalDescription('answer', _this17._rtcAnswerConstraints).catch(function () {
- request.reply(500);
- throw new Error('_createLocalDescription() failed');
- });
- });
- return this._connectionPromiseQueue;
- }
- /**
- * In dialog Refer Reception
- */
- }, {
- key: "_receiveRefer",
- value: function _receiveRefer(request) {
- var _this18 = this;
- debug('receiveRefer()');
- if (!request.refer_to) {
- debug('no Refer-To header field present in REFER');
- request.reply(400);
- return;
- }
- if (request.refer_to.uri.scheme !== JsSIP_C.SIP) {
- debug('Refer-To header field points to a non-SIP URI scheme');
- request.reply(416);
- return;
- } // Reply before the transaction timer expires.
- request.reply(202);
- var notifier = new RTCSession_ReferNotifier(this, request.cseq);
- debug('emit "refer"'); // Emit 'refer'.
- this.emit('refer', {
- request: request,
- accept: function accept(initCallback, options) {
- _accept.call(_this18, initCallback, options);
- },
- reject: function reject() {
- _reject.call(_this18);
- }
- });
- function _accept(initCallback) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- initCallback = typeof initCallback === 'function' ? initCallback : null;
- if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- var session = new RTCSession(this._ua);
- session.on('progress', function (_ref2) {
- var response = _ref2.response;
- notifier.notify(response.status_code, response.reason_phrase);
- });
- session.on('accepted', function (_ref3) {
- var response = _ref3.response;
- notifier.notify(response.status_code, response.reason_phrase);
- });
- session.on('_failed', function (_ref4) {
- var message = _ref4.message,
- cause = _ref4.cause;
- if (message) {
- notifier.notify(message.status_code, message.reason_phrase);
- } else {
- notifier.notify(487, cause);
- }
- }); // Consider the Replaces header present in the Refer-To URI.
- if (request.refer_to.uri.hasHeader('replaces')) {
- var replaces = decodeURIComponent(request.refer_to.uri.getHeader('replaces'));
- options.extraHeaders = Utils.cloneArray(options.extraHeaders);
- options.extraHeaders.push("Replaces: ".concat(replaces));
- }
- session.connect(request.refer_to.uri.toAor(), options, initCallback);
- }
- function _reject() {
- notifier.notify(603);
- }
- }
- /**
- * In dialog Notify Reception
- */
- }, {
- key: "_receiveNotify",
- value: function _receiveNotify(request) {
- debug('receiveNotify()');
- if (!request.event) {
- request.reply(400);
- }
- switch (request.event.event) {
- case 'refer':
- {
- var id;
- var referSubscriber;
- if (request.event.params && request.event.params.id) {
- id = request.event.params.id;
- referSubscriber = this._referSubscribers[id];
- } else if (Object.keys(this._referSubscribers).length === 1) {
- referSubscriber = this._referSubscribers[Object.keys(this._referSubscribers)[0]];
- } else {
- request.reply(400, 'Missing event id parameter');
- return;
- }
- if (!referSubscriber) {
- request.reply(481, 'Subscription does not exist');
- return;
- }
- referSubscriber.receiveNotify(request);
- request.reply(200);
- break;
- }
- default:
- {
- request.reply(489);
- }
- }
- }
- /**
- * INVITE with Replaces Reception
- */
- }, {
- key: "_receiveReplaces",
- value: function _receiveReplaces(request) {
- var _this20 = this;
- debug('receiveReplaces()');
- function _accept2(initCallback) {
- var _this19 = this;
- if (this._status !== C.STATUS_WAITING_FOR_ACK && this._status !== C.STATUS_CONFIRMED) {
- return false;
- }
- var session = new RTCSession(this._ua); // Terminate the current session when the new one is confirmed.
- session.on('confirmed', function () {
- _this19.terminate();
- });
- session.init_incoming(request, initCallback);
- }
- function _reject2() {
- debug('Replaced INVITE rejected by the user');
- request.reply(486);
- } // Emit 'replace'.
- this.emit('replaces', {
- request: request,
- accept: function accept(initCallback) {
- _accept2.call(_this20, initCallback);
- },
- reject: function reject() {
- _reject2.call(_this20);
- }
- });
- }
- /**
- * Initial Request Sender
- */
- }, {
- key: "_sendInitialRequest",
- value: function _sendInitialRequest(mediaConstraints, rtcOfferConstraints, mediaStream) {
- var _this21 = this;
- var request_sender = new RequestSender(this._ua, this._request, {
- onRequestTimeout: function onRequestTimeout() {
- _this21.onRequestTimeout();
- },
- onTransportError: function onTransportError() {
- _this21.onTransportError();
- },
- // Update the request on authentication.
- onAuthenticated: function onAuthenticated(request) {
- _this21._request = request;
- },
- onReceiveResponse: function onReceiveResponse(response) {
- _this21._receiveInviteResponse(response);
- }
- }); // This Promise is resolved within the next iteration, so the app has now
- // a chance to set events such as 'peerconnection' and 'connecting'.
- Promise.resolve() // Get a stream if required.
- .then(function () {
- // A stream is given, let the app set events such as 'peerconnection' and 'connecting'.
- if (mediaStream) {
- return mediaStream;
- } // Request for user media access.
- else if (mediaConstraints.audio || mediaConstraints.video) {
- _this21._localMediaStreamLocallyGenerated = true;
- return navigator.mediaDevices.getUserMedia(mediaConstraints).catch(function (error) {
- if (_this21._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- _this21._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS);
- debugerror('emit "getusermediafailed" [error:%o]', error);
- _this21.emit('getusermediafailed', error);
- throw error;
- });
- }
- }).then(function (stream) {
- if (_this21._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- _this21._localMediaStream = stream;
- if (stream) {
- stream.getTracks().forEach(function (track) {
- _this21._connection.addTrack(track, stream);
- });
- } // TODO: should this be triggered here?
- _this21._connecting(_this21._request);
- return _this21._createLocalDescription('offer', rtcOfferConstraints).catch(function (error) {
- _this21._failed('local', null, JsSIP_C.causes.WEBRTC_ERROR);
- throw error;
- });
- }).then(function (desc) {
- if (_this21._is_canceled || _this21._status === C.STATUS_TERMINATED) {
- throw new Error('terminated');
- }
- _this21._request.body = desc;
- _this21._status = C.STATUS_INVITE_SENT;
- debug('emit "sending" [request:%o]', _this21._request); // Emit 'sending' so the app can mangle the body before the request is sent.
- _this21.emit('sending', {
- request: _this21._request
- });
- request_sender.send();
- }).catch(function (error) {
- if (_this21._status === C.STATUS_TERMINATED) {
- return;
- }
- debugerror(error);
- });
- }
- /**
- * Reception of Response for Initial INVITE
- */
- }, {
- key: "_receiveInviteResponse",
- value: function _receiveInviteResponse(response) {
- var _this22 = this;
- debug('receiveInviteResponse()'); // Handle 2XX retransmissions and responses from forked requests.
- if (this._dialog && response.status_code >= 200 && response.status_code <= 299) {
- /*
- * If it is a retransmission from the endpoint that established
- * the dialog, send an ACK
- */
- if (this._dialog.id.call_id === response.call_id && this._dialog.id.local_tag === response.from_tag && this._dialog.id.remote_tag === response.to_tag) {
- this.sendRequest(JsSIP_C.ACK);
- return;
- } // If not, send an ACK and terminate.
- else {
- var dialog = new Dialog(this, response, 'UAC');
- if (dialog.error !== undefined) {
- debug(dialog.error);
- return;
- }
- this.sendRequest(JsSIP_C.ACK);
- this.sendRequest(JsSIP_C.BYE);
- return;
- }
- } // Proceed to cancellation if the user requested.
- if (this._is_canceled) {
- if (response.status_code >= 100 && response.status_code < 200) {
- this._request.cancel(this._cancel_reason);
- } else if (response.status_code >= 200 && response.status_code < 299) {
- this._acceptAndTerminate(response);
- }
- return;
- }
- if (this._status !== C.STATUS_INVITE_SENT && this._status !== C.STATUS_1XX_RECEIVED) {
- return;
- }
- switch (true) {
- case /^100$/.test(response.status_code):
- this._status = C.STATUS_1XX_RECEIVED;
- break;
- case /^1[0-9]{2}$/.test(response.status_code):
- {
- // Do nothing with 1xx responses without To tag.
- if (!response.to_tag) {
- debug('1xx response received without to tag');
- break;
- } // Create Early Dialog if 1XX comes with contact.
- if (response.hasHeader('contact')) {
- // An error on dialog creation will fire 'failed' event.
- if (!this._createDialog(response, 'UAC', true)) {
- break;
- }
- }
- this._status = C.STATUS_1XX_RECEIVED;
- this._progress('remote', response);
- if (!response.body) {
- break;
- }
- var e = {
- originator: 'remote',
- type: 'answer',
- sdp: response.body
- };
- debug('emit "sdp"');
- this.emit('sdp', e);
- var answer = new RTCSessionDescription({
- type: 'answer',
- sdp: e.sdp
- });
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this22._connection.setRemoteDescription(answer);
- }).catch(function (error) {
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this22.emit('peerconnection:setremotedescriptionfailed', error);
- });
- break;
- }
- case /^2[0-9]{2}$/.test(response.status_code):
- {
- this._status = C.STATUS_CONFIRMED;
- if (!response.body) {
- this._acceptAndTerminate(response, 400, JsSIP_C.causes.MISSING_SDP);
- this._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
- break;
- } // An error on dialog creation will fire 'failed' event.
- if (!this._createDialog(response, 'UAC')) {
- break;
- }
- var _e = {
- originator: 'remote',
- type: 'answer',
- sdp: response.body
- };
- debug('emit "sdp"');
- this.emit('sdp', _e);
- var _answer = new RTCSessionDescription({
- type: 'answer',
- sdp: _e.sdp
- });
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- // Be ready for 200 with SDP after a 180/183 with SDP.
- // We created a SDP 'answer' for it, so check the current signaling state.
- if (_this22._connection.signalingState === 'stable') {
- return _this22._connection.createOffer(_this22._rtcOfferConstraints).then(function (offer) {
- return _this22._connection.setLocalDescription(offer);
- }).catch(function (error) {
- _this22._acceptAndTerminate(response, 500, error.toString());
- _this22._failed('local', response, JsSIP_C.causes.WEBRTC_ERROR);
- });
- }
- }).then(function () {
- _this22._connection.setRemoteDescription(_answer).then(function () {
- // Handle Session Timers.
- _this22._handleSessionTimersInIncomingResponse(response);
- _this22._accepted('remote', response);
- _this22.sendRequest(JsSIP_C.ACK);
- _this22._confirmed('local', null);
- }).catch(function (error) {
- _this22._acceptAndTerminate(response, 488, 'Not Acceptable Here');
- _this22._failed('remote', response, JsSIP_C.causes.BAD_MEDIA_DESCRIPTION);
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this22.emit('peerconnection:setremotedescriptionfailed', error);
- });
- });
- break;
- }
- default:
- {
- var cause = Utils.sipErrorCause(response.status_code);
- this._failed('remote', response, cause);
- }
- }
- }
- /**
- * Send Re-INVITE
- */
- }, {
- key: "_sendReinvite",
- value: function _sendReinvite() {
- var _this23 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- debug('sendReinvite()');
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var eventHandlers = options.eventHandlers || {};
- var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
- var succeeded = false;
- extraHeaders.push("Contact: ".concat(this._contact));
- extraHeaders.push('Content-Type: application/sdp'); // Session Timers.
- if (this._sessionTimers.running) {
- extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
- }
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this23._createLocalDescription('offer', rtcOfferConstraints);
- }).then(function (sdp) {
- sdp = _this23._mangleOffer(sdp);
- var e = {
- originator: 'local',
- type: 'offer',
- sdp: sdp
- };
- debug('emit "sdp"');
- _this23.emit('sdp', e);
- _this23.sendRequest(JsSIP_C.INVITE, {
- extraHeaders: extraHeaders,
- body: sdp,
- eventHandlers: {
- onSuccessResponse: function onSuccessResponse(response) {
- onSucceeded.call(_this23, response);
- succeeded = true;
- },
- onErrorResponse: function onErrorResponse(response) {
- onFailed.call(_this23, response);
- },
- onTransportError: function onTransportError() {
- _this23.onTransportError(); // Do nothing because session ends.
- },
- onRequestTimeout: function onRequestTimeout() {
- _this23.onRequestTimeout(); // Do nothing because session ends.
- },
- onDialogError: function onDialogError() {
- _this23.onDialogError(); // Do nothing because session ends.
- }
- }
- });
- }).catch(function () {
- onFailed();
- });
- function onSucceeded(response) {
- var _this24 = this;
- if (this._status === C.STATUS_TERMINATED) {
- return;
- }
- this.sendRequest(JsSIP_C.ACK); // If it is a 2XX retransmission exit now.
- if (succeeded) {
- return;
- } // Handle Session Timers.
- this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
- if (!response.body) {
- onFailed.call(this);
- return;
- } else if (response.getHeader('Content-Type') !== 'application/sdp') {
- onFailed.call(this);
- return;
- }
- var e = {
- originator: 'remote',
- type: 'answer',
- sdp: response.body
- };
- debug('emit "sdp"');
- this.emit('sdp', e);
- var answer = new RTCSessionDescription({
- type: 'answer',
- sdp: e.sdp
- });
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this24._connection.setRemoteDescription(answer);
- }).then(function () {
- if (eventHandlers.succeeded) {
- eventHandlers.succeeded(response);
- }
- }).catch(function (error) {
- onFailed.call(_this24);
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this24.emit('peerconnection:setremotedescriptionfailed', error);
- });
- }
- function onFailed(response) {
- if (eventHandlers.failed) {
- eventHandlers.failed(response);
- }
- }
- }
- /**
- * Send UPDATE
- */
- }, {
- key: "_sendUpdate",
- value: function _sendUpdate() {
- var _this25 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- debug('sendUpdate()');
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var eventHandlers = options.eventHandlers || {};
- var rtcOfferConstraints = options.rtcOfferConstraints || this._rtcOfferConstraints || null;
- var sdpOffer = options.sdpOffer || false;
- var succeeded = false;
- extraHeaders.push("Contact: ".concat(this._contact)); // Session Timers.
- if (this._sessionTimers.running) {
- extraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(this._sessionTimers.refresher ? 'uac' : 'uas'));
- }
- if (sdpOffer) {
- extraHeaders.push('Content-Type: application/sdp');
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this25._createLocalDescription('offer', rtcOfferConstraints);
- }).then(function (sdp) {
- sdp = _this25._mangleOffer(sdp);
- var e = {
- originator: 'local',
- type: 'offer',
- sdp: sdp
- };
- debug('emit "sdp"');
- _this25.emit('sdp', e);
- _this25.sendRequest(JsSIP_C.UPDATE, {
- extraHeaders: extraHeaders,
- body: sdp,
- eventHandlers: {
- onSuccessResponse: function onSuccessResponse(response) {
- onSucceeded.call(_this25, response);
- succeeded = true;
- },
- onErrorResponse: function onErrorResponse(response) {
- onFailed.call(_this25, response);
- },
- onTransportError: function onTransportError() {
- _this25.onTransportError(); // Do nothing because session ends.
- },
- onRequestTimeout: function onRequestTimeout() {
- _this25.onRequestTimeout(); // Do nothing because session ends.
- },
- onDialogError: function onDialogError() {
- _this25.onDialogError(); // Do nothing because session ends.
- }
- }
- });
- }).catch(function () {
- onFailed.call(_this25);
- });
- } // No SDP.
- else {
- this.sendRequest(JsSIP_C.UPDATE, {
- extraHeaders: extraHeaders,
- eventHandlers: {
- onSuccessResponse: function onSuccessResponse(response) {
- onSucceeded.call(_this25, response);
- },
- onErrorResponse: function onErrorResponse(response) {
- onFailed.call(_this25, response);
- },
- onTransportError: function onTransportError() {
- _this25.onTransportError(); // Do nothing because session ends.
- },
- onRequestTimeout: function onRequestTimeout() {
- _this25.onRequestTimeout(); // Do nothing because session ends.
- },
- onDialogError: function onDialogError() {
- _this25.onDialogError(); // Do nothing because session ends.
- }
- }
- });
- }
- function onSucceeded(response) {
- var _this26 = this;
- if (this._status === C.STATUS_TERMINATED) {
- return;
- } // If it is a 2XX retransmission exit now.
- if (succeeded) {
- return;
- } // Handle Session Timers.
- this._handleSessionTimersInIncomingResponse(response); // Must have SDP answer.
- if (sdpOffer) {
- if (!response.body) {
- onFailed.call(this);
- return;
- } else if (response.getHeader('Content-Type') !== 'application/sdp') {
- onFailed.call(this);
- return;
- }
- var e = {
- originator: 'remote',
- type: 'answer',
- sdp: response.body
- };
- debug('emit "sdp"');
- this.emit('sdp', e);
- var answer = new RTCSessionDescription({
- type: 'answer',
- sdp: e.sdp
- });
- this._connectionPromiseQueue = this._connectionPromiseQueue.then(function () {
- return _this26._connection.setRemoteDescription(answer);
- }).then(function () {
- if (eventHandlers.succeeded) {
- eventHandlers.succeeded(response);
- }
- }).catch(function (error) {
- onFailed.call(_this26);
- debugerror('emit "peerconnection:setremotedescriptionfailed" [error:%o]', error);
- _this26.emit('peerconnection:setremotedescriptionfailed', error);
- });
- } // No SDP answer.
- else if (eventHandlers.succeeded) {
- eventHandlers.succeeded(response);
- }
- }
- function onFailed(response) {
- if (eventHandlers.failed) {
- eventHandlers.failed(response);
- }
- }
- }
- }, {
- key: "_acceptAndTerminate",
- value: function _acceptAndTerminate(response, status_code, reason_phrase) {
- debug('acceptAndTerminate()');
- var extraHeaders = [];
- if (status_code) {
- reason_phrase = reason_phrase || JsSIP_C.REASON_PHRASE[status_code] || '';
- extraHeaders.push("Reason: SIP ;cause=".concat(status_code, "; text=\"").concat(reason_phrase, "\""));
- } // An error on dialog creation will fire 'failed' event.
- if (this._dialog || this._createDialog(response, 'UAC')) {
- this.sendRequest(JsSIP_C.ACK);
- this.sendRequest(JsSIP_C.BYE, {
- extraHeaders: extraHeaders
- });
- } // Update session status.
- this._status = C.STATUS_TERMINATED;
- }
- /**
- * Correctly set the SDP direction attributes if the call is on local hold
- */
- }, {
- key: "_mangleOffer",
- value: function _mangleOffer(sdp) {
- if (!this._localHold && !this._remoteHold) {
- return sdp;
- }
- sdp = sdp_transform.parse(sdp); // Local hold.
- if (this._localHold && !this._remoteHold) {
- debug('mangleOffer() | me on hold, mangling offer');
- var _iteratorNormalCompletion5 = true;
- var _didIteratorError5 = false;
- var _iteratorError5 = undefined;
- try {
- for (var _iterator5 = sdp.media[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
- var m = _step5.value;
- if (holdMediaTypes.indexOf(m.type) === -1) {
- continue;
- }
- if (!m.direction) {
- m.direction = 'sendonly';
- } else if (m.direction === 'sendrecv') {
- m.direction = 'sendonly';
- } else if (m.direction === 'recvonly') {
- m.direction = 'inactive';
- }
- }
- } catch (err) {
- _didIteratorError5 = true;
- _iteratorError5 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
- _iterator5.return();
- }
- } finally {
- if (_didIteratorError5) {
- throw _iteratorError5;
- }
- }
- }
- } // Local and remote hold.
- else if (this._localHold && this._remoteHold) {
- debug('mangleOffer() | both on hold, mangling offer');
- var _iteratorNormalCompletion6 = true;
- var _didIteratorError6 = false;
- var _iteratorError6 = undefined;
- try {
- for (var _iterator6 = sdp.media[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
- var _m = _step6.value;
- if (holdMediaTypes.indexOf(_m.type) === -1) {
- continue;
- }
- _m.direction = 'inactive';
- }
- } catch (err) {
- _didIteratorError6 = true;
- _iteratorError6 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
- _iterator6.return();
- }
- } finally {
- if (_didIteratorError6) {
- throw _iteratorError6;
- }
- }
- }
- } // Remote hold.
- else if (this._remoteHold) {
- debug('mangleOffer() | remote on hold, mangling offer');
- var _iteratorNormalCompletion7 = true;
- var _didIteratorError7 = false;
- var _iteratorError7 = undefined;
- try {
- for (var _iterator7 = sdp.media[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
- var _m2 = _step7.value;
- if (holdMediaTypes.indexOf(_m2.type) === -1) {
- continue;
- }
- if (!_m2.direction) {
- _m2.direction = 'recvonly';
- } else if (_m2.direction === 'sendrecv') {
- _m2.direction = 'recvonly';
- } else if (_m2.direction === 'recvonly') {
- _m2.direction = 'inactive';
- }
- }
- } catch (err) {
- _didIteratorError7 = true;
- _iteratorError7 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
- _iterator7.return();
- }
- } finally {
- if (_didIteratorError7) {
- throw _iteratorError7;
- }
- }
- }
- }
- return sdp_transform.write(sdp);
- }
- }, {
- key: "_setLocalMediaStatus",
- value: function _setLocalMediaStatus() {
- var enableAudio = true,
- enableVideo = true;
- if (this._localHold || this._remoteHold) {
- enableAudio = false;
- enableVideo = false;
- }
- if (this._audioMuted) {
- enableAudio = false;
- }
- if (this._videoMuted) {
- enableVideo = false;
- }
- this._toggleMuteAudio(!enableAudio);
- this._toggleMuteVideo(!enableVideo);
- }
- /**
- * Handle SessionTimers for an incoming INVITE or UPDATE.
- * @param {IncomingRequest} request
- * @param {Array} responseExtraHeaders Extra headers for the 200 response.
- */
- }, {
- key: "_handleSessionTimersInIncomingRequest",
- value: function _handleSessionTimersInIncomingRequest(request, responseExtraHeaders) {
- if (!this._sessionTimers.enabled) {
- return;
- }
- var session_expires_refresher;
- if (request.session_expires && request.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
- this._sessionTimers.currentExpires = request.session_expires;
- session_expires_refresher = request.session_expires_refresher || 'uas';
- } else {
- this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
- session_expires_refresher = 'uas';
- }
- responseExtraHeaders.push("Session-Expires: ".concat(this._sessionTimers.currentExpires, ";refresher=").concat(session_expires_refresher));
- this._sessionTimers.refresher = session_expires_refresher === 'uas';
- this._runSessionTimer();
- }
- /**
- * Handle SessionTimers for an incoming response to INVITE or UPDATE.
- * @param {IncomingResponse} response
- */
- }, {
- key: "_handleSessionTimersInIncomingResponse",
- value: function _handleSessionTimersInIncomingResponse(response) {
- if (!this._sessionTimers.enabled) {
- return;
- }
- var session_expires_refresher;
- if (response.session_expires && response.session_expires >= JsSIP_C.MIN_SESSION_EXPIRES) {
- this._sessionTimers.currentExpires = response.session_expires;
- session_expires_refresher = response.session_expires_refresher || 'uac';
- } else {
- this._sessionTimers.currentExpires = this._sessionTimers.defaultExpires;
- session_expires_refresher = 'uac';
- }
- this._sessionTimers.refresher = session_expires_refresher === 'uac';
- this._runSessionTimer();
- }
- }, {
- key: "_runSessionTimer",
- value: function _runSessionTimer() {
- var _this27 = this;
- var expires = this._sessionTimers.currentExpires;
- this._sessionTimers.running = true;
- clearTimeout(this._sessionTimers.timer); // I'm the refresher.
- if (this._sessionTimers.refresher) {
- this._sessionTimers.timer = setTimeout(function () {
- if (_this27._status === C.STATUS_TERMINATED) {
- return;
- }
- debug('runSessionTimer() | sending session refresh request');
- if (_this27._sessionTimers.refreshMethod === JsSIP_C.UPDATE) {
- _this27._sendUpdate();
- } else {
- _this27._sendReinvite();
- }
- }, expires * 500); // Half the given interval (as the RFC states).
- } // I'm not the refresher.
- else {
- this._sessionTimers.timer = setTimeout(function () {
- if (_this27._status === C.STATUS_TERMINATED) {
- return;
- }
- debugerror('runSessionTimer() | timer expired, terminating the session');
- _this27.terminate({
- cause: JsSIP_C.causes.REQUEST_TIMEOUT,
- status_code: 408,
- reason_phrase: 'Session Timer Expired'
- });
- }, expires * 1100);
- }
- }
- }, {
- key: "_toggleMuteAudio",
- value: function _toggleMuteAudio(mute) {
- var senders = this._connection.getSenders().filter(function (sender) {
- return sender.track && sender.track.kind === 'audio';
- });
- var _iteratorNormalCompletion8 = true;
- var _didIteratorError8 = false;
- var _iteratorError8 = undefined;
- try {
- for (var _iterator8 = senders[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
- var sender = _step8.value;
- sender.track.enabled = !mute;
- }
- } catch (err) {
- _didIteratorError8 = true;
- _iteratorError8 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
- _iterator8.return();
- }
- } finally {
- if (_didIteratorError8) {
- throw _iteratorError8;
- }
- }
- }
- }
- }, {
- key: "_toggleMuteVideo",
- value: function _toggleMuteVideo(mute) {
- var senders = this._connection.getSenders().filter(function (sender) {
- return sender.track && sender.track.kind === 'video';
- });
- var _iteratorNormalCompletion9 = true;
- var _didIteratorError9 = false;
- var _iteratorError9 = undefined;
- try {
- for (var _iterator9 = senders[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
- var sender = _step9.value;
- sender.track.enabled = !mute;
- }
- } catch (err) {
- _didIteratorError9 = true;
- _iteratorError9 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
- _iterator9.return();
- }
- } finally {
- if (_didIteratorError9) {
- throw _iteratorError9;
- }
- }
- }
- }
- }, {
- key: "_newRTCSession",
- value: function _newRTCSession(originator, request) {
- debug('newRTCSession()');
- this._ua.newRTCSession(this, {
- originator: originator,
- session: this,
- request: request
- });
- }
- }, {
- key: "_connecting",
- value: function _connecting(request) {
- debug('session connecting');
- debug('emit "connecting"');
- this.emit('connecting', {
- request: request
- });
- }
- }, {
- key: "_progress",
- value: function _progress(originator, response) {
- debug('session progress');
- debug('emit "progress"');
- this.emit('progress', {
- originator: originator,
- response: response || null
- });
- }
- }, {
- key: "_accepted",
- value: function _accepted(originator, message) {
- debug('session accepted');
- this._start_time = new Date();
- debug('emit "accepted"');
- this.emit('accepted', {
- originator: originator,
- response: message || null
- });
- }
- }, {
- key: "_confirmed",
- value: function _confirmed(originator, ack) {
- debug('session confirmed');
- this._is_confirmed = true;
- debug('emit "confirmed"');
- this.emit('confirmed', {
- originator: originator,
- ack: ack || null
- });
- }
- }, {
- key: "_ended",
- value: function _ended(originator, message, cause) {
- debug('session ended');
- this._end_time = new Date();
- this._close();
- debug('emit "ended"');
- this.emit('ended', {
- originator: originator,
- message: message || null,
- cause: cause
- });
- }
- }, {
- key: "_failed",
- value: function _failed(originator, message, cause) {
- debug('session failed'); // Emit private '_failed' event first.
- debug('emit "_failed"');
- this.emit('_failed', {
- originator: originator,
- message: message || null,
- cause: cause
- });
- this._close();
- debug('emit "failed"');
- this.emit('failed', {
- originator: originator,
- message: message || null,
- cause: cause
- });
- }
- }, {
- key: "_onhold",
- value: function _onhold(originator) {
- debug('session onhold');
- this._setLocalMediaStatus();
- debug('emit "hold"');
- this.emit('hold', {
- originator: originator
- });
- }
- }, {
- key: "_onunhold",
- value: function _onunhold(originator) {
- debug('session onunhold');
- this._setLocalMediaStatus();
- debug('emit "unhold"');
- this.emit('unhold', {
- originator: originator
- });
- }
- }, {
- key: "_onmute",
- value: function _onmute(_ref5) {
- var audio = _ref5.audio,
- video = _ref5.video;
- debug('session onmute');
- this._setLocalMediaStatus();
- debug('emit "muted"');
- this.emit('muted', {
- audio: audio,
- video: video
- });
- }
- }, {
- key: "_onunmute",
- value: function _onunmute(_ref6) {
- var audio = _ref6.audio,
- video = _ref6.video;
- debug('session onunmute');
- this._setLocalMediaStatus();
- debug('emit "unmuted"');
- this.emit('unmuted', {
- audio: audio,
- video: video
- });
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- } // Expose session failed/ended causes as a property of the RTCSession instance.
- }, {
- key: "causes",
- get: function get() {
- return JsSIP_C.causes;
- }
- }, {
- key: "id",
- get: function get() {
- return this._id;
- }
- }, {
- key: "connection",
- get: function get() {
- return this._connection;
- }
- }, {
- key: "contact",
- get: function get() {
- return this._contact;
- }
- }, {
- key: "direction",
- get: function get() {
- return this._direction;
- }
- }, {
- key: "local_identity",
- get: function get() {
- return this._local_identity;
- }
- }, {
- key: "remote_identity",
- get: function get() {
- return this._remote_identity;
- }
- }, {
- key: "start_time",
- get: function get() {
- return this._start_time;
- }
- }, {
- key: "end_time",
- get: function get() {
- return this._end_time;
- }
- }, {
- key: "data",
- get: function get() {
- return this._data;
- },
- set: function set(_data) {
- this._data = _data;
- }
- }, {
- key: "status",
- get: function get() {
- return this._status;
- }
- }]);
- return RTCSession;
- }(EventEmitter);
- },{"./Constants":2,"./Dialog":3,"./Exceptions":6,"./RTCSession/DTMF":13,"./RTCSession/Info":14,"./RTCSession/ReferNotifier":15,"./RTCSession/ReferSubscriber":16,"./RequestSender":18,"./SIPMessage":19,"./Timers":21,"./Transactions":22,"./URI":25,"./Utils":26,"debug":30,"events":29,"sdp-transform":35}],13:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- var EventEmitter = require('events').EventEmitter;
- var JsSIP_C = require('../Constants');
- var Exceptions = require('../Exceptions');
- var Utils = require('../Utils');
- var debug = require('debug')('JsSIP:RTCSession:DTMF');
- var debugerror = require('debug')('JsSIP:ERROR:RTCSession:DTMF');
- debugerror.log = console.warn.bind(console);
- var C = {
- MIN_DURATION: 70,
- MAX_DURATION: 6000,
- DEFAULT_DURATION: 100,
- MIN_INTER_TONE_GAP: 50,
- DEFAULT_INTER_TONE_GAP: 500
- };
- module.exports =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(DTMF, _EventEmitter);
- function DTMF(session) {
- var _this;
- _classCallCheck(this, DTMF);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(DTMF).call(this));
- _this._session = session;
- _this._direction = null;
- _this._tone = null;
- _this._duration = null;
- _this._request = null;
- return _this;
- }
- _createClass(DTMF, [{
- key: "send",
- value: function send(tone) {
- var _this2 = this;
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- if (tone === undefined) {
- throw new TypeError('Not enough arguments');
- }
- this._direction = 'outgoing'; // Check RTCSession Status.
- if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
- throw new Exceptions.InvalidStateError(this._session.status);
- }
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- this.eventHandlers = options.eventHandlers || {}; // Check tone type.
- if (typeof tone === 'string') {
- tone = tone.toUpperCase();
- } else if (typeof tone === 'number') {
- tone = tone.toString();
- } else {
- throw new TypeError("Invalid tone: ".concat(tone));
- } // Check tone value.
- if (!tone.match(/^[0-9A-DR#*]$/)) {
- throw new TypeError("Invalid tone: ".concat(tone));
- } else {
- this._tone = tone;
- } // Duration is checked/corrected in RTCSession.
- this._duration = options.duration;
- extraHeaders.push('Content-Type: application/dtmf-relay');
- var body = "Signal=".concat(this._tone, "\r\n");
- body += "Duration=".concat(this._duration);
- this._session.newDTMF({
- originator: 'local',
- dtmf: this,
- request: this._request
- });
- this._session.sendRequest(JsSIP_C.INFO, {
- extraHeaders: extraHeaders,
- eventHandlers: {
- onSuccessResponse: function onSuccessResponse(response) {
- _this2.emit('succeeded', {
- originator: 'remote',
- response: response
- });
- },
- onErrorResponse: function onErrorResponse(response) {
- if (_this2.eventHandlers.onFailed) {
- _this2.eventHandlers.onFailed();
- }
- _this2.emit('failed', {
- originator: 'remote',
- response: response
- });
- },
- onRequestTimeout: function onRequestTimeout() {
- _this2._session.onRequestTimeout();
- },
- onTransportError: function onTransportError() {
- _this2._session.onTransportError();
- },
- onDialogError: function onDialogError() {
- _this2._session.onDialogError();
- }
- },
- body: body
- });
- }
- }, {
- key: "init_incoming",
- value: function init_incoming(request) {
- var reg_tone = /^(Signal\s*?=\s*?)([0-9A-D#*]{1})(\s)?.*/;
- var reg_duration = /^(Duration\s?=\s?)([0-9]{1,4})(\s)?.*/;
- this._direction = 'incoming';
- this._request = request;
- request.reply(200);
- if (request.body) {
- var body = request.body.split('\n');
- if (body.length >= 1) {
- if (reg_tone.test(body[0])) {
- this._tone = body[0].replace(reg_tone, '$2');
- }
- }
- if (body.length >= 2) {
- if (reg_duration.test(body[1])) {
- this._duration = parseInt(body[1].replace(reg_duration, '$2'), 10);
- }
- }
- }
- if (!this._duration) {
- this._duration = C.DEFAULT_DURATION;
- }
- if (!this._tone) {
- debug('invalid INFO DTMF received, discarded');
- } else {
- this._session.newDTMF({
- originator: 'remote',
- dtmf: this,
- request: request
- });
- }
- }
- }, {
- key: "tone",
- get: function get() {
- return this._tone;
- }
- }, {
- key: "duration",
- get: function get() {
- return this._duration;
- }
- }]);
- return DTMF;
- }(EventEmitter);
- /**
- * Expose C object.
- */
- module.exports.C = C;
- },{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],14:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- var EventEmitter = require('events').EventEmitter;
- var debugerror = require('debug')('JsSIP:ERROR:RTCSession:Info');
- debugerror.log = console.warn.bind(console);
- var JsSIP_C = require('../Constants');
- var Exceptions = require('../Exceptions');
- var Utils = require('../Utils');
- module.exports =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(Info, _EventEmitter);
- function Info(session) {
- var _this;
- _classCallCheck(this, Info);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(Info).call(this));
- _this._session = session;
- _this._direction = null;
- _this._contentType = null;
- _this._body = null;
- return _this;
- }
- _createClass(Info, [{
- key: "send",
- value: function send(contentType, body) {
- var _this2 = this;
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
- this._direction = 'outgoing';
- if (contentType === undefined) {
- throw new TypeError('Not enough arguments');
- } // Check RTCSession Status.
- if (this._session.status !== this._session.C.STATUS_CONFIRMED && this._session.status !== this._session.C.STATUS_WAITING_FOR_ACK) {
- throw new Exceptions.InvalidStateError(this._session.status);
- }
- this._contentType = contentType;
- this._body = body;
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- extraHeaders.push("Content-Type: ".concat(contentType));
- this._session.newInfo({
- originator: 'local',
- info: this,
- request: this.request
- });
- this._session.sendRequest(JsSIP_C.INFO, {
- extraHeaders: extraHeaders,
- eventHandlers: {
- onSuccessResponse: function onSuccessResponse(response) {
- _this2.emit('succeeded', {
- originator: 'remote',
- response: response
- });
- },
- onErrorResponse: function onErrorResponse(response) {
- _this2.emit('failed', {
- originator: 'remote',
- response: response
- });
- },
- onTransportError: function onTransportError() {
- _this2._session.onTransportError();
- },
- onRequestTimeout: function onRequestTimeout() {
- _this2._session.onRequestTimeout();
- },
- onDialogError: function onDialogError() {
- _this2._session.onDialogError();
- }
- },
- body: body
- });
- }
- }, {
- key: "init_incoming",
- value: function init_incoming(request) {
- this._direction = 'incoming';
- this.request = request;
- request.reply(200);
- this._contentType = request.getHeader('content-type');
- this._body = request.body;
- this._session.newInfo({
- originator: 'remote',
- info: this,
- request: request
- });
- }
- }, {
- key: "contentType",
- get: function get() {
- return this._contentType;
- }
- }, {
- key: "body",
- get: function get() {
- return this._body;
- }
- }]);
- return Info;
- }(EventEmitter);
- },{"../Constants":2,"../Exceptions":6,"../Utils":26,"debug":30,"events":29}],15:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var JsSIP_C = require('../Constants');
- var debug = require('debug')('JsSIP:RTCSession:ReferNotifier');
- var C = {
- event_type: 'refer',
- body_type: 'message/sipfrag;version=2.0',
- expires: 300
- };
- module.exports =
- /*#__PURE__*/
- function () {
- function ReferNotifier(session, id, expires) {
- _classCallCheck(this, ReferNotifier);
- this._session = session;
- this._id = id;
- this._expires = expires || C.expires;
- this._active = true; // The creation of a Notifier results in an immediate NOTIFY.
- this.notify(100);
- }
- _createClass(ReferNotifier, [{
- key: "notify",
- value: function notify(code, reason) {
- debug('notify()');
- if (this._active === false) {
- return;
- }
- reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
- var state;
- if (code >= 200) {
- state = 'terminated;reason=noresource';
- } else {
- state = "active;expires=".concat(this._expires);
- } // Put this in a try/catch block.
- this._session.sendRequest(JsSIP_C.NOTIFY, {
- extraHeaders: ["Event: ".concat(C.event_type, ";id=").concat(this._id), "Subscription-State: ".concat(state), "Content-Type: ".concat(C.body_type)],
- body: "SIP/2.0 ".concat(code, " ").concat(reason),
- eventHandlers: {
- // If a negative response is received, subscription is canceled.
- onErrorResponse: function onErrorResponse() {
- this._active = false;
- }
- }
- });
- }
- }]);
- return ReferNotifier;
- }();
- },{"../Constants":2,"debug":30}],16:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- var EventEmitter = require('events').EventEmitter;
- var JsSIP_C = require('../Constants');
- var Grammar = require('../Grammar');
- var Utils = require('../Utils');
- var debug = require('debug')('JsSIP:RTCSession:ReferSubscriber');
- module.exports =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(ReferSubscriber, _EventEmitter);
- function ReferSubscriber(session) {
- var _this;
- _classCallCheck(this, ReferSubscriber);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(ReferSubscriber).call(this));
- _this._id = null;
- _this._session = session;
- return _this;
- }
- _createClass(ReferSubscriber, [{
- key: "sendRefer",
- value: function sendRefer(target) {
- var _this2 = this;
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- debug('sendRefer()');
- var extraHeaders = Utils.cloneArray(options.extraHeaders);
- var eventHandlers = options.eventHandlers || {}; // Set event handlers.
- for (var event in eventHandlers) {
- if (Object.prototype.hasOwnProperty.call(eventHandlers, event)) {
- this.on(event, eventHandlers[event]);
- }
- } // Replaces URI header field.
- var replaces = null;
- if (options.replaces) {
- replaces = options.replaces._request.call_id;
- replaces += ";to-tag=".concat(options.replaces._to_tag);
- replaces += ";from-tag=".concat(options.replaces._from_tag);
- replaces = encodeURIComponent(replaces);
- } // Refer-To header field.
- var referTo = "Refer-To: <".concat(target).concat(replaces ? "?Replaces=".concat(replaces) : '', ">");
- extraHeaders.push(referTo); // Referred-By header field.
- var referredBy = "Referred-By: <".concat(this._session._ua._configuration.uri._scheme, ":").concat(this._session._ua._configuration.uri._user, "@").concat(this._session._ua._configuration.uri._host, ">");
- extraHeaders.push(referredBy);
- extraHeaders.push("Contact: ".concat(this._session.contact));
- var request = this._session.sendRequest(JsSIP_C.REFER, {
- extraHeaders: extraHeaders,
- eventHandlers: {
- onSuccessResponse: function onSuccessResponse(response) {
- _this2._requestSucceeded(response);
- },
- onErrorResponse: function onErrorResponse(response) {
- _this2._requestFailed(response, JsSIP_C.causes.REJECTED);
- },
- onTransportError: function onTransportError() {
- _this2._requestFailed(null, JsSIP_C.causes.CONNECTION_ERROR);
- },
- onRequestTimeout: function onRequestTimeout() {
- _this2._requestFailed(null, JsSIP_C.causes.REQUEST_TIMEOUT);
- },
- onDialogError: function onDialogError() {
- _this2._requestFailed(null, JsSIP_C.causes.DIALOG_ERROR);
- }
- }
- });
- this._id = request.cseq;
- }
- }, {
- key: "receiveNotify",
- value: function receiveNotify(request) {
- debug('receiveNotify()');
- if (!request.body) {
- return;
- }
- var status_line = Grammar.parse(request.body.trim(), 'Status_Line');
- if (status_line === -1) {
- debug("receiveNotify() | error parsing NOTIFY body: \"".concat(request.body, "\""));
- return;
- }
- switch (true) {
- case /^100$/.test(status_line.status_code):
- this.emit('trying', {
- request: request,
- status_line: status_line
- });
- break;
- case /^1[0-9]{2}$/.test(status_line.status_code):
- this.emit('progress', {
- request: request,
- status_line: status_line
- });
- break;
- case /^2[0-9]{2}$/.test(status_line.status_code):
- this.emit('accepted', {
- request: request,
- status_line: status_line
- });
- break;
- default:
- this.emit('failed', {
- request: request,
- status_line: status_line
- });
- break;
- }
- }
- }, {
- key: "_requestSucceeded",
- value: function _requestSucceeded(response) {
- debug('REFER succeeded');
- debug('emit "requestSucceeded"');
- this.emit('requestSucceeded', {
- response: response
- });
- }
- }, {
- key: "_requestFailed",
- value: function _requestFailed(response, cause) {
- debug('REFER failed');
- debug('emit "requestFailed"');
- this.emit('requestFailed', {
- response: response || null,
- cause: cause
- });
- }
- }, {
- key: "id",
- get: function get() {
- return this._id;
- }
- }]);
- return ReferSubscriber;
- }(EventEmitter);
- },{"../Constants":2,"../Grammar":7,"../Utils":26,"debug":30,"events":29}],17:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var Utils = require('./Utils');
- var JsSIP_C = require('./Constants');
- var SIPMessage = require('./SIPMessage');
- var RequestSender = require('./RequestSender');
- var debug = require('debug')('JsSIP:Registrator');
- var MIN_REGISTER_EXPIRES = 10; // In seconds.
- module.exports =
- /*#__PURE__*/
- function () {
- function Registrator(ua, transport) {
- _classCallCheck(this, Registrator);
- var reg_id = 1; // Force reg_id to 1.
- this._ua = ua;
- this._transport = transport;
- this._registrar = ua.configuration.registrar_server;
- this._expires = ua.configuration.register_expires; // Call-ID and CSeq values RFC3261 10.2.
- this._call_id = Utils.createRandomToken(22);
- this._cseq = 0;
- this._to_uri = ua.configuration.uri;
- this._registrationTimer = null; // Ongoing Register request.
- this._registering = false; // Set status.
- this._registered = false; // Contact header.
- this._contact = this._ua.contact.toString(); // Sip.ice media feature tag (RFC 5768).
- this._contact += ';+sip.ice'; // Custom headers for REGISTER and un-REGISTER.
- this._extraHeaders = []; // Custom Contact header params for REGISTER and un-REGISTER.
- this._extraContactParams = '';
- if (reg_id) {
- this._contact += ";reg-id=".concat(reg_id);
- this._contact += ";+sip.instance=\"<urn:uuid:".concat(this._ua.configuration.instance_id, ">\"");
- }
- }
- _createClass(Registrator, [{
- key: "setExtraHeaders",
- value: function setExtraHeaders(extraHeaders) {
- if (!Array.isArray(extraHeaders)) {
- extraHeaders = [];
- }
- this._extraHeaders = extraHeaders.slice();
- }
- }, {
- key: "setExtraContactParams",
- value: function setExtraContactParams(extraContactParams) {
- if (!(extraContactParams instanceof Object)) {
- extraContactParams = {};
- } // Reset it.
- this._extraContactParams = '';
- for (var param_key in extraContactParams) {
- if (Object.prototype.hasOwnProperty.call(extraContactParams, param_key)) {
- var param_value = extraContactParams[param_key];
- this._extraContactParams += ";".concat(param_key);
- if (param_value) {
- this._extraContactParams += "=".concat(param_value);
- }
- }
- }
- }
- }, {
- key: "register",
- value: function register() {
- var _this = this;
- if (this._registering) {
- debug('Register request in progress...');
- return;
- }
- var extraHeaders = this._extraHeaders.slice();
- extraHeaders.push("Contact: ".concat(this._contact, ";expires=").concat(this._expires).concat(this._extraContactParams));
- extraHeaders.push("Expires: ".concat(this._expires));
- var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
- 'to_uri': this._to_uri,
- 'call_id': this._call_id,
- 'cseq': this._cseq += 1
- }, extraHeaders);
- var request_sender = new RequestSender(this._ua, request, {
- onRequestTimeout: function onRequestTimeout() {
- _this._registrationFailure(null, JsSIP_C.causes.REQUEST_TIMEOUT);
- },
- onTransportError: function onTransportError() {
- _this._registrationFailure(null, JsSIP_C.causes.CONNECTION_ERROR);
- },
- // Increase the CSeq on authentication.
- onAuthenticated: function onAuthenticated() {
- _this._cseq += 1;
- },
- onReceiveResponse: function onReceiveResponse(response) {
- // Discard responses to older REGISTER/un-REGISTER requests.
- if (response.cseq !== _this._cseq) {
- return;
- } // Clear registration timer.
- if (_this._registrationTimer !== null) {
- clearTimeout(_this._registrationTimer);
- _this._registrationTimer = null;
- }
- switch (true) {
- case /^1[0-9]{2}$/.test(response.status_code):
- {
- // Ignore provisional responses.
- break;
- }
- case /^2[0-9]{2}$/.test(response.status_code):
- {
- _this._registering = false;
- if (!response.hasHeader('Contact')) {
- debug('no Contact header in response to REGISTER, response ignored');
- break;
- }
- var contacts = response.headers['Contact'].reduce(function (a, b) {
- return a.concat(b.parsed);
- }, []); // Get the Contact pointing to us and update the expires value accordingly.
- var contact = contacts.find(function (element) {
- return element.uri.user === _this._ua.contact.uri.user;
- });
- if (!contact) {
- debug('no Contact header pointing to us, response ignored');
- break;
- }
- var expires = contact.getParam('expires');
- if (!expires && response.hasHeader('expires')) {
- expires = response.getHeader('expires');
- }
- if (!expires) {
- expires = _this._expires;
- }
- expires = Number(expires);
- if (expires < MIN_REGISTER_EXPIRES) expires = MIN_REGISTER_EXPIRES; // Re-Register or emit an event before the expiration interval has elapsed.
- // For that, decrease the expires value. ie: 3 seconds.
- _this._registrationTimer = setTimeout(function () {
- _this._registrationTimer = null; // If there are no listeners for registrationExpiring, renew registration.
- // If there are listeners, let the function listening do the register call.
- if (_this._ua.listeners('registrationExpiring').length === 0) {
- _this.register();
- } else {
- _this._ua.emit('registrationExpiring');
- }
- }, expires * 1000 - 5000); // Save gruu values.
- if (contact.hasParam('temp-gruu')) {
- _this._ua.contact.temp_gruu = contact.getParam('temp-gruu').replace(/"/g, '');
- }
- if (contact.hasParam('pub-gruu')) {
- _this._ua.contact.pub_gruu = contact.getParam('pub-gruu').replace(/"/g, '');
- }
- if (!_this._registered) {
- _this._registered = true;
- _this._ua.registered({
- response: response
- });
- }
- break;
- }
- // Interval too brief RFC3261 10.2.8.
- case /^423$/.test(response.status_code):
- {
- if (response.hasHeader('min-expires')) {
- // Increase our registration interval to the suggested minimum.
- _this._expires = Number(response.getHeader('min-expires'));
- if (_this._expires < MIN_REGISTER_EXPIRES) _this._expires = MIN_REGISTER_EXPIRES; // Attempt the registration again immediately.
- _this.register();
- } else {
- // This response MUST contain a Min-Expires header field.
- debug('423 response received for REGISTER without Min-Expires');
- _this._registrationFailure(response, JsSIP_C.causes.SIP_FAILURE_CODE);
- }
- break;
- }
- default:
- {
- var cause = Utils.sipErrorCause(response.status_code);
- _this._registrationFailure(response, cause);
- }
- }
- }
- });
- this._registering = true;
- request_sender.send();
- }
- }, {
- key: "unregister",
- value: function unregister() {
- var _this2 = this;
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- if (!this._registered) {
- debug('already unregistered');
- return;
- }
- this._registered = false; // Clear the registration timer.
- if (this._registrationTimer !== null) {
- clearTimeout(this._registrationTimer);
- this._registrationTimer = null;
- }
- var extraHeaders = this._extraHeaders.slice();
- if (options.all) {
- extraHeaders.push("Contact: *".concat(this._extraContactParams));
- } else {
- extraHeaders.push("Contact: ".concat(this._contact, ";expires=0").concat(this._extraContactParams));
- }
- extraHeaders.push('Expires: 0');
- var request = new SIPMessage.OutgoingRequest(JsSIP_C.REGISTER, this._registrar, this._ua, {
- 'to_uri': this._to_uri,
- 'call_id': this._call_id,
- 'cseq': this._cseq += 1
- }, extraHeaders);
- var request_sender = new RequestSender(this._ua, request, {
- onRequestTimeout: function onRequestTimeout() {
- _this2._unregistered(null, JsSIP_C.causes.REQUEST_TIMEOUT);
- },
- onTransportError: function onTransportError() {
- _this2._unregistered(null, JsSIP_C.causes.CONNECTION_ERROR);
- },
- // Increase the CSeq on authentication.
- onAuthenticated: function onAuthenticated() {
- _this2._cseq += 1;
- },
- onReceiveResponse: function onReceiveResponse(response) {
- switch (true) {
- case /^1[0-9]{2}$/.test(response.status_code):
- // Ignore provisional responses.
- break;
- case /^2[0-9]{2}$/.test(response.status_code):
- _this2._unregistered(response);
- break;
- default:
- {
- var cause = Utils.sipErrorCause(response.status_code);
- _this2._unregistered(response, cause);
- }
- }
- }
- });
- request_sender.send();
- }
- }, {
- key: "close",
- value: function close() {
- if (this._registered) {
- this.unregister();
- }
- }
- }, {
- key: "onTransportClosed",
- value: function onTransportClosed() {
- this._registering = false;
- if (this._registrationTimer !== null) {
- clearTimeout(this._registrationTimer);
- this._registrationTimer = null;
- }
- if (this._registered) {
- this._registered = false;
- this._ua.unregistered({});
- }
- }
- }, {
- key: "_registrationFailure",
- value: function _registrationFailure(response, cause) {
- this._registering = false;
- this._ua.registrationFailed({
- response: response || null,
- cause: cause
- });
- if (this._registered) {
- this._registered = false;
- this._ua.unregistered({
- response: response || null,
- cause: cause
- });
- }
- }
- }, {
- key: "_unregistered",
- value: function _unregistered(response, cause) {
- this._registering = false;
- this._registered = false;
- this._ua.unregistered({
- response: response || null,
- cause: cause || null
- });
- }
- }, {
- key: "registered",
- get: function get() {
- return this._registered;
- }
- }]);
- return Registrator;
- }();
- },{"./Constants":2,"./RequestSender":18,"./SIPMessage":19,"./Utils":26,"debug":30}],18:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var JsSIP_C = require('./Constants');
- var DigestAuthentication = require('./DigestAuthentication');
- var Transactions = require('./Transactions');
- var debug = require('debug')('JsSIP:RequestSender'); // Default event handlers.
- var EventHandlers = {
- onRequestTimeout: function onRequestTimeout() {},
- onTransportError: function onTransportError() {},
- onReceiveResponse: function onReceiveResponse() {},
- onAuthenticated: function onAuthenticated() {}
- };
- module.exports =
- /*#__PURE__*/
- function () {
- function RequestSender(ua, request, eventHandlers) {
- _classCallCheck(this, RequestSender);
- this._ua = ua;
- this._eventHandlers = eventHandlers;
- this._method = request.method;
- this._request = request;
- this._auth = null;
- this._challenged = false;
- this._staled = false; // Define the undefined handlers.
- for (var handler in EventHandlers) {
- if (Object.prototype.hasOwnProperty.call(EventHandlers, handler)) {
- if (!this._eventHandlers[handler]) {
- this._eventHandlers[handler] = EventHandlers[handler];
- }
- }
- } // If ua is in closing process or even closed just allow sending Bye and ACK.
- if (ua.status === ua.C.STATUS_USER_CLOSED && (this._method !== JsSIP_C.BYE || this._method !== JsSIP_C.ACK)) {
- this._eventHandlers.onTransportError();
- }
- }
- /**
- * Create the client transaction and send the message.
- */
- _createClass(RequestSender, [{
- key: "send",
- value: function send() {
- var _this = this;
- var eventHandlers = {
- onRequestTimeout: function onRequestTimeout() {
- _this._eventHandlers.onRequestTimeout();
- },
- onTransportError: function onTransportError() {
- _this._eventHandlers.onTransportError();
- },
- onReceiveResponse: function onReceiveResponse(response) {
- _this._receiveResponse(response);
- }
- };
- switch (this._method) {
- case 'INVITE':
- this.clientTransaction = new Transactions.InviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
- break;
- case 'ACK':
- this.clientTransaction = new Transactions.AckClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
- break;
- default:
- this.clientTransaction = new Transactions.NonInviteClientTransaction(this._ua, this._ua.transport, this._request, eventHandlers);
- }
- this.clientTransaction.send();
- }
- /**
- * Called from client transaction when receiving a correct response to the request.
- * Authenticate request if needed or pass the response back to the applicant.
- */
- }, {
- key: "_receiveResponse",
- value: function _receiveResponse(response) {
- var challenge;
- var authorization_header_name;
- var status_code = response.status_code;
- /*
- * Authentication
- * Authenticate once. _challenged_ flag used to avoid infinite authentications.
- */
- if ((status_code === 401 || status_code === 407) && (this._ua.configuration.password !== null || this._ua.configuration.ha1 !== null)) {
- // Get and parse the appropriate WWW-Authenticate or Proxy-Authenticate header.
- if (response.status_code === 401) {
- challenge = response.parseHeader('www-authenticate');
- authorization_header_name = 'authorization';
- } else {
- challenge = response.parseHeader('proxy-authenticate');
- authorization_header_name = 'proxy-authorization';
- } // Verify it seems a valid challenge.
- if (!challenge) {
- debug("".concat(response.status_code, " with wrong or missing challenge, cannot authenticate"));
- this._eventHandlers.onReceiveResponse(response);
- return;
- }
- if (!this._challenged || !this._staled && challenge.stale === true) {
- if (!this._auth) {
- this._auth = new DigestAuthentication({
- username: this._ua.configuration.authorization_user,
- password: this._ua.configuration.password,
- realm: this._ua.configuration.realm,
- ha1: this._ua.configuration.ha1
- });
- } // Verify that the challenge is really valid.
- if (!this._auth.authenticate(this._request, challenge)) {
- this._eventHandlers.onReceiveResponse(response);
- return;
- }
- this._challenged = true; // Update ha1 and realm in the UA.
- this._ua.set('realm', this._auth.get('realm'));
- this._ua.set('ha1', this._auth.get('ha1'));
- if (challenge.stale) {
- this._staled = true;
- }
- this._request = this._request.clone();
- this._request.cseq += 1;
- this._request.setHeader('cseq', "".concat(this._request.cseq, " ").concat(this._method));
- this._request.setHeader(authorization_header_name, this._auth.toString());
- this._eventHandlers.onAuthenticated(this._request);
- this.send();
- } else {
- this._eventHandlers.onReceiveResponse(response);
- }
- } else {
- this._eventHandlers.onReceiveResponse(response);
- }
- }
- }]);
- return RequestSender;
- }();
- },{"./Constants":2,"./DigestAuthentication":5,"./Transactions":22,"debug":30}],19:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var sdp_transform = require('sdp-transform');
- var JsSIP_C = require('./Constants');
- var Utils = require('./Utils');
- var NameAddrHeader = require('./NameAddrHeader');
- var Grammar = require('./Grammar');
- var debug = require('debug')('JsSIP:SIPMessage');
- /**
- * -param {String} method request method
- * -param {String} ruri request uri
- * -param {UA} ua
- * -param {Object} params parameters that will have priority over ua.configuration parameters:
- * <br>
- * - cseq, call_id, from_tag, from_uri, from_display_name, to_uri, to_tag, route_set
- * -param {Object} [headers] extra headers
- * -param {String} [body]
- */
- var OutgoingRequest =
- /*#__PURE__*/
- function () {
- function OutgoingRequest(method, ruri, ua, params, extraHeaders, body) {
- _classCallCheck(this, OutgoingRequest);
- // Mandatory parameters check.
- if (!method || !ruri || !ua) {
- return null;
- }
- params = params || {};
- this.ua = ua;
- this.headers = {};
- this.method = method;
- this.ruri = ruri;
- this.body = body;
- this.extraHeaders = Utils.cloneArray(extraHeaders); // Fill the Common SIP Request Headers.
- // Route.
- if (params.route_set) {
- this.setHeader('route', params.route_set);
- } else if (ua.configuration.use_preloaded_route) {
- this.setHeader('route', "<".concat(ua.transport.sip_uri, ";lr>"));
- } // Via.
- // Empty Via header. Will be filled by the client transaction.
- this.setHeader('via', ''); // Max-Forwards.
- this.setHeader('max-forwards', JsSIP_C.MAX_FORWARDS); // To
- var to_uri = params.to_uri || ruri;
- var to_params = params.to_tag ? {
- tag: params.to_tag
- } : null;
- var to_display_name = typeof params.to_display_name !== 'undefined' ? params.to_display_name : null;
- this.to = new NameAddrHeader(to_uri, to_display_name, to_params);
- this.setHeader('to', this.to.toString()); // From.
- var from_uri = params.from_uri || ua.configuration.uri;
- var from_params = {
- tag: params.from_tag || Utils.newTag()
- };
- var display_name;
- if (typeof params.from_display_name !== 'undefined') {
- display_name = params.from_display_name;
- } else if (ua.configuration.display_name) {
- display_name = ua.configuration.display_name;
- } else {
- display_name = null;
- }
- this.from = new NameAddrHeader(from_uri, display_name, from_params);
- this.setHeader('from', this.from.toString()); // Call-ID.
- var call_id = params.call_id || ua.configuration.jssip_id + Utils.createRandomToken(15);
- this.call_id = call_id;
- this.setHeader('call-id', call_id); // CSeq.
- var cseq = params.cseq || Math.floor(Math.random() * 10000);
- this.cseq = cseq;
- this.setHeader('cseq', "".concat(cseq, " ").concat(method));
- }
- /**
- * Replace the the given header by the given value.
- * -param {String} name header name
- * -param {String | Array} value header value
- */
- _createClass(OutgoingRequest, [{
- key: "setHeader",
- value: function setHeader(name, value) {
- // Remove the header from extraHeaders if present.
- var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
- for (var idx = 0; idx < this.extraHeaders.length; idx++) {
- if (regexp.test(this.extraHeaders[idx])) {
- this.extraHeaders.splice(idx, 1);
- }
- }
- this.headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
- }
- /**
- * Get the value of the given header name at the given position.
- * -param {String} name header name
- * -returns {String|undefined} Returns the specified header, null if header doesn't exist.
- */
- }, {
- key: "getHeader",
- value: function getHeader(name) {
- var headers = this.headers[Utils.headerize(name)];
- if (headers) {
- if (headers[0]) {
- return headers[0];
- }
- } else {
- var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = this.extraHeaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var header = _step.value;
- if (regexp.test(header)) {
- return header.substring(header.indexOf(':') + 1).trim();
- }
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- }
- return;
- }
- /**
- * Get the header/s of the given name.
- * -param {String} name header name
- * -returns {Array} Array with all the headers of the specified name.
- */
- }, {
- key: "getHeaders",
- value: function getHeaders(name) {
- var headers = this.headers[Utils.headerize(name)];
- var result = [];
- if (headers) {
- var _iteratorNormalCompletion2 = true;
- var _didIteratorError2 = false;
- var _iteratorError2 = undefined;
- try {
- for (var _iterator2 = headers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
- var header = _step2.value;
- result.push(header);
- }
- } catch (err) {
- _didIteratorError2 = true;
- _iteratorError2 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
- _iterator2.return();
- }
- } finally {
- if (_didIteratorError2) {
- throw _iteratorError2;
- }
- }
- }
- return result;
- } else {
- var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
- var _iteratorNormalCompletion3 = true;
- var _didIteratorError3 = false;
- var _iteratorError3 = undefined;
- try {
- for (var _iterator3 = this.extraHeaders[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
- var _header = _step3.value;
- if (regexp.test(_header)) {
- result.push(_header.substring(_header.indexOf(':') + 1).trim());
- }
- }
- } catch (err) {
- _didIteratorError3 = true;
- _iteratorError3 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
- _iterator3.return();
- }
- } finally {
- if (_didIteratorError3) {
- throw _iteratorError3;
- }
- }
- }
- return result;
- }
- }
- /**
- * Verify the existence of the given header.
- * -param {String} name header name
- * -returns {boolean} true if header with given name exists, false otherwise
- */
- }, {
- key: "hasHeader",
- value: function hasHeader(name) {
- if (this.headers[Utils.headerize(name)]) {
- return true;
- } else {
- var regexp = new RegExp("^\\s*".concat(name, "\\s*:"), 'i');
- var _iteratorNormalCompletion4 = true;
- var _didIteratorError4 = false;
- var _iteratorError4 = undefined;
- try {
- for (var _iterator4 = this.extraHeaders[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
- var header = _step4.value;
- if (regexp.test(header)) {
- return true;
- }
- }
- } catch (err) {
- _didIteratorError4 = true;
- _iteratorError4 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
- _iterator4.return();
- }
- } finally {
- if (_didIteratorError4) {
- throw _iteratorError4;
- }
- }
- }
- }
- return false;
- }
- /**
- * Parse the current body as a SDP and store the resulting object
- * into this.sdp.
- * -param {Boolean} force: Parse even if this.sdp already exists.
- *
- * Returns this.sdp.
- */
- }, {
- key: "parseSDP",
- value: function parseSDP(force) {
- if (!force && this.sdp) {
- return this.sdp;
- } else {
- this.sdp = sdp_transform.parse(this.body || '');
- return this.sdp;
- }
- }
- }, {
- key: "toString",
- value: function toString() {
- var msg = "".concat(this.method, " ").concat(this.ruri, " SIP/2.0\r\n");
- for (var headerName in this.headers) {
- if (Object.prototype.hasOwnProperty.call(this.headers, headerName)) {
- var _iteratorNormalCompletion5 = true;
- var _didIteratorError5 = false;
- var _iteratorError5 = undefined;
- try {
- for (var _iterator5 = this.headers[headerName][Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
- var headerValue = _step5.value;
- msg += "".concat(headerName, ": ").concat(headerValue, "\r\n");
- }
- } catch (err) {
- _didIteratorError5 = true;
- _iteratorError5 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
- _iterator5.return();
- }
- } finally {
- if (_didIteratorError5) {
- throw _iteratorError5;
- }
- }
- }
- }
- }
- var _iteratorNormalCompletion6 = true;
- var _didIteratorError6 = false;
- var _iteratorError6 = undefined;
- try {
- for (var _iterator6 = this.extraHeaders[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
- var header = _step6.value;
- msg += "".concat(header.trim(), "\r\n");
- } // Supported.
- } catch (err) {
- _didIteratorError6 = true;
- _iteratorError6 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
- _iterator6.return();
- }
- } finally {
- if (_didIteratorError6) {
- throw _iteratorError6;
- }
- }
- }
- var supported = [];
- switch (this.method) {
- case JsSIP_C.REGISTER:
- supported.push('path', 'gruu');
- break;
- case JsSIP_C.INVITE:
- if (this.ua.configuration.session_timers) {
- supported.push('timer');
- }
- if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
- supported.push('gruu');
- }
- supported.push('ice', 'replaces');
- break;
- case JsSIP_C.UPDATE:
- if (this.ua.configuration.session_timers) {
- supported.push('timer');
- }
- supported.push('ice');
- break;
- }
- supported.push('outbound');
- var userAgent = this.ua.configuration.user_agent || JsSIP_C.USER_AGENT; // Allow.
- msg += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
- msg += "Supported: ".concat(supported, "\r\n");
- msg += "User-Agent: ".concat(userAgent, "\r\n");
- if (this.body) {
- var length = Utils.str_utf8_length(this.body);
- msg += "Content-Length: ".concat(length, "\r\n\r\n");
- msg += this.body;
- } else {
- msg += 'Content-Length: 0\r\n\r\n';
- }
- return msg;
- }
- }, {
- key: "clone",
- value: function clone() {
- var request = new OutgoingRequest(this.method, this.ruri, this.ua);
- Object.keys(this.headers).forEach(function (name) {
- request.headers[name] = this.headers[name].slice();
- }, this);
- request.body = this.body;
- request.extraHeaders = Utils.cloneArray(this.extraHeaders);
- request.to = this.to;
- request.from = this.from;
- request.call_id = this.call_id;
- request.cseq = this.cseq;
- return request;
- }
- }]);
- return OutgoingRequest;
- }();
- var InitialOutgoingInviteRequest =
- /*#__PURE__*/
- function (_OutgoingRequest) {
- _inherits(InitialOutgoingInviteRequest, _OutgoingRequest);
- function InitialOutgoingInviteRequest(ruri, ua, params, extraHeaders, body) {
- var _this;
- _classCallCheck(this, InitialOutgoingInviteRequest);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(InitialOutgoingInviteRequest).call(this, JsSIP_C.INVITE, ruri, ua, params, extraHeaders, body));
- _this.transaction = null;
- return _this;
- }
- _createClass(InitialOutgoingInviteRequest, [{
- key: "cancel",
- value: function cancel(reason) {
- this.transaction.cancel(reason);
- }
- }, {
- key: "clone",
- value: function clone() {
- var request = new InitialOutgoingInviteRequest(this.ruri, this.ua);
- Object.keys(this.headers).forEach(function (name) {
- request.headers[name] = this.headers[name].slice();
- }, this);
- request.body = this.body;
- request.extraHeaders = Utils.cloneArray(this.extraHeaders);
- request.to = this.to;
- request.from = this.from;
- request.call_id = this.call_id;
- request.cseq = this.cseq;
- request.transaction = this.transaction;
- return request;
- }
- }]);
- return InitialOutgoingInviteRequest;
- }(OutgoingRequest);
- var IncomingMessage =
- /*#__PURE__*/
- function () {
- function IncomingMessage() {
- _classCallCheck(this, IncomingMessage);
- this.data = null;
- this.headers = null;
- this.method = null;
- this.via = null;
- this.via_branch = null;
- this.call_id = null;
- this.cseq = null;
- this.from = null;
- this.from_tag = null;
- this.to = null;
- this.to_tag = null;
- this.body = null;
- this.sdp = null;
- }
- /**
- * Insert a header of the given name and value into the last position of the
- * header array.
- */
- _createClass(IncomingMessage, [{
- key: "addHeader",
- value: function addHeader(name, value) {
- var header = {
- raw: value
- };
- name = Utils.headerize(name);
- if (this.headers[name]) {
- this.headers[name].push(header);
- } else {
- this.headers[name] = [header];
- }
- }
- /**
- * Get the value of the given header name at the given position.
- */
- }, {
- key: "getHeader",
- value: function getHeader(name) {
- var header = this.headers[Utils.headerize(name)];
- if (header) {
- if (header[0]) {
- return header[0].raw;
- }
- } else {
- return;
- }
- }
- /**
- * Get the header/s of the given name.
- */
- }, {
- key: "getHeaders",
- value: function getHeaders(name) {
- var headers = this.headers[Utils.headerize(name)];
- var result = [];
- if (!headers) {
- return [];
- }
- var _iteratorNormalCompletion7 = true;
- var _didIteratorError7 = false;
- var _iteratorError7 = undefined;
- try {
- for (var _iterator7 = headers[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
- var header = _step7.value;
- result.push(header.raw);
- }
- } catch (err) {
- _didIteratorError7 = true;
- _iteratorError7 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
- _iterator7.return();
- }
- } finally {
- if (_didIteratorError7) {
- throw _iteratorError7;
- }
- }
- }
- return result;
- }
- /**
- * Verify the existence of the given header.
- */
- }, {
- key: "hasHeader",
- value: function hasHeader(name) {
- return this.headers[Utils.headerize(name)] ? true : false;
- }
- /**
- * Parse the given header on the given index.
- * -param {String} name header name
- * -param {Number} [idx=0] header index
- * -returns {Object|undefined} Parsed header object, undefined if the header
- * is not present or in case of a parsing error.
- */
- }, {
- key: "parseHeader",
- value: function parseHeader(name) {
- var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
- name = Utils.headerize(name);
- if (!this.headers[name]) {
- debug("header \"".concat(name, "\" not present"));
- return;
- } else if (idx >= this.headers[name].length) {
- debug("not so many \"".concat(name, "\" headers present"));
- return;
- }
- var header = this.headers[name][idx];
- var value = header.raw;
- if (header.parsed) {
- return header.parsed;
- } // Substitute '-' by '_' for grammar rule matching.
- var parsed = Grammar.parse(value, name.replace(/-/g, '_'));
- if (parsed === -1) {
- this.headers[name].splice(idx, 1); // delete from headers
- debug("error parsing \"".concat(name, "\" header field with value \"").concat(value, "\""));
- return;
- } else {
- header.parsed = parsed;
- return parsed;
- }
- }
- /**
- * Message Header attribute selector. Alias of parseHeader.
- * -param {String} name header name
- * -param {Number} [idx=0] header index
- * -returns {Object|undefined} Parsed header object, undefined if the header
- * is not present or in case of a parsing error.
- *
- * -example
- * message.s('via',3).port
- */
- }, {
- key: "s",
- value: function s(name, idx) {
- return this.parseHeader(name, idx);
- }
- /**
- * Replace the value of the given header by the value.
- * -param {String} name header name
- * -param {String} value header value
- */
- }, {
- key: "setHeader",
- value: function setHeader(name, value) {
- var header = {
- raw: value
- };
- this.headers[Utils.headerize(name)] = [header];
- }
- /**
- * Parse the current body as a SDP and store the resulting object
- * into this.sdp.
- * -param {Boolean} force: Parse even if this.sdp already exists.
- *
- * Returns this.sdp.
- */
- }, {
- key: "parseSDP",
- value: function parseSDP(force) {
- if (!force && this.sdp) {
- return this.sdp;
- } else {
- this.sdp = sdp_transform.parse(this.body || '');
- return this.sdp;
- }
- }
- }, {
- key: "toString",
- value: function toString() {
- return this.data;
- }
- }]);
- return IncomingMessage;
- }();
- var IncomingRequest =
- /*#__PURE__*/
- function (_IncomingMessage) {
- _inherits(IncomingRequest, _IncomingMessage);
- function IncomingRequest(ua) {
- var _this2;
- _classCallCheck(this, IncomingRequest);
- _this2 = _possibleConstructorReturn(this, _getPrototypeOf(IncomingRequest).call(this));
- _this2.ua = ua;
- _this2.headers = {};
- _this2.ruri = null;
- _this2.transport = null;
- _this2.server_transaction = null;
- return _this2;
- }
- /**
- * Stateful reply.
- * -param {Number} code status code
- * -param {String} reason reason phrase
- * -param {Object} headers extra headers
- * -param {String} body body
- * -param {Function} [onSuccess] onSuccess callback
- * -param {Function} [onFailure] onFailure callback
- */
- _createClass(IncomingRequest, [{
- key: "reply",
- value: function reply(code, reason, extraHeaders, body, onSuccess, onFailure) {
- var supported = [];
- var to = this.getHeader('To');
- code = code || null;
- reason = reason || null; // Validate code and reason values.
- if (!code || code < 100 || code > 699) {
- throw new TypeError("Invalid status_code: ".concat(code));
- } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
- throw new TypeError("Invalid reason_phrase: ".concat(reason));
- }
- reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
- extraHeaders = Utils.cloneArray(extraHeaders);
- var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
- if (this.method === JsSIP_C.INVITE && code > 100 && code <= 200) {
- var headers = this.getHeaders('record-route');
- var _iteratorNormalCompletion8 = true;
- var _didIteratorError8 = false;
- var _iteratorError8 = undefined;
- try {
- for (var _iterator8 = headers[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
- var header = _step8.value;
- response += "Record-Route: ".concat(header, "\r\n");
- }
- } catch (err) {
- _didIteratorError8 = true;
- _iteratorError8 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
- _iterator8.return();
- }
- } finally {
- if (_didIteratorError8) {
- throw _iteratorError8;
- }
- }
- }
- }
- var vias = this.getHeaders('via');
- var _iteratorNormalCompletion9 = true;
- var _didIteratorError9 = false;
- var _iteratorError9 = undefined;
- try {
- for (var _iterator9 = vias[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
- var via = _step9.value;
- response += "Via: ".concat(via, "\r\n");
- }
- } catch (err) {
- _didIteratorError9 = true;
- _iteratorError9 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion9 && _iterator9.return != null) {
- _iterator9.return();
- }
- } finally {
- if (_didIteratorError9) {
- throw _iteratorError9;
- }
- }
- }
- if (!this.to_tag && code > 100) {
- to += ";tag=".concat(Utils.newTag());
- } else if (this.to_tag && !this.s('to').hasParam('tag')) {
- to += ";tag=".concat(this.to_tag);
- }
- response += "To: ".concat(to, "\r\n");
- response += "From: ".concat(this.getHeader('From'), "\r\n");
- response += "Call-ID: ".concat(this.call_id, "\r\n");
- response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
- var _iteratorNormalCompletion10 = true;
- var _didIteratorError10 = false;
- var _iteratorError10 = undefined;
- try {
- for (var _iterator10 = extraHeaders[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
- var _header2 = _step10.value;
- response += "".concat(_header2.trim(), "\r\n");
- } // Supported.
- } catch (err) {
- _didIteratorError10 = true;
- _iteratorError10 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion10 && _iterator10.return != null) {
- _iterator10.return();
- }
- } finally {
- if (_didIteratorError10) {
- throw _iteratorError10;
- }
- }
- }
- switch (this.method) {
- case JsSIP_C.INVITE:
- if (this.ua.configuration.session_timers) {
- supported.push('timer');
- }
- if (this.ua.contact.pub_gruu || this.ua.contact.temp_gruu) {
- supported.push('gruu');
- }
- supported.push('ice', 'replaces');
- break;
- case JsSIP_C.UPDATE:
- if (this.ua.configuration.session_timers) {
- supported.push('timer');
- }
- if (body) {
- supported.push('ice');
- }
- supported.push('replaces');
- }
- supported.push('outbound'); // Allow and Accept.
- if (this.method === JsSIP_C.OPTIONS) {
- response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
- response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
- } else if (code === 405) {
- response += "Allow: ".concat(JsSIP_C.ALLOWED_METHODS, "\r\n");
- } else if (code === 415) {
- response += "Accept: ".concat(JsSIP_C.ACCEPTED_BODY_TYPES, "\r\n");
- }
- response += "Supported: ".concat(supported, "\r\n");
- if (body) {
- var length = Utils.str_utf8_length(body);
- response += 'Content-Type: application/sdp\r\n';
- response += "Content-Length: ".concat(length, "\r\n\r\n");
- response += body;
- } else {
- response += "Content-Length: ".concat(0, "\r\n\r\n");
- }
- this.server_transaction.receiveResponse(code, response, onSuccess, onFailure);
- }
- /**
- * Stateless reply.
- * -param {Number} code status code
- * -param {String} reason reason phrase
- */
- }, {
- key: "reply_sl",
- value: function reply_sl() {
- var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
- var reason = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
- var vias = this.getHeaders('via'); // Validate code and reason values.
- if (!code || code < 100 || code > 699) {
- throw new TypeError("Invalid status_code: ".concat(code));
- } else if (reason && typeof reason !== 'string' && !(reason instanceof String)) {
- throw new TypeError("Invalid reason_phrase: ".concat(reason));
- }
- reason = reason || JsSIP_C.REASON_PHRASE[code] || '';
- var response = "SIP/2.0 ".concat(code, " ").concat(reason, "\r\n");
- var _iteratorNormalCompletion11 = true;
- var _didIteratorError11 = false;
- var _iteratorError11 = undefined;
- try {
- for (var _iterator11 = vias[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
- var via = _step11.value;
- response += "Via: ".concat(via, "\r\n");
- }
- } catch (err) {
- _didIteratorError11 = true;
- _iteratorError11 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion11 && _iterator11.return != null) {
- _iterator11.return();
- }
- } finally {
- if (_didIteratorError11) {
- throw _iteratorError11;
- }
- }
- }
- var to = this.getHeader('To');
- if (!this.to_tag && code > 100) {
- to += ";tag=".concat(Utils.newTag());
- } else if (this.to_tag && !this.s('to').hasParam('tag')) {
- to += ";tag=".concat(this.to_tag);
- }
- response += "To: ".concat(to, "\r\n");
- response += "From: ".concat(this.getHeader('From'), "\r\n");
- response += "Call-ID: ".concat(this.call_id, "\r\n");
- response += "CSeq: ".concat(this.cseq, " ").concat(this.method, "\r\n");
- response += "Content-Length: ".concat(0, "\r\n\r\n");
- this.transport.send(response);
- }
- }]);
- return IncomingRequest;
- }(IncomingMessage);
- var IncomingResponse =
- /*#__PURE__*/
- function (_IncomingMessage2) {
- _inherits(IncomingResponse, _IncomingMessage2);
- function IncomingResponse() {
- var _this3;
- _classCallCheck(this, IncomingResponse);
- _this3 = _possibleConstructorReturn(this, _getPrototypeOf(IncomingResponse).call(this));
- _this3.headers = {};
- _this3.status_code = null;
- _this3.reason_phrase = null;
- return _this3;
- }
- return IncomingResponse;
- }(IncomingMessage);
- module.exports = {
- OutgoingRequest: OutgoingRequest,
- InitialOutgoingInviteRequest: InitialOutgoingInviteRequest,
- IncomingRequest: IncomingRequest,
- IncomingResponse: IncomingResponse
- };
- },{"./Constants":2,"./Grammar":7,"./NameAddrHeader":10,"./Utils":26,"debug":30,"sdp-transform":35}],20:[function(require,module,exports){
- "use strict";
- var Utils = require('./Utils');
- var Grammar = require('./Grammar');
- var debugerror = require('debug')('JsSIP:ERROR:Socket');
- debugerror.log = console.warn.bind(console);
- /**
- * Interface documentation: https://jssip.net/documentation/$last_version/api/socket/
- *
- * interface Socket {
- * attribute String via_transport
- * attribute String url
- * attribute String sip_uri
- *
- * method connect();
- * method disconnect();
- * method send(data);
- *
- * attribute EventHandler onconnect
- * attribute EventHandler ondisconnect
- * attribute EventHandler ondata
- * }
- *
- */
- exports.isSocket = function (socket) {
- // Ignore if an array is given.
- if (Array.isArray(socket)) {
- return false;
- }
- if (typeof socket === 'undefined') {
- debugerror('undefined JsSIP.Socket instance');
- return false;
- } // Check Properties.
- try {
- if (!Utils.isString(socket.url)) {
- debugerror('missing or invalid JsSIP.Socket url property');
- throw new Error();
- }
- if (!Utils.isString(socket.via_transport)) {
- debugerror('missing or invalid JsSIP.Socket via_transport property');
- throw new Error();
- }
- if (Grammar.parse(socket.sip_uri, 'SIP_URI') === -1) {
- debugerror('missing or invalid JsSIP.Socket sip_uri property');
- throw new Error();
- }
- } catch (e) {
- return false;
- } // Check Methods.
- try {
- ['connect', 'disconnect', 'send'].forEach(function (method) {
- if (!Utils.isFunction(socket[method])) {
- debugerror("missing or invalid JsSIP.Socket method: ".concat(method));
- throw new Error();
- }
- });
- } catch (e) {
- return false;
- }
- return true;
- };
- },{"./Grammar":7,"./Utils":26,"debug":30}],21:[function(require,module,exports){
- "use strict";
- var T1 = 500,
- T2 = 4000,
- T4 = 5000;
- module.exports = {
- T1: T1,
- T2: T2,
- T4: T4,
- TIMER_B: 64 * T1,
- TIMER_D: 0 * T1,
- TIMER_F: 64 * T1,
- TIMER_H: 64 * T1,
- TIMER_I: 0 * T1,
- TIMER_J: 0 * T1,
- TIMER_K: 0 * T4,
- TIMER_L: 64 * T1,
- TIMER_M: 64 * T1,
- PROVISIONAL_RESPONSE_INTERVAL: 60000 // See RFC 3261 Section 13.3.1.1
- };
- },{}],22:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- var EventEmitter = require('events').EventEmitter;
- var JsSIP_C = require('./Constants');
- var SIPMessage = require('./SIPMessage');
- var Timers = require('./Timers');
- var debugnict = require('debug')('JsSIP:NonInviteClientTransaction');
- var debugict = require('debug')('JsSIP:InviteClientTransaction');
- var debugact = require('debug')('JsSIP:AckClientTransaction');
- var debugnist = require('debug')('JsSIP:NonInviteServerTransaction');
- var debugist = require('debug')('JsSIP:InviteServerTransaction');
- var C = {
- // Transaction states.
- STATUS_TRYING: 1,
- STATUS_PROCEEDING: 2,
- STATUS_CALLING: 3,
- STATUS_ACCEPTED: 4,
- STATUS_COMPLETED: 5,
- STATUS_TERMINATED: 6,
- STATUS_CONFIRMED: 7,
- // Transaction types.
- NON_INVITE_CLIENT: 'nict',
- NON_INVITE_SERVER: 'nist',
- INVITE_CLIENT: 'ict',
- INVITE_SERVER: 'ist'
- };
- var NonInviteClientTransaction =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(NonInviteClientTransaction, _EventEmitter);
- function NonInviteClientTransaction(ua, transport, request, eventHandlers) {
- var _this;
- _classCallCheck(this, NonInviteClientTransaction);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(NonInviteClientTransaction).call(this));
- _this.type = C.NON_INVITE_CLIENT;
- _this.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
- _this.ua = ua;
- _this.transport = transport;
- _this.request = request;
- _this.eventHandlers = eventHandlers;
- var via = "SIP/2.0/".concat(transport.via_transport);
- via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this.id);
- _this.request.setHeader('via', via);
- _this.ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this)));
- return _this;
- }
- _createClass(NonInviteClientTransaction, [{
- key: "stateChanged",
- value: function stateChanged(state) {
- this.state = state;
- this.emit('stateChanged');
- }
- }, {
- key: "send",
- value: function send() {
- var _this2 = this;
- this.stateChanged(C.STATUS_TRYING);
- this.F = setTimeout(function () {
- _this2.timer_F();
- }, Timers.TIMER_F);
- if (!this.transport.send(this.request)) {
- this.onTransportError();
- }
- }
- }, {
- key: "onTransportError",
- value: function onTransportError() {
- debugnict("transport error occurred, deleting transaction ".concat(this.id));
- clearTimeout(this.F);
- clearTimeout(this.K);
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- this.eventHandlers.onTransportError();
- }
- }, {
- key: "timer_F",
- value: function timer_F() {
- debugnict("Timer F expired for transaction ".concat(this.id));
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- this.eventHandlers.onRequestTimeout();
- }
- }, {
- key: "timer_K",
- value: function timer_K() {
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }, {
- key: "receiveResponse",
- value: function receiveResponse(response) {
- var _this3 = this;
- var status_code = response.status_code;
- if (status_code < 200) {
- switch (this.state) {
- case C.STATUS_TRYING:
- case C.STATUS_PROCEEDING:
- this.stateChanged(C.STATUS_PROCEEDING);
- this.eventHandlers.onReceiveResponse(response);
- break;
- }
- } else {
- switch (this.state) {
- case C.STATUS_TRYING:
- case C.STATUS_PROCEEDING:
- this.stateChanged(C.STATUS_COMPLETED);
- clearTimeout(this.F);
- if (status_code === 408) {
- this.eventHandlers.onRequestTimeout();
- } else {
- this.eventHandlers.onReceiveResponse(response);
- }
- this.K = setTimeout(function () {
- _this3.timer_K();
- }, Timers.TIMER_K);
- break;
- case C.STATUS_COMPLETED:
- break;
- }
- }
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- }
- }]);
- return NonInviteClientTransaction;
- }(EventEmitter);
- var InviteClientTransaction =
- /*#__PURE__*/
- function (_EventEmitter2) {
- _inherits(InviteClientTransaction, _EventEmitter2);
- function InviteClientTransaction(ua, transport, request, eventHandlers) {
- var _this4;
- _classCallCheck(this, InviteClientTransaction);
- _this4 = _possibleConstructorReturn(this, _getPrototypeOf(InviteClientTransaction).call(this));
- _this4.type = C.INVITE_CLIENT;
- _this4.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
- _this4.ua = ua;
- _this4.transport = transport;
- _this4.request = request;
- _this4.eventHandlers = eventHandlers;
- request.transaction = _assertThisInitialized(_assertThisInitialized(_this4));
- var via = "SIP/2.0/".concat(transport.via_transport);
- via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this4.id);
- _this4.request.setHeader('via', via);
- _this4.ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this4)));
- return _this4;
- }
- _createClass(InviteClientTransaction, [{
- key: "stateChanged",
- value: function stateChanged(state) {
- this.state = state;
- this.emit('stateChanged');
- }
- }, {
- key: "send",
- value: function send() {
- var _this5 = this;
- this.stateChanged(C.STATUS_CALLING);
- this.B = setTimeout(function () {
- _this5.timer_B();
- }, Timers.TIMER_B);
- if (!this.transport.send(this.request)) {
- this.onTransportError();
- }
- }
- }, {
- key: "onTransportError",
- value: function onTransportError() {
- clearTimeout(this.B);
- clearTimeout(this.D);
- clearTimeout(this.M);
- if (this.state !== C.STATUS_ACCEPTED) {
- debugict("transport error occurred, deleting transaction ".concat(this.id));
- this.eventHandlers.onTransportError();
- }
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- } // RFC 6026 7.2.
- }, {
- key: "timer_M",
- value: function timer_M() {
- debugict("Timer M expired for transaction ".concat(this.id));
- if (this.state === C.STATUS_ACCEPTED) {
- clearTimeout(this.B);
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- } // RFC 3261 17.1.1.
- }, {
- key: "timer_B",
- value: function timer_B() {
- debugict("Timer B expired for transaction ".concat(this.id));
- if (this.state === C.STATUS_CALLING) {
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- this.eventHandlers.onRequestTimeout();
- }
- }
- }, {
- key: "timer_D",
- value: function timer_D() {
- debugict("Timer D expired for transaction ".concat(this.id));
- clearTimeout(this.B);
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }, {
- key: "sendACK",
- value: function sendACK(response) {
- var _this6 = this;
- var ack = new SIPMessage.OutgoingRequest(JsSIP_C.ACK, this.request.ruri, this.ua, {
- 'route_set': this.request.getHeaders('route'),
- 'call_id': this.request.getHeader('call-id'),
- 'cseq': this.request.cseq
- });
- ack.setHeader('from', this.request.getHeader('from'));
- ack.setHeader('via', this.request.getHeader('via'));
- ack.setHeader('to', response.getHeader('to'));
- this.D = setTimeout(function () {
- _this6.timer_D();
- }, Timers.TIMER_D);
- this.transport.send(ack);
- }
- }, {
- key: "cancel",
- value: function cancel(reason) {
- // Send only if a provisional response (>100) has been received.
- if (this.state !== C.STATUS_PROCEEDING) {
- return;
- }
- var cancel = new SIPMessage.OutgoingRequest(JsSIP_C.CANCEL, this.request.ruri, this.ua, {
- 'route_set': this.request.getHeaders('route'),
- 'call_id': this.request.getHeader('call-id'),
- 'cseq': this.request.cseq
- });
- cancel.setHeader('from', this.request.getHeader('from'));
- cancel.setHeader('via', this.request.getHeader('via'));
- cancel.setHeader('to', this.request.getHeader('to'));
- if (reason) {
- cancel.setHeader('reason', reason);
- }
- this.transport.send(cancel);
- }
- }, {
- key: "receiveResponse",
- value: function receiveResponse(response) {
- var _this7 = this;
- var status_code = response.status_code;
- if (status_code >= 100 && status_code <= 199) {
- switch (this.state) {
- case C.STATUS_CALLING:
- this.stateChanged(C.STATUS_PROCEEDING);
- this.eventHandlers.onReceiveResponse(response);
- break;
- case C.STATUS_PROCEEDING:
- this.eventHandlers.onReceiveResponse(response);
- break;
- }
- } else if (status_code >= 200 && status_code <= 299) {
- switch (this.state) {
- case C.STATUS_CALLING:
- case C.STATUS_PROCEEDING:
- this.stateChanged(C.STATUS_ACCEPTED);
- this.M = setTimeout(function () {
- _this7.timer_M();
- }, Timers.TIMER_M);
- this.eventHandlers.onReceiveResponse(response);
- break;
- case C.STATUS_ACCEPTED:
- this.eventHandlers.onReceiveResponse(response);
- break;
- }
- } else if (status_code >= 300 && status_code <= 699) {
- switch (this.state) {
- case C.STATUS_CALLING:
- case C.STATUS_PROCEEDING:
- this.stateChanged(C.STATUS_COMPLETED);
- this.sendACK(response);
- this.eventHandlers.onReceiveResponse(response);
- break;
- case C.STATUS_COMPLETED:
- this.sendACK(response);
- break;
- }
- }
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- }
- }]);
- return InviteClientTransaction;
- }(EventEmitter);
- var AckClientTransaction =
- /*#__PURE__*/
- function (_EventEmitter3) {
- _inherits(AckClientTransaction, _EventEmitter3);
- function AckClientTransaction(ua, transport, request, eventHandlers) {
- var _this8;
- _classCallCheck(this, AckClientTransaction);
- _this8 = _possibleConstructorReturn(this, _getPrototypeOf(AckClientTransaction).call(this));
- _this8.id = "z9hG4bK".concat(Math.floor(Math.random() * 10000000));
- _this8.transport = transport;
- _this8.request = request;
- _this8.eventHandlers = eventHandlers;
- var via = "SIP/2.0/".concat(transport.via_transport);
- via += " ".concat(ua.configuration.via_host, ";branch=").concat(_this8.id);
- _this8.request.setHeader('via', via);
- return _this8;
- }
- _createClass(AckClientTransaction, [{
- key: "send",
- value: function send() {
- if (!this.transport.send(this.request)) {
- this.onTransportError();
- }
- }
- }, {
- key: "onTransportError",
- value: function onTransportError() {
- debugact("transport error occurred for transaction ".concat(this.id));
- this.eventHandlers.onTransportError();
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- }
- }]);
- return AckClientTransaction;
- }(EventEmitter);
- var NonInviteServerTransaction =
- /*#__PURE__*/
- function (_EventEmitter4) {
- _inherits(NonInviteServerTransaction, _EventEmitter4);
- function NonInviteServerTransaction(ua, transport, request) {
- var _this9;
- _classCallCheck(this, NonInviteServerTransaction);
- _this9 = _possibleConstructorReturn(this, _getPrototypeOf(NonInviteServerTransaction).call(this));
- _this9.type = C.NON_INVITE_SERVER;
- _this9.id = request.via_branch;
- _this9.ua = ua;
- _this9.transport = transport;
- _this9.request = request;
- _this9.last_response = '';
- request.server_transaction = _assertThisInitialized(_assertThisInitialized(_this9));
- _this9.state = C.STATUS_TRYING;
- ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this9)));
- return _this9;
- }
- _createClass(NonInviteServerTransaction, [{
- key: "stateChanged",
- value: function stateChanged(state) {
- this.state = state;
- this.emit('stateChanged');
- }
- }, {
- key: "timer_J",
- value: function timer_J() {
- debugnist("Timer J expired for transaction ".concat(this.id));
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }, {
- key: "onTransportError",
- value: function onTransportError() {
- if (!this.transportError) {
- this.transportError = true;
- debugnist("transport error occurred, deleting transaction ".concat(this.id));
- clearTimeout(this.J);
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }
- }, {
- key: "receiveResponse",
- value: function receiveResponse(status_code, response, onSuccess, onFailure) {
- var _this10 = this;
- if (status_code === 100) {
- /* RFC 4320 4.1
- * 'A SIP element MUST NOT
- * send any provisional response with a
- * Status-Code other than 100 to a non-INVITE request.'
- */
- switch (this.state) {
- case C.STATUS_TRYING:
- this.stateChanged(C.STATUS_PROCEEDING);
- if (!this.transport.send(response)) {
- this.onTransportError();
- }
- break;
- case C.STATUS_PROCEEDING:
- this.last_response = response;
- if (!this.transport.send(response)) {
- this.onTransportError();
- if (onFailure) {
- onFailure();
- }
- } else if (onSuccess) {
- onSuccess();
- }
- break;
- }
- } else if (status_code >= 200 && status_code <= 699) {
- switch (this.state) {
- case C.STATUS_TRYING:
- case C.STATUS_PROCEEDING:
- this.stateChanged(C.STATUS_COMPLETED);
- this.last_response = response;
- this.J = setTimeout(function () {
- _this10.timer_J();
- }, Timers.TIMER_J);
- if (!this.transport.send(response)) {
- this.onTransportError();
- if (onFailure) {
- onFailure();
- }
- } else if (onSuccess) {
- onSuccess();
- }
- break;
- case C.STATUS_COMPLETED:
- break;
- }
- }
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- }
- }]);
- return NonInviteServerTransaction;
- }(EventEmitter);
- var InviteServerTransaction =
- /*#__PURE__*/
- function (_EventEmitter5) {
- _inherits(InviteServerTransaction, _EventEmitter5);
- function InviteServerTransaction(ua, transport, request) {
- var _this11;
- _classCallCheck(this, InviteServerTransaction);
- _this11 = _possibleConstructorReturn(this, _getPrototypeOf(InviteServerTransaction).call(this));
- _this11.type = C.INVITE_SERVER;
- _this11.id = request.via_branch;
- _this11.ua = ua;
- _this11.transport = transport;
- _this11.request = request;
- _this11.last_response = '';
- request.server_transaction = _assertThisInitialized(_assertThisInitialized(_this11));
- _this11.state = C.STATUS_PROCEEDING;
- ua.newTransaction(_assertThisInitialized(_assertThisInitialized(_this11)));
- _this11.resendProvisionalTimer = null;
- request.reply(100);
- return _this11;
- }
- _createClass(InviteServerTransaction, [{
- key: "stateChanged",
- value: function stateChanged(state) {
- this.state = state;
- this.emit('stateChanged');
- }
- }, {
- key: "timer_H",
- value: function timer_H() {
- debugist("Timer H expired for transaction ".concat(this.id));
- if (this.state === C.STATUS_COMPLETED) {
- debugist('ACK not received, dialog will be terminated');
- }
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }, {
- key: "timer_I",
- value: function timer_I() {
- this.stateChanged(C.STATUS_TERMINATED);
- } // RFC 6026 7.1.
- }, {
- key: "timer_L",
- value: function timer_L() {
- debugist("Timer L expired for transaction ".concat(this.id));
- if (this.state === C.STATUS_ACCEPTED) {
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }
- }, {
- key: "onTransportError",
- value: function onTransportError() {
- if (!this.transportError) {
- this.transportError = true;
- debugist("transport error occurred, deleting transaction ".concat(this.id));
- if (this.resendProvisionalTimer !== null) {
- clearInterval(this.resendProvisionalTimer);
- this.resendProvisionalTimer = null;
- }
- clearTimeout(this.L);
- clearTimeout(this.H);
- clearTimeout(this.I);
- this.stateChanged(C.STATUS_TERMINATED);
- this.ua.destroyTransaction(this);
- }
- }
- }, {
- key: "resend_provisional",
- value: function resend_provisional() {
- if (!this.transport.send(this.last_response)) {
- this.onTransportError();
- }
- } // INVITE Server Transaction RFC 3261 17.2.1.
- }, {
- key: "receiveResponse",
- value: function receiveResponse(status_code, response, onSuccess, onFailure) {
- var _this12 = this;
- if (status_code >= 100 && status_code <= 199) {
- switch (this.state) {
- case C.STATUS_PROCEEDING:
- if (!this.transport.send(response)) {
- this.onTransportError();
- }
- this.last_response = response;
- break;
- }
- }
- if (status_code > 100 && status_code <= 199 && this.state === C.STATUS_PROCEEDING) {
- // Trigger the resendProvisionalTimer only for the first non 100 provisional response.
- if (this.resendProvisionalTimer === null) {
- this.resendProvisionalTimer = setInterval(function () {
- _this12.resend_provisional();
- }, Timers.PROVISIONAL_RESPONSE_INTERVAL);
- }
- } else if (status_code >= 200 && status_code <= 299) {
- switch (this.state) {
- case C.STATUS_PROCEEDING:
- this.stateChanged(C.STATUS_ACCEPTED);
- this.last_response = response;
- this.L = setTimeout(function () {
- _this12.timer_L();
- }, Timers.TIMER_L);
- if (this.resendProvisionalTimer !== null) {
- clearInterval(this.resendProvisionalTimer);
- this.resendProvisionalTimer = null;
- }
- /* falls through */
- case C.STATUS_ACCEPTED:
- // Note that this point will be reached for proceeding this.state also.
- if (!this.transport.send(response)) {
- this.onTransportError();
- if (onFailure) {
- onFailure();
- }
- } else if (onSuccess) {
- onSuccess();
- }
- break;
- }
- } else if (status_code >= 300 && status_code <= 699) {
- switch (this.state) {
- case C.STATUS_PROCEEDING:
- if (this.resendProvisionalTimer !== null) {
- clearInterval(this.resendProvisionalTimer);
- this.resendProvisionalTimer = null;
- }
- if (!this.transport.send(response)) {
- this.onTransportError();
- if (onFailure) {
- onFailure();
- }
- } else {
- this.stateChanged(C.STATUS_COMPLETED);
- this.H = setTimeout(function () {
- _this12.timer_H();
- }, Timers.TIMER_H);
- if (onSuccess) {
- onSuccess();
- }
- }
- break;
- }
- }
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- }
- }]);
- return InviteServerTransaction;
- }(EventEmitter);
- /**
- * INVITE:
- * _true_ if retransmission
- * _false_ new request
- *
- * ACK:
- * _true_ ACK to non2xx response
- * _false_ ACK must be passed to TU (accepted state)
- * ACK to 2xx response
- *
- * CANCEL:
- * _true_ no matching invite transaction
- * _false_ matching invite transaction and no final response sent
- *
- * OTHER:
- * _true_ retransmission
- * _false_ new request
- */
- function checkTransaction(_ref, request) {
- var _transactions = _ref._transactions;
- var tr;
- switch (request.method) {
- case JsSIP_C.INVITE:
- tr = _transactions.ist[request.via_branch];
- if (tr) {
- switch (tr.state) {
- case C.STATUS_PROCEEDING:
- tr.transport.send(tr.last_response);
- break;
- // RFC 6026 7.1 Invite retransmission.
- // Received while in C.STATUS_ACCEPTED state. Absorb it.
- case C.STATUS_ACCEPTED:
- break;
- }
- return true;
- }
- break;
- case JsSIP_C.ACK:
- tr = _transactions.ist[request.via_branch]; // RFC 6026 7.1.
- if (tr) {
- if (tr.state === C.STATUS_ACCEPTED) {
- return false;
- } else if (tr.state === C.STATUS_COMPLETED) {
- tr.state = C.STATUS_CONFIRMED;
- tr.I = setTimeout(function () {
- tr.timer_I();
- }, Timers.TIMER_I);
- return true;
- }
- } // ACK to 2XX Response.
- else {
- return false;
- }
- break;
- case JsSIP_C.CANCEL:
- tr = _transactions.ist[request.via_branch];
- if (tr) {
- request.reply_sl(200);
- if (tr.state === C.STATUS_PROCEEDING) {
- return false;
- } else {
- return true;
- }
- } else {
- request.reply_sl(481);
- return true;
- }
- default:
- // Non-INVITE Server Transaction RFC 3261 17.2.2.
- tr = _transactions.nist[request.via_branch];
- if (tr) {
- switch (tr.state) {
- case C.STATUS_TRYING:
- break;
- case C.STATUS_PROCEEDING:
- case C.STATUS_COMPLETED:
- tr.transport.send(tr.last_response);
- break;
- }
- return true;
- }
- break;
- }
- }
- module.exports = {
- C: C,
- NonInviteClientTransaction: NonInviteClientTransaction,
- InviteClientTransaction: InviteClientTransaction,
- AckClientTransaction: AckClientTransaction,
- NonInviteServerTransaction: NonInviteServerTransaction,
- InviteServerTransaction: InviteServerTransaction,
- checkTransaction: checkTransaction
- };
- },{"./Constants":2,"./SIPMessage":19,"./Timers":21,"debug":30,"events":29}],23:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var Socket = require('./Socket');
- var debug = require('debug')('JsSIP:Transport');
- var debugerror = require('debug')('JsSIP:ERROR:Transport');
- var JsSIP_C = require('./Constants');
- debugerror.log = console.warn.bind(console);
- /**
- * Constants
- */
- var C = {
- // Transport status.
- STATUS_CONNECTED: 0,
- STATUS_CONNECTING: 1,
- STATUS_DISCONNECTED: 2,
- // Socket status.
- SOCKET_STATUS_READY: 0,
- SOCKET_STATUS_ERROR: 1,
- // Recovery options.
- recovery_options: {
- // minimum interval in seconds between recover attempts.
- min_interval: JsSIP_C.CONNECTION_RECOVERY_MIN_INTERVAL,
- // maximum interval in seconds between recover attempts.
- max_interval: JsSIP_C.CONNECTION_RECOVERY_MAX_INTERVAL
- }
- };
- /*
- * Manages one or multiple JsSIP.Socket instances.
- * Is reponsible for transport recovery logic among all socket instances.
- *
- * @socket JsSIP::Socket instance
- */
- module.exports =
- /*#__PURE__*/
- function () {
- function Transport(sockets) {
- var recovery_options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : C.recovery_options;
- _classCallCheck(this, Transport);
- debug('new()');
- this.status = C.STATUS_DISCONNECTED; // Current socket.
- this.socket = null; // Socket collection.
- this.sockets = [];
- this.recovery_options = recovery_options;
- this.recover_attempts = 0;
- this.recovery_timer = null;
- this.close_requested = false;
- if (typeof sockets === 'undefined') {
- throw new TypeError('Invalid argument.' + ' undefined \'sockets\' argument');
- }
- if (!(sockets instanceof Array)) {
- sockets = [sockets];
- }
- sockets.forEach(function (socket) {
- if (!Socket.isSocket(socket.socket)) {
- throw new TypeError('Invalid argument.' + ' invalid \'JsSIP.Socket\' instance');
- }
- if (socket.weight && !Number(socket.weight)) {
- throw new TypeError('Invalid argument.' + ' \'weight\' attribute is not a number');
- }
- this.sockets.push({
- socket: socket.socket,
- weight: socket.weight || 0,
- status: C.SOCKET_STATUS_READY
- });
- }, this); // Get the socket with higher weight.
- this._getSocket();
- }
- /**
- * Instance Methods
- */
- _createClass(Transport, [{
- key: "connect",
- value: function connect() {
- debug('connect()');
- if (this.isConnected()) {
- debug('Transport is already connected');
- return;
- } else if (this.isConnecting()) {
- debug('Transport is connecting');
- return;
- }
- this.close_requested = false;
- this.status = C.STATUS_CONNECTING;
- this.onconnecting({
- socket: this.socket,
- attempts: this.recover_attempts
- });
- if (!this.close_requested) {
- // Bind socket event callbacks.
- this.socket.onconnect = this._onConnect.bind(this);
- this.socket.ondisconnect = this._onDisconnect.bind(this);
- this.socket.ondata = this._onData.bind(this);
- this.socket.connect();
- }
- return;
- }
- }, {
- key: "disconnect",
- value: function disconnect() {
- debug('close()');
- this.close_requested = true;
- this.recover_attempts = 0;
- this.status = C.STATUS_DISCONNECTED; // Clear recovery_timer.
- if (this.recovery_timer !== null) {
- clearTimeout(this.recovery_timer);
- this.recovery_timer = null;
- } // Unbind socket event callbacks.
- this.socket.onconnect = function () {};
- this.socket.ondisconnect = function () {};
- this.socket.ondata = function () {};
- this.socket.disconnect();
- this.ondisconnect({
- socket: this.socket,
- error: false
- });
- }
- }, {
- key: "send",
- value: function send(data) {
- debug('send()');
- if (!this.isConnected()) {
- debugerror('unable to send message, transport is not connected');
- return false;
- }
- var message = data.toString();
- debug("sending message:\n\n".concat(message, "\n"));
- return this.socket.send(message);
- }
- }, {
- key: "isConnected",
- value: function isConnected() {
- return this.status === C.STATUS_CONNECTED;
- }
- }, {
- key: "isConnecting",
- value: function isConnecting() {
- return this.status === C.STATUS_CONNECTING;
- }
- /**
- * Private API.
- */
- }, {
- key: "_reconnect",
- value: function _reconnect() {
- var _this = this;
- this.recover_attempts += 1;
- var k = Math.floor(Math.random() * Math.pow(2, this.recover_attempts) + 1);
- if (k < this.recovery_options.min_interval) {
- k = this.recovery_options.min_interval;
- } else if (k > this.recovery_options.max_interval) {
- k = this.recovery_options.max_interval;
- }
- debug("reconnection attempt: ".concat(this.recover_attempts, ". next connection attempt in ").concat(k, " seconds"));
- this.recovery_timer = setTimeout(function () {
- if (!_this.close_requested && !(_this.isConnected() || _this.isConnecting())) {
- // Get the next available socket with higher weight.
- _this._getSocket(); // Connect the socket.
- _this.connect();
- }
- }, k * 1000);
- }
- /**
- * get the next available socket with higher weight
- */
- }, {
- key: "_getSocket",
- value: function _getSocket() {
- var candidates = [];
- this.sockets.forEach(function (socket) {
- if (socket.status === C.SOCKET_STATUS_ERROR) {
- return; // continue the array iteration
- } else if (candidates.length === 0) {
- candidates.push(socket);
- } else if (socket.weight > candidates[0].weight) {
- candidates = [socket];
- } else if (socket.weight === candidates[0].weight) {
- candidates.push(socket);
- }
- });
- if (candidates.length === 0) {
- // All sockets have failed. reset sockets status.
- this.sockets.forEach(function (socket) {
- socket.status = C.SOCKET_STATUS_READY;
- }); // Get next available socket.
- this._getSocket();
- return;
- }
- var idx = Math.floor(Math.random() * candidates.length);
- this.socket = candidates[idx].socket;
- }
- /**
- * Socket Event Handlers
- */
- }, {
- key: "_onConnect",
- value: function _onConnect() {
- this.recover_attempts = 0;
- this.status = C.STATUS_CONNECTED; // Clear recovery_timer.
- if (this.recovery_timer !== null) {
- clearTimeout(this.recovery_timer);
- this.recovery_timer = null;
- }
- this.onconnect({
- socket: this
- });
- }
- }, {
- key: "_onDisconnect",
- value: function _onDisconnect(error, code, reason) {
- this.status = C.STATUS_DISCONNECTED;
- this.ondisconnect({
- socket: this.socket,
- error: error,
- code: code,
- reason: reason
- });
- if (this.close_requested) {
- return;
- } // Update socket status.
- else {
- this.sockets.forEach(function (socket) {
- if (this.socket === socket.socket) {
- socket.status = C.SOCKET_STATUS_ERROR;
- }
- }, this);
- }
- this._reconnect(error);
- }
- }, {
- key: "_onData",
- value: function _onData(data) {
- // CRLF Keep Alive response from server. Ignore it.
- if (data === '\r\n') {
- debug('received message with CRLF Keep Alive response');
- return;
- } // Binary message.
- else if (typeof data !== 'string') {
- try {
- data = String.fromCharCode.apply(null, new Uint8Array(data));
- } catch (evt) {
- debug('received binary message failed to be converted into string,' + ' message discarded');
- return;
- }
- debug("received binary message:\n\n".concat(data, "\n"));
- } // Text message.
- else {
- debug("received text message:\n\n".concat(data, "\n"));
- }
- this.ondata({
- transport: this,
- message: data
- });
- }
- }, {
- key: "via_transport",
- get: function get() {
- return this.socket.via_transport;
- }
- }, {
- key: "url",
- get: function get() {
- return this.socket.url;
- }
- }, {
- key: "sip_uri",
- get: function get() {
- return this.socket.sip_uri;
- }
- }]);
- return Transport;
- }();
- },{"./Constants":2,"./Socket":20,"debug":30}],24:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
- var EventEmitter = require('events').EventEmitter;
- var JsSIP_C = require('./Constants');
- var Registrator = require('./Registrator');
- var RTCSession = require('./RTCSession');
- var Message = require('./Message');
- var Transactions = require('./Transactions');
- var Transport = require('./Transport');
- var Utils = require('./Utils');
- var Exceptions = require('./Exceptions');
- var URI = require('./URI');
- var Parser = require('./Parser');
- var SIPMessage = require('./SIPMessage');
- var sanityCheck = require('./sanityCheck');
- var config = require('./Config');
- var debug = require('debug')('JsSIP:UA');
- var debugerror = require('debug')('JsSIP:ERROR:UA');
- debugerror.log = console.warn.bind(console);
- var C = {
- // UA status codes.
- STATUS_INIT: 0,
- STATUS_READY: 1,
- STATUS_USER_CLOSED: 2,
- STATUS_NOT_READY: 3,
- // UA error codes.
- CONFIGURATION_ERROR: 1,
- NETWORK_ERROR: 2
- };
- /**
- * The User-Agent class.
- * @class JsSIP.UA
- * @param {Object} configuration Configuration parameters.
- * @throws {JsSIP.Exceptions.ConfigurationError} If a configuration parameter is invalid.
- * @throws {TypeError} If no configuration is given.
- */
- module.exports =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inherits(UA, _EventEmitter);
- _createClass(UA, null, [{
- key: "C",
- // Expose C object.
- get: function get() {
- return C;
- }
- }]);
- function UA(configuration) {
- var _this;
- _classCallCheck(this, UA);
- debug('new() [configuration:%o]', configuration);
- _this = _possibleConstructorReturn(this, _getPrototypeOf(UA).call(this));
- _this._cache = {
- credentials: {}
- };
- _this._configuration = Object.assign({}, config.settings);
- _this._dynConfiguration = {};
- _this._dialogs = {}; // User actions outside any session/dialog (MESSAGE).
- _this._applicants = {};
- _this._sessions = {};
- _this._transport = null;
- _this._contact = null;
- _this._status = C.STATUS_INIT;
- _this._error = null;
- _this._transactions = {
- nist: {},
- nict: {},
- ist: {},
- ict: {}
- }; // Custom UA empty object for high level use.
- _this._data = {};
- _this._closeTimer = null; // Check configuration argument.
- if (configuration === undefined) {
- throw new TypeError('Not enough arguments');
- } // Load configuration.
- try {
- _this._loadConfig(configuration);
- } catch (e) {
- _this._status = C.STATUS_NOT_READY;
- _this._error = C.CONFIGURATION_ERROR;
- throw e;
- } // Initialize registrator.
- _this._registrator = new Registrator(_assertThisInitialized(_assertThisInitialized(_this)));
- return _this;
- }
- _createClass(UA, [{
- key: "start",
- // =================
- // High Level API
- // =================
- /**
- * Connect to the server if status = STATUS_INIT.
- * Resume UA after being closed.
- */
- value: function start() {
- debug('start()');
- if (this._status === C.STATUS_INIT) {
- this._transport.connect();
- } else if (this._status === C.STATUS_USER_CLOSED) {
- debug('restarting UA'); // Disconnect.
- if (this._closeTimer !== null) {
- clearTimeout(this._closeTimer);
- this._closeTimer = null;
- this._transport.disconnect();
- } // Reconnect.
- this._status = C.STATUS_INIT;
- this._transport.connect();
- } else if (this._status === C.STATUS_READY) {
- debug('UA is in READY status, not restarted');
- } else {
- debug('ERROR: connection is down, Auto-Recovery system is trying to reconnect');
- } // Set dynamic configuration.
- this._dynConfiguration.register = this._configuration.register;
- }
- /**
- * Register.
- */
- }, {
- key: "register",
- value: function register() {
- debug('register()');
- this._dynConfiguration.register = true;
- this._registrator.register();
- }
- /**
- * Unregister.
- */
- }, {
- key: "unregister",
- value: function unregister(options) {
- debug('unregister()');
- this._dynConfiguration.register = false;
- this._registrator.unregister(options);
- }
- /**
- * Get the Registrator instance.
- */
- }, {
- key: "registrator",
- value: function registrator() {
- return this._registrator;
- }
- /**
- * Registration state.
- */
- }, {
- key: "isRegistered",
- value: function isRegistered() {
- return this._registrator.registered;
- }
- /**
- * Connection state.
- */
- }, {
- key: "isConnected",
- value: function isConnected() {
- return this._transport.isConnected();
- }
- /**
- * Make an outgoing call.
- *
- * -param {String} target
- * -param {Object} [options]
- *
- * -throws {TypeError}
- *
- */
- }, {
- key: "call",
- value: function call(target, options) {
- debug('call()');
- var session = new RTCSession(this);
- session.connect(target, options);
- return session;
- }
- /**
- * Send a message.
- *
- * -param {String} target
- * -param {String} body
- * -param {Object} [options]
- *
- * -throws {TypeError}
- *
- */
- }, {
- key: "sendMessage",
- value: function sendMessage(target, body, options) {
- debug('sendMessage()');
- var message = new Message(this);
- message.send(target, body, options);
- return message;
- }
- /**
- * Terminate ongoing sessions.
- */
- }, {
- key: "terminateSessions",
- value: function terminateSessions(options) {
- debug('terminateSessions()');
- for (var idx in this._sessions) {
- if (!this._sessions[idx].isEnded()) {
- this._sessions[idx].terminate(options);
- }
- }
- }
- /**
- * Gracefully close.
- *
- */
- }, {
- key: "stop",
- value: function stop() {
- var _this2 = this;
- debug('stop()'); // Remove dynamic settings.
- this._dynConfiguration = {};
- if (this._status === C.STATUS_USER_CLOSED) {
- debug('UA already closed');
- return;
- } // Close registrator.
- this._registrator.close(); // If there are session wait a bit so CANCEL/BYE can be sent and their responses received.
- var num_sessions = Object.keys(this._sessions).length; // Run _terminate_ on every Session.
- for (var session in this._sessions) {
- if (Object.prototype.hasOwnProperty.call(this._sessions, session)) {
- debug("closing session ".concat(session));
- try {
- this._sessions[session].terminate();
- } catch (error) {}
- }
- } // Run _close_ on every applicant.
- for (var applicant in this._applicants) {
- if (Object.prototype.hasOwnProperty.call(this._applicants, applicant)) try {
- this._applicants[applicant].close();
- } catch (error) {}
- }
- this._status = C.STATUS_USER_CLOSED;
- var num_transactions = Object.keys(this._transactions.nict).length + Object.keys(this._transactions.nist).length + Object.keys(this._transactions.ict).length + Object.keys(this._transactions.ist).length;
- if (num_transactions === 0 && num_sessions === 0) {
- this._transport.disconnect();
- } else {
- this._closeTimer = setTimeout(function () {
- _this2._closeTimer = null;
- _this2._transport.disconnect();
- }, 2000);
- }
- }
- /**
- * Normalice a string into a valid SIP request URI
- * -param {String} target
- * -returns {JsSIP.URI|undefined}
- */
- }, {
- key: "normalizeTarget",
- value: function normalizeTarget(target) {
- return Utils.normalizeTarget(target, this._configuration.hostport_params);
- }
- /**
- * Allow retrieving configuration and autogenerated fields in runtime.
- */
- }, {
- key: "get",
- value: function get(parameter) {
- switch (parameter) {
- case 'realm':
- return this._configuration.realm;
- case 'ha1':
- return this._configuration.ha1;
- default:
- debugerror('get() | cannot get "%s" parameter in runtime', parameter);
- return undefined;
- }
- }
- /**
- * Allow configuration changes in runtime.
- * Returns true if the parameter could be set.
- */
- }, {
- key: "set",
- value: function set(parameter, value) {
- switch (parameter) {
- case 'password':
- {
- this._configuration.password = String(value);
- break;
- }
- case 'realm':
- {
- this._configuration.realm = String(value);
- break;
- }
- case 'ha1':
- {
- this._configuration.ha1 = String(value); // Delete the plain SIP password.
- this._configuration.password = null;
- break;
- }
- case 'display_name':
- {
- this._configuration.display_name = value;
- break;
- }
- default:
- debugerror('set() | cannot set "%s" parameter in runtime', parameter);
- return false;
- }
- return true;
- } // ==========================
- // Event Handlers.
- // ==========================
- /**
- * new Transaction
- */
- }, {
- key: "newTransaction",
- value: function newTransaction(transaction) {
- this._transactions[transaction.type][transaction.id] = transaction;
- this.emit('newTransaction', {
- transaction: transaction
- });
- }
- /**
- * Transaction destroyed.
- */
- }, {
- key: "destroyTransaction",
- value: function destroyTransaction(transaction) {
- delete this._transactions[transaction.type][transaction.id];
- this.emit('transactionDestroyed', {
- transaction: transaction
- });
- }
- /**
- * new Dialog
- */
- }, {
- key: "newDialog",
- value: function newDialog(dialog) {
- this._dialogs[dialog.id] = dialog;
- }
- /**
- * Dialog destroyed.
- */
- }, {
- key: "destroyDialog",
- value: function destroyDialog(dialog) {
- delete this._dialogs[dialog.id];
- }
- /**
- * new Message
- */
- }, {
- key: "newMessage",
- value: function newMessage(message, data) {
- this._applicants[message] = message;
- this.emit('newMessage', data);
- }
- /**
- * Message destroyed.
- */
- }, {
- key: "destroyMessage",
- value: function destroyMessage(message) {
- delete this._applicants[message];
- }
- /**
- * new RTCSession
- */
- }, {
- key: "newRTCSession",
- value: function newRTCSession(session, data) {
- this._sessions[session.id] = session;
- this.emit('newRTCSession', data);
- }
- /**
- * RTCSession destroyed.
- */
- }, {
- key: "destroyRTCSession",
- value: function destroyRTCSession(session) {
- delete this._sessions[session.id];
- }
- /**
- * Registered
- */
- }, {
- key: "registered",
- value: function registered(data) {
- this.emit('registered', data);
- }
- /**
- * Unregistered
- */
- }, {
- key: "unregistered",
- value: function unregistered(data) {
- this.emit('unregistered', data);
- }
- /**
- * Registration Failed
- */
- }, {
- key: "registrationFailed",
- value: function registrationFailed(data) {
- this.emit('registrationFailed', data);
- } // =========================
- // ReceiveRequest.
- // =========================
- /**
- * Request reception
- */
- }, {
- key: "receiveRequest",
- value: function receiveRequest(request) {
- var method = request.method; // Check that request URI points to us.
- if (request.ruri.user !== this._configuration.uri.user && request.ruri.user !== this._contact.uri.user) {
- debug('Request-URI does not point to us');
- if (request.method !== JsSIP_C.ACK) {
- request.reply_sl(404);
- }
- return;
- } // Check request URI scheme.
- if (request.ruri.scheme === JsSIP_C.SIPS) {
- request.reply_sl(416);
- return;
- } // Check transaction.
- if (Transactions.checkTransaction(this, request)) {
- return;
- } // Create the server transaction.
- if (method === JsSIP_C.INVITE) {
- /* eslint-disable no-new */
- new Transactions.InviteServerTransaction(this, this._transport, request);
- /* eslint-enable no-new */
- } else if (method !== JsSIP_C.ACK && method !== JsSIP_C.CANCEL) {
- /* eslint-disable no-new */
- new Transactions.NonInviteServerTransaction(this, this._transport, request);
- /* eslint-enable no-new */
- }
- /* RFC3261 12.2.2
- * Requests that do not change in any way the state of a dialog may be
- * received within a dialog (for example, an OPTIONS request).
- * They are processed as if they had been received outside the dialog.
- */
- if (method === JsSIP_C.OPTIONS) {
- request.reply(200);
- } else if (method === JsSIP_C.MESSAGE) {
- if (this.listeners('newMessage').length === 0) {
- request.reply(405);
- return;
- }
- var message = new Message(this);
- message.init_incoming(request);
- } else if (method === JsSIP_C.INVITE) {
- // Initial INVITE.
- if (!request.to_tag && this.listeners('newRTCSession').length === 0) {
- request.reply(405);
- return;
- }
- }
- var dialog;
- var session; // Initial Request.
- if (!request.to_tag) {
- switch (method) {
- case JsSIP_C.INVITE:
- if (window.RTCPeerConnection) {
- // TODO
- if (request.hasHeader('replaces')) {
- var replaces = request.replaces;
- dialog = this._findDialog(replaces.call_id, replaces.from_tag, replaces.to_tag);
- if (dialog) {
- session = dialog.owner;
- if (!session.isEnded()) {
- session.receiveRequest(request);
- } else {
- request.reply(603);
- }
- } else {
- request.reply(481);
- }
- } else {
- session = new RTCSession(this);
- session.init_incoming(request);
- }
- } else {
- debugerror('INVITE received but WebRTC is not supported');
- request.reply(488);
- }
- break;
- case JsSIP_C.BYE:
- // Out of dialog BYE received.
- request.reply(481);
- break;
- case JsSIP_C.CANCEL:
- session = this._findSession(request);
- if (session) {
- session.receiveRequest(request);
- } else {
- debug('received CANCEL request for a non existent session');
- }
- break;
- case JsSIP_C.ACK:
- /* Absorb it.
- * ACK request without a corresponding Invite Transaction
- * and without To tag.
- */
- break;
- case JsSIP_C.NOTIFY:
- // Receive new sip event.
- this.emit('sipEvent', {
- event: request.event,
- request: request
- });
- request.reply(200);
- break;
- default:
- request.reply(405);
- break;
- }
- } // In-dialog request.
- else {
- dialog = this._findDialog(request.call_id, request.from_tag, request.to_tag);
- if (dialog) {
- dialog.receiveRequest(request);
- } else if (method === JsSIP_C.NOTIFY) {
- session = this._findSession(request);
- if (session) {
- session.receiveRequest(request);
- } else {
- debug('received NOTIFY request for a non existent subscription');
- request.reply(481, 'Subscription does not exist');
- }
- }
- /* RFC3261 12.2.2
- * Request with to tag, but no matching dialog found.
- * Exception: ACK for an Invite request for which a dialog has not
- * been created.
- */
- else if (method !== JsSIP_C.ACK) {
- request.reply(481);
- }
- }
- } // =================
- // Utils.
- // =================
- /**
- * Get the session to which the request belongs to, if any.
- */
- }, {
- key: "_findSession",
- value: function _findSession(_ref) {
- var call_id = _ref.call_id,
- from_tag = _ref.from_tag,
- to_tag = _ref.to_tag;
- var sessionIDa = call_id + from_tag;
- var sessionA = this._sessions[sessionIDa];
- var sessionIDb = call_id + to_tag;
- var sessionB = this._sessions[sessionIDb];
- if (sessionA) {
- return sessionA;
- } else if (sessionB) {
- return sessionB;
- } else {
- return null;
- }
- }
- /**
- * Get the dialog to which the request belongs to, if any.
- */
- }, {
- key: "_findDialog",
- value: function _findDialog(call_id, from_tag, to_tag) {
- var id = call_id + from_tag + to_tag;
- var dialog = this._dialogs[id];
- if (dialog) {
- return dialog;
- } else {
- id = call_id + to_tag + from_tag;
- dialog = this._dialogs[id];
- if (dialog) {
- return dialog;
- } else {
- return null;
- }
- }
- }
- }, {
- key: "_loadConfig",
- value: function _loadConfig(configuration) {
- // Check and load the given configuration.
- try {
- config.load(this._configuration, configuration);
- } catch (e) {
- throw e;
- } // Post Configuration Process.
- // Allow passing 0 number as display_name.
- if (this._configuration.display_name === 0) {
- this._configuration.display_name = '0';
- } // Instance-id for GRUU.
- if (!this._configuration.instance_id) {
- this._configuration.instance_id = Utils.newUUID();
- } // Jssip_id instance parameter. Static random tag of length 5.
- this._configuration.jssip_id = Utils.createRandomToken(5); // String containing this._configuration.uri without scheme and user.
- var hostport_params = this._configuration.uri.clone();
- hostport_params.user = null;
- this._configuration.hostport_params = hostport_params.toString().replace(/^sip:/i, ''); // Transport.
- try {
- this._transport = new Transport(this._configuration.sockets, {
- // Recovery options.
- max_interval: this._configuration.connection_recovery_max_interval,
- min_interval: this._configuration.connection_recovery_min_interval
- }); // Transport event callbacks.
- this._transport.onconnecting = onTransportConnecting.bind(this);
- this._transport.onconnect = onTransportConnect.bind(this);
- this._transport.ondisconnect = onTransportDisconnect.bind(this);
- this._transport.ondata = onTransportData.bind(this);
- } catch (e) {
- debugerror(e);
- throw new Exceptions.ConfigurationError('sockets', this._configuration.sockets);
- } // Remove sockets instance from configuration object.
- delete this._configuration.sockets; // Check whether authorization_user is explicitly defined.
- // Take 'this._configuration.uri.user' value if not.
- if (!this._configuration.authorization_user) {
- this._configuration.authorization_user = this._configuration.uri.user;
- } // If no 'registrar_server' is set use the 'uri' value without user portion and
- // without URI params/headers.
- if (!this._configuration.registrar_server) {
- var registrar_server = this._configuration.uri.clone();
- registrar_server.user = null;
- registrar_server.clearParams();
- registrar_server.clearHeaders();
- this._configuration.registrar_server = registrar_server;
- } // User no_answer_timeout.
- this._configuration.no_answer_timeout *= 1000; // Via Host.
- if (this._configuration.contact_uri) {
- this._configuration.via_host = this._configuration.contact_uri.host;
- } // Contact URI.
- else {
- this._configuration.contact_uri = new URI('sip', Utils.createRandomToken(8), this._configuration.via_host, null, {
- transport: 'ws'
- });
- }
- this._contact = {
- pub_gruu: null,
- temp_gruu: null,
- uri: this._configuration.contact_uri,
- toString: function toString() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var anonymous = options.anonymous || null;
- var outbound = options.outbound || null;
- var contact = '<';
- if (anonymous) {
- contact += this.temp_gruu || 'sip:anonymous@anonymous.invalid;transport=ws';
- } else {
- contact += this.pub_gruu || this.uri.toString();
- }
- if (outbound && (anonymous ? !this.temp_gruu : !this.pub_gruu)) {
- contact += ';ob';
- }
- contact += '>';
- return contact;
- }
- }; // Seal the configuration.
- var writable_parameters = ['password', 'realm', 'ha1', 'display_name', 'register'];
- for (var parameter in this._configuration) {
- if (Object.prototype.hasOwnProperty.call(this._configuration, parameter)) {
- if (writable_parameters.indexOf(parameter) !== -1) {
- Object.defineProperty(this._configuration, parameter, {
- writable: true,
- configurable: false
- });
- } else {
- Object.defineProperty(this._configuration, parameter, {
- writable: false,
- configurable: false
- });
- }
- }
- }
- debug('configuration parameters after validation:');
- for (var _parameter in this._configuration) {
- // Only show the user user configurable parameters.
- if (Object.prototype.hasOwnProperty.call(config.settings, _parameter)) {
- switch (_parameter) {
- case 'uri':
- case 'registrar_server':
- debug("- ".concat(_parameter, ": ").concat(this._configuration[_parameter]));
- break;
- case 'password':
- case 'ha1':
- debug("- ".concat(_parameter, ": NOT SHOWN"));
- break;
- default:
- debug("- ".concat(_parameter, ": ").concat(JSON.stringify(this._configuration[_parameter])));
- }
- }
- }
- return;
- }
- }, {
- key: "C",
- get: function get() {
- return C;
- }
- }, {
- key: "status",
- get: function get() {
- return this._status;
- }
- }, {
- key: "contact",
- get: function get() {
- return this._contact;
- }
- }, {
- key: "configuration",
- get: function get() {
- return this._configuration;
- }
- }, {
- key: "transport",
- get: function get() {
- return this._transport;
- }
- }]);
- return UA;
- }(EventEmitter);
- /**
- * Transport event handlers
- */
- // Transport connecting event.
- function onTransportConnecting(data) {
- this.emit('connecting', data);
- } // Transport connected event.
- function onTransportConnect(data) {
- if (this._status === C.STATUS_USER_CLOSED) {
- return;
- }
- this._status = C.STATUS_READY;
- this._error = null;
- this.emit('connected', data);
- if (this._dynConfiguration.register) {
- this._registrator.register();
- }
- } // Transport disconnected event.
- function onTransportDisconnect(data) {
- // Run _onTransportError_ callback on every client transaction using _transport_.
- var client_transactions = ['nict', 'ict', 'nist', 'ist'];
- for (var _i = 0; _i < client_transactions.length; _i++) {
- var type = client_transactions[_i];
- for (var id in this._transactions[type]) {
- if (Object.prototype.hasOwnProperty.call(this._transactions[type], id)) {
- this._transactions[type][id].onTransportError();
- }
- }
- }
- this.emit('disconnected', data); // Call registrator _onTransportClosed_.
- this._registrator.onTransportClosed();
- if (this._status !== C.STATUS_USER_CLOSED) {
- this._status = C.STATUS_NOT_READY;
- this._error = C.NETWORK_ERROR;
- }
- } // Transport data event.
- function onTransportData(data) {
- var transport = data.transport;
- var message = data.message;
- message = Parser.parseMessage(message, this);
- if (!message) {
- return;
- }
- if (this._status === C.STATUS_USER_CLOSED && message instanceof SIPMessage.IncomingRequest) {
- return;
- } // Do some sanity check.
- if (!sanityCheck(message, this, transport)) {
- return;
- }
- if (message instanceof SIPMessage.IncomingRequest) {
- message.transport = transport;
- this.receiveRequest(message);
- } else if (message instanceof SIPMessage.IncomingResponse) {
- /* Unike stated in 18.1.2, if a response does not match
- * any transaction, it is discarded here and no passed to the core
- * in order to be discarded there.
- */
- var transaction;
- switch (message.method) {
- case JsSIP_C.INVITE:
- transaction = this._transactions.ict[message.via_branch];
- if (transaction) {
- transaction.receiveResponse(message);
- }
- break;
- case JsSIP_C.ACK:
- // Just in case ;-).
- break;
- default:
- transaction = this._transactions.nict[message.via_branch];
- if (transaction) {
- transaction.receiveResponse(message);
- }
- break;
- }
- }
- }
- },{"./Config":1,"./Constants":2,"./Exceptions":6,"./Message":9,"./Parser":11,"./RTCSession":12,"./Registrator":17,"./SIPMessage":19,"./Transactions":22,"./Transport":23,"./URI":25,"./Utils":26,"./sanityCheck":28,"debug":30,"events":29}],25:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var JsSIP_C = require('./Constants');
- var Utils = require('./Utils');
- var Grammar = require('./Grammar');
- /**
- * -param {String} [scheme]
- * -param {String} [user]
- * -param {String} host
- * -param {String} [port]
- * -param {Object} [parameters]
- * -param {Object} [headers]
- *
- */
- module.exports =
- /*#__PURE__*/
- function () {
- _createClass(URI, null, [{
- key: "parse",
- /**
- * Parse the given string and returns a JsSIP.URI instance or undefined if
- * it is an invalid URI.
- */
- value: function parse(uri) {
- uri = Grammar.parse(uri, 'SIP_URI');
- if (uri !== -1) {
- return uri;
- } else {
- return undefined;
- }
- }
- }]);
- function URI(scheme, user, host, port) {
- var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
- var headers = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
- _classCallCheck(this, URI);
- // Checks.
- if (!host) {
- throw new TypeError('missing or invalid "host" parameter');
- } // Initialize parameters.
- this._parameters = {};
- this._headers = {};
- this._scheme = scheme || JsSIP_C.SIP;
- this._user = user;
- this._host = host;
- this._port = port;
- for (var param in parameters) {
- if (Object.prototype.hasOwnProperty.call(parameters, param)) {
- this.setParam(param, parameters[param]);
- }
- }
- for (var header in headers) {
- if (Object.prototype.hasOwnProperty.call(headers, header)) {
- this.setHeader(header, headers[header]);
- }
- }
- }
- _createClass(URI, [{
- key: "setParam",
- value: function setParam(key, value) {
- if (key) {
- this._parameters[key.toLowerCase()] = typeof value === 'undefined' || value === null ? null : value.toString();
- }
- }
- }, {
- key: "getParam",
- value: function getParam(key) {
- if (key) {
- return this._parameters[key.toLowerCase()];
- }
- }
- }, {
- key: "hasParam",
- value: function hasParam(key) {
- if (key) {
- return this._parameters.hasOwnProperty(key.toLowerCase()) && true || false;
- }
- }
- }, {
- key: "deleteParam",
- value: function deleteParam(parameter) {
- parameter = parameter.toLowerCase();
- if (this._parameters.hasOwnProperty(parameter)) {
- var value = this._parameters[parameter];
- delete this._parameters[parameter];
- return value;
- }
- }
- }, {
- key: "clearParams",
- value: function clearParams() {
- this._parameters = {};
- }
- }, {
- key: "setHeader",
- value: function setHeader(name, value) {
- this._headers[Utils.headerize(name)] = Array.isArray(value) ? value : [value];
- }
- }, {
- key: "getHeader",
- value: function getHeader(name) {
- if (name) {
- return this._headers[Utils.headerize(name)];
- }
- }
- }, {
- key: "hasHeader",
- value: function hasHeader(name) {
- if (name) {
- return this._headers.hasOwnProperty(Utils.headerize(name)) && true || false;
- }
- }
- }, {
- key: "deleteHeader",
- value: function deleteHeader(header) {
- header = Utils.headerize(header);
- if (this._headers.hasOwnProperty(header)) {
- var value = this._headers[header];
- delete this._headers[header];
- return value;
- }
- }
- }, {
- key: "clearHeaders",
- value: function clearHeaders() {
- this._headers = {};
- }
- }, {
- key: "clone",
- value: function clone() {
- return new URI(this._scheme, this._user, this._host, this._port, JSON.parse(JSON.stringify(this._parameters)), JSON.parse(JSON.stringify(this._headers)));
- }
- }, {
- key: "toString",
- value: function toString() {
- var headers = [];
- var uri = "".concat(this._scheme, ":");
- if (this._user) {
- uri += "".concat(Utils.escapeUser(this._user), "@");
- }
- uri += this._host;
- if (this._port || this._port === 0) {
- uri += ":".concat(this._port);
- }
- for (var parameter in this._parameters) {
- if (Object.prototype.hasOwnProperty.call(this._parameters, parameter)) {
- uri += ";".concat(parameter);
- if (this._parameters[parameter] !== null) {
- uri += "=".concat(this._parameters[parameter]);
- }
- }
- }
- for (var header in this._headers) {
- if (Object.prototype.hasOwnProperty.call(this._headers, header)) {
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = this._headers[header][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var item = _step.value;
- headers.push("".concat(header, "=").concat(item));
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- }
- }
- if (headers.length > 0) {
- uri += "?".concat(headers.join('&'));
- }
- return uri;
- }
- }, {
- key: "toAor",
- value: function toAor(show_port) {
- var aor = "".concat(this._scheme, ":");
- if (this._user) {
- aor += "".concat(Utils.escapeUser(this._user), "@");
- }
- aor += this._host;
- if (show_port && (this._port || this._port === 0)) {
- aor += ":".concat(this._port);
- }
- return aor;
- }
- }, {
- key: "scheme",
- get: function get() {
- return this._scheme;
- },
- set: function set(value) {
- this._scheme = value.toLowerCase();
- }
- }, {
- key: "user",
- get: function get() {
- return this._user;
- },
- set: function set(value) {
- this._user = value;
- }
- }, {
- key: "host",
- get: function get() {
- return this._host;
- },
- set: function set(value) {
- this._host = value.toLowerCase();
- }
- }, {
- key: "port",
- get: function get() {
- return this._port;
- },
- set: function set(value) {
- this._port = value === 0 ? value : parseInt(value, 10) || null;
- }
- }]);
- return URI;
- }();
- },{"./Constants":2,"./Grammar":7,"./Utils":26}],26:[function(require,module,exports){
- "use strict";
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- var JsSIP_C = require('./Constants');
- var URI = require('./URI');
- var Grammar = require('./Grammar');
- exports.str_utf8_length = function (string) {
- return unescape(encodeURIComponent(string)).length;
- }; // Used by 'hasMethods'.
- var isFunction = exports.isFunction = function (fn) {
- if (fn !== undefined) {
- return Object.prototype.toString.call(fn) === '[object Function]' ? true : false;
- } else {
- return false;
- }
- };
- exports.isString = function (str) {
- if (str !== undefined) {
- return Object.prototype.toString.call(str) === '[object String]' ? true : false;
- } else {
- return false;
- }
- };
- exports.isDecimal = function (num) {
- return !isNaN(num) && parseFloat(num) === parseInt(num, 10);
- };
- exports.isEmpty = function (value) {
- return value === null || value === '' || value === undefined || Array.isArray(value) && value.length === 0 || typeof value === 'number' && isNaN(value);
- };
- exports.hasMethods = function (obj) {
- for (var _len = arguments.length, methodNames = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- methodNames[_key - 1] = arguments[_key];
- }
- for (var _i = 0; _i < methodNames.length; _i++) {
- var methodName = methodNames[_i];
- if (isFunction(obj[methodName])) {
- return false;
- }
- }
- return true;
- }; // Used by 'newTag'.
- var createRandomToken = exports.createRandomToken = function (size) {
- var base = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 32;
- var i,
- r,
- token = '';
- for (i = 0; i < size; i++) {
- r = Math.random() * base | 0;
- token += r.toString(base);
- }
- return token;
- };
- exports.newTag = function () {
- return createRandomToken(10);
- }; // https://stackoverflow.com/users/109538/broofa.
- exports.newUUID = function () {
- var UUID = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
- var r = Math.random() * 16 | 0,
- v = c === 'x' ? r : r & 0x3 | 0x8;
- return v.toString(16);
- });
- return UUID;
- };
- exports.hostType = function (host) {
- if (!host) {
- return;
- } else {
- host = Grammar.parse(host, 'host');
- if (host !== -1) {
- return host.host_type;
- }
- }
- };
- /**
- * Hex-escape a SIP URI user.
- * Don't hex-escape ':' (%3A), '+' (%2B), '?' (%3F"), '/' (%2F).
- *
- * Used by 'normalizeTarget'.
- */
- var escapeUser = exports.escapeUser = function (user) {
- return encodeURIComponent(decodeURIComponent(user)).replace(/%3A/ig, ':').replace(/%2B/ig, '+').replace(/%3F/ig, '?').replace(/%2F/ig, '/');
- };
- /**
- * Normalize SIP URI.
- * NOTE: It does not allow a SIP URI without username.
- * Accepts 'sip', 'sips' and 'tel' URIs and convert them into 'sip'.
- * Detects the domain part (if given) and properly hex-escapes the user portion.
- * If the user portion has only 'tel' number symbols the user portion is clean of 'tel' visual separators.
- */
- exports.normalizeTarget = function (target, domain) {
- // If no target is given then raise an error.
- if (!target) {
- return; // If a URI instance is given then return it.
- } else if (target instanceof URI) {
- return target; // If a string is given split it by '@':
- // - Last fragment is the desired domain.
- // - Otherwise append the given domain argument.
- } else if (typeof target === 'string') {
- var target_array = target.split('@');
- var target_user;
- var target_domain;
- switch (target_array.length) {
- case 1:
- if (!domain) {
- return;
- }
- target_user = target;
- target_domain = domain;
- break;
- case 2:
- target_user = target_array[0];
- target_domain = target_array[1];
- break;
- default:
- target_user = target_array.slice(0, target_array.length - 1).join('@');
- target_domain = target_array[target_array.length - 1];
- } // Remove the URI scheme (if present).
- target_user = target_user.replace(/^(sips?|tel):/i, ''); // Remove 'tel' visual separators if the user portion just contains 'tel' number symbols.
- if (/^[-.()]*\+?[0-9\-.()]+$/.test(target_user)) {
- target_user = target_user.replace(/[-.()]/g, '');
- } // Build the complete SIP URI.
- target = "".concat(JsSIP_C.SIP, ":").concat(escapeUser(target_user), "@").concat(target_domain); // Finally parse the resulting URI.
- var uri;
- if (uri = URI.parse(target)) {
- return uri;
- } else {
- return;
- }
- } else {
- return;
- }
- };
- exports.headerize = function (string) {
- var exceptions = {
- 'Call-Id': 'Call-ID',
- 'Cseq': 'CSeq',
- 'Www-Authenticate': 'WWW-Authenticate'
- };
- var name = string.toLowerCase().replace(/_/g, '-').split('-');
- var hname = '';
- var parts = name.length;
- var part;
- for (part = 0; part < parts; part++) {
- if (part !== 0) {
- hname += '-';
- }
- hname += name[part].charAt(0).toUpperCase() + name[part].substring(1);
- }
- if (exceptions[hname]) {
- hname = exceptions[hname];
- }
- return hname;
- };
- exports.sipErrorCause = function (status_code) {
- for (var cause in JsSIP_C.SIP_ERROR_CAUSES) {
- if (JsSIP_C.SIP_ERROR_CAUSES[cause].indexOf(status_code) !== -1) {
- return JsSIP_C.causes[cause];
- }
- }
- return JsSIP_C.causes.SIP_FAILURE_CODE;
- };
- /**
- * Generate a random Test-Net IP (https://tools.ietf.org/html/rfc5735)
- */
- exports.getRandomTestNetIP = function () {
- function getOctet(from, to) {
- return Math.floor(Math.random() * (to - from + 1) + from);
- }
- return "192.0.2.".concat(getOctet(1, 254));
- }; // MD5 (Message-Digest Algorithm) https://www.webtoolkit.info.
- exports.calculateMD5 = function (string) {
- function rotateLeft(lValue, iShiftBits) {
- return lValue << iShiftBits | lValue >>> 32 - iShiftBits;
- }
- function addUnsigned(lX, lY) {
- var lX8 = lX & 0x80000000;
- var lY8 = lY & 0x80000000;
- var lX4 = lX & 0x40000000;
- var lY4 = lY & 0x40000000;
- var lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
- if (lX4 & lY4) {
- return lResult ^ 0x80000000 ^ lX8 ^ lY8;
- }
- if (lX4 | lY4) {
- if (lResult & 0x40000000) {
- return lResult ^ 0xC0000000 ^ lX8 ^ lY8;
- } else {
- return lResult ^ 0x40000000 ^ lX8 ^ lY8;
- }
- } else {
- return lResult ^ lX8 ^ lY8;
- }
- }
- function doF(x, y, z) {
- return x & y | ~x & z;
- }
- function doG(x, y, z) {
- return x & z | y & ~z;
- }
- function doH(x, y, z) {
- return x ^ y ^ z;
- }
- function doI(x, y, z) {
- return y ^ (x | ~z);
- }
- function doFF(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(doF(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
- function doGG(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(doG(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
- function doHH(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(doH(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
- function doII(a, b, c, d, x, s, ac) {
- a = addUnsigned(a, addUnsigned(addUnsigned(doI(b, c, d), x), ac));
- return addUnsigned(rotateLeft(a, s), b);
- }
- function convertToWordArray(str) {
- var lWordCount;
- var lMessageLength = str.length;
- var lNumberOfWords_temp1 = lMessageLength + 8;
- var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - lNumberOfWords_temp1 % 64) / 64;
- var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
- var lWordArray = new Array(lNumberOfWords - 1);
- var lBytePosition = 0;
- var lByteCount = 0;
- while (lByteCount < lMessageLength) {
- lWordCount = (lByteCount - lByteCount % 4) / 4;
- lBytePosition = lByteCount % 4 * 8;
- lWordArray[lWordCount] = lWordArray[lWordCount] | str.charCodeAt(lByteCount) << lBytePosition;
- lByteCount++;
- }
- lWordCount = (lByteCount - lByteCount % 4) / 4;
- lBytePosition = lByteCount % 4 * 8;
- lWordArray[lWordCount] = lWordArray[lWordCount] | 0x80 << lBytePosition;
- lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
- lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
- return lWordArray;
- }
- function wordToHex(lValue) {
- var wordToHexValue = '',
- wordToHexValue_temp = '',
- lByte,
- lCount;
- for (lCount = 0; lCount <= 3; lCount++) {
- lByte = lValue >>> lCount * 8 & 255;
- wordToHexValue_temp = "0".concat(lByte.toString(16));
- wordToHexValue = wordToHexValue + wordToHexValue_temp.substr(wordToHexValue_temp.length - 2, 2);
- }
- return wordToHexValue;
- }
- function utf8Encode(str) {
- str = str.replace(/\r\n/g, '\n');
- var utftext = '';
- for (var n = 0; n < str.length; n++) {
- var _c = str.charCodeAt(n);
- if (_c < 128) {
- utftext += String.fromCharCode(_c);
- } else if (_c > 127 && _c < 2048) {
- utftext += String.fromCharCode(_c >> 6 | 192);
- utftext += String.fromCharCode(_c & 63 | 128);
- } else {
- utftext += String.fromCharCode(_c >> 12 | 224);
- utftext += String.fromCharCode(_c >> 6 & 63 | 128);
- utftext += String.fromCharCode(_c & 63 | 128);
- }
- }
- return utftext;
- }
- var x = [];
- var k, AA, BB, CC, DD, a, b, c, d;
- var S11 = 7,
- S12 = 12,
- S13 = 17,
- S14 = 22;
- var S21 = 5,
- S22 = 9,
- S23 = 14,
- S24 = 20;
- var S31 = 4,
- S32 = 11,
- S33 = 16,
- S34 = 23;
- var S41 = 6,
- S42 = 10,
- S43 = 15,
- S44 = 21;
- string = utf8Encode(string);
- x = convertToWordArray(string);
- a = 0x67452301;
- b = 0xEFCDAB89;
- c = 0x98BADCFE;
- d = 0x10325476;
- for (k = 0; k < x.length; k += 16) {
- AA = a;
- BB = b;
- CC = c;
- DD = d;
- a = doFF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
- d = doFF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
- c = doFF(c, d, a, b, x[k + 2], S13, 0x242070DB);
- b = doFF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
- a = doFF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
- d = doFF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
- c = doFF(c, d, a, b, x[k + 6], S13, 0xA8304613);
- b = doFF(b, c, d, a, x[k + 7], S14, 0xFD469501);
- a = doFF(a, b, c, d, x[k + 8], S11, 0x698098D8);
- d = doFF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
- c = doFF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
- b = doFF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
- a = doFF(a, b, c, d, x[k + 12], S11, 0x6B901122);
- d = doFF(d, a, b, c, x[k + 13], S12, 0xFD987193);
- c = doFF(c, d, a, b, x[k + 14], S13, 0xA679438E);
- b = doFF(b, c, d, a, x[k + 15], S14, 0x49B40821);
- a = doGG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
- d = doGG(d, a, b, c, x[k + 6], S22, 0xC040B340);
- c = doGG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
- b = doGG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
- a = doGG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
- d = doGG(d, a, b, c, x[k + 10], S22, 0x2441453);
- c = doGG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
- b = doGG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
- a = doGG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
- d = doGG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
- c = doGG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
- b = doGG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
- a = doGG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
- d = doGG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
- c = doGG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
- b = doGG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
- a = doHH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
- d = doHH(d, a, b, c, x[k + 8], S32, 0x8771F681);
- c = doHH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
- b = doHH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
- a = doHH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
- d = doHH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
- c = doHH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
- b = doHH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
- a = doHH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
- d = doHH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
- c = doHH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
- b = doHH(b, c, d, a, x[k + 6], S34, 0x4881D05);
- a = doHH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
- d = doHH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
- c = doHH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
- b = doHH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
- a = doII(a, b, c, d, x[k + 0], S41, 0xF4292244);
- d = doII(d, a, b, c, x[k + 7], S42, 0x432AFF97);
- c = doII(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
- b = doII(b, c, d, a, x[k + 5], S44, 0xFC93A039);
- a = doII(a, b, c, d, x[k + 12], S41, 0x655B59C3);
- d = doII(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
- c = doII(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
- b = doII(b, c, d, a, x[k + 1], S44, 0x85845DD1);
- a = doII(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
- d = doII(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
- c = doII(c, d, a, b, x[k + 6], S43, 0xA3014314);
- b = doII(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
- a = doII(a, b, c, d, x[k + 4], S41, 0xF7537E82);
- d = doII(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
- c = doII(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
- b = doII(b, c, d, a, x[k + 9], S44, 0xEB86D391);
- a = addUnsigned(a, AA);
- b = addUnsigned(b, BB);
- c = addUnsigned(c, CC);
- d = addUnsigned(d, DD);
- }
- var temp = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
- return temp.toLowerCase();
- };
- exports.closeMediaStream = function (stream) {
- if (!stream) {
- return;
- } // Latest spec states that MediaStream has no stop() method and instead must
- // call stop() on every MediaStreamTrack.
- try {
- var tracks;
- if (stream.getTracks) {
- tracks = stream.getTracks();
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = tracks[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var track = _step.value;
- track.stop();
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- } else {
- tracks = stream.getAudioTracks();
- var _iteratorNormalCompletion2 = true;
- var _didIteratorError2 = false;
- var _iteratorError2 = undefined;
- try {
- for (var _iterator2 = tracks[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
- var _track = _step2.value;
- _track.stop();
- }
- } catch (err) {
- _didIteratorError2 = true;
- _iteratorError2 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
- _iterator2.return();
- }
- } finally {
- if (_didIteratorError2) {
- throw _iteratorError2;
- }
- }
- }
- tracks = stream.getVideoTracks();
- var _iteratorNormalCompletion3 = true;
- var _didIteratorError3 = false;
- var _iteratorError3 = undefined;
- try {
- for (var _iterator3 = tracks[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
- var _track2 = _step3.value;
- _track2.stop();
- }
- } catch (err) {
- _didIteratorError3 = true;
- _iteratorError3 = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
- _iterator3.return();
- }
- } finally {
- if (_didIteratorError3) {
- throw _iteratorError3;
- }
- }
- }
- }
- } catch (error) {
- // Deprecated by the spec, but still in use.
- // NOTE: In Temasys IE plugin stream.stop is a callable 'object'.
- if (typeof stream.stop === 'function' || _typeof(stream.stop) === 'object') {
- stream.stop();
- }
- }
- };
- exports.cloneArray = function (array) {
- return array && array.slice() || [];
- };
- },{"./Constants":2,"./Grammar":7,"./URI":25}],27:[function(require,module,exports){
- "use strict";
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- var Grammar = require('./Grammar');
- var debug = require('debug')('JsSIP:WebSocketInterface');
- var debugerror = require('debug')('JsSIP:ERROR:WebSocketInterface');
- debugerror.log = console.warn.bind(console);
- module.exports =
- /*#__PURE__*/
- function () {
- function WebSocketInterface(url) {
- _classCallCheck(this, WebSocketInterface);
- debug('new() [url:"%s"]', url);
- this._url = url;
- this._sip_uri = null;
- this._via_transport = null;
- this._ws = null;
- var parsed_url = Grammar.parse(url, 'absoluteURI');
- if (parsed_url === -1) {
- debugerror("invalid WebSocket URI: ".concat(url));
- throw new TypeError("Invalid argument: ".concat(url));
- } else if (parsed_url.scheme !== 'wss' && parsed_url.scheme !== 'ws') {
- debugerror("invalid WebSocket URI scheme: ".concat(parsed_url.scheme));
- throw new TypeError("Invalid argument: ".concat(url));
- } else {
- this._sip_uri = "sip:".concat(parsed_url.host).concat(parsed_url.port ? ":".concat(parsed_url.port) : '', ";transport=ws");
- this._via_transport = parsed_url.scheme.toUpperCase();
- }
- }
- _createClass(WebSocketInterface, [{
- key: "connect",
- value: function connect() {
- debug('connect()');
- if (this.isConnected()) {
- debug("WebSocket ".concat(this._url, " is already connected"));
- return;
- } else if (this.isConnecting()) {
- debug("WebSocket ".concat(this._url, " is connecting"));
- return;
- }
- if (this._ws) {
- this.disconnect();
- }
- debug("connecting to WebSocket ".concat(this._url));
- try {
- this._ws = new WebSocket(this._url, 'sip');
- this._ws.binaryType = 'arraybuffer';
- this._ws.onopen = this._onOpen.bind(this);
- this._ws.onclose = this._onClose.bind(this);
- this._ws.onmessage = this._onMessage.bind(this);
- this._ws.onerror = this._onError.bind(this);
- } catch (e) {
- this._onError(e);
- }
- }
- }, {
- key: "disconnect",
- value: function disconnect() {
- debug('disconnect()');
- if (this._ws) {
- // Unbind websocket event callbacks.
- this._ws.onopen = function () {};
- this._ws.onclose = function () {};
- this._ws.onmessage = function () {};
- this._ws.onerror = function () {};
- this._ws.close();
- this._ws = null;
- }
- }
- }, {
- key: "send",
- value: function send(message) {
- debug('send()');
- if (this.isConnected()) {
- this._ws.send(message);
- return true;
- } else {
- debugerror('unable to send message, WebSocket is not open');
- return false;
- }
- }
- }, {
- key: "isConnected",
- value: function isConnected() {
- return this._ws && this._ws.readyState === this._ws.OPEN;
- }
- }, {
- key: "isConnecting",
- value: function isConnecting() {
- return this._ws && this._ws.readyState === this._ws.CONNECTING;
- }
- /**
- * WebSocket Event Handlers
- */
- }, {
- key: "_onOpen",
- value: function _onOpen() {
- debug("WebSocket ".concat(this._url, " connected"));
- this.onconnect();
- }
- }, {
- key: "_onClose",
- value: function _onClose(_ref) {
- var wasClean = _ref.wasClean,
- code = _ref.code,
- reason = _ref.reason;
- debug("WebSocket ".concat(this._url, " closed"));
- if (wasClean === false) {
- debug('WebSocket abrupt disconnection');
- }
- var data = {
- socket: this,
- error: !wasClean,
- code: code,
- reason: reason
- };
- this.ondisconnect(data);
- }
- }, {
- key: "_onMessage",
- value: function _onMessage(_ref2) {
- var data = _ref2.data;
- debug('received WebSocket message');
- this.ondata(data);
- }
- }, {
- key: "_onError",
- value: function _onError(e) {
- debugerror("WebSocket ".concat(this._url, " error: ").concat(e));
- }
- }, {
- key: "via_transport",
- get: function get() {
- return this._via_transport;
- },
- set: function set(value) {
- this._via_transport = value.toUpperCase();
- }
- }, {
- key: "sip_uri",
- get: function get() {
- return this._sip_uri;
- }
- }, {
- key: "url",
- get: function get() {
- return this._url;
- }
- }]);
- return WebSocketInterface;
- }();
- },{"./Grammar":7,"debug":30}],28:[function(require,module,exports){
- "use strict";
- var JsSIP_C = require('./Constants');
- var SIPMessage = require('./SIPMessage');
- var Utils = require('./Utils');
- var debug = require('debug')('JsSIP:sanityCheck'); // Checks for requests and responses.
- var all = [minimumHeaders]; // Checks for requests.
- var requests = [rfc3261_8_2_2_1, rfc3261_16_3_4, rfc3261_18_3_request, rfc3261_8_2_2_2]; // Checks for responses.
- var responses = [rfc3261_8_1_3_3, rfc3261_18_3_response]; // local variables.
- var message;
- var ua;
- var transport;
- module.exports = function (m, u, t) {
- message = m;
- ua = u;
- transport = t;
- for (var _i = 0; _i < all.length; _i++) {
- var _check2 = all[_i];
- if (_check2() === false) {
- return false;
- }
- }
- if (message instanceof SIPMessage.IncomingRequest) {
- for (var _i2 = 0; _i2 < requests.length; _i2++) {
- var check = requests[_i2];
- if (check() === false) {
- return false;
- }
- }
- } else if (message instanceof SIPMessage.IncomingResponse) {
- for (var _i3 = 0; _i3 < responses.length; _i3++) {
- var _check = responses[_i3];
- if (_check() === false) {
- return false;
- }
- }
- } // Everything is OK.
- return true;
- };
- /*
- * Sanity Check for incoming Messages
- *
- * Requests:
- * - _rfc3261_8_2_2_1_ Receive a Request with a non supported URI scheme
- * - _rfc3261_16_3_4_ Receive a Request already sent by us
- * Does not look at via sent-by but at jssip_id, which is inserted as
- * a prefix in all initial requests generated by the ua
- * - _rfc3261_18_3_request_ Body Content-Length
- * - _rfc3261_8_2_2_2_ Merged Requests
- *
- * Responses:
- * - _rfc3261_8_1_3_3_ Multiple Via headers
- * - _rfc3261_18_3_response_ Body Content-Length
- *
- * All:
- * - Minimum headers in a SIP message
- */
- // Sanity Check functions for requests.
- function rfc3261_8_2_2_1() {
- if (message.s('to').uri.scheme !== 'sip') {
- reply(416);
- return false;
- }
- }
- function rfc3261_16_3_4() {
- if (!message.to_tag) {
- if (message.call_id.substr(0, 5) === ua.configuration.jssip_id) {
- reply(482);
- return false;
- }
- }
- }
- function rfc3261_18_3_request() {
- var len = Utils.str_utf8_length(message.body);
- var contentLength = message.getHeader('content-length');
- if (len < contentLength) {
- reply(400);
- return false;
- }
- }
- function rfc3261_8_2_2_2() {
- var fromTag = message.from_tag;
- var call_id = message.call_id;
- var cseq = message.cseq;
- var tr; // Accept any in-dialog request.
- if (message.to_tag) {
- return;
- } // INVITE request.
- if (message.method === JsSIP_C.INVITE) {
- // If the branch matches the key of any IST then assume it is a retransmission
- // and ignore the INVITE.
- // TODO: we should reply the last response.
- if (ua._transactions.ist[message.via_branch]) {
- return false;
- } // Otherwise check whether it is a merged request.
- else {
- for (var transaction in ua._transactions.ist) {
- if (Object.prototype.hasOwnProperty.call(ua._transactions.ist, transaction)) {
- tr = ua._transactions.ist[transaction];
- if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
- reply(482);
- return false;
- }
- }
- }
- }
- } // Non INVITE request.
- // If the branch matches the key of any NIST then assume it is a retransmission
- // and ignore the request.
- // TODO: we should reply the last response.
- else if (ua._transactions.nist[message.via_branch]) {
- return false;
- } // Otherwise check whether it is a merged request.
- else {
- for (var _transaction in ua._transactions.nist) {
- if (Object.prototype.hasOwnProperty.call(ua._transactions.nist, _transaction)) {
- tr = ua._transactions.nist[_transaction];
- if (tr.request.from_tag === fromTag && tr.request.call_id === call_id && tr.request.cseq === cseq) {
- reply(482);
- return false;
- }
- }
- }
- }
- } // Sanity Check functions for responses.
- function rfc3261_8_1_3_3() {
- if (message.getHeaders('via').length > 1) {
- debug('more than one Via header field present in the response, dropping the response');
- return false;
- }
- }
- function rfc3261_18_3_response() {
- var len = Utils.str_utf8_length(message.body),
- contentLength = message.getHeader('content-length');
- if (len < contentLength) {
- debug('message body length is lower than the value in Content-Length header field, dropping the response');
- return false;
- }
- } // Sanity Check functions for requests and responses.
- function minimumHeaders() {
- var mandatoryHeaders = ['from', 'to', 'call_id', 'cseq', 'via'];
- for (var _i4 = 0; _i4 < mandatoryHeaders.length; _i4++) {
- var header = mandatoryHeaders[_i4];
- if (!message.hasHeader(header)) {
- debug("missing mandatory header field : ".concat(header, ", dropping the response"));
- return false;
- }
- }
- } // Reply.
- function reply(status_code) {
- var vias = message.getHeaders('via');
- var to;
- var response = "SIP/2.0 ".concat(status_code, " ").concat(JsSIP_C.REASON_PHRASE[status_code], "\r\n");
- var _iteratorNormalCompletion = true;
- var _didIteratorError = false;
- var _iteratorError = undefined;
- try {
- for (var _iterator = vias[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
- var via = _step.value;
- response += "Via: ".concat(via, "\r\n");
- }
- } catch (err) {
- _didIteratorError = true;
- _iteratorError = err;
- } finally {
- try {
- if (!_iteratorNormalCompletion && _iterator.return != null) {
- _iterator.return();
- }
- } finally {
- if (_didIteratorError) {
- throw _iteratorError;
- }
- }
- }
- to = message.getHeader('To');
- if (!message.to_tag) {
- to += ";tag=".concat(Utils.newTag());
- }
- response += "To: ".concat(to, "\r\n");
- response += "From: ".concat(message.getHeader('From'), "\r\n");
- response += "Call-ID: ".concat(message.call_id, "\r\n");
- response += "CSeq: ".concat(message.cseq, " ").concat(message.method, "\r\n");
- response += '\r\n';
- transport.send(response);
- }
- },{"./Constants":2,"./SIPMessage":19,"./Utils":26,"debug":30}],29:[function(require,module,exports){
- // Copyright Joyent, Inc. and other Node contributors.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a
- // copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to permit
- // persons to whom the Software is furnished to do so, subject to the
- // following conditions:
- //
- // The above copyright notice and this permission notice shall be included
- // in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
- var objectCreate = Object.create || objectCreatePolyfill
- var objectKeys = Object.keys || objectKeysPolyfill
- var bind = Function.prototype.bind || functionBindPolyfill
- function EventEmitter() {
- if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
- this._events = objectCreate(null);
- this._eventsCount = 0;
- }
- this._maxListeners = this._maxListeners || undefined;
- }
- module.exports = EventEmitter;
- // Backwards-compat with node 0.10.x
- EventEmitter.EventEmitter = EventEmitter;
- EventEmitter.prototype._events = undefined;
- EventEmitter.prototype._maxListeners = undefined;
- // By default EventEmitters will print a warning if more than 10 listeners are
- // added to it. This is a useful default which helps finding memory leaks.
- var defaultMaxListeners = 10;
- var hasDefineProperty;
- try {
- var o = {};
- if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
- hasDefineProperty = o.x === 0;
- } catch (err) { hasDefineProperty = false }
- if (hasDefineProperty) {
- Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
- enumerable: true,
- get: function() {
- return defaultMaxListeners;
- },
- set: function(arg) {
- // check whether the input is a positive number (whose value is zero or
- // greater and not a NaN).
- if (typeof arg !== 'number' || arg < 0 || arg !== arg)
- throw new TypeError('"defaultMaxListeners" must be a positive number');
- defaultMaxListeners = arg;
- }
- });
- } else {
- EventEmitter.defaultMaxListeners = defaultMaxListeners;
- }
- // Obviously not all Emitters should be limited to 10. This function allows
- // that to be increased. Set to zero for unlimited.
- EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
- if (typeof n !== 'number' || n < 0 || isNaN(n))
- throw new TypeError('"n" argument must be a positive number');
- this._maxListeners = n;
- return this;
- };
- function $getMaxListeners(that) {
- if (that._maxListeners === undefined)
- return EventEmitter.defaultMaxListeners;
- return that._maxListeners;
- }
- EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
- return $getMaxListeners(this);
- };
- // These standalone emit* functions are used to optimize calling of event
- // handlers for fast cases because emit() itself often has a variable number of
- // arguments and can be deoptimized because of that. These functions always have
- // the same number of arguments and thus do not get deoptimized, so the code
- // inside them can execute faster.
- function emitNone(handler, isFn, self) {
- if (isFn)
- handler.call(self);
- else {
- var len = handler.length;
- var listeners = arrayClone(handler, len);
- for (var i = 0; i < len; ++i)
- listeners[i].call(self);
- }
- }
- function emitOne(handler, isFn, self, arg1) {
- if (isFn)
- handler.call(self, arg1);
- else {
- var len = handler.length;
- var listeners = arrayClone(handler, len);
- for (var i = 0; i < len; ++i)
- listeners[i].call(self, arg1);
- }
- }
- function emitTwo(handler, isFn, self, arg1, arg2) {
- if (isFn)
- handler.call(self, arg1, arg2);
- else {
- var len = handler.length;
- var listeners = arrayClone(handler, len);
- for (var i = 0; i < len; ++i)
- listeners[i].call(self, arg1, arg2);
- }
- }
- function emitThree(handler, isFn, self, arg1, arg2, arg3) {
- if (isFn)
- handler.call(self, arg1, arg2, arg3);
- else {
- var len = handler.length;
- var listeners = arrayClone(handler, len);
- for (var i = 0; i < len; ++i)
- listeners[i].call(self, arg1, arg2, arg3);
- }
- }
- function emitMany(handler, isFn, self, args) {
- if (isFn)
- handler.apply(self, args);
- else {
- var len = handler.length;
- var listeners = arrayClone(handler, len);
- for (var i = 0; i < len; ++i)
- listeners[i].apply(self, args);
- }
- }
- EventEmitter.prototype.emit = function emit(type) {
- var er, handler, len, args, i, events;
- var doError = (type === 'error');
- events = this._events;
- if (events)
- doError = (doError && events.error == null);
- else if (!doError)
- return false;
- // If there is no 'error' event listener then throw.
- if (doError) {
- if (arguments.length > 1)
- er = arguments[1];
- if (er instanceof Error) {
- throw er; // Unhandled 'error' event
- } else {
- // At least give some kind of context to the user
- var err = new Error('Unhandled "error" event. (' + er + ')');
- err.context = er;
- throw err;
- }
- return false;
- }
- handler = events[type];
- if (!handler)
- return false;
- var isFn = typeof handler === 'function';
- len = arguments.length;
- switch (len) {
- // fast cases
- case 1:
- emitNone(handler, isFn, this);
- break;
- case 2:
- emitOne(handler, isFn, this, arguments[1]);
- break;
- case 3:
- emitTwo(handler, isFn, this, arguments[1], arguments[2]);
- break;
- case 4:
- emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
- break;
- // slower
- default:
- args = new Array(len - 1);
- for (i = 1; i < len; i++)
- args[i - 1] = arguments[i];
- emitMany(handler, isFn, this, args);
- }
- return true;
- };
- function _addListener(target, type, listener, prepend) {
- var m;
- var events;
- var existing;
- if (typeof listener !== 'function')
- throw new TypeError('"listener" argument must be a function');
- events = target._events;
- if (!events) {
- events = target._events = objectCreate(null);
- target._eventsCount = 0;
- } else {
- // To avoid recursion in the case that type === "newListener"! Before
- // adding it to the listeners, first emit "newListener".
- if (events.newListener) {
- target.emit('newListener', type,
- listener.listener ? listener.listener : listener);
- // Re-assign `events` because a newListener handler could have caused the
- // this._events to be assigned to a new object
- events = target._events;
- }
- existing = events[type];
- }
- if (!existing) {
- // Optimize the case of one listener. Don't need the extra array object.
- existing = events[type] = listener;
- ++target._eventsCount;
- } else {
- if (typeof existing === 'function') {
- // Adding the second element, need to change to array.
- existing = events[type] =
- prepend ? [listener, existing] : [existing, listener];
- } else {
- // If we've already got an array, just append.
- if (prepend) {
- existing.unshift(listener);
- } else {
- existing.push(listener);
- }
- }
- // Check for listener leak
- if (!existing.warned) {
- m = $getMaxListeners(target);
- if (m && m > 0 && existing.length > m) {
- existing.warned = true;
- var w = new Error('Possible EventEmitter memory leak detected. ' +
- existing.length + ' "' + String(type) + '" listeners ' +
- 'added. Use emitter.setMaxListeners() to ' +
- 'increase limit.');
- w.name = 'MaxListenersExceededWarning';
- w.emitter = target;
- w.type = type;
- w.count = existing.length;
- if (typeof console === 'object' && console.warn) {
- console.warn('%s: %s', w.name, w.message);
- }
- }
- }
- }
- return target;
- }
- EventEmitter.prototype.addListener = function addListener(type, listener) {
- return _addListener(this, type, listener, false);
- };
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
- EventEmitter.prototype.prependListener =
- function prependListener(type, listener) {
- return _addListener(this, type, listener, true);
- };
- function onceWrapper() {
- if (!this.fired) {
- this.target.removeListener(this.type, this.wrapFn);
- this.fired = true;
- switch (arguments.length) {
- case 0:
- return this.listener.call(this.target);
- case 1:
- return this.listener.call(this.target, arguments[0]);
- case 2:
- return this.listener.call(this.target, arguments[0], arguments[1]);
- case 3:
- return this.listener.call(this.target, arguments[0], arguments[1],
- arguments[2]);
- default:
- var args = new Array(arguments.length);
- for (var i = 0; i < args.length; ++i)
- args[i] = arguments[i];
- this.listener.apply(this.target, args);
- }
- }
- }
- function _onceWrap(target, type, listener) {
- var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
- var wrapped = bind.call(onceWrapper, state);
- wrapped.listener = listener;
- state.wrapFn = wrapped;
- return wrapped;
- }
- EventEmitter.prototype.once = function once(type, listener) {
- if (typeof listener !== 'function')
- throw new TypeError('"listener" argument must be a function');
- this.on(type, _onceWrap(this, type, listener));
- return this;
- };
- EventEmitter.prototype.prependOnceListener =
- function prependOnceListener(type, listener) {
- if (typeof listener !== 'function')
- throw new TypeError('"listener" argument must be a function');
- this.prependListener(type, _onceWrap(this, type, listener));
- return this;
- };
- // Emits a 'removeListener' event if and only if the listener was removed.
- EventEmitter.prototype.removeListener =
- function removeListener(type, listener) {
- var list, events, position, i, originalListener;
- if (typeof listener !== 'function')
- throw new TypeError('"listener" argument must be a function');
- events = this._events;
- if (!events)
- return this;
- list = events[type];
- if (!list)
- return this;
- if (list === listener || list.listener === listener) {
- if (--this._eventsCount === 0)
- this._events = objectCreate(null);
- else {
- delete events[type];
- if (events.removeListener)
- this.emit('removeListener', type, list.listener || listener);
- }
- } else if (typeof list !== 'function') {
- position = -1;
- for (i = list.length - 1; i >= 0; i--) {
- if (list[i] === listener || list[i].listener === listener) {
- originalListener = list[i].listener;
- position = i;
- break;
- }
- }
- if (position < 0)
- return this;
- if (position === 0)
- list.shift();
- else
- spliceOne(list, position);
- if (list.length === 1)
- events[type] = list[0];
- if (events.removeListener)
- this.emit('removeListener', type, originalListener || listener);
- }
- return this;
- };
- EventEmitter.prototype.removeAllListeners =
- function removeAllListeners(type) {
- var listeners, events, i;
- events = this._events;
- if (!events)
- return this;
- // not listening for removeListener, no need to emit
- if (!events.removeListener) {
- if (arguments.length === 0) {
- this._events = objectCreate(null);
- this._eventsCount = 0;
- } else if (events[type]) {
- if (--this._eventsCount === 0)
- this._events = objectCreate(null);
- else
- delete events[type];
- }
- return this;
- }
- // emit removeListener for all listeners on all events
- if (arguments.length === 0) {
- var keys = objectKeys(events);
- var key;
- for (i = 0; i < keys.length; ++i) {
- key = keys[i];
- if (key === 'removeListener') continue;
- this.removeAllListeners(key);
- }
- this.removeAllListeners('removeListener');
- this._events = objectCreate(null);
- this._eventsCount = 0;
- return this;
- }
- listeners = events[type];
- if (typeof listeners === 'function') {
- this.removeListener(type, listeners);
- } else if (listeners) {
- // LIFO order
- for (i = listeners.length - 1; i >= 0; i--) {
- this.removeListener(type, listeners[i]);
- }
- }
- return this;
- };
- function _listeners(target, type, unwrap) {
- var events = target._events;
- if (!events)
- return [];
- var evlistener = events[type];
- if (!evlistener)
- return [];
- if (typeof evlistener === 'function')
- return unwrap ? [evlistener.listener || evlistener] : [evlistener];
- return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
- }
- EventEmitter.prototype.listeners = function listeners(type) {
- return _listeners(this, type, true);
- };
- EventEmitter.prototype.rawListeners = function rawListeners(type) {
- return _listeners(this, type, false);
- };
- EventEmitter.listenerCount = function(emitter, type) {
- if (typeof emitter.listenerCount === 'function') {
- return emitter.listenerCount(type);
- } else {
- return listenerCount.call(emitter, type);
- }
- };
- EventEmitter.prototype.listenerCount = listenerCount;
- function listenerCount(type) {
- var events = this._events;
- if (events) {
- var evlistener = events[type];
- if (typeof evlistener === 'function') {
- return 1;
- } else if (evlistener) {
- return evlistener.length;
- }
- }
- return 0;
- }
- EventEmitter.prototype.eventNames = function eventNames() {
- return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
- };
- // About 1.5x faster than the two-arg version of Array#splice().
- function spliceOne(list, index) {
- for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
- list[i] = list[k];
- list.pop();
- }
- function arrayClone(arr, n) {
- var copy = new Array(n);
- for (var i = 0; i < n; ++i)
- copy[i] = arr[i];
- return copy;
- }
- function unwrapListeners(arr) {
- var ret = new Array(arr.length);
- for (var i = 0; i < ret.length; ++i) {
- ret[i] = arr[i].listener || arr[i];
- }
- return ret;
- }
- function objectCreatePolyfill(proto) {
- var F = function() {};
- F.prototype = proto;
- return new F;
- }
- function objectKeysPolyfill(obj) {
- var keys = [];
- for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
- keys.push(k);
- }
- return k;
- }
- function functionBindPolyfill(context) {
- var fn = this;
- return function () {
- return fn.apply(context, arguments);
- };
- }
- },{}],30:[function(require,module,exports){
- (function (process){
- /* eslint-env browser */
- /**
- * This is the web browser implementation of `debug()`.
- */
- exports.log = log;
- exports.formatArgs = formatArgs;
- exports.save = save;
- exports.load = load;
- exports.useColors = useColors;
- exports.storage = localstorage();
- /**
- * Colors.
- */
- exports.colors = [
- '#0000CC',
- '#0000FF',
- '#0033CC',
- '#0033FF',
- '#0066CC',
- '#0066FF',
- '#0099CC',
- '#0099FF',
- '#00CC00',
- '#00CC33',
- '#00CC66',
- '#00CC99',
- '#00CCCC',
- '#00CCFF',
- '#3300CC',
- '#3300FF',
- '#3333CC',
- '#3333FF',
- '#3366CC',
- '#3366FF',
- '#3399CC',
- '#3399FF',
- '#33CC00',
- '#33CC33',
- '#33CC66',
- '#33CC99',
- '#33CCCC',
- '#33CCFF',
- '#6600CC',
- '#6600FF',
- '#6633CC',
- '#6633FF',
- '#66CC00',
- '#66CC33',
- '#9900CC',
- '#9900FF',
- '#9933CC',
- '#9933FF',
- '#99CC00',
- '#99CC33',
- '#CC0000',
- '#CC0033',
- '#CC0066',
- '#CC0099',
- '#CC00CC',
- '#CC00FF',
- '#CC3300',
- '#CC3333',
- '#CC3366',
- '#CC3399',
- '#CC33CC',
- '#CC33FF',
- '#CC6600',
- '#CC6633',
- '#CC9900',
- '#CC9933',
- '#CCCC00',
- '#CCCC33',
- '#FF0000',
- '#FF0033',
- '#FF0066',
- '#FF0099',
- '#FF00CC',
- '#FF00FF',
- '#FF3300',
- '#FF3333',
- '#FF3366',
- '#FF3399',
- '#FF33CC',
- '#FF33FF',
- '#FF6600',
- '#FF6633',
- '#FF9900',
- '#FF9933',
- '#FFCC00',
- '#FFCC33'
- ];
- /**
- * Currently only WebKit-based Web Inspectors, Firefox >= v31,
- * and the Firebug extension (any Firefox version) are known
- * to support "%c" CSS customizations.
- *
- * TODO: add a `localStorage` variable to explicitly enable/disable colors
- */
- // eslint-disable-next-line complexity
- function useColors() {
- // NB: In an Electron preload script, document will be defined but not fully
- // initialized. Since we know we're in Chrome, we'll just detect this case
- // explicitly
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
- return true;
- }
- // Internet Explorer and Edge do not support colors.
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
- return false;
- }
- // Is webkit? http://stackoverflow.com/a/16459606/376773
- // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
- return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
- // Is firebug? http://stackoverflow.com/a/398120/376773
- (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
- // Is firefox >= v31?
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
- // Double check webkit in userAgent just in case we are in a worker
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
- }
- /**
- * Colorize log arguments if enabled.
- *
- * @api public
- */
- function formatArgs(args) {
- args[0] = (this.useColors ? '%c' : '') +
- this.namespace +
- (this.useColors ? ' %c' : ' ') +
- args[0] +
- (this.useColors ? '%c ' : ' ') +
- '+' + module.exports.humanize(this.diff);
- if (!this.useColors) {
- return;
- }
- const c = 'color: ' + this.color;
- args.splice(1, 0, c, 'color: inherit');
- // The final "%c" is somewhat tricky, because there could be other
- // arguments passed either before or after the %c, so we need to
- // figure out the correct index to insert the CSS into
- let index = 0;
- let lastC = 0;
- args[0].replace(/%[a-zA-Z%]/g, match => {
- if (match === '%%') {
- return;
- }
- index++;
- if (match === '%c') {
- // We only are interested in the *last* %c
- // (the user may have provided their own)
- lastC = index;
- }
- });
- args.splice(lastC, 0, c);
- }
- /**
- * Invokes `console.log()` when available.
- * No-op when `console.log` is not a "function".
- *
- * @api public
- */
- function log(...args) {
- // This hackery is required for IE8/9, where
- // the `console.log` function doesn't have 'apply'
- return typeof console === 'object' &&
- console.log &&
- console.log(...args);
- }
- /**
- * Save `namespaces`.
- *
- * @param {String} namespaces
- * @api private
- */
- function save(namespaces) {
- try {
- if (namespaces) {
- exports.storage.setItem('debug', namespaces);
- } else {
- exports.storage.removeItem('debug');
- }
- } catch (error) {
- // Swallow
- // XXX (@Qix-) should we be logging these?
- }
- }
- /**
- * Load `namespaces`.
- *
- * @return {String} returns the previously persisted debug modes
- * @api private
- */
- function load() {
- let r;
- try {
- r = exports.storage.getItem('debug');
- } catch (error) {
- // Swallow
- // XXX (@Qix-) should we be logging these?
- }
- // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
- if (!r && typeof process !== 'undefined' && 'env' in process) {
- r = process.env.DEBUG;
- }
- return r;
- }
- /**
- * Localstorage attempts to return the localstorage.
- *
- * This is necessary because safari throws
- * when a user disables cookies/localstorage
- * and you attempt to access it.
- *
- * @return {LocalStorage}
- * @api private
- */
- function localstorage() {
- try {
- // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
- // The Browser also has localStorage in the global context.
- return localStorage;
- } catch (error) {
- // Swallow
- // XXX (@Qix-) should we be logging these?
- }
- }
- module.exports = require('./common')(exports);
- const {formatters} = module.exports;
- /**
- * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
- */
- formatters.j = function (v) {
- try {
- return JSON.stringify(v);
- } catch (error) {
- return '[UnexpectedJSONParseError]: ' + error.message;
- }
- };
- }).call(this,require('_process'))
- },{"./common":31,"_process":33}],31:[function(require,module,exports){
- /**
- * This is the common logic for both the Node.js and web browser
- * implementations of `debug()`.
- */
- function setup(env) {
- createDebug.debug = createDebug;
- createDebug.default = createDebug;
- createDebug.coerce = coerce;
- createDebug.disable = disable;
- createDebug.enable = enable;
- createDebug.enabled = enabled;
- createDebug.humanize = require('ms');
- Object.keys(env).forEach(key => {
- createDebug[key] = env[key];
- });
- /**
- * Active `debug` instances.
- */
- createDebug.instances = [];
- /**
- * The currently active debug mode names, and names to skip.
- */
- createDebug.names = [];
- createDebug.skips = [];
- /**
- * Map of special "%n" handling functions, for the debug "format" argument.
- *
- * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
- */
- createDebug.formatters = {};
- /**
- * Selects a color for a debug namespace
- * @param {String} namespace The namespace string for the for the debug instance to be colored
- * @return {Number|String} An ANSI color code for the given namespace
- * @api private
- */
- function selectColor(namespace) {
- let hash = 0;
- for (let i = 0; i < namespace.length; i++) {
- hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
- hash |= 0; // Convert to 32bit integer
- }
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
- }
- createDebug.selectColor = selectColor;
- /**
- * Create a debugger with the given `namespace`.
- *
- * @param {String} namespace
- * @return {Function}
- * @api public
- */
- function createDebug(namespace) {
- let prevTime;
- function debug(...args) {
- // Disabled?
- if (!debug.enabled) {
- return;
- }
- const self = debug;
- // Set `diff` timestamp
- const curr = Number(new Date());
- const ms = curr - (prevTime || curr);
- self.diff = ms;
- self.prev = prevTime;
- self.curr = curr;
- prevTime = curr;
- args[0] = createDebug.coerce(args[0]);
- if (typeof args[0] !== 'string') {
- // Anything else let's inspect with %O
- args.unshift('%O');
- }
- // Apply any `formatters` transformations
- let index = 0;
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
- // If we encounter an escaped % then don't increase the array index
- if (match === '%%') {
- return match;
- }
- index++;
- const formatter = createDebug.formatters[format];
- if (typeof formatter === 'function') {
- const val = args[index];
- match = formatter.call(self, val);
- // Now we need to remove `args[index]` since it's inlined in the `format`
- args.splice(index, 1);
- index--;
- }
- return match;
- });
- // Apply env-specific formatting (colors, etc.)
- createDebug.formatArgs.call(self, args);
- const logFn = self.log || createDebug.log;
- logFn.apply(self, args);
- }
- debug.namespace = namespace;
- debug.enabled = createDebug.enabled(namespace);
- debug.useColors = createDebug.useColors();
- debug.color = selectColor(namespace);
- debug.destroy = destroy;
- debug.extend = extend;
- // Debug.formatArgs = formatArgs;
- // debug.rawLog = rawLog;
- // env-specific initialization logic for debug instances
- if (typeof createDebug.init === 'function') {
- createDebug.init(debug);
- }
- createDebug.instances.push(debug);
- return debug;
- }
- function destroy() {
- const index = createDebug.instances.indexOf(this);
- if (index !== -1) {
- createDebug.instances.splice(index, 1);
- return true;
- }
- return false;
- }
- function extend(namespace, delimiter) {
- return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
- }
- /**
- * Enables a debug mode by namespaces. This can include modes
- * separated by a colon and wildcards.
- *
- * @param {String} namespaces
- * @api public
- */
- function enable(namespaces) {
- createDebug.save(namespaces);
- createDebug.names = [];
- createDebug.skips = [];
- let i;
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
- const len = split.length;
- for (i = 0; i < len; i++) {
- if (!split[i]) {
- // ignore empty strings
- continue;
- }
- namespaces = split[i].replace(/\*/g, '.*?');
- if (namespaces[0] === '-') {
- createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
- } else {
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
- }
- }
- for (i = 0; i < createDebug.instances.length; i++) {
- const instance = createDebug.instances[i];
- instance.enabled = createDebug.enabled(instance.namespace);
- }
- }
- /**
- * Disable debug output.
- *
- * @return {String} namespaces
- * @api public
- */
- function disable() {
- const namespaces = [
- ...createDebug.names.map(toNamespace),
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
- ].join(',');
- createDebug.enable('');
- return namespaces;
- }
- /**
- * Returns true if the given mode name is enabled, false otherwise.
- *
- * @param {String} name
- * @return {Boolean}
- * @api public
- */
- function enabled(name) {
- if (name[name.length - 1] === '*') {
- return true;
- }
- let i;
- let len;
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
- if (createDebug.skips[i].test(name)) {
- return false;
- }
- }
- for (i = 0, len = createDebug.names.length; i < len; i++) {
- if (createDebug.names[i].test(name)) {
- return true;
- }
- }
- return false;
- }
- /**
- * Convert regexp to namespace
- *
- * @param {RegExp} regxep
- * @return {String} namespace
- * @api private
- */
- function toNamespace(regexp) {
- return regexp.toString()
- .substring(2, regexp.toString().length - 2)
- .replace(/\.\*\?$/, '*');
- }
- /**
- * Coerce `val`.
- *
- * @param {Mixed} val
- * @return {Mixed}
- * @api private
- */
- function coerce(val) {
- if (val instanceof Error) {
- return val.stack || val.message;
- }
- return val;
- }
- createDebug.enable(createDebug.load());
- return createDebug;
- }
- module.exports = setup;
- },{"ms":32}],32:[function(require,module,exports){
- /**
- * Helpers.
- */
- var s = 1000;
- var m = s * 60;
- var h = m * 60;
- var d = h * 24;
- var w = d * 7;
- var y = d * 365.25;
- /**
- * Parse or format the given `val`.
- *
- * Options:
- *
- * - `long` verbose formatting [false]
- *
- * @param {String|Number} val
- * @param {Object} [options]
- * @throws {Error} throw an error if val is not a non-empty string or a number
- * @return {String|Number}
- * @api public
- */
- module.exports = function(val, options) {
- options = options || {};
- var type = typeof val;
- if (type === 'string' && val.length > 0) {
- return parse(val);
- } else if (type === 'number' && isNaN(val) === false) {
- return options.long ? fmtLong(val) : fmtShort(val);
- }
- throw new Error(
- 'val is not a non-empty string or a valid number. val=' +
- JSON.stringify(val)
- );
- };
- /**
- * Parse the given `str` and return milliseconds.
- *
- * @param {String} str
- * @return {Number}
- * @api private
- */
- function parse(str) {
- str = String(str);
- if (str.length > 100) {
- return;
- }
- var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
- str
- );
- if (!match) {
- return;
- }
- var n = parseFloat(match[1]);
- var type = (match[2] || 'ms').toLowerCase();
- switch (type) {
- case 'years':
- case 'year':
- case 'yrs':
- case 'yr':
- case 'y':
- return n * y;
- case 'weeks':
- case 'week':
- case 'w':
- return n * w;
- case 'days':
- case 'day':
- case 'd':
- return n * d;
- case 'hours':
- case 'hour':
- case 'hrs':
- case 'hr':
- case 'h':
- return n * h;
- case 'minutes':
- case 'minute':
- case 'mins':
- case 'min':
- case 'm':
- return n * m;
- case 'seconds':
- case 'second':
- case 'secs':
- case 'sec':
- case 's':
- return n * s;
- case 'milliseconds':
- case 'millisecond':
- case 'msecs':
- case 'msec':
- case 'ms':
- return n;
- default:
- return undefined;
- }
- }
- /**
- * Short format for `ms`.
- *
- * @param {Number} ms
- * @return {String}
- * @api private
- */
- function fmtShort(ms) {
- var msAbs = Math.abs(ms);
- if (msAbs >= d) {
- return Math.round(ms / d) + 'd';
- }
- if (msAbs >= h) {
- return Math.round(ms / h) + 'h';
- }
- if (msAbs >= m) {
- return Math.round(ms / m) + 'm';
- }
- if (msAbs >= s) {
- return Math.round(ms / s) + 's';
- }
- return ms + 'ms';
- }
- /**
- * Long format for `ms`.
- *
- * @param {Number} ms
- * @return {String}
- * @api private
- */
- function fmtLong(ms) {
- var msAbs = Math.abs(ms);
- if (msAbs >= d) {
- return plural(ms, msAbs, d, 'day');
- }
- if (msAbs >= h) {
- return plural(ms, msAbs, h, 'hour');
- }
- if (msAbs >= m) {
- return plural(ms, msAbs, m, 'minute');
- }
- if (msAbs >= s) {
- return plural(ms, msAbs, s, 'second');
- }
- return ms + ' ms';
- }
- /**
- * Pluralization helper.
- */
- function plural(ms, msAbs, n, name) {
- var isPlural = msAbs >= n * 1.5;
- return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
- }
- },{}],33:[function(require,module,exports){
- // shim for using process in browser
- var process = module.exports = {};
- // cached from whatever global is present so that test runners that stub it
- // don't break things. But we need to wrap it in a try catch in case it is
- // wrapped in strict mode code which doesn't define any globals. It's inside a
- // function because try/catches deoptimize in certain engines.
- var cachedSetTimeout;
- var cachedClearTimeout;
- function defaultSetTimout() {
- throw new Error('setTimeout has not been defined');
- }
- function defaultClearTimeout () {
- throw new Error('clearTimeout has not been defined');
- }
- (function () {
- try {
- if (typeof setTimeout === 'function') {
- cachedSetTimeout = setTimeout;
- } else {
- cachedSetTimeout = defaultSetTimout;
- }
- } catch (e) {
- cachedSetTimeout = defaultSetTimout;
- }
- try {
- if (typeof clearTimeout === 'function') {
- cachedClearTimeout = clearTimeout;
- } else {
- cachedClearTimeout = defaultClearTimeout;
- }
- } catch (e) {
- cachedClearTimeout = defaultClearTimeout;
- }
- } ())
- function runTimeout(fun) {
- if (cachedSetTimeout === setTimeout) {
- //normal enviroments in sane situations
- return setTimeout(fun, 0);
- }
- // if setTimeout wasn't available but was latter defined
- if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
- cachedSetTimeout = setTimeout;
- return setTimeout(fun, 0);
- }
- try {
- // when when somebody has screwed with setTimeout but no I.E. maddness
- return cachedSetTimeout(fun, 0);
- } catch(e){
- try {
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
- return cachedSetTimeout.call(null, fun, 0);
- } catch(e){
- // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
- return cachedSetTimeout.call(this, fun, 0);
- }
- }
- }
- function runClearTimeout(marker) {
- if (cachedClearTimeout === clearTimeout) {
- //normal enviroments in sane situations
- return clearTimeout(marker);
- }
- // if clearTimeout wasn't available but was latter defined
- if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
- cachedClearTimeout = clearTimeout;
- return clearTimeout(marker);
- }
- try {
- // when when somebody has screwed with setTimeout but no I.E. maddness
- return cachedClearTimeout(marker);
- } catch (e){
- try {
- // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
- return cachedClearTimeout.call(null, marker);
- } catch (e){
- // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
- // Some versions of I.E. have different rules for clearTimeout vs setTimeout
- return cachedClearTimeout.call(this, marker);
- }
- }
- }
- var queue = [];
- var draining = false;
- var currentQueue;
- var queueIndex = -1;
- function cleanUpNextTick() {
- if (!draining || !currentQueue) {
- return;
- }
- draining = false;
- if (currentQueue.length) {
- queue = currentQueue.concat(queue);
- } else {
- queueIndex = -1;
- }
- if (queue.length) {
- drainQueue();
- }
- }
- function drainQueue() {
- if (draining) {
- return;
- }
- var timeout = runTimeout(cleanUpNextTick);
- draining = true;
- var len = queue.length;
- while(len) {
- currentQueue = queue;
- queue = [];
- while (++queueIndex < len) {
- if (currentQueue) {
- currentQueue[queueIndex].run();
- }
- }
- queueIndex = -1;
- len = queue.length;
- }
- currentQueue = null;
- draining = false;
- runClearTimeout(timeout);
- }
- process.nextTick = function (fun) {
- var args = new Array(arguments.length - 1);
- if (arguments.length > 1) {
- for (var i = 1; i < arguments.length; i++) {
- args[i - 1] = arguments[i];
- }
- }
- queue.push(new Item(fun, args));
- if (queue.length === 1 && !draining) {
- runTimeout(drainQueue);
- }
- };
- // v8 likes predictible objects
- function Item(fun, array) {
- this.fun = fun;
- this.array = array;
- }
- Item.prototype.run = function () {
- this.fun.apply(null, this.array);
- };
- process.title = 'browser';
- process.browser = true;
- process.env = {};
- process.argv = [];
- process.version = ''; // empty string to avoid regexp issues
- process.versions = {};
- function noop() {}
- process.on = noop;
- process.addListener = noop;
- process.once = noop;
- process.off = noop;
- process.removeListener = noop;
- process.removeAllListeners = noop;
- process.emit = noop;
- process.prependListener = noop;
- process.prependOnceListener = noop;
- process.listeners = function (name) { return [] }
- process.binding = function (name) {
- throw new Error('process.binding is not supported');
- };
- process.cwd = function () { return '/' };
- process.chdir = function (dir) {
- throw new Error('process.chdir is not supported');
- };
- process.umask = function() { return 0; };
- },{}],34:[function(require,module,exports){
- var grammar = module.exports = {
- v: [{
- name: 'version',
- reg: /^(\d*)$/
- }],
- o: [{ //o=- 20518 0 IN IP4 203.0.113.1
- // NB: sessionId will be a String in most cases because it is huge
- name: 'origin',
- reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
- names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
- format: '%s %s %d %s IP%d %s'
- }],
- // default parsing of these only (though some of these feel outdated)
- s: [{ name: 'name' }],
- i: [{ name: 'description' }],
- u: [{ name: 'uri' }],
- e: [{ name: 'email' }],
- p: [{ name: 'phone' }],
- z: [{ name: 'timezones' }], // TODO: this one can actually be parsed properly..
- r: [{ name: 'repeats' }], // TODO: this one can also be parsed properly
- //k: [{}], // outdated thing ignored
- t: [{ //t=0 0
- name: 'timing',
- reg: /^(\d*) (\d*)/,
- names: ['start', 'stop'],
- format: '%d %d'
- }],
- c: [{ //c=IN IP4 10.47.197.26
- name: 'connection',
- reg: /^IN IP(\d) (\S*)/,
- names: ['version', 'ip'],
- format: 'IN IP%d %s'
- }],
- b: [{ //b=AS:4000
- push: 'bandwidth',
- reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
- names: ['type', 'limit'],
- format: '%s:%s'
- }],
- m: [{ //m=video 51744 RTP/AVP 126 97 98 34 31
- // NB: special - pushes to session
- // TODO: rtp/fmtp should be filtered by the payloads found here?
- reg: /^(\w*) (\d*) ([\w\/]*)(?: (.*))?/,
- names: ['type', 'port', 'protocol', 'payloads'],
- format: '%s %d %s %s'
- }],
- a: [
- { //a=rtpmap:110 opus/48000/2
- push: 'rtp',
- reg: /^rtpmap:(\d*) ([\w\-\.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
- names: ['payload', 'codec', 'rate', 'encoding'],
- format: function (o) {
- return (o.encoding) ?
- 'rtpmap:%d %s/%s/%s':
- o.rate ?
- 'rtpmap:%d %s/%s':
- 'rtpmap:%d %s';
- }
- },
- { //a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
- //a=fmtp:111 minptime=10; useinbandfec=1
- push: 'fmtp',
- reg: /^fmtp:(\d*) ([\S| ]*)/,
- names: ['payload', 'config'],
- format: 'fmtp:%d %s'
- },
- { //a=control:streamid=0
- name: 'control',
- reg: /^control:(.*)/,
- format: 'control:%s'
- },
- { //a=rtcp:65179 IN IP4 193.84.77.194
- name: 'rtcp',
- reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
- names: ['port', 'netType', 'ipVer', 'address'],
- format: function (o) {
- return (o.address != null) ?
- 'rtcp:%d %s IP%d %s':
- 'rtcp:%d';
- }
- },
- { //a=rtcp-fb:98 trr-int 100
- push: 'rtcpFbTrrInt',
- reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
- names: ['payload', 'value'],
- format: 'rtcp-fb:%d trr-int %d'
- },
- { //a=rtcp-fb:98 nack rpsi
- push: 'rtcpFb',
- reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
- names: ['payload', 'type', 'subtype'],
- format: function (o) {
- return (o.subtype != null) ?
- 'rtcp-fb:%s %s %s':
- 'rtcp-fb:%s %s';
- }
- },
- { //a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
- //a=extmap:1/recvonly URI-gps-string
- push: 'ext',
- reg: /^extmap:(\d+)(?:\/(\w+))? (\S*)(?: (\S*))?/,
- names: ['value', 'direction', 'uri', 'config'],
- format: function (o) {
- return 'extmap:%d' + (o.direction ? '/%s' : '%v') + ' %s' + (o.config ? ' %s' : '');
- }
- },
- { //a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
- push: 'crypto',
- reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
- names: ['id', 'suite', 'config', 'sessionConfig'],
- format: function (o) {
- return (o.sessionConfig != null) ?
- 'crypto:%d %s %s %s':
- 'crypto:%d %s %s';
- }
- },
- { //a=setup:actpass
- name: 'setup',
- reg: /^setup:(\w*)/,
- format: 'setup:%s'
- },
- { //a=mid:1
- name: 'mid',
- reg: /^mid:([^\s]*)/,
- format: 'mid:%s'
- },
- { //a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
- name: 'msid',
- reg: /^msid:(.*)/,
- format: 'msid:%s'
- },
- { //a=ptime:20
- name: 'ptime',
- reg: /^ptime:(\d*)/,
- format: 'ptime:%d'
- },
- { //a=maxptime:60
- name: 'maxptime',
- reg: /^maxptime:(\d*)/,
- format: 'maxptime:%d'
- },
- { //a=sendrecv
- name: 'direction',
- reg: /^(sendrecv|recvonly|sendonly|inactive)/
- },
- { //a=ice-lite
- name: 'icelite',
- reg: /^(ice-lite)/
- },
- { //a=ice-ufrag:F7gI
- name: 'iceUfrag',
- reg: /^ice-ufrag:(\S*)/,
- format: 'ice-ufrag:%s'
- },
- { //a=ice-pwd:x9cml/YzichV2+XlhiMu8g
- name: 'icePwd',
- reg: /^ice-pwd:(\S*)/,
- format: 'ice-pwd:%s'
- },
- { //a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
- name: 'fingerprint',
- reg: /^fingerprint:(\S*) (\S*)/,
- names: ['type', 'hash'],
- format: 'fingerprint:%s %s'
- },
- { //a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
- //a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10
- //a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10
- //a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10
- //a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10
- push:'candidates',
- reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
- names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
- format: function (o) {
- var str = 'candidate:%s %d %s %d %s %d typ %s';
- str += (o.raddr != null) ? ' raddr %s rport %d' : '%v%v';
- // NB: candidate has three optional chunks, so %void middles one if it's missing
- str += (o.tcptype != null) ? ' tcptype %s' : '%v';
- if (o.generation != null) {
- str += ' generation %d';
- }
- str += (o['network-id'] != null) ? ' network-id %d' : '%v';
- str += (o['network-cost'] != null) ? ' network-cost %d' : '%v';
- return str;
- }
- },
- { //a=end-of-candidates (keep after the candidates line for readability)
- name: 'endOfCandidates',
- reg: /^(end-of-candidates)/
- },
- { //a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
- name: 'remoteCandidates',
- reg: /^remote-candidates:(.*)/,
- format: 'remote-candidates:%s'
- },
- { //a=ice-options:google-ice
- name: 'iceOptions',
- reg: /^ice-options:(\S*)/,
- format: 'ice-options:%s'
- },
- { //a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
- push: 'ssrcs',
- reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,
- names: ['id', 'attribute', 'value'],
- format: function (o) {
- var str = 'ssrc:%d';
- if (o.attribute != null) {
- str += ' %s';
- if (o.value != null) {
- str += ':%s';
- }
- }
- return str;
- }
- },
- { //a=ssrc-group:FEC 1 2
- //a=ssrc-group:FEC-FR 3004364195 1080772241
- push: 'ssrcGroups',
- // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E
- reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
- names: ['semantics', 'ssrcs'],
- format: 'ssrc-group:%s %s'
- },
- { //a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
- name: 'msidSemantic',
- reg: /^msid-semantic:\s?(\w*) (\S*)/,
- names: ['semantic', 'token'],
- format: 'msid-semantic: %s %s' // space after ':' is not accidental
- },
- { //a=group:BUNDLE audio video
- push: 'groups',
- reg: /^group:(\w*) (.*)/,
- names: ['type', 'mids'],
- format: 'group:%s %s'
- },
- { //a=rtcp-mux
- name: 'rtcpMux',
- reg: /^(rtcp-mux)/
- },
- { //a=rtcp-rsize
- name: 'rtcpRsize',
- reg: /^(rtcp-rsize)/
- },
- { //a=sctpmap:5000 webrtc-datachannel 1024
- name: 'sctpmap',
- reg: /^sctpmap:([\w_\/]*) (\S*)(?: (\S*))?/,
- names: ['sctpmapNumber', 'app', 'maxMessageSize'],
- format: function (o) {
- return (o.maxMessageSize != null) ?
- 'sctpmap:%s %s %s' :
- 'sctpmap:%s %s';
- }
- },
- { //a=x-google-flag:conference
- name: 'xGoogleFlag',
- reg: /^x-google-flag:([^\s]*)/,
- format: 'x-google-flag:%s'
- },
- { //a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0
- push: 'rids',
- reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
- names: ['id', 'direction', 'params'],
- format: function (o) {
- return (o.params) ? 'rid:%s %s %s' : 'rid:%s %s';
- }
- },
- { //a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250]
- //a=imageattr:* send [x=800,y=640] recv *
- //a=imageattr:100 recv [x=320,y=240]
- push: 'imageattrs',
- reg: new RegExp(
- //a=imageattr:97
- '^imageattr:(\\d+|\\*)' +
- //send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320]
- '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' +
- //recv [x=330,y=250]
- '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'
- ),
- names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
- format: function (o) {
- return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
- }
- },
- { //a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8
- //a=simulcast:recv 1;4,5 send 6;7
- name: 'simulcast',
- reg: new RegExp(
- //a=simulcast:
- '^simulcast:' +
- //send 1,2,3;~4,~5
- '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' +
- //space + recv 6;~7,~8
- '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' +
- //end
- '$'
- ),
- names: ['dir1', 'list1', 'dir2', 'list2'],
- format: function (o) {
- return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
- }
- },
- { //Old simulcast draft 03 (implemented by Firefox)
- // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03
- //a=simulcast: recv pt=97;98 send pt=97
- //a=simulcast: send rid=5;6;7 paused=6,7
- name: 'simulcast_03',
- reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
- names: ['value'],
- format: 'simulcast: %s'
- },
- {
- //a=framerate:25
- //a=framerate:29.97
- name: 'framerate',
- reg: /^framerate:(\d+(?:$|\.\d+))/,
- format: 'framerate:%s'
- },
- { // RFC4570
- //a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5
- name: 'sourceFilter',
- reg: /^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,
- names: ['filterMode', 'netType', 'addressTypes', 'destAddress', 'srcList'],
- format: 'source-filter: %s %s %s %s %s'
- },
- { //a=bundle-only
- name: 'bundleOnly',
- reg: /^(bundle-only)/
- },
- { //a=label:1
- name: 'label',
- reg: /^label:(.+)/,
- format: 'label:%s'
- },
- {
- // RFC version 26 for SCTP over DTLS
- // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5
- name:'sctpPort',
- reg: /^sctp-port:(\d+)$/,
- format: 'sctp-port:%s'
- },
- {
- // RFC version 26 for SCTP over DTLS
- // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
- name:'maxMessageSize',
- reg: /^max-message-size:(\d+)$/,
- format: 'max-message-size:%s'
- },
- { // any a= that we don't understand is kepts verbatim on media.invalid
- push: 'invalid',
- names: ['value']
- }
- ]
- };
- // set sensible defaults to avoid polluting the grammar with boring details
- Object.keys(grammar).forEach(function (key) {
- var objs = grammar[key];
- objs.forEach(function (obj) {
- if (!obj.reg) {
- obj.reg = /(.*)/;
- }
- if (!obj.format) {
- obj.format = '%s';
- }
- });
- });
- },{}],35:[function(require,module,exports){
- var parser = require('./parser');
- var writer = require('./writer');
- exports.write = writer;
- exports.parse = parser.parse;
- exports.parseFmtpConfig = parser.parseFmtpConfig;
- exports.parseParams = parser.parseParams;
- exports.parsePayloads = parser.parsePayloads;
- exports.parseRemoteCandidates = parser.parseRemoteCandidates;
- exports.parseImageAttributes = parser.parseImageAttributes;
- exports.parseSimulcastStreamList = parser.parseSimulcastStreamList;
- },{"./parser":36,"./writer":37}],36:[function(require,module,exports){
- var toIntIfInt = function (v) {
- return String(Number(v)) === v ? Number(v) : v;
- };
- var attachProperties = function (match, location, names, rawName) {
- if (rawName && !names) {
- location[rawName] = toIntIfInt(match[1]);
- }
- else {
- for (var i = 0; i < names.length; i += 1) {
- if (match[i+1] != null) {
- location[names[i]] = toIntIfInt(match[i+1]);
- }
- }
- }
- };
- var parseReg = function (obj, location, content) {
- var needsBlank = obj.name && obj.names;
- if (obj.push && !location[obj.push]) {
- location[obj.push] = [];
- }
- else if (needsBlank && !location[obj.name]) {
- location[obj.name] = {};
- }
- var keyLocation = obj.push ?
- {} : // blank object that will be pushed
- needsBlank ? location[obj.name] : location; // otherwise, named location or root
- attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
- if (obj.push) {
- location[obj.push].push(keyLocation);
- }
- };
- var grammar = require('./grammar');
- var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
- exports.parse = function (sdp) {
- var session = {}
- , media = []
- , location = session; // points at where properties go under (one of the above)
- // parse lines we understand
- sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
- var type = l[0];
- var content = l.slice(2);
- if (type === 'm') {
- media.push({rtp: [], fmtp: []});
- location = media[media.length-1]; // point at latest media line
- }
- for (var j = 0; j < (grammar[type] || []).length; j += 1) {
- var obj = grammar[type][j];
- if (obj.reg.test(content)) {
- return parseReg(obj, location, content);
- }
- }
- });
- session.media = media; // link it up
- return session;
- };
- var paramReducer = function (acc, expr) {
- var s = expr.split(/=(.+)/, 2);
- if (s.length === 2) {
- acc[s[0]] = toIntIfInt(s[1]);
- } else if (s.length === 1 && expr.length > 1) {
- acc[s[0]] = undefined;
- }
- return acc;
- };
- exports.parseParams = function (str) {
- return str.split(/\;\s?/).reduce(paramReducer, {});
- };
- // For backward compatibility - alias will be removed in 3.0.0
- exports.parseFmtpConfig = exports.parseParams;
- exports.parsePayloads = function (str) {
- return str.split(' ').map(Number);
- };
- exports.parseRemoteCandidates = function (str) {
- var candidates = [];
- var parts = str.split(' ').map(toIntIfInt);
- for (var i = 0; i < parts.length; i += 3) {
- candidates.push({
- component: parts[i],
- ip: parts[i + 1],
- port: parts[i + 2]
- });
- }
- return candidates;
- };
- exports.parseImageAttributes = function (str) {
- return str.split(' ').map(function (item) {
- return item.substring(1, item.length-1).split(',').reduce(paramReducer, {});
- });
- };
- exports.parseSimulcastStreamList = function (str) {
- return str.split(';').map(function (stream) {
- return stream.split(',').map(function (format) {
- var scid, paused = false;
- if (format[0] !== '~') {
- scid = toIntIfInt(format);
- } else {
- scid = toIntIfInt(format.substring(1, format.length));
- paused = true;
- }
- return {
- scid: scid,
- paused: paused
- };
- });
- });
- };
- },{"./grammar":34}],37:[function(require,module,exports){
- var grammar = require('./grammar');
- // customized util.format - discards excess arguments and can void middle ones
- var formatRegExp = /%[sdv%]/g;
- var format = function (formatStr) {
- var i = 1;
- var args = arguments;
- var len = args.length;
- return formatStr.replace(formatRegExp, function (x) {
- if (i >= len) {
- return x; // missing argument
- }
- var arg = args[i];
- i += 1;
- switch (x) {
- case '%%':
- return '%';
- case '%s':
- return String(arg);
- case '%d':
- return Number(arg);
- case '%v':
- return '';
- }
- });
- // NB: we discard excess arguments - they are typically undefined from makeLine
- };
- var makeLine = function (type, obj, location) {
- var str = obj.format instanceof Function ?
- (obj.format(obj.push ? location : location[obj.name])) :
- obj.format;
- var args = [type + '=' + str];
- if (obj.names) {
- for (var i = 0; i < obj.names.length; i += 1) {
- var n = obj.names[i];
- if (obj.name) {
- args.push(location[obj.name][n]);
- }
- else { // for mLine and push attributes
- args.push(location[obj.names[i]]);
- }
- }
- }
- else {
- args.push(location[obj.name]);
- }
- return format.apply(null, args);
- };
- // RFC specified order
- // TODO: extend this with all the rest
- var defaultOuterOrder = [
- 'v', 'o', 's', 'i',
- 'u', 'e', 'p', 'c',
- 'b', 't', 'r', 'z', 'a'
- ];
- var defaultInnerOrder = ['i', 'c', 'b', 'a'];
- module.exports = function (session, opts) {
- opts = opts || {};
- // ensure certain properties exist
- if (session.version == null) {
- session.version = 0; // 'v=0' must be there (only defined version atm)
- }
- if (session.name == null) {
- session.name = ' '; // 's= ' must be there if no meaningful name set
- }
- session.media.forEach(function (mLine) {
- if (mLine.payloads == null) {
- mLine.payloads = '';
- }
- });
- var outerOrder = opts.outerOrder || defaultOuterOrder;
- var innerOrder = opts.innerOrder || defaultInnerOrder;
- var sdp = [];
- // loop through outerOrder for matching properties on session
- outerOrder.forEach(function (type) {
- grammar[type].forEach(function (obj) {
- if (obj.name in session && session[obj.name] != null) {
- sdp.push(makeLine(type, obj, session));
- }
- else if (obj.push in session && session[obj.push] != null) {
- session[obj.push].forEach(function (el) {
- sdp.push(makeLine(type, obj, el));
- });
- }
- });
- });
- // then for each media line, follow the innerOrder
- session.media.forEach(function (mLine) {
- sdp.push(makeLine('m', grammar.m[0], mLine));
- innerOrder.forEach(function (type) {
- grammar[type].forEach(function (obj) {
- if (obj.name in mLine && mLine[obj.name] != null) {
- sdp.push(makeLine(type, obj, mLine));
- }
- else if (obj.push in mLine && mLine[obj.push] != null) {
- mLine[obj.push].forEach(function (el) {
- sdp.push(makeLine(type, obj, el));
- });
- }
- });
- });
- });
- return sdp.join('\r\n') + '\r\n';
- };
- },{"./grammar":34}],38:[function(require,module,exports){
- module.exports={
- "name": "jssip",
- "title": "JsSIP",
- "description": "the Javascript SIP library",
- "version": "3.3.11",
- "homepage": "https://jssip.net",
- "author": "JosĂŠ Luis MillĂĄn <jmillan@aliax.net> (https://github.com/jmillan)",
- "contributors": [
- "IĂąaki Baz Castillo <ibc@aliax.net> (https://github.com/ibc)"
- ],
- "main": "lib-es5/JsSIP.js",
- "keywords": [
- "sip",
- "websocket",
- "webrtc",
- "node",
- "browser",
- "library"
- ],
- "license": "MIT",
- "repository": {
- "type": "git",
- "url": "https://github.com/versatica/JsSIP.git"
- },
- "bugs": {
- "url": "https://github.com/versatica/JsSIP/issues"
- },
- "dependencies": {
- "debug": "^4.1.1",
- "events": "^3.0.0",
- "sdp-transform": "^2.7.0"
- },
- "devDependencies": {
- "@babel/core": "^7.4.3",
- "@babel/preset-env": "^7.4.3",
- "ansi-colors": "^3.2.4",
- "browserify": "^16.2.3",
- "eslint": "^5.16.0",
- "fancy-log": "^1.3.3",
- "gulp": "^4.0.0",
- "gulp-babel": "^8.0.0",
- "gulp-eslint": "^5.0.0",
- "gulp-expect-file": "^1.0.1",
- "gulp-header": "^2.0.7",
- "gulp-nodeunit-runner": "^0.2.2",
- "gulp-plumber": "^1.2.1",
- "gulp-rename": "^1.4.0",
- "gulp-uglify-es": "^1.0.4",
- "pegjs": "^0.7.0",
- "vinyl-buffer": "^1.0.1",
- "vinyl-source-stream": "^2.0.0"
- },
- "scripts": {
- "lint": "gulp lint",
- "test": "gulp test",
- "prepublishOnly": "gulp babel"
- }
- }
- },{}]},{},[8])(8)
- });
|