ReactOS 0.4.16-dev-2206-gc56950d
documents.c
Go to the documentation of this file.
1/*
2 * documents.c: Implementation of the documents handling
3 *
4 * See Copyright for the status of this software.
5 *
6 * daniel@veillard.com
7 */
8
9#define IN_LIBXSLT
10#include "libxslt.h"
11
12#include <string.h>
13
14#include <libxml/xmlmemory.h>
15#include <libxml/tree.h>
16#include <libxml/hash.h>
17#include <libxml/parser.h>
19#include "xslt.h"
20#include "xsltInternals.h"
21#include "xsltutils.h"
22#include "documents.h"
23#include "transform.h"
24#include "imports.h"
25#include "keys.h"
26#include "security.h"
27
28#ifdef LIBXML_XINCLUDE_ENABLED
29#include <libxml/xinclude.h>
30#endif
31
32#define WITH_XSLT_DEBUG_DOCUMENTS
33
34#ifdef WITH_XSLT_DEBUG
35#define WITH_XSLT_DEBUG_DOCUMENTS
36#endif
37
38/************************************************************************
39 * *
40 * Hooks for the document loader *
41 * *
42 ************************************************************************/
43
60static xmlDocPtr
62 void *ctxt ATTRIBUTE_UNUSED,
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}
106
107
109
118void
120 if (f == NULL)
122 else
124}
125
126/************************************************************************
127 * *
128 * Module interfaces *
129 * *
130 ************************************************************************/
131
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}
170
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}
198
207void
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}
241
248void
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}
271
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}
347
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}
404
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}
Arabic default style
Definition: afstyles.h:94
#define NULL
Definition: types.h:112
xsltSecurityPrefsPtr xsltGetDefaultSecurityPrefs(void)
Definition: security.c:180
int xsltCheckRead(xsltSecurityPrefsPtr sec, xsltTransformContextPtr ctxt, const xmlChar *URL)
Definition: security.c:419
void xsltApplyStripSpaces(xsltTransformContextPtr ctxt, xmlNodePtr node)
Definition: transform.c:5649
void xsltFreeStyleDocuments(xsltStylesheetPtr style)
Definition: documents.c:208
xsltDocumentPtr xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc)
Definition: documents.c:142
xsltDocumentPtr xsltFindDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc)
Definition: documents.c:417
static xmlDocPtr xsltDocDefaultLoaderFunc(const xmlChar *URI, xmlDictPtr dict, int options, void *ctxt ATTRIBUTE_UNUSED, xsltLoadType type ATTRIBUTE_UNUSED)
Definition: documents.c:61
xsltDocLoaderFunc xsltDocDefaultLoader
Definition: documents.c:108
void xsltFreeDocuments(xsltTransformContextPtr ctxt)
Definition: documents.c:249
xsltDocumentPtr xsltNewStyleDocument(xsltStylesheetPtr style, xmlDocPtr doc)
Definition: documents.c:181
xsltDocumentPtr xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI)
Definition: documents.c:358
xsltDocumentPtr xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI)
Definition: documents.c:283
void xsltSetLoaderFunc(xsltDocLoaderFunc f)
Definition: documents.c:119
xmlDocPtr(* xsltDocLoaderFunc)(const xmlChar *URI, xmlDictPtr dict, int options, void *ctxt, xsltLoadType type)
Definition: documents.h:76
xsltLoadType
Definition: documents.h:53
@ XSLT_LOAD_STYLESHEET
Definition: documents.h:55
@ XSLT_LOAD_DOCUMENT
Definition: documents.h:56
return ret
Definition: mutex.c:146
FxCollectionEntry * cur
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint res
Definition: glext.h:9613
GLfloat f
Definition: glext.h:7540
#define ATTRIBUTE_UNUSED
Definition: i386-dis.c:36
int xsltNeedElemSpaceHandling(xsltTransformContextPtr ctxt)
Definition: imports.c:322
#define f
Definition: ke_i.h:83
void xsltFreeDocumentKeys(xsltDocumentPtr idoc)
Definition: keys.c:931
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
xmlFreeFunc xmlFree
Definition: globals.c:184
xmlMallocFunc xmlMalloc
Definition: globals.c:193
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)
#define memset(x, y, z)
Definition: compat.h:39
Definition: dict.c:59
xmlDocPtr doc
xsltDocumentPtr document
xsltStylesheetPtr style
xsltDocumentPtr docList
xsltDocumentPtr styleList
XMLPUBFUN int xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:162
unsigned char xmlChar
Definition: xmlstring.h:28
#define XSLT_IS_RES_TREE_FRAG(n)
Definition: xsltInternals.h:55
xsltDocument * xsltDocumentPtr
#define XSLT_PARSE_OPTIONS
Definition: xslt.h:54
void xsltTransformError(xsltTransformContextPtr ctxt, xsltStylesheetPtr style, xmlNodePtr node, const char *msg,...)
Definition: xsltutils.c:762
xmlGenericErrorFunc xsltGenericDebug
Definition: xsltutils.c:632
void * xsltGenericDebugContext
Definition: xsltutils.c:633
@ XSLT_DEBUG_NONE
Definition: xsltutils.h:304