ReactOS 0.4.16-dev-2207-geb15453
documents.c File Reference
#include "libxslt.h"
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
#include <libxml/hash.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include "xslt.h"
#include "xsltInternals.h"
#include "xsltutils.h"
#include "documents.h"
#include "transform.h"
#include "imports.h"
#include "keys.h"
#include "security.h"
Include dependency graph for documents.c:

Go to the source code of this file.

Macros

#define IN_LIBXSLT
 
#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

◆ IN_LIBXSLT

#define IN_LIBXSLT

Definition at line 9 of file documents.c.

◆ WITH_XSLT_DEBUG_DOCUMENTS

#define WITH_XSLT_DEBUG_DOCUMENTS

Definition at line 32 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 61 of file documents.c.

64{
65 xmlParserCtxtPtr pctxt;
66 xmlParserInputPtr inputStream;
67 xmlDocPtr doc;
68
69 pctxt = xmlNewParserCtxt();
70 if (pctxt == NULL)
71 return(NULL);
72 if ((dict != NULL) && (pctxt->dict != NULL)) {
73 xmlDictFree(pctxt->dict);
74 pctxt->dict = NULL;
75 }
76 if (dict != NULL) {
77 pctxt->dict = dict;
78 xmlDictReference(pctxt->dict);
79#ifdef WITH_XSLT_DEBUG
81 "Reusing dictionary for document\n");
82#endif
83 }
85 inputStream = xmlLoadExternalEntity((const char *) URI, NULL, pctxt);
86 if (inputStream == NULL) {
87 xmlFreeParserCtxt(pctxt);
88 return(NULL);
89 }
90 inputPush(pctxt, inputStream);
91
92 xmlParseDocument(pctxt);
93
94 if (pctxt->wellFormed) {
95 doc = pctxt->myDoc;
96 }
97 else {
98 doc = NULL;
99 xmlFreeDoc(pctxt->myDoc);
100 pctxt->myDoc = NULL;
101 }
102 xmlFreeParserCtxt(pctxt);
103
104 return(doc);
105}
#define NULL
Definition: types.h:112
XMLPUBFUN int inputPush(xmlParserCtxtPtr ctxt, xmlParserInputPtr value)
Definition: parser.c:1897
void xmlDictFree(xmlDictPtr dict)
Definition: dict.c:333
int xmlDictReference(xmlDictPtr dict)
Definition: dict.c:317
XMLPUBFUN int xmlParseDocument(xmlParserCtxtPtr ctxt)
Definition: parser.c:11009
XMLPUBFUN int xmlCtxtUseOptions(xmlParserCtxtPtr ctxt, int options)
Definition: parser.c:14698
XMLPUBFUN xmlParserInputPtr xmlLoadExternalEntity(const char *URL, const char *ID, xmlParserCtxtPtr ctxt)
XMLPUBFUN void xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
XMLPUBFUN xmlParserCtxtPtr xmlNewParserCtxt(void)
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:632
void * xsltGenericDebugContext
Definition: xsltutils.c:633

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 417 of file documents.c.

417 {
419
420 if ((ctxt == NULL) || (doc == NULL))
421 return(NULL);
422
423 /*
424 * Walk the context list to find the document
425 */
426 ret = ctxt->docList;
427 while (ret != NULL) {
428 if (ret->doc == doc)
429 return(ret);
430 ret = ret->next;
431 }
432 if (doc == ctxt->style->doc)
433 return(ctxt->document);
434 return(NULL);
435}
return ret
Definition: mutex.c:146
xsltDocumentPtr document
xsltStylesheetPtr style
xsltDocumentPtr docList

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 249 of file documents.c.

249 {
250 xsltDocumentPtr doc, cur;
251
252 cur = ctxt->docList;
253 while (cur != NULL) {
254 doc = cur;
255 cur = cur->next;
257 if (!doc->main)
258 xmlFreeDoc(doc->doc);
259 xmlFree(doc);
260 }
261 cur = ctxt->styleList;
262 while (cur != NULL) {
263 doc = cur;
264 cur = cur->next;
266 if (!doc->main)
267 xmlFreeDoc(doc->doc);
268 xmlFree(doc);
269 }
270}
FxCollectionEntry * cur
void xsltFreeDocumentKeys(xsltDocumentPtr idoc)
Definition: keys.c:931
xmlFreeFunc xmlFree
Definition: globals.c:184
xmlDocPtr doc
xsltDocumentPtr styleList

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 208 of file documents.c.

208 {
209 xsltDocumentPtr doc, cur;
210#ifdef XSLT_REFACTORED_XSLT_NSCOMP
211 xsltNsMapPtr nsMap;
212#endif
213
214 if (style == NULL)
215 return;
216
217#ifdef XSLT_REFACTORED_XSLT_NSCOMP
218 if (XSLT_HAS_INTERNAL_NSMAP(style))
219 nsMap = XSLT_GET_INTERNAL_NSMAP(style);
220 else
221 nsMap = NULL;
222#endif
223
224 cur = style->docList;
225 while (cur != NULL) {
226 doc = cur;
227 cur = cur->next;
228#ifdef XSLT_REFACTORED_XSLT_NSCOMP
229 /*
230 * Restore all changed namespace URIs of ns-decls.
231 */
232 if (nsMap)
233 xsltRestoreDocumentNamespaces(nsMap, doc->doc);
234#endif
236 if (!doc->main)
237 xmlFreeDoc(doc->doc);
238 xmlFree(doc);
239 }
240}
Arabic default style
Definition: afstyles.h:94

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 283 of file documents.c.

