| OLD | NEW |
| 1 /* | 1 /* |
| 2 * xpath.c: XML Path Language implementation | 2 * xpath.c: XML Path Language implementation |
| 3 * XPath is a language for addressing parts of an XML document, | 3 * XPath is a language for addressing parts of an XML document, |
| 4 * designed to be used by both XSLT and XPointer | 4 * designed to be used by both XSLT and XPointer |
| 5 *f | 5 *f |
| 6 * Reference: W3C Recommendation 16 November 1999 | 6 * Reference: W3C Recommendation 16 November 1999 |
| 7 * http://www.w3.org/TR/1999/REC-xpath-19991116 | 7 * http://www.w3.org/TR/1999/REC-xpath-19991116 |
| 8 * Public reference: | 8 * Public reference: |
| 9 * http://www.w3.org/TR/xpath | 9 * http://www.w3.org/TR/xpath |
| 10 * | 10 * |
| (...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 928 typedef xmlXPathStepOp *xmlXPathStepOpPtr; | 928 typedef xmlXPathStepOp *xmlXPathStepOpPtr; |
| 929 struct _xmlXPathStepOp { | 929 struct _xmlXPathStepOp { |
| 930 xmlXPathOp op; /* The identifier of the operation */ | 930 xmlXPathOp op; /* The identifier of the operation */ |
| 931 int ch1; /* First child */ | 931 int ch1; /* First child */ |
| 932 int ch2; /* Second child */ | 932 int ch2; /* Second child */ |
| 933 int value; | 933 int value; |
| 934 int value2; | 934 int value2; |
| 935 int value3; | 935 int value3; |
| 936 void *value4; | 936 void *value4; |
| 937 void *value5; | 937 void *value5; |
| 938 void *cache; | 938 xmlXPathFunction cache; |
| 939 void *cacheURI; | 939 void *cacheURI; |
| 940 }; | 940 }; |
| 941 | 941 |
| 942 struct _xmlXPathCompExpr { | 942 struct _xmlXPathCompExpr { |
| 943 int nbStep; /* Number of steps in this expression */ | 943 int nbStep; /* Number of steps in this expression */ |
| 944 int maxStep; /* Maximum number of steps allocated */ | 944 int maxStep; /* Maximum number of steps allocated */ |
| 945 xmlXPathStepOp *steps; /* ops for computation of this expression */ | 945 xmlXPathStepOp *steps; /* ops for computation of this expression */ |
| 946 int last; /* index of last step in expression */ | 946 int last; /* index of last step in expression */ |
| 947 xmlChar *expr; /* the expression being computed */ | 947 xmlChar *expr; /* the expression being computed */ |
| 948 xmlDictPtr dict; /* the dictionary to use if any */ | 948 xmlDictPtr dict; /* the dictionary to use if any */ |
| (...skipping 2386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3335 if (l1 < l2) | 3335 if (l1 < l2) |
| 3336 return(1); | 3336 return(1); |
| 3337 if (l1 > l2) | 3337 if (l1 > l2) |
| 3338 return(-1); | 3338 return(-1); |
| 3339 } | 3339 } |
| 3340 | 3340 |
| 3341 /* | 3341 /* |
| 3342 * compute depth to root | 3342 * compute depth to root |
| 3343 */ | 3343 */ |
| 3344 for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) { | 3344 for (depth2 = 0, cur = node2;cur->parent != NULL;cur = cur->parent) { |
| 3345 » if (cur == node1) | 3345 » if (cur->parent == node1) |
| 3346 return(1); | 3346 return(1); |
| 3347 depth2++; | 3347 depth2++; |
| 3348 } | 3348 } |
| 3349 root = cur; | 3349 root = cur; |
| 3350 for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) { | 3350 for (depth1 = 0, cur = node1;cur->parent != NULL;cur = cur->parent) { |
| 3351 » if (cur == node2) | 3351 » if (cur->parent == node2) |
| 3352 return(-1); | 3352 return(-1); |
| 3353 depth1++; | 3353 depth1++; |
| 3354 } | 3354 } |
| 3355 /* | 3355 /* |
| 3356 * Distinct document (or distinct entities :-( ) case. | 3356 * Distinct document (or distinct entities :-( ) case. |
| 3357 */ | 3357 */ |
| 3358 if (root != cur) { | 3358 if (root != cur) { |
| 3359 return(-2); | 3359 return(-2); |
| 3360 } | 3360 } |
| 3361 /* | 3361 /* |
| (...skipping 7329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10691 lc = 1; | 10691 lc = 1; |
| 10692 break; | 10692 break; |
| 10693 } else if ((NXT(len) == '(')) { | 10693 } else if ((NXT(len) == '(')) { |
| 10694 /* Node Type or Function */ | 10694 /* Node Type or Function */ |
| 10695 if (xmlXPathIsNodeType(name)) { | 10695 if (xmlXPathIsNodeType(name)) { |
| 10696 #ifdef DEBUG_STEP | 10696 #ifdef DEBUG_STEP |
| 10697 xmlGenericError(xmlGenericErrorContext, | 10697 xmlGenericError(xmlGenericErrorContext, |
| 10698 "PathExpr: Type search\n"); | 10698 "PathExpr: Type search\n"); |
| 10699 #endif | 10699 #endif |
| 10700 lc = 1; | 10700 lc = 1; |
| 10701 #ifdef LIBXML_XPTR_ENABLED |
| 10701 } else if (ctxt->xptr && | 10702 } else if (ctxt->xptr && |
| 10702 xmlStrEqual(name, BAD_CAST "range-to")) { | 10703 xmlStrEqual(name, BAD_CAST "range-to")) { |
| 10703 lc = 1; | 10704 lc = 1; |
| 10705 #endif |
| 10704 } else { | 10706 } else { |
| 10705 #ifdef DEBUG_STEP | 10707 #ifdef DEBUG_STEP |
| 10706 xmlGenericError(xmlGenericErrorContext, | 10708 xmlGenericError(xmlGenericErrorContext, |
| 10707 "PathExpr: function call\n"); | 10709 "PathExpr: function call\n"); |
| 10708 #endif | 10710 #endif |
| 10709 lc = 0; | 10711 lc = 0; |
| 10710 } | 10712 } |
| 10711 break; | 10713 break; |
| 10712 } else if ((NXT(len) == '[')) { | 10714 } else if ((NXT(len) == '[')) { |
| 10713 /* element name */ | 10715 /* element name */ |
| (...skipping 2842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13556 for (i = 0; i < op->value; i++) { | 13558 for (i = 0; i < op->value; i++) { |
| 13557 if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) { | 13559 if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) { |
| 13558 xmlGenericError(xmlGenericErrorContext, | 13560 xmlGenericError(xmlGenericErrorContext, |
| 13559 "xmlXPathCompOpEval: parameter error\n"); | 13561 "xmlXPathCompOpEval: parameter error\n"); |
| 13560 ctxt->error = XPATH_INVALID_OPERAND; | 13562 ctxt->error = XPATH_INVALID_OPERAND; |
| 13561 xmlXPathPopFrame(ctxt, frame); | 13563 xmlXPathPopFrame(ctxt, frame); |
| 13562 return (total); | 13564 return (total); |
| 13563 } | 13565 } |
| 13564 } | 13566 } |
| 13565 if (op->cache != NULL) | 13567 if (op->cache != NULL) |
| 13566 XML_CAST_FPTR(func) = op->cache; | 13568 func = op->cache; |
| 13567 else { | 13569 else { |
| 13568 const xmlChar *URI = NULL; | 13570 const xmlChar *URI = NULL; |
| 13569 | 13571 |
| 13570 if (op->value5 == NULL) | 13572 if (op->value5 == NULL) |
| 13571 func = | 13573 func = |
| 13572 xmlXPathFunctionLookup(ctxt->context, | 13574 xmlXPathFunctionLookup(ctxt->context, |
| 13573 op->value4); | 13575 op->value4); |
| 13574 else { | 13576 else { |
| 13575 URI = xmlXPathNsLookup(ctxt->context, op->value5); | 13577 URI = xmlXPathNsLookup(ctxt->context, op->value5); |
| 13576 if (URI == NULL) { | 13578 if (URI == NULL) { |
| 13577 xmlGenericError(xmlGenericErrorContext, | 13579 xmlGenericError(xmlGenericErrorContext, |
| 13578 "xmlXPathCompOpEval: function %s bound to undefined prefix %s\n", | 13580 "xmlXPathCompOpEval: function %s bound to undefined prefix %s\n", |
| 13579 (char *)op->value4, (char *)op->value5); | 13581 (char *)op->value4, (char *)op->value5); |
| 13580 xmlXPathPopFrame(ctxt, frame); | 13582 xmlXPathPopFrame(ctxt, frame); |
| 13581 ctxt->error = XPATH_UNDEF_PREFIX_ERROR; | 13583 ctxt->error = XPATH_UNDEF_PREFIX_ERROR; |
| 13582 return (total); | 13584 return (total); |
| 13583 } | 13585 } |
| 13584 func = xmlXPathFunctionLookupNS(ctxt->context, | 13586 func = xmlXPathFunctionLookupNS(ctxt->context, |
| 13585 op->value4, URI); | 13587 op->value4, URI); |
| 13586 } | 13588 } |
| 13587 if (func == NULL) { | 13589 if (func == NULL) { |
| 13588 xmlGenericError(xmlGenericErrorContext, | 13590 xmlGenericError(xmlGenericErrorContext, |
| 13589 "xmlXPathCompOpEval: function %s not found\n", | 13591 "xmlXPathCompOpEval: function %s not found\n", |
| 13590 (char *)op->value4); | 13592 (char *)op->value4); |
| 13591 XP_ERROR0(XPATH_UNKNOWN_FUNC_ERROR); | 13593 XP_ERROR0(XPATH_UNKNOWN_FUNC_ERROR); |
| 13592 } | 13594 } |
| 13593 op->cache = XML_CAST_FPTR(func); | 13595 op->cache = func; |
| 13594 op->cacheURI = (void *) URI; | 13596 op->cacheURI = (void *) URI; |
| 13595 } | 13597 } |
| 13596 oldFunc = ctxt->context->function; | 13598 oldFunc = ctxt->context->function; |
| 13597 oldFuncURI = ctxt->context->functionURI; | 13599 oldFuncURI = ctxt->context->functionURI; |
| 13598 ctxt->context->function = op->value4; | 13600 ctxt->context->function = op->value4; |
| 13599 ctxt->context->functionURI = op->cacheURI; | 13601 ctxt->context->functionURI = op->cacheURI; |
| 13600 func(ctxt, op->value); | 13602 func(ctxt, op->value); |
| 13601 ctxt->context->function = oldFunc; | 13603 ctxt->context->function = oldFunc; |
| 13602 ctxt->context->functionURI = oldFuncURI; | 13604 ctxt->context->functionURI = oldFuncURI; |
| 13603 xmlXPathPopFrame(ctxt, frame); | 13605 xmlXPathPopFrame(ctxt, frame); |
| (...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15391 xmlXPathTranslateFunction); | 15393 xmlXPathTranslateFunction); |
| 15392 | 15394 |
| 15393 xmlXPathRegisterFuncNS(ctxt, (const xmlChar *)"escape-uri", | 15395 xmlXPathRegisterFuncNS(ctxt, (const xmlChar *)"escape-uri", |
| 15394 (const xmlChar *)"http://www.w3.org/2002/08/xquery-functions", | 15396 (const xmlChar *)"http://www.w3.org/2002/08/xquery-functions", |
| 15395 xmlXPathEscapeUriFunction); | 15397 xmlXPathEscapeUriFunction); |
| 15396 } | 15398 } |
| 15397 | 15399 |
| 15398 #endif /* LIBXML_XPATH_ENABLED */ | 15400 #endif /* LIBXML_XPATH_ENABLED */ |
| 15399 #define bottom_xpath | 15401 #define bottom_xpath |
| 15400 #include "elfgcchack.h" | 15402 #include "elfgcchack.h" |
| OLD | NEW |