From ef8dc4f6735bcb5bd050518a7fdd656a2b6feaf9 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Tue, 11 Jun 2024 14:58:55 +0200 Subject: [PATCH] schemas: Add callbacks for resource loader --- include/libxml/xmlschemas.h | 9 +++++++-- xmlschemas.c | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/include/libxml/xmlschemas.h b/include/libxml/xmlschemas.h index c2af3d70..adaff3e3 100644 --- a/include/libxml/xmlschemas.h +++ b/include/libxml/xmlschemas.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -156,12 +157,16 @@ XMLPUBFUN void xmlStructuredErrorFunc serror, void *ctx); XMLPUBFUN int - xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, + xmlSchemaGetParserErrors (xmlSchemaParserCtxtPtr ctxt, xmlSchemaValidityErrorFunc * err, xmlSchemaValidityWarningFunc * warn, void **ctx); +XMLPUBFUN void + xmlSchemaSetResourceLoader (xmlSchemaParserCtxtPtr ctxt, + xmlResourceLoader loader, + void *data); XMLPUBFUN int - xmlSchemaIsValid (xmlSchemaValidCtxtPtr ctxt); + xmlSchemaIsValid (xmlSchemaValidCtxtPtr ctxt); XMLPUBFUN xmlSchemaPtr xmlSchemaParse (xmlSchemaParserCtxtPtr ctxt); diff --git a/xmlschemas.c b/xmlschemas.c index 48b4e328..cae55fac 100644 --- a/xmlschemas.c +++ b/xmlschemas.c @@ -628,6 +628,9 @@ struct _xmlSchemaParserCtxt { xmlSchemaRedefPtr redef; /* Used for redefinitions. */ int redefCounter; /* Used for redefinitions. */ xmlSchemaItemListPtr attrProhibs; + + xmlResourceLoader resourceLoader; + void *resourceCtxt; }; /** @@ -10506,6 +10509,9 @@ doc_load: if (pctxt->serror != NULL) xmlCtxtSetErrorHandler(parserCtxt, pctxt->serror, pctxt->errCtxt); + if (pctxt->resourceLoader != NULL) + xmlCtxtSetResourceLoader(parserCtxt, pctxt->resourceLoader, + pctxt->resourceCtxt); if ((pctxt->dict != NULL) && (parserCtxt->dict != NULL)) { /* @@ -21413,6 +21419,26 @@ xmlSchemaGetParserErrors(xmlSchemaParserCtxtPtr ctxt, return(0); } +/** + * xmlSchemaSetResourceLoader: + * @ctxt: schema parser + * @loader: resource loader + * @data: user data which will be passed to the loader + * + * Register a callback function that will be called to load documents + * or external entities. + * + * Available since 2.14.0. + */ +void +xmlSchemaSetResourceLoader(xmlSchemaParserCtxtPtr ctxt, + xmlResourceLoader loader, void *data) { + if (ctxt == NULL) + return; + ctxt->resourceLoader = loader; + ctxt->resourceCtxt = data; +} + /** * xmlSchemaFacetTypeToString: * @type: the facet type