ReactOS  0.4.13-dev-1174-gdff75d7
documents.c File Reference
#include "precomp.h"
Include dependency graph for documents.c:

Go to the source code of this file.

Macros

#define WITH_XSLT_DEBUG_DOCUMENTS
 

Functions

static xmlDocPtr xsltDocDefaultLoaderFunc (const xmlChar *URI, xmlDictPtr dict, int options, void *ctxt ATTRIBUTE_UNUSED, xsltLoadType type ATTRIBUTE_UNUSED)
 
void xsltSetLoaderFunc (xsltDocLoaderFunc f)
 
xsltDocumentPtr xsltNewDocument (xsltTransformContextPtr ctxt, xmlDocPtr doc)
 
xsltDocumentPtr xsltNewStyleDocument (xsltStylesheetPtr style, xmlDocPtr doc)
 
void xsltFreeStyleDocuments (xsltStylesheetPtr style)
 
void xsltFreeDocuments (xsltTransformContextPtr ctxt)
 
xsltDocumentPtr xsltLoadDocument (xsltTransformContextPtr ctxt, const xmlChar *URI)
 
xsltDocumentPtr xsltLoadStyleDocument (xsltStylesheetPtr style, const xmlChar *URI)
 
xsltDocumentPtr xsltFindDocument (xsltTransformContextPtr ctxt, xmlDocPtr doc)
 

Variables

xsltDocLoaderFunc xsltDocDefaultLoader = xsltDocDefaultLoaderFunc
 

Macro Definition Documentation

◆ WITH_XSLT_DEBUG_DOCUMENTS

#define WITH_XSLT_DEBUG_DOCUMENTS

Definition at line 15 of file documents.c.

Function Documentation

◆ xsltDocDefaultLoaderFunc()

static xmlDocPtr xsltDocDefaultLoaderFunc ( const xmlChar URI,
xmlDictPtr  dict,
int  options,
void *ctxt  ATTRIBUTE_UNUSED,
xsltLoadType type  ATTRIBUTE_UNUSED 
)
static

xsltDocDefaultLoaderFunc: @URI: the URI of the document to load @dict: the dictionary to use when parsing that document @options: parsing options, a set of xmlParserOption @ctxt: the context, either a stylesheet or a transformation context @type: the xsltLoadType indicating the kind of loading required

Default function to load document not provided by the compilation or transformation API themselve, for example when an xsl:import, xsl:include is found at compilation time or when a document() call is made at runtime.

Returns the pointer to the document (which will be modified and freed by the engine later), or NULL in case of error.

Definition at line 44 of file documents.c.

47 {
48  xmlParserCtxtPtr pctxt;
49  xmlParserInputPtr inputStream;
50  xmlDocPtr doc;
51 
52  pctxt = xmlNewParserCtxt();
53  if (pctxt == NULL)
54  return(NULL);
55  if ((dict != NULL) && (pctxt->dict != NULL)) {
56  xmlDictFree(pctxt->dict);
57  pctxt->dict = NULL;
58  }
59  if (dict != NULL) {
60  pctxt->dict = dict;
61  xmlDictReference(pctxt->dict);
62 #ifdef WITH_XSLT_DEBUG
64  "Reusing dictionary for document\n");
65 #endif
66  }
67  xmlCtxtUseOptions(pctxt, options);
68  inputStream = xmlLoadExternalEntity((const char *) URI, NULL, pctxt);
69  if (inputStream == NULL) {
70  xmlFreeParserCtxt(pctxt);
71  return(NULL);
72  }
73  inputPush(pctxt, inputStream);
74  if (pctxt->directory == NULL)
75  pctxt->directory = xmlParserGetDirectory((const char *) URI);
76 
77  xmlParseDocument(pctxt);
78 
79  if (pctxt->wellFormed) {
80  doc = pctxt->myDoc;
81  }
82  else {
83  doc = NULL;
84  xmlFreeDoc(pctxt->myDoc);
85  pctxt->myDoc = NULL;
86  }
87  xmlFreeParserCtxt(pctxt);
88 
89  return(doc);
90 }
XMLPUBFUN int XMLCALL xmlDictReference(xmlDictPtr dict)
Definition: dict.c:638
XMLPUBFUN char *XMLCALL xmlParserGetDirectory(const char *filename)
XMLPUBFUN int XMLCALL inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
Definition: parser.c:1709
XMLPUBFUN void XMLCALL xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
smooth NULL
Definition: ftsmooth.c:416
xmlDictPtr dict
Definition: parser.h:263
void * xsltGenericDebugContext
Definition: xsltutils.c:549
int wellFormed
Definition: parser.h:188
XMLPUBFUN int XMLCALL xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options)
Definition: parser.c:15162
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:548
XMLPUBFUN int XMLCALL xmlParseDocument(xmlParserCtxtPtr ctxt)
Definition: parser.c:10579
xmlDocPtr myDoc
Definition: parser.h:187
XMLPUBFUN void XMLCALL xmlDictFree(xmlDictPtr dict)
Definition: dict.c:793
XMLPUBFUN xmlParserInputPtr XMLCALL xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
char * directory
Definition: parser.h:226
Definition: tree.h:551
XMLPUBFUN xmlParserCtxtPtr XMLCALL xmlNewParserCtxt(void)

