Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 1 | /* |
| 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 |
| 16 | extern "C" { |
| 17 | #endif |
| 18 | |
| 19 | /************************************************************************ |
| 20 | * * |
| 21 | * Helpers * |
| 22 | * * |
| 23 | ************************************************************************/ |
| 24 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 25 | /** |
| 26 | * CHECK_ERROR: |
| 27 | * |
| 28 | * macro to return from the function if an XPath error was detected |
| 29 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 30 | #define CHECK_ERROR \ |
| 31 | if (ctxt->error != XPATH_EXPRESSION_OK) return |
| 32 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 33 | /** |
| 34 | * CHECK_ERROR0: |
| 35 | * |
| 36 | * macro to return 0 from the function if an XPath error was detected |
| 37 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 38 | #define CHECK_ERROR0 \ |
| 39 | if (ctxt->error != XPATH_EXPRESSION_OK) return(0) |
| 40 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 41 | /** |
| 42 | * XP_ERROR: |
| 43 | * @X: the error code |
| 44 | * |
| 45 | * Macro to raise an XPath error and return |
| 46 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 47 | #define XP_ERROR(X) \ |
| 48 | { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \ |
| 49 | ctxt->error = (X); return; } |
| 50 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 51 | /** |
| 52 | * XP_ERROR0: |
| 53 | * @X: the error code |
| 54 | * |
| 55 | * Macro to raise an XPath error and return 0 |
| 56 | */ |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 57 | #define XP_ERROR0(X) \ |
| 58 | { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \ |
| 59 | ctxt->error = (X); return(0); } |
| 60 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 61 | /** |
| 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 Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 68 | #define CHECK_TYPE(typeval) \ |
| 69 | if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \ |
| 70 | XP_ERROR(XPATH_INVALID_TYPE) |
| 71 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 72 | /** |
| 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 Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 78 | #define CHECK_ARITY(x) \ |
| 79 | if (nargs != (x)) \ |
| 80 | XP_ERROR(XPATH_INVALID_ARITY); |
| 81 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 82 | /** |
| 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 Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 87 | #define CAST_TO_STRING \ |
| 88 | if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)) \ |
| 89 | xmlXPathStringFunction(ctxt, 1); |
| 90 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 91 | /** |
| 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 Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 96 | #define CAST_TO_NUMBER \ |
| 97 | if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)) \ |
| 98 | xmlXPathNumberFunction(ctxt, 1); |
| 99 | |
Daniel Veillard | bed7b05 | 2001-05-19 14:59:49 +0000 | [diff] [blame] | 100 | /** |
| 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 Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 105 | #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 | */ |
| 112 | typedef xmlXPathObjectPtr |
| 113 | (*xmlXPathVariableLookupFunc) (void *ctxt, |
| 114 | const xmlChar *name, |
| 115 | const xmlChar *ns_uri); |
| 116 | |
| 117 | void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt, |
| 118 | xmlXPathVariableLookupFunc f, |
| 119 | void *varCtxt); |
| 120 | |
| 121 | /* |
| 122 | * Error reporting |
| 123 | */ |
| 124 | void xmlXPatherror (xmlXPathParserContextPtr ctxt, |
| 125 | const char *file, |
| 126 | int line, |
| 127 | int no); |
| 128 | |
| 129 | void xmlXPathDebugDumpObject (FILE *output, |
| 130 | xmlXPathObjectPtr cur, |
| 131 | int depth); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 132 | void xmlXPathDebugDumpCompExpr(FILE *output, |
| 133 | xmlXPathCompExprPtr comp, |
| 134 | int depth); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 135 | /** |
| 136 | * Extending a context |
| 137 | */ |
| 138 | |
| 139 | int xmlXPathRegisterNs (xmlXPathContextPtr ctxt, |
| 140 | const xmlChar *prefix, |
| 141 | const xmlChar *ns_uri); |
| 142 | const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt, |
| 143 | const xmlChar *ns_uri); |
| 144 | void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt); |
| 145 | |
| 146 | int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt, |
| 147 | const xmlChar *name, |
| 148 | xmlXPathFunction f); |
| 149 | int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt, |
| 150 | const xmlChar *name, |
| 151 | const xmlChar *ns_uri, |
| 152 | xmlXPathFunction f); |
| 153 | int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt, |
| 154 | const xmlChar *name, |
| 155 | xmlXPathObjectPtr value); |
| 156 | int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt, |
| 157 | const xmlChar *name, |
| 158 | const xmlChar *ns_uri, |
| 159 | xmlXPathObjectPtr value); |
| 160 | xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt, |
| 161 | const xmlChar *name); |
| 162 | xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt, |
| 163 | const xmlChar *name, |
| 164 | const xmlChar *ns_uri); |
| 165 | void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt); |
| 166 | xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt, |
| 167 | const xmlChar *name); |
| 168 | xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt, |
| 169 | const xmlChar *name, |
| 170 | const xmlChar *ns_uri); |
| 171 | void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt); |
| 172 | |
| 173 | /** |
| 174 | * Utilities to extend XPath |
| 175 | */ |
| 176 | xmlXPathParserContextPtr |
| 177 | xmlXPathNewParserContext (const xmlChar *str, |
| 178 | xmlXPathContextPtr ctxt); |
| 179 | void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt); |
| 180 | |
| 181 | /* TODO: remap to xmlXPathValuePop and Push */ |
| 182 | xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt); |
| 183 | int valuePush (xmlXPathParserContextPtr ctxt, |
| 184 | xmlXPathObjectPtr value); |
| 185 | |
| 186 | xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val); |
| 187 | xmlXPathObjectPtr xmlXPathNewCString (const char *val); |
Daniel Veillard | ba0b8c9 | 2001-05-15 09:43:47 +0000 | [diff] [blame] | 188 | xmlXPathObjectPtr xmlXPathWrapString (xmlChar *val); |
| 189 | xmlXPathObjectPtr xmlXPathWrapCString (char *val); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 190 | xmlXPathObjectPtr xmlXPathNewFloat (double val); |
| 191 | xmlXPathObjectPtr xmlXPathNewBoolean (int val); |
| 192 | xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val); |
| 193 | xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val); |
| 194 | void xmlXPathNodeSetAdd (xmlNodeSetPtr cur, |
| 195 | xmlNodePtr val); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 196 | void xmlXPathNodeSetAddUnique (xmlNodeSetPtr cur, |
| 197 | xmlNodePtr val); |
| 198 | void xmlXPathNodeSetSort (xmlNodeSetPtr set); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 199 | |
| 200 | void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt, |
| 201 | int nargs); |
| 202 | void xmlXPathRoot (xmlXPathParserContextPtr ctxt); |
| 203 | void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt); |
| 204 | xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt); |
| 205 | xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt); |
| 206 | |
| 207 | /* |
| 208 | * Debug |
| 209 | */ |
| 210 | #ifdef LIBXML_DEBUG_ENABLED |
| 211 | double xmlXPathStringEvalNumber(const xmlChar *str); |
| 212 | void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth); |
| 213 | #endif |
| 214 | /* |
| 215 | * Existing functions |
| 216 | */ |
| 217 | |
| 218 | int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt, |
| 219 | xmlXPathObjectPtr res); |
| 220 | void xmlXPathInit(void); |
| 221 | void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 222 | void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt); |
| 223 | xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val); |
| 224 | void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val); |
| 225 | xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2); |
| 226 | void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val); |
| 227 | void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val); |
| 228 | void xmlXPathFreeNodeSet(xmlNodeSetPtr obj); |
| 229 | xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val); |
| 230 | xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val); |
| 231 | xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val); |
| 232 | void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj); |
| 233 | |
| 234 | |
| 235 | xmlXPathObjectPtr xmlXPathNewFloat(double val); |
| 236 | xmlXPathObjectPtr xmlXPathNewBoolean(int val); |
| 237 | xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val); |
| 238 | xmlXPathObjectPtr xmlXPathNewCString(const char *val); |
| 239 | void xmlXPathFreeObject(xmlXPathObjectPtr obj); |
| 240 | xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc); |
| 241 | void xmlXPathFreeContext(xmlXPathContextPtr ctxt); |
| 242 | |
| 243 | int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt); |
| 244 | int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict); |
| 245 | void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt); |
| 246 | void xmlXPathAddValues(xmlXPathParserContextPtr ctxt); |
| 247 | void xmlXPathSubValues(xmlXPathParserContextPtr ctxt); |
| 248 | void xmlXPathMultValues(xmlXPathParserContextPtr ctxt); |
| 249 | void xmlXPathDivValues(xmlXPathParserContextPtr ctxt); |
| 250 | void xmlXPathModValues(xmlXPathParserContextPtr ctxt); |
| 251 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 252 | int xmlXPathIsNodeType(const xmlChar *name); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 253 | |
| 254 | /* |
| 255 | * Some of the axis navigation routines |
| 256 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 257 | xmlNodePtr xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, |
| 258 | xmlNodePtr cur); |
| 259 | xmlNodePtr xmlXPathNextChild(xmlXPathParserContextPtr ctxt, |
| 260 | xmlNodePtr cur); |
| 261 | xmlNodePtr xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, |
| 262 | xmlNodePtr cur); |
| 263 | xmlNodePtr xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, |
| 264 | xmlNodePtr cur); |
| 265 | xmlNodePtr xmlXPathNextParent(xmlXPathParserContextPtr ctxt, |
| 266 | xmlNodePtr cur); |
| 267 | xmlNodePtr xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, |
| 268 | xmlNodePtr cur); |
| 269 | xmlNodePtr xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, |
| 270 | xmlNodePtr cur); |
| 271 | xmlNodePtr xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, |
| 272 | xmlNodePtr cur); |
| 273 | xmlNodePtr xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, |
| 274 | xmlNodePtr cur); |
| 275 | xmlNodePtr xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt, |
| 276 | xmlNodePtr cur); |
| 277 | xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, |
| 278 | xmlNodePtr cur); |
| 279 | xmlNodePtr xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, |
| 280 | xmlNodePtr cur); |
| 281 | xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, |
| 282 | xmlNodePtr cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 283 | /* |
| 284 | * The official core of XPath functions |
| 285 | */ |
| 286 | void xmlXPathRoot(xmlXPathParserContextPtr ctxt); |
| 287 | void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 288 | void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 289 | void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 290 | void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 291 | void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 292 | void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 293 | void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 294 | void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 295 | void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 296 | void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 297 | void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 298 | void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 299 | void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 300 | void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 301 | void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 302 | void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 303 | void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 304 | void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 305 | void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 306 | void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 307 | void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 308 | void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 309 | void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 310 | void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 311 | void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 312 | void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 313 | #ifdef __cplusplus |
| 314 | } |
| 315 | #endif |
| 316 | #endif /* ! __XML_XPATH_INTERNALS_H__ */ |