From 30f877cfe429cfbeb15575a8b580cf4a74b0ab0a Mon Sep 17 00:00:00 2001
From: SVN-Git Migration <python-modules-team@lists.alioth.debian.org>
Date: Thu, 8 Oct 2015 11:54:08 -0700
Subject: [PATCH] Imported Upstream version 3.10.13

---
 .autoheader                   |   4 +-
 Makefile                      |  38 ++++++-
 contrib/python-dmidecode.spec |  10 +-
 examples/dmidump.py           | 203 +++++++++++++++++++++++++++-------
 src/dmidecode.c               |   7 +-
 src/dmixml.c                  |  24 +++-
 src/version.h                 |   2 +-
 7 files changed, 232 insertions(+), 56 deletions(-)

diff --git a/.autoheader b/.autoheader
index bc6e134..fb8f9cc 100644
--- a/.autoheader
+++ b/.autoheader
@@ -1,6 +1,6 @@
 
-© 2007-2009 Nima Talebi <nima@autonomy.net.au>
-© 2009      David Sommerseth <davids@redhat.com>
+© 2007-2010 Nima Talebi <nima@autonomy.net.au>
+© 2009-2010 David Sommerseth <davids@redhat.com>
 © 2002-2008 Jean Delvare <khali@linux-fr.org>
 © 2000-2002 Alan Cox <alan@redhat.com>
 
diff --git a/Makefile b/Makefile
index 1d82922..d468b70 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,42 @@
+#. ******* coding:utf-8 AUTOHEADER START v1.2 *******
+#. vim: fileencoding=utf-8 syntax=Makefile sw=4 ts=4 et
 #.
-#.	DMI Decode Python Extension Module
+#. © 2007-2010 Nima Talebi <nima@autonomy.net.au>
+#. © 2009-2010 David Sommerseth <davids@redhat.com>
+#. © 2002-2008 Jean Delvare <khali@linux-fr.org>
+#. © 2000-2002 Alan Cox <alan@redhat.com>
 #.
-#.	(C) 2008 Nima Talebi <nima@it.net.au>
+#. This file is part of python-dmidecode.
 #.
-#.	Licensed under the GNU Public License v2
+#.     python-dmidecode 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.
 #.
+#.     python-dmidecode 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 python-dmidecode.  If not, see <http://www.gnu.org/licenses/>.
+#.
+#. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+#. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+#. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
+#. EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+#. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+#. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+#. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+#. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+#. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#.
+#. ADAPTED M. STONE & T. PARKER DISCLAIMER: THIS SOFTWARE COULD RESULT IN INJURY
+#. AND/OR DEATH, AND AS SUCH, IT SHOULD NOT BE BUILT, INSTALLED OR USED BY ANYONE.
+#.
+#. $AutoHeaderSerial::20100225                                                 $
+#. ******* AUTOHEADER END v1.2 *******
 
 VERSION := $(shell cd src;python -c "from setup_common import *; print get_version();")
 PACKAGE := python-dmidecode
diff --git a/contrib/python-dmidecode.spec b/contrib/python-dmidecode.spec
index da818e4..ccd93d7 100644
--- a/contrib/python-dmidecode.spec
+++ b/contrib/python-dmidecode.spec
@@ -3,7 +3,7 @@
 
 Summary: Python module to access DMI data
 Name: python-dmidecode
-Version: 3.10.11
+Version: 3.10.13
 Release: 1%{?dist}
 License: GPLv2
 Group: System Environment/Libraries
@@ -31,7 +31,7 @@ cd ..
 
 %install
 rm -rf $RPM_BUILD_ROOT
-python src/setup.py install --root $RPM_BUILD_ROOT
+python src/setup.py install --root $RPM_BUILD_ROOT --prefix=%{_prefix}
 
 %clean
 rm -rf $RPM_BUILD_ROOT
@@ -49,6 +49,12 @@ rm -rf $RPM_BUILD_ROOT
 %{_datadir}/python-dmidecode/
 
 %changelog
+* Thu Jun 03 2010 Nima Talebi <nima@it.net.au> - 3.10.13-1
+- Update to new release
+
+* Fri Mar 12 2010 Nima Talebi <nima@it.net.au> - 3.10.12-1
+- Update to new release
+
 * Tue Feb 16 2010 Nima Talebi <nima@it.net.au> - 3.10.11-1
 - Update to new release
 