Referenced by xsltSetLoaderFunc().

◆ xsltFindDocument()

xsltDocumentPtr xsltFindDocument ( xsltTransformContextPtr  ctxt,
xmlDocPtr  doc 
)

xsltFindDocument: @ctxt: an XSLT transformation context @doc: a parsed XML document

Try to find a document within the XSLT transformation context. This will not find document infos for temporary Result Tree Fragments.

Returns the desired xsltDocumentPtr or NULL in case of error

Definition at line 398 of file documents.c.

398  {
400 
401  if ((ctxt == NULL) || (doc == NULL))
402  return(NULL);
403 
404  /*
405  * Walk the context list to find the document
406  */
407  ret = ctxt->docList;
408  while (ret != NULL) {
409  if (ret->doc == doc)
410  return(ret);
411  ret = ret->next;
412  }
413  if (doc == ctxt->style->doc)
414  return(ctxt->document);
415  return(NULL);
416 }
xsltDocumentPtr docList
smooth NULL
Definition: ftsmooth.c:416
xsltDocumentPtr document
int ret
xsltStylesheetPtr style

Referenced by xsltKeyFunction().

◆ xsltFreeDocuments()

void xsltFreeDocuments ( xsltTransformContextPtr  ctxt)

xsltFreeDocuments: @ctxt: an XSLT transformation context

Free up all the space used by the loaded documents

Definition at line 234 of file documents.c.

234  {
235  xsltDocumentPtr doc, cur;
236 
237  cur = ctxt->docList;
238  while (cur != NULL) {
239  doc = cur;
240  cur = cur->next;
242  if (!doc->main)
243  xmlFreeDoc(doc->doc);
244  xmlFree(doc);
245  }
246  cur = ctxt->styleList;
247  while (cur != NULL) {
248  doc = cur;
249  cur = cur->next;
251  if (!doc->main)
252  xmlFreeDoc(doc->doc);
253  xmlFree(doc);
254  }
255 }
struct _xsltDocument * next
xsltDocumentPtr docList
xmlDocPtr doc
smooth NULL
Definition: ftsmooth.c:416
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
xsltDocumentPtr styleList
void xsltFreeDocumentKeys(xsltDocumentPtr idoc)
Definition: keys.c:920

Referenced by xsltFreeTransformContext().

◆ xsltFreeStyleDocuments()

void xsltFreeStyleDocuments ( xsltStylesheetPtr  style)

xsltFreeStyleDocuments: @style: an XSLT stylesheet (representing a stylesheet-level)

Frees the node-trees (and xsltDocument structures) of all stylesheet-modules of the stylesheet-level represented by the given @style.

Definition at line 193 of file documents.c.

193  {
194  xsltDocumentPtr doc, cur;
195 #ifdef XSLT_REFACTORED_XSLT_NSCOMP
196  xsltNsMapPtr nsMap;
197 #endif
198 
199  if (style == NULL)
200  return;
201 
202 #ifdef XSLT_REFACTORED_XSLT_NSCOMP
203  if (XSLT_HAS_INTERNAL_NSMAP(style))
204  nsMap = XSLT_GET_INTERNAL_NSMAP(style);
205  else
206  nsMap = NULL;
207 #endif
208 
209  cur = style->docList;
210  while (cur != NULL) {
211  doc = cur;
212  cur = cur->next;
213 #ifdef XSLT_REFACTORED_XSLT_NSCOMP
214  /*
215  * Restore all changed namespace URIs of ns-decls.
216  */
217  if (nsMap)
218  xsltRestoreDocumentNamespaces(nsMap, doc->doc);
219 #endif
221  if (!doc->main)
222  xmlFreeDoc(doc->doc);
223  xmlFree(doc);
224  }
225 }
struct _xsltDocument * next
xmlDocPtr doc
smooth NULL
Definition: ftsmooth.c:416
XMLPUBFUN void XMLCALL xmlFreeDoc(xmlDocPtr cur)
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:250
void xsltFreeDocumentKeys(xsltDocumentPtr idoc)
Definition: keys.c:920
Arabic default style
Definition: afstyles.h:93

