soap.c 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Brad Lafountain <rodif_bl@yahoo.com> |
  16. | Shane Caraveo <shane@caraveo.com> |
  17. | Dmitry Stogov <dmitry@php.net> |
  18. +----------------------------------------------------------------------+
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "php_soap.h"
  24. #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  25. #include "ext/session/php_session.h"
  26. #endif
  27. #include "zend_exceptions.h"
  28. static int le_sdl = 0;
  29. int le_url = 0;
  30. static int le_service = 0;
  31. static int le_typemap = 0;
  32. typedef struct _soapHeader {
  33. sdlFunctionPtr function;
  34. zval function_name;
  35. int mustUnderstand;
  36. int num_params;
  37. zval *parameters;
  38. zval retval;
  39. sdlSoapBindingFunctionHeaderPtr hdr;
  40. struct _soapHeader *next;
  41. } soapHeader;
  42. /* Local functions */
  43. static void function_to_string(sdlFunctionPtr function, smart_str *buf);
  44. static void type_to_string(sdlTypePtr type, smart_str *buf, int level);
  45. static void clear_soap_fault(zval *obj);
  46. static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, char *name);
  47. static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail);
  48. static void soap_server_fault(char* code, char* string, char *actor, zval* details, char *name);
  49. static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeader* hdr);
  50. static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int index, int);
  51. static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name);
  52. static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr node);
  53. static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, char* actor, zval *function_name, int *num_params, zval **parameters, int *version, soapHeader **headers);
  54. static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function_name,char *uri,zval *ret, soapHeader *headers, int version);
  55. static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function, char *function_name, char *uri, zval *arguments, int arg_count, int version, HashTable *soap_headers);
  56. static xmlNodePtr serialize_parameter(sdlParamPtr param,zval *param_val,int index,char *name, int style, xmlNodePtr parent);
  57. static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName, int style, xmlNodePtr parent);
  58. static void delete_service(void *service);
  59. static void delete_url(void *handle);
  60. static void delete_hashtable(void *hashtable);
  61. static void soap_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args);
  62. #define SOAP_SERVER_BEGIN_CODE() \
  63. zend_bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\
  64. char* _old_error_code = SOAP_GLOBAL(error_code);\
  65. zend_object* _old_error_object = Z_OBJ(SOAP_GLOBAL(error_object));\
  66. int _old_soap_version = SOAP_GLOBAL(soap_version);\
  67. SOAP_GLOBAL(use_soap_error_handler) = 1;\
  68. SOAP_GLOBAL(error_code) = "Server";\
  69. Z_OBJ(SOAP_GLOBAL(error_object)) = Z_OBJ(EX(This));
  70. #define SOAP_SERVER_END_CODE() \
  71. SOAP_GLOBAL(use_soap_error_handler) = _old_handler;\
  72. SOAP_GLOBAL(error_code) = _old_error_code;\
  73. Z_OBJ(SOAP_GLOBAL(error_object)) = _old_error_object;\
  74. SOAP_GLOBAL(soap_version) = _old_soap_version;
  75. #define SOAP_CLIENT_BEGIN_CODE() \
  76. zend_bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\
  77. char* _old_error_code = SOAP_GLOBAL(error_code);\
  78. zend_object* _old_error_object = Z_OBJ(SOAP_GLOBAL(error_object));\
  79. int _old_soap_version = SOAP_GLOBAL(soap_version);\
  80. zend_bool _old_in_compilation = CG(in_compilation); \
  81. zend_execute_data *_old_current_execute_data = EG(current_execute_data); \
  82. zval *_old_stack_top = EG(vm_stack_top); \
  83. int _bailout = 0;\
  84. SOAP_GLOBAL(use_soap_error_handler) = 1;\
  85. SOAP_GLOBAL(error_code) = "Client";\
  86. Z_OBJ(SOAP_GLOBAL(error_object)) = Z_OBJ(EX(This));\
  87. zend_try {
  88. #define SOAP_CLIENT_END_CODE() \
  89. } zend_catch {\
  90. CG(in_compilation) = _old_in_compilation; \
  91. EG(current_execute_data) = _old_current_execute_data; \
  92. if (EG(exception) == NULL || \
  93. !instanceof_function(EG(exception)->ce, soap_fault_class_entry)) {\
  94. _bailout = 1;\
  95. }\
  96. if (_old_stack_top != EG(vm_stack_top)) { \
  97. while (EG(vm_stack)->prev != NULL && \
  98. ((char*)_old_stack_top < (char*)EG(vm_stack) || \
  99. (char*) _old_stack_top > (char*)EG(vm_stack)->end)) { \
  100. zend_vm_stack tmp = EG(vm_stack)->prev; \
  101. efree(EG(vm_stack)); \
  102. EG(vm_stack) = tmp; \
  103. EG(vm_stack_end) = tmp->end; \
  104. } \
  105. EG(vm_stack)->top = _old_stack_top; \
  106. } \
  107. } zend_end_try();\
  108. SOAP_GLOBAL(use_soap_error_handler) = _old_handler;\
  109. SOAP_GLOBAL(error_code) = _old_error_code;\
  110. Z_OBJ(SOAP_GLOBAL(error_object)) = _old_error_object;\
  111. SOAP_GLOBAL(soap_version) = _old_soap_version;\
  112. if (_bailout) {\
  113. zend_bailout();\
  114. }
  115. #define FETCH_THIS_SDL(ss) \
  116. { \
  117. zval *__tmp; \
  118. if(FIND_SDL_PROPERTY(getThis(), __tmp) != NULL) { \
  119. FETCH_SDL_RES(ss,__tmp); \
  120. } else { \
  121. ss = NULL; \
  122. } \
  123. }
  124. #define FIND_SDL_PROPERTY(ss,tmp) (tmp = zend_hash_str_find(Z_OBJPROP_P(ss), "sdl", sizeof("sdl")-1))
  125. #define FETCH_SDL_RES(ss,tmp) ss = (sdlPtr) zend_fetch_resource_ex(tmp, "sdl", le_sdl)
  126. #define FIND_TYPEMAP_PROPERTY(ss,tmp) (tmp = zend_hash_str_find(Z_OBJPROP_P(ss), "typemap", sizeof("typemap")-1))
  127. #define FETCH_TYPEMAP_RES(ss,tmp) ss = (HashTable*) zend_fetch_resource_ex(tmp, "typemap", le_typemap)
  128. #define FETCH_THIS_SERVICE(ss) \
  129. { \
  130. zval *tmp; \
  131. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()),"service", sizeof("service")-1)) != NULL) { \
  132. ss = (soapServicePtr)zend_fetch_resource_ex(tmp, "service", le_service); \
  133. } else { \
  134. php_error_docref(NULL, E_WARNING, "Can not fetch service object"); \
  135. SOAP_SERVER_END_CODE(); \
  136. return; \
  137. } \
  138. }
  139. static zend_class_entry* soap_class_entry;
  140. static zend_class_entry* soap_server_class_entry;
  141. static zend_class_entry* soap_fault_class_entry;
  142. static zend_class_entry* soap_header_class_entry;
  143. static zend_class_entry* soap_param_class_entry;
  144. zend_class_entry* soap_var_class_entry;
  145. ZEND_DECLARE_MODULE_GLOBALS(soap)
  146. static void (*old_error_handler)(int, const char *, const uint32_t, const char*, va_list);
  147. #define call_old_error_handler(error_num, error_filename, error_lineno, format, args) \
  148. { \
  149. va_list copy; \
  150. va_copy(copy, args); \
  151. old_error_handler(error_num, error_filename, error_lineno, format, copy); \
  152. va_end(copy); \
  153. }
  154. #define PHP_SOAP_SERVER_CLASSNAME "SoapServer"
  155. #define PHP_SOAP_CLIENT_CLASSNAME "SoapClient"
  156. #define PHP_SOAP_VAR_CLASSNAME "SoapVar"
  157. #define PHP_SOAP_FAULT_CLASSNAME "SoapFault"
  158. #define PHP_SOAP_PARAM_CLASSNAME "SoapParam"
  159. #define PHP_SOAP_HEADER_CLASSNAME "SoapHeader"
  160. PHP_RINIT_FUNCTION(soap);
  161. PHP_MINIT_FUNCTION(soap);
  162. PHP_MSHUTDOWN_FUNCTION(soap);
  163. PHP_MINFO_FUNCTION(soap);
  164. /*
  165. Registry Functions
  166. TODO: this!
  167. */
  168. PHP_FUNCTION(soap_encode_to_xml);
  169. PHP_FUNCTION(soap_encode_to_zval);
  170. PHP_FUNCTION(use_soap_error_handler);
  171. PHP_FUNCTION(is_soap_fault);
  172. /* Server Functions */
  173. PHP_METHOD(SoapServer, SoapServer);
  174. PHP_METHOD(SoapServer, setClass);
  175. PHP_METHOD(SoapServer, setObject);
  176. PHP_METHOD(SoapServer, addFunction);
  177. PHP_METHOD(SoapServer, getFunctions);
  178. PHP_METHOD(SoapServer, handle);
  179. PHP_METHOD(SoapServer, setPersistence);
  180. PHP_METHOD(SoapServer, fault);
  181. PHP_METHOD(SoapServer, addSoapHeader);
  182. /* Client Functions */
  183. PHP_METHOD(SoapClient, SoapClient);
  184. PHP_METHOD(SoapClient, __call);
  185. PHP_METHOD(SoapClient, __getLastRequest);
  186. PHP_METHOD(SoapClient, __getLastResponse);
  187. PHP_METHOD(SoapClient, __getLastRequestHeaders);
  188. PHP_METHOD(SoapClient, __getLastResponseHeaders);
  189. PHP_METHOD(SoapClient, __getFunctions);
  190. PHP_METHOD(SoapClient, __getTypes);
  191. PHP_METHOD(SoapClient, __doRequest);
  192. PHP_METHOD(SoapClient, __setCookie);
  193. PHP_METHOD(SoapClient, __getCookies);
  194. PHP_METHOD(SoapClient, __setLocation);
  195. PHP_METHOD(SoapClient, __setSoapHeaders);
  196. /* SoapVar Functions */
  197. PHP_METHOD(SoapVar, SoapVar);
  198. /* SoapFault Functions */
  199. PHP_METHOD(SoapFault, SoapFault);
  200. PHP_METHOD(SoapFault, __toString);
  201. /* SoapParam Functions */
  202. PHP_METHOD(SoapParam, SoapParam);
  203. /* SoapHeader Functions */
  204. PHP_METHOD(SoapHeader, SoapHeader);
  205. #define SOAP_CTOR(class_name, func_name, arginfo, flags) PHP_ME(class_name, func_name, arginfo, flags)
  206. /* {{{ arginfo */
  207. ZEND_BEGIN_ARG_INFO(arginfo_soap__void, 0)
  208. ZEND_END_ARG_INFO()
  209. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapparam_soapparam, 0, 0, 2)
  210. ZEND_ARG_INFO(0, data)
  211. ZEND_ARG_INFO(0, name)
  212. ZEND_END_ARG_INFO()
  213. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapheader_soapheader, 0, 0, 2)
  214. ZEND_ARG_INFO(0, namespace)
  215. ZEND_ARG_INFO(0, name)
  216. ZEND_ARG_INFO(0, data)
  217. ZEND_ARG_INFO(0, mustunderstand)
  218. ZEND_ARG_INFO(0, actor)
  219. ZEND_END_ARG_INFO()
  220. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapfault_soapfault, 0, 0, 2)
  221. ZEND_ARG_INFO(0, faultcode)
  222. ZEND_ARG_INFO(0, faultstring)
  223. ZEND_ARG_INFO(0, faultactor)
  224. ZEND_ARG_INFO(0, detail)
  225. ZEND_ARG_INFO(0, faultname)
  226. ZEND_ARG_INFO(0, headerfault)
  227. ZEND_END_ARG_INFO()
  228. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapvar_soapvar, 0, 0, 2)
  229. ZEND_ARG_INFO(0, data)
  230. ZEND_ARG_INFO(0, encoding)
  231. ZEND_ARG_INFO(0, type_name)
  232. ZEND_ARG_INFO(0, type_namespace)
  233. ZEND_ARG_INFO(0, node_name)
  234. ZEND_ARG_INFO(0, node_namespace)
  235. ZEND_END_ARG_INFO()
  236. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_fault, 0, 0, 2)
  237. ZEND_ARG_INFO(0, code)
  238. ZEND_ARG_INFO(0, string)
  239. ZEND_ARG_INFO(0, actor)
  240. ZEND_ARG_INFO(0, details)
  241. ZEND_ARG_INFO(0, name)
  242. ZEND_END_ARG_INFO()
  243. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_addsoapheader, 0, 0, 1)
  244. ZEND_ARG_INFO(0, object)
  245. ZEND_END_ARG_INFO()
  246. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_soapserver, 0, 0, 1)
  247. ZEND_ARG_INFO(0, wsdl)
  248. ZEND_ARG_INFO(0, options)
  249. ZEND_END_ARG_INFO()
  250. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_setpersistence, 0, 0, 1)
  251. ZEND_ARG_INFO(0, mode)
  252. ZEND_END_ARG_INFO()
  253. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_setclass, 0, 0, 1)
  254. ZEND_ARG_INFO(0, class_name)
  255. ZEND_ARG_VARIADIC_INFO(0, args)
  256. ZEND_END_ARG_INFO()
  257. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_setobject, 0, 0, 1)
  258. ZEND_ARG_INFO(0, object)
  259. ZEND_END_ARG_INFO()
  260. ZEND_BEGIN_ARG_INFO(arginfo_soapserver_getfunctions, 0)
  261. ZEND_END_ARG_INFO()
  262. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_addfunction, 0, 0, 1)
  263. ZEND_ARG_INFO(0, functions)
  264. ZEND_END_ARG_INFO()
  265. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapserver_handle, 0, 0, 0)
  266. ZEND_ARG_INFO(0, soap_request)
  267. ZEND_END_ARG_INFO()
  268. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient_soapclient, 0, 0, 1)
  269. ZEND_ARG_INFO(0, wsdl)
  270. ZEND_ARG_INFO(0, options)
  271. ZEND_END_ARG_INFO()
  272. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___call, 0, 0, 2)
  273. ZEND_ARG_INFO(0, function_name)
  274. ZEND_ARG_INFO(0, arguments)
  275. ZEND_END_ARG_INFO()
  276. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___soapcall, 0, 0, 2)
  277. ZEND_ARG_INFO(0, function_name)
  278. ZEND_ARG_INFO(0, arguments)
  279. ZEND_ARG_INFO(0, options)
  280. ZEND_ARG_INFO(0, input_headers)
  281. ZEND_ARG_INFO(1, output_headers)
  282. ZEND_END_ARG_INFO()
  283. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getfunctions, 0)
  284. ZEND_END_ARG_INFO()
  285. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___gettypes, 0)
  286. ZEND_END_ARG_INFO()
  287. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastrequest, 0)
  288. ZEND_END_ARG_INFO()
  289. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastresponse, 0)
  290. ZEND_END_ARG_INFO()
  291. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastrequestheaders, 0)
  292. ZEND_END_ARG_INFO()
  293. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getlastresponseheaders, 0)
  294. ZEND_END_ARG_INFO()
  295. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___dorequest, 0, 0, 4)
  296. ZEND_ARG_INFO(0, request)
  297. ZEND_ARG_INFO(0, location)
  298. ZEND_ARG_INFO(0, action)
  299. ZEND_ARG_INFO(0, version)
  300. ZEND_ARG_INFO(0, one_way)
  301. ZEND_END_ARG_INFO()
  302. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___setcookie, 0, 0, 1)
  303. ZEND_ARG_INFO(0, name)
  304. ZEND_ARG_INFO(0, value)
  305. ZEND_END_ARG_INFO()
  306. ZEND_BEGIN_ARG_INFO(arginfo_soapclient___getcookies, 0)
  307. ZEND_END_ARG_INFO()
  308. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___setsoapheaders, 0, 0, 0)
  309. ZEND_ARG_INFO(0, soapheaders)
  310. ZEND_END_ARG_INFO()
  311. ZEND_BEGIN_ARG_INFO_EX(arginfo_soapclient___setlocation, 0, 0, 0)
  312. ZEND_ARG_INFO(0, new_location)
  313. ZEND_END_ARG_INFO()
  314. ZEND_BEGIN_ARG_INFO_EX(arginfo_soap_use_soap_error_handler, 0, 0, 0)
  315. ZEND_ARG_INFO(0, handler)
  316. ZEND_END_ARG_INFO()
  317. ZEND_BEGIN_ARG_INFO_EX(arginfo_soap_is_soap_fault, 0, 0, 1)
  318. ZEND_ARG_INFO(0, object)
  319. ZEND_END_ARG_INFO()
  320. /* }}} */
  321. static const zend_function_entry soap_functions[] = {
  322. PHP_FE(use_soap_error_handler, arginfo_soap_use_soap_error_handler)
  323. PHP_FE(is_soap_fault, arginfo_soap_is_soap_fault)
  324. PHP_FE_END
  325. };
  326. static const zend_function_entry soap_fault_functions[] = {
  327. SOAP_CTOR(SoapFault, SoapFault, arginfo_soapfault_soapfault, 0)
  328. PHP_ME(SoapFault, __toString, arginfo_soap__void, 0)
  329. PHP_FE_END
  330. };
  331. static const zend_function_entry soap_server_functions[] = {
  332. SOAP_CTOR(SoapServer, SoapServer, arginfo_soapserver_soapserver, 0)
  333. PHP_ME(SoapServer, setPersistence, arginfo_soapserver_setpersistence, 0)
  334. PHP_ME(SoapServer, setClass, arginfo_soapserver_setclass, 0)
  335. PHP_ME(SoapServer, setObject, arginfo_soapserver_setobject, 0)
  336. PHP_ME(SoapServer, addFunction, arginfo_soapserver_addfunction, 0)
  337. PHP_ME(SoapServer, getFunctions, arginfo_soapserver_getfunctions, 0)
  338. PHP_ME(SoapServer, handle, arginfo_soapserver_handle, 0)
  339. PHP_ME(SoapServer, fault, arginfo_soapserver_fault, 0)
  340. PHP_ME(SoapServer, addSoapHeader, arginfo_soapserver_addsoapheader, 0)
  341. PHP_FE_END
  342. };
  343. static const zend_function_entry soap_client_functions[] = {
  344. SOAP_CTOR(SoapClient, SoapClient, arginfo_soapclient_soapclient, 0)
  345. PHP_ME(SoapClient, __call, arginfo_soapclient___call, 0)
  346. ZEND_NAMED_ME(__soapCall, ZEND_MN(SoapClient___call), arginfo_soapclient___soapcall, 0)
  347. PHP_ME(SoapClient, __getLastRequest, arginfo_soapclient___getlastrequest, 0)
  348. PHP_ME(SoapClient, __getLastResponse, arginfo_soapclient___getlastresponse, 0)
  349. PHP_ME(SoapClient, __getLastRequestHeaders, arginfo_soapclient___getlastrequestheaders, 0)
  350. PHP_ME(SoapClient, __getLastResponseHeaders, arginfo_soapclient___getlastresponseheaders, 0)
  351. PHP_ME(SoapClient, __getFunctions, arginfo_soapclient___getfunctions, 0)
  352. PHP_ME(SoapClient, __getTypes, arginfo_soapclient___gettypes, 0)
  353. PHP_ME(SoapClient, __doRequest, arginfo_soapclient___dorequest, 0)
  354. PHP_ME(SoapClient, __setCookie, arginfo_soapclient___setcookie, 0)
  355. PHP_ME(SoapClient, __getCookies, arginfo_soapclient___getcookies, 0)
  356. PHP_ME(SoapClient, __setLocation, arginfo_soapclient___setlocation, 0)
  357. PHP_ME(SoapClient, __setSoapHeaders, arginfo_soapclient___setsoapheaders, 0)
  358. PHP_FE_END
  359. };
  360. static const zend_function_entry soap_var_functions[] = {
  361. SOAP_CTOR(SoapVar, SoapVar, arginfo_soapvar_soapvar, 0)
  362. PHP_FE_END
  363. };
  364. static const zend_function_entry soap_param_functions[] = {
  365. SOAP_CTOR(SoapParam, SoapParam, arginfo_soapparam_soapparam, 0)
  366. PHP_FE_END
  367. };
  368. static const zend_function_entry soap_header_functions[] = {
  369. SOAP_CTOR(SoapHeader, SoapHeader, arginfo_soapheader_soapheader, 0)
  370. PHP_FE_END
  371. };
  372. zend_module_entry soap_module_entry = {
  373. #ifdef STANDARD_MODULE_HEADER
  374. STANDARD_MODULE_HEADER,
  375. #endif
  376. "soap",
  377. soap_functions,
  378. PHP_MINIT(soap),
  379. PHP_MSHUTDOWN(soap),
  380. PHP_RINIT(soap),
  381. NULL,
  382. PHP_MINFO(soap),
  383. #ifdef STANDARD_MODULE_HEADER
  384. PHP_SOAP_VERSION,
  385. #endif
  386. STANDARD_MODULE_PROPERTIES,
  387. };
  388. #ifdef COMPILE_DL_SOAP
  389. #ifdef ZTS
  390. ZEND_TSRMLS_CACHE_DEFINE()
  391. #endif
  392. ZEND_GET_MODULE(soap)
  393. #endif
  394. ZEND_INI_MH(OnUpdateCacheMode)
  395. {
  396. char *p;
  397. #ifndef ZTS
  398. char *base = (char *) mh_arg2;
  399. #else
  400. char *base = (char *) ts_resource(*((int *) mh_arg2));
  401. #endif
  402. p = (char*) (base+(size_t) mh_arg1);
  403. *p = (char)atoi(ZSTR_VAL(new_value));
  404. return SUCCESS;
  405. }
  406. static PHP_INI_MH(OnUpdateCacheDir)
  407. {
  408. /* Only do the open_basedir check at runtime */
  409. if (stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) {
  410. char *p;
  411. if (memchr(ZSTR_VAL(new_value), '\0', ZSTR_LEN(new_value)) != NULL) {
  412. return FAILURE;
  413. }
  414. /* we do not use zend_memrchr() since path can contain ; itself */
  415. if ((p = strchr(ZSTR_VAL(new_value), ';'))) {
  416. char *p2;
  417. p++;
  418. if ((p2 = strchr(p, ';'))) {
  419. p = p2 + 1;
  420. }
  421. } else {
  422. p = ZSTR_VAL(new_value);
  423. }
  424. if (PG(open_basedir) && *p && php_check_open_basedir(p)) {
  425. return FAILURE;
  426. }
  427. }
  428. OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
  429. return SUCCESS;
  430. }
  431. PHP_INI_BEGIN()
  432. STD_PHP_INI_ENTRY("soap.wsdl_cache_enabled", "1", PHP_INI_ALL, OnUpdateBool,
  433. cache_enabled, zend_soap_globals, soap_globals)
  434. STD_PHP_INI_ENTRY("soap.wsdl_cache_dir", "/tmp", PHP_INI_ALL, OnUpdateCacheDir,
  435. cache_dir, zend_soap_globals, soap_globals)
  436. STD_PHP_INI_ENTRY("soap.wsdl_cache_ttl", "86400", PHP_INI_ALL, OnUpdateLong,
  437. cache_ttl, zend_soap_globals, soap_globals)
  438. STD_PHP_INI_ENTRY("soap.wsdl_cache", "1", PHP_INI_ALL, OnUpdateCacheMode,
  439. cache_mode, zend_soap_globals, soap_globals)
  440. STD_PHP_INI_ENTRY("soap.wsdl_cache_limit", "5", PHP_INI_ALL, OnUpdateLong,
  441. cache_limit, zend_soap_globals, soap_globals)
  442. PHP_INI_END()
  443. static HashTable defEnc, defEncIndex, defEncNs;
  444. static void php_soap_prepare_globals()
  445. {
  446. int i;
  447. const encode* enc;
  448. zend_hash_init(&defEnc, 0, NULL, NULL, 1);
  449. zend_hash_init(&defEncIndex, 0, NULL, NULL, 1);
  450. zend_hash_init(&defEncNs, 0, NULL, NULL, 1);
  451. i = 0;
  452. do {
  453. enc = &defaultEncoding[i];
  454. /* If has a ns and a str_type then index it */
  455. if (defaultEncoding[i].details.type_str) {
  456. if (defaultEncoding[i].details.ns != NULL) {
  457. char *ns_type;
  458. spprintf(&ns_type, 0, "%s:%s", defaultEncoding[i].details.ns, defaultEncoding[i].details.type_str);
  459. zend_hash_str_add_ptr(&defEnc, ns_type, strlen(ns_type), (void*)enc);
  460. efree(ns_type);
  461. } else {
  462. zend_hash_str_add_ptr(&defEnc, defaultEncoding[i].details.type_str, strlen(defaultEncoding[i].details.type_str), (void*)enc);
  463. }
  464. }
  465. /* Index everything by number */
  466. if (!zend_hash_index_exists(&defEncIndex, defaultEncoding[i].details.type)) {
  467. zend_hash_index_update_ptr(&defEncIndex, defaultEncoding[i].details.type, (void*)enc);
  468. }
  469. i++;
  470. } while (defaultEncoding[i].details.type != END_KNOWN_TYPES);
  471. /* hash by namespace */
  472. zend_hash_str_add_ptr(&defEncNs, XSD_1999_NAMESPACE, sizeof(XSD_1999_NAMESPACE)-1, XSD_NS_PREFIX);
  473. zend_hash_str_add_ptr(&defEncNs, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1, XSD_NS_PREFIX);
  474. zend_hash_str_add_ptr(&defEncNs, XSI_NAMESPACE, sizeof(XSI_NAMESPACE)-1, XSI_NS_PREFIX);
  475. zend_hash_str_add_ptr(&defEncNs, XML_NAMESPACE, sizeof(XML_NAMESPACE)-1, XML_NS_PREFIX);
  476. zend_hash_str_add_ptr(&defEncNs, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1, SOAP_1_1_ENC_NS_PREFIX);
  477. zend_hash_str_add_ptr(&defEncNs, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1, SOAP_1_2_ENC_NS_PREFIX);
  478. }
  479. static void php_soap_init_globals(zend_soap_globals *soap_globals)
  480. {
  481. #if defined(COMPILE_DL_SOAP) && defined(ZTS)
  482. ZEND_TSRMLS_CACHE_UPDATE();
  483. #endif
  484. soap_globals->defEnc = defEnc;
  485. soap_globals->defEncIndex = defEncIndex;
  486. soap_globals->defEncNs = defEncNs;
  487. soap_globals->typemap = NULL;
  488. soap_globals->use_soap_error_handler = 0;
  489. soap_globals->error_code = NULL;
  490. ZVAL_OBJ(&soap_globals->error_object, NULL);
  491. soap_globals->sdl = NULL;
  492. soap_globals->soap_version = SOAP_1_1;
  493. soap_globals->mem_cache = NULL;
  494. soap_globals->ref_map = NULL;
  495. }
  496. PHP_MSHUTDOWN_FUNCTION(soap)
  497. {
  498. zend_error_cb = old_error_handler;
  499. zend_hash_destroy(&SOAP_GLOBAL(defEnc));
  500. zend_hash_destroy(&SOAP_GLOBAL(defEncIndex));
  501. zend_hash_destroy(&SOAP_GLOBAL(defEncNs));
  502. if (SOAP_GLOBAL(mem_cache)) {
  503. zend_hash_destroy(SOAP_GLOBAL(mem_cache));
  504. free(SOAP_GLOBAL(mem_cache));
  505. }
  506. UNREGISTER_INI_ENTRIES();
  507. return SUCCESS;
  508. }
  509. PHP_RINIT_FUNCTION(soap)
  510. {
  511. SOAP_GLOBAL(typemap) = NULL;
  512. SOAP_GLOBAL(use_soap_error_handler) = 0;
  513. SOAP_GLOBAL(error_code) = NULL;
  514. ZVAL_OBJ(&SOAP_GLOBAL(error_object), NULL);
  515. SOAP_GLOBAL(sdl) = NULL;
  516. SOAP_GLOBAL(soap_version) = SOAP_1_1;
  517. SOAP_GLOBAL(encoding) = NULL;
  518. SOAP_GLOBAL(class_map) = NULL;
  519. SOAP_GLOBAL(features) = 0;
  520. SOAP_GLOBAL(ref_map) = NULL;
  521. return SUCCESS;
  522. }
  523. static void delete_sdl_res(zend_resource *res)
  524. {
  525. delete_sdl(res->ptr);
  526. }
  527. static void delete_url_res(zend_resource *res)
  528. {
  529. delete_url(res->ptr);
  530. }
  531. static void delete_service_res(zend_resource *res)
  532. {
  533. delete_service(res->ptr);
  534. }
  535. static void delete_hashtable_res(zend_resource *res)
  536. {
  537. delete_hashtable(res->ptr);
  538. }
  539. PHP_MINIT_FUNCTION(soap)
  540. {
  541. zend_class_entry ce;
  542. /* TODO: add ini entry for always use soap errors */
  543. php_soap_prepare_globals();
  544. ZEND_INIT_MODULE_GLOBALS(soap, php_soap_init_globals, NULL);
  545. REGISTER_INI_ENTRIES();
  546. /* Register SoapClient class */
  547. /* BIG NOTE : THIS EMITS AN COMPILATION WARNING UNDER ZE2 - handle_function_call deprecated.
  548. soap_call_function_handler should be of type struct _zend_function, not (*handle_function_call).
  549. */
  550. {
  551. INIT_CLASS_ENTRY(ce, PHP_SOAP_CLIENT_CLASSNAME, soap_client_functions);
  552. soap_class_entry = zend_register_internal_class(&ce);
  553. }
  554. /* Register SoapVar class */
  555. INIT_CLASS_ENTRY(ce, PHP_SOAP_VAR_CLASSNAME, soap_var_functions);
  556. soap_var_class_entry = zend_register_internal_class(&ce);
  557. /* Register SoapServer class */
  558. INIT_CLASS_ENTRY(ce, PHP_SOAP_SERVER_CLASSNAME, soap_server_functions);
  559. soap_server_class_entry = zend_register_internal_class(&ce);
  560. /* Register SoapFault class */
  561. INIT_CLASS_ENTRY(ce, PHP_SOAP_FAULT_CLASSNAME, soap_fault_functions);
  562. soap_fault_class_entry = zend_register_internal_class_ex(&ce, zend_ce_exception);
  563. /* Register SoapParam class */
  564. INIT_CLASS_ENTRY(ce, PHP_SOAP_PARAM_CLASSNAME, soap_param_functions);
  565. soap_param_class_entry = zend_register_internal_class(&ce);
  566. INIT_CLASS_ENTRY(ce, PHP_SOAP_HEADER_CLASSNAME, soap_header_functions);
  567. soap_header_class_entry = zend_register_internal_class(&ce);
  568. le_sdl = zend_register_list_destructors_ex(delete_sdl_res, NULL, "SOAP SDL", module_number);
  569. le_url = zend_register_list_destructors_ex(delete_url_res, NULL, "SOAP URL", module_number);
  570. le_service = zend_register_list_destructors_ex(delete_service_res, NULL, "SOAP service", module_number);
  571. le_typemap = zend_register_list_destructors_ex(delete_hashtable_res, NULL, "SOAP table", module_number);
  572. REGISTER_LONG_CONSTANT("SOAP_1_1", SOAP_1_1, CONST_CS | CONST_PERSISTENT);
  573. REGISTER_LONG_CONSTANT("SOAP_1_2", SOAP_1_2, CONST_CS | CONST_PERSISTENT);
  574. REGISTER_LONG_CONSTANT("SOAP_PERSISTENCE_SESSION", SOAP_PERSISTENCE_SESSION, CONST_CS | CONST_PERSISTENT);
  575. REGISTER_LONG_CONSTANT("SOAP_PERSISTENCE_REQUEST", SOAP_PERSISTENCE_REQUEST, CONST_CS | CONST_PERSISTENT);
  576. REGISTER_LONG_CONSTANT("SOAP_FUNCTIONS_ALL", SOAP_FUNCTIONS_ALL, CONST_CS | CONST_PERSISTENT);
  577. REGISTER_LONG_CONSTANT("SOAP_ENCODED", SOAP_ENCODED, CONST_CS | CONST_PERSISTENT);
  578. REGISTER_LONG_CONSTANT("SOAP_LITERAL", SOAP_LITERAL, CONST_CS | CONST_PERSISTENT);
  579. REGISTER_LONG_CONSTANT("SOAP_RPC", SOAP_RPC, CONST_CS | CONST_PERSISTENT);
  580. REGISTER_LONG_CONSTANT("SOAP_DOCUMENT", SOAP_DOCUMENT, CONST_CS | CONST_PERSISTENT);
  581. REGISTER_LONG_CONSTANT("SOAP_ACTOR_NEXT", SOAP_ACTOR_NEXT, CONST_CS | CONST_PERSISTENT);
  582. REGISTER_LONG_CONSTANT("SOAP_ACTOR_NONE", SOAP_ACTOR_NONE, CONST_CS | CONST_PERSISTENT);
  583. REGISTER_LONG_CONSTANT("SOAP_ACTOR_UNLIMATERECEIVER", SOAP_ACTOR_UNLIMATERECEIVER, CONST_CS | CONST_PERSISTENT);
  584. REGISTER_LONG_CONSTANT("SOAP_COMPRESSION_ACCEPT", SOAP_COMPRESSION_ACCEPT, CONST_CS | CONST_PERSISTENT);
  585. REGISTER_LONG_CONSTANT("SOAP_COMPRESSION_GZIP", SOAP_COMPRESSION_GZIP, CONST_CS | CONST_PERSISTENT);
  586. REGISTER_LONG_CONSTANT("SOAP_COMPRESSION_DEFLATE", SOAP_COMPRESSION_DEFLATE, CONST_CS | CONST_PERSISTENT);
  587. REGISTER_LONG_CONSTANT("SOAP_AUTHENTICATION_BASIC", SOAP_AUTHENTICATION_BASIC, CONST_CS | CONST_PERSISTENT);
  588. REGISTER_LONG_CONSTANT("SOAP_AUTHENTICATION_DIGEST", SOAP_AUTHENTICATION_DIGEST, CONST_CS | CONST_PERSISTENT);
  589. REGISTER_LONG_CONSTANT("UNKNOWN_TYPE", UNKNOWN_TYPE, CONST_CS | CONST_PERSISTENT);
  590. REGISTER_LONG_CONSTANT("XSD_STRING", XSD_STRING, CONST_CS | CONST_PERSISTENT);
  591. REGISTER_LONG_CONSTANT("XSD_BOOLEAN", XSD_BOOLEAN, CONST_CS | CONST_PERSISTENT);
  592. REGISTER_LONG_CONSTANT("XSD_DECIMAL", XSD_DECIMAL, CONST_CS | CONST_PERSISTENT);
  593. REGISTER_LONG_CONSTANT("XSD_FLOAT", XSD_FLOAT, CONST_CS | CONST_PERSISTENT);
  594. REGISTER_LONG_CONSTANT("XSD_DOUBLE", XSD_DOUBLE, CONST_CS | CONST_PERSISTENT);
  595. REGISTER_LONG_CONSTANT("XSD_DURATION", XSD_DURATION, CONST_CS | CONST_PERSISTENT);
  596. REGISTER_LONG_CONSTANT("XSD_DATETIME", XSD_DATETIME, CONST_CS | CONST_PERSISTENT);
  597. REGISTER_LONG_CONSTANT("XSD_TIME", XSD_TIME, CONST_CS | CONST_PERSISTENT);
  598. REGISTER_LONG_CONSTANT("XSD_DATE", XSD_DATE, CONST_CS | CONST_PERSISTENT);
  599. REGISTER_LONG_CONSTANT("XSD_GYEARMONTH", XSD_GYEARMONTH, CONST_CS | CONST_PERSISTENT);
  600. REGISTER_LONG_CONSTANT("XSD_GYEAR", XSD_GYEAR, CONST_CS | CONST_PERSISTENT);
  601. REGISTER_LONG_CONSTANT("XSD_GMONTHDAY", XSD_GMONTHDAY, CONST_CS | CONST_PERSISTENT);
  602. REGISTER_LONG_CONSTANT("XSD_GDAY", XSD_GDAY, CONST_CS | CONST_PERSISTENT);
  603. REGISTER_LONG_CONSTANT("XSD_GMONTH", XSD_GMONTH, CONST_CS | CONST_PERSISTENT);
  604. REGISTER_LONG_CONSTANT("XSD_HEXBINARY", XSD_HEXBINARY, CONST_CS | CONST_PERSISTENT);
  605. REGISTER_LONG_CONSTANT("XSD_BASE64BINARY", XSD_BASE64BINARY, CONST_CS | CONST_PERSISTENT);
  606. REGISTER_LONG_CONSTANT("XSD_ANYURI", XSD_ANYURI, CONST_CS | CONST_PERSISTENT);
  607. REGISTER_LONG_CONSTANT("XSD_QNAME", XSD_QNAME, CONST_CS | CONST_PERSISTENT);
  608. REGISTER_LONG_CONSTANT("XSD_NOTATION", XSD_NOTATION, CONST_CS | CONST_PERSISTENT);
  609. REGISTER_LONG_CONSTANT("XSD_NORMALIZEDSTRING", XSD_NORMALIZEDSTRING, CONST_CS | CONST_PERSISTENT);
  610. REGISTER_LONG_CONSTANT("XSD_TOKEN", XSD_TOKEN, CONST_CS | CONST_PERSISTENT);
  611. REGISTER_LONG_CONSTANT("XSD_LANGUAGE", XSD_LANGUAGE, CONST_CS | CONST_PERSISTENT);
  612. REGISTER_LONG_CONSTANT("XSD_NMTOKEN", XSD_NMTOKEN, CONST_CS | CONST_PERSISTENT);
  613. REGISTER_LONG_CONSTANT("XSD_NAME", XSD_NAME, CONST_CS | CONST_PERSISTENT);
  614. REGISTER_LONG_CONSTANT("XSD_NCNAME", XSD_NCNAME, CONST_CS | CONST_PERSISTENT);
  615. REGISTER_LONG_CONSTANT("XSD_ID", XSD_ID, CONST_CS | CONST_PERSISTENT);
  616. REGISTER_LONG_CONSTANT("XSD_IDREF", XSD_IDREF, CONST_CS | CONST_PERSISTENT);
  617. REGISTER_LONG_CONSTANT("XSD_IDREFS", XSD_IDREFS, CONST_CS | CONST_PERSISTENT);
  618. REGISTER_LONG_CONSTANT("XSD_ENTITY", XSD_ENTITY, CONST_CS | CONST_PERSISTENT);
  619. REGISTER_LONG_CONSTANT("XSD_ENTITIES", XSD_ENTITIES, CONST_CS | CONST_PERSISTENT);
  620. REGISTER_LONG_CONSTANT("XSD_INTEGER", XSD_INTEGER, CONST_CS | CONST_PERSISTENT);
  621. REGISTER_LONG_CONSTANT("XSD_NONPOSITIVEINTEGER", XSD_NONPOSITIVEINTEGER, CONST_CS | CONST_PERSISTENT);
  622. REGISTER_LONG_CONSTANT("XSD_NEGATIVEINTEGER", XSD_NEGATIVEINTEGER, CONST_CS | CONST_PERSISTENT);
  623. REGISTER_LONG_CONSTANT("XSD_LONG", XSD_LONG, CONST_CS | CONST_PERSISTENT);
  624. REGISTER_LONG_CONSTANT("XSD_INT", XSD_INT, CONST_CS | CONST_PERSISTENT);
  625. REGISTER_LONG_CONSTANT("XSD_SHORT", XSD_SHORT, CONST_CS | CONST_PERSISTENT);
  626. REGISTER_LONG_CONSTANT("XSD_BYTE", XSD_BYTE, CONST_CS | CONST_PERSISTENT);
  627. REGISTER_LONG_CONSTANT("XSD_NONNEGATIVEINTEGER", XSD_NONNEGATIVEINTEGER, CONST_CS | CONST_PERSISTENT);
  628. REGISTER_LONG_CONSTANT("XSD_UNSIGNEDLONG", XSD_UNSIGNEDLONG, CONST_CS | CONST_PERSISTENT);
  629. REGISTER_LONG_CONSTANT("XSD_UNSIGNEDINT", XSD_UNSIGNEDINT, CONST_CS | CONST_PERSISTENT);
  630. REGISTER_LONG_CONSTANT("XSD_UNSIGNEDSHORT", XSD_UNSIGNEDSHORT, CONST_CS | CONST_PERSISTENT);
  631. REGISTER_LONG_CONSTANT("XSD_UNSIGNEDBYTE", XSD_UNSIGNEDBYTE, CONST_CS | CONST_PERSISTENT);
  632. REGISTER_LONG_CONSTANT("XSD_POSITIVEINTEGER", XSD_POSITIVEINTEGER, CONST_CS | CONST_PERSISTENT);
  633. REGISTER_LONG_CONSTANT("XSD_NMTOKENS", XSD_NMTOKENS, CONST_CS | CONST_PERSISTENT);
  634. REGISTER_LONG_CONSTANT("XSD_ANYTYPE", XSD_ANYTYPE, CONST_CS | CONST_PERSISTENT);
  635. REGISTER_LONG_CONSTANT("XSD_ANYXML", XSD_ANYXML, CONST_CS | CONST_PERSISTENT);
  636. REGISTER_LONG_CONSTANT("APACHE_MAP", APACHE_MAP, CONST_CS | CONST_PERSISTENT);
  637. REGISTER_LONG_CONSTANT("SOAP_ENC_OBJECT", SOAP_ENC_OBJECT, CONST_CS | CONST_PERSISTENT);
  638. REGISTER_LONG_CONSTANT("SOAP_ENC_ARRAY", SOAP_ENC_ARRAY, CONST_CS | CONST_PERSISTENT);
  639. REGISTER_LONG_CONSTANT("XSD_1999_TIMEINSTANT", XSD_1999_TIMEINSTANT, CONST_CS | CONST_PERSISTENT);
  640. REGISTER_STRING_CONSTANT("XSD_NAMESPACE", XSD_NAMESPACE, CONST_CS | CONST_PERSISTENT);
  641. REGISTER_STRING_CONSTANT("XSD_1999_NAMESPACE", XSD_1999_NAMESPACE, CONST_CS | CONST_PERSISTENT);
  642. REGISTER_LONG_CONSTANT("SOAP_SINGLE_ELEMENT_ARRAYS", SOAP_SINGLE_ELEMENT_ARRAYS, CONST_CS | CONST_PERSISTENT);
  643. REGISTER_LONG_CONSTANT("SOAP_WAIT_ONE_WAY_CALLS", SOAP_WAIT_ONE_WAY_CALLS, CONST_CS | CONST_PERSISTENT);
  644. REGISTER_LONG_CONSTANT("SOAP_USE_XSI_ARRAY_TYPE", SOAP_USE_XSI_ARRAY_TYPE, CONST_CS | CONST_PERSISTENT);
  645. REGISTER_LONG_CONSTANT("WSDL_CACHE_NONE", WSDL_CACHE_NONE, CONST_CS | CONST_PERSISTENT);
  646. REGISTER_LONG_CONSTANT("WSDL_CACHE_DISK", WSDL_CACHE_DISK, CONST_CS | CONST_PERSISTENT);
  647. REGISTER_LONG_CONSTANT("WSDL_CACHE_MEMORY", WSDL_CACHE_MEMORY, CONST_CS | CONST_PERSISTENT);
  648. REGISTER_LONG_CONSTANT("WSDL_CACHE_BOTH", WSDL_CACHE_BOTH, CONST_CS | CONST_PERSISTENT);
  649. /* New SOAP SSL Method Constants */
  650. REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_TLS", SOAP_SSL_METHOD_TLS, CONST_CS | CONST_PERSISTENT);
  651. REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_SSLv2", SOAP_SSL_METHOD_SSLv2, CONST_CS | CONST_PERSISTENT);
  652. REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_SSLv3", SOAP_SSL_METHOD_SSLv3, CONST_CS | CONST_PERSISTENT);
  653. REGISTER_LONG_CONSTANT("SOAP_SSL_METHOD_SSLv23", SOAP_SSL_METHOD_SSLv23, CONST_CS | CONST_PERSISTENT);
  654. old_error_handler = zend_error_cb;
  655. zend_error_cb = soap_error_handler;
  656. return SUCCESS;
  657. }
  658. PHP_MINFO_FUNCTION(soap)
  659. {
  660. php_info_print_table_start();
  661. php_info_print_table_row(2, "Soap Client", "enabled");
  662. php_info_print_table_row(2, "Soap Server", "enabled");
  663. php_info_print_table_end();
  664. DISPLAY_INI_ENTRIES();
  665. }
  666. /* {{{ proto object SoapParam::SoapParam(mixed data, string name)
  667. SoapParam constructor */
  668. PHP_METHOD(SoapParam, SoapParam)
  669. {
  670. zval *data;
  671. char *name;
  672. size_t name_length;
  673. zval *this_ptr;
  674. if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &data, &name, &name_length) == FAILURE) {
  675. return;
  676. }
  677. if (name_length == 0) {
  678. php_error_docref(NULL, E_WARNING, "Invalid parameter name");
  679. return;
  680. }
  681. this_ptr = getThis();
  682. add_property_stringl(this_ptr, "param_name", name, name_length);
  683. add_property_zval(this_ptr, "param_data", data);
  684. }
  685. /* }}} */
  686. /* {{{ proto object SoapHeader::SoapHeader(string namespace, string name [, mixed data [, bool mustUnderstand [, mixed actor]]])
  687. SoapHeader constructor */
  688. PHP_METHOD(SoapHeader, SoapHeader)
  689. {
  690. zval *data = NULL, *actor = NULL;
  691. char *name, *ns;
  692. size_t name_len, ns_len;
  693. zend_bool must_understand = 0;
  694. zval *this_ptr;
  695. if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "ss|zbz", &ns, &ns_len, &name, &name_len, &data, &must_understand, &actor) == FAILURE) {
  696. return;
  697. }
  698. if (ns_len == 0) {
  699. php_error_docref(NULL, E_WARNING, "Invalid namespace");
  700. return;
  701. }
  702. if (name_len == 0) {
  703. php_error_docref(NULL, E_WARNING, "Invalid header name");
  704. return;
  705. }
  706. this_ptr = getThis();
  707. add_property_stringl(this_ptr, "namespace", ns, ns_len);
  708. add_property_stringl(this_ptr, "name", name, name_len);
  709. if (data) {
  710. add_property_zval(this_ptr, "data", data);
  711. }
  712. add_property_bool(this_ptr, "mustUnderstand", must_understand);
  713. if (actor == NULL) {
  714. } else if (Z_TYPE_P(actor) == IS_LONG &&
  715. (Z_LVAL_P(actor) == SOAP_ACTOR_NEXT ||
  716. Z_LVAL_P(actor) == SOAP_ACTOR_NONE ||
  717. Z_LVAL_P(actor) == SOAP_ACTOR_UNLIMATERECEIVER)) {
  718. add_property_long(this_ptr, "actor", Z_LVAL_P(actor));
  719. } else if (Z_TYPE_P(actor) == IS_STRING && Z_STRLEN_P(actor) > 0) {
  720. add_property_stringl(this_ptr, "actor", Z_STRVAL_P(actor), Z_STRLEN_P(actor));
  721. } else {
  722. php_error_docref(NULL, E_WARNING, "Invalid actor");
  723. }
  724. }
  725. /* }}} */
  726. /* {{{ proto object SoapFault::SoapFault(string faultcode, string faultstring [, string faultactor [, mixed detail [, string faultname [, mixed headerfault]]]])
  727. SoapFault constructor */
  728. PHP_METHOD(SoapFault, SoapFault)
  729. {
  730. char *fault_string = NULL, *fault_code = NULL, *fault_actor = NULL, *name = NULL, *fault_code_ns = NULL;
  731. size_t fault_string_len, fault_actor_len = 0, name_len = 0, fault_code_len = 0;
  732. zval *code = NULL, *details = NULL, *headerfault = NULL, *this_ptr;
  733. if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs|s!z!s!z",
  734. &code,
  735. &fault_string, &fault_string_len,
  736. &fault_actor, &fault_actor_len,
  737. &details, &name, &name_len, &headerfault) == FAILURE) {
  738. return;
  739. }
  740. if (Z_TYPE_P(code) == IS_NULL) {
  741. } else if (Z_TYPE_P(code) == IS_STRING) {
  742. fault_code = Z_STRVAL_P(code);
  743. fault_code_len = Z_STRLEN_P(code);
  744. } else if (Z_TYPE_P(code) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(code)) == 2) {
  745. zval *t_ns = zend_hash_index_find(Z_ARRVAL_P(code), 0);
  746. zval *t_code = zend_hash_index_find(Z_ARRVAL_P(code), 1);
  747. if (t_ns && t_code && Z_TYPE_P(t_ns) == IS_STRING && Z_TYPE_P(t_code) == IS_STRING) {
  748. fault_code_ns = Z_STRVAL_P(t_ns);
  749. fault_code = Z_STRVAL_P(t_code);
  750. fault_code_len = Z_STRLEN_P(t_code);
  751. } else {
  752. php_error_docref(NULL, E_WARNING, "Invalid fault code");
  753. return;
  754. }
  755. } else {
  756. php_error_docref(NULL, E_WARNING, "Invalid fault code");
  757. return;
  758. }
  759. if (fault_code != NULL && fault_code_len == 0) {
  760. php_error_docref(NULL, E_WARNING, "Invalid fault code");
  761. return;
  762. }
  763. if (name != NULL && name_len == 0) {
  764. name = NULL;
  765. }
  766. this_ptr = getThis();
  767. set_soap_fault(this_ptr, fault_code_ns, fault_code, fault_string, fault_actor, details, name);
  768. if (headerfault != NULL) {
  769. add_property_zval(this_ptr, "headerfault", headerfault);
  770. }
  771. }
  772. /* }}} */
  773. /* {{{ proto object SoapFault::SoapFault(string faultcode, string faultstring [, string faultactor [, mixed detail [, string faultname [, mixed headerfault]]]])
  774. SoapFault constructor */
  775. PHP_METHOD(SoapFault, __toString)
  776. {
  777. zval *faultcode, *faultstring, *file, *line, trace, rv1, rv2, rv3, rv4;
  778. zend_string *str;
  779. zend_fcall_info fci;
  780. zval *this_ptr;
  781. zend_string *faultcode_val, *faultstring_val, *file_val;
  782. zend_long line_val;
  783. if (zend_parse_parameters_none() == FAILURE) {
  784. return;
  785. }
  786. this_ptr = getThis();
  787. faultcode = zend_read_property(soap_fault_class_entry, this_ptr, "faultcode", sizeof("faultcode")-1, 1, &rv1);
  788. faultstring = zend_read_property(soap_fault_class_entry, this_ptr, "faultstring", sizeof("faultstring")-1, 1, &rv2);
  789. file = zend_read_property(soap_fault_class_entry, this_ptr, "file", sizeof("file")-1, 1, &rv3);
  790. line = zend_read_property(soap_fault_class_entry, this_ptr, "line", sizeof("line")-1, 1, &rv4);
  791. fci.size = sizeof(fci);
  792. ZVAL_STRINGL(&fci.function_name, "gettraceasstring", sizeof("gettraceasstring")-1);
  793. fci.object = Z_OBJ(EX(This));
  794. fci.retval = &trace;
  795. fci.param_count = 0;
  796. fci.params = NULL;
  797. fci.no_separation = 1;
  798. zend_call_function(&fci, NULL);
  799. zval_ptr_dtor(&fci.function_name);
  800. faultcode_val = zval_get_string(faultcode);
  801. faultstring_val = zval_get_string(faultstring);
  802. file_val = zval_get_string(file);
  803. line_val = zval_get_long(line);
  804. convert_to_string(&trace);
  805. str = strpprintf(0, "SoapFault exception: [%s] %s in %s:" ZEND_LONG_FMT "\nStack trace:\n%s",
  806. ZSTR_VAL(faultcode_val), ZSTR_VAL(faultstring_val), ZSTR_VAL(file_val), line_val,
  807. Z_STRLEN(trace) ? Z_STRVAL(trace) : "#0 {main}\n");
  808. zend_string_release_ex(file_val, 0);
  809. zend_string_release_ex(faultstring_val, 0);
  810. zend_string_release_ex(faultcode_val, 0);
  811. zval_ptr_dtor(&trace);
  812. RETVAL_STR(str);
  813. }
  814. /* }}} */
  815. /* {{{ proto object SoapVar::SoapVar(mixed data, int encoding [, string type_name [, string type_namespace [, string node_name [, string node_namespace]]]])
  816. SoapVar constructor */
  817. PHP_METHOD(SoapVar, SoapVar)
  818. {
  819. zval *data, *type, *this_ptr;
  820. char *stype = NULL, *ns = NULL, *name = NULL, *namens = NULL;
  821. size_t stype_len = 0, ns_len = 0, name_len = 0, namens_len = 0;
  822. if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z!z|ssss", &data, &type, &stype, &stype_len, &ns, &ns_len, &name, &name_len, &namens, &namens_len) == FAILURE) {
  823. return;
  824. }
  825. this_ptr = getThis();
  826. if (Z_TYPE_P(type) == IS_NULL) {
  827. add_property_long(this_ptr, "enc_type", UNKNOWN_TYPE);
  828. } else {
  829. if (zend_hash_index_exists(&SOAP_GLOBAL(defEncIndex), Z_LVAL_P(type))) {
  830. add_property_long(this_ptr, "enc_type", Z_LVAL_P(type));
  831. } else {
  832. php_error_docref(NULL, E_WARNING, "Invalid type ID");
  833. return;
  834. }
  835. }
  836. if (data) {
  837. add_property_zval(this_ptr, "enc_value", data);
  838. }
  839. if (stype && stype_len > 0) {
  840. add_property_stringl(this_ptr, "enc_stype", stype, stype_len);
  841. }
  842. if (ns && ns_len > 0) {
  843. add_property_stringl(this_ptr, "enc_ns", ns, ns_len);
  844. }
  845. if (name && name_len > 0) {
  846. add_property_stringl(this_ptr, "enc_name", name, name_len);
  847. }
  848. if (namens && namens_len > 0) {
  849. add_property_stringl(this_ptr, "enc_namens", namens, namens_len);
  850. }
  851. }
  852. /* }}} */
  853. static HashTable* soap_create_typemap(sdlPtr sdl, HashTable *ht) /* {{{ */
  854. {
  855. zval *tmp;
  856. HashTable *ht2;
  857. HashTable *typemap = NULL;
  858. ZEND_HASH_FOREACH_VAL(ht, tmp) {
  859. char *type_name = NULL;
  860. char *type_ns = NULL;
  861. zval *to_xml = NULL;
  862. zval *to_zval = NULL;
  863. encodePtr enc, new_enc;
  864. zend_string *name;
  865. if (Z_TYPE_P(tmp) != IS_ARRAY) {
  866. php_error_docref(NULL, E_WARNING, "Wrong 'typemap' option");
  867. return NULL;
  868. }
  869. ht2 = Z_ARRVAL_P(tmp);
  870. ZEND_HASH_FOREACH_STR_KEY_VAL(ht2, name, tmp) {
  871. if (name) {
  872. if (ZSTR_LEN(name) == sizeof("type_name")-1 &&
  873. strncmp(ZSTR_VAL(name), "type_name", sizeof("type_name")-1) == 0) {
  874. if (Z_TYPE_P(tmp) == IS_STRING) {
  875. type_name = Z_STRVAL_P(tmp);
  876. } else if (Z_TYPE_P(tmp) != IS_NULL) {
  877. }
  878. } else if (ZSTR_LEN(name) == sizeof("type_ns")-1 &&
  879. strncmp(ZSTR_VAL(name), "type_ns", sizeof("type_ns")-1) == 0) {
  880. if (Z_TYPE_P(tmp) == IS_STRING) {
  881. type_ns = Z_STRVAL_P(tmp);
  882. } else if (Z_TYPE_P(tmp) != IS_NULL) {
  883. }
  884. } else if (ZSTR_LEN(name) == sizeof("to_xml")-1 &&
  885. strncmp(ZSTR_VAL(name), "to_xml", sizeof("to_xml")-1) == 0) {
  886. to_xml = tmp;
  887. } else if (ZSTR_LEN(name) == sizeof("from_xml")-1 &&
  888. strncmp(ZSTR_VAL(name), "from_xml", sizeof("from_xml")-1) == 0) {
  889. to_zval = tmp;
  890. }
  891. }
  892. } ZEND_HASH_FOREACH_END();
  893. if (type_name) {
  894. smart_str nscat = {0};
  895. if (type_ns) {
  896. enc = get_encoder(sdl, type_ns, type_name);
  897. } else {
  898. enc = get_encoder_ex(sdl, type_name, strlen(type_name));
  899. }
  900. new_enc = emalloc(sizeof(encode));
  901. memset(new_enc, 0, sizeof(encode));
  902. if (enc) {
  903. new_enc->details.type = enc->details.type;
  904. new_enc->details.ns = estrdup(enc->details.ns);
  905. new_enc->details.type_str = estrdup(enc->details.type_str);
  906. new_enc->details.sdl_type = enc->details.sdl_type;
  907. } else {
  908. enc = get_conversion(UNKNOWN_TYPE);
  909. new_enc->details.type = enc->details.type;
  910. if (type_ns) {
  911. new_enc->details.ns = estrdup(type_ns);
  912. }
  913. new_enc->details.type_str = estrdup(type_name);
  914. }
  915. new_enc->to_xml = enc->to_xml;
  916. new_enc->to_zval = enc->to_zval;
  917. new_enc->details.map = emalloc(sizeof(soapMapping));
  918. memset(new_enc->details.map, 0, sizeof(soapMapping));
  919. if (to_xml) {
  920. ZVAL_COPY(&new_enc->details.map->to_xml, to_xml);
  921. new_enc->to_xml = to_xml_user;
  922. } else if (enc->details.map && Z_TYPE(enc->details.map->to_xml) != IS_UNDEF) {
  923. ZVAL_COPY(&new_enc->details.map->to_xml, &enc->details.map->to_xml);
  924. }
  925. if (to_zval) {
  926. ZVAL_COPY(&new_enc->details.map->to_zval, to_zval);
  927. new_enc->to_zval = to_zval_user;
  928. } else if (enc->details.map && Z_TYPE(enc->details.map->to_zval) != IS_UNDEF) {
  929. ZVAL_COPY(&new_enc->details.map->to_zval, &enc->details.map->to_zval);
  930. }
  931. if (!typemap) {
  932. typemap = emalloc(sizeof(HashTable));
  933. zend_hash_init(typemap, 0, NULL, delete_encoder, 0);
  934. }
  935. if (type_ns) {
  936. smart_str_appends(&nscat, type_ns);
  937. smart_str_appendc(&nscat, ':');
  938. }
  939. smart_str_appends(&nscat, type_name);
  940. smart_str_0(&nscat);
  941. zend_hash_update_ptr(typemap, nscat.s, new_enc);
  942. smart_str_free(&nscat);
  943. }
  944. } ZEND_HASH_FOREACH_END();
  945. return typemap;
  946. }
  947. /* }}} */
  948. /* {{{ proto object SoapServer::SoapServer(mixed wsdl [, array options])
  949. SoapServer constructor */
  950. PHP_METHOD(SoapServer, SoapServer)
  951. {
  952. soapServicePtr service;
  953. zval *wsdl = NULL, *options = NULL;
  954. zend_resource *res;
  955. int version = SOAP_1_1;
  956. zend_long cache_wsdl;
  957. HashTable *typemap_ht = NULL;
  958. SOAP_SERVER_BEGIN_CODE();
  959. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a", &wsdl, &options) == FAILURE) {
  960. php_error_docref(NULL, E_ERROR, "Invalid parameters");
  961. }
  962. if (Z_TYPE_P(wsdl) != IS_STRING && Z_TYPE_P(wsdl) != IS_NULL) {
  963. php_error_docref(NULL, E_ERROR, "Invalid parameters");
  964. }
  965. service = emalloc(sizeof(soapService));
  966. memset(service, 0, sizeof(soapService));
  967. service->send_errors = 1;
  968. cache_wsdl = SOAP_GLOBAL(cache_enabled) ? SOAP_GLOBAL(cache_mode) : 0;
  969. if (options != NULL) {
  970. HashTable *ht = Z_ARRVAL_P(options);
  971. zval *tmp;
  972. if ((tmp = zend_hash_str_find(ht, "soap_version", sizeof("soap_version")-1)) != NULL) {
  973. if (Z_TYPE_P(tmp) == IS_LONG &&
  974. (Z_LVAL_P(tmp) == SOAP_1_1 || Z_LVAL_P(tmp) == SOAP_1_2)) {
  975. version = Z_LVAL_P(tmp);
  976. } else {
  977. php_error_docref(NULL, E_ERROR, "'soap_version' option must be SOAP_1_1 or SOAP_1_2");
  978. }
  979. }
  980. if ((tmp = zend_hash_str_find(ht, "uri", sizeof("uri")-1)) != NULL &&
  981. Z_TYPE_P(tmp) == IS_STRING) {
  982. service->uri = estrndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  983. } else if (Z_TYPE_P(wsdl) == IS_NULL) {
  984. php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
  985. }
  986. if ((tmp = zend_hash_str_find(ht, "actor", sizeof("actor")-1)) != NULL &&
  987. Z_TYPE_P(tmp) == IS_STRING) {
  988. service->actor = estrndup(Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  989. }
  990. if ((tmp = zend_hash_str_find(ht, "encoding", sizeof("encoding")-1)) != NULL &&
  991. Z_TYPE_P(tmp) == IS_STRING) {
  992. xmlCharEncodingHandlerPtr encoding;
  993. encoding = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
  994. if (encoding == NULL) {
  995. php_error_docref(NULL, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_P(tmp));
  996. } else {
  997. service->encoding = encoding;
  998. }
  999. }
  1000. if ((tmp = zend_hash_str_find(ht, "classmap", sizeof("classmap")-1)) != NULL &&
  1001. Z_TYPE_P(tmp) == IS_ARRAY) {
  1002. service->class_map = zend_array_dup(Z_ARRVAL_P(tmp));
  1003. }
  1004. if ((tmp = zend_hash_str_find(ht, "typemap", sizeof("typemap")-1)) != NULL &&
  1005. Z_TYPE_P(tmp) == IS_ARRAY &&
  1006. zend_hash_num_elements(Z_ARRVAL_P(tmp)) > 0) {
  1007. typemap_ht = Z_ARRVAL_P(tmp);
  1008. }
  1009. if ((tmp = zend_hash_str_find(ht, "features", sizeof("features")-1)) != NULL &&
  1010. Z_TYPE_P(tmp) == IS_LONG) {
  1011. service->features = Z_LVAL_P(tmp);
  1012. }
  1013. if ((tmp = zend_hash_str_find(ht, "cache_wsdl", sizeof("cache_wsdl")-1)) != NULL &&
  1014. Z_TYPE_P(tmp) == IS_LONG) {
  1015. cache_wsdl = Z_LVAL_P(tmp);
  1016. }
  1017. if ((tmp = zend_hash_str_find(ht, "send_errors", sizeof("send_errors")-1)) != NULL) {
  1018. if (Z_TYPE_P(tmp) == IS_FALSE) {
  1019. service->send_errors = 0;
  1020. } else if (Z_TYPE_P(tmp) == IS_TRUE) {
  1021. service->send_errors = 1;
  1022. } else if (Z_TYPE_P(tmp) == IS_LONG) {
  1023. service->send_errors = Z_LVAL_P(tmp);
  1024. }
  1025. }
  1026. } else if (Z_TYPE_P(wsdl) == IS_NULL) {
  1027. php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
  1028. }
  1029. service->version = version;
  1030. service->type = SOAP_FUNCTIONS;
  1031. service->soap_functions.functions_all = FALSE;
  1032. service->soap_functions.ft = zend_new_array(0);
  1033. if (Z_TYPE_P(wsdl) != IS_NULL) {
  1034. service->sdl = get_sdl(getThis(), Z_STRVAL_P(wsdl), cache_wsdl);
  1035. if (service->uri == NULL) {
  1036. if (service->sdl->target_ns) {
  1037. service->uri = estrdup(service->sdl->target_ns);
  1038. } else {
  1039. /*FIXME*/
  1040. service->uri = estrdup("http://unknown-uri/");
  1041. }
  1042. }
  1043. }
  1044. if (typemap_ht) {
  1045. service->typemap = soap_create_typemap(service->sdl, typemap_ht);
  1046. }
  1047. res = zend_register_resource(service, le_service);
  1048. add_property_resource(getThis(), "service", res);
  1049. SOAP_SERVER_END_CODE();
  1050. }
  1051. /* }}} */
  1052. /* {{{ proto object SoapServer::setPersistence(int mode )
  1053. Sets persistence mode of SoapServer */
  1054. PHP_METHOD(SoapServer, setPersistence)
  1055. {
  1056. soapServicePtr service;
  1057. zend_long value;
  1058. SOAP_SERVER_BEGIN_CODE();
  1059. FETCH_THIS_SERVICE(service);
  1060. if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &value) != FAILURE) {
  1061. if (service->type == SOAP_CLASS) {
  1062. if (value == SOAP_PERSISTENCE_SESSION ||
  1063. value == SOAP_PERSISTENCE_REQUEST) {
  1064. service->soap_class.persistence = value;
  1065. } else {
  1066. php_error_docref(NULL, E_WARNING, "Tried to set persistence with bogus value (" ZEND_LONG_FMT ")", value);
  1067. return;
  1068. }
  1069. } else {
  1070. php_error_docref(NULL, E_WARNING, "Tried to set persistence when you are using you SOAP SERVER in function mode, no persistence needed");
  1071. return;
  1072. }
  1073. }
  1074. SOAP_SERVER_END_CODE();
  1075. }
  1076. /* }}} */
  1077. /* {{{ proto void SoapServer::setClass(string class_name [, mixed args])
  1078. Sets class which will handle SOAP requests */
  1079. PHP_METHOD(SoapServer, setClass)
  1080. {
  1081. soapServicePtr service;
  1082. zend_string *classname;
  1083. zend_class_entry *ce;
  1084. int num_args = 0;
  1085. zval *argv = NULL;
  1086. SOAP_SERVER_BEGIN_CODE();
  1087. FETCH_THIS_SERVICE(service);
  1088. if (zend_parse_parameters(ZEND_NUM_ARGS(), "S*", &classname, &argv, &num_args) == FAILURE) {
  1089. return;
  1090. }
  1091. ce = zend_lookup_class(classname);
  1092. if (ce) {
  1093. service->type = SOAP_CLASS;
  1094. service->soap_class.ce = ce;
  1095. service->soap_class.persistence = SOAP_PERSISTENCE_REQUEST;
  1096. service->soap_class.argc = num_args;
  1097. if (service->soap_class.argc > 0) {
  1098. int i;
  1099. service->soap_class.argv = safe_emalloc(sizeof(zval), service->soap_class.argc, 0);
  1100. for (i = 0;i < service->soap_class.argc;i++) {
  1101. ZVAL_COPY(&service->soap_class.argv[i], &argv[i]);
  1102. }
  1103. }
  1104. } else {
  1105. php_error_docref(NULL, E_WARNING, "Tried to set a non existent class (%s)", ZSTR_VAL(classname));
  1106. return;
  1107. }
  1108. SOAP_SERVER_END_CODE();
  1109. }
  1110. /* }}} */
  1111. /* {{{ proto void SoapServer::setObject(object obj)
  1112. Sets object which will handle SOAP requests */
  1113. PHP_METHOD(SoapServer, setObject)
  1114. {
  1115. soapServicePtr service;
  1116. zval *obj;
  1117. SOAP_SERVER_BEGIN_CODE();
  1118. FETCH_THIS_SERVICE(service);
  1119. if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &obj) == FAILURE) {
  1120. return;
  1121. }
  1122. service->type = SOAP_OBJECT;
  1123. ZVAL_COPY(&service->soap_object, obj);
  1124. SOAP_SERVER_END_CODE();
  1125. }
  1126. /* }}} */
  1127. /* {{{ proto array SoapServer::getFunctions(void)
  1128. Returns list of defined functions */
  1129. PHP_METHOD(SoapServer, getFunctions)
  1130. {
  1131. soapServicePtr service;
  1132. HashTable *ft = NULL;
  1133. SOAP_SERVER_BEGIN_CODE();
  1134. if (zend_parse_parameters_none() == FAILURE) {
  1135. return;
  1136. }
  1137. FETCH_THIS_SERVICE(service);
  1138. array_init(return_value);
  1139. if (service->type == SOAP_OBJECT) {
  1140. ft = &(Z_OBJCE(service->soap_object)->function_table);
  1141. } else if (service->type == SOAP_CLASS) {
  1142. ft = &service->soap_class.ce->function_table;
  1143. } else if (service->soap_functions.functions_all == TRUE) {
  1144. ft = EG(function_table);
  1145. } else if (service->soap_functions.ft != NULL) {
  1146. zval *name;
  1147. ZEND_HASH_FOREACH_VAL(service->soap_functions.ft, name) {
  1148. add_next_index_str(return_value, zend_string_copy(Z_STR_P(name)));
  1149. } ZEND_HASH_FOREACH_END();
  1150. }
  1151. if (ft != NULL) {
  1152. zend_function *f;
  1153. ZEND_HASH_FOREACH_PTR(ft, f) {
  1154. if ((service->type != SOAP_OBJECT && service->type != SOAP_CLASS) || (f->common.fn_flags & ZEND_ACC_PUBLIC)) {
  1155. add_next_index_str(return_value, zend_string_copy(f->common.function_name));
  1156. }
  1157. } ZEND_HASH_FOREACH_END();
  1158. }
  1159. SOAP_SERVER_END_CODE();
  1160. }
  1161. /* }}} */
  1162. /* {{{ proto void SoapServer::addFunction(mixed functions)
  1163. Adds one or several functions those will handle SOAP requests */
  1164. PHP_METHOD(SoapServer, addFunction)
  1165. {
  1166. soapServicePtr service;
  1167. zval *function_name, function_copy;
  1168. SOAP_SERVER_BEGIN_CODE();
  1169. FETCH_THIS_SERVICE(service);
  1170. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &function_name) == FAILURE) {
  1171. return;
  1172. }
  1173. /* TODO: could use zend_is_callable here */
  1174. if (Z_TYPE_P(function_name) == IS_ARRAY) {
  1175. if (service->type == SOAP_FUNCTIONS) {
  1176. zval *tmp_function;
  1177. if (service->soap_functions.ft == NULL) {
  1178. service->soap_functions.functions_all = FALSE;
  1179. service->soap_functions.ft = zend_new_array(zend_hash_num_elements(Z_ARRVAL_P(function_name)));
  1180. }
  1181. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(function_name), tmp_function) {
  1182. zend_string *key;
  1183. zend_function *f;
  1184. if (Z_TYPE_P(tmp_function) != IS_STRING) {
  1185. php_error_docref(NULL, E_WARNING, "Tried to add a function that isn't a string");
  1186. return;
  1187. }
  1188. key = zend_string_tolower(Z_STR_P(tmp_function));
  1189. if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
  1190. php_error_docref(NULL, E_WARNING, "Tried to add a non existent function '%s'", Z_STRVAL_P(tmp_function));
  1191. return;
  1192. }
  1193. ZVAL_STR_COPY(&function_copy, f->common.function_name);
  1194. zend_hash_update(service->soap_functions.ft, key, &function_copy);
  1195. zend_string_release_ex(key, 0);
  1196. } ZEND_HASH_FOREACH_END();
  1197. }
  1198. } else if (Z_TYPE_P(function_name) == IS_STRING) {
  1199. zend_string *key;
  1200. zend_function *f;
  1201. key = zend_string_tolower(Z_STR_P(function_name));
  1202. if ((f = zend_hash_find_ptr(EG(function_table), key)) == NULL) {
  1203. php_error_docref(NULL, E_WARNING, "Tried to add a non existent function '%s'", Z_STRVAL_P(function_name));
  1204. return;
  1205. }
  1206. if (service->soap_functions.ft == NULL) {
  1207. service->soap_functions.functions_all = FALSE;
  1208. service->soap_functions.ft = zend_new_array(0);
  1209. }
  1210. ZVAL_STR_COPY(&function_copy, f->common.function_name);
  1211. zend_hash_update(service->soap_functions.ft, key, &function_copy);
  1212. zend_string_release_ex(key, 0);
  1213. } else if (Z_TYPE_P(function_name) == IS_LONG) {
  1214. if (Z_LVAL_P(function_name) == SOAP_FUNCTIONS_ALL) {
  1215. if (service->soap_functions.ft != NULL) {
  1216. zend_hash_destroy(service->soap_functions.ft);
  1217. efree(service->soap_functions.ft);
  1218. service->soap_functions.ft = NULL;
  1219. }
  1220. service->soap_functions.functions_all = TRUE;
  1221. } else {
  1222. php_error_docref(NULL, E_WARNING, "Invalid value passed");
  1223. return;
  1224. }
  1225. }
  1226. SOAP_SERVER_END_CODE();
  1227. }
  1228. /* }}} */
  1229. static void _soap_server_exception(soapServicePtr service, sdlFunctionPtr function, zval *this_ptr) /* {{{ */
  1230. {
  1231. zval exception_object;
  1232. ZVAL_OBJ(&exception_object, EG(exception));
  1233. if (instanceof_function(Z_OBJCE(exception_object), soap_fault_class_entry)) {
  1234. soap_server_fault_ex(function, &exception_object, NULL);
  1235. } else if (instanceof_function(Z_OBJCE(exception_object), zend_ce_error)) {
  1236. if (service->send_errors) {
  1237. zval rv;
  1238. zend_string *msg = zval_get_string(zend_read_property(zend_ce_error, &exception_object, "message", sizeof("message")-1, 0, &rv));
  1239. add_soap_fault_ex(&exception_object, this_ptr, "Server", ZSTR_VAL(msg), NULL, NULL);
  1240. zend_string_release_ex(msg, 0);
  1241. } else {
  1242. add_soap_fault_ex(&exception_object, this_ptr, "Server", "Internal Error", NULL, NULL);
  1243. }
  1244. soap_server_fault_ex(function, &exception_object, NULL);
  1245. }
  1246. }
  1247. /* }}} */
  1248. /* {{{ proto void SoapServer::handle([string soap_request])
  1249. Handles a SOAP request */
  1250. PHP_METHOD(SoapServer, handle)
  1251. {
  1252. int soap_version, old_soap_version;
  1253. sdlPtr old_sdl = NULL;
  1254. soapServicePtr service;
  1255. xmlDocPtr doc_request=NULL, doc_return;
  1256. zval function_name, *params, *soap_obj, retval;
  1257. char *fn_name, cont_len[30];
  1258. int num_params = 0, size, i, call_status = 0;
  1259. xmlChar *buf;
  1260. HashTable *function_table;
  1261. soapHeader *soap_headers = NULL;
  1262. sdlFunctionPtr function;
  1263. char *arg = NULL;
  1264. size_t arg_len = 0;
  1265. xmlCharEncodingHandlerPtr old_encoding;
  1266. HashTable *old_class_map, *old_typemap;
  1267. int old_features;
  1268. zval tmp_soap;
  1269. SOAP_SERVER_BEGIN_CODE();
  1270. FETCH_THIS_SERVICE(service);
  1271. SOAP_GLOBAL(soap_version) = service->version;
  1272. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &arg, &arg_len) == FAILURE) {
  1273. return;
  1274. }
  1275. if (ZEND_NUM_ARGS() > 0 && ZEND_SIZE_T_INT_OVFL(arg_len)) {
  1276. soap_server_fault("Server", "Input string is too long", NULL, NULL, NULL);
  1277. return;
  1278. }
  1279. if (SG(request_info).request_method &&
  1280. strcmp(SG(request_info).request_method, "GET") == 0 &&
  1281. SG(request_info).query_string &&
  1282. stricmp(SG(request_info).query_string, "wsdl") == 0) {
  1283. if (service->sdl) {
  1284. /*
  1285. char *hdr = emalloc(sizeof("Location: ")+strlen(service->sdl->source));
  1286. strcpy(hdr,"Location: ");
  1287. strcat(hdr,service->sdl->source);
  1288. sapi_add_header(hdr, sizeof("Location: ")+strlen(service->sdl->source)-1, 1);
  1289. efree(hdr);
  1290. */
  1291. zval readfile, readfile_ret, param;
  1292. sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
  1293. ZVAL_STRING(&param, service->sdl->source);
  1294. ZVAL_STRING(&readfile, "readfile");
  1295. if (call_user_function(EG(function_table), NULL, &readfile, &readfile_ret, 1, &param ) == FAILURE) {
  1296. soap_server_fault("Server", "Couldn't find WSDL", NULL, NULL, NULL);
  1297. }
  1298. zval_ptr_dtor(&param);
  1299. zval_ptr_dtor_str(&readfile);
  1300. zval_ptr_dtor(&readfile_ret);
  1301. SOAP_SERVER_END_CODE();
  1302. return;
  1303. } else {
  1304. soap_server_fault("Server", "WSDL generation is not supported yet", NULL, NULL, NULL);
  1305. /*
  1306. sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8"), 1);
  1307. PUTS("<?xml version=\"1.0\" ?>\n<definitions\n");
  1308. PUTS(" xmlns=\"http://schemas.xmlsoap.org/wsdl/\"\n");
  1309. PUTS(" targetNamespace=\"");
  1310. PUTS(service->uri);
  1311. PUTS("\">\n");
  1312. PUTS("</definitions>");
  1313. */
  1314. SOAP_SERVER_END_CODE();
  1315. return;
  1316. }
  1317. }
  1318. ZVAL_NULL(&retval);
  1319. if (php_output_start_default() != SUCCESS) {
  1320. php_error_docref(NULL, E_ERROR,"ob_start failed");
  1321. }
  1322. if (ZEND_NUM_ARGS() == 0) {
  1323. if (SG(request_info).request_body && 0 == php_stream_rewind(SG(request_info).request_body)) {
  1324. zval *server_vars, *encoding;
  1325. php_stream_filter *zf = NULL;
  1326. zend_string *server = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
  1327. zend_is_auto_global(server);
  1328. if ((server_vars = zend_hash_find(&EG(symbol_table), server)) != NULL &&
  1329. Z_TYPE_P(server_vars) == IS_ARRAY &&
  1330. (encoding = zend_hash_str_find(Z_ARRVAL_P(server_vars), "HTTP_CONTENT_ENCODING", sizeof("HTTP_CONTENT_ENCODING")-1)) != NULL &&
  1331. Z_TYPE_P(encoding) == IS_STRING) {
  1332. if (strcmp(Z_STRVAL_P(encoding),"gzip") == 0
  1333. || strcmp(Z_STRVAL_P(encoding),"x-gzip") == 0
  1334. || strcmp(Z_STRVAL_P(encoding),"deflate") == 0
  1335. ) {
  1336. zval filter_params;
  1337. array_init_size(&filter_params, 1);
  1338. add_assoc_long_ex(&filter_params, "window", sizeof("window")-1, 0x2f); /* ANY WBITS */
  1339. zf = php_stream_filter_create("zlib.inflate", &filter_params, 0);
  1340. zend_array_destroy(Z_ARR(filter_params));
  1341. if (zf) {
  1342. php_stream_filter_append(&SG(request_info).request_body->readfilters, zf);
  1343. } else {
  1344. php_error_docref(NULL, E_WARNING,"Can't uncompress compressed request");
  1345. zend_string_release_ex(server, 0);
  1346. return;
  1347. }
  1348. } else {
  1349. php_error_docref(NULL, E_WARNING,"Request is compressed with unknown compression '%s'",Z_STRVAL_P(encoding));
  1350. zend_string_release_ex(server, 0);
  1351. return;
  1352. }
  1353. }
  1354. zend_string_release_ex(server, 0);
  1355. doc_request = soap_xmlParseFile("php://input");
  1356. if (zf) {
  1357. php_stream_filter_remove(zf, 1);
  1358. }
  1359. } else {
  1360. zval_ptr_dtor(&retval);
  1361. return;
  1362. }
  1363. } else {
  1364. doc_request = soap_xmlParseMemory(arg,arg_len);
  1365. }
  1366. if (doc_request == NULL) {
  1367. soap_server_fault("Client", "Bad Request", NULL, NULL, NULL);
  1368. }
  1369. if (xmlGetIntSubset(doc_request) != NULL) {
  1370. xmlNodePtr env = get_node(doc_request->children,"Envelope");
  1371. if (env && env->ns) {
  1372. if (strcmp((char*)env->ns->href, SOAP_1_1_ENV_NAMESPACE) == 0) {
  1373. SOAP_GLOBAL(soap_version) = SOAP_1_1;
  1374. } else if (strcmp((char*)env->ns->href,SOAP_1_2_ENV_NAMESPACE) == 0) {
  1375. SOAP_GLOBAL(soap_version) = SOAP_1_2;
  1376. }
  1377. }
  1378. xmlFreeDoc(doc_request);
  1379. soap_server_fault("Server", "DTD are not supported by SOAP", NULL, NULL, NULL);
  1380. }
  1381. old_sdl = SOAP_GLOBAL(sdl);
  1382. SOAP_GLOBAL(sdl) = service->sdl;
  1383. old_encoding = SOAP_GLOBAL(encoding);
  1384. SOAP_GLOBAL(encoding) = service->encoding;
  1385. old_class_map = SOAP_GLOBAL(class_map);
  1386. SOAP_GLOBAL(class_map) = service->class_map;
  1387. old_typemap = SOAP_GLOBAL(typemap);
  1388. SOAP_GLOBAL(typemap) = service->typemap;
  1389. old_features = SOAP_GLOBAL(features);
  1390. SOAP_GLOBAL(features) = service->features;
  1391. old_soap_version = SOAP_GLOBAL(soap_version);
  1392. function = deserialize_function_call(service->sdl, doc_request, service->actor, &function_name, &num_params, &params, &soap_version, &soap_headers);
  1393. xmlFreeDoc(doc_request);
  1394. if (EG(exception)) {
  1395. php_output_discard();
  1396. _soap_server_exception(service, function, getThis());
  1397. goto fail;
  1398. }
  1399. service->soap_headers_ptr = &soap_headers;
  1400. soap_obj = NULL;
  1401. if (service->type == SOAP_OBJECT) {
  1402. soap_obj = &service->soap_object;
  1403. function_table = &((Z_OBJCE_P(soap_obj))->function_table);
  1404. } else if (service->type == SOAP_CLASS) {
  1405. #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  1406. /* If persistent then set soap_obj from from the previous created session (if available) */
  1407. if (service->soap_class.persistence == SOAP_PERSISTENCE_SESSION) {
  1408. zval *session_vars, *tmp_soap_p;
  1409. if (PS(session_status) != php_session_active &&
  1410. PS(session_status) != php_session_disabled) {
  1411. php_session_start();
  1412. }
  1413. /* Find the soap object and assign */
  1414. session_vars = &PS(http_session_vars);
  1415. ZVAL_DEREF(session_vars);
  1416. if (Z_TYPE_P(session_vars) == IS_ARRAY &&
  1417. (tmp_soap_p = zend_hash_str_find(Z_ARRVAL_P(session_vars), "_bogus_session_name", sizeof("_bogus_session_name")-1)) != NULL &&
  1418. Z_TYPE_P(tmp_soap_p) == IS_OBJECT &&
  1419. Z_OBJCE_P(tmp_soap_p) == service->soap_class.ce) {
  1420. soap_obj = tmp_soap_p;
  1421. }
  1422. }
  1423. #endif
  1424. /* If new session or something weird happned */
  1425. if (soap_obj == NULL) {
  1426. object_init_ex(&tmp_soap, service->soap_class.ce);
  1427. /* Call constructor */
  1428. if (zend_hash_str_exists(&Z_OBJCE(tmp_soap)->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1)) {
  1429. zval c_ret, constructor;
  1430. ZVAL_STRING(&constructor, ZEND_CONSTRUCTOR_FUNC_NAME);
  1431. if (call_user_function(NULL, &tmp_soap, &constructor, &c_ret, service->soap_class.argc, service->soap_class.argv) == FAILURE) {
  1432. php_error_docref(NULL, E_ERROR, "Error calling constructor");
  1433. }
  1434. if (EG(exception)) {
  1435. php_output_discard();
  1436. _soap_server_exception(service, function, getThis());
  1437. zval_ptr_dtor_str(&constructor);
  1438. zval_ptr_dtor(&c_ret);
  1439. zval_ptr_dtor(&tmp_soap);
  1440. goto fail;
  1441. }
  1442. zval_ptr_dtor_str(&constructor);
  1443. zval_ptr_dtor(&c_ret);
  1444. } else {
  1445. int class_name_len = ZSTR_LEN(service->soap_class.ce->name);
  1446. char *class_name = emalloc(class_name_len+1);
  1447. memcpy(class_name, ZSTR_VAL(service->soap_class.ce->name), class_name_len+1);
  1448. if (zend_hash_str_exists(&Z_OBJCE(tmp_soap)->function_table, php_strtolower(class_name, class_name_len), class_name_len)) {
  1449. zval c_ret, constructor;
  1450. ZVAL_STR_COPY(&constructor, service->soap_class.ce->name);
  1451. if (call_user_function(NULL, &tmp_soap, &constructor, &c_ret, service->soap_class.argc, service->soap_class.argv) == FAILURE) {
  1452. php_error_docref(NULL, E_ERROR, "Error calling constructor");
  1453. }
  1454. if (EG(exception)) {
  1455. php_output_discard();
  1456. _soap_server_exception(service, function, getThis());
  1457. zval_ptr_dtor_str(&constructor);
  1458. zval_ptr_dtor(&c_ret);
  1459. efree(class_name);
  1460. zval_ptr_dtor(&tmp_soap);
  1461. goto fail;
  1462. }
  1463. zval_ptr_dtor_str(&constructor);
  1464. zval_ptr_dtor(&c_ret);
  1465. }
  1466. efree(class_name);
  1467. }
  1468. #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  1469. /* If session then update session hash with new object */
  1470. if (service->soap_class.persistence == SOAP_PERSISTENCE_SESSION) {
  1471. zval *session_vars = &PS(http_session_vars), *tmp_soap_p;
  1472. ZVAL_DEREF(session_vars);
  1473. if (Z_TYPE_P(session_vars) == IS_ARRAY &&
  1474. (tmp_soap_p = zend_hash_str_update(Z_ARRVAL_P(session_vars), "_bogus_session_name", sizeof("_bogus_session_name")-1, &tmp_soap)) != NULL) {
  1475. soap_obj = tmp_soap_p;
  1476. } else {
  1477. soap_obj = &tmp_soap;
  1478. }
  1479. } else {
  1480. soap_obj = &tmp_soap;
  1481. }
  1482. #else
  1483. soap_obj = &tmp_soap;
  1484. #endif
  1485. }
  1486. function_table = &((Z_OBJCE_P(soap_obj))->function_table);
  1487. } else {
  1488. if (service->soap_functions.functions_all == TRUE) {
  1489. function_table = EG(function_table);
  1490. } else {
  1491. function_table = service->soap_functions.ft;
  1492. }
  1493. }
  1494. doc_return = NULL;
  1495. /* Process soap headers */
  1496. if (soap_headers != NULL) {
  1497. soapHeader *header = soap_headers;
  1498. while (header != NULL) {
  1499. soapHeader *h = header;
  1500. header = header->next;
  1501. #if 0
  1502. if (service->sdl && !h->function && !h->hdr) {
  1503. if (h->mustUnderstand) {
  1504. soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL);
  1505. } else {
  1506. continue;
  1507. }
  1508. }
  1509. #endif
  1510. fn_name = estrndup(Z_STRVAL(h->function_name),Z_STRLEN(h->function_name));
  1511. if (zend_hash_str_exists(function_table, php_strtolower(fn_name, Z_STRLEN(h->function_name)), Z_STRLEN(h->function_name)) ||
  1512. ((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) &&
  1513. zend_hash_str_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
  1514. if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) {
  1515. call_status = call_user_function(NULL, soap_obj, &h->function_name, &h->retval, h->num_params, h->parameters);
  1516. } else {
  1517. call_status = call_user_function(EG(function_table), NULL, &h->function_name, &h->retval, h->num_params, h->parameters);
  1518. }
  1519. if (call_status != SUCCESS) {
  1520. php_error_docref(NULL, E_WARNING, "Function '%s' call failed", Z_STRVAL(h->function_name));
  1521. return;
  1522. }
  1523. if (Z_TYPE(h->retval) == IS_OBJECT &&
  1524. instanceof_function(Z_OBJCE(h->retval), soap_fault_class_entry)) {
  1525. zval *tmp;
  1526. if ((tmp = zend_hash_str_find(Z_OBJPROP(h->retval), "headerfault", sizeof("headerfault")-1)) != NULL &&
  1527. Z_TYPE_P(tmp) != IS_NULL) {
  1528. }
  1529. php_output_discard();
  1530. soap_server_fault_ex(function, &h->retval, h);
  1531. efree(fn_name);
  1532. if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
  1533. goto fail;
  1534. } else if (EG(exception)) {
  1535. php_output_discard();
  1536. _soap_server_exception(service, function, getThis());
  1537. efree(fn_name);
  1538. if (service->type == SOAP_CLASS && soap_obj) {zval_ptr_dtor(soap_obj);}
  1539. goto fail;
  1540. }
  1541. } else if (h->mustUnderstand) {
  1542. soap_server_fault("MustUnderstand","Header not understood", NULL, NULL, NULL);
  1543. }
  1544. efree(fn_name);
  1545. }
  1546. }
  1547. fn_name = estrndup(Z_STRVAL(function_name),Z_STRLEN(function_name));
  1548. if (zend_hash_str_exists(function_table, php_strtolower(fn_name, Z_STRLEN(function_name)), Z_STRLEN(function_name)) ||
  1549. ((service->type == SOAP_CLASS || service->type == SOAP_OBJECT) &&
  1550. zend_hash_str_exists(function_table, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) {
  1551. if (service->type == SOAP_CLASS || service->type == SOAP_OBJECT) {
  1552. call_status = call_user_function(NULL, soap_obj, &function_name, &retval, num_params, params);
  1553. if (service->type == SOAP_CLASS) {
  1554. #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  1555. if (service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {
  1556. zval_ptr_dtor(soap_obj);
  1557. soap_obj = NULL;
  1558. }
  1559. #else
  1560. zval_ptr_dtor(soap_obj);
  1561. soap_obj = NULL;
  1562. #endif
  1563. }
  1564. } else {
  1565. call_status = call_user_function(EG(function_table), NULL, &function_name, &retval, num_params, params);
  1566. }
  1567. } else {
  1568. php_error(E_ERROR, "Function '%s' doesn't exist", Z_STRVAL(function_name));
  1569. }
  1570. efree(fn_name);
  1571. if (EG(exception)) {
  1572. php_output_discard();
  1573. _soap_server_exception(service, function, getThis());
  1574. if (service->type == SOAP_CLASS) {
  1575. #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  1576. if (soap_obj && service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {
  1577. #else
  1578. if (soap_obj) {
  1579. #endif
  1580. zval_ptr_dtor(soap_obj);
  1581. }
  1582. }
  1583. goto fail;
  1584. }
  1585. if (call_status == SUCCESS) {
  1586. char *response_name;
  1587. if (Z_TYPE(retval) == IS_OBJECT &&
  1588. instanceof_function(Z_OBJCE(retval), soap_fault_class_entry)) {
  1589. php_output_discard();
  1590. soap_server_fault_ex(function, &retval, NULL);
  1591. goto fail;
  1592. }
  1593. if (function && function->responseName) {
  1594. response_name = estrdup(function->responseName);
  1595. } else {
  1596. response_name = emalloc(Z_STRLEN(function_name) + sizeof("Response"));
  1597. memcpy(response_name,Z_STRVAL(function_name),Z_STRLEN(function_name));
  1598. memcpy(response_name+Z_STRLEN(function_name),"Response",sizeof("Response"));
  1599. }
  1600. doc_return = serialize_response_call(function, response_name, service->uri, &retval, soap_headers, soap_version);
  1601. efree(response_name);
  1602. } else {
  1603. php_error_docref(NULL, E_WARNING, "Function '%s' call failed", Z_STRVAL(function_name));
  1604. return;
  1605. }
  1606. if (EG(exception)) {
  1607. php_output_discard();
  1608. _soap_server_exception(service, function, getThis());
  1609. if (service->type == SOAP_CLASS) {
  1610. #if HAVE_PHP_SESSION && !defined(COMPILE_DL_SESSION)
  1611. if (soap_obj && service->soap_class.persistence != SOAP_PERSISTENCE_SESSION) {
  1612. #else
  1613. if (soap_obj) {
  1614. #endif
  1615. zval_ptr_dtor(soap_obj);
  1616. }
  1617. }
  1618. goto fail;
  1619. }
  1620. /* Flush buffer */
  1621. php_output_discard();
  1622. if (doc_return) {
  1623. /* xmlDocDumpMemoryEnc(doc_return, &buf, &size, XML_CHAR_ENCODING_UTF8); */
  1624. xmlDocDumpMemory(doc_return, &buf, &size);
  1625. if (size == 0) {
  1626. php_error_docref(NULL, E_ERROR, "Dump memory failed");
  1627. }
  1628. if (soap_version == SOAP_1_2) {
  1629. sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1);
  1630. } else {
  1631. sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
  1632. }
  1633. xmlFreeDoc(doc_return);
  1634. if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
  1635. sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
  1636. } else {
  1637. snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
  1638. sapi_add_header(cont_len, strlen(cont_len), 1);
  1639. }
  1640. php_write(buf, size);
  1641. xmlFree(buf);
  1642. } else {
  1643. sapi_add_header("HTTP/1.1 202 Accepted", sizeof("HTTP/1.1 202 Accepted")-1, 1);
  1644. sapi_add_header("Content-Length: 0", sizeof("Content-Length: 0")-1, 1);
  1645. }
  1646. fail:
  1647. SOAP_GLOBAL(soap_version) = old_soap_version;
  1648. SOAP_GLOBAL(encoding) = old_encoding;
  1649. SOAP_GLOBAL(sdl) = old_sdl;
  1650. SOAP_GLOBAL(class_map) = old_class_map;
  1651. SOAP_GLOBAL(typemap) = old_typemap;
  1652. SOAP_GLOBAL(features) = old_features;
  1653. /* Free soap headers */
  1654. zval_ptr_dtor(&retval);
  1655. while (soap_headers != NULL) {
  1656. soapHeader *h = soap_headers;
  1657. int i;
  1658. soap_headers = soap_headers->next;
  1659. if (h->parameters) {
  1660. i = h->num_params;
  1661. while (i > 0) {
  1662. zval_ptr_dtor(&h->parameters[--i]);
  1663. }
  1664. efree(h->parameters);
  1665. }
  1666. zval_ptr_dtor_str(&h->function_name);
  1667. zval_ptr_dtor(&h->retval);
  1668. efree(h);
  1669. }
  1670. service->soap_headers_ptr = NULL;
  1671. /* Free Memory */
  1672. if (num_params > 0) {
  1673. for (i = 0; i < num_params;i++) {
  1674. zval_ptr_dtor(&params[i]);
  1675. }
  1676. efree(params);
  1677. }
  1678. zval_ptr_dtor_str(&function_name);
  1679. SOAP_SERVER_END_CODE();
  1680. }
  1681. /* }}} */
  1682. /* {{{ proto SoapServer::fault ( staring code, string string [, string actor [, mixed details [, string name]]] )
  1683. Issue SoapFault indicating an error */
  1684. PHP_METHOD(SoapServer, fault)
  1685. {
  1686. char *code, *string, *actor=NULL, *name=NULL;
  1687. size_t code_len, string_len, actor_len = 0, name_len = 0;
  1688. zval* details = NULL;
  1689. soapServicePtr service;
  1690. xmlCharEncodingHandlerPtr old_encoding;
  1691. SOAP_SERVER_BEGIN_CODE();
  1692. FETCH_THIS_SERVICE(service);
  1693. old_encoding = SOAP_GLOBAL(encoding);
  1694. SOAP_GLOBAL(encoding) = service->encoding;
  1695. if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|szs",
  1696. &code, &code_len, &string, &string_len, &actor, &actor_len, &details,
  1697. &name, &name_len) == FAILURE) {
  1698. return;
  1699. }
  1700. soap_server_fault(code, string, actor, details, name);
  1701. SOAP_GLOBAL(encoding) = old_encoding;
  1702. SOAP_SERVER_END_CODE();
  1703. }
  1704. /* }}} */
  1705. /* {{{ proto SoapServer::addSoapHeader(SoapHeader $object) */
  1706. PHP_METHOD(SoapServer, addSoapHeader)
  1707. {
  1708. soapServicePtr service;
  1709. zval *fault;
  1710. soapHeader **p;
  1711. SOAP_SERVER_BEGIN_CODE();
  1712. FETCH_THIS_SERVICE(service);
  1713. if (!service || !service->soap_headers_ptr) {
  1714. php_error_docref(NULL, E_WARNING, "The SoapServer::addSoapHeader function may be called only during SOAP request processing");
  1715. return;
  1716. }
  1717. if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &fault, soap_header_class_entry) == FAILURE) {
  1718. return;
  1719. }
  1720. p = service->soap_headers_ptr;
  1721. while (*p != NULL) {
  1722. p = &(*p)->next;
  1723. }
  1724. *p = emalloc(sizeof(soapHeader));
  1725. memset(*p, 0, sizeof(soapHeader));
  1726. ZVAL_NULL(&(*p)->function_name);
  1727. ZVAL_COPY(&(*p)->retval, fault);
  1728. SOAP_SERVER_END_CODE();
  1729. }
  1730. /* }}} */
  1731. static void soap_server_fault_ex(sdlFunctionPtr function, zval* fault, soapHeader *hdr) /* {{{ */
  1732. {
  1733. int soap_version;
  1734. xmlChar *buf;
  1735. char cont_len[30];
  1736. int size;
  1737. xmlDocPtr doc_return;
  1738. zval *agent_name;
  1739. int use_http_error_status = 1;
  1740. soap_version = SOAP_GLOBAL(soap_version);
  1741. doc_return = serialize_response_call(function, NULL, NULL, fault, hdr, soap_version);
  1742. xmlDocDumpMemory(doc_return, &buf, &size);
  1743. if ((Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY || zend_is_auto_global_str(ZEND_STRL("_SERVER"))) &&
  1744. (agent_name = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT")-1)) != NULL &&
  1745. Z_TYPE_P(agent_name) == IS_STRING) {
  1746. if (strncmp(Z_STRVAL_P(agent_name), "Shockwave Flash", sizeof("Shockwave Flash")-1) == 0) {
  1747. use_http_error_status = 0;
  1748. }
  1749. }
  1750. /*
  1751. Want to return HTTP 500 but apache wants to over write
  1752. our fault code with their own handling... Figure this out later
  1753. */
  1754. if (use_http_error_status) {
  1755. sapi_add_header("HTTP/1.1 500 Internal Server Error", sizeof("HTTP/1.1 500 Internal Server Error")-1, 1);
  1756. }
  1757. if (zend_ini_long("zlib.output_compression", sizeof("zlib.output_compression"), 0)) {
  1758. sapi_add_header("Connection: close", sizeof("Connection: close")-1, 1);
  1759. } else {
  1760. snprintf(cont_len, sizeof(cont_len), "Content-Length: %d", size);
  1761. sapi_add_header(cont_len, strlen(cont_len), 1);
  1762. }
  1763. if (soap_version == SOAP_1_2) {
  1764. sapi_add_header("Content-Type: application/soap+xml; charset=utf-8", sizeof("Content-Type: application/soap+xml; charset=utf-8")-1, 1);
  1765. } else {
  1766. sapi_add_header("Content-Type: text/xml; charset=utf-8", sizeof("Content-Type: text/xml; charset=utf-8")-1, 1);
  1767. }
  1768. php_write(buf, size);
  1769. xmlFreeDoc(doc_return);
  1770. xmlFree(buf);
  1771. zend_clear_exception();
  1772. }
  1773. /* }}} */
  1774. static void soap_server_fault(char* code, char* string, char *actor, zval* details, char* name) /* {{{ */
  1775. {
  1776. zval ret;
  1777. ZVAL_NULL(&ret);
  1778. set_soap_fault(&ret, NULL, code, string, actor, details, name);
  1779. /* TODO: Which function */
  1780. soap_server_fault_ex(NULL, &ret, NULL);
  1781. zend_bailout();
  1782. }
  1783. /* }}} */
  1784. static void soap_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) /* {{{ */
  1785. {
  1786. zend_bool _old_in_compilation;
  1787. zend_execute_data *_old_current_execute_data;
  1788. int _old_http_response_code;
  1789. char *_old_http_status_line;
  1790. _old_in_compilation = CG(in_compilation);
  1791. _old_current_execute_data = EG(current_execute_data);
  1792. _old_http_response_code = SG(sapi_headers).http_response_code;
  1793. _old_http_status_line = SG(sapi_headers).http_status_line;
  1794. if (!PG(modules_activated) || !SOAP_GLOBAL(use_soap_error_handler) || !EG(objects_store).object_buckets) {
  1795. call_old_error_handler(error_num, error_filename, error_lineno, format, args);
  1796. return;
  1797. }
  1798. if (Z_OBJ(SOAP_GLOBAL(error_object)) &&
  1799. instanceof_function(Z_OBJCE(SOAP_GLOBAL(error_object)), soap_class_entry)) {
  1800. zval *tmp;
  1801. int use_exceptions = 0;
  1802. if ((tmp = zend_hash_str_find(Z_OBJPROP(SOAP_GLOBAL(error_object)), "_exceptions", sizeof("_exceptions")-1)) == NULL ||
  1803. Z_TYPE_P(tmp) != IS_FALSE) {
  1804. use_exceptions = 1;
  1805. }
  1806. if ((error_num == E_USER_ERROR ||
  1807. error_num == E_COMPILE_ERROR ||
  1808. error_num == E_CORE_ERROR ||
  1809. error_num == E_ERROR ||
  1810. error_num == E_PARSE) &&
  1811. use_exceptions) {
  1812. zval fault;
  1813. char* code = SOAP_GLOBAL(error_code);
  1814. char buffer[1024];
  1815. size_t buffer_len;
  1816. va_list argcopy;
  1817. va_copy(argcopy, args);
  1818. buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy);
  1819. va_end(argcopy);
  1820. buffer[sizeof(buffer)-1]=0;
  1821. if (buffer_len > sizeof(buffer) - 1 || buffer_len == (size_t)-1) {
  1822. buffer_len = sizeof(buffer) - 1;
  1823. }
  1824. if (code == NULL) {
  1825. code = "Client";
  1826. }
  1827. add_soap_fault_ex(&fault, &SOAP_GLOBAL(error_object), code, buffer, NULL, NULL);
  1828. Z_ADDREF(fault);
  1829. zend_throw_exception_object(&fault);
  1830. zend_bailout();
  1831. } else if (!use_exceptions ||
  1832. !SOAP_GLOBAL(error_code) ||
  1833. strcmp(SOAP_GLOBAL(error_code),"WSDL") != 0) {
  1834. /* Ignore libxml warnings during WSDL parsing */
  1835. call_old_error_handler(error_num, error_filename, error_lineno, format, args);
  1836. }
  1837. } else {
  1838. int old = PG(display_errors);
  1839. int fault = 0;
  1840. zval fault_obj;
  1841. va_list argcopy;
  1842. if (error_num == E_USER_ERROR ||
  1843. error_num == E_COMPILE_ERROR ||
  1844. error_num == E_CORE_ERROR ||
  1845. error_num == E_ERROR ||
  1846. error_num == E_PARSE) {
  1847. char* code = SOAP_GLOBAL(error_code);
  1848. char buffer[1024];
  1849. zval outbuf;
  1850. zval *tmp;
  1851. soapServicePtr service;
  1852. ZVAL_UNDEF(&outbuf);
  1853. if (code == NULL) {
  1854. code = "Server";
  1855. }
  1856. if (Z_OBJ(SOAP_GLOBAL(error_object)) &&
  1857. instanceof_function(Z_OBJCE(SOAP_GLOBAL(error_object)), soap_server_class_entry) &&
  1858. (tmp = zend_hash_str_find(Z_OBJPROP(SOAP_GLOBAL(error_object)), "service", sizeof("service")-1)) != NULL &&
  1859. (service = (soapServicePtr)zend_fetch_resource_ex(tmp, "service", le_service)) &&
  1860. !service->send_errors) {
  1861. strcpy(buffer, "Internal Error");
  1862. } else {
  1863. size_t buffer_len;
  1864. zval outbuflen;
  1865. va_copy(argcopy, args);
  1866. buffer_len = vslprintf(buffer, sizeof(buffer)-1, format, argcopy);
  1867. va_end(argcopy);
  1868. buffer[sizeof(buffer)-1]=0;
  1869. if (buffer_len > sizeof(buffer) - 1 || buffer_len == (size_t)-1) {
  1870. buffer_len = sizeof(buffer) - 1;
  1871. }
  1872. /* Get output buffer and send as fault detials */
  1873. if (php_output_get_length(&outbuflen) != FAILURE && Z_LVAL(outbuflen) != 0) {
  1874. php_output_get_contents(&outbuf);
  1875. }
  1876. php_output_discard();
  1877. }
  1878. ZVAL_NULL(&fault_obj);
  1879. set_soap_fault(&fault_obj, NULL, code, buffer, NULL, &outbuf, NULL);
  1880. fault = 1;
  1881. }
  1882. PG(display_errors) = 0;
  1883. SG(sapi_headers).http_status_line = NULL;
  1884. zend_try {
  1885. call_old_error_handler(error_num, error_filename, error_lineno, format, args);
  1886. } zend_catch {
  1887. CG(in_compilation) = _old_in_compilation;
  1888. EG(current_execute_data) = _old_current_execute_data;
  1889. if (SG(sapi_headers).http_status_line) {
  1890. efree(SG(sapi_headers).http_status_line);
  1891. }
  1892. SG(sapi_headers).http_status_line = _old_http_status_line;
  1893. SG(sapi_headers).http_response_code = _old_http_response_code;
  1894. } zend_end_try();
  1895. PG(display_errors) = old;
  1896. if (fault) {
  1897. soap_server_fault_ex(NULL, &fault_obj, NULL);
  1898. zend_bailout();
  1899. }
  1900. }
  1901. }
  1902. /* }}} */
  1903. /* {{{ proto use_soap_error_handler([bool $handler = TRUE]) */
  1904. PHP_FUNCTION(use_soap_error_handler)
  1905. {
  1906. zend_bool handler = 1;
  1907. ZVAL_BOOL(return_value, SOAP_GLOBAL(use_soap_error_handler));
  1908. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &handler) == SUCCESS) {
  1909. SOAP_GLOBAL(use_soap_error_handler) = handler;
  1910. }
  1911. }
  1912. /* }}} */
  1913. /* {{{ proto is_soap_fault(mixed $object) */
  1914. PHP_FUNCTION(is_soap_fault)
  1915. {
  1916. zval *fault;
  1917. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &fault) == SUCCESS &&
  1918. Z_TYPE_P(fault) == IS_OBJECT &&
  1919. instanceof_function(Z_OBJCE_P(fault), soap_fault_class_entry)) {
  1920. RETURN_TRUE;
  1921. }
  1922. RETURN_FALSE
  1923. }
  1924. /* }}} */
  1925. /* SoapClient functions */
  1926. /* {{{ proto object SoapClient::SoapClient(mixed wsdl [, array options])
  1927. SoapClient constructor */
  1928. PHP_METHOD(SoapClient, SoapClient)
  1929. {
  1930. zval *wsdl, *options = NULL;
  1931. int soap_version = SOAP_1_1;
  1932. php_stream_context *context = NULL;
  1933. zend_long cache_wsdl;
  1934. sdlPtr sdl = NULL;
  1935. HashTable *typemap_ht = NULL;
  1936. zval *this_ptr = getThis();
  1937. SOAP_CLIENT_BEGIN_CODE();
  1938. if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a", &wsdl, &options) == FAILURE) {
  1939. php_error_docref(NULL, E_ERROR, "Invalid parameters");
  1940. }
  1941. if (Z_TYPE_P(wsdl) != IS_STRING && Z_TYPE_P(wsdl) != IS_NULL) {
  1942. php_error_docref(NULL, E_ERROR, "$wsdl must be string or null");
  1943. }
  1944. cache_wsdl = SOAP_GLOBAL(cache_enabled) ? SOAP_GLOBAL(cache_mode) : 0;
  1945. if (options != NULL) {
  1946. HashTable *ht = Z_ARRVAL_P(options);
  1947. zval *tmp, tmp2;
  1948. if (Z_TYPE_P(wsdl) == IS_NULL) {
  1949. /* Fetching non-WSDL mode options */
  1950. if ((tmp = zend_hash_str_find(ht, "uri", sizeof("uri")-1)) != NULL &&
  1951. Z_TYPE_P(tmp) == IS_STRING) {
  1952. add_property_str(this_ptr, "uri", zend_string_copy(Z_STR_P(tmp)));
  1953. } else {
  1954. php_error_docref(NULL, E_ERROR, "'uri' option is required in nonWSDL mode");
  1955. }
  1956. if ((tmp = zend_hash_str_find(ht, "style", sizeof("style")-1)) != NULL &&
  1957. Z_TYPE_P(tmp) == IS_LONG &&
  1958. (Z_LVAL_P(tmp) == SOAP_RPC || Z_LVAL_P(tmp) == SOAP_DOCUMENT)) {
  1959. add_property_long(this_ptr, "style", Z_LVAL_P(tmp));
  1960. }
  1961. if ((tmp = zend_hash_str_find(ht, "use", sizeof("use")-1)) != NULL &&
  1962. Z_TYPE_P(tmp) == IS_LONG &&
  1963. (Z_LVAL_P(tmp) == SOAP_LITERAL || Z_LVAL_P(tmp) == SOAP_ENCODED)) {
  1964. add_property_long(this_ptr, "use", Z_LVAL_P(tmp));
  1965. }
  1966. }
  1967. if ((tmp = zend_hash_str_find(ht, "stream_context", sizeof("stream_context")-1)) != NULL &&
  1968. Z_TYPE_P(tmp) == IS_RESOURCE) {
  1969. context = php_stream_context_from_zval(tmp, 1);
  1970. Z_ADDREF_P(tmp);
  1971. } else {
  1972. context = php_stream_context_alloc();
  1973. }
  1974. if ((tmp = zend_hash_str_find(ht, "location", sizeof("location")-1)) != NULL &&
  1975. Z_TYPE_P(tmp) == IS_STRING) {
  1976. add_property_str(this_ptr, "location", zend_string_copy(Z_STR_P(tmp)));
  1977. } else if (Z_TYPE_P(wsdl) == IS_NULL) {
  1978. php_error_docref(NULL, E_ERROR, "'location' option is required in nonWSDL mode");
  1979. }
  1980. if ((tmp = zend_hash_str_find(ht, "soap_version", sizeof("soap_version")-1)) != NULL) {
  1981. if (Z_TYPE_P(tmp) == IS_LONG &&
  1982. (Z_LVAL_P(tmp) == SOAP_1_1 || Z_LVAL_P(tmp) == SOAP_1_2)) {
  1983. soap_version = Z_LVAL_P(tmp);
  1984. }
  1985. }
  1986. if ((tmp = zend_hash_str_find(ht, "login", sizeof("login")-1)) != NULL &&
  1987. Z_TYPE_P(tmp) == IS_STRING) {
  1988. add_property_str(this_ptr, "_login", zend_string_copy(Z_STR_P(tmp)));
  1989. if ((tmp = zend_hash_str_find(ht, "password", sizeof("password")-1)) != NULL &&
  1990. Z_TYPE_P(tmp) == IS_STRING) {
  1991. add_property_str(this_ptr, "_password", zend_string_copy(Z_STR_P(tmp)));
  1992. }
  1993. if ((tmp = zend_hash_str_find(ht, "authentication", sizeof("authentication")-1)) != NULL &&
  1994. Z_TYPE_P(tmp) == IS_LONG &&
  1995. Z_LVAL_P(tmp) == SOAP_AUTHENTICATION_DIGEST) {
  1996. add_property_null(this_ptr, "_digest");
  1997. }
  1998. }
  1999. if ((tmp = zend_hash_str_find(ht, "proxy_host", sizeof("proxy_host")-1)) != NULL &&
  2000. Z_TYPE_P(tmp) == IS_STRING) {
  2001. add_property_str(this_ptr, "_proxy_host", zend_string_copy(Z_STR_P(tmp)));
  2002. if ((tmp = zend_hash_str_find(ht, "proxy_port", sizeof("proxy_port")-1)) != NULL) {
  2003. if (Z_TYPE_P(tmp) != IS_LONG) {
  2004. ZVAL_LONG(&tmp2, zval_get_long(tmp));
  2005. tmp = &tmp2;
  2006. }
  2007. add_property_long(this_ptr, "_proxy_port", Z_LVAL_P(tmp));
  2008. }
  2009. if ((tmp = zend_hash_str_find(ht, "proxy_login", sizeof("proxy_login")-1)) != NULL &&
  2010. Z_TYPE_P(tmp) == IS_STRING) {
  2011. add_property_str(this_ptr, "_proxy_login", zend_string_copy(Z_STR_P(tmp)));
  2012. if ((tmp = zend_hash_str_find(ht, "proxy_password", sizeof("proxy_password")-1)) != NULL &&
  2013. Z_TYPE_P(tmp) == IS_STRING) {
  2014. add_property_str(this_ptr, "_proxy_password", zend_string_copy(Z_STR_P(tmp)));
  2015. }
  2016. }
  2017. }
  2018. if ((tmp = zend_hash_str_find(ht, "local_cert", sizeof("local_cert")-1)) != NULL &&
  2019. Z_TYPE_P(tmp) == IS_STRING) {
  2020. if (!context) {
  2021. context = php_stream_context_alloc();
  2022. }
  2023. php_stream_context_set_option(context, "ssl", "local_cert", tmp);
  2024. if ((tmp = zend_hash_str_find(ht, "passphrase", sizeof("passphrase")-1)) != NULL &&
  2025. Z_TYPE_P(tmp) == IS_STRING) {
  2026. php_stream_context_set_option(context, "ssl", "passphrase", tmp);
  2027. }
  2028. }
  2029. if ((tmp = zend_hash_str_find(ht, "trace", sizeof("trace")-1)) != NULL &&
  2030. (Z_TYPE_P(tmp) == IS_TRUE ||
  2031. (Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 1))) {
  2032. add_property_long(this_ptr, "trace", 1);
  2033. }
  2034. if ((tmp = zend_hash_str_find(ht, "exceptions", sizeof("exceptions")-1)) != NULL &&
  2035. (Z_TYPE_P(tmp) == IS_FALSE ||
  2036. (Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 0))) {
  2037. add_property_bool(this_ptr, "_exceptions", 0);
  2038. }
  2039. if ((tmp = zend_hash_str_find(ht, "compression", sizeof("compression")-1)) != NULL &&
  2040. Z_TYPE_P(tmp) == IS_LONG &&
  2041. zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1) &&
  2042. zend_hash_str_exists(EG(function_table), "gzdeflate", sizeof("gzdeflate")-1) &&
  2043. zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1) &&
  2044. zend_hash_str_exists(EG(function_table), "gzcompress", sizeof("gzcompress")-1) &&
  2045. zend_hash_str_exists(EG(function_table), "gzencode", sizeof("gzencode")-1)) {
  2046. add_property_long(this_ptr, "compression", Z_LVAL_P(tmp));
  2047. }
  2048. if ((tmp = zend_hash_str_find(ht, "encoding", sizeof("encoding")-1)) != NULL &&
  2049. Z_TYPE_P(tmp) == IS_STRING) {
  2050. xmlCharEncodingHandlerPtr encoding;
  2051. encoding = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
  2052. if (encoding == NULL) {
  2053. php_error_docref(NULL, E_ERROR, "Invalid 'encoding' option - '%s'", Z_STRVAL_P(tmp));
  2054. } else {
  2055. xmlCharEncCloseFunc(encoding);
  2056. add_property_str(this_ptr, "_encoding", zend_string_copy(Z_STR_P(tmp)));
  2057. }
  2058. }
  2059. if ((tmp = zend_hash_str_find(ht, "classmap", sizeof("classmap")-1)) != NULL &&
  2060. Z_TYPE_P(tmp) == IS_ARRAY) {
  2061. add_property_zval(this_ptr, "_classmap", tmp);
  2062. }
  2063. if ((tmp = zend_hash_str_find(ht, "typemap", sizeof("typemap")-1)) != NULL &&
  2064. Z_TYPE_P(tmp) == IS_ARRAY &&
  2065. zend_hash_num_elements(Z_ARRVAL_P(tmp)) > 0) {
  2066. typemap_ht = Z_ARRVAL_P(tmp);
  2067. }
  2068. if ((tmp = zend_hash_str_find(ht, "features", sizeof("features")-1)) != NULL &&
  2069. Z_TYPE_P(tmp) == IS_LONG) {
  2070. add_property_long(this_ptr, "_features", Z_LVAL_P(tmp));
  2071. }
  2072. if ((tmp = zend_hash_str_find(ht, "connection_timeout", sizeof("connection_timeout")-1)) != NULL) {
  2073. if (Z_TYPE_P(tmp) != IS_LONG) {
  2074. ZVAL_LONG(&tmp2, zval_get_long(tmp));
  2075. tmp = &tmp2;
  2076. }
  2077. if (Z_LVAL_P(tmp) > 0) {
  2078. add_property_long(this_ptr, "_connection_timeout", Z_LVAL_P(tmp));
  2079. }
  2080. }
  2081. if (context) {
  2082. add_property_resource(this_ptr, "_stream_context", context->res);
  2083. }
  2084. if ((tmp = zend_hash_str_find(ht, "cache_wsdl", sizeof("cache_wsdl")-1)) != NULL &&
  2085. Z_TYPE_P(tmp) == IS_LONG) {
  2086. cache_wsdl = Z_LVAL_P(tmp);
  2087. }
  2088. if ((tmp = zend_hash_str_find(ht, "user_agent", sizeof("user_agent")-1)) != NULL &&
  2089. Z_TYPE_P(tmp) == IS_STRING) {
  2090. add_property_str(this_ptr, "_user_agent", zend_string_copy(Z_STR_P(tmp)));
  2091. }
  2092. if ((tmp = zend_hash_str_find(ht, "keep_alive", sizeof("keep_alive")-1)) != NULL &&
  2093. (Z_TYPE_P(tmp) == IS_FALSE ||
  2094. (Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == 0))) {
  2095. add_property_long(this_ptr, "_keep_alive", 0);
  2096. }
  2097. if ((tmp = zend_hash_str_find(ht, "ssl_method", sizeof("ssl_method")-1)) != NULL &&
  2098. Z_TYPE_P(tmp) == IS_LONG) {
  2099. add_property_long(this_ptr, "_ssl_method", Z_LVAL_P(tmp));
  2100. }
  2101. } else if (Z_TYPE_P(wsdl) == IS_NULL) {
  2102. php_error_docref(NULL, E_ERROR, "'location' and 'uri' options are required in nonWSDL mode");
  2103. }
  2104. add_property_long(this_ptr, "_soap_version", soap_version);
  2105. if (Z_TYPE_P(wsdl) != IS_NULL) {
  2106. int old_soap_version;
  2107. zend_resource *res;
  2108. old_soap_version = SOAP_GLOBAL(soap_version);
  2109. SOAP_GLOBAL(soap_version) = soap_version;
  2110. sdl = get_sdl(this_ptr, Z_STRVAL_P(wsdl), cache_wsdl);
  2111. res = zend_register_resource(sdl, le_sdl);
  2112. add_property_resource(this_ptr, "sdl", res);
  2113. SOAP_GLOBAL(soap_version) = old_soap_version;
  2114. }
  2115. if (typemap_ht) {
  2116. HashTable *typemap = soap_create_typemap(sdl, typemap_ht);
  2117. if (typemap) {
  2118. zend_resource *res;
  2119. res = zend_register_resource(typemap, le_typemap);
  2120. add_property_resource(this_ptr, "typemap", res);
  2121. }
  2122. }
  2123. SOAP_CLIENT_END_CODE();
  2124. }
  2125. /* }}} */
  2126. static int do_request(zval *this_ptr, xmlDoc *request, char *location, char *action, int version, int one_way, zval *response) /* {{{ */
  2127. {
  2128. int ret = TRUE;
  2129. char *buf;
  2130. int buf_size;
  2131. zval func;
  2132. zval params[5];
  2133. zval *trace;
  2134. zval *fault;
  2135. int _bailout = 0;
  2136. ZVAL_NULL(response);
  2137. xmlDocDumpMemory(request, (xmlChar**)&buf, &buf_size);
  2138. if (!buf) {
  2139. add_soap_fault(this_ptr, "HTTP", "Error build soap request", NULL, NULL);
  2140. return FALSE;
  2141. }
  2142. zend_try {
  2143. if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL &&
  2144. (Z_TYPE_P(trace) == IS_TRUE || (Z_TYPE_P(trace) == IS_LONG && Z_LVAL_P(trace) != 0))) {
  2145. add_property_stringl(this_ptr, "__last_request", buf, buf_size);
  2146. }
  2147. ZVAL_STRINGL(&func,"__doRequest",sizeof("__doRequest")-1);
  2148. ZVAL_STRINGL(&params[0], buf, buf_size);
  2149. if (location == NULL) {
  2150. ZVAL_NULL(&params[1]);
  2151. } else {
  2152. ZVAL_STRING(&params[1], location);
  2153. }
  2154. if (action == NULL) {
  2155. ZVAL_NULL(&params[2]);
  2156. } else {
  2157. ZVAL_STRING(&params[2], action);
  2158. }
  2159. ZVAL_LONG(&params[3], version);
  2160. ZVAL_LONG(&params[4], one_way);
  2161. if (call_user_function(NULL, this_ptr, &func, response, 5, params) != SUCCESS) {
  2162. add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() failed", NULL, NULL);
  2163. ret = FALSE;
  2164. } else if (Z_TYPE_P(response) != IS_STRING) {
  2165. if (EG(exception) && instanceof_function(EG(exception)->ce, zend_ce_error)) {
  2166. zval rv;
  2167. zend_string *msg;
  2168. zval exception_object;
  2169. ZVAL_OBJ(&exception_object, EG(exception));
  2170. msg = zval_get_string(zend_read_property(zend_ce_error, &exception_object, "message", sizeof("message")-1, 0, &rv));
  2171. /* change class */
  2172. EG(exception)->ce = soap_fault_class_entry;
  2173. set_soap_fault(&exception_object, NULL, "Client", ZSTR_VAL(msg), NULL, NULL, NULL);
  2174. zend_string_release_ex(msg, 0);
  2175. } else if ((fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) == NULL) {
  2176. add_soap_fault(this_ptr, "Client", "SoapClient::__doRequest() returned non string value", NULL, NULL);
  2177. }
  2178. ret = FALSE;
  2179. } else if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL &&
  2180. (Z_TYPE_P(trace) == IS_TRUE || (Z_TYPE_P(trace) == IS_LONG && Z_LVAL_P(trace) != 0))) {
  2181. add_property_str(this_ptr, "__last_response", zend_string_copy(Z_STR_P(response)));
  2182. }
  2183. } zend_catch {
  2184. _bailout = 1;
  2185. } zend_end_try();
  2186. zval_ptr_dtor(&func);
  2187. zval_ptr_dtor(&params[2]);
  2188. zval_ptr_dtor(&params[1]);
  2189. zval_ptr_dtor(&params[0]);
  2190. xmlFree(buf);
  2191. if (_bailout) {
  2192. zend_bailout();
  2193. }
  2194. if (ret && (fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) != NULL) {
  2195. ret = FALSE;
  2196. }
  2197. return ret;
  2198. }
  2199. /* }}} */
  2200. static void do_soap_call(zend_execute_data *execute_data,
  2201. zval* this_ptr,
  2202. char* function,
  2203. size_t function_len,
  2204. int arg_count,
  2205. zval* real_args,
  2206. zval* return_value,
  2207. char* location,
  2208. char* soap_action,
  2209. char* call_uri,
  2210. HashTable* soap_headers,
  2211. zval* output_headers
  2212. ) /* {{{ */
  2213. {
  2214. zval *tmp;
  2215. zval *trace;
  2216. sdlPtr sdl = NULL;
  2217. sdlPtr old_sdl = NULL;
  2218. sdlFunctionPtr fn;
  2219. xmlDocPtr request = NULL;
  2220. int ret = FALSE;
  2221. int soap_version;
  2222. zval response;
  2223. xmlCharEncodingHandlerPtr old_encoding;
  2224. HashTable *old_class_map;
  2225. int old_features;
  2226. HashTable *old_typemap, *typemap = NULL;
  2227. smart_str action = {0};
  2228. SOAP_CLIENT_BEGIN_CODE();
  2229. if ((trace = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "trace", sizeof("trace")-1)) != NULL &&
  2230. (Z_TYPE_P(trace) == IS_TRUE || (Z_TYPE_P(trace) == IS_LONG && Z_LVAL_P(trace) != 0))) {
  2231. zend_hash_str_del(Z_OBJPROP_P(this_ptr), "__last_request", sizeof("__last_request")-1);
  2232. zend_hash_str_del(Z_OBJPROP_P(this_ptr), "__last_response", sizeof("__last_response")-1);
  2233. }
  2234. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_soap_version", sizeof("_soap_version")-1)) != NULL &&
  2235. Z_TYPE_P(tmp) == IS_LONG && Z_LVAL_P(tmp) == SOAP_1_2) {
  2236. soap_version = SOAP_1_2;
  2237. } else {
  2238. soap_version = SOAP_1_1;
  2239. }
  2240. if (location == NULL) {
  2241. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "location", sizeof("location")-1)) != NULL &&
  2242. Z_TYPE_P(tmp) == IS_STRING) {
  2243. location = Z_STRVAL_P(tmp);
  2244. }
  2245. }
  2246. if (FIND_SDL_PROPERTY(this_ptr,tmp) != NULL) {
  2247. FETCH_SDL_RES(sdl,tmp);
  2248. }
  2249. if (FIND_TYPEMAP_PROPERTY(this_ptr,tmp) != NULL) {
  2250. FETCH_TYPEMAP_RES(typemap,tmp);
  2251. }
  2252. clear_soap_fault(this_ptr);
  2253. SOAP_GLOBAL(soap_version) = soap_version;
  2254. old_sdl = SOAP_GLOBAL(sdl);
  2255. SOAP_GLOBAL(sdl) = sdl;
  2256. old_encoding = SOAP_GLOBAL(encoding);
  2257. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_encoding", sizeof("_encoding")-1)) != NULL &&
  2258. Z_TYPE_P(tmp) == IS_STRING) {
  2259. SOAP_GLOBAL(encoding) = xmlFindCharEncodingHandler(Z_STRVAL_P(tmp));
  2260. } else {
  2261. SOAP_GLOBAL(encoding) = NULL;
  2262. }
  2263. old_class_map = SOAP_GLOBAL(class_map);
  2264. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_classmap", sizeof("_classmap")-1)) != NULL &&
  2265. Z_TYPE_P(tmp) == IS_ARRAY) {
  2266. SOAP_GLOBAL(class_map) = Z_ARRVAL_P(tmp);
  2267. } else {
  2268. SOAP_GLOBAL(class_map) = NULL;
  2269. }
  2270. old_typemap = SOAP_GLOBAL(typemap);
  2271. SOAP_GLOBAL(typemap) = typemap;
  2272. old_features = SOAP_GLOBAL(features);
  2273. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_features", sizeof("_features")-1)) != NULL &&
  2274. Z_TYPE_P(tmp) == IS_LONG) {
  2275. SOAP_GLOBAL(features) = Z_LVAL_P(tmp);
  2276. } else {
  2277. SOAP_GLOBAL(features) = 0;
  2278. }
  2279. zend_try {
  2280. if (sdl != NULL) {
  2281. fn = get_function(sdl, function);
  2282. if (fn != NULL) {
  2283. sdlBindingPtr binding = fn->binding;
  2284. int one_way = 0;
  2285. if (fn->responseName == NULL &&
  2286. fn->responseParameters == NULL &&
  2287. soap_headers == NULL) {
  2288. one_way = 1;
  2289. }
  2290. if (location == NULL) {
  2291. location = binding->location;
  2292. }
  2293. if (binding->bindingType == BINDING_SOAP) {
  2294. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)fn->bindingAttributes;
  2295. request = serialize_function_call(this_ptr, fn, NULL, fnb->input.ns, real_args, arg_count, soap_version, soap_headers);
  2296. ret = do_request(this_ptr, request, location, fnb->soapAction, soap_version, one_way, &response);
  2297. } else {
  2298. request = serialize_function_call(this_ptr, fn, NULL, sdl->target_ns, real_args, arg_count, soap_version, soap_headers);
  2299. ret = do_request(this_ptr, request, location, NULL, soap_version, one_way, &response);
  2300. }
  2301. xmlFreeDoc(request);
  2302. request = NULL;
  2303. if (ret && Z_TYPE(response) == IS_STRING) {
  2304. encode_reset_ns();
  2305. ret = parse_packet_soap(this_ptr, Z_STRVAL(response), Z_STRLEN(response), fn, NULL, return_value, output_headers);
  2306. encode_finish();
  2307. }
  2308. zval_ptr_dtor(&response);
  2309. } else {
  2310. smart_str error = {0};
  2311. smart_str_appends(&error,"Function (\"");
  2312. smart_str_appends(&error,function);
  2313. smart_str_appends(&error,"\") is not a valid method for this service");
  2314. smart_str_0(&error);
  2315. add_soap_fault(this_ptr, "Client", ZSTR_VAL(error.s), NULL, NULL);
  2316. smart_str_free(&error);
  2317. }
  2318. } else {
  2319. zval *uri;
  2320. if ((uri = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "uri", sizeof("uri")-1)) == NULL || Z_TYPE_P(uri) != IS_STRING) {
  2321. add_soap_fault(this_ptr, "Client", "Error finding \"uri\" property", NULL, NULL);
  2322. } else if (location == NULL) {
  2323. add_soap_fault(this_ptr, "Client", "Error could not find \"location\" property", NULL, NULL);
  2324. } else {
  2325. if (call_uri == NULL) {
  2326. call_uri = Z_STRVAL_P(uri);
  2327. }
  2328. request = serialize_function_call(this_ptr, NULL, function, call_uri, real_args, arg_count, soap_version, soap_headers);
  2329. if (soap_action == NULL) {
  2330. smart_str_appends(&action, call_uri);
  2331. smart_str_appendc(&action, '#');
  2332. smart_str_appends(&action, function);
  2333. } else {
  2334. smart_str_appends(&action, soap_action);
  2335. }
  2336. smart_str_0(&action);
  2337. ret = do_request(this_ptr, request, location, ZSTR_VAL(action.s), soap_version, 0, &response);
  2338. smart_str_free(&action);
  2339. xmlFreeDoc(request);
  2340. request = NULL;
  2341. if (ret && Z_TYPE(response) == IS_STRING) {
  2342. encode_reset_ns();
  2343. ret = parse_packet_soap(this_ptr, Z_STRVAL(response), Z_STRLEN(response), NULL, function, return_value, output_headers);
  2344. encode_finish();
  2345. }
  2346. zval_ptr_dtor(&response);
  2347. }
  2348. }
  2349. if (!ret) {
  2350. zval* fault;
  2351. if ((fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) != NULL) {
  2352. ZVAL_COPY(return_value, fault);
  2353. } else {
  2354. add_soap_fault_ex(return_value, this_ptr, "Client", "Unknown Error", NULL, NULL);
  2355. Z_ADDREF_P(return_value);
  2356. }
  2357. } else {
  2358. zval* fault;
  2359. if ((fault = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__soap_fault", sizeof("__soap_fault")-1)) != NULL) {
  2360. ZVAL_COPY(return_value, fault);
  2361. }
  2362. }
  2363. if (!EG(exception) &&
  2364. Z_TYPE_P(return_value) == IS_OBJECT &&
  2365. instanceof_function(Z_OBJCE_P(return_value), soap_fault_class_entry) &&
  2366. ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_exceptions", sizeof("_exceptions")-1)) == NULL ||
  2367. Z_TYPE_P(tmp) != IS_FALSE)) {
  2368. Z_ADDREF_P(return_value);
  2369. zend_throw_exception_object(return_value);
  2370. }
  2371. } zend_catch {
  2372. _bailout = 1;
  2373. } zend_end_try();
  2374. if (SOAP_GLOBAL(encoding) != NULL) {
  2375. xmlCharEncCloseFunc(SOAP_GLOBAL(encoding));
  2376. }
  2377. SOAP_GLOBAL(features) = old_features;
  2378. SOAP_GLOBAL(typemap) = old_typemap;
  2379. SOAP_GLOBAL(class_map) = old_class_map;
  2380. SOAP_GLOBAL(encoding) = old_encoding;
  2381. SOAP_GLOBAL(sdl) = old_sdl;
  2382. if (_bailout) {
  2383. smart_str_free(&action);
  2384. if (request) {
  2385. xmlFreeDoc(request);
  2386. }
  2387. _bailout = 0;
  2388. zend_bailout();
  2389. }
  2390. SOAP_CLIENT_END_CODE();
  2391. }
  2392. /* }}} */
  2393. static void verify_soap_headers_array(HashTable *ht) /* {{{ */
  2394. {
  2395. zval *tmp;
  2396. ZEND_HASH_FOREACH_VAL(ht, tmp) {
  2397. if (Z_TYPE_P(tmp) != IS_OBJECT ||
  2398. !instanceof_function(Z_OBJCE_P(tmp), soap_header_class_entry)) {
  2399. php_error_docref(NULL, E_ERROR, "Invalid SOAP header");
  2400. }
  2401. } ZEND_HASH_FOREACH_END();
  2402. }
  2403. /* }}} */
  2404. /* {{{ proto mixed SoapClient::__call(string function_name, array arguments [, array options [, array input_headers [, array output_headers]]])
  2405. Calls a SOAP function */
  2406. PHP_METHOD(SoapClient, __call)
  2407. {
  2408. char *function, *location=NULL, *soap_action = NULL, *uri = NULL;
  2409. size_t function_len;
  2410. int i = 0;
  2411. HashTable* soap_headers = NULL;
  2412. zval *options = NULL;
  2413. zval *headers = NULL;
  2414. zval *output_headers = NULL;
  2415. zval *args;
  2416. zval *real_args = NULL;
  2417. zval *param;
  2418. int arg_count;
  2419. zval *tmp;
  2420. zend_bool free_soap_headers = 0;
  2421. zval *this_ptr;
  2422. if (zend_parse_parameters(ZEND_NUM_ARGS(), "sa|a!zz/",
  2423. &function, &function_len, &args, &options, &headers, &output_headers) == FAILURE) {
  2424. return;
  2425. }
  2426. if (options) {
  2427. HashTable *hto = Z_ARRVAL_P(options);
  2428. if ((tmp = zend_hash_str_find(hto, "location", sizeof("location")-1)) != NULL &&
  2429. Z_TYPE_P(tmp) == IS_STRING) {
  2430. location = Z_STRVAL_P(tmp);
  2431. }
  2432. if ((tmp = zend_hash_str_find(hto, "soapaction", sizeof("soapaction")-1)) != NULL &&
  2433. Z_TYPE_P(tmp) == IS_STRING) {
  2434. soap_action = Z_STRVAL_P(tmp);
  2435. }
  2436. if ((tmp = zend_hash_str_find(hto, "uri", sizeof("uri")-1)) != NULL &&
  2437. Z_TYPE_P(tmp) == IS_STRING) {
  2438. uri = Z_STRVAL_P(tmp);
  2439. }
  2440. }
  2441. if (headers == NULL || Z_TYPE_P(headers) == IS_NULL) {
  2442. } else if (Z_TYPE_P(headers) == IS_ARRAY) {
  2443. soap_headers = Z_ARRVAL_P(headers);
  2444. verify_soap_headers_array(soap_headers);
  2445. free_soap_headers = 0;
  2446. } else if (Z_TYPE_P(headers) == IS_OBJECT &&
  2447. instanceof_function(Z_OBJCE_P(headers), soap_header_class_entry)) {
  2448. soap_headers = zend_new_array(0);
  2449. zend_hash_next_index_insert(soap_headers, headers);
  2450. Z_ADDREF_P(headers);
  2451. free_soap_headers = 1;
  2452. } else{
  2453. php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
  2454. return;
  2455. }
  2456. /* Add default headers */
  2457. this_ptr = getThis();
  2458. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers")-1)) != NULL && Z_TYPE_P(tmp) == IS_ARRAY) {
  2459. HashTable *default_headers = Z_ARRVAL_P(tmp);
  2460. if (soap_headers) {
  2461. if (!free_soap_headers) {
  2462. soap_headers = zend_array_dup(soap_headers);
  2463. free_soap_headers = 1;
  2464. }
  2465. ZEND_HASH_FOREACH_VAL(default_headers, tmp) {
  2466. if(Z_TYPE_P(tmp) == IS_OBJECT) {
  2467. Z_ADDREF_P(tmp);
  2468. zend_hash_next_index_insert(soap_headers, tmp);
  2469. }
  2470. } ZEND_HASH_FOREACH_END();
  2471. } else {
  2472. soap_headers = Z_ARRVAL_P(tmp);
  2473. free_soap_headers = 0;
  2474. }
  2475. }
  2476. arg_count = zend_hash_num_elements(Z_ARRVAL_P(args));
  2477. if (arg_count > 0) {
  2478. real_args = safe_emalloc(sizeof(zval), arg_count, 0);
  2479. ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), param) {
  2480. /*zval_add_ref(param);*/
  2481. ZVAL_DEREF(param);
  2482. ZVAL_COPY_VALUE(&real_args[i], param);
  2483. i++;
  2484. } ZEND_HASH_FOREACH_END();
  2485. }
  2486. if (output_headers) {
  2487. zval_ptr_dtor(output_headers);
  2488. array_init(output_headers);
  2489. }
  2490. do_soap_call(execute_data, this_ptr, function, function_len, arg_count, real_args, return_value, location, soap_action, uri, soap_headers, output_headers);
  2491. if (arg_count > 0) {
  2492. efree(real_args);
  2493. }
  2494. if (soap_headers && free_soap_headers) {
  2495. zend_hash_destroy(soap_headers);
  2496. efree(soap_headers);
  2497. }
  2498. }
  2499. /* }}} */
  2500. /* {{{ proto array SoapClient::__getFunctions(void)
  2501. Returns list of SOAP functions */
  2502. PHP_METHOD(SoapClient, __getFunctions)
  2503. {
  2504. sdlPtr sdl;
  2505. FETCH_THIS_SDL(sdl);
  2506. if (zend_parse_parameters_none() == FAILURE) {
  2507. return;
  2508. }
  2509. if (sdl) {
  2510. smart_str buf = {0};
  2511. sdlFunctionPtr function;
  2512. array_init(return_value);
  2513. ZEND_HASH_FOREACH_PTR(&sdl->functions, function) {
  2514. function_to_string(function, &buf);
  2515. add_next_index_stringl(return_value, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s));
  2516. smart_str_free(&buf);
  2517. } ZEND_HASH_FOREACH_END();
  2518. }
  2519. }
  2520. /* }}} */
  2521. /* {{{ proto array SoapClient::__getTypes(void)
  2522. Returns list of SOAP types */
  2523. PHP_METHOD(SoapClient, __getTypes)
  2524. {
  2525. sdlPtr sdl;
  2526. FETCH_THIS_SDL(sdl);
  2527. if (zend_parse_parameters_none() == FAILURE) {
  2528. return;
  2529. }
  2530. if (sdl) {
  2531. sdlTypePtr type;
  2532. smart_str buf = {0};
  2533. array_init(return_value);
  2534. if (sdl->types) {
  2535. ZEND_HASH_FOREACH_PTR(sdl->types, type) {
  2536. type_to_string(type, &buf, 0);
  2537. add_next_index_stringl(return_value, ZSTR_VAL(buf.s), ZSTR_LEN(buf.s));
  2538. smart_str_free(&buf);
  2539. } ZEND_HASH_FOREACH_END();
  2540. }
  2541. }
  2542. }
  2543. /* }}} */
  2544. /* {{{ proto string SoapClient::__getLastRequest(void)
  2545. Returns last SOAP request */
  2546. PHP_METHOD(SoapClient, __getLastRequest)
  2547. {
  2548. zval *tmp;
  2549. if (zend_parse_parameters_none() == FAILURE) {
  2550. return;
  2551. }
  2552. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_request", sizeof("__last_request")-1)) != NULL &&
  2553. Z_TYPE_P(tmp) == IS_STRING) {
  2554. RETURN_STR_COPY(Z_STR_P(tmp));
  2555. }
  2556. RETURN_NULL();
  2557. }
  2558. /* }}} */
  2559. /* {{{ proto object SoapClient::__getLastResponse(void)
  2560. Returns last SOAP response */
  2561. PHP_METHOD(SoapClient, __getLastResponse)
  2562. {
  2563. zval *tmp;
  2564. if (zend_parse_parameters_none() == FAILURE) {
  2565. return;
  2566. }
  2567. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_response", sizeof("__last_response")-1)) != NULL &&
  2568. Z_TYPE_P(tmp) == IS_STRING) {
  2569. RETURN_STR_COPY(Z_STR_P(tmp));
  2570. }
  2571. RETURN_NULL();
  2572. }
  2573. /* }}} */
  2574. /* {{{ proto string SoapClient::__getLastRequestHeaders(void)
  2575. Returns last SOAP request headers */
  2576. PHP_METHOD(SoapClient, __getLastRequestHeaders)
  2577. {
  2578. zval *tmp;
  2579. if (zend_parse_parameters_none() == FAILURE) {
  2580. return;
  2581. }
  2582. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_request_headers", sizeof("__last_request_headers")-1)) != NULL &&
  2583. Z_TYPE_P(tmp) == IS_STRING) {
  2584. RETURN_STR_COPY(Z_STR_P(tmp));
  2585. }
  2586. RETURN_NULL();
  2587. }
  2588. /* }}} */
  2589. /* {{{ proto string SoapClient::__getLastResponseHeaders(void)
  2590. Returns last SOAP response headers */
  2591. PHP_METHOD(SoapClient, __getLastResponseHeaders)
  2592. {
  2593. zval *tmp;
  2594. if (zend_parse_parameters_none() == FAILURE) {
  2595. return;
  2596. }
  2597. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(getThis()), "__last_response_headers", sizeof("__last_response_headers")-1)) != NULL &&
  2598. Z_TYPE_P(tmp) == IS_STRING) {
  2599. RETURN_STR_COPY(Z_STR_P(tmp));
  2600. }
  2601. RETURN_NULL();
  2602. }
  2603. /* }}} */
  2604. /* {{{ proto string SoapClient::__doRequest()
  2605. SoapClient::__doRequest() */
  2606. PHP_METHOD(SoapClient, __doRequest)
  2607. {
  2608. zend_string *buf;
  2609. char *location, *action;
  2610. size_t location_size, action_size;
  2611. zend_long version;
  2612. zend_long one_way = 0;
  2613. zval *this_ptr = getThis();
  2614. if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sssl|l",
  2615. &buf,
  2616. &location, &location_size,
  2617. &action, &action_size,
  2618. &version, &one_way) == FAILURE) {
  2619. return;
  2620. }
  2621. if (SOAP_GLOBAL(features) & SOAP_WAIT_ONE_WAY_CALLS) {
  2622. one_way = 0;
  2623. }
  2624. if (one_way) {
  2625. if (make_http_soap_request(this_ptr, buf, location, action, version, NULL)) {
  2626. RETURN_EMPTY_STRING();
  2627. }
  2628. } else if (make_http_soap_request(this_ptr, buf, location, action, version,
  2629. return_value)) {
  2630. return;
  2631. }
  2632. RETURN_NULL();
  2633. }
  2634. /* }}} */
  2635. /* {{{ proto void SoapClient::__setCookie(string name [, strung value])
  2636. Sets cookie thet will sent with SOAP request.
  2637. The call to this function will effect all following calls of SOAP methods.
  2638. If value is not specified cookie is removed. */
  2639. PHP_METHOD(SoapClient, __setCookie)
  2640. {
  2641. char *name;
  2642. char *val = NULL;
  2643. size_t name_len, val_len = 0;
  2644. zval *cookies;
  2645. zval *this_ptr = getThis();
  2646. if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &name, &name_len, &val, &val_len) == FAILURE) {
  2647. return;
  2648. }
  2649. if (val == NULL) {
  2650. if ((cookies = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1)) != NULL &&
  2651. Z_TYPE_P(cookies) == IS_ARRAY) {
  2652. zend_hash_str_del(Z_ARRVAL_P(cookies), name, name_len);
  2653. }
  2654. } else {
  2655. zval zcookie;
  2656. if ((cookies = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1)) == NULL ||
  2657. Z_TYPE_P(cookies) != IS_ARRAY) {
  2658. zval tmp_cookies;
  2659. array_init(&tmp_cookies);
  2660. cookies = zend_hash_str_update(Z_OBJPROP_P(this_ptr), "_cookies", sizeof("_cookies")-1, &tmp_cookies);
  2661. }
  2662. array_init(&zcookie);
  2663. add_index_stringl(&zcookie, 0, val, val_len);
  2664. add_assoc_zval_ex(cookies, name, name_len, &zcookie);
  2665. }
  2666. }
  2667. /* }}} */
  2668. /* {{{ proto array SoapClient::__getCookies(void)
  2669. Returns list of cookies */
  2670. PHP_METHOD(SoapClient, __getCookies)
  2671. {
  2672. zval *cookies;
  2673. if (zend_parse_parameters_none() == FAILURE) {
  2674. return;
  2675. }
  2676. if ((cookies = zend_hash_str_find(Z_OBJPROP_P(getThis()), "_cookies", sizeof("_cookies")-1)) != NULL &&
  2677. Z_TYPE_P(cookies) == IS_ARRAY) {
  2678. RETURN_ARR(zend_array_dup(Z_ARRVAL_P(cookies)));
  2679. } else {
  2680. array_init(return_value);
  2681. }
  2682. }
  2683. /* }}} */
  2684. /* {{{ proto void SoapClient::__setSoapHeaders(array SoapHeaders)
  2685. Sets SOAP headers for subsequent calls (replaces any previous
  2686. values).
  2687. If no value is specified, all of the headers are removed. */
  2688. PHP_METHOD(SoapClient, __setSoapHeaders)
  2689. {
  2690. zval *headers = NULL;
  2691. zval *this_ptr = getThis();
  2692. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &headers) == FAILURE) {
  2693. return;
  2694. }
  2695. if (headers == NULL || Z_TYPE_P(headers) == IS_NULL) {
  2696. zend_hash_str_del(Z_OBJPROP_P(this_ptr), "__default_headers", sizeof("__default_headers")-1);
  2697. } else if (Z_TYPE_P(headers) == IS_ARRAY) {
  2698. verify_soap_headers_array(Z_ARRVAL_P(headers));
  2699. add_property_zval(this_ptr, "__default_headers", headers);
  2700. } else if (Z_TYPE_P(headers) == IS_OBJECT &&
  2701. instanceof_function(Z_OBJCE_P(headers), soap_header_class_entry)) {
  2702. zval default_headers;
  2703. array_init(&default_headers);
  2704. Z_ADDREF_P(headers);
  2705. add_next_index_zval(&default_headers, headers);
  2706. add_property_zval(this_ptr, "__default_headers", &default_headers);
  2707. Z_DELREF_P(&default_headers);
  2708. } else{
  2709. php_error_docref(NULL, E_WARNING, "Invalid SOAP header");
  2710. }
  2711. RETURN_TRUE;
  2712. }
  2713. /* }}} */
  2714. /* {{{ proto string SoapClient::__setLocation([string new_location])
  2715. Sets the location option (the endpoint URL that will be touched by the
  2716. following SOAP requests).
  2717. If new_location is not specified or null then SoapClient will use endpoint
  2718. from WSDL file.
  2719. The function returns old value of location options. */
  2720. PHP_METHOD(SoapClient, __setLocation)
  2721. {
  2722. char *location = NULL;
  2723. size_t location_len = 0;
  2724. zval *tmp;
  2725. zval *this_ptr = getThis();
  2726. if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &location, &location_len) == FAILURE) {
  2727. return;
  2728. }
  2729. if ((tmp = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "location", sizeof("location")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
  2730. RETVAL_STR_COPY(Z_STR_P(tmp));
  2731. } else {
  2732. RETVAL_NULL();
  2733. }
  2734. if (location && location_len) {
  2735. add_property_stringl(this_ptr, "location", location, location_len);
  2736. } else {
  2737. zend_hash_str_del(Z_OBJPROP_P(this_ptr), "location", sizeof("location")-1);
  2738. }
  2739. }
  2740. /* }}} */
  2741. static void clear_soap_fault(zval *obj) /* {{{ */
  2742. {
  2743. if (obj != NULL && Z_TYPE_P(obj) == IS_OBJECT) {
  2744. zend_hash_str_del(Z_OBJPROP_P(obj), "__soap_fault", sizeof("__soap_fault")-1);
  2745. }
  2746. }
  2747. /* }}} */
  2748. static void add_soap_fault_ex(zval *fault, zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail) /* {{{ */
  2749. {
  2750. ZVAL_NULL(fault);
  2751. set_soap_fault(fault, NULL, fault_code, fault_string, fault_actor, fault_detail, NULL);
  2752. add_property_zval(obj, "__soap_fault", fault);
  2753. Z_DELREF_P(fault);
  2754. }
  2755. /* }}} */
  2756. void add_soap_fault(zval *obj, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail) /* {{{ */
  2757. {
  2758. zval fault;
  2759. ZVAL_NULL(&fault);
  2760. set_soap_fault(&fault, NULL, fault_code, fault_string, fault_actor, fault_detail, NULL);
  2761. add_property_zval(obj, "__soap_fault", &fault);
  2762. Z_DELREF(fault);
  2763. }
  2764. /* }}} */
  2765. static void set_soap_fault(zval *obj, char *fault_code_ns, char *fault_code, char *fault_string, char *fault_actor, zval *fault_detail, char *name) /* {{{ */
  2766. {
  2767. if (Z_TYPE_P(obj) != IS_OBJECT) {
  2768. object_init_ex(obj, soap_fault_class_entry);
  2769. }
  2770. add_property_string(obj, "faultstring", fault_string ? fault_string : "");
  2771. zend_update_property_string(zend_ce_exception, obj, "message", sizeof("message")-1, (fault_string ? fault_string : ""));
  2772. if (fault_code != NULL) {
  2773. int soap_version = SOAP_GLOBAL(soap_version);
  2774. if (fault_code_ns) {
  2775. add_property_string(obj, "faultcode", fault_code);
  2776. add_property_string(obj, "faultcodens", fault_code_ns);
  2777. } else {
  2778. if (soap_version == SOAP_1_1) {
  2779. add_property_string(obj, "faultcode", fault_code);
  2780. if (strcmp(fault_code,"Client") == 0 ||
  2781. strcmp(fault_code,"Server") == 0 ||
  2782. strcmp(fault_code,"VersionMismatch") == 0 ||
  2783. strcmp(fault_code,"MustUnderstand") == 0) {
  2784. add_property_string(obj, "faultcodens", SOAP_1_1_ENV_NAMESPACE);
  2785. }
  2786. } else if (soap_version == SOAP_1_2) {
  2787. if (strcmp(fault_code,"Client") == 0) {
  2788. add_property_string(obj, "faultcode", "Sender");
  2789. add_property_string(obj, "faultcodens", SOAP_1_2_ENV_NAMESPACE);
  2790. } else if (strcmp(fault_code,"Server") == 0) {
  2791. add_property_string(obj, "faultcode", "Receiver");
  2792. add_property_string(obj, "faultcodens", SOAP_1_2_ENV_NAMESPACE);
  2793. } else if (strcmp(fault_code,"VersionMismatch") == 0 ||
  2794. strcmp(fault_code,"MustUnderstand") == 0 ||
  2795. strcmp(fault_code,"DataEncodingUnknown") == 0) {
  2796. add_property_string(obj, "faultcode", fault_code);
  2797. add_property_string(obj, "faultcodens", SOAP_1_2_ENV_NAMESPACE);
  2798. } else {
  2799. add_property_string(obj, "faultcode", fault_code);
  2800. }
  2801. }
  2802. }
  2803. }
  2804. if (fault_actor != NULL) {
  2805. add_property_string(obj, "faultactor", fault_actor);
  2806. }
  2807. if (fault_detail != NULL && Z_TYPE_P(fault_detail) != IS_UNDEF) {
  2808. add_property_zval(obj, "detail", fault_detail);
  2809. }
  2810. if (name != NULL) {
  2811. add_property_string(obj, "_name", name);
  2812. }
  2813. }
  2814. /* }}} */
  2815. static void deserialize_parameters(xmlNodePtr params, sdlFunctionPtr function, int *num_params, zval **parameters) /* {{{ */
  2816. {
  2817. int cur_param = 0,num_of_params = 0;
  2818. zval *tmp_parameters = NULL;
  2819. if (function != NULL) {
  2820. sdlParamPtr param;
  2821. xmlNodePtr val;
  2822. int use_names = 0;
  2823. if (function->requestParameters == NULL) {
  2824. return;
  2825. }
  2826. num_of_params = zend_hash_num_elements(function->requestParameters);
  2827. ZEND_HASH_FOREACH_PTR(function->requestParameters, param) {
  2828. if (get_node(params, param->paramName) != NULL) {
  2829. use_names = 1;
  2830. }
  2831. } ZEND_HASH_FOREACH_END();
  2832. if (use_names) {
  2833. tmp_parameters = safe_emalloc(num_of_params, sizeof(zval), 0);
  2834. ZEND_HASH_FOREACH_PTR(function->requestParameters, param) {
  2835. val = get_node(params, param->paramName);
  2836. if (!val) {
  2837. /* TODO: may be "nil" is not OK? */
  2838. ZVAL_NULL(&tmp_parameters[cur_param]);
  2839. } else {
  2840. master_to_zval(&tmp_parameters[cur_param], param->encode, val);
  2841. }
  2842. cur_param++;
  2843. } ZEND_HASH_FOREACH_END();
  2844. *parameters = tmp_parameters;
  2845. *num_params = num_of_params;
  2846. return;
  2847. }
  2848. }
  2849. if (params) {
  2850. xmlNodePtr trav;
  2851. num_of_params = 0;
  2852. trav = params;
  2853. while (trav != NULL) {
  2854. if (trav->type == XML_ELEMENT_NODE) {
  2855. num_of_params++;
  2856. }
  2857. trav = trav->next;
  2858. }
  2859. if (num_of_params == 1 &&
  2860. function &&
  2861. function->binding &&
  2862. function->binding->bindingType == BINDING_SOAP &&
  2863. ((sdlSoapBindingFunctionPtr)function->bindingAttributes)->style == SOAP_DOCUMENT &&
  2864. (function->requestParameters == NULL ||
  2865. zend_hash_num_elements(function->requestParameters) == 0) &&
  2866. strcmp((char *)params->name, function->functionName) == 0) {
  2867. num_of_params = 0;
  2868. } else if (num_of_params > 0) {
  2869. tmp_parameters = safe_emalloc(num_of_params, sizeof(zval), 0);
  2870. trav = params;
  2871. while (trav != 0 && cur_param < num_of_params) {
  2872. if (trav->type == XML_ELEMENT_NODE) {
  2873. encodePtr enc;
  2874. sdlParamPtr param = NULL;
  2875. if (function != NULL &&
  2876. (param = zend_hash_index_find_ptr(function->requestParameters, cur_param)) == NULL) {
  2877. soap_server_fault("Client", "Error cannot find parameter", NULL, NULL, NULL);
  2878. }
  2879. if (param == NULL) {
  2880. enc = NULL;
  2881. } else {
  2882. enc = param->encode;
  2883. }
  2884. master_to_zval(&tmp_parameters[cur_param], enc, trav);
  2885. cur_param++;
  2886. }
  2887. trav = trav->next;
  2888. }
  2889. }
  2890. }
  2891. if (num_of_params > cur_param) {
  2892. soap_server_fault("Client","Missing parameter", NULL, NULL, NULL);
  2893. }
  2894. (*parameters) = tmp_parameters;
  2895. (*num_params) = num_of_params;
  2896. }
  2897. /* }}} */
  2898. static sdlFunctionPtr find_function(sdlPtr sdl, xmlNodePtr func, zval* function_name) /* {{{ */
  2899. {
  2900. sdlFunctionPtr function;
  2901. function = get_function(sdl, (char*)func->name);
  2902. if (function && function->binding && function->binding->bindingType == BINDING_SOAP) {
  2903. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  2904. if (fnb->style == SOAP_DOCUMENT) {
  2905. if (func->children != NULL ||
  2906. (function->requestParameters != NULL &&
  2907. zend_hash_num_elements(function->requestParameters) > 0)) {
  2908. function = NULL;
  2909. }
  2910. }
  2911. }
  2912. if (sdl != NULL && function == NULL) {
  2913. function = get_doc_function(sdl, func);
  2914. }
  2915. if (function != NULL) {
  2916. ZVAL_STRING(function_name, (char *)function->functionName);
  2917. } else {
  2918. ZVAL_STRING(function_name, (char *)func->name);
  2919. }
  2920. return function;
  2921. }
  2922. /* }}} */
  2923. static sdlFunctionPtr deserialize_function_call(sdlPtr sdl, xmlDocPtr request, char* actor, zval *function_name, int *num_params, zval **parameters, int *version, soapHeader **headers) /* {{{ */
  2924. {
  2925. char* envelope_ns = NULL;
  2926. xmlNodePtr trav,env,head,body,func;
  2927. xmlAttrPtr attr;
  2928. sdlFunctionPtr function;
  2929. encode_reset_ns();
  2930. /* Get <Envelope> element */
  2931. env = NULL;
  2932. trav = request->children;
  2933. while (trav != NULL) {
  2934. if (trav->type == XML_ELEMENT_NODE) {
  2935. if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_1_ENV_NAMESPACE)) {
  2936. env = trav;
  2937. *version = SOAP_1_1;
  2938. envelope_ns = SOAP_1_1_ENV_NAMESPACE;
  2939. SOAP_GLOBAL(soap_version) = SOAP_1_1;
  2940. } else if (env == NULL && node_is_equal_ex(trav,"Envelope",SOAP_1_2_ENV_NAMESPACE)) {
  2941. env = trav;
  2942. *version = SOAP_1_2;
  2943. envelope_ns = SOAP_1_2_ENV_NAMESPACE;
  2944. SOAP_GLOBAL(soap_version) = SOAP_1_2;
  2945. } else {
  2946. soap_server_fault("VersionMismatch", "Wrong Version", NULL, NULL, NULL);
  2947. }
  2948. }
  2949. trav = trav->next;
  2950. }
  2951. if (env == NULL) {
  2952. soap_server_fault("Client", "looks like we got XML without \"Envelope\" element", NULL, NULL, NULL);
  2953. }
  2954. attr = env->properties;
  2955. while (attr != NULL) {
  2956. if (attr->ns == NULL) {
  2957. soap_server_fault("Client", "A SOAP Envelope element cannot have non Namespace qualified attributes", NULL, NULL, NULL);
  2958. } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) {
  2959. if (*version == SOAP_1_2) {
  2960. soap_server_fault("Client", "encodingStyle cannot be specified on the Envelope", NULL, NULL, NULL);
  2961. } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
  2962. soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL);
  2963. }
  2964. }
  2965. attr = attr->next;
  2966. }
  2967. /* Get <Header> element */
  2968. head = NULL;
  2969. trav = env->children;
  2970. while (trav != NULL && trav->type != XML_ELEMENT_NODE) {
  2971. trav = trav->next;
  2972. }
  2973. if (trav != NULL && node_is_equal_ex(trav,"Header",envelope_ns)) {
  2974. head = trav;
  2975. trav = trav->next;
  2976. }
  2977. /* Get <Body> element */
  2978. body = NULL;
  2979. while (trav != NULL && trav->type != XML_ELEMENT_NODE) {
  2980. trav = trav->next;
  2981. }
  2982. if (trav != NULL && node_is_equal_ex(trav,"Body",envelope_ns)) {
  2983. body = trav;
  2984. trav = trav->next;
  2985. }
  2986. while (trav != NULL && trav->type != XML_ELEMENT_NODE) {
  2987. trav = trav->next;
  2988. }
  2989. if (body == NULL) {
  2990. soap_server_fault("Client", "Body must be present in a SOAP envelope", NULL, NULL, NULL);
  2991. }
  2992. attr = body->properties;
  2993. while (attr != NULL) {
  2994. if (attr->ns == NULL) {
  2995. if (*version == SOAP_1_2) {
  2996. soap_server_fault("Client", "A SOAP Body element cannot have non Namespace qualified attributes", NULL, NULL, NULL);
  2997. }
  2998. } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) {
  2999. if (*version == SOAP_1_2) {
  3000. soap_server_fault("Client", "encodingStyle cannot be specified on the Body", NULL, NULL, NULL);
  3001. } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
  3002. soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL);
  3003. }
  3004. }
  3005. attr = attr->next;
  3006. }
  3007. if (trav != NULL && *version == SOAP_1_2) {
  3008. soap_server_fault("Client", "A SOAP 1.2 envelope can contain only Header and Body", NULL, NULL, NULL);
  3009. }
  3010. func = NULL;
  3011. trav = body->children;
  3012. while (trav != NULL) {
  3013. if (trav->type == XML_ELEMENT_NODE) {
  3014. /*
  3015. if (func != NULL) {
  3016. soap_server_fault("Client", "looks like we got \"Body\" with several functions call", NULL, NULL, NULL);
  3017. }
  3018. */
  3019. func = trav;
  3020. break; /* FIXME: the rest of body is ignored */
  3021. }
  3022. trav = trav->next;
  3023. }
  3024. if (func == NULL) {
  3025. function = get_doc_function(sdl, NULL);
  3026. if (function != NULL) {
  3027. ZVAL_STRING(function_name, (char *)function->functionName);
  3028. } else {
  3029. soap_server_fault("Client", "looks like we got \"Body\" without function call", NULL, NULL, NULL);
  3030. }
  3031. } else {
  3032. if (*version == SOAP_1_1) {
  3033. attr = get_attribute_ex(func->properties,"encodingStyle",SOAP_1_1_ENV_NAMESPACE);
  3034. if (attr && strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
  3035. soap_server_fault("Client","Unknown Data Encoding Style", NULL, NULL, NULL);
  3036. }
  3037. } else {
  3038. attr = get_attribute_ex(func->properties,"encodingStyle",SOAP_1_2_ENV_NAMESPACE);
  3039. if (attr && strcmp((char*)attr->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) {
  3040. soap_server_fault("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL);
  3041. }
  3042. }
  3043. function = find_function(sdl, func, function_name);
  3044. if (sdl != NULL && function == NULL) {
  3045. if (*version == SOAP_1_2) {
  3046. soap_server_fault("rpc:ProcedureNotPresent","Procedure not present", NULL, NULL, NULL);
  3047. } else {
  3048. php_error(E_ERROR, "Procedure '%s' not present", func->name);
  3049. }
  3050. }
  3051. }
  3052. *headers = NULL;
  3053. if (head) {
  3054. soapHeader *h, *last = NULL;
  3055. attr = head->properties;
  3056. while (attr != NULL) {
  3057. if (attr->ns == NULL) {
  3058. soap_server_fault("Client", "A SOAP Header element cannot have non Namespace qualified attributes", NULL, NULL, NULL);
  3059. } else if (attr_is_equal_ex(attr,"encodingStyle",SOAP_1_2_ENV_NAMESPACE)) {
  3060. if (*version == SOAP_1_2) {
  3061. soap_server_fault("Client", "encodingStyle cannot be specified on the Header", NULL, NULL, NULL);
  3062. } else if (strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
  3063. soap_server_fault("Client", "Unknown data encoding style", NULL, NULL, NULL);
  3064. }
  3065. }
  3066. attr = attr->next;
  3067. }
  3068. trav = head->children;
  3069. while (trav != NULL) {
  3070. if (trav->type == XML_ELEMENT_NODE) {
  3071. xmlNodePtr hdr_func = trav;
  3072. int mustUnderstand = 0;
  3073. if (*version == SOAP_1_1) {
  3074. attr = get_attribute_ex(hdr_func->properties,"encodingStyle",SOAP_1_1_ENV_NAMESPACE);
  3075. if (attr && strcmp((char*)attr->children->content,SOAP_1_1_ENC_NAMESPACE) != 0) {
  3076. soap_server_fault("Client","Unknown Data Encoding Style", NULL, NULL, NULL);
  3077. }
  3078. attr = get_attribute_ex(hdr_func->properties,"actor",envelope_ns);
  3079. if (attr != NULL) {
  3080. if (strcmp((char*)attr->children->content,SOAP_1_1_ACTOR_NEXT) != 0 &&
  3081. (actor == NULL || strcmp((char*)attr->children->content,actor) != 0)) {
  3082. goto ignore_header;
  3083. }
  3084. }
  3085. } else if (*version == SOAP_1_2) {
  3086. attr = get_attribute_ex(hdr_func->properties,"encodingStyle",SOAP_1_2_ENV_NAMESPACE);
  3087. if (attr && strcmp((char*)attr->children->content,SOAP_1_2_ENC_NAMESPACE) != 0) {
  3088. soap_server_fault("DataEncodingUnknown","Unknown Data Encoding Style", NULL, NULL, NULL);
  3089. }
  3090. attr = get_attribute_ex(hdr_func->properties,"role",envelope_ns);
  3091. if (attr != NULL) {
  3092. if (strcmp((char*)attr->children->content,SOAP_1_2_ACTOR_UNLIMATERECEIVER) != 0 &&
  3093. strcmp((char*)attr->children->content,SOAP_1_2_ACTOR_NEXT) != 0 &&
  3094. (actor == NULL || strcmp((char*)attr->children->content,actor) != 0)) {
  3095. goto ignore_header;
  3096. }
  3097. }
  3098. }
  3099. attr = get_attribute_ex(hdr_func->properties,"mustUnderstand",envelope_ns);
  3100. if (attr) {
  3101. if (strcmp((char*)attr->children->content,"1") == 0 ||
  3102. strcmp((char*)attr->children->content,"true") == 0) {
  3103. mustUnderstand = 1;
  3104. } else if (strcmp((char*)attr->children->content,"0") == 0 ||
  3105. strcmp((char*)attr->children->content,"false") == 0) {
  3106. mustUnderstand = 0;
  3107. } else {
  3108. soap_server_fault("Client","mustUnderstand value is not boolean", NULL, NULL, NULL);
  3109. }
  3110. }
  3111. h = emalloc(sizeof(soapHeader));
  3112. memset(h, 0, sizeof(soapHeader));
  3113. h->mustUnderstand = mustUnderstand;
  3114. h->function = find_function(sdl, hdr_func, &h->function_name);
  3115. if (!h->function && sdl && function && function->binding && function->binding->bindingType == BINDING_SOAP) {
  3116. sdlSoapBindingFunctionHeaderPtr hdr;
  3117. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  3118. if (fnb->input.headers) {
  3119. smart_str key = {0};
  3120. if (hdr_func->ns) {
  3121. smart_str_appends(&key, (char*)hdr_func->ns->href);
  3122. smart_str_appendc(&key, ':');
  3123. }
  3124. smart_str_appendl(&key, Z_STRVAL(h->function_name), Z_STRLEN(h->function_name));
  3125. smart_str_0(&key);
  3126. if ((hdr = zend_hash_find_ptr(fnb->input.headers, key.s)) != NULL) {
  3127. h->hdr = hdr;
  3128. }
  3129. smart_str_free(&key);
  3130. }
  3131. }
  3132. if (h->hdr) {
  3133. h->num_params = 1;
  3134. h->parameters = emalloc(sizeof(zval));
  3135. master_to_zval(&h->parameters[0], h->hdr->encode, hdr_func);
  3136. } else {
  3137. if (h->function && h->function->binding && h->function->binding->bindingType == BINDING_SOAP) {
  3138. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)h->function->bindingAttributes;
  3139. if (fnb->style == SOAP_RPC) {
  3140. hdr_func = hdr_func->children;
  3141. }
  3142. }
  3143. deserialize_parameters(hdr_func, h->function, &h->num_params, &h->parameters);
  3144. }
  3145. ZVAL_NULL(&h->retval);
  3146. if (last == NULL) {
  3147. *headers = h;
  3148. } else {
  3149. last->next = h;
  3150. }
  3151. last = h;
  3152. }
  3153. ignore_header:
  3154. trav = trav->next;
  3155. }
  3156. }
  3157. if (function && function->binding && function->binding->bindingType == BINDING_SOAP) {
  3158. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  3159. if (fnb->style == SOAP_RPC) {
  3160. func = func->children;
  3161. }
  3162. } else {
  3163. func = func->children;
  3164. }
  3165. deserialize_parameters(func, function, num_params, parameters);
  3166. encode_finish();
  3167. return function;
  3168. }
  3169. /* }}} */
  3170. static void set_soap_header_attributes(xmlNodePtr h, HashTable *ht, int version) /* {{{ */
  3171. {
  3172. zval *tmp;
  3173. if ((tmp = zend_hash_str_find(ht, "mustUnderstand", sizeof("mustUnderstand")-1)) != NULL &&
  3174. Z_TYPE_P(tmp) == IS_TRUE) {
  3175. if (version == SOAP_1_1) {
  3176. xmlSetProp(h, BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("1"));
  3177. } else {
  3178. xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":mustUnderstand"), BAD_CAST("true"));
  3179. }
  3180. }
  3181. if ((tmp = zend_hash_str_find(ht, "actor", sizeof("actor")-1)) != NULL) {
  3182. if (Z_TYPE_P(tmp) == IS_STRING) {
  3183. if (version == SOAP_1_1) {
  3184. xmlSetProp(h, BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(Z_STRVAL_P(tmp)));
  3185. } else {
  3186. xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(Z_STRVAL_P(tmp)));
  3187. }
  3188. } else if (Z_TYPE_P(tmp) == IS_LONG) {
  3189. if (version == SOAP_1_1) {
  3190. if (Z_LVAL_P(tmp) == SOAP_ACTOR_NEXT) {
  3191. xmlSetProp(h, BAD_CAST(SOAP_1_1_ENV_NS_PREFIX":actor"), BAD_CAST(SOAP_1_1_ACTOR_NEXT));
  3192. }
  3193. } else {
  3194. if (Z_LVAL_P(tmp) == SOAP_ACTOR_NEXT) {
  3195. xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NEXT));
  3196. } else if (Z_LVAL_P(tmp) == SOAP_ACTOR_NONE) {
  3197. xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_NONE));
  3198. } else if (Z_LVAL_P(tmp) == SOAP_ACTOR_UNLIMATERECEIVER) {
  3199. xmlSetProp(h, BAD_CAST(SOAP_1_2_ENV_NS_PREFIX":role"), BAD_CAST(SOAP_1_2_ACTOR_UNLIMATERECEIVER));
  3200. }
  3201. }
  3202. }
  3203. }
  3204. }
  3205. /* }}} */
  3206. static int serialize_response_call2(xmlNodePtr body, sdlFunctionPtr function, char *function_name, char *uri, zval *ret, int version, int main, xmlNodePtr *node) /* {{{ */
  3207. {
  3208. xmlNodePtr method = NULL, param;
  3209. sdlParamPtr parameter = NULL;
  3210. int param_count;
  3211. int style, use;
  3212. xmlNsPtr ns = NULL;
  3213. if (function != NULL && function->binding->bindingType == BINDING_SOAP) {
  3214. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  3215. style = fnb->style;
  3216. use = fnb->output.use;
  3217. if (style == SOAP_RPC) {
  3218. ns = encode_add_ns(body, fnb->output.ns);
  3219. if (function->responseName) {
  3220. method = xmlNewChild(body, ns, BAD_CAST(function->responseName), NULL);
  3221. } else if (function->responseParameters) {
  3222. method = xmlNewChild(body, ns, BAD_CAST(function->functionName), NULL);
  3223. }
  3224. }
  3225. } else {
  3226. style = main?SOAP_RPC:SOAP_DOCUMENT;
  3227. use = main?SOAP_ENCODED:SOAP_LITERAL;
  3228. if (style == SOAP_RPC) {
  3229. ns = encode_add_ns(body, uri);
  3230. method = xmlNewChild(body, ns, BAD_CAST(function_name), NULL);
  3231. }
  3232. }
  3233. if (function != NULL) {
  3234. if (function->responseParameters) {
  3235. param_count = zend_hash_num_elements(function->responseParameters);
  3236. } else {
  3237. param_count = 0;
  3238. }
  3239. } else {
  3240. param_count = 1;
  3241. }
  3242. if (param_count == 1) {
  3243. parameter = get_param(function, NULL, 0, TRUE);
  3244. if (style == SOAP_RPC) {
  3245. xmlNode *rpc_result;
  3246. if (main && version == SOAP_1_2) {
  3247. xmlNs *rpc_ns = xmlNewNs(body, BAD_CAST(RPC_SOAP12_NAMESPACE), BAD_CAST(RPC_SOAP12_NS_PREFIX));
  3248. rpc_result = xmlNewChild(method, rpc_ns, BAD_CAST("result"), NULL);
  3249. param = serialize_parameter(parameter, ret, 0, "return", use, method);
  3250. xmlNodeSetContent(rpc_result,param->name);
  3251. } else {
  3252. param = serialize_parameter(parameter, ret, 0, "return", use, method);
  3253. }
  3254. } else {
  3255. param = serialize_parameter(parameter, ret, 0, "return", use, body);
  3256. if (function && function->binding->bindingType == BINDING_SOAP) {
  3257. if (parameter && parameter->element) {
  3258. ns = encode_add_ns(param, parameter->element->namens);
  3259. xmlNodeSetName(param, BAD_CAST(parameter->element->name));
  3260. xmlSetNs(param, ns);
  3261. }
  3262. } else if (strcmp((char*)param->name,"return") == 0) {
  3263. ns = encode_add_ns(param, uri);
  3264. xmlNodeSetName(param, BAD_CAST(function_name));
  3265. xmlSetNs(param, ns);
  3266. }
  3267. }
  3268. } else if (param_count > 1 && Z_TYPE_P(ret) == IS_ARRAY) {
  3269. zval *data;
  3270. int i = 0;
  3271. zend_string *param_name;
  3272. zend_ulong param_index = i;
  3273. ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(ret), param_index, param_name, data) {
  3274. parameter = get_param(function, ZSTR_VAL(param_name), param_index, TRUE);
  3275. if (style == SOAP_RPC) {
  3276. param = serialize_parameter(parameter, data, i, ZSTR_VAL(param_name), use, method);
  3277. } else {
  3278. param = serialize_parameter(parameter, data, i, ZSTR_VAL(param_name), use, body);
  3279. if (function && function->binding->bindingType == BINDING_SOAP) {
  3280. if (parameter && parameter->element) {
  3281. ns = encode_add_ns(param, parameter->element->namens);
  3282. xmlNodeSetName(param, BAD_CAST(parameter->element->name));
  3283. xmlSetNs(param, ns);
  3284. }
  3285. }
  3286. }
  3287. i++;
  3288. param_index = i;
  3289. } ZEND_HASH_FOREACH_END();
  3290. }
  3291. if (use == SOAP_ENCODED && version == SOAP_1_2 && method != NULL) {
  3292. xmlSetNsProp(method, body->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
  3293. }
  3294. if (node) {
  3295. *node = method;
  3296. }
  3297. return use;
  3298. }
  3299. /* }}} */
  3300. static xmlDocPtr serialize_response_call(sdlFunctionPtr function, char *function_name, char *uri, zval *ret, soapHeader* headers, int version) /* {{{ */
  3301. {
  3302. xmlDocPtr doc;
  3303. xmlNodePtr envelope = NULL, body, param;
  3304. xmlNsPtr ns = NULL;
  3305. int use = SOAP_LITERAL;
  3306. xmlNodePtr head = NULL;
  3307. encode_reset_ns();
  3308. doc = xmlNewDoc(BAD_CAST("1.0"));
  3309. doc->charset = XML_CHAR_ENCODING_UTF8;
  3310. doc->encoding = xmlCharStrdup("UTF-8");
  3311. if (version == SOAP_1_1) {
  3312. envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
  3313. ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENV_NAMESPACE), BAD_CAST(SOAP_1_1_ENV_NS_PREFIX));
  3314. xmlSetNs(envelope,ns);
  3315. } else if (version == SOAP_1_2) {
  3316. envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
  3317. ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENV_NAMESPACE), BAD_CAST(SOAP_1_2_ENV_NS_PREFIX));
  3318. xmlSetNs(envelope,ns);
  3319. } else {
  3320. soap_server_fault("Server", "Unknown SOAP version", NULL, NULL, NULL);
  3321. }
  3322. xmlDocSetRootElement(doc, envelope);
  3323. if (Z_TYPE_P(ret) == IS_OBJECT &&
  3324. instanceof_function(Z_OBJCE_P(ret), soap_fault_class_entry)) {
  3325. char *detail_name;
  3326. HashTable* prop;
  3327. zval *tmp;
  3328. sdlFaultPtr fault = NULL;
  3329. char *fault_ns = NULL;
  3330. prop = Z_OBJPROP_P(ret);
  3331. if (headers &&
  3332. (tmp = zend_hash_str_find(prop, "headerfault", sizeof("headerfault")-1)) != NULL) {
  3333. encodePtr hdr_enc = NULL;
  3334. int hdr_use = SOAP_LITERAL;
  3335. zval *hdr_ret = tmp;
  3336. char *hdr_ns = headers->hdr?headers->hdr->ns:NULL;
  3337. char *hdr_name = Z_STRVAL(headers->function_name);
  3338. head = xmlNewChild(envelope, ns, BAD_CAST("Header"), NULL);
  3339. if (Z_TYPE_P(hdr_ret) == IS_OBJECT &&
  3340. instanceof_function(Z_OBJCE_P(hdr_ret), soap_header_class_entry)) {
  3341. HashTable* ht = Z_OBJPROP_P(hdr_ret);
  3342. sdlSoapBindingFunctionHeaderPtr hdr;
  3343. smart_str key = {0};
  3344. if ((tmp = zend_hash_str_find(ht, "namespace", sizeof("namespace")-1)) != NULL &&
  3345. Z_TYPE_P(tmp) == IS_STRING) {
  3346. smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  3347. smart_str_appendc(&key, ':');
  3348. hdr_ns = Z_STRVAL_P(tmp);
  3349. }
  3350. if ((tmp = zend_hash_str_find(ht, "name", sizeof("name")-1)) != NULL &&
  3351. Z_TYPE_P(tmp) == IS_STRING) {
  3352. smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  3353. hdr_name = Z_STRVAL_P(tmp);
  3354. }
  3355. smart_str_0(&key);
  3356. if (headers->hdr && headers->hdr->headerfaults &&
  3357. (hdr = zend_hash_find_ptr(headers->hdr->headerfaults, key.s)) != NULL) {
  3358. hdr_enc = hdr->encode;
  3359. hdr_use = hdr->use;
  3360. }
  3361. smart_str_free(&key);
  3362. if ((tmp = zend_hash_str_find(ht, "data", sizeof("data")-1)) != NULL) {
  3363. hdr_ret = tmp;
  3364. } else {
  3365. hdr_ret = NULL;
  3366. }
  3367. }
  3368. if (headers->function) {
  3369. if (serialize_response_call2(head, headers->function, Z_STRVAL(headers->function_name), uri, hdr_ret, version, 0, NULL) == SOAP_ENCODED) {
  3370. use = SOAP_ENCODED;
  3371. }
  3372. } else {
  3373. xmlNodePtr xmlHdr = master_to_xml(hdr_enc, hdr_ret, hdr_use, head);
  3374. if (hdr_name) {
  3375. xmlNodeSetName(xmlHdr, BAD_CAST(hdr_name));
  3376. }
  3377. if (hdr_ns) {
  3378. xmlNsPtr nsptr = encode_add_ns(xmlHdr, hdr_ns);
  3379. xmlSetNs(xmlHdr, nsptr);
  3380. }
  3381. }
  3382. }
  3383. body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
  3384. param = xmlNewChild(body, ns, BAD_CAST("Fault"), NULL);
  3385. if ((tmp = zend_hash_str_find(prop, "faultcodens", sizeof("faultcodens")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
  3386. fault_ns = Z_STRVAL_P(tmp);
  3387. }
  3388. use = SOAP_LITERAL;
  3389. if ((tmp = zend_hash_str_find(prop, "_name", sizeof("_name")-1)) != NULL && Z_TYPE_P(tmp) == IS_STRING) {
  3390. sdlFaultPtr tmp_fault;
  3391. if (function && function->faults &&
  3392. (tmp_fault = zend_hash_find_ptr(function->faults, Z_STR_P(tmp))) != NULL) {
  3393. fault = tmp_fault;
  3394. if (function->binding &&
  3395. function->binding->bindingType == BINDING_SOAP &&
  3396. fault->bindingAttributes) {
  3397. sdlSoapBindingFunctionFaultPtr fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
  3398. use = fb->use;
  3399. if (fault_ns == NULL) {
  3400. fault_ns = fb->ns;
  3401. }
  3402. }
  3403. }
  3404. } else if (function && function->faults &&
  3405. zend_hash_num_elements(function->faults) == 1) {
  3406. zend_hash_internal_pointer_reset(function->faults);
  3407. fault = zend_hash_get_current_data_ptr(function->faults);
  3408. if (function->binding &&
  3409. function->binding->bindingType == BINDING_SOAP &&
  3410. fault->bindingAttributes) {
  3411. sdlSoapBindingFunctionFaultPtr fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
  3412. use = fb->use;
  3413. if (fault_ns == NULL) {
  3414. fault_ns = fb->ns;
  3415. }
  3416. }
  3417. }
  3418. if (fault_ns == NULL &&
  3419. fault &&
  3420. fault->details &&
  3421. zend_hash_num_elements(fault->details) == 1) {
  3422. sdlParamPtr sparam;
  3423. zend_hash_internal_pointer_reset(fault->details);
  3424. sparam = zend_hash_get_current_data_ptr(fault->details);
  3425. if (sparam->element) {
  3426. fault_ns = sparam->element->namens;
  3427. }
  3428. }
  3429. if (version == SOAP_1_1) {
  3430. if ((tmp = zend_hash_str_find(prop, "faultcode", sizeof("faultcode")-1)) != NULL &&
  3431. Z_TYPE_P(tmp) == IS_STRING) {
  3432. xmlNodePtr node = xmlNewNode(NULL, BAD_CAST("faultcode"));
  3433. zend_string *str = php_escape_html_entities((unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), 0, 0, NULL);
  3434. xmlAddChild(param, node);
  3435. if (fault_ns) {
  3436. xmlNsPtr nsptr = encode_add_ns(node, fault_ns);
  3437. xmlChar *code = xmlBuildQName(BAD_CAST(ZSTR_VAL(str)), nsptr->prefix, NULL, 0);
  3438. xmlNodeSetContent(node, code);
  3439. xmlFree(code);
  3440. } else {
  3441. xmlNodeSetContentLen(node, BAD_CAST(ZSTR_VAL(str)), (int)ZSTR_LEN(str));
  3442. }
  3443. zend_string_release_ex(str, 0);
  3444. }
  3445. if ((tmp = zend_hash_str_find(prop, "faultstring", sizeof("faultstring")-1)) != NULL) {
  3446. xmlNodePtr node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, param);
  3447. xmlNodeSetName(node, BAD_CAST("faultstring"));
  3448. }
  3449. if ((tmp = zend_hash_str_find(prop, "faultactor", sizeof("faultactor")-1)) != NULL) {
  3450. xmlNodePtr node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, param);
  3451. xmlNodeSetName(node, BAD_CAST("faultactor"));
  3452. }
  3453. detail_name = "detail";
  3454. } else {
  3455. if ((tmp = zend_hash_str_find(prop, "faultcode", sizeof("faultcode")-1)) != NULL &&
  3456. Z_TYPE_P(tmp) == IS_STRING) {
  3457. xmlNodePtr node = xmlNewChild(param, ns, BAD_CAST("Code"), NULL);
  3458. zend_string *str = php_escape_html_entities((unsigned char*)Z_STRVAL_P(tmp), Z_STRLEN_P(tmp), 0, 0, NULL);
  3459. node = xmlNewChild(node, ns, BAD_CAST("Value"), NULL);
  3460. if (fault_ns) {
  3461. xmlNsPtr nsptr = encode_add_ns(node, fault_ns);
  3462. xmlChar *code = xmlBuildQName(BAD_CAST(ZSTR_VAL(str)), nsptr->prefix, NULL, 0);
  3463. xmlNodeSetContent(node, code);
  3464. xmlFree(code);
  3465. } else {
  3466. xmlNodeSetContentLen(node, BAD_CAST(ZSTR_VAL(str)), (int)ZSTR_LEN(str));
  3467. }
  3468. zend_string_release_ex(str, 0);
  3469. }
  3470. if ((tmp = zend_hash_str_find(prop, "faultstring", sizeof("faultstring")-1)) != NULL) {
  3471. xmlNodePtr node = xmlNewChild(param, ns, BAD_CAST("Reason"), NULL);
  3472. node = master_to_xml(get_conversion(IS_STRING), tmp, SOAP_LITERAL, node);
  3473. xmlNodeSetName(node, BAD_CAST("Text"));
  3474. xmlSetNs(node, ns);
  3475. }
  3476. detail_name = SOAP_1_2_ENV_NS_PREFIX":Detail";
  3477. }
  3478. if (fault && fault->details && zend_hash_num_elements(fault->details) == 1) {
  3479. xmlNodePtr node;
  3480. zval *detail = NULL;
  3481. sdlParamPtr sparam;
  3482. xmlNodePtr x;
  3483. if ((tmp = zend_hash_str_find(prop, "detail", sizeof("detail")-1)) != NULL &&
  3484. Z_TYPE_P(tmp) != IS_NULL) {
  3485. detail = tmp;
  3486. }
  3487. node = xmlNewNode(NULL, BAD_CAST(detail_name));
  3488. xmlAddChild(param, node);
  3489. zend_hash_internal_pointer_reset(fault->details);
  3490. sparam = zend_hash_get_current_data_ptr(fault->details);
  3491. if (detail &&
  3492. Z_TYPE_P(detail) == IS_OBJECT &&
  3493. sparam->element &&
  3494. zend_hash_num_elements(Z_OBJPROP_P(detail)) == 1 &&
  3495. (tmp = zend_hash_str_find(Z_OBJPROP_P(detail), sparam->element->name, strlen(sparam->element->name))) != NULL) {
  3496. detail = tmp;
  3497. }
  3498. x = serialize_parameter(sparam, detail, 1, NULL, use, node);
  3499. if (function &&
  3500. function->binding &&
  3501. function->binding->bindingType == BINDING_SOAP &&
  3502. function->bindingAttributes) {
  3503. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  3504. if (fnb->style == SOAP_RPC && !sparam->element) {
  3505. if (fault->bindingAttributes) {
  3506. sdlSoapBindingFunctionFaultPtr fb = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
  3507. if (fb->ns) {
  3508. xmlNsPtr ns = encode_add_ns(x, fb->ns);
  3509. xmlSetNs(x, ns);
  3510. }
  3511. }
  3512. } else {
  3513. if (sparam->element) {
  3514. ns = encode_add_ns(x, sparam->element->namens);
  3515. xmlNodeSetName(x, BAD_CAST(sparam->element->name));
  3516. xmlSetNs(x, ns);
  3517. }
  3518. }
  3519. }
  3520. if (use == SOAP_ENCODED && version == SOAP_1_2) {
  3521. xmlSetNsProp(x, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
  3522. }
  3523. } else if ((tmp = zend_hash_str_find(prop, "detail", sizeof("detail")-1)) != NULL &&
  3524. Z_TYPE_P(tmp) != IS_NULL) {
  3525. serialize_zval(tmp, NULL, detail_name, use, param);
  3526. }
  3527. } else {
  3528. if (headers) {
  3529. soapHeader *h;
  3530. head = xmlNewChild(envelope, ns, BAD_CAST("Header"), NULL);
  3531. h = headers;
  3532. while (h != NULL) {
  3533. if (Z_TYPE(h->retval) != IS_NULL) {
  3534. encodePtr hdr_enc = NULL;
  3535. int hdr_use = SOAP_LITERAL;
  3536. zval *hdr_ret = &h->retval;
  3537. char *hdr_ns = h->hdr?h->hdr->ns:NULL;
  3538. char *hdr_name = Z_STRVAL(h->function_name);
  3539. HashTable *ht = NULL;
  3540. if (Z_TYPE(h->retval) == IS_OBJECT &&
  3541. instanceof_function(Z_OBJCE(h->retval), soap_header_class_entry)) {
  3542. zval *tmp;
  3543. sdlSoapBindingFunctionHeaderPtr hdr;
  3544. smart_str key = {0};
  3545. ht = Z_OBJPROP(h->retval);
  3546. if ((tmp = zend_hash_str_find(ht, "namespace", sizeof("namespace")-1)) != NULL &&
  3547. Z_TYPE_P(tmp) == IS_STRING) {
  3548. smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  3549. smart_str_appendc(&key, ':');
  3550. hdr_ns = Z_STRVAL_P(tmp);
  3551. }
  3552. if ((tmp = zend_hash_str_find(ht, "name", sizeof("name")-1)) != NULL &&
  3553. Z_TYPE_P(tmp) == IS_STRING) {
  3554. smart_str_appendl(&key, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
  3555. hdr_name = Z_STRVAL_P(tmp);
  3556. }
  3557. smart_str_0(&key);
  3558. if (function && function->binding && function->binding->bindingType == BINDING_SOAP) {
  3559. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  3560. if (fnb->output.headers &&
  3561. (hdr = zend_hash_find_ptr(fnb->output.headers, key.s)) != NULL) {
  3562. hdr_enc = hdr->encode;
  3563. hdr_use = hdr->use;
  3564. }
  3565. }
  3566. smart_str_free(&key);
  3567. if ((tmp = zend_hash_str_find(ht, "data", sizeof("data")-1)) != NULL) {
  3568. hdr_ret = tmp;
  3569. } else {
  3570. hdr_ret = NULL;
  3571. }
  3572. }
  3573. if (h->function) {
  3574. xmlNodePtr xmlHdr = NULL;
  3575. if (serialize_response_call2(head, h->function, Z_STRVAL(h->function_name), uri, hdr_ret, version, 0, &xmlHdr) == SOAP_ENCODED) {
  3576. use = SOAP_ENCODED;
  3577. }
  3578. if (ht) {
  3579. set_soap_header_attributes(xmlHdr, ht, version);
  3580. }
  3581. } else {
  3582. xmlNodePtr xmlHdr = master_to_xml(hdr_enc, hdr_ret, hdr_use, head);
  3583. if (hdr_name) {
  3584. xmlNodeSetName(xmlHdr, BAD_CAST(hdr_name));
  3585. }
  3586. if (hdr_ns) {
  3587. xmlNsPtr nsptr = encode_add_ns(xmlHdr,hdr_ns);
  3588. xmlSetNs(xmlHdr, nsptr);
  3589. }
  3590. if (ht) {
  3591. set_soap_header_attributes(xmlHdr, ht, version);
  3592. }
  3593. }
  3594. }
  3595. h = h->next;
  3596. }
  3597. if (head->children == NULL) {
  3598. xmlUnlinkNode(head);
  3599. xmlFreeNode(head);
  3600. }
  3601. }
  3602. body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
  3603. if (serialize_response_call2(body, function, function_name, uri, ret, version, 1, NULL) == SOAP_ENCODED) {
  3604. use = SOAP_ENCODED;
  3605. }
  3606. }
  3607. if (use == SOAP_ENCODED) {
  3608. xmlNewNs(envelope, BAD_CAST(XSD_NAMESPACE), BAD_CAST(XSD_NS_PREFIX));
  3609. if (version == SOAP_1_1) {
  3610. xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENC_NAMESPACE), BAD_CAST(SOAP_1_1_ENC_NS_PREFIX));
  3611. xmlSetNsProp(envelope, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_1_ENC_NAMESPACE));
  3612. } else if (version == SOAP_1_2) {
  3613. xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENC_NAMESPACE), BAD_CAST(SOAP_1_2_ENC_NS_PREFIX));
  3614. }
  3615. }
  3616. encode_finish();
  3617. if (function && function->responseName == NULL &&
  3618. body->children == NULL && head == NULL) {
  3619. xmlFreeDoc(doc);
  3620. return NULL;
  3621. }
  3622. return doc;
  3623. }
  3624. /* }}} */
  3625. static xmlDocPtr serialize_function_call(zval *this_ptr, sdlFunctionPtr function, char *function_name, char *uri, zval *arguments, int arg_count, int version, HashTable *soap_headers) /* {{{ */
  3626. {
  3627. xmlDoc *doc;
  3628. xmlNodePtr envelope = NULL, body, method = NULL, head = NULL;
  3629. xmlNsPtr ns = NULL;
  3630. zval *zstyle, *zuse;
  3631. int i, style, use;
  3632. HashTable *hdrs = NULL;
  3633. encode_reset_ns();
  3634. doc = xmlNewDoc(BAD_CAST("1.0"));
  3635. doc->encoding = xmlCharStrdup("UTF-8");
  3636. doc->charset = XML_CHAR_ENCODING_UTF8;
  3637. if (version == SOAP_1_1) {
  3638. envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
  3639. ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENV_NAMESPACE), BAD_CAST(SOAP_1_1_ENV_NS_PREFIX));
  3640. xmlSetNs(envelope, ns);
  3641. } else if (version == SOAP_1_2) {
  3642. envelope = xmlNewDocNode(doc, NULL, BAD_CAST("Envelope"), NULL);
  3643. ns = xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENV_NAMESPACE), BAD_CAST(SOAP_1_2_ENV_NS_PREFIX));
  3644. xmlSetNs(envelope, ns);
  3645. } else {
  3646. soap_error0(E_ERROR, "Unknown SOAP version");
  3647. }
  3648. xmlDocSetRootElement(doc, envelope);
  3649. if (soap_headers) {
  3650. head = xmlNewChild(envelope, ns, BAD_CAST("Header"), NULL);
  3651. }
  3652. body = xmlNewChild(envelope, ns, BAD_CAST("Body"), NULL);
  3653. if (function && function->binding->bindingType == BINDING_SOAP) {
  3654. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)function->bindingAttributes;
  3655. hdrs = fnb->input.headers;
  3656. style = fnb->style;
  3657. /*FIXME: how to pass method name if style is SOAP_DOCUMENT */
  3658. /*style = SOAP_RPC;*/
  3659. use = fnb->input.use;
  3660. if (style == SOAP_RPC) {
  3661. ns = encode_add_ns(body, fnb->input.ns);
  3662. if (function->requestName) {
  3663. method = xmlNewChild(body, ns, BAD_CAST(function->requestName), NULL);
  3664. } else {
  3665. method = xmlNewChild(body, ns, BAD_CAST(function->functionName), NULL);
  3666. }
  3667. }
  3668. } else {
  3669. if ((zstyle = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "style", sizeof("style")-1)) != NULL &&
  3670. Z_TYPE_P(zstyle) == IS_LONG) {
  3671. style = Z_LVAL_P(zstyle);
  3672. } else {
  3673. style = SOAP_RPC;
  3674. }
  3675. /*FIXME: how to pass method name if style is SOAP_DOCUMENT */
  3676. /*style = SOAP_RPC;*/
  3677. if (style == SOAP_RPC) {
  3678. ns = encode_add_ns(body, uri);
  3679. if (function_name) {
  3680. method = xmlNewChild(body, ns, BAD_CAST(function_name), NULL);
  3681. } else if (function && function->requestName) {
  3682. method = xmlNewChild(body, ns, BAD_CAST(function->requestName), NULL);
  3683. } else if (function && function->functionName) {
  3684. method = xmlNewChild(body, ns, BAD_CAST(function->functionName), NULL);
  3685. } else {
  3686. method = body;
  3687. }
  3688. } else {
  3689. method = body;
  3690. }
  3691. if ((zuse = zend_hash_str_find(Z_OBJPROP_P(this_ptr), "use", sizeof("use")-1)) != NULL &&
  3692. Z_TYPE_P(zuse) == IS_LONG && Z_LVAL_P(zuse) == SOAP_LITERAL) {
  3693. use = SOAP_LITERAL;
  3694. } else {
  3695. use = SOAP_ENCODED;
  3696. }
  3697. }
  3698. for (i = 0;i < arg_count;i++) {
  3699. xmlNodePtr param;
  3700. sdlParamPtr parameter = get_param(function, NULL, i, FALSE);
  3701. if (style == SOAP_RPC) {
  3702. param = serialize_parameter(parameter, &arguments[i], i, NULL, use, method);
  3703. } else if (style == SOAP_DOCUMENT) {
  3704. param = serialize_parameter(parameter, &arguments[i], i, NULL, use, body);
  3705. if (function && function->binding->bindingType == BINDING_SOAP) {
  3706. if (parameter && parameter->element) {
  3707. ns = encode_add_ns(param, parameter->element->namens);
  3708. xmlNodeSetName(param, BAD_CAST(parameter->element->name));
  3709. xmlSetNs(param, ns);
  3710. }
  3711. }
  3712. }
  3713. }
  3714. if (function && function->requestParameters) {
  3715. int n = zend_hash_num_elements(function->requestParameters);
  3716. if (n > arg_count) {
  3717. for (i = arg_count; i < n; i++) {
  3718. xmlNodePtr param;
  3719. sdlParamPtr parameter = get_param(function, NULL, i, FALSE);
  3720. if (style == SOAP_RPC) {
  3721. param = serialize_parameter(parameter, NULL, i, NULL, use, method);
  3722. } else if (style == SOAP_DOCUMENT) {
  3723. param = serialize_parameter(parameter, NULL, i, NULL, use, body);
  3724. if (function && function->binding->bindingType == BINDING_SOAP) {
  3725. if (parameter && parameter->element) {
  3726. ns = encode_add_ns(param, parameter->element->namens);
  3727. xmlNodeSetName(param, BAD_CAST(parameter->element->name));
  3728. xmlSetNs(param, ns);
  3729. }
  3730. }
  3731. }
  3732. }
  3733. }
  3734. }
  3735. if (head) {
  3736. zval* header;
  3737. ZEND_HASH_FOREACH_VAL(soap_headers, header) {
  3738. HashTable *ht;
  3739. zval *name, *ns, *tmp;
  3740. if (Z_TYPE_P(header) != IS_OBJECT) {
  3741. continue;
  3742. }
  3743. ht = Z_OBJPROP_P(header);
  3744. if ((name = zend_hash_str_find(ht, "name", sizeof("name")-1)) != NULL &&
  3745. Z_TYPE_P(name) == IS_STRING &&
  3746. (ns = zend_hash_str_find(ht, "namespace", sizeof("namespace")-1)) != NULL &&
  3747. Z_TYPE_P(ns) == IS_STRING) {
  3748. xmlNodePtr h;
  3749. xmlNsPtr nsptr;
  3750. int hdr_use = SOAP_LITERAL;
  3751. encodePtr enc = NULL;
  3752. if (hdrs) {
  3753. smart_str key = {0};
  3754. sdlSoapBindingFunctionHeaderPtr hdr;
  3755. smart_str_appendl(&key, Z_STRVAL_P(ns), Z_STRLEN_P(ns));
  3756. smart_str_appendc(&key, ':');
  3757. smart_str_appendl(&key, Z_STRVAL_P(name), Z_STRLEN_P(name));
  3758. smart_str_0(&key);
  3759. if ((hdr = zend_hash_find_ptr(hdrs, key.s)) != NULL) {
  3760. hdr_use = hdr->use;
  3761. enc = hdr->encode;
  3762. if (hdr_use == SOAP_ENCODED) {
  3763. use = SOAP_ENCODED;
  3764. }
  3765. }
  3766. smart_str_free(&key);
  3767. }
  3768. if ((tmp = zend_hash_str_find(ht, "data", sizeof("data")-1)) != NULL) {
  3769. h = master_to_xml(enc, tmp, hdr_use, head);
  3770. xmlNodeSetName(h, BAD_CAST(Z_STRVAL_P(name)));
  3771. } else {
  3772. h = xmlNewNode(NULL, BAD_CAST(Z_STRVAL_P(name)));
  3773. xmlAddChild(head, h);
  3774. }
  3775. nsptr = encode_add_ns(h, Z_STRVAL_P(ns));
  3776. xmlSetNs(h, nsptr);
  3777. set_soap_header_attributes(h, ht, version);
  3778. }
  3779. } ZEND_HASH_FOREACH_END();
  3780. }
  3781. if (use == SOAP_ENCODED) {
  3782. xmlNewNs(envelope, BAD_CAST(XSD_NAMESPACE), BAD_CAST(XSD_NS_PREFIX));
  3783. if (version == SOAP_1_1) {
  3784. xmlNewNs(envelope, BAD_CAST(SOAP_1_1_ENC_NAMESPACE), BAD_CAST(SOAP_1_1_ENC_NS_PREFIX));
  3785. xmlSetNsProp(envelope, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_1_ENC_NAMESPACE));
  3786. } else if (version == SOAP_1_2) {
  3787. xmlNewNs(envelope, BAD_CAST(SOAP_1_2_ENC_NAMESPACE), BAD_CAST(SOAP_1_2_ENC_NS_PREFIX));
  3788. if (method) {
  3789. xmlSetNsProp(method, envelope->ns, BAD_CAST("encodingStyle"), BAD_CAST(SOAP_1_2_ENC_NAMESPACE));
  3790. }
  3791. }
  3792. }
  3793. encode_finish();
  3794. return doc;
  3795. }
  3796. /* }}} */
  3797. static xmlNodePtr serialize_parameter(sdlParamPtr param, zval *param_val, int index, char *name, int style, xmlNodePtr parent) /* {{{ */
  3798. {
  3799. char *paramName;
  3800. xmlNodePtr xmlParam;
  3801. char paramNameBuf[10];
  3802. if (param_val &&
  3803. Z_TYPE_P(param_val) == IS_OBJECT &&
  3804. Z_OBJCE_P(param_val) == soap_param_class_entry) {
  3805. zval *param_name;
  3806. zval *param_data;
  3807. if ((param_name = zend_hash_str_find(Z_OBJPROP_P(param_val), "param_name", sizeof("param_name")-1)) != NULL &&
  3808. Z_TYPE_P(param_name) == IS_STRING &&
  3809. (param_data = zend_hash_str_find(Z_OBJPROP_P(param_val), "param_data", sizeof("param_data")-1)) != NULL) {
  3810. param_val = param_data;
  3811. name = Z_STRVAL_P(param_name);
  3812. }
  3813. }
  3814. if (param != NULL && param->paramName != NULL) {
  3815. paramName = param->paramName;
  3816. } else {
  3817. if (name == NULL) {
  3818. paramName = paramNameBuf;
  3819. snprintf(paramName, sizeof(paramNameBuf), "param%d",index);
  3820. } else {
  3821. paramName = name;
  3822. }
  3823. }
  3824. xmlParam = serialize_zval(param_val, param, paramName, style, parent);
  3825. return xmlParam;
  3826. }
  3827. /* }}} */
  3828. static xmlNodePtr serialize_zval(zval *val, sdlParamPtr param, char *paramName, int style, xmlNodePtr parent) /* {{{ */
  3829. {
  3830. xmlNodePtr xmlParam;
  3831. encodePtr enc;
  3832. zval defval;
  3833. ZVAL_UNDEF(&defval);
  3834. if (param != NULL) {
  3835. enc = param->encode;
  3836. if (val == NULL) {
  3837. if (param->element) {
  3838. if (param->element->fixed) {
  3839. ZVAL_STRING(&defval, param->element->fixed);
  3840. val = &defval;
  3841. } else if (param->element->def && !param->element->nillable) {
  3842. ZVAL_STRING(&defval, param->element->def);
  3843. val = &defval;
  3844. }
  3845. }
  3846. }
  3847. } else {
  3848. enc = NULL;
  3849. }
  3850. xmlParam = master_to_xml(enc, val, style, parent);
  3851. zval_ptr_dtor(&defval);
  3852. if (!strcmp((char*)xmlParam->name, "BOGUS")) {
  3853. xmlNodeSetName(xmlParam, BAD_CAST(paramName));
  3854. }
  3855. return xmlParam;
  3856. }
  3857. /* }}} */
  3858. static sdlParamPtr get_param(sdlFunctionPtr function, char *param_name, int index, int response) /* {{{ */
  3859. {
  3860. sdlParamPtr tmp;
  3861. HashTable *ht;
  3862. if (function == NULL) {
  3863. return NULL;
  3864. }
  3865. if (response == FALSE) {
  3866. ht = function->requestParameters;
  3867. } else {
  3868. ht = function->responseParameters;
  3869. }
  3870. if (ht == NULL) {
  3871. return NULL;
  3872. }
  3873. if (param_name != NULL) {
  3874. if ((tmp = zend_hash_str_find_ptr(ht, param_name, strlen(param_name))) != NULL) {
  3875. return tmp;
  3876. } else {
  3877. ZEND_HASH_FOREACH_PTR(ht, tmp) {
  3878. if (tmp->paramName && strcmp(param_name, tmp->paramName) == 0) {
  3879. return tmp;
  3880. }
  3881. } ZEND_HASH_FOREACH_END();
  3882. }
  3883. } else {
  3884. if ((tmp = zend_hash_index_find_ptr(ht, index)) != NULL) {
  3885. return tmp;
  3886. }
  3887. }
  3888. return NULL;
  3889. }
  3890. /* }}} */
  3891. static sdlFunctionPtr get_function(sdlPtr sdl, const char *function_name) /* {{{ */
  3892. {
  3893. sdlFunctionPtr tmp;
  3894. int len = strlen(function_name);
  3895. char *str = estrndup(function_name,len);
  3896. php_strtolower(str,len);
  3897. if (sdl != NULL) {
  3898. if ((tmp = zend_hash_str_find_ptr(&sdl->functions, str, len)) != NULL) {
  3899. efree(str);
  3900. return tmp;
  3901. } else if (sdl->requests != NULL && (tmp = zend_hash_str_find_ptr(sdl->requests, str, len)) != NULL) {
  3902. efree(str);
  3903. return tmp;
  3904. }
  3905. }
  3906. efree(str);
  3907. return NULL;
  3908. }
  3909. /* }}} */
  3910. static sdlFunctionPtr get_doc_function(sdlPtr sdl, xmlNodePtr params) /* {{{ */
  3911. {
  3912. if (sdl) {
  3913. sdlFunctionPtr tmp;
  3914. sdlParamPtr param;
  3915. ZEND_HASH_FOREACH_PTR(&sdl->functions, tmp) {
  3916. if (tmp->binding && tmp->binding->bindingType == BINDING_SOAP) {
  3917. sdlSoapBindingFunctionPtr fnb = (sdlSoapBindingFunctionPtr)tmp->bindingAttributes;
  3918. if (fnb->style == SOAP_DOCUMENT) {
  3919. if (params == NULL) {
  3920. if (tmp->requestParameters == NULL ||
  3921. zend_hash_num_elements(tmp->requestParameters) == 0) {
  3922. return tmp;
  3923. }
  3924. } else if (tmp->requestParameters != NULL &&
  3925. zend_hash_num_elements(tmp->requestParameters) > 0) {
  3926. int ok = 1;
  3927. xmlNodePtr node = params;
  3928. ZEND_HASH_FOREACH_PTR(tmp->requestParameters, param) {
  3929. if (param->element) {
  3930. if (strcmp(param->element->name, (char*)node->name) != 0) {
  3931. ok = 0;
  3932. break;
  3933. }
  3934. if (param->element->namens != NULL && node->ns != NULL) {
  3935. if (strcmp(param->element->namens, (char*)node->ns->href) != 0) {
  3936. ok = 0;
  3937. break;
  3938. }
  3939. } else if ((void*)param->element->namens != (void*)node->ns) {
  3940. ok = 0;
  3941. break;
  3942. }
  3943. } else if (strcmp(param->paramName, (char*)node->name) != 0) {
  3944. ok = 0;
  3945. break;
  3946. }
  3947. node = node->next;
  3948. } ZEND_HASH_FOREACH_END();
  3949. if (ok /*&& node == NULL*/) {
  3950. return tmp;
  3951. }
  3952. }
  3953. }
  3954. }
  3955. } ZEND_HASH_FOREACH_END();
  3956. }
  3957. return NULL;
  3958. }
  3959. /* }}} */
  3960. static void function_to_string(sdlFunctionPtr function, smart_str *buf) /* {{{ */
  3961. {
  3962. int i = 0;
  3963. sdlParamPtr param;
  3964. if (function->responseParameters &&
  3965. zend_hash_num_elements(function->responseParameters) > 0) {
  3966. if (zend_hash_num_elements(function->responseParameters) == 1) {
  3967. zend_hash_internal_pointer_reset(function->responseParameters);
  3968. param = zend_hash_get_current_data_ptr(function->responseParameters);
  3969. if (param->encode && param->encode->details.type_str) {
  3970. smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str));
  3971. smart_str_appendc(buf, ' ');
  3972. } else {
  3973. smart_str_appendl(buf, "UNKNOWN ", 8);
  3974. }
  3975. } else {
  3976. i = 0;
  3977. smart_str_appendl(buf, "list(", 5);
  3978. ZEND_HASH_FOREACH_PTR(function->responseParameters, param) {
  3979. if (i > 0) {
  3980. smart_str_appendl(buf, ", ", 2);
  3981. }
  3982. if (param->encode && param->encode->details.type_str) {
  3983. smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str));
  3984. } else {
  3985. smart_str_appendl(buf, "UNKNOWN", 7);
  3986. }
  3987. smart_str_appendl(buf, " $", 2);
  3988. smart_str_appendl(buf, param->paramName, strlen(param->paramName));
  3989. i++;
  3990. } ZEND_HASH_FOREACH_END();
  3991. smart_str_appendl(buf, ") ", 2);
  3992. }
  3993. } else {
  3994. smart_str_appendl(buf, "void ", 5);
  3995. }
  3996. smart_str_appendl(buf, function->functionName, strlen(function->functionName));
  3997. smart_str_appendc(buf, '(');
  3998. if (function->requestParameters) {
  3999. i = 0;
  4000. ZEND_HASH_FOREACH_PTR(function->requestParameters, param) {
  4001. if (i > 0) {
  4002. smart_str_appendl(buf, ", ", 2);
  4003. }
  4004. if (param->encode && param->encode->details.type_str) {
  4005. smart_str_appendl(buf, param->encode->details.type_str, strlen(param->encode->details.type_str));
  4006. } else {
  4007. smart_str_appendl(buf, "UNKNOWN", 7);
  4008. }
  4009. smart_str_appendl(buf, " $", 2);
  4010. smart_str_appendl(buf, param->paramName, strlen(param->paramName));
  4011. i++;
  4012. } ZEND_HASH_FOREACH_END();
  4013. }
  4014. smart_str_appendc(buf, ')');
  4015. smart_str_0(buf);
  4016. }
  4017. /* }}} */
  4018. static void model_to_string(sdlContentModelPtr model, smart_str *buf, int level) /* {{{ */
  4019. {
  4020. int i;
  4021. switch (model->kind) {
  4022. case XSD_CONTENT_ELEMENT:
  4023. type_to_string(model->u.element, buf, level);
  4024. smart_str_appendl(buf, ";\n", 2);
  4025. break;
  4026. case XSD_CONTENT_ANY:
  4027. for (i = 0;i < level;i++) {
  4028. smart_str_appendc(buf, ' ');
  4029. }
  4030. smart_str_appendl(buf, "<anyXML> any;\n", sizeof("<anyXML> any;\n")-1);
  4031. break;
  4032. case XSD_CONTENT_SEQUENCE:
  4033. case XSD_CONTENT_ALL:
  4034. case XSD_CONTENT_CHOICE: {
  4035. sdlContentModelPtr tmp;
  4036. ZEND_HASH_FOREACH_PTR(model->u.content, tmp) {
  4037. model_to_string(tmp, buf, level);
  4038. } ZEND_HASH_FOREACH_END();
  4039. break;
  4040. }
  4041. case XSD_CONTENT_GROUP:
  4042. model_to_string(model->u.group->model, buf, level);
  4043. default:
  4044. break;
  4045. }
  4046. }
  4047. /* }}} */
  4048. static void type_to_string(sdlTypePtr type, smart_str *buf, int level) /* {{{ */
  4049. {
  4050. int i;
  4051. smart_str spaces = {0};
  4052. for (i = 0;i < level;i++) {
  4053. smart_str_appendc(&spaces, ' ');
  4054. }
  4055. if (spaces.s) {
  4056. smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s));
  4057. }
  4058. switch (type->kind) {
  4059. case XSD_TYPEKIND_SIMPLE:
  4060. if (type->encode) {
  4061. smart_str_appendl(buf, type->encode->details.type_str, strlen(type->encode->details.type_str));
  4062. smart_str_appendc(buf, ' ');
  4063. } else {
  4064. smart_str_appendl(buf, "anyType ", sizeof("anyType ")-1);
  4065. }
  4066. smart_str_appendl(buf, type->name, strlen(type->name));
  4067. break;
  4068. case XSD_TYPEKIND_LIST:
  4069. smart_str_appendl(buf, "list ", 5);
  4070. smart_str_appendl(buf, type->name, strlen(type->name));
  4071. if (type->elements) {
  4072. sdlTypePtr item_type;
  4073. smart_str_appendl(buf, " {", 2);
  4074. ZEND_HASH_FOREACH_PTR(type->elements, item_type) {
  4075. smart_str_appendl(buf, item_type->name, strlen(item_type->name));
  4076. } ZEND_HASH_FOREACH_END();
  4077. smart_str_appendc(buf, '}');
  4078. }
  4079. break;
  4080. case XSD_TYPEKIND_UNION:
  4081. smart_str_appendl(buf, "union ", 6);
  4082. smart_str_appendl(buf, type->name, strlen(type->name));
  4083. if (type->elements) {
  4084. sdlTypePtr item_type;
  4085. int first = 0;
  4086. smart_str_appendl(buf, " {", 2);
  4087. ZEND_HASH_FOREACH_PTR(type->elements, item_type) {
  4088. if (!first) {
  4089. smart_str_appendc(buf, ',');
  4090. first = 0;
  4091. }
  4092. smart_str_appendl(buf, item_type->name, strlen(item_type->name));
  4093. } ZEND_HASH_FOREACH_END();
  4094. smart_str_appendc(buf, '}');
  4095. }
  4096. break;
  4097. case XSD_TYPEKIND_COMPLEX:
  4098. case XSD_TYPEKIND_RESTRICTION:
  4099. case XSD_TYPEKIND_EXTENSION:
  4100. if (type->encode &&
  4101. (type->encode->details.type == IS_ARRAY ||
  4102. type->encode->details.type == SOAP_ENC_ARRAY)) {
  4103. sdlAttributePtr attr;
  4104. sdlExtraAttributePtr ext;
  4105. if (type->attributes &&
  4106. (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_1_ENC_NAMESPACE":arrayType",
  4107. sizeof(SOAP_1_1_ENC_NAMESPACE":arrayType")-1)) != NULL &&
  4108. attr->extraAttributes &&
  4109. (ext = zend_hash_str_find_ptr(attr->extraAttributes, WSDL_NAMESPACE":arrayType", sizeof(WSDL_NAMESPACE":arrayType")-1)) != NULL) {
  4110. char *end = strchr(ext->val, '[');
  4111. int len;
  4112. if (end == NULL) {
  4113. len = strlen(ext->val);
  4114. } else {
  4115. len = end - ext->val;
  4116. }
  4117. if (len == 0) {
  4118. smart_str_appendl(buf, "anyType", sizeof("anyType")-1);
  4119. } else {
  4120. smart_str_appendl(buf, ext->val, len);
  4121. }
  4122. smart_str_appendc(buf, ' ');
  4123. smart_str_appendl(buf, type->name, strlen(type->name));
  4124. if (end != NULL) {
  4125. smart_str_appends(buf, end);
  4126. }
  4127. } else {
  4128. sdlTypePtr elementType;
  4129. if (type->attributes &&
  4130. (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_2_ENC_NAMESPACE":itemType",
  4131. sizeof(SOAP_1_2_ENC_NAMESPACE":itemType")-1)) != NULL &&
  4132. attr->extraAttributes &&
  4133. (ext = zend_hash_str_find_ptr(attr->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":arrayType")-1)) != NULL) {
  4134. smart_str_appends(buf, ext->val);
  4135. smart_str_appendc(buf, ' ');
  4136. } else if (type->elements &&
  4137. zend_hash_num_elements(type->elements) == 1 &&
  4138. (zend_hash_internal_pointer_reset(type->elements),
  4139. (elementType = zend_hash_get_current_data_ptr(type->elements)) != NULL) &&
  4140. elementType->encode && elementType->encode->details.type_str) {
  4141. smart_str_appends(buf, elementType->encode->details.type_str);
  4142. smart_str_appendc(buf, ' ');
  4143. } else {
  4144. smart_str_appendl(buf, "anyType ", 8);
  4145. }
  4146. smart_str_appendl(buf, type->name, strlen(type->name));
  4147. if (type->attributes &&
  4148. (attr = zend_hash_str_find_ptr(type->attributes, SOAP_1_2_ENC_NAMESPACE":arraySize",
  4149. sizeof(SOAP_1_2_ENC_NAMESPACE":arraySize")-1)) != NULL &&
  4150. attr->extraAttributes &&
  4151. (ext = zend_hash_str_find_ptr(attr->extraAttributes, WSDL_NAMESPACE":itemType", sizeof(WSDL_NAMESPACE":arraySize")-1)) != NULL) {
  4152. smart_str_appendc(buf, '[');
  4153. smart_str_appends(buf, ext->val);
  4154. smart_str_appendc(buf, ']');
  4155. } else {
  4156. smart_str_appendl(buf, "[]", 2);
  4157. }
  4158. }
  4159. } else {
  4160. smart_str_appendl(buf, "struct ", 7);
  4161. smart_str_appendl(buf, type->name, strlen(type->name));
  4162. smart_str_appendc(buf, ' ');
  4163. smart_str_appendl(buf, "{\n", 2);
  4164. if ((type->kind == XSD_TYPEKIND_RESTRICTION ||
  4165. type->kind == XSD_TYPEKIND_EXTENSION) && type->encode) {
  4166. encodePtr enc = type->encode;
  4167. while (enc && enc->details.sdl_type &&
  4168. enc != enc->details.sdl_type->encode &&
  4169. enc->details.sdl_type->kind != XSD_TYPEKIND_SIMPLE &&
  4170. enc->details.sdl_type->kind != XSD_TYPEKIND_LIST &&
  4171. enc->details.sdl_type->kind != XSD_TYPEKIND_UNION) {
  4172. enc = enc->details.sdl_type->encode;
  4173. }
  4174. if (enc) {
  4175. if (spaces.s) {
  4176. smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s));
  4177. }
  4178. smart_str_appendc(buf, ' ');
  4179. smart_str_appendl(buf, type->encode->details.type_str, strlen(type->encode->details.type_str));
  4180. smart_str_appendl(buf, " _;\n", 4);
  4181. }
  4182. }
  4183. if (type->model) {
  4184. model_to_string(type->model, buf, level+1);
  4185. }
  4186. if (type->attributes) {
  4187. sdlAttributePtr attr;
  4188. ZEND_HASH_FOREACH_PTR(type->attributes, attr) {
  4189. if (spaces.s) {
  4190. smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s));
  4191. }
  4192. smart_str_appendc(buf, ' ');
  4193. if (attr->encode && attr->encode->details.type_str) {
  4194. smart_str_appends(buf, attr->encode->details.type_str);
  4195. smart_str_appendc(buf, ' ');
  4196. } else {
  4197. smart_str_appendl(buf, "UNKNOWN ", 8);
  4198. }
  4199. smart_str_appends(buf, attr->name);
  4200. smart_str_appendl(buf, ";\n", 2);
  4201. } ZEND_HASH_FOREACH_END();
  4202. }
  4203. if (spaces.s) {
  4204. smart_str_appendl(buf, ZSTR_VAL(spaces.s), ZSTR_LEN(spaces.s));
  4205. }
  4206. smart_str_appendc(buf, '}');
  4207. }
  4208. break;
  4209. default:
  4210. break;
  4211. }
  4212. smart_str_free(&spaces);
  4213. smart_str_0(buf);
  4214. }
  4215. /* }}} */
  4216. static void delete_url(void *handle) /* {{{ */
  4217. {
  4218. php_url_free((php_url*)handle);
  4219. }
  4220. /* }}} */
  4221. static void delete_service(void *data) /* {{{ */
  4222. {
  4223. soapServicePtr service = (soapServicePtr)data;
  4224. if (service->soap_functions.ft) {
  4225. zend_hash_destroy(service->soap_functions.ft);
  4226. efree(service->soap_functions.ft);
  4227. }
  4228. if (service->typemap) {
  4229. zend_hash_destroy(service->typemap);
  4230. efree(service->typemap);
  4231. }
  4232. if (service->soap_class.argc) {
  4233. int i;
  4234. for (i = 0; i < service->soap_class.argc;i++) {
  4235. zval_ptr_dtor(&service->soap_class.argv[i]);
  4236. }
  4237. efree(service->soap_class.argv);
  4238. }
  4239. if (service->actor) {
  4240. efree(service->actor);
  4241. }
  4242. if (service->uri) {
  4243. efree(service->uri);
  4244. }
  4245. if (service->sdl) {
  4246. delete_sdl(service->sdl);
  4247. }
  4248. if (service->encoding) {
  4249. xmlCharEncCloseFunc(service->encoding);
  4250. }
  4251. if (service->class_map) {
  4252. zend_hash_destroy(service->class_map);
  4253. FREE_HASHTABLE(service->class_map);
  4254. }
  4255. zval_ptr_dtor(&service->soap_object);
  4256. efree(service);
  4257. }
  4258. /* }}} */
  4259. static void delete_hashtable(void *data) /* {{{ */
  4260. {
  4261. HashTable *ht = (HashTable*)data;
  4262. zend_hash_destroy(ht);
  4263. efree(ht);
  4264. }
  4265. /* }}} */
  4266. /*
  4267. * Local variables:
  4268. * tab-width: 4
  4269. * c-basic-offset: 4
  4270. * indent-tabs-mode: t
  4271. * End:
  4272. * vim600: sw=4 ts=4 fdm=marker
  4273. * vim<600: sw=4 ts=4
  4274. */