soap.c 165 KB

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