php_schema.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593
  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 "libxml/uri.h"
  23. static int schema_simpleType(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr simpleType, sdlTypePtr cur_type);
  24. static int schema_complexType(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr compType, sdlTypePtr cur_type);
  25. static int schema_list(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr listType, sdlTypePtr cur_type);
  26. static int schema_union(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr unionType, sdlTypePtr cur_type);
  27. static int schema_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr simpCompType, sdlTypePtr cur_type);
  28. static int schema_restriction_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr restType, sdlTypePtr cur_type, int simpleType);
  29. static int schema_restriction_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr restType, sdlTypePtr cur_type);
  30. static int schema_extension_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr extType, sdlTypePtr cur_type);
  31. static int schema_extension_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr extType, sdlTypePtr cur_type);
  32. static int schema_sequence(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr seqType, sdlTypePtr cur_type, sdlContentModelPtr model);
  33. static int schema_all(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr extType, sdlTypePtr cur_type, sdlContentModelPtr model);
  34. static int schema_choice(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr choiceType, sdlTypePtr cur_type, sdlContentModelPtr model);
  35. static int schema_group(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr groupType, sdlTypePtr cur_type, sdlContentModelPtr model);
  36. static int schema_any(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr extType, sdlTypePtr cur_type, sdlContentModelPtr model);
  37. static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTypePtr cur_type, sdlContentModelPtr model);
  38. static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdlTypePtr cur_type, sdlCtx *ctx);
  39. static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdlTypePtr cur_type, sdlCtx *ctx);
  40. static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valptr);
  41. static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *valptr);
  42. static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type);
  43. static encodePtr create_encoder(sdlPtr sdl, sdlTypePtr cur_type, const xmlChar *ns, const xmlChar *type)
  44. {
  45. smart_str nscat = {0};
  46. encodePtr enc, *enc_ptr;
  47. if (sdl->encoders == NULL) {
  48. sdl->encoders = emalloc(sizeof(HashTable));
  49. zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, 0);
  50. }
  51. smart_str_appends(&nscat, (char*)ns);
  52. smart_str_appendc(&nscat, ':');
  53. smart_str_appends(&nscat, (char*)type);
  54. smart_str_0(&nscat);
  55. if (zend_hash_find(sdl->encoders, nscat.c, nscat.len + 1, (void**)&enc_ptr) == SUCCESS) {
  56. enc = *enc_ptr;
  57. if (enc->details.ns) {
  58. efree(enc->details.ns);
  59. }
  60. if (enc->details.type_str) {
  61. efree(enc->details.type_str);
  62. }
  63. } else {
  64. enc_ptr = NULL;
  65. enc = emalloc(sizeof(encode));
  66. }
  67. memset(enc, 0, sizeof(encode));
  68. enc->details.ns = estrdup((char*)ns);
  69. enc->details.type_str = estrdup((char*)type);
  70. enc->details.sdl_type = cur_type;
  71. enc->to_xml = sdl_guess_convert_xml;
  72. enc->to_zval = sdl_guess_convert_zval;
  73. if (enc_ptr == NULL) {
  74. zend_hash_update(sdl->encoders, nscat.c, nscat.len + 1, &enc, sizeof(encodePtr), NULL);
  75. }
  76. smart_str_free(&nscat);
  77. return enc;
  78. }
  79. static encodePtr get_create_encoder(sdlPtr sdl, sdlTypePtr cur_type, const xmlChar *ns, const xmlChar *type)
  80. {
  81. encodePtr enc = get_encoder(sdl, (char*)ns, (char*)type);
  82. if (enc == NULL) {
  83. enc = create_encoder(sdl, cur_type, ns, type);
  84. }
  85. return enc;
  86. }
  87. static void schema_load_file(sdlCtx *ctx, xmlAttrPtr ns, xmlChar *location, xmlAttrPtr tns, int import TSRMLS_DC) {
  88. if (location != NULL &&
  89. !zend_hash_exists(&ctx->docs, (char*)location, xmlStrlen(location)+1)) {
  90. xmlDocPtr doc;
  91. xmlNodePtr schema;
  92. xmlAttrPtr new_tns;
  93. sdl_set_uri_credentials(ctx, (char*)location TSRMLS_CC);
  94. doc = soap_xmlParseFile((char*)location TSRMLS_CC);
  95. sdl_restore_uri_credentials(ctx TSRMLS_CC);
  96. if (doc == NULL) {
  97. soap_error1(E_ERROR, "Parsing Schema: can't import schema from '%s'", location);
  98. }
  99. schema = get_node(doc->children, "schema");
  100. if (schema == NULL) {
  101. xmlFreeDoc(doc);
  102. soap_error1(E_ERROR, "Parsing Schema: can't import schema from '%s'", location);
  103. }
  104. new_tns = get_attribute(schema->properties, "targetNamespace");
  105. if (import) {
  106. if (ns != NULL && (new_tns == NULL || xmlStrcmp(ns->children->content, new_tns->children->content) != 0)) {
  107. xmlFreeDoc(doc);
  108. soap_error2(E_ERROR, "Parsing Schema: can't import schema from '%s', unexpected 'targetNamespace'='%s'", location, ns->children->content);
  109. }
  110. if (ns == NULL && new_tns != NULL) {
  111. xmlFreeDoc(doc);
  112. soap_error2(E_ERROR, "Parsing Schema: can't import schema from '%s', unexpected 'targetNamespace'='%s'", location, new_tns->children->content);
  113. }
  114. } else {
  115. new_tns = get_attribute(schema->properties, "targetNamespace");
  116. if (new_tns == NULL) {
  117. if (tns != NULL) {
  118. xmlSetProp(schema, BAD_CAST("targetNamespace"), tns->children->content);
  119. }
  120. } else if (tns != NULL && xmlStrcmp(tns->children->content, new_tns->children->content) != 0) {
  121. xmlFreeDoc(doc);
  122. soap_error1(E_ERROR, "Parsing Schema: can't include schema from '%s', different 'targetNamespace'", location);
  123. }
  124. }
  125. zend_hash_add(&ctx->docs, (char*)location, xmlStrlen(location)+1, (void**)&doc, sizeof(xmlDocPtr), NULL);
  126. load_schema(ctx, schema TSRMLS_CC);
  127. }
  128. }
  129. /*
  130. 2.6.1 xsi:type
  131. 2.6.2 xsi:nil
  132. 2.6.3 xsi:schemaLocation, xsi:noNamespaceSchemaLocation
  133. */
  134. /*
  135. <schema
  136. attributeFormDefault = (qualified | unqualified) : unqualified
  137. blockDefault = (#all | List of (extension | restriction | substitution)) : ''
  138. elementFormDefault = (qualified | unqualified) : unqualified
  139. finalDefault = (#all | List of (extension | restriction)) : ''
  140. id = ID
  141. targetNamespace = anyURI
  142. version = token
  143. xml:lang = language
  144. {any attributes with non-schema namespace . . .}>
  145. Content: ((include | import | redefine | annotation)*, (((simpleType | complexType | group | attributeGroup) | element | attribute | notation), annotation*)*)
  146. </schema>
  147. */
  148. int load_schema(sdlCtx *ctx, xmlNodePtr schema TSRMLS_DC)
  149. {
  150. xmlNodePtr trav;
  151. xmlAttrPtr tns;
  152. if (!ctx->sdl->types) {
  153. ctx->sdl->types = emalloc(sizeof(HashTable));
  154. zend_hash_init(ctx->sdl->types, 0, NULL, delete_type, 0);
  155. }
  156. if (!ctx->attributes) {
  157. ctx->attributes = emalloc(sizeof(HashTable));
  158. zend_hash_init(ctx->attributes, 0, NULL, delete_attribute, 0);
  159. }
  160. if (!ctx->attributeGroups) {
  161. ctx->attributeGroups = emalloc(sizeof(HashTable));
  162. zend_hash_init(ctx->attributeGroups, 0, NULL, delete_type, 0);
  163. }
  164. tns = get_attribute(schema->properties, "targetNamespace");
  165. if (tns == NULL) {
  166. tns = xmlSetProp(schema, BAD_CAST("targetNamespace"), BAD_CAST(""));
  167. xmlNewNs(schema, BAD_CAST(""), NULL);
  168. }
  169. trav = schema->children;
  170. while (trav != NULL) {
  171. if (node_is_equal(trav,"include")) {
  172. xmlAttrPtr location;
  173. location = get_attribute(trav->properties, "schemaLocation");
  174. if (location == NULL) {
  175. soap_error0(E_ERROR, "Parsing Schema: include has no 'schemaLocation' attribute");
  176. } else {
  177. xmlChar *uri;
  178. xmlChar *base = xmlNodeGetBase(trav->doc, trav);
  179. if (base == NULL) {
  180. uri = xmlBuildURI(location->children->content, trav->doc->URL);
  181. } else {
  182. uri = xmlBuildURI(location->children->content, base);
  183. xmlFree(base);
  184. }
  185. schema_load_file(ctx, NULL, uri, tns, 0 TSRMLS_CC);
  186. xmlFree(uri);
  187. }
  188. } else if (node_is_equal(trav,"redefine")) {
  189. xmlAttrPtr location;
  190. location = get_attribute(trav->properties, "schemaLocation");
  191. if (location == NULL) {
  192. soap_error0(E_ERROR, "Parsing Schema: redefine has no 'schemaLocation' attribute");
  193. } else {
  194. xmlChar *uri;
  195. xmlChar *base = xmlNodeGetBase(trav->doc, trav);
  196. if (base == NULL) {
  197. uri = xmlBuildURI(location->children->content, trav->doc->URL);
  198. } else {
  199. uri = xmlBuildURI(location->children->content, base);
  200. xmlFree(base);
  201. }
  202. schema_load_file(ctx, NULL, uri, tns, 0 TSRMLS_CC);
  203. xmlFree(uri);
  204. /* TODO: <redefine> support */
  205. }
  206. } else if (node_is_equal(trav,"import")) {
  207. xmlAttrPtr ns, location;
  208. xmlChar *uri = NULL;
  209. ns = get_attribute(trav->properties, "namespace");
  210. location = get_attribute(trav->properties, "schemaLocation");
  211. if (ns != NULL && tns != NULL && xmlStrcmp(ns->children->content, tns->children->content) == 0) {
  212. if (location) {
  213. soap_error1(E_ERROR, "Parsing Schema: can't import schema from '%s', namespace must not match the enclosing schema 'targetNamespace'", location->children->content);
  214. } else {
  215. soap_error0(E_ERROR, "Parsing Schema: can't import schema. Namespace must not match the enclosing schema 'targetNamespace'");
  216. }
  217. }
  218. if (location) {
  219. xmlChar *base = xmlNodeGetBase(trav->doc, trav);
  220. if (base == NULL) {
  221. uri = xmlBuildURI(location->children->content, trav->doc->URL);
  222. } else {
  223. uri = xmlBuildURI(location->children->content, base);
  224. xmlFree(base);
  225. }
  226. }
  227. schema_load_file(ctx, ns, uri, tns, 1 TSRMLS_CC);
  228. if (uri != NULL) {xmlFree(uri);}
  229. } else if (node_is_equal(trav,"annotation")) {
  230. /* TODO: <annotation> support */
  231. /* annotation cleanup
  232. xmlNodePtr tmp = trav;
  233. trav = trav->next;
  234. xmlUnlinkNode(tmp);
  235. xmlFreeNode(tmp);
  236. continue;
  237. */
  238. } else {
  239. break;
  240. }
  241. trav = trav->next;
  242. }
  243. while (trav != NULL) {
  244. if (node_is_equal(trav,"simpleType")) {
  245. schema_simpleType(ctx->sdl, tns, trav, NULL);
  246. } else if (node_is_equal(trav,"complexType")) {
  247. schema_complexType(ctx->sdl, tns, trav, NULL);
  248. } else if (node_is_equal(trav,"group")) {
  249. schema_group(ctx->sdl, tns, trav, NULL, NULL);
  250. } else if (node_is_equal(trav,"attributeGroup")) {
  251. schema_attributeGroup(ctx->sdl, tns, trav, NULL, ctx);
  252. } else if (node_is_equal(trav,"element")) {
  253. schema_element(ctx->sdl, tns, trav, NULL, NULL);
  254. } else if (node_is_equal(trav,"attribute")) {
  255. schema_attribute(ctx->sdl, tns, trav, NULL, ctx);
  256. } else if (node_is_equal(trav,"notation")) {
  257. /* TODO: <notation> support */
  258. } else if (node_is_equal(trav,"annotation")) {
  259. /* TODO: <annotation> support */
  260. } else {
  261. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in schema", trav->name);
  262. }
  263. trav = trav->next;
  264. }
  265. return TRUE;
  266. }
  267. /*
  268. <simpleType
  269. final = (#all | (list | union | restriction))
  270. id = ID
  271. name = NCName
  272. {any attributes with non-schema namespace . . .}>
  273. Content: (annotation?, (restriction | list | union))
  274. </simpleType>
  275. */
  276. static int schema_simpleType(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr simpleType, sdlTypePtr cur_type)
  277. {
  278. xmlNodePtr trav;
  279. xmlAttrPtr name, ns;
  280. ns = get_attribute(simpleType->properties, "targetNamespace");
  281. if (ns == NULL) {
  282. ns = tns;
  283. }
  284. name = get_attribute(simpleType->properties, "name");
  285. if (cur_type != NULL) {
  286. /* Anonymous type inside <element> or <restriction> */
  287. sdlTypePtr newType, *ptr;
  288. newType = emalloc(sizeof(sdlType));
  289. memset(newType, 0, sizeof(sdlType));
  290. newType->kind = XSD_TYPEKIND_SIMPLE;
  291. if (name != NULL) {
  292. newType->name = estrdup((char*)name->children->content);
  293. newType->namens = estrdup((char*)ns->children->content);
  294. } else {
  295. newType->name = estrdup(cur_type->name);
  296. newType->namens = estrdup(cur_type->namens);
  297. }
  298. zend_hash_next_index_insert(sdl->types, &newType, sizeof(sdlTypePtr), (void **)&ptr);
  299. if (sdl->encoders == NULL) {
  300. sdl->encoders = emalloc(sizeof(HashTable));
  301. zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, 0);
  302. }
  303. cur_type->encode = emalloc(sizeof(encode));
  304. memset(cur_type->encode, 0, sizeof(encode));
  305. cur_type->encode->details.ns = estrdup(newType->namens);
  306. cur_type->encode->details.type_str = estrdup(newType->name);
  307. cur_type->encode->details.sdl_type = *ptr;
  308. cur_type->encode->to_xml = sdl_guess_convert_xml;
  309. cur_type->encode->to_zval = sdl_guess_convert_zval;
  310. zend_hash_next_index_insert(sdl->encoders, &cur_type->encode, sizeof(encodePtr), NULL);
  311. cur_type =*ptr;
  312. } else if (name != NULL) {
  313. sdlTypePtr newType, *ptr;
  314. newType = emalloc(sizeof(sdlType));
  315. memset(newType, 0, sizeof(sdlType));
  316. newType->kind = XSD_TYPEKIND_SIMPLE;
  317. newType->name = estrdup((char*)name->children->content);
  318. newType->namens = estrdup((char*)ns->children->content);
  319. if (cur_type == NULL) {
  320. zend_hash_next_index_insert(sdl->types, &newType, sizeof(sdlTypePtr), (void **)&ptr);
  321. } else {
  322. if (cur_type->elements == NULL) {
  323. cur_type->elements = emalloc(sizeof(HashTable));
  324. zend_hash_init(cur_type->elements, 0, NULL, delete_type, 0);
  325. }
  326. zend_hash_update(cur_type->elements, newType->name, strlen(newType->name)+1, &newType, sizeof(sdlTypePtr), (void **)&ptr);
  327. }
  328. cur_type = (*ptr);
  329. create_encoder(sdl, cur_type, ns->children->content, name->children->content);
  330. } else {
  331. soap_error0(E_ERROR, "Parsing Schema: simpleType has no 'name' attribute");
  332. }
  333. trav = simpleType->children;
  334. if (trav != NULL && node_is_equal(trav,"annotation")) {
  335. /* TODO: <annotation> support */
  336. trav = trav->next;
  337. }
  338. if (trav != NULL) {
  339. if (node_is_equal(trav,"restriction")) {
  340. schema_restriction_simpleContent(sdl, tns, trav, cur_type, 1);
  341. trav = trav->next;
  342. } else if (node_is_equal(trav,"list")) {
  343. cur_type->kind = XSD_TYPEKIND_LIST;
  344. schema_list(sdl, tns, trav, cur_type);
  345. trav = trav->next;
  346. } else if (node_is_equal(trav,"union")) {
  347. cur_type->kind = XSD_TYPEKIND_UNION;
  348. schema_union(sdl, tns, trav, cur_type);
  349. trav = trav->next;
  350. } else {
  351. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in simpleType", trav->name);
  352. }
  353. } else {
  354. soap_error0(E_ERROR, "Parsing Schema: expected <restriction>, <list> or <union> in simpleType");
  355. }
  356. if (trav != NULL) {
  357. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in simpleType", trav->name);
  358. }
  359. return TRUE;
  360. }
  361. /*
  362. <list
  363. id = ID
  364. itemType = QName
  365. {any attributes with non-schema namespace . . .}>
  366. Content: (annotation?, (simpleType?))
  367. </list>
  368. */
  369. static int schema_list(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr listType, sdlTypePtr cur_type)
  370. {
  371. xmlNodePtr trav;
  372. xmlAttrPtr itemType;
  373. itemType = get_attribute(listType->properties, "itemType");
  374. if (itemType != NULL) {
  375. char *type, *ns;
  376. xmlNsPtr nsptr;
  377. parse_namespace(itemType->children->content, &type, &ns);
  378. nsptr = xmlSearchNs(listType->doc, listType, BAD_CAST(ns));
  379. if (nsptr != NULL) {
  380. sdlTypePtr newType, *tmp;
  381. newType = emalloc(sizeof(sdlType));
  382. memset(newType, 0, sizeof(sdlType));
  383. newType->name = estrdup(type);
  384. newType->namens = estrdup((char*)nsptr->href);
  385. newType->encode = get_create_encoder(sdl, newType, nsptr->href, BAD_CAST(type));
  386. if (cur_type->elements == NULL) {
  387. cur_type->elements = emalloc(sizeof(HashTable));
  388. zend_hash_init(cur_type->elements, 0, NULL, delete_type, 0);
  389. }
  390. zend_hash_next_index_insert(cur_type->elements, &newType, sizeof(sdlTypePtr), (void **)&tmp);
  391. }
  392. if (type) {efree(type);}
  393. if (ns) {efree(ns);}
  394. }
  395. trav = listType->children;
  396. if (trav != NULL && node_is_equal(trav,"annotation")) {
  397. /* TODO: <annotation> support */
  398. trav = trav->next;
  399. }
  400. if (trav != NULL && node_is_equal(trav,"simpleType")) {
  401. sdlTypePtr newType, *tmp;
  402. if (itemType != NULL) {
  403. soap_error0(E_ERROR, "Parsing Schema: element has both 'itemType' attribute and subtype");
  404. }
  405. newType = emalloc(sizeof(sdlType));
  406. memset(newType, 0, sizeof(sdlType));
  407. {
  408. smart_str anonymous = {0};
  409. smart_str_appendl(&anonymous, "anonymous", sizeof("anonymous")-1);
  410. smart_str_append_long(&anonymous, zend_hash_num_elements(sdl->types));
  411. smart_str_0(&anonymous);
  412. newType->name = anonymous.c;
  413. }
  414. newType->namens = estrdup((char*)tns->children->content);
  415. if (cur_type->elements == NULL) {
  416. cur_type->elements = emalloc(sizeof(HashTable));
  417. zend_hash_init(cur_type->elements, 0, NULL, delete_type, 0);
  418. }
  419. zend_hash_next_index_insert(cur_type->elements, &newType, sizeof(sdlTypePtr), (void **)&tmp);
  420. schema_simpleType(sdl, tns, trav, newType);
  421. trav = trav->next;
  422. }
  423. if (trav != NULL) {
  424. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in list", trav->name);
  425. }
  426. return TRUE;
  427. }
  428. /*
  429. <union
  430. id = ID
  431. memberTypes = List of QName
  432. {any attributes with non-schema namespace . . .}>
  433. Content: (annotation?, (simpleType*))
  434. </union>
  435. */
  436. static int schema_union(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr unionType, sdlTypePtr cur_type)
  437. {
  438. xmlNodePtr trav;
  439. xmlAttrPtr memberTypes;
  440. memberTypes = get_attribute(unionType->properties, "memberTypes");
  441. if (memberTypes != NULL) {
  442. char *str, *start, *end, *next;
  443. char *type, *ns;
  444. xmlNsPtr nsptr;
  445. str = estrdup((char*)memberTypes->children->content);
  446. whiteSpace_collapse(BAD_CAST(str));
  447. start = str;
  448. while (start != NULL && *start != '\0') {
  449. end = strchr(start,' ');
  450. if (end == NULL) {
  451. next = NULL;
  452. } else {
  453. *end = '\0';
  454. next = end+1;
  455. }
  456. parse_namespace(BAD_CAST(start), &type, &ns);
  457. nsptr = xmlSearchNs(unionType->doc, unionType, BAD_CAST(ns));
  458. if (nsptr != NULL) {
  459. sdlTypePtr newType, *tmp;
  460. newType = emalloc(sizeof(sdlType));
  461. memset(newType, 0, sizeof(sdlType));
  462. newType->name = estrdup(type);
  463. newType->namens = estrdup((char*)nsptr->href);
  464. newType->encode = get_create_encoder(sdl, newType, nsptr->href, BAD_CAST(type));
  465. if (cur_type->elements == NULL) {
  466. cur_type->elements = emalloc(sizeof(HashTable));
  467. zend_hash_init(cur_type->elements, 0, NULL, delete_type, 0);
  468. }
  469. zend_hash_next_index_insert(cur_type->elements, &newType, sizeof(sdlTypePtr), (void **)&tmp);
  470. }
  471. if (type) {efree(type);}
  472. if (ns) {efree(ns);}
  473. start = next;
  474. }
  475. efree(str);
  476. }
  477. trav = unionType->children;
  478. if (trav != NULL && node_is_equal(trav,"annotation")) {
  479. /* TODO: <annotation> support */
  480. trav = trav->next;
  481. }
  482. while (trav != NULL) {
  483. if (node_is_equal(trav,"simpleType")) {
  484. sdlTypePtr newType, *tmp;
  485. newType = emalloc(sizeof(sdlType));
  486. memset(newType, 0, sizeof(sdlType));
  487. {
  488. smart_str anonymous = {0};
  489. smart_str_appendl(&anonymous, "anonymous", sizeof("anonymous")-1);
  490. smart_str_append_long(&anonymous, zend_hash_num_elements(sdl->types));
  491. smart_str_0(&anonymous);
  492. newType->name = anonymous.c;
  493. }
  494. newType->namens = estrdup((char*)tns->children->content);
  495. if (cur_type->elements == NULL) {
  496. cur_type->elements = emalloc(sizeof(HashTable));
  497. zend_hash_init(cur_type->elements, 0, NULL, delete_type, 0);
  498. }
  499. zend_hash_next_index_insert(cur_type->elements, &newType, sizeof(sdlTypePtr), (void **)&tmp);
  500. schema_simpleType(sdl, tns, trav, newType);
  501. } else {
  502. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in union", trav->name);
  503. }
  504. trav = trav->next;
  505. }
  506. if (trav != NULL) {
  507. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in union", trav->name);
  508. }
  509. return TRUE;
  510. }
  511. /*
  512. <simpleContent
  513. id = ID
  514. {any attributes with non-schema namespace . . .}>
  515. Content: (annotation?, (restriction | extension))
  516. </simpleContent>
  517. */
  518. static int schema_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr simpCompType, sdlTypePtr cur_type)
  519. {
  520. xmlNodePtr trav;
  521. trav = simpCompType->children;
  522. if (trav != NULL && node_is_equal(trav,"annotation")) {
  523. /* TODO: <annotation> support */
  524. trav = trav->next;
  525. }
  526. if (trav != NULL) {
  527. if (node_is_equal(trav, "restriction")) {
  528. cur_type->kind = XSD_TYPEKIND_RESTRICTION;
  529. schema_restriction_simpleContent(sdl, tns, trav, cur_type, 0);
  530. trav = trav->next;
  531. } else if (node_is_equal(trav, "extension")) {
  532. cur_type->kind = XSD_TYPEKIND_EXTENSION;
  533. schema_extension_simpleContent(sdl, tns, trav, cur_type);
  534. trav = trav->next;
  535. } else {
  536. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in simpleContent", trav->name);
  537. }
  538. } else {
  539. soap_error0(E_ERROR, "Parsing Schema: expected <restriction> or <extension> in simpleContent");
  540. }
  541. if (trav != NULL) {
  542. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in simpleContent", trav->name);
  543. }
  544. return TRUE;
  545. }
  546. /*
  547. simpleType:<restriction
  548. base = QName
  549. id = ID
  550. {any attributes with non-schema namespace . . .}>
  551. Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?)
  552. </restriction>
  553. simpleContent:<restriction
  554. base = QName
  555. id = ID
  556. {any attributes with non-schema namespace . . .}>
  557. Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | length | minLength | maxLength | enumeration | whiteSpace | pattern)*)?, ((attribute | attributeGroup)*, anyAttribute?))
  558. </restriction>
  559. */
  560. static int schema_restriction_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr restType, sdlTypePtr cur_type, int simpleType)
  561. {
  562. xmlNodePtr trav;
  563. xmlAttrPtr base;
  564. base = get_attribute(restType->properties, "base");
  565. if (base != NULL) {
  566. char *type, *ns;
  567. xmlNsPtr nsptr;
  568. parse_namespace(base->children->content, &type, &ns);
  569. nsptr = xmlSearchNs(restType->doc, restType, BAD_CAST(ns));
  570. if (nsptr != NULL) {
  571. cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
  572. }
  573. if (type) {efree(type);}
  574. if (ns) {efree(ns);}
  575. } else if (!simpleType) {
  576. soap_error0(E_ERROR, "Parsing Schema: restriction has no 'base' attribute");
  577. }
  578. if (cur_type->restrictions == NULL) {
  579. cur_type->restrictions = emalloc(sizeof(sdlRestrictions));
  580. memset(cur_type->restrictions, 0, sizeof(sdlRestrictions));
  581. }
  582. trav = restType->children;
  583. if (trav != NULL && node_is_equal(trav, "annotation")) {
  584. /* TODO: <annotation> support */
  585. trav = trav->next;
  586. }
  587. if (trav != NULL && node_is_equal(trav, "simpleType")) {
  588. schema_simpleType(sdl, tns, trav, cur_type);
  589. trav = trav->next;
  590. }
  591. while (trav != NULL) {
  592. if (node_is_equal(trav, "minExclusive")) {
  593. schema_restriction_var_int(trav, &cur_type->restrictions->minExclusive);
  594. } else if (node_is_equal(trav, "minInclusive")) {
  595. schema_restriction_var_int(trav, &cur_type->restrictions->minInclusive);
  596. } else if (node_is_equal(trav, "maxExclusive")) {
  597. schema_restriction_var_int(trav, &cur_type->restrictions->maxExclusive);
  598. } else if (node_is_equal(trav, "maxInclusive")) {
  599. schema_restriction_var_int(trav, &cur_type->restrictions->maxInclusive);
  600. } else if (node_is_equal(trav, "totalDigits")) {
  601. schema_restriction_var_int(trav, &cur_type->restrictions->totalDigits);
  602. } else if (node_is_equal(trav, "fractionDigits")) {
  603. schema_restriction_var_int(trav, &cur_type->restrictions->fractionDigits);
  604. } else if (node_is_equal(trav, "length")) {
  605. schema_restriction_var_int(trav, &cur_type->restrictions->length);
  606. } else if (node_is_equal(trav, "minLength")) {
  607. schema_restriction_var_int(trav, &cur_type->restrictions->minLength);
  608. } else if (node_is_equal(trav, "maxLength")) {
  609. schema_restriction_var_int(trav, &cur_type->restrictions->maxLength);
  610. } else if (node_is_equal(trav, "whiteSpace")) {
  611. schema_restriction_var_char(trav, &cur_type->restrictions->whiteSpace);
  612. } else if (node_is_equal(trav, "pattern")) {
  613. schema_restriction_var_char(trav, &cur_type->restrictions->pattern);
  614. } else if (node_is_equal(trav, "enumeration")) {
  615. sdlRestrictionCharPtr enumval = NULL;
  616. schema_restriction_var_char(trav, &enumval);
  617. if (cur_type->restrictions->enumeration == NULL) {
  618. cur_type->restrictions->enumeration = emalloc(sizeof(HashTable));
  619. zend_hash_init(cur_type->restrictions->enumeration, 0, NULL, delete_restriction_var_char, 0);
  620. }
  621. if (zend_hash_add(cur_type->restrictions->enumeration, enumval->value, strlen(enumval->value)+1, &enumval, sizeof(sdlRestrictionCharPtr), NULL) == FAILURE) {
  622. delete_restriction_var_char(&enumval);
  623. }
  624. } else {
  625. break;
  626. }
  627. trav = trav->next;
  628. }
  629. if (!simpleType) {
  630. while (trav != NULL) {
  631. if (node_is_equal(trav,"attribute")) {
  632. schema_attribute(sdl, tns, trav, cur_type, NULL);
  633. } else if (node_is_equal(trav,"attributeGroup")) {
  634. schema_attributeGroup(sdl, tns, trav, cur_type, NULL);
  635. } else if (node_is_equal(trav,"anyAttribute")) {
  636. /* TODO: <anyAttribute> support */
  637. trav = trav->next;
  638. break;
  639. } else {
  640. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in restriction", trav->name);
  641. }
  642. trav = trav->next;
  643. }
  644. }
  645. if (trav != NULL) {
  646. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in restriction", trav->name);
  647. }
  648. return TRUE;
  649. }
  650. /*
  651. <restriction
  652. base = QName
  653. id = ID
  654. {any attributes with non-schema namespace . . .}>
  655. Content: (annotation?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))
  656. </restriction>
  657. */
  658. static int schema_restriction_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr restType, sdlTypePtr cur_type)
  659. {
  660. xmlAttrPtr base;
  661. xmlNodePtr trav;
  662. base = get_attribute(restType->properties, "base");
  663. if (base != NULL) {
  664. char *type, *ns;
  665. xmlNsPtr nsptr;
  666. parse_namespace(base->children->content, &type, &ns);
  667. nsptr = xmlSearchNs(restType->doc, restType, BAD_CAST(ns));
  668. if (nsptr != NULL) {
  669. cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
  670. }
  671. if (type) {efree(type);}
  672. if (ns) {efree(ns);}
  673. } else {
  674. soap_error0(E_ERROR, "Parsing Schema: restriction has no 'base' attribute");
  675. }
  676. trav = restType->children;
  677. if (trav != NULL && node_is_equal(trav,"annotation")) {
  678. /* TODO: <annotation> support */
  679. trav = trav->next;
  680. }
  681. if (trav != NULL) {
  682. if (node_is_equal(trav,"group")) {
  683. schema_group(sdl, tns, trav, cur_type, NULL);
  684. trav = trav->next;
  685. } else if (node_is_equal(trav,"all")) {
  686. schema_all(sdl, tns, trav, cur_type, NULL);
  687. trav = trav->next;
  688. } else if (node_is_equal(trav,"choice")) {
  689. schema_choice(sdl, tns, trav, cur_type, NULL);
  690. trav = trav->next;
  691. } else if (node_is_equal(trav,"sequence")) {
  692. schema_sequence(sdl, tns, trav, cur_type, NULL);
  693. trav = trav->next;
  694. }
  695. }
  696. while (trav != NULL) {
  697. if (node_is_equal(trav,"attribute")) {
  698. schema_attribute(sdl, tns, trav, cur_type, NULL);
  699. } else if (node_is_equal(trav,"attributeGroup")) {
  700. schema_attributeGroup(sdl, tns, trav, cur_type, NULL);
  701. } else if (node_is_equal(trav,"anyAttribute")) {
  702. /* TODO: <anyAttribute> support */
  703. trav = trav->next;
  704. break;
  705. } else {
  706. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in restriction", trav->name);
  707. }
  708. trav = trav->next;
  709. }
  710. if (trav != NULL) {
  711. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in restriction", trav->name);
  712. }
  713. return TRUE;
  714. }
  715. static int schema_restriction_var_int(xmlNodePtr val, sdlRestrictionIntPtr *valptr)
  716. {
  717. xmlAttrPtr fixed, value;
  718. if ((*valptr) == NULL) {
  719. (*valptr) = emalloc(sizeof(sdlRestrictionInt));
  720. }
  721. memset((*valptr), 0, sizeof(sdlRestrictionInt));
  722. fixed = get_attribute(val->properties, "fixed");
  723. (*valptr)->fixed = FALSE;
  724. if (fixed != NULL) {
  725. if (!strncmp((char*)fixed->children->content, "true", sizeof("true")) ||
  726. !strncmp((char*)fixed->children->content, "1", sizeof("1")))
  727. (*valptr)->fixed = TRUE;
  728. }
  729. value = get_attribute(val->properties, "value");
  730. if (value == NULL) {
  731. soap_error0(E_ERROR, "Parsing Schema: missing restriction value");
  732. }
  733. (*valptr)->value = atoi((char*)value->children->content);
  734. return TRUE;
  735. }
  736. static int schema_restriction_var_char(xmlNodePtr val, sdlRestrictionCharPtr *valptr)
  737. {
  738. xmlAttrPtr fixed, value;
  739. if ((*valptr) == NULL) {
  740. (*valptr) = emalloc(sizeof(sdlRestrictionChar));
  741. }
  742. memset((*valptr), 0, sizeof(sdlRestrictionChar));
  743. fixed = get_attribute(val->properties, "fixed");
  744. (*valptr)->fixed = FALSE;
  745. if (fixed != NULL) {
  746. if (!strncmp((char*)fixed->children->content, "true", sizeof("true")) ||
  747. !strncmp((char*)fixed->children->content, "1", sizeof("1"))) {
  748. (*valptr)->fixed = TRUE;
  749. }
  750. }
  751. value = get_attribute(val->properties, "value");
  752. if (value == NULL) {
  753. soap_error0(E_ERROR, "Parsing Schema: missing restriction value");
  754. }
  755. (*valptr)->value = estrdup((char*)value->children->content);
  756. return TRUE;
  757. }
  758. /*
  759. From simpleContent (not supported):
  760. <extension
  761. base = QName
  762. id = ID
  763. {any attributes with non-schema namespace . . .}>
  764. Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
  765. </extension>
  766. */
  767. static int schema_extension_simpleContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr extType, sdlTypePtr cur_type)
  768. {
  769. xmlNodePtr trav;
  770. xmlAttrPtr base;
  771. base = get_attribute(extType->properties, "base");
  772. if (base != NULL) {
  773. char *type, *ns;
  774. xmlNsPtr nsptr;
  775. parse_namespace(base->children->content, &type, &ns);
  776. nsptr = xmlSearchNs(extType->doc, extType, BAD_CAST(ns));
  777. if (nsptr != NULL) {
  778. cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
  779. }
  780. if (type) {efree(type);}
  781. if (ns) {efree(ns);}
  782. } else {
  783. soap_error0(E_ERROR, "Parsing Schema: extension has no 'base' attribute");
  784. }
  785. trav = extType->children;
  786. if (trav != NULL && node_is_equal(trav,"annotation")) {
  787. /* TODO: <annotation> support */
  788. trav = trav->next;
  789. }
  790. while (trav != NULL) {
  791. if (node_is_equal(trav,"attribute")) {
  792. schema_attribute(sdl, tns, trav, cur_type, NULL);
  793. } else if (node_is_equal(trav,"attributeGroup")) {
  794. schema_attributeGroup(sdl, tns, trav, cur_type, NULL);
  795. } else if (node_is_equal(trav,"anyAttribute")) {
  796. /* TODO: <anyAttribute> support */
  797. trav = trav->next;
  798. break;
  799. } else {
  800. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in extension", trav->name);
  801. }
  802. trav = trav->next;
  803. }
  804. if (trav != NULL) {
  805. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in extension", trav->name);
  806. }
  807. return TRUE;
  808. }
  809. /*
  810. From complexContent:
  811. <extension
  812. base = QName
  813. id = ID
  814. {any attributes with non-schema namespace . . .}>
  815. Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
  816. </extension>
  817. */
  818. static int schema_extension_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr extType, sdlTypePtr cur_type)
  819. {
  820. xmlNodePtr trav;
  821. xmlAttrPtr base;
  822. base = get_attribute(extType->properties, "base");
  823. if (base != NULL) {
  824. char *type, *ns;
  825. xmlNsPtr nsptr;
  826. parse_namespace(base->children->content, &type, &ns);
  827. nsptr = xmlSearchNs(extType->doc, extType, BAD_CAST(ns));
  828. if (nsptr != NULL) {
  829. cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(type));
  830. }
  831. if (type) {efree(type);}
  832. if (ns) {efree(ns);}
  833. } else {
  834. soap_error0(E_ERROR, "Parsing Schema: extension has no 'base' attribute");
  835. }
  836. trav = extType->children;
  837. if (trav != NULL && node_is_equal(trav,"annotation")) {
  838. /* TODO: <annotation> support */
  839. trav = trav->next;
  840. }
  841. if (trav != NULL) {
  842. if (node_is_equal(trav,"group")) {
  843. schema_group(sdl, tns, trav, cur_type, NULL);
  844. trav = trav->next;
  845. } else if (node_is_equal(trav,"all")) {
  846. schema_all(sdl, tns, trav, cur_type, NULL);
  847. trav = trav->next;
  848. } else if (node_is_equal(trav,"choice")) {
  849. schema_choice(sdl, tns, trav, cur_type, NULL);
  850. trav = trav->next;
  851. } else if (node_is_equal(trav,"sequence")) {
  852. schema_sequence(sdl, tns, trav, cur_type, NULL);
  853. trav = trav->next;
  854. }
  855. }
  856. while (trav != NULL) {
  857. if (node_is_equal(trav,"attribute")) {
  858. schema_attribute(sdl, tns, trav, cur_type, NULL);
  859. } else if (node_is_equal(trav,"attributeGroup")) {
  860. schema_attributeGroup(sdl, tns, trav, cur_type, NULL);
  861. } else if (node_is_equal(trav,"anyAttribute")) {
  862. /* TODO: <anyAttribute> support */
  863. trav = trav->next;
  864. break;
  865. } else {
  866. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in extension", trav->name);
  867. }
  868. trav = trav->next;
  869. }
  870. if (trav != NULL) {
  871. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in extension", trav->name);
  872. }
  873. return TRUE;
  874. }
  875. void schema_min_max(xmlNodePtr node, sdlContentModelPtr model)
  876. {
  877. xmlAttrPtr attr = get_attribute(node->properties, "minOccurs");
  878. if (attr) {
  879. model->min_occurs = atoi((char*)attr->children->content);
  880. } else {
  881. model->min_occurs = 1;
  882. }
  883. attr = get_attribute(node->properties, "maxOccurs");
  884. if (attr) {
  885. if (!strncmp((char*)attr->children->content, "unbounded", sizeof("unbounded"))) {
  886. model->max_occurs = -1;
  887. } else {
  888. model->max_occurs = atoi((char*)attr->children->content);
  889. }
  890. } else {
  891. model->max_occurs = 1;
  892. }
  893. }
  894. /*
  895. <all
  896. id = ID
  897. maxOccurs = 1 : 1
  898. minOccurs = (0 | 1) : 1
  899. {any attributes with non-schema namespace . . .}>
  900. Content: (annotation?, element*)
  901. </all>
  902. */
  903. static int schema_all(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr all, sdlTypePtr cur_type, sdlContentModelPtr model)
  904. {
  905. xmlNodePtr trav;
  906. sdlContentModelPtr newModel;
  907. newModel = emalloc(sizeof(sdlContentModel));
  908. newModel->kind = XSD_CONTENT_ALL;
  909. newModel->u.content = emalloc(sizeof(HashTable));
  910. zend_hash_init(newModel->u.content, 0, NULL, delete_model, 0);
  911. if (model == NULL) {
  912. cur_type->model = newModel;
  913. } else {
  914. zend_hash_next_index_insert(model->u.content,&newModel,sizeof(sdlContentModelPtr), NULL);
  915. }
  916. schema_min_max(all, newModel);
  917. trav = all->children;
  918. if (trav != NULL && node_is_equal(trav,"annotation")) {
  919. /* TODO: <annotation> support */
  920. trav = trav->next;
  921. }
  922. while (trav != NULL) {
  923. if (node_is_equal(trav,"element")) {
  924. schema_element(sdl, tns, trav, cur_type, newModel);
  925. } else {
  926. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in all", trav->name);
  927. }
  928. trav = trav->next;
  929. }
  930. return TRUE;
  931. }
  932. /*
  933. <group
  934. name = NCName
  935. Content: (annotation?, (all | choice | sequence))
  936. </group>
  937. <group
  938. name = NCName
  939. ref = QName>
  940. Content: (annotation?)
  941. </group>
  942. */
  943. static int schema_group(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr groupType, sdlTypePtr cur_type, sdlContentModelPtr model)
  944. {
  945. xmlNodePtr trav;
  946. xmlAttrPtr ns, name, ref = NULL;
  947. sdlContentModelPtr newModel;
  948. ns = get_attribute(groupType->properties, "targetNamespace");
  949. if (ns == NULL) {
  950. ns = tns;
  951. }
  952. name = get_attribute(groupType->properties, "name");
  953. if (name == NULL) {
  954. name = ref = get_attribute(groupType->properties, "ref");
  955. }
  956. if (name) {
  957. smart_str key = {0};
  958. if (ref) {
  959. char *type, *ns;
  960. xmlNsPtr nsptr;
  961. parse_namespace(ref->children->content, &type, &ns);
  962. nsptr = xmlSearchNs(groupType->doc, groupType, BAD_CAST(ns));
  963. if (nsptr != NULL) {
  964. smart_str_appends(&key, (char*)nsptr->href);
  965. } else {
  966. xmlAttrPtr ns = get_attribute(groupType->properties, "targetNamespace");
  967. if (ns == NULL) {
  968. ns = tns;
  969. }
  970. if (ns) {
  971. smart_str_appends(&key, (char*)ns->children->content);
  972. }
  973. }
  974. smart_str_appendc(&key, ':');
  975. smart_str_appends(&key, type);
  976. smart_str_0(&key);
  977. newModel = emalloc(sizeof(sdlContentModel));
  978. newModel->kind = XSD_CONTENT_GROUP_REF;
  979. newModel->u.group_ref = estrdup(key.c);
  980. if (type) {efree(type);}
  981. if (ns) {efree(ns);}
  982. } else {
  983. newModel = emalloc(sizeof(sdlContentModel));
  984. newModel->kind = XSD_CONTENT_SEQUENCE; /* will be redefined */
  985. newModel->u.content = emalloc(sizeof(HashTable));
  986. zend_hash_init(newModel->u.content, 0, NULL, delete_model, 0);
  987. smart_str_appends(&key, (char*)ns->children->content);
  988. smart_str_appendc(&key, ':');
  989. smart_str_appends(&key, (char*)name->children->content);
  990. smart_str_0(&key);
  991. }
  992. if (cur_type == NULL) {
  993. sdlTypePtr newType;
  994. newType = emalloc(sizeof(sdlType));
  995. memset(newType, 0, sizeof(sdlType));
  996. if (sdl->groups == NULL) {
  997. sdl->groups = emalloc(sizeof(HashTable));
  998. zend_hash_init(sdl->groups, 0, NULL, delete_type, 0);
  999. }
  1000. if (zend_hash_add(sdl->groups, key.c, key.len+1, (void**)&newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
  1001. soap_error1(E_ERROR, "Parsing Schema: group '%s' already defined", key.c);
  1002. }
  1003. cur_type = newType;
  1004. }
  1005. smart_str_free(&key);
  1006. if (model == NULL) {
  1007. cur_type->model = newModel;
  1008. } else {
  1009. zend_hash_next_index_insert(model->u.content, &newModel, sizeof(sdlContentModelPtr), NULL);
  1010. }
  1011. } else {
  1012. soap_error0(E_ERROR, "Parsing Schema: group has no 'name' nor 'ref' attributes");
  1013. }
  1014. schema_min_max(groupType, newModel);
  1015. trav = groupType->children;
  1016. if (trav != NULL && node_is_equal(trav,"annotation")) {
  1017. /* TODO: <annotation> support */
  1018. trav = trav->next;
  1019. }
  1020. if (trav != NULL) {
  1021. if (node_is_equal(trav,"choice")) {
  1022. if (ref != NULL) {
  1023. soap_error0(E_ERROR, "Parsing Schema: group has both 'ref' attribute and subcontent");
  1024. }
  1025. newModel->kind = XSD_CONTENT_CHOICE;
  1026. schema_choice(sdl, tns, trav, cur_type, newModel);
  1027. trav = trav->next;
  1028. } else if (node_is_equal(trav,"sequence")) {
  1029. if (ref != NULL) {
  1030. soap_error0(E_ERROR, "Parsing Schema: group has both 'ref' attribute and subcontent");
  1031. }
  1032. newModel->kind = XSD_CONTENT_SEQUENCE;
  1033. schema_sequence(sdl, tns, trav, cur_type, newModel);
  1034. trav = trav->next;
  1035. } else if (node_is_equal(trav,"all")) {
  1036. if (ref != NULL) {
  1037. soap_error0(E_ERROR, "Parsing Schema: group has both 'ref' attribute and subcontent");
  1038. }
  1039. newModel->kind = XSD_CONTENT_ALL;
  1040. schema_all(sdl, tns, trav, cur_type, newModel);
  1041. trav = trav->next;
  1042. } else {
  1043. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in group", trav->name);
  1044. }
  1045. }
  1046. if (trav != NULL) {
  1047. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in group", trav->name);
  1048. }
  1049. return TRUE;
  1050. }
  1051. /*
  1052. <choice
  1053. id = ID
  1054. maxOccurs = (nonNegativeInteger | unbounded) : 1
  1055. minOccurs = nonNegativeInteger : 1
  1056. {any attributes with non-schema namespace . . .}>
  1057. Content: (annotation?, (element | group | choice | sequence | any)*)
  1058. </choice>
  1059. */
  1060. static int schema_choice(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr choiceType, sdlTypePtr cur_type, sdlContentModelPtr model)
  1061. {
  1062. xmlNodePtr trav;
  1063. sdlContentModelPtr newModel;
  1064. newModel = emalloc(sizeof(sdlContentModel));
  1065. newModel->kind = XSD_CONTENT_CHOICE;
  1066. newModel->u.content = emalloc(sizeof(HashTable));
  1067. zend_hash_init(newModel->u.content, 0, NULL, delete_model, 0);
  1068. if (model == NULL) {
  1069. cur_type->model = newModel;
  1070. } else {
  1071. zend_hash_next_index_insert(model->u.content,&newModel,sizeof(sdlContentModelPtr), NULL);
  1072. }
  1073. schema_min_max(choiceType, newModel);
  1074. trav = choiceType->children;
  1075. if (trav != NULL && node_is_equal(trav,"annotation")) {
  1076. /* TODO: <annotation> support */
  1077. trav = trav->next;
  1078. }
  1079. while (trav != NULL) {
  1080. if (node_is_equal(trav,"element")) {
  1081. schema_element(sdl, tns, trav, cur_type, newModel);
  1082. } else if (node_is_equal(trav,"group")) {
  1083. schema_group(sdl, tns, trav, cur_type, newModel);
  1084. } else if (node_is_equal(trav,"choice")) {
  1085. schema_choice(sdl, tns, trav, cur_type, newModel);
  1086. } else if (node_is_equal(trav,"sequence")) {
  1087. schema_sequence(sdl, tns, trav, cur_type, newModel);
  1088. } else if (node_is_equal(trav,"any")) {
  1089. schema_any(sdl, tns, trav, cur_type, newModel);
  1090. } else {
  1091. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in choice", trav->name);
  1092. }
  1093. trav = trav->next;
  1094. }
  1095. return TRUE;
  1096. }
  1097. /*
  1098. <sequence
  1099. id = ID
  1100. maxOccurs = (nonNegativeInteger | unbounded) : 1
  1101. minOccurs = nonNegativeInteger : 1
  1102. {any attributes with non-schema namespace . . .}>
  1103. Content: (annotation?, (element | group | choice | sequence | any)*)
  1104. </sequence>
  1105. */
  1106. static int schema_sequence(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr seqType, sdlTypePtr cur_type, sdlContentModelPtr model)
  1107. {
  1108. xmlNodePtr trav;
  1109. sdlContentModelPtr newModel;
  1110. newModel = emalloc(sizeof(sdlContentModel));
  1111. newModel->kind = XSD_CONTENT_SEQUENCE;
  1112. newModel->u.content = emalloc(sizeof(HashTable));
  1113. zend_hash_init(newModel->u.content, 0, NULL, delete_model, 0);
  1114. if (model == NULL) {
  1115. cur_type->model = newModel;
  1116. } else {
  1117. zend_hash_next_index_insert(model->u.content,&newModel,sizeof(sdlContentModelPtr), NULL);
  1118. }
  1119. schema_min_max(seqType, newModel);
  1120. trav = seqType->children;
  1121. if (trav != NULL && node_is_equal(trav,"annotation")) {
  1122. /* TODO: <annotation> support */
  1123. trav = trav->next;
  1124. }
  1125. while (trav != NULL) {
  1126. if (node_is_equal(trav,"element")) {
  1127. schema_element(sdl, tns, trav, cur_type, newModel);
  1128. } else if (node_is_equal(trav,"group")) {
  1129. schema_group(sdl, tns, trav, cur_type, newModel);
  1130. } else if (node_is_equal(trav,"choice")) {
  1131. schema_choice(sdl, tns, trav, cur_type, newModel);
  1132. } else if (node_is_equal(trav,"sequence")) {
  1133. schema_sequence(sdl, tns, trav, cur_type, newModel);
  1134. } else if (node_is_equal(trav,"any")) {
  1135. schema_any(sdl, tns, trav, cur_type, newModel);
  1136. } else {
  1137. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in sequence", trav->name);
  1138. }
  1139. trav = trav->next;
  1140. }
  1141. return TRUE;
  1142. }
  1143. /*
  1144. <any
  1145. id = ID
  1146. maxOccurs = (nonNegativeInteger | unbounded) : 1
  1147. minOccurs = nonNegativeInteger : 1
  1148. namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) : ##any
  1149. processContents = (lax | skip | strict) : strict
  1150. {any attributes with non-schema namespace . . .}>
  1151. Content: (annotation?)
  1152. </any>
  1153. */
  1154. static int schema_any(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr anyType, sdlTypePtr cur_type, sdlContentModelPtr model)
  1155. {
  1156. if (model != NULL) {
  1157. sdlContentModelPtr newModel;
  1158. newModel = emalloc(sizeof(sdlContentModel));
  1159. newModel->kind = XSD_CONTENT_ANY;
  1160. schema_min_max(anyType, newModel);
  1161. zend_hash_next_index_insert(model->u.content, &newModel, sizeof(sdlContentModelPtr), NULL);
  1162. }
  1163. return TRUE;
  1164. }
  1165. /*
  1166. <complexContent
  1167. id = ID
  1168. mixed = boolean
  1169. {any attributes with non-schema namespace . . .}>
  1170. Content: (annotation?, (restriction | extension))
  1171. </complexContent>
  1172. */
  1173. static int schema_complexContent(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr compCont, sdlTypePtr cur_type)
  1174. {
  1175. xmlNodePtr trav;
  1176. trav = compCont->children;
  1177. if (trav != NULL && node_is_equal(trav,"annotation")) {
  1178. /* TODO: <annotation> support */
  1179. trav = trav->next;
  1180. }
  1181. if (trav != NULL) {
  1182. if (node_is_equal(trav, "restriction")) {
  1183. cur_type->kind = XSD_TYPEKIND_RESTRICTION;
  1184. schema_restriction_complexContent(sdl, tns, trav, cur_type);
  1185. trav = trav->next;
  1186. } else if (node_is_equal(trav, "extension")) {
  1187. cur_type->kind = XSD_TYPEKIND_EXTENSION;
  1188. schema_extension_complexContent(sdl, tns, trav, cur_type);
  1189. trav = trav->next;
  1190. } else {
  1191. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in complexContent", trav->name);
  1192. }
  1193. } else {
  1194. soap_error0(E_ERROR, "Parsing Schema: <restriction> or <extension> expected in complexContent");
  1195. }
  1196. if (trav != NULL) {
  1197. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in complexContent", trav->name);
  1198. }
  1199. return TRUE;
  1200. }
  1201. /*
  1202. <complexType
  1203. abstract = boolean : false
  1204. block = (#all | List of (extension | restriction))
  1205. final = (#all | List of (extension | restriction))
  1206. id = ID
  1207. mixed = boolean : false
  1208. name = NCName
  1209. {any attributes with non-schema namespace . . .}>
  1210. Content: (annotation?, (simpleContent | complexContent | ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?))))
  1211. </complexType>
  1212. */
  1213. static int schema_complexType(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr compType, sdlTypePtr cur_type)
  1214. {
  1215. xmlNodePtr trav;
  1216. xmlAttrPtr attrs, name, ns;
  1217. attrs = compType->properties;
  1218. ns = get_attribute(attrs, "targetNamespace");
  1219. if (ns == NULL) {
  1220. ns = tns;
  1221. }
  1222. name = get_attribute(attrs, "name");
  1223. if (cur_type != NULL) {
  1224. /* Anonymous type inside <element> */
  1225. sdlTypePtr newType, *ptr;
  1226. newType = emalloc(sizeof(sdlType));
  1227. memset(newType, 0, sizeof(sdlType));
  1228. newType->kind = XSD_TYPEKIND_COMPLEX;
  1229. if (name != NULL) {
  1230. newType->name = estrdup((char*)name->children->content);
  1231. newType->namens = estrdup((char*)ns->children->content);
  1232. } else {
  1233. newType->name = estrdup(cur_type->name);
  1234. newType->namens = estrdup(cur_type->namens);
  1235. }
  1236. zend_hash_next_index_insert(sdl->types, &newType, sizeof(sdlTypePtr), (void **)&ptr);
  1237. if (sdl->encoders == NULL) {
  1238. sdl->encoders = emalloc(sizeof(HashTable));
  1239. zend_hash_init(sdl->encoders, 0, NULL, delete_encoder, 0);
  1240. }
  1241. cur_type->encode = emalloc(sizeof(encode));
  1242. memset(cur_type->encode, 0, sizeof(encode));
  1243. cur_type->encode->details.ns = estrdup(newType->namens);
  1244. cur_type->encode->details.type_str = estrdup(newType->name);
  1245. cur_type->encode->details.sdl_type = *ptr;
  1246. cur_type->encode->to_xml = sdl_guess_convert_xml;
  1247. cur_type->encode->to_zval = sdl_guess_convert_zval;
  1248. zend_hash_next_index_insert(sdl->encoders, &cur_type->encode, sizeof(encodePtr), NULL);
  1249. cur_type =*ptr;
  1250. } else if (name) {
  1251. sdlTypePtr newType, *ptr;
  1252. newType = emalloc(sizeof(sdlType));
  1253. memset(newType, 0, sizeof(sdlType));
  1254. newType->kind = XSD_TYPEKIND_COMPLEX;
  1255. newType->name = estrdup((char*)name->children->content);
  1256. newType->namens = estrdup((char*)ns->children->content);
  1257. zend_hash_next_index_insert(sdl->types, &newType, sizeof(sdlTypePtr), (void **)&ptr);
  1258. cur_type = (*ptr);
  1259. create_encoder(sdl, cur_type, ns->children->content, name->children->content);
  1260. } else {
  1261. soap_error0(E_ERROR, "Parsing Schema: complexType has no 'name' attribute");
  1262. return FALSE;
  1263. }
  1264. trav = compType->children;
  1265. if (trav != NULL && node_is_equal(trav, "annotation")) {
  1266. /* TODO: <annotation> support */
  1267. trav = trav->next;
  1268. }
  1269. if (trav != NULL) {
  1270. if (node_is_equal(trav,"simpleContent")) {
  1271. schema_simpleContent(sdl, tns, trav, cur_type);
  1272. trav = trav->next;
  1273. } else if (node_is_equal(trav,"complexContent")) {
  1274. schema_complexContent(sdl, tns, trav, cur_type);
  1275. trav = trav->next;
  1276. } else {
  1277. if (node_is_equal(trav,"group")) {
  1278. schema_group(sdl, tns, trav, cur_type, NULL);
  1279. trav = trav->next;
  1280. } else if (node_is_equal(trav,"all")) {
  1281. schema_all(sdl, tns, trav, cur_type, NULL);
  1282. trav = trav->next;
  1283. } else if (node_is_equal(trav,"choice")) {
  1284. schema_choice(sdl, tns, trav, cur_type, NULL);
  1285. trav = trav->next;
  1286. } else if (node_is_equal(trav,"sequence")) {
  1287. schema_sequence(sdl, tns, trav, cur_type, NULL);
  1288. trav = trav->next;
  1289. }
  1290. while (trav != NULL) {
  1291. if (node_is_equal(trav,"attribute")) {
  1292. schema_attribute(sdl, tns, trav, cur_type, NULL);
  1293. } else if (node_is_equal(trav,"attributeGroup")) {
  1294. schema_attributeGroup(sdl, tns, trav, cur_type, NULL);
  1295. } else if (node_is_equal(trav,"anyAttribute")) {
  1296. /* TODO: <anyAttribute> support */
  1297. trav = trav->next;
  1298. break;
  1299. } else {
  1300. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in complexType", trav->name);
  1301. }
  1302. trav = trav->next;
  1303. }
  1304. }
  1305. }
  1306. if (trav != NULL) {
  1307. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in complexType", trav->name);
  1308. }
  1309. return TRUE;
  1310. }
  1311. /*
  1312. <element
  1313. abstract = boolean : false
  1314. block = (#all | List of (extension | restriction | substitution))
  1315. default = string
  1316. final = (#all | List of (extension | restriction))
  1317. fixed = string
  1318. form = (qualified | unqualified)
  1319. id = ID
  1320. maxOccurs = (nonNegativeInteger | unbounded) : 1
  1321. minOccurs = nonNegativeInteger : 1
  1322. name = NCName
  1323. nillable = boolean : false
  1324. ref = QName
  1325. substitutionGroup = QName
  1326. type = QName
  1327. {any attributes with non-schema namespace . . .}>
  1328. Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
  1329. </element>
  1330. */
  1331. static int schema_element(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr element, sdlTypePtr cur_type, sdlContentModelPtr model)
  1332. {
  1333. xmlNodePtr trav;
  1334. xmlAttrPtr attrs, attr, ns, name, type, ref = NULL;
  1335. attrs = element->properties;
  1336. ns = get_attribute(attrs, "targetNamespace");
  1337. if (ns == NULL) {
  1338. ns = tns;
  1339. }
  1340. name = get_attribute(attrs, "name");
  1341. if (name == NULL) {
  1342. name = ref = get_attribute(attrs, "ref");
  1343. }
  1344. if (name) {
  1345. HashTable *addHash;
  1346. sdlTypePtr newType;
  1347. smart_str key = {0};
  1348. newType = emalloc(sizeof(sdlType));
  1349. memset(newType, 0, sizeof(sdlType));
  1350. if (ref) {
  1351. smart_str nscat = {0};
  1352. char *type, *ns;
  1353. xmlNsPtr nsptr;
  1354. parse_namespace(ref->children->content, &type, &ns);
  1355. nsptr = xmlSearchNs(element->doc, element, BAD_CAST(ns));
  1356. if (nsptr != NULL) {
  1357. smart_str_appends(&nscat, (char*)nsptr->href);
  1358. newType->namens = estrdup((char*)nsptr->href);
  1359. } else {
  1360. xmlAttrPtr ns = get_attribute(attrs, "targetNamespace");
  1361. if (ns == NULL) {
  1362. ns = tns;
  1363. }
  1364. if (ns) {
  1365. smart_str_appends(&nscat, (char*)ns->children->content);
  1366. }
  1367. }
  1368. smart_str_appendc(&nscat, ':');
  1369. smart_str_appends(&nscat, type);
  1370. newType->name = estrdup(type);
  1371. smart_str_0(&nscat);
  1372. if (type) {efree(type);}
  1373. if (ns) {efree(ns);}
  1374. newType->ref = estrdup(nscat.c);
  1375. smart_str_free(&nscat);
  1376. } else {
  1377. newType->name = estrdup((char*)name->children->content);
  1378. newType->namens = estrdup((char*)ns->children->content);
  1379. }
  1380. newType->nillable = FALSE;
  1381. if (cur_type == NULL) {
  1382. if (sdl->elements == NULL) {
  1383. sdl->elements = emalloc(sizeof(HashTable));
  1384. zend_hash_init(sdl->elements, 0, NULL, delete_type, 0);
  1385. }
  1386. addHash = sdl->elements;
  1387. smart_str_appends(&key, newType->namens);
  1388. smart_str_appendc(&key, ':');
  1389. smart_str_appends(&key, newType->name);
  1390. } else {
  1391. if (cur_type->elements == NULL) {
  1392. cur_type->elements = emalloc(sizeof(HashTable));
  1393. zend_hash_init(cur_type->elements, 0, NULL, delete_type, 0);
  1394. }
  1395. addHash = cur_type->elements;
  1396. smart_str_appends(&key, newType->name);
  1397. }
  1398. smart_str_0(&key);
  1399. if (zend_hash_add(addHash, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
  1400. if (cur_type == NULL) {
  1401. soap_error1(E_ERROR, "Parsing Schema: element '%s' already defined", key.c);
  1402. } else {
  1403. zend_hash_next_index_insert(addHash, &newType, sizeof(sdlTypePtr), NULL);
  1404. }
  1405. }
  1406. smart_str_free(&key);
  1407. if (model != NULL) {
  1408. sdlContentModelPtr newModel = emalloc(sizeof(sdlContentModel));
  1409. newModel->kind = XSD_CONTENT_ELEMENT;
  1410. newModel->u.element = newType;
  1411. schema_min_max(element, newModel);
  1412. zend_hash_next_index_insert(model->u.content, &newModel, sizeof(sdlContentModelPtr), NULL);
  1413. }
  1414. cur_type = newType;
  1415. } else {
  1416. soap_error0(E_ERROR, "Parsing Schema: element has no 'name' nor 'ref' attributes");
  1417. }
  1418. /* nillable = boolean : false */
  1419. attrs = element->properties;
  1420. attr = get_attribute(attrs, "nillable");
  1421. if (attr) {
  1422. if (ref != NULL) {
  1423. soap_error0(E_ERROR, "Parsing Schema: element has both 'ref' and 'nillable' attributes");
  1424. }
  1425. if (!stricmp((char*)attr->children->content, "true") ||
  1426. !stricmp((char*)attr->children->content, "1")) {
  1427. cur_type->nillable = TRUE;
  1428. } else {
  1429. cur_type->nillable = FALSE;
  1430. }
  1431. } else {
  1432. cur_type->nillable = FALSE;
  1433. }
  1434. attr = get_attribute(attrs, "fixed");
  1435. if (attr) {
  1436. if (ref != NULL) {
  1437. soap_error0(E_ERROR, "Parsing Schema: element has both 'ref' and 'fixed' attributes");
  1438. }
  1439. cur_type->fixed = estrdup((char*)attr->children->content);
  1440. }
  1441. attr = get_attribute(attrs, "default");
  1442. if (attr) {
  1443. if (ref != NULL) {
  1444. soap_error0(E_ERROR, "Parsing Schema: element has both 'ref' and 'fixed' attributes");
  1445. } else if (ref != NULL) {
  1446. soap_error0(E_ERROR, "Parsing Schema: element has both 'default' and 'fixed' attributes");
  1447. }
  1448. cur_type->def = estrdup((char*)attr->children->content);
  1449. }
  1450. /* form */
  1451. attr = get_attribute(attrs, "form");
  1452. if (attr) {
  1453. if (strncmp((char*)attr->children->content, "qualified", sizeof("qualified")) == 0) {
  1454. cur_type->form = XSD_FORM_QUALIFIED;
  1455. } else if (strncmp((char*)attr->children->content, "unqualified", sizeof("unqualified")) == 0) {
  1456. cur_type->form = XSD_FORM_UNQUALIFIED;
  1457. } else {
  1458. cur_type->form = XSD_FORM_DEFAULT;
  1459. }
  1460. } else {
  1461. cur_type->form = XSD_FORM_DEFAULT;
  1462. }
  1463. if (cur_type->form == XSD_FORM_DEFAULT) {
  1464. xmlNodePtr parent = element->parent;
  1465. while (parent) {
  1466. if (node_is_equal_ex(parent, "schema", SCHEMA_NAMESPACE)) {
  1467. xmlAttrPtr def;
  1468. def = get_attribute(parent->properties, "elementFormDefault");
  1469. if(def == NULL || strncmp((char*)def->children->content, "qualified", sizeof("qualified"))) {
  1470. cur_type->form = XSD_FORM_UNQUALIFIED;
  1471. } else {
  1472. cur_type->form = XSD_FORM_QUALIFIED;
  1473. }
  1474. break;
  1475. }
  1476. parent = parent->parent;
  1477. }
  1478. if (parent == NULL) {
  1479. cur_type->form = XSD_FORM_UNQUALIFIED;
  1480. }
  1481. }
  1482. /* type = QName */
  1483. type = get_attribute(attrs, "type");
  1484. if (type) {
  1485. char *cptype, *str_ns;
  1486. xmlNsPtr nsptr;
  1487. if (ref != NULL) {
  1488. soap_error0(E_ERROR, "Parsing Schema: element has both 'ref' and 'type' attributes");
  1489. }
  1490. parse_namespace(type->children->content, &cptype, &str_ns);
  1491. nsptr = xmlSearchNs(element->doc, element, BAD_CAST(str_ns));
  1492. if (nsptr != NULL) {
  1493. cur_type->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(cptype));
  1494. }
  1495. if (str_ns) {efree(str_ns);}
  1496. if (cptype) {efree(cptype);}
  1497. }
  1498. trav = element->children;
  1499. if (trav != NULL && node_is_equal(trav, "annotation")) {
  1500. /* TODO: <annotation> support */
  1501. trav = trav->next;
  1502. }
  1503. if (trav != NULL) {
  1504. if (node_is_equal(trav,"simpleType")) {
  1505. if (ref != NULL) {
  1506. soap_error0(E_ERROR, "Parsing Schema: element has both 'ref' attribute and subtype");
  1507. } else if (type != NULL) {
  1508. soap_error0(E_ERROR, "Parsing Schema: element has both 'type' attribute and subtype");
  1509. }
  1510. schema_simpleType(sdl, tns, trav, cur_type);
  1511. trav = trav->next;
  1512. } else if (node_is_equal(trav,"complexType")) {
  1513. if (ref != NULL) {
  1514. soap_error0(E_ERROR, "Parsing Schema: element has both 'ref' attribute and subtype");
  1515. } else if (type != NULL) {
  1516. soap_error0(E_ERROR, "Parsing Schema: element has both 'type' attribute and subtype");
  1517. }
  1518. schema_complexType(sdl, tns, trav, cur_type);
  1519. trav = trav->next;
  1520. }
  1521. }
  1522. while (trav != NULL) {
  1523. if (node_is_equal(trav,"unique")) {
  1524. /* TODO: <unique> support */
  1525. } else if (node_is_equal(trav,"key")) {
  1526. /* TODO: <key> support */
  1527. } else if (node_is_equal(trav,"keyref")) {
  1528. /* TODO: <keyref> support */
  1529. } else {
  1530. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in element", trav->name);
  1531. }
  1532. trav = trav->next;
  1533. }
  1534. return TRUE;
  1535. }
  1536. /*
  1537. <attribute
  1538. default = string
  1539. fixed = string
  1540. form = (qualified | unqualified)
  1541. id = ID
  1542. name = NCName
  1543. ref = QName
  1544. type = QName
  1545. use = (optional | prohibited | required) : optional
  1546. {any attributes with non-schema namespace . . .}>
  1547. Content: (annotation?, (simpleType?))
  1548. </attribute>
  1549. */
  1550. static int schema_attribute(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrType, sdlTypePtr cur_type, sdlCtx *ctx)
  1551. {
  1552. sdlAttributePtr newAttr;
  1553. xmlAttrPtr attr, name, ref = NULL, type = NULL;
  1554. xmlNodePtr trav;
  1555. name = get_attribute(attrType->properties, "name");
  1556. if (name == NULL) {
  1557. name = ref = get_attribute(attrType->properties, "ref");
  1558. }
  1559. if (name) {
  1560. HashTable *addHash;
  1561. smart_str key = {0};
  1562. newAttr = emalloc(sizeof(sdlAttribute));
  1563. memset(newAttr, 0, sizeof(sdlAttribute));
  1564. if (ref) {
  1565. char *attr_name, *ns;
  1566. xmlNsPtr nsptr;
  1567. parse_namespace(ref->children->content, &attr_name, &ns);
  1568. nsptr = xmlSearchNs(attrType->doc, attrType, BAD_CAST(ns));
  1569. if (nsptr != NULL) {
  1570. smart_str_appends(&key, (char*)nsptr->href);
  1571. newAttr->namens = estrdup((char*)nsptr->href);
  1572. } else {
  1573. xmlAttrPtr ns = get_attribute(attrType->properties, "targetNamespace");
  1574. if (ns == NULL) {
  1575. ns = tns;
  1576. }
  1577. if (ns) {
  1578. smart_str_appends(&key, (char*)ns->children->content);
  1579. }
  1580. }
  1581. smart_str_appendc(&key, ':');
  1582. smart_str_appends(&key, attr_name);
  1583. smart_str_0(&key);
  1584. newAttr->ref = estrdup(key.c);
  1585. if (attr_name) {efree(attr_name);}
  1586. if (ns) {efree(ns);}
  1587. } else {
  1588. xmlAttrPtr ns;
  1589. ns = get_attribute(attrType->properties, "targetNamespace");
  1590. if (ns == NULL) {
  1591. ns = tns;
  1592. }
  1593. if (ns != NULL) {
  1594. smart_str_appends(&key, (char*)ns->children->content);
  1595. smart_str_appendc(&key, ':');
  1596. newAttr->namens = estrdup((char*)ns->children->content);
  1597. }
  1598. smart_str_appends(&key, (char*)name->children->content);
  1599. smart_str_0(&key);
  1600. }
  1601. if (cur_type == NULL) {
  1602. addHash = ctx->attributes;
  1603. } else {
  1604. if (cur_type->attributes == NULL) {
  1605. cur_type->attributes = emalloc(sizeof(HashTable));
  1606. zend_hash_init(cur_type->attributes, 0, NULL, delete_attribute, 0);
  1607. }
  1608. addHash = cur_type->attributes;
  1609. }
  1610. if (zend_hash_add(addHash, key.c, key.len + 1, &newAttr, sizeof(sdlAttributePtr), NULL) != SUCCESS) {
  1611. soap_error1(E_ERROR, "Parsing Schema: attribute '%s' already defined", key.c);
  1612. }
  1613. smart_str_free(&key);
  1614. } else{
  1615. soap_error0(E_ERROR, "Parsing Schema: attribute has no 'name' nor 'ref' attributes");
  1616. }
  1617. /* type = QName */
  1618. type = get_attribute(attrType->properties, "type");
  1619. if (type) {
  1620. char *cptype, *str_ns;
  1621. xmlNsPtr nsptr;
  1622. if (ref != NULL) {
  1623. soap_error0(E_ERROR, "Parsing Schema: attribute has both 'ref' and 'type' attributes");
  1624. }
  1625. parse_namespace(type->children->content, &cptype, &str_ns);
  1626. nsptr = xmlSearchNs(attrType->doc, attrType, BAD_CAST(str_ns));
  1627. if (nsptr != NULL) {
  1628. newAttr->encode = get_create_encoder(sdl, cur_type, nsptr->href, BAD_CAST(cptype));
  1629. }
  1630. if (str_ns) {efree(str_ns);}
  1631. if (cptype) {efree(cptype);}
  1632. }
  1633. attr = attrType->properties;
  1634. while (attr != NULL) {
  1635. if (attr_is_equal_ex(attr, "default", SCHEMA_NAMESPACE)) {
  1636. newAttr->def = estrdup((char*)attr->children->content);
  1637. } else if (attr_is_equal_ex(attr, "fixed", SCHEMA_NAMESPACE)) {
  1638. newAttr->fixed = estrdup((char*)attr->children->content);
  1639. } else if (attr_is_equal_ex(attr, "form", SCHEMA_NAMESPACE)) {
  1640. if (strncmp((char*)attr->children->content, "qualified", sizeof("qualified")) == 0) {
  1641. newAttr->form = XSD_FORM_QUALIFIED;
  1642. } else if (strncmp((char*)attr->children->content, "unqualified", sizeof("unqualified")) == 0) {
  1643. newAttr->form = XSD_FORM_UNQUALIFIED;
  1644. } else {
  1645. newAttr->form = XSD_FORM_DEFAULT;
  1646. }
  1647. } else if (attr_is_equal_ex(attr, "id", SCHEMA_NAMESPACE)) {
  1648. /* skip */
  1649. } else if (attr_is_equal_ex(attr, "name", SCHEMA_NAMESPACE)) {
  1650. newAttr->name = estrdup((char*)attr->children->content);
  1651. } else if (attr_is_equal_ex(attr, "ref", SCHEMA_NAMESPACE)) {
  1652. /* already processed */
  1653. } else if (attr_is_equal_ex(attr, "type", SCHEMA_NAMESPACE)) {
  1654. /* already processed */
  1655. } else if (attr_is_equal_ex(attr, "use", SCHEMA_NAMESPACE)) {
  1656. if (strncmp((char*)attr->children->content, "prohibited", sizeof("prohibited")) == 0) {
  1657. newAttr->use = XSD_USE_PROHIBITED;
  1658. } else if (strncmp((char*)attr->children->content, "required", sizeof("required")) == 0) {
  1659. newAttr->use = XSD_USE_REQUIRED;
  1660. } else if (strncmp((char*)attr->children->content, "optional", sizeof("optional")) == 0) {
  1661. newAttr->use = XSD_USE_OPTIONAL;
  1662. } else {
  1663. newAttr->use = XSD_USE_DEFAULT;
  1664. }
  1665. } else {
  1666. xmlNsPtr nsPtr = attr_find_ns(attr);
  1667. if (strncmp((char*)nsPtr->href, SCHEMA_NAMESPACE, sizeof(SCHEMA_NAMESPACE))) {
  1668. smart_str key2 = {0};
  1669. sdlExtraAttributePtr ext;
  1670. xmlNsPtr nsptr;
  1671. char *value, *ns;
  1672. ext = emalloc(sizeof(sdlExtraAttribute));
  1673. memset(ext, 0, sizeof(sdlExtraAttribute));
  1674. parse_namespace(attr->children->content, &value, &ns);
  1675. nsptr = xmlSearchNs(attr->doc, attr->parent, BAD_CAST(ns));
  1676. if (nsptr) {
  1677. ext->ns = estrdup((char*)nsptr->href);
  1678. ext->val = estrdup(value);
  1679. } else {
  1680. ext->val = estrdup((char*)attr->children->content);
  1681. }
  1682. if (ns) {efree(ns);}
  1683. efree(value);
  1684. if (!newAttr->extraAttributes) {
  1685. newAttr->extraAttributes = emalloc(sizeof(HashTable));
  1686. zend_hash_init(newAttr->extraAttributes, 0, NULL, delete_extra_attribute, 0);
  1687. }
  1688. smart_str_appends(&key2, (char*)nsPtr->href);
  1689. smart_str_appendc(&key2, ':');
  1690. smart_str_appends(&key2, (char*)attr->name);
  1691. smart_str_0(&key2);
  1692. zend_hash_add(newAttr->extraAttributes, key2.c, key2.len + 1, &ext, sizeof(sdlExtraAttributePtr), NULL);
  1693. smart_str_free(&key2);
  1694. }
  1695. }
  1696. attr = attr->next;
  1697. }
  1698. if (newAttr->form == XSD_FORM_DEFAULT) {
  1699. xmlNodePtr parent = attrType->parent;
  1700. while (parent) {
  1701. if (node_is_equal_ex(parent, "schema", SCHEMA_NAMESPACE)) {
  1702. xmlAttrPtr def;
  1703. def = get_attribute(parent->properties, "attributeFormDefault");
  1704. if(def == NULL || strncmp((char*)def->children->content, "qualified", sizeof("qualified"))) {
  1705. newAttr->form = XSD_FORM_UNQUALIFIED;
  1706. } else {
  1707. newAttr->form = XSD_FORM_QUALIFIED;
  1708. }
  1709. break;
  1710. }
  1711. parent = parent->parent;
  1712. }
  1713. if (parent == NULL) {
  1714. newAttr->form = XSD_FORM_UNQUALIFIED;
  1715. }
  1716. }
  1717. trav = attrType->children;
  1718. if (trav != NULL && node_is_equal(trav, "annotation")) {
  1719. /* TODO: <annotation> support */
  1720. trav = trav->next;
  1721. }
  1722. if (trav != NULL) {
  1723. if (node_is_equal(trav,"simpleType")) {
  1724. sdlTypePtr dummy_type;
  1725. if (ref != NULL) {
  1726. soap_error0(E_ERROR, "Parsing Schema: attribute has both 'ref' attribute and subtype");
  1727. } else if (type != NULL) {
  1728. soap_error0(E_ERROR, "Parsing Schema: attribute has both 'type' attribute and subtype");
  1729. }
  1730. dummy_type = emalloc(sizeof(sdlType));
  1731. memset(dummy_type, 0, sizeof(sdlType));
  1732. {
  1733. smart_str anonymous = {0};
  1734. smart_str_appendl(&anonymous, "anonymous", sizeof("anonymous")-1);
  1735. smart_str_append_long(&anonymous, zend_hash_num_elements(sdl->types));
  1736. smart_str_0(&anonymous);
  1737. dummy_type->name = anonymous.c;
  1738. }
  1739. dummy_type->namens = estrdup((char*)tns->children->content);
  1740. schema_simpleType(sdl, tns, trav, dummy_type);
  1741. newAttr->encode = dummy_type->encode;
  1742. delete_type(&dummy_type);
  1743. trav = trav->next;
  1744. }
  1745. }
  1746. if (trav != NULL) {
  1747. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in attribute", trav->name);
  1748. }
  1749. return TRUE;
  1750. }
  1751. static int schema_attributeGroup(sdlPtr sdl, xmlAttrPtr tns, xmlNodePtr attrGroup, sdlTypePtr cur_type, sdlCtx *ctx)
  1752. {
  1753. xmlNodePtr trav;
  1754. xmlAttrPtr name, ref = NULL;
  1755. name = get_attribute(attrGroup->properties, "name");
  1756. if (name == NULL) {
  1757. name = ref = get_attribute(attrGroup->properties, "ref");
  1758. }
  1759. if (name) {
  1760. if (cur_type == NULL) {
  1761. xmlAttrPtr ns;
  1762. sdlTypePtr newType;
  1763. smart_str key = {0};
  1764. ns = get_attribute(attrGroup->properties, "targetNamespace");
  1765. if (ns == NULL) {
  1766. ns = tns;
  1767. }
  1768. newType = emalloc(sizeof(sdlType));
  1769. memset(newType, 0, sizeof(sdlType));
  1770. newType->name = estrdup((char*)name->children->content);
  1771. newType->namens = estrdup((char*)ns->children->content);
  1772. smart_str_appends(&key, newType->namens);
  1773. smart_str_appendc(&key, ':');
  1774. smart_str_appends(&key, newType->name);
  1775. smart_str_0(&key);
  1776. if (zend_hash_add(ctx->attributeGroups, key.c, key.len + 1, &newType, sizeof(sdlTypePtr), NULL) != SUCCESS) {
  1777. soap_error1(E_ERROR, "Parsing Schema: attributeGroup '%s' already defined", key.c);
  1778. }
  1779. cur_type = newType;
  1780. smart_str_free(&key);
  1781. } else if (ref) {
  1782. sdlAttributePtr newAttr;
  1783. char *group_name, *ns;
  1784. smart_str key = {0};
  1785. xmlNsPtr nsptr;
  1786. if (cur_type->attributes == NULL) {
  1787. cur_type->attributes = emalloc(sizeof(HashTable));
  1788. zend_hash_init(cur_type->attributes, 0, NULL, delete_attribute, 0);
  1789. }
  1790. newAttr = emalloc(sizeof(sdlAttribute));
  1791. memset(newAttr, 0, sizeof(sdlAttribute));
  1792. parse_namespace(ref->children->content, &group_name, &ns);
  1793. nsptr = xmlSearchNs(attrGroup->doc, attrGroup, BAD_CAST(ns));
  1794. if (nsptr != NULL) {
  1795. smart_str_appends(&key, (char*)nsptr->href);
  1796. }
  1797. smart_str_appendc(&key, ':');
  1798. smart_str_appends(&key, group_name);
  1799. smart_str_0(&key);
  1800. newAttr->ref = estrdup(key.c);
  1801. if (group_name) {efree(group_name);}
  1802. if (ns) {efree(ns);}
  1803. smart_str_free(&key);
  1804. zend_hash_next_index_insert(cur_type->attributes, &newAttr, sizeof(sdlAttributePtr), NULL);
  1805. cur_type = NULL;
  1806. }
  1807. } else{
  1808. soap_error0(E_ERROR, "Parsing Schema: attributeGroup has no 'name' nor 'ref' attributes");
  1809. }
  1810. trav = attrGroup->children;
  1811. if (trav != NULL && node_is_equal(trav, "annotation")) {
  1812. /* TODO: <annotation> support */
  1813. trav = trav->next;
  1814. }
  1815. while (trav != NULL) {
  1816. if (node_is_equal(trav,"attribute")) {
  1817. if (ref != NULL) {
  1818. soap_error0(E_ERROR, "Parsing Schema: attributeGroup has both 'ref' attribute and subattribute");
  1819. }
  1820. schema_attribute(sdl, tns, trav, cur_type, NULL);
  1821. } else if (node_is_equal(trav,"attributeGroup")) {
  1822. if (ref != NULL) {
  1823. soap_error0(E_ERROR, "Parsing Schema: attributeGroup has both 'ref' attribute and subattribute");
  1824. }
  1825. schema_attributeGroup(sdl, tns, trav, cur_type, NULL);
  1826. } else if (node_is_equal(trav,"anyAttribute")) {
  1827. if (ref != NULL) {
  1828. soap_error0(E_ERROR, "Parsing Schema: attributeGroup has both 'ref' attribute and subattribute");
  1829. }
  1830. /* TODO: <anyAttribute> support */
  1831. trav = trav->next;
  1832. break;
  1833. } else {
  1834. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in attributeGroup", trav->name);
  1835. }
  1836. trav = trav->next;
  1837. }
  1838. if (trav != NULL) {
  1839. soap_error1(E_ERROR, "Parsing Schema: unexpected <%s> in attributeGroup", trav->name);
  1840. }
  1841. return TRUE;
  1842. }
  1843. static void copy_extra_attribute(void *attribute)
  1844. {
  1845. sdlExtraAttributePtr *attr = (sdlExtraAttributePtr*)attribute;
  1846. sdlExtraAttributePtr new_attr;
  1847. new_attr = emalloc(sizeof(sdlExtraAttribute));
  1848. memcpy(new_attr, *attr, sizeof(sdlExtraAttribute));
  1849. *attr = new_attr;
  1850. if (new_attr->ns) {
  1851. new_attr->ns = estrdup(new_attr->ns);
  1852. }
  1853. if (new_attr->val) {
  1854. new_attr->val = estrdup(new_attr->val);
  1855. }
  1856. }
  1857. static void* schema_find_by_ref(HashTable *ht, char *ref)
  1858. {
  1859. void **tmp;
  1860. if (zend_hash_find(ht, ref, strlen(ref)+1, (void**)&tmp) == SUCCESS) {
  1861. return tmp;
  1862. } else {
  1863. ref = strrchr(ref, ':');
  1864. if (ref) {
  1865. if (zend_hash_find(ht, ref, strlen(ref)+1, (void**)&tmp) == SUCCESS) {
  1866. return tmp;
  1867. }
  1868. }
  1869. }
  1870. return NULL;
  1871. }
  1872. static void schema_attribute_fixup(sdlCtx *ctx, sdlAttributePtr attr)
  1873. {
  1874. sdlAttributePtr *tmp;
  1875. if (attr->ref != NULL) {
  1876. if (ctx->attributes != NULL) {
  1877. tmp = (sdlAttributePtr*)schema_find_by_ref(ctx->attributes, attr->ref);
  1878. if (tmp) {
  1879. schema_attribute_fixup(ctx, *tmp);
  1880. if ((*tmp)->name != NULL && attr->name == NULL) {
  1881. attr->name = estrdup((*tmp)->name);
  1882. }
  1883. if ((*tmp)->namens != NULL && attr->namens == NULL) {
  1884. attr->namens = estrdup((*tmp)->namens);
  1885. }
  1886. if ((*tmp)->def != NULL && attr->def == NULL) {
  1887. attr->def = estrdup((*tmp)->def);
  1888. }
  1889. if ((*tmp)->fixed != NULL && attr->fixed == NULL) {
  1890. attr->fixed = estrdup((*tmp)->fixed);
  1891. }
  1892. if (attr->form == XSD_FORM_DEFAULT) {
  1893. attr->form = (*tmp)->form;
  1894. }
  1895. if (attr->use == XSD_USE_DEFAULT) {
  1896. attr->use = (*tmp)->use;
  1897. }
  1898. if ((*tmp)->extraAttributes != NULL) {
  1899. xmlNodePtr node;
  1900. attr->extraAttributes = emalloc(sizeof(HashTable));
  1901. zend_hash_init(attr->extraAttributes, zend_hash_num_elements((*tmp)->extraAttributes), NULL, delete_extra_attribute, 0);
  1902. zend_hash_copy(attr->extraAttributes, (*tmp)->extraAttributes, copy_extra_attribute, &node, sizeof(xmlNodePtr));
  1903. }
  1904. attr->encode = (*tmp)->encode;
  1905. }
  1906. }
  1907. if (attr->name == NULL && attr->ref != NULL) {
  1908. char *name = strrchr(attr->ref, ':');
  1909. if (name) {
  1910. attr->name = estrdup(name+1);
  1911. } else{
  1912. attr->name = estrdup(attr->ref);
  1913. }
  1914. }
  1915. efree(attr->ref);
  1916. attr->ref = NULL;
  1917. }
  1918. }
  1919. static void schema_attributegroup_fixup(sdlCtx *ctx, sdlAttributePtr attr, HashTable *ht)
  1920. {
  1921. sdlTypePtr *tmp;
  1922. sdlAttributePtr *tmp_attr;
  1923. if (attr->ref != NULL) {
  1924. if (ctx->attributeGroups != NULL) {
  1925. tmp = (sdlTypePtr*)schema_find_by_ref(ctx->attributeGroups, attr->ref);
  1926. if (tmp) {
  1927. if ((*tmp)->attributes) {
  1928. zend_hash_internal_pointer_reset((*tmp)->attributes);
  1929. while (zend_hash_get_current_data((*tmp)->attributes,(void**)&tmp_attr) == SUCCESS) {
  1930. if (zend_hash_get_current_key_type((*tmp)->attributes) == HASH_KEY_IS_STRING) {
  1931. char* key;
  1932. uint key_len;
  1933. sdlAttributePtr newAttr;
  1934. schema_attribute_fixup(ctx,*tmp_attr);
  1935. newAttr = emalloc(sizeof(sdlAttribute));
  1936. memcpy(newAttr, *tmp_attr, sizeof(sdlAttribute));
  1937. if (newAttr->def) {newAttr->def = estrdup(newAttr->def);}
  1938. if (newAttr->fixed) {newAttr->fixed = estrdup(newAttr->fixed);}
  1939. if (newAttr->namens) {newAttr->namens = estrdup(newAttr->namens);}
  1940. if (newAttr->name) {newAttr->name = estrdup(newAttr->name);}
  1941. if (newAttr->extraAttributes) {
  1942. xmlNodePtr node;
  1943. HashTable *ht = emalloc(sizeof(HashTable));
  1944. zend_hash_init(ht, zend_hash_num_elements(newAttr->extraAttributes), NULL, delete_extra_attribute, 0);
  1945. zend_hash_copy(ht, newAttr->extraAttributes, copy_extra_attribute, &node, sizeof(xmlNodePtr));
  1946. newAttr->extraAttributes = ht;
  1947. }
  1948. zend_hash_get_current_key_ex((*tmp)->attributes, &key, &key_len, NULL, 0, NULL);
  1949. zend_hash_add(ht, key, key_len, &newAttr, sizeof(sdlAttributePtr), NULL);
  1950. zend_hash_move_forward((*tmp)->attributes);
  1951. } else {
  1952. ulong index;
  1953. schema_attributegroup_fixup(ctx,*tmp_attr, ht);
  1954. zend_hash_get_current_key((*tmp)->attributes, NULL, &index, 0);
  1955. zend_hash_index_del((*tmp)->attributes, index);
  1956. }
  1957. }
  1958. }
  1959. }
  1960. }
  1961. efree(attr->ref);
  1962. attr->ref = NULL;
  1963. }
  1964. }
  1965. static void schema_content_model_fixup(sdlCtx *ctx, sdlContentModelPtr model)
  1966. {
  1967. switch (model->kind) {
  1968. case XSD_CONTENT_GROUP_REF: {
  1969. sdlTypePtr *tmp;
  1970. if (ctx->sdl->groups && zend_hash_find(ctx->sdl->groups, model->u.group_ref, strlen(model->u.group_ref)+1, (void**)&tmp) == SUCCESS) {
  1971. schema_type_fixup(ctx,*tmp);
  1972. efree(model->u.group_ref);
  1973. model->kind = XSD_CONTENT_GROUP;
  1974. model->u.group = (*tmp);
  1975. } else {
  1976. soap_error1(E_ERROR, "Parsing Schema: unresolved group 'ref' attribute '%s'", model->u.group_ref);
  1977. }
  1978. break;
  1979. }
  1980. case XSD_CONTENT_CHOICE: {
  1981. if (model->max_occurs != 1) {
  1982. HashPosition pos;
  1983. sdlContentModelPtr *tmp;
  1984. zend_hash_internal_pointer_reset_ex(model->u.content, &pos);
  1985. while (zend_hash_get_current_data_ex(model->u.content, (void**)&tmp, &pos) == SUCCESS) {
  1986. (*tmp)->min_occurs = 0;
  1987. (*tmp)->max_occurs = model->max_occurs;
  1988. zend_hash_move_forward_ex(model->u.content, &pos);
  1989. }
  1990. model->kind = XSD_CONTENT_ALL;
  1991. model->min_occurs = 1;
  1992. model->max_occurs = 1;
  1993. }
  1994. }
  1995. case XSD_CONTENT_SEQUENCE:
  1996. case XSD_CONTENT_ALL: {
  1997. sdlContentModelPtr *tmp;
  1998. zend_hash_internal_pointer_reset(model->u.content);
  1999. while (zend_hash_get_current_data(model->u.content, (void**)&tmp) == SUCCESS) {
  2000. schema_content_model_fixup(ctx, *tmp);
  2001. zend_hash_move_forward(model->u.content);
  2002. }
  2003. break;
  2004. }
  2005. default:
  2006. break;
  2007. }
  2008. }
  2009. static void schema_type_fixup(sdlCtx *ctx, sdlTypePtr type)
  2010. {
  2011. sdlTypePtr *tmp;
  2012. sdlAttributePtr *attr;
  2013. if (type->ref != NULL) {
  2014. if (ctx->sdl->elements != NULL) {
  2015. tmp = (sdlTypePtr*)schema_find_by_ref(ctx->sdl->elements, type->ref);
  2016. if (tmp) {
  2017. type->kind = (*tmp)->kind;
  2018. type->encode = (*tmp)->encode;
  2019. if ((*tmp)->nillable) {
  2020. type->nillable = 1;
  2021. }
  2022. if ((*tmp)->fixed) {
  2023. type->fixed = estrdup((*tmp)->fixed);
  2024. }
  2025. if ((*tmp)->def) {
  2026. type->def = estrdup((*tmp)->def);
  2027. }
  2028. type->form = (*tmp)->form;
  2029. } else if (strcmp(type->ref, SCHEMA_NAMESPACE ":schema") == 0) {
  2030. type->encode = get_conversion(XSD_ANYXML);
  2031. } else {
  2032. soap_error1(E_ERROR, "Parsing Schema: unresolved element 'ref' attribute '%s'", type->ref);
  2033. }
  2034. }
  2035. efree(type->ref);
  2036. type->ref = NULL;
  2037. }
  2038. if (type->elements) {
  2039. zend_hash_internal_pointer_reset(type->elements);
  2040. while (zend_hash_get_current_data(type->elements,(void**)&tmp) == SUCCESS) {
  2041. schema_type_fixup(ctx,*tmp);
  2042. zend_hash_move_forward(type->elements);
  2043. }
  2044. }
  2045. if (type->model) {
  2046. schema_content_model_fixup(ctx, type->model);
  2047. }
  2048. if (type->attributes) {
  2049. zend_hash_internal_pointer_reset(type->attributes);
  2050. while (zend_hash_get_current_data(type->attributes,(void**)&attr) == SUCCESS) {
  2051. if (zend_hash_get_current_key_type(type->attributes) == HASH_KEY_IS_STRING) {
  2052. schema_attribute_fixup(ctx,*attr);
  2053. zend_hash_move_forward(type->attributes);
  2054. } else {
  2055. ulong index;
  2056. schema_attributegroup_fixup(ctx,*attr,type->attributes);
  2057. zend_hash_get_current_key(type->attributes, NULL, &index, 0);
  2058. zend_hash_index_del(type->attributes, index);
  2059. }
  2060. }
  2061. }
  2062. }
  2063. void schema_pass2(sdlCtx *ctx)
  2064. {
  2065. sdlPtr sdl = ctx->sdl;
  2066. sdlAttributePtr *attr;
  2067. sdlTypePtr *type;
  2068. if (ctx->attributes) {
  2069. zend_hash_internal_pointer_reset(ctx->attributes);
  2070. while (zend_hash_get_current_data(ctx->attributes,(void**)&attr) == SUCCESS) {
  2071. schema_attribute_fixup(ctx,*attr);
  2072. zend_hash_move_forward(ctx->attributes);
  2073. }
  2074. }
  2075. if (ctx->attributeGroups) {
  2076. zend_hash_internal_pointer_reset(ctx->attributeGroups);
  2077. while (zend_hash_get_current_data(ctx->attributeGroups,(void**)&type) == SUCCESS) {
  2078. schema_type_fixup(ctx,*type);
  2079. zend_hash_move_forward(ctx->attributeGroups);
  2080. }
  2081. }
  2082. if (sdl->elements) {
  2083. zend_hash_internal_pointer_reset(sdl->elements);
  2084. while (zend_hash_get_current_data(sdl->elements,(void**)&type) == SUCCESS) {
  2085. schema_type_fixup(ctx,*type);
  2086. zend_hash_move_forward(sdl->elements);
  2087. }
  2088. }
  2089. if (sdl->groups) {
  2090. zend_hash_internal_pointer_reset(sdl->groups);
  2091. while (zend_hash_get_current_data(sdl->groups,(void**)&type) == SUCCESS) {
  2092. schema_type_fixup(ctx,*type);
  2093. zend_hash_move_forward(sdl->groups);
  2094. }
  2095. }
  2096. if (sdl->types) {
  2097. zend_hash_internal_pointer_reset(sdl->types);
  2098. while (zend_hash_get_current_data(sdl->types,(void**)&type) == SUCCESS) {
  2099. schema_type_fixup(ctx,*type);
  2100. zend_hash_move_forward(sdl->types);
  2101. }
  2102. }
  2103. if (ctx->attributes) {
  2104. zend_hash_destroy(ctx->attributes);
  2105. efree(ctx->attributes);
  2106. }
  2107. if (ctx->attributeGroups) {
  2108. zend_hash_destroy(ctx->attributeGroups);
  2109. efree(ctx->attributeGroups);
  2110. }
  2111. }
  2112. void delete_model(void *handle)
  2113. {
  2114. sdlContentModelPtr tmp = *((sdlContentModelPtr*)handle);
  2115. switch (tmp->kind) {
  2116. case XSD_CONTENT_ELEMENT:
  2117. case XSD_CONTENT_GROUP:
  2118. break;
  2119. case XSD_CONTENT_SEQUENCE:
  2120. case XSD_CONTENT_ALL:
  2121. case XSD_CONTENT_CHOICE:
  2122. zend_hash_destroy(tmp->u.content);
  2123. efree(tmp->u.content);
  2124. break;
  2125. case XSD_CONTENT_GROUP_REF:
  2126. efree(tmp->u.group_ref);
  2127. break;
  2128. default:
  2129. break;
  2130. }
  2131. efree(tmp);
  2132. }
  2133. void delete_model_persistent(void *handle)
  2134. {
  2135. sdlContentModelPtr tmp = *((sdlContentModelPtr*)handle);
  2136. switch (tmp->kind) {
  2137. case XSD_CONTENT_ELEMENT:
  2138. case XSD_CONTENT_GROUP:
  2139. break;
  2140. case XSD_CONTENT_SEQUENCE:
  2141. case XSD_CONTENT_ALL:
  2142. case XSD_CONTENT_CHOICE:
  2143. zend_hash_destroy(tmp->u.content);
  2144. free(tmp->u.content);
  2145. break;
  2146. case XSD_CONTENT_GROUP_REF:
  2147. free(tmp->u.group_ref);
  2148. break;
  2149. default:
  2150. break;
  2151. }
  2152. free(tmp);
  2153. }
  2154. void delete_type(void *data)
  2155. {
  2156. sdlTypePtr type = *((sdlTypePtr*)data);
  2157. if (type->name) {
  2158. efree(type->name);
  2159. }
  2160. if (type->namens) {
  2161. efree(type->namens);
  2162. }
  2163. if (type->def) {
  2164. efree(type->def);
  2165. }
  2166. if (type->fixed) {
  2167. efree(type->fixed);
  2168. }
  2169. if (type->elements) {
  2170. zend_hash_destroy(type->elements);
  2171. efree(type->elements);
  2172. }
  2173. if (type->attributes) {
  2174. zend_hash_destroy(type->attributes);
  2175. efree(type->attributes);
  2176. }
  2177. if (type->model) {
  2178. delete_model((void**)&type->model);
  2179. }
  2180. if (type->restrictions) {
  2181. delete_restriction_var_int(&type->restrictions->minExclusive);
  2182. delete_restriction_var_int(&type->restrictions->minInclusive);
  2183. delete_restriction_var_int(&type->restrictions->maxExclusive);
  2184. delete_restriction_var_int(&type->restrictions->maxInclusive);
  2185. delete_restriction_var_int(&type->restrictions->totalDigits);
  2186. delete_restriction_var_int(&type->restrictions->fractionDigits);
  2187. delete_restriction_var_int(&type->restrictions->length);
  2188. delete_restriction_var_int(&type->restrictions->minLength);
  2189. delete_restriction_var_int(&type->restrictions->maxLength);
  2190. delete_restriction_var_char(&type->restrictions->whiteSpace);
  2191. delete_restriction_var_char(&type->restrictions->pattern);
  2192. if (type->restrictions->enumeration) {
  2193. zend_hash_destroy(type->restrictions->enumeration);
  2194. efree(type->restrictions->enumeration);
  2195. }
  2196. efree(type->restrictions);
  2197. }
  2198. efree(type);
  2199. }
  2200. void delete_type_persistent(void *data)
  2201. {
  2202. sdlTypePtr type = *((sdlTypePtr*)data);
  2203. if (type->name) {
  2204. free(type->name);
  2205. }
  2206. if (type->namens) {
  2207. free(type->namens);
  2208. }
  2209. if (type->def) {
  2210. free(type->def);
  2211. }
  2212. if (type->fixed) {
  2213. free(type->fixed);
  2214. }
  2215. if (type->elements) {
  2216. zend_hash_destroy(type->elements);
  2217. free(type->elements);
  2218. }
  2219. if (type->attributes) {
  2220. zend_hash_destroy(type->attributes);
  2221. free(type->attributes);
  2222. }
  2223. if (type->model) {
  2224. delete_model_persistent((void**)&type->model);
  2225. }
  2226. if (type->restrictions) {
  2227. delete_restriction_var_int_persistent(&type->restrictions->minExclusive);
  2228. delete_restriction_var_int_persistent(&type->restrictions->minInclusive);
  2229. delete_restriction_var_int_persistent(&type->restrictions->maxExclusive);
  2230. delete_restriction_var_int_persistent(&type->restrictions->maxInclusive);
  2231. delete_restriction_var_int_persistent(&type->restrictions->totalDigits);
  2232. delete_restriction_var_int_persistent(&type->restrictions->fractionDigits);
  2233. delete_restriction_var_int_persistent(&type->restrictions->length);
  2234. delete_restriction_var_int_persistent(&type->restrictions->minLength);
  2235. delete_restriction_var_int_persistent(&type->restrictions->maxLength);
  2236. delete_restriction_var_char_persistent(&type->restrictions->whiteSpace);
  2237. delete_restriction_var_char_persistent(&type->restrictions->pattern);
  2238. if (type->restrictions->enumeration) {
  2239. zend_hash_destroy(type->restrictions->enumeration);
  2240. free(type->restrictions->enumeration);
  2241. }
  2242. free(type->restrictions);
  2243. }
  2244. free(type);
  2245. }
  2246. void delete_extra_attribute(void *attribute)
  2247. {
  2248. sdlExtraAttributePtr attr = *((sdlExtraAttributePtr*)attribute);
  2249. if (attr->ns) {
  2250. efree(attr->ns);
  2251. }
  2252. if (attr->val) {
  2253. efree(attr->val);
  2254. }
  2255. efree(attr);
  2256. }
  2257. void delete_extra_attribute_persistent(void *attribute)
  2258. {
  2259. sdlExtraAttributePtr attr = *((sdlExtraAttributePtr*)attribute);
  2260. if (attr->ns) {
  2261. free(attr->ns);
  2262. }
  2263. if (attr->val) {
  2264. free(attr->val);
  2265. }
  2266. free(attr);
  2267. }
  2268. void delete_attribute(void *attribute)
  2269. {
  2270. sdlAttributePtr attr = *((sdlAttributePtr*)attribute);
  2271. if (attr->def) {
  2272. efree(attr->def);
  2273. }
  2274. if (attr->fixed) {
  2275. efree(attr->fixed);
  2276. }
  2277. if (attr->name) {
  2278. efree(attr->name);
  2279. }
  2280. if (attr->namens) {
  2281. efree(attr->namens);
  2282. }
  2283. if (attr->ref) {
  2284. efree(attr->ref);
  2285. }
  2286. if (attr->extraAttributes) {
  2287. zend_hash_destroy(attr->extraAttributes);
  2288. efree(attr->extraAttributes);
  2289. }
  2290. efree(attr);
  2291. }
  2292. void delete_attribute_persistent(void *attribute)
  2293. {
  2294. sdlAttributePtr attr = *((sdlAttributePtr*)attribute);
  2295. if (attr->def) {
  2296. free(attr->def);
  2297. }
  2298. if (attr->fixed) {
  2299. free(attr->fixed);
  2300. }
  2301. if (attr->name) {
  2302. free(attr->name);
  2303. }
  2304. if (attr->namens) {
  2305. free(attr->namens);
  2306. }
  2307. if (attr->ref) {
  2308. free(attr->ref);
  2309. }
  2310. if (attr->extraAttributes) {
  2311. zend_hash_destroy(attr->extraAttributes);
  2312. free(attr->extraAttributes);
  2313. }
  2314. free(attr);
  2315. }
  2316. void delete_restriction_var_int(void *rvi)
  2317. {
  2318. sdlRestrictionIntPtr ptr = *((sdlRestrictionIntPtr*)rvi);
  2319. if (ptr) {
  2320. efree(ptr);
  2321. }
  2322. }
  2323. void delete_restriction_var_int_persistent(void *rvi)
  2324. {
  2325. sdlRestrictionIntPtr ptr = *((sdlRestrictionIntPtr*)rvi);
  2326. if (ptr) {
  2327. free(ptr);
  2328. }
  2329. }
  2330. void delete_restriction_var_char(void *srvc)
  2331. {
  2332. sdlRestrictionCharPtr ptr = *((sdlRestrictionCharPtr*)srvc);
  2333. if (ptr) {
  2334. if (ptr->value) {
  2335. efree(ptr->value);
  2336. }
  2337. efree(ptr);
  2338. }
  2339. }
  2340. void delete_restriction_var_char_persistent(void *srvc)
  2341. {
  2342. sdlRestrictionCharPtr ptr = *((sdlRestrictionCharPtr*)srvc);
  2343. if (ptr) {
  2344. if (ptr->value) {
  2345. free(ptr->value);
  2346. }
  2347. free(ptr);
  2348. }
  2349. }