From 1da04aa097db78c7474877049334c2c07b33bda1 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 2 Apr 2009 19:26:56 +0200 Subject: Added dmixml.[ch] - helper function for generating XML nodes --- src/dmixml.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/dmixml.h (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h new file mode 100644 index 0000000..d7d2716 --- /dev/null +++ b/src/dmixml.h @@ -0,0 +1,32 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For the avoidance of doubt the "preferred form" of this code is one which + * is in an open unpatent encumbered format. Where cryptographic key signing + * forms part of the process of creating an executable the information + * including keys needed to generate an equivalently functional executable + * are deemed to be part of the source code. + */ + +#ifndef _XMLHELPER_H +#define _XMLHELPER_H + +#include + +xmlAttrNode *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); +xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); +xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...); + +#endif -- cgit From a35afd0190f6a6925aa134ac43d2653aaf018ff8 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 3 Apr 2009 14:50:02 +0200 Subject: Fixed wrong xmlAttrNode type to xmlAttr --- src/dmixml.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index d7d2716..7d8c4ad 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -24,8 +24,9 @@ #define _XMLHELPER_H #include +#include -xmlAttrNode *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); +xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...); -- cgit From 8b2fe610dc309579f07787696f0814c359aa4de1 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 9 Apr 2009 14:51:31 +0200 Subject: Added missing copyright details --- src/dmixml.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index 7d8c4ad..e3b99a9 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -1,4 +1,7 @@ -/* +/* Simplified XML API for dmidecode + * + * Copyright 2009 David Sommerseth + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or -- cgit From 46988f9abcec9eb072be5f5d52fc594de89478e8 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 9 Apr 2009 15:13:23 +0200 Subject: Added more XML functions --- src/dmixml.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index e3b99a9..4683bc9 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -33,4 +33,9 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt 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_FindNode(xmlNode *, const char *key); +inline char *dmixml_GetContent(xmlNode *node); +inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); + #endif -- cgit From d64ab66e4fbf8d6dfceed628aef21f01063c3d66 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Wed, 29 Apr 2009 18:29:50 +0200 Subject: Added function for retrieving values from XPath objects Reverted commit 75aaf67d43cf4a28fe8d3e07111dab75a0c4396d in addition --- src/dmixml.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index 4683bc9..7176483 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -28,6 +28,7 @@ #include #include +#include xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); @@ -37,5 +38,6 @@ char *dmixml_GetAttrValue(xmlNode *node, const char *key); xmlNode *dmixml_FindNode(xmlNode *, const char *key); inline char *dmixml_GetContent(xmlNode *node); inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); +char *dmixml_GetXPathContent(xmlXPathObject *xpo, int idx); #endif -- cgit From cea1270777d0a5bd42284011307fe183a67f8ada Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Thu, 30 Apr 2009 16:07:43 +0200 Subject: Rewritten dmixml_GetXPathContent(...) and _get_key_value(...) This rewrite was to handle XPATH_NUMBER more correctly. Now these functions needs an preallocated memory buffer for the result. --- src/dmixml.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index 7176483..b1d86c6 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -38,6 +38,6 @@ char *dmixml_GetAttrValue(xmlNode *node, const char *key); xmlNode *dmixml_FindNode(xmlNode *, const char *key); inline char *dmixml_GetContent(xmlNode *node); inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); -char *dmixml_GetXPathContent(xmlXPathObject *xpo, int idx); +char *dmixml_GetXPathContent(char *buf, size_t buflen, xmlXPathObject *xpo, int idx); #endif -- cgit From af27ba4dd2ffdef8e4ee3abf187475c1b3303f71 Mon Sep 17 00:00:00 2001 From: Nima Talebi Date: Sun, 24 May 2009 00:26:23 +1000 Subject: Completed preliminary reimplementation of type() Updated test unit to match. Throw an exception instead of returning None/False in some functions. --- src/dmixml.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index b1d86c6..b1ca6d9 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -35,6 +35,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_FindNode(xmlNode *, const char *key); inline char *dmixml_GetContent(xmlNode *node); inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); -- cgit From 033bd9e5008120546f8d6c973376e848f7a67f00 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Fri, 29 May 2009 18:00:13 +0200 Subject: Added a simple helper macro to simplify xmlNode traversing --- src/dmixml.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index b1ca6d9..f394137 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -30,6 +30,8 @@ #include #include +#define foreach_xmlnode(n, itn) for( itn = n; itn != NULL; itn = itn->next ) + xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt, ...); xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt, ...); xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...); -- cgit From 7e1ef7e718976c6a0ab92c01990a130203860ff5 Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Tue, 2 Jun 2009 15:46:37 +0200 Subject: Rewrote dmixml_FindNodeByAttr(...) function to also use TagName The previous version did not consider the tag name when searching for nodes. --- src/dmixml.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dmixml.h') 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); -- cgit From 655799b06376c503086e43a0225298d170e08dbf Mon Sep 17 00:00:00 2001 From: David Sommerseth Date: Mon, 15 Jun 2009 18:39:49 +0200 Subject: Added new function: dmixml_FindNodeByAttr_NoCase(...) This function will ignore the case of the string of the value to be found. This improves the behaviour mentioned in commit 20030e42b4d3f7283f6143641cb009a8dbf1da24. At the moment, the immediate advantage is that the pymap.xml is not strictly bound to if the type IDs in hex are in upper and/or lower case. Both cases and mixed cases will now work. --- src/dmixml.h | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/dmixml.h') diff --git a/src/dmixml.h b/src/dmixml.h index c78d8b0..3dc32e5 100644 --- a/src/dmixml.h +++ b/src/dmixml.h @@ -37,7 +37,40 @@ 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 *tagkey, const char *attrkey, const char *val); + +xmlNode *__dmixml_FindNodeByAttr(xmlNode *, const char *, const char *, const char *, int); + +/** + * Retrieve a pointer to an XML node based on tag name and a specified attribute value. To get + * a hit, tag name and the attribute must be found and the value of the attribute must match as well. + * The function will traverse all children nodes of the given input node, but it will not go deeper. + * Matching is case sensitive. + * @author David Sommerseth + * @author Nima Talebi + * @param xmlNode* Pointer to the XML node of where to start searching + * @param const char* Tag name the function will search for + * @param const char* Attribute to check for in the tag + * @param const char* Value of the attribute which must match to have a hit + * @return xmlNode* Pointer to the found XML node, NULL if no tag was found. + */ +#define dmixml_FindNodeByAttr(n, t, a, v) __dmixml_FindNodeByAttr(n, t, a, v, 1) + +/** + * Retrieve a pointer to an XML node based on tag name and a specified attribute value. To get + * a hit, tag name and the attribute must be found and the value of the attribute must match as well. + * The function will traverse all children nodes of the given input node, but it will not go deeper. + * Matching is case INsensitive. + * @author David Sommerseth + * @author Nima Talebi + * @param xmlNode* Pointer to the XML node of where to start searching + * @param const char* Tag name the function will search for + * @param const char* Attribute to check for in the tag + * @param const char* Value of the attribute which must match to have a hit + * @return xmlNode* Pointer to the found XML node, NULL if no tag was found. + */ +#define dmixml_FindNodeByAttr_NoCase(n, t, a, v) __dmixml_FindNodeByAttr(n, t, a, v, 0) + + xmlNode *dmixml_FindNode(xmlNode *, const char *key); inline char *dmixml_GetContent(xmlNode *node); inline char *dmixml_GetNodeContent(xmlNode *node, const char *key); -- cgit