php_sdl.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 5 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997-2016 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Brad Lafountain <rodif_bl@yahoo.com> |
  16. | Shane Caraveo <shane@caraveo.com> |
  17. | Dmitry Stogov <dmitry@zend.com> |
  18. +----------------------------------------------------------------------+
  19. */
  20. /* $Id$ */
  21. #include "php_soap.h"
  22. #include "ext/libxml/php_libxml.h"
  23. #include "libxml/uri.h"
  24. #include "ext/standard/md5.h"
  25. #include "zend_virtual_cwd.h"
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #ifndef O_BINARY
  30. # define O_BINARY 0
  31. #endif
  32. static void delete_fault(void *fault);
  33. static void delete_fault_persistent(void *fault);
  34. static void delete_binding(void *binding);
  35. static void delete_binding_persistent(void *binding);
  36. static void delete_function(void *function);
  37. static void delete_function_persistent(void *function);
  38. static void delete_parameter(void *parameter);
  39. static void delete_parameter_persistent(void *parameter);
  40. static void delete_header(void *header);
  41. static void delete_header_persistent(void *header);
  42. static void delete_document(void *doc_ptr);
  43. encodePtr get_encoder_from_prefix(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
  44. {
  45. encodePtr enc = NULL;
  46. xmlNsPtr nsptr;
  47. char *ns, *cptype;
  48. parse_namespace(type, &cptype, &ns);
  49. nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
  50. if (nsptr != NULL) {
  51. enc = get_encoder(sdl, (char*)nsptr->href, cptype);
  52. if (enc == NULL) {
  53. enc = get_encoder_ex(sdl, cptype, strlen(cptype));
  54. }
  55. } else {
  56. enc = get_encoder_ex(sdl, (char*)type, xmlStrlen(type));
  57. }
  58. efree(cptype);
  59. if (ns) {efree(ns);}
  60. return enc;
  61. }
  62. static sdlTypePtr get_element(sdlPtr sdl, xmlNodePtr node, const xmlChar *type)
  63. {
  64. sdlTypePtr ret = NULL;
  65. if (sdl->elements) {
  66. xmlNsPtr nsptr;
  67. char *ns, *cptype;
  68. sdlTypePtr *sdl_type;
  69. parse_namespace(type, &cptype, &ns);
  70. nsptr = xmlSearchNs(node->doc, node, BAD_CAST(ns));
  71. if (nsptr != NULL) {
  72. int ns_len = xmlStrlen(nsptr->href);
  73. int type_len = strlen(cptype);
  74. int len = ns_len + type_len + 1;
  75. char *nscat = emalloc(len + 1);
  76. memcpy(nscat, nsptr->href, ns_len);
  77. nscat[ns_len] = ':';
  78. memcpy(nscat+ns_len+1, cptype, type_len);
  79. nscat[len] = '\0';
  80. if (zend_hash_find(sdl->elements, nscat, len + 1, (void **)&sdl_type) == SUCCESS) {
  81. ret = *sdl_type;
  82. } else if (zend_hash_find(sdl->elements, (char*)type, type_len + 1, (void **)&sdl_type) == SUCCESS) {
  83. ret = *sdl_type;
  84. }
  85. efree(nscat);
  86. } else {
  87. if (zend_hash_find(sdl->elements, (char*)type, xmlStrlen(type) + 1, (void **)&sdl_type) == SUCCESS) {
  88. ret = *sdl_type;
  89. }
  90. }
  91. efree(cptype);
  92. if (ns) {efree(ns);}
  93. }
  94. return ret;
  95. }
  96. encodePtr get_encoder(sdlPtr sdl, const char *ns, const char *type)
  97. {
  98. encodePtr enc = NULL;
  99. char *nscat;
  100. int ns_len = ns ? strlen(ns) : 0;
  101. int type_len = strlen(type);
  102. int len = ns_len + type_len + 1;
  103. nscat = emalloc(len + 1);
  104. memcpy(nscat, ns, ns_len);
  105. nscat[ns_len] = ':';
  106. memcpy(nscat+ns_len+1, type, type_len);
  107. nscat[len] = '\0';
  108. enc = get_encoder_ex(sdl, nscat, len);
  109. if (enc == NULL &&
  110. ((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 &&
  111. memcmp(ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) ||
  112. (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 &&
  113. memcmp(ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) {
  114. char *enc_nscat;
  115. int enc_ns_len;
  116. int enc_len;
  117. enc_ns_len = sizeof(XSD_NAMESPACE)-1;
  118. enc_len = enc_ns_len + type_len + 1;
  119. enc_nscat = emalloc(enc_len + 1);
  120. memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1);
  121. enc_nscat[enc_ns_len] = ':';
  122. memcpy(enc_nscat+enc_ns_len+1, type, type_len);
  123. enc_nscat[enc_len] = '\0';
  124. enc = get_encoder_ex(NULL, enc_nscat, enc_len);
  125. efree(enc_nscat);
  126. if (enc && sdl) {
  127. encodePtr new_enc = pemalloc(sizeof(encode), sdl->is_persistent);
  128. memcpy(new_enc, enc, sizeof(encode));
  129. if (sdl->is_persistent) {
  130. new_enc->details.ns = zend_strndup(ns, ns_len);
  131. new_enc->details.type_str = strdup(new_enc->details.type_str);
  132. } else {
  133. new_enc->details.ns = estrndup(ns, ns_len);
  134. new_enc->details.type_str = estrdup(new_enc->details.type_str);
  135. }
  136. if (sdl->encoders == NULL) {
  137. sdl->encoders = pemalloc(sizeof(HashTable), sdl->is_persistent);
  138. zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, sdl->is_persistent);
  139. }
  140. zend_hash_update(sdl->encoders, nscat, len + 1, &new_enc, sizeof(encodePtr), NULL);
  141. enc = new_enc;
  142. }
  143. }
  144. efree(nscat);
  145. return enc;
  146. }
  147. encodePtr get_encoder_ex(sdlPtr sdl, const char *nscat, int len)
  148. {
  149. encodePtr *enc;
  150. TSRMLS_FETCH();
  151. if (zend_hash_find(&SOAP_GLOBAL(defEnc), (char*)nscat, len + 1, (void **)&enc) == SUCCESS) {
  152. return (*enc);
  153. } else if (sdl && sdl->encoders && zend_hash_find(sdl->encoders, (char*)nscat, len + 1, (void **)&enc) == SUCCESS) {
  154. return (*enc);
  155. }
  156. return NULL;
  157. }
  158. sdlBindingPtr get_binding_from_type(sdlPtr sdl, int type)
  159. {
  160. sdlBindingPtr *binding;
  161. if (sdl == NULL) {
  162. return NULL;
  163. }
  164. for (zend_hash_internal_pointer_reset(sdl->bindings);
  165. zend_hash_get_current_data(sdl->bindings, (void **) &binding) == SUCCESS;
  166. zend_hash_move_forward(sdl->bindings)) {
  167. if ((*binding)->bindingType == type) {
  168. return *binding;
  169. }
  170. }
  171. return NULL;
  172. }
  173. sdlBindingPtr get_binding_from_name(sdlPtr sdl, char *name, char *ns)
  174. {
  175. sdlBindingPtr binding = NULL;
  176. smart_str key = {0};
  177. smart_str_appends(&key, ns);
  178. smart_str_appendc(&key, ':');
  179. smart_str_appends(&key, name);
  180. smart_str_0(&key);
  181. zend_hash_find(sdl->bindings, key.c, key.len, (void **)&binding);
  182. smart_str_free(&key);
  183. return binding;
  184. }
  185. static int is_wsdl_element(xmlNodePtr node)
  186. {
  187. if (node->ns && strcmp((char*)node->ns->href, WSDL_NAMESPACE) != 0) {
  188. xmlAttrPtr attr;
  189. if ((attr = get_attribute_ex(node->properties, "required", WSDL_NAMESPACE)) != NULL &&
  190. attr->children && attr->children->content &&
  191. (strcmp((char*)attr->children->content, "1") == 0 ||
  192. strcmp((char*)attr->children->content, "true") == 0)) {
  193. soap_error1(E_ERROR, "Parsing WSDL: Unknown required WSDL extension '%s'", node->ns->href);
  194. }
  195. return 0;
  196. }
  197. return 1;
  198. }
  199. void sdl_set_uri_credentials(sdlCtx *ctx, char *uri TSRMLS_DC)
  200. {
  201. char *s;
  202. int l1, l2;
  203. zval *context = NULL;
  204. zval **header = NULL;
  205. /* check if we load xsd from the same server */
  206. s = strstr(ctx->sdl->source, "://");
  207. if (!s) return;
  208. s = strchr(s+3, '/');
  209. l1 = s ? (s - ctx->sdl->source) : strlen(ctx->sdl->source);
  210. s = strstr((char*)uri, "://");
  211. if (!s) return;
  212. s = strchr(s+3, '/');
  213. l2 = s ? (s - (char*)uri) : strlen((char*)uri);
  214. if (l1 != l2) {
  215. /* check for http://...:80/ */
  216. if (l1 > 11 &&
  217. ctx->sdl->source[4] == ':' &&
  218. ctx->sdl->source[l1-3] == ':' &&
  219. ctx->sdl->source[l1-2] == '8' &&
  220. ctx->sdl->source[l1-1] == '0') {
  221. l1 -= 3;
  222. }
  223. if (l2 > 11 &&
  224. uri[4] == ':' &&
  225. uri[l2-3] == ':' &&
  226. uri[l2-2] == '8' &&
  227. uri[l2-1] == '0') {
  228. l2 -= 3;
  229. }
  230. /* check for https://...:443/ */
  231. if (l1 > 13 &&
  232. ctx->sdl->source[4] == 's' &&
  233. ctx->sdl->source[l1-4] == ':' &&
  234. ctx->sdl->source[l1-3] == '4' &&
  235. ctx->sdl->source[l1-2] == '4' &&
  236. ctx->sdl->source[l1-1] == '3') {
  237. l1 -= 4;
  238. }
  239. if (l2 > 13 &&
  240. uri[4] == 's' &&
  241. uri[l2-4] == ':' &&
  242. uri[l2-3] == '4' &&
  243. uri[l2-2] == '4' &&
  244. uri[l2-1] == '3') {
  245. l2 -= 4;
  246. }
  247. }
  248. if (l1 != l2 || memcmp(ctx->sdl->source, uri, l1) != 0) {
  249. /* another server. clear authentication credentals */
  250. context = php_libxml_switch_context(NULL TSRMLS_CC);
  251. php_libxml_switch_context(context TSRMLS_CC);
  252. if (context) {
  253. ctx->context = php_stream_context_from_zval(context, 1);
  254. if (ctx->context &&
  255. php_stream_context_get_option(ctx->context, "http", "header", &header) == SUCCESS) {
  256. s = strstr(Z_STRVAL_PP(header), "Authorization: Basic");
  257. if (s && (s == Z_STRVAL_PP(header) || *(s-1) == '\n' || *(s-1) == '\r')) {
  258. char *rest = strstr(s, "\r\n");
  259. if (rest) {
  260. zval new_header;
  261. rest += 2;
  262. Z_TYPE(new_header) = IS_STRING;
  263. Z_STRLEN(new_header) = Z_STRLEN_PP(header) - (rest - s);
  264. Z_STRVAL(new_header) = emalloc(Z_STRLEN_PP(header) + 1);
  265. memcpy(Z_STRVAL(new_header), Z_STRVAL_PP(header), s - Z_STRVAL_PP(header));
  266. memcpy(Z_STRVAL(new_header) + (s - Z_STRVAL_PP(header)), rest, Z_STRLEN_PP(header) - (rest - Z_STRVAL_PP(header)) + 1);
  267. ctx->old_header = *header;
  268. Z_ADDREF_P(ctx->old_header);
  269. php_stream_context_set_option(ctx->context, "http", "header", &new_header);
  270. zval_dtor(&new_header);
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }
  277. void sdl_restore_uri_credentials(sdlCtx *ctx TSRMLS_DC)
  278. {
  279. if (ctx->old_header) {
  280. php_stream_context_set_option(ctx->context, "http", "header", ctx->old_header);
  281. zval_ptr_dtor(&ctx->old_header);
  282. ctx->old_header = NULL;
  283. }
  284. ctx->context = NULL;
  285. }
  286. static void load_wsdl_ex(zval *this_ptr, char *struri, sdlCtx *ctx, int include TSRMLS_DC)
  287. {
  288. sdlPtr tmpsdl = ctx->sdl;
  289. xmlDocPtr wsdl;
  290. xmlNodePtr root, definitions, trav;
  291. xmlAttrPtr targetNamespace;
  292. if (zend_hash_exists(&ctx->docs, struri, strlen(struri)+1)) {
  293. return;
  294. }
  295. sdl_set_uri_credentials(ctx, struri TSRMLS_CC);
  296. wsdl = soap_xmlParseFile(struri TSRMLS_CC);
  297. sdl_restore_uri_credentials(ctx TSRMLS_CC);
  298. if (!wsdl) {
  299. xmlErrorPtr xmlErrorPtr = xmlGetLastError();
  300. if (xmlErrorPtr) {
  301. soap_error2(E_ERROR, "Parsing WSDL: Couldn't load from '%s' : %s", struri, xmlErrorPtr->message);
  302. } else {
  303. soap_error1(E_ERROR, "Parsing WSDL: Couldn't load from '%s'", struri);
  304. }
  305. }
  306. zend_hash_add(&ctx->docs, struri, strlen(struri)+1, (void**)&wsdl, sizeof(xmlDocPtr), NULL);
  307. root = wsdl->children;
  308. definitions = get_node_ex(root, "definitions", WSDL_NAMESPACE);
  309. if (!definitions) {
  310. if (include) {
  311. xmlNodePtr schema = get_node_ex(root, "schema", XSD_NAMESPACE);
  312. if (schema) {
  313. load_schema(ctx, schema TSRMLS_CC);
  314. return;
  315. }
  316. }
  317. soap_error1(E_ERROR, "Parsing WSDL: Couldn't find <definitions> in '%s'", struri);
  318. }
  319. if (!include) {
  320. targetNamespace = get_attribute(definitions->properties, "targetNamespace");
  321. if (targetNamespace) {
  322. tmpsdl->target_ns = estrdup((char*)targetNamespace->children->content);
  323. }
  324. }
  325. trav = definitions->children;
  326. while (trav != NULL) {
  327. if (!is_wsdl_element(trav)) {
  328. trav = trav->next;
  329. continue;
  330. }
  331. if (node_is_equal(trav,"types")) {
  332. /* TODO: Only one "types" is allowed */
  333. xmlNodePtr trav2 = trav->children;
  334. while (trav2 != NULL) {
  335. if (node_is_equal_ex(trav2, "schema", XSD_NAMESPACE)) {
  336. load_schema(ctx, trav2 TSRMLS_CC);
  337. } else if (is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) {
  338. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
  339. }
  340. trav2 = trav2->next;
  341. }
  342. } else if (node_is_equal(trav,"import")) {
  343. /* TODO: namespace ??? */
  344. xmlAttrPtr tmp = get_attribute(trav->properties, "location");
  345. if (tmp) {
  346. xmlChar *uri;
  347. xmlChar *base = xmlNodeGetBase(trav->doc, trav);
  348. if (base == NULL) {
  349. uri = xmlBuildURI(tmp->children->content, trav->doc->URL);
  350. } else {
  351. uri = xmlBuildURI(tmp->children->content, base);
  352. xmlFree(base);
  353. }
  354. load_wsdl_ex(this_ptr, (char*)uri, ctx, 1 TSRMLS_CC);
  355. xmlFree(uri);
  356. }
  357. } else if (node_is_equal(trav,"message")) {
  358. xmlAttrPtr name = get_attribute(trav->properties, "name");
  359. if (name && name->children && name->children->content) {
  360. if (zend_hash_add(&ctx->messages, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  361. soap_error1(E_ERROR, "Parsing WSDL: <message> '%s' already defined", name->children->content);
  362. }
  363. } else {
  364. soap_error0(E_ERROR, "Parsing WSDL: <message> has no name attribute");
  365. }
  366. } else if (node_is_equal(trav,"portType")) {
  367. xmlAttrPtr name = get_attribute(trav->properties, "name");
  368. if (name && name->children && name->children->content) {
  369. if (zend_hash_add(&ctx->portTypes, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  370. soap_error1(E_ERROR, "Parsing WSDL: <portType> '%s' already defined", name->children->content);
  371. }
  372. } else {
  373. soap_error0(E_ERROR, "Parsing WSDL: <portType> has no name attribute");
  374. }
  375. } else if (node_is_equal(trav,"binding")) {
  376. xmlAttrPtr name = get_attribute(trav->properties, "name");
  377. if (name && name->children && name->children->content) {
  378. if (zend_hash_add(&ctx->bindings, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  379. soap_error1(E_ERROR, "Parsing WSDL: <binding> '%s' already defined", name->children->content);
  380. }
  381. } else {
  382. soap_error0(E_ERROR, "Parsing WSDL: <binding> has no name attribute");
  383. }
  384. } else if (node_is_equal(trav,"service")) {
  385. xmlAttrPtr name = get_attribute(trav->properties, "name");
  386. if (name && name->children && name->children->content) {
  387. if (zend_hash_add(&ctx->services, (char*)name->children->content, xmlStrlen(name->children->content)+1,&trav, sizeof(xmlNodePtr), NULL) != SUCCESS) {
  388. soap_error1(E_ERROR, "Parsing WSDL: <service> '%s' already defined", name->children->content);
  389. }
  390. } else {
  391. soap_error0(E_ERROR, "Parsing WSDL: <service> has no name attribute");
  392. }
  393. } else if (!node_is_equal(trav,"documentation")) {
  394. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  395. }
  396. trav = trav->next;
  397. }
  398. }
  399. static sdlSoapBindingFunctionHeaderPtr wsdl_soap_binding_header(sdlCtx* ctx, xmlNodePtr header, char* wsdl_soap_namespace, int fault)
  400. {
  401. xmlAttrPtr tmp;
  402. xmlNodePtr *message, part;
  403. char *ctype;
  404. sdlSoapBindingFunctionHeaderPtr h;
  405. tmp = get_attribute(header->properties, "message");
  406. if (!tmp) {
  407. soap_error0(E_ERROR, "Parsing WSDL: Missing message attribute for <header>");
  408. }
  409. ctype = strrchr((char*)tmp->children->content,':');
  410. if (ctype == NULL) {
  411. ctype = (char*)tmp->children->content;
  412. } else {
  413. ++ctype;
  414. }
  415. if (zend_hash_find(&ctx->messages, ctype, strlen(ctype)+1, (void**)&message) != SUCCESS) {
  416. soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", tmp->children->content);
  417. }
  418. tmp = get_attribute(header->properties, "part");
  419. if (!tmp) {
  420. soap_error0(E_ERROR, "Parsing WSDL: Missing part attribute for <header>");
  421. }
  422. part = get_node_with_attribute_ex((*message)->children, "part", WSDL_NAMESPACE, "name", (char*)tmp->children->content, NULL);
  423. if (!part) {
  424. soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", tmp->children->content);
  425. }
  426. h = emalloc(sizeof(sdlSoapBindingFunctionHeader));
  427. memset(h, 0, sizeof(sdlSoapBindingFunctionHeader));
  428. h->name = estrdup((char*)tmp->children->content);
  429. tmp = get_attribute(header->properties, "use");
  430. if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) {
  431. h->use = SOAP_ENCODED;
  432. } else {
  433. h->use = SOAP_LITERAL;
  434. }
  435. tmp = get_attribute(header->properties, "namespace");
  436. if (tmp) {
  437. h->ns = estrdup((char*)tmp->children->content);
  438. }
  439. if (h->use == SOAP_ENCODED) {
  440. tmp = get_attribute(header->properties, "encodingStyle");
  441. if (tmp) {
  442. if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
  443. h->encodingStyle = SOAP_ENCODING_1_1;
  444. } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
  445. h->encodingStyle = SOAP_ENCODING_1_2;
  446. } else {
  447. soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
  448. }
  449. } else {
  450. soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
  451. }
  452. }
  453. tmp = get_attribute(part->properties, "type");
  454. if (tmp != NULL) {
  455. h->encode = get_encoder_from_prefix(ctx->sdl, part, tmp->children->content);
  456. } else {
  457. tmp = get_attribute(part->properties, "element");
  458. if (tmp != NULL) {
  459. h->element = get_element(ctx->sdl, part, tmp->children->content);
  460. if (h->element) {
  461. h->encode = h->element->encode;
  462. if (!h->ns && h->element->namens) {
  463. h->ns = estrdup(h->element->namens);
  464. }
  465. if (h->element->name) {
  466. efree(h->name);
  467. h->name = estrdup(h->element->name);
  468. }
  469. }
  470. }
  471. }
  472. if (!fault) {
  473. xmlNodePtr trav = header->children;
  474. while (trav != NULL) {
  475. if (node_is_equal_ex(trav, "headerfault", wsdl_soap_namespace)) {
  476. sdlSoapBindingFunctionHeaderPtr hf = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 1);
  477. smart_str key = {0};
  478. if (h->headerfaults == NULL) {
  479. h->headerfaults = emalloc(sizeof(HashTable));
  480. zend_hash_init(h->headerfaults, 0, NULL, delete_header, 0);
  481. }
  482. if (hf->ns) {
  483. smart_str_appends(&key,hf->ns);
  484. smart_str_appendc(&key,':');
  485. }
  486. smart_str_appends(&key,hf->name);
  487. smart_str_0(&key);
  488. if (zend_hash_add(h->headerfaults, key.c, key.len+1, (void**)&hf, sizeof(sdlSoapBindingFunctionHeaderPtr), NULL) != SUCCESS) {
  489. delete_header((void**)&hf);
  490. }
  491. smart_str_free(&key);
  492. } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
  493. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  494. }
  495. trav = trav->next;
  496. }
  497. }
  498. return h;
  499. }
  500. static void wsdl_soap_binding_body(sdlCtx* ctx, xmlNodePtr node, char* wsdl_soap_namespace, sdlSoapBindingFunctionBody *binding, HashTable* params)
  501. {
  502. xmlNodePtr body, trav;
  503. xmlAttrPtr tmp;
  504. trav = node->children;
  505. while (trav != NULL) {
  506. if (node_is_equal_ex(trav, "body", wsdl_soap_namespace)) {
  507. body = trav;
  508. tmp = get_attribute(body->properties, "use");
  509. if (tmp && !strncmp((char*)tmp->children->content, "literal", sizeof("literal"))) {
  510. binding->use = SOAP_LITERAL;
  511. } else {
  512. binding->use = SOAP_ENCODED;
  513. }
  514. tmp = get_attribute(body->properties, "namespace");
  515. if (tmp) {
  516. binding->ns = estrdup((char*)tmp->children->content);
  517. }
  518. tmp = get_attribute(body->properties, "parts");
  519. if (tmp) {
  520. HashTable ht;
  521. char *parts = (char*)tmp->children->content;
  522. /* Delete all parts those are not in the "parts" attribute */
  523. zend_hash_init(&ht, 0, NULL, delete_parameter, 0);
  524. while (*parts) {
  525. HashPosition pos;
  526. sdlParamPtr *param;
  527. int found = 0;
  528. char *end;
  529. while (*parts == ' ') ++parts;
  530. if (*parts == '\0') break;
  531. end = strchr(parts, ' ');
  532. if (end) *end = '\0';
  533. zend_hash_internal_pointer_reset_ex(params, &pos);
  534. while (zend_hash_get_current_data_ex(params, (void **)&param, &pos) != FAILURE) {
  535. if ((*param)->paramName &&
  536. strcmp(parts, (*param)->paramName) == 0) {
  537. sdlParamPtr x_param;
  538. x_param = emalloc(sizeof(sdlParam));
  539. *x_param = **param;
  540. (*param)->paramName = NULL;
  541. zend_hash_next_index_insert(&ht, &x_param, sizeof(sdlParamPtr), NULL);
  542. found = 1;
  543. break;
  544. }
  545. zend_hash_move_forward_ex(params, &pos);
  546. }
  547. if (!found) {
  548. soap_error1(E_ERROR, "Parsing WSDL: Missing part '%s' in <message>", parts);
  549. }
  550. parts += strlen(parts);
  551. if (end) *end = ' ';
  552. }
  553. zend_hash_destroy(params);
  554. *params = ht;
  555. }
  556. if (binding->use == SOAP_ENCODED) {
  557. tmp = get_attribute(body->properties, "encodingStyle");
  558. if (tmp) {
  559. if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
  560. binding->encodingStyle = SOAP_ENCODING_1_1;
  561. } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
  562. binding->encodingStyle = SOAP_ENCODING_1_2;
  563. } else {
  564. soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
  565. }
  566. } else {
  567. soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
  568. }
  569. }
  570. } else if (node_is_equal_ex(trav, "header", wsdl_soap_namespace)) {
  571. sdlSoapBindingFunctionHeaderPtr h = wsdl_soap_binding_header(ctx, trav, wsdl_soap_namespace, 0);
  572. smart_str key = {0};
  573. if (binding->headers == NULL) {
  574. binding->headers = emalloc(sizeof(HashTable));
  575. zend_hash_init(binding->headers, 0, NULL, delete_header, 0);
  576. }
  577. if (h->ns) {
  578. smart_str_appends(&key,h->ns);
  579. smart_str_appendc(&key,':');
  580. }
  581. smart_str_appends(&key,h->name);
  582. smart_str_0(&key);
  583. if (zend_hash_add(binding->headers, key.c, key.len+1, (void**)&h, sizeof(sdlSoapBindingFunctionHeaderPtr), NULL) != SUCCESS) {
  584. delete_header((void**)&h);
  585. }
  586. smart_str_free(&key);
  587. } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
  588. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  589. }
  590. trav = trav->next;
  591. }
  592. }
  593. static HashTable* wsdl_message(sdlCtx *ctx, xmlChar* message_name)
  594. {
  595. xmlNodePtr trav, part, message = NULL, *tmp;
  596. HashTable* parameters = NULL;
  597. char *ctype;
  598. ctype = strrchr((char*)message_name,':');
  599. if (ctype == NULL) {
  600. ctype = (char*)message_name;
  601. } else {
  602. ++ctype;
  603. }
  604. if (zend_hash_find(&ctx->messages, ctype, strlen(ctype)+1, (void**)&tmp) != SUCCESS) {
  605. soap_error1(E_ERROR, "Parsing WSDL: Missing <message> with name '%s'", message_name);
  606. }
  607. message = *tmp;
  608. parameters = emalloc(sizeof(HashTable));
  609. zend_hash_init(parameters, 0, NULL, delete_parameter, 0);
  610. trav = message->children;
  611. while (trav != NULL) {
  612. xmlAttrPtr element, type, name;
  613. sdlParamPtr param;
  614. if (trav->ns != NULL && strcmp((char*)trav->ns->href, WSDL_NAMESPACE) != 0) {
  615. soap_error1(E_ERROR, "Parsing WSDL: Unexpected extensibility element <%s>", trav->name);
  616. }
  617. if (node_is_equal(trav,"documentation")) {
  618. trav = trav->next;
  619. continue;
  620. }
  621. if (!node_is_equal(trav,"part")) {
  622. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  623. }
  624. part = trav;
  625. param = emalloc(sizeof(sdlParam));
  626. memset(param,0,sizeof(sdlParam));
  627. param->order = 0;
  628. name = get_attribute(part->properties, "name");
  629. if (name == NULL) {
  630. soap_error1(E_ERROR, "Parsing WSDL: No name associated with <part> '%s'", message->name);
  631. }
  632. param->paramName = estrdup((char*)name->children->content);
  633. type = get_attribute(part->properties, "type");
  634. if (type != NULL) {
  635. param->encode = get_encoder_from_prefix(ctx->sdl, part, type->children->content);
  636. } else {
  637. element = get_attribute(part->properties, "element");
  638. if (element != NULL) {
  639. param->element = get_element(ctx->sdl, part, element->children->content);
  640. if (param->element) {
  641. param->encode = param->element->encode;
  642. }
  643. }
  644. }
  645. zend_hash_next_index_insert(parameters, &param, sizeof(sdlParamPtr), NULL);
  646. trav = trav->next;
  647. }
  648. return parameters;
  649. }
  650. static sdlPtr load_wsdl(zval *this_ptr, char *struri TSRMLS_DC)
  651. {
  652. sdlCtx ctx;
  653. int i,n;
  654. memset(&ctx,0,sizeof(ctx));
  655. ctx.sdl = emalloc(sizeof(sdl));
  656. memset(ctx.sdl, 0, sizeof(sdl));
  657. ctx.sdl->source = estrdup(struri);
  658. zend_hash_init(&ctx.sdl->functions, 0, NULL, delete_function, 0);
  659. zend_hash_init(&ctx.docs, 0, NULL, delete_document, 0);
  660. zend_hash_init(&ctx.messages, 0, NULL, NULL, 0);
  661. zend_hash_init(&ctx.bindings, 0, NULL, NULL, 0);
  662. zend_hash_init(&ctx.portTypes, 0, NULL, NULL, 0);
  663. zend_hash_init(&ctx.services, 0, NULL, NULL, 0);
  664. load_wsdl_ex(this_ptr, struri,&ctx, 0 TSRMLS_CC);
  665. schema_pass2(&ctx);
  666. n = zend_hash_num_elements(&ctx.services);
  667. if (n > 0) {
  668. zend_hash_internal_pointer_reset(&ctx.services);
  669. for (i = 0; i < n; i++) {
  670. xmlNodePtr *tmp, service;
  671. xmlNodePtr trav, port;
  672. int has_soap_port = 0;
  673. zend_hash_get_current_data(&ctx.services, (void **)&tmp);
  674. service = *tmp;
  675. trav = service->children;
  676. while (trav != NULL) {
  677. xmlAttrPtr type, name, bindingAttr, location;
  678. xmlNodePtr portType, operation;
  679. xmlNodePtr address, binding, trav2;
  680. char *ctype;
  681. sdlBindingPtr tmpbinding;
  682. char *wsdl_soap_namespace = NULL;
  683. if (!is_wsdl_element(trav) || node_is_equal(trav,"documentation")) {
  684. trav = trav->next;
  685. continue;
  686. }
  687. if (!node_is_equal(trav,"port")) {
  688. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  689. }
  690. port = trav;
  691. tmpbinding = emalloc(sizeof(sdlBinding));
  692. memset(tmpbinding, 0, sizeof(sdlBinding));
  693. bindingAttr = get_attribute(port->properties, "binding");
  694. if (bindingAttr == NULL) {
  695. soap_error0(E_ERROR, "Parsing WSDL: No binding associated with <port>");
  696. }
  697. /* find address and figure out binding type */
  698. address = NULL;
  699. trav2 = port->children;
  700. while (trav2 != NULL) {
  701. if (node_is_equal(trav2,"address") && trav2->ns) {
  702. if (!strncmp((char*)trav2->ns->href, WSDL_SOAP11_NAMESPACE, sizeof(WSDL_SOAP11_NAMESPACE))) {
  703. address = trav2;
  704. wsdl_soap_namespace = WSDL_SOAP11_NAMESPACE;
  705. tmpbinding->bindingType = BINDING_SOAP;
  706. } else if (!strncmp((char*)trav2->ns->href, WSDL_SOAP12_NAMESPACE, sizeof(WSDL_SOAP12_NAMESPACE))) {
  707. address = trav2;
  708. wsdl_soap_namespace = WSDL_SOAP12_NAMESPACE;
  709. tmpbinding->bindingType = BINDING_SOAP;
  710. } else if (!strncmp((char*)trav2->ns->href, RPC_SOAP12_NAMESPACE, sizeof(RPC_SOAP12_NAMESPACE))) {
  711. address = trav2;
  712. wsdl_soap_namespace = RPC_SOAP12_NAMESPACE;
  713. tmpbinding->bindingType = BINDING_SOAP;
  714. } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP11_NAMESPACE, sizeof(WSDL_HTTP11_NAMESPACE))) {
  715. address = trav2;
  716. tmpbinding->bindingType = BINDING_HTTP;
  717. } else if (!strncmp((char*)trav2->ns->href, WSDL_HTTP12_NAMESPACE, sizeof(WSDL_HTTP12_NAMESPACE))) {
  718. address = trav2;
  719. tmpbinding->bindingType = BINDING_HTTP;
  720. }
  721. }
  722. if (trav2 != address && is_wsdl_element(trav2) && !node_is_equal(trav2,"documentation")) {
  723. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
  724. }
  725. trav2 = trav2->next;
  726. }
  727. if (!address || tmpbinding->bindingType == BINDING_HTTP) {
  728. if (has_soap_port || trav->next || i < n-1) {
  729. efree(tmpbinding);
  730. trav = trav->next;
  731. continue;
  732. } else if (!address) {
  733. soap_error0(E_ERROR, "Parsing WSDL: No address associated with <port>");
  734. }
  735. }
  736. has_soap_port = 1;
  737. location = get_attribute(address->properties, "location");
  738. if (!location) {
  739. soap_error0(E_ERROR, "Parsing WSDL: No location associated with <port>");
  740. }
  741. tmpbinding->location = estrdup((char*)location->children->content);
  742. ctype = strrchr((char*)bindingAttr->children->content,':');
  743. if (ctype == NULL) {
  744. ctype = (char*)bindingAttr->children->content;
  745. } else {
  746. ++ctype;
  747. }
  748. if (zend_hash_find(&ctx.bindings, ctype, strlen(ctype)+1, (void*)&tmp) != SUCCESS) {
  749. soap_error1(E_ERROR, "Parsing WSDL: No <binding> element with name '%s'", ctype);
  750. }
  751. binding = *tmp;
  752. if (tmpbinding->bindingType == BINDING_SOAP) {
  753. sdlSoapBindingPtr soapBinding;
  754. xmlNodePtr soapBindingNode;
  755. xmlAttrPtr tmp;
  756. soapBinding = emalloc(sizeof(sdlSoapBinding));
  757. memset(soapBinding, 0, sizeof(sdlSoapBinding));
  758. soapBinding->style = SOAP_DOCUMENT;
  759. soapBindingNode = get_node_ex(binding->children, "binding", wsdl_soap_namespace);
  760. if (soapBindingNode) {
  761. tmp = get_attribute(soapBindingNode->properties, "style");
  762. if (tmp && !strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) {
  763. soapBinding->style = SOAP_RPC;
  764. }
  765. tmp = get_attribute(soapBindingNode->properties, "transport");
  766. if (tmp) {
  767. if (strncmp((char*)tmp->children->content, WSDL_HTTP_TRANSPORT, sizeof(WSDL_HTTP_TRANSPORT)) == 0) {
  768. soapBinding->transport = SOAP_TRANSPORT_HTTP;
  769. } else {
  770. /* try the next binding */
  771. efree(soapBinding);
  772. efree(tmpbinding->location);
  773. efree(tmpbinding);
  774. trav = trav->next;
  775. continue;
  776. }
  777. }
  778. }
  779. tmpbinding->bindingAttributes = (void *)soapBinding;
  780. }
  781. name = get_attribute(binding->properties, "name");
  782. if (name == NULL) {
  783. soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <binding>");
  784. }
  785. tmpbinding->name = estrdup((char*)name->children->content);
  786. type = get_attribute(binding->properties, "type");
  787. if (type == NULL) {
  788. soap_error0(E_ERROR, "Parsing WSDL: Missing 'type' attribute for <binding>");
  789. }
  790. ctype = strrchr((char*)type->children->content,':');
  791. if (ctype == NULL) {
  792. ctype = (char*)type->children->content;
  793. } else {
  794. ++ctype;
  795. }
  796. if (zend_hash_find(&ctx.portTypes, ctype, strlen(ctype)+1, (void**)&tmp) != SUCCESS) {
  797. soap_error1(E_ERROR, "Parsing WSDL: Missing <portType> with name '%s'", name->children->content);
  798. }
  799. portType = *tmp;
  800. trav2 = binding->children;
  801. while (trav2 != NULL) {
  802. sdlFunctionPtr function;
  803. xmlNodePtr input, output, fault, portTypeOperation, trav3;
  804. xmlAttrPtr op_name, paramOrder;
  805. if ((tmpbinding->bindingType == BINDING_SOAP &&
  806. node_is_equal_ex(trav2, "binding", wsdl_soap_namespace)) ||
  807. !is_wsdl_element(trav2) ||
  808. node_is_equal(trav2,"documentation")) {
  809. trav2 = trav2->next;
  810. continue;
  811. }
  812. if (!node_is_equal(trav2,"operation")) {
  813. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav2->name);
  814. }
  815. operation = trav2;
  816. op_name = get_attribute(operation->properties, "name");
  817. if (op_name == NULL) {
  818. soap_error0(E_ERROR, "Parsing WSDL: Missing 'name' attribute for <operation>");
  819. }
  820. trav3 = operation->children;
  821. while (trav3 != NULL) {
  822. if (tmpbinding->bindingType == BINDING_SOAP &&
  823. node_is_equal_ex(trav3, "operation", wsdl_soap_namespace)) {
  824. } else if (is_wsdl_element(trav3) &&
  825. !node_is_equal(trav3,"input") &&
  826. !node_is_equal(trav3,"output") &&
  827. !node_is_equal(trav3,"fault") &&
  828. !node_is_equal(trav3,"documentation")) {
  829. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav3->name);
  830. }
  831. trav3 = trav3->next;
  832. }
  833. portTypeOperation = get_node_with_attribute_ex(portType->children, "operation", WSDL_NAMESPACE, "name", (char*)op_name->children->content, NULL);
  834. if (portTypeOperation == NULL) {
  835. soap_error1(E_ERROR, "Parsing WSDL: Missing <portType>/<operation> with name '%s'", op_name->children->content);
  836. }
  837. function = emalloc(sizeof(sdlFunction));
  838. memset(function, 0, sizeof(sdlFunction));
  839. function->functionName = estrdup((char*)op_name->children->content);
  840. if (tmpbinding->bindingType == BINDING_SOAP) {
  841. sdlSoapBindingFunctionPtr soapFunctionBinding;
  842. sdlSoapBindingPtr soapBinding;
  843. xmlNodePtr soapOperation;
  844. xmlAttrPtr tmp;
  845. soapFunctionBinding = emalloc(sizeof(sdlSoapBindingFunction));
  846. memset(soapFunctionBinding, 0, sizeof(sdlSoapBindingFunction));
  847. soapBinding = (sdlSoapBindingPtr)tmpbinding->bindingAttributes;
  848. soapFunctionBinding->style = soapBinding->style;
  849. soapOperation = get_node_ex(operation->children, "operation", wsdl_soap_namespace);
  850. if (soapOperation) {
  851. tmp = get_attribute(soapOperation->properties, "soapAction");
  852. if (tmp) {
  853. soapFunctionBinding->soapAction = estrdup((char*)tmp->children->content);
  854. }
  855. tmp = get_attribute(soapOperation->properties, "style");
  856. if (tmp) {
  857. if (!strncmp((char*)tmp->children->content, "rpc", sizeof("rpc"))) {
  858. soapFunctionBinding->style = SOAP_RPC;
  859. } else {
  860. soapFunctionBinding->style = SOAP_DOCUMENT;
  861. }
  862. } else {
  863. soapFunctionBinding->style = soapBinding->style;
  864. }
  865. }
  866. function->bindingAttributes = (void *)soapFunctionBinding;
  867. }
  868. input = get_node_ex(portTypeOperation->children, "input", WSDL_NAMESPACE);
  869. if (input != NULL) {
  870. xmlAttrPtr message, name;
  871. message = get_attribute(input->properties, "message");
  872. if (message == NULL) {
  873. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <input> of '%s'", op_name->children->content);
  874. }
  875. function->requestParameters = wsdl_message(&ctx, message->children->content);
  876. name = get_attribute(input->properties, "name");
  877. /* FIXME
  878. if (name != NULL) {
  879. function->requestName = estrdup(name->children->content);
  880. } else {
  881. */
  882. {
  883. function->requestName = estrdup(function->functionName);
  884. }
  885. if (tmpbinding->bindingType == BINDING_SOAP) {
  886. input = get_node_ex(operation->children, "input", WSDL_NAMESPACE);
  887. if (input != NULL) {
  888. sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes;
  889. wsdl_soap_binding_body(&ctx, input, wsdl_soap_namespace, &soapFunctionBinding->input, function->requestParameters);
  890. }
  891. }
  892. }
  893. output = get_node_ex(portTypeOperation->children, "output", WSDL_NAMESPACE);
  894. if (output != NULL) {
  895. xmlAttrPtr message, name;
  896. message = get_attribute(output->properties, "message");
  897. if (message == NULL) {
  898. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content);
  899. }
  900. function->responseParameters = wsdl_message(&ctx, message->children->content);
  901. name = get_attribute(output->properties, "name");
  902. /* FIXME
  903. if (name != NULL) {
  904. function->responseName = estrdup(name->children->content);
  905. } else if (input == NULL) {
  906. function->responseName = estrdup(function->functionName);
  907. } else {
  908. */
  909. {
  910. int len = strlen(function->functionName);
  911. function->responseName = emalloc(len + sizeof("Response"));
  912. memcpy(function->responseName, function->functionName, len);
  913. memcpy(function->responseName+len, "Response", sizeof("Response"));
  914. }
  915. if (tmpbinding->bindingType == BINDING_SOAP) {
  916. output = get_node_ex(operation->children, "output", WSDL_NAMESPACE);
  917. if (output != NULL) {
  918. sdlSoapBindingFunctionPtr soapFunctionBinding = function->bindingAttributes;
  919. wsdl_soap_binding_body(&ctx, output, wsdl_soap_namespace, &soapFunctionBinding->output, function->responseParameters);
  920. }
  921. }
  922. }
  923. paramOrder = get_attribute(portTypeOperation->properties, "parameterOrder");
  924. if (paramOrder) {
  925. /* FIXME: */
  926. }
  927. fault = portTypeOperation->children;
  928. while (fault != NULL) {
  929. if (node_is_equal_ex(fault, "fault", WSDL_NAMESPACE)) {
  930. xmlAttrPtr message, name;
  931. sdlFaultPtr f;
  932. name = get_attribute(fault->properties, "name");
  933. if (name == NULL) {
  934. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <fault> of '%s'", op_name->children->content);
  935. }
  936. message = get_attribute(fault->properties, "message");
  937. if (message == NULL) {
  938. soap_error1(E_ERROR, "Parsing WSDL: Missing name for <output> of '%s'", op_name->children->content);
  939. }
  940. f = emalloc(sizeof(sdlFault));
  941. memset(f, 0, sizeof(sdlFault));
  942. f->name = estrdup((char*)name->children->content);
  943. f->details = wsdl_message(&ctx, message->children->content);
  944. if (f->details == NULL || zend_hash_num_elements(f->details) > 1) {
  945. soap_error1(E_ERROR, "Parsing WSDL: The fault message '%s' must have a single part", message->children->content);
  946. }
  947. if (tmpbinding->bindingType == BINDING_SOAP) {
  948. xmlNodePtr soap_fault = get_node_with_attribute_ex(operation->children, "fault", WSDL_NAMESPACE, "name", f->name, NULL);
  949. if (soap_fault != NULL) {
  950. xmlNodePtr trav = soap_fault->children;
  951. while (trav != NULL) {
  952. if (node_is_equal_ex(trav, "fault", wsdl_soap_namespace)) {
  953. xmlAttrPtr tmp;
  954. sdlSoapBindingFunctionFaultPtr binding;
  955. binding = f->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault));
  956. memset(f->bindingAttributes, 0, sizeof(sdlSoapBindingFunctionFault));
  957. tmp = get_attribute(trav->properties, "use");
  958. if (tmp && !strncmp((char*)tmp->children->content, "encoded", sizeof("encoded"))) {
  959. binding->use = SOAP_ENCODED;
  960. } else {
  961. binding->use = SOAP_LITERAL;
  962. }
  963. tmp = get_attribute(trav->properties, "namespace");
  964. if (tmp) {
  965. binding->ns = estrdup((char*)tmp->children->content);
  966. }
  967. if (binding->use == SOAP_ENCODED) {
  968. tmp = get_attribute(trav->properties, "encodingStyle");
  969. if (tmp) {
  970. if (strncmp((char*)tmp->children->content, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)) == 0) {
  971. binding->encodingStyle = SOAP_ENCODING_1_1;
  972. } else if (strncmp((char*)tmp->children->content, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)) == 0) {
  973. binding->encodingStyle = SOAP_ENCODING_1_2;
  974. } else {
  975. soap_error1(E_ERROR, "Parsing WSDL: Unknown encodingStyle '%s'", tmp->children->content);
  976. }
  977. } else {
  978. soap_error0(E_ERROR, "Parsing WSDL: Unspecified encodingStyle");
  979. }
  980. }
  981. } else if (is_wsdl_element(trav) && !node_is_equal(trav,"documentation")) {
  982. soap_error1(E_ERROR, "Parsing WSDL: Unexpected WSDL element <%s>", trav->name);
  983. }
  984. trav = trav->next;
  985. }
  986. }
  987. }
  988. if (function->faults == NULL) {
  989. function->faults = emalloc(sizeof(HashTable));
  990. zend_hash_init(function->faults, 0, NULL, delete_fault, 0);
  991. }
  992. if (zend_hash_add(function->faults, f->name, strlen(f->name)+1, (void**)&f, sizeof(sdlFaultPtr), NULL) != SUCCESS) {
  993. soap_error2(E_ERROR, "Parsing WSDL: <fault> with name '%s' already defined in '%s'", f->name, op_name->children->content);
  994. }
  995. }
  996. fault = fault->next;
  997. }
  998. function->binding = tmpbinding;
  999. {
  1000. char *tmp = estrdup(function->functionName);
  1001. int len = strlen(tmp);
  1002. if (zend_hash_add(&ctx.sdl->functions, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL) != SUCCESS) {
  1003. zend_hash_next_index_insert(&ctx.sdl->functions, &function, sizeof(sdlFunctionPtr), NULL);
  1004. }
  1005. efree(tmp);
  1006. if (function->requestName != NULL && strcmp(function->requestName,function->functionName) != 0) {
  1007. if (ctx.sdl->requests == NULL) {
  1008. ctx.sdl->requests = emalloc(sizeof(HashTable));
  1009. zend_hash_init(ctx.sdl->requests, 0, NULL, NULL, 0);
  1010. }
  1011. tmp = estrdup(function->requestName);
  1012. len = strlen(tmp);
  1013. zend_hash_add(ctx.sdl->requests, php_strtolower(tmp, len), len+1, &function, sizeof(sdlFunctionPtr), NULL);
  1014. efree(tmp);
  1015. }
  1016. }
  1017. trav2 = trav2->next;
  1018. }
  1019. if (!ctx.sdl->bindings) {
  1020. ctx.sdl->bindings = emalloc(sizeof(HashTable));
  1021. zend_hash_init(ctx.sdl->bindings, 0, NULL, delete_binding, 0);
  1022. }
  1023. if (zend_hash_add(ctx.sdl->bindings, tmpbinding->name, strlen(tmpbinding->name), &tmpbinding, sizeof(sdlBindingPtr), NULL) != SUCCESS) {
  1024. zend_hash_next_index_insert(ctx.sdl->bindings, &tmpbinding, sizeof(sdlBindingPtr), NULL);
  1025. }
  1026. trav= trav->next;
  1027. }
  1028. zend_hash_move_forward(&ctx.services);
  1029. }
  1030. } else {
  1031. soap_error0(E_ERROR, "Parsing WSDL: Couldn't bind to service");
  1032. }
  1033. if (ctx.sdl->bindings == NULL || ctx.sdl->bindings->nNumOfElements == 0) {
  1034. soap_error0(E_ERROR, "Parsing WSDL: Could not find any usable binding services in WSDL.");
  1035. }
  1036. zend_hash_destroy(&ctx.messages);
  1037. zend_hash_destroy(&ctx.bindings);
  1038. zend_hash_destroy(&ctx.portTypes);
  1039. zend_hash_destroy(&ctx.services);
  1040. zend_hash_destroy(&ctx.docs);
  1041. return ctx.sdl;
  1042. }
  1043. #define WSDL_CACHE_VERSION 0x0e
  1044. #define WSDL_CACHE_GET(ret,type,buf) memcpy(&ret,*buf,sizeof(type)); *buf += sizeof(type);
  1045. #define WSDL_CACHE_GET_INT(ret,buf) ret = ((unsigned char)(*buf)[0])|((unsigned char)(*buf)[1]<<8)|((unsigned char)(*buf)[2]<<16)|((int)(*buf)[3]<<24); *buf += 4;
  1046. #define WSDL_CACHE_GET_1(ret,type,buf) ret = (type)(**buf); (*buf)++;
  1047. #define WSDL_CACHE_GET_N(ret,n,buf) memcpy(ret,*buf,n); *buf += n;
  1048. #define WSDL_CACHE_SKIP(n,buf) *buf += n;
  1049. #define WSDL_CACHE_PUT_INT(val,buf) smart_str_appendc(buf,val & 0xff); \
  1050. smart_str_appendc(buf,(val >> 8) & 0xff); \
  1051. smart_str_appendc(buf,(val >> 16) & 0xff); \
  1052. smart_str_appendc(buf,(val >> 24) & 0xff);
  1053. #define WSDL_CACHE_PUT_1(val,buf) smart_str_appendc(buf,val);
  1054. #define WSDL_CACHE_PUT_N(val,n,buf) smart_str_appendl(buf,(char*)val,n);
  1055. static char* sdl_deserialize_string(char **in)
  1056. {
  1057. char *s;
  1058. int len;
  1059. WSDL_CACHE_GET_INT(len, in);
  1060. if (len == 0x7fffffff) {
  1061. return NULL;
  1062. } else {
  1063. s = emalloc(len+1);
  1064. WSDL_CACHE_GET_N(s, len, in);
  1065. s[len] = '\0';
  1066. return s;
  1067. }
  1068. }
  1069. static void sdl_deserialize_key(HashTable* ht, void* data, char **in)
  1070. {
  1071. int len;
  1072. WSDL_CACHE_GET_INT(len, in);
  1073. if (len == 0) {
  1074. zend_hash_next_index_insert(ht, &data, sizeof(void*), NULL);
  1075. } else {
  1076. zend_hash_add(ht, *in, len, &data, sizeof(void*), NULL);
  1077. WSDL_CACHE_SKIP(len, in);
  1078. }
  1079. }
  1080. static void sdl_deserialize_attribute(sdlAttributePtr attr, encodePtr *encoders, char **in)
  1081. {
  1082. int i;
  1083. attr->name = sdl_deserialize_string(in);
  1084. attr->namens = sdl_deserialize_string(in);
  1085. attr->ref = sdl_deserialize_string(in);
  1086. attr->def = sdl_deserialize_string(in);
  1087. attr->fixed = sdl_deserialize_string(in);
  1088. WSDL_CACHE_GET_1(attr->form, sdlForm, in);
  1089. WSDL_CACHE_GET_1(attr->use, sdlUse, in);
  1090. WSDL_CACHE_GET_INT(i, in);
  1091. attr->encode = encoders[i];
  1092. WSDL_CACHE_GET_INT(i, in);
  1093. if (i > 0) {
  1094. attr->extraAttributes = emalloc(sizeof(HashTable));
  1095. zend_hash_init(attr->extraAttributes, i, NULL, delete_extra_attribute, 0);
  1096. while (i > 0) {
  1097. sdlExtraAttributePtr x = emalloc(sizeof(sdlExtraAttribute));
  1098. sdl_deserialize_key(attr->extraAttributes, x, in);
  1099. x->ns = sdl_deserialize_string(in);
  1100. x->val = sdl_deserialize_string(in);
  1101. --i;
  1102. }
  1103. }
  1104. }
  1105. static sdlRestrictionIntPtr sdl_deserialize_resriction_int(char **in)
  1106. {
  1107. if (**in == 1) {
  1108. sdlRestrictionIntPtr x = emalloc(sizeof(sdlRestrictionInt));
  1109. WSDL_CACHE_SKIP(1, in);
  1110. WSDL_CACHE_GET_INT(x->value, in);
  1111. WSDL_CACHE_GET_1(x->fixed, char, in);
  1112. return x;
  1113. } else {
  1114. WSDL_CACHE_SKIP(1, in);
  1115. return NULL;
  1116. }
  1117. }
  1118. static sdlRestrictionCharPtr sdl_deserialize_resriction_char(char **in)
  1119. {
  1120. if (**in == 1) {
  1121. sdlRestrictionCharPtr x = emalloc(sizeof(sdlRestrictionChar));
  1122. WSDL_CACHE_SKIP(1, in);
  1123. x->value = sdl_deserialize_string(in);
  1124. WSDL_CACHE_GET_1(x->fixed, char, in);
  1125. return x;
  1126. } else {
  1127. WSDL_CACHE_SKIP(1, in);
  1128. return NULL;
  1129. }
  1130. }
  1131. static sdlContentModelPtr sdl_deserialize_model(sdlTypePtr *types, sdlTypePtr *elements, char **in)
  1132. {
  1133. int i;
  1134. sdlContentModelPtr model = emalloc(sizeof(sdlContentModel));
  1135. WSDL_CACHE_GET_1(model->kind, sdlContentKind, in);
  1136. WSDL_CACHE_GET_INT(model->min_occurs, in);
  1137. WSDL_CACHE_GET_INT(model->max_occurs, in);
  1138. switch (model->kind) {
  1139. case XSD_CONTENT_ELEMENT:
  1140. WSDL_CACHE_GET_INT(i, in);
  1141. model->u.element = elements[i];
  1142. break;
  1143. case XSD_CONTENT_SEQUENCE:
  1144. case XSD_CONTENT_ALL:
  1145. case XSD_CONTENT_CHOICE:
  1146. WSDL_CACHE_GET_INT(i, in);
  1147. model->u.content = emalloc(sizeof(HashTable));
  1148. zend_hash_init(model->u.content, i, NULL, delete_model, 0);
  1149. while (i > 0) {
  1150. sdlContentModelPtr x = sdl_deserialize_model(types, elements, in);
  1151. zend_hash_next_index_insert(model->u.content,&x,sizeof(sdlContentModelPtr),NULL);
  1152. i--;
  1153. }
  1154. break;
  1155. case XSD_CONTENT_GROUP_REF:
  1156. model->u.group_ref = sdl_deserialize_string(in);
  1157. break;
  1158. case XSD_CONTENT_GROUP:
  1159. WSDL_CACHE_GET_INT(i, in);
  1160. model->u.group = types[i];
  1161. break;
  1162. default:
  1163. break;
  1164. }
  1165. return model;
  1166. }
  1167. static void sdl_deserialize_type(sdlTypePtr type, sdlTypePtr *types, encodePtr *encoders, char **in)
  1168. {
  1169. int i;
  1170. sdlTypePtr *elements = NULL;
  1171. WSDL_CACHE_GET_1(type->kind, sdlTypeKind, in);
  1172. type->name = sdl_deserialize_string(in);
  1173. type->namens = sdl_deserialize_string(in);
  1174. type->def = sdl_deserialize_string(in);
  1175. type->fixed = sdl_deserialize_string(in);
  1176. type->ref = sdl_deserialize_string(in);
  1177. WSDL_CACHE_GET_1(type->nillable, char, in);
  1178. WSDL_CACHE_GET_1(type->form, sdlForm, in);
  1179. WSDL_CACHE_GET_INT(i, in);
  1180. type->encode = encoders[i];
  1181. if (**in == 1) {
  1182. WSDL_CACHE_SKIP(1, in);
  1183. type->restrictions = emalloc(sizeof(sdlRestrictions));
  1184. /*memset(type->restrictions, 0, sizeof(sdlRestrictions));*/
  1185. type->restrictions->minExclusive = sdl_deserialize_resriction_int(in);
  1186. type->restrictions->minInclusive = sdl_deserialize_resriction_int(in);
  1187. type->restrictions->maxExclusive = sdl_deserialize_resriction_int(in);
  1188. type->restrictions->maxInclusive = sdl_deserialize_resriction_int(in);
  1189. type->restrictions->totalDigits = sdl_deserialize_resriction_int(in);
  1190. type->restrictions->fractionDigits = sdl_deserialize_resriction_int(in);
  1191. type->restrictions->length = sdl_deserialize_resriction_int(in);
  1192. type->restrictions->minLength = sdl_deserialize_resriction_int(in);
  1193. type->restrictions->maxLength = sdl_deserialize_resriction_int(in);
  1194. type->restrictions->whiteSpace = sdl_deserialize_resriction_char(in);
  1195. type->restrictions->pattern = sdl_deserialize_resriction_char(in);
  1196. WSDL_CACHE_GET_INT(i, in);
  1197. if (i > 0) {
  1198. type->restrictions->enumeration = emalloc(sizeof(HashTable));
  1199. zend_hash_init(type->restrictions->enumeration, i, NULL, delete_restriction_var_char, 0);
  1200. while (i > 0) {
  1201. sdlRestrictionCharPtr x = sdl_deserialize_resriction_char(in);
  1202. sdl_deserialize_key(type->restrictions->enumeration, x, in);
  1203. --i;
  1204. }
  1205. } else {
  1206. type->restrictions->enumeration = NULL;
  1207. }
  1208. } else {
  1209. WSDL_CACHE_SKIP(1, in);
  1210. }
  1211. WSDL_CACHE_GET_INT(i, in);
  1212. if (i > 0) {
  1213. elements = safe_emalloc((i+1), sizeof(sdlTypePtr), 0);
  1214. elements[0] = NULL;
  1215. type->elements = emalloc(sizeof(HashTable));
  1216. zend_hash_init(type->elements, i, NULL, delete_type, 0);
  1217. while (i > 0) {
  1218. sdlTypePtr t = emalloc(sizeof(sdlType));
  1219. memset(t, 0, sizeof(sdlType));
  1220. sdl_deserialize_key(type->elements, t, in);
  1221. sdl_deserialize_type(t, types, encoders, in);
  1222. elements[i] = t;
  1223. --i;
  1224. }
  1225. }
  1226. WSDL_CACHE_GET_INT(i, in);
  1227. if (i > 0) {
  1228. type->attributes = emalloc(sizeof(HashTable));
  1229. zend_hash_init(type->attributes, i, NULL, delete_attribute, 0);
  1230. while (i > 0) {
  1231. sdlAttributePtr attr = emalloc(sizeof(sdlAttribute));
  1232. memset(attr, 0, sizeof(sdlAttribute));
  1233. sdl_deserialize_key(type->attributes, attr, in);
  1234. sdl_deserialize_attribute(attr, encoders, in);
  1235. --i;
  1236. }
  1237. }
  1238. if (**in != 0) {
  1239. WSDL_CACHE_SKIP(1, in);
  1240. type->model = sdl_deserialize_model(types, elements, in);
  1241. } else {
  1242. WSDL_CACHE_SKIP(1, in);
  1243. }
  1244. if (elements != NULL) {
  1245. efree(elements);
  1246. }
  1247. }
  1248. static void sdl_deserialize_encoder(encodePtr enc, sdlTypePtr *types, char **in)
  1249. {
  1250. int i;
  1251. WSDL_CACHE_GET_INT(enc->details.type, in);
  1252. enc->details.type_str = sdl_deserialize_string(in);
  1253. enc->details.ns = sdl_deserialize_string(in);
  1254. WSDL_CACHE_GET_INT(i, in);
  1255. enc->details.sdl_type = types[i];
  1256. enc->to_xml = sdl_guess_convert_xml;
  1257. enc->to_zval = sdl_guess_convert_zval;
  1258. if (enc->details.sdl_type == NULL) {
  1259. int ns_len = strlen(enc->details.ns);
  1260. int type_len = strlen(enc->details.type_str);
  1261. if (((ns_len == sizeof(SOAP_1_1_ENC_NAMESPACE)-1 &&
  1262. memcmp(enc->details.ns, SOAP_1_1_ENC_NAMESPACE, sizeof(SOAP_1_1_ENC_NAMESPACE)-1) == 0) ||
  1263. (ns_len == sizeof(SOAP_1_2_ENC_NAMESPACE)-1 &&
  1264. memcmp(enc->details.ns, SOAP_1_2_ENC_NAMESPACE, sizeof(SOAP_1_2_ENC_NAMESPACE)-1) == 0))) {
  1265. char *enc_nscat;
  1266. int enc_ns_len;
  1267. int enc_len;
  1268. encodePtr real_enc;
  1269. enc_ns_len = sizeof(XSD_NAMESPACE)-1;
  1270. enc_len = enc_ns_len + type_len + 1;
  1271. enc_nscat = emalloc(enc_len + 1);
  1272. memcpy(enc_nscat, XSD_NAMESPACE, sizeof(XSD_NAMESPACE)-1);
  1273. enc_nscat[enc_ns_len] = ':';
  1274. memcpy(enc_nscat+enc_ns_len+1, enc->details.type_str, type_len);
  1275. enc_nscat[enc_len] = '\0';
  1276. real_enc = get_encoder_ex(NULL, enc_nscat, enc_len);
  1277. efree(enc_nscat);
  1278. if (real_enc) {
  1279. enc->to_zval = real_enc->to_zval;
  1280. enc->to_xml = real_enc->to_xml;
  1281. }
  1282. }
  1283. }
  1284. }
  1285. static void sdl_deserialize_soap_body(sdlSoapBindingFunctionBodyPtr body, encodePtr *encoders, sdlTypePtr *types, char **in)
  1286. {
  1287. int i, j, n;
  1288. WSDL_CACHE_GET_1(body->use, sdlEncodingUse, in);
  1289. if (body->use == SOAP_ENCODED) {
  1290. WSDL_CACHE_GET_1(body->encodingStyle, sdlRpcEncodingStyle, in);
  1291. } else {
  1292. body->encodingStyle = SOAP_ENCODING_DEFAULT;
  1293. }
  1294. body->ns = sdl_deserialize_string(in);
  1295. WSDL_CACHE_GET_INT(i, in);
  1296. if (i > 0) {
  1297. body->headers = emalloc(sizeof(HashTable));
  1298. zend_hash_init(body->headers, i, NULL, delete_header, 0);
  1299. while (i > 0) {
  1300. sdlSoapBindingFunctionHeaderPtr tmp = emalloc(sizeof(sdlSoapBindingFunctionHeader));
  1301. memset(tmp, 0, sizeof(sdlSoapBindingFunctionHeader));
  1302. sdl_deserialize_key(body->headers, tmp, in);
  1303. WSDL_CACHE_GET_1(tmp->use, sdlEncodingUse, in);
  1304. if (tmp->use == SOAP_ENCODED) {
  1305. WSDL_CACHE_GET_1(tmp->encodingStyle, sdlRpcEncodingStyle, in);
  1306. } else {
  1307. tmp->encodingStyle = SOAP_ENCODING_DEFAULT;
  1308. }
  1309. tmp->name = sdl_deserialize_string(in);
  1310. tmp->ns = sdl_deserialize_string(in);
  1311. WSDL_CACHE_GET_INT(n, in);
  1312. tmp->encode = encoders[n];
  1313. WSDL_CACHE_GET_INT(n, in);
  1314. tmp->element = types[n];
  1315. --i;
  1316. WSDL_CACHE_GET_INT(j, in);
  1317. if (j > 0) {
  1318. tmp->headerfaults = emalloc(sizeof(HashTable));
  1319. zend_hash_init(tmp->headerfaults, i, NULL, delete_header, 0);
  1320. while (j > 0) {
  1321. sdlSoapBindingFunctionHeaderPtr tmp2 = emalloc(sizeof(sdlSoapBindingFunctionHeader));
  1322. memset(tmp2, 0, sizeof(sdlSoapBindingFunctionHeader));
  1323. sdl_deserialize_key(tmp->headerfaults, tmp2, in);
  1324. WSDL_CACHE_GET_1(tmp2->use, sdlEncodingUse, in);
  1325. if (tmp2->use == SOAP_ENCODED) {
  1326. WSDL_CACHE_GET_1(tmp2->encodingStyle, sdlRpcEncodingStyle, in);
  1327. } else {
  1328. tmp2->encodingStyle = SOAP_ENCODING_DEFAULT;
  1329. }
  1330. tmp2->name = sdl_deserialize_string(in);
  1331. tmp2->ns = sdl_deserialize_string(in);
  1332. WSDL_CACHE_GET_INT(n, in);
  1333. tmp2->encode = encoders[n];
  1334. WSDL_CACHE_GET_INT(n, in);
  1335. tmp2->element = types[n];
  1336. --j;
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. static HashTable* sdl_deserialize_parameters(encodePtr *encoders, sdlTypePtr *types, char **in)
  1343. {
  1344. int i, n;
  1345. HashTable *ht;
  1346. WSDL_CACHE_GET_INT(i, in);
  1347. if (i == 0) {return NULL;}
  1348. ht = emalloc(sizeof(HashTable));
  1349. zend_hash_init(ht, i, NULL, delete_parameter, 0);
  1350. while (i > 0) {
  1351. sdlParamPtr param = emalloc(sizeof(sdlParam));
  1352. sdl_deserialize_key(ht, param, in);
  1353. param->paramName = sdl_deserialize_string(in);
  1354. WSDL_CACHE_GET_INT(param->order, in);
  1355. WSDL_CACHE_GET_INT(n, in);
  1356. param->encode = encoders[n];
  1357. WSDL_CACHE_GET_INT(n, in);
  1358. param->element = types[n];
  1359. --i;
  1360. }
  1361. return ht;
  1362. }
  1363. static sdlPtr get_sdl_from_cache(const char *fn, const char *uri, time_t t, time_t *cached TSRMLS_DC)
  1364. {
  1365. sdlPtr sdl;
  1366. time_t old_t;
  1367. int i, num_groups, num_types, num_elements, num_encoders, num_bindings, num_func;
  1368. sdlFunctionPtr *functions = NULL;
  1369. sdlBindingPtr *bindings;
  1370. sdlTypePtr *types;
  1371. encodePtr *encoders;
  1372. encodePtr enc;
  1373. int f;
  1374. struct stat st;
  1375. char *in, *buf;
  1376. f = open(fn, O_RDONLY|O_BINARY);
  1377. if (f < 0) {
  1378. return NULL;
  1379. }
  1380. if (fstat(f, &st) != 0) {
  1381. close(f);
  1382. return NULL;
  1383. }
  1384. buf = in = emalloc(st.st_size);
  1385. if (read(f, in, st.st_size) != st.st_size) {
  1386. close(f);
  1387. efree(in);
  1388. return NULL;
  1389. }
  1390. close(f);
  1391. if (strncmp(in,"wsdl",4) != 0 || in[4] != WSDL_CACHE_VERSION || in[5] != '\0') {
  1392. unlink(fn);
  1393. efree(buf);
  1394. return NULL;
  1395. }
  1396. in += 6;
  1397. WSDL_CACHE_GET(old_t, time_t, &in);
  1398. if (old_t < t) {
  1399. unlink(fn);
  1400. efree(buf);
  1401. return NULL;
  1402. }
  1403. *cached = old_t;
  1404. WSDL_CACHE_GET_INT(i, &in);
  1405. if (i == 0 && strncmp(in, uri, i) != 0) {
  1406. unlink(fn);
  1407. efree(buf);
  1408. return NULL;
  1409. }
  1410. WSDL_CACHE_SKIP(i, &in);
  1411. sdl = emalloc(sizeof(*sdl));
  1412. memset(sdl, 0, sizeof(*sdl));
  1413. sdl->source = sdl_deserialize_string(&in);
  1414. sdl->target_ns = sdl_deserialize_string(&in);
  1415. WSDL_CACHE_GET_INT(num_groups, &in);
  1416. WSDL_CACHE_GET_INT(num_types, &in);
  1417. WSDL_CACHE_GET_INT(num_elements, &in);
  1418. WSDL_CACHE_GET_INT(num_encoders, &in);
  1419. i = num_groups+num_types+num_elements;
  1420. types = safe_emalloc((i+1), sizeof(sdlTypePtr), 0);
  1421. types[0] = NULL;
  1422. while (i > 0) {
  1423. types[i] = emalloc(sizeof(sdlType));
  1424. memset(types[i], 0, sizeof(sdlType));
  1425. i--;
  1426. }
  1427. i = num_encoders;
  1428. enc = defaultEncoding;
  1429. while (enc->details.type != END_KNOWN_TYPES) {
  1430. i++; enc++;
  1431. }
  1432. encoders = safe_emalloc((i+1), sizeof(encodePtr), 0);
  1433. i = num_encoders;
  1434. encoders[0] = NULL;
  1435. while (i > 0) {
  1436. encoders[i] = emalloc(sizeof(encode));
  1437. memset(encoders[i], 0, sizeof(encode));
  1438. i--;
  1439. }
  1440. i = num_encoders;
  1441. enc = defaultEncoding;
  1442. while (enc->details.type != END_KNOWN_TYPES) {
  1443. encoders[++i] = enc++;
  1444. }
  1445. i = 1;
  1446. if (num_groups > 0) {
  1447. sdl->groups = emalloc(sizeof(HashTable));
  1448. zend_hash_init(sdl->groups, num_groups, NULL, delete_type, 0);
  1449. while (i < num_groups+1) {
  1450. sdl_deserialize_key(sdl->groups, types[i], &in);
  1451. sdl_deserialize_type(types[i], types, encoders, &in);
  1452. i++;
  1453. }
  1454. }
  1455. if (num_types > 0) {
  1456. sdl->types = emalloc(sizeof(HashTable));
  1457. zend_hash_init(sdl->types, num_types, NULL, delete_type, 0);
  1458. while (i < num_groups+num_types+1) {
  1459. sdl_deserialize_key(sdl->types, types[i], &in);
  1460. sdl_deserialize_type(types[i], types, encoders, &in);
  1461. i++;
  1462. }
  1463. }
  1464. if (num_elements > 0) {
  1465. sdl->elements = emalloc(sizeof(HashTable));
  1466. zend_hash_init(sdl->elements, num_elements, NULL, delete_type, 0);
  1467. while (i < num_groups+num_types+num_elements+1) {
  1468. sdl_deserialize_key(sdl->elements, types[i], &in);
  1469. sdl_deserialize_type(types[i], types, encoders, &in);
  1470. i++;
  1471. }
  1472. }
  1473. i = 1;
  1474. if (num_encoders > 0) {
  1475. sdl->encoders = emalloc(sizeof(HashTable));
  1476. zend_hash_init(sdl->encoders, num_encoders, NULL, delete_encoder, 0);
  1477. while (i < num_encoders+1) {
  1478. sdl_deserialize_key(sdl->encoders, encoders[i], &in);
  1479. sdl_deserialize_encoder(encoders[i], types, &in);
  1480. i++;
  1481. }
  1482. }
  1483. /* deserialize bindings */
  1484. WSDL_CACHE_GET_INT(num_bindings, &in);
  1485. bindings = safe_emalloc(num_bindings, sizeof(sdlBindingPtr), 0);
  1486. if (num_bindings > 0) {
  1487. sdl->bindings = emalloc(sizeof(HashTable));
  1488. zend_hash_init(sdl->bindings, num_bindings, NULL, delete_binding, 0);
  1489. for (i = 0; i < num_bindings; i++) {
  1490. sdlBindingPtr binding = emalloc(sizeof(sdlBinding));
  1491. memset(binding, 0, sizeof(sdlBinding));
  1492. sdl_deserialize_key(sdl->bindings, binding, &in);
  1493. binding->name = sdl_deserialize_string(&in);
  1494. binding->location = sdl_deserialize_string(&in);
  1495. WSDL_CACHE_GET_1(binding->bindingType,sdlBindingType,&in);
  1496. if (binding->bindingType == BINDING_SOAP && *in != 0) {
  1497. sdlSoapBindingPtr soap_binding = binding->bindingAttributes = emalloc(sizeof(sdlSoapBinding));
  1498. WSDL_CACHE_GET_1(soap_binding->style,sdlEncodingStyle,&in);
  1499. WSDL_CACHE_GET_1(soap_binding->transport,sdlTransport,&in);
  1500. } else {
  1501. WSDL_CACHE_SKIP(1,&in);
  1502. }
  1503. bindings[i] = binding;
  1504. }
  1505. }
  1506. /* deserialize functions */
  1507. WSDL_CACHE_GET_INT(num_func, &in);
  1508. zend_hash_init(&sdl->functions, num_func, NULL, delete_function, 0);
  1509. if (num_func > 0) {
  1510. functions = safe_emalloc(num_func, sizeof(sdlFunctionPtr), 0);
  1511. for (i = 0; i < num_func; i++) {
  1512. int binding_num, num_faults;
  1513. sdlFunctionPtr func = emalloc(sizeof(sdlFunction));
  1514. sdl_deserialize_key(&sdl->functions, func, &in);
  1515. func->functionName = sdl_deserialize_string(&in);
  1516. func->requestName = sdl_deserialize_string(&in);
  1517. func->responseName = sdl_deserialize_string(&in);
  1518. WSDL_CACHE_GET_INT(binding_num, &in);
  1519. if (binding_num == 0) {
  1520. func->binding = NULL;
  1521. } else {
  1522. func->binding = bindings[binding_num-1];
  1523. }
  1524. if (func->binding && func->binding->bindingType == BINDING_SOAP && *in != 0) {
  1525. sdlSoapBindingFunctionPtr binding = func->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunction));
  1526. memset(binding, 0, sizeof(sdlSoapBindingFunction));
  1527. WSDL_CACHE_GET_1(binding->style,sdlEncodingStyle,&in);
  1528. binding->soapAction = sdl_deserialize_string(&in);
  1529. sdl_deserialize_soap_body(&binding->input, encoders, types, &in);
  1530. sdl_deserialize_soap_body(&binding->output, encoders, types, &in);
  1531. } else {
  1532. WSDL_CACHE_SKIP(1, &in);
  1533. func->bindingAttributes = NULL;
  1534. }
  1535. func->requestParameters = sdl_deserialize_parameters(encoders, types, &in);
  1536. func->responseParameters = sdl_deserialize_parameters(encoders, types, &in);
  1537. WSDL_CACHE_GET_INT(num_faults, &in);
  1538. if (num_faults > 0) {
  1539. int j;
  1540. func->faults = emalloc(sizeof(HashTable));
  1541. zend_hash_init(func->faults, num_faults, NULL, delete_fault, 0);
  1542. for (j = 0; j < num_faults; j++) {
  1543. sdlFaultPtr fault = emalloc(sizeof(sdlFault));
  1544. sdl_deserialize_key(func->faults, fault, &in);
  1545. fault->name =sdl_deserialize_string(&in);
  1546. fault->details =sdl_deserialize_parameters(encoders, types, &in);
  1547. if (*in != 0) {
  1548. sdlSoapBindingFunctionFaultPtr binding = fault->bindingAttributes = emalloc(sizeof(sdlSoapBindingFunctionFault));
  1549. memset(binding, 0, sizeof(sdlSoapBindingFunctionFault));
  1550. WSDL_CACHE_GET_1(binding->use,sdlEncodingUse,&in);
  1551. if (binding->use == SOAP_ENCODED) {
  1552. WSDL_CACHE_GET_1(binding->encodingStyle, sdlRpcEncodingStyle, &in);
  1553. } else {
  1554. binding->encodingStyle = SOAP_ENCODING_DEFAULT;
  1555. }
  1556. binding->ns = sdl_deserialize_string(&in);
  1557. } else {
  1558. WSDL_CACHE_SKIP(1, &in);
  1559. fault->bindingAttributes = NULL;
  1560. }
  1561. }
  1562. } else {
  1563. func->faults = NULL;
  1564. }
  1565. functions[i] = func;
  1566. }
  1567. }
  1568. /* deserialize requests */
  1569. WSDL_CACHE_GET_INT(i, &in);
  1570. if (i > 0) {
  1571. sdl->requests = emalloc(sizeof(HashTable));
  1572. zend_hash_init(sdl->requests, i, NULL, NULL, 0);
  1573. while (i > 0) {
  1574. int function_num;
  1575. WSDL_CACHE_GET_INT(function_num, &in);
  1576. sdl_deserialize_key(sdl->requests, functions[function_num-1], &in);
  1577. i--;
  1578. }
  1579. }
  1580. if (functions) {
  1581. efree(functions);
  1582. }
  1583. efree(bindings);
  1584. efree(encoders);
  1585. efree(types);
  1586. efree(buf);
  1587. return sdl;
  1588. }
  1589. static void sdl_serialize_string(const char *str, smart_str *out)
  1590. {
  1591. int i;
  1592. if (str) {
  1593. i = strlen(str);
  1594. WSDL_CACHE_PUT_INT(i, out);
  1595. if (i > 0) {
  1596. WSDL_CACHE_PUT_N(str, i, out);
  1597. }
  1598. } else {
  1599. WSDL_CACHE_PUT_INT(0x7fffffff, out);
  1600. }
  1601. }
  1602. static void sdl_serialize_key(HashTable *ht, smart_str *out)
  1603. {
  1604. char *key;
  1605. uint key_len;
  1606. ulong index;
  1607. if (zend_hash_get_current_key_ex(ht, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  1608. WSDL_CACHE_PUT_INT(key_len, out);
  1609. WSDL_CACHE_PUT_N(key, key_len, out);
  1610. } else {
  1611. WSDL_CACHE_PUT_INT(0, out);
  1612. }
  1613. }
  1614. static void sdl_serialize_encoder_ref(encodePtr enc, HashTable *tmp_encoders, smart_str *out) {
  1615. if (enc) {
  1616. int *encoder_num;
  1617. if (zend_hash_find(tmp_encoders, (char*)&enc, sizeof(enc), (void**)&encoder_num) == SUCCESS) {
  1618. WSDL_CACHE_PUT_INT(*encoder_num, out);
  1619. } else {
  1620. WSDL_CACHE_PUT_INT(0, out);
  1621. }
  1622. } else {
  1623. WSDL_CACHE_PUT_INT(0, out);
  1624. }
  1625. }
  1626. static void sdl_serialize_type_ref(sdlTypePtr type, HashTable *tmp_types, smart_str *out) {
  1627. if (type) {
  1628. int *type_num;
  1629. if (zend_hash_find(tmp_types, (char*)&type, sizeof(type), (void**)&type_num) == SUCCESS) {
  1630. WSDL_CACHE_PUT_INT(*type_num, out);
  1631. } else {
  1632. WSDL_CACHE_PUT_INT(0, out);
  1633. }
  1634. } else {
  1635. WSDL_CACHE_PUT_INT(0,out);
  1636. }
  1637. }
  1638. static void sdl_serialize_attribute(sdlAttributePtr attr, HashTable *tmp_encoders, smart_str *out)
  1639. {
  1640. int i;
  1641. sdl_serialize_string(attr->name, out);
  1642. sdl_serialize_string(attr->namens, out);
  1643. sdl_serialize_string(attr->ref, out);
  1644. sdl_serialize_string(attr->def, out);
  1645. sdl_serialize_string(attr->fixed, out);
  1646. WSDL_CACHE_PUT_1(attr->form, out);
  1647. WSDL_CACHE_PUT_1(attr->use, out);
  1648. sdl_serialize_encoder_ref(attr->encode, tmp_encoders, out);
  1649. if (attr->extraAttributes) {
  1650. i = zend_hash_num_elements(attr->extraAttributes);
  1651. } else {
  1652. i = 0;
  1653. }
  1654. WSDL_CACHE_PUT_INT(i, out);
  1655. if (i > 0) {
  1656. sdlExtraAttributePtr *tmp;
  1657. zend_hash_internal_pointer_reset(attr->extraAttributes);
  1658. while (zend_hash_get_current_data(attr->extraAttributes, (void**)&tmp) == SUCCESS) {
  1659. sdl_serialize_key(attr->extraAttributes, out);
  1660. sdl_serialize_string((*tmp)->ns, out);
  1661. sdl_serialize_string((*tmp)->val, out);
  1662. zend_hash_move_forward(attr->extraAttributes);
  1663. }
  1664. }
  1665. }
  1666. static void sdl_serialize_model(sdlContentModelPtr model, HashTable *tmp_types, HashTable *tmp_elements, smart_str *out)
  1667. {
  1668. WSDL_CACHE_PUT_1(model->kind, out);
  1669. WSDL_CACHE_PUT_INT(model->min_occurs, out);
  1670. WSDL_CACHE_PUT_INT(model->max_occurs, out);
  1671. switch (model->kind) {
  1672. case XSD_CONTENT_ELEMENT:
  1673. sdl_serialize_type_ref(model->u.element, tmp_elements, out);
  1674. break;
  1675. case XSD_CONTENT_SEQUENCE:
  1676. case XSD_CONTENT_ALL:
  1677. case XSD_CONTENT_CHOICE: {
  1678. sdlContentModelPtr *tmp;
  1679. int i = zend_hash_num_elements(model->u.content);
  1680. WSDL_CACHE_PUT_INT(i, out);
  1681. zend_hash_internal_pointer_reset(model->u.content);
  1682. while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
  1683. sdl_serialize_model(*tmp, tmp_types, tmp_elements, out);
  1684. zend_hash_move_forward(model->u.content);
  1685. }
  1686. }
  1687. break;
  1688. case XSD_CONTENT_GROUP_REF:
  1689. sdl_serialize_string(model->u.group_ref,out);
  1690. break;
  1691. case XSD_CONTENT_GROUP:
  1692. sdl_serialize_type_ref(model->u.group, tmp_types, out);
  1693. break;
  1694. default:
  1695. break;
  1696. }
  1697. }
  1698. static void sdl_serialize_resriction_int(sdlRestrictionIntPtr x, smart_str *out)
  1699. {
  1700. if (x) {
  1701. WSDL_CACHE_PUT_1(1, out);
  1702. WSDL_CACHE_PUT_INT(x->value, out);
  1703. WSDL_CACHE_PUT_1(x->fixed, out);
  1704. } else {
  1705. WSDL_CACHE_PUT_1(0, out);
  1706. }
  1707. }
  1708. static void sdl_serialize_resriction_char(sdlRestrictionCharPtr x, smart_str *out)
  1709. {
  1710. if (x) {
  1711. WSDL_CACHE_PUT_1(1, out);
  1712. sdl_serialize_string(x->value, out);
  1713. WSDL_CACHE_PUT_1(x->fixed, out);
  1714. } else {
  1715. WSDL_CACHE_PUT_1(0, out);
  1716. }
  1717. }
  1718. static void sdl_serialize_type(sdlTypePtr type, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out)
  1719. {
  1720. int i;
  1721. HashTable *tmp_elements = NULL;
  1722. WSDL_CACHE_PUT_1(type->kind, out);
  1723. sdl_serialize_string(type->name, out);
  1724. sdl_serialize_string(type->namens, out);
  1725. sdl_serialize_string(type->def, out);
  1726. sdl_serialize_string(type->fixed, out);
  1727. sdl_serialize_string(type->ref, out);
  1728. WSDL_CACHE_PUT_1(type->nillable, out);
  1729. WSDL_CACHE_PUT_1(type->form, out);
  1730. sdl_serialize_encoder_ref(type->encode, tmp_encoders, out);
  1731. if (type->restrictions) {
  1732. WSDL_CACHE_PUT_1(1, out);
  1733. sdl_serialize_resriction_int(type->restrictions->minExclusive,out);
  1734. sdl_serialize_resriction_int(type->restrictions->minInclusive,out);
  1735. sdl_serialize_resriction_int(type->restrictions->maxExclusive,out);
  1736. sdl_serialize_resriction_int(type->restrictions->maxInclusive,out);
  1737. sdl_serialize_resriction_int(type->restrictions->totalDigits,out);
  1738. sdl_serialize_resriction_int(type->restrictions->fractionDigits,out);
  1739. sdl_serialize_resriction_int(type->restrictions->length,out);
  1740. sdl_serialize_resriction_int(type->restrictions->minLength,out);
  1741. sdl_serialize_resriction_int(type->restrictions->maxLength,out);
  1742. sdl_serialize_resriction_char(type->restrictions->whiteSpace,out);
  1743. sdl_serialize_resriction_char(type->restrictions->pattern,out);
  1744. if (type->restrictions->enumeration) {
  1745. i = zend_hash_num_elements(type->restrictions->enumeration);
  1746. } else {
  1747. i = 0;
  1748. }
  1749. WSDL_CACHE_PUT_INT(i, out);
  1750. if (i > 0) {
  1751. sdlRestrictionCharPtr *tmp;
  1752. zend_hash_internal_pointer_reset(type->restrictions->enumeration);
  1753. while (zend_hash_get_current_data(type->restrictions->enumeration, (void**)&tmp) == SUCCESS) {
  1754. sdl_serialize_resriction_char(*tmp, out);
  1755. sdl_serialize_key(type->restrictions->enumeration, out);
  1756. zend_hash_move_forward(type->restrictions->enumeration);
  1757. }
  1758. }
  1759. } else {
  1760. WSDL_CACHE_PUT_1(0, out);
  1761. }
  1762. if (type->elements) {
  1763. i = zend_hash_num_elements(type->elements);
  1764. } else {
  1765. i = 0;
  1766. }
  1767. WSDL_CACHE_PUT_INT(i, out);
  1768. if (i > 0) {
  1769. sdlTypePtr *tmp;
  1770. tmp_elements = emalloc(sizeof(HashTable));
  1771. zend_hash_init(tmp_elements, i, NULL, NULL, 0);
  1772. zend_hash_internal_pointer_reset(type->elements);
  1773. while (zend_hash_get_current_data(type->elements, (void**)&tmp) == SUCCESS) {
  1774. sdl_serialize_key(type->elements, out);
  1775. sdl_serialize_type(*tmp, tmp_encoders, tmp_types, out);
  1776. zend_hash_add(tmp_elements, (char*)tmp, sizeof(*tmp), &i, sizeof(int), NULL);
  1777. i--;
  1778. zend_hash_move_forward(type->elements);
  1779. }
  1780. }
  1781. if (type->attributes) {
  1782. i = zend_hash_num_elements(type->attributes);
  1783. } else {
  1784. i = 0;
  1785. }
  1786. WSDL_CACHE_PUT_INT(i, out);
  1787. if (i > 0) {
  1788. sdlAttributePtr *tmp;
  1789. zend_hash_internal_pointer_reset(type->attributes);
  1790. while (zend_hash_get_current_data(type->attributes, (void**)&tmp) == SUCCESS) {
  1791. sdl_serialize_key(type->attributes, out);
  1792. sdl_serialize_attribute(*tmp, tmp_encoders, out);
  1793. zend_hash_move_forward(type->attributes);
  1794. }
  1795. }
  1796. if (type->model) {
  1797. WSDL_CACHE_PUT_1(1, out);
  1798. sdl_serialize_model(type->model, tmp_types, tmp_elements, out);
  1799. } else {
  1800. WSDL_CACHE_PUT_1(0, out);
  1801. }
  1802. if (tmp_elements != NULL) {
  1803. zend_hash_destroy(tmp_elements);
  1804. efree(tmp_elements);
  1805. }
  1806. }
  1807. static void sdl_serialize_encoder(encodePtr enc, HashTable *tmp_types, smart_str *out)
  1808. {
  1809. WSDL_CACHE_PUT_INT(enc->details.type, out);
  1810. sdl_serialize_string(enc->details.type_str, out);
  1811. sdl_serialize_string(enc->details.ns, out);
  1812. sdl_serialize_type_ref(enc->details.sdl_type, tmp_types, out);
  1813. }
  1814. static void sdl_serialize_parameters(HashTable *ht, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out)
  1815. {
  1816. int i;
  1817. if (ht) {
  1818. i = zend_hash_num_elements(ht);
  1819. } else {
  1820. i = 0;
  1821. }
  1822. WSDL_CACHE_PUT_INT(i, out);
  1823. if (i > 0) {
  1824. sdlParamPtr *tmp;
  1825. zend_hash_internal_pointer_reset(ht);
  1826. while (zend_hash_get_current_data(ht, (void**)&tmp) == SUCCESS) {
  1827. sdl_serialize_key(ht, out);
  1828. sdl_serialize_string((*tmp)->paramName, out);
  1829. WSDL_CACHE_PUT_INT((*tmp)->order, out);
  1830. sdl_serialize_encoder_ref((*tmp)->encode, tmp_encoders, out);
  1831. sdl_serialize_type_ref((*tmp)->element, tmp_types, out);
  1832. zend_hash_move_forward(ht);
  1833. }
  1834. }
  1835. }
  1836. static void sdl_serialize_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTable *tmp_encoders, HashTable *tmp_types, smart_str *out)
  1837. {
  1838. int i, j;
  1839. WSDL_CACHE_PUT_1(body->use, out);
  1840. if (body->use == SOAP_ENCODED) {
  1841. WSDL_CACHE_PUT_1(body->encodingStyle, out);
  1842. }
  1843. sdl_serialize_string(body->ns, out);
  1844. if (body->headers) {
  1845. i = zend_hash_num_elements(body->headers);
  1846. } else {
  1847. i = 0;
  1848. }
  1849. WSDL_CACHE_PUT_INT(i, out);
  1850. if (i > 0) {
  1851. sdlSoapBindingFunctionHeaderPtr *tmp;
  1852. zend_hash_internal_pointer_reset(body->headers);
  1853. while (zend_hash_get_current_data(body->headers, (void**)&tmp) == SUCCESS) {
  1854. sdl_serialize_key(body->headers, out);
  1855. WSDL_CACHE_PUT_1((*tmp)->use, out);
  1856. if ((*tmp)->use == SOAP_ENCODED) {
  1857. WSDL_CACHE_PUT_1((*tmp)->encodingStyle, out);
  1858. }
  1859. sdl_serialize_string((*tmp)->name, out);
  1860. sdl_serialize_string((*tmp)->ns, out);
  1861. sdl_serialize_encoder_ref((*tmp)->encode, tmp_encoders, out);
  1862. sdl_serialize_type_ref((*tmp)->element, tmp_types, out);
  1863. if ((*tmp)->headerfaults) {
  1864. j = zend_hash_num_elements((*tmp)->headerfaults);
  1865. } else {
  1866. j = 0;
  1867. }
  1868. WSDL_CACHE_PUT_INT(j, out);
  1869. if (j > 0) {
  1870. sdlSoapBindingFunctionHeaderPtr *tmp2;
  1871. zend_hash_internal_pointer_reset((*tmp)->headerfaults);
  1872. while (zend_hash_get_current_data((*tmp)->headerfaults, (void**)&tmp2) == SUCCESS) {
  1873. sdl_serialize_key((*tmp)->headerfaults, out);
  1874. WSDL_CACHE_PUT_1((*tmp2)->use, out);
  1875. if ((*tmp2)->use == SOAP_ENCODED) {
  1876. WSDL_CACHE_PUT_1((*tmp2)->encodingStyle, out);
  1877. }
  1878. sdl_serialize_string((*tmp2)->name, out);
  1879. sdl_serialize_string((*tmp2)->ns, out);
  1880. sdl_serialize_encoder_ref((*tmp2)->encode, tmp_encoders, out);
  1881. sdl_serialize_type_ref((*tmp2)->element, tmp_types, out);
  1882. zend_hash_move_forward((*tmp)->headerfaults);
  1883. }
  1884. }
  1885. zend_hash_move_forward(body->headers);
  1886. }
  1887. }
  1888. }
  1889. static void add_sdl_to_cache(const char *fn, const char *uri, time_t t, sdlPtr sdl TSRMLS_DC)
  1890. {
  1891. smart_str buf = {0};
  1892. smart_str *out = &buf;
  1893. int i;
  1894. int type_num = 1;
  1895. int encoder_num = 1;
  1896. int f;
  1897. encodePtr enc;
  1898. HashTable tmp_types;
  1899. HashTable tmp_encoders;
  1900. HashTable tmp_bindings;
  1901. HashTable tmp_functions;
  1902. #ifdef ZEND_WIN32
  1903. f = open(fn,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,S_IREAD|S_IWRITE);
  1904. #else
  1905. f = open(fn,O_CREAT|O_WRONLY|O_EXCL|O_BINARY,S_IREAD|S_IWRITE);
  1906. #endif
  1907. if (f < 0) {return;}
  1908. zend_hash_init(&tmp_types, 0, NULL, NULL, 0);
  1909. zend_hash_init(&tmp_encoders, 0, NULL, NULL, 0);
  1910. zend_hash_init(&tmp_bindings, 0, NULL, NULL, 0);
  1911. zend_hash_init(&tmp_functions, 0, NULL, NULL, 0);
  1912. WSDL_CACHE_PUT_N("wsdl", 4, out);
  1913. WSDL_CACHE_PUT_1(WSDL_CACHE_VERSION,out);
  1914. WSDL_CACHE_PUT_1(0,out);
  1915. WSDL_CACHE_PUT_N(&t, sizeof(t), out);
  1916. sdl_serialize_string(uri, out);
  1917. sdl_serialize_string(sdl->source, out);
  1918. sdl_serialize_string(sdl->target_ns, out);
  1919. if (sdl->groups) {
  1920. i = zend_hash_num_elements(sdl->groups);
  1921. } else {
  1922. i = 0;
  1923. }
  1924. WSDL_CACHE_PUT_INT(i, out);
  1925. if (i > 0) {
  1926. sdlTypePtr *tmp;
  1927. zend_hash_internal_pointer_reset(sdl->groups);
  1928. while (zend_hash_get_current_data(sdl->groups, (void**)&tmp) == SUCCESS) {
  1929. zend_hash_add(&tmp_types, (char*)tmp, sizeof(*tmp), (void**)&type_num, sizeof(type_num), NULL);
  1930. ++type_num;
  1931. zend_hash_move_forward(sdl->groups);
  1932. }
  1933. }
  1934. if (sdl->types) {
  1935. i = zend_hash_num_elements(sdl->types);
  1936. } else {
  1937. i = 0;
  1938. }
  1939. WSDL_CACHE_PUT_INT(i, out);
  1940. if (i > 0) {
  1941. sdlTypePtr *tmp;
  1942. zend_hash_internal_pointer_reset(sdl->types);
  1943. while (zend_hash_get_current_data(sdl->types, (void**)&tmp) == SUCCESS) {
  1944. zend_hash_add(&tmp_types, (char*)tmp, sizeof(*tmp), (void**)&type_num, sizeof(type_num), NULL);
  1945. ++type_num;
  1946. zend_hash_move_forward(sdl->types);
  1947. }
  1948. }
  1949. if (sdl->elements) {
  1950. i = zend_hash_num_elements(sdl->elements);
  1951. } else {
  1952. i = 0;
  1953. }
  1954. WSDL_CACHE_PUT_INT(i, out);
  1955. if (i > 0) {
  1956. sdlTypePtr *tmp;
  1957. zend_hash_internal_pointer_reset(sdl->elements);
  1958. while (zend_hash_get_current_data(sdl->elements, (void**)&tmp) == SUCCESS) {
  1959. zend_hash_add(&tmp_types, (char*)tmp, sizeof(*tmp), (void**)&type_num, sizeof(type_num), NULL);
  1960. ++type_num;
  1961. zend_hash_move_forward(sdl->elements);
  1962. }
  1963. }
  1964. if (sdl->encoders) {
  1965. i = zend_hash_num_elements(sdl->encoders);
  1966. } else {
  1967. i = 0;
  1968. }
  1969. WSDL_CACHE_PUT_INT(i, out);
  1970. if (i > 0) {
  1971. encodePtr *tmp;
  1972. zend_hash_internal_pointer_reset(sdl->encoders);
  1973. while (zend_hash_get_current_data(sdl->encoders, (void**)&tmp) == SUCCESS) {
  1974. zend_hash_add(&tmp_encoders, (char*)tmp, sizeof(*tmp), (void**)&encoder_num, sizeof(encoder_num), NULL);
  1975. ++encoder_num;
  1976. zend_hash_move_forward(sdl->encoders);
  1977. }
  1978. }
  1979. enc = defaultEncoding;
  1980. while (enc->details.type != END_KNOWN_TYPES) {
  1981. zend_hash_add(&tmp_encoders, (char*)&enc, sizeof(encodePtr), (void**)&encoder_num, sizeof(encoder_num), NULL);
  1982. enc++;
  1983. ++encoder_num;
  1984. }
  1985. if (sdl->groups) {
  1986. sdlTypePtr *tmp;
  1987. zend_hash_internal_pointer_reset(sdl->groups);
  1988. while (zend_hash_get_current_data(sdl->groups, (void**)&tmp) == SUCCESS) {
  1989. sdl_serialize_key(sdl->groups, out);
  1990. sdl_serialize_type(*tmp, &tmp_encoders, &tmp_types, out);
  1991. zend_hash_move_forward(sdl->groups);
  1992. }
  1993. }
  1994. if (sdl->types) {
  1995. sdlTypePtr *tmp;
  1996. zend_hash_internal_pointer_reset(sdl->types);
  1997. while (zend_hash_get_current_data(sdl->types, (void**)&tmp) == SUCCESS) {
  1998. sdl_serialize_key(sdl->types, out);
  1999. sdl_serialize_type(*tmp, &tmp_encoders, &tmp_types, out);
  2000. zend_hash_move_forward(sdl->types);
  2001. }
  2002. }
  2003. if (sdl->elements) {
  2004. sdlTypePtr *tmp;
  2005. zend_hash_internal_pointer_reset(sdl->elements);
  2006. while (zend_hash_get_current_data(sdl->elements, (void**)&tmp) == SUCCESS) {
  2007. sdl_serialize_key(sdl->elements, out);
  2008. sdl_serialize_type(*tmp, &tmp_encoders, &tmp_types, out);
  2009. zend_hash_move_forward(sdl->elements);
  2010. }
  2011. }
  2012. if (sdl->encoders) {
  2013. encodePtr *tmp;
  2014. zend_hash_internal_pointer_reset(sdl->encoders);
  2015. while (zend_hash_get_current_data(sdl->encoders, (void**)&tmp) == SUCCESS) {
  2016. sdl_serialize_key(sdl->encoders, out);
  2017. sdl_serialize_encoder(*tmp, &tmp_types, out);
  2018. zend_hash_move_forward(sdl->encoders);
  2019. }
  2020. }
  2021. /* serialize bindings */
  2022. if (sdl->bindings) {
  2023. i = zend_hash_num_elements(sdl->bindings);
  2024. } else {
  2025. i = 0;
  2026. }
  2027. WSDL_CACHE_PUT_INT(i, out);
  2028. if (i > 0) {
  2029. sdlBindingPtr *tmp;
  2030. int binding_num = 1;
  2031. zend_hash_internal_pointer_reset(sdl->bindings);
  2032. while (zend_hash_get_current_data(sdl->bindings, (void**)&tmp) == SUCCESS) {
  2033. sdl_serialize_key(sdl->bindings, out);
  2034. sdl_serialize_string((*tmp)->name, out);
  2035. sdl_serialize_string((*tmp)->location, out);
  2036. WSDL_CACHE_PUT_1((*tmp)->bindingType,out);
  2037. if ((*tmp)->bindingType == BINDING_SOAP && (*tmp)->bindingAttributes != NULL) {
  2038. sdlSoapBindingPtr binding = (sdlSoapBindingPtr)(*tmp)->bindingAttributes;
  2039. WSDL_CACHE_PUT_1(binding->style, out);
  2040. WSDL_CACHE_PUT_1(binding->transport, out);
  2041. } else {
  2042. WSDL_CACHE_PUT_1(0,out);
  2043. }
  2044. zend_hash_add(&tmp_bindings, (char*)tmp, sizeof(*tmp), (void**)&binding_num, sizeof(binding_num), NULL);
  2045. binding_num++;
  2046. zend_hash_move_forward(sdl->bindings);
  2047. }
  2048. }
  2049. /* serialize functions */
  2050. i = zend_hash_num_elements(&sdl->functions);
  2051. WSDL_CACHE_PUT_INT(i, out);
  2052. if (i > 0) {
  2053. sdlFunctionPtr *tmp;
  2054. int *binding_num;
  2055. int function_num = 1;
  2056. zend_hash_internal_pointer_reset(&sdl->functions);
  2057. while (zend_hash_get_current_data(&sdl->functions, (void**)&tmp) == SUCCESS) {
  2058. sdl_serialize_key(&sdl->functions, out);
  2059. sdl_serialize_string((*tmp)->functionName, out);
  2060. sdl_serialize_string((*tmp)->requestName, out);
  2061. sdl_serialize_string((*tmp)->responseName, out);
  2062. if ((*tmp)->binding == NULL ||
  2063. zend_hash_find(&tmp_bindings,(char*)&(*tmp)->binding,sizeof((*tmp)->binding), (void**)&binding_num) != SUCCESS) {
  2064. }
  2065. WSDL_CACHE_PUT_INT(*binding_num, out);
  2066. if (*binding_num >= 0) {
  2067. if ((*tmp)->binding->bindingType == BINDING_SOAP && (*tmp)->bindingAttributes != NULL) {
  2068. sdlSoapBindingFunctionPtr binding = (sdlSoapBindingFunctionPtr)(*tmp)->bindingAttributes;
  2069. WSDL_CACHE_PUT_1(binding->style, out);
  2070. sdl_serialize_string(binding->soapAction, out);
  2071. sdl_serialize_soap_body(&binding->input, &tmp_encoders, &tmp_types, out);
  2072. sdl_serialize_soap_body(&binding->output, &tmp_encoders, &tmp_types, out);
  2073. } else {
  2074. WSDL_CACHE_PUT_1(0,out);
  2075. }
  2076. }
  2077. sdl_serialize_parameters((*tmp)->requestParameters, &tmp_encoders, &tmp_types, out);
  2078. sdl_serialize_parameters((*tmp)->responseParameters, &tmp_encoders, &tmp_types, out);
  2079. if ((*tmp)->faults) {
  2080. sdlFaultPtr *fault;
  2081. WSDL_CACHE_PUT_INT(zend_hash_num_elements((*tmp)->faults), out);
  2082. zend_hash_internal_pointer_reset((*tmp)->faults);
  2083. while (zend_hash_get_current_data((*tmp)->faults, (void**)&fault) == SUCCESS) {
  2084. sdl_serialize_key((*tmp)->faults, out);
  2085. sdl_serialize_string((*fault)->name, out);
  2086. sdl_serialize_parameters((*fault)->details, &tmp_encoders, &tmp_types, out);
  2087. if ((*tmp)->binding->bindingType == BINDING_SOAP && (*fault)->bindingAttributes != NULL) {
  2088. sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)(*fault)->bindingAttributes;
  2089. WSDL_CACHE_PUT_1(binding->use, out);
  2090. if (binding->use == SOAP_ENCODED) {
  2091. WSDL_CACHE_PUT_1(binding->encodingStyle, out);
  2092. }
  2093. sdl_serialize_string(binding->ns, out);
  2094. } else {
  2095. WSDL_CACHE_PUT_1(0, out);
  2096. }
  2097. zend_hash_move_forward((*tmp)->faults);
  2098. }
  2099. } else {
  2100. WSDL_CACHE_PUT_INT(0, out);
  2101. }
  2102. zend_hash_add(&tmp_functions, (char*)tmp, sizeof(*tmp), (void**)&function_num, sizeof(function_num), NULL);
  2103. function_num++;
  2104. zend_hash_move_forward(&sdl->functions);
  2105. }
  2106. }
  2107. /* serialize requests */
  2108. if (sdl->requests) {
  2109. i = zend_hash_num_elements(sdl->requests);
  2110. } else {
  2111. i = 0;
  2112. }
  2113. WSDL_CACHE_PUT_INT(i, out);
  2114. if (i > 0) {
  2115. sdlFunctionPtr *tmp;
  2116. int *function_num;
  2117. zend_hash_internal_pointer_reset(sdl->requests);
  2118. while (zend_hash_get_current_data(sdl->requests, (void**)&tmp) == SUCCESS) {
  2119. if (zend_hash_find(&tmp_functions, (char*)tmp, sizeof(*tmp), (void**)&function_num) != SUCCESS) {
  2120. }
  2121. WSDL_CACHE_PUT_INT(*function_num, out);
  2122. sdl_serialize_key(sdl->requests, out);
  2123. zend_hash_move_forward(sdl->requests);
  2124. }
  2125. }
  2126. php_ignore_value(write(f, buf.c, buf.len));
  2127. close(f);
  2128. smart_str_free(&buf);
  2129. zend_hash_destroy(&tmp_functions);
  2130. zend_hash_destroy(&tmp_bindings);
  2131. zend_hash_destroy(&tmp_encoders);
  2132. zend_hash_destroy(&tmp_types);
  2133. }
  2134. static void make_persistent_restriction_int(void *data)
  2135. {
  2136. sdlRestrictionIntPtr *rest = (sdlRestrictionIntPtr *)data;
  2137. sdlRestrictionIntPtr prest = NULL;
  2138. prest = malloc(sizeof(sdlRestrictionInt));
  2139. *prest = **rest;
  2140. *rest = prest;
  2141. }
  2142. static void make_persistent_restriction_char(void *data)
  2143. {
  2144. sdlRestrictionCharPtr *rest = (sdlRestrictionCharPtr *)data;
  2145. sdlRestrictionCharPtr prest = NULL;
  2146. prest = malloc(sizeof(sdlRestrictionChar));
  2147. memset(prest, 0, sizeof(sdlRestrictionChar));
  2148. prest->value = strdup((*rest)->value);
  2149. prest->fixed = (*rest)->fixed;
  2150. *rest = prest;
  2151. }
  2152. static void make_persistent_sdl_type_ref(sdlTypePtr *type, HashTable *ptr_map, HashTable *bp_types)
  2153. {
  2154. sdlTypePtr *tmp;
  2155. if (zend_hash_find(ptr_map, (char *)type, sizeof(sdlTypePtr), (void**)&tmp) == SUCCESS) {
  2156. *type = *tmp;
  2157. } else {
  2158. zend_hash_next_index_insert(bp_types, (void*)&type, sizeof(sdlTypePtr*), NULL);
  2159. }
  2160. }
  2161. static void make_persistent_sdl_encoder_ref(encodePtr *enc, HashTable *ptr_map, HashTable *bp_encoders)
  2162. {
  2163. encodePtr *tmp;
  2164. /* do not process defaultEncoding's here */
  2165. if ((*enc) >= defaultEncoding && (*enc) < defaultEncoding + numDefaultEncodings) {
  2166. return;
  2167. }
  2168. if (zend_hash_find(ptr_map, (char *)enc, sizeof(encodePtr), (void**)&tmp) == SUCCESS) {
  2169. *enc = *tmp;
  2170. } else {
  2171. zend_hash_next_index_insert(bp_encoders, (void*)&enc, sizeof(encodePtr*), NULL);
  2172. }
  2173. }
  2174. static HashTable* make_persistent_sdl_function_headers(HashTable *headers, HashTable *ptr_map)
  2175. {
  2176. HashTable *pheaders;
  2177. sdlSoapBindingFunctionHeaderPtr *tmp, pheader;
  2178. encodePtr *penc;
  2179. sdlTypePtr *ptype;
  2180. ulong index;
  2181. char *key;
  2182. uint key_len;
  2183. pheaders = malloc(sizeof(HashTable));
  2184. zend_hash_init(pheaders, zend_hash_num_elements(headers), NULL, delete_header_persistent, 1);
  2185. zend_hash_internal_pointer_reset(headers);
  2186. while (zend_hash_get_current_data(headers, (void**)&tmp) == SUCCESS) {
  2187. pheader = malloc(sizeof(sdlSoapBindingFunctionHeader));
  2188. memset(pheader, 0, sizeof(sdlSoapBindingFunctionHeader));
  2189. *pheader = **tmp;
  2190. if (pheader->name) {
  2191. pheader->name = strdup(pheader->name);
  2192. }
  2193. if (pheader->ns) {
  2194. pheader->ns = strdup(pheader->ns);
  2195. }
  2196. if (pheader->encode->details.sdl_type) {
  2197. if (zend_hash_find(ptr_map, (char*)&pheader->encode, sizeof(encodePtr), (void**)&penc) == FAILURE) {
  2198. assert(0);
  2199. }
  2200. pheader->encode = *penc;
  2201. }
  2202. if (pheader->element) {
  2203. if (zend_hash_find(ptr_map, (char*)&pheader->element, sizeof(sdlTypePtr), (void**)&ptype) == FAILURE) {
  2204. assert(0);
  2205. }
  2206. pheader->element = *ptype;
  2207. }
  2208. if (pheader->headerfaults) {
  2209. pheader->headerfaults = make_persistent_sdl_function_headers(pheader->headerfaults, ptr_map);
  2210. }
  2211. if (zend_hash_get_current_key_ex(headers, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2212. zend_hash_add(pheaders, key, key_len, (void*)&pheader, sizeof(sdlSoapBindingFunctionHeaderPtr), NULL);
  2213. } else {
  2214. zend_hash_next_index_insert(pheaders, (void*)&pheader, sizeof(sdlSoapBindingFunctionHeaderPtr), NULL);
  2215. }
  2216. zend_hash_move_forward(headers);
  2217. }
  2218. return pheaders;
  2219. }
  2220. static void make_persistent_sdl_soap_body(sdlSoapBindingFunctionBodyPtr body, HashTable *ptr_map)
  2221. {
  2222. if (body->ns) {
  2223. body->ns = strdup(body->ns);
  2224. }
  2225. if (body->headers) {
  2226. body->headers = make_persistent_sdl_function_headers(body->headers, ptr_map);
  2227. }
  2228. }
  2229. static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *ptr_map)
  2230. {
  2231. HashTable *pparams;
  2232. sdlParamPtr *tmp, pparam;
  2233. sdlTypePtr *ptype;
  2234. encodePtr *penc;
  2235. ulong index;
  2236. char *key;
  2237. uint key_len;
  2238. pparams = malloc(sizeof(HashTable));
  2239. zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1);
  2240. zend_hash_internal_pointer_reset(params);
  2241. while (zend_hash_get_current_data(params, (void**)&tmp) == SUCCESS) {
  2242. pparam = malloc(sizeof(sdlParam));
  2243. memset(pparam, 0, sizeof(sdlParam));
  2244. *pparam = **tmp;
  2245. if (pparam->paramName) {
  2246. pparam->paramName = strdup(pparam->paramName);
  2247. }
  2248. if (pparam->encode && pparam->encode->details.sdl_type) {
  2249. if (zend_hash_find(ptr_map, (char*)&pparam->encode, sizeof(encodePtr), (void**)&penc) == FAILURE) {
  2250. assert(0);
  2251. }
  2252. pparam->encode = *penc;
  2253. }
  2254. if (pparam->element) {
  2255. if (zend_hash_find(ptr_map, (char*)&pparam->element, sizeof(sdlTypePtr), (void**)&ptype) == FAILURE) {
  2256. assert(0);
  2257. }
  2258. pparam->element = *ptype;
  2259. }
  2260. if (zend_hash_get_current_key_ex(params, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2261. zend_hash_add(pparams, key, key_len, (void*)&pparam, sizeof(sdlParamPtr), NULL);
  2262. } else {
  2263. zend_hash_next_index_insert(pparams, (void*)&pparam, sizeof(sdlParamPtr), NULL);
  2264. }
  2265. zend_hash_move_forward(params);
  2266. }
  2267. return pparams;
  2268. }
  2269. static HashTable* make_persistent_sdl_function_faults(sdlFunctionPtr func, HashTable *faults, HashTable *ptr_map)
  2270. {
  2271. HashTable *pfaults;
  2272. sdlFaultPtr *tmp, pfault;
  2273. ulong index;
  2274. char *key;
  2275. uint key_len;
  2276. pfaults = malloc(sizeof(HashTable));
  2277. zend_hash_init(pfaults, zend_hash_num_elements(faults), NULL, delete_fault_persistent, 1);
  2278. zend_hash_internal_pointer_reset(faults);
  2279. while (zend_hash_get_current_data(faults, (void**)&tmp) == SUCCESS) {
  2280. pfault = malloc(sizeof(sdlFault));
  2281. memset(pfault, 0, sizeof(sdlFault));
  2282. *pfault = **tmp;
  2283. if (pfault->name) {
  2284. pfault->name = strdup(pfault->name);
  2285. }
  2286. if (pfault->details) {
  2287. pfault->details = make_persistent_sdl_parameters(pfault->details, ptr_map);
  2288. }
  2289. if (func->binding->bindingType == BINDING_SOAP && pfault->bindingAttributes) {
  2290. sdlSoapBindingFunctionFaultPtr soap_binding;
  2291. soap_binding = malloc(sizeof(sdlSoapBindingFunctionFault));
  2292. memset(soap_binding, 0, sizeof(sdlSoapBindingFunctionFault));
  2293. *soap_binding = *(sdlSoapBindingFunctionFaultPtr)pfault->bindingAttributes;
  2294. if (soap_binding->ns) {
  2295. soap_binding->ns = strdup(soap_binding->ns);
  2296. }
  2297. pfault->bindingAttributes = soap_binding;
  2298. }
  2299. if (zend_hash_get_current_key_ex(faults, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2300. zend_hash_add(pfaults, key, key_len, (void*)&pfault, sizeof(sdlParamPtr), NULL);
  2301. } else {
  2302. zend_hash_next_index_insert(pfaults, (void*)&pfault, sizeof(sdlParamPtr), NULL);
  2303. }
  2304. zend_hash_move_forward(faults);
  2305. }
  2306. return pfaults;
  2307. }
  2308. static sdlAttributePtr make_persistent_sdl_attribute(sdlAttributePtr attr, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
  2309. {
  2310. sdlAttributePtr pattr;
  2311. ulong index;
  2312. char *key;
  2313. uint key_len;
  2314. pattr = malloc(sizeof(sdlAttribute));
  2315. memset(pattr, 0, sizeof(sdlAttribute));
  2316. *pattr = *attr;
  2317. if (pattr->name) {
  2318. pattr->name = strdup(pattr->name);
  2319. }
  2320. if (pattr->namens) {
  2321. pattr->namens = strdup(pattr->namens);
  2322. }
  2323. if (pattr->ref) {
  2324. pattr->ref = strdup(pattr->ref);
  2325. }
  2326. if (pattr->def) {
  2327. pattr->def = strdup(pattr->def);
  2328. }
  2329. if (pattr->fixed) {
  2330. pattr->fixed = strdup(pattr->fixed);
  2331. }
  2332. /* we do not want to process defaultEncoding's here */
  2333. if (pattr->encode) {
  2334. make_persistent_sdl_encoder_ref(&pattr->encode, ptr_map, bp_encoders);
  2335. }
  2336. if (pattr->extraAttributes) {
  2337. sdlExtraAttributePtr *tmp, pextra;
  2338. pattr->extraAttributes = malloc(sizeof(HashTable));
  2339. zend_hash_init(pattr->extraAttributes, zend_hash_num_elements(attr->extraAttributes), NULL, delete_extra_attribute_persistent, 1);
  2340. zend_hash_internal_pointer_reset(pattr->extraAttributes);
  2341. while (zend_hash_get_current_data(attr->extraAttributes, (void**)&tmp) == SUCCESS) {
  2342. if (zend_hash_get_current_key_ex(attr->extraAttributes, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2343. pextra = malloc(sizeof(sdlExtraAttribute));
  2344. memset(pextra, 0, sizeof(sdlExtraAttribute));
  2345. if ((*tmp)->ns) {
  2346. pextra->ns = strdup((*tmp)->ns);
  2347. }
  2348. if ((*tmp)->val) {
  2349. pextra->val = strdup((*tmp)->val);
  2350. }
  2351. zend_hash_add(pattr->extraAttributes, key, key_len, (void*)&pextra, sizeof(sdlExtraAttributePtr), NULL);
  2352. }
  2353. zend_hash_move_forward(attr->extraAttributes);
  2354. }
  2355. }
  2356. return pattr;
  2357. }
  2358. static sdlContentModelPtr make_persistent_sdl_model(sdlContentModelPtr model, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
  2359. {
  2360. sdlContentModelPtr pmodel;
  2361. sdlContentModelPtr *tmp, pcontent;
  2362. pmodel = malloc(sizeof(sdlContentModel));
  2363. memset(pmodel, 0, sizeof(sdlContentModel));
  2364. *pmodel = *model;
  2365. switch (pmodel->kind) {
  2366. case XSD_CONTENT_ELEMENT:
  2367. if (pmodel->u.element) {
  2368. make_persistent_sdl_type_ref(&pmodel->u.element, ptr_map, bp_types);
  2369. }
  2370. break;
  2371. case XSD_CONTENT_SEQUENCE:
  2372. case XSD_CONTENT_ALL:
  2373. case XSD_CONTENT_CHOICE:
  2374. pmodel->u.content = malloc(sizeof(HashTable));
  2375. zend_hash_init(pmodel->u.content, zend_hash_num_elements(model->u.content), NULL, delete_model_persistent, 1);
  2376. zend_hash_internal_pointer_reset(model->u.content);
  2377. while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
  2378. pcontent = make_persistent_sdl_model(*tmp, ptr_map, bp_types, bp_encoders);
  2379. zend_hash_next_index_insert(pmodel->u.content, (void*)&pcontent, sizeof(sdlContentModelPtr), NULL);
  2380. zend_hash_move_forward(model->u.content);
  2381. }
  2382. break;
  2383. case XSD_CONTENT_GROUP_REF:
  2384. if (pmodel->u.group_ref) {
  2385. pmodel->u.group_ref = strdup(pmodel->u.group_ref);
  2386. }
  2387. break;
  2388. case XSD_CONTENT_GROUP:
  2389. if (pmodel->u.group) {
  2390. make_persistent_sdl_type_ref(&pmodel->u.group, ptr_map, bp_types);
  2391. }
  2392. break;
  2393. default:
  2394. break;
  2395. }
  2396. return pmodel;
  2397. }
  2398. static sdlTypePtr make_persistent_sdl_type(sdlTypePtr type, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
  2399. {
  2400. ulong index;
  2401. char *key;
  2402. uint key_len;
  2403. sdlTypePtr ptype = NULL;
  2404. ptype = malloc(sizeof(sdlType));
  2405. memset(ptype, 0, sizeof(sdlType));
  2406. *ptype = *type;
  2407. if (ptype->name) {
  2408. ptype->name = strdup(ptype->name);
  2409. }
  2410. if (ptype->namens) {
  2411. ptype->namens = strdup(ptype->namens);
  2412. }
  2413. if (ptype->def) {
  2414. ptype->def = strdup(ptype->def);
  2415. }
  2416. if (ptype->fixed) {
  2417. ptype->fixed = strdup(ptype->fixed);
  2418. }
  2419. if (ptype->ref) {
  2420. ptype->ref = strdup(ptype->ref);
  2421. }
  2422. /* we do not want to process defaultEncoding's here */
  2423. if (ptype->encode) {
  2424. make_persistent_sdl_encoder_ref(&ptype->encode, ptr_map, bp_encoders);
  2425. }
  2426. if (ptype->restrictions) {
  2427. ptype->restrictions = malloc(sizeof(sdlRestrictions));
  2428. memset(ptype->restrictions, 0, sizeof(sdlRestrictions));
  2429. *ptype->restrictions = *type->restrictions;
  2430. if (ptype->restrictions->minExclusive) {
  2431. make_persistent_restriction_int(&ptype->restrictions->minExclusive);
  2432. }
  2433. if (ptype->restrictions->maxExclusive) {
  2434. make_persistent_restriction_int(&ptype->restrictions->maxExclusive);
  2435. }
  2436. if (ptype->restrictions->minInclusive) {
  2437. make_persistent_restriction_int(&ptype->restrictions->minInclusive);
  2438. }
  2439. if (ptype->restrictions->maxInclusive) {
  2440. make_persistent_restriction_int(&ptype->restrictions->maxInclusive);
  2441. }
  2442. if (ptype->restrictions->totalDigits) {
  2443. make_persistent_restriction_int(&ptype->restrictions->totalDigits);
  2444. }
  2445. if (ptype->restrictions->fractionDigits) {
  2446. make_persistent_restriction_int(&ptype->restrictions->fractionDigits);
  2447. }
  2448. if (ptype->restrictions->length) {
  2449. make_persistent_restriction_int(&ptype->restrictions->length);
  2450. }
  2451. if (ptype->restrictions->minLength) {
  2452. make_persistent_restriction_int(&ptype->restrictions->minLength);
  2453. }
  2454. if (ptype->restrictions->maxLength) {
  2455. make_persistent_restriction_int(&ptype->restrictions->maxLength);
  2456. }
  2457. if (ptype->restrictions->whiteSpace) {
  2458. make_persistent_restriction_char(&ptype->restrictions->whiteSpace);
  2459. }
  2460. if (ptype->restrictions->pattern) {
  2461. make_persistent_restriction_char(&ptype->restrictions->pattern);
  2462. }
  2463. if (type->restrictions->enumeration) {
  2464. sdlRestrictionCharPtr tmp;
  2465. ptype->restrictions->enumeration = malloc(sizeof(HashTable));
  2466. zend_hash_init(ptype->restrictions->enumeration, zend_hash_num_elements(type->restrictions->enumeration), NULL, delete_restriction_var_char_persistent, 1);
  2467. zend_hash_copy(ptype->restrictions->enumeration, type->restrictions->enumeration, make_persistent_restriction_char, (void*)&tmp, sizeof(sdlRestrictionCharPtr));
  2468. }
  2469. }
  2470. if (ptype->elements) {
  2471. sdlTypePtr *tmp, pelem;
  2472. ptype->elements = malloc(sizeof(HashTable));
  2473. zend_hash_init(ptype->elements, zend_hash_num_elements(type->elements), NULL, delete_type_persistent, 1);
  2474. zend_hash_internal_pointer_reset(type->elements);
  2475. while (zend_hash_get_current_data(type->elements, (void **)&tmp) == SUCCESS) {
  2476. pelem = make_persistent_sdl_type(*tmp, ptr_map, bp_types, bp_encoders);
  2477. if (zend_hash_get_current_key_ex(type->elements, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2478. zend_hash_add(ptype->elements, key, key_len, (void*)&pelem, sizeof(sdlTypePtr), NULL);
  2479. } else {
  2480. zend_hash_next_index_insert(ptype->elements, (void*)&pelem, sizeof(sdlTypePtr), NULL);
  2481. }
  2482. zend_hash_add(ptr_map, (char*)tmp, sizeof(*tmp), (void*)&pelem, sizeof(sdlTypePtr), NULL);
  2483. zend_hash_move_forward(type->elements);
  2484. }
  2485. }
  2486. if (ptype->attributes) {
  2487. sdlAttributePtr *tmp, pattr;
  2488. ptype->attributes = malloc(sizeof(HashTable));
  2489. zend_hash_init(ptype->attributes, zend_hash_num_elements(type->attributes), NULL, delete_attribute_persistent, 1);
  2490. zend_hash_internal_pointer_reset(type->attributes);
  2491. while (zend_hash_get_current_data(type->attributes, (void **)&tmp) == SUCCESS) {
  2492. pattr = make_persistent_sdl_attribute(*tmp, ptr_map, bp_types, bp_encoders);
  2493. if (zend_hash_get_current_key_ex(type->attributes, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2494. zend_hash_add(ptype->attributes, key, key_len, (void*)&pattr, sizeof(sdlAttributePtr), NULL);
  2495. } else {
  2496. zend_hash_next_index_insert(ptype->attributes, (void*)&pattr, sizeof(sdlAttributePtr), NULL);
  2497. }
  2498. zend_hash_move_forward(type->attributes);
  2499. }
  2500. }
  2501. if (type->model) {
  2502. ptype->model = make_persistent_sdl_model(ptype->model, ptr_map, bp_types, bp_encoders);
  2503. }
  2504. return ptype;
  2505. }
  2506. static encodePtr make_persistent_sdl_encoder(encodePtr enc, HashTable *ptr_map, HashTable *bp_types, HashTable *bp_encoders)
  2507. {
  2508. encodePtr penc = NULL;
  2509. penc = malloc(sizeof(encode));
  2510. memset(penc, 0, sizeof(encode));
  2511. *penc = *enc;
  2512. if (penc->details.type_str) {
  2513. penc->details.type_str = strdup(penc->details.type_str);
  2514. }
  2515. if (penc->details.ns) {
  2516. penc->details.ns = strdup(penc->details.ns);
  2517. }
  2518. if (penc->details.sdl_type) {
  2519. make_persistent_sdl_type_ref(&penc->details.sdl_type, ptr_map, bp_types);
  2520. }
  2521. return penc;
  2522. }
  2523. static sdlBindingPtr make_persistent_sdl_binding(sdlBindingPtr bind, HashTable *ptr_map)
  2524. {
  2525. sdlBindingPtr pbind = NULL;
  2526. pbind = malloc(sizeof(sdlBinding));
  2527. memset(pbind, 0, sizeof(sdlBinding));
  2528. *pbind = *bind;
  2529. if (pbind->name) {
  2530. pbind->name = strdup(pbind->name);
  2531. }
  2532. if (pbind->location) {
  2533. pbind->location = strdup(pbind->location);
  2534. }
  2535. if (pbind->bindingType == BINDING_SOAP && pbind->bindingAttributes) {
  2536. sdlSoapBindingPtr soap_binding;
  2537. soap_binding = malloc(sizeof(sdlSoapBinding));
  2538. memset(soap_binding, 0, sizeof(sdlSoapBinding));
  2539. *soap_binding = *(sdlSoapBindingPtr)pbind->bindingAttributes;
  2540. pbind->bindingAttributes = soap_binding;
  2541. }
  2542. return pbind;
  2543. }
  2544. static sdlFunctionPtr make_persistent_sdl_function(sdlFunctionPtr func, HashTable *ptr_map)
  2545. {
  2546. sdlFunctionPtr pfunc = NULL;
  2547. pfunc = malloc(sizeof(sdlFunction));
  2548. memset(pfunc, 0, sizeof(sdlFunction));
  2549. *pfunc = *func;
  2550. if (pfunc->functionName) {
  2551. pfunc->functionName = strdup(pfunc->functionName);
  2552. }
  2553. if (pfunc->requestName) {
  2554. pfunc->requestName = strdup(pfunc->requestName);
  2555. }
  2556. if (pfunc->responseName) {
  2557. pfunc->responseName = strdup(pfunc->responseName);
  2558. }
  2559. if (pfunc->binding) {
  2560. sdlBindingPtr *tmp;
  2561. if (zend_hash_find(ptr_map, (char*)&pfunc->binding, sizeof(pfunc->binding), (void**)&tmp) == FAILURE) {
  2562. assert(0);
  2563. }
  2564. pfunc->binding = *tmp;
  2565. if (pfunc->binding->bindingType == BINDING_SOAP && pfunc->bindingAttributes) {
  2566. sdlSoapBindingFunctionPtr soap_binding;
  2567. soap_binding = malloc(sizeof(sdlSoapBindingFunction));
  2568. memset(soap_binding, 0, sizeof(sdlSoapBindingFunction));
  2569. *soap_binding = *(sdlSoapBindingFunctionPtr)pfunc->bindingAttributes;
  2570. if (soap_binding->soapAction) {
  2571. soap_binding->soapAction = strdup(soap_binding->soapAction);
  2572. }
  2573. make_persistent_sdl_soap_body(&soap_binding->input, ptr_map);
  2574. make_persistent_sdl_soap_body(&soap_binding->output, ptr_map);
  2575. pfunc->bindingAttributes = soap_binding;
  2576. }
  2577. if (pfunc->requestParameters) {
  2578. pfunc->requestParameters = make_persistent_sdl_parameters(pfunc->requestParameters, ptr_map);
  2579. }
  2580. if (pfunc->responseParameters) {
  2581. pfunc->responseParameters = make_persistent_sdl_parameters(pfunc->responseParameters, ptr_map);
  2582. }
  2583. if (pfunc->faults) {
  2584. pfunc->faults = make_persistent_sdl_function_faults(pfunc, pfunc->faults, ptr_map);
  2585. }
  2586. }
  2587. return pfunc;
  2588. }
  2589. static sdlPtr make_persistent_sdl(sdlPtr sdl TSRMLS_DC)
  2590. {
  2591. sdlPtr psdl = NULL;
  2592. HashTable ptr_map;
  2593. HashTable bp_types, bp_encoders;
  2594. ulong index;
  2595. char *key;
  2596. uint key_len;
  2597. zend_hash_init(&bp_types, 0, NULL, NULL, 0);
  2598. zend_hash_init(&bp_encoders, 0, NULL, NULL, 0);
  2599. zend_hash_init(&ptr_map, 0, NULL, NULL, 0);
  2600. psdl = malloc(sizeof(*sdl));
  2601. memset(psdl, 0, sizeof(*sdl));
  2602. if (sdl->source) {
  2603. psdl->source = strdup(sdl->source);
  2604. }
  2605. if (sdl->target_ns) {
  2606. psdl->target_ns = strdup(sdl->target_ns);
  2607. }
  2608. if (sdl->groups) {
  2609. sdlTypePtr *tmp;
  2610. sdlTypePtr ptype;
  2611. psdl->groups = malloc(sizeof(HashTable));
  2612. zend_hash_init(psdl->groups, zend_hash_num_elements(sdl->groups), NULL, delete_type_persistent, 1);
  2613. zend_hash_internal_pointer_reset(sdl->groups);
  2614. while (zend_hash_get_current_data(sdl->groups, (void **)&tmp) == SUCCESS) {
  2615. ptype = make_persistent_sdl_type(*tmp, &ptr_map, &bp_types, &bp_encoders);
  2616. if (zend_hash_get_current_key_ex(sdl->groups, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2617. zend_hash_add(psdl->groups, key, key_len, (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2618. } else {
  2619. zend_hash_next_index_insert(psdl->groups, (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2620. }
  2621. zend_hash_add(&ptr_map, (char*)tmp, sizeof(*tmp), (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2622. zend_hash_move_forward(sdl->groups);
  2623. }
  2624. }
  2625. if (sdl->types) {
  2626. sdlTypePtr *tmp;
  2627. sdlTypePtr ptype;
  2628. psdl->types = malloc(sizeof(HashTable));
  2629. zend_hash_init(psdl->types, zend_hash_num_elements(sdl->types), NULL, delete_type_persistent, 1);
  2630. zend_hash_internal_pointer_reset(sdl->types);
  2631. while (zend_hash_get_current_data(sdl->types, (void **)&tmp) == SUCCESS) {
  2632. ptype = make_persistent_sdl_type(*tmp, &ptr_map, &bp_types, &bp_encoders);
  2633. if (zend_hash_get_current_key_ex(sdl->types, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2634. zend_hash_add(psdl->types, key, key_len, (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2635. } else {
  2636. zend_hash_next_index_insert(psdl->types, (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2637. }
  2638. zend_hash_add(&ptr_map, (char*)tmp, sizeof(*tmp), (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2639. zend_hash_move_forward(sdl->types);
  2640. }
  2641. }
  2642. if (sdl->elements) {
  2643. sdlTypePtr *tmp;
  2644. sdlTypePtr ptype;
  2645. psdl->elements = malloc(sizeof(HashTable));
  2646. zend_hash_init(psdl->elements, zend_hash_num_elements(sdl->elements), NULL, delete_type_persistent, 1);
  2647. zend_hash_internal_pointer_reset(sdl->elements);
  2648. while (zend_hash_get_current_data(sdl->elements, (void **)&tmp) == SUCCESS) {
  2649. ptype = make_persistent_sdl_type(*tmp, &ptr_map, &bp_types, &bp_encoders);
  2650. if (zend_hash_get_current_key_ex(sdl->elements, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2651. zend_hash_add(psdl->elements, key, key_len, (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2652. } else {
  2653. zend_hash_next_index_insert(psdl->elements, (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2654. }
  2655. zend_hash_add(&ptr_map, (char*)tmp, sizeof(*tmp), (void*)&ptype, sizeof(sdlTypePtr), NULL);
  2656. zend_hash_move_forward(sdl->elements);
  2657. }
  2658. }
  2659. if (sdl->encoders) {
  2660. encodePtr *tmp;
  2661. encodePtr penc;
  2662. psdl->encoders = malloc(sizeof(HashTable));
  2663. zend_hash_init(psdl->encoders, zend_hash_num_elements(sdl->encoders), NULL, delete_encoder_persistent, 1);
  2664. zend_hash_internal_pointer_reset(sdl->encoders);
  2665. while (zend_hash_get_current_data(sdl->encoders, (void **)&tmp) == SUCCESS) {
  2666. penc = make_persistent_sdl_encoder(*tmp, &ptr_map, &bp_types, &bp_encoders);
  2667. if (zend_hash_get_current_key_ex(sdl->encoders, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2668. zend_hash_add(psdl->encoders, key, key_len, (void*)&penc, sizeof(encodePtr), NULL);
  2669. } else {
  2670. zend_hash_next_index_insert(psdl->encoders, (void*)&penc, sizeof(encodePtr), NULL);
  2671. }
  2672. zend_hash_add(&ptr_map, (char*)tmp, sizeof(*tmp), (void*)&penc, sizeof(encodePtr), NULL);
  2673. zend_hash_move_forward(sdl->encoders);
  2674. }
  2675. }
  2676. /* do backpatching here */
  2677. if (zend_hash_num_elements(&bp_types)) {
  2678. sdlTypePtr **tmp, *ptype = NULL;
  2679. zend_hash_internal_pointer_reset(&bp_types);
  2680. while (zend_hash_get_current_data(&bp_types, (void**)&tmp) == SUCCESS) {
  2681. if (zend_hash_find(&ptr_map, (char*)(*tmp), sizeof(**tmp), (void**)&ptype) == FAILURE) {
  2682. assert(0);
  2683. }
  2684. **tmp = *ptype;
  2685. zend_hash_move_forward(&bp_types);
  2686. }
  2687. }
  2688. if (zend_hash_num_elements(&bp_encoders)) {
  2689. encodePtr **tmp, *penc = NULL;
  2690. zend_hash_internal_pointer_reset(&bp_encoders);
  2691. while (zend_hash_get_current_data(&bp_encoders, (void**)&tmp) == SUCCESS) {
  2692. if (zend_hash_find(&ptr_map, (char*)(*tmp), sizeof(**tmp), (void**)&penc) == FAILURE) {
  2693. assert(0);
  2694. }
  2695. **tmp = *penc;
  2696. zend_hash_move_forward(&bp_encoders);
  2697. }
  2698. }
  2699. if (sdl->bindings) {
  2700. sdlBindingPtr *tmp;
  2701. sdlBindingPtr pbind;
  2702. psdl->bindings = malloc(sizeof(HashTable));
  2703. zend_hash_init(psdl->bindings, zend_hash_num_elements(sdl->bindings), NULL, delete_binding_persistent, 1);
  2704. zend_hash_internal_pointer_reset(sdl->bindings);
  2705. while (zend_hash_get_current_data(sdl->bindings, (void **)&tmp) == SUCCESS) {
  2706. pbind = make_persistent_sdl_binding(*tmp, &ptr_map);
  2707. if (zend_hash_get_current_key_ex(sdl->bindings, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2708. zend_hash_add(psdl->bindings, key, key_len, (void*)&pbind, sizeof(sdlBindingPtr), NULL);
  2709. } else {
  2710. zend_hash_next_index_insert(psdl->bindings, (void*)&pbind, sizeof(sdlBindingPtr), NULL);
  2711. }
  2712. zend_hash_add(&ptr_map, (char*)tmp, sizeof(*tmp), (void*)&pbind, sizeof(sdlBindingPtr), NULL);
  2713. zend_hash_move_forward(sdl->bindings);
  2714. }
  2715. }
  2716. zend_hash_init(&psdl->functions, zend_hash_num_elements(&sdl->functions), NULL, delete_function_persistent, 1);
  2717. if (zend_hash_num_elements(&sdl->functions)) {
  2718. sdlFunctionPtr *tmp;
  2719. sdlFunctionPtr pfunc;
  2720. zend_hash_internal_pointer_reset(&sdl->functions);
  2721. while (zend_hash_get_current_data(&sdl->functions, (void **)&tmp) == SUCCESS) {
  2722. pfunc = make_persistent_sdl_function(*tmp, &ptr_map);
  2723. if (zend_hash_get_current_key_ex(&sdl->functions, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2724. zend_hash_add(&psdl->functions, key, key_len, (void*)&pfunc, sizeof(sdlFunctionPtr), NULL);
  2725. } else {
  2726. zend_hash_next_index_insert(&psdl->functions, (void*)&pfunc, sizeof(sdlFunctionPtr), NULL);
  2727. }
  2728. zend_hash_add(&ptr_map, (char*)tmp, sizeof(*tmp), (void*)&pfunc, sizeof(sdlFunctionPtr), NULL);
  2729. zend_hash_move_forward(&sdl->functions);
  2730. }
  2731. }
  2732. if (sdl->requests) {
  2733. sdlFunctionPtr *tmp;
  2734. sdlFunctionPtr *preq;
  2735. psdl->requests = malloc(sizeof(HashTable));
  2736. zend_hash_init(psdl->requests, zend_hash_num_elements(sdl->requests), NULL, NULL, 1);
  2737. zend_hash_internal_pointer_reset(sdl->requests);
  2738. while (zend_hash_get_current_data(sdl->requests, (void **)&tmp) == SUCCESS) {
  2739. if (zend_hash_find(&ptr_map, (char*)tmp, sizeof(*tmp), (void**)&preq) == FAILURE) {
  2740. assert(0);
  2741. }
  2742. *tmp = *preq;
  2743. if (zend_hash_get_current_key_ex(sdl->requests, &key, &key_len, &index, 0, NULL) == HASH_KEY_IS_STRING) {
  2744. zend_hash_add(psdl->requests, key, key_len, (void*)&preq, sizeof(sdlFunctionPtr), NULL);
  2745. }
  2746. zend_hash_move_forward(sdl->requests);
  2747. }
  2748. }
  2749. zend_hash_destroy(&ptr_map);
  2750. zend_hash_destroy(&bp_encoders);
  2751. zend_hash_destroy(&bp_types);
  2752. return psdl;
  2753. }
  2754. typedef struct _sdl_cache_bucket {
  2755. sdlPtr sdl;
  2756. time_t time;
  2757. } sdl_cache_bucket;
  2758. static void delete_psdl(void *data)
  2759. {
  2760. sdl_cache_bucket *p = (sdl_cache_bucket*)data;
  2761. sdlPtr tmp = p->sdl;
  2762. zend_hash_destroy(&tmp->functions);
  2763. if (tmp->source) {
  2764. free(tmp->source);
  2765. }
  2766. if (tmp->target_ns) {
  2767. free(tmp->target_ns);
  2768. }
  2769. if (tmp->elements) {
  2770. zend_hash_destroy(tmp->elements);
  2771. free(tmp->elements);
  2772. }
  2773. if (tmp->encoders) {
  2774. zend_hash_destroy(tmp->encoders);
  2775. free(tmp->encoders);
  2776. }
  2777. if (tmp->types) {
  2778. zend_hash_destroy(tmp->types);
  2779. free(tmp->types);
  2780. }
  2781. if (tmp->groups) {
  2782. zend_hash_destroy(tmp->groups);
  2783. free(tmp->groups);
  2784. }
  2785. if (tmp->bindings) {
  2786. zend_hash_destroy(tmp->bindings);
  2787. free(tmp->bindings);
  2788. }
  2789. if (tmp->requests) {
  2790. zend_hash_destroy(tmp->requests);
  2791. free(tmp->requests);
  2792. }
  2793. free(tmp);
  2794. }
  2795. sdlPtr get_sdl(zval *this_ptr, char *uri, long cache_wsdl TSRMLS_DC)
  2796. {
  2797. char fn[MAXPATHLEN];
  2798. sdlPtr sdl = NULL;
  2799. char* old_error_code = SOAP_GLOBAL(error_code);
  2800. int uri_len = 0;
  2801. php_stream_context *context=NULL;
  2802. zval **tmp, **proxy_host, **proxy_port, *orig_context = NULL, *new_context = NULL;
  2803. smart_str headers = {0};
  2804. char* key = NULL;
  2805. time_t t = time(0);
  2806. zend_bool has_proxy_authorization = 0;
  2807. zend_bool has_authorization = 0;
  2808. if (strchr(uri,':') != NULL || IS_ABSOLUTE_PATH(uri, uri_len)) {
  2809. uri_len = strlen(uri);
  2810. } else if (VCWD_REALPATH(uri, fn) == NULL) {
  2811. cache_wsdl = WSDL_CACHE_NONE;
  2812. } else {
  2813. uri = fn;
  2814. uri_len = strlen(uri);
  2815. }
  2816. if ((cache_wsdl & WSDL_CACHE_MEMORY) && SOAP_GLOBAL(mem_cache)) {
  2817. sdl_cache_bucket *p;
  2818. if (SUCCESS == zend_hash_find(SOAP_GLOBAL(mem_cache), uri, uri_len+1, (void*)&p)) {
  2819. if (p->time < t - SOAP_GLOBAL(cache_ttl)) {
  2820. /* in-memory cache entry is expired */
  2821. zend_hash_del(&EG(persistent_list), uri, uri_len+1);
  2822. } else {
  2823. return p->sdl;
  2824. }
  2825. }
  2826. }
  2827. if ((cache_wsdl & WSDL_CACHE_DISK) && (uri_len < MAXPATHLEN)) {
  2828. time_t t = time(0);
  2829. char md5str[33];
  2830. PHP_MD5_CTX context;
  2831. unsigned char digest[16];
  2832. int len = strlen(SOAP_GLOBAL(cache_dir));
  2833. time_t cached;
  2834. char *user = php_get_current_user(TSRMLS_C);
  2835. int user_len = user ? strlen(user) + 1 : 0;
  2836. md5str[0] = '\0';
  2837. PHP_MD5Init(&context);
  2838. PHP_MD5Update(&context, (unsigned char*)uri, uri_len);
  2839. PHP_MD5Final(digest, &context);
  2840. make_digest(md5str, digest);
  2841. key = emalloc(len+sizeof("/wsdl-")-1+user_len+sizeof(md5str));
  2842. memcpy(key,SOAP_GLOBAL(cache_dir),len);
  2843. memcpy(key+len,"/wsdl-",sizeof("/wsdl-")-1);
  2844. len += sizeof("/wsdl-")-1;
  2845. if (user_len) {
  2846. memcpy(key+len, user, user_len-1);
  2847. len += user_len-1;
  2848. key[len++] = '-';
  2849. }
  2850. memcpy(key+len,md5str,sizeof(md5str));
  2851. if ((sdl = get_sdl_from_cache(key, uri, t-SOAP_GLOBAL(cache_ttl), &cached TSRMLS_CC)) != NULL) {
  2852. t = cached;
  2853. efree(key);
  2854. goto cache_in_memory;
  2855. }
  2856. }
  2857. if (SUCCESS == zend_hash_find(Z_OBJPROP_P(this_ptr),
  2858. "_stream_context", sizeof("_stream_context"), (void**)&tmp)) {
  2859. context = php_stream_context_from_zval(*tmp, 0);
  2860. } else {
  2861. context = php_stream_context_alloc(TSRMLS_C);
  2862. }
  2863. if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_user_agent", sizeof("_user_agent"), (void **) &tmp) == SUCCESS &&
  2864. Z_TYPE_PP(tmp) == IS_STRING && Z_STRLEN_PP(tmp) > 0) {
  2865. smart_str_appends(&headers, "User-Agent: ");
  2866. smart_str_appends(&headers, Z_STRVAL_PP(tmp));
  2867. smart_str_appends(&headers, "\r\n");
  2868. }
  2869. if (zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_host", sizeof("_proxy_host"), (void **) &proxy_host) == SUCCESS &&
  2870. Z_TYPE_PP(proxy_host) == IS_STRING &&
  2871. zend_hash_find(Z_OBJPROP_P(this_ptr), "_proxy_port", sizeof("_proxy_port"), (void **) &proxy_port) == SUCCESS &&
  2872. Z_TYPE_PP(proxy_port) == IS_LONG) {
  2873. zval str_port, *str_proxy;
  2874. smart_str proxy = {0};
  2875. str_port = **proxy_port;
  2876. zval_copy_ctor(&str_port);
  2877. convert_to_string(&str_port);
  2878. smart_str_appends(&proxy,"tcp://");
  2879. smart_str_appends(&proxy,Z_STRVAL_PP(proxy_host));
  2880. smart_str_appends(&proxy,":");
  2881. smart_str_appends(&proxy,Z_STRVAL(str_port));
  2882. smart_str_0(&proxy);
  2883. zval_dtor(&str_port);
  2884. MAKE_STD_ZVAL(str_proxy);
  2885. ZVAL_STRING(str_proxy, proxy.c, 1);
  2886. smart_str_free(&proxy);
  2887. if (!context) {
  2888. context = php_stream_context_alloc(TSRMLS_C);
  2889. }
  2890. php_stream_context_set_option(context, "http", "proxy", str_proxy);
  2891. zval_ptr_dtor(&str_proxy);
  2892. if (uri_len < sizeof("https://")-1 ||
  2893. strncasecmp(uri, "https://", sizeof("https://")-1) != 0) {
  2894. MAKE_STD_ZVAL(str_proxy);
  2895. ZVAL_BOOL(str_proxy, 1);
  2896. php_stream_context_set_option(context, "http", "request_fulluri", str_proxy);
  2897. zval_ptr_dtor(&str_proxy);
  2898. }
  2899. has_proxy_authorization = proxy_authentication(this_ptr, &headers TSRMLS_CC);
  2900. }
  2901. has_authorization = basic_authentication(this_ptr, &headers TSRMLS_CC);
  2902. /* Use HTTP/1.1 with "Connection: close" by default */
  2903. if (php_stream_context_get_option(context, "http", "protocol_version", &tmp) == FAILURE) {
  2904. zval *http_version;
  2905. MAKE_STD_ZVAL(http_version);
  2906. ZVAL_DOUBLE(http_version, 1.1);
  2907. php_stream_context_set_option(context, "http", "protocol_version", http_version);
  2908. zval_ptr_dtor(&http_version);
  2909. smart_str_appendl(&headers, "Connection: close\r\n", sizeof("Connection: close\r\n")-1);
  2910. }
  2911. if (headers.len > 0) {
  2912. zval *str_headers;
  2913. if (!context) {
  2914. context = php_stream_context_alloc(TSRMLS_C);
  2915. } else {
  2916. http_context_headers(context, has_authorization, has_proxy_authorization, 0, &headers TSRMLS_CC);
  2917. }
  2918. smart_str_0(&headers);
  2919. MAKE_STD_ZVAL(str_headers);
  2920. ZVAL_STRING(str_headers, headers.c, 1);
  2921. php_stream_context_set_option(context, "http", "header", str_headers);
  2922. smart_str_free(&headers);
  2923. zval_ptr_dtor(&str_headers);
  2924. }
  2925. if (context) {
  2926. MAKE_STD_ZVAL(new_context);
  2927. php_stream_context_to_zval(context, new_context);
  2928. orig_context = php_libxml_switch_context(new_context TSRMLS_CC);
  2929. }
  2930. SOAP_GLOBAL(error_code) = "WSDL";
  2931. sdl = load_wsdl(this_ptr, uri TSRMLS_CC);
  2932. if (sdl) {
  2933. sdl->is_persistent = 0;
  2934. }
  2935. SOAP_GLOBAL(error_code) = old_error_code;
  2936. if (context) {
  2937. php_libxml_switch_context(orig_context TSRMLS_CC);
  2938. zval_ptr_dtor(&new_context);
  2939. }
  2940. if ((cache_wsdl & WSDL_CACHE_DISK) && key) {
  2941. if (sdl) {
  2942. add_sdl_to_cache(key, uri, t, sdl TSRMLS_CC);
  2943. }
  2944. efree(key);
  2945. }
  2946. cache_in_memory:
  2947. if (cache_wsdl & WSDL_CACHE_MEMORY) {
  2948. if (sdl) {
  2949. sdlPtr psdl;
  2950. sdl_cache_bucket p;
  2951. if (SOAP_GLOBAL(mem_cache) == NULL) {
  2952. SOAP_GLOBAL(mem_cache) = malloc(sizeof(HashTable));
  2953. zend_hash_init(SOAP_GLOBAL(mem_cache), 0, NULL, delete_psdl, 1);
  2954. } else if (SOAP_GLOBAL(cache_limit) > 0 &&
  2955. SOAP_GLOBAL(cache_limit) <= zend_hash_num_elements(SOAP_GLOBAL(mem_cache))) {
  2956. /* in-memory cache overflow */
  2957. sdl_cache_bucket *q;
  2958. HashPosition pos;
  2959. time_t latest = t;
  2960. char *key = NULL;
  2961. uint key_len;
  2962. ulong idx;
  2963. for (zend_hash_internal_pointer_reset_ex(SOAP_GLOBAL(mem_cache), &pos);
  2964. zend_hash_get_current_data_ex(SOAP_GLOBAL(mem_cache), (void **) &q, &pos) == SUCCESS;
  2965. zend_hash_move_forward_ex(SOAP_GLOBAL(mem_cache), &pos)) {
  2966. if (q->time < latest) {
  2967. latest = q->time;
  2968. zend_hash_get_current_key_ex(SOAP_GLOBAL(mem_cache), &key, &key_len, &idx, 0, &pos);
  2969. }
  2970. }
  2971. if (key) {
  2972. zend_hash_del(SOAP_GLOBAL(mem_cache), key, key_len);
  2973. } else {
  2974. return sdl;
  2975. }
  2976. }
  2977. psdl = make_persistent_sdl(sdl TSRMLS_CC);
  2978. psdl->is_persistent = 1;
  2979. p.time = t;
  2980. p.sdl = psdl;
  2981. if (SUCCESS == zend_hash_update(SOAP_GLOBAL(mem_cache), uri,
  2982. uri_len+1, (void*)&p, sizeof(sdl_cache_bucket), NULL)) {
  2983. /* remove non-persitent sdl structure */
  2984. delete_sdl_impl(sdl);
  2985. /* and replace it with persistent one */
  2986. sdl = psdl;
  2987. } else {
  2988. php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to register persistent entry");
  2989. /* clean up persistent sdl */
  2990. delete_psdl(&p);
  2991. /* keep non-persistent sdl and return it */
  2992. }
  2993. }
  2994. }
  2995. return sdl;
  2996. }
  2997. /* Deletes */
  2998. void delete_sdl_impl(void *handle)
  2999. {
  3000. sdlPtr tmp = (sdlPtr)handle;
  3001. zend_hash_destroy(&tmp->functions);
  3002. if (tmp->source) {
  3003. efree(tmp->source);
  3004. }
  3005. if (tmp->target_ns) {
  3006. efree(tmp->target_ns);
  3007. }
  3008. if (tmp->elements) {
  3009. zend_hash_destroy(tmp->elements);
  3010. efree(tmp->elements);
  3011. }
  3012. if (tmp->encoders) {
  3013. zend_hash_destroy(tmp->encoders);
  3014. efree(tmp->encoders);
  3015. }
  3016. if (tmp->types) {
  3017. zend_hash_destroy(tmp->types);
  3018. efree(tmp->types);
  3019. }
  3020. if (tmp->groups) {
  3021. zend_hash_destroy(tmp->groups);
  3022. efree(tmp->groups);
  3023. }
  3024. if (tmp->bindings) {
  3025. zend_hash_destroy(tmp->bindings);
  3026. efree(tmp->bindings);
  3027. }
  3028. if (tmp->requests) {
  3029. zend_hash_destroy(tmp->requests);
  3030. efree(tmp->requests);
  3031. }
  3032. efree(tmp);
  3033. }
  3034. void delete_sdl(void *handle)
  3035. {
  3036. sdlPtr tmp = (sdlPtr)handle;
  3037. if (!tmp->is_persistent) {
  3038. delete_sdl_impl(tmp);
  3039. }
  3040. }
  3041. static void delete_binding(void *data)
  3042. {
  3043. sdlBindingPtr binding = *((sdlBindingPtr*)data);
  3044. if (binding->location) {
  3045. efree(binding->location);
  3046. }
  3047. if (binding->name) {
  3048. efree(binding->name);
  3049. }
  3050. if (binding->bindingType == BINDING_SOAP) {
  3051. sdlSoapBindingPtr soapBind = binding->bindingAttributes;
  3052. if (soapBind) {
  3053. efree(soapBind);
  3054. }
  3055. }
  3056. efree(binding);
  3057. }
  3058. static void delete_binding_persistent(void *data)
  3059. {
  3060. sdlBindingPtr binding = *((sdlBindingPtr*)data);
  3061. if (binding->location) {
  3062. free(binding->location);
  3063. }
  3064. if (binding->name) {
  3065. free(binding->name);
  3066. }
  3067. if (binding->bindingType == BINDING_SOAP) {
  3068. sdlSoapBindingPtr soapBind = binding->bindingAttributes;
  3069. if (soapBind) {
  3070. free(soapBind);
  3071. }
  3072. }
  3073. free(binding);
  3074. }
  3075. static void delete_sdl_soap_binding_function_body(sdlSoapBindingFunctionBody body)
  3076. {
  3077. if (body.ns) {
  3078. efree(body.ns);
  3079. }
  3080. if (body.headers) {
  3081. zend_hash_destroy(body.headers);
  3082. efree(body.headers);
  3083. }
  3084. }
  3085. static void delete_sdl_soap_binding_function_body_persistent(sdlSoapBindingFunctionBody body)
  3086. {
  3087. if (body.ns) {
  3088. free(body.ns);
  3089. }
  3090. if (body.headers) {
  3091. zend_hash_destroy(body.headers);
  3092. free(body.headers);
  3093. }
  3094. }
  3095. static void delete_function(void *data)
  3096. {
  3097. sdlFunctionPtr function = *((sdlFunctionPtr*)data);
  3098. if (function->functionName) {
  3099. efree(function->functionName);
  3100. }
  3101. if (function->requestName) {
  3102. efree(function->requestName);
  3103. }
  3104. if (function->responseName) {
  3105. efree(function->responseName);
  3106. }
  3107. if (function->requestParameters) {
  3108. zend_hash_destroy(function->requestParameters);
  3109. efree(function->requestParameters);
  3110. }
  3111. if (function->responseParameters) {
  3112. zend_hash_destroy(function->responseParameters);
  3113. efree(function->responseParameters);
  3114. }
  3115. if (function->faults) {
  3116. zend_hash_destroy(function->faults);
  3117. efree(function->faults);
  3118. }
  3119. if (function->bindingAttributes &&
  3120. function->binding && function->binding->bindingType == BINDING_SOAP) {
  3121. sdlSoapBindingFunctionPtr soapFunction = function->bindingAttributes;
  3122. if (soapFunction->soapAction) {
  3123. efree(soapFunction->soapAction);
  3124. }
  3125. delete_sdl_soap_binding_function_body(soapFunction->input);
  3126. delete_sdl_soap_binding_function_body(soapFunction->output);
  3127. efree(soapFunction);
  3128. }
  3129. efree(function);
  3130. }
  3131. static void delete_function_persistent(void *data)
  3132. {
  3133. sdlFunctionPtr function = *((sdlFunctionPtr*)data);
  3134. if (function->functionName) {
  3135. free(function->functionName);
  3136. }
  3137. if (function->requestName) {
  3138. free(function->requestName);
  3139. }
  3140. if (function->responseName) {
  3141. free(function->responseName);
  3142. }
  3143. if (function->requestParameters) {
  3144. zend_hash_destroy(function->requestParameters);
  3145. free(function->requestParameters);
  3146. }
  3147. if (function->responseParameters) {
  3148. zend_hash_destroy(function->responseParameters);
  3149. free(function->responseParameters);
  3150. }
  3151. if (function->faults) {
  3152. zend_hash_destroy(function->faults);
  3153. free(function->faults);
  3154. }
  3155. if (function->bindingAttributes &&
  3156. function->binding && function->binding->bindingType == BINDING_SOAP) {
  3157. sdlSoapBindingFunctionPtr soapFunction = function->bindingAttributes;
  3158. if (soapFunction->soapAction) {
  3159. free(soapFunction->soapAction);
  3160. }
  3161. delete_sdl_soap_binding_function_body_persistent(soapFunction->input);
  3162. delete_sdl_soap_binding_function_body_persistent(soapFunction->output);
  3163. free(soapFunction);
  3164. }
  3165. free(function);
  3166. }
  3167. static void delete_parameter(void *data)
  3168. {
  3169. sdlParamPtr param = *((sdlParamPtr*)data);
  3170. if (param->paramName) {
  3171. efree(param->paramName);
  3172. }
  3173. efree(param);
  3174. }
  3175. static void delete_parameter_persistent(void *data)
  3176. {
  3177. sdlParamPtr param = *((sdlParamPtr*)data);
  3178. if (param->paramName) {
  3179. free(param->paramName);
  3180. }
  3181. free(param);
  3182. }
  3183. static void delete_header(void *data)
  3184. {
  3185. sdlSoapBindingFunctionHeaderPtr hdr = *((sdlSoapBindingFunctionHeaderPtr*)data);
  3186. if (hdr->name) {
  3187. efree(hdr->name);
  3188. }
  3189. if (hdr->ns) {
  3190. efree(hdr->ns);
  3191. }
  3192. if (hdr->headerfaults) {
  3193. zend_hash_destroy(hdr->headerfaults);
  3194. efree(hdr->headerfaults);
  3195. }
  3196. efree(hdr);
  3197. }
  3198. static void delete_header_persistent(void *data)
  3199. {
  3200. sdlSoapBindingFunctionHeaderPtr hdr = *((sdlSoapBindingFunctionHeaderPtr*)data);
  3201. if (hdr->name) {
  3202. free(hdr->name);
  3203. }
  3204. if (hdr->ns) {
  3205. free(hdr->ns);
  3206. }
  3207. if (hdr->headerfaults) {
  3208. zend_hash_destroy(hdr->headerfaults);
  3209. free(hdr->headerfaults);
  3210. }
  3211. free(hdr);
  3212. }
  3213. static void delete_fault(void *data)
  3214. {
  3215. sdlFaultPtr fault = *((sdlFaultPtr*)data);
  3216. if (fault->name) {
  3217. efree(fault->name);
  3218. }
  3219. if (fault->details) {
  3220. zend_hash_destroy(fault->details);
  3221. efree(fault->details);
  3222. }
  3223. if (fault->bindingAttributes) {
  3224. sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
  3225. if (binding->ns) {
  3226. efree(binding->ns);
  3227. }
  3228. efree(fault->bindingAttributes);
  3229. }
  3230. efree(fault);
  3231. }
  3232. static void delete_fault_persistent(void *data)
  3233. {
  3234. sdlFaultPtr fault = *((sdlFaultPtr*)data);
  3235. if (fault->name) {
  3236. free(fault->name);
  3237. }
  3238. if (fault->details) {
  3239. zend_hash_destroy(fault->details);
  3240. free(fault->details);
  3241. }
  3242. if (fault->bindingAttributes) {
  3243. sdlSoapBindingFunctionFaultPtr binding = (sdlSoapBindingFunctionFaultPtr)fault->bindingAttributes;
  3244. if (binding->ns) {
  3245. free(binding->ns);
  3246. }
  3247. free(fault->bindingAttributes);
  3248. }
  3249. free(fault);
  3250. }
  3251. static void delete_document(void *doc_ptr)
  3252. {
  3253. xmlDocPtr doc = *((xmlDocPtr*)doc_ptr);
  3254. xmlFreeDoc(doc);
  3255. }