nusoap.php 281 KB

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