OLD | NEW |
1 /* | 1 /* |
2 * documents.c: Implementation of the documents handling | 2 * documents.c: Implementation of the documents handling |
3 * | 3 * |
4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
5 * | 5 * |
6 * daniel@veillard.com | 6 * daniel@veillard.com |
7 */ | 7 */ |
8 | 8 |
9 #define IN_LIBXSLT | 9 #define IN_LIBXSLT |
10 #include "libxslt.h" | 10 #include "libxslt.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include <libxml/xinclude.h> | 29 #include <libxml/xinclude.h> |
30 #endif | 30 #endif |
31 | 31 |
32 #define WITH_XSLT_DEBUG_DOCUMENTS | 32 #define WITH_XSLT_DEBUG_DOCUMENTS |
33 | 33 |
34 #ifdef WITH_XSLT_DEBUG | 34 #ifdef WITH_XSLT_DEBUG |
35 #define WITH_XSLT_DEBUG_DOCUMENTS | 35 #define WITH_XSLT_DEBUG_DOCUMENTS |
36 #endif | 36 #endif |
37 | 37 |
38 /************************************************************************ | 38 /************************************************************************ |
39 * » » » » » » » » » * | 39 *» » » » » » » » » * |
40 * » » Hooks for the document loader» » » » * | 40 *» » Hooks for the document loader» » » » * |
41 * » » » » » » » » » * | 41 *» » » » » » » » » * |
42 ************************************************************************/ | 42 ************************************************************************/ |
43 | 43 |
44 /** | 44 /** |
45 * xsltDocDefaultLoaderFunc: | 45 * xsltDocDefaultLoaderFunc: |
46 * @URI: the URI of the document to load | 46 * @URI: the URI of the document to load |
47 * @dict: the dictionary to use when parsing that document | 47 * @dict: the dictionary to use when parsing that document |
48 * @options: parsing options, a set of xmlParserOption | 48 * @options: parsing options, a set of xmlParserOption |
49 * @ctxt: the context, either a stylesheet or a transformation context | 49 * @ctxt: the context, either a stylesheet or a transformation context |
50 * @type: the xsltLoadType indicating the kind of loading required | 50 * @type: the xsltLoadType indicating the kind of loading required |
51 * | 51 * |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 xsltDocLoaderFunc xsltDocDefaultLoader = xsltDocDefaultLoaderFunc; | 110 xsltDocLoaderFunc xsltDocDefaultLoader = xsltDocDefaultLoaderFunc; |
111 | 111 |
112 /** | 112 /** |
113 * xsltSetLoaderFunc: | 113 * xsltSetLoaderFunc: |
114 * @f: the new function to handle document loading. | 114 * @f: the new function to handle document loading. |
115 * | 115 * |
116 * Set the new function to load document, if NULL it resets it to the | 116 * Set the new function to load document, if NULL it resets it to the |
117 * default function. | 117 * default function. |
118 */ | 118 */ |
119 | 119 |
120 void | 120 void |
121 xsltSetLoaderFunc(xsltDocLoaderFunc f) { | 121 xsltSetLoaderFunc(xsltDocLoaderFunc f) { |
122 if (f == NULL) | 122 if (f == NULL) |
123 xsltDocDefaultLoader = xsltDocDefaultLoaderFunc; | 123 xsltDocDefaultLoader = xsltDocDefaultLoaderFunc; |
124 else | 124 else |
125 xsltDocDefaultLoader = f; | 125 xsltDocDefaultLoader = f; |
126 } | 126 } |
127 | 127 |
128 /************************************************************************ | 128 /************************************************************************ |
129 * * | 129 * * |
130 * Module interfaces * | 130 * Module interfaces * |
131 * * | 131 * * |
132 ************************************************************************/ | 132 ************************************************************************/ |
133 | 133 |
134 /** | 134 /** |
135 * xsltNewDocument: | 135 * xsltNewDocument: |
136 * @ctxt: an XSLT transformation context (or NULL) | 136 * @ctxt: an XSLT transformation context (or NULL) |
137 * @doc: a parsed XML document | 137 * @doc: a parsed XML document |
138 * | 138 * |
139 * Register a new document, apply key computations | 139 * Register a new document, apply key computations |
140 * | 140 * |
141 * Returns a handler to the document | 141 * Returns a handler to the document |
142 */ | 142 */ |
143 xsltDocumentPtr» | 143 xsltDocumentPtr |
144 xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc) { | 144 xsltNewDocument(xsltTransformContextPtr ctxt, xmlDocPtr doc) { |
145 xsltDocumentPtr cur; | 145 xsltDocumentPtr cur; |
146 | 146 |
147 cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument)); | 147 cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument)); |
148 if (cur == NULL) { | 148 if (cur == NULL) { |
149 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, | 149 xsltTransformError(ctxt, NULL, (xmlNodePtr) doc, |
150 "xsltNewDocument : malloc failed\n"); | 150 "xsltNewDocument : malloc failed\n"); |
151 return(NULL); | 151 return(NULL); |
152 } | 152 } |
153 memset(cur, 0, sizeof(xsltDocument)); | 153 memset(cur, 0, sizeof(xsltDocument)); |
(...skipping 18 matching lines...) Expand all Loading... |
172 | 172 |
173 /** | 173 /** |
174 * xsltNewStyleDocument: | 174 * xsltNewStyleDocument: |
175 * @style: an XSLT style sheet | 175 * @style: an XSLT style sheet |
176 * @doc: a parsed XML document | 176 * @doc: a parsed XML document |
177 * | 177 * |
178 * Register a new document, apply key computations | 178 * Register a new document, apply key computations |
179 * | 179 * |
180 * Returns a handler to the document | 180 * Returns a handler to the document |
181 */ | 181 */ |
182 xsltDocumentPtr» | 182 xsltDocumentPtr |
183 xsltNewStyleDocument(xsltStylesheetPtr style, xmlDocPtr doc) { | 183 xsltNewStyleDocument(xsltStylesheetPtr style, xmlDocPtr doc) { |
184 xsltDocumentPtr cur; | 184 xsltDocumentPtr cur; |
185 | 185 |
186 cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument)); | 186 cur = (xsltDocumentPtr) xmlMalloc(sizeof(xsltDocument)); |
187 if (cur == NULL) { | 187 if (cur == NULL) { |
188 xsltTransformError(NULL, style, (xmlNodePtr) doc, | 188 xsltTransformError(NULL, style, (xmlNodePtr) doc, |
189 "xsltNewStyleDocument : malloc failed\n"); | 189 "xsltNewStyleDocument : malloc failed\n"); |
190 return(NULL); | 190 return(NULL); |
191 } | 191 } |
192 memset(cur, 0, sizeof(xsltDocument)); | 192 memset(cur, 0, sizeof(xsltDocument)); |
193 cur->doc = doc; | 193 cur->doc = doc; |
194 if (style != NULL) { | 194 if (style != NULL) { |
195 cur->next = style->docList; | 195 cur->next = style->docList; |
196 style->docList = cur; | 196 style->docList = cur; |
197 } | 197 } |
198 return(cur); | 198 return(cur); |
199 } | 199 } |
200 | 200 |
201 /** | 201 /** |
202 * xsltFreeStyleDocuments: | 202 * xsltFreeStyleDocuments: |
203 * @style: an XSLT stylesheet (representing a stylesheet-level) | 203 * @style: an XSLT stylesheet (representing a stylesheet-level) |
204 * | 204 * |
205 * Frees the node-trees (and xsltDocument structures) of all | 205 * Frees the node-trees (and xsltDocument structures) of all |
206 * stylesheet-modules of the stylesheet-level represented by | 206 * stylesheet-modules of the stylesheet-level represented by |
207 * the given @style. | 207 * the given @style. |
208 */ | 208 */ |
209 void» | 209 void |
210 xsltFreeStyleDocuments(xsltStylesheetPtr style) { | 210 xsltFreeStyleDocuments(xsltStylesheetPtr style) { |
211 xsltDocumentPtr doc, cur; | 211 xsltDocumentPtr doc, cur; |
212 #ifdef XSLT_REFACTORED_XSLT_NSCOMP | 212 #ifdef XSLT_REFACTORED_XSLT_NSCOMP |
213 xsltNsMapPtr nsMap; | 213 xsltNsMapPtr nsMap; |
214 #endif | 214 #endif |
215 | 215 |
216 if (style == NULL) | 216 if (style == NULL) |
217 return; | 217 return; |
218 | 218 |
219 #ifdef XSLT_REFACTORED_XSLT_NSCOMP | 219 #ifdef XSLT_REFACTORED_XSLT_NSCOMP |
220 if (XSLT_HAS_INTERNAL_NSMAP(style)) | 220 if (XSLT_HAS_INTERNAL_NSMAP(style)) |
221 nsMap = XSLT_GET_INTERNAL_NSMAP(style); | 221 nsMap = XSLT_GET_INTERNAL_NSMAP(style); |
222 else | 222 else |
223 » nsMap = NULL; | 223 » nsMap = NULL; |
224 #endif | 224 #endif |
225 | 225 |
226 cur = style->docList; | 226 cur = style->docList; |
227 while (cur != NULL) { | 227 while (cur != NULL) { |
228 doc = cur; | 228 doc = cur; |
229 cur = cur->next; | 229 cur = cur->next; |
230 #ifdef XSLT_REFACTORED_XSLT_NSCOMP | 230 #ifdef XSLT_REFACTORED_XSLT_NSCOMP |
231 /* | 231 /* |
232 * Restore all changed namespace URIs of ns-decls. | 232 * Restore all changed namespace URIs of ns-decls. |
233 */ | 233 */ |
234 if (nsMap) | 234 if (nsMap) |
235 xsltRestoreDocumentNamespaces(nsMap, doc->doc); | 235 xsltRestoreDocumentNamespaces(nsMap, doc->doc); |
236 #endif | 236 #endif |
237 xsltFreeDocumentKeys(doc); | 237 xsltFreeDocumentKeys(doc); |
238 if (!doc->main) | 238 if (!doc->main) |
239 xmlFreeDoc(doc->doc); | 239 xmlFreeDoc(doc->doc); |
240 xmlFree(doc); | 240 xmlFree(doc); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 /** | 244 /** |
245 * xsltFreeDocuments: | 245 * xsltFreeDocuments: |
246 * @ctxt: an XSLT transformation context | 246 * @ctxt: an XSLT transformation context |
247 * | 247 * |
248 * Free up all the space used by the loaded documents | 248 * Free up all the space used by the loaded documents |
249 */ | 249 */ |
250 void» | 250 void |
251 xsltFreeDocuments(xsltTransformContextPtr ctxt) { | 251 xsltFreeDocuments(xsltTransformContextPtr ctxt) { |
252 xsltDocumentPtr doc, cur; | 252 xsltDocumentPtr doc, cur; |
253 | 253 |
254 cur = ctxt->docList; | 254 cur = ctxt->docList; |
255 while (cur != NULL) { | 255 while (cur != NULL) { |
256 doc = cur; | 256 doc = cur; |
257 cur = cur->next; | 257 cur = cur->next; |
258 xsltFreeDocumentKeys(doc); | 258 xsltFreeDocumentKeys(doc); |
259 if (!doc->main) | 259 if (!doc->main) |
260 xmlFreeDoc(doc->doc); | 260 xmlFreeDoc(doc->doc); |
(...skipping 13 matching lines...) Expand all Loading... |
274 /** | 274 /** |
275 * xsltLoadDocument: | 275 * xsltLoadDocument: |
276 * @ctxt: an XSLT transformation context | 276 * @ctxt: an XSLT transformation context |
277 * @URI: the computed URI of the document | 277 * @URI: the computed URI of the document |
278 * | 278 * |
279 * Try to load a document (not a stylesheet) | 279 * Try to load a document (not a stylesheet) |
280 * within the XSLT transformation context | 280 * within the XSLT transformation context |
281 * | 281 * |
282 * Returns the new xsltDocumentPtr or NULL in case of error | 282 * Returns the new xsltDocumentPtr or NULL in case of error |
283 */ | 283 */ |
284 xsltDocumentPtr» | 284 xsltDocumentPtr |
285 xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) { | 285 xsltLoadDocument(xsltTransformContextPtr ctxt, const xmlChar *URI) { |
286 xsltDocumentPtr ret; | 286 xsltDocumentPtr ret; |
287 xmlDocPtr doc; | 287 xmlDocPtr doc; |
288 | 288 |
289 if ((ctxt == NULL) || (URI == NULL)) | 289 if ((ctxt == NULL) || (URI == NULL)) |
290 return(NULL); | 290 return(NULL); |
291 | 291 |
292 /* | 292 /* |
293 * Security framework check | 293 * Security framework check |
294 */ | 294 */ |
295 if (ctxt->sec != NULL) { | 295 if (ctxt->sec != NULL) { |
296 int res; | 296 int res; |
297 » | 297 |
298 res = xsltCheckRead(ctxt->sec, ctxt, URI); | 298 res = xsltCheckRead(ctxt->sec, ctxt, URI); |
299 if (res == 0) { | 299 if (res == 0) { |
300 xsltTransformError(ctxt, NULL, NULL, | 300 xsltTransformError(ctxt, NULL, NULL, |
301 "xsltLoadDocument: read rights for %s denied\n", | 301 "xsltLoadDocument: read rights for %s denied\n", |
302 URI); | 302 URI); |
303 return(NULL); | 303 return(NULL); |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 /* | 307 /* |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 348 |
349 /** | 349 /** |
350 * xsltLoadStyleDocument: | 350 * xsltLoadStyleDocument: |
351 * @style: an XSLT style sheet | 351 * @style: an XSLT style sheet |
352 * @URI: the computed URI of the document | 352 * @URI: the computed URI of the document |
353 * | 353 * |
354 * Try to load a stylesheet document within the XSLT transformation context | 354 * Try to load a stylesheet document within the XSLT transformation context |
355 * | 355 * |
356 * Returns the new xsltDocumentPtr or NULL in case of error | 356 * Returns the new xsltDocumentPtr or NULL in case of error |
357 */ | 357 */ |
358 xsltDocumentPtr» | 358 xsltDocumentPtr |
359 xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI) { | 359 xsltLoadStyleDocument(xsltStylesheetPtr style, const xmlChar *URI) { |
360 xsltDocumentPtr ret; | 360 xsltDocumentPtr ret; |
361 xmlDocPtr doc; | 361 xmlDocPtr doc; |
362 xsltSecurityPrefsPtr sec; | 362 xsltSecurityPrefsPtr sec; |
363 | 363 |
364 if ((style == NULL) || (URI == NULL)) | 364 if ((style == NULL) || (URI == NULL)) |
365 return(NULL); | 365 return(NULL); |
366 | 366 |
367 /* | 367 /* |
368 * Security framework check | 368 * Security framework check |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 while (ret != NULL) { | 425 while (ret != NULL) { |
426 if (ret->doc == doc) | 426 if (ret->doc == doc) |
427 return(ret); | 427 return(ret); |
428 ret = ret->next; | 428 ret = ret->next; |
429 } | 429 } |
430 if (doc == ctxt->style->doc) | 430 if (doc == ctxt->style->doc) |
431 return(ctxt->document); | 431 return(ctxt->document); |
432 return(NULL); | 432 return(NULL); |
433 } | 433 } |
434 | 434 |
OLD | NEW |