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 | |
| 25 | #define CHECK_ERROR \ |
| 26 | if (ctxt->error != XPATH_EXPRESSION_OK) return |
| 27 | |
| 28 | #define CHECK_ERROR0 \ |
| 29 | if (ctxt->error != XPATH_EXPRESSION_OK) return(0) |
| 30 | |
| 31 | #define XP_ERROR(X) \ |
| 32 | { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \ |
| 33 | ctxt->error = (X); return; } |
| 34 | |
| 35 | #define XP_ERROR0(X) \ |
| 36 | { xmlXPatherror(ctxt, __FILE__, __LINE__, X); \ |
| 37 | ctxt->error = (X); return(0); } |
| 38 | |
| 39 | #define CHECK_TYPE(typeval) \ |
| 40 | if ((ctxt->value == NULL) || (ctxt->value->type != typeval)) \ |
| 41 | XP_ERROR(XPATH_INVALID_TYPE) |
| 42 | |
| 43 | #define CHECK_ARITY(x) \ |
| 44 | if (nargs != (x)) \ |
| 45 | XP_ERROR(XPATH_INVALID_ARITY); |
| 46 | |
| 47 | #define CAST_TO_STRING \ |
| 48 | if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_STRING)) \ |
| 49 | xmlXPathStringFunction(ctxt, 1); |
| 50 | |
| 51 | #define CAST_TO_NUMBER \ |
| 52 | if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_NUMBER)) \ |
| 53 | xmlXPathNumberFunction(ctxt, 1); |
| 54 | |
| 55 | #define CAST_TO_BOOLEAN \ |
| 56 | if ((ctxt->value != NULL) && (ctxt->value->type != XPATH_BOOLEAN)) \ |
| 57 | xmlXPathBooleanFunction(ctxt, 1); |
| 58 | |
| 59 | /* |
| 60 | * Varibale Lookup forwarding |
| 61 | */ |
| 62 | typedef xmlXPathObjectPtr |
| 63 | (*xmlXPathVariableLookupFunc) (void *ctxt, |
| 64 | const xmlChar *name, |
| 65 | const xmlChar *ns_uri); |
| 66 | |
| 67 | void xmlXPathRegisterVariableLookup (xmlXPathContextPtr ctxt, |
| 68 | xmlXPathVariableLookupFunc f, |
| 69 | void *varCtxt); |
| 70 | |
| 71 | /* |
| 72 | * Error reporting |
| 73 | */ |
| 74 | void xmlXPatherror (xmlXPathParserContextPtr ctxt, |
| 75 | const char *file, |
| 76 | int line, |
| 77 | int no); |
| 78 | |
| 79 | void xmlXPathDebugDumpObject (FILE *output, |
| 80 | xmlXPathObjectPtr cur, |
| 81 | int depth); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 82 | void xmlXPathDebugDumpCompExpr(FILE *output, |
| 83 | xmlXPathCompExprPtr comp, |
| 84 | int depth); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 85 | /** |
| 86 | * Extending a context |
| 87 | */ |
| 88 | |
| 89 | int xmlXPathRegisterNs (xmlXPathContextPtr ctxt, |
| 90 | const xmlChar *prefix, |
| 91 | const xmlChar *ns_uri); |
| 92 | const xmlChar * xmlXPathNsLookup (xmlXPathContextPtr ctxt, |
| 93 | const xmlChar *ns_uri); |
| 94 | void xmlXPathRegisteredNsCleanup (xmlXPathContextPtr ctxt); |
| 95 | |
| 96 | int xmlXPathRegisterFunc (xmlXPathContextPtr ctxt, |
| 97 | const xmlChar *name, |
| 98 | xmlXPathFunction f); |
| 99 | int xmlXPathRegisterFuncNS (xmlXPathContextPtr ctxt, |
| 100 | const xmlChar *name, |
| 101 | const xmlChar *ns_uri, |
| 102 | xmlXPathFunction f); |
| 103 | int xmlXPathRegisterVariable (xmlXPathContextPtr ctxt, |
| 104 | const xmlChar *name, |
| 105 | xmlXPathObjectPtr value); |
| 106 | int xmlXPathRegisterVariableNS (xmlXPathContextPtr ctxt, |
| 107 | const xmlChar *name, |
| 108 | const xmlChar *ns_uri, |
| 109 | xmlXPathObjectPtr value); |
| 110 | xmlXPathFunction xmlXPathFunctionLookup (xmlXPathContextPtr ctxt, |
| 111 | const xmlChar *name); |
| 112 | xmlXPathFunction xmlXPathFunctionLookupNS (xmlXPathContextPtr ctxt, |
| 113 | const xmlChar *name, |
| 114 | const xmlChar *ns_uri); |
| 115 | void xmlXPathRegisteredFuncsCleanup(xmlXPathContextPtr ctxt); |
| 116 | xmlXPathObjectPtr xmlXPathVariableLookup (xmlXPathContextPtr ctxt, |
| 117 | const xmlChar *name); |
| 118 | xmlXPathObjectPtr xmlXPathVariableLookupNS (xmlXPathContextPtr ctxt, |
| 119 | const xmlChar *name, |
| 120 | const xmlChar *ns_uri); |
| 121 | void xmlXPathRegisteredVariablesCleanup(xmlXPathContextPtr ctxt); |
| 122 | |
| 123 | /** |
| 124 | * Utilities to extend XPath |
| 125 | */ |
| 126 | xmlXPathParserContextPtr |
| 127 | xmlXPathNewParserContext (const xmlChar *str, |
| 128 | xmlXPathContextPtr ctxt); |
| 129 | void xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt); |
| 130 | |
| 131 | /* TODO: remap to xmlXPathValuePop and Push */ |
| 132 | xmlXPathObjectPtr valuePop (xmlXPathParserContextPtr ctxt); |
| 133 | int valuePush (xmlXPathParserContextPtr ctxt, |
| 134 | xmlXPathObjectPtr value); |
| 135 | |
| 136 | xmlXPathObjectPtr xmlXPathNewString (const xmlChar *val); |
| 137 | xmlXPathObjectPtr xmlXPathNewCString (const char *val); |
| 138 | xmlXPathObjectPtr xmlXPathNewFloat (double val); |
| 139 | xmlXPathObjectPtr xmlXPathNewBoolean (int val); |
| 140 | xmlXPathObjectPtr xmlXPathNewNodeSet (xmlNodePtr val); |
| 141 | xmlXPathObjectPtr xmlXPathNewValueTree (xmlNodePtr val); |
| 142 | void xmlXPathNodeSetAdd (xmlNodeSetPtr cur, |
| 143 | xmlNodePtr val); |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 144 | void xmlXPathNodeSetAddUnique (xmlNodeSetPtr cur, |
| 145 | xmlNodePtr val); |
| 146 | void xmlXPathNodeSetSort (xmlNodeSetPtr set); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 147 | |
| 148 | void xmlXPathIdFunction (xmlXPathParserContextPtr ctxt, |
| 149 | int nargs); |
| 150 | void xmlXPathRoot (xmlXPathParserContextPtr ctxt); |
| 151 | void xmlXPathEvalExpr (xmlXPathParserContextPtr ctxt); |
| 152 | xmlChar * xmlXPathParseName (xmlXPathParserContextPtr ctxt); |
| 153 | xmlChar * xmlXPathParseNCName (xmlXPathParserContextPtr ctxt); |
| 154 | |
| 155 | /* |
| 156 | * Debug |
| 157 | */ |
| 158 | #ifdef LIBXML_DEBUG_ENABLED |
| 159 | double xmlXPathStringEvalNumber(const xmlChar *str); |
| 160 | void xmlXPathDebugDumpObject(FILE *output, xmlXPathObjectPtr cur, int depth); |
| 161 | #endif |
| 162 | /* |
| 163 | * Existing functions |
| 164 | */ |
| 165 | |
| 166 | int xmlXPathEvaluatePredicateResult(xmlXPathParserContextPtr ctxt, |
| 167 | xmlXPathObjectPtr res); |
| 168 | void xmlXPathInit(void); |
| 169 | void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 170 | void xmlXPathRegisterAllFunctions(xmlXPathContextPtr ctxt); |
| 171 | xmlNodeSetPtr xmlXPathNodeSetCreate(xmlNodePtr val); |
| 172 | void xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val); |
| 173 | xmlNodeSetPtr xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr val2); |
| 174 | void xmlXPathNodeSetDel(xmlNodeSetPtr cur, xmlNodePtr val); |
| 175 | void xmlXPathNodeSetRemove(xmlNodeSetPtr cur, int val); |
| 176 | void xmlXPathFreeNodeSet(xmlNodeSetPtr obj); |
| 177 | xmlXPathObjectPtr xmlXPathNewNodeSet(xmlNodePtr val); |
| 178 | xmlXPathObjectPtr xmlXPathNewNodeSetList(xmlNodeSetPtr val); |
| 179 | xmlXPathObjectPtr xmlXPathWrapNodeSet(xmlNodeSetPtr val); |
| 180 | void xmlXPathFreeNodeSetList(xmlXPathObjectPtr obj); |
| 181 | |
| 182 | |
| 183 | xmlXPathObjectPtr xmlXPathNewFloat(double val); |
| 184 | xmlXPathObjectPtr xmlXPathNewBoolean(int val); |
| 185 | xmlXPathObjectPtr xmlXPathNewString(const xmlChar *val); |
| 186 | xmlXPathObjectPtr xmlXPathNewCString(const char *val); |
| 187 | void xmlXPathFreeObject(xmlXPathObjectPtr obj); |
| 188 | xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc); |
| 189 | void xmlXPathFreeContext(xmlXPathContextPtr ctxt); |
| 190 | |
| 191 | int xmlXPathEqualValues(xmlXPathParserContextPtr ctxt); |
| 192 | int xmlXPathCompareValues(xmlXPathParserContextPtr ctxt, int inf, int strict); |
| 193 | void xmlXPathValueFlipSign(xmlXPathParserContextPtr ctxt); |
| 194 | void xmlXPathAddValues(xmlXPathParserContextPtr ctxt); |
| 195 | void xmlXPathSubValues(xmlXPathParserContextPtr ctxt); |
| 196 | void xmlXPathMultValues(xmlXPathParserContextPtr ctxt); |
| 197 | void xmlXPathDivValues(xmlXPathParserContextPtr ctxt); |
| 198 | void xmlXPathModValues(xmlXPathParserContextPtr ctxt); |
| 199 | |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 200 | int xmlXPathIsNodeType(const xmlChar *name); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * Some of the axis navigation routines |
| 204 | */ |
Daniel Veillard | 56a4cb8 | 2001-03-24 17:00:36 +0000 | [diff] [blame] | 205 | xmlNodePtr xmlXPathNextSelf(xmlXPathParserContextPtr ctxt, |
| 206 | xmlNodePtr cur); |
| 207 | xmlNodePtr xmlXPathNextChild(xmlXPathParserContextPtr ctxt, |
| 208 | xmlNodePtr cur); |
| 209 | xmlNodePtr xmlXPathNextDescendant(xmlXPathParserContextPtr ctxt, |
| 210 | xmlNodePtr cur); |
| 211 | xmlNodePtr xmlXPathNextDescendantOrSelf(xmlXPathParserContextPtr ctxt, |
| 212 | xmlNodePtr cur); |
| 213 | xmlNodePtr xmlXPathNextParent(xmlXPathParserContextPtr ctxt, |
| 214 | xmlNodePtr cur); |
| 215 | xmlNodePtr xmlXPathNextAncestorOrSelf(xmlXPathParserContextPtr ctxt, |
| 216 | xmlNodePtr cur); |
| 217 | xmlNodePtr xmlXPathNextFollowingSibling(xmlXPathParserContextPtr ctxt, |
| 218 | xmlNodePtr cur); |
| 219 | xmlNodePtr xmlXPathNextFollowing(xmlXPathParserContextPtr ctxt, |
| 220 | xmlNodePtr cur); |
| 221 | xmlNodePtr xmlXPathNextNamespace(xmlXPathParserContextPtr ctxt, |
| 222 | xmlNodePtr cur); |
| 223 | xmlNodePtr xmlXPathNextAttribute(xmlXPathParserContextPtr ctxt, |
| 224 | xmlNodePtr cur); |
| 225 | xmlNodePtr xmlXPathNextPreceding(xmlXPathParserContextPtr ctxt, |
| 226 | xmlNodePtr cur); |
| 227 | xmlNodePtr xmlXPathNextAncestor(xmlXPathParserContextPtr ctxt, |
| 228 | xmlNodePtr cur); |
| 229 | xmlNodePtr xmlXPathNextPrecedingSibling(xmlXPathParserContextPtr ctxt, |
| 230 | xmlNodePtr cur); |
Owen Taylor | 3473f88 | 2001-02-23 17:55:21 +0000 | [diff] [blame] | 231 | /* |
| 232 | * The official core of XPath functions |
| 233 | */ |
| 234 | void xmlXPathRoot(xmlXPathParserContextPtr ctxt); |
| 235 | void xmlXPathLastFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 236 | void xmlXPathPositionFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 237 | void xmlXPathCountFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 238 | void xmlXPathIdFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 239 | void xmlXPathLocalNameFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 240 | void xmlXPathNamespaceURIFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 241 | void xmlXPathStringFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 242 | void xmlXPathStringLengthFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 243 | void xmlXPathConcatFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 244 | void xmlXPathContainsFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 245 | void xmlXPathStartsWithFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 246 | void xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 247 | void xmlXPathSubstringBeforeFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 248 | void xmlXPathSubstringAfterFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 249 | void xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 250 | void xmlXPathTranslateFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 251 | void xmlXPathNotFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 252 | void xmlXPathTrueFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 253 | void xmlXPathFalseFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 254 | void xmlXPathLangFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 255 | void xmlXPathNumberFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 256 | void xmlXPathSumFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 257 | void xmlXPathFloorFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 258 | void xmlXPathCeilingFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 259 | void xmlXPathRoundFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 260 | void xmlXPathBooleanFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 261 | #ifdef __cplusplus |
| 262 | } |
| 263 | #endif |
| 264 | #endif /* ! __XML_XPATH_INTERNALS_H__ */ |