[PATCH 01/16] virml: Introduce VIR_XML_PROP_NONNEGATIVE flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



For easier attribute parsing we have virXMLProp*() family of
functions. These accept flags through which a caller can pose
some conditions onto the attribute value, for instance:
VIR_XML_PROP_NONZERO when the attribute may not be zero, etc.

What we are missing is VIR_XML_PROP_NONNEGATIVE when the
attribute value may be non-negative. Obviously, this flag makes
sense only for some members of the virXMLProp*() family.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virxml.c | 7 +++++++
 src/util/virxml.h | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 12b2ef635a..d6e2e5dd91 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -643,6 +643,13 @@ virXMLPropInt(xmlNodePtr node,
         return -1;
     }
 
+    if ((flags & VIR_XML_PROP_NONNEGATIVE) && (val < 0)) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Invalid value for attribute '%s' in element '%s': '%s'. Expected non-negative value"),
+                       name, node->name, tmp);
+        return -1;
+    }
+
     if ((flags & VIR_XML_PROP_NONZERO) && (val == 0)) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("Invalid value for attribute '%s' in element '%s': Zero is not permitted"),
diff --git a/src/util/virxml.h b/src/util/virxml.h
index 5d49056bc7..539228a9ba 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -38,6 +38,9 @@ typedef enum {
     VIR_XML_PROP_NONE = 0,
     VIR_XML_PROP_REQUIRED = 1 << 0, /* Attribute may not be absent */
     VIR_XML_PROP_NONZERO = 1 << 1, /* Attribute may not be zero */
+    VIR_XML_PROP_NONNEGATIVE = 1 << 2, /* Attribute may not be negative, makes
+                                          sense only for some virXMLProp*()
+                                          functions. */
 } virXMLPropFlags;
 
 
-- 
2.35.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux