blob: 122244b9b1d5d43f8a1c1cd3047c6003a6d18bfc [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
13#include <libxml/xpath.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/************************************************************************
20 * *
21 * Helpers *
22 * *
23 ************************************************************************/
24
Daniel Veillardbed7b052001-05-19 14:59:49 +000025/**
26 * CHECK_ERROR:
27 *
28 * macro to return from the function if an XPath error was detected
29 */
Owen Taylor3473f882001-02-23 17:55:21 +000030#define CHECK_ERROR \
31 if (ctxt->error != XPATH_EXPRESSION_OK) return
32
Daniel Veillardbed7b052001-05-19 14:59:49 +000033/**
34 * CHECK_ERROR0:
35 *
36 * macro to return 0 from the function if an XPath error was detected
37 */
Owen Taylor3473f882001-02-23 17:55:21 +000038#define CHECK_ERROR0 \
39 if (ctxt->error != XPATH_EXPRESSION_OK) return(0)
40
Daniel Veillardbed7b052001-05-19 14:59:49 +000041/**
42 * XP_ERROR:
43 * @X: the error code
44 *
45 * Macro to raise an XPath error and return
46 */
Owen Taylor3473f882001-02-23 17:55:21 +000047#define XP_ERROR(X) \
48 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
49 ctxt->error = (X); return; }
50
Daniel Veillardbed7b052001-05-19 14:59:49 +000051/**
52 * XP_ERROR0:
53 * @X: the error code
54 *
55 * Macro to raise an XPath error and return 0
56 */
Owen Taylor3473f882001-02-23 17:55:21 +000057#define XP_ERROR0(X) \
58 { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \
59 ctxt->error = (X); return(0); }
60
Daniel Veillardbed7b052001-05-19 14:59:49 +000061/**
62 * CHECK_TYPE:
63 * @typeval: the XPath type
64 *
65 * Macro to check that the value on top of the XPath stack is of a given
66 * type.
67 */
Owen Taylor3473f882001-02-23 17:55:21 +000068#define CHECK_TYPE(typeval) \
69 if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \
70 XP_ERROR(XPATH_INVALID_TYPE)
71
Daniel Veillardbed7b052001-05-19 14:59:49 +000072/**
73 * CHECK_ARITY:
74 * @x: the number of expected args
75 *
76 * Macro to check that the number of args passed to an XPath function matches
77 */
Owen Taylor3473f882001-02-23 17:55:21 +000078#define CHECK_ARITY(x) \
79 if (nargs != (x)) \
80 XP_ERROR(XPATH_INVALID_ARITY);
81
Daniel Veillardbed7b052001-05-19 14:59:49 +000082/**
83 * CAST_TO_STRING:
84 *
85 * Macro to try to cast the value on the top of the XPath stack to a string
86 */
Owen Taylor3473f882001-02-23 17:55:21 +000087#define CAST_TO_STRING \
88 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)) \
89 xmlXPathStringFunction(ctxt, 1);
90
Daniel Veillardbed7b052001-05-19 14:59:49 +000091/**
92 * CAST_TO_NUMBER:
93 *
94 * Macro to try to cast the value on the top of the XPath stack to a number
95 */
Owen Taylor3473f882001-02-23 17:55:21 +000096#define CAST_TO_NUMBER \
97 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)) \
98 xmlXPathNumberFunction(ctxt, 1);
99
Daniel Veillardbed7b052001-05-19 14:59:49 +0000100/**
101 * CAST_TO_BOOLEAN:
102 *
103 * Macro to try to cast the value on the top of the XPath stack to a boolean
104 */
Owen Taylor3473f882001-02-23 17:55:21 +0000105#define CAST_TO_BOOLEAN \
106 if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN)) \
107 xmlXPathBooleanFunction(ctxt, 1);
108
109/*
110 * Varibale Lookup forwarding
111 */
112typedef xmlXPathObjectPtr
113 (*xmlXPathVariableLookupFunc) (void *ctxt,
114 const xmlChar *name,
115 const xmlChar *ns_uri);
116
117void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt,
118 xmlXPathVariableLookupFunc f,
119 void *varCtxt);
120
121/*
122 * Error reporting
123 */
124void xmlXPatherror (xmlXPathParserContextPtr ctxt,
125 const char *file,
126 int line,
127 int no);
128
129void xmlXPathDebugDumpObject (FILE *output,
130 xmlXPathObjectPtr cur,
131 int depth);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000132void xmlXPathDebugDumpCompExpr(FILE *output,
133 xmlXPathCompExprPtr comp,
134 int depth);
Owen Taylor3473f882001-02-23 17:55:21 +0000135/**
136 * Extending a context
137 */
138
139int xmlXPathRegisterNs (xmlXPathContextPtr ctxt,
140 const xmlChar *prefix,
141 const xmlChar *ns_uri);
142const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt,
143 const xmlChar *ns_uri);
144void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt);
145
146int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt,
147 const xmlChar *name,
148 xmlXPathFunction f);
149int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt,
150 const xmlChar *name,
151 const xmlChar *ns_uri,
152 xmlXPathFunction f);
153int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt,
154 const xmlChar *name,
155 xmlXPathObjectPtr value);
156int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt,
157 const xmlChar *name,
158 const xmlChar *ns_uri,
159 xmlXPathObjectPtr value);
160xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt,
161 const xmlChar *name);
162xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt,
163 const xmlChar *name,
164 const xmlChar *ns_uri);
165void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt);
166xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt,
167 const xmlChar *name);
168xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt,
169 const xmlChar *name,
170 const xmlChar *ns_uri);
171void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt);
172
173/**
174 * Utilities to extend XPath
175 */
176xmlXPathParserContextPtr
177 xmlXPathNewParserContext (const xmlChar *str,
178 xmlXPathContextPtr ctxt);
179void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt);
180
181/* TODO: remap to xmlXPathValuePop and Push */
182xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt);
183int valuePush (xmlXPathParserContextPtr ctxt,
184 xmlXPathObjectPtr value);
185
186xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val);
187xmlXPathObjectPtr xmlXPathNewCString (const char *val);
Daniel Veillardba0b8c92001-05-15 09:43:47 +0000188xmlXPathObjectPtr xmlXPathWrapString (xmlChar *val);
189xmlXPathObjectPtr xmlXPathWrapCString (char *val);
Owen Taylor3473f882001-02-23 17:55:21 +0000190xmlXPathObjectPtr xmlXPathNewFloat (double val);
191xmlXPathObjectPtr xmlXPathNewBoolean (int val);
192xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val);
193xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val);
194void xmlXPathNodeSetAdd (xmlNodeSetPtr cur,
195 xmlNodePtr val);
Daniel Veillard56a4cb82001-03-24 17:00:36 +0000196void xmlXPathNodeSetAddUnique (xmlNodeSetPtr cur,
197 xmlNodePtr val);
198void xmlXPathNodeSetSort (xmlNodeSetPtr set);
Owen Taylor3473f882001-02-23 17:55:21 +0000199
200void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt,
201 int nargs);
202void xmlXPathRoot (xmlXPathParserContextPtr ctxt);
203void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt);
204xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt);
205xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt);
206
207/*
208 * Debug
209 */
210#ifdef LIBXML_DEBUG_ENABLED
211double xmlXPathStringEvalNumber(const xmlChar *str);
212void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth);
213#endif
214/*
215 * Existing functions
216 */
217
218int 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__ */