nusoap.php 282 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147
  1. <?php
  2. /*
  3. NuSOAP - Web Services Toolkit for PHP
  4. Copyright (c) 2002 NuSphere Corporation
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. The NuSOAP project home is:
  16. http://sourceforge.net/projects/nusoap/
  17. The primary support for NuSOAP is the Help forum on the project home page.
  18. If you have any questions or comments, please email:
  19. Dietrich Ayala
  20. dietrich@ganx4.com
  21. http://dietrich.ganx4.com/nusoap
  22. NuSphere Corporation
  23. http://www.nusphere.com
  24. */
  25. /*
  26. * Some of the standards implmented in whole or part by NuSOAP:
  27. *
  28. * SOAP 1.1 (http://www.w3.org/TR/2000/NOTE-SOAP-20000508/)
  29. * WSDL 1.1 (http://www.w3.org/TR/2001/NOTE-wsdl-20010315)
  30. * SOAP Messages With Attachments (http://www.w3.org/TR/SOAP-attachments)
  31. * XML 1.0 (http://www.w3.org/TR/2006/REC-xml-20060816/)
  32. * Namespaces in XML 1.0 (http://www.w3.org/TR/2006/REC-xml-names-20060816/)
  33. * XML Schema 1.0 (http://www.w3.org/TR/xmlschema-0/)
  34. * RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
  35. * RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1
  36. * RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
  37. */
  38. /* load classes
  39. // necessary classes
  40. require_once('class.soapclient.php');
  41. require_once('class.soap_val.php');
  42. require_once('class.soap_parser.php');
  43. require_once('class.soap_fault.php');
  44. // transport classes
  45. require_once('class.soap_transport_http.php');
  46. // optional add-on classes
  47. require_once('class.xmlschema.php');
  48. require_once('class.wsdl.php');
  49. // server class
  50. require_once('class.soap_server.php');*/
  51. // class variable emulation
  52. // cf. http://www.webkreator.com/php/techniques/php-static-class-variables.html
  53. $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
  54. /**
  55. *
  56. * nusoap_base
  57. *
  58. * @author Dietrich Ayala <dietrich@ganx4.com>
  59. * @author Scott Nichol <snichol@users.sourceforge.net>
  60. * @access public
  61. */
  62. class nusoap_base {
  63. /**
  64. * Identification for HTTP headers.
  65. *
  66. * @var string
  67. * @access private
  68. */
  69. var $title = 'NuSOAP';
  70. /**
  71. * Version for HTTP headers.
  72. *
  73. * @var string
  74. * @access private
  75. */
  76. var $version = '0.9.5';
  77. /**
  78. * CVS revision for HTTP headers.
  79. *
  80. * @var string
  81. * @access private
  82. */
  83. var $revision = '1.15';
  84. /**
  85. * Current error string (manipulated by getError/setError)
  86. *
  87. * @var string
  88. * @access private
  89. */
  90. var $error_str = '';
  91. /**
  92. * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
  93. *
  94. * @var string
  95. * @access private
  96. */
  97. var $debug_str = '';
  98. /**
  99. * toggles automatic encoding of special characters as entities
  100. * (should always be true, I think)
  101. *
  102. * @var boolean
  103. * @access private
  104. */
  105. var $charencoding = true;
  106. /**
  107. * the debug level for this instance
  108. *
  109. * @var integer
  110. * @access private
  111. */
  112. var $debugLevel;
  113. /**
  114. * set schema version
  115. *
  116. * @var string
  117. * @access public
  118. */
  119. var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
  120. /**
  121. * charset encoding for outgoing messages
  122. *
  123. * @var string
  124. * @access public
  125. */
  126. var $soap_defencoding = 'ISO-8859-1';
  127. //var $soap_defencoding = 'UTF-8';
  128. /**
  129. * namespaces in an array of prefix => uri
  130. *
  131. * this is "seeded" by a set of constants, but it may be altered by code
  132. *
  133. * @var array
  134. * @access public
  135. */
  136. var $namespaces = array(
  137. 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
  138. 'xsd' => 'http://www.w3.org/2001/XMLSchema',
  139. 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
  140. 'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
  141. );
  142. /**
  143. * namespaces used in the current context, e.g. during serialization
  144. *
  145. * @var array
  146. * @access private
  147. */
  148. var $usedNamespaces = array();
  149. /**
  150. * XML Schema types in an array of uri => (array of xml type => php type)
  151. * is this legacy yet?
  152. * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
  153. * @var array
  154. * @access public
  155. */
  156. var $typemap = array(
  157. 'http://www.w3.org/2001/XMLSchema' => array(
  158. 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
  159. 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
  160. 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
  161. // abstract "any" types
  162. 'anyType'=>'string','anySimpleType'=>'string',
  163. // derived datatypes
  164. 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
  165. 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
  166. 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
  167. 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
  168. 'http://www.w3.org/2000/10/XMLSchema' => array(
  169. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  170. 'float'=>'double','dateTime'=>'string',
  171. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  172. 'http://www.w3.org/1999/XMLSchema' => array(
  173. 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
  174. 'float'=>'double','dateTime'=>'string',
  175. 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
  176. 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
  177. 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
  178. 'http://xml.apache.org/xml-soap' => array('Map')
  179. );
  180. /**
  181. * XML entities to convert
  182. *
  183. * @var array
  184. * @access public
  185. * @deprecated
  186. * @see expandEntities
  187. */
  188. var $xmlEntities = array('quot' => '"','amp' => '&',
  189. 'lt' => '<','gt' => '>','apos' => "'");
  190. /**
  191. * constructor
  192. *
  193. * @access public
  194. */
  195. function __construct() {
  196. $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
  197. }
  198. /**
  199. * gets the global debug level, which applies to future instances
  200. *
  201. * @return integer Debug level 0-9, where 0 turns off
  202. * @access public
  203. */
  204. function getGlobalDebugLevel() {
  205. return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
  206. }
  207. /**
  208. * sets the global debug level, which applies to future instances
  209. *
  210. * @param int $level Debug level 0-9, where 0 turns off
  211. * @access public
  212. */
  213. function setGlobalDebugLevel($level) {
  214. $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
  215. }
  216. /**
  217. * gets the debug level for this instance
  218. *
  219. * @return int Debug level 0-9, where 0 turns off
  220. * @access public
  221. */
  222. function getDebugLevel() {
  223. return $this->debugLevel;
  224. }
  225. /**
  226. * sets the debug level for this instance
  227. *
  228. * @param int $level Debug level 0-9, where 0 turns off
  229. * @access public
  230. */
  231. function setDebugLevel($level) {
  232. $this->debugLevel = $level;
  233. }
  234. /**
  235. * adds debug data to the instance debug string with formatting
  236. *
  237. * @param string $string debug data
  238. * @access private
  239. */
  240. function debug($string){
  241. if ($this->debugLevel > 0) {
  242. $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
  243. }
  244. }
  245. /**
  246. * adds debug data to the instance debug string without formatting
  247. *
  248. * @param string $string debug data
  249. * @access public
  250. */
  251. function appendDebug($string){
  252. if ($this->debugLevel > 0) {
  253. // it would be nice to use a memory stream here to use
  254. // memory more efficiently
  255. $this->debug_str .= $string;
  256. }
  257. }
  258. /**
  259. * clears the current debug data for this instance
  260. *
  261. * @access public
  262. */
  263. function clearDebug() {
  264. // it would be nice to use a memory stream here to use
  265. // memory more efficiently
  266. $this->debug_str = '';
  267. }
  268. /**
  269. * gets the current debug data for this instance
  270. *
  271. * @return debug data
  272. * @access public
  273. */
  274. function &getDebug() {
  275. // it would be nice to use a memory stream here to use
  276. // memory more efficiently
  277. return $this->debug_str;
  278. }
  279. /**
  280. * gets the current debug data for this instance as an XML comment
  281. * this may change the contents of the debug data
  282. *
  283. * @return debug data as an XML comment
  284. * @access public
  285. */
  286. function &getDebugAsXMLComment() {
  287. // it would be nice to use a memory stream here to use
  288. // memory more efficiently
  289. while (strpos($this->debug_str, '--')) {
  290. $this->debug_str = str_replace('--', '- -', $this->debug_str);
  291. }
  292. $ret = "<!--\n" . $this->debug_str . "\n-->";
  293. return $ret;
  294. }
  295. /**
  296. * expands entities, e.g. changes '<' to '&lt;'.
  297. *
  298. * @param string $val The string in which to expand entities.
  299. * @access private
  300. */
  301. function expandEntities($val) {
  302. if ($this->charencoding) {
  303. $val = str_replace('&', '&amp;', $val);
  304. $val = str_replace("'", '&apos;', $val);
  305. $val = str_replace('"', '&quot;', $val);
  306. $val = str_replace('<', '&lt;', $val);
  307. $val = str_replace('>', '&gt;', $val);
  308. }
  309. return $val;
  310. }
  311. /**
  312. * returns error string if present
  313. *
  314. * @return mixed error string or false
  315. * @access public
  316. */
  317. function getError(){
  318. if($this->error_str != ''){
  319. return $this->error_str;
  320. }
  321. return false;
  322. }
  323. /**
  324. * sets error string
  325. *
  326. * @return boolean $string error string
  327. * @access private
  328. */
  329. function setError($str){
  330. $this->error_str = $str;
  331. }
  332. /**
  333. * detect if array is a simple array or a struct (associative array)
  334. *
  335. * @param mixed $val The PHP array
  336. * @return string (arraySimple|arrayStruct)
  337. * @access private
  338. */
  339. function isArraySimpleOrStruct($val) {
  340. $keyList = array_keys($val);
  341. foreach ($keyList as $keyListValue) {
  342. if (!is_int($keyListValue)) {
  343. return 'arrayStruct';
  344. }
  345. }
  346. return 'arraySimple';
  347. }
  348. /**
  349. * serializes PHP values in accordance w/ section 5. Type information is
  350. * not serialized if $use == 'literal'.
  351. *
  352. * @param mixed $val The value to serialize
  353. * @param string $name The name (local part) of the XML element
  354. * @param string $type The XML schema type (local part) for the element
  355. * @param string $name_ns The namespace for the name of the XML element
  356. * @param string $type_ns The namespace for the type of the element
  357. * @param array $attributes The attributes to serialize as name=>value pairs
  358. * @param string $use The WSDL "use" (encoded|literal)
  359. * @param boolean $soapval Whether this is called from soapval.
  360. * @return string The serialized element, possibly with child elements
  361. * @access public
  362. */
  363. function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
  364. $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
  365. $this->appendDebug('value=' . $this->varDump($val));
  366. $this->appendDebug('attributes=' . $this->varDump($attributes));
  367. if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
  368. $this->debug("serialize_val: serialize soapval");
  369. $xml = $val->serialize($use);
  370. $this->appendDebug($val->getDebug());
  371. $val->clearDebug();
  372. $this->debug("serialize_val of soapval returning $xml");
  373. return $xml;
  374. }
  375. // force valid name if necessary
  376. if (is_numeric($name)) {
  377. $name = '__numeric_' . $name;
  378. } elseif (! $name) {
  379. $name = 'noname';
  380. }
  381. // if name has ns, add ns prefix to name
  382. $xmlns = '';
  383. if($name_ns){
  384. $prefix = 'nu'.rand(1000,9999);
  385. $name = $prefix.':'.$name;
  386. $xmlns .= " xmlns:$prefix=\"$name_ns\"";
  387. }
  388. // if type is prefixed, create type prefix
  389. if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
  390. // need to fix this. shouldn't default to xsd if no ns specified
  391. // w/o checking against typemap
  392. $type_prefix = 'xsd';
  393. } elseif($type_ns){
  394. $type_prefix = 'ns'.rand(1000,9999);
  395. $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
  396. }
  397. // serialize attributes if present
  398. $atts = '';
  399. if($attributes){
  400. foreach($attributes as $k => $v){
  401. $atts .= " $k=\"".$this->expandEntities($v).'"';
  402. }
  403. }
  404. // serialize null value
  405. if (is_null($val)) {
  406. $this->debug("serialize_val: serialize null");
  407. if ($use == 'literal') {
  408. // TODO: depends on minOccurs
  409. $xml = "<$name$xmlns$atts/>";
  410. $this->debug("serialize_val returning $xml");
  411. return $xml;
  412. } else {
  413. if (isset($type) && isset($type_prefix)) {
  414. $type_str = " xsi:type=\"$type_prefix:$type\"";
  415. } else {
  416. $type_str = '';
  417. }
  418. $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
  419. $this->debug("serialize_val returning $xml");
  420. return $xml;
  421. }
  422. }
  423. // serialize if an xsd built-in primitive type
  424. if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
  425. $this->debug("serialize_val: serialize xsd built-in primitive type");
  426. if (is_bool($val)) {
  427. if ($type == 'boolean') {
  428. $val = $val ? 'true' : 'false';
  429. } elseif (! $val) {
  430. $val = 0;
  431. }
  432. } else if (is_string($val)) {
  433. $val = $this->expandEntities($val);
  434. }
  435. if ($use == 'literal') {
  436. $xml = "<$name$xmlns$atts>$val</$name>";
  437. $this->debug("serialize_val returning $xml");
  438. return $xml;
  439. } else {
  440. $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
  441. $this->debug("serialize_val returning $xml");
  442. return $xml;
  443. }
  444. }
  445. // detect type and serialize
  446. $xml = '';
  447. switch(true) {
  448. case (is_bool($val) || $type == 'boolean'):
  449. $this->debug("serialize_val: serialize boolean");
  450. if ($type == 'boolean') {
  451. $val = $val ? 'true' : 'false';
  452. } elseif (! $val) {
  453. $val = 0;
  454. }
  455. if ($use == 'literal') {
  456. $xml .= "<$name$xmlns$atts>$val</$name>";
  457. } else {
  458. $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
  459. }
  460. break;
  461. case (is_int($val) || is_long($val) || $type == 'int'):
  462. $this->debug("serialize_val: serialize int");
  463. if ($use == 'literal') {
  464. $xml .= "<$name$xmlns$atts>$val</$name>";
  465. } else {
  466. $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
  467. }
  468. break;
  469. case (is_float($val)|| is_double($val) || $type == 'float'):
  470. $this->debug("serialize_val: serialize float");
  471. if ($use == 'literal') {
  472. $xml .= "<$name$xmlns$atts>$val</$name>";
  473. } else {
  474. $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
  475. }
  476. break;
  477. case (is_string($val) || $type == 'string'):
  478. $this->debug("serialize_val: serialize string");
  479. $val = $this->expandEntities($val);
  480. if ($use == 'literal') {
  481. $xml .= "<$name$xmlns$atts>$val</$name>";
  482. } else {
  483. $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
  484. }
  485. break;
  486. case is_object($val):
  487. $this->debug("serialize_val: serialize object");
  488. if (get_class($val) == 'soapval') {
  489. $this->debug("serialize_val: serialize soapval object");
  490. $pXml = $val->serialize($use);
  491. $this->appendDebug($val->getDebug());
  492. $val->clearDebug();
  493. } else {
  494. if (! $name) {
  495. $name = get_class($val);
  496. $this->debug("In serialize_val, used class name $name as element name");
  497. } else {
  498. $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
  499. }
  500. foreach(get_object_vars($val) as $k => $v){
  501. $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
  502. }
  503. }
  504. if(isset($type) && isset($type_prefix)){
  505. $type_str = " xsi:type=\"$type_prefix:$type\"";
  506. } else {
  507. $type_str = '';
  508. }
  509. if ($use == 'literal') {
  510. $xml .= "<$name$xmlns$atts>$pXml</$name>";
  511. } else {
  512. $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
  513. }
  514. break;
  515. break;
  516. case (is_array($val) || $type):
  517. // detect if struct or array
  518. $valueType = $this->isArraySimpleOrStruct($val);
  519. if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){
  520. $this->debug("serialize_val: serialize array");
  521. $i = 0;
  522. if(is_array($val) && count($val)> 0){
  523. foreach($val as $v){
  524. if(is_object($v) && get_class($v) == 'soapval'){
  525. $tt_ns = $v->type_ns;
  526. $tt = $v->type;
  527. } elseif (is_array($v)) {
  528. $tt = $this->isArraySimpleOrStruct($v);
  529. } else {
  530. $tt = gettype($v);
  531. }
  532. $array_types[$tt] = 1;
  533. // TODO: for literal, the name should be $name
  534. // @CHANGE This is to have tag name with name reported by wsdl and not "item"
  535. //$xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
  536. $tmp=preg_replace('/s$/i','',$name);
  537. $xml .= $this->serialize_val($v,$tmp?$tmp:'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. * @access public
  938. */
  939. class nusoap_fault extends nusoap_base {
  940. /**
  941. * The fault code (client|server)
  942. * @var string
  943. * @access private
  944. */
  945. var $faultcode;
  946. /**
  947. * The fault actor
  948. * @var string
  949. * @access private
  950. */
  951. var $faultactor;
  952. /**
  953. * The fault string, a description of the fault
  954. * @var string
  955. * @access private
  956. */
  957. var $faultstring;
  958. /**
  959. * The fault detail, typically a string or array of string
  960. * @var mixed
  961. * @access private
  962. */
  963. var $faultdetail;
  964. /**
  965. * constructor
  966. *
  967. * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server)
  968. * @param string $faultactor only used when msg routed between multiple actors
  969. * @param string $faultstring human readable error message
  970. * @param mixed $faultdetail detail, typically a string or array of string
  971. */
  972. function __construct($faultcode,$faultactor='',$faultstring='',$faultdetail=''){
  973. parent::__construct();
  974. $this->faultcode = $faultcode;
  975. $this->faultactor = $faultactor;
  976. $this->faultstring = $faultstring;
  977. $this->faultdetail = $faultdetail;
  978. }
  979. /**
  980. * serialize a fault
  981. *
  982. * @return string The serialization of the fault instance.
  983. * @access public
  984. */
  985. function serialize(){
  986. $ns_string = '';
  987. foreach($this->namespaces as $k => $v){
  988. $ns_string .= "\n xmlns:$k=\"$v\"";
  989. }
  990. $return_msg =
  991. '<?xml version="1.0" encoding="'.$this->soap_defencoding.'"?>'.
  992. '<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"'.$ns_string.">\n".
  993. '<SOAP-ENV:Body>'.
  994. '<SOAP-ENV:Fault>'.
  995. $this->serialize_val($this->faultcode, 'faultcode').
  996. $this->serialize_val($this->faultactor, 'faultactor').
  997. $this->serialize_val($this->faultstring, 'faultstring').
  998. $this->serialize_val($this->faultdetail, 'detail').
  999. '</SOAP-ENV:Fault>'.
  1000. '</SOAP-ENV:Body>'.
  1001. '</SOAP-ENV:Envelope>';
  1002. return $return_msg;
  1003. }
  1004. }
  1005. /**
  1006. * Backward compatibility
  1007. */
  1008. class soap_fault extends nusoap_fault {
  1009. }
  1010. ?><?php
  1011. /**
  1012. * parses an XML Schema, allows access to it's data, other utility methods.
  1013. * imperfect, no validation... yet, but quite functional.
  1014. *
  1015. * @author Dietrich Ayala <dietrich@ganx4.com>
  1016. * @author Scott Nichol <snichol@users.sourceforge.net>
  1017. * @access public
  1018. */
  1019. class nusoap_xmlschema extends nusoap_base {
  1020. // files
  1021. var $schema = '';
  1022. var $xml = '';
  1023. // namespaces
  1024. var $enclosingNamespaces;
  1025. // schema info
  1026. var $schemaInfo = array();
  1027. var $schemaTargetNamespace = '';
  1028. // types, elements, attributes defined by the schema
  1029. var $attributes = array();
  1030. var $complexTypes = array();
  1031. var $complexTypeStack = array();
  1032. var $currentComplexType = null;
  1033. var $elements = array();
  1034. var $elementStack = array();
  1035. var $currentElement = null;
  1036. var $simpleTypes = array();
  1037. var $simpleTypeStack = array();
  1038. var $currentSimpleType = null;
  1039. // imports
  1040. var $imports = array();
  1041. // parser vars
  1042. var $parser;
  1043. var $position = 0;
  1044. var $depth = 0;
  1045. var $depth_array = array();
  1046. var $message = array();
  1047. var $defaultNamespace = array();
  1048. /**
  1049. * constructor
  1050. *
  1051. * @param string $schema schema document URI
  1052. * @param string $xml xml document URI
  1053. * @param string $namespaces namespaces defined in enclosing XML
  1054. * @access public
  1055. */
  1056. function __construct($schema='',$xml='',$namespaces=array()){
  1057. parent::__construct();
  1058. $this->debug('nusoap_xmlschema class instantiated, inside constructor');
  1059. // files
  1060. $this->schema = $schema;
  1061. $this->xml = $xml;
  1062. // namespaces
  1063. $this->enclosingNamespaces = $namespaces;
  1064. $this->namespaces = array_merge($this->namespaces, $namespaces);
  1065. // parse schema file
  1066. if($schema != ''){
  1067. $this->debug('initial schema file: '.$schema);
  1068. $this->parseFile($schema, 'schema');
  1069. }
  1070. // parse xml file
  1071. if($xml != ''){
  1072. $this->debug('initial xml file: '.$xml);
  1073. $this->parseFile($xml, 'xml');
  1074. }
  1075. }
  1076. /**
  1077. * parse an XML file
  1078. *
  1079. * @param string $xml path/URL to XML file
  1080. * @param string $type (schema | xml)
  1081. * @return boolean
  1082. * @access public
  1083. */
  1084. function parseFile($xml,$type){
  1085. // parse xml file
  1086. if($xml != ""){
  1087. $xmlStr = @join("",@file($xml));
  1088. if($xmlStr == ""){
  1089. $msg = 'Error reading XML from '.$xml;
  1090. $this->setError($msg);
  1091. $this->debug($msg);
  1092. return false;
  1093. } else {
  1094. $this->debug("parsing $xml");
  1095. $this->parseString($xmlStr,$type);
  1096. $this->debug("done parsing $xml");
  1097. return true;
  1098. }
  1099. }
  1100. return false;
  1101. }
  1102. /**
  1103. * parse an XML string
  1104. *
  1105. * @param string $xml path or URL
  1106. * @param string $type (schema|xml)
  1107. * @access private
  1108. */
  1109. function parseString($xml,$type){
  1110. // parse xml string
  1111. if($xml != ""){
  1112. // Create an XML parser.
  1113. $this->parser = xml_parser_create();
  1114. // Set the options for parsing the XML data.
  1115. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  1116. // Set the object for the parser.
  1117. xml_set_object($this->parser, $this);
  1118. // Set the element handlers for the parser.
  1119. if($type == "schema"){
  1120. xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement');
  1121. xml_set_character_data_handler($this->parser,'schemaCharacterData');
  1122. } elseif($type == "xml"){
  1123. xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement');
  1124. xml_set_character_data_handler($this->parser,'xmlCharacterData');
  1125. }
  1126. // Parse the XML file.
  1127. if(!xml_parse($this->parser,$xml,true)){
  1128. // Display an error message.
  1129. $errstr = sprintf('XML error parsing XML schema on line %d: %s',
  1130. xml_get_current_line_number($this->parser),
  1131. xml_error_string(xml_get_error_code($this->parser))
  1132. );
  1133. $this->debug($errstr);
  1134. $this->debug("XML payload:\n" . $xml);
  1135. $this->setError($errstr);
  1136. }
  1137. xml_parser_free($this->parser);
  1138. } else{
  1139. $this->debug('no xml passed to parseString()!!');
  1140. $this->setError('no xml passed to parseString()!!');
  1141. }
  1142. }
  1143. /**
  1144. * gets a type name for an unnamed type
  1145. *
  1146. * @param string Element name
  1147. * @return string A type name for an unnamed type
  1148. * @access private
  1149. */
  1150. function CreateTypeName($ename) {
  1151. $scope = '';
  1152. for ($i = 0; $i < count($this->complexTypeStack); $i++) {
  1153. $scope .= $this->complexTypeStack[$i] . '_';
  1154. }
  1155. return $scope . $ename . '_ContainedType';
  1156. }
  1157. /**
  1158. * start-element handler
  1159. *
  1160. * @param string $parser XML parser object
  1161. * @param string $name element name
  1162. * @param string $attrs associative array of attributes
  1163. * @access private
  1164. */
  1165. function schemaStartElement($parser, $name, $attrs) {
  1166. // position in the total number of elements, starting from 0
  1167. $pos = $this->position++;
  1168. $depth = $this->depth++;
  1169. // set self as current value for this depth
  1170. $this->depth_array[$depth] = $pos;
  1171. $this->message[$pos] = array('cdata' => '');
  1172. if ($depth > 0) {
  1173. $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
  1174. } else {
  1175. $this->defaultNamespace[$pos] = false;
  1176. }
  1177. // get element prefix
  1178. if($prefix = $this->getPrefix($name)){
  1179. // get unqualified name
  1180. $name = $this->getLocalPart($name);
  1181. } else {
  1182. $prefix = '';
  1183. }
  1184. // loop thru attributes, expanding, and registering namespace declarations
  1185. if(count($attrs) > 0){
  1186. foreach($attrs as $k => $v){
  1187. // if ns declarations, add to class level array of valid namespaces
  1188. if(preg_match('/^xmlns/',$k)){
  1189. //$this->xdebug("$k: $v");
  1190. //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
  1191. if($ns_prefix = substr(strrchr($k,':'),1)){
  1192. //$this->xdebug("Add namespace[$ns_prefix] = $v");
  1193. $this->namespaces[$ns_prefix] = $v;
  1194. } else {
  1195. $this->defaultNamespace[$pos] = $v;
  1196. if (! $this->getPrefixFromNamespace($v)) {
  1197. $this->namespaces['ns'.(count($this->namespaces)+1)] = $v;
  1198. }
  1199. }
  1200. if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){
  1201. $this->XMLSchemaVersion = $v;
  1202. $this->namespaces['xsi'] = $v.'-instance';
  1203. }
  1204. }
  1205. }
  1206. foreach($attrs as $k => $v){
  1207. // expand each attribute
  1208. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  1209. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  1210. $eAttrs[$k] = $v;
  1211. }
  1212. $attrs = $eAttrs;
  1213. } else {
  1214. $attrs = array();
  1215. }
  1216. // find status, register data
  1217. switch($name){
  1218. case 'all': // (optional) compositor content for a complexType
  1219. case 'choice':
  1220. case 'group':
  1221. case 'sequence':
  1222. //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
  1223. $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
  1224. //if($name == 'all' || $name == 'sequence'){
  1225. // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  1226. //}
  1227. break;
  1228. case 'attribute': // complexType attribute
  1229. //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
  1230. $this->xdebug("parsing attribute:");
  1231. $this->appendDebug($this->varDump($attrs));
  1232. if (!isset($attrs['form'])) {
  1233. // TODO: handle globals
  1234. $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
  1235. }
  1236. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
  1237. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1238. if (!strpos($v, ':')) {
  1239. // no namespace in arrayType attribute value...
  1240. if ($this->defaultNamespace[$pos]) {
  1241. // ...so use the default
  1242. $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1243. }
  1244. }
  1245. }
  1246. if(isset($attrs['name'])){
  1247. $this->attributes[$attrs['name']] = $attrs;
  1248. $aname = $attrs['name'];
  1249. } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){
  1250. if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
  1251. $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1252. } else {
  1253. $aname = '';
  1254. }
  1255. } elseif(isset($attrs['ref'])){
  1256. $aname = $attrs['ref'];
  1257. $this->attributes[$attrs['ref']] = $attrs;
  1258. }
  1259. if($this->currentComplexType){ // This should *always* be
  1260. $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
  1261. }
  1262. // arrayType attribute
  1263. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){
  1264. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1265. $prefix = $this->getPrefix($aname);
  1266. if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){
  1267. $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
  1268. } else {
  1269. $v = '';
  1270. }
  1271. if(strpos($v,'[,]')){
  1272. $this->complexTypes[$this->currentComplexType]['multidimensional'] = true;
  1273. }
  1274. $v = substr($v,0,strpos($v,'[')); // clip the []
  1275. if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){
  1276. $v = $this->XMLSchemaVersion.':'.$v;
  1277. }
  1278. $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
  1279. }
  1280. break;
  1281. case 'complexContent': // (optional) content for a complexType
  1282. $this->xdebug("do nothing for element $name");
  1283. break;
  1284. case 'complexType':
  1285. array_push($this->complexTypeStack, $this->currentComplexType);
  1286. if(isset($attrs['name'])){
  1287. // TODO: what is the scope of named complexTypes that appear
  1288. // nested within other c complexTypes?
  1289. $this->xdebug('processing named complexType '.$attrs['name']);
  1290. //$this->currentElement = false;
  1291. $this->currentComplexType = $attrs['name'];
  1292. $this->complexTypes[$this->currentComplexType] = $attrs;
  1293. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
  1294. // This is for constructs like
  1295. // <complexType name="ListOfString" base="soap:Array">
  1296. // <sequence>
  1297. // <element name="string" type="xsd:string"
  1298. // minOccurs="0" maxOccurs="unbounded" />
  1299. // </sequence>
  1300. // </complexType>
  1301. if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
  1302. $this->xdebug('complexType is unusual array');
  1303. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1304. } else {
  1305. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  1306. }
  1307. } else {
  1308. $name = $this->CreateTypeName($this->currentElement);
  1309. $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
  1310. $this->currentComplexType = $name;
  1311. //$this->currentElement = false;
  1312. $this->complexTypes[$this->currentComplexType] = $attrs;
  1313. $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
  1314. // This is for constructs like
  1315. // <complexType name="ListOfString" base="soap:Array">
  1316. // <sequence>
  1317. // <element name="string" type="xsd:string"
  1318. // minOccurs="0" maxOccurs="unbounded" />
  1319. // </sequence>
  1320. // </complexType>
  1321. if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){
  1322. $this->xdebug('complexType is unusual array');
  1323. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1324. } else {
  1325. $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
  1326. }
  1327. }
  1328. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
  1329. break;
  1330. case 'element':
  1331. array_push($this->elementStack, $this->currentElement);
  1332. if (!isset($attrs['form'])) {
  1333. if ($this->currentComplexType) {
  1334. $attrs['form'] = $this->schemaInfo['elementFormDefault'];
  1335. } else {
  1336. // global
  1337. $attrs['form'] = 'qualified';
  1338. }
  1339. }
  1340. if(isset($attrs['type'])){
  1341. $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']);
  1342. if (! $this->getPrefix($attrs['type'])) {
  1343. if ($this->defaultNamespace[$pos]) {
  1344. $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
  1345. $this->xdebug('used default namespace to make type ' . $attrs['type']);
  1346. }
  1347. }
  1348. // This is for constructs like
  1349. // <complexType name="ListOfString" base="soap:Array">
  1350. // <sequence>
  1351. // <element name="string" type="xsd:string"
  1352. // minOccurs="0" maxOccurs="unbounded" />
  1353. // </sequence>
  1354. // </complexType>
  1355. if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
  1356. $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
  1357. $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
  1358. }
  1359. $this->currentElement = $attrs['name'];
  1360. $ename = $attrs['name'];
  1361. } elseif(isset($attrs['ref'])){
  1362. $this->xdebug("processing element as ref to ".$attrs['ref']);
  1363. $this->currentElement = "ref to ".$attrs['ref'];
  1364. $ename = $this->getLocalPart($attrs['ref']);
  1365. } else {
  1366. $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
  1367. $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
  1368. $this->currentElement = $attrs['name'];
  1369. $attrs['type'] = $this->schemaTargetNamespace . ':' . $type;
  1370. $ename = $attrs['name'];
  1371. }
  1372. if (isset($ename) && $this->currentComplexType) {
  1373. $this->xdebug("add element $ename to complexType $this->currentComplexType");
  1374. $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
  1375. } elseif (!isset($attrs['ref'])) {
  1376. $this->xdebug("add element $ename to elements array");
  1377. $this->elements[ $attrs['name'] ] = $attrs;
  1378. $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
  1379. }
  1380. break;
  1381. case 'enumeration': // restriction value list member
  1382. $this->xdebug('enumeration ' . $attrs['value']);
  1383. if ($this->currentSimpleType) {
  1384. $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
  1385. } elseif ($this->currentComplexType) {
  1386. $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
  1387. }
  1388. break;
  1389. case 'extension': // simpleContent or complexContent type extension
  1390. $this->xdebug('extension ' . $attrs['base']);
  1391. if ($this->currentComplexType) {
  1392. $ns = $this->getPrefix($attrs['base']);
  1393. if ($ns == '') {
  1394. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
  1395. } else {
  1396. $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
  1397. }
  1398. } else {
  1399. $this->xdebug('no current complexType to set extensionBase');
  1400. }
  1401. break;
  1402. case 'import':
  1403. if (isset($attrs['schemaLocation'])) {
  1404. $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
  1405. $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
  1406. } else {
  1407. $this->xdebug('import namespace ' . $attrs['namespace']);
  1408. $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
  1409. if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
  1410. $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
  1411. }
  1412. }
  1413. break;
  1414. case 'include':
  1415. if (isset($attrs['schemaLocation'])) {
  1416. $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
  1417. $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false);
  1418. } else {
  1419. $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
  1420. }
  1421. break;
  1422. case 'list': // simpleType value list
  1423. $this->xdebug("do nothing for element $name");
  1424. break;
  1425. case 'restriction': // simpleType, simpleContent or complexContent value restriction
  1426. $this->xdebug('restriction ' . $attrs['base']);
  1427. if($this->currentSimpleType){
  1428. $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
  1429. } elseif($this->currentComplexType){
  1430. $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
  1431. if(strstr($attrs['base'],':') == ':Array'){
  1432. $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
  1433. }
  1434. }
  1435. break;
  1436. case 'schema':
  1437. $this->schemaInfo = $attrs;
  1438. $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
  1439. if (isset($attrs['targetNamespace'])) {
  1440. $this->schemaTargetNamespace = $attrs['targetNamespace'];
  1441. }
  1442. if (!isset($attrs['elementFormDefault'])) {
  1443. $this->schemaInfo['elementFormDefault'] = 'unqualified';
  1444. }
  1445. if (!isset($attrs['attributeFormDefault'])) {
  1446. $this->schemaInfo['attributeFormDefault'] = 'unqualified';
  1447. }
  1448. break;
  1449. case 'simpleContent': // (optional) content for a complexType
  1450. if ($this->currentComplexType) { // This should *always* be
  1451. $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
  1452. } else {
  1453. $this->xdebug("do nothing for element $name because there is no current complexType");
  1454. }
  1455. break;
  1456. case 'simpleType':
  1457. array_push($this->simpleTypeStack, $this->currentSimpleType);
  1458. if(isset($attrs['name'])){
  1459. $this->xdebug("processing simpleType for name " . $attrs['name']);
  1460. $this->currentSimpleType = $attrs['name'];
  1461. $this->simpleTypes[ $attrs['name'] ] = $attrs;
  1462. $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType';
  1463. $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar';
  1464. } else {
  1465. $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
  1466. $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
  1467. $this->currentSimpleType = $name;
  1468. //$this->currentElement = false;
  1469. $this->simpleTypes[$this->currentSimpleType] = $attrs;
  1470. $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
  1471. }
  1472. break;
  1473. case 'union': // simpleType type list
  1474. $this->xdebug("do nothing for element $name");
  1475. break;
  1476. default:
  1477. $this->xdebug("do not have any logic to process element $name");
  1478. }
  1479. }
  1480. /**
  1481. * end-element handler
  1482. *
  1483. * @param string $parser XML parser object
  1484. * @param string $name element name
  1485. * @access private
  1486. */
  1487. function schemaEndElement($parser, $name) {
  1488. // bring depth down a notch
  1489. $this->depth--;
  1490. // position of current element is equal to the last value left in depth_array for my depth
  1491. if(isset($this->depth_array[$this->depth])){
  1492. $pos = $this->depth_array[$this->depth];
  1493. }
  1494. // get element prefix
  1495. if ($prefix = $this->getPrefix($name)){
  1496. // get unqualified name
  1497. $name = $this->getLocalPart($name);
  1498. } else {
  1499. $prefix = '';
  1500. }
  1501. // move on...
  1502. if($name == 'complexType'){
  1503. $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)'));
  1504. $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType]));
  1505. $this->currentComplexType = array_pop($this->complexTypeStack);
  1506. //$this->currentElement = false;
  1507. }
  1508. if($name == 'element'){
  1509. $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)'));
  1510. $this->currentElement = array_pop($this->elementStack);
  1511. }
  1512. if($name == 'simpleType'){
  1513. $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)'));
  1514. $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType]));
  1515. $this->currentSimpleType = array_pop($this->simpleTypeStack);
  1516. }
  1517. }
  1518. /**
  1519. * element content handler
  1520. *
  1521. * @param string $parser XML parser object
  1522. * @param string $data element content
  1523. * @access private
  1524. */
  1525. function schemaCharacterData($parser, $data){
  1526. $pos = $this->depth_array[$this->depth - 1];
  1527. $this->message[$pos]['cdata'] .= $data;
  1528. }
  1529. /**
  1530. * serialize the schema
  1531. *
  1532. * @access public
  1533. */
  1534. function serializeSchema(){
  1535. $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion);
  1536. $xml = '';
  1537. // imports
  1538. if (sizeof($this->imports) > 0) {
  1539. foreach($this->imports as $ns => $list) {
  1540. foreach ($list as $ii) {
  1541. if ($ii['location'] != '') {
  1542. $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n";
  1543. } else {
  1544. $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n";
  1545. }
  1546. }
  1547. }
  1548. }
  1549. // complex types
  1550. foreach($this->complexTypes as $typeName => $attrs){
  1551. $contentStr = '';
  1552. // serialize child elements
  1553. if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){
  1554. foreach($attrs['elements'] as $element => $eParts){
  1555. if(isset($eParts['ref'])){
  1556. $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n";
  1557. } else {
  1558. $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"";
  1559. foreach ($eParts as $aName => $aValue) {
  1560. // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable
  1561. if ($aName != 'name' && $aName != 'type') {
  1562. $contentStr .= " $aName=\"$aValue\"";
  1563. }
  1564. }
  1565. $contentStr .= "/>\n";
  1566. }
  1567. }
  1568. // compositor wraps elements
  1569. if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) {
  1570. $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n";
  1571. }
  1572. }
  1573. // attributes
  1574. if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){
  1575. foreach($attrs['attrs'] as $attr => $aParts){
  1576. $contentStr .= " <$schemaPrefix:attribute";
  1577. foreach ($aParts as $a => $v) {
  1578. if ($a == 'ref' || $a == 'type') {
  1579. $contentStr .= " $a=\"".$this->contractQName($v).'"';
  1580. } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') {
  1581. $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl'];
  1582. $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"';
  1583. } else {
  1584. $contentStr .= " $a=\"$v\"";
  1585. }
  1586. }
  1587. $contentStr .= "/>\n";
  1588. }
  1589. }
  1590. // if restriction
  1591. if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){
  1592. $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n";
  1593. // complex or simple content
  1594. if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){
  1595. $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n";
  1596. }
  1597. }
  1598. // finalize complex type
  1599. if($contentStr != ''){
  1600. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n";
  1601. } else {
  1602. $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n";
  1603. }
  1604. $xml .= $contentStr;
  1605. }
  1606. // simple types
  1607. if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){
  1608. foreach($this->simpleTypes as $typeName => $eParts){
  1609. $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n";
  1610. if (isset($eParts['enumeration'])) {
  1611. foreach ($eParts['enumeration'] as $e) {
  1612. $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n";
  1613. }
  1614. }
  1615. $xml .= " </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>";
  1616. }
  1617. }
  1618. // elements
  1619. if(isset($this->elements) && count($this->elements) > 0){
  1620. foreach($this->elements as $element => $eParts){
  1621. $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n";
  1622. }
  1623. }
  1624. // attributes
  1625. if(isset($this->attributes) && count($this->attributes) > 0){
  1626. foreach($this->attributes as $attr => $aParts){
  1627. $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>";
  1628. }
  1629. }
  1630. // finish 'er up
  1631. $attr = '';
  1632. foreach ($this->schemaInfo as $k => $v) {
  1633. if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') {
  1634. $attr .= " $k=\"$v\"";
  1635. }
  1636. }
  1637. $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n";
  1638. foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) {
  1639. $el .= " xmlns:$nsp=\"$ns\"";
  1640. }
  1641. $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n";
  1642. return $xml;
  1643. }
  1644. /**
  1645. * adds debug data to the clas level debug string
  1646. *
  1647. * @param string $string debug data
  1648. * @access private
  1649. */
  1650. function xdebug($string){
  1651. $this->debug('<' . $this->schemaTargetNamespace . '> '.$string);
  1652. }
  1653. /**
  1654. * get the PHP type of a user defined type in the schema
  1655. * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays
  1656. * returns false if no type exists, or not w/ the given namespace
  1657. * else returns a string that is either a native php type, or 'struct'
  1658. *
  1659. * @param string $type name of defined type
  1660. * @param string $ns namespace of type
  1661. * @return mixed
  1662. * @access public
  1663. * @deprecated
  1664. */
  1665. function getPHPType($type,$ns){
  1666. if(isset($this->typemap[$ns][$type])){
  1667. //print "found type '$type' and ns $ns in typemap<br>";
  1668. return $this->typemap[$ns][$type];
  1669. } elseif(isset($this->complexTypes[$type])){
  1670. //print "getting type '$type' and ns $ns from complexTypes array<br>";
  1671. return $this->complexTypes[$type]['phpType'];
  1672. }
  1673. return false;
  1674. }
  1675. /**
  1676. * returns an associative array of information about a given type
  1677. * returns false if no type exists by the given name
  1678. *
  1679. * For a complexType typeDef = array(
  1680. * 'restrictionBase' => '',
  1681. * 'phpType' => '',
  1682. * 'compositor' => '(sequence|all)',
  1683. * 'elements' => array(), // refs to elements array
  1684. * 'attrs' => array() // refs to attributes array
  1685. * ... and so on (see addComplexType)
  1686. * )
  1687. *
  1688. * For simpleType or element, the array has different keys.
  1689. *
  1690. * @param string $type
  1691. * @return mixed
  1692. * @access public
  1693. * @see addComplexType
  1694. * @see addSimpleType
  1695. * @see addElement
  1696. */
  1697. function getTypeDef($type){
  1698. //$this->debug("in getTypeDef for type $type");
  1699. if (substr($type, -1) == '^') {
  1700. $is_element = 1;
  1701. $type = substr($type, 0, -1);
  1702. } else {
  1703. $is_element = 0;
  1704. }
  1705. if((! $is_element) && isset($this->complexTypes[$type])){
  1706. $this->xdebug("in getTypeDef, found complexType $type");
  1707. return $this->complexTypes[$type];
  1708. } elseif((! $is_element) && isset($this->simpleTypes[$type])){
  1709. $this->xdebug("in getTypeDef, found simpleType $type");
  1710. if (!isset($this->simpleTypes[$type]['phpType'])) {
  1711. // get info for type to tack onto the simple type
  1712. // TODO: can this ever really apply (i.e. what is a simpleType really?)
  1713. $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1);
  1714. $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':'));
  1715. $etype = $this->getTypeDef($uqType);
  1716. if ($etype) {
  1717. $this->xdebug("in getTypeDef, found type for simpleType $type:");
  1718. $this->xdebug($this->varDump($etype));
  1719. if (isset($etype['phpType'])) {
  1720. $this->simpleTypes[$type]['phpType'] = $etype['phpType'];
  1721. }
  1722. if (isset($etype['elements'])) {
  1723. $this->simpleTypes[$type]['elements'] = $etype['elements'];
  1724. }
  1725. }
  1726. }
  1727. return $this->simpleTypes[$type];
  1728. } elseif(isset($this->elements[$type])){
  1729. $this->xdebug("in getTypeDef, found element $type");
  1730. if (!isset($this->elements[$type]['phpType'])) {
  1731. // get info for type to tack onto the element
  1732. $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1);
  1733. $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':'));
  1734. $etype = $this->getTypeDef($uqType);
  1735. if ($etype) {
  1736. $this->xdebug("in getTypeDef, found type for element $type:");
  1737. $this->xdebug($this->varDump($etype));
  1738. if (isset($etype['phpType'])) {
  1739. $this->elements[$type]['phpType'] = $etype['phpType'];
  1740. }
  1741. if (isset($etype['elements'])) {
  1742. $this->elements[$type]['elements'] = $etype['elements'];
  1743. }
  1744. if (isset($etype['extensionBase'])) {
  1745. $this->elements[$type]['extensionBase'] = $etype['extensionBase'];
  1746. }
  1747. } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') {
  1748. $this->xdebug("in getTypeDef, element $type is an XSD type");
  1749. $this->elements[$type]['phpType'] = 'scalar';
  1750. }
  1751. }
  1752. return $this->elements[$type];
  1753. } elseif(isset($this->attributes[$type])){
  1754. $this->xdebug("in getTypeDef, found attribute $type");
  1755. return $this->attributes[$type];
  1756. } elseif (preg_match('/_ContainedType$/', $type)) {
  1757. $this->xdebug("in getTypeDef, have an untyped element $type");
  1758. $typeDef['typeClass'] = 'simpleType';
  1759. $typeDef['phpType'] = 'scalar';
  1760. $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string';
  1761. return $typeDef;
  1762. }
  1763. $this->xdebug("in getTypeDef, did not find $type");
  1764. return false;
  1765. }
  1766. /**
  1767. * returns a sample serialization of a given type, or false if no type by the given name
  1768. *
  1769. * @param string $type name of type
  1770. * @return mixed
  1771. * @access public
  1772. * @deprecated
  1773. */
  1774. function serializeTypeDef($type){
  1775. //print "in sTD() for type $type<br>";
  1776. if($typeDef = $this->getTypeDef($type)){
  1777. $str .= '<'.$type;
  1778. if(is_array($typeDef['attrs'])){
  1779. foreach($typeDef['attrs'] as $attName => $data){
  1780. $str .= " $attName=\"{type = ".$data['type']."}\"";
  1781. }
  1782. }
  1783. $str .= " xmlns=\"".$this->schema['targetNamespace']."\"";
  1784. if(count($typeDef['elements']) > 0){
  1785. $str .= ">";
  1786. foreach($typeDef['elements'] as $element => $eData){
  1787. $str .= $this->serializeTypeDef($element);
  1788. }
  1789. $str .= "</$type>";
  1790. } elseif($typeDef['typeClass'] == 'element') {
  1791. $str .= "></$type>";
  1792. } else {
  1793. $str .= "/>";
  1794. }
  1795. return $str;
  1796. }
  1797. return false;
  1798. }
  1799. /**
  1800. * returns HTML form elements that allow a user
  1801. * to enter values for creating an instance of the given type.
  1802. *
  1803. * @param string $name name for type instance
  1804. * @param string $type name of type
  1805. * @return string
  1806. * @access public
  1807. * @deprecated
  1808. */
  1809. function typeToForm($name,$type){
  1810. // get typedef
  1811. if($typeDef = $this->getTypeDef($type)){
  1812. // if struct
  1813. if($typeDef['phpType'] == 'struct'){
  1814. $buffer .= '<table>';
  1815. foreach($typeDef['elements'] as $child => $childDef){
  1816. $buffer .= "
  1817. <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td>
  1818. <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>";
  1819. }
  1820. $buffer .= '</table>';
  1821. // if array
  1822. } elseif($typeDef['phpType'] == 'array'){
  1823. $buffer .= '<table>';
  1824. for($i=0;$i < 3; $i++){
  1825. $buffer .= "
  1826. <tr><td align='right'>array item (type: $typeDef[arrayType]):</td>
  1827. <td><input type='text' name='parameters[".$name."][]'></td></tr>";
  1828. }
  1829. $buffer .= '</table>';
  1830. // if scalar
  1831. } else {
  1832. $buffer .= "<input type='text' name='parameters[$name]'>";
  1833. }
  1834. } else {
  1835. $buffer .= "<input type='text' name='parameters[$name]'>";
  1836. }
  1837. return $buffer;
  1838. }
  1839. /**
  1840. * adds a complex type to the schema
  1841. *
  1842. * example: array
  1843. *
  1844. * addType(
  1845. * 'ArrayOfstring',
  1846. * 'complexType',
  1847. * 'array',
  1848. * '',
  1849. * 'SOAP-ENC:Array',
  1850. * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'),
  1851. * 'xsd:string'
  1852. * );
  1853. *
  1854. * example: PHP associative array ( SOAP Struct )
  1855. *
  1856. * addType(
  1857. * 'SOAPStruct',
  1858. * 'complexType',
  1859. * 'struct',
  1860. * 'all',
  1861. * array('myVar'=> array('name'=>'myVar','type'=>'string')
  1862. * );
  1863. *
  1864. * @param name
  1865. * @param typeClass (complexType|simpleType|attribute)
  1866. * @param phpType: currently supported are array and struct (php assoc array)
  1867. * @param compositor (all|sequence|choice)
  1868. * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  1869. * @param elements = array ( name = array(name=>'',type=>'') )
  1870. * @param attrs = array(
  1871. * array(
  1872. * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType",
  1873. * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]"
  1874. * )
  1875. * )
  1876. * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
  1877. * @access public
  1878. * @see getTypeDef
  1879. */
  1880. function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){
  1881. $this->complexTypes[$name] = array(
  1882. 'name' => $name,
  1883. 'typeClass' => $typeClass,
  1884. 'phpType' => $phpType,
  1885. 'compositor'=> $compositor,
  1886. 'restrictionBase' => $restrictionBase,
  1887. 'elements' => $elements,
  1888. 'attrs' => $attrs,
  1889. 'arrayType' => $arrayType
  1890. );
  1891. $this->xdebug("addComplexType $name:");
  1892. $this->appendDebug($this->varDump($this->complexTypes[$name]));
  1893. }
  1894. /**
  1895. * adds a simple type to the schema
  1896. *
  1897. * @param string $name
  1898. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  1899. * @param string $typeClass (should always be simpleType)
  1900. * @param string $phpType (should always be scalar)
  1901. * @param array $enumeration array of values
  1902. * @access public
  1903. * @see nusoap_xmlschema
  1904. * @see getTypeDef
  1905. */
  1906. function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
  1907. $this->simpleTypes[$name] = array(
  1908. 'name' => $name,
  1909. 'typeClass' => $typeClass,
  1910. 'phpType' => $phpType,
  1911. 'type' => $restrictionBase,
  1912. 'enumeration' => $enumeration
  1913. );
  1914. $this->xdebug("addSimpleType $name:");
  1915. $this->appendDebug($this->varDump($this->simpleTypes[$name]));
  1916. }
  1917. /**
  1918. * adds an element to the schema
  1919. *
  1920. * @param array $attrs attributes that must include name and type
  1921. * @see nusoap_xmlschema
  1922. * @access public
  1923. */
  1924. function addElement($attrs) {
  1925. if (! $this->getPrefix($attrs['type'])) {
  1926. $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type'];
  1927. }
  1928. $this->elements[ $attrs['name'] ] = $attrs;
  1929. $this->elements[ $attrs['name'] ]['typeClass'] = 'element';
  1930. $this->xdebug("addElement " . $attrs['name']);
  1931. $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ]));
  1932. }
  1933. }
  1934. /**
  1935. * Backward compatibility
  1936. */
  1937. class XMLSchema extends nusoap_xmlschema {
  1938. }
  1939. ?><?php
  1940. /**
  1941. * For creating serializable abstractions of native PHP types. This class
  1942. * allows element name/namespace, XSD type, and XML attributes to be
  1943. * associated with a value. This is extremely useful when WSDL is not
  1944. * used, but is also useful when WSDL is used with polymorphic types, including
  1945. * xsd:anyType and user-defined types.
  1946. *
  1947. * @author Dietrich Ayala <dietrich@ganx4.com>
  1948. * @access public
  1949. */
  1950. class soapval extends nusoap_base {
  1951. /**
  1952. * The XML element name
  1953. *
  1954. * @var string
  1955. * @access private
  1956. */
  1957. var $name;
  1958. /**
  1959. * The XML type name (string or false)
  1960. *
  1961. * @var mixed
  1962. * @access private
  1963. */
  1964. var $type;
  1965. /**
  1966. * The PHP value
  1967. *
  1968. * @var mixed
  1969. * @access private
  1970. */
  1971. var $value;
  1972. /**
  1973. * The XML element namespace (string or false)
  1974. *
  1975. * @var mixed
  1976. * @access private
  1977. */
  1978. var $element_ns;
  1979. /**
  1980. * The XML type namespace (string or false)
  1981. *
  1982. * @var mixed
  1983. * @access private
  1984. */
  1985. var $type_ns;
  1986. /**
  1987. * The XML element attributes (array or false)
  1988. *
  1989. * @var mixed
  1990. * @access private
  1991. */
  1992. var $attributes;
  1993. /**
  1994. * constructor
  1995. *
  1996. * @param string $name optional name
  1997. * @param mixed $type optional type name
  1998. * @param mixed $value optional value
  1999. * @param mixed $element_ns optional namespace of value
  2000. * @param mixed $type_ns optional namespace of type
  2001. * @param mixed $attributes associative array of attributes to add to element serialization
  2002. * @access public
  2003. */
  2004. function __construct($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) {
  2005. parent::__construct();
  2006. $this->name = $name;
  2007. $this->type = $type;
  2008. $this->value = $value;
  2009. $this->element_ns = $element_ns;
  2010. $this->type_ns = $type_ns;
  2011. $this->attributes = $attributes;
  2012. }
  2013. /**
  2014. * return serialized value
  2015. *
  2016. * @param string $use The WSDL use value (encoded|literal)
  2017. * @return string XML data
  2018. * @access public
  2019. */
  2020. function serialize($use='encoded') {
  2021. return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true);
  2022. }
  2023. /**
  2024. * decodes a soapval object into a PHP native type
  2025. *
  2026. * @return mixed
  2027. * @access public
  2028. */
  2029. function decode(){
  2030. return $this->value;
  2031. }
  2032. }
  2033. ?><?php
  2034. /**
  2035. * transport class for sending/receiving data via HTTP and HTTPS
  2036. * NOTE: PHP must be compiled with the CURL extension for HTTPS support
  2037. *
  2038. * @author Dietrich Ayala <dietrich@ganx4.com>
  2039. * @author Scott Nichol <snichol@users.sourceforge.net>
  2040. * @access public
  2041. */
  2042. class soap_transport_http extends nusoap_base {
  2043. var $url = '';
  2044. var $uri = '';
  2045. var $digest_uri = '';
  2046. var $scheme = '';
  2047. var $host = '';
  2048. var $port = '';
  2049. var $path = '';
  2050. var $request_method = 'POST';
  2051. var $protocol_version = '1.0';
  2052. var $encoding = '';
  2053. var $outgoing_headers = array();
  2054. var $incoming_headers = array();
  2055. var $incoming_cookies = array();
  2056. var $outgoing_payload = '';
  2057. var $incoming_payload = '';
  2058. var $response_status_line; // HTTP response status line
  2059. var $useSOAPAction = true;
  2060. var $persistentConnection = false;
  2061. var $ch = false; // cURL handle
  2062. var $ch_options = array(); // cURL custom options
  2063. var $use_curl = false; // force cURL use
  2064. var $proxy = null; // proxy information (associative array)
  2065. var $username = '';
  2066. var $password = '';
  2067. var $authtype = '';
  2068. var $digestRequest = array();
  2069. var $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional)
  2070. // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem'
  2071. // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem'
  2072. // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem'
  2073. // passphrase: SSL key password/passphrase
  2074. // certpassword: SSL certificate password
  2075. // verifypeer: default is 1
  2076. // verifyhost: default is 1
  2077. /**
  2078. * constructor
  2079. *
  2080. * @param string $url The URL to which to connect
  2081. * @param array $curl_options User-specified cURL options
  2082. * @param boolean $use_curl Whether to try to force cURL use
  2083. * @access public
  2084. */
  2085. function __construct($url, $curl_options = NULL, $use_curl = false){
  2086. parent::__construct();
  2087. $this->debug("ctor url=$url use_curl=$use_curl curl_options:");
  2088. $this->appendDebug($this->varDump($curl_options));
  2089. $this->setURL($url);
  2090. if (is_array($curl_options)) {
  2091. $this->ch_options = $curl_options;
  2092. }
  2093. $this->use_curl = $use_curl;
  2094. preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev);
  2095. $this->setHeader('User-Agent', $this->title.'/'.$this->version.(isset($rev[1])?' ('.$rev[1].')':''));
  2096. }
  2097. /**
  2098. * sets a cURL option
  2099. *
  2100. * @param mixed $option The cURL option (always integer?)
  2101. * @param mixed $value The cURL option value
  2102. * @access private
  2103. */
  2104. function setCurlOption($option, $value) {
  2105. $this->debug("setCurlOption option=$option, value=");
  2106. $this->appendDebug($this->varDump($value));
  2107. curl_setopt($this->ch, $option, $value);
  2108. }
  2109. /**
  2110. * sets an HTTP header
  2111. *
  2112. * @param string $name The name of the header
  2113. * @param string $value The value of the header
  2114. * @access private
  2115. */
  2116. function setHeader($name, $value) {
  2117. $this->outgoing_headers[$name] = $value;
  2118. $this->debug("set header $name: $value");
  2119. }
  2120. /**
  2121. * unsets an HTTP header
  2122. *
  2123. * @param string $name The name of the header
  2124. * @access private
  2125. */
  2126. function unsetHeader($name) {
  2127. if (isset($this->outgoing_headers[$name])) {
  2128. $this->debug("unset header $name");
  2129. unset($this->outgoing_headers[$name]);
  2130. }
  2131. }
  2132. /**
  2133. * sets the URL to which to connect
  2134. *
  2135. * @param string $url The URL to which to connect
  2136. * @access private
  2137. */
  2138. function setURL($url) {
  2139. $this->url = $url;
  2140. $u = parse_url($url);
  2141. foreach($u as $k => $v){
  2142. $this->debug("parsed URL $k = $v");
  2143. $this->$k = $v;
  2144. }
  2145. // add any GET params to path
  2146. if(isset($u['query']) && $u['query'] != ''){
  2147. $this->path .= '?' . $u['query'];
  2148. }
  2149. // set default port
  2150. if(!isset($u['port'])){
  2151. if($u['scheme'] == 'https'){
  2152. $this->port = 443;
  2153. } else {
  2154. $this->port = 80;
  2155. }
  2156. }
  2157. $this->uri = $this->path;
  2158. $this->digest_uri = $this->uri;
  2159. // build headers
  2160. if (!isset($u['port'])) {
  2161. $this->setHeader('Host', $this->host);
  2162. } else {
  2163. $this->setHeader('Host', $this->host.':'.$this->port);
  2164. }
  2165. if (isset($u['user']) && $u['user'] != '') {
  2166. $this->setCredentials(urldecode($u['user']), isset($u['pass']) ? urldecode($u['pass']) : '');
  2167. }
  2168. }
  2169. /**
  2170. * gets the I/O method to use
  2171. *
  2172. * @return string I/O method to use (socket|curl|unknown)
  2173. * @access private
  2174. */
  2175. function io_method() {
  2176. if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm'))
  2177. return 'curl';
  2178. if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm'))
  2179. return 'socket';
  2180. return 'unknown';
  2181. }
  2182. /**
  2183. * establish an HTTP connection
  2184. *
  2185. * @param integer $timeout set connection timeout in seconds
  2186. * @param integer $response_timeout set response timeout in seconds
  2187. * @return boolean true if connected, false if not
  2188. * @access private
  2189. */
  2190. function connect($connection_timeout=0,$response_timeout=30){
  2191. // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
  2192. // "regular" socket.
  2193. // TODO: disabled for now because OpenSSL must be *compiled* in (not just
  2194. // loaded), and until PHP5 stream_get_wrappers is not available.
  2195. // if ($this->scheme == 'https') {
  2196. // if (version_compare(phpversion(), '4.3.0') >= 0) {
  2197. // if (extension_loaded('openssl')) {
  2198. // $this->scheme = 'ssl';
  2199. // $this->debug('Using SSL over OpenSSL');
  2200. // }
  2201. // }
  2202. // }
  2203. $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port");
  2204. if ($this->io_method() == 'socket') {
  2205. if (!is_array($this->proxy)) {
  2206. $host = $this->host;
  2207. $port = $this->port;
  2208. } else {
  2209. $host = $this->proxy['host'];
  2210. $port = $this->proxy['port'];
  2211. }
  2212. // use persistent connection
  2213. if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){
  2214. if (!feof($this->fp)) {
  2215. $this->debug('Re-use persistent connection');
  2216. return true;
  2217. }
  2218. fclose($this->fp);
  2219. $this->debug('Closed persistent connection at EOF');
  2220. }
  2221. // munge host if using OpenSSL
  2222. if ($this->scheme == 'ssl') {
  2223. $host = 'ssl://' . $host;
  2224. }
  2225. $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
  2226. // open socket
  2227. if($connection_timeout > 0){
  2228. $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout);
  2229. } else {
  2230. $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str);
  2231. }
  2232. // test pointer
  2233. if(!$this->fp) {
  2234. $msg = 'Couldn\'t open socket connection to server ' . $this->url;
  2235. if ($this->errno) {
  2236. $msg .= ', Error ('.$this->errno.'): '.$this->error_str;
  2237. } else {
  2238. $msg .= ' prior to connect(). This is often a problem looking up the host name.';
  2239. }
  2240. $this->debug($msg);
  2241. $this->setError($msg);
  2242. return false;
  2243. }
  2244. // set response timeout
  2245. $this->debug('set response timeout to ' . $response_timeout);
  2246. socket_set_timeout( $this->fp, $response_timeout);
  2247. $this->debug('socket connected');
  2248. return true;
  2249. } else if ($this->io_method() == 'curl') {
  2250. if (!extension_loaded('curl')) {
  2251. // $this->setError('cURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
  2252. $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.');
  2253. return false;
  2254. }
  2255. // Avoid warnings when PHP does not have these options
  2256. if (defined('CURLOPT_CONNECTIONTIMEOUT'))
  2257. $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT;
  2258. else
  2259. $CURLOPT_CONNECTIONTIMEOUT = 78;
  2260. if (defined('CURLOPT_HTTPAUTH'))
  2261. $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH;
  2262. else
  2263. $CURLOPT_HTTPAUTH = 107;
  2264. if (defined('CURLOPT_PROXYAUTH'))
  2265. $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH;
  2266. else
  2267. $CURLOPT_PROXYAUTH = 111;
  2268. if (defined('CURLAUTH_BASIC'))
  2269. $CURLAUTH_BASIC = CURLAUTH_BASIC;
  2270. else
  2271. $CURLAUTH_BASIC = 1;
  2272. if (defined('CURLAUTH_DIGEST'))
  2273. $CURLAUTH_DIGEST = CURLAUTH_DIGEST;
  2274. else
  2275. $CURLAUTH_DIGEST = 2;
  2276. if (defined('CURLAUTH_NTLM'))
  2277. $CURLAUTH_NTLM = CURLAUTH_NTLM;
  2278. else
  2279. $CURLAUTH_NTLM = 8;
  2280. $this->debug('connect using cURL');
  2281. // init CURL
  2282. $this->ch = curl_init();
  2283. // set url
  2284. $hostURL = ($this->port != '') ? "$this->scheme://$this->host:$this->port" : "$this->scheme://$this->host";
  2285. // add path
  2286. $hostURL .= $this->path;
  2287. $this->setCurlOption(CURLOPT_URL, $hostURL);
  2288. // follow location headers (re-directs)
  2289. if (ini_get('safe_mode') || ini_get('open_basedir')) {
  2290. $this->debug('safe_mode or open_basedir set, so do not set CURLOPT_FOLLOWLOCATION');
  2291. $this->debug('safe_mode = ');
  2292. $this->appendDebug($this->varDump(ini_get('safe_mode')));
  2293. $this->debug('open_basedir = ');
  2294. $this->appendDebug($this->varDump(ini_get('open_basedir')));
  2295. } else {
  2296. $this->setCurlOption(CURLOPT_FOLLOWLOCATION, 1);
  2297. }
  2298. // ask for headers in the response output
  2299. $this->setCurlOption(CURLOPT_HEADER, 1);
  2300. // ask for the response output as the return value
  2301. $this->setCurlOption(CURLOPT_RETURNTRANSFER, 1);
  2302. // encode
  2303. // We manage this ourselves through headers and encoding
  2304. // if(function_exists('gzuncompress')){
  2305. // $this->setCurlOption(CURLOPT_ENCODING, 'deflate');
  2306. // }
  2307. // persistent connection
  2308. if ($this->persistentConnection) {
  2309. // I believe the following comment is now bogus, having applied to
  2310. // the code when it used CURLOPT_CUSTOMREQUEST to send the request.
  2311. // The way we send data, we cannot use persistent connections, since
  2312. // there will be some "junk" at the end of our request.
  2313. //$this->setCurlOption(CURL_HTTP_VERSION_1_1, true);
  2314. $this->persistentConnection = false;
  2315. $this->setHeader('Connection', 'close');
  2316. }
  2317. // set timeouts
  2318. if ($connection_timeout != 0) {
  2319. $this->setCurlOption($CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
  2320. }
  2321. if ($response_timeout != 0) {
  2322. $this->setCurlOption(CURLOPT_TIMEOUT, $response_timeout);
  2323. }
  2324. if ($this->scheme == 'https') {
  2325. $this->debug('set cURL SSL verify options');
  2326. // recent versions of cURL turn on peer/host checking by default,
  2327. // while PHP binaries are not compiled with a default location for the
  2328. // CA cert bundle, so disable peer/host checking.
  2329. //$this->setCurlOption(CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
  2330. $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
  2331. $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 0);
  2332. // support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
  2333. if ($this->authtype == 'certificate') {
  2334. $this->debug('set cURL certificate options');
  2335. if (isset($this->certRequest['cainfofile'])) {
  2336. $this->setCurlOption(CURLOPT_CAINFO, $this->certRequest['cainfofile']);
  2337. }
  2338. if (isset($this->certRequest['verifypeer'])) {
  2339. $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
  2340. } else {
  2341. $this->setCurlOption(CURLOPT_SSL_VERIFYPEER, 1);
  2342. }
  2343. if (isset($this->certRequest['verifyhost'])) {
  2344. $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
  2345. } else {
  2346. $this->setCurlOption(CURLOPT_SSL_VERIFYHOST, 1);
  2347. }
  2348. if (isset($this->certRequest['sslcertfile'])) {
  2349. $this->setCurlOption(CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
  2350. }
  2351. if (isset($this->certRequest['sslkeyfile'])) {
  2352. $this->setCurlOption(CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
  2353. }
  2354. if (isset($this->certRequest['passphrase'])) {
  2355. $this->setCurlOption(CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
  2356. }
  2357. if (isset($this->certRequest['certpassword'])) {
  2358. $this->setCurlOption(CURLOPT_SSLCERTPASSWD, $this->certRequest['certpassword']);
  2359. }
  2360. }
  2361. }
  2362. if ($this->authtype && ($this->authtype != 'certificate')) {
  2363. if ($this->username) {
  2364. $this->debug('set cURL username/password');
  2365. $this->setCurlOption(CURLOPT_USERPWD, "$this->username:$this->password");
  2366. }
  2367. if ($this->authtype == 'basic') {
  2368. $this->debug('set cURL for Basic authentication');
  2369. $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_BASIC);
  2370. }
  2371. if ($this->authtype == 'digest') {
  2372. $this->debug('set cURL for digest authentication');
  2373. $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_DIGEST);
  2374. }
  2375. if ($this->authtype == 'ntlm') {
  2376. $this->debug('set cURL for NTLM authentication');
  2377. $this->setCurlOption($CURLOPT_HTTPAUTH, $CURLAUTH_NTLM);
  2378. }
  2379. }
  2380. if (is_array($this->proxy)) {
  2381. $this->debug('set cURL proxy options');
  2382. if ($this->proxy['port'] != '') {
  2383. $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']);
  2384. } else {
  2385. $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']);
  2386. }
  2387. if ($this->proxy['username'] || $this->proxy['password']) {
  2388. $this->debug('set cURL proxy authentication options');
  2389. $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']);
  2390. if ($this->proxy['authtype'] == 'basic') {
  2391. $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC);
  2392. }
  2393. if ($this->proxy['authtype'] == 'ntlm') {
  2394. $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_NTLM);
  2395. }
  2396. }
  2397. }
  2398. $this->debug('cURL connection set up');
  2399. return true;
  2400. } else {
  2401. $this->setError('Unknown scheme ' . $this->scheme);
  2402. $this->debug('Unknown scheme ' . $this->scheme);
  2403. return false;
  2404. }
  2405. }
  2406. /**
  2407. * sends the SOAP request and gets the SOAP response via HTTP[S]
  2408. *
  2409. * @param string $data message data
  2410. * @param integer $timeout set connection timeout in seconds
  2411. * @param integer $response_timeout set response timeout in seconds
  2412. * @param array $cookies cookies to send
  2413. * @return string data
  2414. * @access public
  2415. */
  2416. function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) {
  2417. $this->debug('entered send() with data of length: '.strlen($data));
  2418. $this->tryagain = true;
  2419. $tries = 0;
  2420. while ($this->tryagain) {
  2421. $this->tryagain = false;
  2422. if ($tries++ < 2) {
  2423. // make connnection
  2424. if (!$this->connect($timeout, $response_timeout)){
  2425. return false;
  2426. }
  2427. // send request
  2428. if (!$this->sendRequest($data, $cookies)){
  2429. return false;
  2430. }
  2431. // get response
  2432. $respdata = $this->getResponse();
  2433. } else {
  2434. $this->setError("Too many tries to get an OK response ($this->response_status_line)");
  2435. }
  2436. }
  2437. $this->debug('end of send()');
  2438. return $respdata;
  2439. }
  2440. /**
  2441. * sends the SOAP request and gets the SOAP response via HTTPS using CURL
  2442. *
  2443. * @param string $data message data
  2444. * @param integer $timeout set connection timeout in seconds
  2445. * @param integer $response_timeout set response timeout in seconds
  2446. * @param array $cookies cookies to send
  2447. * @return string data
  2448. * @access public
  2449. * @deprecated
  2450. */
  2451. function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) {
  2452. return $this->send($data, $timeout, $response_timeout, $cookies);
  2453. }
  2454. /**
  2455. * if authenticating, set user credentials here
  2456. *
  2457. * @param string $username
  2458. * @param string $password
  2459. * @param string $authtype (basic|digest|certificate|ntlm)
  2460. * @param array $digestRequest (keys must be nonce, nc, realm, qop)
  2461. * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
  2462. * @access public
  2463. */
  2464. function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) {
  2465. $this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
  2466. $this->appendDebug($this->varDump($digestRequest));
  2467. $this->debug("certRequest=");
  2468. $this->appendDebug($this->varDump($certRequest));
  2469. // cf. RFC 2617
  2470. if ($authtype == 'basic') {
  2471. $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password));
  2472. } elseif ($authtype == 'digest') {
  2473. if (isset($digestRequest['nonce'])) {
  2474. $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
  2475. // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
  2476. // A1 = unq(username-value) ":" unq(realm-value) ":" passwd
  2477. $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
  2478. // H(A1) = MD5(A1)
  2479. $HA1 = md5($A1);
  2480. // A2 = Method ":" digest-uri-value
  2481. $A2 = $this->request_method . ':' . $this->digest_uri;
  2482. // H(A2)
  2483. $HA2 = md5($A2);
  2484. // KD(secret, data) = H(concat(secret, ":", data))
  2485. // if qop == auth:
  2486. // request-digest = <"> < KD ( H(A1), unq(nonce-value)
  2487. // ":" nc-value
  2488. // ":" unq(cnonce-value)
  2489. // ":" unq(qop-value)
  2490. // ":" H(A2)
  2491. // ) <">
  2492. // if qop is missing,
  2493. // request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
  2494. $unhashedDigest = '';
  2495. $nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
  2496. $cnonce = $nonce;
  2497. if ($digestRequest['qop'] != '') {
  2498. $unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
  2499. } else {
  2500. $unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
  2501. }
  2502. $hashedDigest = md5($unhashedDigest);
  2503. $opaque = '';
  2504. if (isset($digestRequest['opaque'])) {
  2505. $opaque = ', opaque="' . $digestRequest['opaque'] . '"';
  2506. }
  2507. $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 . '"');
  2508. }
  2509. } elseif ($authtype == 'certificate') {
  2510. $this->certRequest = $certRequest;
  2511. $this->debug('Authorization header not set for certificate');
  2512. } elseif ($authtype == 'ntlm') {
  2513. // do nothing
  2514. $this->debug('Authorization header not set for ntlm');
  2515. }
  2516. $this->username = $username;
  2517. $this->password = $password;
  2518. $this->authtype = $authtype;
  2519. $this->digestRequest = $digestRequest;
  2520. }
  2521. /**
  2522. * set the soapaction value
  2523. *
  2524. * @param string $soapaction
  2525. * @access public
  2526. */
  2527. function setSOAPAction($soapaction) {
  2528. $this->setHeader('SOAPAction', '"' . $soapaction . '"');
  2529. }
  2530. /**
  2531. * use http encoding
  2532. *
  2533. * @param string $enc encoding style. supported values: gzip, deflate, or both
  2534. * @access public
  2535. */
  2536. function setEncoding($enc='gzip, deflate') {
  2537. if (function_exists('gzdeflate')) {
  2538. $this->protocol_version = '1.1';
  2539. $this->setHeader('Accept-Encoding', $enc);
  2540. if (!isset($this->outgoing_headers['Connection'])) {
  2541. $this->setHeader('Connection', 'close');
  2542. $this->persistentConnection = false;
  2543. }
  2544. // deprecated as of PHP 5.3.0
  2545. //set_magic_quotes_runtime(0);
  2546. $this->encoding = $enc;
  2547. }
  2548. }
  2549. /**
  2550. * set proxy info here
  2551. *
  2552. * @param string $proxyhost use an empty string to remove proxy
  2553. * @param string $proxyport
  2554. * @param string $proxyusername
  2555. * @param string $proxypassword
  2556. * @param string $proxyauthtype (basic|ntlm)
  2557. * @access public
  2558. */
  2559. function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') {
  2560. if ($proxyhost) {
  2561. $this->proxy = array(
  2562. 'host' => $proxyhost,
  2563. 'port' => $proxyport,
  2564. 'username' => $proxyusername,
  2565. 'password' => $proxypassword,
  2566. 'authtype' => $proxyauthtype
  2567. );
  2568. if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') {
  2569. $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword));
  2570. }
  2571. } else {
  2572. $this->debug('remove proxy');
  2573. $proxy = null;
  2574. unsetHeader('Proxy-Authorization');
  2575. }
  2576. }
  2577. /**
  2578. * Test if the given string starts with a header that is to be skipped.
  2579. * Skippable headers result from chunked transfer and proxy requests.
  2580. *
  2581. * @param string $data The string to check.
  2582. * @returns boolean Whether a skippable header was found.
  2583. * @access private
  2584. */
  2585. function isSkippableCurlHeader(&$data) {
  2586. $skipHeaders = array( 'HTTP/1.1 100',
  2587. 'HTTP/1.0 301',
  2588. 'HTTP/1.1 301',
  2589. 'HTTP/1.0 302',
  2590. 'HTTP/1.1 302',
  2591. 'HTTP/1.0 401',
  2592. 'HTTP/1.1 401',
  2593. 'HTTP/1.0 200 Connection established');
  2594. foreach ($skipHeaders as $hd) {
  2595. $prefix = substr($data, 0, strlen($hd));
  2596. if ($prefix == $hd) return true;
  2597. }
  2598. return false;
  2599. }
  2600. /**
  2601. * decode a string that is encoded w/ "chunked' transfer encoding
  2602. * as defined in RFC2068 19.4.6
  2603. *
  2604. * @param string $buffer
  2605. * @param string $lb
  2606. * @returns string
  2607. * @access public
  2608. * @deprecated
  2609. */
  2610. function decodeChunked($buffer, $lb){
  2611. // length := 0
  2612. $length = 0;
  2613. $new = '';
  2614. // read chunk-size, chunk-extension (if any) and CRLF
  2615. // get the position of the linebreak
  2616. $chunkend = strpos($buffer, $lb);
  2617. if ($chunkend == FALSE) {
  2618. $this->debug('no linebreak found in decodeChunked');
  2619. return $new;
  2620. }
  2621. $temp = substr($buffer,0,$chunkend);
  2622. $chunk_size = hexdec( trim($temp) );
  2623. $chunkstart = $chunkend + strlen($lb);
  2624. // while (chunk-size > 0) {
  2625. while ($chunk_size > 0) {
  2626. $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size");
  2627. $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size);
  2628. // Just in case we got a broken connection
  2629. if ($chunkend == FALSE) {
  2630. $chunk = substr($buffer,$chunkstart);
  2631. // append chunk-data to entity-body
  2632. $new .= $chunk;
  2633. $length += strlen($chunk);
  2634. break;
  2635. }
  2636. // read chunk-data and CRLF
  2637. $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
  2638. // append chunk-data to entity-body
  2639. $new .= $chunk;
  2640. // length := length + chunk-size
  2641. $length += strlen($chunk);
  2642. // read chunk-size and CRLF
  2643. $chunkstart = $chunkend + strlen($lb);
  2644. $chunkend = strpos($buffer, $lb, $chunkstart) + strlen($lb);
  2645. if ($chunkend == FALSE) {
  2646. break; //Just in case we got a broken connection
  2647. }
  2648. $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
  2649. $chunk_size = hexdec( trim($temp) );
  2650. $chunkstart = $chunkend;
  2651. }
  2652. return $new;
  2653. }
  2654. /**
  2655. * Writes the payload, including HTTP headers, to $this->outgoing_payload.
  2656. *
  2657. * @param string $data HTTP body
  2658. * @param string $cookie_str data for HTTP Cookie header
  2659. * @return void
  2660. * @access private
  2661. */
  2662. function buildPayload($data, $cookie_str = '') {
  2663. // Note: for cURL connections, $this->outgoing_payload is ignored,
  2664. // as is the Content-Length header, but these are still created as
  2665. // debugging guides.
  2666. // add content-length header
  2667. if ($this->request_method != 'GET') {
  2668. $this->setHeader('Content-Length', strlen($data));
  2669. }
  2670. // start building outgoing payload:
  2671. if ($this->proxy) {
  2672. $uri = $this->url;
  2673. } else {
  2674. $uri = $this->uri;
  2675. }
  2676. $req = "$this->request_method $uri HTTP/$this->protocol_version";
  2677. $this->debug("HTTP request: $req");
  2678. $this->outgoing_payload = "$req\r\n";
  2679. // loop thru headers, serializing
  2680. foreach($this->outgoing_headers as $k => $v){
  2681. $hdr = $k.': '.$v;
  2682. $this->debug("HTTP header: $hdr");
  2683. $this->outgoing_payload .= "$hdr\r\n";
  2684. }
  2685. // add any cookies
  2686. if ($cookie_str != '') {
  2687. $hdr = 'Cookie: '.$cookie_str;
  2688. $this->debug("HTTP header: $hdr");
  2689. $this->outgoing_payload .= "$hdr\r\n";
  2690. }
  2691. // header/body separator
  2692. $this->outgoing_payload .= "\r\n";
  2693. // add data
  2694. $this->outgoing_payload .= $data;
  2695. }
  2696. /**
  2697. * sends the SOAP request via HTTP[S]
  2698. *
  2699. * @param string $data message data
  2700. * @param array $cookies cookies to send
  2701. * @return boolean true if OK, false if problem
  2702. * @access private
  2703. */
  2704. function sendRequest($data, $cookies = NULL) {
  2705. // build cookie string
  2706. $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https')));
  2707. // build payload
  2708. $this->buildPayload($data, $cookie_str);
  2709. if ($this->io_method() == 'socket') {
  2710. // send payload
  2711. if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
  2712. $this->setError('couldn\'t write message data to socket');
  2713. $this->debug('couldn\'t write message data to socket');
  2714. return false;
  2715. }
  2716. $this->debug('wrote data to socket, length = ' . strlen($this->outgoing_payload));
  2717. return true;
  2718. } else if ($this->io_method() == 'curl') {
  2719. // set payload
  2720. // cURL does say this should only be the verb, and in fact it
  2721. // turns out that the URI and HTTP version are appended to this, which
  2722. // some servers refuse to work with (so we no longer use this method!)
  2723. //$this->setCurlOption(CURLOPT_CUSTOMREQUEST, $this->outgoing_payload);
  2724. $curl_headers = array();
  2725. foreach($this->outgoing_headers as $k => $v){
  2726. if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') {
  2727. $this->debug("Skip cURL header $k: $v");
  2728. } else {
  2729. $curl_headers[] = "$k: $v";
  2730. }
  2731. }
  2732. if ($cookie_str != '') {
  2733. $curl_headers[] = 'Cookie: ' . $cookie_str;
  2734. }
  2735. $this->setCurlOption(CURLOPT_HTTPHEADER, $curl_headers);
  2736. $this->debug('set cURL HTTP headers');
  2737. if ($this->request_method == "POST") {
  2738. $this->setCurlOption(CURLOPT_POST, 1);
  2739. $this->setCurlOption(CURLOPT_POSTFIELDS, $data);
  2740. $this->debug('set cURL POST data');
  2741. } else {
  2742. }
  2743. // insert custom user-set cURL options
  2744. foreach ($this->ch_options as $key => $val) {
  2745. $this->setCurlOption($key, $val);
  2746. }
  2747. $this->debug('set cURL payload');
  2748. return true;
  2749. }
  2750. }
  2751. /**
  2752. * gets the SOAP response via HTTP[S]
  2753. *
  2754. * @return string the response (also sets member variables like incoming_payload)
  2755. * @access private
  2756. */
  2757. function getResponse(){
  2758. $this->incoming_payload = '';
  2759. if ($this->io_method() == 'socket') {
  2760. // loop until headers have been retrieved
  2761. $data = '';
  2762. while (!isset($lb)){
  2763. // We might EOF during header read.
  2764. if(feof($this->fp)) {
  2765. $this->incoming_payload = $data;
  2766. $this->debug('found no headers before EOF after length ' . strlen($data));
  2767. $this->debug("received before EOF:\n" . $data);
  2768. $this->setError('server failed to send headers');
  2769. return false;
  2770. }
  2771. $tmp = fgets($this->fp, 256);
  2772. $tmplen = strlen($tmp);
  2773. $this->debug("read line of $tmplen bytes: " . trim($tmp));
  2774. if ($tmplen == 0) {
  2775. $this->incoming_payload = $data;
  2776. $this->debug('socket read of headers timed out after length ' . strlen($data));
  2777. $this->debug("read before timeout: " . $data);
  2778. $this->setError('socket read of headers timed out');
  2779. return false;
  2780. }
  2781. $data .= $tmp;
  2782. $pos = strpos($data,"\r\n\r\n");
  2783. if($pos > 1){
  2784. $lb = "\r\n";
  2785. } else {
  2786. $pos = strpos($data,"\n\n");
  2787. if($pos > 1){
  2788. $lb = "\n";
  2789. }
  2790. }
  2791. // remove 100 headers
  2792. if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) {
  2793. unset($lb);
  2794. $data = '';
  2795. }//
  2796. }
  2797. // store header data
  2798. $this->incoming_payload .= $data;
  2799. $this->debug('found end of headers after length ' . strlen($data));
  2800. // process headers
  2801. $header_data = trim(substr($data,0,$pos));
  2802. $header_array = explode($lb,$header_data);
  2803. $this->incoming_headers = array();
  2804. $this->incoming_cookies = array();
  2805. foreach($header_array as $header_line){
  2806. $arr = explode(':',$header_line, 2);
  2807. if(count($arr) > 1){
  2808. $header_name = strtolower(trim($arr[0]));
  2809. $this->incoming_headers[$header_name] = trim($arr[1]);
  2810. if ($header_name == 'set-cookie') {
  2811. // TODO: allow multiple cookies from parseCookie
  2812. $cookie = $this->parseCookie(trim($arr[1]));
  2813. if ($cookie) {
  2814. $this->incoming_cookies[] = $cookie;
  2815. $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
  2816. } else {
  2817. $this->debug('did not find cookie in ' . trim($arr[1]));
  2818. }
  2819. }
  2820. } else if (isset($header_name)) {
  2821. // append continuation line to previous header
  2822. $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
  2823. }
  2824. }
  2825. // loop until msg has been received
  2826. if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') {
  2827. $content_length = 2147483647; // ignore any content-length header
  2828. $chunked = true;
  2829. $this->debug("want to read chunked content");
  2830. } elseif (isset($this->incoming_headers['content-length'])) {
  2831. $content_length = $this->incoming_headers['content-length'];
  2832. $chunked = false;
  2833. $this->debug("want to read content of length $content_length");
  2834. } else {
  2835. $content_length = 2147483647;
  2836. $chunked = false;
  2837. $this->debug("want to read content to EOF");
  2838. }
  2839. $data = '';
  2840. do {
  2841. if ($chunked) {
  2842. $tmp = fgets($this->fp, 256);
  2843. $tmplen = strlen($tmp);
  2844. $this->debug("read chunk line of $tmplen bytes");
  2845. if ($tmplen == 0) {
  2846. $this->incoming_payload = $data;
  2847. $this->debug('socket read of chunk length timed out after length ' . strlen($data));
  2848. $this->debug("read before timeout:\n" . $data);
  2849. $this->setError('socket read of chunk length timed out');
  2850. return false;
  2851. }
  2852. $content_length = hexdec(trim($tmp));
  2853. $this->debug("chunk length $content_length");
  2854. }
  2855. $strlen = 0;
  2856. while (($strlen < $content_length) && (!feof($this->fp))) {
  2857. $readlen = min(8192, $content_length - $strlen);
  2858. $tmp = fread($this->fp, $readlen);
  2859. $tmplen = strlen($tmp);
  2860. $this->debug("read buffer of $tmplen bytes");
  2861. if (($tmplen == 0) && (!feof($this->fp))) {
  2862. $this->incoming_payload = $data;
  2863. $this->debug('socket read of body timed out after length ' . strlen($data));
  2864. $this->debug("read before timeout:\n" . $data);
  2865. $this->setError('socket read of body timed out');
  2866. return false;
  2867. }
  2868. $strlen += $tmplen;
  2869. $data .= $tmp;
  2870. }
  2871. if ($chunked && ($content_length > 0)) {
  2872. $tmp = fgets($this->fp, 256);
  2873. $tmplen = strlen($tmp);
  2874. $this->debug("read chunk terminator of $tmplen bytes");
  2875. if ($tmplen == 0) {
  2876. $this->incoming_payload = $data;
  2877. $this->debug('socket read of chunk terminator timed out after length ' . strlen($data));
  2878. $this->debug("read before timeout:\n" . $data);
  2879. $this->setError('socket read of chunk terminator timed out');
  2880. return false;
  2881. }
  2882. }
  2883. } while ($chunked && ($content_length > 0) && (!feof($this->fp)));
  2884. if (feof($this->fp)) {
  2885. $this->debug('read to EOF');
  2886. }
  2887. $this->debug('read body of length ' . strlen($data));
  2888. $this->incoming_payload .= $data;
  2889. $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server');
  2890. // close filepointer
  2891. if(
  2892. (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') ||
  2893. (! $this->persistentConnection) || feof($this->fp)){
  2894. fclose($this->fp);
  2895. $this->fp = false;
  2896. $this->debug('closed socket');
  2897. }
  2898. // connection was closed unexpectedly
  2899. if($this->incoming_payload == ''){
  2900. $this->setError('no response from server');
  2901. return false;
  2902. }
  2903. // decode transfer-encoding
  2904. // if(isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked'){
  2905. // if(!$data = $this->decodeChunked($data, $lb)){
  2906. // $this->setError('Decoding of chunked data failed');
  2907. // return false;
  2908. // }
  2909. //print "<pre>\nde-chunked:\n---------------\n$data\n\n---------------\n</pre>";
  2910. // set decoded payload
  2911. // $this->incoming_payload = $header_data.$lb.$lb.$data;
  2912. // }
  2913. } else if ($this->io_method() == 'curl') {
  2914. // send and receive
  2915. $this->debug('send and receive with cURL');
  2916. $this->incoming_payload = curl_exec($this->ch);
  2917. $data = $this->incoming_payload;
  2918. $cErr = curl_error($this->ch);
  2919. if ($cErr != '') {
  2920. $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>';
  2921. // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE
  2922. foreach(curl_getinfo($this->ch) as $k => $v){
  2923. $err .= "$k: $v<br>";
  2924. }
  2925. $this->debug($err);
  2926. $this->setError($err);
  2927. curl_close($this->ch);
  2928. return false;
  2929. } else {
  2930. //echo '<pre>';
  2931. //var_dump(curl_getinfo($this->ch));
  2932. //echo '</pre>';
  2933. }
  2934. // close curl
  2935. $this->debug('No cURL error, closing cURL');
  2936. curl_close($this->ch);
  2937. // try removing skippable headers
  2938. $savedata = $data;
  2939. while ($this->isSkippableCurlHeader($data)) {
  2940. $this->debug("Found HTTP header to skip");
  2941. if ($pos = strpos($data,"\r\n\r\n")) {
  2942. $data = ltrim(substr($data,$pos));
  2943. } elseif($pos = strpos($data,"\n\n") ) {
  2944. $data = ltrim(substr($data,$pos));
  2945. }
  2946. }
  2947. if ($data == '') {
  2948. // have nothing left; just remove 100 header(s)
  2949. $data = $savedata;
  2950. while (preg_match('/^HTTP\/1.1 100/',$data)) {
  2951. if ($pos = strpos($data,"\r\n\r\n")) {
  2952. $data = ltrim(substr($data,$pos));
  2953. } elseif($pos = strpos($data,"\n\n") ) {
  2954. $data = ltrim(substr($data,$pos));
  2955. }
  2956. }
  2957. }
  2958. // separate content from HTTP headers
  2959. if ($pos = strpos($data,"\r\n\r\n")) {
  2960. $lb = "\r\n";
  2961. } elseif( $pos = strpos($data,"\n\n")) {
  2962. $lb = "\n";
  2963. } else {
  2964. $this->debug('no proper separation of headers and document');
  2965. $this->setError('no proper separation of headers and document');
  2966. return false;
  2967. }
  2968. $header_data = trim(substr($data,0,$pos));
  2969. $header_array = explode($lb,$header_data);
  2970. $data = ltrim(substr($data,$pos));
  2971. $this->debug('found proper separation of headers and document');
  2972. $this->debug('cleaned data, stringlen: '.strlen($data));
  2973. // clean headers
  2974. foreach ($header_array as $header_line) {
  2975. $arr = explode(':',$header_line,2);
  2976. if(count($arr) > 1){
  2977. $header_name = strtolower(trim($arr[0]));
  2978. $this->incoming_headers[$header_name] = trim($arr[1]);
  2979. if ($header_name == 'set-cookie') {
  2980. // TODO: allow multiple cookies from parseCookie
  2981. $cookie = $this->parseCookie(trim($arr[1]));
  2982. if ($cookie) {
  2983. $this->incoming_cookies[] = $cookie;
  2984. $this->debug('found cookie: ' . $cookie['name'] . ' = ' . $cookie['value']);
  2985. } else {
  2986. $this->debug('did not find cookie in ' . trim($arr[1]));
  2987. }
  2988. }
  2989. } else if (isset($header_name)) {
  2990. // append continuation line to previous header
  2991. $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line;
  2992. }
  2993. }
  2994. }
  2995. $this->response_status_line = $header_array[0];
  2996. $arr = explode(' ', $this->response_status_line, 3);
  2997. $http_version = $arr[0];
  2998. $http_status = intval($arr[1]);
  2999. $http_reason = count($arr) > 2 ? $arr[2] : '';
  3000. // see if we need to resend the request with http digest authentication
  3001. if (isset($this->incoming_headers['location']) && ($http_status == 301 || $http_status == 302)) {
  3002. $this->debug("Got $http_status $http_reason with Location: " . $this->incoming_headers['location']);
  3003. $this->setURL($this->incoming_headers['location']);
  3004. $this->tryagain = true;
  3005. return false;
  3006. }
  3007. // see if we need to resend the request with http digest authentication
  3008. if (isset($this->incoming_headers['www-authenticate']) && $http_status == 401) {
  3009. $this->debug("Got 401 $http_reason with WWW-Authenticate: " . $this->incoming_headers['www-authenticate']);
  3010. if (strstr($this->incoming_headers['www-authenticate'], "Digest ")) {
  3011. $this->debug('Server wants digest authentication');
  3012. // remove "Digest " from our elements
  3013. $digestString = str_replace('Digest ', '', $this->incoming_headers['www-authenticate']);
  3014. // parse elements into array
  3015. $digestElements = explode(',', $digestString);
  3016. foreach ($digestElements as $val) {
  3017. $tempElement = explode('=', trim($val), 2);
  3018. $digestRequest[$tempElement[0]] = str_replace("\"", '', $tempElement[1]);
  3019. }
  3020. // should have (at least) qop, realm, nonce
  3021. if (isset($digestRequest['nonce'])) {
  3022. $this->setCredentials($this->username, $this->password, 'digest', $digestRequest);
  3023. $this->tryagain = true;
  3024. return false;
  3025. }
  3026. }
  3027. $this->debug('HTTP authentication failed');
  3028. $this->setError('HTTP authentication failed');
  3029. return false;
  3030. }
  3031. if (
  3032. ($http_status >= 300 && $http_status <= 307) ||
  3033. ($http_status >= 400 && $http_status <= 417) ||
  3034. ($http_status >= 501 && $http_status <= 505)
  3035. ) {
  3036. $this->setError("Unsupported HTTP response status $http_status $http_reason (soapclient->response has contents of the response)");
  3037. return false;
  3038. }
  3039. // decode content-encoding
  3040. if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){
  3041. if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){
  3042. // if decoding works, use it. else assume data wasn't gzencoded
  3043. if(function_exists('gzinflate')){
  3044. //$timer->setMarker('starting decoding of gzip/deflated content');
  3045. // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress)
  3046. // this means there are no Zlib headers, although there should be
  3047. $this->debug('The gzinflate function exists');
  3048. $datalen = strlen($data);
  3049. if ($this->incoming_headers['content-encoding'] == 'deflate') {
  3050. if ($degzdata = @gzinflate($data)) {
  3051. $data = $degzdata;
  3052. $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes');
  3053. if (strlen($data) < $datalen) {
  3054. // test for the case that the payload has been compressed twice
  3055. $this->debug('The inflated payload is smaller than the gzipped one; try again');
  3056. if ($degzdata = @gzinflate($data)) {
  3057. $data = $degzdata;
  3058. $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes');
  3059. }
  3060. }
  3061. } else {
  3062. $this->debug('Error using gzinflate to inflate the payload');
  3063. $this->setError('Error using gzinflate to inflate the payload');
  3064. }
  3065. } elseif ($this->incoming_headers['content-encoding'] == 'gzip') {
  3066. if ($degzdata = @gzinflate(substr($data, 10))) { // do our best
  3067. $data = $degzdata;
  3068. $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes');
  3069. if (strlen($data) < $datalen) {
  3070. // test for the case that the payload has been compressed twice
  3071. $this->debug('The un-gzipped payload is smaller than the gzipped one; try again');
  3072. if ($degzdata = @gzinflate(substr($data, 10))) {
  3073. $data = $degzdata;
  3074. $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes');
  3075. }
  3076. }
  3077. } else {
  3078. $this->debug('Error using gzinflate to un-gzip the payload');
  3079. $this->setError('Error using gzinflate to un-gzip the payload');
  3080. }
  3081. }
  3082. //$timer->setMarker('finished decoding of gzip/deflated content');
  3083. //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>";
  3084. // set decoded payload
  3085. $this->incoming_payload = $header_data.$lb.$lb.$data;
  3086. } else {
  3087. $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
  3088. $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.');
  3089. }
  3090. } else {
  3091. $this->debug('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
  3092. $this->setError('Unsupported Content-Encoding ' . $this->incoming_headers['content-encoding']);
  3093. }
  3094. } else {
  3095. $this->debug('No Content-Encoding header');
  3096. }
  3097. if(strlen($data) == 0){
  3098. $this->debug('no data after headers!');
  3099. $this->setError('no data present after HTTP headers');
  3100. return false;
  3101. }
  3102. return $data;
  3103. }
  3104. /**
  3105. * sets the content-type for the SOAP message to be sent
  3106. *
  3107. * @param string $type the content type, MIME style
  3108. * @param mixed $charset character set used for encoding (or false)
  3109. * @access public
  3110. */
  3111. function setContentType($type, $charset = false) {
  3112. $this->setHeader('Content-Type', $type . ($charset ? '; charset=' . $charset : ''));
  3113. }
  3114. /**
  3115. * specifies that an HTTP persistent connection should be used
  3116. *
  3117. * @return boolean whether the request was honored by this method.
  3118. * @access public
  3119. */
  3120. function usePersistentConnection(){
  3121. if (isset($this->outgoing_headers['Accept-Encoding'])) {
  3122. return false;
  3123. }
  3124. $this->protocol_version = '1.1';
  3125. $this->persistentConnection = true;
  3126. $this->setHeader('Connection', 'Keep-Alive');
  3127. return true;
  3128. }
  3129. /**
  3130. * parse an incoming Cookie into it's parts
  3131. *
  3132. * @param string $cookie_str content of cookie
  3133. * @return array with data of that cookie
  3134. * @access private
  3135. */
  3136. /*
  3137. * TODO: allow a Set-Cookie string to be parsed into multiple cookies
  3138. */
  3139. function parseCookie($cookie_str) {
  3140. $cookie_str = str_replace('; ', ';', $cookie_str) . ';';
  3141. $data = preg_split('/;/', $cookie_str);
  3142. $value_str = $data[0];
  3143. $cookie_param = 'domain=';
  3144. $start = strpos($cookie_str, $cookie_param);
  3145. if ($start > 0) {
  3146. $domain = substr($cookie_str, $start + strlen($cookie_param));
  3147. $domain = substr($domain, 0, strpos($domain, ';'));
  3148. } else {
  3149. $domain = '';
  3150. }
  3151. $cookie_param = 'expires=';
  3152. $start = strpos($cookie_str, $cookie_param);
  3153. if ($start > 0) {
  3154. $expires = substr($cookie_str, $start + strlen($cookie_param));
  3155. $expires = substr($expires, 0, strpos($expires, ';'));
  3156. } else {
  3157. $expires = '';
  3158. }
  3159. $cookie_param = 'path=';
  3160. $start = strpos($cookie_str, $cookie_param);
  3161. if ( $start > 0 ) {
  3162. $path = substr($cookie_str, $start + strlen($cookie_param));
  3163. $path = substr($path, 0, strpos($path, ';'));
  3164. } else {
  3165. $path = '/';
  3166. }
  3167. $cookie_param = ';secure;';
  3168. if (strpos($cookie_str, $cookie_param) !== FALSE) {
  3169. $secure = true;
  3170. } else {
  3171. $secure = false;
  3172. }
  3173. $sep_pos = strpos($value_str, '=');
  3174. if ($sep_pos) {
  3175. $name = substr($value_str, 0, $sep_pos);
  3176. $value = substr($value_str, $sep_pos + 1);
  3177. $cookie= array( 'name' => $name,
  3178. 'value' => $value,
  3179. 'domain' => $domain,
  3180. 'path' => $path,
  3181. 'expires' => $expires,
  3182. 'secure' => $secure
  3183. );
  3184. return $cookie;
  3185. }
  3186. return false;
  3187. }
  3188. /**
  3189. * sort out cookies for the current request
  3190. *
  3191. * @param array $cookies array with all cookies
  3192. * @param boolean $secure is the send-content secure or not?
  3193. * @return string for Cookie-HTTP-Header
  3194. * @access private
  3195. */
  3196. function getCookiesForRequest($cookies, $secure=false) {
  3197. $cookie_str = '';
  3198. if ((! is_null($cookies)) && (is_array($cookies))) {
  3199. foreach ($cookies as $cookie) {
  3200. if (! is_array($cookie)) {
  3201. continue;
  3202. }
  3203. $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']);
  3204. if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
  3205. if (strtotime($cookie['expires']) <= time()) {
  3206. $this->debug('cookie has expired');
  3207. continue;
  3208. }
  3209. }
  3210. if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) {
  3211. $domain = preg_quote($cookie['domain']);
  3212. if (! preg_match("'.*$domain$'i", $this->host)) {
  3213. $this->debug('cookie has different domain');
  3214. continue;
  3215. }
  3216. }
  3217. if ((isset($cookie['path'])) && (! empty($cookie['path']))) {
  3218. $path = preg_quote($cookie['path']);
  3219. if (! preg_match("'^$path.*'i", $this->path)) {
  3220. $this->debug('cookie is for a different path');
  3221. continue;
  3222. }
  3223. }
  3224. if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) {
  3225. $this->debug('cookie is secure, transport is not');
  3226. continue;
  3227. }
  3228. $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; ';
  3229. $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']);
  3230. }
  3231. }
  3232. return $cookie_str;
  3233. }
  3234. }
  3235. ?><?php
  3236. /**
  3237. *
  3238. * nusoap_server allows the user to create a SOAP server
  3239. * that is capable of receiving messages and returning responses
  3240. *
  3241. * @author Dietrich Ayala <dietrich@ganx4.com>
  3242. * @author Scott Nichol <snichol@users.sourceforge.net>
  3243. * @access public
  3244. */
  3245. class nusoap_server extends nusoap_base {
  3246. /**
  3247. * HTTP headers of request
  3248. * @var array
  3249. * @access private
  3250. */
  3251. var $headers = array();
  3252. /**
  3253. * HTTP request
  3254. * @var string
  3255. * @access private
  3256. */
  3257. var $request = '';
  3258. /**
  3259. * SOAP headers from request (incomplete namespace resolution; special characters not escaped) (text)
  3260. * @var string
  3261. * @access public
  3262. */
  3263. var $requestHeaders = '';
  3264. /**
  3265. * SOAP Headers from request (parsed)
  3266. * @var mixed
  3267. * @access public
  3268. */
  3269. var $requestHeader = NULL;
  3270. /**
  3271. * SOAP body request portion (incomplete namespace resolution; special characters not escaped) (text)
  3272. * @var string
  3273. * @access public
  3274. */
  3275. var $document = '';
  3276. /**
  3277. * SOAP payload for request (text)
  3278. * @var string
  3279. * @access public
  3280. */
  3281. var $requestSOAP = '';
  3282. /**
  3283. * requested method namespace URI
  3284. * @var string
  3285. * @access private
  3286. */
  3287. var $methodURI = '';
  3288. /**
  3289. * name of method requested
  3290. * @var string
  3291. * @access private
  3292. */
  3293. var $methodname = '';
  3294. /**
  3295. * method parameters from request
  3296. * @var array
  3297. * @access private
  3298. */
  3299. var $methodparams = array();
  3300. /**
  3301. * SOAP Action from request
  3302. * @var string
  3303. * @access private
  3304. */
  3305. var $SOAPAction = '';
  3306. /**
  3307. * character set encoding of incoming (request) messages
  3308. * @var string
  3309. * @access public
  3310. */
  3311. var $xml_encoding = '';
  3312. /**
  3313. * toggles whether the parser decodes element content w/ utf8_decode()
  3314. * @var boolean
  3315. * @access public
  3316. */
  3317. var $decode_utf8 = true;
  3318. /**
  3319. * HTTP headers of response
  3320. * @var array
  3321. * @access public
  3322. */
  3323. var $outgoing_headers = array();
  3324. /**
  3325. * HTTP response
  3326. * @var string
  3327. * @access private
  3328. */
  3329. var $response = '';
  3330. /**
  3331. * SOAP headers for response (text or array of soapval or associative array)
  3332. * @var mixed
  3333. * @access public
  3334. */
  3335. var $responseHeaders = '';
  3336. /**
  3337. * SOAP payload for response (text)
  3338. * @var string
  3339. * @access private
  3340. */
  3341. var $responseSOAP = '';
  3342. /**
  3343. * method return value to place in response
  3344. * @var mixed
  3345. * @access private
  3346. */
  3347. var $methodreturn = false;
  3348. /**
  3349. * whether $methodreturn is a string of literal XML
  3350. * @var boolean
  3351. * @access public
  3352. */
  3353. var $methodreturnisliteralxml = false;
  3354. /**
  3355. * SOAP fault for response (or false)
  3356. * @var mixed
  3357. * @access private
  3358. */
  3359. var $fault = false;
  3360. /**
  3361. * text indication of result (for debugging)
  3362. * @var string
  3363. * @access private
  3364. */
  3365. var $result = 'successful';
  3366. /**
  3367. * assoc array of operations => opData; operations are added by the register()
  3368. * method or by parsing an external WSDL definition
  3369. * @var array
  3370. * @access private
  3371. */
  3372. var $operations = array();
  3373. /**
  3374. * wsdl instance (if one)
  3375. * @var mixed
  3376. * @access private
  3377. */
  3378. var $wsdl = false;
  3379. /**
  3380. * URL for WSDL (if one)
  3381. * @var mixed
  3382. * @access private
  3383. */
  3384. var $externalWSDLURL = false;
  3385. /**
  3386. * whether to append debug to response as XML comment
  3387. * @var boolean
  3388. * @access public
  3389. */
  3390. var $debug_flag = false;
  3391. /**
  3392. * constructor
  3393. * the optional parameter is a path to a WSDL file that you'd like to bind the server instance to.
  3394. *
  3395. * @param mixed $wsdl file path or URL (string), or wsdl instance (object)
  3396. * @access public
  3397. */
  3398. function __construct($wsdl=false) {
  3399. parent::__construct();
  3400. // turn on debugging?
  3401. global $debug;
  3402. global $HTTP_SERVER_VARS;
  3403. if (isset($_SERVER)) {
  3404. $this->debug("_SERVER is defined:");
  3405. $this->appendDebug($this->varDump($_SERVER));
  3406. } elseif (isset($HTTP_SERVER_VARS)) {
  3407. $this->debug("HTTP_SERVER_VARS is defined:");
  3408. $this->appendDebug($this->varDump($HTTP_SERVER_VARS));
  3409. } else {
  3410. $this->debug("Neither _SERVER nor HTTP_SERVER_VARS is defined.");
  3411. }
  3412. if (isset($debug)) {
  3413. $this->debug("In nusoap_server, set debug_flag=$debug based on global flag");
  3414. $this->debug_flag = $debug;
  3415. } elseif (isset($_SERVER['QUERY_STRING'])) {
  3416. $qs = explode('&', $_SERVER['QUERY_STRING']);
  3417. foreach ($qs as $v) {
  3418. if (substr($v, 0, 6) == 'debug=') {
  3419. $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #1");
  3420. $this->debug_flag = substr($v, 6);
  3421. }
  3422. }
  3423. } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  3424. $qs = explode('&', $HTTP_SERVER_VARS['QUERY_STRING']);
  3425. foreach ($qs as $v) {
  3426. if (substr($v, 0, 6) == 'debug=') {
  3427. $this->debug("In nusoap_server, set debug_flag=" . substr($v, 6) . " based on query string #2");
  3428. $this->debug_flag = substr($v, 6);
  3429. }
  3430. }
  3431. }
  3432. // wsdl
  3433. if($wsdl){
  3434. $this->debug("In nusoap_server, WSDL is specified");
  3435. if (is_object($wsdl) && (get_class($wsdl) == 'wsdl')) {
  3436. $this->wsdl = $wsdl;
  3437. $this->externalWSDLURL = $this->wsdl->wsdl;
  3438. $this->debug('Use existing wsdl instance from ' . $this->externalWSDLURL);
  3439. } else {
  3440. $this->debug('Create wsdl from ' . $wsdl);
  3441. $this->wsdl = new wsdl($wsdl);
  3442. $this->externalWSDLURL = $wsdl;
  3443. }
  3444. $this->appendDebug($this->wsdl->getDebug());
  3445. $this->wsdl->clearDebug();
  3446. if($err = $this->wsdl->getError()){
  3447. die('WSDL ERROR: '.$err);
  3448. }
  3449. }
  3450. }
  3451. /**
  3452. * processes request and returns response
  3453. *
  3454. * @param string $data usually is the value of $HTTP_RAW_POST_DATA
  3455. * @access public
  3456. */
  3457. function service($data){
  3458. global $HTTP_SERVER_VARS;
  3459. if (isset($_SERVER['REQUEST_METHOD'])) {
  3460. $rm = $_SERVER['REQUEST_METHOD'];
  3461. } elseif (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) {
  3462. $rm = $HTTP_SERVER_VARS['REQUEST_METHOD'];
  3463. } else {
  3464. $rm = '';
  3465. }
  3466. if (isset($_SERVER['QUERY_STRING'])) {
  3467. $qs = $_SERVER['QUERY_STRING'];
  3468. } elseif (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  3469. $qs = $HTTP_SERVER_VARS['QUERY_STRING'];
  3470. } else {
  3471. $qs = '';
  3472. }
  3473. $this->debug("In service, request method=$rm query string=$qs strlen(\$data)=" . strlen($data));
  3474. if ($rm == 'POST') {
  3475. $this->debug("In service, invoke the request");
  3476. $this->parse_request($data);
  3477. if (! $this->fault) {
  3478. $this->invoke_method();
  3479. }
  3480. if (! $this->fault) {
  3481. $this->serialize_return();
  3482. }
  3483. $this->send_response();
  3484. } elseif (preg_match('/wsdl/', $qs) ){
  3485. $this->debug("In service, this is a request for WSDL");
  3486. if ($this->externalWSDLURL){
  3487. if (strpos($this->externalWSDLURL, "http://") !== false) { // assume URL
  3488. $this->debug("In service, re-direct for WSDL");
  3489. header('Location: '.$this->externalWSDLURL);
  3490. } else { // assume file
  3491. $this->debug("In service, use file passthru for WSDL");
  3492. header("Content-Type: text/xml\r\n");
  3493. $pos = strpos($this->externalWSDLURL, "file://");
  3494. if ($pos === false) {
  3495. $filename = $this->externalWSDLURL;
  3496. } else {
  3497. $filename = substr($this->externalWSDLURL, $pos + 7);
  3498. }
  3499. $fp = fopen($this->externalWSDLURL, 'r');
  3500. fpassthru($fp);
  3501. }
  3502. } elseif ($this->wsdl) {
  3503. $this->debug("In service, serialize WSDL");
  3504. header("Content-Type: text/xml; charset=ISO-8859-1\r\n");
  3505. print $this->wsdl->serialize($this->debug_flag);
  3506. if ($this->debug_flag) {
  3507. $this->debug('wsdl:');
  3508. $this->appendDebug($this->varDump($this->wsdl));
  3509. print $this->getDebugAsXMLComment();
  3510. }
  3511. } else {
  3512. $this->debug("In service, there is no WSDL");
  3513. header("Content-Type: text/html; charset=ISO-8859-1\r\n");
  3514. print "This service does not provide WSDL";
  3515. }
  3516. } elseif ($this->wsdl) {
  3517. $this->debug("In service, return Web description");
  3518. print $this->wsdl->webDescription();
  3519. } else {
  3520. $this->debug("In service, no Web description");
  3521. header("Content-Type: text/html; charset=ISO-8859-1\r\n");
  3522. print "This service does not provide a Web description";
  3523. }
  3524. }
  3525. /**
  3526. * parses HTTP request headers.
  3527. *
  3528. * The following fields are set by this function (when successful)
  3529. *
  3530. * headers
  3531. * request
  3532. * xml_encoding
  3533. * SOAPAction
  3534. *
  3535. * @access private
  3536. */
  3537. function parse_http_headers() {
  3538. global $HTTP_SERVER_VARS;
  3539. $this->request = '';
  3540. $this->SOAPAction = '';
  3541. if(function_exists('getallheaders')){
  3542. $this->debug("In parse_http_headers, use getallheaders");
  3543. $headers = getallheaders();
  3544. foreach($headers as $k=>$v){
  3545. $k = strtolower($k);
  3546. $this->headers[$k] = $v;
  3547. $this->request .= "$k: $v\r\n";
  3548. $this->debug("$k: $v");
  3549. }
  3550. // get SOAPAction header
  3551. if(isset($this->headers['soapaction'])){
  3552. $this->SOAPAction = str_replace('"','',$this->headers['soapaction']);
  3553. }
  3554. // get the character encoding of the incoming request
  3555. if(isset($this->headers['content-type']) && strpos($this->headers['content-type'],'=')){
  3556. $enc = str_replace('"','',substr(strstr($this->headers["content-type"],'='),1));
  3557. if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
  3558. $this->xml_encoding = strtoupper($enc);
  3559. } else {
  3560. $this->xml_encoding = 'US-ASCII';
  3561. }
  3562. } else {
  3563. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  3564. $this->xml_encoding = 'ISO-8859-1';
  3565. }
  3566. } elseif(isset($_SERVER) && is_array($_SERVER)){
  3567. $this->debug("In parse_http_headers, use _SERVER");
  3568. foreach ($_SERVER as $k => $v) {
  3569. if (substr($k, 0, 5) == 'HTTP_') {
  3570. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5))));
  3571. } else {
  3572. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k)));
  3573. }
  3574. if ($k == 'soapaction') {
  3575. // get SOAPAction header
  3576. $k = 'SOAPAction';
  3577. $v = str_replace('"', '', $v);
  3578. $v = str_replace('\\', '', $v);
  3579. $this->SOAPAction = $v;
  3580. } else if ($k == 'content-type') {
  3581. // get the character encoding of the incoming request
  3582. if (strpos($v, '=')) {
  3583. $enc = substr(strstr($v, '='), 1);
  3584. $enc = str_replace('"', '', $enc);
  3585. $enc = str_replace('\\', '', $enc);
  3586. if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
  3587. $this->xml_encoding = strtoupper($enc);
  3588. } else {
  3589. $this->xml_encoding = 'US-ASCII';
  3590. }
  3591. } else {
  3592. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  3593. $this->xml_encoding = 'ISO-8859-1';
  3594. }
  3595. }
  3596. $this->headers[$k] = $v;
  3597. $this->request .= "$k: $v\r\n";
  3598. $this->debug("$k: $v");
  3599. }
  3600. } elseif (is_array($HTTP_SERVER_VARS)) {
  3601. $this->debug("In parse_http_headers, use HTTP_SERVER_VARS");
  3602. foreach ($HTTP_SERVER_VARS as $k => $v) {
  3603. if (substr($k, 0, 5) == 'HTTP_') {
  3604. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', substr($k, 5)))); $k = strtolower(substr($k, 5));
  3605. } else {
  3606. $k = str_replace(' ', '-', strtolower(str_replace('_', ' ', $k))); $k = strtolower($k);
  3607. }
  3608. if ($k == 'soapaction') {
  3609. // get SOAPAction header
  3610. $k = 'SOAPAction';
  3611. $v = str_replace('"', '', $v);
  3612. $v = str_replace('\\', '', $v);
  3613. $this->SOAPAction = $v;
  3614. } else if ($k == 'content-type') {
  3615. // get the character encoding of the incoming request
  3616. if (strpos($v, '=')) {
  3617. $enc = substr(strstr($v, '='), 1);
  3618. $enc = str_replace('"', '', $enc);
  3619. $enc = str_replace('\\', '', $enc);
  3620. if (preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)) {
  3621. $this->xml_encoding = strtoupper($enc);
  3622. } else {
  3623. $this->xml_encoding = 'US-ASCII';
  3624. }
  3625. } else {
  3626. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  3627. $this->xml_encoding = 'ISO-8859-1';
  3628. }
  3629. }
  3630. $this->headers[$k] = $v;
  3631. $this->request .= "$k: $v\r\n";
  3632. $this->debug("$k: $v");
  3633. }
  3634. } else {
  3635. $this->debug("In parse_http_headers, HTTP headers not accessible");
  3636. $this->setError("HTTP headers not accessible");
  3637. }
  3638. }
  3639. /**
  3640. * parses a request
  3641. *
  3642. * The following fields are set by this function (when successful)
  3643. *
  3644. * headers
  3645. * request
  3646. * xml_encoding
  3647. * SOAPAction
  3648. * request
  3649. * requestSOAP
  3650. * methodURI
  3651. * methodname
  3652. * methodparams
  3653. * requestHeaders
  3654. * document
  3655. *
  3656. * This sets the fault field on error
  3657. *
  3658. * @param string $data XML string
  3659. * @access private
  3660. */
  3661. function parse_request($data='') {
  3662. $this->debug('entering parse_request()');
  3663. $this->parse_http_headers();
  3664. $this->debug('got character encoding: '.$this->xml_encoding);
  3665. // uncompress if necessary
  3666. if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] != '') {
  3667. $this->debug('got content encoding: ' . $this->headers['content-encoding']);
  3668. if ($this->headers['content-encoding'] == 'deflate' || $this->headers['content-encoding'] == 'gzip') {
  3669. // if decoding works, use it. else assume data wasn't gzencoded
  3670. if (function_exists('gzuncompress')) {
  3671. if ($this->headers['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
  3672. $data = $degzdata;
  3673. } elseif ($this->headers['content-encoding'] == 'gzip' && $degzdata = gzinflate(substr($data, 10))) {
  3674. $data = $degzdata;
  3675. } else {
  3676. $this->fault('SOAP-ENV:Client', 'Errors occurred when trying to decode the data');
  3677. return;
  3678. }
  3679. } else {
  3680. $this->fault('SOAP-ENV:Client', 'This Server does not support compressed data');
  3681. return;
  3682. }
  3683. }
  3684. }
  3685. $this->request .= "\r\n".$data;
  3686. $data = $this->parseRequest($this->headers, $data);
  3687. $this->requestSOAP = $data;
  3688. $this->debug('leaving parse_request');
  3689. }
  3690. /**
  3691. * invokes a PHP function for the requested SOAP method
  3692. *
  3693. * The following fields are set by this function (when successful)
  3694. *
  3695. * methodreturn
  3696. *
  3697. * Note that the PHP function that is called may also set the following
  3698. * fields to affect the response sent to the client
  3699. *
  3700. * responseHeaders
  3701. * outgoing_headers
  3702. *
  3703. * This sets the fault field on error
  3704. *
  3705. * @access private
  3706. */
  3707. function invoke_method() {
  3708. $this->debug('in invoke_method, methodname=' . $this->methodname . ' methodURI=' . $this->methodURI . ' SOAPAction=' . $this->SOAPAction);
  3709. //
  3710. // if you are debugging in this area of the code, your service uses a class to implement methods,
  3711. // you use SOAP RPC, and the client is .NET, please be aware of the following...
  3712. // when the .NET wsdl.exe utility generates a proxy, it will remove the '.' or '..' from the
  3713. // method name. that is fine for naming the .NET methods. it is not fine for properly constructing
  3714. // the XML request and reading the XML response. you need to add the RequestElementName and
  3715. // ResponseElementName to the System.Web.Services.Protocols.SoapRpcMethodAttribute that wsdl.exe
  3716. // generates for the method. these parameters are used to specify the correct XML element names
  3717. // for .NET to use, i.e. the names with the '.' in them.
  3718. //
  3719. $orig_methodname = $this->methodname;
  3720. if ($this->wsdl) {
  3721. if ($this->opData = $this->wsdl->getOperationData($this->methodname)) {
  3722. $this->debug('in invoke_method, found WSDL operation=' . $this->methodname);
  3723. $this->appendDebug('opData=' . $this->varDump($this->opData));
  3724. } elseif ($this->opData = $this->wsdl->getOperationDataForSoapAction($this->SOAPAction)) {
  3725. // Note: hopefully this case will only be used for doc/lit, since rpc services should have wrapper element
  3726. $this->debug('in invoke_method, found WSDL soapAction=' . $this->SOAPAction . ' for operation=' . $this->opData['name']);
  3727. $this->appendDebug('opData=' . $this->varDump($this->opData));
  3728. $this->methodname = $this->opData['name'];
  3729. } else {
  3730. $this->debug('in invoke_method, no WSDL for operation=' . $this->methodname);
  3731. $this->fault('SOAP-ENV:Client', "Operation '" . $this->methodname . "' is not defined in the WSDL for this service");
  3732. return;
  3733. }
  3734. } else {
  3735. $this->debug('in invoke_method, no WSDL to validate method');
  3736. }
  3737. // if a . is present in $this->methodname, we see if there is a class in scope,
  3738. // which could be referred to. We will also distinguish between two deliminators,
  3739. // to allow methods to be called a the class or an instance
  3740. if (strpos($this->methodname, '..') > 0) {
  3741. $delim = '..';
  3742. } else if (strpos($this->methodname, '.') > 0) {
  3743. $delim = '.';
  3744. } else {
  3745. $delim = '';
  3746. }
  3747. $this->debug("in invoke_method, delim=$delim");
  3748. $class = '';
  3749. $method = '';
  3750. if (strlen($delim) > 0 && substr_count($this->methodname, $delim) == 1) {
  3751. $try_class = substr($this->methodname, 0, strpos($this->methodname, $delim));
  3752. if (class_exists($try_class)) {
  3753. // get the class and method name
  3754. $class = $try_class;
  3755. $method = substr($this->methodname, strpos($this->methodname, $delim) + strlen($delim));
  3756. $this->debug("in invoke_method, class=$class method=$method delim=$delim");
  3757. } else {
  3758. $this->debug("in invoke_method, class=$try_class not found");
  3759. }
  3760. } else {
  3761. $try_class = '';
  3762. $this->debug("in invoke_method, no class to try");
  3763. }
  3764. // does method exist?
  3765. if ($class == '') {
  3766. if (!function_exists($this->methodname)) {
  3767. $this->debug("in invoke_method, function '$this->methodname' not found!");
  3768. $this->result = 'fault: method not found';
  3769. $this->fault('SOAP-ENV:Client',"method '$this->methodname'('$orig_methodname') not defined in service('$try_class' '$delim')");
  3770. return;
  3771. }
  3772. } else {
  3773. $method_to_compare = (substr(phpversion(), 0, 2) == '4.') ? strtolower($method) : $method;
  3774. if (!in_array($method_to_compare, get_class_methods($class))) {
  3775. $this->debug("in invoke_method, method '$this->methodname' not found in class '$class'!");
  3776. $this->result = 'fault: method not found';
  3777. $this->fault('SOAP-ENV:Client',"method '$this->methodname'/'$method_to_compare'('$orig_methodname') not defined in service/'$class'('$try_class' '$delim')");
  3778. return;
  3779. }
  3780. }
  3781. // evaluate message, getting back parameters
  3782. // verify that request parameters match the method's signature
  3783. if(! $this->verify_method($this->methodname,$this->methodparams)){
  3784. // debug
  3785. $this->debug('ERROR: request not verified against method signature');
  3786. $this->result = 'fault: request failed validation against method signature';
  3787. // return fault
  3788. $this->fault('SOAP-ENV:Client',"Operation '$this->methodname' not defined in service.");
  3789. return;
  3790. }
  3791. // if there are parameters to pass
  3792. $this->debug('in invoke_method, params:');
  3793. $this->appendDebug($this->varDump($this->methodparams));
  3794. $this->debug("in invoke_method, calling '$this->methodname'");
  3795. if (!function_exists('call_user_func_array')) {
  3796. if ($class == '') {
  3797. $this->debug('in invoke_method, calling function using eval()');
  3798. $funcCall = "\$this->methodreturn = $this->methodname(";
  3799. } else {
  3800. if ($delim == '..') {
  3801. $this->debug('in invoke_method, calling class method using eval()');
  3802. $funcCall = "\$this->methodreturn = ".$class."::".$method."(";
  3803. } else {
  3804. $this->debug('in invoke_method, calling instance method using eval()');
  3805. // generate unique instance name
  3806. $instname = "\$inst_".time();
  3807. $funcCall = $instname." = new ".$class."(); ";
  3808. $funcCall .= "\$this->methodreturn = ".$instname."->".$method."(";
  3809. }
  3810. }
  3811. if ($this->methodparams) {
  3812. foreach ($this->methodparams as $param) {
  3813. if (is_array($param) || is_object($param)) {
  3814. $this->fault('SOAP-ENV:Client', 'NuSOAP does not handle complexType parameters correctly when using eval; call_user_func_array must be available');
  3815. return;
  3816. }
  3817. $funcCall .= "\"$param\",";
  3818. }
  3819. $funcCall = substr($funcCall, 0, -1);
  3820. }
  3821. $funcCall .= ');';
  3822. $this->debug('in invoke_method, function call: '.$funcCall);
  3823. @eval($funcCall);
  3824. } else {
  3825. if ($class == '') {
  3826. $this->debug('in invoke_method, calling function using call_user_func_array()');
  3827. $call_arg = "$this->methodname"; // straight assignment changes $this->methodname to lower case after call_user_func_array()
  3828. } elseif ($delim == '..') {
  3829. $this->debug('in invoke_method, calling class method using call_user_func_array()');
  3830. $call_arg = array ($class, $method);
  3831. } else {
  3832. $this->debug('in invoke_method, calling instance method using call_user_func_array()');
  3833. $instance = new $class ();
  3834. $call_arg = array(&$instance, $method);
  3835. }
  3836. if (is_array($this->methodparams)) {
  3837. $this->methodreturn = call_user_func_array($call_arg, array_values($this->methodparams));
  3838. } else {
  3839. $this->methodreturn = call_user_func_array($call_arg, array());
  3840. }
  3841. }
  3842. $this->debug('in invoke_method, methodreturn:');
  3843. $this->appendDebug($this->varDump($this->methodreturn));
  3844. $this->debug("in invoke_method, called method $this->methodname, received data of type ".gettype($this->methodreturn));
  3845. }
  3846. /**
  3847. * serializes the return value from a PHP function into a full SOAP Envelope
  3848. *
  3849. * The following fields are set by this function (when successful)
  3850. *
  3851. * responseSOAP
  3852. *
  3853. * This sets the fault field on error
  3854. *
  3855. * @access private
  3856. */
  3857. function serialize_return() {
  3858. $this->debug('Entering serialize_return methodname: ' . $this->methodname . ' methodURI: ' . $this->methodURI);
  3859. // if fault
  3860. if (isset($this->methodreturn) && is_object($this->methodreturn) && ((get_class($this->methodreturn) == 'soap_fault') || (get_class($this->methodreturn) == 'nusoap_fault'))) {
  3861. $this->debug('got a fault object from method');
  3862. $this->fault = $this->methodreturn;
  3863. return;
  3864. } elseif ($this->methodreturnisliteralxml) {
  3865. $return_val = $this->methodreturn;
  3866. // returned value(s)
  3867. } else {
  3868. $this->debug('got a(n) '.gettype($this->methodreturn).' from method');
  3869. $this->debug('serializing return value');
  3870. if($this->wsdl){
  3871. if (sizeof($this->opData['output']['parts']) > 1) {
  3872. $this->debug('more than one output part, so use the method return unchanged');
  3873. $opParams = $this->methodreturn;
  3874. } elseif (sizeof($this->opData['output']['parts']) == 1) {
  3875. $this->debug('exactly one output part, so wrap the method return in a simple array');
  3876. // TODO: verify that it is not already wrapped!
  3877. //foreach ($this->opData['output']['parts'] as $name => $type) {
  3878. // $this->debug('wrap in element named ' . $name);
  3879. //}
  3880. $opParams = array($this->methodreturn);
  3881. }
  3882. $return_val = $this->wsdl->serializeRPCParameters($this->methodname,'output',$opParams);
  3883. $this->appendDebug($this->wsdl->getDebug());
  3884. $this->wsdl->clearDebug();
  3885. if($errstr = $this->wsdl->getError()){
  3886. $this->debug('got wsdl error: '.$errstr);
  3887. $this->fault('SOAP-ENV:Server', 'unable to serialize result');
  3888. return;
  3889. }
  3890. } else {
  3891. if (isset($this->methodreturn)) {
  3892. $return_val = $this->serialize_val($this->methodreturn, 'return');
  3893. } else {
  3894. $return_val = '';
  3895. $this->debug('in absence of WSDL, assume void return for backward compatibility');
  3896. }
  3897. }
  3898. }
  3899. $this->debug('return value:');
  3900. $this->appendDebug($this->varDump($return_val));
  3901. $this->debug('serializing response');
  3902. if ($this->wsdl) {
  3903. $this->debug('have WSDL for serialization: style is ' . $this->opData['style']);
  3904. if ($this->opData['style'] == 'rpc') {
  3905. $this->debug('style is rpc for serialization: use is ' . $this->opData['output']['use']);
  3906. if ($this->opData['output']['use'] == 'literal') {
  3907. // 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
  3908. if ($this->methodURI) {
  3909. $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
  3910. } else {
  3911. $payload = '<'.$this->methodname.'Response>'.$return_val.'</'.$this->methodname.'Response>';
  3912. }
  3913. } else {
  3914. if ($this->methodURI) {
  3915. $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
  3916. } else {
  3917. $payload = '<'.$this->methodname.'Response>'.$return_val.'</'.$this->methodname.'Response>';
  3918. }
  3919. }
  3920. } else {
  3921. $this->debug('style is not rpc for serialization: assume document');
  3922. $payload = $return_val;
  3923. }
  3924. } else {
  3925. $this->debug('do not have WSDL for serialization: assume rpc/encoded');
  3926. $payload = '<ns1:'.$this->methodname.'Response xmlns:ns1="'.$this->methodURI.'">'.$return_val.'</ns1:'.$this->methodname."Response>";
  3927. }
  3928. $this->result = 'successful';
  3929. if($this->wsdl){
  3930. //if($this->debug_flag){
  3931. $this->appendDebug($this->wsdl->getDebug());
  3932. // }
  3933. if (isset($this->opData['output']['encodingStyle'])) {
  3934. $encodingStyle = $this->opData['output']['encodingStyle'];
  3935. } else {
  3936. $encodingStyle = '';
  3937. }
  3938. // Added: In case we use a WSDL, return a serialized env. WITH the usedNamespaces.
  3939. $this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders,$this->wsdl->usedNamespaces,$this->opData['style'],$this->opData['output']['use'],$encodingStyle);
  3940. } else {
  3941. $this->responseSOAP = $this->serializeEnvelope($payload,$this->responseHeaders);
  3942. }
  3943. $this->debug("Leaving serialize_return");
  3944. }
  3945. /**
  3946. * sends an HTTP response
  3947. *
  3948. * The following fields are set by this function (when successful)
  3949. *
  3950. * outgoing_headers
  3951. * response
  3952. *
  3953. * @access private
  3954. */
  3955. function send_response() {
  3956. $this->debug('Enter send_response');
  3957. if ($this->fault) {
  3958. $payload = $this->fault->serialize();
  3959. $this->outgoing_headers[] = "HTTP/1.0 500 Internal Server Error";
  3960. $this->outgoing_headers[] = "Status: 500 Internal Server Error";
  3961. } else {
  3962. $payload = $this->responseSOAP;
  3963. // Some combinations of PHP+Web server allow the Status
  3964. // to come through as a header. Since OK is the default
  3965. // just do nothing.
  3966. // $this->outgoing_headers[] = "HTTP/1.0 200 OK";
  3967. // $this->outgoing_headers[] = "Status: 200 OK";
  3968. }
  3969. // add debug data if in debug mode
  3970. if(isset($this->debug_flag) && $this->debug_flag){
  3971. $payload .= $this->getDebugAsXMLComment();
  3972. }
  3973. $this->outgoing_headers[] = "Server: $this->title Server v$this->version";
  3974. // @CHANGE Fix for php8
  3975. $rev = array();
  3976. preg_match('/\$Revision: ([^ ]+)/', $this->revision, $rev);
  3977. $this->outgoing_headers[] = "X-SOAP-Server: $this->title/$this->version (".(isset($rev[1]) ? $rev[1] : '').")";
  3978. // Let the Web server decide about this
  3979. //$this->outgoing_headers[] = "Connection: Close\r\n";
  3980. $payload = $this->getHTTPBody($payload);
  3981. $type = $this->getHTTPContentType();
  3982. $charset = $this->getHTTPContentTypeCharset();
  3983. $this->outgoing_headers[] = "Content-Type: $type" . ($charset ? '; charset=' . $charset : '');
  3984. //begin code to compress payload - by John
  3985. // NOTE: there is no way to know whether the Web server will also compress
  3986. // this data.
  3987. if (strlen($payload) > 1024 && isset($this->headers) && isset($this->headers['accept-encoding'])) {
  3988. if (strstr($this->headers['accept-encoding'], 'gzip')) {
  3989. if (function_exists('gzencode')) {
  3990. if (isset($this->debug_flag) && $this->debug_flag) {
  3991. $payload .= "<!-- Content being gzipped -->";
  3992. }
  3993. $this->outgoing_headers[] = "Content-Encoding: gzip";
  3994. $payload = gzencode($payload);
  3995. } else {
  3996. if (isset($this->debug_flag) && $this->debug_flag) {
  3997. $payload .= "<!-- Content will not be gzipped: no gzencode -->";
  3998. }
  3999. }
  4000. } elseif (strstr($this->headers['accept-encoding'], 'deflate')) {
  4001. // Note: MSIE requires gzdeflate output (no Zlib header and checksum),
  4002. // instead of gzcompress output,
  4003. // which conflicts with HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.5)
  4004. if (function_exists('gzdeflate')) {
  4005. if (isset($this->debug_flag) && $this->debug_flag) {
  4006. $payload .= "<!-- Content being deflated -->";
  4007. }
  4008. $this->outgoing_headers[] = "Content-Encoding: deflate";
  4009. $payload = gzdeflate($payload);
  4010. } else {
  4011. if (isset($this->debug_flag) && $this->debug_flag) {
  4012. $payload .= "<!-- Content will not be deflated: no gzcompress -->";
  4013. }
  4014. }
  4015. }
  4016. }
  4017. //end code
  4018. $this->outgoing_headers[] = "Content-Length: ".strlen($payload);
  4019. reset($this->outgoing_headers);
  4020. foreach($this->outgoing_headers as $hdr){
  4021. header($hdr, false);
  4022. }
  4023. print $payload;
  4024. $this->response = join("\r\n",$this->outgoing_headers)."\r\n\r\n".$payload;
  4025. }
  4026. /**
  4027. * takes the value that was created by parsing the request
  4028. * and compares to the method's signature, if available.
  4029. *
  4030. * @param string $operation The operation to be invoked
  4031. * @param array $request The array of parameter values
  4032. * @return boolean Whether the operation was found
  4033. * @access private
  4034. */
  4035. function verify_method($operation,$request){
  4036. if(isset($this->wsdl) && is_object($this->wsdl)){
  4037. if($this->wsdl->getOperationData($operation)){
  4038. return true;
  4039. }
  4040. } elseif(isset($this->operations[$operation])){
  4041. return true;
  4042. }
  4043. return false;
  4044. }
  4045. /**
  4046. * processes SOAP message received from client
  4047. *
  4048. * @param array $headers The HTTP headers
  4049. * @param string $data unprocessed request data from client
  4050. * @return mixed value of the message, decoded into a PHP type
  4051. * @access private
  4052. */
  4053. function parseRequest($headers, $data) {
  4054. $this->debug('Entering parseRequest() for data of length ' . strlen($data) . ' headers:');
  4055. $this->appendDebug($this->varDump($headers));
  4056. if (!isset($headers['content-type'])) {
  4057. $this->setError('Request not of type text/xml (no content-type header)');
  4058. return false;
  4059. }
  4060. if (!strstr($headers['content-type'], 'text/xml')) {
  4061. $this->setError('Request not of type text/xml');
  4062. return false;
  4063. }
  4064. if (strpos($headers['content-type'], '=')) {
  4065. $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
  4066. $this->debug('Got response encoding: ' . $enc);
  4067. if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
  4068. $this->xml_encoding = strtoupper($enc);
  4069. } else {
  4070. $this->xml_encoding = 'US-ASCII';
  4071. }
  4072. } else {
  4073. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  4074. $this->xml_encoding = 'ISO-8859-1';
  4075. }
  4076. $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
  4077. // parse response, get soap parser obj
  4078. $parser = new nusoap_parser($data,$this->xml_encoding,'',$this->decode_utf8);
  4079. // parser debug
  4080. $this->debug("parser debug: \n".$parser->getDebug());
  4081. // if fault occurred during message parsing
  4082. if($err = $parser->getError()){
  4083. $this->result = 'fault: error in msg parsing: '.$err;
  4084. $this->fault('SOAP-ENV:Client',"error in msg parsing:\n".$err);
  4085. // else successfully parsed request into soapval object
  4086. } else {
  4087. // get/set methodname
  4088. $this->methodURI = $parser->root_struct_namespace;
  4089. $this->methodname = $parser->root_struct_name;
  4090. $this->debug('methodname: '.$this->methodname.' methodURI: '.$this->methodURI);
  4091. $this->debug('calling parser->get_soapbody()');
  4092. $this->methodparams = $parser->get_soapbody();
  4093. // get SOAP headers
  4094. $this->requestHeaders = $parser->getHeaders();
  4095. // get SOAP Header
  4096. $this->requestHeader = $parser->get_soapheader();
  4097. // add document for doclit support
  4098. $this->document = $parser->document;
  4099. }
  4100. }
  4101. /**
  4102. * gets the HTTP body for the current response.
  4103. *
  4104. * @param string $soapmsg The SOAP payload
  4105. * @return string The HTTP body, which includes the SOAP payload
  4106. * @access private
  4107. */
  4108. function getHTTPBody($soapmsg) {
  4109. return $soapmsg;
  4110. }
  4111. /**
  4112. * gets the HTTP content type for the current response.
  4113. *
  4114. * Note: getHTTPBody must be called before this.
  4115. *
  4116. * @return string the HTTP content type for the current response.
  4117. * @access private
  4118. */
  4119. function getHTTPContentType() {
  4120. return 'text/xml';
  4121. }
  4122. /**
  4123. * gets the HTTP content type charset for the current response.
  4124. * returns false for non-text content types.
  4125. *
  4126. * Note: getHTTPBody must be called before this.
  4127. *
  4128. * @return string the HTTP content type charset for the current response.
  4129. * @access private
  4130. */
  4131. function getHTTPContentTypeCharset() {
  4132. return $this->soap_defencoding;
  4133. }
  4134. /**
  4135. * add a method to the dispatch map (this has been replaced by the register method)
  4136. *
  4137. * @param string $methodname
  4138. * @param string $in array of input values
  4139. * @param string $out array of output values
  4140. * @access public
  4141. * @deprecated
  4142. */
  4143. function add_to_map($methodname,$in,$out){
  4144. $this->operations[$methodname] = array('name' => $methodname,'in' => $in,'out' => $out);
  4145. }
  4146. /**
  4147. * register a service function with the server
  4148. *
  4149. * @param string $name the name of the PHP function, class.method or class..method
  4150. * @param array $in assoc array of input values: key = param name, value = param type
  4151. * @param array $out assoc array of output values: key = param name, value = param type
  4152. * @param mixed $namespace the element namespace for the method or false
  4153. * @param mixed $soapaction the soapaction for the method or false
  4154. * @param mixed $style optional (rpc|document) or false Note: when 'document' is specified, parameter and return wrappers are created for you automatically
  4155. * @param mixed $use optional (encoded|literal) or false
  4156. * @param string $documentation optional Description to include in WSDL
  4157. * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
  4158. * @access public
  4159. */
  4160. function register($name,$in=array(),$out=array(),$namespace=false,$soapaction=false,$style=false,$use=false,$documentation='',$encodingStyle=''){
  4161. global $HTTP_SERVER_VARS;
  4162. if($this->externalWSDLURL){
  4163. die('You cannot bind to an external WSDL file, and register methods outside of it! Please choose either WSDL or no WSDL.');
  4164. }
  4165. if (! $name) {
  4166. die('You must specify a name when you register an operation');
  4167. }
  4168. if (!is_array($in)) {
  4169. die('You must provide an array for operation inputs');
  4170. }
  4171. if (!is_array($out)) {
  4172. die('You must provide an array for operation outputs');
  4173. }
  4174. if(false == $namespace) {
  4175. }
  4176. if(false == $soapaction) {
  4177. if (isset($_SERVER)) {
  4178. $SERVER_NAME = $_SERVER['SERVER_NAME'];
  4179. $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
  4180. $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
  4181. } elseif (isset($HTTP_SERVER_VARS)) {
  4182. $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
  4183. $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
  4184. $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
  4185. } else {
  4186. $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
  4187. }
  4188. if ($HTTPS == '1' || $HTTPS == 'on') {
  4189. $SCHEME = 'https';
  4190. } else {
  4191. $SCHEME = 'http';
  4192. }
  4193. $soapaction = "$SCHEME://$SERVER_NAME$SCRIPT_NAME/$name";
  4194. }
  4195. if(false == $style) {
  4196. $style = "rpc";
  4197. }
  4198. if(false == $use) {
  4199. $use = "encoded";
  4200. }
  4201. if ($use == 'encoded' && $encodingStyle == '') {
  4202. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  4203. }
  4204. $this->operations[$name] = array(
  4205. 'name' => $name,
  4206. 'in' => $in,
  4207. 'out' => $out,
  4208. 'namespace' => $namespace,
  4209. 'soapaction' => $soapaction,
  4210. 'style' => $style);
  4211. if($this->wsdl){
  4212. $this->wsdl->addOperation($name,$in,$out,$namespace,$soapaction,$style,$use,$documentation,$encodingStyle);
  4213. }
  4214. return true;
  4215. }
  4216. /**
  4217. * Specify a fault to be returned to the client.
  4218. * This also acts as a flag to the server that a fault has occured.
  4219. *
  4220. * @param string $faultcode
  4221. * @param string $faultstring
  4222. * @param string $faultactor
  4223. * @param string $faultdetail
  4224. * @access public
  4225. */
  4226. function fault($faultcode,$faultstring,$faultactor='',$faultdetail=''){
  4227. if ($faultdetail == '' && $this->debug_flag) {
  4228. $faultdetail = $this->getDebug();
  4229. }
  4230. $this->fault = new nusoap_fault($faultcode,$faultactor,$faultstring,$faultdetail);
  4231. $this->fault->soap_defencoding = $this->soap_defencoding;
  4232. }
  4233. /**
  4234. * Sets up wsdl object.
  4235. * Acts as a flag to enable internal WSDL generation
  4236. *
  4237. * @param string $serviceName, name of the service
  4238. * @param mixed $namespace optional 'tns' service namespace or false
  4239. * @param mixed $endpoint optional URL of service endpoint or false
  4240. * @param string $style optional (rpc|document) WSDL style (also specified by operation)
  4241. * @param string $transport optional SOAP transport
  4242. * @param mixed $schemaTargetNamespace optional 'types' targetNamespace for service schema or false
  4243. */
  4244. function configureWSDL($serviceName,$namespace = false,$endpoint = false,$style='rpc', $transport = 'http://schemas.xmlsoap.org/soap/http', $schemaTargetNamespace = false)
  4245. {
  4246. global $HTTP_SERVER_VARS;
  4247. if (isset($_SERVER)) {
  4248. $SERVER_NAME = $_SERVER['SERVER_NAME'];
  4249. $SERVER_PORT = $_SERVER['SERVER_PORT'];
  4250. $SCRIPT_NAME = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
  4251. $HTTPS = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : (isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off');
  4252. } elseif (isset($HTTP_SERVER_VARS)) {
  4253. $SERVER_NAME = $HTTP_SERVER_VARS['SERVER_NAME'];
  4254. $SERVER_PORT = $HTTP_SERVER_VARS['SERVER_PORT'];
  4255. $SCRIPT_NAME = isset($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : $HTTP_SERVER_VARS['SCRIPT_NAME'];
  4256. $HTTPS = isset($HTTP_SERVER_VARS['HTTPS']) ? $HTTP_SERVER_VARS['HTTPS'] : 'off';
  4257. } else {
  4258. $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
  4259. }
  4260. // If server name has port number attached then strip it (else port number gets duplicated in WSDL output) (occurred using lighttpd and FastCGI)
  4261. $colon = strpos($SERVER_NAME,":");
  4262. if ($colon) {
  4263. $SERVER_NAME = substr($SERVER_NAME, 0, $colon);
  4264. }
  4265. if ($SERVER_PORT == 80) {
  4266. $SERVER_PORT = '';
  4267. } else {
  4268. $SERVER_PORT = ':' . $SERVER_PORT;
  4269. }
  4270. if(false == $namespace) {
  4271. $namespace = "http://$SERVER_NAME/soap/$serviceName";
  4272. }
  4273. if(false == $endpoint) {
  4274. if ($HTTPS == '1' || $HTTPS == 'on') {
  4275. $SCHEME = 'https';
  4276. } else {
  4277. $SCHEME = 'http';
  4278. }
  4279. $endpoint = "$SCHEME://$SERVER_NAME$SERVER_PORT$SCRIPT_NAME";
  4280. }
  4281. if(false == $schemaTargetNamespace) {
  4282. $schemaTargetNamespace = $namespace;
  4283. }
  4284. $this->wsdl = new wsdl;
  4285. $this->wsdl->serviceName = $serviceName;
  4286. $this->wsdl->endpoint = $endpoint;
  4287. $this->wsdl->namespaces['tns'] = $namespace;
  4288. $this->wsdl->namespaces['soap'] = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4289. $this->wsdl->namespaces['wsdl'] = 'http://schemas.xmlsoap.org/wsdl/';
  4290. if ($schemaTargetNamespace != $namespace) {
  4291. $this->wsdl->namespaces['types'] = $schemaTargetNamespace;
  4292. }
  4293. $this->wsdl->schemas[$schemaTargetNamespace][0] = new nusoap_xmlschema('', '', $this->wsdl->namespaces);
  4294. if ($style == 'document') {
  4295. $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaInfo['elementFormDefault'] = 'qualified';
  4296. }
  4297. $this->wsdl->schemas[$schemaTargetNamespace][0]->schemaTargetNamespace = $schemaTargetNamespace;
  4298. $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/soap/encoding/'][0] = array('location' => '', 'loaded' => true);
  4299. $this->wsdl->schemas[$schemaTargetNamespace][0]->imports['http://schemas.xmlsoap.org/wsdl/'][0] = array('location' => '', 'loaded' => true);
  4300. $this->wsdl->bindings[$serviceName.'Binding'] = array(
  4301. 'name'=>$serviceName.'Binding',
  4302. 'style'=>$style,
  4303. 'transport'=>$transport,
  4304. 'portType'=>$serviceName.'PortType');
  4305. $this->wsdl->ports[$serviceName.'Port'] = array(
  4306. 'binding'=>$serviceName.'Binding',
  4307. 'location'=>$endpoint,
  4308. 'bindingType'=>'http://schemas.xmlsoap.org/wsdl/soap/');
  4309. }
  4310. }
  4311. /**
  4312. * Backward compatibility
  4313. */
  4314. class soap_server extends nusoap_server {
  4315. }
  4316. ?><?php
  4317. /**
  4318. * parses a WSDL file, allows access to it's data, other utility methods.
  4319. * also builds WSDL structures programmatically.
  4320. *
  4321. * @author Dietrich Ayala <dietrich@ganx4.com>
  4322. * @author Scott Nichol <snichol@users.sourceforge.net>
  4323. * @access public
  4324. */
  4325. class wsdl extends nusoap_base {
  4326. // URL or filename of the root of this WSDL
  4327. var $wsdl;
  4328. // define internal arrays of bindings, ports, operations, messages, etc.
  4329. var $schemas = array();
  4330. var $currentSchema;
  4331. var $message = array();
  4332. var $complexTypes = array();
  4333. var $messages = array();
  4334. var $currentMessage;
  4335. var $currentOperation;
  4336. var $portTypes = array();
  4337. var $currentPortType;
  4338. var $bindings = array();
  4339. var $currentBinding;
  4340. var $ports = array();
  4341. var $currentPort;
  4342. var $opData = array();
  4343. var $status = '';
  4344. var $documentation = false;
  4345. var $endpoint = '';
  4346. // array of wsdl docs to import
  4347. var $import = array();
  4348. // parser vars
  4349. var $parser;
  4350. var $position = 0;
  4351. var $depth = 0;
  4352. var $depth_array = array();
  4353. // for getting wsdl
  4354. var $proxyhost = '';
  4355. var $proxyport = '';
  4356. var $proxyusername = '';
  4357. var $proxypassword = '';
  4358. var $timeout = 0;
  4359. var $response_timeout = 30;
  4360. var $curl_options = array(); // User-specified cURL options
  4361. var $use_curl = false; // whether to always try to use cURL
  4362. // for HTTP authentication
  4363. var $username = ''; // Username for HTTP authentication
  4364. var $password = ''; // Password for HTTP authentication
  4365. var $authtype = ''; // Type of HTTP authentication
  4366. var $certRequest = array(); // Certificate for HTTP SSL authentication
  4367. /**
  4368. * constructor
  4369. *
  4370. * @param string $wsdl WSDL document URL
  4371. * @param string $proxyhost
  4372. * @param string $proxyport
  4373. * @param string $proxyusername
  4374. * @param string $proxypassword
  4375. * @param integer $timeout set the connection timeout
  4376. * @param integer $response_timeout set the response timeout
  4377. * @param array $curl_options user-specified cURL options
  4378. * @param boolean $use_curl try to use cURL
  4379. * @access public
  4380. */
  4381. function __construct($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){
  4382. parent::__construct();
  4383. $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
  4384. $this->proxyhost = $proxyhost;
  4385. $this->proxyport = $proxyport;
  4386. $this->proxyusername = $proxyusername;
  4387. $this->proxypassword = $proxypassword;
  4388. $this->timeout = $timeout;
  4389. $this->response_timeout = $response_timeout;
  4390. if (is_array($curl_options))
  4391. $this->curl_options = $curl_options;
  4392. $this->use_curl = $use_curl;
  4393. $this->fetchWSDL($wsdl);
  4394. }
  4395. /**
  4396. * fetches the WSDL document and parses it
  4397. *
  4398. * @access public
  4399. */
  4400. function fetchWSDL($wsdl) {
  4401. $this->debug("parse and process WSDL path=$wsdl");
  4402. $this->wsdl = $wsdl;
  4403. // parse wsdl file
  4404. if ($this->wsdl != "") {
  4405. $this->parseWSDL($this->wsdl);
  4406. }
  4407. // imports
  4408. // TODO: handle imports more properly, grabbing them in-line and nesting them
  4409. $imported_urls = array();
  4410. $imported = 1;
  4411. while ($imported > 0) {
  4412. $imported = 0;
  4413. // Schema imports
  4414. foreach ($this->schemas as $ns => $list) {
  4415. foreach ($list as $xs) {
  4416. $wsdlparts = parse_url($this->wsdl); // this is bogusly simple!
  4417. foreach ($xs->imports as $ns2 => $list2) {
  4418. for ($ii = 0; $ii < count($list2); $ii++) {
  4419. if (! $list2[$ii]['loaded']) {
  4420. $this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
  4421. $url = $list2[$ii]['location'];
  4422. if ($url != '') {
  4423. $urlparts = parse_url($url);
  4424. if (!isset($urlparts['host'])) {
  4425. $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') .
  4426. substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
  4427. }
  4428. if (! in_array($url, $imported_urls)) {
  4429. $this->parseWSDL($url);
  4430. $imported++;
  4431. $imported_urls[] = $url;
  4432. }
  4433. } else {
  4434. $this->debug("Unexpected scenario: empty URL for unloaded import");
  4435. }
  4436. }
  4437. }
  4438. }
  4439. }
  4440. }
  4441. // WSDL imports
  4442. $wsdlparts = parse_url($this->wsdl); // this is bogusly simple!
  4443. foreach ($this->import as $ns => $list) {
  4444. for ($ii = 0; $ii < count($list); $ii++) {
  4445. if (! $list[$ii]['loaded']) {
  4446. $this->import[$ns][$ii]['loaded'] = true;
  4447. $url = $list[$ii]['location'];
  4448. if ($url != '') {
  4449. $urlparts = parse_url($url);
  4450. if (!isset($urlparts['host'])) {
  4451. $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') .
  4452. substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path'];
  4453. }
  4454. if (! in_array($url, $imported_urls)) {
  4455. $this->parseWSDL($url);
  4456. $imported++;
  4457. $imported_urls[] = $url;
  4458. }
  4459. } else {
  4460. $this->debug("Unexpected scenario: empty URL for unloaded import");
  4461. }
  4462. }
  4463. }
  4464. }
  4465. }
  4466. // add new data to operation data
  4467. foreach($this->bindings as $binding => $bindingData) {
  4468. if (isset($bindingData['operations']) && is_array($bindingData['operations'])) {
  4469. foreach($bindingData['operations'] as $operation => $data) {
  4470. $this->debug('post-parse data gathering for ' . $operation);
  4471. $this->bindings[$binding]['operations'][$operation]['input'] =
  4472. isset($this->bindings[$binding]['operations'][$operation]['input']) ?
  4473. array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) :
  4474. $this->portTypes[ $bindingData['portType'] ][$operation]['input'];
  4475. $this->bindings[$binding]['operations'][$operation]['output'] =
  4476. isset($this->bindings[$binding]['operations'][$operation]['output']) ?
  4477. array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) :
  4478. $this->portTypes[ $bindingData['portType'] ][$operation]['output'];
  4479. if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){
  4480. $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ];
  4481. }
  4482. if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){
  4483. $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ];
  4484. }
  4485. // Set operation style if necessary, but do not override one already provided
  4486. if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) {
  4487. $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style'];
  4488. }
  4489. $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : '';
  4490. $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : '';
  4491. $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : '';
  4492. }
  4493. }
  4494. }
  4495. }
  4496. /**
  4497. * parses the wsdl document
  4498. *
  4499. * @param string $wsdl path or URL
  4500. * @access private
  4501. */
  4502. function parseWSDL($wsdl = '') {
  4503. $this->debug("parse WSDL at path=$wsdl");
  4504. if ($wsdl == '') {
  4505. $this->debug('no wsdl passed to parseWSDL()!!');
  4506. $this->setError('no wsdl passed to parseWSDL()!!');
  4507. return false;
  4508. }
  4509. // parse $wsdl for url format
  4510. $wsdl_props = parse_url($wsdl);
  4511. if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) {
  4512. $this->debug('getting WSDL http(s) URL ' . $wsdl);
  4513. // get wsdl
  4514. $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl);
  4515. $tr->request_method = 'GET';
  4516. $tr->useSOAPAction = false;
  4517. if($this->proxyhost && $this->proxyport){
  4518. $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
  4519. }
  4520. if ($this->authtype != '') {
  4521. $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
  4522. }
  4523. $tr->setEncoding('gzip, deflate');
  4524. $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout);
  4525. //$this->debug("WSDL request\n" . $tr->outgoing_payload);
  4526. //$this->debug("WSDL response\n" . $tr->incoming_payload);
  4527. $this->appendDebug($tr->getDebug());
  4528. // catch errors
  4529. if($err = $tr->getError() ){
  4530. $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err;
  4531. $this->debug($errstr);
  4532. $this->setError($errstr);
  4533. unset($tr);
  4534. return false;
  4535. }
  4536. unset($tr);
  4537. $this->debug("got WSDL URL");
  4538. } else {
  4539. // $wsdl is not http(s), so treat it as a file URL or plain file path
  4540. if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) {
  4541. $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path'];
  4542. } else {
  4543. $path = $wsdl;
  4544. }
  4545. $this->debug('getting WSDL file ' . $path);
  4546. if ($fp = @fopen($path, 'r')) {
  4547. $wsdl_string = '';
  4548. while ($data = fread($fp, 32768)) {
  4549. $wsdl_string .= $data;
  4550. }
  4551. fclose($fp);
  4552. } else {
  4553. $errstr = "Bad path to WSDL file $path";
  4554. $this->debug($errstr);
  4555. $this->setError($errstr);
  4556. return false;
  4557. }
  4558. }
  4559. $this->debug('Parse WSDL');
  4560. // end new code added
  4561. // Create an XML parser.
  4562. $this->parser = xml_parser_create();
  4563. // Set the options for parsing the XML data.
  4564. // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  4565. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  4566. // Set the object for the parser.
  4567. xml_set_object($this->parser, $this);
  4568. // Set the element handlers for the parser.
  4569. xml_set_element_handler($this->parser, 'start_element', 'end_element');
  4570. xml_set_character_data_handler($this->parser, 'character_data');
  4571. // Parse the XML file.
  4572. if (!xml_parse($this->parser, $wsdl_string, true)) {
  4573. // Display an error message.
  4574. $errstr = sprintf(
  4575. 'XML error parsing WSDL from %s on line %d: %s',
  4576. $wsdl,
  4577. xml_get_current_line_number($this->parser),
  4578. xml_error_string(xml_get_error_code($this->parser))
  4579. );
  4580. $this->debug($errstr);
  4581. $this->debug("XML payload:\n" . $wsdl_string);
  4582. $this->setError($errstr);
  4583. return false;
  4584. }
  4585. // free the parser
  4586. xml_parser_free($this->parser);
  4587. $this->debug('Parsing WSDL done');
  4588. // catch wsdl parse errors
  4589. if($this->getError()){
  4590. return false;
  4591. }
  4592. return true;
  4593. }
  4594. /**
  4595. * start-element handler
  4596. *
  4597. * @param string $parser XML parser object
  4598. * @param string $name element name
  4599. * @param string $attrs associative array of attributes
  4600. * @access private
  4601. */
  4602. function start_element($parser, $name, $attrs)
  4603. {
  4604. if ($this->status == 'schema') {
  4605. $this->currentSchema->schemaStartElement($parser, $name, $attrs);
  4606. $this->appendDebug($this->currentSchema->getDebug());
  4607. $this->currentSchema->clearDebug();
  4608. } elseif (preg_match('/schema$/', $name)) {
  4609. $this->debug('Parsing WSDL schema');
  4610. // $this->debug("startElement for $name ($attrs[name]). status = $this->status (".$this->getLocalPart($name).")");
  4611. $this->status = 'schema';
  4612. $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces);
  4613. $this->currentSchema->schemaStartElement($parser, $name, $attrs);
  4614. $this->appendDebug($this->currentSchema->getDebug());
  4615. $this->currentSchema->clearDebug();
  4616. } else {
  4617. // position in the total number of elements, starting from 0
  4618. $pos = $this->position++;
  4619. $depth = $this->depth++;
  4620. // set self as current value for this depth
  4621. $this->depth_array[$depth] = $pos;
  4622. $this->message[$pos] = array('cdata' => '');
  4623. // process attributes
  4624. if (count($attrs) > 0) {
  4625. // register namespace declarations
  4626. foreach($attrs as $k => $v) {
  4627. if (preg_match('/^xmlns/',$k)) {
  4628. if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
  4629. $this->namespaces[$ns_prefix] = $v;
  4630. } else {
  4631. $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
  4632. }
  4633. if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
  4634. $this->XMLSchemaVersion = $v;
  4635. $this->namespaces['xsi'] = $v . '-instance';
  4636. }
  4637. }
  4638. }
  4639. // expand each attribute prefix to its namespace
  4640. foreach($attrs as $k => $v) {
  4641. $k = strpos($k, ':') ? $this->expandQname($k) : $k;
  4642. if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') {
  4643. $v = strpos($v, ':') ? $this->expandQname($v) : $v;
  4644. }
  4645. $eAttrs[$k] = $v;
  4646. }
  4647. $attrs = $eAttrs;
  4648. } else {
  4649. $attrs = array();
  4650. }
  4651. // get element prefix, namespace and name
  4652. if (preg_match('/:/', $name)) {
  4653. // get ns prefix
  4654. $prefix = substr($name, 0, strpos($name, ':'));
  4655. // get ns
  4656. $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : '';
  4657. // get unqualified name
  4658. $name = substr(strstr($name, ':'), 1);
  4659. }
  4660. // process attributes, expanding any prefixes to namespaces
  4661. // find status, register data
  4662. switch ($this->status) {
  4663. case 'message':
  4664. if ($name == 'part') {
  4665. if (isset($attrs['type'])) {
  4666. $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs));
  4667. $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type'];
  4668. }
  4669. if (isset($attrs['element'])) {
  4670. $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs));
  4671. $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^';
  4672. }
  4673. }
  4674. break;
  4675. case 'portType':
  4676. switch ($name) {
  4677. case 'operation':
  4678. $this->currentPortOperation = $attrs['name'];
  4679. $this->debug("portType $this->currentPortType operation: $this->currentPortOperation");
  4680. if (isset($attrs['parameterOrder'])) {
  4681. $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder'];
  4682. }
  4683. break;
  4684. case 'documentation':
  4685. $this->documentation = true;
  4686. break;
  4687. // merge input/output data
  4688. default:
  4689. $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : '';
  4690. $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m;
  4691. break;
  4692. }
  4693. break;
  4694. case 'binding':
  4695. switch ($name) {
  4696. case 'binding':
  4697. // get ns prefix
  4698. if (isset($attrs['style'])) {
  4699. $this->bindings[$this->currentBinding]['prefix'] = $prefix;
  4700. }
  4701. $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs);
  4702. break;
  4703. case 'header':
  4704. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs;
  4705. break;
  4706. case 'operation':
  4707. if (isset($attrs['soapAction'])) {
  4708. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction'];
  4709. }
  4710. if (isset($attrs['style'])) {
  4711. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style'];
  4712. }
  4713. if (isset($attrs['name'])) {
  4714. $this->currentOperation = $attrs['name'];
  4715. $this->debug("current binding operation: $this->currentOperation");
  4716. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name'];
  4717. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding;
  4718. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : '';
  4719. }
  4720. break;
  4721. case 'input':
  4722. $this->opStatus = 'input';
  4723. break;
  4724. case 'output':
  4725. $this->opStatus = 'output';
  4726. break;
  4727. case 'body':
  4728. if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) {
  4729. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs);
  4730. } else {
  4731. $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs;
  4732. }
  4733. break;
  4734. }
  4735. break;
  4736. case 'service':
  4737. switch ($name) {
  4738. case 'port':
  4739. $this->currentPort = $attrs['name'];
  4740. $this->debug('current port: ' . $this->currentPort);
  4741. $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']);
  4742. break;
  4743. case 'address':
  4744. $this->ports[$this->currentPort]['location'] = $attrs['location'];
  4745. $this->ports[$this->currentPort]['bindingType'] = $namespace;
  4746. $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace;
  4747. $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location'];
  4748. break;
  4749. }
  4750. break;
  4751. }
  4752. // set status
  4753. switch ($name) {
  4754. case 'import':
  4755. if (isset($attrs['location'])) {
  4756. $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false);
  4757. $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')');
  4758. } else {
  4759. $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true);
  4760. if (! $this->getPrefixFromNamespace($attrs['namespace'])) {
  4761. $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace'];
  4762. }
  4763. $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')');
  4764. }
  4765. break;
  4766. //wait for schema
  4767. //case 'types':
  4768. // $this->status = 'schema';
  4769. // break;
  4770. case 'message':
  4771. $this->status = 'message';
  4772. $this->messages[$attrs['name']] = array();
  4773. $this->currentMessage = $attrs['name'];
  4774. break;
  4775. case 'portType':
  4776. $this->status = 'portType';
  4777. $this->portTypes[$attrs['name']] = array();
  4778. $this->currentPortType = $attrs['name'];
  4779. break;
  4780. case "binding":
  4781. if (isset($attrs['name'])) {
  4782. // get binding name
  4783. if (strpos($attrs['name'], ':')) {
  4784. $this->currentBinding = $this->getLocalPart($attrs['name']);
  4785. } else {
  4786. $this->currentBinding = $attrs['name'];
  4787. }
  4788. $this->status = 'binding';
  4789. $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']);
  4790. $this->debug("current binding: $this->currentBinding of portType: " . $attrs['type']);
  4791. }
  4792. break;
  4793. case 'service':
  4794. $this->serviceName = $attrs['name'];
  4795. $this->status = 'service';
  4796. $this->debug('current service: ' . $this->serviceName);
  4797. break;
  4798. case 'definitions':
  4799. foreach ($attrs as $name => $value) {
  4800. $this->wsdl_info[$name] = $value;
  4801. }
  4802. break;
  4803. }
  4804. }
  4805. }
  4806. /**
  4807. * end-element handler
  4808. *
  4809. * @param string $parser XML parser object
  4810. * @param string $name element name
  4811. * @access private
  4812. */
  4813. function end_element($parser, $name){
  4814. // unset schema status
  4815. if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) {
  4816. $this->status = "";
  4817. $this->appendDebug($this->currentSchema->getDebug());
  4818. $this->currentSchema->clearDebug();
  4819. $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema;
  4820. $this->debug('Parsing WSDL schema done');
  4821. }
  4822. if ($this->status == 'schema') {
  4823. $this->currentSchema->schemaEndElement($parser, $name);
  4824. } else {
  4825. // bring depth down a notch
  4826. $this->depth--;
  4827. }
  4828. // end documentation
  4829. if ($this->documentation) {
  4830. //TODO: track the node to which documentation should be assigned; it can be a part, message, etc.
  4831. //$this->portTypes[$this->currentPortType][$this->currentPortOperation]['documentation'] = $this->documentation;
  4832. $this->documentation = false;
  4833. }
  4834. }
  4835. /**
  4836. * element content handler
  4837. *
  4838. * @param string $parser XML parser object
  4839. * @param string $data element content
  4840. * @access private
  4841. */
  4842. function character_data($parser, $data)
  4843. {
  4844. $pos = isset($this->depth_array[$this->depth]) ? $this->depth_array[$this->depth] : 0;
  4845. if (isset($this->message[$pos]['cdata'])) {
  4846. $this->message[$pos]['cdata'] .= $data;
  4847. }
  4848. if ($this->documentation) {
  4849. $this->documentation .= $data;
  4850. }
  4851. }
  4852. /**
  4853. * if authenticating, set user credentials here
  4854. *
  4855. * @param string $username
  4856. * @param string $password
  4857. * @param string $authtype (basic|digest|certificate|ntlm)
  4858. * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
  4859. * @access public
  4860. */
  4861. function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
  4862. $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
  4863. $this->appendDebug($this->varDump($certRequest));
  4864. $this->username = $username;
  4865. $this->password = $password;
  4866. $this->authtype = $authtype;
  4867. $this->certRequest = $certRequest;
  4868. }
  4869. function getBindingData($binding)
  4870. {
  4871. if (is_array($this->bindings[$binding])) {
  4872. return $this->bindings[$binding];
  4873. }
  4874. }
  4875. /**
  4876. * returns an assoc array of operation names => operation data
  4877. *
  4878. * @param string $portName WSDL port name
  4879. * @param string $bindingType eg: soap, smtp, dime (only soap and soap12 are currently supported)
  4880. * @return array
  4881. * @access public
  4882. */
  4883. function getOperations($portName = '', $bindingType = 'soap') {
  4884. $ops = array();
  4885. if ($bindingType == 'soap') {
  4886. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4887. } elseif ($bindingType == 'soap12') {
  4888. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
  4889. } else {
  4890. $this->debug("getOperations bindingType $bindingType may not be supported");
  4891. }
  4892. $this->debug("getOperations for port '$portName' bindingType $bindingType");
  4893. // loop thru ports
  4894. foreach($this->ports as $port => $portData) {
  4895. $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']);
  4896. if ($portName == '' || $port == $portName) {
  4897. // binding type of port matches parameter
  4898. if ($portData['bindingType'] == $bindingType) {
  4899. $this->debug("getOperations found port $port bindingType $bindingType");
  4900. //$this->debug("port data: " . $this->varDump($portData));
  4901. //$this->debug("bindings: " . $this->varDump($this->bindings[ $portData['binding'] ]));
  4902. // merge bindings
  4903. if (isset($this->bindings[ $portData['binding'] ]['operations'])) {
  4904. $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']);
  4905. }
  4906. }
  4907. }
  4908. }
  4909. if (count($ops) == 0) {
  4910. $this->debug("getOperations found no operations for port '$portName' bindingType $bindingType");
  4911. }
  4912. return $ops;
  4913. }
  4914. /**
  4915. * returns an associative array of data necessary for calling an operation
  4916. *
  4917. * @param string $operation name of operation
  4918. * @param string $bindingType type of binding eg: soap, soap12
  4919. * @return array
  4920. * @access public
  4921. */
  4922. function getOperationData($operation, $bindingType = 'soap')
  4923. {
  4924. if ($bindingType == 'soap') {
  4925. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4926. } elseif ($bindingType == 'soap12') {
  4927. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
  4928. }
  4929. // loop thru ports
  4930. foreach($this->ports as $port => $portData) {
  4931. // binding type of port matches parameter
  4932. if ($portData['bindingType'] == $bindingType) {
  4933. // get binding
  4934. //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
  4935. foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) {
  4936. // note that we could/should also check the namespace here
  4937. if ($operation == $bOperation) {
  4938. $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation];
  4939. return $opData;
  4940. }
  4941. }
  4942. }
  4943. }
  4944. }
  4945. /**
  4946. * returns an associative array of data necessary for calling an operation
  4947. *
  4948. * @param string $soapAction soapAction for operation
  4949. * @param string $bindingType type of binding eg: soap, soap12
  4950. * @return array
  4951. * @access public
  4952. */
  4953. function getOperationDataForSoapAction($soapAction, $bindingType = 'soap') {
  4954. if ($bindingType == 'soap') {
  4955. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap/';
  4956. } elseif ($bindingType == 'soap12') {
  4957. $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/';
  4958. }
  4959. // loop thru ports
  4960. foreach($this->ports as $port => $portData) {
  4961. // binding type of port matches parameter
  4962. if ($portData['bindingType'] == $bindingType) {
  4963. // loop through operations for the binding
  4964. foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) {
  4965. if ($opData['soapAction'] == $soapAction) {
  4966. return $opData;
  4967. }
  4968. }
  4969. }
  4970. }
  4971. }
  4972. /**
  4973. * returns an array of information about a given type
  4974. * returns false if no type exists by the given name
  4975. *
  4976. * typeDef = array(
  4977. * 'elements' => array(), // refs to elements array
  4978. * 'restrictionBase' => '',
  4979. * 'phpType' => '',
  4980. * 'order' => '(sequence|all)',
  4981. * 'attrs' => array() // refs to attributes array
  4982. * )
  4983. *
  4984. * @param string $type the type
  4985. * @param string $ns namespace (not prefix) of the type
  4986. * @return mixed
  4987. * @access public
  4988. * @see nusoap_xmlschema
  4989. */
  4990. function getTypeDef($type, $ns) {
  4991. $this->debug("in getTypeDef: type=$type, ns=$ns");
  4992. if ((! $ns) && isset($this->namespaces['tns'])) {
  4993. $ns = $this->namespaces['tns'];
  4994. $this->debug("in getTypeDef: type namespace forced to $ns");
  4995. }
  4996. if (!isset($this->schemas[$ns])) {
  4997. foreach ($this->schemas as $ns0 => $schema0) {
  4998. if (strcasecmp($ns, $ns0) == 0) {
  4999. $this->debug("in getTypeDef: replacing schema namespace $ns with $ns0");
  5000. $ns = $ns0;
  5001. break;
  5002. }
  5003. }
  5004. }
  5005. if (isset($this->schemas[$ns])) {
  5006. $this->debug("in getTypeDef: have schema for namespace $ns");
  5007. for ($i = 0; $i < count($this->schemas[$ns]); $i++) {
  5008. $xs = &$this->schemas[$ns][$i];
  5009. $t = $xs->getTypeDef($type);
  5010. $this->appendDebug($xs->getDebug());
  5011. $xs->clearDebug();
  5012. if ($t) {
  5013. $this->debug("in getTypeDef: found type $type");
  5014. if (!isset($t['phpType'])) {
  5015. // get info for type to tack onto the element
  5016. $uqType = substr($t['type'], strrpos($t['type'], ':') + 1);
  5017. $ns = substr($t['type'], 0, strrpos($t['type'], ':'));
  5018. $etype = $this->getTypeDef($uqType, $ns);
  5019. if ($etype) {
  5020. $this->debug("found type for [element] $type:");
  5021. $this->debug($this->varDump($etype));
  5022. if (isset($etype['phpType'])) {
  5023. $t['phpType'] = $etype['phpType'];
  5024. }
  5025. if (isset($etype['elements'])) {
  5026. $t['elements'] = $etype['elements'];
  5027. }
  5028. if (isset($etype['attrs'])) {
  5029. $t['attrs'] = $etype['attrs'];
  5030. }
  5031. } else {
  5032. $this->debug("did not find type for [element] $type");
  5033. }
  5034. }
  5035. return $t;
  5036. }
  5037. }
  5038. $this->debug("in getTypeDef: did not find type $type");
  5039. } else {
  5040. $this->debug("in getTypeDef: do not have schema for namespace $ns");
  5041. }
  5042. return false;
  5043. }
  5044. /**
  5045. * prints html description of services
  5046. *
  5047. * @access private
  5048. */
  5049. function webDescription(){
  5050. global $HTTP_SERVER_VARS;
  5051. if (isset($_SERVER)) {
  5052. $PHP_SELF = $_SERVER['PHP_SELF'];
  5053. } elseif (isset($HTTP_SERVER_VARS)) {
  5054. $PHP_SELF = $HTTP_SERVER_VARS['PHP_SELF'];
  5055. } else {
  5056. $this->setError("Neither _SERVER nor HTTP_SERVER_VARS is available");
  5057. }
  5058. $b = '
  5059. <html><head><title>NuSOAP: '.$this->serviceName.'</title>
  5060. <style type="text/css">
  5061. body { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; }
  5062. p { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; }
  5063. pre { background-color: silver; padding: 5px; font-family: Courier New; font-size: x-small; color: #000000;}
  5064. ul { margin-top: 10px; margin-left: 20px; }
  5065. li { list-style-type: none; margin-top: 10px; color: #000000; }
  5066. .content{
  5067. margin-left: 0px; padding-bottom: 2em; }
  5068. .nav {
  5069. padding-top: 10px; padding-bottom: 10px; padding-left: 15px; font-size: .70em;
  5070. margin-top: 10px; margin-left: 0px; color: #000000;
  5071. background-color: #ccccff; width: 20%; margin-left: 20px; margin-top: 20px; }
  5072. .title {
  5073. font-family: arial; font-size: 26px; color: #ffffff;
  5074. background-color: #999999; width: 100%;
  5075. margin-left: 0px; margin-right: 0px;
  5076. padding-top: 10px; padding-bottom: 10px;}
  5077. .hidden {
  5078. position: absolute; visibility: hidden; z-index: 200; left: 250px; top: 100px;
  5079. font-family: arial; overflow: hidden; width: 600;
  5080. padding: 20px; font-size: 10px; background-color: #999999;
  5081. layer-background-color:#FFFFFF; }
  5082. a,a:active { color: charcoal; font-weight: bold; }
  5083. a:visited { color: #666666; font-weight: bold; }
  5084. a:hover { color: cc3300; font-weight: bold; }
  5085. </style>
  5086. <script language="JavaScript" type="text/javascript">
  5087. <!--
  5088. // POP-UP CAPTIONS...
  5089. function lib_bwcheck(){ //Browsercheck (needed)
  5090. this.ver=navigator.appVersion
  5091. this.agent=navigator.userAgent
  5092. this.dom=document.getElementById?1:0
  5093. this.opera5=this.agent.indexOf("Opera 5")>-1
  5094. this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  5095. this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  5096. this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  5097. this.ie=this.ie4||this.ie5||this.ie6
  5098. this.mac=this.agent.indexOf("Mac")>-1
  5099. this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  5100. this.ns4=(document.layers && !this.dom)?1:0;
  5101. this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
  5102. return this
  5103. }
  5104. var bw = new lib_bwcheck()
  5105. //Makes crossbrowser object.
  5106. function makeObj(obj){
  5107. this.evnt=bw.dom? document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?document.layers[obj]:0;
  5108. if(!this.evnt) return false
  5109. this.css=bw.dom||bw.ie4?this.evnt.style:bw.ns4?this.evnt:0;
  5110. this.wref=bw.dom||bw.ie4?this.evnt:bw.ns4?this.css.document:0;
  5111. this.writeIt=b_writeIt;
  5112. return this
  5113. }
  5114. // A unit of measure that will be added when setting the position of a layer.
  5115. //var px = bw.ns4||window.opera?"":"px";
  5116. function b_writeIt(text){
  5117. if (bw.ns4){this.wref.write(text);this.wref.close()}
  5118. else this.wref.innerHTML = text
  5119. }
  5120. //Shows the messages
  5121. var oDesc;
  5122. function popup(divid){
  5123. if(oDesc = new makeObj(divid)){
  5124. oDesc.css.visibility = "visible"
  5125. }
  5126. }
  5127. function popout(){ // Hides message
  5128. if(oDesc) oDesc.css.visibility = "hidden"
  5129. }
  5130. //-->
  5131. </script>
  5132. </head>
  5133. <body>
  5134. <div class=content>
  5135. <br><br>
  5136. <div class=title>'.$this->serviceName.'</div>
  5137. <div class=nav>
  5138. <p>View the <a href="'.$PHP_SELF.'?wsdl">WSDL</a> for the service.
  5139. Click on an operation name to view it&apos;s details.</p>
  5140. <ul>';
  5141. foreach($this->getOperations() as $op => $data){
  5142. $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>";
  5143. // create hidden div
  5144. $b .= "<div id='$op' class='hidden'>
  5145. <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>";
  5146. foreach($data as $donnie => $marie){ // loop through opdata
  5147. if($donnie == 'input' || $donnie == 'output'){ // show input/output data
  5148. $b .= "<font color='white'>".ucfirst($donnie).':</font><br>';
  5149. foreach($marie as $captain => $tenille){ // loop through data
  5150. if($captain == 'parts'){ // loop thru parts
  5151. $b .= "&nbsp;&nbsp;$captain:<br>";
  5152. //if(is_array($tenille)){
  5153. foreach($tenille as $joanie => $chachi){
  5154. $b .= "&nbsp;&nbsp;&nbsp;&nbsp;$joanie: $chachi<br>";
  5155. }
  5156. //}
  5157. } else {
  5158. $b .= "&nbsp;&nbsp;$captain: $tenille<br>";
  5159. }
  5160. }
  5161. } else {
  5162. $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>";
  5163. }
  5164. }
  5165. $b .= '</div>';
  5166. }
  5167. $b .= '
  5168. <ul>
  5169. </div>
  5170. </div></body></html>';
  5171. return $b;
  5172. }
  5173. /**
  5174. * serialize the parsed wsdl
  5175. *
  5176. * @param mixed $debug whether to put debug=1 in endpoint URL
  5177. * @return string serialization of WSDL
  5178. * @access public
  5179. */
  5180. function serialize($debug = 0)
  5181. {
  5182. $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>';
  5183. $xml .= "\n<definitions";
  5184. foreach($this->namespaces as $k => $v) {
  5185. $xml .= " xmlns:$k=\"$v\"";
  5186. }
  5187. // 10.9.02 - add poulter fix for wsdl and tns declarations
  5188. if (isset($this->namespaces['wsdl'])) {
  5189. $xml .= " xmlns=\"" . $this->namespaces['wsdl'] . "\"";
  5190. }
  5191. if (isset($this->namespaces['tns'])) {
  5192. $xml .= " targetNamespace=\"" . $this->namespaces['tns'] . "\"";
  5193. }
  5194. $xml .= '>';
  5195. // imports
  5196. if (sizeof($this->import) > 0) {
  5197. foreach($this->import as $ns => $list) {
  5198. foreach ($list as $ii) {
  5199. if ($ii['location'] != '') {
  5200. $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />';
  5201. } else {
  5202. $xml .= '<import namespace="' . $ns . '" />';
  5203. }
  5204. }
  5205. }
  5206. }
  5207. // types
  5208. if (count($this->schemas)>=1) {
  5209. $xml .= "\n<types>\n";
  5210. foreach ($this->schemas as $ns => $list) {
  5211. foreach ($list as $xs) {
  5212. $xml .= $xs->serializeSchema();
  5213. }
  5214. }
  5215. $xml .= '</types>';
  5216. }
  5217. // messages
  5218. if (count($this->messages) >= 1) {
  5219. foreach($this->messages as $msgName => $msgParts) {
  5220. $xml .= "\n<message name=\"" . $msgName . '">';
  5221. if(is_array($msgParts)){
  5222. foreach($msgParts as $partName => $partType) {
  5223. // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>';
  5224. if (strpos($partType, ':')) {
  5225. $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType));
  5226. } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) {
  5227. // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>';
  5228. $typePrefix = 'xsd';
  5229. } else {
  5230. foreach($this->typemap as $ns => $types) {
  5231. if (isset($types[$partType])) {
  5232. $typePrefix = $this->getPrefixFromNamespace($ns);
  5233. }
  5234. }
  5235. if (!isset($typePrefix)) {
  5236. die("$partType has no namespace!");
  5237. }
  5238. }
  5239. $ns = $this->getNamespaceFromPrefix($typePrefix);
  5240. $localPart = $this->getLocalPart($partType);
  5241. $typeDef = $this->getTypeDef($localPart, $ns);
  5242. if ($typeDef['typeClass'] == 'element') {
  5243. $elementortype = 'element';
  5244. if (substr($localPart, -1) == '^') {
  5245. $localPart = substr($localPart, 0, -1);
  5246. }
  5247. } else {
  5248. $elementortype = 'type';
  5249. }
  5250. $xml .= "\n" . ' <part name="' . $partName . '" ' . $elementortype . '="' . $typePrefix . ':' . $localPart . '" />';
  5251. }
  5252. }
  5253. $xml .= '</message>';
  5254. }
  5255. }
  5256. // bindings & porttypes
  5257. if (count($this->bindings) >= 1) {
  5258. $binding_xml = '';
  5259. $portType_xml = '';
  5260. foreach($this->bindings as $bindingName => $attrs) {
  5261. $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">';
  5262. $binding_xml .= "\n" . ' <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>';
  5263. $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">';
  5264. foreach($attrs['operations'] as $opName => $opParts) {
  5265. $binding_xml .= "\n" . ' <operation name="' . $opName . '">';
  5266. $binding_xml .= "\n" . ' <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>';
  5267. if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') {
  5268. $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"';
  5269. } else {
  5270. $enc_style = '';
  5271. }
  5272. $binding_xml .= "\n" . ' <input><soap:body use="' . $opParts['input']['use'] . '" namespace="' . $opParts['input']['namespace'] . '"' . $enc_style . '/></input>';
  5273. if (isset($opParts['output']['encodingStyle']) && $opParts['output']['encodingStyle'] != '') {
  5274. $enc_style = ' encodingStyle="' . $opParts['output']['encodingStyle'] . '"';
  5275. } else {
  5276. $enc_style = '';
  5277. }
  5278. $binding_xml .= "\n" . ' <output><soap:body use="' . $opParts['output']['use'] . '" namespace="' . $opParts['output']['namespace'] . '"' . $enc_style . '/></output>';
  5279. $binding_xml .= "\n" . ' </operation>';
  5280. $portType_xml .= "\n" . ' <operation name="' . $opParts['name'] . '"';
  5281. if (isset($opParts['parameterOrder'])) {
  5282. $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"';
  5283. }
  5284. $portType_xml .= '>';
  5285. if(isset($opParts['documentation']) && $opParts['documentation'] != '') {
  5286. $portType_xml .= "\n" . ' <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>';
  5287. }
  5288. $portType_xml .= "\n" . ' <input message="tns:' . $opParts['input']['message'] . '"/>';
  5289. $portType_xml .= "\n" . ' <output message="tns:' . $opParts['output']['message'] . '"/>';
  5290. $portType_xml .= "\n" . ' </operation>';
  5291. }
  5292. $portType_xml .= "\n" . '</portType>';
  5293. $binding_xml .= "\n" . '</binding>';
  5294. }
  5295. $xml .= $portType_xml . $binding_xml;
  5296. }
  5297. // services
  5298. $xml .= "\n<service name=\"" . $this->serviceName . '">';
  5299. if (count($this->ports) >= 1) {
  5300. foreach($this->ports as $pName => $attrs) {
  5301. $xml .= "\n" . ' <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">';
  5302. $xml .= "\n" . ' <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>';
  5303. $xml .= "\n" . ' </port>';
  5304. }
  5305. }
  5306. $xml .= "\n" . '</service>';
  5307. return $xml . "\n</definitions>";
  5308. }
  5309. /**
  5310. * determine whether a set of parameters are unwrapped
  5311. * when they are expect to be wrapped, Microsoft-style.
  5312. *
  5313. * @param string $type the type (element name) of the wrapper
  5314. * @param array $parameters the parameter values for the SOAP call
  5315. * @return boolean whether they parameters are unwrapped (and should be wrapped)
  5316. * @access private
  5317. */
  5318. function parametersMatchWrapped($type, &$parameters) {
  5319. $this->debug("in parametersMatchWrapped type=$type, parameters=");
  5320. $this->appendDebug($this->varDump($parameters));
  5321. // split type into namespace:unqualified-type
  5322. if (strpos($type, ':')) {
  5323. $uqType = substr($type, strrpos($type, ':') + 1);
  5324. $ns = substr($type, 0, strrpos($type, ':'));
  5325. $this->debug("in parametersMatchWrapped: got a prefixed type: $uqType, $ns");
  5326. if ($this->getNamespaceFromPrefix($ns)) {
  5327. $ns = $this->getNamespaceFromPrefix($ns);
  5328. $this->debug("in parametersMatchWrapped: expanded prefixed type: $uqType, $ns");
  5329. }
  5330. } else {
  5331. // TODO: should the type be compared to types in XSD, and the namespace
  5332. // set to XSD if the type matches?
  5333. $this->debug("in parametersMatchWrapped: No namespace for type $type");
  5334. $ns = '';
  5335. $uqType = $type;
  5336. }
  5337. // get the type information
  5338. if (!$typeDef = $this->getTypeDef($uqType, $ns)) {
  5339. $this->debug("in parametersMatchWrapped: $type ($uqType) is not a supported type.");
  5340. return false;
  5341. }
  5342. $this->debug("in parametersMatchWrapped: found typeDef=");
  5343. $this->appendDebug($this->varDump($typeDef));
  5344. if (substr($uqType, -1) == '^') {
  5345. $uqType = substr($uqType, 0, -1);
  5346. }
  5347. $phpType = $typeDef['phpType'];
  5348. $arrayType = (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '');
  5349. $this->debug("in parametersMatchWrapped: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: $arrayType");
  5350. // we expect a complexType or element of complexType
  5351. if ($phpType != 'struct') {
  5352. $this->debug("in parametersMatchWrapped: not a struct");
  5353. return false;
  5354. }
  5355. // see whether the parameter names match the elements
  5356. if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
  5357. $elements = 0;
  5358. $matches = 0;
  5359. foreach ($typeDef['elements'] as $name => $attrs) {
  5360. if (isset($parameters[$name])) {
  5361. $this->debug("in parametersMatchWrapped: have parameter named $name");
  5362. $matches++;
  5363. } else {
  5364. $this->debug("in parametersMatchWrapped: do not have parameter named $name");
  5365. }
  5366. $elements++;
  5367. }
  5368. $this->debug("in parametersMatchWrapped: $matches parameter names match $elements wrapped parameter names");
  5369. if ($matches == 0) {
  5370. return false;
  5371. }
  5372. return true;
  5373. }
  5374. // since there are no elements for the type, if the user passed no
  5375. // parameters, the parameters match wrapped.
  5376. $this->debug("in parametersMatchWrapped: no elements type $ns:$uqType");
  5377. return count($parameters) == 0;
  5378. }
  5379. /**
  5380. * serialize PHP values according to a WSDL message definition
  5381. * contrary to the method name, this is not limited to RPC
  5382. *
  5383. * TODO
  5384. * - multi-ref serialization
  5385. * - validate PHP values against type definitions, return errors if invalid
  5386. *
  5387. * @param string $operation operation name
  5388. * @param string $direction (input|output)
  5389. * @param mixed $parameters parameter value(s)
  5390. * @param string $bindingType (soap|soap12)
  5391. * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
  5392. * @access public
  5393. */
  5394. function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') {
  5395. $this->debug("in serializeRPCParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion, bindingType=$bindingType");
  5396. $this->appendDebug('parameters=' . $this->varDump($parameters));
  5397. if ($direction != 'input' && $direction != 'output') {
  5398. $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
  5399. $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
  5400. return false;
  5401. }
  5402. if (!$opData = $this->getOperationData($operation, $bindingType)) {
  5403. $this->debug('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
  5404. $this->setError('Unable to retrieve WSDL data for operation: ' . $operation . ' bindingType: ' . $bindingType);
  5405. return false;
  5406. }
  5407. $this->debug('in serializeRPCParameters: opData:');
  5408. $this->appendDebug($this->varDump($opData));
  5409. // Get encoding style for output and set to current
  5410. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  5411. if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
  5412. $encodingStyle = $opData['output']['encodingStyle'];
  5413. $enc_style = $encodingStyle;
  5414. }
  5415. // set input params
  5416. $xml = '';
  5417. if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
  5418. $parts = &$opData[$direction]['parts'];
  5419. $part_count = sizeof($parts);
  5420. $style = $opData['style'];
  5421. $use = $opData[$direction]['use'];
  5422. $this->debug("have $part_count part(s) to serialize using $style/$use");
  5423. if (is_array($parameters)) {
  5424. $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
  5425. $parameter_count = count($parameters);
  5426. $this->debug("have $parameter_count parameter(s) provided as $parametersArrayType to serialize");
  5427. // check for Microsoft-style wrapped parameters
  5428. if ($style == 'document' && $use == 'literal' && $part_count == 1 && isset($parts['parameters'])) {
  5429. $this->debug('check whether the caller has wrapped the parameters');
  5430. if ($direction == 'output' && $parametersArrayType == 'arraySimple' && $parameter_count == 1) {
  5431. // TODO: consider checking here for double-wrapping, when
  5432. // service function wraps, then NuSOAP wraps again
  5433. $this->debug("change simple array to associative with 'parameters' element");
  5434. $parameters['parameters'] = $parameters[0];
  5435. unset($parameters[0]);
  5436. }
  5437. if (($parametersArrayType == 'arrayStruct' || $parameter_count == 0) && !isset($parameters['parameters'])) {
  5438. $this->debug('check whether caller\'s parameters match the wrapped ones');
  5439. if ($this->parametersMatchWrapped($parts['parameters'], $parameters)) {
  5440. $this->debug('wrap the parameters for the caller');
  5441. $parameters = array('parameters' => $parameters);
  5442. $parameter_count = 1;
  5443. }
  5444. }
  5445. }
  5446. foreach ($parts as $name => $type) {
  5447. $this->debug("serializing part $name of type $type");
  5448. // Track encoding style
  5449. if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
  5450. $encodingStyle = $opData[$direction]['encodingStyle'];
  5451. $enc_style = $encodingStyle;
  5452. } else {
  5453. $enc_style = false;
  5454. }
  5455. // NOTE: add error handling here
  5456. // if serializeType returns false, then catch global error and fault
  5457. if ($parametersArrayType == 'arraySimple') {
  5458. $p = array_shift($parameters);
  5459. $this->debug('calling serializeType w/indexed param');
  5460. $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
  5461. } elseif (isset($parameters[$name])) {
  5462. $this->debug('calling serializeType w/named param');
  5463. $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
  5464. } else {
  5465. // TODO: only send nillable
  5466. $this->debug('calling serializeType w/null param');
  5467. $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
  5468. }
  5469. }
  5470. } else {
  5471. $this->debug('no parameters passed.');
  5472. }
  5473. }
  5474. $this->debug("serializeRPCParameters returning: $xml");
  5475. return $xml;
  5476. }
  5477. /**
  5478. * serialize a PHP value according to a WSDL message definition
  5479. *
  5480. * TODO
  5481. * - multi-ref serialization
  5482. * - validate PHP values against type definitions, return errors if invalid
  5483. *
  5484. * @param string $operation operation name
  5485. * @param string $direction (input|output)
  5486. * @param mixed $parameters parameter value(s)
  5487. * @return mixed parameters serialized as XML or false on error (e.g. operation not found)
  5488. * @access public
  5489. * @deprecated
  5490. */
  5491. function serializeParameters($operation, $direction, $parameters)
  5492. {
  5493. $this->debug("in serializeParameters: operation=$operation, direction=$direction, XMLSchemaVersion=$this->XMLSchemaVersion");
  5494. $this->appendDebug('parameters=' . $this->varDump($parameters));
  5495. if ($direction != 'input' && $direction != 'output') {
  5496. $this->debug('The value of the \$direction argument needs to be either "input" or "output"');
  5497. $this->setError('The value of the \$direction argument needs to be either "input" or "output"');
  5498. return false;
  5499. }
  5500. if (!$opData = $this->getOperationData($operation)) {
  5501. $this->debug('Unable to retrieve WSDL data for operation: ' . $operation);
  5502. $this->setError('Unable to retrieve WSDL data for operation: ' . $operation);
  5503. return false;
  5504. }
  5505. $this->debug('opData:');
  5506. $this->appendDebug($this->varDump($opData));
  5507. // Get encoding style for output and set to current
  5508. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  5509. if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) {
  5510. $encodingStyle = $opData['output']['encodingStyle'];
  5511. $enc_style = $encodingStyle;
  5512. }
  5513. // set input params
  5514. $xml = '';
  5515. if (isset($opData[$direction]['parts']) && sizeof($opData[$direction]['parts']) > 0) {
  5516. $use = $opData[$direction]['use'];
  5517. $this->debug("use=$use");
  5518. $this->debug('got ' . count($opData[$direction]['parts']) . ' part(s)');
  5519. if (is_array($parameters)) {
  5520. $parametersArrayType = $this->isArraySimpleOrStruct($parameters);
  5521. $this->debug('have ' . $parametersArrayType . ' parameters');
  5522. foreach($opData[$direction]['parts'] as $name => $type) {
  5523. $this->debug('serializing part "'.$name.'" of type "'.$type.'"');
  5524. // Track encoding style
  5525. if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) {
  5526. $encodingStyle = $opData[$direction]['encodingStyle'];
  5527. $enc_style = $encodingStyle;
  5528. } else {
  5529. $enc_style = false;
  5530. }
  5531. // NOTE: add error handling here
  5532. // if serializeType returns false, then catch global error and fault
  5533. if ($parametersArrayType == 'arraySimple') {
  5534. $p = array_shift($parameters);
  5535. $this->debug('calling serializeType w/indexed param');
  5536. $xml .= $this->serializeType($name, $type, $p, $use, $enc_style);
  5537. } elseif (isset($parameters[$name])) {
  5538. $this->debug('calling serializeType w/named param');
  5539. $xml .= $this->serializeType($name, $type, $parameters[$name], $use, $enc_style);
  5540. } else {
  5541. // TODO: only send nillable
  5542. $this->debug('calling serializeType w/null param');
  5543. $xml .= $this->serializeType($name, $type, null, $use, $enc_style);
  5544. }
  5545. }
  5546. } else {
  5547. $this->debug('no parameters passed.');
  5548. }
  5549. }
  5550. $this->debug("serializeParameters returning: $xml");
  5551. return $xml;
  5552. }
  5553. /**
  5554. * serializes a PHP value according a given type definition
  5555. *
  5556. * @param string $name name of value (part or element)
  5557. * @param string $type XML schema type of value (type or element)
  5558. * @param mixed $value a native PHP value (parameter value)
  5559. * @param string $use use for part (encoded|literal)
  5560. * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
  5561. * @param boolean $unqualified a kludge for what should be XML namespace form handling
  5562. * @return string value serialized as an XML string
  5563. * @access private
  5564. */
  5565. function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false)
  5566. {
  5567. $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified"));
  5568. $this->appendDebug("value=" . $this->varDump($value));
  5569. if($use == 'encoded' && $encodingStyle) {
  5570. $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"';
  5571. }
  5572. // if a soapval has been supplied, let its type override the WSDL
  5573. if (is_object($value) && get_class($value) == 'soapval') {
  5574. if ($value->type_ns) {
  5575. $type = $value->type_ns . ':' . $value->type;
  5576. $forceType = true;
  5577. $this->debug("in serializeType: soapval overrides type to $type");
  5578. } elseif ($value->type) {
  5579. $type = $value->type;
  5580. $forceType = true;
  5581. $this->debug("in serializeType: soapval overrides type to $type");
  5582. } else {
  5583. $forceType = false;
  5584. $this->debug("in serializeType: soapval does not override type");
  5585. }
  5586. $attrs = $value->attributes;
  5587. $value = $value->value;
  5588. $this->debug("in serializeType: soapval overrides value to $value");
  5589. if ($attrs) {
  5590. if (!is_array($value)) {
  5591. $value['!'] = $value;
  5592. }
  5593. foreach ($attrs as $n => $v) {
  5594. $value['!' . $n] = $v;
  5595. }
  5596. $this->debug("in serializeType: soapval provides attributes");
  5597. }
  5598. } else {
  5599. $forceType = false;
  5600. }
  5601. $xml = '';
  5602. if (strpos($type, ':')) {
  5603. $uqType = substr($type, strrpos($type, ':') + 1);
  5604. $ns = substr($type, 0, strrpos($type, ':'));
  5605. $this->debug("in serializeType: got a prefixed type: $uqType, $ns");
  5606. if ($this->getNamespaceFromPrefix($ns)) {
  5607. $ns = $this->getNamespaceFromPrefix($ns);
  5608. $this->debug("in serializeType: expanded prefixed type: $uqType, $ns");
  5609. }
  5610. if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){
  5611. $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type');
  5612. if ($unqualified && $use == 'literal') {
  5613. $elementNS = " xmlns=\"\"";
  5614. } else {
  5615. $elementNS = '';
  5616. }
  5617. if (is_null($value)) {
  5618. if ($use == 'literal') {
  5619. // TODO: depends on minOccurs
  5620. $xml = "<$name$elementNS/>";
  5621. } else {
  5622. // TODO: depends on nillable, which should be checked before calling this method
  5623. $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
  5624. }
  5625. $this->debug("in serializeType: returning: $xml");
  5626. return $xml;
  5627. }
  5628. if ($uqType == 'Array') {
  5629. // JBoss/Axis does this sometimes
  5630. return $this->serialize_val($value, $name, false, false, false, false, $use);
  5631. }
  5632. if ($uqType == 'boolean') {
  5633. if ((is_string($value) && $value == 'false') || (! $value)) {
  5634. $value = 'false';
  5635. } else {
  5636. $value = 'true';
  5637. }
  5638. }
  5639. if ($uqType == 'string' && gettype($value) == 'string') {
  5640. $value = $this->expandEntities($value);
  5641. }
  5642. if (($uqType == 'long' || $uqType == 'unsignedLong') && gettype($value) == 'double') {
  5643. $value = sprintf("%.0lf", $value);
  5644. }
  5645. // it's a scalar
  5646. // TODO: what about null/nil values?
  5647. // check type isn't a custom type extending xmlschema namespace
  5648. if (!$this->getTypeDef($uqType, $ns)) {
  5649. if ($use == 'literal') {
  5650. if ($forceType) {
  5651. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
  5652. } else {
  5653. $xml = "<$name$elementNS>$value</$name>";
  5654. }
  5655. } else {
  5656. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
  5657. }
  5658. $this->debug("in serializeType: returning: $xml");
  5659. return $xml;
  5660. }
  5661. $this->debug('custom type extends XML Schema or SOAP Encoding namespace (yuck)');
  5662. } else if ($ns == 'http://xml.apache.org/xml-soap') {
  5663. $this->debug('in serializeType: appears to be Apache SOAP type');
  5664. if ($uqType == 'Map') {
  5665. $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
  5666. if (! $tt_prefix) {
  5667. $this->debug('in serializeType: Add namespace for Apache SOAP type');
  5668. $tt_prefix = 'ns' . rand(1000, 9999);
  5669. $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap';
  5670. // force this to be added to usedNamespaces
  5671. $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap');
  5672. }
  5673. $contents = '';
  5674. foreach($value as $k => $v) {
  5675. $this->debug("serializing map element: key $k, value $v");
  5676. $contents .= '<item>';
  5677. $contents .= $this->serialize_val($k,'key',false,false,false,false,$use);
  5678. $contents .= $this->serialize_val($v,'value',false,false,false,false,$use);
  5679. $contents .= '</item>';
  5680. }
  5681. if ($use == 'literal') {
  5682. if ($forceType) {
  5683. $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\">$contents</$name>";
  5684. } else {
  5685. $xml = "<$name>$contents</$name>";
  5686. }
  5687. } else {
  5688. $xml = "<$name xsi:type=\"" . $tt_prefix . ":$uqType\"$encodingStyle>$contents</$name>";
  5689. }
  5690. $this->debug("in serializeType: returning: $xml");
  5691. return $xml;
  5692. }
  5693. $this->debug('in serializeType: Apache SOAP type, but only support Map');
  5694. }
  5695. } else {
  5696. // TODO: should the type be compared to types in XSD, and the namespace
  5697. // set to XSD if the type matches?
  5698. $this->debug("in serializeType: No namespace for type $type");
  5699. $ns = '';
  5700. $uqType = $type;
  5701. }
  5702. if(!$typeDef = $this->getTypeDef($uqType, $ns)){
  5703. $this->setError("$type ($uqType) is not a supported type.");
  5704. $this->debug("in serializeType: $type ($uqType) is not a supported type.");
  5705. return false;
  5706. } else {
  5707. $this->debug("in serializeType: found typeDef");
  5708. $this->appendDebug('typeDef=' . $this->varDump($typeDef));
  5709. if (substr($uqType, -1) == '^') {
  5710. $uqType = substr($uqType, 0, -1);
  5711. }
  5712. }
  5713. if (!isset($typeDef['phpType'])) {
  5714. $this->setError("$type ($uqType) has no phpType.");
  5715. $this->debug("in serializeType: $type ($uqType) has no phpType.");
  5716. return false;
  5717. }
  5718. $phpType = $typeDef['phpType'];
  5719. $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') );
  5720. // if php type == struct, map value to the <all> element names
  5721. if ($phpType == 'struct') {
  5722. if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') {
  5723. $elementName = $uqType;
  5724. if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
  5725. $elementNS = " xmlns=\"$ns\"";
  5726. } else {
  5727. $elementNS = " xmlns=\"\"";
  5728. }
  5729. } else {
  5730. $elementName = $name;
  5731. if ($unqualified) {
  5732. $elementNS = " xmlns=\"\"";
  5733. } else {
  5734. $elementNS = '';
  5735. }
  5736. }
  5737. if (is_null($value)) {
  5738. if ($use == 'literal') {
  5739. // TODO: depends on minOccurs and nillable
  5740. $xml = "<$elementName$elementNS/>";
  5741. } else {
  5742. $xml = "<$elementName$elementNS xsi:nil=\"true\" xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"/>";
  5743. }
  5744. $this->debug("in serializeType: returning: $xml");
  5745. return $xml;
  5746. }
  5747. if (is_object($value)) {
  5748. $value = get_object_vars($value);
  5749. }
  5750. if (is_array($value)) {
  5751. $elementAttrs = $this->serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType);
  5752. if ($use == 'literal') {
  5753. if ($forceType) {
  5754. $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">";
  5755. } else {
  5756. $xml = "<$elementName$elementNS$elementAttrs>";
  5757. }
  5758. } else {
  5759. $xml = "<$elementName$elementNS$elementAttrs xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>";
  5760. }
  5761. if (isset($typeDef['simpleContent']) && $typeDef['simpleContent'] == 'true') {
  5762. if (isset($value['!'])) {
  5763. $xml .= $value['!'];
  5764. $this->debug("in serializeType: serialized simpleContent for type $type");
  5765. } else {
  5766. $this->debug("in serializeType: no simpleContent to serialize for type $type");
  5767. }
  5768. } else {
  5769. // complexContent
  5770. $xml .= $this->serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use, $encodingStyle);
  5771. }
  5772. $xml .= "</$elementName>";
  5773. } else {
  5774. $this->debug("in serializeType: phpType is struct, but value is not an array");
  5775. $this->setError("phpType is struct, but value is not an array: see debug output for details");
  5776. $xml = '';
  5777. }
  5778. } elseif ($phpType == 'array') {
  5779. if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
  5780. $elementNS = " xmlns=\"$ns\"";
  5781. } else {
  5782. if ($unqualified) {
  5783. $elementNS = " xmlns=\"\"";
  5784. } else {
  5785. $elementNS = '';
  5786. }
  5787. }
  5788. if (is_null($value)) {
  5789. if ($use == 'literal') {
  5790. // TODO: depends on minOccurs
  5791. $xml = "<$name$elementNS/>";
  5792. } else {
  5793. $xml = "<$name$elementNS xsi:nil=\"true\" xsi:type=\"" .
  5794. $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
  5795. ":Array\" " .
  5796. $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') .
  5797. ':arrayType="' .
  5798. $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) .
  5799. ':' .
  5800. $this->getLocalPart($typeDef['arrayType'])."[0]\"/>";
  5801. }
  5802. $this->debug("in serializeType: returning: $xml");
  5803. return $xml;
  5804. }
  5805. if (isset($typeDef['multidimensional'])) {
  5806. $nv = array();
  5807. foreach($value as $v) {
  5808. $cols = ',' . sizeof($v);
  5809. $nv = array_merge($nv, $v);
  5810. }
  5811. $value = $nv;
  5812. } else {
  5813. $cols = '';
  5814. }
  5815. if (is_array($value) && sizeof($value) >= 1) {
  5816. $rows = sizeof($value);
  5817. $contents = '';
  5818. foreach($value as $k => $v) {
  5819. $this->debug("serializing array element: $k of type: ".$typeDef['arrayType']);
  5820. //if (strpos($typeDef['arrayType'], ':') ) {
  5821. if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) {
  5822. $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);
  5823. } else {
  5824. // @CHANGE This is to have tag name with name reported by wsdl and not "item"
  5825. //$contents .= $this->serialize_val($v, 'itemzzzz', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
  5826. $tmp=array_keys($typeDef['elements']); //var_dump($tmp[0]);
  5827. $contents .= $this->serialize_val($v, ($tmp[0]?$tmp[0]:'item'), $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use);
  5828. }
  5829. }
  5830. } else {
  5831. $rows = 0;
  5832. $contents = null;
  5833. }
  5834. // TODO: for now, an empty value will be serialized as a zero element
  5835. // array. Revisit this when coding the handling of null/nil values.
  5836. if ($use == 'literal') {
  5837. $xml = "<$name$elementNS>"
  5838. .$contents
  5839. ."</$name>";
  5840. } else {
  5841. $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '.
  5842. $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/')
  5843. .':arrayType="'
  5844. .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType']))
  5845. .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">"
  5846. .$contents
  5847. ."</$name>";
  5848. }
  5849. } elseif ($phpType == 'scalar') {
  5850. if (isset($typeDef['form']) && ($typeDef['form'] == 'qualified')) {
  5851. $elementNS = " xmlns=\"$ns\"";
  5852. } else {
  5853. if ($unqualified) {
  5854. $elementNS = " xmlns=\"\"";
  5855. } else {
  5856. $elementNS = '';
  5857. }
  5858. }
  5859. if ($use == 'literal') {
  5860. if ($forceType) {
  5861. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\">$value</$name>";
  5862. } else {
  5863. $xml = "<$name$elementNS>$value</$name>";
  5864. }
  5865. } else {
  5866. $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace($ns) . ":$uqType\"$encodingStyle>$value</$name>";
  5867. }
  5868. }
  5869. $this->debug("in serializeType: returning: $xml");
  5870. return $xml;
  5871. }
  5872. /**
  5873. * serializes the attributes for a complexType
  5874. *
  5875. * @param array $typeDef our internal representation of an XML schema type (or element)
  5876. * @param mixed $value a native PHP value (parameter value)
  5877. * @param string $ns the namespace of the type
  5878. * @param string $uqType the local part of the type
  5879. * @return string value serialized as an XML string
  5880. * @access private
  5881. */
  5882. function serializeComplexTypeAttributes($typeDef, $value, $ns, $uqType) {
  5883. $this->debug("serializeComplexTypeAttributes for XML Schema type $ns:$uqType");
  5884. $xml = '';
  5885. if (isset($typeDef['extensionBase'])) {
  5886. $nsx = $this->getPrefix($typeDef['extensionBase']);
  5887. $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
  5888. if ($this->getNamespaceFromPrefix($nsx)) {
  5889. $nsx = $this->getNamespaceFromPrefix($nsx);
  5890. }
  5891. if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
  5892. $this->debug("serialize attributes for extension base $nsx:$uqTypex");
  5893. $xml .= $this->serializeComplexTypeAttributes($typeDefx, $value, $nsx, $uqTypex);
  5894. } else {
  5895. $this->debug("extension base $nsx:$uqTypex is not a supported type");
  5896. }
  5897. }
  5898. if (isset($typeDef['attrs']) && is_array($typeDef['attrs'])) {
  5899. $this->debug("serialize attributes for XML Schema type $ns:$uqType");
  5900. if (is_array($value)) {
  5901. $xvalue = $value;
  5902. } elseif (is_object($value)) {
  5903. $xvalue = get_object_vars($value);
  5904. } else {
  5905. $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
  5906. $xvalue = array();
  5907. }
  5908. foreach ($typeDef['attrs'] as $aName => $attrs) {
  5909. if (isset($xvalue['!' . $aName])) {
  5910. $xname = '!' . $aName;
  5911. $this->debug("value provided for attribute $aName with key $xname");
  5912. } elseif (isset($xvalue[$aName])) {
  5913. $xname = $aName;
  5914. $this->debug("value provided for attribute $aName with key $xname");
  5915. } elseif (isset($attrs['default'])) {
  5916. $xname = '!' . $aName;
  5917. $xvalue[$xname] = $attrs['default'];
  5918. $this->debug('use default value of ' . $xvalue[$aName] . ' for attribute ' . $aName);
  5919. } else {
  5920. $xname = '';
  5921. $this->debug("no value provided for attribute $aName");
  5922. }
  5923. if ($xname) {
  5924. $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\"";
  5925. }
  5926. }
  5927. } else {
  5928. $this->debug("no attributes to serialize for XML Schema type $ns:$uqType");
  5929. }
  5930. return $xml;
  5931. }
  5932. /**
  5933. * serializes the elements for a complexType
  5934. *
  5935. * @param array $typeDef our internal representation of an XML schema type (or element)
  5936. * @param mixed $value a native PHP value (parameter value)
  5937. * @param string $ns the namespace of the type
  5938. * @param string $uqType the local part of the type
  5939. * @param string $use use for part (encoded|literal)
  5940. * @param string $encodingStyle SOAP encoding style for the value (if different than the enclosing style)
  5941. * @return string value serialized as an XML string
  5942. * @access private
  5943. */
  5944. function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) {
  5945. $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType");
  5946. $xml = '';
  5947. if (isset($typeDef['extensionBase'])) {
  5948. $nsx = $this->getPrefix($typeDef['extensionBase']);
  5949. $uqTypex = $this->getLocalPart($typeDef['extensionBase']);
  5950. if ($this->getNamespaceFromPrefix($nsx)) {
  5951. $nsx = $this->getNamespaceFromPrefix($nsx);
  5952. }
  5953. if ($typeDefx = $this->getTypeDef($uqTypex, $nsx)) {
  5954. $this->debug("serialize elements for extension base $nsx:$uqTypex");
  5955. $xml .= $this->serializeComplexTypeElements($typeDefx, $value, $nsx, $uqTypex, $use, $encodingStyle);
  5956. } else {
  5957. $this->debug("extension base $nsx:$uqTypex is not a supported type");
  5958. }
  5959. }
  5960. if (isset($typeDef['elements']) && is_array($typeDef['elements'])) {
  5961. $this->debug("in serializeComplexTypeElements, serialize elements for XML Schema type $ns:$uqType");
  5962. if (is_array($value)) {
  5963. $xvalue = $value;
  5964. } elseif (is_object($value)) {
  5965. $xvalue = get_object_vars($value);
  5966. } else {
  5967. $this->debug("value is neither an array nor an object for XML Schema type $ns:$uqType");
  5968. $xvalue = array();
  5969. }
  5970. // toggle whether all elements are present - ideally should validate against schema
  5971. if (count($typeDef['elements']) != count($xvalue)){
  5972. $optionals = true;
  5973. }
  5974. foreach ($typeDef['elements'] as $eName => $attrs) {
  5975. if (!isset($xvalue[$eName])) {
  5976. if (isset($attrs['default'])) {
  5977. $xvalue[$eName] = $attrs['default'];
  5978. $this->debug('use default value of ' . $xvalue[$eName] . ' for element ' . $eName);
  5979. }
  5980. }
  5981. // if user took advantage of a minOccurs=0, then only serialize named parameters
  5982. if (isset($optionals)
  5983. && (!isset($xvalue[$eName]))
  5984. && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true')
  5985. ){
  5986. if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') {
  5987. $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']);
  5988. }
  5989. // do nothing
  5990. $this->debug("no value provided for complexType element $eName and element is not nillable, so serialize nothing");
  5991. } else {
  5992. // get value
  5993. if (isset($xvalue[$eName])) {
  5994. $v = $xvalue[$eName];
  5995. } else {
  5996. $v = null;
  5997. }
  5998. if (isset($attrs['form'])) {
  5999. $unqualified = ($attrs['form'] == 'unqualified');
  6000. } else {
  6001. $unqualified = false;
  6002. }
  6003. if (isset($attrs['maxOccurs']) && ($attrs['maxOccurs'] == 'unbounded' || $attrs['maxOccurs'] > 1) && isset($v) && is_array($v) && $this->isArraySimpleOrStruct($v) == 'arraySimple') {
  6004. $vv = $v;
  6005. foreach ($vv as $k => $v) {
  6006. if (isset($attrs['type']) || isset($attrs['ref'])) {
  6007. // serialize schema-defined type
  6008. $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
  6009. } else {
  6010. // serialize generic type (can this ever really happen?)
  6011. $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
  6012. $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
  6013. }
  6014. }
  6015. } else {
  6016. if (is_null($v) && isset($attrs['minOccurs']) && $attrs['minOccurs'] == '0') {
  6017. // do nothing
  6018. } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') {
  6019. // TODO: serialize a nil correctly, but for now serialize schema-defined type
  6020. $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
  6021. } elseif (isset($attrs['type']) || isset($attrs['ref'])) {
  6022. // serialize schema-defined type
  6023. $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified);
  6024. } else {
  6025. // serialize generic type (can this ever really happen?)
  6026. $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use");
  6027. $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use);
  6028. }
  6029. }
  6030. }
  6031. }
  6032. } else {
  6033. $this->debug("no elements to serialize for XML Schema type $ns:$uqType");
  6034. }
  6035. return $xml;
  6036. }
  6037. /**
  6038. * adds an XML Schema complex type to the WSDL types
  6039. *
  6040. * @param string $name
  6041. * @param string $typeClass (complexType|simpleType|attribute)
  6042. * @param string $phpType currently supported are array and struct (php assoc array)
  6043. * @param string $compositor (all|sequence|choice)
  6044. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  6045. * @param array $elements e.g. array ( name => array(name=>'',type=>'') )
  6046. * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]'))
  6047. * @param string $arrayType as namespace:name (xsd:string)
  6048. * @see nusoap_xmlschema
  6049. * @access public
  6050. */
  6051. function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') {
  6052. if (count($elements) > 0) {
  6053. $eElements = array();
  6054. foreach($elements as $n => $e){
  6055. // expand each element
  6056. $ee = array();
  6057. foreach ($e as $k => $v) {
  6058. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  6059. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  6060. $ee[$k] = $v;
  6061. }
  6062. $eElements[$n] = $ee;
  6063. }
  6064. $elements = $eElements;
  6065. }
  6066. // @CHANGE LDR FIX for PHP7.2
  6067. //if (count($attrs) > 0) {
  6068. if (is_array($attrs) && count($attrs) > 0) {
  6069. foreach($attrs as $n => $a){
  6070. // expand each attribute
  6071. foreach ($a as $k => $v) {
  6072. $k = strpos($k,':') ? $this->expandQname($k) : $k;
  6073. $v = strpos($v,':') ? $this->expandQname($v) : $v;
  6074. $aa[$k] = $v;
  6075. }
  6076. $eAttrs[$n] = $aa;
  6077. }
  6078. $attrs = $eAttrs;
  6079. }
  6080. $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
  6081. $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType;
  6082. $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
  6083. $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType);
  6084. }
  6085. /**
  6086. * adds an XML Schema simple type to the WSDL types
  6087. *
  6088. * @param string $name
  6089. * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
  6090. * @param string $typeClass (should always be simpleType)
  6091. * @param string $phpType (should always be scalar)
  6092. * @param array $enumeration array of values
  6093. * @see nusoap_xmlschema
  6094. * @access public
  6095. */
  6096. function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) {
  6097. $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase;
  6098. $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
  6099. $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration);
  6100. }
  6101. /**
  6102. * adds an element to the WSDL types
  6103. *
  6104. * @param array $attrs attributes that must include name and type
  6105. * @see nusoap_xmlschema
  6106. * @access public
  6107. */
  6108. function addElement($attrs) {
  6109. $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns'];
  6110. $this->schemas[$typens][0]->addElement($attrs);
  6111. }
  6112. /**
  6113. * register an operation with the server
  6114. *
  6115. * @param string $name operation (method) name
  6116. * @param array $in assoc array of input values: key = param name, value = param type
  6117. * @param array $out assoc array of output values: key = param name, value = param type
  6118. * @param string $namespace optional The namespace for the operation
  6119. * @param string $soapaction optional The soapaction for the operation
  6120. * @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
  6121. * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now)
  6122. * @param string $documentation optional The description to include in the WSDL
  6123. * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
  6124. * @access public
  6125. */
  6126. function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){
  6127. if ($use == 'encoded' && $encodingStyle == '') {
  6128. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  6129. }
  6130. if ($style == 'document') {
  6131. $elements = array();
  6132. foreach ($in as $n => $t) {
  6133. $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
  6134. }
  6135. $this->addComplexType($name . 'RequestType', 'complexType', 'struct', 'all', '', $elements);
  6136. $this->addElement(array('name' => $name, 'type' => $name . 'RequestType'));
  6137. $in = array('parameters' => 'tns:' . $name . '^');
  6138. $elements = array();
  6139. foreach ($out as $n => $t) {
  6140. $elements[$n] = array('name' => $n, 'type' => $t, 'form' => 'unqualified');
  6141. }
  6142. $this->addComplexType($name . 'ResponseType', 'complexType', 'struct', 'all', '', $elements);
  6143. $this->addElement(array('name' => $name . 'Response', 'type' => $name . 'ResponseType', 'form' => 'qualified'));
  6144. $out = array('parameters' => 'tns:' . $name . 'Response' . '^');
  6145. }
  6146. // get binding
  6147. $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] =
  6148. array(
  6149. 'name' => $name,
  6150. 'binding' => $this->serviceName . 'Binding',
  6151. 'endpoint' => $this->endpoint,
  6152. 'soapAction' => $soapaction,
  6153. 'style' => $style,
  6154. 'input' => array(
  6155. 'use' => $use,
  6156. 'namespace' => $namespace,
  6157. 'encodingStyle' => $encodingStyle,
  6158. 'message' => $name . 'Request',
  6159. 'parts' => $in),
  6160. 'output' => array(
  6161. 'use' => $use,
  6162. 'namespace' => $namespace,
  6163. 'encodingStyle' => $encodingStyle,
  6164. 'message' => $name . 'Response',
  6165. 'parts' => $out),
  6166. 'namespace' => $namespace,
  6167. 'transport' => 'http://schemas.xmlsoap.org/soap/http',
  6168. 'documentation' => $documentation);
  6169. // add portTypes
  6170. // add messages
  6171. if($in)
  6172. {
  6173. foreach($in as $pName => $pType)
  6174. {
  6175. if(strpos($pType,':')) {
  6176. $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
  6177. }
  6178. $this->messages[$name.'Request'][$pName] = $pType;
  6179. }
  6180. } else {
  6181. $this->messages[$name.'Request']= '0';
  6182. }
  6183. if($out)
  6184. {
  6185. foreach($out as $pName => $pType)
  6186. {
  6187. if(strpos($pType,':')) {
  6188. $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType);
  6189. }
  6190. $this->messages[$name.'Response'][$pName] = $pType;
  6191. }
  6192. } else {
  6193. $this->messages[$name.'Response']= '0';
  6194. }
  6195. return true;
  6196. }
  6197. }
  6198. ?><?php
  6199. /**
  6200. *
  6201. * nusoap_parser class parses SOAP XML messages into native PHP values
  6202. *
  6203. * @author Dietrich Ayala <dietrich@ganx4.com>
  6204. * @author Scott Nichol <snichol@users.sourceforge.net>
  6205. * @access public
  6206. */
  6207. class nusoap_parser extends nusoap_base {
  6208. var $xml = '';
  6209. var $xml_encoding = '';
  6210. var $method = '';
  6211. var $root_struct = '';
  6212. var $root_struct_name = '';
  6213. var $root_struct_namespace = '';
  6214. var $root_header = '';
  6215. var $document = ''; // incoming SOAP body (text)
  6216. // determines where in the message we are (envelope,header,body,method)
  6217. var $status = '';
  6218. var $position = 0;
  6219. var $depth = 0;
  6220. var $default_namespace = '';
  6221. var $namespaces = array();
  6222. var $message = array();
  6223. var $parent = '';
  6224. var $fault = false;
  6225. var $fault_code = '';
  6226. var $fault_str = '';
  6227. var $fault_detail = '';
  6228. var $depth_array = array();
  6229. var $debug_flag = true;
  6230. var $soapresponse = NULL; // parsed SOAP Body
  6231. var $soapheader = NULL; // parsed SOAP Header
  6232. var $responseHeaders = ''; // incoming SOAP headers (text)
  6233. var $body_position = 0;
  6234. // for multiref parsing:
  6235. // array of id => pos
  6236. var $ids = array();
  6237. // array of id => hrefs => pos
  6238. var $multirefs = array();
  6239. // toggle for auto-decoding element content
  6240. var $decode_utf8 = true;
  6241. /**
  6242. * constructor that actually does the parsing
  6243. *
  6244. * @param string $xml SOAP message
  6245. * @param string $encoding character encoding scheme of message
  6246. * @param string $method method for which XML is parsed (unused?)
  6247. * @param string $decode_utf8 whether to decode UTF-8 to ISO-8859-1
  6248. * @access public
  6249. */
  6250. function __construct($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
  6251. parent::__construct();
  6252. $this->xml = $xml;
  6253. $this->xml_encoding = $encoding;
  6254. $this->method = $method;
  6255. $this->decode_utf8 = $decode_utf8;
  6256. // Check whether content has been read.
  6257. if(!empty($xml)){
  6258. // Check XML encoding
  6259. $pos_xml = strpos($xml, '<?xml');
  6260. if ($pos_xml !== FALSE) {
  6261. $xml_decl = substr($xml, $pos_xml, strpos($xml, '?>', $pos_xml + 2) - $pos_xml + 1);
  6262. if (preg_match("/encoding=[\"']([^\"']*)[\"']/", $xml_decl, $res)) {
  6263. $xml_encoding = $res[1];
  6264. if (strtoupper($xml_encoding) != $encoding) {
  6265. $err = "Charset from HTTP Content-Type '" . $encoding . "' does not match encoding from XML declaration '" . $xml_encoding . "'";
  6266. $this->debug($err);
  6267. if ($encoding != 'ISO-8859-1' || strtoupper($xml_encoding) != 'UTF-8') {
  6268. $this->setError($err);
  6269. return;
  6270. }
  6271. // when HTTP says ISO-8859-1 (the default) and XML says UTF-8 (the typical), assume the other endpoint is just sloppy and proceed
  6272. } else {
  6273. $this->debug('Charset from HTTP Content-Type matches encoding from XML declaration');
  6274. }
  6275. } else {
  6276. $this->debug('No encoding specified in XML declaration');
  6277. }
  6278. } else {
  6279. $this->debug('No XML declaration');
  6280. }
  6281. $this->debug('Entering nusoap_parser(), length='.strlen($xml).', encoding='.$encoding);
  6282. // Create an XML parser - why not xml_parser_create_ns?
  6283. $this->parser = xml_parser_create($this->xml_encoding);
  6284. // Set the options for parsing the XML data.
  6285. //xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  6286. xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
  6287. xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->xml_encoding);
  6288. // Set the object for the parser.
  6289. xml_set_object($this->parser, $this);
  6290. // Set the element handlers for the parser.
  6291. xml_set_element_handler($this->parser, 'start_element','end_element');
  6292. xml_set_character_data_handler($this->parser,'character_data');
  6293. // Parse the XML file.
  6294. if(!xml_parse($this->parser,$xml,true)){
  6295. // Display an error message.
  6296. $err = sprintf('XML error parsing SOAP payload on line %d: %s',
  6297. xml_get_current_line_number($this->parser),
  6298. xml_error_string(xml_get_error_code($this->parser)));
  6299. $this->debug($err);
  6300. $this->debug("XML payload:\n" . $xml);
  6301. $this->setError($err);
  6302. } else {
  6303. $this->debug('in nusoap_parser ctor, message:');
  6304. $this->appendDebug($this->varDump($this->message));
  6305. $this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
  6306. // get final value
  6307. $this->soapresponse = $this->message[$this->root_struct]['result'];
  6308. // get header value
  6309. if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){
  6310. $this->soapheader = $this->message[$this->root_header]['result'];
  6311. }
  6312. // resolve hrefs/ids
  6313. if(sizeof($this->multirefs) > 0){
  6314. foreach($this->multirefs as $id => $hrefs){
  6315. $this->debug('resolving multirefs for id: '.$id);
  6316. $idVal = $this->buildVal($this->ids[$id]);
  6317. if (is_array($idVal) && isset($idVal['!id'])) {
  6318. unset($idVal['!id']);
  6319. }
  6320. foreach($hrefs as $refPos => $ref){
  6321. $this->debug('resolving href at pos '.$refPos);
  6322. $this->multirefs[$id][$refPos] = $idVal;
  6323. }
  6324. }
  6325. }
  6326. }
  6327. xml_parser_free($this->parser);
  6328. } else {
  6329. $this->debug('xml was empty, didn\'t parse!');
  6330. $this->setError('xml was empty, didn\'t parse!');
  6331. }
  6332. }
  6333. /**
  6334. * start-element handler
  6335. *
  6336. * @param resource $parser XML parser object
  6337. * @param string $name element name
  6338. * @param array $attrs associative array of attributes
  6339. * @access private
  6340. */
  6341. function start_element($parser, $name, $attrs) {
  6342. // position in a total number of elements, starting from 0
  6343. // update class level pos
  6344. $pos = $this->position++;
  6345. // and set mine
  6346. $this->message[$pos] = array('pos' => $pos,'children'=>'','cdata'=>'');
  6347. // depth = how many levels removed from root?
  6348. // set mine as current global depth and increment global depth value
  6349. $this->message[$pos]['depth'] = $this->depth++;
  6350. // else add self as child to whoever the current parent is
  6351. if($pos != 0){
  6352. $this->message[$this->parent]['children'] .= '|'.$pos;
  6353. }
  6354. // set my parent
  6355. $this->message[$pos]['parent'] = $this->parent;
  6356. // set self as current parent
  6357. $this->parent = $pos;
  6358. // set self as current value for this depth
  6359. $this->depth_array[$this->depth] = $pos;
  6360. // get element prefix
  6361. if(strpos($name,':')){
  6362. // get ns prefix
  6363. $prefix = substr($name,0,strpos($name,':'));
  6364. // get unqualified name
  6365. $name = substr(strstr($name,':'),1);
  6366. }
  6367. // set status
  6368. if ($name == 'Envelope' && $this->status == '') {
  6369. $this->status = 'envelope';
  6370. } elseif ($name == 'Header' && $this->status == 'envelope') {
  6371. $this->root_header = $pos;
  6372. $this->status = 'header';
  6373. } elseif ($name == 'Body' && $this->status == 'envelope'){
  6374. $this->status = 'body';
  6375. $this->body_position = $pos;
  6376. // set method
  6377. } elseif($this->status == 'body' && $pos == ($this->body_position+1)) {
  6378. $this->status = 'method';
  6379. $this->root_struct_name = $name;
  6380. $this->root_struct = $pos;
  6381. $this->message[$pos]['type'] = 'struct';
  6382. $this->debug("found root struct $this->root_struct_name, pos $this->root_struct");
  6383. }
  6384. // set my status
  6385. $this->message[$pos]['status'] = $this->status;
  6386. // set name
  6387. $this->message[$pos]['name'] = htmlspecialchars($name);
  6388. // set attrs
  6389. $this->message[$pos]['attrs'] = $attrs;
  6390. // loop through atts, logging ns and type declarations
  6391. $attstr = '';
  6392. foreach($attrs as $key => $value){
  6393. $key_prefix = $this->getPrefix($key);
  6394. $key_localpart = $this->getLocalPart($key);
  6395. // if ns declarations, add to class level array of valid namespaces
  6396. if($key_prefix == 'xmlns'){
  6397. if(preg_match('/^http:\/\/www.w3.org\/[0-9]{4}\/XMLSchema$/',$value)){
  6398. $this->XMLSchemaVersion = $value;
  6399. $this->namespaces['xsd'] = $this->XMLSchemaVersion;
  6400. $this->namespaces['xsi'] = $this->XMLSchemaVersion.'-instance';
  6401. }
  6402. $this->namespaces[$key_localpart] = $value;
  6403. // set method namespace
  6404. if($name == $this->root_struct_name){
  6405. $this->methodNamespace = $value;
  6406. }
  6407. // if it's a type declaration, set type
  6408. } elseif($key_localpart == 'type'){
  6409. if (isset($this->message[$pos]['type']) && $this->message[$pos]['type'] == 'array') {
  6410. // do nothing: already processed arrayType
  6411. } else {
  6412. $value_prefix = $this->getPrefix($value);
  6413. $value_localpart = $this->getLocalPart($value);
  6414. $this->message[$pos]['type'] = $value_localpart;
  6415. $this->message[$pos]['typePrefix'] = $value_prefix;
  6416. if(isset($this->namespaces[$value_prefix])){
  6417. $this->message[$pos]['type_namespace'] = $this->namespaces[$value_prefix];
  6418. } else if(isset($attrs['xmlns:'.$value_prefix])) {
  6419. $this->message[$pos]['type_namespace'] = $attrs['xmlns:'.$value_prefix];
  6420. }
  6421. // should do something here with the namespace of specified type?
  6422. }
  6423. } elseif($key_localpart == 'arrayType'){
  6424. $this->message[$pos]['type'] = 'array';
  6425. /* do arrayType ereg here
  6426. [1] arrayTypeValue ::= atype asize
  6427. [2] atype ::= QName rank*
  6428. [3] rank ::= '[' (',')* ']'
  6429. [4] asize ::= '[' length~ ']'
  6430. [5] length ::= nextDimension* Digit+
  6431. [6] nextDimension ::= Digit+ ','
  6432. */
  6433. $expr = '/([A-Za-z0-9_]+):([A-Za-z]+[A-Za-z0-9_]+)\[([0-9]+),?([0-9]*)\]/';
  6434. if(preg_match($expr,$value,$regs)){
  6435. $this->message[$pos]['typePrefix'] = $regs[1];
  6436. $this->message[$pos]['arrayTypePrefix'] = $regs[1];
  6437. if (isset($this->namespaces[$regs[1]])) {
  6438. $this->message[$pos]['arrayTypeNamespace'] = $this->namespaces[$regs[1]];
  6439. } else if (isset($attrs['xmlns:'.$regs[1]])) {
  6440. $this->message[$pos]['arrayTypeNamespace'] = $attrs['xmlns:'.$regs[1]];
  6441. }
  6442. $this->message[$pos]['arrayType'] = $regs[2];
  6443. $this->message[$pos]['arraySize'] = $regs[3];
  6444. $this->message[$pos]['arrayCols'] = $regs[4];
  6445. }
  6446. // specifies nil value (or not)
  6447. } elseif ($key_localpart == 'nil'){
  6448. $this->message[$pos]['nil'] = ($value == 'true' || $value == '1');
  6449. // some other attribute
  6450. } elseif ($key != 'href' && $key != 'xmlns' && $key_localpart != 'encodingStyle' && $key_localpart != 'root') {
  6451. $this->message[$pos]['xattrs']['!' . $key] = $value;
  6452. }
  6453. if ($key == 'xmlns') {
  6454. $this->default_namespace = $value;
  6455. }
  6456. // log id
  6457. if($key == 'id'){
  6458. $this->ids[$value] = $pos;
  6459. }
  6460. // root
  6461. if($key_localpart == 'root' && $value == 1){
  6462. $this->status = 'method';
  6463. $this->root_struct_name = $name;
  6464. $this->root_struct = $pos;
  6465. $this->debug("found root struct $this->root_struct_name, pos $pos");
  6466. }
  6467. // for doclit
  6468. $attstr .= " $key=\"$value\"";
  6469. }
  6470. // get namespace - must be done after namespace atts are processed
  6471. if(isset($prefix)){
  6472. $this->message[$pos]['namespace'] = $this->namespaces[$prefix];
  6473. $this->default_namespace = $this->namespaces[$prefix];
  6474. } else {
  6475. $this->message[$pos]['namespace'] = $this->default_namespace;
  6476. }
  6477. if($this->status == 'header'){
  6478. if ($this->root_header != $pos) {
  6479. $this->responseHeaders .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
  6480. }
  6481. } elseif($this->root_struct_name != ''){
  6482. $this->document .= "<" . (isset($prefix) ? $prefix . ':' : '') . "$name$attstr>";
  6483. }
  6484. }
  6485. /**
  6486. * end-element handler
  6487. *
  6488. * @param resource $parser XML parser object
  6489. * @param string $name element name
  6490. * @access private
  6491. */
  6492. function end_element($parser, $name) {
  6493. // position of current element is equal to the last value left in depth_array for my depth
  6494. $pos = $this->depth_array[$this->depth--];
  6495. // get element prefix
  6496. if(strpos($name,':')){
  6497. // get ns prefix
  6498. $prefix = substr($name,0,strpos($name,':'));
  6499. // get unqualified name
  6500. $name = substr(strstr($name,':'),1);
  6501. }
  6502. // build to native type
  6503. if(isset($this->body_position) && $pos > $this->body_position){
  6504. // deal w/ multirefs
  6505. if(isset($this->message[$pos]['attrs']['href'])){
  6506. // get id
  6507. $id = substr($this->message[$pos]['attrs']['href'],1);
  6508. // add placeholder to href array
  6509. $this->multirefs[$id][$pos] = 'placeholder';
  6510. // add set a reference to it as the result value
  6511. $this->message[$pos]['result'] =& $this->multirefs[$id][$pos];
  6512. // build complexType values
  6513. } elseif($this->message[$pos]['children'] != ''){
  6514. // if result has already been generated (struct/array)
  6515. if(!isset($this->message[$pos]['result'])){
  6516. $this->message[$pos]['result'] = $this->buildVal($pos);
  6517. }
  6518. // build complexType values of attributes and possibly simpleContent
  6519. } elseif (isset($this->message[$pos]['xattrs'])) {
  6520. if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
  6521. $this->message[$pos]['xattrs']['!'] = null;
  6522. } elseif (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
  6523. if (isset($this->message[$pos]['type'])) {
  6524. $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'] : '');
  6525. } else {
  6526. $parent = $this->message[$pos]['parent'];
  6527. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6528. $this->message[$pos]['xattrs']['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6529. } else {
  6530. $this->message[$pos]['xattrs']['!'] = $this->message[$pos]['cdata'];
  6531. }
  6532. }
  6533. }
  6534. $this->message[$pos]['result'] = $this->message[$pos]['xattrs'];
  6535. // set value of simpleType (or nil complexType)
  6536. } else {
  6537. //$this->debug('adding data for scalar value '.$this->message[$pos]['name'].' of value '.$this->message[$pos]['cdata']);
  6538. if (isset($this->message[$pos]['nil']) && $this->message[$pos]['nil']) {
  6539. $this->message[$pos]['xattrs']['!'] = null;
  6540. } elseif (isset($this->message[$pos]['type'])) {
  6541. $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'] : '');
  6542. } else {
  6543. $parent = $this->message[$pos]['parent'];
  6544. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6545. $this->message[$pos]['result'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6546. } else {
  6547. $this->message[$pos]['result'] = $this->message[$pos]['cdata'];
  6548. }
  6549. }
  6550. /* add value to parent's result, if parent is struct/array
  6551. $parent = $this->message[$pos]['parent'];
  6552. if($this->message[$parent]['type'] != 'map'){
  6553. if(strtolower($this->message[$parent]['type']) == 'array'){
  6554. $this->message[$parent]['result'][] = $this->message[$pos]['result'];
  6555. } else {
  6556. $this->message[$parent]['result'][$this->message[$pos]['name']] = $this->message[$pos]['result'];
  6557. }
  6558. }
  6559. */
  6560. }
  6561. }
  6562. // for doclit
  6563. if($this->status == 'header'){
  6564. if ($this->root_header != $pos) {
  6565. $this->responseHeaders .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
  6566. }
  6567. } elseif($pos >= $this->root_struct){
  6568. $this->document .= "</" . (isset($prefix) ? $prefix . ':' : '') . "$name>";
  6569. }
  6570. // switch status
  6571. if ($pos == $this->root_struct){
  6572. $this->status = 'body';
  6573. $this->root_struct_namespace = $this->message[$pos]['namespace'];
  6574. } elseif ($pos == $this->root_header) {
  6575. $this->status = 'envelope';
  6576. } elseif ($name == 'Body' && $this->status == 'body') {
  6577. $this->status = 'envelope';
  6578. } elseif ($name == 'Header' && $this->status == 'header') { // will never happen
  6579. $this->status = 'envelope';
  6580. } elseif ($name == 'Envelope' && $this->status == 'envelope') {
  6581. $this->status = '';
  6582. }
  6583. // set parent back to my parent
  6584. $this->parent = $this->message[$pos]['parent'];
  6585. }
  6586. /**
  6587. * element content handler
  6588. *
  6589. * @param resource $parser XML parser object
  6590. * @param string $data element content
  6591. * @access private
  6592. */
  6593. function character_data($parser, $data){
  6594. $pos = $this->depth_array[$this->depth];
  6595. if ($this->xml_encoding=='UTF-8'){
  6596. // TODO: add an option to disable this for folks who want
  6597. // raw UTF-8 that, e.g., might not map to iso-8859-1
  6598. // TODO: this can also be handled with xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, "ISO-8859-1");
  6599. if($this->decode_utf8){
  6600. $data = utf8_decode($data);
  6601. }
  6602. }
  6603. $this->message[$pos]['cdata'] .= $data;
  6604. // for doclit
  6605. if($this->status == 'header'){
  6606. $this->responseHeaders .= $data;
  6607. } else {
  6608. $this->document .= $data;
  6609. }
  6610. }
  6611. /**
  6612. * get the parsed message (SOAP Body)
  6613. *
  6614. * @return mixed
  6615. * @access public
  6616. * @deprecated use get_soapbody instead
  6617. */
  6618. function get_response(){
  6619. return $this->soapresponse;
  6620. }
  6621. /**
  6622. * get the parsed SOAP Body (NULL if there was none)
  6623. *
  6624. * @return mixed
  6625. * @access public
  6626. */
  6627. function get_soapbody(){
  6628. return $this->soapresponse;
  6629. }
  6630. /**
  6631. * get the parsed SOAP Header (NULL if there was none)
  6632. *
  6633. * @return mixed
  6634. * @access public
  6635. */
  6636. function get_soapheader(){
  6637. return $this->soapheader;
  6638. }
  6639. /**
  6640. * get the unparsed SOAP Header
  6641. *
  6642. * @return string XML or empty if no Header
  6643. * @access public
  6644. */
  6645. function getHeaders(){
  6646. return $this->responseHeaders;
  6647. }
  6648. /**
  6649. * decodes simple types into PHP variables
  6650. *
  6651. * @param string $value value to decode
  6652. * @param string $type XML type to decode
  6653. * @param string $typens XML type namespace to decode
  6654. * @return mixed PHP value
  6655. * @access private
  6656. */
  6657. function decodeSimple($value, $type, $typens) {
  6658. // TODO: use the namespace!
  6659. if ((!isset($type)) || $type == 'string' || $type == 'long' || $type == 'unsignedLong') {
  6660. return (string) $value;
  6661. }
  6662. if ($type == 'int' || $type == 'integer' || $type == 'short' || $type == 'byte') {
  6663. return (int) $value;
  6664. }
  6665. if ($type == 'float' || $type == 'double' || $type == 'decimal') {
  6666. return (double) $value;
  6667. }
  6668. if ($type == 'boolean') {
  6669. if (strtolower($value) == 'false' || strtolower($value) == 'f') {
  6670. return false;
  6671. }
  6672. return (boolean) $value;
  6673. }
  6674. if ($type == 'base64' || $type == 'base64Binary') {
  6675. $this->debug('Decode base64 value');
  6676. return base64_decode($value);
  6677. }
  6678. // obscure numeric types
  6679. if ($type == 'nonPositiveInteger' || $type == 'negativeInteger'
  6680. || $type == 'nonNegativeInteger' || $type == 'positiveInteger'
  6681. || $type == 'unsignedInt'
  6682. || $type == 'unsignedShort' || $type == 'unsignedByte') {
  6683. return (int) $value;
  6684. }
  6685. // bogus: parser treats array with no elements as a simple type
  6686. if ($type == 'array') {
  6687. return array();
  6688. }
  6689. // everything else
  6690. return (string) $value;
  6691. }
  6692. /**
  6693. * builds response structures for compound values (arrays/structs)
  6694. * and scalars
  6695. *
  6696. * @param integer $pos position in node tree
  6697. * @return mixed PHP value
  6698. * @access private
  6699. */
  6700. function buildVal($pos){
  6701. if(!isset($this->message[$pos]['type'])){
  6702. $this->message[$pos]['type'] = '';
  6703. }
  6704. $this->debug('in buildVal() for '.$this->message[$pos]['name']."(pos $pos) of type ".$this->message[$pos]['type']);
  6705. // if there are children...
  6706. if($this->message[$pos]['children'] != ''){
  6707. $this->debug('in buildVal, there are children');
  6708. $children = explode('|',$this->message[$pos]['children']);
  6709. array_shift($children); // knock off empty
  6710. // md array
  6711. if(isset($this->message[$pos]['arrayCols']) && $this->message[$pos]['arrayCols'] != ''){
  6712. $r=0; // rowcount
  6713. $c=0; // colcount
  6714. foreach($children as $child_pos){
  6715. $this->debug("in buildVal, got an MD array element: $r, $c");
  6716. $params[$r][] = $this->message[$child_pos]['result'];
  6717. $c++;
  6718. if($c == $this->message[$pos]['arrayCols']){
  6719. $c = 0;
  6720. $r++;
  6721. }
  6722. }
  6723. // array
  6724. } elseif($this->message[$pos]['type'] == 'array' || $this->message[$pos]['type'] == 'Array'){
  6725. $this->debug('in buildVal, adding array '.$this->message[$pos]['name']);
  6726. foreach($children as $child_pos){
  6727. $params[] = &$this->message[$child_pos]['result'];
  6728. }
  6729. // apache Map type: java hashtable
  6730. } elseif($this->message[$pos]['type'] == 'Map' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap'){
  6731. $this->debug('in buildVal, Java Map '.$this->message[$pos]['name']);
  6732. foreach($children as $child_pos){
  6733. $kv = explode("|",$this->message[$child_pos]['children']);
  6734. $params[$this->message[$kv[1]]['result']] = &$this->message[$kv[2]]['result'];
  6735. }
  6736. // generic compound type
  6737. //} elseif($this->message[$pos]['type'] == 'SOAPStruct' || $this->message[$pos]['type'] == 'struct') {
  6738. } else {
  6739. // Apache Vector type: treat as an array
  6740. $this->debug('in buildVal, adding Java Vector or generic compound type '.$this->message[$pos]['name']);
  6741. if ($this->message[$pos]['type'] == 'Vector' && $this->message[$pos]['type_namespace'] == 'http://xml.apache.org/xml-soap') {
  6742. $notstruct = 1;
  6743. } else {
  6744. $notstruct = 0;
  6745. }
  6746. //
  6747. foreach($children as $child_pos){
  6748. if($notstruct){
  6749. $params[] = &$this->message[$child_pos]['result'];
  6750. } else {
  6751. if (isset($params[$this->message[$child_pos]['name']])) {
  6752. // de-serialize repeated element name into an array
  6753. if ((!is_array($params[$this->message[$child_pos]['name']])) || (!isset($params[$this->message[$child_pos]['name']][0]))) {
  6754. $params[$this->message[$child_pos]['name']] = array($params[$this->message[$child_pos]['name']]);
  6755. }
  6756. $params[$this->message[$child_pos]['name']][] = &$this->message[$child_pos]['result'];
  6757. } else {
  6758. $params[$this->message[$child_pos]['name']] = &$this->message[$child_pos]['result'];
  6759. }
  6760. }
  6761. }
  6762. }
  6763. if (isset($this->message[$pos]['xattrs'])) {
  6764. $this->debug('in buildVal, handling attributes');
  6765. foreach ($this->message[$pos]['xattrs'] as $n => $v) {
  6766. $params[$n] = $v;
  6767. }
  6768. }
  6769. // handle simpleContent
  6770. if (isset($this->message[$pos]['cdata']) && trim($this->message[$pos]['cdata']) != '') {
  6771. $this->debug('in buildVal, handling simpleContent');
  6772. if (isset($this->message[$pos]['type'])) {
  6773. $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  6774. } else {
  6775. $parent = $this->message[$pos]['parent'];
  6776. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6777. $params['!'] = $this->decodeSimple($this->message[$pos]['cdata'], $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6778. } else {
  6779. $params['!'] = $this->message[$pos]['cdata'];
  6780. }
  6781. }
  6782. }
  6783. $ret = is_array($params) ? $params : array();
  6784. $this->debug('in buildVal, return:');
  6785. $this->appendDebug($this->varDump($ret));
  6786. return $ret;
  6787. } else {
  6788. $this->debug('in buildVal, no children, building scalar');
  6789. $cdata = isset($this->message[$pos]['cdata']) ? $this->message[$pos]['cdata'] : '';
  6790. if (isset($this->message[$pos]['type'])) {
  6791. $ret = $this->decodeSimple($cdata, $this->message[$pos]['type'], isset($this->message[$pos]['type_namespace']) ? $this->message[$pos]['type_namespace'] : '');
  6792. $this->debug("in buildVal, return: $ret");
  6793. return $ret;
  6794. }
  6795. $parent = $this->message[$pos]['parent'];
  6796. if (isset($this->message[$parent]['type']) && ($this->message[$parent]['type'] == 'array') && isset($this->message[$parent]['arrayType'])) {
  6797. $ret = $this->decodeSimple($cdata, $this->message[$parent]['arrayType'], isset($this->message[$parent]['arrayTypeNamespace']) ? $this->message[$parent]['arrayTypeNamespace'] : '');
  6798. $this->debug("in buildVal, return: $ret");
  6799. return $ret;
  6800. }
  6801. $ret = $this->message[$pos]['cdata'];
  6802. $this->debug("in buildVal, return: $ret");
  6803. return $ret;
  6804. }
  6805. }
  6806. }
  6807. /**
  6808. * Backward compatibility
  6809. */
  6810. class soap_parser extends nusoap_parser {
  6811. }
  6812. ?><?php
  6813. /**
  6814. *
  6815. * [nu]soapclient higher level class for easy usage.
  6816. *
  6817. * usage:
  6818. *
  6819. * // instantiate client with server info
  6820. * $soapclient = new nusoap_client( string path [ ,mixed wsdl] );
  6821. *
  6822. * // call method, get results
  6823. * echo $soapclient->call( string methodname [ ,array parameters] );
  6824. *
  6825. * // bye bye client
  6826. * unset($soapclient);
  6827. *
  6828. * @author Dietrich Ayala <dietrich@ganx4.com>
  6829. * @author Scott Nichol <snichol@users.sourceforge.net>
  6830. * @access public
  6831. */
  6832. class nusoap_client extends nusoap_base {
  6833. var $username = ''; // Username for HTTP authentication
  6834. var $password = ''; // Password for HTTP authentication
  6835. var $authtype = ''; // Type of HTTP authentication
  6836. var $certRequest = array(); // Certificate for HTTP SSL authentication
  6837. var $requestHeaders = false; // SOAP headers in request (text)
  6838. var $responseHeaders = ''; // SOAP headers from response (incomplete namespace resolution) (text)
  6839. var $responseHeader = NULL; // SOAP Header from response (parsed)
  6840. var $document = ''; // SOAP body response portion (incomplete namespace resolution) (text)
  6841. var $endpoint;
  6842. var $forceEndpoint = ''; // overrides WSDL endpoint
  6843. var $proxyhost = '';
  6844. var $proxyport = '';
  6845. var $proxyusername = '';
  6846. var $proxypassword = '';
  6847. var $portName = ''; // port name to use in WSDL
  6848. var $xml_encoding = ''; // character set encoding of incoming (response) messages
  6849. var $http_encoding = false;
  6850. var $timeout = 0; // HTTP connection timeout
  6851. var $response_timeout = 30; // HTTP response timeout
  6852. var $endpointType = ''; // soap|wsdl, empty for WSDL initialization error
  6853. var $persistentConnection = false;
  6854. var $defaultRpcParams = false; // This is no longer used
  6855. var $request = ''; // HTTP request
  6856. var $response = ''; // HTTP response
  6857. var $responseData = ''; // SOAP payload of response
  6858. var $cookies = array(); // Cookies from response or for request
  6859. var $decode_utf8 = true; // toggles whether the parser decodes element content w/ utf8_decode()
  6860. var $operations = array(); // WSDL operations, empty for WSDL initialization error
  6861. var $curl_options = array(); // User-specified cURL options
  6862. var $bindingType = ''; // WSDL operation binding type
  6863. var $use_curl = false; // whether to always try to use cURL
  6864. /*
  6865. * fault related variables
  6866. */
  6867. /**
  6868. * @var fault
  6869. * @access public
  6870. */
  6871. var $fault;
  6872. /**
  6873. * @var faultcode
  6874. * @access public
  6875. */
  6876. var $faultcode;
  6877. /**
  6878. * @var faultstring
  6879. * @access public
  6880. */
  6881. var $faultstring;
  6882. /**
  6883. * @var faultdetail
  6884. * @access public
  6885. */
  6886. var $faultdetail;
  6887. /**
  6888. * constructor
  6889. *
  6890. * @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object)
  6891. * @param mixed $wsdl optional, set to 'wsdl' or true if using WSDL
  6892. * @param string $proxyhost optional
  6893. * @param string $proxyport optional
  6894. * @param string $proxyusername optional
  6895. * @param string $proxypassword optional
  6896. * @param integer $timeout set the connection timeout
  6897. * @param integer $response_timeout set the response timeout
  6898. * @param string $portName optional portName in WSDL document
  6899. * @access public
  6900. */
  6901. function __construct($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $portName = ''){
  6902. parent::__construct();
  6903. $this->endpoint = $endpoint;
  6904. $this->proxyhost = $proxyhost;
  6905. $this->proxyport = $proxyport;
  6906. $this->proxyusername = $proxyusername;
  6907. $this->proxypassword = $proxypassword;
  6908. $this->timeout = $timeout;
  6909. $this->response_timeout = $response_timeout;
  6910. $this->portName = $portName;
  6911. $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout");
  6912. $this->appendDebug('endpoint=' . $this->varDump($endpoint));
  6913. // make values
  6914. if($wsdl){
  6915. if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) {
  6916. $this->wsdl = $endpoint;
  6917. $this->endpoint = $this->wsdl->wsdl;
  6918. $this->wsdlFile = $this->endpoint;
  6919. $this->debug('existing wsdl instance created from ' . $this->endpoint);
  6920. $this->checkWSDL();
  6921. } else {
  6922. $this->wsdlFile = $this->endpoint;
  6923. $this->wsdl = null;
  6924. $this->debug('will use lazy evaluation of wsdl from ' . $this->endpoint);
  6925. }
  6926. $this->endpointType = 'wsdl';
  6927. } else {
  6928. $this->debug("instantiate SOAP with endpoint at $endpoint");
  6929. $this->endpointType = 'soap';
  6930. }
  6931. }
  6932. /**
  6933. * calls method, returns PHP native type
  6934. *
  6935. * @param string $operation SOAP server URL or path
  6936. * @param mixed $params An array, associative or simple, of the parameters
  6937. * for the method call, or a string that is the XML
  6938. * for the call. For rpc style, this call will
  6939. * wrap the XML in a tag named after the method, as
  6940. * well as the SOAP Envelope and Body. For document
  6941. * style, this will only wrap with the Envelope and Body.
  6942. * IMPORTANT: when using an array with document style,
  6943. * in which case there
  6944. * is really one parameter, the root of the fragment
  6945. * used in the call, which encloses what programmers
  6946. * normally think of parameters. A parameter array
  6947. * *must* include the wrapper.
  6948. * @param string $namespace optional method namespace (WSDL can override)
  6949. * @param string $soapAction optional SOAPAction value (WSDL can override)
  6950. * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
  6951. * @param boolean $rpcParams optional (no longer used)
  6952. * @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override)
  6953. * @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override)
  6954. * @return mixed response from SOAP call, normally an associative array mirroring the structure of the XML response, false for certain fatal errors
  6955. * @access public
  6956. */
  6957. function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){
  6958. $this->operation = $operation;
  6959. $this->fault = false;
  6960. $this->setError('');
  6961. $this->request = '';
  6962. $this->response = '';
  6963. $this->responseData = '';
  6964. $this->faultstring = '';
  6965. $this->faultcode = '';
  6966. $this->opData = array();
  6967. $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType");
  6968. $this->appendDebug('params=' . $this->varDump($params));
  6969. $this->appendDebug('headers=' . $this->varDump($headers));
  6970. if ($headers) {
  6971. $this->requestHeaders = $headers;
  6972. }
  6973. if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
  6974. $this->loadWSDL();
  6975. if ($this->getError())
  6976. return false;
  6977. }
  6978. // serialize parameters
  6979. if($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)){
  6980. // use WSDL for operation
  6981. $this->opData = $opData;
  6982. $this->debug("found operation");
  6983. $this->appendDebug('opData=' . $this->varDump($opData));
  6984. if (isset($opData['soapAction'])) {
  6985. $soapAction = $opData['soapAction'];
  6986. }
  6987. if (! $this->forceEndpoint) {
  6988. $this->endpoint = $opData['endpoint'];
  6989. } else {
  6990. $this->endpoint = $this->forceEndpoint;
  6991. }
  6992. $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace;
  6993. $style = $opData['style'];
  6994. $use = $opData['input']['use'];
  6995. // add ns to ns array
  6996. if($namespace != '' && !isset($this->wsdl->namespaces[$namespace])){
  6997. $nsPrefix = 'ns' . rand(1000, 9999);
  6998. $this->wsdl->namespaces[$nsPrefix] = $namespace;
  6999. }
  7000. $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);
  7001. // serialize payload
  7002. if (is_string($params)) {
  7003. $this->debug("serializing param string for WSDL operation $operation");
  7004. $payload = $params;
  7005. } elseif (is_array($params)) {
  7006. $this->debug("serializing param array for WSDL operation $operation");
  7007. $payload = $this->wsdl->serializeRPCParameters($operation,'input',$params,$this->bindingType);
  7008. } else {
  7009. $this->debug('params must be array or string');
  7010. $this->setError('params must be array or string');
  7011. return false;
  7012. }
  7013. $usedNamespaces = $this->wsdl->usedNamespaces;
  7014. if (isset($opData['input']['encodingStyle'])) {
  7015. $encodingStyle = $opData['input']['encodingStyle'];
  7016. } else {
  7017. $encodingStyle = '';
  7018. }
  7019. $this->appendDebug($this->wsdl->getDebug());
  7020. $this->wsdl->clearDebug();
  7021. if ($errstr = $this->wsdl->getError()) {
  7022. $this->debug('got wsdl error: '.$errstr);
  7023. $this->setError('wsdl error: '.$errstr);
  7024. return false;
  7025. }
  7026. } elseif($this->endpointType == 'wsdl') {
  7027. // operation not in WSDL
  7028. $this->appendDebug($this->wsdl->getDebug());
  7029. $this->wsdl->clearDebug();
  7030. $this->setError('operation '.$operation.' not present in WSDL.');
  7031. $this->debug("operation '$operation' not present in WSDL.");
  7032. return false;
  7033. } else {
  7034. // no WSDL
  7035. //$this->namespaces['ns1'] = $namespace;
  7036. $nsPrefix = 'ns' . rand(1000, 9999);
  7037. // serialize
  7038. $payload = '';
  7039. if (is_string($params)) {
  7040. $this->debug("serializing param string for operation $operation");
  7041. $payload = $params;
  7042. } elseif (is_array($params)) {
  7043. $this->debug("serializing param array for operation $operation");
  7044. foreach($params as $k => $v){
  7045. $payload .= $this->serialize_val($v,$k,false,false,false,false,$use);
  7046. }
  7047. } else {
  7048. $this->debug('params must be array or string');
  7049. $this->setError('params must be array or string');
  7050. return false;
  7051. }
  7052. $usedNamespaces = array();
  7053. if ($use == 'encoded') {
  7054. $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/';
  7055. } else {
  7056. $encodingStyle = '';
  7057. }
  7058. }
  7059. // wrap RPC calls with method element
  7060. if ($style == 'rpc') {
  7061. if ($use == 'literal') {
  7062. $this->debug("wrapping RPC request with literal method element");
  7063. if ($namespace) {
  7064. // 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
  7065. $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
  7066. $payload .
  7067. "</$nsPrefix:$operation>";
  7068. } else {
  7069. $payload = "<$operation>" . $payload . "</$operation>";
  7070. }
  7071. } else {
  7072. $this->debug("wrapping RPC request with encoded method element");
  7073. if ($namespace) {
  7074. $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" .
  7075. $payload .
  7076. "</$nsPrefix:$operation>";
  7077. } else {
  7078. $payload = "<$operation>" .
  7079. $payload .
  7080. "</$operation>";
  7081. }
  7082. }
  7083. }
  7084. // serialize envelope
  7085. $soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$usedNamespaces,$style,$use,$encodingStyle);
  7086. $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle");
  7087. $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000));
  7088. // send
  7089. $return = $this->send($this->getHTTPBody($soapmsg),$soapAction,$this->timeout,$this->response_timeout);
  7090. if($errstr = $this->getError()){
  7091. $this->debug('Error: '.$errstr);
  7092. return false;
  7093. } else {
  7094. $this->return = $return;
  7095. $this->debug('sent message successfully and got a(n) '.gettype($return));
  7096. $this->appendDebug('return=' . $this->varDump($return));
  7097. // fault?
  7098. if(is_array($return) && isset($return['faultcode'])){
  7099. $this->debug('got fault');
  7100. $this->setError($return['faultcode'].': '.$return['faultstring']);
  7101. $this->fault = true;
  7102. foreach($return as $k => $v){
  7103. $this->$k = $v;
  7104. $this->debug("$k = $v<br>");
  7105. }
  7106. return $return;
  7107. } elseif ($style == 'document') {
  7108. // NOTE: if the response is defined to have multiple parts (i.e. unwrapped),
  7109. // we are only going to return the first part here...sorry about that
  7110. return $return;
  7111. } else {
  7112. // array of return values
  7113. if(is_array($return)){
  7114. // multiple 'out' parameters, which we return wrapped up
  7115. // in the array
  7116. if(sizeof($return) > 1){
  7117. return $return;
  7118. }
  7119. // single 'out' parameter (normally the return value)
  7120. $return = array_shift($return);
  7121. $this->debug('return shifted value: ');
  7122. $this->appendDebug($this->varDump($return));
  7123. return $return;
  7124. // nothing returned (ie, echoVoid)
  7125. } else {
  7126. return "";
  7127. }
  7128. }
  7129. }
  7130. }
  7131. /**
  7132. * check WSDL passed as an instance or pulled from an endpoint
  7133. *
  7134. * @access private
  7135. */
  7136. function checkWSDL() {
  7137. $this->appendDebug($this->wsdl->getDebug());
  7138. $this->wsdl->clearDebug();
  7139. $this->debug('checkWSDL');
  7140. // catch errors
  7141. if ($errstr = $this->wsdl->getError()) {
  7142. $this->appendDebug($this->wsdl->getDebug());
  7143. $this->wsdl->clearDebug();
  7144. $this->debug('got wsdl error: '.$errstr);
  7145. $this->setError('wsdl error: '.$errstr);
  7146. } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap')) {
  7147. $this->appendDebug($this->wsdl->getDebug());
  7148. $this->wsdl->clearDebug();
  7149. $this->bindingType = 'soap';
  7150. $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType);
  7151. } elseif ($this->operations = $this->wsdl->getOperations($this->portName, 'soap12')) {
  7152. $this->appendDebug($this->wsdl->getDebug());
  7153. $this->wsdl->clearDebug();
  7154. $this->bindingType = 'soap12';
  7155. $this->debug('got '.count($this->operations).' operations from wsdl '.$this->wsdlFile.' for binding type '.$this->bindingType);
  7156. $this->debug('**************** WARNING: SOAP 1.2 BINDING *****************');
  7157. } else {
  7158. $this->appendDebug($this->wsdl->getDebug());
  7159. $this->wsdl->clearDebug();
  7160. $this->debug('getOperations returned false');
  7161. $this->setError('no operations defined in the WSDL document!');
  7162. }
  7163. }
  7164. /**
  7165. * instantiate wsdl object and parse wsdl file
  7166. *
  7167. * @access public
  7168. */
  7169. function loadWSDL() {
  7170. $this->debug('instantiating wsdl class with doc: '.$this->wsdlFile);
  7171. $this->wsdl = new wsdl('',$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout,$this->curl_options,$this->use_curl);
  7172. $this->wsdl->setCredentials($this->username, $this->password, $this->authtype, $this->certRequest);
  7173. $this->wsdl->fetchWSDL($this->wsdlFile);
  7174. $this->checkWSDL();
  7175. }
  7176. /**
  7177. * get available data pertaining to an operation
  7178. *
  7179. * @param string $operation operation name
  7180. * @return array array of data pertaining to the operation
  7181. * @access public
  7182. */
  7183. function getOperationData($operation){
  7184. if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
  7185. $this->loadWSDL();
  7186. if ($this->getError())
  7187. return false;
  7188. }
  7189. if(isset($this->operations[$operation])){
  7190. return $this->operations[$operation];
  7191. }
  7192. $this->debug("No data for operation: $operation");
  7193. }
  7194. /**
  7195. * send the SOAP message
  7196. *
  7197. * Note: if the operation has multiple return values
  7198. * the return value of this method will be an array
  7199. * of those values.
  7200. *
  7201. * @param string $msg a SOAPx4 soapmsg object
  7202. * @param string $soapaction SOAPAction value
  7203. * @param integer $timeout set connection timeout in seconds
  7204. * @param integer $response_timeout set response timeout in seconds
  7205. * @return mixed native PHP types.
  7206. * @access private
  7207. */
  7208. function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) {
  7209. $this->checkCookies();
  7210. // detect transport
  7211. switch(true){
  7212. // http(s)
  7213. case preg_match('/^http/',$this->endpoint):
  7214. $this->debug('transporting via HTTP');
  7215. if($this->persistentConnection == true && is_object($this->persistentConnection)){
  7216. $http =& $this->persistentConnection;
  7217. } else {
  7218. $http = new soap_transport_http($this->endpoint, $this->curl_options, $this->use_curl);
  7219. if ($this->persistentConnection) {
  7220. $http->usePersistentConnection();
  7221. }
  7222. }
  7223. $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset());
  7224. $http->setSOAPAction($soapaction);
  7225. if($this->proxyhost && $this->proxyport){
  7226. $http->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword);
  7227. }
  7228. if($this->authtype != '') {
  7229. $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest);
  7230. }
  7231. if($this->http_encoding != ''){
  7232. $http->setEncoding($this->http_encoding);
  7233. }
  7234. $this->debug('sending message, length='.strlen($msg));
  7235. if(preg_match('/^http:/',$this->endpoint)){
  7236. //if(strpos($this->endpoint,'http:')){
  7237. $this->responseData = $http->send($msg,$timeout,$response_timeout,$this->cookies);
  7238. } elseif(preg_match('/^https/',$this->endpoint)){
  7239. //} elseif(strpos($this->endpoint,'https:')){
  7240. //if(phpversion() == '4.3.0-dev'){
  7241. //$response = $http->send($msg,$timeout,$response_timeout);
  7242. //$this->request = $http->outgoing_payload;
  7243. //$this->response = $http->incoming_payload;
  7244. //} else
  7245. $this->responseData = $http->sendHTTPS($msg,$timeout,$response_timeout,$this->cookies);
  7246. } else {
  7247. $this->setError('no http/s in endpoint url');
  7248. }
  7249. $this->request = $http->outgoing_payload;
  7250. $this->response = $http->incoming_payload;
  7251. $this->appendDebug($http->getDebug());
  7252. $this->UpdateCookies($http->incoming_cookies);
  7253. // save transport object if using persistent connections
  7254. if ($this->persistentConnection) {
  7255. $http->clearDebug();
  7256. if (!is_object($this->persistentConnection)) {
  7257. $this->persistentConnection = $http;
  7258. }
  7259. }
  7260. if($err = $http->getError()){
  7261. $this->setError('HTTP Error: '.$err);
  7262. return false;
  7263. } elseif($this->getError()){
  7264. return false;
  7265. } else {
  7266. $this->debug('got response, length='. strlen($this->responseData).' type='.$http->incoming_headers['content-type']);
  7267. return $this->parseResponse($http->incoming_headers, $this->responseData);
  7268. }
  7269. break;
  7270. default:
  7271. $this->setError('no transport found, or selected transport is not yet supported!');
  7272. return false;
  7273. break;
  7274. }
  7275. }
  7276. /**
  7277. * processes SOAP message returned from server
  7278. *
  7279. * @param array $headers The HTTP headers
  7280. * @param string $data unprocessed response data from server
  7281. * @return mixed value of the message, decoded into a PHP type
  7282. * @access private
  7283. */
  7284. function parseResponse($headers, $data) {
  7285. $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' headers:');
  7286. $this->appendDebug($this->varDump($headers));
  7287. if (!isset($headers['content-type'])) {
  7288. $this->setError('Response not of type text/xml (no content-type header)');
  7289. return false;
  7290. }
  7291. if (!strstr($headers['content-type'], 'text/xml')) {
  7292. $this->setError('Response not of type text/xml: ' . $headers['content-type']);
  7293. return false;
  7294. }
  7295. if (strpos($headers['content-type'], '=')) {
  7296. $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1));
  7297. $this->debug('Got response encoding: ' . $enc);
  7298. if(preg_match('/^(ISO-8859-1|US-ASCII|UTF-8)$/i',$enc)){
  7299. $this->xml_encoding = strtoupper($enc);
  7300. } else {
  7301. $this->xml_encoding = 'US-ASCII';
  7302. }
  7303. } else {
  7304. // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1
  7305. $this->xml_encoding = 'ISO-8859-1';
  7306. }
  7307. $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating nusoap_parser');
  7308. $parser = new nusoap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8);
  7309. // add parser debug data to our debug
  7310. $this->appendDebug($parser->getDebug());
  7311. // if parse errors
  7312. if($errstr = $parser->getError()){
  7313. $this->setError( $errstr);
  7314. // destroy the parser object
  7315. unset($parser);
  7316. return false;
  7317. } else {
  7318. // get SOAP headers
  7319. $this->responseHeaders = $parser->getHeaders();
  7320. // get SOAP headers
  7321. $this->responseHeader = $parser->get_soapheader();
  7322. // get decoded message
  7323. $return = $parser->get_soapbody();
  7324. // add document for doclit support
  7325. $this->document = $parser->document;
  7326. // destroy the parser object
  7327. unset($parser);
  7328. // return decode message
  7329. return $return;
  7330. }
  7331. }
  7332. /**
  7333. * sets user-specified cURL options
  7334. *
  7335. * @param mixed $option The cURL option (always integer?)
  7336. * @param mixed $value The cURL option value
  7337. * @access public
  7338. */
  7339. function setCurlOption($option, $value) {
  7340. $this->debug("setCurlOption option=$option, value=");
  7341. $this->appendDebug($this->varDump($value));
  7342. $this->curl_options[$option] = $value;
  7343. }
  7344. /**
  7345. * sets the SOAP endpoint, which can override WSDL
  7346. *
  7347. * @param string $endpoint The endpoint URL to use, or empty string or false to prevent override
  7348. * @access public
  7349. */
  7350. function setEndpoint($endpoint) {
  7351. $this->debug("setEndpoint(\"$endpoint\")");
  7352. $this->forceEndpoint = $endpoint;
  7353. }
  7354. /**
  7355. * set the SOAP headers
  7356. *
  7357. * @param mixed $headers String of XML with SOAP header content, or array of soapval objects for SOAP headers
  7358. * @access public
  7359. */
  7360. function setHeaders($headers){
  7361. $this->debug("setHeaders headers=");
  7362. $this->appendDebug($this->varDump($headers));
  7363. $this->requestHeaders = $headers;
  7364. }
  7365. /**
  7366. * get the SOAP response headers (namespace resolution incomplete)
  7367. *
  7368. * @return string
  7369. * @access public
  7370. */
  7371. function getHeaders(){
  7372. return $this->responseHeaders;
  7373. }
  7374. /**
  7375. * get the SOAP response Header (parsed)
  7376. *
  7377. * @return mixed
  7378. * @access public
  7379. */
  7380. function getHeader(){
  7381. return $this->responseHeader;
  7382. }
  7383. /**
  7384. * set proxy info here
  7385. *
  7386. * @param string $proxyhost
  7387. * @param string $proxyport
  7388. * @param string $proxyusername
  7389. * @param string $proxypassword
  7390. * @access public
  7391. */
  7392. function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '') {
  7393. $this->proxyhost = $proxyhost;
  7394. $this->proxyport = $proxyport;
  7395. $this->proxyusername = $proxyusername;
  7396. $this->proxypassword = $proxypassword;
  7397. }
  7398. /**
  7399. * if authenticating, set user credentials here
  7400. *
  7401. * @param string $username
  7402. * @param string $password
  7403. * @param string $authtype (basic|digest|certificate|ntlm)
  7404. * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
  7405. * @access public
  7406. */
  7407. function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) {
  7408. $this->debug("setCredentials username=$username authtype=$authtype certRequest=");
  7409. $this->appendDebug($this->varDump($certRequest));
  7410. $this->username = $username;
  7411. $this->password = $password;
  7412. $this->authtype = $authtype;
  7413. $this->certRequest = $certRequest;
  7414. }
  7415. /**
  7416. * use HTTP encoding
  7417. *
  7418. * @param string $enc HTTP encoding
  7419. * @access public
  7420. */
  7421. function setHTTPEncoding($enc='gzip, deflate'){
  7422. $this->debug("setHTTPEncoding(\"$enc\")");
  7423. $this->http_encoding = $enc;
  7424. }
  7425. /**
  7426. * Set whether to try to use cURL connections if possible
  7427. *
  7428. * @param boolean $use Whether to try to use cURL
  7429. * @access public
  7430. */
  7431. function setUseCURL($use) {
  7432. $this->debug("setUseCURL($use)");
  7433. $this->use_curl = $use;
  7434. }
  7435. /**
  7436. * use HTTP persistent connections if possible
  7437. *
  7438. * @access public
  7439. */
  7440. function useHTTPPersistentConnection(){
  7441. $this->debug("useHTTPPersistentConnection");
  7442. $this->persistentConnection = true;
  7443. }
  7444. /**
  7445. * gets the default RPC parameter setting.
  7446. * If true, default is that call params are like RPC even for document style.
  7447. * Each call() can override this value.
  7448. *
  7449. * This is no longer used.
  7450. *
  7451. * @return boolean
  7452. * @access public
  7453. * @deprecated
  7454. */
  7455. function getDefaultRpcParams() {
  7456. return $this->defaultRpcParams;
  7457. }
  7458. /**
  7459. * sets the default RPC parameter setting.
  7460. * If true, default is that call params are like RPC even for document style
  7461. * Each call() can override this value.
  7462. *
  7463. * This is no longer used.
  7464. *
  7465. * @param boolean $rpcParams
  7466. * @access public
  7467. * @deprecated
  7468. */
  7469. function setDefaultRpcParams($rpcParams) {
  7470. $this->defaultRpcParams = $rpcParams;
  7471. }
  7472. /**
  7473. * dynamically creates an instance of a proxy class,
  7474. * allowing user to directly call methods from wsdl
  7475. *
  7476. * @return object soap_proxy object
  7477. * @access public
  7478. */
  7479. function getProxy() {
  7480. $r = rand();
  7481. $evalStr = $this->_getProxyClassCode($r);
  7482. //$this->debug("proxy class: $evalStr");
  7483. if ($this->getError()) {
  7484. $this->debug("Error from _getProxyClassCode, so return NULL");
  7485. return null;
  7486. }
  7487. // eval the class
  7488. eval($evalStr);
  7489. // instantiate proxy object
  7490. eval("\$proxy = new nusoap_proxy_$r('');");
  7491. // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice
  7492. $proxy->endpointType = 'wsdl';
  7493. $proxy->wsdlFile = $this->wsdlFile;
  7494. $proxy->wsdl = $this->wsdl;
  7495. $proxy->operations = $this->operations;
  7496. $proxy->defaultRpcParams = $this->defaultRpcParams;
  7497. // transfer other state
  7498. $proxy->soap_defencoding = $this->soap_defencoding;
  7499. $proxy->username = $this->username;
  7500. $proxy->password = $this->password;
  7501. $proxy->authtype = $this->authtype;
  7502. $proxy->certRequest = $this->certRequest;
  7503. $proxy->requestHeaders = $this->requestHeaders;
  7504. $proxy->endpoint = $this->endpoint;
  7505. $proxy->forceEndpoint = $this->forceEndpoint;
  7506. $proxy->proxyhost = $this->proxyhost;
  7507. $proxy->proxyport = $this->proxyport;
  7508. $proxy->proxyusername = $this->proxyusername;
  7509. $proxy->proxypassword = $this->proxypassword;
  7510. $proxy->http_encoding = $this->http_encoding;
  7511. $proxy->timeout = $this->timeout;
  7512. $proxy->response_timeout = $this->response_timeout;
  7513. $proxy->persistentConnection = &$this->persistentConnection;
  7514. $proxy->decode_utf8 = $this->decode_utf8;
  7515. $proxy->curl_options = $this->curl_options;
  7516. $proxy->bindingType = $this->bindingType;
  7517. $proxy->use_curl = $this->use_curl;
  7518. return $proxy;
  7519. }
  7520. /**
  7521. * dynamically creates proxy class code
  7522. *
  7523. * @return string PHP/NuSOAP code for the proxy class
  7524. * @access private
  7525. */
  7526. function _getProxyClassCode($r) {
  7527. $this->debug("in getProxy endpointType=$this->endpointType");
  7528. $this->appendDebug("wsdl=" . $this->varDump($this->wsdl));
  7529. if ($this->endpointType != 'wsdl') {
  7530. $evalStr = 'A proxy can only be created for a WSDL client';
  7531. $this->setError($evalStr);
  7532. $evalStr = "echo \"$evalStr\";";
  7533. return $evalStr;
  7534. }
  7535. if ($this->endpointType == 'wsdl' && is_null($this->wsdl)) {
  7536. $this->loadWSDL();
  7537. if ($this->getError()) {
  7538. return "echo \"" . $this->getError() . "\";";
  7539. }
  7540. }
  7541. $evalStr = '';
  7542. foreach ($this->operations as $operation => $opData) {
  7543. if ($operation != '') {
  7544. // create param string and param comment string
  7545. if (sizeof($opData['input']['parts']) > 0) {
  7546. $paramStr = '';
  7547. $paramArrayStr = '';
  7548. $paramCommentStr = '';
  7549. foreach ($opData['input']['parts'] as $name => $type) {
  7550. $paramStr .= "\$$name, ";
  7551. $paramArrayStr .= "'$name' => \$$name, ";
  7552. $paramCommentStr .= "$type \$$name, ";
  7553. }
  7554. $paramStr = substr($paramStr, 0, strlen($paramStr)-2);
  7555. $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr)-2);
  7556. $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr)-2);
  7557. } else {
  7558. $paramStr = '';
  7559. $paramArrayStr = '';
  7560. $paramCommentStr = 'void';
  7561. }
  7562. $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace'];
  7563. $evalStr .= "// $paramCommentStr
  7564. function " . str_replace('.', '__', $operation) . "($paramStr) {
  7565. \$params = array($paramArrayStr);
  7566. return \$this->call('$operation', \$params, '".$opData['namespace']."', '".(isset($opData['soapAction']) ? $opData['soapAction'] : '')."');
  7567. }
  7568. ";
  7569. unset($paramStr);
  7570. unset($paramCommentStr);
  7571. }
  7572. }
  7573. $evalStr = 'class nusoap_proxy_'.$r.' extends nusoap_client {
  7574. '.$evalStr.'
  7575. }';
  7576. return $evalStr;
  7577. }
  7578. /**
  7579. * dynamically creates proxy class code
  7580. *
  7581. * @return string PHP/NuSOAP code for the proxy class
  7582. * @access public
  7583. */
  7584. function getProxyClassCode() {
  7585. $r = rand();
  7586. return $this->_getProxyClassCode($r);
  7587. }
  7588. /**
  7589. * gets the HTTP body for the current request.
  7590. *
  7591. * @param string $soapmsg The SOAP payload
  7592. * @return string The HTTP body, which includes the SOAP payload
  7593. * @access private
  7594. */
  7595. function getHTTPBody($soapmsg) {
  7596. return $soapmsg;
  7597. }
  7598. /**
  7599. * gets the HTTP content type for the current request.
  7600. *
  7601. * Note: getHTTPBody must be called before this.
  7602. *
  7603. * @return string the HTTP content type for the current request.
  7604. * @access private
  7605. */
  7606. function getHTTPContentType() {
  7607. return 'text/xml';
  7608. }
  7609. /**
  7610. * gets the HTTP content type charset for the current request.
  7611. * returns false for non-text content types.
  7612. *
  7613. * Note: getHTTPBody must be called before this.
  7614. *
  7615. * @return string the HTTP content type charset for the current request.
  7616. * @access private
  7617. */
  7618. function getHTTPContentTypeCharset() {
  7619. return $this->soap_defencoding;
  7620. }
  7621. /*
  7622. * whether or not parser should decode utf8 element content
  7623. *
  7624. * @return always returns true
  7625. * @access public
  7626. */
  7627. function decodeUTF8($bool){
  7628. $this->decode_utf8 = $bool;
  7629. return true;
  7630. }
  7631. /**
  7632. * adds a new Cookie into $this->cookies array
  7633. *
  7634. * @param string $name Cookie Name
  7635. * @param string $value Cookie Value
  7636. * @return boolean if cookie-set was successful returns true, else false
  7637. * @access public
  7638. */
  7639. function setCookie($name, $value) {
  7640. if (strlen($name) == 0) {
  7641. return false;
  7642. }
  7643. $this->cookies[] = array('name' => $name, 'value' => $value);
  7644. return true;
  7645. }
  7646. /**
  7647. * gets all Cookies
  7648. *
  7649. * @return array with all internal cookies
  7650. * @access public
  7651. */
  7652. function getCookies() {
  7653. return $this->cookies;
  7654. }
  7655. /**
  7656. * checks all Cookies and delete those which are expired
  7657. *
  7658. * @return boolean always return true
  7659. * @access private
  7660. */
  7661. function checkCookies() {
  7662. if (sizeof($this->cookies) == 0) {
  7663. return true;
  7664. }
  7665. $this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies');
  7666. $curr_cookies = $this->cookies;
  7667. $this->cookies = array();
  7668. foreach ($curr_cookies as $cookie) {
  7669. if (! is_array($cookie)) {
  7670. $this->debug('Remove cookie that is not an array');
  7671. continue;
  7672. }
  7673. if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) {
  7674. if (strtotime($cookie['expires']) > time()) {
  7675. $this->cookies[] = $cookie;
  7676. } else {
  7677. $this->debug('Remove expired cookie ' . $cookie['name']);
  7678. }
  7679. } else {
  7680. $this->cookies[] = $cookie;
  7681. }
  7682. }
  7683. $this->debug('checkCookie: '.sizeof($this->cookies).' cookies left in array');
  7684. return true;
  7685. }
  7686. /**
  7687. * updates the current cookies with a new set
  7688. *
  7689. * @param array $cookies new cookies with which to update current ones
  7690. * @return boolean always return true
  7691. * @access private
  7692. */
  7693. function UpdateCookies($cookies) {
  7694. if (sizeof($this->cookies) == 0) {
  7695. // no existing cookies: take whatever is new
  7696. if (sizeof($cookies) > 0) {
  7697. $this->debug('Setting new cookie(s)');
  7698. $this->cookies = $cookies;
  7699. }
  7700. return true;
  7701. }
  7702. if (sizeof($cookies) == 0) {
  7703. // no new cookies: keep what we've got
  7704. return true;
  7705. }
  7706. // merge
  7707. foreach ($cookies as $newCookie) {
  7708. if (!is_array($newCookie)) {
  7709. continue;
  7710. }
  7711. if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) {
  7712. continue;
  7713. }
  7714. $newName = $newCookie['name'];
  7715. $found = false;
  7716. for ($i = 0; $i < count($this->cookies); $i++) {
  7717. $cookie = $this->cookies[$i];
  7718. if (!is_array($cookie)) {
  7719. continue;
  7720. }
  7721. if (!isset($cookie['name'])) {
  7722. continue;
  7723. }
  7724. if ($newName != $cookie['name']) {
  7725. continue;
  7726. }
  7727. $newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN';
  7728. $domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN';
  7729. if ($newDomain != $domain) {
  7730. continue;
  7731. }
  7732. $newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH';
  7733. $path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH';
  7734. if ($newPath != $path) {
  7735. continue;
  7736. }
  7737. $this->cookies[$i] = $newCookie;
  7738. $found = true;
  7739. $this->debug('Update cookie ' . $newName . '=' . $newCookie['value']);
  7740. break;
  7741. }
  7742. if (! $found) {
  7743. $this->debug('Add cookie ' . $newName . '=' . $newCookie['value']);
  7744. $this->cookies[] = $newCookie;
  7745. }
  7746. }
  7747. return true;
  7748. }
  7749. }
  7750. if (!extension_loaded('soap')) {
  7751. /**
  7752. * For backwards compatiblity, define soapclient unless the PHP SOAP extension is loaded.
  7753. */
  7754. class soapclient extends nusoap_client {
  7755. }
  7756. }
  7757. ?>