libfyaml.h 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428
  1. /*
  2. * libfyaml.h - Main header file of the public interface
  3. *
  4. * Copyright (c) 2019-2021 Pantelis Antoniou <pantelis.antoniou@konsulko.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * SPDX-License-Identifier: MIT
  25. */
  26. #ifndef LIBFYAML_H
  27. #define LIBFYAML_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include <stdint.h>
  32. #include <stdbool.h>
  33. #include <stddef.h>
  34. #include <stdarg.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <stdlib.h>
  38. #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
  39. #include <unistd.h>
  40. #define FY_ALLOCA(x) alloca(x)
  41. #elif defined(_MSC_VER)
  42. #include <BaseTsd.h>
  43. typedef SSIZE_T ssize_t;
  44. #define FY_ALLOCA(x) _alloca(x)
  45. #endif
  46. /* opaque types for the user */
  47. struct fy_token;
  48. struct fy_document_state;
  49. struct fy_parser;
  50. struct fy_emitter;
  51. struct fy_document;
  52. struct fy_node;
  53. struct fy_node_pair;
  54. struct fy_anchor;
  55. struct fy_node_mapping_sort_ctx;
  56. struct fy_token_iter;
  57. struct fy_diag;
  58. struct fy_path_parser;
  59. struct fy_path_expr;
  60. struct fy_path_exec;
  61. struct fy_path_component;
  62. struct fy_path;
  63. struct fy_document_iterator;
  64. #ifndef FY_BIT
  65. #define FY_BIT(x) (1U << (x))
  66. #endif
  67. /* NULL terminated string length specifier */
  68. #define FY_NT ((size_t)-1)
  69. #if defined(__GNUC__) && __GNUC__ >= 4
  70. #define FY_ATTRIBUTE(attr) __attribute ((attr))
  71. #define FY_EXPORT __attribute__ ((visibility ("default")))
  72. #define FY_DEPRECATED __attribute__ ((deprecated))
  73. #else
  74. #define FY_ATTRIBUTE(attr) /* nothing */
  75. #define FY_EXPORT /* nothing */
  76. #define FY_DEPRECATED /* nothing */
  77. #endif
  78. /* make a copy of an allocated string and return it on stack
  79. * note that this is a convenience, and should not be called
  80. * in a loop. The string is always '\0' terminated.
  81. * If the _str pointer is NULL, then NULL will be returned
  82. */
  83. #ifndef FY_ALLOCA_COPY_FREE
  84. #define FY_ALLOCA_COPY_FREE(_str, _len, _res) \
  85. do { \
  86. char *__res, *__str = (char*)(_str); \
  87. size_t __len = (size_t)(_len); \
  88. __res = NULL; \
  89. \
  90. if (__str) { \
  91. if (__len == FY_NT) \
  92. __len = strlen(__str); \
  93. __res = FY_ALLOCA(__len + 1); \
  94. memcpy(__res, __str, __len); \
  95. (__res[__len]) = '\0'; \
  96. free(__str); \
  97. } \
  98. *(_res) = __res; \
  99. } while(false)
  100. #endif
  101. /* same as above but when _str == NULL return "" */
  102. #ifndef FY_ALLOCA_COPY_FREE_NO_NULL
  103. #define FY_ALLOCA_COPY_FREE_NO_NULL(_str, _len, _res) \
  104. do { \
  105. FY_ALLOCA_COPY_FREE(_str, _len, _res); \
  106. if (!*(_res)) \
  107. *(_res) = ""; \
  108. } while(false)
  109. #endif
  110. /**
  111. * DOC: libfyaml public API
  112. *
  113. */
  114. /**
  115. * struct fy_version - The YAML version
  116. *
  117. * @major: Major version number
  118. * @minor: Major version number
  119. *
  120. * The parser fills it according to the \%YAML directive
  121. * found in the document.
  122. */
  123. struct fy_version {
  124. int major;
  125. int minor;
  126. };
  127. /* Build a fy_version * from the given major and minor */
  128. #define fy_version_make(_maj, _min) (&(struct fy_version){ (_maj), (_min) })
  129. /**
  130. * fy_version_compare() - Compare two yaml versions
  131. *
  132. * Compare the versions
  133. *
  134. * @va: The first version, if NULL use default version
  135. * @vb: The second version, if NULL use default version
  136. *
  137. * Returns:
  138. * 0 if versions are equal, > 0 if version va is higher than vb
  139. * < 0 if version va is lower than vb
  140. */
  141. int
  142. fy_version_compare(const struct fy_version *va, const struct fy_version *vb)
  143. FY_EXPORT;
  144. /**
  145. * fy_version_default() - Get the default version of the library
  146. *
  147. * Return the default version of the library, i.e. the highest
  148. * stable version that is supported.
  149. *
  150. * Returns:
  151. * The default YAML version of this library
  152. */
  153. const struct fy_version *
  154. fy_version_default(void)
  155. FY_EXPORT;
  156. /**
  157. * fy_version_is_supported() - Check if supported version
  158. *
  159. * Check if the given YAML version is supported.
  160. *
  161. * @vers: The version to check, NULL means default version.
  162. *
  163. * Returns:
  164. * true if version supported, false otherwise.
  165. */
  166. bool
  167. fy_version_is_supported(const struct fy_version *vers)
  168. FY_EXPORT;
  169. /**
  170. * fy_version_supported_iterate() - Iterate over the supported YAML versions
  171. *
  172. * This method iterates over the supported YAML versions of this ibrary.
  173. * The start of the iteration is signalled by a NULL in \*prevp.
  174. *
  175. * @prevp: The previous version iterator
  176. *
  177. * Returns:
  178. * The next node in sequence or NULL at the end of the sequence.
  179. */
  180. const struct fy_version *
  181. fy_version_supported_iterate(void **prevp)
  182. FY_EXPORT;
  183. /**
  184. * struct fy_tag - The YAML tag structure.
  185. *
  186. * @handle: Handle of the tag (i.e. `"!!"` )
  187. * @prefix: The prefix of the tag (i.e. `"tag:yaml.org,2002:"`
  188. *
  189. * The parser fills it according to the \%TAG directives
  190. * encountered during parsing.
  191. */
  192. struct fy_tag {
  193. const char *handle;
  194. const char *prefix;
  195. };
  196. /**
  197. * struct fy_mark - marker holding information about a location
  198. * in a &struct fy_input
  199. *
  200. * @input_pos: Position of the mark (from the start of the current input)
  201. * @line: Line position (0 index based)
  202. * @column: Column position (0 index based)
  203. */
  204. struct fy_mark {
  205. size_t input_pos;
  206. int line;
  207. int column;
  208. };
  209. /**
  210. * enum fy_error_type - The supported diagnostic/error types
  211. *
  212. * @FYET_DEBUG: Debug level (disabled if library is not compiled in debug mode)
  213. * @FYET_INFO: Informational level
  214. * @FYET_NOTICE: Notice level
  215. * @FYET_WARNING: Warning level
  216. * @FYET_ERROR: Error level - error reporting is using this level
  217. * @FYET_MAX: Non inclusive maximum fy_error_type value
  218. *
  219. */
  220. enum fy_error_type {
  221. FYET_DEBUG,
  222. FYET_INFO,
  223. FYET_NOTICE,
  224. FYET_WARNING,
  225. FYET_ERROR,
  226. FYET_MAX,
  227. };
  228. /**
  229. * enum fy_error_module - Module which generated the diagnostic/error
  230. *
  231. * @FYEM_UNKNOWN: Unknown, default if not specific
  232. * @FYEM_ATOM: Atom module, used by atom chunking
  233. * @FYEM_SCAN: Scanner module
  234. * @FYEM_PARSE: Parser module
  235. * @FYEM_DOC: Document module
  236. * @FYEM_BUILD: Build document module (after tree is constructed)
  237. * @FYEM_INTERNAL: Internal error/diagnostic module
  238. * @FYEM_SYSTEM: System error/diagnostic module
  239. * @FYEM_MAX: Non inclusive maximum fy_error_module value
  240. */
  241. enum fy_error_module {
  242. FYEM_UNKNOWN,
  243. FYEM_ATOM,
  244. FYEM_SCAN,
  245. FYEM_PARSE,
  246. FYEM_DOC,
  247. FYEM_BUILD,
  248. FYEM_INTERNAL,
  249. FYEM_SYSTEM,
  250. FYEM_MAX,
  251. };
  252. /* Shift amount of the default version */
  253. #define FYPCF_DEFAULT_VERSION_SHIFT 9
  254. /* Mask of the default version */
  255. #define FYPCF_DEFAULT_VERSION_MASK ((1U << 5) - 1)
  256. /* Build a default version */
  257. #define FYPCF_DEFAULT_VERSION(x) (((unsigned int)(x) & FYPCF_DEFAULT_VERSION_MASK) << FYPCF_DEFAULT_VERSION_SHIFT)
  258. /* Shift amount of the JSON input mode */
  259. #define FYPCF_JSON_SHIFT 16
  260. /* Mask of the JSON input mode */
  261. #define FYPCF_JSON_MASK ((1U << 2) - 1)
  262. /* Build a JSON input mode option */
  263. #define FYPCF_JSON(x) (((unsigned int)(x) & FYPCF_JSON_MASK) << FYPCF_JSON_SHIFT)
  264. /* guaranteed minimum depth limit for generated document */
  265. /* the actual limit is larger depending on the platform */
  266. #define FYPCF_GUARANTEED_MINIMUM_DEPTH_LIMIT 64
  267. /**
  268. * enum fy_parse_cfg_flags - Parse configuration flags
  269. *
  270. * These flags control the operation of the parse and the debugging
  271. * output/error reporting via filling in the &fy_parse_cfg->flags member.
  272. *
  273. * @FYPCF_QUIET: Quiet, do not output any information messages
  274. * @FYPCF_COLLECT_DIAG: Collect diagnostic/error messages
  275. * @FYPCF_RESOLVE_DOCUMENT: When producing documents, automatically resolve them
  276. * @FYPCF_DISABLE_MMAP_OPT: Disable mmap optimization
  277. * @FYPCF_DISABLE_RECYCLING: Disable recycling optimization
  278. * @FYPCF_PARSE_COMMENTS: Enable parsing of comments (experimental)
  279. * @FYPCF_DISABLE_DEPTH_LIMIT: Disable depth limit check, use with enlarged stack
  280. * @FYPCF_DISABLE_ACCELERATORS: Disable use of access accelerators (saves memory)
  281. * @FYPCF_DISABLE_BUFFERING: Disable use of buffering where possible
  282. * @FYPCF_DEFAULT_VERSION_AUTO: Automatically use the most recent version the library supports
  283. * @FYPCF_DEFAULT_VERSION_1_1: Default version is YAML 1.1
  284. * @FYPCF_DEFAULT_VERSION_1_2: Default version is YAML 1.2
  285. * @FYPCF_DEFAULT_VERSION_1_3: Default version is YAML 1.3 (experimental)
  286. * @FYPCF_SLOPPY_FLOW_INDENTATION: Allow sloppy indentation in flow mode
  287. * @FYPCF_PREFER_RECURSIVE: Prefer recursive algorighms instead of iterative whenever possible
  288. * @FYPCF_JSON_AUTO: Automatically enable JSON mode (when extension is .json)
  289. * @FYPCF_JSON_NONE: Never enable JSON input mode
  290. * @FYPCF_JSON_FORCE: Force JSON mode always
  291. * @FYPCF_YPATH_ALIASES: Enable YPATH aliases mode
  292. * @FYPCF_ALLOW_DUPLICATE_KEYS: Allow duplicate keys on mappings
  293. */
  294. enum fy_parse_cfg_flags {
  295. FYPCF_QUIET = FY_BIT(0),
  296. FYPCF_COLLECT_DIAG = FY_BIT(1),
  297. FYPCF_RESOLVE_DOCUMENT = FY_BIT(2),
  298. FYPCF_DISABLE_MMAP_OPT = FY_BIT(3),
  299. FYPCF_DISABLE_RECYCLING = FY_BIT(4),
  300. FYPCF_PARSE_COMMENTS = FY_BIT(5),
  301. FYPCF_DISABLE_DEPTH_LIMIT = FY_BIT(6),
  302. FYPCF_DISABLE_ACCELERATORS = FY_BIT(7),
  303. FYPCF_DISABLE_BUFFERING = FY_BIT(8),
  304. FYPCF_DEFAULT_VERSION_AUTO = FYPCF_DEFAULT_VERSION(0),
  305. FYPCF_DEFAULT_VERSION_1_1 = FYPCF_DEFAULT_VERSION(1),
  306. FYPCF_DEFAULT_VERSION_1_2 = FYPCF_DEFAULT_VERSION(2),
  307. FYPCF_DEFAULT_VERSION_1_3 = FYPCF_DEFAULT_VERSION(3),
  308. FYPCF_SLOPPY_FLOW_INDENTATION = FY_BIT(14),
  309. FYPCF_PREFER_RECURSIVE = FY_BIT(15),
  310. FYPCF_JSON_AUTO = FYPCF_JSON(0),
  311. FYPCF_JSON_NONE = FYPCF_JSON(1),
  312. FYPCF_JSON_FORCE = FYPCF_JSON(2),
  313. FYPCF_YPATH_ALIASES = FY_BIT(18),
  314. FYPCF_ALLOW_DUPLICATE_KEYS = FY_BIT(19),
  315. };
  316. #define FYPCF_DEFAULT_PARSE (0)
  317. #define FYPCF_DEFAULT_DOC (FYPCF_QUIET | FYPCF_DEFAULT_PARSE)
  318. /*
  319. * The FYPCF_DEBUG and FYPCF_COLOR flags have been removed, however
  320. * to help with backwards compatibility we will define them as 0
  321. * so that code can continue to compile.
  322. *
  323. * You will need to eventualy modify the code if you actually depended
  324. * on the old behaviour.
  325. */
  326. #define FYPCF_MODULE_SHIFT 0
  327. #define FYPCF_MODULE_MASK 0
  328. #define FYPCF_DEBUG_LEVEL_SHIFT 0
  329. #define FYPCF_DEBUG_LEVEL_MASK 0
  330. #define FYPCF_DEBUG_LEVEL(x) 0
  331. #define FYPCF_DEBUG_DIAG_SHIFT 0
  332. #define FYPCF_DEBUG_DIAG_MASK 0
  333. #define FYPCF_DEBUG_DIAG_ALL 0
  334. #define FYPCF_DEBUG_DIAG_DEFAULT 0
  335. #define FYPCF_DEBUG_UNKNOWN 0
  336. #define FYPCF_DEBUG_ATOM 0
  337. #define FYPCF_DEBUG_SCAN 0
  338. #define FYPCF_DEBUG_PARSE 0
  339. #define FYPCF_DEBUG_DOC 0
  340. #define FYPCF_DEBUG_BUILD 0
  341. #define FYPCF_DEBUG_INTERNAL 0
  342. #define FYPCF_DEBUG_SYSTEM 0
  343. #define FYPCF_DEBUG_LEVEL_DEBUG 0
  344. #define FYPCF_DEBUG_LEVEL_INFO 0
  345. #define FYPCF_DEBUG_LEVEL_NOTICE 0
  346. #define FYPCF_DEBUG_LEVEL_WARNING 0
  347. #define FYPCF_DEBUG_LEVEL_ERROR 0
  348. #define FYPCF_DEBUG_DIAG_SOURCE 0
  349. #define FYPCF_DEBUG_DIAG_POSITION 0
  350. #define FYPCF_DEBUG_DIAG_TYPE 0
  351. #define FYPCF_DEBUG_DIAG_MODULE 0
  352. #define FYPCF_DEBUG_ALL 0
  353. #define FYPCF_DEBUG_DEFAULT 0
  354. #define FYPCF_COLOR_SHIFT 0
  355. #define FYPCF_COLOR_MASK 0
  356. #define FYPCF_COLOR(x) 0
  357. #define FYPCF_COLOR_AUTO 0
  358. #define FYPCF_COLOR_NONE 0
  359. #define FYPCF_COLOR_FORCE 0
  360. /**
  361. * struct fy_parse_cfg - parser configuration structure.
  362. *
  363. * Argument to the fy_parser_create() method which
  364. * perform parsing of YAML files.
  365. *
  366. * @search_path: Search path when accessing files, seperate with ':'
  367. * @flags: Configuration flags
  368. * @userdata: Opaque user data pointer
  369. * @diag: Optional diagnostic interface to use
  370. */
  371. struct fy_parse_cfg {
  372. const char *search_path;
  373. enum fy_parse_cfg_flags flags;
  374. void *userdata;
  375. struct fy_diag *diag;
  376. };
  377. /**
  378. * enum fy_event_type - Event types
  379. *
  380. * @FYET_NONE: No event
  381. * @FYET_STREAM_START: Stream start event
  382. * @FYET_STREAM_END: Stream end event
  383. * @FYET_DOCUMENT_START: Document start event
  384. * @FYET_DOCUMENT_END: Document end event
  385. * @FYET_MAPPING_START: YAML mapping start event
  386. * @FYET_MAPPING_END: YAML mapping end event
  387. * @FYET_SEQUENCE_START: YAML sequence start event
  388. * @FYET_SEQUENCE_END: YAML sequence end event
  389. * @FYET_SCALAR: YAML scalar event
  390. * @FYET_ALIAS: YAML alias event
  391. */
  392. enum fy_event_type {
  393. FYET_NONE,
  394. FYET_STREAM_START,
  395. FYET_STREAM_END,
  396. FYET_DOCUMENT_START,
  397. FYET_DOCUMENT_END,
  398. FYET_MAPPING_START,
  399. FYET_MAPPING_END,
  400. FYET_SEQUENCE_START,
  401. FYET_SEQUENCE_END,
  402. FYET_SCALAR,
  403. FYET_ALIAS,
  404. };
  405. /**
  406. * fy_event_type_get_text() - Return text of an event type
  407. *
  408. * @type: The event type to get text from
  409. *
  410. * Returns:
  411. * A pointer to a text, i.e for FYET_SCALAR "=VAL".
  412. */
  413. const char *
  414. fy_event_type_get_text(enum fy_event_type type)
  415. FY_EXPORT;
  416. /**
  417. * enum fy_scalar_style - Scalar styles supported by the parser/emitter
  418. *
  419. * @FYSS_ANY: Any scalar style, not generated by the parser.
  420. * Lets the emitter to choose
  421. * @FYSS_PLAIN: Plain scalar style
  422. * @FYSS_SINGLE_QUOTED: Single quoted style
  423. * @FYSS_DOUBLE_QUOTED: Double quoted style
  424. * @FYSS_LITERAL: YAML literal block style
  425. * @FYSS_FOLDED: YAML folded block style
  426. * @FYSS_MAX: marks end of scalar styles
  427. */
  428. enum fy_scalar_style {
  429. FYSS_ANY = -1,
  430. FYSS_PLAIN,
  431. FYSS_SINGLE_QUOTED,
  432. FYSS_DOUBLE_QUOTED,
  433. FYSS_LITERAL,
  434. FYSS_FOLDED,
  435. FYSS_MAX,
  436. };
  437. /**
  438. * struct fy_event_stream_start_data - stream start event data
  439. *
  440. * @stream_start: The token that started the stream
  441. */
  442. struct fy_event_stream_start_data {
  443. struct fy_token *stream_start;
  444. };
  445. /*
  446. * struct fy_event_stream_end_data - stream end event data
  447. *
  448. * @stream_end: The token that ended the stream
  449. */
  450. struct fy_event_stream_end_data {
  451. struct fy_token *stream_end;
  452. };
  453. /*
  454. * struct fy_event_document_start_data - doument start event data
  455. *
  456. * @document_start: The token that started the document, or NULL if
  457. * the document was implicitly started.
  458. * @document_state: The state of the document (i.e. information about
  459. * the YAML version and configured tags)
  460. * @implicit: True if the document started implicitly
  461. */
  462. struct fy_event_document_start_data {
  463. struct fy_token *document_start;
  464. struct fy_document_state *document_state;
  465. bool implicit;
  466. };
  467. /*
  468. * struct fy_event_document_end_data - doument end event data
  469. *
  470. * @document_end: The token that ended the document, or NULL if the
  471. * document was implicitly ended
  472. * @implicit: True if the document ended implicitly
  473. */
  474. struct fy_event_document_end_data {
  475. struct fy_token *document_end;
  476. bool implicit;
  477. };
  478. /*
  479. * struct fy_event_alias_data - alias event data
  480. *
  481. * @anchor: The anchor token definining this alias.
  482. */
  483. struct fy_event_alias_data {
  484. struct fy_token *anchor;
  485. };
  486. /*
  487. * struct fy_event_scalar_data - scalar event data
  488. *
  489. * @.anchor: anchor token or NULL
  490. * @tag: tag token or NULL
  491. * @value: scalar value token (cannot be NULL)
  492. * @tag_implicit: true if the tag was implicit or explicit
  493. */
  494. struct fy_event_scalar_data {
  495. struct fy_token *anchor;
  496. struct fy_token *tag;
  497. struct fy_token *value;
  498. bool tag_implicit;
  499. };
  500. /*
  501. * struct fy_event_sequence_start_data - sequence start event data
  502. *
  503. * @anchor: anchor token or NULL
  504. * @tag: tag token or NULL
  505. * @sequence_start: sequence start value token or NULL if the sequence
  506. * was started implicitly
  507. */
  508. struct fy_event_sequence_start_data {
  509. struct fy_token *anchor;
  510. struct fy_token *tag;
  511. struct fy_token *sequence_start;
  512. };
  513. /*
  514. * struct fy_event_sequence_end_data - sequence end event data
  515. *
  516. * @sequence_end: The token that ended the sequence, or NULL if
  517. * the sequence was implicitly ended
  518. */
  519. struct fy_event_sequence_end_data {
  520. struct fy_token *sequence_end;
  521. };
  522. /*
  523. * struct fy_event_mapping_start_data - mapping start event data
  524. *
  525. * @anchor: anchor token or NULL
  526. * @tag: tag token or NULL
  527. * @mapping_start: mapping start value token or NULL if the mapping
  528. * was started implicitly
  529. */
  530. struct fy_event_mapping_start_data {
  531. struct fy_token *anchor;
  532. struct fy_token *tag;
  533. struct fy_token *mapping_start;
  534. };
  535. /*
  536. * struct fy_event_mapping_end_data - mapping end event data
  537. *
  538. * @mapping_end: The token that ended the mapping, or NULL if
  539. * the mapping was implicitly ended
  540. */
  541. struct fy_event_mapping_end_data {
  542. struct fy_token *mapping_end;
  543. };
  544. /**
  545. * struct fy_event - Event generated by the parser
  546. *
  547. * This structure is generated by the parser by each call
  548. * to fy_parser_parse() and release by fy_parser_event_free()
  549. *
  550. * @type: Type of the event, see &enum fy_event_type
  551. *
  552. * @stream_start: Stream start information, it is valid when
  553. * &fy_event->type is &enum FYET_STREAM_START
  554. * @stream_end: Stream end information, it is valid when
  555. * &fy_event->type is &enum FYET_STREAM_END
  556. * @document_start: Document start information, it is valid when
  557. * &fy_event->type is &enum FYET_DOCUMENT_START
  558. * @document_end: Document end information, it is valid when
  559. * &fy_event->type is &enum FYET_DOCUMENT_END
  560. * @alias: Alias information, it is valid when
  561. * &fy_event->type is &enum FYET_ALIAS
  562. * @scalar: Scalar information, it is valid when
  563. * &fy_event->type is &enum FYET_SCALAR
  564. * @sequence_start: Sequence start information, it is valid when
  565. * &fy_event->type is &enum FYET_SEQUENCE_START
  566. * @sequence_end: Sequence end information, it is valid when
  567. * &fy_event->type is &enum FYET_SEQUENCE_END
  568. * @mapping_start: Mapping start information, it is valid when
  569. * &fy_event->type is &enum FYET_MAPPING_START
  570. * @mapping_end: Mapping end information, it is valid when
  571. * &fy_event->type is &enum FYET_MAPPING_END
  572. */
  573. struct fy_event {
  574. enum fy_event_type type;
  575. /* anonymous union */
  576. union {
  577. struct fy_event_stream_start_data stream_start;
  578. struct fy_event_stream_end_data stream_end;
  579. struct fy_event_document_start_data document_start;
  580. struct fy_event_document_end_data document_end;
  581. struct fy_event_alias_data alias;
  582. struct fy_event_scalar_data scalar;
  583. struct fy_event_sequence_start_data sequence_start;
  584. struct fy_event_sequence_end_data sequence_end;
  585. struct fy_event_mapping_start_data mapping_start;
  586. struct fy_event_mapping_end_data mapping_end;
  587. };
  588. };
  589. /**
  590. * fy_event_data() - Get a pointer to the event data
  591. *
  592. * Some languages *cough*golang*cough* really don't like
  593. * unions, and anonymous unions in particular.
  594. *
  595. * You should not have to use this in other language bindings.
  596. *
  597. * @fye: The event
  598. *
  599. * Returns:
  600. * A pointer to the event data structure, or NULL if the
  601. * event is invalid
  602. */
  603. static inline void *
  604. fy_event_data(struct fy_event *fye)
  605. {
  606. if (!fye)
  607. return NULL;
  608. /* note that the unions should all be laid out
  609. * at the same address, but play it straight and
  610. * hope the optimizer will figure this is all
  611. * the same...
  612. */
  613. switch (fye->type) {
  614. case FYET_STREAM_START:
  615. return &fye->stream_start;
  616. case FYET_STREAM_END:
  617. return &fye->stream_end;
  618. case FYET_DOCUMENT_START:
  619. return &fye->document_start;
  620. case FYET_DOCUMENT_END:
  621. return &fye->document_end;
  622. case FYET_ALIAS:
  623. return &fye->alias;
  624. case FYET_SCALAR:
  625. return &fye->scalar;
  626. case FYET_SEQUENCE_START:
  627. return &fye->sequence_start;
  628. case FYET_SEQUENCE_END:
  629. return &fye->sequence_end;
  630. case FYET_MAPPING_START:
  631. return &fye->mapping_start;
  632. case FYET_MAPPING_END:
  633. return &fye->mapping_end;
  634. default:
  635. break;
  636. }
  637. return NULL;
  638. }
  639. /**
  640. * fy_library_version() - Return the library version string
  641. *
  642. * Returns:
  643. * A pointer to a version string of the form
  644. * <MAJOR>.<MINOR>[[.<PATCH>][-EXTRA-VERSION-INFO]]
  645. */
  646. const char *
  647. fy_library_version(void)
  648. FY_EXPORT;
  649. /**
  650. * fy_string_to_error_type() - Return the error type from a string
  651. *
  652. * @str: The string to convert to an error type
  653. *
  654. * Returns:
  655. * The error type if greater or equal to zero, FYET_MAX otherwise
  656. */
  657. enum fy_error_type fy_string_to_error_type(const char *str)
  658. FY_EXPORT;
  659. /**
  660. * fy_error_type_to_string() - Convert an error type to string
  661. *
  662. * @type: The error type to convert
  663. *
  664. * Returns:
  665. * The string value of the error type or the empty string "" on error
  666. */
  667. const char *fy_error_type_to_string(enum fy_error_type type)
  668. FY_EXPORT;
  669. /**
  670. * fy_string_to_error_module() - Return the error module from a string
  671. *
  672. * @str: The string to convert to an error module
  673. *
  674. * Returns:
  675. * The error type if greater or equal to zero, FYEM_MAX otherwise
  676. */
  677. enum fy_error_module fy_string_to_error_module(const char *str)
  678. FY_EXPORT;
  679. /**
  680. * fy_error_module_to_string() - Convert an error module to string
  681. *
  682. * @module: The error module to convert
  683. *
  684. * Returns:
  685. * The string value of the error module or the empty string "" on error
  686. */
  687. const char *fy_error_module_to_string(enum fy_error_module module)
  688. FY_EXPORT;
  689. /**
  690. * fy_event_is_implicit() - Check whether the given event is an implicit one
  691. *
  692. * @fye: A pointer to a &struct fy_event to check.
  693. *
  694. * Returns:
  695. * true if the event is an implicit one.
  696. */
  697. bool
  698. fy_event_is_implicit(struct fy_event *fye)
  699. FY_EXPORT;
  700. /**
  701. * fy_document_event_is_implicit() - Check whether the given document event is an implicit one
  702. *
  703. * @fye: A pointer to a &struct fy_event to check.
  704. * It must be either a document start or document end event.
  705. *
  706. * Returns:
  707. * true if the event is an implicit one.
  708. */
  709. bool
  710. fy_document_event_is_implicit(const struct fy_event *fye)
  711. FY_EXPORT;
  712. /**
  713. * fy_parser_create() - Create a parser.
  714. *
  715. * Creates a parser with its configuration @cfg
  716. * The parser may be destroyed by a corresponding call to
  717. * fy_parser_destroy().
  718. *
  719. * @cfg: The configuration for the parser
  720. *
  721. * Returns:
  722. * A pointer to the parser or NULL in case of an error.
  723. */
  724. struct fy_parser *
  725. fy_parser_create(const struct fy_parse_cfg *cfg)
  726. FY_EXPORT;
  727. /**
  728. * fy_parser_destroy() - Destroy the given parser
  729. *
  730. * Destroy a parser created earlier via fy_parser_create().
  731. *
  732. * @fyp: The parser to destroy
  733. */
  734. void
  735. fy_parser_destroy(struct fy_parser *fyp)
  736. FY_EXPORT;
  737. /**
  738. * fy_parser_get_cfg() - Get the configuration of a parser
  739. *
  740. * @fyp: The parser
  741. *
  742. * Returns:
  743. * The configuration of the parser
  744. */
  745. const struct fy_parse_cfg *
  746. fy_parser_get_cfg(struct fy_parser *fyp)
  747. FY_EXPORT;
  748. /**
  749. * fy_parser_get_diag() - Get the diagnostic object of a parser
  750. *
  751. * Return a pointer to the diagnostic object of a parser object.
  752. * Note that the returned diag object has a reference taken so
  753. * you should fy_diag_unref() it when you're done with it.
  754. *
  755. * @fyp: The parser to get the diagnostic object
  756. *
  757. * Returns:
  758. * A pointer to a ref'ed diagnostic object or NULL in case of an
  759. * error.
  760. */
  761. struct fy_diag *
  762. fy_parser_get_diag(struct fy_parser *fyp)
  763. FY_EXPORT;
  764. /**
  765. * fy_parser_set_diag() - Set the diagnostic object of a parser
  766. *
  767. * Replace the parser's current diagnostic object with the one
  768. * given as an argument. The previous diagnostic object will be
  769. * unref'ed (and freed if its reference gets to 0).
  770. * Also note that the diag argument shall take a reference too.
  771. *
  772. * @fyp: The parser to replace the diagnostic object
  773. * @diag: The parser's new diagnostic object, NULL for default
  774. *
  775. * Returns:
  776. * 0 if everything OK, -1 otherwise
  777. */
  778. int
  779. fy_parser_set_diag(struct fy_parser *fyp, struct fy_diag *diag)
  780. FY_EXPORT;
  781. /**
  782. * fy_parser_reset() - Reset a parser completely
  783. *
  784. * Completely reset a parser, including after an error
  785. * that caused a parser error to be emitted.
  786. *
  787. * @fyp: The parser to reset
  788. *
  789. * Returns:
  790. * 0 if the reset was successful, -1 otherwise
  791. */
  792. int
  793. fy_parser_reset(struct fy_parser *fyp)
  794. FY_EXPORT;
  795. /**
  796. * fy_parser_set_input_file() - Set the parser to process the given file
  797. *
  798. * Point the parser to the given @file for processing. The file
  799. * is located by honoring the search path of the configuration set
  800. * by the earlier call to fy_parser_create().
  801. * While the parser is in use the file will must be available.
  802. *
  803. * @fyp: The parser
  804. * @file: The file to parse.
  805. *
  806. * Returns:
  807. * zero on success, -1 on error
  808. */
  809. int
  810. fy_parser_set_input_file(struct fy_parser *fyp, const char *file)
  811. FY_EXPORT;
  812. /**
  813. * fy_parser_set_string() - Set the parser to process the given string.
  814. *
  815. * Point the parser to the given (NULL terminated) string. Note that
  816. * while the parser is active the string must not go out of scope.
  817. *
  818. * @fyp: The parser
  819. * @str: The YAML string to parse.
  820. * @len: The length of the string (or -1 if '\0' terminated)
  821. *
  822. * Returns:
  823. * zero on success, -1 on error
  824. */
  825. int
  826. fy_parser_set_string(struct fy_parser *fyp, const char *str, size_t len)
  827. FY_EXPORT;
  828. /**
  829. * fy_parser_set_malloc_string() - Set the parser to process the given malloced string.
  830. *
  831. * Point the parser to the given (possible NULL terminated) string. Note that
  832. * the string is expected to be allocated via malloc(3) and ownership is transferred
  833. * to the created input. When the input is free'ed the memory will be automatically
  834. * freed.
  835. *
  836. * In case of an error the string is not freed.
  837. *
  838. * @fyp: The parser
  839. * @str: The YAML string to parse (allocated).
  840. * @len: The length of the string (or -1 if '\0' terminated)
  841. *
  842. * Returns:
  843. * zero on success, -1 on error
  844. */
  845. int
  846. fy_parser_set_malloc_string(struct fy_parser *fyp, char *str, size_t len)
  847. FY_EXPORT;
  848. /**
  849. * fy_parser_set_input_fp() - Set the parser to process the given file
  850. *
  851. * Point the parser to use @fp for processing.
  852. *
  853. * @fyp: The parser
  854. * @name: The label of the stream
  855. * @fp: The FILE pointer, it must be open in read mode.
  856. *
  857. * Returns:
  858. * zero on success, -1 on error
  859. */
  860. int
  861. fy_parser_set_input_fp(struct fy_parser *fyp, const char *name, FILE *fp)
  862. FY_EXPORT;
  863. /**
  864. * fy_parser_set_input_callback() - Set the parser to process via a callback
  865. *
  866. * Point the parser to use a callback for input.
  867. *
  868. * @fyp: The parser
  869. * @user: The user data pointer
  870. * @callback: The callback method to request data with
  871. *
  872. * Returns:
  873. * zero on success, -1 on error
  874. */
  875. int fy_parser_set_input_callback(struct fy_parser *fyp, void *user,
  876. ssize_t (*callback)(void *user, void *buf, size_t count))
  877. FY_EXPORT;
  878. /**
  879. * fy_parser_set_input_db() - Set the parser to process the given file descriptor
  880. *
  881. * Point the parser to use @fd for processing.
  882. *
  883. * @fyp: The parser
  884. * @fd: The file descriptor to use
  885. *
  886. * Returns:
  887. * zero on success, -1 on error
  888. */
  889. int
  890. fy_parser_set_input_fd(struct fy_parser *fyp, int fd)
  891. FY_EXPORT;
  892. /**
  893. * fy_parser_parse() - Parse and return the next event.
  894. *
  895. * Each call to fy_parser_parse() returns the next event from
  896. * the configured input of the parser, or NULL at the end of
  897. * the stream. The returned event must be released via
  898. * a matching call to fy_parser_event_free().
  899. *
  900. * @fyp: The parser
  901. *
  902. * Returns:
  903. * The next event in the stream or NULL.
  904. */
  905. struct fy_event *
  906. fy_parser_parse(struct fy_parser *fyp)
  907. FY_EXPORT;
  908. /**
  909. * fy_parser_event_free() - Free an event
  910. *
  911. * Free a previously returned event from fy_parser_parse().
  912. *
  913. * @fyp: The parser
  914. * @fye: The event to free (may be NULL)
  915. */
  916. void
  917. fy_parser_event_free(struct fy_parser *fyp, struct fy_event *fye)
  918. FY_EXPORT;
  919. /**
  920. * fy_parser_get_stream_error() - Check the parser for stream errors
  921. *
  922. * @fyp: The parser
  923. *
  924. * Returns:
  925. * true in case of a stream error, false otherwise.
  926. */
  927. bool
  928. fy_parser_get_stream_error(struct fy_parser *fyp)
  929. FY_EXPORT;
  930. /**
  931. * fy_token_scalar_style() - Get the style of a scalar token
  932. *
  933. * @fyt: The scalar token to get it's style. Note that a NULL
  934. * token is a &enum FYSS_PLAIN.
  935. *
  936. * Returns:
  937. * The scalar style of the token, or FYSS_PLAIN on each other case
  938. */
  939. enum fy_scalar_style
  940. fy_token_scalar_style(struct fy_token *fyt)
  941. FY_EXPORT;
  942. /**
  943. * fy_token_scalar_is_null() - Test whether the scalar is null (content)
  944. *
  945. * @fyt: The scalar token to check for NULLity.
  946. *
  947. * Note that this is different than null of the YAML type system.
  948. * It is null as in null content. It is also different than an
  949. * empty scalar.
  950. *
  951. * Returns:
  952. * true if is a null scalar, false otherwise
  953. */
  954. bool
  955. fy_token_scalar_is_null(struct fy_token *fyt)
  956. FY_EXPORT;
  957. /**
  958. * fy_token_get_text() - Get text (and length of it) of a token
  959. *
  960. * This method will return a pointer to the text of a token
  961. * along with the length of it. Note that this text is *not*
  962. * NULL terminated. If you need a NULL terminated pointer
  963. * use fy_token_get_text0().
  964. *
  965. * In case that the token is 'simple' enough (i.e. a plain scalar)
  966. * or something similar the returned pointer is a direct pointer
  967. * to the space of the input that contains the token.
  968. *
  969. * That means that the pointer is *not* guaranteed to be valid
  970. * after the parser is destroyed.
  971. *
  972. * If the token is 'complex' enough, then space shall be allocated,
  973. * filled and returned.
  974. *
  975. * Note that the concept of 'simple' and 'complex' is vague, and
  976. * that's on purpose.
  977. *
  978. * @fyt: The token out of which the text pointer will be returned.
  979. * @lenp: Pointer to a variable that will hold the returned length
  980. *
  981. * Returns:
  982. * A pointer to the text representation of the token, while
  983. * @lenp will be assigned the character length of said representation.
  984. * NULL in case of an error.
  985. */
  986. const char *
  987. fy_token_get_text(struct fy_token *fyt, size_t *lenp)
  988. FY_EXPORT;
  989. /**
  990. * fy_token_get_text0() - Get zero terminated text of a token
  991. *
  992. * This method will return a pointer to the text of a token
  993. * which is zero terminated. It will allocate memory to hold
  994. * it in the token structure so try to use fy_token_get_text()
  995. * instead if possible.
  996. *
  997. * @fyt: The token out of which the text pointer will be returned.
  998. *
  999. * Returns:
  1000. * A pointer to a zero terminated text representation of the token.
  1001. * NULL in case of an error.
  1002. */
  1003. const char *
  1004. fy_token_get_text0(struct fy_token *fyt)
  1005. FY_EXPORT;
  1006. /**
  1007. * fy_token_get_text_length() - Get length of the text of a token
  1008. *
  1009. * This method will return the length of the text representation
  1010. * of a token.
  1011. *
  1012. * @fyt: The token
  1013. *
  1014. * Returns:
  1015. * The size of the text representation of a token, -1 in case of an error.
  1016. * Note that the NULL token will return a length of zero.
  1017. */
  1018. size_t
  1019. fy_token_get_text_length(struct fy_token *fyt)
  1020. FY_EXPORT;
  1021. /**
  1022. * fy_token_get_utf8_length() - Get length of the text of a token
  1023. *
  1024. * This method will return the length of the text representation
  1025. * of a token as a utf8 string.
  1026. *
  1027. * @fyt: The token
  1028. *
  1029. * Returns:
  1030. * The size of the utf8 text representation of a token, -1 in case of an error.
  1031. * Note that the NULL token will return a length of zero.
  1032. */
  1033. size_t
  1034. fy_token_get_utf8_length(struct fy_token *fyt)
  1035. FY_EXPORT;
  1036. /**
  1037. * enum fy_comment_placement - Comment placement relative to token
  1038. *
  1039. * @fycp_top: Comment on top of token
  1040. * @fycp_right: Comment to the right of the token
  1041. * @fycp_bottom: Comment to the bottom of the token
  1042. */
  1043. enum fy_comment_placement {
  1044. fycp_top,
  1045. fycp_right,
  1046. fycp_bottom
  1047. };
  1048. #define fycp_max (fycp_bottom + 1)
  1049. /**
  1050. * fy_token_get_comment() - Get zero terminated comment of a token
  1051. *
  1052. * @fyt: The token out of which the comment text will be returned.
  1053. * @buf: The buffer to be filled with the contents of the token
  1054. * @maxsz: The maximum size of the comment buffer
  1055. * @which: The comment placement
  1056. *
  1057. * Returns:
  1058. * A pointer to a zero terminated text representation of the token comment.
  1059. * NULL in case of an error or if the token has no comment.
  1060. */
  1061. const char *
  1062. fy_token_get_comment(struct fy_token *fyt, char *buf, size_t maxsz,
  1063. enum fy_comment_placement which)
  1064. FY_EXPORT;
  1065. /**
  1066. * struct fy_iter_chunk - An iteration chunk
  1067. *
  1068. * @str: Pointer to the start of the chunk
  1069. * @len: The size of the chunk
  1070. *
  1071. * The iterator produces a stream of chunks which
  1072. * cover the whole object.
  1073. */
  1074. struct fy_iter_chunk {
  1075. const char *str;
  1076. size_t len;
  1077. };
  1078. /**
  1079. * fy_token_iter_create() - Create a token iterator
  1080. *
  1081. * Create an iterator for operating on the given token, or
  1082. * a generic iterator for use with fy_token_iter_start().
  1083. * The iterator must be destroyed with a matching call to
  1084. * fy_token_iter_destroy().
  1085. *
  1086. * @fyt: The token to iterate, or NULL.
  1087. *
  1088. * Returns:
  1089. * A pointer to the newly created iterator, or NULL in case of
  1090. * an error.
  1091. */
  1092. struct fy_token_iter *
  1093. fy_token_iter_create(struct fy_token *fyt)
  1094. FY_EXPORT;
  1095. /**
  1096. * fy_token_iter_destroy() - Destroy the iterator
  1097. *
  1098. * Destroy the iterator created by fy_token_iter_create().
  1099. *
  1100. * @iter: The iterator to destroy.
  1101. */
  1102. void
  1103. fy_token_iter_destroy(struct fy_token_iter *iter)
  1104. FY_EXPORT;
  1105. /**
  1106. * fy_token_iter_start() - Start iterating over the contents of a token
  1107. *
  1108. * Prepare an iterator for operating on the given token.
  1109. * The iterator must be created via a previous call to fy_token_iter_create()
  1110. * for user level API access.
  1111. *
  1112. * @fyt: The token to iterate over
  1113. * @iter: The iterator to prepare.
  1114. */
  1115. void
  1116. fy_token_iter_start(struct fy_token *fyt, struct fy_token_iter *iter)
  1117. FY_EXPORT;
  1118. /**
  1119. * fy_token_iter_finish() - Stop iterating over the contents of a token
  1120. *
  1121. * Stop the iteration operation.
  1122. *
  1123. * @iter: The iterator.
  1124. */
  1125. void
  1126. fy_token_iter_finish(struct fy_token_iter *iter)
  1127. FY_EXPORT;
  1128. /**
  1129. * fy_token_iter_peek_chunk() - Peek at the next iterator chunk
  1130. *
  1131. * Peek at the next iterator chunk
  1132. *
  1133. * @iter: The iterator.
  1134. *
  1135. * Returns:
  1136. * A pointer to the next iterator chunk, or NULL in case there's
  1137. * no other.
  1138. */
  1139. const struct fy_iter_chunk *
  1140. fy_token_iter_peek_chunk(struct fy_token_iter *iter)
  1141. FY_EXPORT;
  1142. /**
  1143. * fy_token_iter_chunk_next() - Get next iterator chunk
  1144. *
  1145. * Get the next iterator chunk in sequence,
  1146. *
  1147. * @iter: The iterator.
  1148. * @curr: The current chunk, or NULL for the first one.
  1149. * @errp: Pointer to an error return value or NULL
  1150. *
  1151. * Returns:
  1152. * A pointer to the next iterator chunk, or NULL in case there's
  1153. * no other. When the return value is NULL, the errp variable
  1154. * will be filled with 0 for normal end, or -1 in case of an error.
  1155. */
  1156. const struct fy_iter_chunk *
  1157. fy_token_iter_chunk_next(struct fy_token_iter *iter,
  1158. const struct fy_iter_chunk *curr, int *errp)
  1159. FY_EXPORT;
  1160. /**
  1161. * fy_token_iter_advance() - Advance the iterator position
  1162. *
  1163. * Advance the read pointer of the iterator.
  1164. * Note that mixing calls of this with any call of fy_token_iter_ungetc() /
  1165. * fy_token_iter_utf8_unget() in a single iterator sequence leads
  1166. * to undefined behavior.
  1167. *
  1168. * @iter: The iterator.
  1169. * @len: Number of bytes to advance the iterator position
  1170. */
  1171. void
  1172. fy_token_iter_advance(struct fy_token_iter *iter, size_t len)
  1173. FY_EXPORT;
  1174. /**
  1175. * fy_token_iter_read() - Read a block from an iterator
  1176. *
  1177. * Read a block from an iterator. Note than mixing calls of this
  1178. * and any of the ungetc methods leads to undefined behavior.
  1179. *
  1180. * @iter: The iterator.
  1181. * @buf: Pointer to a block of memory to receive the data. Must be at
  1182. * least count bytes long.
  1183. * @count: Amount of bytes to read.
  1184. *
  1185. * Returns:
  1186. * The amount of data read, or -1 in case of an error.
  1187. */
  1188. ssize_t
  1189. fy_token_iter_read(struct fy_token_iter *iter, void *buf, size_t count)
  1190. FY_EXPORT;
  1191. /**
  1192. * fy_token_iter_getc() - Get a single character from an iterator
  1193. *
  1194. * Reads a single character from an iterator. If the iterator is
  1195. * finished, it will return -1. If any calls to ungetc have pushed
  1196. * a character in the iterator it shall return that.
  1197. *
  1198. * @iter: The iterator.
  1199. *
  1200. * Returns:
  1201. * The next character in the iterator, or -1 in case of an error, or
  1202. * end of stream.
  1203. */
  1204. int
  1205. fy_token_iter_getc(struct fy_token_iter *iter)
  1206. FY_EXPORT;
  1207. /**
  1208. * fy_token_iter_ungetc() - Ungets a single character from an iterator
  1209. *
  1210. * Pushes back a single character to an iterator stream. It will be
  1211. * returned in subsequent calls of fy_token_iter_getc(). Currently
  1212. * only a single character is allowed to be pushed back, and any
  1213. * further calls to ungetc will return an error.
  1214. *
  1215. * @iter: The iterator.
  1216. * @c: The character to push back, or -1 to reset the pushback buffer.
  1217. *
  1218. * Returns:
  1219. * The pushed back character given as argument, or -1 in case of an error.
  1220. * If the pushed back character was -1, then 0 will be returned.
  1221. */
  1222. int
  1223. fy_token_iter_ungetc(struct fy_token_iter *iter, int c)
  1224. FY_EXPORT;
  1225. /**
  1226. * fy_token_iter_peekc() - Peeks at single character from an iterator
  1227. *
  1228. * Peeks at the next character to get from an iterator. If the iterator is
  1229. * finished, it will return -1. If any calls to ungetc have pushed
  1230. * a character in the iterator it shall return that. The character is not
  1231. * removed from the iterator stream.
  1232. *
  1233. * @iter: The iterator.
  1234. *
  1235. * Returns:
  1236. * The next character in the iterator, or -1 in case of an error, or end
  1237. * of stream.
  1238. */
  1239. int
  1240. fy_token_iter_peekc(struct fy_token_iter *iter)
  1241. FY_EXPORT;
  1242. /**
  1243. * fy_token_iter_utf8_get() - Get a single utf8 character from an iterator
  1244. *
  1245. * Reads a single utf8 character from an iterator. If the iterator is
  1246. * finished, it will return -1. If any calls to ungetc have pushed
  1247. * a character in the iterator it shall return that.
  1248. *
  1249. * @iter: The iterator.
  1250. *
  1251. * Returns:
  1252. * The next utf8 character in the iterator, or -1 in case of an error, or end
  1253. * of stream.
  1254. */
  1255. int
  1256. fy_token_iter_utf8_get(struct fy_token_iter *iter)
  1257. FY_EXPORT;
  1258. /**
  1259. * fy_token_iter_utf8_unget() - Ungets a single utf8 character from an iterator
  1260. *
  1261. * Pushes back a single utf8 character to an iterator stream. It will be
  1262. * returned in subsequent calls of fy_token_iter_utf8_getc(). Currently
  1263. * only a single character is allowed to be pushed back, and any
  1264. * further calls to ungetc will return an error.
  1265. *
  1266. * @iter: The iterator.
  1267. * @c: The character to push back, or -1 to reset the pushback buffer.
  1268. *
  1269. * Returns:
  1270. * The pushed back utf8 character given as argument, or -1 in case of an error.
  1271. * If the pushed back utf8 character was -1, then 0 will be returned.
  1272. */
  1273. int
  1274. fy_token_iter_utf8_unget(struct fy_token_iter *iter, int c)
  1275. FY_EXPORT;
  1276. /**
  1277. * fy_token_iter_utf8_peek() - Peeks at single utf8 character from an iterator
  1278. *
  1279. * Peeks at the next utf8 character to get from an iterator. If the iterator is
  1280. * finished, it will return -1. If any calls to ungetc have pushed
  1281. * a character in the iterator it shall return that. The character is not
  1282. * removed from the iterator stream.
  1283. *
  1284. * @iter: The iterator.
  1285. *
  1286. * Returns:
  1287. * The next utf8 character in the iterator, or -1 in case of an error, or end
  1288. * of stream.
  1289. */
  1290. int
  1291. fy_token_iter_utf8_peek(struct fy_token_iter *iter)
  1292. FY_EXPORT;
  1293. /**
  1294. * fy_parse_load_document() - Parse the next document from the parser stream
  1295. *
  1296. * This method performs parsing on a parser stream and returns the next
  1297. * document. This means that for a compound document with multiple
  1298. * documents, each call will return the next document.
  1299. *
  1300. * @fyp: The parser
  1301. *
  1302. * Returns:
  1303. * The next document from the parser stream.
  1304. */
  1305. struct fy_document *
  1306. fy_parse_load_document(struct fy_parser *fyp)
  1307. FY_EXPORT;
  1308. /**
  1309. * fy_parse_document_destroy() - Destroy a document created by fy_parse_load_document()
  1310. *
  1311. * @fyp: The parser
  1312. * @fyd: The document to destroy
  1313. */
  1314. void
  1315. fy_parse_document_destroy(struct fy_parser *fyp, struct fy_document *fyd)
  1316. FY_EXPORT;
  1317. /**
  1318. * fy_document_resolve() - Resolve anchors and merge keys
  1319. *
  1320. * This method performs resolution of the given document,
  1321. * by replacing references to anchors with their contents
  1322. * and handling merge keys (<<)
  1323. *
  1324. * @fyd: The document to resolve
  1325. *
  1326. * Returns:
  1327. * zero on success, -1 on error
  1328. */
  1329. int
  1330. fy_document_resolve(struct fy_document *fyd)
  1331. FY_EXPORT;
  1332. /**
  1333. * fy_document_has_directives() - Document directive check
  1334. *
  1335. * Checks whether the given document has any directives, i.e.
  1336. * %TAG or %VERSION.
  1337. *
  1338. * @fyd: The document to check for directives existence
  1339. *
  1340. * Returns:
  1341. * true if directives exist, false if not
  1342. */
  1343. bool
  1344. fy_document_has_directives(const struct fy_document *fyd)
  1345. FY_EXPORT;
  1346. /**
  1347. * fy_document_has_explicit_document_start() - Explicit document start check
  1348. *
  1349. * Checks whether the given document has an explicit document start marker,
  1350. * i.e. ---
  1351. *
  1352. * @fyd: The document to check for explicit start marker
  1353. *
  1354. * Returns:
  1355. * true if document has an explicit document start marker, false if not
  1356. */
  1357. bool
  1358. fy_document_has_explicit_document_start(const struct fy_document *fyd)
  1359. FY_EXPORT;
  1360. /**
  1361. * fy_document_has_explicit_document_end() - Explicit document end check
  1362. *
  1363. * Checks whether the given document has an explicit document end marker,
  1364. * i.e. ...
  1365. *
  1366. * @fyd: The document to check for explicit end marker
  1367. *
  1368. * Returns:
  1369. * true if document has an explicit document end marker, false if not
  1370. */
  1371. bool
  1372. fy_document_has_explicit_document_end(const struct fy_document *fyd)
  1373. FY_EXPORT;
  1374. /**
  1375. * fy_node_document() - Retreive the document the node belong to
  1376. *
  1377. * Returns the document of the node; note that while the node may not
  1378. * be reachable via a path expression, it may still be member of a
  1379. * document.
  1380. *
  1381. * @fyn: The node to retreive it's document
  1382. *
  1383. * Returns:
  1384. * The document of the node, or NULL in case of an error, or
  1385. * when the node has no document attached.
  1386. */
  1387. struct fy_document *
  1388. fy_node_document(struct fy_node *fyn)
  1389. FY_EXPORT;
  1390. /*
  1391. * enum fy_emitter_write_type - Type of the emitted output
  1392. *
  1393. * Describes the kind of emitted output, which makes it
  1394. * possible to colorize the output, or do some other content related
  1395. * filtering.
  1396. *
  1397. * @fyewt_document_indicator: Output chunk is a document indicator
  1398. * @fyewt_tag_directive: Output chunk is a tag directive
  1399. * @fyewt_version_directive: Output chunk is a version directive
  1400. * @fyewt_indent: Output chunk is a document indicator
  1401. * @fyewt_indicator: Output chunk is an indicator
  1402. * @fyewt_whitespace: Output chunk is white space
  1403. * @fyewt_plain_scalar: Output chunk is a plain scalar
  1404. * @fyewt_single_quoted_scalar: Output chunk is a single quoted scalar
  1405. * @fyewt_double_quoted_scalar: Output chunk is a double quoted scalar
  1406. * @fyewt_literal_scalar: Output chunk is a literal block scalar
  1407. * @fyewt_folded_scalar: Output chunk is a folded block scalar
  1408. * @fyewt_anchor: Output chunk is an anchor
  1409. * @fyewt_tag: Output chunk is a tag
  1410. * @fyewt_linebreak: Output chunk is a linebreak
  1411. * @fyewt_alias: Output chunk is an alias
  1412. * @fyewt_terminating_zero: Output chunk is a terminating zero
  1413. * @fyewt_plain_scalar_key: Output chunk is an plain scalar key
  1414. * @fyewt_single_quoted_scalar_key: Output chunk is an single quoted scalar key
  1415. * @fyewt_double_quoted_scalar_key: Output chunk is an double quoted scalar key
  1416. * @fyewt_comment: Output chunk is a comment
  1417. *
  1418. */
  1419. enum fy_emitter_write_type {
  1420. fyewt_document_indicator,
  1421. fyewt_tag_directive,
  1422. fyewt_version_directive,
  1423. fyewt_indent,
  1424. fyewt_indicator,
  1425. fyewt_whitespace,
  1426. fyewt_plain_scalar,
  1427. fyewt_single_quoted_scalar,
  1428. fyewt_double_quoted_scalar,
  1429. fyewt_literal_scalar,
  1430. fyewt_folded_scalar,
  1431. fyewt_anchor,
  1432. fyewt_tag,
  1433. fyewt_linebreak,
  1434. fyewt_alias,
  1435. fyewt_terminating_zero,
  1436. fyewt_plain_scalar_key,
  1437. fyewt_single_quoted_scalar_key,
  1438. fyewt_double_quoted_scalar_key,
  1439. fyewt_comment,
  1440. };
  1441. #define FYECF_INDENT_SHIFT 8
  1442. #define FYECF_INDENT_MASK 0xf
  1443. #define FYECF_INDENT(x) (((x) & FYECF_INDENT_MASK) << FYECF_INDENT_SHIFT)
  1444. #define FYECF_WIDTH_SHIFT 12
  1445. #define FYECF_WIDTH_MASK 0xff
  1446. #define FYECF_WIDTH(x) (((x) & FYECF_WIDTH_MASK) << FYECF_WIDTH_SHIFT)
  1447. #define FYECF_MODE_SHIFT 20
  1448. #define FYECF_MODE_MASK 0xf
  1449. #define FYECF_MODE(x) (((x) & FYECF_MODE_MASK) << FYECF_MODE_SHIFT)
  1450. #define FYECF_DOC_START_MARK_SHIFT 24
  1451. #define FYECF_DOC_START_MARK_MASK 0x3
  1452. #define FYECF_DOC_START_MARK(x) (((x) & FYECF_DOC_START_MARK_MASK) << FYECF_DOC_START_MARK_SHIFT)
  1453. #define FYECF_DOC_END_MARK_SHIFT 26
  1454. #define FYECF_DOC_END_MARK_MASK 0x3
  1455. #define FYECF_DOC_END_MARK(x) (((x) & FYECF_DOC_END_MARK_MASK) << FYECF_DOC_END_MARK_SHIFT)
  1456. #define FYECF_VERSION_DIR_SHIFT 28
  1457. #define FYECF_VERSION_DIR_MASK 0x3
  1458. #define FYECF_VERSION_DIR(x) (((x) & FYECF_VERSION_DIR_MASK) << FYECF_VERSION_DIR_SHIFT)
  1459. #define FYECF_TAG_DIR_SHIFT 30
  1460. #define FYECF_TAG_DIR_MASK 0x3
  1461. #define FYECF_TAG_DIR(x) (((unsigned int)(x) & FYECF_TAG_DIR_MASK) << FYECF_TAG_DIR_SHIFT)
  1462. /**
  1463. * enum fy_emitter_cfg_flags - Emitter configuration flags
  1464. *
  1465. * These flags control the operation of the emitter
  1466. *
  1467. * @FYECF_SORT_KEYS: Sort key when emitting
  1468. * @FYECF_OUTPUT_COMMENTS: Output comments (experimental)
  1469. * @FYECF_STRIP_LABELS: Strip labels when emitting
  1470. * @FYECF_STRIP_TAGS: Strip tags when emitting
  1471. * @FYECF_STRIP_DOC: Strip document tags and markers when emitting
  1472. * @FYECF_NO_ENDING_NEWLINE: Do not output ending new line (useful for single line mode)
  1473. * @FYECF_STRIP_EMPTY_KV: Remove all keys with empty values from the output (not available in streaming mode)
  1474. * @FYECF_INDENT_DEFAULT: Default emit output indent
  1475. * @FYECF_INDENT_1: Output indent is 1
  1476. * @FYECF_INDENT_2: Output indent is 2
  1477. * @FYECF_INDENT_3: Output indent is 3
  1478. * @FYECF_INDENT_4: Output indent is 4
  1479. * @FYECF_INDENT_5: Output indent is 5
  1480. * @FYECF_INDENT_6: Output indent is 6
  1481. * @FYECF_INDENT_7: Output indent is 7
  1482. * @FYECF_INDENT_8: Output indent is 8
  1483. * @FYECF_INDENT_9: Output indent is 9
  1484. * @FYECF_WIDTH_DEFAULT: Default emit output width
  1485. * @FYECF_WIDTH_80: Output width is 80
  1486. * @FYECF_WIDTH_132: Output width is 132
  1487. * @FYECF_WIDTH_INF: Output width is infinite
  1488. * @FYECF_MODE_ORIGINAL: Emit using the same flow mode as the original
  1489. * @FYECF_MODE_BLOCK: Emit using only the block mode
  1490. * @FYECF_MODE_FLOW: Emit using only the flow mode
  1491. * @FYECF_MODE_FLOW_ONELINE: Emit using only the flow mode (in one line)
  1492. * @FYECF_MODE_JSON: Emit using JSON mode (non type preserving)
  1493. * @FYECF_MODE_JSON_TP: Emit using JSON mode (type preserving)
  1494. * @FYECF_MODE_JSON_ONELINE: Emit using JSON mode (non type preserving, one line)
  1495. * @FYECF_MODE_DEJSON: Emit YAML trying to pretify JSON
  1496. * @FYECF_MODE_PRETTY: Emit YAML that tries to look good
  1497. * @FYECF_MODE_MANUAL: Emit YAML respecting all manual style hints (reformats if needed)
  1498. * @FYECF_DOC_START_MARK_AUTO: Automatically generate document start markers if required
  1499. * @FYECF_DOC_START_MARK_OFF: Do not generate document start markers
  1500. * @FYECF_DOC_START_MARK_ON: Always generate document start markers
  1501. * @FYECF_DOC_END_MARK_AUTO: Automatically generate document end markers if required
  1502. * @FYECF_DOC_END_MARK_OFF: Do not generate document end markers
  1503. * @FYECF_DOC_END_MARK_ON: Always generate document end markers
  1504. * @FYECF_VERSION_DIR_AUTO: Automatically generate version directive
  1505. * @FYECF_VERSION_DIR_OFF: Never generate version directive
  1506. * @FYECF_VERSION_DIR_ON: Always generate version directive
  1507. * @FYECF_TAG_DIR_AUTO: Automatically generate tag directives
  1508. * @FYECF_TAG_DIR_OFF: Never generate tag directives
  1509. * @FYECF_TAG_DIR_ON: Always generate tag directives
  1510. * @FYECF_DEFAULT: The default emitter configuration
  1511. */
  1512. enum fy_emitter_cfg_flags {
  1513. FYECF_SORT_KEYS = FY_BIT(0),
  1514. FYECF_OUTPUT_COMMENTS = FY_BIT(1),
  1515. FYECF_STRIP_LABELS = FY_BIT(2),
  1516. FYECF_STRIP_TAGS = FY_BIT(3),
  1517. FYECF_STRIP_DOC = FY_BIT(4),
  1518. FYECF_NO_ENDING_NEWLINE = FY_BIT(5),
  1519. FYECF_STRIP_EMPTY_KV = FY_BIT(6),
  1520. FYECF_INDENT_DEFAULT = FYECF_INDENT(0),
  1521. FYECF_INDENT_1 = FYECF_INDENT(1),
  1522. FYECF_INDENT_2 = FYECF_INDENT(2),
  1523. FYECF_INDENT_3 = FYECF_INDENT(3),
  1524. FYECF_INDENT_4 = FYECF_INDENT(4),
  1525. FYECF_INDENT_5 = FYECF_INDENT(5),
  1526. FYECF_INDENT_6 = FYECF_INDENT(6),
  1527. FYECF_INDENT_7 = FYECF_INDENT(7),
  1528. FYECF_INDENT_8 = FYECF_INDENT(8),
  1529. FYECF_INDENT_9 = FYECF_INDENT(9),
  1530. FYECF_WIDTH_DEFAULT = FYECF_WIDTH(80),
  1531. FYECF_WIDTH_80 = FYECF_WIDTH(80),
  1532. FYECF_WIDTH_132 = FYECF_WIDTH(132),
  1533. FYECF_WIDTH_INF = FYECF_WIDTH(255),
  1534. FYECF_MODE_ORIGINAL = FYECF_MODE(0),
  1535. FYECF_MODE_BLOCK = FYECF_MODE(1),
  1536. FYECF_MODE_FLOW = FYECF_MODE(2),
  1537. FYECF_MODE_FLOW_ONELINE = FYECF_MODE(3),
  1538. FYECF_MODE_JSON = FYECF_MODE(4),
  1539. FYECF_MODE_JSON_TP = FYECF_MODE(5),
  1540. FYECF_MODE_JSON_ONELINE = FYECF_MODE(6),
  1541. FYECF_MODE_DEJSON = FYECF_MODE(7),
  1542. FYECF_MODE_PRETTY = FYECF_MODE(8),
  1543. FYECF_MODE_MANUAL = FYECF_MODE(9),
  1544. FYECF_DOC_START_MARK_AUTO = FYECF_DOC_START_MARK(0),
  1545. FYECF_DOC_START_MARK_OFF = FYECF_DOC_START_MARK(1),
  1546. FYECF_DOC_START_MARK_ON = FYECF_DOC_START_MARK(2),
  1547. FYECF_DOC_END_MARK_AUTO = FYECF_DOC_END_MARK(0),
  1548. FYECF_DOC_END_MARK_OFF = FYECF_DOC_END_MARK(1),
  1549. FYECF_DOC_END_MARK_ON = FYECF_DOC_END_MARK(2),
  1550. FYECF_VERSION_DIR_AUTO = FYECF_VERSION_DIR(0),
  1551. FYECF_VERSION_DIR_OFF = FYECF_VERSION_DIR(1),
  1552. FYECF_VERSION_DIR_ON = FYECF_VERSION_DIR(2),
  1553. FYECF_TAG_DIR_AUTO = FYECF_TAG_DIR(0),
  1554. FYECF_TAG_DIR_OFF = FYECF_TAG_DIR(1),
  1555. FYECF_TAG_DIR_ON = FYECF_TAG_DIR(2),
  1556. FYECF_DEFAULT = FYECF_WIDTH_INF |
  1557. FYECF_MODE_ORIGINAL |
  1558. FYECF_INDENT_DEFAULT,
  1559. };
  1560. /**
  1561. * struct fy_emitter_cfg - emitter configuration structure.
  1562. *
  1563. * Argument to the fy_emitter_create() method which
  1564. * is the way to convert a runtime document structure back to YAML.
  1565. *
  1566. * @flags: Configuration flags
  1567. * @output: Pointer to the method that will perform output.
  1568. * @userdata: Opaque user data pointer
  1569. * @diag: Diagnostic interface
  1570. */
  1571. struct fy_emitter_cfg {
  1572. enum fy_emitter_cfg_flags flags;
  1573. int (*output)(struct fy_emitter *emit, enum fy_emitter_write_type type,
  1574. const char *str, int len, void *userdata);
  1575. void *userdata;
  1576. struct fy_diag *diag;
  1577. };
  1578. /**
  1579. * fy_emitter_create() - Create an emitter
  1580. *
  1581. * Creates an emitter using the supplied configuration
  1582. *
  1583. * @cfg: The emitter configuration
  1584. *
  1585. * Returns:
  1586. * The newly created emitter or NULL on error.
  1587. */
  1588. struct fy_emitter *
  1589. fy_emitter_create(const struct fy_emitter_cfg *cfg)
  1590. FY_EXPORT;
  1591. /**
  1592. * fy_emitter_destroy() - Destroy an emitter
  1593. *
  1594. * Destroy an emitter previously created by fy_emitter_create()
  1595. *
  1596. * @emit: The emitter to destroy
  1597. */
  1598. void
  1599. fy_emitter_destroy(struct fy_emitter *emit)
  1600. FY_EXPORT;
  1601. /**
  1602. * fy_emitter_get_cfg() - Get the configuration of an emitter
  1603. *
  1604. * @emit: The emitter
  1605. *
  1606. * Returns:
  1607. * The configuration of the emitter
  1608. */
  1609. const struct fy_emitter_cfg *
  1610. fy_emitter_get_cfg(struct fy_emitter *emit)
  1611. FY_EXPORT;
  1612. /**
  1613. * fy_emitter_get_diag() - Get the diagnostic object of an emitter
  1614. *
  1615. * Return a pointer to the diagnostic object of an emitter object.
  1616. * Note that the returned diag object has a reference taken so
  1617. * you should fy_diag_unref() it when you're done with it.
  1618. *
  1619. * @emit: The emitter to get the diagnostic object
  1620. *
  1621. * Returns:
  1622. * A pointer to a ref'ed diagnostic object or NULL in case of an
  1623. * error.
  1624. */
  1625. struct fy_diag *
  1626. fy_emitter_get_diag(struct fy_emitter *emit)
  1627. FY_EXPORT;
  1628. /**
  1629. * fy_emitter_set_diag() - Set the diagnostic object of an emitter
  1630. *
  1631. * Replace the emitters's current diagnostic object with the one
  1632. * given as an argument. The previous diagnostic object will be
  1633. * unref'ed (and freed if its reference gets to 0).
  1634. * Also note that the diag argument shall take a reference too.
  1635. *
  1636. * @emit: The emitter to replace the diagnostic object
  1637. * @diag: The emitter's new diagnostic object, NULL for default
  1638. *
  1639. * Returns:
  1640. * 0 if everything OK, -1 otherwise
  1641. */
  1642. int
  1643. fy_emitter_set_diag(struct fy_emitter *emit, struct fy_diag *diag)
  1644. FY_EXPORT;
  1645. /**
  1646. * fy_emitter_set_finalizer() - Set emitter finalizer
  1647. *
  1648. * Set a method callback to be called when the emitter
  1649. * is disposed of. If finalizer is NULL, then the method
  1650. * is removed.
  1651. *
  1652. * @emit: The emitter to replace the diagnostic object
  1653. * @finalizer: The finalizer callback
  1654. */
  1655. void
  1656. fy_emitter_set_finalizer(struct fy_emitter *emit,
  1657. void (*finalizer)(struct fy_emitter *emit))
  1658. FY_EXPORT;
  1659. /**
  1660. * struct fy_emitter_default_output_data - emitter default output configuration
  1661. *
  1662. * This is the argument to the default output method of the emitter.
  1663. *
  1664. * @fp: File where the output is directed to
  1665. * @colorize: Use ANSI color sequences to colorize the output
  1666. * @visible: Make whitespace visible (requires a UTF8 capable terminal)
  1667. */
  1668. struct fy_emitter_default_output_data {
  1669. FILE *fp;
  1670. bool colorize;
  1671. bool visible;
  1672. };
  1673. /**
  1674. * fy_emitter_default_output() - The default colorizing output method
  1675. *
  1676. * This is the default colorizing output method.
  1677. * Will be used when the output field of the emitter configuration is NULL.
  1678. *
  1679. * @fye: The emitter
  1680. * @type: Type of the emitted output
  1681. * @str: Pointer to the string to output
  1682. * @len: Length of the string
  1683. * @userdata: Must point to a fy_emitter_default_output_data structure
  1684. *
  1685. * Returns:
  1686. * 0 on success, -1 on error
  1687. */
  1688. int
  1689. fy_emitter_default_output(struct fy_emitter *fye, enum fy_emitter_write_type type,
  1690. const char *str, int len, void *userdata)
  1691. FY_EXPORT;
  1692. /**
  1693. * fy_document_default_emit_to_fp() - Emit a document to a file, using defaults
  1694. *
  1695. * Simple one shot emitter to a file, using the default emitter output.
  1696. * The output will be colorized if the the file points to a tty.
  1697. *
  1698. * @fyd: The document to emit
  1699. * @fp: The file where the output is sent
  1700. *
  1701. * Returns:
  1702. * 0 on success, -1 on error
  1703. */
  1704. int
  1705. fy_document_default_emit_to_fp(struct fy_document *fyd, FILE *fp)
  1706. FY_EXPORT;
  1707. /**
  1708. * fy_emit_event() - Queue (and possibly emit) an event
  1709. *
  1710. * Queue and output using the emitter. This is the streaming
  1711. * output method which does not require creating a document.
  1712. *
  1713. * @emit: The emitter to use
  1714. * @fye: The event to queue for emission
  1715. *
  1716. * Returns:
  1717. * 0 on success, -1 on error
  1718. */
  1719. int
  1720. fy_emit_event(struct fy_emitter *emit, struct fy_event *fye)
  1721. FY_EXPORT;
  1722. /**
  1723. * fy_emit_event_from_parser() - Queue (and possibly emit) an event
  1724. * generated by the parser.
  1725. *
  1726. * Queue and output using the emitter. This is the streaming
  1727. * output method which does not require creating a document.
  1728. * Similar to fy_emit_event() but it is more efficient.
  1729. *
  1730. * @emit: The emitter to use
  1731. * @fyp: The parser that generated the event
  1732. * @fye: The event to queue for emission
  1733. *
  1734. * Returns:
  1735. * 0 on success, -1 on error
  1736. */
  1737. int
  1738. fy_emit_event_from_parser(struct fy_emitter *emit, struct fy_parser *fyp, struct fy_event *fye)
  1739. FY_EXPORT;
  1740. /**
  1741. * fy_emit_document() - Emit the document using the emitter
  1742. *
  1743. * Emits a document in YAML format using the emitter.
  1744. *
  1745. * @emit: The emitter
  1746. * @fyd: The document to emit
  1747. *
  1748. * Returns:
  1749. * 0 on success, -1 on error
  1750. */
  1751. int
  1752. fy_emit_document(struct fy_emitter *emit, struct fy_document *fyd)
  1753. FY_EXPORT;
  1754. /**
  1755. * fy_emit_document_start() - Emit document start using the emitter
  1756. *
  1757. * Emits a document start using the emitter. This is used in case
  1758. * you need finer control over the emitting output.
  1759. *
  1760. * @emit: The emitter
  1761. * @fyd: The document to use for emitting it's start
  1762. * @fyn: The root (or NULL for using the document's root)
  1763. *
  1764. * Returns:
  1765. * 0 on success, -1 on error
  1766. */
  1767. int
  1768. fy_emit_document_start(struct fy_emitter *emit, struct fy_document *fyd,
  1769. struct fy_node *fyn)
  1770. FY_EXPORT;
  1771. /**
  1772. * fy_emit_document_end() - Emit document end using the emitter
  1773. *
  1774. * Emits a document end using the emitter. This is used in case
  1775. * you need finer control over the emitting output.
  1776. *
  1777. * @emit: The emitter
  1778. *
  1779. * Returns:
  1780. * 0 on success, -1 on error
  1781. */
  1782. int
  1783. fy_emit_document_end(struct fy_emitter *emit)
  1784. FY_EXPORT;
  1785. /**
  1786. * fy_emit_node() - Emit a single node using the emitter
  1787. *
  1788. * Emits a single node using the emitter. This is used in case
  1789. * you need finer control over the emitting output.
  1790. *
  1791. * @emit: The emitter
  1792. * @fyn: The node to emit
  1793. *
  1794. * Returns:
  1795. * 0 on success, -1 on error
  1796. */
  1797. int
  1798. fy_emit_node(struct fy_emitter *emit, struct fy_node *fyn)
  1799. FY_EXPORT;
  1800. /**
  1801. * fy_emit_root_node() - Emit a single root node using the emitter
  1802. *
  1803. * Emits a single root node using the emitter. This is used in case
  1804. * you need finer control over the emitting output.
  1805. *
  1806. * @emit: The emitter
  1807. * @fyn: The root node to emit
  1808. *
  1809. * Returns:
  1810. * 0 on success, -1 on error
  1811. */
  1812. int
  1813. fy_emit_root_node(struct fy_emitter *emit, struct fy_node *fyn)
  1814. FY_EXPORT;
  1815. /**
  1816. * fy_emit_explicit_document_end() - Emit an explicit document end
  1817. *
  1818. * Emits an explicit document end, i.e. ... . Use this if you
  1819. * you need finer control over the emitting output.
  1820. *
  1821. * @emit: The emitter
  1822. *
  1823. * Returns:
  1824. * 0 on success, -1 on error
  1825. */
  1826. int
  1827. fy_emit_explicit_document_end(struct fy_emitter *emit)
  1828. FY_EXPORT;
  1829. /**
  1830. * fy_emit_document_to_fp() - Emit a document to an file pointer
  1831. *
  1832. * Emits a document from the root to the given file pointer.
  1833. *
  1834. * @fyd: The document to emit
  1835. * @flags: The emitter flags to use
  1836. * @fp: The file pointer to output to
  1837. *
  1838. * Returns:
  1839. * 0 on success, -1 on error
  1840. */
  1841. int
  1842. fy_emit_document_to_fp(struct fy_document *fyd,
  1843. enum fy_emitter_cfg_flags flags, FILE *fp)
  1844. FY_EXPORT;
  1845. /**
  1846. * fy_emit_document_to_file() - Emit a document to file
  1847. *
  1848. * Emits a document from the root to the given file.
  1849. * The file will be fopen'ed using a "wa" mode.
  1850. *
  1851. * @fyd: The document to emit
  1852. * @flags: The emitter flags to use
  1853. * @filename: The filename to output to, or NULL for stdout
  1854. *
  1855. * Returns:
  1856. * 0 on success, -1 on error
  1857. */
  1858. int
  1859. fy_emit_document_to_file(struct fy_document *fyd,
  1860. enum fy_emitter_cfg_flags flags,
  1861. const char *filename)
  1862. FY_EXPORT;
  1863. /**
  1864. * fy_emit_document_to_fd() - Emit a document to a file descriptor
  1865. *
  1866. * Emits a document from the root to the given file descriptor
  1867. *
  1868. * @fyd: The document to emit
  1869. * @flags: The emitter flags to use
  1870. * @fd: The file descriptor to output to
  1871. *
  1872. * Returns:
  1873. * 0 on success, -1 on error
  1874. */
  1875. int
  1876. fy_emit_document_to_fd(struct fy_document *fyd,
  1877. enum fy_emitter_cfg_flags flags, int fd)
  1878. FY_EXPORT;
  1879. /**
  1880. * fy_emit_document_to_buffer() - Emit a document to a buffer
  1881. *
  1882. * Emits an document from the root to the given buffer.
  1883. * If the document does not fit, an error will be returned.
  1884. *
  1885. * @fyd: The document to emit
  1886. * @flags: The emitter flags to use
  1887. * @buf: Pointer to the buffer area to fill
  1888. * @size: Size of the buffer
  1889. *
  1890. * Returns:
  1891. * A positive number, which is the size of the emitted document
  1892. * on the buffer on success, -1 on error
  1893. */
  1894. int
  1895. fy_emit_document_to_buffer(struct fy_document *fyd,
  1896. enum fy_emitter_cfg_flags flags,
  1897. char *buf, size_t size)
  1898. FY_EXPORT;
  1899. /**
  1900. * fy_emit_document_to_string() - Emit a document to an allocated string
  1901. *
  1902. * Emits an document from the root to a string which will be dynamically
  1903. * allocated.
  1904. *
  1905. * @fyd: The document to emit
  1906. * @flags: The emitter flags to use
  1907. *
  1908. * Returns:
  1909. * A pointer to the allocated string, or NULL in case of an error
  1910. */
  1911. char *
  1912. fy_emit_document_to_string(struct fy_document *fyd,
  1913. enum fy_emitter_cfg_flags flags)
  1914. FY_EXPORT;
  1915. #define fy_emit_document_to_string_alloca(_fyd, _flags, _res) \
  1916. FY_ALLOCA_COPY_FREE(fy_emit_document_to_string((_fyd), (_flags)), FY_NT, (_res))
  1917. /**
  1918. * fy_emit_node_to_buffer() - Emit a node (recursively) to a buffer
  1919. *
  1920. * Emits a node recursively to the given buffer.
  1921. * If the document does not fit, an error will be returned.
  1922. *
  1923. * @fyn: The node to emit
  1924. * @flags: The emitter flags to use
  1925. * @buf: Pointer to the buffer area to fill
  1926. * @size: Size of the buffer
  1927. *
  1928. * Returns:
  1929. * A positive number, which is the size of the emitted node
  1930. * on the buffer on success, -1 on error
  1931. */
  1932. int
  1933. fy_emit_node_to_buffer(struct fy_node *fyn, enum fy_emitter_cfg_flags flags,
  1934. char *buf, size_t size)
  1935. FY_EXPORT;
  1936. /**
  1937. * fy_emit_node_to_string() - Emit a node to an allocated string
  1938. *
  1939. * Emits a node recursively to a string which will be dynamically
  1940. * allocated.
  1941. *
  1942. * @fyn: The node to emit
  1943. * @flags: The emitter flags to use
  1944. *
  1945. * Returns:
  1946. * A pointer to the allocated string, or NULL in case of an error
  1947. */
  1948. char *
  1949. fy_emit_node_to_string(struct fy_node *fyn, enum fy_emitter_cfg_flags flags)
  1950. FY_EXPORT;
  1951. #define fy_emit_node_to_string_alloca(_fyn, _flags, _res) \
  1952. FY_ALLOCA_COPY_FREE(fy_emit_node_to_string((_fyn), (_flags)), FY_NT, (_res))
  1953. /**
  1954. * fy_emit_to_buffer() - Create an emitter for buffer output.
  1955. *
  1956. * Creates a special purpose emitter for buffer output.
  1957. * Calls to fy_emit_event() populate the buffer.
  1958. * The contents are retreived by a call to fy_emit_to_buffer_collect()
  1959. *
  1960. * @flags: The emitter flags to use
  1961. * @buf: Pointer to the buffer area to fill
  1962. * @size: Size of the buffer
  1963. *
  1964. * Returns:
  1965. * The newly created emitter or NULL on error.
  1966. */
  1967. struct fy_emitter *
  1968. fy_emit_to_buffer(enum fy_emitter_cfg_flags flags, char *buf, size_t size)
  1969. FY_EXPORT;
  1970. /**
  1971. * fy_emit_to_buffer_collect() - Collect the buffer emitter output
  1972. *
  1973. * Collects the output of the emitter which was created by
  1974. * fy_emit_to_buffer() and populated using fy_emit_event() calls.
  1975. * The NULL terminated returned buffer is the same as the one used in the
  1976. * fy_emit_to_buffer() call and the sizep argument will be filled with
  1977. * the size of the buffer.
  1978. *
  1979. * @emit: The emitter
  1980. * @sizep: Pointer to the size to be filled
  1981. *
  1982. * Returns:
  1983. * The buffer or NULL in case of an error.
  1984. */
  1985. char *
  1986. fy_emit_to_buffer_collect(struct fy_emitter *emit, size_t *sizep)
  1987. FY_EXPORT;
  1988. /**
  1989. * fy_emit_to_string() - Create an emitter to create a dynamically
  1990. * allocated string.
  1991. *
  1992. * Creates a special purpose emitter for output to a dynamically
  1993. * allocated string.
  1994. * Calls to fy_emit_event() populate the buffer.
  1995. * The contents are retreived by a call to fy_emit_to_string_collect()
  1996. *
  1997. * @flags: The emitter flags to use
  1998. *
  1999. * Returns:
  2000. * The newly created emitter or NULL on error.
  2001. */
  2002. struct fy_emitter *
  2003. fy_emit_to_string(enum fy_emitter_cfg_flags flags)
  2004. FY_EXPORT;
  2005. /**
  2006. * fy_emit_to_string_collect() - Collect the string emitter output
  2007. *
  2008. * Collects the output of the emitter which was created by
  2009. * fy_emit_to_string() and populated using fy_emit_event() calls.
  2010. * The NULL terminated returned buffer is dynamically allocated
  2011. * and must be freed via a call to free().
  2012. * The sizep argument will be filled with the size of the buffer.
  2013. *
  2014. * @emit: The emitter
  2015. * @sizep: Pointer to the size to be filled
  2016. *
  2017. * Returns:
  2018. * The dynamically allocated string or NULL in case of an error.
  2019. */
  2020. char *
  2021. fy_emit_to_string_collect(struct fy_emitter *emit, size_t *sizep)
  2022. FY_EXPORT;
  2023. /**
  2024. * fy_node_copy() - Copy a node, associating the new node with the given document
  2025. *
  2026. * Make a deep copy of a node, associating the copy with the given document.
  2027. * Note that no content copying takes place as the contents of the nodes
  2028. * are reference counted. This means that the operation is relatively inexpensive.
  2029. *
  2030. * Note that the copy includes all anchors contained in the subtree of the
  2031. * source, so this call will register them with the document.
  2032. *
  2033. * @fyd: The document which the resulting node will be associated with
  2034. * @fyn_from: The source node to recursively copy
  2035. *
  2036. * Returns:
  2037. * The copied node on success, NULL on error
  2038. */
  2039. struct fy_node *
  2040. fy_node_copy(struct fy_document *fyd, struct fy_node *fyn_from)
  2041. FY_EXPORT;
  2042. /**
  2043. * fy_document_clone() - Clones a document
  2044. *
  2045. * Clone a document, by making a deep copy of the source.
  2046. * Note that no content copying takes place as the contents of the nodes
  2047. * are reference counted. This means that the operation is relatively inexpensive.
  2048. *
  2049. * @fydsrc: The source document to clone
  2050. *
  2051. * Returns:
  2052. * The newly created clone document, or NULL in case of an error
  2053. */
  2054. struct fy_document *
  2055. fy_document_clone(struct fy_document *fydsrc)
  2056. FY_EXPORT;
  2057. /**
  2058. * fy_node_insert() - Insert a node to the given node
  2059. *
  2060. * Insert a node to another node. If @fyn_from is NULL then this
  2061. * operation will delete the @fyn_to node.
  2062. *
  2063. * The operation varies according to the types of the arguments:
  2064. *
  2065. * from: scalar
  2066. *
  2067. * to: another-scalar -> scalar
  2068. * to: { key: value } -> scalar
  2069. * to: [ seq0, seq1 ] -> scalar
  2070. *
  2071. * from: [ seq2 ]
  2072. * to: scalar -> [ seq2 ]
  2073. * to: { key: value } -> [ seq2 ]
  2074. * to: [ seq0, seq1 ] -> [ seq0, seq1, sec2 ]
  2075. *
  2076. * from: { another-key: another-value }
  2077. * to: scalar -> { another-key: another-value }
  2078. * to: { key: value } -> { key: value, another-key: another-value }
  2079. * to: [ seq0, seq1 ] -> { another-key: another-value }
  2080. *
  2081. * from: { key: another-value }
  2082. * to: scalar -> { key: another-value }
  2083. * to: { key: value } -> { key: another-value }
  2084. * to: [ seq0, seq1 ] -> { key: another-value }
  2085. *
  2086. * The rules are:
  2087. * - If target node changes type, source ovewrites target.
  2088. * - If source or target node are scalars, source it overwrites target.
  2089. * - If target and source are sequences the items of the source sequence
  2090. * are appended to the target sequence.
  2091. * - If target and source are maps the key, value pairs of the source
  2092. * are appended to the target map. If the target map contains a
  2093. * key-value pair that is present in the source map, it is overwriten
  2094. * by it.
  2095. *
  2096. * @fyn_to: The target node
  2097. * @fyn_from: The source node
  2098. *
  2099. * Returns:
  2100. * 0 on success, -1 on error
  2101. */
  2102. int
  2103. fy_node_insert(struct fy_node *fyn_to, struct fy_node *fyn_from)
  2104. FY_EXPORT;
  2105. /**
  2106. * fy_document_insert_at() - Insert a node to the given path in the document
  2107. *
  2108. * Insert a node to a given point in the document. If @fyn is NULL then this
  2109. * operation will delete the target node.
  2110. *
  2111. * Please see fy_node_insert for details of operation.
  2112. *
  2113. * Note that in any case the fyn node will be unref'ed.
  2114. * So if the operation fails, and the reference is 0
  2115. * the node will be freed. If you want it to stick around
  2116. * take a reference before.
  2117. *
  2118. * @fyd: The document
  2119. * @path: The path where the insert operation will target
  2120. * @pathlen: The length of the path (or -1 if '\0' terminated)
  2121. * @fyn: The source node
  2122. *
  2123. * Returns:
  2124. * 0 on success, -1 on error
  2125. */
  2126. int
  2127. fy_document_insert_at(struct fy_document *fyd,
  2128. const char *path, size_t pathlen,
  2129. struct fy_node *fyn)
  2130. FY_EXPORT;
  2131. /**
  2132. * enum fy_node_type - Node type
  2133. *
  2134. * Each node may be one of the following types
  2135. *
  2136. * @FYNT_SCALAR: Node is a scalar
  2137. * @FYNT_SEQUENCE: Node is a sequence
  2138. * @FYNT_MAPPING: Node is a mapping
  2139. */
  2140. enum fy_node_type {
  2141. FYNT_SCALAR,
  2142. FYNT_SEQUENCE,
  2143. FYNT_MAPPING,
  2144. };
  2145. /**
  2146. * enum fy_node_style - Node style
  2147. *
  2148. * A node may contain a hint of how it should be
  2149. * rendered, encoded as a style.
  2150. *
  2151. * @FYNS_ANY: No hint, let the emitter decide
  2152. * @FYNS_FLOW: Prefer flow style (for sequence/mappings)
  2153. * @FYNS_BLOCK: Prefer block style (for sequence/mappings)
  2154. * @FYNS_PLAIN: Plain style preferred
  2155. * @FYNS_SINGLE_QUOTED: Single quoted style preferred
  2156. * @FYNS_DOUBLE_QUOTED: Double quoted style preferred
  2157. * @FYNS_LITERAL: Literal style preferred (valid in block context)
  2158. * @FYNS_FOLDED: Folded style preferred (valid in block context)
  2159. * @FYNS_ALIAS: It's an alias
  2160. */
  2161. enum fy_node_style {
  2162. FYNS_ANY = -1,
  2163. FYNS_FLOW,
  2164. FYNS_BLOCK,
  2165. FYNS_PLAIN,
  2166. FYNS_SINGLE_QUOTED,
  2167. FYNS_DOUBLE_QUOTED,
  2168. FYNS_LITERAL,
  2169. FYNS_FOLDED,
  2170. FYNS_ALIAS,
  2171. };
  2172. /* maximum depth is 256 */
  2173. #define FYNWF_MAXDEPTH_SHIFT 4
  2174. #define FYNWF_MAXDEPTH_MASK 0xff
  2175. #define FYNWF_MAXDEPTH(x) (((x) & FYNWF_MAXDEPTH_MASK) << FYNWF_MAXDEPTH_SHIFT)
  2176. #define FYNWF_MARKER_SHIFT 12
  2177. #define FYNWF_MARKER_MASK 0x1f
  2178. #define FYNWF_MARKER(x) (((x) & FYNWF_MARKER_MASK) << FYNWF_MARKER_SHIFT)
  2179. #define FYNWF_PTR_SHIFT 16
  2180. #define FYNWF_PTR_MASK 0x03
  2181. #define FYNWF_PTR(x) (((x) & FYNWF_PTR_MASK) << FYNWF_PTR_SHIFT)
  2182. /**
  2183. * enum fy_node_walk_flags - Node walk flags
  2184. *
  2185. * @FYNWF_DONT_FOLLOW: Don't follow aliases during pathwalk
  2186. * @FYNWF_FOLLOW: Follow aliases during pathwalk
  2187. * @FYNWF_PTR_YAML: YAML pointer path walks
  2188. * @FYNWF_PTR_JSON: JSON pointer path walks
  2189. * @FYNWF_PTR_RELJSON: Relative JSON pointer path walks
  2190. * @FYNWF_PTR_YPATH: YPATH pointer path walks
  2191. * @FYNWF_URI_ENCODED: The path is URI encoded
  2192. * @FYNWF_MAXDEPTH_DEFAULT: Max follow depth is automatically determined
  2193. * @FYNWF_MARKER_DEFAULT: Default marker to use when scanning
  2194. * @FYNWF_PTR_DEFAULT: Default path type
  2195. */
  2196. enum fy_node_walk_flags {
  2197. FYNWF_DONT_FOLLOW = 0,
  2198. FYNWF_FOLLOW = FY_BIT(0),
  2199. FYNWF_PTR_YAML = FYNWF_PTR(0),
  2200. FYNWF_PTR_JSON = FYNWF_PTR(1),
  2201. FYNWF_PTR_RELJSON = FYNWF_PTR(2),
  2202. FYNWF_PTR_YPATH = FYNWF_PTR(3),
  2203. FYNWF_URI_ENCODED = FY_BIT(18),
  2204. FYNWF_MAXDEPTH_DEFAULT = FYNWF_MAXDEPTH(0),
  2205. FYNWF_MARKER_DEFAULT = FYNWF_MARKER(0),
  2206. FYNWF_PTR_DEFAULT = FYNWF_PTR(0),
  2207. };
  2208. /* the maximum user marker */
  2209. #define FYNWF_MAX_USER_MARKER 24
  2210. /**
  2211. * fy_node_style_from_scalar_style() - Convert from scalar to node style
  2212. *
  2213. * Convert a scalar style to a node style.
  2214. *
  2215. * @sstyle: The input scalar style
  2216. *
  2217. * Returns:
  2218. * The matching node style
  2219. */
  2220. static inline enum fy_node_style
  2221. fy_node_style_from_scalar_style(enum fy_scalar_style sstyle)
  2222. {
  2223. if (sstyle == FYSS_ANY)
  2224. return FYNS_ANY;
  2225. return (enum fy_node_style)(FYNS_PLAIN + (sstyle - FYSS_PLAIN));
  2226. }
  2227. /**
  2228. * typedef fy_node_mapping_sort_fn - Mapping sorting method function
  2229. *
  2230. * @fynp_a: The first node_pair used in the comparison
  2231. * @fynp_b: The second node_pair used in the comparison
  2232. * @arg: The opaque user provided pointer to the sort operation
  2233. *
  2234. * Returns:
  2235. * <0 if @fynp_a is less than @fynp_b
  2236. * 0 if @fynp_a is equal to fynp_b
  2237. * >0 if @fynp_a is greater than @fynp_b
  2238. */
  2239. typedef int (*fy_node_mapping_sort_fn)(const struct fy_node_pair *fynp_a,
  2240. const struct fy_node_pair *fynp_b,
  2241. void *arg);
  2242. /**
  2243. * typedef fy_node_scalar_compare_fn - Node compare method function for scalars
  2244. *
  2245. * @fyn_a: The first scalar node used in the comparison
  2246. * @fyn_b: The second scalar node used in the comparison
  2247. * @arg: The opaque user provided pointer to the compare operation
  2248. *
  2249. * Returns:
  2250. * <0 if @fyn_a is less than @fyn_b
  2251. * 0 if @fyn_a is equal to fyn_b
  2252. * >0 if @fyn_a is greater than @fyn_b
  2253. */
  2254. typedef int (*fy_node_scalar_compare_fn)(struct fy_node *fyn_a,
  2255. struct fy_node *fyn_b,
  2256. void *arg);
  2257. /**
  2258. * fy_node_compare() - Compare two nodes for equality
  2259. *
  2260. * Compare two nodes for equality.
  2261. * The comparison is 'deep', i.e. it recurses in subnodes,
  2262. * and orders the keys of maps using default libc strcmp
  2263. * ordering. For scalar the comparison is performed after
  2264. * any escaping so it's a true content comparison.
  2265. *
  2266. * @fyn1: The first node to use in the comparison
  2267. * @fyn2: The second node to use in the comparison
  2268. *
  2269. * Returns:
  2270. * true if the nodes contain the same content, false otherwise
  2271. */
  2272. bool
  2273. fy_node_compare(struct fy_node *fyn1, struct fy_node *fyn2)
  2274. FY_EXPORT;
  2275. /**
  2276. * fy_node_compare_user() - Compare two nodes for equality using
  2277. * user supplied sort and scalar compare methods
  2278. *
  2279. * Compare two nodes for equality using user supplied sot and scalar
  2280. * compare methods.
  2281. * The comparison is 'deep', i.e. it recurses in subnodes,
  2282. * and orders the keys of maps using the supplied mapping sort method for
  2283. * ordering. For scalars the comparison is performed using the supplied
  2284. * scalar node compare methods.
  2285. *
  2286. * @fyn1: The first node to use in the comparison
  2287. * @fyn2: The second node to use in the comparison
  2288. * @sort_fn: The method to use for sorting maps, or NULL for the default
  2289. * @sort_fn_arg: The extra user supplied argument to the @sort_fn
  2290. * @cmp_fn: The method to use for comparing scalars, or NULL for the default
  2291. * @cmp_fn_arg: The extra user supplied argument to the @cmp_fn
  2292. *
  2293. * Returns:
  2294. * true if the nodes contain the same content, false otherwise
  2295. */
  2296. bool
  2297. fy_node_compare_user(struct fy_node *fyn1, struct fy_node *fyn2,
  2298. fy_node_mapping_sort_fn sort_fn, void *sort_fn_arg,
  2299. fy_node_scalar_compare_fn cmp_fn, void *cmp_fn_arg)
  2300. FY_EXPORT;
  2301. /**
  2302. * fy_node_compare_string() - Compare a node for equality with a YAML string
  2303. *
  2304. * Compare a node for equality with a YAML string.
  2305. * The comparison is performed using fy_node_compare() with the
  2306. * first node supplied as an argument and the second being generated
  2307. * by calling fy_document_build_from_string with the YAML string.
  2308. *
  2309. * @fyn: The node to use in the comparison
  2310. * @str: The YAML string to compare against
  2311. * @len: The length of the string (or -1 if '\0' terminated)
  2312. *
  2313. * Returns:
  2314. * true if the node and the string are equal.
  2315. */
  2316. bool
  2317. fy_node_compare_string(struct fy_node *fyn, const char *str, size_t len)
  2318. FY_EXPORT;
  2319. /**
  2320. * fy_node_compare_token() - Compare a node for equality against a token
  2321. *
  2322. * Compare a node for equality with a token.
  2323. * Both the node and the tokens must be a scalars.
  2324. *
  2325. * @fyn: The node to use in the comparison
  2326. * @fyt: The scalar token
  2327. *
  2328. * Returns:
  2329. * true if the node and the token are equal.
  2330. */
  2331. bool
  2332. fy_node_compare_token(struct fy_node *fyn, struct fy_token *fyt)
  2333. FY_EXPORT;
  2334. /**
  2335. * fy_node_compare_text() - Compare a node for equality with a raw C text
  2336. *
  2337. * Compare a node for equality with a raw C string.
  2338. * The node must be a scalar.
  2339. *
  2340. * @fyn: The node to use in the comparison
  2341. * @text: The raw C text to compare against
  2342. * @len: The length of the text (or -1 if '\0' terminated)
  2343. *
  2344. * Returns:
  2345. * true if the node and the text are equal.
  2346. */
  2347. bool
  2348. fy_node_compare_text(struct fy_node *fyn, const char *text, size_t len)
  2349. FY_EXPORT;
  2350. /**
  2351. * fy_document_create() - Create an empty document
  2352. *
  2353. * Create an empty document using the provided parser configuration.
  2354. * If NULL use the default parse configuration.
  2355. *
  2356. * @cfg: The parse configuration to use or NULL for the default.
  2357. *
  2358. * Returns:
  2359. * The created empty document, or NULL on error.
  2360. */
  2361. struct fy_document *
  2362. fy_document_create(const struct fy_parse_cfg *cfg)
  2363. FY_EXPORT;
  2364. /**
  2365. * fy_document_destroy() - Destroy a document previously created via
  2366. * fy_document_create()
  2367. *
  2368. * Destroy a document (along with all children documents)
  2369. *
  2370. * @fyd: The document to destroy
  2371. *
  2372. */
  2373. void
  2374. fy_document_destroy(struct fy_document *fyd)
  2375. FY_EXPORT;
  2376. /**
  2377. * fy_document_get_cfg() - Get the configuration of a document
  2378. *
  2379. * @fyd: The document
  2380. *
  2381. * Returns:
  2382. * The configuration of the document
  2383. */
  2384. const struct fy_parse_cfg *
  2385. fy_document_get_cfg(struct fy_document *fyd)
  2386. FY_EXPORT;
  2387. /**
  2388. * fy_document_get_diag() - Get the diagnostic object of a document
  2389. *
  2390. * Return a pointer to the diagnostic object of a document object.
  2391. * Note that the returned diag object has a reference taken so
  2392. * you should fy_diag_unref() it when you're done with it.
  2393. *
  2394. * @fyd: The document to get the diagnostic object
  2395. *
  2396. * Returns:
  2397. * A pointer to a ref'ed diagnostic object or NULL in case of an
  2398. * error.
  2399. */
  2400. struct fy_diag *
  2401. fy_document_get_diag(struct fy_document *fyd)
  2402. FY_EXPORT;
  2403. /**
  2404. * fy_document_set_diag() - Set the diagnostic object of a document
  2405. *
  2406. * Replace the documents's current diagnostic object with the one
  2407. * given as an argument. The previous diagnostic object will be
  2408. * unref'ed (and freed if its reference gets to 0).
  2409. * Also note that the diag argument shall take a reference too.
  2410. *
  2411. * @fyd: The document to replace the diagnostic object
  2412. * @diag: The document's new diagnostic object, NULL for default
  2413. *
  2414. * Returns:
  2415. * 0 if everything OK, -1 otherwise
  2416. */
  2417. int
  2418. fy_document_set_diag(struct fy_document *fyd, struct fy_diag *diag)
  2419. FY_EXPORT;
  2420. /**
  2421. * fy_document_set_parent() - Make a document a child of another
  2422. *
  2423. * Set the parent of @fyd_child document to be @fyd
  2424. *
  2425. * @fyd: The parent document
  2426. * @fyd_child: The child document
  2427. *
  2428. * Returns:
  2429. * 0 if all OK, -1 on error.
  2430. */
  2431. int
  2432. fy_document_set_parent(struct fy_document *fyd, struct fy_document *fyd_child)
  2433. FY_EXPORT;
  2434. /**
  2435. * fy_document_build_from_string() - Create a document using the provided YAML source.
  2436. *
  2437. * Create a document parsing the provided string as a YAML source.
  2438. *
  2439. * @cfg: The parse configuration to use or NULL for the default.
  2440. * @str: The YAML source to use.
  2441. * @len: The length of the string (or -1 if '\0' terminated)
  2442. *
  2443. * Returns:
  2444. * The created document, or NULL on error.
  2445. */
  2446. struct fy_document *
  2447. fy_document_build_from_string(const struct fy_parse_cfg *cfg,
  2448. const char *str, size_t len)
  2449. FY_EXPORT;
  2450. /**
  2451. * fy_document_build_from_malloc_string() - Create a document using the provided YAML source which was malloced.
  2452. *
  2453. * Create a document parsing the provided string as a YAML source. The string is expected to have been
  2454. * allocated by malloc(3) and when the document is destroyed it will be automatically freed.
  2455. *
  2456. * @cfg: The parse configuration to use or NULL for the default.
  2457. * @str: The YAML source to use.
  2458. * @len: The length of the string (or -1 if '\0' terminated)
  2459. *
  2460. * Returns:
  2461. * The created document, or NULL on error.
  2462. */
  2463. struct fy_document *
  2464. fy_document_build_from_malloc_string(const struct fy_parse_cfg *cfg,
  2465. char *str, size_t len)
  2466. FY_EXPORT;
  2467. /**
  2468. * fy_document_build_from_file() - Create a document parsing the given file
  2469. *
  2470. * Create a document parsing the provided file as a YAML source.
  2471. *
  2472. * @cfg: The parse configuration to use or NULL for the default.
  2473. * @file: The name of the file to parse
  2474. *
  2475. * Returns:
  2476. * The created document, or NULL on error.
  2477. */
  2478. struct fy_document *
  2479. fy_document_build_from_file(const struct fy_parse_cfg *cfg, const char *file)
  2480. FY_EXPORT;
  2481. /**
  2482. * fy_document_build_from_fp() - Create a document parsing the given file pointer
  2483. *
  2484. * Create a document parsing the provided file pointer as a YAML source.
  2485. *
  2486. * @cfg: The parse configuration to use or NULL for the default.
  2487. * @fp: The file pointer
  2488. *
  2489. * Returns:
  2490. * The created document, or NULL on error.
  2491. */
  2492. struct fy_document *
  2493. fy_document_build_from_fp(const struct fy_parse_cfg *cfg, FILE *fp)
  2494. FY_EXPORT;
  2495. /**
  2496. * fy_document_vbuildf() - Create a document using the provided YAML via vprintf formatting
  2497. *
  2498. * Create a document parsing the provided string as a YAML source. The string
  2499. * is created by applying vprintf formatting.
  2500. *
  2501. * @cfg: The parse configuration to use or NULL for the default.
  2502. * @fmt: The format string creating the YAML source to use.
  2503. * @ap: The va_list argument pointer
  2504. *
  2505. * Returns:
  2506. * The created document, or NULL on error.
  2507. */
  2508. struct fy_document *
  2509. fy_document_vbuildf(const struct fy_parse_cfg *cfg,
  2510. const char *fmt, va_list ap)
  2511. FY_EXPORT;
  2512. /**
  2513. * fy_document_buildf() - Create a document using the provided YAML source via printf formatting
  2514. *
  2515. * Create a document parsing the provided string as a YAML source. The string
  2516. * is created by applying printf formatting.
  2517. *
  2518. * @cfg: The parse configuration to use or NULL for the default.
  2519. * @fmt: The format string creating the YAML source to use.
  2520. * @...: The printf arguments
  2521. *
  2522. * Returns:
  2523. * The created document, or NULL on error.
  2524. */
  2525. struct fy_document *
  2526. fy_document_buildf(const struct fy_parse_cfg *cfg, const char *fmt, ...)
  2527. FY_ATTRIBUTE(format(printf, 2, 3))
  2528. FY_EXPORT;
  2529. /**
  2530. * fy_flow_document_build_from_string() - Create a document using the provided YAML source.
  2531. *
  2532. * Create a document parsing the provided string as a YAML source.
  2533. *
  2534. * The document is a flow document, i.e. does not contain any block content
  2535. * and is usually laid out in a single line.
  2536. *
  2537. * Example of flow documents:
  2538. *
  2539. * plain-scalar
  2540. * "double-quoted-scalar"
  2541. * 'single-quoted-scalar'
  2542. * { foo: bar }
  2543. * [ 0, 1, 2 ]
  2544. *
  2545. * A flow document is important because parsing stops at the end
  2546. * of it, and so can be placed in other non-yaml content.
  2547. *
  2548. * @cfg: The parse configuration to use or NULL for the default.
  2549. * @str: The YAML source to use.
  2550. * @len: The length of the string (or -1 if '\0' terminated)
  2551. * @consumed: A pointer to the consumed amount
  2552. *
  2553. * Returns:
  2554. * The created document, or NULL on error.
  2555. */
  2556. struct fy_document *
  2557. fy_flow_document_build_from_string(const struct fy_parse_cfg *cfg,
  2558. const char *str, size_t len, size_t *consumed)
  2559. FY_EXPORT;
  2560. /**
  2561. * fy_document_root() - Return the root node of the document
  2562. *
  2563. * Returns the root of the document. If the document is empty
  2564. * NULL will be returned instead.
  2565. *
  2566. * @fyd: The document
  2567. *
  2568. * Returns:
  2569. * The root of the document, or NULL if the document is empty.
  2570. */
  2571. struct fy_node *
  2572. fy_document_root(struct fy_document *fyd)
  2573. FY_EXPORT;
  2574. /**
  2575. * fy_document_set_root() - Set the root of the document
  2576. *
  2577. * Set the root of a document. If the document was not empty
  2578. * the old root will be freed. If @fyn is NULL then the
  2579. * document is set to empty.
  2580. *
  2581. * @fyd: The document
  2582. * @fyn: The new root of the document.
  2583. *
  2584. * Returns:
  2585. * 0 on success, -1 on error
  2586. */
  2587. int
  2588. fy_document_set_root(struct fy_document *fyd, struct fy_node *fyn)
  2589. FY_EXPORT;
  2590. /**
  2591. * fy_node_get_type() - Get the node type
  2592. *
  2593. * Retrieve the node type. It is one of FYNT_SCALAR, FYNT_SEQUENCE
  2594. * or FYNT_MAPPING. A NULL node argument is a FYNT_SCALAR.
  2595. *
  2596. * @fyn: The node
  2597. *
  2598. * Returns:
  2599. * The node type
  2600. */
  2601. enum fy_node_type
  2602. fy_node_get_type(struct fy_node *fyn)
  2603. FY_EXPORT;
  2604. /**
  2605. * fy_node_get_style() - Get the node style
  2606. *
  2607. * Retrieve the node rendering style.
  2608. * If the node is NULL then the style is FYNS_PLAIN.
  2609. *
  2610. * @fyn: The node
  2611. *
  2612. * Returns:
  2613. * The node style
  2614. */
  2615. enum fy_node_style
  2616. fy_node_get_style(struct fy_node *fyn)
  2617. FY_EXPORT;
  2618. /**
  2619. * fy_node_set_style() - Set the node style
  2620. *
  2621. * Set the node rendering style.
  2622. * If current node style is alias it won't be changed
  2623. * to save document structure
  2624. *
  2625. * @fyn: The node
  2626. * @style: The node style
  2627. */
  2628. void
  2629. fy_node_set_style(struct fy_node *fyn, enum fy_node_style style)
  2630. FY_EXPORT;
  2631. /**
  2632. * fy_node_is_scalar() - Check whether the node is a scalar
  2633. *
  2634. * Convenience method for checking whether a node is a scalar.
  2635. *
  2636. * @fyn: The node
  2637. *
  2638. * Returns:
  2639. * true if the node is a scalar, false otherwise
  2640. */
  2641. static inline bool
  2642. fy_node_is_scalar(struct fy_node *fyn)
  2643. {
  2644. return fy_node_get_type(fyn) == FYNT_SCALAR;
  2645. }
  2646. /**
  2647. * fy_node_is_sequence() - Check whether the node is a sequence
  2648. *
  2649. * Convenience method for checking whether a node is a sequence.
  2650. *
  2651. * @fyn: The node
  2652. *
  2653. * Returns:
  2654. * true if the node is a sequence, false otherwise
  2655. */
  2656. static inline bool
  2657. fy_node_is_sequence(struct fy_node *fyn)
  2658. {
  2659. return fy_node_get_type(fyn) == FYNT_SEQUENCE;
  2660. }
  2661. /**
  2662. * fy_node_is_mapping() - Check whether the node is a mapping
  2663. *
  2664. * Convenience method for checking whether a node is a mapping.
  2665. *
  2666. * @fyn: The node
  2667. *
  2668. * Returns:
  2669. * true if the node is a mapping, false otherwise
  2670. */
  2671. static inline bool
  2672. fy_node_is_mapping(struct fy_node *fyn)
  2673. {
  2674. return fy_node_get_type(fyn) == FYNT_MAPPING;
  2675. }
  2676. /**
  2677. * fy_node_is_alias() - Check whether the node is an alias
  2678. *
  2679. * Convenience method for checking whether a node is an alias.
  2680. *
  2681. * @fyn: The node
  2682. *
  2683. * Returns:
  2684. * true if the node is an alias, false otherwise
  2685. */
  2686. static inline bool
  2687. fy_node_is_alias(struct fy_node *fyn)
  2688. {
  2689. return fy_node_get_type(fyn) == FYNT_SCALAR &&
  2690. fy_node_get_style(fyn) == FYNS_ALIAS;
  2691. }
  2692. /**
  2693. * fy_node_is_null() - Check whether the node is a NULL
  2694. *
  2695. * Convenience method for checking whether a node is a NULL scalar..
  2696. * Note that a NULL node argument returns true...
  2697. *
  2698. * @fyn: The node
  2699. *
  2700. * Returns:
  2701. * true if the node is a NULL scalar, false otherwise
  2702. */
  2703. bool
  2704. fy_node_is_null(struct fy_node *fyn)
  2705. FY_EXPORT;
  2706. /**
  2707. * fy_node_is_attached() - Check whether the node is attached
  2708. *
  2709. * Checks whether a node is attached in a document structure.
  2710. * An attached node may not be freed, before being detached.
  2711. * Note that there is no method that explicitly detaches
  2712. * a node, since this is handled internaly by the sequence
  2713. * and mapping removal methods.
  2714. *
  2715. * @fyn: The node
  2716. *
  2717. * Returns:
  2718. * true if the node is attached, false otherwise
  2719. */
  2720. bool
  2721. fy_node_is_attached(struct fy_node *fyn)
  2722. FY_EXPORT;
  2723. /**
  2724. * fy_node_get_tag_token() - Gets the tag token of a node (if it exists)
  2725. *
  2726. * Gets the tag token of a node, if it exists
  2727. *
  2728. * @fyn: The node which has the tag token to be returned
  2729. *
  2730. * Returns:
  2731. * The tag token of the given node, or NULL if the tag does not
  2732. * exist.
  2733. */
  2734. struct fy_token *
  2735. fy_node_get_tag_token(struct fy_node *fyn)
  2736. FY_EXPORT;
  2737. /**
  2738. * fy_node_get_scalar_token() - Gets the scalar token of a node (if it exists)
  2739. *
  2740. * Gets the scalar token of a node, if it exists and the node is a valid scalar
  2741. * node. Note that aliases are scalars, so if this call is issued on an alias
  2742. * node the return shall be of an alias token.
  2743. *
  2744. * @fyn: The node which has the scalar token to be returned
  2745. *
  2746. * Returns:
  2747. * The scalar token of the given node, or NULL if the node is not a scalar.
  2748. */
  2749. struct fy_token *
  2750. fy_node_get_scalar_token(struct fy_node *fyn)
  2751. FY_EXPORT;
  2752. /**
  2753. * fy_node_resolve_alias() - Resolve an alias node
  2754. *
  2755. * Resolve an alias node, following any subsequent aliases until
  2756. * a non alias node has been found. This call performs cycle detection
  2757. * and excessive redirections checks so it's safe to call in any
  2758. * context.
  2759. *
  2760. * @fyn: The alias node to be resolved
  2761. *
  2762. * Returns:
  2763. * The resolved alias node, or NULL if either fyn is not an alias, or
  2764. * resolution fails due to a graph cycle.
  2765. */
  2766. struct fy_node *
  2767. fy_node_resolve_alias(struct fy_node *fyn)
  2768. FY_EXPORT;
  2769. /**
  2770. * fy_node_dereference() - Dereference a single alias node
  2771. *
  2772. * Dereference an alias node. This is different than resolution
  2773. * in that will only perform a single alias follow call and
  2774. * it will fail if the input is not an alias.
  2775. * This call performs cycle detection
  2776. * and excessive redirections checks so it's safe to call in any
  2777. * context.
  2778. *
  2779. * @fyn: The alias node to be dereferenced
  2780. *
  2781. * Returns:
  2782. * The dereferenced alias node, or NULL if either fyn is not an alias, or
  2783. * resolution fails due to a graph cycle.
  2784. */
  2785. struct fy_node *
  2786. fy_node_dereference(struct fy_node *fyn)
  2787. FY_EXPORT;
  2788. /**
  2789. * fy_node_free() - Free a node
  2790. *
  2791. * Recursively frees the given node releasing the memory it uses, removing
  2792. * any anchors on the document it contains, and releasing references
  2793. * on the tokens it contains.
  2794. *
  2795. * This method will return an error if the node is attached, or
  2796. * if not NULL it is not a member of a document.
  2797. *
  2798. * @fyn: The node to free
  2799. *
  2800. * Returns:
  2801. * 0 on success, -1 on error.
  2802. */
  2803. int
  2804. fy_node_free(struct fy_node *fyn)
  2805. FY_EXPORT;
  2806. /**
  2807. * fy_node_build_from_string() - Create a node using the provided YAML source.
  2808. *
  2809. * Create a node parsing the provided string as a YAML source. The
  2810. * node created will be associated with the provided document.
  2811. *
  2812. * @fyd: The document
  2813. * @str: The YAML source to use.
  2814. * @len: The length of the string (or -1 if '\0' terminated)
  2815. *
  2816. * Returns:
  2817. * The created node, or NULL on error.
  2818. */
  2819. struct fy_node *
  2820. fy_node_build_from_string(struct fy_document *fyd,
  2821. const char *str, size_t len)
  2822. FY_EXPORT;
  2823. /**
  2824. * fy_node_build_from_malloc_string() - Create a node using the provided YAML source which was malloced.
  2825. *
  2826. * Create a node parsing the provided string as a YAML source. The
  2827. * node created will be associated with the provided document. The string is expected to have been
  2828. * allocated by malloc(3) and when the document is destroyed it will be automatically freed.
  2829. *
  2830. * @fyd: The document
  2831. * @str: The YAML source to use.
  2832. * @len: The length of the string (or -1 if '\0' terminated)
  2833. *
  2834. * Returns:
  2835. * The created node, or NULL on error.
  2836. */
  2837. struct fy_node *
  2838. fy_node_build_from_malloc_string(struct fy_document *fyd,
  2839. char *str, size_t len)
  2840. FY_EXPORT;
  2841. /**
  2842. * fy_node_build_from_file() - Create a node using the provided YAML file.
  2843. *
  2844. * Create a node parsing the provided file as a YAML source. The
  2845. * node created will be associated with the provided document.
  2846. *
  2847. * @fyd: The document
  2848. * @file: The name of the file to parse
  2849. *
  2850. * Returns:
  2851. * The created node, or NULL on error.
  2852. */
  2853. struct fy_node *
  2854. fy_node_build_from_file(struct fy_document *fyd, const char *file)
  2855. FY_EXPORT;
  2856. /**
  2857. * fy_node_build_from_fp() - Create a node using the provided file pointer.
  2858. *
  2859. * Create a node parsing the provided file pointer as a YAML source. The
  2860. * node created will be associated with the provided document.
  2861. *
  2862. * @fyd: The document
  2863. * @fp: The file pointer
  2864. *
  2865. * Returns:
  2866. * The created node, or NULL on error.
  2867. */
  2868. struct fy_node *
  2869. fy_node_build_from_fp(struct fy_document *fyd, FILE *fp)
  2870. FY_EXPORT;
  2871. /**
  2872. * fy_node_vbuildf() - Create a node using the provided YAML source via vprintf formatting
  2873. *
  2874. * Create a node parsing the resulting string as a YAML source. The string
  2875. * is created by applying vprintf formatting.
  2876. *
  2877. * @fyd: The document
  2878. * @fmt: The format string creating the YAML source to use.
  2879. * @ap: The va_list argument pointer
  2880. *
  2881. * Returns:
  2882. * The created node, or NULL on error.
  2883. */
  2884. struct fy_node *
  2885. fy_node_vbuildf(struct fy_document *fyd, const char *fmt, va_list ap)
  2886. FY_EXPORT;
  2887. /**
  2888. * fy_node_buildf() - Create a node using the provided YAML source via printf formatting
  2889. *
  2890. * Create a node parsing the resulting string as a YAML source. The string
  2891. * is created by applying printf formatting.
  2892. *
  2893. * @fyd: The document
  2894. * @fmt: The format string creating the YAML source to use.
  2895. * @...: The printf arguments
  2896. *
  2897. * Returns:
  2898. * The created node, or NULL on error.
  2899. */
  2900. struct fy_node *
  2901. fy_node_buildf(struct fy_document *fyd, const char *fmt, ...)
  2902. FY_ATTRIBUTE(format(printf, 2, 3))
  2903. FY_EXPORT;
  2904. /**
  2905. * fy_node_by_path() - Retrieve a node using the provided path spec.
  2906. *
  2907. * This method will retrieve a node relative to the given node using
  2908. * the provided path spec.
  2909. *
  2910. * Path specs are comprised of keys seperated by slashes '/'.
  2911. * Keys are either regular YAML expressions in flow format for traversing
  2912. * mappings, or indexes in brackets for traversing sequences.
  2913. * Path specs may start with '/' which is silently ignored.
  2914. *
  2915. * A few examples will make this clear
  2916. *
  2917. * fyn = { foo: bar } - fy_node_by_path(fyn, "/foo") -> bar
  2918. * fyn = [ foo, bar ] - fy_node_by_path(fyn, "1") -> bar
  2919. * fyn = { { foo: bar }: baz } - fy_node_by_path(fyn, "{foo: bar}") -> baz
  2920. * fyn = [ foo, { bar: baz } } - fy_node_by_path(fyn, "1/bar") -> baz
  2921. *
  2922. * Note that the special characters /{}[] are not escaped in plain style,
  2923. * so you will not be able to use them as path traversal keys.
  2924. * In that case you can easily use either the single, or double quoted forms:
  2925. *
  2926. * fyn = { foo/bar: baz } - fy_node_by_path(fyn, "'foo/bar'") -> baz
  2927. *
  2928. * @fyn: The node to use as start of the traversal operation
  2929. * @path: The path spec to use in the traversal operation
  2930. * @len: The length of the path (or -1 if '\0' terminated)
  2931. * @flags: The extra path walk flags
  2932. *
  2933. * Returns:
  2934. * The retrieved node, or NULL if not possible to be found.
  2935. */
  2936. struct fy_node *
  2937. fy_node_by_path(struct fy_node *fyn, const char *path, size_t len,
  2938. enum fy_node_walk_flags flags)
  2939. FY_EXPORT;
  2940. /**
  2941. * fy_node_get_path() - Get the path of this node
  2942. *
  2943. * Retrieve the given node's path address relative to the document root.
  2944. * The address is dynamically allocated and should be freed when
  2945. * you're done with it.
  2946. *
  2947. * @fyn: The node
  2948. *
  2949. * Returns:
  2950. * The node's address, or NULL if fyn is the root.
  2951. */
  2952. char *
  2953. fy_node_get_path(struct fy_node *fyn)
  2954. FY_EXPORT;
  2955. #define fy_node_get_path_alloca(_fyn, _res) \
  2956. FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path((_fyn)), FY_NT, (_res))
  2957. /**
  2958. * fy_node_get_parent() - Get the parent node of a node
  2959. *
  2960. * Get the parent node of a node. The parent of a document's root
  2961. * is NULL, and so is the parent of the root of a key node's of a mapping.
  2962. * This is because the nodes of a key may not be addressed using a
  2963. * path expression.
  2964. *
  2965. * @fyn: The node
  2966. *
  2967. * Returns:
  2968. * The node's parent, or NULL if fyn is the root, or the root of a key mapping.
  2969. */
  2970. struct fy_node *
  2971. fy_node_get_parent(struct fy_node *fyn)
  2972. FY_EXPORT;
  2973. /**
  2974. * fy_node_get_document_parent() - Get the document parent node of a node
  2975. *
  2976. * Get the document parent node of a node. The document parent differs
  2977. * than the regular parent in that a key's root node of a mapping is not
  2978. * NULL, rather it points to the actual node parent.
  2979. *
  2980. * @fyn: The node
  2981. *
  2982. * Returns:
  2983. * The node's document parent, or NULL if fyn is the root
  2984. */
  2985. struct fy_node *
  2986. fy_node_get_document_parent(struct fy_node *fyn)
  2987. FY_EXPORT;
  2988. /**
  2989. * fy_node_get_parent_address() - Get the path address of this node's parent
  2990. *
  2991. * Retrieve the given node's parent path address
  2992. * The address is dynamically allocated and should be freed when
  2993. * you're done with it.
  2994. *
  2995. * @fyn: The node
  2996. *
  2997. * Returns:
  2998. * The parent's address, or NULL if fyn is the root.
  2999. */
  3000. char *
  3001. fy_node_get_parent_address(struct fy_node *fyn)
  3002. FY_EXPORT;
  3003. #define fy_node_get_parent_address_alloca(_fyn, _res) \
  3004. FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_parent_address((_fyn)), FY_NT, (_res))
  3005. /**
  3006. * fy_node_get_path_relative_to() - Get a path address of a node
  3007. * relative to one of it's parents
  3008. *
  3009. * Retrieve the given node's path address relative to an arbitrary
  3010. * parent in the tree.
  3011. * The address is dynamically allocated and should be freed when
  3012. * you're done with it.
  3013. *
  3014. * @fyn_parent: The node parent/grandparent...
  3015. * @fyn: The node
  3016. *
  3017. * Returns:
  3018. * The relative address from the parent to the node
  3019. */
  3020. char *
  3021. fy_node_get_path_relative_to(struct fy_node *fyn_parent, struct fy_node *fyn)
  3022. FY_EXPORT;
  3023. #define fy_node_get_path_relative_to_alloca(_fynp, _fyn, _res) \
  3024. FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_path_relative_to((_fynp), (_fyn)), FY_NT, (_res))
  3025. /**
  3026. * fy_node_get_short_path() - Get a path address of a node in the shortest
  3027. * path possible
  3028. *
  3029. * Retrieve the given node's short path address relative to the
  3030. * closest anchor (either on this node, or it's parent).
  3031. * If no such parent is found then returns the absolute path
  3032. * from the start of the document.
  3033. *
  3034. * --- &foo
  3035. * foo: &bar
  3036. * bar
  3037. * baz
  3038. *
  3039. * - The short path of /foo is \*foo
  3040. * - The short path of /foo/bar is \*bar
  3041. * - The short path of /baz is \*foo/baz
  3042. *
  3043. * The address is dynamically allocated and should be freed when
  3044. * you're done with it.
  3045. *
  3046. * @fyn: The node
  3047. *
  3048. * Returns:
  3049. * The shortest path describing the node
  3050. */
  3051. char *
  3052. fy_node_get_short_path(struct fy_node *fyn)
  3053. FY_EXPORT;
  3054. #define fy_node_get_short_path_alloca(_fyn, _res) \
  3055. FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_short_path((_fyn)), FY_NT, (_res))
  3056. /**
  3057. * fy_node_get_reference() - Get a textual reference to a node
  3058. *
  3059. * Retrieve the given node's textual reference. If the node
  3060. * contains an anchor the expression that references the anchor
  3061. * will be returned, otherwise an absolute path reference relative
  3062. * to the root of the document will be returned.
  3063. *
  3064. * The address is dynamically allocated and should be freed when
  3065. * you're done with it.
  3066. *
  3067. * @fyn: The node
  3068. *
  3069. * Returns:
  3070. * The node's text reference.
  3071. */
  3072. char *
  3073. fy_node_get_reference(struct fy_node *fyn)
  3074. FY_EXPORT;
  3075. #define fy_node_get_reference_alloca(_fyn, _res) \
  3076. FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_reference((_fyn)), FY_NT, (_res))
  3077. /**
  3078. * fy_node_create_reference() - Create an alias reference node
  3079. *
  3080. * Create an alias node reference. If the node
  3081. * contains an anchor the expression that references the alias will
  3082. * use the anchor, otherwise an absolute path reference relative
  3083. * to the root of the document will be created.
  3084. *
  3085. * @fyn: The node
  3086. *
  3087. * Returns:
  3088. * An alias node referencing the argument node
  3089. */
  3090. struct fy_node *
  3091. fy_node_create_reference(struct fy_node *fyn)
  3092. FY_EXPORT;
  3093. /**
  3094. * fy_node_get_relative_reference() - Get a textual reference to a node
  3095. * relative to a base node.
  3096. *
  3097. * Retrieve the given node's textual reference as generated using
  3098. * another parent (or grand parent) as a base.
  3099. * If the node contains an anchor the expression that references the anchor
  3100. * will be returned.
  3101. * If the base node contains an anchor the reference will be relative to it
  3102. * otherwise an absolute path reference will be returned.
  3103. *
  3104. * The address is dynamically allocated and should be freed when
  3105. * you're done with it.
  3106. *
  3107. * @fyn_base: The base node
  3108. * @fyn: The node
  3109. *
  3110. * Returns:
  3111. * The node's text reference.
  3112. */
  3113. char *
  3114. fy_node_get_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)
  3115. FY_EXPORT;
  3116. #define fy_node_get_relative_reference_alloca(_fynb, _fyn, _res) \
  3117. FY_ALLOCA_COPY_FREE_NO_NULL(fy_node_get_relative_reference((_fynb), (_fyn)), FY_NT, (_res))
  3118. /**
  3119. * fy_node_create_relative_reference() - Create an alias reference node
  3120. *
  3121. * Create a relative alias node reference using
  3122. * another parent (or grand parent) as a base.
  3123. * If the node contains an anchor the alias will reference the anchor.
  3124. * If the base node contains an anchor the alias will be relative to it
  3125. * otherwise an absolute path reference will be created.
  3126. *
  3127. * @fyn_base: The base node
  3128. * @fyn: The node
  3129. *
  3130. * Returns:
  3131. * An alias node referencing the argument node relative to the base
  3132. */
  3133. struct fy_node *
  3134. fy_node_create_relative_reference(struct fy_node *fyn_base, struct fy_node *fyn)
  3135. FY_EXPORT;
  3136. /**
  3137. * fy_node_create_scalar() - Create a scalar node.
  3138. *
  3139. * Create a scalar node using the provided memory area as input.
  3140. * The input is expected to be regular utf8 encoded. It may contain
  3141. * escaped characters in which case the style of the scalar will be
  3142. * set to double quoted.
  3143. *
  3144. * Note that the data are not copied, merely a reference is taken, so
  3145. * it must be available while the node is in use.
  3146. *
  3147. * @fyd: The document which the resulting node will be associated with
  3148. * @data: Pointer to the data area
  3149. * @size: Size of the data area, or (size_t)-1 for '\0' terminated data.
  3150. *
  3151. * Returns:
  3152. * The created node, or NULL on error.
  3153. */
  3154. struct fy_node *
  3155. fy_node_create_scalar(struct fy_document *fyd,
  3156. const char *data, size_t size)
  3157. FY_EXPORT;
  3158. /**
  3159. * fy_node_create_scalar_copy() - Create a scalar node copying the data.
  3160. *
  3161. * Create a scalar node using the provided memory area as input.
  3162. * The input is expected to be regular utf8 encoded. It may contain
  3163. * escaped characters in which case the style of the scalar will be
  3164. * set to double quoted.
  3165. *
  3166. * A copy of the data will be made, so it is safe to free the data
  3167. * after the call.
  3168. *
  3169. * @fyd: The document which the resulting node will be associated with
  3170. * @data: Pointer to the data area
  3171. * @size: Size of the data area, or (size_t)-1 for '\0' terminated data.
  3172. *
  3173. * Returns:
  3174. * The created node, or NULL on error.
  3175. */
  3176. struct fy_node *
  3177. fy_node_create_scalar_copy(struct fy_document *fyd,
  3178. const char *data, size_t size)
  3179. FY_EXPORT;
  3180. /**
  3181. * fy_node_create_vscalarf() - vprintf interface for creating scalars
  3182. *
  3183. * Create a scalar node using a vprintf interface.
  3184. * The input is expected to be regular utf8 encoded. It may contain
  3185. * escaped characters in which case the style of the scalar will be
  3186. * set to double quoted.
  3187. *
  3188. * @fyd: The document which the resulting node will be associated with
  3189. * @fmt: The printf based format string
  3190. * @ap: The va_list containing the arguments
  3191. *
  3192. * Returns:
  3193. * The created node, or NULL on error.
  3194. */
  3195. struct fy_node *
  3196. fy_node_create_vscalarf(struct fy_document *fyd, const char *fmt, va_list ap)
  3197. FY_EXPORT;
  3198. /**
  3199. * fy_node_create_scalarf() - printf interface for creating scalars
  3200. *
  3201. * Create a scalar node using a printf interface.
  3202. * The input is expected to be regular utf8 encoded. It may contain
  3203. * escaped characters in which case the style of the scalar will be
  3204. * set to double quoted.
  3205. *
  3206. * @fyd: The document which the resulting node will be associated with
  3207. * @fmt: The printf based format string
  3208. * @...: The arguments
  3209. *
  3210. * Returns:
  3211. * The created node, or NULL on error.
  3212. */
  3213. struct fy_node *
  3214. fy_node_create_scalarf(struct fy_document *fyd, const char *fmt, ...)
  3215. FY_EXPORT
  3216. FY_ATTRIBUTE(format(printf, 2, 3));
  3217. /**
  3218. * fy_node_create_sequence() - Create an empty sequence node.
  3219. *
  3220. * Create an empty sequence node associated with the given document.
  3221. *
  3222. * @fyd: The document which the resulting node will be associated with
  3223. *
  3224. * Returns:
  3225. * The created node, or NULL on error.
  3226. */
  3227. struct fy_node *
  3228. fy_node_create_sequence(struct fy_document *fyd)
  3229. FY_EXPORT;
  3230. /**
  3231. * fy_node_create_mapping() - Create an empty mapping node.
  3232. *
  3233. * Create an empty mapping node associated with the given document.
  3234. *
  3235. * @fyd: The document which the resulting node will be associated with
  3236. *
  3237. * Returns:
  3238. * The created node, or NULL on error.
  3239. */
  3240. struct fy_node *
  3241. fy_node_create_mapping(struct fy_document *fyd)
  3242. FY_EXPORT;
  3243. /**
  3244. * fy_node_set_tag() - Set the tag of node
  3245. *
  3246. * Manually set the tag of a node. The tag must be a valid one for
  3247. * the document the node belongs to.
  3248. *
  3249. * Note that the data are not copied, merely a reference is taken, so
  3250. * it must be available while the node is in use.
  3251. *
  3252. * If the node already contains a tag it will be overwriten.
  3253. *
  3254. * @fyn: The node to set it's tag.
  3255. * @data: Pointer to the tag data.
  3256. * @len: Size of the tag data, or (size_t)-1 for '\0' terminated.
  3257. *
  3258. * Returns:
  3259. * 0 on success, -1 on error.
  3260. */
  3261. int
  3262. fy_node_set_tag(struct fy_node *fyn, const char *data, size_t len)
  3263. FY_EXPORT;
  3264. /**
  3265. * fy_node_remove_tag() - Remove the tag of node
  3266. *
  3267. * Remove the tag of a node.
  3268. *
  3269. * @fyn: The node to remove it's tag.
  3270. *
  3271. * Returns:
  3272. * 0 on success, -1 on error.
  3273. */
  3274. int
  3275. fy_node_remove_tag(struct fy_node *fyn)
  3276. FY_EXPORT;
  3277. /**
  3278. * fy_node_get_tag() - Get the tag of the node
  3279. *
  3280. * This method will return a pointer to the text of a tag
  3281. * along with the length of it. Note that this text is *not*
  3282. * NULL terminated.
  3283. *
  3284. * @fyn: The node
  3285. * @lenp: Pointer to a variable that will hold the returned length
  3286. *
  3287. * Returns:
  3288. * A pointer to the tag of the node, while @lenp will be assigned the
  3289. * length of said tag.
  3290. * A NULL will be returned in case of an error.
  3291. */
  3292. const char *
  3293. fy_node_get_tag(struct fy_node *fyn, size_t *lenp)
  3294. FY_EXPORT;
  3295. /**
  3296. * fy_node_get_scalar() - Get the scalar content of the node
  3297. *
  3298. * This method will return a pointer to the text of the scalar
  3299. * content of a node along with the length of it.
  3300. * Note that this pointer is *not* NULL terminated.
  3301. *
  3302. * @fyn: The scalar node
  3303. * @lenp: Pointer to a variable that will hold the returned length
  3304. *
  3305. * Returns:
  3306. * A pointer to the scalar content of the node, while @lenp will be assigned the
  3307. * length of said content.
  3308. * A NULL will be returned in case of an error, i.e. the node is not
  3309. * a scalar.
  3310. */
  3311. const char *
  3312. fy_node_get_scalar(struct fy_node *fyn, size_t *lenp)
  3313. FY_EXPORT;
  3314. /**
  3315. * fy_node_get_scalar0() - Get the scalar content of the node
  3316. *
  3317. * This method will return a pointer to the text of the scalar
  3318. * content of a node as a null terminated string.
  3319. * Note that this call will allocate memory to hold the null terminated
  3320. * string so if possible use fy_node_get_scalar()
  3321. *
  3322. * @fyn: The scalar node
  3323. *
  3324. * Returns:
  3325. * A pointer to the scalar content of the node or NULL in returned in case of an error.
  3326. */
  3327. const char *
  3328. fy_node_get_scalar0(struct fy_node *fyn)
  3329. FY_EXPORT;
  3330. /**
  3331. * fy_node_get_scalar_length() - Get the length of the scalar content
  3332. *
  3333. * This method will return the size of the scalar content of the node.
  3334. * If the node is not a scalar it will return 0.
  3335. *
  3336. * @fyn: The scalar node
  3337. *
  3338. * Returns:
  3339. * The size of the scalar content, or 0 if node is not scalar.
  3340. */
  3341. size_t
  3342. fy_node_get_scalar_length(struct fy_node *fyn)
  3343. FY_EXPORT;
  3344. /**
  3345. * fy_node_get_scalar_utf8_length() - Get the length of the scalar content
  3346. * in utf8 characters
  3347. *
  3348. * This method will return the size of the scalar content of the node in
  3349. * utf8 characters.
  3350. * If the node is not a scalar it will return 0.
  3351. *
  3352. * @fyn: The scalar node
  3353. *
  3354. * Returns:
  3355. * The size of the scalar content in utf8 characters, or 0 if node is not scalar.
  3356. */
  3357. size_t
  3358. fy_node_get_scalar_utf8_length(struct fy_node *fyn)
  3359. FY_EXPORT;
  3360. /**
  3361. * fy_node_sequence_iterate() - Iterate over a sequence node
  3362. *
  3363. * This method iterates over all the item nodes in the sequence node.
  3364. * The start of the iteration is signalled by a NULL in \*prevp.
  3365. *
  3366. * @fyn: The sequence node
  3367. * @prevp: The previous sequence iterator
  3368. *
  3369. * Returns:
  3370. * The next node in sequence or NULL at the end of the sequence.
  3371. */
  3372. struct fy_node *
  3373. fy_node_sequence_iterate(struct fy_node *fyn, void **prevp)
  3374. FY_EXPORT;
  3375. /**
  3376. * fy_node_sequence_reverse_iterate() - Iterate over a sequence node in reverse
  3377. *
  3378. * This method iterates in reverse over all the item nodes in the sequence node.
  3379. * The start of the iteration is signalled by a NULL in \*prevp.
  3380. *
  3381. * @fyn: The sequence node
  3382. * @prevp: The previous sequence iterator
  3383. *
  3384. * Returns:
  3385. * The next node in reverse sequence or NULL at the end of the sequence.
  3386. */
  3387. struct fy_node *
  3388. fy_node_sequence_reverse_iterate(struct fy_node *fyn, void **prevp)
  3389. FY_EXPORT;
  3390. /**
  3391. * fy_node_sequence_item_count() - Return the item count of the sequence
  3392. *
  3393. * Get the item count of the sequence.
  3394. *
  3395. * @fyn: The sequence node
  3396. *
  3397. * Returns:
  3398. * The count of items in the sequence or -1 in case of an error.
  3399. */
  3400. int
  3401. fy_node_sequence_item_count(struct fy_node *fyn)
  3402. FY_EXPORT;
  3403. /**
  3404. * fy_node_sequence_is_empty() - Check whether the sequence is empty
  3405. *
  3406. * Check whether the sequence contains items.
  3407. *
  3408. * @fyn: The sequence node
  3409. *
  3410. * Returns:
  3411. * true if the node is a sequence containing items, false otherwise
  3412. */
  3413. bool
  3414. fy_node_sequence_is_empty(struct fy_node *fyn)
  3415. FY_EXPORT;
  3416. /**
  3417. * fy_node_sequence_get_by_index() - Return a sequence item by index
  3418. *
  3419. * Retrieve a node in the sequence using it's index. If index
  3420. * is positive or zero the count is from the start of the sequence,
  3421. * while if negative from the end. I.e. -1 returns the last item
  3422. * in the sequence.
  3423. *
  3424. * @fyn: The sequence node
  3425. * @index: The index of the node to retrieve.
  3426. * - >= 0 counting from the start
  3427. * - < 0 counting from the end
  3428. *
  3429. * Returns:
  3430. * The node at the specified index or NULL if no such item exist.
  3431. */
  3432. struct fy_node *
  3433. fy_node_sequence_get_by_index(struct fy_node *fyn, int index)
  3434. FY_EXPORT;
  3435. /**
  3436. * fy_node_sequence_append() - Append a node item to a sequence
  3437. *
  3438. * Append a node item to a sequence.
  3439. *
  3440. * @fyn_seq: The sequence node
  3441. * @fyn: The node item to append
  3442. *
  3443. * Returns:
  3444. * 0 on success, -1 on error
  3445. */
  3446. int
  3447. fy_node_sequence_append(struct fy_node *fyn_seq, struct fy_node *fyn)
  3448. FY_EXPORT;
  3449. /**
  3450. * fy_node_sequence_prepend() - Append a node item to a sequence
  3451. *
  3452. * Prepend a node item to a sequence.
  3453. *
  3454. * @fyn_seq: The sequence node
  3455. * @fyn: The node item to prepend
  3456. *
  3457. * Returns:
  3458. * 0 on success, -1 on error
  3459. */
  3460. int fy_node_sequence_prepend(struct fy_node *fyn_seq, struct fy_node *fyn)
  3461. FY_EXPORT;
  3462. /**
  3463. * fy_node_sequence_insert_before() - Insert a node item before another
  3464. *
  3465. * Insert a node item before another in the sequence.
  3466. *
  3467. * @fyn_seq: The sequence node
  3468. * @fyn_mark: The node item which the node will be inserted before.
  3469. * @fyn: The node item to insert in the sequence.
  3470. *
  3471. * Returns:
  3472. * 0 on success, -1 on error
  3473. */
  3474. int
  3475. fy_node_sequence_insert_before(struct fy_node *fyn_seq,
  3476. struct fy_node *fyn_mark, struct fy_node *fyn)
  3477. FY_EXPORT;
  3478. /**
  3479. * fy_node_sequence_insert_after() - Insert a node item after another
  3480. *
  3481. * Insert a node item after another in the sequence.
  3482. *
  3483. * @fyn_seq: The sequence node
  3484. * @fyn_mark: The node item which the node will be inserted after.
  3485. * @fyn: The node item to insert in the sequence.
  3486. *
  3487. * Returns:
  3488. * 0 on success, -1 on error
  3489. */
  3490. int
  3491. fy_node_sequence_insert_after(struct fy_node *fyn_seq,
  3492. struct fy_node *fyn_mark, struct fy_node *fyn)
  3493. FY_EXPORT;
  3494. /**
  3495. * fy_node_sequence_remove() - Remove an item from a sequence
  3496. *
  3497. * Remove a node item from a sequence and return it.
  3498. *
  3499. * @fyn_seq: The sequence node
  3500. * @fyn: The node item to remove from the sequence.
  3501. *
  3502. * Returns:
  3503. * The removed node item fyn, or NULL in case of an error.
  3504. */
  3505. struct fy_node *
  3506. fy_node_sequence_remove(struct fy_node *fyn_seq, struct fy_node *fyn)
  3507. FY_EXPORT;
  3508. /**
  3509. * fy_node_mapping_iterate() - Iterate over a mapping node
  3510. *
  3511. * This method iterates over all the node pairs in the mapping node.
  3512. * The start of the iteration is signalled by a NULL in \*prevp.
  3513. *
  3514. * Note that while a mapping is an unordered collection of key/values
  3515. * the order of which they are created is important for presentation
  3516. * purposes.
  3517. *
  3518. * @fyn: The mapping node
  3519. * @prevp: The previous sequence iterator
  3520. *
  3521. * Returns:
  3522. * The next node pair in the mapping or NULL at the end of the mapping.
  3523. */
  3524. struct fy_node_pair *
  3525. fy_node_mapping_iterate(struct fy_node *fyn, void **prevp)
  3526. FY_EXPORT;
  3527. /**
  3528. * fy_node_mapping_reverse_iterate() - Iterate over a mapping node in reverse
  3529. *
  3530. * This method iterates in reverse over all the node pairs in the mapping node.
  3531. * The start of the iteration is signalled by a NULL in \*prevp.
  3532. *
  3533. * Note that while a mapping is an unordered collection of key/values
  3534. * the order of which they are created is important for presentation
  3535. * purposes.
  3536. *
  3537. * @fyn: The mapping node
  3538. * @prevp: The previous sequence iterator
  3539. *
  3540. * Returns:
  3541. * The next node pair in reverse sequence in the mapping or NULL at the end of the mapping.
  3542. */
  3543. struct fy_node_pair *
  3544. fy_node_mapping_reverse_iterate(struct fy_node *fyn, void **prevp)
  3545. FY_EXPORT;
  3546. /**
  3547. * fy_node_mapping_item_count() - Return the node pair count of the mapping
  3548. *
  3549. * Get the count of the node pairs in the mapping.
  3550. *
  3551. * @fyn: The mapping node
  3552. *
  3553. * Returns:
  3554. * The count of node pairs in the mapping or -1 in case of an error.
  3555. */
  3556. int
  3557. fy_node_mapping_item_count(struct fy_node *fyn)
  3558. FY_EXPORT;
  3559. /**
  3560. * fy_node_mapping_is_empty() - Check whether the mapping is empty
  3561. *
  3562. * Check whether the mapping contains any node pairs.
  3563. *
  3564. * @fyn: The mapping node
  3565. *
  3566. * Returns:
  3567. * true if the node is a mapping containing node pairs, false otherwise
  3568. */
  3569. bool
  3570. fy_node_mapping_is_empty(struct fy_node *fyn)
  3571. FY_EXPORT;
  3572. /**
  3573. * fy_node_mapping_get_by_index() - Return a node pair by index
  3574. *
  3575. * Retrieve a node pair in the mapping using its index. If index
  3576. * is positive or zero the count is from the start of the sequence,
  3577. * while if negative from the end. I.e. -1 returns the last node pair
  3578. * in the mapping.
  3579. *
  3580. * @fyn: The mapping node
  3581. * @index: The index of the node pair to retrieve.
  3582. * - >= 0 counting from the start
  3583. * - < 0 counting from the end
  3584. *
  3585. * Returns:
  3586. * The node pair at the specified index or NULL if no such item exist.
  3587. */
  3588. struct fy_node_pair *
  3589. fy_node_mapping_get_by_index(struct fy_node *fyn, int index)
  3590. FY_EXPORT;
  3591. /**
  3592. * fy_node_mapping_lookup_pair_by_string() - Lookup a node pair in mapping by string
  3593. *
  3594. * This method will return the node pair that contains the same key
  3595. * from the YAML node created from the @key argument. The comparison of the
  3596. * node is using fy_node_compare()
  3597. *
  3598. * @fyn: The mapping node
  3599. * @key: The YAML source to use as key
  3600. * @len: The length of the key (or -1 if '\0' terminated)
  3601. *
  3602. * Returns:
  3603. * The value matching the given key, or NULL if not found.
  3604. */
  3605. struct fy_node_pair *
  3606. fy_node_mapping_lookup_pair_by_string(struct fy_node *fyn,
  3607. const char *key, size_t len)
  3608. FY_EXPORT;
  3609. /**
  3610. * fy_node_mapping_lookup_by_string() - Lookup a node value in mapping by string
  3611. *
  3612. * This method will return the value of node pair that contains the same key
  3613. * from the YAML node created from the @key argument. The comparison of the
  3614. * node is using fy_node_compare()
  3615. *
  3616. * @fyn: The mapping node
  3617. * @key: The YAML source to use as key
  3618. * @len: The length of the key (or -1 if '\0' terminated)
  3619. *
  3620. * Returns:
  3621. * The value matching the given key, or NULL if not found.
  3622. */
  3623. struct fy_node *
  3624. fy_node_mapping_lookup_by_string(struct fy_node *fyn,
  3625. const char *key, size_t len)
  3626. FY_EXPORT;
  3627. /**
  3628. * fy_node_mapping_lookup_value_by_string() - Lookup a node value in mapping by string
  3629. *
  3630. * This method will return the value of node pair that contains the same key
  3631. * from the YAML node created from the @key argument. The comparison of the
  3632. * node is using fy_node_compare()
  3633. *
  3634. * It is synonymous with fy_node_mapping_lookup_by_string().
  3635. *
  3636. * @fyn: The mapping node
  3637. * @key: The YAML source to use as key
  3638. * @len: The length of the key (or -1 if '\0' terminated)
  3639. *
  3640. * Returns:
  3641. * The value matching the given key, or NULL if not found.
  3642. */
  3643. struct fy_node *
  3644. fy_node_mapping_lookup_value_by_string(struct fy_node *fyn,
  3645. const char *key, size_t len)
  3646. FY_EXPORT;
  3647. /**
  3648. * fy_node_mapping_lookup_key_by_string() - Lookup a node key in mapping by string
  3649. *
  3650. * This method will return the key of node pair that contains the same key
  3651. * from the YAML node created from the @key argument. The comparison of the
  3652. * node is using fy_node_compare()
  3653. *
  3654. * @fyn: The mapping node
  3655. * @key: The YAML source to use as key
  3656. * @len: The length of the key (or -1 if '\0' terminated)
  3657. *
  3658. * Returns:
  3659. * The key matching the given key, or NULL if not found.
  3660. */
  3661. struct fy_node *
  3662. fy_node_mapping_lookup_key_by_string(struct fy_node *fyn,
  3663. const char *key, size_t len)
  3664. FY_EXPORT;
  3665. /**
  3666. * fy_node_mapping_lookup_pair_by_simple_key() - Lookup a node pair in mapping by simple string
  3667. *
  3668. * This method will return the node pair that contains the same key
  3669. * from the YAML node created from the @key argument. The comparison of the
  3670. * node is using by comparing the strings for identity.
  3671. *
  3672. * @fyn: The mapping node
  3673. * @key: The string to use as key
  3674. * @len: The length of the key (or -1 if '\0' terminated)
  3675. *
  3676. * Returns:
  3677. * The node pair matching the given key, or NULL if not found.
  3678. */
  3679. struct fy_node_pair *
  3680. fy_node_mapping_lookup_pair_by_simple_key(struct fy_node *fyn,
  3681. const char *key, size_t len)
  3682. FY_EXPORT;
  3683. /**
  3684. * fy_node_mapping_lookup_value_by_simple_key() - Lookup a node value in mapping by simple string
  3685. *
  3686. * This method will return the value of node pair that contains the same key
  3687. * from the YAML node created from the @key argument. The comparison of the
  3688. * node is using by comparing the strings for identity.
  3689. *
  3690. * @fyn: The mapping node
  3691. * @key: The string to use as key
  3692. * @len: The length of the key (or -1 if '\0' terminated)
  3693. *
  3694. * Returns:
  3695. * The value matching the given key, or NULL if not found.
  3696. */
  3697. struct fy_node *
  3698. fy_node_mapping_lookup_value_by_simple_key(struct fy_node *fyn,
  3699. const char *key, size_t len)
  3700. FY_EXPORT;
  3701. /**
  3702. * fy_node_mapping_lookup_pair_by_null_key() - Lookup a node pair in mapping that has a NULL key
  3703. *
  3704. * This method will return the node pair that has a NULL key.
  3705. * Note this method is not using the mapping accelerator
  3706. * and arguably NULL keys should not exist. Alas...
  3707. *
  3708. * @fyn: The mapping node
  3709. *
  3710. * Returns:
  3711. * The node pair with a NULL key, NULL otherwise
  3712. */
  3713. struct fy_node_pair *
  3714. fy_node_mapping_lookup_pair_by_null_key(struct fy_node *fyn)
  3715. FY_EXPORT;
  3716. /**
  3717. * fy_node_mapping_lookup_value_by_null_key() - Lookup a node value with a NULL key.
  3718. *
  3719. * Return the value of a node pair that has a NULL key.
  3720. *
  3721. * @fyn: The mapping node
  3722. *
  3723. * Returns:
  3724. * The value matching the null key, NULL otherwise.
  3725. * Note that the value may be NULL too, but for that pathological case
  3726. * use the node pair method instead.
  3727. */
  3728. struct fy_node *
  3729. fy_node_mapping_lookup_value_by_null_key(struct fy_node *fyn)
  3730. FY_EXPORT;
  3731. /**
  3732. * fy_node_mapping_lookup_scalar_by_simple_key() - Lookup a scalar in mapping by simple string
  3733. *
  3734. * This method will return the scalar contents that contains the same key
  3735. * from the YAML node created from the @key argument. The comparison of the
  3736. * node is using by comparing the strings for identity.
  3737. *
  3738. * @fyn: The mapping node
  3739. * @lenp: Pointer to a variable that will hold the returned length
  3740. * @key: The string to use as key
  3741. * @keylen: The length of the key (or -1 if '\0' terminated)
  3742. *
  3743. * Returns:
  3744. * The scalar contents matching the given key, or NULL if not found.
  3745. */
  3746. const char *
  3747. fy_node_mapping_lookup_scalar_by_simple_key(struct fy_node *fyn, size_t *lenp,
  3748. const char *key, size_t keylen)
  3749. FY_EXPORT;
  3750. /**
  3751. * fy_node_mapping_lookup_scalar0_by_simple_key() - Lookup a scalar in mapping by simple string
  3752. * returning a '\0' terminated scalar
  3753. *
  3754. * This method will return the NUL terminated scalar contents that contains the same key
  3755. * from the YAML node created from the @key argument. The comparison of the
  3756. * node is using by comparing the strings for identity.
  3757. *
  3758. * @fyn: The mapping node
  3759. * @key: The string to use as key
  3760. * @keylen: The length of the key (or -1 if '\0' terminated)
  3761. *
  3762. * Returns:
  3763. * The NUL terminated scalar contents matching the given key, or NULL if not found.
  3764. */
  3765. const char *
  3766. fy_node_mapping_lookup_scalar0_by_simple_key(struct fy_node *fyn,
  3767. const char *key, size_t keylen)
  3768. FY_EXPORT;
  3769. /**
  3770. * fy_node_mapping_lookup_pair() - Lookup a node pair matching the provided key
  3771. *
  3772. * This method will return the node pair that matches the provided @fyn_key
  3773. *
  3774. * @fyn: The mapping node
  3775. * @fyn_key: The node to use as key
  3776. *
  3777. * Returns:
  3778. * The node pair matching the given key, or NULL if not found.
  3779. */
  3780. struct fy_node_pair *
  3781. fy_node_mapping_lookup_pair(struct fy_node *fyn, struct fy_node *fyn_key)
  3782. FY_EXPORT;
  3783. /**
  3784. * fy_node_mapping_lookup_value_by_key() - Lookup a node pair's value matching the provided key
  3785. *
  3786. * This method will return the node pair that matches the provided @fyn_key
  3787. * The key may be collection and a content match check is performed recursively
  3788. * in order to find the right key.
  3789. *
  3790. * @fyn: The mapping node
  3791. * @fyn_key: The node to use as key
  3792. *
  3793. * Returns:
  3794. * The node value matching the given key, or NULL if not found.
  3795. */
  3796. struct fy_node *
  3797. fy_node_mapping_lookup_value_by_key(struct fy_node *fyn, struct fy_node *fyn_key);
  3798. /**
  3799. * fy_node_mapping_lookup_key_by_key() - Lookup a node pair's key matching the provided key
  3800. *
  3801. * This method will return the node pair that matches the provided @fyn_key
  3802. * The key may be collection and a content match check is performed recursively
  3803. * in order to find the right key.
  3804. *
  3805. * @fyn: The mapping node
  3806. * @fyn_key: The node to use as key
  3807. *
  3808. * Returns:
  3809. * The node key matching the given key, or NULL if not found.
  3810. */
  3811. struct fy_node *
  3812. fy_node_mapping_lookup_key_by_key(struct fy_node *fyn, struct fy_node *fyn_key);
  3813. /**
  3814. * fy_node_mapping_get_pair_index() - Return the node pair index in the mapping
  3815. *
  3816. * This method will return the node pair index in the mapping of the given
  3817. * node pair argument.
  3818. *
  3819. * @fyn: The mapping node
  3820. * @fynp: The node pair
  3821. *
  3822. * Returns:
  3823. * The index of the node pair in the mapping or -1 in case of an error.
  3824. */
  3825. int
  3826. fy_node_mapping_get_pair_index(struct fy_node *fyn,
  3827. const struct fy_node_pair *fynp)
  3828. FY_EXPORT;
  3829. /**
  3830. * fy_node_pair_key() - Return the key of a node pair
  3831. *
  3832. * This method will return the node pair's key.
  3833. * Note that this may be NULL, which is returned also in case
  3834. * the node pair argument is NULL, so you should protect against
  3835. * such a case.
  3836. *
  3837. * @fynp: The node pair
  3838. *
  3839. * Returns:
  3840. * The node pair key
  3841. */
  3842. struct fy_node *
  3843. fy_node_pair_key(struct fy_node_pair *fynp)
  3844. FY_EXPORT;
  3845. /**
  3846. * fy_node_pair_value() - Return the value of a node pair
  3847. *
  3848. * This method will return the node pair's value.
  3849. * Note that this may be NULL, which is returned also in case
  3850. * the node pair argument is NULL, so you should protect against
  3851. * such a case.
  3852. *
  3853. * @fynp: The node pair
  3854. *
  3855. * Returns:
  3856. * The node pair value
  3857. */
  3858. struct fy_node *
  3859. fy_node_pair_value(struct fy_node_pair *fynp)
  3860. FY_EXPORT;
  3861. /**
  3862. * fy_node_pair_set_key() - Sets the key of a node pair
  3863. *
  3864. * This method will set the key part of the node pair.
  3865. * It will ovewrite any previous key.
  3866. *
  3867. * Note that no checks for duplicate keys are going to be
  3868. * performed.
  3869. *
  3870. * @fynp: The node pair
  3871. * @fyn: The key node
  3872. *
  3873. * Returns:
  3874. * 0 on success, -1 on error
  3875. */
  3876. int
  3877. fy_node_pair_set_key(struct fy_node_pair *fynp, struct fy_node *fyn)
  3878. FY_EXPORT;
  3879. /**
  3880. * fy_node_pair_set_value() - Sets the value of a node pair
  3881. *
  3882. * This method will set the value part of the node pair.
  3883. * It will ovewrite any previous value.
  3884. *
  3885. * @fynp: The node pair
  3886. * @fyn: The value node
  3887. *
  3888. * Returns:
  3889. * 0 on success, -1 on error
  3890. */
  3891. int
  3892. fy_node_pair_set_value(struct fy_node_pair *fynp, struct fy_node *fyn)
  3893. FY_EXPORT;
  3894. /**
  3895. * fy_node_mapping_append() - Append a node item to a mapping
  3896. *
  3897. * Append a node pair to a mapping.
  3898. *
  3899. * @fyn_map: The mapping node
  3900. * @fyn_key: The node pair's key
  3901. * @fyn_value: The node pair's value
  3902. *
  3903. * Returns:
  3904. * 0 on success, -1 on error
  3905. */
  3906. int
  3907. fy_node_mapping_append(struct fy_node *fyn_map,
  3908. struct fy_node *fyn_key, struct fy_node *fyn_value)
  3909. FY_EXPORT;
  3910. /**
  3911. * fy_node_mapping_prepend() - Prepend a node item to a mapping
  3912. *
  3913. * Prepend a node pair to a mapping.
  3914. *
  3915. * @fyn_map: The mapping node
  3916. * @fyn_key: The node pair's key
  3917. * @fyn_value: The node pair's value
  3918. *
  3919. * Returns:
  3920. * 0 on success, -1 on error
  3921. */
  3922. int
  3923. fy_node_mapping_prepend(struct fy_node *fyn_map,
  3924. struct fy_node *fyn_key, struct fy_node *fyn_value)
  3925. FY_EXPORT;
  3926. /**
  3927. * fy_node_mapping_remove() - Remove a node pair from a mapping
  3928. *
  3929. * Remove node pair from a mapping.
  3930. *
  3931. * @fyn_map: The mapping node
  3932. * @fynp: The node pair to remove
  3933. *
  3934. * Returns:
  3935. * 0 on success, -1 on failure.
  3936. */
  3937. int
  3938. fy_node_mapping_remove(struct fy_node *fyn_map, struct fy_node_pair *fynp)
  3939. FY_EXPORT;
  3940. /**
  3941. * fy_node_mapping_remove_by_key() - Remove a node pair from a mapping returning the value
  3942. *
  3943. * Remove node pair from a mapping using the supplied key.
  3944. *
  3945. * @fyn_map: The mapping node
  3946. * @fyn_key: The node pair's key
  3947. *
  3948. * Returns:
  3949. * The value part of removed node pair, or NULL in case of an error.
  3950. */
  3951. struct fy_node *
  3952. fy_node_mapping_remove_by_key(struct fy_node *fyn_map, struct fy_node *fyn_key)
  3953. FY_EXPORT;
  3954. /**
  3955. * fy_node_sort() - Recursively sort node
  3956. *
  3957. * Recursively sort all mappings of the given node, using the given
  3958. * comparison method (if NULL use the default one).
  3959. *
  3960. * @fyn: The node to sort
  3961. * @key_cmp: The comparison method
  3962. * @arg: An opaque user pointer for the comparison method
  3963. *
  3964. * Returns:
  3965. * 0 on success, -1 on error
  3966. */
  3967. int
  3968. fy_node_sort(struct fy_node *fyn, fy_node_mapping_sort_fn key_cmp, void *arg)
  3969. FY_EXPORT;
  3970. /**
  3971. * fy_node_vscanf() - Retrieve data via vscanf
  3972. *
  3973. * This method easily retrieves data using a familiar vscanf interface.
  3974. * The format string is a regular scanf format string with the following format.
  3975. *
  3976. * "pathspec %opt pathspec %opt..."
  3977. *
  3978. * Each pathspec is separated with space from the scanf option
  3979. *
  3980. * For example:
  3981. * fyn = { foo: 3 } -> fy_node_scanf(fyn, "/foo %d", &var) -> var = 3
  3982. *
  3983. *
  3984. * @fyn: The node to use as a pathspec root
  3985. * @fmt: The scanf based format string
  3986. * @ap: The va_list containing the arguments
  3987. *
  3988. * Returns:
  3989. * The number of scanned arguments, or -1 on error.
  3990. */
  3991. int fy_node_vscanf(struct fy_node *fyn, const char *fmt, va_list ap);
  3992. /**
  3993. * fy_node_scanf() - Retrieve data via scanf
  3994. *
  3995. * This method easily retrieves data using a familiar vscanf interface.
  3996. * The format string is a regular scanf format string with the following format.
  3997. *
  3998. * "pathspec %opt pathspec %opt..."
  3999. *
  4000. * Each pathspec is separated with space from the scanf option
  4001. *
  4002. * For example:
  4003. * fyn = { foo: 3 } -> fy_node_scanf(fyn, "/foo %d", &var) -> var = 3
  4004. *
  4005. *
  4006. * @fyn: The node to use as a pathspec root
  4007. * @fmt: The scanf based format string
  4008. * @...: The arguments
  4009. *
  4010. * Returns:
  4011. * The number of scanned arguments, or -1 on error.
  4012. */
  4013. int
  4014. fy_node_scanf(struct fy_node *fyn, const char *fmt, ...)
  4015. FY_ATTRIBUTE(format(scanf, 2, 3))
  4016. FY_EXPORT;
  4017. /**
  4018. * fy_document_vscanf() - Retrieve data via vscanf relative to document root
  4019. *
  4020. * This method easily retrieves data using a familiar vscanf interface.
  4021. * The format string is a regular scanf format string with the following format.
  4022. *
  4023. * "pathspec %opt pathspec %opt..."
  4024. *
  4025. * Each pathspec is separated with space from the scanf option
  4026. *
  4027. * For example:
  4028. * fyd = { foo: 3 } -> fy_document_scanf(fyd, "/foo %d", &var) -> var = 3
  4029. *
  4030. *
  4031. * @fyd: The document
  4032. * @fmt: The scanf based format string
  4033. * @ap: The va_list containing the arguments
  4034. *
  4035. * Returns:
  4036. * The number of scanned arguments, or -1 on error.
  4037. */
  4038. int
  4039. fy_document_vscanf(struct fy_document *fyd, const char *fmt, va_list ap)
  4040. FY_EXPORT;
  4041. /**
  4042. * fy_document_scanf() - Retrieve data via scanf relative to document root
  4043. *
  4044. * This method easily retrieves data using a familiar vscanf interface.
  4045. * The format string is a regular scanf format string with the following format.
  4046. *
  4047. * "pathspec %opt pathspec %opt..."
  4048. *
  4049. * Each pathspec is separated with space from the scanf option
  4050. *
  4051. * For example:
  4052. * fyn = { foo: 3 } -> fy_node_scanf(fyd, "/foo %d", &var) -> var = 3
  4053. *
  4054. *
  4055. * @fyd: The document
  4056. * @fmt: The scanf based format string
  4057. * @...: The arguments
  4058. *
  4059. * Returns:
  4060. * The number of scanned arguments, or -1 on error.
  4061. */
  4062. int
  4063. fy_document_scanf(struct fy_document *fyd, const char *fmt, ...)
  4064. FY_ATTRIBUTE(format(scanf, 2, 3))
  4065. FY_EXPORT;
  4066. /**
  4067. * fy_document_tag_directive_iterate() - Iterate over a document's tag directives
  4068. *
  4069. * This method iterates over all the documents tag directives.
  4070. * The start of the iteration is signalled by a NULL in \*prevp.
  4071. *
  4072. * @fyd: The document
  4073. * @prevp: The previous state of the iterator
  4074. *
  4075. * Returns:
  4076. * The next tag directive token in the document or NULL at the end of them.
  4077. */
  4078. struct fy_token *
  4079. fy_document_tag_directive_iterate(struct fy_document *fyd, void **prevp)
  4080. FY_EXPORT;
  4081. /**
  4082. * fy_document_tag_directive_lookup() - Retreive a document's tag directive
  4083. *
  4084. * Retreives the matching tag directive token of the document matching the handle.
  4085. *
  4086. * @fyd: The document
  4087. * @handle: The handle to look for
  4088. *
  4089. * Returns:
  4090. * The tag directive token with the given handle or NULL if not found
  4091. */
  4092. struct fy_token *
  4093. fy_document_tag_directive_lookup(struct fy_document *fyd, const char *handle)
  4094. FY_EXPORT;
  4095. /**
  4096. * fy_tag_directive_token_handle() - Get a tag directive handle
  4097. *
  4098. * Retreives the tag directives token handle value. Only valid on
  4099. * tag directive tokens.
  4100. *
  4101. * @fyt: The tag directive token
  4102. * @lenp: Pointer to a variable that will hold the returned length
  4103. *
  4104. * Returns:
  4105. * A pointer to the tag directive's handle, while @lenp will be assigned the
  4106. * length of said handle.
  4107. * A NULL will be returned in case of an error.
  4108. */
  4109. const char *
  4110. fy_tag_directive_token_handle(struct fy_token *fyt, size_t *lenp)
  4111. FY_EXPORT;
  4112. /**
  4113. * fy_tag_directive_token_prefix() - Get a tag directive prefix
  4114. *
  4115. * Retreives the tag directives token prefix value. Only valid on
  4116. * tag directive tokens.
  4117. *
  4118. * @fyt: The tag directive token
  4119. * @lenp: Pointer to a variable that will hold the returned length
  4120. *
  4121. * Returns:
  4122. * A pointer to the tag directive's prefix, while @lenp will be assigned the
  4123. * length of said prefix.
  4124. * A NULL will be returned in case of an error.
  4125. */
  4126. const char *
  4127. fy_tag_directive_token_prefix(struct fy_token *fyt, size_t *lenp)
  4128. FY_EXPORT;
  4129. /**
  4130. * fy_document_tag_directive_add() - Add a tag directive to a document
  4131. *
  4132. * Add tag directive to the document.
  4133. *
  4134. * @fyd: The document
  4135. * @handle: The handle of the tag directive
  4136. * @prefix: The prefix of the tag directive
  4137. *
  4138. * Returns:
  4139. * 0 on success, -1 on error
  4140. */
  4141. int
  4142. fy_document_tag_directive_add(struct fy_document *fyd,
  4143. const char *handle, const char *prefix)
  4144. FY_EXPORT;
  4145. /**
  4146. * fy_document_tag_directive_remove() - Remove a tag directive
  4147. *
  4148. * Remove a tag directive from a document.
  4149. * Note that removal is prohibited if any node is still using this tag directive.
  4150. *
  4151. * @fyd: The document
  4152. * @handle: The handle of the tag directive to remove.
  4153. *
  4154. * Returns:
  4155. * 0 on success, -1 on error
  4156. */
  4157. int
  4158. fy_document_tag_directive_remove(struct fy_document *fyd, const char *handle)
  4159. FY_EXPORT;
  4160. /**
  4161. * fy_document_lookup_anchor() - Lookup an anchor
  4162. *
  4163. * Lookup for an anchor having the name provided
  4164. *
  4165. * @fyd: The document
  4166. * @anchor: The anchor to look for
  4167. * @len: The length of the anchor (or -1 if '\0' terminated)
  4168. *
  4169. * Returns:
  4170. * The anchor if found, NULL otherwise
  4171. */
  4172. struct fy_anchor *
  4173. fy_document_lookup_anchor(struct fy_document *fyd,
  4174. const char *anchor, size_t len)
  4175. FY_EXPORT;
  4176. /**
  4177. * fy_document_lookup_anchor_by_token() - Lookup an anchor by token text
  4178. *
  4179. * Lookup for an anchor having the name provided from the text of the token
  4180. *
  4181. * @fyd: The document
  4182. * @anchor: The token contains the anchor text to look for
  4183. *
  4184. * Returns:
  4185. * The anchor if found, NULL otherwise
  4186. */
  4187. struct fy_anchor *
  4188. fy_document_lookup_anchor_by_token(struct fy_document *fyd,
  4189. struct fy_token *anchor)
  4190. FY_EXPORT;
  4191. /**
  4192. * fy_document_lookup_anchor_by_node() - Lookup an anchor by node
  4193. *
  4194. * Lookup for an anchor located in the given node
  4195. *
  4196. * @fyd: The document
  4197. * @fyn: The node
  4198. *
  4199. * Returns:
  4200. * The anchor if found, NULL otherwise
  4201. */
  4202. struct fy_anchor *
  4203. fy_document_lookup_anchor_by_node(struct fy_document *fyd,
  4204. struct fy_node *fyn)
  4205. FY_EXPORT;
  4206. /**
  4207. * fy_anchor_get_text() - Get the text of an anchor
  4208. *
  4209. * This method will return a pointer to the text of an anchor
  4210. * along with the length of it. Note that this text is *not*
  4211. * NULL terminated.
  4212. *
  4213. * @fya: The anchor
  4214. * @lenp: Pointer to a variable that will hold the returned length
  4215. *
  4216. * Returns:
  4217. * A pointer to the text of the anchor, while @lenp will be assigned the
  4218. * length of said anchor.
  4219. * A NULL will be returned in case of an error.
  4220. */
  4221. const char *
  4222. fy_anchor_get_text(struct fy_anchor *fya, size_t *lenp)
  4223. FY_EXPORT;
  4224. /**
  4225. * fy_anchor_node() - Get the node of an anchor
  4226. *
  4227. * This method returns the node associated with the anchor.
  4228. *
  4229. * @fya: The anchor
  4230. *
  4231. * Returns:
  4232. * The node of the anchor, or NULL in case of an error.
  4233. */
  4234. struct fy_node *
  4235. fy_anchor_node(struct fy_anchor *fya)
  4236. FY_EXPORT;
  4237. /**
  4238. * fy_document_anchor_iterate() - Iterate over a document's anchors
  4239. *
  4240. * This method iterates over all the documents anchors.
  4241. * The start of the iteration is signalled by a NULL in \*prevp.
  4242. *
  4243. * @fyd: The document
  4244. * @prevp: The previous state of the iterator
  4245. *
  4246. * Returns:
  4247. * The next anchor in the document or NULL at the end of them.
  4248. */
  4249. struct fy_anchor *
  4250. fy_document_anchor_iterate(struct fy_document *fyd, void **prevp)
  4251. FY_EXPORT;
  4252. /**
  4253. * fy_document_set_anchor() - Place an anchor
  4254. *
  4255. * Places an anchor to the node with the give text name.
  4256. *
  4257. * Note that the data are not copied, merely a reference is taken, so
  4258. * it must be available while the node is in use.
  4259. *
  4260. * Also not that this method is deprecated; use fy_node_set_anchor()
  4261. * instead.
  4262. *
  4263. * @fyd: The document
  4264. * @fyn: The node to set the anchor to
  4265. * @text: Pointer to the anchor text
  4266. * @len: Size of the anchor text, or (size_t)-1 for '\0' terminated.
  4267. *
  4268. * Returns:
  4269. * 0 on success, -1 on error.
  4270. */
  4271. int
  4272. fy_document_set_anchor(struct fy_document *fyd, struct fy_node *fyn,
  4273. const char *text, size_t len)
  4274. FY_EXPORT FY_DEPRECATED;
  4275. /**
  4276. * fy_node_set_anchor() - Place an anchor to the node
  4277. *
  4278. * Places an anchor to the node with the give text name.
  4279. *
  4280. * Note that the data are not copied, merely a reference is taken, so
  4281. * it must be available while the node is in use.
  4282. *
  4283. * This is similar to fy_document_set_anchor() with the document set
  4284. * to the document of the @fyn node.
  4285. *
  4286. * @fyn: The node to set the anchor to
  4287. * @text: Pointer to the anchor text
  4288. * @len: Size of the anchor text, or (size_t)-1 for '\0' terminated.
  4289. *
  4290. * Returns:
  4291. * 0 on success, -1 on error.
  4292. */
  4293. int
  4294. fy_node_set_anchor(struct fy_node *fyn, const char *text, size_t len)
  4295. FY_EXPORT;
  4296. /**
  4297. * fy_node_set_anchor_copy() - Place an anchor to the node copying the text
  4298. *
  4299. * Places an anchor to the node with the give text name, which
  4300. * will be copied, so it's safe to dispose the text after the call.
  4301. *
  4302. * @fyn: The node to set the anchor to
  4303. * @text: Pointer to the anchor text
  4304. * @len: Size of the anchor text, or (size_t)-1 for '\0' terminated.
  4305. *
  4306. * Returns:
  4307. * 0 on success, -1 on error.
  4308. */
  4309. int
  4310. fy_node_set_anchor_copy(struct fy_node *fyn, const char *text, size_t len)
  4311. FY_EXPORT;
  4312. /**
  4313. * fy_node_set_vanchorf() - Place an anchor to the node using a vprintf interface.
  4314. *
  4315. * Places an anchor to the node with the give text name as created
  4316. * via vprintf'ing the arguments.
  4317. *
  4318. * @fyn: The node to set the anchor to
  4319. * @fmt: Pointer to the anchor format string
  4320. * @ap: The argument list.
  4321. *
  4322. * Returns:
  4323. * 0 on success, -1 on error.
  4324. */
  4325. int
  4326. fy_node_set_vanchorf(struct fy_node *fyn, const char *fmt, va_list ap)
  4327. FY_EXPORT;
  4328. /**
  4329. * fy_node_set_anchorf() - Place an anchor to the node using a printf interface.
  4330. *
  4331. * Places an anchor to the node with the give text name as created
  4332. * via printf'ing the arguments.
  4333. *
  4334. * @fyn: The node to set the anchor to
  4335. * @fmt: Pointer to the anchor format string
  4336. * @...: The extra arguments.
  4337. *
  4338. * Returns:
  4339. * 0 on success, -1 on error.
  4340. */
  4341. int
  4342. fy_node_set_anchorf(struct fy_node *fyn, const char *fmt, ...)
  4343. FY_EXPORT FY_ATTRIBUTE(format(printf, 2, 3));
  4344. /**
  4345. * fy_node_remove_anchor() - Remove an anchor
  4346. *
  4347. * Remove an anchor for the given node (if it exists)
  4348. *
  4349. * @fyn: The node to remove anchors from
  4350. *
  4351. * Returns:
  4352. * 0 on success, -1 on error.
  4353. */
  4354. int
  4355. fy_node_remove_anchor(struct fy_node *fyn)
  4356. FY_EXPORT;
  4357. /**
  4358. * fy_node_get_anchor() - Get the anchor of a node
  4359. *
  4360. * Retrieve the anchor of the given node (if it exists)
  4361. *
  4362. * @fyn: The node
  4363. *
  4364. * Returns:
  4365. * The anchor if there's one at the node, or NULL otherwise
  4366. */
  4367. struct fy_anchor *
  4368. fy_node_get_anchor(struct fy_node *fyn)
  4369. FY_EXPORT;
  4370. /**
  4371. * fy_node_get_nearest_anchor() - Get the nearest anchor of the node
  4372. *
  4373. * Retrieve the anchor of the nearest parent of the given node or
  4374. * the given node if it has one.
  4375. *
  4376. * @fyn: The node
  4377. *
  4378. * Returns:
  4379. * The nearest anchor if there's one, or NULL otherwise
  4380. */
  4381. struct fy_anchor *
  4382. fy_node_get_nearest_anchor(struct fy_node *fyn)
  4383. FY_EXPORT;
  4384. /**
  4385. * fy_node_get_nearest_child_of() - Get the nearest node which is a
  4386. * child of the base
  4387. *
  4388. * Retrieve the nearest node which is a child of fyn_base starting
  4389. * at fyn and working upwards.
  4390. *
  4391. * @fyn_base: The base node
  4392. * @fyn: The node to start from
  4393. *
  4394. * Returns:
  4395. * The nearest child of the base if there's one, or NULL otherwise
  4396. */
  4397. struct fy_node *
  4398. fy_node_get_nearest_child_of(struct fy_node *fyn_base, struct fy_node *fyn)
  4399. FY_EXPORT;
  4400. /**
  4401. * fy_node_create_alias() - Create an alias node
  4402. *
  4403. * Create an alias on the given document
  4404. *
  4405. * Note that the data are not copied, merely a reference is taken, so
  4406. * it must be available while the node is in use.
  4407. *
  4408. * @fyd: The document
  4409. * @alias: The alias text
  4410. * @len: The length of the alias (or -1 if '\0' terminated)
  4411. *
  4412. * Returns:
  4413. * The created alias node, or NULL in case of an error
  4414. */
  4415. struct fy_node *
  4416. fy_node_create_alias(struct fy_document *fyd,
  4417. const char *alias, size_t len)
  4418. FY_EXPORT;
  4419. /**
  4420. * fy_node_create_alias_copy() - Create an alias node copying the data
  4421. *
  4422. * Create an alias on the given document
  4423. *
  4424. * A copy of the data will be made, so it is safe to free the data
  4425. * after the call.
  4426. *
  4427. * @fyd: The document
  4428. * @alias: The alias text
  4429. * @len: The length of the alias (or -1 if '\0' terminated)
  4430. *
  4431. * Returns:
  4432. * The created alias node, or NULL in case of an error
  4433. */
  4434. struct fy_node *
  4435. fy_node_create_alias_copy(struct fy_document *fyd,
  4436. const char *alias, size_t len)
  4437. FY_EXPORT;
  4438. /**
  4439. * fy_node_get_meta() - Get the meta pointer of a node
  4440. *
  4441. * Return the meta pointer of a node.
  4442. *
  4443. * @fyn: The node to get meta data from
  4444. *
  4445. * Returns:
  4446. * The stored meta data pointer
  4447. */
  4448. void *
  4449. fy_node_get_meta(struct fy_node *fyn)
  4450. FY_EXPORT;
  4451. /**
  4452. * fy_node_set_meta() - Set the meta pointer of a node
  4453. *
  4454. * Set the meta pointer of a node. If @meta is NULL
  4455. * then clear the meta data.
  4456. *
  4457. * @fyn: The node to set meta data
  4458. * @meta: The meta data pointer
  4459. *
  4460. * Returns:
  4461. * 0 on success, -1 on error
  4462. */
  4463. int
  4464. fy_node_set_meta(struct fy_node *fyn, void *meta)
  4465. FY_EXPORT;
  4466. /**
  4467. * fy_node_clear_meta() - Clear the meta data of a node
  4468. *
  4469. * Clears the meta data of a node.
  4470. *
  4471. * @fyn: The node to clear meta data
  4472. */
  4473. void
  4474. fy_node_clear_meta(struct fy_node *fyn)
  4475. FY_EXPORT;
  4476. /**
  4477. * typedef fy_node_meta_clear_fn - Meta data clear method
  4478. *
  4479. * This is the callback called when meta data are cleared.
  4480. *
  4481. * @fyn: The node which the meta data is being cleared
  4482. * @meta: The meta data of the node assigned via fy_node_set_meta()
  4483. * @user: The user pointer of fy_document_register_meta()
  4484. *
  4485. */
  4486. typedef void (*fy_node_meta_clear_fn)(struct fy_node *fyn, void *meta, void *user);
  4487. /**
  4488. * fy_document_register_meta() - Register a meta cleanup hook
  4489. *
  4490. * Register a meta data cleanup hook, to be called when
  4491. * the node is freed via a final call to fy_node_free().
  4492. * The hook is active for all nodes belonging to the document.
  4493. *
  4494. * @fyd: The document which the hook is registered to
  4495. * @clear_fn: The clear hook method
  4496. * @user: Opaque user provided pointer to the clear method
  4497. *
  4498. * Returns:
  4499. * 0 on success, -1 if another hook is already registered.
  4500. */
  4501. int
  4502. fy_document_register_meta(struct fy_document *fyd,
  4503. fy_node_meta_clear_fn clear_fn, void *user)
  4504. FY_EXPORT;
  4505. /**
  4506. * fy_document_unregister_meta() - Unregister a meta cleanup hook
  4507. *
  4508. * Unregister the currently active meta cleanup hook.
  4509. * The previous cleanup hook will be called for every node in
  4510. * the document.
  4511. *
  4512. * @fyd: The document to unregister it's meta cleanup hook.
  4513. */
  4514. void
  4515. fy_document_unregister_meta(struct fy_document *fyd)
  4516. FY_EXPORT;
  4517. /**
  4518. * fy_document_get_userdata() - Get the userdata pointer of a document
  4519. *
  4520. * Return the userdata pointer of a document.
  4521. *
  4522. * @fyn: The document to get userdata from
  4523. *
  4524. * Returns:
  4525. * The stored userdata pointer
  4526. */
  4527. void *
  4528. fy_document_get_userdata(struct fy_document *fyd)
  4529. FY_EXPORT;
  4530. /**
  4531. * fy_document_set_userdata() - Set the userdata pointer of a document
  4532. *
  4533. * Set the userdata pointer of a document. If @userdata is NULL
  4534. * then clear the userdata.
  4535. *
  4536. * @fyd: The document to set userdata
  4537. * @userdata: The userdata pointer
  4538. *
  4539. * Returns:
  4540. * 0 on success, -1 on error
  4541. */
  4542. int
  4543. fy_document_set_userdata(struct fy_document *fyd, void *userdata)
  4544. FY_EXPORT;
  4545. /**
  4546. * typedef fy_document_on_destroy_fn - Userdata clear method
  4547. *
  4548. * This is the callback called just before document is destroyed.
  4549. *
  4550. * @fyd: The document which will be destroyed
  4551. * @userdata: The userdata pointer of a document
  4552. *
  4553. */
  4554. typedef void (*fy_document_on_destroy_fn)(struct fy_document *fyd, void *userdata);
  4555. /**
  4556. * fy_document_register_on_destroy() - Register an on_destroy hook
  4557. *
  4558. * Register an on_destroy hook, to be called when
  4559. * the document is freed via a final call to fy_document_destroy().
  4560. *
  4561. * @fyd: The document which the hook is registered to
  4562. * @on_destroy_fn: The on_destroy hook method
  4563. *
  4564. * Returns:
  4565. * 0 on success, -1 if another hook is already registered.
  4566. */
  4567. int
  4568. fy_document_register_on_destroy(struct fy_document *fyd,
  4569. fy_document_on_destroy_fn on_destroy_fn)
  4570. FY_EXPORT;
  4571. /**
  4572. * fy_document_unregister_on_destroy() - Unregister an on_destroy hook
  4573. *
  4574. * Unregister the currently active on_destroy hook.
  4575. *
  4576. * @fyd: The document to unregister it's on_destroy hook.
  4577. */
  4578. void
  4579. fy_document_unregister_on_destroy(struct fy_document *fyd)
  4580. FY_EXPORT;
  4581. /**
  4582. * fy_node_set_marker() - Set a marker of a node
  4583. *
  4584. * Sets the marker of the given node, while returning
  4585. * the previous state of the marker. Note that the
  4586. * markers use the same space as the node follow markers.
  4587. *
  4588. * @fyn: The node
  4589. * @marker: The marker to set
  4590. *
  4591. * Returns:
  4592. * The previous value of the marker
  4593. */
  4594. bool
  4595. fy_node_set_marker(struct fy_node *fyn, unsigned int marker)
  4596. FY_EXPORT;
  4597. /**
  4598. * fy_node_clear_marker() - Clear a marker of a node
  4599. *
  4600. * Clears the marker of the given node, while returning
  4601. * the previous state of the marker. Note that the
  4602. * markers use the same space as the node follow markers.
  4603. *
  4604. * @fyn: The node
  4605. * @marker: The marker to clear
  4606. *
  4607. * Returns:
  4608. * The previous value of the marker
  4609. */
  4610. bool
  4611. fy_node_clear_marker(struct fy_node *fyn, unsigned int marker)
  4612. FY_EXPORT;
  4613. /**
  4614. * fy_node_is_marker_set() - Checks whether a marker is set
  4615. *
  4616. * Check the state of the given marker.
  4617. *
  4618. * @fyn: The node
  4619. * @marker: The marker index (must be less that FYNWF_MAX_USER_MARKER)
  4620. *
  4621. * Returns:
  4622. * The value of the marker (invalid markers return false)
  4623. */
  4624. bool
  4625. fy_node_is_marker_set(struct fy_node *fyn, unsigned int marker)
  4626. FY_EXPORT;
  4627. /**
  4628. * fy_node_vreport() - Report about a node vprintf style
  4629. *
  4630. * Output a report about the given node via the specific
  4631. * error type, and using the reporting configuration of the node's
  4632. * document.
  4633. *
  4634. * @fyn: The node
  4635. * @type: The error type
  4636. * @fmt: The printf format string
  4637. * @ap: The argument list
  4638. */
  4639. void
  4640. fy_node_vreport(struct fy_node *fyn, enum fy_error_type type,
  4641. const char *fmt, va_list ap)
  4642. FY_EXPORT;
  4643. /**
  4644. * fy_node_report() - Report about a node printf style
  4645. *
  4646. * Output a report about the given node via the specific
  4647. * error type, and using the reporting configuration of the node's
  4648. * document.
  4649. *
  4650. * @fyn: The node
  4651. * @type: The error type
  4652. * @fmt: The printf format string
  4653. * @...: The extra arguments.
  4654. */
  4655. void
  4656. fy_node_report(struct fy_node *fyn, enum fy_error_type type,
  4657. const char *fmt, ...)
  4658. FY_ATTRIBUTE(format(printf, 3, 4))
  4659. FY_EXPORT;
  4660. /**
  4661. * fy_node_override_vreport() - Report about a node vprintf style,
  4662. * overriding file, line and column info
  4663. *
  4664. * Output a report about the given node via the specific
  4665. * error type, and using the reporting configuration of the node's
  4666. * document. This method will use the overrides provided in order
  4667. * to massage the reporting information.
  4668. * If @file is NULL, no file location will be reported.
  4669. * If either @line or @column is negative no location will be reported.
  4670. *
  4671. * @fyn: The node
  4672. * @type: The error type
  4673. * @file: The file override
  4674. * @line: The line override
  4675. * @column: The column override
  4676. * @fmt: The printf format string
  4677. * @ap: The argument list
  4678. */
  4679. void
  4680. fy_node_override_vreport(struct fy_node *fyn, enum fy_error_type type,
  4681. const char *file, int line, int column,
  4682. const char *fmt, va_list ap)
  4683. FY_EXPORT;
  4684. /**
  4685. * fy_node_override_report() - Report about a node printf style,
  4686. * overriding file, line and column info
  4687. *
  4688. * Output a report about the given node via the specific
  4689. * error type, and using the reporting configuration of the node's
  4690. * document. This method will use the overrides provided in order
  4691. * to massage the reporting information.
  4692. * If @file is NULL, no file location will be reported.
  4693. * If either @line or @column is negative no location will be reported.
  4694. *
  4695. * @fyn: The node
  4696. * @type: The error type
  4697. * @file: The file override
  4698. * @line: The line override
  4699. * @column: The column override
  4700. * @fmt: The printf format string
  4701. * @...: The extra arguments.
  4702. */
  4703. void
  4704. fy_node_override_report(struct fy_node *fyn, enum fy_error_type type,
  4705. const char *file, int line, int column,
  4706. const char *fmt, ...)
  4707. FY_ATTRIBUTE(format(printf, 6, 7))
  4708. FY_EXPORT;
  4709. typedef void (*fy_diag_output_fn)(struct fy_diag *diag, void *user,
  4710. const char *buf, size_t len);
  4711. /**
  4712. * struct fy_diag_cfg - The diagnostics configuration
  4713. *
  4714. * @fp: File descriptor of the error output
  4715. * @output_fn: Callback to use when fp is NULL
  4716. * @user: User pointer to pass to the output_fn
  4717. * @level: The minimum debugging level
  4718. * @module_mask: A bitmask of the enabled modules
  4719. * @colorize: true if output should be colorized using ANSI sequences
  4720. * @show_source: true if source location should be displayed
  4721. * @show_position: true if position should be displayed
  4722. * @show_type: true if the type should be displayed
  4723. * @show_module: true if the module should be displayed
  4724. * @source_width: Width of the source field
  4725. * @position_width: Width of the position field
  4726. * @type_width: Width of the type field
  4727. * @module_width: Width of the module field
  4728. *
  4729. * This structure contains the configuration of the
  4730. * diagnostic object.
  4731. */
  4732. struct fy_diag_cfg {
  4733. FILE *fp;
  4734. fy_diag_output_fn output_fn;
  4735. void *user;
  4736. enum fy_error_type level;
  4737. unsigned int module_mask;
  4738. bool colorize : 1;
  4739. bool show_source : 1;
  4740. bool show_position : 1;
  4741. bool show_type : 1;
  4742. bool show_module : 1;
  4743. int source_width;
  4744. int position_width;
  4745. int type_width;
  4746. int module_width;
  4747. };
  4748. /**
  4749. * struct fy_diag_error - A collected diagnostic error
  4750. *
  4751. * @type: Error type
  4752. * @module: The module
  4753. * @fyt: The token (may be NULL)
  4754. * @msg: The message to be output alongside
  4755. * @file: The file which contained the input
  4756. * @line: The line at the error
  4757. * @column: The column at the error
  4758. *
  4759. * This structure contains information about an error
  4760. * being collected by the diagnostic object.
  4761. */
  4762. struct fy_diag_error {
  4763. enum fy_error_type type;
  4764. enum fy_error_module module;
  4765. struct fy_token *fyt;
  4766. const char *msg;
  4767. const char *file;
  4768. int line;
  4769. int column;
  4770. };
  4771. /**
  4772. * fy_diag_create() - Create a diagnostic object
  4773. *
  4774. * Creates a diagnostic object using the provided configuration.
  4775. *
  4776. * @cfg: The configuration for the diagnostic object (NULL is default)
  4777. *
  4778. * Returns:
  4779. * A pointer to the diagnostic object or NULL in case of an error.
  4780. */
  4781. struct fy_diag *
  4782. fy_diag_create(const struct fy_diag_cfg *cfg)
  4783. FY_EXPORT;
  4784. /**
  4785. * fy_diag_destroy() - Destroy a diagnostic object
  4786. *
  4787. * Destroy a diagnostic object; note that the actual
  4788. * destruction only occurs when no more references to the
  4789. * object are present. However no output will be generated
  4790. * after this call.
  4791. *
  4792. * @diag: The diagnostic object to destroy
  4793. */
  4794. void
  4795. fy_diag_destroy(struct fy_diag *diag)
  4796. FY_EXPORT;
  4797. /**
  4798. * fy_diag_get_cfg() - Get a diagnostic object's configuration
  4799. *
  4800. * Return the current configuration of a diagnostic object
  4801. *
  4802. * @diag: The diagnostic object
  4803. *
  4804. * Returns:
  4805. * A const pointer to the diagnostic object configuration, or NULL
  4806. * in case where diag is NULL
  4807. */
  4808. const struct fy_diag_cfg *
  4809. fy_diag_get_cfg(struct fy_diag *diag)
  4810. FY_EXPORT;
  4811. /**
  4812. * fy_diag_set_cfg() - Set a diagnostic object's configuration
  4813. *
  4814. * Replace the current diagnostic configuration with the given
  4815. * configuration passed as an argument.
  4816. *
  4817. * @diag: The diagnostic object
  4818. * @cfg: The diagnostic configuration
  4819. */
  4820. void
  4821. fy_diag_set_cfg(struct fy_diag *diag, const struct fy_diag_cfg *cfg)
  4822. FY_EXPORT;
  4823. /**
  4824. * fy_diag_set_level() - Set a diagnostic object's debug error level
  4825. *
  4826. * @diag: The diagnostic object
  4827. * @level: The debugging level to set
  4828. */
  4829. void
  4830. fy_diag_set_level(struct fy_diag *diag, enum fy_error_type level);
  4831. /**
  4832. * fy_diag_set_colorize() - Set a diagnostic object's colorize option
  4833. *
  4834. * @diag: The diagnostic object
  4835. * @colorize: The colorize option
  4836. */
  4837. void
  4838. fy_diag_set_colorize(struct fy_diag *diag, bool colorize);
  4839. /**
  4840. * fy_diag_ref() - Increment that reference counter of a diagnostic object
  4841. *
  4842. * Increment the reference.
  4843. *
  4844. * @diag: The diagnostic object to reference
  4845. *
  4846. * Returns:
  4847. * Always returns the @diag argument
  4848. */
  4849. struct fy_diag *
  4850. fy_diag_ref(struct fy_diag *diag)
  4851. FY_EXPORT;
  4852. /**
  4853. * fy_diag_unref() - Take away a ref from a diagnostic object
  4854. *
  4855. * Take away a reference, if it gets to 0, the diagnostic object
  4856. * is freed.
  4857. *
  4858. * @diag: The diagnostic object to unref
  4859. */
  4860. void
  4861. fy_diag_unref(struct fy_diag *diag)
  4862. FY_EXPORT;
  4863. /**
  4864. * fy_diag_got_error() - Test whether an error level diagnostic
  4865. * has been produced
  4866. *
  4867. * Tests whether an error diagnostic has been produced.
  4868. *
  4869. * @diag: The diagnostic object
  4870. *
  4871. * Returns:
  4872. * true if an error has been produced, false otherwise
  4873. */
  4874. bool
  4875. fy_diag_got_error(struct fy_diag *diag)
  4876. FY_EXPORT;
  4877. /**
  4878. * fy_diag_reset_error() - Reset the error flag of
  4879. * the diagnostic object
  4880. *
  4881. * Clears the error flag which was set by an output
  4882. * of an error level diagnostic
  4883. *
  4884. * @diag: The diagnostic object
  4885. */
  4886. void
  4887. fy_diag_reset_error(struct fy_diag *diag)
  4888. FY_EXPORT;
  4889. /**
  4890. * fy_diag_set_collect_errors() - Collect errors instead of outputting
  4891. *
  4892. * Set the collect errors mode. When true instead of outputting to
  4893. * the diagnostic interface, errors are collected for later
  4894. * retrieval.
  4895. *
  4896. * @diag: The diagnostic object
  4897. * @collect_errors: The collect errors mode
  4898. */
  4899. void
  4900. fy_diag_set_collect_errors(struct fy_diag *diag, bool collect_errors)
  4901. FY_EXPORT;
  4902. /**
  4903. * fy_diag_cfg_default() - Fill in the configuration structure
  4904. * with defaults
  4905. *
  4906. * Fills the configuration structure with defaults. The default
  4907. * always associates the file descriptor to stderr.
  4908. *
  4909. * @cfg: The diagnostic configuration structure
  4910. */
  4911. void
  4912. fy_diag_cfg_default(struct fy_diag_cfg *cfg)
  4913. FY_EXPORT;
  4914. /**
  4915. * fy_diag_cfg_from_parser_flags() - Fill partial diagnostic config
  4916. * structure from parser config flags
  4917. *
  4918. * Fills in part of the configuration structure using parser flags.
  4919. * Since the parser flags do not contain debugging flags anymore this
  4920. * method is deprecated.
  4921. *
  4922. * @cfg: The diagnostic configuration structure
  4923. * @pflags: The parser flags
  4924. */
  4925. void
  4926. fy_diag_cfg_from_parser_flags(struct fy_diag_cfg *cfg,
  4927. enum fy_parse_cfg_flags pflags)
  4928. FY_EXPORT FY_DEPRECATED;
  4929. /**
  4930. * fy_diag_vprintf() - vprintf raw interface to diagnostics
  4931. *
  4932. * Raw output to the diagnostic object using a standard
  4933. * vprintf interface. Note that this is the lowest level
  4934. * interface, and as such is not recommended for use, since
  4935. * no formatting or coloring will take place.
  4936. *
  4937. * @diag: The diagnostic object to use
  4938. * @fmt: The vprintf format string
  4939. * @ap: The arguments
  4940. *
  4941. * Returns:
  4942. * The number of characters output, or -1 in case of an error
  4943. * Note that 0 shall be returned if the diagnostic object has
  4944. * been destroyed but not yet freed.
  4945. */
  4946. int
  4947. fy_diag_vprintf(struct fy_diag *diag, const char *fmt, va_list ap)
  4948. FY_EXPORT;
  4949. /**
  4950. * fy_diag_printf() - printf raw interface to diagnostics
  4951. *
  4952. * Raw output to the diagnostic object using a standard
  4953. * printf interface. Note that this is the lowest level
  4954. * interface, and as such is not recommended for use, since
  4955. * no formatting or coloring will take place.
  4956. *
  4957. * @diag: The diagnostic object to use
  4958. * @fmt: The printf format string
  4959. * @...: The arguments
  4960. *
  4961. * Returns:
  4962. * The number of characters output, or -1 in case of an error
  4963. * Note that 0 shall be returned if the diagnostic object has
  4964. * been destroyed but not yet freed.
  4965. */
  4966. int
  4967. fy_diag_printf(struct fy_diag *diag, const char *fmt, ...)
  4968. FY_EXPORT
  4969. FY_ATTRIBUTE(format(printf, 2, 3));
  4970. /**
  4971. * struct fy_diag_ctx - The diagnostics context
  4972. *
  4973. * @level: The level of the diagnostic
  4974. * @module: The module of the diagnostic
  4975. * @source_func: The source function
  4976. * @source_file: The source file
  4977. * @source_line: The source line
  4978. * @file: The file that caused the error
  4979. * @line: The line where the diagnostic occured
  4980. * @column: The column where the diagnostic occured
  4981. *
  4982. * This structure contains the diagnostic context
  4983. */
  4984. struct fy_diag_ctx {
  4985. enum fy_error_type level;
  4986. enum fy_error_module module;
  4987. const char *source_func;
  4988. const char *source_file;
  4989. int source_line;
  4990. const char *file;
  4991. int line;
  4992. int column;
  4993. };
  4994. /**
  4995. * fy_vdiag() - context aware diagnostic output like vprintf
  4996. *
  4997. * Context aware output to the diagnostic object using a standard
  4998. * vprintf interface.
  4999. *
  5000. * @diag: The diagnostic object to use
  5001. * @fydc: The diagnostic context
  5002. * @fmt: The vprintf format string
  5003. * @ap: The arguments
  5004. *
  5005. * Returns:
  5006. * The number of characters output, or -1 in case of an error
  5007. * Note that 0 shall be returned if the diagnostic object has
  5008. * been destroyed but not yet freed.
  5009. */
  5010. int
  5011. fy_vdiag(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
  5012. const char *fmt, va_list ap)
  5013. FY_EXPORT;
  5014. /**
  5015. * fy_diagf() - context aware diagnostic output like printf
  5016. *
  5017. * Context aware output to the diagnostic object using a standard
  5018. * printf interface.
  5019. *
  5020. * @diag: The diagnostic object to use
  5021. * @fydc: The diagnostic context
  5022. * @fmt: The vprintf format string
  5023. *
  5024. * Returns:
  5025. * The number of characters output, or -1 in case of an error
  5026. * Note that 0 shall be returned if the diagnostic object has
  5027. * been destroyed but not yet freed.
  5028. */
  5029. int
  5030. fy_diagf(struct fy_diag *diag, const struct fy_diag_ctx *fydc,
  5031. const char *fmt, ...)
  5032. FY_EXPORT
  5033. FY_ATTRIBUTE(format(printf, 3, 4));
  5034. int fy_diag_diag(struct fy_diag *diag, enum fy_error_type level, const char* fmt, ...);
  5035. #ifndef NDEBUG
  5036. #define fy_debug(_diag, _fmt, ...) \
  5037. fy_diag_diag((_diag), FYET_DEBUG, (_fmt) , ## __VA_ARGS__)
  5038. #else
  5039. #define fy_debug(_diag, _fmt, ...) \
  5040. do { } while(0)
  5041. #endif
  5042. #define fy_info(_diag, _fmt, ...) \
  5043. fy_diag_diag((_diag), FYET_INFO, (_fmt) , ## __VA_ARGS__)
  5044. #define fy_notice(_diag, _fmt, ...) \
  5045. fy_diag_diag((_diag), FYET_NOTICE, (_fmt) , ## __VA_ARGS__)
  5046. #define fy_warning(_diag, _fmt, ...) \
  5047. fy_diag_diag((_diag), FYET_WARNING, (_fmt) , ## __VA_ARGS__)
  5048. #define fy_error(_diag, _fmt, ...) \
  5049. fy_diag_diag((_diag), FYET_ERROR, (_fmt) , ## __VA_ARGS__)
  5050. /**
  5051. * fy_diag_node_vreport() - Report about a node vprintf style using
  5052. * the given diagnostic object
  5053. *
  5054. * Output a report about the given node via the specific
  5055. * error type, and using the reporting configuration of the node's
  5056. * document.
  5057. *
  5058. * @diag: The diag object
  5059. * @fyn: The node
  5060. * @type: The error type
  5061. * @fmt: The printf format string
  5062. * @ap: The argument list
  5063. */
  5064. void
  5065. fy_diag_node_vreport(struct fy_diag *diag, struct fy_node *fyn,
  5066. enum fy_error_type type, const char *fmt, va_list ap)
  5067. FY_EXPORT;
  5068. /**
  5069. * fy_diag_node_report() - Report about a node printf style using
  5070. * the given diagnostic object
  5071. *
  5072. * Output a report about the given node via the specific
  5073. * error type, and using the reporting configuration of the node's
  5074. * document.
  5075. *
  5076. * @diag: The diag object
  5077. * @fyn: The node
  5078. * @type: The error type
  5079. * @fmt: The printf format string
  5080. * @...: The extra arguments.
  5081. */
  5082. void
  5083. fy_diag_node_report(struct fy_diag *diag, struct fy_node *fyn,
  5084. enum fy_error_type type, const char *fmt, ...)
  5085. FY_ATTRIBUTE(format(printf, 4, 5))
  5086. FY_EXPORT;
  5087. /**
  5088. * fy_diag_node_override_vreport() - Report about a node vprintf style,
  5089. * overriding file, line and column info using
  5090. * the given diagnostic object
  5091. *
  5092. * Output a report about the given node via the specific
  5093. * error type, and using the reporting configuration of the node's
  5094. * document. This method will use the overrides provided in order
  5095. * to massage the reporting information.
  5096. * If @file is NULL, no file location will be reported.
  5097. * If either @line or @column is negative no location will be reported.
  5098. *
  5099. * @diag: The diag object
  5100. * @fyn: The node
  5101. * @type: The error type
  5102. * @file: The file override
  5103. * @line: The line override
  5104. * @column: The column override
  5105. * @fmt: The printf format string
  5106. * @ap: The argument list
  5107. */
  5108. void
  5109. fy_diag_node_override_vreport(struct fy_diag *diag, struct fy_node *fyn,
  5110. enum fy_error_type type, const char *file,
  5111. int line, int column, const char *fmt, va_list ap)
  5112. FY_EXPORT;
  5113. /**
  5114. * fy_diag_node_override_report() - Report about a node printf style,
  5115. * overriding file, line and column info using
  5116. * the given diagnostic object
  5117. *
  5118. * Output a report about the given node via the specific
  5119. * error type, and using the reporting configuration of the node's
  5120. * document. This method will use the overrides provided in order
  5121. * to massage the reporting information.
  5122. * If @file is NULL, no file location will be reported.
  5123. * If either @line or @column is negative no location will be reported.
  5124. *
  5125. * @diag: The diag object
  5126. * @fyn: The node
  5127. * @type: The error type
  5128. * @file: The file override
  5129. * @line: The line override
  5130. * @column: The column override
  5131. * @fmt: The printf format string
  5132. * @...: The extra arguments.
  5133. */
  5134. void
  5135. fy_diag_node_override_report(struct fy_diag *diag, struct fy_node *fyn,
  5136. enum fy_error_type type, const char *file,
  5137. int line, int column, const char *fmt, ...)
  5138. FY_ATTRIBUTE(format(printf, 7, 8))
  5139. FY_EXPORT;
  5140. /**
  5141. * fy_diag_errors_iterate() - Iterate over the errors of a diagnostic object
  5142. *
  5143. * This method iterates over all the errors collected on the diagnostic object.
  5144. * The start of the iteration is signalled by a NULL in \*prevp.
  5145. *
  5146. * @diag: The diagnostic object
  5147. * @prevp: The previous result iterator
  5148. *
  5149. * Returns:
  5150. * The next errors or NULL when there are not any more.
  5151. */
  5152. struct fy_diag_error *
  5153. fy_diag_errors_iterate(struct fy_diag *diag, void **prevp)
  5154. FY_EXPORT;
  5155. /**
  5156. * enum fy_path_parse_cfg_flags - Path parse configuration flags
  5157. *
  5158. * These flags control the operation of the path parse
  5159. *
  5160. * @FYPPCF_QUIET: Quiet, do not output any information messages
  5161. * @FYPPCF_DISABLE_RECYCLING: Disable recycling optimization
  5162. * @FYPPCF_DISABLE_ACCELERATORS: Disable use of access accelerators (saves memory)
  5163. */
  5164. enum fy_path_parse_cfg_flags {
  5165. FYPPCF_QUIET = FY_BIT(0),
  5166. FYPPCF_DISABLE_RECYCLING = FY_BIT(1),
  5167. FYPPCF_DISABLE_ACCELERATORS = FY_BIT(2),
  5168. };
  5169. /**
  5170. * struct fy_path_parse_cfg - path parser configuration structure.
  5171. *
  5172. * Argument to the fy_path_parser_create() method which
  5173. * performs parsing of a ypath expression
  5174. *
  5175. * @flags: Configuration flags
  5176. * @userdata: Opaque user data pointer
  5177. * @diag: Optional diagnostic interface to use
  5178. */
  5179. struct fy_path_parse_cfg {
  5180. enum fy_path_parse_cfg_flags flags;
  5181. void *userdata;
  5182. struct fy_diag *diag;
  5183. };
  5184. /**
  5185. * fy_path_parser_create() - Create a ypath parser.
  5186. *
  5187. * Creates a path parser with its configuration @cfg
  5188. * The path parser may be destroyed by a corresponding call to
  5189. * fy_path_parser_destroy().
  5190. *
  5191. * @cfg: The configuration for the path parser
  5192. *
  5193. * Returns:
  5194. * A pointer to the path parser or NULL in case of an error.
  5195. */
  5196. struct fy_path_parser *
  5197. fy_path_parser_create(const struct fy_path_parse_cfg *cfg)
  5198. FY_EXPORT;
  5199. /**
  5200. * fy_path_parser_destroy() - Destroy the given path parser
  5201. *
  5202. * Destroy a path parser created earlier via fy_path_parser_create().
  5203. *
  5204. * @fypp: The path parser to destroy
  5205. */
  5206. void
  5207. fy_path_parser_destroy(struct fy_path_parser *fypp)
  5208. FY_EXPORT;
  5209. /**
  5210. * fy_path_parser_reset() - Reset a path parser completely
  5211. *
  5212. * Completely reset a path parser, including after an error
  5213. * that caused a parser error to be emitted.
  5214. *
  5215. * @fypp: The path parser to reset
  5216. *
  5217. * Returns:
  5218. * 0 if the reset was successful, -1 otherwise
  5219. */
  5220. int
  5221. fy_path_parser_reset(struct fy_path_parser *fypp)
  5222. FY_EXPORT;
  5223. /**
  5224. * fy_path_parse_expr_from_string() - Parse an expression from a given string
  5225. *
  5226. * Create a path expression from a string using the provided path parser.
  5227. *
  5228. * @fypp: The path parser to use
  5229. * @str: The ypath source to use.
  5230. * @len: The length of the string (or -1 if '\0' terminated)
  5231. *
  5232. * Returns:
  5233. * The created path expression or NULL on error.
  5234. */
  5235. struct fy_path_expr *
  5236. fy_path_parse_expr_from_string(struct fy_path_parser *fypp,
  5237. const char *str, size_t len)
  5238. FY_EXPORT;
  5239. /**
  5240. * fy_path_expr_build_from_string() - Parse an expression from a given string
  5241. *
  5242. * Create a path expression from a string using the provided path parser
  5243. * configuration.
  5244. *
  5245. * @pcfg: The path parser configuration to use, or NULL for default
  5246. * @str: The ypath source to use.
  5247. * @len: The length of the string (or -1 if '\0' terminated)
  5248. *
  5249. * Returns:
  5250. * The created path expression or NULL on error.
  5251. */
  5252. struct fy_path_expr *
  5253. fy_path_expr_build_from_string(const struct fy_path_parse_cfg *pcfg,
  5254. const char *str, size_t len)
  5255. FY_EXPORT;
  5256. /**
  5257. * fy_path_expr_free() - Free a path expression
  5258. *
  5259. * Free a previously returned expression from any of the path parser
  5260. * methods like fy_path_expr_build_from_string()
  5261. *
  5262. * @expr: The expression to free (may be NULL)
  5263. */
  5264. void
  5265. fy_path_expr_free(struct fy_path_expr *expr)
  5266. FY_EXPORT;
  5267. /**
  5268. * fy_path_expr_dump() - Dump the contents of a path expression to
  5269. * the diagnostic object
  5270. *
  5271. * Dumps the expression using the provided error level.
  5272. *
  5273. * @expr: The expression to dump
  5274. * @diag: The diagnostic object to use
  5275. * @errlevel: The error level which the diagnostic will use
  5276. * @level: The nest level; should be set to 0
  5277. * @banner: The banner to display on level 0
  5278. */
  5279. void
  5280. fy_path_expr_dump(struct fy_path_expr *expr, struct fy_diag *diag,
  5281. enum fy_error_type errlevel, int level, const char *banner)
  5282. FY_EXPORT;
  5283. /**
  5284. * fy_path_expr_to_document() - Converts the path expression to a YAML document
  5285. *
  5286. * Converts the expression to a YAML document which is useful for
  5287. * understanding what the expression evaluates to.
  5288. *
  5289. * @expr: The expression to convert to a document
  5290. *
  5291. * Returns:
  5292. * The document of the expression or NULL on error.
  5293. */
  5294. struct fy_document *
  5295. fy_path_expr_to_document(struct fy_path_expr *expr)
  5296. FY_EXPORT;
  5297. /**
  5298. * enum fy_path_exec_cfg_flags - Path executor configuration flags
  5299. *
  5300. * These flags control the operation of the path expression executor
  5301. *
  5302. * @FYPXCF_QUIET: Quiet, do not output any information messages
  5303. * @FYPXCF_DISABLE_RECYCLING: Disable recycling optimization
  5304. * @FYPXCF_DISABLE_ACCELERATORS: Disable use of access accelerators (saves memory)
  5305. */
  5306. enum fy_path_exec_cfg_flags {
  5307. FYPXCF_QUIET = FY_BIT(0),
  5308. FYPXCF_DISABLE_RECYCLING = FY_BIT(1),
  5309. FYPXCF_DISABLE_ACCELERATORS = FY_BIT(2),
  5310. };
  5311. /**
  5312. * struct fy_path_exec_cfg - path expression executor configuration structure.
  5313. *
  5314. * Argument to the fy_path_exec_create() method which
  5315. * performs execution of a ypath expression
  5316. *
  5317. * @flags: Configuration flags
  5318. * @userdata: Opaque user data pointer
  5319. * @diag: Optional diagnostic interface to use
  5320. */
  5321. struct fy_path_exec_cfg {
  5322. enum fy_path_exec_cfg_flags flags;
  5323. void *userdata;
  5324. struct fy_diag *diag;
  5325. };
  5326. /**
  5327. * fy_path_exec_create() - Create a ypath expression executor.
  5328. *
  5329. * Creates a ypath expression parser with its configuration @cfg
  5330. * The executor may be destroyed by a corresponding call to
  5331. * fy_path_exec_destroy().
  5332. *
  5333. * @xcfg: The configuration for the executor
  5334. *
  5335. * Returns:
  5336. * A pointer to the executor or NULL in case of an error.
  5337. */
  5338. struct fy_path_exec *
  5339. fy_path_exec_create(const struct fy_path_exec_cfg *xcfg)
  5340. FY_EXPORT;
  5341. /**
  5342. * fy_path_exec_destroy() - Destroy the given path expression executor
  5343. *
  5344. * Destroy ane executor created earlier via fy_path_exec_create().
  5345. *
  5346. * @fypx: The path parser to destroy
  5347. */
  5348. void
  5349. fy_path_exec_destroy(struct fy_path_exec *fypx)
  5350. FY_EXPORT;
  5351. /**
  5352. * fy_path_exec_reset() - Reset an executor
  5353. *
  5354. * Completely reset an executor without releasing it.
  5355. *
  5356. * @fypx: The executor to reset
  5357. *
  5358. * Returns:
  5359. * 0 if the reset was successful, -1 otherwise
  5360. */
  5361. int
  5362. fy_path_exec_reset(struct fy_path_exec *fypx)
  5363. FY_EXPORT;
  5364. /**
  5365. * fy_path_exec_execute() - Execute a path expression starting at
  5366. * the given start node
  5367. *
  5368. * Execute the expression starting at fyn_start. If execution
  5369. * is successful the results are available via fy_path_exec_results_iterate()
  5370. *
  5371. * Note that it is illegal to modify the state of the document that the
  5372. * results reside between this call and the results collection.
  5373. *
  5374. * @fypx: The executor to use
  5375. * @expr: The expression to use
  5376. * @fyn_start: The node on which the expression will begin.
  5377. *
  5378. * Returns:
  5379. * 0 if the execution was successful, -1 otherwise
  5380. *
  5381. * Note that the execution may be successful but no results were
  5382. * produced, in which case the iterator will return NULL.
  5383. */
  5384. int
  5385. fy_path_exec_execute(struct fy_path_exec *fypx, struct fy_path_expr *expr,
  5386. struct fy_node *fyn_start)
  5387. FY_EXPORT;
  5388. /**
  5389. * fy_path_exec_results_iterate() - Iterate over the results of execution
  5390. *
  5391. * This method iterates over all the results in the executor.
  5392. * The start of the iteration is signalled by a NULL in \*prevp.
  5393. *
  5394. * @fypx: The executor
  5395. * @prevp: The previous result iterator
  5396. *
  5397. * Returns:
  5398. * The next node in the result set or NULL at the end of the results.
  5399. */
  5400. struct fy_node *
  5401. fy_path_exec_results_iterate(struct fy_path_exec *fypx, void **prevp)
  5402. FY_EXPORT;
  5403. /*
  5404. * Helper methods for binding implementers
  5405. * Note that users of the library do not need to know these details.
  5406. * However bindings that were developed against libyaml expect these
  5407. * to be exported, so provide a shim here
  5408. */
  5409. /**
  5410. * enum fy_token_type - Token types
  5411. *
  5412. * The available token types that the tokenizer produces.
  5413. *
  5414. * @FYTT_NONE: No token
  5415. * @FYTT_STREAM_START: Stream start
  5416. * @FYTT_STREAM_END: Stream end
  5417. * @FYTT_VERSION_DIRECTIVE: Version directive
  5418. * @FYTT_TAG_DIRECTIVE: Tag directive
  5419. * @FYTT_DOCUMENT_START: Document start
  5420. * @FYTT_DOCUMENT_END: Document end
  5421. * @FYTT_BLOCK_SEQUENCE_START: Start of a block sequence
  5422. * @FYTT_BLOCK_MAPPING_START: Start of a block mapping
  5423. * @FYTT_BLOCK_END: End of a block mapping or a sequence
  5424. * @FYTT_FLOW_SEQUENCE_START: Start of a flow sequence
  5425. * @FYTT_FLOW_SEQUENCE_END: End of a flow sequence
  5426. * @FYTT_FLOW_MAPPING_START: Start of a flow mapping
  5427. * @FYTT_FLOW_MAPPING_END: End of a flow mapping
  5428. * @FYTT_BLOCK_ENTRY: A block entry
  5429. * @FYTT_FLOW_ENTRY: A flow entry
  5430. * @FYTT_KEY: A key of a mapping
  5431. * @FYTT_VALUE: A value of a mapping
  5432. * @FYTT_ALIAS: An alias
  5433. * @FYTT_ANCHOR: An anchor
  5434. * @FYTT_TAG: A tag
  5435. * @FYTT_SCALAR: A scalar
  5436. * @FYTT_INPUT_MARKER: Internal input marker token
  5437. * @FYTT_PE_SLASH: A slash
  5438. * @FYTT_PE_ROOT: A root
  5439. * @FYTT_PE_THIS: A this
  5440. * @FYTT_PE_PARENT: A parent
  5441. * @FYTT_PE_MAP_KEY: A map key
  5442. * @FYTT_PE_SEQ_INDEX: A sequence index
  5443. * @FYTT_PE_SEQ_SLICE: A sequence slice
  5444. * @FYTT_PE_SCALAR_FILTER: A scalar filter
  5445. * @FYTT_PE_COLLECTION_FILTER: A collection filter
  5446. * @FYTT_PE_SEQ_FILTER: A sequence filter
  5447. * @FYTT_PE_MAP_FILTER: A mapping filter
  5448. * @FYTT_PE_UNIQUE_FILTER: Filters out duplicates
  5449. * @FYTT_PE_EVERY_CHILD: Every child
  5450. * @FYTT_PE_EVERY_CHILD_R: Every child recursive
  5451. * @FYTT_PE_ALIAS: An alias
  5452. * @FYTT_PE_SIBLING: A sibling marker
  5453. * @FYTT_PE_COMMA: A comma
  5454. * @FYTT_PE_BARBAR: A ||
  5455. * @FYTT_PE_AMPAMP: A &&
  5456. * @FYTT_PE_LPAREN: A left parenthesis
  5457. * @FYTT_PE_RPAREN: A right parenthesis
  5458. * @FYTT_PE_EQEQ: Equality operator
  5459. * @FYTT_PE_NOTEQ: Non-equality operator
  5460. * @FYTT_PE_LT: Less than operator
  5461. * @FYTT_PE_GT: Greater than operator
  5462. * @FYTT_PE_LTE: Less or equal than operator
  5463. * @FYTT_PE_GTE: Greater or equal than operator
  5464. * @FYTT_SE_PLUS: Plus operator
  5465. * @FYTT_SE_MINUS: Minus operator
  5466. * @FYTT_SE_MULT: Multiply operator
  5467. * @FYTT_SE_DIV: Divide operator
  5468. * @FYTT_PE_METHOD: Path expression method (chained)
  5469. * @FYTT_SE_METHOD: Scalar expression method (non chained)
  5470. */
  5471. enum fy_token_type {
  5472. /* non-content token types */
  5473. FYTT_NONE,
  5474. FYTT_STREAM_START,
  5475. FYTT_STREAM_END,
  5476. FYTT_VERSION_DIRECTIVE,
  5477. FYTT_TAG_DIRECTIVE,
  5478. FYTT_DOCUMENT_START,
  5479. FYTT_DOCUMENT_END,
  5480. /* content token types */
  5481. FYTT_BLOCK_SEQUENCE_START,
  5482. FYTT_BLOCK_MAPPING_START,
  5483. FYTT_BLOCK_END,
  5484. FYTT_FLOW_SEQUENCE_START,
  5485. FYTT_FLOW_SEQUENCE_END,
  5486. FYTT_FLOW_MAPPING_START,
  5487. FYTT_FLOW_MAPPING_END,
  5488. FYTT_BLOCK_ENTRY,
  5489. FYTT_FLOW_ENTRY,
  5490. FYTT_KEY,
  5491. FYTT_VALUE,
  5492. FYTT_ALIAS,
  5493. FYTT_ANCHOR,
  5494. FYTT_TAG,
  5495. FYTT_SCALAR,
  5496. /* special error reporting */
  5497. FYTT_INPUT_MARKER,
  5498. /* path expression tokens */
  5499. FYTT_PE_SLASH,
  5500. FYTT_PE_ROOT,
  5501. FYTT_PE_THIS,
  5502. FYTT_PE_PARENT,
  5503. FYTT_PE_MAP_KEY,
  5504. FYTT_PE_SEQ_INDEX,
  5505. FYTT_PE_SEQ_SLICE,
  5506. FYTT_PE_SCALAR_FILTER,
  5507. FYTT_PE_COLLECTION_FILTER,
  5508. FYTT_PE_SEQ_FILTER,
  5509. FYTT_PE_MAP_FILTER,
  5510. FYTT_PE_UNIQUE_FILTER,
  5511. FYTT_PE_EVERY_CHILD,
  5512. FYTT_PE_EVERY_CHILD_R,
  5513. FYTT_PE_ALIAS,
  5514. FYTT_PE_SIBLING,
  5515. FYTT_PE_COMMA,
  5516. FYTT_PE_BARBAR,
  5517. FYTT_PE_AMPAMP,
  5518. FYTT_PE_LPAREN,
  5519. FYTT_PE_RPAREN,
  5520. /* comparison operators */
  5521. FYTT_PE_EQEQ, /* == */
  5522. FYTT_PE_NOTEQ, /* != */
  5523. FYTT_PE_LT, /* < */
  5524. FYTT_PE_GT, /* > */
  5525. FYTT_PE_LTE, /* <= */
  5526. FYTT_PE_GTE, /* >= */
  5527. /* scalar expression tokens */
  5528. FYTT_SE_PLUS,
  5529. FYTT_SE_MINUS,
  5530. FYTT_SE_MULT,
  5531. FYTT_SE_DIV,
  5532. FYTT_PE_METHOD, /* path expr method (chained) */
  5533. FYTT_SE_METHOD, /* scalar expr method (non chained) */
  5534. };
  5535. /* The number of token types available */
  5536. #define FYTT_COUNT (FYTT_SE_METHOD+1)
  5537. /**
  5538. * fy_token_type_is_valid() - Check token type validity
  5539. *
  5540. * Check if argument token type is a valid one.
  5541. *
  5542. * @type: The token type
  5543. *
  5544. * Returns:
  5545. * true if the token type is valid, false otherwise
  5546. */
  5547. static inline bool
  5548. fy_token_type_is_valid(enum fy_token_type type)
  5549. {
  5550. return type >= FYTT_NONE && type < FYTT_COUNT;
  5551. }
  5552. /**
  5553. * fy_token_type_is_yaml() - Check if token type is valid for YAML
  5554. *
  5555. * Check if argument token type is a valid YAML one.
  5556. *
  5557. * @type: The token type
  5558. *
  5559. * Returns:
  5560. * true if the token type is a valid YAML one, false otherwise
  5561. */
  5562. static inline bool
  5563. fy_token_type_is_yaml(enum fy_token_type type)
  5564. {
  5565. return type >= FYTT_STREAM_START && type <= FYTT_SCALAR;
  5566. }
  5567. /**
  5568. * fy_token_type_is_content() - Check if token type is
  5569. * valid for YAML content
  5570. *
  5571. * Check if argument token type is a valid YAML content one.
  5572. *
  5573. * @type: The token type
  5574. *
  5575. * Returns:
  5576. * true if the token type is a valid YAML content one, false otherwise
  5577. */
  5578. static inline bool
  5579. fy_token_type_is_content(enum fy_token_type type)
  5580. {
  5581. return type >= FYTT_BLOCK_SEQUENCE_START && type <= FYTT_SCALAR;
  5582. }
  5583. /**
  5584. * fy_token_type_is_path_expr() - Check if token type is
  5585. * valid for a YPATH expression
  5586. *
  5587. * Check if argument token type is a valid YPATH parse expression token
  5588. *
  5589. * @type: The token type
  5590. *
  5591. * Returns:
  5592. * true if the token type is a valid YPATH one, false otherwise
  5593. */
  5594. static inline bool
  5595. fy_token_type_is_path_expr(enum fy_token_type type)
  5596. {
  5597. return type >= FYTT_PE_SLASH && type <= FYTT_PE_GTE;
  5598. }
  5599. /**
  5600. * fy_token_type_is_scalar_expr() - Check if token type is
  5601. * valid for a YPATH scalar expression
  5602. *
  5603. * Check if argument token type is a valid YPATH parse scalar expression token
  5604. *
  5605. * @type: The token type
  5606. *
  5607. * Returns:
  5608. * true if the token type is a valid YPATH scalar one, false otherwise
  5609. */
  5610. static inline bool
  5611. fy_token_type_is_scalar_expr(enum fy_token_type type)
  5612. {
  5613. return type >= FYTT_SE_PLUS && type <= FYTT_SE_DIV;
  5614. }
  5615. /**
  5616. * fy_token_get_type() - Return the token's type
  5617. *
  5618. * Return the token's type; if NULL then FYTT_NONE is returned
  5619. *
  5620. * @fyt: The token
  5621. *
  5622. * Returns:
  5623. * The token's type; FYTT_NONE if not a valid token (or NULL)
  5624. */
  5625. enum fy_token_type
  5626. fy_token_get_type(struct fy_token *fyt)
  5627. FY_EXPORT;
  5628. /**
  5629. * fy_token_start_mark() - Get token's start marker
  5630. *
  5631. * Return the token's start marker if it exists. Note
  5632. * it is permissable for some token types to have no
  5633. * start marker because they are without content.
  5634. *
  5635. * @fyt: The token to get its start marker
  5636. *
  5637. * Returns:
  5638. * The token's start marker, NULL if not available.
  5639. */
  5640. const struct fy_mark *
  5641. fy_token_start_mark(struct fy_token *fyt)
  5642. FY_EXPORT;
  5643. /**
  5644. * fy_token_end_mark() - Get token's end marker
  5645. *
  5646. * Return the token's end marker if it exists. Note
  5647. * it is permissable for some token types to have no
  5648. * end marker because they are without content.
  5649. *
  5650. * @fyt: The token to get its end marker
  5651. *
  5652. * Returns:
  5653. * The token's end marker, NULL if not available.
  5654. */
  5655. const struct fy_mark *
  5656. fy_token_end_mark(struct fy_token *fyt)
  5657. FY_EXPORT;
  5658. /**
  5659. * fy_scan() - Low level access to the scanner
  5660. *
  5661. * Return the next scanner token. Note this is a very
  5662. * low level interface, intended for users that want/need
  5663. * to implement their own YAML parser. The returned
  5664. * token is expected to be disposed using fy_scan_token_free()
  5665. *
  5666. * @fyp: The parser to get the next token from.
  5667. *
  5668. * Returns:
  5669. * The next token, or NULL if no more tokens are available.
  5670. */
  5671. struct fy_token *
  5672. fy_scan(struct fy_parser *fyp)
  5673. FY_EXPORT;
  5674. /**
  5675. * fy_scan_token_free() - Free the token returned by fy_scan()
  5676. *
  5677. * Free the token returned by fy_scan().
  5678. *
  5679. * @fyp: The parser of which the token was returned by fy_scan()
  5680. * @fyt: The token to free
  5681. */
  5682. void
  5683. fy_scan_token_free(struct fy_parser *fyp, struct fy_token *fyt)
  5684. FY_EXPORT;
  5685. /**
  5686. * fy_tag_directive_token_prefix0() - Get the prefix contained in the
  5687. * tag directive token as zero terminated
  5688. * string
  5689. *
  5690. * Retrieve the tag directive's prefix contents as a zero terminated string.
  5691. * It is similar to fy_tag_directive_token_prefix(), with the difference
  5692. * that the returned string is zero terminated and memory may be allocated
  5693. * to hold it associated with the token.
  5694. *
  5695. * @fyt: The tag directive token out of which the prefix pointer
  5696. * will be returned.
  5697. *
  5698. * Returns:
  5699. * A pointer to the zero terminated text representation of the prefix token.
  5700. * NULL in case of an error.
  5701. */
  5702. const char *
  5703. fy_tag_directive_token_prefix0(struct fy_token *fyt)
  5704. FY_EXPORT;
  5705. /**
  5706. * fy_tag_directive_token_handle0() - Get the handle contained in the
  5707. * tag directive token as zero terminated
  5708. * string
  5709. *
  5710. * Retrieve the tag directive's handle contents as a zero terminated string.
  5711. * It is similar to fy_tag_directive_token_handle(), with the difference
  5712. * that the returned string is zero terminated and memory may be allocated
  5713. * to hold it associated with the token.
  5714. *
  5715. * @fyt: The tag directive token out of which the handle pointer
  5716. * will be returned.
  5717. *
  5718. * Returns:
  5719. * A pointer to the zero terminated text representation of the handle token.
  5720. * NULL in case of an error.
  5721. */
  5722. const char *
  5723. fy_tag_directive_token_handle0(struct fy_token *fyt)
  5724. FY_EXPORT;
  5725. /**
  5726. * fy_tag_token_handle() - Get the handle contained in the
  5727. * tag token
  5728. *
  5729. * Retrieve the tag handle contents. Will fail if
  5730. * token is not a tag token, or if a memory error happens.
  5731. *
  5732. * @fyt: The tag token out of which the handle pointer
  5733. * will be returned.
  5734. * @lenp: Pointer to a variable that will hold the returned length
  5735. *
  5736. * Returns:
  5737. * A pointer to the text representation of the handle token, while
  5738. * @lenp will be assigned the character length of said representation.
  5739. * NULL in case of an error.
  5740. */
  5741. const char *
  5742. fy_tag_token_handle(struct fy_token *fyt, size_t *lenp)
  5743. FY_EXPORT;
  5744. /**
  5745. * fy_tag_token_suffix() - Get the suffix contained in the
  5746. * tag token
  5747. *
  5748. * Retrieve the tag suffix contents. Will fail if
  5749. * token is not a tag token, or if a memory error happens.
  5750. *
  5751. * @fyt: The tag token out of which the suffix pointer
  5752. * will be returned.
  5753. * @lenp: Pointer to a variable that will hold the returned length
  5754. *
  5755. * Returns:
  5756. * A pointer to the text representation of the suffix token, while
  5757. * @lenp will be assigned the character length of said representation.
  5758. * NULL in case of an error.
  5759. */
  5760. const char *
  5761. fy_tag_token_suffix(struct fy_token *fyt, size_t *lenp)
  5762. FY_EXPORT;
  5763. /**
  5764. * fy_tag_token_handle0() - Get the handle contained in the
  5765. * tag token as zero terminated string
  5766. *
  5767. * Retrieve the tag handle contents as a zero terminated string.
  5768. * It is similar to fy_tag_token_handle(), with the difference
  5769. * that the returned string is zero terminated and memory may be allocated
  5770. * to hold it associated with the token.
  5771. *
  5772. * @fyt: The tag token out of which the handle pointer will be returned.
  5773. *
  5774. * Returns:
  5775. * A pointer to the zero terminated text representation of the handle token.
  5776. * NULL in case of an error.
  5777. */
  5778. const char *
  5779. fy_tag_token_handle0(struct fy_token *fyt)
  5780. FY_EXPORT;
  5781. /**
  5782. * fy_tag_token_suffix0() - Get the suffix contained in the
  5783. * tag token as zero terminated string
  5784. *
  5785. * Retrieve the tag suffix contents as a zero terminated string.
  5786. * It is similar to fy_tag_token_suffix(), with the difference
  5787. * that the returned string is zero terminated and memory may be allocated
  5788. * to hold it associated with the token.
  5789. *
  5790. * @fyt: The tag token out of which the suffix pointer will be returned.
  5791. *
  5792. * Returns:
  5793. * A pointer to the zero terminated text representation of the suffix token.
  5794. * NULL in case of an error.
  5795. */
  5796. const char *
  5797. fy_tag_token_suffix0(struct fy_token *fyt)
  5798. FY_EXPORT;
  5799. /**
  5800. * fy_version_directive_token_version() - Return the version of a version
  5801. * directive token
  5802. *
  5803. * Retrieve the version stored in a version directive token.
  5804. *
  5805. * @fyt: The version directive token
  5806. *
  5807. * Returns:
  5808. * A pointer to the version stored in the version directive token, or
  5809. * NULL in case of an error, or the token not being a version directive token.
  5810. */
  5811. const struct fy_version *
  5812. fy_version_directive_token_version(struct fy_token *fyt)
  5813. FY_EXPORT;
  5814. /**
  5815. * fy_scalar_token_get_style() - Return the style of a scalar token
  5816. *
  5817. * Retrieve the style of a scalar token.
  5818. *
  5819. * @fyt: The scalar token
  5820. *
  5821. * Returns:
  5822. * The scalar style of the token, or FYSS_ANY for an error
  5823. */
  5824. enum fy_scalar_style
  5825. fy_scalar_token_get_style(struct fy_token *fyt)
  5826. FY_EXPORT;
  5827. /**
  5828. * fy_tag_token_tag() - Get tag of a tag token
  5829. *
  5830. * Retrieve the tag of a tag token.
  5831. *
  5832. * @fyt: The tag token
  5833. *
  5834. * Returns:
  5835. * A pointer to the tag or NULL in case of an error
  5836. */
  5837. const struct fy_tag *
  5838. fy_tag_token_tag(struct fy_token *fyt)
  5839. FY_EXPORT;
  5840. /**
  5841. * fy_tag_directive_token_tag() - Get tag of a tag directive token
  5842. *
  5843. * Retrieve the tag of a tag directive token.
  5844. *
  5845. * @fyt: The tag directive token
  5846. *
  5847. * Returns:
  5848. * A pointer to the tag or NULL in case of an error
  5849. */
  5850. const struct fy_tag *
  5851. fy_tag_directive_token_tag(struct fy_token *fyt)
  5852. FY_EXPORT;
  5853. /**
  5854. * fy_event_get_token() - Return the main token of an event
  5855. *
  5856. * Retrieve the main token (i.e. not the tag or the anchor) of
  5857. * an event. It may be NULL in case of an implicit event.
  5858. *
  5859. * @fye: The event to get its main token
  5860. *
  5861. * Returns:
  5862. * The main token if it exists, NULL otherwise or in case of an error
  5863. */
  5864. struct fy_token *
  5865. fy_event_get_token(struct fy_event *fye)
  5866. FY_EXPORT;
  5867. /**
  5868. * fy_event_get_anchor_token() - Return the anchor token of an event
  5869. *
  5870. * Retrieve the anchor token if it exists. Only valid for
  5871. * mapping/sequence start and scalar events.
  5872. *
  5873. * @fye: The event to get its anchor token
  5874. *
  5875. * Returns:
  5876. * The anchor token if it exists, NULL otherwise or in case of an error
  5877. */
  5878. struct fy_token *
  5879. fy_event_get_anchor_token(struct fy_event *fye)
  5880. FY_EXPORT;
  5881. /**
  5882. * fy_event_get_tag_token() - Return the tag token of an event
  5883. *
  5884. * Retrieve the tag token if it exists. Only valid for
  5885. * mapping/sequence start and scalar events.
  5886. *
  5887. * @fye: The event to get its tag token
  5888. *
  5889. * Returns:
  5890. * The tag token if it exists, NULL otherwise or in case of an error
  5891. */
  5892. struct fy_token *
  5893. fy_event_get_tag_token(struct fy_event *fye)
  5894. FY_EXPORT;
  5895. /**
  5896. * fy_event_start_mark() - Get event's start marker
  5897. *
  5898. * Return the event's start marker if it exists. The
  5899. * start marker is the one of the event's main token.
  5900. *
  5901. * @fye: The event to get its start marker
  5902. *
  5903. * Returns:
  5904. * The event's start marker, NULL if not available.
  5905. */
  5906. const struct fy_mark *
  5907. fy_event_start_mark(struct fy_event *fye)
  5908. FY_EXPORT;
  5909. /**
  5910. * fy_event_end_mark() - Get event's end marker
  5911. *
  5912. * Return the event's end marker if it exists. The
  5913. * end marker is the one of the event's main token.
  5914. *
  5915. * @fye: The event to get its end marker
  5916. *
  5917. * Returns:
  5918. * The event's end marker, NULL if not available.
  5919. */
  5920. const struct fy_mark *
  5921. fy_event_end_mark(struct fy_event *fye)
  5922. FY_EXPORT;
  5923. /**
  5924. * fy_event_get_node_style() - Get the node style of an event
  5925. *
  5926. * Return the node style (FYNS_*) of an event. May return
  5927. * FYNS_ANY if the event is implicit.
  5928. * For collection start events the only possible values is
  5929. * FYNS_ANY, FYNS_FLOW, FYNS_BLOCK.
  5930. * A scalar event may return any.
  5931. *
  5932. * @fye: The event to get it's node style
  5933. *
  5934. * Returns:
  5935. * The event's end marker, NULL if not available.
  5936. */
  5937. enum fy_node_style
  5938. fy_event_get_node_style(struct fy_event *fye)
  5939. FY_EXPORT;
  5940. /**
  5941. * fy_document_start_event_version() - Return the version of a document
  5942. * start event
  5943. *
  5944. * Retrieve the version stored in a document start event
  5945. *
  5946. * @fye: The document start event
  5947. *
  5948. * Returns:
  5949. * A pointer to the version, or NULL in case of an error, or the event
  5950. * not being a document start event.
  5951. */
  5952. const struct fy_version *
  5953. fy_document_start_event_version(struct fy_event *fye)
  5954. FY_EXPORT;
  5955. /**
  5956. * fy_document_state_version() - Return the version of a document state
  5957. * object
  5958. *
  5959. * Retrieve the version stored in a document state object
  5960. *
  5961. * @fyds: The document state object
  5962. *
  5963. * Returns:
  5964. * A pointer to the version, or NULL in case of an error
  5965. */
  5966. const struct fy_version *
  5967. fy_document_state_version(struct fy_document_state *fyds)
  5968. FY_EXPORT;
  5969. /**
  5970. * fy_document_state_start_mark() - Get document state's start mark
  5971. *
  5972. * Return the document state's start mark (if it exists).
  5973. * Note that purely synthetic documents do not contain one
  5974. *
  5975. * @fyds: The document state object
  5976. *
  5977. * Returns:
  5978. * The document's start marker, NULL if not available.
  5979. */
  5980. const struct fy_mark *
  5981. fy_document_state_start_mark(struct fy_document_state *fyds)
  5982. FY_EXPORT;
  5983. /**
  5984. * fy_document_state_end_mark() - Get document state's end mark
  5985. *
  5986. * Return the document state's end mark (if it exists).
  5987. * Note that purely synthetic documents do not contain one
  5988. *
  5989. * @fyds: The document state object
  5990. *
  5991. * Returns:
  5992. * The document's end marker, NULL if not available.
  5993. */
  5994. const struct fy_mark *
  5995. fy_document_state_end_mark(struct fy_document_state *fyds)
  5996. FY_EXPORT;
  5997. /**
  5998. * fy_document_state_version_explicit() - Version explicit?
  5999. *
  6000. * Find out if a document state object's version was explicitly
  6001. * set in the document.
  6002. * Note that for synthetic documents this method returns false.
  6003. *
  6004. * @fyds: The document state object
  6005. *
  6006. * Returns:
  6007. * true if version was set explicitly, false otherwise
  6008. */
  6009. bool
  6010. fy_document_state_version_explicit(struct fy_document_state *fyds)
  6011. FY_EXPORT;
  6012. /**
  6013. * fy_document_state_tags_explicit() - Tags explicit?
  6014. *
  6015. * Find out if a document state object's tags were explicitly
  6016. * set in the document.
  6017. * Note that for synthetic documents this method returns false.
  6018. *
  6019. * @fyds: The document state object
  6020. *
  6021. * Returns:
  6022. * true if document had tags set explicitly, false otherwise
  6023. */
  6024. bool
  6025. fy_document_state_tags_explicit(struct fy_document_state *fyds)
  6026. FY_EXPORT;
  6027. /**
  6028. * fy_document_state_start_implicit() - Started implicitly?
  6029. *
  6030. * Find out if a document state object's document was
  6031. * started implicitly.
  6032. * Note that for synthetic documents this method returns false.
  6033. *
  6034. * @fyds: The document state object
  6035. *
  6036. * Returns:
  6037. * true if document was started implicitly, false otherwise
  6038. */
  6039. bool
  6040. fy_document_state_start_implicit(struct fy_document_state *fyds)
  6041. FY_EXPORT;
  6042. /**
  6043. * fy_document_state_end_implicit() - Started implicitly?
  6044. *
  6045. * Find out if a document state object's document was
  6046. * ended implicitly.
  6047. * Note that for synthetic documents this method returns false.
  6048. *
  6049. * @fyds: The document state object
  6050. *
  6051. * Returns:
  6052. * true if document was ended implicitly, false otherwise
  6053. */
  6054. bool
  6055. fy_document_state_end_implicit(struct fy_document_state *fyds)
  6056. FY_EXPORT;
  6057. /**
  6058. * fy_document_state_json_mode() - Input was JSON?
  6059. *
  6060. * Find out if a document state object's document was
  6061. * created by a JSON input.
  6062. * Note that for synthetic documents this method returns false.
  6063. *
  6064. * @fyds: The document state object
  6065. *
  6066. * Returns:
  6067. * true if document was created in JSON mode, false otherwise
  6068. */
  6069. bool
  6070. fy_document_state_json_mode(struct fy_document_state *fyds)
  6071. FY_EXPORT;
  6072. /**
  6073. * fy_document_state_tag_directive_iterate() - Iterate over the tag
  6074. * directives of a document state
  6075. * object
  6076. *
  6077. * This method iterates over all the tag directives nodes in the document state
  6078. * object.
  6079. * The start of the iteration is signalled by a NULL in \*prevp.
  6080. *
  6081. * @fyds: The document state
  6082. * @prevp: The previous iterator
  6083. *
  6084. * Returns:
  6085. * The next tag or NULL at the end of the iteration sequence.
  6086. */
  6087. const struct fy_tag *
  6088. fy_document_state_tag_directive_iterate(struct fy_document_state *fyds, void **prevp)
  6089. FY_EXPORT;
  6090. /**
  6091. * fy_document_state_tag_is_default() - Test whether the given tag is a default one
  6092. *
  6093. * Test whether a tag is a default (i.e. impliciticly set)
  6094. *
  6095. * @fyds: The document state
  6096. * @tag: The tag to check
  6097. *
  6098. * Returns:
  6099. * true in case that the tag is a default one, false otherwise
  6100. */
  6101. bool
  6102. fy_document_state_tag_is_default(struct fy_document_state *fyds, const struct fy_tag *tag)
  6103. FY_EXPORT;
  6104. /**
  6105. * fy_parser_get_document_state() - Get the document state of a parser object
  6106. *
  6107. * Retrieve the document state object of a parser. Note that this is only
  6108. * valid during parsing.
  6109. *
  6110. * @fyp: The parser
  6111. *
  6112. * Returns:
  6113. * The active document state object of the parser, NULL otherwise
  6114. */
  6115. struct fy_document_state *
  6116. fy_parser_get_document_state(struct fy_parser *fyp)
  6117. FY_EXPORT;
  6118. /**
  6119. * fy_document_get_document_state() - Get the document state of a document
  6120. *
  6121. * Retrieve the document state object of a document.
  6122. *
  6123. * @fyd: The document
  6124. *
  6125. * Returns:
  6126. * The document state object of the document, NULL otherwise
  6127. */
  6128. struct fy_document_state *
  6129. fy_document_get_document_state(struct fy_document *fyd)
  6130. FY_EXPORT;
  6131. /**
  6132. * fy_document_set_document_state() - Set the document state of a document
  6133. *
  6134. * Set the document state of a document
  6135. *
  6136. * @fyd: The document
  6137. * @fyds: The document state to use, or NULL for default
  6138. *
  6139. * Returns:
  6140. * 0 if set operation was successful, -1 otherwise
  6141. */
  6142. int
  6143. fy_document_set_document_state(struct fy_document *fyd, struct fy_document_state *fyds)
  6144. FY_EXPORT;
  6145. /**
  6146. * fy_document_create_from_event() - Create an empty document using the event
  6147. *
  6148. * Create an empty document using the FYET_DOCUMENT_START event generated
  6149. * by the parser.
  6150. *
  6151. * @fyp: The parser
  6152. * @fye: The event
  6153. *
  6154. * Returns:
  6155. * The created empty document, or NULL on error.
  6156. */
  6157. struct fy_document *
  6158. fy_document_create_from_event(struct fy_parser *fyp, struct fy_event *fye)
  6159. FY_EXPORT;
  6160. /**
  6161. * fy_document_update_from_event() - Update the document with the event
  6162. *
  6163. * Update the document using the FYET_DOCUMENT_END event generated
  6164. * by the parser.
  6165. *
  6166. * @fyd: The document
  6167. * @fyp: The parser
  6168. * @fye: The event
  6169. *
  6170. * Returns:
  6171. * 0 on success, -1 on error
  6172. */
  6173. int
  6174. fy_document_update_from_event(struct fy_document *fyd, struct fy_parser *fyp, struct fy_event *fye)
  6175. FY_EXPORT;
  6176. /**
  6177. * fy_node_create_from_event() - Create a node using the event
  6178. *
  6179. * Create a new node using the supplied event.
  6180. * Allowed events are FYET_SCALAR, FYET_ALIAS, FYET_MAPPING_START & FYET_SEQUENCE_START
  6181. *
  6182. * @fyd: The document
  6183. * @fyp: The parser
  6184. * @fye: The event
  6185. *
  6186. * Returns:
  6187. * The newly created node, or NULL on error
  6188. */
  6189. struct fy_node *
  6190. fy_node_create_from_event(struct fy_document *fyd, struct fy_parser *fyp, struct fy_event *fye)
  6191. FY_EXPORT;
  6192. /**
  6193. * fy_node_update_from_event() - Update a node using the event
  6194. *
  6195. * Update information of node created using fy_node_create_from_event()
  6196. * Allowed events are FYET_MAPPING_END & FYET_SEQUENCE_END
  6197. *
  6198. * @fyn: The node
  6199. * @fyp: The parser
  6200. * @fye: The event
  6201. *
  6202. * Returns:
  6203. * 0 on success, -1 on error
  6204. */
  6205. int
  6206. fy_node_update_from_event(struct fy_node *fyn, struct fy_parser *fyp, struct fy_event *fye)
  6207. FY_EXPORT;
  6208. /**
  6209. * fy_node_pair_create_with_key() - Create a new node pair and set it's key
  6210. *
  6211. * Create a new node pair using the supplied fyn_parent mapping and fyn node as
  6212. * a key. Note that the nodes _must_ have been created by fy_node_create_from_event
  6213. * and they are not interchangeable with other node pair methods.
  6214. *
  6215. * The node pair will be added to the fyn_parent mapping with a subsequent call
  6216. * to fy_node_pair_update_with_value().
  6217. *
  6218. * @fyd: The document
  6219. * @fyn_parent: The mapping
  6220. * @fyn: The node pair key
  6221. *
  6222. * Returns:
  6223. * The newly created node pair, or NULL on error
  6224. */
  6225. struct fy_node_pair *
  6226. fy_node_pair_create_with_key(struct fy_document *fyd, struct fy_node *fyn_parent, struct fy_node *fyn)
  6227. FY_EXPORT;
  6228. /**
  6229. * fy_node_pair_update_with_value() - Update a node pair with a value and add it to the parent mapping
  6230. *
  6231. * Update the node pair with the given value and add it to the parent mapping.
  6232. * Note that the fyn node _must_ have been created by fy_node_create_from_event
  6233. * and the node pair created by fy_node_pair_create_with_key().
  6234. * Do not intermix other node pair manipulation methods.
  6235. *
  6236. * @fynp: The node pair
  6237. * @fyn: The node pair value
  6238. *
  6239. * Returns:
  6240. * 0 on success, -1 on error
  6241. */
  6242. int
  6243. fy_node_pair_update_with_value(struct fy_node_pair *fynp, struct fy_node *fyn)
  6244. FY_EXPORT;
  6245. /**
  6246. * fy_node_sequence_add_item() - Add an item node to a sequence node
  6247. *
  6248. * Add an item to the end of the sequence node fyn_parent.
  6249. * Note that the fyn_parent and fyn nodes _must_ have been created by
  6250. * fy_node_create_from_event.
  6251. * Do not intermix other sequence node manipulation methods.
  6252. *
  6253. * @fyn_parent: The parent sequence node
  6254. * @fyn: The node pair item
  6255. *
  6256. * Returns:
  6257. * 0 on success, -1 on error
  6258. */
  6259. int
  6260. fy_node_sequence_add_item(struct fy_node *fyn_parent, struct fy_node *fyn)
  6261. FY_EXPORT;
  6262. /**
  6263. * fy_emitter_get_document_state() - Get the document state of an emitter object
  6264. *
  6265. * Retrieve the document state object of an emitter. Note that this is only
  6266. * valid during emitting.
  6267. *
  6268. * @emit: The emitter
  6269. *
  6270. * Returns:
  6271. * The active document state object of the emitter, NULL otherwise
  6272. */
  6273. struct fy_document_state *
  6274. fy_emitter_get_document_state(struct fy_emitter *emit)
  6275. FY_EXPORT;
  6276. /**
  6277. * fy_emit_event_create() - Create an emit event.
  6278. *
  6279. * Create an emit event to pass to fy_emit_event()
  6280. * The extra arguments differ according to the event to be created
  6281. *
  6282. * FYET_STREAM_START:
  6283. * - None
  6284. *
  6285. * FYET_STREAM_END:
  6286. * - None
  6287. *
  6288. * FYET_DOCUMENT_START:
  6289. * - int implicit
  6290. * true if document start should be marked implicit
  6291. * false if document start should not be marked implicit
  6292. * - const struct fy_version \*vers
  6293. * Pointer to version to use for the document, or NULL for default
  6294. * - const struct fy_tag \* const \*tags
  6295. * Pointer to a NULL terminated array of tag pointers (like argv)
  6296. * NULL if no extra tags are to be used
  6297. *
  6298. * FYET_DOCUMENT_END:
  6299. * - int implicit
  6300. * true if document end should be marked implicit
  6301. * false if document end should not be marked implicit
  6302. *
  6303. * FYET_MAPPING_START:
  6304. * - enum fy_node_style style
  6305. * Style of the mapping (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
  6306. * - const char \*anchor
  6307. * Anchor to place at the mapping, or NULL for none
  6308. * - const char \*tag
  6309. * Tag to place at the mapping, or NULL for none
  6310. *
  6311. * FYET_MAPPING_END:
  6312. * - None
  6313. *
  6314. * FYET_SEQUENCE_START:
  6315. * - enum fy_node_style style
  6316. * Style of the sequence (one of FYNS_ANY, FYNS_BLOCK or FYNS_FLOW)
  6317. * - const char \*anchor
  6318. * Anchor to place at the sequence, or NULL for none
  6319. * - const char \*tag
  6320. * Tag to place at the sequence, or NULL for none
  6321. *
  6322. * FYET_SEQUENCE_END:
  6323. * - None
  6324. *
  6325. * FYET_SCALAR:
  6326. * - enum fy_scalar_style style
  6327. * Style of the scalar, any valid FYSS_* value
  6328. * Note that certain styles may not be used according to the
  6329. * contents of the data
  6330. * - const char \*value
  6331. * Pointer to the scalar contents.
  6332. * - size_t len
  6333. * Length of the scalar contents, of FY_NT (-1) for strlen(value)
  6334. * - const char \*anchor
  6335. * Anchor to place at the scalar, or NULL for none
  6336. * - const char \*tag
  6337. * Tag to place at the scalar, or NULL for none
  6338. *
  6339. * FYET_ALIAS:
  6340. * - const char \*value
  6341. * Pointer to the alias.
  6342. *
  6343. * @emit: The emitter
  6344. * @type: The event type to create
  6345. *
  6346. * Returns:
  6347. * The created event or NULL in case of an error
  6348. */
  6349. struct fy_event *
  6350. fy_emit_event_create(struct fy_emitter *emit, enum fy_event_type type, ...)
  6351. FY_EXPORT;
  6352. /**
  6353. * fy_emit_event_vcreate() - Create an emit event using varargs.
  6354. *
  6355. * Create an emit event to pass to fy_emit_event()
  6356. * The varargs analogous to fy_emit_event_create().
  6357. *
  6358. * @emit: The emitter
  6359. * @type: The event type to create
  6360. * @ap: The variable argument list pointer.
  6361. *
  6362. * Returns:
  6363. * The created event or NULL in case of an error
  6364. */
  6365. struct fy_event *
  6366. fy_emit_event_vcreate(struct fy_emitter *emit, enum fy_event_type type, va_list ap)
  6367. FY_EXPORT;
  6368. /**
  6369. * fy_emit_event_free() - Free an event created via fy_emit_event_create()
  6370. *
  6371. * Free an event previously created via fy_emit_event_create(). Note
  6372. * that usually you don't have to call this method since if you pass
  6373. * the event to fy_emit_event() it shall be disposed properly.
  6374. * Only use is error recovery and cleanup.
  6375. *
  6376. * @emit: The emitter
  6377. * @fye: The event to free
  6378. */
  6379. void
  6380. fy_emit_event_free(struct fy_emitter *emit, struct fy_event *fye)
  6381. FY_EXPORT;
  6382. /**
  6383. * fy_parse_event_create() - Create an emit event.
  6384. *
  6385. * See fy_emit_event_create()...
  6386. *
  6387. * @fyp: The parser
  6388. * @type: The event type to create
  6389. *
  6390. * Returns:
  6391. * The created event or NULL in case of an error
  6392. */
  6393. struct fy_event *
  6394. fy_parse_event_create(struct fy_parser *fyp, enum fy_event_type type, ...)
  6395. FY_EXPORT;
  6396. /**
  6397. * fy_parse_event_vcreate() - Create an emit event using varargs.
  6398. *
  6399. * Create an emit event to pass to fy_emit_event()
  6400. * The varargs analogous to fy_parse_event_create().
  6401. *
  6402. * @fyp: The parser
  6403. * @type: The event type to create
  6404. * @ap: The variable argument list pointer.
  6405. *
  6406. * Returns:
  6407. * The created event or NULL in case of an error
  6408. */
  6409. struct fy_event *
  6410. fy_parse_event_vcreate(struct fy_parser *fyp, enum fy_event_type type, va_list ap)
  6411. FY_EXPORT;
  6412. /**
  6413. * enum fy_composer_return - The returns of the composer callback
  6414. *
  6415. * @FYCR_OK_CONTINUE: continue processing, event processed
  6416. * @FYCR_OK_STOP: stop processing, event processed
  6417. * @FYCR_OK_START_SKIP: start skip object(s), event processed
  6418. * @FYCR_OK_STOP_SKIP: stop skipping of objects, event processed
  6419. * @FYCR_ERROR: error, stop processing
  6420. */
  6421. enum fy_composer_return {
  6422. FYCR_OK_CONTINUE = 0,
  6423. FYCR_OK_STOP = 1,
  6424. FYCR_OK_START_SKIP = 2,
  6425. FYCR_OK_STOP_SKIP = 3,
  6426. FYCR_ERROR = -1,
  6427. };
  6428. /**
  6429. * fy_composer_return_is_ok() - Check if the return code is OK
  6430. *
  6431. * Convenience method for checking if it's OK to continue
  6432. *
  6433. * @ret: the composer return to check
  6434. *
  6435. * Returns:
  6436. * true if non error or skip condition
  6437. */
  6438. static inline bool
  6439. fy_composer_return_is_ok(enum fy_composer_return ret)
  6440. {
  6441. return ret == FYCR_OK_CONTINUE || ret == FYCR_OK_STOP;
  6442. }
  6443. /**
  6444. * typedef fy_parse_composer_cb - composer callback method
  6445. *
  6446. * This method is called by the fy_parse_compose() method
  6447. * when an event must be processed.
  6448. *
  6449. * @fyp: The parser
  6450. * @fye: The event
  6451. * @path: The path that the parser is processing
  6452. * @userdata: The user data of the fy_parse_compose() method
  6453. *
  6454. * Returns:
  6455. * fy_composer_return code telling the parser what to do
  6456. */
  6457. typedef enum fy_composer_return
  6458. (*fy_parse_composer_cb)(struct fy_parser *fyp, struct fy_event *fye,
  6459. struct fy_path *path, void *userdata);
  6460. /**
  6461. * fy_parse_compose() - Parse using a compose callback
  6462. *
  6463. * Alternative parsing method using a composer callback.
  6464. *
  6465. * The parser will construct a path argument that is used
  6466. * by the callback to make intelligent decisions about
  6467. * creating a document and/or DOM.
  6468. *
  6469. * @fyp: The parser
  6470. * @cb: The callback that will be called
  6471. * @userdata: user pointer to pass to the callback
  6472. *
  6473. * Returns:
  6474. * 0 if no error occured
  6475. * -1 on error
  6476. */
  6477. int
  6478. fy_parse_compose(struct fy_parser *fyp, fy_parse_composer_cb cb,
  6479. void *userdata)
  6480. FY_EXPORT;
  6481. /**
  6482. * fy_path_component_is_mapping() - Check if the component is a mapping
  6483. *
  6484. * @fypc: The path component to check
  6485. *
  6486. * Returns:
  6487. * true if the path component is a mapping, false otherwise
  6488. */
  6489. bool
  6490. fy_path_component_is_mapping(struct fy_path_component *fypc)
  6491. FY_EXPORT;
  6492. /**
  6493. * fy_path_component_is_sequence() - Check if the component is a sequence
  6494. *
  6495. * @fypc: The path component to check
  6496. *
  6497. * Returns:
  6498. * true if the path component is a sequence, false otherwise
  6499. */
  6500. bool
  6501. fy_path_component_is_sequence(struct fy_path_component *fypc)
  6502. FY_EXPORT;
  6503. /**
  6504. * fy_path_component_sequence_get_index() - Get the index of sequence path component
  6505. *
  6506. * @fypc: The sequence path component to return it's index value
  6507. *
  6508. * Returns:
  6509. * >= 0 the sequence index
  6510. * -1 if the component is either not in the proper mode, or not a sequence
  6511. */
  6512. int
  6513. fy_path_component_sequence_get_index(struct fy_path_component *fypc)
  6514. FY_EXPORT;
  6515. /**
  6516. * fy_path_component_mapping_get_scalar_key() - Get the scalar key of a mapping
  6517. *
  6518. * @fypc: The mapping path component to return it's scalar key
  6519. *
  6520. * Returns:
  6521. * a non NULL scalar or alias token if the mapping contains a scalar key
  6522. * NULL in case of an error, or if the component has a complex key
  6523. */
  6524. struct fy_token *
  6525. fy_path_component_mapping_get_scalar_key(struct fy_path_component *fypc)
  6526. FY_EXPORT;
  6527. /**
  6528. * fy_path_component_mapping_get_scalar_key_tag() - Get the scalar key's tag of a mapping
  6529. *
  6530. * @fypc: The mapping path component to return it's scalar key's tag
  6531. *
  6532. * Returns:
  6533. * a non NULL tag token if the mapping contains a scalar key with a tag or
  6534. * NULL in case of an error, or if the component has a complex key
  6535. */
  6536. struct fy_token *
  6537. fy_path_component_mapping_get_scalar_key_tag(struct fy_path_component *fypc)
  6538. FY_EXPORT;
  6539. /**
  6540. * fy_path_component_mapping_get_complex_key() - Get the complex key of a mapping
  6541. *
  6542. * @fypc: The mapping path component to return it's complex key
  6543. *
  6544. * Returns:
  6545. * a non NULL document if the mapping contains a complex key
  6546. * NULL in case of an error, or if the component has a simple key
  6547. */
  6548. struct fy_document *
  6549. fy_path_component_mapping_get_complex_key(struct fy_path_component *fypc)
  6550. FY_EXPORT;
  6551. /**
  6552. * fy_path_component_get_text() - Get the textual representation of a path component
  6553. *
  6554. * Given a path component, return a malloc'ed string which contains
  6555. * the textual representation of it.
  6556. *
  6557. * Note that this method will only return fully completed components and not
  6558. * ones that are in the building process.
  6559. *
  6560. * @fypc: The path component to get it's textual representation
  6561. *
  6562. * Returns:
  6563. * The textual representation of the path component, NULL on error, or
  6564. * if the component has not been completely built during the composition
  6565. * of a complex key.
  6566. * The string must be free'ed using free.
  6567. */
  6568. char *
  6569. fy_path_component_get_text(struct fy_path_component *fypc)
  6570. FY_EXPORT;
  6571. #define fy_path_component_get_text_alloca(_fypc, _res) \
  6572. FY_ALLOCA_COPY_FREE(fy_path_component_get_text((_fypc)), FY_NT, (_res))
  6573. /**
  6574. * fy_path_depth() - Get the depth of a path
  6575. *
  6576. * @fypp: The path to query
  6577. *
  6578. * Returns:
  6579. * The depth of the path, or -1 on error
  6580. */
  6581. int
  6582. fy_path_depth(struct fy_path *fypp)
  6583. FY_EXPORT;
  6584. /**
  6585. * fy_path_parent() - Get the parent of a path
  6586. *
  6587. * Paths may contain parents when traversing complex keys.
  6588. * This method returns the immediate parent.
  6589. *
  6590. * @fypp: The path to return it's parent
  6591. *
  6592. * Returns:
  6593. * The path parent or NULL on error, if it doesn't exist
  6594. */
  6595. struct fy_path *
  6596. fy_path_parent(struct fy_path *fypp)
  6597. FY_EXPORT;
  6598. /**
  6599. * fy_path_get_text() - Get the textual representation of a path
  6600. *
  6601. * Given a path, return a malloc'ed string which contains
  6602. * the textual representation of it.
  6603. *
  6604. * Note that during processing, complex key paths are simply
  6605. * indicative and not to be used for addressing.
  6606. *
  6607. * @fypp: The path to get it's textual representation
  6608. *
  6609. * Returns:
  6610. * The textual representation of the path, NULL on error.
  6611. * The string must be free'ed using free.
  6612. */
  6613. char *
  6614. fy_path_get_text(struct fy_path *fypp)
  6615. FY_EXPORT;
  6616. #define fy_path_get_text_alloca(_fypp, _res) \
  6617. FY_ALLOCA_COPY_FREE(fy_path_get_text((_fypp)), FY_NT, (_res))
  6618. /**
  6619. * fy_path_in_root() - Check if the path is in the root of the document
  6620. *
  6621. * @fypp: The path
  6622. *
  6623. * Returns:
  6624. * true if the path is located within the root of the document
  6625. */
  6626. bool
  6627. fy_path_in_root(struct fy_path *fypp)
  6628. FY_EXPORT;
  6629. /**
  6630. * fy_path_in_mapping() - Check if the path is in a mapping
  6631. *
  6632. * @fypp: The path
  6633. *
  6634. * Returns:
  6635. * true if the path is located within a mapping
  6636. */
  6637. bool
  6638. fy_path_in_mapping(struct fy_path *fypp)
  6639. FY_EXPORT;
  6640. /**
  6641. * fy_path_in_sequence() - Check if the path is in a sequence
  6642. *
  6643. * @fypp: The path
  6644. *
  6645. * Returns:
  6646. * true if the path is located within a sequence
  6647. */
  6648. bool
  6649. fy_path_in_sequence(struct fy_path *fypp)
  6650. FY_EXPORT;
  6651. /**
  6652. * fy_path_in_mapping_key() - Check if the path is in a mapping key state
  6653. *
  6654. * @fypp: The path
  6655. *
  6656. * Returns:
  6657. * true if the path is located within a mapping key state
  6658. */
  6659. bool
  6660. fy_path_in_mapping_key(struct fy_path *fypp)
  6661. FY_EXPORT;
  6662. /**
  6663. * fy_path_in_mapping_value() - Check if the path is in a mapping value state
  6664. *
  6665. * @fypp: The path
  6666. *
  6667. * Returns:
  6668. * true if the path is located within a mapping value state
  6669. */
  6670. bool
  6671. fy_path_in_mapping_value(struct fy_path *fypp)
  6672. FY_EXPORT;
  6673. /**
  6674. * fy_path_in_collection_root() - Check if the path is in a collection root
  6675. *
  6676. * A collection root state is when the path points to a sequence or mapping
  6677. * but the state does not allow setting keys, values or adding items.
  6678. *
  6679. * This occurs on MAPPING/SEQUENCE START/END events.
  6680. *
  6681. * @fypp: The path
  6682. *
  6683. * Returns:
  6684. * true if the path is located within a collectin root state
  6685. */
  6686. bool
  6687. fy_path_in_collection_root(struct fy_path *fypp)
  6688. FY_EXPORT;
  6689. /**
  6690. * fy_path_get_root_user_data() - Return the userdata associated with the path root
  6691. *
  6692. * @fypp: The path
  6693. *
  6694. * Returns:
  6695. * The user data associated with the root of the path, or NULL if no path
  6696. */
  6697. void *
  6698. fy_path_get_root_user_data(struct fy_path *fypp)
  6699. FY_EXPORT;
  6700. /**
  6701. * fy_path_set_root_user_data() - Set the user data associated with the root
  6702. *
  6703. * Note, no error condition if not a path
  6704. *
  6705. * @fypp: The path
  6706. * @data: The data to set as root data
  6707. */
  6708. void
  6709. fy_path_set_root_user_data(struct fy_path *fypp, void *data)
  6710. FY_EXPORT;
  6711. /**
  6712. * fy_path_component_get_mapping_user_data() - Return the userdata associated with the mapping
  6713. *
  6714. * @fypc: The path component
  6715. *
  6716. * Returns:
  6717. * The user data associated with the mapping, or NULL if not a mapping or the user data are NULL
  6718. */
  6719. void *
  6720. fy_path_component_get_mapping_user_data(struct fy_path_component *fypc)
  6721. FY_EXPORT;
  6722. /**
  6723. * fy_path_component_get_mapping_key_user_data() - Return the userdata associated with the mapping key
  6724. *
  6725. * @fypc: The path component
  6726. *
  6727. * Returns:
  6728. * The user data associated with the mapping key, or NULL if not a mapping or the user data are NULL
  6729. */
  6730. void *
  6731. fy_path_component_get_mapping_key_user_data(struct fy_path_component *fypc)
  6732. FY_EXPORT;
  6733. /**
  6734. * fy_path_component_get_sequence_user_data() - Return the userdata associated with the sequence
  6735. *
  6736. * @fypc: The path component
  6737. *
  6738. * Returns:
  6739. * The user data associated with the sequence, or NULL if not a sequence or the user data are NULL
  6740. */
  6741. void *
  6742. fy_path_component_get_sequence_user_data(struct fy_path_component *fypc)
  6743. FY_EXPORT;
  6744. /**
  6745. * fy_path_component_set_mapping_user_data() - Set the user data associated with a mapping
  6746. *
  6747. * Note, no error condition if not a mapping
  6748. *
  6749. * @fypc: The path component
  6750. * @data: The data to set as mapping data
  6751. */
  6752. void
  6753. fy_path_component_set_mapping_user_data(struct fy_path_component *fypc, void *data)
  6754. FY_EXPORT;
  6755. /**
  6756. * fy_path_component_set_mapping_key_user_data() - Set the user data associated with a mapping key
  6757. *
  6758. * Note, no error condition if not in a mapping key state
  6759. *
  6760. * @fypc: The path component
  6761. * @data: The data to set as mapping key data
  6762. */
  6763. void
  6764. fy_path_component_set_mapping_key_user_data(struct fy_path_component *fypc, void *data)
  6765. FY_EXPORT;
  6766. /**
  6767. * fy_path_component_set_sequence_user_data() - Set the user data associated with a sequence
  6768. *
  6769. * Note, no error condition if not a sequence
  6770. *
  6771. * @fypc: The path component
  6772. * @data: The data to set as sequence data
  6773. */
  6774. void
  6775. fy_path_component_set_sequence_user_data(struct fy_path_component *fypc, void *data)
  6776. FY_EXPORT;
  6777. /**
  6778. * fy_path_last_component() - Get the very last component of a path
  6779. *
  6780. * Returns the last component of a path.
  6781. *
  6782. * @fypp: The path
  6783. *
  6784. * Returns:
  6785. * The last path component (which may be a collection root component), or NULL
  6786. * if it does not exist
  6787. */
  6788. struct fy_path_component *
  6789. fy_path_last_component(struct fy_path *fypp)
  6790. FY_EXPORT;
  6791. /**
  6792. * fy_path_last_not_collection_root_component() - Get the last non collection root component of a path
  6793. *
  6794. * Returns the last non collection root component of a path. This may not be the
  6795. * last component that is returned by fy_path_last_component().
  6796. *
  6797. * The difference is present on MAPPING/SEQUENCE START/END events where the
  6798. * last component is present but not usuable as a object parent.
  6799. *
  6800. * @fypp: The path
  6801. *
  6802. * Returns:
  6803. * The last non collection root component, or NULL if it does not exist
  6804. */
  6805. struct fy_path_component *
  6806. fy_path_last_not_collection_root_component(struct fy_path *fypp)
  6807. FY_EXPORT;
  6808. /**
  6809. * fy_document_iterator_create() - Create a document iterator
  6810. *
  6811. * Creates a document iterator, that can trawl through a document
  6812. * without using recursion.
  6813. *
  6814. * Returns:
  6815. * The newly created document iterator or NULL on error
  6816. */
  6817. struct fy_document_iterator *
  6818. fy_document_iterator_create(void)
  6819. FY_EXPORT;
  6820. /**
  6821. * fy_document_iterator_destroy() - Destroy the given document iterator
  6822. *
  6823. * Destroy a document iterator created earlier via fy_document_iterator_create().
  6824. *
  6825. * @fydi: The document iterator to destroy
  6826. */
  6827. void
  6828. fy_document_iterator_destroy(struct fy_document_iterator *fydi)
  6829. FY_EXPORT;
  6830. /**
  6831. * fy_document_iterator_event_free() - Free an event that was created by a document iterator
  6832. *
  6833. * Free (possibly recycling) an event that was created by a document iterator.
  6834. *
  6835. * @fydi: The document iterator that created the event
  6836. * @fye: The event
  6837. */
  6838. void
  6839. fy_document_iterator_event_free(struct fy_document_iterator *fydi, struct fy_event *fye)
  6840. FY_EXPORT;
  6841. /**
  6842. * fy_document_iterator_stream_start() - Create a stream start event using the iterator
  6843. *
  6844. * Creates a stream start event on the document iterator and advances the internal state
  6845. * of it accordingly.
  6846. *
  6847. * @fydi: The document iterator to create the event
  6848. *
  6849. * Returns:
  6850. * The newly created stream start event, or NULL on error.
  6851. */
  6852. struct fy_event *
  6853. fy_document_iterator_stream_start(struct fy_document_iterator *fydi)
  6854. FY_EXPORT;
  6855. /**
  6856. * fy_document_iterator_stream_end() - Create a stream end event using the iterator
  6857. *
  6858. * Creates a stream end event on the document iterator and advances the internal state
  6859. * of it accordingly.
  6860. *
  6861. * @fydi: The document iterator to create the event
  6862. *
  6863. * Returns:
  6864. * The newly created stream end event, or NULL on error.
  6865. */
  6866. struct fy_event *
  6867. fy_document_iterator_stream_end(struct fy_document_iterator *fydi)
  6868. FY_EXPORT;
  6869. /**
  6870. * fy_document_iterator_document_start() - Create a document start event using the iterator
  6871. *
  6872. * Creates a document start event on the document iterator and advances the internal state
  6873. * of it accordingly. The document must not be released until an error, cleanup or a call
  6874. * to fy_document_iterator_document_end().
  6875. *
  6876. * @fydi: The document iterator to create the event
  6877. * @fyd: The document containing the document state that is used in the event
  6878. *
  6879. * Returns:
  6880. * The newly created document start event, or NULL on error.
  6881. */
  6882. struct fy_event *
  6883. fy_document_iterator_document_start(struct fy_document_iterator *fydi, struct fy_document *fyd)
  6884. FY_EXPORT;
  6885. /**
  6886. * fy_document_iterator_document_end() - Create a document end event using the iterator
  6887. *
  6888. * Creates a document end event on the document iterator and advances the internal state
  6889. * of it accordingly. The document that was used earlier in the call of
  6890. * fy_document_iterator_document_start() can now be released.
  6891. *
  6892. * @fydi: The document iterator to create the event
  6893. *
  6894. * Returns:
  6895. * The newly created document end event, or NULL on error.
  6896. */
  6897. struct fy_event *
  6898. fy_document_iterator_document_end(struct fy_document_iterator *fydi)
  6899. FY_EXPORT;
  6900. /**
  6901. * fy_document_iterator_body_next() - Create document body events until the end
  6902. *
  6903. * Creates the next document body, depth first until the end of the document.
  6904. * The events are created depth first and are in same exact sequence that the
  6905. * original events that created the document.
  6906. *
  6907. * That means that the finite event stream that generated the document is losslesly
  6908. * preserved in such a way that the document tree representation is functionally
  6909. * equivalent.
  6910. *
  6911. * Repeated calls to this function will generate a stream of SCALAR, ALIAS, SEQUENCE
  6912. * START, SEQUENCE END, MAPPING START and MAPPING END events, returning NULL at the
  6913. * end of the body event stream.
  6914. *
  6915. * @fydi: The document iterator to create the event
  6916. *
  6917. * Returns:
  6918. * The newly created document body event or NULL at an error, or an end of the
  6919. * event stream. Use fy_document_iterator_get_error() to check if an error occured.
  6920. */
  6921. struct fy_event *
  6922. fy_document_iterator_body_next(struct fy_document_iterator *fydi)
  6923. FY_EXPORT;
  6924. /**
  6925. * fy_document_iterator_node_start() - Start a document node iteration run using a starting point
  6926. *
  6927. * Starts an iteration run starting at the given node.
  6928. *
  6929. * @fydi: The document iterator to run with
  6930. * @fyn: The iterator root for the iteration
  6931. */
  6932. void
  6933. fy_document_iterator_node_start(struct fy_document_iterator *fydi, struct fy_node *fyn)
  6934. FY_EXPORT;
  6935. /**
  6936. * fy_document_iterator_node_next() - Return the next node in the iteration sequence
  6937. *
  6938. * Returns a pointer to the next node iterating using as a start the node given
  6939. * at fy_document_iterator_node_start(). The first node returned will be that,
  6940. * followed by all the remaing nodes in the subtree.
  6941. *
  6942. * @fydi: The document iterator to use for the iteration
  6943. *
  6944. * Returns:
  6945. * The next node in the iteration sequence or NULL at the end, or if an error occured.
  6946. */
  6947. struct fy_node *
  6948. fy_document_iterator_node_next(struct fy_document_iterator *fydi)
  6949. FY_EXPORT;
  6950. /**
  6951. * fy_document_iterator_get_error() - Get the error state of the document iterator
  6952. *
  6953. * Returns the error state of the iterator. If it's in error state, return true
  6954. * and reset the iterator to the state just after creation.
  6955. *
  6956. * @fydi: The document iterator to use for checking it's error state.
  6957. *
  6958. * Returns:
  6959. * true if it was in an error state, false otherwise.
  6960. */
  6961. bool
  6962. fy_document_iterator_get_error(struct fy_document_iterator *fydi)
  6963. FY_EXPORT;
  6964. #ifdef __cplusplus
  6965. }
  6966. #endif
  6967. #endif