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