You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
8.1 KiB

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