Referenced by xsltFreeStylesheet().

◆ xsltLoadDocument()

xsltDocumentPtr xsltLoadDocument ( xsltTransformContextPtr  ctxt,
const xmlChar URI 
)

xsltLoadDocument: @ctxt: an XSLT transformation context @URI: the computed URI of the document

Try to load a document (not a stylesheet) within the XSLT transformation context

Returns the new xsltDocumentPtr or NULL in case of error

Definition at line 268 of file documents.c.

268  {
270  xmlDocPtr doc;
271 
272  if ((ctxt == NULL) || (URI == NULL))
273  return(NULL);
274 
275  /*
276  * Security framework check
277  */
278  if (ctxt->sec != NULL) {
279  int res;
280 
281  res = xsltCheckRead(ctxt->sec, ctxt, URI);
282  if (res == 0) {
284  "xsltLoadDocument: read rights for %s denied\n",
285  URI);
286  return(NULL);
287  }
288  }
289 
290  /*
291  * Walk the context list to find the document if preparsed
292  */
293  ret = ctxt->docList;
294  while (ret != NULL) {
295  if ((ret->doc != NULL) && (ret->doc->URL != NULL) &&
296  (xmlStrEqual(ret->doc->URL, URI)))
297  return(ret);
298  ret = ret->next;
299  }
300 
301  doc = xsltDocDefaultLoader(URI, ctxt->dict, ctxt->parserOptions,
302  (void *) ctxt, XSLT_LOAD_DOCUMENT);
303 
304  if (doc == NULL)
305  return(NULL);
306 
307  if (ctxt->xinclude != 0) {
308 #ifdef LIBXML_XINCLUDE_ENABLED
309 #if LIBXML_VERSION >= 20603
310  xmlXIncludeProcessFlags(doc, ctxt->parserOptions);
311 #else
312  xmlXIncludeProcess(doc);
313 #endif
314 #else
316  "xsltLoadDocument(%s) : XInclude processing not compiled in\n",
317  URI);
318 #endif
319  }
320  /*
321  * Apply white-space stripping if asked for
322  */
323  if (xsltNeedElemSpaceHandling(ctxt))
325  if (ctxt->debugStatus == XSLT_DEBUG_NONE)
326  xmlXPathOrderDocElems(doc);
327 
328  ret = xsltNewDocument(ctxt, doc);
329  return(ret);
330 }
xsltDocumentPtr docList
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:93
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:400
smooth NULL
Definition: ftsmooth.c:416
int ret
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:275
void xsltApplyStripSpaces(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: transform.c:5681
Definition: tree.h:551
GLuint res
Definition: glext.h:9613
XMLPUBFUN xmlNodePtr XMLCALL xmlDocGetRootElement(const xmlDoc *doc)
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
xsltDocumentPtr xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc)
Definition: documents.c:127

Referenced by xsltDocumentFunctionLoadDocument().

◆ xsltLoadStyleDocument()

xsltDocumentPtr xsltLoadStyleDocument ( xsltStylesheetPtr  style,
const xmlChar URI 
)

xsltLoadStyleDocument: @style: an XSLT style sheet @URI: the computed URI of the document

Try to load a stylesheet document within the XSLT transformation context

Returns the new xsltDocumentPtr or NULL in case of error

Definition at line 342 of file documents.c.