283 {
285 xmlDocPtr doc;
286
287 if ((ctxt == NULL) || (URI == NULL))
288 return(NULL);
289
290 /*
291 * Security framework check
292 */
293 if (ctxt->sec != NULL) {
294 int res;
295
296 res = xsltCheckRead(ctxt->sec, ctxt, URI);
297 if (res <= 0) {
298 if (res == 0)
300 "xsltLoadDocument: read rights for %s denied\n",
301 URI);
302 return(NULL);
303 }
304 }
305
306 /*
307 * Walk the context list to find the document if preparsed
308 */
309 ret = ctxt->docList;
310 while (ret != NULL) {
311 if ((ret->doc != NULL) && (ret->doc->URL != NULL) &&
312 (xmlStrEqual(ret->doc->URL, URI)))
313 return(ret);
314 ret = ret->next;
315 }
316
317 doc = xsltDocDefaultLoader(URI, ctxt->dict, ctxt->parserOptions,
318 (void *) ctxt, XSLT_LOAD_DOCUMENT);
319
320 if (doc == NULL)
321 return(NULL);
322
323 if (ctxt->xinclude != 0) {
324#ifdef LIBXML_XINCLUDE_ENABLED
325#if LIBXML_VERSION >= 20603
326 xmlXIncludeProcessFlags(doc, ctxt->parserOptions);
327#else
328 xmlXIncludeProcess(doc);
329#endif
330#else
332 "xsltLoadDocument(%s) : XInclude processing not compiled in\n",
333 URI);
334#endif
335 }
336 /*
337 * Apply white-space stripping if asked for
338 */
340 xsltApplyStripSpaces(ctxt, xmlDocGetRootElement(doc));
341 if (ctxt->debugStatus == XSLT_DEBUG_NONE)
342 xmlXPathOrderDocElems(doc);
343
344 ret = xsltNewDocument(ctxt, doc);
345 return(ret);
346}
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:419
void xsltApplyStripSpaces(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: transform.c:5649
xsltDocumentPtr xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc)
Definition: documents.c:142
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:108
@ XSLT_LOAD_DOCUMENT
Definition: documents.h:56
GLuint res
Definition: glext.h:9613
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:322
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
@ XSLT_DEBUG_NONE
Definition: xsltutils.h:304

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 358 of file documents.c.

358 {
360 xmlDocPtr doc;
362
363 if ((style == NULL) || (URI == NULL))
364 return(NULL);
365
366 /*
367 * Security framework check
368 */
370 if (sec != NULL) {
371 int res;
372
373 res = xsltCheckRead(sec, NULL, URI);
374 if (res <= 0) {
375 if (res == 0)
377 "xsltLoadStyleDocument: read rights for %s denied\n",
378 URI);
379 return(NULL);
380 }
381 }
382
383 /*
384 * Walk the context list to find the document if preparsed
385 */
386 ret = style->docList;
387 while (ret != NULL) {
388 if ((ret->doc != NULL) && (ret->doc->URL != NULL) &&
389 (xmlStrEqual(ret->doc->URL, URI)))
390 return(ret);
391 ret = ret->next;
392 }
393
395 (void *) style, XSLT_LOAD_STYLESHEET);
396 if (doc == NULL)
397 return(NULL);
398
400 if (ret == NULL)
401 xmlFreeDoc(doc);
402 return(ret);
403}
xsltSecurityPrefsPtr xsltGetDefaultSecurityPrefs(void)
Definition: security.c:180
xsltDocumentPtr xsltNewStyleDocument(xsltStylesheetPtr style, xmlDocPtr doc)
Definition: documents.c:181
@ XSLT_LOAD_STYLESHEET
Definition: documents.h:55
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54

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 142 of file documents.c.

142 {
144
146 if (cur == NULL) {
147 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc,
148 "xsltNewDocument : malloc failed\n");
149 return(NULL);
150 }
151 memset(cur, 0, sizeof(xsltDocument));
152 cur->doc = doc;
153 if (ctxt != NULL) {
154 if (! XSLT_IS_RES_TREE_FRAG(doc)) {
155 cur->next = ctxt->docList;
156 ctxt->docList = cur;
157 }
158 /*
159 * A key with a specific name for a specific document
160 * will only be computed if there's a call to the key()
161 * function using that specific name for that specific
162 * document. I.e. computation of keys will be done in
163 * xsltGetKey() (keys.c) on an on-demand basis.
164 *
165 * xsltInitCtxtKeys(ctxt, cur); not called here anymore
166 */
167 }
168 return(cur);
169}
xmlMallocFunc xmlMalloc
Definition: globals.c:193
#define memset(x, y, z)
Definition: compat.h:39
#define XSLT_IS_RES_TREE_FRAG(n)
Definition: xsltInternals.h:55
xsltDocument * xsltDocumentPtr

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 181 of file documents.c.

181 {
183
185 if (cur == NULL) {
186 xsltTransformError(NULL, style, (xmlNodePtr) doc,
187 "xsltNewStyleDocument : malloc failed\n");
188 return(NULL);
189 }
190 memset(cur, 0, sizeof(xsltDocument));
191 cur->doc = doc;
192 if (style != NULL) {
193 cur->next = style->docList;
194 style->docList = cur;
195 }
196 return(cur);
197}

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 119 of file documents.c.

119 {
120 if (f == NULL)
122 else
124}
static xmlDocPtr xsltDocDefaultLoaderFunc(const xmlChar *URI, xmlDictPtr dict, int options, void *ctxt ATTRIBUTE_UNUSED, xsltLoadType type ATTRIBUTE_UNUSED)
Definition: documents.c:61
GLfloat f
Definition: glext.h:7540
#define f
Definition: ke_i.h:83

Referenced by init_libxslt().

Variable Documentation

◆ xsltDocDefaultLoader