1 --- raptor-1.4.21.orig/src/raptor.h 2010-01-29 15:54:42.000000000 -0800
2 +++ raptor-1.4.21/src/raptor.h 2012-02-04 12:22:29.000000000 -0800
4 * @RAPTOR_FEATURE_RSS_TRIPLES: Atom/RSS serializer writes extra RDF triples it finds (none, rdf-xml, atom-triples)
5 * @RAPTOR_FEATURE_ATOM_ENTRY_URI: Atom entry URI. If given, generate an Atom Entry Document with the item having the given URI, otherwise generate an Atom Feed Document with any items found.
6 * @RAPTOR_FEATURE_PREFIX_ELEMENTS: Integer. If set, generate Atom/RSS1.0 documents with prefixed elements, otherwise unprefixed.
7 + * @RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES: When reading XML, load external entities.
8 * @RAPTOR_FEATURE_LAST: Internal
10 * Raptor parser, serializer or XML writer features.
12 RAPTOR_FEATURE_RSS_TRIPLES,
13 RAPTOR_FEATURE_ATOM_ENTRY_URI,
14 RAPTOR_FEATURE_PREFIX_ELEMENTS,
15 - RAPTOR_FEATURE_LAST = RAPTOR_FEATURE_PREFIX_ELEMENTS
16 + RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES,
17 + RAPTOR_FEATURE_LAST = RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES
21 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_feature.c raptor-1.4.21/src/raptor_feature.c
22 --- raptor-1.4.21.orig/src/raptor_feature.c 2010-01-29 15:54:42.000000000 -0800
23 +++ raptor-1.4.21/src/raptor_feature.c 2012-02-04 12:22:39.000000000 -0800
25 { RAPTOR_FEATURE_JSON_EXTRA_DATA , 6, "jsonExtraData", "JSON serializer extra data" },
26 { RAPTOR_FEATURE_RSS_TRIPLES , 6, "rssTriples", "Atom/RSS serializer writes extra RDF triples" },
27 { RAPTOR_FEATURE_ATOM_ENTRY_URI , 6, "atomEntryUri", "Atom serializer Entry URI" },
28 - { RAPTOR_FEATURE_PREFIX_ELEMENTS , 2, "prefixElements", "Atom/RSS serializers write namespace-prefixed elements" }
29 + { RAPTOR_FEATURE_PREFIX_ELEMENTS , 2, "prefixElements", "Atom/RSS serializers write namespace-prefixed elements" },
30 + { RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES, 1, "loadExternalEntities", "Load external XML entities." }
34 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_internal.h raptor-1.4.21/src/raptor_internal.h
35 --- raptor-1.4.21.orig/src/raptor_internal.h 2010-01-29 15:54:42.000000000 -0800
36 +++ raptor-1.4.21/src/raptor_internal.h 2012-02-04 12:23:45.000000000 -0800
37 @@ -1060,6 +1060,14 @@
39 /* sax2 init failed - do not try to do anything with it */
42 + /* call SAX2 handlers if non-0 */
46 + * non 0 if XML entities should be loaded
48 + int feature_load_external_entities;
51 int raptor_sax2_init(raptor_world* world);
52 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_libxml.c raptor-1.4.21/src/raptor_libxml.c
53 --- raptor-1.4.21.orig/src/raptor_libxml.c 2010-01-29 15:54:42.000000000 -0800
54 +++ raptor-1.4.21/src/raptor_libxml.c 2012-02-04 12:23:38.000000000 -0800
55 @@ -142,18 +142,115 @@
57 static xmlParserInputPtr
58 raptor_libxml_resolveEntity(void* user_data,
59 - const xmlChar *publicId, const xmlChar *systemId) {
60 - raptor_sax2* sax2=(raptor_sax2*)user_data;
61 - return libxml2_resolveEntity(sax2->xc, publicId, systemId);
62 + const xmlChar *publicId, const xmlChar *systemId)
64 + raptor_sax2* sax2 = (raptor_sax2*)user_data;
65 + xmlParserCtxtPtr ctxt = sax2->xc;
66 + const unsigned char *uri_string = NULL;
67 + xmlParserInputPtr entity_input;
68 + int load_entity = 0;
71 + uri_string = (const unsigned char *)ctxt->input->filename;
74 + uri_string = (const unsigned char *)ctxt->directory;
76 + load_entity = sax2->feature_load_external_entities;
79 + entity_input = xmlLoadExternalEntity((const char*)uri_string,
80 + (const char*)publicId,
83 + RAPTOR_DEBUG4("Not loading entity URI %s by policy for publicId '%s' systemId '%s'\n", uri_string, publicId, systemId);
86 + return entity_input;
91 -raptor_libxml_getEntity(void* user_data, const xmlChar *name) {
92 - raptor_sax2* sax2=(raptor_sax2*)user_data;
93 - return libxml2_getEntity(sax2->xc, name);
95 +raptor_libxml_getEntity(void* user_data, const xmlChar *name)
97 + raptor_sax2* sax2 = (raptor_sax2*)user_data;
98 + xmlParserCtxtPtr xc = sax2->xc;
99 + xmlEntityPtr ret = NULL;
104 + if(!xc->inSubset) {
105 + /* looks for hardcoded set of entity names - lt, gt etc. */
106 + ret = xmlGetPredefinedEntity(name);
108 + RAPTOR_DEBUG2("Entity '%s' found in predefined set\n", name);
113 + /* This section uses xmlGetDocEntity which looks for entities in
114 + * memory only, never from a file or URI
116 + if(xc->myDoc && (xc->myDoc->standalone == 1)) {
117 + RAPTOR_DEBUG2("Entity '%s' document is standalone\n", name);
118 + /* Document is standalone: no entities are required to interpret doc */
119 + if(xc->inSubset == 2) {
120 + xc->myDoc->standalone = 0;
121 + ret = xmlGetDocEntity(xc->myDoc, name);
122 + xc->myDoc->standalone = 1;
124 + ret = xmlGetDocEntity(xc->myDoc, name);
126 + xc->myDoc->standalone = 0;
127 + ret = xmlGetDocEntity(xc->myDoc, name);
128 + xc->myDoc->standalone = 1;
132 + ret = xmlGetDocEntity(xc->myDoc, name);
135 + if(ret && !ret->children &&
136 + (ret->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY)) {
137 + /* Entity is an external general parsed entity. It may be in a
138 + * catalog file, user file or user URI
141 + xmlNodePtr children;
142 + int load_entity = 0;
144 + load_entity = sax2->feature_load_external_entities;
147 + RAPTOR_DEBUG2("Not getting entity URI %s by policy\n", ret->URI);
148 + children = xmlNewText((const xmlChar*)"");
150 + /* Disable SAX2 handlers so that the SAX2 events do not all get
151 + * sent to callbacks during dealing with the entity parsing.
154 + val = xmlParseCtxtExternalEntity(xc, ret->URI, ret->ExternalID, &children);
159 + xmlAddChildList((xmlNodePtr)ret, children);
167 + /* Mark this entity as having been checked - never do this again */
177 raptor_libxml_getParameterEntity(void* user_data, const xmlChar *name) {
178 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_parse.c raptor-1.4.21/src/raptor_parse.c
179 --- raptor-1.4.21.orig/src/raptor_parse.c 2010-01-29 15:54:42.000000000 -0800
180 +++ raptor-1.4.21/src/raptor_parse.c 2012-02-04 12:22:46.000000000 -0800
181 @@ -1443,6 +1443,7 @@
182 case RAPTOR_FEATURE_MICROFORMATS:
183 case RAPTOR_FEATURE_HTML_LINK:
184 case RAPTOR_FEATURE_WWW_TIMEOUT:
185 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
186 parser->features[(int)feature]=value;
189 @@ -1564,6 +1565,7 @@
190 case RAPTOR_FEATURE_MICROFORMATS:
191 case RAPTOR_FEATURE_HTML_LINK:
192 case RAPTOR_FEATURE_WWW_TIMEOUT:
193 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
194 result = parser->features[(int)feature];
197 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_rdfxml.c raptor-1.4.21/src/raptor_rdfxml.c
198 --- raptor-1.4.21.orig/src/raptor_rdfxml.c 2010-01-29 15:54:42.000000000 -0800
199 +++ raptor-1.4.21/src/raptor_rdfxml.c 2012-02-04 12:22:50.000000000 -0800
200 @@ -1130,6 +1130,9 @@
201 raptor_sax2_set_feature(rdf_xml_parser->sax2,
202 RAPTOR_FEATURE_NO_NET,
203 rdf_parser->features[RAPTOR_FEATURE_NO_NET]);
204 + raptor_sax2_set_feature(rdf_xml_parser->sax2,
205 + RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES,
206 + rdf_parser->features[RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES]);
208 raptor_sax2_parse_start(rdf_xml_parser->sax2, uri);
210 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_rss.c raptor-1.4.21/src/raptor_rss.c
211 --- raptor-1.4.21.orig/src/raptor_rss.c 2010-01-29 15:54:42.000000000 -0800
212 +++ raptor-1.4.21/src/raptor_rss.c 2012-02-04 12:22:54.000000000 -0800
214 raptor_sax2_set_feature(rss_parser->sax2,
215 RAPTOR_FEATURE_NO_NET,
216 rdf_parser->features[RAPTOR_FEATURE_NO_NET]);
217 + raptor_sax2_set_feature(rss_parser->sax2,
218 + RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES,
219 + rdf_parser->features[RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES]);
221 raptor_sax2_parse_start(rss_parser->sax2, uri);
223 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_sax2.c raptor-1.4.21/src/raptor_sax2.c
224 --- raptor-1.4.21.orig/src/raptor_sax2.c 2010-01-29 15:54:42.000000000 -0800
225 +++ raptor-1.4.21/src/raptor_sax2.c 2012-02-04 15:04:23.000000000 -0800
228 sax2->user_data=user_data;
232 sax2->locator=error_handlers->locator;
234 sax2->error_handlers=error_handlers;
236 sax2->feature_no_net=value;
239 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
240 + sax2->feature_load_external_entities=value;
243 case RAPTOR_FEATURE_SCANNING:
244 case RAPTOR_FEATURE_ASSUME_IS_RDF:
245 case RAPTOR_FEATURE_ALLOW_NON_NS_ATTRIBUTES:
247 unsigned char *xml_language=NULL;
248 raptor_uri *xml_base=NULL;
251 + if(sax2->failed || !sax2->enabled)
254 #ifdef RAPTOR_XML_EXPAT
255 @@ -1031,7 +1037,7 @@
256 raptor_sax2* sax2=(raptor_sax2*)user_data;
257 raptor_xml_element* xml_element;
260 + if(sax2->failed || !sax2->enabled)
263 #ifdef RAPTOR_XML_EXPAT
264 @@ -1069,7 +1075,11 @@
265 raptor_sax2_characters(void* user_data, const unsigned char *s, int len)
267 raptor_sax2* sax2=(raptor_sax2*)user_data;
268 - if(!sax2->failed && sax2->characters_handler)
270 + if(sax2->failed || !sax2->enabled)
273 + if(sax2->characters_handler)
274 sax2->characters_handler(sax2->user_data, sax2->current_element, s, len);
277 @@ -1085,7 +1095,10 @@
281 - if(!sax2->failed && sax2->cdata_handler)
282 + if(sax2->failed || !sax2->enabled)
285 + if(sax2->cdata_handler)
286 sax2->cdata_handler(sax2->user_data, sax2->current_element, s, len);
289 @@ -1095,7 +1108,11 @@
290 raptor_sax2_comment(void* user_data, const unsigned char *s)
292 raptor_sax2* sax2=(raptor_sax2*)user_data;
293 - if(!sax2->failed && sax2->comment_handler)
295 + if(sax2->failed || !sax2->enabled)
298 + if(sax2->comment_handler)
299 sax2->comment_handler(sax2->user_data, sax2->current_element, s);
302 @@ -1110,7 +1127,11 @@
303 const unsigned char* notationName)
305 raptor_sax2* sax2=(raptor_sax2*)user_data;
306 - if(!sax2->failed && sax2->unparsed_entity_decl_handler)
308 + if(sax2->failed || !sax2->enabled)
311 + if(sax2->unparsed_entity_decl_handler)
312 sax2->unparsed_entity_decl_handler(sax2->user_data,
313 entityName, base, systemId,
314 publicId, notationName);
315 @@ -1127,7 +1148,7 @@
317 raptor_sax2* sax2=(raptor_sax2*)user_data;
320 + if(sax2->failed || !sax2->enabled)
323 if(sax2->external_entity_ref_handler)
324 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_serialize.c raptor-1.4.21/src/raptor_serialize.c
325 --- raptor-1.4.21.orig/src/raptor_serialize.c 2010-01-29 15:54:42.000000000 -0800
326 +++ raptor-1.4.21/src/raptor_serialize.c 2012-02-04 12:23:05.000000000 -0800
330 case RAPTOR_FEATURE_NO_NET:
331 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
333 /* XML writer features */
334 case RAPTOR_FEATURE_WRITER_AUTO_INDENT:
335 @@ -1081,6 +1082,7 @@
338 case RAPTOR_FEATURE_NO_NET:
339 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
341 /* XML writer features */
342 case RAPTOR_FEATURE_WRITER_AUTO_INDENT:
343 @@ -1222,6 +1224,7 @@
346 case RAPTOR_FEATURE_NO_NET:
347 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
349 /* XML writer features */
350 case RAPTOR_FEATURE_WRITER_AUTO_INDENT:
351 @@ -1324,6 +1327,7 @@
354 case RAPTOR_FEATURE_NO_NET:
355 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
357 /* XML writer features */
358 case RAPTOR_FEATURE_WRITER_AUTO_INDENT:
359 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_turtle_writer.c raptor-1.4.21/src/raptor_turtle_writer.c
360 --- raptor-1.4.21.orig/src/raptor_turtle_writer.c 2010-01-29 15:54:42.000000000 -0800
361 +++ raptor-1.4.21/src/raptor_turtle_writer.c 2012-02-04 12:23:10.000000000 -0800
365 case RAPTOR_FEATURE_NO_NET:
366 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
368 /* XML writer features */
369 case RAPTOR_FEATURE_RELATIVE_URIS:
373 case RAPTOR_FEATURE_NO_NET:
374 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
376 /* XML writer features */
377 case RAPTOR_FEATURE_RELATIVE_URIS:
378 diff -urN -X /Users/dajobe/dev/dontdiff -x raptor.rdf -x file1.txt -x xmlent1.rdf -x rapper -x rdfdiff raptor-1.4.21.orig/src/raptor_xml_writer.c raptor-1.4.21/src/raptor_xml_writer.c
379 --- raptor-1.4.21.orig/src/raptor_xml_writer.c 2010-01-29 15:54:42.000000000 -0800
380 +++ raptor-1.4.21/src/raptor_xml_writer.c 2012-02-04 12:23:24.000000000 -0800
384 case RAPTOR_FEATURE_NO_NET:
385 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
387 /* XML writer features */
388 case RAPTOR_FEATURE_RELATIVE_URIS:
389 @@ -1094,6 +1095,7 @@
392 case RAPTOR_FEATURE_NO_NET:
393 + case RAPTOR_FEATURE_LOAD_EXTERNAL_ENTITIES:
395 /* XML writer features */
396 case RAPTOR_FEATURE_RELATIVE_URIS: