soap.c 141 KB

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