hidlcomp.cpp 239 KB

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