342  {
344  xmlDocPtr doc;
346 
347  if ((style == NULL) || (URI == NULL))
348  return(NULL);
349 
350  /*
351  * Security framework check
352  */
354  if (sec != NULL) {
355  int res;
356 
357  res = xsltCheckRead(sec, NULL, URI);
358  if (res == 0) {
360  "xsltLoadStyleDocument: read rights for %s denied\n",
361  URI);
362  return(NULL);
363  }
364  }
365 
366  /*
367  * Walk the context list to find the document if preparsed
368  */
369  ret = style->docList;
370  while (ret != NULL) {
371  if ((ret->doc != NULL) && (ret->doc->URL != NULL) &&
372  (xmlStrEqual(ret->doc->URL, URI)))
373  return(ret);
374  ret = ret->next;
375  }
376 
378  (void *) style, XSLT_LOAD_STYLESHEET);
379  if (doc == NULL)
380  return(NULL);
381 
383  return(ret);
384 }
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:93
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:400
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54
smooth NULL
Definition: ftsmooth.c:416
xsltDocumentPtr xsltNewStyleDocument(xsltStylesheetPtr style, xmlDocPtr doc)
Definition: documents.c:166
int ret
Definition: tree.h:551
GLuint res
Definition: glext.h:9613
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

Referenced by xsltParseStylesheetInclude().

◆ xsltNewDocument()

xsltDocumentPtr xsltNewDocument ( xsltTransformContextPtr  ctxt,
xmlDocPtr  doc 
)

xsltNewDocument: @ctxt: an XSLT transformation context (or NULL) @doc: a parsed XML document

Register a new document, apply key computations

Returns a handler to the document

Definition at line 127 of file documents.c.

127  {
128  xsltDocumentPtr cur;
129 
130  cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument));
131  if (cur == NULL) {
132  xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
133  "xsltNewDocument : malloc failed\n");
134  return(NULL);
135  }
136  memset(cur, 0, sizeof(xsltDocument));
137  cur->doc = doc;
138  if (ctxt != NULL) {
139  if (! XSLT_IS_RES_TREE_FRAG(doc)) {
140  cur->next = ctxt->docList;
141  ctxt->docList = cur;
142  }
143  /*
144  * A key with a specific name for a specific document
145  * will only be computed if there's a call to the key()
146  * function using that specific name for that specific
147  * document. I.e. computation of keys will be done in
148  * xsltGetKey() (keys.c) on an on-demand basis.
149  *
150  * xsltInitCtxtKeys(ctxt, cur); not called here anymore
151  */
152  }
153  return(cur);
154 }
struct _xsltDocument * next
xsltDocumentPtr docList
xsltDocument * xsltDocumentPtr
xmlDocPtr doc
smooth NULL
Definition: ftsmooth.c:416
Definition: tree.h:489
#define XSLT_IS_RES_TREE_FRAG(n)
Definition: xsltInternals.h:56
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
#define memset(x, y, z)
Definition: compat.h:39

Referenced by xsltComputeAllKeys(), xsltKeyFunction(), xsltLoadDocument(), and xsltNewTransformContext().

◆ xsltNewStyleDocument()

xsltDocumentPtr xsltNewStyleDocument ( xsltStylesheetPtr  style,
xmlDocPtr  doc 
)

xsltNewStyleDocument: @style: an XSLT style sheet @doc: a parsed XML document

Register a new document, apply key computations

Returns a handler to the document

Definition at line 166 of file documents.c.

166  {
167  xsltDocumentPtr cur;
168 
169  cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument));
170  if (cur == NULL) {
172  "xsltNewStyleDocument : malloc failed\n");
173  return(NULL);
174  }
175  memset(cur, 0, sizeof(xsltDocument));
176  cur->doc = doc;
177  if (style != NULL) {
178  cur->next = style->docList;
179  style->docList = cur;
180  }
181  return(cur);
182 }
struct _xsltDocument * next
xsltDocument * xsltDocumentPtr
xmlDocPtr doc
smooth NULL
Definition: ftsmooth.c:416
Definition: tree.h:489
XMLPUBVAR xmlMallocFunc xmlMalloc
Definition: globals.h:247
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:678
Arabic default style
Definition: afstyles.h:93
#define memset(x, y, z)
Definition: compat.h:39

Referenced by xsltLoadStyleDocument().

◆ xsltSetLoaderFunc()

void xsltSetLoaderFunc ( xsltDocLoaderFunc  f)

xsltSetLoaderFunc: @f: the new function to handle document loading.

Set the new function to load document, if NULL it resets it to the default function.

Definition at line 104 of file documents.c.

104  {
105  if (f == NULL)
107  else
109 }
static xmlDocPtr xsltDocDefaultLoaderFunc(const xmlChar *URI, xmlDictPtr dict, int options, void *ctxt ATTRIBUTE_UNUSED, xsltLoadType type ATTRIBUTE_UNUSED)
Definition: documents.c:44
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:93
smooth NULL
Definition: ftsmooth.c:416
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83

Variable Documentation

◆ xsltDocDefaultLoader