hidlcomp.cpp 242 KB

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