]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virml: Introduce VIR_XML_PROP_NONNEGATIVE flag
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 7 Mar 2022 15:44:46 +0000 (16:44 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 10 Jun 2022 11:53:52 +0000 (13:53 +0200)
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@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/util/virxml.c
src/util/virxml.h

index 12b2ef635a16769d3ea0be8863632d7f72dfee0e..d6e2e5dd91b28b490539246d3da3cd185e644b4f 100644 (file)
@@ -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"),
index 5d49056bc75fa7ff43bba4fb9a03766eb5f92d2b..539228a9ba811dd2533ba35d228174a4cd48dbee 100644 (file)
@@ -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;