mirror of
				https://gitlab.gnome.org/GNOME/libxml2.git
				synced 2025-10-31 21:50:33 +03:00 
			
		
		
		
	relaxng: Add callbacks for resource loader
This commit is contained in:
		| @@ -14,6 +14,7 @@ | |||||||
| #include <libxml/xmlerror.h> | #include <libxml/xmlerror.h> | ||||||
| #include <libxml/xmlstring.h> | #include <libxml/xmlstring.h> | ||||||
| #include <libxml/tree.h> | #include <libxml/tree.h> | ||||||
|  | #include <libxml/parser.h> | ||||||
|  |  | ||||||
| #ifdef LIBXML_SCHEMAS_ENABLED | #ifdef LIBXML_SCHEMAS_ENABLED | ||||||
|  |  | ||||||
| @@ -155,6 +156,10 @@ XMLPUBFUN void | |||||||
| 					 xmlRelaxNGParserCtxtPtr ctxt, | 					 xmlRelaxNGParserCtxtPtr ctxt, | ||||||
| 					 xmlStructuredErrorFunc serror, | 					 xmlStructuredErrorFunc serror, | ||||||
| 					 void *ctx); | 					 void *ctx); | ||||||
|  | XMLPUBFUN void | ||||||
|  | 		    xmlRelaxNGSetResourceLoader	(xmlRelaxNGParserCtxtPtr ctxt, | ||||||
|  | 						 xmlResourceLoader loader, | ||||||
|  | 						 void *vctxt); | ||||||
| XMLPUBFUN xmlRelaxNGPtr | XMLPUBFUN xmlRelaxNGPtr | ||||||
| 		    xmlRelaxNGParse		(xmlRelaxNGParserCtxtPtr ctxt); | 		    xmlRelaxNGParse		(xmlRelaxNGParserCtxtPtr ctxt); | ||||||
| XMLPUBFUN void | XMLPUBFUN void | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								relaxng.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								relaxng.c
									
									
									
									
									
								
							| @@ -229,6 +229,9 @@ struct _xmlRelaxNGParserCtxt { | |||||||
|  |  | ||||||
|     int crng;			/* compact syntax and other flags */ |     int crng;			/* compact syntax and other flags */ | ||||||
|     int freedoc;		/* need to free the document */ |     int freedoc;		/* need to free the document */ | ||||||
|  |  | ||||||
|  |     xmlResourceLoader resourceLoader; | ||||||
|  |     void *resourceCtxt; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| #define FLAGS_IGNORABLE		1 | #define FLAGS_IGNORABLE		1 | ||||||
| @@ -1423,6 +1426,9 @@ xmlRelaxReadFile(xmlRelaxNGParserCtxtPtr ctxt, const char *filename) { | |||||||
|     } |     } | ||||||
|     if (ctxt->serror != NULL) |     if (ctxt->serror != NULL) | ||||||
|         xmlCtxtSetErrorHandler(pctxt, ctxt->serror, ctxt->userData); |         xmlCtxtSetErrorHandler(pctxt, ctxt->serror, ctxt->userData); | ||||||
|  |     if (ctxt->resourceLoader != NULL) | ||||||
|  |         xmlCtxtSetResourceLoader(pctxt, ctxt->resourceLoader, | ||||||
|  |                                  ctxt->resourceCtxt); | ||||||
|     doc = xmlCtxtReadFile(pctxt, filename, NULL, 0); |     doc = xmlCtxtReadFile(pctxt, filename, NULL, 0); | ||||||
|     xmlFreeParserCtxt(pctxt); |     xmlFreeParserCtxt(pctxt); | ||||||
|  |  | ||||||
| @@ -1441,6 +1447,9 @@ xmlRelaxReadMemory(xmlRelaxNGParserCtxtPtr ctxt, const char *buf, int size) { | |||||||
|     } |     } | ||||||
|     if (ctxt->serror != NULL) |     if (ctxt->serror != NULL) | ||||||
|         xmlCtxtSetErrorHandler(pctxt, ctxt->serror, ctxt->userData); |         xmlCtxtSetErrorHandler(pctxt, ctxt->serror, ctxt->userData); | ||||||
|  |     if (ctxt->resourceLoader != NULL) | ||||||
|  |         xmlCtxtSetResourceLoader(pctxt, ctxt->resourceLoader, | ||||||
|  |                                  ctxt->resourceCtxt); | ||||||
|     doc = xmlCtxtReadMemory(pctxt, buf, size, NULL, NULL, 0); |     doc = xmlCtxtReadMemory(pctxt, buf, size, NULL, NULL, 0); | ||||||
|     xmlFreeParserCtxt(pctxt); |     xmlFreeParserCtxt(pctxt); | ||||||
|  |  | ||||||
| @@ -7566,6 +7575,23 @@ xmlRelaxNGSetParserStructuredErrors(xmlRelaxNGParserCtxtPtr ctxt, | |||||||
|     ctxt->userData = ctx; |     ctxt->userData = ctx; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * xmlRelaxNGSetResourceLoader: | ||||||
|  |  * @ctxt:  a Relax-NG parser context | ||||||
|  |  * @loader:  the callback | ||||||
|  |  * @vctxt:  contextual data for the callbacks | ||||||
|  |  * | ||||||
|  |  * Set the callback function used to load external resources. | ||||||
|  |  */ | ||||||
|  | void | ||||||
|  | xmlRelaxNGSetResourceLoader(xmlRelaxNGParserCtxtPtr ctxt, | ||||||
|  |                             xmlResourceLoader loader, void *vctxt) { | ||||||
|  |     if (ctxt == NULL) | ||||||
|  |         return; | ||||||
|  |     ctxt->resourceLoader = loader; | ||||||
|  |     ctxt->resourceCtxt = vctxt; | ||||||
|  | } | ||||||
|  |  | ||||||
| #ifdef LIBXML_OUTPUT_ENABLED | #ifdef LIBXML_OUTPUT_ENABLED | ||||||
|  |  | ||||||
| /************************************************************************ | /************************************************************************ | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								runsuite.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								runsuite.c
									
									
									
									
									
								
							| @@ -113,25 +113,22 @@ static int addEntity(char *name, char *content) { | |||||||
|     return(0); |     return(0); | ||||||
| } | } | ||||||
|  |  | ||||||
| static xmlParserInputPtr | static int | ||||||
| testExternalEntityLoader(const char *URL, const char *ID ATTRIBUTE_UNUSED, | testResourceLoader(void *vctxt ATTRIBUTE_UNUSED, const char *URL, | ||||||
| 			 xmlParserCtxtPtr ctxt) { |                    const char *ID ATTRIBUTE_UNUSED, int type ATTRIBUTE_UNUSED, | ||||||
|     xmlParserInputPtr ret; |                    int flags ATTRIBUTE_UNUSED, xmlParserInputPtr *out) { | ||||||
|     int i; |     int i; | ||||||
|  |  | ||||||
|     for (i = 0;i < nb_entities;i++) { |     for (i = 0; i < nb_entities; i++) { | ||||||
|         if (!strcmp(testEntitiesName[i], URL)) { |         if (!strcmp(testEntitiesName[i], URL)) { | ||||||
| 	    ret = xmlNewStringInputStream(ctxt, | 	    *out = xmlInputCreateString(testEntitiesName[i], | ||||||
| 	                (const xmlChar *) testEntitiesValue[i]); |                                         testEntitiesValue[i], | ||||||
| 	    if (ret != NULL) { |                                         XML_INPUT_BUF_STATIC); | ||||||
| 	        ret->filename = (const char *) | 	    return(XML_ERR_OK); | ||||||
| 		                xmlStrdup((xmlChar *)testEntitiesName[i]); |  | ||||||
| 	    } |  | ||||||
| 	    return(ret); |  | ||||||
| 	} | 	} | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return(xmlNewInputFromFile(ctxt, URL)); |     return(xmlInputCreateUrl(URL, 0, out)); | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -186,7 +183,6 @@ static void | |||||||
| initializeLibxml2(void) { | initializeLibxml2(void) { | ||||||
|     xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup); |     xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup); | ||||||
|     xmlInitParser(); |     xmlInitParser(); | ||||||
|     xmlSetExternalEntityLoader(testExternalEntityLoader); |  | ||||||
|     ctxtXPath = xmlXPathNewContext(NULL); |     ctxtXPath = xmlXPathNewContext(NULL); | ||||||
|     /* |     /* | ||||||
|     * Deactivate the cache if created; otherwise we have to create/free it |     * Deactivate the cache if created; otherwise we have to create/free it | ||||||
| @@ -308,6 +304,7 @@ xsdIncorrectTestCase(xmlNodePtr cur) { | |||||||
|     pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use); |     pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use); | ||||||
|     xmlRelaxNGSetParserErrors(pctxt, testErrorHandler, testErrorHandler, |     xmlRelaxNGSetParserErrors(pctxt, testErrorHandler, testErrorHandler, | ||||||
|             pctxt); |             pctxt); | ||||||
|  |     xmlRelaxNGSetResourceLoader(pctxt, testResourceLoader, NULL); | ||||||
|     rng = xmlRelaxNGParse(pctxt); |     rng = xmlRelaxNGParse(pctxt); | ||||||
|     xmlRelaxNGFreeParserCtxt(pctxt); |     xmlRelaxNGFreeParserCtxt(pctxt); | ||||||
|     if (rng != NULL) { |     if (rng != NULL) { | ||||||
| @@ -442,6 +439,7 @@ xsdTestCase(xmlNodePtr tst) { | |||||||
|     pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use); |     pctxt = xmlRelaxNGNewMemParserCtxt((const char *)buf->content, buf->use); | ||||||
|     xmlRelaxNGSetParserErrors(pctxt, testErrorHandler, testErrorHandler, |     xmlRelaxNGSetParserErrors(pctxt, testErrorHandler, testErrorHandler, | ||||||
|             pctxt); |             pctxt); | ||||||
|  |     xmlRelaxNGSetResourceLoader(pctxt, testResourceLoader, NULL); | ||||||
|     rng = xmlRelaxNGParse(pctxt); |     rng = xmlRelaxNGParse(pctxt); | ||||||
|     xmlRelaxNGFreeParserCtxt(pctxt); |     xmlRelaxNGFreeParserCtxt(pctxt); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user