diff --git a/examples/dmidump.py b/examples/dmidump.py
index ed9908f..11b04ff 100755
--- a/examples/dmidump.py
+++ b/examples/dmidump.py
@@ -1,54 +1,179 @@
 #!/usr/bin/env python
+#
+#   Examples which makes use of the different python-dmidecode features
+#   This script should be run as root, or else expect permission warnings
+#
+#   Copyright 2008-2009 Nima Talebi <nima@autonomy.net.au>
+#   Copyright 2010      David Sommerseth <davids@redhat.com>
+#
+#   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.
+#
+
 import dmidecode
-import sys
+import sys, os
 from pprint import pprint
 
-#. Test all functions using /dev/mem...
-print "*** bios ***\n";      dmidecode.bios()
-print "*** system ***\n";    dmidecode.system()
-print "*** system ***\n";    dmidecode.system()
-print "*** baseboard ***\n"; dmidecode.baseboard()
-print "*** chassis ***\n";   dmidecode.chassis()
-print "*** processor ***\n"; dmidecode.processor()
-print "*** memory ***\n";    dmidecode.memory()
-print "*** cache ***\n";     dmidecode.cache()
-print "*** connector ***\n"; dmidecode.connector()
-print "*** slot ***\n";      dmidecode.slot()
+def print_warnings():
+        "Simple function, dumping out warnings with a prefix if warnings are found and clearing warning buffer"
+        warn = dmidecode.get_warnings()
+        if warn:
+              print "### WARNING: %s" % warn
+              dmidecode.clear_warnings()
+
+
+# Check if running as root .... provide a warning if not
+root_user = (os.getuid() == 0 and True or False)
+if not root_user:
+        print "####"
+        print "####  NOT RUNNING AS ROOT"
+        print "####"
+        print "#### The first run must always be done as root for this example to work."
+        print "#### When not run as root, quite some permission errors might appear"
+        print "####"
+        print "#### If this script is first run as root, it should be possible to run this script"
+        print "#### as an unprivileged user afterwards, with less warnings."
+        print "####"
+        print
+        print
+
+
+#. Test for presence of important functions using /dev/mem...  Using the legacy API
+#. This does not print any decoded info.  If the call fails, either a warning will
+#. be issued or an exception will be raised.  This test is now only used to check
+#. for presence of the legacy API, which "under the hood" uses
+#. dmidecode.QuerySection(name), where name can be 'bios', 'system', etc.
+if root_user:
+        print "*** bios ***\n";      dmidecode.bios()
+        print_warnings()
+        print "*** system ***\n";    dmidecode.system()
+        print_warnings()
+        print "*** baseboard ***\n"; dmidecode.baseboard()
+        print_warnings()
+        print "*** chassis ***\n";   dmidecode.chassis()
+        print_warnings()
+        print "*** processor ***\n"; dmidecode.processor()
+        print_warnings()
+        print "*** memory ***\n";    dmidecode.memory()
+        print_warnings()
+        print "*** cache ***\n";     dmidecode.cache()
+        print_warnings()
+        print "*** connector ***\n"; dmidecode.connector()
+        print_warnings()
+        print "*** slot ***\n";      dmidecode.slot()
+        print_warnings()
+
 
 #. Now test get/set of memory device file...
+print "*** get_dev()"
 print dmidecode.get_dev()
-print dmidecode.set_dev("private/mem-XXX");
+print_warnings()
+print "*** set_dev('dmidata.dump')"
+print dmidecode.set_dev("dmidata.dump");
+print_warnings()
+print "*** get_dev()"
 print dmidecode.get_dev()
+print_warnings()
 
 #. Test taking a dump...
