blob: 40c3bcee20c86f79b35dddc8698300639a7d4bef [file] [log] [blame]
Owen Taylor3473f882001-02-23 17:55:21 +00001/*
2 * xpath.c: internal interfaces for XML Path Language implementation
3 * used to build new modules on top of XPath
4 *
5 * See COPYRIGHT for the status of this software
6 *
Daniel Veillardc5d64342001-06-24 12:13:24 +00007 * Author: daniel@veillard.com
Owen Taylor3473f882001-02-23 17:55:21 +00008 */
9
10#ifndef __XML_XPATH_INTERNALS_H__
11#define __XML_XPATH_INTERNALS_H__
12
Daniel Veillardc5d64342001-06-24 12:13:24 +000013#if defined(WIN32) && defined(_MSC_VER)
14#include <libxml/xmlwin32version.h>
15#else
Daniel Veillard017b1082001-06-21 11:20:21 +000016#include <libxml/xmlversion.h>
Daniel Veillardc5d64342001-06-24 12:13:24 +000017#endif
Owen Taylor3473f882001-02-23 17:55:21 +000018#include <libxml/xpath.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24/************************************************************************
25 * *
26 * Helpers *
27 * *
28 ************************************************************************/
29
Daniel Veillardbed7b052001-05-19 14:59:49 +000030/**
31 * CHECK_ERROR:
32 *
33 * macro to return from the function if an XPath error was detected
34 */
Owen Taylor3473f882001-02-23 17:55:21 +000035#define CHECK_ERROR \
36 if (ctxt->error != XPATH_EXPRESSION_OK) return
37
Daniel Veillardbed7b052001-05-19 14:59:49 +000038/**
39 * CHECK_ERROR0:
40 *
41 * macro to return 0 from the function if an XPath error was detected
42 */
Owen Taylor3473f882001-02-23 17:55:21 +000043#define CHECK_ERROR0 \
44 if (ctxt->error != XPATH_EXPRESSION_OK) return(0)
45
Daniel Veillardbed7b052001-05-19 14:59:49 +000046/**
47 * XP_ERROR:
48 * @X: the error code
49 *
50 * Macro to raise an XPath error and return
51 */
Owen Taylor3473f882001-02-23 17:55:21 +000052#define XP_ERROR(X) \
53 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
54 ctxt->error = (X); return; }
55
Daniel Veillardbed7b052001-05-19 14:59:49 +000056/**
57 * XP_ERROR0:
58 * @X: the error code
59 *
60 * Macro to raise an XPath error and return 0
61 */
Owen Taylor3473f882001-02-23 17:55:21 +000062#define XP_ERROR0(X) \
63 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
64 ctxt->error = (X); return(0); }
65
Daniel Veillardbed7b052001-05-19 14:59:49 +000066/**
67 * CHECK_TYPE:
68 * @typeval: the XPath type
69 *
70 * Macro to check that the value on top of the XPath stack is of a given
71 * type.
72 */
Owen Taylor3473f882001-02-23 17:55:21 +000073#define CHECK_TYPE(typeval) \
74 if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \
75 XP_ERROR(XPATH_INVALID_TYPE)
76
Daniel Veillardbed7b052001-05-19 14:59:49 +000077/**
Daniel Veillardf06307e2001-07-03 10:35:50 +000078 * CHECK_TYPE0:
79 * @typeval: the XPath type
80 *
81 * Macro to check that the value on top of the XPath stack is of a given
82 * type. return(0) in case of failure
83 */
84#define CHECK_TYPE0(typeval) \
85 if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \
86 XP_ERROR0(XPATH_INVALID_TYPE)
87
88/**
Daniel Veillardbed7b052001-05-19 14:59:49 +000089 * CHECK_ARITY:
90 * @x: the number of expected args
91 *
92 * Macro to check that the number of args passed to an XPath function matches
93 */
Owen Taylor3473f882001-02-23 17:55:21 +000094#define CHECK_ARITY(x) \
95 if (nargs != (x)) \
96 XP_ERROR(XPATH_INVALID_ARITY);
97
Daniel Veillardbed7b052001-05-19 14:59:49 +000098/**
99 * CAST_TO_STRING:
100 *
101 * Macro to try to cast the value on the top of the XPath stack to a string
102 */
Owen Taylor3473f882001-02-23 17:55:21 +0000103#define CAST_TO_STRING \
104 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)) \
105 xmlXPathStringFunction(ctxt, 1);
106
Daniel Veillardbed7b052001-05-19 14:59:49 +0000107/**
108 * CAST_TO_NUMBER:
109 *
110 * Macro to try to cast the value on the top of the XPath stack to a number
111 */
Owen Taylor3473f882001-02-23 17:55:21 +0000112#define CAST_TO_NUMBER \
113 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)) \
114 xmlXPathNumberFunction(ctxt, 1);
115
Daniel Veillardbed7b052001-05-19 14:59:49 +0000116/**
117 * CAST_TO_BOOLEAN:
118 *
119 * Macro to try to cast the value on the top of the XPath stack to a boolean
120 */
Owen Taylor3473f882001-02-23 17:55:21 +0000121#define CAST_TO_BOOLEAN \
122 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN)) \
123 xmlXPathBooleanFunction(ctxt, 1);
124
125/*
126 * Varibale Lookup forwarding
127 */
128typedef xmlXPathObjectPtr
129 (*xmlXPathVariableLookupFunc) (void *ctxt,
130 const xmlChar *name,
131 const xmlChar *ns_uri);
132
133void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt,
134 xmlXPathVariableLookupFunc f,
135 void *varCtxt);
136
137/*
138 * Error reporting
139 */
140void xmlXPatherror (xmlXPathParserContextPtr ctxt,
141 const char *file,
142 int line,
143 int no);
144
145void xmlXPathDebugDumpObject (FILE *output,
146 xmlXPathObjectPtr cur,
147 int depth);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000148void xmlXPathDebugDumpCompExpr(FILE *output,
149 xmlXPathCompExprPtr comp,
150 int depth);
Owen Taylor3473f882001-02-23 17:55:21 +0000151/**
152 * Extending a context
153 */
154
155int xmlXPathRegisterNs (xmlXPathContextPtr ctxt,
156 const xmlChar *prefix,
157 const xmlChar *ns_uri);
158const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt,
159 const xmlChar *ns_uri);
160void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt);
161
162int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
163 const xmlChar *name,
164 xmlXPathFunction f);
165int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt,
166 const xmlChar *name,
167 const xmlChar *ns_uri,
168 xmlXPathFunction f);
169int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
170 const xmlChar *name,
171 xmlXPathObjectPtr value);
172int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt,
173 const xmlChar *name,
174 const xmlChar *ns_uri,
175 xmlXPathObjectPtr value);
176xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt,
177 const xmlChar *name);
178xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt,
179 const xmlChar *name,
180 const xmlChar *ns_uri);
181void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt);
182xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt,
183 const xmlChar *name);
184xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt,
185 const xmlChar *name,
186 const xmlChar *ns_uri);
187void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt);
188
189/**
190 * Utilities to extend XPath
191 */
192xmlXPathParserContextPtr
193 xmlXPathNewParserContext (const xmlChar *str,
194 xmlXPathContextPtr ctxt);
195void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt);
196
197/* TODO: remap to xmlXPathValuePop and Push */
198xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt);
199int valuePush (xmlXPathParserContextPtr ctxt,
200 xmlXPathObjectPtr value);
201
202xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val);
203xmlXPathObjectPtr xmlXPathNewCString (const char *val);
Daniel Veillardba0b8c92001-05-15 09:43:47 +0000204xmlXPathObjectPtr xmlXPathWrapString (xmlChar *val);
205xmlXPathObjectPtr xmlXPathWrapCString (char *val);
Owen Taylor3473f882001-02-23 17:55:21 +0000206xmlXPathObjectPtr xmlXPathNewFloat (double val);
207xmlXPathObjectPtr xmlXPathNewBoolean (int val);
208xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val);
209xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val);
210void xmlXPathNodeSetAdd (xmlNodeSetPtr cur,
211 xmlNodePtr val);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000212void xmlXPathNodeSetAddUnique (xmlNodeSetPtr cur,
213 xmlNodePtr val);
214void xmlXPathNodeSetSort (xmlNodeSetPtr set);
Owen Taylor3473f882001-02-23 17:55:21 +0000215
216void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
217 int nargs);
218void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
219void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
220xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
221xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
222
223/*
224 * Debug
225 */
226#ifdef LIBXML_DEBUG_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000227void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
228#endif
229/*
230 * Existing functions
231 */
Daniel Veillard017b1082001-06-21 11:20:21 +0000232double xmlXPathStringEvalNumber(const xmlChar *str);
Owen Taylor3473f882001-02-23 17:55:21 +0000233int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt,
234 xmlXPathObjectPtr res);
235void xmlXPathInit(void);
236void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
237void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt);
238xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val);
239void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val);
240xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2);
241void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val);
242void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val);
243void xmlXPathFreeNodeSet(xmlNodeSetPtr obj);
244xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val);
245xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val);
246xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val);
247void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj);
248
249
250xmlXPathObjectPtr xmlXPathNewFloat(double val);
251xmlXPathObjectPtr xmlXPathNewBoolean(int val);
252xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val);
253xmlXPathObjectPtr xmlXPathNewCString(const char *val);
254void xmlXPathFreeObject(xmlXPathObjectPtr obj);
255xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc);
256void xmlXPathFreeContext(xmlXPathContextPtr ctxt);
257
258int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt);
259int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict);
260void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt);
261void xmlXPathAddValues(xmlXPathParserContextPtr ctxt);
262void xmlXPathSubValues(xmlXPathParserContextPtr ctxt);
263void xmlXPathMultValues(xmlXPathParserContextPtr ctxt);
264void xmlXPathDivValues(xmlXPathParserContextPtr ctxt);
265void xmlXPathModValues(xmlXPathParserContextPtr ctxt);
266
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000267int xmlXPathIsNodeType(const xmlChar *name);
Owen Taylor3473f882001-02-23 17:55:21 +0000268
269/*
270 * Some of the axis navigation routines
271 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000272xmlNodePtr xmlXPathNextSelf(xmlXPathParserContextPtr ctxt,
273 xmlNodePtr cur);
274xmlNodePtr xmlXPathNextChild(xmlXPathParserContextPtr ctxt,
275 xmlNodePtr cur);
276xmlNodePtr xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt,
277 xmlNodePtr cur);
278xmlNodePtr xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt,
279 xmlNodePtr cur);
280xmlNodePtr xmlXPathNextParent(xmlXPathParserContextPtr ctxt,
281 xmlNodePtr cur);
282xmlNodePtr xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt,
283 xmlNodePtr cur);
284xmlNodePtr xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt,
285 xmlNodePtr cur);
286xmlNodePtr xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt,
287 xmlNodePtr cur);
288xmlNodePtr xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt,
289 xmlNodePtr cur);
290xmlNodePtr xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt,
291 xmlNodePtr cur);
292xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt,
293 xmlNodePtr cur);
294xmlNodePtr xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt,
295 xmlNodePtr cur);
296xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt,
297 xmlNodePtr cur);
Owen Taylor3473f882001-02-23 17:55:21 +0000298/*
299 * The official core of XPath functions
300 */
301void xmlXPathRoot(xmlXPathParserContextPtr ctxt);
302void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs);
303void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs);
304void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs);
305void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs);
306void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs);
307void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs);
308void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
309void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs);
310void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs);
311void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs);
312void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs);
313void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs);
314void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs);
315void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs);
316void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs);
317void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs);
318void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs);
319void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs);
320void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs);
321void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs);
322void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);
323void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs);
324void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs);
325void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs);
326void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs);
327void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
328#ifdef __cplusplus
329}
330#endif
331#endif /* ! __XML_XPATH_INTERNALS_H__ */