hidlcomp.cpp 242 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098
  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. outf(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, typname);
  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. outf("const char* ", typname);
  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 (isSCM)
  1872. outf("");
  1873. if (classpfx)
  1874. outf(" %s::%s",classpfx,name);
  1875. else
  1876. outf(" %s",name);
  1877. out_parameter_list("");
  1878. if (constfunc) {
  1879. if (isSCM)
  1880. outf(" const");
  1881. else
  1882. outf(" /* const (omitted by HIDL) */");
  1883. }
  1884. if ((virt==2)&&!omitvirt) {
  1885. if (isSCM)
  1886. outf(" = 0");
  1887. else
  1888. outf(" HRPCpure%s",callback?"callback":"");
  1889. }
  1890. }
  1891. void ProcInfo::out_parameter_list(const char *pfx,int forclarion)
  1892. {
  1893. outs("(");
  1894. ParamInfo * p = params;
  1895. while (p)
  1896. {
  1897. p->out_parameter(pfx, forclarion);
  1898. p = p->next;
  1899. if (p)
  1900. outs(", ");
  1901. }
  1902. outs(")");
  1903. }
  1904. void ProcInfo::write_body_method_structs2(const char * modname)
  1905. {
  1906. // buffer structure
  1907. outf("struct HRPC_d_%s__%s\n{\n",modname,name);
  1908. ParamInfo *p;
  1909. lastin=NULL;
  1910. firstin=NULL;
  1911. ForEachParam(this,p,0,0)
  1912. p->flags &= ~PF_SIMPLE;
  1913. size_t align=0;
  1914. int dummy = 0;
  1915. ForEachParam(this,p,PF_IN,PF_OUT|PF_REF|PF_PTR|PF_VARSIZE) {
  1916. p->flags |= PF_SIMPLE;
  1917. lastin = p;
  1918. if (!firstin)
  1919. firstin = p;
  1920. size_t a=p->typesizealign(align);
  1921. if (a>0) {
  1922. dummy++;
  1923. if (a>1)
  1924. outf("\tchar __dummy%d[%d];\n",dummy,a);
  1925. else
  1926. outf("\tchar __dummy%d;\n",dummy,a);
  1927. }
  1928. p->write_body_struct_elem(0);
  1929. }
  1930. if (align>0) {
  1931. dummy++;
  1932. outf("\tchar _dummy%d[%d];\n",dummy,4-align);
  1933. align = 0;
  1934. }
  1935. ForEachParam(this,p,PF_IN,PF_OUT|PF_SIMPLE) {
  1936. p->write_body_struct_elem(1);
  1937. }
  1938. ForEachParam(this,p,PF_IN|PF_OUT,PF_SIMPLE) {
  1939. p->write_body_struct_elem(1);
  1940. }
  1941. ForEachParam(this,p,PF_OUT,PF_IN|PF_SIMPLE) {
  1942. p->write_body_struct_elem(1);
  1943. }
  1944. if (rettype) {
  1945. rettype->typesizealign(align);
  1946. rettype->write_body_struct_elem(0);
  1947. if (align>0) {
  1948. dummy++;
  1949. outf("\tchar _dummy%d[%d];\n",dummy,4-align);
  1950. align = 0;
  1951. }
  1952. }
  1953. int swapp=write_body_swapparam();
  1954. write_body_pushparam(swapp);
  1955. write_body_popparam(swapp);
  1956. if (!async) {
  1957. write_body_pushreturn();
  1958. write_body_popreturn();
  1959. }
  1960. // now constructors
  1961. outf("\tHRPC_d_%s__%s() {}\n",modname,name);
  1962. if (params) {
  1963. outf("\tHRPC_d_%s__%s",modname,name);
  1964. out_parameter_list("_");
  1965. outs(": ");
  1966. ForEachParam(this,p,0,0) {
  1967. outf("%s(",p->name);
  1968. if (p->flags&PF_REF) {
  1969. outs("&");
  1970. }
  1971. else if ((p->flags&(PF_PTR&PF_CONST))==(PF_PTR&PF_CONST)) {
  1972. p->write_param_convert();
  1973. }
  1974. outf("_%s)",p->name);
  1975. if (p->next)
  1976. outs(", ") ;
  1977. }
  1978. outs("\n\t{\n");
  1979. outs("\t};");
  1980. }
  1981. outs("\n};\n");
  1982. }
  1983. void ProcInfo::write_body_popparam(int swapp)
  1984. {
  1985. outs("\tvoid popparams(HRPCbuffer &_b)\n\t{\n");
  1986. if (lastin) {
  1987. outf("\t\t_b.read(&%s,",firstin->name);
  1988. write_head_size();
  1989. outs(");\n");
  1990. }
  1991. int needensure=0;
  1992. ParamInfo *p;
  1993. ForEachParam(this,p,PF_OUT,PF_IN|PF_SIMPLE) {
  1994. if (needensure) {
  1995. outs("\t\t\t+");
  1996. }
  1997. else {
  1998. outs("\t\t_b.ensure(\n");
  1999. outs("\t\t\t");
  2000. needensure = 1;
  2001. }
  2002. if ((p->flags&PF_VARSIZE)&&!(INDIRECTSIZE(p))) {
  2003. outf("(%s)\n",p->bytesize());
  2004. }
  2005. else {
  2006. outf("sizeof(*%s)\n",p->name);
  2007. }
  2008. }
  2009. if (needensure) {
  2010. outs("\t\t);\n");
  2011. }
  2012. ForEachParam(this,p,PF_OUT,PF_IN|PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2013. outf("\t\t%s = ",p->name);
  2014. p->write_param_convert();
  2015. outf("_b.writeptr(sizeof(*%s));\n",p->name);
  2016. }
  2017. ForEachParam(this,p,PF_OUT|PF_STRING,0) {
  2018. outf("\t\t%s = ",p->name);
  2019. p->write_param_convert();
  2020. outf("_b.writeptr(sizeof(*%s));\n",p->name);
  2021. outf("\t\t*%s = 0;\n",p->name);
  2022. }
  2023. ForEachParam(this,p,PF_IN,PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2024. outf("\t\t%s = ",p->name);
  2025. p->write_param_convert();
  2026. outf("_b.readptr(sizeof(*%s));\n",p->name);
  2027. outf("\t\t\t//_b.readptrrev(sizeof(*%s));\n",p->name);
  2028. }
  2029. ForEachParam(this,p,PF_IN|PF_STRING,PF_SIMPLE|PF_VARSIZE) {
  2030. outf("\t\t%s = _b.readstrptr();\n",p->name);
  2031. }
  2032. // now dynamic sizes
  2033. ForEachParam(this,p,PF_VARSIZE|PF_IN,0) {
  2034. outf("\t\t%s = ",p->name);
  2035. p->write_param_convert();
  2036. if (INDIRECTSIZE(p)) {
  2037. // should handle size_t* as well as ref
  2038. outs("_b.readptr(sizeof");
  2039. p->write_param_convert();
  2040. outs(")\n");
  2041. }
  2042. else {
  2043. outf("_b.readptr(%s);\n",p->bytesize());
  2044. }
  2045. }
  2046. ForEachParam(this,p,PF_OUT|PF_VARSIZE,PF_IN|PF_SIMPLE) {
  2047. outf("\t\t%s = ",p->name);
  2048. p->write_param_convert();
  2049. outs("_b.writeptr(");
  2050. if ((p->flags&PF_VARSIZE)&&!(INDIRECTSIZE(p))) {
  2051. outf("%s);\n",p->bytesize());
  2052. }
  2053. else {
  2054. outf("sizeof(*%s));\n",p->name);
  2055. }
  2056. }
  2057. if (swapp)
  2058. outs("\t\t//swapparams();\n");
  2059. outs("\t}\n\n");
  2060. }
  2061. void ProcInfo::write_body_popreturn()
  2062. {
  2063. if (!async) {
  2064. outs("\tvoid popreturn(HRPCbuffer &_b)\n\t{\n");
  2065. ParamInfo *p;
  2066. ForEachParam(this,p,PF_OUT,PF_SIMPLE|PF_VARSIZE|PF_RETURN|PF_STRING) {
  2067. outf("\t\t_b.read(%s,sizeof(*%s));\n",p->name,p->name);
  2068. }
  2069. ForEachParam(this,p,PF_OUT|PF_STRING,0) {
  2070. outf("\t\t*%s = _b.readstrdup();\n",p->name);
  2071. }
  2072. // now dynamic sizes
  2073. ForEachParam(this,p,PF_VARSIZE|PF_OUT,0) {
  2074. if (INDIRECTSIZE(p)) {
  2075. outf("\t\t*%s = ",p->name);
  2076. p->write_param_convert(1);
  2077. outf("malloc(%s);\n",p->bytesize(1));
  2078. outf("\t\t_b.read(*%s,%s);\n",p->name,p->bytesize(1));
  2079. }
  2080. else {
  2081. outf("\t\t_b.read(%s,%s);\n",p->name,p->bytesize());
  2082. }
  2083. }
  2084. p = rettype;
  2085. if (p) {
  2086. if ((p->flags&(PF_PTR|PF_STRING))==(PF_PTR|PF_STRING)) {
  2087. outf("\t\t%s = _b.readstrdup();\n",p->name);
  2088. }
  2089. else if (p->flags&PF_PTR) {
  2090. outf("\t\t%s = ",p->name);
  2091. p->write_param_convert();
  2092. outf("malloc(%s);\n",p->bytesize(1));
  2093. outf("\t\t_b.read(%s,%s);\n",p->name,p->bytesize(1));
  2094. }
  2095. else {
  2096. outf("\t\t_b.read(&%s,sizeof(%s));\n",p->name,p->name);
  2097. }
  2098. }
  2099. outs("\t}\n\n");
  2100. }
  2101. }
  2102. int ProcInfo::write_body_swapparam()
  2103. {
  2104. int ret=0;
  2105. ParamInfo *p;
  2106. ForEachParam(this,p,PF_IN|PF_SIMPLE,PF_VARSIZE|PF_STRING) {
  2107. if(p->simpleneedsswap()) {
  2108. if (!ret) {
  2109. outs("\tvoid swapparams()\n\t{\n");
  2110. ret = 1;
  2111. }
  2112. outf("\t\t_WINREV%d(%s);\n",type_size[p->kind],p->name);
  2113. }
  2114. }
  2115. if (ret)
  2116. outs("\t}\n\n");
  2117. return ret;
  2118. }
  2119. void ProcInfo::write_body_pushparam(int swapp)
  2120. {
  2121. outs("\tvoid pushparams(HRPCbuffer &_b)\n\t{\n");
  2122. if (swapp)
  2123. outs("\t\t//swapparams();\n");
  2124. if (lastin) {
  2125. outf("\t\t_b.write(&%s,",firstin->name);
  2126. write_head_size();
  2127. outs(");\n");
  2128. }
  2129. ParamInfo *p;
  2130. ForEachParam(this,p,PF_IN,PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2131. if (p->simpleneedsswap()) {
  2132. outf("\t\t//_b.writerev(%s,sizeof(*%s));\n",p->name,p->name);
  2133. outf("\t\t_b.write(%s,sizeof(*%s));\n",p->name,p->name);
  2134. }
  2135. else
  2136. outf("\t\t_b.write(%s,sizeof(*%s));\n",p->name,p->name);
  2137. }
  2138. ForEachParam(this,p,PF_IN|PF_STRING,PF_SIMPLE|PF_VARSIZE) {
  2139. outf("\t\t_b.writestr(%s);\n",p->name);
  2140. }
  2141. // now dynamic sizes
  2142. ForEachParam(this,p,PF_VARSIZE|PF_IN,0) {
  2143. if (INDIRECTSIZE(p)) {
  2144. // should handle size_t* as well as ref
  2145. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize());
  2146. }
  2147. else {
  2148. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize());
  2149. }
  2150. }
  2151. outs("\t}\n\n");
  2152. }
  2153. void ProcInfo::write_body_pushreturn()
  2154. {
  2155. if (!async) {
  2156. outs("\tvoid pushreturn(HRPCbuffer &_b)\n\t{\n");
  2157. ParamInfo *p;
  2158. ForEachParam(this,p,PF_OUT,PF_SIMPLE|PF_VARSIZE|PF_STRING) {
  2159. outf("\t\t_b.write(%s,sizeof(*%s));\n",p->name,p->name);
  2160. }
  2161. ForEachParam(this,p,PF_OUT|PF_STRING,0) {
  2162. outf("\t\t_b.writestr(*%s);\n",p->name);
  2163. outf("\t\tfree(*%s);\n",p->name);
  2164. }
  2165. // now dynamic sizes
  2166. ForEachParam(this,p,PF_VARSIZE|PF_OUT,0) {
  2167. if (INDIRECTSIZE(p)) {
  2168. // should handle size_t* as well as ref
  2169. outf("\t\t_b.write(*%s,%s);\n",p->name,p->bytesize(1));
  2170. outf("\t\tfree(*%s);\n",p->name);
  2171. }
  2172. else {
  2173. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize());
  2174. }
  2175. }
  2176. p = rettype;
  2177. if (p) {
  2178. if ((p->flags&(PF_PTR|PF_STRING))==(PF_PTR|PF_STRING)) {
  2179. outf("\t\t_b.writestr(%s);\n",p->name);
  2180. outf("\t\tfree(%s);\n",p->name);
  2181. }
  2182. else if (p->flags&PF_PTR) {
  2183. outf("\t\t_b.write(%s,%s);\n",p->name,p->bytesize(1));
  2184. outf("\t\tfree(%s);\n",p->name);
  2185. }
  2186. else {
  2187. outf("\t\t_b.write(&%s,sizeof(%s));\n",p->name,p->name);
  2188. }
  2189. }
  2190. outs("\t}\n\n");
  2191. }
  2192. }
  2193. void ProcInfo::write_head_size()
  2194. // used for simple types only at the head of the packet
  2195. {
  2196. if (lastin) {
  2197. char sz[2048];
  2198. sz[0] = 0;
  2199. size_t sza=0;
  2200. ParamInfo *p=params;
  2201. ParamInfo *lp=NULL;
  2202. while (1) {
  2203. if (p->flags&PF_SIMPLE) {
  2204. lp = p;
  2205. }
  2206. if(p==lastin)
  2207. break;
  2208. p = p->next;
  2209. }
  2210. if (lp==NULL)
  2211. outs("0");
  2212. else if (lp!=firstin)
  2213. outf("sizeof(%s)+(byte *)&%s-(byte *)&%s",lp->name,lp->name,firstin->name);
  2214. else
  2215. outf("sizeof(%s)",firstin->name);
  2216. }
  2217. else
  2218. outs("0");
  2219. }
  2220. //-------------------------------------------------------------------------------------------------------------
  2221. // class ApiInfo
  2222. ApiInfo::ApiInfo(const char *n)
  2223. {
  2224. name = NULL;
  2225. group = strdup(n);
  2226. proc = NULL;
  2227. next = NULL;
  2228. }
  2229. ApiInfo::~ApiInfo()
  2230. {
  2231. if (name)
  2232. free(name);
  2233. if (proc)
  2234. delete proc;
  2235. if (group)
  2236. free(group);
  2237. delete next;
  2238. }
  2239. void ApiInfo::write_header_method()
  2240. {
  2241. ProcInfo *pi = proc;
  2242. if (!pi->callback)
  2243. {
  2244. outf("extern \"C\" %s_API ", group);
  2245. pi->rettype->out_type();
  2246. outf(" %s", pi->name);
  2247. pi->out_parameter_list("");
  2248. outs(";\n");
  2249. }
  2250. }
  2251. void ApiInfo::write_clarion_include_method()
  2252. {
  2253. ProcInfo *pi = proc;
  2254. if (!pi->callback)
  2255. {
  2256. outf(" %s ",xlat(pi->name));
  2257. pi->out_clarion_parameter_list();
  2258. if (pi->rettype)
  2259. {
  2260. outs(",");
  2261. pi->rettype->out_clarion_type(true);
  2262. }
  2263. ParamInfo *pa;
  2264. unsigned sizeOfParms=0;
  2265. ForEachParam(pi, pa, 0, 0)
  2266. {
  2267. if (pa->flags&(PF_PTR|PF_REF))
  2268. sizeOfParms+=4;
  2269. else
  2270. sizeOfParms+=type_size[pa->kind];
  2271. }
  2272. outf(", pascal, raw, name('_%s@%d')\n", pi->name,sizeOfParms);
  2273. }
  2274. }
  2275. //-------------------------------------------------------------------------------------------------------------
  2276. // class ModuleInfo
  2277. ModuleInfo::ModuleInfo(const char *n)
  2278. {
  2279. name = strdup(n);
  2280. base = NULL;
  2281. version = 0;
  2282. procs = NULL;
  2283. next = NULL;
  2284. isSCMinterface=false;
  2285. }
  2286. ModuleInfo::~ModuleInfo()
  2287. {
  2288. free(name);
  2289. if (base)
  2290. free(base);
  2291. delete procs;
  2292. delete next;
  2293. }
  2294. void ModuleInfo::write_body_class()
  2295. {
  2296. outf("// class %s \n\n",name);
  2297. outf("static struct HRPCmoduleid _id_%s = { { ",name);
  2298. char *mn = name;
  2299. for (int i=0;i<8;i++)
  2300. {
  2301. if (i)
  2302. outs(", ");
  2303. if (*mn) {
  2304. outf("'%c'",*mn);
  2305. mn++;
  2306. }
  2307. else
  2308. outs("0");
  2309. }
  2310. outf("}, %d };\n\n",version);
  2311. int fn=0;
  2312. for (ProcInfo *pi=procs; pi; pi=pi->next)
  2313. {
  2314. fn++;
  2315. pi->write_body_method_structs2(name);
  2316. }
  2317. outs("\n");
  2318. outf("%s::%s() { _id = &_id_%s; }\n\n",name,name,name);
  2319. outf("#ifdef LOCAL_%s // Stub(%s):\n\n",name,name);
  2320. write_body_class_stub(0);
  2321. write_body_class_proxy(1);
  2322. outf("#else // Proxy(%s):\n\n",name);
  2323. write_body_class_proxy(0);
  2324. write_body_class_stub(1);
  2325. outf("\n#endif // end class %s\n",name);
  2326. }
  2327. void ModuleInfo::write_body_class_proxy(int cb)
  2328. {
  2329. int fn = 0;
  2330. ProcInfo *pi;
  2331. for (pi=procs; pi; pi=pi->next) {
  2332. fn++;
  2333. if (cb!=pi->callback)
  2334. continue;
  2335. pi->out_method(name,true);
  2336. outs("\n{\n");
  2337. if (pi->callback) {
  2338. outs("\tHRPCcallframe _callframe(&_server->Sync(),cbbuff);\n");
  2339. }
  2340. else {
  2341. outs("\tHRPCcallframe _callframe(sync,inbuff);\n");
  2342. }
  2343. outf("\tHRPC_d_%s__%s _params",name,pi->name);
  2344. if (pi->params) {
  2345. outs("(");
  2346. ParamInfo *p;
  2347. ForEachParam(pi,p,0,0) {
  2348. outf("%s",p->name);
  2349. if (p->next)
  2350. outs(", ");
  2351. }
  2352. outs(")");
  2353. }
  2354. outs(";\n");
  2355. if (pi->conntimeout&&*pi->conntimeout) {
  2356. outf("\tTryConnect(%s,false);\n",pi->conntimeout);
  2357. }
  2358. if (pi->calltimeout&&*pi->calltimeout) {
  2359. outf("\tSetCallTimeLimit(%s);\n",pi->calltimeout);
  2360. }
  2361. if (pi->callback) {
  2362. outs("\t_params.pushparams(cbbuff);\n");
  2363. outf("\t_callbackproxy(_callframe,%d);\n",fn);
  2364. if (!pi->async)
  2365. outs("\t_params.popreturn(cbbuff);\n");
  2366. }
  2367. else {
  2368. outs("\t_params.pushparams(inbuff);\n");
  2369. outf("\t_proxy(_callframe,%d);\n",fn);
  2370. if (!pi->async)
  2371. outs("\t_params.popreturn(inbuff);\n");
  2372. }
  2373. if (pi->rettype) {
  2374. outf("\treturn _params.%s;\n",RETURNNAME);
  2375. }
  2376. outs("}\n\n");
  2377. }
  2378. outs("\n\n");
  2379. }
  2380. void ModuleInfo::write_body_class_stub(int cb)
  2381. {
  2382. outf("void %s::_%sstub(HRPCbuffer &_b,HRPCbuffer &_br,int fn)\n{\n",name,cb?"callback":"");
  2383. int fn=0;
  2384. int switchdone = 0;
  2385. ProcInfo *pi;
  2386. for (pi=procs; pi; pi=pi->next) {
  2387. fn++;
  2388. if (cb!=pi->callback)
  2389. continue;
  2390. if (!switchdone) {
  2391. outs("\tswitch(fn) {\n");
  2392. switchdone = 1;
  2393. }
  2394. outf("\tcase %d: {\n",fn);
  2395. outf("\t\t\tHRPC_d_%s__%s _params;\n",name,pi->name,name,pi->name);
  2396. outs("\t\t\t_params.popparams(_b);\n");
  2397. if (pi->async) {
  2398. outs("\t\t\t_returnasync(_br);\n");
  2399. }
  2400. outs("\t\t\t");
  2401. if (pi->rettype) {
  2402. outf("_params.%s = ",RETURNNAME);
  2403. }
  2404. outf("%s(",pi->name);
  2405. ParamInfo *p;
  2406. ForEachParam(pi,p,0,0) {
  2407. if (p->flags&PF_REF)
  2408. outs("*");
  2409. outf("_params.%s",p->name);
  2410. if (p->next)
  2411. outs(", ");
  2412. }
  2413. outs(");\n");
  2414. if (!pi->async) {
  2415. outs("\t\t\t_returnOK(_br);\n");
  2416. outs("\t\t\t_params.pushreturn(_br);\n");
  2417. }
  2418. outs("\t\t\tbreak;\n");
  2419. outs("\t\t}\n");
  2420. }
  2421. if (switchdone) {
  2422. outs("\t}\n");
  2423. }
  2424. outs("}\n\n");
  2425. }
  2426. void ModuleInfo::write_clarion_include_module()
  2427. {
  2428. if (isSCM) {
  2429. char _name[256];
  2430. toClaInterface(_name, name);
  2431. if (base) {
  2432. char _base[256];
  2433. toClaInterface(_base, base);
  2434. outf("%s INTERFACE(%s),COM\n", _name, _base);
  2435. }
  2436. else
  2437. outf("%s INTERFACE,COM\n", _name);
  2438. }
  2439. else
  2440. outf("HRPCI_%s INTERFACE(HRPCI_Clarion_Module)\n",name);
  2441. ProcInfo *pi;
  2442. for (pi=procs; pi; pi=pi->next) {
  2443. if (pi->callback)
  2444. continue;
  2445. outf("%-15s PROCEDURE",xlat(pi->name));
  2446. pi->out_clarion_parameter_list();
  2447. if (pi->rettype) {
  2448. outs(",");
  2449. pi->rettype->out_clarion_type(true);
  2450. }
  2451. if (isSCM)
  2452. outs(",PROC\n");
  2453. else
  2454. outs(",PASCAL\n");
  2455. }
  2456. outs("END\n\n");
  2457. }
  2458. void ModuleInfo::write_clarion_scm_stub_class()
  2459. {
  2460. outf("// clarion interface stub for %s \n",name);
  2461. outf("class SCMCLWSTUB_%s: public SCMStubBase, implements %s // interface\n",name,name);
  2462. outf("\t%s &_o;\n",name);
  2463. outf("public:\n");
  2464. outf("\tIMPLEMENT_SCMSTUBBASE\n");
  2465. outf("\tSCMCLW_%s(%s *_if) : SCMStubBase(_if), _o(*LINK(_if)) { } \n",name,name);
  2466. outf("\t~SCMCLW_%s() { _o.Release(); } \n",name);
  2467. ProcInfo *pi;
  2468. for (pi=procs; pi; pi=pi->next) {
  2469. if (pi->callback)
  2470. continue;
  2471. outs("\t");
  2472. if (pi->rettype==NULL)
  2473. {
  2474. outs("void");
  2475. }
  2476. else
  2477. pi->rettype->out_type();
  2478. outf(" _stdcall %s",pi->name);
  2479. pi->out_parameter_list("",1);
  2480. outs("\n");
  2481. outs("\t{\n");
  2482. outs("\t\tSCMCLW_INTRO;\n");
  2483. outf("#ifdef SCMCLW_INTRO_%s_%s;\n",name,pi->name);
  2484. outf("\t\tSCMCLW_INTRO_%s_%s;\n",name,pi->name);
  2485. outs("#endif\n");
  2486. if (pi->rettype) {
  2487. outs("\t");
  2488. pi->rettype->write_body_struct_elem(0);
  2489. outs("\t\t_return = ");
  2490. }
  2491. else
  2492. outs("\t\t");
  2493. outf("_o.%s(",pi->name);
  2494. ParamInfo *p;
  2495. ForEachParam(pi,p,0,0) {
  2496. outf("%s",p->name);
  2497. if (p->next)
  2498. outs(", ");
  2499. }
  2500. outs(");\n");
  2501. outf("#ifdef SCMCLW_OUTRO_%s_%s;\n",name,pi->name);
  2502. outf("\t\tSCMCLW_OUTRO_%s_%s;\n",name,pi->name);
  2503. outs("#endif\n");
  2504. outs("\t\tSCMCLW_OUTRO;\n");
  2505. if (pi->rettype) {
  2506. outs("\t\treturn _return;");
  2507. }
  2508. outs("\t}\n");
  2509. }
  2510. outs("};\n");
  2511. }
  2512. void ModuleInfo::write_clarion_interface_class()
  2513. {
  2514. outs("extern \"C\" {\n\n");
  2515. outs("\n");
  2516. outf("// clarion interface class CIC_%s \n",name);
  2517. outf("struct HRPCI_%s: public HRPCI_Clarion_Module // interface\n",name);
  2518. ProcInfo *pi;
  2519. outs("{\n");
  2520. for (pi=procs; pi; pi=pi->next) {
  2521. if (pi->callback)
  2522. continue;
  2523. outs("\tvirtual ");
  2524. if (pi->rettype==NULL)
  2525. {
  2526. outs("void");
  2527. }
  2528. else
  2529. pi->rettype->out_type();
  2530. outf(" _stdcall %s",pi->name);
  2531. pi->out_parameter_list("",1);
  2532. outs("=0;\n");
  2533. }
  2534. outs("};\n");
  2535. outf("#ifndef LOCAL_%s\n\n",name);
  2536. outf("class CIC_%s : public HRPCI_%s\n",name,name);
  2537. outs("{\n");
  2538. outs("public:\n");
  2539. outf("\t%s _o;\n",name);
  2540. outs("\tunsigned xxcount;\n");
  2541. for (pi=procs; pi; pi=pi->next) {
  2542. if (pi->callback)
  2543. continue;
  2544. outs("\t");
  2545. if (pi->rettype==NULL)
  2546. {
  2547. outs("void");
  2548. }
  2549. else
  2550. pi->rettype->out_type();
  2551. outf(" _stdcall %s",pi->name);
  2552. pi->out_parameter_list("",1);
  2553. outs("\n");
  2554. outs("\t{\n");
  2555. outs("\t\t");
  2556. if (pi->rettype) {
  2557. outs("return ");
  2558. }
  2559. outf("_o.%s(",pi->name);
  2560. ParamInfo *p;
  2561. ForEachParam(pi,p,0,0) {
  2562. outf("%s",p->name);
  2563. if (p->next)
  2564. outs(", ");
  2565. }
  2566. outs(");\n");
  2567. outs("\t}\n");
  2568. }
  2569. outf("\tCIC_%s() { xxcount = 0; }\n",name);
  2570. outf("\tvoid _stdcall Link() const { ++const_cast<CIC_%s*>(this)->xxcount; }\n", name);
  2571. 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);
  2572. outs("\tvoid _stdcall FreeMem(void *p) { free(p); }\n");
  2573. outs("};\n");
  2574. outf("CIC_%s* PASCAL HRPC_Make_%s(HRPCI_Clarion_Transport *t)\n",name,name);
  2575. outs("{\n");
  2576. outf("\tCIC_%s *ret=new CIC_%s;\n",name,name);
  2577. outs("\tret->_o.UseTransport(t->GetTransport());\n");
  2578. outs("\treturn ret;\n");
  2579. outs("}\n");
  2580. outs("#endif\n");
  2581. outs("}\n");
  2582. }
  2583. void ModuleInfo::write_define()
  2584. {
  2585. outf("#define LOCAL_%s // implementation of %s\n",name,name);
  2586. }
  2587. void ModuleInfo::write_example_module()
  2588. {
  2589. outf("void %s_Server()\n",name);
  2590. outs("{\n");
  2591. outs("\tHRPCserver server(MakeTcpTransport(NULL,PORTNO)); // PORTNO TBD\n");
  2592. outf("\t%s stub;\n",name);
  2593. outs("\tserver.AttachStub(&stub); // NB a server can service more than one module\n");
  2594. outs("\tserver.Listen();\n");
  2595. outs("}\n\n");
  2596. ProcInfo *pi;
  2597. for (pi=procs; pi; pi=pi->next) {
  2598. pi->out_method(name,true);
  2599. outs("\n{\n");
  2600. outf("\t // TBD\n");
  2601. if (pi->rettype) {
  2602. outs("\treturn TBD;\n");
  2603. }
  2604. outs("}\n\n");
  2605. }
  2606. }
  2607. void ModuleInfo::write_header_class()
  2608. {
  2609. int hasvirts = 0;
  2610. ProcInfo *pi;
  2611. for (pi=procs; pi; pi=pi->next) {
  2612. if (pi->virt) {
  2613. hasvirts = 1;
  2614. break;
  2615. }
  2616. }
  2617. if (isSCM) {
  2618. if (base)
  2619. outf("interface %s : extends %s\n",name,base);
  2620. else
  2621. outf("interface %s\n",name);
  2622. outs("{\n");
  2623. for (pi=procs; pi; pi=pi->next) {
  2624. outs("\t");
  2625. pi->out_method();
  2626. outs(";\n");
  2627. }
  2628. outs("};\n");
  2629. }
  2630. else {
  2631. outf("#ifdef LOCAL_%s\n",name);
  2632. outf("#define %s STUB_%s\n",name,name);
  2633. if (hasvirts) {
  2634. outs("#define HRPCvirtual virtual\n");
  2635. outs("#define HRPCpure =0\n");
  2636. outs("#define HRPCvirtualcallback\n");
  2637. outs("#define HRPCpurecallback\n");
  2638. }
  2639. outf("class %s : public HRPCstub\n",name);
  2640. outs("#else\n");
  2641. if (hasvirts) {
  2642. outs("#define HRPCvirtual\n");
  2643. outs("#define HRPCpure\n");
  2644. outs("#define HRPCvirtualcallback virtual\n");
  2645. outs("#define HRPCpurecallback =0\n");
  2646. }
  2647. outf("class %s : public HRPCmodule\n",name);
  2648. outs("#endif\n");
  2649. outs("{\npublic:\n");
  2650. outf("\t%s();\n",name);
  2651. for (pi=procs; pi; pi=pi->next) {
  2652. outs("\t");
  2653. pi->out_method();
  2654. outs(";\n");
  2655. }
  2656. outf("private:\n");
  2657. outf("#ifdef LOCAL_%s\n",name);
  2658. outf("\tvoid _stub(HRPCbuffer &_b,HRPCbuffer &_rb,int fn);\n");
  2659. outs("#else\n");
  2660. outf("\tvoid _callbackstub(HRPCbuffer &_b,HRPCbuffer &_rb,int fn);\n");
  2661. outs("#endif\n");
  2662. if (hasvirts) {
  2663. outs("#undef HRPCvirtual\n");
  2664. outs("#undef HRPCpure\n");
  2665. outs("#undef HRPCvirtualcallback\n");
  2666. outs("#undef HRPCpurecallback\n");
  2667. }
  2668. outs("};\n");
  2669. }
  2670. }
  2671. //-------------------------------------------------------------------------------------------------------------
  2672. // class EspMessageInfo
  2673. void EspMessageInfo::write_esp_ipp()
  2674. {
  2675. ParamInfo *pi;
  2676. const char *parent = getParentName();
  2677. if (espm_type_ == espm_enum)
  2678. {
  2679. //const char* defaultValue = getParams()->getMetaString("enum",NULL); // first enum item
  2680. outf("class CX%s : public SoapEnumParamNew<C%s>\n",name_,name_);
  2681. outf("{\n");
  2682. outs("public:\n");
  2683. outf("\tCX%s(nilBehavior nilB) : SoapEnumParamNew<C%s>(nilB)\n", name_, name_);
  2684. outf("\t{ doInit(); }\n");
  2685. outf("\tCX%s(C%s defvalue_) : SoapEnumParamNew<C%s>(defvalue_)\n", name_, name_, name_);
  2686. outf("\t{ doInit(); }\n");
  2687. outf("\tCX%s(const char* defvalue_) : SoapEnumParamNew<C%s>()\n", name_, name_, name_);
  2688. outf("\t{ doInit(); setDefaultValue(defvalue_); }\n");
  2689. // getXsdDefinition
  2690. outs("\tstatic void getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &schema, BoolHash &added)\n");
  2691. outs("\t{ getSharedInstance().getXsdDefinitionInternal(context,request,schema,added); }\n");
  2692. // getMapInfo()
  2693. outs("\tstatic void getMapInfo(IMapInfo& info, BoolHash& added) { getSharedInstance().getMapInfo_(info,added); }\n\n");
  2694. outf("\tstatic const char* stringOf(C%s val) { return getSharedInstance().toString(val); }\n\n",name_);
  2695. outf("\tstatic C%s enumOf(const char* s) { return getSharedInstance().toEnum(s); }\n\n",name_, name_);
  2696. outf("static const char *queryXsdElementName() { return \"%s\"; }\n", name_);
  2697. // internal: getSharedInstance()
  2698. outs("private:\n");
  2699. outf("\tstatic CX%s& getSharedInstance() { static CX%s instance(nilIgnore); return instance; }\n", name_, name_);
  2700. // TODO: getMapInfo_() internal implementation
  2701. outs("\tvoid getMapInfo_(IMapInfo& info, BoolHash& added) { }\n");
  2702. // handle descriptions
  2703. {
  2704. outs("\tvoid getXsdDefinitionInternal(IEspContext &context, CHttpRequest* request, StringBuffer &schema, BoolHash &added)\n");
  2705. bool hasDesc = false;
  2706. for (pi = getParams(); pi!=NULL; pi=pi->next)
  2707. {
  2708. const char* desc = pi->getMetaString("desc",NULL);
  2709. if (desc) { hasDesc = true; break; }
  2710. }
  2711. if (hasDesc)
  2712. {
  2713. outs("\t{\n\t\tconst char* descriptions [] = {");
  2714. for (pi = getParams(); pi!=NULL; pi=pi->next)
  2715. {
  2716. const char* desc = pi->getMetaString("desc",NULL);
  2717. outf("%s,", desc ? desc : "NULL");
  2718. }
  2719. outs("};\n");
  2720. outs("\t\tgetXsdDefinition_(context,request,schema,added,descriptions);\n\t}\n");
  2721. }
  2722. else
  2723. outf("\t{ getXsdDefinition_(context,request,schema,added,NULL); }\n");
  2724. }
  2725. outf("\tvoid doInit()\n");
  2726. outs("\t{\n");
  2727. outs("\t\tstatic const char* inits[] = {");
  2728. for (pi = getParams(); pi!=NULL; pi=pi->next)
  2729. {
  2730. if (strcmp(parent,"string")==0)
  2731. {
  2732. const char* def = pi->getMetaString("enum",NULL);
  2733. outf("%s", def);
  2734. }
  2735. else if (strcmp(parent,"int")==0 || strcmp(parent,"short")==0)
  2736. {
  2737. int def = pi->getMetaInt("enum");
  2738. outf("\"%d\"",def);
  2739. }
  2740. else if (strcmp(parent,"double")==0 || strcmp(parent,"float")==0)
  2741. {
  2742. double def = pi->getMetaDouble("enum");
  2743. outf("\"%g\"",def);
  2744. }
  2745. else
  2746. throw "Unhandled base type";
  2747. outs(",");
  2748. }
  2749. outs("NULL};\n");
  2750. outf("\t\tinit(\"%s\",\"%s\",inits);\n",name_,parent);
  2751. outs("\t}\n");
  2752. outs("};\n\n");
  2753. // array
  2754. /*
  2755. //outf("MAKEValueArray(C%s, %sArray);\n\n", name_, name_);
  2756. outf("inline C%s Array__Member2Param(C%s &src) { return src; }\n", name_, name_);
  2757. outf("inline void Array__Assign(C%s & dest, C%s const & src){ dest = src; }\n", name_, name_);
  2758. outf("inline bool Array__Equal(C%s const & m, C%s const p) { return m==p; }\n", name_, name_);
  2759. outf("inline void Array__Destroy(C%s & /*next* /) { }\n", name_);
  2760. //outf("MAKECopyArrayOf(simple, simple, array)
  2761. outf("MAKEArrayOf(C%s, C%s, %sArray)\n\n", name_,name_,name_);
  2762. //outf("class %sArray : public ArrayOf<C%s, C%s> {};\n\n",name_,name_,name_);
  2763. outs("\n");
  2764. */
  2765. return;
  2766. }
  2767. ParamInfo *contentVar=NULL;
  2768. bool removeNil=(getMetaInt("nil_remove", 0)!=0);
  2769. for (pi=getParams();pi!=NULL;pi=pi->next)
  2770. {
  2771. if (pi->getMetaString("http_content", NULL)!=NULL)
  2772. {
  2773. contentVar=pi;
  2774. break;
  2775. }
  2776. }
  2777. const char *baseclass = parent;
  2778. if (!baseclass)
  2779. {
  2780. switch(espm_type_)
  2781. {
  2782. case espm_struct:
  2783. baseclass="SoapComplexType";
  2784. break;
  2785. case espm_request:
  2786. baseclass="SoapRequestBinding";
  2787. break;
  2788. default:
  2789. baseclass="SoapResponseBinding";
  2790. break;
  2791. }
  2792. }
  2793. outf("class C%s : public C%s,\n", name_, baseclass);
  2794. outf(" implements IEsp%s,\n", name_);
  2795. outf(" implements IClient%s\n", name_);
  2796. outs("{\n");
  2797. outs("protected:\n");
  2798. for (pi=getParams();pi!=NULL;pi=pi->next)
  2799. {
  2800. pi->write_esp_declaration();
  2801. }
  2802. if (getMetaInt("element")!=0)
  2803. outs(1, "StringBuffer m_tag_value;\n");
  2804. if (contentVar!=NULL)
  2805. outf("\tStringBuffer m_%s_mimetype;\n", contentVar->name);
  2806. outs("\n\tvoid *m_eventSink;\n");
  2807. outs("\n\tIInterface* m_RequestState;\n");
  2808. outs("\tStringBuffer m_serviceName;\n");
  2809. outs("\tStringBuffer m_methodName;\n");
  2810. outs("\tStringBuffer m_msgName;\n");
  2811. outs("\n\tlong m_reqId;\n");
  2812. outs("\tMutex m_mutex;\n");
  2813. outs("public:\n");
  2814. outs("\tIMPLEMENT_IINTERFACE;\n");
  2815. //default constructor
  2816. outf("\n\tC%s(const char *serviceName, const char *bcompat);\n", name_);
  2817. outf("\n\tC%s(const char *serviceName, IRpcMessageBinding *init=NULL);", name_);
  2818. if (espm_type_==espm_struct)
  2819. {
  2820. //Raw message constructor
  2821. //outf("\n\tC%s(const char *serviceName, const char * msg);", name_);
  2822. }
  2823. else
  2824. {
  2825. //rpc message constructor
  2826. outf("\n\tC%s(const char *serviceName, IRpcMessage* rpcmsg);", name_);
  2827. //IProperties constructor
  2828. outf("\n\tC%s(IEspContext* ctx, const char *serviceName, IProperties *params, MapStrToBuf *attachments);", name_);
  2829. }
  2830. outs("\n\tvoid setMsgName(const char *msgname)\n");
  2831. outs("\t{\n");
  2832. outs("\t\tm_msgName.set(msgname);\n");
  2833. outs("\t}\n\n");
  2834. outs("\tstatic const char *queryXsdElementName()\n");
  2835. outs("\t{\n");
  2836. outf("\t\treturn \"%s\";\n", name_);
  2837. outs("\t}\n\n");
  2838. //method ==> getXsdDefinition
  2839. outs("\tstatic StringBuffer &getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &schema, BoolHash&added, const char *xns=\"xsd\", const char *wsns=\"tns\", unsigned flags=1)\n");
  2840. outs("\t{\n");
  2841. outs("\t\treturn getXsdDefinition(context, request, queryXsdElementName(), schema, added, xns, wsns, flags);\n");
  2842. outs("\t}\n");
  2843. //method ==> getXsdDefinition
  2844. 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");
  2845. //method ==> getMapInfo
  2846. outs("\tstatic void getMapInfo(IMapInfo& info);\n");
  2847. outs("\tstatic void getMapInfo(IMapInfo& info, BoolHash& added);\n");
  2848. //method ==> getHtmlForm
  2849. outs("\tstatic StringBuffer &getHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &form, bool includeFormTag=true, const char *prefix=NULL);\n");
  2850. //method ==> hasCustomHttpContent
  2851. outs("\tstatic bool hasCustomHttpContent()\n");
  2852. outs("\t{\n");
  2853. if (contentVar)
  2854. outs("\t\treturn true;\n");
  2855. else
  2856. outs("\t\treturn false;\n");
  2857. outs("\t}\n");
  2858. //method ==> serializeHtml
  2859. outs("\tStringBuffer &serializeHtml(IEspContext &context, const char *serv, const char *method, StringBuffer &html);\n");
  2860. //method ==> serialize (IRpcMessage&)
  2861. outs("\n\tvoid serialize(IRpcMessage& rpc_resp);\n");
  2862. //method ==> copy
  2863. outf("\n\tvoid copy(C%s &from);\n", name_);
  2864. //method ==> copy from interface
  2865. outf("\n\tvoid copy(IConst%s &ifrom);\n", name_);
  2866. //method ==> serializeContent (StringBuffer&)
  2867. outs("\n\tvoid serializeContent(IEspContext* ctx, StringBuffer& buffer, IProperties **pprops=NULL);\n");
  2868. //method ==> serialize (StringBuffer&)
  2869. outs("\n\tvoid serialize(IEspContext* ctx, StringBuffer& buffer, const char *name=NULL);\n");
  2870. //method ==> serialize (StringBuffer&)
  2871. outf("\n\tstatic void serializer(IEspContext* ctx, IConst%s &ifrom, StringBuffer& buffer, bool keepRootTag=true);\n", name_);
  2872. //method ==> serialize (MemoryBuffer&, StringBuffer &)
  2873. outs("\n\tvoid serialize(IEspContext* ctx, MemoryBuffer& buffer, StringBuffer &mimetype);\n");
  2874. outs("\tvoid setEventSink(void * val){m_eventSink=val;}\n");
  2875. outs("\tvoid * getEventSink(){return m_eventSink;}\n");
  2876. outs("\tvoid setState(IInterface * val){m_RequestState = val;}\n");
  2877. outs("\tIInterface * queryState(){return m_RequestState;}\n");
  2878. outs("\tvoid setMethod(const char * method){m_methodName.set(method);}\n");
  2879. outs("\tconst char * getMethod(){return m_methodName.str();}\n\n");
  2880. outs("\tvoid setReqId(unsigned val){m_reqId=val;}\n");
  2881. outs("\tunsigned getReqId(){return m_reqId;}\n\n");
  2882. outs("\tvoid lock(){m_mutex.lock();}\n");
  2883. outs("\tvoid unlock(){m_mutex.unlock();}\n\n");
  2884. if (getMetaInt("element")!=0)
  2885. {
  2886. outs(1, "void set_tag_value(const char * value){m_tag_value.set(value);}\n");
  2887. outs(1, "const char * get_tag_value(){return m_tag_value.str();}\n\n");
  2888. }
  2889. outs("\n\tbool unserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath);\n");
  2890. if (parent)
  2891. {
  2892. outs("\n\tbool localUnserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath);\n");
  2893. outs("\n\tbool unserialize(IEspContext* ctx, CSoapValue& soapval, bool localOnly=false);\n");
  2894. outs("\n\tbool unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath=NULL, bool localOnly=false);\n");
  2895. }
  2896. else
  2897. {
  2898. outs("\n\tbool unserialize(IEspContext* ctx, CSoapValue& soapval);\n");
  2899. outs("\n\tbool unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath=NULL);\n");
  2900. }
  2901. //outs("\n\tvoid unserialize(const char * msg);\n");
  2902. if (espm_type_==espm_response)
  2903. {
  2904. outs("\n\tvirtual void setRedirectUrl(const char *url)\n");
  2905. outs("\t{ CSoapResponseBinding::setRedirectUrl(url); }\n");
  2906. outs("\n\tvirtual const IMultiException& getExceptions()\n");
  2907. outs("\t{ return CSoapResponseBinding::getExceptions(); }\n");
  2908. outs("\n\tvirtual int queryClientStatus()\n");
  2909. outs("\t{ return CSoapResponseBinding::getRpcState(); }\n");
  2910. outs("\n\tvirtual void noteException(IException& e)\n");
  2911. outs("\t{ CSoapResponseBinding::noteException(e); }\n");
  2912. }
  2913. outs("\n");
  2914. write_esp_methods(espaxm_both, true, false);
  2915. outs("};\n\n");
  2916. }
  2917. bool EspMessageInfo::hasMapInfo()
  2918. {
  2919. for (ParamInfo* pi=getParams();pi!=NULL;pi=pi->next)
  2920. if (pi->hasMapInfo())
  2921. return true;
  2922. return false;
  2923. }
  2924. void EspMessageInfo::write_esp()
  2925. {
  2926. if (espm_type_ == espm_enum)
  2927. return;
  2928. const char *parent=getParentName();
  2929. ParamInfo *contentVar=NULL;
  2930. ParamInfo *pi=NULL;
  2931. bool removeNil=(getMetaInt("nil_remove", 0)!=0);
  2932. for (pi=getParams();pi!=NULL;pi=pi->next)
  2933. {
  2934. if (pi->getMetaString("http_content", NULL)!=NULL)
  2935. {
  2936. contentVar=pi;
  2937. break;
  2938. }
  2939. }
  2940. //comment
  2941. outs("\n//=======================================================");
  2942. outf("\n// class C%s Implementation", name_);
  2943. outs("\n//=======================================================");
  2944. outs("\n");
  2945. //default constructor
  2946. outf("\nC%s::C%s(const char *serviceName, IRpcMessageBinding *init)", name_, name_);
  2947. bool isFirstInited=true;
  2948. if (parent)
  2949. {
  2950. outf(" : C%s(serviceName, init)", parent);
  2951. isFirstInited=false;
  2952. }
  2953. for (pi=getParams();pi!=NULL;pi=pi->next)
  2954. {
  2955. pi->write_esp_init(isFirstInited, removeNil);
  2956. }
  2957. if (contentVar)
  2958. {
  2959. outs((isFirstInited) ? "\n\t: " : ",");
  2960. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  2961. }
  2962. outs("\n{\n");
  2963. outs("\tm_eventSink=NULL;\n");
  2964. outs("\tm_RequestState=NULL;\n");
  2965. outs("\tm_serviceName.append(serviceName);\n");
  2966. outf("\tm_msgName.append(\"%s\");\n", name_);
  2967. outs("\tif (init)\n");
  2968. outs("\t{\n");
  2969. outs("\t\tsetClientValue(init->getClientValue());\n");
  2970. outs("\t\tsetReqId(init->getReqId());\n");
  2971. outs("\t\tsetEventSink(init->getEventSink());\n");
  2972. outs("\t\tsetState(init->queryState());\n");
  2973. outs("\t\tsetThunkHandle(init->getThunkHandle());\n");
  2974. outs("\t\tsetMethod(init->getMethod());\n");
  2975. outs("\t}\n");
  2976. outs("}\n");
  2977. outf("\nC%s::C%s(const char *serviceName, const char *bc)", name_, name_);
  2978. isFirstInited=true;
  2979. if (parent)
  2980. {
  2981. outf(" : C%s(serviceName)", parent);
  2982. isFirstInited=false;
  2983. }
  2984. for (pi=getParams();pi!=NULL;pi=pi->next)
  2985. {
  2986. pi->write_esp_init(isFirstInited, removeNil);
  2987. }
  2988. if (contentVar)
  2989. {
  2990. outs((isFirstInited) ? " : " : ", ");
  2991. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  2992. }
  2993. outs("\n{\n");
  2994. outs("\tm_eventSink=NULL;\n");
  2995. outs("\tm_RequestState=NULL;\n");
  2996. outs("\tm_serviceName.append(serviceName);\n");
  2997. outf("\tm_msgName.append(\"%s\");\n", name_);
  2998. outs("}\n");
  2999. if (espm_type_==espm_struct)
  3000. {
  3001. //Raw message constructor
  3002. /*
  3003. outf("\nC%s::C%s(const char *serviceName, const char * msg)", name_, name_);
  3004. isFirstInited=true;
  3005. if (parent)
  3006. {
  3007. outf(" : C%s(serviceName, msg)", parent);
  3008. isFirstInited=false;
  3009. }
  3010. for (pi=getParams();pi!=NULL;pi=pi->next)
  3011. {
  3012. pi->write_esp_init(isFirstInited, removeNil);
  3013. }
  3014. if (contentVar)
  3015. {
  3016. outs((isFirstInited) ? " : " : ", ");
  3017. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3018. }
  3019. outs("\n\t{\n\t\tm_eventSink=NULL;\n");
  3020. outs("\t\tm_RequestState=NULL;\n");
  3021. outs("\t\tm_serviceName.append(serviceName);\n");
  3022. outf("\t\tm_msgName.append(\"%s\");\n", name_);
  3023. outs("\t\tunserialize(msg);\n\t}\n");
  3024. */
  3025. }
  3026. else
  3027. {
  3028. //rpc message constructor
  3029. outf("\nC%s::C%s(const char *serviceName, IRpcMessage* rpcmsg)", name_, name_);
  3030. isFirstInited=true;
  3031. if (parent)
  3032. {
  3033. outf(" : C%s(serviceName, rpcmsg)", parent);
  3034. isFirstInited=false;
  3035. }
  3036. for (pi=getParams();pi!=NULL;pi=pi->next)
  3037. {
  3038. pi->write_esp_init(isFirstInited, removeNil);
  3039. }
  3040. if (contentVar)
  3041. {
  3042. outs((isFirstInited) ? " : " : ", ");
  3043. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3044. }
  3045. outs("\n{\n");
  3046. outs("\tm_eventSink=NULL;\n");
  3047. outs("\tm_RequestState=NULL;\n");
  3048. outs("\tm_serviceName.append(serviceName);\n");
  3049. outf("\tm_msgName.append(\"%s\");\n", name_);
  3050. if (parent)
  3051. outs("\tlocalUnserialize(*rpcmsg,NULL,NULL);\n");
  3052. else
  3053. outs("\tunserialize(*rpcmsg,NULL,NULL);\n");
  3054. outs("}\n");
  3055. //IProperties constructor
  3056. outf("\nC%s::C%s(IEspContext* ctx, const char *serviceName, IProperties *params, MapStrToBuf *attachments)", name_, name_);
  3057. isFirstInited=true;
  3058. if (parent)
  3059. {
  3060. outf(" : C%s(ctx, serviceName, params, attachments)", parent);
  3061. isFirstInited=false;
  3062. }
  3063. for (pi=getParams();pi!=NULL;pi=pi->next)
  3064. {
  3065. pi->write_esp_init(isFirstInited, removeNil);
  3066. }
  3067. if (contentVar)
  3068. {
  3069. outs((isFirstInited) ? " : " : ", ");
  3070. outf("m_%s_mimetype(%s)", contentVar->name, contentVar->getMetaString("http_content", "\"text/xml; charset=UTF-8\""));
  3071. }
  3072. outs("\n{\n\tm_eventSink=NULL;\n");
  3073. outs("\tm_RequestState=NULL;\n");
  3074. outs("\tm_serviceName.append(serviceName);\n");
  3075. outf("\tm_msgName.append(\"%s\");\n", name_);
  3076. if (parent)
  3077. outs("\tunserialize(ctx,*params,attachments, NULL,true);\n}\n");
  3078. else
  3079. outs("\tunserialize(ctx,*params,attachments, NULL);\n}\n");
  3080. }
  3081. //=======================================================================================
  3082. //method ==> getXsdDefinition
  3083. // @context: the context could affect the schema, e.g., the version, the URL parameters
  3084. // @flags: 0x001 - define the struct/enum as complexType.
  3085. // 0x010 - do not include group-type enclosure (i.e., just define the fields, e.g., as part of other complex type definition)
  3086. // 0x100 - do not include fields at all (only to include definitions of fields, recursively)
  3087. bool isExtSimpleType = getMetaInt("element", 0)!=0;
  3088. 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_);
  3089. outs("{\n");
  3090. indentReset(1);
  3091. indentOuts("if (!(flags & 0x100))\n\t{\n");
  3092. indentOuts(1,"IProperties *props = request->queryParameters();\n");
  3093. indentOuts("if(msgTypeName) {\n");
  3094. indentOuts(1,"if(added.getValue(msgTypeName))\n");
  3095. indentOuts1(1,"return schema;\n");
  3096. indentOuts("else\n");
  3097. indentOuts1(1,"added.setValue(msgTypeName, 1);\n");
  3098. indentOuts(-1,"}\n");
  3099. indentOuts("if (flags & 0x01) {\n");
  3100. if (espm_type_==espm_struct)
  3101. indentOuts(1,"schema.appendf(\"<xsd:complexType name=\\\"%s\\\">\\n\", msgTypeName);\n");
  3102. else
  3103. indentOuts(1,"schema.appendf(\"<xsd:element name=\\\"%s\\\"><xsd:complexType>\\n\", msgTypeName);\n");
  3104. if (isExtSimpleType)
  3105. indentOuts("schema.append(\"<xsd:simpleContent><xsd:extension base=\\\"xsd:string\\\">\\n\");\n");
  3106. indentOuts(-1, "}\n");
  3107. // native arrays
  3108. typedef std::map<std::string,std::string> EspNativeArrays;
  3109. EspNativeArrays nativeArrays;
  3110. // esp struct arrays
  3111. typedef std::set<std::string> EspStructArrays;
  3112. EspStructArrays structArrays;
  3113. //no element children for extended simple type
  3114. if (!isExtSimpleType)
  3115. {
  3116. const char *xsdGroupType = getXsdGroupType();
  3117. bool hasChild = hasNonAttributeChild();
  3118. bool exceptions = espm_type_==espm_response && getMetaInt("exceptions_inline", 0);
  3119. bool needGroupType = exceptions || hasChild || parent;
  3120. if (needGroupType)
  3121. {
  3122. indentOuts("if (!(flags & 0x10)) {\n");
  3123. indentOutf1(1,"schema.append(\"<xsd:%s>\");\n", xsdGroupType);
  3124. if (exceptions)
  3125. indentOuts("schema.append(\"<xsd:element name=\\\"Exceptions\\\" type=\\\"tns:ArrayOfEspException\\\" minOccurs=\\\"0\\\" maxOccurs=\\\"1\\\"/>\");\n");
  3126. indentOuts("}\n");
  3127. }
  3128. if (parent)
  3129. indentOutf("C%s::getXsdDefinition(context, request, NULL, schema, added, xns, wsns, 0x10);\n", parent);
  3130. for (pi=getParams();pi!=NULL;pi=pi->next)
  3131. {
  3132. if (!pi->getMetaInt("attribute", 0) && !pi->getMetaInt("hidden", 0) && !pi->getMetaInt("hidden_soap", 0))
  3133. {
  3134. enum {definedtype, inline_primitive_array, inline_array, complextype} complexity=definedtype;
  3135. StrBuffer buffer;
  3136. const char *xsd_type = pi->getMetaXsdType();
  3137. if (xsd_type)
  3138. {
  3139. buffer.append(xsd_type);
  3140. }
  3141. else if (pi->flags & PF_TEMPLATE)
  3142. {
  3143. if (!strcmp(pi->templ, "ESParray"))
  3144. {
  3145. if (pi->isPrimitiveArray())
  3146. {
  3147. if (pi->getMetaString("item_tag", NULL))
  3148. complexity=inline_primitive_array;
  3149. else {
  3150. const char* type = pi->getArrayImplType();
  3151. nativeArrays[pi->getArrayItemXsdType()] = VStrBuffer("Esp%s", type).str();
  3152. buffer.appendf("tns:Esp%s", type);
  3153. }
  3154. }
  3155. else
  3156. {
  3157. buffer.append("tns:");
  3158. if (pi->getMetaString("item_tag", NULL))
  3159. complexity=inline_array;
  3160. else {
  3161. structArrays.insert(pi->typname);
  3162. buffer.append("ArrayOf");
  3163. }
  3164. buffer.append(pi->typname);
  3165. }
  3166. }
  3167. else
  3168. buffer.append("xsd:string");
  3169. }
  3170. else if (pi->kind==TK_ESPSTRUCT || pi->kind==TK_ESPENUM)
  3171. {
  3172. buffer.appendf("tns:%s",pi->typname);
  3173. }
  3174. else
  3175. {
  3176. buffer.append(pi->getXsdType());
  3177. }
  3178. const char *xsdtype = buffer.str();
  3179. const char *xsdns = "";
  3180. if (xsdtype)
  3181. {
  3182. int count= buffer.length();
  3183. if (count>0 && buffer.charAt(count-1)=='\"')
  3184. buffer.setCharAt(count-1,0);
  3185. if (*xsdtype=='\"')
  3186. xsdtype++;
  3187. if (strchr(xsdtype, ':')==NULL)
  3188. xsdns="xsd:";
  3189. }
  3190. bool hasMapInfo = pi->hasMapInfo();
  3191. if (hasMapInfo)
  3192. {
  3193. indentOutf("if (!context.suppressed(\"%s\",\"%s\")) {\n", this->name_, pi->name);
  3194. indentInc(1);
  3195. }
  3196. const char *access=pi->getMetaString("access", NULL);
  3197. if (access)
  3198. {
  3199. indentOuts("SecAccessFlags acc;\n");
  3200. indentOutf("if (context.authorizeFeature(%s, acc) && acc>=SecAccess_Read) {\n", access);
  3201. indentInc(1);
  3202. }
  3203. StrBuffer xmlTag;
  3204. const char* tagName = pi->getMetaStringValue(xmlTag,"xml_tag") ? xmlTag.str() : pi->name;
  3205. switch (complexity)
  3206. {
  3207. case inline_array:
  3208. {
  3209. indentOutf("schema.append(\"<xsd:element minOccurs=\\\"0\\\" name=\\\"%s\\\">\\n\");\n", tagName);
  3210. indentOuts("schema.append(\"<xsd:complexType><xsd:sequence>\\n\");\n");
  3211. indentOutf("schema.append(\"<xsd:element minOccurs=\\\"0\\\" maxOccurs=\\\"unbounded\\\" name=\\\"%s\\\" type=\\\"%s\\\"/>\");\n", pi->getMetaString("item_tag", "Item"), xsdtype);
  3212. indentOuts("schema.append(\"</xsd:sequence></xsd:complexType>\");\n");
  3213. indentOutf("schema.append(\"</xsd:element>\");\n");
  3214. break;
  3215. }
  3216. case inline_primitive_array:
  3217. {
  3218. indentOutf("schema.append(\"<xsd:element minOccurs=\\\"0\\\" name=\\\"%s\\\">\");\n", tagName);
  3219. indentOuts("schema.append(\"<xsd:complexType><xsd:sequence>\");\n");
  3220. indentOutf("schema.append(\"<xsd:element name=\\\"%s\\\" type=\\\"xsd:%s\\\" minOccurs=\\\"0\\\" maxOccurs=\\\"unbounded\\\"", pi->getMetaString("item_tag", "Item"), pi->getArrayItemXsdType());
  3221. int cols = pi->getMetaInt("cols",0);
  3222. int rows = pi->getMetaInt("rows",0);
  3223. if (cols>0 || rows>0)
  3224. {
  3225. outs("\");\n");
  3226. indentOuts("if (context.queryOptions()&ESPCTX_ALL_ANNOTATION)\n");
  3227. indentOuts(1,"schema.append(\"> <xsd:annotation><xsd:appinfo><form");
  3228. if (cols>0)
  3229. outf(" formCols=\\\"%d\\\"", cols);
  3230. if (rows>0)
  3231. outf(" formRows=\\\"%d\\\"", rows);
  3232. outs("/></xsd:appinfo></xsd:annotation></xsd:element>\\n\");\n");
  3233. indentOuts(-1,"else\n");
  3234. indentOuts("\tschema.append(\"/>\\n\");\n");
  3235. }
  3236. else
  3237. outs("/>\\n\");\n");
  3238. indentOuts("schema.append(\"</xsd:sequence></xsd:complexType>\\n\");\n");
  3239. indentOutf("schema.append(\"</xsd:element>\\n\");\n");
  3240. break;
  3241. }
  3242. case definedtype:
  3243. {
  3244. indentOutf("schema.append(\"<xsd:element");
  3245. // min occurs
  3246. int minOccurs = (pi->getMetaInt("required", 0)) ? 1 : 0;
  3247. if (minOccurs==0)
  3248. outs(" minOccurs=\\\"0\\\"");
  3249. // default value
  3250. if (pi->hasMetaTag("default"))
  3251. {
  3252. if (pi->kind==TK_CHAR || pi->kind==TK_UNSIGNEDCHAR || strcmp(xsdtype,"string")==0)
  3253. {
  3254. const char* val = pi->getMetaString("default",NULL);
  3255. if (val && *val)
  3256. {
  3257. // remove quotes
  3258. if (*val=='"' || *val=='\'')
  3259. {
  3260. char* s = strdup(val);
  3261. *(s+strlen(s)-1) = 0;
  3262. outf(" default=\\\"%s\\\"", s+1);
  3263. free(s);
  3264. }
  3265. else
  3266. outf(" default=\\\"%s\\\"", val);
  3267. }
  3268. }
  3269. else if (pi->kind==TK_DOUBLE || pi->kind==TK_FLOAT || strcmp(xsdtype,"double")==0)
  3270. {
  3271. double val = pi->getMetaDouble("default");
  3272. if (val==0)
  3273. val = pi->getMetaInt("default"); // auto conversion
  3274. if (val!=0)
  3275. outf(" default=\\\"%g\\\"", val);
  3276. }
  3277. else if (pi->kind==TK_BOOL || strcmp(xsdtype,"bool")==0)
  3278. {
  3279. outf(" default=\\\"%s\\\"", pi->getMetaInt("default") ? "true" : "false");
  3280. }
  3281. else if (pi->kind==TK_ESPENUM)
  3282. {
  3283. const char* val = pi->getMetaString("default",NULL);
  3284. if (val && *val)
  3285. {
  3286. // remove quotes
  3287. if (*val=='"' || *val=='\'')
  3288. {
  3289. char* s = strdup(val);
  3290. *(s+strlen(s)-1) = 0;
  3291. outf(" default=\\\"%s\\\"", s+1);
  3292. free(s);
  3293. }
  3294. else
  3295. outf(" default=\\\"%s\\\"", val);
  3296. }
  3297. else
  3298. {
  3299. int val = pi->getMetaInt("default", -1);
  3300. if (val != -1)
  3301. outf(" default=\\\"%d\\\"", val);
  3302. }
  3303. }
  3304. else// assume it is integer
  3305. {
  3306. int val = pi->getMetaInt("default");
  3307. if (val)
  3308. outf(" default=\\\"%d\\\"", val);
  3309. }
  3310. }
  3311. // name & type
  3312. outf(" name=\\\"%s\\\" type=\\\"%s%s\\\"", tagName, xsdns, xsdtype);
  3313. // check for annotations
  3314. StrBuffer annot;
  3315. const char* formType = pi->getMetaInt("password") ? "password" : NULL;
  3316. if (formType)
  3317. annot.appendf(" formType=\\\"%s\\\"",formType);
  3318. bool collapsed = pi->getMetaInt("collapsed")?true:false;;
  3319. if (collapsed)
  3320. annot.append(" collapsed=\\\"true\\\"");
  3321. int cols = pi->getMetaInt("cols",0);
  3322. if (cols>0)
  3323. annot.appendf(" formCols=\\\"%d\\\"", cols);
  3324. int rows = pi->getMetaInt("rows",0);
  3325. if (rows>0)
  3326. annot.appendf(" formRows=\\\"%d\\\"", rows);
  3327. StrBuffer tmp;
  3328. pi->getMetaStringValue(tmp,"form_ui");
  3329. if (tmp.length()) {
  3330. StrBuffer encoded;
  3331. encodeXML(tmp.str(),encoded);
  3332. annot.appendf(" ui=\\\"%s\\\"", printfEncode(encoded.str(), tmp.clear()).str());
  3333. }
  3334. pi->getMetaStringValue(tmp.clear(), "html_head");
  3335. if (tmp.length()) {
  3336. StrBuffer encoded;
  3337. encodeXML(tmp.str(),encoded);
  3338. annot.appendf(" html_head=\\\"%s\\\"", printfEncode(encoded.str(), tmp.clear()).str());
  3339. }
  3340. if (annot.length())
  3341. {
  3342. outs("\");\n");
  3343. indentOuts("if (context.queryOptions()&ESPCTX_ALL_ANNOTATION)\n");
  3344. indentOuts(1,"schema.append(\"> <xsd:annotation><xsd:appinfo><form");
  3345. outf("%s", annot.str());
  3346. outs("/></xsd:appinfo></xsd:annotation></xsd:element>\\n\");\n");
  3347. indentOuts(-1,"else\n");
  3348. indentOuts("\tschema.append(\"/>\\n\");\n");
  3349. }
  3350. else
  3351. outs("/>\\n\");\n");
  3352. break;
  3353. }
  3354. default:
  3355. break;
  3356. }
  3357. if (access)
  3358. indentOuts(-1,"}\n");
  3359. //if (optional)
  3360. if (hasMapInfo)
  3361. indentOuts(-1,"}\n");
  3362. }
  3363. }
  3364. if (needGroupType)
  3365. {
  3366. indentOuts("if (!(flags & 0x10))\n");
  3367. indentOutf1(1,"schema.append(\"</xsd:%s>\\n\");\n", xsdGroupType);
  3368. }
  3369. } //!isExtSimpleType
  3370. //attributes last
  3371. for (pi=getParams();pi!=NULL;pi=pi->next)
  3372. {
  3373. if (pi->getMetaInt("attribute")!=0 && !pi->getMetaInt("hidden"))
  3374. {
  3375. StrBuffer tmp;
  3376. const char* tagName = pi->getMetaStringValue(tmp,"xml_tag") ? tmp.str() : pi->name;
  3377. indentOutf("schema.append(\"<xsd:attribute name=\\\"%s\\\" type=\\\"xsd:%s\\\"/>\");\n", tagName, pi->getXsdType());
  3378. }
  3379. }
  3380. indentOuts("if (flags & 0x01) {\n");
  3381. if (isExtSimpleType)
  3382. indentOuts1(1,"schema.append(\"</xsd:extension></xsd:simpleContent>\\n\");\n");
  3383. if (espm_type_==espm_struct)
  3384. indentOuts1(1,"schema.append(\"</xsd:complexType>\\n\");\n");
  3385. else
  3386. indentOuts1(1,"schema.append(\"</xsd:complexType></xsd:element>\\n\");\n");
  3387. indentOuts("}\n");
  3388. indentOuts(-1,"}\n"); // if (flags & 0x100)
  3389. //-------------------------------------------------------------------------
  3390. // try to figure out structs without ESPuses
  3391. // true if it is with map info, once a STRUCT or ENUM is there without map info, it is false
  3392. const int MIT_HasMap = 0x01;
  3393. const int MIT_IsEnum = 0x02;
  3394. const int MIT_IsStruct = 0x04;
  3395. enum MapInfoType { MIT_EnumFalse=MIT_IsEnum, MIT_EnumTrue=MIT_HasMap|MIT_IsEnum,
  3396. MIT_StructFalse=MIT_IsStruct,MIT_StructTrue=MIT_IsStruct|MIT_HasMap };
  3397. typedef std::map<std::string, int> TypeMap;
  3398. TypeMap typesNeeded;
  3399. bool parenthesisOpened = false;
  3400. if (parent)
  3401. {
  3402. outs("\tif (!(flags & 0x10) || (flags & 0x100))\n");
  3403. outs("\t{\n");
  3404. parenthesisOpened = true;
  3405. outf("\t\tC%s::getXsdDefinition(context, request, schema, added, xns, wsns, 0x110);\n", parent);
  3406. typesNeeded[parent] = false;
  3407. }
  3408. for (pi=getParams();pi!=NULL;pi=pi->next)
  3409. {
  3410. // we still need to make it usable for the service writer
  3411. //if (pi->getMetaInt("hidden", 0) || pi->getMetaInt("hidden_soap", 0))
  3412. // continue;
  3413. std::string thisType;
  3414. const char *xsd_type=pi->getMetaXsdType();
  3415. if (xsd_type)
  3416. {
  3417. char* buf = strdup(xsd_type[0]=='"' ? xsd_type+1 : xsd_type);
  3418. size_t count= strlen(buf);
  3419. if (count>0 && buf[count-1]=='\"')
  3420. buf[count-1]=0;
  3421. char* typeName = getToBeDefinedType(buf);
  3422. if (typeName)
  3423. {
  3424. thisType = typeName;
  3425. free(typeName);
  3426. }
  3427. free(buf);
  3428. }
  3429. else if (pi->kind==TK_ESPSTRUCT || pi->kind==TK_ESPENUM)
  3430. {
  3431. if (pi->typname)
  3432. thisType = pi->typname;
  3433. else
  3434. outs("\t\t*** pi->typname is empty!!\n");
  3435. }
  3436. else if (pi->flags & PF_TEMPLATE)
  3437. {
  3438. if (strcmp(pi->templ, "ESParray")==0)
  3439. {
  3440. if (pi->typname && strcmp(pi->typname, "string")!=0 && strcmp(pi->typname, "EspTextFile")!=0)
  3441. thisType = pi->typname;
  3442. }
  3443. else
  3444. outf("\t\t// *** skip field: name=%s, type=%s\n", pi->name, pi->typname);
  3445. }
  3446. if (thisType.length() && strcmp(thisType.c_str(),name_)!=0)
  3447. {
  3448. TypeMap::const_iterator it = typesNeeded.find(thisType);
  3449. if (it==typesNeeded.end() || (*it).second & MIT_HasMap) // thisType is not in typesNeeded or it is there with version info
  3450. {
  3451. if (!parenthesisOpened)
  3452. {
  3453. outs("\tif (!(flags & 0x10) || (flags & 0x100))\n\t{\n");
  3454. parenthesisOpened = true;
  3455. }
  3456. if (pi->hasMapInfo())
  3457. {
  3458. outf("\t\tif (!context.suppressed(\"%s\",\"%s\"))\n\t", this->name_, pi->name);
  3459. typesNeeded[thisType] = (pi->kind==TK_ESPENUM) ? MIT_EnumTrue : MIT_StructTrue;
  3460. }
  3461. else
  3462. typesNeeded[thisType] = (pi->kind==TK_ESPENUM) ? MIT_EnumFalse : MIT_StructFalse;
  3463. if (pi->kind == TK_ESPENUM)
  3464. outf("\t\tCX%s::getXsdDefinition(context, request, schema, added);\n", thisType.c_str());
  3465. else
  3466. outf("\t\tC%s::getXsdDefinition(context, request, schema, added);\n", thisType.c_str());
  3467. }
  3468. }
  3469. }
  3470. if (parenthesisOpened)
  3471. outs("\t}\n");
  3472. // native arrays
  3473. for (EspNativeArrays::const_iterator it = nativeArrays.begin(); it!=nativeArrays.end(); it++)
  3474. {
  3475. outf("\tif (added.getValue(\"%s\")==NULL) {\n", (*it).second.c_str());
  3476. outf("\t\taddEspNativeArray(schema,\"%s\",\"%s\");\n", (*it).first.c_str(), (*it).second.c_str());
  3477. outf("\t\tadded.setValue(\"%s\",1);\n", (*it).second.c_str());
  3478. outf("\t}\n");
  3479. }
  3480. // struct arrays
  3481. for (EspStructArrays::const_iterator it2 = structArrays.begin(); it2!=structArrays.end(); it2++)
  3482. {
  3483. const char* type = (*it2).c_str();
  3484. outf("\tif (added.getValue(\"%s\") && added.getValue(\"ArrayOf%s\")==NULL) {\n", type, type);
  3485. outf("\t\tschema.append(\"<xsd:complexType name=\\\"ArrayOf%s\\\">\\n\");\n",type);
  3486. outf("\t\tschema.append(\"<xsd:sequence>\\n\");\n");
  3487. outf("\t\tschema.append(\"<xsd:element minOccurs=\\\"0\\\" maxOccurs=\\\"unbounded\\\" name=\\\"%s\\\" type=\\\"tns:%s\\\"/>\\n\");\n", type, type);
  3488. outf("\t\tschema.append(\"</xsd:sequence>\\n\");\n");
  3489. outf("\t\tschema.append(\"</xsd:complexType>\\n\");\n");
  3490. outf("\t\tadded.setValue(\"ArrayOf%s\",1);\n", type);
  3491. outf("\t}\n");
  3492. }
  3493. /*
  3494. //typesNeeded.erase(name_); // Do not include self: avoid recursive call
  3495. if (typesNeeded.size()>0)
  3496. {
  3497. outs("\tif (!(flags & 0x10))\n");
  3498. outs("\t{\n");
  3499. for (TypeMap::const_iterator it = typesNeeded.begin(); it!=typesNeeded.end(); ++it)
  3500. {
  3501. const char* type = (*it).first.c_str();
  3502. const char* fld = (*it).second.c_str();
  3503. if (fld[0] != 0)
  3504. {
  3505. outf("\t\tif (!context.suppressed(\"%s\",\"%s\"))\n\t", this->name_, fld);
  3506. outf("\t\t\tC%s::getXsdDefinition(context, request, schema, added);\n", type);
  3507. }
  3508. else
  3509. outf("\t\tC%s::getXsdDefinition(context, request, schema, added);\n", type);
  3510. }
  3511. outs("\t}\n");
  3512. }
  3513. */
  3514. outs("\treturn schema;\n");
  3515. outs("}\n");
  3516. //=======================================================================================
  3517. //method ==> getMapInfo
  3518. outf("\nvoid C%s::getMapInfo(IMapInfo& info) { BoolHash added; getMapInfo(info, added); }\n",name_);
  3519. outf("\nvoid C%s::getMapInfo(IMapInfo& info, BoolHash& added)\n",name_);
  3520. outf("{\n");
  3521. for (pi=getParams();pi!=NULL;pi=pi->next)
  3522. {
  3523. if (pi->hasMapInfo())
  3524. {
  3525. StrBuffer ver;
  3526. bool hasVer = pi->getMetaVerInfo("min_ver",ver);
  3527. if (hasVer)
  3528. outf("\tinfo.addMinVersion(\"%s\",\"%s\",%s);\n", name_, pi->name, ver.str());
  3529. hasVer = pi->getMetaVerInfo("depr_ver",ver.clear());
  3530. if (hasVer)
  3531. outf("\tinfo.addDeprVersion(\"%s\",\"%s\",%s);\n", name_, pi->name, ver.str());
  3532. hasVer = pi->getMetaVerInfo("max_ver",ver.clear());
  3533. if (hasVer)
  3534. outf("\tinfo.addMaxVersion(\"%s\",\"%s\",%s);\n", name_, pi->name, ver.str());
  3535. const char* opt = pi->getMetaString("optional", NULL);
  3536. if (opt)
  3537. {
  3538. const char* quote = (*opt=='"' || *opt=='\'') ? "" : "\"";
  3539. outf("\tinfo.addOptional(\"%s\",\"%s\",%s%s%s);\n", name_, pi->name,quote,opt,quote);
  3540. }
  3541. }
  3542. }
  3543. if (typesNeeded.size()>0)
  3544. {
  3545. for (TypeMap::const_iterator it = typesNeeded.begin(); it!=typesNeeded.end(); ++it)
  3546. {
  3547. outf("\tif (!added.getValue(\"%s\"))\n", (*it).first.c_str());
  3548. outf("\t{\n");
  3549. outf("\t\tadded.setValue(\"%s\",1);\n", (*it).first.c_str());
  3550. outf("\t\tC%s%s::getMapInfo(info,added);\n",((*it).second & MIT_IsEnum)?"X":"",(*it).first.c_str());
  3551. outf("\t}\n");
  3552. }
  3553. }
  3554. outs("}\n");
  3555. //=======================================================================================
  3556. //method ==> getHtmlForm
  3557. //TODO: move includeFormTag into onGetForm() to reduce significant generated code
  3558. indentReset();
  3559. indentOutf("\nStringBuffer &C%s::getHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &form, bool includeFormTag, const char *prefix)\n", name_);
  3560. indentOuts("{\n");
  3561. indentOuts(1,"IProperties *props = request->queryParameters();\n");
  3562. bool hasAttachment=false;
  3563. for (pi=getParams();pi;pi=pi->next)
  3564. {
  3565. if (pi->typname && !stricmp("EspTextFile", pi->typname))
  3566. hasAttachment=true;
  3567. }
  3568. indentOuts("if (includeFormTag) {\n");
  3569. indentOutf(1,"StringBuffer params, versionTag;\n");
  3570. indentOuts("bool hasVersion = getUrlParams(props,params);\n");
  3571. indentOuts("if (!hasVersion) versionTag.appendf(\"%cver_=%g\",params.length()?'&':'?',context.getClientVersion());\n");
  3572. 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",
  3573. hasAttachment ? "multipart/form-data" : "application/x-www-form-urlencoded");
  3574. indentOutf(-1,"}\n");
  3575. if (parent)
  3576. indentOutf("C%s::getHtmlForm(context, request, serv, method, form, false, prefix);\n", parent);
  3577. indentOuts("StringBuffer extfix;\n");
  3578. indentOuts("form.append(\" <table>\\n\");\n");
  3579. for (pi=getParams();pi!=NULL;pi=pi->next)
  3580. {
  3581. bool hasMapInfo = pi->hasMapInfo();
  3582. if (hasMapInfo)
  3583. {
  3584. indentOutf("if (!context.suppressed(\"%s\",\"%s\")) {\n", this->name_, pi->name);
  3585. indentInc(1);
  3586. }
  3587. if (!pi->getMetaInt("hidden"))
  3588. {
  3589. int rows = pi->getMetaInt("rows", 5);
  3590. StrBuffer label;
  3591. if (!pi->getMetaStringValue(label,"label"))
  3592. if (!pi->getMetaStringValue(label,"xml_tag"))
  3593. label = pi->name;
  3594. if (pi->getMetaInt("rows") || (pi->flags & PF_TEMPLATE))
  3595. {
  3596. int cols = pi->getMetaInt("cols", 50);
  3597. indentOuts("extfix.clear();\n");
  3598. indentOuts("if (prefix && *prefix)\n");
  3599. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3600. indentOutf("extfix.append(\"%s\");\n", pi->name);
  3601. indentOutf("form.appendf(\"<tr><td><b>%s: </b></td><td>\");\n", label.str());
  3602. if (!pi->isEspStringArray())
  3603. {
  3604. // handle default value
  3605. StrBuffer tmp;
  3606. const char* def = pi->getMetaStringValue(tmp,"default") ? tmp.str() : "";
  3607. indentOutf("form.appendf(\"<table><tr><td><textarea name=\\\"%%s\\\" cols=\\\"%d\\\" rows=\\\"%d\\\">%s</textarea></td>\", extfix.str());\n",
  3608. cols, rows, def);
  3609. indentOutf("form.append(\"</tr></table>\");\n");
  3610. }
  3611. else
  3612. {
  3613. indentOutf("form.appendf(\"<textarea name=\\\"%%s\\\" cols=\\\"%d\\\" rows=\\\"%d\\\"></textarea>\", extfix.str());\n", cols, rows);
  3614. }
  3615. indentOutf("form.append(\"</td></tr>\");\n");
  3616. }
  3617. else
  3618. {
  3619. esp_xlate_info *espinfo = esp_xlat(pi);
  3620. if (pi->kind==TK_ESPSTRUCT)
  3621. {
  3622. indentOuts("extfix.clear();\n");
  3623. indentOuts("if (prefix && *prefix)\n");
  3624. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3625. indentOutf("extfix.append(\"%s\");\n", pi->getXmlTag());
  3626. indentOutf("form.append(\"<tr>\").append(\"<td><b>%s: </b></td><td><hr/>\");\n", label.str());
  3627. indentOutf("C%s::getHtmlForm(context, request, serv, method, form, false, extfix.str());\n", pi->typname);
  3628. indentOuts("form.append(\"<hr/></td></tr>\");\n");
  3629. }
  3630. else if (espinfo->access_kind==TK_BOOL)
  3631. {
  3632. indentOuts("extfix.clear();\n");
  3633. indentOuts("if (prefix && *prefix)\n");
  3634. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3635. indentOutf("extfix.append(\"%s\");\n", pi->getXmlTag());
  3636. // handle default value
  3637. 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",
  3638. label.str(), pi->getMetaInt("default",0)?"checked=\\\"1\\\"":"");
  3639. }
  3640. else if (espinfo->access_kind==TK_INT || espinfo->access_kind==TK_UNSIGNED
  3641. || espinfo->access_kind==TK_SHORT || espinfo->access_kind==TK_UNSIGNEDSHORT)
  3642. {
  3643. indentOuts("extfix.clear();\n");
  3644. indentOuts("if (prefix && *prefix) extfix.append(prefix).append(\".\");\n");
  3645. indentOutf("\textfix.append(\"%s\");\n", pi->getXmlTag());
  3646. int cols = pi->getMetaInt("cols", 20);
  3647. indentOutf("form.appendf(\" <tr><td><b>%s: </b></td><td><input type=\\\"text\\\" name=\\\"%%s\\\" size=\\\"%d\\\"", label.str(), cols);
  3648. int defValue = pi->getMetaInt("default");
  3649. if (defValue!=0)
  3650. indentOutf(" value=\\\"%d\\\"", defValue);
  3651. outs("/>\", extfix.str());\n");
  3652. indentOuts("form.append(\"</td></tr>\\n\");\n");
  3653. }
  3654. //TODO: handle default value for float, double, long, longlong etc
  3655. else
  3656. {
  3657. const char *xsdtype = pi->getXsdType();
  3658. bool isDate = (!stricmp(xsdtype, "date"));
  3659. const char *inputType = "text";
  3660. if (pi->typname && !strcmp(pi->typname, "EspTextFile"))
  3661. inputType="file";
  3662. else if (pi->getMetaInt("password"))
  3663. inputType="password";
  3664. indentOuts("extfix.clear();\n");
  3665. indentOuts("if (prefix && *prefix)\n");
  3666. indentOuts1(1,"extfix.append(prefix).append(\".\");\n");
  3667. indentOutf("extfix.append(\"%s\");\n", pi->getXmlTag());
  3668. // handle default value
  3669. StrBuffer tmp;
  3670. const char* def = pi->getMetaStringValue(tmp,"default") ? tmp.str() : "";
  3671. int cols = pi->getMetaInt("cols", isDate ? 20 : 50);
  3672. 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);
  3673. if (isDate)
  3674. 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);
  3675. indentOuts("form.append(\"</td></tr>\\n\");\n");
  3676. }
  3677. }
  3678. }
  3679. if (hasMapInfo)
  3680. indentOuts(-1,"}\n");
  3681. }
  3682. indentReset(1);
  3683. indentOuts("if (includeFormTag) {\n");
  3684. indentOuts(1,"form.append(\"<tr><td></td><td><input type=\\\"submit\\\" value=\\\"Submit\\\" name=\\\"S1\\\" />\");\n");
  3685. indentOuts("form.append(\" &nbsp; <input type=\\\"reset\\\" value=\\\"Clear\\\"/> </td> </tr>\");\n");
  3686. indentOuts(-1,"}\n");
  3687. indentOuts("form.append(\"</table>\");\n");
  3688. indentOuts("if (includeFormTag)\n");
  3689. indentOuts(1,"form.append(\"</form>\");\n");
  3690. indentOuts(-1,"return form;\n");
  3691. indentOuts(-1,"}\n");
  3692. //method ==> serializeHtml
  3693. outf("\nStringBuffer &C%s::serializeHtml(IEspContext &context, const char *serv, const char *method, StringBuffer &html)\n", name_);
  3694. outs("{\n");
  3695. if (getMetaInt("serialize_html"))
  3696. {
  3697. outs("\thtml.append(\"<p align=\\\"left\\\">\");\n");
  3698. if (contentVar)
  3699. {
  3700. if (!(contentVar->flags & PF_TEMPLATE))
  3701. {
  3702. if (contentVar->typname!=NULL && strcmp(contentVar->typname, "EspResultSet")==0)
  3703. {
  3704. outf("\thtml.appendf(\"<br/><b>%s: </b><br/>\");\n", contentVar->name);
  3705. outf("\tEspHttpBinding::formatHtmlResultSet(context, serv, method, m_%s->str(), html);", contentVar->name);
  3706. }
  3707. else if (contentVar->typname==NULL || strcmp(contentVar->typname, "binary")!=0)
  3708. {
  3709. 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);
  3710. }
  3711. }
  3712. }
  3713. else
  3714. {
  3715. for (pi=getParams();pi!=NULL;pi=pi->next)
  3716. {
  3717. if (!(pi->flags & PF_TEMPLATE) && (pi->kind!=TK_ESPSTRUCT))
  3718. {
  3719. if (pi->typname!=NULL && strcmp(pi->typname, "EspResultSet")==0)
  3720. {
  3721. outf("\thtml.appendf(\"<br/><b>%s: </b><br/>\");\n", pi->name);
  3722. outf("\tEspHttpBinding::formatHtmlResultSet(context, serv, method, m_%s->str(), html);", pi->name);
  3723. }
  3724. else if (pi->typname==NULL || strcmp(pi->typname, "binary")!=0)
  3725. {
  3726. 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);
  3727. }
  3728. }
  3729. }
  3730. }
  3731. outs("\thtml.append(\"</p>\");\n");
  3732. }
  3733. outs("\treturn html;\n");
  3734. outs("}\n");
  3735. //method ==> serialize (IRpcMessage&)
  3736. outf("\nvoid C%s::serialize(IRpcMessage& rpc_resp)\n{\n", name_);
  3737. if (parent)
  3738. outf("\tC%s::serialize(rpc_resp);\n", parent);
  3739. // versioning
  3740. if (hasMapInfo())
  3741. {
  3742. outf("\tIEspContext* ctx = rpc_resp.queryContext();\n");
  3743. outf("\tdouble clientVer= ctx ? ctx->getClientVersion() : -1; /* no context gets everything */\n");
  3744. }
  3745. outf("\trpc_resp.set_ns(%s);\n", getMetaString("ns_var", "\"\""));
  3746. outs("\trpc_resp.set_name(m_msgName.str());\n");
  3747. const char *nsuri = getMetaString("ns_uri", NULL);
  3748. if (nsuri)
  3749. outf("\trpc_resp.set_nsuri(%s);\n\n", nsuri);
  3750. else
  3751. {
  3752. outs("\tStringBuffer nsuri;\n");
  3753. outs("\tnsuri.append(\"urn:hpccsystems:ws:\").appendLower(m_serviceName.length(), m_serviceName.str());\n");
  3754. outs("\trpc_resp.set_nsuri(nsuri.str());\n\n");
  3755. }
  3756. int soap_encode = getMetaInt("soap_encode", -1);
  3757. if (soap_encode ==-1)
  3758. soap_encode = getMetaInt("encode", 1);
  3759. if (soap_encode==0)
  3760. outs("\trpc_resp.setEncodeXml(false);\n");
  3761. if (espm_type_==espm_response)
  3762. {
  3763. outs(
  3764. "\tconst IMultiException& exceptions = getExceptions();\n"
  3765. "\tif (exceptions.ordinality() > 0)\n"
  3766. "\t{\n"
  3767. "\t\tStringBuffer xml;\n"
  3768. "\t\texceptions.serialize(xml, 0, true, false);\n"
  3769. "\t\trpc_resp.add_value(\"\", \"\", \"Exceptions\", \"\", xml.str(), false);\n"
  3770. "\t}\n"
  3771. "\telse\n"
  3772. "\t{\n");
  3773. }
  3774. //attributes first
  3775. int attrCount=0;
  3776. for (pi=getParams();pi!=NULL;pi=pi->next)
  3777. {
  3778. if (pi->getMetaInt("attribute"))
  3779. {
  3780. attrCount++;
  3781. if (attrCount==1)
  3782. outs(1, "Owned<IProperties> props=createProperties();\n");
  3783. outf(1, "if (!m_%s.is_nil())\n", pi->name);
  3784. outf(2, "props->setProp(\"%s\", m_%s.getValue());\n", pi->getXmlTag(), pi->name);
  3785. }
  3786. }
  3787. if (attrCount!=0)
  3788. outs(1, "rpc_resp.add_attr(NULL, NULL, NULL, *props.get());\n");
  3789. for (pi=getParams();pi!=NULL;pi=pi->next)
  3790. {
  3791. pi->write_esp_marshall(true,"rpc_resp", true, true, (espm_type_==espm_response)?2:1);
  3792. }
  3793. if (espm_type_==espm_response)
  3794. outs("\t}\n");
  3795. outs("}\n\n");
  3796. //method ==> copy
  3797. outf("\nvoid C%s::copy(C%s &from)\n{\n", name_, name_);
  3798. if (parent)
  3799. outf("\tC%s::copy(*dynamic_cast<C%s*>(&from));\n", parent, parent);
  3800. for (pi=getParams();pi!=NULL;pi=pi->next)
  3801. outf("\tm_%s.copy(from.m_%s);\n", pi->name, pi->name);
  3802. if (getMetaInt("element"))
  3803. outf("\tset_tag_value(from.get_tag_value());\n");
  3804. outs("}\n\n");
  3805. //method ==> copy from interface
  3806. outf("\nvoid C%s::copy(IConst%s &ifrom)\n{\n", name_, name_);
  3807. if (parent)
  3808. outf("\tC%s::copy(*dynamic_cast<IConst%s*>(&ifrom));\n", parent, parent);
  3809. for (pi=getParams();pi!=NULL;pi=pi->next)
  3810. {
  3811. char *uname=strdup(pi->name);
  3812. *uname=upperchar(*uname);
  3813. outf("\tset%s(ifrom.get%s());\n", uname, uname);
  3814. free(uname);
  3815. }
  3816. if (getMetaInt("element"))
  3817. outf("\tset_tag_value(ifrom.get_tag_value());\n");
  3818. outs("}\n\n");
  3819. //method ==> serializeContent (StringBuffer&)
  3820. outf("\nvoid C%s::serializeContent(IEspContext* ctx, StringBuffer& buffer, IProperties **pprops)\n{\n", name_);
  3821. int http_encode = getMetaInt("http_encode", -1);
  3822. if (http_encode ==-1)
  3823. http_encode = getMetaInt("encode", 1);
  3824. bool encodeXML = http_encode==1;
  3825. if (espm_type_==espm_response)
  3826. {
  3827. outs(
  3828. "\tconst IMultiException& exceptions = getExceptions();\n"
  3829. "\tif (exceptions.ordinality() > 0)\n"
  3830. "\t\texceptions.serialize(buffer, 0, true);\n"
  3831. "\telse\n"
  3832. "\t{\n");
  3833. if (parent)
  3834. outf("\t\tC%s::serializeContent(ctx,buffer);\n", parent);
  3835. if (hasMapInfo())
  3836. outf("\t\tdouble clientVer = ctx ? ctx->getClientVersion() : -1;\n");
  3837. for (pi=getParams();pi!=NULL;pi=pi->next)
  3838. {
  3839. if (!pi->getMetaInt("attribute"))
  3840. pi->write_esp_marshall(false,"buffer", encodeXML,true,2);
  3841. }
  3842. outs("\t}\n");
  3843. }
  3844. else
  3845. {
  3846. if (parent)
  3847. outf("\tC%s::serializeContent(ctx,buffer);\n", parent);
  3848. if (hasMapInfo())
  3849. outf("\tdouble clientVer = ctx ? ctx->getClientVersion() : -1;\n");
  3850. //attributes first
  3851. int attrCount=0;
  3852. for (pi=getParams();pi!=NULL;pi=pi->next)
  3853. {
  3854. if (pi->getMetaInt("attribute"))
  3855. {
  3856. attrCount++;
  3857. if (attrCount==1)
  3858. {
  3859. outs(1, "if (pprops)\n");
  3860. outs(1, "{\n");
  3861. outs(2, "*pprops=NULL;\n");
  3862. }
  3863. outf(2, "if (!m_%s.is_nil())\n", pi->name);
  3864. outs(2, "{\n");
  3865. outs(3, "if (!*pprops)\n");
  3866. outs(4, "*pprops=createProperties();\n");
  3867. outf(3, "(*pprops)->setProp(\"%s\", m_%s.getValue());\n", pi->getXmlTag(), pi->name);
  3868. outs(2, "}\n");
  3869. }
  3870. }
  3871. if (attrCount!=0)
  3872. outs(1, "}\n");
  3873. for (pi=getParams();pi!=NULL;pi=pi->next)
  3874. {
  3875. if (!pi->getMetaInt("attribute"))
  3876. pi->write_esp_marshall(false,"buffer", encodeXML, true);
  3877. }
  3878. if (getMetaInt("element")!=0)
  3879. {
  3880. outs(1, "if (m_tag_value.length()) {\n");
  3881. outs(2, "StringBuffer encoded;\n");
  3882. outs(2, "encodeXML(m_tag_value, encoded);\n");
  3883. outs(2, "buffer.append(encoded);\n");
  3884. outs(1, "}\n");
  3885. }
  3886. }
  3887. outs("}\n\n");
  3888. //method ==> serialize (StringBuffer&)
  3889. outf("\nvoid C%s::serialize(IEspContext* ctx, StringBuffer& buffer, const char *name)\n{\n", name_);
  3890. outs(1, "const char *tname = (name && *name) ? name : m_msgName.str();\n");
  3891. StrBuffer nsvar;
  3892. getMetaStringValue(nsvar, "ns_var");
  3893. const char *nuri=getMetaString("ns_uri", NULL);
  3894. outs(1, "buffer.append(\"<\");\n");
  3895. if (nsvar.length())
  3896. outf(1, "buffer.append(\"%s\").append(':');\n", nsvar.str());
  3897. outs(1, "buffer.appendf(\"%s\", tname);\n");
  3898. if (nuri)
  3899. {
  3900. outs(1, "buffer.append(\" xmlns\");\n");
  3901. if (nsvar.length())
  3902. outf(1, "buffer.append(':').append(\"%s\");\n", nsvar.str());
  3903. outf(1, "buffer.append(\"=\\\"\").append(%s).append('\\\"');\n", nuri);
  3904. }
  3905. for (pi=getParams();pi!=NULL;pi=pi->next)
  3906. {
  3907. if (pi->getMetaInt("attribute"))
  3908. {
  3909. outf(1, "if (!m_%s.is_nil()) {\n", pi->name);
  3910. outf(2, "StringBuffer encoded;\n");
  3911. outf(2, "encodeXML(m_%s.getValue(), encoded);\n", pi->name);
  3912. outf(2, "buffer.appendf(\" %s=\\\"%%s\\\"\", encoded.str());\n", pi->getXmlTag());
  3913. outf(1, "}\n");
  3914. }
  3915. }
  3916. outs(1, "buffer.append(\">\");\n");
  3917. outs(1, "serializeContent(ctx,buffer);\n");
  3918. outs(1, "buffer.append(\"</\");\n");
  3919. if (nsvar.length())
  3920. outf(1, "buffer.append(\"%s\").append(':');\n", nsvar.str());
  3921. outs(1, "buffer.appendf(\"%s>\", tname);\n");
  3922. outs("}\n");
  3923. //method ==> serializer(IEspContext* ctx, ..., StringBuffer&, ...)
  3924. outf("\nvoid C%s::serializer(IEspContext* ctx, IConst%s &src, StringBuffer& buffer, bool keepRootTag)\n{\n", name_, name_);
  3925. // attributes
  3926. int nAttrs = 0;
  3927. for (pi=getParams();pi!=NULL;pi=pi->next)
  3928. if (pi->getMetaInt("attribute"))
  3929. nAttrs++;
  3930. if (nAttrs)
  3931. {
  3932. outf(1,"if (keepRootTag)\n\t{\n");
  3933. outf(2,"buffer.append(\"<%s\");\n", name_);
  3934. for (pi=getParams();pi!=NULL;pi=pi->next)
  3935. {
  3936. if (pi->getMetaInt("attribute"))
  3937. {
  3938. char* fname = getFieldName(pi->name);
  3939. outf(2, "%sattr = src.get%s();\n", (pi==getParams())?"const char* ":"", fname);
  3940. free(fname);
  3941. outf(2, "if (attr && *attr) {\n");
  3942. outf(3, "StringBuffer encoded;\n");
  3943. outf(3, "encodeXML(attr,encoded);\n");
  3944. outf(3, "buffer.appendf(\" %s=\\\"%%s\\\"\",encoded.str());\n", pi->getXmlTag());
  3945. outf(2, "}\n");
  3946. }
  3947. }
  3948. outf(2,"buffer.append(\">\");\n");
  3949. outf(1,"}\n");
  3950. }
  3951. else
  3952. outf(1,"if (keepRootTag)\n\tbuffer.append(\"<%s>\");\n", name_);
  3953. if (parent)
  3954. {
  3955. outf("\tC%s::serializer(ctx,dynamic_cast<C%s&>(src),buffer,false);\n",parent,parent);
  3956. }
  3957. // -- versioning
  3958. if (hasMapInfo())
  3959. {
  3960. outf("\tdouble clientVer = ctx ? ctx->getClientVersion() : -1;\n");
  3961. }
  3962. #if 1
  3963. // not respecting nil_remove: backward compatible
  3964. for (pi=getParams();pi!=NULL;pi=pi->next)
  3965. {
  3966. if (pi->getMetaInt("attribute"))
  3967. continue;
  3968. outf("\t// field %s\n", pi->name);
  3969. char *uname=getFieldName(pi->name);
  3970. bool hasIf = false;
  3971. if (pi->hasMapInfo())
  3972. hasIf = pi->write_mapinfo_check(1,"ctx");
  3973. //if (hasIf) outs("\t{\n");
  3974. const char* ifIndent = hasIf?"\t":"";
  3975. if (pi->flags & PF_TEMPLATE) // array
  3976. {
  3977. outf("\t{\n");
  3978. if (pi->isPrimitiveArray())
  3979. {
  3980. const char *item_tag = pi->getMetaString("item_tag", "Item");
  3981. const char *type = pi->getArrayImplType();
  3982. outf("\t\t%s& v = src.get%s();\n",type,uname);
  3983. outf("\t\tif (v.length()>0)\n");
  3984. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  3985. outf("\t\tfor (size32_t i=0;i<v.length();i++)\n");
  3986. const char* fmt = "%"; // print %% when undefined
  3987. switch(pi->kind)
  3988. {
  3989. case TK_BOOL:
  3990. case TK_SHORT:
  3991. case TK_INT: fmt = "d"; break;
  3992. case TK_UNSIGNED: fmt = "u"; break;
  3993. case TK_LONG: fmt = "ld"; break;
  3994. case TK_UNSIGNEDLONG: fmt = "lu"; break;
  3995. case TK_FLOAT:
  3996. case TK_DOUBLE: fmt = "g"; break;
  3997. case TK_null:
  3998. case TK_CHAR: fmt = "s"; break;
  3999. default:
  4000. {
  4001. char buf[128];
  4002. sprintf(buf,"Unhandled array type: %s (%s)", getTypeKindName(pi->kind), name_);
  4003. yyerror(buf);
  4004. }
  4005. }
  4006. outf("\t\t\tbuffer.appendf(\"<%s>%%%s</%s>\",v.item(i));\n",item_tag,fmt,item_tag);
  4007. outf("\t\tif (v.length()>0)\n");
  4008. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4009. }
  4010. else if (pi->typname)
  4011. {
  4012. if (pi->kind == TK_ESPENUM)
  4013. {
  4014. outf("\t\t%sArray& v = src.get%s();\n",pi->typname,uname);
  4015. outf("\t\tint size = v.length();\n");
  4016. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4017. outf("\t\tif (size>0)\n");
  4018. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4019. outf("\t\tfor (int i=0;i<size;i++)\n");
  4020. //outf("\t\t{\n");
  4021. outf("\t\t\tbuffer.appendf(\"<%s>%%s</%s>\", CX%s::stringOf(v.item(i)));\n",item_tag, item_tag, pi->typname);
  4022. //outf("\t\t\tC%s::serializer(ctx,v.item(i),buffer,false);\n",pi->typname);
  4023. //outf("\t\t\tbuffer.append(\"</%s>\");\n",item_tag);
  4024. //outf("\t\t}\n");
  4025. outf("\t\tif (size>0)\n");
  4026. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4027. }
  4028. else if (pi->kind == TK_ESPSTRUCT || pi->kind == TK_null) // should be fixed at lex/yacc
  4029. {
  4030. outf("\t\tIArrayOf<IConst%s>& v = src.get%s();\n",pi->typname,uname);
  4031. outf("\t\tint size = v.length();\n");
  4032. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4033. outf("\t\tif (size>0)\n");
  4034. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4035. outf("\t\tfor (int i=0;i<size;i++)\n");
  4036. outf("\t\t{\n");
  4037. outf("\t\t\tbuffer.append(\"<%s>\");\n",item_tag);
  4038. outf("\t\t\tC%s::serializer(ctx,v.item(i),buffer,false);\n",pi->typname);
  4039. outf("\t\t\tbuffer.append(\"</%s>\");\n",item_tag);
  4040. outf("\t\t}\n");
  4041. outf("\t\tif (size>0)\n");
  4042. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4043. }
  4044. else
  4045. outf("\t\t**** TODO: unhandled array: kind=%s, type=%s, name=%s, xsd-type=%s\n", getTypeKindName(pi->kind), pi->typname, uname, pi->getXsdType());
  4046. }
  4047. else
  4048. {
  4049. outf("\t\t**** TODO: unhandled array: type=<NULL>, name=%s, xsd-type=%s\n", uname, pi->getXsdType());
  4050. }
  4051. outf("\t}\n");
  4052. }
  4053. else if (pi->kind == TK_ESPSTRUCT)
  4054. {
  4055. outf("\t{\n");
  4056. outf("\t\tStringBuffer tmp;\n");
  4057. outf("\t\tC%s::serializer(ctx,src.get%s(), tmp, false);\n", pi->typname, uname);
  4058. outf("\t\tif (tmp.length()>0)\n");
  4059. const char* tag = pi->getXmlTag();
  4060. outf("\t\t\tbuffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag, tag);
  4061. outf("\t}\n");
  4062. }
  4063. else if (pi->kind == TK_ESPENUM)
  4064. {
  4065. outs("\t{\n");
  4066. outf("\t\tconst char* s = src.get%sAsString();\n",uname);
  4067. outf("\t\tbuffer.append(\"<%s>\");\n",pi->getXmlTag());
  4068. outs("\t\tencodeUtf8XML(s,buffer);\n");
  4069. outf("\t\tbuffer.append(\"</%s>\");\n",pi->getXmlTag());
  4070. outs("\t}\n");
  4071. }
  4072. else
  4073. {
  4074. esp_xlate_info* info = esp_xlat(pi);
  4075. switch(info->access_kind)
  4076. {
  4077. case TK_CHAR:
  4078. outf("\t{\n");
  4079. outf("\t\tconst char* s = src.get%s();\n", uname);
  4080. outf("\t\tif (s && *s)\n");
  4081. if (!getMetaInt("encode",1))
  4082. {
  4083. outf("\t\tbuffer.appendf(\"<%s>%%s</%s>\",s);\n",pi->name,pi->name);
  4084. }
  4085. else
  4086. {
  4087. outf("\t\t{\n");
  4088. outf("\t\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4089. outf("\t\t\tencodeUtf8XML(s,buffer);\n");
  4090. outf("\t\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4091. outf("\t\t}\n");
  4092. }
  4093. outf("\t}\n");
  4094. break;
  4095. case TK_INT:
  4096. case TK_SHORT:
  4097. {
  4098. outf("\t{\n");
  4099. outf("\t\t%s n = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4100. outf("\t\tif (n)\n");
  4101. const char* tag = pi->getXmlTag();
  4102. outf("\t\t\tbuffer.appendf(\"<%s>%%d</%s>\", n);\n", tag, tag);
  4103. outf("\t}\n");
  4104. break;
  4105. }
  4106. case TK_LONG:
  4107. {
  4108. outf("\t{\n");
  4109. outf("\t\t%s n = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4110. outf("\t\tif (n)\n");
  4111. const char* tag = pi->getXmlTag();
  4112. outf("\t\t\tbuffer.appendf(\"<%s>%%\"I64F\"d</%s>\", n);\n", tag, tag);
  4113. outf("\t}\n");
  4114. break;
  4115. }
  4116. case TK_BOOL:
  4117. {
  4118. outf("\t{\n");
  4119. outf("\t\t%s b = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4120. outf("\t\tif (b)\n");
  4121. const char* tag = pi->getXmlTag();
  4122. outf("\t\t\tbuffer.appendf(\"<%s>1</%s>\");\n", tag, tag);
  4123. outf("\t}\n");
  4124. break;
  4125. }
  4126. default:
  4127. if (pi->kind == TK_STRUCT && info->eam_type == EAM_jmbin) // binary
  4128. {
  4129. //TODO: should we encode binary data?
  4130. outf("\t{\n");
  4131. outf("\t\tStringBuffer tmp;\n");
  4132. outf("\t\tJBASE64_Encode(src.get%s().toByteArray(), src.get%s().length(), tmp);\n", uname, uname);
  4133. outf("\t\tif (tmp.length()>0)\n");
  4134. const char* tag = pi->getXmlTag();
  4135. outf("\t\t\tbuffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag, tag);
  4136. outf("\t}\n");
  4137. }
  4138. else
  4139. {
  4140. outf("\t{\n");
  4141. outf("\t\t//*** default kind: %s; type=%s, name=%s\n", getTypeKindName(pi->kind), pi->typname, uname);
  4142. outf("\t\tbuffer.append(\"<%s>\");\n", pi->getXmlTag());
  4143. outf("\t\tbuffer.append(src.get%s());\n", uname);
  4144. outf("\t\tbuffer.append(\"</%s>\");\n", pi->getXmlTag());
  4145. outf("\t}\n");
  4146. }
  4147. break;
  4148. }
  4149. }
  4150. //if (hasIf) outs("\t}\n");
  4151. free(uname);
  4152. }
  4153. #else
  4154. // respect nil_remove: may cause backward compatibility problem
  4155. bool nilRemove = getMetaInt("nil_remove", 0)!=0;
  4156. indentReset(1);
  4157. for (pi=getParams();pi!=NULL;pi=pi->next)
  4158. {
  4159. char *uname=strdup(pi->name);
  4160. *uname = upperchar(*uname);
  4161. if (pi->hasMapInfo())
  4162. pi->write_mapinfo_check(1,"ctx");
  4163. if (pi->flags & PF_TEMPLATE) // array
  4164. {
  4165. indentOutf("{\n");
  4166. indentInc(1);
  4167. if (pi->isPrimitiveArray())
  4168. {
  4169. const char *item_tag = pi->getMetaString("item_tag", "Item");
  4170. const char *type = pi->getArrayImplType();
  4171. indentOutf("%s& v = src.get%s();\n",type,uname);
  4172. indentOutf("int size = v.length();\n");
  4173. if (nilRemove)
  4174. {
  4175. indentOutf("if (size>0)\n");
  4176. indentOutf1(1,"buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4177. }
  4178. else
  4179. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4180. indentOuts("for (int i=0;i<size;i++)\n");
  4181. const char* fmt;
  4182. switch(pi->kind)
  4183. {
  4184. case TK_BOOL:
  4185. case TK_SHORT:
  4186. case TK_INT: fmt = "d"; break;
  4187. case TK_UNSIGNED: fmt = "u"; break;
  4188. case TK_LONG: fmt = "ld"; break;
  4189. case TK_UNSIGNEDLONG: fmt = "lu"; break;
  4190. case TK_FLOAT:
  4191. case TK_DOUBLE: fmt = "g"; break;
  4192. case TK_null:
  4193. case TK_CHAR: fmt = "s"; break;
  4194. default:
  4195. {
  4196. char buf[128];
  4197. sprintf(buf,"Unhandled array type: %s (%s)", getTypeKindName(pi->kind), name_);
  4198. yyerror(buf);
  4199. }
  4200. }
  4201. indentOutf1(1,"buffer.appendf(\"<%s>%%%s</%s>\",v.item(i));\n",item_tag,fmt,item_tag);
  4202. if (nilRemove)
  4203. {
  4204. indentOutf("if (size>0)\n");
  4205. indentOutf1(1,"buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4206. }
  4207. else
  4208. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4209. }
  4210. else if (pi->typname)
  4211. {
  4212. indentOutf("IArrayOf<IConst%s>& v = src.get%s();\n",pi->typname,uname);
  4213. indentOuts("int size = v.length();\n");
  4214. const char *item_tag = pi->getMetaString("item_tag", pi->typname);
  4215. if (nilRemove)
  4216. {
  4217. indentOutf("if (size>0)\n");
  4218. indentOutf1(1,"buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4219. }
  4220. else
  4221. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4222. indentOutf("for (int i=0;i<size;i++)\n");
  4223. indentOutf("{\n");
  4224. indentOutf(1,"buffer.append(\"<%s>\");\n",item_tag);
  4225. indentOutf("C%s::serializer(ctx,v.item(i),buffer,false);\n",pi->typname);
  4226. indentOutf("buffer.append(\"</%s>\");\n",item_tag);
  4227. indentOutf(-1,"}\n");
  4228. if (nilRemove)
  4229. {
  4230. indentOutf("if (size>0)\n");
  4231. indentOutf1(1,"buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4232. }
  4233. else
  4234. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4235. }
  4236. else
  4237. {
  4238. indentOutf("**** TODO: unhandled array: type=%s, name=%s, xsd-type=%s\n", pi->typname, uname, pi->getXsdType());
  4239. }
  4240. indentOutf(-1,"}\n");
  4241. }
  4242. else if (pi->kind == TK_ESPSTRUCT)
  4243. {
  4244. indentOutf("{\n");
  4245. indentInc(1);
  4246. if (nilRemove)
  4247. {
  4248. indentOutf("StringBuffer tmp;\n");
  4249. indentOutf("C%s::serializer(ctx,src.get%s(), tmp, false);\n", pi->typname, uname);
  4250. indentOutf("if (tmp.length()>0)\n");
  4251. const char* tag = pi->getXmlTag();
  4252. indentOutf1(1,"buffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag, tag);
  4253. }
  4254. else
  4255. {
  4256. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4257. indentOutf("C%s::serializer(ctx,src.get%s(), buffer, false);\n", pi->typname, uname);
  4258. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4259. }
  4260. indentOutf(-1,"}\n");
  4261. }
  4262. else
  4263. {
  4264. esp_xlate_info* info = esp_xlat(pi);
  4265. switch(info->access_kind)
  4266. {
  4267. case TK_CHAR:
  4268. indentOuts("{\n");
  4269. indentOutf(1,"const char* s = src.get%s();\n", uname);
  4270. if (nilRemove)
  4271. {
  4272. indentOutf("if (s && *s)\n");
  4273. indentInc(1);
  4274. }
  4275. if (!getMetaInt("encode",1))
  4276. {
  4277. indentOutf("buffer.appendf(\"<%s>%%s</%s>\",s);\n",pi->name,pi->name);
  4278. }
  4279. else
  4280. {
  4281. if (nilRemove)
  4282. indentOutf1(-1,"{\n");
  4283. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4284. indentOutf("encodeUtf8XML(s,buffer);\n");
  4285. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4286. if (nilRemove)
  4287. indentOutf1(-1,"}\n");
  4288. }
  4289. if (nilRemove)
  4290. indentInc(-1);
  4291. indentOuts(-1,"}\n");
  4292. break;
  4293. case TK_INT:
  4294. case TK_LONG:
  4295. case TK_SHORT:
  4296. indentOuts("{\n");
  4297. indentOutf(1,"%s n = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4298. if (nilRemove)
  4299. {
  4300. indentOuts("if (n)\n");
  4301. indentInc(1);
  4302. }
  4303. indentOutf("buffer.appendf(\"<%s>%%d</%s>\", n);\n", pi->name,pi->name);
  4304. if (nilRemove)
  4305. indentInc(-1);
  4306. indentOuts(-1,"}\n");
  4307. break;
  4308. case TK_BOOL:
  4309. indentOuts("{\n");
  4310. indentOutf(1,"%s b = src.get%s();\n", esp_xlat(pi)->access_type, uname);
  4311. if (nilRemove)
  4312. {
  4313. indentOuts("if (b)\n");
  4314. indentInc(1);
  4315. }
  4316. const char* tag = pi->getXmlTag();
  4317. indentOutf("buffer.append(\"<%s>1</%s>\");\n", tag,tag);
  4318. if (nilRemove)
  4319. indentInc(-1);
  4320. indentOuts(-1,"}\n");
  4321. break;
  4322. default:
  4323. if (pi->kind == TK_STRUCT && info->eam_type == EAM_jmbin) // binary
  4324. {
  4325. //TODO: should we encode binary data?
  4326. indentOuts("{\n");
  4327. if (nilRemove)
  4328. {
  4329. indentOutf(1,"StringBuffer tmp;\n");
  4330. indentOutf("JBASE64_Encode(src.get%s().toByteArray(), src.get%s().length(), tmp);\n", uname, uname);
  4331. indentOutf("if (tmp.length()>0)\n");
  4332. const char* tag = pi->getXmlTag();
  4333. indentOutf1(1,"buffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", tag,tag);
  4334. }
  4335. else
  4336. {
  4337. indentOutf(1,"buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4338. indentOutf("JBASE64_Encode(src.get%s().toByteArray(), src.get%s().length(), buffer);\n", uname, uname);
  4339. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4340. }
  4341. indentOuts(-1,"}\n");
  4342. }
  4343. else
  4344. {
  4345. indentOuts("{\n");
  4346. if (nilRemove)
  4347. {
  4348. indentOutf(1,"//*** default kind: %s; type=%s, name=%s\n", getTypeKindName(pi->kind), pi->typname, uname);
  4349. indentOutf("StringBuffer tmp(src.get%s());\n",uname);
  4350. indentOutf("if (tmp.length()>0)\n");
  4351. indentOutf1(1,"buffer.appendf(\"<%s>%%s</%s>\",tmp.str());\n", pi->name,pi->name);
  4352. }
  4353. else
  4354. {
  4355. indentOutf(1,"//*** default kind: %s; type=%s, name=%s\n", getTypeKindName(pi->kind), pi->typname, uname);
  4356. indentOutf("buffer.append(\"<%s>\");\n", pi->getXmlTag());
  4357. indentOutf("buffer.append(src.get%s());\n", uname);
  4358. indentOutf("buffer.append(\"</%s>\");\n", pi->getXmlTag());
  4359. }
  4360. indentOuts(-1,"}\n");
  4361. }
  4362. break;
  4363. }
  4364. }
  4365. free(uname);
  4366. }
  4367. #endif
  4368. outf("\tif (keepRootTag)\n\t\tbuffer.append(\"</%s>\");\n", name_);
  4369. outs("}\n");
  4370. //=============================================================================================================
  4371. //method ==> serialize (MemoryBuffer&, StringBuffer &)
  4372. outf("\nvoid C%s::serialize(IEspContext* ctx, MemoryBuffer& buffer, StringBuffer &mimetype)\n{\n", name_);
  4373. if (contentVar)
  4374. {
  4375. esp_xlate_info *xinfo = esp_xlat(contentVar);
  4376. if (strcmp(xinfo->store_type, "StringBuffer")!=0)
  4377. outf("\tbuffer.clear().append(m_%s.getValue());\n", contentVar->name);
  4378. else
  4379. outf("\tbuffer.clear().append(m_%s.getValue().length(), m_%s.getValue().str());\n", contentVar->name, contentVar->name);
  4380. outf("\tmimetype.set(m_%s_mimetype.str());\n", contentVar->name);
  4381. }
  4382. else
  4383. {
  4384. outs("\tStringBuffer strbuffer;\n");
  4385. outf("\tstrbuffer.append(\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\");\n");
  4386. outf("\tserialize(ctx,strbuffer);\n");
  4387. outs("\tbuffer.append(strbuffer.length(), strbuffer.str());\n");
  4388. outs("\tmimetype.set(\"text/xml; charset=UTF-8\");\n");
  4389. }
  4390. outs("}\n");
  4391. //=============================================================================================================
  4392. //method: unserialize(IRcpMessage...)
  4393. outf("\nbool C%s::unserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath)\n{\n", name_);
  4394. if (parent)
  4395. {
  4396. outf("\tbool hasValue = C%s::unserialize(rpc_request, tagname, basepath);\n", parent);
  4397. outf("\treturn hasValue | localUnserialize(rpc_request, tagname, basepath);\n");
  4398. outs("}\n");
  4399. //method: localUnserialize(IRcpMessage...)
  4400. outf("\nbool C%s::localUnserialize(IRpcMessage& rpc_request, const char *tagname, const char *basepath)\n{\n", name_);
  4401. }
  4402. outs("\trpc_request.setEncodeXml(false);\n");
  4403. outs("\tbool hasValue = false;\n");
  4404. if (espm_type_==espm_response)
  4405. {
  4406. outs(
  4407. "\tStringBuffer xml;\n"
  4408. "\trpc_request.get_value(\"Exceptions\", xml, false);\n\n"
  4409. "\tOwned<IMultiException> me = MakeMultiException();\n"
  4410. "\tif(xml.length() > 0)\n"
  4411. "\t\tme->deserialize(xml.str());\n\n"
  4412. "\tif (me->ordinality() > 0 )\n"
  4413. "\t{\n"
  4414. "\t\tIArrayOf<IException>& exceptions = me->getArray();\n"
  4415. "\t\tForEachItemIn(i, exceptions)\n"
  4416. "\t\t\tnoteException(*LINK(&exceptions.item(i)));\n"
  4417. "\t}\n"
  4418. "\telse\n"
  4419. "\t{\n");
  4420. }
  4421. for (pi=getParams();pi!=NULL;pi=pi->next)
  4422. {
  4423. pi->write_esp_unmarshall("rpc_request", true, (espm_type_==espm_response)?2:1);
  4424. }
  4425. if (getMetaInt("element"))
  4426. {
  4427. outs(1, "hasValue |= rpc_request.get_value(basepath, m_tag_value);\n");
  4428. }
  4429. if (espm_type_==espm_response)
  4430. outs("\t}\n");
  4431. outs("\treturn hasValue;\n");
  4432. outs("}\n");
  4433. //=============================================================================================================
  4434. //method: unserialize(CSoapValue...)
  4435. if (parent)
  4436. {
  4437. outf("\nbool C%s::unserialize(IEspContext* ctx, CSoapValue& soapval, bool localOnly)\n{\n", name_);
  4438. outf("bool hasValue = false;\n");
  4439. outf("\tif(!localOnly)\n");
  4440. outf("\t\thasValue |= C%s::unserialize(ctx,soapval);\n", parent);
  4441. }
  4442. else
  4443. {
  4444. outf("\nbool C%s::unserialize(IEspContext* ctx, CSoapValue& soapval)\n{\n", name_);
  4445. outf("\tbool hasValue = false;\n");
  4446. }
  4447. for (pi=getParams();pi!=NULL;pi=pi->next)
  4448. {
  4449. pi->write_esp_unmarshall_soapval("soapval");
  4450. }
  4451. if (getMetaInt("element"))
  4452. outs(1, "hasValue |= soapval.get_value(\"\",m_tag_value);\n");
  4453. outs("\treturn hasValue;\n");
  4454. outs("}\n");
  4455. //=============================================================================================================
  4456. //method: unserialize(IProperties...)
  4457. if (parent)
  4458. {
  4459. outf("\nbool C%s::unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath, bool localOnly)\n{\n", name_);
  4460. outf("\tbool hasValue = false;\n");
  4461. outf("\tif(!localOnly)\n");
  4462. outf("\t\thasValue |= C%s::unserialize(ctx,params,attachments, basepath);\n", parent);
  4463. }
  4464. else
  4465. {
  4466. outf("\nbool C%s::unserialize(IEspContext* ctx, IProperties& params, MapStrToBuf *attachments, const char *basepath)\n{\n", name_);
  4467. outf("\tbool hasValue = false;\n");
  4468. }
  4469. for (pi=getParams();pi!=NULL;pi=pi->next)
  4470. {
  4471. if (pi->typname && !strcmp(pi->typname, "EspTextFile"))
  4472. {
  4473. pi->write_esp_unmarshall_attachments("params", "attachments");
  4474. indent(1);
  4475. outf("hasValue |= m_%s_name.unmarshall(ctx, params, attachments, \"%s\", basepath%s);\n", pi->name, pi->name, pi->getOptionalParam());
  4476. }
  4477. else
  4478. pi->write_esp_unmarshall_properties("params", "attachments");;
  4479. }
  4480. if (getMetaInt("element"))
  4481. {
  4482. outs(1, "const char* val = params.queryProp(basepath);\n");
  4483. outs(1, "if (val && *val) {\n");
  4484. outs(2, "m_tag_value.set(val);\n");
  4485. outs(2, "hasValue = true;\n");
  4486. outs(1, "}\n");
  4487. }
  4488. outs("\treturn hasValue;\n");
  4489. outs("}\n");
  4490. //outf("\n\tvoid C%s::unserialize(const char * msg)\n\t{\n", name_);
  4491. //for (pi=getParams();pi!=NULL;pi=pi->next)
  4492. //{
  4493. // pi->write_esp_unmarshall("msg");
  4494. //}
  4495. //outs("\t}\n\n");
  4496. outs("\n");
  4497. write_esp_methods();
  4498. //outs("};\n\n");
  4499. write_factory_impl();
  4500. }
  4501. void EspMessageInfo::write_clarion_methods(enum espaxm_type axstype)
  4502. {
  4503. ParamInfo *pi;
  4504. if (axstype!=espaxm_setters)
  4505. {
  4506. if (espm_type_==espm_response)
  4507. outs("queryClientStatus PROCEDURE(),LONG,PROC\n");
  4508. for (pi=getParams();pi!=NULL;pi=pi->next)
  4509. {
  4510. pi->write_clarion_attr_method(false);
  4511. }
  4512. }
  4513. if (axstype!=espaxm_getters)
  4514. {
  4515. for (pi=getParams();pi!=NULL;pi=pi->next)
  4516. {
  4517. pi->write_clarion_attr_method(true);
  4518. }
  4519. }
  4520. }
  4521. void EspMessageInfo::write_esp_mapinfo(bool isDecl)
  4522. {
  4523. #ifdef MAP_INFO
  4524. outs("\nstatic IEspMapInfo& getMapInfo();");
  4525. #endif
  4526. }
  4527. char* makeXsdType(const char* s)
  4528. {
  4529. if (!s)
  4530. return NULL;
  4531. if (*s == '"')
  4532. s++;
  4533. if (strncmp(s,"tns:",4)==0)
  4534. {
  4535. s+=4;
  4536. size_t len = strlen(s);
  4537. if (*(s+len-1)=='"')
  4538. len--;
  4539. char* t = (char*)malloc(len+1);
  4540. memcpy(t,s,len);
  4541. t[len] = 0;
  4542. return t;
  4543. }
  4544. else
  4545. return NULL;
  4546. }
  4547. void EspMessageInfo::write_esp_methods(enum espaxm_type axstype, bool isDecl, bool isPure)
  4548. {
  4549. ParamInfo *pi;
  4550. if (axstype!=espaxm_setters)
  4551. {
  4552. for (pi=getParams();pi!=NULL;pi=pi->next)
  4553. {
  4554. char* xsd = makeXsdType(pi->getMetaString("format_as",NULL));
  4555. pi->write_esp_attr_method(name_, false, getMetaInt("nil_remove")!=0, isDecl, isPure, getMetaInt("trim")!=0,xsd);
  4556. if (xsd)
  4557. free(xsd);
  4558. }
  4559. }
  4560. if (axstype!=espaxm_getters)
  4561. {
  4562. for (pi=getParams();pi!=NULL;pi=pi->next)
  4563. {
  4564. char* xsd = makeXsdType(pi->getMetaString("format_as",NULL));
  4565. pi->write_esp_attr_method(name_, true, getMetaInt("nil_remove")!=0, isDecl, isPure, getMetaInt("trim")!=0,xsd);
  4566. if (xsd)
  4567. free(xsd);
  4568. }
  4569. }
  4570. }
  4571. void EspMessageInfo::write_esp_parms(bool isClientImpl)
  4572. {
  4573. ParamInfo *pi=getParams();
  4574. if (pi)
  4575. {
  4576. if (isClientImpl)
  4577. pi->write_esp_client_impl();
  4578. else
  4579. pi->write_esp_param();
  4580. for (pi=pi->next;pi!=NULL;pi=pi->next)
  4581. {
  4582. if (isClientImpl)
  4583. pi->write_esp_client_impl();
  4584. else
  4585. {
  4586. outs(", ");
  4587. pi->write_esp_param();
  4588. }
  4589. }
  4590. }
  4591. }
  4592. void EspMessageInfo::write_esp_client_method(const char *serv, const char *respname, const char *methname, bool isDecl, bool isPure)
  4593. {
  4594. outs("\n");
  4595. if (isDecl)
  4596. outs("\tvirtual ");
  4597. outf("IClient%s *", respname);
  4598. if (!isDecl && !isPure)
  4599. outf("CClient%s::", serv);
  4600. outf("%sFn(", methname);
  4601. write_esp_parms(false);
  4602. outs(")");
  4603. if (isPure)
  4604. outs("=0");
  4605. if (isDecl)
  4606. outs(";\n");
  4607. else
  4608. {
  4609. outs("\n{\n");
  4610. outf("\tOwned<IClient%s> req = create%sRequest();\n", name_, methname);
  4611. write_esp_parms(true);
  4612. outf("\treturn %s(req.get());\n", methname);
  4613. outs("}\n");
  4614. }
  4615. }
  4616. void EspMessageInfo::write_cpp_interfaces()
  4617. {
  4618. if (espm_type_ == espm_enum)
  4619. {
  4620. // C enum type
  4621. outf("enum C%s { %s_Undefined=-1,", name_, name_);
  4622. const char* base = getParentName();
  4623. bool isIntBase = strieq(base,"int") || strieq(base,"long") || strieq(base,"uint") || strieq(base,"short");
  4624. for (ParamInfo* pi=getParams();pi!=NULL;pi=pi->next)
  4625. {
  4626. outf("C%s_%s", name_, pi->name);
  4627. if (isIntBase) {
  4628. int v = pi->getMetaInt("enum",-1);
  4629. if (v==-1)
  4630. outf("*** invalid value of Enum type");
  4631. outf("=%d",v);
  4632. }
  4633. outs(", ");
  4634. }
  4635. outs("};\n");
  4636. // array
  4637. outf("MAKEValueArray(C%s, %sArray);\n", name_, name_);
  4638. return;
  4639. }
  4640. outf("interface IConst%s : extends ", name_);
  4641. switch (espm_type_)
  4642. {
  4643. case espm_request:
  4644. outs("IEspRequest\n{\n");
  4645. break;
  4646. case espm_response:
  4647. outs("IEspResponse\n{\n");
  4648. break;
  4649. case espm_struct:
  4650. outs("IEspStruct\n{\n");
  4651. break;
  4652. case espm_enum:
  4653. case espm_none:
  4654. assert(!"Code shouldn't be reached");
  4655. break;
  4656. }
  4657. write_esp_methods(espaxm_getters, true, true);
  4658. if (getMetaInt("element")!=0)
  4659. outs(1, "virtual const char * get_tag_value()=0;\n");
  4660. outs("};\n\n");
  4661. outf("interface IEsp%s : extends IConst%s\n{\n", name_, name_);
  4662. write_esp_methods(espaxm_setters, true, true);
  4663. outf("\tvirtual void copy(IConst%s &from)=0;\n", name_);
  4664. if (getMetaInt("element"))
  4665. outs(1, "virtual void set_tag_value(const char *value)=0;\n");
  4666. outs("};\n\n");
  4667. outf("interface IClient%s : extends IInterface\n", name_);
  4668. outs("{\n");
  4669. switch (espm_type_)
  4670. {
  4671. case espm_request:
  4672. write_esp_methods(espaxm_setters, true, true);
  4673. write_esp_mapinfo(true);
  4674. break;
  4675. case espm_response:
  4676. outs("\n\tvirtual int queryClientStatus()=0;\n");
  4677. write_esp_methods(espaxm_getters, true, true);
  4678. if (getMetaInt("exceptions_inline")!=0)
  4679. outs("\n\tvirtual const IMultiException& getExceptions()=0;\n");
  4680. write_esp_mapinfo(true);
  4681. break;
  4682. case espm_struct:
  4683. write_esp_methods(espaxm_setters, true, true);
  4684. write_esp_methods(espaxm_getters, true, true);
  4685. break;
  4686. case espm_enum:
  4687. case espm_none:
  4688. assert(!"Code shouldn't be reached");
  4689. break;
  4690. }
  4691. outs("};\n\n");
  4692. }
  4693. void EspMessageInfo::write_factory_decl()
  4694. {
  4695. switch (espm_type_)
  4696. {
  4697. case espm_struct:
  4698. 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_);
  4699. 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_);
  4700. break;
  4701. case espm_request:
  4702. case espm_response:
  4703. outf("extern \"C\" %s IEsp%s *create%s(const char *serv=NULL);\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_);
  4704. outf("extern \"C\" %s IClient%s *createClient%s(const char *serv=NULL);\n", (esp_def_export_tag) ? esp_def_export_tag : "", name_, name_);
  4705. break;
  4706. case espm_enum:
  4707. // no factory for enum
  4708. return;
  4709. default:
  4710. assert(!"Unhandled espm type");
  4711. }
  4712. }
  4713. void EspMessageInfo::write_factory_impl()
  4714. {
  4715. switch (espm_type_)
  4716. {
  4717. case espm_struct:
  4718. 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_);
  4719. 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_);
  4720. break;
  4721. case espm_request:
  4722. case espm_response:
  4723. 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_);
  4724. 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_);
  4725. break;
  4726. case espm_enum:
  4727. break;
  4728. default:
  4729. assert(!"Unhandled espm type");
  4730. }
  4731. }
  4732. void EspMessageInfo::write_clarion_include_interface()
  4733. {
  4734. static char ifname[256];
  4735. strcpy(ifname, "cppClient");
  4736. strcat(ifname, name_);
  4737. outf("%s INTERFACE(cppInterface),COM\n", ifname);
  4738. if (espm_type_==espm_struct)
  4739. {
  4740. write_clarion_methods(espaxm_setters);
  4741. write_clarion_methods(espaxm_getters);
  4742. }
  4743. else if (espm_type_==espm_request)
  4744. write_clarion_methods(espaxm_setters);
  4745. else
  4746. write_clarion_methods(espaxm_getters);
  4747. outs(" END\n\n");
  4748. }
  4749. EspMessageInfo *EspMethodInfo::getRequestInfo()
  4750. {
  4751. EspMessageInfo *msg = hcp->msgs;
  4752. for(;msg!=NULL; msg=msg->next)
  4753. {
  4754. if (!strcmp(msg->getName(), request_))
  4755. return msg;
  4756. }
  4757. return NULL;
  4758. }
  4759. bool EspMethodInfo::write_mapinfo_check(const char* ctxvar)
  4760. {
  4761. StrBuffer minVer, maxVer;
  4762. bool hasMin = getMetaVerInfo("min_ver", minVer);
  4763. bool hasMax = getMetaVerInfo("max_ver", maxVer);
  4764. bool hasOutput = false;
  4765. if (hasMin || hasMax)
  4766. {
  4767. hasOutput = true;
  4768. indentOuts("if (");
  4769. if (hasMin && hasMax)
  4770. outf("(%s.getClientVersion()>=%s && %s.getClientVersion()<=%s)", ctxvar, minVer.str(), ctxvar, maxVer.str());
  4771. else if (hasMin)
  4772. outf("%s.getClientVersion()>=%s", ctxvar,minVer.str());
  4773. else
  4774. outf("%s.getClientVersion()<=%s", ctxvar,maxVer.str());
  4775. }
  4776. const char* optional = getMetaString("optional", NULL);
  4777. if (optional)
  4778. {
  4779. if (hasOutput)
  4780. outs(" && ");
  4781. else
  4782. {
  4783. indentOuts("if (");
  4784. hasOutput = true;
  4785. }
  4786. const char* quote = (*optional == '"') ? "":"\"";
  4787. outf("%s.checkOptional(%s%s%s)", ctxvar, quote,optional,quote);
  4788. }
  4789. if (hasOutput)
  4790. {
  4791. outs(") {\n");
  4792. indentInc(1);
  4793. }
  4794. return hasOutput;
  4795. }
  4796. void EspMethodInfo::write_esp_method(const char *serv, bool isDecl, bool isPure)
  4797. {
  4798. EspMessageInfo *req = getRequestInfo();
  4799. if (req)
  4800. {
  4801. req->write_esp_client_method(serv, getResp(), name_, isDecl, isPure);
  4802. }
  4803. }
  4804. void EspServInfo::write_factory_impl()
  4805. {
  4806. outs("extern \"C\"");
  4807. if (esp_def_export_tag)
  4808. outf(" %s", esp_def_export_tag);
  4809. outf(" IClient%s * create%sClient() { return new CClient%s(); }\n", name_, name_, name_);
  4810. }
  4811. void EspServInfo::write_esp_binding_ipp()
  4812. {
  4813. EspMethodInfo *mthi=NULL;
  4814. int useMethodName = getMetaInt("use_method_name", 0);
  4815. outf("\n\nclass C%sSoapBinding : public CHttpSoapBinding\n", name_);
  4816. outs("{\npublic:\n");
  4817. //dom
  4818. outf("\tC%sSoapBinding(http_soap_log_level level=hsl_none);\n", name_);
  4819. outf("\tC%sSoapBinding(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL, http_soap_log_level level=hsl_none);\n", name_);
  4820. outs("\tvirtual void init_strings();\n");
  4821. //method ==> processRequest
  4822. outs("\tvirtual int processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response);\n");
  4823. //method ==> getXsdDefinition
  4824. outs("\tint getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &content, const char *service, const char *method, bool mda);\n");
  4825. //method ==> getMethodHtmlForm
  4826. outs("\tvirtual int getMethodHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &page, bool bIncludeFormTag);\n");
  4827. //method ==> getQualifiedNames
  4828. outs("\tint getQualifiedNames(IEspContext& ctx, MethodInfoArray & methods);\n");
  4829. //method ==> getServiceName
  4830. outs("\tStringBuffer & getServiceName(StringBuffer &resp);\n");
  4831. //method ==> isValidServiceName
  4832. outs("\tbool isValidServiceName(IEspContext &context, const char *name);\n");
  4833. //method ==> qualifyMethodName
  4834. outs("\tbool qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName);\n");
  4835. //method ==> qualifyServiceName
  4836. outs("\tbool qualifyServiceName(IEspContext &context, const char *servname, const char *methname, StringBuffer &servQName, StringBuffer *methQName);\n");
  4837. //method ==> onGetFile
  4838. outs("\tvirtual int onGetFile(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *pathex);\n");
  4839. //Method ==> onGetForm
  4840. outs("\tvirtual int onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);\n");
  4841. //Method ==> onGetXForm
  4842. //if (getMetaInt("use_new_form",0))
  4843. outs("\tvirtual int onGetXForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);\n");
  4844. //Method ==> supportGeneratedForms
  4845. if (getMetaInt("noforms", 0))
  4846. outs("\tvirtual bool supportGeneratedForms(){return false;}\n");
  4847. if (getMetaInt("no_ws_index", 0))
  4848. {
  4849. //Method ==> onGetIndex
  4850. outs("\tvirtual int onGetIndex(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service)\n");
  4851. outs("\t{\n");
  4852. outs("\t\treturn onGetNotFound(context, request, response, service);\n");
  4853. outs("\t}\n");
  4854. }
  4855. //Method ==> onGetService
  4856. outs("\tvirtual int onGetService(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method, const char *pathex);\n");
  4857. //Method ==> createReqBinding
  4858. outs(1, "virtual IRpcRequestBinding *createReqBinding(IEspContext &context, IHttpMessage* request, const char *service, const char *method);\n");
  4859. //Method ==> onGetInstantQuery
  4860. outs("\tvirtual int onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);\n");
  4861. //Method ==> xslTransform
  4862. if (needsXslt)
  4863. {
  4864. outs("\tvoid setXslProcessor(IInterface *xslp_){xslp.set(dynamic_cast<IXslProcessor *>(xslp_));}\n");
  4865. outs("private:\n");
  4866. outs("\tOwned<IXslProcessor> xslp;\n");
  4867. outs("\tvoid xslTransform(const char* xml, const char* xslFile, StringBuffer& output, IProperties *params)\n"
  4868. "\t{\n"
  4869. "\t\tif (xslp)\n"
  4870. "\t\t{\n"
  4871. "\t\t\tOwned<IXslTransform> xform = xslp->createXslTransform();\n"
  4872. "\t\t\tStringBuffer xslpath;\n"
  4873. "\t\t\tif (!strnicmp(xslFile, \"/esp/xslt/\", 10))\n"
  4874. "\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"
  4875. "\t\t\t\t\treturn;\n"
  4876. "\t\t\txform->setXslSource((xslpath.length()) ? xslpath.str() : xslFile);\n"
  4877. "\t\t\txform->setXmlSource(xml, strlen(xml)+1);\n"
  4878. "\t\t\tif (params) xform->copyParameters(params);\n"
  4879. "\t\t\txform->transform(output.clear());\n"
  4880. "\t\t}\n"
  4881. "\t}\n");
  4882. }
  4883. else
  4884. outs("\tvoid setXslProcessor(IInterface *xslp){}\n");
  4885. outs("};\n\n");
  4886. }
  4887. void EspServInfo::write_esp_binding()
  4888. {
  4889. EspMethodInfo *mthi=NULL;
  4890. int useMethodName = getMetaInt("use_method_name", 0);
  4891. StrBuffer wsdlVer;
  4892. bool hasVersion = getMetaVerInfo(tags,"version",wsdlVer);
  4893. if (!hasVersion)
  4894. wsdlVer.append("1");
  4895. //comment
  4896. outs("\n//=======================================================");
  4897. outf("\n// class C%sSoapBinding Implementation", name_);
  4898. outs("\n//=======================================================");
  4899. outs("\n");
  4900. 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());
  4901. 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());
  4902. outf("\nvoid C%sSoapBinding::init_strings()\n", name_);
  4903. outs("{\n");
  4904. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  4905. {
  4906. StrBuffer val;
  4907. mthi->getMetaStringValue(val,"description");
  4908. if (val.length()) {
  4909. StrBuffer tmp;
  4910. outf("\taddMethodDescription(\"%s\", \"%s\");\n", mthi->getName(), printfEncode(val.str(), tmp).str());
  4911. }
  4912. mthi->getMetaStringValue(val.clear(),"help");
  4913. if (val.length()) {
  4914. StrBuffer tmp;
  4915. outf("\taddMethodHelp(\"%s\", \"%s\");\n", mthi->getName(), printfEncode(val.str(), tmp).str());
  4916. }
  4917. }
  4918. outs("}\n");
  4919. outf("\nint C%sSoapBinding::processRequest(IRpcMessage* rpc_call, IRpcMessage* rpc_response)\n", name_);
  4920. outs("{\n");
  4921. outs("\tif(rpc_call == NULL || rpc_response == NULL)\n\t\treturn -1;\n\n");
  4922. outs(1, "IEspContext *ctx=rpc_call->queryContext();\n");
  4923. outs(1, "DBGLOG(\"Client version: %g\", ctx->getClientVersion());\n");
  4924. outs(1, "StringBuffer serviceName;\n");
  4925. outs(1, "double clientVer=(ctx) ? ctx->getClientVersion() : 0.0;\n");
  4926. outs(1, "qualifyServiceName(*ctx, ctx->queryServiceName(NULL), NULL, serviceName, NULL);\n");
  4927. outs(1, "CRpcCall* thecall = dynamic_cast<CRpcCall *>(rpc_call);\n");
  4928. outs(1, "CRpcResponse* response = dynamic_cast<CRpcResponse*>(rpc_response);\n\n");
  4929. outf("\tOwned<IEsp%s> iserv = (IEsp%s*)getService();\n", name_, name_);
  4930. outs("\tif(iserv == NULL)\n");
  4931. outs("\t{\n");
  4932. outs("\t\tresponse->set_status(SOAP_SERVER_ERROR);\n");
  4933. outs("\t\tresponse->set_err(\"Service not available\");\n");
  4934. outs("\t\tDBGLOG(\"Service not available\");\n");
  4935. outs("\t\treturn -1;\n\t}\n");
  4936. outs("\tif (thecall->get_name() == NULL)\n");
  4937. outs("\t{\n");
  4938. outs("\t\tresponse->set_status(SOAP_CLIENT_ERROR);\n");
  4939. outs("\t\tresponse->set_err(\"No service method specified\");\n");
  4940. outs("\t\tERRLOG(\"No service method specified\");\n");
  4941. outs("\t\treturn -1;\n");
  4942. outs("\t}\n");
  4943. outs("\n\tIEspContext& context = *rpc_call->queryContext();\n\n");
  4944. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  4945. {
  4946. outf("\tif(!stricmp(thecall->get_name(), \"%s\")||!stricmp(thecall->get_name(), \"%s\"))\n", mthi->getName(), mthi->getReq());
  4947. outs("\t{\n");
  4948. //esp_request + esp_response can persist longer than the scope of this method
  4949. outf("\t\tOwned<C%s> esp_request = new C%s(serviceName.str(), thecall);\n", mthi->getReq(), mthi->getReq());
  4950. outs("\t\tcheckRequest(context);\n");
  4951. outf("\t\tOwned<C%s> esp_response = new C%s(serviceName.str());\n", mthi->getResp(), mthi->getResp());
  4952. StrBuffer minVer;
  4953. bool hasMinVer = mthi->getMetaVerInfo("min_ver", minVer);
  4954. bool bHandleExceptions = 0 != mthi->getMetaInt("exceptions_inline", 0);
  4955. if (!bHandleExceptions)
  4956. bHandleExceptions = 0 != getMetaInt("exceptions_inline", 0);
  4957. //begin try block
  4958. if (bHandleExceptions)
  4959. {
  4960. outs("\t\tStringBuffer source;\n");
  4961. outf("\t\tsource.appendf(\"%s::%%s()\", thecall->get_name());\n", name_);
  4962. outf("\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  4963. outs("\t\ttry\n");
  4964. outs("\t\t{\n");
  4965. if (hasMinVer)
  4966. {
  4967. outf("\t\t\tif (clientVer!=-1.0 && clientVer<%s)\n", minVer.str());
  4968. outs("\t\t\t\tthrow MakeStringException(-1, \"Client version is too old, please update your client application.\");");
  4969. }
  4970. outs("\t\t\tresponse->set_status(SOAP_OK);\n");
  4971. outf("\t\t\tiserv->on%s(context, *esp_request, *esp_response);\n", mthi->getName());
  4972. outs("\t\t}\n");
  4973. write_catch_blocks(mthi, ct_soapresp, 2);
  4974. }
  4975. else
  4976. {
  4977. if (hasMinVer)
  4978. {
  4979. outf("\t\tif (clientVer!=-1.0 && clientVer<%s)\n", minVer.str());
  4980. outs("\t\t\tthrow MakeStringException(-1, \"Client version is too old (can't pass exception to client)\");\n");
  4981. }
  4982. if (mthi->getMetaInt("do_not_log",0))
  4983. outs("\t\tcontext.queryRequestParameters()->setProp(\"do_not_log\",1);\n");
  4984. outf("\t\tiserv->on%s(*rpc_call->queryContext(), *esp_request, *esp_response);\n", mthi->getName());
  4985. outs("\t\tresponse->set_status(SOAP_OK);\n");
  4986. }
  4987. outf("\t\tresponse->set_name(\"%s\");\n", mthi->getResp());
  4988. outs("\t\tesp_response->serialize(*response);\n");
  4989. outs("\t\treturn 0;\n\t}\n\n");
  4990. }
  4991. outs("\tresponse->set_status(SOAP_CLIENT_ERROR);\n");
  4992. outs("\tStringBuffer msg, svcName;\n");
  4993. outs("\tmsg.appendf(\"Method %s not available in service %s\",thecall->get_name(),getServiceName(svcName).str());\n");
  4994. outs("\tERRLOG(msg);\n");
  4995. outs("\tresponse->set_err(msg);\n");
  4996. outs("\treturn -1;\n");
  4997. outs("}\n");
  4998. //method ==> getXsdDefinition
  4999. outf("\nint C%sSoapBinding::getXsdDefinition(IEspContext &context, CHttpRequest* request, StringBuffer &content, const char *service, const char *method, bool mda)\n", name_);
  5000. outs("{\n");
  5001. outs("\tBoolHash added;\n");
  5002. // version
  5003. if (hasVersion)
  5004. {
  5005. outs("\tif (context.getClientVersion()<=0)\n");
  5006. outf("\t\tcontext.setClientVersion(%s);\n\n", wsdlVer.str());
  5007. }
  5008. outs("\tDBGLOG(\"Client version: %g\", context.getClientVersion());\n");
  5009. // kept for backward compatible
  5010. EspStructInfo *sti=NULL;
  5011. for (sti=structs;sti!=NULL;sti=sti->next)
  5012. {
  5013. outf("\tC%s::getXsdDefinition(context, request, content, added);\n", sti->getName());
  5014. }
  5015. indentReset(1);
  5016. outf(1, "bool fullservice = (!Utils::strcasecmp(service, \"%s\"));\n", name_);
  5017. indentOuts("bool allMethods = (method==NULL || *method==0);\n");
  5018. bool needPropsDeclare = true;
  5019. bool needAccessFlagDeclare = true;
  5020. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5021. {
  5022. const char *requestName = (useMethodName) ? mthi->getName() : mthi->getReq();
  5023. const char *optional=mthi->getMetaString("optional", NULL);
  5024. const char *access=mthi->getMetaString("access", NULL);
  5025. if (optional)
  5026. {
  5027. if (needPropsDeclare)
  5028. {
  5029. indentOuts("IProperties *props = request->queryParameters();\n");
  5030. needPropsDeclare = false;
  5031. }
  5032. indentOutf("if (props && props->hasProp(%s)) {\n", optional);
  5033. indentInc(1);
  5034. }
  5035. if (access)
  5036. {
  5037. if (needAccessFlagDeclare)
  5038. {
  5039. indentOuts("SecAccessFlags acc;\n");
  5040. needAccessFlagDeclare = false;
  5041. }
  5042. indentOutf("if (context.authorizeFeature(%s, acc) && acc>=SecAccess_Read) {\n", access);
  5043. indentInc(1);
  5044. }
  5045. indentOutf("if ((allMethods&&(fullservice||isMethodInSubService(context, service, \"%s\"))) || Utils::strcasecmp(method, \"%s\")==0)\n", mthi->getName(), mthi->getName());
  5046. indentOuts("{\n");
  5047. indentInc(1);
  5048. bool hasMap = mthi->write_mapinfo_check("context");
  5049. indentOutf("C%s::getMapInfo(context.queryMapInfo());\n", mthi->getReq());
  5050. indentOutf("C%s::getMapInfo(context.queryMapInfo());\n", mthi->getResp());
  5051. indentOutf("C%s::getXsdDefinition(context, request, \"%s\", content, added);\n", mthi->getReq(), requestName);
  5052. indentOutf("C%s::getXsdDefinition(context, request, content, added);\n", mthi->getResp());
  5053. if (hasMap)
  5054. indentOuts(-1,"}\n");
  5055. indentOuts(-1,"}\n");
  5056. if (access)
  5057. indentOuts(-1,"}\n");
  5058. if (optional)
  5059. indentOuts(-1,"}\n");
  5060. }
  5061. indentOuts("return 0;\n");
  5062. indentOuts(-1,"}\n");
  5063. //method ==> getMethodHtmlForm
  5064. outf("\nint C%sSoapBinding::getMethodHtmlForm(IEspContext &context, CHttpRequest* request, const char *serv, const char *method, StringBuffer &page, bool bIncludeFormTag)\n", name_);
  5065. outs("{\n");
  5066. outf("\tDBGLOG(\"Client version: %%g\", context.getClientVersion());\n");
  5067. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5068. {
  5069. outf("\tif (Utils::strcasecmp(method, \"%s\")==0)\n", mthi->getName());
  5070. outs("\t{\n");
  5071. outf("\t\tC%s::getHtmlForm(context, request, serv, method, page);\n", mthi->getReq());
  5072. outs("\t}\n");
  5073. }
  5074. outs("\treturn 0;\n");
  5075. outs("}\n");
  5076. //method ==> getQualifiedNames
  5077. outf("\nint C%sSoapBinding::getQualifiedNames(IEspContext& ctx, MethodInfoArray & methods)\n", name_);
  5078. outs("{\n");
  5079. outs(1, "double ver = ctx.getClientVersion();\n");
  5080. outs(1, "if (ver<=0)\n");
  5081. outs(2, "ver = getWsdlVersion();\n");
  5082. outs(1, "const char *servname=ctx.queryServiceName(NULL);\n");
  5083. outf(1, "bool fullservice = (!stricmp(servname, \"esp\")||!stricmp(servname, \"%s\"));\n", name_);
  5084. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5085. {
  5086. if (!mthi->getMetaInt("noform",0))
  5087. {
  5088. const char *optional=mthi->getMetaString("optional", "NULL");
  5089. const char *access=mthi->getMetaString("access", "NULL");
  5090. const char *method_name = (getMetaInt("use_method_name")!=0) ? mthi->getName() : mthi->getReq();
  5091. StrBuffer minVer, maxVer;
  5092. bool hasMinVer = mthi->getMetaVerInfo("min_ver",minVer);
  5093. bool hasMaxVer = mthi->getMetaVerInfo("max_ver",maxVer);
  5094. outf("\tif ((fullservice || isMethodInSubService(ctx, servname, \"%s\")) && ctx.isMethodAllowed(ver,%s, %s, %s, %s))\n",
  5095. mthi->getName(), optional, access, hasMinVer ? minVer.str() : "-1", hasMaxVer ? maxVer.str() : "-1");
  5096. outf("\t\tmethods.append(*new CMethodInfo(\"%s\", \"%s\", \"%s\"));\n", mthi->getName(), method_name, mthi->getResp());
  5097. }
  5098. }
  5099. outs("\treturn methods.ordinality();\n");
  5100. outs("}\n");
  5101. //method ==> getServiceName
  5102. outf("\nStringBuffer & C%sSoapBinding::getServiceName(StringBuffer &resp)\n", name_);
  5103. outs("{\n");
  5104. outf("\tresp.append(\"%s\");\n", name_);
  5105. outs("\treturn resp;\n");
  5106. outs("}\n");
  5107. //method ==> isValidServiceName
  5108. outf("\nbool C%sSoapBinding::isValidServiceName(IEspContext &context, const char *name)\n", name_);
  5109. outs("{\n");
  5110. outf(1, "if (!Utils::strcasecmp(name, \"%s\"))\n", name_);
  5111. outs(2, "return true;\n");
  5112. outs(1, "else\n");
  5113. outs(2, "return (hasSubService(context, name));\n");
  5114. outs("}\n");
  5115. //method ==> qualifyMethodName
  5116. outf("\nbool C%sSoapBinding::qualifyMethodName(IEspContext &context, const char *methname, StringBuffer *methQName)\n", name_);
  5117. outs("{\n");
  5118. outs("\tif (!methname || !*methname)\n");
  5119. outs("\t{\n");
  5120. outs("\t\tif (methQName!=NULL)\n");
  5121. outs("\t\t\tmethQName->clear();\n");
  5122. outs("\t\treturn true;\n");
  5123. outs("\t}\n");
  5124. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5125. {
  5126. outf("\tif (Utils::strcasecmp(methname, \"%s\")==0)\n", mthi->getName());
  5127. outs("\t{\n");
  5128. outs("\t\tif (methQName!=NULL)\n");
  5129. outf("\t\t\tmethQName->set(\"%s\");\n", mthi->getName());
  5130. outs("\t\treturn true;\n");
  5131. outs("\t}\n");
  5132. }
  5133. outs("\treturn false;\n");
  5134. outs("}\n");
  5135. //method ==> qualifyServiceName
  5136. outf("\nbool C%sSoapBinding::qualifyServiceName(IEspContext &context, const char *servname, const char *methname, StringBuffer &servQName, StringBuffer *methQName)\n", name_);
  5137. outs("{\n");
  5138. outs(1, "servQName.clear();\n");
  5139. outf(1, "if (!Utils::strcasecmp(servname, \"%s\"))\n", name_);
  5140. outs(1, "{\n");
  5141. outf(2, "servQName.append(\"%s\");\n", name_);
  5142. outs(2, "return qualifyMethodName(context, methname, methQName);\n");
  5143. outs(1, "}\n");
  5144. outs(1, "return qualifySubServiceName(context, servname, methname, servQName, methQName);\n");
  5145. outs("}\n");
  5146. //method ==> onGetFile
  5147. outf("\nint C%sSoapBinding::onGetFile(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *pathex)\n", name_);
  5148. outs("{\n");
  5149. outs("\tif(request == NULL || response == NULL)\n");
  5150. outs("\t\treturn -1;\n");
  5151. outs("\tStringBuffer mimetype;\n");
  5152. outs("\tMemoryBuffer content;\n\n");
  5153. outs("\tStringBuffer filepath;\n");
  5154. outs("\tgetBaseFilePath(filepath);\n");
  5155. outs("\tif (strchr(\"\\\\/\", filepath.charAt(filepath.length()-1))==NULL)\n");
  5156. outs("\t\tfilepath.append(\"/\");\n");
  5157. outs("\tfilepath.append(pathex);\n");
  5158. outs("\tresponse->httpContentFromFile(filepath.str());\n");
  5159. outs("\tresponse->send();\n");
  5160. outs("\treturn 0;\n");
  5161. outs("}\n");
  5162. //Method ==> onGetForm
  5163. outf("\nint C%sSoapBinding::onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)\n", name_);
  5164. outs("{\n");
  5165. if (getMetaInt("noforms", 0))
  5166. {
  5167. outs("\treturn onGetNotFound(context, request, response, service);\n");
  5168. }
  5169. else
  5170. {
  5171. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5172. {
  5173. if (mthi->getMetaInt("noform", 0))
  5174. {
  5175. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5176. outs("\t\treturn onGetNotFound(context, request, response, service);\n");
  5177. }
  5178. else
  5179. {
  5180. const char *formHtmlPath = mthi->getMetaString("form_html", NULL);
  5181. if (formHtmlPath)
  5182. {
  5183. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5184. outs("\t{\n");
  5185. outf("\t\tresponse->httpContentFromFile(%s);\n", formHtmlPath);
  5186. outs("\t\tresponse->send();\n");
  5187. outs("\t\treturn 0;\n");
  5188. outs("\t}\n");
  5189. }
  5190. }
  5191. }
  5192. // normal test form
  5193. if (hasVersion)
  5194. {
  5195. outs("\tif (context.getClientVersion()<=0)\n");
  5196. outf("\t\tcontext.setClientVersion(%s);\n\n", wsdlVer.str());
  5197. }
  5198. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5199. {
  5200. outf("\tif (!stricmp(\"%s\", method)) {\n", mthi->getName());
  5201. if (mthi->getMetaInt("use_new_form",0))
  5202. outs("\t\treturn EspHttpBinding::onGetXForm(context, request, response, service, method);\n");
  5203. else {
  5204. outf("\t\tC%s::getMapInfo(context.queryMapInfo());\n", mthi->getReq());
  5205. outf("\t\tC%s::getMapInfo(context.queryMapInfo());\n", mthi->getResp());
  5206. }
  5207. outs("\t}\n");
  5208. }
  5209. outs("\n\treturn EspHttpBinding::onGetForm(context, request, response, service, method);\n");
  5210. }
  5211. outs("}\n");
  5212. // method ==> onGetXForm
  5213. outf("int C%sSoapBinding::onGetXForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)\n", name_);
  5214. outs("{\n");
  5215. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5216. {
  5217. if (mthi->getMetaInt("use_new_form",0))
  5218. {
  5219. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5220. outs("\t\treturn EspHttpBinding::onGetForm(context, request, response, service, method);\n");
  5221. }
  5222. }
  5223. outs("\treturn EspHttpBinding::onGetXForm(context, request, response, service, method);\n");
  5224. outs("}\n");
  5225. if (getMetaInt("no_ws_index", 0))
  5226. {
  5227. //Method ==> onGetIndex
  5228. outf("\nint C%sSoapBinding::onGetIndex(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service)\n", name_);
  5229. outs("{\n");
  5230. outs("\treturn onGetNotFound(context, request, response, service);\n");
  5231. outs("}\n");
  5232. }
  5233. //Method ==> onGetService
  5234. outf("\nint C%sSoapBinding::onGetService(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method, const char *pathex)\n", name_);
  5235. outs("{\n");
  5236. outs("\tif(request == NULL || response == NULL)\n");
  5237. outs("\t\treturn -1;\n");
  5238. EspMountInfo *mnt;
  5239. for (mnt=mounts;mnt!=NULL;mnt=mnt->next)
  5240. {
  5241. outs("\t");
  5242. if (mnt!=mounts)
  5243. outs("else ");
  5244. outf("if(!stricmp(method, \"%s\"))\n", mnt->getName());
  5245. outs("\t{\n");
  5246. outs("\t\tMemoryBuffer content;\n");
  5247. outs("\t\tStringBuffer mimetype;\n");
  5248. outf("\t\tStringBuffer filepath(%s);\n\n", mnt->getLocalPath());
  5249. outs("\t\tif (filepath.length()>0 && strchr(\"/\\\\\", filepath.charAt(filepath.length()-1))==NULL)\n");
  5250. outs("\t\t{\n");
  5251. outs("\t\t\tfilepath.append(\"/\");\n");
  5252. outs("\t\t}\n");
  5253. outs("\t\tfilepath.append((pathex!=NULL && *pathex!=0) ? pathex : \"index.html\");\n\n");
  5254. outs("\t\tif (!response->httpContentFromFile(filepath.str()))\n");
  5255. outs("\t\t{\n");
  5256. outs("\t\t\treturn onGetQuery(context, request, response, service, method);\n");
  5257. outs("\t\t}\n");
  5258. outs("\t\tresponse->send();\n");
  5259. outs("\t\treturn 0;\n");
  5260. outs("\t}\n");
  5261. }
  5262. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5263. {
  5264. int formIsDefault = mthi->getMetaInt("form_is_default");
  5265. if (formIsDefault)
  5266. {
  5267. outf("\tif (!stricmp(\"%s\", method))\n", mthi->getName());
  5268. outs("\t{\n");
  5269. outs("\treturn onGetForm(context, request, response, service, method);\n");
  5270. outs("\t}\n");
  5271. }
  5272. }
  5273. outs("\treturn onGetQuery(context, request, response, service, method);\n");
  5274. outs("}\n");
  5275. outf("\n IRpcRequestBinding *C%sSoapBinding::createReqBinding(IEspContext &context, IHttpMessage *ireq, const char *service, const char *method)\n", name_);
  5276. outs("{\n");
  5277. outs(1, "CHttpRequest *request=dynamic_cast<CHttpRequest*>(ireq);\n");
  5278. outs(1, "IProperties *props = (request) ? request->queryParameters() : NULL;\n\n");
  5279. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5280. {
  5281. outf(1, "if (!stricmp(method, \"%s\") || !stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5282. outf(2, "return new C%s(&context, \"%s\", props, NULL);\n", mthi->getReq(), name_);
  5283. }
  5284. outs(1, "return NULL;\n");
  5285. outs("}\n");
  5286. //Method ==> onGetInstantQuery
  5287. outf("\nint C%sSoapBinding::onGetInstantQuery(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method)\n", name_);
  5288. outs("{\n");
  5289. StrBuffer defVer;
  5290. bool hasDefVer = getMetaVerInfo(tags,"default_client_version",defVer);
  5291. if (hasDefVer)
  5292. {
  5293. outf("\tif (context.getClientVersion()<=0)\n");
  5294. outf("\t\tcontext.setClientVersion(%s);\n\n", defVer.str());
  5295. }
  5296. outs("\tif(request == NULL || response == NULL)\n");
  5297. outs("\t\treturn -1;\n");
  5298. outs("\tStringBuffer respStr;\n");
  5299. outf("\tOwned<IEsp%s> iserv = (IEsp%s*)getService();\n", name_, name_);
  5300. outs("\tif(iserv == NULL)\n");
  5301. outs("\t{\n");
  5302. outs("\t\trespStr.append(\"Service not available\");\n");
  5303. outs("\t\tresponse->setContent(respStr.str());\n");
  5304. outs("\t\tresponse->setContentType(\"text/html\");\n");
  5305. outs("\t\tresponse->send();\n");
  5306. outs("\t}\n");
  5307. outs("\telse\n");
  5308. outs("\t{\n");
  5309. #ifdef NEW_INSTANT_QUERY
  5310. outf("\t\tOwned<CSoapResponseBinding> esp_response;\n");
  5311. outf("\t\tStringBuffer source;\n");
  5312. outf("\t\tIEspContext& context = *request->queryContext();\n");
  5313. #endif
  5314. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5315. {
  5316. bool bClientXslt=false;
  5317. const char *respXsl = mthi->getMetaString("resp_xsl_default", NULL);
  5318. const char *respContentType = mthi->getMetaString("http_content_type", "\"text/html\"");
  5319. if (!respXsl)
  5320. {
  5321. respXsl = mthi->getMetaString("client_xslt", NULL);
  5322. bClientXslt=(respXsl!=NULL);
  5323. }
  5324. bool bHandleExceptions = 0 != mthi->getMetaInt("exceptions_inline", 0) || mthi->getMetaInt("http_exceptions_inline", 0);
  5325. if (!bHandleExceptions)
  5326. bHandleExceptions = 0 != getMetaInt("exceptions_inline", 0) || getMetaInt("http_exceptions_inline", 0);
  5327. if (respXsl==NULL)
  5328. {
  5329. #ifdef NEW_INSTANT_QUERY
  5330. // reduce the code size significantly
  5331. outf("\t\tif(!stricmp(method, \"%s\")||!stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5332. outs("\t\t{\n");
  5333. outf("\t\t\tOwned<C%s> esp_request = new C%s(&context, \"%s\", request->queryParameters(), request->queryAttachments());\n", mthi->getReq(), mthi->getReq(), name_);
  5334. outf("\t\t\tcheckRequest(context);\n");
  5335. outf("\t\t\tC%s* resp = new C%s(\"%s\");\n", mthi->getResp(), mthi->getResp(), name_);
  5336. outf("\t\t\tesp_response.setown(resp);\n");
  5337. if (bHandleExceptions)
  5338. {
  5339. outf("\t\t\tsource.setf(\"%s::%%s()\", method);\n", name_);
  5340. outf("\t\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  5341. //begin try block
  5342. outs("\t\t\ttry\n");
  5343. outs("\t\t\t{\n");
  5344. if (mthi->getMetaInt("do_not_log",0))
  5345. outf("\t\t\t\tcontext.queryRequestParameters()->setProp(\"do_not_log\",1);\n");
  5346. outf("\t\t\t\tiserv->on%s(context, *esp_request.get(), *resp);\n", mthi->getName());
  5347. outs("\t\t\t}\n");
  5348. write_catch_blocks(mthi, ct_httpresp, 3);
  5349. }
  5350. else
  5351. outf("\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *resp);\n", mthi->getName());
  5352. outs("\t\t}\n");
  5353. #else
  5354. outf("\t\tif(!stricmp(method, \"%s\")||!stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5355. outs("\t\t{\n");
  5356. outs("\t\t\tMemoryBuffer content;\n");
  5357. outs("\t\t\tStringBuffer mimetype;\n");
  5358. outf("\t\t\tOwned<C%s> esp_request = new C%s(&context, \"%s\", request->queryParameters(), request->queryAttachments());\n", mthi->getReq(), mthi->getReq(), name_);
  5359. outf("\t\t\tOwned<C%s> esp_response = new C%s(&context, \"%s\");\n", mthi->getResp(), mthi->getResp(), name_);
  5360. if (bHandleExceptions)
  5361. {
  5362. outs("\t\t\tStringBuffer source;\n");
  5363. outf("\t\t\tsource.appendf(\"%s::%%s()\", method);\n", name_);
  5364. outf("\t\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  5365. //begin try block
  5366. outs("\t\t\ttry\n");
  5367. outs("\t\t\t{\n");
  5368. outf("\t\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *esp_response.get());\n", mthi->getName());
  5369. outs("\t\t\t}\n");
  5370. write_catch_blocks(mthi, ct_httpresp, 3);
  5371. }
  5372. else
  5373. outf("\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *esp_response.get());\n", mthi->getName());
  5374. outs("\t\t\tif (esp_response->getRedirectUrl() && *esp_response->getRedirectUrl())\n");
  5375. outs("\t\t\t{\n");
  5376. outs("\t\t\t\tresponse->redirect(*request, esp_response->getRedirectUrl());\n");
  5377. outs("\t\t\t}\n");
  5378. outs("\t\t\telse\n");
  5379. outs("\t\t\t{\n");
  5380. outs("\t\t\t\tStringBuffer resultsHtml;\n");
  5381. outs("\t\t\t\tStringBuffer htmlPage;\n");
  5382. outs("\t\t\t\tIProperties *props=request->queryParameters();\n");
  5383. outs("\t\t\t\tesp_response->serialize(context, content, mimetype);\n");
  5384. outs("\t\t\t\onBeforeSendResponse(context,request,content,service,method);\n");
  5385. outs("\t\t\t\tresponse->setContent(content.length(), content.toByteArray());\n");
  5386. outs("\t\t\t\tresponse->setContentType(mimetype.str());\n");
  5387. outs("\t\t\t\tresponse->send();\n");
  5388. outs("\t\t\t}\n");
  5389. outs("\t\t\treturn 0;\n");
  5390. outs("\t\t}\n");
  5391. #endif
  5392. }
  5393. else
  5394. {
  5395. outf("\t\tif(!stricmp(method, \"%s\")||!stricmp(method, \"%s\"))\n", mthi->getName(), mthi->getReq());
  5396. outs("\t\t{\n");
  5397. outf("\t\t\tOwned<C%s> esp_request = new C%s(&context, \"%s\", request->queryParameters(), request->queryAttachments());\n", mthi->getReq(), mthi->getReq(), name_);
  5398. outf("\t\t\tcheckRequest(context);\n");
  5399. outf("\t\t\tOwned<C%s> esp_response = new C%s(\"%s\");\n", mthi->getResp(), mthi->getResp(), name_);
  5400. if (bHandleExceptions)
  5401. {
  5402. outs("\t\t\tStringBuffer source;\n");
  5403. outf("\t\t\tsource.appendf(\"%s::%%s()\", method);\n", name_);
  5404. outf("\t\t\tOwned<IMultiException> me = MakeMultiException(source.str());\n");
  5405. //begin try block
  5406. outs("\t\t\ttry\n");
  5407. outs("\t\t\t{\n");
  5408. outf("\t\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *esp_response.get());\n", mthi->getName());
  5409. outs("\t\t\t}\n");
  5410. write_catch_blocks(mthi, ct_httpresp,3);
  5411. }
  5412. else
  5413. {
  5414. outf("\t\t\t\tiserv->on%s(*request->queryContext(), *esp_request.get(), *esp_response.get());\n", mthi->getName());
  5415. }
  5416. outs("\t\t\tif (esp_response->getRedirectUrl() && *esp_response->getRedirectUrl())\n");
  5417. outs("\t\t\t{\n");
  5418. outs("\t\t\t\tresponse->redirect(*request, esp_response->getRedirectUrl());\n");
  5419. outs("\t\t\t}\n");
  5420. outs("\t\t\telse\n");
  5421. outs("\t\t\t{\n");
  5422. outs("\t\t\t\tIProperties *props=request->queryParameters();\n");
  5423. outs("\t\t\t\tif (props && props->queryProp(\"rawxml_\")!=NULL)\n");
  5424. outs("\t\t\t\t{\n");
  5425. outs("\t\t\t\t\tMemoryBuffer content;\n");
  5426. outs("\t\t\t\t\tStringBuffer mimetype;\n");
  5427. outs("\t\t\t\t\tesp_response->serialize(&context,content, mimetype);\n");
  5428. outs("\t\t\t\t\tonBeforeSendResponse(context,request,content,service,method);\n");
  5429. outs("\t\t\t\t\tresponse->setContent(content.length(), content.toByteArray());\n");
  5430. outs("\t\t\t\t\tresponse->setContentType(mimetype.str());\n");
  5431. outs("\t\t\t\t}\n");
  5432. outs("\t\t\t\telse\n");
  5433. outs("\t\t\t\t{\n");
  5434. outs("\t\t\t\t\tStringBuffer xml;\n");
  5435. outs("\t\t\t\t\tStringBuffer sResponse;\n");
  5436. if (bClientXslt)
  5437. {
  5438. outs("\t\t\t\t\tif (request->supportClientXslt())\n");
  5439. 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);
  5440. }
  5441. outs("\t\t\t\t\tesp_response->serialize(&context,xml);\n\n");
  5442. if (bClientXslt)
  5443. {
  5444. outs("\t\t\t\t\tif (request->supportClientXslt()){\n");
  5445. outs("\t\t\t\t\t\txml.swapWith(sResponse);\n");
  5446. outs("\t\t\t\t\t\tresponse->setContentType(\"text/xml\");\n");
  5447. outs("\t\t\t\t\t}else{\n");
  5448. }
  5449. if(respXsl[1] == '/')
  5450. {
  5451. outf("\t\t\t\t\txslTransform(xml.str(), %s, sResponse.clear(), context.queryXslParameters());\n", respXsl);
  5452. }
  5453. else
  5454. {
  5455. outf("\t\t\t\t\txslTransform(xml.str(), StringBuffer(getCFD()).append(%s).str(), sResponse.clear(), context.queryXslParameters());\n", respXsl);
  5456. }
  5457. outf("\t\t\t\t\tresponse->setContentType(%s);\n", respContentType);
  5458. needsXslt = true;
  5459. if (bClientXslt)
  5460. outs("\t\t\t\t\t}\n");
  5461. outs("\t\t\t\t\tresponse->setContent(sResponse.str());\n");
  5462. outs("\t\t\t\t}\n");
  5463. outs("\t\t\t\tresponse->send();\n");
  5464. outs("\t\t\t}\n");
  5465. outs("\t\t\treturn 0;\n");
  5466. outs("\t\t}\n");
  5467. }
  5468. }
  5469. #ifdef NEW_INSTANT_QUERY
  5470. outs("\n");
  5471. indentReset(2);
  5472. indentOuts("if (esp_response.get())\n");
  5473. indentOuts("{\n");
  5474. indentOuts(1,"if (esp_response->getRedirectUrl() && *esp_response->getRedirectUrl())\n");
  5475. indentOuts(1,"response->redirect(*request, esp_response->getRedirectUrl());\n");
  5476. indentOuts(-1,"else\n");
  5477. indentOuts("{\n");
  5478. indentOuts(1,"MemoryBuffer content;\n");
  5479. indentOuts("StringBuffer mimetype;\n");
  5480. indentOuts("esp_response->serialize(&context,content, mimetype);\n");
  5481. indentOuts("onBeforeSendResponse(context,request,content,service,method);\n");
  5482. indentOuts("response->setContent(content.length(), content.toByteArray());\n");
  5483. indentOuts("response->setContentType(mimetype.str());\n");
  5484. indentOuts("response->send();\n");
  5485. indentOuts(-1,"}\n");
  5486. indentOuts("return 0;\n");
  5487. indentOuts(-1,"}\n");
  5488. #endif
  5489. outs("\t}\n");
  5490. outs("\treturn onGetNotFound(context, request, response, service);\n");
  5491. outs("}\n");
  5492. }
  5493. //-------------------------------------------------------------------------------------------------------------
  5494. // class EspServInfo
  5495. void EspServInfo::write_catch_blocks(EspMethodInfo* mthi, catch_type ct, int indents)
  5496. {
  5497. const char* errorXslt=NULL;
  5498. if (ct==ct_httpresp)
  5499. {
  5500. errorXslt = mthi->getMetaString("exceptions_inline", NULL);
  5501. if (!errorXslt)
  5502. errorXslt = mthi->getMetaString("http_exceptions_inline", NULL);
  5503. if (!errorXslt)
  5504. errorXslt = getMetaString("exceptions_inline", NULL);
  5505. if (!errorXslt)
  5506. errorXslt = getMetaString("http_exceptions_inline", NULL);
  5507. }
  5508. outs(indents,"catch (IMultiException* mex)\n");
  5509. outs(indents,"{\n");
  5510. outs(indents+1,"me->append(*mex);\n");
  5511. outs(indents+1,"mex->Release();\n");
  5512. outs(indents,"}\n");
  5513. //catch IException
  5514. outs(indents,"catch (IException* e)\n");
  5515. outs(indents,"{\n");
  5516. outs(indents+1,"me->append(*e);\n");
  5517. outs(indents,"}\n");
  5518. //catch ...
  5519. outs(indents,"catch (...)\n");
  5520. outs(indents,"{\n");
  5521. outs(indents+1,"me->append(*MakeStringExceptionDirect(-1, \"Unknown Exception\"));\n");
  5522. outs(indents,"}\n");
  5523. //apply any xslt on the error(s), if it is specified in scm file
  5524. //
  5525. if (errorXslt)
  5526. {
  5527. if(errorXslt[1] == '/')
  5528. {
  5529. outf(indents, "if (response->handleExceptions(xslp, me, \"%s\", \"%s\", %s))\n", name_, mthi->getName(), errorXslt);
  5530. }
  5531. else
  5532. {
  5533. outf(indents, "if (response->handleExceptions(xslp, me, \"%s\", \"%s\", StringBuffer(getCFD()).append(%s).str()))\n", name_, mthi->getName(), errorXslt);
  5534. }
  5535. outs(indents+1, "return 0;\n");
  5536. needsXslt=true;
  5537. }
  5538. else
  5539. outf(indents, "esp_response->handleExceptions(me, \"%s\", \"%s\");\n", name_, mthi->getName());
  5540. }
  5541. void EspServInfo::write_esp_service_ipp()
  5542. {
  5543. outf("class C%s : public CInterface,\n", name_);
  5544. outf("\timplements IEsp%s\n", name_);
  5545. outs("{\n");
  5546. outs("private:\n");
  5547. outs("\tIEspContainer* m_container;\n");
  5548. outs("public:\n");
  5549. outs("\tIMPLEMENT_IINTERFACE;\n\n");
  5550. outf("\tC%s(){}\n\tvirtual ~C%s(){}\n", name_, name_);
  5551. outs("\tvirtual void init(IPropertyTree *cfg, const char *process, const char *service)\n\t{\n\t}\n");
  5552. outs("\tvirtual bool init(const char * service, const char * type, IPropertyTree * cfg, const char * process)\n\t{\n\t\treturn true;\n\t}\n");
  5553. outs("\tvirtual void setContainer(IEspContainer *c)\n\t{\n\t\tm_container = c;\n\t}\n");
  5554. outs("\tvirtual IEspContainer *queryContainer()\n\t{\n\t\treturn m_container;\n\t}\n");
  5555. outf("\tvirtual const char* getServiceType(){return \"%s\";}\n\n", name_);
  5556. EspMethodInfo *mthi;
  5557. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5558. {
  5559. bool stubbed = (findMetaTag(mthi->tags,"stubbed")!=NULL);
  5560. outf(1, "%sbool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)\n", (stubbed) ? "" : "//", mthi->getName(), mthi->getReq(), mthi->getResp());
  5561. outf(1, "%s{\n", (stubbed) ? "" : "//");
  5562. outf(2, "%sreturn false;\n", (stubbed) ? "" : "//");
  5563. outf(1, "%s}\n", (stubbed) ? "" : "//");
  5564. }
  5565. outs("};\n\n");
  5566. }
  5567. void EspServInfo::write_esp_service()
  5568. {
  5569. }
  5570. void EspServInfo::write_esp_client_ipp()
  5571. {
  5572. int useMethodName = getMetaInt("use_method_name", 0);
  5573. outf("class CClient%s : public CInterface,\n", name_);
  5574. outf("\timplements IClient%s\n", name_);
  5575. outs("{\nprotected:\n");
  5576. outs("\tStringBuffer m_proxy;\n");
  5577. outs("\tStringBuffer m_url;\n");
  5578. //dom
  5579. outs("\tStringBuffer m_userid;\n");
  5580. outs("\tStringBuffer m_password;\n");
  5581. outs("\tStringBuffer m_realm;\n");
  5582. outs("\tStringBuffer m_action;\n");
  5583. outs("\tlong m_reqId;\n");
  5584. outs("\npublic:\n");
  5585. outs("\tIMPLEMENT_IINTERFACE;\n\n");
  5586. outf("\tCClient%s()\n\t{\n\t\tm_reqId=0;\n\t}\n\tvirtual ~CClient%s(){}\n", name_, name_);
  5587. outs("\tvirtual void setProxyAddress(const char *address)\n\t{\n\t\tm_proxy.set(address);\n\t}\n");
  5588. outs("\tvirtual void addServiceUrl(const char *url)\n\t{\n\t\tm_url.set(url);\n\t}\n");
  5589. outs("\tvirtual void removeServiceUrl(const char *url)\n\t{\n\t}\n");
  5590. //domsetUsernameToken
  5591. 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");
  5592. outs("\tvirtual void setSoapAction(const char *action)\n\t{\n\t\tm_action.set(action);\n\t}\n");
  5593. EspMethodInfo *mthi;
  5594. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5595. {
  5596. outs("\n");
  5597. outf("\tvirtual IClient%s * create%sRequest();\n", mthi->getReq(), mthi->getName());
  5598. outf("\tvirtual IClient%s * %s(IClient%s *request);\n", mthi->getResp(), mthi->getName(), mthi->getReq());
  5599. outf("\tvirtual void async_%s(IClient%s *request, IClient%sEvents *events,IInterface* state=0);\n", mthi->getName(), mthi->getReq(), name_);
  5600. mthi->write_esp_method(name_, true, false);
  5601. }
  5602. outs("\tstatic int transferThunkEvent(void *data);\n");
  5603. outs("#ifdef _WIN32\n");
  5604. outs("\tstatic void espWorkerThread(void* data);\n");
  5605. outs("#else\n");
  5606. outs("\tstatic void *espWorkerThread(void *data);\n");
  5607. outs("#endif\n");
  5608. outs("};\n\n");
  5609. }
  5610. void EspServInfo::write_esp_client()
  5611. {
  5612. int useMethodName = getMetaInt("use_method_name", 0);
  5613. //comment
  5614. outs("\n//=======================================================");
  5615. outs("\n// client util methods");
  5616. outs("\n//=======================================================");
  5617. outs("\n");
  5618. EspMethodInfo *mthi;
  5619. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5620. {
  5621. outf("\n//------ method %s ---------\n", mthi->getName());
  5622. outf("\nIClient%s * CClient%s::create%sRequest()\n", mthi->getReq(), name_, mthi->getName());
  5623. outf("{\n\tC%s* request = new C%s(\"%s\");\n", mthi->getReq(), mthi->getReq(), name_);
  5624. outs("\trequest->setProxyAddress(m_proxy.str());\n");
  5625. outs("\trequest->setUrl(m_url.str());\n");
  5626. if (useMethodName)
  5627. outf("\trequest->setMsgName(\"%s\");\n", mthi->getName());
  5628. outs("\treturn request;\n}\n");
  5629. outf("\nIClient%s * CClient%s::%s(IClient%s *request)\n", mthi->getResp(), name_, mthi->getName(), mthi->getReq());
  5630. outs("{\n");
  5631. outs("\tif(m_url.length()== 0){ throw MakeStringExceptionDirect(-1, \"url not set\"); }\n\n");
  5632. outf("\tC%s* esprequest = dynamic_cast<C%s*>(request);\n", mthi->getReq(), mthi->getReq());
  5633. outf("\tC%s* espresponse = new C%s(\"%s\");\n\n", mthi->getResp(), mthi->getResp(), name_);
  5634. outs("\tespresponse->setReqId(m_reqId++);\n");
  5635. //dom
  5636. outs("\tesprequest->setUserId(m_userid.str());\n");
  5637. outs("\tesprequest->setPassword(m_password.str());\n");
  5638. outs("\tesprequest->setRealm(m_realm.str());\n");
  5639. outs("\tconst char *soapaction=(m_action.length()) ? m_action.str() : NULL;\n");
  5640. outs("\tesprequest->post(m_proxy.str(), m_url.str(), *espresponse, soapaction);\n");
  5641. outs("\treturn espresponse;\n");
  5642. outs("}\n");
  5643. outf("\nvoid CClient%s::async_%s(IClient%s *request, IClient%sEvents *events,IInterface* state)\n", name_, mthi->getName(), mthi->getReq(), name_);
  5644. outs("{\n");
  5645. outs("\tif(m_url.length()==0){ throw MakeStringExceptionDirect(-1, \"url not set\"); }\n\n");
  5646. outf("\tC%s* esprequest = dynamic_cast<C%s*>(request);\n", mthi->getReq(), mthi->getReq());
  5647. outf("\tesprequest->setMethod(\"%s\");\n", mthi->getName());
  5648. outs("\tesprequest->setReqId(m_reqId++);\n");
  5649. outs("\tesprequest->setEventSink(events);\n");
  5650. outs("\tesprequest->setState(state);\n");
  5651. outs("\tesprequest->setUserId(m_userid.str());\n");
  5652. outs("\tesprequest->setPassword(m_password.str());\n");
  5653. outs("\tesprequest->setRealm(m_realm.str());\n");
  5654. outs("#ifdef USE_CLIENT_THREAD\n");
  5655. outs("\tesprequest->setThunkHandle(GetThunkingHandle());\n");
  5656. outs("#endif\n");
  5657. outs("\tesprequest->Link();\n\n");
  5658. outs("\tif(state!=NULL)\n");
  5659. outs("\t\tstate->Link();\n\n");
  5660. outs("#ifdef _WIN32\n");
  5661. outs("\t_beginthread(espWorkerThread, 0, (void *)(IRpcRequestBinding *)(esprequest));\n");
  5662. outs("#else\n");
  5663. outs("\tpthread_attr_t attr;\n");
  5664. outs("\tpthread_attr_init(&attr);\n");
  5665. outs("\tpthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);\n");
  5666. outs("\tpthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);\n");
  5667. outs("\tpthread_attr_setstacksize(&attr, 0x10000);\n");
  5668. outs("\tThreadId threadid;\n");
  5669. outs("\tint status;\n");
  5670. outs("\tdo\n");
  5671. outs("\t{\n");
  5672. outf("\t\tstatus = pthread_create(&threadid, &attr, CClient%s::espWorkerThread, (void *)(IRpcRequestBinding *)(esprequest));\n", name_);
  5673. outs("\t} while (0 != status && (errno == EINTR));\n");
  5674. outs("\tif (status) {\n");
  5675. outs("\t\tRelease();\n");
  5676. outs("\t\tthrow MakeOsException(errno);\n");
  5677. outs("\t}\n");
  5678. outs("#endif\n");
  5679. outs("}\n");
  5680. mthi->write_esp_method(name_, false, false);
  5681. }
  5682. outf("\nint CClient%s::transferThunkEvent(void *data)\n", name_);
  5683. outs("{\n");
  5684. outs("\tIRpcResponseBinding *response = (IRpcResponseBinding *)data;\n");
  5685. outs("\tif (response!=NULL)\n");
  5686. outs("\t{\n");
  5687. outf("\t\tIClient%sEvents *eventSink = (IClient%sEvents *)response->getEventSink();\n", name_, name_);
  5688. outs("\t\tresponse->lock();\n\n");
  5689. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5690. {
  5691. outf("\t\tif (stricmp(response->getMethod(), \"%s\")==0)\n", mthi->getName());
  5692. outs("\t\t{\n\t\t\tif(response->getRpcState() == RPC_MESSAGE_OK)\n");
  5693. outf("\t\t\t\teventSink->on%sComplete(dynamic_cast<IClient%s*>(response),response->queryState());\n", mthi->getName(), mthi->getResp());
  5694. outf("\t\t\telse\n\t\t\t\teventSink->on%sError(dynamic_cast<IClient%s*>(response),response->queryState());\n", mthi->getName(), mthi->getResp());
  5695. outs("\t\t}\n");
  5696. }
  5697. outs("\t\tresponse->unlock();\n");
  5698. outs("\t}\n");
  5699. outs("\treturn 0;\n");
  5700. outs("}\n");
  5701. //=============================================================================
  5702. // method: espWorkerThread(void* data)
  5703. outf("\nstatic IRpcResponseBinding* create%sResponseObject(IRpcRequestBinding *request)\n",name_);
  5704. outs("{\n");
  5705. outs("\tconst char* method = request->getMethod();\n");
  5706. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5707. {
  5708. outf("\tif (stricmp(method, \"%s\")==0)\n", mthi->getName());
  5709. outf("\t\treturn new C%s(\"%s\", request);\n", mthi->getResp(), name_);
  5710. }
  5711. outf("\treturn NULL;\n");
  5712. outs("}\n");
  5713. outf("\n#ifdef _WIN32\n");
  5714. outf("void CClient%s::espWorkerThread(void* data)\n", name_);
  5715. outf("#else\n");
  5716. outf("void *CClient%s::espWorkerThread(void *data)\n", name_);
  5717. outf("#endif\n");
  5718. outs("{\n");
  5719. outs("\tIRpcRequestBinding *request = (IRpcRequestBinding *) data;\n\n");
  5720. outs("\tif (request != NULL)\n");
  5721. outs("\t{\n");
  5722. outs("\t\trequest->lock();\n");
  5723. outf("\t\tIRpcResponseBinding *response=create%sResponseObject(request);\n",name_);
  5724. /*
  5725. const char *preif="";
  5726. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5727. {
  5728. outf("\t\t%sif (stricmp(request->getMethod(), \"%s\")==0)\n\t\t{\n", preif, mthi->getName());
  5729. outf("\t\t\tresponse = new C%s(\"%s\", request);\n\t\t}\n", mthi->getResp(), name_);
  5730. preif="else ";
  5731. }
  5732. outf("\tresponse = createResponseObject(request);\n");
  5733. */
  5734. outs(2, "if (response!=NULL)\n");
  5735. outs(2, "{\n");
  5736. outs(3, "try{\n");
  5737. outs(4, "request->post(*response);\n");
  5738. outs(3, "}\n");
  5739. outs(3, "catch(IException* ex){\n");
  5740. outs(4, "StringBuffer errorStr;\n");
  5741. outs(4, "ex->errorMessage(errorStr);\n");
  5742. outf(4, "ERRLOG(\"CClient%s::espWorkerThread(%%s)--Exception caught while posting async request: %%s\", request->getMethod(), errorStr.str());\n", name_);
  5743. outs(4, "ex->Release();\n");
  5744. outs(3, "}\n");
  5745. outs(3, "catch(...){\n");
  5746. outs(4, "ERRLOG(\"Unknown exception caught while posting async request\");\n");
  5747. outs(3, "}\n");
  5748. outs(2, "}\n");
  5749. outs("#ifdef USE_CLIENT_THREAD\n");
  5750. outs("\t\tThunkToClientThread(request->getThunkHandle(), transferThunkEvent, (void *)response);\n");
  5751. outs("#else\n");
  5752. outs("\t\ttransferThunkEvent((void *)response);\n");
  5753. outs("#endif\n");
  5754. outs("\t\trequest->unlock();\n");
  5755. outs("\t\tif(request->queryState()!=NULL)\n");
  5756. outs("\t\t\trequest->queryState()->Release();\n\n");
  5757. outs("\t\tif(response!=NULL)\n");
  5758. outs("\t\t\tresponse->Release();\n\n");
  5759. outs("\t\trequest->Release();\n");
  5760. outs("\t}\n");
  5761. outs("#if defined(_WIN32)\n");
  5762. outs("#else\n");
  5763. outs("\treturn (void *) 0 ;\n");
  5764. outs("#endif\n");
  5765. outs("}\n\n");
  5766. }
  5767. void EspServInfo::write_clarion_include_interface()
  5768. {
  5769. outf("cppClient%sEvents INTERFACE(cppInterface),COM\n", name_);
  5770. EspMethodInfo *mthi;
  5771. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5772. {
  5773. outf("on%sComplete PROCEDURE(*cppClient%s resp),PROC\n", mthi->getName(), mthi->getResp());
  5774. outf("on%sError PROCEDURE(*cppClient%s resp),PROC\n", mthi->getName(), mthi->getResp());
  5775. }
  5776. outs("\n END\n\n");
  5777. outf("cppClient%s INTERFACE(cppInterface),COM\n", name_);
  5778. outs("setProxyAddress PROCEDURE(CONST *CSTRING address),PROC\n");
  5779. outs("addServiceUrl PROCEDURE(CONST *CSTRING url),PROC\n");
  5780. outs("removeServiceUrl PROCEDURE(CONST *CSTRING url),PROC\n");
  5781. outs("setUsernameToken PROCEDURE(CONST *CSTRING Username,CONST *CSTRING Password,CONST *CSTRING Realm ),PROC\n");
  5782. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5783. {
  5784. outf("create%sRequest PROCEDURE(),*cppClient%s,PROC\n", mthi->getName(), mthi->getReq());//mthi->getName());
  5785. outf("%s PROCEDURE(*cppClient%s request),*cppClient%s,PROC\n", mthi->getName(), mthi->getReq(), mthi->getResp());
  5786. outf("async_%s PROCEDURE(*cppClient%s request, *cppClient%sEvents events,*cppInterface State),PROC\n", mthi->getName(), mthi->getReq(), name_);
  5787. }
  5788. outs("\n END\n\n");
  5789. }
  5790. //interface IEspInstantEcl
  5791. void EspServInfo::write_event_interface()
  5792. {
  5793. outf("interface IClient%sEvents : extends IInterface\n", name_);
  5794. outs("{");
  5795. EspMethodInfo *mthi;
  5796. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5797. {
  5798. outs("\n");
  5799. outf("\tvirtual int on%sComplete(IClient%s *resp,IInterface* state)=0;\n", mthi->getName(), mthi->getResp());
  5800. outf("\tvirtual int on%sError(IClient%s *resp,IInterface* state)=0;", mthi->getName(), mthi->getResp());
  5801. }
  5802. outs("\n};\n\n");
  5803. }
  5804. void EspServInfo::write_esp_interface()
  5805. {
  5806. outf("interface IEsp%s : extends IEspService\n", name_);
  5807. outs("{");
  5808. EspMethodInfo *mthi;
  5809. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5810. {
  5811. outs("\n");
  5812. outf("\tvirtual bool on%s(IEspContext &context, IEsp%s &req, IEsp%s &resp)=0;", mthi->getName(), mthi->getReq(), mthi->getResp());
  5813. }
  5814. outs("\n};\n\n");
  5815. }
  5816. void EspServInfo::write_client_interface()
  5817. {
  5818. outf("interface IClient%s : extends IInterface\n", name_);
  5819. outs("{\n");
  5820. outs("\tvirtual void setProxyAddress(const char *address)=0;\n");
  5821. outs("\tvirtual void addServiceUrl(const char *url)=0;\n");
  5822. outs("\tvirtual void removeServiceUrl(const char *url)=0;\n");
  5823. outs("\tvirtual void setUsernameToken(const char *userName,const char *passWord,const char *realm)=0;\n");
  5824. outs("\tvirtual void setSoapAction(const char *action)=0;\n");
  5825. EspMethodInfo *mthi;
  5826. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5827. {
  5828. outs("\n");
  5829. outf("\tvirtual IClient%s * create%sRequest()=0;\n", mthi->getReq(), mthi->getName());
  5830. outf("\tvirtual IClient%s * %s(IClient%s *request)=0;\n", mthi->getResp(), mthi->getName(), mthi->getReq());
  5831. outf("\tvirtual void async_%s(IClient%s *request, IClient%sEvents *events,IInterface* state=0)=0;\n", mthi->getName(), mthi->getReq(), name_);
  5832. }
  5833. //add the new "flattened" client methods at the end
  5834. outs("\n");
  5835. for (mthi=methods;mthi!=NULL;mthi=mthi->next)
  5836. {
  5837. mthi->write_esp_method(name_, true, true);
  5838. }
  5839. outs("};\n\n");
  5840. }
  5841. static EspMethodInfo* sortMethods(EspMethodInfo* ms)
  5842. {
  5843. if (ms==NULL)
  5844. return ms;
  5845. // find the smallest node
  5846. EspMethodInfo* smallest = ms;
  5847. EspMethodInfo* prev = NULL; // the node right before the smallest node
  5848. for (EspMethodInfo* p = ms; p->next!=NULL; p = p->next)
  5849. {
  5850. if (strcmp(p->next->getName(), smallest->getName())<0)
  5851. {
  5852. prev = p;
  5853. smallest = p->next;
  5854. }
  5855. }
  5856. // move the smallest to the head
  5857. if (smallest != ms)
  5858. {
  5859. if (prev == ms)
  5860. {
  5861. ms->next = smallest->next;
  5862. smallest->next = ms;
  5863. }
  5864. else
  5865. {
  5866. EspMethodInfo* tmp = smallest->next;
  5867. smallest->next = ms->next;
  5868. prev->next = ms;
  5869. ms->next = tmp;
  5870. }
  5871. }
  5872. // recurively sort
  5873. smallest->next = sortMethods(smallest->next);
  5874. return smallest;
  5875. }
  5876. void EspServInfo::sortMethods()
  5877. {
  5878. methods = ::sortMethods(methods);
  5879. }
  5880. //-------------------------------------------------------------------------------------------------------------
  5881. // class HIDLcompiler
  5882. char* getTargetBase(const char* outDir, const char* src)
  5883. {
  5884. if (outDir && *outDir)
  5885. {
  5886. size_t dirlen = strlen(outDir);
  5887. size_t srclen = strlen(src);
  5888. char* buf = (char*)malloc(dirlen+srclen+5);
  5889. // get file name only
  5890. const char* p = src+srclen-1;
  5891. while(p>src && *p!='/' && *p!='\\') p--;
  5892. if (*p == '/' || *p == '\\') p++;
  5893. // absolute path
  5894. if (*outDir=='/' || *outDir=='\\' || outDir[1]==':')
  5895. {
  5896. // dir: outDir+'/'+fileName
  5897. strcpy(buf,outDir);
  5898. }
  5899. else // relative path
  5900. {
  5901. // dir: srcPath + '/' + outDir+'/'+fileName
  5902. size_t len = p-src;
  5903. if (len>0)
  5904. {
  5905. strncpy(buf,src,len);
  5906. if (buf[len-1]=='/' || buf[len-1]=='\\')
  5907. buf[len-1]='/';
  5908. else
  5909. buf[len++] = '/';
  5910. }
  5911. strcpy(buf+len,outDir);
  5912. }
  5913. size_t len = strlen(buf);
  5914. if (buf[len-1]=='/' || buf[len-1]=='\\')
  5915. {
  5916. buf[len-1]=0;
  5917. len--;
  5918. }
  5919. // now buf has the directory name for output: make the directory if not exist
  5920. createDirectory(buf);
  5921. // copy the file name
  5922. buf[len] = '/';
  5923. strcpy(buf+len+1, p);
  5924. //printf("src: %s. dir: %s.\n", src,outDir);
  5925. //printf("buf: %s\n", buf);
  5926. return buf;
  5927. }
  5928. else
  5929. return strdup(src);
  5930. }
  5931. HIDLcompiler::HIDLcompiler(const char * sourceFile,const char *outDir)
  5932. {
  5933. modules = NULL;
  5934. enums = NULL;
  5935. apis = NULL;
  5936. servs = NULL;
  5937. msgs = NULL;
  5938. includes = NULL;
  5939. filename = strdup(sourceFile);
  5940. size_t l = strlen(filename);
  5941. yyin = fopen(sourceFile, "rt");
  5942. if (!yyin) {
  5943. printf("Fatal Error: Cannot read %s\n",sourceFile);
  5944. exit(1);
  5945. }
  5946. packagename = gettail(sourceFile);
  5947. char* targetBase = getTargetBase(outDir, sourceFile);
  5948. ho = createFile(targetBase,"hpp");
  5949. cppo = createFile(targetBase, isSCM ? "ipp" : "cpp");
  5950. #if 0
  5951. xsvo = createFile(targetBase, "xsv");
  5952. #endif
  5953. clwo = createFile(targetBase, "int");
  5954. espx = isESP ? createFile(targetBase,"esp") : -1;
  5955. espng = isESPng ? createFile(targetBase,"_esp_ng", "ipp") : -1;
  5956. espngc= isESPng ? createFile(targetBase,"_esp_ng", "cpp") : -1;
  5957. espi= isESP ? createFile(targetBase, "_esp", "ipp") : -1;
  5958. espc= isESP ? createFile(targetBase, "_esp", "cpp") : -1;
  5959. free(targetBase);
  5960. }
  5961. HIDLcompiler::~HIDLcompiler()
  5962. {
  5963. fclose(yyin);
  5964. close(ho);
  5965. close(cppo);
  5966. //close(xsvo);
  5967. close(clwo);
  5968. free(packagename);
  5969. free(filename);
  5970. delete modules;
  5971. delete enums;
  5972. delete apis;
  5973. delete msgs;
  5974. delete servs;
  5975. delete includes;
  5976. }
  5977. void HIDLcompiler::Process()
  5978. {
  5979. hcp = this;
  5980. write_header_class_intro();
  5981. nCommentStartLine = -1;
  5982. yyparse();
  5983. if (nCommentStartLine > -1)
  5984. {
  5985. char tempBuf[256];
  5986. sprintf(tempBuf, "The comment that started at line %d is not ended yet", nCommentStartLine);
  5987. yyerror(tempBuf);
  5988. }
  5989. write_header_class_outro();
  5990. write_source_file_classes();
  5991. //write_example_implementation_module();
  5992. if (isESP)
  5993. {
  5994. write_esp();
  5995. write_esp_ex_ipp();
  5996. }
  5997. if (isESPng)
  5998. {
  5999. write_esp_ng();
  6000. write_esp_ng_cpp();
  6001. }
  6002. if (isSCM)
  6003. write_clarion_HRPC_interfaces();
  6004. }
  6005. void HIDLcompiler::write_esp()
  6006. {
  6007. //create the *.esp file
  6008. gOutfile = espx;
  6009. outf("// *** Source file generated by "HIDL" Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6010. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6011. outf("#ifndef %s_ESPGEN_INCLUDED\n", packagename);
  6012. outf("#define %s_ESPGEN_INCLUDED\n\n", packagename);
  6013. outf("#include \"%s_esp.ipp\"\n", packagename);
  6014. outs("\n");
  6015. outs("#ifdef _WIN32\n");
  6016. outs("#include \"edwin.h\"\n");
  6017. outs("#include <process.h>\n");
  6018. outs("#endif\n");
  6019. outs("\n\n");
  6020. EspMessageInfo * mi;
  6021. for (mi=msgs;mi;mi=mi->next)
  6022. {
  6023. mi->write_esp();
  6024. }
  6025. EspServInfo *si;
  6026. for (si=servs;si;si=si->next)
  6027. {
  6028. si->write_esp_binding();
  6029. outs("\n\n");
  6030. si->write_esp_service();
  6031. outs("\n\n");
  6032. si->write_esp_client();
  6033. outs("\n\n");
  6034. si->write_factory_impl();
  6035. outs("\n\n");
  6036. }
  6037. outf("#endif //%s_ESPGEN_INCLUDED\n", packagename);
  6038. gOutfile = espc;
  6039. outf("// *** Source file generated by "HIDL" Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6040. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6041. //outf("#ifndef %s_ESPX_INCLUDED\n", packagename);
  6042. //outf("#define %s_ESPX_INCLUDED\n\n", packagename);
  6043. //if (esp_def_export_tag)
  6044. // outf("#include \"%s.esp\"\n", packagename);
  6045. outf("#include \"%s.esp\"\n", packagename);
  6046. outs("\n\n");
  6047. //outf("#endif //%s_ESPX_INCLUDED\n", packagename);
  6048. }
  6049. void HIDLcompiler::write_esp_ex_ipp()
  6050. {
  6051. gOutfile = espi;
  6052. outf("// *** Source file generated by "HIDL" Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6053. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6054. outf("#ifndef %s_EX_ESPGEN_INCLUDED\n", packagename);
  6055. outf("#define %s_EX_ESPGEN_INCLUDED\n\n", packagename);
  6056. outs("#pragma warning( disable : 4786)\n\n");
  6057. outs("//JLib\n");
  6058. outs("#include \"jliball.hpp\"\n");
  6059. outs("\n");
  6060. outs("//SCM Interfaces\n");
  6061. outs("#include \"esp.hpp\"\n");
  6062. outs("#include \"soapesp.hpp\"\n");
  6063. outf("#include \"%s.hpp\"\n", packagename);
  6064. outs("//ESP Bindings\n");
  6065. outs("#include \"SOAP/Platform/soapmessage.hpp\"\n");
  6066. outs("#include \"SOAP/Platform/soapmacro.hpp\"\n");
  6067. outs("#include \"SOAP/Platform/soapservice.hpp\"\n");
  6068. outs("#include \"SOAP/Platform/soapparam.hpp\"\n");
  6069. outs("#include \"SOAP/client/soapclient.hpp\"\n");
  6070. outs("\n\n");
  6071. outf("namespace %s\n{\n\n", packagename);
  6072. EspMessageInfo * mi;
  6073. for (mi=msgs;mi;mi=mi->next)
  6074. {
  6075. mi->write_esp_ipp();
  6076. }
  6077. EspServInfo *si;
  6078. for (si=servs;si;si=si->next)
  6079. {
  6080. si->write_esp_service_ipp();
  6081. outs("\n\n");
  6082. si->write_esp_binding_ipp();
  6083. outs("\n\n");
  6084. si->write_esp_client_ipp();
  6085. outs("\n\n");
  6086. }
  6087. outs("}\n");
  6088. outf("using namespace %s;\n\n", packagename);
  6089. outf("#endif //%s_ESPGEN_INCLUDED\n", packagename);
  6090. }
  6091. void HIDLcompiler::write_source_file_classes()
  6092. {
  6093. gOutfile = cppo;
  6094. outf("// *** Source file generated by "HIDL" Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6095. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6096. outf("#include \"%s.hpp\"\n\n",packagename);
  6097. ModuleInfo * mi;
  6098. for (mi=modules;mi;mi=mi->next)
  6099. {
  6100. if (isSCM) {
  6101. mi->write_clarion_scm_stub_class();
  6102. }
  6103. else {
  6104. mi->write_body_class();
  6105. mi->write_clarion_interface_class();
  6106. }
  6107. }
  6108. outs("//end\n"); // CR for Clarion
  6109. }
  6110. void HIDLcompiler::write_clarion_esp_interfaces()
  6111. {
  6112. gOutfile = clwo;
  6113. EspMessageInfo * mi;
  6114. for (mi=msgs;mi;mi=mi->next)
  6115. {
  6116. mi->write_clarion_include_interface();
  6117. outs("\n\n");
  6118. }
  6119. EspServInfo *si;
  6120. for (si=servs;si;si=si->next)
  6121. {
  6122. si->write_clarion_include_interface();
  6123. outs("\n\n");
  6124. }
  6125. }
  6126. void HIDLcompiler::write_clarion_HRPC_interfaces()
  6127. {
  6128. gOutfile = clwo;
  6129. if (isSCM)
  6130. outs("! Clarion SCM Interfaces\n");
  6131. else
  6132. {
  6133. // outs("! Clarion HRPC Interfaces\n");
  6134. outs("*** No longer generated\n");
  6135. return;
  6136. }
  6137. outf("! Include file generated by "HIDL" Version %s from %s.%s\n", HIDLVER, packagename, srcFileExt);
  6138. outs("! *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6139. outf(" OMIT('EndOfInclude',_%s_I_)\n",packagename);
  6140. outf("_%s_I_ EQUATE(1)\n\n",packagename);
  6141. if (isSCM)
  6142. {
  6143. outs(" INCLUDE('SCM.INT'),ONCE\n\n");
  6144. if (clarion.length())
  6145. {
  6146. outs(clarion.str());
  6147. outs("\n\n");
  6148. }
  6149. }
  6150. else
  6151. outs(" INCLUDE('HRPC.INC'),ONCE\n\n");
  6152. EnumInfo * ei;
  6153. for (ei=enums;ei;ei=ei->next)
  6154. {
  6155. ei->write_clarion_enum();
  6156. }
  6157. ModuleInfo * mi;
  6158. for (mi=modules;mi;mi=mi->next)
  6159. {
  6160. mi->write_clarion_include_module();
  6161. }
  6162. if (isESP)
  6163. {
  6164. write_clarion_esp_interfaces();
  6165. }
  6166. outs("\n");
  6167. outs(" MAP\n");
  6168. outf(" MODULE('%s')\n",packagename);
  6169. if (!isSCM)
  6170. {
  6171. for (mi=modules;mi;mi=mi->next)
  6172. {
  6173. outf(" HRPC_Make_%s(HRPCI_Clarion_Transport transport),*HRPCI_%s,PASCAL,NAME('_HRPC_Make_%s@4')\n",mi->name,mi->name,mi->name);
  6174. }
  6175. }
  6176. else
  6177. {
  6178. ApiInfo * fi;
  6179. for (fi=apis;fi;fi=fi->next)
  6180. {
  6181. fi->write_clarion_include_method();
  6182. }
  6183. }
  6184. outs(" END\n\n");
  6185. outs(" END\n\n");
  6186. outf("\nEndOfInclude\n");
  6187. }
  6188. void HIDLcompiler::write_example_implementation_module()
  6189. {
  6190. gOutfile = xsvo;
  6191. outs("// Example Server Implementation Template\n");
  6192. outf("// Source file generated by "HIDL" Version %s from %s.%s\n", HIDLVER, packagename, srcFileExt);
  6193. outs("// *** You should copy this file before changing, as it will be overwritten next time "HIDL" is run ***\n\n");
  6194. outs("#include <stddef.h>\n");
  6195. outs("#include <stdlib.h>\n");
  6196. outs("#include <assert.h>\n\n");
  6197. outs("#include \"hrpcsock.hpp\"// default use TCP/IP sockets\n\n");
  6198. outs("// TBD - Add other includes here\n\n");
  6199. ModuleInfo * mi;
  6200. for (mi=modules;mi;mi=mi->next)
  6201. {
  6202. mi->write_define();
  6203. }
  6204. outf("#include \"%s.cpp\"\n\n",packagename);
  6205. for (mi=modules;mi;mi=mi->next)
  6206. {
  6207. mi->write_example_module();
  6208. }
  6209. }
  6210. void HIDLcompiler::write_header_class_intro()
  6211. {
  6212. gOutfile=ho;
  6213. outf("// *** Include file generated by "HIDL" Version %s from %s.%s ***\n", HIDLVER, packagename, srcFileExt);
  6214. outf("// *** Not to be hand edited (changes will be lost on re-generation) ***\n\n");
  6215. outf("#ifndef %s_%s_INCL\n",packagename,isSCM?"SCM":"HID");
  6216. outf("#define %s_%s_INCL\n\n",packagename,isSCM?"SCM":"HID");
  6217. if (isESP)
  6218. {
  6219. outf("#include \"esp.hpp\"\n\n");
  6220. }
  6221. else if (isSCM)
  6222. {
  6223. //outf("#include \"scm.hpp\"\n\n");
  6224. }
  6225. else
  6226. outf("#include \"hrpc.hpp\"\n\n");
  6227. }
  6228. void HIDLcompiler::write_header_class_outro()
  6229. {
  6230. outs("\n");
  6231. EspMessageInfo * mi;
  6232. for (mi=msgs;mi;mi=mi->next)
  6233. {
  6234. mi->write_factory_decl();
  6235. }
  6236. outs("\n");
  6237. outf("#endif // _%s_%s_INCL\n", packagename,isSCM?"SCM":"HID");
  6238. outs("//end\n"); // CR for Clarion
  6239. }
  6240. //-------------------------------------------------------------------------------------------------------------
  6241. // class EnumInfo
  6242. void EnumInfo::write_header_enum()
  6243. {
  6244. outf("enum %s\n{\n", name);
  6245. for (EnumValInfo *vi=vals;vi;vi=vi->next) {
  6246. outf("\t%s = %d",vi->name,vi->val);
  6247. if (vi->next)
  6248. outs(",\n");
  6249. else
  6250. outs("\n");
  6251. }
  6252. outs("};\n\n");
  6253. }
  6254. void EnumInfo::write_clarion_enum()
  6255. {
  6256. outf("%s EQUATE(UNSIGNED)\n", xlat(name));
  6257. outf(" ITEMIZE,PRE(%s)\n",xlat(name));
  6258. for (EnumValInfo *vi=vals;vi;vi=vi->next) {
  6259. outf("%s\tEQUATE(%d)\n",xlat(vi->name),vi->val);
  6260. }
  6261. outs("\tEND\n\n");
  6262. }
  6263. // end
  6264. //-------------------------------------------------------------------------------------------------------------