version 1.1.1.1, 2012/02/21 23:37:58
|
version 1.1.1.2, 2013/07/22 01:22:22
|
Line 252 static const char *xmlXPathErrorMessages[] = {
|
Line 252 static const char *xmlXPathErrorMessages[] = {
|
"Encoding error\n", |
"Encoding error\n", |
"Char out of XML range\n", |
"Char out of XML range\n", |
"Invalid or incomplete context\n", |
"Invalid or incomplete context\n", |
|
"Stack usage errror\n", |
"?? Unknown error ??\n" /* Must be last in the list! */ |
"?? Unknown error ??\n" /* Must be last in the list! */ |
}; |
}; |
#define MAXERRNO ((int)(sizeof(xmlXPathErrorMessages) / \ |
#define MAXERRNO ((int)(sizeof(xmlXPathErrorMessages) / \ |
Line 2398 xmlXPathCacheConvertNumber(xmlXPathContextPtr ctxt, xm
|
Line 2399 xmlXPathCacheConvertNumber(xmlXPathContextPtr ctxt, xm
|
************************************************************************/ |
************************************************************************/ |
|
|
/** |
/** |
|
* xmlXPathSetFrame: |
|
* @ctxt: an XPath parser context |
|
* |
|
* Set the callee evaluation frame |
|
* |
|
* Returns the previous frame value to be restored once done |
|
*/ |
|
static int |
|
xmlXPathSetFrame(xmlXPathParserContextPtr ctxt) { |
|
int ret; |
|
|
|
if (ctxt == NULL) |
|
return(0); |
|
ret = ctxt->valueFrame; |
|
ctxt->valueFrame = ctxt->valueNr; |
|
return(ret); |
|
} |
|
|
|
/** |
|
* xmlXPathPopFrame: |
|
* @ctxt: an XPath parser context |
|
* @frame: the previous frame value |
|
* |
|
* Remove the callee evaluation frame |
|
*/ |
|
static void |
|
xmlXPathPopFrame(xmlXPathParserContextPtr ctxt, int frame) { |
|
if (ctxt == NULL) |
|
return; |
|
if (ctxt->valueNr < ctxt->valueFrame) { |
|
xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_STACK_ERROR); |
|
} |
|
ctxt->valueFrame = frame; |
|
} |
|
|
|
/** |
* valuePop: |
* valuePop: |
* @ctxt: an XPath evaluation context |
* @ctxt: an XPath evaluation context |
* |
* |
Line 2412 valuePop(xmlXPathParserContextPtr ctxt)
|
Line 2449 valuePop(xmlXPathParserContextPtr ctxt)
|
|
|
if ((ctxt == NULL) || (ctxt->valueNr <= 0)) |
if ((ctxt == NULL) || (ctxt->valueNr <= 0)) |
return (NULL); |
return (NULL); |
|
|
|
if (ctxt->valueNr <= ctxt->valueFrame) { |
|
xmlXPatherror(ctxt, __FILE__, __LINE__, XPATH_STACK_ERROR); |
|
return (NULL); |
|
} |
|
|
ctxt->valueNr--; |
ctxt->valueNr--; |
if (ctxt->valueNr > 0) |
if (ctxt->valueNr > 0) |
ctxt->value = ctxt->valueTab[ctxt->valueNr - 1]; |
ctxt->value = ctxt->valueTab[ctxt->valueNr - 1]; |
Line 2442 valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjec
|
Line 2485 valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjec
|
sizeof(ctxt->valueTab[0])); |
sizeof(ctxt->valueTab[0])); |
if (tmp == NULL) { |
if (tmp == NULL) { |
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n"); |
xmlGenericError(xmlGenericErrorContext, "realloc failed !\n"); |
|
ctxt->error = XPATH_MEMORY_ERROR; |
return (0); |
return (0); |
} |
} |
ctxt->valueMax *= 2; |
ctxt->valueMax *= 2; |
Line 3522 xmlXPathNodeSetAddNs(xmlNodeSetPtr cur, xmlNodePtr nod
|
Line 3566 xmlXPathNodeSetAddNs(xmlNodeSetPtr cur, xmlNodePtr nod
|
} else if (cur->nodeNr == cur->nodeMax) { |
} else if (cur->nodeNr == cur->nodeMax) { |
xmlNodePtr *temp; |
xmlNodePtr *temp; |
|
|
cur->nodeMax *= 2; | temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * |
temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * | |
sizeof(xmlNodePtr)); |
sizeof(xmlNodePtr)); |
if (temp == NULL) { |
if (temp == NULL) { |
xmlXPathErrMemory(NULL, "growing nodeset\n"); |
xmlXPathErrMemory(NULL, "growing nodeset\n"); |
return; |
return; |
} |
} |
|
cur->nodeMax *= 2; |
cur->nodeTab = temp; |
cur->nodeTab = temp; |
} |
} |
cur->nodeTab[cur->nodeNr++] = xmlXPathNodeSetDupNs(node, ns); |
cur->nodeTab[cur->nodeNr++] = xmlXPathNodeSetDupNs(node, ns); |
Line 3575 xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val)
|
Line 3619 xmlXPathNodeSetAdd(xmlNodeSetPtr cur, xmlNodePtr val)
|
} else if (cur->nodeNr == cur->nodeMax) { |
} else if (cur->nodeNr == cur->nodeMax) { |
xmlNodePtr *temp; |
xmlNodePtr *temp; |
|
|
cur->nodeMax *= 2; | temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * |
temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * | |
sizeof(xmlNodePtr)); |
sizeof(xmlNodePtr)); |
if (temp == NULL) { |
if (temp == NULL) { |
xmlXPathErrMemory(NULL, "growing nodeset\n"); |
xmlXPathErrMemory(NULL, "growing nodeset\n"); |
return; |
return; |
} |
} |
|
cur->nodeMax *= 2; |
cur->nodeTab = temp; |
cur->nodeTab = temp; |
} |
} |
if (val->type == XML_NAMESPACE_DECL) { |
if (val->type == XML_NAMESPACE_DECL) { |
Line 3627 xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr
|
Line 3671 xmlXPathNodeSetAddUnique(xmlNodeSetPtr cur, xmlNodePtr
|
} else if (cur->nodeNr == cur->nodeMax) { |
} else if (cur->nodeNr == cur->nodeMax) { |
xmlNodePtr *temp; |
xmlNodePtr *temp; |
|
|
cur->nodeMax *= 2; | temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * 2 * |
temp = (xmlNodePtr *) xmlRealloc(cur->nodeTab, cur->nodeMax * | |
sizeof(xmlNodePtr)); |
sizeof(xmlNodePtr)); |
if (temp == NULL) { |
if (temp == NULL) { |
xmlXPathErrMemory(NULL, "growing nodeset\n"); |
xmlXPathErrMemory(NULL, "growing nodeset\n"); |
return; |
return; |
} |
} |
cur->nodeTab = temp; |
cur->nodeTab = temp; |
|
cur->nodeMax *= 2; |
} |
} |
if (val->type == XML_NAMESPACE_DECL) { |
if (val->type == XML_NAMESPACE_DECL) { |
xmlNsPtr ns = (xmlNsPtr) val; |
xmlNsPtr ns = (xmlNsPtr) val; |
Line 3738 xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr
|
Line 3782 xmlXPathNodeSetMerge(xmlNodeSetPtr val1, xmlNodeSetPtr
|
} else if (val1->nodeNr == val1->nodeMax) { |
} else if (val1->nodeNr == val1->nodeMax) { |
xmlNodePtr *temp; |
xmlNodePtr *temp; |
|
|
val1->nodeMax *= 2; | temp = (xmlNodePtr *) xmlRealloc(val1->nodeTab, val1->nodeMax * 2 * |
temp = (xmlNodePtr *) xmlRealloc(val1->nodeTab, val1->nodeMax * | |
sizeof(xmlNodePtr)); |
sizeof(xmlNodePtr)); |
if (temp == NULL) { |
if (temp == NULL) { |
xmlXPathErrMemory(NULL, "merging nodeset\n"); |
xmlXPathErrMemory(NULL, "merging nodeset\n"); |
return(NULL); |
return(NULL); |
} |
} |
val1->nodeTab = temp; |
val1->nodeTab = temp; |
|
val1->nodeMax *= 2; |
} |
} |
if (n2->type == XML_NAMESPACE_DECL) { |
if (n2->type == XML_NAMESPACE_DECL) { |
xmlNsPtr ns = (xmlNsPtr) n2; |
xmlNsPtr ns = (xmlNsPtr) n2; |
Line 3907 xmlXPathNodeSetMergeAndClear(xmlNodeSetPtr set1, xmlNo
|
Line 3951 xmlXPathNodeSetMergeAndClear(xmlNodeSetPtr set1, xmlNo
|
} else if (set1->nodeNr >= set1->nodeMax) { |
} else if (set1->nodeNr >= set1->nodeMax) { |
xmlNodePtr *temp; |
xmlNodePtr *temp; |
|
|
set1->nodeMax *= 2; |
|
temp = (xmlNodePtr *) xmlRealloc( |
temp = (xmlNodePtr *) xmlRealloc( |
set1->nodeTab, set1->nodeMax * sizeof(xmlNodePtr)); | set1->nodeTab, set1->nodeMax * 2 * sizeof(xmlNodePtr)); |
if (temp == NULL) { |
if (temp == NULL) { |
xmlXPathErrMemory(NULL, "merging nodeset\n"); |
xmlXPathErrMemory(NULL, "merging nodeset\n"); |
return(NULL); |
return(NULL); |
} |
} |
set1->nodeTab = temp; |
set1->nodeTab = temp; |
|
set1->nodeMax *= 2; |
} |
} |
if (n2->type == XML_NAMESPACE_DECL) { |
if (n2->type == XML_NAMESPACE_DECL) { |
xmlNsPtr ns = (xmlNsPtr) n2; |
xmlNsPtr ns = (xmlNsPtr) n2; |
Line 3991 xmlXPathNodeSetMergeAndClearNoDupls(xmlNodeSetPtr set1
|
Line 4035 xmlXPathNodeSetMergeAndClearNoDupls(xmlNodeSetPtr set1
|
} else if (set1->nodeNr >= set1->nodeMax) { |
} else if (set1->nodeNr >= set1->nodeMax) { |
xmlNodePtr *temp; |
xmlNodePtr *temp; |
|
|
set1->nodeMax *= 2; |
|
temp = (xmlNodePtr *) xmlRealloc( |
temp = (xmlNodePtr *) xmlRealloc( |
set1->nodeTab, set1->nodeMax * sizeof(xmlNodePtr)); | set1->nodeTab, set1->nodeMax * 2 * sizeof(xmlNodePtr)); |
if (temp == NULL) { |
if (temp == NULL) { |
xmlXPathErrMemory(NULL, "merging nodeset\n"); |
xmlXPathErrMemory(NULL, "merging nodeset\n"); |
return(NULL); |
return(NULL); |
} |
} |
set1->nodeTab = temp; |
set1->nodeTab = temp; |
|
set1->nodeMax *= 2; |
} |
} |
set1->nodeTab[set1->nodeNr++] = n2; |
set1->nodeTab[set1->nodeNr++] = n2; |
} |
} |
Line 6154 xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xm
|
Line 6198 xmlXPathCompParserContext(xmlXPathCompExprPtr comp, xm
|
ret->valueNr = 0; |
ret->valueNr = 0; |
ret->valueMax = 10; |
ret->valueMax = 10; |
ret->value = NULL; |
ret->value = NULL; |
|
ret->valueFrame = 0; |
|
|
ret->context = ctxt; |
ret->context = ctxt; |
ret->comp = comp; |
ret->comp = comp; |
Line 9296 xmlXPathTranslateFunction(xmlXPathParserContextPtr ctx
|
Line 9341 xmlXPathTranslateFunction(xmlXPathParserContextPtr ctx
|
if ( (ch & 0xc0) != 0xc0 ) { |
if ( (ch & 0xc0) != 0xc0 ) { |
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"xmlXPathTranslateFunction: Invalid UTF8 string\n"); |
"xmlXPathTranslateFunction: Invalid UTF8 string\n"); |
|
/* not asserting an XPath error is probably better */ |
break; |
break; |
} |
} |
/* then skip over remaining bytes for this char */ |
/* then skip over remaining bytes for this char */ |
Line 9303 xmlXPathTranslateFunction(xmlXPathParserContextPtr ctx
|
Line 9349 xmlXPathTranslateFunction(xmlXPathParserContextPtr ctx
|
if ( (*cptr++ & 0xc0) != 0x80 ) { |
if ( (*cptr++ & 0xc0) != 0x80 ) { |
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"xmlXPathTranslateFunction: Invalid UTF8 string\n"); |
"xmlXPathTranslateFunction: Invalid UTF8 string\n"); |
|
/* not asserting an XPath error is probably better */ |
break; |
break; |
} |
} |
if (ch & 0x80) /* must have had error encountered */ |
if (ch & 0x80) /* must have had error encountered */ |
Line 10044 static void
|
Line 10091 static void
|
xmlXPathCompNumber(xmlXPathParserContextPtr ctxt) |
xmlXPathCompNumber(xmlXPathParserContextPtr ctxt) |
{ |
{ |
double ret = 0.0; |
double ret = 0.0; |
double mult = 1; |
|
int ok = 0; |
int ok = 0; |
int exponent = 0; |
int exponent = 0; |
int is_exponent_negative = 0; |
int is_exponent_negative = 0; |
Line 11712 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserCo
|
Line 11758 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserCo
|
xmlXPathObjectPtr contextObj = NULL, exprRes = NULL; |
xmlXPathObjectPtr contextObj = NULL, exprRes = NULL; |
xmlNodePtr oldContextNode, contextNode = NULL; |
xmlNodePtr oldContextNode, contextNode = NULL; |
xmlXPathContextPtr xpctxt = ctxt->context; |
xmlXPathContextPtr xpctxt = ctxt->context; |
|
int frame; |
|
|
#ifdef LIBXML_XPTR_ENABLED |
#ifdef LIBXML_XPTR_ENABLED |
/* |
/* |
Line 11731 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserCo
|
Line 11778 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserCo
|
*/ |
*/ |
exprOp = &ctxt->comp->steps[op->ch2]; |
exprOp = &ctxt->comp->steps[op->ch2]; |
for (i = 0; i < set->nodeNr; i++) { |
for (i = 0; i < set->nodeNr; i++) { |
|
xmlXPathObjectPtr tmp; |
|
|
if (set->nodeTab[i] == NULL) |
if (set->nodeTab[i] == NULL) |
continue; |
continue; |
|
|
Line 11758 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserCo
|
Line 11807 xmlXPathCompOpEvalPositionalPredicate(xmlXPathParserCo
|
xmlXPathNodeSetAddUnique(contextObj->nodesetval, |
xmlXPathNodeSetAddUnique(contextObj->nodesetval, |
contextNode); |
contextNode); |
|
|
|
frame = xmlXPathSetFrame(ctxt); |
valuePush(ctxt, contextObj); |
valuePush(ctxt, contextObj); |
res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp, 1); |
res = xmlXPathCompOpEvalToBoolean(ctxt, exprOp, 1); |
|
tmp = valuePop(ctxt); |
|
xmlXPathPopFrame(ctxt, frame); |
|
|
if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1)) { |
if ((ctxt->error != XPATH_EXPRESSION_OK) || (res == -1)) { |
xmlXPathObjectPtr tmp; | while (tmp != contextObj) { |
/* pop the result */ | /* |
tmp = valuePop(ctxt); | * Free up the result |
xmlXPathReleaseObject(xpctxt, tmp); | * then pop off contextObj, which will be freed later |
/* then pop off contextObj, which will be freed later */ | */ |
valuePop(ctxt); | xmlXPathReleaseObject(xpctxt, tmp); |
| tmp = valuePop(ctxt); |
| } |
goto evaluation_error; |
goto evaluation_error; |
} |
} |
|
/* push the result back onto the stack */ |
|
valuePush(ctxt, tmp); |
|
|
if (res) |
if (res) |
pos++; |
pos++; |
Line 13357 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
Line 13413 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"xmlXPathCompOpEval: variable %s bound to undefined prefix %s\n", |
"xmlXPathCompOpEval: variable %s bound to undefined prefix %s\n", |
(char *) op->value4, (char *)op->value5); |
(char *) op->value4, (char *)op->value5); |
|
ctxt->error = XPATH_UNDEF_PREFIX_ERROR; |
return (total); |
return (total); |
} |
} |
val = xmlXPathVariableLookupNS(ctxt->context, |
val = xmlXPathVariableLookupNS(ctxt->context, |
Line 13373 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
Line 13430 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
xmlXPathFunction func; |
xmlXPathFunction func; |
const xmlChar *oldFunc, *oldFuncURI; |
const xmlChar *oldFunc, *oldFuncURI; |
int i; |
int i; |
|
int frame; |
|
|
|
frame = xmlXPathSetFrame(ctxt); |
if (op->ch1 != -1) |
if (op->ch1 != -1) |
total += |
total += |
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); |
xmlXPathCompOpEval(ctxt, &comp->steps[op->ch1]); |
Line 13381 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
Line 13440 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"xmlXPathCompOpEval: parameter error\n"); |
"xmlXPathCompOpEval: parameter error\n"); |
ctxt->error = XPATH_INVALID_OPERAND; |
ctxt->error = XPATH_INVALID_OPERAND; |
|
xmlXPathPopFrame(ctxt, frame); |
return (total); |
return (total); |
} |
} |
for (i = 0; i < op->value; i++) | for (i = 0; i < op->value; i++) { |
if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) { |
if (ctxt->valueTab[(ctxt->valueNr - 1) - i] == NULL) { |
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"xmlXPathCompOpEval: parameter error\n"); |
"xmlXPathCompOpEval: parameter error\n"); |
ctxt->error = XPATH_INVALID_OPERAND; |
ctxt->error = XPATH_INVALID_OPERAND; |
|
xmlXPathPopFrame(ctxt, frame); |
return (total); |
return (total); |
} |
} |
|
} |
if (op->cache != NULL) |
if (op->cache != NULL) |
XML_CAST_FPTR(func) = op->cache; |
XML_CAST_FPTR(func) = op->cache; |
else { |
else { |
Line 13405 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
Line 13467 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"xmlXPathCompOpEval: function %s bound to undefined prefix %s\n", |
"xmlXPathCompOpEval: function %s bound to undefined prefix %s\n", |
(char *)op->value4, (char *)op->value5); |
(char *)op->value4, (char *)op->value5); |
|
xmlXPathPopFrame(ctxt, frame); |
|
ctxt->error = XPATH_UNDEF_PREFIX_ERROR; |
return (total); |
return (total); |
} |
} |
func = xmlXPathFunctionLookupNS(ctxt->context, |
func = xmlXPathFunctionLookupNS(ctxt->context, |
Line 13426 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
Line 13490 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
func(ctxt, op->value); |
func(ctxt, op->value); |
ctxt->context->function = oldFunc; |
ctxt->context->function = oldFunc; |
ctxt->context->functionURI = oldFuncURI; |
ctxt->context->functionURI = oldFuncURI; |
|
xmlXPathPopFrame(ctxt, frame); |
return (total); |
return (total); |
} |
} |
case XPATH_OP_ARG: |
case XPATH_OP_ARG: |
Line 13982 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
Line 14047 xmlXPathCompOpEval(xmlXPathParserContextPtr ctxt, xmlX
|
} |
} |
xmlGenericError(xmlGenericErrorContext, |
xmlGenericError(xmlGenericErrorContext, |
"XPath: unknown precompiled operation %d\n", op->op); |
"XPath: unknown precompiled operation %d\n", op->op); |
|
ctxt->error = XPATH_INVALID_OPERAND; |
return (total); |
return (total); |
} |
} |
|
|
Line 14329 xmlXPathRunEval(xmlXPathParserContextPtr ctxt, int toB
|
Line 14395 xmlXPathRunEval(xmlXPathParserContextPtr ctxt, int toB
|
ctxt->valueNr = 0; |
ctxt->valueNr = 0; |
ctxt->valueMax = 10; |
ctxt->valueMax = 10; |
ctxt->value = NULL; |
ctxt->value = NULL; |
|
ctxt->valueFrame = 0; |
} |
} |
#ifdef XPATH_STREAMING |
#ifdef XPATH_STREAMING |
if (ctxt->comp->stream) { |
if (ctxt->comp->stream) { |