ReactOS  0.4.15-dev-1033-gd7d716a
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) {
97  if (secres == 0)
99  "xsl:import: read rights for %s denied\n",
100  URI);
101  goto error;
102  }
103  }
104 
105  import = xsltDocDefaultLoader(URI, style->dict, XSLT_PARSE_OPTIONS,
106  (void *) style, XSLT_LOAD_STYLESHEET);
107  if (import == NULL) {
109  "xsl:import : unable to load %s\n", URI);
110  goto error;
111  }
112 
114  if (res != NULL) {
115  res->next = style->imports;
116  style->imports = res;
117  if (style->parent == NULL) {
119  }
120  ret = 0;
121  } else {
122  xmlFreeDoc(import);
123  }
124 
125 error:
126  if (uriRef != NULL)
127  xmlFree(uriRef);
128  if (base != NULL)
129  xmlFree(base);
130  if (URI != NULL)
131  xmlFree(URI);
132 
133  return (ret);
134 }
135 
146 int
148  int ret = -1;
149  xmlDocPtr oldDoc;
150  xmlChar *base = NULL;
151  xmlChar *uriRef = NULL;
152  xmlChar *URI = NULL;
155  xsltDocumentPtr docptr;
156  int oldNopreproc;
157 
158  if ((cur == NULL) || (style == NULL))
159  return (ret);
160 
161  uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", NULL);
162  if (uriRef == NULL) {
164  "xsl:include : missing href attribute\n");
165  goto error;
166  }
167 
168  base = xmlNodeGetBase(style->doc, cur);
169  URI = xmlBuildURI(uriRef, base);
170  if (URI == NULL) {
172  "xsl:include : invalid URI reference %s\n", uriRef);
173  goto error;
174  }
175 
176  /*
177  * in order to detect recursion, we check all previously included
178  * stylesheets.
179  */
180  docptr = style->includes;
181  while (docptr != NULL) {
182  if (xmlStrEqual(docptr->doc->URL, URI)) {
184  "xsl:include : recursion detected on included URL %s\n", URI);
185  goto error;
186  }
187  docptr = docptr->includes;
188  }
189 
191  if (include == NULL) {
193  "xsl:include : unable to load %s\n", URI);
194  goto error;
195  }
196 #ifdef XSLT_REFACTORED
197  if (IS_XSLT_ELEM_FAST(cur) && (cur->psvi != NULL)) {
198  ((xsltStyleItemIncludePtr) cur->psvi)->include = include;
199  } else {
201  "Internal error: (xsltParseStylesheetInclude) "
202  "The xsl:include element was not compiled.\n", URI);
203  style->errors++;
204  }
205 #endif
206  oldDoc = style->doc;
207  style->doc = include->doc;
208  /* chain to stylesheet for recursion checking */
209  include->includes = style->includes;
210  style->includes = include;
211  oldNopreproc = style->nopreproc;
212  style->nopreproc = include->preproc;
213  /*
214  * TODO: This will change some values of the
215  * including stylesheet with every included module
216  * (e.g. excluded-result-prefixes)
217  * We need to strictly seperate such stylesheet-owned values.
218  */
220  style->nopreproc = oldNopreproc;
221  include->preproc = 1;
222  style->includes = include->includes;
223  style->doc = oldDoc;
224  if (result == NULL) {
225  ret = -1;
226  goto error;
227  }
228  ret = 0;
229 
230 error:
231  if (uriRef != NULL)
232  xmlFree(uriRef);
233  if (base != NULL)
234  xmlFree(base);
235  if (URI != NULL)
236  xmlFree(URI);
237 
238  return (ret);
239 }
240 
252  if (cur == NULL)
253  return(NULL);
254  if (cur->imports != NULL)
255  return(cur->imports);
256  if (cur->next != NULL)
257  return(cur->next) ;
258  do {
259  cur = cur->parent;
260  if (cur == NULL) break;
261  if (cur->next != NULL) return(cur->next);
262  } while (cur != NULL);
263  return(cur);
264 }
265 
275 int
278 
279  if (ctxt == NULL)
280  return(0);
281  style = ctxt->style;
282  while (style != NULL) {
283  if (style->stripSpaces != NULL)
284  return(1);
286  }
287  return(0);
288 }
289 
302 int
305  const xmlChar *val;
306 
307  if ((ctxt == NULL) || (node == NULL))
308  return(0);
309  style = ctxt->style;
310  while (style != NULL) {
311  if (node->ns != NULL) {
312  val = (const xmlChar *)
313  xmlHashLookup2(style->stripSpaces, node->name, node->ns->href);
314  if (val == NULL) {
315  val = (const xmlChar *)
316  xmlHashLookup2(style->stripSpaces, BAD_CAST "*",
317  node->ns->href);
318  }
319  } else {
320  val = (const xmlChar *)
321  xmlHashLookup2(style->stripSpaces, node->name, NULL);
322  }
323  if (val != NULL) {
324  if (xmlStrEqual(val, (xmlChar *) "strip"))
325  return(1);
326  if (xmlStrEqual(val, (xmlChar *) "preserve"))
327  return(0);
328  }
329  if (style->stripAll == 1)
330  return(1);
331  if (style->stripAll == -1)
332  return(0);
333 
335  }
336  return(0);
337 }
338 
358  const xmlChar *nameURI) {
359  xsltTemplatePtr cur;
361 
362  if ((ctxt == NULL) || (name == NULL))
363  return(NULL);
364  style = ctxt->style;
365  while (style != NULL) {
366  if (style->namedTemplates != NULL) {
367  cur = (xsltTemplatePtr)
368  xmlHashLookup2(style->namedTemplates, name, nameURI);
369  if (cur != NULL)
370  return(cur);
371  }
372 
374  }
375  return(NULL);
376 }
377 
xsltStylesheetPtr xsltParseStylesheetImportedDoc(xmlDocPtr doc, xsltStylesheetPtr parentStyle)
Definition: xslt.c:6518
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:864
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:357
xsltStylesheetPtr xsltNextImport(xsltStylesheetPtr cur)
Definition: imports.c:251
void xsltNormalizeCompSteps(void *payload, void *data, const xmlChar *name ATTRIBUTE_UNUSED)
Definition: pattern.c:217
struct _xsltStylesheet * imports
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:93
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:402
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:481
xmlDocPtr doc
xsltTemplate * xsltTemplatePtr
struct _xsltDocument * includes
struct _xsltStylesheet * parent
int xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur)
Definition: imports.c:147
XMLPUBFUN xmlChar *XMLCALL xmlBuildURI(const xmlChar *URI, const xmlChar *base)
Definition: uri.c:1884
smooth NULL
Definition: ftsmooth.c:416
#define BAD_CAST
Definition: xmlstring.h:35
GLuint GLfloat * val
Definition: glext.h:7180
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:30
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:303
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:276
xsltStylesheetPtr style
xsltDocumentPtr xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI)
Definition: documents.c:343
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:6410
Definition: dlist.c:348