ReactOS 0.4.16-dev-2208-g6350669
imports.c File Reference
#include "libxslt.h"
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/hash.h>
#include <libxml/xmlerror.h>
#include <libxml/uri.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "xsltutils.h"
#include "preproc.h"
#include "imports.h"
#include "documents.h"
#include "security.h"
#include "pattern.h"
Include dependency graph for imports.c:

Go to the source code of this file.

Macros

#define IN_LIBXSLT
 
#define XSLT_MAX_NESTING   40
 

Functions

static void xsltFixImportedCompSteps (xsltStylesheetPtr master, xsltStylesheetPtr style)
 
static int xsltCheckCycle (xsltStylesheetPtr style, xmlNodePtr cur, const xmlChar *URI)
 
int xsltParseStylesheetImport (xsltStylesheetPtr style, xmlNodePtr cur)
 
int xsltParseStylesheetInclude (xsltStylesheetPtr style, xmlNodePtr cur)
 
xsltStylesheetPtr xsltNextImport (xsltStylesheetPtr cur)
 
int xsltNeedElemSpaceHandling (xsltTransformContextPtr ctxt)
 
int xsltFindElemSpaceHandling (xsltTransformContextPtr ctxt, xmlNodePtr node)
 
: the template name

xsltFindTemplate: @ctxt: an XSLT transformation context

@nameURI: the template name URI

Finds the named template, apply import precedence rule. REVISIT TODO: We'll change the nameURI fields of templates to be in the string dict, so if the specified @nameURI is in the same dict, then use pointer comparison. Check if this can be done in a sane way. Maybe this function is not needed internally at transformation-time if we hard-wire the called templates to the caller.

Returns the xsltTemplatePtr or NULL if not found

xsltTemplatePtr xsltFindTemplate (xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI)
 

Macro Definition Documentation

◆ IN_LIBXSLT

#define IN_LIBXSLT

Definition at line 12 of file imports.c.

◆ XSLT_MAX_NESTING

#define XSLT_MAX_NESTING   40

Definition at line 56 of file imports.c.

Function Documentation

◆ xsltCheckCycle()

static int xsltCheckCycle ( xsltStylesheetPtr  style,
xmlNodePtr  cur,
const xmlChar URI 
)
static

Definition at line 59 of file imports.c.

59 {
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}
Arabic default style
Definition: afstyles.h:94
#define NULL
Definition: types.h:112
FxCollectionEntry * cur
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
#define XSLT_MAX_NESTING
Definition: imports.c:56
xmlDocPtr doc
struct _xsltDocument * includes
xsltDocumentPtr includes
struct _xsltStylesheet * parent
XMLPUBFUN int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:162
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:762

Referenced by xsltParseStylesheetImport(), and xsltParseStylesheetInclude().

◆ xsltFindElemSpaceHandling()

int xsltFindElemSpaceHandling ( xsltTransformContextPtr  ctxt,
xmlNodePtr  node 
)

xsltFindElemSpaceHandling: @ctxt: an XSLT transformation context @node: an XML node

Find strip-space or preserve-space information for an element respect the import precedence or the wildcards

Returns 1 if space should be stripped, 0 if not, and 2 if everything should be CDTATA wrapped.

Definition at line 349 of file imports.c.

349 {
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}
GLuint GLfloat * val
Definition: glext.h:7180
xsltStylesheetPtr xsltNextImport(xsltStylesheetPtr cur)
Definition: imports.c:297
void * xmlHashLookup2(xmlHashTablePtr hash, const xmlChar *key, const xmlChar *key2)
Definition: hash.c:754
xsltStylesheetPtr style
Definition: dlist.c:348
#define BAD_CAST
Definition: xmlstring.h:35
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xsltApplyStripSpaces().

◆ xsltFindTemplate()

xsltTemplatePtr xsltFindTemplate ( xsltTransformContextPtr  ctxt,
const xmlChar name,
const xmlChar nameURI 
)

Definition at line 403 of file imports.c.

404 {
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}
Definition: name.c:39
xsltTemplate * xsltTemplatePtr

Referenced by xsltCallTemplate().

◆ xsltFixImportedCompSteps()

static void xsltFixImportedCompSteps ( xsltStylesheetPtr  master,
xsltStylesheetPtr  style 
)
static