-print dmidecode.dump()
-
-#. Test reading the dump...
-print "*** bios ***\n";      pprint(dmidecode.bios())
-print "*** system ***\n";    pprint(dmidecode.system())
-print "*** system ***\n";    pprint(dmidecode.system())
-print "*** baseboard ***\n"; pprint(dmidecode.baseboard())
-print "*** chassis ***\n";   pprint(dmidecode.chassis())
-print "*** processor ***\n"; pprint(dmidecode.processor())
-print "*** memory ***\n";    pprint(dmidecode.memory())
-print "*** cache ***\n";     pprint(dmidecode.cache())
-print "*** connector ***\n"; pprint(dmidecode.connector())
-print "*** slot ***\n";      pprint(dmidecode.slot())
-
-sys.exit(0)
-print "*** bios ***\n";      pprint(dmidecode.bios())
-print "*** system ***\n";    pprint(dmidecode.system())
-print "*** baseboard ***\n"; pprint(dmidecode.baseboard())
-print "*** chassis ***\n";   pprint(dmidecode.chassis())
-print "*** processor ***\n"; pprint(dmidecode.processor())
-print "*** memory ***\n";    pprint(dmidecode.memory())
-print "*** cache ***\n";     pprint(dmidecode.cache())
-print "*** connector ***\n"; pprint(dmidecode.connector())
-print "*** slot ***\n";      pprint(dmidecode.slot())
+if root_user:
+        print "*** Dumping DMI data to dump file"
+        print dmidecode.dump()
+        print_warnings()
 
+#. Test reading the dump...  Using the preferred API
+print "*** bios ***\n";      pprint(dmidecode.QuerySection('bios'))
+print_warnings()
+print "*** system ***\n";    pprint(dmidecode.QuerySection('system'))
+print_warnings()
+print "*** baseboard ***\n"; pprint(dmidecode.QuerySection('baseboard'))
+print_warnings()
+print "*** chassis ***\n";   pprint(dmidecode.QuerySection('chassis'))
+print_warnings()
+print "*** processor ***\n"; pprint(dmidecode.QuerySection('processor'))
+print_warnings()
+print "*** memory ***\n";    pprint(dmidecode.QuerySection('memory'))
+print_warnings()
+print "*** cache ***\n";     pprint(dmidecode.QuerySection('cache'))
+print_warnings()
+print "*** connector ***\n"; pprint(dmidecode.QuerySection('connector'))
+print_warnings()
+print "*** slot ***\n";      pprint(dmidecode.QuerySection('slot'))
+print_warnings()
+
+print "*** Extracting memory information"
 for v in dmidecode.memory().values():
   if type(v) == dict and v['dmi_type'] == 17:
     pprint(v['data']['Size']),
 
