schemas: Add callbacks for resource loader

This commit is contained in:
Nick Wellnhofer 2024-06-11 14:58:55 +02:00
parent fd7d9e5eca
commit ef8dc4f673
2 changed files with 33 additions and 2 deletions

View File

@ -18,6 +18,7 @@
#include <stdio.h>
#include <libxml/encoding.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlerror.h>
@ -156,10 +157,14 @@ 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);

View File

@ -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