hidlcomp.cpp 251 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #pragma warning(disable:4786)
  14. #include "platform.h"
  15. #include "hidl_utils.hpp"
  16. #include "hidlcomp.h"
  17. #include <map>
  18. #include <set>
  19. #include <string>
  20. //-------------------------------------------------------------------------------------------------------------
  21. inline bool strieq(const char* s,const char* t) { return stricmp(s,t)==0; }
  22. //-------------------------------------------------------------------------------------------------------------
  23. #define HIDL "HIDL"
  24. extern FILE *yyin;
  25. extern int yyparse();
  26. extern HIDLcompiler * hcp;
  27. // --- globals -----
  28. bool isSCM = true;
  29. bool isESP = false;
  30. bool isESPng = false;
  31. StrBuffer clarion;
  32. char srcFileExt[4];
  33. int gOutfile;
  34. //-------------------------------------------------------------------------------------------------------------
  35. // Utility struct and function
  36. char* getFieldName(const char* name)
  37. {
  38. char *uname=strdup(name);
  39. *uname=upperchar(*uname);
  40. return uname;
  41. }
  42. static const char* getTypeKindName(type_kind kind)
  43. {
  44. switch (kind)
  45. {
  46. case TK_null: return "TK_null";
  47. case TK_CHAR: return "TK_CHAR";
  48. case TK_UNSIGNEDCHAR: return "TK_UNSIGNEDCHAR";
  49. case TK_BYTE: return "TK_BYTE";
  50. case TK_BOOL: return "TK_BOOL";
  51. case TK_SHORT: return "TK_SHORT";
  52. case TK_UNSIGNEDSHORT: return "TK_UNSIGNEDSHORT";
  53. case TK_INT: return "TK_INT";
  54. case TK_UNSIGNED: return "TK_UNSIGNED";
  55. case TK_LONG: return "TK_LONG";
  56. case TK_UNSIGNEDLONG: return "TK_UNSIGNEDLONG";
  57. case TK_LONGLONG: return "TK_LONGLONG";
  58. case TK_UNSIGNEDLONGLONG: return "TK_UNSIGNEDLONGLONG";
  59. case TK_DOUBLE: return "TK_DOUBLE";
  60. case TK_FLOAT: return "TK_FLOAT";
  61. case TK_STRUCT: return "TK_STRUCT";
  62. case TK_ENUM: return "TK_ENUM";
  63. case TK_VOID: return "TK_VOID";
  64. case TK_ESPSTRUCT: return "TK_ESPSTRUCT";
  65. case TK_ESPENUM: return "TK_ESPENUM";
  66. default: return "<unknown kind>";
  67. }
  68. };
  69. const char *type_name[] =
  70. {
  71. "??",
  72. "char",
  73. "unsigned char",
  74. "byte",
  75. "bool",
  76. "short",
  77. "unsigned short",
  78. "int",
  79. "unsigned",
  80. "long",
  81. "unsigned long",
  82. "__int64",
  83. "unsigned __int64",
  84. "double",
  85. "float",
  86. "", // STRUCT
  87. "", // ENUM
  88. "void",
  89. "??", // ESPSTRUCT
  90. "??" // ESPENUM
  91. };
  92. const char *clarion_type_name[] =
  93. {
  94. "??",
  95. "BYTE",
  96. "BYTE",
  97. "BYTE",
  98. "CBOOL",
  99. "SHORT",
  100. "USHORT",
  101. "LONG",
  102. "ULONG",
  103. "LONG",
  104. "ULONG",
  105. "LONGLONG",
  106. "ULONGLONG",
  107. "REAL",
  108. "SREAL",
  109. "",
  110. "",
  111. "BYTE",
  112. "??",
  113. "??"
  114. };
  115. const int type_size[] =
  116. {
  117. 1,
  118. 1,
  119. 1,
  120. 1,
  121. 0, // pretend we don't know (To be fixed at some later date)
  122. 2,
  123. 2,
  124. 4,
  125. 4,
  126. 4,
  127. 4,
  128. 8,
  129. 8,
  130. 8,
  131. 4, // STRUCT
  132. 4, // ENUM
  133. 0, // void
  134. 1, // ESP_STRUCT
  135. 1 // ESP_ENUM
  136. };
  137. static const char *xlattable[] =
  138. {
  139. "abs","_abs",
  140. "add","_add",
  141. "address","_address",
  142. "age","_age",
  143. "any","_any",
  144. "append","_append",
  145. "at","_at",
  146. "band","_band",
  147. "bfloat4","_bfloat4",
  148. "bfloat8","_bfloat8",
  149. "binary","_binary",
  150. "bind","_bind",
  151. "blob","_blob",
  152. "bor","_bor",
  153. "bshift","_bshift",
  154. "bxor","_bxor",
  155. "byte","_byte",
  156. "chr","_chr",
  157. "clear","_clear",
  158. "column","_column",
  159. "create","_create",
  160. "decimal","_decimal",
  161. "deformat","_deformat",
  162. "device","_device",
  163. "dim","_dim",
  164. "dispose","_dispose",
  165. "dock","_dock",
  166. "docked","_docked",
  167. "dup","_dup",
  168. "encrypt","_encrypt",
  169. "entry","_entry",
  170. "equate","_equate",
  171. "errorcode","_errorcode",
  172. "format","_format",
  173. "get","_get",
  174. "hlp","_hlp",
  175. "icon","_icon",
  176. "imm","_imm",
  177. "in","_in",
  178. "index","_index",
  179. "inlist","_inlist",
  180. "inrange","_inrange",
  181. "ins","_ins",
  182. "int","_int",
  183. "key","_key",
  184. "length","_length",
  185. "like","_like",
  186. "logout","_logout",
  187. "long","_long",
  188. "maximum","_maximum",
  189. "memo","_memo",
  190. "nocase","_nocase",
  191. "omitted","_omitted",
  192. "opt","_opt",
  193. "out","_out",
  194. "over","_over",
  195. "ovr","_ovr",
  196. "owner","_owner",
  197. "page","_page",
  198. "pageno","_pageno",
  199. "pdecimal","_pdecimal",
  200. "peek","_peek",
  201. "poke","_poke",
  202. "pre","_pre",
  203. "press","_press",
  204. "print","_print",
  205. "project","_project",
  206. "put","_put",
  207. "range","_range",
  208. "real","_real",
  209. "reclaim","_reclaim",
  210. "req","_req",
  211. "round","_round",
  212. "scroll","_scroll",
  213. "short","_short",
  214. "size","_size",
  215. "sort","_sort",
  216. "step","_step",
  217. "string","_string",
  218. "text","_text",
  219. "upr","_upr",
  220. "use","_use",
  221. "val","_val",
  222. "width","_width",
  223. NULL,NULL
  224. };
  225. static const char *xlat(const char *from)
  226. {
  227. for (unsigned i=0;xlattable[i];i+=2) {
  228. if (stricmp(from,xlattable[i])==0)
  229. return xlattable[i+1];
  230. }
  231. return from;
  232. }
  233. bool toClaInterface(char * dest, const char * src)
  234. {
  235. if(*src == 'I' && strlen(src) > 1)
  236. {
  237. strcpy(dest, "cpp");
  238. strcpy(dest + 3, src + 1);
  239. return true;
  240. }
  241. strcpy(dest, src);
  242. return false;
  243. }
  244. #define ForEachParam(pr,pa,flagsset,flagsclear) for (pa=pr->params;pa;pa=pa->next) \
  245. if (((pa->flags&(flagsset))==(flagsset))&((pa->flags&(flagsclear))==0))
  246. #define INDIRECTSIZE(p) ((p->flags&(PF_PTR|PF_REF))==(PF_PTR|PF_REF))
  247. void indent(int indents)
  248. {
  249. for (int i=0;i<indents; i++)
  250. out("\t",1);
  251. }
  252. void out(const char *s,size_t l)
  253. {
  254. ssize_t written = write(gOutfile,s,(unsigned)l);
  255. if (written < 0)
  256. throw "Error while writing out";
  257. if (written != l)
  258. throw "Truncated write";
  259. }
  260. void outs(const char *s)
  261. {
  262. out(s,strlen(s));
  263. }
  264. void outs(int indents, const char *s)
  265. {
  266. indent(indents);
  267. out(s,strlen(s));
  268. }
  269. static void voutf(const char* fmt,va_list args) __attribute__((format(printf,1,0)));
  270. void voutf(const char* fmt,va_list args)
  271. {
  272. const int BUF_LEN = 0x4000;
  273. static char buf[BUF_LEN+1];
  274. // Better to use StringBuffer.valist_appendf, but unfortunately, project dependencies
  275. // disallow us to use StringBuffer (defined in jlib).
  276. if (_vsnprintf(buf, BUF_LEN, fmt, args)<0)
  277. fprintf(stderr,"Warning: outf() gets too many long buffer (>%d)", BUF_LEN);
  278. va_end(args);
  279. outs(buf);
  280. }
  281. void outf(const char *fmt, ...)
  282. {
  283. va_list args;
  284. va_start(args, fmt);
  285. voutf(fmt,args);
  286. }
  287. void outf(int indents, const char *fmt, ...)
  288. {
  289. indent(indents);
  290. va_list args;
  291. va_start(args, fmt);
  292. voutf(fmt,args);
  293. }
  294. // ------------------------------------
  295. // "auto" indenting
  296. int gIndent = 0;
  297. void indentReset(int indent=0) { gIndent = indent; }
  298. void indentInc(int inc) { gIndent += inc; }
  299. void indentOuts(const char* s)
  300. {
  301. indent(gIndent);
  302. out(s,strlen(s));
  303. }
  304. void indentOuts(int inc, const char* s)
  305. {
  306. gIndent += inc;
  307. indentOuts(s);
  308. }
  309. void indentOuts1(int inc, const char* s)
  310. {
  311. indent(gIndent+inc);
  312. out(s,strlen(s));
  313. }
  314. void indentOutf(const char* fmt,...) __attribute__((format(printf,1,2)));
  315. void indentOutf(const char* fmt, ...)
  316. {
  317. indent(gIndent);
  318. va_list args;
  319. va_start(args, fmt);
  320. voutf(fmt,args);
  321. }
  322. void indentOutf(int inc, const char* fmt,...) __attribute__((format(printf,2,3)));
  323. void indentOutf(int inc, const char* fmt, ...)
  324. {
  325. gIndent += inc;
  326. indent(gIndent);
  327. va_list args;
  328. va_start(args, fmt);
  329. voutf(fmt,args);
  330. }
  331. void indentOutf1(int inc, const char* fmt,...) __attribute__((format(printf,2,3)));
  332. void indentOutf1(int inc, const char* fmt, ...)
  333. {
  334. indent(gIndent+inc);
  335. va_list args;
  336. va_start(args, fmt);
  337. voutf(fmt,args);
  338. }
  339. //-------------------------------------------------------------------------------------------------------------
  340. // class LayoutInfo
  341. LayoutInfo::LayoutInfo()
  342. {
  343. size = 0;
  344. count = 0;
  345. next = NULL;
  346. }
  347. LayoutInfo::~LayoutInfo()
  348. {
  349. delete next;
  350. }
  351. //-------------------------------------------------------------------------------------------------------------
  352. // class ParamInfo
  353. ParamInfo::ParamInfo()
  354. {
  355. name = NULL;
  356. templ = NULL;
  357. typname = NULL;
  358. size = NULL;
  359. flags = 0;
  360. next = NULL;
  361. kind = TK_null;
  362. sizebytes = NULL;
  363. layouts = NULL;
  364. tags = NULL;
  365. xsdtype = NULL;
  366. m_arrayImplType = NULL;
  367. }
  368. ParamInfo::~ParamInfo()
  369. {
  370. if (name)
  371. free(name);
  372. if (typname)
  373. free(typname);
  374. if (size)
  375. free(size);
  376. if (sizebytes)
  377. free(sizebytes);
  378. if (templ)
  379. free(templ);
  380. if (xsdtype)
  381. free(xsdtype);
  382. if (m_arrayImplType)
  383. delete m_arrayImplType;
  384. delete tags;
  385. delete layouts;
  386. delete next;
  387. }
  388. char * ParamInfo::bytesize(int deref)
  389. {
  390. if (!size)
  391. return NULL;
  392. if (sizebytes)
  393. return sizebytes;
  394. char str[1024];
  395. if (type_size[kind]==1)
  396. {
  397. if (deref)
  398. {
  399. strcpy(str,"*");
  400. strcat(str,size);
  401. sizebytes = strdup(str);
  402. return sizebytes;
  403. }
  404. else
  405. return size;
  406. }
  407. strcpy(str,"sizeof(");
  408. if (kind==TK_STRUCT)
  409. strcat(str,typname);
  410. else
  411. strcat(str,type_name[kind]);
  412. strcat(str,")*(");
  413. if (deref)
  414. strcat(str,"*");
  415. strcat(str,size);
  416. strcat(str,")");
  417. sizebytes = strdup(str);
  418. return sizebytes;
  419. }
  420. bool ParamInfo::simpleneedsswap()
  421. {
  422. switch(kind) {
  423. case TK_SHORT:
  424. case TK_UNSIGNEDSHORT:
  425. case TK_INT:
  426. case TK_UNSIGNED:
  427. case TK_LONG:
  428. case TK_UNSIGNEDLONG:
  429. case TK_LONGLONG:
  430. case TK_UNSIGNEDLONGLONG:
  431. return true;
  432. default:
  433. return false;
  434. }
  435. }
  436. void ParamInfo::cat_type(char *s,int deref,int var)
  437. {
  438. if ((flags&PF_CONST)&&!var)
  439. strcat(s,"const ");
  440. if (typname)
  441. strcat(s,typname);
  442. else {
  443. if (kind!=TK_null)
  444. strcat(s,type_name[kind]);
  445. else
  446. strcat(s,"string"); // TODO: why this happens?
  447. }
  448. if (!deref) {
  449. if (flags&PF_PTR)
  450. strcat(s," *");
  451. if (flags&PF_REF)
  452. strcat(s," &");
  453. }
  454. }
  455. clarion_special_type_enum ParamInfo::clarion_special_type()
  456. {
  457. if ((type_size[kind]==1)&&((flags&(PF_PTR|PF_REF))==PF_PTR)) {
  458. if ((flags&PF_CONST)==0)
  459. return cte_cstr;
  460. return cte_constcstr;
  461. }
  462. else if ((flags&(PF_PTR|PF_REF))==(PF_PTR|PF_REF)) { // no support - convert to long
  463. return cte_longref;
  464. }
  465. return cte_normal;
  466. }
  467. void ParamInfo::out_parameter(const char * pfx, int forclarion)
  468. {
  469. if (forclarion && (clarion_special_type()==cte_cstr))
  470. outs("int, ");
  471. out_type();
  472. outf(" %s%s",pfx,name);
  473. }
  474. void ParamInfo::out_type(int deref,int var)
  475. {
  476. char s[256];
  477. s[0] = 0;
  478. cat_type(s,deref,var);
  479. outs(s);
  480. }
  481. void ParamInfo::typesizeacc(char *accstr,size_t &acc)
  482. {
  483. if ((kind==TK_STRUCT)||(flags&(PF_PTR|PF_REF))) {
  484. acc = (acc+3)&~3;
  485. if (*accstr)
  486. strcat(accstr,"+");
  487. strcat(accstr,"sizeof(");
  488. cat_type(accstr);
  489. strcat(accstr,")");
  490. }
  491. else {
  492. size_t sz=type_size[kind];
  493. if (sz==2)
  494. acc = (acc+1)&~1;
  495. else if (sz>=4)
  496. acc = (acc+3)&~3;
  497. acc += type_size[kind];
  498. }
  499. }
  500. size_t ParamInfo::typesizealign(size_t &ofs)
  501. {
  502. size_t ret=0;
  503. if ((kind==TK_STRUCT)||(flags&(PF_PTR|PF_REF))) {
  504. if (ofs) {
  505. ret = 4-ofs;
  506. ofs = 0;
  507. }
  508. }
  509. else {
  510. size_t sz=type_size[kind];
  511. if (sz==1) {
  512. ret = 0;
  513. ofs = (ofs+1)%4;
  514. }
  515. else if (sz==2) {
  516. ret = (ofs&1);
  517. ofs = (ofs+ret+2)%4;
  518. }
  519. else {
  520. if (ofs) {
  521. ret = 4-ofs;
  522. ofs = 0;
  523. }
  524. }
  525. }
  526. return ret;
  527. }
  528. void ParamInfo::write_body_struct_elem(int ref)
  529. {
  530. outs("\t");
  531. out_type(ref,1);
  532. if (ref&&(flags&(PF_REF|PF_PTR)))
  533. {
  534. outs(" *");
  535. if ((flags&(PF_REF|PF_PTR))==(PF_REF|PF_PTR))
  536. {
  537. outs(" *");
  538. }
  539. }
  540. outf(" %s;\n",name);
  541. }
  542. void ParamInfo::out_clarion_parameter()
  543. {
  544. out_clarion_type(false);
  545. if(!typname || strcmp(typname, "__int64") != 0) outs(" ");
  546. if (clarion_special_type()==cte_longref)
  547. outs("REF_");
  548. if (name)
  549. outs(name);
  550. else
  551. outs("???");
  552. }
  553. void ParamInfo::out_clarion_type(bool ret)
  554. {
  555. clarion_special_type_enum cte = clarion_special_type();
  556. bool isInt64 = (typname && strcmp(typname, "__int64") == 0);
  557. if (!isInt64 && ((flags&PF_REF)||((flags&PF_PTR)&&(cte==cte_normal)))) {
  558. outs("*");
  559. }
  560. if (cte==cte_longref) {
  561. outs("LONG");
  562. }
  563. else if (cte==cte_cstr) {
  564. outs("*CSTRING");
  565. }
  566. else if (cte==cte_constcstr) {
  567. if (ret)
  568. outs("*CSTRING");
  569. else
  570. outs("CONST *CSTRING");
  571. }
  572. else if (typname) {
  573. static char _typname[256];
  574. if(isInt64) {
  575. if(ret) {
  576. strcpy(_typname, "__int64"); // __int64 return type unsupported defaulting to ulong for now.
  577. }
  578. else if((flags & PF_REF) || (flags & PF_PTR)) {
  579. strcpy(_typname, "LONG ");
  580. }
  581. else {
  582. strcpy(_typname, "LONG hi");
  583. strcat(_typname, name);
  584. strcat(_typname, ", LONG lo");
  585. }
  586. }
  587. else if(!toClaInterface(_typname, typname)){
  588. xlat(_typname);
  589. }
  590. outs(_typname);
  591. }
  592. else {
  593. outs(clarion_type_name[kind]);
  594. }
  595. }
  596. void ParamInfo::write_param_convert(int deref)
  597. {
  598. outs("(");
  599. out_type(1,1);
  600. if (flags&(PF_REF|PF_PTR)) {
  601. if (!deref)
  602. outs(" *");
  603. if ((flags&(PF_REF|PF_PTR))==(PF_REF|PF_PTR)) {
  604. outs(" *");
  605. }
  606. }
  607. outs(")");
  608. }
  609. bool ParamInfo::hasMapInfo()
  610. {
  611. if (hasMetaVerInfo("min_ver") || hasMetaVerInfo("max_ver") || hasMetaVerInfo("depr_ver"))
  612. return true;
  613. if (getMetaString("optional", NULL))
  614. return true;
  615. return false;
  616. }
  617. static esp_xlate_info esp_xlate_table[]=
  618. {
  619. //meta type xsd type implementation array impl access type type_kind flags method
  620. //------------------ --------------- -------------- -------------- -------------- ----------- ------------ ----------
  621. // {"string", "string", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  622. {"string", "string", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  623. {"StringBuffer", "string", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  624. // {"hexBinary", "base64Binary", "MemoryBuffer", "???", "unsigned char *", TK_UNSIGNEDCHAR, (PF_PTR), EAM_jmbuf},
  625. {"binary", "base64Binary", "MemoryBuffer", "???", "const MemoryBuffer &", TK_STRUCT, (PF_REF), EAM_jmbin},
  626. {"bool", "boolean", "bool", "BoolArray", "bool", TK_BOOL, 0, EAM_basic},
  627. {"boolean", "boolean", "bool", "BoolArray", "bool", TK_BOOL, 0, EAM_basic},
  628. {"decimal", "decimal", "float", "???", "float", TK_FLOAT, 0, EAM_basic},
  629. {"float", "float", "float", "FloatArray", "float", TK_FLOAT, 0, EAM_basic},
  630. {"double", "double", "double", "DoubleArray", "double", TK_DOUBLE, 0, EAM_basic},
  631. {"integer", "integer", "int", "???", "int", TK_INT, 0, EAM_basic},
  632. {"int64", "long", "__int64", "Int64Array", "__int64", TK_LONGLONG, 0, EAM_basic},
  633. {"long", "long", "long", "Int64Array", "__int64", TK_LONG, 0, EAM_basic},
  634. {"int", "int", "int", "IntArray", "int", TK_INT, 0, EAM_basic},
  635. {"short", "short", "short", "ShortArray", "short", TK_SHORT, 0, EAM_basic},
  636. {"nonPositiveInteger", "nonPositiveInteger", "int", "???", "int", TK_INT, 0, EAM_basic},
  637. {"negativeInteger", "negativeInteger", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  638. {"nonNegativeInteger", "nonNegativeInteger", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  639. {"unsignedLong", "unsignedLong", "unsigned long", "???", "unsigned long", TK_UNSIGNEDLONG, 0, EAM_basic},
  640. {"unsignedInt", "unsignedInt", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  641. {"unsigned", "unsignedInt", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  642. {"unsignedShort", "unsignedShort", "unsigned short", "???", "unsigned short", TK_UNSIGNEDSHORT, 0, EAM_basic},
  643. {"unsignedByte", "unsignedByte", "unsigned char", "???", "unsigned char", TK_UNSIGNEDCHAR, 0, EAM_basic},
  644. {"positiveInteger", "positiveInteger", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  645. {"base64Binary", "base64Binary", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  646. {"normalizedString", "normalizedString", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  647. {"xsdString", "string", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  648. {"xsdBinary", "binary", "MemoryBuffer", "???", "const MemoryBuffer &", TK_STRUCT, (PF_REF), EAM_jmbin},
  649. {"xsdBoolean", "boolean", "bool", "???", "bool", TK_BOOL, 0, EAM_basic},
  650. {"xsdDecimal", "decimal", "float", "???", "float", TK_FLOAT, 0, EAM_basic},
  651. {"xsdInteger", "integer", "int", "???", "int", TK_INT, 0, EAM_basic},
  652. {"xsdByte", "byte", "unsigned char", "???", "unsigned char", TK_UNSIGNEDCHAR, 0, EAM_basic},
  653. {"xsdDuration", "duration", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  654. {"xsdDateTime", "dateTime", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  655. {"xsdTime", "time", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  656. {"xsdDate", "date", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  657. {"xsdYearMonth", "gYearMonth", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  658. {"xsdYear", "gYear", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  659. {"xsdMonthDay", "gMonthDay", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  660. {"xsdDay", "gDay", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  661. {"xsdMonth", "gMonth", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  662. {"xsdAnyURI", "anyURI", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  663. {"xsdQName", "QName", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  664. {"xsdNOTATION", "NOTATION", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  665. {"xsdToken", "token", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  666. {"xsdLanguage", "language", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  667. {"xsdNMTOKEN", "NMTOKEN", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  668. {"xsdNMTOKENS", "NMTOKENS", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  669. {"xsdName", "Name", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  670. {"xsdNCName", "NCName", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  671. {"xsdID", "ID", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  672. {"xsdIDREF", "IDREF", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  673. {"xsdIDREFS", "IDREFS", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  674. {"xsdENTITY", "ENTITY", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  675. {"xsdENTITIES", "ENTITIES", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  676. {"xsdNonPositiveInteger", "nonPositiveInteger", "int", "???", "int", TK_INT, 0, EAM_basic},
  677. {"xsdNegativeInteger", "negativeInteger", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  678. {"xsdNonNegativeInteger", "nonNegativeInteger", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  679. {"xsdUnsignedLong", "unsignedLong", "unsigned long", "???", "unsigned long", TK_UNSIGNEDLONG, 0, EAM_basic},
  680. {"xsdUnsignedInt", "unsignedInt", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  681. {"xsdUnsignedShort", "unsignedShort", "unsigned short", "???", "unsigned short", TK_UNSIGNEDSHORT, 0, EAM_basic},
  682. {"xsdUnsignedByte", "unsignedByte", "unsigned char", "???", "unsigned char", TK_UNSIGNEDCHAR, 0, EAM_basic},
  683. {"xsdPositiveInteger", "positiveInteger", "unsigned int", "???", "unsigned int", TK_UNSIGNED, 0, EAM_basic},
  684. {"xsdBase64Binary", "base64Binary", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  685. {"xsdNormalizedString", "normalizedString", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  686. {"EspTextFile", "string", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  687. {"EspResultSet", "string", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  688. {"AdoDataSet", "tns:AdoDataSet", "StringBuffer", "StringArray", "const char *", TK_CHAR, (PF_PTR|PF_CONST), EAM_jsbuf},
  689. {NULL, NULL, NULL, NULL, NULL, TK_null, 0, EAM_basic}
  690. };
  691. esp_xlate_info *esp_xlat(const char *from, bool defaultToString)
  692. {
  693. if (from)
  694. {
  695. for (unsigned i=0; esp_xlate_table[i].meta_type!=NULL; i++)
  696. {
  697. if (stricmp(from,esp_xlate_table[i].meta_type)==0)
  698. return &esp_xlate_table[i];
  699. }
  700. }
  701. return (defaultToString) ? &esp_xlate_table[0] : NULL;
  702. }
  703. //TODO: this is not bullet proof. better idea??
  704. // Return: NULL if no need to be defined, otherwise the type to be defined
  705. // Note: the caller needs to free memory
  706. static char* getToBeDefinedType(const char* type)
  707. {
  708. const char* colon = strchr(type, ':');
  709. const char* bareType = colon ? colon+1 : type;
  710. if (strnicmp(type, "xsd",colon-type)==0)
  711. return NULL;
  712. /*
  713. for (unsigned i=0; esp_xlate_table[i].meta_type!=NULL; i++)
  714. {
  715. if (stricmp(bareType,esp_xlate_table[i].xsd_type)==0)
  716. return NULL;
  717. }
  718. */
  719. if (strnicmp(type, "tns", colon-type)!=0)
  720. {
  721. char msg[128];
  722. sprintf(msg, "*** unhandled type: %s", type);
  723. outs(msg);
  724. yyerror(msg);
  725. return NULL;
  726. }
  727. if (strncmp(bareType, "ArrayOf", sizeof("ArrayOf")-1)==0)
  728. return strdup(bareType+sizeof("ArrayOf")-1);
  729. else
  730. return strdup(bareType);
  731. }
  732. static const char *MetaTypeToXsdType(const char *val)
  733. {
  734. esp_xlate_info *xlation=esp_xlat(val);
  735. return (xlation) ? xlation->xsd_type : (const char *)"string";
  736. }
  737. // return: true if the ver tag is defined
  738. bool hasMetaVerInfo(MetaTagInfo *list, const char* tag)
  739. {
  740. double ver = getMetaDouble(list,tag,-1);
  741. if (ver>0)
  742. return true;
  743. const char* vs = getMetaString(list,tag, NULL);
  744. if (vs!=NULL)
  745. return true;
  746. const char* id = getMetaConstId(list,tag,NULL);
  747. if (id)
  748. return true;
  749. return false;
  750. }
  751. bool getMetaVerInfo(MetaTagInfo *list, const char* tag, StrBuffer& s)
  752. {
  753. double ver = getMetaDouble(list,tag,-1);
  754. if (ver>0) {
  755. s.append(ver);
  756. return true;
  757. }
  758. const char* vs = getMetaString(list,tag, NULL);
  759. if (vs!=NULL) {
  760. if (*vs=='"' || *vs=='\'')
  761. vs++;
  762. double v = atof(vs);
  763. s.append(v);
  764. return true;
  765. }
  766. const char* id = getMetaConstId(list,tag,NULL);
  767. if (id) {
  768. s.append(id);
  769. return true;
  770. }
  771. return false;
  772. }
  773. static esp_xlate_info *esp_xlat(ParamInfo *pi)
  774. {
  775. char metatype[256];
  776. *metatype=0;
  777. pi->cat_type(metatype);
  778. return esp_xlat(metatype);
  779. }
  780. void ParamInfo::setXsdType(const char *value)
  781. {
  782. if (xsdtype)
  783. free(xsdtype);
  784. const char *newValue=value;
  785. if (strncmp(value, "xsd", 3)==0)
  786. newValue=MetaTypeToXsdType(value);
  787. xsdtype = (newValue!=NULL) ? strdup(newValue) : NULL;
  788. }
  789. const char *ParamInfo::getXsdType()
  790. {
  791. if (xsdtype==NULL)
  792. {
  793. char metatype[256];
  794. *metatype=0;
  795. cat_type(metatype);
  796. setXsdType(MetaTypeToXsdType(metatype));
  797. }
  798. return xsdtype;
  799. }
  800. const char* ParamInfo::getArrayImplType()
  801. {
  802. if (m_arrayImplType)
  803. return m_arrayImplType->str();
  804. if (isPrimitiveArray())
  805. {
  806. char metatype[256];
  807. metatype[0] = 0;
  808. cat_type(metatype);
  809. esp_xlate_info *xlation=esp_xlat(metatype, false);
  810. m_arrayImplType = new StrBuffer(xlation->array_type);
  811. }
  812. else
  813. {
  814. if (kind == TK_ESPENUM)
  815. m_arrayImplType = new VStrBuffer("%sArray", typname);
  816. else
  817. m_arrayImplType = new VStrBuffer("IArrayOf<IConst%s>", typname);
  818. }
  819. return m_arrayImplType->str();
  820. }
  821. const char* ParamInfo::getArrayItemXsdType()
  822. {
  823. switch (kind)
  824. {
  825. case TK_CHAR: return "string";
  826. case TK_UNSIGNEDCHAR: return "string"; //?
  827. case TK_BYTE: return "byte";
  828. case TK_BOOL: return "boolean";
  829. case TK_SHORT: return "short";
  830. case TK_UNSIGNEDSHORT: return "unsignedShort";
  831. case TK_INT: return "int";
  832. case TK_UNSIGNED: return "unsignedInt";
  833. case TK_LONG: return "long";
  834. case TK_UNSIGNEDLONG: return "unsignedLong";
  835. case TK_LONGLONG: return "long";
  836. case TK_UNSIGNEDLONGLONG: return "unsignedLong";
  837. case TK_DOUBLE: return "double";
  838. case TK_FLOAT: return "float";
  839. case TK_null: return "string";
  840. case TK_STRUCT:
  841. case TK_VOID:
  842. case TK_ESPSTRUCT:
  843. case TK_ESPENUM:
  844. default: throw "Unimplemented";
  845. }
  846. }
  847. const char* ParamInfo::getArrayItemTag()
  848. {
  849. const char *item_tag = getMetaString("item_tag", NULL);
  850. if (item_tag)
  851. return item_tag;
  852. if (!(flags & PF_TEMPLATE) || !streq(templ, "ESParray"))
  853. return NULL;
  854. if (isEspStringArray())
  855. return "Item";
  856. return typname;
  857. }
  858. void ParamInfo::write_esp_declaration()
  859. {
  860. char metatype[256];
  861. *metatype=0;
  862. cat_type(metatype);
  863. esp_xlate_info *xlation=esp_xlat(metatype, false);
  864. if (hasNameTag())
  865. outf("\tSoapStringParam m_%s_name;\n", name);
  866. if (xlation)
  867. {
  868. if (xlation->eam_type==EAM_jmbin)
  869. {
  870. if (getMetaInt("attach", 0))
  871. outf("\tSoapAttachBinary m_%s;\n", name);
  872. else
  873. outf("\tSoapParamBinary m_%s;\n", name);
  874. }
  875. else
  876. {
  877. if (getMetaInt("attach", 0))
  878. {
  879. if (!stricmp(xlation->store_type, "StringBuffer"))
  880. outf("\tSoapAttachString m_%s;\n", name);
  881. else
  882. outf("\tSoapAttachParam<%s> m_%s;\n", xlation->store_type, name);
  883. }
  884. else if (flags & PF_TEMPLATE)
  885. // outf("\tSoapArrayParam<%s> m_%s;\n", xlation->array_type, name);
  886. outf("\tSoap%s m_%s;\n", xlation->array_type, name);
  887. else if (!stricmp(xlation->store_type, "StringBuffer"))
  888. outf("\tSoapStringParam m_%s;\n", name);
  889. else
  890. outf("\tSoapParam<%s> m_%s;\n", xlation->store_type, name);
  891. }
  892. }
  893. else
  894. {
  895. if (getMetaInt("attach", 0))
  896. outf("\tSoapAttachString m_%s;\n", name);
  897. else if (flags & PF_TEMPLATE && templ && !strcmp(templ, "ESParray"))
  898. {
  899. if (isEspStringArray())
  900. //outf("\tSoapArrayParam<StringArray> m_%s;\n", name);
  901. outf("\tSoapStringArray m_%s;\n", name);
  902. else if (kind==TK_ESPENUM)
  903. outf("\tSoapEnumArrayParam<C%s, CX%s, %sArray> m_%s;\n", typname, typname, typname, name);
  904. else
  905. outf("\tSoapStructArrayParam<IConst%s, C%s> m_%s;\n", typname, typname, name);
  906. }
  907. else if (kind==TK_ESPSTRUCT)
  908. outf("\tSoapStruct<C%s, IConst%s> m_%s;\n", typname, typname, name);
  909. else if (kind==TK_ESPENUM)
  910. outf("\tCX%s m_%s;\n", typname, name);
  911. else
  912. outf("\tSoapStringParam m_%s;\n", name);
  913. }
  914. }
  915. void ParamInfo::write_esp_init(bool &isFirst, bool msgRemoveNil)
  916. {
  917. outs(isFirst ? "\n\t: " : ",");
  918. MetaTagInfo* deftag = findMetaTag(tags, "default");
  919. bool removeNil = (msgRemoveNil || findMetaTag(tags, "nil_remove")!=NULL);
  920. const char *nilStr = (removeNil) ? "nilRemove" : "nilIgnore";
  921. if (kind==TK_ESPSTRUCT)
  922. {
  923. outf("m_%s(serviceName, %s)", name, nilStr);
  924. }
  925. else if (kind==TK_ESPENUM)
  926. {
  927. if (deftag)
  928. {
  929. outf("m_%s(", name);
  930. switch(deftag->mttype_)
  931. {
  932. case MetaTagInfo::mt_string: outf("%s",deftag->getString()); break;
  933. case MetaTagInfo::mt_int: outf("\"%d\"", deftag->getInt()); break;
  934. case MetaTagInfo::mt_double: outf("\"%g\"", deftag->getDouble()); break;
  935. case MetaTagInfo::mt_const_id: outf("\"%s\"", deftag->getName()); break;
  936. case MetaTagInfo::mt_none: assert(false); break;
  937. }
  938. outf(")");
  939. }
  940. else
  941. outf("m_%s(%s)", name, nilStr);
  942. }
  943. else if ((flags & PF_TEMPLATE) || kind==TK_STRUCT || getMetaInt("attach", 0))
  944. {
  945. outf("m_%s(%s)", name, nilStr);
  946. }
  947. else if (deftag)
  948. {
  949. if (deftag->mttype_==MetaTagInfo::mt_string)
  950. outf("m_%s(%s, %s)", name, deftag->getString(), nilStr);
  951. else if (deftag->mttype_==MetaTagInfo::mt_int)
  952. outf("m_%s(%d, %s,false)", name, deftag->getInt(), nilStr);
  953. else if (deftag->mttype_==MetaTagInfo::mt_double)
  954. outf("m_%s(%g, %s,false)", name, deftag->getDouble(), nilStr);
  955. }
  956. else
  957. {
  958. if (getMetaInt("http_nillable", 1)!=0)
  959. outf("m_%s(%s)", name, nilStr);
  960. else
  961. outf("m_%s(%s, false)", name, nilStr);
  962. }
  963. isFirst=false;
  964. }
  965. void ParamInfo::write_esp_attr_method(const char *msgname, bool isSet, bool parNilRemove, bool isDecl, bool isPure, bool parTrim, const char* xsdType)
  966. {
  967. char metatype[256];
  968. *metatype=0;
  969. cat_type(metatype);
  970. esp_xlate_info *xlation=esp_xlat(metatype);
  971. char *methName=strdup(name);
  972. *methName=upperchar(*methName);
  973. const char *httpcont = getMetaString("http_content", NULL);
  974. bool hasNilRemove = (parNilRemove || getMetaInt("nil_remove"));
  975. bool hasTrim = (parTrim || getMetaInt("trim"));
  976. if (hasNameTag())
  977. {
  978. if (isSet)
  979. {
  980. if (isDecl)
  981. outs("\t");
  982. if (isDecl && isPure)
  983. outs("virtual ");
  984. outs("void ");
  985. if (!isDecl && msgname)
  986. outf("C%s::", msgname);
  987. outf("set%s_name", methName);
  988. outs("(const char * val)");
  989. if (isDecl)
  990. outs((isPure) ? "=0;\n" : ";\n");
  991. else
  992. outf("{ m_%s_name.set(val); }\n", name);
  993. }
  994. else
  995. {
  996. if (isDecl)
  997. outs("\t");
  998. if (isDecl && isPure)
  999. outs("virtual ");
  1000. outs("const char *");
  1001. if (!isDecl && msgname)
  1002. outf("C%s::", msgname);
  1003. outf("get%s_name()", methName);
  1004. if (isDecl)
  1005. outs((isPure) ? "=0;\n" : ";\n");
  1006. else
  1007. outf("{ return m_%s_name.query(); }\n", name);
  1008. if (isDecl)
  1009. outs("\t");
  1010. if (isDecl && isPure)
  1011. outs("virtual ");
  1012. outs("const StringBuffer& ");
  1013. if (!isDecl && msgname)
  1014. outf("C%s::", msgname);
  1015. outf("get%s_value()", methName);
  1016. if (isDecl)
  1017. outs((isPure) ? "=0;\n" : ";\n");
  1018. else
  1019. outf("{ return m_%s.getValue(); }\n", name);
  1020. }
  1021. }
  1022. if (httpcont!=NULL)
  1023. {
  1024. if (isSet)
  1025. {
  1026. if (isDecl)
  1027. outs("\t");
  1028. if (isDecl && isPure)
  1029. outs("virtual ");
  1030. outs("void ");
  1031. if (!isDecl && msgname)
  1032. outf("C%s::", msgname);
  1033. outf("set%s_mimetype", methName);
  1034. outs("(const char * val)");
  1035. if (isDecl)
  1036. outs((isPure) ? "=0;\n" : ";\n");
  1037. else
  1038. outf("{ m_%s_mimetype.set(val); }\n", name);
  1039. }
  1040. else
  1041. {
  1042. if (isDecl)
  1043. outs("\t");
  1044. if (isDecl && isPure)
  1045. outs("virtual ");
  1046. outs("const char *");
  1047. if (!isDecl && msgname)
  1048. outf("C%s::", msgname);
  1049. outf("get%s_mimetype()", methName);
  1050. if (isDecl)
  1051. outs((isPure) ? "=0;\n" : ";\n");
  1052. else
  1053. outf("{ return m_%s_mimetype.str(); }\n", name);
  1054. }
  1055. }
  1056. if (isSet)
  1057. {
  1058. if (hasNilRemove && xlation->eam_type == EAM_basic && (flags & PF_TEMPLATE)==0 )
  1059. {
  1060. if (isDecl)
  1061. outs("\t");
  1062. if (isDecl && isPure)
  1063. outs("virtual ");
  1064. outs("void ");
  1065. if (!isDecl && msgname)
  1066. outf("C%s::", msgname);
  1067. outf("set%s_null()", methName);
  1068. if (isDecl)
  1069. outs((isPure) ? "=0;\n" : ";\n");
  1070. else
  1071. outf("{ m_%s.Nil(); }", name);
  1072. }
  1073. if (isDecl)
  1074. outs("\t");
  1075. if (isDecl && isPure)
  1076. outs("virtual ");
  1077. if (flags & PF_TEMPLATE)
  1078. {
  1079. // setXXX(IArrayOf<IEspXXX>);
  1080. if (templ && !strcmp(templ, "ESParray") && typname && !isEspStringArray() && kind!=TK_ESPENUM)
  1081. {
  1082. outs("void ");
  1083. if (!isDecl && msgname)
  1084. outf("C%s::", msgname);
  1085. outf("set%s", methName);
  1086. if (kind == TK_ESPENUM)
  1087. ;// outf("(%sArray &val)", typname);
  1088. else
  1089. outf("(IArrayOf<IEsp%s> &val)", typname);
  1090. if (isDecl)
  1091. {
  1092. if (isPure)
  1093. outs("=0;\n\tvirtual ");
  1094. else
  1095. outs(";\n ");
  1096. }
  1097. else
  1098. {
  1099. outs("\n{\n");
  1100. if (kind == TK_ESPENUM)
  1101. {
  1102. /*
  1103. outf("\tm_%s->kill();\n", name);
  1104. outf("\t%sArray &target = m_%s.getValue();\n", typname, name);
  1105. outs("\tForEachItemIn(idx, val)\n");
  1106. outs("\t{\n");
  1107. outf("\t\tC%s &item = (val).item(idx);\n", typname);
  1108. outs("\t\ttarget.append(item);\n");
  1109. outs("\t}\n");
  1110. */
  1111. }
  1112. else
  1113. {
  1114. outf("\tm_%s->kill();\n", name);
  1115. outf("\tIArrayOf<IConst%s> &target = m_%s.getValue();\n", typname, name);
  1116. outs("\tForEachItemIn(idx, val)\n");
  1117. outs("\t{\n");
  1118. outf("\t\tIEsp%s &item = (val).item(idx);\n", typname);
  1119. outs("\t\titem.Link();\n");
  1120. outs("\t\ttarget.append(item);\n");
  1121. outs("\t}\n");
  1122. }
  1123. outs("}\n");
  1124. }
  1125. }
  1126. outs("void ");
  1127. if (!isDecl && msgname)
  1128. outf("C%s::", msgname);
  1129. outf("set%s", methName);
  1130. if (templ && !strcmp(templ, "ESParray"))
  1131. {
  1132. //if (isEspStringArray())
  1133. // outf("(%s &val)", "StringArray");
  1134. //else
  1135. // outf("(IArrayOf<IConst%s> &val)", typname);
  1136. outf("(%s &val)", getArrayImplType());
  1137. }
  1138. else
  1139. {
  1140. switch (xlation->eam_type)
  1141. {
  1142. case EAM_jmbuf:
  1143. outf("(%s val, unsigned int len)", xlation->access_type);
  1144. break;
  1145. case EAM_jmbin:
  1146. case EAM_basic:
  1147. case EAM_jsbuf:
  1148. default:
  1149. outf("(%s val)", xlation->access_type);
  1150. break;
  1151. }
  1152. }
  1153. if (isDecl)
  1154. {
  1155. if (isPure)
  1156. outs("=0");
  1157. outs(";\n");
  1158. }
  1159. else
  1160. {
  1161. if (isPrimitiveArray())
  1162. {
  1163. outf("{ ");
  1164. if (isEspStringArray())
  1165. outf("m_%s->kill(); ",name);
  1166. outf(" CloneArray(m_%s.getValue(), val); }\n", name);
  1167. }
  1168. else if (kind == TK_ESPENUM)
  1169. {
  1170. outs("\n{\n");
  1171. outf("\tm_%s->kill();\n", name);
  1172. outf("\t%sArray &target = m_%s.getValue();\n", typname, name);
  1173. outs("\tForEachItemIn(idx, val)\n");
  1174. outs("\t{\n");
  1175. outf("\t\tC%s item = val.item(idx);\n", typname);
  1176. outs("\t\ttarget.append(item);\n");
  1177. outs("\t}\n");
  1178. outs("}\n");
  1179. }
  1180. else
  1181. {
  1182. outs("\n{\n");
  1183. outf("\tm_%s->kill();\n", name);
  1184. outf("\tIArrayOf<IConst%s> &target = m_%s.getValue();\n", typname, name);
  1185. outs("\tForEachItemIn(idx, val)\n");
  1186. outs("\t{\n");
  1187. outf("\t\tIConst%s &item = val.item(idx);\n", typname);
  1188. outs("\t\titem.Link();\n");
  1189. outs("\t\ttarget.append(item);\n");
  1190. outs("\t}\n");
  1191. outs("}\n");
  1192. }
  1193. }
  1194. } // flags & PF_TEMPLATE
  1195. else if (kind==TK_ESPSTRUCT)
  1196. {
  1197. outf("IEsp%s & ", typname);
  1198. if (!isDecl && msgname)
  1199. outf("C%s::", msgname);
  1200. outf("update%s()", methName);
  1201. if (isDecl)
  1202. {
  1203. if (isPure)
  1204. outs("=0;\n");
  1205. else
  1206. outs(";\n");
  1207. }
  1208. else
  1209. {
  1210. outf("{ return (IEsp%s &) m_%s.getValue(); }\n", typname, name);
  1211. }
  1212. if (isDecl)
  1213. outs("\t");
  1214. if (isDecl && isPure)
  1215. outs("virtual ");
  1216. outs("void ");
  1217. if (!isDecl && msgname)
  1218. outf("C%s::", msgname);
  1219. outf("set%s(IConst%s &ifrom)", methName, typname);
  1220. if (isDecl)
  1221. {
  1222. if (isPure)
  1223. outs("=0");
  1224. outs(";\n");
  1225. }
  1226. else
  1227. {
  1228. outf("{ m_%s.copy(ifrom); }\n", name);
  1229. }
  1230. }
  1231. else if (kind==TK_ESPENUM)
  1232. {
  1233. outs("void ");
  1234. if (!isDecl && msgname)
  1235. outf("C%s::", msgname);
  1236. outf("set%s(C%s val)",methName, typname);
  1237. if (isDecl)
  1238. {
  1239. if (isPure)
  1240. outs("=0");
  1241. outs(";\n");
  1242. }
  1243. else
  1244. outf(" { m_%s.setValue(val); }\n", name);
  1245. // as string
  1246. if (isDecl && isPure)
  1247. outs("\tvirtual void ");
  1248. else
  1249. outs("void ");
  1250. if (!isDecl && msgname)
  1251. outf("C%s::",msgname);
  1252. outf("set%s(const char* val)", methName);
  1253. if (isDecl)
  1254. {
  1255. if (isPure)
  1256. outs("=0");
  1257. outs(";\n");
  1258. }
  1259. else
  1260. outf(" { m_%s.setValue(val); }\n", name);
  1261. }
  1262. else
  1263. {
  1264. //else
  1265. {
  1266. outs("void ");
  1267. if (!isDecl && msgname)
  1268. outf("C%s::", msgname);
  1269. outf("set%s", methName);
  1270. switch (xlation->eam_type)
  1271. {
  1272. case EAM_jmbuf:
  1273. outf("(%s val, unsigned int len)", xlation->access_type);
  1274. break;
  1275. case EAM_jsbuf:
  1276. //if (xsdType)
  1277. // outf("(%s val, IEspContext& ctx)", xlation->access_type);
  1278. //else
  1279. outf("(%s val)", xlation->access_type);
  1280. break;
  1281. case EAM_jmbin:
  1282. case EAM_basic:
  1283. default:
  1284. outf("(%s val)", xlation->access_type);
  1285. break;
  1286. }
  1287. if (isDecl)
  1288. {
  1289. if (isPure)
  1290. outs("=0");
  1291. outs(";\n");
  1292. }
  1293. else
  1294. {
  1295. //outf("{ m_%s", name);
  1296. switch (xlation->eam_type)
  1297. {
  1298. case EAM_jsbuf:
  1299. // TODO: can not handle ArrayOfXXX yet
  1300. /**
  1301. if (xsdType && strncmp(xsdType,"ArrayOf",7)!=0)
  1302. {
  1303. //do a deserialization to enforce the versioning
  1304. outf("\n{\n");
  1305. outf("\tif (ctx)\n");
  1306. outf("\t{\n");
  1307. outf("\t\tXmlPullParser xpp(val,strlen(val));\n");
  1308. outf("\t\tCRpcMessage msg;\n");
  1309. outf("\t\tmsg.unmarshall(&xpp);\n");
  1310. outf("\t\tStringBuffer s;\n");
  1311. outf("\t\tC%s tmp(\"%s\");\n", xsdType, "XX"); // msgname?: not right
  1312. outf("\t\ttmp.unserialize(msg,NULL,\"%s\");\n", name);
  1313. outf("\t\tC%s::serializer(ctx,tmp,s,false);\n",xsdType);
  1314. outf("\t\tm_%s.set(s.str()%s); \n", name, hasTrim?",true":"");
  1315. outf("\t}\n");
  1316. outf("\telse\n");
  1317. outf("\t\tm_%s.set(val%s);\n",name,hasTrim?",true":"");
  1318. outf("}\n");
  1319. }
  1320. else
  1321. */
  1322. outf("{ m_%s.set(val%s); }\n", name, hasTrim?",true":"");
  1323. break;
  1324. case EAM_jmbin:
  1325. outf("{ m_%s->clear().append(val); }\n", name);
  1326. break;
  1327. case EAM_jmbuf:
  1328. outf("{ m_%s->set(len, val); }\n", name);
  1329. break;
  1330. case EAM_basic:
  1331. default:
  1332. outf("{ m_%s=val; }\n", name);
  1333. break;
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. else // get function
  1340. {
  1341. if (hasNilRemove && xlation->eam_type == EAM_basic && (flags & PF_TEMPLATE)==0 )
  1342. {
  1343. if (isDecl && isPure)
  1344. outs("\tvirtual ");
  1345. outf("bool ");
  1346. if (!isDecl && msgname)
  1347. outf("C%s::", msgname);
  1348. outf("get%s_isNull()", methName);
  1349. if (isDecl)
  1350. outs((isPure) ? "=0;\n" : ";\n");
  1351. else
  1352. outf("{return m_%s.is_nil();}\n", name);
  1353. }
  1354. if (isDecl)
  1355. outs("\t");
  1356. if (isDecl && isPure)
  1357. outs("virtual ");
  1358. if (flags & PF_TEMPLATE)
  1359. {
  1360. outf("%s & ",getArrayImplType());
  1361. if (!isDecl && msgname)
  1362. outf("C%s::",msgname);
  1363. outf("get%s()", methName);
  1364. }
  1365. else if (kind==TK_ESPSTRUCT)
  1366. {
  1367. outf("IConst%s & ", typname);
  1368. if (!isDecl && msgname)
  1369. outf("C%s::", msgname);
  1370. outf("get%s()", methName);
  1371. }
  1372. else if (kind==TK_ESPENUM)
  1373. {
  1374. outf("C%s ", typname);
  1375. if (!isDecl && msgname)
  1376. outf("C%s::", msgname);
  1377. outf("get%s()", methName);
  1378. }
  1379. else
  1380. {
  1381. switch (xlation->eam_type)
  1382. {
  1383. case EAM_jmbuf:
  1384. outs("void ");
  1385. if (!isDecl && msgname)
  1386. outf("C%s::", msgname);
  1387. outf("get%s(%s val, unsigned int len)", methName, xlation->access_type);
  1388. break;
  1389. case EAM_jmbin:
  1390. case EAM_basic:
  1391. case EAM_jsbuf:
  1392. default:
  1393. outf("%s ", xlation->access_type);
  1394. if (!isDecl && msgname)
  1395. outf("C%s::", msgname);
  1396. outf("get%s()", methName);
  1397. break;
  1398. }
  1399. }
  1400. if (isDecl)
  1401. {
  1402. if (isPure)
  1403. outs("=0");
  1404. outs(";\n");
  1405. }
  1406. else
  1407. {
  1408. if (kind==TK_ESPSTRUCT)
  1409. {
  1410. outf(" { return (IConst%s &) m_%s.getValue();}\n", typname, name);
  1411. }
  1412. else if (kind==TK_ESPENUM)
  1413. {
  1414. outf(" { return m_%s.getValue(); }\n", name);
  1415. }
  1416. else if (flags & PF_TEMPLATE)
  1417. {
  1418. outf(" { return (%s &) m_%s; }\n", getArrayImplType(), name);
  1419. }
  1420. else
  1421. {
  1422. switch (xlation->eam_type)
  1423. {
  1424. case EAM_jsbuf:
  1425. outf(" { return m_%s.query();}\n", name);
  1426. break;
  1427. case EAM_jmbuf:
  1428. outf(" { m_%s->read(len, val);}\n", name);
  1429. break;
  1430. case EAM_jmbin:
  1431. outf(" { return m_%s.getValue();}\n", name);
  1432. break;
  1433. case EAM_basic:
  1434. default:
  1435. outf(" { return m_%s;}\n", name);
  1436. break;
  1437. }
  1438. }
  1439. }
  1440. // additonal method
  1441. switch(kind)
  1442. {
  1443. case TK_ESPENUM:
  1444. // getXXAsString
  1445. if (!(flags & PF_TEMPLATE))
  1446. {
  1447. if (isDecl)
  1448. outs("\t");
  1449. if (isDecl && isPure)
  1450. outs("virtual ");
  1451. outs("const char* ");
  1452. if (!isDecl && msgname)
  1453. outf("C%s::", msgname);
  1454. outf("get%sAsString()", methName);
  1455. if (isDecl)
  1456. {
  1457. if (isPure)
  1458. outs("=0");
  1459. outs(";\n");
  1460. }
  1461. else
  1462. outf(" { return (const char*)m_%s; }\n", name);
  1463. }
  1464. break;
  1465. default:
  1466. // nothing to do
  1467. break;
  1468. }
  1469. }
  1470. free(methName);
  1471. }
  1472. void ParamInfo::write_esp_client_impl()
  1473. {
  1474. char *methName=strdup(name);
  1475. *methName=upperchar(*methName);
  1476. outf("\treq->set%s(%s_);\n", methName, name);
  1477. free(methName);
  1478. }
  1479. void ParamInfo::write_esp_param()
  1480. {
  1481. char metatype[256];
  1482. *metatype=0;
  1483. cat_type(metatype);
  1484. esp_xlate_info *xlation=esp_xlat(metatype);
  1485. if (kind==TK_ESPSTRUCT)
  1486. {
  1487. outf("IConst%s &%s_", typname, name);
  1488. }
  1489. else if (kind==TK_ESPENUM)
  1490. {
  1491. outf("C%s %s_", typname, name);
  1492. }
  1493. else
  1494. {
  1495. if (flags & PF_TEMPLATE)
  1496. {
  1497. if (templ && !strcmp(templ, "ESParray"))
  1498. {
  1499. /*if (isEspStringArray())
  1500. outf("StringArray &%s_", name);
  1501. else
  1502. outf("IArrayOf<IConst%s> &%s_", typname, name);
  1503. */
  1504. outf("%s &%s_", getArrayImplType(), name);
  1505. }
  1506. else
  1507. {
  1508. switch (xlation->eam_type)
  1509. {
  1510. case EAM_jmbuf:
  1511. outf("%s %s_, unsigned int %s_len)", xlation->access_type, name, name);
  1512. break;
  1513. case EAM_jmbin:
  1514. case EAM_basic:
  1515. case EAM_jsbuf:
  1516. default:
  1517. outf("%s %s_", xlation->access_type, name);
  1518. break;
  1519. }
  1520. }
  1521. }
  1522. else
  1523. {
  1524. switch (xlation->eam_type)
  1525. {
  1526. case EAM_jmbuf:
  1527. outf("%s %s_, unsigned int %s_len", xlation->access_type, name, name);
  1528. break;
  1529. case EAM_jmbin:
  1530. case EAM_basic:
  1531. case EAM_jsbuf:
  1532. default:
  1533. outf("%s %s_", xlation->access_type, name);
  1534. break;
  1535. }
  1536. }
  1537. }
  1538. }
  1539. void ParamInfo::write_clarion_attr_method(bool isSet)
  1540. {
  1541. ParamInfo *savenext = next;
  1542. char metatype[256]={0};
  1543. esp_xlate_info *xlation = NULL;
  1544. if (isESP && kind==TK_null)
  1545. {
  1546. xlation=esp_xlat(xsdtype);
  1547. if (xlation)
  1548. {
  1549. kind = xlation->access_kind;
  1550. flags |= xlation->access_flags;
  1551. cat_type(metatype);
  1552. }
  1553. }
  1554. else
  1555. {
  1556. cat_type(metatype);
  1557. xlation=esp_xlat(metatype);
  1558. }
  1559. char methName[256]={0};
  1560. const char *httpcont = getMetaString("http_content", NULL);
  1561. if (httpcont!=NULL)
  1562. {
  1563. ParamInfo strparm;
  1564. strparm.name = strdup("mimetype");
  1565. strparm.typname = strdup("const char *");
  1566. if (isSet)
  1567. {
  1568. ProcInfo setProc;
  1569. sprintf(methName, "set%s_mimetype", name);
  1570. methName[3]=upperchar(methName[3]);
  1571. setProc.name = strdup(methName);
  1572. setProc.params = &strparm;
  1573. setProc.out_clarion_method();
  1574. setProc.params = 0;
  1575. }
  1576. else
  1577. {
  1578. ProcInfo setProc;
  1579. sprintf(methName, "get%s_mimetype", name);
  1580. methName[3]=upperchar(methName[3]);
  1581. setProc.name = strdup(methName);
  1582. setProc.rettype = &strparm;
  1583. setProc.out_clarion_method();
  1584. setProc.rettype = 0;
  1585. }
  1586. }
  1587. ParamInfo lenparm;
  1588. lenparm.typname = strdup("unsigned int");
  1589. lenparm.name = strdup("len");
  1590. if (isSet)
  1591. {
  1592. ProcInfo setProc;
  1593. sprintf(methName, "set%s", name);
  1594. methName[3]=upperchar(methName[3]);
  1595. setProc.name = strdup(methName);
  1596. next = 0;
  1597. setProc.params = this;
  1598. switch (xlation->eam_type)
  1599. {
  1600. case EAM_jmbuf:
  1601. {
  1602. next = &lenparm;
  1603. setProc.out_clarion_method();
  1604. next=0;
  1605. break;
  1606. }
  1607. case EAM_jmbin:
  1608. case EAM_basic:
  1609. case EAM_jsbuf:
  1610. default:
  1611. setProc.out_clarion_method();
  1612. break;
  1613. }
  1614. setProc.params = 0;
  1615. }
  1616. else
  1617. {
  1618. ProcInfo getProc;
  1619. sprintf(methName, "get%s", name);
  1620. methName[3]=upperchar(methName[3]);
  1621. getProc.name = strdup(methName);
  1622. switch (xlation->eam_type)
  1623. {
  1624. case EAM_jmbuf:
  1625. {
  1626. next = 0;
  1627. getProc.params = this;
  1628. outf("void get%s(%s val, unsigned int len)", methName, xlation->access_type);
  1629. next = &lenparm;
  1630. getProc.out_clarion_method();
  1631. break;
  1632. }
  1633. case EAM_jmbin:
  1634. case EAM_basic:
  1635. case EAM_jsbuf:
  1636. default:
  1637. getProc.rettype = this;
  1638. getProc.out_clarion_method();
  1639. break;
  1640. }
  1641. getProc.params=0;
  1642. getProc.rettype=0;
  1643. }
  1644. next=savenext;
  1645. }
  1646. bool ParamInfo::write_mapinfo_check(int indents, const char* ctxvar)
  1647. {
  1648. StrBuffer minVer, maxVer, deprVer;
  1649. bool hasMin = getMetaVerInfo("min_ver", minVer);
  1650. bool hasMax = getMetaVerInfo("max_ver", maxVer);
  1651. bool hasDepr = getMetaVerInfo("depr_ver", deprVer);
  1652. bool hasOutput = false;
  1653. if (hasMin || hasDepr || hasMax)
  1654. {
  1655. hasOutput = true;
  1656. indent(indents);
  1657. outs("if ((clientVer==-1.0");
  1658. if (hasMin)
  1659. {
  1660. if (hasDepr)
  1661. outf(" || (clientVer>=%s && clientVer<%s))", minVer.str(), deprVer.str());
  1662. else if (hasMax)
  1663. outf(" || (clientVer>=%s && clientVer<=%s))", minVer.str(), maxVer.str());
  1664. else
  1665. outf(" || clientVer>=%s)", minVer.str());
  1666. }
  1667. else if (hasDepr)
  1668. outf(" || clientVer<%s)", deprVer.str());
  1669. else // maxVer>0
  1670. outf(" || clientVer<=%s)", maxVer.str());
  1671. }
  1672. if (ctxvar)
  1673. {
  1674. const char* optional = getMetaString("optional",NULL);
  1675. if (optional)
  1676. {
  1677. if (hasOutput)
  1678. outs(" && ");
  1679. else
  1680. {
  1681. indent(indents);
  1682. outs("if (");
  1683. hasOutput = true;
  1684. }
  1685. const char* quote = (*optional == '"') ? "":"\"";
  1686. outf("(!ctx || %s->checkOptional(%s%s%s))", ctxvar, quote,optional,quote);
  1687. }
  1688. }
  1689. if (hasOutput)
  1690. outs(")\n");
  1691. return hasOutput;
  1692. }
  1693. void ParamInfo::write_esp_marshall(bool isRpc, bool encodeXml, bool checkVer, int indents)
  1694. {
  1695. const char *soap_path=getMetaString("soap_path", NULL);
  1696. char *path = (soap_path!=NULL) ? strdup(soap_path) : NULL;
  1697. char *tagname = NULL;
  1698. if (path)
  1699. {
  1700. path[strlen(path)-1]=0;
  1701. path++;
  1702. tagname=strrchr(path, '/');
  1703. if (tagname)
  1704. {
  1705. *tagname=0;
  1706. tagname++;
  1707. }
  1708. else
  1709. {
  1710. tagname=path;
  1711. path= (char *) ""; // cast to kill a warning. Could recode to avoid more cleanly but this is obsolete code anyway
  1712. }
  1713. }
  1714. if (checkVer)
  1715. {
  1716. if (write_mapinfo_check(indents,"ctx"))
  1717. indents++;
  1718. }
  1719. if (!isEspArrayOf() && getMetaInt("encode_newlines", -1)!=-1)
  1720. {
  1721. indent(indents);
  1722. outf("m_%s.setEncodeNewlines(true);\n", name);
  1723. }
  1724. indent(indents);
  1725. if (isRpc)
  1726. outf("m_%s.marshall(rpc_resp, ", name);
  1727. else
  1728. outf("m_%s.toStr(ctx, buffer, ", name);
  1729. if (isEspArrayOf())
  1730. {
  1731. if (path)
  1732. outf("\"%s\", \"%s\", \"%s\");\n", tagname, getArrayItemTag(), path);
  1733. else
  1734. outf("\"%s\", \"%s\");\n", getXmlTag(), getArrayItemTag());
  1735. }
  1736. else
  1737. {
  1738. const char *prefix = getMetaString("ns_var", "\"\"");
  1739. const char *encode = encodeXml ? "true" : "false";
  1740. if (path)
  1741. {
  1742. outf("\"%s\", \"%s\"", tagname, path);
  1743. if (isRpc)
  1744. outf(", \"\", %s", prefix);
  1745. else if (kind!=TK_ESPSTRUCT)
  1746. outf(", %s", encode);
  1747. outs(");\n");
  1748. }
  1749. else if (!getMetaInt("attribute"))
  1750. {
  1751. outf("\"%s\", \"\", ", getXmlTag());
  1752. if (isRpc)
  1753. outf("\"\", %s);\n", prefix);
  1754. else if (kind==TK_ESPSTRUCT)
  1755. outf("false, \"\", %s);\n", prefix);
  1756. else
  1757. {
  1758. outf("%s, \"\", %s", encode, prefix);
  1759. if (getMetaInt("json_inline"))
  1760. outs(", false");
  1761. outs(");\n");
  1762. }
  1763. }
  1764. }
  1765. }
  1766. const char* ParamInfo::getOptionalParam()
  1767. {
  1768. static StrBuffer optGroup;
  1769. StrBuffer optional;
  1770. optGroup.clear();
  1771. if (getMetaStringValue(optional,"optional"))
  1772. optGroup.appendf(", \"%s\"", optional.str());
  1773. return optGroup.str();
  1774. }
  1775. void ParamInfo::write_esp_unmarshall(const char *rpcvar, bool useBasePath, int indents)
  1776. {
  1777. const char *soap_path=getMetaString("soap_path", NULL);
  1778. char *path = (soap_path!=NULL) ? strdup(soap_path) : NULL;
  1779. if (path && *path)
  1780. {
  1781. path[strlen(path)-1]=0;
  1782. path++;
  1783. char *tagname=strrchr((char *)path, '/');
  1784. indent(indents);
  1785. if (tagname)
  1786. {
  1787. *tagname=0;
  1788. tagname++;
  1789. outf("hasValue |= m_%s.unmarshall(%s, \"%s\", \"%s\"%s);\n", name, rpcvar, tagname, path, getOptionalParam());
  1790. }
  1791. else
  1792. {
  1793. outf("hasValue |= m_%s.unmarshall(%s, \"%s\"%s);\n", name, rpcvar, path, getOptionalParam());
  1794. }
  1795. }
  1796. else
  1797. {
  1798. bool isAttr = getMetaInt("attribute")!=0;
  1799. indent(indents);
  1800. outf("hasValue |= m_%s.unmarshall(%s, \"%s%s\"%s%s);\n", name, rpcvar, isAttr ? "@" : "",getXmlTag(), (useBasePath) ? ", basepath" : "", getOptionalParam());
  1801. }
  1802. free(path);
  1803. }
  1804. void ParamInfo::write_esp_unmarshall_properties(const char *propvar, const char *attachvar, int indents)
  1805. {
  1806. indent(indents);
  1807. const char* at = getMetaInt("attribute") ? "@" : "";
  1808. outf("hasValue |= m_%s.unmarshall(ctx, %s, %s, \"%s%s\", basepath%s);\n", name, propvar, attachvar, at, getXmlTag(), getOptionalParam());
  1809. }
  1810. void ParamInfo::write_esp_unmarshall_attachments(const char *propvar, const char *attachvar, int indents)
  1811. {
  1812. indent(indents);
  1813. const char* at = getMetaInt("attribute") ? "@" : "";
  1814. outf("hasValue |= m_%s.unmarshallAttach(ctx, %s, %s, \"%s%s\", basepath%s);\n", name, propvar, attachvar, at, getXmlTag(), getOptionalParam());
  1815. }
  1816. void ParamInfo::write_esp_unmarshall_soapval(const char *var, int indents)
  1817. {
  1818. indent(indents);
  1819. const char* at = getMetaInt("attribute") ? "@" : "";
  1820. outf("hasValue |= m_%s.unmarshall(ctx, %s, \"%s%s\"%s);\n", name, var, at, getXmlTag(), getOptionalParam());
  1821. }
  1822. //-------------------------------------------------------------------------------------------------------------
  1823. // class ProcInfo
  1824. ProcInfo::ProcInfo()
  1825. {
  1826. name = NULL;
  1827. rettype = NULL;
  1828. params = NULL;
  1829. next = NULL;
  1830. conntimeout = NULL;
  1831. calltimeout = NULL;
  1832. async = 0;
  1833. callback = 0;
  1834. virt = 0;
  1835. constfunc = 0;
  1836. }
  1837. ProcInfo::~ProcInfo()
  1838. {
  1839. if (name)
  1840. free(name);
  1841. if (conntimeout)
  1842. free(conntimeout);
  1843. if (calltimeout)
  1844. free(calltimeout);
  1845. delete rettype;
  1846. delete params;
  1847. delete next;
  1848. }
  1849. void ProcInfo::out_clarion_parameter_list()
  1850. {
  1851. outs("(");
  1852. ParamInfo * p=params;
  1853. while (p) {
  1854. p->out_clarion_parameter();
  1855. p = p->next;
  1856. if (p)
  1857. outs(", ");
  1858. }
  1859. outs(")");
  1860. }
  1861. void ProcInfo::out_clarion_method()
  1862. {
  1863. outf("%-15s PROCEDURE",xlat(name));
  1864. out_clarion_parameter_list();
  1865. if (rettype)
  1866. {
  1867. outs(",");
  1868. rettype->out_clarion_type(true);
  1869. }
  1870. if (isSCM)
  1871. outs(",PROC\n");
  1872. else
  1873. outs(",PASCAL\n");
  1874. }
  1875. void ProcInfo::out_method(const char *classpfx, int omitvirt)
  1876. {
  1877. if (virt&&!omitvirt)
  1878. {
  1879. if (callback)
  1880. outf("HRPCvirtualcallback ");
  1881. else
  1882. outf("virtual ");
  1883. }
  1884. if (rettype==NULL)
  1885. outs("void");
  1886. else
  1887. rettype->out_type();
  1888. if (classpfx)
  1889. outf(" %s::%s",classpfx,name);
  1890. else
  1891. outf(" %s",name);
  1892. out_parameter_list("");
  1893. if (constfunc)
  1894. {
  1895. if (isSCM)
  1896. outf(" const");
  1897. else
  1898. outf(" /* const (omitted by HIDL) */");
  1899. }
  1900. if ((virt==2)&&!omitvirt)
  1901. {
  1902. if (isSCM)
  1903. outf(" = 0");
  1904. else
  1905. outf(" HRPCpure%s", callback ? "callback" : "");
  1906. }
  1907. }
  1908. void ProcInfo::out_parameter_list(const char *pfx,int forclarion)
  1909. {
  1910. outs("(");
  1911. ParamInfo * p = params;
  1912. while (p)
  1913. {
  1914. p->out_parameter(pfx, forclarion);
  1915. p = p->next;
  1916. if (p)
  1917. outs(", ");
  1918. }
  1919. outs(")");
  1920. }
  1921. void ProcInfo::write_body_method_structs2(const char * modname)
  1922. {
  1923. // buffer structure
  1924. outf("struct HRPC_d_%s__%s\n{\n",modname,name);
  1925. ParamInfo *p;
  1926. lastin=NULL;
  1927. firstin=NULL;
  1928. ForEachParam(this,p,0,0)
  1929. p->flags &= ~PF_SIMPLE;
  1930. size_t align=0;
  1931. int dummy = 0;
  1932. ForEachParam(this,p,PF_IN,PF_OUT|PF_REF|PF_PTR|PF_VARSIZE) {
  1933. p->flags |= PF_SIMPLE;
  1934. lastin = p;
  1935. if (!firstin)
  1936. firstin = p;
  1937. size_t a=p->typesizealign(align);
  1938. if (a>0) {
  1939. dummy++;
  1940. if (a>1)
  1941. outf("\tchar __dummy%d[%u];\n",dummy,(unsigned)a);
  1942. else
  1943. outf("\tchar __dummy%d;\n",dummy);
  1944. }
  1945. p->write_body_struct_elem(0);
  1946. }
  1947. if (align>0) {
  1948. dummy++;
  1949. outf("\tchar _dummy%d[%u];\n",dummy,(unsigned)(4-align));
  1950. align = 0;
  1951. }
  1952. ForEachParam(this,p,PF_IN,PF_OUT|PF_SIMPLE) {
  1953. p->write_body_struct_elem(1);
  1954. }
  1955. ForEachParam(this,p,PF_IN|PF_OUT,PF_SIMPLE) {
  1956. p->write_body_struct_elem(1);
  1957. }
  1958. ForEachParam(this,p,PF_OUT,PF_IN|PF_SIMPLE) {
  1959. p->write_body_struct_elem(1);
  1960. }
  1961. if (rettype) {
  1962. rettype->typesizealign(align);
  1963. rettype->write_body_struct_elem(0);
  1964. if (align>0) {
  1965. dummy++;
  1966. outf("\tchar _dummy%d[%u];\n",dummy,(unsigned)(4-align));
  1967. align = 0;
  1968. }
  1969. }
  1970. int swapp=write_body_swapparam();
  1971. write_body_pushparam(swapp);
  1972. write_body_popparam(swapp);
  1973. if (!async) {
  1974. write_body_pushreturn();
  1975. write_body_popreturn();
  1976. }
  1977. // now constructors
  1978. outf("\tHRPC_d_%s__%s() {}\n",modname,name);
  1979. if (params) {
  1980. outf("\tHRPC_d_%s__%s",modname,name);
  1981. out_parameter_list("_");
  1982. outs(": ");
  1983. ForEachParam(this,p,0,0) {
  1984. outf("%s(",p->name);
  1985. if (p->flags&PF_REF) {
  1986. outs("&");
  1987. }
  1988. else if ((p->flags&(PF_PTR&PF_CONST))==(PF_PTR&PF_CONST)) {
  1989. p->write_param_convert();
  1990. }
  1991. outf("_%s)",p->name);
  1992. if (p->next)
  1993. outs(", ") ;
  1994. }
  1995. outs("\n\t{\n");
  1996. outs("\t};");
  1997. }
  1998. outs("\n};\n");
  1999. }
  2000. void ProcInfo::write_body_popparam(int swapp)
  2001. {
  2002. outs("\tvoid popparams(HRPCbuffer &_b)\n\t{\n");
  2003. if (lastin) {
  2004. outf("\t\t_b.read(&%s,",firstin->name);
  2005. write_head_size();
  2006. outs(");\n");
  2007. }
  2008. int needensure=0;
  2009. ParamInfo *p;
  2010. ForEachParam(this,p,PF_OUT,PF_IN|PF_SIMPLE) {
  2011. if (needensure) {
  2012. outs("\t\t\t+");
  2013. }
  2014. else {
  2015. outs("\t\t_b.ensure(\n");
  2016. outs("\t\t\t");
  2017. needensure = 1;
  2018. }
  2019. if ((p->flags&PF_VARSIZE)&&!(INDIRECTSIZE(p))) {
  2020. outf("(%s)\n",p->bytesize());
  2021. }
  2022. else {
  2023. outf("sizeof(*%s)\n",p->name);
  2024. }
  2025. }
  2026. if (needensure) {
  2027. outs("\t\t);\n");
  2028. }
  2029. ForEachParam(this,p,PF_OUT,PF_IN|PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2030. outf("\t\t%s = ",p->name);
  2031. p->write_param_convert();
  2032. outf("_b.writeptr(sizeof(*%s));\n",p->name);
  2033. }
  2034. ForEachParam(this,p,PF_OUT|PF_STRING,0) {
  2035. outf("\t\t%s = ",p->name);
  2036. p->write_param_convert();
  2037. outf("_b.writeptr(sizeof(*%s));\n",p->name);
  2038. outf("\t\t*%s = 0;\n",p->name);
  2039. }
  2040. ForEachParam(this,p,PF_IN,PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2041. outf("\t\t%s = ",p->name);
  2042. p->write_param_convert();
  2043. outf("_b.readptr(sizeof(*%s));\n",p->name);
  2044. outf("\t\t\t//_b.readptrrev(sizeof(*%s));\n",p->name);
  2045. }
  2046. ForEachParam(this,p,PF_IN|PF_STRING,PF_SIMPLE|PF_VARSIZE) {
  2047. outf("\t\t%s = _b.readstrptr();\n",p->name);
  2048. }
  2049. // now dynamic sizes
  2050. ForEachParam(this,p,PF_VARSIZE|PF_IN,0) {
  2051. outf("\t\t%s = ",p->name);
  2052. p->write_param_convert();
  2053. if (INDIRECTSIZE(p)) {
  2054. // should handle size_t* as well as ref
  2055. outs("_b.readptr(sizeof");
  2056. p->write_param_convert();
  2057. outs(")\n");
  2058. }
  2059. else {
  2060. outf("_b.readptr(%s);\n",p->bytesize());
  2061. }
  2062. }
  2063. ForEachParam(this,p,PF_OUT|PF_VARSIZE,PF_IN|PF_SIMPLE) {
  2064. outf("\t\t%s = ",p->name);
  2065. p->write_param_convert();
  2066. outs("_b.writeptr(");
  2067. if ((p->flags&PF_VARSIZE)&&!(INDIRECTSIZE(p))) {
  2068. outf("%s);\n",p->bytesize());
  2069. }
  2070. else {
  2071. outf("sizeof(*%s));\n",p->name);
  2072. }
  2073. }
  2074. if (swapp)
  2075. outs("\t\t//swapparams();\n");
  2076. outs("\t}\n\n");
  2077. }
  2078. void ProcInfo::write_body_popreturn()
  2079. {
  2080. if (!async) {
  2081. outs("\tvoid popreturn(HRPCbuffer &_b)\n\t{\n");
  2082. ParamInfo *p;
  2083. ForEachParam(this,p,PF_OUT,PF_SIMPLE|PF_VARSIZE|PF_RETURN|PF_STRING) {
  2084. outf("\t\t_b.read(%s,sizeof(*%s));\n",p->name,p->name);
  2085. }
  2086. ForEachParam(this,p,PF_OUT|PF_STRING,0) {
  2087. outf("\t\t*%s = _b.readstrdup();\n",p->name);
  2088. }
  2089. // now dynamic sizes
  2090. ForEachParam(this,p,PF_VARSIZE|PF_OUT,0) {
  2091. if (INDIRECTSIZE(p)) {
  2092. outf("\t\t*%s = ",p->name);
  2093. p->write_param_convert(1);
  2094. outf("malloc(%s);\n",p->bytesize(1));
  2095. outf("\t\t_b.read(*%s,%s);\n",p->name,p->bytesize(1));
  2096. }
  2097. else {
  2098. outf("\t\t_b.read(%s,%s);\n",p->name,p->bytesize());
  2099. }
  2100. }
  2101. p = rettype;
  2102. if (p) {
  2103. if ((p->flags&(PF_PTR|PF_STRING))==(PF_PTR|PF_STRING)) {
  2104. outf("\t\t%s = _b.readstrdup();\n",p->name);
  2105. }
  2106. else if (p->flags&PF_PTR) {
  2107. outf("\t\t%s = ",p->name);
  2108. p->write_param_convert();
  2109. outf("malloc(%s);\n",p->bytesize(1));
  2110. outf("\t\t_b.read(%s,%s);\n",p->name,p->bytesize(1));
  2111. }
  2112. else {
  2113. outf("\t\t_b.read(&%s,sizeof(%s));\n",p->name,p->name);
  2114. }
  2115. }
  2116. outs("\t}\n\n");
  2117. }
  2118. }
  2119. int ProcInfo::write_body_swapparam()
  2120. {
  2121. int ret=0;
  2122. ParamInfo *p;
  2123. ForEachParam(this,p,PF_IN|PF_SIMPLE,PF_VARSIZE|PF_STRING) {
  2124. if(p->simpleneedsswap()) {
  2125. if (!ret) {
  2126. outs("\tvoid swapparams()\n\t{\n");
  2127. ret = 1;
  2128. }
  2129. outf("\t\t_WINREV%d(%s);\n",type_size[p->kind],p->name);
  2130. }
  2131. }
  2132. if (ret)
  2133. outs("\t}\n\n");
  2134. return ret;
  2135. }
  2136. void ProcInfo::write_body_pushparam(int swapp)
  2137. {
  2138. outs("\tvoid pushparams(HRPCbuffer &_b)\n\t{\n");
  2139. if (swapp)
  2140. outs("\t\t//swapparams();\n");
  2141. if (lastin) {
  2142. outf("\t\t_b.write(&%s,",firstin->name);
  2143. write_head_size();
  2144. outs(");\n");
  2145. }
  2146. ParamInfo *p;
  2147. ForEachParam(this,p,PF_IN,PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2148. if (p->simpleneedsswap()) {
  2149. outf("\t\t//_b.writerev(%s,sizeof(*%s));\n",p->name,p->name);
  2150. outf("\t\t_b.write(%s,sizeof(*%s));\n",p->name,p->name);
  2151. }
  2152. else
  2153. outf("\t\t_b.write(%s,sizeof(*%s));\n",p->name,p->name);
  2154. }
  2155. ForEachParam(this,p,PF_IN|PF_STRING,PF_SIMPLE|PF_VARSIZE) {
  2156. outf("\t\t_b.writestr(%s);\n",p->name);
  2157. }
  2158. // now dynamic sizes
  2159. ForEachParam(this,p,PF_VARSIZE|PF_IN,0) {
  2160. if (INDIRECTSIZE(p)) {
  2161. // should handle size_t* as well as ref
  2162. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize());
  2163. }
  2164. else {
  2165. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize());
  2166. }
  2167. }
  2168. outs("\t}\n\n");
  2169. }
  2170. void ProcInfo::write_body_pushreturn()
  2171. {
  2172. if (!async) {
  2173. outs("\tvoid pushreturn(HRPCbuffer &_b)\n\t{\n");
  2174. ParamInfo *p;
  2175. ForEachParam(this,p,PF_OUT,PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2176. outf("\t\t_b.write(%s,sizeof(*%s));\n",p->name,p->name);
  2177. }
  2178. ForEachParam(this,p,PF_OUT|PF_STRING,0) {
  2179. outf("\t\t_b.writestr(*%s);\n",p->name);
  2180. outf("\t\tfree(*%s);\n",p->name);
  2181. }
  2182. // now dynamic sizes
  2183. ForEachParam(this,p,PF_VARSIZE|PF_OUT,0) {
  2184. if (INDIRECTSIZE(p)) {
  2185. // should handle size_t* as well as ref
  2186. outf("\t\t_b.write(*%s,%s);\n",p->name,p->bytesize(1));
  2187. outf("\t\tfree(*%s);\n",p->name);
  2188. }
  2189. else {
  2190. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize());
  2191. }
  2192. }
  2193. p = rettype;
  2194. if (p) {
  2195. if ((p->flags&(PF_PTR|PF_STRING))==(PF_PTR|PF_STRING)) {
  2196. outf("\t\t_b.writestr(%s);\n",p->name);
  2197. outf("\t\tfree(%s);\n",p->name);
  2198. }
  2199. else if (p->flags&PF_PTR) {
  2200. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize(1));
  2201. outf("\t\tfree(%s);\n",p->name);
  2202. }
  2203. else {
  2204. outf("\t\t_b.write(&%s,sizeof(%s));\n",p->name,p->name);
  2205. }
  2206. }
  2207. outs("\t}\n\n");
  2208. }
  2209. }
  2210. void ProcInfo::write_head_size()
  2211. // used for simple types only at the head of the packet
  2212. {
  2213. if (lastin) {
  2214. char sz[2048];
  2215. sz[0] = 0;
  2216. size_t sza=0;
  2217. ParamInfo *p=params;
  2218. ParamInfo *lp=NULL;
  2219. while (1) {
  2220. if (p->flags&PF_SIMPLE) {
  2221. lp = p;
  2222. }
  2223. if(p==lastin)
  2224. break;
  2225. p = p->next;
  2226. }
  2227. if (lp==NULL)
  2228. outs("0");
  2229. else if (lp!=firstin)
  2230. outf("sizeof(%s)+(byte *)&%s-(byte *)&%s",lp->name,lp->name,firstin->name);
  2231. else
  2232. outf("sizeof(%s)",firstin->name);
  2233. }
  2234. else
  2235. outs("0");
  2236. }
  2237. //-------------------------------------------------------------------------------------------------------------
  2238. // class ApiInfo
  2239. ApiInfo::ApiInfo(const char *n)
  2240. {
  2241. name = NULL;
  2242. group = strdup(n);
  2243. proc = NULL;
  2244. next = NULL;
  2245. }
  2246. ApiInfo::~ApiInfo()
  2247. {
  2248. if (name)
  2249. free(name);
  2250. if (proc)
  2251. delete proc;
  2252. if (group)
  2253. free(group);
  2254. delete next;
  2255. }
  2256. void ApiInfo::write_header_method()
  2257. {
  2258. ProcInfo *pi = proc;
  2259. if (!pi->callback)
  2260. {
  2261. outf("extern \"C\" %s_API ", group);
  2262. pi->rettype->out_type();
  2263. outf(" %s", pi->name);
  2264. pi->out_parameter_list("");
  2265. outs(";\n");
  2266. }
  2267. }
  2268. void ApiInfo::write_clarion_include_method()
  2269. {
  2270. ProcInfo *pi = proc;
  2271. if (!pi->callback)
  2272. {
  2273. outf(" %s ",xlat(pi->name));
  2274. pi->out_clarion_parameter_list();
  2275. if (pi->rettype)
  2276. {
  2277. outs(",");
  2278. pi->rettype->out_clarion_type(true);
  2279. }
  2280. ParamInfo *pa;
  2281. unsigned sizeOfParms=0;
  2282. ForEachParam(pi, pa, 0, 0)
  2283. {
  2284. if (pa->flags&(PF_PTR|PF_REF))
  2285. sizeOfParms+=4;
  2286. else
  2287. sizeOfParms+=type_size[pa->kind];
  2288. }
  2289. outf(", pascal, raw, name('_%s@%d')\n", pi->name,sizeOfParms);
  2290. }
  2291. }
  2292. //-------------------------------------------------------------------------------------------------------------
  2293. // class ModuleInfo
  2294. ModuleInfo::ModuleInfo(const char *n)
  2295. {
  2296. name = strdup(n);
  2297. base = NULL;
  2298. version = 0;
  2299. procs = NULL;
  2300. next = NULL;
  2301. isSCMinterface=false;
  2302. }
  2303. ModuleInfo::~ModuleInfo()
  2304. {
  2305. free(name);
  2306. if (base)
  2307. free(base);
  2308. delete procs;
  2309. delete next;
  2310. }
  2311. void ModuleInfo::write_body_class()
  2312. {
  2313. outf("// class %s \n\n",name);
  2314. outf("static struct HRPCmoduleid _id_%s = { { ",name);
  2315. char *mn = name;
  2316. for (int i=0;i<8;i++)
  2317. {
  2318. if (i)
  2319. outs(", ");
  2320. if (*mn) {
  2321. outf("'%c'",*mn);
  2322. mn++;
  2323. }
  2324. else
  2325. outs("0");
  2326. }
  2327. outf("}, %d };\n\n",version);
  2328. int fn=0;
  2329. for (ProcInfo *pi=procs; pi; pi=pi->next)
  2330. {
  2331. fn++;
  2332. pi->write_body_method_structs2(name);
  2333. }
  2334. outs("\n");
  2335. outf("%s::%s() { _id = &_id_%s; }\n\n",name,name,name);
  2336. outf("#ifdef LOCAL_%s // Stub(%s):\n\n",name,name);
  2337. write_body_class_stub(0);
  2338. write_body_class_proxy(1);
  2339. outf("#else // Proxy(%s):\n\n",name);
  2340. write_body_class_proxy(0);
  2341. write_body_class_stub(1);
  2342. outf("\n#endif // end class %s\n",name);
  2343. }
  2344. void ModuleInfo::write_body_class_proxy(int cb)
  2345. {
  2346. int fn = 0;
  2347. ProcInfo *pi;
  2348. for (pi=procs; pi; pi=pi->next) {
  2349. fn++;
  2350. if (cb!=pi->callback)
  2351. continue;
  2352. pi->out_method(name,true);
  2353. outs("\n{\n");
  2354. if (pi->callback) {
  2355. outs("\tHRPCcallframe _callframe(&_server->Sync(),cbbuff);\n");
  2356. }
  2357. else {
  2358. outs("\tHRPCcallframe _callframe(sync,inbuff);\n");
  2359. }
  2360. outf("\tHRPC_d_%s__%s _params",name,pi->name);
  2361. if (pi->params) {
  2362. outs("(");
  2363. ParamInfo *p;
  2364. ForEachParam(pi,p,0,0) {
  2365. outf("%s",p->name);
  2366. if (p->next)
  2367. outs(", ");
  2368. }
  2369. outs(")");
  2370. }
  2371. outs(";\n");
  2372. if (pi->conntimeout&&*pi->conntimeout) {
  2373. outf("\tTryConnect(%s,false);\n",pi->conntimeout);
  2374. }
  2375. if (pi->calltimeout&&*pi->calltimeout) {
  2376. outf("\tSetCallTimeLimit(%s);\n",pi->calltimeout);
  2377. }
  2378. if (pi->callback) {
  2379. outs("\t_params.pushparams(cbbuff);\n");
  2380. outf("\t_callbackproxy(_callframe,%d);\n",fn);
  2381. if (!pi->async)
  2382. outs("\t_params.popreturn(cbbuff);\n");
  2383. }
  2384. else {
  2385. outs("\t_params.pushparams(inbuff);\n");
  2386. outf("\t_proxy(_callframe,%d);\n",fn);
  2387. if (!pi->async)
  2388. outs("\t_params.popreturn(inbuff);\n");
  2389. }
  2390. if (pi->rettype) {
  2391. outf("\treturn _params.%s;\n",RETURNNAME);
  2392. }
  2393. outs("}\n\n");
  2394. }
  2395. outs("\n\n");
  2396. }
  2397. void ModuleInfo::write_body_class_stub(int cb)
  2398. {
  2399. outf("void %s::_%sstub(HRPCbuffer &_b,HRPCbuffer &_br,int fn)\n{\n",name,cb?"callback":"");
  2400. int fn=0;
  2401. int switchdone = 0;
  2402. ProcInfo *pi;
  2403. for (pi=procs; pi; pi=pi->next) {
  2404. fn++;
  2405. if (cb!=pi->callback)
  2406. continue;
  2407. if (!switchdone) {
  2408. outs("\tswitch(fn) {\n");
  2409. switchdone = 1;
  2410. }
  2411. outf("\tcase %d: {\n",fn);
  2412. outf("\t\t\tHRPC_d_%s__%s _params;\n",name,pi->name);
  2413. outs("\t\t\t_params.popparams(_b);\n");
  2414. if (pi->async) {
  2415. outs("\t\t\t_returnasync(_br);\n");
  2416. }
  2417. outs("\t\t\t");
  2418. if (pi->rettype) {
  2419. outf("_params.%s = ",RETURNNAME);
  2420. }
  2421. outf("%s(",pi->name);
  2422. ParamInfo *p;
  2423. ForEachParam(pi,p,0,0) {
  2424. if (p->flags&PF_REF)
  2425. outs("*");
  2426. outf("_params.%s",p->name);
  2427. if (p->next)
  2428. outs(", ");
  2429. }
  2430. outs(");\n");
  2431. if (!pi->async) {
  2432. outs("\t\t\t_returnOK(_br);\n");
  2433. outs("\t\t\t_params.pushreturn(_br);\n");
  2434. }
  2435. outs("\t\t\tbreak;\n");
  2436. outs("\t\t}\n");
  2437. }
  2438. if (switchdone) {
  2439. outs("\t}\n");
  2440. }
  2441. outs("}\n\n");
  2442. }
  2443. void ModuleInfo::write_clarion_include_module()
  2444. {
  2445. if (isSCM) {
  2446. char _name[256];
  2447. toClaInterface(_name, name);
  2448. if (base) {
  2449. char _base[256];
  2450. toClaInterface(_base, base);
  2451. outf("%s INTERFACE(%s),COM\n", _name, _base);
  2452. }
  2453. else
  2454. outf("%s INTERFACE,COM\n", _name);
  2455. }
  2456. else
  2457. outf("HRPCI_%s INTERFACE(HRPCI_Clarion_Module)\n",name);
  2458. ProcInfo *pi;
  2459. for (pi=procs; pi; pi=pi->next) {
  2460. if (pi->callback)
  2461. continue;
  2462. outf("%-15s PROCEDURE",xlat(pi->name));
  2463. pi->out_clarion_parameter_list();
  2464. if (pi->rettype) {
  2465. outs(",");
  2466. pi->rettype->out_clarion_type(true);
  2467. }
  2468. if (isSCM)
  2469. outs(",PROC\n");
  2470. else
  2471. outs(",PASCAL\n");
  2472. }
  2473. outs("END\n\n");
  2474. }
  2475. void ModuleInfo::write_clarion_scm_stub_class()
  2476. {
  2477. outf("// clarion interface stub for %s \n",name);
  2478. outf("class SCMCLWSTUB_%s: public SCMStubBase, implements %s // interface\n",name,name);
  2479. outf("\t%s &_o;\n",name);
  2480. outf("public:\n");
  2481. outf("\tIMPLEMENT_SCMSTUBBASE\n");
  2482. outf("\tSCMCLW_%s(%s *_if) : SCMStubBase(_if), _o(*LINK(_if)) { } \n",name,name);
  2483. outf("\t~SCMCLW_%s() { _o.Release(); } \n",name);
  2484. ProcInfo *pi;
  2485. for (pi=procs; pi; pi=pi->next) {
  2486. if (pi->callback)
  2487. continue;
  2488. outs("\t");
  2489. if (pi->rettype==NULL)
  2490. {
  2491. outs("void");
  2492. }
  2493. else
  2494. pi->rettype->out_type();
  2495. outf(" _stdcall %s",pi->name);
  2496. pi->out_parameter_list("",1);
  2497. outs("\n");
  2498. outs("\t{\n");
  2499. outs("\t\tSCMCLW_INTRO;\n");
  2500. outf("#ifdef SCMCLW_INTRO_%s_%s;\n",name,pi->name);
  2501. outf("\t\tSCMCLW_INTRO_%s_%s;\n",name,pi->name);
  2502. outs("#endif\n");
  2503. if (pi->rettype) {
  2504. outs("\t");
  2505. pi->rettype->write_body_struct_elem(0);
  2506. outs("\t\t_return = ");
  2507. }
  2508. else
  2509. outs("\t\t");
  2510. outf("_o.%s(",pi->name);
  2511. ParamInfo *p;
  2512. ForEachParam(pi,p,0,0) {
  2513. outf("%s",p->name);
  2514. if (p->next)
  2515. outs(", ");
  2516. }
  2517. outs(");\n");
  2518. outf("#ifdef SCMCLW_OUTRO_%s_%s;\n",name,pi->name);
  2519. outf("\t\tSCMCLW_OUTRO_%s_%s;\n",name,pi->name);
  2520. outs("#endif\n");
  2521. outs("\t\tSCMCLW_OUTRO;\n");
  2522. if (pi->rettype) {
  2523. outs("\t\treturn _return;");
  2524. }
  2525. outs("\t}\n");
  2526. }
  2527. outs("};\n");
  2528. }
  2529. void ModuleInfo::write_clarion_interface_class()
  2530. {
  2531. outs("extern \"C\" {\n\n");
  2532. outs("\n");
  2533. outf("// clarion interface class CIC_%s \n",name);
  2534. outf("struct HRPCI_%s: public HRPCI_Clarion_Module // interface\n",name);
  2535. ProcInfo *pi;
  2536. outs("{\n");
  2537. for (pi=procs; pi; pi=pi->next) {
  2538. if (pi->callback)
  2539. continue;
  2540. outs("\tvirtual ");
  2541. if (pi->rettype==NULL)
  2542. {
  2543. outs("void");
  2544. }
  2545. else
  2546. pi->rettype->out_type();
  2547. outf(" _stdcall %s",pi->name);
  2548. pi->out_parameter_list("",1);
  2549. outs("=0;\n");
  2550. }
  2551. outs("};\n");
  2552. outf("#ifndef LOCAL_%s\n\n",name);
  2553. outf("class CIC_%s : public HRPCI_%s\n",name,name);
  2554. outs("{\n");
  2555. outs("public:\n");
  2556. outf("\t%s _o;\n",name);
  2557. outs("\tunsigned xxcount;\n");
  2558. for (pi=procs; pi; pi=pi->next) {
  2559. if (pi->callback)
  2560. continue;
  2561. outs("\t");
  2562. if (pi->rettype==NULL)
  2563. {
  2564. outs("void");
  2565. }
  2566. else
  2567. pi->rettype->out_type();
  2568. outf(" _stdcall %s",pi->name);
  2569. pi->out_parameter_list("",1);
  2570. outs("\n");
  2571. outs("\t{\n");
  2572. outs("\t\t");
  2573. if (pi->rettype) {
  2574. outs("return ");
  2575. }
  2576. outf("_o.%s(",pi->name);
  2577. ParamInfo *p;
  2578. ForEachParam(pi,p,0,0) {
  2579. outf("%s",p->name);
  2580. if (p->next)
  2581. outs(", ");
  2582. }
  2583. outs(");\n");
  2584. outs("\t}\n");
  2585. }
  2586. outf("\tCIC_%s() { xxcount = 0; }\n",name);
  2587. outf("\tvoid _stdcall Link() const { ++const_cast<CIC_%s*>(this)->xxcount; }\n", name);
  2588. outf("\tint _stdcall Release() const { \n\t\tCIC_%s* ths = const_cast<CIC_%s*>(this);\n\t\tif (ths->xxcount == 0) { delete ths; return 1; }\n\t\t--ths->xxcount;\n\t\treturn 0;\n\t}\n",name,name);
  2589. outs("\tvoid _stdcall FreeMem(void *p) { free(p); }\n");
  2590. outs("};\n");
  2591. outf("CIC_%s* PASCAL HRPC_Make_%s(HRPCI_Clarion_Transport *t)\n",name,name);
  2592. outs("{\n");
  2593. outf("\tCIC_%s *ret=new CIC_%s;\n",name,name);
  2594. outs("\tret->_o.UseTransport(t->GetTransport());\n");
  2595. outs("\treturn ret;\n");
  2596. outs("}\n");
  2597. outs("#endif\n");
  2598. outs("}\n");
  2599. }
  2600. void ModuleInfo::write_define()
  2601. {
  2602. outf("#define LOCAL_%s // implementation of %s\n",name,name);
  2603. }
  2604. void ModuleInfo::write_example_module()
  2605. {
  2606. outf("void %s_Server()\n",name);
  2607. outs("{\n");
  2608. outs("\tHRPCserver server(MakeTcpTransport(NULL,PORTNO)); // PORTNO TBD\n");
  2609. outf("\t%s stub;\n",name);
  2610. outs("\tserver.AttachStub(&stub); // NB a server can service more than one module\n");
  2611. outs("\tserver.Listen();\n");
  2612. outs("}\n\n");
  2613. ProcInfo *pi;
  2614. for (pi=procs; pi; pi=pi->next) {
  2615. pi->out_method(name,true);
  2616. outs("\n{\n");
  2617. outf("\t // TBD\n");
  2618. if (pi->rettype) {
  2619. outs("\treturn TBD;\n");
  2620. }
  2621. outs("}\n\n");
  2622. }
  2623. }
  2624. void ModuleInfo::write_header_class()
  2625. {
  2626. int hasvirts = 0;
  2627. ProcInfo *pi;
  2628. for (pi=procs; pi; pi=pi->next) {
  2629. if (pi->virt) {
  2630. hasvirts = 1;
  2631. break;
  2632. }
  2633. }
  2634. if (isSCM) {
  2635. if (base)
  2636. outf("interface %s : extends %s\n",name,base);
  2637. else
  2638. outf("interface %s\n",name);
  2639. outs("{\n");
  2640. for (pi=procs; pi; pi=pi->next) {
  2641. outs("\t");
  2642. pi->out_method();
  2643. outs(";\n");
  2644. }
  2645. outs("};\n");
  2646. }
  2647. else {
  2648. outf("#ifdef LOCAL_%s\n",name);
  2649. outf("#define %s STUB_%s\n",name,name);
  2650. if (hasvirts) {
  2651. outs("#define HRPCvirtual virtual\n");
  2652. outs("#define HRPCpure =0\n");
  2653. outs("#define HRPCvirtualcallback\n");
  2654. outs("#define HRPCpurecallback\n");
  2655. }
  2656. outf("class %s : public HRPCstub\n",name);
  2657. outs("#else\n");
  2658. if (hasvirts) {
  2659. outs("#define HRPCvirtual\n");
  2660. outs("#define HRPCpure\n");
  2661. outs("#define HRPCvirtualcallback virtual\n");
  2662. outs("#define HRPCpurecallback =0\n");
  2663. }
  2664. outf("class %s : public HRPCmodule\n",name);
  2665. outs("#endif\n");
  2666. outs("{\npublic:\n");
  2667. outf("\t%s();\n",name);
  2668. for (pi=procs; pi; pi=pi->next) {
  2669. outs("\t");
  2670. pi->out_method();
  2671. outs(";\n");
  2672. }
  2673. outf("private:\n");
  2674. outf("#ifdef LOCAL_%s\n",name);
  2675. outf("\tvoid _stub(HRPCbuffer &_b,HRPCbuffer &_rb,int fn);\n");
  2676. outs("#else\n");
  2677. outf("\tvoid _callbackstub(HRPCbuffer &_b,HRPCbuffer &_rb,int fn);\n");
  2678. outs("#endif\n");
  2679. if (hasvirts) {
  2680. outs("#undef HRPCvirtual\n");
  2681. outs("#undef HRPCpure\n");
  2682. outs("#undef HRPCvirtualcallback\n");
  2683. outs("#undef HRPCpurecallback\n");
  2684. }
  2685. outs("};\n");
  2686. }
  2687. }
  2688. //-------------------------------------------------------------------------------------------------------------
  2689. // class EspMessageInfo
  2690. void EspMessageInfo::write_esp_ipp()
  2691. {
  2692. ParamInfo *pi;
  2693. const char *parent = getParentName();
  2694. if (espm_type_ == espm_enum)
  2695. {
  2696. //const char* defaultValue = getParams()->getMetaString("enum",NULL); // first enum item
  2697. outf("class CX%s : public SoapEnumParamNew<C%s>\n",name_,name_);
  2698. outf("{\n");
  2699. outs("public:\n");
  2700. outf("\tCX%s(nilBehavior nilB) : SoapEnumParamNew<C%s>(nilB)\n", name_, name_);
  2701. outf("\t{ doInit(); }\n");
  2702. outf("\tCX%s(C%s defvalue_) : SoapEnumParamNew<C%s>(defvalue_)\n", name_, name_, name_);
  2703. outf("\t{ doInit(); }\n");
  2704. outf("\tCX%s(const char* defvalue_) : SoapEnumParamNew<C%s>()\n", name_, name_);
  2705. outf("\t{ doInit(); setDefaultValue(defvalue_); }\n");
  2706. // getXsdDefinition
  2707. outs("\tstatic void getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &schema, BoolHash &added)\n");
  2708. outs("\t{ getSharedInstance().getXsdDefinitionInternal(context,request,schema,added); }\n");
  2709. // getMapInfo()
  2710. outs("\tstatic void getMapInfo(IMapInfo& info, BoolHash& added) { getSharedInstance().getMapInfo_(info,added); }\n\n");
  2711. outf("\tstatic const char* stringOf(C%s val) { return getSharedInstance().toString(val); }\n\n",name_);
  2712. outf("\tstatic C%s enumOf(const char* s) { return getSharedInstance().toEnum(s); }\n\n",name_);
  2713. outf("static const char *queryXsdElementName() { return \"%s\"; }\n", name_);
  2714. // internal: getSharedInstance()
  2715. outs("private:\n");
  2716. outf("\tstatic CX%s& getSharedInstance() { static CX%s instance(nilIgnore); return instance; }\n", name_, name_);
  2717. // TODO: getMapInfo_() internal implementation
  2718. outs("\tvoid getMapInfo_(IMapInfo& info, BoolHash& added) { }\n");
  2719. // handle descriptions
  2720. {
  2721. outs("\tvoid getXsdDefinitionInternal(IEspContext &context, CHttpRequest* request, StringBuffer &schema, BoolHash &added)\n");
  2722. bool hasDesc = false;
  2723. for (pi = getParams(); pi!=NULL; pi=pi->next)
  2724. {
  2725. const char* desc = pi->getMetaString("desc",NULL);
  2726. if (desc) { hasDesc = true; break; }
  2727. }
  2728. if (hasDesc)
  2729. {
  2730. outs("\t{\n\t\tconst char* descriptions [] = {");
  2731. for (pi = getParams(); pi!=NULL; pi=pi->next)
  2732. {
  2733. const char* desc = pi->getMetaString("desc",NULL);
  2734. outf("%s,", desc ? desc : "NULL");
  2735. }
  2736. outs("};\n");
  2737. outs("\t\tgetXsdDefinition_(context,request,schema,added,descriptions);\n\t}\n");
  2738. }
  2739. else
  2740. outf("\t{ getXsdDefinition_(context,request,schema,added,NULL); }\n");
  2741. }
  2742. outf("\tvoid doInit()\n");
  2743. outs("\t{\n");
  2744. outs("\t\tstatic const char* inits[] = {");
  2745. for (pi = getParams(); pi!=NULL; pi=pi->next)
  2746. {
  2747. if (strcmp(parent,"string")==0)
  2748. {
  2749. const char* def = pi->getMetaString("enum",NULL);
  2750. outf("%s", def);
  2751. }
  2752. else if (strcmp(parent,"int")==0 || strcmp(parent,"short")==0)
  2753. {
  2754. int def = pi->getMetaInt("enum");
  2755. outf("\"%d\"",def);
  2756. }
  2757. else if (strcmp(parent,"double")==0 || strcmp(parent,"float")==0)
  2758. {
  2759. double def = pi->getMetaDouble("enum");
  2760. outf("\"%g\"",def);
  2761. }
  2762. else
  2763. throw "Unhandled base type";
  2764. outs(",");
  2765. }
  2766. outs("NULL};\n");
  2767. outf("\t\tinit(\"%s\",\"%s\",inits);\n",name_,parent);
  2768. outs("\t}\n");
  2769. outs("};\n\n");
  2770. // array
  2771. #if 0
  2772. //outf("MAKEValueArray(C%s, %sArray);\n\n", name_, name_);
  2773. outf("inline C%s Array__Member2Param(C%s &src) { return src; }\n", name_, name_);
  2774. outf("inline void Array__Assign(C%s & dest, C%s const & src){ dest = src; }\n", name_, name_);
  2775. outf("inline bool Array__Equal(C%s const & m, C%s const p) { return m==p; }\n", name_, name_);
  2776. outf("inline void Array__Destroy(C%s & /*next* /) { }\n", name_);
  2777. //outf("MAKECopyArrayOf(simple, simple, array)
  2778. outf("MAKEArrayOf(C%s, C%s, %sArray)\n\n", name_,name_,name_);
  2779. //outf("class %sArray : public ArrayOf<C%s, C%s> {};\n\n",name_,name_,name_);
  2780. outs("\n");
  2781. #endif
  2782. return;
  2783. }
  2784. ParamInfo *contentVar=NULL;
  2785. bool removeNil=(getMetaInt("nil_remove", 0)!=0);
  2786. for (pi=getParams();pi!=NULL;pi=pi->next)
  2787. {
  2788. if (pi->getMetaString("http_content", NULL)!=NULL)
  2789. {
  2790. contentVar=pi;
  2791. break;
  2792. }
  2793. }
  2794. const char *baseclass = parent;
  2795. if (!baseclass)
  2796. {
  2797. switch(espm_type_)
  2798. {
  2799. case espm_struct:
  2800. baseclass="SoapComplexType";
  2801. break;
  2802. case espm_request:
  2803. baseclass="SoapRequestBinding";
  2804. break;
  2805. default:
  2806. baseclass="SoapResponseBinding";
  2807. break;
  2808. }
  2809. }
  2810. outf("class C%s : public C%s,\n", name_, baseclass);
  2811. outf(" implements IEsp%s,\n", name_);
  2812. outf(" implements IClient%s\n", name_);
  2813. outs("{\n");
  2814. outs("protected:\n");
  2815. for (pi=getParams();pi!=NULL;pi=pi->next)
  2816. {
  2817. pi->write_esp_declaration();
  2818. }
  2819. if (getMetaInt("element")!=0)
  2820. outs(1, "StringBuffer m_tag_value;\n");
  2821. if (contentVar!=NULL)
  2822. outf("\tStringBuffer m_%s_mimetype;\n", contentVar->name);
  2823. outs("\n\tvoid *m_eventSink = nullptr;\n");
  2824. outs("\n\tIInterface* m_RequestState = nullptr;\n");
  2825. outs("\tStringBuffer m_serviceName;\n");
  2826. outs("\tStringBuffer m_methodName;\n");
  2827. outs("\tStringBuffer m_msgName;\n");
  2828. outs("\n\tlong soap_reqid = 0;\n");
  2829. outs("\tMutex m_mutex;\n");
  2830. outs("public:\n");
  2831. outs("\tIMPLEMENT_IINTERFACE;\n");
  2832. //default constructor
  2833. outf("\n\tC%s(const char *serviceName, const char *bcompat);\n", name_);
  2834. outf("\n\tC%s(const char *serviceName, IRpcMessageBinding *init=NULL);", name_);
  2835. if (espm_type_==espm_struct)
  2836. {
  2837. //Raw message constructor
  2838. //outf("\n\tC%s(const char *serviceName, const char * msg);", name_);
  2839. }
  2840. else
  2841. {
  2842. //rpc message constructor
  2843. outf("\n\tC%s(const char *serviceName, IRpcMessage* rpcmsg);", name_);
  2844. //IProperties constructor
  2845. outf("\n\tC%s(IEspContext* ctx, const char *serviceName, IProperties *params, MapStrToBuf *attachments);", name_);
  2846. }
  2847. if (espm_type_==espm_request)
  2848. outs("\n\tIEspClientRpcSettings &rpc(){return *static_cast<IEspClientRpcSettings*>(this);}\n\n");
  2849. outf("\n\tvirtual const char *getNsURI(){return %s;}\n", getMetaString("ns_uri", "NULL"));
  2850. outf("\n\tvirtual const char *getNsPrefix(){return %s;}\n", getMetaString("ns_var", "NULL"));
  2851. outs("\n\tvirtual const char *getRootName(){return m_msgName.str();}\n");
  2852. outs("\n\tvoid setMsgName(const char *msgname)\n");
  2853. outs("\t{\n");
  2854. outs("\t\tm_msgName.set(msgname);\n");
  2855. outs("\t}\n\n");
  2856. outs("\tstatic const char *queryXsdElementName()\n");
  2857. outs("\t{\n");
  2858. outf("\t\treturn \"%s\";\n", name_);
  2859. outs("\t}\n\n");
  2860. //method ==> getXsdDefinition
  2861. outs("\tstatic StringBuffer &getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &schema, BoolHash&added, const char *xns=\"xsd\", const char *wsns=\"tns\", unsigned flags=1)\n");
  2862. outs("\t{\n");
  2863. outs("\t\treturn getXsdDefinition(context, request, queryXsdElementName(), schema, added, xns, wsns, flags);\n");
  2864. outs("\t}\n");
  2865. //method ==> getXsdDefinition
  2866. outs("\tstatic StringBuffer &getXsdDefinition(IEspContext &context, CHttpRequest* request, const char *msgTypeName, StringBuffer &schema, BoolHash&added, const char *xns=\"xsd\", const char *wsns=\"tns\", unsigned flags=1);\n");
  2867. //method ==> getMapInfo
  2868. outs("\tstatic void getMapInfo(IMapInfo& info);\n");
  2869. outs("\tstatic void getMapInfo(IMapInfo& info, BoolHash& added);\n");
  2870. //method ==> getHtmlForm
  2871. outs("\tstatic StringBuffer &getHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &form, bool includeFormTag=true, const char *prefix=NULL);\n");
  2872. //method ==> hasCustomHttpContent
  2873. outs("\tstatic bool hasCustomHttpContent()\n");
  2874. outs("\t{\n");
  2875. if (contentVar)
  2876. outs("\t\treturn true;\n");
  2877. else
  2878. outs("\t\treturn false;\n");
  2879. outs("\t}\n");
  2880. //method ==> serializeHtml
  2881. outs("\tStringBuffer &serializeHtml(IEspContext &context, const char *serv, const char *method, StringBuffer &html);\n");
  2882. //method ==> serialize (IRpcMessage&)
  2883. outs("\n\tvoid serialize(IRpcMessage& rpc_resp);\n");
  2884. //method ==> copy
  2885. outf("\n\tvoid copy(C%s &from);\n", name_);
  2886. //method ==> copy from interface
  2887. outf("\n\tvoid copy(IConst%s &ifrom);\n", name_);
  2888. //method ==> serializeContent (StringBuffer&)
  2889. outs("\n\tvoid serializeContent(IEspContext* ctx, StringBuffer& buffer, IProperties **pprops=NULL);\n");
  2890. outs("\n\tvoid serializeAttributes(IEspContext* ctx, StringBuffer& s);\n");
  2891. outs("\n\tvoid getAttributes(IProperties &attributes);\n");
  2892. //method ==> serialize (StringBuffer&)
  2893. outf("\n\tstatic void serializer(IEspContext* ctx, IConst%s &ifrom, StringBuffer& buffer, bool keepRootTag=true);\n", name_);
  2894. //method ==> serialize (MemoryBuffer&, StringBuffer &)
  2895. if (contentVar)
  2896. outs("\n\tvoid appendContent(IEspContext* ctx, MemoryBuffer& buffer, StringBuffer &mimetype);\n");
  2897. outs("\tvoid setEventSink(void * val){m_eventSink=val;}\n");
  2898. outs("\tvoid * getEventSink(){return m_eventSink;}\n");
  2899. outs("\tvoid setState(IInterface * val){m_RequestState = val;}\n");
  2900. outs("\tIInterface * queryState(){return m_RequestState;}\n");
  2901. outs("\tvoid setMethod(const char * method){m_methodName.set(method);}\n");
  2902. outs("\tconst char * getMethod(){return m_methodName.str();}\n\n");
  2903. outs("\tvoid setReqId(unsigned val){soap_reqid=val;}\n");
  2904. outs("\tunsigned getReqId(){return soap_reqid;}\n\n");
  2905. outs("\tvoid lock(){m_mutex.lock();}\n");
  2906. outs("\tvoid unlock(){m_mutex.unlock();}\n\n");
  2907. if (getMetaInt("element")!=0)
  2908. {
  2909. outs(1, "void set_tag_value(const char * value){m_tag_value.set(value);}\n");
  2910. outs(1, "const char * get_tag_value(){return m_tag_value.str();}\n\n");
  2911. }
  2912. outs("\n\tbool unserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath);\n");
  2913. if (parent)
  2914. {
  2915. outs("\n\tbool localUnserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath);\n");
  2916. outs("\n\tbool unserialize(IEspContext* ctx, CSoapValue& soapval, bool localOnly=false);\n");
  2917. outs("\n\tbool unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath=NULL, bool localOnly=false);\n");
  2918. }
  2919. else
  2920. {
  2921. outs("\n\tbool unserialize(IEspContext* ctx, CSoapValue& soapval);\n");
  2922. outs("\n\tbool unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath=NULL);\n");
  2923. }
  2924. //outs("\n\tvoid unserialize(const char * msg);\n");
  2925. if (espm_type_==espm_response)
  2926. {
  2927. outs("\n\tvirtual void setRedirectUrl(const char *url)\n");
  2928. outs("\t{ CSoapResponseBinding::setRedirectUrl(url); }\n");
  2929. outs("\n\tvirtual const IMultiException& getExceptions()\n");
  2930. outs("\t{ return CSoapResponseBinding::getExceptions(); }\n");
  2931. outs("\n\tvirtual int queryClientStatus()\n");
  2932. outs("\t{ return CSoapResponseBinding::getRpcState(); }\n");
  2933. outs("\n\tvirtual void noteException(IException& e)\n");
  2934. outs("\t{ CSoapResponseBinding::noteException(e); }\n");
  2935. }
  2936. outs("\n");
  2937. write_esp_methods(espaxm_both, true, false);
  2938. outs("};\n\n");
  2939. }
  2940. bool EspMessageInfo::hasMapInfo()
  2941. {
  2942. for (ParamInfo* pi=getParams();pi!=NULL;pi=pi->next)
  2943. if (pi->hasMapInfo())
  2944. return true;
  2945. return false;
  2946. }
  2947. void EspMessageInfo::write_esp()
  2948. {
  2949. if (espm_type_ == espm_enum)
  2950. return;
  2951. const char *parent=getParentName();
  2952. ParamInfo *contentVar=NULL;
  2953. ParamInfo *pi=NULL;
  2954. bool removeNil=(getMetaInt("nil_remove", 0)!=0);
  2955. for (pi=getParams();pi!=NULL;pi=pi->next)
  2956. {
  2957. if (pi->getMetaString("http_content", NULL)!=NULL)
  2958. {
  2959. contentVar=pi;
  2960. break;
  2961. }
  2962. }
  2963. //comment
  2964. outs("\n//=======================================================");
  2965. outf("\n// class C%s Implementation", name_);
  2966. outs("\n//=======================================================");
  2967. outs("\n");
  2968. //default constructor
  2969. outf("\nC%s::C%s(const char *serviceName, IRpcMessageBinding *init)", name_, name_);
  2970. bool isFirstInited=true;
  2971. if (parent)
  2972. {
  2973. outf(" : C%s(serviceName, init)", parent);
  2974. isFirstInited=false;
  2975. }
  2976. for (pi=getParams();pi!=NULL;pi=pi->next)
  2977. {
  2978. pi->write_esp_init(isFirstInited, removeNil);
  2979. }
  2980. if (contentVar)
  2981. {
  2982. outs((isFirstInited) ? "\n\t: " : ",");
  2983. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  2984. }
  2985. outs("\n{\n");
  2986. outs("\tm_eventSink=NULL;\n");
  2987. outs("\tm_RequestState=NULL;\n");
  2988. outs("\tm_serviceName.append(serviceName);\n");
  2989. outf("\tm_msgName.append(\"%s\");\n", name_);
  2990. outs("\tif (init)\n");
  2991. outs("\t{\n");
  2992. outs("\t\tsetClientValue(init->getClientValue());\n");
  2993. outs("\t\tsetReqId(init->getReqId());\n");
  2994. outs("\t\tsetEventSink(init->getEventSink());\n");
  2995. outs("\t\tsetState(init->queryState());\n");
  2996. outs("\t\tsetThunkHandle(init->getThunkHandle());\n");
  2997. outs("\t\tsetMethod(init->getMethod());\n");
  2998. outs("\t}\n");
  2999. outs("}\n");
  3000. outf("\nC%s::C%s(const char *serviceName, const char *bc)", name_, name_);
  3001. isFirstInited=true;
  3002. if (parent)
  3003. {
  3004. outf(" : C%s(serviceName)", parent);
  3005. isFirstInited=false;
  3006. }
  3007. for (pi=getParams();pi!=NULL;pi=pi->next)
  3008. {
  3009. pi->write_esp_init(isFirstInited, removeNil);
  3010. }
  3011. if (contentVar)
  3012. {
  3013. outs((isFirstInited) ? " : " : ", ");
  3014. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3015. }
  3016. outs("\n{\n");
  3017. outs("\tm_eventSink=NULL;\n");
  3018. outs("\tm_RequestState=NULL;\n");
  3019. outs("\tm_serviceName.append(serviceName);\n");
  3020. outf("\tm_msgName.append(\"%s\");\n", name_);
  3021. outs("}\n");
  3022. if (espm_type_==espm_struct)
  3023. {
  3024. //Raw message constructor
  3025. /*
  3026. outf("\nC%s::C%s(const char *serviceName, const char * msg)", name_, name_);
  3027. isFirstInited=true;
  3028. if (parent)
  3029. {
  3030. outf(" : C%s(serviceName, msg)", parent);
  3031. isFirstInited=false;
  3032. }
  3033. for (pi=getParams();pi!=NULL;pi=pi->next)
  3034. {
  3035. pi->write_esp_init(isFirstInited, removeNil);
  3036. }
  3037. if (contentVar)
  3038. {
  3039. outs((isFirstInited) ? " : " : ", ");
  3040. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3041. }
  3042. outs("\n\t{\n\t\tm_eventSink=NULL;\n");
  3043. outs("\t\tm_RequestState=NULL;\n");
  3044. outs("\t\tm_serviceName.append(serviceName);\n");
  3045. outf("\t\tm_msgName.append(\"%s\");\n", name_);
  3046. outs("\t\tunserialize(msg);\n\t}\n");
  3047. */
  3048. }
  3049. else
  3050. {
  3051. //rpc message constructor
  3052. outf("\nC%s::C%s(const char *serviceName, IRpcMessage* rpcmsg)", name_, name_);
  3053. isFirstInited=true;
  3054. if (parent)
  3055. {
  3056. outf(" : C%s(serviceName, rpcmsg)", parent);
  3057. isFirstInited=false;
  3058. }
  3059. for (pi=getParams();pi!=NULL;pi=pi->next)
  3060. {
  3061. pi->write_esp_init(isFirstInited, removeNil);
  3062. }
  3063. if (contentVar)
  3064. {
  3065. outs((isFirstInited) ? " : " : ", ");
  3066. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3067. }
  3068. outs("\n{\n");
  3069. outs("\tm_eventSink=NULL;\n");
  3070. outs("\tm_RequestState=NULL;\n");
  3071. outs("\tm_serviceName.append(serviceName);\n");
  3072. outf("\tm_msgName.append(\"%s\");\n", name_);
  3073. if (parent)
  3074. outs("\tlocalUnserialize(*rpcmsg,NULL,NULL);\n");
  3075. else
  3076. outs("\tunserialize(*rpcmsg,NULL,NULL);\n");
  3077. outs("}\n");
  3078. //IProperties constructor
  3079. outf("\nC%s::C%s(IEspContext* ctx, const char *serviceName, IProperties *params, MapStrToBuf *attachments)", name_, name_);
  3080. isFirstInited=true;
  3081. if (parent)
  3082. {
  3083. outf(" : C%s(ctx, serviceName, params, attachments)", parent);
  3084. isFirstInited=false;
  3085. }
  3086. for (pi=getParams();pi!=NULL;pi=pi->next)
  3087. {
  3088. pi->write_esp_init(isFirstInited, removeNil);
  3089. }
  3090. if (contentVar)
  3091. {
  3092. outs((isFirstInited) ? " : " : ", ");
  3093. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3094. }
  3095. outs("\n{\n\tm_eventSink=NULL;\n");
  3096. outs("\tm_RequestState=NULL;\n");
  3097. outs("\tm_serviceName.append(serviceName);\n");
  3098. outf("\tm_msgName.append(\"%s\");\n", name_);
  3099. if (parent)
  3100. outs("\tunserialize(ctx,*params,attachments, NULL,true);\n}\n");
  3101. else
  3102. outs("\tunserialize(ctx,*params,attachments, NULL);\n}\n");
  3103. }
  3104. //=======================================================================================
  3105. //method ==> getXsdDefinition
  3106. // @context: the context could affect the schema, e.g., the version, the URL parameters
  3107. // @flags: 0x001 - define the struct/enum as complexType.
  3108. // 0x010 - do not include group-type enclosure (i.e., just define the fields, e.g., as part of other complex type definition)
  3109. // 0x100 - do not include fields at all (only to include definitions of fields, recursively)
  3110. bool isExtSimpleType = getMetaInt("element", 0)!=0;
  3111. outf("\nStringBuffer &C%s::getXsdDefinition(IEspContext &context, CHttpRequest* request, const char *msgTypeName, StringBuffer &schema, BoolHash &added, const char *xns, const char *wsns, unsigned flags)\n", name_);
  3112. outs("{\n");
  3113. indentReset(1);
  3114. indentOuts("if (!(flags & 0x100))\n\t{\n");
  3115. indentOuts(1,"IProperties *props = request->queryParameters();\n");
  3116. indentOuts("if(msgTypeName) {\n");
  3117. indentOuts(1,"if(added.getValue(msgTypeName))\n");
  3118. indentOuts1(1,"return schema;\n");
  3119. indentOuts("else\n");
  3120. indentOuts1(1,"added.setValue(msgTypeName, 1);\n");
  3121. indentOuts(-1,"}\n");
  3122. indentOuts("if (flags & 0x01) {\n");
  3123. bool isEmptyComplexType = true; //a complex type with no children, no attribute and no parent
  3124. if (isExtSimpleType || getParentName() || hasNonAttributeChild() || (espm_type_==espm_response && getMetaInt("exceptions_inline", 0)))
  3125. isEmptyComplexType = false;
  3126. else
  3127. {
  3128. for (pi=getParams();pi!=NULL;pi=pi->next)
  3129. {
  3130. if (!pi->getMetaInt("attribute", 0) && !pi->getMetaInt("hidden", 0) && !pi->getMetaInt("hidden_soap", 0))
  3131. isEmptyComplexType = false;
  3132. }
  3133. }
  3134. if (isEmptyComplexType)
  3135. {
  3136. if (espm_type_==espm_struct)
  3137. indentOuts(1,"schema.appendf(\"<xsd:complexType name=\\\"%s\\\"><xsd:all/></xsd:complexType>\\n\", msgTypeName);\n");
  3138. else
  3139. indentOuts(1,"schema.appendf(\"<xsd:element name=\\\"%s\\\"><xsd:complexType><xsd:all/></xsd:complexType></xsd:element>\\n\", msgTypeName);\n");
  3140. }
  3141. else if (espm_type_==espm_struct)
  3142. indentOuts(1,"schema.appendf(\"<xsd:complexType name=\\\"%s\\\">\\n\", msgTypeName);\n");
  3143. else
  3144. indentOuts(1,"schema.appendf(\"<xsd:element name=\\\"%s\\\"><xsd:complexType>\\n\", msgTypeName);\n");
  3145. if (isExtSimpleType)
  3146. indentOuts("schema.append(\"<xsd:simpleContent><xsd:extension base=\\\"xsd:string\\\">\\n\");\n");
  3147. indentOuts(-1, "}\n");
  3148. // native arrays
  3149. typedef std::map<std::string,std::string> EspNativeArrays;
  3150. EspNativeArrays nativeArrays;
  3151. // esp struct arrays
  3152. typedef std::set<std::string> EspStructArrays;
  3153. EspStructArrays structArrays;
  3154. //no element children for extended simple type
  3155. if (!isEmptyComplexType && !isExtSimpleType)
  3156. {
  3157. const char *xsdGroupType = getXsdGroupType();
  3158. bool hasChild = hasNonAttributeChild();
  3159. bool exceptions = espm_type_==espm_response && getMetaInt("exceptions_inline", 0);
  3160. bool needGroupType = exceptions || hasChild || parent;
  3161. if (needGroupType)
  3162. {
  3163. indentOuts("if (!(flags & 0x10)) {\n");
  3164. indentOutf1(1,"schema.append(\"<xsd:%s>\");\n", xsdGroupType);
  3165. if (exceptions)
  3166. indentOuts("schema.append(\"<xsd:element name=\\\"Exceptions\\\" type=\\\"tns:ArrayOfEspException\\\" minOccurs=\\\"0\\\" maxOccurs=\\\"1\\\"/>\");\n");
  3167. indentOuts("}\n");
  3168. }
  3169. if (parent)
  3170. indentOutf("C%s::getXsdDefinition(context, request, NULL, schema, added, xns, wsns, 0x10);\n", parent);
  3171. for (pi=getParams();pi!=NULL;pi=pi->next)
  3172. {
  3173. if (!pi->getMetaInt("attribute", 0) && !pi->getMetaInt("hidden", 0) && !pi->getMetaInt("hidden_soap", 0))
  3174. {
  3175. enum {definedtype, inline_primitive_array, inline_array, complextype} complexity=definedtype;
  3176. StrBuffer buffer;
  3177. const char *xsd_type = pi->getMetaXsdType();
  3178. if (xsd_type)
  3179. {
  3180. buffer.append(xsd_type);
  3181. }
  3182. else if (pi->flags & PF_TEMPLATE)
  3183. {
  3184. if (!strcmp(pi->templ, "ESParray"))
  3185. {
  3186. if (pi->isPrimitiveArray())
  3187. {
  3188. if (pi->getMetaString("item_tag", NULL))
  3189. complexity=inline_primitive_array;
  3190. else {
  3191. const char* type = pi->getArrayImplType();
  3192. nativeArrays[pi->getArrayItemXsdType()] = VStrBuffer("Esp%s", type).str();
  3193. buffer.appendf("tns:Esp%s", type);
  3194. }
  3195. }
  3196. else
  3197. {
  3198. buffer.append("tns:");
  3199. if (pi->getMetaString("item_tag", NULL))
  3200. complexity=inline_array;
  3201. else {
  3202. structArrays.insert(pi->typname);
  3203. buffer.append("ArrayOf");
  3204. }
  3205. buffer.append(pi->typname);
  3206. }
  3207. }
  3208. else
  3209. buffer.append("xsd:string");
  3210. }
  3211. else if (pi->kind==TK_ESPSTRUCT || pi->kind==TK_ESPENUM)
  3212. {
  3213. buffer.appendf("tns:%s",pi->typname);
  3214. }
  3215. else
  3216. {
  3217. buffer.append(pi->getXsdType());
  3218. }
  3219. const char *xsdtype = buffer.str();
  3220. const char *xsdns = "";
  3221. if (xsdtype)
  3222. {
  3223. int count= buffer.length();
  3224. if (count>0 && buffer.charAt(count-1)=='\"')
  3225. buffer.setCharAt(count-1,0);
  3226. if (*xsdtype=='\"')
  3227. xsdtype++;
  3228. if (strchr(xsdtype, ':')==NULL)
  3229. xsdns="xsd:";
  3230. }
  3231. bool hasMapInfo = pi->hasMapInfo();
  3232. if (hasMapInfo)
  3233. {
  3234. indentOutf("if (!context.suppressed(\"%s\",\"%s\")) {\n", this->name_, pi->name);
  3235. indentInc(1);
  3236. }
  3237. const char *access=pi->getMetaString("access", NULL);
  3238. if (access)
  3239. {
  3240. indentOuts("SecAccessFlags acc;\n");
  3241. indentOutf("if (context.authorizeFeature(%s, acc) && acc>=SecAccess_Read) {\n", access);
  3242. indentInc(1);
  3243. }
  3244. StrBuffer xmlTag;
  3245. const char* tagName = pi->getMetaStringValue(xmlTag,"xml_tag") ? xmlTag.str() : pi->name;
  3246. switch (complexity)
  3247. {
  3248. case inline_array:
  3249. {
  3250. indentOutf("schema.append(\"<xsd:element minOccurs=\\\"0\\\" name=\\\"%s\\\">\\n\");\n", tagName);
  3251. indentOuts("schema.append(\"<xsd:complexType><xsd:sequence>\\n\");\n");
  3252. indentOutf("schema.append(\"<xsd:element minOccurs=\\\"0\\\" maxOccurs=\\\"unbounded\\\" name=\\\"%s\\\" type=\\\"%s\\\"/>\");\n", pi->getMetaString("item_tag", "Item"), xsdtype);
  3253. indentOuts("schema.append(\"</xsd:sequence></xsd:complexType>\");\n");
  3254. indentOutf("schema.append(\"</xsd:element>\");\n");
  3255. break;
  3256. }
  3257. case inline_primitive_array:
  3258. {
  3259. indentOutf("schema.append(\"<xsd:element minOccurs=\\\"0\\\" name=\\\"%s\\\">\");\n", tagName);
  3260. indentOuts("schema.append(\"<xsd:complexType><xsd:sequence>\");\n");
  3261. indentOutf("schema.append(\"<xsd:element name=\\\"%s\\\" type=\\\"xsd:%s\\\" minOccurs=\\\"0\\\" maxOccurs=\\\"unbounded\\\"", pi->getMetaString("item_tag", "Item"), pi->getArrayItemXsdType());
  3262. int cols = pi->getMetaInt("cols",0);
  3263. int rows = pi->getMetaInt("rows",0);
  3264. if (cols>0 || rows>0)
  3265. {
  3266. outs("\");\n");
  3267. indentOuts("if (context.queryOptions()&ESPCTX_ALL_ANNOTATION)\n");
  3268. indentOuts(1,"schema.append(\"> <xsd:annotation><xsd:appinfo><form");
  3269. if (cols>0)
  3270. outf(" formCols=\\\"%d\\\"", cols);
  3271. if (rows>0)
  3272. outf(" formRows=\\\"%d\\\"", rows);
  3273. outs("/></xsd:appinfo></xsd:annotation></xsd:element>\\n\");\n");
  3274. indentOuts(-1,"else\n");
  3275. indentOuts("\tschema.append(\"/>\\n\");\n");
  3276. }
  3277. else
  3278. outs("/>\\n\");\n");
  3279. indentOuts("schema.append(\"</xsd:sequence></xsd:complexType>\\n\");\n");
  3280. indentOutf("schema.append(\"</xsd:element>\\n\");\n");
  3281. break;
  3282. }
  3283. case definedtype:
  3284. {
  3285. indentOutf("schema.append(\"<xsd:element");
  3286. // min occurs
  3287. int minOccurs = (pi->getMetaInt("required", 0)) ? 1 : 0;
  3288. if (minOccurs==0)
  3289. outs(" minOccurs=\\\"0\\\"");
  3290. // default value
  3291. if (pi->hasMetaTag("default"))
  3292. {
  3293. if (pi->kind==TK_CHAR || pi->kind==TK_UNSIGNEDCHAR || strcmp(xsdtype,"string")==0)
  3294. {
  3295. const char* val = pi->getMetaString("default",NULL);
  3296. if (val && *val)
  3297. {
  3298. // remove quotes
  3299. if (*val=='"' || *val=='\'')
  3300. {
  3301. char* s = strdup(val);
  3302. *(s+strlen(s)-1) = 0;
  3303. outf(" default=\\\"%s\\\"", s+1);
  3304. free(s);
  3305. }
  3306. else
  3307. outf(" default=\\\"%s\\\"", val);
  3308. }
  3309. }
  3310. else if (pi->kind==TK_DOUBLE || pi->kind==TK_FLOAT || strcmp(xsdtype,"double")==0)
  3311. {
  3312. double val = pi->getMetaDouble("default");
  3313. if (val==0)
  3314. val = pi->getMetaInt("default"); // auto conversion
  3315. if (val!=0)
  3316. outf(" default=\\\"%g\\\"", val);
  3317. }
  3318. else if (pi->kind==TK_BOOL || strcmp(xsdtype,"bool")==0)
  3319. {
  3320. outf(" default=\\\"%s\\\"", pi->getMetaInt("default") ? "true" : "false");
  3321. }
  3322. else if (pi->kind==TK_ESPENUM)
  3323. {
  3324. const char* val = pi->getMetaString("default",NULL);
  3325. if (val && *val)
  3326. {
  3327. // remove quotes
  3328. if (*val=='"' || *val=='\'')
  3329. {
  3330. char* s = strdup(val);
  3331. *(s+strlen(s)-1) = 0;
  3332. outf(" default=\\\"%s\\\"", s+1);
  3333. free(s);
  3334. }
  3335. else
  3336. outf(" default=\\\"%s\\\"", val);
  3337. }
  3338. else
  3339. {
  3340. int val = pi->getMetaInt("default", -1);
  3341. if (val != -1)
  3342. outf(" default=\\\"%d\\\"", val);
  3343. }
  3344. }
  3345. else// assume it is integer
  3346. {
  3347. int val = pi->getMetaInt("default");
  3348. if (val)
  3349. outf(" default=\\\"%d\\\"", val);
  3350. }
  3351. }
  3352. // name & type
  3353. outf(" name=\\\"%s\\\" type=\\\"%s%s\\\"", tagName, xsdns, xsdtype);
  3354. // check for annotations
  3355. StrBuffer annot;
  3356. const char* formType = pi->getMetaInt("password") ? "password" : NULL;
  3357. if (formType)
  3358. annot.appendf(" formType=\\\"%s\\\"",formType);
  3359. bool collapsed = pi->getMetaInt("collapsed")?true:false;;
  3360. if (collapsed)
  3361. annot.append(" collapsed=\\\"true\\\"");
  3362. int cols = pi->getMetaInt("cols",0);
  3363. if (cols>0)
  3364. annot.appendf(" formCols=\\\"%d\\\"", cols);
  3365. int rows = pi->getMetaInt("rows",0);
  3366. if (rows>0)
  3367. annot.appendf(" formRows=\\\"%d\\\"", rows);
  3368. StrBuffer tmp;
  3369. pi->getMetaStringValue(tmp,"form_ui");
  3370. if (tmp.length()) {
  3371. StrBuffer encoded;
  3372. encodeXML(tmp.str(),encoded);
  3373. annot.appendf(" ui=\\\"%s\\\"", printfEncode(encoded.str(), tmp.clear()).str());
  3374. }
  3375. pi->getMetaStringValue(tmp.clear(), "html_head");
  3376. if (tmp.length()) {
  3377. StrBuffer encoded;
  3378. encodeXML(tmp.str(),encoded);
  3379. annot.appendf(" html_head=\\\"%s\\\"", printfEncode(encoded.str(), tmp.clear()).str());
  3380. }
  3381. if (annot.length())
  3382. {
  3383. outs("\");\n");
  3384. indentOuts("if (context.queryOptions()&ESPCTX_ALL_ANNOTATION)\n");
  3385. indentOuts(1,"schema.append(\"> <xsd:annotation><xsd:appinfo><form");
  3386. outf("%s", annot.str());
  3387. outs("/></xsd:appinfo></xsd:annotation></xsd:element>\\n\");\n");
  3388. indentOuts(-1,"else\n");
  3389. indentOuts("\tschema.append(\"/>\\n\");\n");
  3390. }
  3391. else
  3392. outs("/>\\n\");\n");
  3393. break;
  3394. }
  3395. default:
  3396. break;
  3397. }
  3398. if (access)
  3399. indentOuts(-1,"}\n");
  3400. //if (optional)
  3401. if (hasMapInfo)
  3402. indentOuts(-1,"}\n");
  3403. }
  3404. }
  3405. if (needGroupType)
  3406. {
  3407. indentOuts("if (!(flags & 0x10))\n");
  3408. indentOutf1(1,"schema.append(\"</xsd:%s>\\n\");\n", xsdGroupType);
  3409. }
  3410. } //!isEmptyComplexType && !isExtSimpleType
  3411. if (!isEmptyComplexType)
  3412. {
  3413. //attributes last
  3414. for (pi=getParams();pi!=NULL;pi=pi->next)
  3415. {
  3416. if (pi->getMetaInt("attribute")!=0 && !pi->getMetaInt("hidden"))
  3417. {
  3418. StrBuffer tmp;
  3419. const char* tagName = pi->getMetaStringValue(tmp,"xml_tag") ? tmp.str() : pi->name;
  3420. indentOutf("schema.append(\"<xsd:attribute name=\\\"%s\\\" type=\\\"xsd:%s\\\"/>\");\n", tagName, pi->getXsdType());
  3421. }
  3422. }
  3423. indentOuts("if (flags & 0x01) {\n");
  3424. if (isExtSimpleType)
  3425. indentOuts1(1,"schema.append(\"</xsd:extension></xsd:simpleContent>\\n\");\n");
  3426. if (espm_type_==espm_struct)
  3427. indentOuts1(1,"schema.append(\"</xsd:complexType>\\n\");\n");
  3428. else
  3429. indentOuts1(1,"schema.append(\"</xsd:complexType></xsd:element>\\n\");\n");
  3430. indentOuts("}\n");
  3431. }
  3432. indentOuts(-1,"}\n"); // if (flags & 0x100)
  3433. //-------------------------------------------------------------------------
  3434. // try to figure out structs without ESPuses
  3435. // true if it is with map info, once a STRUCT or ENUM is there without map info, it is false
  3436. const int MIT_HasMap = 0x01;
  3437. const int MIT_IsEnum = 0x02;
  3438. const int MIT_IsStruct = 0x04;
  3439. enum MapInfoType { MIT_EnumFalse=MIT_IsEnum, MIT_EnumTrue=MIT_HasMap|MIT_IsEnum,
  3440. MIT_StructFalse=MIT_IsStruct,MIT_StructTrue=MIT_IsStruct|MIT_HasMap };
  3441. typedef std::map<std::string, int> TypeMap;
  3442. TypeMap typesNeeded;
  3443. bool parenthesisOpened = false;
  3444. if (parent)
  3445. {
  3446. outs("\tif (!(flags & 0x10) || (flags & 0x100))\n");
  3447. outs("\t{\n");
  3448. parenthesisOpened = true;
  3449. outf("\t\tC%s::getXsdDefinition(context, request, schema, added, xns, wsns, 0x110);\n", parent);
  3450. typesNeeded[parent] = false;
  3451. }
  3452. for (pi=getParams();pi!=NULL;pi=pi->next)
  3453. {
  3454. // we still need to make it usable for the service writer
  3455. //if (pi->getMetaInt("hidden", 0) || pi->getMetaInt("hidden_soap", 0))
  3456. // continue;
  3457. std::string thisType;
  3458. const char *xsd_type=pi->getMetaXsdType();
  3459. if (xsd_type)
  3460. {
  3461. char* buf = strdup(xsd_type[0]=='"' ? xsd_type+1 : xsd_type);
  3462. size_t count= strlen(buf);
  3463. if (count>0 && buf[count-1]=='\"')
  3464. buf[count-1]=0;
  3465. char* typeName = getToBeDefinedType(buf);
  3466. if (typeName)
  3467. {
  3468. thisType = typeName;
  3469. free(typeName);
  3470. }
  3471. free(buf);
  3472. }
  3473. else if (pi->kind==TK_ESPSTRUCT || pi->kind==TK_ESPENUM)
  3474. {
  3475. if (pi->typname)
  3476. thisType = pi->typname;
  3477. else
  3478. outs("\t\t*** pi->typname is empty!!\n");
  3479. }
  3480. else if (pi->flags & PF_TEMPLATE)
  3481. {
  3482. if (strcmp(pi->templ, "ESParray")==0)
  3483. {
  3484. if (pi->typname && strcmp(pi->typname, "string")!=0 && strcmp(pi->typname, "EspTextFile")!=0)
  3485. thisType = pi->typname;
  3486. }
  3487. else
  3488. outf("\t\t// *** skip field: name=%s, type=%s\n", pi->name, pi->typname);
  3489. }
  3490. if (thisType.length() && strcmp(thisType.c_str(),name_)!=0)
  3491. {
  3492. TypeMap::const_iterator it = typesNeeded.find(thisType);
  3493. if (it==typesNeeded.end() || (*it).second & MIT_HasMap) // thisType is not in typesNeeded or it is there with version info
  3494. {
  3495. if (!parenthesisOpened)
  3496. {
  3497. outs("\tif (!(flags & 0x10) || (flags & 0x100))\n\t{\n");
  3498. parenthesisOpened = true;
  3499. }
  3500. if (pi->hasMapInfo())
  3501. {
  3502. outf("\t\tif (!context.suppressed(\"%s\",\"%s\"))\n\t", this->name_, pi->name);
  3503. typesNeeded[thisType] = (pi->kind==TK_ESPENUM) ? MIT_EnumTrue : MIT_StructTrue;
  3504. }
  3505. else
  3506. typesNeeded[thisType] = (pi->kind==TK_ESPENUM) ? MIT_EnumFalse : MIT_StructFalse;
  3507. if (pi->kind == TK_ESPENUM)
  3508. outf("\t\tCX%s::getXsdDefinition(context, request, schema, added);\n", thisType.c_str());
  3509. else
  3510. outf("\t\tC%s::getXsdDefinition(context, request, schema, added);\n", thisType.c_str());
  3511. }
  3512. }
  3513. }
  3514. if (parenthesisOpened)
  3515. outs("\t}\n");
  3516. // native arrays
  3517. for (EspNativeArrays::const_iterator it = nativeArrays.begin(); it!=nativeArrays.end(); it++)
  3518. {
  3519. outf("\tif (added.getValue(\"%s\")==NULL) {\n", (*it).second.c_str());
  3520. outf("\t\taddEspNativeArray(schema,\"%s\",\"%s\");\n", (*it).first.c_str(), (*it).second.c_str());
  3521. outf("\t\tadded.setValue(\"%s\",1);\n", (*it).second.c_str());
  3522. outf("\t}\n");
  3523. }
  3524. // struct arrays
  3525. for (EspStructArrays::const_iterator it2 = structArrays.begin(); it2!=structArrays.end(); it2++)
  3526. {
  3527. const char* type = (*it2).c_str();
  3528. outf("\tif (added.getValue(\"%s\") && added.getValue(\"ArrayOf%s\")==NULL) {\n", type, type);
  3529. outf("\t\tschema.append(\"<xsd:complexType name=\\\"ArrayOf%s\\\">\\n\");\n",type);
  3530. outf("\t\tschema.append(\"<xsd:sequence>\\n\");\n");
  3531. outf("\t\tschema.append(\"<xsd:element minOccurs=\\\"0\\\" maxOccurs=\\\"unbounded\\\" name=\\\"%s\\\" type=\\\"tns:%s\\\"/>\\n\");\n", type, type);
  3532. outf("\t\tschema.append(\"</xsd:sequence>\\n\");\n");
  3533. outf("\t\tschema.append(\"</xsd:complexType>\\n\");\n");
  3534. outf("\t\tadded.setValue(\"ArrayOf%s\",1);\n", type);
  3535. outf("\t}\n");
  3536. }
  3537. /*
  3538. //typesNeeded.erase(name_); // Do not include self: avoid recursive call
  3539. if (typesNeeded.size()>0)
  3540. {
  3541. outs("\tif (!(flags & 0x10))\n");
  3542. outs("\t{\n");
  3543. for (TypeMap::const_iterator it = typesNeeded.begin(); it!=typesNeeded.end(); ++it)
  3544. {
  3545. const char* type = (*it).first.c_str();
  3546. const char* fld = (*it).second.c_str();
  3547. if (fld[0] != 0)
  3548. {
  3549. outf("\t\tif (!context.suppressed(\"%s\",\"%s\"))\n\t", this->name_, fld);
  3550. outf("\t\t\tC%s::getXsdDefinition(context, request, schema, added);\n", type);
  3551. }
  3552. else
  3553. outf("\t\tC%s::getXsdDefinition(context, request, schema, added);\n", type);
  3554. }
  3555. outs("\t}\n");
  3556. }
  3557. */
  3558. outs("\treturn schema;\n");
  3559. outs("}\n");
  3560. //=======================================================================================
  3561. //method ==> getMapInfo
  3562. outf("\nvoid C%s::getMapInfo(IMapInfo& info) { BoolHash added; getMapInfo(info, added); }\n",name_);
  3563. outf("\nvoid C%s::getMapInfo(IMapInfo& info, BoolHash& added)\n",name_);
  3564. outf("{\n");
  3565. for (pi=getParams();pi!=NULL;pi=pi->next)
  3566. {
  3567. if (pi->hasMapInfo())
  3568. {
  3569. StrBuffer ver;
  3570. bool hasVer = pi->getMetaVerInfo("min_ver",ver);
  3571. if (hasVer)
  3572. outf("\tinfo.addMinVersion(\"%s\",\"%s\",%s);\n", name_, pi->name, ver.str());
  3573. hasVer = pi->getMetaVerInfo("depr_ver",ver.clear());
  3574. if (hasVer)
  3575. outf("\tinfo.addDeprVersion(\"%s\",\"%s\",%s);\n", name_, pi->name, ver.str());
  3576. hasVer = pi->getMetaVerInfo("max_ver",ver.clear());
  3577. if (hasVer)
  3578. outf("\tinfo.addMaxVersion(\"%s\",\"%s\",%s);\n", name_, pi->name, ver.str());
  3579. const char* opt = pi->getMetaString("optional", NULL);
  3580. if (opt)
  3581. {
  3582. const char* quote = (*opt=='"' || *opt=='\'') ? "" : "\"";
  3583. outf("\tinfo.addOptional(\"%s\",\"%s\",%s%s%s);\n", name_, pi->name,quote,opt,quote);
  3584. }
  3585. }
  3586. }
  3587. if (typesNeeded.size()>0)
  3588. {
  3589. for (TypeMap::const_iterator it = typesNeeded.begin(); it!=typesNeeded.end(); ++it)
  3590. {
  3591. outf("\tif (!added.getValue(\"%s\"))\n", (*it).first.c_str());
  3592. outf("\t{\n");
  3593. outf("\t\tadded.setValue(\"%s\",1);\n", (*it).first.c_str());
  3594. outf("\t\tC%s%s::getMapInfo(info,added);\n",((*it).second & MIT_IsEnum)?"X":"",(*it).first.c_str());
  3595. outf("\t}\n");
  3596. }
  3597. }
  3598. outs("}\n");
  3599. //=======================================================================================
  3600. //method ==> getHtmlForm
  3601. //TODO: move includeFormTag into onGetForm() to reduce significant generated code
  3602. indentReset();
  3603. indentOutf("\nStringBuffer &C%s::getHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &form, bool includeFormTag, const char *prefix)\n", name_);
  3604. indentOuts("{\n");
  3605. indentOuts(1,"IProperties *props = request->queryParameters();\n");
  3606. bool hasAttachment=false;
  3607. for (pi=getParams();pi;pi=pi->next)
  3608. {
  3609. if (pi->typname && !stricmp("EspTextFile", pi->typname))
  3610. hasAttachment=true;
  3611. }
  3612. indentOuts("if (includeFormTag) {\n");
  3613. indentOutf(1,"StringBuffer params, versionTag;\n");
  3614. indentOuts("bool hasVersion = getUrlParams(props,params);\n");
  3615. indentOuts("if (!hasVersion) versionTag.appendf(\"%cver_=%g\",params.length()?'&':'?',context.getClientVersion());\n");
  3616. indentOutf("form.appendf(\"\\n<form name=\\\"esp_form\\\" method=\\\"POST\\\" enctype=\\\"%s\\\" action=\\\"/%%s/%%s%%s%%s\\\">\\n\", serv, method, params.str(), versionTag.str());\n",
  3617. hasAttachment ? "multipart/form-data" : "application/x-www-form-urlencoded");
  3618. indentOutf(-1,"}\n");
  3619. if (parent)
  3620. indentOutf("C%s::getHtmlForm(context, request, serv, method, form, false, prefix);\n", parent);
  3621. indentOuts("StringBuffer extfix;\n");
  3622. indentOuts("form.append(\" <table>\\n\");\n");
  3623. for (pi=getParams();pi!=NULL;pi=pi->next)
  3624. {
  3625. bool hasMapInfo = pi->hasMapInfo();
  3626. if (hasMapInfo)
  3627. {
  3628. indentOutf("if (!context.suppressed(\"%s\",\"%s\")) {\n", this->name_, pi->name);
  3629. indentInc(1);
  3630. }
  3631. if (!pi->getMetaInt("hidden"))
  3632. {
  3633. int rows = pi->getMetaInt("rows", 5);
  3634. StrBuffer label;
  3635. if (!pi->getMetaStringValue(label,"label"))
  3636. if (!pi->getMetaStringValue(label,"xml_tag"))
  3637. label = pi->name;
  3638. if (pi->getMetaInt("rows") || (pi->flags & PF_TEMPLATE))
  3639. {
  3640. int cols = pi->getMetaInt("cols", 50);
  3641. indentOuts("extfix.clear();\n");
  3642. indentOuts("if (prefix && *prefix)\n");
  3643. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3644. indentOutf("extfix.append(\"%s\");\n", pi->name);
  3645. indentOutf("form.appendf(\"<tr><td><b>%s: </b></td><td>\");\n", label.str());
  3646. if (!pi->isEspStringArray())
  3647. {
  3648. // handle default value
  3649. StrBuffer tmp;
  3650. const char* def = pi->getMetaStringValue(tmp,"default") ? tmp.str() : "";
  3651. indentOutf("form.appendf(\"<table><tr><td><textarea name=\\\"%%s\\\" cols=\\\"%d\\\" rows=\\\"%d\\\">%s</textarea></td>\", extfix.str());\n",
  3652. cols, rows, def);
  3653. indentOutf("form.append(\"</tr></table>\");\n");
  3654. }
  3655. else
  3656. {
  3657. indentOutf("form.appendf(\"<textarea name=\\\"%%s\\\" cols=\\\"%d\\\" rows=\\\"%d\\\"></textarea>\", extfix.str());\n", cols, rows);
  3658. }
  3659. indentOutf("form.append(\"</td></tr>\");\n");
  3660. }
  3661. else
  3662. {
  3663. esp_xlate_info *espinfo = esp_xlat(pi);
  3664. if (pi->kind==TK_ESPSTRUCT)
  3665. {
  3666. indentOuts("extfix.clear();\n");
  3667. indentOuts("if (prefix && *prefix)\n");
  3668. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3669. indentOutf("extfix.append(\"%s\");\n", pi->getXmlTag());
  3670. indentOutf("form.append(\"<tr>\").append(\"<td><b>%s: </b></td><td><hr/>\");\n", label.str());
  3671. indentOutf("C%s::getHtmlForm(context, request, serv, method, form, false, extfix.str());\n", pi->typname);
  3672. indentOuts("form.append(\"<hr/></td></tr>\");\n");
  3673. }
  3674. else if (espinfo->access_kind==TK_BOOL)
  3675. {
  3676. indentOuts("extfix.clear();\n");
  3677. indentOuts("if (prefix && *prefix)\n");
  3678. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3679. indentOutf("extfix.append(\"%s\");\n", pi->getXmlTag());
  3680. // handle default value
  3681. indentOutf("\n\tform.appendf(\" <tr><td><b>%s? </b></td><td><input type=\\\"checkbox\\\" name=\\\"%%s\\\" value=\\\"1\\\" %s /></td></tr>\\n\", extfix.str());\n",
  3682. label.str(), pi->getMetaInt("default",0)?"checked=\\\"1\\\"":"");
  3683. }
  3684. else if (espinfo->access_kind==TK_INT || espinfo->access_kind==TK_UNSIGNED
  3685. || espinfo->access_kind==TK_SHORT || espinfo->access_kind==TK_UNSIGNEDSHORT)
  3686. {
  3687. indentOuts("extfix.clear();\n");
  3688. indentOuts("if (prefix && *prefix) extfix.append(prefix).append(\".\");\n");
  3689. indentOutf("\textfix.append(\"%s\");\n", pi->getXmlTag());
  3690. int cols = pi->getMetaInt("cols", 20);
  3691. indentOutf("form.appendf(\" <tr><td><b>%s: </b></td><td><input type=\\\"text\\\" name=\\\"%%s\\\" size=\\\"%d\\\"", label.str(), cols);
  3692. int defValue = pi->getMetaInt("default");
  3693. if (defValue!=0)
  3694. indentOutf(" value=\\\"%d\\\"", defValue);
  3695. outs("/>\", extfix.str());\n");
  3696. indentOuts("form.append(\"</td></tr>\\n\");\n");
  3697. }
  3698. //TODO: handle default value for float, double, long, longlong etc
  3699. else
  3700. {
  3701. const char *xsdtype = pi->getXsdType();
  3702. bool isDate = (!stricmp(xsdtype, "date"));
  3703. const char *inputType = "text";
  3704. if (pi->typname && !strcmp(pi->typname, "EspTextFile"))
  3705. inputType="file";
  3706. else if (pi->getMetaInt("password"))
  3707. inputType="password";
  3708. indentOuts("extfix.clear();\n");
  3709. indentOuts("if (prefix && *prefix)\n");
  3710. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3711. indentOutf("extfix.append(\"%s\");\n", pi->getXmlTag());
  3712. // handle default value
  3713. StrBuffer tmp;
  3714. const char* def = pi->getMetaStringValue(tmp,"default") ? tmp.str() : "";
  3715. int cols = pi->getMetaInt("cols", isDate ? 20 : 50);
  3716. indentOutf("form.appendf(\" <tr><td><b>%s: </b></td><td><input type=\\\"%s\\\" name=\\\"%%s\\\" size=\\\"%d\\\" value=\\\"%s\\\" />\", extfix.str());\n", label.str(), inputType, cols, def);
  3717. if (isDate)
  3718. indentOutf("form.append(\"<a href=\\\"javascript:show_calendar('%s');\\\"><img src=\\\"files_/img/cal.gif\\\" width=\\\"16\\\" height=\\\"16\\\" border=\\\"0\\\" alt=\\\"Pick Date\\\"/><br/>\");\n", pi->name);
  3719. indentOuts("form.append(\"</td></tr>\\n\");\n");
  3720. }
  3721. }
  3722. }
  3723. if (hasMapInfo)
  3724. indentOuts(-1,"}\n");
  3725. }
  3726. indentReset(1);
  3727. indentOuts("if (includeFormTag) {\n");
  3728. indentOuts(1,"form.append(\"<tr><td></td><td><input type=\\\"submit\\\" value=\\\"Submit\\\" name=\\\"S1\\\" />\");\n");
  3729. indentOuts("form.append(\" &nbsp; <input type=\\\"reset\\\" value=\\\"Clear\\\"/> </td> </tr>\");\n");
  3730. indentOuts(-1,"}\n");
  3731. indentOuts("form.append(\"</table>\");\n");
  3732. indentOuts("if (includeFormTag)\n");
  3733. indentOuts(1,"form.append(\"</form>\");\n");
  3734. indentOuts(-1,"return form;\n");
  3735. indentOuts(-1,"}\n");
  3736. //method ==> serializeHtml
  3737. outf("\nStringBuffer &C%s::serializeHtml(IEspContext &context, const char *serv, const char *method, StringBuffer &html)\n", name_);
  3738. outs("{\n");
  3739. if (getMetaInt("serialize_html"))
  3740. {
  3741. outs("\thtml.append(\"<p align=\\\"left\\\">\");\n");
  3742. if (contentVar)
  3743. {
  3744. if (!(contentVar->flags & PF_TEMPLATE))
  3745. {
  3746. if (contentVar->typname!=NULL && strcmp(contentVar->typname, "EspResultSet")==0)
  3747. {
  3748. outf("\thtml.appendf(\"<br/><b>%s: </b><br/>\");\n", contentVar->name);
  3749. outf("\tEspHttpBinding::formatHtmlResultSet(context, serv, method, m_%s->str(), html);", contentVar->name);
  3750. }
  3751. else if (contentVar->typname==NULL || strcmp(contentVar->typname, "binary")!=0)
  3752. {
  3753. outf("\thtml.appendf(\"<br/><b>%s: </b><br/><input type=\\\"text\\\" name=\\\"%s\\\" size=\\\"50\\\" readonly=\\\"1\\\" value=\\\"\").append(m_%s.getValue()).append(\"\\\"/>\");\n", contentVar->name, contentVar->name, contentVar->name);
  3754. }
  3755. }
  3756. }
  3757. else
  3758. {
  3759. for (pi=getParams();pi!=NULL;pi=pi->next)
  3760. {
  3761. if (!(pi->flags & PF_TEMPLATE) && (pi->kind!=TK_ESPSTRUCT))
  3762. {
  3763. if (pi->typname!=NULL && strcmp(pi->typname, "EspResultSet")==0)
  3764. {
  3765. outf("\thtml.appendf(\"<br/><b>%s: </b><br/>\");\n", pi->name);
  3766. outf("\tEspHttpBinding::formatHtmlResultSet(context, serv, method, m_%s->str(), html);", pi->name);
  3767. }
  3768. else if (pi->typname==NULL || strcmp(pi->typname, "binary")!=0)
  3769. {
  3770. outf("\thtml.appendf(\"<br/><b>%s: </b><br/><input type=\\\"text\\\" name=\\\"%s\\\" size=\\\"50\\\" readonly=\\\"1\\\" value=\\\"\").append(m_%s.getValue()).append(\"\\\"/>\");\n", pi->name, pi->name, pi->name);
  3771. }
  3772. }
  3773. }
  3774. }
  3775. outs("\thtml.append(\"</p>\");\n");
  3776. }
  3777. outs("\treturn html;\n");
  3778. outs("}\n");
  3779. //method ==> serialize (IRpcMessage&)
  3780. outf("\nvoid C%s::serialize(IRpcMessage& rpc_resp)\n{\n", name_);
  3781. if (parent)
  3782. outf("\tC%s::serialize(rpc_resp);\n", parent);
  3783. // versioning
  3784. if (hasMapInfo())
  3785. {
  3786. outf("\tIEspContext* ctx = rpc_resp.queryContext();\n");
  3787. outf("\tdouble clientVer= ctx ? ctx->getClientVersion() : -1; /* no context gets everything */\n");
  3788. }
  3789. outf("\trpc_resp.set_ns(%s);\n", getMetaString("ns_var", "\"\""));
  3790. outs("\trpc_resp.set_name(m_msgName.str());\n");
  3791. const char *nsuri = getMetaString("ns_uri", NULL);
  3792. if (nsuri)
  3793. outf("\trpc_resp.set_nsuri(%s);\n\n", nsuri);
  3794. else
  3795. {
  3796. outs("\tStringBuffer nsuri;\n");
  3797. outs("\tnsuri.append(\"urn:hpccsystems:ws:\").appendLower(m_serviceName.length(), m_serviceName.str());\n");
  3798. outs("\trpc_resp.set_nsuri(nsuri.str());\n\n");
  3799. }
  3800. int soap_encode = getMetaInt("soap_encode", -1);
  3801. if (soap_encode ==-1)
  3802. soap_encode = getMetaInt("encode", 1);
  3803. if (soap_encode==0)
  3804. outs("\trpc_resp.setEncodeXml(false);\n");
  3805. if (espm_type_==espm_response)
  3806. {
  3807. outs(
  3808. "\tconst IMultiException& exceptions = getExceptions();\n"
  3809. "\tif (exceptions.ordinality() > 0)\n"
  3810. "\t{\n"
  3811. "\t\tStringBuffer xml;\n"
  3812. "\t\texceptions.serialize(xml, 0, true, false);\n"
  3813. "\t\trpc_resp.add_value(\"\", \"\", \"Exceptions\", \"\", xml.str(), false);\n"
  3814. "\t}\n"
  3815. "\telse\n"
  3816. "\t{\n");
  3817. }
  3818. //attributes first
  3819. int attrCount=0;
  3820. for (pi=getParams();pi!=NULL;pi=pi->next)
  3821. {
  3822. if (pi->getMetaInt("attribute"))
  3823. {
  3824. attrCount++;
  3825. if (attrCount==1)
  3826. outs(1, "Owned<IProperties> props=createProperties();\n");
  3827. outf(1, "if (!m_%s.is_nil())\n", pi->name);
  3828. outf(2, "props->setProp(\"%s\", m_%s.getValue());\n", pi->getXmlTag(), pi->name);
  3829. }
  3830. }
  3831. if (attrCount!=0)
  3832. outs(1, "rpc_resp.add_attr(NULL, NULL, NULL, *props.get());\n");
  3833. for (pi=getParams();pi!=NULL;pi=pi->next)
  3834. {
  3835. pi->write_esp_marshall(true, true, true, (espm_type_==espm_response)?2:1);
  3836. }
  3837. if (espm_type_==espm_response)
  3838. outs("\t}\n");
  3839. outs("}\n\n");
  3840. //method ==> copy
  3841. outf("\nvoid C%s::copy(C%s &from)\n{\n", name_, name_);
  3842. if (parent)
  3843. {
  3844. outf(1, "C%s *baseFrom = static_cast<C%s*>(&from);\n", parent, parent);
  3845. outf(2, "C%s::copy(*baseFrom);\n", parent);
  3846. }
  3847. for (pi=getParams();pi!=NULL;pi=pi->next)
  3848. outf("\tm_%s.copy(from.m_%s);\n", pi->name, pi->name);
  3849. if (getMetaInt("element"))
  3850. outf("\tset_tag_value(from.get_tag_value());\n");
  3851. outs("}\n\n");
  3852. //method ==> copy from interface
  3853. outf("\nvoid C%s::copy(IConst%s &ifrom)\n{\n", name_, name_);
  3854. if (parent)
  3855. {
  3856. outf(1, "C%s *classFrom = static_cast<C%s*>(&ifrom);\n", name_, name_);
  3857. outf(1, "IConst%s *baseICFrom = static_cast<IConst%s*>(classFrom);\n", parent, parent);
  3858. outf(2, "C%s::copy(*baseICFrom);\n", parent);
  3859. }
  3860. for (pi=getParams();pi!=NULL;pi=pi->next)
  3861. {
  3862. char *uname=strdup(pi->name);
  3863. *uname=upperchar(*uname);
  3864. outf("\tset%s(ifrom.get%s());\n", uname, uname);
  3865. free(uname);
  3866. }
  3867. if (getMetaInt("element"))
  3868. outf("\tset_tag_value(ifrom.get_tag_value());\n");
  3869. outs("}\n\n");
  3870. //method ==> getAttributes (IProperties &attributes)
  3871. outf("\nvoid C%s::getAttributes(IProperties &attributes)\n{\n", name_);
  3872. for (pi=getParams(); pi!=NULL; pi=pi->next)
  3873. {
  3874. if (pi->getMetaInt("attribute"))
  3875. outf(2, "attributes.setProp(\"%s\", m_%s.getValue());\n", pi->getXmlTag(), pi->name);
  3876. }
  3877. outs("}\n\n");
  3878. //method ==> serializeContent (StringBuffer&)
  3879. outf("\nvoid C%s::serializeContent(IEspContext* ctx, StringBuffer& buffer, IProperties **pprops)\n{\n", name_);
  3880. int http_encode = getMetaInt("http_encode", -1);
  3881. if (http_encode ==-1)
  3882. http_encode = getMetaInt("encode", 1);
  3883. bool encodeXML = http_encode==1;
  3884. if (espm_type_==espm_response)
  3885. {
  3886. outs(
  3887. "\tconst IMultiException& exceptions = getExceptions();\n"
  3888. "\tif (exceptions.ordinality() > 0)\n"
  3889. "\t\texceptions.serialize(buffer, 0, true);\n"
  3890. "\telse\n"
  3891. "\t{\n");
  3892. if (parent)
  3893. outf("\t\tC%s::serializeContent(ctx,buffer);\n", parent);
  3894. if (hasMapInfo())
  3895. outf("\t\tdouble clientVer = ctx ? ctx->getClientVersion() : -1;\n");
  3896. for (pi=getParams();pi!=NULL;pi=pi->next)
  3897. {
  3898. if (!pi->getMetaInt("attribute"))
  3899. pi->write_esp_marshall(false, encodeXML, true, 2);
  3900. }
  3901. outs("\t}\n");
  3902. }
  3903. else
  3904. {
  3905. if (parent)
  3906. outf("\tC%s::serializeContent(ctx,buffer);\n", parent);
  3907. if (hasMapInfo())
  3908. outf("\tdouble clientVer = ctx ? ctx->getClientVersion() : -1;\n");
  3909. //attributes first
  3910. int attrCount=0;
  3911. for (pi=getParams();pi!=NULL;pi=pi->next)
  3912. {
  3913. if (pi->getMetaInt("attribute"))
  3914. {
  3915. attrCount++;
  3916. if (attrCount==1)
  3917. {
  3918. outs(1, "if (pprops)\n");
  3919. outs(1, "{\n");
  3920. outs(2, "*pprops=NULL;\n");
  3921. }
  3922. outf(2, "if (!m_%s.is_nil())\n", pi->name);
  3923. outs(2, "{\n");
  3924. outs(3, "if (!*pprops)\n");
  3925. outs(4, "*pprops=createProperties();\n");
  3926. outf(3, "(*pprops)->setProp(\"%s\", m_%s.getValue());\n", pi->getXmlTag(), pi->name);
  3927. outs(2, "}\n");
  3928. }
  3929. }
  3930. if (attrCount!=0)
  3931. outs(1, "}\n");
  3932. for (pi=getParams();pi!=NULL;pi=pi->next)
  3933. {
  3934. if (!pi->getMetaInt("attribute"))
  3935. pi->write_esp_marshall(false, encodeXML, true);
  3936. }
  3937. if (getMetaInt("element")!=0)
  3938. {
  3939. outs(1, "if (m_tag_value.length()) {\n");
  3940. outs(2, "StringBuffer encoded;\n");
  3941. outs(2, "encodeXML(m_tag_value, encoded);\n");
  3942. outs(2, "buffer.append(encoded);\n");
  3943. outs(1, "}\n");
  3944. }
  3945. }
  3946. outs("}\n\n");
  3947. //method ==> serialize (StringBuffer&)
  3948. outf("\nvoid C%s::serializeAttributes(IEspContext* ctx, StringBuffer& s)\n{\n", name_);
  3949. for (pi=getParams();pi!=NULL;pi=pi->next)
  3950. {
  3951. if (pi->getMetaInt("attribute"))
  3952. {
  3953. outf(1, "if (!m_%s.is_nil()) {\n", pi->name);
  3954. outf(2, "StringBuffer enc;\n");
  3955. outf(2, "encodeXML(m_%s.getValue(), enc);\n", pi->name);
  3956. outf(2, "s.appendf(\" %s=\\\"%%s\\\"\", enc.str());\n", pi->getXmlTag());
  3957. outf(1, "}\n");
  3958. }
  3959. }
  3960. outs("}\n");
  3961. //method ==> serializer(IEspContext* ctx, ..., StringBuffer&, ...)
  3962. outf("\nvoid C%s::serializer(IEspContext* ctx, IConst%s &src, StringBuffer& buffer, bool keepRootTag)\n{\n", name_, name_);
  3963. // attributes
  3964. int nAttrs = 0;
  3965. for (pi=getParams();pi!=NULL;pi=pi->next)
  3966. if (pi->getMetaInt("attribute"))
  3967. nAttrs++;
  3968. if (nAttrs)
  3969. {
  3970. outf(1,"if (keepRootTag)\n\t{\n");
  3971. outf(2,"buffer.append(\"<%s\");\n", name_);
  3972. for (pi=getParams();pi!=NULL;pi=pi->next)
  3973. {
  3974. if (pi->getMetaInt("attribute"))
  3975. {
  3976. char* fname = getFieldName(pi->name);
  3977. outf(2, "%sattr = src.get%s();\n", (pi==getParams())?"const char* ":"", fname);
  3978. free(fname);
  3979. outf(2, "if (attr && *attr) {\n");
  3980. outf(3, "StringBuffer encoded;\n");
  3981. outf(3, "encodeXML(attr,encoded);\n");
  3982. outf(3, "buffer.appendf(\" %s=\\\"%%s\\\"\",encoded.str());\n", pi->getXmlTag());
  3983. outf(2, "}\n");
  3984. }
  3985. }
  3986. outf(2,"buffer.append(\">\");\n");
  3987. outf(1,"}\n");
  3988. }
  3989. else
  3990. outf(1,"if (keepRootTag)\n\tbuffer.append(\"<%s>\");\n", name_);
  3991. if (parent)
  3992. {
  3993. outf(1, "C%s *classSrc = static_cast<C%s*>(&src);\n", name_, name_);
  3994. outf(1, "C%s *baseSrc = static_cast<C%s*>(classSrc);\n", parent, parent);
  3995. outf(2, "C%s::serializer(ctx, *baseSrc, buffer, false);\n",parent);
  3996. }
  3997. // -- versioning
  3998. if (hasMapInfo())
  3999. {
  4000. outf("\tdouble clientVer = ctx ? ctx->getClientVersion() : -1;\n");
  4001. }
  4002. #if 1
  4003. // not respecting nil_remove: backward compatible
  4004. for (pi=getParams();pi!=NULL;pi=pi->next)
  4005. {
  4006. if (pi->getMetaInt("attribute"))
  4007. continue;
  4008. outf("\t// field %s\n", pi->name);
  4009. char *uname=getFieldName(pi->name);
  4010. bool hasIf = false;
  4011. if (pi->hasMapInfo())
  4012. hasIf = pi->write_mapinfo_check(1,"ctx");
  4013. //if (hasIf) outs("\t{\n");
  4014. const char* ifIndent = hasIf?"\t":"";
  4015. if (pi->flags & PF_TEMPLATE) // array
  4016. {
  4017. outf("\t{\n");
  4018. if (pi->isPrimitiveArray())
  4019. {
  4020. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4021. const char *type = pi->getArrayImplType();
  4022. outf("\t\t%s& v = src.get%s();\n",type,uname);
  4023. outf("\t\tif (v.length()>0)\n");
  4024. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4025. outf("\t\tfor (size32_t i=0;i<v.length();i++)\n");
  4026. const char* fmt = "%"; // print %% when undefined
  4027. switch(pi->kind)
  4028. {
  4029. case TK_BOOL:
  4030. case TK_SHORT:
  4031. case TK_INT: fmt = "d"; break;
  4032. case TK_UNSIGNED: fmt = "u"; break;
  4033. case TK_LONG: fmt = "ld"; break;
  4034. case TK_UNSIGNEDLONG: fmt = "lu"; break;
  4035. case TK_FLOAT:
  4036. case TK_DOUBLE: fmt = "g"; break;
  4037. case TK_null:
  4038. case TK_CHAR: fmt = "s"; break;
  4039. default:
  4040. {
  4041. char buf[128];
  4042. sprintf(buf,"Unhandled array type: %s (%s)", getTypeKindName(pi->kind), name_);
  4043. yyerror(buf);
  4044. }
  4045. }
  4046. outf("\t\t\tbuffer.appendf(\"<%s>%%%s</%s>\",v.item(i));\n",item_tag,fmt,item_tag);
  4047. outf("\t\tif (v.length()>0)\n");
  4048. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4049. }
  4050. else if (pi->typname)
  4051. {
  4052. if (pi->kind == TK_ESPENUM)
  4053. {
  4054. outf("\t\t%sArray& v = src.get%s();\n",pi->typname,uname);
  4055. outf("\t\tint size = v.length();\n");
  4056. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4057. outf("\t\tif (size>0)\n");
  4058. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4059. outf("\t\tfor (int i=0;i<size;i++)\n");
  4060. //outf("\t\t{\n");
  4061. outf("\t\t\tbuffer.appendf(\"<%s>%%s</%s>\", CX%s::stringOf(v.item(i)));\n",item_tag, item_tag, pi->typname);
  4062. //outf("\t\t\tC%s::serializer(ctx,v.item(i),buffer,false);\n",pi->typname);
  4063. //outf("\t\t\tbuffer.append(\"</%s>\");\n",item_tag);
  4064. //outf("\t\t}\n");
  4065. outf("\t\tif (size>0)\n");
  4066. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4067. }
  4068. else if (pi->kind == TK_ESPSTRUCT || pi->kind == TK_null) // should be fixed at lex/yacc
  4069. {
  4070. outf("\t\tIArrayOf<IConst%s>& v = src.get%s();\n",pi->typname,uname);
  4071. outf("\t\tint size = v.length();\n");
  4072. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4073. outf("\t\tif (size>0)\n");
  4074. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4075. outf("\t\tfor (int i=0;i<size;i++)\n");
  4076. outf("\t\t{\n");
  4077. outf("\t\t\tbuffer.append(\"<%s>\");\n",item_tag);
  4078. outf("\t\t\tC%s::serializer(ctx,v.item(i),buffer,false);\n",pi->typname);
  4079. outf("\t\t\tbuffer.append(\"</%s>\");\n",item_tag);
  4080. outf("\t\t}\n");
  4081. outf("\t\tif (size>0)\n");
  4082. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4083. }
  4084. else
  4085. outf("\t\t**** TODO: unhandled array: kind=%s, type=%s, name=%s, xsd-type=%s\n", getTypeKindName(pi->kind), pi->typname, uname, pi->getXsdType());
  4086. }
  4087. else
  4088. {
  4089. outf("\t\t**** TODO: unhandled array: type=<NULL>, name=%s, xsd-type=%s\n", uname, pi->getXsdType());
  4090. }
  4091. outf("\t}\n");
  4092. }
  4093. else if (pi->kind == TK_ESPSTRUCT)
  4094. {
  4095. outf("\t{\n");
  4096. outf("\t\tStringBuffer tmp;\n");
  4097. outf("\t\tC%s::serializer(ctx,src.get%s(), tmp, false);\n", pi->typname, uname);
  4098. outf("\t\tif (tmp.length()>0)\n");
  4099. const char* tag = pi->getXmlTag();
  4100. outf("\t\t\tbuffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag, tag);
  4101. outf("\t}\n");
  4102. }
  4103. else if (pi->kind == TK_ESPENUM)
  4104. {
  4105. outs("\t{\n");
  4106. outf("\t\tconst char* s = src.get%sAsString();\n",uname);
  4107. outf("\t\tbuffer.append(\"<%s>\");\n",pi->getXmlTag());
  4108. outs("\t\tencodeUtf8XML(s,buffer);\n");
  4109. outf("\t\tbuffer.append(\"</%s>\");\n",pi->getXmlTag());
  4110. outs("\t}\n");
  4111. }
  4112. else
  4113. {
  4114. esp_xlate_info* info = esp_xlat(pi);
  4115. switch(info->access_kind)
  4116. {
  4117. case TK_CHAR:
  4118. outf("\t{\n");
  4119. outf("\t\tconst char* s = src.get%s();\n", uname);
  4120. outf("\t\tif (s && *s)\n");
  4121. if (!getMetaInt("encode",1))
  4122. {
  4123. outf("\t\tbuffer.appendf(\"<%s>%%s</%s>\",s);\n",pi->name,pi->name);
  4124. }
  4125. else
  4126. {
  4127. outf("\t\t{\n");
  4128. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4129. outf("\t\t\tencodeUtf8XML(s,buffer);\n");
  4130. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4131. outf("\t\t}\n");
  4132. }
  4133. outf("\t}\n");
  4134. break;
  4135. case TK_INT:
  4136. case TK_SHORT:
  4137. {
  4138. outf("\t{\n");
  4139. outf("\t\t%s n = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4140. outf("\t\tif (n)\n");
  4141. const char* tag = pi->getXmlTag();
  4142. outf("\t\t\tbuffer.appendf(\"<%s>%%d</%s>\", n);\n", tag, tag);
  4143. outf("\t}\n");
  4144. break;
  4145. }
  4146. case TK_LONG:
  4147. {
  4148. outf("\t{\n");
  4149. outf("\t\t%s n = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4150. outf("\t\tif (n)\n");
  4151. const char* tag = pi->getXmlTag();
  4152. outf("\t\t\tbuffer.appendf(\"<%s>%%\" I64F \"d</%s>\", n);\n", tag, tag);
  4153. outf("\t}\n");
  4154. break;
  4155. }
  4156. case TK_BOOL:
  4157. {
  4158. outf("\t{\n");
  4159. outf("\t\t%s b = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4160. outf("\t\tif (b)\n");
  4161. const char* tag = pi->getXmlTag();
  4162. outf("\t\t\tbuffer.appendf(\"<%s>1</%s>\");\n", tag, tag);
  4163. outf("\t}\n");
  4164. break;
  4165. }
  4166. default:
  4167. if (pi->kind == TK_STRUCT && info->eam_type == EAM_jmbin) // binary
  4168. {
  4169. //TODO: should we encode binary data?
  4170. outf("\t{\n");
  4171. outf("\t\tStringBuffer tmp;\n");
  4172. outf("\t\tJBASE64_Encode(src.get%s().toByteArray(), src.get%s().length(), tmp);\n", uname, uname);
  4173. outf("\t\tif (tmp.length()>0)\n");
  4174. const char* tag = pi->getXmlTag();
  4175. outf("\t\t\tbuffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag, tag);
  4176. outf("\t}\n");
  4177. }
  4178. else
  4179. {
  4180. outf("\t{\n");
  4181. outf("\t\t//*** default kind: %s; type=%s, name=%s\n", getTypeKindName(pi->kind), pi->typname, uname);
  4182. outf("\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4183. outf("\t\tbuffer.append(src.get%s());\n", uname);
  4184. outf("\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4185. outf("\t}\n");
  4186. }
  4187. break;
  4188. }
  4189. }
  4190. //if (hasIf) outs("\t}\n");
  4191. free(uname);
  4192. }
  4193. #else
  4194. // respect nil_remove: may cause backward compatibility problem
  4195. bool nilRemove = getMetaInt("nil_remove", 0)!=0;
  4196. indentReset(1);
  4197. for (pi=getParams();pi!=NULL;pi=pi->next)
  4198. {
  4199. char *uname=strdup(pi->name);
  4200. *uname = upperchar(*uname);
  4201. if (pi->hasMapInfo())
  4202. pi->write_mapinfo_check(1,"ctx");
  4203. if (pi->flags & PF_TEMPLATE) // array
  4204. {
  4205. indentOutf("{\n");
  4206. indentInc(1);
  4207. if (pi->isPrimitiveArray())
  4208. {
  4209. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4210. const char *type = pi->getArrayImplType();
  4211. indentOutf("%s& v = src.get%s();\n",type,uname);
  4212. indentOutf("int size = v.length();\n");
  4213. if (nilRemove)
  4214. {
  4215. indentOutf("if (size>0)\n");
  4216. indentOutf1(1,"buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4217. }
  4218. else
  4219. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4220. indentOuts("for (int i=0;i<size;i++)\n");
  4221. const char* fmt;
  4222. switch(pi->kind)
  4223. {
  4224. case TK_BOOL:
  4225. case TK_SHORT:
  4226. case TK_INT: fmt = "d"; break;
  4227. case TK_UNSIGNED: fmt = "u"; break;
  4228. case TK_LONG: fmt = "ld"; break;
  4229. case TK_UNSIGNEDLONG: fmt = "lu"; break;
  4230. case TK_FLOAT:
  4231. case TK_DOUBLE: fmt = "g"; break;
  4232. case TK_null:
  4233. case TK_CHAR: fmt = "s"; break;
  4234. default:
  4235. {
  4236. char buf[128];
  4237. sprintf(buf,"Unhandled array type: %s (%s)", getTypeKindName(pi->kind), name_);
  4238. yyerror(buf);
  4239. }
  4240. }
  4241. indentOutf1(1,"buffer.appendf(\"<%s>%%%s</%s>\",v.item(i));\n",item_tag,fmt,item_tag);
  4242. if (nilRemove)
  4243. {
  4244. indentOutf("if (size>0)\n");
  4245. indentOutf1(1,"buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4246. }
  4247. else
  4248. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4249. }
  4250. else if (pi->typname)
  4251. {
  4252. indentOutf("IArrayOf<IConst%s>& v = src.get%s();\n",pi->typname,uname);
  4253. indentOuts("int size = v.length();\n");
  4254. const char *item_tag = pi->getMetaString("item_tag", pi->typname);
  4255. if (nilRemove)
  4256. {
  4257. indentOutf("if (size>0)\n");
  4258. indentOutf1(1,"buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4259. }
  4260. else
  4261. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4262. indentOutf("for (int i=0;i<size;i++)\n");
  4263. indentOutf("{\n");
  4264. indentOutf(1,"buffer.append(\"<%s>\");\n",item_tag);
  4265. indentOutf("C%s::serializer(ctx,v.item(i),buffer,false);\n",pi->typname);
  4266. indentOutf("buffer.append(\"</%s>\");\n",item_tag);
  4267. indentOutf(-1,"}\n");
  4268. if (nilRemove)
  4269. {
  4270. indentOutf("if (size>0)\n");
  4271. indentOutf1(1,"buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4272. }
  4273. else
  4274. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4275. }
  4276. else
  4277. {
  4278. indentOutf("**** TODO: unhandled array: type=%s, name=%s, xsd-type=%s\n", pi->typname, uname, pi->getXsdType());
  4279. }
  4280. indentOutf(-1,"}\n");
  4281. }
  4282. else if (pi->kind == TK_ESPSTRUCT)
  4283. {
  4284. indentOutf("{\n");
  4285. indentInc(1);
  4286. if (nilRemove)
  4287. {
  4288. indentOutf("StringBuffer tmp;\n");
  4289. indentOutf("C%s::serializer(ctx,src.get%s(), tmp, false);\n", pi->typname, uname);
  4290. indentOutf("if (tmp.length()>0)\n");
  4291. const char* tag = pi->getXmlTag();
  4292. indentOutf1(1,"buffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag, tag);
  4293. }
  4294. else
  4295. {
  4296. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4297. indentOutf("C%s::serializer(ctx,src.get%s(), buffer, false);\n", pi->typname, uname);
  4298. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4299. }
  4300. indentOutf(-1,"}\n");
  4301. }
  4302. else
  4303. {
  4304. esp_xlate_info* info = esp_xlat(pi);
  4305. switch(info->access_kind)
  4306. {
  4307. case TK_CHAR:
  4308. indentOuts("{\n");
  4309. indentOutf(1,"const char* s = src.get%s();\n", uname);
  4310. if (nilRemove)
  4311. {
  4312. indentOutf("if (s && *s)\n");
  4313. indentInc(1);
  4314. }
  4315. if (!getMetaInt("encode",1))
  4316. {
  4317. indentOutf("buffer.appendf(\"<%s>%%s</%s>\",s);\n",pi->name,pi->name);
  4318. }
  4319. else
  4320. {
  4321. if (nilRemove)
  4322. indentOutf1(-1,"{\n");
  4323. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4324. indentOutf("encodeUtf8XML(s,buffer);\n");
  4325. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4326. if (nilRemove)
  4327. indentOutf1(-1,"}\n");
  4328. }
  4329. if (nilRemove)
  4330. indentInc(-1);
  4331. indentOuts(-1,"}\n");
  4332. break;
  4333. case TK_INT:
  4334. case TK_LONG:
  4335. case TK_SHORT:
  4336. indentOuts("{\n");
  4337. indentOutf(1,"%s n = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4338. if (nilRemove)
  4339. {
  4340. indentOuts("if (n)\n");
  4341. indentInc(1);
  4342. }
  4343. indentOutf("buffer.appendf(\"<%s>%%d</%s>\", n);\n", pi->name,pi->name);
  4344. if (nilRemove)
  4345. indentInc(-1);
  4346. indentOuts(-1,"}\n");
  4347. break;
  4348. case TK_BOOL:
  4349. indentOuts("{\n");
  4350. indentOutf(1,"%s b = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4351. if (nilRemove)
  4352. {
  4353. indentOuts("if (b)\n");
  4354. indentInc(1);
  4355. }
  4356. const char* tag = pi->getXmlTag();
  4357. indentOutf("buffer.append(\"<%s>1</%s>\");\n", tag,tag);
  4358. if (nilRemove)
  4359. indentInc(-1);
  4360. indentOuts(-1,"}\n");
  4361. break;
  4362. default:
  4363. if (pi->kind == TK_STRUCT && info->eam_type == EAM_jmbin) // binary
  4364. {
  4365. //TODO: should we encode binary data?
  4366. indentOuts("{\n");
  4367. if (nilRemove)
  4368. {
  4369. indentOutf(1,"StringBuffer tmp;\n");
  4370. indentOutf("JBASE64_Encode(src.get%s().toByteArray(), src.get%s().length(), tmp);\n", uname, uname);
  4371. indentOutf("if (tmp.length()>0)\n");
  4372. const char* tag = pi->getXmlTag();
  4373. indentOutf1(1,"buffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag,tag);
  4374. }
  4375. else
  4376. {
  4377. indentOutf(1,"buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4378. indentOutf("JBASE64_Encode(src.get%s().toByteArray(), src.get%s().length(), buffer);\n", uname, uname);
  4379. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4380. }
  4381. indentOuts(-1,"}\n");
  4382. }
  4383. else
  4384. {
  4385. indentOuts("{\n");
  4386. if (nilRemove)
  4387. {
  4388. indentOutf(1,"//*** default kind: %s; type=%s, name=%s\n", getTypeKindName(pi->kind), pi->typname, uname);
  4389. indentOutf("StringBuffer tmp(src.get%s());\n",uname);
  4390. indentOutf("if (tmp.length()>0)\n");
  4391. indentOutf1(1,"buffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", pi->name,pi->name);
  4392. }
  4393. else
  4394. {
  4395. indentOutf(1,"//*** default kind: %s; type=%s, name=%s\n", getTypeKindName(pi->kind), pi->typname, uname);
  4396. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4397. indentOutf("buffer.append(src.get%s());\n", uname);
  4398. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4399. }
  4400. indentOuts(-1,"}\n");
  4401. }
  4402. break;
  4403. }
  4404. }
  4405. free(uname);
  4406. }
  4407. #endif
  4408. outf("\tif (keepRootTag)\n\t\tbuffer.append(\"</%s>\");\n", name_);
  4409. outs("}\n");
  4410. //=============================================================================================================
  4411. //method ==> serialize (MemoryBuffer&, StringBuffer &)
  4412. if (contentVar)
  4413. {
  4414. outf("\nvoid C%s::appendContent(IEspContext* ctx, MemoryBuffer& buffer, StringBuffer &mimetype)\n{\n", name_);
  4415. esp_xlate_info *xinfo = esp_xlat(contentVar);
  4416. if (strcmp(xinfo->store_type, "StringBuffer")!=0)
  4417. outf("\tbuffer.clear().append(m_%s.getValue());\n", contentVar->name);
  4418. else
  4419. outf("\tbuffer.clear().append(m_%s.getValue().length(), m_%s.getValue().str());\n", contentVar->name, contentVar->name);
  4420. outf("\tmimetype.set(m_%s_mimetype.str());\n", contentVar->name);
  4421. outs("}\n");
  4422. }
  4423. //=============================================================================================================
  4424. //method: unserialize(IRcpMessage...)
  4425. outf("\nbool C%s::unserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath)\n{\n", name_);
  4426. if (parent)
  4427. {
  4428. outf("\tbool hasValue = C%s::unserialize(rpc_request, tagname, basepath);\n", parent);
  4429. outf("\treturn hasValue | localUnserialize(rpc_request, tagname, basepath);\n");
  4430. outs("}\n");
  4431. //method: localUnserialize(IRcpMessage...)
  4432. outf("\nbool C%s::localUnserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath)\n{\n", name_);
  4433. }
  4434. outs("\trpc_request.setEncodeXml(false);\n");
  4435. outs("\tbool hasValue = false;\n");
  4436. if (espm_type_==espm_response)
  4437. {
  4438. outs(
  4439. "\tStringBuffer xml;\n"
  4440. "\trpc_request.get_value(\"Exceptions\", xml, false);\n\n"
  4441. "\tOwned<IMultiException> me = MakeMultiException();\n"
  4442. "\tif(xml.length() > 0)\n"
  4443. "\t\tme->deserialize(xml.str());\n\n"
  4444. "\tif (me->ordinality() > 0 )\n"
  4445. "\t{\n"
  4446. "\t\tIArrayOf<IException>& exceptions = me->getArray();\n"
  4447. "\t\tForEachItemIn(i, exceptions)\n"
  4448. "\t\t\tnoteException(*LINK(&exceptions.item(i)));\n"
  4449. "\t}\n"
  4450. "\telse\n"
  4451. "\t{\n");
  4452. }
  4453. for (pi=getParams();pi!=NULL;pi=pi->next)
  4454. {
  4455. pi->write_esp_unmarshall("rpc_request", true, (espm_type_==espm_response)?2:1);
  4456. }
  4457. if (getMetaInt("element"))
  4458. {
  4459. outs(1, "hasValue |= rpc_request.get_value(basepath, m_tag_value);\n");
  4460. }
  4461. if (espm_type_==espm_response)
  4462. outs("\t}\n");
  4463. outs("\treturn hasValue;\n");
  4464. outs("}\n");
  4465. //=============================================================================================================
  4466. //method: unserialize(CSoapValue...)
  4467. if (parent)
  4468. {
  4469. outf("\nbool C%s::unserialize(IEspContext* ctx, CSoapValue& soapval, bool localOnly)\n{\n", name_);
  4470. outf("\tbool hasValue = false;\n");
  4471. outf("\tif(!localOnly)\n");
  4472. outf("\t\thasValue |= C%s::unserialize(ctx,soapval);\n", parent);
  4473. }
  4474. else
  4475. {
  4476. outf("\nbool C%s::unserialize(IEspContext* ctx, CSoapValue& soapval)\n{\n", name_);
  4477. outf("\tbool hasValue = false;\n");
  4478. }
  4479. for (pi=getParams();pi!=NULL;pi=pi->next)
  4480. {
  4481. pi->write_esp_unmarshall_soapval("soapval");
  4482. }
  4483. if (getMetaInt("element"))
  4484. outs(1, "hasValue |= soapval.get_value(\"\",m_tag_value);\n");
  4485. outs("\treturn hasValue;\n");
  4486. outs("}\n");
  4487. //=============================================================================================================
  4488. //method: unserialize(IProperties...)
  4489. if (parent)
  4490. {
  4491. outf("\nbool C%s::unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath, bool localOnly)\n{\n", name_);
  4492. outf("\tbool hasValue = false;\n");
  4493. outf("\tif(!localOnly)\n");
  4494. outf("\t\thasValue |= C%s::unserialize(ctx,params,attachments, basepath);\n", parent);
  4495. }
  4496. else
  4497. {
  4498. outf("\nbool C%s::unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath)\n{\n", name_);
  4499. outf("\tbool hasValue = false;\n");
  4500. }
  4501. for (pi=getParams();pi!=NULL;pi=pi->next)
  4502. {
  4503. if (pi->typname && !strcmp(pi->typname, "EspTextFile"))
  4504. {
  4505. pi->write_esp_unmarshall_attachments("params", "attachments");
  4506. indent(1);
  4507. outf("hasValue |= m_%s_name.unmarshall(ctx, params, attachments, \"%s\", basepath%s);\n", pi->name, pi->name, pi->getOptionalParam());
  4508. }
  4509. else
  4510. pi->write_esp_unmarshall_properties("params", "attachments");;
  4511. }
  4512. if (getMetaInt("element"))
  4513. {
  4514. outs(1, "const char* val = params.queryProp(basepath);\n");
  4515. outs(1, "if (val && *val) {\n");
  4516. outs(2, "m_tag_value.set(val);\n");
  4517. outs(2, "hasValue = true;\n");
  4518. outs(1, "}\n");
  4519. }
  4520. outs("\treturn hasValue;\n");
  4521. outs("}\n");
  4522. //outf("\n\tvoid C%s::unserialize(const char * msg)\n\t{\n", name_);
  4523. //for (pi=getParams();pi!=NULL;pi=pi->next)
  4524. //{
  4525. // pi->write_esp_unmarshall("msg");
  4526. //}
  4527. //outs("\t}\n\n");
  4528. outs("\n");
  4529. write_esp_methods();
  4530. //outs("};\n\n");
  4531. write_factory_impl();
  4532. }
  4533. void EspMessageInfo::write_clarion_methods(enum espaxm_type axstype)
  4534. {
  4535. ParamInfo *pi;
  4536. if (axstype!=espaxm_setters)
  4537. {
  4538. if (espm_type_==espm_response)
  4539. outs("queryClientStatus PROCEDURE(),LONG,PROC\n");
  4540. for (pi=getParams();pi!=NULL;pi=pi->next)
  4541. {
  4542. pi->write_clarion_attr_method(false);
  4543. }
  4544. }
  4545. if (axstype!=espaxm_getters)
  4546. {
  4547. for (pi=getParams();pi!=NULL;pi=pi->next)
  4548. {
  4549. pi->write_clarion_attr_method(true);
  4550. }
  4551. }
  4552. }
  4553. void EspMessageInfo::write_esp_mapinfo(bool isDecl)
  4554. {
  4555. #ifdef MAP_INFO
  4556. outs("\nstatic IEspMapInfo& getMapInfo();");
  4557. #endif
  4558. }
  4559. char* makeXsdType(const char* s)
  4560. {
  4561. if (!s)
  4562. return NULL;
  4563. if (*s == '"')
  4564. s++;
  4565. if (strncmp(s,"tns:",4)==0)
  4566. {
  4567. s+=4;
  4568. size_t len = strlen(s);
  4569. if (*(s+len-1)=='"')
  4570. len--;
  4571. char* t = (char*)malloc(len+1);
  4572. memcpy(t,s,len);
  4573. t[len] = 0;
  4574. return t;
  4575. }
  4576. else
  4577. return NULL;
  4578. }
  4579. void EspMessageInfo::write_esp_methods(enum espaxm_type axstype, bool isDecl, bool isPure)
  4580. {
  4581. ParamInfo *pi;
  4582. if (axstype!=espaxm_setters)
  4583. {
  4584. for (pi=getParams();pi!=NULL;pi=pi->next)
  4585. {
  4586. char* xsd = makeXsdType(pi->getMetaString("format_as",NULL));
  4587. pi->write_esp_attr_method(name_, false, getMetaInt("nil_remove")!=0, isDecl, isPure, getMetaInt("trim")!=0,xsd);
  4588. if (xsd)
  4589. free(xsd);
  4590. }
  4591. }
  4592. if (axstype!=espaxm_getters)
  4593. {
  4594. for (pi=getParams();pi!=NULL;pi=pi->next)
  4595. {
  4596. char* xsd = makeXsdType(pi->getMetaString("format_as",NULL));
  4597. pi->write_esp_attr_method(name_, true, getMetaInt("nil_remove")!=0, isDecl, isPure, getMetaInt("trim")!=0,xsd);
  4598. if (xsd)
  4599. free(xsd);
  4600. }
  4601. }
  4602. }
  4603. void EspMessageInfo::write_esp_parms(bool isClientImpl)
  4604. {
  4605. ParamInfo *pi=getParams();
  4606. if (pi)
  4607. {
  4608. if (isClientImpl)
  4609. pi->write_esp_client_impl();
  4610. else
  4611. pi->write_esp_param();
  4612. for (pi=pi->next;pi!=NULL;pi=pi->next)
  4613. {
  4614. if (isClientImpl)
  4615. pi->write_esp_client_impl();
  4616. else
  4617. {
  4618. outs(", ");
  4619. pi->write_esp_param();
  4620. }
  4621. }
  4622. }
  4623. }
  4624. void EspMessageInfo::write_esp_client_method(const char *serv, const char *respname, const char *methname, bool isDecl, bool isPure)
  4625. {
  4626. outs("\n");
  4627. if (isDecl)
  4628. outs("\tvirtual ");
  4629. outf("IClient%s *", respname);
  4630. if (!isDecl && !isPure)
  4631. outf("CClient%s::", serv);
  4632. outf("%sFn(", methname);
  4633. write_esp_parms(false);
  4634. outs(")");
  4635. if (isPure)
  4636. outs("=0");
  4637. if (isDecl)
  4638. outs(";\n");
  4639. else
  4640. {
  4641. outs("\n{\n");
  4642. outf("\tOwned<IClient%s> req = create%sRequest();\n", name_, methname);
  4643. write_esp_parms(true);
  4644. outf("\treturn %s(req.get());\n", methname);
  4645. outs("}\n");
  4646. }
  4647. }
  4648. void EspMessageInfo::write_cpp_interfaces()
  4649. {
  4650. if (espm_type_ == espm_enum)
  4651. {
  4652. // C enum type
  4653. outf("enum C%s { %s_Undefined=-1,", name_, name_);
  4654. const char* base = getParentName();
  4655. bool isIntBase = strieq(base,"int") || strieq(base,"long") || strieq(base,"uint") || strieq(base,"short");
  4656. for (ParamInfo* pi=getParams();pi!=NULL;pi=pi->next)
  4657. {
  4658. outf("C%s_%s", name_, pi->name);
  4659. if (isIntBase) {
  4660. int v = pi->getMetaInt("enum",-1);
  4661. if (v==-1)
  4662. outf("*** invalid value of Enum type");
  4663. outf("=%d",v);
  4664. }
  4665. outs(", ");
  4666. }
  4667. outs("};\n");
  4668. // array of values
  4669. outf("typedef ArrayOf<C%s> %sArray;\n", name_, name_);
  4670. return;
  4671. }
  4672. outf("interface IConst%s : extends ", name_);
  4673. switch (espm_type_)
  4674. {
  4675. case espm_request:
  4676. outs("IEspRequest\n{\n");
  4677. break;
  4678. case espm_response:
  4679. outs("IEspResponse\n{\n");
  4680. break;
  4681. case espm_struct:
  4682. outs("IEspStruct\n{\n");
  4683. break;
  4684. case espm_enum:
  4685. case espm_none:
  4686. assert(!"Code shouldn't be reached");
  4687. break;
  4688. }
  4689. write_esp_methods(espaxm_getters, true, true);
  4690. if (getMetaInt("element")!=0)
  4691. outs(1, "virtual const char * get_tag_value()=0;\n");
  4692. outs("};\n\n");
  4693. outf("interface IEsp%s : extends IConst%s\n{\n", name_, name_);
  4694. write_esp_methods(espaxm_setters, true, true);
  4695. outf("\tvirtual void copy(IConst%s &from)=0;\n", name_);
  4696. if (getMetaInt("element"))
  4697. outs(1, "virtual void set_tag_value(const char *value)=0;\n");
  4698. outs("};\n\n");
  4699. outf("interface IClient%s : extends IInterface\n", name_);
  4700. outs("{\n");
  4701. switch (espm_type_)
  4702. {
  4703. case espm_request:
  4704. outs("\n\tvirtual IEspClientRpcSettings &rpc() = 0;\n\n");
  4705. write_esp_methods(espaxm_setters, true, true);
  4706. write_esp_mapinfo(true);
  4707. break;
  4708. case espm_response:
  4709. outs("\n\tvirtual int queryClientStatus()=0;\n");
  4710. write_esp_methods(espaxm_getters, true, true);
  4711. if (getMetaInt("exceptions_inline")!=0)
  4712. outs("\n\tvirtual const IMultiException& getExceptions()=0;\n");
  4713. write_esp_mapinfo(true);
  4714. break;
  4715. case espm_struct:
  4716. write_esp_methods(espaxm_setters, true, true);
  4717. write_esp_methods(espaxm_getters, true, true);
  4718. break;
  4719. case espm_enum:
  4720. case espm_none:
  4721. assert(!"Code shouldn't be reached");
  4722. break;
  4723. }
  4724. outs("};\n\n");
  4725. }
  4726. void EspMessageInfo::write_factory_decl()
  4727. {
  4728. switch (espm_type_)
  4729. {
  4730. case espm_struct:
  4731. outf("extern \"C\" %s IEsp%s *create%s(const char *serv=NULL, const char *msgname=NULL);\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_);
  4732. outf("extern \"C\" %s IClient%s *createClient%s(const char *serv=NULL, const char *msgname=NULL);\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_);
  4733. break;
  4734. case espm_request:
  4735. case espm_response:
  4736. outf("extern \"C\" %s IEsp%s *create%s(const char *serv=NULL);\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_);
  4737. outf("extern \"C\" %s IClient%s *createClient%s(const char *serv=NULL);\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_);
  4738. break;
  4739. case espm_enum:
  4740. // no factory for enum
  4741. return;
  4742. default:
  4743. assert(!"Unhandled espm type");
  4744. }
  4745. }
  4746. void EspMessageInfo::write_factory_impl()
  4747. {
  4748. switch (espm_type_)
  4749. {
  4750. case espm_struct:
  4751. outf("extern \"C\" %s IEsp%s *create%s(const char *serv, const char *msgname){return ((IEsp%s *)new C%s(serv /*, msgname*/));}\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_, name_, name_);
  4752. outf("extern \"C\" %s IClient%s *createClient%s(const char *serv, const char *msgname){return ((IClient%s *)new C%s(serv /*, msgname*/));}\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_, name_, name_);
  4753. break;
  4754. case espm_request:
  4755. case espm_response:
  4756. outf("extern \"C\" %s IEsp%s *create%s(const char *serv){return ((IEsp%s *)new C%s(serv));}\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_, name_, name_);
  4757. outf("extern \"C\" %s IClient%s *createClient%s(const char *serv){return ((IClient%s *)new C%s(serv));}\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_, name_, name_);
  4758. break;
  4759. case espm_enum:
  4760. break;
  4761. default:
  4762. assert(!"Unhandled espm type");
  4763. }
  4764. }
  4765. void EspMessageInfo::write_clarion_include_interface()
  4766. {
  4767. static char ifname[256];
  4768. strcpy(ifname, "cppClient");
  4769. strcat(ifname, name_);
  4770. outf("%s INTERFACE(cppInterface),COM\n", ifname);
  4771. if (espm_type_==espm_struct)
  4772. {
  4773. write_clarion_methods(espaxm_setters);
  4774. write_clarion_methods(espaxm_getters);
  4775. }
  4776. else if (espm_type_==espm_request)
  4777. write_clarion_methods(espaxm_setters);
  4778. else
  4779. write_clarion_methods(espaxm_getters);
  4780. outs(" END\n\n");
  4781. }
  4782. EspMessageInfo *EspMethodInfo::getRequestInfo()
  4783. {
  4784. EspMessageInfo *msg = hcp->msgs;
  4785. for(;msg!=NULL; msg=msg->next)
  4786. {
  4787. if (!strcmp(msg->getName(), request_))
  4788. return msg;
  4789. }
  4790. return NULL;
  4791. }
  4792. bool EspMethodInfo::write_mapinfo_check(const char* ctxvar)
  4793. {
  4794. StrBuffer minVer, maxVer;
  4795. bool hasMin = getMetaVerInfo("min_ver", minVer);
  4796. bool hasMax = getMetaVerInfo("max_ver", maxVer);
  4797. bool hasOutput = false;
  4798. if (hasMin || hasMax)
  4799. {
  4800. hasOutput = true;
  4801. indentOuts("if (");
  4802. if (hasMin && hasMax)
  4803. outf("(%s.getClientVersion()>=%s && %s.getClientVersion()<=%s)", ctxvar, minVer.str(), ctxvar, maxVer.str());
  4804. else if (hasMin)
  4805. outf("%s.getClientVersion()>=%s", ctxvar,minVer.str());
  4806. else
  4807. outf("%s.getClientVersion()<=%s", ctxvar,maxVer.str());
  4808. }
  4809. const char* optional = getMetaString("optional", NULL);
  4810. if (optional)
  4811. {
  4812. if (hasOutput)
  4813. outs(" && ");
  4814. else
  4815. {
  4816. indentOuts("if (");
  4817. hasOutput = true;
  4818. }
  4819. const char* quote = (*optional == '"') ? "":"\"";
  4820. outf("%s.checkOptional(%s%s%s)", ctxvar, quote,optional,quote);
  4821. }
  4822. if (hasOutput)
  4823. {
  4824. outs(") {\n");
  4825. indentInc(1);
  4826. }
  4827. return hasOutput;
  4828. }
  4829. void EspMethodInfo::write_esp_method(const char *serv, bool isDecl, bool isPure)
  4830. {
  4831. EspMessageInfo *req = getRequestInfo();
  4832. if (req)
  4833. {
  4834. req->write_esp_client_method(serv, getResp(), name_, isDecl, isPure);
  4835. }
  4836. }
  4837. void EspServInfo::write_factory_impl()
  4838. {
  4839. outs("extern \"C\"");
  4840. if (esp_def_export_tag)
  4841. outf(" %s", esp_def_export_tag);
  4842. outf(" IClient%s * create%sClient() { return new CClient%s(); }\n", name_, name_, name_);
  4843. }
  4844. const char * translateAuthLevel(const char * level)
  4845. {
  4846. /*
  4847. * This method might belong in seclib where the enumeration is defined (selib.h)
  4848. * enum SecAccessFlags
  4849. * {
  4850. * SecAccess_Unknown = -255,
  4851. * SecAccess_None = 0,
  4852. * SecAccess_Access = 1,
  4853. * SecAccess_Read = 3,
  4854. * SecAccess_Write = 7,
  4855. * SecAccess_Full = 255
  4856. * };
  4857. */
  4858. if (!level || !*level)
  4859. {
  4860. outs(2, "\n//FEATURE LEVEL NOT SET, DEFAULTING TO 'READ'\n");
  4861. return "SecAccess_Read";
  4862. }
  4863. if (strieq(level, "NONE"))
  4864. {
  4865. outs(2, "\n//WARNING: FEATURE LEVEL AUTHORIZATION HAS BEEN TURNED OFF!!\n");
  4866. return "SecAccess_None";
  4867. }
  4868. if (strieq(level, "DEFERRED"))
  4869. {
  4870. outs(2, "\n//WARNING: AUTOMATIC FEATURE LEVEL AUTHORIZATION LOGIC HAS BEEN DEFERED TO IN METHOD(DEVELOPER'S RESPONSIBILITY)!!\n");
  4871. return "SecAccess_None";
  4872. }
  4873. if (strieq(level, "FULL"))
  4874. return "SecAccess_Full";
  4875. else if (strieq(level, "WRITE"))
  4876. return "SecAccess_Write";
  4877. else if (strieq(level, "READ"))
  4878. return "SecAccess_Read";
  4879. else if (strieq(level, "ACCESS"))
  4880. return "SecAccess_Access";
  4881. //we might need to throw here...
  4882. outf(2, "\n//FEATURE LEVEL VALUE '%s' INVALID: DEFAULTING REQUIRED LEVEL to 'FULL'!\n//Valid values are NONE, DEFERRED, ACCESS, READ, WRITE, FULL\n", level);
  4883. return "SecAccess_Full";
  4884. }
  4885. void writeAccessMap(const char * rawServiceAccessList, const char * methodname, int tabs)
  4886. {
  4887. StrBuffer indent;
  4888. for (int tabindex = 0; tabindex < tabs; tabindex++)
  4889. indent.append('\t');
  4890. outf("%sMapStringTo<SecAccessFlags> accessmap;\n", indent.str());
  4891. if (rawServiceAccessList && *rawServiceAccessList)
  4892. {
  4893. int listlen = strlen(rawServiceAccessList);
  4894. StrBuffer currAccessName;
  4895. StrBuffer currAccessLevel;
  4896. bool nameComplete = false;
  4897. for (int i = 0; i <= listlen; i++ )
  4898. {
  4899. if (i == listlen || rawServiceAccessList[i] == ',')
  4900. {
  4901. if (nameComplete == false)
  4902. {
  4903. if (strieq(currAccessName, "NONE") || strieq(currAccessName, "DEFERRED"))
  4904. {
  4905. outf("\n//WARNING: Developer has suppressed automatic feature level authorization, ensure this behavior is correct!\n");
  4906. currAccessName.clear();
  4907. continue;
  4908. }
  4909. else
  4910. outf("\nError: Access level must be declared in service definition: %s. Example: ESPservice [%s(\"myAccessFeature:FULL\"]\n", currAccessName.str(), FEATEACCESSATTRIBUTE);
  4911. }
  4912. outf("%saccessmap.setValue(\"%s\", %s);\n", indent.str(), currAccessName.str(), translateAuthLevel(currAccessLevel.str()));
  4913. currAccessName.clear();
  4914. currAccessLevel.clear();
  4915. nameComplete = false;
  4916. continue;
  4917. }
  4918. else if (rawServiceAccessList[i] == ':')
  4919. {
  4920. if (currAccessName.length()==0)
  4921. {
  4922. currAccessName.setf("%sAccess", methodname);
  4923. outf("\n//processaccesslist: defaulted current name to : %s\n", currAccessName.str());
  4924. }
  4925. nameComplete = true;
  4926. continue;
  4927. }
  4928. else if (rawServiceAccessList[i] == '"')
  4929. continue;
  4930. if (!nameComplete)
  4931. currAccessName.append(rawServiceAccessList[i]);
  4932. else
  4933. currAccessLevel.append(rawServiceAccessList[i]);
  4934. }
  4935. }
  4936. else
  4937. {
  4938. outf("\n%saccessmap.setValue(\"%sAccess\", %s);\n", indent.str(), methodname, "SecAccess_Read"); //This seems to be the default per seclib
  4939. }
  4940. }
  4941. void EspServInfo::write_esp_binding_ipp()
  4942. {
  4943. EspMethodInfo *mthi=NULL;
  4944. int useMethodName = getMetaInt("use_method_name", 0);
  4945. outf("\n\nclass C%sSoapBinding : public CHttpSoapBinding\n", name_);
  4946. outs("{\npublic:\n");
  4947. //dom
  4948. outf("\tC%sSoapBinding(http_soap_log_level level=hsl_none);\n", name_);
  4949. outf("\tC%sSoapBinding(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL, http_soap_log_level level=hsl_none);\n", name_);
  4950. outs("\tvirtual void init_strings();\n");
  4951. outs("\tvirtual unsigned getCacheMethodCount(){return m_cacheMethodCount;}\n");
  4952. //method ==> processRequest
  4953. outs("\tvirtual int processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response);\n");
  4954. //method ==> getXsdDefinition
  4955. outs("\tint getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &content, const char *service, const char *method, bool mda);\n");
  4956. //method ==> getMethodHtmlForm
  4957. outs("\tvirtual int getMethodHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &page, bool bIncludeFormTag);\n");
  4958. //method ==> getQualifiedNames
  4959. outs("\tint getQualifiedNames(IEspContext& ctx, MethodInfoArray & methods);\n");
  4960. //method ==> getServiceName
  4961. outs("\tStringBuffer & getServiceName(StringBuffer &resp);\n");
  4962. //method ==> isValidServiceName
  4963. outs("\tbool isValidServiceName(IEspContext &context, const char *name);\n");
  4964. //method ==> qualifyMethodName
  4965. outs("\tbool qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName);\n");
  4966. //method ==> qualifyServiceName
  4967. outs("\tbool qualifyServiceName(IEspContext &context, const char *servname, const char *methname, StringBuffer &servQName, StringBuffer *methQName);\n");
  4968. //method ==> onGetFile
  4969. outs("\tvirtual int onGetFile(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *pathex);\n");
  4970. //Method ==> onGetForm
  4971. outs("\tvirtual int onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);\n");
  4972. //Method ==> onGetXForm
  4973. //if (getMetaInt("use_new_form",0))
  4974. outs("\tvirtual int onGetXForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);\n");
  4975. //Method ==> supportGeneratedForms
  4976. if (getMetaInt("noforms", 0))
  4977. outs("\tvirtual bool supportGeneratedForms(){return false;}\n");
  4978. if (getMetaInt("no_ws_index", 0))
  4979. {
  4980. //Method ==> onGetIndex
  4981. outs("\tvirtual int onGetIndex(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service)\n");
  4982. outs("\t{\n");
  4983. outs("\t\treturn onGetNotFound(context, request, response, service);\n");
  4984. outs("\t}\n");
  4985. }
  4986. //Method ==> onGetService
  4987. outs("\tvirtual int onGetService(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method, const char *pathex);\n");
  4988. //Method ==> createReqBinding
  4989. outs(1, "virtual IRpcRequestBinding *createReqBinding(IEspContext &context, IHttpMessage* request, const char *service, const char *method);\n");
  4990. //Method ==> onGetInstantQuery
  4991. outs("\tvirtual int onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);\n");
  4992. //Method ==> xslTransform
  4993. if (needsXslt)
  4994. {
  4995. outs(1, "void setXslProcessor(IInterface *xslp_)\n");
  4996. outs(1, "{\n");
  4997. outs(2, "IXslProcessor *ixslp = dynamic_cast<IXslProcessor *>(xslp_);\n");
  4998. outs(2, "if (!ixslp)\n");
  4999. outs(3, "xslp.clear();\n"); //set(NULL) would basically be same, but be explicit
  5000. outs(2, "else\n");
  5001. outs(3, "xslp.set(ixslp);\n");
  5002. outs(1, "}\n");
  5003. outs("private:\n");
  5004. outs("\tOwned<IXslProcessor> xslp;\n");
  5005. outs("\tvoid xslTransform(const char* xml, const char* xslFile, StringBuffer& output, IProperties *params)\n"
  5006. "\t{\n"
  5007. "\t\tif (xslp)\n"
  5008. "\t\t{\n"
  5009. "\t\t\tOwned<IXslTransform> xform = xslp->createXslTransform();\n"
  5010. "\t\t\tStringBuffer xslpath;\n"
  5011. "\t\t\tif (!strnicmp(xslFile, \"/esp/xslt/\", 10))\n"
  5012. "\t\t\t\tif (!checkFileExists(xslpath.append(getCFD()).append(\"smc_xslt/\").append(xslFile+10).str()) && !checkFileExists(xslpath.append(getCFD()).append(\"xslt/\").append(xslFile+10).str()))\n"
  5013. "\t\t\t\t\treturn;\n"
  5014. "\t\t\txform->loadXslFromFile((xslpath.length()) ? xslpath.str() : xslFile);\n"
  5015. "\t\t\txform->setXmlSource(xml, strlen(xml)+1);\n"
  5016. "\t\t\tif (params) xform->copyParameters(params);\n"
  5017. "\t\t\txform->transform(output.clear());\n"
  5018. "\t\t}\n"
  5019. "\t}\n");
  5020. }
  5021. else
  5022. outs("\tvoid setXslProcessor(IInterface *xslp){}\n");
  5023. outs("\tunsigned m_cacheMethodCount = 0;\n");
  5024. outs("};\n\n");
  5025. }
  5026. void EspServInfo::write_esp_binding()
  5027. {
  5028. EspMethodInfo *mthi=NULL;
  5029. int useMethodName = getMetaInt("use_method_name", 0);
  5030. StrBuffer wsdlVer;
  5031. bool hasVersion = getMetaVerInfo(tags,"version",wsdlVer);
  5032. if (!hasVersion)
  5033. wsdlVer.append("1");
  5034. //comment
  5035. outs("\n//=======================================================");
  5036. outf("\n// class C%sSoapBinding Implementation", name_);
  5037. outs("\n//=======================================================");
  5038. outs("\n");
  5039. StrBuffer servicefeatureurl;
  5040. getMetaStringValue(servicefeatureurl,FEATEACCESSATTRIBUTE);
  5041. if (servicefeatureurl.length() == 0)
  5042. outf("ESDL Error: %s service definition must declare default feature access. Example 'ESPservice [%s(\"MyServiceAccess:FULL\")]'", name_, FEATEACCESSATTRIBUTE);
  5043. outf("\nC%sSoapBinding::C%sSoapBinding(http_soap_log_level level):CHttpSoapBinding(NULL, NULL, NULL, level)\n{\n\tinit_strings();\n\tsetWsdlVersion(%s);", name_, name_, wsdlVer.str());
  5044. outf("\n}\n");
  5045. outf("\nC%sSoapBinding::C%sSoapBinding(IPropertyTree* cfg, const char *bindname, const char *procname, http_soap_log_level level):CHttpSoapBinding(cfg, bindname, procname, level)\n{\n\tinit_strings(); \n\tsetWsdlVersion(%s);\n", name_, name_, wsdlVer.str());
  5046. outf("\n}\n");
  5047. outf("\nvoid C%sSoapBinding::init_strings()\n", name_);
  5048. outs("{\n");
  5049. bool cacheDefined = false;
  5050. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5051. {
  5052. StrBuffer val;
  5053. mthi->getMetaStringValue(val,"description");
  5054. if (val.length()) {
  5055. StrBuffer tmp;
  5056. outf("\taddMethodDescription(\"%s\", \"%s\");\n", mthi->getName(), printfEncode(val.str(), tmp).str());
  5057. }
  5058. mthi->getMetaStringValue(val.clear(),"help");
  5059. if (val.length()) {
  5060. StrBuffer tmp;
  5061. outf("\taddMethodHelp(\"%s\", \"%s\");\n", mthi->getName(), printfEncode(val.str(), tmp).str());
  5062. }
  5063. int cacheGlobal = mthi->getMetaInt("cache_global", 0);
  5064. int cacheSeconds = mthi->getMetaInt("cache_seconds", -1);
  5065. if (cacheSeconds > -1) {
  5066. cacheDefined = true;
  5067. if (cacheGlobal > 0)
  5068. outf("\tsetCacheTimeout(\"%s\", %d, 1);\n", mthi->getName(), cacheSeconds);
  5069. else
  5070. outf("\tsetCacheTimeout(\"%s\", %d, 0);\n", mthi->getName(), cacheSeconds);
  5071. outs("\tm_cacheMethodCount++;\n");
  5072. StrBuffer methodCacheGroupID;
  5073. mthi->getMetaStringValue(methodCacheGroupID,"cache_group");
  5074. if (methodCacheGroupID.length() > 0)
  5075. outf("\tsetCacheGroupID(\"%s\", \"%s\");\n", mthi->getName(), methodCacheGroupID.str());
  5076. }
  5077. }
  5078. StrBuffer serviceCacheGroupID;
  5079. if (cacheDefined)
  5080. {
  5081. getMetaStringValue(serviceCacheGroupID,"cache_group");
  5082. if (serviceCacheGroupID.length() == 0)
  5083. serviceCacheGroupID.set(name_);
  5084. outf("\tsetCacheGroupID(nullptr, \"%s\");\n", serviceCacheGroupID.str());
  5085. }
  5086. outs("}\n");
  5087. outf("\nint C%sSoapBinding::processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response)\n", name_);
  5088. outs("{\n");
  5089. outs("\tif(rpc_call == NULL || rpc_response == NULL)\n\t\treturn -1;\n\n");
  5090. outs(1, "IEspContext *ctx=rpc_call->queryContext();\n");
  5091. outs(1, "DBGLOG(\"Client version: %g\", ctx->getClientVersion());\n");
  5092. outs(1, "StringBuffer serviceName;\n");
  5093. outs(1, "double clientVer=(ctx) ? ctx->getClientVersion() : 0.0;\n");
  5094. outs(1, "qualifyServiceName(*ctx, ctx->queryServiceName(NULL), NULL, serviceName, NULL);\n");
  5095. outs(1, "CRpcCall* thecall = static_cast<CRpcCall *>(rpc_call);\n"); //interface must be from a class derived from CRpcCall
  5096. outs(1, "CRpcResponse* response = static_cast<CRpcResponse*>(rpc_response);\n\n"); //interface must be from a class derived from CRpcResponse
  5097. outf("\tOwned<IEsp%s> iserv = (IEsp%s*)getService();\n", name_, name_);
  5098. outs("\tif(iserv == NULL)\n");
  5099. outs("\t{\n");
  5100. outs("\t\tresponse->set_status(SOAP_SERVER_ERROR);\n");
  5101. outs("\t\tresponse->set_err(\"Service not available\");\n");
  5102. outs("\t\tDBGLOG(\"Service not available\");\n");
  5103. outs("\t\treturn -1;\n\t}\n");
  5104. outs("\tif (thecall->get_name() == NULL)\n");
  5105. outs("\t{\n");
  5106. outs("\t\tresponse->set_status(SOAP_CLIENT_ERROR);\n");
  5107. outs("\t\tresponse->set_err(\"No service method specified\");\n");
  5108. outs("\t\tERRLOG(\"No service method specified\");\n");
  5109. outs("\t\treturn -1;\n");
  5110. outs("\t}\n");
  5111. outs("\n\tIEspContext& context = *rpc_call->queryContext();\n\n");
  5112. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5113. {
  5114. outf("\tif(!stricmp(thecall->get_name(), \"%s\")||!stricmp(thecall->get_name(), \"%s\"))\n", mthi->getName(), mthi->getReq());
  5115. outs("\t{\n");
  5116. //esp_request + esp_response can persist longer than the scope of this method
  5117. outf("\t\tOwned<C%s> esp_request = new C%s(serviceName.str(), thecall);\n", mthi->getReq(), mthi->getReq());
  5118. outs("\t\tcheckRequest(context);\n");
  5119. outf("\t\tOwned<C%s> esp_response = new C%s(serviceName.str());\n", mthi->getResp(), mthi->getResp());
  5120. StrBuffer minVer;
  5121. bool hasMinVer = mthi->getMetaVerInfo("min_ver", minVer);
  5122. bool bHandleExceptions = 0 != mthi->getMetaInt("exceptions_inline", 0);
  5123. if (!bHandleExceptions)
  5124. bHandleExceptions = 0 != getMetaInt("exceptions_inline", 0);
  5125. const char * methodAccess = mthi->getMetaString(FEATEACCESSATTRIBUTE, NULL);
  5126. StrBuffer servicefeatureurl;
  5127. getMetaStringValue(servicefeatureurl,FEATEACCESSATTRIBUTE);
  5128. if (methodAccess && *methodAccess)
  5129. {
  5130. if (servicefeatureurl.length() != 0)
  5131. servicefeatureurl.append(",");
  5132. servicefeatureurl.append(methodAccess);
  5133. }
  5134. writeAccessMap(servicefeatureurl.str(),name_, 2);
  5135. StrBuffer clearCacheGroupIDs;
  5136. if (mthi->hasMetaTag("clear_cache_group"))
  5137. {
  5138. StrBuffer cCGIDs;
  5139. mthi->getMetaStringValue(cCGIDs,"clear_cache_group");
  5140. if (cacheDefined || (cCGIDs.length() != 0))
  5141. clearCacheGroupIDs.set((cCGIDs.length() != 0) ? cCGIDs.str() : serviceCacheGroupID.str());
  5142. }
  5143. //begin try block
  5144. if (bHandleExceptions)
  5145. {
  5146. outs("\t\tStringBuffer source;\n");
  5147. outf("\t\tsource.appendf(\"%s::%%s()\", thecall->get_name());\n", name_);
  5148. outf("\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  5149. outs("\t\ttry\n");
  5150. outs("\t\t{\n");
  5151. if (hasMinVer)
  5152. {
  5153. outf("\t\t\tif (clientVer!=-1.0 && clientVer<%s)\n", minVer.str());
  5154. outs("\t\t\t\tthrow MakeStringException(-1, \"Client version is too old, please update your client application.\");");
  5155. }
  5156. outs("\t\t\tresponse->set_status(SOAP_OK);\n");
  5157. if (servicefeatureurl.length() != 0)
  5158. outf("\t\t\tif( accessmap.ordinality() > 0 )\n\t\t\t\tonFeaturesAuthorize(context, accessmap, \"%s\", \"%s\");\n", name_, mthi->getName());
  5159. outf("\t\t\tiserv->on%s(context, *esp_request, *esp_response);\n", mthi->getName());
  5160. if (clearCacheGroupIDs.length() > 0)
  5161. outf("\t\t\tclearCacheByGroupID(\"%s\");\n", clearCacheGroupIDs.str());
  5162. outs("\t\t}\n");
  5163. write_catch_blocks(mthi, ct_soapresp, 2);
  5164. }
  5165. else
  5166. {
  5167. if (hasMinVer)
  5168. {
  5169. outf("\t\tif (clientVer!=-1.0 && clientVer<%s)\n", minVer.str());
  5170. outs("\t\t\tthrow MakeStringException(-1, \"Client version is too old (can't pass exception to client)\");\n");
  5171. }
  5172. if (mthi->getMetaInt("do_not_log",0))
  5173. outs("\t\tcontext.queryRequestParameters()->setProp(\"do_not_log\",1);\n");
  5174. if (servicefeatureurl.length() != 0)
  5175. outf("\t\tif( accessmap.ordinality() > 0 )\n\t\t\tonFeaturesAuthorize(context, accessmap, \"%s\", \"%s\");\n", name_, mthi->getName());
  5176. outf("\t\tiserv->on%s(*rpc_call->queryContext(), *esp_request, *esp_response);\n", mthi->getName());
  5177. if (clearCacheGroupIDs.length() > 0)
  5178. outf("\t\tclearCacheByGroupID(\"%s\");\n", clearCacheGroupIDs.str());
  5179. outs("\t\tresponse->set_status(SOAP_OK);\n");
  5180. }
  5181. outf("\t\tresponse->set_name(\"%s\");\n", mthi->getResp());
  5182. outs("\t\tesp_response->serialize(*response);\n");
  5183. outs("\t\treturn 0;\n\t}\n\n");
  5184. }
  5185. outs("\tresponse->set_status(SOAP_CLIENT_ERROR);\n");
  5186. outs("\tStringBuffer msg, svcName;\n");
  5187. outs("\tmsg.appendf(\"Method %s not available in service %s\",thecall->get_name(),getServiceName(svcName).str());\n");
  5188. outs("\tERRLOG(\"%s\", msg.str());\n");
  5189. outs("\tresponse->set_err(msg);\n");
  5190. outs("\treturn -1;\n");
  5191. outs("}\n");
  5192. //method ==> getXsdDefinition
  5193. outf("\nint C%sSoapBinding::getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &content, const char *service, const char *method, bool mda)\n", name_);
  5194. outs("{\n");
  5195. outs("\tBoolHash added;\n");
  5196. // version
  5197. if (hasVersion)
  5198. {
  5199. outs("\tif (context.getClientVersion()<=0)\n");
  5200. outf("\t\tcontext.setClientVersion(%s);\n\n", wsdlVer.str());
  5201. }
  5202. outs("\tDBGLOG(\"Client version: %g\", context.getClientVersion());\n");
  5203. indentReset(1);
  5204. outf(1, "bool fullservice = (!Utils::strcasecmp(service, \"%s\"));\n", name_);
  5205. indentOuts("bool allMethods = (method==NULL || *method==0);\n");
  5206. bool needPropsDeclare = true;
  5207. bool needAccessFlagDeclare = true;
  5208. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5209. {
  5210. const char *requestName = (useMethodName) ? mthi->getName() : mthi->getReq();
  5211. const char *optional=mthi->getMetaString("optional", NULL);
  5212. const char *access=mthi->getMetaString("access", NULL);
  5213. if (optional)
  5214. {
  5215. if (needPropsDeclare)
  5216. {
  5217. indentOuts("IProperties *props = request->queryParameters();\n");
  5218. needPropsDeclare = false;
  5219. }
  5220. indentOutf("if (props && props->hasProp(%s)) {\n", optional);
  5221. indentInc(1);
  5222. }
  5223. if (access)
  5224. {
  5225. if (needAccessFlagDeclare)
  5226. {
  5227. indentOuts("SecAccessFlags acc;\n");
  5228. needAccessFlagDeclare = false;
  5229. }
  5230. indentOutf("if (context.authorizeFeature(%s, acc) && acc>=SecAccess_Read) {\n", access);
  5231. indentInc(1);
  5232. }
  5233. indentOutf("if ((allMethods&&(fullservice||isMethodInSubService(context, service, \"%s\"))) || Utils::strcasecmp(method, \"%s\")==0)\n", mthi->getName(), mthi->getName());
  5234. indentOuts("{\n");
  5235. indentInc(1);
  5236. bool hasMap = mthi->write_mapinfo_check("context");
  5237. indentOutf("C%s::getMapInfo(context.queryMapInfo());\n", mthi->getReq());
  5238. indentOutf("C%s::getMapInfo(context.queryMapInfo());\n", mthi->getResp());
  5239. indentOutf("C%s::getXsdDefinition(context, request, \"%s\", content, added);\n", mthi->getReq(), requestName);
  5240. indentOutf("C%s::getXsdDefinition(context, request, content, added);\n", mthi->getResp());
  5241. if (hasMap)
  5242. indentOuts(-1,"}\n");
  5243. indentOuts(-1,"}\n");
  5244. if (access)
  5245. indentOuts(-1,"}\n");
  5246. if (optional)
  5247. indentOuts(-1,"}\n");
  5248. }
  5249. indentOuts("return 0;\n");
  5250. indentOuts(-1,"}\n");
  5251. //method ==> getMethodHtmlForm
  5252. outf("\nint C%sSoapBinding::getMethodHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &page, bool bIncludeFormTag)\n", name_);
  5253. outs("{\n");
  5254. outf("\tDBGLOG(\"Client version: %%g\", context.getClientVersion());\n");
  5255. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5256. {
  5257. outf("\tif (Utils::strcasecmp(method, \"%s\")==0)\n", mthi->getName());
  5258. outs("\t{\n");
  5259. outf("\t\tC%s::getHtmlForm(context, request, serv, method, page);\n", mthi->getReq());
  5260. outs("\t}\n");
  5261. }
  5262. outs("\treturn 0;\n");
  5263. outs("}\n");
  5264. //method ==> getQualifiedNames
  5265. outf("\nint C%sSoapBinding::getQualifiedNames(IEspContext& ctx, MethodInfoArray & methods)\n", name_);
  5266. outs("{\n");
  5267. outs(1, "double ver = ctx.getClientVersion();\n");
  5268. outs(1, "if (ver<=0)\n");
  5269. outs(2, "ver = getWsdlVersion();\n");
  5270. outs(1, "const char *servname=ctx.queryServiceName(NULL);\n");
  5271. outf(1, "bool fullservice = (!stricmp(servname, \"esp\")||!stricmp(servname, \"%s\"));\n", name_);
  5272. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5273. {
  5274. if (!mthi->getMetaInt("noform",0))
  5275. {
  5276. const char *optional=mthi->getMetaString("optional", "NULL");
  5277. const char *access=mthi->getMetaString("access", "NULL");
  5278. const char *method_name = (getMetaInt("use_method_name")!=0) ? mthi->getName() : mthi->getReq();
  5279. StrBuffer minVer, maxVer;
  5280. bool hasMinVer = mthi->getMetaVerInfo("min_ver",minVer);
  5281. bool hasMaxVer = mthi->getMetaVerInfo("max_ver",maxVer);
  5282. outf("\tif ((fullservice || isMethodInSubService(ctx, servname, \"%s\")) && ctx.isMethodAllowed(ver,%s, %s, %s, %s))\n",
  5283. mthi->getName(), optional, access, hasMinVer ? minVer.str() : "-1", hasMaxVer ? maxVer.str() : "-1");
  5284. outf("\t\tmethods.append(*new CMethodInfo(\"%s\", \"%s\", \"%s\"));\n", mthi->getName(), method_name, mthi->getResp());
  5285. }
  5286. }
  5287. outs("\treturn methods.ordinality();\n");
  5288. outs("}\n");
  5289. //method ==> getServiceName
  5290. outf("\nStringBuffer & C%sSoapBinding::getServiceName(StringBuffer &resp)\n", name_);
  5291. outs("{\n");
  5292. outf("\tresp.append(\"%s\");\n", name_);
  5293. outs("\treturn resp;\n");
  5294. outs("}\n");
  5295. //method ==> isValidServiceName
  5296. outf("\nbool C%sSoapBinding::isValidServiceName(IEspContext &context, const char *name)\n", name_);
  5297. outs("{\n");
  5298. outf(1, "if (!Utils::strcasecmp(name, \"%s\"))\n", name_);
  5299. outs(2, "return true;\n");
  5300. outs(1, "else\n");
  5301. outs(2, "return (hasSubService(context, name));\n");
  5302. outs("}\n");
  5303. //method ==> qualifyMethodName
  5304. outf("\nbool C%sSoapBinding::qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName)\n", name_);
  5305. outs("{\n");
  5306. outs("\tif (!methname || !*methname)\n");
  5307. outs("\t{\n");
  5308. outs("\t\tif (methQName!=NULL)\n");
  5309. outs("\t\t\tmethQName->clear();\n");
  5310. outs("\t\treturn true;\n");
  5311. outs("\t}\n");
  5312. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5313. {
  5314. outf("\tif (Utils::strcasecmp(methname, \"%s\")==0)\n", mthi->getName());
  5315. outs("\t{\n");
  5316. outs("\t\tif (methQName!=NULL)\n");
  5317. outf("\t\t\tmethQName->set(\"%s\");\n", mthi->getName());
  5318. outs("\t\treturn true;\n");
  5319. outs("\t}\n");
  5320. }
  5321. outs("\treturn false;\n");
  5322. outs("}\n");
  5323. //method ==> qualifyServiceName
  5324. outf("\nbool C%sSoapBinding::qualifyServiceName(IEspContext &context, const char *servname, const char *methname, StringBuffer &servQName, StringBuffer *methQName)\n", name_);
  5325. outs("{\n");
  5326. outs(1, "servQName.clear();\n");
  5327. outf(1, "if (!Utils::strcasecmp(servname, \"%s\"))\n", name_);
  5328. outs(1, "{\n");
  5329. outf(2, "servQName.append(\"%s\");\n", name_);
  5330. outs(2, "return qualifyMethodName(context, methname, methQName);\n");
  5331. outs(1, "}\n");
  5332. outs(1, "return qualifySubServiceName(context, servname, methname, servQName, methQName);\n");
  5333. outs("}\n");
  5334. //method ==> onGetFile
  5335. outf("\nint C%sSoapBinding::onGetFile(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *pathex)\n", name_);
  5336. outs("{\n");
  5337. outs("\tif(request == NULL || response == NULL)\n");
  5338. outs("\t\treturn -1;\n");
  5339. outs("\tStringBuffer mimetype;\n");
  5340. outs("\tMemoryBuffer content;\n\n");
  5341. outs("\tStringBuffer filepath;\n");
  5342. outs("\tgetBaseFilePath(filepath);\n");
  5343. outs("\tif (strchr(\"\\\\/\", filepath.charAt(filepath.length()-1))==NULL)\n");
  5344. outs("\t\tfilepath.append(\"/\");\n");
  5345. outs("\tfilepath.append(pathex);\n");
  5346. outs("\tresponse->httpContentFromFile(filepath.str());\n");
  5347. outs("\tresponse->send();\n");
  5348. outs("\treturn 0;\n");
  5349. outs("}\n");
  5350. //Method ==> onGetForm
  5351. outf("\nint C%sSoapBinding::onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)\n", name_);
  5352. outs("{\n");
  5353. if (getMetaInt("noforms", 0))
  5354. {
  5355. outs("\treturn onGetNotFound(context, request, response, service);\n");
  5356. }
  5357. else
  5358. {
  5359. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5360. {
  5361. if (mthi->getMetaInt("noform", 0))
  5362. {
  5363. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5364. outs("\t\treturn onGetNotFound(context, request, response, service);\n");
  5365. }
  5366. else
  5367. {
  5368. const char *formHtmlPath = mthi->getMetaString("form_html", NULL);
  5369. if (formHtmlPath)
  5370. {
  5371. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5372. outs("\t{\n");
  5373. outf("\t\tresponse->httpContentFromFile(%s);\n", formHtmlPath);
  5374. outs("\t\tresponse->send();\n");
  5375. outs("\t\treturn 0;\n");
  5376. outs("\t}\n");
  5377. }
  5378. }
  5379. }
  5380. // normal test form
  5381. if (hasVersion)
  5382. {
  5383. outs("\tif (context.getClientVersion()<=0)\n");
  5384. outf("\t\tcontext.setClientVersion(%s);\n\n", wsdlVer.str());
  5385. }
  5386. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5387. {
  5388. outf("\tif (!stricmp(\"%s\", method)) {\n", mthi->getName());
  5389. if (mthi->getMetaInt("use_new_form",0))
  5390. outs("\t\treturn EspHttpBinding::onGetXForm(context, request, response, service, method);\n");
  5391. else {
  5392. outf("\t\tC%s::getMapInfo(context.queryMapInfo());\n", mthi->getReq());
  5393. outf("\t\tC%s::getMapInfo(context.queryMapInfo());\n", mthi->getResp());
  5394. }
  5395. outs("\t}\n");
  5396. }
  5397. outs("\n\treturn EspHttpBinding::onGetForm(context, request, response, service, method);\n");
  5398. }
  5399. outs("}\n");
  5400. // method ==> onGetXForm
  5401. outf("int C%sSoapBinding::onGetXForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)\n", name_);
  5402. outs("{\n");
  5403. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5404. {
  5405. if (mthi->getMetaInt("use_new_form",0))
  5406. {
  5407. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5408. outs("\t\treturn EspHttpBinding::onGetForm(context, request, response, service, method);\n");
  5409. }
  5410. }
  5411. outs("\treturn EspHttpBinding::onGetXForm(context, request, response, service, method);\n");
  5412. outs("}\n");
  5413. if (getMetaInt("no_ws_index", 0))
  5414. {
  5415. //Method ==> onGetIndex
  5416. outf("\nint C%sSoapBinding::onGetIndex(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service)\n", name_);
  5417. outs("{\n");
  5418. outs("\treturn onGetNotFound(context, request, response, service);\n");
  5419. outs("}\n");
  5420. }
  5421. //Method ==> onGetService
  5422. outf("\nint C%sSoapBinding::onGetService(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method, const char *pathex)\n", name_);
  5423. outs("{\n");
  5424. outs("\tif(request == NULL || response == NULL)\n");
  5425. outs("\t\treturn -1;\n");
  5426. EspMountInfo *mnt;
  5427. for (mnt=mounts;mnt!=NULL;mnt=mnt->next)
  5428. {
  5429. outs("\t");
  5430. if (mnt!=mounts)
  5431. outs("else ");
  5432. outf("if(!stricmp(method, \"%s\"))\n", mnt->getName());
  5433. outs("\t{\n");
  5434. outs("\t\tMemoryBuffer content;\n");
  5435. outs("\t\tStringBuffer mimetype;\n");
  5436. outf("\t\tStringBuffer filepath(%s);\n\n", mnt->getLocalPath());
  5437. outs("\t\tif (filepath.length()>0 && strchr(\"/\\\\\", filepath.charAt(filepath.length()-1))==NULL)\n");
  5438. outs("\t\t{\n");
  5439. outs("\t\t\tfilepath.append(\"/\");\n");
  5440. outs("\t\t}\n");
  5441. outs("\t\tfilepath.append((pathex!=NULL && *pathex!=0) ? pathex : \"index.html\");\n\n");
  5442. outs("\t\tif (!response->httpContentFromFile(filepath.str()))\n");
  5443. outs("\t\t{\n");
  5444. outs("\t\t\treturn onGetQuery(context, request, response, service, method);\n");
  5445. outs("\t\t}\n");
  5446. outs("\t\tresponse->send();\n");
  5447. outs("\t\treturn 0;\n");
  5448. outs("\t}\n");
  5449. }
  5450. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5451. {
  5452. int formIsDefault = mthi->getMetaInt("form_is_default");
  5453. if (formIsDefault)
  5454. {
  5455. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5456. outs("\t{\n");
  5457. outs("\treturn onGetForm(context, request, response, service, method);\n");
  5458. outs("\t}\n");
  5459. }
  5460. }
  5461. outs("\treturn onGetQuery(context, request, response, service, method);\n");
  5462. outs("}\n");
  5463. outf("\n IRpcRequestBinding *C%sSoapBinding::createReqBinding(IEspContext &context, IHttpMessage *ireq, const char *service, const char *method)\n", name_);
  5464. outs("{\n");
  5465. outs(1, "CHttpRequest *request=static_cast<CHttpRequest*>(ireq);\n");
  5466. outs(1, "IProperties *props = (request) ? request->queryParameters() : NULL;\n\n");
  5467. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5468. {
  5469. outf(1, "if (!stricmp(method, \"%s\") || !stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5470. outf(2, "return new C%s(&context, \"%s\", props, NULL);\n", mthi->getReq(), name_);
  5471. }
  5472. outs(1, "return NULL;\n");
  5473. outs("}\n");
  5474. //Method ==> onGetInstantQuery
  5475. outf("\nint C%sSoapBinding::onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)\n", name_);
  5476. outs("{\n");
  5477. StrBuffer defVer;
  5478. bool hasDefVer = getMetaVerInfo(tags,"default_client_version",defVer);
  5479. if (!hasDefVer)
  5480. hasDefVer = getMetaVerInfo(tags,"version",defVer);
  5481. if (hasDefVer)
  5482. {
  5483. outf("\tif (context.getClientVersion()<=0)\n");
  5484. outf("\t\tcontext.setClientVersion(%s);\n\n", defVer.str());
  5485. }
  5486. outs("\tif(request == NULL || response == NULL)\n");
  5487. outs("\t\treturn -1;\n");
  5488. outs("\tStringBuffer respStr;\n");
  5489. outf("\tOwned<IEsp%s> iserv = (IEsp%s*)getService();\n", name_, name_);
  5490. outs("\tif(iserv == NULL)\n");
  5491. outs("\t{\n");
  5492. outs("\t\trespStr.append(\"Service not available\");\n");
  5493. outs("\t\tresponse->setContent(respStr.str());\n");
  5494. outs("\t\tresponse->setContentType(\"text/html\");\n");
  5495. outs("\t\tresponse->send();\n");
  5496. outs("\t}\n");
  5497. outs("\telse\n");
  5498. outs("\t{\n");
  5499. outf("\t\tOwned<CSoapResponseBinding> esp_response;\n");
  5500. outf("\t\tStringBuffer source;\n");
  5501. outf("\t\tIEspContext& context = *request->queryContext();\n");
  5502. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5503. {
  5504. bool bClientXslt=false;
  5505. const char *respXsl = mthi->getMetaString("resp_xsl_default", NULL);
  5506. const char *respContentType = mthi->getMetaString("http_content_type", "\"text/html\"");
  5507. if (!respXsl)
  5508. {
  5509. respXsl = mthi->getMetaString("client_xslt", NULL);
  5510. bClientXslt=(respXsl!=NULL);
  5511. }
  5512. StrBuffer clearCacheGroupIDs;
  5513. if (mthi->hasMetaTag("clear_cache_group"))
  5514. {
  5515. StrBuffer cCGIDs;
  5516. mthi->getMetaStringValue(cCGIDs,"clear_cache_group");
  5517. if (cacheDefined || (cCGIDs.length() != 0))
  5518. clearCacheGroupIDs.set((cCGIDs.length() != 0) ? cCGIDs.str() : serviceCacheGroupID.str());
  5519. }
  5520. bool bHandleExceptions = 0 != mthi->getMetaInt("exceptions_inline", 0) || mthi->getMetaInt("http_exceptions_inline", 0);
  5521. if (!bHandleExceptions)
  5522. bHandleExceptions = 0 != getMetaInt("exceptions_inline", 0) || getMetaInt("http_exceptions_inline", 0);
  5523. if (respXsl==NULL)
  5524. {
  5525. outf("\t\tif(!stricmp(method, \"%s\")||!stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5526. outs("\t\t{\n");
  5527. outf("\t\t\tOwned<C%s> esp_request = new C%s(&context, \"%s\", request->queryParameters(), request->queryAttachments());\n", mthi->getReq(), mthi->getReq(), name_);
  5528. outf("\t\t\tcheckRequest(context);\n");
  5529. outf("\t\t\tC%s* resp = new C%s(\"%s\");\n", mthi->getResp(), mthi->getResp(), name_);
  5530. outf("\t\t\tesp_response.setown(resp);\n");
  5531. const char * methodAccess = mthi->getMetaString(FEATEACCESSATTRIBUTE, NULL);
  5532. StrBuffer servicefeatureurl;
  5533. getMetaStringValue(servicefeatureurl,FEATEACCESSATTRIBUTE);
  5534. if (methodAccess && *methodAccess)
  5535. {
  5536. if (servicefeatureurl.length() != 0)
  5537. servicefeatureurl.append(",");
  5538. servicefeatureurl.append(methodAccess);
  5539. }
  5540. writeAccessMap(servicefeatureurl.str(),name_, 3);
  5541. if (bHandleExceptions)
  5542. {
  5543. outf("\t\t\tsource.setf(\"%s::%%s()\", method);\n", name_);
  5544. outf("\t\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  5545. //begin try block
  5546. outs("\t\t\ttry\n");
  5547. outs("\t\t\t{\n");
  5548. if (servicefeatureurl.length() != 0)
  5549. outf("\t\t\t\tif(accessmap.ordinality()>0)\n\t\t\t\t\tonFeaturesAuthorize(context, accessmap, \"%s\", \"%s\");\n", name_, mthi->getName());
  5550. if (mthi->getMetaInt("do_not_log",0))
  5551. outf("\t\t\t\tcontext.queryRequestParameters()->setProp(\"do_not_log\",1);\n");
  5552. outf("\t\t\t\tiserv->on%s(context, *esp_request.get(), *resp);\n", mthi->getName());
  5553. if (clearCacheGroupIDs.length() > 0)
  5554. outf("\t\t\t\tclearCacheByGroupID(\"%s\");\n", clearCacheGroupIDs.str());
  5555. outs("\t\t\t}\n");
  5556. write_catch_blocks(mthi, ct_httpresp, 3);
  5557. }
  5558. else
  5559. {
  5560. if (servicefeatureurl.length() != 0)
  5561. outf("\t\t\tif(accessmap.ordinality()>0)\n\t\t\t\tonFeaturesAuthorize(context, accessmap, \"%s\", \"%s\");\n", name_, mthi->getName());
  5562. outf("\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *resp);\n", mthi->getName());
  5563. if (clearCacheGroupIDs.length() > 0)
  5564. outf("\t\t\tclearCacheByGroupID(\"%s\");\n", clearCacheGroupIDs.str());
  5565. }
  5566. outs("\t\t}\n");
  5567. }
  5568. else
  5569. {
  5570. outf("\t\tif(!stricmp(method, \"%s\")||!stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5571. outs("\t\t{\n");
  5572. outf("\t\t\tOwned<C%s> esp_request = new C%s(&context, \"%s\", request->queryParameters(), request->queryAttachments());\n", mthi->getReq(), mthi->getReq(), name_);
  5573. outf("\t\t\tcheckRequest(context);\n");
  5574. outf("\t\t\tOwned<C%s> esp_response = new C%s(\"%s\");\n", mthi->getResp(), mthi->getResp(), name_);
  5575. if (bHandleExceptions)
  5576. {
  5577. outs("\t\t\tStringBuffer source;\n");
  5578. outf("\t\t\tsource.appendf(\"%s::%%s()\", method);\n", name_);
  5579. outf("\t\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  5580. //begin try block
  5581. outs("\t\t\ttry\n");
  5582. outs("\t\t\t{\n");
  5583. outf("\t\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *esp_response.get());\n", mthi->getName());
  5584. if (clearCacheGroupIDs.length() > 0)
  5585. outf("\t\t\t\tclearCacheByGroupID(\"%s\");\n", clearCacheGroupIDs.str());
  5586. outs("\t\t\t}\n");
  5587. write_catch_blocks(mthi, ct_httpresp,3);
  5588. }
  5589. else
  5590. {
  5591. outf("\t\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *esp_response.get());\n", mthi->getName());
  5592. if (clearCacheGroupIDs.length() > 0)
  5593. outf("\t\t\tclearCacheByGroupID(\"%s\");\n", clearCacheGroupIDs.str());
  5594. }
  5595. outs("\t\t\tif (canRedirect(*request) && esp_response->getRedirectUrl() && *esp_response->getRedirectUrl())\n");
  5596. outs("\t\t\t{\n");
  5597. outs("\t\t\t\tresponse->redirect(*request, esp_response->getRedirectUrl());\n");
  5598. outs("\t\t\t}\n");
  5599. outs("\t\t\telse\n");
  5600. outs("\t\t\t{\n");
  5601. outs("\t\t\t\tIProperties *props=request->queryParameters();\n");
  5602. outs("\t\t\t\tif (skipXslt(context))\n");
  5603. outs("\t\t\t\t{\n");
  5604. outs("\t\t\t\t\tMemoryBuffer content;\n");
  5605. outs("\t\t\t\t\tStringBuffer mimetype;\n");
  5606. outs("\t\t\t\t\tesp_response->appendContent(&context,content, mimetype);\n");
  5607. outs("\t\t\t\t\tonBeforeSendResponse(context,request,content,service,method);\n");
  5608. outs("\t\t\t\t\tresponse->setContent(content.length(), content.toByteArray());\n");
  5609. outs("\t\t\t\t\tresponse->setContentType(mimetype.str());\n");
  5610. outs("\t\t\t\t}\n");
  5611. outs("\t\t\t\telse\n");
  5612. outs("\t\t\t\t{\n");
  5613. outs("\t\t\t\t\tStringBuffer xml;\n");
  5614. outs("\t\t\t\t\tStringBuffer sResponse;\n");
  5615. if (bClientXslt)
  5616. {
  5617. outs("\t\t\t\t\tif (request->supportClientXslt())\n");
  5618. outf("\t\t\t\t\t\txml.appendf(\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><?xml-stylesheet type=\\\"text/xsl\\\" href=\\\"%%s\\\"?>\", %s);\n", respXsl);
  5619. }
  5620. outs("\t\t\t\t\tesp_response->serializeStruct(&context, xml, NULL);\n\n");
  5621. if (bClientXslt)
  5622. {
  5623. outs("\t\t\t\t\tif (request->supportClientXslt()){\n");
  5624. outs("\t\t\t\t\t\txml.swapWith(sResponse);\n");
  5625. outs("\t\t\t\t\t\tresponse->setContentType(\"text/xml\");\n");
  5626. outs("\t\t\t\t\t}else{\n");
  5627. }
  5628. if(respXsl[1] == '/')
  5629. {
  5630. outf("\t\t\t\t\txslTransform(xml.str(), %s, sResponse.clear(), context.queryXslParameters());\n", respXsl);
  5631. }
  5632. else
  5633. {
  5634. outf("\t\t\t\t\txslTransform(xml.str(), StringBuffer(getCFD()).append(%s).str(), sResponse.clear(), context.queryXslParameters());\n", respXsl);
  5635. }
  5636. outf("\t\t\t\t\tresponse->setContentType(%s);\n", respContentType);
  5637. needsXslt = true;
  5638. if (bClientXslt)
  5639. outs("\t\t\t\t\t}\n");
  5640. outs("\t\t\t\t\tresponse->setContent(sResponse.str());\n");
  5641. outs("\t\t\t\t}\n");
  5642. outs("\t\t\t\tresponse->send();\n");
  5643. outs("\t\t\t}\n");
  5644. outs("\t\t\treturn 0;\n");
  5645. outs("\t\t}\n");
  5646. }
  5647. }
  5648. outs("\n");
  5649. indentReset(2);
  5650. indentOuts("if (esp_response.get())\n");
  5651. indentOuts("{\n");
  5652. indentOuts(1,"if (canRedirect(*request) && esp_response->getRedirectUrl() && *esp_response->getRedirectUrl())\n");
  5653. indentOuts(1,"response->redirect(*request, esp_response->getRedirectUrl());\n");
  5654. indentOuts(-1,"else\n");
  5655. indentOuts("{\n");
  5656. indentOuts(1,"MemoryBuffer content;\n");
  5657. indentOuts("StringBuffer mimetype;\n");
  5658. indentOuts("esp_response->appendContent(&context,content, mimetype);\n");
  5659. indentOuts("onBeforeSendResponse(context,request,content,service,method);\n");
  5660. indentOuts("response->setContent(content.length(), content.toByteArray());\n");
  5661. indentOuts("response->setContentType(mimetype.str());\n");
  5662. indentOuts("response->send();\n");
  5663. indentOuts(-1,"}\n");
  5664. indentOuts("return 0;\n");
  5665. indentOuts(-1,"}\n");
  5666. outs("\t}\n");
  5667. outs("\treturn onGetNotFound(context, request, response, service);\n");
  5668. outs("}\n");
  5669. }
  5670. //-------------------------------------------------------------------------------------------------------------
  5671. // class EspServInfo
  5672. void EspServInfo::write_catch_blocks(EspMethodInfo* mthi, catch_type ct, int indents)
  5673. {
  5674. const char* errorXslt=NULL;
  5675. if (ct==ct_httpresp)
  5676. {
  5677. errorXslt = mthi->getMetaString("exceptions_inline", NULL);
  5678. if (!errorXslt)
  5679. errorXslt = mthi->getMetaString("http_exceptions_inline", NULL);
  5680. if (!errorXslt)
  5681. errorXslt = getMetaString("exceptions_inline", NULL);
  5682. if (!errorXslt)
  5683. errorXslt = getMetaString("http_exceptions_inline", NULL);
  5684. }
  5685. outs(indents,"catch (IMultiException* mex)\n");
  5686. outs(indents,"{\n");
  5687. outs(indents+1,"me->append(*mex);\n");
  5688. outs(indents+1,"mex->Release();\n");
  5689. outs(indents,"}\n");
  5690. //catch IException
  5691. outs(indents,"catch (IException* e)\n");
  5692. outs(indents,"{\n");
  5693. outs(indents+1,"me->append(*e);\n");
  5694. outs(indents,"}\n");
  5695. //catch ...
  5696. outs(indents,"catch (...)\n");
  5697. outs(indents,"{\n");
  5698. outs(indents+1,"me->append(*MakeStringExceptionDirect(-1, \"Unknown Exception\"));\n");
  5699. outs(indents,"}\n");
  5700. //apply any xslt on the error(s), if it is specified in scm file
  5701. //
  5702. if (errorXslt)
  5703. {
  5704. if(errorXslt[1] == '/')
  5705. {
  5706. outf(indents, "if (response->handleExceptions(xslp, me, \"%s\", \"%s\", %s))\n", name_, mthi->getName(), errorXslt);
  5707. }
  5708. else
  5709. {
  5710. outf(indents, "if (response->handleExceptions(xslp, me, \"%s\", \"%s\", StringBuffer(getCFD()).append(%s).str()))\n", name_, mthi->getName(), errorXslt);
  5711. }
  5712. outs(indents+1, "return 0;\n");
  5713. needsXslt=true;
  5714. }
  5715. else
  5716. outf(indents, "esp_response->handleExceptions(me, \"%s\", \"%s\");\n", name_, mthi->getName());
  5717. }
  5718. void EspServInfo::write_esp_service_ipp()
  5719. {
  5720. outf("class C%s : public CInterface,\n", name_);
  5721. outf("\timplements IEsp%s\n", name_);
  5722. outs("{\n");
  5723. outs("private:\n");
  5724. outs("\tIEspContainer* m_container;\n");
  5725. outs("public:\n");
  5726. outs("\tIMPLEMENT_IINTERFACE;\n\n");
  5727. outf("\tC%s(){}\n\tvirtual ~C%s(){}\n", name_, name_);
  5728. outs("\tvirtual void init(IPropertyTree *cfg, const char *process, const char *service)\n\t{\n\t}\n");
  5729. outs("\tvirtual bool init(const char * service, const char * type, IPropertyTree * cfg, const char * process)\n\t{\n\t\treturn true;\n\t}\n");
  5730. outs("\tvirtual void setContainer(IEspContainer *c)\n\t{\n\t\tm_container = c;\n\t}\n");
  5731. outs("\tvirtual IEspContainer *queryContainer()\n\t{\n\t\treturn m_container;\n\t}\n");
  5732. outf("\tvirtual const char* getServiceType(){return \"%s\";}\n\n", name_);
  5733. outf("\tvirtual bool unsubscribeServiceFromDali(){return false;}\n\n");
  5734. outf("\tvirtual bool subscribeServiceToDali(){return false;}\n\n");
  5735. outf("\tvirtual bool detachServiceFromDali(){return false;}\n\n");
  5736. outf("\tvirtual bool attachServiceToDali(){return false;}\n\n");
  5737. outf("\tvirtual bool canDetachFromDali(){return false;}\n\n");
  5738. EspMethodInfo *mthi;
  5739. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5740. {
  5741. bool stubbed = (findMetaTag(mthi->tags,"stubbed")!=NULL);
  5742. if (streq(mthi->getName(), "Ping")) //We'll implement the onPing automatically for all ESP Services.
  5743. {
  5744. outf(1, "bool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)\n", mthi->getName(), mthi->getReq(), mthi->getResp());
  5745. outs(1, "{\n");
  5746. outs(2, "return true;\n");
  5747. outs(1, "}\n");
  5748. }
  5749. else
  5750. {
  5751. outf(1, "%sbool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)\n", (stubbed) ? "" : "//", mthi->getName(), mthi->getReq(), mthi->getResp());
  5752. outf(1, "%s{\n", (stubbed) ? "" : "//");
  5753. outf(2, "%sreturn false;\n", (stubbed) ? "" : "//");
  5754. outf(1, "%s}\n", (stubbed) ? "" : "//");
  5755. }
  5756. }
  5757. outs("};\n\n");
  5758. }
  5759. void EspServInfo::write_esp_service()
  5760. {
  5761. }
  5762. void EspServInfo::write_esp_client_ipp()
  5763. {
  5764. int useMethodName = getMetaInt("use_method_name", 0);
  5765. outf("class CClient%s : public CInterface,\n", name_);
  5766. outf("\timplements IClient%s\n", name_);
  5767. outs("{\nprotected:\n");
  5768. outs("\tStringBuffer soap_proxy;\n");
  5769. outs("\tStringBuffer soap_url;\n");
  5770. //dom
  5771. outs("\tStringBuffer soap_userid;\n");
  5772. outs("\tStringBuffer soap_password;\n");
  5773. outs("\tStringBuffer soap_realm;\n");
  5774. outs("\tStringBuffer soap_action;\n");
  5775. outs("\tlong soap_reqid = 0;\n");
  5776. outs("\npublic:\n");
  5777. outs("\tIMPLEMENT_IINTERFACE;\n\n");
  5778. outf("\tCClient%s()\n\t{\n", name_);
  5779. outs("\t\tsoap_reqid=0;\n\t");
  5780. outf("\t\tsoap_action.append(\"%s\");\n\t", name_);
  5781. const char *ver = getMetaString("default_client_version", NULL);
  5782. if (ver && *ver)
  5783. outf("\t\tsoap_action.append(\"?ver_=\").append(%s);\n\t", ver);
  5784. outf("}\n\tvirtual ~CClient%s(){}\n", name_);
  5785. outs("\tvirtual void setProxyAddress(const char *address)\n\t{\n\t\tsoap_proxy.set(address);\n\t}\n");
  5786. outs("\tvirtual void addServiceUrl(const char *url)\n\t{\n\t\tsoap_url.set(url);\n\t}\n");
  5787. outs("\tvirtual void removeServiceUrl(const char *url)\n\t{\n\t}\n");
  5788. //domsetUsernameToken
  5789. outs("\tvirtual void setUsernameToken(const char *userid,const char *password,const char *realm)\n\t{\n\t\t soap_userid.set(userid);\n\t\t soap_password.set(password);\n\t\t soap_realm.set(realm);\n\t}\n");
  5790. outs("\tvirtual void setAction(const char *action)\n\t{\n\t\tsoap_action.set(action);\n\t}\n");
  5791. EspMethodInfo *mthi;
  5792. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5793. {
  5794. outs("\n");
  5795. outf("\tvirtual IClient%s * create%sRequest();\n", mthi->getReq(), mthi->getName());
  5796. outf("\tvirtual IClient%s * %s(IClient%s *request);\n", mthi->getResp(), mthi->getName(), mthi->getReq());
  5797. outf("\tvirtual void async_%s(IClient%s *request, IClient%sEvents *events,IInterface* state=0);\n", mthi->getName(), mthi->getReq(), name_);
  5798. mthi->write_esp_method(name_, true, false);
  5799. }
  5800. outs("\tstatic int transferThunkEvent(void *data);\n");
  5801. outs("#ifdef _WIN32\n");
  5802. outs("\tstatic void espWorkerThread(void* data);\n");
  5803. outs("#else\n");
  5804. outs("\tstatic void *espWorkerThread(void *data);\n");
  5805. outs("#endif\n");
  5806. outs("};\n\n");
  5807. }
  5808. void EspServInfo::write_esp_client()
  5809. {
  5810. int useMethodName = getMetaInt("use_method_name", 0);
  5811. //comment
  5812. outs("\n//=======================================================");
  5813. outs("\n// client util methods");
  5814. outs("\n//=======================================================");
  5815. outs("\n");
  5816. EspMethodInfo *mthi;
  5817. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5818. {
  5819. outf("\n//------ method %s ---------\n", mthi->getName());
  5820. outf("\nIClient%s * CClient%s::create%sRequest()\n", mthi->getReq(), name_, mthi->getName());
  5821. outf("{\n\tC%s* request = new C%s(\"%s\");\n", mthi->getReq(), mthi->getReq(), name_);
  5822. outs("\trequest->setProxyAddress(soap_proxy.str());\n");
  5823. outs("\trequest->setUrl(soap_url.str());\n");
  5824. if (useMethodName)
  5825. outf("\trequest->setMsgName(\"%s\");\n", mthi->getName());
  5826. outs("\treturn request;\n}\n");
  5827. outf("\nIClient%s * CClient%s::%s(IClient%s *request)\n", mthi->getResp(), name_, mthi->getName(), mthi->getReq());
  5828. outs("{\n");
  5829. outs("\tif(soap_url.length()== 0){ throw MakeStringExceptionDirect(-1, \"url not set\"); }\n\n");
  5830. outf("\tC%s* esprequest = static_cast<C%s*>(request);\n", mthi->getReq(), mthi->getReq());
  5831. outf("\tC%s* espresponse = new C%s(\"%s\");\n\n", mthi->getResp(), mthi->getResp(), name_);
  5832. outs("\tespresponse->setReqId(soap_reqid++);\n");
  5833. //dom
  5834. outs("\tesprequest->soap_setUserId( soap_userid.str());\n");
  5835. outs("\tesprequest->soap_setPassword(soap_password.str());\n");
  5836. outs("\tesprequest->soap_setRealm(soap_realm.str());\n");
  5837. outs("\tconst char *soapaction=(soap_action.length()) ? soap_action.str() : NULL;\n");
  5838. outs("\tesprequest->post(soap_proxy.str(), soap_url.str(), *espresponse, soapaction);\n");
  5839. outs("\treturn espresponse;\n");
  5840. outs("}\n");
  5841. outf("\nvoid CClient%s::async_%s(IClient%s *request, IClient%sEvents *events,IInterface* state)\n", name_, mthi->getName(), mthi->getReq(), name_);
  5842. outs("{\n");
  5843. outs("\tif(soap_url.length()==0){ throw MakeStringExceptionDirect(-1, \"url not set\"); }\n\n");
  5844. outf("\tC%s* esprequest = static_cast<C%s*>(request);\n", mthi->getReq(), mthi->getReq());
  5845. outf("\tesprequest->setMethod(\"%s\");\n", mthi->getName());
  5846. outs("\tesprequest->setReqId(soap_reqid++);\n");
  5847. outs("\tesprequest->setEventSink(events);\n");
  5848. outs("\tesprequest->setState(state);\n");
  5849. outs("\tesprequest->soap_setUserId( soap_userid.str());\n");
  5850. outs("\tesprequest->soap_setPassword( soap_password.str());\n");
  5851. outs("\tesprequest->soap_setRealm( soap_realm.str());\n");
  5852. outs("#ifdef USE_CLIENT_THREAD\n");
  5853. outs("\tesprequest->setThunkHandle(GetThunkingHandle());\n");
  5854. outs("#endif\n");
  5855. outs("\tesprequest->Link();\n\n");
  5856. outs("\tif(state!=NULL)\n");
  5857. outs("\t\tstate->Link();\n\n");
  5858. outs("#ifdef _WIN32\n");
  5859. outs("\t_beginthread(espWorkerThread, 0, (void *)(IRpcRequestBinding *)(esprequest));\n");
  5860. outs("#else\n");
  5861. outs("\tpthread_attr_t attr;\n");
  5862. outs("\tpthread_attr_init(&attr);\n");
  5863. outs("\tpthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);\n");
  5864. outs("\tpthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);\n");
  5865. outs("\tpthread_attr_setstacksize(&attr, 0x10000);\n");
  5866. outs("\tThreadId threadid;\n");
  5867. outs("\tint status;\n");
  5868. outs("\tdo\n");
  5869. outs("\t{\n");
  5870. outf("\t\tstatus = pthread_create(&threadid, &attr, CClient%s::espWorkerThread, (void *)(IRpcRequestBinding *)(esprequest));\n", name_);
  5871. outs("\t} while (0 != status && (errno == EINTR));\n");
  5872. outs("\tif (status) {\n");
  5873. outs("\t\tRelease();\n");
  5874. outs("\t\tthrow makeOsException(errno);\n");
  5875. outs("\t}\n");
  5876. outs("#endif\n");
  5877. outs("}\n");
  5878. mthi->write_esp_method(name_, false, false);
  5879. }
  5880. outf("\nint CClient%s::transferThunkEvent(void *data)\n", name_);
  5881. outs("{\n");
  5882. outs("\tIRpcResponseBinding *response = (IRpcResponseBinding *)data;\n");
  5883. outs("\tif (response!=NULL)\n");
  5884. outs("\t{\n");
  5885. outf("\t\tIClient%sEvents *eventSink = (IClient%sEvents *)response->getEventSink();\n", name_, name_);
  5886. outs("\t\tresponse->lock();\n\n");
  5887. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5888. {
  5889. outf(2, "if (stricmp(response->getMethod(), \"%s\")==0)\n", mthi->getName());
  5890. outs(2, "{\n");
  5891. outf(3, "IClient%s* icresp = dynamic_cast<IClient%s*>(response);\n", mthi->getResp(), mthi->getResp());
  5892. outf(3, "if (icresp) {\n");
  5893. outs(4, "if (response->getRpcState() == RPC_MESSAGE_OK)\n");
  5894. outf(5, "eventSink->on%sComplete(icresp, response->queryState());\n", mthi->getName());
  5895. outf(4, "else\n");
  5896. outf(5, "eventSink->on%sError(icresp,response->queryState());\n", mthi->getName());
  5897. outs(3, "}\n");
  5898. outs(2, "}\n");
  5899. }
  5900. outs("\t\tresponse->unlock();\n");
  5901. outs("\t}\n");
  5902. outs("\treturn 0;\n");
  5903. outs("}\n");
  5904. //=============================================================================
  5905. // method: espWorkerThread(void* data)
  5906. outf("\nstatic IRpcResponseBinding* create%sResponseObject(IRpcRequestBinding *request)\n",name_);
  5907. outs("{\n");
  5908. outs("\tconst char* method = request->getMethod();\n");
  5909. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5910. {
  5911. outf("\tif (stricmp(method, \"%s\")==0)\n", mthi->getName());
  5912. outf("\t\treturn new C%s(\"%s\", request);\n", mthi->getResp(), name_);
  5913. }
  5914. outf("\treturn NULL;\n");
  5915. outs("}\n");
  5916. outf("\n#ifdef _WIN32\n");
  5917. outf("void CClient%s::espWorkerThread(void* data)\n", name_);
  5918. outf("#else\n");
  5919. outf("void *CClient%s::espWorkerThread(void *data)\n", name_);
  5920. outf("#endif\n");
  5921. outs("{\n");
  5922. outs("\tIRpcRequestBinding *request = (IRpcRequestBinding *) data;\n\n");
  5923. outs("\tif (request != NULL)\n");
  5924. outs("\t{\n");
  5925. outs("\t\trequest->lock();\n");
  5926. outf("\t\tIRpcResponseBinding *response=create%sResponseObject(request);\n",name_);
  5927. /*
  5928. const char *preif="";
  5929. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5930. {
  5931. outf("\t\t%sif (stricmp(request->getMethod(), \"%s\")==0)\n\t\t{\n", preif, mthi->getName());
  5932. outf("\t\t\tresponse = new C%s(\"%s\", request);\n\t\t}\n", mthi->getResp(), name_);
  5933. preif="else ";
  5934. }
  5935. outf("\tresponse = createResponseObject(request);\n");
  5936. */
  5937. outs(2, "if (response!=NULL)\n");
  5938. outs(2, "{\n");
  5939. outs(3, "try{\n");
  5940. outs(4, "request->post(*response);\n");
  5941. outs(3, "}\n");
  5942. outs(3, "catch(IException* ex){\n");
  5943. outs(4, "StringBuffer errorStr;\n");
  5944. outs(4, "ex->errorMessage(errorStr);\n");
  5945. outf(4, "ERRLOG(\"CClient%s::espWorkerThread(%%s)--Exception caught while posting async request: %%s\", request->getMethod(), errorStr.str());\n", name_);
  5946. outs(4, "ex->Release();\n");
  5947. outs(3, "}\n");
  5948. outs(3, "catch(...){\n");
  5949. outs(4, "ERRLOG(\"Unknown exception caught while posting async request\");\n");
  5950. outs(3, "}\n");
  5951. outs(2, "}\n");
  5952. outs("#ifdef USE_CLIENT_THREAD\n");
  5953. outs("\t\tThunkToClientThread(request->getThunkHandle(), transferThunkEvent, (void *)response);\n");
  5954. outs("#else\n");
  5955. outs("\t\ttransferThunkEvent((void *)response);\n");
  5956. outs("#endif\n");
  5957. outs("\t\trequest->unlock();\n");
  5958. outs("\t\tif(request->queryState()!=NULL)\n");
  5959. outs("\t\t\trequest->queryState()->Release();\n\n");
  5960. outs("\t\tif(response!=NULL)\n");
  5961. outs("\t\t\tresponse->Release();\n\n");
  5962. outs("\t\trequest->Release();\n");
  5963. outs("\t}\n");
  5964. outs("#if defined(_WIN32)\n");
  5965. outs("#else\n");
  5966. outs("\treturn (void *) 0 ;\n");
  5967. outs("#endif\n");
  5968. outs("}\n\n");
  5969. }
  5970. void EspServInfo::write_clarion_include_interface()
  5971. {
  5972. outf("cppClient%sEvents INTERFACE(cppInterface),COM\n", name_);
  5973. EspMethodInfo *mthi;
  5974. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5975. {
  5976. outf("on%sComplete PROCEDURE(*cppClient%s resp),PROC\n", mthi->getName(), mthi->getResp());
  5977. outf("on%sError PROCEDURE(*cppClient%s resp),PROC\n", mthi->getName(), mthi->getResp());
  5978. }
  5979. outs("\n END\n\n");
  5980. outf("cppClient%s INTERFACE(cppInterface),COM\n", name_);
  5981. outs("setProxyAddress PROCEDURE(CONST *CSTRING address),PROC\n");
  5982. outs("addServiceUrl PROCEDURE(CONST *CSTRING url),PROC\n");
  5983. outs("removeServiceUrl PROCEDURE(CONST *CSTRING url),PROC\n");
  5984. outs("setUsernameToken PROCEDURE(CONST *CSTRING Username,CONST *CSTRING Password,CONST *CSTRING Realm ),PROC\n");
  5985. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5986. {
  5987. outf("create%sRequest PROCEDURE(),*cppClient%s,PROC\n", mthi->getName(), mthi->getReq());//mthi->getName());
  5988. outf("%s PROCEDURE(*cppClient%s request),*cppClient%s,PROC\n", mthi->getName(), mthi->getReq(), mthi->getResp());
  5989. outf("async_%s PROCEDURE(*cppClient%s request, *cppClient%sEvents events,*cppInterface State),PROC\n", mthi->getName(), mthi->getReq(), name_);
  5990. }
  5991. outs("\n END\n\n");
  5992. }
  5993. //interface IEspInstantEcl
  5994. void EspServInfo::write_event_interface()
  5995. {
  5996. outf("interface IClient%sEvents : extends IInterface\n", name_);
  5997. outs("{");
  5998. EspMethodInfo *mthi;
  5999. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  6000. {
  6001. outs("\n");
  6002. outf("\tvirtual int on%sComplete(IClient%s *resp,IInterface* state)=0;\n", mthi->getName(), mthi->getResp());
  6003. outf("\tvirtual int on%sError(IClient%s *resp,IInterface* state)=0;", mthi->getName(), mthi->getResp());
  6004. }
  6005. outs("\n};\n\n");
  6006. }
  6007. void EspServInfo::write_esp_interface()
  6008. {
  6009. outf("interface IEsp%s : extends IEspService\n", name_);
  6010. outs("{");
  6011. EspMethodInfo *mthi;
  6012. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  6013. {
  6014. outs("\n");
  6015. outf("\tvirtual bool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)=0;", mthi->getName(), mthi->getReq(), mthi->getResp());
  6016. }
  6017. outs("\n};\n\n");
  6018. }
  6019. void EspServInfo::write_client_interface()
  6020. {
  6021. outf("interface IClient%s : extends IInterface\n", name_);
  6022. outs("{\n");
  6023. outs("\tvirtual void setProxyAddress(const char *address)=0;\n");
  6024. outs("\tvirtual void addServiceUrl(const char *url)=0;\n");
  6025. outs("\tvirtual void removeServiceUrl(const char *url)=0;\n");
  6026. outs("\tvirtual void setUsernameToken(const char *userName,const char *passWord,const char *realm)=0;\n");
  6027. outs("\tvirtual void setAction(const char *action)=0;\n");
  6028. EspMethodInfo *mthi;
  6029. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  6030. {
  6031. outs("\n");
  6032. outf("\tvirtual IClient%s * create%sRequest()=0;\n", mthi->getReq(), mthi->getName());
  6033. outf("\tvirtual IClient%s * %s(IClient%s *request)=0;\n", mthi->getResp(), mthi->getName(), mthi->getReq());
  6034. outf("\tvirtual void async_%s(IClient%s *request, IClient%sEvents *events,IInterface* state=0)=0;\n", mthi->getName(), mthi->getReq(), name_);
  6035. }
  6036. //add the new "flattened" client methods at the end
  6037. outs("\n");
  6038. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  6039. {
  6040. mthi->write_esp_method(name_, true, true);
  6041. }
  6042. outs("};\n\n");
  6043. }
  6044. static EspMethodInfo* sortMethods(EspMethodInfo* ms)
  6045. {
  6046. if (ms==NULL)
  6047. return ms;
  6048. // find the smallest node
  6049. EspMethodInfo* smallest = ms;
  6050. EspMethodInfo* prev = NULL; // the node right before the smallest node
  6051. for (EspMethodInfo* p = ms; p->next!=NULL; p = p->next)
  6052. {
  6053. if (strcmp(p->next->getName(), smallest->getName())<0)
  6054. {
  6055. prev = p;
  6056. smallest = p->next;
  6057. }
  6058. }
  6059. // move the smallest to the head
  6060. if (smallest != ms)
  6061. {
  6062. if (prev == ms)
  6063. {
  6064. ms->next = smallest->next;
  6065. smallest->next = ms;
  6066. }
  6067. else
  6068. {
  6069. EspMethodInfo* tmp = smallest->next;
  6070. smallest->next = ms->next;
  6071. prev->next = ms;
  6072. ms->next = tmp;
  6073. }
  6074. }
  6075. // recurively sort
  6076. smallest->next = sortMethods(smallest->next);
  6077. return smallest;
  6078. }
  6079. void EspServInfo::sortMethods()
  6080. {
  6081. methods = ::sortMethods(methods);
  6082. }
  6083. //-------------------------------------------------------------------------------------------------------------
  6084. // class HIDLcompiler
  6085. char* getTargetBase(const char* outDir, const char* src)
  6086. {
  6087. if (outDir && *outDir)
  6088. {
  6089. size_t dirlen = strlen(outDir);
  6090. size_t srclen = strlen(src);
  6091. char* buf = (char*)malloc(dirlen+srclen+5);
  6092. // get file name only
  6093. const char* p = src+srclen-1;
  6094. while(p>src && *p!='/' && *p!='\\') p--;
  6095. if (*p == '/' || *p == '\\') p++;
  6096. // absolute path
  6097. if (*outDir=='/' || *outDir=='\\' || outDir[1]==':')
  6098. {
  6099. // dir: outDir+'/'+fileName
  6100. strcpy(buf,outDir);
  6101. }
  6102. else // relative path
  6103. {
  6104. // dir: srcPath + '/' + outDir+'/'+fileName
  6105. size_t len = p-src;
  6106. if (len>0)
  6107. {
  6108. strncpy(buf,src,len);
  6109. if (buf[len-1]=='/' || buf[len-1]=='\\')
  6110. buf[len-1]='/';
  6111. else
  6112. buf[len++] = '/';
  6113. }
  6114. strcpy(buf+len,outDir);
  6115. }
  6116. size_t len = strlen(buf);
  6117. if (buf[len-1]=='/' || buf[len-1]=='\\')
  6118. {
  6119. buf[len-1]=0;
  6120. len--;
  6121. }
  6122. // now buf has the directory name for output: make the directory if not exist
  6123. createDirectory(buf);
  6124. // copy the file name
  6125. buf[len] = '/';
  6126. strcpy(buf+len+1, p);
  6127. //printf("src: %s. dir: %s.\n", src,outDir);
  6128. //printf("buf: %s\n", buf);
  6129. return buf;
  6130. }
  6131. else
  6132. return strdup(src);
  6133. }
  6134. static void safeclose(int fh)
  6135. {
  6136. if (fh >= 0)
  6137. close(fh);
  6138. }
  6139. HIDLcompiler::HIDLcompiler(const char * sourceFile,const char *outDir)
  6140. {
  6141. modules = NULL;
  6142. enums = NULL;
  6143. apis = NULL;
  6144. servs = NULL;
  6145. msgs = NULL;
  6146. includes = NULL;
  6147. filename = strdup(sourceFile);
  6148. size_t l = strlen(filename);
  6149. yyin = fopen(sourceFile, "rt");
  6150. if (!yyin) {
  6151. printf("Fatal Error: Cannot read %s\n",sourceFile);
  6152. exit(1);
  6153. }
  6154. packagename = gettail(sourceFile);
  6155. char* targetBase = getTargetBase(outDir, sourceFile);
  6156. ho = createFile(targetBase,"hpp");
  6157. cppo = createFile(targetBase, isSCM ? "ipp" : "cpp");
  6158. #if 0
  6159. xsvo = createFile(targetBase, "xsv");
  6160. #endif
  6161. clwo = createFile(targetBase, "int");
  6162. espx = isESP ? createFile(targetBase,"esp") : -1;
  6163. espng = isESPng ? createFile(targetBase,"_esp_ng", "ipp") : -1;
  6164. espngc= isESPng ? createFile(targetBase,"_esp_ng", "cpp") : -1;
  6165. espi= isESP ? createFile(targetBase, "_esp", "ipp") : -1;
  6166. espc= isESP ? createFile(targetBase, "_esp", "cpp") : -1;
  6167. free(targetBase);
  6168. }
  6169. HIDLcompiler::~HIDLcompiler()
  6170. {
  6171. fclose(yyin);
  6172. close(ho);
  6173. close(cppo);
  6174. //close(xsvo);
  6175. close(clwo);
  6176. safeclose(espx);
  6177. safeclose(espng);
  6178. safeclose(espngc);
  6179. safeclose(espi);
  6180. safeclose(espc);
  6181. free(packagename);
  6182. free(filename);
  6183. delete modules;
  6184. delete enums;
  6185. delete apis;
  6186. delete msgs;
  6187. delete servs;
  6188. delete includes;
  6189. }
  6190. void HIDLcompiler::Process()
  6191. {
  6192. hcp = this;
  6193. write_header_class_intro();
  6194. nCommentStartLine = -1;
  6195. yyparse();
  6196. if (nCommentStartLine > -1)
  6197. {
  6198. char tempBuf[256];
  6199. sprintf(tempBuf, "The comment that started at line %d is not ended yet", nCommentStartLine);
  6200. yyerror(tempBuf);
  6201. }
  6202. write_header_class_outro();
  6203. write_source_file_classes();
  6204. //write_example_implementation_module();
  6205. if (isESP)
  6206. {
  6207. write_esp();
  6208. write_esp_ex_ipp();
  6209. }
  6210. if (isESPng)
  6211. {
  6212. write_esp_ng();
  6213. write_esp_ng_cpp();
  6214. }
  6215. if (isSCM)
  6216. write_clarion_HRPC_interfaces();
  6217. }
  6218. void HIDLcompiler::write_esp()
  6219. {
  6220. //create the *.esp file
  6221. gOutfile = espx;
  6222. outf("// *** Source file generated by " HIDL " Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6223. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6224. outf("#ifndef %s_ESPGEN_INCLUDED\n", packagename);
  6225. outf("#define %s_ESPGEN_INCLUDED\n\n", packagename);
  6226. outf("#include \"%s_esp.ipp\"\n", packagename);
  6227. outs("\n");
  6228. outs("#ifdef _WIN32\n");
  6229. outs("#include \"edwin.h\"\n");
  6230. outs("#include <process.h>\n");
  6231. outs("#endif\n");
  6232. outs("\n\n");
  6233. EspMessageInfo * mi;
  6234. for (mi=msgs;mi;mi=mi->next)
  6235. {
  6236. mi->write_esp();
  6237. }
  6238. EspServInfo *si;
  6239. for (si=servs;si;si=si->next)
  6240. {
  6241. si->write_esp_binding();
  6242. outs("\n\n");
  6243. si->write_esp_service();
  6244. outs("\n\n");
  6245. si->write_esp_client();
  6246. outs("\n\n");
  6247. si->write_factory_impl();
  6248. outs("\n\n");
  6249. }
  6250. outf("#endif //%s_ESPGEN_INCLUDED\n", packagename);
  6251. gOutfile = espc;
  6252. outf("// *** Source file generated by " HIDL " Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6253. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6254. //outf("#ifndef %s_ESPX_INCLUDED\n", packagename);
  6255. //outf("#define %s_ESPX_INCLUDED\n\n", packagename);
  6256. //if (esp_def_export_tag)
  6257. // outf("#include \"%s.esp\"\n", packagename);
  6258. outf("#include \"%s.esp\"\n", packagename);
  6259. outs("\n\n");
  6260. //outf("#endif //%s_ESPX_INCLUDED\n", packagename);
  6261. }
  6262. void HIDLcompiler::write_esp_ex_ipp()
  6263. {
  6264. gOutfile = espi;
  6265. outf("// *** Source file generated by " HIDL " Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6266. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6267. outf("#ifndef %s_EX_ESPGEN_INCLUDED\n", packagename);
  6268. outf("#define %s_EX_ESPGEN_INCLUDED\n\n", packagename);
  6269. outs("#pragma warning( disable : 4786)\n\n");
  6270. outs("//JLib\n");
  6271. outs("#include \"jliball.hpp\"\n");
  6272. outs("\n");
  6273. outs("//SCM Interfaces\n");
  6274. outs("#include \"esp.hpp\"\n");
  6275. outs("#include \"soapesp.hpp\"\n");
  6276. outf("#include \"%s.hpp\"\n", packagename);
  6277. outs("//ESP Bindings\n");
  6278. outs("#include \"SOAP/Platform/soapmessage.hpp\"\n");
  6279. outs("#include \"SOAP/Platform/soapmacro.hpp\"\n");
  6280. outs("#include \"SOAP/Platform/soapservice.hpp\"\n");
  6281. outs("#include \"SOAP/Platform/soapparam.hpp\"\n");
  6282. outs("#include \"SOAP/client/soapclient.hpp\"\n");
  6283. outs("\n\n");
  6284. outf("namespace %s\n{\n\n", packagename);
  6285. EspMessageInfo * mi;
  6286. for (mi=msgs;mi;mi=mi->next)
  6287. {
  6288. mi->write_esp_ipp();
  6289. }
  6290. EspServInfo *si;
  6291. for (si=servs;si;si=si->next)
  6292. {
  6293. si->write_esp_service_ipp();
  6294. outs("\n\n");
  6295. si->write_esp_binding_ipp();
  6296. outs("\n\n");
  6297. si->write_esp_client_ipp();
  6298. outs("\n\n");
  6299. }
  6300. outs("}\n");
  6301. outf("using namespace %s;\n\n", packagename);
  6302. outf("#endif //%s_ESPGEN_INCLUDED\n", packagename);
  6303. }
  6304. void HIDLcompiler::write_source_file_classes()
  6305. {
  6306. gOutfile = cppo;
  6307. outf("// *** Source file generated by " HIDL " Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6308. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6309. outf("#include \"%s.hpp\"\n\n",packagename);
  6310. ModuleInfo * mi;
  6311. for (mi=modules;mi;mi=mi->next)
  6312. {
  6313. if (isSCM) {
  6314. mi->write_clarion_scm_stub_class();
  6315. }
  6316. else {
  6317. mi->write_body_class();
  6318. mi->write_clarion_interface_class();
  6319. }
  6320. }
  6321. outs("//end\n"); // CR for Clarion
  6322. }
  6323. void HIDLcompiler::write_clarion_esp_interfaces()
  6324. {
  6325. gOutfile = clwo;
  6326. EspMessageInfo * mi;
  6327. for (mi=msgs;mi;mi=mi->next)
  6328. {
  6329. mi->write_clarion_include_interface();
  6330. outs("\n\n");
  6331. }
  6332. EspServInfo *si;
  6333. for (si=servs;si;si=si->next)
  6334. {
  6335. si->write_clarion_include_interface();
  6336. outs("\n\n");
  6337. }
  6338. }
  6339. void HIDLcompiler::write_clarion_HRPC_interfaces()
  6340. {
  6341. gOutfile = clwo;
  6342. if (isSCM)
  6343. outs("! Clarion SCM Interfaces\n");
  6344. else
  6345. {
  6346. // outs("! Clarion HRPC Interfaces\n");
  6347. outs("*** No longer generated\n");
  6348. return;
  6349. }
  6350. outf("! Include file generated by " HIDL " Version %s from %s.%s\n", HIDLVER, packagename, srcFileExt);
  6351. outs("! *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6352. outf(" OMIT('EndOfInclude',_%s_I_)\n",packagename);
  6353. outf("_%s_I_ EQUATE(1)\n\n",packagename);
  6354. if (isSCM)
  6355. {
  6356. outs(" INCLUDE('SCM.INT'),ONCE\n\n");
  6357. if (clarion.length())
  6358. {
  6359. outs(clarion.str());
  6360. outs("\n\n");
  6361. }
  6362. }
  6363. else
  6364. outs(" INCLUDE('HRPC.INC'),ONCE\n\n");
  6365. EnumInfo * ei;
  6366. for (ei=enums;ei;ei=ei->next)
  6367. {
  6368. ei->write_clarion_enum();
  6369. }
  6370. ModuleInfo * mi;
  6371. for (mi=modules;mi;mi=mi->next)
  6372. {
  6373. mi->write_clarion_include_module();
  6374. }
  6375. if (isESP)
  6376. {
  6377. write_clarion_esp_interfaces();
  6378. }
  6379. outs("\n");
  6380. outs(" MAP\n");
  6381. outf(" MODULE('%s')\n",packagename);
  6382. if (!isSCM)
  6383. {
  6384. for (mi=modules;mi;mi=mi->next)
  6385. {
  6386. outf(" HRPC_Make_%s(HRPCI_Clarion_Transport transport),*HRPCI_%s,PASCAL,NAME('_HRPC_Make_%s@4')\n",mi->name,mi->name,mi->name);
  6387. }
  6388. }
  6389. else
  6390. {
  6391. ApiInfo * fi;
  6392. for (fi=apis;fi;fi=fi->next)
  6393. {
  6394. fi->write_clarion_include_method();
  6395. }
  6396. }
  6397. outs(" END\n\n");
  6398. outs(" END\n\n");
  6399. outf("\nEndOfInclude\n");
  6400. }
  6401. void HIDLcompiler::write_example_implementation_module()
  6402. {
  6403. gOutfile = xsvo;
  6404. outs("// Example Server Implementation Template\n");
  6405. outf("// Source file generated by " HIDL " Version %s from %s.%s\n", HIDLVER, packagename, srcFileExt);
  6406. outs("// *** You should copy this file before changing, as it will be overwritten next time " HIDL " is run ***\n\n");
  6407. outs("#include <stddef.h>\n");
  6408. outs("#include <stdlib.h>\n");
  6409. outs("#include <assert.h>\n\n");
  6410. outs("#include \"hrpcsock.hpp\"// default use TCP/IP sockets\n\n");
  6411. outs("// TBD - Add other includes here\n\n");
  6412. ModuleInfo * mi;
  6413. for (mi=modules;mi;mi=mi->next)
  6414. {
  6415. mi->write_define();
  6416. }
  6417. outf("#include \"%s.cpp\"\n\n",packagename);
  6418. for (mi=modules;mi;mi=mi->next)
  6419. {
  6420. mi->write_example_module();
  6421. }
  6422. }
  6423. void HIDLcompiler::write_header_class_intro()
  6424. {
  6425. gOutfile=ho;
  6426. outf("// *** Include file generated by " HIDL " Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6427. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6428. outf("#ifndef %s_%s_INCL\n",packagename,isSCM?"SCM":"HID");
  6429. outf("#define %s_%s_INCL\n\n",packagename,isSCM?"SCM":"HID");
  6430. if (isESP)
  6431. {
  6432. outf("#include \"esp.hpp\"\n\n");
  6433. }
  6434. else if (isSCM)
  6435. {
  6436. //outf("#include \"scm.hpp\"\n\n");
  6437. }
  6438. else
  6439. outf("#include \"hrpc.hpp\"\n\n");
  6440. }
  6441. void HIDLcompiler::write_header_class_outro()
  6442. {
  6443. outs("\n");
  6444. EspMessageInfo * mi;
  6445. for (mi=msgs;mi;mi=mi->next)
  6446. {
  6447. mi->write_factory_decl();
  6448. }
  6449. outs("\n");
  6450. outf("#endif // _%s_%s_INCL\n", packagename,isSCM?"SCM":"HID");
  6451. outs("//end\n"); // CR for Clarion
  6452. }
  6453. //-------------------------------------------------------------------------------------------------------------
  6454. // class EnumInfo
  6455. void EnumInfo::write_header_enum()
  6456. {
  6457. outf("enum %s\n{\n", name);
  6458. for (EnumValInfo *vi=vals;vi;vi=vi->next) {
  6459. outf("\t%s = %d",vi->name,vi->val);
  6460. if (vi->next)
  6461. outs(",\n");
  6462. else
  6463. outs("\n");
  6464. }
  6465. outs("};\n\n");
  6466. }
  6467. void EnumInfo::write_clarion_enum()
  6468. {
  6469. outf("%s EQUATE(UNSIGNED)\n", xlat(name));
  6470. outf(" ITEMIZE,PRE(%s)\n",xlat(name));
  6471. for (EnumValInfo *vi=vals;vi;vi=vi->next) {
  6472. outf("%s\tEQUATE(%d)\n",xlat(vi->name),vi->val);
  6473. }
  6474. outs("\tEND\n\n");
  6475. }
  6476. // end
  6477. //-------------------------------------------------------------------------------------------------------------