1 /*
2  * Summary: set of utilities for the XSLT engine
3  * Description: interfaces for the utilities module of the XSLT engine.
4  *              things like message handling, profiling, and other
5  *              generally useful routines.
6  *
7  * Copy: See Copyright for the status of this software.
8  *
9  * Author: Daniel Veillard
10  */
11 
12 #ifndef __XML_XSLTUTILS_H__
13 #define __XML_XSLTUTILS_H__
14 
15 #include <libxslt/xsltconfig.h>
16 #include <libxml/xpath.h>
17 #include <libxml/dict.h>
18 #include <libxml/xmlerror.h>
19 #include "xsltexports.h"
20 #include "xsltInternals.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /**
27  * XSLT_TODO:
28  *
29  * Macro to flag unimplemented blocks.
30  */
31 #define XSLT_TODO							\
32     xsltGenericError(xsltGenericErrorContext,				\
33 	    "Unimplemented block at %s:%d\n",				\
34             __FILE__, __LINE__);
35 
36 /**
37  * XSLT_STRANGE:
38  *
39  * Macro to flag that a problem was detected internally.
40  */
41 #define XSLT_STRANGE							\
42     xsltGenericError(xsltGenericErrorContext,				\
43 	    "Internal error at %s:%d\n",				\
44             __FILE__, __LINE__);
45 
46 /**
47  * IS_XSLT_ELEM:
48  *
49  * Checks that the element pertains to XSLT namespace.
50  */
51 #define IS_XSLT_ELEM(n)							\
52     (((n) != NULL) && ((n)->type == XML_ELEMENT_NODE) &&                \
53      ((n)->ns != NULL) && (xmlStrEqual((n)->ns->href, XSLT_NAMESPACE)))
54 
55 /**
56  * IS_XSLT_NAME:
57  *
58  * Checks the value of an element in XSLT namespace.
59  */
60 #define IS_XSLT_NAME(n, val)						\
61     (xmlStrEqual((n)->name, (const xmlChar *) (val)))
62 
63 /**
64  * IS_XSLT_REAL_NODE:
65  *
66  * Check that a node is a 'real' one: document, element, text or attribute.
67  */
68 #define IS_XSLT_REAL_NODE(n)						\
69     (((n) != NULL) &&							\
70      (((n)->type == XML_ELEMENT_NODE) ||				\
71       ((n)->type == XML_TEXT_NODE) ||					\
72       ((n)->type == XML_CDATA_SECTION_NODE) ||				\
73       ((n)->type == XML_ATTRIBUTE_NODE) ||				\
74       ((n)->type == XML_DOCUMENT_NODE) ||				\
75       ((n)->type == XML_HTML_DOCUMENT_NODE) ||				\
76       ((n)->type == XML_COMMENT_NODE) ||				\
77       ((n)->type == XML_PI_NODE)))
78 
79 /*
80  * Our own version of namespaced attributes lookup.
81  */
82 XSLTPUBFUN xmlChar * XSLTCALL
83 		xsltGetNsProp	(xmlNodePtr node,
84 				 const xmlChar *name,
85 				 const xmlChar *nameSpace);
86 XSLTPUBFUN const xmlChar * XSLTCALL
87 		xsltGetCNsProp	(xsltStylesheetPtr style,
88 				 xmlNodePtr node,
89 				 const xmlChar *name,
90 				 const xmlChar *nameSpace);
91 XSLTPUBFUN int XSLTCALL
92 		xsltGetUTF8Char	(const unsigned char *utf,
93 				 int *len);
94 
95 /*
96  * XSLT Debug Tracing Tracing Types
97  */
98 typedef enum {
99 	XSLT_TRACE_ALL =		-1,
100 	XSLT_TRACE_NONE =		0,
101 	XSLT_TRACE_COPY_TEXT =		1<<0,
102 	XSLT_TRACE_PROCESS_NODE =	1<<1,
103 	XSLT_TRACE_APPLY_TEMPLATE =	1<<2,
104 	XSLT_TRACE_COPY =		1<<3,
105 	XSLT_TRACE_COMMENT =		1<<4,
106 	XSLT_TRACE_PI =			1<<5,
107 	XSLT_TRACE_COPY_OF =		1<<6,
108 	XSLT_TRACE_VALUE_OF =		1<<7,
109 	XSLT_TRACE_CALL_TEMPLATE =	1<<8,
110 	XSLT_TRACE_APPLY_TEMPLATES =	1<<9,
111 	XSLT_TRACE_CHOOSE =		1<<10,
112 	XSLT_TRACE_IF =			1<<11,
113 	XSLT_TRACE_FOR_EACH =		1<<12,
114 	XSLT_TRACE_STRIP_SPACES =	1<<13,
115 	XSLT_TRACE_TEMPLATES =		1<<14,
116 	XSLT_TRACE_KEYS =		1<<15,
117 	XSLT_TRACE_VARIABLES =		1<<16
118 } xsltDebugTraceCodes;
119 
120 /**
121  * XSLT_TRACE:
122  *
123  * Control the type of xsl debugtrace messages emitted.
124  */
125 #define XSLT_TRACE(ctxt,code,call)	\
126 	if (ctxt->traceCode && (*(ctxt->traceCode) & code)) \
127 	    call
128 
129 XSLTPUBFUN void XSLTCALL
130 		xsltDebugSetDefaultTrace(xsltDebugTraceCodes val);
131 XSLTPUBFUN xsltDebugTraceCodes XSLTCALL
132 		xsltDebugGetDefaultTrace(void);
133 
134 /*
135  * XSLT specific error and debug reporting functions.
136  */
137 XSLTPUBVAR xmlGenericErrorFunc xsltGenericError;
138 XSLTPUBVAR void *xsltGenericErrorContext;
139 XSLTPUBVAR xmlGenericErrorFunc xsltGenericDebug;
140 XSLTPUBVAR void *xsltGenericDebugContext;
141 
142 XSLTPUBFUN void XSLTCALL
143 		xsltPrintErrorContext		(xsltTransformContextPtr ctxt,
144 	                                         xsltStylesheetPtr style,
145 						 xmlNodePtr node);
146 XSLTPUBFUN void XSLTCALL
147 		xsltMessage			(xsltTransformContextPtr ctxt,
148 						 xmlNodePtr node,
149 						 xmlNodePtr inst);
150 XSLTPUBFUN void XSLTCALL
151 		xsltSetGenericErrorFunc		(void *ctx,
152 						 xmlGenericErrorFunc handler);
153 XSLTPUBFUN void XSLTCALL
154 		xsltSetGenericDebugFunc		(void *ctx,
155 						 xmlGenericErrorFunc handler);
156 XSLTPUBFUN void XSLTCALL
157 		xsltSetTransformErrorFunc	(xsltTransformContextPtr ctxt,
158 						 void *ctx,
159 						 xmlGenericErrorFunc handler);
160 XSLTPUBFUN void XSLTCALL
161 		xsltTransformError		(xsltTransformContextPtr ctxt,
162 						 xsltStylesheetPtr style,
163 						 xmlNodePtr node,
164 						 const char *msg,
165 						 ...) LIBXSLT_ATTR_FORMAT(4,5);
166 
167 XSLTPUBFUN int XSLTCALL
168 		xsltSetCtxtParseOptions		(xsltTransformContextPtr ctxt,
169 						 int options);
170 /*
171  * Sorting.
172  */
173 
174 XSLTPUBFUN void XSLTCALL
175 		xsltDocumentSortFunction	(xmlNodeSetPtr list);
176 XSLTPUBFUN void XSLTCALL
177 		xsltSetSortFunc			(xsltSortFunc handler);
178 XSLTPUBFUN void XSLTCALL
179 		xsltSetCtxtSortFunc		(xsltTransformContextPtr ctxt,
180 						 xsltSortFunc handler);
181 XSLTPUBFUN void XSLTCALL
182 		xsltDefaultSortFunction		(xsltTransformContextPtr ctxt,
183 						 xmlNodePtr *sorts,
184 						 int nbsorts);
185 XSLTPUBFUN void XSLTCALL
186 		xsltDoSortFunction		(xsltTransformContextPtr ctxt,
187 						 xmlNodePtr * sorts,
188 						 int nbsorts);
189 XSLTPUBFUN xmlXPathObjectPtr * XSLTCALL
190 		xsltComputeSortResult		(xsltTransformContextPtr ctxt,
191 						 xmlNodePtr sort);
192 
193 /*
194  * QNames handling.
195  */
196 
197 XSLTPUBFUN const xmlChar * XSLTCALL
198 		xsltSplitQName			(xmlDictPtr dict,
199 						 const xmlChar *name,
200 						 const xmlChar **prefix);
201 XSLTPUBFUN const xmlChar * XSLTCALL
202 		xsltGetQNameURI			(xmlNodePtr node,
203 						 xmlChar **name);
204 
205 XSLTPUBFUN const xmlChar * XSLTCALL
206 		xsltGetQNameURI2		(xsltStylesheetPtr style,
207 						 xmlNodePtr node,
208 						 const xmlChar **name);
209 
210 /*
211  * Output, reuse libxml I/O buffers.
212  */
213 XSLTPUBFUN int XSLTCALL
214 		xsltSaveResultTo		(xmlOutputBufferPtr buf,
215 						 xmlDocPtr result,
216 						 xsltStylesheetPtr style);
217 XSLTPUBFUN int XSLTCALL
218 		xsltSaveResultToFilename	(const char *URI,
219 						 xmlDocPtr result,
220 						 xsltStylesheetPtr style,
221 						 int compression);
222 XSLTPUBFUN int XSLTCALL
223 		xsltSaveResultToFile		(FILE *file,
224 						 xmlDocPtr result,
225 						 xsltStylesheetPtr style);
226 XSLTPUBFUN int XSLTCALL
227 		xsltSaveResultToFd		(int fd,
228 						 xmlDocPtr result,
229 						 xsltStylesheetPtr style);
230 XSLTPUBFUN int XSLTCALL
231 		xsltSaveResultToString          (xmlChar **doc_txt_ptr,
232                                                  int * doc_txt_len,
233                                                  xmlDocPtr result,
234                                                  xsltStylesheetPtr style);
235 
236 /*
237  * XPath interface
238  */
239 XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL
240 		xsltXPathCompile		(xsltStylesheetPtr style,
241 						 const xmlChar *str);
242 XSLTPUBFUN xmlXPathCompExprPtr XSLTCALL
243 		xsltXPathCompileFlags		(xsltStylesheetPtr style,
244 						 const xmlChar *str,
245 						 int flags);
246 
247 /*
248  * Profiling.
249  */
250 XSLTPUBFUN void XSLTCALL
251 		xsltSaveProfiling		(xsltTransformContextPtr ctxt,
252 						 FILE *output);
253 XSLTPUBFUN xmlDocPtr XSLTCALL
254 		xsltGetProfileInformation	(xsltTransformContextPtr ctxt);
255 
256 XSLTPUBFUN long XSLTCALL
257 		xsltTimestamp			(void);
258 XSLTPUBFUN void XSLTCALL
259 		xsltCalibrateAdjust		(long delta);
260 
261 /**
262  * XSLT_TIMESTAMP_TICS_PER_SEC:
263  *
264  * Sampling precision for profiling
265  */
266 #define XSLT_TIMESTAMP_TICS_PER_SEC 100000l
267 
268 /*
269  * Hooks for the debugger.
270  */
271 
272 typedef enum {
273     XSLT_DEBUG_NONE = 0, /* no debugging allowed */
274     XSLT_DEBUG_INIT,
275     XSLT_DEBUG_STEP,
276     XSLT_DEBUG_STEPOUT,
277     XSLT_DEBUG_NEXT,
278     XSLT_DEBUG_STOP,
279     XSLT_DEBUG_CONT,
280     XSLT_DEBUG_RUN,
281     XSLT_DEBUG_RUN_RESTART,
282     XSLT_DEBUG_QUIT
283 } xsltDebugStatusCodes;
284 
285 XSLTPUBVAR int xslDebugStatus;
286 
287 typedef void (*xsltHandleDebuggerCallback) (xmlNodePtr cur, xmlNodePtr node,
288 			xsltTemplatePtr templ, xsltTransformContextPtr ctxt);
289 typedef int (*xsltAddCallCallback) (xsltTemplatePtr templ, xmlNodePtr source);
290 typedef void (*xsltDropCallCallback) (void);
291 
292 XSLTPUBFUN void XSLTCALL
293 		xsltSetDebuggerStatus		(int value);
294 XSLTPUBFUN int XSLTCALL
295 		xsltGetDebuggerStatus		(void);
296 XSLTPUBFUN int XSLTCALL
297 		xsltSetDebuggerCallbacks	(int no, void *block);
298 XSLTPUBFUN int XSLTCALL
299 		xslAddCall			(xsltTemplatePtr templ,
300 						 xmlNodePtr source);
301 XSLTPUBFUN void XSLTCALL
302 		xslDropCall			(void);
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif /* __XML_XSLTUTILS_H__ */
309 
310 
311