blob: 557b8e9d24449e0bfbd1e377052083263f04b382 [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 *
7 * Author: Daniel.Veillard@w3.org
8 */
9
10#ifndef __XML_XPATH_INTERNALS_H__
11#define __XML_XPATH_INTERNALS_H__
12
Daniel Veillard017b1082001-06-21 11:20:21 +000013#include <libxml/xmlversion.h>
Owen Taylor3473f882001-02-23 17:55:21 +000014#include <libxml/xpath.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/************************************************************************
21 * *
22 * Helpers *
23 * *
24 ************************************************************************/
25
Daniel Veillardbed7b052001-05-19 14:59:49 +000026/**
27 * CHECK_ERROR:
28 *
29 * macro to return from the function if an XPath error was detected
30 */
Owen Taylor3473f882001-02-23 17:55:21 +000031#define CHECK_ERROR \
32 if (ctxt->error != XPATH_EXPRESSION_OK) return
33
Daniel Veillardbed7b052001-05-19 14:59:49 +000034/**
35 * CHECK_ERROR0:
36 *
37 * macro to return 0 from the function if an XPath error was detected
38 */
Owen Taylor3473f882001-02-23 17:55:21 +000039#define CHECK_ERROR0 \
40 if (ctxt->error != XPATH_EXPRESSION_OK) return(0)
41
Daniel Veillardbed7b052001-05-19 14:59:49 +000042/**
43 * XP_ERROR:
44 * @X: the error code
45 *
46 * Macro to raise an XPath error and return
47 */
Owen Taylor3473f882001-02-23 17:55:21 +000048#define XP_ERROR(X) \
49 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
50 ctxt->error = (X); return; }
51
Daniel Veillardbed7b052001-05-19 14:59:49 +000052/**
53 * XP_ERROR0:
54 * @X: the error code
55 *
56 * Macro to raise an XPath error and return 0
57 */
Owen Taylor3473f882001-02-23 17:55:21 +000058#define XP_ERROR0(X) \
59 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
60 ctxt->error = (X); return(0); }
61
Daniel Veillardbed7b052001-05-19 14:59:49 +000062/**
63 * CHECK_TYPE:
64 * @typeval: the XPath type
65 *
66 * Macro to check that the value on top of the XPath stack is of a given
67 * type.
68 */
Owen Taylor3473f882001-02-23 17:55:21 +000069#define CHECK_TYPE(typeval) \
70 if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \
71 XP_ERROR(XPATH_INVALID_TYPE)
72
Daniel Veillardbed7b052001-05-19 14:59:49 +000073/**
74 * CHECK_ARITY:
75 * @x: the number of expected args
76 *
77 * Macro to check that the number of args passed to an XPath function matches
78 */
Owen Taylor3473f882001-02-23 17:55:21 +000079#define CHECK_ARITY(x) \
80 if (nargs != (x)) \
81 XP_ERROR(XPATH_INVALID_ARITY);
82
Daniel Veillardbed7b052001-05-19 14:59:49 +000083/**
84 * CAST_TO_STRING:
85 *
86 * Macro to try to cast the value on the top of the XPath stack to a string
87 */
Owen Taylor3473f882001-02-23 17:55:21 +000088#define CAST_TO_STRING \
89 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)) \
90 xmlXPathStringFunction(ctxt, 1);
91
Daniel Veillardbed7b052001-05-19 14:59:49 +000092/**
93 * CAST_TO_NUMBER:
94 *
95 * Macro to try to cast the value on the top of the XPath stack to a number
96 */
Owen Taylor3473f882001-02-23 17:55:21 +000097#define CAST_TO_NUMBER \
98 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)) \
99 xmlXPathNumberFunction(ctxt, 1);
100
Daniel Veillardbed7b052001-05-19 14:59:49 +0000101/**
102 * CAST_TO_BOOLEAN:
103 *
104 * Macro to try to cast the value on the top of the XPath stack to a boolean
105 */
Owen Taylor3473f882001-02-23 17:55:21 +0000106#define CAST_TO_BOOLEAN \
107 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN)) \
108 xmlXPathBooleanFunction(ctxt, 1);
109
110/*
111 * Varibale Lookup forwarding
112 */
113typedef xmlXPathObjectPtr
114 (*xmlXPathVariableLookupFunc) (void *ctxt,
115 const xmlChar *name,
116 const xmlChar *ns_uri);
117
118void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt,
119 xmlXPathVariableLookupFunc f,
120 void *varCtxt);
121
122/*
123 * Error reporting
124 */
125void xmlXPatherror (xmlXPathParserContextPtr ctxt,
126 const char *file,
127 int line,
128 int no);
129
130void xmlXPathDebugDumpObject (FILE *output,
131 xmlXPathObjectPtr cur,
132 int depth);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000133void xmlXPathDebugDumpCompExpr(FILE *output,
134 xmlXPathCompExprPtr comp,
135 int depth);
Owen Taylor3473f882001-02-23 17:55:21 +0000136/**
137 * Extending a context
138 */
139
140int xmlXPathRegisterNs (xmlXPathContextPtr ctxt,
141 const xmlChar *prefix,
142 const xmlChar *ns_uri);
143const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt,
144 const xmlChar *ns_uri);
145void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt);
146
147int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
148 const xmlChar *name,
149 xmlXPathFunction f);
150int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt,
151 const xmlChar *name,
152 const xmlChar *ns_uri,
153 xmlXPathFunction f);
154int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
155 const xmlChar *name,
156 xmlXPathObjectPtr value);
157int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt,
158 const xmlChar *name,
159 const xmlChar *ns_uri,
160 xmlXPathObjectPtr value);
161xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt,
162 const xmlChar *name);
163xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt,
164 const xmlChar *name,
165 const xmlChar *ns_uri);
166void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt);
167xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt,
168 const xmlChar *name);
169xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt,
170 const xmlChar *name,
171 const xmlChar *ns_uri);
172void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt);
173
174/**
175 * Utilities to extend XPath
176 */
177xmlXPathParserContextPtr
178 xmlXPathNewParserContext (const xmlChar *str,
179 xmlXPathContextPtr ctxt);
180void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt);
181
182/* TODO: remap to xmlXPathValuePop and Push */
183xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt);
184int valuePush (xmlXPathParserContextPtr ctxt,
185 xmlXPathObjectPtr value);
186
187xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val);
188xmlXPathObjectPtr xmlXPathNewCString (const char *val);
Daniel Veillardba0b8c92001-05-15 09:43:47 +0000189xmlXPathObjectPtr xmlXPathWrapString (xmlChar *val);
190xmlXPathObjectPtr xmlXPathWrapCString (char *val);
Owen Taylor3473f882001-02-23 17:55:21 +0000191xmlXPathObjectPtr xmlXPathNewFloat (double val);
192xmlXPathObjectPtr xmlXPathNewBoolean (int val);
193xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val);
194xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val);
195void xmlXPathNodeSetAdd (xmlNodeSetPtr cur,
196 xmlNodePtr val);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000197void xmlXPathNodeSetAddUnique (xmlNodeSetPtr cur,
198 xmlNodePtr val);
199void xmlXPathNodeSetSort (xmlNodeSetPtr set);
Owen Taylor3473f882001-02-23 17:55:21 +0000200
201void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
202 int nargs);
203void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
204void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
205xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
206xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
207
208/*
209 * Debug
210 */
211#ifdef LIBXML_DEBUG_ENABLED
Owen Taylor3473f882001-02-23 17:55:21 +0000212void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
213#endif
214/*
215 * Existing functions
216 */
Daniel Veillard017b1082001-06-21 11:20:21 +0000217double xmlXPathStringEvalNumber(const xmlChar *str);
Owen Taylor3473f882001-02-23 17:55:21 +0000218int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt,
219 xmlXPathObjectPtr res);
220void xmlXPathInit(void);
221void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
222void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt);
223xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val);
224void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val);
225xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2);
226void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val);
227void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val);
228void xmlXPathFreeNodeSet(xmlNodeSetPtr obj);
229xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val);
230xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val);
231xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val);
232void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj);
233
234
235xmlXPathObjectPtr xmlXPathNewFloat(double val);
236xmlXPathObjectPtr xmlXPathNewBoolean(int val);
237xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val);
238xmlXPathObjectPtr xmlXPathNewCString(const char *val);
239void xmlXPathFreeObject(xmlXPathObjectPtr obj);
240xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc);
241void xmlXPathFreeContext(xmlXPathContextPtr ctxt);
242
243int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt);
244int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict);
245void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt);
246void xmlXPathAddValues(xmlXPathParserContextPtr ctxt);
247void xmlXPathSubValues(xmlXPathParserContextPtr ctxt);
248void xmlXPathMultValues(xmlXPathParserContextPtr ctxt);
249void xmlXPathDivValues(xmlXPathParserContextPtr ctxt);
250void xmlXPathModValues(xmlXPathParserContextPtr ctxt);
251
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000252int xmlXPathIsNodeType(const xmlChar *name);
Owen Taylor3473f882001-02-23 17:55:21 +0000253
254/*
255 * Some of the axis navigation routines
256 */
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000257xmlNodePtr xmlXPathNextSelf(xmlXPathParserContextPtr ctxt,
258 xmlNodePtr cur);
259xmlNodePtr xmlXPathNextChild(xmlXPathParserContextPtr ctxt,
260 xmlNodePtr cur);
261xmlNodePtr xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt,
262 xmlNodePtr cur);
263xmlNodePtr xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt,
264 xmlNodePtr cur);
265xmlNodePtr xmlXPathNextParent(xmlXPathParserContextPtr ctxt,
266 xmlNodePtr cur);
267xmlNodePtr xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt,
268 xmlNodePtr cur);
269xmlNodePtr xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt,
270 xmlNodePtr cur);
271xmlNodePtr xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt,
272 xmlNodePtr cur);
273xmlNodePtr xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt,
274 xmlNodePtr cur);
275xmlNodePtr xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt,
276 xmlNodePtr cur);
277xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt,
278 xmlNodePtr cur);
279xmlNodePtr xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt,
280 xmlNodePtr cur);
281xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt,
282 xmlNodePtr cur);
Owen Taylor3473f882001-02-23 17:55:21 +0000283/*
284 * The official core of XPath functions
285 */
286void xmlXPathRoot(xmlXPathParserContextPtr ctxt);
287void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs);
288void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs);
289void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs);
290void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs);
291void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs);
292void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs);
293void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs);
294void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs);
295void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs);
296void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs);
297void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs);
298void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs);
299void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs);
300void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs);
301void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs);
302void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs);
303void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs);
304void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs);
305void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs);
306void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs);
307void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs);
308void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs);
309void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs);
310void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs);
311void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs);
312void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs);
313#ifdef __cplusplus
314}
315#endif
316#endif /* ! __XML_XPATH_INTERNALS_H__ */