summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Sommerseth <davids@redhat.com>2009-06-02 15:46:37 +0200
committerDavid Sommerseth <davids@redhat.com>2009-06-02 15:54:49 +0200
commit7e1ef7e718976c6a0ab92c01990a130203860ff5 (patch)
treee5878cd7239b0cf411e77417554ef5cbac885ec9 /src
parent033bd9e5008120546f8d6c973376e848f7a67f00 (diff)
downloadpython-dmidecode-7e1ef7e718976c6a0ab92c01990a130203860ff5.tar.gz
python-dmidecode-7e1ef7e718976c6a0ab92c01990a130203860ff5.tar.xz
python-dmidecode-7e1ef7e718976c6a0ab92c01990a130203860ff5.zip
Rewrote dmixml_FindNodeByAttr(...) function to also use TagName
The previous version did not consider the tag name when searching for nodes.
Diffstat (limited to 'src')
-rw-r--r--src/dmixml.c38
-rw-r--r--src/dmixml.h2
2 files changed, 19 insertions, 21 deletions
diff --git a/src/dmixml.c b/src/dmixml.c
index 27e5f3f..de79d99 100644
--- a/src/dmixml.c
+++ b/src/dmixml.c
@@ -31,6 +31,8 @@
#include <libxml/xpath.h>
#include <libxml/xmlstring.h>
+#include "dmixml.h"
+
// Internal function for dmixml_* functions ... builds up a variable xmlChar* string
xmlChar *dmixml_buildstr(size_t len, const char *fmt, va_list ap) {
xmlChar *ret = NULL, *xmlfmt = NULL;
@@ -179,34 +181,30 @@ char *dmixml_GetAttrValue(xmlNode *node, const char *key) {
return NULL;
}
-xmlNode *dmixml_FindNodeByAttr(xmlNode *node, const char *key, const char *val) {
+xmlNode *dmixml_FindNodeByAttr(xmlNode *node, const char *tagkey, const char *attrkey, const char *val) {
+ xmlNode *ptr_n = NULL;
+ xmlChar *tag_s = NULL;
+
+ assert( node != NULL );
if( node->children == NULL ) {
return NULL;
}
- xmlNode *ptr_n = NULL;
- xmlChar *key_s = NULL;
- xmlChar *val_s = NULL;
- xmlChar *_val_s = NULL;
-
- key_s = xmlCharStrdup(key);
- assert( key_s != NULL );
- val_s = xmlCharStrdup(val);
- assert( val_s != NULL );
+ tag_s = xmlCharStrdup(tagkey);
+ assert( tag_s != NULL );
- for( ptr_n = node->children; ptr_n != NULL; ptr_n = ptr_n->next ) {
- _val_s = xmlCharStrdup(dmixml_GetAttrValue(ptr_n, (const char *)key_s));
+ foreach_xmlnode(node->children, ptr_n) {
+ // To return the correct node, we need to check node type,
+ // tag name and the attribute value of the given attribute.
if( (ptr_n->type == XML_ELEMENT_NODE)
- && (xmlStrcmp(val_s, _val_s) == 0) ) {
- free(val_s); val_s = NULL;
- free(key_s); key_s = NULL;
- return ptr_n;
+ && (xmlStrcmp(ptr_n->name, tag_s) == 0)
+ && (strcmp(dmixml_GetAttrValue(ptr_n, attrkey), val) == 0 ) ) {
+ goto exit;
}
- free(_val_s);
}
- free(key_s); key_s = NULL;
- free(val_s); val_s = NULL;
- return NULL;
+ exit:
+ free(tag_s); tag_s = NULL;
+ return ptr_n;
}
xmlNode *dmixml_FindNode(xmlNode *node, const char *key) {
diff --git a/src/dmixml.h b/src/dmixml.h
index f394137..c78d8b0 100644
--- a/src/dmixml.h
+++ b/src/dmixml.h
@@ -37,7 +37,7 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt
xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...);
char *dmixml_GetAttrValue(xmlNode *node, const char *key);
-xmlNode *dmixml_FindNodeByAttr(xmlNode *node, const char *key, const char *val);
+xmlNode *dmixml_FindNodeByAttr(xmlNode *node, const char *tagkey, const char *attrkey, const char *val);
xmlNode *dmixml_FindNode(xmlNode *, const char *key);
inline char *dmixml_GetContent(xmlNode *node);
inline char *dmixml_GetNodeContent(xmlNode *node, const char *key);