static cache_entry* cache_entry_from_xdr_doc(xmlDocPtr doc, xmlChar const* nsURI, MSXML_VERSION version) { cache_entry* entry = heap_alloc(sizeof(cache_entry)); xmlSchemaParserCtxtPtr spctx; xmlDocPtr new_doc = xmlCopyDoc(doc, 1), xsd_doc = XDR_to_XSD_doc(doc, nsURI); link_datatypes(xsd_doc); entry->type = CacheEntryType_XDR; entry->ref = 0; spctx = xmlSchemaNewDocParserCtxt(xsd_doc); if ((entry->schema = Schema_parse(spctx))) { entry->doc = new_doc; xmldoc_init(entry->schema->doc, version); xmldoc_init(entry->doc, version); xmldoc_add_ref(entry->doc); xmldoc_add_ref(entry->schema->doc); } else { FIXME("failed to parse doc\n"); xmlFreeDoc(new_doc); xmlFreeDoc(xsd_doc); heap_free(entry); entry = NULL; } xmlSchemaFreeParserCtxt(spctx); return entry; }
static cache_entry* cache_entry_from_xsd_doc(xmlDocPtr doc, xmlChar const* nsURI, MSXML_VERSION v) { cache_entry* entry = heap_alloc(sizeof(cache_entry)); xmlSchemaParserCtxtPtr spctx; xmlDocPtr new_doc = xmlCopyDoc(doc, 1); link_datatypes(new_doc); /* TODO: if the nsURI is different from the default xmlns or targetNamespace, * do we need to do something special here? */ entry->type = CacheEntryType_XSD; entry->ref = 0; spctx = xmlSchemaNewDocParserCtxt(new_doc); if ((entry->schema = Schema_parse(spctx))) { xmldoc_init(entry->schema->doc, v); entry->doc = entry->schema->doc; xmldoc_add_ref(entry->doc); } else { FIXME("failed to parse doc\n"); xmlFreeDoc(new_doc); heap_free(entry); entry = NULL; } xmlSchemaFreeParserCtxt(spctx); return entry; }
HRESULT dt_validate(XDR_DT dt, xmlChar const* content) { xmlDocPtr tmp_doc; xmlNodePtr node; xmlNsPtr ns; HRESULT hr; TRACE("(dt:%s, %s)\n", debugstr_dt(dt), debugstr_a((char const*)content)); if (!datatypes_schema) { xmlSchemaParserCtxtPtr spctx; assert(datatypes_src != NULL); spctx = xmlSchemaNewMemParserCtxt((char const*)datatypes_src, datatypes_len); datatypes_schema = Schema_parse(spctx); xmlSchemaFreeParserCtxt(spctx); } switch (dt) { case DT_INVALID: return E_FAIL; case DT_BIN_BASE64: case DT_BIN_HEX: case DT_BOOLEAN: case DT_CHAR: case DT_DATE: case DT_DATE_TZ: case DT_DATETIME: case DT_DATETIME_TZ: case DT_FIXED_14_4: case DT_FLOAT: case DT_I1: case DT_I2: case DT_I4: case DT_I8: case DT_INT: case DT_NMTOKEN: case DT_NMTOKENS: case DT_NUMBER: case DT_R4: case DT_R8: case DT_STRING: case DT_TIME: case DT_TIME_TZ: case DT_UI1: case DT_UI2: case DT_UI4: case DT_UI8: case DT_URI: case DT_UUID: if (!datatypes_schema) { ERR("failed to load schema for urn:schemas-microsoft-com:datatypes, " "you're probably using an old version of libxml2: " LIBXML_DOTTED_VERSION "\n"); /* Hopefully they don't need much in the way of XDR datatypes support... */ return S_OK; } if (content && xmlStrlen(content)) { tmp_doc = xmlNewDoc(NULL); node = xmlNewChild((xmlNodePtr)tmp_doc, NULL, dt_to_str(dt), content); ns = xmlNewNs(node, DT_nsURI, BAD_CAST "dt"); xmlSetNs(node, ns); xmlDocSetRootElement(tmp_doc, node); hr = Schema_validate_tree(datatypes_schema, (xmlNodePtr)tmp_doc); xmlFreeDoc(tmp_doc); } else { /* probably the node is being created manually and has no content yet */ hr = S_OK; } return hr; default: FIXME("need to handle dt:%s\n", debugstr_dt(dt)); return S_OK; } }
HRESULT dt_validate(XDR_DT dt, xmlChar const* content) { xmlDocPtr tmp_doc; xmlNodePtr node; xmlNsPtr ns; HRESULT hr; TRACE("(dt:%s, %s)\n", dt_to_str(dt), wine_dbgstr_a((char const*)content)); if (!datatypes_schema) { xmlSchemaParserCtxtPtr spctx; assert(datatypes_src != NULL); spctx = xmlSchemaNewMemParserCtxt((char const*)datatypes_src, datatypes_len); datatypes_schema = Schema_parse(spctx); xmlSchemaFreeParserCtxt(spctx); } switch (dt) { case DT_INVALID: return E_FAIL; case DT_BIN_BASE64: case DT_BIN_HEX: case DT_BOOLEAN: case DT_CHAR: case DT_DATE: case DT_DATE_TZ: case DT_DATETIME: case DT_DATETIME_TZ: case DT_FIXED_14_4: case DT_FLOAT: case DT_I1: case DT_I2: case DT_I4: case DT_I8: case DT_INT: case DT_NMTOKEN: case DT_NMTOKENS: case DT_NUMBER: case DT_R4: case DT_R8: case DT_STRING: case DT_TIME: case DT_TIME_TZ: case DT_UI1: case DT_UI2: case DT_UI4: case DT_UI8: case DT_URI: case DT_UUID: assert(datatypes_schema != NULL); if (content && xmlStrlen(content)) { tmp_doc = xmlNewDoc(NULL); node = xmlNewChild((xmlNodePtr)tmp_doc, NULL, dt_to_str(dt), content); ns = xmlNewNs(node, DT_nsURI, BAD_CAST "dt"); xmlSetNs(node, ns); xmlDocSetRootElement(tmp_doc, node); hr = Schema_validate_tree(datatypes_schema, (xmlNodePtr)tmp_doc); xmlFreeDoc(tmp_doc); } else { /* probably the node is being created manually and has no content yet */ hr = S_OK; } return hr; default: FIXME("need to handle dt:%s\n", dt_to_str(dt)); return S_OK; } }