mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
util: xml: Introduce virXMLPropUUID
The helper function extracts a UUID with semantics similar to other helpers we have. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a38c47bfb9
commit
fe54d2a94f
@ -3688,6 +3688,7 @@ virXMLPropTristateBoolAllowDefault;
|
|||||||
virXMLPropTristateSwitch;
|
virXMLPropTristateSwitch;
|
||||||
virXMLPropUInt;
|
virXMLPropUInt;
|
||||||
virXMLPropULongLong;
|
virXMLPropULongLong;
|
||||||
|
virXMLPropUUID;
|
||||||
virXMLSaveFile;
|
virXMLSaveFile;
|
||||||
virXMLValidateAgainstSchema;
|
virXMLValidateAgainstSchema;
|
||||||
virXMLValidatorFree;
|
virXMLValidatorFree;
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virutil.h"
|
#include "virutil.h"
|
||||||
|
#include "viruuid.h"
|
||||||
#include "configmake.h"
|
#include "configmake.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_XML
|
#define VIR_FROM_THIS VIR_FROM_XML
|
||||||
@ -808,6 +809,50 @@ virXMLPropEnumDefault(xmlNodePtr node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virXMLPropUUID:
|
||||||
|
* @node: XML dom node pointer
|
||||||
|
* @name: Name of the property (attribute) to get
|
||||||
|
* @flags: Bitwise-OR of virXMLPropFlags
|
||||||
|
* @result: Array of VIR_UUID_BUFLEN bytes to store the raw UUID
|
||||||
|
*
|
||||||
|
* Convenience function to fetch an XML property as a UUID.
|
||||||
|
*
|
||||||
|
* Returns 1 in case of success in which case @result is set,
|
||||||
|
* or 0 if the attribute is not present,
|
||||||
|
* or -1 and reports an error on failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virXMLPropUUID(xmlNodePtr node,
|
||||||
|
const char* name,
|
||||||
|
virXMLPropFlags flags,
|
||||||
|
unsigned char *result)
|
||||||
|
{
|
||||||
|
g_autofree char *tmp = NULL;
|
||||||
|
unsigned char val[VIR_UUID_BUFLEN];
|
||||||
|
|
||||||
|
if (!(tmp = virXMLPropString(node, name))) {
|
||||||
|
if (!(flags & VIR_XML_PROP_REQUIRED))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("Missing required attribute '%s' in element '%s'"),
|
||||||
|
name, node->name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virUUIDParse(tmp, val) < 0) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("Invalid value for attribute '%s' in element '%s': '%s'. Expected UUID"),
|
||||||
|
name, node->name, tmp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(result, val, VIR_UUID_BUFLEN);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virXMLPropEnum:
|
* virXMLPropEnum:
|
||||||
* @node: XML dom node pointer
|
* @node: XML dom node pointer
|
||||||
|
@ -154,6 +154,13 @@ virXMLPropEnum(xmlNodePtr node,
|
|||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
|
||||||
ATTRIBUTE_NONNULL(5);
|
ATTRIBUTE_NONNULL(5);
|
||||||
|
|
||||||
|
int
|
||||||
|
virXMLPropUUID(xmlNodePtr node,
|
||||||
|
const char *name,
|
||||||
|
virXMLPropFlags flags,
|
||||||
|
unsigned char *result)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
|
||||||
|
|
||||||
int
|
int
|
||||||
virXMLPropEnumDefault(xmlNodePtr node,
|
virXMLPropEnumDefault(xmlNodePtr node,
|
||||||
const char* name,
|
const char* name,
|
||||||
|
Loading…
Reference in New Issue
Block a user