*
* Added support for the element() scheme described in:
* W3C Proposed Recommendation 13 November 2002
- * http://www.w3.org/TR/2002/PR-xptr-element-20021113/
+ * http://www.w3.org/TR/2002/PR-xptr-element-20021113/
*
* See Copyright for the status of this software.
*
#endif
#endif
-#define TODO \
+#define TODO \
xmlGenericError(xmlGenericErrorContext, \
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
-#define STRANGE \
+#define STRANGE \
xmlGenericError(xmlGenericErrorContext, \
"Internal error at %s:%d\n", \
__FILE__, __LINE__);
/************************************************************************
* *
- * Some factorized error routines *
+ * Some factorized error routines *
* *
************************************************************************/
static int
xmlXPtrGetArity(xmlNodePtr cur) {
int i;
- if (cur == NULL)
+ if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
cur = cur->children;
for (i = 0;cur != NULL;cur = cur->next) {
static int
xmlXPtrGetIndex(xmlNodePtr cur) {
int i;
- if (cur == NULL)
+ if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
for (i = 1;cur != NULL;cur = cur->prev) {
if ((cur->type == XML_ELEMENT_NODE) ||
static xmlNodePtr
xmlXPtrGetNthChild(xmlNodePtr cur, int no) {
int i;
- if (cur == NULL)
+ if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(cur);
cur = cur->children;
for (i = 0;i <= no;cur = cur->next) {
- if (cur == NULL)
+ if (cur == NULL)
return(cur);
if ((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_DOCUMENT_NODE) ||
break;
case XPATH_NODESET:
/*
- * Empty set ...
+ * Empty set ...
*/
if (end->nodesetval->nodeNr <= 0)
return(NULL);
if (i >= cur->locNr) {
#ifdef DEBUG
- xmlGenericError(xmlGenericErrorContext,
+ xmlGenericError(xmlGenericErrorContext,
"xmlXPtrLocationSetDel: Range wasn't found in RangeList\n");
#endif
return;
#define NXT(val) ctxt->cur[(val)]
#define CUR_PTR ctxt->cur
-#define SKIP_BLANKS \
+#define SKIP_BLANKS \
while (IS_BLANK_CH(*(ctxt->cur))) NEXT
#define CURRENT (*ctxt->cur)
* xmlXPtrEvalXPtrPart:
* @ctxt: the XPointer Parser context
* @name: the preparsed Scheme for the XPtrPart
- *
+ *
* XPtrPart ::= 'xpointer' '(' XPtrExpr ')'
* | Scheme '(' SchemeSpecificExpr ')'
*
*
* SchemeSpecificExpr ::= StringWithBalancedParens
*
- * StringWithBalancedParens ::=
+ * StringWithBalancedParens ::=
* [^()]* ('(' StringWithBalancedParens ')' [^()]*)*
* [VC: Parenthesis escaping]
*
*
* Parse and evaluate an XPtrPart. Basically it generates the unescaped
* string and if the scheme is 'xpointer' it will call the XPath interpreter.
- *
+ *
* TODO: there is no new scheme registration mechanism
*/
xmlFree(name);
XP_ERROR(XPATH_MEMORY_ERROR);
}
-
+
xmlXPathRegisterNs(ctxt->context, prefix, URI);
CUR_PTR = left;
xmlFree(URI);
while (CUR == '/') {
int child = 0;
NEXT;
-
+
while ((CUR >= '0') && (CUR <= '9')) {
child = child * 10 + (CUR - '0');
NEXT;
xmlXPtrEvalXPointer(xmlXPathParserContextPtr ctxt) {
if (ctxt->valueTab == NULL) {
/* Allocate the value stack */
- ctxt->valueTab = (xmlXPathObjectPtr *)
+ ctxt->valueTab = (xmlXPathObjectPtr *)
xmlMalloc(10 * sizeof(xmlXPathObjectPtr));
if (ctxt->valueTab == NULL) {
xmlXPtrErrMemory("allocating evaluation context");
return(NULL);
ctxt = xmlXPathNewParserContext(str, ctx);
+ if (ctxt == NULL)
+ return(NULL);
ctxt->xptr = 1;
xmlXPtrEvalXPointer(ctxt);
/*
* Evaluation may push a root nodeset which is unused
*/
- xmlNodeSetPtr set;
+ xmlNodeSetPtr set;
set = tmp->nodesetval;
if ((set->nodeNr != 1) ||
(set->nodeTab[0] != (xmlNodePtr) ctx->doc))
stack++;
} else
- stack++;
+ stack++;
}
xmlXPathFreeObject(tmp);
}
xmlXPathFreeObject(res);
res = NULL;
}
-
+
xmlXPathFreeParserContext(ctxt);
return(res);
}
return(NULL);
start = (xmlNodePtr) range->user;
- if (start == NULL)
+ if ((start == NULL) || (start->type == XML_NAMESPACE_DECL))
return(NULL);
end = range->user2;
if (end == NULL)
return(xmlCopyNode(start, 1));
+ if (end->type == XML_NAMESPACE_DECL)
+ return(NULL);
cur = start;
index1 = range->index;
/* prune and return full set */
if (last != NULL)
xmlAddNextSibling(last, tmp);
- else
+ else
xmlAddChild(parent, tmp);
return(list);
} else {
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
- * Function implementing here() operation
+ * Function implementing here() operation
* as described in 5.4.3
*/
static void
if (ctxt->context->here == NULL)
XP_ERROR(XPTR_SYNTAX_ERROR);
-
+
valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->here, NULL));
}
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
- * Function implementing origin() operation
+ * Function implementing origin() operation
* as described in 5.4.3
*/
static void
if (ctxt->context->origin == NULL)
XP_ERROR(XPTR_SYNTAX_ERROR);
-
+
valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->origin, NULL));
}
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
- * Function implementing start-point() operation
+ * Function implementing start-point() operation
* as described in 5.4.3
* ----------------
* location-set start-point(location-set)
*/
tmp = xmlXPtrNewLocationSetNodeSet(obj->nodesetval);
xmlXPathFreeObject(obj);
+ if (tmp == NULL)
+ XP_ERROR(XPATH_MEMORY_ERROR)
obj = tmp;
}
* @ctxt: the XPointer Parser context
* @nargs: the number of args
*
- * Function implementing end-point() operation
+ * Function implementing end-point() operation
* as described in 5.4.3
* ----------------------------
* location-set end-point(location-set)
*/
tmp = xmlXPtrNewLocationSetNodeSet(obj->nodesetval);
xmlXPathFreeObject(obj);
+ if (tmp == NULL)
+ XP_ERROR(XPATH_MEMORY_ERROR)
obj = tmp;
}
newset = xmlXPtrLocationSetCreate(NULL);
+ if (newset == NULL) {
+ xmlXPathFreeObject(obj);
+ XP_ERROR(XPATH_MEMORY_ERROR);
+ }
oldset = (xmlLocationSetPtr) obj->user;
if (oldset != NULL) {
int i;
case XML_NOTATION_NODE:
case XML_HTML_DOCUMENT_NODE: {
int indx = xmlXPtrGetIndex(node);
-
+
node = node->parent;
return(xmlXPtrNewRange(node, indx - 1,
node, indx + 1));
*/
tmp = xmlXPtrNewLocationSetNodeSet(set->nodesetval);
xmlXPathFreeObject(set);
+ if (tmp == NULL)
+ XP_ERROR(XPATH_MEMORY_ERROR)
set = tmp;
}
oldset = (xmlLocationSetPtr) set->user;
* The loop is to compute the covering range for each item and add it
*/
newset = xmlXPtrLocationSetCreate(NULL);
+ if (newset == NULL) {
+ xmlXPathFreeObject(set);
+ XP_ERROR(XPATH_MEMORY_ERROR);
+ }
for (i = 0;i < oldset->locNr;i++) {
xmlXPtrLocationSetAdd(newset,
xmlXPtrCoveringRange(ctxt, oldset->locTab[i]));
*/
tmp = xmlXPtrNewLocationSetNodeSet(set->nodesetval);
xmlXPathFreeObject(set);
+ if (tmp == NULL)
+ XP_ERROR(XPATH_MEMORY_ERROR)
set = tmp;
}
oldset = (xmlLocationSetPtr) set->user;
* The loop is to compute the covering range for each item and add it
*/
newset = xmlXPtrLocationSetCreate(NULL);
+ if (newset == NULL) {
+ xmlXPathFreeObject(set);
+ XP_ERROR(XPATH_MEMORY_ERROR);
+ }
for (i = 0;i < oldset->locNr;i++) {
xmlXPtrLocationSetAdd(newset,
xmlXPtrInsideRange(ctxt, oldset->locTab[i]));
cur = ctxt->cur;
newset = xmlXPtrLocationSetCreate(NULL);
-
+
for (i = 0; i < oldset->nodeNr; i++) {
ctxt->cur = cur;
res = valuePop(ctxt);
xmlXPathFreeObject(res);
}
-
+
ctxt->context->node = NULL;
}
* @level: incremented/decremented to show level in tree
*
* Advance to the next element or text node in document order
- * TODO: add a stack for entering/exiting entities
+ * TODO: add a stack for entering/exiting entities
*
* Returns -1 in case of failure, 0 otherwise
*/
xmlNodePtr
xmlXPtrAdvanceNode(xmlNodePtr cur, int *level) {
next:
- if (cur == NULL)
+ if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(NULL);
if (cur->children != NULL) {
cur = cur->children ;
if ((node == NULL) || (indx == NULL))
return(-1);
cur = *node;
- if (cur == NULL)
+ if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
return(-1);
pos = *indx;
return(0);
}
/*
- * We should have a text (or cdata) node ...
+ * We should have a text (or cdata) node ...
*/
len = 0;
if ((cur->type != XML_ELEMENT_NODE) &&
if (string == NULL)
return(-1);
- if (start == NULL)
+ if ((start == NULL) || (start->type == XML_NAMESPACE_DECL))
return(-1);
- if ((end == NULL) || (endindex == NULL))
+ if ((end == NULL) || (*end == NULL) ||
+ ((*end)->type == XML_NAMESPACE_DECL) || (endindex == NULL))
return(-1);
cur = start;
- if (cur == NULL)
- return(-1);
pos = startindex - 1;
stringlen = xmlStrlen(string);
if (string == NULL)
return(-1);
- if ((start == NULL) || (startindex == NULL))
+ if ((start == NULL) || (*start == NULL) ||
+ ((*start)->type == XML_NAMESPACE_DECL) || (startindex == NULL))
return(-1);
if ((end == NULL) || (endindex == NULL))
return(-1);
cur = *start;
- if (cur == NULL)
- return(-1);
pos = *startindex - 1;
first = string[0];
/*
* An empty string is considered to match before each
* character of the string-value and after the final
- * character.
+ * character.
*/
#ifdef DEBUG_RANGES
xmlGenericError(xmlGenericErrorContext,
xmlNodePtr cur;
int pos, len = 0;
- if ((node == NULL) || (indx == NULL))
+ if ((node == NULL) || (*node == NULL) ||
+ ((*node)->type == XML_NAMESPACE_DECL) || (indx == NULL))
return(-1);
cur = *node;
pos = *indx;
- if (cur == NULL)
- return(-1);
-
if ((cur->type == XML_ELEMENT_NODE) ||
(cur->type == XML_DOCUMENT_NODE) ||
(cur->type == XML_HTML_DOCUMENT_NODE)) {
* @nargs: the number of args
*
* Function implementing the string-range() function
- * range as described in 5.4.2
+ * range as described in 5.4.2
*
* ------------------------------
* [Definition: For each location in the location-set argument,
set = valuePop(ctxt);
newset = xmlXPtrLocationSetCreate(NULL);
+ if (newset == NULL) {
+ xmlXPathFreeObject(set);
+ XP_ERROR(XPATH_MEMORY_ERROR);
+ }
if (set->nodesetval == NULL) {
goto error;
}
*/
tmp = xmlXPtrNewLocationSetNodeSet(set->nodesetval);
xmlXPathFreeObject(set);
+ if (tmp == NULL)
+ XP_ERROR(XPATH_MEMORY_ERROR)
set = tmp;
}
oldset = (xmlLocationSetPtr) set->user;
* @ctxt: the XPointer Parser context
*
* [8] Predicate ::= '[' PredicateExpr ']'
- * [9] PredicateExpr ::= Expr
+ * [9] PredicateExpr ::= Expr
*
* Evaluate a predicate as in xmlXPathEvalPredicate() but for
* a Location Set instead of a node set
*/
cur = ctxt->cur;
newset = xmlXPtrLocationSetCreate(NULL);
-
+
for (i = 0; i < oldset->locNr; i++) {
ctxt->cur = cur;
res = valuePop(ctxt);
xmlXPathFreeObject(res);
}
-
+
ctxt->context->node = NULL;
}