1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766 |
- #define IN_LIBXML
- #include "libxml.h"
- #ifdef LIBXML_SCHEMAS_ENABLED
- #include <string.h>
- #include <libxml/xmlmemory.h>
- #include <libxml/parser.h>
- #include <libxml/parserInternals.h>
- #include <libxml/hash.h>
- #include <libxml/uri.h>
- #include <libxml/xmlschemas.h>
- #include <libxml/schemasInternals.h>
- #include <libxml/xmlschemastypes.h>
- #include <libxml/xmlautomata.h>
- #include <libxml/xmlregexp.h>
- #include <libxml/dict.h>
- #include <libxml/encoding.h>
- #include <libxml/xmlIO.h>
- #ifdef LIBXML_PATTERN_ENABLED
- #include <libxml/pattern.h>
- #endif
- #ifdef LIBXML_READER_ENABLED
- #include <libxml/xmlreader.h>
- #endif
- #ifdef DEBUG_IDC
- #ifndef DEBUG_IDC_NODE_TABLE
- #define DEBUG_IDC_NODE_TABLE
- #endif
- #endif
- #define ENABLE_REDEFINE
- #define DUMP_CONTENT_MODEL
- #ifdef LIBXML_READER_ENABLED
- #endif
- #define UNBOUNDED (1 << 30)
- #define TODO \
- xmlGenericError(xmlGenericErrorContext, \
- "Unimplemented block at %s:%d\n", \
- __FILE__, __LINE__);
- #define XML_SCHEMAS_NO_NAMESPACE (const xmlChar *) "##"
- static const xmlChar *xmlSchemaNs = (const xmlChar *)
- "http://www.w3.org/2001/XMLSchema";
- static const xmlChar *xmlSchemaInstanceNs = (const xmlChar *)
- "http://www.w3.org/2001/XMLSchema-instance";
- static const xmlChar *xmlNamespaceNs = (const xmlChar *)
- "http://www.w3.org/2000/xmlns/";
- #define ACTXT_CAST (xmlSchemaAbstractCtxtPtr)
- #define PCTXT_CAST (xmlSchemaParserCtxtPtr)
- #define VCTXT_CAST (xmlSchemaValidCtxtPtr)
- #define WXS_BASIC_CAST (xmlSchemaBasicItemPtr)
- #define WXS_TREE_CAST (xmlSchemaTreeItemPtr)
- #define WXS_PTC_CAST (xmlSchemaParticlePtr)
- #define WXS_TYPE_CAST (xmlSchemaTypePtr)
- #define WXS_ELEM_CAST (xmlSchemaElementPtr)
- #define WXS_ATTR_GROUP_CAST (xmlSchemaAttributeGroupPtr)
- #define WXS_ATTR_CAST (xmlSchemaAttributePtr)
- #define WXS_ATTR_USE_CAST (xmlSchemaAttributeUsePtr)
- #define WXS_ATTR_PROHIB_CAST (xmlSchemaAttributeUseProhibPtr)
- #define WXS_MODEL_GROUPDEF_CAST (xmlSchemaModelGroupDefPtr)
- #define WXS_MODEL_GROUP_CAST (xmlSchemaModelGroupPtr)
- #define WXS_IDC_CAST (xmlSchemaIDCPtr)
- #define WXS_QNAME_CAST (xmlSchemaQNameRefPtr)
- #define WXS_LIST_CAST (xmlSchemaItemListPtr)
- #define WXS_ITEM_NODE(i) xmlSchemaGetComponentNode(WXS_BASIC_CAST (i))
- #define WXS_ITEM_TYPE_NAME(i) xmlSchemaGetComponentTypeStr(WXS_BASIC_CAST (i))
- #define WXS_ELEM_TYPEDEF(e) (e)->subtypes
- #define WXS_SUBST_HEAD(item) (item)->refDecl
- #define WXS_ATTR_TYPEDEF(a) (a)->subtypes
- #define WXS_ATTRUSE_DECL(au) WXS_ATTR_CAST (WXS_ATTR_USE_CAST (au))->attrDecl
- #define WXS_ATTRUSE_TYPEDEF(au) WXS_ATTR_TYPEDEF(WXS_ATTRUSE_DECL( WXS_ATTR_USE_CAST au))
- #define WXS_ATTRUSE_DECL_NAME(au) (WXS_ATTRUSE_DECL(au))->name
- #define WXS_ATTRUSE_DECL_TNS(au) (WXS_ATTRUSE_DECL(au))->targetNamespace
- #define WXS_ATTR_GROUP_HAS_REFS(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS)
- #define WXS_ATTR_GROUP_EXPANDED(ag) ((WXS_ATTR_GROUP_CAST (ag))->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED)
- #define WXS_PARTICLE(p) WXS_PTC_CAST (p)
- #define WXS_PARTICLE_TERM(p) (WXS_PARTICLE(p))->children
- #define WXS_PARTICLE_TERM_AS_ELEM(p) (WXS_ELEM_CAST WXS_PARTICLE_TERM(p))
- #define WXS_PARTICLE_MODEL(p) WXS_MODEL_GROUP_CAST WXS_PARTICLE(p)->children
- #define WXS_MODELGROUPDEF_MODEL(mgd) (WXS_MODEL_GROUP_CAST (mgd))->children
- #define WXS_IS_MODEL_GROUP(i) \
- (((i)->type == XML_SCHEMA_TYPE_SEQUENCE) || \
- ((i)->type == XML_SCHEMA_TYPE_CHOICE) || \
- ((i)->type == XML_SCHEMA_TYPE_ALL))
- #define WXS_MODELGROUP_PARTICLE(mg) WXS_PTC_CAST (mg)->children
- #define WXS_IS_BUCKET_INCREDEF(t) (((t) == XML_SCHEMA_SCHEMA_INCLUDE) || \
- ((t) == XML_SCHEMA_SCHEMA_REDEFINE))
- #define WXS_IS_BUCKET_IMPMAIN(t) (((t) == XML_SCHEMA_SCHEMA_MAIN) || \
- ((t) == XML_SCHEMA_SCHEMA_IMPORT))
- #define WXS_IMPBUCKET(b) ((xmlSchemaImportPtr) (b))
- #define WXS_INCBUCKET(b) ((xmlSchemaIncludePtr) (b))
- #define WXS_IS_ANYTYPE(i) \
- (( (i)->type == XML_SCHEMA_TYPE_BASIC) && \
- ( (WXS_TYPE_CAST (i))->builtInType == XML_SCHEMAS_ANYTYPE))
- #define WXS_IS_COMPLEX(i) \
- (((i)->type == XML_SCHEMA_TYPE_COMPLEX) || \
- ((i)->builtInType == XML_SCHEMAS_ANYTYPE))
- #define WXS_IS_SIMPLE(item) \
- ((item->type == XML_SCHEMA_TYPE_SIMPLE) || \
- ((item->type == XML_SCHEMA_TYPE_BASIC) && \
- (item->builtInType != XML_SCHEMAS_ANYTYPE)))
- #define WXS_IS_ANY_SIMPLE_TYPE(i) \
- (((i)->type == XML_SCHEMA_TYPE_BASIC) && \
- ((i)->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
- #define WXS_IS_RESTRICTION(t) \
- ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION)
- #define WXS_IS_EXTENSION(t) \
- ((t)->flags & XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION)
- #define WXS_IS_TYPE_NOT_FIXED(i) \
- (((i)->type != XML_SCHEMA_TYPE_BASIC) && \
- (((i)->flags & XML_SCHEMAS_TYPE_INTERNAL_RESOLVED) == 0))
- #define WXS_IS_TYPE_NOT_FIXED_1(item) \
- (((item)->type != XML_SCHEMA_TYPE_BASIC) && \
- (((item)->flags & XML_SCHEMAS_TYPE_FIXUP_1) == 0))
- #define WXS_TYPE_IS_GLOBAL(t) ((t)->flags & XML_SCHEMAS_TYPE_GLOBAL)
- #define WXS_TYPE_IS_LOCAL(t) (((t)->flags & XML_SCHEMAS_TYPE_GLOBAL) == 0)
- #define WXS_HAS_COMPLEX_CONTENT(item) \
- ((item->contentType == XML_SCHEMA_CONTENT_MIXED) || \
- (item->contentType == XML_SCHEMA_CONTENT_EMPTY) || \
- (item->contentType == XML_SCHEMA_CONTENT_ELEMENTS))
- #define WXS_HAS_SIMPLE_CONTENT(item) \
- ((item->contentType == XML_SCHEMA_CONTENT_SIMPLE) || \
- (item->contentType == XML_SCHEMA_CONTENT_BASIC))
- #define WXS_HAS_MIXED_CONTENT(item) \
- (item->contentType == XML_SCHEMA_CONTENT_MIXED)
- #define WXS_EMPTIABLE(t) \
- (xmlSchemaIsParticleEmptiable(WXS_PTC_CAST (t)->subtypes))
- #define WXS_TYPE_CONTENTTYPE(t) (t)->subtypes
- #define WXS_TYPE_PARTICLE(t) WXS_PTC_CAST (t)->subtypes
- #define WXS_TYPE_PARTICLE_TERM(t) WXS_PARTICLE_TERM(WXS_TYPE_PARTICLE(t))
- #define WXS_LIST_ITEMTYPE(t) (t)->subtypes
- #define WXS_IS_ATOMIC(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_ATOMIC)
- #define WXS_IS_LIST(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_LIST)
- #define WXS_IS_UNION(t) (t->flags & XML_SCHEMAS_TYPE_VARIETY_UNION)
- #define WXS_CONSTRUCTOR(ctx) (ctx)->constructor
- #define WXS_HAS_BUCKETS(ctx) \
- ( (WXS_CONSTRUCTOR((ctx))->buckets != NULL) && \
- (WXS_CONSTRUCTOR((ctx))->buckets->nbItems > 0) )
- #define WXS_SUBST_GROUPS(ctx) WXS_CONSTRUCTOR((ctx))->substGroups
- #define WXS_BUCKET(ctx) WXS_CONSTRUCTOR((ctx))->bucket
- #define WXS_SCHEMA(ctx) (ctx)->schema
- #define WXS_ADD_LOCAL(ctx, item) \
- xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->locals), 10, item)
- #define WXS_ADD_GLOBAL(ctx, item) \
- xmlSchemaAddItemSize(&(WXS_BUCKET(ctx)->globals), 5, item)
- #define WXS_ADD_PENDING(ctx, item) \
- xmlSchemaAddItemSize(&((ctx)->constructor->pending), 10, item)
- #define WXS_ILIST_IS_EMPTY(l) ((l == NULL) || ((l)->nbItems == 0))
- #define IS_SCHEMA(node, type) \
- ((node != NULL) && (node->ns != NULL) && \
- (xmlStrEqual(node->name, (const xmlChar *) type)) && \
- (xmlStrEqual(node->ns->href, xmlSchemaNs)))
- #define FREE_AND_NULL(str) if ((str) != NULL) { xmlFree((xmlChar *) (str)); str = NULL; }
- #define WXS_ARE_DEFAULT_STR_EQUAL(v1, v2) ((v1) == (v2))
- #define INODE_NILLED(item) (item->flags & XML_SCHEMA_ELEM_INFO_NILLED)
- #define CAN_PARSE_SCHEMA(b) (((b)->doc != NULL) && ((b)->parsed == 0))
- #define HFAILURE if (res == -1) goto exit_failure;
- #define HERROR if (res != 0) goto exit_error;
- #define HSTOP(ctx) if ((ctx)->stop) goto exit;
- #define SUBSET_RESTRICTION 1<<0
- #define SUBSET_EXTENSION 1<<1
- #define SUBSET_SUBSTITUTION 1<<2
- #define SUBSET_LIST 1<<3
- #define SUBSET_UNION 1<<4
- typedef struct _xmlSchemaNodeInfo xmlSchemaNodeInfo;
- typedef xmlSchemaNodeInfo *xmlSchemaNodeInfoPtr;
- typedef struct _xmlSchemaItemList xmlSchemaItemList;
- typedef xmlSchemaItemList *xmlSchemaItemListPtr;
- struct _xmlSchemaItemList {
- void **items;
- int nbItems;
- int sizeItems;
- };
- #define XML_SCHEMA_CTXT_PARSER 1
- #define XML_SCHEMA_CTXT_VALIDATOR 2
- typedef struct _xmlSchemaAbstractCtxt xmlSchemaAbstractCtxt;
- typedef xmlSchemaAbstractCtxt *xmlSchemaAbstractCtxtPtr;
- struct _xmlSchemaAbstractCtxt {
- int type;
- };
- typedef struct _xmlSchemaBucket xmlSchemaBucket;
- typedef xmlSchemaBucket *xmlSchemaBucketPtr;
- #define XML_SCHEMA_SCHEMA_MAIN 0
- #define XML_SCHEMA_SCHEMA_IMPORT 1
- #define XML_SCHEMA_SCHEMA_INCLUDE 2
- #define XML_SCHEMA_SCHEMA_REDEFINE 3
- typedef struct _xmlSchemaSchemaRelation xmlSchemaSchemaRelation;
- typedef xmlSchemaSchemaRelation *xmlSchemaSchemaRelationPtr;
- struct _xmlSchemaSchemaRelation {
- xmlSchemaSchemaRelationPtr next;
- int type;
- const xmlChar *importNamespace;
- xmlSchemaBucketPtr bucket;
- };
- #define XML_SCHEMA_BUCKET_MARKED 1<<0
- #define XML_SCHEMA_BUCKET_COMPS_ADDED 1<<1
- struct _xmlSchemaBucket {
- int type;
- int flags;
- const xmlChar *schemaLocation;
- const xmlChar *origTargetNamespace;
- const xmlChar *targetNamespace;
- xmlDocPtr doc;
- xmlSchemaSchemaRelationPtr relations;
- int located;
- int parsed;
- int imported;
- int preserveDoc;
- xmlSchemaItemListPtr globals;
- xmlSchemaItemListPtr locals;
- };
- typedef struct _xmlSchemaImport xmlSchemaImport;
- typedef xmlSchemaImport *xmlSchemaImportPtr;
- struct _xmlSchemaImport {
- int type;
- int flags;
- const xmlChar *schemaLocation;
-
- const xmlChar *origTargetNamespace;
-
- const xmlChar *targetNamespace;
- xmlDocPtr doc;
-
- xmlSchemaSchemaRelationPtr relations;
- int located;
- int parsed;
- int imported;
- int preserveDoc;
- xmlSchemaItemListPtr globals;
- xmlSchemaItemListPtr locals;
-
- xmlSchemaPtr schema;
- };
- typedef struct _xmlSchemaInclude xmlSchemaInclude;
- typedef xmlSchemaInclude *xmlSchemaIncludePtr;
- struct _xmlSchemaInclude {
- int type;
- int flags;
- const xmlChar *schemaLocation;
- const xmlChar *origTargetNamespace;
- const xmlChar *targetNamespace;
- xmlDocPtr doc;
- xmlSchemaSchemaRelationPtr relations;
- int located;
- int parsed;
- int imported;
- int preserveDoc;
- xmlSchemaItemListPtr globals;
- xmlSchemaItemListPtr locals;
-
- xmlSchemaImportPtr ownerImport;
- };
- typedef struct _xmlSchemaBasicItem xmlSchemaBasicItem;
- typedef xmlSchemaBasicItem *xmlSchemaBasicItemPtr;
- struct _xmlSchemaBasicItem {
- xmlSchemaTypeType type;
- };
- typedef struct _xmlSchemaAnnotItem xmlSchemaAnnotItem;
- typedef xmlSchemaAnnotItem *xmlSchemaAnnotItemPtr;
- struct _xmlSchemaAnnotItem {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- };
- typedef struct _xmlSchemaTreeItem xmlSchemaTreeItem;
- typedef xmlSchemaTreeItem *xmlSchemaTreeItemPtr;
- struct _xmlSchemaTreeItem {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- xmlSchemaTreeItemPtr next;
- xmlSchemaTreeItemPtr children;
- };
- #define XML_SCHEMA_ATTR_USE_FIXED 1<<0
- typedef struct _xmlSchemaAttributeUse xmlSchemaAttributeUse;
- typedef xmlSchemaAttributeUse *xmlSchemaAttributeUsePtr;
- struct _xmlSchemaAttributeUse {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- xmlSchemaAttributeUsePtr next;
-
- xmlSchemaAttributePtr attrDecl;
- int flags;
- xmlNodePtr node;
- int occurs;
- const xmlChar * defValue;
- xmlSchemaValPtr defVal;
- };
- typedef struct _xmlSchemaAttributeUseProhib xmlSchemaAttributeUseProhib;
- typedef xmlSchemaAttributeUseProhib *xmlSchemaAttributeUseProhibPtr;
- struct _xmlSchemaAttributeUseProhib {
- xmlSchemaTypeType type;
- xmlNodePtr node;
- const xmlChar *name;
- const xmlChar *targetNamespace;
- int isRef;
- };
- typedef struct _xmlSchemaRedef xmlSchemaRedef;
- typedef xmlSchemaRedef *xmlSchemaRedefPtr;
- struct _xmlSchemaRedef {
- xmlSchemaRedefPtr next;
- xmlSchemaBasicItemPtr item;
- xmlSchemaBasicItemPtr reference;
- xmlSchemaBasicItemPtr target;
- const xmlChar *refName;
- const xmlChar *refTargetNs;
- xmlSchemaBucketPtr targetBucket;
- };
- typedef struct _xmlSchemaConstructionCtxt xmlSchemaConstructionCtxt;
- typedef xmlSchemaConstructionCtxt *xmlSchemaConstructionCtxtPtr;
- struct _xmlSchemaConstructionCtxt {
- xmlSchemaPtr mainSchema;
- xmlSchemaBucketPtr mainBucket;
- xmlDictPtr dict;
- xmlSchemaItemListPtr buckets;
-
- xmlSchemaBucketPtr bucket;
- xmlSchemaItemListPtr pending;
- xmlHashTablePtr substGroups;
- xmlSchemaRedefPtr redefs;
- xmlSchemaRedefPtr lastRedef;
- };
- #define XML_SCHEMAS_PARSE_ERROR 1
- #define SCHEMAS_PARSE_OPTIONS XML_PARSE_NOENT
- struct _xmlSchemaParserCtxt {
- int type;
- void *errCtxt;
- xmlSchemaValidityErrorFunc error;
- xmlSchemaValidityWarningFunc warning;
- int err;
- int nberrors;
- xmlStructuredErrorFunc serror;
- xmlSchemaConstructionCtxtPtr constructor;
- int ownsConstructor;
-
-
- xmlSchemaPtr schema;
- int counter;
- const xmlChar *URL;
- xmlDocPtr doc;
- int preserve;
- const char *buffer;
- int size;
-
- xmlAutomataPtr am;
- xmlAutomataStatePtr start;
- xmlAutomataStatePtr end;
- xmlAutomataStatePtr state;
- xmlDictPtr dict;
- xmlSchemaTypePtr ctxtType;
- int options;
- xmlSchemaValidCtxtPtr vctxt;
- int isS4S;
- int isRedefine;
- int xsiAssemble;
- int stop;
- const xmlChar *targetNamespace;
- xmlSchemaBucketPtr redefined;
- xmlSchemaRedefPtr redef;
- int redefCounter;
- xmlSchemaItemListPtr attrProhibs;
- };
- typedef struct _xmlSchemaQNameRef xmlSchemaQNameRef;
- typedef xmlSchemaQNameRef *xmlSchemaQNameRefPtr;
- struct _xmlSchemaQNameRef {
- xmlSchemaTypeType type;
- xmlSchemaBasicItemPtr item;
- xmlSchemaTypeType itemType;
- const xmlChar *name;
- const xmlChar *targetNamespace;
- xmlNodePtr node;
- };
- typedef struct _xmlSchemaParticle xmlSchemaParticle;
- typedef xmlSchemaParticle *xmlSchemaParticlePtr;
- struct _xmlSchemaParticle {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- xmlSchemaTreeItemPtr next;
- xmlSchemaTreeItemPtr children;
- int minOccurs;
- int maxOccurs;
- xmlNodePtr node;
- };
- typedef struct _xmlSchemaModelGroup xmlSchemaModelGroup;
- typedef xmlSchemaModelGroup *xmlSchemaModelGroupPtr;
- struct _xmlSchemaModelGroup {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- xmlSchemaTreeItemPtr next;
- xmlSchemaTreeItemPtr children;
- xmlNodePtr node;
- };
- #define XML_SCHEMA_MODEL_GROUP_DEF_MARKED 1<<0
- #define XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED 1<<1
- typedef struct _xmlSchemaModelGroupDef xmlSchemaModelGroupDef;
- typedef xmlSchemaModelGroupDef *xmlSchemaModelGroupDefPtr;
- struct _xmlSchemaModelGroupDef {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- xmlSchemaTreeItemPtr next;
- xmlSchemaTreeItemPtr children;
- const xmlChar *name;
- const xmlChar *targetNamespace;
- xmlNodePtr node;
- int flags;
- };
- typedef struct _xmlSchemaIDC xmlSchemaIDC;
- typedef xmlSchemaIDC *xmlSchemaIDCPtr;
- typedef struct _xmlSchemaIDCSelect xmlSchemaIDCSelect;
- typedef xmlSchemaIDCSelect *xmlSchemaIDCSelectPtr;
- struct _xmlSchemaIDCSelect {
- xmlSchemaIDCSelectPtr next;
- xmlSchemaIDCPtr idc;
- int index;
- const xmlChar *xpath;
- void *xpathComp;
- };
- struct _xmlSchemaIDC {
- xmlSchemaTypeType type;
- xmlSchemaAnnotPtr annot;
- xmlSchemaIDCPtr next;
- xmlNodePtr node;
- const xmlChar *name;
- const xmlChar *targetNamespace;
- xmlSchemaIDCSelectPtr selector;
- xmlSchemaIDCSelectPtr fields;
- int nbFields;
- xmlSchemaQNameRefPtr ref;
- };
- typedef struct _xmlSchemaIDCAug xmlSchemaIDCAug;
- typedef xmlSchemaIDCAug *xmlSchemaIDCAugPtr;
- struct _xmlSchemaIDCAug {
- xmlSchemaIDCAugPtr next;
- xmlSchemaIDCPtr def;
- int keyrefDepth;
- };
- typedef struct _xmlSchemaPSVIIDCKey xmlSchemaPSVIIDCKey;
- typedef xmlSchemaPSVIIDCKey *xmlSchemaPSVIIDCKeyPtr;
- struct _xmlSchemaPSVIIDCKey {
- xmlSchemaTypePtr type;
- xmlSchemaValPtr val;
- };
- typedef struct _xmlSchemaPSVIIDCNode xmlSchemaPSVIIDCNode;
- typedef xmlSchemaPSVIIDCNode *xmlSchemaPSVIIDCNodePtr;
- struct _xmlSchemaPSVIIDCNode {
- xmlNodePtr node;
- xmlSchemaPSVIIDCKeyPtr *keys;
- int nodeLine;
- int nodeQNameID;
- };
- typedef struct _xmlSchemaPSVIIDCBinding xmlSchemaPSVIIDCBinding;
- typedef xmlSchemaPSVIIDCBinding *xmlSchemaPSVIIDCBindingPtr;
- struct _xmlSchemaPSVIIDCBinding {
- xmlSchemaPSVIIDCBindingPtr next;
- xmlSchemaIDCPtr definition;
- xmlSchemaPSVIIDCNodePtr *nodeTable;
- int nbNodes;
- int sizeNodes;
- xmlSchemaItemListPtr dupls;
- };
- #define XPATH_STATE_OBJ_TYPE_IDC_SELECTOR 1
- #define XPATH_STATE_OBJ_TYPE_IDC_FIELD 2
- #define XPATH_STATE_OBJ_MATCHES -2
- #define XPATH_STATE_OBJ_BLOCKED -3
- typedef struct _xmlSchemaIDCMatcher xmlSchemaIDCMatcher;
- typedef xmlSchemaIDCMatcher *xmlSchemaIDCMatcherPtr;
- typedef struct _xmlSchemaIDCStateObj xmlSchemaIDCStateObj;
- typedef xmlSchemaIDCStateObj *xmlSchemaIDCStateObjPtr;
- struct _xmlSchemaIDCStateObj {
- int type;
- xmlSchemaIDCStateObjPtr next;
- int depth;
- int *history;
- int nbHistory;
- int sizeHistory;
- xmlSchemaIDCMatcherPtr matcher;
- xmlSchemaIDCSelectPtr sel;
- void *xpathCtxt;
- };
- #define IDC_MATCHER 0
- struct _xmlSchemaIDCMatcher {
- int type;
- int depth;
- xmlSchemaIDCMatcherPtr next;
- xmlSchemaIDCMatcherPtr nextCached;
- xmlSchemaIDCAugPtr aidc;
- int idcType;
- xmlSchemaPSVIIDCKeyPtr **keySeqs;
- int sizeKeySeqs;
- xmlSchemaItemListPtr targets;
- };
- #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES 1<<0
- #define XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES 1<<1
- #define XML_SCHEMA_ELEM_INFO_NILLED 1<<2
- #define XML_SCHEMA_ELEM_INFO_LOCAL_TYPE 1<<3
- #define XML_SCHEMA_NODE_INFO_VALUE_NEEDED 1<<4
- #define XML_SCHEMA_ELEM_INFO_EMPTY 1<<5
- #define XML_SCHEMA_ELEM_INFO_HAS_CONTENT 1<<6
- #define XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT 1<<7
- #define XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT 1<<8
- #define XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED 1<<9
- #define XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE 1<<10
- struct _xmlSchemaNodeInfo {
- int nodeType;
- xmlNodePtr node;
- int nodeLine;
- const xmlChar *localName;
- const xmlChar *nsName;
- const xmlChar *value;
- xmlSchemaValPtr val;
- xmlSchemaTypePtr typeDef;
- int flags;
- int valNeeded;
- int normVal;
- xmlSchemaElementPtr decl;
- int depth;
- xmlSchemaPSVIIDCBindingPtr idcTable;
- xmlSchemaIDCMatcherPtr idcMatchers;
- xmlRegExecCtxtPtr regexCtxt;
- const xmlChar **nsBindings;
- int nbNsBindings;
- int sizeNsBindings;
- int hasKeyrefs;
- int appliedXPath;
- };
- #define XML_SCHEMAS_ATTR_UNKNOWN 1
- #define XML_SCHEMAS_ATTR_ASSESSED 2
- #define XML_SCHEMAS_ATTR_PROHIBITED 3
- #define XML_SCHEMAS_ATTR_ERR_MISSING 4
- #define XML_SCHEMAS_ATTR_INVALID_VALUE 5
- #define XML_SCHEMAS_ATTR_ERR_NO_TYPE 6
- #define XML_SCHEMAS_ATTR_ERR_FIXED_VALUE 7
- #define XML_SCHEMAS_ATTR_DEFAULT 8
- #define XML_SCHEMAS_ATTR_VALIDATE_VALUE 9
- #define XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL 10
- #define XML_SCHEMAS_ATTR_HAS_ATTR_USE 11
- #define XML_SCHEMAS_ATTR_HAS_ATTR_DECL 12
- #define XML_SCHEMAS_ATTR_WILD_SKIP 13
- #define XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL 14
- #define XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID 15
- #define XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID 16
- #define XML_SCHEMAS_ATTR_META 17
- #define XML_SCHEMA_ATTR_INFO_META_XSI_TYPE 1
- #define XML_SCHEMA_ATTR_INFO_META_XSI_NIL 2
- #define XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC 3
- #define XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC 4
- #define XML_SCHEMA_ATTR_INFO_META_XMLNS 5
- typedef struct _xmlSchemaAttrInfo xmlSchemaAttrInfo;
- typedef xmlSchemaAttrInfo *xmlSchemaAttrInfoPtr;
- struct _xmlSchemaAttrInfo {
- int nodeType;
- xmlNodePtr node;
- int nodeLine;
- const xmlChar *localName;
- const xmlChar *nsName;
- const xmlChar *value;
- xmlSchemaValPtr val;
- xmlSchemaTypePtr typeDef;
- int flags;
- xmlSchemaAttributePtr decl;
- xmlSchemaAttributeUsePtr use;
- int state;
- int metaType;
- const xmlChar *vcValue;
- xmlSchemaNodeInfoPtr parent;
- };
- #define XML_SCHEMA_VALID_CTXT_FLAG_STREAM 1
- struct _xmlSchemaValidCtxt {
- int type;
- void *errCtxt;
- xmlSchemaValidityErrorFunc error;
- xmlSchemaValidityWarningFunc warning;
- xmlStructuredErrorFunc serror;
- xmlSchemaPtr schema;
- xmlDocPtr doc;
- xmlParserInputBufferPtr input;
- xmlCharEncoding enc;
- xmlSAXHandlerPtr sax;
- xmlParserCtxtPtr parserCtxt;
- void *user_data;
- int err;
- int nberrors;
- xmlNodePtr node;
- xmlNodePtr cur;
-
- xmlRegExecCtxtPtr regexp;
- xmlSchemaValPtr value;
- int valueWS;
- int options;
- xmlNodePtr validationRoot;
- xmlSchemaParserCtxtPtr pctxt;
- int xsiAssemble;
- int depth;
- xmlSchemaNodeInfoPtr *elemInfos;
- int sizeElemInfos;
- xmlSchemaNodeInfoPtr inode;
- xmlSchemaIDCAugPtr aidcs;
- xmlSchemaIDCStateObjPtr xpathStates;
- xmlSchemaIDCStateObjPtr xpathStatePool;
- xmlSchemaIDCMatcherPtr idcMatcherCache;
- xmlSchemaPSVIIDCNodePtr *idcNodes;
- int nbIdcNodes;
- int sizeIdcNodes;
- xmlSchemaPSVIIDCKeyPtr *idcKeys;
- int nbIdcKeys;
- int sizeIdcKeys;
- int flags;
- xmlDictPtr dict;
- #ifdef LIBXML_READER_ENABLED
- xmlTextReaderPtr reader;
- #endif
- xmlSchemaAttrInfoPtr *attrInfos;
- int nbAttrInfos;
- int sizeAttrInfos;
- int skipDepth;
- xmlSchemaItemListPtr nodeQNames;
- int hasKeyrefs;
- int createIDCNodeTables;
- int psviExposeIDCNodeTables;
- };
- typedef struct _xmlSchemaSubstGroup xmlSchemaSubstGroup;
- typedef xmlSchemaSubstGroup *xmlSchemaSubstGroupPtr;
- struct _xmlSchemaSubstGroup {
- xmlSchemaElementPtr head;
- xmlSchemaItemListPtr members;
- };
- static int xmlSchemaParseInclude(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node);
- static int xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node);
- static int
- xmlSchemaTypeFixup(xmlSchemaTypePtr type,
- xmlSchemaAbstractCtxtPtr ctxt);
- static const xmlChar *
- xmlSchemaFacetTypeToString(xmlSchemaTypeType type);
- static int
- xmlSchemaParseImport(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node);
- static int
- xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
- xmlSchemaParserCtxtPtr ctxt);
- static void
- xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt);
- static xmlSchemaWhitespaceValueType
- xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type);
- static xmlSchemaTreeItemPtr
- xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, xmlSchemaTypeType type,
- int withParticle);
- static const xmlChar *
- xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item);
- static xmlSchemaTypeLinkPtr
- xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type);
- static void
- xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
- const char *funcName,
- const char *message);
- static int
- xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr ctxt,
- xmlSchemaTypePtr type,
- xmlSchemaTypePtr baseType,
- int subset);
- static void
- xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
- xmlSchemaParserCtxtPtr ctxt);
- static void
- xmlSchemaComponentListFree(xmlSchemaItemListPtr list);
- static xmlSchemaQNameRefPtr
- xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node);
- static const xmlChar *
- xmlSchemaItemTypeToStr(xmlSchemaTypeType type)
- {
- switch (type) {
- case XML_SCHEMA_TYPE_BASIC:
- return(BAD_CAST "simple type definition");
- case XML_SCHEMA_TYPE_SIMPLE:
- return(BAD_CAST "simple type definition");
- case XML_SCHEMA_TYPE_COMPLEX:
- return(BAD_CAST "complex type definition");
- case XML_SCHEMA_TYPE_ELEMENT:
- return(BAD_CAST "element declaration");
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- return(BAD_CAST "attribute use");
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- return(BAD_CAST "attribute declaration");
- case XML_SCHEMA_TYPE_GROUP:
- return(BAD_CAST "model group definition");
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- return(BAD_CAST "attribute group definition");
- case XML_SCHEMA_TYPE_NOTATION:
- return(BAD_CAST "notation declaration");
- case XML_SCHEMA_TYPE_SEQUENCE:
- return(BAD_CAST "model group (sequence)");
- case XML_SCHEMA_TYPE_CHOICE:
- return(BAD_CAST "model group (choice)");
- case XML_SCHEMA_TYPE_ALL:
- return(BAD_CAST "model group (all)");
- case XML_SCHEMA_TYPE_PARTICLE:
- return(BAD_CAST "particle");
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- return(BAD_CAST "unique identity-constraint");
-
- case XML_SCHEMA_TYPE_IDC_KEY:
- return(BAD_CAST "key identity-constraint");
-
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- return(BAD_CAST "keyref identity-constraint");
-
- case XML_SCHEMA_TYPE_ANY:
- return(BAD_CAST "wildcard (any)");
- case XML_SCHEMA_EXTRA_QNAMEREF:
- return(BAD_CAST "[helper component] QName reference");
- case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
- return(BAD_CAST "[helper component] attribute use prohibition");
- default:
- return(BAD_CAST "Not a schema component");
- }
- }
- static const xmlChar *
- xmlSchemaGetComponentTypeStr(xmlSchemaBasicItemPtr item)
- {
- switch (item->type) {
- case XML_SCHEMA_TYPE_BASIC:
- if (WXS_IS_COMPLEX(WXS_TYPE_CAST item))
- return(BAD_CAST "complex type definition");
- else
- return(BAD_CAST "simple type definition");
- default:
- return(xmlSchemaItemTypeToStr(item->type));
- }
- }
- static xmlNodePtr
- xmlSchemaGetComponentNode(xmlSchemaBasicItemPtr item)
- {
- switch (item->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- return (((xmlSchemaElementPtr) item)->node);
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- return (((xmlSchemaAttributePtr) item)->node);
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- return (((xmlSchemaTypePtr) item)->node);
- case XML_SCHEMA_TYPE_ANY:
- case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
- return (((xmlSchemaWildcardPtr) item)->node);
- case XML_SCHEMA_TYPE_PARTICLE:
- return (((xmlSchemaParticlePtr) item)->node);
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL:
- return (((xmlSchemaModelGroupPtr) item)->node);
- case XML_SCHEMA_TYPE_GROUP:
- return (((xmlSchemaModelGroupDefPtr) item)->node);
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- return (((xmlSchemaAttributeGroupPtr) item)->node);
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- return (((xmlSchemaIDCPtr) item)->node);
- case XML_SCHEMA_EXTRA_QNAMEREF:
- return(((xmlSchemaQNameRefPtr) item)->node);
-
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- return (((xmlSchemaAttributeUsePtr) item)->node);
- default:
- return (NULL);
- }
- }
- #if 0
- static xmlSchemaBasicItemPtr
- xmlSchemaGetNextComponent(xmlSchemaBasicItemPtr item)
- {
- switch (item->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- return ((xmlSchemaBasicItemPtr) ((xmlSchemaElementPtr) item)->next);
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributePtr) item)->next);
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- return ((xmlSchemaBasicItemPtr) ((xmlSchemaTypePtr) item)->next);
- case XML_SCHEMA_TYPE_ANY:
- case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
- return (NULL);
- case XML_SCHEMA_TYPE_PARTICLE:
- return ((xmlSchemaBasicItemPtr) ((xmlSchemaParticlePtr) item)->next);
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL:
- return (NULL);
- case XML_SCHEMA_TYPE_GROUP:
- return (NULL);
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- return ((xmlSchemaBasicItemPtr) ((xmlSchemaAttributeGroupPtr) item)->next);
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- return ((xmlSchemaBasicItemPtr) ((xmlSchemaIDCPtr) item)->next);
- default:
- return (NULL);
- }
- }
- #endif
- static const xmlChar*
- xmlSchemaFormatQName(xmlChar **buf,
- const xmlChar *namespaceName,
- const xmlChar *localName)
- {
- FREE_AND_NULL(*buf)
- if (namespaceName != NULL) {
- *buf = xmlStrdup(BAD_CAST "{");
- *buf = xmlStrcat(*buf, namespaceName);
- *buf = xmlStrcat(*buf, BAD_CAST "}");
- }
- if (localName != NULL) {
- if (namespaceName == NULL)
- return(localName);
- *buf = xmlStrcat(*buf, localName);
- } else {
- *buf = xmlStrcat(*buf, BAD_CAST "(NULL)");
- }
- return ((const xmlChar *) *buf);
- }
- static const xmlChar*
- xmlSchemaFormatQNameNs(xmlChar **buf, xmlNsPtr ns, const xmlChar *localName)
- {
- if (ns != NULL)
- return (xmlSchemaFormatQName(buf, ns->href, localName));
- else
- return (xmlSchemaFormatQName(buf, NULL, localName));
- }
- static const xmlChar *
- xmlSchemaGetComponentName(xmlSchemaBasicItemPtr item)
- {
- switch (item->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- return (((xmlSchemaElementPtr) item)->name);
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- return (((xmlSchemaAttributePtr) item)->name);
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- return (((xmlSchemaAttributeGroupPtr) item)->name);
- case XML_SCHEMA_TYPE_BASIC:
- case XML_SCHEMA_TYPE_SIMPLE:
- case XML_SCHEMA_TYPE_COMPLEX:
- return (((xmlSchemaTypePtr) item)->name);
- case XML_SCHEMA_TYPE_GROUP:
- return (((xmlSchemaModelGroupDefPtr) item)->name);
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- return (((xmlSchemaIDCPtr) item)->name);
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- if (WXS_ATTRUSE_DECL(item) != NULL) {
- return(xmlSchemaGetComponentName(
- WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
- } else
- return(NULL);
- case XML_SCHEMA_EXTRA_QNAMEREF:
- return (((xmlSchemaQNameRefPtr) item)->name);
- case XML_SCHEMA_TYPE_NOTATION:
- return (((xmlSchemaNotationPtr) item)->name);
- default:
-
- break;
- }
- return (NULL);
- }
- #define xmlSchemaGetQNameRefName(r) (WXS_QNAME_CAST (r))->name
- #define xmlSchemaGetQNameRefTargetNs(r) (WXS_QNAME_CAST (r))->targetNamespace
- static const xmlChar *
- xmlSchemaGetComponentTargetNs(xmlSchemaBasicItemPtr item)
- {
- switch (item->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- return (((xmlSchemaElementPtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- return (((xmlSchemaAttributePtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- return (((xmlSchemaAttributeGroupPtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_BASIC:
- return (BAD_CAST "http://www.w3.org/2001/XMLSchema");
- case XML_SCHEMA_TYPE_SIMPLE:
- case XML_SCHEMA_TYPE_COMPLEX:
- return (((xmlSchemaTypePtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_GROUP:
- return (((xmlSchemaModelGroupDefPtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- return (((xmlSchemaIDCPtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- if (WXS_ATTRUSE_DECL(item) != NULL) {
- return(xmlSchemaGetComponentTargetNs(
- WXS_BASIC_CAST WXS_ATTRUSE_DECL(item)));
- }
-
- break;
- case XML_SCHEMA_EXTRA_QNAMEREF:
- return (((xmlSchemaQNameRefPtr) item)->targetNamespace);
- case XML_SCHEMA_TYPE_NOTATION:
- return (((xmlSchemaNotationPtr) item)->targetNamespace);
- default:
-
- break;
- }
- return (NULL);
- }
- static const xmlChar*
- xmlSchemaGetComponentQName(xmlChar **buf,
- void *item)
- {
- return (xmlSchemaFormatQName(buf,
- xmlSchemaGetComponentTargetNs((xmlSchemaBasicItemPtr) item),
- xmlSchemaGetComponentName((xmlSchemaBasicItemPtr) item)));
- }
- static const xmlChar*
- xmlSchemaGetComponentDesignation(xmlChar **buf, void *item)
- {
- xmlChar *str = NULL;
- *buf = xmlStrcat(*buf, WXS_ITEM_TYPE_NAME(item));
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str,
- (xmlSchemaBasicItemPtr) item));
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- FREE_AND_NULL(str);
- return(*buf);
- }
- static const xmlChar*
- xmlSchemaGetIDCDesignation(xmlChar **buf, xmlSchemaIDCPtr idc)
- {
- return(xmlSchemaGetComponentDesignation(buf, idc));
- }
- static const xmlChar *
- xmlSchemaWildcardPCToString(int pc)
- {
- switch (pc) {
- case XML_SCHEMAS_ANY_SKIP:
- return (BAD_CAST "skip");
- case XML_SCHEMAS_ANY_LAX:
- return (BAD_CAST "lax");
- case XML_SCHEMAS_ANY_STRICT:
- return (BAD_CAST "strict");
- default:
- return (BAD_CAST "invalid process contents");
- }
- }
- static int
- xmlSchemaGetCanonValueWhtspExt(xmlSchemaValPtr val,
- xmlSchemaWhitespaceValueType ws,
- xmlChar **retValue)
- {
- int list;
- xmlSchemaValType valType;
- const xmlChar *value, *value2 = NULL;
- if ((retValue == NULL) || (val == NULL))
- return (-1);
- list = xmlSchemaValueGetNext(val) ? 1 : 0;
- *retValue = NULL;
- do {
- value = NULL;
- valType = xmlSchemaGetValType(val);
- switch (valType) {
- case XML_SCHEMAS_STRING:
- case XML_SCHEMAS_NORMSTRING:
- case XML_SCHEMAS_ANYSIMPLETYPE:
- value = xmlSchemaValueGetAsString(val);
- if (value != NULL) {
- if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE)
- value2 = xmlSchemaCollapseString(value);
- else if (ws == XML_SCHEMA_WHITESPACE_REPLACE)
- value2 = xmlSchemaWhiteSpaceReplace(value);
- if (value2 != NULL)
- value = value2;
- }
- break;
- default:
- if (xmlSchemaGetCanonValue(val, &value2) == -1) {
- if (value2 != NULL)
- xmlFree((xmlChar *) value2);
- goto internal_error;
- }
- value = value2;
- }
- if (*retValue == NULL)
- if (value == NULL) {
- if (! list)
- *retValue = xmlStrdup(BAD_CAST "");
- } else
- *retValue = xmlStrdup(value);
- else if (value != NULL) {
-
- *retValue = xmlStrcat((xmlChar *) *retValue, BAD_CAST " ");
- *retValue = xmlStrcat((xmlChar *) *retValue, value);
- }
- FREE_AND_NULL(value2)
- val = xmlSchemaValueGetNext(val);
- } while (val != NULL);
- return (0);
- internal_error:
- if (*retValue != NULL)
- xmlFree((xmlChar *) (*retValue));
- if (value2 != NULL)
- xmlFree((xmlChar *) value2);
- return (-1);
- }
- static xmlChar*
- xmlSchemaFormatItemForReport(xmlChar **buf,
- const xmlChar *itemDes,
- xmlSchemaBasicItemPtr item,
- xmlNodePtr itemNode)
- {
- xmlChar *str = NULL;
- int named = 1;
- if (*buf != NULL) {
- xmlFree(*buf);
- *buf = NULL;
- }
- if (itemDes != NULL) {
- *buf = xmlStrdup(itemDes);
- } else if (item != NULL) {
- switch (item->type) {
- case XML_SCHEMA_TYPE_BASIC: {
- xmlSchemaTypePtr type = WXS_TYPE_CAST item;
- if (WXS_IS_ATOMIC(type))
- *buf = xmlStrdup(BAD_CAST "atomic type 'xs:");
- else if (WXS_IS_LIST(type))
- *buf = xmlStrdup(BAD_CAST "list type 'xs:");
- else if (WXS_IS_UNION(type))
- *buf = xmlStrdup(BAD_CAST "union type 'xs:");
- else
- *buf = xmlStrdup(BAD_CAST "simple type 'xs:");
- *buf = xmlStrcat(*buf, type->name);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- break;
- case XML_SCHEMA_TYPE_SIMPLE: {
- xmlSchemaTypePtr type = WXS_TYPE_CAST item;
- if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
- *buf = xmlStrdup(BAD_CAST"");
- } else {
- *buf = xmlStrdup(BAD_CAST "local ");
- }
- if (WXS_IS_ATOMIC(type))
- *buf = xmlStrcat(*buf, BAD_CAST "atomic type");
- else if (WXS_IS_LIST(type))
- *buf = xmlStrcat(*buf, BAD_CAST "list type");
- else if (WXS_IS_UNION(type))
- *buf = xmlStrcat(*buf, BAD_CAST "union type");
- else
- *buf = xmlStrcat(*buf, BAD_CAST "simple type");
- if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, type->name);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- }
- break;
- case XML_SCHEMA_TYPE_COMPLEX: {
- xmlSchemaTypePtr type = WXS_TYPE_CAST item;
- if (type->flags & XML_SCHEMAS_TYPE_GLOBAL)
- *buf = xmlStrdup(BAD_CAST "");
- else
- *buf = xmlStrdup(BAD_CAST "local ");
- *buf = xmlStrcat(*buf, BAD_CAST "complex type");
- if (type->flags & XML_SCHEMAS_TYPE_GLOBAL) {
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, type->name);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- }
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE: {
- xmlSchemaAttributeUsePtr ause;
- ause = WXS_ATTR_USE_CAST item;
- *buf = xmlStrdup(BAD_CAST "attribute use ");
- if (WXS_ATTRUSE_DECL(ause) != NULL) {
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- *buf = xmlStrcat(*buf,
- xmlSchemaGetComponentQName(&str, WXS_ATTRUSE_DECL(ause)));
- FREE_AND_NULL(str)
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- } else {
- *buf = xmlStrcat(*buf, BAD_CAST "(unknown)");
- }
- }
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE: {
- xmlSchemaAttributePtr attr;
- attr = (xmlSchemaAttributePtr) item;
- *buf = xmlStrdup(BAD_CAST "attribute decl.");
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
- attr->targetNamespace, attr->name));
- FREE_AND_NULL(str)
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- xmlSchemaGetComponentDesignation(buf, item);
- break;
- case XML_SCHEMA_TYPE_ELEMENT: {
- xmlSchemaElementPtr elem;
- elem = (xmlSchemaElementPtr) item;
- *buf = xmlStrdup(BAD_CAST "element decl.");
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
- elem->targetNamespace, elem->name));
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- break;
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- if (item->type == XML_SCHEMA_TYPE_IDC_UNIQUE)
- *buf = xmlStrdup(BAD_CAST "unique '");
- else if (item->type == XML_SCHEMA_TYPE_IDC_KEY)
- *buf = xmlStrdup(BAD_CAST "key '");
- else
- *buf = xmlStrdup(BAD_CAST "keyRef '");
- *buf = xmlStrcat(*buf, ((xmlSchemaIDCPtr) item)->name);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- break;
- case XML_SCHEMA_TYPE_ANY:
- case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
- *buf = xmlStrdup(xmlSchemaWildcardPCToString(
- ((xmlSchemaWildcardPtr) item)->processContents));
- *buf = xmlStrcat(*buf, BAD_CAST " wildcard");
- break;
- case XML_SCHEMA_FACET_MININCLUSIVE:
- case XML_SCHEMA_FACET_MINEXCLUSIVE:
- case XML_SCHEMA_FACET_MAXINCLUSIVE:
- case XML_SCHEMA_FACET_MAXEXCLUSIVE:
- case XML_SCHEMA_FACET_TOTALDIGITS:
- case XML_SCHEMA_FACET_FRACTIONDIGITS:
- case XML_SCHEMA_FACET_PATTERN:
- case XML_SCHEMA_FACET_ENUMERATION:
- case XML_SCHEMA_FACET_WHITESPACE:
- case XML_SCHEMA_FACET_LENGTH:
- case XML_SCHEMA_FACET_MAXLENGTH:
- case XML_SCHEMA_FACET_MINLENGTH:
- *buf = xmlStrdup(BAD_CAST "facet '");
- *buf = xmlStrcat(*buf, xmlSchemaFacetTypeToString(item->type));
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- break;
- case XML_SCHEMA_TYPE_GROUP: {
- *buf = xmlStrdup(BAD_CAST "model group def.");
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- FREE_AND_NULL(str)
- }
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL:
- case XML_SCHEMA_TYPE_PARTICLE:
- *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
- break;
- case XML_SCHEMA_TYPE_NOTATION: {
- *buf = xmlStrdup(WXS_ITEM_TYPE_NAME(item));
- *buf = xmlStrcat(*buf, BAD_CAST " '");
- *buf = xmlStrcat(*buf, xmlSchemaGetComponentQName(&str, item));
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- FREE_AND_NULL(str);
- }
- default:
- named = 0;
- }
- } else
- named = 0;
- if ((named == 0) && (itemNode != NULL)) {
- xmlNodePtr elem;
- if (itemNode->type == XML_ATTRIBUTE_NODE)
- elem = itemNode->parent;
- else
- elem = itemNode;
- *buf = xmlStrdup(BAD_CAST "Element '");
- if (elem->ns != NULL) {
- *buf = xmlStrcat(*buf,
- xmlSchemaFormatQName(&str, elem->ns->href, elem->name));
- FREE_AND_NULL(str)
- } else
- *buf = xmlStrcat(*buf, elem->name);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- if ((itemNode != NULL) && (itemNode->type == XML_ATTRIBUTE_NODE)) {
- *buf = xmlStrcat(*buf, BAD_CAST ", attribute '");
- if (itemNode->ns != NULL) {
- *buf = xmlStrcat(*buf, xmlSchemaFormatQName(&str,
- itemNode->ns->href, itemNode->name));
- FREE_AND_NULL(str)
- } else
- *buf = xmlStrcat(*buf, itemNode->name);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- }
- FREE_AND_NULL(str)
- return (*buf);
- }
- static const xmlChar *
- xmlSchemaFormatFacetEnumSet(xmlSchemaAbstractCtxtPtr actxt,
- xmlChar **buf, xmlSchemaTypePtr type)
- {
- xmlSchemaFacetPtr facet;
- xmlSchemaWhitespaceValueType ws;
- xmlChar *value = NULL;
- int res, found = 0;
- if (*buf != NULL)
- xmlFree(*buf);
- *buf = NULL;
- do {
-
- ws = xmlSchemaGetWhiteSpaceFacetValue(type->baseType);
- for (facet = type->facets; facet != NULL; facet = facet->next) {
- if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
- continue;
- found = 1;
- res = xmlSchemaGetCanonValueWhtspExt(facet->val,
- ws, &value);
- if (res == -1) {
- xmlSchemaInternalErr(actxt,
- "xmlSchemaFormatFacetEnumSet",
- "compute the canonical lexical representation");
- if (*buf != NULL)
- xmlFree(*buf);
- *buf = NULL;
- return (NULL);
- }
- if (*buf == NULL)
- *buf = xmlStrdup(BAD_CAST "'");
- else
- *buf = xmlStrcat(*buf, BAD_CAST ", '");
- *buf = xmlStrcat(*buf, BAD_CAST value);
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- if (value != NULL) {
- xmlFree((xmlChar *)value);
- value = NULL;
- }
- }
-
- if (found)
- break;
- type = type->baseType;
- } while ((type != NULL) && (type->type != XML_SCHEMA_TYPE_BASIC));
- return ((const xmlChar *) *buf);
- }
- #if 0
- static void
- xmlSchemaErrMemory(const char *msg)
- {
- __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
- msg);
- }
- #endif
- static void
- xmlSchemaPSimpleErr(const char *msg)
- {
- __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, NULL, NULL,
- msg);
- }
- static void
- xmlSchemaPErrMemory(xmlSchemaParserCtxtPtr ctxt,
- const char *extra, xmlNodePtr node)
- {
- if (ctxt != NULL)
- ctxt->nberrors++;
- __xmlSimpleError(XML_FROM_SCHEMASP, XML_ERR_NO_MEMORY, node, NULL,
- extra);
- }
- static void
- xmlSchemaPErr(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
- const char *msg, const xmlChar * str1, const xmlChar * str2)
- {
- xmlGenericErrorFunc channel = NULL;
- xmlStructuredErrorFunc schannel = NULL;
- void *data = NULL;
- if (ctxt != NULL) {
- ctxt->nberrors++;
- ctxt->err = error;
- channel = ctxt->error;
- data = ctxt->errCtxt;
- schannel = ctxt->serror;
- }
- __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
- error, XML_ERR_ERROR, NULL, 0,
- (const char *) str1, (const char *) str2, NULL, 0, 0,
- msg, str1, str2);
- }
- static void
- xmlSchemaPErr2(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
- xmlNodePtr child, int error,
- const char *msg, const xmlChar * str1, const xmlChar * str2)
- {
- if (child != NULL)
- xmlSchemaPErr(ctxt, child, error, msg, str1, str2);
- else
- xmlSchemaPErr(ctxt, node, error, msg, str1, str2);
- }
- static void
- xmlSchemaPErrExt(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int error,
- const xmlChar * strData1, const xmlChar * strData2,
- const xmlChar * strData3, const char *msg, const xmlChar * str1,
- const xmlChar * str2, const xmlChar * str3, const xmlChar * str4,
- const xmlChar * str5)
- {
- xmlGenericErrorFunc channel = NULL;
- xmlStructuredErrorFunc schannel = NULL;
- void *data = NULL;
- if (ctxt != NULL) {
- ctxt->nberrors++;
- ctxt->err = error;
- channel = ctxt->error;
- data = ctxt->errCtxt;
- schannel = ctxt->serror;
- }
- __xmlRaiseError(schannel, channel, data, ctxt, node, XML_FROM_SCHEMASP,
- error, XML_ERR_ERROR, NULL, 0,
- (const char *) strData1, (const char *) strData2,
- (const char *) strData3, 0, 0, msg, str1, str2,
- str3, str4, str5);
- }
- static void
- xmlSchemaVErrMemory(xmlSchemaValidCtxtPtr ctxt,
- const char *extra, xmlNodePtr node)
- {
- if (ctxt != NULL) {
- ctxt->nberrors++;
- ctxt->err = XML_SCHEMAV_INTERNAL;
- }
- __xmlSimpleError(XML_FROM_SCHEMASV, XML_ERR_NO_MEMORY, node, NULL,
- extra);
- }
- static void
- xmlSchemaPSimpleInternalErr(xmlNodePtr node,
- const char *msg, const xmlChar *str)
- {
- __xmlSimpleError(XML_FROM_SCHEMASP, XML_SCHEMAP_INTERNAL, node,
- msg, (const char *) str);
- }
- #define WXS_ERROR_TYPE_ERROR 1
- #define WXS_ERROR_TYPE_WARNING 2
- static void
- xmlSchemaErr4Line(xmlSchemaAbstractCtxtPtr ctxt,
- xmlErrorLevel errorLevel,
- int error, xmlNodePtr node, int line, const char *msg,
- const xmlChar *str1, const xmlChar *str2,
- const xmlChar *str3, const xmlChar *str4)
- {
- xmlStructuredErrorFunc schannel = NULL;
- xmlGenericErrorFunc channel = NULL;
- void *data = NULL;
- if (ctxt != NULL) {
- if (ctxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctxt;
- const char *file = NULL;
- if (errorLevel != XML_ERR_WARNING) {
- vctxt->nberrors++;
- vctxt->err = error;
- channel = vctxt->error;
- } else {
- channel = vctxt->warning;
- }
- schannel = vctxt->serror;
- data = vctxt->errCtxt;
-
- if (line == 0) {
- if ((node == NULL) &&
- (vctxt->depth >= 0) &&
- (vctxt->inode != NULL)) {
- node = vctxt->inode->node;
- }
-
- if ((node == NULL) &&
- (vctxt->parserCtxt != NULL) &&
- (vctxt->parserCtxt->input != NULL)) {
- file = vctxt->parserCtxt->input->filename;
- line = vctxt->parserCtxt->input->line;
- }
- } else {
-
- node = NULL;
-
- if (vctxt->doc != NULL)
- file = (const char *) vctxt->doc->URL;
- else if ((vctxt->parserCtxt != NULL) &&
- (vctxt->parserCtxt->input != NULL))
- file = vctxt->parserCtxt->input->filename;
- }
- __xmlRaiseError(schannel, channel, data, ctxt,
- node, XML_FROM_SCHEMASV,
- error, errorLevel, file, line,
- (const char *) str1, (const char *) str2,
- (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
- } else if (ctxt->type == XML_SCHEMA_CTXT_PARSER) {
- xmlSchemaParserCtxtPtr pctxt = (xmlSchemaParserCtxtPtr) ctxt;
- if (errorLevel != XML_ERR_WARNING) {
- pctxt->nberrors++;
- pctxt->err = error;
- channel = pctxt->error;
- } else {
- channel = pctxt->warning;
- }
- schannel = pctxt->serror;
- data = pctxt->errCtxt;
- __xmlRaiseError(schannel, channel, data, ctxt,
- node, XML_FROM_SCHEMASP, error,
- errorLevel, NULL, 0,
- (const char *) str1, (const char *) str2,
- (const char *) str3, 0, 0, msg, str1, str2, str3, str4);
- } else {
- TODO
- }
- }
- }
- static void
- xmlSchemaErr3(xmlSchemaAbstractCtxtPtr actxt,
- int error, xmlNodePtr node, const char *msg,
- const xmlChar *str1, const xmlChar *str2, const xmlChar *str3)
- {
- xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
- msg, str1, str2, str3, NULL);
- }
- static void
- xmlSchemaErr4(xmlSchemaAbstractCtxtPtr actxt,
- int error, xmlNodePtr node, const char *msg,
- const xmlChar *str1, const xmlChar *str2,
- const xmlChar *str3, const xmlChar *str4)
- {
- xmlSchemaErr4Line(actxt, XML_ERR_ERROR, error, node, 0,
- msg, str1, str2, str3, str4);
- }
- static void
- xmlSchemaErr(xmlSchemaAbstractCtxtPtr actxt,
- int error, xmlNodePtr node, const char *msg,
- const xmlChar *str1, const xmlChar *str2)
- {
- xmlSchemaErr4(actxt, error, node, msg, str1, str2, NULL, NULL);
- }
- static xmlChar *
- xmlSchemaFormatNodeForError(xmlChar ** msg,
- xmlSchemaAbstractCtxtPtr actxt,
- xmlNodePtr node)
- {
- xmlChar *str = NULL;
- *msg = NULL;
- if ((node != NULL) &&
- (node->type != XML_ELEMENT_NODE) &&
- (node->type != XML_ATTRIBUTE_NODE))
- {
-
- *msg = xmlStrdup(BAD_CAST "");
- return(*msg);
- }
- if (node != NULL) {
-
- if (node->type == XML_ATTRIBUTE_NODE) {
- xmlNodePtr elem = node->parent;
- *msg = xmlStrdup(BAD_CAST "Element '");
- if (elem->ns != NULL)
- *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
- elem->ns->href, elem->name));
- else
- *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
- NULL, elem->name));
- FREE_AND_NULL(str);
- *msg = xmlStrcat(*msg, BAD_CAST "', ");
- *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
- } else {
- *msg = xmlStrdup(BAD_CAST "Element '");
- }
- if (node->ns != NULL)
- *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
- node->ns->href, node->name));
- else
- *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
- NULL, node->name));
- FREE_AND_NULL(str);
- *msg = xmlStrcat(*msg, BAD_CAST "': ");
- } else if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) actxt;
-
- if (vctxt->inode->nodeType == XML_ATTRIBUTE_NODE) {
- xmlSchemaNodeInfoPtr ielem =
- vctxt->elemInfos[vctxt->depth];
- *msg = xmlStrdup(BAD_CAST "Element '");
- *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
- ielem->nsName, ielem->localName));
- FREE_AND_NULL(str);
- *msg = xmlStrcat(*msg, BAD_CAST "', ");
- *msg = xmlStrcat(*msg, BAD_CAST "attribute '");
- } else {
- *msg = xmlStrdup(BAD_CAST "Element '");
- }
- *msg = xmlStrcat(*msg, xmlSchemaFormatQName(&str,
- vctxt->inode->nsName, vctxt->inode->localName));
- FREE_AND_NULL(str);
- *msg = xmlStrcat(*msg, BAD_CAST "': ");
- } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
-
- *msg = xmlStrdup(BAD_CAST "");
- } else {
- TODO
- return (NULL);
- }
-
- #if 0
- if ((type != NULL) && (xmlSchemaIsGlobalItem(type))) {
- *msg = xmlStrcat(*msg, BAD_CAST " [");
- *msg = xmlStrcat(*msg, xmlSchemaFormatItemForReport(&str,
- NULL, type, NULL, 0));
- FREE_AND_NULL(str)
- *msg = xmlStrcat(*msg, BAD_CAST "]");
- }
- #endif
- return (*msg);
- }
- static void
- xmlSchemaInternalErr2(xmlSchemaAbstractCtxtPtr actxt,
- const char *funcName,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2)
- {
- xmlChar *msg = NULL;
- if (actxt == NULL)
- return;
- msg = xmlStrdup(BAD_CAST "Internal error: ");
- msg = xmlStrcat(msg, BAD_CAST funcName);
- msg = xmlStrcat(msg, BAD_CAST ", ");
- msg = xmlStrcat(msg, BAD_CAST message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR)
- xmlSchemaErr(actxt, XML_SCHEMAV_INTERNAL, NULL,
- (const char *) msg, str1, str2);
- else if (actxt->type == XML_SCHEMA_CTXT_PARSER)
- xmlSchemaErr(actxt, XML_SCHEMAP_INTERNAL, NULL,
- (const char *) msg, str1, str2);
- FREE_AND_NULL(msg)
- }
- static void
- xmlSchemaInternalErr(xmlSchemaAbstractCtxtPtr actxt,
- const char *funcName,
- const char *message)
- {
- xmlSchemaInternalErr2(actxt, funcName, message, NULL, NULL);
- }
- #if 0
- static void
- xmlSchemaPInternalErr(xmlSchemaParserCtxtPtr pctxt,
- const char *funcName,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2)
- {
- xmlSchemaInternalErr2(ACTXT_CAST pctxt, funcName, message,
- str1, str2);
- }
- #endif
- static void
- xmlSchemaCustomErr4(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlNodePtr node,
- xmlSchemaBasicItemPtr item,
- const char *message,
- const xmlChar *str1, const xmlChar *str2,
- const xmlChar *str3, const xmlChar *str4)
- {
- xmlChar *msg = NULL;
- if ((node == NULL) && (item != NULL) &&
- (actxt->type == XML_SCHEMA_CTXT_PARSER)) {
- node = WXS_ITEM_NODE(item);
- xmlSchemaFormatItemForReport(&msg, NULL, item, NULL);
- msg = xmlStrcat(msg, BAD_CAST ": ");
- } else
- xmlSchemaFormatNodeForError(&msg, actxt, node);
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- xmlSchemaErr4(actxt, error, node,
- (const char *) msg, str1, str2, str3, str4);
- FREE_AND_NULL(msg)
- }
- static void
- xmlSchemaCustomErr(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlNodePtr node,
- xmlSchemaBasicItemPtr item,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2)
- {
- xmlSchemaCustomErr4(actxt, error, node, item,
- message, str1, str2, NULL, NULL);
- }
- static void
- xmlSchemaCustomWarning(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlNodePtr node,
- xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2,
- const xmlChar *str3)
- {
- xmlChar *msg = NULL;
- xmlSchemaFormatNodeForError(&msg, actxt, node);
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
-
- xmlSchemaErr4Line(actxt, XML_ERR_WARNING, error, node, 0,
- (const char *) msg, str1, str2, str3, NULL);
- FREE_AND_NULL(msg)
- }
- static void
- xmlSchemaKeyrefErr(xmlSchemaValidCtxtPtr vctxt,
- xmlParserErrors error,
- xmlSchemaPSVIIDCNodePtr idcNode,
- xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2)
- {
- xmlChar *msg = NULL, *qname = NULL;
- msg = xmlStrdup(BAD_CAST "Element '%s': ");
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- xmlSchemaErr4Line(ACTXT_CAST vctxt, XML_ERR_ERROR,
- error, NULL, idcNode->nodeLine, (const char *) msg,
- xmlSchemaFormatQName(&qname,
- vctxt->nodeQNames->items[idcNode->nodeQNameID +1],
- vctxt->nodeQNames->items[idcNode->nodeQNameID]),
- str1, str2, NULL);
- FREE_AND_NULL(qname);
- FREE_AND_NULL(msg);
- }
- static int
- xmlSchemaEvalErrorNodeType(xmlSchemaAbstractCtxtPtr actxt,
- xmlNodePtr node)
- {
- if (node != NULL)
- return (node->type);
- if ((actxt->type == XML_SCHEMA_CTXT_VALIDATOR) &&
- (((xmlSchemaValidCtxtPtr) actxt)->inode != NULL))
- return ( ((xmlSchemaValidCtxtPtr) actxt)->inode->nodeType);
- return (-1);
- }
- static int
- xmlSchemaIsGlobalItem(xmlSchemaTypePtr item)
- {
- switch (item->type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- if (item->flags & XML_SCHEMAS_TYPE_GLOBAL)
- return(1);
- break;
- case XML_SCHEMA_TYPE_GROUP:
- return (1);
- case XML_SCHEMA_TYPE_ELEMENT:
- if ( ((xmlSchemaElementPtr) item)->flags &
- XML_SCHEMAS_ELEM_GLOBAL)
- return(1);
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- if ( ((xmlSchemaAttributePtr) item)->flags &
- XML_SCHEMAS_ATTR_GLOBAL)
- return(1);
- break;
-
- default:
- return(1);
- }
- return (0);
- }
- static void
- xmlSchemaSimpleTypeErr(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlNodePtr node,
- const xmlChar *value,
- xmlSchemaTypePtr type,
- int displayValue)
- {
- xmlChar *msg = NULL;
- xmlSchemaFormatNodeForError(&msg, actxt, node);
- if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
- XML_ATTRIBUTE_NODE))
- msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
- else
- msg = xmlStrcat(msg, BAD_CAST "The character content is not a valid "
- "value of ");
- if (! xmlSchemaIsGlobalItem(type))
- msg = xmlStrcat(msg, BAD_CAST "the local ");
- else
- msg = xmlStrcat(msg, BAD_CAST "the ");
- if (WXS_IS_ATOMIC(type))
- msg = xmlStrcat(msg, BAD_CAST "atomic type");
- else if (WXS_IS_LIST(type))
- msg = xmlStrcat(msg, BAD_CAST "list type");
- else if (WXS_IS_UNION(type))
- msg = xmlStrcat(msg, BAD_CAST "union type");
- if (xmlSchemaIsGlobalItem(type)) {
- xmlChar *str = NULL;
- msg = xmlStrcat(msg, BAD_CAST " '");
- if (type->builtInType != 0) {
- msg = xmlStrcat(msg, BAD_CAST "xs:");
- msg = xmlStrcat(msg, type->name);
- } else
- msg = xmlStrcat(msg,
- xmlSchemaFormatQName(&str,
- type->targetNamespace, type->name));
- msg = xmlStrcat(msg, BAD_CAST "'");
- FREE_AND_NULL(str);
- }
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- if (displayValue || (xmlSchemaEvalErrorNodeType(actxt, node) ==
- XML_ATTRIBUTE_NODE))
- xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
- else
- xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
- FREE_AND_NULL(msg)
- }
- static const xmlChar *
- xmlSchemaFormatErrorNodeQName(xmlChar ** str,
- xmlSchemaNodeInfoPtr ni,
- xmlNodePtr node)
- {
- if (node != NULL) {
- if (node->ns != NULL)
- return (xmlSchemaFormatQName(str, node->ns->href, node->name));
- else
- return (xmlSchemaFormatQName(str, NULL, node->name));
- } else if (ni != NULL)
- return (xmlSchemaFormatQName(str, ni->nsName, ni->localName));
- return (NULL);
- }
- static void
- xmlSchemaIllegalAttrErr(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlSchemaAttrInfoPtr ni,
- xmlNodePtr node)
- {
- xmlChar *msg = NULL, *str = NULL;
- xmlSchemaFormatNodeForError(&msg, actxt, node);
- msg = xmlStrcat(msg, BAD_CAST "The attribute '%s' is not allowed.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg,
- xmlSchemaFormatErrorNodeQName(&str, (xmlSchemaNodeInfoPtr) ni, node),
- NULL);
- FREE_AND_NULL(str)
- FREE_AND_NULL(msg)
- }
- static void
- xmlSchemaComplexTypeErr(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlNodePtr node,
- xmlSchemaTypePtr type ATTRIBUTE_UNUSED,
- const char *message,
- int nbval,
- int nbneg,
- xmlChar **values)
- {
- xmlChar *str = NULL, *msg = NULL;
- xmlChar *localName, *nsName;
- const xmlChar *cur, *end;
- int i;
- xmlSchemaFormatNodeForError(&msg, actxt, node);
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".");
-
- if (nbval + nbneg > 0) {
- if (nbval + nbneg > 1) {
- str = xmlStrdup(BAD_CAST " Expected is one of ( ");
- } else
- str = xmlStrdup(BAD_CAST " Expected is ( ");
- nsName = NULL;
- for (i = 0; i < nbval + nbneg; i++) {
- cur = values[i];
- if (cur == NULL)
- continue;
- if ((cur[0] == 'n') && (cur[1] == 'o') && (cur[2] == 't') &&
- (cur[3] == ' ')) {
- cur += 4;
- str = xmlStrcat(str, BAD_CAST "##other");
- }
-
- localName = NULL;
- end = cur;
- if (*end == '*') {
- localName = xmlStrdup(BAD_CAST "*");
- end++;
- } else {
- while ((*end != 0) && (*end != '|'))
- end++;
- localName = xmlStrncat(localName, BAD_CAST cur, end - cur);
- }
- if (*end != 0) {
- end++;
-
- if ((nbneg == 0) || (*end != '*') || (*localName != '*')) {
-
- cur = end;
- if (*end == '*') {
- nsName = xmlStrdup(BAD_CAST "{*}");
- } else {
- while (*end != 0)
- end++;
- if (i >= nbval)
- nsName = xmlStrdup(BAD_CAST "{##other:");
- else
- nsName = xmlStrdup(BAD_CAST "{");
- nsName = xmlStrncat(nsName, BAD_CAST cur, end - cur);
- nsName = xmlStrcat(nsName, BAD_CAST "}");
- }
- str = xmlStrcat(str, BAD_CAST nsName);
- FREE_AND_NULL(nsName)
- } else {
- FREE_AND_NULL(localName);
- continue;
- }
- }
- str = xmlStrcat(str, BAD_CAST localName);
- FREE_AND_NULL(localName);
- if (i < nbval + nbneg -1)
- str = xmlStrcat(str, BAD_CAST ", ");
- }
- str = xmlStrcat(str, BAD_CAST " ).\n");
- msg = xmlStrcat(msg, BAD_CAST str);
- FREE_AND_NULL(str)
- } else
- msg = xmlStrcat(msg, BAD_CAST "\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
- xmlFree(msg);
- }
- static void
- xmlSchemaFacetErr(xmlSchemaAbstractCtxtPtr actxt,
- xmlParserErrors error,
- xmlNodePtr node,
- const xmlChar *value,
- unsigned long length,
- xmlSchemaTypePtr type,
- xmlSchemaFacetPtr facet,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2)
- {
- xmlChar *str = NULL, *msg = NULL;
- xmlSchemaTypeType facetType;
- int nodeType = xmlSchemaEvalErrorNodeType(actxt, node);
- xmlSchemaFormatNodeForError(&msg, actxt, node);
- if (error == XML_SCHEMAV_CVC_ENUMERATION_VALID) {
- facetType = XML_SCHEMA_FACET_ENUMERATION;
-
- } else
- facetType = facet->type;
- msg = xmlStrcat(msg, BAD_CAST "[");
- msg = xmlStrcat(msg, BAD_CAST "facet '");
- msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facetType));
- msg = xmlStrcat(msg, BAD_CAST "'] ");
- if (message == NULL) {
-
- if ((facetType == XML_SCHEMA_FACET_LENGTH) ||
- (facetType == XML_SCHEMA_FACET_MINLENGTH) ||
- (facetType == XML_SCHEMA_FACET_MAXLENGTH)) {
- char len[25], actLen[25];
-
- if (nodeType == XML_ATTRIBUTE_NODE)
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' has a length of '%s'; ");
- else
- msg = xmlStrcat(msg, BAD_CAST "The value has a length of '%s'; ");
- snprintf(len, 24, "%lu", xmlSchemaGetFacetValueAsULong(facet));
- snprintf(actLen, 24, "%lu", length);
- if (facetType == XML_SCHEMA_FACET_LENGTH)
- msg = xmlStrcat(msg,
- BAD_CAST "this differs from the allowed length of '%s'.\n");
- else if (facetType == XML_SCHEMA_FACET_MAXLENGTH)
- msg = xmlStrcat(msg,
- BAD_CAST "this exceeds the allowed maximum length of '%s'.\n");
- else if (facetType == XML_SCHEMA_FACET_MINLENGTH)
- msg = xmlStrcat(msg,
- BAD_CAST "this underruns the allowed minimum length of '%s'.\n");
- if (nodeType == XML_ATTRIBUTE_NODE)
- xmlSchemaErr3(actxt, error, node, (const char *) msg,
- value, (const xmlChar *) actLen, (const xmlChar *) len);
- else
- xmlSchemaErr(actxt, error, node, (const char *) msg,
- (const xmlChar *) actLen, (const xmlChar *) len);
- } else if (facetType == XML_SCHEMA_FACET_ENUMERATION) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not an element "
- "of the set {%s}.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value,
- xmlSchemaFormatFacetEnumSet(actxt, &str, type));
- } else if (facetType == XML_SCHEMA_FACET_PATTERN) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not accepted "
- "by the pattern '%s'.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value,
- facet->value);
- } else if (facetType == XML_SCHEMA_FACET_MININCLUSIVE) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' is less than the "
- "minimum value allowed ('%s').\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value,
- facet->value);
- } else if (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' is greater than the "
- "maximum value allowed ('%s').\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value,
- facet->value);
- } else if (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be greater than "
- "'%s'.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value,
- facet->value);
- } else if (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' must be less than "
- "'%s'.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value,
- facet->value);
- } else if (facetType == XML_SCHEMA_FACET_TOTALDIGITS) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more "
- "digits than are allowed ('%s').\n");
- xmlSchemaErr(actxt, error, node, (const char*) msg, value,
- facet->value);
- } else if (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' has more fractional "
- "digits than are allowed ('%s').\n");
- xmlSchemaErr(actxt, error, node, (const char*) msg, value,
- facet->value);
- } else if (nodeType == XML_ATTRIBUTE_NODE) {
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not facet-valid.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, value, NULL);
- } else {
- msg = xmlStrcat(msg, BAD_CAST "The value is not facet-valid.\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, NULL, NULL);
- }
- } else {
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- xmlSchemaErr(actxt, error, node, (const char *) msg, str1, str2);
- }
- FREE_AND_NULL(str)
- xmlFree(msg);
- }
- #define VERROR(err, type, msg) \
- xmlSchemaCustomErr(ACTXT_CAST vctxt, err, NULL, type, msg, NULL, NULL);
- #define VERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST vctxt, func, msg);
- #define PERROR_INT(func, msg) xmlSchemaInternalErr(ACTXT_CAST pctxt, func, msg);
- #define PERROR_INT2(func, msg) xmlSchemaInternalErr(ACTXT_CAST ctxt, func, msg);
- #define AERROR_INT(func, msg) xmlSchemaInternalErr(actxt, func, msg);
- static void
- xmlSchemaPMissingAttrErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr ownerItem,
- xmlNodePtr ownerElem,
- const char *name,
- const char *message)
- {
- xmlChar *des = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
- if (message != NULL)
- xmlSchemaPErr(ctxt, ownerElem, error, "%s: %s.\n", BAD_CAST des, BAD_CAST message);
- else
- xmlSchemaPErr(ctxt, ownerElem, error,
- "%s: The attribute '%s' is required but missing.\n",
- BAD_CAST des, BAD_CAST name);
- FREE_AND_NULL(des);
- }
- static void
- xmlSchemaPResCompAttrErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr ownerItem,
- xmlNodePtr ownerElem,
- const char *name,
- const xmlChar *refName,
- const xmlChar *refURI,
- xmlSchemaTypeType refType,
- const char *refTypeStr)
- {
- xmlChar *des = NULL, *strA = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
- if (refTypeStr == NULL)
- refTypeStr = (const char *) xmlSchemaItemTypeToStr(refType);
- xmlSchemaPErrExt(ctxt, ownerElem, error,
- NULL, NULL, NULL,
- "%s, attribute '%s': The QName value '%s' does not resolve to a(n) "
- "%s.\n", BAD_CAST des, BAD_CAST name,
- xmlSchemaFormatQName(&strA, refURI, refName),
- BAD_CAST refTypeStr, NULL);
- FREE_AND_NULL(des)
- FREE_AND_NULL(strA)
- }
- static void
- xmlSchemaPCustomAttrErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlChar **ownerDes,
- xmlSchemaBasicItemPtr ownerItem,
- xmlAttrPtr attr,
- const char *msg)
- {
- xmlChar *des = NULL;
- if (ownerDes == NULL)
- xmlSchemaFormatItemForReport(&des, NULL, ownerItem, attr->parent);
- else if (*ownerDes == NULL) {
- xmlSchemaFormatItemForReport(ownerDes, NULL, ownerItem, attr->parent);
- des = *ownerDes;
- } else
- des = *ownerDes;
- if (attr == NULL) {
- xmlSchemaPErrExt(ctxt, NULL, error, NULL, NULL, NULL,
- "%s, attribute '%s': %s.\n",
- BAD_CAST des, (const xmlChar *) "Unknown",
- (const xmlChar *) msg, NULL, NULL);
- } else {
- xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
- "%s, attribute '%s': %s.\n",
- BAD_CAST des, attr->name, (const xmlChar *) msg, NULL, NULL);
- }
- if (ownerDes == NULL)
- FREE_AND_NULL(des);
- }
- static void
- xmlSchemaPIllegalAttrErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr ownerComp ATTRIBUTE_UNUSED,
- xmlAttrPtr attr)
- {
- xmlChar *strA = NULL, *strB = NULL;
- xmlSchemaFormatNodeForError(&strA, ACTXT_CAST ctxt, attr->parent);
- xmlSchemaErr4(ACTXT_CAST ctxt, error, (xmlNodePtr) attr,
- "%sThe attribute '%s' is not allowed.\n", BAD_CAST strA,
- xmlSchemaFormatQNameNs(&strB, attr->ns, attr->name),
- NULL, NULL);
- FREE_AND_NULL(strA);
- FREE_AND_NULL(strB);
- }
- static void
- xmlSchemaPCustomErrExt(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr item,
- xmlNodePtr itemElem,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2,
- const xmlChar *str3)
- {
- xmlChar *des = NULL, *msg = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, item, itemElem);
- msg = xmlStrdup(BAD_CAST "%s: ");
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- if ((itemElem == NULL) && (item != NULL))
- itemElem = WXS_ITEM_NODE(item);
- xmlSchemaPErrExt(ctxt, itemElem, error, NULL, NULL, NULL,
- (const char *) msg, BAD_CAST des, str1, str2, str3, NULL);
- FREE_AND_NULL(des);
- FREE_AND_NULL(msg);
- }
- static void
- xmlSchemaPCustomErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr item,
- xmlNodePtr itemElem,
- const char *message,
- const xmlChar *str1)
- {
- xmlSchemaPCustomErrExt(ctxt, error, item, itemElem, message,
- str1, NULL, NULL);
- }
- static void
- xmlSchemaPAttrUseErr4(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlNodePtr node,
- xmlSchemaBasicItemPtr ownerItem,
- const xmlSchemaAttributeUsePtr attruse,
- const char *message,
- const xmlChar *str1, const xmlChar *str2,
- const xmlChar *str3,const xmlChar *str4)
- {
- xmlChar *str = NULL, *msg = NULL;
- xmlSchemaFormatItemForReport(&msg, NULL, ownerItem, NULL);
- msg = xmlStrcat(msg, BAD_CAST ", ");
- msg = xmlStrcat(msg,
- BAD_CAST xmlSchemaFormatItemForReport(&str, NULL,
- WXS_BASIC_CAST attruse, NULL));
- FREE_AND_NULL(str);
- msg = xmlStrcat(msg, BAD_CAST ": ");
- msg = xmlStrcat(msg, (const xmlChar *) message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- xmlSchemaErr4(ACTXT_CAST ctxt, error, node,
- (const char *) msg, str1, str2, str3, str4);
- xmlFree(msg);
- }
- static void
- xmlSchemaPIllegalFacetAtomicErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaTypePtr type,
- xmlSchemaTypePtr baseType,
- xmlSchemaFacetPtr facet)
- {
- xmlChar *des = NULL, *strT = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type, type->node);
- xmlSchemaPErrExt(ctxt, type->node, error, NULL, NULL, NULL,
- "%s: The facet '%s' is not allowed on types derived from the "
- "type %s.\n",
- BAD_CAST des, xmlSchemaFacetTypeToString(facet->type),
- xmlSchemaFormatItemForReport(&strT, NULL, WXS_BASIC_CAST baseType, NULL),
- NULL, NULL);
- FREE_AND_NULL(des);
- FREE_AND_NULL(strT);
- }
- static void
- xmlSchemaPIllegalFacetListUnionErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaTypePtr type,
- xmlSchemaFacetPtr facet)
- {
- xmlChar *des = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST type,
- type->node);
- xmlSchemaPErr(ctxt, type->node, error,
- "%s: The facet '%s' is not allowed.\n",
- BAD_CAST des, xmlSchemaFacetTypeToString(facet->type));
- FREE_AND_NULL(des);
- }
- static void
- xmlSchemaPMutualExclAttrErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr ownerItem,
- xmlAttrPtr attr,
- const char *name1,
- const char *name2)
- {
- xmlChar *des = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, WXS_BASIC_CAST ownerItem, attr->parent);
- xmlSchemaPErrExt(ctxt, (xmlNodePtr) attr, error, NULL, NULL, NULL,
- "%s: The attributes '%s' and '%s' are mutually exclusive.\n",
- BAD_CAST des, BAD_CAST name1, BAD_CAST name2, NULL, NULL);
- FREE_AND_NULL(des);
- }
- static void
- xmlSchemaPSimpleTypeErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr ownerItem ATTRIBUTE_UNUSED,
- xmlNodePtr node,
- xmlSchemaTypePtr type,
- const char *expected,
- const xmlChar *value,
- const char *message,
- const xmlChar *str1,
- const xmlChar *str2)
- {
- xmlChar *msg = NULL;
- xmlSchemaFormatNodeForError(&msg, ACTXT_CAST ctxt, node);
- if (message == NULL) {
-
- if (type != NULL) {
- if (node->type == XML_ATTRIBUTE_NODE)
- msg = xmlStrcat(msg, BAD_CAST "'%s' is not a valid value of ");
- else
- msg = xmlStrcat(msg, BAD_CAST "The character content is not a "
- "valid value of ");
- if (! xmlSchemaIsGlobalItem(type))
- msg = xmlStrcat(msg, BAD_CAST "the local ");
- else
- msg = xmlStrcat(msg, BAD_CAST "the ");
- if (WXS_IS_ATOMIC(type))
- msg = xmlStrcat(msg, BAD_CAST "atomic type");
- else if (WXS_IS_LIST(type))
- msg = xmlStrcat(msg, BAD_CAST "list type");
- else if (WXS_IS_UNION(type))
- msg = xmlStrcat(msg, BAD_CAST "union type");
- if (xmlSchemaIsGlobalItem(type)) {
- xmlChar *str = NULL;
- msg = xmlStrcat(msg, BAD_CAST " '");
- if (type->builtInType != 0) {
- msg = xmlStrcat(msg, BAD_CAST "xs:");
- msg = xmlStrcat(msg, type->name);
- } else
- msg = xmlStrcat(msg,
- xmlSchemaFormatQName(&str,
- type->targetNamespace, type->name));
- msg = xmlStrcat(msg, BAD_CAST "'.");
- FREE_AND_NULL(str);
- }
- } else {
- if (node->type == XML_ATTRIBUTE_NODE)
- msg = xmlStrcat(msg, BAD_CAST "The value '%s' is not valid.");
- else
- msg = xmlStrcat(msg, BAD_CAST "The character content is not "
- "valid.");
- }
- if (expected) {
- msg = xmlStrcat(msg, BAD_CAST " Expected is '");
- msg = xmlStrcat(msg, BAD_CAST expected);
- msg = xmlStrcat(msg, BAD_CAST "'.\n");
- } else
- msg = xmlStrcat(msg, BAD_CAST "\n");
- if (node->type == XML_ATTRIBUTE_NODE)
- xmlSchemaPErr(ctxt, node, error, (const char *) msg, value, NULL);
- else
- xmlSchemaPErr(ctxt, node, error, (const char *) msg, NULL, NULL);
- } else {
- msg = xmlStrcat(msg, BAD_CAST message);
- msg = xmlStrcat(msg, BAD_CAST ".\n");
- xmlSchemaPErrExt(ctxt, node, error, NULL, NULL, NULL,
- (const char*) msg, str1, str2, NULL, NULL, NULL);
- }
-
- FREE_AND_NULL(msg)
- }
- static void
- xmlSchemaPContentErr(xmlSchemaParserCtxtPtr ctxt,
- xmlParserErrors error,
- xmlSchemaBasicItemPtr ownerItem,
- xmlNodePtr ownerElem,
- xmlNodePtr child,
- const char *message,
- const char *content)
- {
- xmlChar *des = NULL;
- xmlSchemaFormatItemForReport(&des, NULL, ownerItem, ownerElem);
- if (message != NULL)
- xmlSchemaPErr2(ctxt, ownerElem, child, error,
- "%s: %s.\n",
- BAD_CAST des, BAD_CAST message);
- else {
- if (content != NULL) {
- xmlSchemaPErr2(ctxt, ownerElem, child, error,
- "%s: The content is not valid. Expected is %s.\n",
- BAD_CAST des, BAD_CAST content);
- } else {
- xmlSchemaPErr2(ctxt, ownerElem, child, error,
- "%s: The content is not valid.\n",
- BAD_CAST des, NULL);
- }
- }
- FREE_AND_NULL(des)
- }
- static xmlSchemaPtr
- xmlSchemaNewSchema(xmlSchemaParserCtxtPtr ctxt)
- {
- xmlSchemaPtr ret;
- ret = (xmlSchemaPtr) xmlMalloc(sizeof(xmlSchema));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating schema", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchema));
- ret->dict = ctxt->dict;
- xmlDictReference(ret->dict);
- return (ret);
- }
- xmlSchemaFacetPtr
- xmlSchemaNewFacet(void)
- {
- xmlSchemaFacetPtr ret;
- ret = (xmlSchemaFacetPtr) xmlMalloc(sizeof(xmlSchemaFacet));
- if (ret == NULL) {
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaFacet));
- return (ret);
- }
- static xmlSchemaAnnotPtr
- xmlSchemaNewAnnot(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
- {
- xmlSchemaAnnotPtr ret;
- ret = (xmlSchemaAnnotPtr) xmlMalloc(sizeof(xmlSchemaAnnot));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating annotation", node);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaAnnot));
- ret->content = node;
- return (ret);
- }
- static xmlSchemaItemListPtr
- xmlSchemaItemListCreate(void)
- {
- xmlSchemaItemListPtr ret;
- ret = xmlMalloc(sizeof(xmlSchemaItemList));
- if (ret == NULL) {
- xmlSchemaPErrMemory(NULL,
- "allocating an item list structure", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaItemList));
- return (ret);
- }
- static void
- xmlSchemaItemListClear(xmlSchemaItemListPtr list)
- {
- if (list->items != NULL) {
- xmlFree(list->items);
- list->items = NULL;
- }
- list->nbItems = 0;
- list->sizeItems = 0;
- }
- static int
- xmlSchemaItemListAdd(xmlSchemaItemListPtr list, void *item)
- {
- if (list->items == NULL) {
- list->items = (void **) xmlMalloc(
- 20 * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
- return(-1);
- }
- list->sizeItems = 20;
- } else if (list->sizeItems <= list->nbItems) {
- list->sizeItems *= 2;
- list->items = (void **) xmlRealloc(list->items,
- list->sizeItems * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "growing item list", NULL);
- list->sizeItems = 0;
- return(-1);
- }
- }
- list->items[list->nbItems++] = item;
- return(0);
- }
- static int
- xmlSchemaItemListAddSize(xmlSchemaItemListPtr list,
- int initialSize,
- void *item)
- {
- if (list->items == NULL) {
- if (initialSize <= 0)
- initialSize = 1;
- list->items = (void **) xmlMalloc(
- initialSize * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
- return(-1);
- }
- list->sizeItems = initialSize;
- } else if (list->sizeItems <= list->nbItems) {
- list->sizeItems *= 2;
- list->items = (void **) xmlRealloc(list->items,
- list->sizeItems * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "growing item list", NULL);
- list->sizeItems = 0;
- return(-1);
- }
- }
- list->items[list->nbItems++] = item;
- return(0);
- }
- static int
- xmlSchemaItemListInsert(xmlSchemaItemListPtr list, void *item, int idx)
- {
- if (list->items == NULL) {
- list->items = (void **) xmlMalloc(
- 20 * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
- return(-1);
- }
- list->sizeItems = 20;
- } else if (list->sizeItems <= list->nbItems) {
- list->sizeItems *= 2;
- list->items = (void **) xmlRealloc(list->items,
- list->sizeItems * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "growing item list", NULL);
- list->sizeItems = 0;
- return(-1);
- }
- }
-
- if (idx >= list->nbItems) {
- list->items[list->nbItems++] = item;
- } else {
- int i;
- for (i = list->nbItems; i > idx; i--)
- list->items[i] = list->items[i-1];
- list->items[idx] = item;
- list->nbItems++;
- }
- return(0);
- }
- #if 0
- static int
- xmlSchemaItemListInsertSize(xmlSchemaItemListPtr list,
- int initialSize,
- void *item,
- int idx)
- {
- if (list->items == NULL) {
- if (initialSize <= 0)
- initialSize = 1;
- list->items = (void **) xmlMalloc(
- initialSize * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating new item list", NULL);
- return(-1);
- }
- list->sizeItems = initialSize;
- } else if (list->sizeItems <= list->nbItems) {
- list->sizeItems *= 2;
- list->items = (void **) xmlRealloc(list->items,
- list->sizeItems * sizeof(void *));
- if (list->items == NULL) {
- xmlSchemaPErrMemory(NULL, "growing item list", NULL);
- list->sizeItems = 0;
- return(-1);
- }
- }
-
- if (idx >= list->nbItems) {
- list->items[list->nbItems++] = item;
- } else {
- int i;
- for (i = list->nbItems; i > idx; i--)
- list->items[i] = list->items[i-1];
- list->items[idx] = item;
- list->nbItems++;
- }
- return(0);
- }
- #endif
- static int
- xmlSchemaItemListRemove(xmlSchemaItemListPtr list, int idx)
- {
- int i;
- if ((list->items == NULL) || (idx >= list->nbItems)) {
- xmlSchemaPSimpleErr("Internal error: xmlSchemaItemListRemove, "
- "index error.\n");
- return(-1);
- }
- if (list->nbItems == 1) {
-
- xmlFree(list->items);
- list->items = NULL;
- list->nbItems = 0;
- list->sizeItems = 0;
- } else if (list->nbItems -1 == idx) {
- list->nbItems--;
- } else {
- for (i = idx; i < list->nbItems -1; i++)
- list->items[i] = list->items[i+1];
- list->nbItems--;
- }
- return(0);
- }
- static void
- xmlSchemaItemListFree(xmlSchemaItemListPtr list)
- {
- if (list == NULL)
- return;
- if (list->items != NULL)
- xmlFree(list->items);
- xmlFree(list);
- }
- static void
- xmlSchemaBucketFree(xmlSchemaBucketPtr bucket)
- {
- if (bucket == NULL)
- return;
- if (bucket->globals != NULL) {
- xmlSchemaComponentListFree(bucket->globals);
- xmlSchemaItemListFree(bucket->globals);
- }
- if (bucket->locals != NULL) {
- xmlSchemaComponentListFree(bucket->locals);
- xmlSchemaItemListFree(bucket->locals);
- }
- if (bucket->relations != NULL) {
- xmlSchemaSchemaRelationPtr prev, cur = bucket->relations;
- do {
- prev = cur;
- cur = cur->next;
- xmlFree(prev);
- } while (cur != NULL);
- }
- if ((! bucket->preserveDoc) && (bucket->doc != NULL)) {
- xmlFreeDoc(bucket->doc);
- }
- if (bucket->type == XML_SCHEMA_SCHEMA_IMPORT) {
- if (WXS_IMPBUCKET(bucket)->schema != NULL)
- xmlSchemaFree(WXS_IMPBUCKET(bucket)->schema);
- }
- xmlFree(bucket);
- }
- static xmlSchemaBucketPtr
- xmlSchemaBucketCreate(xmlSchemaParserCtxtPtr pctxt,
- int type, const xmlChar *targetNamespace)
- {
- xmlSchemaBucketPtr ret;
- int size;
- xmlSchemaPtr mainSchema;
- if (WXS_CONSTRUCTOR(pctxt)->mainSchema == NULL) {
- PERROR_INT("xmlSchemaBucketCreate",
- "no main schema on constructor");
- return(NULL);
- }
- mainSchema = WXS_CONSTRUCTOR(pctxt)->mainSchema;
-
- if (WXS_IS_BUCKET_INCREDEF(type))
- size = sizeof(xmlSchemaInclude);
- else
- size = sizeof(xmlSchemaImport);
- ret = (xmlSchemaBucketPtr) xmlMalloc(size);
- if (ret == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating schema bucket", NULL);
- return(NULL);
- }
- memset(ret, 0, size);
- ret->targetNamespace = targetNamespace;
- ret->type = type;
- ret->globals = xmlSchemaItemListCreate();
- if (ret->globals == NULL) {
- xmlFree(ret);
- return(NULL);
- }
- ret->locals = xmlSchemaItemListCreate();
- if (ret->locals == NULL) {
- xmlFree(ret);
- return(NULL);
- }
-
- if (! WXS_HAS_BUCKETS(pctxt)) {
- if (WXS_IS_BUCKET_INCREDEF(type)) {
- PERROR_INT("xmlSchemaBucketCreate",
- "first bucket but it's an include or redefine");
- xmlSchemaBucketFree(ret);
- return(NULL);
- }
-
- ret->type = XML_SCHEMA_SCHEMA_MAIN;
-
- WXS_CONSTRUCTOR(pctxt)->mainBucket = ret;
- WXS_IMPBUCKET(ret)->schema = mainSchema;
-
- mainSchema->targetNamespace = targetNamespace;
- } else {
- if (type == XML_SCHEMA_SCHEMA_MAIN) {
- PERROR_INT("xmlSchemaBucketCreate",
- "main bucket but it's not the first one");
- xmlSchemaBucketFree(ret);
- return(NULL);
- } else if (type == XML_SCHEMA_SCHEMA_IMPORT) {
-
- WXS_IMPBUCKET(ret)->schema = xmlSchemaNewSchema(pctxt);
- if (WXS_IMPBUCKET(ret)->schema == NULL) {
- xmlSchemaBucketFree(ret);
- return(NULL);
- }
- WXS_IMPBUCKET(ret)->schema->targetNamespace = targetNamespace;
- }
- }
- if (WXS_IS_BUCKET_IMPMAIN(type)) {
- int res;
-
- if (mainSchema->schemasImports == NULL) {
- mainSchema->schemasImports = xmlHashCreateDict(5,
- WXS_CONSTRUCTOR(pctxt)->dict);
- if (mainSchema->schemasImports == NULL) {
- xmlSchemaBucketFree(ret);
- return(NULL);
- }
- }
- if (targetNamespace == NULL)
- res = xmlHashAddEntry(mainSchema->schemasImports,
- XML_SCHEMAS_NO_NAMESPACE, ret);
- else
- res = xmlHashAddEntry(mainSchema->schemasImports,
- targetNamespace, ret);
- if (res != 0) {
- PERROR_INT("xmlSchemaBucketCreate",
- "failed to add the schema bucket to the hash");
- xmlSchemaBucketFree(ret);
- return(NULL);
- }
- } else {
-
- if (WXS_IS_BUCKET_IMPMAIN(WXS_CONSTRUCTOR(pctxt)->bucket->type))
- WXS_INCBUCKET(ret)->ownerImport =
- WXS_IMPBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket);
- else
- WXS_INCBUCKET(ret)->ownerImport =
- WXS_INCBUCKET(WXS_CONSTRUCTOR(pctxt)->bucket)->ownerImport;
-
- if (mainSchema->includes == NULL) {
- mainSchema->includes = xmlSchemaItemListCreate();
- if (mainSchema->includes == NULL) {
- xmlSchemaBucketFree(ret);
- return(NULL);
- }
- }
- xmlSchemaItemListAdd(mainSchema->includes, ret);
- }
-
- if (xmlSchemaItemListAdd(WXS_CONSTRUCTOR(pctxt)->buckets, ret) == -1)
- return(NULL);
- return(ret);
- }
- static int
- xmlSchemaAddItemSize(xmlSchemaItemListPtr *list, int initialSize, void *item)
- {
- if (*list == NULL) {
- *list = xmlSchemaItemListCreate();
- if (*list == NULL)
- return(-1);
- }
- xmlSchemaItemListAddSize(*list, initialSize, item);
- return(0);
- }
- static void
- xmlSchemaFreeAnnot(xmlSchemaAnnotPtr annot)
- {
- if (annot == NULL)
- return;
- if (annot->next == NULL) {
- xmlFree(annot);
- } else {
- xmlSchemaAnnotPtr prev;
- do {
- prev = annot;
- annot = annot->next;
- xmlFree(prev);
- } while (annot != NULL);
- }
- }
- static void
- xmlSchemaFreeNotation(xmlSchemaNotationPtr nota)
- {
- if (nota == NULL)
- return;
- xmlFree(nota);
- }
- static void
- xmlSchemaFreeAttribute(xmlSchemaAttributePtr attr)
- {
- if (attr == NULL)
- return;
- if (attr->annot != NULL)
- xmlSchemaFreeAnnot(attr->annot);
- if (attr->defVal != NULL)
- xmlSchemaFreeValue(attr->defVal);
- xmlFree(attr);
- }
- static void
- xmlSchemaFreeAttributeUse(xmlSchemaAttributeUsePtr use)
- {
- if (use == NULL)
- return;
- if (use->annot != NULL)
- xmlSchemaFreeAnnot(use->annot);
- if (use->defVal != NULL)
- xmlSchemaFreeValue(use->defVal);
- xmlFree(use);
- }
- static void
- xmlSchemaFreeAttributeUseProhib(xmlSchemaAttributeUseProhibPtr prohib)
- {
- if (prohib == NULL)
- return;
- xmlFree(prohib);
- }
- static void
- xmlSchemaFreeWildcardNsSet(xmlSchemaWildcardNsPtr set)
- {
- xmlSchemaWildcardNsPtr next;
- while (set != NULL) {
- next = set->next;
- xmlFree(set);
- set = next;
- }
- }
- void
- xmlSchemaFreeWildcard(xmlSchemaWildcardPtr wildcard)
- {
- if (wildcard == NULL)
- return;
- if (wildcard->annot != NULL)
- xmlSchemaFreeAnnot(wildcard->annot);
- if (wildcard->nsSet != NULL)
- xmlSchemaFreeWildcardNsSet(wildcard->nsSet);
- if (wildcard->negNsSet != NULL)
- xmlFree(wildcard->negNsSet);
- xmlFree(wildcard);
- }
- static void
- xmlSchemaFreeAttributeGroup(xmlSchemaAttributeGroupPtr attrGr)
- {
- if (attrGr == NULL)
- return;
- if (attrGr->annot != NULL)
- xmlSchemaFreeAnnot(attrGr->annot);
- if (attrGr->attrUses != NULL)
- xmlSchemaItemListFree(WXS_LIST_CAST attrGr->attrUses);
- xmlFree(attrGr);
- }
- static void
- xmlSchemaFreeQNameRef(xmlSchemaQNameRefPtr item)
- {
- xmlFree(item);
- }
- static void
- xmlSchemaFreeTypeLinkList(xmlSchemaTypeLinkPtr link)
- {
- xmlSchemaTypeLinkPtr next;
- while (link != NULL) {
- next = link->next;
- xmlFree(link);
- link = next;
- }
- }
- static void
- xmlSchemaFreeIDCStateObjList(xmlSchemaIDCStateObjPtr sto)
- {
- xmlSchemaIDCStateObjPtr next;
- while (sto != NULL) {
- next = sto->next;
- if (sto->history != NULL)
- xmlFree(sto->history);
- if (sto->xpathCtxt != NULL)
- xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
- xmlFree(sto);
- sto = next;
- }
- }
- static void
- xmlSchemaFreeIDC(xmlSchemaIDCPtr idcDef)
- {
- xmlSchemaIDCSelectPtr cur, prev;
- if (idcDef == NULL)
- return;
- if (idcDef->annot != NULL)
- xmlSchemaFreeAnnot(idcDef->annot);
-
- if (idcDef->selector != NULL) {
- if (idcDef->selector->xpathComp != NULL)
- xmlFreePattern((xmlPatternPtr) idcDef->selector->xpathComp);
- xmlFree(idcDef->selector);
- }
-
- if (idcDef->fields != NULL) {
- cur = idcDef->fields;
- do {
- prev = cur;
- cur = cur->next;
- if (prev->xpathComp != NULL)
- xmlFreePattern((xmlPatternPtr) prev->xpathComp);
- xmlFree(prev);
- } while (cur != NULL);
- }
- xmlFree(idcDef);
- }
- static void
- xmlSchemaFreeElement(xmlSchemaElementPtr elem)
- {
- if (elem == NULL)
- return;
- if (elem->annot != NULL)
- xmlSchemaFreeAnnot(elem->annot);
- if (elem->contModel != NULL)
- xmlRegFreeRegexp(elem->contModel);
- if (elem->defVal != NULL)
- xmlSchemaFreeValue(elem->defVal);
- xmlFree(elem);
- }
- void
- xmlSchemaFreeFacet(xmlSchemaFacetPtr facet)
- {
- if (facet == NULL)
- return;
- if (facet->val != NULL)
- xmlSchemaFreeValue(facet->val);
- if (facet->regexp != NULL)
- xmlRegFreeRegexp(facet->regexp);
- if (facet->annot != NULL)
- xmlSchemaFreeAnnot(facet->annot);
- xmlFree(facet);
- }
- void
- xmlSchemaFreeType(xmlSchemaTypePtr type)
- {
- if (type == NULL)
- return;
- if (type->annot != NULL)
- xmlSchemaFreeAnnot(type->annot);
- if (type->facets != NULL) {
- xmlSchemaFacetPtr facet, next;
- facet = type->facets;
- while (facet != NULL) {
- next = facet->next;
- xmlSchemaFreeFacet(facet);
- facet = next;
- }
- }
- if (type->attrUses != NULL)
- xmlSchemaItemListFree((xmlSchemaItemListPtr) type->attrUses);
- if (type->memberTypes != NULL)
- xmlSchemaFreeTypeLinkList(type->memberTypes);
- if (type->facetSet != NULL) {
- xmlSchemaFacetLinkPtr next, link;
- link = type->facetSet;
- do {
- next = link->next;
- xmlFree(link);
- link = next;
- } while (link != NULL);
- }
- if (type->contModel != NULL)
- xmlRegFreeRegexp(type->contModel);
- xmlFree(type);
- }
- static void
- xmlSchemaFreeModelGroupDef(xmlSchemaModelGroupDefPtr item)
- {
- if (item->annot != NULL)
- xmlSchemaFreeAnnot(item->annot);
- xmlFree(item);
- }
- static void
- xmlSchemaFreeModelGroup(xmlSchemaModelGroupPtr item)
- {
- if (item->annot != NULL)
- xmlSchemaFreeAnnot(item->annot);
- xmlFree(item);
- }
- static void
- xmlSchemaComponentListFree(xmlSchemaItemListPtr list)
- {
- if ((list == NULL) || (list->nbItems == 0))
- return;
- {
- xmlSchemaTreeItemPtr item;
- xmlSchemaTreeItemPtr *items = (xmlSchemaTreeItemPtr *) list->items;
- int i;
- for (i = 0; i < list->nbItems; i++) {
- item = items[i];
- if (item == NULL)
- continue;
- switch (item->type) {
- case XML_SCHEMA_TYPE_SIMPLE:
- case XML_SCHEMA_TYPE_COMPLEX:
- xmlSchemaFreeType((xmlSchemaTypePtr) item);
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- xmlSchemaFreeAttribute((xmlSchemaAttributePtr) item);
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- xmlSchemaFreeAttributeUse((xmlSchemaAttributeUsePtr) item);
- break;
- case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
- xmlSchemaFreeAttributeUseProhib(
- (xmlSchemaAttributeUseProhibPtr) item);
- break;
- case XML_SCHEMA_TYPE_ELEMENT:
- xmlSchemaFreeElement((xmlSchemaElementPtr) item);
- break;
- case XML_SCHEMA_TYPE_PARTICLE:
- if (item->annot != NULL)
- xmlSchemaFreeAnnot(item->annot);
- xmlFree(item);
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL:
- xmlSchemaFreeModelGroup((xmlSchemaModelGroupPtr) item);
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- xmlSchemaFreeAttributeGroup(
- (xmlSchemaAttributeGroupPtr) item);
- break;
- case XML_SCHEMA_TYPE_GROUP:
- xmlSchemaFreeModelGroupDef(
- (xmlSchemaModelGroupDefPtr) item);
- break;
- case XML_SCHEMA_TYPE_ANY:
- case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
- xmlSchemaFreeWildcard((xmlSchemaWildcardPtr) item);
- break;
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- xmlSchemaFreeIDC((xmlSchemaIDCPtr) item);
- break;
- case XML_SCHEMA_TYPE_NOTATION:
- xmlSchemaFreeNotation((xmlSchemaNotationPtr) item);
- break;
- case XML_SCHEMA_EXTRA_QNAMEREF:
- xmlSchemaFreeQNameRef((xmlSchemaQNameRefPtr) item);
- break;
- default: {
-
- xmlSchemaPSimpleInternalErr(NULL,
- "Internal error: xmlSchemaComponentListFree, "
- "unexpected component type '%s'\n",
- (const xmlChar *) WXS_ITEM_TYPE_NAME(item));
- }
- break;
- }
- }
- list->nbItems = 0;
- }
- }
- void
- xmlSchemaFree(xmlSchemaPtr schema)
- {
- if (schema == NULL)
- return;
-
- if (schema->volatiles != NULL)
- TODO
-
- if (schema->notaDecl != NULL)
- xmlHashFree(schema->notaDecl, NULL);
- if (schema->attrDecl != NULL)
- xmlHashFree(schema->attrDecl, NULL);
- if (schema->attrgrpDecl != NULL)
- xmlHashFree(schema->attrgrpDecl, NULL);
- if (schema->elemDecl != NULL)
- xmlHashFree(schema->elemDecl, NULL);
- if (schema->typeDecl != NULL)
- xmlHashFree(schema->typeDecl, NULL);
- if (schema->groupDecl != NULL)
- xmlHashFree(schema->groupDecl, NULL);
- if (schema->idcDef != NULL)
- xmlHashFree(schema->idcDef, NULL);
- if (schema->schemasImports != NULL)
- xmlHashFree(schema->schemasImports,
- (xmlHashDeallocator) xmlSchemaBucketFree);
- if (schema->includes != NULL) {
- xmlSchemaItemListPtr list = (xmlSchemaItemListPtr) schema->includes;
- int i;
- for (i = 0; i < list->nbItems; i++) {
- xmlSchemaBucketFree((xmlSchemaBucketPtr) list->items[i]);
- }
- xmlSchemaItemListFree(list);
- }
- if (schema->annot != NULL)
- xmlSchemaFreeAnnot(schema->annot);
-
- xmlDictFree(schema->dict);
- xmlFree(schema);
- }
- #ifdef LIBXML_OUTPUT_ENABLED
- static void
- xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output);
- static void
- xmlSchemaElementDump(xmlSchemaElementPtr elem, FILE * output,
- const xmlChar * name ATTRIBUTE_UNUSED,
- const xmlChar * namespace ATTRIBUTE_UNUSED,
- const xmlChar * context ATTRIBUTE_UNUSED)
- {
- if (elem == NULL)
- return;
- fprintf(output, "Element");
- if (elem->flags & XML_SCHEMAS_ELEM_GLOBAL)
- fprintf(output, " (global)");
- fprintf(output, ": '%s' ", elem->name);
- if (namespace != NULL)
- fprintf(output, "ns '%s'", namespace);
- fprintf(output, "\n");
- #if 0
- if ((elem->minOccurs != 1) || (elem->maxOccurs != 1)) {
- fprintf(output, " min %d ", elem->minOccurs);
- if (elem->maxOccurs >= UNBOUNDED)
- fprintf(output, "max: unbounded\n");
- else if (elem->maxOccurs != 1)
- fprintf(output, "max: %d\n", elem->maxOccurs);
- else
- fprintf(output, "\n");
- }
- #endif
-
- if ((elem->flags & XML_SCHEMAS_ELEM_NILLABLE) ||
- (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT) ||
- (elem->flags & XML_SCHEMAS_ELEM_FIXED) ||
- (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)) {
- fprintf(output, " props: ");
- if (elem->flags & XML_SCHEMAS_ELEM_FIXED)
- fprintf(output, "[fixed] ");
- if (elem->flags & XML_SCHEMAS_ELEM_DEFAULT)
- fprintf(output, "[default] ");
- if (elem->flags & XML_SCHEMAS_ELEM_ABSTRACT)
- fprintf(output, "[abstract] ");
- if (elem->flags & XML_SCHEMAS_ELEM_NILLABLE)
- fprintf(output, "[nillable] ");
- fprintf(output, "\n");
- }
-
- if (elem->value != NULL)
- fprintf(output, " value: '%s'\n", elem->value);
-
- if (elem->namedType != NULL) {
- fprintf(output, " type: '%s' ", elem->namedType);
- if (elem->namedTypeNs != NULL)
- fprintf(output, "ns '%s'\n", elem->namedTypeNs);
- else
- fprintf(output, "\n");
- } else if (elem->subtypes != NULL) {
-
- xmlSchemaTypeDump(elem->subtypes, output);
- }
-
- if (elem->substGroup != NULL) {
- fprintf(output, " substitutionGroup: '%s' ", elem->substGroup);
- if (elem->substGroupNs != NULL)
- fprintf(output, "ns '%s'\n", elem->substGroupNs);
- else
- fprintf(output, "\n");
- }
- }
- static void
- xmlSchemaAnnotDump(FILE * output, xmlSchemaAnnotPtr annot)
- {
- xmlChar *content;
- if (annot == NULL)
- return;
- content = xmlNodeGetContent(annot->content);
- if (content != NULL) {
- fprintf(output, " Annot: %s\n", content);
- xmlFree(content);
- } else
- fprintf(output, " Annot: empty\n");
- }
- static void
- xmlSchemaContentModelDump(xmlSchemaParticlePtr particle, FILE * output, int depth)
- {
- xmlChar *str = NULL;
- xmlSchemaTreeItemPtr term;
- char shift[100];
- int i;
- if (particle == NULL)
- return;
- for (i = 0;((i < depth) && (i < 25));i++)
- shift[2 * i] = shift[2 * i + 1] = ' ';
- shift[2 * i] = shift[2 * i + 1] = 0;
- fprintf(output, "%s", shift);
- if (particle->children == NULL) {
- fprintf(output, "MISSING particle term\n");
- return;
- }
- term = particle->children;
- if (term == NULL) {
- fprintf(output, "(NULL)");
- } else {
- switch (term->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- fprintf(output, "ELEM '%s'", xmlSchemaFormatQName(&str,
- ((xmlSchemaElementPtr)term)->targetNamespace,
- ((xmlSchemaElementPtr)term)->name));
- FREE_AND_NULL(str);
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- fprintf(output, "SEQUENCE");
- break;
- case XML_SCHEMA_TYPE_CHOICE:
- fprintf(output, "CHOICE");
- break;
- case XML_SCHEMA_TYPE_ALL:
- fprintf(output, "ALL");
- break;
- case XML_SCHEMA_TYPE_ANY:
- fprintf(output, "ANY");
- break;
- default:
- fprintf(output, "UNKNOWN\n");
- return;
- }
- }
- if (particle->minOccurs != 1)
- fprintf(output, " min: %d", particle->minOccurs);
- if (particle->maxOccurs >= UNBOUNDED)
- fprintf(output, " max: unbounded");
- else if (particle->maxOccurs != 1)
- fprintf(output, " max: %d", particle->maxOccurs);
- fprintf(output, "\n");
- if (term &&
- ((term->type == XML_SCHEMA_TYPE_SEQUENCE) ||
- (term->type == XML_SCHEMA_TYPE_CHOICE) ||
- (term->type == XML_SCHEMA_TYPE_ALL)) &&
- (term->children != NULL)) {
- xmlSchemaContentModelDump((xmlSchemaParticlePtr) term->children,
- output, depth +1);
- }
- if (particle->next != NULL)
- xmlSchemaContentModelDump((xmlSchemaParticlePtr) particle->next,
- output, depth);
- }
- static void
- xmlSchemaAttrUsesDump(xmlSchemaItemListPtr uses, FILE * output)
- {
- xmlSchemaAttributeUsePtr use;
- xmlSchemaAttributeUseProhibPtr prohib;
- xmlSchemaQNameRefPtr ref;
- const xmlChar *name, *tns;
- xmlChar *str = NULL;
- int i;
- if ((uses == NULL) || (uses->nbItems == 0))
- return;
- fprintf(output, " attributes:\n");
- for (i = 0; i < uses->nbItems; i++) {
- use = uses->items[i];
- if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
- fprintf(output, " [prohibition] ");
- prohib = (xmlSchemaAttributeUseProhibPtr) use;
- name = prohib->name;
- tns = prohib->targetNamespace;
- } else if (use->type == XML_SCHEMA_EXTRA_QNAMEREF) {
- fprintf(output, " [reference] ");
- ref = (xmlSchemaQNameRefPtr) use;
- name = ref->name;
- tns = ref->targetNamespace;
- } else {
- fprintf(output, " [use] ");
- name = WXS_ATTRUSE_DECL_NAME(use);
- tns = WXS_ATTRUSE_DECL_TNS(use);
- }
- fprintf(output, "'%s'\n",
- (const char *) xmlSchemaFormatQName(&str, tns, name));
- FREE_AND_NULL(str);
- }
- }
- static void
- xmlSchemaTypeDump(xmlSchemaTypePtr type, FILE * output)
- {
- if (type == NULL) {
- fprintf(output, "Type: NULL\n");
- return;
- }
- fprintf(output, "Type: ");
- if (type->name != NULL)
- fprintf(output, "'%s' ", type->name);
- else
- fprintf(output, "(no name) ");
- if (type->targetNamespace != NULL)
- fprintf(output, "ns '%s' ", type->targetNamespace);
- switch (type->type) {
- case XML_SCHEMA_TYPE_BASIC:
- fprintf(output, "[basic] ");
- break;
- case XML_SCHEMA_TYPE_SIMPLE:
- fprintf(output, "[simple] ");
- break;
- case XML_SCHEMA_TYPE_COMPLEX:
- fprintf(output, "[complex] ");
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- fprintf(output, "[sequence] ");
- break;
- case XML_SCHEMA_TYPE_CHOICE:
- fprintf(output, "[choice] ");
- break;
- case XML_SCHEMA_TYPE_ALL:
- fprintf(output, "[all] ");
- break;
- case XML_SCHEMA_TYPE_UR:
- fprintf(output, "[ur] ");
- break;
- case XML_SCHEMA_TYPE_RESTRICTION:
- fprintf(output, "[restriction] ");
- break;
- case XML_SCHEMA_TYPE_EXTENSION:
- fprintf(output, "[extension] ");
- break;
- default:
- fprintf(output, "[unknown type %d] ", type->type);
- break;
- }
- fprintf(output, "content: ");
- switch (type->contentType) {
- case XML_SCHEMA_CONTENT_UNKNOWN:
- fprintf(output, "[unknown] ");
- break;
- case XML_SCHEMA_CONTENT_EMPTY:
- fprintf(output, "[empty] ");
- break;
- case XML_SCHEMA_CONTENT_ELEMENTS:
- fprintf(output, "[element] ");
- break;
- case XML_SCHEMA_CONTENT_MIXED:
- fprintf(output, "[mixed] ");
- break;
- case XML_SCHEMA_CONTENT_MIXED_OR_ELEMENTS:
-
- break;
- case XML_SCHEMA_CONTENT_BASIC:
- fprintf(output, "[basic] ");
- break;
- case XML_SCHEMA_CONTENT_SIMPLE:
- fprintf(output, "[simple] ");
- break;
- case XML_SCHEMA_CONTENT_ANY:
- fprintf(output, "[any] ");
- break;
- }
- fprintf(output, "\n");
- if (type->base != NULL) {
- fprintf(output, " base type: '%s'", type->base);
- if (type->baseNs != NULL)
- fprintf(output, " ns '%s'\n", type->baseNs);
- else
- fprintf(output, "\n");
- }
- if (type->attrUses != NULL)
- xmlSchemaAttrUsesDump(type->attrUses, output);
- if (type->annot != NULL)
- xmlSchemaAnnotDump(output, type->annot);
- #ifdef DUMP_CONTENT_MODEL
- if ((type->type == XML_SCHEMA_TYPE_COMPLEX) &&
- (type->subtypes != NULL)) {
- xmlSchemaContentModelDump((xmlSchemaParticlePtr) type->subtypes,
- output, 1);
- }
- #endif
- }
- void
- xmlSchemaDump(FILE * output, xmlSchemaPtr schema)
- {
- if (output == NULL)
- return;
- if (schema == NULL) {
- fprintf(output, "Schemas: NULL\n");
- return;
- }
- fprintf(output, "Schemas: ");
- if (schema->name != NULL)
- fprintf(output, "%s, ", schema->name);
- else
- fprintf(output, "no name, ");
- if (schema->targetNamespace != NULL)
- fprintf(output, "%s", (const char *) schema->targetNamespace);
- else
- fprintf(output, "no target namespace");
- fprintf(output, "\n");
- if (schema->annot != NULL)
- xmlSchemaAnnotDump(output, schema->annot);
- xmlHashScan(schema->typeDecl, (xmlHashScanner) xmlSchemaTypeDump,
- output);
- xmlHashScanFull(schema->elemDecl,
- (xmlHashScannerFull) xmlSchemaElementDump, output);
- }
- #ifdef DEBUG_IDC_NODE_TABLE
- static void
- xmlSchemaDebugDumpIDCTable(FILE * output,
- const xmlChar *namespaceName,
- const xmlChar *localName,
- xmlSchemaPSVIIDCBindingPtr bind)
- {
- xmlChar *str = NULL;
- const xmlChar *value;
- xmlSchemaPSVIIDCNodePtr tab;
- xmlSchemaPSVIIDCKeyPtr key;
- int i, j, res;
- fprintf(output, "IDC: TABLES on '%s'\n",
- xmlSchemaFormatQName(&str, namespaceName, localName));
- FREE_AND_NULL(str)
- if (bind == NULL)
- return;
- do {
- fprintf(output, "IDC: BINDING '%s' (%d)\n",
- xmlSchemaGetComponentQName(&str,
- bind->definition), bind->nbNodes);
- FREE_AND_NULL(str)
- for (i = 0; i < bind->nbNodes; i++) {
- tab = bind->nodeTable[i];
- fprintf(output, " ( ");
- for (j = 0; j < bind->definition->nbFields; j++) {
- key = tab->keys[j];
- if ((key != NULL) && (key->val != NULL)) {
- res = xmlSchemaGetCanonValue(key->val, &value);
- if (res >= 0)
- fprintf(output, "'%s' ", value);
- else
- fprintf(output, "CANON-VALUE-FAILED ");
- if (res == 0)
- FREE_AND_NULL(value)
- } else if (key != NULL)
- fprintf(output, "(no val), ");
- else
- fprintf(output, "(key missing), ");
- }
- fprintf(output, ")\n");
- }
- if (bind->dupls && bind->dupls->nbItems) {
- fprintf(output, "IDC: dupls (%d):\n", bind->dupls->nbItems);
- for (i = 0; i < bind->dupls->nbItems; i++) {
- tab = bind->dupls->items[i];
- fprintf(output, " ( ");
- for (j = 0; j < bind->definition->nbFields; j++) {
- key = tab->keys[j];
- if ((key != NULL) && (key->val != NULL)) {
- res = xmlSchemaGetCanonValue(key->val, &value);
- if (res >= 0)
- fprintf(output, "'%s' ", value);
- else
- fprintf(output, "CANON-VALUE-FAILED ");
- if (res == 0)
- FREE_AND_NULL(value)
- } else if (key != NULL)
- fprintf(output, "(no val), ");
- else
- fprintf(output, "(key missing), ");
- }
- fprintf(output, ")\n");
- }
- }
- bind = bind->next;
- } while (bind != NULL);
- }
- #endif
- #endif
- static xmlAttrPtr
- xmlSchemaGetPropNode(xmlNodePtr node, const char *name)
- {
- xmlAttrPtr prop;
- if ((node == NULL) || (name == NULL))
- return(NULL);
- prop = node->properties;
- while (prop != NULL) {
- if ((prop->ns == NULL) && xmlStrEqual(prop->name, BAD_CAST name))
- return(prop);
- prop = prop->next;
- }
- return (NULL);
- }
- static xmlAttrPtr
- xmlSchemaGetPropNodeNs(xmlNodePtr node, const char *uri, const char *name)
- {
- xmlAttrPtr prop;
- if ((node == NULL) || (name == NULL))
- return(NULL);
- prop = node->properties;
- while (prop != NULL) {
- if ((prop->ns != NULL) &&
- xmlStrEqual(prop->name, BAD_CAST name) &&
- xmlStrEqual(prop->ns->href, BAD_CAST uri))
- return(prop);
- prop = prop->next;
- }
- return (NULL);
- }
- static const xmlChar *
- xmlSchemaGetNodeContent(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node)
- {
- xmlChar *val;
- const xmlChar *ret;
- val = xmlNodeGetContent(node);
- if (val == NULL)
- val = xmlStrdup((xmlChar *)"");
- ret = xmlDictLookup(ctxt->dict, val, -1);
- xmlFree(val);
- return(ret);
- }
- static const xmlChar *
- xmlSchemaGetNodeContentNoDict(xmlNodePtr node)
- {
- return((const xmlChar*) xmlNodeGetContent(node));
- }
- static const xmlChar *
- xmlSchemaGetProp(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
- const char *name)
- {
- xmlChar *val;
- const xmlChar *ret;
- val = xmlGetNoNsProp(node, BAD_CAST name);
- if (val == NULL)
- return(NULL);
- ret = xmlDictLookup(ctxt->dict, val, -1);
- xmlFree(val);
- return(ret);
- }
- #define WXS_FIND_GLOBAL_ITEM(slot) \
- if (xmlStrEqual(nsName, schema->targetNamespace)) { \
- ret = xmlHashLookup(schema->slot, name); \
- if (ret != NULL) goto exit; \
- } \
- if (xmlHashSize(schema->schemasImports) > 1) { \
- xmlSchemaImportPtr import; \
- if (nsName == NULL) \
- import = xmlHashLookup(schema->schemasImports, \
- XML_SCHEMAS_NO_NAMESPACE); \
- else \
- import = xmlHashLookup(schema->schemasImports, nsName); \
- if (import == NULL) \
- goto exit; \
- ret = xmlHashLookup(import->schema->slot, name); \
- }
- static xmlSchemaElementPtr
- xmlSchemaGetElem(xmlSchemaPtr schema, const xmlChar * name,
- const xmlChar * nsName)
- {
- xmlSchemaElementPtr ret = NULL;
- if ((name == NULL) || (schema == NULL))
- return(NULL);
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(elemDecl)
- }
- exit:
- #ifdef DEBUG
- if (ret == NULL) {
- if (nsName == NULL)
- fprintf(stderr, "Unable to lookup element decl. %s", name);
- else
- fprintf(stderr, "Unable to lookup element decl. %s:%s", name,
- nsName);
- }
- #endif
- return (ret);
- }
- static xmlSchemaTypePtr
- xmlSchemaGetType(xmlSchemaPtr schema, const xmlChar * name,
- const xmlChar * nsName)
- {
- xmlSchemaTypePtr ret = NULL;
- if (name == NULL)
- return (NULL);
-
- if ((nsName != NULL) && xmlStrEqual(nsName, xmlSchemaNs)) {
- ret = xmlSchemaGetPredefinedType(name, nsName);
- if (ret != NULL)
- goto exit;
-
- }
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(typeDecl)
- }
- exit:
- #ifdef DEBUG
- if (ret == NULL) {
- if (nsName == NULL)
- fprintf(stderr, "Unable to lookup type %s", name);
- else
- fprintf(stderr, "Unable to lookup type %s:%s", name,
- nsName);
- }
- #endif
- return (ret);
- }
- static xmlSchemaAttributePtr
- xmlSchemaGetAttributeDecl(xmlSchemaPtr schema, const xmlChar * name,
- const xmlChar * nsName)
- {
- xmlSchemaAttributePtr ret = NULL;
- if ((name == NULL) || (schema == NULL))
- return (NULL);
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(attrDecl)
- }
- exit:
- #ifdef DEBUG
- if (ret == NULL) {
- if (nsName == NULL)
- fprintf(stderr, "Unable to lookup attribute %s", name);
- else
- fprintf(stderr, "Unable to lookup attribute %s:%s", name,
- nsName);
- }
- #endif
- return (ret);
- }
- static xmlSchemaAttributeGroupPtr
- xmlSchemaGetAttributeGroup(xmlSchemaPtr schema, const xmlChar * name,
- const xmlChar * nsName)
- {
- xmlSchemaAttributeGroupPtr ret = NULL;
- if ((name == NULL) || (schema == NULL))
- return (NULL);
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(attrgrpDecl)
- }
- exit:
-
- #ifdef DEBUG
- if (ret == NULL) {
- if (nsName == NULL)
- fprintf(stderr, "Unable to lookup attribute group %s", name);
- else
- fprintf(stderr, "Unable to lookup attribute group %s:%s", name,
- nsName);
- }
- #endif
- return (ret);
- }
- static xmlSchemaModelGroupDefPtr
- xmlSchemaGetGroup(xmlSchemaPtr schema, const xmlChar * name,
- const xmlChar * nsName)
- {
- xmlSchemaModelGroupDefPtr ret = NULL;
- if ((name == NULL) || (schema == NULL))
- return (NULL);
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(groupDecl)
- }
- exit:
- #ifdef DEBUG
- if (ret == NULL) {
- if (nsName == NULL)
- fprintf(stderr, "Unable to lookup group %s", name);
- else
- fprintf(stderr, "Unable to lookup group %s:%s", name,
- nsName);
- }
- #endif
- return (ret);
- }
- static xmlSchemaNotationPtr
- xmlSchemaGetNotation(xmlSchemaPtr schema,
- const xmlChar *name,
- const xmlChar *nsName)
- {
- xmlSchemaNotationPtr ret = NULL;
- if ((name == NULL) || (schema == NULL))
- return (NULL);
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(notaDecl)
- }
- exit:
- return (ret);
- }
- static xmlSchemaIDCPtr
- xmlSchemaGetIDC(xmlSchemaPtr schema,
- const xmlChar *name,
- const xmlChar *nsName)
- {
- xmlSchemaIDCPtr ret = NULL;
- if ((name == NULL) || (schema == NULL))
- return (NULL);
- if (schema != NULL) {
- WXS_FIND_GLOBAL_ITEM(idcDef)
- }
- exit:
- return (ret);
- }
- static xmlSchemaBasicItemPtr
- xmlSchemaGetNamedComponent(xmlSchemaPtr schema,
- xmlSchemaTypeType itemType,
- const xmlChar *name,
- const xmlChar *targetNs)
- {
- switch (itemType) {
- case XML_SCHEMA_TYPE_GROUP:
- return ((xmlSchemaBasicItemPtr) xmlSchemaGetGroup(schema,
- name, targetNs));
- case XML_SCHEMA_TYPE_ELEMENT:
- return ((xmlSchemaBasicItemPtr) xmlSchemaGetElem(schema,
- name, targetNs));
- default:
- TODO
- return (NULL);
- }
- }
- #define IS_BLANK_NODE(n) \
- (((n)->type == XML_TEXT_NODE) && (xmlSchemaIsBlank((n)->content, -1)))
- static int
- xmlSchemaIsBlank(xmlChar * str, int len)
- {
- if (str == NULL)
- return (1);
- if (len < 0) {
- while (*str != 0) {
- if (!(IS_BLANK_CH(*str)))
- return (0);
- str++;
- }
- } else while ((*str != 0) && (len != 0)) {
- if (!(IS_BLANK_CH(*str)))
- return (0);
- str++;
- len--;
- }
- return (1);
- }
- #define WXS_COMP_NAME(c, t) ((t) (c))->name
- #define WXS_COMP_TNS(c, t) ((t) (c))->targetNamespace
- static xmlSchemaBasicItemPtr
- xmlSchemaFindRedefCompInGraph(xmlSchemaBucketPtr bucket,
- xmlSchemaTypeType type,
- const xmlChar *name,
- const xmlChar *nsName)
- {
- xmlSchemaBasicItemPtr ret;
- int i;
- if ((bucket == NULL) || (name == NULL))
- return(NULL);
- if ((bucket->globals == NULL) ||
- (bucket->globals->nbItems == 0))
- goto subschemas;
-
- for (i = 0; i < bucket->globals->nbItems; i++) {
- ret = bucket->globals->items[i];
- if (ret->type == type) {
- switch (type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- if ((WXS_COMP_NAME(ret, xmlSchemaTypePtr) == name) &&
- (WXS_COMP_TNS(ret, xmlSchemaTypePtr) ==
- nsName))
- {
- return(ret);
- }
- break;
- case XML_SCHEMA_TYPE_GROUP:
- if ((WXS_COMP_NAME(ret,
- xmlSchemaModelGroupDefPtr) == name) &&
- (WXS_COMP_TNS(ret,
- xmlSchemaModelGroupDefPtr) == nsName))
- {
- return(ret);
- }
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- if ((WXS_COMP_NAME(ret,
- xmlSchemaAttributeGroupPtr) == name) &&
- (WXS_COMP_TNS(ret,
- xmlSchemaAttributeGroupPtr) == nsName))
- {
- return(ret);
- }
- break;
- default:
-
- return(NULL);
- }
- }
- }
- subschemas:
-
- if (bucket->relations != NULL) {
- xmlSchemaSchemaRelationPtr rel = bucket->relations;
-
- bucket->flags |= XML_SCHEMA_BUCKET_MARKED;
- do {
- if ((rel->bucket != NULL) &&
- ((rel->bucket->flags & XML_SCHEMA_BUCKET_MARKED) == 0)) {
- ret = xmlSchemaFindRedefCompInGraph(rel->bucket,
- type, name, nsName);
- if (ret != NULL)
- return(ret);
- }
- rel = rel->next;
- } while (rel != NULL);
- bucket->flags ^= XML_SCHEMA_BUCKET_MARKED;
- }
- return(NULL);
- }
- static xmlSchemaNotationPtr
- xmlSchemaAddNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- const xmlChar *name, const xmlChar *nsName,
- xmlNodePtr node ATTRIBUTE_UNUSED)
- {
- xmlSchemaNotationPtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
- return (NULL);
- ret = (xmlSchemaNotationPtr) xmlMalloc(sizeof(xmlSchemaNotation));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "add annotation", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaNotation));
- ret->type = XML_SCHEMA_TYPE_NOTATION;
- ret->name = name;
- ret->targetNamespace = nsName;
-
- WXS_ADD_GLOBAL(ctxt, ret);
- return (ret);
- }
- static xmlSchemaAttributePtr
- xmlSchemaAddAttribute(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- const xmlChar * name, const xmlChar * nsName,
- xmlNodePtr node, int topLevel)
- {
- xmlSchemaAttributePtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL))
- return (NULL);
- ret = (xmlSchemaAttributePtr) xmlMalloc(sizeof(xmlSchemaAttribute));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating attribute", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaAttribute));
- ret->type = XML_SCHEMA_TYPE_ATTRIBUTE;
- ret->node = node;
- ret->name = name;
- ret->targetNamespace = nsName;
- if (topLevel)
- WXS_ADD_GLOBAL(ctxt, ret);
- else
- WXS_ADD_LOCAL(ctxt, ret);
- WXS_ADD_PENDING(ctxt, ret);
- return (ret);
- }
- static xmlSchemaAttributeUsePtr
- xmlSchemaAddAttributeUse(xmlSchemaParserCtxtPtr pctxt,
- xmlNodePtr node)
- {
- xmlSchemaAttributeUsePtr ret = NULL;
- if (pctxt == NULL)
- return (NULL);
- ret = (xmlSchemaAttributeUsePtr) xmlMalloc(sizeof(xmlSchemaAttributeUse));
- if (ret == NULL) {
- xmlSchemaPErrMemory(pctxt, "allocating attribute", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaAttributeUse));
- ret->type = XML_SCHEMA_TYPE_ATTRIBUTE_USE;
- ret->node = node;
- WXS_ADD_LOCAL(pctxt, ret);
- return (ret);
- }
- static xmlSchemaRedefPtr
- xmlSchemaAddRedef(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBucketPtr targetBucket,
- void *item,
- const xmlChar *refName,
- const xmlChar *refTargetNs)
- {
- xmlSchemaRedefPtr ret;
- ret = (xmlSchemaRedefPtr)
- xmlMalloc(sizeof(xmlSchemaRedef));
- if (ret == NULL) {
- xmlSchemaPErrMemory(pctxt,
- "allocating redefinition info", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaRedef));
- ret->item = item;
- ret->targetBucket = targetBucket;
- ret->refName = refName;
- ret->refTargetNs = refTargetNs;
- if (WXS_CONSTRUCTOR(pctxt)->redefs == NULL)
- WXS_CONSTRUCTOR(pctxt)->redefs = ret;
- else
- WXS_CONSTRUCTOR(pctxt)->lastRedef->next = ret;
- WXS_CONSTRUCTOR(pctxt)->lastRedef = ret;
- return (ret);
- }
- static xmlSchemaAttributeGroupPtr
- xmlSchemaAddAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema ATTRIBUTE_UNUSED,
- const xmlChar *name,
- const xmlChar *nsName,
- xmlNodePtr node)
- {
- xmlSchemaAttributeGroupPtr ret = NULL;
- if ((pctxt == NULL) || (name == NULL))
- return (NULL);
- ret = (xmlSchemaAttributeGroupPtr)
- xmlMalloc(sizeof(xmlSchemaAttributeGroup));
- if (ret == NULL) {
- xmlSchemaPErrMemory(pctxt, "allocating attribute group", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaAttributeGroup));
- ret->type = XML_SCHEMA_TYPE_ATTRIBUTEGROUP;
- ret->name = name;
- ret->targetNamespace = nsName;
- ret->node = node;
-
- ret->flags |= XML_SCHEMAS_ATTRGROUP_GLOBAL;
- if (pctxt->isRedefine) {
- pctxt->redef = xmlSchemaAddRedef(pctxt, pctxt->redefined,
- ret, name, nsName);
- if (pctxt->redef == NULL) {
- xmlFree(ret);
- return(NULL);
- }
- pctxt->redefCounter = 0;
- }
- WXS_ADD_GLOBAL(pctxt, ret);
- WXS_ADD_PENDING(pctxt, ret);
- return (ret);
- }
- static xmlSchemaElementPtr
- xmlSchemaAddElement(xmlSchemaParserCtxtPtr ctxt,
- const xmlChar * name, const xmlChar * nsName,
- xmlNodePtr node, int topLevel)
- {
- xmlSchemaElementPtr ret = NULL;
- if ((ctxt == NULL) || (name == NULL))
- return (NULL);
- ret = (xmlSchemaElementPtr) xmlMalloc(sizeof(xmlSchemaElement));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating element", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaElement));
- ret->type = XML_SCHEMA_TYPE_ELEMENT;
- ret->name = name;
- ret->targetNamespace = nsName;
- ret->node = node;
- if (topLevel)
- WXS_ADD_GLOBAL(ctxt, ret);
- else
- WXS_ADD_LOCAL(ctxt, ret);
- WXS_ADD_PENDING(ctxt, ret);
- return (ret);
- }
- static xmlSchemaTypePtr
- xmlSchemaAddType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlSchemaTypeType type,
- const xmlChar * name, const xmlChar * nsName,
- xmlNodePtr node, int topLevel)
- {
- xmlSchemaTypePtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL))
- return (NULL);
- ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating type", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaType));
- ret->type = type;
- ret->name = name;
- ret->targetNamespace = nsName;
- ret->node = node;
- if (topLevel) {
- if (ctxt->isRedefine) {
- ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
- ret, name, nsName);
- if (ctxt->redef == NULL) {
- xmlFree(ret);
- return(NULL);
- }
- ctxt->redefCounter = 0;
- }
- WXS_ADD_GLOBAL(ctxt, ret);
- } else
- WXS_ADD_LOCAL(ctxt, ret);
- WXS_ADD_PENDING(ctxt, ret);
- return (ret);
- }
- static xmlSchemaQNameRefPtr
- xmlSchemaNewQNameRef(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypeType refType,
- const xmlChar *refName,
- const xmlChar *refNs)
- {
- xmlSchemaQNameRefPtr ret;
- ret = (xmlSchemaQNameRefPtr)
- xmlMalloc(sizeof(xmlSchemaQNameRef));
- if (ret == NULL) {
- xmlSchemaPErrMemory(pctxt,
- "allocating QName reference item", NULL);
- return (NULL);
- }
- ret->node = NULL;
- ret->type = XML_SCHEMA_EXTRA_QNAMEREF;
- ret->name = refName;
- ret->targetNamespace = refNs;
- ret->item = NULL;
- ret->itemType = refType;
-
- WXS_ADD_LOCAL(pctxt, ret);
- return (ret);
- }
- static xmlSchemaAttributeUseProhibPtr
- xmlSchemaAddAttributeUseProhib(xmlSchemaParserCtxtPtr pctxt)
- {
- xmlSchemaAttributeUseProhibPtr ret;
- ret = (xmlSchemaAttributeUseProhibPtr)
- xmlMalloc(sizeof(xmlSchemaAttributeUseProhib));
- if (ret == NULL) {
- xmlSchemaPErrMemory(pctxt,
- "allocating attribute use prohibition", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaAttributeUseProhib));
- ret->type = XML_SCHEMA_EXTRA_ATTR_USE_PROHIB;
- WXS_ADD_LOCAL(pctxt, ret);
- return (ret);
- }
- static xmlSchemaModelGroupPtr
- xmlSchemaAddModelGroup(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlSchemaTypeType type,
- xmlNodePtr node)
- {
- xmlSchemaModelGroupPtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL))
- return (NULL);
- ret = (xmlSchemaModelGroupPtr)
- xmlMalloc(sizeof(xmlSchemaModelGroup));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating model group component",
- NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaModelGroup));
- ret->type = type;
- ret->node = node;
- WXS_ADD_LOCAL(ctxt, ret);
- if ((type == XML_SCHEMA_TYPE_SEQUENCE) ||
- (type == XML_SCHEMA_TYPE_CHOICE))
- WXS_ADD_PENDING(ctxt, ret);
- return (ret);
- }
- static xmlSchemaParticlePtr
- xmlSchemaAddParticle(xmlSchemaParserCtxtPtr ctxt,
- xmlNodePtr node, int min, int max)
- {
- xmlSchemaParticlePtr ret = NULL;
- if (ctxt == NULL)
- return (NULL);
- #ifdef DEBUG
- fprintf(stderr, "Adding particle component\n");
- #endif
- ret = (xmlSchemaParticlePtr)
- xmlMalloc(sizeof(xmlSchemaParticle));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating particle component",
- NULL);
- return (NULL);
- }
- ret->type = XML_SCHEMA_TYPE_PARTICLE;
- ret->annot = NULL;
- ret->node = node;
- ret->minOccurs = min;
- ret->maxOccurs = max;
- ret->next = NULL;
- ret->children = NULL;
- WXS_ADD_LOCAL(ctxt, ret);
-
- return (ret);
- }
- static xmlSchemaModelGroupDefPtr
- xmlSchemaAddModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- const xmlChar *name,
- const xmlChar *nsName,
- xmlNodePtr node)
- {
- xmlSchemaModelGroupDefPtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
- return (NULL);
- ret = (xmlSchemaModelGroupDefPtr)
- xmlMalloc(sizeof(xmlSchemaModelGroupDef));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "adding group", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaModelGroupDef));
- ret->name = name;
- ret->type = XML_SCHEMA_TYPE_GROUP;
- ret->node = node;
- ret->targetNamespace = nsName;
- if (ctxt->isRedefine) {
- ctxt->redef = xmlSchemaAddRedef(ctxt, ctxt->redefined,
- ret, name, nsName);
- if (ctxt->redef == NULL) {
- xmlFree(ret);
- return(NULL);
- }
- ctxt->redefCounter = 0;
- }
- WXS_ADD_GLOBAL(ctxt, ret);
- WXS_ADD_PENDING(ctxt, ret);
- return (ret);
- }
- static xmlSchemaWildcardNsPtr
- xmlSchemaNewWildcardNsConstraint(xmlSchemaParserCtxtPtr ctxt)
- {
- xmlSchemaWildcardNsPtr ret;
- ret = (xmlSchemaWildcardNsPtr)
- xmlMalloc(sizeof(xmlSchemaWildcardNs));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "creating wildcard namespace constraint", NULL);
- return (NULL);
- }
- ret->value = NULL;
- ret->next = NULL;
- return (ret);
- }
- static xmlSchemaIDCPtr
- xmlSchemaAddIDC(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- const xmlChar *name, const xmlChar *nsName,
- int category, xmlNodePtr node)
- {
- xmlSchemaIDCPtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL) || (name == NULL))
- return (NULL);
- ret = (xmlSchemaIDCPtr) xmlMalloc(sizeof(xmlSchemaIDC));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt,
- "allocating an identity-constraint definition", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaIDC));
-
- ret->targetNamespace = nsName;
- ret->name = name;
- ret->type = category;
- ret->node = node;
- WXS_ADD_GLOBAL(ctxt, ret);
-
- if (category == XML_SCHEMA_TYPE_IDC_KEYREF)
- WXS_ADD_PENDING(ctxt, ret);
- return (ret);
- }
- static xmlSchemaWildcardPtr
- xmlSchemaAddWildcard(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlSchemaTypeType type, xmlNodePtr node)
- {
- xmlSchemaWildcardPtr ret = NULL;
- if ((ctxt == NULL) || (schema == NULL))
- return (NULL);
- ret = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard));
- if (ret == NULL) {
- xmlSchemaPErrMemory(ctxt, "adding wildcard", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaWildcard));
- ret->type = type;
- ret->node = node;
- WXS_ADD_LOCAL(ctxt, ret);
- return (ret);
- }
- static void
- xmlSchemaSubstGroupFree(xmlSchemaSubstGroupPtr group)
- {
- if (group == NULL)
- return;
- if (group->members != NULL)
- xmlSchemaItemListFree(group->members);
- xmlFree(group);
- }
- static xmlSchemaSubstGroupPtr
- xmlSchemaSubstGroupAdd(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaElementPtr head)
- {
- xmlSchemaSubstGroupPtr ret;
-
- if (WXS_SUBST_GROUPS(pctxt) == NULL) {
- WXS_SUBST_GROUPS(pctxt) = xmlHashCreateDict(10, pctxt->dict);
- if (WXS_SUBST_GROUPS(pctxt) == NULL)
- return(NULL);
- }
-
- ret = (xmlSchemaSubstGroupPtr) xmlMalloc(sizeof(xmlSchemaSubstGroup));
- if (ret == NULL) {
- xmlSchemaPErrMemory(NULL,
- "allocating a substitution group container", NULL);
- return(NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaSubstGroup));
- ret->head = head;
-
- ret->members = xmlSchemaItemListCreate();
- if (ret->members == NULL) {
- xmlSchemaSubstGroupFree(ret);
- return(NULL);
- }
-
- if (xmlHashAddEntry2(WXS_SUBST_GROUPS(pctxt),
- head->name, head->targetNamespace, ret) != 0) {
- PERROR_INT("xmlSchemaSubstGroupAdd",
- "failed to add a new substitution container");
- xmlSchemaSubstGroupFree(ret);
- return(NULL);
- }
- return(ret);
- }
- static xmlSchemaSubstGroupPtr
- xmlSchemaSubstGroupGet(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaElementPtr head)
- {
- if (WXS_SUBST_GROUPS(pctxt) == NULL)
- return(NULL);
- return(xmlHashLookup2(WXS_SUBST_GROUPS(pctxt),
- head->name, head->targetNamespace));
- }
- static int
- xmlSchemaAddElementSubstitutionMember(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaElementPtr head,
- xmlSchemaElementPtr member)
- {
- xmlSchemaSubstGroupPtr substGroup = NULL;
- if ((pctxt == NULL) || (head == NULL) || (member == NULL))
- return (-1);
- substGroup = xmlSchemaSubstGroupGet(pctxt, head);
- if (substGroup == NULL)
- substGroup = xmlSchemaSubstGroupAdd(pctxt, head);
- if (substGroup == NULL)
- return(-1);
- if (xmlSchemaItemListAdd(substGroup->members, member) == -1)
- return(-1);
- return(0);
- }
- static int
- xmlSchemaPValAttrNodeQNameValue(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlSchemaBasicItemPtr ownerItem,
- xmlAttrPtr attr,
- const xmlChar *value,
- const xmlChar **uri,
- const xmlChar **local)
- {
- const xmlChar *pref;
- xmlNsPtr ns;
- int len, ret;
- *uri = NULL;
- *local = NULL;
- ret = xmlValidateQName(value, 1);
- if (ret > 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- ownerItem, (xmlNodePtr) attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
- NULL, value, NULL, NULL, NULL);
- *local = value;
- return (ctxt->err);
- } else if (ret < 0)
- return (-1);
- if (!strchr((char *) value, ':')) {
- ns = xmlSearchNs(attr->doc, attr->parent, NULL);
- if (ns)
- *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
- else if (schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) {
-
-
- *uri = ctxt->targetNamespace;
- }
- *local = xmlDictLookup(ctxt->dict, value, -1);
- return (0);
- }
-
- *local = xmlSplitQName3(value, &len);
- *local = xmlDictLookup(ctxt->dict, *local, -1);
- pref = xmlDictLookup(ctxt->dict, value, len);
- ns = xmlSearchNs(attr->doc, attr->parent, pref);
- if (ns == NULL) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- ownerItem, (xmlNodePtr) attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), NULL, value,
- "The value '%s' of simple type 'xs:QName' has no "
- "corresponding namespace declaration in scope", value, NULL);
- return (ctxt->err);
- } else {
- *uri = xmlDictLookup(ctxt->dict, ns->href, -1);
- }
- return (0);
- }
- static int
- xmlSchemaPValAttrNodeQName(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlSchemaBasicItemPtr ownerItem,
- xmlAttrPtr attr,
- const xmlChar **uri,
- const xmlChar **local)
- {
- const xmlChar *value;
- value = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- return (xmlSchemaPValAttrNodeQNameValue(ctxt, schema,
- ownerItem, attr, value, uri, local));
- }
- static int
- xmlSchemaPValAttrQName(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlSchemaBasicItemPtr ownerItem,
- xmlNodePtr ownerElem,
- const char *name,
- const xmlChar **uri,
- const xmlChar **local)
- {
- xmlAttrPtr attr;
- attr = xmlSchemaGetPropNode(ownerElem, name);
- if (attr == NULL) {
- *local = NULL;
- *uri = NULL;
- return (0);
- }
- return (xmlSchemaPValAttrNodeQName(ctxt, schema,
- ownerItem, attr, uri, local));
- }
- static int
- xmlSchemaPValAttrNodeID(xmlSchemaParserCtxtPtr ctxt, xmlAttrPtr attr)
- {
- int ret;
- const xmlChar *value;
- if (attr == NULL)
- return(0);
- value = xmlSchemaGetNodeContentNoDict((xmlNodePtr) attr);
- ret = xmlValidateNCName(value, 1);
- if (ret == 0) {
-
- if (attr->atype != XML_ATTRIBUTE_ID) {
- xmlIDPtr res;
- xmlChar *strip;
-
- strip = xmlSchemaCollapseString(value);
- if (strip != NULL) {
- xmlFree((xmlChar *) value);
- value = strip;
- }
- res = xmlAddID(NULL, attr->doc, value, attr);
- if (res == NULL) {
- ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ID),
- NULL, NULL, "Duplicate value '%s' of simple "
- "type 'xs:ID'", value, NULL);
- } else
- attr->atype = XML_ATTRIBUTE_ID;
- }
- } else if (ret > 0) {
- ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ID),
- NULL, NULL, "The value '%s' of simple type 'xs:ID' is "
- "not a valid 'xs:NCName'",
- value, NULL);
- }
- if (value != NULL)
- xmlFree((xmlChar *)value);
- return (ret);
- }
- static int
- xmlSchemaPValAttrID(xmlSchemaParserCtxtPtr ctxt,
- xmlNodePtr ownerElem,
- const xmlChar *name)
- {
- xmlAttrPtr attr;
- attr = xmlSchemaGetPropNode(ownerElem, (const char *) name);
- if (attr == NULL)
- return(0);
- return(xmlSchemaPValAttrNodeID(ctxt, attr));
- }
- static int
- xmlGetMaxOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
- int min, int max, int def, const char *expected)
- {
- const xmlChar *val, *cur;
- int ret = 0;
- xmlAttrPtr attr;
- attr = xmlSchemaGetPropNode(node, "maxOccurs");
- if (attr == NULL)
- return (def);
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if (xmlStrEqual(val, (const xmlChar *) "unbounded")) {
- if (max != UNBOUNDED) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
-
- NULL, (xmlNodePtr) attr, NULL, expected,
- val, NULL, NULL, NULL);
- return (def);
- } else
- return (UNBOUNDED);
- }
- cur = val;
- while (IS_BLANK_CH(*cur))
- cur++;
- if (*cur == 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
-
- NULL, (xmlNodePtr) attr, NULL, expected,
- val, NULL, NULL, NULL);
- return (def);
- }
- while ((*cur >= '0') && (*cur <= '9')) {
- ret = ret * 10 + (*cur - '0');
- cur++;
- }
- while (IS_BLANK_CH(*cur))
- cur++;
-
- if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
-
- NULL, (xmlNodePtr) attr, NULL, expected,
- val, NULL, NULL, NULL);
- return (def);
- }
- return (ret);
- }
- static int
- xmlGetMinOccurs(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node,
- int min, int max, int def, const char *expected)
- {
- const xmlChar *val, *cur;
- int ret = 0;
- xmlAttrPtr attr;
- attr = xmlSchemaGetPropNode(node, "minOccurs");
- if (attr == NULL)
- return (def);
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- cur = val;
- while (IS_BLANK_CH(*cur))
- cur++;
- if (*cur == 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
-
- NULL, (xmlNodePtr) attr, NULL, expected,
- val, NULL, NULL, NULL);
- return (def);
- }
- while ((*cur >= '0') && (*cur <= '9')) {
- ret = ret * 10 + (*cur - '0');
- cur++;
- }
- while (IS_BLANK_CH(*cur))
- cur++;
-
- if ((*cur != 0) || (ret < min) || ((max != -1) && (ret > max))) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
-
- NULL, (xmlNodePtr) attr, NULL, expected,
- val, NULL, NULL, NULL);
- return (def);
- }
- return (ret);
- }
- static int
- xmlSchemaPGetBoolNodeValue(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaBasicItemPtr ownerItem,
- xmlNodePtr node)
- {
- xmlChar *value = NULL;
- int res = 0;
- value = xmlNodeGetContent(node);
-
- if (xmlStrEqual(BAD_CAST value, BAD_CAST "true"))
- res = 1;
- else if (xmlStrEqual(BAD_CAST value, BAD_CAST "false"))
- res = 0;
- else if (xmlStrEqual(BAD_CAST value, BAD_CAST "1"))
- res = 1;
- else if (xmlStrEqual(BAD_CAST value, BAD_CAST "0"))
- res = 0;
- else {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_INVALID_BOOLEAN,
- ownerItem, node,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
- NULL, BAD_CAST value,
- NULL, NULL, NULL);
- }
- if (value != NULL)
- xmlFree(value);
- return (res);
- }
- static int
- xmlGetBooleanProp(xmlSchemaParserCtxtPtr ctxt,
- xmlNodePtr node,
- const char *name, int def)
- {
- const xmlChar *val;
- val = xmlSchemaGetProp(ctxt, node, name);
- if (val == NULL)
- return (def);
-
- if (xmlStrEqual(val, BAD_CAST "true"))
- def = 1;
- else if (xmlStrEqual(val, BAD_CAST "false"))
- def = 0;
- else if (xmlStrEqual(val, BAD_CAST "1"))
- def = 1;
- else if (xmlStrEqual(val, BAD_CAST "0"))
- def = 0;
- else {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_INVALID_BOOLEAN,
- NULL,
- (xmlNodePtr) xmlSchemaGetPropNode(node, name),
- xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
- NULL, val, NULL, NULL, NULL);
- }
- return (def);
- }
- static xmlSchemaTypePtr xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr
- ctxt, xmlSchemaPtr schema,
- xmlNodePtr node,
- int topLevel);
- static xmlSchemaTypePtr xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr
- ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- int topLevel);
- static xmlSchemaTypePtr xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr
- ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- xmlSchemaTypeType parentType);
- static xmlSchemaBasicItemPtr
- xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- xmlSchemaItemListPtr uses,
- int parentType);
- static xmlSchemaTypePtr xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node);
- static xmlSchemaWildcardPtr
- xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema, xmlNodePtr node);
- static int
- xmlSchemaPValAttrNodeValue(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBasicItemPtr ownerItem,
- xmlAttrPtr attr,
- const xmlChar *value,
- xmlSchemaTypePtr type)
- {
- int ret = 0;
-
- if ((pctxt == NULL) || (type == NULL) || (attr == NULL))
- return (-1);
- if (type->type != XML_SCHEMA_TYPE_BASIC) {
- PERROR_INT("xmlSchemaPValAttrNodeValue",
- "the given type is not a built-in type");
- return (-1);
- }
- switch (type->builtInType) {
- case XML_SCHEMAS_NCNAME:
- case XML_SCHEMAS_QNAME:
- case XML_SCHEMAS_ANYURI:
- case XML_SCHEMAS_TOKEN:
- case XML_SCHEMAS_LANGUAGE:
- ret = xmlSchemaValPredefTypeNode(type, value, NULL,
- (xmlNodePtr) attr);
- break;
- default: {
- PERROR_INT("xmlSchemaPValAttrNodeValue",
- "validation using the given type is not supported while "
- "parsing a schema");
- return (-1);
- }
- }
-
- if (ret < 0) {
- PERROR_INT("xmlSchemaPValAttrNodeValue",
- "failed to validate a schema attribute value");
- return (-1);
- } else if (ret > 0) {
- if (WXS_IS_LIST(type))
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
- else
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
- xmlSchemaPSimpleTypeErr(pctxt,
- ret, ownerItem, (xmlNodePtr) attr,
- type, NULL, value, NULL, NULL, NULL);
- }
- return (ret);
- }
- static int
- xmlSchemaPValAttrNode(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaBasicItemPtr ownerItem,
- xmlAttrPtr attr,
- xmlSchemaTypePtr type,
- const xmlChar **value)
- {
- const xmlChar *val;
- if ((ctxt == NULL) || (type == NULL) || (attr == NULL))
- return (-1);
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if (value != NULL)
- *value = val;
- return (xmlSchemaPValAttrNodeValue(ctxt, ownerItem, attr,
- val, type));
- }
- static int
- xmlSchemaPValAttr(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaBasicItemPtr ownerItem,
- xmlNodePtr ownerElem,
- const char *name,
- xmlSchemaTypePtr type,
- const xmlChar **value)
- {
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (type == NULL)) {
- if (value != NULL)
- *value = NULL;
- return (-1);
- }
- if (type->type != XML_SCHEMA_TYPE_BASIC) {
- if (value != NULL)
- *value = NULL;
- xmlSchemaPErr(ctxt, ownerElem,
- XML_SCHEMAP_INTERNAL,
- "Internal error: xmlSchemaPValAttr, the given "
- "type '%s' is not a built-in type.\n",
- type->name, NULL);
- return (-1);
- }
- attr = xmlSchemaGetPropNode(ownerElem, name);
- if (attr == NULL) {
- if (value != NULL)
- *value = NULL;
- return (0);
- }
- return (xmlSchemaPValAttrNode(ctxt, ownerItem, attr,
- type, value));
- }
- static int
- xmlSchemaCheckReference(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema ATTRIBUTE_UNUSED,
- xmlNodePtr node,
- xmlAttrPtr attr,
- const xmlChar *namespaceName)
- {
-
- if (xmlStrEqual(pctxt->targetNamespace, namespaceName))
- return (0);
- if (xmlStrEqual(xmlSchemaNs, namespaceName))
- return (0);
-
- if (WXS_BUCKET(pctxt)->relations != NULL) {
- xmlSchemaSchemaRelationPtr rel;
- rel = WXS_BUCKET(pctxt)->relations;
- do {
- if (WXS_IS_BUCKET_IMPMAIN(rel->type) &&
- xmlStrEqual(namespaceName, rel->importNamespace))
- return (0);
- rel = rel->next;
- } while (rel != NULL);
- }
-
- {
- xmlNodePtr n = (attr != NULL) ? (xmlNodePtr) attr : node;
- if (namespaceName == NULL)
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_SRC_RESOLVE, n, NULL,
- "References from this schema to components in no "
- "namespace are not allowed, since not indicated by an "
- "import statement", NULL, NULL);
- else
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_SRC_RESOLVE, n, NULL,
- "References from this schema to components in the "
- "namespace '%s' are not allowed, since not indicated by an "
- "import statement", namespaceName, NULL);
- }
- return (XML_SCHEMAP_SRC_RESOLVE);
- }
- static int
- xmlSchemaParseLocalAttributes(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr *child, xmlSchemaItemListPtr *list,
- int parentType, int *hasRefs)
- {
- void *item;
- while ((IS_SCHEMA((*child), "attribute")) ||
- (IS_SCHEMA((*child), "attributeGroup"))) {
- if (IS_SCHEMA((*child), "attribute")) {
- item = xmlSchemaParseLocalAttribute(ctxt, schema, *child,
- *list, parentType);
- } else {
- item = xmlSchemaParseAttributeGroupRef(ctxt, schema, *child);
- if ((item != NULL) && (hasRefs != NULL))
- *hasRefs = 1;
- }
- if (item != NULL) {
- if (*list == NULL) {
-
- *list = xmlSchemaItemListCreate();
- if (*list == NULL)
- return(-1);
- }
- if (xmlSchemaItemListAddSize(*list, 2, item) == -1)
- return(-1);
- }
- *child = (*child)->next;
- }
- return (0);
- }
- static xmlSchemaAnnotPtr
- xmlSchemaParseAnnotation(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr node, int needed)
- {
- xmlSchemaAnnotPtr ret;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- int barked = 0;
-
-
- if ((ctxt == NULL) || (node == NULL))
- return (NULL);
- if (needed)
- ret = xmlSchemaNewAnnot(ctxt, node);
- else
- ret = NULL;
- attr = node->properties;
- while (attr != NULL) {
- if (((attr->ns == NULL) &&
- (!xmlStrEqual(attr->name, BAD_CAST "id"))) ||
- ((attr->ns != NULL) &&
- xmlStrEqual(attr->ns->href, xmlSchemaNs))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- child = node->children;
- while (child != NULL) {
- if (IS_SCHEMA(child, "appinfo")) {
-
-
- attr = child->properties;
- while (attr != NULL) {
- if (((attr->ns == NULL) &&
- (!xmlStrEqual(attr->name, BAD_CAST "source"))) ||
- ((attr->ns != NULL) &&
- xmlStrEqual(attr->ns->href, xmlSchemaNs))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttr(ctxt, NULL, child, "source",
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL);
- child = child->next;
- } else if (IS_SCHEMA(child, "documentation")) {
-
-
- attr = child->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if (!xmlStrEqual(attr->name, BAD_CAST "source")) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else {
- if (xmlStrEqual(attr->ns->href, xmlSchemaNs) ||
- (xmlStrEqual(attr->name, BAD_CAST "lang") &&
- (!xmlStrEqual(attr->ns->href, XML_XML_NAMESPACE)))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- }
- attr = attr->next;
- }
-
- attr = xmlSchemaGetPropNodeNs(child, (const char *) XML_XML_NAMESPACE, "lang");
- if (attr != NULL)
- xmlSchemaPValAttrNode(ctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_LANGUAGE), NULL);
- child = child->next;
- } else {
- if (!barked)
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL, "(appinfo | documentation)*");
- barked = 1;
- child = child->next;
- }
- }
- return (ret);
- }
- static xmlSchemaFacetPtr
- xmlSchemaParseFacet(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaFacetPtr facet;
- xmlNodePtr child = NULL;
- const xmlChar *value;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- facet = xmlSchemaNewFacet();
- if (facet == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating facet", node);
- return (NULL);
- }
- facet->node = node;
- value = xmlSchemaGetProp(ctxt, node, "value");
- if (value == NULL) {
- xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_FACET_NO_VALUE,
- "Facet %s has no value\n", node->name, NULL);
- xmlSchemaFreeFacet(facet);
- return (NULL);
- }
- if (IS_SCHEMA(node, "minInclusive")) {
- facet->type = XML_SCHEMA_FACET_MININCLUSIVE;
- } else if (IS_SCHEMA(node, "minExclusive")) {
- facet->type = XML_SCHEMA_FACET_MINEXCLUSIVE;
- } else if (IS_SCHEMA(node, "maxInclusive")) {
- facet->type = XML_SCHEMA_FACET_MAXINCLUSIVE;
- } else if (IS_SCHEMA(node, "maxExclusive")) {
- facet->type = XML_SCHEMA_FACET_MAXEXCLUSIVE;
- } else if (IS_SCHEMA(node, "totalDigits")) {
- facet->type = XML_SCHEMA_FACET_TOTALDIGITS;
- } else if (IS_SCHEMA(node, "fractionDigits")) {
- facet->type = XML_SCHEMA_FACET_FRACTIONDIGITS;
- } else if (IS_SCHEMA(node, "pattern")) {
- facet->type = XML_SCHEMA_FACET_PATTERN;
- } else if (IS_SCHEMA(node, "enumeration")) {
- facet->type = XML_SCHEMA_FACET_ENUMERATION;
- } else if (IS_SCHEMA(node, "whiteSpace")) {
- facet->type = XML_SCHEMA_FACET_WHITESPACE;
- } else if (IS_SCHEMA(node, "length")) {
- facet->type = XML_SCHEMA_FACET_LENGTH;
- } else if (IS_SCHEMA(node, "maxLength")) {
- facet->type = XML_SCHEMA_FACET_MAXLENGTH;
- } else if (IS_SCHEMA(node, "minLength")) {
- facet->type = XML_SCHEMA_FACET_MINLENGTH;
- } else {
- xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_TYPE,
- "Unknown facet type %s\n", node->name, NULL);
- xmlSchemaFreeFacet(facet);
- return (NULL);
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- facet->value = value;
- if ((facet->type != XML_SCHEMA_FACET_PATTERN) &&
- (facet->type != XML_SCHEMA_FACET_ENUMERATION)) {
- const xmlChar *fixed;
- fixed = xmlSchemaGetProp(ctxt, node, "fixed");
- if (fixed != NULL) {
- if (xmlStrEqual(fixed, BAD_CAST "true"))
- facet->fixed = 1;
- }
- }
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- facet->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_UNKNOWN_FACET_CHILD,
- "Facet %s has unexpected child content\n",
- node->name, NULL);
- }
- return (facet);
- }
- static int
- xmlSchemaParseWildcardNs(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema ATTRIBUTE_UNUSED,
- xmlSchemaWildcardPtr wildc,
- xmlNodePtr node)
- {
- const xmlChar *pc, *ns, *dictnsItem;
- int ret = 0;
- xmlChar *nsItem;
- xmlSchemaWildcardNsPtr tmp, lastNs = NULL;
- xmlAttrPtr attr;
- pc = xmlSchemaGetProp(ctxt, node, "processContents");
- if ((pc == NULL)
- || (xmlStrEqual(pc, (const xmlChar *) "strict"))) {
- wildc->processContents = XML_SCHEMAS_ANY_STRICT;
- } else if (xmlStrEqual(pc, (const xmlChar *) "skip")) {
- wildc->processContents = XML_SCHEMAS_ANY_SKIP;
- } else if (xmlStrEqual(pc, (const xmlChar *) "lax")) {
- wildc->processContents = XML_SCHEMAS_ANY_LAX;
- } else {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, node,
- NULL, "(strict | skip | lax)", pc,
- NULL, NULL, NULL);
- wildc->processContents = XML_SCHEMAS_ANY_STRICT;
- ret = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
- }
-
- attr = xmlSchemaGetPropNode(node, "namespace");
- ns = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if ((attr == NULL) || (xmlStrEqual(ns, BAD_CAST "##any")))
- wildc->any = 1;
- else if (xmlStrEqual(ns, BAD_CAST "##other")) {
- wildc->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (wildc->negNsSet == NULL) {
- return (-1);
- }
- wildc->negNsSet->value = ctxt->targetNamespace;
- } else {
- const xmlChar *end, *cur;
- cur = ns;
- do {
- while (IS_BLANK_CH(*cur))
- cur++;
- end = cur;
- while ((*end != 0) && (!(IS_BLANK_CH(*end))))
- end++;
- if (end == cur)
- break;
- nsItem = xmlStrndup(cur, end - cur);
- if ((xmlStrEqual(nsItem, BAD_CAST "##other")) ||
- (xmlStrEqual(nsItem, BAD_CAST "##any"))) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER,
- NULL, (xmlNodePtr) attr,
- NULL,
- "((##any | ##other) | List of (xs:anyURI | "
- "(##targetNamespace | ##local)))",
- nsItem, NULL, NULL, NULL);
- ret = XML_SCHEMAP_WILDCARD_INVALID_NS_MEMBER;
- } else {
- if (xmlStrEqual(nsItem, BAD_CAST "##targetNamespace")) {
- dictnsItem = ctxt->targetNamespace;
- } else if (xmlStrEqual(nsItem, BAD_CAST "##local")) {
- dictnsItem = NULL;
- } else {
-
- xmlSchemaPValAttrNodeValue(ctxt, NULL, attr,
- nsItem, xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI));
- dictnsItem = xmlDictLookup(ctxt->dict, nsItem, -1);
- }
-
- tmp = wildc->nsSet;
- while (tmp != NULL) {
- if (dictnsItem == tmp->value)
- break;
- tmp = tmp->next;
- }
- if (tmp == NULL) {
- tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (tmp == NULL) {
- xmlFree(nsItem);
- return (-1);
- }
- tmp->value = dictnsItem;
- tmp->next = NULL;
- if (wildc->nsSet == NULL)
- wildc->nsSet = tmp;
- else if (lastNs != NULL)
- lastNs->next = tmp;
- lastNs = tmp;
- }
- }
- xmlFree(nsItem);
- cur = end;
- } while (*cur != 0);
- }
- return (ret);
- }
- static int
- xmlSchemaPCheckParticleCorrect_2(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr item ATTRIBUTE_UNUSED,
- xmlNodePtr node,
- int minOccurs,
- int maxOccurs) {
- if ((maxOccurs == 0) && ( minOccurs == 0))
- return (0);
- if (maxOccurs != UNBOUNDED) {
-
-
- if (maxOccurs < 1) {
-
- xmlSchemaPCustomAttrErr(ctxt,
- XML_SCHEMAP_P_PROPS_CORRECT_2_2,
- NULL, NULL,
- xmlSchemaGetPropNode(node, "maxOccurs"),
- "The value must be greater than or equal to 1");
- return (XML_SCHEMAP_P_PROPS_CORRECT_2_2);
- } else if (minOccurs > maxOccurs) {
-
- xmlSchemaPCustomAttrErr(ctxt,
- XML_SCHEMAP_P_PROPS_CORRECT_2_1,
- NULL, NULL,
- xmlSchemaGetPropNode(node, "minOccurs"),
- "The value must not be greater than the value of 'maxOccurs'");
- return (XML_SCHEMAP_P_PROPS_CORRECT_2_1);
- }
- }
- return (0);
- }
- static xmlSchemaParticlePtr
- xmlSchemaParseAny(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaParticlePtr particle;
- xmlNodePtr child = NULL;
- xmlSchemaWildcardPtr wild;
- int min, max;
- xmlAttrPtr attr;
- xmlSchemaAnnotPtr annot = NULL;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
- "(xs:nonNegativeInteger | unbounded)");
- min = xmlGetMinOccurs(ctxt, node, 0, -1, 1,
- "xs:nonNegativeInteger");
- xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
-
- wild = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY, node);
- if (wild == NULL)
- return (NULL);
- xmlSchemaParseWildcardNs(ctxt, schema, wild, node);
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?)");
- }
-
- if ((min == 0) && (max == 0)) {
-
- return (NULL);
- }
-
- particle = xmlSchemaAddParticle(ctxt, node, min, max);
- if (particle == NULL)
- return (NULL);
- particle->annot = annot;
- particle->children = (xmlSchemaTreeItemPtr) wild;
- return (particle);
- }
- static xmlSchemaNotationPtr
- xmlSchemaParseNotation(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- const xmlChar *name;
- xmlSchemaNotationPtr ret;
- xmlNodePtr child = NULL;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- name = xmlSchemaGetProp(ctxt, node, "name");
- if (name == NULL) {
- xmlSchemaPErr2(ctxt, node, child, XML_SCHEMAP_NOTATION_NO_NAME,
- "Notation has no name\n", NULL, NULL);
- return (NULL);
- }
- ret = xmlSchemaAddNotation(ctxt, schema, name,
- ctxt->targetNamespace, node);
- if (ret == NULL)
- return (NULL);
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?)");
- }
- return (ret);
- }
- static xmlSchemaWildcardPtr
- xmlSchemaParseAnyAttribute(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema, xmlNodePtr node)
- {
- xmlSchemaWildcardPtr ret;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- ret = xmlSchemaAddWildcard(ctxt, schema, XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
- node);
- if (ret == NULL) {
- return (NULL);
- }
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "processContents"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- if (xmlSchemaParseWildcardNs(ctxt, schema, ret, node) != 0)
- return (NULL);
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- ret->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?)");
- }
- return (ret);
- }
- static xmlSchemaBasicItemPtr
- xmlSchemaParseLocalAttribute(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- xmlSchemaItemListPtr uses,
- int parentType)
- {
- const xmlChar *attrValue, *name = NULL, *ns = NULL;
- xmlSchemaAttributeUsePtr use = NULL;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- const xmlChar *tmpNs = NULL, *tmpName = NULL, *defValue = NULL;
- int isRef = 0, occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
- int nberrors, hasForm = 0, defValueType = 0;
- #define WXS_ATTR_DEF_VAL_DEFAULT 1
- #define WXS_ATTR_DEF_VAL_FIXED 2
-
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- attr = xmlSchemaGetPropNode(node, "ref");
- if (attr != NULL) {
- if (xmlSchemaPValAttrNodeQName(pctxt, schema,
- NULL, attr, &tmpNs, &tmpName) != 0) {
- return (NULL);
- }
- if (xmlSchemaCheckReference(pctxt, schema, node, attr, tmpNs) != 0)
- return(NULL);
- isRef = 1;
- }
- nberrors = pctxt->nberrors;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if (isRef) {
- if (xmlStrEqual(attr->name, BAD_CAST "id")) {
- xmlSchemaPValAttrNodeID(pctxt, attr);
- goto attr_next;
- } else if (xmlStrEqual(attr->name, BAD_CAST "ref")) {
- goto attr_next;
- }
- } else {
- if (xmlStrEqual(attr->name, BAD_CAST "name")) {
- goto attr_next;
- } else if (xmlStrEqual(attr->name, BAD_CAST "id")) {
- xmlSchemaPValAttrNodeID(pctxt, attr);
- goto attr_next;
- } else if (xmlStrEqual(attr->name, BAD_CAST "type")) {
- xmlSchemaPValAttrNodeQName(pctxt, schema, NULL,
- attr, &tmpNs, &tmpName);
- goto attr_next;
- } else if (xmlStrEqual(attr->name, BAD_CAST "form")) {
-
- hasForm = 1;
- attrValue = xmlSchemaGetNodeContent(pctxt,
- (xmlNodePtr) attr);
- if (xmlStrEqual(attrValue, BAD_CAST "qualified")) {
- ns = pctxt->targetNamespace;
- } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified"))
- {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr,
- NULL, "(qualified | unqualified)",
- attrValue, NULL, NULL, NULL);
- }
- goto attr_next;
- }
- }
- if (xmlStrEqual(attr->name, BAD_CAST "use")) {
- attrValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
-
- if (xmlStrEqual(attrValue, BAD_CAST "optional"))
- occurs = XML_SCHEMAS_ATTR_USE_OPTIONAL;
- else if (xmlStrEqual(attrValue, BAD_CAST "prohibited"))
- occurs = XML_SCHEMAS_ATTR_USE_PROHIBITED;
- else if (xmlStrEqual(attrValue, BAD_CAST "required"))
- occurs = XML_SCHEMAS_ATTR_USE_REQUIRED;
- else {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_INVALID_ATTR_USE,
- NULL, (xmlNodePtr) attr,
- NULL, "(optional | prohibited | required)",
- attrValue, NULL, NULL, NULL);
- }
- goto attr_next;
- } else if (xmlStrEqual(attr->name, BAD_CAST "default")) {
-
- if (defValue) {
- xmlSchemaPMutualExclAttrErr(pctxt,
- XML_SCHEMAP_SRC_ATTRIBUTE_1,
- NULL, attr, "default", "fixed");
- } else {
- defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
- defValueType = WXS_ATTR_DEF_VAL_DEFAULT;
- }
- goto attr_next;
- } else if (xmlStrEqual(attr->name, BAD_CAST "fixed")) {
-
- if (defValue) {
- xmlSchemaPMutualExclAttrErr(pctxt,
- XML_SCHEMAP_SRC_ATTRIBUTE_1,
- NULL, attr, "default", "fixed");
- } else {
- defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
- defValueType = WXS_ATTR_DEF_VAL_FIXED;
- }
- goto attr_next;
- }
- } else if (! xmlStrEqual(attr->ns->href, xmlSchemaNs))
- goto attr_next;
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- attr_next:
- attr = attr->next;
- }
-
- if ((defValueType == WXS_ATTR_DEF_VAL_DEFAULT) &&
- (occurs != XML_SCHEMAS_ATTR_USE_OPTIONAL)) {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_SRC_ATTRIBUTE_2,
- NULL, node, NULL,
- "(optional | prohibited | required)", NULL,
- "The value of the attribute 'use' must be 'optional' "
- "if the attribute 'default' is present",
- NULL, NULL);
- }
-
- if (nberrors != pctxt->nberrors)
- return(NULL);
- if (! isRef) {
- xmlSchemaAttributePtr attrDecl;
-
- if ((! hasForm) && (schema->flags & XML_SCHEMAS_QUALIF_ATTR))
- ns = pctxt->targetNamespace;
-
- if (xmlStrEqual(ns, xmlSchemaInstanceNs)) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_NO_XSI,
- node, NULL,
- "The target namespace must not match '%s'",
- xmlSchemaInstanceNs, NULL);
- }
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "name", NULL);
- return (NULL);
- }
- if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
- return (NULL);
- }
-
- if (xmlStrEqual(name, BAD_CAST "xmlns")) {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_NO_XMLNS,
- NULL, (xmlNodePtr) attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL,
- "The value of the attribute must not match 'xmlns'",
- NULL, NULL);
- return (NULL);
- }
- if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED)
- goto check_children;
-
- use = xmlSchemaAddAttributeUse(pctxt, node);
- if (use == NULL)
- return(NULL);
- use->occurs = occurs;
-
- attrDecl = xmlSchemaAddAttribute(pctxt, schema, name, ns, node, 0);
- if (attrDecl == NULL)
- return (NULL);
- if (tmpName != NULL) {
- attrDecl->typeName = tmpName;
- attrDecl->typeNs = tmpNs;
- }
- use->attrDecl = attrDecl;
-
- if (defValue != NULL) {
- attrDecl->defValue = defValue;
- if (defValueType == WXS_ATTR_DEF_VAL_FIXED)
- attrDecl->flags |= XML_SCHEMAS_ATTR_FIXED;
- }
- } else if (occurs != XML_SCHEMAS_ATTR_USE_PROHIBITED) {
- xmlSchemaQNameRefPtr ref;
-
- use = xmlSchemaAddAttributeUse(pctxt, node);
- if (use == NULL)
- return(NULL);
-
- WXS_ADD_PENDING(pctxt, use);
- use->occurs = occurs;
-
- ref = xmlSchemaNewQNameRef(pctxt, XML_SCHEMA_TYPE_ATTRIBUTE,
- tmpName, tmpNs);
- if (ref == NULL)
- return(NULL);
-
- use->attrDecl = WXS_ATTR_CAST ref;
-
- if (defValue != NULL)
- use->defValue = defValue;
- if (defValueType == WXS_ATTR_DEF_VAL_FIXED)
- use->flags |= XML_SCHEMA_ATTR_USE_FIXED;
- }
- check_children:
-
- child = node->children;
- if (occurs == XML_SCHEMAS_ATTR_USE_PROHIBITED) {
- xmlSchemaAttributeUseProhibPtr prohib;
- if (IS_SCHEMA(child, "annotation")) {
- xmlSchemaParseAnnotation(pctxt, child, 0);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(pctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?)");
- }
-
- if (parentType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) {
- xmlSchemaCustomWarning(ACTXT_CAST pctxt,
- XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
- node, NULL,
- "Skipping attribute use prohibition, since it is "
- "pointless inside an <attributeGroup>",
- NULL, NULL, NULL);
- return(NULL);
- } else if (parentType == XML_SCHEMA_TYPE_EXTENSION) {
- xmlSchemaCustomWarning(ACTXT_CAST pctxt,
- XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
- node, NULL,
- "Skipping attribute use prohibition, since it is "
- "pointless when extending a type",
- NULL, NULL, NULL);
- return(NULL);
- }
- if (! isRef) {
- tmpName = name;
- tmpNs = ns;
- }
-
- if (uses) {
- int i;
- for (i = 0; i < uses->nbItems; i++) {
- use = uses->items[i];
- if ((use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) &&
- (tmpName == (WXS_ATTR_PROHIB_CAST use)->name) &&
- (tmpNs == (WXS_ATTR_PROHIB_CAST use)->targetNamespace))
- {
- xmlChar *str = NULL;
- xmlSchemaCustomWarning(ACTXT_CAST pctxt,
- XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
- node, NULL,
- "Skipping duplicate attribute use prohibition '%s'",
- xmlSchemaFormatQName(&str, tmpNs, tmpName),
- NULL, NULL);
- FREE_AND_NULL(str)
- return(NULL);
- }
- }
- }
-
- prohib = xmlSchemaAddAttributeUseProhib(pctxt);
- if (prohib == NULL)
- return(NULL);
- prohib->node = node;
- prohib->name = tmpName;
- prohib->targetNamespace = tmpNs;
- if (isRef) {
-
- WXS_ADD_PENDING(pctxt, prohib);
- }
- return(WXS_BASIC_CAST prohib);
- } else {
- if (IS_SCHEMA(child, "annotation")) {
-
- use->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
- child = child->next;
- }
- if (isRef) {
- if (child != NULL) {
- if (IS_SCHEMA(child, "simpleType"))
-
- xmlSchemaPContentErr(pctxt,
- XML_SCHEMAP_SRC_ATTRIBUTE_3_2,
- NULL, node, child, NULL,
- "(annotation?)");
- else
- xmlSchemaPContentErr(pctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?)");
- }
- } else {
- if (IS_SCHEMA(child, "simpleType")) {
- if (WXS_ATTRUSE_DECL(use)->typeName != NULL) {
-
- xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4,
- NULL, node, child,
- "The attribute 'type' and the <simpleType> child "
- "are mutually exclusive", NULL);
- } else
- WXS_ATTRUSE_TYPEDEF(use) =
- xmlSchemaParseSimpleType(pctxt, schema, child, 0);
- child = child->next;
- }
- if (child != NULL)
- xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, simpleType?)");
- }
- }
- return (WXS_BASIC_CAST use);
- }
- static xmlSchemaAttributePtr
- xmlSchemaParseGlobalAttribute(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- const xmlChar *attrValue;
- xmlSchemaAttributePtr ret;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
-
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
-
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(pctxt, XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "name", NULL);
- return (NULL);
- }
- if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0) {
- return (NULL);
- }
-
- if (xmlStrEqual(attrValue, BAD_CAST "xmlns")) {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_NO_XMLNS,
- NULL, (xmlNodePtr) attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), NULL, NULL,
- "The value of the attribute must not match 'xmlns'",
- NULL, NULL);
- return (NULL);
- }
-
- if (xmlStrEqual(pctxt->targetNamespace, xmlSchemaInstanceNs)) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_NO_XSI, node, NULL,
- "The target namespace must not match '%s'",
- xmlSchemaInstanceNs, NULL);
- }
- ret = xmlSchemaAddAttribute(pctxt, schema, attrValue,
- pctxt->targetNamespace, node, 1);
- if (ret == NULL)
- return (NULL);
- ret->flags |= XML_SCHEMAS_ATTR_GLOBAL;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "default")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "fixed")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "type")))
- {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrQName(pctxt, schema, NULL,
- node, "type", &ret->typeNs, &ret->typeName);
- xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
-
- ret->defValue = xmlSchemaGetProp(pctxt, node, "fixed");
- if (ret->defValue != NULL)
- ret->flags |= XML_SCHEMAS_ATTR_FIXED;
-
- attr = xmlSchemaGetPropNode(node, "default");
- if (attr != NULL) {
-
- if (ret->flags & XML_SCHEMAS_ATTR_FIXED) {
- xmlSchemaPMutualExclAttrErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_1,
- WXS_BASIC_CAST ret, attr, "default", "fixed");
- } else
- ret->defValue = xmlSchemaGetNodeContent(pctxt, (xmlNodePtr) attr);
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
- child = child->next;
- }
- if (IS_SCHEMA(child, "simpleType")) {
- if (ret->typeName != NULL) {
-
- xmlSchemaPContentErr(pctxt, XML_SCHEMAP_SRC_ATTRIBUTE_4,
- NULL, node, child,
- "The attribute 'type' and the <simpleType> child "
- "are mutually exclusive", NULL);
- } else
- ret->subtypes = xmlSchemaParseSimpleType(pctxt, schema, child, 0);
- child = child->next;
- }
- if (child != NULL)
- xmlSchemaPContentErr(pctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, simpleType?)");
- return (ret);
- }
- static xmlSchemaQNameRefPtr
- xmlSchemaParseAttributeGroupRef(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaQNameRefPtr ret;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- const xmlChar *refNs = NULL, *ref = NULL;
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- attr = xmlSchemaGetPropNode(node, "ref");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "ref", NULL);
- return (NULL);
- }
- xmlSchemaPValAttrNodeQName(pctxt, schema,
- NULL, attr, &refNs, &ref);
- if (xmlSchemaCheckReference(pctxt, schema, node, attr, refNs) != 0)
- return(NULL);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "id")))
- {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaParseAnnotation(pctxt, child, 0);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(pctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?)");
- }
-
- if (pctxt->isRedefine && pctxt->redef &&
- (pctxt->redef->item->type ==
- XML_SCHEMA_TYPE_ATTRIBUTEGROUP) &&
- (ref == pctxt->redef->refName) &&
- (refNs == pctxt->redef->refTargetNs))
- {
-
- if (pctxt->redefCounter != 0) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_SRC_REDEFINE, node, NULL,
- "The redefining attribute group definition "
- "'%s' must not contain more than one "
- "reference to the redefined definition",
- xmlSchemaFormatQName(&str, refNs, ref), NULL);
- FREE_AND_NULL(str);
- return(NULL);
- }
- pctxt->redefCounter++;
-
- ret = xmlSchemaNewQNameRef(pctxt,
- XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs);
- if (ret == NULL)
- return(NULL);
- ret->node = node;
- pctxt->redef->reference = WXS_BASIC_CAST ret;
- } else {
-
- ret = xmlSchemaNewQNameRef(pctxt,
- XML_SCHEMA_TYPE_ATTRIBUTEGROUP, ref, refNs);
- if (ret == NULL)
- return(NULL);
- ret->node = node;
-
- WXS_ADD_PENDING(pctxt, ret);
- }
- return (ret);
- }
- static xmlSchemaAttributeGroupPtr
- xmlSchemaParseAttributeGroupDefinition(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- const xmlChar *name;
- xmlSchemaAttributeGroupPtr ret;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- int hasRefs = 0;
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "name", NULL);
- return (NULL);
- }
-
- if (xmlSchemaPValAttrNode(pctxt,
- NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
- return (NULL);
- }
- ret = xmlSchemaAddAttributeGroupDefinition(pctxt, schema,
- name, pctxt->targetNamespace, node);
- if (ret == NULL)
- return (NULL);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "id")))
- {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- ret->annot = xmlSchemaParseAnnotation(pctxt, child, 1);
- child = child->next;
- }
-
- if (xmlSchemaParseLocalAttributes(pctxt, schema, &child,
- (xmlSchemaItemListPtr *) &(ret->attrUses),
- XML_SCHEMA_TYPE_ATTRIBUTEGROUP, &hasRefs) == -1)
- return(NULL);
- if (hasRefs)
- ret->flags |= XML_SCHEMAS_ATTRGROUP_HAS_REFS;
-
- if (IS_SCHEMA(child, "anyAttribute")) {
- ret->attributeWildcard = xmlSchemaParseAnyAttribute(pctxt,
- schema, child);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(pctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, ((attribute | attributeGroup)*, anyAttribute?))");
- }
- return (ret);
- }
- static int
- xmlSchemaPValAttrFormDefault(const xmlChar *value,
- int *flags,
- int flagQualified)
- {
- if (xmlStrEqual(value, BAD_CAST "qualified")) {
- if ((*flags & flagQualified) == 0)
- *flags |= flagQualified;
- } else if (!xmlStrEqual(value, BAD_CAST "unqualified"))
- return (1);
- return (0);
- }
- static int
- xmlSchemaPValAttrBlockFinal(const xmlChar *value,
- int *flags,
- int flagAll,
- int flagExtension,
- int flagRestriction,
- int flagSubstitution,
- int flagList,
- int flagUnion)
- {
- int ret = 0;
-
- if ((flags == NULL) || (value == NULL))
- return (-1);
- if (value[0] == 0)
- return (0);
- if (xmlStrEqual(value, BAD_CAST "#all")) {
- if (flagAll != -1)
- *flags |= flagAll;
- else {
- if (flagExtension != -1)
- *flags |= flagExtension;
- if (flagRestriction != -1)
- *flags |= flagRestriction;
- if (flagSubstitution != -1)
- *flags |= flagSubstitution;
- if (flagList != -1)
- *flags |= flagList;
- if (flagUnion != -1)
- *flags |= flagUnion;
- }
- } else {
- const xmlChar *end, *cur = value;
- xmlChar *item;
- do {
- while (IS_BLANK_CH(*cur))
- cur++;
- end = cur;
- while ((*end != 0) && (!(IS_BLANK_CH(*end))))
- end++;
- if (end == cur)
- break;
- item = xmlStrndup(cur, end - cur);
- if (xmlStrEqual(item, BAD_CAST "extension")) {
- if (flagExtension != -1) {
- if ((*flags & flagExtension) == 0)
- *flags |= flagExtension;
- } else
- ret = 1;
- } else if (xmlStrEqual(item, BAD_CAST "restriction")) {
- if (flagRestriction != -1) {
- if ((*flags & flagRestriction) == 0)
- *flags |= flagRestriction;
- } else
- ret = 1;
- } else if (xmlStrEqual(item, BAD_CAST "substitution")) {
- if (flagSubstitution != -1) {
- if ((*flags & flagSubstitution) == 0)
- *flags |= flagSubstitution;
- } else
- ret = 1;
- } else if (xmlStrEqual(item, BAD_CAST "list")) {
- if (flagList != -1) {
- if ((*flags & flagList) == 0)
- *flags |= flagList;
- } else
- ret = 1;
- } else if (xmlStrEqual(item, BAD_CAST "union")) {
- if (flagUnion != -1) {
- if ((*flags & flagUnion) == 0)
- *flags |= flagUnion;
- } else
- ret = 1;
- } else
- ret = 1;
- if (item != NULL)
- xmlFree(item);
- cur = end;
- } while ((ret == 0) && (*cur != 0));
- }
- return (ret);
- }
- static int
- xmlSchemaCheckCSelectorXPath(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaIDCPtr idc,
- xmlSchemaIDCSelectPtr selector,
- xmlAttrPtr attr,
- int isField)
- {
- xmlNodePtr node;
-
- if (selector == NULL) {
- xmlSchemaPErr(ctxt, idc->node,
- XML_SCHEMAP_INTERNAL,
- "Internal error: xmlSchemaCheckCSelectorXPath, "
- "the selector is not specified.\n", NULL, NULL);
- return (-1);
- }
- if (attr == NULL)
- node = idc->node;
- else
- node = (xmlNodePtr) attr;
- if (selector->xpath == NULL) {
- xmlSchemaPCustomErr(ctxt,
-
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, node,
- "The XPath expression of the selector is not valid", NULL);
- return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE);
- } else {
- const xmlChar **nsArray = NULL;
- xmlNsPtr *nsList = NULL;
-
-
- if (attr == NULL)
- nsList = NULL;
- else
- nsList = xmlGetNsList(attr->doc, attr->parent);
-
- if (nsList != NULL) {
- int i, count = 0;
- for (i = 0; nsList[i] != NULL; i++)
- count++;
- nsArray = (const xmlChar **) xmlMalloc(
- (count * 2 + 1) * sizeof(const xmlChar *));
- if (nsArray == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating a namespace array",
- NULL);
- xmlFree(nsList);
- return (-1);
- }
- for (i = 0; i < count; i++) {
- nsArray[2 * i] = nsList[i]->href;
- nsArray[2 * i + 1] = nsList[i]->prefix;
- }
- nsArray[count * 2] = NULL;
- xmlFree(nsList);
- }
-
- if (isField)
- selector->xpathComp = (void *) xmlPatterncompile(selector->xpath,
- NULL, XML_PATTERN_XSFIELD, nsArray);
- else
- selector->xpathComp = (void *) xmlPatterncompile(selector->xpath,
- NULL, XML_PATTERN_XSSEL, nsArray);
- if (nsArray != NULL)
- xmlFree((xmlChar **) nsArray);
- if (selector->xpathComp == NULL) {
- xmlSchemaPCustomErr(ctxt,
-
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, node,
- "The XPath expression '%s' could not be "
- "compiled", selector->xpath);
- return (XML_SCHEMAP_S4S_ATTR_INVALID_VALUE);
- }
- }
- return (0);
- }
- #define ADD_ANNOTATION(annot) \
- xmlSchemaAnnotPtr cur = item->annot; \
- if (item->annot == NULL) { \
- item->annot = annot; \
- return (annot); \
- } \
- cur = item->annot; \
- if (cur->next != NULL) { \
- cur = cur->next; \
- } \
- cur->next = annot;
- static xmlSchemaAnnotPtr
- xmlSchemaAddAnnotation(xmlSchemaAnnotItemPtr annItem,
- xmlSchemaAnnotPtr annot)
- {
- if ((annItem == NULL) || (annot == NULL))
- return (NULL);
- switch (annItem->type) {
- case XML_SCHEMA_TYPE_ELEMENT: {
- xmlSchemaElementPtr item = (xmlSchemaElementPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE: {
- xmlSchemaAttributePtr item = (xmlSchemaAttributePtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_ANY_ATTRIBUTE:
- case XML_SCHEMA_TYPE_ANY: {
- xmlSchemaWildcardPtr item = (xmlSchemaWildcardPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_PARTICLE:
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- case XML_SCHEMA_TYPE_IDC_UNIQUE: {
- xmlSchemaAnnotItemPtr item = (xmlSchemaAnnotItemPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP: {
- xmlSchemaAttributeGroupPtr item =
- (xmlSchemaAttributeGroupPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_NOTATION: {
- xmlSchemaNotationPtr item = (xmlSchemaNotationPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_FACET_MININCLUSIVE:
- case XML_SCHEMA_FACET_MINEXCLUSIVE:
- case XML_SCHEMA_FACET_MAXINCLUSIVE:
- case XML_SCHEMA_FACET_MAXEXCLUSIVE:
- case XML_SCHEMA_FACET_TOTALDIGITS:
- case XML_SCHEMA_FACET_FRACTIONDIGITS:
- case XML_SCHEMA_FACET_PATTERN:
- case XML_SCHEMA_FACET_ENUMERATION:
- case XML_SCHEMA_FACET_WHITESPACE:
- case XML_SCHEMA_FACET_LENGTH:
- case XML_SCHEMA_FACET_MAXLENGTH:
- case XML_SCHEMA_FACET_MINLENGTH: {
- xmlSchemaFacetPtr item = (xmlSchemaFacetPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_SIMPLE:
- case XML_SCHEMA_TYPE_COMPLEX: {
- xmlSchemaTypePtr item = (xmlSchemaTypePtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_GROUP: {
- xmlSchemaModelGroupDefPtr item = (xmlSchemaModelGroupDefPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL: {
- xmlSchemaModelGroupPtr item = (xmlSchemaModelGroupPtr) annItem;
- ADD_ANNOTATION(annot)
- }
- break;
- default:
- xmlSchemaPCustomErr(NULL,
- XML_SCHEMAP_INTERNAL,
- NULL, NULL,
- "Internal error: xmlSchemaAddAnnotation, "
- "The item is not a annotated schema component", NULL);
- break;
- }
- return (annot);
- }
- static xmlSchemaIDCSelectPtr
- xmlSchemaParseIDCSelectorAndField(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaIDCPtr idc,
- xmlNodePtr node,
- int isField)
- {
- xmlSchemaIDCSelectPtr item;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "xpath"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- item = (xmlSchemaIDCSelectPtr) xmlMalloc(sizeof(xmlSchemaIDCSelect));
- if (item == NULL) {
- xmlSchemaPErrMemory(ctxt,
- "allocating a 'selector' of an identity-constraint definition",
- NULL);
- return (NULL);
- }
- memset(item, 0, sizeof(xmlSchemaIDCSelect));
-
- attr = xmlSchemaGetPropNode(node, "xpath");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node,
- "name", NULL);
- } else {
- item->xpath = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
-
- if (xmlSchemaCheckCSelectorXPath(ctxt, idc, item, attr,
- isField) == -1) {
- xmlSchemaPErr(ctxt,
- (xmlNodePtr) attr,
- XML_SCHEMAP_INTERNAL,
- "Internal error: xmlSchemaParseIDCSelectorAndField, "
- "validating the XPath expression of a IDC selector.\n",
- NULL, NULL);
- }
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) idc,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?)");
- }
- return (item);
- }
- static xmlSchemaIDCPtr
- xmlSchemaParseIDC(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- xmlSchemaTypeType idcCategory,
- const xmlChar *targetNamespace)
- {
- xmlSchemaIDCPtr item = NULL;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- const xmlChar *name = NULL;
- xmlSchemaIDCSelectPtr field = NULL, lastField = NULL;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
- ((idcCategory != XML_SCHEMA_TYPE_IDC_KEYREF) ||
- (!xmlStrEqual(attr->name, BAD_CAST "refer")))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node,
- "name", NULL);
- return (NULL);
- } else if (xmlSchemaPValAttrNode(ctxt,
- NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
- return (NULL);
- }
-
- item = xmlSchemaAddIDC(ctxt, schema, name, targetNamespace,
- idcCategory, node);
- if (item == NULL)
- return(NULL);
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- if (idcCategory == XML_SCHEMA_TYPE_IDC_KEYREF) {
-
- attr = xmlSchemaGetPropNode(node, "refer");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node,
- "refer", NULL);
- } else {
-
- item->ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_IDC_KEY,
- NULL, NULL);
- if (item->ref == NULL)
- return (NULL);
- xmlSchemaPValAttrNodeQName(ctxt, schema,
- NULL, attr,
- &(item->ref->targetNamespace),
- &(item->ref->name));
- xmlSchemaCheckReference(ctxt, schema, node, attr,
- item->ref->targetNamespace);
- }
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child == NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_MISSING,
- NULL, node, child,
- "A child element is missing",
- "(annotation?, (selector, field+))");
- }
-
- if (IS_SCHEMA(child, "selector")) {
- item->selector = xmlSchemaParseIDCSelectorAndField(ctxt,
- item, child, 0);
- child = child->next;
-
- if (IS_SCHEMA(child, "field")) {
- do {
- field = xmlSchemaParseIDCSelectorAndField(ctxt,
- item, child, 1);
- if (field != NULL) {
- field->index = item->nbFields;
- item->nbFields++;
- if (lastField != NULL)
- lastField->next = field;
- else
- item->fields = field;
- lastField = field;
- }
- child = child->next;
- } while (IS_SCHEMA(child, "field"));
- } else {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?, (selector, field+))");
- }
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?, (selector, field+))");
- }
- return (item);
- }
- static xmlSchemaBasicItemPtr
- xmlSchemaParseElement(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, int *isElemRef, int topLevel)
- {
- xmlSchemaElementPtr decl = NULL;
- xmlSchemaParticlePtr particle = NULL;
- xmlSchemaAnnotPtr annot = NULL;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr, nameAttr;
- int min, max, isRef = 0;
- xmlChar *des = NULL;
-
-
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- if (isElemRef != NULL)
- *isElemRef = 0;
-
- nameAttr = xmlSchemaGetPropNode(node, "name");
- attr = xmlSchemaGetPropNode(node, "ref");
- if ((topLevel) || (attr == NULL)) {
- if (nameAttr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "name", NULL);
- return (NULL);
- }
- } else
- isRef = 1;
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
-
- if (topLevel)
- goto declaration_part;
-
- min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
- max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1, "(xs:nonNegativeInteger | unbounded)");
- xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
- particle = xmlSchemaAddParticle(ctxt, node, min, max);
- if (particle == NULL)
- goto return_null;
-
- if (isRef) {
- const xmlChar *refNs = NULL, *ref = NULL;
- xmlSchemaQNameRefPtr refer = NULL;
-
- if (isElemRef != NULL)
- *isElemRef = 1;
- xmlSchemaPValAttrNodeQName(ctxt, schema,
- NULL, attr, &refNs, &ref);
- xmlSchemaCheckReference(ctxt, schema, node, attr, refNs);
-
- if (nameAttr != NULL) {
- xmlSchemaPMutualExclAttrErr(ctxt,
- XML_SCHEMAP_SRC_ELEMENT_2_1, NULL, nameAttr, "ref", "name");
- }
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if (xmlStrEqual(attr->name, BAD_CAST "ref") ||
- xmlStrEqual(attr->name, BAD_CAST "name") ||
- xmlStrEqual(attr->name, BAD_CAST "id") ||
- xmlStrEqual(attr->name, BAD_CAST "maxOccurs") ||
- xmlStrEqual(attr->name, BAD_CAST "minOccurs"))
- {
- attr = attr->next;
- continue;
- } else {
-
- xmlSchemaPCustomAttrErr(ctxt,
- XML_SCHEMAP_SRC_ELEMENT_2_2,
- NULL, NULL, attr,
- "Only the attributes 'minOccurs', 'maxOccurs' and "
- "'id' are allowed in addition to 'ref'");
- break;
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL, "(annotation?)");
- }
- if ((min == 0) && (max == 0))
- goto return_null;
-
- refer = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_ELEMENT,
- ref, refNs);
- if (refer == NULL)
- goto return_null;
- particle->children = (xmlSchemaTreeItemPtr) refer;
- particle->annot = annot;
-
- WXS_ADD_PENDING(ctxt, particle);
- return ((xmlSchemaBasicItemPtr) particle);
- }
-
- declaration_part:
- {
- const xmlChar *ns = NULL, *fixed, *name, *attrValue;
- xmlSchemaIDCPtr curIDC = NULL, lastIDC = NULL;
- if (xmlSchemaPValAttrNode(ctxt, NULL, nameAttr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0)
- goto return_null;
-
- if (topLevel) {
- ns = ctxt->targetNamespace;
- } else {
- attr = xmlSchemaGetPropNode(node, "form");
- if (attr != NULL) {
- attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if (xmlStrEqual(attrValue, BAD_CAST "qualified")) {
- ns = ctxt->targetNamespace;
- } else if (!xmlStrEqual(attrValue, BAD_CAST "unqualified")) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr,
- NULL, "(qualified | unqualified)",
- attrValue, NULL, NULL, NULL);
- }
- } else if (schema->flags & XML_SCHEMAS_QUALIF_ELEM)
- ns = ctxt->targetNamespace;
- }
- decl = xmlSchemaAddElement(ctxt, name, ns, node, topLevel);
- if (decl == NULL) {
- goto return_null;
- }
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "type")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "default")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "fixed")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "block")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "nillable")))
- {
- if (topLevel == 0) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "form")))
- {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if ((!xmlStrEqual(attr->name, BAD_CAST "final")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "abstract")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "substitutionGroup"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- if (topLevel) {
-
- decl->flags |= XML_SCHEMAS_ELEM_GLOBAL;
- decl->flags |= XML_SCHEMAS_ELEM_TOPLEVEL;
- xmlSchemaPValAttrQName(ctxt, schema,
- NULL, node, "substitutionGroup",
- &(decl->substGroupNs), &(decl->substGroup));
- if (xmlGetBooleanProp(ctxt, node, "abstract", 0))
- decl->flags |= XML_SCHEMAS_ELEM_ABSTRACT;
-
- attr = xmlSchemaGetPropNode(node, "final");
- if (attr == NULL) {
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
- decl->flags |= XML_SCHEMAS_ELEM_FINAL_EXTENSION;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
- decl->flags |= XML_SCHEMAS_ELEM_FINAL_RESTRICTION;
- } else {
- attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags),
- -1,
- XML_SCHEMAS_ELEM_FINAL_EXTENSION,
- XML_SCHEMAS_ELEM_FINAL_RESTRICTION, -1, -1, -1) != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr,
- NULL, "(#all | List of (extension | restriction))",
- attrValue, NULL, NULL, NULL);
- }
- }
- }
-
- attr = xmlSchemaGetPropNode(node, "block");
- if (attr == NULL) {
-
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
- decl->flags |= XML_SCHEMAS_ELEM_BLOCK_RESTRICTION;
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
- decl->flags |= XML_SCHEMAS_ELEM_BLOCK_EXTENSION;
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION)
- decl->flags |= XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION;
- } else {
- attrValue = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if (xmlSchemaPValAttrBlockFinal(attrValue, &(decl->flags),
- -1,
- XML_SCHEMAS_ELEM_BLOCK_EXTENSION,
- XML_SCHEMAS_ELEM_BLOCK_RESTRICTION,
- XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION, -1, -1) != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr,
- NULL, "(#all | List of (extension | "
- "restriction | substitution))", attrValue,
- NULL, NULL, NULL);
- }
- }
- if (xmlGetBooleanProp(ctxt, node, "nillable", 0))
- decl->flags |= XML_SCHEMAS_ELEM_NILLABLE;
- attr = xmlSchemaGetPropNode(node, "type");
- if (attr != NULL) {
- xmlSchemaPValAttrNodeQName(ctxt, schema,
- NULL, attr,
- &(decl->namedTypeNs), &(decl->namedType));
- xmlSchemaCheckReference(ctxt, schema, node,
- attr, decl->namedTypeNs);
- }
- decl->value = xmlSchemaGetProp(ctxt, node, "default");
- attr = xmlSchemaGetPropNode(node, "fixed");
- if (attr != NULL) {
- fixed = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- if (decl->value != NULL) {
-
- xmlSchemaPMutualExclAttrErr(ctxt,
- XML_SCHEMAP_SRC_ELEMENT_1,
- NULL, attr, "default", "fixed");
- } else {
- decl->flags |= XML_SCHEMAS_ELEM_FIXED;
- decl->value = fixed;
- }
- }
-
- if (IS_SCHEMA(child, "complexType")) {
-
- if (decl->namedType != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_SRC_ELEMENT_3,
- NULL, node, child,
- "The attribute 'type' and the <complexType> child are "
- "mutually exclusive", NULL);
- } else
- WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseComplexType(ctxt, schema, child, 0);
- child = child->next;
- } else if (IS_SCHEMA(child, "simpleType")) {
-
- if (decl->namedType != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_SRC_ELEMENT_3,
- NULL, node, child,
- "The attribute 'type' and the <simpleType> child are "
- "mutually exclusive", NULL);
- } else
- WXS_ELEM_TYPEDEF(decl) = xmlSchemaParseSimpleType(ctxt, schema, child, 0);
- child = child->next;
- }
- while ((IS_SCHEMA(child, "unique")) ||
- (IS_SCHEMA(child, "key")) || (IS_SCHEMA(child, "keyref"))) {
- if (IS_SCHEMA(child, "unique")) {
- curIDC = xmlSchemaParseIDC(ctxt, schema, child,
- XML_SCHEMA_TYPE_IDC_UNIQUE, decl->targetNamespace);
- } else if (IS_SCHEMA(child, "key")) {
- curIDC = xmlSchemaParseIDC(ctxt, schema, child,
- XML_SCHEMA_TYPE_IDC_KEY, decl->targetNamespace);
- } else if (IS_SCHEMA(child, "keyref")) {
- curIDC = xmlSchemaParseIDC(ctxt, schema, child,
- XML_SCHEMA_TYPE_IDC_KEYREF, decl->targetNamespace);
- }
- if (lastIDC != NULL)
- lastIDC->next = curIDC;
- else
- decl->idcs = (void *) curIDC;
- lastIDC = curIDC;
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?, ((simpleType | complexType)?, "
- "(unique | key | keyref)*))");
- }
- decl->annot = annot;
- }
-
- FREE_AND_NULL(des)
- if (topLevel)
- return ((xmlSchemaBasicItemPtr) decl);
- else {
- particle->children = (xmlSchemaTreeItemPtr) decl;
- return ((xmlSchemaBasicItemPtr) particle);
- }
- return_null:
- FREE_AND_NULL(des);
- if (annot != NULL) {
- if (particle != NULL)
- particle->annot = NULL;
- if (decl != NULL)
- decl->annot = NULL;
- xmlSchemaFreeAnnot(annot);
- }
- return (NULL);
- }
- static int
- xmlSchemaParseUnion(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaTypePtr type;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- const xmlChar *cur = NULL;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (-1);
-
- type = ctxt->ctxtType;
-
- type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
-
- type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "memberTypes"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- attr = xmlSchemaGetPropNode(node, "memberTypes");
- if (attr != NULL) {
- const xmlChar *end;
- xmlChar *tmp;
- const xmlChar *localName, *nsName;
- xmlSchemaTypeLinkPtr link, lastLink = NULL;
- xmlSchemaQNameRefPtr ref;
- cur = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- type->base = cur;
- do {
- while (IS_BLANK_CH(*cur))
- cur++;
- end = cur;
- while ((*end != 0) && (!(IS_BLANK_CH(*end))))
- end++;
- if (end == cur)
- break;
- tmp = xmlStrndup(cur, end - cur);
- if (xmlSchemaPValAttrNodeQNameValue(ctxt, schema,
- NULL, attr, BAD_CAST tmp, &nsName, &localName) == 0) {
-
- link = (xmlSchemaTypeLinkPtr)
- xmlMalloc(sizeof(xmlSchemaTypeLink));
- if (link == NULL) {
- xmlSchemaPErrMemory(ctxt, "xmlSchemaParseUnion, "
- "allocating a type link", NULL);
- return (-1);
- }
- link->type = NULL;
- link->next = NULL;
- if (lastLink == NULL)
- type->memberTypes = link;
- else
- lastLink->next = link;
- lastLink = link;
-
- ref = xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_SIMPLE,
- localName, nsName);
- if (ref == NULL) {
- FREE_AND_NULL(tmp)
- return (-1);
- }
-
- link->type = (xmlSchemaTypePtr) ref;
- }
- FREE_AND_NULL(tmp)
- cur = end;
- } while (*cur != 0);
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (IS_SCHEMA(child, "simpleType")) {
- xmlSchemaTypePtr subtype, last = NULL;
-
- while (IS_SCHEMA(child, "simpleType")) {
- subtype = (xmlSchemaTypePtr)
- xmlSchemaParseSimpleType(ctxt, schema, child, 0);
- if (subtype != NULL) {
- if (last == NULL) {
- type->subtypes = subtype;
- last = subtype;
- } else {
- last->next = subtype;
- last = subtype;
- }
- last->next = NULL;
- }
- child = child->next;
- }
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL, "(annotation?, simpleType*)");
- }
- if ((attr == NULL) && (type->subtypes == NULL)) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_UNION_MEMBERTYPES_OR_SIMPLETYPES,
- NULL, node,
- "Either the attribute 'memberTypes' or "
- "at least one <simpleType> child must be present", NULL);
- }
- return (0);
- }
- static xmlSchemaTypePtr
- xmlSchemaParseList(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaTypePtr type;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
-
- type = ctxt->ctxtType;
-
- type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
-
- type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "itemType"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- xmlSchemaPValAttrQName(ctxt, schema, NULL,
- node, "itemType", &(type->baseNs), &(type->base));
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (IS_SCHEMA(child, "simpleType")) {
-
- if (type->base != NULL) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
- NULL, node,
- "The attribute 'itemType' and the <simpleType> child "
- "are mutually exclusive", NULL);
- } else {
- type->subtypes = xmlSchemaParseSimpleType(ctxt, schema, child, 0);
- }
- child = child->next;
- } else if (type->base == NULL) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
- NULL, node,
- "Either the attribute 'itemType' or the <simpleType> child "
- "must be present", NULL);
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL, "(annotation?, simpleType?)");
- }
- if ((type->base == NULL) &&
- (type->subtypes == NULL) &&
- (xmlSchemaGetPropNode(node, "itemType") == NULL)) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_SIMPLE_TYPE_1,
- NULL, node,
- "Either the attribute 'itemType' or the <simpleType> child "
- "must be present", NULL);
- }
- return (NULL);
- }
- static xmlSchemaTypePtr
- xmlSchemaParseSimpleType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, int topLevel)
- {
- xmlSchemaTypePtr type, oldCtxtType;
- xmlNodePtr child = NULL;
- const xmlChar *attrValue = NULL;
- xmlAttrPtr attr;
- int hasRestriction = 0;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- if (topLevel) {
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node,
- "name", NULL);
- return (NULL);
- } else {
- if (xmlSchemaPValAttrNode(ctxt,
- NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &attrValue) != 0)
- return (NULL);
-
- if (ctxt->isS4S) {
- xmlSchemaTypePtr biType;
- if (ctxt->isRedefine) {
-
- xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
- NULL, node,
- "Redefinition of built-in simple types is not "
- "supported", NULL);
- return(NULL);
- }
- biType = xmlSchemaGetPredefinedType(attrValue, xmlSchemaNs);
- if (biType != NULL)
- return (biType);
- }
- }
- }
-
- if (topLevel == 0) {
- #ifdef ENABLE_NAMED_LOCALS
- char buf[40];
- #endif
-
- #ifdef ENABLE_NAMED_LOCALS
- snprintf(buf, 39, "#ST%d", ctxt->counter++ + 1);
- type = xmlSchemaAddType(ctxt, schema,
- XML_SCHEMA_TYPE_SIMPLE,
- xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1),
- ctxt->targetNamespace, node, 0);
- #else
- type = xmlSchemaAddType(ctxt, schema,
- XML_SCHEMA_TYPE_SIMPLE,
- NULL, ctxt->targetNamespace, node, 0);
- #endif
- if (type == NULL)
- return (NULL);
- type->type = XML_SCHEMA_TYPE_SIMPLE;
- type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if (!xmlStrEqual(attr->name, BAD_CAST "id")) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- } else {
-
- type = xmlSchemaAddType(ctxt, schema, XML_SCHEMA_TYPE_SIMPLE,
- attrValue, ctxt->targetNamespace, node, 1);
- if (type == NULL)
- return (NULL);
- type->type = XML_SCHEMA_TYPE_SIMPLE;
- type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
- type->flags |= XML_SCHEMAS_TYPE_GLOBAL;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "name")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "final"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- attr = xmlSchemaGetPropNode(node, "final");
- if (attr == NULL) {
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
- type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST)
- type->flags |= XML_SCHEMAS_TYPE_FINAL_LIST;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION)
- type->flags |= XML_SCHEMAS_TYPE_FINAL_UNION;
- } else {
- attrValue = xmlSchemaGetProp(ctxt, node, "final");
- if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags),
- -1, -1, XML_SCHEMAS_TYPE_FINAL_RESTRICTION, -1,
- XML_SCHEMAS_TYPE_FINAL_LIST,
- XML_SCHEMAS_TYPE_FINAL_UNION) != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- WXS_BASIC_CAST type, (xmlNodePtr) attr,
- NULL, "(#all | List of (list | union | restriction)",
- attrValue, NULL, NULL, NULL);
- }
- }
- }
- type->targetNamespace = ctxt->targetNamespace;
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- oldCtxtType = ctxt->ctxtType;
- ctxt->ctxtType = type;
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- type->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child == NULL) {
- xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_MISSING,
- NULL, node, child, NULL,
- "(annotation?, (restriction | list | union))");
- } else if (IS_SCHEMA(child, "restriction")) {
- xmlSchemaParseRestriction(ctxt, schema, child,
- XML_SCHEMA_TYPE_SIMPLE);
- hasRestriction = 1;
- child = child->next;
- } else if (IS_SCHEMA(child, "list")) {
- xmlSchemaParseList(ctxt, schema, child);
- child = child->next;
- } else if (IS_SCHEMA(child, "union")) {
- xmlSchemaParseUnion(ctxt, schema, child);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt, XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (restriction | list | union))");
- }
-
- if (topLevel && ctxt->isRedefine && (! hasRestriction)) {
- xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
- NULL, node, "This is a redefinition, thus the "
- "<simpleType> must have a <restriction> child", NULL);
- }
- ctxt->ctxtType = oldCtxtType;
- return (type);
- }
- static xmlSchemaTreeItemPtr
- xmlSchemaParseModelGroupDefRef(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaParticlePtr item;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- const xmlChar *ref = NULL, *refNs = NULL;
- int min, max;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- attr = xmlSchemaGetPropNode(node, "ref");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "ref", NULL);
- return (NULL);
- } else if (xmlSchemaPValAttrNodeQName(ctxt, schema, NULL,
- attr, &refNs, &ref) != 0) {
- return (NULL);
- }
- xmlSchemaCheckReference(ctxt, schema, node, attr, refNs);
- min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
- max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
- "(xs:nonNegativeInteger | unbounded)");
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "ref")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "minOccurs")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- item = xmlSchemaAddParticle(ctxt, node, min, max);
- if (item == NULL)
- return (NULL);
-
- item->children = (xmlSchemaTreeItemPtr)
- xmlSchemaNewQNameRef(ctxt, XML_SCHEMA_TYPE_GROUP, ref, refNs);
- xmlSchemaPCheckParticleCorrect_2(ctxt, item, node, min, max);
-
- child = node->children;
-
- if (IS_SCHEMA(child, "annotation")) {
-
- item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?)");
- }
-
- if ((min == 0) && (max == 0))
- return (NULL);
- return ((xmlSchemaTreeItemPtr) item);
- }
- static xmlSchemaModelGroupDefPtr
- xmlSchemaParseModelGroupDefinition(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlSchemaModelGroupDefPtr item;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- const xmlChar *name;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node,
- "name", NULL);
- return (NULL);
- } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
- return (NULL);
- }
- item = xmlSchemaAddModelGroupDefinition(ctxt, schema, name,
- ctxt->targetNamespace, node);
- if (item == NULL)
- return (NULL);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "name")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "id"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (IS_SCHEMA(child, "all")) {
- item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_ALL, 0);
- child = child->next;
- } else if (IS_SCHEMA(child, "choice")) {
- item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_CHOICE, 0);
- child = child->next;
- } else if (IS_SCHEMA(child, "sequence")) {
- item->children = xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_SEQUENCE, 0);
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (all | choice | sequence)?)");
- }
- return (item);
- }
- static void
- xmlSchemaCleanupDoc(xmlSchemaParserCtxtPtr ctxt, xmlNodePtr root)
- {
- xmlNodePtr delete, cur;
- if ((ctxt == NULL) || (root == NULL)) return;
-
- delete = NULL;
- cur = root;
- while (cur != NULL) {
- if (delete != NULL) {
- xmlUnlinkNode(delete);
- xmlFreeNode(delete);
- delete = NULL;
- }
- if (cur->type == XML_TEXT_NODE) {
- if (IS_BLANK_NODE(cur)) {
- if (xmlNodeGetSpacePreserve(cur) != 1) {
- delete = cur;
- }
- }
- } else if ((cur->type != XML_ELEMENT_NODE) &&
- (cur->type != XML_CDATA_SECTION_NODE)) {
- delete = cur;
- goto skip_children;
- }
-
- if (cur->children != NULL) {
- if ((cur->children->type != XML_ENTITY_DECL) &&
- (cur->children->type != XML_ENTITY_REF_NODE) &&
- (cur->children->type != XML_ENTITY_NODE)) {
- cur = cur->children;
- continue;
- }
- }
- skip_children:
- if (cur->next != NULL) {
- cur = cur->next;
- continue;
- }
- do {
- cur = cur->parent;
- if (cur == NULL)
- break;
- if (cur == root) {
- cur = NULL;
- break;
- }
- if (cur->next != NULL) {
- cur = cur->next;
- break;
- }
- } while (cur != NULL);
- }
- if (delete != NULL) {
- xmlUnlinkNode(delete);
- xmlFreeNode(delete);
- delete = NULL;
- }
- }
- static void
- xmlSchemaClearSchemaDefaults(xmlSchemaPtr schema)
- {
- if (schema->flags & XML_SCHEMAS_QUALIF_ELEM)
- schema->flags ^= XML_SCHEMAS_QUALIF_ELEM;
- if (schema->flags & XML_SCHEMAS_QUALIF_ATTR)
- schema->flags ^= XML_SCHEMAS_QUALIF_ATTR;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
- schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_EXTENSION;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
- schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_LIST)
- schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_LIST;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_UNION)
- schema->flags ^= XML_SCHEMAS_FINAL_DEFAULT_UNION;
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
- schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION;
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
- schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION;
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION)
- schema->flags ^= XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION;
- }
- static int
- xmlSchemaParseSchemaElement(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlAttrPtr attr;
- const xmlChar *val;
- int res = 0, oldErrs = ctxt->nberrors;
-
- res = xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- HFAILURE;
-
-
- attr = xmlSchemaGetPropNode(node, "targetNamespace");
- if (attr != NULL) {
- res = xmlSchemaPValAttrNode(ctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI), NULL);
- HFAILURE;
- if (res != 0) {
- ctxt->stop = XML_SCHEMAP_S4S_ATTR_INVALID_VALUE;
- goto exit;
- }
- }
- attr = xmlSchemaGetPropNode(node, "elementFormDefault");
- if (attr != NULL) {
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- res = xmlSchemaPValAttrFormDefault(val, &schema->flags,
- XML_SCHEMAS_QUALIF_ELEM);
- HFAILURE;
- if (res != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_ELEMFORMDEFAULT_VALUE,
- NULL, (xmlNodePtr) attr, NULL,
- "(qualified | unqualified)", val, NULL, NULL, NULL);
- }
- }
- attr = xmlSchemaGetPropNode(node, "attributeFormDefault");
- if (attr != NULL) {
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- res = xmlSchemaPValAttrFormDefault(val, &schema->flags,
- XML_SCHEMAS_QUALIF_ATTR);
- HFAILURE;
- if (res != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_ATTRFORMDEFAULT_VALUE,
- NULL, (xmlNodePtr) attr, NULL,
- "(qualified | unqualified)", val, NULL, NULL, NULL);
- }
- }
- attr = xmlSchemaGetPropNode(node, "finalDefault");
- if (attr != NULL) {
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1,
- XML_SCHEMAS_FINAL_DEFAULT_EXTENSION,
- XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION,
- -1,
- XML_SCHEMAS_FINAL_DEFAULT_LIST,
- XML_SCHEMAS_FINAL_DEFAULT_UNION);
- HFAILURE;
- if (res != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr, NULL,
- "(#all | List of (extension | restriction | list | union))",
- val, NULL, NULL, NULL);
- }
- }
- attr = xmlSchemaGetPropNode(node, "blockDefault");
- if (attr != NULL) {
- val = xmlSchemaGetNodeContent(ctxt, (xmlNodePtr) attr);
- res = xmlSchemaPValAttrBlockFinal(val, &(schema->flags), -1,
- XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION,
- XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION,
- XML_SCHEMAS_BLOCK_DEFAULT_SUBSTITUTION, -1, -1);
- HFAILURE;
- if (res != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr, NULL,
- "(#all | List of (extension | restriction | substitution))",
- val, NULL, NULL, NULL);
- }
- }
- exit:
- if (oldErrs != ctxt->nberrors)
- res = ctxt->err;
- return(res);
- exit_failure:
- return(-1);
- }
- static int
- xmlSchemaParseSchemaTopLevel(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema, xmlNodePtr nodes)
- {
- xmlNodePtr child;
- xmlSchemaAnnotPtr annot;
- int res = 0, oldErrs, tmpOldErrs;
- if ((ctxt == NULL) || (schema == NULL) || (nodes == NULL))
- return(-1);
- oldErrs = ctxt->nberrors;
- child = nodes;
- while ((IS_SCHEMA(child, "include")) ||
- (IS_SCHEMA(child, "import")) ||
- (IS_SCHEMA(child, "redefine")) ||
- (IS_SCHEMA(child, "annotation"))) {
- if (IS_SCHEMA(child, "annotation")) {
- annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- if (schema->annot == NULL)
- schema->annot = annot;
- else
- xmlSchemaFreeAnnot(annot);
- } else if (IS_SCHEMA(child, "import")) {
- tmpOldErrs = ctxt->nberrors;
- res = xmlSchemaParseImport(ctxt, schema, child);
- HFAILURE;
- HSTOP(ctxt);
- if (tmpOldErrs != ctxt->nberrors)
- goto exit;
- } else if (IS_SCHEMA(child, "include")) {
- tmpOldErrs = ctxt->nberrors;
- res = xmlSchemaParseInclude(ctxt, schema, child);
- HFAILURE;
- HSTOP(ctxt);
- if (tmpOldErrs != ctxt->nberrors)
- goto exit;
- } else if (IS_SCHEMA(child, "redefine")) {
- tmpOldErrs = ctxt->nberrors;
- res = xmlSchemaParseRedefine(ctxt, schema, child);
- HFAILURE;
- HSTOP(ctxt);
- if (tmpOldErrs != ctxt->nberrors)
- goto exit;
- }
- child = child->next;
- }
-
- while (child != NULL) {
- if (IS_SCHEMA(child, "complexType")) {
- xmlSchemaParseComplexType(ctxt, schema, child, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "simpleType")) {
- xmlSchemaParseSimpleType(ctxt, schema, child, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "element")) {
- xmlSchemaParseElement(ctxt, schema, child, NULL, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "attribute")) {
- xmlSchemaParseGlobalAttribute(ctxt, schema, child);
- child = child->next;
- } else if (IS_SCHEMA(child, "attributeGroup")) {
- xmlSchemaParseAttributeGroupDefinition(ctxt, schema, child);
- child = child->next;
- } else if (IS_SCHEMA(child, "group")) {
- xmlSchemaParseModelGroupDefinition(ctxt, schema, child);
- child = child->next;
- } else if (IS_SCHEMA(child, "notation")) {
- xmlSchemaParseNotation(ctxt, schema, child);
- child = child->next;
- } else {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, child->parent, child,
- NULL, "((include | import | redefine | annotation)*, "
- "(((simpleType | complexType | group | attributeGroup) "
- "| element | attribute | notation), annotation*)*)");
- child = child->next;
- }
- while (IS_SCHEMA(child, "annotation")) {
-
- annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- if (schema->annot == NULL)
- schema->annot = annot;
- else
- xmlSchemaFreeAnnot(annot);
- child = child->next;
- }
- }
- exit:
- ctxt->ctxtType = NULL;
- if (oldErrs != ctxt->nberrors)
- res = ctxt->err;
- return(res);
- exit_failure:
- return(-1);
- }
- static xmlSchemaSchemaRelationPtr
- xmlSchemaSchemaRelationCreate(void)
- {
- xmlSchemaSchemaRelationPtr ret;
- ret = (xmlSchemaSchemaRelationPtr)
- xmlMalloc(sizeof(xmlSchemaSchemaRelation));
- if (ret == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating schema relation", NULL);
- return(NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaSchemaRelation));
- return(ret);
- }
- #if 0
- static void
- xmlSchemaSchemaRelationFree(xmlSchemaSchemaRelationPtr rel)
- {
- xmlFree(rel);
- }
- #endif
- static void
- xmlSchemaRedefListFree(xmlSchemaRedefPtr redef)
- {
- xmlSchemaRedefPtr prev;
- while (redef != NULL) {
- prev = redef;
- redef = redef->next;
- xmlFree(prev);
- }
- }
- static void
- xmlSchemaConstructionCtxtFree(xmlSchemaConstructionCtxtPtr con)
- {
-
- if (con->buckets != NULL)
- xmlSchemaItemListFree(con->buckets);
- if (con->pending != NULL)
- xmlSchemaItemListFree(con->pending);
- if (con->substGroups != NULL)
- xmlHashFree(con->substGroups,
- (xmlHashDeallocator) xmlSchemaSubstGroupFree);
- if (con->redefs != NULL)
- xmlSchemaRedefListFree(con->redefs);
- if (con->dict != NULL)
- xmlDictFree(con->dict);
- xmlFree(con);
- }
- static xmlSchemaConstructionCtxtPtr
- xmlSchemaConstructionCtxtCreate(xmlDictPtr dict)
- {
- xmlSchemaConstructionCtxtPtr ret;
- ret = (xmlSchemaConstructionCtxtPtr)
- xmlMalloc(sizeof(xmlSchemaConstructionCtxt));
- if (ret == NULL) {
- xmlSchemaPErrMemory(NULL,
- "allocating schema construction context", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaConstructionCtxt));
- ret->buckets = xmlSchemaItemListCreate();
- if (ret->buckets == NULL) {
- xmlSchemaPErrMemory(NULL,
- "allocating list of schema buckets", NULL);
- xmlFree(ret);
- return (NULL);
- }
- ret->pending = xmlSchemaItemListCreate();
- if (ret->pending == NULL) {
- xmlSchemaPErrMemory(NULL,
- "allocating list of pending global components", NULL);
- xmlSchemaConstructionCtxtFree(ret);
- return (NULL);
- }
- ret->dict = dict;
- xmlDictReference(dict);
- return(ret);
- }
- static xmlSchemaParserCtxtPtr
- xmlSchemaParserCtxtCreate(void)
- {
- xmlSchemaParserCtxtPtr ret;
- ret = (xmlSchemaParserCtxtPtr) xmlMalloc(sizeof(xmlSchemaParserCtxt));
- if (ret == NULL) {
- xmlSchemaPErrMemory(NULL, "allocating schema parser context",
- NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaParserCtxt));
- ret->type = XML_SCHEMA_CTXT_PARSER;
- ret->attrProhibs = xmlSchemaItemListCreate();
- if (ret->attrProhibs == NULL) {
- xmlFree(ret);
- return(NULL);
- }
- return(ret);
- }
- static xmlSchemaParserCtxtPtr
- xmlSchemaNewParserCtxtUseDict(const char *URL, xmlDictPtr dict)
- {
- xmlSchemaParserCtxtPtr ret;
- ret = xmlSchemaParserCtxtCreate();
- if (ret == NULL)
- return (NULL);
- ret->dict = dict;
- xmlDictReference(dict);
- if (URL != NULL)
- ret->URL = xmlDictLookup(dict, (const xmlChar *) URL, -1);
- return (ret);
- }
- static int
- xmlSchemaCreatePCtxtOnVCtxt(xmlSchemaValidCtxtPtr vctxt)
- {
- if (vctxt->pctxt == NULL) {
- if (vctxt->schema != NULL)
- vctxt->pctxt =
- xmlSchemaNewParserCtxtUseDict("*", vctxt->schema->dict);
- else
- vctxt->pctxt = xmlSchemaNewParserCtxt("*");
- if (vctxt->pctxt == NULL) {
- VERROR_INT("xmlSchemaCreatePCtxtOnVCtxt",
- "failed to create a temp. parser context");
- return (-1);
- }
-
- xmlSchemaSetParserErrors(vctxt->pctxt, vctxt->error,
- vctxt->warning, vctxt->errCtxt);
- xmlSchemaSetParserStructuredErrors(vctxt->pctxt, vctxt->serror,
- vctxt->errCtxt);
- }
- return (0);
- }
- static xmlSchemaBucketPtr
- xmlSchemaGetSchemaBucket(xmlSchemaParserCtxtPtr pctxt,
- const xmlChar *schemaLocation)
- {
- xmlSchemaBucketPtr cur;
- xmlSchemaItemListPtr list;
- list = pctxt->constructor->buckets;
- if (list->nbItems == 0)
- return(NULL);
- else {
- int i;
- for (i = 0; i < list->nbItems; i++) {
- cur = (xmlSchemaBucketPtr) list->items[i];
-
- if (cur->schemaLocation == schemaLocation)
- return(cur);
- }
- }
- return(NULL);
- }
- static xmlSchemaBucketPtr
- xmlSchemaGetChameleonSchemaBucket(xmlSchemaParserCtxtPtr pctxt,
- const xmlChar *schemaLocation,
- const xmlChar *targetNamespace)
- {
- xmlSchemaBucketPtr cur;
- xmlSchemaItemListPtr list;
- list = pctxt->constructor->buckets;
- if (list->nbItems == 0)
- return(NULL);
- else {
- int i;
- for (i = 0; i < list->nbItems; i++) {
- cur = (xmlSchemaBucketPtr) list->items[i];
-
- if ((cur->origTargetNamespace == NULL) &&
- (cur->schemaLocation == schemaLocation) &&
- (cur->targetNamespace == targetNamespace))
- return(cur);
- }
- }
- return(NULL);
- }
- #define IS_BAD_SCHEMA_DOC(b) \
- (((b)->doc == NULL) && ((b)->schemaLocation != NULL))
- static xmlSchemaBucketPtr
- xmlSchemaGetSchemaBucketByTNS(xmlSchemaParserCtxtPtr pctxt,
- const xmlChar *targetNamespace,
- int imported)
- {
- xmlSchemaBucketPtr cur;
- xmlSchemaItemListPtr list;
- list = pctxt->constructor->buckets;
- if (list->nbItems == 0)
- return(NULL);
- else {
- int i;
- for (i = 0; i < list->nbItems; i++) {
- cur = (xmlSchemaBucketPtr) list->items[i];
- if ((! IS_BAD_SCHEMA_DOC(cur)) &&
- (cur->origTargetNamespace == targetNamespace) &&
- ((imported && cur->imported) ||
- ((!imported) && (!cur->imported))))
- return(cur);
- }
- }
- return(NULL);
- }
- static int
- xmlSchemaParseNewDocWithContext(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlSchemaBucketPtr bucket)
- {
- int oldFlags;
- xmlDocPtr oldDoc;
- xmlNodePtr node;
- int ret, oldErrs;
- xmlSchemaBucketPtr oldbucket = pctxt->constructor->bucket;
-
- oldFlags = schema->flags;
- oldDoc = schema->doc;
- if (schema->flags != 0)
- xmlSchemaClearSchemaDefaults(schema);
- schema->doc = bucket->doc;
- pctxt->schema = schema;
-
- pctxt->targetNamespace = bucket->targetNamespace;
- WXS_CONSTRUCTOR(pctxt)->bucket = bucket;
- if ((bucket->targetNamespace != NULL) &&
- xmlStrEqual(bucket->targetNamespace, xmlSchemaNs)) {
-
- pctxt->isS4S = 1;
- }
-
- bucket->parsed++;
-
- node = xmlDocGetRootElement(bucket->doc);
- ret = xmlSchemaParseSchemaElement(pctxt, schema, node);
- if (ret != 0)
- goto exit;
-
- if (node->children == NULL)
- goto exit;
- oldErrs = pctxt->nberrors;
- ret = xmlSchemaParseSchemaTopLevel(pctxt, schema, node->children);
- if (ret != 0)
- goto exit;
-
- if ((ret == 0) && (oldErrs != pctxt->nberrors)) {
- ret = pctxt->err;
- goto exit;
- }
- exit:
- WXS_CONSTRUCTOR(pctxt)->bucket = oldbucket;
-
- schema->doc = oldDoc;
- schema->flags = oldFlags;
- return(ret);
- }
- static int
- xmlSchemaParseNewDoc(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlSchemaBucketPtr bucket)
- {
- xmlSchemaParserCtxtPtr newpctxt;
- int res = 0;
- if (bucket == NULL)
- return(0);
- if (bucket->parsed) {
- PERROR_INT("xmlSchemaParseNewDoc",
- "reparsing a schema doc");
- return(-1);
- }
- if (bucket->doc == NULL) {
- PERROR_INT("xmlSchemaParseNewDoc",
- "parsing a schema doc, but there's no doc");
- return(-1);
- }
- if (pctxt->constructor == NULL) {
- PERROR_INT("xmlSchemaParseNewDoc",
- "no constructor");
- return(-1);
- }
-
- newpctxt = xmlSchemaNewParserCtxtUseDict(
- (const char *) bucket->schemaLocation, pctxt->dict);
- if (newpctxt == NULL)
- return(-1);
- newpctxt->constructor = pctxt->constructor;
-
- newpctxt->schema = schema;
- xmlSchemaSetParserErrors(newpctxt, pctxt->error, pctxt->warning,
- pctxt->errCtxt);
- xmlSchemaSetParserStructuredErrors(newpctxt, pctxt->serror,
- pctxt->errCtxt);
- newpctxt->counter = pctxt->counter;
- res = xmlSchemaParseNewDocWithContext(newpctxt, schema, bucket);
-
- if (res != 0)
- pctxt->err = res;
- pctxt->nberrors += newpctxt->nberrors;
- pctxt->counter = newpctxt->counter;
- newpctxt->constructor = NULL;
-
- xmlSchemaFreeParserCtxt(newpctxt);
- return(res);
- }
- static void
- xmlSchemaSchemaRelationAddChild(xmlSchemaBucketPtr bucket,
- xmlSchemaSchemaRelationPtr rel)
- {
- xmlSchemaSchemaRelationPtr cur = bucket->relations;
- if (cur == NULL) {
- bucket->relations = rel;
- return;
- }
- while (cur->next != NULL)
- cur = cur->next;
- cur->next = rel;
- }
- static const xmlChar *
- xmlSchemaBuildAbsoluteURI(xmlDictPtr dict, const xmlChar* location,
- xmlNodePtr ctxtNode)
- {
-
- if (location != NULL) {
- if (ctxtNode == NULL)
- return(location);
- else {
- xmlChar *base, *URI;
- const xmlChar *ret = NULL;
- base = xmlNodeGetBase(ctxtNode->doc, ctxtNode);
- if (base == NULL) {
- URI = xmlBuildURI(location, ctxtNode->doc->URL);
- } else {
- URI = xmlBuildURI(location, base);
- xmlFree(base);
- }
- if (URI != NULL) {
- ret = xmlDictLookup(dict, URI, -1);
- xmlFree(URI);
- return(ret);
- }
- }
- }
- return(NULL);
- }
- static int
- xmlSchemaAddSchemaDoc(xmlSchemaParserCtxtPtr pctxt,
- int type,
- const xmlChar *schemaLocation,
- xmlDocPtr schemaDoc,
- const char *schemaBuffer,
- int schemaBufferLen,
- xmlNodePtr invokingNode,
- const xmlChar *sourceTargetNamespace,
- const xmlChar *importNamespace,
- xmlSchemaBucketPtr *bucket)
- {
- const xmlChar *targetNamespace = NULL;
- xmlSchemaSchemaRelationPtr relation = NULL;
- xmlDocPtr doc = NULL;
- int res = 0, err = 0, located = 0, preserveDoc = 0;
- xmlSchemaBucketPtr bkt = NULL;
- if (bucket != NULL)
- *bucket = NULL;
- switch (type) {
- case XML_SCHEMA_SCHEMA_IMPORT:
- case XML_SCHEMA_SCHEMA_MAIN:
- err = XML_SCHEMAP_SRC_IMPORT;
- break;
- case XML_SCHEMA_SCHEMA_INCLUDE:
- err = XML_SCHEMAP_SRC_INCLUDE;
- break;
- case XML_SCHEMA_SCHEMA_REDEFINE:
- err = XML_SCHEMAP_SRC_REDEFINE;
- break;
- }
-
- if ((type == XML_SCHEMA_SCHEMA_MAIN) || (! WXS_HAS_BUCKETS(pctxt)))
- goto doc_load;
-
- if (schemaLocation != NULL) {
- bkt = xmlSchemaGetSchemaBucket(pctxt, schemaLocation);
- if ((bkt != NULL) &&
- (pctxt->constructor->bucket == bkt)) {
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
- invokingNode, NULL,
- "The schema must not import/include/redefine itself",
- NULL, NULL);
- goto exit;
- }
- }
-
- relation = xmlSchemaSchemaRelationCreate();
- if (relation == NULL)
- return(-1);
- xmlSchemaSchemaRelationAddChild(pctxt->constructor->bucket,
- relation);
- relation->type = type;
-
- if (WXS_IS_BUCKET_IMPMAIN(type)) {
- relation->importNamespace = importNamespace;
- if (schemaLocation == NULL) {
-
- goto exit;
- }
- targetNamespace = importNamespace;
- }
-
- if (bkt != NULL) {
- if ((WXS_IS_BUCKET_IMPMAIN(type)) && (! bkt->imported)) {
-
- if (schemaLocation == NULL)
- schemaLocation = BAD_CAST "in_memory_buffer";
- if (!xmlStrEqual(schemaLocation,
- bkt->schemaLocation)) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
- invokingNode, NULL,
- "The schema document '%s' cannot be imported, since "
- "it was already included or redefined",
- schemaLocation, NULL);
- goto exit;
- }
- } else if ((! WXS_IS_BUCKET_IMPMAIN(type)) && (bkt->imported)) {
-
- if (schemaLocation == NULL)
- schemaLocation = BAD_CAST "in_memory_buffer";
- if (!xmlStrEqual(schemaLocation,
- bkt->schemaLocation)) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt, err,
- invokingNode, NULL,
- "The schema document '%s' cannot be included or "
- "redefined, since it was already imported",
- schemaLocation, NULL);
- goto exit;
- }
- }
- }
- if (WXS_IS_BUCKET_IMPMAIN(type)) {
-
- if (bkt != NULL) {
- relation->bucket = bkt;
- goto exit;
- }
- bkt = xmlSchemaGetSchemaBucketByTNS(pctxt,
- importNamespace, 1);
- if (bkt != NULL) {
- relation->bucket = bkt;
- if (bkt->schemaLocation == NULL) {
-
- bkt->schemaLocation = schemaLocation;
- } else {
- if (!xmlStrEqual(schemaLocation,
- bkt->schemaLocation)) {
-
- if (schemaLocation == NULL)
- schemaLocation = BAD_CAST "in_memory_buffer";
- xmlSchemaCustomWarning(ACTXT_CAST pctxt,
- XML_SCHEMAP_WARN_SKIP_SCHEMA,
- invokingNode, NULL,
- "Skipping import of schema located at '%s' for the "
- "namespace '%s', since this namespace was already "
- "imported with the schema located at '%s'",
- schemaLocation, importNamespace, bkt->schemaLocation);
- }
- goto exit;
- }
- }
-
- } else {
-
- if (bkt != NULL) {
- if ((bkt->origTargetNamespace == NULL) &&
- (bkt->targetNamespace != sourceTargetNamespace)) {
- xmlSchemaBucketPtr chamel;
-
-
- chamel = xmlSchemaGetChameleonSchemaBucket(pctxt,
- schemaLocation, sourceTargetNamespace);
- if (chamel != NULL) {
-
- relation->bucket = chamel;
- goto exit;
- }
-
- bkt = NULL;
- } else {
- relation->bucket = bkt;
- goto exit;
- }
- }
- }
- if ((bkt != NULL) && (bkt->doc != NULL)) {
- PERROR_INT("xmlSchemaAddSchemaDoc",
- "trying to load a schema doc, but a doc is already "
- "assigned to the schema bucket");
- goto exit_failure;
- }
- doc_load:
-
- if (schemaDoc != NULL) {
- doc = schemaDoc;
-
- preserveDoc = 1;
-
- if (schemaDoc->URL != NULL)
- schemaLocation = xmlDictLookup(pctxt->dict,
- schemaDoc->URL, -1);
- else
- schemaLocation = BAD_CAST "in_memory_buffer";
- } else if ((schemaLocation != NULL) || (schemaBuffer != NULL)) {
- xmlParserCtxtPtr parserCtxt;
- parserCtxt = xmlNewParserCtxt();
- if (parserCtxt == NULL) {
- xmlSchemaPErrMemory(NULL, "xmlSchemaGetDoc, "
- "allocating a parser context", NULL);
- goto exit_failure;
- }
- if ((pctxt->dict != NULL) && (parserCtxt->dict != NULL)) {
-
- xmlDictFree(parserCtxt->dict);
- parserCtxt->dict = pctxt->dict;
- xmlDictReference(parserCtxt->dict);
- }
- if (schemaLocation != NULL) {
-
- doc = xmlCtxtReadFile(parserCtxt, (const char *) schemaLocation,
- NULL, SCHEMAS_PARSE_OPTIONS);
- } else if (schemaBuffer != NULL) {
-
- doc = xmlCtxtReadMemory(parserCtxt, schemaBuffer, schemaBufferLen,
- NULL, NULL, SCHEMAS_PARSE_OPTIONS);
- schemaLocation = BAD_CAST "in_memory_buffer";
- if (doc != NULL)
- doc->URL = xmlStrdup(schemaLocation);
- }
-
- if (doc == NULL) {
- xmlErrorPtr lerr;
- lerr = xmlGetLastError();
-
- if ((lerr == NULL) || (lerr->domain != XML_FROM_IO)) {
-
- located = 1;
-
- res = XML_SCHEMAP_SRC_IMPORT_2_1;
- xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
- invokingNode, NULL,
- "Failed to parse the XML resource '%s'",
- schemaLocation, NULL);
- }
- }
- xmlFreeParserCtxt(parserCtxt);
- if ((doc == NULL) && located)
- goto exit_error;
- } else {
- xmlSchemaPErr(pctxt, NULL,
- XML_SCHEMAP_NOTHING_TO_PARSE,
- "No information for parsing was provided with the "
- "given schema parser context.\n",
- NULL, NULL);
- goto exit_failure;
- }
-
- if (doc != NULL) {
- xmlNodePtr docElem = NULL;
- located = 1;
- docElem = xmlDocGetRootElement(doc);
- if (docElem == NULL) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOROOT,
- invokingNode, NULL,
- "The document '%s' has no document element",
- schemaLocation, NULL);
- goto exit_error;
- }
-
- xmlSchemaCleanupDoc(pctxt, docElem);
-
- if (!IS_SCHEMA(docElem, "schema")) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt, XML_SCHEMAP_NOT_SCHEMA,
- invokingNode, NULL,
- "The XML document '%s' is not a schema document",
- schemaLocation, NULL);
- goto exit_error;
- }
-
- targetNamespace = xmlSchemaGetProp(pctxt, docElem,
- "targetNamespace");
- }
- if ((bkt == NULL) && located) {
-
- bkt = xmlSchemaBucketCreate(pctxt, type,
- targetNamespace);
- if (bkt == NULL)
- goto exit_failure;
- }
- if (bkt != NULL) {
- bkt->schemaLocation = schemaLocation;
- bkt->located = located;
- if (doc != NULL) {
- bkt->doc = doc;
- bkt->targetNamespace = targetNamespace;
- bkt->origTargetNamespace = targetNamespace;
- if (preserveDoc)
- bkt->preserveDoc = 1;
- }
- if (WXS_IS_BUCKET_IMPMAIN(type))
- bkt->imported++;
-
- if (relation != NULL)
- relation->bucket = bkt;
- }
- exit:
-
- if (bucket != NULL)
- *bucket = bkt;
- return (0);
- exit_error:
- if ((doc != NULL) && (! preserveDoc)) {
- xmlFreeDoc(doc);
- if (bkt != NULL)
- bkt->doc = NULL;
- }
- return(pctxt->err);
- exit_failure:
- if ((doc != NULL) && (! preserveDoc)) {
- xmlFreeDoc(doc);
- if (bkt != NULL)
- bkt->doc = NULL;
- }
- return (-1);
- }
- static int
- xmlSchemaParseImport(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- xmlNodePtr child;
- const xmlChar *namespaceName = NULL, *schemaLocation = NULL;
- const xmlChar *thisTargetNamespace;
- xmlAttrPtr attr;
- int ret = 0;
- xmlSchemaBucketPtr bucket = NULL;
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
- return (-1);
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "namespace")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- if (xmlSchemaPValAttr(pctxt, NULL, node,
- "namespace", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
- &namespaceName) != 0) {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, node,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
- NULL, namespaceName, NULL, NULL, NULL);
- return (pctxt->err);
- }
- if (xmlSchemaPValAttr(pctxt, NULL, node,
- "schemaLocation", xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
- &schemaLocation) != 0) {
- xmlSchemaPSimpleTypeErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, node,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
- NULL, namespaceName, NULL, NULL, NULL);
- return (pctxt->err);
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(pctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?)");
- }
-
- thisTargetNamespace = WXS_BUCKET(pctxt)->origTargetNamespace;
- if (namespaceName != NULL) {
-
- if (xmlStrEqual(thisTargetNamespace, namespaceName)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_SRC_IMPORT_1_1,
- NULL, node,
- "The value of the attribute 'namespace' must not match "
- "the target namespace '%s' of the importing schema",
- thisTargetNamespace);
- return (pctxt->err);
- }
- } else {
-
- if (thisTargetNamespace == NULL) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_SRC_IMPORT_1_2,
- NULL, node,
- "The attribute 'namespace' must be existent if "
- "the importing schema has no target namespace",
- NULL);
- return (pctxt->err);
- }
- }
-
- if (schemaLocation != NULL)
- schemaLocation = xmlSchemaBuildAbsoluteURI(pctxt->dict,
- schemaLocation, node);
- ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT,
- schemaLocation, NULL, NULL, 0, node, thisTargetNamespace,
- namespaceName, &bucket);
- if (ret != 0)
- return(ret);
-
- if ((bucket == NULL) && (schemaLocation != NULL)) {
- xmlSchemaCustomWarning(ACTXT_CAST pctxt,
- XML_SCHEMAP_WARN_UNLOCATED_SCHEMA,
- node, NULL,
- "Failed to locate a schema at location '%s'. "
- "Skipping the import", schemaLocation, NULL, NULL);
- }
- if ((bucket != NULL) && CAN_PARSE_SCHEMA(bucket)) {
- ret = xmlSchemaParseNewDoc(pctxt, schema, bucket);
- }
- return (ret);
- }
- static int
- xmlSchemaParseIncludeOrRedefineAttrs(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- xmlChar **schemaLocation,
- int type)
- {
- xmlAttrPtr attr;
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL) ||
- (schemaLocation == NULL))
- return (-1);
- *schemaLocation = NULL;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "schemaLocation"))) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(pctxt, node, BAD_CAST "id");
-
-
- attr = xmlSchemaGetPropNode(node, "schemaLocation");
- if (attr != NULL) {
- xmlChar *base = NULL;
- xmlChar *uri = NULL;
- if (xmlSchemaPValAttrNode(pctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYURI),
- (const xmlChar **) schemaLocation) != 0)
- goto exit_error;
- base = xmlNodeGetBase(node->doc, node);
- if (base == NULL) {
- uri = xmlBuildURI(*schemaLocation, node->doc->URL);
- } else {
- uri = xmlBuildURI(*schemaLocation, base);
- xmlFree(base);
- }
- if (uri == NULL) {
- PERROR_INT("xmlSchemaParseIncludeOrRedefine",
- "could not build an URI from the schemaLocation")
- goto exit_failure;
- }
- (*schemaLocation) = (xmlChar *) xmlDictLookup(pctxt->dict, uri, -1);
- xmlFree(uri);
- } else {
- xmlSchemaPMissingAttrErr(pctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "schemaLocation", NULL);
- goto exit_error;
- }
-
- if (xmlStrEqual(*schemaLocation, pctxt->URL)) {
- if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_SRC_REDEFINE,
- NULL, node,
- "The schema document '%s' cannot redefine itself.",
- *schemaLocation);
- } else {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_SRC_INCLUDE,
- NULL, node,
- "The schema document '%s' cannot include itself.",
- *schemaLocation);
- }
- goto exit_error;
- }
- return(0);
- exit_error:
- return(pctxt->err);
- exit_failure:
- return(-1);
- }
- static int
- xmlSchemaParseIncludeOrRedefine(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- int type)
- {
- xmlNodePtr child = NULL;
- const xmlChar *schemaLocation = NULL;
- int res = 0;
- int isChameleon = 0, wasChameleon = 0;
- xmlSchemaBucketPtr bucket = NULL;
- if ((pctxt == NULL) || (schema == NULL) || (node == NULL))
- return (-1);
-
- res = xmlSchemaParseIncludeOrRedefineAttrs(pctxt, schema,
- node, (xmlChar **) (&schemaLocation), type);
- if (res != 0)
- return(res);
-
- res = xmlSchemaAddSchemaDoc(pctxt, type, schemaLocation, NULL,
- NULL, 0, node, pctxt->targetNamespace, NULL, &bucket);
- if (res != 0)
- return(res);
-
- if ((bucket == NULL) || (bucket->doc == NULL)) {
- if (type == XML_SCHEMA_SCHEMA_INCLUDE) {
-
- res = XML_SCHEMAP_SRC_INCLUDE;
- xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
- node, NULL,
- "Failed to load the document '%s' for inclusion",
- schemaLocation, NULL);
- } else {
-
- res = XML_SCHEMAP_SRC_REDEFINE;
- xmlSchemaCustomErr(ACTXT_CAST pctxt, res,
- node, NULL,
- "Failed to load the document '%s' for redefinition",
- schemaLocation, NULL);
- }
- } else {
-
- if (bucket->origTargetNamespace != NULL) {
-
- if (pctxt->targetNamespace == NULL) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_SRC_INCLUDE,
- node, NULL,
- "The target namespace of the included/redefined schema "
- "'%s' has to be absent, since the including/redefining "
- "schema has no target namespace",
- schemaLocation, NULL);
- goto exit_error;
- } else if (!xmlStrEqual(bucket->origTargetNamespace,
- pctxt->targetNamespace)) {
-
- xmlSchemaPCustomErrExt(pctxt,
- XML_SCHEMAP_SRC_INCLUDE,
- NULL, node,
- "The target namespace '%s' of the included/redefined "
- "schema '%s' differs from '%s' of the "
- "including/redefining schema",
- bucket->origTargetNamespace, schemaLocation,
- pctxt->targetNamespace);
- goto exit_error;
- }
- } else if (pctxt->targetNamespace != NULL) {
-
- isChameleon = 1;
- if (bucket->parsed &&
- bucket->origTargetNamespace != NULL) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_SRC_INCLUDE,
- node, NULL,
- "The target namespace of the included/redefined schema "
- "'%s' has to be absent or the same as the "
- "including/redefining schema's target namespace",
- schemaLocation, NULL);
- goto exit_error;
- }
- bucket->targetNamespace = pctxt->targetNamespace;
- }
- }
-
- if (bucket && (!bucket->parsed) && (bucket->doc != NULL)) {
- if (isChameleon) {
-
- if ((schema->flags & XML_SCHEMAS_INCLUDING_CONVERT_NS) == 0) {
- schema->flags |= XML_SCHEMAS_INCLUDING_CONVERT_NS;
- } else
- wasChameleon = 1;
- }
- xmlSchemaParseNewDoc(pctxt, schema, bucket);
-
- if (isChameleon && (!wasChameleon))
- schema->flags ^= XML_SCHEMAS_INCLUDING_CONVERT_NS;
- }
-
- child = node->children;
- if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
-
- pctxt->redefined = bucket;
-
- pctxt->isRedefine = 1;
- while (IS_SCHEMA(child, "annotation") ||
- IS_SCHEMA(child, "simpleType") ||
- IS_SCHEMA(child, "complexType") ||
- IS_SCHEMA(child, "group") ||
- IS_SCHEMA(child, "attributeGroup")) {
- if (IS_SCHEMA(child, "annotation")) {
-
- } else if (IS_SCHEMA(child, "simpleType")) {
- xmlSchemaParseSimpleType(pctxt, schema, child, 1);
- } else if (IS_SCHEMA(child, "complexType")) {
- xmlSchemaParseComplexType(pctxt, schema, child, 1);
-
- } else if (IS_SCHEMA(child, "group")) {
-
- xmlSchemaParseModelGroupDefinition(pctxt,
- schema, child);
- } else if (IS_SCHEMA(child, "attributeGroup")) {
-
- xmlSchemaParseAttributeGroupDefinition(pctxt, schema,
- child);
- }
- child = child->next;
- }
- pctxt->redefined = NULL;
- pctxt->isRedefine = 0;
- } else {
- if (IS_SCHEMA(child, "annotation")) {
-
- child = child->next;
- }
- }
- if (child != NULL) {
- res = XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED;
- if (type == XML_SCHEMA_SCHEMA_REDEFINE) {
- xmlSchemaPContentErr(pctxt, res,
- NULL, node, child, NULL,
- "(annotation | (simpleType | complexType | group | attributeGroup))*");
- } else {
- xmlSchemaPContentErr(pctxt, res,
- NULL, node, child, NULL,
- "(annotation?)");
- }
- }
- return(res);
- exit_error:
- return(pctxt->err);
- }
- static int
- xmlSchemaParseRedefine(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- int res;
- #ifndef ENABLE_REDEFINE
- TODO
- return(0);
- #endif
- res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node,
- XML_SCHEMA_SCHEMA_REDEFINE);
- if (res != 0)
- return(res);
- return(0);
- }
- static int
- xmlSchemaParseInclude(xmlSchemaParserCtxtPtr pctxt, xmlSchemaPtr schema,
- xmlNodePtr node)
- {
- int res;
- res = xmlSchemaParseIncludeOrRedefine(pctxt, schema, node,
- XML_SCHEMA_SCHEMA_INCLUDE);
- if (res != 0)
- return(res);
- return(0);
- }
- static xmlSchemaTreeItemPtr
- xmlSchemaParseModelGroup(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, xmlSchemaTypeType type,
- int withParticle)
- {
- xmlSchemaModelGroupPtr item;
- xmlSchemaParticlePtr particle = NULL;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- int min = 1, max = 1, isElemRef, hasRefs = 0;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
-
- item = xmlSchemaAddModelGroup(ctxt, schema, type, node);
- if (item == NULL)
- return (NULL);
- if (withParticle) {
- if (type == XML_SCHEMA_TYPE_ALL) {
- min = xmlGetMinOccurs(ctxt, node, 0, 1, 1, "(0 | 1)");
- max = xmlGetMaxOccurs(ctxt, node, 1, 1, 1, "1");
- } else {
-
- min = xmlGetMinOccurs(ctxt, node, 0, -1, 1, "xs:nonNegativeInteger");
- max = xmlGetMaxOccurs(ctxt, node, 0, UNBOUNDED, 1,
- "(xs:nonNegativeInteger | unbounded)");
- }
- xmlSchemaPCheckParticleCorrect_2(ctxt, NULL, node, min, max);
-
- particle = xmlSchemaAddParticle(ctxt, node, min, max);
- if (particle == NULL)
- return (NULL);
- particle->children = (xmlSchemaTreeItemPtr) item;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "maxOccurs")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "minOccurs"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- } else {
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if (!xmlStrEqual(attr->name, BAD_CAST "id")) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- }
-
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- item->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- if (type == XML_SCHEMA_TYPE_ALL) {
- xmlSchemaParticlePtr part, last = NULL;
- while (IS_SCHEMA(child, "element")) {
- part = (xmlSchemaParticlePtr) xmlSchemaParseElement(ctxt,
- schema, child, &isElemRef, 0);
-
- if (part != NULL) {
- if (isElemRef)
- hasRefs++;
- if (part->minOccurs > 1) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_ALL_LIMITED,
- NULL, child,
- "Invalid value for minOccurs (must be 0 or 1)",
- NULL);
-
- part->minOccurs = 1;
- }
- if (part->maxOccurs > 1) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_ALL_LIMITED,
- NULL, child,
- "Invalid value for maxOccurs (must be 0 or 1)",
- NULL);
-
- part->maxOccurs = 1;
- }
- if (last == NULL)
- item->children = (xmlSchemaTreeItemPtr) part;
- else
- last->next = (xmlSchemaTreeItemPtr) part;
- last = part;
- }
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (annotation?, element*)");
- }
- } else {
-
- xmlSchemaTreeItemPtr part = NULL, last = NULL;
- while ((IS_SCHEMA(child, "element")) ||
- (IS_SCHEMA(child, "group")) ||
- (IS_SCHEMA(child, "any")) ||
- (IS_SCHEMA(child, "choice")) ||
- (IS_SCHEMA(child, "sequence"))) {
- if (IS_SCHEMA(child, "element")) {
- part = (xmlSchemaTreeItemPtr)
- xmlSchemaParseElement(ctxt, schema, child, &isElemRef, 0);
- if (part && isElemRef)
- hasRefs++;
- } else if (IS_SCHEMA(child, "group")) {
- part =
- xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
- if (part != NULL)
- hasRefs++;
-
- if (ctxt->isRedefine && ctxt->redef &&
- (ctxt->redef->item->type == XML_SCHEMA_TYPE_GROUP) &&
- part && part->children)
- {
- if ((xmlSchemaGetQNameRefName(part->children) ==
- ctxt->redef->refName) &&
- (xmlSchemaGetQNameRefTargetNs(part->children) ==
- ctxt->redef->refTargetNs))
- {
-
- if (ctxt->redefCounter != 0) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_SRC_REDEFINE, child, NULL,
- "The redefining model group definition "
- "'%s' must not contain more than one "
- "reference to the redefined definition",
- xmlSchemaFormatQName(&str,
- ctxt->redef->refTargetNs,
- ctxt->redef->refName),
- NULL);
- FREE_AND_NULL(str)
- part = NULL;
- } else if (((WXS_PARTICLE(part))->minOccurs != 1) ||
- ((WXS_PARTICLE(part))->maxOccurs != 1))
- {
- xmlChar *str = NULL;
-
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_SRC_REDEFINE, child, NULL,
- "The redefining model group definition "
- "'%s' must not contain a reference to the "
- "redefined definition with a "
- "maxOccurs/minOccurs other than 1",
- xmlSchemaFormatQName(&str,
- ctxt->redef->refTargetNs,
- ctxt->redef->refName),
- NULL);
- FREE_AND_NULL(str)
- part = NULL;
- }
- ctxt->redef->reference = WXS_BASIC_CAST part;
- ctxt->redefCounter++;
- }
- }
- } else if (IS_SCHEMA(child, "any")) {
- part = (xmlSchemaTreeItemPtr)
- xmlSchemaParseAny(ctxt, schema, child);
- } else if (IS_SCHEMA(child, "choice")) {
- part = xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_CHOICE, 1);
- } else if (IS_SCHEMA(child, "sequence")) {
- part = xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_SEQUENCE, 1);
- }
- if (part != NULL) {
- if (last == NULL)
- item->children = part;
- else
- last->next = part;
- last = part;
- }
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (element | group | choice | sequence | any)*)");
- }
- }
- if ((max == 0) && (min == 0))
- return (NULL);
- if (hasRefs) {
-
- WXS_ADD_PENDING(ctxt, item);
- }
- if (withParticle)
- return ((xmlSchemaTreeItemPtr) particle);
- else
- return ((xmlSchemaTreeItemPtr) item);
- }
- static xmlSchemaTypePtr
- xmlSchemaParseRestriction(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, xmlSchemaTypeType parentType)
- {
- xmlSchemaTypePtr type;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
-
- type = ctxt->ctxtType;
- type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "base"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
-
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
-
- if (xmlSchemaPValAttrQName(ctxt, schema, NULL, node, "base",
- &(type->baseNs), &(type->base)) == 0)
- {
- if ((type->base == NULL) && (type->type == XML_SCHEMA_TYPE_COMPLEX)) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "base", NULL);
- } else if ((ctxt->isRedefine) &&
- (type->flags & XML_SCHEMAS_TYPE_GLOBAL))
- {
- if (type->base == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "base", NULL);
- } else if ((! xmlStrEqual(type->base, type->name)) ||
- (! xmlStrEqual(type->baseNs, type->targetNamespace)))
- {
- xmlChar *str1 = NULL, *str2 = NULL;
-
- xmlSchemaPCustomErrExt(ctxt, XML_SCHEMAP_SRC_REDEFINE,
- NULL, node, "This is a redefinition, but the QName "
- "value '%s' of the 'base' attribute does not match the "
- "type's designation '%s'",
- xmlSchemaFormatQName(&str1, type->baseNs, type->base),
- xmlSchemaFormatQName(&str2, type->targetNamespace,
- type->name), NULL);
- FREE_AND_NULL(str1);
- FREE_AND_NULL(str2);
-
- type->base = NULL;
- type->baseNs = NULL;
- }
- }
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (parentType == XML_SCHEMA_TYPE_SIMPLE) {
-
- if (IS_SCHEMA(child, "simpleType")) {
- if (type->base != NULL) {
-
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE,
- NULL, node, child,
- "The attribute 'base' and the <simpleType> child are "
- "mutually exclusive", NULL);
- } else {
- type->baseType = (xmlSchemaTypePtr)
- xmlSchemaParseSimpleType(ctxt, schema, child, 0);
- }
- child = child->next;
- } else if (type->base == NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_SRC_RESTRICTION_BASE_OR_SIMPLETYPE,
- NULL, node, child,
- "Either the attribute 'base' or a <simpleType> child "
- "must be present", NULL);
- }
- } else if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
-
- if (IS_SCHEMA(child, "all")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_ALL, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "choice")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt,
- schema, child, XML_SCHEMA_TYPE_CHOICE, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "sequence")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_SEQUENCE, 1);
- child = child->next;
-
- } else if (IS_SCHEMA(child, "group")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
-
- child = child->next;
- }
- } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) {
-
- if (IS_SCHEMA(child, "simpleType")) {
-
- type->contentTypeDef = (xmlSchemaTypePtr)
- xmlSchemaParseSimpleType(ctxt, schema, child, 0);
- if ( type->contentTypeDef == NULL)
- return (NULL);
- child = child->next;
- }
- }
- if ((parentType == XML_SCHEMA_TYPE_SIMPLE) ||
- (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT)) {
- xmlSchemaFacetPtr facet, lastfacet = NULL;
-
-
-
- while ((IS_SCHEMA(child, "minInclusive")) ||
- (IS_SCHEMA(child, "minExclusive")) ||
- (IS_SCHEMA(child, "maxInclusive")) ||
- (IS_SCHEMA(child, "maxExclusive")) ||
- (IS_SCHEMA(child, "totalDigits")) ||
- (IS_SCHEMA(child, "fractionDigits")) ||
- (IS_SCHEMA(child, "pattern")) ||
- (IS_SCHEMA(child, "enumeration")) ||
- (IS_SCHEMA(child, "whiteSpace")) ||
- (IS_SCHEMA(child, "length")) ||
- (IS_SCHEMA(child, "maxLength")) ||
- (IS_SCHEMA(child, "minLength"))) {
- facet = xmlSchemaParseFacet(ctxt, schema, child);
- if (facet != NULL) {
- if (lastfacet == NULL)
- type->facets = facet;
- else
- lastfacet->next = facet;
- lastfacet = facet;
- lastfacet->next = NULL;
- }
- child = child->next;
- }
-
- if (type->facets != NULL) {
- xmlSchemaFacetLinkPtr facetLink, lastFacetLink = NULL;
- facet = type->facets;
- do {
- facetLink = (xmlSchemaFacetLinkPtr)
- xmlMalloc(sizeof(xmlSchemaFacetLink));
- if (facetLink == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating a facet link", NULL);
- xmlFree(facetLink);
- return (NULL);
- }
- facetLink->facet = facet;
- facetLink->next = NULL;
- if (lastFacetLink == NULL)
- type->facetSet = facetLink;
- else
- lastFacetLink->next = facetLink;
- lastFacetLink = facetLink;
- facet = facet->next;
- } while (facet != NULL);
- }
- }
- if (type->type == XML_SCHEMA_TYPE_COMPLEX) {
-
- if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
- (xmlSchemaItemListPtr *) &(type->attrUses),
- XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1)
- return(NULL);
-
- if (IS_SCHEMA(child, "anyAttribute")) {
- type->attributeWildcard =
- xmlSchemaParseAnyAttribute(ctxt, schema, child);
- child = child->next;
- }
- }
- if (child != NULL) {
- if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "annotation?, (group | all | choice | sequence)?, "
- "((attribute | attributeGroup)*, anyAttribute?))");
- } else if (parentType == XML_SCHEMA_TYPE_SIMPLE_CONTENT) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (simpleType?, (minExclusive | minInclusive | "
- "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
- "length | minLength | maxLength | enumeration | whiteSpace | "
- "pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))");
- } else {
-
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (simpleType?, (minExclusive | minInclusive | "
- "maxExclusive | maxInclusive | totalDigits | fractionDigits | "
- "length | minLength | maxLength | enumeration | whiteSpace | "
- "pattern)*))");
- }
- }
- return (NULL);
- }
- static xmlSchemaTypePtr
- xmlSchemaParseExtension(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, xmlSchemaTypeType parentType)
- {
- xmlSchemaTypePtr type;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
-
- type = ctxt->ctxtType;
- type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_EXTENSION;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "base"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- if ((xmlSchemaPValAttrQName(ctxt, schema, NULL, node,
- "base", &(type->baseNs), &(type->base)) == 0) &&
- (type->base == NULL)) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING,
- NULL, node, "base", NULL);
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
-
- if (IS_SCHEMA(child, "all")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema,
- child, XML_SCHEMA_TYPE_ALL, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "choice")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema,
- child, XML_SCHEMA_TYPE_CHOICE, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "sequence")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema,
- child, XML_SCHEMA_TYPE_SEQUENCE, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "group")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
-
- child = child->next;
- }
- }
- if (child != NULL) {
-
- if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
- (xmlSchemaItemListPtr *) &(type->attrUses),
- XML_SCHEMA_TYPE_EXTENSION, NULL) == -1)
- return(NULL);
-
- if (IS_SCHEMA(child, "anyAttribute")) {
- ctxt->ctxtType->attributeWildcard =
- xmlSchemaParseAnyAttribute(ctxt, schema, child);
- child = child->next;
- }
- }
- if (child != NULL) {
- if (parentType == XML_SCHEMA_TYPE_COMPLEX_CONTENT) {
-
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, ((group | all | choice | sequence)?, "
- "((attribute | attributeGroup)*, anyAttribute?)))");
- } else {
-
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, ((attribute | attributeGroup)*, "
- "anyAttribute?))");
- }
- }
- return (NULL);
- }
- static int
- xmlSchemaParseSimpleContent(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema, xmlNodePtr node,
- int *hasRestrictionOrExtension)
- {
- xmlSchemaTypePtr type;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL) ||
- (hasRestrictionOrExtension == NULL))
- return (-1);
- *hasRestrictionOrExtension = 0;
-
- type = ctxt->ctxtType;
- type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id"))) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (child == NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_MISSING,
- NULL, node, NULL, NULL,
- "(annotation?, (restriction | extension))");
- }
- if (child == NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_MISSING,
- NULL, node, NULL, NULL,
- "(annotation?, (restriction | extension))");
- }
- if (IS_SCHEMA(child, "restriction")) {
- xmlSchemaParseRestriction(ctxt, schema, child,
- XML_SCHEMA_TYPE_SIMPLE_CONTENT);
- (*hasRestrictionOrExtension) = 1;
- child = child->next;
- } else if (IS_SCHEMA(child, "extension")) {
- xmlSchemaParseExtension(ctxt, schema, child,
- XML_SCHEMA_TYPE_SIMPLE_CONTENT);
- (*hasRestrictionOrExtension) = 1;
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child, NULL,
- "(annotation?, (restriction | extension))");
- }
- return (0);
- }
- static int
- xmlSchemaParseComplexContent(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaPtr schema, xmlNodePtr node,
- int *hasRestrictionOrExtension)
- {
- xmlSchemaTypePtr type;
- xmlNodePtr child = NULL;
- xmlAttrPtr attr;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL) ||
- (hasRestrictionOrExtension == NULL))
- return (-1);
- *hasRestrictionOrExtension = 0;
-
- type = ctxt->ctxtType;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if ((!xmlStrEqual(attr->name, BAD_CAST "id")) &&
- (!xmlStrEqual(attr->name, BAD_CAST "mixed")))
- {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
-
- if (xmlGetBooleanProp(ctxt, node, "mixed", 0)) {
- if ((type->flags & XML_SCHEMAS_TYPE_MIXED) == 0)
- type->flags |= XML_SCHEMAS_TYPE_MIXED;
- }
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
-
- xmlSchemaAddAnnotation((xmlSchemaAnnotItemPtr) type,
- xmlSchemaParseAnnotation(ctxt, child, 1));
- child = child->next;
- }
- if (child == NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_MISSING,
- NULL, node, NULL,
- NULL, "(annotation?, (restriction | extension))");
- }
- if (child == NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_MISSING,
- NULL, node, NULL,
- NULL, "(annotation?, (restriction | extension))");
- }
- if (IS_SCHEMA(child, "restriction")) {
- xmlSchemaParseRestriction(ctxt, schema, child,
- XML_SCHEMA_TYPE_COMPLEX_CONTENT);
- (*hasRestrictionOrExtension) = 1;
- child = child->next;
- } else if (IS_SCHEMA(child, "extension")) {
- xmlSchemaParseExtension(ctxt, schema, child,
- XML_SCHEMA_TYPE_COMPLEX_CONTENT);
- (*hasRestrictionOrExtension) = 1;
- child = child->next;
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?, (restriction | extension))");
- }
- return (0);
- }
- static xmlSchemaTypePtr
- xmlSchemaParseComplexType(xmlSchemaParserCtxtPtr ctxt, xmlSchemaPtr schema,
- xmlNodePtr node, int topLevel)
- {
- xmlSchemaTypePtr type, ctxtType;
- xmlNodePtr child = NULL;
- const xmlChar *name = NULL;
- xmlAttrPtr attr;
- const xmlChar *attrValue;
- #ifdef ENABLE_NAMED_LOCALS
- char buf[40];
- #endif
- int final = 0, block = 0, hasRestrictionOrExtension = 0;
- if ((ctxt == NULL) || (schema == NULL) || (node == NULL))
- return (NULL);
- ctxtType = ctxt->ctxtType;
- if (topLevel) {
- attr = xmlSchemaGetPropNode(node, "name");
- if (attr == NULL) {
- xmlSchemaPMissingAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_MISSING, NULL, node, "name", NULL);
- return (NULL);
- } else if (xmlSchemaPValAttrNode(ctxt, NULL, attr,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NCNAME), &name) != 0) {
- return (NULL);
- }
- }
- if (topLevel == 0) {
-
- #ifdef ENABLE_NAMED_LOCALS
- snprintf(buf, 39, "#CT%d", ctxt->counter++ + 1);
- type = xmlSchemaAddType(ctxt, schema,
- XML_SCHEMA_TYPE_COMPLEX,
- xmlDictLookup(ctxt->dict, (const xmlChar *)buf, -1),
- ctxt->targetNamespace, node, 0);
- #else
- type = xmlSchemaAddType(ctxt, schema,
- XML_SCHEMA_TYPE_COMPLEX,
- NULL, ctxt->targetNamespace, node, 0);
- #endif
- if (type == NULL)
- return (NULL);
- name = type->name;
- type->node = node;
- type->type = XML_SCHEMA_TYPE_COMPLEX;
-
- } else {
-
- type = xmlSchemaAddType(ctxt, schema,
- XML_SCHEMA_TYPE_COMPLEX,
- name, ctxt->targetNamespace, node, 1);
- if (type == NULL)
- return (NULL);
- type->node = node;
- type->type = XML_SCHEMA_TYPE_COMPLEX;
- type->flags |= XML_SCHEMAS_TYPE_GLOBAL;
- }
- type->targetNamespace = ctxt->targetNamespace;
-
- attr = node->properties;
- while (attr != NULL) {
- if (attr->ns == NULL) {
- if (xmlStrEqual(attr->name, BAD_CAST "id")) {
-
- xmlSchemaPValAttrID(ctxt, node, BAD_CAST "id");
- } else if (xmlStrEqual(attr->name, BAD_CAST "mixed")) {
-
- if (xmlSchemaPGetBoolNodeValue(ctxt,
- NULL, (xmlNodePtr) attr))
- type->flags |= XML_SCHEMAS_TYPE_MIXED;
- } else if (topLevel) {
-
- if (xmlStrEqual(attr->name, BAD_CAST "name")) {
-
- } else if (xmlStrEqual(attr->name, BAD_CAST "abstract")) {
-
- if (xmlSchemaPGetBoolNodeValue(ctxt,
- NULL, (xmlNodePtr) attr))
- type->flags |= XML_SCHEMAS_TYPE_ABSTRACT;
- } else if (xmlStrEqual(attr->name, BAD_CAST "final")) {
-
- attrValue = xmlSchemaGetNodeContent(ctxt,
- (xmlNodePtr) attr);
- if (xmlSchemaPValAttrBlockFinal(attrValue,
- &(type->flags),
- -1,
- XML_SCHEMAS_TYPE_FINAL_EXTENSION,
- XML_SCHEMAS_TYPE_FINAL_RESTRICTION,
- -1, -1, -1) != 0)
- {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr, NULL,
- "(#all | List of (extension | restriction))",
- attrValue, NULL, NULL, NULL);
- } else
- final = 1;
- } else if (xmlStrEqual(attr->name, BAD_CAST "block")) {
-
- attrValue = xmlSchemaGetNodeContent(ctxt,
- (xmlNodePtr) attr);
- if (xmlSchemaPValAttrBlockFinal(attrValue, &(type->flags),
- -1,
- XML_SCHEMAS_TYPE_BLOCK_EXTENSION,
- XML_SCHEMAS_TYPE_BLOCK_RESTRICTION,
- -1, -1, -1) != 0) {
- xmlSchemaPSimpleTypeErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_INVALID_VALUE,
- NULL, (xmlNodePtr) attr, NULL,
- "(#all | List of (extension | restriction)) ",
- attrValue, NULL, NULL, NULL);
- } else
- block = 1;
- } else {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- } else if (xmlStrEqual(attr->ns->href, xmlSchemaNs)) {
- xmlSchemaPIllegalAttrErr(ctxt,
- XML_SCHEMAP_S4S_ATTR_NOT_ALLOWED, NULL, attr);
- }
- attr = attr->next;
- }
- if (! block) {
-
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_RESTRICTION)
- type->flags |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
- if (schema->flags & XML_SCHEMAS_BLOCK_DEFAULT_EXTENSION)
- type->flags |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
- }
- if (! final) {
-
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_RESTRICTION)
- type->flags |= XML_SCHEMAS_TYPE_FINAL_RESTRICTION;
- if (schema->flags & XML_SCHEMAS_FINAL_DEFAULT_EXTENSION)
- type->flags |= XML_SCHEMAS_TYPE_FINAL_EXTENSION;
- }
-
- child = node->children;
- if (IS_SCHEMA(child, "annotation")) {
- type->annot = xmlSchemaParseAnnotation(ctxt, child, 1);
- child = child->next;
- }
- ctxt->ctxtType = type;
- if (IS_SCHEMA(child, "simpleContent")) {
-
- if (type->flags & XML_SCHEMAS_TYPE_MIXED)
- type->flags ^= XML_SCHEMAS_TYPE_MIXED;
- xmlSchemaParseSimpleContent(ctxt, schema, child,
- &hasRestrictionOrExtension);
- child = child->next;
- } else if (IS_SCHEMA(child, "complexContent")) {
-
- type->contentType = XML_SCHEMA_CONTENT_EMPTY;
- xmlSchemaParseComplexContent(ctxt, schema, child,
- &hasRestrictionOrExtension);
- child = child->next;
- } else {
-
- type->baseType = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
- type->flags |= XML_SCHEMAS_TYPE_DERIVATION_METHOD_RESTRICTION;
-
- if (IS_SCHEMA(child, "all")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_ALL, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "choice")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_CHOICE, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "sequence")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroup(ctxt, schema, child,
- XML_SCHEMA_TYPE_SEQUENCE, 1);
- child = child->next;
- } else if (IS_SCHEMA(child, "group")) {
- type->subtypes = (xmlSchemaTypePtr)
- xmlSchemaParseModelGroupDefRef(ctxt, schema, child);
-
- child = child->next;
- }
-
- if (xmlSchemaParseLocalAttributes(ctxt, schema, &child,
- (xmlSchemaItemListPtr *) &(type->attrUses),
- XML_SCHEMA_TYPE_RESTRICTION, NULL) == -1)
- return(NULL);
-
- if (IS_SCHEMA(child, "anyAttribute")) {
- type->attributeWildcard = xmlSchemaParseAnyAttribute(ctxt, schema, child);
- child = child->next;
- }
- }
- if (child != NULL) {
- xmlSchemaPContentErr(ctxt,
- XML_SCHEMAP_S4S_ELEM_NOT_ALLOWED,
- NULL, node, child,
- NULL, "(annotation?, (simpleContent | complexContent | "
- "((group | all | choice | sequence)?, ((attribute | "
- "attributeGroup)*, anyAttribute?))))");
- }
-
- if (topLevel && ctxt->isRedefine && (! hasRestrictionOrExtension)) {
- xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_SRC_REDEFINE,
- NULL, node, "This is a redefinition, thus the "
- "<complexType> must have a <restriction> or <extension> "
- "grand-child", NULL);
- }
- ctxt->ctxtType = ctxtType;
- return (type);
- }
- #if 0
- static int
- xmlSchemaParserCtxtSetOptions(xmlSchemaParserCtxtPtr ctxt,
- int options)
- {
- int i;
- if (ctxt == NULL)
- return (-1);
-
- for (i = 1; i < (int) sizeof(int) * 8; i++) {
- if (options & 1<<i) {
- return (-1);
- }
- }
- ctxt->options = options;
- return (0);
- }
- static int
- xmlSchemaParserCtxtGetOptions(xmlSchemaParserCtxtPtr ctxt)
- {
- if (ctxt == NULL)
- return (-1);
- else
- return (ctxt->options);
- }
- #endif
- xmlSchemaParserCtxtPtr
- xmlSchemaNewParserCtxt(const char *URL)
- {
- xmlSchemaParserCtxtPtr ret;
- if (URL == NULL)
- return (NULL);
- ret = xmlSchemaParserCtxtCreate();
- if (ret == NULL)
- return(NULL);
- ret->dict = xmlDictCreate();
- ret->URL = xmlDictLookup(ret->dict, (const xmlChar *) URL, -1);
- return (ret);
- }
- xmlSchemaParserCtxtPtr
- xmlSchemaNewMemParserCtxt(const char *buffer, int size)
- {
- xmlSchemaParserCtxtPtr ret;
- if ((buffer == NULL) || (size <= 0))
- return (NULL);
- ret = xmlSchemaParserCtxtCreate();
- if (ret == NULL)
- return(NULL);
- ret->buffer = buffer;
- ret->size = size;
- ret->dict = xmlDictCreate();
- return (ret);
- }
- xmlSchemaParserCtxtPtr
- xmlSchemaNewDocParserCtxt(xmlDocPtr doc)
- {
- xmlSchemaParserCtxtPtr ret;
- if (doc == NULL)
- return (NULL);
- ret = xmlSchemaParserCtxtCreate();
- if (ret == NULL)
- return(NULL);
- ret->doc = doc;
- ret->dict = xmlDictCreate();
-
- ret->preserve = 1;
- return (ret);
- }
- void
- xmlSchemaFreeParserCtxt(xmlSchemaParserCtxtPtr ctxt)
- {
- if (ctxt == NULL)
- return;
- if (ctxt->doc != NULL && !ctxt->preserve)
- xmlFreeDoc(ctxt->doc);
- if (ctxt->vctxt != NULL) {
- xmlSchemaFreeValidCtxt(ctxt->vctxt);
- }
- if (ctxt->ownsConstructor && (ctxt->constructor != NULL)) {
- xmlSchemaConstructionCtxtFree(ctxt->constructor);
- ctxt->constructor = NULL;
- ctxt->ownsConstructor = 0;
- }
- if (ctxt->attrProhibs != NULL)
- xmlSchemaItemListFree(ctxt->attrProhibs);
- xmlDictFree(ctxt->dict);
- xmlFree(ctxt);
- }
- static int
- xmlSchemaBuildContentModelForSubstGroup(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaParticlePtr particle, int counter, xmlAutomataStatePtr end)
- {
- xmlAutomataStatePtr start, tmp;
- xmlSchemaElementPtr elemDecl, member;
- xmlSchemaSubstGroupPtr substGroup;
- int i;
- int ret = 0;
- elemDecl = (xmlSchemaElementPtr) particle->children;
-
- start = pctxt->state;
- if (end == NULL)
- end = xmlAutomataNewState(pctxt->am);
- substGroup = xmlSchemaSubstGroupGet(pctxt, elemDecl);
- if (substGroup == NULL) {
- xmlSchemaPErr(pctxt, WXS_ITEM_NODE(particle),
- XML_SCHEMAP_INTERNAL,
- "Internal error: xmlSchemaBuildContentModelForSubstGroup, "
- "declaration is marked having a subst. group but none "
- "available.\n", elemDecl->name, NULL);
- return(0);
- }
- if (counter >= 0) {
-
- tmp = xmlAutomataNewCountedTrans(pctxt->am, start, NULL, counter);
- xmlAutomataNewTransition2(pctxt->am, tmp, end,
- elemDecl->name, elemDecl->targetNamespace, elemDecl);
-
- for (i = 0; i < substGroup->members->nbItems; i++) {
- member = (xmlSchemaElementPtr) substGroup->members->items[i];
- xmlAutomataNewTransition2(pctxt->am, tmp, end,
- member->name, member->targetNamespace, member);
- }
- } else if (particle->maxOccurs == 1) {
-
- xmlAutomataNewEpsilon(pctxt->am,
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL,
- elemDecl->name, elemDecl->targetNamespace, elemDecl), end);
-
- for (i = 0; i < substGroup->members->nbItems; i++) {
- member = (xmlSchemaElementPtr) substGroup->members->items[i];
-
- tmp = xmlAutomataNewTransition2(pctxt->am, start, NULL,
- member->name, member->targetNamespace, member);
- xmlAutomataNewEpsilon(pctxt->am, tmp, end);
- }
- } else {
- xmlAutomataStatePtr hop;
- int maxOccurs = particle->maxOccurs == UNBOUNDED ?
- UNBOUNDED : particle->maxOccurs - 1;
- int minOccurs = particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
- counter =
- xmlAutomataNewCounter(pctxt->am, minOccurs,
- maxOccurs);
- hop = xmlAutomataNewState(pctxt->am);
- xmlAutomataNewEpsilon(pctxt->am,
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL,
- elemDecl->name, elemDecl->targetNamespace, elemDecl),
- hop);
-
- for (i = 0; i < substGroup->members->nbItems; i++) {
- member = (xmlSchemaElementPtr) substGroup->members->items[i];
- xmlAutomataNewEpsilon(pctxt->am,
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL,
- member->name, member->targetNamespace, member),
- hop);
- }
- xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter);
- xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
- }
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(pctxt->am, start, end);
- ret = 1;
- }
- pctxt->state = end;
- return(ret);
- }
- static int
- xmlSchemaBuildContentModelForElement(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr particle)
- {
- int ret = 0;
- if (((xmlSchemaElementPtr) particle->children)->flags &
- XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) {
-
- ret = xmlSchemaBuildContentModelForSubstGroup(ctxt, particle, -1, NULL);
- } else {
- xmlSchemaElementPtr elemDecl;
- xmlAutomataStatePtr start;
- elemDecl = (xmlSchemaElementPtr) particle->children;
- if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT)
- return(0);
- if (particle->maxOccurs == 1) {
- start = ctxt->state;
- ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
- elemDecl->name, elemDecl->targetNamespace, elemDecl);
- } else if ((particle->maxOccurs >= UNBOUNDED) &&
- (particle->minOccurs < 2)) {
-
- start = ctxt->state;
- ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
- elemDecl->name, elemDecl->targetNamespace, elemDecl);
- ctxt->state = xmlAutomataNewTransition2(ctxt->am, ctxt->state, ctxt->state,
- elemDecl->name, elemDecl->targetNamespace, elemDecl);
- } else {
- int counter;
- int maxOccurs = particle->maxOccurs == UNBOUNDED ?
- UNBOUNDED : particle->maxOccurs - 1;
- int minOccurs = particle->minOccurs < 1 ?
- 0 : particle->minOccurs - 1;
- start = xmlAutomataNewEpsilon(ctxt->am, ctxt->state, NULL);
- counter = xmlAutomataNewCounter(ctxt->am, minOccurs, maxOccurs);
- ctxt->state = xmlAutomataNewTransition2(ctxt->am, start, NULL,
- elemDecl->name, elemDecl->targetNamespace, elemDecl);
- xmlAutomataNewCountedTrans(ctxt->am, ctxt->state, start, counter);
- ctxt->state = xmlAutomataNewCounterTrans(ctxt->am, ctxt->state,
- NULL, counter);
- }
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(ctxt->am, start, ctxt->state);
- ret = 1;
- }
- }
- return(ret);
- }
- static int
- xmlSchemaBuildAContentModel(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaParticlePtr particle)
- {
- int ret = 0, tmp2;
- if (particle == NULL) {
- PERROR_INT("xmlSchemaBuildAContentModel", "particle is NULL");
- return(1);
- }
- if (particle->children == NULL) {
-
- return(1);
- }
- switch (particle->children->type) {
- case XML_SCHEMA_TYPE_ANY: {
- xmlAutomataStatePtr start, end;
- xmlSchemaWildcardPtr wild;
- xmlSchemaWildcardNsPtr ns;
- wild = (xmlSchemaWildcardPtr) particle->children;
- start = pctxt->state;
- end = xmlAutomataNewState(pctxt->am);
- if (particle->maxOccurs == 1) {
- if (wild->any == 1) {
-
- pctxt->state =
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
-
- pctxt->state =
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL, BAD_CAST "*", NULL, wild);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
- } else if (wild->nsSet != NULL) {
- ns = wild->nsSet;
- do {
- pctxt->state = start;
- pctxt->state = xmlAutomataNewTransition2(pctxt->am,
- pctxt->state, NULL, BAD_CAST "*", ns->value, wild);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
- ns = ns->next;
- } while (ns != NULL);
- } else if (wild->negNsSet != NULL) {
- pctxt->state = xmlAutomataNewNegTrans(pctxt->am,
- start, end, BAD_CAST "*", wild->negNsSet->value,
- wild);
- }
- } else {
- int counter;
- xmlAutomataStatePtr hop;
- int maxOccurs =
- particle->maxOccurs == UNBOUNDED ? UNBOUNDED :
- particle->maxOccurs - 1;
- int minOccurs =
- particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
- counter = xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs);
- hop = xmlAutomataNewState(pctxt->am);
- if (wild->any == 1) {
- pctxt->state =
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL, BAD_CAST "*", BAD_CAST "*", wild);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
- pctxt->state =
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL, BAD_CAST "*", NULL, wild);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
- } else if (wild->nsSet != NULL) {
- ns = wild->nsSet;
- do {
- pctxt->state =
- xmlAutomataNewTransition2(pctxt->am,
- start, NULL, BAD_CAST "*", ns->value, wild);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
- ns = ns->next;
- } while (ns != NULL);
- } else if (wild->negNsSet != NULL) {
- pctxt->state = xmlAutomataNewNegTrans(pctxt->am,
- start, hop, BAD_CAST "*", wild->negNsSet->value,
- wild);
- }
- xmlAutomataNewCountedTrans(pctxt->am, hop, start, counter);
- xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
- }
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(pctxt->am, start, end);
- ret = 1;
- }
- pctxt->state = end;
- break;
- }
- case XML_SCHEMA_TYPE_ELEMENT:
- ret = xmlSchemaBuildContentModelForElement(pctxt, particle);
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:{
- xmlSchemaTreeItemPtr sub;
- ret = 1;
-
- if ((particle->minOccurs == 1) && (particle->maxOccurs == 1)) {
- sub = particle->children->children;
- while (sub != NULL) {
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 != 1) ret = 0;
- sub = sub->next;
- }
- } else {
- xmlAutomataStatePtr oldstate = pctxt->state;
- if (particle->maxOccurs >= UNBOUNDED) {
- if (particle->minOccurs > 1) {
- xmlAutomataStatePtr tmp;
- int counter;
- pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
- oldstate, NULL);
- oldstate = pctxt->state;
- counter = xmlAutomataNewCounter(pctxt->am,
- particle->minOccurs - 1, UNBOUNDED);
- sub = particle->children->children;
- while (sub != NULL) {
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 != 1) ret = 0;
- sub = sub->next;
- }
- tmp = pctxt->state;
- xmlAutomataNewCountedTrans(pctxt->am, tmp,
- oldstate, counter);
- pctxt->state =
- xmlAutomataNewCounterTrans(pctxt->am, tmp,
- NULL, counter);
- if (ret == 1)
- xmlAutomataNewEpsilon(pctxt->am,
- oldstate, pctxt->state);
- } else {
- pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
- oldstate, NULL);
- oldstate = pctxt->state;
- sub = particle->children->children;
- while (sub != NULL) {
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 != 1) ret = 0;
- sub = sub->next;
- }
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state,
- oldstate);
-
- pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
- pctxt->state, NULL);
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(pctxt->am,
- oldstate, pctxt->state);
- ret = 1;
- }
- }
- } else if ((particle->maxOccurs > 1)
- || (particle->minOccurs > 1)) {
- xmlAutomataStatePtr tmp;
- int counter;
- pctxt->state = xmlAutomataNewEpsilon(pctxt->am,
- oldstate, NULL);
- oldstate = pctxt->state;
- counter = xmlAutomataNewCounter(pctxt->am,
- particle->minOccurs - 1,
- particle->maxOccurs - 1);
- sub = particle->children->children;
- while (sub != NULL) {
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 != 1) ret = 0;
- sub = sub->next;
- }
- tmp = pctxt->state;
- xmlAutomataNewCountedTrans(pctxt->am,
- tmp, oldstate, counter);
- pctxt->state =
- xmlAutomataNewCounterTrans(pctxt->am, tmp, NULL,
- counter);
- if ((particle->minOccurs == 0) || (ret == 1)) {
- xmlAutomataNewEpsilon(pctxt->am,
- oldstate, pctxt->state);
- ret = 1;
- }
- } else {
- sub = particle->children->children;
- while (sub != NULL) {
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 != 1) ret = 0;
- sub = sub->next;
- }
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(pctxt->am, oldstate,
- pctxt->state);
- ret = 1;
- }
- }
- }
- break;
- }
- case XML_SCHEMA_TYPE_CHOICE:{
- xmlSchemaTreeItemPtr sub;
- xmlAutomataStatePtr start, end;
- ret = 0;
- start = pctxt->state;
- end = xmlAutomataNewState(pctxt->am);
-
- if (particle->maxOccurs == 1) {
- sub = particle->children->children;
- while (sub != NULL) {
- pctxt->state = start;
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 == 1) ret = 1;
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, end);
- sub = sub->next;
- }
- } else {
- int counter;
- xmlAutomataStatePtr hop, base;
- int maxOccurs = particle->maxOccurs == UNBOUNDED ?
- UNBOUNDED : particle->maxOccurs - 1;
- int minOccurs =
- particle->minOccurs < 1 ? 0 : particle->minOccurs - 1;
-
- counter =
- xmlAutomataNewCounter(pctxt->am, minOccurs, maxOccurs);
- hop = xmlAutomataNewState(pctxt->am);
- base = xmlAutomataNewState(pctxt->am);
- sub = particle->children->children;
- while (sub != NULL) {
- pctxt->state = base;
- tmp2 = xmlSchemaBuildAContentModel(pctxt,
- (xmlSchemaParticlePtr) sub);
- if (tmp2 == 1) ret = 1;
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, hop);
- sub = sub->next;
- }
- xmlAutomataNewEpsilon(pctxt->am, start, base);
- xmlAutomataNewCountedTrans(pctxt->am, hop, base, counter);
- xmlAutomataNewCounterTrans(pctxt->am, hop, end, counter);
- if (ret == 1)
- xmlAutomataNewEpsilon(pctxt->am, base, end);
- }
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(pctxt->am, start, end);
- ret = 1;
- }
- pctxt->state = end;
- break;
- }
- case XML_SCHEMA_TYPE_ALL:{
- xmlAutomataStatePtr start, tmp;
- xmlSchemaParticlePtr sub;
- xmlSchemaElementPtr elemDecl;
- ret = 1;
- sub = (xmlSchemaParticlePtr) particle->children->children;
- if (sub == NULL)
- break;
- ret = 0;
- start = pctxt->state;
- tmp = xmlAutomataNewState(pctxt->am);
- xmlAutomataNewEpsilon(pctxt->am, pctxt->state, tmp);
- pctxt->state = tmp;
- while (sub != NULL) {
- pctxt->state = tmp;
- elemDecl = (xmlSchemaElementPtr) sub->children;
- if (elemDecl == NULL) {
- PERROR_INT("xmlSchemaBuildAContentModel",
- "<element> particle has no term");
- return(ret);
- };
-
- if (elemDecl->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) {
- int counter;
-
- counter = xmlAutomataNewCounter(pctxt->am,
- sub->minOccurs, sub->maxOccurs);
- xmlSchemaBuildContentModelForSubstGroup(pctxt,
- sub, counter, pctxt->state);
- } else {
- if ((sub->minOccurs == 1) &&
- (sub->maxOccurs == 1)) {
- xmlAutomataNewOnceTrans2(pctxt->am, pctxt->state,
- pctxt->state,
- elemDecl->name,
- elemDecl->targetNamespace,
- 1, 1, elemDecl);
- } else if ((sub->minOccurs == 0) &&
- (sub->maxOccurs == 1)) {
- xmlAutomataNewCountTrans2(pctxt->am, pctxt->state,
- pctxt->state,
- elemDecl->name,
- elemDecl->targetNamespace,
- 0,
- 1,
- elemDecl);
- }
- }
- sub = (xmlSchemaParticlePtr) sub->next;
- }
- pctxt->state =
- xmlAutomataNewAllTrans(pctxt->am, pctxt->state, NULL, 0);
- if (particle->minOccurs == 0) {
- xmlAutomataNewEpsilon(pctxt->am, start, pctxt->state);
- ret = 1;
- }
- break;
- }
- case XML_SCHEMA_TYPE_GROUP:
-
- ret = 1;
- break;
- default:
- xmlSchemaInternalErr2(ACTXT_CAST pctxt,
- "xmlSchemaBuildAContentModel",
- "found unexpected term of type '%s' in content model",
- WXS_ITEM_TYPE_NAME(particle->children), NULL);
- return(ret);
- }
- return(ret);
- }
- static void
- xmlSchemaBuildContentModel(xmlSchemaTypePtr type,
- xmlSchemaParserCtxtPtr ctxt)
- {
- if ((type->type != XML_SCHEMA_TYPE_COMPLEX) ||
- (type->contModel != NULL) ||
- ((type->contentType != XML_SCHEMA_CONTENT_ELEMENTS) &&
- (type->contentType != XML_SCHEMA_CONTENT_MIXED)))
- return;
- #ifdef DEBUG_CONTENT
- xmlGenericError(xmlGenericErrorContext,
- "Building content model for %s\n", name);
- #endif
- ctxt->am = NULL;
- ctxt->am = xmlNewAutomata();
- if (ctxt->am == NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "Cannot create automata for complex type %s\n", type->name);
- return;
- }
- ctxt->state = xmlAutomataGetInitState(ctxt->am);
-
- xmlSchemaBuildAContentModel(ctxt, WXS_TYPE_PARTICLE(type));
- xmlAutomataSetFinalState(ctxt->am, ctxt->state);
- type->contModel = xmlAutomataCompile(ctxt->am);
- if (type->contModel == NULL) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_INTERNAL,
- WXS_BASIC_CAST type, type->node,
- "Failed to compile the content model", NULL);
- } else if (xmlRegexpIsDeterminist(type->contModel) != 1) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_NOT_DETERMINISTIC,
-
- WXS_BASIC_CAST type, type->node,
- "The content model is not determinist", NULL);
- } else {
- #ifdef DEBUG_CONTENT_REGEXP
- xmlGenericError(xmlGenericErrorContext,
- "Content model of %s:\n", type->name);
- xmlRegexpPrint(stderr, type->contModel);
- #endif
- }
- ctxt->state = NULL;
- xmlFreeAutomata(ctxt->am);
- ctxt->am = NULL;
- }
- static void
- xmlSchemaResolveElementReferences(xmlSchemaElementPtr elemDecl,
- xmlSchemaParserCtxtPtr ctxt)
- {
- if ((ctxt == NULL) || (elemDecl == NULL) ||
- ((elemDecl != NULL) &&
- (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_RESOLVED)))
- return;
- elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_RESOLVED;
- if ((elemDecl->subtypes == NULL) && (elemDecl->namedType != NULL)) {
- xmlSchemaTypePtr type;
-
- type = xmlSchemaGetType(ctxt->schema, elemDecl->namedType,
- elemDecl->namedTypeNs);
- if (type == NULL) {
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST elemDecl, elemDecl->node,
- "type", elemDecl->namedType, elemDecl->namedTypeNs,
- XML_SCHEMA_TYPE_BASIC, "type definition");
- } else
- elemDecl->subtypes = type;
- }
- if (elemDecl->substGroup != NULL) {
- xmlSchemaElementPtr substHead;
-
- substHead = xmlSchemaGetElem(ctxt->schema, elemDecl->substGroup,
- elemDecl->substGroupNs);
- if (substHead == NULL) {
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST elemDecl, NULL,
- "substitutionGroup", elemDecl->substGroup,
- elemDecl->substGroupNs, XML_SCHEMA_TYPE_ELEMENT, NULL);
- } else {
- xmlSchemaResolveElementReferences(substHead, ctxt);
-
- WXS_SUBST_HEAD(elemDecl) = substHead;
-
- if (elemDecl->subtypes == NULL)
- elemDecl->subtypes = substHead->subtypes;
- }
- }
-
- if ((elemDecl->subtypes == NULL) &&
- (elemDecl->namedType == NULL) &&
- (elemDecl->substGroup == NULL))
- elemDecl->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
- }
- static int
- xmlSchemaResolveUnionMemberTypes(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypeLinkPtr link, lastLink, newLink;
- xmlSchemaTypePtr memberType;
-
-
- link = type->memberTypes;
- lastLink = NULL;
- while (link != NULL) {
- const xmlChar *name, *nsName;
- name = ((xmlSchemaQNameRefPtr) link->type)->name;
- nsName = ((xmlSchemaQNameRefPtr) link->type)->targetNamespace;
- memberType = xmlSchemaGetType(ctxt->schema, name, nsName);
- if ((memberType == NULL) || (! WXS_IS_SIMPLE(memberType))) {
- xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST type, type->node, "memberTypes",
- name, nsName, XML_SCHEMA_TYPE_SIMPLE, NULL);
-
- if (lastLink == NULL)
- type->memberTypes = link->next;
- else
- lastLink->next = link->next;
- newLink = link;
- link = link->next;
- xmlFree(newLink);
- } else {
- link->type = memberType;
- lastLink = link;
- link = link->next;
- }
- }
-
- memberType = type->subtypes;
- while (memberType != NULL) {
- link = (xmlSchemaTypeLinkPtr) xmlMalloc(sizeof(xmlSchemaTypeLink));
- if (link == NULL) {
- xmlSchemaPErrMemory(ctxt, "allocating a type link", NULL);
- return (-1);
- }
- link->type = memberType;
- link->next = NULL;
- if (lastLink == NULL)
- type->memberTypes = link;
- else
- lastLink->next = link;
- lastLink = link;
- memberType = memberType->next;
- }
- return (0);
- }
- static int
- xmlSchemaIsDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType)
- {
- if (type == NULL)
- return (0);
- if (WXS_IS_COMPLEX(type))
- return (0);
- if (type->type == XML_SCHEMA_TYPE_BASIC) {
- if (type->builtInType == valType)
- return(1);
- if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) ||
- (type->builtInType == XML_SCHEMAS_ANYTYPE))
- return (0);
- return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
- }
- return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
- }
- #if 0
- static int
- xmlSchemaIsUserDerivedFromBuiltInType(xmlSchemaTypePtr type, int valType)
- {
- if (type == NULL)
- return (0);
- if (WXS_IS_COMPLEX(type))
- return (0);
- if (type->type == XML_SCHEMA_TYPE_BASIC) {
- if (type->builtInType == valType)
- return(1);
- return (0);
- } else
- return(xmlSchemaIsDerivedFromBuiltInType(type->subtypes, valType));
- return (0);
- }
- static xmlSchemaTypePtr
- xmlSchemaQueryBuiltInType(xmlSchemaTypePtr type)
- {
- if (type == NULL)
- return (NULL);
- if (WXS_IS_COMPLEX(type))
- return (NULL);
- if (type->type == XML_SCHEMA_TYPE_BASIC)
- return(type);
- return(xmlSchemaQueryBuiltInType(type->subtypes));
- }
- #endif
- static xmlSchemaTypePtr
- xmlSchemaGetPrimitiveType(xmlSchemaTypePtr type)
- {
- while (type != NULL) {
-
- if ((type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) ||
- (type->flags & XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE))
- return (type);
- type = type->baseType;
- }
- return (NULL);
- }
- #if 0
- static xmlSchemaTypePtr
- xmlSchemaGetBuiltInTypeAncestor(xmlSchemaTypePtr type)
- {
- if (WXS_IS_LIST(type) || WXS_IS_UNION(type))
- return (0);
- while (type != NULL) {
- if (type->type == XML_SCHEMA_TYPE_BASIC)
- return (type);
- type = type->baseType;
- }
- return (NULL);
- }
- #endif
- static int
- xmlSchemaCloneWildcardNsConstraints(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaWildcardPtr dest,
- xmlSchemaWildcardPtr source)
- {
- xmlSchemaWildcardNsPtr cur, tmp, last;
- if ((source == NULL) || (dest == NULL))
- return(-1);
- dest->any = source->any;
- cur = source->nsSet;
- last = NULL;
- while (cur != NULL) {
- tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (tmp == NULL)
- return(-1);
- tmp->value = cur->value;
- if (last == NULL)
- dest->nsSet = tmp;
- else
- last->next = tmp;
- last = tmp;
- cur = cur->next;
- }
- if (dest->negNsSet != NULL)
- xmlSchemaFreeWildcardNsSet(dest->negNsSet);
- if (source->negNsSet != NULL) {
- dest->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (dest->negNsSet == NULL)
- return(-1);
- dest->negNsSet->value = source->negNsSet->value;
- } else
- dest->negNsSet = NULL;
- return(0);
- }
- static int
- xmlSchemaUnionWildcards(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaWildcardPtr completeWild,
- xmlSchemaWildcardPtr curWild)
- {
- xmlSchemaWildcardNsPtr cur, curB, tmp;
-
- if ((completeWild->any == curWild->any) &&
- ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) &&
- ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) {
- if ((completeWild->negNsSet == NULL) ||
- (completeWild->negNsSet->value == curWild->negNsSet->value)) {
- if (completeWild->nsSet != NULL) {
- int found = 0;
-
- cur = completeWild->nsSet;
- while (cur != NULL) {
- found = 0;
- curB = curWild->nsSet;
- while (curB != NULL) {
- if (cur->value == curB->value) {
- found = 1;
- break;
- }
- curB = curB->next;
- }
- if (!found)
- break;
- cur = cur->next;
- }
- if (found)
- return(0);
- } else
- return(0);
- }
- }
-
- if (completeWild->any != curWild->any) {
- if (completeWild->any == 0) {
- completeWild->any = 1;
- if (completeWild->nsSet != NULL) {
- xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
- completeWild->nsSet = NULL;
- }
- if (completeWild->negNsSet != NULL) {
- xmlFree(completeWild->negNsSet);
- completeWild->negNsSet = NULL;
- }
- }
- return (0);
- }
-
- if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
- int found;
- xmlSchemaWildcardNsPtr start;
- cur = curWild->nsSet;
- start = completeWild->nsSet;
- while (cur != NULL) {
- found = 0;
- curB = start;
- while (curB != NULL) {
- if (cur->value == curB->value) {
- found = 1;
- break;
- }
- curB = curB->next;
- }
- if (!found) {
- tmp = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (tmp == NULL)
- return (-1);
- tmp->value = cur->value;
- tmp->next = completeWild->nsSet;
- completeWild->nsSet = tmp;
- }
- cur = cur->next;
- }
- return(0);
- }
-
- if ((completeWild->negNsSet != NULL) &&
- (curWild->negNsSet != NULL) &&
- (completeWild->negNsSet->value != curWild->negNsSet->value)) {
- completeWild->negNsSet->value = NULL;
- return(0);
- }
-
- if (((completeWild->negNsSet != NULL) &&
- (completeWild->negNsSet->value != NULL) &&
- (curWild->nsSet != NULL)) ||
- ((curWild->negNsSet != NULL) &&
- (curWild->negNsSet->value != NULL) &&
- (completeWild->nsSet != NULL))) {
- int nsFound, absentFound = 0;
- if (completeWild->nsSet != NULL) {
- cur = completeWild->nsSet;
- curB = curWild->negNsSet;
- } else {
- cur = curWild->nsSet;
- curB = completeWild->negNsSet;
- }
- nsFound = 0;
- while (cur != NULL) {
- if (cur->value == NULL)
- absentFound = 1;
- else if (cur->value == curB->value)
- nsFound = 1;
- if (nsFound && absentFound)
- break;
- cur = cur->next;
- }
- if (nsFound && absentFound) {
-
- completeWild->any = 1;
- if (completeWild->nsSet != NULL) {
- xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
- completeWild->nsSet = NULL;
- }
- if (completeWild->negNsSet != NULL) {
- xmlFree(completeWild->negNsSet);
- completeWild->negNsSet = NULL;
- }
- } else if (nsFound && (!absentFound)) {
-
- if (completeWild->nsSet != NULL) {
- xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
- completeWild->nsSet = NULL;
- }
- if (completeWild->negNsSet == NULL) {
- completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (completeWild->negNsSet == NULL)
- return (-1);
- }
- completeWild->negNsSet->value = NULL;
- } else if ((!nsFound) && absentFound) {
-
- xmlSchemaPErr(ctxt, completeWild->node,
- XML_SCHEMAP_UNION_NOT_EXPRESSIBLE,
- "The union of the wilcard is not expressible.\n",
- NULL, NULL);
- return(XML_SCHEMAP_UNION_NOT_EXPRESSIBLE);
- } else if ((!nsFound) && (!absentFound)) {
-
- if (completeWild->negNsSet == NULL) {
- if (completeWild->nsSet != NULL) {
- xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
- completeWild->nsSet = NULL;
- }
- completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (completeWild->negNsSet == NULL)
- return (-1);
- completeWild->negNsSet->value = curWild->negNsSet->value;
- }
- }
- return (0);
- }
-
- if (((completeWild->negNsSet != NULL) &&
- (completeWild->negNsSet->value == NULL) &&
- (curWild->nsSet != NULL)) ||
- ((curWild->negNsSet != NULL) &&
- (curWild->negNsSet->value == NULL) &&
- (completeWild->nsSet != NULL))) {
- if (completeWild->nsSet != NULL) {
- cur = completeWild->nsSet;
- } else {
- cur = curWild->nsSet;
- }
- while (cur != NULL) {
- if (cur->value == NULL) {
-
- completeWild->any = 1;
- if (completeWild->nsSet != NULL) {
- xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
- completeWild->nsSet = NULL;
- }
- if (completeWild->negNsSet != NULL) {
- xmlFree(completeWild->negNsSet);
- completeWild->negNsSet = NULL;
- }
- return (0);
- }
- cur = cur->next;
- }
- if (completeWild->negNsSet == NULL) {
-
- if (completeWild->nsSet != NULL) {
- xmlSchemaFreeWildcardNsSet(completeWild->nsSet);
- completeWild->nsSet = NULL;
- }
- completeWild->negNsSet = xmlSchemaNewWildcardNsConstraint(ctxt);
- if (completeWild->negNsSet == NULL)
- return (-1);
- completeWild->negNsSet->value = NULL;
- }
- return (0);
- }
- return (0);
- }
- static int
- xmlSchemaIntersectWildcards(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaWildcardPtr completeWild,
- xmlSchemaWildcardPtr curWild)
- {
- xmlSchemaWildcardNsPtr cur, curB, prev, tmp;
-
- if ((completeWild->any == curWild->any) &&
- ((completeWild->nsSet == NULL) == (curWild->nsSet == NULL)) &&
- ((completeWild->negNsSet == NULL) == (curWild->negNsSet == NULL))) {
- if ((completeWild->negNsSet == NULL) ||
- (completeWild->negNsSet->value == curWild->negNsSet->value)) {
- if (completeWild->nsSet != NULL) {
- int found = 0;
-
- cur = completeWild->nsSet;
- while (cur != NULL) {
- found = 0;
- curB = curWild->nsSet;
- while (curB != NULL) {
- if (cur->value == curB->value) {
- found = 1;
- break;
- }
- curB = curB->next;
- }
- if (!found)
- break;
- cur = cur->next;
- }
- if (found)
- return(0);
- } else
- return(0);
- }
- }
-
- if ((completeWild->any != curWild->any) && (completeWild->any)) {
- if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1)
- return(-1);
- return(0);
- }
-
- if (((completeWild->negNsSet != NULL) && (curWild->nsSet != NULL)) ||
- ((curWild->negNsSet != NULL) && (completeWild->nsSet != NULL))) {
- const xmlChar *neg;
- if (completeWild->nsSet == NULL) {
- neg = completeWild->negNsSet->value;
- if (xmlSchemaCloneWildcardNsConstraints(ctxt, completeWild, curWild) == -1)
- return(-1);
- } else
- neg = curWild->negNsSet->value;
-
- prev = NULL;
- cur = completeWild->nsSet;
- while (cur != NULL) {
- if (cur->value == NULL) {
- if (prev == NULL)
- completeWild->nsSet = cur->next;
- else
- prev->next = cur->next;
- xmlFree(cur);
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- if (neg != NULL) {
- prev = NULL;
- cur = completeWild->nsSet;
- while (cur != NULL) {
- if (cur->value == neg) {
- if (prev == NULL)
- completeWild->nsSet = cur->next;
- else
- prev->next = cur->next;
- xmlFree(cur);
- break;
- }
- prev = cur;
- cur = cur->next;
- }
- }
- return(0);
- }
-
- if ((completeWild->nsSet != NULL) && (curWild->nsSet != NULL)) {
- int found;
- cur = completeWild->nsSet;
- prev = NULL;
- while (cur != NULL) {
- found = 0;
- curB = curWild->nsSet;
- while (curB != NULL) {
- if (cur->value == curB->value) {
- found = 1;
- break;
- }
- curB = curB->next;
- }
- if (!found) {
- if (prev == NULL)
- completeWild->nsSet = cur->next;
- else
- prev->next = cur->next;
- tmp = cur->next;
- xmlFree(cur);
- cur = tmp;
- continue;
- }
- prev = cur;
- cur = cur->next;
- }
- return(0);
- }
-
- if ((completeWild->negNsSet != NULL) &&
- (curWild->negNsSet != NULL) &&
- (completeWild->negNsSet->value != curWild->negNsSet->value) &&
- (completeWild->negNsSet->value != NULL) &&
- (curWild->negNsSet->value != NULL)) {
- xmlSchemaPErr(ctxt, completeWild->node, XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE,
- "The intersection of the wilcard is not expressible.\n",
- NULL, NULL);
- return(XML_SCHEMAP_INTERSECTION_NOT_EXPRESSIBLE);
- }
-
- if ((completeWild->negNsSet != NULL) && (curWild->negNsSet != NULL) &&
- (completeWild->negNsSet->value != curWild->negNsSet->value) &&
- (completeWild->negNsSet->value == NULL)) {
- completeWild->negNsSet->value = curWild->negNsSet->value;
- }
- return(0);
- }
- static int
- xmlSchemaCheckCOSNSSubset(xmlSchemaWildcardPtr sub,
- xmlSchemaWildcardPtr super)
- {
-
- if (super->any)
- return (0);
-
- if ((sub->negNsSet != NULL) &&
- (super->negNsSet != NULL) &&
- (sub->negNsSet->value == sub->negNsSet->value))
- return (0);
-
- if (sub->nsSet != NULL) {
-
- if (super->nsSet != NULL) {
- xmlSchemaWildcardNsPtr cur, curB;
- int found = 0;
- cur = sub->nsSet;
- while (cur != NULL) {
- found = 0;
- curB = super->nsSet;
- while (curB != NULL) {
- if (cur->value == curB->value) {
- found = 1;
- break;
- }
- curB = curB->next;
- }
- if (!found)
- return (1);
- cur = cur->next;
- }
- if (found)
- return (0);
- } else if (super->negNsSet != NULL) {
- xmlSchemaWildcardNsPtr cur;
-
- cur = sub->nsSet;
- while (cur != NULL) {
- if (cur->value == super->negNsSet->value)
- return (1);
- cur = cur->next;
- }
- return (0);
- }
- }
- return (1);
- }
- static int
- xmlSchemaGetEffectiveValueConstraint(xmlSchemaAttributeUsePtr attruse,
- int *fixed,
- const xmlChar **value,
- xmlSchemaValPtr *val)
- {
- *fixed = 0;
- *value = NULL;
- if (val != 0)
- *val = NULL;
- if (attruse->defValue != NULL) {
- *value = attruse->defValue;
- if (val != NULL)
- *val = attruse->defVal;
- if (attruse->flags & XML_SCHEMA_ATTR_USE_FIXED)
- *fixed = 1;
- return(1);
- } else if ((attruse->attrDecl != NULL) &&
- (attruse->attrDecl->defValue != NULL)) {
- *value = attruse->attrDecl->defValue;
- if (val != NULL)
- *val = attruse->attrDecl->defVal;
- if (attruse->attrDecl->flags & XML_SCHEMAS_ATTR_FIXED)
- *fixed = 1;
- return(1);
- }
- return(0);
- }
- static int
- xmlSchemaCheckCVCWildcardNamespace(xmlSchemaWildcardPtr wild,
- const xmlChar* ns)
- {
- if (wild == NULL)
- return(-1);
- if (wild->any)
- return(0);
- else if (wild->nsSet != NULL) {
- xmlSchemaWildcardNsPtr cur;
- cur = wild->nsSet;
- while (cur != NULL) {
- if (xmlStrEqual(cur->value, ns))
- return(0);
- cur = cur->next;
- }
- } else if ((wild->negNsSet != NULL) && (ns != NULL) &&
- (!xmlStrEqual(wild->negNsSet->value, ns)))
- return(0);
- return(1);
- }
- #define XML_SCHEMA_ACTION_DERIVE 0
- #define XML_SCHEMA_ACTION_REDEFINE 1
- #define WXS_ACTION_STR(a) \
- ((a) == XML_SCHEMA_ACTION_DERIVE) ? (const xmlChar *) "base" : (const xmlChar *) "redefined"
- static int
- xmlSchemaCheckDerivationOKRestriction2to4(xmlSchemaParserCtxtPtr pctxt,
- int action,
- xmlSchemaBasicItemPtr item,
- xmlSchemaBasicItemPtr baseItem,
- xmlSchemaItemListPtr uses,
- xmlSchemaItemListPtr baseUses,
- xmlSchemaWildcardPtr wild,
- xmlSchemaWildcardPtr baseWild)
- {
- xmlSchemaAttributeUsePtr cur = NULL, bcur;
- int i, j, found;
- const xmlChar *bEffValue;
- int effFixed;
- if (uses != NULL) {
- for (i = 0; i < uses->nbItems; i++) {
- cur = uses->items[i];
- found = 0;
- if (baseUses == NULL)
- goto not_found;
- for (j = 0; j < baseUses->nbItems; j++) {
- bcur = baseUses->items[j];
- if ((WXS_ATTRUSE_DECL_NAME(cur) ==
- WXS_ATTRUSE_DECL_NAME(bcur)) &&
- (WXS_ATTRUSE_DECL_TNS(cur) ==
- WXS_ATTRUSE_DECL_TNS(bcur)))
- {
-
- found = 1;
- if ((cur->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) &&
- (bcur->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED))
- {
- xmlChar *str = NULL;
-
- xmlSchemaPAttrUseErr4(pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_1,
- WXS_ITEM_NODE(item), item, cur,
- "The 'optional' attribute use is inconsistent "
- "with the corresponding 'required' attribute use of "
- "the %s %s",
- WXS_ACTION_STR(action),
- xmlSchemaGetComponentDesignation(&str, baseItem),
- NULL, NULL);
- FREE_AND_NULL(str);
-
- } else if (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
- WXS_ATTRUSE_TYPEDEF(cur),
- WXS_ATTRUSE_TYPEDEF(bcur), 0) != 0)
- {
- xmlChar *strA = NULL, *strB = NULL, *strC = NULL;
-
- xmlSchemaPAttrUseErr4(pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_2,
- WXS_ITEM_NODE(item), item, cur,
- "The attribute declaration's %s "
- "is not validly derived from "
- "the corresponding %s of the "
- "attribute declaration in the %s %s",
- xmlSchemaGetComponentDesignation(&strA,
- WXS_ATTRUSE_TYPEDEF(cur)),
- xmlSchemaGetComponentDesignation(&strB,
- WXS_ATTRUSE_TYPEDEF(bcur)),
- WXS_ACTION_STR(action),
- xmlSchemaGetComponentDesignation(&strC, baseItem));
-
- FREE_AND_NULL(strA);
- FREE_AND_NULL(strB);
- FREE_AND_NULL(strC);
-
- } else {
-
- xmlSchemaGetEffectiveValueConstraint(bcur,
- &effFixed, &bEffValue, NULL);
-
- if ((bEffValue != NULL) &&
- (effFixed == 1)) {
- const xmlChar *rEffValue = NULL;
- xmlSchemaGetEffectiveValueConstraint(bcur,
- &effFixed, &rEffValue, NULL);
-
- if ((effFixed == 0) ||
- (! WXS_ARE_DEFAULT_STR_EQUAL(rEffValue, bEffValue)))
- {
- xmlChar *str = NULL;
- xmlSchemaPAttrUseErr4(pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_1_3,
- WXS_ITEM_NODE(item), item, cur,
- "The effective value constraint of the "
- "attribute use is inconsistent with "
- "its correspondent in the %s %s",
- WXS_ACTION_STR(action),
- xmlSchemaGetComponentDesignation(&str,
- baseItem),
- NULL, NULL);
- FREE_AND_NULL(str);
-
- }
- }
- }
- break;
- }
- }
- not_found:
- if (!found) {
-
- if ((baseWild == NULL) ||
- (xmlSchemaCheckCVCWildcardNamespace(baseWild,
- (WXS_ATTRUSE_DECL(cur))->targetNamespace) != 0))
- {
- xmlChar *str = NULL;
- xmlSchemaPAttrUseErr4(pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_2_2,
- WXS_ITEM_NODE(item), item, cur,
- "Neither a matching attribute use, "
- "nor a matching wildcard exists in the %s %s",
- WXS_ACTION_STR(action),
- xmlSchemaGetComponentDesignation(&str, baseItem),
- NULL, NULL);
- FREE_AND_NULL(str);
-
- }
- }
- }
- }
-
- if (baseUses != NULL) {
- for (j = 0; j < baseUses->nbItems; j++) {
- bcur = baseUses->items[j];
- if (bcur->occurs != XML_SCHEMAS_ATTR_USE_REQUIRED)
- continue;
- found = 0;
- if (uses != NULL) {
- for (i = 0; i < uses->nbItems; i++) {
- cur = uses->items[i];
- if ((WXS_ATTRUSE_DECL_NAME(cur) ==
- WXS_ATTRUSE_DECL_NAME(bcur)) &&
- (WXS_ATTRUSE_DECL_TNS(cur) ==
- WXS_ATTRUSE_DECL_TNS(bcur))) {
- found = 1;
- break;
- }
- }
- }
- if (!found) {
- xmlChar *strA = NULL, *strB = NULL;
- xmlSchemaCustomErr4(ACTXT_CAST pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_3,
- NULL, item,
- "A matching attribute use for the "
- "'required' %s of the %s %s is missing",
- xmlSchemaGetComponentDesignation(&strA, bcur),
- WXS_ACTION_STR(action),
- xmlSchemaGetComponentDesignation(&strB, baseItem),
- NULL);
- FREE_AND_NULL(strA);
- FREE_AND_NULL(strB);
- }
- }
- }
-
- if (wild != NULL) {
-
- if (baseWild == NULL) {
- xmlChar *str = NULL;
-
- xmlSchemaCustomErr4(ACTXT_CAST pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_1,
- NULL, item,
- "The %s has an attribute wildcard, "
- "but the %s %s '%s' does not have one",
- WXS_ITEM_TYPE_NAME(item),
- WXS_ACTION_STR(action),
- WXS_ITEM_TYPE_NAME(baseItem),
- xmlSchemaGetComponentQName(&str, baseItem));
- FREE_AND_NULL(str);
- return(pctxt->err);
- } else if ((baseWild->any == 0) &&
- xmlSchemaCheckCOSNSSubset(wild, baseWild))
- {
- xmlChar *str = NULL;
-
- xmlSchemaCustomErr4(ACTXT_CAST pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_2,
- NULL, item,
- "The attribute wildcard is not a valid "
- "subset of the wildcard in the %s %s '%s'",
- WXS_ACTION_STR(action),
- WXS_ITEM_TYPE_NAME(baseItem),
- xmlSchemaGetComponentQName(&str, baseItem),
- NULL);
- FREE_AND_NULL(str);
- return(pctxt->err);
- }
-
- if ((! WXS_IS_ANYTYPE(baseItem)) &&
- (wild->processContents < baseWild->processContents)) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr4(ACTXT_CAST pctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_4_3,
- NULL, baseItem,
- "The {process contents} of the attribute wildcard is "
- "weaker than the one in the %s %s '%s'",
- WXS_ACTION_STR(action),
- WXS_ITEM_TYPE_NAME(baseItem),
- xmlSchemaGetComponentQName(&str, baseItem),
- NULL);
- FREE_AND_NULL(str)
- return(pctxt->err);
- }
- }
- return(0);
- }
- static int
- xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBasicItemPtr item,
- xmlSchemaWildcardPtr *completeWild,
- xmlSchemaItemListPtr list,
- xmlSchemaItemListPtr prohibs);
- static int
- xmlSchemaFixupTypeAttributeUses(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypePtr baseType = NULL;
- xmlSchemaAttributeUsePtr use;
- xmlSchemaItemListPtr uses, baseUses, prohibs = NULL;
- if (type->baseType == NULL) {
- PERROR_INT("xmlSchemaFixupTypeAttributeUses",
- "no base type");
- return (-1);
- }
- baseType = type->baseType;
- if (WXS_IS_TYPE_NOT_FIXED(baseType))
- if (xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt) == -1)
- return(-1);
- uses = type->attrUses;
- baseUses = baseType->attrUses;
-
- if (uses != NULL) {
- if (WXS_IS_RESTRICTION(type)) {
-
- if (xmlSchemaExpandAttributeGroupRefs(pctxt,
- WXS_BASIC_CAST type, &(type->attributeWildcard), uses,
- pctxt->attrProhibs) == -1)
- {
- PERROR_INT("xmlSchemaFixupTypeAttributeUses",
- "failed to expand attributes");
- }
- if (pctxt->attrProhibs->nbItems != 0)
- prohibs = pctxt->attrProhibs;
- } else {
- if (xmlSchemaExpandAttributeGroupRefs(pctxt,
- WXS_BASIC_CAST type, &(type->attributeWildcard), uses,
- NULL) == -1)
- {
- PERROR_INT("xmlSchemaFixupTypeAttributeUses",
- "failed to expand attributes");
- }
- }
- }
-
- if (baseUses != NULL) {
- int i, j;
- xmlSchemaAttributeUseProhibPtr pro;
- if (WXS_IS_RESTRICTION(type)) {
- int usesCount;
- xmlSchemaAttributeUsePtr tmp;
- if (uses != NULL)
- usesCount = uses->nbItems;
- else
- usesCount = 0;
-
- for (i = 0; i < baseUses->nbItems; i++) {
- use = baseUses->items[i];
- if (prohibs) {
-
- for (j = 0; j < prohibs->nbItems; j++) {
- pro = prohibs->items[j];
- if ((WXS_ATTRUSE_DECL_NAME(use) == pro->name) &&
- (WXS_ATTRUSE_DECL_TNS(use) ==
- pro->targetNamespace))
- {
- goto inherit_next;
- }
- }
- }
- if (usesCount) {
-
- for (j = 0; j < usesCount; j++) {
- tmp = uses->items[j];
- if ((WXS_ATTRUSE_DECL_NAME(use) ==
- WXS_ATTRUSE_DECL_NAME(tmp)) &&
- (WXS_ATTRUSE_DECL_TNS(use) ==
- WXS_ATTRUSE_DECL_TNS(tmp)))
- {
- goto inherit_next;
- }
- }
- }
- if (uses == NULL) {
- type->attrUses = xmlSchemaItemListCreate();
- if (type->attrUses == NULL)
- goto exit_failure;
- uses = type->attrUses;
- }
- xmlSchemaItemListAddSize(uses, 2, use);
- inherit_next: {}
- }
- } else {
-
- for (i = 0; i < baseUses->nbItems; i++) {
- use = baseUses->items[i];
- if (uses == NULL) {
- type->attrUses = xmlSchemaItemListCreate();
- if (type->attrUses == NULL)
- goto exit_failure;
- uses = type->attrUses;
- }
- xmlSchemaItemListAddSize(uses, baseUses->nbItems, use);
- }
- }
- }
-
- if (uses) {
- if (uses->nbItems == 0) {
- xmlSchemaItemListFree(uses);
- type->attrUses = NULL;
- }
-
- }
-
- if (WXS_IS_EXTENSION(type)) {
- if (baseType->attributeWildcard != NULL) {
-
- if (type->attributeWildcard != NULL) {
-
- if (xmlSchemaUnionWildcards(pctxt, type->attributeWildcard,
- baseType->attributeWildcard) == -1)
- goto exit_failure;
- } else {
-
- type->attributeWildcard = baseType->attributeWildcard;
- }
- } else {
-
- }
- } else {
-
- }
- return (0);
- exit_failure:
- return(-1);
- }
- static int
- xmlSchemaTypeFinalContains(xmlSchemaTypePtr type, int final)
- {
- if (type == NULL)
- return (0);
- if (type->flags & final)
- return (1);
- else
- return (0);
- }
- static xmlSchemaTypeLinkPtr
- xmlSchemaGetUnionSimpleTypeMemberTypes(xmlSchemaTypePtr type)
- {
- while ((type != NULL) && (type->type == XML_SCHEMA_TYPE_SIMPLE)) {
- if (type->memberTypes != NULL)
- return (type->memberTypes);
- else
- type = type->baseType;
- }
- return (NULL);
- }
- static int
- xmlSchemaGetParticleTotalRangeMin(xmlSchemaParticlePtr particle)
- {
- if ((particle->children == NULL) ||
- (particle->minOccurs == 0))
- return (0);
- if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) {
- int min = -1, cur;
- xmlSchemaParticlePtr part =
- (xmlSchemaParticlePtr) particle->children->children;
- if (part == NULL)
- return (0);
- while (part != NULL) {
- if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
- (part->children->type == XML_SCHEMA_TYPE_ANY))
- cur = part->minOccurs;
- else
- cur = xmlSchemaGetParticleTotalRangeMin(part);
- if (cur == 0)
- return (0);
- if ((min > cur) || (min == -1))
- min = cur;
- part = (xmlSchemaParticlePtr) part->next;
- }
- return (particle->minOccurs * min);
- } else {
-
- int sum = 0;
- xmlSchemaParticlePtr part =
- (xmlSchemaParticlePtr) particle->children->children;
- if (part == NULL)
- return (0);
- do {
- if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
- (part->children->type == XML_SCHEMA_TYPE_ANY))
- sum += part->minOccurs;
- else
- sum += xmlSchemaGetParticleTotalRangeMin(part);
- part = (xmlSchemaParticlePtr) part->next;
- } while (part != NULL);
- return (particle->minOccurs * sum);
- }
- }
- #if 0
- static int
- xmlSchemaGetParticleTotalRangeMax(xmlSchemaParticlePtr particle)
- {
- if ((particle->children == NULL) ||
- (particle->children->children == NULL))
- return (0);
- if (particle->children->type == XML_SCHEMA_TYPE_CHOICE) {
- int max = -1, cur;
- xmlSchemaParticlePtr part =
- (xmlSchemaParticlePtr) particle->children->children;
- for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) {
- if (part->children == NULL)
- continue;
- if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
- (part->children->type == XML_SCHEMA_TYPE_ANY))
- cur = part->maxOccurs;
- else
- cur = xmlSchemaGetParticleTotalRangeMax(part);
- if (cur == UNBOUNDED)
- return (UNBOUNDED);
- if ((max < cur) || (max == -1))
- max = cur;
- }
-
- return (particle->maxOccurs * max);
- } else {
-
- int sum = 0, cur;
- xmlSchemaParticlePtr part =
- (xmlSchemaParticlePtr) particle->children->children;
- for (; part != NULL; part = (xmlSchemaParticlePtr) part->next) {
- if (part->children == NULL)
- continue;
- if ((part->children->type == XML_SCHEMA_TYPE_ELEMENT) ||
- (part->children->type == XML_SCHEMA_TYPE_ANY))
- cur = part->maxOccurs;
- else
- cur = xmlSchemaGetParticleTotalRangeMax(part);
- if (cur == UNBOUNDED)
- return (UNBOUNDED);
- if ((cur > 0) && (particle->maxOccurs == UNBOUNDED))
- return (UNBOUNDED);
- sum += cur;
- }
-
- return (particle->maxOccurs * sum);
- }
- }
- #endif
- static int
- xmlSchemaIsParticleEmptiable(xmlSchemaParticlePtr particle)
- {
-
- if ((particle == NULL) || (particle->minOccurs == 0) ||
- (particle->children == NULL))
- return (1);
-
- if (WXS_IS_MODEL_GROUP(particle->children)) {
- if (xmlSchemaGetParticleTotalRangeMin(particle) == 0)
- return (1);
- }
- return (0);
- }
- static int
- xmlSchemaCheckCOSSTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
- xmlSchemaTypePtr type,
- xmlSchemaTypePtr baseType,
- int subset)
- {
-
- if (type == baseType)
- return (0);
-
- if (WXS_IS_TYPE_NOT_FIXED(type))
- if (xmlSchemaTypeFixup(type, actxt) == -1)
- return(-1);
- if (WXS_IS_TYPE_NOT_FIXED(baseType))
- if (xmlSchemaTypeFixup(baseType, actxt) == -1)
- return(-1);
- if ((subset & SUBSET_RESTRICTION) ||
- (xmlSchemaTypeFinalContains(type->baseType,
- XML_SCHEMAS_TYPE_FINAL_RESTRICTION))) {
- return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_1);
- }
-
- if (type->baseType == baseType) {
-
- return (0);
- }
-
- if ((! WXS_IS_ANYTYPE(type->baseType)) &&
- (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
- baseType, subset) == 0)) {
- return (0);
- }
-
- if (WXS_IS_ANY_SIMPLE_TYPE(baseType) &&
- (WXS_IS_LIST(type) || WXS_IS_UNION(type))) {
- return (0);
- }
-
- if (WXS_IS_UNION(baseType)) {
- xmlSchemaTypeLinkPtr cur;
- cur = baseType->memberTypes;
- while (cur != NULL) {
- if (WXS_IS_TYPE_NOT_FIXED(cur->type))
- if (xmlSchemaTypeFixup(cur->type, actxt) == -1)
- return(-1);
- if (xmlSchemaCheckCOSSTDerivedOK(actxt,
- type, cur->type, subset) == 0)
- {
-
- return (0);
- }
- cur = cur->next;
- }
- }
- return (XML_SCHEMAP_COS_ST_DERIVED_OK_2_2);
- }
- static int
- xmlSchemaCheckTypeDefCircularInternal(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr ctxtType,
- xmlSchemaTypePtr ancestor)
- {
- int ret;
- if ((ancestor == NULL) || (ancestor->type == XML_SCHEMA_TYPE_BASIC))
- return (0);
- if (ctxtType == ancestor) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_ST_PROPS_CORRECT_2,
- WXS_BASIC_CAST ctxtType, WXS_ITEM_NODE(ctxtType),
- "The definition is circular", NULL);
- return (XML_SCHEMAP_ST_PROPS_CORRECT_2);
- }
- if (ancestor->flags & XML_SCHEMAS_TYPE_MARKED) {
-
- return (0);
- }
- ancestor->flags |= XML_SCHEMAS_TYPE_MARKED;
- ret = xmlSchemaCheckTypeDefCircularInternal(pctxt, ctxtType,
- ancestor->baseType);
- ancestor->flags ^= XML_SCHEMAS_TYPE_MARKED;
- return (ret);
- }
- static void
- xmlSchemaCheckTypeDefCircular(xmlSchemaTypePtr item,
- xmlSchemaParserCtxtPtr ctxt)
- {
- if ((item == NULL) ||
- (item->type == XML_SCHEMA_TYPE_BASIC) ||
- (item->baseType == NULL))
- return;
- xmlSchemaCheckTypeDefCircularInternal(ctxt, item,
- item->baseType);
- }
- static int
- xmlSchemaCheckUnionTypeDefCircularRecur(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr ctxType,
- xmlSchemaTypeLinkPtr members)
- {
- xmlSchemaTypeLinkPtr member;
- xmlSchemaTypePtr memberType;
- member = members;
- while (member != NULL) {
- memberType = member->type;
- while ((memberType != NULL) &&
- (memberType->type != XML_SCHEMA_TYPE_BASIC)) {
- if (memberType == ctxType) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_SRC_SIMPLE_TYPE_4,
- WXS_BASIC_CAST ctxType, NULL,
- "The union type definition is circular", NULL);
- return (XML_SCHEMAP_SRC_SIMPLE_TYPE_4);
- }
- if ((WXS_IS_UNION(memberType)) &&
- ((memberType->flags & XML_SCHEMAS_TYPE_MARKED) == 0))
- {
- int res;
- memberType->flags |= XML_SCHEMAS_TYPE_MARKED;
- res = xmlSchemaCheckUnionTypeDefCircularRecur(pctxt,
- ctxType,
- xmlSchemaGetUnionSimpleTypeMemberTypes(memberType));
- memberType->flags ^= XML_SCHEMAS_TYPE_MARKED;
- if (res != 0)
- return(res);
- }
- memberType = memberType->baseType;
- }
- member = member->next;
- }
- return(0);
- }
- static int
- xmlSchemaCheckUnionTypeDefCircular(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- if (! WXS_IS_UNION(type))
- return(0);
- return(xmlSchemaCheckUnionTypeDefCircularRecur(pctxt, type,
- type->memberTypes));
- }
- static void
- xmlSchemaResolveTypeReferences(xmlSchemaTypePtr typeDef,
- xmlSchemaParserCtxtPtr ctxt)
- {
- if (typeDef == NULL)
- return;
-
- if (typeDef->baseType == NULL) {
- typeDef->baseType = xmlSchemaGetType(ctxt->schema,
- typeDef->base, typeDef->baseNs);
- if (typeDef->baseType == NULL) {
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST typeDef, typeDef->node,
- "base", typeDef->base, typeDef->baseNs,
- XML_SCHEMA_TYPE_SIMPLE, NULL);
- return;
- }
- }
- if (WXS_IS_SIMPLE(typeDef)) {
- if (WXS_IS_UNION(typeDef)) {
-
- xmlSchemaResolveUnionMemberTypes(ctxt, typeDef);
- return;
- } else if (WXS_IS_LIST(typeDef)) {
-
- if ((typeDef->subtypes == NULL) && (typeDef->base != NULL)) {
- typeDef->subtypes = xmlSchemaGetType(ctxt->schema,
- typeDef->base, typeDef->baseNs);
- if ((typeDef->subtypes == NULL) ||
- (! WXS_IS_SIMPLE(typeDef->subtypes)))
- {
- typeDef->subtypes = NULL;
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST typeDef, typeDef->node,
- "itemType", typeDef->base, typeDef->baseNs,
- XML_SCHEMA_TYPE_SIMPLE, NULL);
- }
- }
- return;
- }
- }
-
- else if ((WXS_TYPE_CONTENTTYPE(typeDef) != NULL) &&
- ((WXS_TYPE_CONTENTTYPE(typeDef))->type ==
- XML_SCHEMA_TYPE_PARTICLE) &&
- (WXS_TYPE_PARTICLE_TERM(typeDef) != NULL) &&
- ((WXS_TYPE_PARTICLE_TERM(typeDef))->type ==
- XML_SCHEMA_EXTRA_QNAMEREF))
- {
- xmlSchemaQNameRefPtr ref =
- WXS_QNAME_CAST WXS_TYPE_PARTICLE_TERM(typeDef);
- xmlSchemaModelGroupDefPtr groupDef;
-
- WXS_TYPE_PARTICLE_TERM(typeDef) = NULL;
-
- groupDef =
- WXS_MODEL_GROUPDEF_CAST xmlSchemaGetNamedComponent(ctxt->schema,
- ref->itemType, ref->name, ref->targetNamespace);
- if (groupDef == NULL) {
- xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
- NULL, WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)),
- "ref", ref->name, ref->targetNamespace, ref->itemType,
- NULL);
-
- WXS_TYPE_CONTENTTYPE(typeDef) = NULL;
- } else if (WXS_MODELGROUPDEF_MODEL(groupDef) == NULL)
-
- WXS_TYPE_CONTENTTYPE(typeDef) = NULL;
- else {
-
- WXS_TYPE_PARTICLE_TERM(typeDef) = WXS_MODELGROUPDEF_MODEL(groupDef);
- if (WXS_MODELGROUPDEF_MODEL(groupDef)->type == XML_SCHEMA_TYPE_ALL) {
-
- if ((WXS_TYPE_PARTICLE(typeDef))->maxOccurs != 1) {
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
-
- XML_SCHEMAP_COS_ALL_LIMITED,
- WXS_ITEM_NODE(WXS_TYPE_PARTICLE(typeDef)), NULL,
- "The particle's {max occurs} must be 1, since the "
- "reference resolves to an 'all' model group",
- NULL, NULL);
- }
- }
- }
- }
- }
- static int
- xmlSchemaCheckSTPropsCorrect(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypePtr baseType = type->baseType;
- xmlChar *str = NULL;
-
-
-
- if (baseType == NULL) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_ST_PROPS_CORRECT_1,
- WXS_BASIC_CAST type, NULL,
- "No base type existent", NULL);
- return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
- }
- if (! WXS_IS_SIMPLE(baseType)) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_ST_PROPS_CORRECT_1,
- WXS_BASIC_CAST type, NULL,
- "The base type '%s' is not a simple type",
- xmlSchemaGetComponentQName(&str, baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
- }
- if ( (WXS_IS_LIST(type) || WXS_IS_UNION(type)) &&
- (WXS_IS_RESTRICTION(type) == 0) &&
- (! WXS_IS_ANY_SIMPLE_TYPE(baseType))) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_ST_PROPS_CORRECT_1,
- WXS_BASIC_CAST type, NULL,
- "A type, derived by list or union, must have "
- "the simple ur-type definition as base type, not '%s'",
- xmlSchemaGetComponentQName(&str, baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
- }
-
- if ((! WXS_IS_ATOMIC(type)) && (! WXS_IS_UNION(type)) &&
- (! WXS_IS_LIST(type))) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_ST_PROPS_CORRECT_1,
- WXS_BASIC_CAST type, NULL,
- "The variety is absent", NULL);
- return (XML_SCHEMAP_ST_PROPS_CORRECT_1);
- }
-
-
- if (xmlSchemaTypeFinalContains(baseType,
- XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_ST_PROPS_CORRECT_3,
- WXS_BASIC_CAST type, NULL,
- "The 'final' of its base type '%s' must not contain "
- "'restriction'",
- xmlSchemaGetComponentQName(&str, baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_ST_PROPS_CORRECT_3);
- }
-
- return (0);
- }
- static int
- xmlSchemaCheckCOSSTRestricts(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- xmlChar *str = NULL;
- if (type->type != XML_SCHEMA_TYPE_SIMPLE) {
- PERROR_INT("xmlSchemaCheckCOSSTRestricts",
- "given type is not a user-derived simpleType");
- return (-1);
- }
- if (WXS_IS_ATOMIC(type)) {
- xmlSchemaTypePtr primitive;
-
- if (! WXS_IS_ATOMIC(type->baseType)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_1_1,
- WXS_BASIC_CAST type, NULL,
- "The base type '%s' is not an atomic simple type",
- xmlSchemaGetComponentQName(&str, type->baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_1_1);
- }
-
-
- if (xmlSchemaTypeFinalContains(type->baseType,
- XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_1_2,
- WXS_BASIC_CAST type, NULL,
- "The final of its base type '%s' must not contain 'restriction'",
- xmlSchemaGetComponentQName(&str, type->baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_1_2);
- }
-
- if (type->facets != NULL) {
- xmlSchemaFacetPtr facet;
- int ok = 1;
- primitive = xmlSchemaGetPrimitiveType(type);
- if (primitive == NULL) {
- PERROR_INT("xmlSchemaCheckCOSSTRestricts",
- "failed to get primitive type");
- return (-1);
- }
- facet = type->facets;
- do {
- if (xmlSchemaIsBuiltInTypeFacet(primitive, facet->type) == 0) {
- ok = 0;
- xmlSchemaPIllegalFacetAtomicErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1,
- type, primitive, facet);
- }
- facet = facet->next;
- } while (facet != NULL);
- if (ok == 0)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_1_3_1);
- }
-
- } else if (WXS_IS_LIST(type)) {
- xmlSchemaTypePtr itemType = NULL;
- itemType = type->subtypes;
- if ((itemType == NULL) || (! WXS_IS_SIMPLE(itemType))) {
- PERROR_INT("xmlSchemaCheckCOSSTRestricts",
- "failed to evaluate the item type");
- return (-1);
- }
- if (WXS_IS_TYPE_NOT_FIXED(itemType))
- xmlSchemaTypeFixup(itemType, ACTXT_CAST pctxt);
-
- if ((! WXS_IS_ATOMIC(itemType)) &&
- (! WXS_IS_UNION(itemType))) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_1,
- WXS_BASIC_CAST type, NULL,
- "The item type '%s' does not have a variety of atomic or union",
- xmlSchemaGetComponentQName(&str, itemType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1);
- } else if (WXS_IS_UNION(itemType)) {
- xmlSchemaTypeLinkPtr member;
- member = itemType->memberTypes;
- while (member != NULL) {
- if (! WXS_IS_ATOMIC(member->type)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_1,
- WXS_BASIC_CAST type, NULL,
- "The item type is a union type, but the "
- "member type '%s' of this item type is not atomic",
- xmlSchemaGetComponentQName(&str, member->type));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_1);
- }
- member = member->next;
- }
- }
- if (WXS_IS_ANY_SIMPLE_TYPE(type->baseType)) {
- xmlSchemaFacetPtr facet;
-
-
- if (xmlSchemaTypeFinalContains(itemType,
- XML_SCHEMAS_TYPE_FINAL_LIST)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1,
- WXS_BASIC_CAST type, NULL,
- "The final of its item type '%s' must not contain 'list'",
- xmlSchemaGetComponentQName(&str, itemType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_1);
- }
-
- if (type->facets != NULL) {
- facet = type->facets;
- do {
- if (facet->type != XML_SCHEMA_FACET_WHITESPACE) {
- xmlSchemaPIllegalFacetListUnionErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2,
- type, facet);
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_1_2);
- }
- facet = facet->next;
- } while (facet != NULL);
- }
-
- } else {
-
-
- if (! WXS_IS_LIST(type->baseType)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1,
- WXS_BASIC_CAST type, NULL,
- "The base type '%s' must be a list type",
- xmlSchemaGetComponentQName(&str, type->baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_1);
- }
-
- if (xmlSchemaTypeFinalContains(type->baseType,
- XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2,
- WXS_BASIC_CAST type, NULL,
- "The 'final' of the base type '%s' must not contain 'restriction'",
- xmlSchemaGetComponentQName(&str, type->baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_2);
- }
-
- {
- xmlSchemaTypePtr baseItemType;
- baseItemType = type->baseType->subtypes;
- if ((baseItemType == NULL) || (! WXS_IS_SIMPLE(baseItemType))) {
- PERROR_INT("xmlSchemaCheckCOSSTRestricts",
- "failed to eval the item type of a base type");
- return (-1);
- }
- if ((itemType != baseItemType) &&
- (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt, itemType,
- baseItemType, 0) != 0)) {
- xmlChar *strBIT = NULL, *strBT = NULL;
- xmlSchemaPCustomErrExt(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3,
- WXS_BASIC_CAST type, NULL,
- "The item type '%s' is not validly derived from "
- "the item type '%s' of the base type '%s'",
- xmlSchemaGetComponentQName(&str, itemType),
- xmlSchemaGetComponentQName(&strBIT, baseItemType),
- xmlSchemaGetComponentQName(&strBT, type->baseType));
- FREE_AND_NULL(str)
- FREE_AND_NULL(strBIT)
- FREE_AND_NULL(strBT)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_3);
- }
- }
- if (type->facets != NULL) {
- xmlSchemaFacetPtr facet;
- int ok = 1;
-
- facet = type->facets;
- do {
- switch (facet->type) {
- case XML_SCHEMA_FACET_LENGTH:
- case XML_SCHEMA_FACET_MINLENGTH:
- case XML_SCHEMA_FACET_MAXLENGTH:
- case XML_SCHEMA_FACET_WHITESPACE:
-
- case XML_SCHEMA_FACET_PATTERN:
- case XML_SCHEMA_FACET_ENUMERATION:
- break;
- default: {
- xmlSchemaPIllegalFacetListUnionErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4,
- type, facet);
-
- ok = 0;
- }
- }
- facet = facet->next;
- } while (facet != NULL);
- if (ok == 0)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_2_3_2_4);
-
- }
- }
- } else if (WXS_IS_UNION(type)) {
-
- xmlSchemaTypeLinkPtr member;
- member = type->memberTypes;
- while (member != NULL) {
- if (WXS_IS_TYPE_NOT_FIXED(member->type))
- xmlSchemaTypeFixup(member->type, ACTXT_CAST pctxt);
- if ((! WXS_IS_ATOMIC(member->type)) &&
- (! WXS_IS_LIST(member->type))) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_1,
- WXS_BASIC_CAST type, NULL,
- "The member type '%s' is neither an atomic, nor a list type",
- xmlSchemaGetComponentQName(&str, member->type));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_1);
- }
- member = member->next;
- }
-
- if (type->baseType->builtInType == XML_SCHEMAS_ANYSIMPLETYPE) {
-
- member = type->memberTypes;
- while (member != NULL) {
- if (xmlSchemaTypeFinalContains(member->type,
- XML_SCHEMAS_TYPE_FINAL_UNION)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1,
- WXS_BASIC_CAST type, NULL,
- "The 'final' of member type '%s' contains 'union'",
- xmlSchemaGetComponentQName(&str, member->type));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1);
- }
- member = member->next;
- }
-
- if (type->facetSet != NULL) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2,
- WXS_BASIC_CAST type, NULL,
- "No facets allowed", NULL);
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_1_2);
- }
- } else {
-
- if (! WXS_IS_UNION(type->baseType)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1,
- WXS_BASIC_CAST type, NULL,
- "The base type '%s' is not a union type",
- xmlSchemaGetComponentQName(&str, type->baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_1);
- }
-
- if (xmlSchemaTypeFinalContains(type->baseType,
- XML_SCHEMAS_TYPE_FINAL_RESTRICTION)) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2,
- WXS_BASIC_CAST type, NULL,
- "The 'final' of its base type '%s' must not contain 'restriction'",
- xmlSchemaGetComponentQName(&str, type->baseType));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_2);
- }
-
- {
- xmlSchemaTypeLinkPtr baseMember;
-
-
- if (type->memberTypes != NULL) {
- member = type->memberTypes;
- baseMember = xmlSchemaGetUnionSimpleTypeMemberTypes(type->baseType);
- if ((member == NULL) && (baseMember != NULL)) {
- PERROR_INT("xmlSchemaCheckCOSSTRestricts",
- "different number of member types in base");
- }
- while (member != NULL) {
- if (baseMember == NULL) {
- PERROR_INT("xmlSchemaCheckCOSSTRestricts",
- "different number of member types in base");
- } else if ((member->type != baseMember->type) &&
- (xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST pctxt,
- member->type, baseMember->type, 0) != 0)) {
- xmlChar *strBMT = NULL, *strBT = NULL;
- xmlSchemaPCustomErrExt(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3,
- WXS_BASIC_CAST type, NULL,
- "The member type %s is not validly "
- "derived from its corresponding member "
- "type %s of the base type %s",
- xmlSchemaGetComponentQName(&str, member->type),
- xmlSchemaGetComponentQName(&strBMT, baseMember->type),
- xmlSchemaGetComponentQName(&strBT, type->baseType));
- FREE_AND_NULL(str)
- FREE_AND_NULL(strBMT)
- FREE_AND_NULL(strBT)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_3);
- }
- member = member->next;
- if (baseMember != NULL)
- baseMember = baseMember->next;
- }
- }
- }
-
- if (type->facets != NULL) {
- xmlSchemaFacetPtr facet;
- int ok = 1;
- facet = type->facets;
- do {
- if ((facet->type != XML_SCHEMA_FACET_PATTERN) &&
- (facet->type != XML_SCHEMA_FACET_ENUMERATION)) {
- xmlSchemaPIllegalFacetListUnionErr(pctxt,
- XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4,
- type, facet);
- ok = 0;
- }
- facet = facet->next;
- } while (facet != NULL);
- if (ok == 0)
- return (XML_SCHEMAP_COS_ST_RESTRICTS_3_3_2_4);
- }
-
- }
- }
- return (0);
- }
- #if 0
- static int
- xmlSchemaCheckSRCSimpleType(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
-
- if (WXS_IS_RESTRICTION(type)) {
-
-
- } else if (WXS_IS_LIST(type)) {
-
- } else if (WXS_IS_UNION(type)) {
-
- }
- return (0);
- }
- #endif
- static int
- xmlSchemaCreateVCtxtOnPCtxt(xmlSchemaParserCtxtPtr ctxt)
- {
- if (ctxt->vctxt == NULL) {
- ctxt->vctxt = xmlSchemaNewValidCtxt(NULL);
- if (ctxt->vctxt == NULL) {
- xmlSchemaPErr(ctxt, NULL,
- XML_SCHEMAP_INTERNAL,
- "Internal error: xmlSchemaCreateVCtxtOnPCtxt, "
- "failed to create a temp. validation context.\n",
- NULL, NULL);
- return (-1);
- }
-
- xmlSchemaSetValidErrors(ctxt->vctxt,
- ctxt->error, ctxt->warning, ctxt->errCtxt);
- xmlSchemaSetValidStructuredErrors(ctxt->vctxt,
- ctxt->serror, ctxt->errCtxt);
- }
- return (0);
- }
- static int
- xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
- xmlNodePtr node,
- xmlSchemaTypePtr type,
- const xmlChar *value,
- xmlSchemaValPtr *retVal,
- int fireErrors,
- int normalize,
- int isNormalized);
- static int
- xmlSchemaParseCheckCOSValidDefault(xmlSchemaParserCtxtPtr pctxt,
- xmlNodePtr node,
- xmlSchemaTypePtr type,
- const xmlChar *value,
- xmlSchemaValPtr *val)
- {
- int ret = 0;
-
- if WXS_IS_COMPLEX(type) {
-
- if ((! WXS_HAS_SIMPLE_CONTENT(type)) &&
- ((! WXS_HAS_MIXED_CONTENT(type)) || (! WXS_EMPTIABLE(type)))) {
-
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_COS_VALID_DEFAULT_2_1,
- WXS_BASIC_CAST type, type->node,
- "For a string to be a valid default, the type definition "
- "must be a simple type or a complex type with mixed content "
- "and a particle emptiable", NULL);
- return(XML_SCHEMAP_COS_VALID_DEFAULT_2_1);
- }
- }
-
- if (WXS_IS_SIMPLE(type))
- ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
- type, value, val, 1, 1, 0);
- else if (WXS_HAS_SIMPLE_CONTENT(type))
- ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt, node,
- type->contentTypeDef, value, val, 1, 1, 0);
- else
- return (ret);
- if (ret < 0) {
- PERROR_INT("xmlSchemaParseCheckCOSValidDefault",
- "calling xmlSchemaVCheckCVCSimpleType()");
- }
- return (ret);
- }
- static int
- xmlSchemaCheckCTPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
-
- if ((type->baseType != NULL) &&
- (WXS_IS_SIMPLE(type->baseType)) &&
- (WXS_IS_EXTENSION(type) == 0)) {
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_SRC_CT_1,
- NULL, WXS_BASIC_CAST type,
- "If the base type is a simple type, the derivation method must be "
- "'extension'", NULL, NULL);
- return (XML_SCHEMAP_SRC_CT_1);
- }
-
-
- if (type->attrUses &&
- (((xmlSchemaItemListPtr) type->attrUses)->nbItems > 1))
- {
- xmlSchemaItemListPtr uses = (xmlSchemaItemListPtr) type->attrUses;
- xmlSchemaAttributeUsePtr use, tmp;
- int i, j, hasId = 0;
- for (i = uses->nbItems -1; i >= 0; i--) {
- use = uses->items[i];
-
- if (i > 0) {
- for (j = i -1; j >= 0; j--) {
- tmp = uses->items[j];
- if ((WXS_ATTRUSE_DECL_NAME(use) ==
- WXS_ATTRUSE_DECL_NAME(tmp)) &&
- (WXS_ATTRUSE_DECL_TNS(use) ==
- WXS_ATTRUSE_DECL_TNS(tmp)))
- {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_AG_PROPS_CORRECT,
- NULL, WXS_BASIC_CAST type,
- "Duplicate %s",
- xmlSchemaGetComponentDesignation(&str, use),
- NULL);
- FREE_AND_NULL(str);
-
- if (xmlSchemaItemListRemove(uses, i) == -1)
- goto exit_failure;
- goto next_use;
- }
- }
- }
-
- if (WXS_ATTRUSE_TYPEDEF(use) != NULL) {
- if (xmlSchemaIsDerivedFromBuiltInType(
- WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
- {
- if (hasId) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_AG_PROPS_CORRECT,
- NULL, WXS_BASIC_CAST type,
- "There must not exist more than one attribute "
- "declaration of type 'xs:ID' "
- "(or derived from 'xs:ID'). The %s violates this "
- "constraint",
- xmlSchemaGetComponentDesignation(&str, use),
- NULL);
- FREE_AND_NULL(str);
- if (xmlSchemaItemListRemove(uses, i) == -1)
- goto exit_failure;
- }
- hasId = 1;
- }
- }
- next_use: {}
- }
- }
- return (0);
- exit_failure:
- return(-1);
- }
- static int
- xmlSchemaAreEqualTypes(xmlSchemaTypePtr typeA,
- xmlSchemaTypePtr typeB)
- {
-
- if ((typeA == NULL) || (typeB == NULL))
- return (0);
- return (typeA == typeB);
- }
- static int
- xmlSchemaCheckCOSCTDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
- xmlSchemaTypePtr type,
- xmlSchemaTypePtr baseType,
- int set)
- {
- int equal = xmlSchemaAreEqualTypes(type, baseType);
-
-
- if (! equal) {
-
- if (((set & SUBSET_EXTENSION) && (WXS_IS_EXTENSION(type))) ||
- ((set & SUBSET_RESTRICTION) && (WXS_IS_RESTRICTION(type))))
- return (1);
- } else {
-
- return (0);
- }
-
- if (type->baseType == baseType)
- return (0);
-
- if (WXS_IS_ANYTYPE(type->baseType))
- return (1);
- if (WXS_IS_COMPLEX(type->baseType)) {
-
- return (xmlSchemaCheckCOSCTDerivedOK(actxt, type->baseType,
- baseType, set));
- } else {
-
- return (xmlSchemaCheckCOSSTDerivedOK(actxt, type->baseType,
- baseType, set));
- }
- }
- static int
- xmlSchemaCheckCOSDerivedOK(xmlSchemaAbstractCtxtPtr actxt,
- xmlSchemaTypePtr type,
- xmlSchemaTypePtr baseType,
- int set)
- {
- if (WXS_IS_SIMPLE(type))
- return (xmlSchemaCheckCOSSTDerivedOK(actxt, type, baseType, set));
- else
- return (xmlSchemaCheckCOSCTDerivedOK(actxt, type, baseType, set));
- }
- static int
- xmlSchemaCheckCOSCTExtends(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypePtr base = type->baseType;
-
-
- if (WXS_IS_COMPLEX(base)) {
-
- if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_1,
- WXS_BASIC_CAST type, NULL,
- "The 'final' of the base type definition "
- "contains 'extension'", NULL);
- return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
- }
-
- #if 0
-
- if (base->attrUses != NULL) {
- int i, j, found;
- xmlSchemaAttributeUsePtr use, buse;
- for (i = 0; i < (WXS_LIST_CAST base->attrUses)->nbItems; i ++) {
- buse = (WXS_LIST_CAST base->attrUses)->items[i];
- found = 0;
- if (type->attrUses != NULL) {
- use = (WXS_LIST_CAST type->attrUses)->items[j];
- for (j = 0; j < (WXS_LIST_CAST type->attrUses)->nbItems; j ++)
- {
- if ((WXS_ATTRUSE_DECL_NAME(use) ==
- WXS_ATTRUSE_DECL_NAME(buse)) &&
- (WXS_ATTRUSE_DECL_TNS(use) ==
- WXS_ATTRUSE_DECL_TNS(buse)) &&
- (WXS_ATTRUSE_TYPEDEF(use) ==
- WXS_ATTRUSE_TYPEDEF(buse))
- {
- found = 1;
- break;
- }
- }
- }
- if (! found) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_2,
- NULL, WXS_BASIC_CAST type,
-
- "This type is missing a matching correspondent "
- "for its {base type}'s %s in its {attribute uses}",
- xmlSchemaGetComponentDesignation(&str,
- buse->children),
- NULL);
- FREE_AND_NULL(str)
- }
- }
- }
-
-
- if (base->attributeWildcard != NULL) {
- if (type->attributeWilcard == NULL) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_3,
- NULL, type,
- "The base %s has an attribute wildcard, "
- "but this type is missing an attribute wildcard",
- xmlSchemaGetComponentDesignation(&str, base));
- FREE_AND_NULL(str)
- } else if (xmlSchemaCheckCOSNSSubset(
- base->attributeWildcard, type->attributeWildcard))
- {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_3,
- NULL, type,
- "The attribute wildcard is not a valid "
- "superset of the one in the base %s",
- xmlSchemaGetComponentDesignation(&str, base));
- FREE_AND_NULL(str)
- }
- }
- #endif
-
- if ((type->contentTypeDef != NULL) &&
- (type->contentTypeDef == base->contentTypeDef)) {
-
- } else if ((type->contentType == XML_SCHEMA_CONTENT_EMPTY) &&
- (base->contentType == XML_SCHEMA_CONTENT_EMPTY) ) {
-
- } else {
-
- if (type->subtypes == NULL) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_1,
- WXS_BASIC_CAST type, NULL,
- "The content type must specify a particle", NULL);
- return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
- }
-
- if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) {
-
- } else {
-
- if ((type->contentType != base->contentType) ||
- ((type->contentType != XML_SCHEMA_CONTENT_MIXED) &&
- (type->contentType != XML_SCHEMA_CONTENT_ELEMENTS))) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_1,
- WXS_BASIC_CAST type, NULL,
- "The content type of both, the type and its base "
- "type, must either 'mixed' or 'element-only'", NULL);
- return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
- }
-
- }
-
- }
- } else {
-
- if (type->contentTypeDef != base) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_1,
- WXS_BASIC_CAST type, NULL,
- "The content type must be the simple base type", NULL);
- return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
- }
- if (base->flags & XML_SCHEMAS_TYPE_FINAL_EXTENSION) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_COS_CT_EXTENDS_1_1,
- WXS_BASIC_CAST type, NULL,
- "The 'final' of the base type definition "
- "contains 'extension'", NULL);
- return (XML_SCHEMAP_COS_CT_EXTENDS_1_1);
- }
- }
- return (0);
- }
- static int
- xmlSchemaCheckDerivationOKRestriction(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypePtr base;
-
- base = type->baseType;
- if (! WXS_IS_COMPLEX(base)) {
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- type->node, WXS_BASIC_CAST type,
- "The base type must be a complex type", NULL, NULL);
- return(ctxt->err);
- }
- if (base->flags & XML_SCHEMAS_TYPE_FINAL_RESTRICTION) {
-
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- type->node, WXS_BASIC_CAST type,
- "The 'final' of the base type definition "
- "contains 'restriction'", NULL, NULL);
- return (ctxt->err);
- }
-
- if (xmlSchemaCheckDerivationOKRestriction2to4(ctxt,
- XML_SCHEMA_ACTION_DERIVE,
- WXS_BASIC_CAST type, WXS_BASIC_CAST base,
- type->attrUses, base->attrUses,
- type->attributeWildcard,
- base->attributeWildcard) == -1)
- {
- return(-1);
- }
-
- if (base->builtInType == XML_SCHEMAS_ANYTYPE) {
-
- } else if ((type->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
- (type->contentType == XML_SCHEMA_CONTENT_BASIC)) {
-
- if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
- (base->contentType == XML_SCHEMA_CONTENT_BASIC))
- {
- int err;
-
- err = xmlSchemaCheckCOSSTDerivedOK(ACTXT_CAST ctxt,
- type->contentTypeDef, base->contentTypeDef, 0);
- if (err != 0) {
- xmlChar *strA = NULL, *strB = NULL;
- if (err == -1)
- return(-1);
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- NULL, WXS_BASIC_CAST type,
- "The {content type} %s is not validly derived from the "
- "base type's {content type} %s",
- xmlSchemaGetComponentDesignation(&strA,
- type->contentTypeDef),
- xmlSchemaGetComponentDesignation(&strB,
- base->contentTypeDef));
- FREE_AND_NULL(strA);
- FREE_AND_NULL(strB);
- return(ctxt->err);
- }
- } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) &&
- (xmlSchemaIsParticleEmptiable(
- (xmlSchemaParticlePtr) base->subtypes))) {
-
- } else {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- WXS_BASIC_CAST type, NULL,
- "The content type of the base type must be either "
- "a simple type or 'mixed' and an emptiable particle", NULL);
- return (ctxt->err);
- }
- } else if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
-
- if (base->contentType == XML_SCHEMA_CONTENT_EMPTY) {
-
- } else if (((base->contentType == XML_SCHEMA_CONTENT_ELEMENTS) ||
- (base->contentType == XML_SCHEMA_CONTENT_MIXED)) &&
- xmlSchemaIsParticleEmptiable(
- (xmlSchemaParticlePtr) base->subtypes)) {
-
- } else {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- WXS_BASIC_CAST type, NULL,
- "The content type of the base type must be either "
- "empty or 'mixed' (or 'elements-only') and an emptiable "
- "particle", NULL);
- return (ctxt->err);
- }
- } else if ((type->contentType == XML_SCHEMA_CONTENT_ELEMENTS) ||
- WXS_HAS_MIXED_CONTENT(type)) {
-
- if (WXS_HAS_MIXED_CONTENT(type) && (! WXS_HAS_MIXED_CONTENT(base))) {
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- WXS_BASIC_CAST type, NULL,
- "If the content type is 'mixed', then the content type of the "
- "base type must also be 'mixed'", NULL);
- return (ctxt->err);
- }
-
- } else {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_DERIVATION_OK_RESTRICTION_1,
- WXS_BASIC_CAST type, NULL,
- "The type is not a valid restriction of its base type", NULL);
- return (ctxt->err);
- }
- return (0);
- }
- static int
- xmlSchemaCheckCTComponent(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
- int ret;
-
- ret = xmlSchemaCheckCTPropsCorrect(ctxt, type);
- if (ret != 0)
- return (ret);
- if (WXS_IS_EXTENSION(type))
- ret = xmlSchemaCheckCOSCTExtends(ctxt, type);
- else
- ret = xmlSchemaCheckDerivationOKRestriction(ctxt, type);
- return (ret);
- }
- static int
- xmlSchemaCheckSRCCT(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypePtr base;
- int ret = 0;
-
- base = type->baseType;
- if (! WXS_HAS_SIMPLE_CONTENT(type)) {
-
- if (! WXS_IS_COMPLEX(base)) {
- xmlChar *str = NULL;
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_CT_1,
- WXS_BASIC_CAST type, type->node,
- "If using <complexContent>, the base type is expected to be "
- "a complex type. The base type '%s' is a simple type",
- xmlSchemaFormatQName(&str, base->targetNamespace,
- base->name));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_SRC_CT_1);
- }
- } else {
-
- if (WXS_IS_SIMPLE(base)) {
- if (WXS_IS_EXTENSION(type) == 0) {
- xmlChar *str = NULL;
-
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_CT_1,
- WXS_BASIC_CAST type, NULL,
- "If using <simpleContent> and <restriction>, the base "
- "type must be a complex type. The base type '%s' is "
- "a simple type",
- xmlSchemaFormatQName(&str, base->targetNamespace,
- base->name));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_SRC_CT_1);
- }
- } else {
-
- if ((base->contentType == XML_SCHEMA_CONTENT_SIMPLE) ||
- (base->contentType == XML_SCHEMA_CONTENT_BASIC)) {
-
- if (base->contentTypeDef == NULL) {
- xmlSchemaPCustomErr(ctxt, XML_SCHEMAP_INTERNAL,
- WXS_BASIC_CAST type, NULL,
- "Internal error: xmlSchemaCheckSRCCT, "
- "'%s', base type has no content type",
- type->name);
- return (-1);
- }
- } else if ((base->contentType == XML_SCHEMA_CONTENT_MIXED) &&
- (WXS_IS_RESTRICTION(type))) {
-
- if (! xmlSchemaIsParticleEmptiable(
- (xmlSchemaParticlePtr) base->subtypes)) {
- ret = XML_SCHEMAP_SRC_CT_1;
- } else
-
- if (type->contentTypeDef == NULL) {
- xmlChar *str = NULL;
-
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_CT_1,
- WXS_BASIC_CAST type, NULL,
- "A <simpleType> is expected among the children "
- "of <restriction>, if <simpleContent> is used and "
- "the base type '%s' is a complex type",
- xmlSchemaFormatQName(&str, base->targetNamespace,
- base->name));
- FREE_AND_NULL(str)
- return (XML_SCHEMAP_SRC_CT_1);
- }
- } else {
- ret = XML_SCHEMAP_SRC_CT_1;
- }
- }
- if (ret > 0) {
- xmlChar *str = NULL;
- if (WXS_IS_RESTRICTION(type)) {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_CT_1,
- WXS_BASIC_CAST type, NULL,
- "If <simpleContent> and <restriction> is used, the "
- "base type must be a simple type or a complex type with "
- "mixed content and particle emptiable. The base type "
- "'%s' is none of those",
- xmlSchemaFormatQName(&str, base->targetNamespace,
- base->name));
- } else {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_CT_1,
- WXS_BASIC_CAST type, NULL,
- "If <simpleContent> and <extension> is used, the "
- "base type must be a simple type. The base type '%s' "
- "is a complex type",
- xmlSchemaFormatQName(&str, base->targetNamespace,
- base->name));
- }
- FREE_AND_NULL(str)
- }
- }
-
-
- return (ret);
- }
- #ifdef ENABLE_PARTICLE_RESTRICTION
- static int
- xmlSchemaCheckParticleRangeOK(int rmin, int rmax,
- int bmin, int bmax)
- {
- if (rmin < bmin)
- return (1);
- if ((bmax != UNBOUNDED) &&
- (rmax > bmax))
- return (1);
- return (0);
- }
- static int
- xmlSchemaCheckRCaseNameAndTypeOK(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b)
- {
- xmlSchemaElementPtr elemR, elemB;
-
- elemR = (xmlSchemaElementPtr) r->children;
- elemB = (xmlSchemaElementPtr) b->children;
-
- if ((elemR != elemB) &&
- ((! xmlStrEqual(elemR->name, elemB->name)) ||
- (! xmlStrEqual(elemR->targetNamespace, elemB->targetNamespace))))
- return (1);
-
- if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
- b->minOccurs, b->maxOccurs) != 0)
- return (1);
-
- if (elemR == elemB)
- return (0);
-
- if (((elemB->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) &&
- (elemR->flags & XML_SCHEMAS_ELEM_NILLABLE))
- return (1);
-
- if ((elemB->value != NULL) && (elemB->flags & XML_SCHEMAS_ELEM_FIXED) &&
- ((elemR->value == NULL) ||
- ((elemR->flags & XML_SCHEMAS_ELEM_FIXED) == 0) ||
-
- (! xmlStrEqual(elemR->value, elemB->value))))
- return (1);
-
- if (elemB->idcs != NULL) {
-
- }
-
- if (((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) &&
- ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) == 0)) ||
- ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) &&
- ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) == 0)) ||
- ((elemB->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) &&
- ((elemR->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION) == 0)))
- return (1);
-
- {
- int set = 0;
- set |= SUBSET_EXTENSION;
- set |= SUBSET_LIST;
- set |= SUBSET_UNION;
- if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST ctxt, elemR->subtypes,
- elemB->subtypes, set) != 0)
- return (1);
- }
- return (0);
- }
- static int
- xmlSchemaCheckRCaseNSCompat(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b)
- {
-
-
- if (xmlSchemaCheckCVCWildcardNamespace((xmlSchemaWildcardPtr) b->children,
- ((xmlSchemaElementPtr) r->children)->targetNamespace) != 0)
- return (1);
-
- if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
- b->minOccurs, b->maxOccurs) != 0)
- return (1);
- return (0);
- }
- static int
- xmlSchemaCheckRCaseRecurseAsIfGroup(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b)
- {
-
- TODO
- return (0);
- }
- static int
- xmlSchemaCheckRCaseNSSubset(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b,
- int isAnyTypeBase)
- {
-
-
- if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
- b->minOccurs, b->maxOccurs))
- return (1);
-
- if (xmlSchemaCheckCOSNSSubset((xmlSchemaWildcardPtr) r->children,
- (xmlSchemaWildcardPtr) b->children))
- return (1);
-
- if (! isAnyTypeBase) {
- if ( ((xmlSchemaWildcardPtr) r->children)->processContents <
- ((xmlSchemaWildcardPtr) b->children)->processContents)
- return (1);
- }
- return (0);
- }
- static int
- xmlSchemaCheckCOSParticleRestrict(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b)
- {
- int ret = 0;
-
- TODO
-
- if (r == b)
- return (0);
- return (0);
- }
- #if 0
- static int
- xmlSchemaCheckRCaseNSRecurseCheckCardinality(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b)
- {
- xmlSchemaParticlePtr part;
-
- if ((r->children == NULL) || (r->children->children == NULL))
- return (-1);
-
- part = (xmlSchemaParticlePtr) r->children->children;
- do {
- if (xmlSchemaCheckCOSParticleRestrict(ctxt, part, b))
- return (1);
- part = (xmlSchemaParticlePtr) part->next;
- } while (part != NULL);
-
- if (xmlSchemaCheckParticleRangeOK(
- xmlSchemaGetParticleTotalRangeMin(r),
- xmlSchemaGetParticleTotalRangeMax(r),
- b->minOccurs, b->maxOccurs) != 0)
- return (1);
- return (0);
- }
- #endif
- static int
- xmlSchemaCheckRCaseRecurse(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaParticlePtr r,
- xmlSchemaParticlePtr b)
- {
-
-
- if ((r->children == NULL) || (b->children == NULL) ||
- (r->children->type != b->children->type))
- return (-1);
-
- if (xmlSchemaCheckParticleRangeOK(r->minOccurs, r->maxOccurs,
- b->minOccurs, b->maxOccurs))
- return (1);
- return (0);
- }
- #endif
- #define FACET_RESTR_MUTUAL_ERR(fac1, fac2) \
- xmlSchemaPCustomErrExt(pctxt, \
- XML_SCHEMAP_INVALID_FACET_VALUE, \
- WXS_BASIC_CAST fac1, fac1->node, \
- "It is an error for both '%s' and '%s' to be specified on the "\
- "same type definition", \
- BAD_CAST xmlSchemaFacetTypeToString(fac1->type), \
- BAD_CAST xmlSchemaFacetTypeToString(fac2->type), NULL);
- #define FACET_RESTR_ERR(fac1, msg) \
- xmlSchemaPCustomErr(pctxt, \
- XML_SCHEMAP_INVALID_FACET_VALUE, \
- WXS_BASIC_CAST fac1, fac1->node, \
- msg, NULL);
- #define FACET_RESTR_FIXED_ERR(fac) \
- xmlSchemaPCustomErr(pctxt, \
- XML_SCHEMAP_INVALID_FACET_VALUE, \
- WXS_BASIC_CAST fac, fac->node, \
- "The base type's facet is 'fixed', thus the value must not " \
- "differ", NULL);
- static void
- xmlSchemaDeriveFacetErr(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaFacetPtr facet1,
- xmlSchemaFacetPtr facet2,
- int lessGreater,
- int orEqual,
- int ofBase)
- {
- xmlChar *msg = NULL;
- msg = xmlStrdup(BAD_CAST "'");
- msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet1->type));
- msg = xmlStrcat(msg, BAD_CAST "' has to be");
- if (lessGreater == 0)
- msg = xmlStrcat(msg, BAD_CAST " equal to");
- if (lessGreater == 1)
- msg = xmlStrcat(msg, BAD_CAST " greater than");
- else
- msg = xmlStrcat(msg, BAD_CAST " less than");
- if (orEqual)
- msg = xmlStrcat(msg, BAD_CAST " or equal to");
- msg = xmlStrcat(msg, BAD_CAST " '");
- msg = xmlStrcat(msg, xmlSchemaFacetTypeToString(facet2->type));
- if (ofBase)
- msg = xmlStrcat(msg, BAD_CAST "' of the base type");
- else
- msg = xmlStrcat(msg, BAD_CAST "'");
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_INVALID_FACET_VALUE,
- WXS_BASIC_CAST facet1, NULL,
- (const char *) msg, NULL);
- if (msg != NULL)
- xmlFree(msg);
- }
- static int
- xmlSchemaDeriveAndValidateFacets(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypePtr base = type->baseType;
- xmlSchemaFacetLinkPtr link, cur, last = NULL;
- xmlSchemaFacetPtr facet, bfacet,
- flength = NULL, ftotdig = NULL, ffracdig = NULL,
- fmaxlen = NULL, fminlen = NULL,
- fmininc = NULL, fmaxinc = NULL,
- fminexc = NULL, fmaxexc = NULL,
- bflength = NULL, bftotdig = NULL, bffracdig = NULL,
- bfmaxlen = NULL, bfminlen = NULL,
- bfmininc = NULL, bfmaxinc = NULL,
- bfminexc = NULL, bfmaxexc = NULL;
- int res;
-
-
-
- if ((type->facetSet == NULL) && (base->facetSet == NULL))
- return (0);
- last = type->facetSet;
- if (last != NULL)
- while (last->next != NULL)
- last = last->next;
- for (cur = type->facetSet; cur != NULL; cur = cur->next) {
- facet = cur->facet;
- switch (facet->type) {
- case XML_SCHEMA_FACET_LENGTH:
- flength = facet; break;
- case XML_SCHEMA_FACET_MINLENGTH:
- fminlen = facet; break;
- case XML_SCHEMA_FACET_MININCLUSIVE:
- fmininc = facet; break;
- case XML_SCHEMA_FACET_MINEXCLUSIVE:
- fminexc = facet; break;
- case XML_SCHEMA_FACET_MAXLENGTH:
- fmaxlen = facet; break;
- case XML_SCHEMA_FACET_MAXINCLUSIVE:
- fmaxinc = facet; break;
- case XML_SCHEMA_FACET_MAXEXCLUSIVE:
- fmaxexc = facet; break;
- case XML_SCHEMA_FACET_TOTALDIGITS:
- ftotdig = facet; break;
- case XML_SCHEMA_FACET_FRACTIONDIGITS:
- ffracdig = facet; break;
- default:
- break;
- }
- }
- for (cur = base->facetSet; cur != NULL; cur = cur->next) {
- facet = cur->facet;
- switch (facet->type) {
- case XML_SCHEMA_FACET_LENGTH:
- bflength = facet; break;
- case XML_SCHEMA_FACET_MINLENGTH:
- bfminlen = facet; break;
- case XML_SCHEMA_FACET_MININCLUSIVE:
- bfmininc = facet; break;
- case XML_SCHEMA_FACET_MINEXCLUSIVE:
- bfminexc = facet; break;
- case XML_SCHEMA_FACET_MAXLENGTH:
- bfmaxlen = facet; break;
- case XML_SCHEMA_FACET_MAXINCLUSIVE:
- bfmaxinc = facet; break;
- case XML_SCHEMA_FACET_MAXEXCLUSIVE:
- bfmaxexc = facet; break;
- case XML_SCHEMA_FACET_TOTALDIGITS:
- bftotdig = facet; break;
- case XML_SCHEMA_FACET_FRACTIONDIGITS:
- bffracdig = facet; break;
- default:
- break;
- }
- }
-
- if (flength && (fminlen || fmaxlen)) {
- FACET_RESTR_ERR(flength, "It is an error for both 'length' and "
- "either of 'minLength' or 'maxLength' to be specified on "
- "the same type definition")
- }
-
- if ((fmaxinc) && (fmaxexc)) {
-
- FACET_RESTR_MUTUAL_ERR(fmaxinc, fmaxexc)
- }
- if ((fmininc) && (fminexc)) {
-
- FACET_RESTR_MUTUAL_ERR(fmininc, fminexc)
- }
- if (flength && bflength) {
-
- res = xmlSchemaCompareValues(flength->val, bflength->val);
- if (res == -2)
- goto internal_error;
- if (res != 0)
- xmlSchemaDeriveFacetErr(pctxt, flength, bflength, 0, 0, 1);
- if ((res != 0) && (bflength->fixed)) {
- FACET_RESTR_FIXED_ERR(flength)
- }
- }
- if (fminlen && bfminlen) {
-
- res = xmlSchemaCompareValues(fminlen->val, bfminlen->val);
- if (res == -2)
- goto internal_error;
- if (res == -1)
- xmlSchemaDeriveFacetErr(pctxt, fminlen, bfminlen, 1, 1, 1);
- if ((res != 0) && (bfminlen->fixed)) {
- FACET_RESTR_FIXED_ERR(fminlen)
- }
- }
- if (fmaxlen && bfmaxlen) {
-
- res = xmlSchemaCompareValues(fmaxlen->val, bfmaxlen->val);
- if (res == -2)
- goto internal_error;
- if (res == 1)
- xmlSchemaDeriveFacetErr(pctxt, fmaxlen, bfmaxlen, -1, 1, 1);
- if ((res != 0) && (bfmaxlen->fixed)) {
- FACET_RESTR_FIXED_ERR(fmaxlen)
- }
- }
-
- if (! flength)
- flength = bflength;
- if (flength) {
- if (! fminlen)
- fminlen = bfminlen;
- if (fminlen) {
-
- res = xmlSchemaCompareValues(flength->val, fminlen->val);
- if (res == -2)
- goto internal_error;
- if (res == -1)
- xmlSchemaDeriveFacetErr(pctxt, flength, fminlen, 1, 1, 0);
- }
- if (! fmaxlen)
- fmaxlen = bfmaxlen;
- if (fmaxlen) {
-
- res = xmlSchemaCompareValues(flength->val, fmaxlen->val);
- if (res == -2)
- goto internal_error;
- if (res == 1)
- xmlSchemaDeriveFacetErr(pctxt, flength, fmaxlen, -1, 1, 0);
- }
- }
- if (fmaxinc) {
-
- if (fmininc) {
-
- res = xmlSchemaCompareValues(fmaxinc->val, fmininc->val);
- if (res == -2)
- goto internal_error;
- if (res == -1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxinc, fmininc, 1, 1, 0);
- }
- }
-
- if (bfmaxinc) {
-
- res = xmlSchemaCompareValues(fmaxinc->val, bfmaxinc->val);
- if (res == -2)
- goto internal_error;
- if (res == 1)
- xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxinc, -1, 1, 1);
- if ((res != 0) && (bfmaxinc->fixed)) {
- FACET_RESTR_FIXED_ERR(fmaxinc)
- }
- }
- if (bfmaxexc) {
-
- res = xmlSchemaCompareValues(fmaxinc->val, bfmaxexc->val);
- if (res == -2)
- goto internal_error;
- if (res != -1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmaxexc, -1, 0, 1);
- }
- }
- if (bfmininc) {
-
- res = xmlSchemaCompareValues(fmaxinc->val, bfmininc->val);
- if (res == -2)
- goto internal_error;
- if (res == -1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfmininc, 1, 1, 1);
- }
- }
- if (bfminexc) {
-
- res = xmlSchemaCompareValues(fmaxinc->val, bfminexc->val);
- if (res == -2)
- goto internal_error;
- if (res != 1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxinc, bfminexc, 1, 0, 1);
- }
- }
- }
- if (fmaxexc) {
-
- if (fminexc) {
- res = xmlSchemaCompareValues(fmaxexc->val, fminexc->val);
- if (res == -2)
- goto internal_error;
- if (res == -1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxexc, fminexc, 1, 1, 0);
- }
- }
-
- if (bfmaxexc) {
-
- res = xmlSchemaCompareValues(fmaxexc->val, bfmaxexc->val);
- if (res == -2)
- goto internal_error;
- if (res == 1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxexc, -1, 1, 1);
- }
- if ((res != 0) && (bfmaxexc->fixed)) {
- FACET_RESTR_FIXED_ERR(fmaxexc)
- }
- }
- if (bfmaxinc) {
-
- res = xmlSchemaCompareValues(fmaxexc->val, bfmaxinc->val);
- if (res == -2)
- goto internal_error;
- if (res == 1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmaxinc, -1, 1, 1);
- }
- }
- if (bfmininc) {
-
- res = xmlSchemaCompareValues(fmaxexc->val, bfmininc->val);
- if (res == -2)
- goto internal_error;
- if (res != 1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfmininc, 1, 0, 1);
- }
- }
- if (bfminexc) {
-
- res = xmlSchemaCompareValues(fmaxexc->val, bfminexc->val);
- if (res == -2)
- goto internal_error;
- if (res != 1) {
- xmlSchemaDeriveFacetErr(pctxt, fmaxexc, bfminexc, 1, 0, 1);
- }
- }
- }
- if (fminexc) {
-
- if (fmaxinc) {
- res = xmlSchemaCompareValues(fminexc->val, fmaxinc->val);
- if (res == -2)
- goto internal_error;
- if (res != -1) {
- xmlSchemaDeriveFacetErr(pctxt, fminexc, fmaxinc, -1, 0, 0);
- }
- }
-
- if (bfminexc) {
-
- res = xmlSchemaCompareValues(fminexc->val, bfminexc->val);
- if (res == -2)
- goto internal_error;
- if (res == -1) {
- xmlSchemaDeriveFacetErr(pctxt, fminexc, bfminexc, 1, 1, 1);
- }
- if ((res != 0) && (bfminexc->fixed)) {
- FACET_RESTR_FIXED_ERR(fminexc)
- }
- }
- if (bfmaxinc) {
-
- res = xmlSchemaCompareValues(fminexc->val, bfmaxinc->val);
- if (res == -2)
- goto internal_error;
- if (res == 1) {
- xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxinc, -1, 1, 1);
- }
- }
- if (bfmininc) {
-
- res = xmlSchemaCompareValues(fminexc->val, bfmininc->val);
- if (res == -2)
- goto internal_error;
- if (res == -1) {
- xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmininc, 1, 1, 1);
- }
- }
- if (bfmaxexc) {
-
- res = xmlSchemaCompareValues(fminexc->val, bfmaxexc->val);
- if (res == -2)
- goto internal_error;
- if (res != -1) {
- xmlSchemaDeriveFacetErr(pctxt, fminexc, bfmaxexc, -1, 0, 1);
- }
- }
- }
- if (fmininc) {
-
- if (fmaxexc) {
- res = xmlSchemaCompareValues(fmininc->val, fmaxexc->val);
- if (res == -2)
- goto internal_error;
- if (res != -1) {
- xmlSchemaDeriveFacetErr(pctxt, fmininc, fmaxexc, -1, 0, 0);
- }
- }
-
- if (bfmininc) {
-
- res = xmlSchemaCompareValues(fmininc->val, bfmininc->val);
- if (res == -2)
- goto internal_error;
- if (res == -1) {
- xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmininc, 1, 1, 1);
- }
- if ((res != 0) && (bfmininc->fixed)) {
- FACET_RESTR_FIXED_ERR(fmininc)
- }
- }
- if (bfmaxinc) {
-
- res = xmlSchemaCompareValues(fmininc->val, bfmaxinc->val);
- if (res == -2)
- goto internal_error;
- if (res == 1) {
- xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxinc, -1, 1, 1);
- }
- }
- if (bfminexc) {
-
- res = xmlSchemaCompareValues(fmininc->val, bfminexc->val);
- if (res == -2)
- goto internal_error;
- if (res != 1)
- xmlSchemaDeriveFacetErr(pctxt, fmininc, bfminexc, 1, 0, 1);
- }
- if (bfmaxexc) {
-
- res = xmlSchemaCompareValues(fmininc->val, bfmaxexc->val);
- if (res == -2)
- goto internal_error;
- if (res != -1)
- xmlSchemaDeriveFacetErr(pctxt, fmininc, bfmaxexc, -1, 0, 1);
- }
- }
- if (ftotdig && bftotdig) {
-
- res = xmlSchemaCompareValues(ftotdig->val, bftotdig->val);
- if (res == -2)
- goto internal_error;
- if (res == 1)
- xmlSchemaDeriveFacetErr(pctxt, ftotdig, bftotdig,
- -1, 1, 1);
- if ((res != 0) && (bftotdig->fixed)) {
- FACET_RESTR_FIXED_ERR(ftotdig)
- }
- }
- if (ffracdig && bffracdig) {
-
- res = xmlSchemaCompareValues(ffracdig->val, bffracdig->val);
- if (res == -2)
- goto internal_error;
- if (res == 1)
- xmlSchemaDeriveFacetErr(pctxt, ffracdig, bffracdig,
- -1, 1, 1);
- if ((res != 0) && (bffracdig->fixed)) {
- FACET_RESTR_FIXED_ERR(ffracdig)
- }
- }
-
- if (! ftotdig)
- ftotdig = bftotdig;
- if (! ffracdig)
- ffracdig = bffracdig;
- if (ftotdig && ffracdig) {
- res = xmlSchemaCompareValues(ffracdig->val, ftotdig->val);
- if (res == -2)
- goto internal_error;
- if (res == 1)
- xmlSchemaDeriveFacetErr(pctxt, ffracdig, ftotdig,
- -1, 1, 0);
- }
-
- for (cur = base->facetSet; cur != NULL; cur = cur->next) {
- bfacet = cur->facet;
-
- if ((bfacet->type == XML_SCHEMA_FACET_PATTERN) ||
- (bfacet->type == XML_SCHEMA_FACET_ENUMERATION))
- continue;
-
- link = type->facetSet;
-
-
- while (link != NULL) {
- facet = link->facet;
- if (facet->type == bfacet->type) {
- switch (facet->type) {
- case XML_SCHEMA_FACET_WHITESPACE:
-
- if (facet->whitespace < bfacet->whitespace) {
- FACET_RESTR_ERR(facet,
- "The 'whitespace' value has to be equal to "
- "or stronger than the 'whitespace' value of "
- "the base type")
- }
- if ((bfacet->fixed) &&
- (facet->whitespace != bfacet->whitespace)) {
- FACET_RESTR_FIXED_ERR(facet)
- }
- break;
- default:
- break;
- }
-
- break;
- }
- link = link->next;
- }
-
- if (link == NULL) {
- link = (xmlSchemaFacetLinkPtr)
- xmlMalloc(sizeof(xmlSchemaFacetLink));
- if (link == NULL) {
- xmlSchemaPErrMemory(pctxt,
- "deriving facets, creating a facet link", NULL);
- return (-1);
- }
- link->facet = cur->facet;
- link->next = NULL;
- if (last == NULL)
- type->facetSet = link;
- else
- last->next = link;
- last = link;
- }
- }
- return (0);
- internal_error:
- PERROR_INT("xmlSchemaDeriveAndValidateFacets",
- "an error occured");
- return (-1);
- }
- static int
- xmlSchemaFinishMemberTypeDefinitionsProperty(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- xmlSchemaTypeLinkPtr link, lastLink, prevLink, subLink, newLink;
-
- link = type->memberTypes;
- while (link != NULL) {
- if (WXS_IS_TYPE_NOT_FIXED(link->type))
- xmlSchemaTypeFixup(link->type, ACTXT_CAST pctxt);
- if (WXS_IS_UNION(link->type)) {
- subLink = xmlSchemaGetUnionSimpleTypeMemberTypes(link->type);
- if (subLink != NULL) {
- link->type = subLink->type;
- if (subLink->next != NULL) {
- lastLink = link->next;
- subLink = subLink->next;
- prevLink = link;
- while (subLink != NULL) {
- newLink = (xmlSchemaTypeLinkPtr)
- xmlMalloc(sizeof(xmlSchemaTypeLink));
- if (newLink == NULL) {
- xmlSchemaPErrMemory(pctxt, "allocating a type link",
- NULL);
- return (-1);
- }
- newLink->type = subLink->type;
- prevLink->next = newLink;
- prevLink = newLink;
- newLink->next = lastLink;
- subLink = subLink->next;
- }
- }
- }
- }
- link = link->next;
- }
- return (0);
- }
- static void
- xmlSchemaTypeFixupOptimFacets(xmlSchemaTypePtr type)
- {
- int has = 0, needVal = 0, normVal = 0;
- has = (type->baseType->flags & XML_SCHEMAS_TYPE_HAS_FACETS) ? 1 : 0;
- if (has) {
- needVal = (type->baseType->flags &
- XML_SCHEMAS_TYPE_FACETSNEEDVALUE) ? 1 : 0;
- normVal = (type->baseType->flags &
- XML_SCHEMAS_TYPE_NORMVALUENEEDED) ? 1 : 0;
- }
- if (type->facets != NULL) {
- xmlSchemaFacetPtr fac;
- for (fac = type->facets; fac != NULL; fac = fac->next) {
- switch (fac->type) {
- case XML_SCHEMA_FACET_WHITESPACE:
- break;
- case XML_SCHEMA_FACET_PATTERN:
- normVal = 1;
- has = 1;
- break;
- case XML_SCHEMA_FACET_ENUMERATION:
- needVal = 1;
- normVal = 1;
- has = 1;
- break;
- default:
- has = 1;
- break;
- }
- }
- }
- if (normVal)
- type->flags |= XML_SCHEMAS_TYPE_NORMVALUENEEDED;
- if (needVal)
- type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE;
- if (has)
- type->flags |= XML_SCHEMAS_TYPE_HAS_FACETS;
- if (has && (! needVal) && WXS_IS_ATOMIC(type)) {
- xmlSchemaTypePtr prim = xmlSchemaGetPrimitiveType(type);
-
- if ((prim->builtInType != XML_SCHEMAS_ANYSIMPLETYPE) &&
- (prim->builtInType != XML_SCHEMAS_STRING)) {
- type->flags |= XML_SCHEMAS_TYPE_FACETSNEEDVALUE;
- }
- }
- }
- static int
- xmlSchemaTypeFixupWhitespace(xmlSchemaTypePtr type)
- {
-
- if (WXS_IS_LIST(type)) {
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
- return (0);
- } else if (WXS_IS_UNION(type))
- return (0);
- if (type->facetSet != NULL) {
- xmlSchemaFacetLinkPtr lin;
- for (lin = type->facetSet; lin != NULL; lin = lin->next) {
- if (lin->facet->type == XML_SCHEMA_FACET_WHITESPACE) {
- switch (lin->facet->whitespace) {
- case XML_SCHEMAS_FACET_PRESERVE:
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE;
- break;
- case XML_SCHEMAS_FACET_REPLACE:
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE;
- break;
- case XML_SCHEMAS_FACET_COLLAPSE:
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
- break;
- default:
- return (-1);
- }
- return (0);
- }
- }
- }
-
- {
- xmlSchemaTypePtr anc;
- for (anc = type->baseType; anc != NULL &&
- anc->builtInType != XML_SCHEMAS_ANYTYPE;
- anc = anc->baseType) {
- if (anc->type == XML_SCHEMA_TYPE_BASIC) {
- if (anc->builtInType == XML_SCHEMAS_NORMSTRING) {
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_REPLACE;
- } else if ((anc->builtInType == XML_SCHEMAS_STRING) ||
- (anc->builtInType == XML_SCHEMAS_ANYSIMPLETYPE)) {
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE;
- } else
- type->flags |= XML_SCHEMAS_TYPE_WHITESPACE_COLLAPSE;
- break;
- }
- }
- }
- return (0);
- }
- static int
- xmlSchemaFixupSimpleTypeStageOne(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- if (type->type != XML_SCHEMA_TYPE_SIMPLE)
- return(0);
- if (! WXS_IS_TYPE_NOT_FIXED_1(type))
- return(0);
- type->flags |= XML_SCHEMAS_TYPE_FIXUP_1;
- if (WXS_IS_LIST(type)) {
-
- if (type->subtypes == NULL) {
-
- PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
- "list type has no item-type assigned");
- return(-1);
- }
- } else if (WXS_IS_UNION(type)) {
-
- if (type->memberTypes == NULL) {
-
- PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
- "union type has no member-types assigned");
- return(-1);
- }
- } else {
-
- if (type->baseType == NULL) {
- PERROR_INT("xmlSchemaFixupSimpleTypeStageOne",
- "type has no base-type assigned");
- return(-1);
- }
- if (WXS_IS_TYPE_NOT_FIXED_1(type->baseType))
- if (xmlSchemaFixupSimpleTypeStageOne(pctxt, type->baseType) == -1)
- return(-1);
-
- if (WXS_IS_ATOMIC(type->baseType))
- type->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC;
- else if (WXS_IS_LIST(type->baseType)) {
- type->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST;
-
- type->subtypes = type->baseType->subtypes;
- } else if (WXS_IS_UNION(type->baseType)) {
- type->flags |= XML_SCHEMAS_TYPE_VARIETY_UNION;
-
- }
- }
- return(0);
- }
- #ifdef DEBUG_TYPE
- static void
- xmlSchemaDebugFixedType(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- if (type->node != NULL) {
- xmlGenericError(xmlGenericErrorContext,
- "Type of %s : %s:%d :", name,
- type->node->doc->URL,
- xmlGetLineNo(type->node));
- } else {
- xmlGenericError(xmlGenericErrorContext, "Type of %s :", name);
- }
- if ((WXS_IS_SIMPLE(type)) || (WXS_IS_COMPLEX(type))) {
- switch (type->contentType) {
- case XML_SCHEMA_CONTENT_SIMPLE:
- xmlGenericError(xmlGenericErrorContext, "simple\n");
- break;
- case XML_SCHEMA_CONTENT_ELEMENTS:
- xmlGenericError(xmlGenericErrorContext, "elements\n");
- break;
- case XML_SCHEMA_CONTENT_UNKNOWN:
- xmlGenericError(xmlGenericErrorContext, "unknown !!!\n");
- break;
- case XML_SCHEMA_CONTENT_EMPTY:
- xmlGenericError(xmlGenericErrorContext, "empty\n");
- break;
- case XML_SCHEMA_CONTENT_MIXED:
- if (xmlSchemaIsParticleEmptiable((xmlSchemaParticlePtr)
- type->subtypes))
- xmlGenericError(xmlGenericErrorContext,
- "mixed as emptiable particle\n");
- else
- xmlGenericError(xmlGenericErrorContext, "mixed\n");
- break;
-
-
- case XML_SCHEMA_CONTENT_BASIC:
- xmlGenericError(xmlGenericErrorContext, "basic\n");
- break;
- default:
- xmlGenericError(xmlGenericErrorContext,
- "not registered !!!\n");
- break;
- }
- }
- }
- #endif
- static int
- xmlSchemaFixupSimpleTypeStageTwo(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- int res, olderrs = pctxt->nberrors;
- if (type->type != XML_SCHEMA_TYPE_SIMPLE)
- return(-1);
- if (! WXS_IS_TYPE_NOT_FIXED(type))
- return(0);
- type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED;
- type->contentType = XML_SCHEMA_CONTENT_SIMPLE;
- if (type->baseType == NULL) {
- PERROR_INT("xmlSchemaFixupSimpleTypeStageTwo",
- "missing baseType");
- goto exit_failure;
- }
- if (WXS_IS_TYPE_NOT_FIXED(type->baseType))
- xmlSchemaTypeFixup(type->baseType, ACTXT_CAST pctxt);
-
- if ((type->memberTypes != NULL) &&
- (xmlSchemaFinishMemberTypeDefinitionsProperty(pctxt, type) == -1))
- return(-1);
-
-
- res = xmlSchemaCheckSTPropsCorrect(pctxt, type);
- HFAILURE HERROR
-
- res = xmlSchemaCheckCOSSTRestricts(pctxt, type);
- HFAILURE HERROR
-
-
- res = xmlSchemaCheckFacetValues(type, pctxt);
- HFAILURE HERROR
- if ((type->facetSet != NULL) ||
- (type->baseType->facetSet != NULL)) {
- res = xmlSchemaDeriveAndValidateFacets(pctxt, type);
- HFAILURE HERROR
- }
-
- res = xmlSchemaTypeFixupWhitespace(type);
- HFAILURE HERROR
- xmlSchemaTypeFixupOptimFacets(type);
- exit_error:
- #ifdef DEBUG_TYPE
- xmlSchemaDebugFixedType(pctxt, type);
- #endif
- if (olderrs != pctxt->nberrors)
- return(pctxt->err);
- return(0);
- exit_failure:
- #ifdef DEBUG_TYPE
- xmlSchemaDebugFixedType(pctxt, type);
- #endif
- return(-1);
- }
- static int
- xmlSchemaFixupComplexType(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaTypePtr type)
- {
- int res = 0, olderrs = pctxt->nberrors;
- xmlSchemaTypePtr baseType = type->baseType;
- if (! WXS_IS_TYPE_NOT_FIXED(type))
- return(0);
- type->flags |= XML_SCHEMAS_TYPE_INTERNAL_RESOLVED;
- if (baseType == NULL) {
- PERROR_INT("xmlSchemaFixupComplexType",
- "missing baseType");
- goto exit_failure;
- }
-
- if (WXS_IS_TYPE_NOT_FIXED(baseType))
- xmlSchemaTypeFixup(baseType, ACTXT_CAST pctxt);
- if (baseType->flags & XML_SCHEMAS_TYPE_INTERNAL_INVALID) {
-
- return(0);
- }
-
- res = xmlSchemaCheckSRCCT(pctxt, type);
- HFAILURE HERROR
-
- if (type->contentType == XML_SCHEMA_CONTENT_SIMPLE) {
-
- if ((WXS_IS_COMPLEX(baseType)) &&
- (baseType->contentTypeDef != NULL) &&
- (WXS_IS_RESTRICTION(type))) {
- xmlSchemaTypePtr contentBase, content;
- #ifdef ENABLE_NAMED_LOCALS
- char buf[30];
- const xmlChar *tmpname;
- #endif
-
- if (type->contentTypeDef != NULL) {
-
- contentBase = type->contentTypeDef;
- type->contentTypeDef = NULL;
- } else {
-
- contentBase = baseType->contentTypeDef;
- }
-
- #ifdef ENABLE_NAMED_LOCALS
- snprintf(buf, 29, "#scST%d", ++(pctxt->counter));
- tmpname = xmlDictLookup(pctxt->dict, BAD_CAST buf, -1);
- content = xmlSchemaAddType(pctxt, pctxt->schema,
- XML_SCHEMA_TYPE_SIMPLE, tmpname, type->targetNamespace,
- type->node, 0);
- #else
- content = xmlSchemaAddType(pctxt, pctxt->schema,
- XML_SCHEMA_TYPE_SIMPLE, NULL, type->targetNamespace,
- type->node, 0);
- #endif
- if (content == NULL)
- goto exit_failure;
-
- content->type = XML_SCHEMA_TYPE_SIMPLE;
- content->baseType = contentBase;
-
- content->facets = type->facets;
- type->facets = NULL;
- content->facetSet = type->facetSet;
- type->facetSet = NULL;
- type->contentTypeDef = content;
- if (WXS_IS_TYPE_NOT_FIXED(contentBase))
- xmlSchemaTypeFixup(contentBase, ACTXT_CAST pctxt);
-
- res = xmlSchemaFixupSimpleTypeStageOne(pctxt, content);
- HFAILURE HERROR
- res = xmlSchemaFixupSimpleTypeStageTwo(pctxt, content);
- HFAILURE HERROR
- } else if ((WXS_IS_COMPLEX(baseType)) &&
- (baseType->contentType == XML_SCHEMA_CONTENT_MIXED) &&
- (WXS_IS_RESTRICTION(type))) {
-
- if ((type->contentTypeDef == NULL) ||
- (type->contentTypeDef->baseType == NULL)) {
-
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_INTERNAL,
- WXS_BASIC_CAST type, NULL,
- "Internal error: xmlSchemaTypeFixup, "
- "complex type '%s': the <simpleContent><restriction> "
- "is missing a <simpleType> child, but was not catched "
- "by xmlSchemaCheckSRCCT()", type->name);
- goto exit_failure;
- }
- } else if ((WXS_IS_COMPLEX(baseType)) && WXS_IS_EXTENSION(type)) {
-
- if (baseType->contentTypeDef == NULL) {
-
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_INTERNAL,
- WXS_BASIC_CAST type, NULL,
- "Internal error: xmlSchemaTypeFixup, "
- "complex type '%s': the <extension>ed base type is "
- "a complex type with no simple content type",
- type->name);
- goto exit_failure;
- }
- type->contentTypeDef = baseType->contentTypeDef;
- } else if ((WXS_IS_SIMPLE(baseType)) && WXS_IS_EXTENSION(type)) {
-
- type->contentTypeDef = baseType;
- } else {
-
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_INTERNAL,
- WXS_BASIC_CAST type, NULL,
- "Internal error: xmlSchemaTypeFixup, "
- "complex type '%s' with <simpleContent>: unhandled "
- "derivation case", type->name);
- goto exit_failure;
- }
- } else {
- int dummySequence = 0;
- xmlSchemaParticlePtr particle =
- (xmlSchemaParticlePtr) type->subtypes;
-
- if ((particle == NULL) ||
- ((particle->type == XML_SCHEMA_TYPE_PARTICLE) &&
- ((particle->children->type == XML_SCHEMA_TYPE_ALL) ||
- (particle->children->type == XML_SCHEMA_TYPE_SEQUENCE) ||
- ((particle->children->type == XML_SCHEMA_TYPE_CHOICE) &&
- (particle->minOccurs == 0))) &&
- ( ((xmlSchemaTreeItemPtr) particle->children)->children == NULL))) {
- if (type->flags & XML_SCHEMAS_TYPE_MIXED) {
-
- if ((particle == NULL) ||
- (particle->children->type != XML_SCHEMA_TYPE_SEQUENCE)) {
-
- particle = xmlSchemaAddParticle(pctxt,
- type->node, 1, 1);
- if (particle == NULL)
- goto exit_failure;
-
-
- particle->children = (xmlSchemaTreeItemPtr)
- xmlSchemaAddModelGroup(pctxt, pctxt->schema,
- XML_SCHEMA_TYPE_SEQUENCE, type->node);
- if (particle->children == NULL)
- goto exit_failure;
- type->subtypes = (xmlSchemaTypePtr) particle;
- }
- dummySequence = 1;
- type->contentType = XML_SCHEMA_CONTENT_ELEMENTS;
- } else {
-
- type->contentType = XML_SCHEMA_CONTENT_EMPTY;
- }
- } else {
-
- type->contentType = XML_SCHEMA_CONTENT_ELEMENTS;
- }
-
- if (WXS_IS_RESTRICTION(type)) {
-
- if (type->contentType != XML_SCHEMA_CONTENT_EMPTY) {
- if (type->flags & XML_SCHEMAS_TYPE_MIXED)
- type->contentType = XML_SCHEMA_CONTENT_MIXED;
- }
- } else {
-
- if (type->contentType == XML_SCHEMA_CONTENT_EMPTY) {
-
- type->contentType = baseType->contentType;
- type->subtypes = baseType->subtypes;
-
- type->contentTypeDef = baseType->contentTypeDef;
-
- } else if (baseType->contentType == XML_SCHEMA_CONTENT_EMPTY) {
-
- if (type->flags & XML_SCHEMAS_TYPE_MIXED)
- type->contentType = XML_SCHEMA_CONTENT_MIXED;
- } else {
-
- if (type->flags & XML_SCHEMAS_TYPE_MIXED)
- type->contentType = XML_SCHEMA_CONTENT_MIXED;
-
- if ((WXS_TYPE_PARTICLE(type) != NULL) &&
- (WXS_TYPE_PARTICLE_TERM(type) != NULL) &&
- ((WXS_TYPE_PARTICLE_TERM(type))->type ==
- XML_SCHEMA_TYPE_ALL))
- {
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
-
- XML_SCHEMAP_COS_ALL_LIMITED,
- WXS_ITEM_NODE(type), NULL,
- "The type has an 'all' model group in its "
- "{content type} and thus cannot be derived from "
- "a non-empty type, since this would produce a "
- "'sequence' model group containing the 'all' "
- "model group; 'all' model groups are not "
- "allowed to appear inside other model groups",
- NULL, NULL);
- } else if ((WXS_TYPE_PARTICLE(baseType) != NULL) &&
- (WXS_TYPE_PARTICLE_TERM(baseType) != NULL) &&
- ((WXS_TYPE_PARTICLE_TERM(baseType))->type ==
- XML_SCHEMA_TYPE_ALL))
- {
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
-
- XML_SCHEMAP_COS_ALL_LIMITED,
- WXS_ITEM_NODE(type), NULL,
- "A type cannot be derived by extension from a type "
- "which has an 'all' model group in its "
- "{content type}, since this would produce a "
- "'sequence' model group containing the 'all' "
- "model group; 'all' model groups are not "
- "allowed to appear inside other model groups",
- NULL, NULL);
- } else if (! dummySequence) {
- xmlSchemaTreeItemPtr effectiveContent =
- (xmlSchemaTreeItemPtr) type->subtypes;
-
- particle = xmlSchemaAddParticle(pctxt,
- type->node, 1, 1);
- if (particle == NULL)
- goto exit_failure;
-
- particle->children = (xmlSchemaTreeItemPtr)
- xmlSchemaAddModelGroup(pctxt, pctxt->schema,
- XML_SCHEMA_TYPE_SEQUENCE, type->node);
- if (particle->children == NULL)
- goto exit_failure;
- WXS_TYPE_CONTENTTYPE(type) = (xmlSchemaTypePtr) particle;
-
- particle->children->children =
- (xmlSchemaTreeItemPtr) xmlSchemaAddParticle(pctxt,
- type->node,
- ((xmlSchemaParticlePtr) type->subtypes)->minOccurs,
- ((xmlSchemaParticlePtr) type->subtypes)->maxOccurs);
- if (particle->children->children == NULL)
- goto exit_failure;
- particle = (xmlSchemaParticlePtr)
- particle->children->children;
- particle->children =
- ((xmlSchemaParticlePtr) baseType->subtypes)->children;
-
- particle->next = effectiveContent;
-
- } else {
-
- particle->children->children =
- (xmlSchemaTreeItemPtr) baseType->subtypes;
- }
- }
- }
- }
-
- res = xmlSchemaFixupTypeAttributeUses(pctxt, type);
- HFAILURE HERROR
-
- res = xmlSchemaCheckCTComponent(pctxt, type);
- HFAILURE HERROR
- #ifdef DEBUG_TYPE
- xmlSchemaDebugFixedType(pctxt, type);
- #endif
- if (olderrs != pctxt->nberrors)
- return(pctxt->err);
- else
- return(0);
- exit_error:
- type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID;
- #ifdef DEBUG_TYPE
- xmlSchemaDebugFixedType(pctxt, type);
- #endif
- return(pctxt->err);
- exit_failure:
- type->flags |= XML_SCHEMAS_TYPE_INTERNAL_INVALID;
- #ifdef DEBUG_TYPE
- xmlSchemaDebugFixedType(pctxt, type);
- #endif
- return(-1);
- }
- static int
- xmlSchemaTypeFixup(xmlSchemaTypePtr type,
- xmlSchemaAbstractCtxtPtr actxt)
- {
- if (type == NULL)
- return(0);
- if (actxt->type != XML_SCHEMA_CTXT_PARSER) {
- AERROR_INT("xmlSchemaTypeFixup",
- "this function needs a parser context");
- return(-1);
- }
- if (! WXS_IS_TYPE_NOT_FIXED(type))
- return(0);
- if (type->type == XML_SCHEMA_TYPE_COMPLEX)
- return(xmlSchemaFixupComplexType(PCTXT_CAST actxt, type));
- else if (type->type == XML_SCHEMA_TYPE_SIMPLE)
- return(xmlSchemaFixupSimpleTypeStageTwo(PCTXT_CAST actxt, type));
- return(0);
- }
- int
- xmlSchemaCheckFacet(xmlSchemaFacetPtr facet,
- xmlSchemaTypePtr typeDecl,
- xmlSchemaParserCtxtPtr pctxt,
- const xmlChar * name ATTRIBUTE_UNUSED)
- {
- int ret = 0, ctxtGiven;
- if ((facet == NULL) || (typeDecl == NULL))
- return(-1);
-
- if (pctxt == NULL)
- ctxtGiven = 0;
- else
- ctxtGiven = 1;
- switch (facet->type) {
- case XML_SCHEMA_FACET_MININCLUSIVE:
- case XML_SCHEMA_FACET_MINEXCLUSIVE:
- case XML_SCHEMA_FACET_MAXINCLUSIVE:
- case XML_SCHEMA_FACET_MAXEXCLUSIVE:
- case XML_SCHEMA_FACET_ENUMERATION: {
-
- xmlSchemaTypePtr base;
-
-
- if (typeDecl->type != XML_SCHEMA_TYPE_BASIC) {
- base = typeDecl->baseType;
- if (base == NULL) {
- PERROR_INT("xmlSchemaCheckFacet",
- "a type user derived type has no base type");
- return (-1);
- }
- } else
- base = typeDecl;
- if (! ctxtGiven) {
-
- pctxt = xmlSchemaNewParserCtxt("*");
- if (pctxt == NULL)
- return (-1);
- }
-
- ret = xmlSchemaVCheckCVCSimpleType(
- ACTXT_CAST pctxt, facet->node, base,
- facet->value, &(facet->val), 1, 1, 0);
- if (ret != 0) {
- if (ret < 0) {
-
- if (ctxtGiven) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_INTERNAL, facet->node, NULL,
- "Internal error: xmlSchemaCheckFacet, "
- "failed to validate the value '%s' of the "
- "facet '%s' against the base type",
- facet->value, xmlSchemaFacetTypeToString(facet->type));
- }
- goto internal_error;
- }
- ret = XML_SCHEMAP_INVALID_FACET_VALUE;
-
- if (ctxtGiven) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- ret, facet->node, WXS_BASIC_CAST facet,
- "The value '%s' of the facet does not validate "
- "against the base type '%s'",
- facet->value,
- xmlSchemaFormatQName(&str,
- base->targetNamespace, base->name));
- FREE_AND_NULL(str);
- }
- goto exit;
- } else if (facet->val == NULL) {
- if (ctxtGiven) {
- PERROR_INT("xmlSchemaCheckFacet",
- "value was not computed");
- }
- TODO
- }
- break;
- }
- case XML_SCHEMA_FACET_PATTERN:
- facet->regexp = xmlRegexpCompile(facet->value);
- if (facet->regexp == NULL) {
- ret = XML_SCHEMAP_REGEXP_INVALID;
-
- if (ctxtGiven) {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- ret, facet->node, WXS_BASIC_CAST typeDecl,
- "The value '%s' of the facet 'pattern' is not a "
- "valid regular expression",
- facet->value, NULL);
- }
- }
- break;
- case XML_SCHEMA_FACET_TOTALDIGITS:
- case XML_SCHEMA_FACET_FRACTIONDIGITS:
- case XML_SCHEMA_FACET_LENGTH:
- case XML_SCHEMA_FACET_MAXLENGTH:
- case XML_SCHEMA_FACET_MINLENGTH:
- if (facet->type == XML_SCHEMA_FACET_TOTALDIGITS) {
- ret = xmlSchemaValidatePredefinedType(
- xmlSchemaGetBuiltInType(XML_SCHEMAS_PINTEGER),
- facet->value, &(facet->val));
- } else {
- ret = xmlSchemaValidatePredefinedType(
- xmlSchemaGetBuiltInType(XML_SCHEMAS_NNINTEGER),
- facet->value, &(facet->val));
- }
- if (ret != 0) {
- if (ret < 0) {
-
- if (ctxtGiven) {
- PERROR_INT("xmlSchemaCheckFacet",
- "validating facet value");
- }
- goto internal_error;
- }
- ret = XML_SCHEMAP_INVALID_FACET_VALUE;
-
- if (ctxtGiven) {
-
- xmlSchemaCustomErr4(ACTXT_CAST pctxt,
- ret, facet->node, WXS_BASIC_CAST typeDecl,
- "The value '%s' of the facet '%s' is not a valid '%s'",
- facet->value,
- xmlSchemaFacetTypeToString(facet->type),
- (facet->type != XML_SCHEMA_FACET_TOTALDIGITS) ?
- BAD_CAST "nonNegativeInteger" :
- BAD_CAST "positiveInteger",
- NULL);
- }
- }
- break;
- case XML_SCHEMA_FACET_WHITESPACE:{
- if (xmlStrEqual(facet->value, BAD_CAST "preserve")) {
- facet->whitespace = XML_SCHEMAS_FACET_PRESERVE;
- } else if (xmlStrEqual(facet->value, BAD_CAST "replace")) {
- facet->whitespace = XML_SCHEMAS_FACET_REPLACE;
- } else if (xmlStrEqual(facet->value, BAD_CAST "collapse")) {
- facet->whitespace = XML_SCHEMAS_FACET_COLLAPSE;
- } else {
- ret = XML_SCHEMAP_INVALID_FACET_VALUE;
-
- if (ctxtGiven) {
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- ret, facet->node, WXS_BASIC_CAST typeDecl,
- "The value '%s' of the facet 'whitespace' is not "
- "valid", facet->value, NULL);
- }
- }
- }
- default:
- break;
- }
- exit:
- if ((! ctxtGiven) && (pctxt != NULL))
- xmlSchemaFreeParserCtxt(pctxt);
- return (ret);
- internal_error:
- if ((! ctxtGiven) && (pctxt != NULL))
- xmlSchemaFreeParserCtxt(pctxt);
- return (-1);
- }
- static int
- xmlSchemaCheckFacetValues(xmlSchemaTypePtr typeDecl,
- xmlSchemaParserCtxtPtr pctxt)
- {
- int res, olderrs = pctxt->nberrors;
- const xmlChar *name = typeDecl->name;
-
- if (typeDecl->facets != NULL) {
- xmlSchemaFacetPtr facet = typeDecl->facets;
-
- if (pctxt->vctxt == NULL) {
- if (xmlSchemaCreateVCtxtOnPCtxt(pctxt) == -1)
- return(-1);
- }
- pctxt->vctxt->schema = pctxt->schema;
- while (facet != NULL) {
- res = xmlSchemaCheckFacet(facet, typeDecl, pctxt, name);
- HFAILURE
- facet = facet->next;
- }
- pctxt->vctxt->schema = NULL;
- }
- if (olderrs != pctxt->nberrors)
- return(pctxt->err);
- return(0);
- exit_failure:
- return(-1);
- }
- static xmlSchemaTreeItemPtr
- xmlSchemaGetCircModelGrDefRef(xmlSchemaModelGroupDefPtr groupDef,
- xmlSchemaTreeItemPtr particle)
- {
- xmlSchemaTreeItemPtr circ = NULL;
- xmlSchemaTreeItemPtr term;
- xmlSchemaModelGroupDefPtr gdef;
- for (; particle != NULL; particle = particle->next) {
- term = particle->children;
- if (term == NULL)
- continue;
- switch (term->type) {
- case XML_SCHEMA_TYPE_GROUP:
- gdef = (xmlSchemaModelGroupDefPtr) term;
- if (gdef == groupDef)
- return (particle);
-
- if (gdef->flags & XML_SCHEMA_MODEL_GROUP_DEF_MARKED)
- continue;
- if (gdef->children != NULL) {
- gdef->flags |= XML_SCHEMA_MODEL_GROUP_DEF_MARKED;
- circ = xmlSchemaGetCircModelGrDefRef(groupDef,
- gdef->children->children);
- gdef->flags ^= XML_SCHEMA_MODEL_GROUP_DEF_MARKED;
- if (circ != NULL)
- return (circ);
- }
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL:
- circ = xmlSchemaGetCircModelGrDefRef(groupDef, term->children);
- if (circ != NULL)
- return (circ);
- break;
- default:
- break;
- }
- }
- return (NULL);
- }
- static void
- xmlSchemaCheckGroupDefCircular(xmlSchemaModelGroupDefPtr item,
- xmlSchemaParserCtxtPtr ctxt)
- {
-
- if ((item == NULL) ||
- (item->type != XML_SCHEMA_TYPE_GROUP) ||
- (item->children == NULL))
- return;
- {
- xmlSchemaTreeItemPtr circ;
- circ = xmlSchemaGetCircModelGrDefRef(item, item->children->children);
- if (circ != NULL) {
- xmlChar *str = NULL;
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_MG_PROPS_CORRECT_2,
- NULL, WXS_ITEM_NODE(circ),
- "Circular reference to the model group definition '%s' "
- "defined", xmlSchemaFormatQName(&str,
- item->targetNamespace, item->name));
- FREE_AND_NULL(str)
-
- circ->children = NULL;
- }
- }
- }
- static void
- xmlSchemaModelGroupToModelGroupDefFixup(
- xmlSchemaParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
- xmlSchemaModelGroupPtr mg)
- {
- xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg);
- while (particle != NULL) {
- if ((WXS_PARTICLE_TERM(particle) == NULL) ||
- ((WXS_PARTICLE_TERM(particle))->type !=
- XML_SCHEMA_TYPE_GROUP))
- {
- particle = WXS_PTC_CAST particle->next;
- continue;
- }
- if (WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle)) == NULL) {
-
- WXS_PARTICLE_TERM(particle) = NULL;
- particle = WXS_PTC_CAST particle->next;
- continue;
- }
-
- WXS_PARTICLE_TERM(particle) =
- WXS_TREE_CAST WXS_MODELGROUPDEF_MODEL(WXS_PARTICLE_TERM(particle));
- particle = WXS_PTC_CAST particle->next;
- }
- }
- static xmlSchemaQNameRefPtr
- xmlSchemaCheckAttrGroupCircularRecur(xmlSchemaAttributeGroupPtr ctxtGr,
- xmlSchemaItemListPtr list)
- {
- xmlSchemaAttributeGroupPtr gr;
- xmlSchemaQNameRefPtr ref, circ;
- int i;
-
- for (i = 0; i < list->nbItems; i++) {
- ref = list->items[i];
- if ((ref->type == XML_SCHEMA_EXTRA_QNAMEREF) &&
- (ref->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP) &&
- (ref->item != NULL))
- {
- gr = WXS_ATTR_GROUP_CAST ref->item;
- if (gr == ctxtGr)
- return(ref);
- if (gr->flags & XML_SCHEMAS_ATTRGROUP_MARKED)
- continue;
-
- if ((gr->attrUses) &&
- (gr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS))
- {
- gr->flags |= XML_SCHEMAS_ATTRGROUP_MARKED;
- circ = xmlSchemaCheckAttrGroupCircularRecur(ctxtGr,
- (xmlSchemaItemListPtr) gr->attrUses);
- gr->flags ^= XML_SCHEMAS_ATTRGROUP_MARKED;
- if (circ != NULL)
- return (circ);
- }
- }
- }
- return (NULL);
- }
- static int
- xmlSchemaCheckAttrGroupCircular(xmlSchemaAttributeGroupPtr attrGr,
- xmlSchemaParserCtxtPtr ctxt)
- {
-
- if (attrGr->attrUses == NULL)
- return(0);
- else if ((attrGr->flags & XML_SCHEMAS_ATTRGROUP_HAS_REFS) == 0)
- return(0);
- else {
- xmlSchemaQNameRefPtr circ;
- circ = xmlSchemaCheckAttrGroupCircularRecur(attrGr,
- (xmlSchemaItemListPtr) attrGr->attrUses);
- if (circ != NULL) {
- xmlChar *str = NULL;
-
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_SRC_ATTRIBUTE_GROUP_3,
- NULL, WXS_ITEM_NODE(WXS_BASIC_CAST circ),
- "Circular reference to the attribute group '%s' "
- "defined", xmlSchemaGetComponentQName(&str, attrGr));
- FREE_AND_NULL(str);
-
- circ->item = NULL;
- return(ctxt->err);
- }
- }
- return(0);
- }
- static int
- xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaAttributeGroupPtr attrGr);
- static int
- xmlSchemaExpandAttributeGroupRefs(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBasicItemPtr item,
- xmlSchemaWildcardPtr *completeWild,
- xmlSchemaItemListPtr list,
- xmlSchemaItemListPtr prohibs)
- {
- xmlSchemaAttributeGroupPtr gr;
- xmlSchemaAttributeUsePtr use;
- xmlSchemaItemListPtr sublist;
- int i, j;
- int created = (*completeWild == NULL) ? 0 : 1;
- if (prohibs)
- prohibs->nbItems = 0;
- for (i = 0; i < list->nbItems; i++) {
- use = list->items[i];
- if (use->type == XML_SCHEMA_EXTRA_ATTR_USE_PROHIB) {
- if (prohibs == NULL) {
- PERROR_INT("xmlSchemaExpandAttributeGroupRefs",
- "unexpected attr prohibition found");
- return(-1);
- }
-
- if (xmlSchemaItemListRemove(list, i) == -1)
- return(-1);
- i--;
-
-
- xmlSchemaItemListAddSize(prohibs, 2, use);
- continue;
- }
- if ((use->type == XML_SCHEMA_EXTRA_QNAMEREF) &&
- ((WXS_QNAME_CAST use)->itemType == XML_SCHEMA_TYPE_ATTRIBUTEGROUP))
- {
- if ((WXS_QNAME_CAST use)->item == NULL)
- return(-1);
- gr = WXS_ATTR_GROUP_CAST (WXS_QNAME_CAST use)->item;
-
- if ((gr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED) == 0) {
- if (xmlSchemaAttributeGroupExpandRefs(pctxt, gr) == -1)
- return(-1);
- }
-
- if (gr->attributeWildcard != NULL) {
- if (*completeWild == NULL) {
- *completeWild = gr->attributeWildcard;
- } else {
- if (! created) {
- xmlSchemaWildcardPtr tmpWild;
-
- tmpWild = xmlSchemaAddWildcard(pctxt, pctxt->schema,
- XML_SCHEMA_TYPE_ANY_ATTRIBUTE,
- WXS_ITEM_NODE(item));
- if (tmpWild == NULL)
- return(-1);
- if (xmlSchemaCloneWildcardNsConstraints(pctxt,
- tmpWild, *completeWild) == -1)
- return (-1);
- tmpWild->processContents = (*completeWild)->processContents;
- *completeWild = tmpWild;
- created = 1;
- }
- if (xmlSchemaIntersectWildcards(pctxt, *completeWild,
- gr->attributeWildcard) == -1)
- return(-1);
- }
- }
-
- sublist = ((xmlSchemaItemListPtr) gr->attrUses);
- if ((sublist == NULL) || sublist->nbItems == 0) {
- if (xmlSchemaItemListRemove(list, i) == -1)
- return(-1);
- i--;
- continue;
- }
-
- list->items[i] = sublist->items[0];
- if (sublist->nbItems != 1) {
- for (j = 1; j < sublist->nbItems; j++) {
- i++;
- if (xmlSchemaItemListInsert(list,
- sublist->items[j], i) == -1)
- return(-1);
- }
- }
- }
- }
-
- if (prohibs && (prohibs->nbItems != 0) && (list->nbItems != 0)) {
- xmlSchemaAttributeUseProhibPtr prohib;
- for (i = prohibs->nbItems -1; i >= 0; i--) {
- prohib = prohibs->items[i];
- for (j = 0; j < list->nbItems; j++) {
- use = list->items[j];
- if ((prohib->name == WXS_ATTRUSE_DECL_NAME(use)) &&
- (prohib->targetNamespace == WXS_ATTRUSE_DECL_TNS(use)))
- {
- xmlChar *str = NULL;
- xmlSchemaCustomWarning(ACTXT_CAST pctxt,
- XML_SCHEMAP_WARN_ATTR_POINTLESS_PROH,
- prohib->node, NULL,
- "Skipping pointless attribute use prohibition "
- "'%s', since a corresponding attribute use "
- "exists already in the type definition",
- xmlSchemaFormatQName(&str,
- prohib->targetNamespace, prohib->name),
- NULL, NULL);
- FREE_AND_NULL(str);
-
- if (xmlSchemaItemListRemove(prohibs, i) == -1)
- return(-1);
- break;
- }
- }
- }
- }
- return(0);
- }
- static int
- xmlSchemaAttributeGroupExpandRefs(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaAttributeGroupPtr attrGr)
- {
- if ((attrGr->attrUses == NULL) ||
- (attrGr->flags & XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED))
- return(0);
- attrGr->flags |= XML_SCHEMAS_ATTRGROUP_WILDCARD_BUILDED;
- if (xmlSchemaExpandAttributeGroupRefs(pctxt, WXS_BASIC_CAST attrGr,
- &(attrGr->attributeWildcard), attrGr->attrUses, NULL) == -1)
- return(-1);
- return(0);
- }
- static int
- xmlSchemaCheckAGPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaAttributeGroupPtr attrGr)
- {
-
- if ((attrGr->attrUses != NULL) &&
- (WXS_LIST_CAST attrGr->attrUses)->nbItems > 1)
- {
- xmlSchemaItemListPtr uses = WXS_LIST_CAST attrGr->attrUses;
- xmlSchemaAttributeUsePtr use, tmp;
- int i, j, hasId = 0;
- for (i = uses->nbItems -1; i >= 0; i--) {
- use = uses->items[i];
-
- if (i > 0) {
- for (j = i -1; j >= 0; j--) {
- tmp = uses->items[j];
- if ((WXS_ATTRUSE_DECL_NAME(use) ==
- WXS_ATTRUSE_DECL_NAME(tmp)) &&
- (WXS_ATTRUSE_DECL_TNS(use) ==
- WXS_ATTRUSE_DECL_TNS(tmp)))
- {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_AG_PROPS_CORRECT,
- attrGr->node, WXS_BASIC_CAST attrGr,
- "Duplicate %s",
- xmlSchemaGetComponentDesignation(&str, use),
- NULL);
- FREE_AND_NULL(str);
-
- if (xmlSchemaItemListRemove(uses, i) == -1)
- return(-1);
- goto next_use;
- }
- }
- }
-
- if (WXS_ATTRUSE_TYPEDEF(use) != NULL) {
- if (xmlSchemaIsDerivedFromBuiltInType(
- WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
- {
- if (hasId) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_AG_PROPS_CORRECT,
- attrGr->node, WXS_BASIC_CAST attrGr,
- "There must not exist more than one attribute "
- "declaration of type 'xs:ID' "
- "(or derived from 'xs:ID'). The %s violates this "
- "constraint",
- xmlSchemaGetComponentDesignation(&str, use),
- NULL);
- FREE_AND_NULL(str);
- if (xmlSchemaItemListRemove(uses, i) == -1)
- return(-1);
- }
- hasId = 1;
- }
- }
- next_use: {}
- }
- }
- return(0);
- }
- static int
- xmlSchemaResolveAttrGroupReferences(xmlSchemaQNameRefPtr ref,
- xmlSchemaParserCtxtPtr ctxt)
- {
- xmlSchemaAttributeGroupPtr group;
- if (ref->item != NULL)
- return(0);
- group = xmlSchemaGetAttributeGroup(ctxt->schema,
- ref->name,
- ref->targetNamespace);
- if (group == NULL) {
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- NULL, ref->node,
- "ref", ref->name, ref->targetNamespace,
- ref->itemType, NULL);
- return(ctxt->err);
- }
- ref->item = WXS_BASIC_CAST group;
- return(0);
- }
- static int
- xmlSchemaCheckAttrPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaAttributePtr attr)
- {
-
- if (WXS_ATTR_TYPEDEF(attr) == NULL)
- return(0);
- if (attr->defValue != NULL) {
- int ret;
-
- if (xmlSchemaIsDerivedFromBuiltInType(
- WXS_ATTR_TYPEDEF(attr), XML_SCHEMAS_ID))
- {
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_A_PROPS_CORRECT_3,
- NULL, WXS_BASIC_CAST attr,
- "Value constraints are not allowed if the type definition "
- "is or is derived from xs:ID",
- NULL, NULL);
- return(pctxt->err);
- }
-
- ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST pctxt,
- attr->node, WXS_ATTR_TYPEDEF(attr),
- attr->defValue, &(attr->defVal),
- 1, 1, 0);
- if (ret != 0) {
- if (ret < 0) {
- PERROR_INT("xmlSchemaCheckAttrPropsCorrect",
- "calling xmlSchemaVCheckCVCSimpleType()");
- return(-1);
- }
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_A_PROPS_CORRECT_2,
- NULL, WXS_BASIC_CAST attr,
- "The value of the value constraint is not valid",
- NULL, NULL);
- return(pctxt->err);
- }
- }
- return(0);
- }
- static xmlSchemaElementPtr
- xmlSchemaCheckSubstGroupCircular(xmlSchemaElementPtr elemDecl,
- xmlSchemaElementPtr ancestor)
- {
- xmlSchemaElementPtr ret;
- if (WXS_SUBST_HEAD(ancestor) == NULL)
- return (NULL);
- if (WXS_SUBST_HEAD(ancestor) == elemDecl)
- return (ancestor);
- if (WXS_SUBST_HEAD(ancestor)->flags & XML_SCHEMAS_ELEM_CIRCULAR)
- return (NULL);
- WXS_SUBST_HEAD(ancestor)->flags |= XML_SCHEMAS_ELEM_CIRCULAR;
- ret = xmlSchemaCheckSubstGroupCircular(elemDecl,
- WXS_SUBST_HEAD(ancestor));
- WXS_SUBST_HEAD(ancestor)->flags ^= XML_SCHEMAS_ELEM_CIRCULAR;
- return (ret);
- }
- static int
- xmlSchemaCheckElemPropsCorrect(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaElementPtr elemDecl)
- {
- int ret = 0;
- xmlSchemaTypePtr typeDef = WXS_ELEM_TYPEDEF(elemDecl);
-
- if (WXS_SUBST_HEAD(elemDecl) != NULL) {
- xmlSchemaElementPtr head = WXS_SUBST_HEAD(elemDecl), circ;
- xmlSchemaCheckElementDeclComponent(head, pctxt);
-
- if ((elemDecl->flags & XML_SCHEMAS_ELEM_GLOBAL) == 0) {
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_E_PROPS_CORRECT_3,
- WXS_BASIC_CAST elemDecl, NULL,
- "Only global element declarations can have a "
- "substitution group affiliation", NULL);
- ret = XML_SCHEMAP_E_PROPS_CORRECT_3;
- }
-
- if (head == elemDecl)
- circ = head;
- else if (WXS_SUBST_HEAD(head) != NULL)
- circ = xmlSchemaCheckSubstGroupCircular(head, head);
- else
- circ = NULL;
- if (circ != NULL) {
- xmlChar *strA = NULL, *strB = NULL;
- xmlSchemaPCustomErrExt(pctxt,
- XML_SCHEMAP_E_PROPS_CORRECT_6,
- WXS_BASIC_CAST circ, NULL,
- "The element declaration '%s' defines a circular "
- "substitution group to element declaration '%s'",
- xmlSchemaGetComponentQName(&strA, circ),
- xmlSchemaGetComponentQName(&strB, head),
- NULL);
- FREE_AND_NULL(strA)
- FREE_AND_NULL(strB)
- ret = XML_SCHEMAP_E_PROPS_CORRECT_6;
- }
-
- if (typeDef != WXS_ELEM_TYPEDEF(WXS_SUBST_HEAD(elemDecl))) {
- int set = 0;
- if (head->flags & XML_SCHEMAS_ELEM_FINAL_EXTENSION)
- set |= SUBSET_EXTENSION;
- if (head->flags & XML_SCHEMAS_ELEM_FINAL_RESTRICTION)
- set |= SUBSET_RESTRICTION;
- if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST pctxt, typeDef,
- WXS_ELEM_TYPEDEF(head), set) != 0) {
- xmlChar *strA = NULL, *strB = NULL, *strC = NULL;
- ret = XML_SCHEMAP_E_PROPS_CORRECT_4;
- xmlSchemaPCustomErrExt(pctxt,
- XML_SCHEMAP_E_PROPS_CORRECT_4,
- WXS_BASIC_CAST elemDecl, NULL,
- "The type definition '%s' was "
- "either rejected by the substitution group "
- "affiliation '%s', or not validly derived from its type "
- "definition '%s'",
- xmlSchemaGetComponentQName(&strA, typeDef),
- xmlSchemaGetComponentQName(&strB, head),
- xmlSchemaGetComponentQName(&strC, WXS_ELEM_TYPEDEF(head)));
- FREE_AND_NULL(strA)
- FREE_AND_NULL(strB)
- FREE_AND_NULL(strC)
- }
- }
- }
-
- if ((elemDecl->value != NULL) &&
- ((WXS_IS_SIMPLE(typeDef) &&
- xmlSchemaIsDerivedFromBuiltInType(typeDef, XML_SCHEMAS_ID)) ||
- (WXS_IS_COMPLEX(typeDef) &&
- WXS_HAS_SIMPLE_CONTENT(typeDef) &&
- xmlSchemaIsDerivedFromBuiltInType(typeDef->contentTypeDef,
- XML_SCHEMAS_ID)))) {
- ret = XML_SCHEMAP_E_PROPS_CORRECT_5;
- xmlSchemaPCustomErr(pctxt,
- XML_SCHEMAP_E_PROPS_CORRECT_5,
- WXS_BASIC_CAST elemDecl, NULL,
- "The type definition (or type definition's content type) is or "
- "is derived from ID; value constraints are not allowed in "
- "conjunction with such a type definition", NULL);
- } else if (elemDecl->value != NULL) {
- int vcret;
- xmlNodePtr node = NULL;
-
- if (typeDef == NULL) {
- xmlSchemaPErr(pctxt, elemDecl->node,
- XML_SCHEMAP_INTERNAL,
- "Internal error: xmlSchemaCheckElemPropsCorrect, "
- "type is missing... skipping validation of "
- "the value constraint", NULL, NULL);
- return (-1);
- }
- if (elemDecl->node != NULL) {
- if (elemDecl->flags & XML_SCHEMAS_ELEM_FIXED)
- node = (xmlNodePtr) xmlHasProp(elemDecl->node,
- BAD_CAST "fixed");
- else
- node = (xmlNodePtr) xmlHasProp(elemDecl->node,
- BAD_CAST "default");
- }
- vcret = xmlSchemaParseCheckCOSValidDefault(pctxt, node,
- typeDef, elemDecl->value, &(elemDecl->defVal));
- if (vcret != 0) {
- if (vcret < 0) {
- PERROR_INT("xmlSchemaElemCheckValConstr",
- "failed to validate the value constraint of an "
- "element declaration");
- return (-1);
- }
- return (vcret);
- }
- }
- return (ret);
- }
- static void
- xmlSchemaCheckElemSubstGroup(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaElementPtr elemDecl)
- {
- if ((WXS_SUBST_HEAD(elemDecl) == NULL) ||
-
- (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT))
- return;
- {
- xmlSchemaElementPtr head;
- xmlSchemaTypePtr headType, type;
- int set, methSet;
-
- for (head = WXS_SUBST_HEAD(elemDecl); head != NULL;
- head = WXS_SUBST_HEAD(head)) {
- set = 0;
- methSet = 0;
-
- if (head->flags & XML_SCHEMAS_ELEM_BLOCK_SUBSTITUTION)
- continue;
- headType = head->subtypes;
- type = elemDecl->subtypes;
- if (headType == type)
- goto add_member;
- if (head->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION)
- set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
- if (head->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION)
- set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
-
-
-
- while ((type != NULL) && (type != headType)) {
- if ((WXS_IS_EXTENSION(type)) &&
- ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
- methSet |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
- if (WXS_IS_RESTRICTION(type) &&
- ((methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
- methSet |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
- type = type->baseType;
- }
-
- type = elemDecl->subtypes->baseType;
- while (type != NULL) {
- if (WXS_IS_COMPLEX(type)) {
- if ((type->flags &
- XML_SCHEMAS_TYPE_BLOCK_EXTENSION) &&
- ((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) == 0))
- set |= XML_SCHEMAS_TYPE_BLOCK_EXTENSION;
- if ((type->flags &
- XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) &&
- ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) == 0))
- set |= XML_SCHEMAS_TYPE_BLOCK_RESTRICTION;
- } else
- break;
- if (type == headType)
- break;
- type = type->baseType;
- }
- if ((set != 0) &&
- (((set & XML_SCHEMAS_TYPE_BLOCK_EXTENSION) &&
- (methSet & XML_SCHEMAS_TYPE_BLOCK_EXTENSION)) ||
- ((set & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION) &&
- (methSet & XML_SCHEMAS_TYPE_BLOCK_RESTRICTION)))) {
- continue;
- }
- add_member:
- xmlSchemaAddElementSubstitutionMember(ctxt, head, elemDecl);
- if ((head->flags & XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD) == 0)
- head->flags |= XML_SCHEMAS_ELEM_SUBST_GROUP_HEAD;
- }
- }
- }
- #ifdef WXS_ELEM_DECL_CONS_ENABLED
- static int
- xmlSchemaCheckElementDeclConsistent(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBasicItemPtr ctxtComponent,
- xmlSchemaParticlePtr ctxtParticle,
- xmlSchemaParticlePtr searchParticle,
- xmlSchemaParticlePtr curParticle,
- int search)
- {
- return(0);
- int ret = 0;
- xmlSchemaParticlePtr cur = curParticle;
- if (curParticle == NULL) {
- return(0);
- }
- if (WXS_PARTICLE_TERM(curParticle) == NULL) {
-
- return(0);
- }
- while (cur != NULL) {
- switch (WXS_PARTICLE_TERM(cur)->type) {
- case XML_SCHEMA_TYPE_ANY:
- break;
- case XML_SCHEMA_TYPE_ELEMENT:
- if (search == 0) {
- ret = xmlSchemaCheckElementDeclConsistent(pctxt,
- ctxtComponent, ctxtParticle, cur, ctxtParticle, 1);
- if (ret != 0)
- return(ret);
- } else {
- xmlSchemaElementPtr elem =
- WXS_ELEM_CAST(WXS_PARTICLE_TERM(cur));
-
- if (xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->name,
- WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->name) &&
- xmlStrEqual(WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace,
- WXS_PARTICLE_TERM_AS_ELEM(searchParticle)->targetNamespace))
- {
- xmlChar *strA = NULL, *strB = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
-
- XML_SCHEMAP_COS_NONAMBIG,
- WXS_ITEM_NODE(cur), NULL,
- "In the content model of %s, there are multiple "
- "element declarations for '%s' with different "
- "type definitions",
- xmlSchemaGetComponentDesignation(&strA,
- ctxtComponent),
- xmlSchemaFormatQName(&strB,
- WXS_PARTICLE_TERM_AS_ELEM(cur)->targetNamespace,
- WXS_PARTICLE_TERM_AS_ELEM(cur)->name));
- FREE_AND_NULL(strA);
- FREE_AND_NULL(strB);
- return(XML_SCHEMAP_COS_NONAMBIG);
- }
- }
- break;
- case XML_SCHEMA_TYPE_SEQUENCE: {
- break;
- }
- case XML_SCHEMA_TYPE_CHOICE:{
-
- break;
- }
- case XML_SCHEMA_TYPE_ALL:
- break;
- case XML_SCHEMA_TYPE_GROUP:
- break;
- default:
- xmlSchemaInternalErr2(ACTXT_CAST pctxt,
- "xmlSchemaCheckElementDeclConsistent",
- "found unexpected term of type '%s' in content model",
- WXS_ITEM_TYPE_NAME(WXS_PARTICLE_TERM(cur)), NULL);
- return(-1);
- }
- cur = (xmlSchemaParticlePtr) cur->next;
- }
- exit:
- return(ret);
- }
- #endif
- static void
- xmlSchemaCheckElementDeclComponent(xmlSchemaElementPtr elemDecl,
- xmlSchemaParserCtxtPtr ctxt)
- {
- if (elemDecl == NULL)
- return;
- if (elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED)
- return;
- elemDecl->flags |= XML_SCHEMAS_ELEM_INTERNAL_CHECKED;
- if (xmlSchemaCheckElemPropsCorrect(ctxt, elemDecl) == 0) {
-
- xmlSchemaCheckElemSubstGroup(ctxt, elemDecl);
- }
- }
- static void
- xmlSchemaResolveModelGroupParticleReferences(
- xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaModelGroupPtr mg)
- {
- xmlSchemaParticlePtr particle = WXS_MODELGROUP_PARTICLE(mg);
- xmlSchemaQNameRefPtr ref;
- xmlSchemaBasicItemPtr refItem;
-
- while (particle != NULL) {
- if ((WXS_PARTICLE_TERM(particle) == NULL) ||
- ((WXS_PARTICLE_TERM(particle))->type !=
- XML_SCHEMA_EXTRA_QNAMEREF))
- {
- goto next_particle;
- }
- ref = WXS_QNAME_CAST WXS_PARTICLE_TERM(particle);
-
- particle->children = NULL;
- refItem = xmlSchemaGetNamedComponent(ctxt->schema,
- ref->itemType, ref->name, ref->targetNamespace);
- if (refItem == NULL) {
- xmlSchemaPResCompAttrErr(ctxt, XML_SCHEMAP_SRC_RESOLVE,
- NULL, WXS_ITEM_NODE(particle), "ref", ref->name,
- ref->targetNamespace, ref->itemType, NULL);
-
- goto next_particle;
- }
- if (refItem->type == XML_SCHEMA_TYPE_GROUP) {
- if (WXS_MODELGROUPDEF_MODEL(refItem) == NULL)
-
- goto next_particle;
-
- if ((WXS_MODELGROUPDEF_MODEL(refItem))->type ==
- XML_SCHEMA_TYPE_ALL) {
-
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
-
- XML_SCHEMAP_COS_ALL_LIMITED,
- WXS_ITEM_NODE(particle), NULL,
- "A model group definition is referenced, but "
- "it contains an 'all' model group, which "
- "cannot be contained by model groups",
- NULL, NULL);
-
- goto next_particle;
- }
- particle->children = (xmlSchemaTreeItemPtr) refItem;
- } else {
-
- particle->children = (xmlSchemaTreeItemPtr) refItem;
- }
- next_particle:
- particle = WXS_PTC_CAST particle->next;
- }
- }
- static int
- xmlSchemaAreValuesEqual(xmlSchemaValPtr x,
- xmlSchemaValPtr y)
- {
- xmlSchemaTypePtr tx, ty, ptx, pty;
- int ret;
- while (x != NULL) {
-
- tx = xmlSchemaGetBuiltInType(xmlSchemaGetValType(x));
- ty = xmlSchemaGetBuiltInType(xmlSchemaGetValType(y));
- ptx = xmlSchemaGetPrimitiveType(tx);
- pty = xmlSchemaGetPrimitiveType(ty);
-
-
- if (ptx != pty)
- return(0);
-
- if ((ptx->builtInType == XML_SCHEMAS_STRING) ||
- WXS_IS_ANY_SIMPLE_TYPE(ptx)) {
- if (! xmlStrEqual(
- xmlSchemaValueGetAsString(x),
- xmlSchemaValueGetAsString(y)))
- return (0);
- } else {
- ret = xmlSchemaCompareValuesWhtsp(
- x, XML_SCHEMA_WHITESPACE_PRESERVE,
- y, XML_SCHEMA_WHITESPACE_PRESERVE);
- if (ret == -2)
- return(-1);
- if (ret != 0)
- return(0);
- }
-
- x = xmlSchemaValueGetNext(x);
- if (x != NULL) {
- y = xmlSchemaValueGetNext(y);
- if (y == NULL)
- return (0);
- } else if (xmlSchemaValueGetNext(y) != NULL)
- return (0);
- else
- return (1);
- }
- return (0);
- }
- static int
- xmlSchemaResolveAttrUseReferences(xmlSchemaAttributeUsePtr ause,
- xmlSchemaParserCtxtPtr ctxt)
- {
- if ((ctxt == NULL) || (ause == NULL))
- return(-1);
- if ((ause->attrDecl == NULL) ||
- (ause->attrDecl->type != XML_SCHEMA_EXTRA_QNAMEREF))
- return(0);
- {
- xmlSchemaQNameRefPtr ref = WXS_QNAME_CAST ause->attrDecl;
-
- ause->attrDecl = xmlSchemaGetAttributeDecl(ctxt->schema,
- ref->name, ref->targetNamespace);
- if (ause->attrDecl == NULL) {
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST ause, ause->node,
- "ref", ref->name, ref->targetNamespace,
- XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
- return(ctxt->err);;
- }
- }
- return(0);
- }
- static int
- xmlSchemaCheckAttrUsePropsCorrect(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaAttributeUsePtr use)
- {
- if ((ctxt == NULL) || (use == NULL))
- return(-1);
- if ((use->defValue == NULL) || (WXS_ATTRUSE_DECL(use) == NULL) ||
- ((WXS_ATTRUSE_DECL(use))->type != XML_SCHEMA_TYPE_ATTRIBUTE))
- return(0);
-
- if (((WXS_ATTRUSE_DECL(use))->defValue != NULL) &&
- ((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMAS_ATTR_FIXED) &&
- ((use->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0))
- {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_AU_PROPS_CORRECT_2,
- WXS_BASIC_CAST use, NULL,
- "The attribute declaration has a 'fixed' value constraint "
- ", thus the attribute use must also have a 'fixed' value "
- "constraint",
- NULL);
- return(ctxt->err);
- }
-
- if ((use->defVal != NULL) && (WXS_ATTRUSE_TYPEDEF(use) != NULL)) {
- int ret;
-
-
- if (xmlSchemaIsDerivedFromBuiltInType(
- WXS_ATTRUSE_TYPEDEF(use), XML_SCHEMAS_ID))
- {
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_AU_PROPS_CORRECT,
- NULL, WXS_BASIC_CAST use,
- "Value constraints are not allowed if the type definition "
- "is or is derived from xs:ID",
- NULL, NULL);
- return(ctxt->err);
- }
- ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST ctxt,
- use->node, WXS_ATTRUSE_TYPEDEF(use),
- use->defValue, &(use->defVal),
- 1, 1, 0);
- if (ret != 0) {
- if (ret < 0) {
- PERROR_INT2("xmlSchemaCheckAttrUsePropsCorrect",
- "calling xmlSchemaVCheckCVCSimpleType()");
- return(-1);
- }
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAP_AU_PROPS_CORRECT,
- NULL, WXS_BASIC_CAST use,
- "The value of the value constraint is not valid",
- NULL, NULL);
- return(ctxt->err);
- }
- }
-
- if (((WXS_ATTRUSE_DECL(use))->defVal != NULL) &&
- (((WXS_ATTRUSE_DECL(use))->flags & XML_SCHEMA_ATTR_USE_FIXED) == 0))
- {
- if (! xmlSchemaAreValuesEqual(use->defVal,
- (WXS_ATTRUSE_DECL(use))->defVal))
- {
- xmlSchemaPCustomErr(ctxt,
- XML_SCHEMAP_AU_PROPS_CORRECT_2,
- WXS_BASIC_CAST use, NULL,
- "The 'fixed' value constraint of the attribute use "
- "must match the attribute declaration's value "
- "constraint '%s'",
- (WXS_ATTRUSE_DECL(use))->defValue);
- }
- return(ctxt->err);
- }
- return(0);
- }
- static int
- xmlSchemaResolveAttrTypeReferences(xmlSchemaAttributePtr item,
- xmlSchemaParserCtxtPtr ctxt)
- {
-
- if (item->flags & XML_SCHEMAS_ATTR_INTERNAL_RESOLVED)
- return(0);
- item->flags |= XML_SCHEMAS_ATTR_INTERNAL_RESOLVED;
- if (item->subtypes != NULL)
- return(0);
- if (item->typeName != NULL) {
- xmlSchemaTypePtr type;
- type = xmlSchemaGetType(ctxt->schema, item->typeName,
- item->typeNs);
- if ((type == NULL) || (! WXS_IS_SIMPLE(type))) {
- xmlSchemaPResCompAttrErr(ctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST item, item->node,
- "type", item->typeName, item->typeNs,
- XML_SCHEMA_TYPE_SIMPLE, NULL);
- return(ctxt->err);
- } else
- item->subtypes = type;
- } else {
-
- item->subtypes = xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYSIMPLETYPE);
- }
- return(0);
- }
- static int
- xmlSchemaResolveIDCKeyReferences(xmlSchemaIDCPtr idc,
- xmlSchemaParserCtxtPtr pctxt)
- {
- if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF)
- return(0);
- if (idc->ref->name != NULL) {
- idc->ref->item = (xmlSchemaBasicItemPtr)
- xmlSchemaGetIDC(pctxt->schema, idc->ref->name,
- idc->ref->targetNamespace);
- if (idc->ref->item == NULL) {
-
- xmlSchemaPResCompAttrErr(pctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- WXS_BASIC_CAST idc, idc->node,
- "refer", idc->ref->name,
- idc->ref->targetNamespace,
- XML_SCHEMA_TYPE_IDC_KEY, NULL);
- return(pctxt->err);
- } else if (idc->ref->item->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_C_PROPS_CORRECT,
- NULL, WXS_BASIC_CAST idc,
- "The keyref references a keyref",
- NULL, NULL);
- idc->ref->item = NULL;
- return(pctxt->err);
- } else {
- if (idc->nbFields !=
- ((xmlSchemaIDCPtr) idc->ref->item)->nbFields) {
- xmlChar *str = NULL;
- xmlSchemaIDCPtr refer;
- refer = (xmlSchemaIDCPtr) idc->ref->item;
-
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_C_PROPS_CORRECT,
- NULL, WXS_BASIC_CAST idc,
- "The cardinality of the keyref differs from the "
- "cardinality of the referenced key/unique '%s'",
- xmlSchemaFormatQName(&str, refer->targetNamespace,
- refer->name),
- NULL);
- FREE_AND_NULL(str)
- return(pctxt->err);
- }
- }
- }
- return(0);
- }
- static int
- xmlSchemaResolveAttrUseProhibReferences(xmlSchemaAttributeUseProhibPtr prohib,
- xmlSchemaParserCtxtPtr pctxt)
- {
- if (xmlSchemaGetAttributeDecl(pctxt->schema, prohib->name,
- prohib->targetNamespace) == NULL) {
- xmlSchemaPResCompAttrErr(pctxt,
- XML_SCHEMAP_SRC_RESOLVE,
- NULL, prohib->node,
- "ref", prohib->name, prohib->targetNamespace,
- XML_SCHEMA_TYPE_ATTRIBUTE, NULL);
- return(XML_SCHEMAP_SRC_RESOLVE);
- }
- return(0);
- }
- #define WXS_REDEFINED_TYPE(c) \
- (((xmlSchemaTypePtr) item)->flags & XML_SCHEMAS_TYPE_REDEFINED)
- #define WXS_REDEFINED_MODEL_GROUP_DEF(c) \
- (((xmlSchemaModelGroupDefPtr) item)->flags & XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
- #define WXS_REDEFINED_ATTR_GROUP(c) \
- (((xmlSchemaAttributeGroupPtr) item)->flags & XML_SCHEMAS_ATTRGROUP_REDEFINED)
- static int
- xmlSchemaCheckSRCRedefineFirst(xmlSchemaParserCtxtPtr pctxt)
- {
- int err = 0;
- xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs;
- xmlSchemaBasicItemPtr prev, item;
- int wasRedefined;
- if (redef == NULL)
- return(0);
- do {
- item = redef->item;
-
- prev = xmlSchemaFindRedefCompInGraph(
- redef->targetBucket, item->type,
- redef->refName, redef->refTargetNs);
- if (prev == NULL) {
- xmlChar *str = NULL;
- xmlNodePtr node;
-
- if (redef->reference)
- node = WXS_ITEM_NODE(redef->reference);
- else
- node = WXS_ITEM_NODE(item);
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
-
- XML_SCHEMAP_SRC_REDEFINE, node, NULL,
- "The %s '%s' to be redefined could not be found in "
- "the redefined schema",
- WXS_ITEM_TYPE_NAME(item),
- xmlSchemaFormatQName(&str, redef->refTargetNs,
- redef->refName));
- FREE_AND_NULL(str);
- err = pctxt->err;
- redef = redef->next;
- continue;
- }
-
- wasRedefined = 0;
- switch (item->type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- if ((WXS_TYPE_CAST prev)->flags &
- XML_SCHEMAS_TYPE_REDEFINED)
- {
- wasRedefined = 1;
- break;
- }
-
- (WXS_TYPE_CAST prev)->flags |= XML_SCHEMAS_TYPE_REDEFINED;
-
- ((xmlSchemaTypePtr) item)->baseType =
- (xmlSchemaTypePtr) prev;
- break;
- case XML_SCHEMA_TYPE_GROUP:
- if ((WXS_MODEL_GROUPDEF_CAST prev)->flags &
- XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED)
- {
- wasRedefined = 1;
- break;
- }
-
- (WXS_MODEL_GROUPDEF_CAST prev)->flags |=
- XML_SCHEMA_MODEL_GROUP_DEF_REDEFINED;
- if (redef->reference != NULL) {
-
- (WXS_PTC_CAST redef->reference)->children =
- WXS_TREE_CAST prev;
- }
- redef->target = prev;
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- if ((WXS_ATTR_GROUP_CAST prev)->flags &
- XML_SCHEMAS_ATTRGROUP_REDEFINED)
- {
- wasRedefined = 1;
- break;
- }
- (WXS_ATTR_GROUP_CAST prev)->flags |=
- XML_SCHEMAS_ATTRGROUP_REDEFINED;
- if (redef->reference != NULL) {
-
- (WXS_QNAME_CAST redef->reference)->item = prev;
- redef->target = NULL;
- } else {
-
- redef->target = prev;
- }
- break;
- default:
- PERROR_INT("xmlSchemaResolveRedefReferences",
- "Unexpected redefined component type");
- return(-1);
- }
- if (wasRedefined) {
- xmlChar *str = NULL;
- xmlNodePtr node;
- if (redef->reference)
- node = WXS_ITEM_NODE(redef->reference);
- else
- node = WXS_ITEM_NODE(redef->item);
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
-
- XML_SCHEMAP_SRC_REDEFINE,
- node, NULL,
- "The referenced %s was already redefined. Multiple "
- "redefinition of the same component is not supported",
- xmlSchemaGetComponentDesignation(&str, prev),
- NULL);
- FREE_AND_NULL(str)
- err = pctxt->err;
- redef = redef->next;
- continue;
- }
- redef = redef->next;
- } while (redef != NULL);
- return(err);
- }
- static int
- xmlSchemaCheckSRCRedefineSecond(xmlSchemaParserCtxtPtr pctxt)
- {
- int err = 0;
- xmlSchemaRedefPtr redef = WXS_CONSTRUCTOR(pctxt)->redefs;
- xmlSchemaBasicItemPtr item;
- if (redef == NULL)
- return(0);
- do {
- if (redef->target == NULL) {
- redef = redef->next;
- continue;
- }
- item = redef->item;
- switch (item->type) {
- case XML_SCHEMA_TYPE_SIMPLE:
- case XML_SCHEMA_TYPE_COMPLEX:
-
- (WXS_TYPE_CAST redef->target)->name = NULL;
-
- break;
- case XML_SCHEMA_TYPE_GROUP:
-
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
-
- err = xmlSchemaCheckDerivationOKRestriction2to4(pctxt,
- XML_SCHEMA_ACTION_REDEFINE,
- item, redef->target,
- (WXS_ATTR_GROUP_CAST item)->attrUses,
- (WXS_ATTR_GROUP_CAST redef->target)->attrUses,
- (WXS_ATTR_GROUP_CAST item)->attributeWildcard,
- (WXS_ATTR_GROUP_CAST redef->target)->attributeWildcard);
- if (err == -1)
- return(-1);
- break;
- default:
- break;
- }
- redef = redef->next;
- } while (redef != NULL);
- return(0);
- }
- static int
- xmlSchemaAddComponents(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBucketPtr bucket)
- {
- xmlSchemaBasicItemPtr item;
- int err;
- xmlHashTablePtr *table;
- const xmlChar *name;
- int i;
- #define WXS_GET_GLOBAL_HASH(c, slot) { \
- if (WXS_IS_BUCKET_IMPMAIN((c)->type)) \
- table = &(WXS_IMPBUCKET((c))->schema->slot); \
- else \
- table = &(WXS_INCBUCKET((c))->ownerImport->schema->slot); }
-
- if (bucket == NULL)
- return(-1);
- if (bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED)
- return(0);
- bucket->flags |= XML_SCHEMA_BUCKET_COMPS_ADDED;
- for (i = 0; i < bucket->globals->nbItems; i++) {
- item = bucket->globals->items[i];
- table = NULL;
- switch (item->type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- if (WXS_REDEFINED_TYPE(item))
- continue;
- name = (WXS_TYPE_CAST item)->name;
- WXS_GET_GLOBAL_HASH(bucket, typeDecl)
- break;
- case XML_SCHEMA_TYPE_ELEMENT:
- name = (WXS_ELEM_CAST item)->name;
- WXS_GET_GLOBAL_HASH(bucket, elemDecl)
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- name = (WXS_ATTR_CAST item)->name;
- WXS_GET_GLOBAL_HASH(bucket, attrDecl)
- break;
- case XML_SCHEMA_TYPE_GROUP:
- if (WXS_REDEFINED_MODEL_GROUP_DEF(item))
- continue;
- name = (WXS_MODEL_GROUPDEF_CAST item)->name;
- WXS_GET_GLOBAL_HASH(bucket, groupDecl)
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- if (WXS_REDEFINED_ATTR_GROUP(item))
- continue;
- name = (WXS_ATTR_GROUP_CAST item)->name;
- WXS_GET_GLOBAL_HASH(bucket, attrgrpDecl)
- break;
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- name = (WXS_IDC_CAST item)->name;
- WXS_GET_GLOBAL_HASH(bucket, idcDef)
- break;
- case XML_SCHEMA_TYPE_NOTATION:
- name = ((xmlSchemaNotationPtr) item)->name;
- WXS_GET_GLOBAL_HASH(bucket, notaDecl)
- break;
- default:
- PERROR_INT("xmlSchemaAddComponents",
- "Unexpected global component type");
- continue;
- }
- if (*table == NULL) {
- *table = xmlHashCreateDict(10, pctxt->dict);
- if (*table == NULL) {
- PERROR_INT("xmlSchemaAddComponents",
- "failed to create a component hash table");
- return(-1);
- }
- }
- err = xmlHashAddEntry(*table, name, item);
- if (err != 0) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST pctxt,
- XML_SCHEMAP_REDEFINED_TYPE,
- WXS_ITEM_NODE(item),
- WXS_BASIC_CAST item,
- "A global %s '%s' does already exist",
- WXS_ITEM_TYPE_NAME(item),
- xmlSchemaGetComponentQName(&str, item));
- FREE_AND_NULL(str);
- }
- }
-
- if (bucket->relations != NULL) {
- xmlSchemaSchemaRelationPtr rel = bucket->relations;
- do {
- if ((rel->bucket != NULL) &&
- ((rel->bucket->flags & XML_SCHEMA_BUCKET_COMPS_ADDED) == 0)) {
- if (xmlSchemaAddComponents(pctxt, rel->bucket) == -1)
- return(-1);
- }
- rel = rel->next;
- } while (rel != NULL);
- }
- return(0);
- }
- static int
- xmlSchemaFixupComponents(xmlSchemaParserCtxtPtr pctxt,
- xmlSchemaBucketPtr rootBucket)
- {
- xmlSchemaConstructionCtxtPtr con = pctxt->constructor;
- xmlSchemaTreeItemPtr item, *items;
- int nbItems, i, ret = 0;
- xmlSchemaBucketPtr oldbucket = con->bucket;
- xmlSchemaElementPtr elemDecl;
- #define FIXHFAILURE if (pctxt->err == XML_SCHEMAP_INTERNAL) goto exit_failure;
- if ((con->pending == NULL) ||
- (con->pending->nbItems == 0))
- return(0);
-
- if (con->bucket == NULL)
- con->bucket = rootBucket;
-
- xmlSchemaCheckSRCRedefineFirst(pctxt);
-
- xmlSchemaAddComponents(pctxt, rootBucket);
- pctxt->ctxtType = NULL;
- items = (xmlSchemaTreeItemPtr *) con->pending->items;
- nbItems = con->pending->nbItems;
-
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- xmlSchemaResolveElementReferences(
- (xmlSchemaElementPtr) item, pctxt);
- FIXHFAILURE;
- break;
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- xmlSchemaResolveTypeReferences(
- (xmlSchemaTypePtr) item, pctxt);
- FIXHFAILURE;
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- xmlSchemaResolveAttrTypeReferences(
- (xmlSchemaAttributePtr) item, pctxt);
- FIXHFAILURE;
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- xmlSchemaResolveAttrUseReferences(
- (xmlSchemaAttributeUsePtr) item, pctxt);
- FIXHFAILURE;
- break;
- case XML_SCHEMA_EXTRA_QNAMEREF:
- if ((WXS_QNAME_CAST item)->itemType ==
- XML_SCHEMA_TYPE_ATTRIBUTEGROUP)
- {
- xmlSchemaResolveAttrGroupReferences(
- WXS_QNAME_CAST item, pctxt);
- }
- FIXHFAILURE;
- break;
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- case XML_SCHEMA_TYPE_ALL:
- xmlSchemaResolveModelGroupParticleReferences(pctxt,
- WXS_MODEL_GROUP_CAST item);
- FIXHFAILURE;
- break;
- case XML_SCHEMA_TYPE_IDC_KEY:
- case XML_SCHEMA_TYPE_IDC_UNIQUE:
- case XML_SCHEMA_TYPE_IDC_KEYREF:
- xmlSchemaResolveIDCKeyReferences(
- (xmlSchemaIDCPtr) item, pctxt);
- FIXHFAILURE;
- break;
- case XML_SCHEMA_EXTRA_ATTR_USE_PROHIB:
-
- xmlSchemaResolveAttrUseProhibReferences(
- WXS_ATTR_PROHIB_CAST item, pctxt);
- FIXHFAILURE;
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
-
- switch (item->type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- case XML_SCHEMA_TYPE_SIMPLE:
- xmlSchemaCheckTypeDefCircular(
- (xmlSchemaTypePtr) item, pctxt);
- FIXHFAILURE;
- if (pctxt->nberrors != 0)
- goto exit_error;
- break;
- case XML_SCHEMA_TYPE_GROUP:
- xmlSchemaCheckGroupDefCircular(
- (xmlSchemaModelGroupDefPtr) item, pctxt);
- FIXHFAILURE;
- if (pctxt->nberrors != 0)
- goto exit_error;
- break;
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- xmlSchemaCheckAttrGroupCircular(
- (xmlSchemaAttributeGroupPtr) item, pctxt);
- FIXHFAILURE;
- if (pctxt->nberrors != 0)
- goto exit_error;
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_SEQUENCE:
- case XML_SCHEMA_TYPE_CHOICE:
- xmlSchemaModelGroupToModelGroupDefFixup(pctxt,
- WXS_MODEL_GROUP_CAST item);
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- if ((! WXS_ATTR_GROUP_EXPANDED(item)) &&
- WXS_ATTR_GROUP_HAS_REFS(item))
- {
- xmlSchemaAttributeGroupExpandRefs(pctxt,
- WXS_ATTR_GROUP_CAST item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_SIMPLE:
- if (WXS_IS_TYPE_NOT_FIXED_1((xmlSchemaTypePtr) item)) {
- xmlSchemaFixupSimpleTypeStageOne(pctxt,
- (xmlSchemaTypePtr) item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_SIMPLE:
- if (((xmlSchemaTypePtr) item)->memberTypes != NULL) {
- xmlSchemaCheckUnionTypeDefCircular(pctxt,
- (xmlSchemaTypePtr) item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_SIMPLE:
- if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) {
- xmlSchemaFixupSimpleTypeStageTwo(pctxt, WXS_TYPE_CAST item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_ATTRIBUTE:
- xmlSchemaCheckAttrPropsCorrect(pctxt, WXS_ATTR_CAST item);
- FIXHFAILURE;
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_ATTRIBUTE_USE:
- if (((xmlSchemaAttributeUsePtr)item)->defValue != NULL) {
- xmlSchemaCheckAttrUsePropsCorrect(pctxt,
- WXS_ATTR_USE_CAST item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_ATTRIBUTEGROUP:
- if (( (WXS_ATTR_GROUP_CAST item)->attrUses != NULL) &&
- ( (WXS_LIST_CAST (WXS_ATTR_GROUP_CAST item)->attrUses)->nbItems > 1))
- {
- xmlSchemaCheckAGPropsCorrect(pctxt, WXS_ATTR_GROUP_CAST item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- if (WXS_CONSTRUCTOR(pctxt)->redefs != NULL)
- xmlSchemaCheckSRCRedefineSecond(pctxt);
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = con->pending->items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- if (WXS_IS_TYPE_NOT_FIXED(WXS_TYPE_CAST item)) {
- xmlSchemaFixupComplexType(pctxt, WXS_TYPE_CAST item);
- FIXHFAILURE;
- }
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- items = (xmlSchemaTreeItemPtr *) con->pending->items;
- nbItems = con->pending->nbItems;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_ELEMENT:
- elemDecl = (xmlSchemaElementPtr) item;
- if ((elemDecl->flags & XML_SCHEMAS_ELEM_INTERNAL_CHECKED) == 0)
- {
- xmlSchemaCheckElementDeclComponent(
- (xmlSchemaElementPtr) elemDecl, pctxt);
- FIXHFAILURE;
- }
- #ifdef WXS_ELEM_DECL_CONS_ENABLED
-
- if ((WXS_ELEM_TYPEDEF(elemDecl) != NULL) &&
- (WXS_IS_COMPLEX(WXS_ELEM_TYPEDEF(elemDecl))) &&
- (WXS_TYPE_IS_LOCAL(WXS_ELEM_TYPEDEF(elemDecl))))
- {
- xmlSchemaCheckElementDeclConsistent(pctxt,
- WXS_BASIC_CAST elemDecl,
- WXS_TYPE_PARTICLE(WXS_ELEM_TYPEDEF(elemDecl)),
- NULL, NULL, 0);
- }
- #endif
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- for (i = 0; i < nbItems; i++) {
- item = items[i];
- switch (item->type) {
- case XML_SCHEMA_TYPE_COMPLEX:
- xmlSchemaBuildContentModel((xmlSchemaTypePtr) item, pctxt);
-
- break;
- default:
- break;
- }
- }
- if (pctxt->nberrors != 0)
- goto exit_error;
-
- goto exit;
- exit_error:
- ret = pctxt->err;
- goto exit;
- exit_failure:
- ret = -1;
- exit:
-
- con->bucket = oldbucket;
- con->pending->nbItems = 0;
- if (con->substGroups != NULL) {
- xmlHashFree(con->substGroups,
- (xmlHashDeallocator) xmlSchemaSubstGroupFree);
- con->substGroups = NULL;
- }
- if (con->redefs != NULL) {
- xmlSchemaRedefListFree(con->redefs);
- con->redefs = NULL;
- }
- return(ret);
- }
- xmlSchemaPtr
- xmlSchemaParse(xmlSchemaParserCtxtPtr ctxt)
- {
- xmlSchemaPtr mainSchema = NULL;
- xmlSchemaBucketPtr bucket = NULL;
- int res;
-
- xmlSchemaInitTypes();
- if (ctxt == NULL)
- return (NULL);
-
- ctxt->nberrors = 0;
- ctxt->err = 0;
- ctxt->counter = 0;
-
- mainSchema = xmlSchemaNewSchema(ctxt);
- if (mainSchema == NULL)
- goto exit_failure;
-
- if (ctxt->constructor == NULL) {
- ctxt->constructor = xmlSchemaConstructionCtxtCreate(ctxt->dict);
- if (ctxt->constructor == NULL)
- return(NULL);
-
- ctxt->ownsConstructor = 1;
- }
- ctxt->constructor->mainSchema = mainSchema;
-
- res = xmlSchemaAddSchemaDoc(ctxt, XML_SCHEMA_SCHEMA_MAIN,
- ctxt->URL, ctxt->doc, ctxt->buffer, ctxt->size, NULL,
- NULL, NULL, &bucket);
- if (res == -1)
- goto exit_failure;
- if (res != 0)
- goto exit;
- if (bucket == NULL) {
-
- if (ctxt->URL)
- xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD,
- NULL, NULL,
- "Failed to locate the main schema resource at '%s'",
- ctxt->URL, NULL);
- else
- xmlSchemaCustomErr(ACTXT_CAST ctxt, XML_SCHEMAP_FAILED_LOAD,
- NULL, NULL,
- "Failed to locate the main schema resource",
- NULL, NULL);
- goto exit;
- }
-
- if (xmlSchemaParseNewDocWithContext(ctxt, mainSchema, bucket) == -1)
- goto exit_failure;
- if (ctxt->nberrors != 0)
- goto exit;
- mainSchema->doc = bucket->doc;
- mainSchema->preserve = ctxt->preserve;
- ctxt->schema = mainSchema;
- if (xmlSchemaFixupComponents(ctxt, WXS_CONSTRUCTOR(ctxt)->mainBucket) == -1)
- goto exit_failure;
-
- exit:
- if (ctxt->nberrors != 0) {
- if (mainSchema) {
- xmlSchemaFree(mainSchema);
- mainSchema = NULL;
- }
- if (ctxt->constructor) {
- xmlSchemaConstructionCtxtFree(ctxt->constructor);
- ctxt->constructor = NULL;
- ctxt->ownsConstructor = 0;
- }
- }
- ctxt->schema = NULL;
- return(mainSchema);
- exit_failure:
-
- if (mainSchema) {
- xmlSchemaFree(mainSchema);
- mainSchema = NULL;
- }
- if (ctxt->constructor) {
- xmlSchemaConstructionCtxtFree(ctxt->constructor);
- ctxt->constructor = NULL;
- ctxt->ownsConstructor = 0;
- }
- PERROR_INT2("xmlSchemaParse",
- "An internal error occured");
- ctxt->schema = NULL;
- return(NULL);
- }
- void
- xmlSchemaSetParserErrors(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaValidityErrorFunc err,
- xmlSchemaValidityWarningFunc warn, void *ctx)
- {
- if (ctxt == NULL)
- return;
- ctxt->error = err;
- ctxt->warning = warn;
- ctxt->errCtxt = ctx;
- if (ctxt->vctxt != NULL)
- xmlSchemaSetValidErrors(ctxt->vctxt, err, warn, ctx);
- }
- void
- xmlSchemaSetParserStructuredErrors(xmlSchemaParserCtxtPtr ctxt,
- xmlStructuredErrorFunc serror,
- void *ctx)
- {
- if (ctxt == NULL)
- return;
- ctxt->serror = serror;
- ctxt->errCtxt = ctx;
- if (ctxt->vctxt != NULL)
- xmlSchemaSetValidStructuredErrors(ctxt->vctxt, serror, ctx);
- }
- int
- xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt,
- xmlSchemaValidityErrorFunc * err,
- xmlSchemaValidityWarningFunc * warn, void **ctx)
- {
- if (ctxt == NULL)
- return(-1);
- if (err != NULL)
- *err = ctxt->error;
- if (warn != NULL)
- *warn = ctxt->warning;
- if (ctx != NULL)
- *ctx = ctxt->errCtxt;
- return(0);
- }
- static const xmlChar *
- xmlSchemaFacetTypeToString(xmlSchemaTypeType type)
- {
- switch (type) {
- case XML_SCHEMA_FACET_PATTERN:
- return (BAD_CAST "pattern");
- case XML_SCHEMA_FACET_MAXEXCLUSIVE:
- return (BAD_CAST "maxExclusive");
- case XML_SCHEMA_FACET_MAXINCLUSIVE:
- return (BAD_CAST "maxInclusive");
- case XML_SCHEMA_FACET_MINEXCLUSIVE:
- return (BAD_CAST "minExclusive");
- case XML_SCHEMA_FACET_MININCLUSIVE:
- return (BAD_CAST "minInclusive");
- case XML_SCHEMA_FACET_WHITESPACE:
- return (BAD_CAST "whiteSpace");
- case XML_SCHEMA_FACET_ENUMERATION:
- return (BAD_CAST "enumeration");
- case XML_SCHEMA_FACET_LENGTH:
- return (BAD_CAST "length");
- case XML_SCHEMA_FACET_MAXLENGTH:
- return (BAD_CAST "maxLength");
- case XML_SCHEMA_FACET_MINLENGTH:
- return (BAD_CAST "minLength");
- case XML_SCHEMA_FACET_TOTALDIGITS:
- return (BAD_CAST "totalDigits");
- case XML_SCHEMA_FACET_FRACTIONDIGITS:
- return (BAD_CAST "fractionDigits");
- default:
- break;
- }
- return (BAD_CAST "Internal Error");
- }
- static xmlSchemaWhitespaceValueType
- xmlSchemaGetWhiteSpaceFacetValue(xmlSchemaTypePtr type)
- {
-
- if (type->type == XML_SCHEMA_TYPE_BASIC) {
-
- if ((type->builtInType == XML_SCHEMAS_STRING) ||
- (type->builtInType == XML_SCHEMAS_ANYSIMPLETYPE))
- return(XML_SCHEMA_WHITESPACE_PRESERVE);
- else if (type->builtInType == XML_SCHEMAS_NORMSTRING)
- return(XML_SCHEMA_WHITESPACE_REPLACE);
- else {
-
- return(XML_SCHEMA_WHITESPACE_COLLAPSE);
- }
- } else if (WXS_IS_LIST(type)) {
-
- return (XML_SCHEMA_WHITESPACE_COLLAPSE);
- } else if (WXS_IS_UNION(type)) {
- return (XML_SCHEMA_WHITESPACE_UNKNOWN);
- } else if (WXS_IS_ATOMIC(type)) {
- if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_PRESERVE)
- return (XML_SCHEMA_WHITESPACE_PRESERVE);
- else if (type->flags & XML_SCHEMAS_TYPE_WHITESPACE_REPLACE)
- return (XML_SCHEMA_WHITESPACE_REPLACE);
- else
- return (XML_SCHEMA_WHITESPACE_COLLAPSE);
- }
- return (-1);
- }
- static int
- xmlSchemaAssembleByLocation(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- const xmlChar *nsName,
- const xmlChar *location)
- {
- int ret = 0;
- xmlSchemaParserCtxtPtr pctxt;
- xmlSchemaBucketPtr bucket = NULL;
- if ((vctxt == NULL) || (schema == NULL))
- return (-1);
- if (vctxt->pctxt == NULL) {
- VERROR_INT("xmlSchemaAssembleByLocation",
- "no parser context available");
- return(-1);
- }
- pctxt = vctxt->pctxt;
- if (pctxt->constructor == NULL) {
- PERROR_INT("xmlSchemaAssembleByLocation",
- "no constructor");
- return(-1);
- }
-
- location = xmlSchemaBuildAbsoluteURI(pctxt->dict,
- location, node);
-
- ret = xmlSchemaAddSchemaDoc(pctxt, XML_SCHEMA_SCHEMA_IMPORT,
- location, NULL, NULL, 0, node, NULL, nsName,
- &bucket);
- if (ret != 0)
- return(ret);
- if (bucket == NULL) {
-
- xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC,
- node, NULL,
- "The document at location '%s' could not be acquired",
- location, NULL, NULL);
- return(ret);
- }
-
- if ((bucket != NULL) &&
- (WXS_CONSTRUCTOR(pctxt)->bucket == NULL))
- WXS_CONSTRUCTOR(pctxt)->bucket = bucket;
-
- if ((bucket == NULL) || (! CAN_PARSE_SCHEMA(bucket)))
- return(0);
-
- pctxt->nberrors = 0;
- pctxt->err = 0;
- pctxt->doc = bucket->doc;
- ret = xmlSchemaParseNewDocWithContext(pctxt, schema, bucket);
- if (ret == -1) {
- pctxt->doc = NULL;
- goto exit_failure;
- }
-
- if ((ret == 0) && (pctxt->nberrors != 0))
- ret = pctxt->err;
- if (pctxt->nberrors == 0) {
-
- xmlSchemaFixupComponents(pctxt, bucket);
- ret = pctxt->err;
-
- if ((ret != 0) && (vctxt->err == 0))
- vctxt->err = ret;
- vctxt->nberrors += pctxt->nberrors;
- } else {
-
- vctxt->nberrors += pctxt->nberrors;
- }
- pctxt->doc = NULL;
- return(ret);
- exit_failure:
- pctxt->doc = NULL;
- return (-1);
- }
- static xmlSchemaAttrInfoPtr
- xmlSchemaGetMetaAttrInfo(xmlSchemaValidCtxtPtr vctxt,
- int metaType)
- {
- if (vctxt->nbAttrInfos == 0)
- return (NULL);
- {
- int i;
- xmlSchemaAttrInfoPtr iattr;
- for (i = 0; i < vctxt->nbAttrInfos; i++) {
- iattr = vctxt->attrInfos[i];
- if (iattr->metaType == metaType)
- return (iattr);
- }
- }
- return (NULL);
- }
- static int
- xmlSchemaAssembleByXSI(xmlSchemaValidCtxtPtr vctxt)
- {
- const xmlChar *cur, *end;
- const xmlChar *nsname = NULL, *location;
- int count = 0;
- int ret = 0;
- xmlSchemaAttrInfoPtr iattr;
-
- iattr = xmlSchemaGetMetaAttrInfo(vctxt,
- XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC);
- if (iattr == NULL)
- iattr = xmlSchemaGetMetaAttrInfo(vctxt,
- XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC);
- if (iattr == NULL)
- return (0);
- cur = iattr->value;
- do {
-
- if (iattr->metaType == XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC) {
-
- while (IS_BLANK_CH(*cur))
- cur++;
- end = cur;
- while ((*end != 0) && (!(IS_BLANK_CH(*end))))
- end++;
- if (end == cur)
- break;
- count++;
- nsname = xmlDictLookup(vctxt->schema->dict, cur, end - cur);
- cur = end;
- }
-
- while (IS_BLANK_CH(*cur))
- cur++;
- end = cur;
- while ((*end != 0) && (!(IS_BLANK_CH(*end))))
- end++;
- if (end == cur) {
- if (iattr->metaType ==
- XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC)
- {
-
- xmlSchemaCustomWarning(ACTXT_CAST vctxt, XML_SCHEMAV_MISC,
- iattr->node, NULL,
- "The value must consist of tuples: the target namespace "
- "name and the document's URI", NULL, NULL, NULL);
- }
- break;
- }
- count++;
- location = xmlDictLookup(vctxt->schema->dict, cur, end - cur);
- cur = end;
- ret = xmlSchemaAssembleByLocation(vctxt, vctxt->schema,
- iattr->node, nsname, location);
- if (ret == -1) {
- VERROR_INT("xmlSchemaAssembleByXSI",
- "assembling schemata");
- return (-1);
- }
- } while (*cur != 0);
- return (ret);
- }
- static const xmlChar *
- xmlSchemaLookupNamespace(xmlSchemaValidCtxtPtr vctxt,
- const xmlChar *prefix)
- {
- if (vctxt->sax != NULL) {
- int i, j;
- xmlSchemaNodeInfoPtr inode;
- for (i = vctxt->depth; i >= 0; i--) {
- if (vctxt->elemInfos[i]->nbNsBindings != 0) {
- inode = vctxt->elemInfos[i];
- for (j = 0; j < inode->nbNsBindings * 2; j += 2) {
- if (((prefix == NULL) &&
- (inode->nsBindings[j] == NULL)) ||
- ((prefix != NULL) && xmlStrEqual(prefix,
- inode->nsBindings[j]))) {
-
- return (inode->nsBindings[j+1]);
- }
- }
- }
- }
- return (NULL);
- #ifdef LIBXML_READER_ENABLED
- } else if (vctxt->reader != NULL) {
- xmlChar *nsName;
- nsName = xmlTextReaderLookupNamespace(vctxt->reader, prefix);
- if (nsName != NULL) {
- const xmlChar *ret;
- ret = xmlDictLookup(vctxt->dict, nsName, -1);
- xmlFree(nsName);
- return (ret);
- } else
- return (NULL);
- #endif
- } else {
- xmlNsPtr ns;
- if ((vctxt->inode->node == NULL) ||
- (vctxt->inode->node->doc == NULL)) {
- VERROR_INT("xmlSchemaLookupNamespace",
- "no node or node's doc avaliable");
- return (NULL);
- }
- ns = xmlSearchNs(vctxt->inode->node->doc,
- vctxt->inode->node, prefix);
- if (ns != NULL)
- return (ns->href);
- return (NULL);
- }
- }
- static int
- xmlSchemaValidateNotation(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaPtr schema,
- xmlNodePtr node,
- const xmlChar *value,
- xmlSchemaValPtr *val,
- int valNeeded)
- {
- int ret;
- if (vctxt && (vctxt->schema == NULL)) {
- VERROR_INT("xmlSchemaValidateNotation",
- "a schema is needed on the validation context");
- return (-1);
- }
- ret = xmlValidateQName(value, 1);
- if (ret != 0)
- return (ret);
- {
- xmlChar *localName = NULL;
- xmlChar *prefix = NULL;
- localName = xmlSplitQName2(value, &prefix);
- if (prefix != NULL) {
- const xmlChar *nsName = NULL;
- if (vctxt != NULL)
- nsName = xmlSchemaLookupNamespace(vctxt, BAD_CAST prefix);
- else if (node != NULL) {
- xmlNsPtr ns = xmlSearchNs(node->doc, node, prefix);
- if (ns != NULL)
- nsName = ns->href;
- } else {
- xmlFree(prefix);
- xmlFree(localName);
- return (1);
- }
- if (nsName == NULL) {
- xmlFree(prefix);
- xmlFree(localName);
- return (1);
- }
- if (xmlSchemaGetNotation(schema, localName, nsName) != NULL) {
- if ((valNeeded) && (val != NULL)) {
- (*val) = xmlSchemaNewNOTATIONValue(xmlStrdup(localName),
- xmlStrdup(nsName));
- if (*val == NULL)
- ret = -1;
- }
- } else
- ret = 1;
- xmlFree(prefix);
- xmlFree(localName);
- } else {
- if (xmlSchemaGetNotation(schema, value, NULL) != NULL) {
- if (valNeeded && (val != NULL)) {
- (*val) = xmlSchemaNewNOTATIONValue(
- BAD_CAST xmlStrdup(value), NULL);
- if (*val == NULL)
- ret = -1;
- }
- } else
- return (1);
- }
- }
- return (ret);
- }
- static int
- xmlSchemaVAddNodeQName(xmlSchemaValidCtxtPtr vctxt,
- const xmlChar* lname,
- const xmlChar* nsname)
- {
- int i;
- lname = xmlDictLookup(vctxt->dict, lname, -1);
- if (lname == NULL)
- return(-1);
- if (nsname != NULL) {
- nsname = xmlDictLookup(vctxt->dict, nsname, -1);
- if (nsname == NULL)
- return(-1);
- }
- for (i = 0; i < vctxt->nodeQNames->nbItems; i += 2) {
- if ((vctxt->nodeQNames->items [i] == lname) &&
- (vctxt->nodeQNames->items[i +1] == nsname))
-
- return(i);
- }
-
- i = vctxt->nodeQNames->nbItems;
- xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) lname);
- xmlSchemaItemListAdd(vctxt->nodeQNames, (void *) nsname);
- return(i);
- }
- static void
- xmlSchemaAugmentIDC(xmlSchemaIDCPtr idcDef,
- xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaIDCAugPtr aidc;
- aidc = (xmlSchemaIDCAugPtr) xmlMalloc(sizeof(xmlSchemaIDCAug));
- if (aidc == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "xmlSchemaAugmentIDC: allocating an augmented IDC definition",
- NULL);
- return;
- }
- aidc->keyrefDepth = -1;
- aidc->def = idcDef;
- aidc->next = NULL;
- if (vctxt->aidcs == NULL)
- vctxt->aidcs = aidc;
- else {
- aidc->next = vctxt->aidcs;
- vctxt->aidcs = aidc;
- }
-
- if ((vctxt->hasKeyrefs == 0) &&
- (idcDef->type == XML_SCHEMA_TYPE_IDC_KEYREF))
- vctxt->hasKeyrefs = 1;
- }
- static void
- xmlSchemaAugmentImportedIDC(xmlSchemaImportPtr imported, xmlSchemaValidCtxtPtr vctxt) {
- if (imported->schema->idcDef != NULL) {
- xmlHashScan(imported->schema->idcDef ,
- (xmlHashScanner) xmlSchemaAugmentIDC, vctxt);
- }
- }
- static xmlSchemaPSVIIDCBindingPtr
- xmlSchemaIDCNewBinding(xmlSchemaIDCPtr idcDef)
- {
- xmlSchemaPSVIIDCBindingPtr ret;
- ret = (xmlSchemaPSVIIDCBindingPtr) xmlMalloc(
- sizeof(xmlSchemaPSVIIDCBinding));
- if (ret == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating a PSVI IDC binding item", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaPSVIIDCBinding));
- ret->definition = idcDef;
- return (ret);
- }
- static int
- xmlSchemaIDCStoreNodeTableItem(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaPSVIIDCNodePtr item)
- {
-
- if (vctxt->idcNodes == NULL) {
- vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *)
- xmlMalloc(20 * sizeof(xmlSchemaPSVIIDCNodePtr));
- if (vctxt->idcNodes == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating the IDC node table item list", NULL);
- return (-1);
- }
- vctxt->sizeIdcNodes = 20;
- } else if (vctxt->sizeIdcNodes <= vctxt->nbIdcNodes) {
- vctxt->sizeIdcNodes *= 2;
- vctxt->idcNodes = (xmlSchemaPSVIIDCNodePtr *)
- xmlRealloc(vctxt->idcNodes, vctxt->sizeIdcNodes *
- sizeof(xmlSchemaPSVIIDCNodePtr));
- if (vctxt->idcNodes == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "re-allocating the IDC node table item list", NULL);
- return (-1);
- }
- }
- vctxt->idcNodes[vctxt->nbIdcNodes++] = item;
- return (0);
- }
- static int
- xmlSchemaIDCStoreKey(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaPSVIIDCKeyPtr key)
- {
-
- if (vctxt->idcKeys == NULL) {
- vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *)
- xmlMalloc(40 * sizeof(xmlSchemaPSVIIDCKeyPtr));
- if (vctxt->idcKeys == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating the IDC key storage list", NULL);
- return (-1);
- }
- vctxt->sizeIdcKeys = 40;
- } else if (vctxt->sizeIdcKeys <= vctxt->nbIdcKeys) {
- vctxt->sizeIdcKeys *= 2;
- vctxt->idcKeys = (xmlSchemaPSVIIDCKeyPtr *)
- xmlRealloc(vctxt->idcKeys, vctxt->sizeIdcKeys *
- sizeof(xmlSchemaPSVIIDCKeyPtr));
- if (vctxt->idcKeys == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "re-allocating the IDC key storage list", NULL);
- return (-1);
- }
- }
- vctxt->idcKeys[vctxt->nbIdcKeys++] = key;
- return (0);
- }
- static int
- xmlSchemaIDCAppendNodeTableItem(xmlSchemaPSVIIDCBindingPtr bind,
- xmlSchemaPSVIIDCNodePtr ntItem)
- {
- if (bind->nodeTable == NULL) {
- bind->sizeNodes = 10;
- bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
- xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr));
- if (bind->nodeTable == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating an array of IDC node-table items", NULL);
- return(-1);
- }
- } else if (bind->sizeNodes <= bind->nbNodes) {
- bind->sizeNodes *= 2;
- bind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
- xmlRealloc(bind->nodeTable, bind->sizeNodes *
- sizeof(xmlSchemaPSVIIDCNodePtr));
- if (bind->nodeTable == NULL) {
- xmlSchemaVErrMemory(NULL,
- "re-allocating an array of IDC node-table items", NULL);
- return(-1);
- }
- }
- bind->nodeTable[bind->nbNodes++] = ntItem;
- return(0);
- }
- static xmlSchemaPSVIIDCBindingPtr
- xmlSchemaIDCAcquireBinding(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaIDCMatcherPtr matcher)
- {
- xmlSchemaNodeInfoPtr ielem;
- ielem = vctxt->elemInfos[matcher->depth];
- if (ielem->idcTable == NULL) {
- ielem->idcTable = xmlSchemaIDCNewBinding(matcher->aidc->def);
- if (ielem->idcTable == NULL)
- return (NULL);
- return(ielem->idcTable);
- } else {
- xmlSchemaPSVIIDCBindingPtr bind = NULL;
- bind = ielem->idcTable;
- do {
- if (bind->definition == matcher->aidc->def)
- return(bind);
- if (bind->next == NULL) {
- bind->next = xmlSchemaIDCNewBinding(matcher->aidc->def);
- if (bind->next == NULL)
- return (NULL);
- return(bind->next);
- }
- bind = bind->next;
- } while (bind != NULL);
- }
- return (NULL);
- }
- static xmlSchemaItemListPtr
- xmlSchemaIDCAcquireTargetList(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
- xmlSchemaIDCMatcherPtr matcher)
- {
- if (matcher->targets == NULL)
- matcher->targets = xmlSchemaItemListCreate();
- return(matcher->targets);
- }
- static void
- xmlSchemaIDCFreeKey(xmlSchemaPSVIIDCKeyPtr key)
- {
- if (key->val != NULL)
- xmlSchemaFreeValue(key->val);
- xmlFree(key);
- }
- static void
- xmlSchemaIDCFreeBinding(xmlSchemaPSVIIDCBindingPtr bind)
- {
- if (bind->nodeTable != NULL)
- xmlFree(bind->nodeTable);
- if (bind->dupls != NULL)
- xmlSchemaItemListFree(bind->dupls);
- xmlFree(bind);
- }
- static void
- xmlSchemaIDCFreeIDCTable(xmlSchemaPSVIIDCBindingPtr bind)
- {
- xmlSchemaPSVIIDCBindingPtr prev;
- while (bind != NULL) {
- prev = bind;
- bind = bind->next;
- xmlSchemaIDCFreeBinding(prev);
- }
- }
- static void
- xmlSchemaIDCFreeMatcherList(xmlSchemaIDCMatcherPtr matcher)
- {
- xmlSchemaIDCMatcherPtr next;
- while (matcher != NULL) {
- next = matcher->next;
- if (matcher->keySeqs != NULL) {
- int i;
- for (i = 0; i < matcher->sizeKeySeqs; i++)
- if (matcher->keySeqs[i] != NULL)
- xmlFree(matcher->keySeqs[i]);
- xmlFree(matcher->keySeqs);
- }
- if (matcher->targets != NULL) {
- if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) {
- int i;
- xmlSchemaPSVIIDCNodePtr idcNode;
-
- for (i = 0; i < matcher->targets->nbItems; i++) {
- idcNode =
- (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i];
- xmlFree(idcNode->keys);
- xmlFree(idcNode);
- }
- }
- xmlSchemaItemListFree(matcher->targets);
- }
- xmlFree(matcher);
- matcher = next;
- }
- }
- static void
- xmlSchemaIDCReleaseMatcherList(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaIDCMatcherPtr matcher)
- {
- xmlSchemaIDCMatcherPtr next;
- while (matcher != NULL) {
- next = matcher->next;
- if (matcher->keySeqs != NULL) {
- int i;
-
- for (i = 0; i < matcher->sizeKeySeqs; i++)
- if (matcher->keySeqs[i] != NULL) {
- xmlFree(matcher->keySeqs[i]);
- matcher->keySeqs[i] = NULL;
- }
- }
- if (matcher->targets) {
- if (matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) {
- int i;
- xmlSchemaPSVIIDCNodePtr idcNode;
-
- for (i = 0; i < matcher->targets->nbItems; i++) {
- idcNode =
- (xmlSchemaPSVIIDCNodePtr) matcher->targets->items[i];
- xmlFree(idcNode->keys);
- xmlFree(idcNode);
- }
- }
- xmlSchemaItemListFree(matcher->targets);
- matcher->targets = NULL;
- }
- matcher->next = NULL;
-
- if (vctxt->idcMatcherCache != NULL)
- matcher->nextCached = vctxt->idcMatcherCache;
- vctxt->idcMatcherCache = matcher;
- matcher = next;
- }
- }
- static int
- xmlSchemaIDCAddStateObject(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaIDCMatcherPtr matcher,
- xmlSchemaIDCSelectPtr sel,
- int type)
- {
- xmlSchemaIDCStateObjPtr sto;
-
- if (vctxt->xpathStatePool != NULL) {
- sto = vctxt->xpathStatePool;
- vctxt->xpathStatePool = sto->next;
- sto->next = NULL;
- } else {
-
- sto = (xmlSchemaIDCStateObjPtr) xmlMalloc(sizeof(xmlSchemaIDCStateObj));
- if (sto == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating an IDC state object", NULL);
- return (-1);
- }
- memset(sto, 0, sizeof(xmlSchemaIDCStateObj));
- }
-
- if (vctxt->xpathStates != NULL)
- sto->next = vctxt->xpathStates;
- vctxt->xpathStates = sto;
-
- if (sto->xpathCtxt != NULL)
- xmlFreeStreamCtxt((xmlStreamCtxtPtr) sto->xpathCtxt);
-
- sto->xpathCtxt = (void *) xmlPatternGetStreamCtxt(
- (xmlPatternPtr) sel->xpathComp);
- if (sto->xpathCtxt == NULL) {
- VERROR_INT("xmlSchemaIDCAddStateObject",
- "failed to create an XPath validation context");
- return (-1);
- }
- sto->type = type;
- sto->depth = vctxt->depth;
- sto->matcher = matcher;
- sto->sel = sel;
- sto->nbHistory = 0;
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: STO push '%s'\n",
- sto->sel->xpath);
- #endif
- return (0);
- }
- static int
- xmlSchemaXPathEvaluate(xmlSchemaValidCtxtPtr vctxt,
- xmlElementType nodeType)
- {
- xmlSchemaIDCStateObjPtr sto, head = NULL, first;
- int res, resolved = 0, depth = vctxt->depth;
- if (vctxt->xpathStates == NULL)
- return (0);
- if (nodeType == XML_ATTRIBUTE_NODE)
- depth++;
- #ifdef DEBUG_IDC
- {
- xmlChar *str = NULL;
- xmlGenericError(xmlGenericErrorContext,
- "IDC: EVAL on %s, depth %d, type %d\n",
- xmlSchemaFormatQName(&str, vctxt->inode->nsName,
- vctxt->inode->localName), depth, nodeType);
- FREE_AND_NULL(str)
- }
- #endif
-
- first = vctxt->xpathStates;
- sto = first;
- while (sto != head) {
- #ifdef DEBUG_IDC
- if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR)
- xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] selector '%s'\n",
- sto->matcher->aidc->def->name, sto->sel->xpath);
- else
- xmlGenericError(xmlGenericErrorContext, "IDC: ['%s'] field '%s'\n",
- sto->matcher->aidc->def->name, sto->sel->xpath);
- #endif
- if (nodeType == XML_ELEMENT_NODE)
- res = xmlStreamPush((xmlStreamCtxtPtr) sto->xpathCtxt,
- vctxt->inode->localName, vctxt->inode->nsName);
- else
- res = xmlStreamPushAttr((xmlStreamCtxtPtr) sto->xpathCtxt,
- vctxt->inode->localName, vctxt->inode->nsName);
- if (res == -1) {
- VERROR_INT("xmlSchemaXPathEvaluate",
- "calling xmlStreamPush()");
- return (-1);
- }
- if (res == 0)
- goto next_sto;
-
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: "
- "MATCH\n");
- #endif
-
- if (sto->history == NULL) {
- sto->history = (int *) xmlMalloc(5 * sizeof(int));
- if (sto->history == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating the state object history", NULL);
- return(-1);
- }
- sto->sizeHistory = 5;
- } else if (sto->sizeHistory <= sto->nbHistory) {
- sto->sizeHistory *= 2;
- sto->history = (int *) xmlRealloc(sto->history,
- sto->sizeHistory * sizeof(int));
- if (sto->history == NULL) {
- xmlSchemaVErrMemory(NULL,
- "re-allocating the state object history", NULL);
- return(-1);
- }
- }
- sto->history[sto->nbHistory++] = depth;
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: push match '%d'\n",
- vctxt->depth);
- #endif
- if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) {
- xmlSchemaIDCSelectPtr sel;
-
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: "
- "activating field states\n");
- #endif
- sel = sto->matcher->aidc->def->fields;
- while (sel != NULL) {
- if (xmlSchemaIDCAddStateObject(vctxt, sto->matcher,
- sel, XPATH_STATE_OBJ_TYPE_IDC_FIELD) == -1)
- return (-1);
- sel = sel->next;
- }
- } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) {
-
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext,
- "IDC: key found\n");
- #endif
-
- if (resolved == 0) {
- if ((vctxt->inode->flags &
- XML_SCHEMA_NODE_INFO_VALUE_NEEDED) == 0)
- vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED;
- }
- resolved++;
- }
- next_sto:
- if (sto->next == NULL) {
-
- head = first;
- sto = vctxt->xpathStates;
- } else
- sto = sto->next;
- }
- return (resolved);
- }
- static const xmlChar *
- xmlSchemaFormatIDCKeySequence(xmlSchemaValidCtxtPtr vctxt,
- xmlChar **buf,
- xmlSchemaPSVIIDCKeyPtr *seq,
- int count)
- {
- int i, res;
- xmlChar *value = NULL;
- *buf = xmlStrdup(BAD_CAST "[");
- for (i = 0; i < count; i++) {
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- res = xmlSchemaGetCanonValueWhtspExt(seq[i]->val,
- xmlSchemaGetWhiteSpaceFacetValue(seq[i]->type),
- &value);
- if (res == 0)
- *buf = xmlStrcat(*buf, BAD_CAST value);
- else {
- VERROR_INT("xmlSchemaFormatIDCKeySequence",
- "failed to compute a canonical value");
- *buf = xmlStrcat(*buf, BAD_CAST "???");
- }
- if (i < count -1)
- *buf = xmlStrcat(*buf, BAD_CAST "', ");
- else
- *buf = xmlStrcat(*buf, BAD_CAST "'");
- if (value != NULL) {
- xmlFree(value);
- value = NULL;
- }
- }
- *buf = xmlStrcat(*buf, BAD_CAST "]");
- return (BAD_CAST *buf);
- }
- static int
- xmlSchemaXPathPop(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaIDCStateObjPtr sto;
- int res;
- if (vctxt->xpathStates == NULL)
- return(0);
- sto = vctxt->xpathStates;
- do {
- res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt);
- if (res == -1)
- return (-1);
- sto = sto->next;
- } while (sto != NULL);
- return(0);
- }
- static int
- xmlSchemaXPathProcessHistory(xmlSchemaValidCtxtPtr vctxt,
- int depth)
- {
- xmlSchemaIDCStateObjPtr sto, nextsto;
- int res, matchDepth;
- xmlSchemaPSVIIDCKeyPtr key = NULL;
- xmlSchemaTypePtr type = vctxt->inode->typeDef, simpleType = NULL;
- if (vctxt->xpathStates == NULL)
- return (0);
- sto = vctxt->xpathStates;
- #ifdef DEBUG_IDC
- {
- xmlChar *str = NULL;
- xmlGenericError(xmlGenericErrorContext,
- "IDC: BACK on %s, depth %d\n",
- xmlSchemaFormatQName(&str, vctxt->inode->nsName,
- vctxt->inode->localName), vctxt->depth);
- FREE_AND_NULL(str)
- }
- #endif
-
- while (sto != NULL) {
- res = xmlStreamPop((xmlStreamCtxtPtr) sto->xpathCtxt);
- if (res == -1) {
- VERROR_INT("xmlSchemaXPathProcessHistory",
- "calling xmlStreamPop()");
- return (-1);
- }
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: stream pop '%s'\n",
- sto->sel->xpath);
- #endif
- if (sto->nbHistory == 0)
- goto deregister_check;
- matchDepth = sto->history[sto->nbHistory -1];
-
- if (matchDepth != depth) {
- sto = sto->next;
- continue;
- }
- if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_FIELD) {
-
- if (WXS_IS_COMPLEX(type)) {
- if (WXS_HAS_SIMPLE_CONTENT(type)) {
-
- simpleType = type->contentTypeDef;
- if (simpleType == NULL) {
- VERROR_INT("xmlSchemaXPathProcessHistory",
- "field resolves to a CT with simple content "
- "but the CT is missing the ST definition");
- return (-1);
- }
- } else
- simpleType = NULL;
- } else
- simpleType = type;
- if (simpleType == NULL) {
- xmlChar *str = NULL;
-
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_IDC, NULL,
- WXS_BASIC_CAST sto->matcher->aidc->def,
- "The XPath '%s' of a field of %s does evaluate to a node of "
- "non-simple type",
- sto->sel->xpath,
- xmlSchemaGetIDCDesignation(&str, sto->matcher->aidc->def));
- FREE_AND_NULL(str);
- sto->nbHistory--;
- goto deregister_check;
- }
- if ((key == NULL) && (vctxt->inode->val == NULL)) {
-
- VERROR(XML_SCHEMAV_CVC_IDC,
- WXS_BASIC_CAST sto->matcher->aidc->def,
- "Warning: No precomputed value available, the value "
- "was either invalid or something strange happend");
- sto->nbHistory--;
- goto deregister_check;
- } else {
- xmlSchemaIDCMatcherPtr matcher = sto->matcher;
- xmlSchemaPSVIIDCKeyPtr *keySeq;
- int pos, idx;
-
- pos = sto->depth - matcher->depth;
- idx = sto->sel->index;
-
- if (matcher->keySeqs == NULL) {
- if (pos > 9)
- matcher->sizeKeySeqs = pos * 2;
- else
- matcher->sizeKeySeqs = 10;
- matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **)
- xmlMalloc(matcher->sizeKeySeqs *
- sizeof(xmlSchemaPSVIIDCKeyPtr *));
- if (matcher->keySeqs == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating an array of key-sequences",
- NULL);
- return(-1);
- }
- memset(matcher->keySeqs, 0,
- matcher->sizeKeySeqs *
- sizeof(xmlSchemaPSVIIDCKeyPtr *));
- } else if (pos >= matcher->sizeKeySeqs) {
- int i = matcher->sizeKeySeqs;
- matcher->sizeKeySeqs *= 2;
- matcher->keySeqs = (xmlSchemaPSVIIDCKeyPtr **)
- xmlRealloc(matcher->keySeqs,
- matcher->sizeKeySeqs *
- sizeof(xmlSchemaPSVIIDCKeyPtr *));
- if (matcher->keySeqs == NULL) {
- xmlSchemaVErrMemory(NULL,
- "reallocating an array of key-sequences",
- NULL);
- return (-1);
- }
-
- for (; i < matcher->sizeKeySeqs; i++)
- matcher->keySeqs[i] = NULL;
- }
-
- keySeq = matcher->keySeqs[pos];
- if (keySeq == NULL) {
- goto create_sequence;
- } else if (keySeq[idx] != NULL) {
- xmlChar *str = NULL;
-
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_IDC, NULL,
- WXS_BASIC_CAST matcher->aidc->def,
- "The XPath '%s' of a field of %s evaluates to a "
- "node-set with more than one member",
- sto->sel->xpath,
- xmlSchemaGetIDCDesignation(&str, matcher->aidc->def));
- FREE_AND_NULL(str);
- sto->nbHistory--;
- goto deregister_check;
- } else
- goto create_key;
- create_sequence:
-
- keySeq = (xmlSchemaPSVIIDCKeyPtr *) xmlMalloc(
- matcher->aidc->def->nbFields *
- sizeof(xmlSchemaPSVIIDCKeyPtr));
- if (keySeq == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating an IDC key-sequence", NULL);
- return(-1);
- }
- memset(keySeq, 0, matcher->aidc->def->nbFields *
- sizeof(xmlSchemaPSVIIDCKeyPtr));
- matcher->keySeqs[pos] = keySeq;
- create_key:
-
- if (key == NULL) {
- key = (xmlSchemaPSVIIDCKeyPtr) xmlMalloc(
- sizeof(xmlSchemaPSVIIDCKey));
- if (key == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating a IDC key", NULL);
- xmlFree(keySeq);
- matcher->keySeqs[pos] = NULL;
- return(-1);
- }
-
- key->type = simpleType;
- key->val = vctxt->inode->val;
- vctxt->inode->val = NULL;
-
- if (xmlSchemaIDCStoreKey(vctxt, key) == -1) {
- xmlSchemaIDCFreeKey(key);
- return (-1);
- }
- }
- keySeq[idx] = key;
- }
- } else if (sto->type == XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) {
- xmlSchemaPSVIIDCKeyPtr **keySeq = NULL;
-
- xmlSchemaPSVIIDCNodePtr ntItem;
- xmlSchemaIDCMatcherPtr matcher;
- xmlSchemaIDCPtr idc;
- xmlSchemaItemListPtr targets;
- int pos, i, j, nbKeys;
-
- matcher = sto->matcher;
- idc = matcher->aidc->def;
- nbKeys = idc->nbFields;
- pos = depth - matcher->depth;
-
- if ((matcher->keySeqs == NULL) ||
- (matcher->sizeKeySeqs <= pos)) {
- if (idc->type == XML_SCHEMA_TYPE_IDC_KEY)
- goto selector_key_error;
- else
- goto selector_leave;
- }
- keySeq = &(matcher->keySeqs[pos]);
- if (*keySeq == NULL) {
- if (idc->type == XML_SCHEMA_TYPE_IDC_KEY)
- goto selector_key_error;
- else
- goto selector_leave;
- }
- for (i = 0; i < nbKeys; i++) {
- if ((*keySeq)[i] == NULL) {
-
- if (idc->type == XML_SCHEMA_TYPE_IDC_KEY) {
-
- goto selector_key_error;
- }
- goto selector_leave;
- }
- }
-
-
- #if 0
- bind = xmlSchemaIDCAcquireBinding(vctxt, matcher);
- #endif
- targets = xmlSchemaIDCAcquireTargetList(vctxt, matcher);
- if ((idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) &&
- (targets->nbItems != 0)) {
- xmlSchemaPSVIIDCKeyPtr ckey, bkey, *bkeySeq;
- i = 0;
- res = 0;
-
- do {
- bkeySeq =
- ((xmlSchemaPSVIIDCNodePtr) targets->items[i])->keys;
- for (j = 0; j < nbKeys; j++) {
- ckey = (*keySeq)[j];
- bkey = bkeySeq[j];
- res = xmlSchemaAreValuesEqual(ckey->val, bkey->val);
- if (res == -1) {
- return (-1);
- } else if (res == 0) {
-
- break;
- }
- }
- if (res == 1) {
-
- break;
- }
- i++;
- } while (i < targets->nbItems);
- if (i != targets->nbItems) {
- xmlChar *str = NULL, *strB = NULL;
-
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_IDC, NULL,
- WXS_BASIC_CAST idc,
- "Duplicate key-sequence %s in %s",
- xmlSchemaFormatIDCKeySequence(vctxt, &str,
- (*keySeq), nbKeys),
- xmlSchemaGetIDCDesignation(&strB, idc));
- FREE_AND_NULL(str);
- FREE_AND_NULL(strB);
- goto selector_leave;
- }
- }
-
- ntItem = (xmlSchemaPSVIIDCNodePtr) xmlMalloc(
- sizeof(xmlSchemaPSVIIDCNode));
- if (ntItem == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating an IDC node-table item", NULL);
- xmlFree(*keySeq);
- *keySeq = NULL;
- return(-1);
- }
- memset(ntItem, 0, sizeof(xmlSchemaPSVIIDCNode));
-
- if (idc->type != XML_SCHEMA_TYPE_IDC_KEYREF) {
- if (xmlSchemaIDCStoreNodeTableItem(vctxt, ntItem) == -1) {
- xmlFree(ntItem);
- xmlFree(*keySeq);
- *keySeq = NULL;
- return (-1);
- }
- ntItem->nodeQNameID = -1;
- } else {
-
- ntItem->nodeQNameID = xmlSchemaVAddNodeQName(vctxt,
- vctxt->inode->localName, vctxt->inode->nsName);
- if (ntItem->nodeQNameID == -1) {
- xmlFree(ntItem);
- xmlFree(*keySeq);
- *keySeq = NULL;
- return (-1);
- }
- }
-
- ntItem->node = vctxt->node;
- ntItem->nodeLine = vctxt->inode->nodeLine;
- ntItem->keys = *keySeq;
- *keySeq = NULL;
- #if 0
- if (xmlSchemaIDCAppendNodeTableItem(bind, ntItem) == -1)
- #endif
- if (xmlSchemaItemListAdd(targets, ntItem) == -1) {
- if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
-
- xmlFree(ntItem->keys);
- xmlFree(ntItem);
- }
- return (-1);
- }
- goto selector_leave;
- selector_key_error:
- {
- xmlChar *str = NULL;
-
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_IDC, NULL,
- WXS_BASIC_CAST idc,
- "Not all fields of %s evaluate to a node",
- xmlSchemaGetIDCDesignation(&str, idc), NULL);
- FREE_AND_NULL(str);
- }
- selector_leave:
-
- if ((keySeq != NULL) && (*keySeq != NULL)) {
- xmlFree(*keySeq);
- *keySeq = NULL;
- }
- }
- sto->nbHistory--;
- deregister_check:
-
- if ((sto->nbHistory == 0) && (sto->depth == depth)) {
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: STO pop '%s'\n",
- sto->sel->xpath);
- #endif
- if (vctxt->xpathStates != sto) {
- VERROR_INT("xmlSchemaXPathProcessHistory",
- "The state object to be removed is not the first "
- "in the list");
- }
- nextsto = sto->next;
-
- vctxt->xpathStates = sto->next;
- sto->next = vctxt->xpathStatePool;
-
- vctxt->xpathStatePool = sto;
- sto = nextsto;
- } else
- sto = sto->next;
- }
- return (0);
- }
- static int
- xmlSchemaIDCRegisterMatchers(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaElementPtr elemDecl)
- {
- xmlSchemaIDCMatcherPtr matcher, last = NULL;
- xmlSchemaIDCPtr idc, refIdc;
- xmlSchemaIDCAugPtr aidc;
- idc = (xmlSchemaIDCPtr) elemDecl->idcs;
- if (idc == NULL)
- return (0);
- #ifdef DEBUG_IDC
- {
- xmlChar *str = NULL;
- xmlGenericError(xmlGenericErrorContext,
- "IDC: REGISTER on %s, depth %d\n",
- (char *) xmlSchemaFormatQName(&str, vctxt->inode->nsName,
- vctxt->inode->localName), vctxt->depth);
- FREE_AND_NULL(str)
- }
- #endif
- if (vctxt->inode->idcMatchers != NULL) {
- VERROR_INT("xmlSchemaIDCRegisterMatchers",
- "The chain of IDC matchers is expected to be empty");
- return (-1);
- }
- do {
- if (idc->type == XML_SCHEMA_TYPE_IDC_KEYREF) {
-
- refIdc = (xmlSchemaIDCPtr) idc->ref->item;
- if (refIdc != NULL) {
-
- vctxt->inode->hasKeyrefs = 1;
-
- aidc = vctxt->aidcs;
- while (aidc != NULL) {
- if (aidc->def == refIdc)
- break;
- aidc = aidc->next;
- }
- if (aidc == NULL) {
- VERROR_INT("xmlSchemaIDCRegisterMatchers",
- "Could not find an augmented IDC item for an IDC "
- "definition");
- return (-1);
- }
- if ((aidc->keyrefDepth == -1) ||
- (vctxt->depth < aidc->keyrefDepth))
- aidc->keyrefDepth = vctxt->depth;
- }
- }
-
- aidc = vctxt->aidcs;
- while (aidc != NULL) {
- if (aidc->def == idc)
- break;
- aidc = aidc->next;
- }
- if (aidc == NULL) {
- VERROR_INT("xmlSchemaIDCRegisterMatchers",
- "Could not find an augmented IDC item for an IDC definition");
- return (-1);
- }
-
- if (vctxt->idcMatcherCache != NULL) {
-
- matcher = vctxt->idcMatcherCache;
- vctxt->idcMatcherCache = matcher->nextCached;
- matcher->nextCached = NULL;
- } else {
- matcher = (xmlSchemaIDCMatcherPtr)
- xmlMalloc(sizeof(xmlSchemaIDCMatcher));
- if (matcher == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating an IDC matcher", NULL);
- return (-1);
- }
- memset(matcher, 0, sizeof(xmlSchemaIDCMatcher));
- }
- if (last == NULL)
- vctxt->inode->idcMatchers = matcher;
- else
- last->next = matcher;
- last = matcher;
- matcher->type = IDC_MATCHER;
- matcher->depth = vctxt->depth;
- matcher->aidc = aidc;
- matcher->idcType = aidc->def->type;
- #ifdef DEBUG_IDC
- xmlGenericError(xmlGenericErrorContext, "IDC: register matcher\n");
- #endif
-
- if (xmlSchemaIDCAddStateObject(vctxt, matcher,
- idc->selector, XPATH_STATE_OBJ_TYPE_IDC_SELECTOR) == -1)
- return (-1);
- idc = idc->next;
- } while (idc != NULL);
- return (0);
- }
- static int
- xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaNodeInfoPtr ielem)
- {
- xmlSchemaPSVIIDCBindingPtr bind;
- int res, i, j, k, nbTargets, nbFields, nbDupls, nbNodeTable;
- xmlSchemaPSVIIDCKeyPtr *keys, *ntkeys;
- xmlSchemaPSVIIDCNodePtr *targets, *dupls;
- xmlSchemaIDCMatcherPtr matcher = ielem->idcMatchers;
-
- while (matcher != NULL) {
-
- if ((matcher->aidc->def->type == XML_SCHEMA_TYPE_IDC_KEYREF) ||
- WXS_ILIST_IS_EMPTY(matcher->targets))
- {
- matcher = matcher->next;
- continue;
- }
-
- if ((! vctxt->createIDCNodeTables) &&
- ((matcher->aidc->keyrefDepth == -1) ||
- (matcher->aidc->keyrefDepth > vctxt->depth)))
- {
- matcher = matcher->next;
- continue;
- }
-
- bind = xmlSchemaIDCAcquireBinding(vctxt, matcher);
- if (! WXS_ILIST_IS_EMPTY(bind->dupls)) {
- dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items;
- nbDupls = bind->dupls->nbItems;
- } else {
- dupls = NULL;
- nbDupls = 0;
- }
- if (bind->nodeTable != NULL) {
- nbNodeTable = bind->nbNodes;
- } else {
- nbNodeTable = 0;
- }
- if ((nbNodeTable == 0) && (nbDupls == 0)) {
-
- bind->nodeTable =
- (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items;
- bind->sizeNodes = matcher->targets->sizeItems;
- bind->nbNodes = matcher->targets->nbItems;
- matcher->targets->items = NULL;
- matcher->targets->sizeItems = 0;
- matcher->targets->nbItems = 0;
- } else {
-
- nbTargets = matcher->targets->nbItems;
- targets = (xmlSchemaPSVIIDCNodePtr *) matcher->targets->items;
- nbFields = matcher->aidc->def->nbFields;
- i = 0;
- do {
- keys = targets[i]->keys;
- if (nbDupls) {
-
- j = 0;
- do {
- if (nbFields == 1) {
- res = xmlSchemaAreValuesEqual(keys[0]->val,
- dupls[j]->keys[0]->val);
- if (res == -1)
- goto internal_error;
- if (res == 1) {
-
- goto next_target;
- }
- } else {
- res = 0;
- ntkeys = dupls[j]->keys;
- for (k = 0; k < nbFields; k++) {
- res = xmlSchemaAreValuesEqual(keys[k]->val,
- ntkeys[k]->val);
- if (res == -1)
- goto internal_error;
- if (res == 0) {
-
- break;
- }
- }
- if (res == 1) {
-
- goto next_target;
- }
- }
- j++;
- } while (j < nbDupls);
- }
- if (nbNodeTable) {
- j = 0;
- do {
- if (nbFields == 1) {
- res = xmlSchemaAreValuesEqual(keys[0]->val,
- bind->nodeTable[j]->keys[0]->val);
- if (res == -1)
- goto internal_error;
- if (res == 0) {
-
- goto next_node_table_entry;
- }
- } else {
- res = 0;
- ntkeys = bind->nodeTable[j]->keys;
- for (k = 0; k < nbFields; k++) {
- res = xmlSchemaAreValuesEqual(keys[k]->val,
- ntkeys[k]->val);
- if (res == -1)
- goto internal_error;
- if (res == 0) {
-
- goto next_node_table_entry;
- }
- }
- }
-
- if (bind->dupls == NULL) {
- bind->dupls = xmlSchemaItemListCreate();
- if (bind->dupls == NULL)
- goto internal_error;
- }
- if (xmlSchemaItemListAdd(bind->dupls, bind->nodeTable[j]) == -1)
- goto internal_error;
-
- bind->nodeTable[j] = bind->nodeTable[bind->nbNodes -1];
- bind->nbNodes--;
- goto next_target;
- next_node_table_entry:
- j++;
- } while (j < nbNodeTable);
- }
-
- if (xmlSchemaIDCAppendNodeTableItem(bind, targets[i]) == -1)
- goto internal_error;
- next_target:
- i++;
- } while (i < nbTargets);
- }
- matcher = matcher->next;
- }
- return(0);
- internal_error:
- return(-1);
- }
- static int
- xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaPSVIIDCBindingPtr bind;
- xmlSchemaPSVIIDCBindingPtr *parTable, parBind = NULL;
- xmlSchemaPSVIIDCNodePtr node, parNode = NULL, *dupls, *parNodes;
- xmlSchemaIDCAugPtr aidc;
- int i, j, k, ret = 0, nbFields, oldNum, oldDupls;
- bind = vctxt->inode->idcTable;
- if (bind == NULL) {
-
- return (0);
- }
- parTable = &(vctxt->elemInfos[vctxt->depth -1]->idcTable);
-
- while (bind != NULL) {
- if ((bind->nbNodes == 0) && WXS_ILIST_IS_EMPTY(bind->dupls))
- goto next_binding;
-
- if (! vctxt->createIDCNodeTables) {
- aidc = vctxt->aidcs;
- do {
- if (aidc->def == bind->definition) {
- if ((aidc->keyrefDepth == -1) ||
- (aidc->keyrefDepth >= vctxt->depth)) {
- goto next_binding;
- }
- break;
- }
- aidc = aidc->next;
- } while (aidc != NULL);
- }
- if (parTable != NULL)
- parBind = *parTable;
-
- while (parBind != NULL) {
- if (parBind->definition == bind->definition)
- break;
- parBind = parBind->next;
- }
- if (parBind != NULL) {
-
- oldNum = parBind->nbNodes;
- if (! WXS_ILIST_IS_EMPTY(parBind->dupls)) {
- oldDupls = parBind->dupls->nbItems;
- dupls = (xmlSchemaPSVIIDCNodePtr *) parBind->dupls->items;
- } else {
- dupls = NULL;
- oldDupls = 0;
- }
- parNodes = parBind->nodeTable;
- nbFields = bind->definition->nbFields;
- for (i = 0; i < bind->nbNodes; i++) {
- node = bind->nodeTable[i];
- if (node == NULL)
- continue;
-
- if (oldDupls) {
- j = 0;
- while (j < oldDupls) {
- if (nbFields == 1) {
- ret = xmlSchemaAreValuesEqual(
- node->keys[0]->val,
- dupls[j]->keys[0]->val);
- if (ret == -1)
- goto internal_error;
- if (ret == 0) {
- j++;
- continue;
- }
- } else {
- parNode = dupls[j];
- for (k = 0; k < nbFields; k++) {
- ret = xmlSchemaAreValuesEqual(
- node->keys[k]->val,
- parNode->keys[k]->val);
- if (ret == -1)
- goto internal_error;
- if (ret == 0)
- break;
- }
- }
- if (ret == 1)
-
- break;
- j++;
- }
- if (j != oldDupls) {
-
- continue;
- }
- }
-
- if (oldNum) {
- j = 0;
- while (j < oldNum) {
- parNode = parNodes[j];
- if (nbFields == 1) {
- ret = xmlSchemaAreValuesEqual(
- node->keys[0]->val,
- parNode->keys[0]->val);
- if (ret == -1)
- goto internal_error;
- if (ret == 0) {
- j++;
- continue;
- }
- } else {
- for (k = 0; k < nbFields; k++) {
- ret = xmlSchemaAreValuesEqual(
- node->keys[k]->val,
- parNode->keys[k]->val);
- if (ret == -1)
- goto internal_error;
- if (ret == 0)
- break;
- }
- }
- if (ret == 1)
-
- break;
- j++;
- }
- if (j != oldNum) {
-
- oldNum--;
- parBind->nbNodes--;
-
- parNodes[j] = parNodes[oldNum];
- if (parBind->nbNodes != oldNum) {
-
- parNodes[oldNum] =
- parNodes[parBind->nbNodes];
- }
- if (parBind->dupls == NULL) {
- parBind->dupls = xmlSchemaItemListCreate();
- if (parBind->dupls == NULL)
- goto internal_error;
- }
- xmlSchemaItemListAdd(parBind->dupls, parNode);
- } else {
-
- if (parBind->nodeTable == NULL) {
- parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
- xmlMalloc(10 * sizeof(xmlSchemaPSVIIDCNodePtr));
- if (parBind->nodeTable == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating IDC list of node-table items", NULL);
- goto internal_error;
- }
- parBind->sizeNodes = 1;
- } else if (parBind->nbNodes >= parBind->sizeNodes) {
- parBind->sizeNodes *= 2;
- parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
- xmlRealloc(parBind->nodeTable, parBind->sizeNodes *
- sizeof(xmlSchemaPSVIIDCNodePtr));
- if (parBind->nodeTable == NULL) {
- xmlSchemaVErrMemory(NULL,
- "re-allocating IDC list of node-table items", NULL);
- goto internal_error;
- }
- }
- parNodes = parBind->nodeTable;
-
- parNodes[parBind->nbNodes++] = node;
- }
- }
- }
- } else {
-
- parBind = xmlSchemaIDCNewBinding(bind->definition);
- if (parBind == NULL)
- goto internal_error;
-
- if (bind->nbNodes != 0) {
-
- if (! vctxt->psviExposeIDCNodeTables) {
-
- parBind->nodeTable = bind->nodeTable;
- bind->nodeTable = NULL;
- parBind->sizeNodes = bind->sizeNodes;
- bind->sizeNodes = 0;
- parBind->nbNodes = bind->nbNodes;
- bind->nbNodes = 0;
- } else {
-
- parBind->nodeTable = (xmlSchemaPSVIIDCNodePtr *)
- xmlMalloc(bind->nbNodes *
- sizeof(xmlSchemaPSVIIDCNodePtr));
- if (parBind->nodeTable == NULL) {
- xmlSchemaVErrMemory(NULL,
- "allocating an array of IDC node-table "
- "items", NULL);
- xmlSchemaIDCFreeBinding(parBind);
- goto internal_error;
- }
- parBind->sizeNodes = bind->nbNodes;
- parBind->nbNodes = bind->nbNodes;
- memcpy(parBind->nodeTable, bind->nodeTable,
- bind->nbNodes * sizeof(xmlSchemaPSVIIDCNodePtr));
- }
- }
- if (bind->dupls) {
-
- if (parBind->dupls != NULL)
- xmlSchemaItemListFree(parBind->dupls);
- parBind->dupls = bind->dupls;
- bind->dupls = NULL;
- }
- if (parTable != NULL) {
- if (*parTable == NULL)
- *parTable = parBind;
- else {
- parBind->next = *parTable;
- *parTable = parBind;
- }
- }
- }
- next_binding:
- bind = bind->next;
- }
- return (0);
- internal_error:
- return(-1);
- }
- static int
- xmlSchemaCheckCVCIDCKeyRef(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaIDCMatcherPtr matcher;
- xmlSchemaPSVIIDCBindingPtr bind;
- matcher = vctxt->inode->idcMatchers;
-
- while (matcher != NULL) {
- if ((matcher->idcType == XML_SCHEMA_TYPE_IDC_KEYREF) &&
- matcher->targets &&
- matcher->targets->nbItems)
- {
- int i, j, k, res, nbFields, hasDupls;
- xmlSchemaPSVIIDCKeyPtr *refKeys, *keys;
- xmlSchemaPSVIIDCNodePtr refNode = NULL;
- nbFields = matcher->aidc->def->nbFields;
-
- bind = vctxt->inode->idcTable;
- while (bind != NULL) {
- if ((xmlSchemaIDCPtr) matcher->aidc->def->ref->item ==
- bind->definition)
- break;
- bind = bind->next;
- }
- hasDupls = (bind && bind->dupls && bind->dupls->nbItems) ? 1 : 0;
-
- for (i = 0; i < matcher->targets->nbItems; i++) {
- res = 0;
- refNode = matcher->targets->items[i];
- if (bind != NULL) {
- refKeys = refNode->keys;
- for (j = 0; j < bind->nbNodes; j++) {
- keys = bind->nodeTable[j]->keys;
- for (k = 0; k < nbFields; k++) {
- res = xmlSchemaAreValuesEqual(keys[k]->val,
- refKeys[k]->val);
- if (res == 0)
- break;
- else if (res == -1) {
- return (-1);
- }
- }
- if (res == 1) {
-
- break;
- }
- }
- if ((res == 0) && hasDupls) {
-
- for (j = 0; j < bind->dupls->nbItems; j++) {
- keys = ((xmlSchemaPSVIIDCNodePtr)
- bind->dupls->items[j])->keys;
- for (k = 0; k < nbFields; k++) {
- res = xmlSchemaAreValuesEqual(keys[k]->val,
- refKeys[k]->val);
- if (res == 0)
- break;
- else if (res == -1) {
- return (-1);
- }
- }
- if (res == 1) {
-
- xmlChar *str = NULL, *strB = NULL;
- xmlSchemaKeyrefErr(vctxt,
- XML_SCHEMAV_CVC_IDC, refNode,
- (xmlSchemaTypePtr) matcher->aidc->def,
- "More than one match found for "
- "key-sequence %s of keyref '%s'",
- xmlSchemaFormatIDCKeySequence(vctxt, &str,
- refNode->keys, nbFields),
- xmlSchemaGetComponentQName(&strB,
- matcher->aidc->def));
- FREE_AND_NULL(str);
- FREE_AND_NULL(strB);
- break;
- }
- }
- }
- }
- if (res == 0) {
- xmlChar *str = NULL, *strB = NULL;
- xmlSchemaKeyrefErr(vctxt,
- XML_SCHEMAV_CVC_IDC, refNode,
- (xmlSchemaTypePtr) matcher->aidc->def,
- "No match found for key-sequence %s of keyref '%s'",
- xmlSchemaFormatIDCKeySequence(vctxt, &str,
- refNode->keys, nbFields),
- xmlSchemaGetComponentQName(&strB, matcher->aidc->def));
- FREE_AND_NULL(str);
- FREE_AND_NULL(strB);
- }
- }
- }
- matcher = matcher->next;
- }
-
- return (0);
- }
- static xmlSchemaAttrInfoPtr
- xmlSchemaGetFreshAttrInfo(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaAttrInfoPtr iattr;
-
- if (vctxt->attrInfos == NULL) {
- vctxt->attrInfos = (xmlSchemaAttrInfoPtr *)
- xmlMalloc(sizeof(xmlSchemaAttrInfoPtr));
- vctxt->sizeAttrInfos = 1;
- if (vctxt->attrInfos == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating attribute info list", NULL);
- return (NULL);
- }
- } else if (vctxt->sizeAttrInfos <= vctxt->nbAttrInfos) {
- vctxt->sizeAttrInfos++;
- vctxt->attrInfos = (xmlSchemaAttrInfoPtr *)
- xmlRealloc(vctxt->attrInfos,
- vctxt->sizeAttrInfos * sizeof(xmlSchemaAttrInfoPtr));
- if (vctxt->attrInfos == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "re-allocating attribute info list", NULL);
- return (NULL);
- }
- } else {
- iattr = vctxt->attrInfos[vctxt->nbAttrInfos++];
- if (iattr->localName != NULL) {
- VERROR_INT("xmlSchemaGetFreshAttrInfo",
- "attr info not cleared");
- return (NULL);
- }
- iattr->nodeType = XML_ATTRIBUTE_NODE;
- return (iattr);
- }
-
- iattr = (xmlSchemaAttrInfoPtr)
- xmlMalloc(sizeof(xmlSchemaAttrInfo));
- if (iattr == NULL) {
- xmlSchemaVErrMemory(vctxt, "creating new attribute info", NULL);
- return (NULL);
- }
- memset(iattr, 0, sizeof(xmlSchemaAttrInfo));
- iattr->nodeType = XML_ATTRIBUTE_NODE;
- vctxt->attrInfos[vctxt->nbAttrInfos++] = iattr;
- return (iattr);
- }
- static int
- xmlSchemaValidatorPushAttribute(xmlSchemaValidCtxtPtr vctxt,
- xmlNodePtr attrNode,
- int nodeLine,
- const xmlChar *localName,
- const xmlChar *nsName,
- int ownedNames,
- xmlChar *value,
- int ownedValue)
- {
- xmlSchemaAttrInfoPtr attr;
- attr = xmlSchemaGetFreshAttrInfo(vctxt);
- if (attr == NULL) {
- VERROR_INT("xmlSchemaPushAttribute",
- "calling xmlSchemaGetFreshAttrInfo()");
- return (-1);
- }
- attr->node = attrNode;
- attr->nodeLine = nodeLine;
- attr->state = XML_SCHEMAS_ATTR_UNKNOWN;
- attr->localName = localName;
- attr->nsName = nsName;
- if (ownedNames)
- attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES;
-
- if (nsName != NULL) {
- if (xmlStrEqual(localName, BAD_CAST "nil")) {
- if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
- attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NIL;
- }
- } else if (xmlStrEqual(localName, BAD_CAST "type")) {
- if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
- attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_TYPE;
- }
- } else if (xmlStrEqual(localName, BAD_CAST "schemaLocation")) {
- if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
- attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_SCHEMA_LOC;
- }
- } else if (xmlStrEqual(localName, BAD_CAST "noNamespaceSchemaLocation")) {
- if (xmlStrEqual(attr->nsName, xmlSchemaInstanceNs)) {
- attr->metaType = XML_SCHEMA_ATTR_INFO_META_XSI_NO_NS_SCHEMA_LOC;
- }
- } else if (xmlStrEqual(attr->nsName, xmlNamespaceNs)) {
- attr->metaType = XML_SCHEMA_ATTR_INFO_META_XMLNS;
- }
- }
- attr->value = value;
- if (ownedValue)
- attr->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
- if (attr->metaType != 0)
- attr->state = XML_SCHEMAS_ATTR_META;
- return (0);
- }
- static void
- xmlSchemaClearElemInfo(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaNodeInfoPtr ielem)
- {
- ielem->hasKeyrefs = 0;
- ielem->appliedXPath = 0;
- if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) {
- FREE_AND_NULL(ielem->localName);
- FREE_AND_NULL(ielem->nsName);
- } else {
- ielem->localName = NULL;
- ielem->nsName = NULL;
- }
- if (ielem->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
- FREE_AND_NULL(ielem->value);
- } else {
- ielem->value = NULL;
- }
- if (ielem->val != NULL) {
-
- xmlSchemaFreeValue(ielem->val);
- ielem->val = NULL;
- }
- if (ielem->idcMatchers != NULL) {
-
- xmlSchemaIDCReleaseMatcherList(vctxt, ielem->idcMatchers);
- #if 0
- xmlSchemaIDCFreeMatcherList(ielem->idcMatchers);
- #endif
- ielem->idcMatchers = NULL;
- }
- if (ielem->idcTable != NULL) {
-
- xmlSchemaIDCFreeIDCTable(ielem->idcTable);
- ielem->idcTable = NULL;
- }
- if (ielem->regexCtxt != NULL) {
- xmlRegFreeExecCtxt(ielem->regexCtxt);
- ielem->regexCtxt = NULL;
- }
- if (ielem->nsBindings != NULL) {
- xmlFree((xmlChar **)ielem->nsBindings);
- ielem->nsBindings = NULL;
- ielem->nbNsBindings = 0;
- ielem->sizeNsBindings = 0;
- }
- }
- static xmlSchemaNodeInfoPtr
- xmlSchemaGetFreshElemInfo(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaNodeInfoPtr info = NULL;
- if (vctxt->depth > vctxt->sizeElemInfos) {
- VERROR_INT("xmlSchemaGetFreshElemInfo",
- "inconsistent depth encountered");
- return (NULL);
- }
- if (vctxt->elemInfos == NULL) {
- vctxt->elemInfos = (xmlSchemaNodeInfoPtr *)
- xmlMalloc(10 * sizeof(xmlSchemaNodeInfoPtr));
- if (vctxt->elemInfos == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating the element info array", NULL);
- return (NULL);
- }
- memset(vctxt->elemInfos, 0, 10 * sizeof(xmlSchemaNodeInfoPtr));
- vctxt->sizeElemInfos = 10;
- } else if (vctxt->sizeElemInfos <= vctxt->depth) {
- int i = vctxt->sizeElemInfos;
- vctxt->sizeElemInfos *= 2;
- vctxt->elemInfos = (xmlSchemaNodeInfoPtr *)
- xmlRealloc(vctxt->elemInfos, vctxt->sizeElemInfos *
- sizeof(xmlSchemaNodeInfoPtr));
- if (vctxt->elemInfos == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "re-allocating the element info array", NULL);
- return (NULL);
- }
-
- for (; i < vctxt->sizeElemInfos; i++)
- vctxt->elemInfos[i] = NULL;
- } else
- info = vctxt->elemInfos[vctxt->depth];
- if (info == NULL) {
- info = (xmlSchemaNodeInfoPtr)
- xmlMalloc(sizeof(xmlSchemaNodeInfo));
- if (info == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating an element info", NULL);
- return (NULL);
- }
- vctxt->elemInfos[vctxt->depth] = info;
- } else {
- if (info->localName != NULL) {
- VERROR_INT("xmlSchemaGetFreshElemInfo",
- "elem info has not been cleared");
- return (NULL);
- }
- }
- memset(info, 0, sizeof(xmlSchemaNodeInfo));
- info->nodeType = XML_ELEMENT_NODE;
- info->depth = vctxt->depth;
- return (info);
- }
- #define ACTIVATE_ATTRIBUTE(item) vctxt->inode = (xmlSchemaNodeInfoPtr) item;
- #define ACTIVATE_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth];
- #define ACTIVATE_PARENT_ELEM vctxt->inode = vctxt->elemInfos[vctxt->depth -1];
- static int
- xmlSchemaValidateFacets(xmlSchemaAbstractCtxtPtr actxt,
- xmlNodePtr node,
- xmlSchemaTypePtr type,
- xmlSchemaValType valType,
- const xmlChar * value,
- xmlSchemaValPtr val,
- unsigned long length,
- int fireErrors)
- {
- int ret, error = 0;
- xmlSchemaTypePtr tmpType;
- xmlSchemaFacetLinkPtr facetLink;
- xmlSchemaFacetPtr facet;
- unsigned long len = 0;
- xmlSchemaWhitespaceValueType ws;
-
- if (type->type == XML_SCHEMA_TYPE_BASIC)
- return (0);
-
- if (type->facetSet == NULL)
- goto pattern_and_enum;
- if (! WXS_IS_ATOMIC(type)) {
- if (WXS_IS_LIST(type))
- goto WXS_IS_LIST;
- else
- goto pattern_and_enum;
- }
-
- tmpType = xmlSchemaGetPrimitiveType(type);
- if ((tmpType->builtInType == XML_SCHEMAS_STRING) ||
- WXS_IS_ANY_SIMPLE_TYPE(tmpType)) {
- ws = xmlSchemaGetWhiteSpaceFacetValue(type);
- } else
- ws = XML_SCHEMA_WHITESPACE_COLLAPSE;
-
- if (val == NULL)
- valType = valType;
- else
- valType = xmlSchemaGetValType(val);
- ret = 0;
- for (facetLink = type->facetSet; facetLink != NULL;
- facetLink = facetLink->next) {
-
- switch (facetLink->facet->type) {
- case XML_SCHEMA_FACET_WHITESPACE:
- case XML_SCHEMA_FACET_PATTERN:
- case XML_SCHEMA_FACET_ENUMERATION:
- continue;
- case XML_SCHEMA_FACET_LENGTH:
- case XML_SCHEMA_FACET_MINLENGTH:
- case XML_SCHEMA_FACET_MAXLENGTH:
- ret = xmlSchemaValidateLengthFacetWhtsp(facetLink->facet,
- valType, value, val, &len, ws);
- break;
- default:
- ret = xmlSchemaValidateFacetWhtsp(facetLink->facet, ws,
- valType, value, val, ws);
- break;
- }
- if (ret < 0) {
- AERROR_INT("xmlSchemaValidateFacets",
- "validating against a atomic type facet");
- return (-1);
- } else if (ret > 0) {
- if (fireErrors)
- xmlSchemaFacetErr(actxt, ret, node,
- value, len, type, facetLink->facet, NULL, NULL, NULL);
- else
- return (ret);
- if (error == 0)
- error = ret;
- }
- ret = 0;
- }
- WXS_IS_LIST:
- if (! WXS_IS_LIST(type))
- goto pattern_and_enum;
-
- ret = 0;
- for (facetLink = type->facetSet; facetLink != NULL;
- facetLink = facetLink->next) {
- switch (facetLink->facet->type) {
- case XML_SCHEMA_FACET_LENGTH:
- case XML_SCHEMA_FACET_MINLENGTH:
- case XML_SCHEMA_FACET_MAXLENGTH:
- ret = xmlSchemaValidateListSimpleTypeFacet(facetLink->facet,
- value, length, NULL);
- break;
- default:
- continue;
- }
- if (ret < 0) {
- AERROR_INT("xmlSchemaValidateFacets",
- "validating against a list type facet");
- return (-1);
- } else if (ret > 0) {
- if (fireErrors)
- xmlSchemaFacetErr(actxt, ret, node,
- value, length, type, facetLink->facet, NULL, NULL, NULL);
- else
- return (ret);
- if (error == 0)
- error = ret;
- }
- ret = 0;
- }
- pattern_and_enum:
- if (error >= 0) {
- int found = 0;
-
- ret = 0;
- tmpType = type;
- do {
- for (facet = tmpType->facets; facet != NULL; facet = facet->next) {
- if (facet->type != XML_SCHEMA_FACET_ENUMERATION)
- continue;
- found = 1;
- ret = xmlSchemaAreValuesEqual(facet->val, val);
- if (ret == 1)
- break;
- else if (ret < 0) {
- AERROR_INT("xmlSchemaValidateFacets",
- "validating against an enumeration facet");
- return (-1);
- }
- }
- if (ret != 0)
- break;
-
- if (found)
- break;
- tmpType = tmpType->baseType;
- } while ((tmpType != NULL) &&
- (tmpType->type != XML_SCHEMA_TYPE_BASIC));
- if (found && (ret == 0)) {
- ret = XML_SCHEMAV_CVC_ENUMERATION_VALID;
- if (fireErrors) {
- xmlSchemaFacetErr(actxt, ret, node,
- value, 0, type, NULL, NULL, NULL, NULL);
- } else
- return (ret);
- if (error == 0)
- error = ret;
- }
- }
- if (error >= 0) {
- int found;
-
- tmpType = type;
- facet = NULL;
- do {
- found = 0;
- for (facetLink = tmpType->facetSet; facetLink != NULL;
- facetLink = facetLink->next) {
- if (facetLink->facet->type != XML_SCHEMA_FACET_PATTERN)
- continue;
- found = 1;
-
- ret = xmlRegexpExec(facetLink->facet->regexp, value);
- if (ret == 1)
- break;
- else if (ret < 0) {
- AERROR_INT("xmlSchemaValidateFacets",
- "validating against a pattern facet");
- return (-1);
- } else {
-
- facet = facetLink->facet;
- }
- }
- if (found && (ret != 1)) {
- ret = XML_SCHEMAV_CVC_PATTERN_VALID;
- if (fireErrors) {
- xmlSchemaFacetErr(actxt, ret, node,
- value, 0, type, facet, NULL, NULL, NULL);
- } else
- return (ret);
- if (error == 0)
- error = ret;
- break;
- }
- tmpType = tmpType->baseType;
- } while ((tmpType != NULL) && (tmpType->type != XML_SCHEMA_TYPE_BASIC));
- }
- return (error);
- }
- static xmlChar *
- xmlSchemaNormalizeValue(xmlSchemaTypePtr type,
- const xmlChar *value)
- {
- switch (xmlSchemaGetWhiteSpaceFacetValue(type)) {
- case XML_SCHEMA_WHITESPACE_COLLAPSE:
- return (xmlSchemaCollapseString(value));
- case XML_SCHEMA_WHITESPACE_REPLACE:
- return (xmlSchemaWhiteSpaceReplace(value));
- default:
- return (NULL);
- }
- }
- static int
- xmlSchemaValidateQName(xmlSchemaValidCtxtPtr vctxt,
- const xmlChar *value,
- xmlSchemaValPtr *val,
- int valNeeded)
- {
- int ret;
- const xmlChar *nsName;
- xmlChar *local, *prefix = NULL;
- ret = xmlValidateQName(value, 1);
- if (ret != 0) {
- if (ret == -1) {
- VERROR_INT("xmlSchemaValidateQName",
- "calling xmlValidateQName()");
- return (-1);
- }
- return( XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1);
- }
-
- local = xmlSplitQName2(value, &prefix);
- if (local == NULL)
- local = xmlStrdup(value);
-
- nsName = xmlSchemaLookupNamespace(vctxt, prefix);
- if (prefix != NULL) {
- xmlFree(prefix);
-
- if (nsName == NULL) {
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
- xmlSchemaCustomErr(ACTXT_CAST vctxt, ret, NULL,
- WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
- "The QName value '%s' has no "
- "corresponding namespace declaration in "
- "scope", value, NULL);
- if (local != NULL)
- xmlFree(local);
- return (ret);
- }
- }
- if (valNeeded && val) {
- if (nsName != NULL)
- *val = xmlSchemaNewQNameValue(
- BAD_CAST xmlStrdup(nsName), BAD_CAST local);
- else
- *val = xmlSchemaNewQNameValue(NULL,
- BAD_CAST local);
- } else
- xmlFree(local);
- return (0);
- }
- static int
- xmlSchemaVCheckCVCSimpleType(xmlSchemaAbstractCtxtPtr actxt,
- xmlNodePtr node,
- xmlSchemaTypePtr type,
- const xmlChar *value,
- xmlSchemaValPtr *retVal,
- int fireErrors,
- int normalize,
- int isNormalized)
- {
- int ret = 0, valNeeded = (retVal) ? 1 : 0;
- xmlSchemaValPtr val = NULL;
-
- xmlChar *normValue = NULL;
- #define NORMALIZE(atype) \
- if ((! isNormalized) && \
- (normalize || (type->flags & XML_SCHEMAS_TYPE_NORMVALUENEEDED))) { \
- normValue = xmlSchemaNormalizeValue(atype, value); \
- if (normValue != NULL) \
- value = normValue; \
- isNormalized = 1; \
- }
- if ((retVal != NULL) && (*retVal != NULL)) {
- xmlSchemaFreeValue(*retVal);
- *retVal = NULL;
- }
-
-
-
-
-
- if ((! valNeeded) && (type->flags & XML_SCHEMAS_TYPE_FACETSNEEDVALUE))
- valNeeded = 1;
- if (value == NULL)
- value = BAD_CAST "";
- if (WXS_IS_ANY_SIMPLE_TYPE(type) || WXS_IS_ATOMIC(type)) {
- xmlSchemaTypePtr biType;
-
-
- NORMALIZE(type);
- if (type->type != XML_SCHEMA_TYPE_BASIC) {
-
- biType = type->baseType;
- while ((biType != NULL) &&
- (biType->type != XML_SCHEMA_TYPE_BASIC))
- biType = biType->baseType;
- if (biType == NULL) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "could not get the built-in type");
- goto internal_error;
- }
- } else
- biType = type;
-
- if (actxt->type == XML_SCHEMA_CTXT_VALIDATOR) {
- switch (biType->builtInType) {
- case XML_SCHEMAS_NOTATION:
- ret = xmlSchemaValidateNotation(
- (xmlSchemaValidCtxtPtr) actxt,
- ((xmlSchemaValidCtxtPtr) actxt)->schema,
- NULL, value, &val, valNeeded);
- break;
- case XML_SCHEMAS_QNAME:
- ret = xmlSchemaValidateQName((xmlSchemaValidCtxtPtr) actxt,
- value, &val, valNeeded);
- break;
- default:
-
- if (valNeeded)
- ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
- value, &val, node);
- else
- ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
- value, NULL, node);
- break;
- }
- } else if (actxt->type == XML_SCHEMA_CTXT_PARSER) {
- switch (biType->builtInType) {
- case XML_SCHEMAS_NOTATION:
- ret = xmlSchemaValidateNotation(NULL,
- ((xmlSchemaParserCtxtPtr) actxt)->schema, node,
- value, &val, valNeeded);
- break;
- default:
-
- if (valNeeded)
- ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
- value, &val, node);
- else
- ret = xmlSchemaValPredefTypeNodeNoNorm(biType,
- value, NULL, node);
- break;
- }
- } else {
-
- TODO
- goto internal_error;
- }
- if (ret != 0) {
- if (ret < 0) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "validating against a built-in type");
- goto internal_error;
- }
- if (WXS_IS_LIST(type))
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
- else
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
- }
- if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
-
- ret = xmlSchemaValidateFacets(actxt, node, type,
- (xmlSchemaValType) biType->builtInType, value, val,
- 0, fireErrors);
- if (ret != 0) {
- if (ret < 0) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "validating facets of atomic simple type");
- goto internal_error;
- }
- if (WXS_IS_LIST(type))
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
- else
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1;
- }
- }
- if (fireErrors && (ret > 0))
- xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
- } else if (WXS_IS_LIST(type)) {
- xmlSchemaTypePtr itemType;
- const xmlChar *cur, *end;
- xmlChar *tmpValue = NULL;
- unsigned long len = 0;
- xmlSchemaValPtr prevVal = NULL, curVal = NULL;
-
-
- NORMALIZE(type);
-
- itemType = WXS_LIST_ITEMTYPE(type);
- cur = value;
- do {
- while (IS_BLANK_CH(*cur))
- cur++;
- end = cur;
- while ((*end != 0) && (!(IS_BLANK_CH(*end))))
- end++;
- if (end == cur)
- break;
- tmpValue = xmlStrndup(cur, end - cur);
- len++;
- if (valNeeded)
- ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType,
- tmpValue, &curVal, fireErrors, 0, 1);
- else
- ret = xmlSchemaVCheckCVCSimpleType(actxt, node, itemType,
- tmpValue, NULL, fireErrors, 0, 1);
- FREE_AND_NULL(tmpValue);
- if (curVal != NULL) {
-
- if (val == NULL)
- val = curVal;
- else
- xmlSchemaValueAppend(prevVal, curVal);
- prevVal = curVal;
- curVal = NULL;
- }
- if (ret != 0) {
- if (ret < 0) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "validating an item of list simple type");
- goto internal_error;
- }
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
- break;
- }
- cur = end;
- } while (*cur != 0);
- FREE_AND_NULL(tmpValue);
- if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
-
- ret = xmlSchemaValidateFacets(actxt, node, type,
- XML_SCHEMAS_UNKNOWN, value, val,
- len, fireErrors);
- if (ret != 0) {
- if (ret < 0) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "validating facets of list simple type");
- goto internal_error;
- }
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_2;
- }
- }
- if (fireErrors && (ret > 0)) {
-
- normalize = 1;
- NORMALIZE(type);
- xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
- }
- } else if (WXS_IS_UNION(type)) {
- xmlSchemaTypeLinkPtr memberLink;
-
-
- memberLink = xmlSchemaGetUnionSimpleTypeMemberTypes(type);
- if (memberLink == NULL) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "union simple type has no member types");
- goto internal_error;
- }
-
- while (memberLink != NULL) {
- if (valNeeded)
- ret = xmlSchemaVCheckCVCSimpleType(actxt, node,
- memberLink->type, value, &val, 0, 1, 0);
- else
- ret = xmlSchemaVCheckCVCSimpleType(actxt, node,
- memberLink->type, value, NULL, 0, 1, 0);
- if (ret <= 0)
- break;
- memberLink = memberLink->next;
- }
- if (ret != 0) {
- if (ret < 0) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "validating members of union simple type");
- goto internal_error;
- }
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3;
- }
-
- if ((ret == 0) && (type->flags & XML_SCHEMAS_TYPE_HAS_FACETS)) {
-
- NORMALIZE(memberLink->type);
- ret = xmlSchemaValidateFacets(actxt, node, type,
- XML_SCHEMAS_UNKNOWN, value, val,
- 0, fireErrors);
- if (ret != 0) {
- if (ret < 0) {
- AERROR_INT("xmlSchemaVCheckCVCSimpleType",
- "validating facets of union simple type");
- goto internal_error;
- }
- ret = XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_3;
- }
- }
- if (fireErrors && (ret > 0))
- xmlSchemaSimpleTypeErr(actxt, ret, node, value, type, 1);
- }
- if (normValue != NULL)
- xmlFree(normValue);
- if (ret == 0) {
- if (retVal != NULL)
- *retVal = val;
- else if (val != NULL)
- xmlSchemaFreeValue(val);
- } else if (val != NULL)
- xmlSchemaFreeValue(val);
- return (ret);
- internal_error:
- if (normValue != NULL)
- xmlFree(normValue);
- if (val != NULL)
- xmlSchemaFreeValue(val);
- return (-1);
- }
- static int
- xmlSchemaVExpandQName(xmlSchemaValidCtxtPtr vctxt,
- const xmlChar *value,
- const xmlChar **nsName,
- const xmlChar **localName)
- {
- int ret = 0;
- if ((nsName == NULL) || (localName == NULL))
- return (-1);
- *nsName = NULL;
- *localName = NULL;
- ret = xmlValidateQName(value, 1);
- if (ret == -1)
- return (-1);
- if (ret > 0) {
- xmlSchemaSimpleTypeErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL,
- value, xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME), 1);
- return (1);
- }
- {
- xmlChar *local = NULL;
- xmlChar *prefix;
-
- local = xmlSplitQName2(value, &prefix);
- if (local == NULL)
- *localName = xmlDictLookup(vctxt->dict, value, -1);
- else {
- *localName = xmlDictLookup(vctxt->dict, local, -1);
- xmlFree(local);
- }
- *nsName = xmlSchemaLookupNamespace(vctxt, prefix);
- if (prefix != NULL) {
- xmlFree(prefix);
-
- if (*nsName == NULL) {
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_DATATYPE_VALID_1_2_1, NULL,
- WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
- "The QName value '%s' has no "
- "corresponding namespace declaration in scope",
- value, NULL);
- return (2);
- }
- }
- }
- return (0);
- }
- static int
- xmlSchemaProcessXSIType(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaAttrInfoPtr iattr,
- xmlSchemaTypePtr *localType,
- xmlSchemaElementPtr elemDecl)
- {
- int ret = 0;
-
- if (localType == NULL)
- return (-1);
- *localType = NULL;
- if (iattr == NULL)
- return (0);
- else {
- const xmlChar *nsName = NULL, *local = NULL;
-
- ACTIVATE_ATTRIBUTE(iattr);
-
- ret = xmlSchemaVExpandQName(vctxt, iattr->value,
- &nsName, &local);
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidateElementByDeclaration",
- "calling xmlSchemaQNameExpand() to validate the "
- "attribute 'xsi:type'");
- goto internal_error;
- }
- goto exit;
- }
-
- *localType = xmlSchemaGetType(vctxt->schema, local, nsName);
- if (*localType == NULL) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_ELT_4_2, NULL,
- WXS_BASIC_CAST xmlSchemaGetBuiltInType(XML_SCHEMAS_QNAME),
- "The QName value '%s' of the xsi:type attribute does not "
- "resolve to a type definition",
- xmlSchemaFormatQName(&str, nsName, local), NULL);
- FREE_AND_NULL(str);
- ret = vctxt->err;
- goto exit;
- }
- if (elemDecl != NULL) {
- int set = 0;
-
-
- if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_EXTENSION) ||
- (elemDecl->subtypes->flags &
- XML_SCHEMAS_TYPE_BLOCK_EXTENSION))
- set |= SUBSET_EXTENSION;
- if ((elemDecl->flags & XML_SCHEMAS_ELEM_BLOCK_RESTRICTION) ||
- (elemDecl->subtypes->flags &
- XML_SCHEMAS_TYPE_BLOCK_RESTRICTION))
- set |= SUBSET_RESTRICTION;
-
- if (xmlSchemaCheckCOSDerivedOK(ACTXT_CAST vctxt, *localType,
- elemDecl->subtypes, set) != 0) {
- xmlChar *str = NULL;
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_ELT_4_3, NULL, NULL,
- "The type definition '%s', specified by xsi:type, is "
- "blocked or not validly derived from the type definition "
- "of the element declaration",
- xmlSchemaFormatQName(&str,
- (*localType)->targetNamespace,
- (*localType)->name),
- NULL);
- FREE_AND_NULL(str);
- ret = vctxt->err;
- *localType = NULL;
- }
- }
- }
- exit:
- ACTIVATE_ELEM;
- return (ret);
- internal_error:
- ACTIVATE_ELEM;
- return (-1);
- }
- static int
- xmlSchemaValidateElemDecl(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaElementPtr elemDecl = vctxt->inode->decl;
- xmlSchemaTypePtr actualType;
-
- if (elemDecl == NULL) {
- VERROR(XML_SCHEMAV_CVC_ELT_1, NULL,
- "No matching declaration available");
- return (vctxt->err);
- }
- actualType = WXS_ELEM_TYPEDEF(elemDecl);
-
- if (elemDecl->flags & XML_SCHEMAS_ELEM_ABSTRACT) {
- VERROR(XML_SCHEMAV_CVC_ELT_2, NULL,
- "The element declaration is abstract");
- return (vctxt->err);
- }
- if (actualType == NULL) {
- VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
- "The type definition is absent");
- return (XML_SCHEMAV_CVC_TYPE_1);
- }
- if (vctxt->nbAttrInfos != 0) {
- int ret;
- xmlSchemaAttrInfoPtr iattr;
-
- iattr = xmlSchemaGetMetaAttrInfo(vctxt,
- XML_SCHEMA_ATTR_INFO_META_XSI_NIL);
- if (iattr) {
- ACTIVATE_ATTRIBUTE(iattr);
-
- ret = xmlSchemaVCheckCVCSimpleType(
- ACTXT_CAST vctxt, NULL,
- xmlSchemaGetBuiltInType(XML_SCHEMAS_BOOLEAN),
- iattr->value, &(iattr->val), 1, 0, 0);
- ACTIVATE_ELEM;
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidateElemDecl",
- "calling xmlSchemaVCheckCVCSimpleType() to "
- "validate the attribute 'xsi:nil'");
- return (-1);
- }
- if (ret == 0) {
- if ((elemDecl->flags & XML_SCHEMAS_ELEM_NILLABLE) == 0) {
-
- VERROR(XML_SCHEMAV_CVC_ELT_3_1, NULL,
- "The element is not 'nillable'");
-
- } else {
- if (xmlSchemaValueGetAsBoolean(iattr->val)) {
-
- if ((elemDecl->flags & XML_SCHEMAS_ELEM_FIXED) &&
- (elemDecl->value != NULL)) {
- VERROR(XML_SCHEMAV_CVC_ELT_3_2_2, NULL,
- "The element cannot be 'nilled' because "
- "there is a fixed value constraint defined "
- "for it");
-
- } else
- vctxt->inode->flags |=
- XML_SCHEMA_ELEM_INFO_NILLED;
- }
- }
- }
- }
-
- iattr = xmlSchemaGetMetaAttrInfo(vctxt,
- XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
- if (iattr) {
- xmlSchemaTypePtr localType = NULL;
- ret = xmlSchemaProcessXSIType(vctxt, iattr, &localType,
- elemDecl);
- if (ret != 0) {
- if (ret == -1) {
- VERROR_INT("xmlSchemaValidateElemDecl",
- "calling xmlSchemaProcessXSIType() to "
- "process the attribute 'xsi:type'");
- return (-1);
- }
-
- }
- if (localType != NULL) {
- vctxt->inode->flags |= XML_SCHEMA_ELEM_INFO_LOCAL_TYPE;
- actualType = localType;
- }
- }
- }
-
- if ((elemDecl->idcs != NULL) &&
- (xmlSchemaIDCRegisterMatchers(vctxt, elemDecl) == -1))
- return (-1);
-
- if (actualType == NULL) {
- VERROR(XML_SCHEMAV_CVC_TYPE_1, NULL,
- "The type definition is absent");
- return (XML_SCHEMAV_CVC_TYPE_1);
- }
-
- vctxt->inode->typeDef = actualType;
- return (0);
- }
- static int
- xmlSchemaVAttributesSimple(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaAttrInfoPtr iattr;
- int ret = 0, i;
-
- if (vctxt->nbAttrInfos == 0)
- return (0);
- for (i = 0; i < vctxt->nbAttrInfos; i++) {
- iattr = vctxt->attrInfos[i];
- if (! iattr->metaType) {
- ACTIVATE_ATTRIBUTE(iattr)
- xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_TYPE_3_1_1, iattr, NULL);
- ret = XML_SCHEMAV_CVC_TYPE_3_1_1;
- }
- }
- ACTIVATE_ELEM
- return (ret);
- }
- static void
- xmlSchemaClearAttrInfos(xmlSchemaValidCtxtPtr vctxt)
- {
- int i;
- xmlSchemaAttrInfoPtr attr;
- if (vctxt->nbAttrInfos == 0)
- return;
- for (i = 0; i < vctxt->nbAttrInfos; i++) {
- attr = vctxt->attrInfos[i];
- if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES) {
- if (attr->localName != NULL)
- xmlFree((xmlChar *) attr->localName);
- if (attr->nsName != NULL)
- xmlFree((xmlChar *) attr->nsName);
- }
- if (attr->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
- if (attr->value != NULL)
- xmlFree((xmlChar *) attr->value);
- }
- if (attr->val != NULL) {
- xmlSchemaFreeValue(attr->val);
- attr->val = NULL;
- }
- memset(attr, 0, sizeof(xmlSchemaAttrInfo));
- }
- vctxt->nbAttrInfos = 0;
- }
- static int
- xmlSchemaVAttributesComplex(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaTypePtr type = vctxt->inode->typeDef;
- xmlSchemaItemListPtr attrUseList;
- xmlSchemaAttributeUsePtr attrUse = NULL;
- xmlSchemaAttributePtr attrDecl = NULL;
- xmlSchemaAttrInfoPtr iattr, tmpiattr;
- int i, j, found, nbAttrs, nbUses;
- int xpathRes = 0, res, wildIDs = 0, fixed;
- xmlNodePtr defAttrOwnerElem = NULL;
-
- attrUseList = (xmlSchemaItemListPtr) type->attrUses;
-
- nbAttrs = vctxt->nbAttrInfos;
- if (attrUseList != NULL)
- nbUses = attrUseList->nbItems;
- else
- nbUses = 0;
- for (i = 0; i < nbUses; i++) {
- found = 0;
- attrUse = attrUseList->items[i];
- attrDecl = WXS_ATTRUSE_DECL(attrUse);
- for (j = 0; j < nbAttrs; j++) {
- iattr = vctxt->attrInfos[j];
-
- if (iattr->metaType)
- continue;
- if (iattr->localName[0] != attrDecl->name[0])
- continue;
- if (!xmlStrEqual(iattr->localName, attrDecl->name))
- continue;
- if (!xmlStrEqual(iattr->nsName, attrDecl->targetNamespace))
- continue;
- found = 1;
-
- iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
- iattr->use = attrUse;
-
- iattr->decl = attrDecl;
- iattr->typeDef = attrDecl->subtypes;
- break;
- }
- if (found)
- continue;
- if (attrUse->occurs == XML_SCHEMAS_ATTR_USE_REQUIRED) {
-
- tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt);
- if (tmpiattr == NULL) {
- VERROR_INT(
- "xmlSchemaVAttributesComplex",
- "calling xmlSchemaGetFreshAttrInfo()");
- return (-1);
- }
- tmpiattr->state = XML_SCHEMAS_ATTR_ERR_MISSING;
- tmpiattr->use = attrUse;
- tmpiattr->decl = attrDecl;
- } else if ((attrUse->occurs == XML_SCHEMAS_ATTR_USE_OPTIONAL) &&
- ((attrUse->defValue != NULL) ||
- (attrDecl->defValue != NULL))) {
-
- tmpiattr = xmlSchemaGetFreshAttrInfo(vctxt);
- if (tmpiattr == NULL) {
- VERROR_INT(
- "xmlSchemaVAttributesComplex",
- "calling xmlSchemaGetFreshAttrInfo()");
- return (-1);
- }
- tmpiattr->state = XML_SCHEMAS_ATTR_DEFAULT;
- tmpiattr->use = attrUse;
- tmpiattr->decl = attrDecl;
- tmpiattr->typeDef = attrDecl->subtypes;
- tmpiattr->localName = attrDecl->name;
- tmpiattr->nsName = attrDecl->targetNamespace;
- }
- }
- if (vctxt->nbAttrInfos == 0)
- return (0);
-
- if (type->attributeWildcard != NULL) {
-
- for (i = 0; i < nbAttrs; i++) {
- iattr = vctxt->attrInfos[i];
-
- if (iattr->state != XML_SCHEMAS_ATTR_UNKNOWN)
- continue;
-
- if (xmlSchemaCheckCVCWildcardNamespace(type->attributeWildcard,
- iattr->nsName) == 0) {
-
- if (type->attributeWildcard->processContents ==
- XML_SCHEMAS_ANY_SKIP) {
-
- iattr->state = XML_SCHEMAS_ATTR_WILD_SKIP;
- continue;
- }
-
- iattr->decl = xmlSchemaGetAttributeDecl(vctxt->schema,
- iattr->localName, iattr->nsName);
- if (iattr->decl != NULL) {
- iattr->state = XML_SCHEMAS_ATTR_ASSESSED;
-
- iattr->typeDef = WXS_ATTR_TYPEDEF(iattr->decl);
- if (xmlSchemaIsDerivedFromBuiltInType(
- iattr->typeDef, XML_SCHEMAS_ID)) {
-
- if (wildIDs != 0) {
-
- iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_DUPLICATE_ID;
- TODO
- continue;
- }
- wildIDs++;
-
- if (attrUseList != NULL) {
- for (j = 0; j < attrUseList->nbItems; j++) {
- if (xmlSchemaIsDerivedFromBuiltInType(
- WXS_ATTRUSE_TYPEDEF(attrUseList->items[j]),
- XML_SCHEMAS_ID)) {
-
- iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_AND_USE_ID;
- TODO
- break;
- }
- }
- }
- }
- } else if (type->attributeWildcard->processContents ==
- XML_SCHEMAS_ANY_LAX) {
- iattr->state = XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL;
-
- } else {
- iattr->state = XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL;
- }
- }
- }
- }
- if (vctxt->nbAttrInfos == 0)
- return (0);
-
- if (vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) {
- xmlSchemaNodeInfoPtr ielem = vctxt->elemInfos[vctxt->depth];
- if (ielem && ielem->node && ielem->node->doc)
- defAttrOwnerElem = ielem->node;
- }
-
- for (i = 0; i < vctxt->nbAttrInfos; i++) {
- iattr = vctxt->attrInfos[i];
-
- if ((iattr->state != XML_SCHEMAS_ATTR_ASSESSED) &&
- (iattr->state != XML_SCHEMAS_ATTR_DEFAULT))
- continue;
-
- if (iattr->typeDef == NULL) {
- iattr->state = XML_SCHEMAS_ATTR_ERR_NO_TYPE;
- continue;
- }
- ACTIVATE_ATTRIBUTE(iattr);
- fixed = 0;
- xpathRes = 0;
- if (vctxt->xpathStates != NULL) {
-
- xpathRes = xmlSchemaXPathEvaluate(vctxt,
- XML_ATTRIBUTE_NODE);
- if (xpathRes == -1) {
- VERROR_INT("xmlSchemaVAttributesComplex",
- "calling xmlSchemaXPathEvaluate()");
- goto internal_error;
- }
- }
- if (iattr->state == XML_SCHEMAS_ATTR_DEFAULT) {
-
- if ((xpathRes) || (defAttrOwnerElem)) {
- if (iattr->use->defValue != NULL) {
- iattr->value = (xmlChar *) iattr->use->defValue;
- iattr->val = iattr->use->defVal;
- } else {
- iattr->value = (xmlChar *) iattr->decl->defValue;
- iattr->val = iattr->decl->defVal;
- }
-
- if (iattr->val == NULL) {
- VERROR_INT("xmlSchemaVAttributesComplex",
- "default/fixed value on an attribute use was "
- "not precomputed");
- goto internal_error;
- }
- iattr->val = xmlSchemaCopyValue(iattr->val);
- if (iattr->val == NULL) {
- VERROR_INT("xmlSchemaVAttributesComplex",
- "calling xmlSchemaCopyValue()");
- goto internal_error;
- }
- }
-
- if (defAttrOwnerElem) {
- xmlChar *normValue;
- const xmlChar *value;
- value = iattr->value;
-
- normValue = xmlSchemaNormalizeValue(iattr->typeDef,
- iattr->value);
- if (normValue != NULL)
- value = BAD_CAST normValue;
- if (iattr->nsName == NULL) {
- if (xmlNewProp(defAttrOwnerElem,
- iattr->localName, value) == NULL) {
- VERROR_INT("xmlSchemaVAttributesComplex",
- "callling xmlNewProp()");
- if (normValue != NULL)
- xmlFree(normValue);
- goto internal_error;
- }
- } else {
- xmlNsPtr ns;
- ns = xmlSearchNsByHref(defAttrOwnerElem->doc,
- defAttrOwnerElem, iattr->nsName);
- if (ns == NULL) {
- xmlChar prefix[12];
- int counter = 0;
-
- do {
- snprintf((char *) prefix, 12, "p%d", counter++);
- ns = xmlSearchNs(defAttrOwnerElem->doc,
- defAttrOwnerElem, BAD_CAST prefix);
- if (counter > 1000) {
- VERROR_INT(
- "xmlSchemaVAttributesComplex",
- "could not compute a ns prefix for a "
- "default/fixed attribute");
- if (normValue != NULL)
- xmlFree(normValue);
- goto internal_error;
- }
- } while (ns != NULL);
- ns = xmlNewNs(vctxt->validationRoot,
- iattr->nsName, BAD_CAST prefix);
- }
-
- xmlNewNsProp(defAttrOwnerElem, ns, iattr->localName, value);
- }
- if (normValue != NULL)
- xmlFree(normValue);
- }
-
- goto eval_idcs;
- }
-
- if (vctxt->value != NULL) {
-
- xmlSchemaFreeValue(vctxt->value);
- vctxt->value = NULL;
- }
-
- if ((iattr->decl->flags & XML_SCHEMAS_ATTR_FIXED) ||
- ((iattr->use != NULL) &&
- (iattr->use->flags & XML_SCHEMAS_ATTR_FIXED)))
- fixed = 1;
- else
- fixed = 0;
-
- if (xpathRes || fixed) {
- iattr->flags |= XML_SCHEMA_NODE_INFO_VALUE_NEEDED;
-
- res = xmlSchemaVCheckCVCSimpleType(
- ACTXT_CAST vctxt,
- iattr->node, iattr->typeDef, iattr->value, &(iattr->val),
- 1, 1, 0);
- } else {
- res = xmlSchemaVCheckCVCSimpleType(
- ACTXT_CAST vctxt,
- iattr->node, iattr->typeDef, iattr->value, NULL,
- 1, 0, 0);
- }
- if (res != 0) {
- if (res == -1) {
- VERROR_INT("xmlSchemaVAttributesComplex",
- "calling xmlSchemaStreamValidateSimpleTypeValue()");
- goto internal_error;
- }
- iattr->state = XML_SCHEMAS_ATTR_INVALID_VALUE;
-
- goto eval_idcs;
- }
- if (fixed) {
-
-
- if (iattr->val == NULL) {
-
- TODO
- goto eval_idcs;
- }
- if ((iattr->use != NULL) &&
- (iattr->use->defValue != NULL)) {
- if (iattr->use->defVal == NULL) {
-
- TODO
- goto eval_idcs;
- }
- iattr->vcValue = iattr->use->defValue;
-
- if (! xmlSchemaAreValuesEqual(iattr->val, iattr->use->defVal))
- iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE;
- } else {
- if (iattr->decl->defVal == NULL) {
-
- TODO
- goto eval_idcs;
- }
- iattr->vcValue = iattr->decl->defValue;
-
- if (! xmlSchemaAreValuesEqual(iattr->val, iattr->decl->defVal))
- iattr->state = XML_SCHEMAS_ATTR_ERR_FIXED_VALUE;
- }
-
- }
- eval_idcs:
-
- if (xpathRes) {
- if (xmlSchemaXPathProcessHistory(vctxt,
- vctxt->depth +1) == -1) {
- VERROR_INT("xmlSchemaVAttributesComplex",
- "calling xmlSchemaXPathEvaluate()");
- goto internal_error;
- }
- } else if (vctxt->xpathStates != NULL)
- xmlSchemaXPathPop(vctxt);
- }
-
- for (i = 0; i < vctxt->nbAttrInfos; i++) {
- iattr = vctxt->attrInfos[i];
- if ((iattr->state == XML_SCHEMAS_ATTR_META) ||
- (iattr->state == XML_SCHEMAS_ATTR_ASSESSED) ||
- (iattr->state == XML_SCHEMAS_ATTR_WILD_SKIP) ||
- (iattr->state == XML_SCHEMAS_ATTR_WILD_LAX_NO_DECL))
- continue;
- ACTIVATE_ATTRIBUTE(iattr);
- switch (iattr->state) {
- case XML_SCHEMAS_ATTR_ERR_MISSING: {
- xmlChar *str = NULL;
- ACTIVATE_ELEM;
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_COMPLEX_TYPE_4, NULL, NULL,
- "The attribute '%s' is required but missing",
- xmlSchemaFormatQName(&str,
- iattr->decl->targetNamespace,
- iattr->decl->name),
- NULL);
- FREE_AND_NULL(str)
- break;
- }
- case XML_SCHEMAS_ATTR_ERR_NO_TYPE:
- VERROR(XML_SCHEMAV_CVC_ATTRIBUTE_2, NULL,
- "The type definition is absent");
- break;
- case XML_SCHEMAS_ATTR_ERR_FIXED_VALUE:
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_AU, NULL, NULL,
- "The value '%s' does not match the fixed "
- "value constraint '%s'",
- iattr->value, iattr->vcValue);
- break;
- case XML_SCHEMAS_ATTR_ERR_WILD_STRICT_NO_DECL:
- VERROR(XML_SCHEMAV_CVC_WILDCARD, NULL,
- "No matching global attribute declaration available, but "
- "demanded by the strict wildcard");
- break;
- case XML_SCHEMAS_ATTR_UNKNOWN:
- if (iattr->metaType)
- break;
-
- if (type->attributeWildcard == NULL) {
- xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_1, iattr, NULL);
- } else {
- xmlSchemaIllegalAttrErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_CVC_COMPLEX_TYPE_3_2_2, iattr, NULL);
- }
- break;
- default:
- break;
- }
- }
- ACTIVATE_ELEM;
- return (0);
- internal_error:
- ACTIVATE_ELEM;
- return (-1);
- }
- static int
- xmlSchemaValidateElemWildcard(xmlSchemaValidCtxtPtr vctxt,
- int *skip)
- {
- xmlSchemaWildcardPtr wild = (xmlSchemaWildcardPtr) vctxt->inode->decl;
-
- if ((skip == NULL) || (wild == NULL) ||
- (wild->type != XML_SCHEMA_TYPE_ANY)) {
- VERROR_INT("xmlSchemaValidateElemWildcard",
- "bad arguments");
- return (-1);
- }
- *skip = 0;
- if (wild->processContents == XML_SCHEMAS_ANY_SKIP) {
-
- *skip = 1;
- return (0);
- }
- {
- xmlSchemaElementPtr decl = NULL;
- decl = xmlSchemaGetElem(vctxt->schema,
- vctxt->inode->localName, vctxt->inode->nsName);
- if (decl != NULL) {
- vctxt->inode->decl = decl;
- return (0);
- }
- }
- if (wild->processContents == XML_SCHEMAS_ANY_STRICT) {
-
- VERROR(XML_SCHEMAV_CVC_ELT_1, NULL,
- "No matching global element declaration available, but "
- "demanded by the strict wildcard");
- return (vctxt->err);
- }
- if (vctxt->nbAttrInfos != 0) {
- xmlSchemaAttrInfoPtr iattr;
-
- iattr = xmlSchemaGetMetaAttrInfo(vctxt,
- XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
- if (iattr != NULL) {
- if (xmlSchemaProcessXSIType(vctxt, iattr,
- &(vctxt->inode->typeDef), NULL) == -1) {
- VERROR_INT("xmlSchemaValidateElemWildcard",
- "calling xmlSchemaProcessXSIType() to "
- "process the attribute 'xsi:nil'");
- return (-1);
- }
-
- return (0);
- }
- }
-
- vctxt->inode->typeDef =
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
- return (0);
- }
- static int
- xmlSchemaCheckCOSValidDefault(xmlSchemaValidCtxtPtr vctxt,
- const xmlChar *value,
- xmlSchemaValPtr *val)
- {
- int ret = 0;
- xmlSchemaNodeInfoPtr inode = vctxt->inode;
-
- if WXS_IS_COMPLEX(inode->typeDef) {
-
- if ((! WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) &&
- ((! WXS_HAS_MIXED_CONTENT(inode->typeDef)) ||
- (! WXS_EMPTIABLE(inode->typeDef)))) {
- ret = XML_SCHEMAP_COS_VALID_DEFAULT_2_1;
-
- VERROR(ret, NULL,
- "For a string to be a valid default, the type definition "
- "must be a simple type or a complex type with simple content "
- "or mixed content and a particle emptiable");
- return(ret);
- }
- }
-
- if (WXS_IS_SIMPLE(inode->typeDef)) {
- ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt,
- NULL, inode->typeDef, value, val, 1, 1, 0);
- } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
- ret = xmlSchemaVCheckCVCSimpleType(ACTXT_CAST vctxt,
- NULL, inode->typeDef->contentTypeDef, value, val, 1, 1, 0);
- }
- if (ret < 0) {
- VERROR_INT("xmlSchemaCheckCOSValidDefault",
- "calling xmlSchemaVCheckCVCSimpleType()");
- }
- return (ret);
- }
- static void
- xmlSchemaVContentModelCallback(xmlSchemaValidCtxtPtr vctxt ATTRIBUTE_UNUSED,
- const xmlChar * name ATTRIBUTE_UNUSED,
- xmlSchemaElementPtr item,
- xmlSchemaNodeInfoPtr inode)
- {
- inode->decl = item;
- #ifdef DEBUG_CONTENT
- {
- xmlChar *str = NULL;
- if (item->type == XML_SCHEMA_TYPE_ELEMENT) {
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON callback for '%s' [declaration]\n",
- xmlSchemaFormatQName(&str,
- inode->localName, inode->nsName));
- } else {
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON callback for '%s' [wildcard]\n",
- xmlSchemaFormatQName(&str,
- inode->localName, inode->nsName));
- }
- FREE_AND_NULL(str)
- }
- #endif
- }
- static int
- xmlSchemaValidatorPushElem(xmlSchemaValidCtxtPtr vctxt)
- {
- vctxt->inode = xmlSchemaGetFreshElemInfo(vctxt);
- if (vctxt->inode == NULL) {
- VERROR_INT("xmlSchemaValidatorPushElem",
- "calling xmlSchemaGetFreshElemInfo()");
- return (-1);
- }
- vctxt->nbAttrInfos = 0;
- return (0);
- }
- static int
- xmlSchemaVCheckINodeDataType(xmlSchemaValidCtxtPtr vctxt,
- xmlSchemaNodeInfoPtr inode,
- xmlSchemaTypePtr type,
- const xmlChar *value)
- {
- if (inode->flags & XML_SCHEMA_NODE_INFO_VALUE_NEEDED)
- return (xmlSchemaVCheckCVCSimpleType(
- ACTXT_CAST vctxt, NULL,
- type, value, &(inode->val), 1, 1, 0));
- else
- return (xmlSchemaVCheckCVCSimpleType(
- ACTXT_CAST vctxt, NULL,
- type, value, NULL, 1, 0, 0));
- }
- static int
- xmlSchemaValidatorPopElem(xmlSchemaValidCtxtPtr vctxt)
- {
- int ret = 0;
- xmlSchemaNodeInfoPtr inode = vctxt->inode;
- if (vctxt->nbAttrInfos != 0)
- xmlSchemaClearAttrInfos(vctxt);
- if (inode->flags & XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED) {
-
- vctxt->skipDepth = vctxt->depth -1;
- goto end_elem;
- }
- if ((inode->typeDef == NULL) ||
- (inode->flags & XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE)) {
-
- goto end_elem;
- }
-
- if ((inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) ||
- (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)) {
-
- if (inode->typeDef->builtInType == XML_SCHEMAS_ANYTYPE)
- goto character_content;
- if ((inode->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) == 0) {
- xmlChar *values[10];
- int terminal, nbval = 10, nbneg;
- if (inode->regexCtxt == NULL) {
-
- inode->regexCtxt =
- xmlRegNewExecCtxt(inode->typeDef->contModel,
- (xmlRegExecCallbacks) xmlSchemaVContentModelCallback,
- vctxt);
- if (inode->regexCtxt == NULL) {
- VERROR_INT("xmlSchemaValidatorPopElem",
- "failed to create a regex context");
- goto internal_error;
- }
- #ifdef DEBUG_AUTOMATA
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON create on '%s'\n", inode->localName);
- #endif
- }
-
- xmlRegExecNextValues(inode->regexCtxt,
- &nbval, &nbneg, &values[0], &terminal);
- ret = xmlRegExecPushString(inode->regexCtxt, NULL, NULL);
- if ((ret<0) || ((ret==0) && (!INODE_NILLED(inode)))) {
-
- ret = 1;
- inode->flags |=
- XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT;
- xmlSchemaComplexTypeErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_ELEMENT_CONTENT, NULL, NULL,
- "Missing child element(s)",
- nbval, nbneg, values);
- #ifdef DEBUG_AUTOMATA
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON missing ERROR on '%s'\n",
- inode->localName);
- #endif
- } else {
-
- ret = 0;
- #ifdef DEBUG_AUTOMATA
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON succeeded on '%s'\n",
- inode->localName);
- #endif
- }
- }
- }
- if (inode->typeDef->contentType == XML_SCHEMA_CONTENT_ELEMENTS)
- goto end_elem;
- character_content:
- if (vctxt->value != NULL) {
- xmlSchemaFreeValue(vctxt->value);
- vctxt->value = NULL;
- }
-
- if (inode->decl == NULL) {
-
- if (WXS_IS_SIMPLE(inode->typeDef)) {
- ret = xmlSchemaVCheckINodeDataType(vctxt,
- inode, inode->typeDef, inode->value);
- } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
- ret = xmlSchemaVCheckINodeDataType(vctxt,
- inode, inode->typeDef->contentTypeDef,
- inode->value);
- }
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidatorPopElem",
- "calling xmlSchemaVCheckCVCSimpleType()");
- goto internal_error;
- }
- goto end_elem;
- }
-
-
- if ((inode->decl->value != NULL) &&
- (inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY) &&
- (! INODE_NILLED(inode))) {
-
-
- if (inode->flags & XML_SCHEMA_ELEM_INFO_LOCAL_TYPE) {
- ret = xmlSchemaCheckCOSValidDefault(vctxt,
- inode->decl->value, &(inode->val));
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidatorPopElem",
- "calling xmlSchemaCheckCOSValidDefault()");
- goto internal_error;
- }
- goto end_elem;
- }
-
- goto default_psvi;
- }
-
- if (WXS_IS_SIMPLE(inode->typeDef)) {
- ret = xmlSchemaVCheckINodeDataType(vctxt,
- inode, inode->typeDef, inode->decl->value);
- } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
- ret = xmlSchemaVCheckINodeDataType(vctxt,
- inode, inode->typeDef->contentTypeDef,
- inode->decl->value);
- }
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidatorPopElem",
- "calling xmlSchemaVCheckCVCSimpleType()");
- goto internal_error;
- }
- goto end_elem;
- }
- default_psvi:
-
- if ((vctxt->options & XML_SCHEMA_VAL_VC_I_CREATE) &&
- (inode->node != NULL)) {
- xmlNodePtr textChild;
- xmlChar *normValue;
-
- normValue = xmlSchemaNormalizeValue(inode->typeDef,
- inode->decl->value);
- if (normValue != NULL) {
- textChild = xmlNewText(BAD_CAST normValue);
- xmlFree(normValue);
- } else
- textChild = xmlNewText(inode->decl->value);
- if (textChild == NULL) {
- VERROR_INT("xmlSchemaValidatorPopElem",
- "calling xmlNewText()");
- goto internal_error;
- } else
- xmlAddChild(inode->node, textChild);
- }
- } else if (! INODE_NILLED(inode)) {
-
- if (WXS_IS_SIMPLE(inode->typeDef)) {
-
- ret = xmlSchemaVCheckINodeDataType(vctxt,
- inode, inode->typeDef, inode->value);
- } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
-
- ret = xmlSchemaVCheckINodeDataType(vctxt,
- inode, inode->typeDef->contentTypeDef, inode->value);
- }
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidatorPopElem",
- "calling xmlSchemaVCheckCVCSimpleType()");
- goto internal_error;
- }
- goto end_elem;
- }
-
- if ((inode->decl->value != NULL) &&
- (inode->decl->flags & XML_SCHEMAS_ELEM_FIXED)) {
-
-
- if (inode->flags &
- XML_SCHEMA_ELEM_INFO_HAS_ELEM_CONTENT) {
- ret = XML_SCHEMAV_CVC_ELT_5_2_2_1;
- VERROR(ret, NULL,
- "The content must not containt element nodes since "
- "there is a fixed value constraint");
- goto end_elem;
- } else {
-
- if (WXS_HAS_MIXED_CONTENT(inode->typeDef)) {
-
- if (! xmlStrEqual(inode->value, inode->decl->value)){
-
- ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_1;
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- ret, NULL, NULL,
- "The initial value '%s' does not match the fixed "
- "value constraint '%s'",
- inode->value, inode->decl->value);
- goto end_elem;
- }
- } else if (WXS_HAS_SIMPLE_CONTENT(inode->typeDef)) {
-
-
- if (! xmlStrEqual(inode->value,
- inode->decl->value)) {
- ret = XML_SCHEMAV_CVC_ELT_5_2_2_2_2;
- xmlSchemaCustomErr(ACTXT_CAST vctxt,
- ret, NULL, NULL,
- "The actual value '%s' does not match the fixed "
- "value constraint '%s'",
- inode->value,
- inode->decl->value);
- goto end_elem;
- }
- }
- }
- }
- }
- end_elem:
- if (vctxt->depth < 0) {
-
- return (0);
- }
- if (vctxt->depth == vctxt->skipDepth)
- vctxt->skipDepth = -1;
-
- if (inode->appliedXPath &&
- (xmlSchemaXPathProcessHistory(vctxt, vctxt->depth) == -1))
- goto internal_error;
-
-
-
- if ((inode->idcMatchers != NULL) &&
- (vctxt->hasKeyrefs || vctxt->createIDCNodeTables))
- {
- if (xmlSchemaIDCFillNodeTables(vctxt, inode) == -1)
- goto internal_error;
- }
-
- if (vctxt->inode->hasKeyrefs)
- if (xmlSchemaCheckCVCIDCKeyRef(vctxt) == -1)
- goto internal_error;
-
- if (inode->idcTable != NULL) {
- #ifdef DEBUG_IDC_NODE_TABLE
- xmlSchemaDebugDumpIDCTable(stdout,
- inode->nsName,
- inode->localName,
- inode->idcTable);
- #endif
- if ((vctxt->depth > 0) &&
- (vctxt->hasKeyrefs || vctxt->createIDCNodeTables))
- {
-
- if (xmlSchemaBubbleIDCNodeTables(vctxt) == -1)
- goto internal_error;
- }
- }
-
- xmlSchemaClearElemInfo(vctxt, inode);
-
- if (vctxt->depth == 0) {
- vctxt->depth--;
- vctxt->inode = NULL;
- return (0);
- }
-
- if (vctxt->aidcs != NULL) {
- xmlSchemaIDCAugPtr aidc = vctxt->aidcs;
- do {
- if (aidc->keyrefDepth == vctxt->depth) {
-
- aidc->keyrefDepth = -1;
- }
- aidc = aidc->next;
- } while (aidc != NULL);
- }
- vctxt->depth--;
- vctxt->inode = vctxt->elemInfos[vctxt->depth];
-
- return (ret);
- internal_error:
- vctxt->err = -1;
- return (-1);
- }
- static int
- xmlSchemaValidateChildElem(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlSchemaNodeInfoPtr pielem;
- xmlSchemaTypePtr ptype;
- int ret = 0;
- if (vctxt->depth <= 0) {
- VERROR_INT("xmlSchemaValidateChildElem",
- "not intended for the validation root");
- return (-1);
- }
- pielem = vctxt->elemInfos[vctxt->depth -1];
- if (pielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
- pielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
-
- if (INODE_NILLED(pielem)) {
-
- ACTIVATE_PARENT_ELEM;
- ret = XML_SCHEMAV_CVC_ELT_3_2_1;
- VERROR(ret, NULL,
- "Neither character nor element content is allowed, "
- "because the element was 'nilled'");
- ACTIVATE_ELEM;
- goto unexpected_elem;
- }
- ptype = pielem->typeDef;
- if (ptype->builtInType == XML_SCHEMAS_ANYTYPE) {
-
- vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema,
- vctxt->inode->localName,
- vctxt->inode->nsName);
- if (vctxt->inode->decl == NULL) {
- xmlSchemaAttrInfoPtr iattr;
-
- iattr = xmlSchemaGetMetaAttrInfo(vctxt,
- XML_SCHEMA_ATTR_INFO_META_XSI_TYPE);
- if (iattr != NULL) {
- ret = xmlSchemaProcessXSIType(vctxt, iattr,
- &(vctxt->inode->typeDef), NULL);
- if (ret != 0) {
- if (ret == -1) {
- VERROR_INT("xmlSchemaValidateChildElem",
- "calling xmlSchemaProcessXSIType() to "
- "process the attribute 'xsi:nil'");
- return (-1);
- }
- return (ret);
- }
- } else {
-
- vctxt->inode->typeDef =
- xmlSchemaGetBuiltInType(XML_SCHEMAS_ANYTYPE);
- }
- }
- return (0);
- }
- switch (ptype->contentType) {
- case XML_SCHEMA_CONTENT_EMPTY:
-
- ACTIVATE_PARENT_ELEM
- ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1;
- VERROR(ret, NULL,
- "Element content is not allowed, "
- "because the content type is empty");
- ACTIVATE_ELEM
- goto unexpected_elem;
- break;
- case XML_SCHEMA_CONTENT_MIXED:
- case XML_SCHEMA_CONTENT_ELEMENTS: {
- xmlRegExecCtxtPtr regexCtxt;
- xmlChar *values[10];
- int terminal, nbval = 10, nbneg;
-
- if (ptype->contModel == NULL) {
- VERROR_INT("xmlSchemaValidateChildElem",
- "type has elem content but no content model");
- return (-1);
- }
-
- if (pielem->flags & XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT) {
- VERROR_INT("xmlSchemaValidateChildElem",
- "validating elem, but elem content is already invalid");
- return (-1);
- }
- regexCtxt = pielem->regexCtxt;
- if (regexCtxt == NULL) {
-
- regexCtxt = xmlRegNewExecCtxt(ptype->contModel,
- (xmlRegExecCallbacks) xmlSchemaVContentModelCallback,
- vctxt);
- if (regexCtxt == NULL) {
- VERROR_INT("xmlSchemaValidateChildElem",
- "failed to create a regex context");
- return (-1);
- }
- pielem->regexCtxt = regexCtxt;
- #ifdef DEBUG_AUTOMATA
- xmlGenericError(xmlGenericErrorContext, "AUTOMATA create on '%s'\n",
- pielem->localName);
- #endif
- }
-
- ret = xmlRegExecPushString2(regexCtxt,
- vctxt->inode->localName,
- vctxt->inode->nsName,
- vctxt->inode);
- #ifdef DEBUG_AUTOMATA
- if (ret < 0)
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON push ERROR for '%s' on '%s'\n",
- vctxt->inode->localName, pielem->localName);
- else
- xmlGenericError(xmlGenericErrorContext,
- "AUTOMATON push OK for '%s' on '%s'\n",
- vctxt->inode->localName, pielem->localName);
- #endif
- if (vctxt->err == XML_SCHEMAV_INTERNAL) {
- VERROR_INT("xmlSchemaValidateChildElem",
- "calling xmlRegExecPushString2()");
- return (-1);
- }
- if (ret < 0) {
- xmlRegExecErrInfo(regexCtxt, NULL, &nbval, &nbneg,
- &values[0], &terminal);
- xmlSchemaComplexTypeErr(ACTXT_CAST vctxt,
- XML_SCHEMAV_ELEMENT_CONTENT, NULL,NULL,
- "This element is not expected",
- nbval, nbneg, values);
- ret = vctxt->err;
- goto unexpected_elem;
- } else
- ret = 0;
- }
- break;
- case XML_SCHEMA_CONTENT_SIMPLE:
- case XML_SCHEMA_CONTENT_BASIC:
- ACTIVATE_PARENT_ELEM
- if (WXS_IS_COMPLEX(ptype)) {
-
- ret = XML_SCHEMAV_CVC_COMPLEX_TYPE_2_2;
- VERROR(ret, NULL, "Element content is not allowed, "
- "because the content type is a simple type definition");
- } else {
-
- ret = XML_SCHEMAV_CVC_TYPE_3_1_2;
- VERROR(ret, NULL, "Element content is not allowed, "
- "because the type definition is simple");
- }
- ACTIVATE_ELEM
- ret = vctxt->err;
- goto unexpected_elem;
- break;
- default:
- break;
- }
- return (ret);
- unexpected_elem:
-
- vctxt->skipDepth = vctxt->depth;
- vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_NOT_EXPECTED;
- pielem->flags |= XML_SCHEMA_ELEM_INFO_ERR_BAD_CONTENT;
- return (ret);
- }
- #define XML_SCHEMA_PUSH_TEXT_PERSIST 1
- #define XML_SCHEMA_PUSH_TEXT_CREATED 2
- #define XML_SCHEMA_PUSH_TEXT_VOLATILE 3
- static int
- xmlSchemaVPushText(xmlSchemaValidCtxtPtr vctxt,
- int nodeType, const xmlChar *value, int len,
- int mode, int *consumed)
- {
-
- if (consumed != NULL)
- *consumed = 0;
- if (INODE_NILLED(vctxt->inode)) {
-
- VERROR(XML_SCHEMAV_CVC_ELT_3_2_1, NULL,
- "Neither character nor element content is allowed "
- "because the element is 'nilled'");
- return (vctxt->err);
- }
-
- if (vctxt->inode->typeDef->contentType ==
- XML_SCHEMA_CONTENT_EMPTY) {
- VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_1, NULL,
- "Character content is not allowed, "
- "because the content type is empty");
- return (vctxt->err);
- }
- if (vctxt->inode->typeDef->contentType ==
- XML_SCHEMA_CONTENT_ELEMENTS) {
- if ((nodeType != XML_TEXT_NODE) ||
- (! xmlSchemaIsBlank((xmlChar *) value, len))) {
-
- VERROR(XML_SCHEMAV_CVC_COMPLEX_TYPE_2_3, NULL,
- "Character content other than whitespace is not allowed "
- "because the content type is 'element-only'");
- return (vctxt->err);
- }
- return (0);
- }
- if ((value == NULL) || (value[0] == 0))
- return (0);
-
- if ((vctxt->inode->typeDef->contentType == XML_SCHEMA_CONTENT_MIXED) &&
- ((vctxt->inode->decl == NULL) ||
- (vctxt->inode->decl->value == NULL)))
- return (0);
- if (vctxt->inode->value == NULL) {
-
- switch (mode) {
- case XML_SCHEMA_PUSH_TEXT_PERSIST:
-
- vctxt->inode->value = value;
- break;
- case XML_SCHEMA_PUSH_TEXT_CREATED:
-
- vctxt->inode->value = value;
- if (consumed != NULL)
- *consumed = 1;
- vctxt->inode->flags |=
- XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
- break;
- case XML_SCHEMA_PUSH_TEXT_VOLATILE:
-
- if (len != -1)
- vctxt->inode->value = BAD_CAST xmlStrndup(value, len);
- else
- vctxt->inode->value = BAD_CAST xmlStrdup(value);
- vctxt->inode->flags |=
- XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
- break;
- default:
- break;
- }
- } else {
- if (len < 0)
- len = xmlStrlen(value);
-
- if (vctxt->inode->flags & XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES) {
- vctxt->inode->value = BAD_CAST xmlStrncat(
- (xmlChar *) vctxt->inode->value, value, len);
- } else {
- vctxt->inode->value =
- BAD_CAST xmlStrncatNew(vctxt->inode->value, value, len);
- vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_VALUES;
- }
- }
- return (0);
- }
- static int
- xmlSchemaValidateElem(xmlSchemaValidCtxtPtr vctxt)
- {
- int ret = 0;
- if ((vctxt->skipDepth != -1) &&
- (vctxt->depth >= vctxt->skipDepth)) {
- VERROR_INT("xmlSchemaValidateElem",
- "in skip-state");
- goto internal_error;
- }
- if (vctxt->xsiAssemble) {
-
- ret = xmlSchemaAssembleByXSI(vctxt);
- if (ret != 0) {
- if (ret == -1)
- goto internal_error;
- vctxt->skipDepth = 0;
- return(ret);
- }
- }
- if (vctxt->depth > 0) {
-
- ret = xmlSchemaValidateChildElem(vctxt);
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidateElem",
- "calling xmlSchemaStreamValidateChildElement()");
- goto internal_error;
- }
- goto exit;
- }
- if (vctxt->depth == vctxt->skipDepth)
- goto exit;
- if ((vctxt->inode->decl == NULL) &&
- (vctxt->inode->typeDef == NULL)) {
- VERROR_INT("xmlSchemaValidateElem",
- "the child element was valid but neither the "
- "declaration nor the type was set");
- goto internal_error;
- }
- } else {
-
- vctxt->inode->decl = xmlSchemaGetElem(vctxt->schema,
- vctxt->inode->localName,
- vctxt->inode->nsName);
- if (vctxt->inode->decl == NULL) {
- ret = XML_SCHEMAV_CVC_ELT_1;
- VERROR(ret, NULL,
- "No matching global declaration available "
- "for the validation root");
- goto exit;
- }
- }
- if (vctxt->inode->decl == NULL)
- goto type_validation;
- if (vctxt->inode->decl->type == XML_SCHEMA_TYPE_ANY) {
- int skip;
-
- ret = xmlSchemaValidateElemWildcard(vctxt, &skip);
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidateElem",
- "calling xmlSchemaValidateElemWildcard()");
- goto internal_error;
- }
- goto exit;
- }
- if (skip) {
- vctxt->skipDepth = vctxt->depth;
- goto exit;
- }
-
- if (vctxt->inode->decl->type != XML_SCHEMA_TYPE_ELEMENT) {
-
- vctxt->inode->decl = NULL;
- goto type_validation;
- }
- }
-
- ret = xmlSchemaValidateElemDecl(vctxt);
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaValidateElem",
- "calling xmlSchemaValidateElemDecl()");
- goto internal_error;
- }
- goto exit;
- }
-
- type_validation:
- if (vctxt->inode->typeDef == NULL) {
- vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
- ret = XML_SCHEMAV_CVC_TYPE_1;
- VERROR(ret, NULL,
- "The type definition is absent");
- goto exit;
- }
- if (vctxt->inode->typeDef->flags & XML_SCHEMAS_TYPE_ABSTRACT) {
- vctxt->inode->flags |= XML_SCHEMA_NODE_INFO_ERR_BAD_TYPE;
- ret = XML_SCHEMAV_CVC_TYPE_2;
- VERROR(ret, NULL,
- "The type definition is abstract");
- goto exit;
- }
-
- if (vctxt->xpathStates != NULL) {
- ret = xmlSchemaXPathEvaluate(vctxt, XML_ELEMENT_NODE);
- vctxt->inode->appliedXPath = 1;
- if (ret == -1) {
- VERROR_INT("xmlSchemaValidateElem",
- "calling xmlSchemaXPathEvaluate()");
- goto internal_error;
- }
- }
-
- if (WXS_IS_COMPLEX(vctxt->inode->typeDef)) {
- if ((vctxt->nbAttrInfos != 0) ||
- (vctxt->inode->typeDef->attrUses != NULL)) {
- ret = xmlSchemaVAttributesComplex(vctxt);
- }
- } else if (vctxt->nbAttrInfos != 0) {
- ret = xmlSchemaVAttributesSimple(vctxt);
- }
-
- if (vctxt->nbAttrInfos != 0)
- xmlSchemaClearAttrInfos(vctxt);
- if (ret == -1) {
- VERROR_INT("xmlSchemaValidateElem",
- "calling attributes validation");
- goto internal_error;
- }
-
- ret = 0;
- exit:
- if (ret != 0)
- vctxt->skipDepth = vctxt->depth;
- return (ret);
- internal_error:
- return (-1);
- }
- #ifdef XML_SCHEMA_READER_ENABLED
- static int
- xmlSchemaVReaderWalk(xmlSchemaValidCtxtPtr vctxt)
- {
- const int WHTSP = 13, SIGN_WHTSP = 14, END_ELEM = 15;
- int depth, nodeType, ret = 0, consumed;
- xmlSchemaNodeInfoPtr ielem;
- vctxt->depth = -1;
- ret = xmlTextReaderRead(vctxt->reader);
-
- while (ret == 1) {
- nodeType = xmlTextReaderNodeType(vctxt->reader);
- if (nodeType == XML_ELEMENT_NODE)
- goto root_found;
- ret = xmlTextReaderRead(vctxt->reader);
- }
- goto exit;
- root_found:
- do {
- depth = xmlTextReaderDepth(vctxt->reader);
- nodeType = xmlTextReaderNodeType(vctxt->reader);
- if (nodeType == XML_ELEMENT_NODE) {
- vctxt->depth++;
- if (xmlSchemaValidatorPushElem(vctxt) == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlSchemaValidatorPushElem()");
- goto internal_error;
- }
- ielem = vctxt->inode;
- ielem->localName = xmlTextReaderLocalName(vctxt->reader);
- ielem->nsName = xmlTextReaderNamespaceUri(vctxt->reader);
- ielem->flags |= XML_SCHEMA_NODE_INFO_FLAG_OWNED_NAMES;
-
- ret = xmlTextReaderIsEmptyElement(vctxt->reader);
- if (ret == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlTextReaderIsEmptyElement()");
- goto internal_error;
- }
- if (ret) {
- ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
- }
-
- vctxt->nbAttrInfos = 0;
- ret = xmlTextReaderMoveToFirstAttribute(vctxt->reader);
- if (ret == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlTextReaderMoveToFirstAttribute()");
- goto internal_error;
- }
- if (ret == 1) {
- do {
-
- if (xmlSchemaValidatorPushAttribute(vctxt, NULL,
- (const xmlChar *) xmlTextReaderLocalName(vctxt->reader),
- xmlTextReaderNamespaceUri(vctxt->reader), 1,
- xmlTextReaderValue(vctxt->reader), 1) == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlSchemaValidatorPushAttribute()");
- goto internal_error;
- }
- ret = xmlTextReaderMoveToNextAttribute(vctxt->reader);
- if (ret == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlTextReaderMoveToFirstAttribute()");
- goto internal_error;
- }
- } while (ret == 1);
-
- ret = xmlTextReaderMoveToElement(vctxt->reader);
- if (ret == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlTextReaderMoveToElement()");
- goto internal_error;
- }
- }
-
- ret= xmlSchemaValidateElem(vctxt);
- if (ret != 0) {
- if (ret == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlSchemaValidateElem()");
- goto internal_error;
- }
- goto exit;
- }
- if (vctxt->depth == vctxt->skipDepth) {
- int curDepth;
-
- if ((ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY) == 0) {
- ret = xmlTextReaderRead(vctxt->reader);
- curDepth = xmlTextReaderDepth(vctxt->reader);
- while ((ret == 1) && (curDepth != depth)) {
- ret = xmlTextReaderRead(vctxt->reader);
- curDepth = xmlTextReaderDepth(vctxt->reader);
- }
- if (ret < 0) {
-
- ret = 1;
- goto exit;
- }
- }
- goto leave_elem;
- }
-
- if (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
- goto leave_elem;
- } else if (nodeType == END_ELEM) {
-
- leave_elem:
- ret = xmlSchemaValidatorPopElem(vctxt);
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlSchemaValidatorPopElem()");
- goto internal_error;
- }
- goto exit;
- }
- if (vctxt->depth >= 0)
- ielem = vctxt->inode;
- else
- ielem = NULL;
- } else if ((nodeType == XML_TEXT_NODE) ||
- (nodeType == XML_CDATA_SECTION_NODE) ||
- (nodeType == WHTSP) ||
- (nodeType == SIGN_WHTSP)) {
-
- xmlChar *value;
- if ((nodeType == WHTSP) || (nodeType == SIGN_WHTSP))
- nodeType = XML_TEXT_NODE;
- value = xmlTextReaderValue(vctxt->reader);
- ret = xmlSchemaVPushText(vctxt, nodeType, BAD_CAST value,
- -1, XML_SCHEMA_PUSH_TEXT_CREATED, &consumed);
- if (! consumed)
- xmlFree(value);
- if (ret == -1) {
- VERROR_INT("xmlSchemaVReaderWalk",
- "calling xmlSchemaVPushText()");
- goto internal_error;
- }
- } else if ((nodeType == XML_ENTITY_NODE) ||
- (nodeType == XML_ENTITY_REF_NODE)) {
-
- TODO
- }
-
- ret = xmlTextReaderRead(vctxt->reader);
- } while (ret == 1);
- exit:
- return (ret);
- internal_error:
- return (-1);
- }
- #endif
- static void
- xmlSchemaSAXHandleText(void *ctx,
- const xmlChar * ch,
- int len)
- {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
- if (vctxt->depth < 0)
- return;
- if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
- return;
- if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
- vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
- if (xmlSchemaVPushText(vctxt, XML_TEXT_NODE, ch, len,
- XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) {
- VERROR_INT("xmlSchemaSAXHandleCDataSection",
- "calling xmlSchemaVPushText()");
- vctxt->err = -1;
- xmlStopParser(vctxt->parserCtxt);
- }
- }
- static void
- xmlSchemaSAXHandleCDataSection(void *ctx,
- const xmlChar * ch,
- int len)
- {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
- if (vctxt->depth < 0)
- return;
- if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
- return;
- if (vctxt->inode->flags & XML_SCHEMA_ELEM_INFO_EMPTY)
- vctxt->inode->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
- if (xmlSchemaVPushText(vctxt, XML_CDATA_SECTION_NODE, ch, len,
- XML_SCHEMA_PUSH_TEXT_VOLATILE, NULL) == -1) {
- VERROR_INT("xmlSchemaSAXHandleCDataSection",
- "calling xmlSchemaVPushText()");
- vctxt->err = -1;
- xmlStopParser(vctxt->parserCtxt);
- }
- }
- static void
- xmlSchemaSAXHandleReference(void *ctx ATTRIBUTE_UNUSED,
- const xmlChar * name ATTRIBUTE_UNUSED)
- {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
- if (vctxt->depth < 0)
- return;
- if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
- return;
-
- TODO
- }
- static void
- xmlSchemaSAXHandleStartElementNs(void *ctx,
- const xmlChar * localname,
- const xmlChar * prefix ATTRIBUTE_UNUSED,
- const xmlChar * URI,
- int nb_namespaces,
- const xmlChar ** namespaces,
- int nb_attributes,
- int nb_defaulted ATTRIBUTE_UNUSED,
- const xmlChar ** attributes)
- {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
- int ret;
- xmlSchemaNodeInfoPtr ielem;
- int i, j;
-
-
- vctxt->depth++;
- if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
- return;
-
- if (xmlSchemaValidatorPushElem(vctxt) == -1) {
- VERROR_INT("xmlSchemaSAXHandleStartElementNs",
- "calling xmlSchemaValidatorPushElem()");
- goto internal_error;
- }
- ielem = vctxt->inode;
-
- ielem->nodeLine = xmlSAX2GetLineNumber(vctxt->parserCtxt);
- ielem->localName = localname;
- ielem->nsName = URI;
- ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
-
- if (nb_namespaces != 0) {
-
- for (i = 0, j = 0; i < nb_namespaces; i++, j += 2) {
-
- if (ielem->nsBindings == NULL) {
- ielem->nsBindings =
- (const xmlChar **) xmlMalloc(10 *
- sizeof(const xmlChar *));
- if (ielem->nsBindings == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "allocating namespace bindings for SAX validation",
- NULL);
- goto internal_error;
- }
- ielem->nbNsBindings = 0;
- ielem->sizeNsBindings = 5;
- } else if (ielem->sizeNsBindings <= ielem->nbNsBindings) {
- ielem->sizeNsBindings *= 2;
- ielem->nsBindings =
- (const xmlChar **) xmlRealloc(
- (void *) ielem->nsBindings,
- ielem->sizeNsBindings * 2 * sizeof(const xmlChar *));
- if (ielem->nsBindings == NULL) {
- xmlSchemaVErrMemory(vctxt,
- "re-allocating namespace bindings for SAX validation",
- NULL);
- goto internal_error;
- }
- }
- ielem->nsBindings[ielem->nbNsBindings * 2] = namespaces[j];
- if (namespaces[j+1][0] == 0) {
-
- ielem->nsBindings[ielem->nbNsBindings * 2 + 1] = NULL;
- } else
- ielem->nsBindings[ielem->nbNsBindings * 2 + 1] =
- namespaces[j+1];
- ielem->nbNsBindings++;
- }
- }
-
- if (nb_attributes != 0) {
- xmlChar *value;
- for (j = 0, i = 0; i < nb_attributes; i++, j += 5) {
-
- value = xmlStrndup(attributes[j+3],
- attributes[j+4] - attributes[j+3]);
-
- ret = xmlSchemaValidatorPushAttribute(vctxt,
- NULL, ielem->nodeLine, attributes[j], attributes[j+2], 0,
- value, 1);
- if (ret == -1) {
- VERROR_INT("xmlSchemaSAXHandleStartElementNs",
- "calling xmlSchemaValidatorPushAttribute()");
- goto internal_error;
- }
- }
- }
-
- ret = xmlSchemaValidateElem(vctxt);
- if (ret != 0) {
- if (ret == -1) {
- VERROR_INT("xmlSchemaSAXHandleStartElementNs",
- "calling xmlSchemaValidateElem()");
- goto internal_error;
- }
- goto exit;
- }
- exit:
- return;
- internal_error:
- vctxt->err = -1;
- xmlStopParser(vctxt->parserCtxt);
- return;
- }
- static void
- xmlSchemaSAXHandleEndElementNs(void *ctx,
- const xmlChar * localname ATTRIBUTE_UNUSED,
- const xmlChar * prefix ATTRIBUTE_UNUSED,
- const xmlChar * URI ATTRIBUTE_UNUSED)
- {
- xmlSchemaValidCtxtPtr vctxt = (xmlSchemaValidCtxtPtr) ctx;
- int res;
-
- if (vctxt->skipDepth != -1) {
- if (vctxt->depth > vctxt->skipDepth) {
- vctxt->depth--;
- return;
- } else
- vctxt->skipDepth = -1;
- }
-
- if ((!xmlStrEqual(vctxt->inode->localName, localname)) ||
- (!xmlStrEqual(vctxt->inode->nsName, URI))) {
- VERROR_INT("xmlSchemaSAXHandleEndElementNs",
- "elem pop mismatch");
- }
- res = xmlSchemaValidatorPopElem(vctxt);
- if (res != 0) {
- if (res < 0) {
- VERROR_INT("xmlSchemaSAXHandleEndElementNs",
- "calling xmlSchemaValidatorPopElem()");
- goto internal_error;
- }
- goto exit;
- }
- exit:
- return;
- internal_error:
- vctxt->err = -1;
- xmlStopParser(vctxt->parserCtxt);
- return;
- }
- xmlSchemaValidCtxtPtr
- xmlSchemaNewValidCtxt(xmlSchemaPtr schema)
- {
- xmlSchemaValidCtxtPtr ret;
- ret = (xmlSchemaValidCtxtPtr) xmlMalloc(sizeof(xmlSchemaValidCtxt));
- if (ret == NULL) {
- xmlSchemaVErrMemory(NULL, "allocating validation context", NULL);
- return (NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaValidCtxt));
- ret->type = XML_SCHEMA_CTXT_VALIDATOR;
- ret->dict = xmlDictCreate();
- ret->nodeQNames = xmlSchemaItemListCreate();
- ret->schema = schema;
- return (ret);
- }
- static void
- xmlSchemaClearValidCtxt(xmlSchemaValidCtxtPtr vctxt)
- {
- if (vctxt == NULL)
- return;
-
- vctxt->flags = 0;
- vctxt->validationRoot = NULL;
- vctxt->doc = NULL;
- #ifdef LIBXML_READER_ENABLED
- vctxt->reader = NULL;
- #endif
- vctxt->hasKeyrefs = 0;
- if (vctxt->value != NULL) {
- xmlSchemaFreeValue(vctxt->value);
- vctxt->value = NULL;
- }
-
- if (vctxt->aidcs != NULL) {
- xmlSchemaIDCAugPtr cur = vctxt->aidcs, next;
- do {
- next = cur->next;
- xmlFree(cur);
- cur = next;
- } while (cur != NULL);
- vctxt->aidcs = NULL;
- }
- if (vctxt->idcMatcherCache != NULL) {
- xmlSchemaIDCMatcherPtr matcher = vctxt->idcMatcherCache, tmp;
- while (matcher) {
- tmp = matcher;
- matcher = matcher->nextCached;
- xmlSchemaIDCFreeMatcherList(tmp);
- }
- vctxt->idcMatcherCache = NULL;
- }
- if (vctxt->idcNodes != NULL) {
- int i;
- xmlSchemaPSVIIDCNodePtr item;
- for (i = 0; i < vctxt->nbIdcNodes; i++) {
- item = vctxt->idcNodes[i];
- xmlFree(item->keys);
- xmlFree(item);
- }
- xmlFree(vctxt->idcNodes);
- vctxt->idcNodes = NULL;
- vctxt->nbIdcNodes = 0;
- vctxt->sizeIdcNodes = 0;
- }
-
- if (vctxt->xpathStates != NULL) {
- xmlSchemaFreeIDCStateObjList(vctxt->xpathStates);
- vctxt->xpathStates = NULL;
- }
-
- if (vctxt->nbAttrInfos != 0) {
- xmlSchemaClearAttrInfos(vctxt);
- }
-
- if (vctxt->elemInfos != NULL) {
- int i;
- xmlSchemaNodeInfoPtr ei;
- for (i = 0; i < vctxt->sizeElemInfos; i++) {
- ei = vctxt->elemInfos[i];
- if (ei == NULL)
- break;
- xmlSchemaClearElemInfo(vctxt, ei);
- }
- }
- xmlSchemaItemListClear(vctxt->nodeQNames);
-
- xmlDictFree(vctxt->dict);
-
- vctxt->dict = xmlDictCreate();
- }
- void
- xmlSchemaFreeValidCtxt(xmlSchemaValidCtxtPtr ctxt)
- {
- if (ctxt == NULL)
- return;
- if (ctxt->value != NULL)
- xmlSchemaFreeValue(ctxt->value);
- if (ctxt->pctxt != NULL)
- xmlSchemaFreeParserCtxt(ctxt->pctxt);
- if (ctxt->idcNodes != NULL) {
- int i;
- xmlSchemaPSVIIDCNodePtr item;
- for (i = 0; i < ctxt->nbIdcNodes; i++) {
- item = ctxt->idcNodes[i];
- xmlFree(item->keys);
- xmlFree(item);
- }
- xmlFree(ctxt->idcNodes);
- }
- if (ctxt->idcKeys != NULL) {
- int i;
- for (i = 0; i < ctxt->nbIdcKeys; i++)
- xmlSchemaIDCFreeKey(ctxt->idcKeys[i]);
- xmlFree(ctxt->idcKeys);
- }
- if (ctxt->xpathStates != NULL) {
- xmlSchemaFreeIDCStateObjList(ctxt->xpathStates);
- ctxt->xpathStates = NULL;
- }
- if (ctxt->xpathStatePool != NULL) {
- xmlSchemaFreeIDCStateObjList(ctxt->xpathStatePool);
- ctxt->xpathStatePool = NULL;
- }
-
- if (ctxt->aidcs != NULL) {
- xmlSchemaIDCAugPtr cur = ctxt->aidcs, next;
- do {
- next = cur->next;
- xmlFree(cur);
- cur = next;
- } while (cur != NULL);
- }
- if (ctxt->attrInfos != NULL) {
- int i;
- xmlSchemaAttrInfoPtr attr;
-
- if (ctxt->nbAttrInfos != 0)
- xmlSchemaClearAttrInfos(ctxt);
- for (i = 0; i < ctxt->sizeAttrInfos; i++) {
- attr = ctxt->attrInfos[i];
- xmlFree(attr);
- }
- xmlFree(ctxt->attrInfos);
- }
- if (ctxt->elemInfos != NULL) {
- int i;
- xmlSchemaNodeInfoPtr ei;
- for (i = 0; i < ctxt->sizeElemInfos; i++) {
- ei = ctxt->elemInfos[i];
- if (ei == NULL)
- break;
- xmlSchemaClearElemInfo(ctxt, ei);
- xmlFree(ei);
- }
- xmlFree(ctxt->elemInfos);
- }
- if (ctxt->nodeQNames != NULL)
- xmlSchemaItemListFree(ctxt->nodeQNames);
- if (ctxt->dict != NULL)
- xmlDictFree(ctxt->dict);
- xmlFree(ctxt);
- }
- int
- xmlSchemaIsValid(xmlSchemaValidCtxtPtr ctxt)
- {
- if (ctxt == NULL)
- return(-1);
- return(ctxt->err == 0);
- }
- void
- xmlSchemaSetValidErrors(xmlSchemaValidCtxtPtr ctxt,
- xmlSchemaValidityErrorFunc err,
- xmlSchemaValidityWarningFunc warn, void *ctx)
- {
- if (ctxt == NULL)
- return;
- ctxt->error = err;
- ctxt->warning = warn;
- ctxt->errCtxt = ctx;
- if (ctxt->pctxt != NULL)
- xmlSchemaSetParserErrors(ctxt->pctxt, err, warn, ctx);
- }
- void
- xmlSchemaSetValidStructuredErrors(xmlSchemaValidCtxtPtr ctxt,
- xmlStructuredErrorFunc serror, void *ctx)
- {
- if (ctxt == NULL)
- return;
- ctxt->serror = serror;
- ctxt->error = NULL;
- ctxt->warning = NULL;
- ctxt->errCtxt = ctx;
- if (ctxt->pctxt != NULL)
- xmlSchemaSetParserStructuredErrors(ctxt->pctxt, serror, ctx);
- }
- int
- xmlSchemaGetValidErrors(xmlSchemaValidCtxtPtr ctxt,
- xmlSchemaValidityErrorFunc * err,
- xmlSchemaValidityWarningFunc * warn, void **ctx)
- {
- if (ctxt == NULL)
- return (-1);
- if (err != NULL)
- *err = ctxt->error;
- if (warn != NULL)
- *warn = ctxt->warning;
- if (ctx != NULL)
- *ctx = ctxt->errCtxt;
- return (0);
- }
- int
- xmlSchemaSetValidOptions(xmlSchemaValidCtxtPtr ctxt,
- int options)
- {
- int i;
- if (ctxt == NULL)
- return (-1);
-
- for (i = 1; i < (int) sizeof(int) * 8; i++) {
- if (options & 1<<i)
- return (-1);
- }
- ctxt->options = options;
- return (0);
- }
- int
- xmlSchemaValidCtxtGetOptions(xmlSchemaValidCtxtPtr ctxt)
- {
- if (ctxt == NULL)
- return (-1);
- else
- return (ctxt->options);
- }
- static int
- xmlSchemaVDocWalk(xmlSchemaValidCtxtPtr vctxt)
- {
- xmlAttrPtr attr;
- int ret = 0;
- xmlSchemaNodeInfoPtr ielem = NULL;
- xmlNodePtr node, valRoot;
- const xmlChar *nsName;
-
- valRoot = xmlDocGetRootElement(vctxt->doc);
- if (valRoot == NULL) {
-
- VERROR(1, NULL, "The document has no document element");
- return (1);
- }
- vctxt->depth = -1;
- vctxt->validationRoot = valRoot;
- node = valRoot;
- while (node != NULL) {
- if ((vctxt->skipDepth != -1) && (vctxt->depth >= vctxt->skipDepth))
- goto next_sibling;
- if (node->type == XML_ELEMENT_NODE) {
-
- vctxt->depth++;
- if (xmlSchemaValidatorPushElem(vctxt) == -1)
- goto internal_error;
- ielem = vctxt->inode;
- ielem->node = node;
- ielem->nodeLine = node->line;
- ielem->localName = node->name;
- if (node->ns != NULL)
- ielem->nsName = node->ns->href;
- ielem->flags |= XML_SCHEMA_ELEM_INFO_EMPTY;
-
- vctxt->nbAttrInfos = 0;
- if (node->properties != NULL) {
- attr = node->properties;
- do {
- if (attr->ns != NULL)
- nsName = attr->ns->href;
- else
- nsName = NULL;
- ret = xmlSchemaValidatorPushAttribute(vctxt,
- (xmlNodePtr) attr,
-
- ielem->nodeLine,
- attr->name, nsName, 0,
- xmlNodeListGetString(attr->doc, attr->children, 1), 1);
- if (ret == -1) {
- VERROR_INT("xmlSchemaDocWalk",
- "calling xmlSchemaValidatorPushAttribute()");
- goto internal_error;
- }
- attr = attr->next;
- } while (attr);
- }
-
- ret = xmlSchemaValidateElem(vctxt);
- if (ret != 0) {
- if (ret == -1) {
- VERROR_INT("xmlSchemaDocWalk",
- "calling xmlSchemaValidateElem()");
- goto internal_error;
- }
-
- goto leave_node;
- }
- if ((vctxt->skipDepth != -1) &&
- (vctxt->depth >= vctxt->skipDepth))
- goto leave_node;
- } else if ((node->type == XML_TEXT_NODE) ||
- (node->type == XML_CDATA_SECTION_NODE)) {
-
- if ((ielem != NULL) && (ielem->flags & XML_SCHEMA_ELEM_INFO_EMPTY))
- ielem->flags ^= XML_SCHEMA_ELEM_INFO_EMPTY;
- ret = xmlSchemaVPushText(vctxt, node->type, node->content,
- -1, XML_SCHEMA_PUSH_TEXT_PERSIST, NULL);
- if (ret < 0) {
- VERROR_INT("xmlSchemaVDocWalk",
- "calling xmlSchemaVPushText()");
- goto internal_error;
- }
-
- } else if ((node->type == XML_ENTITY_NODE) ||
- (node->type == XML_ENTITY_REF_NODE)) {
-
- VERROR_INT("xmlSchemaVDocWalk",
- "there is at least one entity reference in the node-tree "
- "currently being validated. Processing of entities with "
- "this XML Schema processor is not supported (yet). Please "
- "substitute entities before validation.");
- goto internal_error;
- } else {
- goto leave_node;
-
- }
-
- if (node->children != NULL) {
- node = node->children;
- continue;
- }
- leave_node:
- if (node->type == XML_ELEMENT_NODE) {
-
- if (node != vctxt->inode->node) {
- VERROR_INT("xmlSchemaVDocWalk",
- "element position mismatch");
- goto internal_error;
- }
- ret = xmlSchemaValidatorPopElem(vctxt);
- if (ret != 0) {
- if (ret < 0) {
- VERROR_INT("xmlSchemaVDocWalk",
- "calling xmlSchemaValidatorPopElem()");
- goto internal_error;
- }
- }
- if (node == valRoot)
- goto exit;
- }
- next_sibling:
- if (node->next != NULL)
- node = node->next;
- else {
- node = node->parent;
- goto leave_node;
- }
- }
- exit:
- return (ret);
- internal_error:
- return (-1);
- }
- static int
- xmlSchemaPreRun(xmlSchemaValidCtxtPtr vctxt) {
-
- vctxt->err = 0;
- vctxt->nberrors = 0;
- vctxt->depth = -1;
- vctxt->skipDepth = -1;
- vctxt->xsiAssemble = 0;
- vctxt->hasKeyrefs = 0;
- #ifdef ENABLE_IDC_NODE_TABLES_TEST
- vctxt->createIDCNodeTables = 1;
- #else
- vctxt->createIDCNodeTables = 0;
- #endif
-
- if (vctxt->schema == NULL) {
- xmlSchemaParserCtxtPtr pctxt;
- vctxt->xsiAssemble = 1;
-
- if ((vctxt->pctxt == NULL) &&
- (xmlSchemaCreatePCtxtOnVCtxt(vctxt) == -1))
- return (-1);
- pctxt = vctxt->pctxt;
- pctxt->xsiAssemble = 1;
-
- vctxt->schema = xmlSchemaNewSchema(pctxt);
- if (vctxt->schema == NULL)
- return (-1);
-
- pctxt->constructor = xmlSchemaConstructionCtxtCreate(pctxt->dict);
- if (pctxt->constructor == NULL)
- return(-1);
- pctxt->constructor->mainSchema = vctxt->schema;
-
- pctxt->ownsConstructor = 1;
- }
-
- xmlHashScan(vctxt->schema->schemasImports,(xmlHashScanner)xmlSchemaAugmentImportedIDC, vctxt);
- return(0);
- }
- static void
- xmlSchemaPostRun(xmlSchemaValidCtxtPtr vctxt) {
- if (vctxt->xsiAssemble) {
- if (vctxt->schema != NULL) {
- xmlSchemaFree(vctxt->schema);
- vctxt->schema = NULL;
- }
- }
- xmlSchemaClearValidCtxt(vctxt);
- }
- static int
- xmlSchemaVStart(xmlSchemaValidCtxtPtr vctxt)
- {
- int ret = 0;
- if (xmlSchemaPreRun(vctxt) < 0)
- return(-1);
- if (vctxt->doc != NULL) {
-
- ret = xmlSchemaVDocWalk(vctxt);
- #ifdef LIBXML_READER_ENABLED
- } else if (vctxt->reader != NULL) {
-
- #ifdef XML_SCHEMA_READER_ENABLED
- ret = xmlSchemaVReaderWalk(vctxt);
- #endif
- #endif
- } else if ((vctxt->sax != NULL) && (vctxt->parserCtxt != NULL)) {
-
- ret = xmlParseDocument(vctxt->parserCtxt);
- } else {
- VERROR_INT("xmlSchemaVStart",
- "no instance to validate");
- ret = -1;
- }
- xmlSchemaPostRun(vctxt);
- if (ret == 0)
- ret = vctxt->err;
- return (ret);
- }
- int
- xmlSchemaValidateOneElement(xmlSchemaValidCtxtPtr ctxt, xmlNodePtr elem)
- {
- if ((ctxt == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE))
- return (-1);
- if (ctxt->schema == NULL)
- return (-1);
- ctxt->doc = elem->doc;
- ctxt->node = elem;
- ctxt->validationRoot = elem;
- return(xmlSchemaVStart(ctxt));
- }
- int
- xmlSchemaValidateDoc(xmlSchemaValidCtxtPtr ctxt, xmlDocPtr doc)
- {
- if ((ctxt == NULL) || (doc == NULL))
- return (-1);
- ctxt->doc = doc;
- ctxt->node = xmlDocGetRootElement(doc);
- if (ctxt->node == NULL) {
- xmlSchemaCustomErr(ACTXT_CAST ctxt,
- XML_SCHEMAV_DOCUMENT_ELEMENT_MISSING,
- (xmlNodePtr) doc, NULL,
- "The document has no document element", NULL, NULL);
- return (ctxt->err);
- }
- ctxt->validationRoot = ctxt->node;
- return (xmlSchemaVStart(ctxt));
- }
- typedef struct _xmlSchemaSplitSAXData xmlSchemaSplitSAXData;
- typedef xmlSchemaSplitSAXData *xmlSchemaSplitSAXDataPtr;
- struct _xmlSchemaSplitSAXData {
- xmlSAXHandlerPtr user_sax;
- void *user_data;
- xmlSchemaValidCtxtPtr ctxt;
- xmlSAXHandlerPtr schemas_sax;
- };
- #define XML_SAX_PLUG_MAGIC 0xdc43ba21
- struct _xmlSchemaSAXPlug {
- unsigned int magic;
-
- xmlSAXHandlerPtr *user_sax_ptr;
- xmlSAXHandlerPtr user_sax;
- void **user_data_ptr;
- void *user_data;
-
- xmlSAXHandler schemas_sax;
- xmlSchemaValidCtxtPtr ctxt;
- };
- static void
- internalSubsetSplit(void *ctx, const xmlChar *name,
- const xmlChar *ExternalID, const xmlChar *SystemID)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->internalSubset != NULL))
- ctxt->user_sax->internalSubset(ctxt->user_data, name, ExternalID,
- SystemID);
- }
- static int
- isStandaloneSplit(void *ctx)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->isStandalone != NULL))
- return(ctxt->user_sax->isStandalone(ctxt->user_data));
- return(0);
- }
- static int
- hasInternalSubsetSplit(void *ctx)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->hasInternalSubset != NULL))
- return(ctxt->user_sax->hasInternalSubset(ctxt->user_data));
- return(0);
- }
- static int
- hasExternalSubsetSplit(void *ctx)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->hasExternalSubset != NULL))
- return(ctxt->user_sax->hasExternalSubset(ctxt->user_data));
- return(0);
- }
- static void
- externalSubsetSplit(void *ctx, const xmlChar *name,
- const xmlChar *ExternalID, const xmlChar *SystemID)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->externalSubset != NULL))
- ctxt->user_sax->externalSubset(ctxt->user_data, name, ExternalID,
- SystemID);
- }
- static xmlParserInputPtr
- resolveEntitySplit(void *ctx, const xmlChar *publicId, const xmlChar *systemId)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->resolveEntity != NULL))
- return(ctxt->user_sax->resolveEntity(ctxt->user_data, publicId,
- systemId));
- return(NULL);
- }
- static xmlEntityPtr
- getEntitySplit(void *ctx, const xmlChar *name)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->getEntity != NULL))
- return(ctxt->user_sax->getEntity(ctxt->user_data, name));
- return(NULL);
- }
- static xmlEntityPtr
- getParameterEntitySplit(void *ctx, const xmlChar *name)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->getParameterEntity != NULL))
- return(ctxt->user_sax->getParameterEntity(ctxt->user_data, name));
- return(NULL);
- }
- static void
- entityDeclSplit(void *ctx, const xmlChar *name, int type,
- const xmlChar *publicId, const xmlChar *systemId, xmlChar *content)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->entityDecl != NULL))
- ctxt->user_sax->entityDecl(ctxt->user_data, name, type, publicId,
- systemId, content);
- }
- static void
- attributeDeclSplit(void *ctx, const xmlChar * elem,
- const xmlChar * name, int type, int def,
- const xmlChar * defaultValue, xmlEnumerationPtr tree)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->attributeDecl != NULL)) {
- ctxt->user_sax->attributeDecl(ctxt->user_data, elem, name, type,
- def, defaultValue, tree);
- } else {
- xmlFreeEnumeration(tree);
- }
- }
- static void
- elementDeclSplit(void *ctx, const xmlChar *name, int type,
- xmlElementContentPtr content)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->elementDecl != NULL))
- ctxt->user_sax->elementDecl(ctxt->user_data, name, type, content);
- }
- static void
- notationDeclSplit(void *ctx, const xmlChar *name,
- const xmlChar *publicId, const xmlChar *systemId)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->notationDecl != NULL))
- ctxt->user_sax->notationDecl(ctxt->user_data, name, publicId,
- systemId);
- }
- static void
- unparsedEntityDeclSplit(void *ctx, const xmlChar *name,
- const xmlChar *publicId, const xmlChar *systemId,
- const xmlChar *notationName)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->unparsedEntityDecl != NULL))
- ctxt->user_sax->unparsedEntityDecl(ctxt->user_data, name, publicId,
- systemId, notationName);
- }
- static void
- setDocumentLocatorSplit(void *ctx, xmlSAXLocatorPtr loc)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->setDocumentLocator != NULL))
- ctxt->user_sax->setDocumentLocator(ctxt->user_data, loc);
- }
- static void
- startDocumentSplit(void *ctx)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->startDocument != NULL))
- ctxt->user_sax->startDocument(ctxt->user_data);
- }
- static void
- endDocumentSplit(void *ctx)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->endDocument != NULL))
- ctxt->user_sax->endDocument(ctxt->user_data);
- }
- static void
- processingInstructionSplit(void *ctx, const xmlChar *target,
- const xmlChar *data)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->processingInstruction != NULL))
- ctxt->user_sax->processingInstruction(ctxt->user_data, target, data);
- }
- static void
- commentSplit(void *ctx, const xmlChar *value)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->comment != NULL))
- ctxt->user_sax->comment(ctxt->user_data, value);
- }
- static void XMLCDECL
- warningSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->warning != NULL)) {
- TODO
- }
- }
- static void XMLCDECL
- errorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->error != NULL)) {
- TODO
- }
- }
- static void XMLCDECL
- fatalErrorSplit(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...) {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->fatalError != NULL)) {
- TODO
- }
- }
- static void
- charactersSplit(void *ctx, const xmlChar *ch, int len)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if (ctxt == NULL)
- return;
- if ((ctxt->user_sax != NULL) && (ctxt->user_sax->characters != NULL))
- ctxt->user_sax->characters(ctxt->user_data, ch, len);
- if (ctxt->ctxt != NULL)
- xmlSchemaSAXHandleText(ctxt->ctxt, ch, len);
- }
- static void
- ignorableWhitespaceSplit(void *ctx, const xmlChar *ch, int len)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if (ctxt == NULL)
- return;
- if ((ctxt->user_sax != NULL) &&
- (ctxt->user_sax->ignorableWhitespace != NULL))
- ctxt->user_sax->ignorableWhitespace(ctxt->user_data, ch, len);
- if (ctxt->ctxt != NULL)
- xmlSchemaSAXHandleText(ctxt->ctxt, ch, len);
- }
- static void
- cdataBlockSplit(void *ctx, const xmlChar *value, int len)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if (ctxt == NULL)
- return;
- if ((ctxt->user_sax != NULL) &&
- (ctxt->user_sax->cdataBlock != NULL))
- ctxt->user_sax->cdataBlock(ctxt->user_data, value, len);
- if (ctxt->ctxt != NULL)
- xmlSchemaSAXHandleCDataSection(ctxt->ctxt, value, len);
- }
- static void
- referenceSplit(void *ctx, const xmlChar *name)
- {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if (ctxt == NULL)
- return;
- if ((ctxt != NULL) && (ctxt->user_sax != NULL) &&
- (ctxt->user_sax->reference != NULL))
- ctxt->user_sax->reference(ctxt->user_data, name);
- if (ctxt->ctxt != NULL)
- xmlSchemaSAXHandleReference(ctxt->user_data, name);
- }
- static void
- startElementNsSplit(void *ctx, const xmlChar * localname,
- const xmlChar * prefix, const xmlChar * URI,
- int nb_namespaces, const xmlChar ** namespaces,
- int nb_attributes, int nb_defaulted,
- const xmlChar ** attributes) {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if (ctxt == NULL)
- return;
- if ((ctxt->user_sax != NULL) &&
- (ctxt->user_sax->startElementNs != NULL))
- ctxt->user_sax->startElementNs(ctxt->user_data, localname, prefix,
- URI, nb_namespaces, namespaces,
- nb_attributes, nb_defaulted,
- attributes);
- if (ctxt->ctxt != NULL)
- xmlSchemaSAXHandleStartElementNs(ctxt->ctxt, localname, prefix,
- URI, nb_namespaces, namespaces,
- nb_attributes, nb_defaulted,
- attributes);
- }
- static void
- endElementNsSplit(void *ctx, const xmlChar * localname,
- const xmlChar * prefix, const xmlChar * URI) {
- xmlSchemaSAXPlugPtr ctxt = (xmlSchemaSAXPlugPtr) ctx;
- if (ctxt == NULL)
- return;
- if ((ctxt->user_sax != NULL) &&
- (ctxt->user_sax->endElementNs != NULL))
- ctxt->user_sax->endElementNs(ctxt->user_data, localname, prefix, URI);
- if (ctxt->ctxt != NULL)
- xmlSchemaSAXHandleEndElementNs(ctxt->ctxt, localname, prefix, URI);
- }
- xmlSchemaSAXPlugPtr
- xmlSchemaSAXPlug(xmlSchemaValidCtxtPtr ctxt,
- xmlSAXHandlerPtr *sax, void **user_data)
- {
- xmlSchemaSAXPlugPtr ret;
- xmlSAXHandlerPtr old_sax;
- if ((ctxt == NULL) || (sax == NULL) || (user_data == NULL))
- return(NULL);
-
- old_sax = *sax;
- if ((old_sax != NULL) && (old_sax->initialized != XML_SAX2_MAGIC))
- return(NULL);
- if ((old_sax != NULL) &&
- (old_sax->startElementNs == NULL) && (old_sax->endElementNs == NULL) &&
- ((old_sax->startElement != NULL) || (old_sax->endElement != NULL)))
- return(NULL);
-
- ret = (xmlSchemaSAXPlugPtr) xmlMalloc(sizeof(xmlSchemaSAXPlugStruct));
- if (ret == NULL) {
- return(NULL);
- }
- memset(ret, 0, sizeof(xmlSchemaSAXPlugStruct));
- ret->magic = XML_SAX_PLUG_MAGIC;
- ret->schemas_sax.initialized = XML_SAX2_MAGIC;
- ret->ctxt = ctxt;
- ret->user_sax_ptr = sax;
- ret->user_sax = old_sax;
- if (old_sax == NULL) {
-
- ret->schemas_sax.startElementNs = xmlSchemaSAXHandleStartElementNs;
- ret->schemas_sax.endElementNs = xmlSchemaSAXHandleEndElementNs;
-
- ret->schemas_sax.ignorableWhitespace = xmlSchemaSAXHandleText;
- ret->schemas_sax.characters = xmlSchemaSAXHandleText;
- ret->schemas_sax.cdataBlock = xmlSchemaSAXHandleCDataSection;
- ret->schemas_sax.reference = xmlSchemaSAXHandleReference;
- ret->user_data = ctxt;
- *user_data = ctxt;
- } else {
-
- if (old_sax->internalSubset != NULL)
- ret->schemas_sax.internalSubset = internalSubsetSplit;
- if (old_sax->isStandalone != NULL)
- ret->schemas_sax.isStandalone = isStandaloneSplit;
- if (old_sax->hasInternalSubset != NULL)
- ret->schemas_sax.hasInternalSubset = hasInternalSubsetSplit;
- if (old_sax->hasExternalSubset != NULL)
- ret->schemas_sax.hasExternalSubset = hasExternalSubsetSplit;
- if (old_sax->resolveEntity != NULL)
- ret->schemas_sax.resolveEntity = resolveEntitySplit;
- if (old_sax->getEntity != NULL)
- ret->schemas_sax.getEntity = getEntitySplit;
- if (old_sax->entityDecl != NULL)
- ret->schemas_sax.entityDecl = entityDeclSplit;
- if (old_sax->notationDecl != NULL)
- ret->schemas_sax.notationDecl = notationDeclSplit;
- if (old_sax->attributeDecl != NULL)
- ret->schemas_sax.attributeDecl = attributeDeclSplit;
- if (old_sax->elementDecl != NULL)
- ret->schemas_sax.elementDecl = elementDeclSplit;
- if (old_sax->unparsedEntityDecl != NULL)
- ret->schemas_sax.unparsedEntityDecl = unparsedEntityDeclSplit;
- if (old_sax->setDocumentLocator != NULL)
- ret->schemas_sax.setDocumentLocator = setDocumentLocatorSplit;
- if (old_sax->startDocument != NULL)
- ret->schemas_sax.startDocument = startDocumentSplit;
- if (old_sax->endDocument != NULL)
- ret->schemas_sax.endDocument = endDocumentSplit;
- if (old_sax->processingInstruction != NULL)
- ret->schemas_sax.processingInstruction = processingInstructionSplit;
- if (old_sax->comment != NULL)
- ret->schemas_sax.comment = commentSplit;
- if (old_sax->warning != NULL)
- ret->schemas_sax.warning = warningSplit;
- if (old_sax->error != NULL)
- ret->schemas_sax.error = errorSplit;
- if (old_sax->fatalError != NULL)
- ret->schemas_sax.fatalError = fatalErrorSplit;
- if (old_sax->getParameterEntity != NULL)
- ret->schemas_sax.getParameterEntity = getParameterEntitySplit;
- if (old_sax->externalSubset != NULL)
- ret->schemas_sax.externalSubset = externalSubsetSplit;
-
- ret->schemas_sax.characters = charactersSplit;
- if ((old_sax->ignorableWhitespace != NULL) &&
- (old_sax->ignorableWhitespace != old_sax->characters))
- ret->schemas_sax.ignorableWhitespace = ignorableWhitespaceSplit;
- else
- ret->schemas_sax.ignorableWhitespace = charactersSplit;
- ret->schemas_sax.cdataBlock = cdataBlockSplit;
- ret->schemas_sax.reference = referenceSplit;
- ret->schemas_sax.startElementNs = startElementNsSplit;
- ret->schemas_sax.endElementNs = endElementNsSplit;
- ret->user_data_ptr = user_data;
- ret->user_data = *user_data;
- *user_data = ret;
- }
-
- *sax = &(ret->schemas_sax);
- ctxt->sax = *sax;
- ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM;
- xmlSchemaPreRun(ctxt);
- return(ret);
- }
- int
- xmlSchemaSAXUnplug(xmlSchemaSAXPlugPtr plug)
- {
- xmlSAXHandlerPtr *sax;
- void **user_data;
- if ((plug == NULL) || (plug->magic != XML_SAX_PLUG_MAGIC))
- return(-1);
- plug->magic = 0;
- xmlSchemaPostRun(plug->ctxt);
-
- sax = plug->user_sax_ptr;
- *sax = plug->user_sax;
- if (plug->user_sax != NULL) {
- user_data = plug->user_data_ptr;
- *user_data = plug->user_data;
- }
-
- xmlFree(plug);
- return(0);
- }
- int
- xmlSchemaValidateStream(xmlSchemaValidCtxtPtr ctxt,
- xmlParserInputBufferPtr input, xmlCharEncoding enc,
- xmlSAXHandlerPtr sax, void *user_data)
- {
- xmlSchemaSAXPlugPtr plug = NULL;
- xmlSAXHandlerPtr old_sax = NULL;
- xmlParserCtxtPtr pctxt = NULL;
- xmlParserInputPtr inputStream = NULL;
- int ret;
- if ((ctxt == NULL) || (input == NULL))
- return (-1);
-
- pctxt = xmlNewParserCtxt();
- if (pctxt == NULL)
- return (-1);
- old_sax = pctxt->sax;
- pctxt->sax = sax;
- pctxt->userData = user_data;
- #if 0
- if (options)
- xmlCtxtUseOptions(pctxt, options);
- #endif
- pctxt->linenumbers = 1;
- inputStream = xmlNewIOInputStream(pctxt, input, enc);;
- if (inputStream == NULL) {
- ret = -1;
- goto done;
- }
- inputPush(pctxt, inputStream);
- ctxt->parserCtxt = pctxt;
- ctxt->input = input;
-
- plug = xmlSchemaSAXPlug(ctxt, &(pctxt->sax), &(pctxt->userData));
- if (plug == NULL) {
- ret = -1;
- goto done;
- }
- ctxt->input = input;
- ctxt->enc = enc;
- ctxt->sax = pctxt->sax;
- ctxt->flags |= XML_SCHEMA_VALID_CTXT_FLAG_STREAM;
- ret = xmlSchemaVStart(ctxt);
- if ((ret == 0) && (! ctxt->parserCtxt->wellFormed)) {
- ret = ctxt->parserCtxt->errNo;
- if (ret == 0)
- ret = 1;
- }
- done:
- ctxt->parserCtxt = NULL;
- ctxt->sax = NULL;
- ctxt->input = NULL;
- if (plug != NULL) {
- xmlSchemaSAXUnplug(plug);
- }
-
- if (pctxt != NULL) {
- pctxt->sax = old_sax;
- xmlFreeParserCtxt(pctxt);
- }
- return (ret);
- }
- int
- xmlSchemaValidateFile(xmlSchemaValidCtxtPtr ctxt,
- const char * filename,
- int options ATTRIBUTE_UNUSED)
- {
- int ret;
- xmlParserInputBufferPtr input;
- if ((ctxt == NULL) || (filename == NULL))
- return (-1);
- input = xmlParserInputBufferCreateFilename(filename,
- XML_CHAR_ENCODING_NONE);
- if (input == NULL)
- return (-1);
- ret = xmlSchemaValidateStream(ctxt, input, XML_CHAR_ENCODING_NONE,
- NULL, NULL);
- return (ret);
- }
- xmlParserCtxtPtr
- xmlSchemaValidCtxtGetParserCtxt(xmlSchemaValidCtxtPtr ctxt)
- {
- if (ctxt == NULL)
- return(NULL);
- return (ctxt->parserCtxt);
- }
- #define bottom_xmlschemas
- #include "elfgcchack.h"
- #endif
|