mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virDomainRedirFilterUSBDevDefParseXML: Use virXMLProp*
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
0ed95ae926
commit
54fb0b9e95
@ -14506,52 +14506,28 @@ static virDomainRedirFilterUSBDevDef *
|
|||||||
virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
|
virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
|
||||||
{
|
{
|
||||||
virDomainRedirFilterUSBDevDef *def;
|
virDomainRedirFilterUSBDevDef *def;
|
||||||
g_autofree char *class = NULL;
|
|
||||||
g_autofree char *vendor = NULL;
|
|
||||||
g_autofree char *product = NULL;
|
|
||||||
g_autofree char *version = NULL;
|
g_autofree char *version = NULL;
|
||||||
g_autofree char *allow = NULL;
|
virTristateBool allow;
|
||||||
|
|
||||||
def = g_new0(virDomainRedirFilterUSBDevDef, 1);
|
def = g_new0(virDomainRedirFilterUSBDevDef, 1);
|
||||||
|
|
||||||
class = virXMLPropString(node, "class");
|
def->usbClass = -1;
|
||||||
if (class) {
|
if (virXMLPropInt(node, "class", 0, VIR_XML_PROP_NONE, &def->usbClass) < 0)
|
||||||
if ((virStrToLong_i(class, NULL, 0, &def->usbClass)) < 0) {
|
goto error;
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("Cannot parse USB Class code %s"), class);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (def->usbClass != -1 && def->usbClass &~ 0xFF) {
|
if (def->usbClass != -1 && def->usbClass &~ 0xFF) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Invalid USB Class code %s"), class);
|
_("Invalid USB Class code 0x%x"), def->usbClass);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
def->usbClass = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vendor = virXMLPropString(node, "vendor");
|
def->vendor = -1;
|
||||||
if (vendor) {
|
if (virXMLPropInt(node, "vendor", 0, VIR_XML_PROP_NONE, &def->vendor) < 0)
|
||||||
if ((virStrToLong_i(vendor, NULL, 0, &def->vendor)) < 0) {
|
goto error;
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("Cannot parse USB vendor ID %s"), vendor);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
def->vendor = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
product = virXMLPropString(node, "product");
|
def->product = -1;
|
||||||
if (product) {
|
if (virXMLPropInt(node, "product", 0, VIR_XML_PROP_NONE, &def->product) < 0)
|
||||||
if ((virStrToLong_i(product, NULL, 0, &def->product)) < 0) {
|
goto error;
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("Cannot parse USB product ID %s"), product);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
def->product = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
version = virXMLPropString(node, "version");
|
version = virXMLPropString(node, "version");
|
||||||
if (version) {
|
if (version) {
|
||||||
@ -14563,18 +14539,10 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
|
|||||||
def->version = -1;
|
def->version = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
allow = virXMLPropString(node, "allow");
|
if (virXMLPropTristateBool(node, "allow", VIR_XML_PROP_REQUIRED, &allow) < 0)
|
||||||
if (allow) {
|
|
||||||
if (virStringParseYesNo(allow, &def->allow) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Invalid allow value, either 'yes' or 'no'"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
||||||
_("Missing allow attribute for USB redirection filter"));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
def->allow = allow == VIR_TRISTATE_BOOL_YES;
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user