ReactOS  0.4.14-dev-593-g1793dcc
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 #include "precomp.h"
13 
14 /************************************************************************
15  * *
16  * Module interfaces *
17  * *
18  ************************************************************************/
31  xmlHashScan(style->templatesHash, xsltNormalizeCompSteps, master);
32  master->extrasNr += style->extrasNr;
33  for (res = style->imports; res != NULL; res = res->next) {
35  }
36 }
37 
48 int
50  int ret = -1;
51  xmlDocPtr import = NULL;
52  xmlChar *base = NULL;
53  xmlChar *uriRef = NULL;
54  xmlChar *URI = NULL;
57 
58  if ((cur == NULL) || (style == NULL))
59  return (ret);
60 
61  uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
62  if (uriRef == NULL) {
64  "xsl:import : missing href attribute\n");
65  goto error;
66  }
67 
68  base = xmlNodeGetBase(style->doc, cur);
69  URI = xmlBuildURI(uriRef, base);
70  if (URI == NULL) {
72  "xsl:import : invalid URI reference %s\n", uriRef);
73  goto error;
74  }
75 
76  res = style;
77  while (res != NULL) {
78  if (res->doc == NULL)
79  break;
80  if (xmlStrEqual(res->doc->URL, URI)) {
82  "xsl:import : recursion detected on imported URL %s\n", URI);
83  goto error;
84  }
85  res = res->parent;
86  }
87 
88  /*
89  * Security framework check
90  */
92  if (sec != NULL) {
93  int secres;
94 
95  secres = xsltCheckRead(sec, NULL, URI);
96  if (secres == 0) {
98  "xsl:import: read rights for %s denied\n",
99  URI);
100  goto error;
101  }
102  }
103 
104  import = xsltDocDefaultLoader(URI, style->dict, XSLT_PARSE_OPTIONS,
105  (void *) style, XSLT_LOAD_STYLESHEET);
106  if (import == NULL) {
108  "xsl:import : unable to load %s\n", URI);
109  goto error;
110  }
111 
113  if (res != NULL) {
114  res->next = style->imports;
115  style->imports = res;
116  if (style->parent == NULL) {
118  }
119  ret = 0;
120  } else {
121  xmlFreeDoc(import);
122  }
123 
124 error:
125  if (uriRef != NULL)
126  xmlFree(uriRef);
127  if (base != NULL)
128  xmlFree(base);
129  if (URI != NULL)
130  xmlFree(URI);
131 
132  return (ret);
133 }
134 
145 int
147  int ret = -1;
148  xmlDocPtr oldDoc;
149  xmlChar *base = NULL;
150  xmlChar *uriRef = NULL;
151  xmlChar *URI = NULL;
154  xsltDocumentPtr docptr;
155  int oldNopreproc;
156 
157  if ((cur == NULL) || (style == NULL))
158  return (ret);
159 
160  uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
161  if (uriRef == NULL) {
163  "xsl:include : missing href attribute\n");
164  goto error;
165  }
166 
167  base = xmlNodeGetBase(style->doc, cur);
168  URI = xmlBuildURI(uriRef, base);
169  if (URI == NULL) {
171  "xsl:include : invalid URI reference %s\n", uriRef);
172  goto error;
173  }
174 
175  /*
176  * in order to detect recursion, we check all previously included
177  * stylesheets.
178  */
179  docptr = style->includes;
180  while (docptr != NULL) {
181  if (xmlStrEqual(docptr->doc->URL, URI)) {
183  "xsl:include : recursion detected on included URL %s\n", URI);
184  goto error;
185  }
186  docptr = docptr->includes;
187  }
188 
190  if (include == NULL) {
192  "xsl:include : unable to load %s\n", URI);
193  goto error;
194  }
195 #ifdef XSLT_REFACTORED
196  if (IS_XSLT_ELEM_FAST(cur) && (cur->psvi != NULL)) {
197  ((xsltStyleItemIncludePtr) cur->psvi)->include = include;
198  } else {
200  "Internal error: (xsltParseStylesheetInclude) "
201  "The xsl:include element was not compiled.\n", URI);
202  style->errors++;
203  }
204 #endif
205  oldDoc = style->doc;
206  style->doc = include->doc;
207  /* chain to stylesheet for recursion checking */
208  include->includes = style->includes;
209  style->includes = include;
210  oldNopreproc = style->nopreproc;
211  style->nopreproc = include->preproc;
212  /*
213  * TODO: This will change some values of the
214  * including stylesheet with every included module
215  * (e.g. excluded-result-prefixes)
216  * We need to strictly seperate such stylesheet-owned values.
217  */
219  style->nopreproc = oldNopreproc;
220  include->preproc = 1;
221  style->includes = include->includes;
222  style->doc = oldDoc;
223  if (result == NULL) {
224  ret = -1;
225  goto error;
226  }
227  ret = 0;
228 
229 error:
230  if (uriRef != NULL)
231  xmlFree(uriRef);
232  if (base != NULL)
233  xmlFree(base);
234  if (URI != NULL)
235  xmlFree(URI);
236 
237  return (ret);
238 }
239 
251  if (cur == NULL)
252  return(NULL);
253  if (cur->imports != NULL)
254  return(cur->imports);
255  if (cur->next != NULL)
256  return(cur->next) ;
257  do {
258  cur = cur->parent;
259  if (cur == NULL) break;
260  if (cur->next != NULL) return(cur->next);
261  } while (cur != NULL);
262  return(cur);
263 }
264 
274 int
277 
278  if (ctxt == NULL)
279  return(0);
280  style = ctxt->style;
281  while (style != NULL) {
282  if (style->stripSpaces != NULL)
283  return(1);
285  }
286  return(0);
287 }
288 
301 int
304  const xmlChar *val;
305 
306  if ((ctxt == NULL) || (node == NULL))
307  return(0);
308  style = ctxt->style;
309  while (style != NULL) {
310  if (node->ns != NULL) {
311  val = (const xmlChar *)
312  xmlHashLookup2(style->stripSpaces, node->name, node->ns->href);
313  if (val == NULL) {
314  val = (const xmlChar *)
315  xmlHashLookup2(style->stripSpaces, BAD_CAST "*",
316  node->ns->href);
317  }
318  } else {
319  val = (const xmlChar *)
320  xmlHashLookup2(style->stripSpaces, node->name, NULL);
321  }
322  if (val != NULL) {
323  if (xmlStrEqual(val, (xmlChar *) "strip"))
324  return(1);
325  if (xmlStrEqual(val, (xmlChar *) "preserve"))
326  return(0);
327  }
328  if (style->stripAll == 1)
329  return(1);
330  if (style->stripAll == -1)
331  return(0);
332 
334  }
335  return(0);
336 }
337 
357  const xmlChar *nameURI) {
358  xsltTemplatePtr cur;
360 
361  if ((ctxt == NULL) || (name == NULL))
362  return(NULL);
363  style = ctxt->style;
364  while (style != NULL) {
365  if (style->namedTemplates != NULL) {
366  cur = (xsltTemplatePtr)
367  xmlHashLookup2(style->namedTemplates, name, nameURI);
368  if (cur != NULL)
369  return(cur);
370  }
371 
373  }
374  return(NULL);
375 }
376 
xsltStylesheetPtr xsltParseStylesheetImportedDoc(xmlDocPtr doc, xsltStylesheetPtr parentStyle)
Definition: xslt.c:6499
void * psvi
Definition: tree.h:505
static void xsltFixImportedCompSteps(xsltStylesheetPtr master, xsltStylesheetPtr style)
Definition: imports.c:28
XMLPUBFUN void XMLCALL xmlHashScan(xmlHashTablePtr table, xmlHashScanner f, void *data)
Definition: hash.c:857
const xmlChar * URL
Definition: tree.h:577
#define error(str)
Definition: mkdosfs.c:1605
xsltTemplatePtr xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name, const xmlChar *nameURI)
Definition: imports.c:356
xsltStylesheetPtr xsltNextImport(xsltStylesheetPtr cur)
Definition: imports.c:250
void xsltNormalizeCompSteps(void *payload, void *data, const xmlChar *name ATTRIBUTE_UNUSED)
Definition: pattern.c:218
struct _xsltStylesheet * imports
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:93
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:400
XMLPUBFUN xmlChar *XMLCALL xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur)
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54
XMLPUBFUN void *XMLCALL xmlHashLookup2(xmlHashTablePtr table, const xmlChar *name, const xmlChar *name2)
Definition: hash.c:474
xmlDocPtr doc
xsltTemplate * xsltTemplatePtr
struct _xsltDocument * includes
struct _xsltStylesheet * parent
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:30
int xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur)
Definition: imports.c:146
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI(const xmlChar *URI, const xmlChar *base)
Definition: uri.c:1882
smooth NULL
Definition: ftsmooth.c:416
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
XMLPUBFUN xmlChar *XMLCALL xmlGetNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace)
Definition: tree.h:489
struct _xsltStylesheet * next
int ret
unsigned char xmlChar
Definition: xmlstring.h:28
int xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: imports.c:302
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:275
xsltStylesheetPtr style
xsltDocumentPtr xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI)
Definition: documents.c:342
Definition: tree.h:551
Definition: name.c:38
GLuint res
Definition: glext.h:9613
int xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur)
Definition: imports.c:49
xsltSecurityPrefsPtr xsltGetDefaultSecurityPrefs(void)
Definition: security.c:163
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:157
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
Arabic default style
Definition: afstyles.h:93
GLuint64EXT * result
Definition: glext.h:11304
xsltStylesheetPtr xsltParseStylesheetProcess(xsltStylesheetPtr ret, xmlDocPtr doc)
Definition: xslt.c:6391
Definition: dlist.c:348