summaryrefslogtreecommitdiff
path: root/src/nodeset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nodeset.c')
-rw-r--r--src/nodeset.c75
1 files changed, 32 insertions, 43 deletions
diff --git a/src/nodeset.c b/src/nodeset.c
index 800f1507..be5138ad 100644
--- a/src/nodeset.c
+++ b/src/nodeset.c
@@ -1,13 +1,19 @@
-/**
+/*
* XML Security Library (http://www.aleksey.com/xmlsec).
*
- * Enchanced nodes set
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
* Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
*/
+/**
+ * SECTION:nodeset
+ * @Short_description: XML nodes set functions
+ * @Stability: Stable
+ *
+ */
+
#include "globals.h"
#include <stdlib.h>
@@ -20,6 +26,7 @@
#include <xmlsec/xmlsec.h>
#include <xmlsec/nodeset.h>
#include <xmlsec/errors.h>
+#include <xmlsec/private.h>
#define xmlSecGetParent(node) \
(((node)->type != XML_NAMESPACE_DECL) ? \
@@ -52,12 +59,7 @@ xmlSecNodeSetCreate(xmlDocPtr doc, xmlNodeSetPtr nodes, xmlSecNodeSetType type)
nset = (xmlSecNodeSetPtr)xmlMalloc(sizeof(xmlSecNodeSet));
if(nset == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_MALLOC_FAILED,
- "sizeof(xmlSecNodeSet)=%d",
- (int)sizeof(xmlSecNodeSet));
+ xmlSecMallocError(sizeof(xmlSecNodeSet), NULL);
return(NULL);
}
memset(nset, 0, sizeof(xmlSecNodeSet));
@@ -193,11 +195,8 @@ xmlSecNodeSetOneContains(xmlSecNodeSetPtr nset, xmlNodePtr node, xmlNodePtr pare
}
return(1);
default:
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_INVALID_TYPE,
- "type=%d", nset->type);
+ xmlSecInvalidIntegerTypeError("node set type", nset->type,
+ "supported nodeset type", NULL);
}
return(0);
@@ -246,11 +245,8 @@ xmlSecNodeSetContains(xmlSecNodeSetPtr nset, xmlNodePtr node, xmlNodePtr parent)
}
break;
default:
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_INVALID_OPERATION,
- "operation=%d", cur->op);
+ xmlSecOtherError2(XMLSEC_ERRORS_R_INVALID_OPERATION, NULL,
+ "node set operation=%d", (int)cur->op);
return(-1);
}
cur = cur->next;
@@ -261,7 +257,7 @@ xmlSecNodeSetContains(xmlSecNodeSetPtr nset, xmlNodePtr node, xmlNodePtr parent)
/**
* xmlSecNodeSetAdd:
- * @nset: the pointer to currrent nodes set (or NULL).
+ * @nset: the pointer to current nodes set (or NULL).
* @newNSet: the pointer to new nodes set.
* @op: the operation type.
*
@@ -293,7 +289,7 @@ xmlSecNodeSetAdd(xmlSecNodeSetPtr nset, xmlSecNodeSetPtr newNSet,
/**
* xmlSecNodeSetAddList:
- * @nset: the pointer to currrent nodes set (or NULL).
+ * @nset: the pointer to current nodes set (or NULL).
* @newNSet: the pointer to new nodes set.
* @op: the operation type.
*
@@ -310,22 +306,14 @@ xmlSecNodeSetAddList(xmlSecNodeSetPtr nset, xmlSecNodeSetPtr newNSet, xmlSecNode
tmp1 = xmlSecNodeSetCreate(newNSet->doc, NULL, xmlSecNodeSetList);
if(tmp1 == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecNodeSetCreate",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecNodeSetCreate", NULL);
return(NULL);
}
tmp1->children = newNSet;
tmp2 = xmlSecNodeSetAdd(nset, tmp1, op);
if(tmp2 == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlSecNodeSetAdd",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecNodeSetAdd", NULL);
xmlSecNodeSetDestroy(tmp1);
return(NULL);
}
@@ -477,11 +465,7 @@ xmlSecNodeSetGetChildren(xmlDocPtr doc, const xmlNodePtr parent, int withComment
nodes = xmlXPathNodeSetCreate(parent);
if(nodes == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- "xmlXPathNodeSetCreate",
- XMLSEC_ERRORS_R_XML_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecXmlError("xmlXPathNodeSetCreate", NULL);
return(NULL);
}
@@ -512,13 +496,21 @@ static int
xmlSecNodeSetDumpTextNodesWalkCallback(xmlSecNodeSetPtr nset, xmlNodePtr cur,
xmlNodePtr parent ATTRIBUTE_UNUSED,
void* data) {
+ int ret;
xmlSecAssert2(nset != NULL, -1);
xmlSecAssert2(cur != NULL, -1);
xmlSecAssert2(data != NULL, -1);
- if(cur->type == XML_TEXT_NODE) {
- xmlOutputBufferWriteString((xmlOutputBufferPtr)data,
- (char*)(cur->content));
+ UNREFERENCED_PARAMETER(parent);
+
+ if(cur->type != XML_TEXT_NODE) {
+ return(0);
+ }
+ ret = xmlOutputBufferWriteString((xmlOutputBufferPtr)data,
+ (char*)(cur->content));
+ if(ret < 0) {
+ xmlSecXmlError("xmlOutputBufferWriteString", NULL);
+ return(-1);
}
return(0);
}
@@ -583,11 +575,8 @@ xmlSecNodeSetDebugDump(xmlSecNodeSetPtr nset, FILE *output) {
return;
default:
fprintf(output, "(unknown=%d)\n", nset->type);
- xmlSecError(XMLSEC_ERRORS_HERE,
- NULL,
- NULL,
- XMLSEC_ERRORS_R_INVALID_TYPE,
- "type=%d", nset->type);
+ xmlSecInvalidIntegerTypeError("node set type", nset->type,
+ "supported nodeset type", NULL);
}
l = xmlXPathNodeSetGetLength(nset->nodes);