-pprint(dmidecode.type('3'))
-pprint(dmidecode.type('bios'))
+print "*** Querying for DMI type 3 and 7"
+pprint(dmidecode.type(3))        # <-- Legacy API
+pprint(dmidecode.QueryTypeId(7)) # <-- preferred API
+print_warnings()
+
+print "*** Querying for the BIOS section"
+pprint(dmidecode.QuerySection('bios'))
+print_warnings()
+
+#
+# Test XML stuff
+#
+print
+print
+print
+print "---------------------------------------"
+print "*** *** *** Testing XML API *** *** ***"
+print "---------------------------------------"
+print
+print
+dmixml = dmidecode.dmidecodeXML()
+
+# Fetch all DMI data into a libxml2.xmlDoc object
+print "*** Getting all DMI data into a XML document variable"
+dmixml.SetResultType(dmidecode.DMIXML_DOC)  # Valid values: dmidecode.DMIXML_DOC, dmidecode.DMIXML_NODE
+xmldoc = dmixml.QuerySection('all')
+
+# Dump the XML to dmidump.xml - formated in UTF-8 decoding
+print "*** Dumping XML document to dmidump.xml"
+xmldoc.saveFormatFileEnc('dmidump.xml','UTF-8',1)
+
+# Do some XPath queries on the XML document
+print "*** Doing some XPath queries against the XML document"
+dmixp = xmldoc.xpathNewContext()
+
+# What to look for - XPath expressions
+keys = ['/dmidecode/SystemInfo/Manufacturer',
+	'/dmidecode/SystemInfo/ProductName',
+	'/dmidecode/SystemInfo/SerialNumber',
+	'/dmidecode/SystemInfo/SystemUUID']
+
+# Extract data and print it
+for k in keys:
+	data = dmixp.xpathEval(k)
+	for d in data:
+		print "%s: %s" % (k, d.get_content())
+
+del dmixp
+del xmldoc
+
+# Query for only a particular DMI TypeID - 0x04 - Processor
+print "*** Quering for Type ID 0x04 - Processor - dumping XML document to stdout"
+dmixml.QueryTypeId(0x04).saveFormatFileEnc('-','UTF-8',1)
+print_warnings()
diff --git a/src/dmidecode.c b/src/dmidecode.c
index 02dd9b0..4a2e445 100644
--- a/src/dmidecode.c
+++ b/src/dmidecode.c
@@ -1019,7 +1019,6 @@ xmlNode *dmi_processor_id(xmlNode *node, u8 type, const u8 * p, const char *vers
          ** CPUID instruction or another form of identification.
          */
 
-        //. TODO: PyString_FromFormat does not support %x (yet?)...
         dmixml_AddTextChild(data_n, "ID",
                             "%02x %02x %02x %02x %02x %02x %02x %02x",
                             p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
@@ -1075,7 +1074,7 @@ xmlNode *dmi_processor_id(xmlNode *node, u8 type, const u8 * p, const char *vers
 
                 sig = 2;
 
-        } else if(type == 0x01 || type == 0x02) {
+        } else if(version && (type == 0x01 || type == 0x02)) {
                 /*
                  ** Some X86-class CPU have family "Other" or "Unknown". In this case,
                  ** we use the version string to determine if they are known to
@@ -4890,8 +4889,8 @@ static void dmi_table(Log_t *logp, int type, u32 base, u16 len, u16 num, u16 ver
                  */
                 if(h.length < 4) {
                         log_append(logp, LOGFL_NORMAL, LOG_WARNING,
-				   "Invalid entry length (%i). DMI table is broken! Stop.",
-				   (unsigned int)h.length);
+				   "Invalid entry length (%i) for type %i. DMI table is broken! Stop.",
+				   (unsigned int)h.length, type);
                         break;
                 }
 
diff --git a/src/dmixml.c b/src/dmixml.c
index ba285e8..3b05ad4 100644
--- a/src/dmixml.c
+++ b/src/dmixml.c
@@ -92,13 +92,18 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt
         xmlAttr *res = NULL;
         va_list ap;
 
-        if( (node == NULL) || (atrname == NULL) || (fmt == NULL) ) {
+        if( (node == NULL) || (atrname == NULL) ) {
                 return NULL;
         }
 
         atrname_s = xmlCharStrdup(atrname);
         assert( atrname_s != NULL );
 
+	if( fmt == NULL ) {
+		res = xmlNewProp(node, atrname_s, NULL);
+		goto exit;
+	}
+
         va_start(ap, fmt);
         val_s = dmixml_buildstr(2048, fmt, ap);
         va_end(ap);
@@ -106,8 +111,9 @@ xmlAttr *dmixml_AddAttribute(xmlNode *node, const char *atrname, const char *fmt
         res = xmlNewProp(node, atrname_s,
                          (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s));
 
-        free(atrname_s);
         free(val_s);
+ exit:
+        free(atrname_s);
 
         assert( res != NULL );
         return res;
@@ -129,13 +135,18 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt
         xmlNode *res = NULL;
         va_list ap;
 
-        if( (node == NULL) || (tagname == NULL) || (fmt == NULL) ) {
+        if( (node == NULL) || (tagname == NULL) ) {
                 return NULL;
         }
 
         tagname_s = xmlCharStrdup(tagname);
         assert( tagname_s != NULL );
 
+	if( fmt == NULL ) {
+		res = xmlNewChild(node, NULL, tagname_s, NULL);
+		goto exit;
+	}
+
         va_start(ap, fmt);
         val_s = dmixml_buildstr(2048, fmt, ap);
         va_end(ap);
@@ -144,8 +155,9 @@ xmlNode *dmixml_AddTextChild(xmlNode *node, const char *tagname, const char *fmt
         res = xmlNewTextChild(node, NULL, tagname_s,
                               (xmlStrcmp(val_s, (xmlChar *) "(null)") == 0 ? NULL : val_s));
 
-        free(tagname_s);
         free(val_s);
+ exit:
+        free(tagname_s);
 
         assert( res != NULL );
         return res;
@@ -165,7 +177,9 @@ xmlNode *dmixml_AddTextContent(xmlNode *node, const char *fmt, ...)
         va_list ap;
 
         if( (node == NULL) || (fmt == NULL) ) {
-                return NULL;
+                // Return node and not NULL, as node may not be NULL but fmt can be,
+                // thus doing a similar string check (val_s != "(null)") as later on
+                return node;
         }
 
         va_start(ap, fmt);
diff --git a/src/version.h b/src/version.h
index 180cf92..742a13f 100644
--- a/src/version.h
+++ b/src/version.h
@@ -1 +1 @@
-#define VERSION "3.10.11"
+#define VERSION "3.10.13"
-- 
GitLab