nusoap.php 291 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154
  1. <?php
  2. /*
  3. $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  4. NuSOAP - Web Services Toolkit for PHP
  5. Copyright (c) 2002 NuSphere Corporation
  6. This library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. The NuSOAP project home is:
  18. http://sourceforge.net/projects/nusoap/
  19. The primary support for NuSOAP is the Help forum on the project home page.
  20. If you have any questions or comments, please email:
  21. Dietrich Ayala
  22. dietrich@ganx4.com
  23. http://dietrich.ganx4.com/nusoap
  24. NuSphere Corporation
  25. http://www.nusphere.com
  26. */
  27. /*
  28. * Some of the standards implmented in whole or part by NuSOAP:
  29. *
  30. * SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
  31. * WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
  32. * SOAP Messages With Attachments (http://www.w3.org/TR/SOAP-attachments)
  33. * XML 1.0 (http://www.w3.org/TR/2006/REC-xml-20060816/)
  34. * Namespaces in XML 1.0 (http://www.w3.org/TR/2006/REC-xml-names-20060816/)
  35. * XML Schema 1.0 (http://www.w3.org/TR/xmlschema-0/)
  36. * RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
  37. * RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
  38. * RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
  39. */
  40. /* load classes
  41. // necessary classes
  42. require_once('class.soapclient.php');
  43. require_once('class.soap_val.php');
  44. require_once('class.soap_parser.php');
  45. require_once('class.soap_fault.php');
  46. // transport classes
  47. require_once('class.soap_transport_http.php');
  48. // optional add-on classes
  49. require_once('class.xmlschema.php');
  50. require_once('class.wsdl.php');
  51. // server class
  52. require_once('class.soap_server.php');*/
  53. // class variable emulation
  54. // cf. http://www.webkreator.com/php/techniques/php-static-class-variables.html
  55. $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
  56. /**
  57. *
  58. * nusoap_base
  59. *
  60. * @author Dietrich Ayala <dietrich@ganx4.com>
  61. * @author Scott Nichol <snichol@users.sourceforge.net>
  62. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  63. * @access public
  64. */
  65. class nusoap_base {
  66. /**
  67. * Identification for HTTP headers.
  68. *
  69. * @var string
  70. * @access private
  71. */
  72. var $title = 'NuSOAP';
  73. /**
  74. * Version for HTTP headers.
  75. *
  76. * @var string
  77. * @access private
  78. */
  79. var $version = '0.9.5';
  80. /**
  81. * CVS revision for HTTP headers.
  82. *
  83. * @var string
  84. * @access private
  85. */
  86. var $revision = '$Revision: 1.123 $';
  87. /**
  88. * Current error string (manipulated by getError/setError)
  89. *
  90. * @var string
  91. * @access private
  92. */
  93. var $error_str = '';
  94. /**
  95. * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
  96. *
  97. * @var string
  98. * @access private
  99. */
  100. var $debug_str = '';
  101. /**
  102. * toggles automatic encoding of special characters as entities
  103. * (should always be true, I think)
  104. *
  105. * @var boolean
  106. * @access private
  107. */
  108. var $charencoding = true;
  109. /**
  110. * the debug level for this instance
  111. *
  112. * @var integer
  113. * @access private
  114. */
  115. var $debugLevel;
  116. /**
  117. * set schema version
  118. *
  119. * @var string
  120. * @access public
  121. */
  122. var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
  123. /**
  124. * charset encoding for outgoing messages
  125. *
  126. * @var string
  127. * @access public
  128. */
  129. var $soap_defencoding = 'ISO-8859-1';
  130. //var $soap_defencoding = 'UTF-8';
  131. /**
  132. * namespaces in an array of prefix => uri
  133. *
  134. * this is "seeded" by a set of constants, but it may be altered by code
  135. *
  136. * @var array
  137. * @access public
  138. */
  139. var $namespaces = array(
  140. 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
  141. 'xsd' => 'http://www.w3.org/2001/XMLSchema',
  142. 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  143. 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
  144. );
  145. /**
  146. * namespaces used in the current context, e.g. during serialization
  147. *
  148. * @var array
  149. * @access private
  150. */
  151. var $usedNamespaces = array();
  152. /**
  153. * XML Schema types in an array of uri => (array of xml type => php type)
  154. * is this legacy yet?
  155. * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
  156. * @var array
  157. * @access public
  158. */
  159. var $typemap = array(
  160. 'http://www.w3.org/2001/XMLSchema' => array(
  161. 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
  162. 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
  163. 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
  164. // abstract "any" types
  165. 'anyType'=>'string','anySimpleType'=>'string',
  166. // derived datatypes
  167. 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
  168. 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
  169. 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
  170. 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
  171. 'http://www.w3.org/2000/10/XMLSchema' => array(
  172. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  173. 'float'=>'double','dateTime'=>'string',
  174. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  175. 'http://www.w3.org/1999/XMLSchema' => array(
  176. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  177. 'float'=>'double','dateTime'=>'string',
  178. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  179. 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
  180. 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
  181. 'http://xml.apache.org/xml-soap' => array('Map')
  182. );
  183. /**
  184. * XML entities to convert
  185. *
  186. * @var array
  187. * @access public
  188. * @deprecated
  189. * @see expandEntities
  190. */
  191. var $xmlEntities = array('quot' => '"','amp' => '&',
  192. 'lt' => '<','gt' => '>','apos' => "'");
  193. /**
  194. * constructor
  195. *
  196. * @access public
  197. */
  198. function nusoap_base() {
  199. $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
  200. }
  201. /**
  202. * gets the global debug level, which applies to future instances
  203. *
  204. * @return integer Debug level 0-9, where 0 turns off
  205. * @access public
  206. */
  207. function getGlobalDebugLevel() {
  208. return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
  209. }
  210. /**
  211. * sets the global debug level, which applies to future instances
  212. *
  213. * @param int $level Debug level 0-9, where 0 turns off
  214. * @access public
  215. */
  216. function setGlobalDebugLevel($level) {
  217. $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
  218. }
  219. /**
  220. * gets the debug level for this instance
  221. *
  222. * @return int Debug level 0-9, where 0 turns off
  223. * @access public
  224. */
  225. function getDebugLevel() {
  226. return $this->debugLevel;
  227. }
  228. /**
  229. * sets the debug level for this instance
  230. *
  231. * @param int $level Debug level 0-9, where 0 turns off
  232. * @access public
  233. */
  234. function setDebugLevel($level) {
  235. $this->debugLevel = $level;
  236. }
  237. /**
  238. * adds debug data to the instance debug string with formatting
  239. *
  240. * @param string $string debug data
  241. * @access private
  242. */
  243. function debug($string){
  244. if ($this->debugLevel > 0) {
  245. $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
  246. }
  247. }
  248. /**
  249. * adds debug data to the instance debug string without formatting
  250. *
  251. * @param string $string debug data
  252. * @access public
  253. */
  254. function appendDebug($string){
  255. if ($this->debugLevel > 0) {
  256. // it would be nice to use a memory stream here to use
  257. // memory more efficiently
  258. $this->debug_str .= $string;
  259. }
  260. }
  261. /**
  262. * clears the current debug data for this instance
  263. *
  264. * @access public
  265. */
  266. function clearDebug() {
  267. // it would be nice to use a memory stream here to use
  268. // memory more efficiently
  269. $this->debug_str = '';
  270. }
  271. /**
  272. * gets the current debug data for this instance
  273. *
  274. * @return debug data
  275. * @access public
  276. */
  277. function &getDebug() {
  278. // it would be nice to use a memory stream here to use
  279. // memory more efficiently
  280. return $this->debug_str;
  281. }
  282. /**
  283. * gets the current debug data for this instance as an XML comment
  284. * this may change the contents of the debug data
  285. *
  286. * @return debug data as an XML comment
  287. * @access public
  288. */
  289. function &getDebugAsXMLComment() {
  290. // it would be nice to use a memory stream here to use
  291. // memory more efficiently
  292. while (strpos($this->debug_str, '--')) {
  293. $this->debug_str = str_replace('--', '- -', $this->debug_str);
  294. }
  295. $ret = "<!--\n" . $this->debug_str . "\n-->";
  296. return $ret;
  297. }
  298. /**
  299. * expands entities, e.g. changes '<' to '&lt;'.
  300. *
  301. * @param string $val The string in which to expand entities.
  302. * @access private
  303. */
  304. function expandEntities($val) {
  305. if ($this->charencoding) {
  306. $val = str_replace('&', '&amp;', $val);
  307. $val = str_replace("'", '&apos;', $val);
  308. $val = str_replace('"', '&quot;', $val);
  309. $val = str_replace('<', '&lt;', $val);
  310. $val = str_replace('>', '&gt;', $val);
  311. }
  312. return $val;
  313. }
  314. /**
  315. * returns error string if present
  316. *
  317. * @return mixed error string or false
  318. * @access public
  319. */
  320. function getError(){
  321. if($this->error_str != ''){
  322. return $this->error_str;
  323. }
  324. return false;
  325. }
  326. /**
  327. * sets error string
  328. *
  329. * @return boolean $string error string
  330. * @access private
  331. */
  332. function setError($str){
  333. $this->error_str = $str;
  334. }
  335. /**
  336. * detect if array is a simple array or a struct (associative array)
  337. *
  338. * @param mixed $val The PHP array
  339. * @return string (arraySimple|arrayStruct)
  340. * @access private
  341. */
  342. function isArraySimpleOrStruct($val) {
  343. $keyList = array_keys($val);
  344. foreach ($keyList as $keyListValue) {
  345. if (!is_int($keyListValue)) {
  346. return 'arrayStruct';
  347. }
  348. }
  349. return 'arraySimple';
  350. }
  351. /**
  352. * serializes PHP values in accordance w/ section 5. Type information is
  353. * not serialized if $use == 'literal'.
  354. *
  355. * @param mixed $val The value to serialize
  356. * @param string $name The name (local part) of the XML element
  357. * @param string $type The XML schema type (local part) for the element
  358. * @param string $name_ns The namespace for the name of the XML element
  359. * @param string $type_ns The namespace for the type of the element
  360. * @param array $attributes The attributes to serialize as name=>value pairs
  361. * @param string $use The WSDL "use" (encoded|literal)
  362. * @param boolean $soapval Whether this is called from soapval.
  363. * @return string The serialized element, possibly with child elements
  364. * @access public
  365. */
  366. function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
  367. $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
  368. $this->appendDebug('value=' . $this->varDump($val));
  369. $this->appendDebug('attributes=' . $this->varDump($attributes));
  370. if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
  371. $this->debug("serialize_val: serialize soapval");
  372. $xml = $val->serialize($use);
  373. $this->appendDebug($val->getDebug());
  374. $val->clearDebug();
  375. $this->debug("serialize_val of soapval returning $xml");
  376. return $xml;
  377. }
  378. // force valid name if necessary
  379. if (is_numeric($name)) {
  380. $name = '__numeric_' . $name;
  381. } elseif (! $name) {
  382. $name = 'noname';
  383. }
  384. // if name has ns, add ns prefix to name
  385. $xmlns = '';
  386. if($name_ns){
  387. $prefix = 'nu'.rand(1000,9999);
  388. $name = $prefix.':'.$name;
  389. $xmlns .= " xmlns:$prefix=\"$name_ns\"";
  390. }
  391. // if type is prefixed, create type prefix
  392. if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
  393. // need to fix this. shouldn't default to xsd if no ns specified
  394. // w/o checking against typemap
  395. $type_prefix = 'xsd';
  396. } elseif($type_ns){
  397. $type_prefix = 'ns'.rand(1000,9999);
  398. $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
  399. }
  400. // serialize attributes if present
  401. $atts = '';
  402. if($attributes){
  403. foreach($attributes as $k => $v){
  404. $atts .= " $k=\"".$this->expandEntities($v).'"';
  405. }
  406. }
  407. // serialize null value
  408. if (is_null($val)) {
  409. $this->debug("serialize_val: serialize null");
  410. if ($use == 'literal') {
  411. // TODO: depends on minOccurs
  412. $xml = "<$name$xmlns$atts/>";
  413. $this->debug("serialize_val returning $xml");
  414. return $xml;
  415. } else {
  416. if (isset($type) && isset($type_prefix)) {
  417. $type_str = " xsi:type=\"$type_prefix:$type\"";
  418. } else {
  419. $type_str = '';
  420. }
  421. $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
  422. $this->debug("serialize_val returning $xml");
  423. return $xml;
  424. }
  425. }
  426. // serialize if an xsd built-in primitive type
  427. if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
  428. $this->debug("serialize_val: serialize xsd built-in primitive type");
  429. if (is_bool($val)) {
  430. if ($type == 'boolean') {
  431. $val = $val ? 'true' : 'false';
  432. } elseif (! $val) {
  433. $val = 0;
  434. }
  435. } else if (is_string($val)) {
  436. $val = $this->expandEntities($val);
  437. }
  438. if ($use == 'literal') {
  439. $xml = "<$name$xmlns$atts>$val</$name>";
  440. $this->debug("serialize_val returning $xml");
  441. return $xml;
  442. } else {
  443. $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
  444. $this->debug("serialize_val returning $xml");
  445. return $xml;
  446. }
  447. }
  448. // detect type and serialize
  449. $xml = '';
  450. switch(true) {
  451. case (is_bool($val) || $type == 'boolean'):
  452. $this->debug("serialize_val: serialize boolean");
  453. if ($type == 'boolean') {
  454. $val = $val ? 'true' : 'false';
  455. } elseif (! $val) {
  456. $val = 0;
  457. }
  458. if ($use == 'literal') {
  459. $xml .= "<$name$xmlns$atts>$val</$name>";
  460. } else {
  461. $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
  462. }
  463. break;
  464. case (is_int($val) || is_long($val) || $type == 'int'):
  465. $this->debug("serialize_val: serialize int");
  466. if ($use == 'literal') {
  467. $xml .= "<$name$xmlns$atts>$val</$name>";
  468. } else {
  469. $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
  470. }
  471. break;
  472. case (is_float($val)|| is_double($val) || $type == 'float'):
  473. $this->debug("serialize_val: serialize float");
  474. if ($use == 'literal') {
  475. $xml .= "<$name$xmlns$atts>$val</$name>";
  476. } else {
  477. $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
  478. }
  479. break;
  480. case (is_string($val) || $type == 'string'):
  481. $this->debug("serialize_val: serialize string");
  482. $val = $this->expandEntities($val);
  483. if ($use == 'literal') {
  484. $xml .= "<$name$xmlns$atts>$val</$name>";
  485. } else {
  486. $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
  487. }
  488. break;
  489. case is_object($val):
  490. $this->debug("serialize_val: serialize object");
  491. if (get_class($val) == 'soapval') {
  492. $this->debug("serialize_val: serialize soapval object");
  493. $pXml = $val->serialize($use);
  494. $this->appendDebug($val->getDebug());
  495. $val->clearDebug();
  496. } else {
  497. if (! $name) {
  498. $name = get_class($val);
  499. $this->debug("In serialize_val, used class name $name as element name");
  500. } else {
  501. $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
  502. }
  503. foreach(get_object_vars($val) as $k => $v){
  504. $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
  505. }
  506. }
  507. if(isset($type) && isset($type_prefix)){
  508. $type_str = " xsi:type=\"$type_prefix:$type\"";
  509. } else {
  510. $type_str = '';
  511. }
  512. if ($use == 'literal') {
  513. $xml .= "<$name$xmlns$atts>$pXml</$name>";
  514. } else {
  515. $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
  516. }
  517. break;
  518. break;
  519. case (is_array($val) || $type):
  520. // detect if struct or array
  521. $valueType = $this->isArraySimpleOrStruct($val);
  522. if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){
  523. $this->debug("serialize_val: serialize array");
  524. $i = 0;
  525. if(is_array($val) && count($val)> 0){
  526. foreach($val as $v){
  527. if(is_object($v) && get_class($v) == 'soapval'){
  528. $tt_ns = $v->type_ns;
  529. $tt = $v->type;
  530. } elseif (is_array($v)) {
  531. $tt = $this->isArraySimpleOrStruct($v);
  532. } else {
  533. $tt = gettype($v);
  534. }
  535. $array_types[$tt] = 1;
  536. // TODO: for literal, the name should be $name
  537. $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
  538. ++$i;
  539. }
  540. if(count($array_types) > 1){
  541. $array_typename = 'xsd:anyType';
  542. } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
  543. if ($tt == 'integer') {
  544. $tt = 'int';
  545. }
  546. $array_typename = 'xsd:'.$tt;
  547. } elseif(isset($tt) && $tt == 'arraySimple'){
  548. $array_typename = 'SOAP-ENC:Array';
  549. } elseif(isset($tt) && $tt == 'arrayStruct'){
  550. $array_typename = 'unnamed_struct_use_soapval';
  551. } else {
  552. // if type is prefixed, create type prefix
  553. if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
  554. $array_typename = 'xsd:' . $tt;
  555. } elseif ($tt_ns) {
  556. $tt_prefix = 'ns' . rand(1000, 9999);
  557. $array_typename = "$tt_prefix:$tt";
  558. $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
  559. } else {
  560. $array_typename = $tt;
  561. }
  562. }
  563. $array_type = $i;
  564. if ($use == 'literal') {
  565. $type_str = '';
  566. } else if (isset($type) && isset($type_prefix)) {
  567. $type_str = " xsi:type=\"$type_prefix:$type\"";
  568. } else {
  569. $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
  570. }
  571. // empty array
  572. } else {
  573. if ($use == 'literal') {
  574. $type_str = '';
  575. } else if (isset($type) && isset($type_prefix)) {
  576. $type_str = " xsi:type=\"$type_prefix:$type\"";
  577. } else {
  578. $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
  579. }
  580. }
  581. // TODO: for array in literal, there is no wrapper here
  582. $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
  583. } else {
  584. // got a struct
  585. $this->debug("serialize_val: serialize struct");
  586. if(isset($type) && isset($type_prefix)){
  587. $type_str = " xsi:type=\"$type_prefix:$type\"";
  588. } else {
  589. $type_str = '';
  590. }
  591. if ($use == 'literal') {
  592. $xml .= "<$name$xmlns$atts>";
  593. } else {
  594. $xml .= "<$name$xmlns$type_str$atts>";
  595. }
  596. foreach($val as $k => $v){
  597. // Apache Map
  598. if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
  599. $xml .= '<item>';
  600. $xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
  601. $xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
  602. $xml .= '</item>';
  603. } else {
  604. $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
  605. }
  606. }
  607. $xml .= "</$name>";
  608. }
  609. break;
  610. default:
  611. $this->debug("serialize_val: serialize unknown");
  612. $xml .= 'not detected, got '.gettype($val).' for '.$val;
  613. break;
  614. }
  615. $this->debug("serialize_val returning $xml");
  616. return $xml;
  617. }
  618. /**
  619. * serializes a message
  620. *
  621. * @param string $body the XML of the SOAP body
  622. * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
  623. * @param array $namespaces optional the namespaces used in generating the body and headers
  624. * @param string $style optional (rpc|document)
  625. * @param string $use optional (encoded|literal)
  626. * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
  627. * @return string the message
  628. * @access public
  629. */
  630. function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){
  631. // TODO: add an option to automatically run utf8_encode on $body and $headers
  632. // if $this->soap_defencoding is UTF-8. Not doing this automatically allows
  633. // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
  634. $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
  635. $this->debug("headers:");
  636. $this->appendDebug($this->varDump($headers));
  637. $this->debug("namespaces:");
  638. $this->appendDebug($this->varDump($namespaces));
  639. // serialize namespaces
  640. $ns_string = '';
  641. foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
  642. $ns_string .= " xmlns:$k=\"$v\"";
  643. }
  644. if($encodingStyle) {
  645. $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
  646. }
  647. // serialize headers
  648. if($headers){
  649. if (is_array($headers)) {
  650. $xml = '';
  651. foreach ($headers as $k => $v) {
  652. if (is_object($v) && get_class($v) == 'soapval') {
  653. $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
  654. } else {
  655. $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
  656. }
  657. }
  658. $headers = $xml;
  659. $this->debug("In serializeEnvelope, serialized array of headers to $headers");
  660. }
  661. $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
  662. }
  663. // serialize envelope
  664. return
  665. '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
  666. '<SOAP-ENV:Envelope'.$ns_string.">".
  667. $headers.
  668. "<SOAP-ENV:Body>".
  669. $body.
  670. "</SOAP-ENV:Body>".
  671. "</SOAP-ENV:Envelope>";
  672. }
  673. /**
  674. * formats a string to be inserted into an HTML stream
  675. *
  676. * @param string $str The string to format
  677. * @return string The formatted string
  678. * @access public
  679. * @deprecated
  680. */
  681. function formatDump($str){
  682. $str = htmlspecialchars($str);
  683. return nl2br($str);
  684. }
  685. /**
  686. * contracts (changes namespace to prefix) a qualified name
  687. *
  688. * @param string $qname qname
  689. * @return string contracted qname
  690. * @access private
  691. */
  692. function contractQname($qname){
  693. // get element namespace
  694. //$this->xdebug("Contract $qname");
  695. if (strrpos($qname, ':')) {
  696. // get unqualified name
  697. $name = substr($qname, strrpos($qname, ':') + 1);
  698. // get ns
  699. $ns = substr($qname, 0, strrpos($qname, ':'));
  700. $p = $this->getPrefixFromNamespace($ns);
  701. if ($p) {
  702. return $p . ':' . $name;
  703. }
  704. return $qname;
  705. } else {
  706. return $qname;
  707. }
  708. }
  709. /**
  710. * expands (changes prefix to namespace) a qualified name
  711. *
  712. * @param string $qname qname
  713. * @return string expanded qname
  714. * @access private
  715. */
  716. function expandQname($qname){
  717. // get element prefix
  718. if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){
  719. // get unqualified name
  720. $name = substr(strstr($qname,':'),1);
  721. // get ns prefix
  722. $prefix = substr($qname,0,strpos($qname,':'));
  723. if(isset($this->namespaces[$prefix])){
  724. return $this->namespaces[$prefix].':'.$name;
  725. } else {
  726. return $qname;
  727. }
  728. } else {
  729. return $qname;
  730. }
  731. }
  732. /**
  733. * returns the local part of a prefixed string
  734. * returns the original string, if not prefixed
  735. *
  736. * @param string $str The prefixed string
  737. * @return string The local part
  738. * @access public
  739. */
  740. function getLocalPart($str){
  741. if($sstr = strrchr($str,':')){
  742. // get unqualified name
  743. return substr( $sstr, 1 );
  744. } else {
  745. return $str;
  746. }
  747. }
  748. /**
  749. * returns the prefix part of a prefixed string
  750. * returns false, if not prefixed
  751. *
  752. * @param string $str The prefixed string
  753. * @return mixed The prefix or false if there is no prefix
  754. * @access public
  755. */
  756. function getPrefix($str){
  757. if($pos = strrpos($str,':')){
  758. // get prefix
  759. return substr($str,0,$pos);
  760. }
  761. return false;
  762. }
  763. /**
  764. * pass it a prefix, it returns a namespace
  765. *
  766. * @param string $prefix The prefix
  767. * @return mixed The namespace, false if no namespace has the specified prefix
  768. * @access public
  769. */
  770. function getNamespaceFromPrefix($prefix){
  771. if (isset($this->namespaces[$prefix])) {
  772. return $this->namespaces[$prefix];
  773. }
  774. //$this->setError("No namespace registered for prefix '$prefix'");
  775. return false;
  776. }
  777. /**
  778. * returns the prefix for a given namespace (or prefix)
  779. * or false if no prefixes registered for the given namespace
  780. *
  781. * @param string $ns The namespace
  782. * @return mixed The prefix, false if the namespace has no prefixes
  783. * @access public
  784. */
  785. function getPrefixFromNamespace($ns) {
  786. foreach ($this->namespaces as $p => $n) {
  787. if ($ns == $n || $ns == $p) {
  788. $this->usedNamespaces[$p] = $n;
  789. return $p;
  790. }
  791. }
  792. return false;
  793. }
  794. /**
  795. * returns the time in ODBC canonical form with microseconds
  796. *
  797. * @return string The time in ODBC canonical form with microseconds
  798. * @access public
  799. */
  800. function getmicrotime() {
  801. if (function_exists('gettimeofday')) {
  802. $tod = gettimeofday();
  803. $sec = $tod['sec'];
  804. $usec = $tod['usec'];
  805. } else {
  806. $sec = time();
  807. $usec = 0;
  808. }
  809. return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
  810. }
  811. /**
  812. * Returns a string with the output of var_dump
  813. *
  814. * @param mixed $data The variable to var_dump
  815. * @return string The output of var_dump
  816. * @access public
  817. */
  818. function varDump($data) {
  819. ob_start();
  820. var_dump($data);
  821. $ret_val = ob_get_contents();
  822. ob_end_clean();
  823. return $ret_val;
  824. }
  825. /**
  826. * represents the object as a string
  827. *
  828. * @return string
  829. * @access public
  830. */
  831. function __toString() {
  832. return $this->varDump($this);
  833. }
  834. }
  835. // XML Schema Datatype Helper Functions
  836. //xsd:dateTime helpers
  837. /**
  838. * convert unix timestamp to ISO 8601 compliant date string
  839. *
  840. * @param int $timestamp Unix time stamp
  841. * @param boolean $utc Whether the time stamp is UTC or local
  842. * @return mixed ISO 8601 date string or false
  843. * @access public
  844. */
  845. function timestamp_to_iso8601($timestamp,$utc=true){
  846. $datestr = date('Y-m-d\TH:i:sO',$timestamp);
  847. $pos = strrpos($datestr, "+");
  848. if ($pos === FALSE) {
  849. $pos = strrpos($datestr, "-");
  850. }
  851. if ($pos !== FALSE) {
  852. if (strlen($datestr) == $pos + 5) {
  853. $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
  854. }
  855. }
  856. if($utc){
  857. $pattern = '/'.
  858. '([0-9]{4})-'. // centuries & years CCYY-
  859. '([0-9]{2})-'. // months MM-
  860. '([0-9]{2})'. // days DD
  861. 'T'. // separator T
  862. '([0-9]{2}):'. // hours hh:
  863. '([0-9]{2}):'. // minutes mm:
  864. '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
  865. '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
  866. '/';
  867. if(preg_match($pattern,$datestr,$regs)){
  868. return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
  869. }
  870. return false;
  871. } else {
  872. return $datestr;
  873. }
  874. }
  875. /**
  876. * convert ISO 8601 compliant date string to unix timestamp
  877. *
  878. * @param string $datestr ISO 8601 compliant date string
  879. * @return mixed Unix timestamp (int) or false
  880. * @access public
  881. */
  882. function iso8601_to_timestamp($datestr){
  883. $pattern = '/'.
  884. '([0-9]{4})-'. // centuries & years CCYY-
  885. '([0-9]{2})-'. // months MM-
  886. '([0-9]{2})'. // days DD
  887. 'T'. // separator T
  888. '([0-9]{2}):'. // hours hh:
  889. '([0-9]{2}):'. // minutes mm:
  890. '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
  891. '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
  892. '/';
  893. if(preg_match($pattern,$datestr,$regs)){
  894. // not utc
  895. if($regs[8] != 'Z'){
  896. $op = substr($regs[8],0,1);
  897. $h = substr($regs[8],1,2);
  898. $m = substr($regs[8],strlen($regs[8])-2,2);
  899. if($op == '-'){
  900. $regs[4] = $regs[4] + $h;
  901. $regs[5] = $regs[5] + $m;
  902. } elseif($op == '+'){
  903. $regs[4] = $regs[4] - $h;
  904. $regs[5] = $regs[5] - $m;
  905. }
  906. }
  907. return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
  908. // return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
  909. } else {
  910. return false;
  911. }
  912. }
  913. /**
  914. * sleeps some number of microseconds
  915. *
  916. * @param string $usec the number of microseconds to sleep
  917. * @access public
  918. * @deprecated
  919. */
  920. function usleepWindows($usec)
  921. {
  922. $start = gettimeofday();
  923. do
  924. {
  925. $stop = gettimeofday();
  926. $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
  927. + $stop['usec'] - $start['usec'];
  928. }
  929. while ($timePassed < $usec);
  930. }
  931. ?><?php
  932. /**
  933. * Contains information for a SOAP fault.
  934. * Mainly used for returning faults from deployed functions
  935. * in a server instance.
  936. * @author Dietrich Ayala <dietrich@ganx4.com>
  937. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  938. * @access public
  939. */
  940. class nusoap_fault extends nusoap_base {
  941. /**
  942. * The fault code (client|server)
  943. * @var string
  944. * @access private
  945. */
  946. var $faultcode;
  947. /**
  948. * The fault actor
  949. * @var string
  950. * @access private
  951. */
  952. var $faultactor;
  953. /**
  954. * The fault string, a description of the fault
  955. * @var string
  956. * @access private
  957. */
  958. var $faultstring;
  959. /**
  960. * The fault detail, typically a string or array of string
  961. * @var mixed
  962. * @access private
  963. */
  964. var $faultdetail;
  965. /**
  966. * constructor
  967. *
  968. * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
  969. * @param string $faultactor only used when msg routed between multiple actors
  970. * @param string $faultstring human readable error message
  971. * @param mixed $faultdetail detail, typically a string or array of string
  972. */
  973. function nusoap_fault($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
  974. parent::nusoap_base();
  975. $this->faultcode = $faultcode;
  976. $this->faultactor = $faultactor;
  977. $this->faultstring = $faultstring;
  978. $this->faultdetail = $faultdetail;
  979. }
  980. /**
  981. * serialize a fault
  982. *
  983. * @return string The serialization of the fault instance.
  984. * @access public
  985. */
  986. function serialize(){
  987. $ns_string = '';
  988. foreach($this->namespaces as $k => $v){
  989. $ns_string .= "\n xmlns:$k=\"$v\"";
  990. }
  991. $return_msg =
  992. '<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
  993. '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
  994. '<SOAP-ENV:Body>'.
  995. '<SOAP-ENV:Fault>'.
  996. $this->serialize_val($this->faultcode, 'faultcode').
  997. $this->serialize_val($this->faultactor, 'faultactor').
  998. $this->serialize_val($this->faultstring, 'faultstring').
  999. $this->serialize_val($this->faultdetail, 'detail').
  1000. '</SOAP-ENV:Fault>'.
  1001. '</SOAP-ENV:Body>'.
  1002. '</SOAP-ENV:Envelope>';
  1003. return $return_msg;
  1004. }
  1005. }
  1006. /**
  1007. * Backward compatibility
  1008. */
  1009. class soap_fault extends nusoap_fault {
  1010. }
  1011. ?><?php
  1012. /**
  1013. * parses an XML Schema, allows access to it's data, other utility methods.
  1014. * imperfect, no validation... yet, but quite functional.
  1015. *
  1016. * @author Dietrich Ayala <dietrich@ganx4.com>
  1017. * @author Scott Nichol <snichol@users.sourceforge.net>
  1018. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  1019. * @access public
  1020. */
  1021. class nusoap_xmlschema extends nusoap_base {
  1022. // files
  1023. var $schema = '';
  1024. var $xml = '';
  1025. // namespaces
  1026. var $enclosingNamespaces;
  1027. // schema info
  1028. var $schemaInfo = array();
  1029. var $schemaTargetNamespace = '';
  1030. // types, elements, attributes defined by the schema
  1031. var $attributes = array();
  1032. var $complexTypes = array();
  1033. var $complexTypeStack = array();
  1034. var $currentComplexType = null;
  1035. var $elements = array();
  1036. var $elementStack = array();
  1037. var $currentElement = null;
  1038. var $simpleTypes = array();
  1039. var $simpleTypeStack = array();
  1040. var $currentSimpleType = null;
  1041. // imports
  1042. var $imports = array();
  1043. // parser vars
  1044. var $parser;
  1045. var $position = 0;
  1046. var $depth = 0;
  1047. var $depth_array = array();
  1048. var $message = array();
  1049. var $defaultNamespace = array();
  1050. /**
  1051. * constructor
  1052. *
  1053. * @param string $schema schema document URI
  1054. * @param string $xml xml document URI
  1055. * @param string $namespaces namespaces defined in enclosing XML
  1056. * @access public
  1057. */
  1058. function nusoap_xmlschema($schema='',$xml='',$namespaces=array()){
  1059. parent::nusoap_base();
  1060. $this->debug('nusoap_xmlschema class instantiated, inside constructor');
  1061. // files
  1062. $this->schema = $schema;
  1063. $this->xml = $xml;
  1064. // namespaces
  1065. $this->enclosingNamespaces = $namespaces;
  1066. $this->namespaces = array_merge($this->namespaces, $namespaces);
  1067. // parse schema file
  1068. if($schema != ''){
  1069. $this->debug('initial schema file: '.$schema);
  1070. $this->parseFile($schema, 'schema');
  1071. }
  1072. // parse xml file
  1073. if($xml != ''){
  1074. $this->debug('initial xml file: '.$xml);
  1075. $this->parseFile($xml, 'xml');
  1076. }
  1077. }
  1078. /**
  1079. * parse an XML file
  1080. *
  1081. * @param string $xml path/URL to XML file
  1082. * @param string $type (schema | xml)
  1083. * @return boolean
  1084. * @access public
  1085. */
  1086. function parseFile($xml,$type){
  1087. // parse xml file
  1088. if($xml != ""){
  1089. $xmlStr = @join("",@file($xml));
  1090. if($xmlStr == ""){
  1091. $msg = 'Error reading XML from '.$xml;
  1092. $this->setError($msg);
  1093. $this->debug($msg);
  1094. return false;
  1095. } else {
  1096. $this->debug("parsing $xml");
  1097. $this->parseString($xmlStr,$type);
  1098. $this->debug("done parsing $xml");
  1099. return true;
  1100. }
  1101. }
  1102. return false;
  1103. }
  1104. /**
  1105. * parse an XML string
  1106. *
  1107. * @param string $xml path or URL
  1108. * @param string $type (schema|xml)
  1109. * @access private
  1110. */
  1111. function parseString($xml,$type){
  1112. // parse xml string
  1113. if($xml != ""){
  1114. // Create an XML parser.
  1115. $this->parser = xml_parser_create();
  1116. // Set the options for parsing the XML data.
  1117. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  1118. // Set the object for the parser.
  1119. xml_set_object($this->parser, $this);
  1120. // Set the element handlers for the parser.
  1121. if($type == "schema"){
  1122. xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
  1123. xml_set_character_data_handler($this->parser,'schemaCharacterData');
  1124. } elseif($type == "xml"){
  1125. xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
  1126. xml_set_character_data_handler($this->parser,'xmlCharacterData');
  1127. }
  1128. // Parse the XML file.
  1129. if(!xml_parse($this->parser,$xml,true)){
  1130. // Display an error message.
  1131. $errstr = sprintf('XML error parsing XML schema on line %d: %s',
  1132. xml_get_current_line_number($this->parser),
  1133. xml_error_string(xml_get_error_code($this->parser))
  1134. );
  1135. $this->debug($errstr);
  1136. $this->debug("XML payload:\n" . $xml);
  1137. $this->setError($errstr);
  1138. }
  1139. xml_parser_free($this->parser);
  1140. } else{
  1141. $this->debug('no xml passed to parseString()!!');
  1142. $this->setError('no xml passed to parseString()!!');
  1143. }
  1144. }
  1145. /**
  1146. * gets a type name for an unnamed type
  1147. *
  1148. * @param string Element name
  1149. * @return string A type name for an unnamed type
  1150. * @access private
  1151. */
  1152. function CreateTypeName($ename) {
  1153. $scope = '';
  1154. for ($i = 0; $i < count($this->complexTypeStack); $i++) {
  1155. $scope .= $this->complexTypeStack[$i] . '_';
  1156. }
  1157. return $scope . $ename . '_ContainedType';
  1158. }
  1159. /**
  1160. * start-element handler
  1161. *
  1162. * @param string $parser XML parser object
  1163. * @param string $name element name
  1164. * @param string $attrs associative array of attributes
  1165. * @access private
  1166. */
  1167. function schemaStartElement($parser, $name, $attrs) {
  1168. // position in the total number of elements, starting from 0
  1169. $pos = $this->position++;
  1170. $depth = $this->depth++;
  1171. // set self as current value for this depth
  1172. $this->depth_array[$depth] = $pos;
  1173. $this->message[$pos] = array('cdata' => '');
  1174. if ($depth > 0) {
  1175. $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
  1176. } else {
  1177. $this->defaultNamespace[$pos] = false;
  1178. }
  1179. // get element prefix
  1180. if($prefix = $this->getPrefix($name)){
  1181. // get unqualified name
  1182. $name = $this->getLocalPart($name);
  1183. } else {
  1184. $prefix = '';
  1185. }
  1186. // loop thru attributes, expanding, and registering namespace declarations
  1187. if(count($attrs) > 0){
  1188. foreach($attrs as $k => $v){
  1189. // if ns declarations, add to class level array of valid namespaces
  1190. if(preg_match('/^xmlns/',$k)){
  1191. //$this->xdebug("$k: $v");
  1192. //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
  1193. if($ns_prefix = substr(strrchr($k,':'),1)){
  1194. //$this->xdebug("Add namespace[$ns_prefix] = $v");
  1195. $this->namespaces[$ns_prefix] = $v;
  1196. } else {
  1197. $this->defaultNamespace[$pos] = $v;
  1198. if (! $this->getPrefixFromNamespace($v)) {
  1199. $this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
  1200. }
  1201. }
  1202. if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){
  1203. $this->XMLSchemaVersion = $v;
  1204. $this->namespaces['xsi'] = $v.'-instance';
  1205. }
  1206. }
  1207. }
  1208. foreach($attrs as $k => $v){
  1209. // expand each attribute
  1210. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  1211. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  1212. $eAttrs[$k] = $v;
  1213. }
  1214. $attrs = $eAttrs;
  1215. } else {
  1216. $attrs = array();
  1217. }
  1218. // find status, register data
  1219. switch($name){
  1220. case 'all': // (optional) compositor content for a complexType
  1221. case 'choice':
  1222. case 'group':
  1223. case 'sequence':
  1224. //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
  1225. $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
  1226. //if($name == 'all' || $name == 'sequence'){
  1227. // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  1228. //}
  1229. break;
  1230. case 'attribute': // complexType attribute
  1231. //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
  1232. $this->xdebug("parsing attribute:");
  1233. $this->appendDebug($this->varDump($attrs));
  1234. if (!isset($attrs['form'])) {
  1235. // TODO: handle globals
  1236. $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
  1237. }
  1238. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
  1239. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1240. if (!strpos($v, ':')) {
  1241. // no namespace in arrayType attribute value...
  1242. if ($this->defaultNamespace[$pos]) {
  1243. // ...so use the default
  1244. $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1245. }
  1246. }
  1247. }
  1248. if(isset($attrs['name'])){
  1249. $this->attributes[$attrs['name']] = $attrs;
  1250. $aname = $attrs['name'];
  1251. } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
  1252. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
  1253. $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1254. } else {
  1255. $aname = '';
  1256. }
  1257. } elseif(isset($attrs['ref'])){
  1258. $aname = $attrs['ref'];
  1259. $this->attributes[$attrs['ref']] = $attrs;
  1260. }
  1261. if($this->currentComplexType){ // This should *always* be
  1262. $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
  1263. }
  1264. // arrayType attribute
  1265. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
  1266. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1267. $prefix = $this->getPrefix($aname);
  1268. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
  1269. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1270. } else {
  1271. $v = '';
  1272. }
  1273. if(strpos($v,'[,]')){
  1274. $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
  1275. }
  1276. $v = substr($v,0,strpos($v,'[')); // clip the []
  1277. if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
  1278. $v = $this->XMLSchemaVersion.':'.$v;
  1279. }
  1280. $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
  1281. }
  1282. break;
  1283. case 'complexContent': // (optional) content for a complexType
  1284. $this->xdebug("do nothing for element $name");
  1285. break;
  1286. case 'complexType':
  1287. array_push($this->complexTypeStack, $this->currentComplexType);
  1288. if(isset($attrs['name'])){
  1289. // TODO: what is the scope of named complexTypes that appear
  1290. // nested within other c complexTypes?
  1291. $this->xdebug('processing named complexType '.$attrs['name']);
  1292. //$this->currentElement = false;
  1293. $this->currentComplexType = $attrs['name'];
  1294. $this->complexTypes[$this->currentComplexType] = $attrs;
  1295. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
  1296. // This is for constructs like
  1297. // <complexType name="ListOfString" base="soap:Array">
  1298. // <sequence>
  1299. // <element name="string" type="xsd:string"
  1300. // minOccurs="0" maxOccurs="unbounded" />
  1301. // </sequence>
  1302. // </complexType>
  1303. if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
  1304. $this->xdebug('complexType is unusual array');
  1305. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1306. } else {
  1307. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  1308. }
  1309. } else {
  1310. $name = $this->CreateTypeName($this->currentElement);
  1311. $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
  1312. $this->currentComplexType = $name;
  1313. //$this->currentElement = false;
  1314. $this->complexTypes[$this->currentComplexType] = $attrs;
  1315. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
  1316. // This is for constructs like
  1317. // <complexType name="ListOfString" base="soap:Array">
  1318. // <sequence>
  1319. // <element name="string" type="xsd:string"
  1320. // minOccurs="0" maxOccurs="unbounded" />
  1321. // </sequence>
  1322. // </complexType>
  1323. if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
  1324. $this->xdebug('complexType is unusual array');
  1325. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1326. } else {
  1327. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  1328. }
  1329. }
  1330. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
  1331. break;
  1332. case 'element':
  1333. array_push($this->elementStack, $this->currentElement);
  1334. if (!isset($attrs['form'])) {
  1335. if ($this->currentComplexType) {
  1336. $attrs['form'] = $this->schemaInfo['elementFormDefault'];
  1337. } else {
  1338. // global
  1339. $attrs['form'] = 'qualified';
  1340. }
  1341. }
  1342. if(isset($attrs['type'])){
  1343. $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
  1344. if (! $this->getPrefix($attrs['type'])) {
  1345. if ($this->defaultNamespace[$pos]) {
  1346. $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
  1347. $this->xdebug('used default namespace to make type ' . $attrs['type']);
  1348. }
  1349. }
  1350. // This is for constructs like
  1351. // <complexType name="ListOfString" base="soap:Array">
  1352. // <sequence>
  1353. // <element name="string" type="xsd:string"
  1354. // minOccurs="0" maxOccurs="unbounded" />
  1355. // </sequence>
  1356. // </complexType>
  1357. if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
  1358. $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
  1359. $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
  1360. }
  1361. $this->currentElement = $attrs['name'];
  1362. $ename = $attrs['name'];
  1363. } elseif(isset($attrs['ref'])){
  1364. $this->xdebug("processing element as ref to ".$attrs['ref']);
  1365. $this->currentElement = "ref to ".$attrs['ref'];
  1366. $ename = $this->getLocalPart($attrs['ref']);
  1367. } else {
  1368. $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
  1369. $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
  1370. $this->currentElement = $attrs['name'];
  1371. $attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
  1372. $ename = $attrs['name'];
  1373. }
  1374. if (isset($ename) && $this->currentComplexType) {
  1375. $this->xdebug("add element $ename to complexType $this->currentComplexType");
  1376. $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
  1377. } elseif (!isset($attrs['ref'])) {
  1378. $this->xdebug("add element $ename to elements array");
  1379. $this->elements[ $attrs['name'] ] = $attrs;
  1380. $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
  1381. }
  1382. break;
  1383. case 'enumeration': // restriction value list member
  1384. $this->xdebug('enumeration ' . $attrs['value']);
  1385. if ($this->currentSimpleType) {
  1386. $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
  1387. } elseif ($this->currentComplexType) {
  1388. $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
  1389. }
  1390. break;
  1391. case 'extension': // simpleContent or complexContent type extension
  1392. $this->xdebug('extension ' . $attrs['base']);
  1393. if ($this->currentComplexType) {
  1394. $ns = $this->getPrefix($attrs['base']);
  1395. if ($ns == '') {
  1396. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
  1397. } else {
  1398. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
  1399. }
  1400. } else {
  1401. $this->xdebug('no current complexType to set extensionBase');
  1402. }
  1403. break;
  1404. case 'import':
  1405. if (isset($attrs['schemaLocation'])) {
  1406. $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
  1407. $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
  1408. } else {
  1409. $this->xdebug('import namespace ' . $attrs['namespace']);
  1410. $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
  1411. if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
  1412. $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
  1413. }
  1414. }
  1415. break;
  1416. case 'include':
  1417. if (isset($attrs['schemaLocation'])) {
  1418. $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
  1419. $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
  1420. } else {
  1421. $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
  1422. }
  1423. break;
  1424. case 'list': // simpleType value list
  1425. $this->xdebug("do nothing for element $name");
  1426. break;
  1427. case 'restriction': // simpleType, simpleContent or complexContent value restriction
  1428. $this->xdebug('restriction ' . $attrs['base']);
  1429. if($this->currentSimpleType){
  1430. $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
  1431. } elseif($this->currentComplexType){
  1432. $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
  1433. if(strstr($attrs['base'],':') == ':Array'){
  1434. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1435. }
  1436. }
  1437. break;
  1438. case 'schema':
  1439. $this->schemaInfo = $attrs;
  1440. $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
  1441. if (isset($attrs['targetNamespace'])) {
  1442. $this->schemaTargetNamespace = $attrs['targetNamespace'];
  1443. }
  1444. if (!isset($attrs['elementFormDefault'])) {
  1445. $this->schemaInfo['elementFormDefault'] = 'unqualified';
  1446. }
  1447. if (!isset($attrs['attributeFormDefault'])) {
  1448. $this->schemaInfo['attributeFormDefault'] = 'unqualified';
  1449. }
  1450. break;
  1451. case 'simpleContent': // (optional) content for a complexType
  1452. if ($this->currentComplexType) { // This should *always* be
  1453. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
  1454. } else {
  1455. $this->xdebug("do nothing for element $name because there is no current complexType");
  1456. }
  1457. break;
  1458. case 'simpleType':
  1459. array_push($this->simpleTypeStack, $this->currentSimpleType);
  1460. if(isset($attrs['name'])){
  1461. $this->xdebug("processing simpleType for name " . $attrs['name']);
  1462. $this->currentSimpleType = $attrs['name'];
  1463. $this->simpleTypes[ $attrs['name'] ] = $attrs;
  1464. $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType';
  1465. $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar';
  1466. } else {
  1467. $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
  1468. $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
  1469. $this->currentSimpleType = $name;
  1470. //$this->currentElement = false;
  1471. $this->simpleTypes[$this->currentSimpleType] = $attrs;
  1472. $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
  1473. }
  1474. break;
  1475. case 'union': // simpleType type list
  1476. $this->xdebug("do nothing for element $name");
  1477. break;
  1478. default:
  1479. $this->xdebug("do not have any logic to process element $name");
  1480. }
  1481. }
  1482. /**
  1483. * end-element handler
  1484. *
  1485. * @param string $parser XML parser object
  1486. * @param string $name element name
  1487. * @access private
  1488. */
  1489. function schemaEndElement($parser, $name) {
  1490. // bring depth down a notch
  1491. $this->depth--;
  1492. // position of current element is equal to the last value left in depth_array for my depth
  1493. if(isset($this->depth_array[$this->depth])){
  1494. $pos = $this->depth_array[$this->depth];
  1495. }
  1496. // get element prefix
  1497. if ($prefix = $this->getPrefix($name)){
  1498. // get unqualified name
  1499. $name = $this->getLocalPart($name);
  1500. } else {
  1501. $prefix = '';
  1502. }
  1503. // move on...
  1504. if($name == 'complexType'){
  1505. $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
  1506. $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
  1507. $this->currentComplexType = array_pop($this->complexTypeStack);
  1508. //$this->currentElement = false;
  1509. }
  1510. if($name == 'element'){
  1511. $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)'));
  1512. $this->currentElement = array_pop($this->elementStack);
  1513. }
  1514. if($name == 'simpleType'){
  1515. $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)'));
  1516. $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
  1517. $this->currentSimpleType = array_pop($this->simpleTypeStack);
  1518. }
  1519. }
  1520. /**
  1521. * element content handler
  1522. *
  1523. * @param string $parser XML parser object
  1524. * @param string $data element content
  1525. * @access private
  1526. */
  1527. function schemaCharacterData($parser, $data){
  1528. $pos = $this->depth_array[$this->depth - 1];
  1529. $this->message[$pos]['cdata'] .= $data;
  1530. }
  1531. /**
  1532. * serialize the schema
  1533. *
  1534. * @access public
  1535. */
  1536. function serializeSchema(){
  1537. $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
  1538. $xml = '';
  1539. // imports
  1540. if (sizeof($this->imports) > 0) {
  1541. foreach($this->imports as $ns => $list) {
  1542. foreach ($list as $ii) {
  1543. if ($ii['location'] != '') {
  1544. $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
  1545. } else {
  1546. $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
  1547. }
  1548. }
  1549. }
  1550. }
  1551. // complex types
  1552. foreach($this->complexTypes as $typeName => $attrs){
  1553. $contentStr = '';
  1554. // serialize child elements
  1555. if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){
  1556. foreach($attrs['elements'] as $element => $eParts){
  1557. if(isset($eParts['ref'])){
  1558. $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n";
  1559. } else {
  1560. $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
  1561. foreach ($eParts as $aName => $aValue) {
  1562. // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
  1563. if ($aName != 'name' && $aName != 'type') {
  1564. $contentStr .= " $aName=\"$aValue\"";
  1565. }
  1566. }
  1567. $contentStr .= "/>\n";
  1568. }
  1569. }
  1570. // compositor wraps elements
  1571. if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
  1572. $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n";
  1573. }
  1574. }
  1575. // attributes
  1576. if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){
  1577. foreach($attrs['attrs'] as $attr => $aParts){
  1578. $contentStr .= " <$schemaPrefix:attribute";
  1579. foreach ($aParts as $a => $v) {
  1580. if ($a == 'ref' || $a == 'type') {
  1581. $contentStr .= " $a=\"".$this->contractQName($v).'"';
  1582. } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
  1583. $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
  1584. $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"';
  1585. } else {
  1586. $contentStr .= " $a=\"$v\"";
  1587. }
  1588. }
  1589. $contentStr .= "/>\n";
  1590. }
  1591. }
  1592. // if restriction
  1593. if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){
  1594. $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n";
  1595. // complex or simple content
  1596. if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){
  1597. $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n";
  1598. }
  1599. }
  1600. // finalize complex type
  1601. if($contentStr != ''){
  1602. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n";
  1603. } else {
  1604. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
  1605. }
  1606. $xml .= $contentStr;
  1607. }
  1608. // simple types
  1609. if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){
  1610. foreach($this->simpleTypes as $typeName => $eParts){
  1611. $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n";
  1612. if (isset($eParts['enumeration'])) {
  1613. foreach ($eParts['enumeration'] as $e) {
  1614. $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n";
  1615. }
  1616. }
  1617. $xml .= " </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
  1618. }
  1619. }
  1620. // elements
  1621. if(isset($this->elements) && count($this->elements) > 0){
  1622. foreach($this->elements as $element => $eParts){
  1623. $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n";
  1624. }
  1625. }
  1626. // attributes
  1627. if(isset($this->attributes) && count($this->attributes) > 0){
  1628. foreach($this->attributes as $attr => $aParts){
  1629. $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>";
  1630. }
  1631. }
  1632. // finish 'er up
  1633. $attr = '';
  1634. foreach ($this->schemaInfo as $k => $v) {
  1635. if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
  1636. $attr .= " $k=\"$v\"";
  1637. }
  1638. }
  1639. $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
  1640. foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
  1641. $el .= " xmlns:$nsp=\"$ns\"";
  1642. }
  1643. $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n";
  1644. return $xml;
  1645. }
  1646. /**
  1647. * adds debug data to the clas level debug string
  1648. *
  1649. * @param string $string debug data
  1650. * @access private
  1651. */
  1652. function xdebug($string){
  1653. $this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
  1654. }
  1655. /**
  1656. * get the PHP type of a user defined type in the schema
  1657. * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
  1658. * returns false if no type exists, or not w/ the given namespace
  1659. * else returns a string that is either a native php type, or 'struct'
  1660. *
  1661. * @param string $type name of defined type
  1662. * @param string $ns namespace of type
  1663. * @return mixed
  1664. * @access public
  1665. * @deprecated
  1666. */
  1667. function getPHPType($type,$ns){
  1668. if(isset($this->typemap[$ns][$type])){
  1669. //print "found type '$type' and ns $ns in typemap<br>";
  1670. return $this->typemap[$ns][$type];
  1671. } elseif(isset($this->complexTypes[$type])){
  1672. //print "getting type '$type' and ns $ns from complexTypes array<br>";
  1673. return $this->complexTypes[$type]['phpType'];
  1674. }
  1675. return false;
  1676. }
  1677. /**
  1678. * returns an associative array of information about a given type
  1679. * returns false if no type exists by the given name
  1680. *
  1681. * For a complexType typeDef = array(
  1682. * 'restrictionBase' => '',
  1683. * 'phpType' => '',
  1684. * 'compositor' => '(sequence|all)',
  1685. * 'elements' => array(), // refs to elements array
  1686. * 'attrs' => array() // refs to attributes array
  1687. * ... and so on (see addComplexType)
  1688. * )
  1689. *
  1690. * For simpleType or element, the array has different keys.
  1691. *
  1692. * @param string $type
  1693. * @return mixed
  1694. * @access public
  1695. * @see addComplexType
  1696. * @see addSimpleType
  1697. * @see addElement
  1698. */
  1699. function getTypeDef($type){
  1700. //$this->debug("in getTypeDef for type $type");
  1701. if (substr($type, -1) == '^') {
  1702. $is_element = 1;
  1703. $type = substr($type, 0, -1);
  1704. } else {
  1705. $is_element = 0;
  1706. }
  1707. if((! $is_element) && isset($this->complexTypes[$type])){
  1708. $this->xdebug("in getTypeDef, found complexType $type");
  1709. return $this->complexTypes[$type];
  1710. } elseif((! $is_element) && isset($this->simpleTypes[$type])){
  1711. $this->xdebug("in getTypeDef, found simpleType $type");
  1712. if (!isset($this->simpleTypes[$type]['phpType'])) {
  1713. // get info for type to tack onto the simple type
  1714. // TODO: can this ever really apply (i.e. what is a simpleType really?)
  1715. $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
  1716. $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
  1717. $etype = $this->getTypeDef($uqType);
  1718. if ($etype) {
  1719. $this->xdebug("in getTypeDef, found type for simpleType $type:");
  1720. $this->xdebug($this->varDump($etype));
  1721. if (isset($etype['phpType'])) {
  1722. $this->simpleTypes[$type]['phpType'] = $etype['phpType'];
  1723. }
  1724. if (isset($etype['elements'])) {
  1725. $this->simpleTypes[$type]['elements'] = $etype['elements'];
  1726. }
  1727. }
  1728. }
  1729. return $this->simpleTypes[$type];
  1730. } elseif(isset($this->elements[$type])){
  1731. $this->xdebug("in getTypeDef, found element $type");
  1732. if (!isset($this->elements[$type]['phpType'])) {
  1733. // get info for type to tack onto the element
  1734. $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
  1735. $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
  1736. $etype = $this->getTypeDef($uqType);
  1737. if ($etype) {
  1738. $this->xdebug("in getTypeDef, found type for element $type:");
  1739. $this->xdebug($this->varDump($etype));
  1740. if (isset($etype['phpType'])) {
  1741. $this->elements[$type]['phpType'] = $etype['phpType'];
  1742. }
  1743. if (isset($etype['elements'])) {
  1744. $this->elements[$type]['elements'] = $etype['elements'];
  1745. }
  1746. if (isset($etype['extensionBase'])) {
  1747. $this->elements[$type]['extensionBase'] = $etype['extensionBase'];
  1748. }
  1749. } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
  1750. $this->xdebug("in getTypeDef, element $type is an XSD type");
  1751. $this->elements[$type]['phpType'] = 'scalar';
  1752. }
  1753. }
  1754. return $this->elements[$type];
  1755. } elseif(isset($this->attributes[$type])){
  1756. $this->xdebug("in getTypeDef, found attribute $type");
  1757. return $this->attributes[$type];
  1758. } elseif (preg_match('/_ContainedType$/', $type)) {
  1759. $this->xdebug("in getTypeDef, have an untyped element $type");
  1760. $typeDef['typeClass'] = 'simpleType';
  1761. $typeDef['phpType'] = 'scalar';
  1762. $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
  1763. return $typeDef;
  1764. }
  1765. $this->xdebug("in getTypeDef, did not find $type");
  1766. return false;
  1767. }
  1768. /**
  1769. * returns a sample serialization of a given type, or false if no type by the given name
  1770. *
  1771. * @param string $type name of type
  1772. * @return mixed
  1773. * @access public
  1774. * @deprecated
  1775. */
  1776. function serializeTypeDef($type){
  1777. //print "in sTD() for type $type<br>";
  1778. if($typeDef = $this->getTypeDef($type)){
  1779. $str .= '<'.$type;
  1780. if(is_array($typeDef['attrs'])){
  1781. foreach($typeDef['attrs'] as $attName => $data){
  1782. $str .= " $attName=\"{type = ".$data['type']."}\"";
  1783. }
  1784. }
  1785. $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
  1786. if(count($typeDef['elements']) > 0){
  1787. $str .= ">";
  1788. foreach($typeDef['elements'] as $element => $eData){
  1789. $str .= $this->serializeTypeDef($element);
  1790. }
  1791. $str .= "</$type>";
  1792. } elseif($typeDef['typeClass'] == 'element') {
  1793. $str .= "></$type>";
  1794. } else {
  1795. $str .= "/>";
  1796. }
  1797. return $str;
  1798. }
  1799. return false;
  1800. }
  1801. /**
  1802. * returns HTML form elements that allow a user
  1803. * to enter values for creating an instance of the given type.
  1804. *
  1805. * @param string $name name for type instance
  1806. * @param string $type name of type
  1807. * @return string
  1808. * @access public
  1809. * @deprecated
  1810. */
  1811. function typeToForm($name,$type){
  1812. // get typedef
  1813. if($typeDef = $this->getTypeDef($type)){
  1814. // if struct
  1815. if($typeDef['phpType'] == 'struct'){
  1816. $buffer .= '<table>';
  1817. foreach($typeDef['elements'] as $child => $childDef){
  1818. $buffer .= "
  1819. <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td>
  1820. <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>";
  1821. }
  1822. $buffer .= '</table>';
  1823. // if array
  1824. } elseif($typeDef['phpType'] == 'array'){
  1825. $buffer .= '<table>';
  1826. for($i=0;$i < 3; $i++){
  1827. $buffer .= "
  1828. <tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
  1829. <td><input type='text' name='parameters[".$name."][]'></td></tr>";
  1830. }
  1831. $buffer .= '</table>';
  1832. // if scalar
  1833. } else {
  1834. $buffer .= "<input type='text' name='parameters[$name]'>";
  1835. }
  1836. } else {
  1837. $buffer .= "<input type='text' name='parameters[$name]'>";
  1838. }
  1839. return $buffer;
  1840. }
  1841. /**
  1842. * adds a complex type to the schema
  1843. *
  1844. * example: array
  1845. *
  1846. * addType(
  1847. * 'ArrayOfstring',
  1848. * 'complexType',
  1849. * 'array',
  1850. * '',
  1851. * 'SOAP-ENC:Array',
  1852. * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
  1853. * 'xsd:string'
  1854. * );
  1855. *
  1856. * example: PHP associative array ( SOAP Struct )
  1857. *
  1858. * addType(
  1859. * 'SOAPStruct',
  1860. * 'complexType',
  1861. * 'struct',
  1862. * 'all',
  1863. * array('myVar'=> array('name'=>'myVar','type'=>'string')
  1864. * );
  1865. *
  1866. * @param name
  1867. * @param typeClass (complexType|simpleType|attribute)
  1868. * @param phpType: currently supported are array and struct (php assoc array)
  1869. * @param compositor (all|sequence|choice)
  1870. * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  1871. * @param elements = array ( name = array(name=>'',type=>'') )
  1872. * @param attrs = array(
  1873. * array(
  1874. * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
  1875. * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
  1876. * )
  1877. * )
  1878. * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
  1879. * @access public
  1880. * @see getTypeDef
  1881. */
  1882. function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
  1883. $this->complexTypes[$name] = array(
  1884. 'name' => $name,
  1885. 'typeClass' => $typeClass,
  1886. 'phpType' => $phpType,
  1887. 'compositor'=> $compositor,
  1888. 'restrictionBase' => $restrictionBase,
  1889. 'elements' => $elements,
  1890. 'attrs' => $attrs,
  1891. 'arrayType' => $arrayType
  1892. );
  1893. $this->xdebug("addComplexType $name:");
  1894. $this->appendDebug($this->varDump($this->complexTypes[$name]));
  1895. }
  1896. /**
  1897. * adds a simple type to the schema
  1898. *
  1899. * @param string $name
  1900. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  1901. * @param string $typeClass (should always be simpleType)
  1902. * @param string $phpType (should always be scalar)
  1903. * @param array $enumeration array of values
  1904. * @access public
  1905. * @see nusoap_xmlschema
  1906. * @see getTypeDef
  1907. */
  1908. function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
  1909. $this->simpleTypes[$name] = array(
  1910. 'name' => $name,
  1911. 'typeClass' => $typeClass,
  1912. 'phpType' => $phpType,
  1913. 'type' => $restrictionBase,
  1914. 'enumeration' => $enumeration
  1915. );
  1916. $this->xdebug("addSimpleType $name:");
  1917. $this->appendDebug($this->varDump($this->simpleTypes[$name]));
  1918. }
  1919. /**
  1920. * adds an element to the schema
  1921. *
  1922. * @param array $attrs attributes that must include name and type
  1923. * @see nusoap_xmlschema
  1924. * @access public
  1925. */
  1926. function addElement($attrs) {
  1927. if (! $this->getPrefix($attrs['type'])) {
  1928. $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
  1929. }
  1930. $this->elements[ $attrs['name'] ] = $attrs;
  1931. $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
  1932. $this->xdebug("addElement " . $attrs['name']);
  1933. $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));
  1934. }
  1935. }
  1936. /**
  1937. * Backward compatibility
  1938. */
  1939. class XMLSchema extends nusoap_xmlschema {
  1940. }
  1941. ?><?php
  1942. /**
  1943. * For creating serializable abstractions of native PHP types. This class
  1944. * allows element name/namespace, XSD type, and XML attributes to be
  1945. * associated with a value. This is extremely useful when WSDL is not
  1946. * used, but is also useful when WSDL is used with polymorphic types, including
  1947. * xsd:anyType and user-defined types.
  1948. *
  1949. * @author Dietrich Ayala <dietrich@ganx4.com>
  1950. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  1951. * @access public
  1952. */
  1953. class soapval extends nusoap_base {
  1954. /**
  1955. * The XML element name
  1956. *
  1957. * @var string
  1958. * @access private
  1959. */
  1960. var $name;
  1961. /**
  1962. * The XML type name (string or false)
  1963. *
  1964. * @var mixed
  1965. * @access private
  1966. */
  1967. var $type;
  1968. /**
  1969. * The PHP value
  1970. *
  1971. * @var mixed
  1972. * @access private
  1973. */
  1974. var $value;
  1975. /**
  1976. * The XML element namespace (string or false)
  1977. *
  1978. * @var mixed
  1979. * @access private
  1980. */
  1981. var $element_ns;
  1982. /**
  1983. * The XML type namespace (string or false)
  1984. *
  1985. * @var mixed
  1986. * @access private
  1987. */
  1988. var $type_ns;
  1989. /**
  1990. * The XML element attributes (array or false)
  1991. *
  1992. * @var mixed
  1993. * @access private
  1994. */
  1995. var $attributes;
  1996. /**
  1997. * constructor
  1998. *
  1999. * @param string $name optional name
  2000. * @param mixed $type optional type name
  2001. * @param mixed $value optional value
  2002. * @param mixed $element_ns optional namespace of value
  2003. * @param mixed $type_ns optional namespace of type
  2004. * @param mixed $attributes associative array of attributes to add to element serialization
  2005. * @access public
  2006. */
  2007. function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
  2008. parent::nusoap_base();
  2009. $this->name = $name;
  2010. $this->type = $type;
  2011. $this->value = $value;
  2012. $this->element_ns = $element_ns;
  2013. $this->type_ns = $type_ns;
  2014. $this->attributes = $attributes;
  2015. }
  2016. /**
  2017. * return serialized value
  2018. *
  2019. * @param string $use The WSDL use value (encoded|literal)
  2020. * @return string XML data
  2021. * @access public
  2022. */
  2023. function serialize($use='encoded') {
  2024. return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
  2025. }
  2026. /**
  2027. * decodes a soapval object into a PHP native type
  2028. *
  2029. * @return mixed
  2030. * @access public
  2031. */
  2032. function decode(){
  2033. return $this->value;
  2034. }
  2035. }
  2036. ?><?php
  2037. /**
  2038. * transport class for sending/receiving data via HTTP and HTTPS
  2039. * NOTE: PHP must be compiled with the CURL extension for HTTPS support
  2040. *
  2041. * @author Dietrich Ayala <dietrich@ganx4.com>
  2042. * @author Scott Nichol <snichol@users.sourceforge.net>
  2043. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  2044. * @access public
  2045. */
  2046. class soap_transport_http extends nusoap_base {
  2047. var $url = '';
  2048. var $uri = '';
  2049. var $digest_uri = '';
  2050. var $scheme = '';
  2051. var $host = '';
  2052. var $port = '';
  2053. var $path = '';
  2054. var $request_method = 'POST';
  2055. var $protocol_version = '1.0';
  2056. var $encoding = '';
  2057. var $outgoing_headers = array();
  2058. var $incoming_headers = array();
  2059. var $incoming_cookies = array();
  2060. var $outgoing_payload = '';
  2061. var $incoming_payload = '';
  2062. var $response_status_line; // HTTP response status line
  2063. var $useSOAPAction = true;
  2064. var $persistentConnection = false;
  2065. var $ch = false; // cURL handle
  2066. var $ch_options = array(); // cURL custom options
  2067. var $use_curl = false; // force cURL use
  2068. var $proxy = null; // proxy information (associative array)
  2069. var $username = '';
  2070. var $password = '';
  2071. var $authtype = '';
  2072. var $digestRequest = array();
  2073. var $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
  2074. // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
  2075. // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
  2076. // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
  2077. // passphrase: SSL key password/passphrase
  2078. // certpassword: SSL certificate password
  2079. // verifypeer: default is 1
  2080. // verifyhost: default is 1
  2081. /**
  2082. * constructor
  2083. *
  2084. * @param string $url The URL to which to connect
  2085. * @param array $curl_options User-specified cURL options
  2086. * @param boolean $use_curl Whether to try to force cURL use
  2087. * @access public
  2088. */
  2089. function soap_transport_http($url, $curl_options = NULL, $use_curl = false){
  2090. parent::nusoap_base();
  2091. $this->debug("ctor url=$url use_curl=$use_curl curl_options:");
  2092. $this->appendDebug($this->varDump($curl_options));
  2093. $this->setURL($url);
  2094. if (is_array($curl_options)) {
  2095. $this->ch_options = $curl_options;
  2096. }
  2097. $this->use_curl = $use_curl;
  2098. preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
  2099. $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')');
  2100. }
  2101. /**
  2102. * sets a cURL option
  2103. *
  2104. * @param mixed $option The cURL option (always integer?)
  2105. * @param mixed $value The cURL option value
  2106. * @access private
  2107. */
  2108. function setCurlOption($option, $value) {
  2109. $this->debug("setCurlOption option=$option, value=");
  2110. $this->appendDebug($this->varDump($value));
  2111. curl_setopt($this->ch, $option, $value);
  2112. }
  2113. /**
  2114. * sets an HTTP header
  2115. *
  2116. * @param string $name The name of the header
  2117. * @param string $value The value of the header
  2118. * @access private
  2119. */
  2120. function setHeader($name, $value) {
  2121. $this->outgoing_headers[$name] = $value;
  2122. $this->debug("set header $name: $value");
  2123. }
  2124. /**
  2125. * unsets an HTTP header
  2126. *
  2127. * @param string $name The name of the header
  2128. * @access private
  2129. */
  2130. function unsetHeader($name) {
  2131. if (isset($this->outgoing_headers[$name])) {
  2132. $this->debug("unset header $name");
  2133. unset($this->outgoing_headers[$name]);
  2134. }
  2135. }
  2136. /**
  2137. * sets the URL to which to connect
  2138. *
  2139. * @param string $url The URL to which to connect
  2140. * @access private
  2141. */
  2142. function setURL($url) {
  2143. $this->url = $url;
  2144. $u = parse_url($url);
  2145. foreach($u as $k => $v){
  2146. $this->debug("parsed URL $k = $v");
  2147. $this->$k = $v;
  2148. }
  2149. // add any GET params to path
  2150. if(isset($u['query']) && $u['query'] != ''){
  2151. $this->path .= '?' . $u['query'];
  2152. }
  2153. // set default port
  2154. if(!isset($u['port'])){
  2155. if($u['scheme'] == 'https'){
  2156. $this->port = 443;
  2157. } else {
  2158. $this->port = 80;
  2159. }
  2160. }
  2161. $this->uri = $this->path;
  2162. $this->digest_uri = $this->uri;
  2163. // build headers
  2164. if (!isset($u['port'])) {
  2165. $this->setHeader('Host', $this->host);
  2166. } else {
  2167. $this->setHeader('Host', $this->host.':'.$this->port);
  2168. }
  2169. if (isset($u['user']) && $u['user'] != '') {
  2170. $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
  2171. }
  2172. }
  2173. /**
  2174. * gets the I/O method to use
  2175. *
  2176. * @return string I/O method to use (socket|curl|unknown)
  2177. * @access private
  2178. */
  2179. function io_method() {
  2180. if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm'))
  2181. return 'curl';
  2182. if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm'))
  2183. return 'socket';
  2184. return 'unknown';
  2185. }
  2186. /**
  2187. * establish an HTTP connection
  2188. *
  2189. * @param integer $timeout set connection timeout in seconds
  2190. * @param integer $response_timeout set response timeout in seconds
  2191. * @return boolean true if connected, false if not
  2192. * @access private
  2193. */
  2194. function connect($connection_timeout=0,$response_timeout=30){
  2195. // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
  2196. // "regular" socket.
  2197. // TODO: disabled for now because OpenSSL must be *compiled* in (not just
  2198. // loaded), and until PHP5 stream_get_wrappers is not available.
  2199. // if ($this->scheme == 'https') {
  2200. // if (version_compare(phpversion(), '4.3.0') >= 0) {
  2201. // if (extension_loaded('openssl')) {
  2202. // $this->scheme = 'ssl';
  2203. // $this->debug('Using SSL over OpenSSL');
  2204. // }
  2205. // }
  2206. // }
  2207. $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
  2208. if ($this->io_method() == 'socket') {
  2209. if (!is_array($this->proxy)) {
  2210. $host = $this->host;
  2211. $port = $this->port;
  2212. } else {
  2213. $host = $this->proxy['host'];
  2214. $port = $this->proxy['port'];
  2215. }
  2216. // use persistent connection
  2217. if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){
  2218. if (!feof($this->fp)) {
  2219. $this->debug('Re-use persistent connection');
  2220. return true;
  2221. }
  2222. fclose($this->fp);
  2223. $this->debug('Closed persistent connection at EOF');
  2224. }
  2225. // munge host if using OpenSSL
  2226. if ($this->scheme == 'ssl') {
  2227. $host = 'ssl://' . $host;
  2228. }
  2229. $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
  2230. // open socket
  2231. if($connection_timeout > 0){
  2232. $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout);
  2233. } else {
  2234. $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
  2235. }
  2236. // test pointer
  2237. if(!$this->fp) {
  2238. $msg = 'Couldn\'t open socket connection to server ' . $this->url;
  2239. if ($this->errno) {
  2240. $msg .= ', Error ('.$this->errno.'): '.$this->error_str;
  2241. } else {
  2242. $msg .= ' prior to connect(). This is often a problem looking up the host name.';
  2243. }
  2244. $this->debug($msg);
  2245. $this->setError($msg);
  2246. return false;
  2247. }
  2248. // set response timeout
  2249. $this->debug('set response timeout to ' . $response_timeout);
  2250. socket_set_timeout( $this->fp, $response_timeout);
  2251. $this->debug('socket connected');
  2252. return true;
  2253. } else if ($this->io_method() == 'curl') {
  2254. if (!extension_loaded('curl')) {
  2255. // $this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
  2256. $this->setError('The PHP cURL Extension is required for HTTPS or NLTM. You will need to re-build or update your PHP to include cURL or change php.ini to load the PHP cURL extension.');
  2257. return false;
  2258. }
  2259. // Avoid warnings when PHP does not have these options
  2260. if (defined('CURLOPT_CONNECTIONTIMEOUT'))
  2261. $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
  2262. else
  2263. $CURLOPT_CONNECTIONTIMEOUT = 78;
  2264. if (defined('CURLOPT_HTTPAUTH'))
  2265. $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
  2266. else
  2267. $CURLOPT_HTTPAUTH = 107;
  2268. if (defined('CURLOPT_PROXYAUTH'))
  2269. $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
  2270. else
  2271. $CURLOPT_PROXYAUTH = 111;
  2272. if (defined('CURLAUTH_BASIC'))
  2273. $CURLAUTH_BASIC = CURLAUTH_BASIC;
  2274. else
  2275. $CURLAUTH_BASIC = 1;
  2276. if (defined('CURLAUTH_DIGEST'))
  2277. $CURLAUTH_DIGEST = CURLAUTH_DIGEST;
  2278. else
  2279. $CURLAUTH_DIGEST = 2;
  2280. if (defined('CURLAUTH_NTLM'))
  2281. $CURLAUTH_NTLM = CURLAUTH_NTLM;
  2282. else
  2283. $CURLAUTH_NTLM = 8;
  2284. $this->debug('connect using cURL');
  2285. // init CURL
  2286. $this->ch = curl_init();
  2287. // set url
  2288. $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
  2289. // add path
  2290. $hostURL .= $this->path;
  2291. $this->setCurlOption(CURLOPT_URL, $hostURL);
  2292. // follow location headers (re-directs)
  2293. if (ini_get('safe_mode') || ini_get('open_basedir')) {
  2294. $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
  2295. $this->debug('safe_mode = ');
  2296. $this->appendDebug($this->varDump(ini_get('safe_mode')));
  2297. $this->debug('open_basedir = ');
  2298. $this->appendDebug($this->varDump(ini_get('open_basedir')));
  2299. } else {
  2300. $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
  2301. }
  2302. // ask for headers in the response output
  2303. $this->setCurlOption(CURLOPT_HEADER, 1);
  2304. // ask for the response output as the return value
  2305. $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
  2306. // encode
  2307. // We manage this ourselves through headers and encoding
  2308. // if(function_exists('gzuncompress')){
  2309. // $this->setCurlOption(CURLOPT_ENCODING, 'deflate');
  2310. // }
  2311. // persistent connection
  2312. if ($this->persistentConnection) {
  2313. // I believe the following comment is now bogus, having applied to
  2314. // the code when it used CURLOPT_CUSTOMREQUEST to send the request.
  2315. // The way we send data, we cannot use persistent connections, since
  2316. // there will be some "junk" at the end of our request.
  2317. //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
  2318. $this->persistentConnection = false;
  2319. $this->setHeader('Connection', 'close');
  2320. }
  2321. // set timeouts
  2322. if ($connection_timeout != 0) {
  2323. $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
  2324. }
  2325. if ($response_timeout != 0) {
  2326. $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
  2327. }
  2328. if ($this->scheme == 'https') {
  2329. $this->debug('set cURL SSL verify options');
  2330. // recent versions of cURL turn on peer/host checking by default,
  2331. // while PHP binaries are not compiled with a default location for the
  2332. // CA cert bundle, so disable peer/host checking.
  2333. //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
  2334. $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
  2335. $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
  2336. // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
  2337. if ($this->authtype == 'certificate') {
  2338. $this->debug('set cURL certificate options');
  2339. if (isset($this->certRequest['cainfofile'])) {
  2340. $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
  2341. }
  2342. if (isset($this->certRequest['verifypeer'])) {
  2343. $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
  2344. } else {
  2345. $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
  2346. }
  2347. if (isset($this->certRequest['verifyhost'])) {
  2348. $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
  2349. } else {
  2350. $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
  2351. }
  2352. if (isset($this->certRequest['sslcertfile'])) {
  2353. $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
  2354. }
  2355. if (isset($this->certRequest['sslkeyfile'])) {
  2356. $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
  2357. }
  2358. if (isset($this->certRequest['passphrase'])) {
  2359. $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
  2360. }
  2361. if (isset($this->certRequest['certpassword'])) {
  2362. $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
  2363. }
  2364. }
  2365. }
  2366. if ($this->authtype && ($this->authtype != 'certificate')) {
  2367. if ($this->username) {
  2368. $this->debug('set cURL username/password');
  2369. $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
  2370. }
  2371. if ($this->authtype == 'basic') {
  2372. $this->debug('set cURL for Basic authentication');
  2373. $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
  2374. }
  2375. if ($this->authtype == 'digest') {
  2376. $this->debug('set cURL for digest authentication');
  2377. $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
  2378. }
  2379. if ($this->authtype == 'ntlm') {
  2380. $this->debug('set cURL for NTLM authentication');
  2381. $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
  2382. }
  2383. }
  2384. if (is_array($this->proxy)) {
  2385. $this->debug('set cURL proxy options');
  2386. if ($this->proxy['port'] != '') {
  2387. $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']);
  2388. } else {
  2389. $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
  2390. }
  2391. if ($this->proxy['username'] || $this->proxy['password']) {
  2392. $this->debug('set cURL proxy authentication options');
  2393. $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']);
  2394. if ($this->proxy['authtype'] == 'basic') {
  2395. $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
  2396. }
  2397. if ($this->proxy['authtype'] == 'ntlm') {
  2398. $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
  2399. }
  2400. }
  2401. }
  2402. $this->debug('cURL connection set up');
  2403. return true;
  2404. } else {
  2405. $this->setError('Unknown scheme ' . $this->scheme);
  2406. $this->debug('Unknown scheme ' . $this->scheme);
  2407. return false;
  2408. }
  2409. }
  2410. /**
  2411. * sends the SOAP request and gets the SOAP response via HTTP[S]
  2412. *
  2413. * @param string $data message data
  2414. * @param integer $timeout set connection timeout in seconds
  2415. * @param integer $response_timeout set response timeout in seconds
  2416. * @param array $cookies cookies to send
  2417. * @return string data
  2418. * @access public
  2419. */
  2420. function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) {
  2421. $this->debug('entered send() with data of length: '.strlen($data));
  2422. $this->tryagain = true;
  2423. $tries = 0;
  2424. while ($this->tryagain) {
  2425. $this->tryagain = false;
  2426. if ($tries++ < 2) {
  2427. // make connnection
  2428. if (!$this->connect($timeout, $response_timeout)){
  2429. return false;
  2430. }
  2431. // send request
  2432. if (!$this->sendRequest($data, $cookies)){
  2433. return false;
  2434. }
  2435. // get response
  2436. $respdata = $this->getResponse();
  2437. } else {
  2438. $this->setError("Too many tries to get an OK response ($this->response_status_line)");
  2439. }
  2440. }
  2441. $this->debug('end of send()');
  2442. return $respdata;
  2443. }
  2444. /**
  2445. * sends the SOAP request and gets the SOAP response via HTTPS using CURL
  2446. *
  2447. * @param string $data message data
  2448. * @param integer $timeout set connection timeout in seconds
  2449. * @param integer $response_timeout set response timeout in seconds
  2450. * @param array $cookies cookies to send
  2451. * @return string data
  2452. * @access public
  2453. * @deprecated
  2454. */
  2455. function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) {
  2456. return $this->send($data, $timeout, $response_timeout, $cookies);
  2457. }
  2458. /**
  2459. * if authenticating, set user credentials here
  2460. *
  2461. * @param string $username
  2462. * @param string $password
  2463. * @param string $authtype (basic|digest|certificate|ntlm)
  2464. * @param array $digestRequest (keys must be nonce, nc, realm, qop)
  2465. * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
  2466. * @access public
  2467. */
  2468. function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) {
  2469. $this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
  2470. $this->appendDebug($this->varDump($digestRequest));
  2471. $this->debug("certRequest=");
  2472. $this->appendDebug($this->varDump($certRequest));
  2473. // cf. RFC 2617
  2474. if ($authtype == 'basic') {
  2475. $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password));
  2476. } elseif ($authtype == 'digest') {
  2477. if (isset($digestRequest['nonce'])) {
  2478. $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
  2479. // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
  2480. // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
  2481. $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
  2482. // H(A1) = MD5(A1)
  2483. $HA1 = md5($A1);
  2484. // A2 = Method ":" digest-uri-value
  2485. $A2 = $this->request_method . ':' . $this->digest_uri;
  2486. // H(A2)
  2487. $HA2 = md5($A2);
  2488. // KD(secret, data) = H(concat(secret, ":", data))
  2489. // if qop == auth:
  2490. // request-digest = <"> < KD ( H(A1), unq(nonce-value)
  2491. // ":" nc-value
  2492. // ":" unq(cnonce-value)
  2493. // ":" unq(qop-value)
  2494. // ":" H(A2)
  2495. // ) <">
  2496. // if qop is missing,
  2497. // request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
  2498. $unhashedDigest = '';
  2499. $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
  2500. $cnonce = $nonce;
  2501. if ($digestRequest['qop'] != '') {
  2502. $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
  2503. } else {
  2504. $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
  2505. }
  2506. $hashedDigest = md5($unhashedDigest);
  2507. $opaque = '';
  2508. if (isset($digestRequest['opaque'])) {
  2509. $opaque = ', opaque="' . $digestRequest['opaque'] . '"';
  2510. }
  2511. $this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
  2512. }
  2513. } elseif ($authtype == 'certificate') {
  2514. $this->certRequest = $certRequest;
  2515. $this->debug('Authorization header not set for certificate');
  2516. } elseif ($authtype == 'ntlm') {
  2517. // do nothing
  2518. $this->debug('Authorization header not set for ntlm');
  2519. }
  2520. $this->username = $username;
  2521. $this->password = $password;
  2522. $this->authtype = $authtype;
  2523. $this->digestRequest = $digestRequest;
  2524. }
  2525. /**
  2526. * set the soapaction value
  2527. *
  2528. * @param string $soapaction
  2529. * @access public
  2530. */
  2531. function setSOAPAction($soapaction) {
  2532. $this->setHeader('SOAPAction', '"' . $soapaction . '"');
  2533. }
  2534. /**
  2535. * use http encoding
  2536. *
  2537. * @param string $enc encoding style. supported values: gzip, deflate, or both
  2538. * @access public
  2539. */
  2540. function setEncoding($enc='gzip, deflate') {
  2541. if (function_exists('gzdeflate')) {
  2542. $this->protocol_version = '1.1';
  2543. $this->setHeader('Accept-Encoding', $enc);
  2544. if (!isset($this->outgoing_headers['Connection'])) {
  2545. $this->setHeader('Connection', 'close');
  2546. $this->persistentConnection = false;
  2547. }
  2548. // deprecated as of PHP 5.3.0
  2549. //set_magic_quotes_runtime(0);
  2550. $this->encoding = $enc;
  2551. }
  2552. }
  2553. /**
  2554. * set proxy info here
  2555. *
  2556. * @param string $proxyhost use an empty string to remove proxy
  2557. * @param string $proxyport
  2558. * @param string $proxyusername
  2559. * @param string $proxypassword
  2560. * @param string $proxyauthtype (basic|ntlm)
  2561. * @access public
  2562. */
  2563. function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') {
  2564. if ($proxyhost) {
  2565. $this->proxy = array(
  2566. 'host' => $proxyhost,
  2567. 'port' => $proxyport,
  2568. 'username' => $proxyusername,
  2569. 'password' => $proxypassword,
  2570. 'authtype' => $proxyauthtype
  2571. );
  2572. if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') {
  2573. $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword));
  2574. }
  2575. } else {
  2576. $this->debug('remove proxy');
  2577. $proxy = null;
  2578. unsetHeader('Proxy-Authorization');
  2579. }
  2580. }
  2581. /**
  2582. * Test if the given string starts with a header that is to be skipped.
  2583. * Skippable headers result from chunked transfer and proxy requests.
  2584. *
  2585. * @param string $data The string to check.
  2586. * @returns boolean Whether a skippable header was found.
  2587. * @access private
  2588. */
  2589. function isSkippableCurlHeader(&$data) {
  2590. $skipHeaders = array( 'HTTP/1.1 100',
  2591. 'HTTP/1.0 301',
  2592. 'HTTP/1.1 301',
  2593. 'HTTP/1.0 302',
  2594. 'HTTP/1.1 302',
  2595. 'HTTP/1.0 401',
  2596. 'HTTP/1.1 401',
  2597. 'HTTP/1.0 200 Connection established');
  2598. foreach ($skipHeaders as $hd) {
  2599. $prefix = substr($data, 0, strlen($hd));
  2600. if ($prefix == $hd) return true;
  2601. }
  2602. return false;
  2603. }
  2604. /**
  2605. * decode a string that is encoded w/ "chunked' transfer encoding
  2606. * as defined in RFC2068 19.4.6
  2607. *
  2608. * @param string $buffer
  2609. * @param string $lb
  2610. * @returns string
  2611. * @access public
  2612. * @deprecated
  2613. */
  2614. function decodeChunked($buffer, $lb){
  2615. // length := 0
  2616. $length = 0;
  2617. $new = '';
  2618. // read chunk-size, chunk-extension (if any) and CRLF
  2619. // get the position of the linebreak
  2620. $chunkend = strpos($buffer, $lb);
  2621. if ($chunkend == FALSE) {
  2622. $this->debug('no linebreak found in decodeChunked');
  2623. return $new;
  2624. }
  2625. $temp = substr($buffer,0,$chunkend);
  2626. $chunk_size = hexdec( trim($temp) );
  2627. $chunkstart = $chunkend + strlen($lb);
  2628. // while (chunk-size > 0) {
  2629. while ($chunk_size > 0) {
  2630. $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
  2631. $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size);
  2632. // Just in case we got a broken connection
  2633. if ($chunkend == FALSE) {
  2634. $chunk = substr($buffer,$chunkstart);
  2635. // append chunk-data to entity-body
  2636. $new .= $chunk;
  2637. $length += strlen($chunk);
  2638. break;
  2639. }
  2640. // read chunk-data and CRLF
  2641. $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
  2642. // append chunk-data to entity-body
  2643. $new .= $chunk;
  2644. // length := length + chunk-size
  2645. $length += strlen($chunk);
  2646. // read chunk-size and CRLF
  2647. $chunkstart = $chunkend + strlen($lb);
  2648. $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
  2649. if ($chunkend == FALSE) {
  2650. break; //Just in case we got a broken connection
  2651. }
  2652. $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
  2653. $chunk_size = hexdec( trim($temp) );
  2654. $chunkstart = $chunkend;
  2655. }
  2656. return $new;
  2657. }
  2658. /**
  2659. * Writes the payload, including HTTP headers, to $this->outgoing_payload.
  2660. *
  2661. * @param string $data HTTP body
  2662. * @param string $cookie_str data for HTTP Cookie header
  2663. * @return void
  2664. * @access private
  2665. */
  2666. function buildPayload($data, $cookie_str = '') {
  2667. // Note: for cURL connections, $this->outgoing_payload is ignored,
  2668. // as is the Content-Length header, but these are still created as
  2669. // debugging guides.
  2670. // add content-length header
  2671. if ($this->request_method != 'GET') {
  2672. $this->setHeader('Content-Length', strlen($data));
  2673. }
  2674. // start building outgoing payload:
  2675. if ($this->proxy) {
  2676. $uri = $this->url;
  2677. } else {
  2678. $uri = $this->uri;
  2679. }
  2680. $req = "$this->request_method $uri HTTP/$this->protocol_version";
  2681. $this->debug("HTTP request: $req");
  2682. $this->outgoing_payload = "$req\r\n";
  2683. // loop thru headers, serializing
  2684. foreach($this->outgoing_headers as $k => $v){
  2685. $hdr = $k.': '.$v;
  2686. $this->debug("HTTP header: $hdr");
  2687. $this->outgoing_payload .= "$hdr\r\n";
  2688. }
  2689. // add any cookies
  2690. if ($cookie_str != '') {
  2691. $hdr = 'Cookie: '.$cookie_str;
  2692. $this->debug("HTTP header: $hdr");
  2693. $this->outgoing_payload .= "$hdr\r\n";
  2694. }
  2695. // header/body separator
  2696. $this->outgoing_payload .= "\r\n";
  2697. // add data
  2698. $this->outgoing_payload .= $data;
  2699. }
  2700. /**
  2701. * sends the SOAP request via HTTP[S]
  2702. *
  2703. * @param string $data message data
  2704. * @param array $cookies cookies to send
  2705. * @return boolean true if OK, false if problem
  2706. * @access private
  2707. */
  2708. function sendRequest($data, $cookies = NULL) {
  2709. // build cookie string
  2710. $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
  2711. // build payload
  2712. $this->buildPayload($data, $cookie_str);
  2713. if ($this->io_method() == 'socket') {
  2714. // send payload
  2715. if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
  2716. $this->setError('couldn\'t write message data to socket');
  2717. $this->debug('couldn\'t write message data to socket');
  2718. return false;
  2719. }
  2720. $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
  2721. return true;
  2722. } else if ($this->io_method() == 'curl') {
  2723. // set payload
  2724. // cURL does say this should only be the verb, and in fact it
  2725. // turns out that the URI and HTTP version are appended to this, which
  2726. // some servers refuse to work with (so we no longer use this method!)
  2727. //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
  2728. $curl_headers = array();
  2729. foreach($this->outgoing_headers as $k => $v){
  2730. if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
  2731. $this->debug("Skip cURL header $k: $v");
  2732. } else {
  2733. $curl_headers[] = "$k: $v";
  2734. }
  2735. }
  2736. if ($cookie_str != '') {
  2737. $curl_headers[] = 'Cookie: ' . $cookie_str;
  2738. }
  2739. $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
  2740. $this->debug('set cURL HTTP headers');
  2741. if ($this->request_method == "POST") {
  2742. $this->setCurlOption(CURLOPT_POST, 1);
  2743. $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
  2744. $this->debug('set cURL POST data');
  2745. } else {
  2746. }
  2747. // insert custom user-set cURL options
  2748. foreach ($this->ch_options as $key => $val) {
  2749. $this->setCurlOption($key, $val);
  2750. }
  2751. $this->debug('set cURL payload');
  2752. return true;
  2753. }
  2754. }
  2755. /**
  2756. * gets the SOAP response via HTTP[S]
  2757. *
  2758. * @return string the response (also sets member variables like incoming_payload)
  2759. * @access private
  2760. */
  2761. function getResponse(){
  2762. $this->incoming_payload = '';
  2763. if ($this->io_method() == 'socket') {
  2764. // loop until headers have been retrieved
  2765. $data = '';
  2766. while (!isset($lb)){
  2767. // We might EOF during header read.
  2768. if(feof($this->fp)) {
  2769. $this->incoming_payload = $data;
  2770. $this->debug('found no headers before EOF after length ' . strlen($data));
  2771. $this->debug("received before EOF:\n" . $data);
  2772. $this->setError('server failed to send headers');
  2773. return false;
  2774. }
  2775. $tmp = fgets($this->fp, 256);
  2776. $tmplen = strlen($tmp);
  2777. $this->debug("read line of $tmplen bytes: " . trim($tmp));
  2778. if ($tmplen == 0) {
  2779. $this->incoming_payload = $data;
  2780. $this->debug('socket read of headers timed out after length ' . strlen($data));
  2781. $this->debug("read before timeout: " . $data);
  2782. $this->setError('socket read of headers timed out');
  2783. return false;
  2784. }
  2785. $data .= $tmp;
  2786. $pos = strpos($data,"\r\n\r\n");
  2787. if($pos > 1){
  2788. $lb = "\r\n";
  2789. } else {
  2790. $pos = strpos($data,"\n\n");
  2791. if($pos > 1){
  2792. $lb = "\n";
  2793. }
  2794. }
  2795. // remove 100 headers
  2796. if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) {
  2797. unset($lb);
  2798. $data = '';
  2799. }//
  2800. }
  2801. // store header data
  2802. $this->incoming_payload .= $data;
  2803. $this->debug('found end of headers after length ' . strlen($data));
  2804. // process headers
  2805. $header_data = trim(substr($data,0,$pos));
  2806. $header_array = explode($lb,$header_data);
  2807. $this->incoming_headers = array();
  2808. $this->incoming_cookies = array();
  2809. foreach($header_array as $header_line){
  2810. $arr = explode(':',$header_line, 2);
  2811. if(count($arr) > 1){
  2812. $header_name = strtolower(trim($arr[0]));
  2813. $this->incoming_headers[$header_name] = trim($arr[1]);
  2814. if ($header_name == 'set-cookie') {
  2815. // TODO: allow multiple cookies from parseCookie
  2816. $cookie = $this->parseCookie(trim($arr[1]));
  2817. if ($cookie) {
  2818. $this->incoming_cookies[] = $cookie;
  2819. $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
  2820. } else {
  2821. $this->debug('did not find cookie in ' . trim($arr[1]));
  2822. }
  2823. }
  2824. } else if (isset($header_name)) {
  2825. // append continuation line to previous header
  2826. $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
  2827. }
  2828. }
  2829. // loop until msg has been received
  2830. if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
  2831. $content_length = 2147483647; // ignore any content-length header
  2832. $chunked = true;
  2833. $this->debug("want to read chunked content");
  2834. } elseif (isset($this->incoming_headers['content-length'])) {
  2835. $content_length = $this->incoming_headers['content-length'];
  2836. $chunked = false;
  2837. $this->debug("want to read content of length $content_length");
  2838. } else {
  2839. $content_length = 2147483647;
  2840. $chunked = false;
  2841. $this->debug("want to read content to EOF");
  2842. }
  2843. $data = '';
  2844. do {
  2845. if ($chunked) {
  2846. $tmp = fgets($this->fp, 256);
  2847. $tmplen = strlen($tmp);
  2848. $this->debug("read chunk line of $tmplen bytes");
  2849. if ($tmplen == 0) {
  2850. $this->incoming_payload = $data;
  2851. $this->debug('socket read of chunk length timed out after length ' . strlen($data));
  2852. $this->debug("read before timeout:\n" . $data);
  2853. $this->setError('socket read of chunk length timed out');
  2854. return false;
  2855. }
  2856. $content_length = hexdec(trim($tmp));
  2857. $this->debug("chunk length $content_length");
  2858. }
  2859. $strlen = 0;
  2860. while (($strlen < $content_length) && (!feof($this->fp))) {
  2861. $readlen = min(8192, $content_length - $strlen);
  2862. $tmp = fread($this->fp, $readlen);
  2863. $tmplen = strlen($tmp);
  2864. $this->debug("read buffer of $tmplen bytes");
  2865. if (($tmplen == 0) && (!feof($this->fp))) {
  2866. $this->incoming_payload = $data;
  2867. $this->debug('socket read of body timed out after length ' . strlen($data));
  2868. $this->debug("read before timeout:\n" . $data);
  2869. $this->setError('socket read of body timed out');
  2870. return false;
  2871. }
  2872. $strlen += $tmplen;
  2873. $data .= $tmp;
  2874. }
  2875. if ($chunked && ($content_length > 0)) {
  2876. $tmp = fgets($this->fp, 256);
  2877. $tmplen = strlen($tmp);
  2878. $this->debug("read chunk terminator of $tmplen bytes");
  2879. if ($tmplen == 0) {
  2880. $this->incoming_payload = $data;
  2881. $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
  2882. $this->debug("read before timeout:\n" . $data);
  2883. $this->setError('socket read of chunk terminator timed out');
  2884. return false;
  2885. }
  2886. }
  2887. } while ($chunked && ($content_length > 0) && (!feof($this->fp)));
  2888. if (feof($this->fp)) {
  2889. $this->debug('read to EOF');
  2890. }
  2891. $this->debug('read body of length ' . strlen($data));
  2892. $this->incoming_payload .= $data;
  2893. $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server');
  2894. // close filepointer
  2895. if(
  2896. (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
  2897. (! $this->persistentConnection) || feof($this->fp)){
  2898. fclose($this->fp);
  2899. $this->fp = false;
  2900. $this->debug('closed socket');
  2901. }
  2902. // connection was closed unexpectedly
  2903. if($this->incoming_payload == ''){
  2904. $this->setError('no response from server');
  2905. return false;
  2906. }
  2907. // decode transfer-encoding
  2908. // if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
  2909. // if(!$data = $this->decodeChunked($data, $lb)){
  2910. // $this->setError('Decoding of chunked data failed');
  2911. // return false;
  2912. // }
  2913. //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
  2914. // set decoded payload
  2915. // $this->incoming_payload = $header_data.$lb.$lb.$data;
  2916. // }
  2917. } else if ($this->io_method() == 'curl') {
  2918. // send and receive
  2919. $this->debug('send and receive with cURL');
  2920. $this->incoming_payload = curl_exec($this->ch);
  2921. $data = $this->incoming_payload;
  2922. $cErr = curl_error($this->ch);
  2923. if ($cErr != '') {
  2924. $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>';
  2925. // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
  2926. foreach(curl_getinfo($this->ch) as $k => $v){
  2927. $err .= "$k: $v<br>";
  2928. }
  2929. $this->debug($err);
  2930. $this->setError($err);
  2931. curl_close($this->ch);
  2932. return false;
  2933. } else {
  2934. //echo '<pre>';
  2935. //var_dump(curl_getinfo($this->ch));
  2936. //echo '</pre>';
  2937. }
  2938. // close curl
  2939. $this->debug('No cURL error, closing cURL');
  2940. curl_close($this->ch);
  2941. // try removing skippable headers
  2942. $savedata = $data;
  2943. while ($this->isSkippableCurlHeader($data)) {
  2944. $this->debug("Found HTTP header to skip");
  2945. if ($pos = strpos($data,"\r\n\r\n")) {
  2946. $data = ltrim(substr($data,$pos));
  2947. } elseif($pos = strpos($data,"\n\n") ) {
  2948. $data = ltrim(substr($data,$pos));
  2949. }
  2950. }
  2951. if ($data == '') {
  2952. // have nothing left; just remove 100 header(s)
  2953. $data = $savedata;
  2954. while (preg_match('/^HTTP\/1.1 100/',$data)) {
  2955. if ($pos = strpos($data,"\r\n\r\n")) {
  2956. $data = ltrim(substr($data,$pos));
  2957. } elseif($pos = strpos($data,"\n\n") ) {
  2958. $data = ltrim(substr($data,$pos));
  2959. }
  2960. }
  2961. }
  2962. // separate content from HTTP headers
  2963. if ($pos = strpos($data,"\r\n\r\n")) {
  2964. $lb = "\r\n";
  2965. } elseif( $pos = strpos($data,"\n\n")) {
  2966. $lb = "\n";
  2967. } else {
  2968. $this->debug('no proper separation of headers and document');
  2969. $this->setError('no proper separation of headers and document');
  2970. return false;
  2971. }
  2972. $header_data = trim(substr($data,0,$pos));
  2973. $header_array = explode($lb,$header_data);
  2974. $data = ltrim(substr($data,$pos));
  2975. $this->debug('found proper separation of headers and document');
  2976. $this->debug('cleaned data, stringlen: '.strlen($data));
  2977. // clean headers
  2978. foreach ($header_array as $header_line) {
  2979. $arr = explode(':',$header_line,2);
  2980. if(count($arr) > 1){
  2981. $header_name = strtolower(trim($arr[0]));
  2982. $this->incoming_headers[$header_name] = trim($arr[1]);
  2983. if ($header_name == 'set-cookie') {
  2984. // TODO: allow multiple cookies from parseCookie
  2985. $cookie = $this->parseCookie(trim($arr[1]));
  2986. if ($cookie) {
  2987. $this->incoming_cookies[] = $cookie;
  2988. $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
  2989. } else {
  2990. $this->debug('did not find cookie in ' . trim($arr[1]));
  2991. }
  2992. }
  2993. } else if (isset($header_name)) {
  2994. // append continuation line to previous header
  2995. $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
  2996. }
  2997. }
  2998. }
  2999. $this->response_status_line = $header_array[0];
  3000. $arr = explode(' ', $this->response_status_line, 3);
  3001. $http_version = $arr[0];
  3002. $http_status = intval($arr[1]);
  3003. $http_reason = count($arr) > 2 ? $arr[2] : '';
  3004. // see if we need to resend the request with http digest authentication
  3005. if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
  3006. $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
  3007. $this->setURL($this->incoming_headers['location']);
  3008. $this->tryagain = true;
  3009. return false;
  3010. }
  3011. // see if we need to resend the request with http digest authentication
  3012. if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
  3013. $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
  3014. if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
  3015. $this->debug('Server wants digest authentication');
  3016. // remove "Digest " from our elements
  3017. $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
  3018. // parse elements into array
  3019. $digestElements = explode(',', $digestString);
  3020. foreach ($digestElements as $val) {
  3021. $tempElement = explode('=', trim($val), 2);
  3022. $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
  3023. }
  3024. // should have (at least) qop, realm, nonce
  3025. if (isset($digestRequest['nonce'])) {
  3026. $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
  3027. $this->tryagain = true;
  3028. return false;
  3029. }
  3030. }
  3031. $this->debug('HTTP authentication failed');
  3032. $this->setError('HTTP authentication failed');
  3033. return false;
  3034. }
  3035. if (
  3036. ($http_status >= 300 && $http_status <= 307) ||
  3037. ($http_status >= 400 && $http_status <= 417) ||
  3038. ($http_status >= 501 && $http_status <= 505)
  3039. ) {
  3040. $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
  3041. return false;
  3042. }
  3043. // decode content-encoding
  3044. if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){
  3045. if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){
  3046. // if decoding works, use it. else assume data wasn't gzencoded
  3047. if(function_exists('gzinflate')){
  3048. //$timer->setMarker('starting decoding of gzip/deflated content');
  3049. // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
  3050. // this means there are no Zlib headers, although there should be
  3051. $this->debug('The gzinflate function exists');
  3052. $datalen = strlen($data);
  3053. if ($this->incoming_headers['content-encoding'] == 'deflate') {
  3054. if ($degzdata = @gzinflate($data)) {
  3055. $data = $degzdata;
  3056. $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
  3057. if (strlen($data) < $datalen) {
  3058. // test for the case that the payload has been compressed twice
  3059. $this->debug('The inflated payload is smaller than the gzipped one; try again');
  3060. if ($degzdata = @gzinflate($data)) {
  3061. $data = $degzdata;
  3062. $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
  3063. }
  3064. }
  3065. } else {
  3066. $this->debug('Error using gzinflate to inflate the payload');
  3067. $this->setError('Error using gzinflate to inflate the payload');
  3068. }
  3069. } elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
  3070. if ($degzdata = @gzinflate(substr($data, 10))) { // do our best
  3071. $data = $degzdata;
  3072. $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
  3073. if (strlen($data) < $datalen) {
  3074. // test for the case that the payload has been compressed twice
  3075. $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
  3076. if ($degzdata = @gzinflate(substr($data, 10))) {
  3077. $data = $degzdata;
  3078. $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
  3079. }
  3080. }
  3081. } else {
  3082. $this->debug('Error using gzinflate to un-gzip the payload');
  3083. $this->setError('Error using gzinflate to un-gzip the payload');
  3084. }
  3085. }
  3086. //$timer->setMarker('finished decoding of gzip/deflated content');
  3087. //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
  3088. // set decoded payload
  3089. $this->incoming_payload = $header_data.$lb.$lb.$data;
  3090. } else {
  3091. $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
  3092. $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
  3093. }
  3094. } else {
  3095. $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
  3096. $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
  3097. }
  3098. } else {
  3099. $this->debug('No Content-Encoding header');
  3100. }
  3101. if(strlen($data) == 0){
  3102. $this->debug('no data after headers!');
  3103. $this->setError('no data present after HTTP headers');
  3104. return false;
  3105. }
  3106. return $data;
  3107. }
  3108. /**
  3109. * sets the content-type for the SOAP message to be sent
  3110. *
  3111. * @param string $type the content type, MIME style
  3112. * @param mixed $charset character set used for encoding (or false)
  3113. * @access public
  3114. */
  3115. function setContentType($type, $charset = false) {
  3116. $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
  3117. }
  3118. /**
  3119. * specifies that an HTTP persistent connection should be used
  3120. *
  3121. * @return boolean whether the request was honored by this method.
  3122. * @access public
  3123. */
  3124. function usePersistentConnection(){
  3125. if (isset($this->outgoing_headers['Accept-Encoding'])) {
  3126. return false;
  3127. }
  3128. $this->protocol_version = '1.1';
  3129. $this->persistentConnection = true;
  3130. $this->setHeader('Connection', 'Keep-Alive');
  3131. return true;
  3132. }
  3133. /**
  3134. * parse an incoming Cookie into it's parts
  3135. *
  3136. * @param string $cookie_str content of cookie
  3137. * @return array with data of that cookie
  3138. * @access private
  3139. */
  3140. /*
  3141. * TODO: allow a Set-Cookie string to be parsed into multiple cookies
  3142. */
  3143. function parseCookie($cookie_str) {
  3144. $cookie_str = str_replace('; ', ';', $cookie_str) . ';';
  3145. $data = preg_split('/;/', $cookie_str);
  3146. $value_str = $data[0];
  3147. $cookie_param = 'domain=';
  3148. $start = strpos($cookie_str, $cookie_param);
  3149. if ($start > 0) {
  3150. $domain = substr($cookie_str, $start + strlen($cookie_param));
  3151. $domain = substr($domain, 0, strpos($domain, ';'));
  3152. } else {
  3153. $domain = '';
  3154. }
  3155. $cookie_param = 'expires=';
  3156. $start = strpos($cookie_str, $cookie_param);
  3157. if ($start > 0) {
  3158. $expires = substr($cookie_str, $start + strlen($cookie_param));
  3159. $expires = substr($expires, 0, strpos($expires, ';'));
  3160. } else {
  3161. $expires = '';
  3162. }
  3163. $cookie_param = 'path=';
  3164. $start = strpos($cookie_str, $cookie_param);
  3165. if ( $start > 0 ) {
  3166. $path = substr($cookie_str, $start + strlen($cookie_param));
  3167. $path = substr($path, 0, strpos($path, ';'));
  3168. } else {
  3169. $path = '/';
  3170. }
  3171. $cookie_param = ';secure;';
  3172. if (strpos($cookie_str, $cookie_param) !== FALSE) {
  3173. $secure = true;
  3174. } else {
  3175. $secure = false;
  3176. }
  3177. $sep_pos = strpos($value_str, '=');
  3178. if ($sep_pos) {
  3179. $name = substr($value_str, 0, $sep_pos);
  3180. $value = substr($value_str, $sep_pos + 1);
  3181. $cookie= array( 'name' => $name,
  3182. 'value' => $value,
  3183. 'domain' => $domain,
  3184. 'path' => $path,
  3185. 'expires' => $expires,
  3186. 'secure' => $secure
  3187. );
  3188. return $cookie;
  3189. }
  3190. return false;
  3191. }
  3192. /**
  3193. * sort out cookies for the current request
  3194. *
  3195. * @param array $cookies array with all cookies
  3196. * @param boolean $secure is the send-content secure or not?
  3197. * @return string for Cookie-HTTP-Header
  3198. * @access private
  3199. */
  3200. function getCookiesForRequest($cookies, $secure=false) {
  3201. $cookie_str = '';
  3202. if ((! is_null($cookies)) && (is_array($cookies))) {
  3203. foreach ($cookies as $cookie) {
  3204. if (! is_array($cookie)) {
  3205. continue;
  3206. }
  3207. $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']);
  3208. if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
  3209. if (strtotime($cookie['expires']) <= time()) {
  3210. $this->debug('cookie has expired');
  3211. continue;
  3212. }
  3213. }
  3214. if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) {
  3215. $domain = preg_quote($cookie['domain']);
  3216. if (! preg_match("'.*$domain$'i", $this->host)) {
  3217. $this->debug('cookie has different domain');
  3218. continue;
  3219. }
  3220. }
  3221. if ((isset($cookie['path'])) && (! empty($cookie['path']))) {
  3222. $path = preg_quote($cookie['path']);
  3223. if (! preg_match("'^$path.*'i", $this->path)) {
  3224. $this->debug('cookie is for a different path');
  3225. continue;
  3226. }
  3227. }
  3228. if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
  3229. $this->debug('cookie is secure, transport is not');
  3230. continue;
  3231. }
  3232. $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
  3233. $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
  3234. }
  3235. }
  3236. return $cookie_str;
  3237. }
  3238. }
  3239. ?><?php
  3240. /**
  3241. *
  3242. * nusoap_server allows the user to create a SOAP server
  3243. * that is capable of receiving messages and returning responses
  3244. *
  3245. * @author Dietrich Ayala <dietrich@ganx4.com>
  3246. * @author Scott Nichol <snichol@users.sourceforge.net>
  3247. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  3248. * @access public
  3249. */
  3250. class nusoap_server extends nusoap_base {
  3251. /**
  3252. * HTTP headers of request
  3253. * @var array
  3254. * @access private
  3255. */
  3256. var $headers = array();
  3257. /**
  3258. * HTTP request
  3259. * @var string
  3260. * @access private
  3261. */
  3262. var $request = '';
  3263. /**
  3264. * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
  3265. * @var string
  3266. * @access public
  3267. */
  3268. var $requestHeaders = '';
  3269. /**
  3270. * SOAP Headers from request (parsed)
  3271. * @var mixed
  3272. * @access public
  3273. */
  3274. var $requestHeader = NULL;
  3275. /**
  3276. * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
  3277. * @var string
  3278. * @access public
  3279. */
  3280. var $document = '';
  3281. /**
  3282. * SOAP payload for request (text)
  3283. * @var string
  3284. * @access public
  3285. */
  3286. var $requestSOAP = '';
  3287. /**
  3288. * requested method namespace URI
  3289. * @var string
  3290. * @access private
  3291. */
  3292. var $methodURI = '';
  3293. /**
  3294. * name of method requested
  3295. * @var string
  3296. * @access private
  3297. */
  3298. var $methodname = '';
  3299. /**
  3300. * method parameters from request
  3301. * @var array
  3302. * @access private
  3303. */
  3304. var $methodparams = array();
  3305. /**
  3306. * SOAP Action from request
  3307. * @var string
  3308. * @access private
  3309. */
  3310. var $SOAPAction = '';
  3311. /**
  3312. * character set encoding of incoming (request) messages
  3313. * @var string
  3314. * @access public
  3315. */
  3316. var $xml_encoding = '';
  3317. /**
  3318. * toggles whether the parser decodes element content w/ utf8_decode()
  3319. * @var boolean
  3320. * @access public
  3321. */
  3322. var $decode_utf8 = true;
  3323. /**
  3324. * HTTP headers of response
  3325. * @var array
  3326. * @access public
  3327. */
  3328. var $outgoing_headers = array();
  3329. /**
  3330. * HTTP response
  3331. * @var string
  3332. * @access private
  3333. */
  3334. var $response = '';
  3335. /**
  3336. * SOAP headers for response (text or array of soapval or associative array)
  3337. * @var mixed
  3338. * @access public
  3339. */
  3340. var $responseHeaders = '';
  3341. /**
  3342. * SOAP payload for response (text)
  3343. * @var string
  3344. * @access private
  3345. */
  3346. var $responseSOAP = '';
  3347. /**
  3348. * method return value to place in response
  3349. * @var mixed
  3350. * @access private
  3351. */
  3352. var $methodreturn = false;
  3353. /**
  3354. * whether $methodreturn is a string of literal XML
  3355. * @var boolean
  3356. * @access public
  3357. */
  3358. var $methodreturnisliteralxml = false;
  3359. /**
  3360. * SOAP fault for response (or false)
  3361. * @var mixed
  3362. * @access private
  3363. */
  3364. var $fault = false;
  3365. /**
  3366. * text indication of result (for debugging)
  3367. * @var string
  3368. * @access private
  3369. */
  3370. var $result = 'successful';
  3371. /**
  3372. * assoc array of operations => opData; operations are added by the register()
  3373. * method or by parsing an external WSDL definition
  3374. * @var array
  3375. * @access private
  3376. */
  3377. var $operations = array();
  3378. /**
  3379. * wsdl instance (if one)
  3380. * @var mixed
  3381. * @access private
  3382. */
  3383. var $wsdl = false;
  3384. /**
  3385. * URL for WSDL (if one)
  3386. * @var mixed
  3387. * @access private
  3388. */
  3389. var $externalWSDLURL = false;
  3390. /**
  3391. * whether to append debug to response as XML comment
  3392. * @var boolean
  3393. * @access public
  3394. */
  3395. var $debug_flag = false;
  3396. /**
  3397. * constructor
  3398. * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
  3399. *
  3400. * @param mixed $wsdl file path or URL (string), or wsdl instance (object)
  3401. * @access public
  3402. */
  3403. function nusoap_server($wsdl=false){
  3404. parent::nusoap_base();
  3405. // turn on debugging?
  3406. global $debug;
  3407. global $HTTP_SERVER_VARS;
  3408. if (isset($_SERVER)) {
  3409. $this->debug("_SERVER is defined:");
  3410. $this->appendDebug($this->varDump($_SERVER));
  3411. } elseif (isset($HTTP_SERVER_VARS)) {
  3412. $this->debug("HTTP_SERVER_VARS is defined:");
  3413. $this->appendDebug($this->varDump($HTTP_SERVER_VARS));
  3414. } else {
  3415. $this->debug("Neither _SERVER nor HTTP_SERVER_VARS is defined.");
  3416. }
  3417. if (isset($debug)) {
  3418. $this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
  3419. $this->debug_flag = $debug;
  3420. } elseif (isset($_SERVER['QUERY_STRING'])) {
  3421. $qs = explode('&', $_SERVER['QUERY_STRING']);
  3422. foreach ($qs as $v) {
  3423. if (substr($v, 0, 6) == 'debug=') {
  3424. $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #1");
  3425. $this->debug_flag = substr($v, 6);
  3426. }
  3427. }
  3428. } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  3429. $qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
  3430. foreach ($qs as $v) {
  3431. if (substr($v, 0, 6) == 'debug=') {
  3432. $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #2");
  3433. $this->debug_flag = substr($v, 6);
  3434. }
  3435. }
  3436. }
  3437. // wsdl
  3438. if($wsdl){
  3439. $this->debug("In nusoap_server, WSDL is specified");
  3440. if (is_object($wsdl) && (get_class($wsdl) == 'wsdl')) {
  3441. $this->wsdl = $wsdl;
  3442. $this->externalWSDLURL = $this->wsdl->wsdl;
  3443. $this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
  3444. } else {
  3445. $this->debug('Create wsdl from ' . $wsdl);
  3446. $this->wsdl = new wsdl($wsdl);
  3447. $this->externalWSDLURL = $wsdl;
  3448. }
  3449. $this->appendDebug($this->wsdl->getDebug());
  3450. $this->wsdl->clearDebug();
  3451. if($err = $this->wsdl->getError()){
  3452. die('WSDL ERROR: '.$err);
  3453. }
  3454. }
  3455. }
  3456. /**
  3457. * processes request and returns response
  3458. *
  3459. * @param string $data usually is the value of $HTTP_RAW_POST_DATA
  3460. * @access public
  3461. */
  3462. function service($data){
  3463. global $HTTP_SERVER_VARS;
  3464. if (isset($_SERVER['REQUEST_METHOD'])) {
  3465. $rm = $_SERVER['REQUEST_METHOD'];
  3466. } elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
  3467. $rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
  3468. } else {
  3469. $rm = '';
  3470. }
  3471. if (isset($_SERVER['QUERY_STRING'])) {
  3472. $qs = $_SERVER['QUERY_STRING'];
  3473. } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  3474. $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
  3475. } else {
  3476. $qs = '';
  3477. }
  3478. $this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
  3479. if ($rm == 'POST') {
  3480. $this->debug("In service, invoke the request");
  3481. $this->parse_request($data);
  3482. if (! $this->fault) {
  3483. $this->invoke_method();
  3484. }
  3485. if (! $this->fault) {
  3486. $this->serialize_return();
  3487. }
  3488. $this->send_response();
  3489. } elseif (preg_match('/wsdl/', $qs) ){
  3490. $this->debug("In service, this is a request for WSDL");
  3491. if ($this->externalWSDLURL){
  3492. if (strpos($this->externalWSDLURL, "http://") !== false) { // assume URL
  3493. $this->debug("In service, re-direct for WSDL");
  3494. header('Location: '.$this->externalWSDLURL);
  3495. } else { // assume file
  3496. $this->debug("In service, use file passthru for WSDL");
  3497. header("Content-Type: text/xml\r\n");
  3498. $pos = strpos($this->externalWSDLURL, "file://");
  3499. if ($pos === false) {
  3500. $filename = $this->externalWSDLURL;
  3501. } else {
  3502. $filename = substr($this->externalWSDLURL, $pos + 7);
  3503. }
  3504. $fp = fopen($this->externalWSDLURL, 'r');
  3505. fpassthru($fp);
  3506. }
  3507. } elseif ($this->wsdl) {
  3508. $this->debug("In service, serialize WSDL");
  3509. header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
  3510. print $this->wsdl->serialize($this->debug_flag);
  3511. if ($this->debug_flag) {
  3512. $this->debug('wsdl:');
  3513. $this->appendDebug($this->varDump($this->wsdl));
  3514. print $this->getDebugAsXMLComment();
  3515. }
  3516. } else {
  3517. $this->debug("In service, there is no WSDL");
  3518. header("Content-Type: text/html; charset=ISO-8859-1\r\n");
  3519. print "This service does not provide WSDL";
  3520. }
  3521. } elseif ($this->wsdl) {
  3522. $this->debug("In service, return Web description");
  3523. print $this->wsdl->webDescription();
  3524. } else {
  3525. $this->debug("In service, no Web description");
  3526. header("Content-Type: text/html; charset=ISO-8859-1\r\n");
  3527. print "This service does not provide a Web description";
  3528. }
  3529. }
  3530. /**
  3531. * parses HTTP request headers.
  3532. *
  3533. * The following fields are set by this function (when successful)
  3534. *
  3535. * headers
  3536. * request
  3537. * xml_encoding
  3538. * SOAPAction
  3539. *
  3540. * @access private
  3541. */
  3542. function parse_http_headers() {
  3543. global $HTTP_SERVER_VARS;
  3544. $this->request = '';
  3545. $this->SOAPAction = '';
  3546. if(function_exists('getallheaders')){
  3547. $this->debug("In parse_http_headers, use getallheaders");
  3548. $headers = getallheaders();
  3549. foreach($headers as $k=>$v){
  3550. $k = strtolower($k);
  3551. $this->headers[$k] = $v;
  3552. $this->request .= "$k: $v\r\n";
  3553. $this->debug("$k: $v");
  3554. }
  3555. // get SOAPAction header
  3556. if(isset($this->headers['soapaction'])){
  3557. $this->SOAPAction = str_replace('"','',$this->headers['soapaction']);
  3558. }
  3559. // get the character encoding of the incoming request
  3560. if(isset($this->headers['content-type']) && strpos($this->headers['content-type'],'=')){
  3561. $enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1));
  3562. if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
  3563. $this->xml_encoding = strtoupper($enc);
  3564. } else {
  3565. $this->xml_encoding = 'US-ASCII';
  3566. }
  3567. } else {
  3568. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  3569. $this->xml_encoding = 'ISO-8859-1';
  3570. }
  3571. } elseif(isset($_SERVER) && is_array($_SERVER)){
  3572. $this->debug("In parse_http_headers, use _SERVER");
  3573. foreach ($_SERVER as $k => $v) {
  3574. if (substr($k, 0, 5) == 'HTTP_') {
  3575. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
  3576. } else {
  3577. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
  3578. }
  3579. if ($k == 'soapaction') {
  3580. // get SOAPAction header
  3581. $k = 'SOAPAction';
  3582. $v = str_replace('"', '', $v);
  3583. $v = str_replace('\\', '', $v);
  3584. $this->SOAPAction = $v;
  3585. } else if ($k == 'content-type') {
  3586. // get the character encoding of the incoming request
  3587. if (strpos($v, '=')) {
  3588. $enc = substr(strstr($v, '='), 1);
  3589. $enc = str_replace('"', '', $enc);
  3590. $enc = str_replace('\\', '', $enc);
  3591. if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
  3592. $this->xml_encoding = strtoupper($enc);
  3593. } else {
  3594. $this->xml_encoding = 'US-ASCII';
  3595. }
  3596. } else {
  3597. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  3598. $this->xml_encoding = 'ISO-8859-1';
  3599. }
  3600. }
  3601. $this->headers[$k] = $v;
  3602. $this->request .= "$k: $v\r\n";
  3603. $this->debug("$k: $v");
  3604. }
  3605. } elseif (is_array($HTTP_SERVER_VARS)) {
  3606. $this->debug("In parse_http_headers, use HTTP_SERVER_VARS");
  3607. foreach ($HTTP_SERVER_VARS as $k => $v) {
  3608. if (substr($k, 0, 5) == 'HTTP_') {
  3609. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5)))); $k = strtolower(substr($k, 5));
  3610. } else {
  3611. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k))); $k = strtolower($k);
  3612. }
  3613. if ($k == 'soapaction') {
  3614. // get SOAPAction header
  3615. $k = 'SOAPAction';
  3616. $v = str_replace('"', '', $v);
  3617. $v = str_replace('\\', '', $v);
  3618. $this->SOAPAction = $v;
  3619. } else if ($k == 'content-type') {
  3620. // get the character encoding of the incoming request
  3621. if (strpos($v, '=')) {
  3622. $enc = substr(strstr($v, '='), 1);
  3623. $enc = str_replace('"', '', $enc);
  3624. $enc = str_replace('\\', '', $enc);
  3625. if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
  3626. $this->xml_encoding = strtoupper($enc);
  3627. } else {
  3628. $this->xml_encoding = 'US-ASCII';
  3629. }
  3630. } else {
  3631. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  3632. $this->xml_encoding = 'ISO-8859-1';
  3633. }
  3634. }
  3635. $this->headers[$k] = $v;
  3636. $this->request .= "$k: $v\r\n";
  3637. $this->debug("$k: $v");
  3638. }
  3639. } else {
  3640. $this->debug("In parse_http_headers, HTTP headers not accessible");
  3641. $this->setError("HTTP headers not accessible");
  3642. }
  3643. }
  3644. /**
  3645. * parses a request
  3646. *
  3647. * The following fields are set by this function (when successful)
  3648. *
  3649. * headers
  3650. * request
  3651. * xml_encoding
  3652. * SOAPAction
  3653. * request
  3654. * requestSOAP
  3655. * methodURI
  3656. * methodname
  3657. * methodparams
  3658. * requestHeaders
  3659. * document
  3660. *
  3661. * This sets the fault field on error
  3662. *
  3663. * @param string $data XML string
  3664. * @access private
  3665. */
  3666. function parse_request($data='') {
  3667. $this->debug('entering parse_request()');
  3668. $this->parse_http_headers();
  3669. $this->debug('got character encoding: '.$this->xml_encoding);
  3670. // uncompress if necessary
  3671. if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] != '') {
  3672. $this->debug('got content encoding: ' . $this->headers['content-encoding']);
  3673. if ($this->headers['content-encoding'] == 'deflate' || $this->headers['content-encoding'] == 'gzip') {
  3674. // if decoding works, use it. else assume data wasn't gzencoded
  3675. if (function_exists('gzuncompress')) {
  3676. if ($this->headers['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
  3677. $data = $degzdata;
  3678. } elseif ($this->headers['content-encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))) {
  3679. $data = $degzdata;
  3680. } else {
  3681. $this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
  3682. return;
  3683. }
  3684. } else {
  3685. $this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
  3686. return;
  3687. }
  3688. }
  3689. }
  3690. $this->request .= "\r\n".$data;
  3691. $data = $this->parseRequest($this->headers, $data);
  3692. $this->requestSOAP = $data;
  3693. $this->debug('leaving parse_request');
  3694. }
  3695. /**
  3696. * invokes a PHP function for the requested SOAP method
  3697. *
  3698. * The following fields are set by this function (when successful)
  3699. *
  3700. * methodreturn
  3701. *
  3702. * Note that the PHP function that is called may also set the following
  3703. * fields to affect the response sent to the client
  3704. *
  3705. * responseHeaders
  3706. * outgoing_headers
  3707. *
  3708. * This sets the fault field on error
  3709. *
  3710. * @access private
  3711. */
  3712. function invoke_method() {
  3713. $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
  3714. //
  3715. // if you are debugging in this area of the code, your service uses a class to implement methods,
  3716. // you use SOAP RPC, and the client is .NET, please be aware of the following...
  3717. // when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
  3718. // method name. that is fine for naming the .NET methods. it is not fine for properly constructing
  3719. // the XML request and reading the XML response. you need to add the RequestElementName and
  3720. // ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
  3721. // generates for the method. these parameters are used to specify the correct XML element names
  3722. // for .NET to use, i.e. the names with the '.' in them.
  3723. //
  3724. $orig_methodname = $this->methodname;
  3725. if ($this->wsdl) {
  3726. if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
  3727. $this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
  3728. $this->appendDebug('opData=' . $this->varDump($this->opData));
  3729. } elseif ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction)) {
  3730. // Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
  3731. $this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
  3732. $this->appendDebug('opData=' . $this->varDump($this->opData));
  3733. $this->methodname = $this->opData['name'];
  3734. } else {
  3735. $this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
  3736. $this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
  3737. return;
  3738. }
  3739. } else {
  3740. $this->debug('in invoke_method, no WSDL to validate method');
  3741. }
  3742. // if a . is present in $this->methodname, we see if there is a class in scope,
  3743. // which could be referred to. We will also distinguish between two deliminators,
  3744. // to allow methods to be called a the class or an instance
  3745. if (strpos($this->methodname, '..') > 0) {
  3746. $delim = '..';
  3747. } else if (strpos($this->methodname, '.') > 0) {
  3748. $delim = '.';
  3749. } else {
  3750. $delim = '';
  3751. }
  3752. $this->debug("in invoke_method, delim=$delim");
  3753. $class = '';
  3754. $method = '';
  3755. if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
  3756. $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
  3757. if (class_exists($try_class)) {
  3758. // get the class and method name
  3759. $class = $try_class;
  3760. $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
  3761. $this->debug("in invoke_method, class=$class method=$method delim=$delim");
  3762. } else {
  3763. $this->debug("in invoke_method, class=$try_class not found");
  3764. }
  3765. } else {
  3766. $try_class = '';
  3767. $this->debug("in invoke_method, no class to try");
  3768. }
  3769. // does method exist?
  3770. if ($class == '') {
  3771. if (!function_exists($this->methodname)) {
  3772. $this->debug("in invoke_method, function '$this->methodname' not found!");
  3773. $this->result = 'fault: method not found';
  3774. $this->fault('SOAP-ENV:Client',"method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
  3775. return;
  3776. }
  3777. } else {
  3778. $method_to_compare = (substr(phpversion(), 0, 2) == '4.') ? strtolower($method) : $method;
  3779. if (!in_array($method_to_compare, get_class_methods($class))) {
  3780. $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
  3781. $this->result = 'fault: method not found';
  3782. $this->fault('SOAP-ENV:Client',"method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
  3783. return;
  3784. }
  3785. }
  3786. // evaluate message, getting back parameters
  3787. // verify that request parameters match the method's signature
  3788. if(! $this->verify_method($this->methodname,$this->methodparams)){
  3789. // debug
  3790. $this->debug('ERROR: request not verified against method signature');
  3791. $this->result = 'fault: request failed validation against method signature';
  3792. // return fault
  3793. $this->fault('SOAP-ENV:Client',"Operation '$this->methodname' not defined in service.");
  3794. return;
  3795. }
  3796. // if there are parameters to pass
  3797. $this->debug('in invoke_method, params:');
  3798. $this->appendDebug($this->varDump($this->methodparams));
  3799. $this->debug("in invoke_method, calling '$this->methodname'");
  3800. if (!function_exists('call_user_func_array')) {
  3801. if ($class == '') {
  3802. $this->debug('in invoke_method, calling function using eval()');
  3803. $funcCall = "\$this->methodreturn = $this->methodname(";
  3804. } else {
  3805. if ($delim == '..') {
  3806. $this->debug('in invoke_method, calling class method using eval()');
  3807. $funcCall = "\$this->methodreturn = ".$class."::".$method."(";
  3808. } else {
  3809. $this->debug('in invoke_method, calling instance method using eval()');
  3810. // generate unique instance name
  3811. $instname = "\$inst_".time();
  3812. $funcCall = $instname." = new ".$class."(); ";
  3813. $funcCall .= "\$this->methodreturn = ".$instname."->".$method."(";
  3814. }
  3815. }
  3816. if ($this->methodparams) {
  3817. foreach ($this->methodparams as $param) {
  3818. if (is_array($param) || is_object($param)) {
  3819. $this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
  3820. return;
  3821. }
  3822. $funcCall .= "\"$param\",";
  3823. }
  3824. $funcCall = substr($funcCall, 0, -1);
  3825. }
  3826. $funcCall .= ');';
  3827. $this->debug('in invoke_method, function call: '.$funcCall);
  3828. @eval($funcCall);
  3829. } else {
  3830. if ($class == '') {
  3831. $this->debug('in invoke_method, calling function using call_user_func_array()');
  3832. $call_arg = "$this->methodname"; // straight assignment changes $this->methodname to lower case after call_user_func_array()
  3833. } elseif ($delim == '..') {
  3834. $this->debug('in invoke_method, calling class method using call_user_func_array()');
  3835. $call_arg = array ($class, $method);
  3836. } else {
  3837. $this->debug('in invoke_method, calling instance method using call_user_func_array()');
  3838. $instance = new $class ();
  3839. $call_arg = array(&$instance, $method);
  3840. }
  3841. if (is_array($this->methodparams)) {
  3842. $this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
  3843. } else {
  3844. $this->methodreturn = call_user_func_array($call_arg, array());
  3845. }
  3846. }
  3847. $this->debug('in invoke_method, methodreturn:');
  3848. $this->appendDebug($this->varDump($this->methodreturn));
  3849. $this->debug("in invoke_method, called method $this->methodname, received data of type ".gettype($this->methodreturn));
  3850. }
  3851. /**
  3852. * serializes the return value from a PHP function into a full SOAP Envelope
  3853. *
  3854. * The following fields are set by this function (when successful)
  3855. *
  3856. * responseSOAP
  3857. *
  3858. * This sets the fault field on error
  3859. *
  3860. * @access private
  3861. */
  3862. function serialize_return() {
  3863. $this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
  3864. // if fault
  3865. if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) {
  3866. $this->debug('got a fault object from method');
  3867. $this->fault = $this->methodreturn;
  3868. return;
  3869. } elseif ($this->methodreturnisliteralxml) {
  3870. $return_val = $this->methodreturn;
  3871. // returned value(s)
  3872. } else {
  3873. $this->debug('got a(n) '.gettype($this->methodreturn).' from method');
  3874. $this->debug('serializing return value');
  3875. if($this->wsdl){
  3876. if (sizeof($this->opData['output']['parts']) > 1) {
  3877. $this->debug('more than one output part, so use the method return unchanged');
  3878. $opParams = $this->methodreturn;
  3879. } elseif (sizeof($this->opData['output']['parts']) == 1) {
  3880. $this->debug('exactly one output part, so wrap the method return in a simple array');
  3881. // TODO: verify that it is not already wrapped!
  3882. //foreach ($this->opData['output']['parts'] as $name => $type) {
  3883. // $this->debug('wrap in element named ' . $name);
  3884. //}
  3885. $opParams = array($this->methodreturn);
  3886. }
  3887. $return_val = $this->wsdl->serializeRPCParameters($this->methodname,'output',$opParams);
  3888. $this->appendDebug($this->wsdl->getDebug());
  3889. $this->wsdl->clearDebug();
  3890. if($errstr = $this->wsdl->getError()){
  3891. $this->debug('got wsdl error: '.$errstr);
  3892. $this->fault('SOAP-ENV:Server', 'unable to serialize result');
  3893. return;
  3894. }
  3895. } else {
  3896. if (isset($this->methodreturn)) {
  3897. $return_val = $this->serialize_val($this->methodreturn, 'return');
  3898. } else {
  3899. $return_val = '';
  3900. $this->debug('in absence of WSDL, assume void return for backward compatibility');
  3901. }
  3902. }
  3903. }
  3904. $this->debug('return value:');
  3905. $this->appendDebug($this->varDump($return_val));
  3906. $this->debug('serializing response');
  3907. if ($this->wsdl) {
  3908. $this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
  3909. if ($this->opData['style'] == 'rpc') {
  3910. $this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
  3911. if ($this->opData['output']['use'] == 'literal') {
  3912. // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
  3913. if ($this->methodURI) {
  3914. $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
  3915. } else {
  3916. $payload = '<'.$this->methodname.'Response>'.$return_val.'</'.$this->methodname.'Response>';
  3917. }
  3918. } else {
  3919. if ($this->methodURI) {
  3920. $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
  3921. } else {
  3922. $payload = '<'.$this->methodname.'Response>'.$return_val.'</'.$this->methodname.'Response>';
  3923. }
  3924. }
  3925. } else {
  3926. $this->debug('style is not rpc for serialization: assume document');
  3927. $payload = $return_val;
  3928. }
  3929. } else {
  3930. $this->debug('do not have WSDL for serialization: assume rpc/encoded');
  3931. $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
  3932. }
  3933. $this->result = 'successful';
  3934. if($this->wsdl){
  3935. //if($this->debug_flag){
  3936. $this->appendDebug($this->wsdl->getDebug());
  3937. // }
  3938. if (isset($this->opData['output']['encodingStyle'])) {
  3939. $encodingStyle = $this->opData['output']['encodingStyle'];
  3940. } else {
  3941. $encodingStyle = '';
  3942. }
  3943. // Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
  3944. $this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders,$this->wsdl->usedNamespaces,$this->opData['style'],$this->opData['output']['use'],$encodingStyle);
  3945. } else {
  3946. $this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders);
  3947. }
  3948. $this->debug("Leaving serialize_return");
  3949. }
  3950. /**
  3951. * sends an HTTP response
  3952. *
  3953. * The following fields are set by this function (when successful)
  3954. *
  3955. * outgoing_headers
  3956. * response
  3957. *
  3958. * @access private
  3959. */
  3960. function send_response() {
  3961. $this->debug('Enter send_response');
  3962. if ($this->fault) {
  3963. $payload = $this->fault->serialize();
  3964. $this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
  3965. $this->outgoing_headers[] = "Status: 500 Internal Server Error";
  3966. } else {
  3967. $payload = $this->responseSOAP;
  3968. // Some combinations of PHP+Web server allow the Status
  3969. // to come through as a header. Since OK is the default
  3970. // just do nothing.
  3971. // $this->outgoing_headers[] = "HTTP/1.0 200 OK";
  3972. // $this->outgoing_headers[] = "Status: 200 OK";
  3973. }
  3974. // add debug data if in debug mode
  3975. if(isset($this->debug_flag) && $this->debug_flag){
  3976. $payload .= $this->getDebugAsXMLComment();
  3977. }
  3978. $this->outgoing_headers[] = "Server: $this->title Server v$this->version";
  3979. preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
  3980. $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".$rev[1].")";
  3981. // Let the Web server decide about this
  3982. //$this->outgoing_headers[] = "Connection: Close\r\n";
  3983. $payload = $this->getHTTPBody($payload);
  3984. $type = $this->getHTTPContentType();
  3985. $charset = $this->getHTTPContentTypeCharset();
  3986. $this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
  3987. //begin code to compress payload - by John
  3988. // NOTE: there is no way to know whether the Web server will also compress
  3989. // this data.
  3990. if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
  3991. if (strstr($this->headers['accept-encoding'], 'gzip')) {
  3992. if (function_exists('gzencode')) {
  3993. if (isset($this->debug_flag) && $this->debug_flag) {
  3994. $payload .= "<!-- Content being gzipped -->";
  3995. }
  3996. $this->outgoing_headers[] = "Content-Encoding: gzip";
  3997. $payload = gzencode($payload);
  3998. } else {
  3999. if (isset($this->debug_flag) && $this->debug_flag) {
  4000. $payload .= "<!-- Content will not be gzipped: no gzencode -->";
  4001. }
  4002. }
  4003. } elseif (strstr($this->headers['accept-encoding'], 'deflate')) {
  4004. // Note: MSIE requires gzdeflate output (no Zlib header and checksum),
  4005. // instead of gzcompress output,
  4006. // which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
  4007. if (function_exists('gzdeflate')) {
  4008. if (isset($this->debug_flag) && $this->debug_flag) {
  4009. $payload .= "<!-- Content being deflated -->";
  4010. }
  4011. $this->outgoing_headers[] = "Content-Encoding: deflate";
  4012. $payload = gzdeflate($payload);
  4013. } else {
  4014. if (isset($this->debug_flag) && $this->debug_flag) {
  4015. $payload .= "<!-- Content will not be deflated: no gzcompress -->";
  4016. }
  4017. }
  4018. }
  4019. }
  4020. //end code
  4021. $this->outgoing_headers[] = "Content-Length: ".strlen($payload);
  4022. reset($this->outgoing_headers);
  4023. foreach($this->outgoing_headers as $hdr){
  4024. header($hdr, false);
  4025. }
  4026. print $payload;
  4027. $this->response = join("\r\n",$this->outgoing_headers)."\r\n\r\n".$payload;
  4028. }
  4029. /**
  4030. * takes the value that was created by parsing the request
  4031. * and compares to the method's signature, if available.
  4032. *
  4033. * @param string $operation The operation to be invoked
  4034. * @param array $request The array of parameter values
  4035. * @return boolean Whether the operation was found
  4036. * @access private
  4037. */
  4038. function verify_method($operation,$request){
  4039. if(isset($this->wsdl) && is_object($this->wsdl)){
  4040. if($this->wsdl->getOperationData($operation)){
  4041. return true;
  4042. }
  4043. } elseif(isset($this->operations[$operation])){
  4044. return true;
  4045. }
  4046. return false;
  4047. }
  4048. /**
  4049. * processes SOAP message received from client
  4050. *
  4051. * @param array $headers The HTTP headers
  4052. * @param string $data unprocessed request data from client
  4053. * @return mixed value of the message, decoded into a PHP type
  4054. * @access private
  4055. */
  4056. function parseRequest($headers, $data) {
  4057. $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
  4058. $this->appendDebug($this->varDump($headers));
  4059. if (!isset($headers['content-type'])) {
  4060. $this->setError('Request not of type text/xml (no content-type header)');
  4061. return false;
  4062. }
  4063. if (!strstr($headers['content-type'], 'text/xml')) {
  4064. $this->setError('Request not of type text/xml');
  4065. return false;
  4066. }
  4067. if (strpos($headers['content-type'], '=')) {
  4068. $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
  4069. $this->debug('Got response encoding: ' . $enc);
  4070. if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
  4071. $this->xml_encoding = strtoupper($enc);
  4072. } else {
  4073. $this->xml_encoding = 'US-ASCII';
  4074. }
  4075. } else {
  4076. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  4077. $this->xml_encoding = 'ISO-8859-1';
  4078. }
  4079. $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
  4080. // parse response, get soap parser obj
  4081. $parser = new nusoap_parser($data,$this->xml_encoding,'',$this->decode_utf8);
  4082. // parser debug
  4083. $this->debug("parser debug: \n".$parser->getDebug());
  4084. // if fault occurred during message parsing
  4085. if($err = $parser->getError()){
  4086. $this->result = 'fault: error in msg parsing: '.$err;
  4087. $this->fault('SOAP-ENV:Client',"error in msg parsing:\n".$err);
  4088. // else successfully parsed request into soapval object
  4089. } else {
  4090. // get/set methodname
  4091. $this->methodURI = $parser->root_struct_namespace;
  4092. $this->methodname = $parser->root_struct_name;
  4093. $this->debug('methodname: '.$this->methodname.' methodURI: '.$this->methodURI);
  4094. $this->debug('calling parser->get_soapbody()');
  4095. $this->methodparams = $parser->get_soapbody();
  4096. // get SOAP headers
  4097. $this->requestHeaders = $parser->getHeaders();
  4098. // get SOAP Header
  4099. $this->requestHeader = $parser->get_soapheader();
  4100. // add document for doclit support
  4101. $this->document = $parser->document;
  4102. }
  4103. }
  4104. /**
  4105. * gets the HTTP body for the current response.
  4106. *
  4107. * @param string $soapmsg The SOAP payload
  4108. * @return string The HTTP body, which includes the SOAP payload
  4109. * @access private
  4110. */
  4111. function getHTTPBody($soapmsg) {
  4112. return $soapmsg;
  4113. }
  4114. /**
  4115. * gets the HTTP content type for the current response.
  4116. *
  4117. * Note: getHTTPBody must be called before this.
  4118. *
  4119. * @return string the HTTP content type for the current response.
  4120. * @access private
  4121. */
  4122. function getHTTPContentType() {
  4123. return 'text/xml';
  4124. }
  4125. /**
  4126. * gets the HTTP content type charset for the current response.
  4127. * returns false for non-text content types.
  4128. *
  4129. * Note: getHTTPBody must be called before this.
  4130. *
  4131. * @return string the HTTP content type charset for the current response.
  4132. * @access private
  4133. */
  4134. function getHTTPContentTypeCharset() {
  4135. return $this->soap_defencoding;
  4136. }
  4137. /**
  4138. * add a method to the dispatch map (this has been replaced by the register method)
  4139. *
  4140. * @param string $methodname
  4141. * @param string $in array of input values
  4142. * @param string $out array of output values
  4143. * @access public
  4144. * @deprecated
  4145. */
  4146. function add_to_map($methodname,$in,$out){
  4147. $this->operations[$methodname] = array('name' => $methodname,'in' => $in,'out' => $out);
  4148. }
  4149. /**
  4150. * register a service function with the server
  4151. *
  4152. * @param string $name the name of the PHP function, class.method or class..method
  4153. * @param array $in assoc array of input values: key = param name, value = param type
  4154. * @param array $out assoc array of output values: key = param name, value = param type
  4155. * @param mixed $namespace the element namespace for the method or false
  4156. * @param mixed $soapaction the soapaction for the method or false
  4157. * @param mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
  4158. * @param mixed $use optional (encoded|literal) or false
  4159. * @param string $documentation optional Description to include in WSDL
  4160. * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
  4161. * @access public
  4162. */
  4163. function register($name,$in=array(),$out=array(),$namespace=false,$soapaction=false,$style=false,$use=false,$documentation='',$encodingStyle=''){
  4164. global $HTTP_SERVER_VARS;
  4165. if($this->externalWSDLURL){
  4166. die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
  4167. }
  4168. if (! $name) {
  4169. die('You must specify a name when you register an operation');
  4170. }
  4171. if (!is_array($in)) {
  4172. die('You must provide an array for operation inputs');
  4173. }
  4174. if (!is_array($out)) {
  4175. die('You must provide an array for operation outputs');
  4176. }
  4177. if(false == $namespace) {
  4178. }
  4179. if(false == $soapaction) {
  4180. if (isset($_SERVER)) {
  4181. $SERVER_NAME = $_SERVER['SERVER_NAME'];
  4182. $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
  4183. $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
  4184. } elseif (isset($HTTP_SERVER_VARS)) {
  4185. $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
  4186. $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
  4187. $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
  4188. } else {
  4189. $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
  4190. }
  4191. if ($HTTPS == '1' || $HTTPS == 'on') {
  4192. $SCHEME = 'https';
  4193. } else {
  4194. $SCHEME = 'http';
  4195. }
  4196. $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
  4197. }
  4198. if(false == $style) {
  4199. $style = "rpc";
  4200. }
  4201. if(false == $use) {
  4202. $use = "encoded";
  4203. }
  4204. if ($use == 'encoded' && $encodingStyle == '') {
  4205. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  4206. }
  4207. $this->operations[$name] = array(
  4208. 'name' => $name,
  4209. 'in' => $in,
  4210. 'out' => $out,
  4211. 'namespace' => $namespace,
  4212. 'soapaction' => $soapaction,
  4213. 'style' => $style);
  4214. if($this->wsdl){
  4215. $this->wsdl->addOperation($name,$in,$out,$namespace,$soapaction,$style,$use,$documentation,$encodingStyle);
  4216. }
  4217. return true;
  4218. }
  4219. /**
  4220. * Specify a fault to be returned to the client.
  4221. * This also acts as a flag to the server that a fault has occured.
  4222. *
  4223. * @param string $faultcode
  4224. * @param string $faultstring
  4225. * @param string $faultactor
  4226. * @param string $faultdetail
  4227. * @access public
  4228. */
  4229. function fault($faultcode,$faultstring,$faultactor='',$faultdetail=''){
  4230. if ($faultdetail == '' && $this->debug_flag) {
  4231. $faultdetail = $this->getDebug();
  4232. }
  4233. $this->fault = new nusoap_fault($faultcode,$faultactor,$faultstring,$faultdetail);
  4234. $this->fault->soap_defencoding = $this->soap_defencoding;
  4235. }
  4236. /**
  4237. * Sets up wsdl object.
  4238. * Acts as a flag to enable internal WSDL generation
  4239. *
  4240. * @param string $serviceName, name of the service
  4241. * @param mixed $namespace optional 'tns' service namespace or false
  4242. * @param mixed $endpoint optional URL of service endpoint or false
  4243. * @param string $style optional (rpc|document) WSDL style (also specified by operation)
  4244. * @param string $transport optional SOAP transport
  4245. * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
  4246. */
  4247. function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
  4248. {
  4249. global $HTTP_SERVER_VARS;
  4250. if (isset($_SERVER)) {
  4251. $SERVER_NAME = $_SERVER['SERVER_NAME'];
  4252. $SERVER_PORT = $_SERVER['SERVER_PORT'];
  4253. $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
  4254. $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
  4255. } elseif (isset($HTTP_SERVER_VARS)) {
  4256. $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
  4257. $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
  4258. $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
  4259. $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
  4260. } else {
  4261. $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
  4262. }
  4263. // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
  4264. $colon = strpos($SERVER_NAME,":");
  4265. if ($colon) {
  4266. $SERVER_NAME = substr($SERVER_NAME, 0, $colon);
  4267. }
  4268. if ($SERVER_PORT == 80) {
  4269. $SERVER_PORT = '';
  4270. } else {
  4271. $SERVER_PORT = ':' . $SERVER_PORT;
  4272. }
  4273. if(false == $namespace) {
  4274. $namespace = "http://$SERVER_NAME/soap/$serviceName";
  4275. }
  4276. if(false == $endpoint) {
  4277. if ($HTTPS == '1' || $HTTPS == 'on') {
  4278. $SCHEME = 'https';
  4279. } else {
  4280. $SCHEME = 'http';
  4281. }
  4282. $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
  4283. }
  4284. if(false == $schemaTargetNamespace) {
  4285. $schemaTargetNamespace = $namespace;
  4286. }
  4287. $this->wsdl = new wsdl;
  4288. //$this->wsdl->soap_defencoding = $this->soap_defencoding;
  4289. $this->wsdl->serviceName = $serviceName;
  4290. $this->wsdl->endpoint = $endpoint;
  4291. $this->wsdl->namespaces['tns'] = $namespace;
  4292. $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4293. $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
  4294. if ($schemaTargetNamespace != $namespace) {
  4295. $this->wsdl->namespaces['types'] = $schemaTargetNamespace;
  4296. }
  4297. $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
  4298. if ($style == 'document') {
  4299. $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
  4300. }
  4301. $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
  4302. $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = array('location' => '', 'loaded' => true);
  4303. $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = array('location' => '', 'loaded' => true);
  4304. $this->wsdl->bindings[$serviceName.'Binding'] = array(
  4305. 'name'=>$serviceName.'Binding',
  4306. 'style'=>$style,
  4307. 'transport'=>$transport,
  4308. 'portType'=>$serviceName.'PortType');
  4309. $this->wsdl->ports[$serviceName.'Port'] = array(
  4310. 'binding'=>$serviceName.'Binding',
  4311. 'location'=>$endpoint,
  4312. 'bindingType'=>'http://schemas.xmlsoap.org/wsdl/soap/');
  4313. }
  4314. }
  4315. /**
  4316. * Backward compatibility
  4317. */
  4318. class soap_server extends nusoap_server {
  4319. }
  4320. ?><?php
  4321. /**
  4322. * parses a WSDL file, allows access to it's data, other utility methods.
  4323. * also builds WSDL structures programmatically.
  4324. *
  4325. * @author Dietrich Ayala <dietrich@ganx4.com>
  4326. * @author Scott Nichol <snichol@users.sourceforge.net>
  4327. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  4328. * @access public
  4329. */
  4330. class wsdl extends nusoap_base {
  4331. // URL or filename of the root of this WSDL
  4332. var $wsdl;
  4333. // define internal arrays of bindings, ports, operations, messages, etc.
  4334. var $schemas = array();
  4335. var $currentSchema;
  4336. var $message = array();
  4337. var $complexTypes = array();
  4338. var $messages = array();
  4339. var $currentMessage;
  4340. var $currentOperation;
  4341. var $portTypes = array();
  4342. var $currentPortType;
  4343. var $bindings = array();
  4344. var $currentBinding;
  4345. var $ports = array();
  4346. var $currentPort;
  4347. var $opData = array();
  4348. var $status = '';
  4349. var $documentation = false;
  4350. var $endpoint = '';
  4351. // array of wsdl docs to import
  4352. var $import = array();
  4353. // parser vars
  4354. var $parser;
  4355. var $position = 0;
  4356. var $depth = 0;
  4357. var $depth_array = array();
  4358. // for getting wsdl
  4359. var $proxyhost = '';
  4360. var $proxyport = '';
  4361. var $proxyusername = '';
  4362. var $proxypassword = '';
  4363. var $timeout = 0;
  4364. var $response_timeout = 30;
  4365. var $curl_options = array(); // User-specified cURL options
  4366. var $use_curl = false; // whether to always try to use cURL
  4367. // for HTTP authentication
  4368. var $username = ''; // Username for HTTP authentication
  4369. var $password = ''; // Password for HTTP authentication
  4370. var $authtype = ''; // Type of HTTP authentication
  4371. var $certRequest = array(); // Certificate for HTTP SSL authentication
  4372. /**
  4373. * constructor
  4374. *
  4375. * @param string $wsdl WSDL document URL
  4376. * @param string $proxyhost
  4377. * @param string $proxyport
  4378. * @param string $proxyusername
  4379. * @param string $proxypassword
  4380. * @param integer $timeout set the connection timeout
  4381. * @param integer $response_timeout set the response timeout
  4382. * @param array $curl_options user-specified cURL options
  4383. * @param boolean $use_curl try to use cURL
  4384. * @access public
  4385. */
  4386. function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){
  4387. parent::nusoap_base();
  4388. $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
  4389. $this->proxyhost = $proxyhost;
  4390. $this->proxyport = $proxyport;
  4391. $this->proxyusername = $proxyusername;
  4392. $this->proxypassword = $proxypassword;
  4393. $this->timeout = $timeout;
  4394. $this->response_timeout = $response_timeout;
  4395. if (is_array($curl_options))
  4396. $this->curl_options = $curl_options;
  4397. $this->use_curl = $use_curl;
  4398. $this->fetchWSDL($wsdl);
  4399. }
  4400. /**
  4401. * fetches the WSDL document and parses it
  4402. *
  4403. * @access public
  4404. */
  4405. function fetchWSDL($wsdl) {
  4406. $this->debug("parse and process WSDL path=$wsdl");
  4407. $this->wsdl = $wsdl;
  4408. // parse wsdl file
  4409. if ($this->wsdl != "") {
  4410. $this->parseWSDL($this->wsdl);
  4411. }
  4412. // imports
  4413. // TODO: handle imports more properly, grabbing them in-line and nesting them
  4414. $imported_urls = array();
  4415. $imported = 1;
  4416. while ($imported > 0) {
  4417. $imported = 0;
  4418. // Schema imports
  4419. foreach ($this->schemas as $ns => $list) {
  4420. foreach ($list as $xs) {
  4421. $wsdlparts = parse_url($this->wsdl); // this is bogusly simple!
  4422. foreach ($xs->imports as $ns2 => $list2) {
  4423. for ($ii = 0; $ii < count($list2); $ii++) {
  4424. if (! $list2[$ii]['loaded']) {
  4425. $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
  4426. $url = $list2[$ii]['location'];
  4427. if ($url != '') {
  4428. $urlparts = parse_url($url);
  4429. if (!isset($urlparts['host'])) {
  4430. $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') .
  4431. substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
  4432. }
  4433. if (! in_array($url, $imported_urls)) {
  4434. $this->parseWSDL($url);
  4435. $imported++;
  4436. $imported_urls[] = $url;
  4437. }
  4438. } else {
  4439. $this->debug("Unexpected scenario: empty URL for unloaded import");
  4440. }
  4441. }
  4442. }
  4443. }
  4444. }
  4445. }
  4446. // WSDL imports
  4447. $wsdlparts = parse_url($this->wsdl); // this is bogusly simple!
  4448. foreach ($this->import as $ns => $list) {
  4449. for ($ii = 0; $ii < count($list); $ii++) {
  4450. if (! $list[$ii]['loaded']) {
  4451. $this->import[$ns][$ii]['loaded'] = true;
  4452. $url = $list[$ii]['location'];
  4453. if ($url != '') {
  4454. $urlparts = parse_url($url);
  4455. if (!isset($urlparts['host'])) {
  4456. $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
  4457. substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
  4458. }
  4459. if (! in_array($url, $imported_urls)) {
  4460. $this->parseWSDL($url);
  4461. $imported++;
  4462. $imported_urls[] = $url;
  4463. }
  4464. } else {
  4465. $this->debug("Unexpected scenario: empty URL for unloaded import");
  4466. }
  4467. }
  4468. }
  4469. }
  4470. }
  4471. // add new data to operation data
  4472. foreach($this->bindings as $binding => $bindingData) {
  4473. if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
  4474. foreach($bindingData['operations'] as $operation => $data) {
  4475. $this->debug('post-parse data gathering for ' . $operation);
  4476. $this->bindings[$binding]['operations'][$operation]['input'] =
  4477. isset($this->bindings[$binding]['operations'][$operation]['input']) ?
  4478. array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) :
  4479. $this->portTypes[ $bindingData['portType'] ][$operation]['input'];
  4480. $this->bindings[$binding]['operations'][$operation]['output'] =
  4481. isset($this->bindings[$binding]['operations'][$operation]['output']) ?
  4482. array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) :
  4483. $this->portTypes[ $bindingData['portType'] ][$operation]['output'];
  4484. if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){
  4485. $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ];
  4486. }
  4487. if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){
  4488. $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
  4489. }
  4490. // Set operation style if necessary, but do not override one already provided
  4491. if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
  4492. $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
  4493. }
  4494. $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
  4495. $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
  4496. $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
  4497. }
  4498. }
  4499. }
  4500. }
  4501. /**
  4502. * parses the wsdl document
  4503. *
  4504. * @param string $wsdl path or URL
  4505. * @access private
  4506. */
  4507. function parseWSDL($wsdl = '') {
  4508. $this->debug("parse WSDL at path=$wsdl");
  4509. if ($wsdl == '') {
  4510. $this->debug('no wsdl passed to parseWSDL()!!');
  4511. $this->setError('no wsdl passed to parseWSDL()!!');
  4512. return false;
  4513. }
  4514. // parse $wsdl for url format
  4515. $wsdl_props = parse_url($wsdl);
  4516. if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
  4517. $this->debug('getting WSDL http(s) URL ' . $wsdl);
  4518. // get wsdl
  4519. $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
  4520. $tr->request_method = 'GET';
  4521. $tr->useSOAPAction = false;
  4522. if($this->proxyhost && $this->proxyport){
  4523. $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
  4524. }
  4525. if ($this->authtype != '') {
  4526. $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
  4527. }
  4528. $tr->setEncoding('gzip, deflate');
  4529. $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
  4530. //$this->debug("WSDL request\n" . $tr->outgoing_payload);
  4531. //$this->debug("WSDL response\n" . $tr->incoming_payload);
  4532. $this->appendDebug($tr->getDebug());
  4533. // catch errors
  4534. if($err = $tr->getError() ){
  4535. $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err;
  4536. $this->debug($errstr);
  4537. $this->setError($errstr);
  4538. unset($tr);
  4539. return false;
  4540. }
  4541. unset($tr);
  4542. $this->debug("got WSDL URL");
  4543. } else {
  4544. // $wsdl is not http(s), so treat it as a file URL or plain file path
  4545. if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
  4546. $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
  4547. } else {
  4548. $path = $wsdl;
  4549. }
  4550. $this->debug('getting WSDL file ' . $path);
  4551. if ($fp = @fopen($path, 'r')) {
  4552. $wsdl_string = '';
  4553. while ($data = fread($fp, 32768)) {
  4554. $wsdl_string .= $data;
  4555. }
  4556. fclose($fp);
  4557. } else {
  4558. $errstr = "Bad path to WSDL file $path";
  4559. $this->debug($errstr);
  4560. $this->setError($errstr);
  4561. return false;
  4562. }
  4563. }
  4564. $this->debug('Parse WSDL');
  4565. // end new code added
  4566. // Create an XML parser.
  4567. $this->parser = xml_parser_create();
  4568. // Set the options for parsing the XML data.
  4569. // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  4570. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  4571. // Set the object for the parser.
  4572. xml_set_object($this->parser, $this);
  4573. // Set the element handlers for the parser.
  4574. xml_set_element_handler($this->parser, 'start_element', 'end_element');
  4575. xml_set_character_data_handler($this->parser, 'character_data');
  4576. // Parse the XML file.
  4577. if (!xml_parse($this->parser, $wsdl_string, true)) {
  4578. // Display an error message.
  4579. $errstr = sprintf(
  4580. 'XML error parsing WSDL from %s on line %d: %s',
  4581. $wsdl,
  4582. xml_get_current_line_number($this->parser),
  4583. xml_error_string(xml_get_error_code($this->parser))
  4584. );
  4585. $this->debug($errstr);
  4586. $this->debug("XML payload:\n" . $wsdl_string);
  4587. $this->setError($errstr);
  4588. return false;
  4589. }
  4590. // free the parser
  4591. xml_parser_free($this->parser);
  4592. $this->debug('Parsing WSDL done');
  4593. // catch wsdl parse errors
  4594. if($this->getError()){
  4595. return false;
  4596. }
  4597. return true;
  4598. }
  4599. /**
  4600. * start-element handler
  4601. *
  4602. * @param string $parser XML parser object
  4603. * @param string $name element name
  4604. * @param string $attrs associative array of attributes
  4605. * @access private
  4606. */
  4607. function start_element($parser, $name, $attrs)
  4608. {
  4609. if ($this->status == 'schema') {
  4610. $this->currentSchema->schemaStartElement($parser, $name, $attrs);
  4611. $this->appendDebug($this->currentSchema->getDebug());
  4612. $this->currentSchema->clearDebug();
  4613. } elseif (preg_match('/schema$/', $name)) {
  4614. $this->debug('Parsing WSDL schema');
  4615. // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
  4616. $this->status = 'schema';
  4617. $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
  4618. $this->currentSchema->schemaStartElement($parser, $name, $attrs);
  4619. $this->appendDebug($this->currentSchema->getDebug());
  4620. $this->currentSchema->clearDebug();
  4621. } else {
  4622. // position in the total number of elements, starting from 0
  4623. $pos = $this->position++;
  4624. $depth = $this->depth++;
  4625. // set self as current value for this depth
  4626. $this->depth_array[$depth] = $pos;
  4627. $this->message[$pos] = array('cdata' => '');
  4628. // process attributes
  4629. if (count($attrs) > 0) {
  4630. // register namespace declarations
  4631. foreach($attrs as $k => $v) {
  4632. if (preg_match('/^xmlns/',$k)) {
  4633. if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
  4634. $this->namespaces[$ns_prefix] = $v;
  4635. } else {
  4636. $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
  4637. }
  4638. if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
  4639. $this->XMLSchemaVersion = $v;
  4640. $this->namespaces['xsi'] = $v . '-instance';
  4641. }
  4642. }
  4643. }
  4644. // expand each attribute prefix to its namespace
  4645. foreach($attrs as $k => $v) {
  4646. $k = strpos($k, ':') ? $this->expandQname($k) : $k;
  4647. if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
  4648. $v = strpos($v, ':') ? $this->expandQname($v) : $v;
  4649. }
  4650. $eAttrs[$k] = $v;
  4651. }
  4652. $attrs = $eAttrs;
  4653. } else {
  4654. $attrs = array();
  4655. }
  4656. // get element prefix, namespace and name
  4657. if (preg_match('/:/', $name)) {
  4658. // get ns prefix
  4659. $prefix = substr($name, 0, strpos($name, ':'));
  4660. // get ns
  4661. $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
  4662. // get unqualified name
  4663. $name = substr(strstr($name, ':'), 1);
  4664. }
  4665. // process attributes, expanding any prefixes to namespaces
  4666. // find status, register data
  4667. switch ($this->status) {
  4668. case 'message':
  4669. if ($name == 'part') {
  4670. if (isset($attrs['type'])) {
  4671. $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
  4672. $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
  4673. }
  4674. if (isset($attrs['element'])) {
  4675. $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
  4676. $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
  4677. }
  4678. }
  4679. break;
  4680. case 'portType':
  4681. switch ($name) {
  4682. case 'operation':
  4683. $this->currentPortOperation = $attrs['name'];
  4684. $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
  4685. if (isset($attrs['parameterOrder'])) {
  4686. $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
  4687. }
  4688. break;
  4689. case 'documentation':
  4690. $this->documentation = true;
  4691. break;
  4692. // merge input/output data
  4693. default:
  4694. $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
  4695. $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
  4696. break;
  4697. }
  4698. break;
  4699. case 'binding':
  4700. switch ($name) {
  4701. case 'binding':
  4702. // get ns prefix
  4703. if (isset($attrs['style'])) {
  4704. $this->bindings[$this->currentBinding]['prefix'] = $prefix;
  4705. }
  4706. $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
  4707. break;
  4708. case 'header':
  4709. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
  4710. break;
  4711. case 'operation':
  4712. if (isset($attrs['soapAction'])) {
  4713. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
  4714. }
  4715. if (isset($attrs['style'])) {
  4716. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
  4717. }
  4718. if (isset($attrs['name'])) {
  4719. $this->currentOperation = $attrs['name'];
  4720. $this->debug("current binding operation: $this->currentOperation");
  4721. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
  4722. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
  4723. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
  4724. }
  4725. break;
  4726. case 'input':
  4727. $this->opStatus = 'input';
  4728. break;
  4729. case 'output':
  4730. $this->opStatus = 'output';
  4731. break;
  4732. case 'body':
  4733. if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
  4734. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
  4735. } else {
  4736. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
  4737. }
  4738. break;
  4739. }
  4740. break;
  4741. case 'service':
  4742. switch ($name) {
  4743. case 'port':
  4744. $this->currentPort = $attrs['name'];
  4745. $this->debug('current port: ' . $this->currentPort);
  4746. $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
  4747. break;
  4748. case 'address':
  4749. $this->ports[$this->currentPort]['location'] = $attrs['location'];
  4750. $this->ports[$this->currentPort]['bindingType'] = $namespace;
  4751. $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
  4752. $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
  4753. break;
  4754. }
  4755. break;
  4756. }
  4757. // set status
  4758. switch ($name) {
  4759. case 'import':
  4760. if (isset($attrs['location'])) {
  4761. $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
  4762. $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
  4763. } else {
  4764. $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
  4765. if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
  4766. $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
  4767. }
  4768. $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
  4769. }
  4770. break;
  4771. //wait for schema
  4772. //case 'types':
  4773. // $this->status = 'schema';
  4774. // break;
  4775. case 'message':
  4776. $this->status = 'message';
  4777. $this->messages[$attrs['name']] = array();
  4778. $this->currentMessage = $attrs['name'];
  4779. break;
  4780. case 'portType':
  4781. $this->status = 'portType';
  4782. $this->portTypes[$attrs['name']] = array();
  4783. $this->currentPortType = $attrs['name'];
  4784. break;
  4785. case "binding":
  4786. if (isset($attrs['name'])) {
  4787. // get binding name
  4788. if (strpos($attrs['name'], ':')) {
  4789. $this->currentBinding = $this->getLocalPart($attrs['name']);
  4790. } else {
  4791. $this->currentBinding = $attrs['name'];
  4792. }
  4793. $this->status = 'binding';
  4794. $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
  4795. $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
  4796. }
  4797. break;
  4798. case 'service':
  4799. $this->serviceName = $attrs['name'];
  4800. $this->status = 'service';
  4801. $this->debug('current service: ' . $this->serviceName);
  4802. break;
  4803. case 'definitions':
  4804. foreach ($attrs as $name => $value) {
  4805. $this->wsdl_info[$name] = $value;
  4806. }
  4807. break;
  4808. }
  4809. }
  4810. }
  4811. /**
  4812. * end-element handler
  4813. *
  4814. * @param string $parser XML parser object
  4815. * @param string $name element name
  4816. * @access private
  4817. */
  4818. function end_element($parser, $name){
  4819. // unset schema status
  4820. if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) {
  4821. $this->status = "";
  4822. $this->appendDebug($this->currentSchema->getDebug());
  4823. $this->currentSchema->clearDebug();
  4824. $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
  4825. $this->debug('Parsing WSDL schema done');
  4826. }
  4827. if ($this->status == 'schema') {
  4828. $this->currentSchema->schemaEndElement($parser, $name);
  4829. } else {
  4830. // bring depth down a notch
  4831. $this->depth--;
  4832. }
  4833. // end documentation
  4834. if ($this->documentation) {
  4835. //TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
  4836. //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
  4837. $this->documentation = false;
  4838. }
  4839. }
  4840. /**
  4841. * element content handler
  4842. *
  4843. * @param string $parser XML parser object
  4844. * @param string $data element content
  4845. * @access private
  4846. */
  4847. function character_data($parser, $data)
  4848. {
  4849. $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
  4850. if (isset($this->message[$pos]['cdata'])) {
  4851. $this->message[$pos]['cdata'] .= $data;
  4852. }
  4853. if ($this->documentation) {
  4854. $this->documentation .= $data;
  4855. }
  4856. }
  4857. /**
  4858. * if authenticating, set user credentials here
  4859. *
  4860. * @param string $username
  4861. * @param string $password
  4862. * @param string $authtype (basic|digest|certificate|ntlm)
  4863. * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
  4864. * @access public
  4865. */
  4866. function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
  4867. $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
  4868. $this->appendDebug($this->varDump($certRequest));
  4869. $this->username = $username;
  4870. $this->password = $password;
  4871. $this->authtype = $authtype;
  4872. $this->certRequest = $certRequest;
  4873. }
  4874. function getBindingData($binding)
  4875. {
  4876. if (is_array($this->bindings[$binding])) {
  4877. return $this->bindings[$binding];
  4878. }
  4879. }
  4880. /**
  4881. * returns an assoc array of operation names => operation data
  4882. *
  4883. * @param string $portName WSDL port name
  4884. * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
  4885. * @return array
  4886. * @access public
  4887. */
  4888. function getOperations($portName = '', $bindingType = 'soap') {
  4889. $ops = array();
  4890. if ($bindingType == 'soap') {
  4891. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4892. } elseif ($bindingType == 'soap12') {
  4893. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
  4894. } else {
  4895. $this->debug("getOperations bindingType $bindingType may not be supported");
  4896. }
  4897. $this->debug("getOperations for port '$portName' bindingType $bindingType");
  4898. // loop thru ports
  4899. foreach($this->ports as $port => $portData) {
  4900. $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
  4901. if ($portName == '' || $port == $portName) {
  4902. // binding type of port matches parameter
  4903. if ($portData['bindingType'] == $bindingType) {
  4904. $this->debug("getOperations found port $port bindingType $bindingType");
  4905. //$this->debug("port data: " . $this->varDump($portData));
  4906. //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
  4907. // merge bindings
  4908. if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
  4909. $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
  4910. }
  4911. }
  4912. }
  4913. }
  4914. if (count($ops) == 0) {
  4915. $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
  4916. }
  4917. return $ops;
  4918. }
  4919. /**
  4920. * returns an associative array of data necessary for calling an operation
  4921. *
  4922. * @param string $operation name of operation
  4923. * @param string $bindingType type of binding eg: soap, soap12
  4924. * @return array
  4925. * @access public
  4926. */
  4927. function getOperationData($operation, $bindingType = 'soap')
  4928. {
  4929. if ($bindingType == 'soap') {
  4930. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4931. } elseif ($bindingType == 'soap12') {
  4932. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
  4933. }
  4934. // loop thru ports
  4935. foreach($this->ports as $port => $portData) {
  4936. // binding type of port matches parameter
  4937. if ($portData['bindingType'] == $bindingType) {
  4938. // get binding
  4939. //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
  4940. foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) {
  4941. // note that we could/should also check the namespace here
  4942. if ($operation == $bOperation) {
  4943. $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
  4944. return $opData;
  4945. }
  4946. }
  4947. }
  4948. }
  4949. }
  4950. /**
  4951. * returns an associative array of data necessary for calling an operation
  4952. *
  4953. * @param string $soapAction soapAction for operation
  4954. * @param string $bindingType type of binding eg: soap, soap12
  4955. * @return array
  4956. * @access public
  4957. */
  4958. function getOperationDataForSoapAction($soapAction, $bindingType = 'soap') {
  4959. if ($bindingType == 'soap') {
  4960. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4961. } elseif ($bindingType == 'soap12') {
  4962. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
  4963. }
  4964. // loop thru ports
  4965. foreach($this->ports as $port => $portData) {
  4966. // binding type of port matches parameter
  4967. if ($portData['bindingType'] == $bindingType) {
  4968. // loop through operations for the binding
  4969. foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
  4970. if ($opData['soapAction'] == $soapAction) {
  4971. return $opData;
  4972. }
  4973. }
  4974. }
  4975. }
  4976. }
  4977. /**
  4978. * returns an array of information about a given type
  4979. * returns false if no type exists by the given name
  4980. *
  4981. * typeDef = array(
  4982. * 'elements' => array(), // refs to elements array
  4983. * 'restrictionBase' => '',
  4984. * 'phpType' => '',
  4985. * 'order' => '(sequence|all)',
  4986. * 'attrs' => array() // refs to attributes array
  4987. * )
  4988. *
  4989. * @param string $type the type
  4990. * @param string $ns namespace (not prefix) of the type
  4991. * @return mixed
  4992. * @access public
  4993. * @see nusoap_xmlschema
  4994. */
  4995. function getTypeDef($type, $ns) {
  4996. $this->debug("in getTypeDef: type=$type, ns=$ns");
  4997. if ((! $ns) && isset($this->namespaces['tns'])) {
  4998. $ns = $this->namespaces['tns'];
  4999. $this->debug("in getTypeDef: type namespace forced to $ns");
  5000. }
  5001. if (!isset($this->schemas[$ns])) {
  5002. foreach ($this->schemas as $ns0 => $schema0) {
  5003. if (strcasecmp($ns, $ns0) == 0) {
  5004. $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
  5005. $ns = $ns0;
  5006. break;
  5007. }
  5008. }
  5009. }
  5010. if (isset($this->schemas[$ns])) {
  5011. $this->debug("in getTypeDef: have schema for namespace $ns");
  5012. for ($i = 0; $i < count($this->schemas[$ns]); $i++) {
  5013. $xs = &$this->schemas[$ns][$i];
  5014. $t = $xs->getTypeDef($type);
  5015. $this->appendDebug($xs->getDebug());
  5016. $xs->clearDebug();
  5017. if ($t) {
  5018. $this->debug("in getTypeDef: found type $type");
  5019. if (!isset($t['phpType'])) {
  5020. // get info for type to tack onto the element
  5021. $uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
  5022. $ns = substr($t['type'], 0, strrpos($t['type'], ':'));
  5023. $etype = $this->getTypeDef($uqType, $ns);
  5024. if ($etype) {
  5025. $this->debug("found type for [element] $type:");
  5026. $this->debug($this->varDump($etype));
  5027. if (isset($etype['phpType'])) {
  5028. $t['phpType'] = $etype['phpType'];
  5029. }
  5030. if (isset($etype['elements'])) {
  5031. $t['elements'] = $etype['elements'];
  5032. }
  5033. if (isset($etype['attrs'])) {
  5034. $t['attrs'] = $etype['attrs'];
  5035. }
  5036. } else {
  5037. $this->debug("did not find type for [element] $type");
  5038. }
  5039. }
  5040. return $t;
  5041. }
  5042. }
  5043. $this->debug("in getTypeDef: did not find type $type");
  5044. } else {
  5045. $this->debug("in getTypeDef: do not have schema for namespace $ns");
  5046. }
  5047. return false;
  5048. }
  5049. /**
  5050. * prints html description of services
  5051. *
  5052. * @access private
  5053. */
  5054. function webDescription(){
  5055. global $HTTP_SERVER_VARS;
  5056. if (isset($_SERVER)) {
  5057. $PHP_SELF = $_SERVER['PHP_SELF'];
  5058. } elseif (isset($HTTP_SERVER_VARS)) {
  5059. $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
  5060. } else {
  5061. $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
  5062. }
  5063. $b = '
  5064. <html><head><title>NuSOAP: '.$this->serviceName.'</title>
  5065. <style type="text/css">
  5066. body { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
  5067. p { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
  5068. pre { background-color: silver; padding: 5px; font-family: Courier New; font-size: x-small; color: #000000;}
  5069. ul { margin-top: 10px; margin-left: 20px; }
  5070. li { list-style-type: none; margin-top: 10px; color: #000000; }
  5071. .content{
  5072. margin-left: 0px; padding-bottom: 2em; }
  5073. .nav {
  5074. padding-top: 10px; padding-bottom: 10px; padding-left: 15px; font-size: .70em;
  5075. margin-top: 10px; margin-left: 0px; color: #000000;
  5076. background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
  5077. .title {
  5078. font-family: arial; font-size: 26px; color: #ffffff;
  5079. background-color: #999999; width: 100%;
  5080. margin-left: 0px; margin-right: 0px;
  5081. padding-top: 10px; padding-bottom: 10px;}
  5082. .hidden {
  5083. position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
  5084. font-family: arial; overflow: hidden; width: 600;
  5085. padding: 20px; font-size: 10px; background-color: #999999;
  5086. layer-background-color:#FFFFFF; }
  5087. a,a:active { color: charcoal; font-weight: bold; }
  5088. a:visited { color: #666666; font-weight: bold; }
  5089. a:hover { color: cc3300; font-weight: bold; }
  5090. </style>
  5091. <script language="JavaScript" type="text/javascript">
  5092. <!--
  5093. // POP-UP CAPTIONS...
  5094. function lib_bwcheck(){ //Browsercheck (needed)
  5095. this.ver=navigator.appVersion
  5096. this.agent=navigator.userAgent
  5097. this.dom=document.getElementById?1:0
  5098. this.opera5=this.agent.indexOf("Opera 5")>-1
  5099. this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  5100. this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  5101. this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  5102. this.ie=this.ie4||this.ie5||this.ie6
  5103. this.mac=this.agent.indexOf("Mac")>-1
  5104. this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  5105. this.ns4=(document.layers && !this.dom)?1:0;
  5106. this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
  5107. return this
  5108. }
  5109. var bw = new lib_bwcheck()
  5110. //Makes crossbrowser object.
  5111. function makeObj(obj){
  5112. this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
  5113. if(!this.evnt) return false
  5114. this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
  5115. this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
  5116. this.writeIt=b_writeIt;
  5117. return this
  5118. }
  5119. // A unit of measure that will be added when setting the position of a layer.
  5120. //var px = bw.ns4||window.opera?"":"px";
  5121. function b_writeIt(text){
  5122. if (bw.ns4){this.wref.write(text);this.wref.close()}
  5123. else this.wref.innerHTML = text
  5124. }
  5125. //Shows the messages
  5126. var oDesc;
  5127. function popup(divid){
  5128. if(oDesc = new makeObj(divid)){
  5129. oDesc.css.visibility = "visible"
  5130. }
  5131. }
  5132. function popout(){ // Hides message
  5133. if(oDesc) oDesc.css.visibility = "hidden"
  5134. }
  5135. //-->
  5136. </script>
  5137. </head>
  5138. <body>
  5139. <div class=content>
  5140. <br><br>
  5141. <div class=title>'.$this->serviceName.'</div>
  5142. <div class=nav>
  5143. <p>View the <a href="'.$PHP_SELF.'?wsdl">WSDL</a> for the service.
  5144. Click on an operation name to view it&apos;s details.</p>
  5145. <ul>';
  5146. foreach($this->getOperations() as $op => $data){
  5147. $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
  5148. // create hidden div
  5149. $b .= "<div id='$op' class='hidden'>
  5150. <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
  5151. foreach($data as $donnie => $marie){ // loop through opdata
  5152. if($donnie == 'input' || $donnie == 'output'){ // show input/output data
  5153. $b .= "<font color='white'>".ucfirst($donnie).':</font><br>';
  5154. foreach($marie as $captain => $tenille){ // loop through data
  5155. if($captain == 'parts'){ // loop thru parts
  5156. $b .= "&nbsp;&nbsp;$captain:<br>";
  5157. //if(is_array($tenille)){
  5158. foreach($tenille as $joanie => $chachi){
  5159. $b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
  5160. }
  5161. //}
  5162. } else {
  5163. $b .= "&nbsp;&nbsp;$captain: $tenille<br>";
  5164. }
  5165. }
  5166. } else {
  5167. $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>";
  5168. }
  5169. }
  5170. $b .= '</div>';
  5171. }
  5172. $b .= '
  5173. <ul>
  5174. </div>
  5175. </div></body></html>';
  5176. return $b;
  5177. }
  5178. /**
  5179. * serialize the parsed wsdl
  5180. *
  5181. * @param mixed $debug whether to put debug=1 in endpoint URL
  5182. * @return string serialization of WSDL
  5183. * @access public
  5184. */
  5185. function serialize($debug = 0)
  5186. {
  5187. /* $xml = '<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>';*/
  5188. $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  5189. $xml .= "\n<definitions";
  5190. foreach($this->namespaces as $k => $v) {
  5191. $xml .= " xmlns:$k=\"$v\"";
  5192. }
  5193. // 10.9.02 - add poulter fix for wsdl and tns declarations
  5194. if (isset($this->namespaces['wsdl'])) {
  5195. $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
  5196. }
  5197. if (isset($this->namespaces['tns'])) {
  5198. $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
  5199. }
  5200. $xml .= '>';
  5201. // imports
  5202. if (sizeof($this->import) > 0) {
  5203. foreach($this->import as $ns => $list) {
  5204. foreach ($list as $ii) {
  5205. if ($ii['location'] != '') {
  5206. $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
  5207. } else {
  5208. $xml .= '<import namespace="' . $ns . '" />';
  5209. }
  5210. }
  5211. }
  5212. }
  5213. // types
  5214. if (count($this->schemas)>=1) {
  5215. $xml .= "\n<types>\n";
  5216. foreach ($this->schemas as $ns => $list) {
  5217. foreach ($list as $xs) {
  5218. $xml .= $xs->serializeSchema();
  5219. }
  5220. }
  5221. $xml .= '</types>';
  5222. }
  5223. // messages
  5224. if (count($this->messages) >= 1) {
  5225. foreach($this->messages as $msgName => $msgParts) {
  5226. $xml .= "\n<message name=\"" . $msgName . '">';
  5227. if(is_array($msgParts)){
  5228. foreach($msgParts as $partName => $partType) {
  5229. // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
  5230. if (strpos($partType, ':')) {
  5231. $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
  5232. } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
  5233. // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
  5234. $typePrefix = 'xsd';
  5235. } else {
  5236. foreach($this->typemap as $ns => $types) {
  5237. if (isset($types[$partType])) {
  5238. $typePrefix = $this->getPrefixFromNamespace($ns);
  5239. }
  5240. }
  5241. if (!isset($typePrefix)) {
  5242. die("$partType has no namespace!");
  5243. }
  5244. }
  5245. $ns = $this->getNamespaceFromPrefix($typePrefix);
  5246. $localPart = $this->getLocalPart($partType);
  5247. $typeDef = $this->getTypeDef($localPart, $ns);
  5248. if ($typeDef['typeClass'] == 'element') {
  5249. $elementortype = 'element';
  5250. if (substr($localPart, -1) == '^') {
  5251. $localPart = substr($localPart, 0, -1);
  5252. }
  5253. } else {
  5254. $elementortype = 'type';
  5255. }
  5256. $xml .= "\n" . ' <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
  5257. }
  5258. }
  5259. $xml .= '</message>';
  5260. }
  5261. }
  5262. // bindings & porttypes
  5263. if (count($this->bindings) >= 1) {
  5264. $binding_xml = '';
  5265. $portType_xml = '';
  5266. foreach($this->bindings as $bindingName => $attrs) {
  5267. $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
  5268. $binding_xml .= "\n" . ' <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
  5269. $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
  5270. foreach($attrs['operations'] as $opName => $opParts) {
  5271. $binding_xml .= "\n" . ' <operation name="' . $opName . '">';
  5272. $binding_xml .= "\n" . ' <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>';
  5273. if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
  5274. $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
  5275. } else {
  5276. $enc_style = '';
  5277. }
  5278. $binding_xml .= "\n" . ' <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
  5279. if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
  5280. $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
  5281. } else {
  5282. $enc_style = '';
  5283. }
  5284. $binding_xml .= "\n" . ' <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
  5285. $binding_xml .= "\n" . ' </operation>';
  5286. $portType_xml .= "\n" . ' <operation name="' . $opParts['name'] . '"';
  5287. if (isset($opParts['parameterOrder'])) {
  5288. $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
  5289. }
  5290. $portType_xml .= '>';
  5291. if(isset($opParts['documentation']) && $opParts['documentation'] != '') {
  5292. $portType_xml .= "\n" . ' <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
  5293. }
  5294. $portType_xml .= "\n" . ' <input message="tns:' . $opParts['input']['message'] . '"/>';
  5295. $portType_xml .= "\n" . ' <output message="tns:' . $opParts['output']['message'] . '"/>';
  5296. $portType_xml .= "\n" . ' </operation>';
  5297. }
  5298. $portType_xml .= "\n" . '</portType>';
  5299. $binding_xml .= "\n" . '</binding>';
  5300. }
  5301. $xml .= $portType_xml . $binding_xml;
  5302. }
  5303. // services
  5304. $xml .= "\n<service name=\"" . $this->serviceName . '">';
  5305. if (count($this->ports) >= 1) {
  5306. foreach($this->ports as $pName => $attrs) {
  5307. $xml .= "\n" . ' <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
  5308. $xml .= "\n" . ' <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
  5309. $xml .= "\n" . ' </port>';
  5310. }
  5311. }
  5312. $xml .= "\n" . '</service>';
  5313. return $xml . "\n</definitions>";
  5314. }
  5315. /**
  5316. * determine whether a set of parameters are unwrapped
  5317. * when they are expect to be wrapped, Microsoft-style.
  5318. *
  5319. * @param string $type the type (element name) of the wrapper
  5320. * @param array $parameters the parameter values for the SOAP call
  5321. * @return boolean whether they parameters are unwrapped (and should be wrapped)
  5322. * @access private
  5323. */
  5324. function parametersMatchWrapped($type, &$parameters) {
  5325. $this->debug("in parametersMatchWrapped type=$type, parameters=");
  5326. $this->appendDebug($this->varDump($parameters));
  5327. // split type into namespace:unqualified-type
  5328. if (strpos($type, ':')) {
  5329. $uqType = substr($type, strrpos($type, ':') + 1);
  5330. $ns = substr($type, 0, strrpos($type, ':'));
  5331. $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
  5332. if ($this->getNamespaceFromPrefix($ns)) {
  5333. $ns = $this->getNamespaceFromPrefix($ns);
  5334. $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
  5335. }
  5336. } else {
  5337. // TODO: should the type be compared to types in XSD, and the namespace
  5338. // set to XSD if the type matches?
  5339. $this->debug("in parametersMatchWrapped: No namespace for type $type");
  5340. $ns = '';
  5341. $uqType = $type;
  5342. }
  5343. // get the type information
  5344. if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
  5345. $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
  5346. return false;
  5347. }
  5348. $this->debug("in parametersMatchWrapped: found typeDef=");
  5349. $this->appendDebug($this->varDump($typeDef));
  5350. if (substr($uqType, -1) == '^') {
  5351. $uqType = substr($uqType, 0, -1);
  5352. }
  5353. $phpType = $typeDef['phpType'];
  5354. $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
  5355. $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
  5356. // we expect a complexType or element of complexType
  5357. if ($phpType != 'struct') {
  5358. $this->debug("in parametersMatchWrapped: not a struct");
  5359. return false;
  5360. }
  5361. // see whether the parameter names match the elements
  5362. if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
  5363. $elements = 0;
  5364. $matches = 0;
  5365. foreach ($typeDef['elements'] as $name => $attrs) {
  5366. if (isset($parameters[$name])) {
  5367. $this->debug("in parametersMatchWrapped: have parameter named $name");
  5368. $matches++;
  5369. } else {
  5370. $this->debug("in parametersMatchWrapped: do not have parameter named $name");
  5371. }
  5372. $elements++;
  5373. }
  5374. $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
  5375. if ($matches == 0) {
  5376. return false;
  5377. }
  5378. return true;
  5379. }
  5380. // since there are no elements for the type, if the user passed no
  5381. // parameters, the parameters match wrapped.
  5382. $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
  5383. return count($parameters) == 0;
  5384. }
  5385. /**
  5386. * serialize PHP values according to a WSDL message definition
  5387. * contrary to the method name, this is not limited to RPC
  5388. *
  5389. * TODO
  5390. * - multi-ref serialization
  5391. * - validate PHP values against type definitions, return errors if invalid
  5392. *
  5393. * @param string $operation operation name
  5394. * @param string $direction (input|output)
  5395. * @param mixed $parameters parameter value(s)
  5396. * @param string $bindingType (soap|soap12)
  5397. * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
  5398. * @access public
  5399. */
  5400. function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') {
  5401. $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
  5402. $this->appendDebug('parameters=' . $this->varDump($parameters));
  5403. if ($direction != 'input' && $direction != 'output') {
  5404. $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
  5405. $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
  5406. return false;
  5407. }
  5408. if (!$opData = $this->getOperationData($operation, $bindingType)) {
  5409. $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
  5410. $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
  5411. return false;
  5412. }
  5413. $this->debug('in serializeRPCParameters: opData:');
  5414. $this->appendDebug($this->varDump($opData));
  5415. // Get encoding style for output and set to current
  5416. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  5417. if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
  5418. $encodingStyle = $opData['output']['encodingStyle'];
  5419. $enc_style = $encodingStyle;
  5420. }
  5421. // set input params
  5422. $xml = '';
  5423. if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
  5424. $parts = &$opData[$direction]['parts'];
  5425. $part_count = sizeof($parts);
  5426. $style = $opData['style'];
  5427. $use = $opData[$direction]['use'];
  5428. $this->debug("have $part_count part(s) to serialize using $style/$use");
  5429. if (is_array($parameters)) {
  5430. $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
  5431. $parameter_count = count($parameters);
  5432. $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
  5433. // check for Microsoft-style wrapped parameters
  5434. if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) {
  5435. $this->debug('check whether the caller has wrapped the parameters');
  5436. if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) {
  5437. // TODO: consider checking here for double-wrapping, when
  5438. // service function wraps, then NuSOAP wraps again
  5439. $this->debug("change simple array to associative with 'parameters' element");
  5440. $parameters['parameters'] = $parameters[0];
  5441. unset($parameters[0]);
  5442. }
  5443. if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) {
  5444. $this->debug('check whether caller\'s parameters match the wrapped ones');
  5445. if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
  5446. $this->debug('wrap the parameters for the caller');
  5447. $parameters = array('parameters' => $parameters);
  5448. $parameter_count = 1;
  5449. }
  5450. }
  5451. }
  5452. foreach ($parts as $name => $type) {
  5453. $this->debug("serializing part $name of type $type");
  5454. // Track encoding style
  5455. if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
  5456. $encodingStyle = $opData[$direction]['encodingStyle'];
  5457. $enc_style = $encodingStyle;
  5458. } else {
  5459. $enc_style = false;
  5460. }
  5461. // NOTE: add error handling here
  5462. // if serializeType returns false, then catch global error and fault
  5463. if ($parametersArrayType == 'arraySimple') {
  5464. $p = array_shift($parameters);
  5465. $this->debug('calling serializeType w/indexed param');
  5466. $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
  5467. } elseif (isset($parameters[$name])) {
  5468. $this->debug('calling serializeType w/named param');
  5469. $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
  5470. } else {
  5471. // TODO: only send nillable
  5472. $this->debug('calling serializeType w/null param');
  5473. $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
  5474. }
  5475. }
  5476. } else {
  5477. $this->debug('no parameters passed.');
  5478. }
  5479. }
  5480. $this->debug("serializeRPCParameters returning: $xml");
  5481. return $xml;
  5482. }
  5483. /**
  5484. * serialize a PHP value according to a WSDL message definition
  5485. *
  5486. * TODO
  5487. * - multi-ref serialization
  5488. * - validate PHP values against type definitions, return errors if invalid
  5489. *
  5490. * @param string $operation operation name
  5491. * @param string $direction (input|output)
  5492. * @param mixed $parameters parameter value(s)
  5493. * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
  5494. * @access public
  5495. * @deprecated
  5496. */
  5497. function serializeParameters($operation, $direction, $parameters)
  5498. {
  5499. $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
  5500. $this->appendDebug('parameters=' . $this->varDump($parameters));
  5501. if ($direction != 'input' && $direction != 'output') {
  5502. $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
  5503. $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
  5504. return false;
  5505. }
  5506. if (!$opData = $this->getOperationData($operation)) {
  5507. $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
  5508. $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
  5509. return false;
  5510. }
  5511. $this->debug('opData:');
  5512. $this->appendDebug($this->varDump($opData));
  5513. // Get encoding style for output and set to current
  5514. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  5515. if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
  5516. $encodingStyle = $opData['output']['encodingStyle'];
  5517. $enc_style = $encodingStyle;
  5518. }
  5519. // set input params
  5520. $xml = '';
  5521. if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
  5522. $use = $opData[$direction]['use'];
  5523. $this->debug("use=$use");
  5524. $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
  5525. if (is_array($parameters)) {
  5526. $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
  5527. $this->debug('have ' . $parametersArrayType . ' parameters');
  5528. foreach($opData[$direction]['parts'] as $name => $type) {
  5529. $this->debug('serializing part "'.$name.'" of type "'.$type.'"');
  5530. // Track encoding style
  5531. if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
  5532. $encodingStyle = $opData[$direction]['encodingStyle'];
  5533. $enc_style = $encodingStyle;
  5534. } else {
  5535. $enc_style = false;
  5536. }
  5537. // NOTE: add error handling here
  5538. // if serializeType returns false, then catch global error and fault
  5539. if ($parametersArrayType == 'arraySimple') {
  5540. $p = array_shift($parameters);
  5541. $this->debug('calling serializeType w/indexed param');
  5542. $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
  5543. } elseif (isset($parameters[$name])) {
  5544. $this->debug('calling serializeType w/named param');
  5545. $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
  5546. } else {
  5547. // TODO: only send nillable
  5548. $this->debug('calling serializeType w/null param');
  5549. $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
  5550. }
  5551. }
  5552. } else {
  5553. $this->debug('no parameters passed.');
  5554. }
  5555. }
  5556. $this->debug("serializeParameters returning: $xml");
  5557. return $xml;
  5558. }
  5559. /**
  5560. * serializes a PHP value according a given type definition
  5561. *
  5562. * @param string $name name of value (part or element)
  5563. * @param string $type XML schema type of value (type or element)
  5564. * @param mixed $value a native PHP value (parameter value)
  5565. * @param string $use use for part (encoded|literal)
  5566. * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
  5567. * @param boolean $unqualified a kludge for what should be XML namespace form handling
  5568. * @return string value serialized as an XML string
  5569. * @access private
  5570. */
  5571. function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false)
  5572. {
  5573. $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified"));
  5574. $this->appendDebug("value=" . $this->varDump($value));
  5575. if($use == 'encoded' && $encodingStyle) {
  5576. $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
  5577. }
  5578. // if a soapval has been supplied, let its type override the WSDL
  5579. if (is_object($value) && get_class($value) == 'soapval') {
  5580. if ($value->type_ns) {
  5581. $type = $value->type_ns . ':' . $value->type;
  5582. $forceType = true;
  5583. $this->debug("in serializeType: soapval overrides type to $type");
  5584. } elseif ($value->type) {
  5585. $type = $value->type;
  5586. $forceType = true;
  5587. $this->debug("in serializeType: soapval overrides type to $type");
  5588. } else {
  5589. $forceType = false;
  5590. $this->debug("in serializeType: soapval does not override type");
  5591. }
  5592. $attrs = $value->attributes;
  5593. $value = $value->value;
  5594. $this->debug("in serializeType: soapval overrides value to $value");
  5595. if ($attrs) {
  5596. if (!is_array($value)) {
  5597. $value['!'] = $value;
  5598. }
  5599. foreach ($attrs as $n => $v) {
  5600. $value['!' . $n] = $v;
  5601. }
  5602. $this->debug("in serializeType: soapval provides attributes");
  5603. }
  5604. } else {
  5605. $forceType = false;
  5606. }
  5607. $xml = '';
  5608. if (strpos($type, ':')) {
  5609. $uqType = substr($type, strrpos($type, ':') + 1);
  5610. $ns = substr($type, 0, strrpos($type, ':'));
  5611. $this->debug("in serializeType: got a prefixed type: $uqType, $ns");
  5612. if ($this->getNamespaceFromPrefix($ns)) {
  5613. $ns = $this->getNamespaceFromPrefix($ns);
  5614. $this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
  5615. }
  5616. if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){
  5617. $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
  5618. if ($unqualified && $use == 'literal') {
  5619. $elementNS = " xmlns=\"\"";
  5620. } else {
  5621. $elementNS = '';
  5622. }
  5623. if (is_null($value)) {
  5624. if ($use == 'literal') {
  5625. // TODO: depends on minOccurs
  5626. $xml = "<$name$elementNS/>";
  5627. } else {
  5628. // TODO: depends on nillable, which should be checked before calling this method
  5629. $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
  5630. }
  5631. $this->debug("in serializeType: returning: $xml");
  5632. return $xml;
  5633. }
  5634. if ($uqType == 'Array') {
  5635. // JBoss/Axis does this sometimes
  5636. return $this->serialize_val($value, $name, false, false, false, false, $use);
  5637. }
  5638. if ($uqType == 'boolean') {
  5639. if ((is_string($value) && $value == 'false') || (! $value)) {
  5640. $value = 'false';
  5641. } else {
  5642. $value = 'true';
  5643. }
  5644. }
  5645. if ($uqType == 'string' && gettype($value) == 'string') {
  5646. $value = $this->expandEntities($value);
  5647. }
  5648. if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') {
  5649. $value = sprintf("%.0lf", $value);
  5650. }
  5651. // it's a scalar
  5652. // TODO: what about null/nil values?
  5653. // check type isn't a custom type extending xmlschema namespace
  5654. if (!$this->getTypeDef($uqType, $ns)) {
  5655. if ($use == 'literal') {
  5656. if ($forceType) {
  5657. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
  5658. } else {
  5659. $xml = "<$name$elementNS>$value</$name>";
  5660. }
  5661. } else {
  5662. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
  5663. }
  5664. $this->debug("in serializeType: returning: $xml");
  5665. return $xml;
  5666. }
  5667. $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
  5668. } else if ($ns == 'http://xml.apache.org/xml-soap') {
  5669. $this->debug('in serializeType: appears to be Apache SOAP type');
  5670. if ($uqType == 'Map') {
  5671. $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
  5672. if (! $tt_prefix) {
  5673. $this->debug('in serializeType: Add namespace for Apache SOAP type');
  5674. $tt_prefix = 'ns' . rand(1000, 9999);
  5675. $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
  5676. // force this to be added to usedNamespaces
  5677. $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
  5678. }
  5679. $contents = '';
  5680. foreach($value as $k => $v) {
  5681. $this->debug("serializing map element: key $k, value $v");
  5682. $contents .= '<item>';
  5683. $contents .= $this->serialize_val($k,'key',false,false,false,false,$use);
  5684. $contents .= $this->serialize_val($v,'value',false,false,false,false,$use);
  5685. $contents .= '</item>';
  5686. }
  5687. if ($use == 'literal') {
  5688. if ($forceType) {
  5689. $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
  5690. } else {
  5691. $xml = "<$name>$contents</$name>";
  5692. }
  5693. } else {
  5694. $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
  5695. }
  5696. $this->debug("in serializeType: returning: $xml");
  5697. return $xml;
  5698. }
  5699. $this->debug('in serializeType: Apache SOAP type, but only support Map');
  5700. }
  5701. } else {
  5702. // TODO: should the type be compared to types in XSD, and the namespace
  5703. // set to XSD if the type matches?
  5704. $this->debug("in serializeType: No namespace for type $type");
  5705. $ns = '';
  5706. $uqType = $type;
  5707. }
  5708. if(!$typeDef = $this->getTypeDef($uqType, $ns)){
  5709. $this->setError("$type ($uqType) is not a supported type.");
  5710. $this->debug("in serializeType: $type ($uqType) is not a supported type.");
  5711. return false;
  5712. } else {
  5713. $this->debug("in serializeType: found typeDef");
  5714. $this->appendDebug('typeDef=' . $this->varDump($typeDef));
  5715. if (substr($uqType, -1) == '^') {
  5716. $uqType = substr($uqType, 0, -1);
  5717. }
  5718. }
  5719. if (!isset($typeDef['phpType'])) {
  5720. $this->setError("$type ($uqType) has no phpType.");
  5721. $this->debug("in serializeType: $type ($uqType) has no phpType.");
  5722. return false;
  5723. }
  5724. $phpType = $typeDef['phpType'];
  5725. $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') );
  5726. // if php type == struct, map value to the <all> element names
  5727. if ($phpType == 'struct') {
  5728. if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
  5729. $elementName = $uqType;
  5730. if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
  5731. $elementNS = " xmlns=\"$ns\"";
  5732. } else {
  5733. $elementNS = " xmlns=\"\"";
  5734. }
  5735. } else {
  5736. $elementName = $name;
  5737. if ($unqualified) {
  5738. $elementNS = " xmlns=\"\"";
  5739. } else {
  5740. $elementNS = '';
  5741. }
  5742. }
  5743. if (is_null($value)) {
  5744. if ($use == 'literal') {
  5745. // TODO: depends on minOccurs and nillable
  5746. $xml = "<$elementName$elementNS/>";
  5747. } else {
  5748. $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
  5749. }
  5750. $this->debug("in serializeType: returning: $xml");
  5751. return $xml;
  5752. }
  5753. if (is_object($value)) {
  5754. $value = get_object_vars($value);
  5755. }
  5756. if (is_array($value)) {
  5757. $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
  5758. if ($use == 'literal') {
  5759. if ($forceType) {
  5760. $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
  5761. } else {
  5762. $xml = "<$elementName$elementNS$elementAttrs>";
  5763. }
  5764. } else {
  5765. $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
  5766. }
  5767. if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') {
  5768. if (isset($value['!'])) {
  5769. $xml .= $value['!'];
  5770. $this->debug("in serializeType: serialized simpleContent for type $type");
  5771. } else {
  5772. $this->debug("in serializeType: no simpleContent to serialize for type $type");
  5773. }
  5774. } else {
  5775. // complexContent
  5776. $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
  5777. }
  5778. $xml .= "</$elementName>";
  5779. } else {
  5780. $this->debug("in serializeType: phpType is struct, but value is not an array");
  5781. $this->setError("phpType is struct, but value is not an array: see debug output for details");
  5782. $xml = '';
  5783. }
  5784. } elseif ($phpType == 'array') {
  5785. if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
  5786. $elementNS = " xmlns=\"$ns\"";
  5787. } else {
  5788. if ($unqualified) {
  5789. $elementNS = " xmlns=\"\"";
  5790. } else {
  5791. $elementNS = '';
  5792. }
  5793. }
  5794. if (is_null($value)) {
  5795. if ($use == 'literal') {
  5796. // TODO: depends on minOccurs
  5797. $xml = "<$name$elementNS/>";
  5798. } else {
  5799. $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
  5800. $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
  5801. ":Array\" " .
  5802. $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
  5803. ':arrayType="' .
  5804. $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
  5805. ':' .
  5806. $this->getLocalPart($typeDef['arrayType'])."[0]\"/>";
  5807. }
  5808. $this->debug("in serializeType: returning: $xml");
  5809. return $xml;
  5810. }
  5811. if (isset($typeDef['multidimensional'])) {
  5812. $nv = array();
  5813. foreach($value as $v) {
  5814. $cols = ',' . sizeof($v);
  5815. $nv = array_merge($nv, $v);
  5816. }
  5817. $value = $nv;
  5818. } else {
  5819. $cols = '';
  5820. }
  5821. if (is_array($value) && sizeof($value) >= 1) {
  5822. $rows = sizeof($value);
  5823. $contents = '';
  5824. foreach($value as $k => $v) {
  5825. $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
  5826. //if (strpos($typeDef['arrayType'], ':') ) {
  5827. if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
  5828. $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
  5829. } else {
  5830. $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
  5831. }
  5832. }
  5833. } else {
  5834. $rows = 0;
  5835. $contents = null;
  5836. }
  5837. // TODO: for now, an empty value will be serialized as a zero element
  5838. // array. Revisit this when coding the handling of null/nil values.
  5839. if ($use == 'literal') {
  5840. $xml = "<$name$elementNS>"
  5841. .$contents
  5842. ."</$name>";
  5843. } else {
  5844. $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '.
  5845. $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
  5846. .':arrayType="'
  5847. .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
  5848. .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">"
  5849. .$contents
  5850. ."</$name>";
  5851. }
  5852. } elseif ($phpType == 'scalar') {
  5853. if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
  5854. $elementNS = " xmlns=\"$ns\"";
  5855. } else {
  5856. if ($unqualified) {
  5857. $elementNS = " xmlns=\"\"";
  5858. } else {
  5859. $elementNS = '';
  5860. }
  5861. }
  5862. if ($use == 'literal') {
  5863. if ($forceType) {
  5864. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
  5865. } else {
  5866. $xml = "<$name$elementNS>$value</$name>";
  5867. }
  5868. } else {
  5869. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
  5870. }
  5871. }
  5872. $this->debug("in serializeType: returning: $xml");
  5873. return $xml;
  5874. }
  5875. /**
  5876. * serializes the attributes for a complexType
  5877. *
  5878. * @param array $typeDef our internal representation of an XML schema type (or element)
  5879. * @param mixed $value a native PHP value (parameter value)
  5880. * @param string $ns the namespace of the type
  5881. * @param string $uqType the local part of the type
  5882. * @return string value serialized as an XML string
  5883. * @access private
  5884. */
  5885. function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) {
  5886. $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
  5887. $xml = '';
  5888. if (isset($typeDef['extensionBase'])) {
  5889. $nsx = $this->getPrefix($typeDef['extensionBase']);
  5890. $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
  5891. if ($this->getNamespaceFromPrefix($nsx)) {
  5892. $nsx = $this->getNamespaceFromPrefix($nsx);
  5893. }
  5894. if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
  5895. $this->debug("serialize attributes for extension base $nsx:$uqTypex");
  5896. $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
  5897. } else {
  5898. $this->debug("extension base $nsx:$uqTypex is not a supported type");
  5899. }
  5900. }
  5901. if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
  5902. $this->debug("serialize attributes for XML Schema type $ns:$uqType");
  5903. if (is_array($value)) {
  5904. $xvalue = $value;
  5905. } elseif (is_object($value)) {
  5906. $xvalue = get_object_vars($value);
  5907. } else {
  5908. $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
  5909. $xvalue = array();
  5910. }
  5911. foreach ($typeDef['attrs'] as $aName => $attrs) {
  5912. if (isset($xvalue['!' . $aName])) {
  5913. $xname = '!' . $aName;
  5914. $this->debug("value provided for attribute $aName with key $xname");
  5915. } elseif (isset($xvalue[$aName])) {
  5916. $xname = $aName;
  5917. $this->debug("value provided for attribute $aName with key $xname");
  5918. } elseif (isset($attrs['default'])) {
  5919. $xname = '!' . $aName;
  5920. $xvalue[$xname] = $attrs['default'];
  5921. $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
  5922. } else {
  5923. $xname = '';
  5924. $this->debug("no value provided for attribute $aName");
  5925. }
  5926. if ($xname) {
  5927. $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
  5928. }
  5929. }
  5930. } else {
  5931. $this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
  5932. }
  5933. return $xml;
  5934. }
  5935. /**
  5936. * serializes the elements for a complexType
  5937. *
  5938. * @param array $typeDef our internal representation of an XML schema type (or element)
  5939. * @param mixed $value a native PHP value (parameter value)
  5940. * @param string $ns the namespace of the type
  5941. * @param string $uqType the local part of the type
  5942. * @param string $use use for part (encoded|literal)
  5943. * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
  5944. * @return string value serialized as an XML string
  5945. * @access private
  5946. */
  5947. function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) {
  5948. $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
  5949. $xml = '';
  5950. if (isset($typeDef['extensionBase'])) {
  5951. $nsx = $this->getPrefix($typeDef['extensionBase']);
  5952. $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
  5953. if ($this->getNamespaceFromPrefix($nsx)) {
  5954. $nsx = $this->getNamespaceFromPrefix($nsx);
  5955. }
  5956. if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
  5957. $this->debug("serialize elements for extension base $nsx:$uqTypex");
  5958. $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
  5959. } else {
  5960. $this->debug("extension base $nsx:$uqTypex is not a supported type");
  5961. }
  5962. }
  5963. if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
  5964. $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
  5965. if (is_array($value)) {
  5966. $xvalue = $value;
  5967. } elseif (is_object($value)) {
  5968. $xvalue = get_object_vars($value);
  5969. } else {
  5970. $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
  5971. $xvalue = array();
  5972. }
  5973. // toggle whether all elements are present - ideally should validate against schema
  5974. if (count($typeDef['elements']) != count($xvalue)){
  5975. $optionals = true;
  5976. }
  5977. foreach ($typeDef['elements'] as $eName => $attrs) {
  5978. if (!isset($xvalue[$eName])) {
  5979. if (isset($attrs['default'])) {
  5980. $xvalue[$eName] = $attrs['default'];
  5981. $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
  5982. }
  5983. }
  5984. // if user took advantage of a minOccurs=0, then only serialize named parameters
  5985. if (isset($optionals)
  5986. && (!isset($xvalue[$eName]))
  5987. && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
  5988. ){
  5989. if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
  5990. $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
  5991. }
  5992. // do nothing
  5993. $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
  5994. } else {
  5995. // get value
  5996. if (isset($xvalue[$eName])) {
  5997. $v = $xvalue[$eName];
  5998. } else {
  5999. $v = null;
  6000. }
  6001. if (isset($attrs['form'])) {
  6002. $unqualified = ($attrs['form'] == 'unqualified');
  6003. } else {
  6004. $unqualified = false;
  6005. }
  6006. if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
  6007. $vv = $v;
  6008. foreach ($vv as $k => $v) {
  6009. if (isset($attrs['type']) || isset($attrs['ref'])) {
  6010. // serialize schema-defined type
  6011. $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
  6012. } else {
  6013. // serialize generic type (can this ever really happen?)
  6014. $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
  6015. $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
  6016. }
  6017. }
  6018. } else {
  6019. if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') {
  6020. // do nothing
  6021. } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') {
  6022. // TODO: serialize a nil correctly, but for now serialize schema-defined type
  6023. $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
  6024. } elseif (isset($attrs['type']) || isset($attrs['ref'])) {
  6025. // serialize schema-defined type
  6026. $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
  6027. } else {
  6028. // serialize generic type (can this ever really happen?)
  6029. $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
  6030. $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
  6031. }
  6032. }
  6033. }
  6034. }
  6035. } else {
  6036. $this->debug("no elements to serialize for XML Schema type $ns:$uqType");
  6037. }
  6038. return $xml;
  6039. }
  6040. /**
  6041. * adds an XML Schema complex type to the WSDL types
  6042. *
  6043. * @param string $name
  6044. * @param string $typeClass (complexType|simpleType|attribute)
  6045. * @param string $phpType currently supported are array and struct (php assoc array)
  6046. * @param string $compositor (all|sequence|choice)
  6047. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  6048. * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
  6049. * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
  6050. * @param string $arrayType as namespace:name (xsd:string)
  6051. * @see nusoap_xmlschema
  6052. * @access public
  6053. */
  6054. function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
  6055. if (count($elements) > 0) {
  6056. $eElements = array();
  6057. foreach($elements as $n => $e){
  6058. // expand each element
  6059. $ee = array();
  6060. if (is_array($e) && count($e)>0) {
  6061. foreach ($e as $k => $v) {
  6062. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  6063. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  6064. $ee[$k] = $v;
  6065. }
  6066. $eElements[$n] = $ee;
  6067. }
  6068. }
  6069. $elements = $eElements;
  6070. }
  6071. if (count($attrs) > 0) {
  6072. foreach($attrs as $n => $a){
  6073. // expand each attribute
  6074. foreach ($a as $k => $v) {
  6075. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  6076. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  6077. $aa[$k] = $v;
  6078. }
  6079. $eAttrs[$n] = $aa;
  6080. }
  6081. $attrs = $eAttrs;
  6082. }
  6083. $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
  6084. $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType;
  6085. $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
  6086. $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
  6087. }
  6088. /**
  6089. * adds an XML Schema simple type to the WSDL types
  6090. *
  6091. * @param string $name
  6092. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  6093. * @param string $typeClass (should always be simpleType)
  6094. * @param string $phpType (should always be scalar)
  6095. * @param array $enumeration array of values
  6096. * @see nusoap_xmlschema
  6097. * @access public
  6098. */
  6099. function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
  6100. $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
  6101. $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
  6102. $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
  6103. }
  6104. /**
  6105. * adds an element to the WSDL types
  6106. *
  6107. * @param array $attrs attributes that must include name and type
  6108. * @see nusoap_xmlschema
  6109. * @access public
  6110. */
  6111. function addElement($attrs) {
  6112. $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
  6113. $this->schemas[$typens][0]->addElement($attrs);
  6114. }
  6115. /**
  6116. * register an operation with the server
  6117. *
  6118. * @param string $name operation (method) name
  6119. * @param array $in assoc array of input values: key = param name, value = param type
  6120. * @param array $out assoc array of output values: key = param name, value = param type
  6121. * @param string $namespace optional The namespace for the operation
  6122. * @param string $soapaction optional The soapaction for the operation
  6123. * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically
  6124. * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
  6125. * @param string $documentation optional The description to include in the WSDL
  6126. * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
  6127. * @access public
  6128. */
  6129. function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){
  6130. if ($use == 'encoded' && $encodingStyle == '') {
  6131. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  6132. }
  6133. if ($style == 'document') {
  6134. $elements = array();
  6135. foreach ($in as $n => $t) {
  6136. $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
  6137. }
  6138. $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
  6139. $this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
  6140. $in = array('parameters' => 'tns:' . $name . '^');
  6141. $elements = array();
  6142. foreach ($out as $n => $t) {
  6143. $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
  6144. }
  6145. $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
  6146. $this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified'));
  6147. $out = array('parameters' => 'tns:' . $name . 'Response' . '^');
  6148. }
  6149. // get binding
  6150. $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] =
  6151. array(
  6152. 'name' => $name,
  6153. 'binding' => $this->serviceName . 'Binding',
  6154. 'endpoint' => $this->endpoint,
  6155. 'soapAction' => $soapaction,
  6156. 'style' => $style,
  6157. 'input' => array(
  6158. 'use' => $use,
  6159. 'namespace' => $namespace,
  6160. 'encodingStyle' => $encodingStyle,
  6161. 'message' => $name . 'Request',
  6162. 'parts' => $in),
  6163. 'output' => array(
  6164. 'use' => $use,
  6165. 'namespace' => $namespace,
  6166. 'encodingStyle' => $encodingStyle,
  6167. 'message' => $name . 'Response',
  6168. 'parts' => $out),
  6169. 'namespace' => $namespace,
  6170. 'transport' => 'http://schemas.xmlsoap.org/soap/http',
  6171. 'documentation' => $documentation);
  6172. // add portTypes
  6173. // add messages
  6174. if($in)
  6175. {
  6176. foreach($in as $pName => $pType)
  6177. {
  6178. if(strpos($pType,':')) {
  6179. $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
  6180. }
  6181. $this->messages[$name.'Request'][$pName] = $pType;
  6182. }
  6183. } else {
  6184. $this->messages[$name.'Request']= '0';
  6185. }
  6186. if($out)
  6187. {
  6188. foreach($out as $pName => $pType)
  6189. {
  6190. if(strpos($pType,':')) {
  6191. $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
  6192. }
  6193. $this->messages[$name.'Response'][$pName] = $pType;
  6194. }
  6195. } else {
  6196. $this->messages[$name.'Response']= '0';
  6197. }
  6198. return true;
  6199. }
  6200. }
  6201. ?><?php
  6202. /**
  6203. *
  6204. * nusoap_parser class parses SOAP XML messages into native PHP values
  6205. *
  6206. * @author Dietrich Ayala <dietrich@ganx4.com>
  6207. * @author Scott Nichol <snichol@users.sourceforge.net>
  6208. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  6209. * @access public
  6210. */
  6211. class nusoap_parser extends nusoap_base {
  6212. var $xml = '';
  6213. var $xml_encoding = '';
  6214. var $method = '';
  6215. var $root_struct = '';
  6216. var $root_struct_name = '';
  6217. var $root_struct_namespace = '';
  6218. var $root_header = '';
  6219. var $document = ''; // incoming SOAP body (text)
  6220. // determines where in the message we are (envelope,header,body,method)
  6221. var $status = '';
  6222. var $position = 0;
  6223. var $depth = 0;
  6224. var $default_namespace = '';
  6225. var $namespaces = array();
  6226. var $message = array();
  6227. var $parent = '';
  6228. var $fault = false;
  6229. var $fault_code = '';
  6230. var $fault_str = '';
  6231. var $fault_detail = '';
  6232. var $depth_array = array();
  6233. var $debug_flag = true;
  6234. var $soapresponse = NULL; // parsed SOAP Body
  6235. var $soapheader = NULL; // parsed SOAP Header
  6236. var $responseHeaders = ''; // incoming SOAP headers (text)
  6237. var $body_position = 0;
  6238. // for multiref parsing:
  6239. // array of id => pos
  6240. var $ids = array();
  6241. // array of id => hrefs => pos
  6242. var $multirefs = array();
  6243. // toggle for auto-decoding element content
  6244. var $decode_utf8 = true;
  6245. /**
  6246. * constructor that actually does the parsing
  6247. *
  6248. * @param string $xml SOAP message
  6249. * @param string $encoding character encoding scheme of message
  6250. * @param string $method method for which XML is parsed (unused?)
  6251. * @param string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
  6252. * @access public
  6253. */
  6254. function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
  6255. parent::nusoap_base();
  6256. $this->xml = $xml;
  6257. $this->xml_encoding = $encoding;
  6258. $this->method = $method;
  6259. $this->decode_utf8 = $decode_utf8;
  6260. // Check whether content has been read.
  6261. if(!empty($xml)){
  6262. // Check XML encoding
  6263. $pos_xml = strpos($xml, '<?xml');
  6264. if ($pos_xml !== FALSE) {
  6265. $xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
  6266. if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
  6267. $xml_encoding = $res[1];
  6268. if (strtoupper($xml_encoding) != $encoding) {
  6269. $err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
  6270. $this->debug($err);
  6271. if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
  6272. $this->setError($err);
  6273. return;
  6274. }
  6275. // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
  6276. } else {
  6277. $this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
  6278. }
  6279. } else {
  6280. $this->debug('No encoding specified in XML declaration');
  6281. }
  6282. } else {
  6283. $this->debug('No XML declaration');
  6284. }
  6285. $this->debug('Entering nusoap_parser(), length='.strlen($xml).', encoding='.$encoding);
  6286. // Create an XML parser - why not xml_parser_create_ns?
  6287. $this->parser = xml_parser_create($this->xml_encoding);
  6288. // Set the options for parsing the XML data.
  6289. //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  6290. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  6291. xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
  6292. // Set the object for the parser.
  6293. xml_set_object($this->parser, $this);
  6294. // Set the element handlers for the parser.
  6295. xml_set_element_handler($this->parser, 'start_element','end_element');
  6296. xml_set_character_data_handler($this->parser,'character_data');
  6297. // Parse the XML file.
  6298. if(!xml_parse($this->parser,$xml,true)){
  6299. // Display an error message.
  6300. $err = sprintf('XML error parsing SOAP payload on line %d: %s',
  6301. xml_get_current_line_number($this->parser),
  6302. xml_error_string(xml_get_error_code($this->parser)));
  6303. $this->debug($err);
  6304. $this->debug("XML payload:\n" . $xml);
  6305. $this->setError($err);
  6306. } else {
  6307. $this->debug('in nusoap_parser ctor, message:');
  6308. $this->appendDebug($this->varDump($this->message));
  6309. $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
  6310. // get final value
  6311. $this->soapresponse = $this->message[$this->root_struct]['result'];
  6312. // get header value
  6313. if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){
  6314. $this->soapheader = $this->message[$this->root_header]['result'];
  6315. }
  6316. // resolve hrefs/ids
  6317. if(sizeof($this->multirefs) > 0){
  6318. foreach($this->multirefs as $id => $hrefs){
  6319. $this->debug('resolving multirefs for id: '.$id);
  6320. $idVal = $this->buildVal($this->ids[$id]);
  6321. if (is_array($idVal) && isset($idVal['!id'])) {
  6322. unset($idVal['!id']);
  6323. }
  6324. foreach($hrefs as $refPos => $ref){
  6325. $this->debug('resolving href at pos '.$refPos);
  6326. $this->multirefs[$id][$refPos] = $idVal;
  6327. }
  6328. }
  6329. }
  6330. }
  6331. xml_parser_free($this->parser);
  6332. } else {
  6333. $this->debug('xml was empty, didn\'t parse!');
  6334. $this->setError('xml was empty, didn\'t parse!');
  6335. }
  6336. }
  6337. /**
  6338. * start-element handler
  6339. *
  6340. * @param resource $parser XML parser object
  6341. * @param string $name element name
  6342. * @param array $attrs associative array of attributes
  6343. * @access private
  6344. */
  6345. function start_element($parser, $name, $attrs) {
  6346. // position in a total number of elements, starting from 0
  6347. // update class level pos
  6348. $pos = $this->position++;
  6349. // and set mine
  6350. $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>'');
  6351. // depth = how many levels removed from root?
  6352. // set mine as current global depth and increment global depth value
  6353. $this->message[$pos]['depth'] = $this->depth++;
  6354. // else add self as child to whoever the current parent is
  6355. if($pos != 0){
  6356. $this->message[$this->parent]['children'] .= '|'.$pos;
  6357. }
  6358. // set my parent
  6359. $this->message[$pos]['parent'] = $this->parent;
  6360. // set self as current parent
  6361. $this->parent = $pos;
  6362. // set self as current value for this depth
  6363. $this->depth_array[$this->depth] = $pos;
  6364. // get element prefix
  6365. if(strpos($name,':')){
  6366. // get ns prefix
  6367. $prefix = substr($name,0,strpos($name,':'));
  6368. // get unqualified name
  6369. $name = substr(strstr($name,':'),1);
  6370. }
  6371. // set status
  6372. if ($name == 'Envelope' && $this->status == '') {
  6373. $this->status = 'envelope';
  6374. } elseif ($name == 'Header' && $this->status == 'envelope') {
  6375. $this->root_header = $pos;
  6376. $this->status = 'header';
  6377. } elseif ($name == 'Body' && $this->status == 'envelope'){
  6378. $this->status = 'body';
  6379. $this->body_position = $pos;
  6380. // set method
  6381. } elseif($this->status == 'body' && $pos == ($this->body_position+1)) {
  6382. $this->status = 'method';
  6383. $this->root_struct_name = $name;
  6384. $this->root_struct = $pos;
  6385. $this->message[$pos]['type'] = 'struct';
  6386. $this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
  6387. }
  6388. // set my status
  6389. $this->message[$pos]['status'] = $this->status;
  6390. // set name
  6391. $this->message[$pos]['name'] = htmlspecialchars($name);
  6392. // set attrs
  6393. $this->message[$pos]['attrs'] = $attrs;
  6394. // loop through atts, logging ns and type declarations
  6395. $attstr = '';
  6396. foreach($attrs as $key => $value){
  6397. $key_prefix = $this->getPrefix($key);
  6398. $key_localpart = $this->getLocalPart($key);
  6399. // if ns declarations, add to class level array of valid namespaces
  6400. if($key_prefix == 'xmlns'){
  6401. if(preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/',$value)){
  6402. $this->XMLSchemaVersion = $value;
  6403. $this->namespaces['xsd'] = $this->XMLSchemaVersion;
  6404. $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance';
  6405. }
  6406. $this->namespaces[$key_localpart] = $value;
  6407. // set method namespace
  6408. if($name == $this->root_struct_name){
  6409. $this->methodNamespace = $value;
  6410. }
  6411. // if it's a type declaration, set type
  6412. } elseif($key_localpart == 'type'){
  6413. if (isset($this->message[$pos]['type']) && $this->message[$pos]['type'] == 'array') {
  6414. // do nothing: already processed arrayType
  6415. } else {
  6416. $value_prefix = $this->getPrefix($value);
  6417. $value_localpart = $this->getLocalPart($value);
  6418. $this->message[$pos]['type'] = $value_localpart;
  6419. $this->message[$pos]['typePrefix'] = $value_prefix;
  6420. if(isset($this->namespaces[$value_prefix])){
  6421. $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
  6422. } else if(isset($attrs['xmlns:'.$value_prefix])) {
  6423. $this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix];
  6424. }
  6425. // should do something here with the namespace of specified type?
  6426. }
  6427. } elseif($key_localpart == 'arrayType'){
  6428. $this->message[$pos]['type'] = 'array';
  6429. /* do arrayType ereg here
  6430. [1] arrayTypeValue ::= atype asize
  6431. [2] atype ::= QName rank*
  6432. [3] rank ::= '[' (',')* ']'
  6433. [4] asize ::= '[' length~ ']'
  6434. [5] length ::= nextDimension* Digit+
  6435. [6] nextDimension ::= Digit+ ','
  6436. */
  6437. $expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
  6438. if(preg_match($expr,$value,$regs)){
  6439. $this->message[$pos]['typePrefix'] = $regs[1];
  6440. $this->message[$pos]['arrayTypePrefix'] = $regs[1];
  6441. if (isset($this->namespaces[$regs[1]])) {
  6442. $this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
  6443. } else if (isset($attrs['xmlns:'.$regs[1]])) {
  6444. $this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:'.$regs[1]];
  6445. }
  6446. $this->message[$pos]['arrayType'] = $regs[2];
  6447. $this->message[$pos]['arraySize'] = $regs[3];
  6448. $this->message[$pos]['arrayCols'] = $regs[4];
  6449. }
  6450. // specifies nil value (or not)
  6451. } elseif ($key_localpart == 'nil'){
  6452. $this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
  6453. // some other attribute
  6454. } elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
  6455. $this->message[$pos]['xattrs']['!' . $key] = $value;
  6456. }
  6457. if ($key == 'xmlns') {
  6458. $this->default_namespace = $value;
  6459. }
  6460. // log id
  6461. if($key == 'id'){
  6462. $this->ids[$value] = $pos;
  6463. }
  6464. // root
  6465. if($key_localpart == 'root' && $value == 1){
  6466. $this->status = 'method';
  6467. $this->root_struct_name = $name;
  6468. $this->root_struct = $pos;
  6469. $this->debug("found root struct $this->root_struct_name, pos $pos");
  6470. }
  6471. // for doclit
  6472. $attstr .= " $key=\"$value\"";
  6473. }
  6474. // get namespace - must be done after namespace atts are processed
  6475. if(isset($prefix)){
  6476. $this->message[$pos]['namespace'] = $this->namespaces[$prefix];
  6477. $this->default_namespace = $this->namespaces[$prefix];
  6478. } else {
  6479. $this->message[$pos]['namespace'] = $this->default_namespace;
  6480. }
  6481. if($this->status == 'header'){
  6482. if ($this->root_header != $pos) {
  6483. $this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
  6484. }
  6485. } elseif($this->root_struct_name != ''){
  6486. $this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
  6487. }
  6488. }
  6489. /**
  6490. * end-element handler
  6491. *
  6492. * @param resource $parser XML parser object
  6493. * @param string $name element name
  6494. * @access private
  6495. */
  6496. function end_element($parser, $name) {
  6497. // position of current element is equal to the last value left in depth_array for my depth
  6498. $pos = $this->depth_array[$this->depth--];
  6499. // get element prefix
  6500. if(strpos($name,':')){
  6501. // get ns prefix
  6502. $prefix = substr($name,0,strpos($name,':'));
  6503. // get unqualified name
  6504. $name = substr(strstr($name,':'),1);
  6505. }
  6506. // build to native type
  6507. if(isset($this->body_position) && $pos > $this->body_position){
  6508. // deal w/ multirefs
  6509. if(isset($this->message[$pos]['attrs']['href'])){
  6510. // get id
  6511. $id = substr($this->message[$pos]['attrs']['href'],1);
  6512. // add placeholder to href array
  6513. $this->multirefs[$id][$pos] = 'placeholder';
  6514. // add set a reference to it as the result value
  6515. $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
  6516. // build complexType values
  6517. } elseif($this->message[$pos]['children'] != ''){
  6518. // if result has already been generated (struct/array)
  6519. if(!isset($this->message[$pos]['result'])){
  6520. $this->message[$pos]['result'] = $this->buildVal($pos);
  6521. }
  6522. // build complexType values of attributes and possibly simpleContent
  6523. } elseif (isset($this->message[$pos]['xattrs'])) {
  6524. if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
  6525. $this->message[$pos]['xattrs']['!'] = null;
  6526. } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
  6527. if (isset($this->message[$pos]['type'])) {
  6528. $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  6529. } else {
  6530. $parent = $this->message[$pos]['parent'];
  6531. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6532. $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6533. } else {
  6534. $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
  6535. }
  6536. }
  6537. }
  6538. $this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
  6539. // set value of simpleType (or nil complexType)
  6540. } else {
  6541. //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
  6542. if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
  6543. $this->message[$pos]['xattrs']['!'] = null;
  6544. } elseif (isset($this->message[$pos]['type'])) {
  6545. $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  6546. } else {
  6547. $parent = $this->message[$pos]['parent'];
  6548. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6549. $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6550. } else {
  6551. $this->message[$pos]['result'] = $this->message[$pos]['cdata'];
  6552. }
  6553. }
  6554. /* add value to parent's result, if parent is struct/array
  6555. $parent = $this->message[$pos]['parent'];
  6556. if($this->message[$parent]['type'] != 'map'){
  6557. if(strtolower($this->message[$parent]['type']) == 'array'){
  6558. $this->message[$parent]['result'][] = $this->message[$pos]['result'];
  6559. } else {
  6560. $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
  6561. }
  6562. }
  6563. */
  6564. }
  6565. }
  6566. // for doclit
  6567. if($this->status == 'header'){
  6568. if ($this->root_header != $pos) {
  6569. $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
  6570. }
  6571. } elseif($pos >= $this->root_struct){
  6572. $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
  6573. }
  6574. // switch status
  6575. if ($pos == $this->root_struct){
  6576. $this->status = 'body';
  6577. $this->root_struct_namespace = $this->message[$pos]['namespace'];
  6578. } elseif ($pos == $this->root_header) {
  6579. $this->status = 'envelope';
  6580. } elseif ($name == 'Body' && $this->status == 'body') {
  6581. $this->status = 'envelope';
  6582. } elseif ($name == 'Header' && $this->status == 'header') { // will never happen
  6583. $this->status = 'envelope';
  6584. } elseif ($name == 'Envelope' && $this->status == 'envelope') {
  6585. $this->status = '';
  6586. }
  6587. // set parent back to my parent
  6588. $this->parent = $this->message[$pos]['parent'];
  6589. }
  6590. /**
  6591. * element content handler
  6592. *
  6593. * @param resource $parser XML parser object
  6594. * @param string $data element content
  6595. * @access private
  6596. */
  6597. function character_data($parser, $data){
  6598. $pos = $this->depth_array[$this->depth];
  6599. if ($this->xml_encoding=='UTF-8'){
  6600. // TODO: add an option to disable this for folks who want
  6601. // raw UTF-8 that, e.g., might not map to iso-8859-1
  6602. // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
  6603. if($this->decode_utf8){
  6604. $data = utf8_decode($data);
  6605. }
  6606. }
  6607. $this->message[$pos]['cdata'] .= $data;
  6608. // for doclit
  6609. if($this->status == 'header'){
  6610. $this->responseHeaders .= $data;
  6611. } else {
  6612. $this->document .= $data;
  6613. }
  6614. }
  6615. /**
  6616. * get the parsed message (SOAP Body)
  6617. *
  6618. * @return mixed
  6619. * @access public
  6620. * @deprecated use get_soapbody instead
  6621. */
  6622. function get_response(){
  6623. return $this->soapresponse;
  6624. }
  6625. /**
  6626. * get the parsed SOAP Body (NULL if there was none)
  6627. *
  6628. * @return mixed
  6629. * @access public
  6630. */
  6631. function get_soapbody(){
  6632. return $this->soapresponse;
  6633. }
  6634. /**
  6635. * get the parsed SOAP Header (NULL if there was none)
  6636. *
  6637. * @return mixed
  6638. * @access public
  6639. */
  6640. function get_soapheader(){
  6641. return $this->soapheader;
  6642. }
  6643. /**
  6644. * get the unparsed SOAP Header
  6645. *
  6646. * @return string XML or empty if no Header
  6647. * @access public
  6648. */
  6649. function getHeaders(){
  6650. return $this->responseHeaders;
  6651. }
  6652. /**
  6653. * decodes simple types into PHP variables
  6654. *
  6655. * @param string $value value to decode
  6656. * @param string $type XML type to decode
  6657. * @param string $typens XML type namespace to decode
  6658. * @return mixed PHP value
  6659. * @access private
  6660. */
  6661. function decodeSimple($value, $type, $typens) {
  6662. // TODO: use the namespace!
  6663. if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
  6664. return (string) $value;
  6665. }
  6666. if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
  6667. return (int) $value;
  6668. }
  6669. if ($type == 'float' || $type == 'double' || $type == 'decimal') {
  6670. return (double) $value;
  6671. }
  6672. if ($type == 'boolean') {
  6673. if (strtolower($value) == 'false' || strtolower($value) == 'f') {
  6674. return false;
  6675. }
  6676. return (boolean) $value;
  6677. }
  6678. if ($type == 'base64' || $type == 'base64Binary') {
  6679. $this->debug('Decode base64 value');
  6680. return base64_decode($value);
  6681. }
  6682. // obscure numeric types
  6683. if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
  6684. || $type == 'nonNegativeInteger' || $type == 'positiveInteger'
  6685. || $type == 'unsignedInt'
  6686. || $type == 'unsignedShort' || $type == 'unsignedByte') {
  6687. return (int) $value;
  6688. }
  6689. // bogus: parser treats array with no elements as a simple type
  6690. if ($type == 'array') {
  6691. return array();
  6692. }
  6693. // everything else
  6694. return (string) $value;
  6695. }
  6696. /**
  6697. * builds response structures for compound values (arrays/structs)
  6698. * and scalars
  6699. *
  6700. * @param integer $pos position in node tree
  6701. * @return mixed PHP value
  6702. * @access private
  6703. */
  6704. function buildVal($pos){
  6705. if(!isset($this->message[$pos]['type'])){
  6706. $this->message[$pos]['type'] = '';
  6707. }
  6708. $this->debug('in buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']);
  6709. // if there are children...
  6710. if($this->message[$pos]['children'] != ''){
  6711. $this->debug('in buildVal, there are children');
  6712. $children = explode('|',$this->message[$pos]['children']);
  6713. array_shift($children); // knock off empty
  6714. // md array
  6715. if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){
  6716. $r=0; // rowcount
  6717. $c=0; // colcount
  6718. foreach($children as $child_pos){
  6719. $this->debug("in buildVal, got an MD array element: $r, $c");
  6720. $params[$r][] = $this->message[$child_pos]['result'];
  6721. $c++;
  6722. if($c == $this->message[$pos]['arrayCols']){
  6723. $c = 0;
  6724. $r++;
  6725. }
  6726. }
  6727. // array
  6728. } elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){
  6729. $this->debug('in buildVal, adding array '.$this->message[$pos]['name']);
  6730. foreach($children as $child_pos){
  6731. $params[] = &$this->message[$child_pos]['result'];
  6732. }
  6733. // apache Map type: java hashtable
  6734. } elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){
  6735. $this->debug('in buildVal, Java Map '.$this->message[$pos]['name']);
  6736. foreach($children as $child_pos){
  6737. $kv = explode("|",$this->message[$child_pos]['children']);
  6738. $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
  6739. }
  6740. // generic compound type
  6741. //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
  6742. } else {
  6743. // Apache Vector type: treat as an array
  6744. $this->debug('in buildVal, adding Java Vector or generic compound type '.$this->message[$pos]['name']);
  6745. if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
  6746. $notstruct = 1;
  6747. } else {
  6748. $notstruct = 0;
  6749. }
  6750. //
  6751. foreach($children as $child_pos){
  6752. if($notstruct){
  6753. $params[] = &$this->message[$child_pos]['result'];
  6754. } else {
  6755. if (isset($params[$this->message[$child_pos]['name']])) {
  6756. // de-serialize repeated element name into an array
  6757. if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
  6758. $params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
  6759. }
  6760. $params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
  6761. } else {
  6762. $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
  6763. }
  6764. }
  6765. }
  6766. }
  6767. if (isset($this->message[$pos]['xattrs'])) {
  6768. $this->debug('in buildVal, handling attributes');
  6769. foreach ($this->message[$pos]['xattrs'] as $n => $v) {
  6770. $params[$n] = $v;
  6771. }
  6772. }
  6773. // handle simpleContent
  6774. if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
  6775. $this->debug('in buildVal, handling simpleContent');
  6776. if (isset($this->message[$pos]['type'])) {
  6777. $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  6778. } else {
  6779. $parent = $this->message[$pos]['parent'];
  6780. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6781. $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6782. } else {
  6783. $params['!'] = $this->message[$pos]['cdata'];
  6784. }
  6785. }
  6786. }
  6787. $ret = is_array($params) ? $params : array();
  6788. $this->debug('in buildVal, return:');
  6789. $this->appendDebug($this->varDump($ret));
  6790. return $ret;
  6791. } else {
  6792. $this->debug('in buildVal, no children, building scalar');
  6793. $cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
  6794. if (isset($this->message[$pos]['type'])) {
  6795. $ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  6796. $this->debug("in buildVal, return: $ret");
  6797. return $ret;
  6798. }
  6799. $parent = $this->message[$pos]['parent'];
  6800. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6801. $ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6802. $this->debug("in buildVal, return: $ret");
  6803. return $ret;
  6804. }
  6805. $ret = $this->message[$pos]['cdata'];
  6806. $this->debug("in buildVal, return: $ret");
  6807. return $ret;
  6808. }
  6809. }
  6810. }
  6811. /**
  6812. * Backward compatibility
  6813. */
  6814. class soap_parser extends nusoap_parser {
  6815. }
  6816. ?><?php
  6817. /**
  6818. *
  6819. * [nu]soapclient higher level class for easy usage.
  6820. *
  6821. * usage:
  6822. *
  6823. * // instantiate client with server info
  6824. * $soapclient = new nusoap_client( string path [ ,mixed wsdl] );
  6825. *
  6826. * // call method, get results
  6827. * echo $soapclient->call( string methodname [ ,array parameters] );
  6828. *
  6829. * // bye bye client
  6830. * unset($soapclient);
  6831. *
  6832. * @author Dietrich Ayala <dietrich@ganx4.com>
  6833. * @author Scott Nichol <snichol@users.sourceforge.net>
  6834. * @version $Id: nusoap.php,v 1.123 2010/04/26 20:15:08 snichol Exp $
  6835. * @access public
  6836. */
  6837. class nusoap_client extends nusoap_base {
  6838. var $username = ''; // Username for HTTP authentication
  6839. var $password = ''; // Password for HTTP authentication
  6840. var $authtype = ''; // Type of HTTP authentication
  6841. var $certRequest = array(); // Certificate for HTTP SSL authentication
  6842. var $requestHeaders = false; // SOAP headers in request (text)
  6843. var $responseHeaders = ''; // SOAP headers from response (incomplete namespace resolution) (text)
  6844. var $responseHeader = NULL; // SOAP Header from response (parsed)
  6845. var $document = ''; // SOAP body response portion (incomplete namespace resolution) (text)
  6846. var $endpoint;
  6847. var $forceEndpoint = ''; // overrides WSDL endpoint
  6848. var $proxyhost = '';
  6849. var $proxyport = '';
  6850. var $proxyusername = '';
  6851. var $proxypassword = '';
  6852. var $portName = ''; // port name to use in WSDL
  6853. var $xml_encoding = ''; // character set encoding of incoming (response) messages
  6854. var $http_encoding = false;
  6855. var $timeout = 0; // HTTP connection timeout
  6856. var $response_timeout = 30; // HTTP response timeout
  6857. var $endpointType = ''; // soap|wsdl, empty for WSDL initialization error
  6858. var $persistentConnection = false;
  6859. var $defaultRpcParams = false; // This is no longer used
  6860. var $request = ''; // HTTP request
  6861. var $response = ''; // HTTP response
  6862. var $responseData = ''; // SOAP payload of response
  6863. var $cookies = array(); // Cookies from response or for request
  6864. var $decode_utf8 = true; // toggles whether the parser decodes element content w/ utf8_decode()
  6865. var $operations = array(); // WSDL operations, empty for WSDL initialization error
  6866. var $curl_options = array(); // User-specified cURL options
  6867. var $bindingType = ''; // WSDL operation binding type
  6868. var $use_curl = false; // whether to always try to use cURL
  6869. /*
  6870. * fault related variables
  6871. */
  6872. /**
  6873. * @var fault
  6874. * @access public
  6875. */
  6876. var $fault;
  6877. /**
  6878. * @var faultcode
  6879. * @access public
  6880. */
  6881. var $faultcode;
  6882. /**
  6883. * @var faultstring
  6884. * @access public
  6885. */
  6886. var $faultstring;
  6887. /**
  6888. * @var faultdetail
  6889. * @access public
  6890. */
  6891. var $faultdetail;
  6892. /**
  6893. * constructor
  6894. *
  6895. * @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
  6896. * @param mixed $wsdl optional, set to 'wsdl' or true if using WSDL
  6897. * @param string $proxyhost optional
  6898. * @param string $proxyport optional
  6899. * @param string $proxyusername optional
  6900. * @param string $proxypassword optional
  6901. * @param integer $timeout set the connection timeout
  6902. * @param integer $response_timeout set the response timeout
  6903. * @param string $portName optional portName in WSDL document
  6904. * @access public
  6905. */
  6906. function nusoap_client($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = ''){
  6907. parent::nusoap_base();
  6908. $this->endpoint = $endpoint;
  6909. $this->proxyhost = $proxyhost;
  6910. $this->proxyport = $proxyport;
  6911. $this->proxyusername = $proxyusername;
  6912. $this->proxypassword = $proxypassword;
  6913. $this->timeout = $timeout;
  6914. $this->response_timeout = $response_timeout;
  6915. $this->portName = $portName;
  6916. $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
  6917. $this->appendDebug('endpoint=' . $this->varDump($endpoint));
  6918. // make values
  6919. if($wsdl){
  6920. if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
  6921. $this->wsdl = $endpoint;
  6922. $this->endpoint = $this->wsdl->wsdl;
  6923. $this->wsdlFile = $this->endpoint;
  6924. $this->debug('existing wsdl instance created from ' . $this->endpoint);
  6925. $this->checkWSDL();
  6926. } else {
  6927. $this->wsdlFile = $this->endpoint;
  6928. $this->wsdl = null;
  6929. $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
  6930. }
  6931. $this->endpointType = 'wsdl';
  6932. } else {
  6933. $this->debug("instantiate SOAP with endpoint at $endpoint");
  6934. $this->endpointType = 'soap';
  6935. }
  6936. }
  6937. /**
  6938. * calls method, returns PHP native type
  6939. *
  6940. * @param string $operation SOAP server URL or path
  6941. * @param mixed $params An array, associative or simple, of the parameters
  6942. * for the method call, or a string that is the XML
  6943. * for the call. For rpc style, this call will
  6944. * wrap the XML in a tag named after the method, as
  6945. * well as the SOAP Envelope and Body. For document
  6946. * style, this will only wrap with the Envelope and Body.
  6947. * IMPORTANT: when using an array with document style,
  6948. * in which case there
  6949. * is really one parameter, the root of the fragment
  6950. * used in the call, which encloses what programmers
  6951. * normally think of parameters. A parameter array
  6952. * *must* include the wrapper.
  6953. * @param string $namespace optional method namespace (WSDL can override)
  6954. * @param string $soapAction optional SOAPAction value (WSDL can override)
  6955. * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
  6956. * @param boolean $rpcParams optional (no longer used)
  6957. * @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
  6958. * @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override)
  6959. * @return mixed response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
  6960. * @access public
  6961. */
  6962. function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){
  6963. $this->operation = $operation;
  6964. $this->fault = false;
  6965. $this->setError('');
  6966. $this->request = '';
  6967. $this->response = '';
  6968. $this->responseData = '';
  6969. $this->faultstring = '';
  6970. $this->faultcode = '';
  6971. $this->opData = array();
  6972. $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
  6973. $this->appendDebug('params=' . $this->varDump($params));
  6974. $this->appendDebug('headers=' . $this->varDump($headers));
  6975. if ($headers) {
  6976. $this->requestHeaders = $headers;
  6977. }
  6978. if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
  6979. $this->loadWSDL();
  6980. if ($this->getError())
  6981. return false;
  6982. }
  6983. // serialize parameters
  6984. if($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)){
  6985. // use WSDL for operation
  6986. $this->opData = $opData;
  6987. $this->debug("found operation");
  6988. $this->appendDebug('opData=' . $this->varDump($opData));
  6989. if (isset($opData['soapAction'])) {
  6990. $soapAction = $opData['soapAction'];
  6991. }
  6992. if (! $this->forceEndpoint) {
  6993. $this->endpoint = $opData['endpoint'];
  6994. } else {
  6995. $this->endpoint = $this->forceEndpoint;
  6996. }
  6997. $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
  6998. $style = $opData['style'];
  6999. $use = $opData['input']['use'];
  7000. // add ns to ns array
  7001. if($namespace != '' && !isset($this->wsdl->namespaces[$namespace])){
  7002. $nsPrefix = 'ns' . rand(1000, 9999);
  7003. $this->wsdl->namespaces[$nsPrefix] = $namespace;
  7004. }
  7005. $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
  7006. // serialize payload
  7007. if (is_string($params)) {
  7008. $this->debug("serializing param string for WSDL operation $operation");
  7009. $payload = $params;
  7010. } elseif (is_array($params)) {
  7011. $this->debug("serializing param array for WSDL operation $operation");
  7012. $payload = $this->wsdl->serializeRPCParameters($operation,'input',$params,$this->bindingType);
  7013. } else {
  7014. $this->debug('params must be array or string');
  7015. $this->setError('params must be array or string');
  7016. return false;
  7017. }
  7018. $usedNamespaces = $this->wsdl->usedNamespaces;
  7019. if (isset($opData['input']['encodingStyle'])) {
  7020. $encodingStyle = $opData['input']['encodingStyle'];
  7021. } else {
  7022. $encodingStyle = '';
  7023. }
  7024. $this->appendDebug($this->wsdl->getDebug());
  7025. $this->wsdl->clearDebug();
  7026. if ($errstr = $this->wsdl->getError()) {
  7027. $this->debug('got wsdl error: '.$errstr);
  7028. $this->setError('wsdl error: '.$errstr);
  7029. return false;
  7030. }
  7031. } elseif($this->endpointType == 'wsdl') {
  7032. // operation not in WSDL
  7033. $this->appendDebug($this->wsdl->getDebug());
  7034. $this->wsdl->clearDebug();
  7035. $this->setError('operation '.$operation.' not present in WSDL.');
  7036. $this->debug("operation '$operation' not present in WSDL.");
  7037. return false;
  7038. } else {
  7039. // no WSDL
  7040. //$this->namespaces['ns1'] = $namespace;
  7041. $nsPrefix = 'ns' . rand(1000, 9999);
  7042. // serialize
  7043. $payload = '';
  7044. if (is_string($params)) {
  7045. $this->debug("serializing param string for operation $operation");
  7046. $payload = $params;
  7047. } elseif (is_array($params)) {
  7048. $this->debug("serializing param array for operation $operation");
  7049. foreach($params as $k => $v){
  7050. $payload .= $this->serialize_val($v,$k,false,false,false,false,$use);
  7051. }
  7052. } else {
  7053. $this->debug('params must be array or string');
  7054. $this->setError('params must be array or string');
  7055. return false;
  7056. }
  7057. $usedNamespaces = array();
  7058. if ($use == 'encoded') {
  7059. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  7060. } else {
  7061. $encodingStyle = '';
  7062. }
  7063. }
  7064. // wrap RPC calls with method element
  7065. if ($style == 'rpc') {
  7066. if ($use == 'literal') {
  7067. $this->debug("wrapping RPC request with literal method element");
  7068. if ($namespace) {
  7069. // http://www.ws-i.org/Profiles/BasicProfile-1.1-2004-08-24.html R2735 says rpc/literal accessor elements should not be in a namespace
  7070. $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
  7071. $payload .
  7072. "</$nsPrefix:$operation>";
  7073. } else {
  7074. $payload = "<$operation>" . $payload . "</$operation>";
  7075. }
  7076. } else {
  7077. $this->debug("wrapping RPC request with encoded method element");
  7078. if ($namespace) {
  7079. $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
  7080. $payload .
  7081. "</$nsPrefix:$operation>";
  7082. } else {
  7083. $payload = "<$operation>" .
  7084. $payload .
  7085. "</$operation>";
  7086. }
  7087. }
  7088. }
  7089. // serialize envelope
  7090. $soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$usedNamespaces,$style,$use,$encodingStyle);
  7091. $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
  7092. $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
  7093. // send
  7094. $return = $this->send($this->getHTTPBody($soapmsg),$soapAction,$this->timeout,$this->response_timeout);
  7095. if($errstr = $this->getError()){
  7096. $this->debug('Error: '.$errstr);
  7097. return false;
  7098. } else {
  7099. $this->return = $return;
  7100. $this->debug('sent message successfully and got a(n) '.gettype($return));
  7101. $this->appendDebug('return=' . $this->varDump($return));
  7102. // fault?
  7103. if(is_array($return) && isset($return['faultcode'])){
  7104. $this->debug('got fault');
  7105. $this->setError($return['faultcode'].': '.$return['faultstring']);
  7106. $this->fault = true;
  7107. foreach($return as $k => $v){
  7108. $this->$k = $v;
  7109. $this->debug("$k = $v<br>");
  7110. }
  7111. return $return;
  7112. } elseif ($style == 'document') {
  7113. // NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
  7114. // we are only going to return the first part here...sorry about that
  7115. return $return;
  7116. } else {
  7117. // array of return values
  7118. if(is_array($return)){
  7119. // multiple 'out' parameters, which we return wrapped up
  7120. // in the array
  7121. if(sizeof($return) > 1){
  7122. return $return;
  7123. }
  7124. // single 'out' parameter (normally the return value)
  7125. $return = array_shift($return);
  7126. $this->debug('return shifted value: ');
  7127. $this->appendDebug($this->varDump($return));
  7128. return $return;
  7129. // nothing returned (ie, echoVoid)
  7130. } else {
  7131. return "";
  7132. }
  7133. }
  7134. }
  7135. }
  7136. /**
  7137. * check WSDL passed as an instance or pulled from an endpoint
  7138. *
  7139. * @access private
  7140. */
  7141. function checkWSDL() {
  7142. $this->appendDebug($this->wsdl->getDebug());
  7143. $this->wsdl->clearDebug();
  7144. $this->debug('checkWSDL');
  7145. // catch errors
  7146. if ($errstr = $this->wsdl->getError()) {
  7147. $this->appendDebug($this->wsdl->getDebug());
  7148. $this->wsdl->clearDebug();
  7149. $this->debug('got wsdl error: '.$errstr);
  7150. $this->setError('wsdl error: '.$errstr);
  7151. } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap')) {
  7152. $this->appendDebug($this->wsdl->getDebug());
  7153. $this->wsdl->clearDebug();
  7154. $this->bindingType = 'soap';
  7155. $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType);
  7156. } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12')) {
  7157. $this->appendDebug($this->wsdl->getDebug());
  7158. $this->wsdl->clearDebug();
  7159. $this->bindingType = 'soap12';
  7160. $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType);
  7161. $this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
  7162. } else {
  7163. $this->appendDebug($this->wsdl->getDebug());
  7164. $this->wsdl->clearDebug();
  7165. $this->debug('getOperations returned false');
  7166. $this->setError('no operations defined in the WSDL document!');
  7167. }
  7168. }
  7169. /**
  7170. * instantiate wsdl object and parse wsdl file
  7171. *
  7172. * @access public
  7173. */
  7174. function loadWSDL() {
  7175. $this->debug('instantiating wsdl class with doc: '.$this->wsdlFile);
  7176. $this->wsdl = new wsdl('',$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout,$this->curl_options,$this->use_curl);
  7177. $this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
  7178. $this->wsdl->fetchWSDL($this->wsdlFile);
  7179. $this->checkWSDL();
  7180. }
  7181. /**
  7182. * get available data pertaining to an operation
  7183. *
  7184. * @param string $operation operation name
  7185. * @return array array of data pertaining to the operation
  7186. * @access public
  7187. */
  7188. function getOperationData($operation){
  7189. if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
  7190. $this->loadWSDL();
  7191. if ($this->getError())
  7192. return false;
  7193. }
  7194. if(isset($this->operations[$operation])){
  7195. return $this->operations[$operation];
  7196. }
  7197. $this->debug("No data for operation: $operation");
  7198. }
  7199. /**
  7200. * send the SOAP message
  7201. *
  7202. * Note: if the operation has multiple return values
  7203. * the return value of this method will be an array
  7204. * of those values.
  7205. *
  7206. * @param string $msg a SOAPx4 soapmsg object
  7207. * @param string $soapaction SOAPAction value
  7208. * @param integer $timeout set connection timeout in seconds
  7209. * @param integer $response_timeout set response timeout in seconds
  7210. * @return mixed native PHP types.
  7211. * @access private
  7212. */
  7213. function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) {
  7214. $this->checkCookies();
  7215. // detect transport
  7216. switch(true){
  7217. // http(s)
  7218. case preg_match('/^http/',$this->endpoint):
  7219. $this->debug('transporting via HTTP');
  7220. if($this->persistentConnection == true && is_object($this->persistentConnection)){
  7221. $http =& $this->persistentConnection;
  7222. } else {
  7223. $http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
  7224. if ($this->persistentConnection) {
  7225. $http->usePersistentConnection();
  7226. }
  7227. }
  7228. $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
  7229. $http->setSOAPAction($soapaction);
  7230. if($this->proxyhost && $this->proxyport){
  7231. $http->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
  7232. }
  7233. if($this->authtype != '') {
  7234. $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
  7235. }
  7236. if($this->http_encoding != ''){
  7237. $http->setEncoding($this->http_encoding);
  7238. }
  7239. $this->debug('sending message, length='.strlen($msg));
  7240. if(preg_match('/^http:/',$this->endpoint)){
  7241. //if(strpos($this->endpoint,'http:')){
  7242. $this->responseData = $http->send($msg,$timeout,$response_timeout,$this->cookies);
  7243. } elseif(preg_match('/^https/',$this->endpoint)){
  7244. //} elseif(strpos($this->endpoint,'https:')){
  7245. //if(phpversion() == '4.3.0-dev'){
  7246. //$response = $http->send($msg,$timeout,$response_timeout);
  7247. //$this->request = $http->outgoing_payload;
  7248. //$this->response = $http->incoming_payload;
  7249. //} else
  7250. $this->responseData = $http->sendHTTPS($msg,$timeout,$response_timeout,$this->cookies);
  7251. } else {
  7252. $this->setError('no http/s in endpoint url');
  7253. }
  7254. $this->request = $http->outgoing_payload;
  7255. $this->response = $http->incoming_payload;
  7256. $this->appendDebug($http->getDebug());
  7257. $this->UpdateCookies($http->incoming_cookies);
  7258. // save transport object if using persistent connections
  7259. if ($this->persistentConnection) {
  7260. $http->clearDebug();
  7261. if (!is_object($this->persistentConnection)) {
  7262. $this->persistentConnection = $http;
  7263. }
  7264. }
  7265. if($err = $http->getError()){
  7266. $this->setError('HTTP Error: '.$err);
  7267. return false;
  7268. } elseif($this->getError()){
  7269. return false;
  7270. } else {
  7271. $this->debug('got response, length='. strlen($this->responseData).' type='.$http->incoming_headers['content-type']);
  7272. return $this->parseResponse($http->incoming_headers, $this->responseData);
  7273. }
  7274. break;
  7275. default:
  7276. $this->setError('no transport found, or selected transport is not yet supported!');
  7277. return false;
  7278. break;
  7279. }
  7280. }
  7281. /**
  7282. * processes SOAP message returned from server
  7283. *
  7284. * @param array $headers The HTTP headers
  7285. * @param string $data unprocessed response data from server
  7286. * @return mixed value of the message, decoded into a PHP type
  7287. * @access private
  7288. */
  7289. function parseResponse($headers, $data) {
  7290. $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
  7291. $this->appendDebug($this->varDump($headers));
  7292. if (!isset($headers['content-type'])) {
  7293. $this->setError('Response not of type text/xml (no content-type header)');
  7294. return false;
  7295. }
  7296. if (!strstr($headers['content-type'], 'text/xml')) {
  7297. $this->setError('Response not of type text/xml: ' . $headers['content-type']);
  7298. return false;
  7299. }
  7300. if (strpos($headers['content-type'], '=')) {
  7301. $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
  7302. $this->debug('Got response encoding: ' . $enc);
  7303. if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
  7304. $this->xml_encoding = strtoupper($enc);
  7305. } else {
  7306. $this->xml_encoding = 'US-ASCII';
  7307. }
  7308. } else {
  7309. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  7310. $this->xml_encoding = 'ISO-8859-1';
  7311. }
  7312. $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
  7313. $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8);
  7314. // add parser debug data to our debug
  7315. $this->appendDebug($parser->getDebug());
  7316. // if parse errors
  7317. if($errstr = $parser->getError()){
  7318. $this->setError( $errstr);
  7319. // destroy the parser object
  7320. unset($parser);
  7321. return false;
  7322. } else {
  7323. // get SOAP headers
  7324. $this->responseHeaders = $parser->getHeaders();
  7325. // get SOAP headers
  7326. $this->responseHeader = $parser->get_soapheader();
  7327. // get decoded message
  7328. $return = $parser->get_soapbody();
  7329. // add document for doclit support
  7330. $this->document = $parser->document;
  7331. // destroy the parser object
  7332. unset($parser);
  7333. // return decode message
  7334. return $return;
  7335. }
  7336. }
  7337. /**
  7338. * sets user-specified cURL options
  7339. *
  7340. * @param mixed $option The cURL option (always integer?)
  7341. * @param mixed $value The cURL option value
  7342. * @access public
  7343. */
  7344. function setCurlOption($option, $value) {
  7345. $this->debug("setCurlOption option=$option, value=");
  7346. $this->appendDebug($this->varDump($value));
  7347. $this->curl_options[$option] = $value;
  7348. }
  7349. /**
  7350. * sets the SOAP endpoint, which can override WSDL
  7351. *
  7352. * @param string $endpoint The endpoint URL to use, or empty string or false to prevent override
  7353. * @access public
  7354. */
  7355. function setEndpoint($endpoint) {
  7356. $this->debug("setEndpoint(\"$endpoint\")");
  7357. $this->forceEndpoint = $endpoint;
  7358. }
  7359. /**
  7360. * set the SOAP headers
  7361. *
  7362. * @param mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
  7363. * @access public
  7364. */
  7365. function setHeaders($headers){
  7366. $this->debug("setHeaders headers=");
  7367. $this->appendDebug($this->varDump($headers));
  7368. $this->requestHeaders = $headers;
  7369. }
  7370. /**
  7371. * get the SOAP response headers (namespace resolution incomplete)
  7372. *
  7373. * @return string
  7374. * @access public
  7375. */
  7376. function getHeaders(){
  7377. return $this->responseHeaders;
  7378. }
  7379. /**
  7380. * get the SOAP response Header (parsed)
  7381. *
  7382. * @return mixed
  7383. * @access public
  7384. */
  7385. function getHeader(){
  7386. return $this->responseHeader;
  7387. }
  7388. /**
  7389. * set proxy info here
  7390. *
  7391. * @param string $proxyhost
  7392. * @param string $proxyport
  7393. * @param string $proxyusername
  7394. * @param string $proxypassword
  7395. * @access public
  7396. */
  7397. function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '') {
  7398. $this->proxyhost = $proxyhost;
  7399. $this->proxyport = $proxyport;
  7400. $this->proxyusername = $proxyusername;
  7401. $this->proxypassword = $proxypassword;
  7402. }
  7403. /**
  7404. * if authenticating, set user credentials here
  7405. *
  7406. * @param string $username
  7407. * @param string $password
  7408. * @param string $authtype (basic|digest|certificate|ntlm)
  7409. * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
  7410. * @access public
  7411. */
  7412. function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
  7413. $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
  7414. $this->appendDebug($this->varDump($certRequest));
  7415. $this->username = $username;
  7416. $this->password = $password;
  7417. $this->authtype = $authtype;
  7418. $this->certRequest = $certRequest;
  7419. }
  7420. /**
  7421. * use HTTP encoding
  7422. *
  7423. * @param string $enc HTTP encoding
  7424. * @access public
  7425. */
  7426. function setHTTPEncoding($enc='gzip, deflate'){
  7427. $this->debug("setHTTPEncoding(\"$enc\")");
  7428. $this->http_encoding = $enc;
  7429. }
  7430. /**
  7431. * Set whether to try to use cURL connections if possible
  7432. *
  7433. * @param boolean $use Whether to try to use cURL
  7434. * @access public
  7435. */
  7436. function setUseCURL($use) {
  7437. $this->debug("setUseCURL($use)");
  7438. $this->use_curl = $use;
  7439. }
  7440. /**
  7441. * use HTTP persistent connections if possible
  7442. *
  7443. * @access public
  7444. */
  7445. function useHTTPPersistentConnection(){
  7446. $this->debug("useHTTPPersistentConnection");
  7447. $this->persistentConnection = true;
  7448. }
  7449. /**
  7450. * gets the default RPC parameter setting.
  7451. * If true, default is that call params are like RPC even for document style.
  7452. * Each call() can override this value.
  7453. *
  7454. * This is no longer used.
  7455. *
  7456. * @return boolean
  7457. * @access public
  7458. * @deprecated
  7459. */
  7460. function getDefaultRpcParams() {
  7461. return $this->defaultRpcParams;
  7462. }
  7463. /**
  7464. * sets the default RPC parameter setting.
  7465. * If true, default is that call params are like RPC even for document style
  7466. * Each call() can override this value.
  7467. *
  7468. * This is no longer used.
  7469. *
  7470. * @param boolean $rpcParams
  7471. * @access public
  7472. * @deprecated
  7473. */
  7474. function setDefaultRpcParams($rpcParams) {
  7475. $this->defaultRpcParams = $rpcParams;
  7476. }
  7477. /**
  7478. * dynamically creates an instance of a proxy class,
  7479. * allowing user to directly call methods from wsdl
  7480. *
  7481. * @return object soap_proxy object
  7482. * @access public
  7483. */
  7484. function getProxy() {
  7485. $r = rand();
  7486. $evalStr = $this->_getProxyClassCode($r);
  7487. //$this->debug("proxy class: $evalStr");
  7488. if ($this->getError()) {
  7489. $this->debug("Error from _getProxyClassCode, so return NULL");
  7490. return null;
  7491. }
  7492. // eval the class
  7493. eval($evalStr);
  7494. // instantiate proxy object
  7495. eval("\$proxy = new nusoap_proxy_$r('');");
  7496. // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
  7497. $proxy->endpointType = 'wsdl';
  7498. $proxy->wsdlFile = $this->wsdlFile;
  7499. $proxy->wsdl = $this->wsdl;
  7500. $proxy->operations = $this->operations;
  7501. $proxy->defaultRpcParams = $this->defaultRpcParams;
  7502. // transfer other state
  7503. $proxy->soap_defencoding = $this->soap_defencoding;
  7504. $proxy->username = $this->username;
  7505. $proxy->password = $this->password;
  7506. $proxy->authtype = $this->authtype;
  7507. $proxy->certRequest = $this->certRequest;
  7508. $proxy->requestHeaders = $this->requestHeaders;
  7509. $proxy->endpoint = $this->endpoint;
  7510. $proxy->forceEndpoint = $this->forceEndpoint;
  7511. $proxy->proxyhost = $this->proxyhost;
  7512. $proxy->proxyport = $this->proxyport;
  7513. $proxy->proxyusername = $this->proxyusername;
  7514. $proxy->proxypassword = $this->proxypassword;
  7515. $proxy->http_encoding = $this->http_encoding;
  7516. $proxy->timeout = $this->timeout;
  7517. $proxy->response_timeout = $this->response_timeout;
  7518. $proxy->persistentConnection = &$this->persistentConnection;
  7519. $proxy->decode_utf8 = $this->decode_utf8;
  7520. $proxy->curl_options = $this->curl_options;
  7521. $proxy->bindingType = $this->bindingType;
  7522. $proxy->use_curl = $this->use_curl;
  7523. return $proxy;
  7524. }
  7525. /**
  7526. * dynamically creates proxy class code
  7527. *
  7528. * @return string PHP/NuSOAP code for the proxy class
  7529. * @access private
  7530. */
  7531. function _getProxyClassCode($r) {
  7532. $this->debug("in getProxy endpointType=$this->endpointType");
  7533. $this->appendDebug("wsdl=" . $this->varDump($this->wsdl));
  7534. if ($this->endpointType != 'wsdl') {
  7535. $evalStr = 'A proxy can only be created for a WSDL client';
  7536. $this->setError($evalStr);
  7537. $evalStr = "echo \"$evalStr\";";
  7538. return $evalStr;
  7539. }
  7540. if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
  7541. $this->loadWSDL();
  7542. if ($this->getError()) {
  7543. return "echo \"" . $this->getError() . "\";";
  7544. }
  7545. }
  7546. $evalStr = '';
  7547. foreach ($this->operations as $operation => $opData) {
  7548. if ($operation != '') {
  7549. // create param string and param comment string
  7550. if (sizeof($opData['input']['parts']) > 0) {
  7551. $paramStr = '';
  7552. $paramArrayStr = '';
  7553. $paramCommentStr = '';
  7554. foreach ($opData['input']['parts'] as $name => $type) {
  7555. $paramStr .= "\$$name, ";
  7556. $paramArrayStr .= "'$name' => \$$name, ";
  7557. $paramCommentStr .= "$type \$$name, ";
  7558. }
  7559. $paramStr = substr($paramStr, 0, strlen($paramStr)-2);
  7560. $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr)-2);
  7561. $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr)-2);
  7562. } else {
  7563. $paramStr = '';
  7564. $paramArrayStr = '';
  7565. $paramCommentStr = 'void';
  7566. }
  7567. $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
  7568. $evalStr .= "// $paramCommentStr
  7569. function " . str_replace('.', '__', $operation) . "($paramStr) {
  7570. \$params = array($paramArrayStr);
  7571. return \$this->call('$operation', \$params, '".$opData['namespace']."', '".(isset($opData['soapAction']) ? $opData['soapAction'] : '')."');
  7572. }
  7573. ";
  7574. unset($paramStr);
  7575. unset($paramCommentStr);
  7576. }
  7577. }
  7578. $evalStr = 'class nusoap_proxy_'.$r.' extends nusoap_client {
  7579. '.$evalStr.'
  7580. }';
  7581. return $evalStr;
  7582. }
  7583. /**
  7584. * dynamically creates proxy class code
  7585. *
  7586. * @return string PHP/NuSOAP code for the proxy class
  7587. * @access public
  7588. */
  7589. function getProxyClassCode() {
  7590. $r = rand();
  7591. return $this->_getProxyClassCode($r);
  7592. }
  7593. /**
  7594. * gets the HTTP body for the current request.
  7595. *
  7596. * @param string $soapmsg The SOAP payload
  7597. * @return string The HTTP body, which includes the SOAP payload
  7598. * @access private
  7599. */
  7600. function getHTTPBody($soapmsg) {
  7601. return $soapmsg;
  7602. }
  7603. /**
  7604. * gets the HTTP content type for the current request.
  7605. *
  7606. * Note: getHTTPBody must be called before this.
  7607. *
  7608. * @return string the HTTP content type for the current request.
  7609. * @access private
  7610. */
  7611. function getHTTPContentType() {
  7612. return 'text/xml';
  7613. }
  7614. /**
  7615. * gets the HTTP content type charset for the current request.
  7616. * returns false for non-text content types.
  7617. *
  7618. * Note: getHTTPBody must be called before this.
  7619. *
  7620. * @return string the HTTP content type charset for the current request.
  7621. * @access private
  7622. */
  7623. function getHTTPContentTypeCharset() {
  7624. return $this->soap_defencoding;
  7625. }
  7626. /*
  7627. * whether or not parser should decode utf8 element content
  7628. *
  7629. * @return always returns true
  7630. * @access public
  7631. */
  7632. function decodeUTF8($bool){
  7633. $this->decode_utf8 = $bool;
  7634. return true;
  7635. }
  7636. /**
  7637. * adds a new Cookie into $this->cookies array
  7638. *
  7639. * @param string $name Cookie Name
  7640. * @param string $value Cookie Value
  7641. * @return boolean if cookie-set was successful returns true, else false
  7642. * @access public
  7643. */
  7644. function setCookie($name, $value) {
  7645. if (strlen($name) == 0) {
  7646. return false;
  7647. }
  7648. $this->cookies[] = array('name' => $name, 'value' => $value);
  7649. return true;
  7650. }
  7651. /**
  7652. * gets all Cookies
  7653. *
  7654. * @return array with all internal cookies
  7655. * @access public
  7656. */
  7657. function getCookies() {
  7658. return $this->cookies;
  7659. }
  7660. /**
  7661. * checks all Cookies and delete those which are expired
  7662. *
  7663. * @return boolean always return true
  7664. * @access private
  7665. */
  7666. function checkCookies() {
  7667. if (sizeof($this->cookies) == 0) {
  7668. return true;
  7669. }
  7670. $this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies');
  7671. $curr_cookies = $this->cookies;
  7672. $this->cookies = array();
  7673. foreach ($curr_cookies as $cookie) {
  7674. if (! is_array($cookie)) {
  7675. $this->debug('Remove cookie that is not an array');
  7676. continue;
  7677. }
  7678. if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
  7679. if (strtotime($cookie['expires']) > time()) {
  7680. $this->cookies[] = $cookie;
  7681. } else {
  7682. $this->debug('Remove expired cookie ' . $cookie['name']);
  7683. }
  7684. } else {
  7685. $this->cookies[] = $cookie;
  7686. }
  7687. }
  7688. $this->debug('checkCookie: '.sizeof($this->cookies).' cookies left in array');
  7689. return true;
  7690. }
  7691. /**
  7692. * updates the current cookies with a new set
  7693. *
  7694. * @param array $cookies new cookies with which to update current ones
  7695. * @return boolean always return true
  7696. * @access private
  7697. */
  7698. function UpdateCookies($cookies) {
  7699. if (sizeof($this->cookies) == 0) {
  7700. // no existing cookies: take whatever is new
  7701. if (sizeof($cookies) > 0) {
  7702. $this->debug('Setting new cookie(s)');
  7703. $this->cookies = $cookies;
  7704. }
  7705. return true;
  7706. }
  7707. if (sizeof($cookies) == 0) {
  7708. // no new cookies: keep what we've got
  7709. return true;
  7710. }
  7711. // merge
  7712. foreach ($cookies as $newCookie) {
  7713. if (!is_array($newCookie)) {
  7714. continue;
  7715. }
  7716. if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
  7717. continue;
  7718. }
  7719. $newName = $newCookie['name'];
  7720. $found = false;
  7721. for ($i = 0; $i < count($this->cookies); $i++) {
  7722. $cookie = $this->cookies[$i];
  7723. if (!is_array($cookie)) {
  7724. continue;
  7725. }
  7726. if (!isset($cookie['name'])) {
  7727. continue;
  7728. }
  7729. if ($newName != $cookie['name']) {
  7730. continue;
  7731. }
  7732. $newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
  7733. $domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
  7734. if ($newDomain != $domain) {
  7735. continue;
  7736. }
  7737. $newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
  7738. $path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
  7739. if ($newPath != $path) {
  7740. continue;
  7741. }
  7742. $this->cookies[$i] = $newCookie;
  7743. $found = true;
  7744. $this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
  7745. break;
  7746. }
  7747. if (! $found) {
  7748. $this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
  7749. $this->cookies[] = $newCookie;
  7750. }
  7751. }
  7752. return true;
  7753. }
  7754. }
  7755. if (!extension_loaded('soap')) {
  7756. /**
  7757. * For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
  7758. */
  7759. class soapclient extends nusoap_client {
  7760. }
  7761. }
  7762. ?>