ReactOS 0.4.16-dev-2206-gc56950d
imports.c
Go to the documentation of this file.
1/*
2 * imports.c: Implementation of the XSLT imports
3 *
4 * Reference:
5 * http://www.w3.org/TR/1999/REC-xslt-19991116
6 *
7 * See Copyright for the status of this software.
8 *
9 * daniel@veillard.com
10 */
11
12#define IN_LIBXSLT
13#include "libxslt.h"
14
15#include <string.h>
16
17#include <libxml/xmlmemory.h>
18#include <libxml/parser.h>
19#include <libxml/hash.h>
20#include <libxml/xmlerror.h>
21#include <libxml/uri.h>
22#include "xslt.h"
23#include "xsltInternals.h"
24#include "xsltutils.h"
25#include "preproc.h"
26#include "imports.h"
27#include "documents.h"
28#include "security.h"
29#include "pattern.h"
30
31
32/************************************************************************
33 * *
34 * Module interfaces *
35 * *
36 ************************************************************************/
49 xmlHashScan(style->templatesHash, xsltNormalizeCompSteps, master);
50 master->extrasNr += style->extrasNr;
51 for (res = style->imports; res != NULL; res = res->next) {
53 }
54}
55
56#define XSLT_MAX_NESTING 40
57
58static int
60 xsltStylesheetPtr ancestor;
61 xsltDocumentPtr docptr;
62 int depth;
63
64 /*
65 * Check imported stylesheets.
66 */
67 depth = 0;
68 ancestor = style;
69 while (ancestor != NULL) {
70 if (++depth >= XSLT_MAX_NESTING) {
72 "maximum nesting depth exceeded: %s\n", URI);
73 return(-1);
74 }
75 if (xmlStrEqual(ancestor->doc->URL, URI)) {
77 "recursion detected on imported URL %s\n", URI);
78 return(-1);
79 }
80
81 /*
82 * Check included stylesheets.
83 */
84 docptr = ancestor->includes;
85 while (docptr != NULL) {
86 if (++depth >= XSLT_MAX_NESTING) {
88 "maximum nesting depth exceeded: %s\n", URI);
89 return(-1);
90 }
91 if (xmlStrEqual(docptr->doc->URL, URI)) {
93 "recursion detected on included URL %s\n", URI);
94 return(-1);
95 }
96 docptr = docptr->includes;
97 }
98
99 ancestor = ancestor->parent;
100 }
101
102 return(0);
103}
104
115int
117 int ret = -1;
118 xmlDocPtr import = NULL;
119 xmlChar *base = NULL;
120 xmlChar *uriRef = NULL;
121 xmlChar *URI = NULL;
124
125 if ((cur == NULL) || (style == NULL))
126 return (ret);
127
128 uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
129 if (uriRef == NULL) {
131 "xsl:import : missing href attribute\n");
132 goto error;
133 }
134
135 base = xmlNodeGetBase(style->doc, cur);
136 URI = xmlBuildURI(uriRef, base);
137 if (URI == NULL) {
139 "xsl:import : invalid URI reference %s\n", uriRef);
140 goto error;
141 }
142
143 if (xsltCheckCycle(style, cur, URI) < 0)
144 goto error;
145
146 /*
147 * Security framework check
148 */
150 if (sec != NULL) {
151 int secres;
152
153 secres = xsltCheckRead(sec, NULL, URI);
154 if (secres <= 0) {
155 if (secres == 0)
157 "xsl:import: read rights for %s denied\n",
158 URI);
159 goto error;
160 }
161 }
162
163 import = xsltDocDefaultLoader(URI, style->dict, XSLT_PARSE_OPTIONS,
164 (void *) style, XSLT_LOAD_STYLESHEET);
165 if (import == NULL) {
167 "xsl:import : unable to load %s\n", URI);
168 goto error;
169 }
170
172 if (res != NULL) {
173 res->next = style->imports;
174 style->imports = res;
175 if (style->parent == NULL) {
177 }
178 ret = 0;
179 } else {
180 xmlFreeDoc(import);
181 }
182
183error:
184 if (uriRef != NULL)
185 xmlFree(uriRef);
186 if (base != NULL)
187 xmlFree(base);
188 if (URI != NULL)
189 xmlFree(URI);
190
191 return (ret);
192}
193
204int
206 int ret = -1;
207 xmlDocPtr oldDoc;
208 xmlChar *base = NULL;
209 xmlChar *uriRef = NULL;
210 xmlChar *URI = NULL;
213 int oldNopreproc;
214
215 if ((cur == NULL) || (style == NULL))
216 return (ret);
217
218 uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
219 if (uriRef == NULL) {
221 "xsl:include : missing href attribute\n");
222 goto error;
223 }
224
225 base = xmlNodeGetBase(style->doc, cur);
226 URI = xmlBuildURI(uriRef, base);
227 if (URI == NULL) {
229 "xsl:include : invalid URI reference %s\n", uriRef);
230 goto error;
231 }
232
233 if (xsltCheckCycle(style, cur, URI) < 0)
234 goto error;
235
237 if (include == NULL) {
239 "xsl:include : unable to load %s\n", URI);
240 goto error;
241 }
242#ifdef XSLT_REFACTORED
243 if (IS_XSLT_ELEM_FAST(cur) && (cur->psvi != NULL)) {
244 ((xsltStyleItemIncludePtr) cur->psvi)->include = include;
245 } else {
247 "Internal error: (xsltParseStylesheetInclude) "
248 "The xsl:include element was not compiled.\n", URI);
249 style->errors++;
250 }
251#endif
252 oldDoc = style->doc;
253 style->doc = include->doc;
254 /* chain to stylesheet for recursion checking */
255 include->includes = style->includes;
256 style->includes = include;
257 oldNopreproc = style->nopreproc;
258 style->nopreproc = include->preproc;
259 /*
260 * TODO: This will change some values of the
261 * including stylesheet with every included module
262 * (e.g. excluded-result-prefixes)
263 * We need to strictly seperate such stylesheet-owned values.
264 */
266 style->nopreproc = oldNopreproc;
267 include->preproc = 1;
268 style->includes = include->includes;
269 style->doc = oldDoc;
270 if (result == NULL) {
271 ret = -1;
272 goto error;
273 }
274 ret = 0;
275
276error:
277 if (uriRef != NULL)
278 xmlFree(uriRef);
279 if (base != NULL)
280 xmlFree(base);
281 if (URI != NULL)
282 xmlFree(URI);
283
284 return (ret);
285}
286
298 if (cur == NULL)
299 return(NULL);
300 if (cur->imports != NULL)
301 return(cur->imports);
302 if (cur->next != NULL)
303 return(cur->next) ;
304 do {
305 cur = cur->parent;
306 if (cur == NULL) break;
307 if (cur->next != NULL) return(cur->next);
308 } while (cur != NULL);
309 return(cur);
310}
311
321int
324
325 if (ctxt == NULL)
326 return(0);
327 style = ctxt->style;
328 while (style != NULL) {
329 if (style->stripSpaces != NULL)
330 return(1);
332 }
333 return(0);
334}
335
348int
351 const xmlChar *val;
352
353 if ((ctxt == NULL) || (node == NULL))
354 return(0);
355 style = ctxt->style;
356 while (style != NULL) {
357 if (node->ns != NULL) {
358 val = (const xmlChar *)
359 xmlHashLookup2(style->stripSpaces, node->name, node->ns->href);
360 if (val == NULL) {
361 val = (const xmlChar *)
362 xmlHashLookup2(style->stripSpaces, BAD_CAST "*",
363 node->ns->href);
364 }
365 } else {
366 val = (const xmlChar *)
367 xmlHashLookup2(style->stripSpaces, node->name, NULL);
368 }
369 if (val != NULL) {
370 if (xmlStrEqual(val, (xmlChar *) "strip"))
371 return(1);
372 if (xmlStrEqual(val, (xmlChar *) "preserve"))
373 return(0);
374 }
375 if (style->stripAll == 1)
376 return(1);
377 if (style->stripAll == -1)
378 return(0);
379
381 }
382 return(0);
383}
384
404 const xmlChar *nameURI) {
407
408 if ((ctxt == NULL) || (name == NULL))
409 return(NULL);
410 style = ctxt->style;
411 while (style != NULL) {
412 if (style->namedTemplates != NULL) {
414 xmlHashLookup2(style->namedTemplates, name, nameURI);
415 if (cur != NULL)
416 return(cur);
417 }
418
420 }
421 return(NULL);
422}
Arabic default style
Definition: afstyles.h:94
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:31
#define NULL
Definition: types.h:112
void xsltNormalizeCompSteps(void *payload, void *data, const xmlChar *name ATTRIBUTE_UNUSED)
Definition: pattern.c:236
xsltSecurityPrefsPtr xsltGetDefaultSecurityPrefs(void)
Definition: security.c:180
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:419
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:108
xsltDocumentPtr xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI)
Definition: documents.c:358
@ XSLT_LOAD_STYLESHEET
Definition: documents.h:55
return ret
Definition: mutex.c:146
FxCollectionEntry * cur
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLuint res
Definition: glext.h:9613
GLuint GLfloat * val
Definition: glext.h:7180
GLuint64EXT * result
Definition: glext.h:11304
static int xsltCheckCycle(xsltStylesheetPtr style, xmlNodePtr cur, const xmlChar *URI)
Definition: imports.c:59
#define XSLT_MAX_NESTING
Definition: imports.c:56
int xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: imports.c:349
static void xsltFixImportedCompSteps(xsltStylesheetPtr master, xsltStylesheetPtr style)
Definition: imports.c:46
int xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur)
Definition: imports.c:116
int xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur)
Definition: imports.c:205
xsltTemplatePtr xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI)
Definition: imports.c:403
xsltStylesheetPtr xsltNextImport(xsltStylesheetPtr cur)
Definition: imports.c:297
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:322
#define error(str)
Definition: mkdosfs.c:1605
xmlFreeFunc xmlFree
Definition: globals.c:184
void xmlHashScan(xmlHashTablePtr hash, xmlHashScanner scan, void *data)
Definition: hash.c:898
void * xmlHashLookup2(xmlHashTablePtr hash, const xmlChar *key, const xmlChar *key2)
Definition: hash.c:754
xmlDocPtr doc
struct _xsltDocument * includes
xsltDocumentPtr includes
struct _xsltStylesheet * parent
xsltStylesheetPtr style
struct define * next
Definition: compiler.c:65
Definition: name.c:39
Definition: dlist.c:348
XMLPUBFUN xmlChar * xmlBuildURI(const xmlChar *URI, const xmlChar *base)
Definition: uri.c:1902
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:162
unsigned char xmlChar
Definition: xmlstring.h:28
xsltTemplate * xsltTemplatePtr
xsltStylesheetPtr xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc)
Definition: xslt.c:6447
xsltStylesheetPtr xsltParseStylesheetImportedDoc(xmlDocPtr doc, xsltStylesheetPtr parentStyle)
Definition: xslt.c:6555
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:762