xsltFixImportedCompSteps: @master: the "master" stylesheet @style: the stylesheet being imported by the master

normalize the comp steps for the stylesheet being imported by the master, together with any imports within that.

Definition at line 46 of file imports.c.

47 {
49 xmlHashScan(style->templatesHash, xsltNormalizeCompSteps, master);
50 master->extrasNr += style->extrasNr;
51 for (res = style->imports; res != NULL; res = res->next) {
53 }
54}
void xsltNormalizeCompSteps(void *payload, void *data, const xmlChar *name ATTRIBUTE_UNUSED)
Definition: pattern.c:236
GLuint res
Definition: glext.h:9613
static void xsltFixImportedCompSteps(xsltStylesheetPtr master, xsltStylesheetPtr style)
Definition: imports.c:46
void xmlHashScan(xmlHashTablePtr hash, xmlHashScanner scan, void *data)
Definition: hash.c:898
struct define * next
Definition: compiler.c:65

Referenced by xsltFixImportedCompSteps(), and xsltParseStylesheetImport().

◆ xsltNeedElemSpaceHandling()

int xsltNeedElemSpaceHandling ( xsltTransformContextPtr  ctxt)

xsltNeedElemSpaceHandling: @ctxt: an XSLT transformation context

Checks whether that stylesheet requires white-space stripping

Returns 1 if space should be stripped, 0 if not

Definition at line 322 of file imports.c.

322 {
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}

Referenced by xsltApplyStylesheetInternal(), and xsltLoadDocument().

◆ xsltNextImport()

xsltStylesheetPtr xsltNextImport ( xsltStylesheetPtr  cur)

xsltNextImport: @cur: the current XSLT stylesheet

Find the next stylesheet in import precedence.

Returns the next stylesheet or NULL if it was the last one

Definition at line 297 of file imports.c.

297 {
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}

Referenced by xsltApplySequenceConstructor(), xsltCountKeys(), xsltDecimalFormatGetByName(), xsltDecimalFormatGetByQName(), xsltEvalGlobalVariables(), xsltFindElemSpaceHandling(), xsltFindTemplate(), xsltGetNamespace(), xsltGetTemplate(), xsltInitAllDocKeys(), xsltInitCtxtExts(), xsltInitCtxtKeys(), xsltInitDocKeyTable(), xsltNeedElemSpaceHandling(), xsltProcessUserParamInternal(), xsltResolveAttrSet(), xsltResolveStylesheetAttributeSet(), and xsltResolveUseAttrSets().

◆ xsltParseStylesheetImport()

int xsltParseStylesheetImport ( xsltStylesheetPtr  style,
xmlNodePtr  cur 
)

xsltParseStylesheetImport: @style: the XSLT stylesheet @cur: the import element

parse an XSLT stylesheet import element

Returns 0 in case of success -1 in case of failure.

Definition at line 116 of file imports.c.

116 {
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}
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
@ XSLT_LOAD_STYLESHEET
Definition: documents.h:55
return ret
Definition: mutex.c:146
static int xsltCheckCycle(xsltStylesheetPtr style, xmlNodePtr cur, const xmlChar *URI)
Definition: imports.c:59
#define error(str)
Definition: mkdosfs.c:1605
xmlFreeFunc xmlFree
Definition: globals.c:184
XMLPUBFUN xmlChar * xmlBuildURI(const xmlChar *URI, const xmlChar *base)
Definition: uri.c:1902
xsltStylesheetPtr xsltParseStylesheetImportedDoc(xmlDocPtr doc, xsltStylesheetPtr parentStyle)
Definition: xslt.c:6555
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54

Referenced by xsltParseStylesheetTop().

◆ xsltParseStylesheetInclude()

int xsltParseStylesheetInclude ( xsltStylesheetPtr  style,
xmlNodePtr  cur 
)

xsltParseStylesheetInclude: @style: the XSLT stylesheet @cur: the include node

parse an XSLT stylesheet include element

Returns 0 in case of success -1 in case of failure

Definition at line 205 of file imports.c.

205 {
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}
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:31
xsltDocumentPtr xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI)
Definition: documents.c:358
GLuint64EXT * result
Definition: glext.h:11304
xsltStylesheetPtr xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc)
Definition: xslt.c:6447

Referenced by xsltParseStylesheetTop().