g_autofree char *cpuMode = NULL;
g_autofree char *fallback = NULL;
g_autofree char *vendor_id = NULL;
- g_autofree char *tscScaling = NULL;
g_autofree virHostCPUTscInfo *tsc = NULL;
*cpu = NULL;
if (def->type == VIR_CPU_TYPE_HOST) {
g_autofree char *arch = virXPathString("string(./arch[1])", ctxt);
+ xmlNodePtr counter_node = NULL;
+
if (!arch) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing CPU architecture"));
return -1;
}
- if (virXPathBoolean("boolean(./counter[@name='tsc'])", ctxt) > 0) {
+ if ((counter_node = virXPathNode("./counter[@name='tsc'])", ctxt))) {
tsc = g_new0(virHostCPUTscInfo, 1);
if (virXPathULongLong("string(./counter[@name='tsc']/@frequency)",
return -1;
}
- tscScaling = virXPathString("string(./counter[@name='tsc']/@scaling)",
- ctxt);
- if (tscScaling) {
- int scaling = virTristateBoolTypeFromString(tscScaling);
- if (scaling < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("Invalid TSC scaling attribute"));
- return -1;
- }
- tsc->scaling = scaling;
- }
+ if (virXMLPropTristateBool(counter_node, "scaling",
+ VIR_XML_PROP_NONE,
+ &tsc->scaling) < 0)
+ return -1;
def->tsc = g_steal_pointer(&tsc);
}
virDomainHostdevDef *def,
unsigned int flags)
{
- g_autofree char *filtering = NULL;
xmlNodePtr address = NULL;
xmlNodePtr origstates = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
ctxt->node = node;
- if ((filtering = virXMLPropString(node, "writeFiltering"))) {
- int val;
- if ((val = virTristateBoolTypeFromString(filtering)) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("unknown pci writeFiltering setting '%s'"),
- filtering);
- return -1;
- }
- def->writeFiltering = val;
- }
+ if (virXMLPropTristateBool(node, "writeFiltering",
+ VIR_XML_PROP_NONE,
+ &def->writeFiltering) < 0)
+ return -1;
if ((address = virXPathNode("./address", ctxt)) &&
virPCIDeviceAddressParseXML(address, &def->source.subsys.u.pci.addr) < 0)
virDomainHostdevSubsysSCSI *scsisrc = &def->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHost *scsihostsrc = &def->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev;
- g_autofree char *managed = NULL;
+ virTristateBool managed;
g_autofree char *sgio = NULL;
- g_autofree char *rawio = NULL;
g_autofree char *backendStr = NULL;
g_autofree char *model = NULL;
+ int rv;
/* @managed can be read from the xml document - it is always an
* attribute of the toplevel element, no matter what type of
* element that might be (pure hostdev, or higher level device
* (e.g. <interface>) with type='hostdev')
*/
- if ((managed = virXMLPropString(node, "managed")) != NULL)
- ignore_value(virStringParseYesNo(managed, &def->managed));
+ ignore_value(virXMLPropTristateBool(node, "managed",
+ VIR_XML_PROP_NONE, &managed));
+ virTristateBoolToBool(managed, &def->managed);
sgio = virXMLPropString(node, "sgio");
- rawio = virXMLPropString(node, "rawio");
model = virXMLPropString(node, "model");
/* @type is passed in from the caller rather than read from the
}
}
- if (rawio) {
- if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("rawio is only supported for scsi host device"));
- return -1;
- }
-
- if ((scsisrc->rawio = virTristateBoolTypeFromString(rawio)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("unknown hostdev rawio setting '%s'"),
- rawio);
- return -1;
- }
+ if ((rv = virXMLPropTristateBool(node, "rawio",
+ VIR_XML_PROP_NONE,
+ &scsisrc->rawio)) < 0) {
+ return -1;
+ } else if (rv > 0 &&
+ def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("rawio is only supported for scsi host device"));
+ return -1;
}
if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
xmlNodePtr vlan_node = NULL;
xmlNodePtr bandwidth_node = NULL;
xmlNodePtr tmpNode;
+ xmlNodePtr mac_node = NULL;
g_autoptr(GHashTable) filterparams = NULL;
virDomainActualNetDef *actual = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
int rv, val;
g_autofree char *macaddr = NULL;
g_autofree char *macaddr_type = NULL;
- g_autofree char *macaddr_check = NULL;
g_autofree char *network = NULL;
g_autofree char *portgroup = NULL;
g_autofree char *portid = NULL;
if ((vhost = virXPathString("string(./backend/@vhost)", ctxt)))
vhost_path = virFileSanitizePath(vhost);
- if ((macaddr = virXPathString("string(./mac/@address)", ctxt))) {
+ mac_node = virXPathNode("./mac", ctxt);
+
+ if ((macaddr = virXMLPropString(mac_node, "address"))) {
if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unable to parse mac address '%s'"),
def->mac_type = tmp;
}
- if ((macaddr_check = virXPathString("string(./mac/@check)", ctxt))) {
- int tmpCheck;
-
- if ((tmpCheck = virTristateBoolTypeFromString(macaddr_check)) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("invalid mac address check value: '%s'"),
- macaddr_check);
- goto error;
- }
- def->mac_check = tmpCheck;
- }
+ if (virXMLPropTristateBool(mac_node, "check",
+ VIR_XML_PROP_NONE,
+ &def->mac_check) < 0)
+ goto error;
if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info,
flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT
virDomainVideoAccelDefParseXML(xmlNodePtr node)
{
g_autofree virDomainVideoAccelDef *def = NULL;
- int val;
- g_autofree char *accel2d = NULL;
- g_autofree char *accel3d = NULL;
g_autofree char *rendernode = NULL;
- accel3d = virXMLPropString(node, "accel3d");
- accel2d = virXMLPropString(node, "accel2d");
rendernode = virXMLPropString(node, "rendernode");
- if (!accel3d && !accel2d && !rendernode) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("missing values for acceleration"));
- return NULL;
- }
-
def = g_new0(virDomainVideoAccelDef, 1);
- if (accel3d) {
- if ((val = virTristateBoolTypeFromString(accel3d)) <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown accel3d value '%s'"), accel3d);
- return NULL;
- }
- def->accel3d = val;
- }
+ if (virXMLPropTristateBool(node, "accel3d",
+ VIR_XML_PROP_NONE,
+ &def->accel3d) < 0)
+ return NULL;
- if (accel2d) {
- if ((val = virTristateBoolTypeFromString(accel2d)) <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown accel2d value '%s'"), accel2d);
- return NULL;
- }
- def->accel2d = val;
- }
+ if (virXMLPropTristateBool(node, "accel2d",
+ VIR_XML_PROP_NONE,
+ &def->accel2d) < 0)
+ return NULL;
if (rendernode)
def->rendernode = virFileSanitizePath(rendernode);
static int
virDomainPMStateParseXML(xmlXPathContextPtr ctxt,
const char *xpath,
- int *val)
+ virTristateBool *val)
{
- g_autofree char *tmp = virXPathString(xpath, ctxt);
-
- if (tmp) {
- *val = virTristateBoolTypeFromString(tmp);
- if (*val < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown PM state value %s"), tmp);
- return -1;
- }
- }
+ xmlNodePtr node = virXPathNode(xpath, ctxt);
- return 0;
+ return virXMLPropTristateBool(node, "enabled",
+ VIR_XML_PROP_NONE,
+ val);
}
}
if ((node = virXPathNode("./os/bootmenu[1]", ctxt))) {
- tmp = virXMLPropString(node, "enable");
- if (tmp) {
- def->os.bootmenu = virTristateBoolTypeFromString(tmp);
- if (def->os.bootmenu <= 0) {
- /* In order not to break misconfigured machines, this
- * should not emit an error, but rather set the bootmenu
- * to disabled */
- VIR_WARN("disabling bootmenu due to unknown option '%s'",
- tmp);
- def->os.bootmenu = VIR_TRISTATE_BOOL_NO;
- }
- VIR_FREE(tmp);
- }
+ if (virXMLPropTristateBool(node, "enable",
+ VIR_XML_PROP_NONE,
+ &def->os.bootmenu) < 0)
+ return -1;
tmp = virXMLPropString(node, "timeout");
if (tmp && def->os.bootmenu == VIR_TRISTATE_BOOL_YES) {
features = g_new0(int, VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_LAST);
for (i = 0; i < n; i++) {
- g_autofree char *name = virXMLPropString(nodes[i], "name");
- g_autofree char *enabled = virXMLPropString(nodes[i], "enabled");
- int feature = virDomainOsDefFirmwareFeatureTypeFromString(name);
- int val = virTristateBoolTypeFromString(enabled);
+ unsigned int feature;
+ virTristateBool enabled;
- if (feature < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("invalid firmware feature name '%s'"),
- name);
+ if (virXMLPropEnum(nodes[i], "name",
+ virDomainOsDefFirmwareFeatureTypeFromString,
+ VIR_XML_PROP_REQUIRED,
+ &feature) < 0)
return -1;
- }
- if (val < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("invalid firmware feature enabled value '%s'"),
- enabled);
+ if (virXMLPropTristateBool(nodes[i], "enabled",
+ VIR_XML_PROP_REQUIRED,
+ &enabled) < 0)
return -1;
- }
- features[feature] = val;
+ features[feature] = enabled;
}
def->os.firmwareFeatures = g_steal_pointer(&features);
return -1;
if (virDomainPMStateParseXML(ctxt,
- "string(./pm/suspend-to-mem/@enabled)",
+ "./pm/suspend-to-mem",
&def->pm.s3) < 0)
return -1;
if (virDomainPMStateParseXML(ctxt,
- "string(./pm/suspend-to-disk/@enabled)",
+ "./pm/suspend-to-disk",
&def->pm.s4) < 0)
return -1;
break;
case VIR_TRISTATE_BOOL_ABSENT:
case VIR_TRISTATE_BOOL_NO:
+ case VIR_TRISTATE_BOOL_LAST:
actual->data.hostdev.def.managed = false;
break;
}
struct _virDomainHostdevSubsysSCSI {
int protocol; /* enum virDomainHostdevSCSIProtocolType */
int sgio; /* enum virDomainDeviceSGIO */
- int rawio; /* enum virTristateBool */
+ virTristateBool rawio;
union {
virDomainHostdevSubsysSCSIHost host;
virDomainHostdevSubsysSCSIiSCSI iscsi;
VIR_ENUM_DECL(virDomainVideoVGAConf);
struct _virDomainVideoAccelDef {
- int accel2d; /* enum virTristateBool */
- int accel3d; /* enum virTristateBool */
+ virTristateBool accel2d;
+ virTristateBool accel3d;
char *rendernode;
};
char *machine;
size_t nBootDevs;
int bootDevs[VIR_DOMAIN_BOOT_LAST];
- int bootmenu; /* enum virTristateBool */
+ virTristateBool bootmenu;
unsigned int bm_timeout;
bool bm_timeout_set;
char *init;
};
struct _virDomainPowerManagement {
- /* These options are of type enum virTristateBool */
- int s3;
- int s4;
+ virTristateBool s3;
+ virTristateBool s4;
};
struct _virDomainPerfDef {
g_autofree xmlNodePtr *srvNodes = NULL;
g_autofree xmlNodePtr *txtNodes = NULL;
g_autofree xmlNodePtr *fwdNodes = NULL;
- g_autofree char *forwardPlainNames = NULL;
- g_autofree char *enable = NULL;
int nhosts, nsrvs, ntxts, nfwds;
size_t i;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
ctxt->node = node;
- enable = virXPathString("string(./@enable)", ctxt);
- if (enable) {
- def->enable = virTristateBoolTypeFromString(enable);
- if (def->enable <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid dns enable setting '%s' "
- "in network '%s'"),
- enable, networkName);
- return -1;
- }
- }
+ if (virXMLPropTristateBool(node, "enable",
+ VIR_XML_PROP_NONE,
+ &def->enable) < 0)
+ return -1;
- forwardPlainNames = virXPathString("string(./@forwardPlainNames)", ctxt);
- if (forwardPlainNames) {
- def->forwardPlainNames = virTristateBoolTypeFromString(forwardPlainNames);
- if (def->forwardPlainNames <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid dns forwardPlainNames setting '%s' "
- "in network '%s'"),
- forwardPlainNames, networkName);
- return -1;
- }
- }
+ if (virXMLPropTristateBool(node, "forwardPlainNames",
+ VIR_XML_PROP_NONE,
+ &def->forwardPlainNames) < 0)
+ return -1;
nfwds = virXPathNodeSet("./forwarder", ctxt, &fwdNodes);
if (nfwds < 0) {
xmlNodePtr dhcp;
g_autofree char *address = NULL;
g_autofree char *netmask = NULL;
- g_autofree char *localPtr = NULL;
unsigned long prefix = 0;
int prefixRc;
int ret = -1;
else
def->prefix = prefix;
- localPtr = virXPathString("string(./@localPtr)", ctxt);
- if (localPtr) {
- def->localPTR = virTristateBoolTypeFromString(localPtr);
- if (def->localPTR <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid localPtr value '%s' in network '%s'"),
- localPtr, networkName);
- goto cleanup;
- }
- }
+ if (virXMLPropTristateBool(node, "localPtr",
+ VIR_XML_PROP_NONE,
+ &def->localPTR) < 0)
+ goto cleanup;
/* validate address, etc. for each family */
if ((def->family == NULL) || (STREQ(def->family, "ipv4"))) {
virNetworkPortOptionsParseXML(xmlXPathContextPtr ctxt,
virTristateBool *isolatedPort)
{
- g_autofree char *str = NULL;
- int tmp = VIR_TRISTATE_BOOL_ABSENT;
-
- if ((str = virXPathString("string(./port/@isolated)", ctxt))) {
- if ((tmp = virTristateBoolTypeFromString(str)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("unknown port isolated value '%s'"), str);
- return -1;
- }
- }
+ xmlNodePtr port_node = virXPathNode("./port", ctxt);
- *isolatedPort = tmp;
- return 0;
+ return virXMLPropTristateBool(port_node, "isolated",
+ VIR_XML_PROP_NONE,
+ isolatedPort);
}
xmlNodePtr vlanNode;
xmlNodePtr bandwidth_node;
g_autofree char *isDefault = NULL;
- g_autofree char *trustGuestRxFilters = NULL;
int ret = -1;
isDefault = virXPathString("string(./@default)", ctxt);
def->isDefault = isDefault && STRCASEEQ(isDefault, "yes");
- trustGuestRxFilters
- = virXPathString("string(./@trustGuestRxFilters)", ctxt);
- if (trustGuestRxFilters) {
- if ((def->trustGuestRxFilters
- = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid trustGuestRxFilters setting '%s' "
- "in portgroup"), trustGuestRxFilters);
- goto cleanup;
- }
- }
+ if (virXMLPropTristateBool(node, "trustGuestRxFilters",
+ VIR_XML_PROP_NONE,
+ &def->trustGuestRxFilters) < 0)
+ goto cleanup;
virtPortNode = virXPathNode("./virtualport", ctxt);
if (virtPortNode &&
{
g_autoptr(virNetworkDef) def = NULL;
g_autofree char *uuid = NULL;
- g_autofree char *localOnly = NULL;
g_autofree char *stp = NULL;
g_autofree char *stpDelay = NULL;
g_autofree char *macTableManager = NULL;
xmlNodePtr virtPortNode = NULL;
xmlNodePtr forwardNode = NULL;
g_autofree char *ipv6nogwStr = NULL;
- g_autofree char *trustGuestRxFilters = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
xmlNodePtr bandwidthNode = NULL;
xmlNodePtr vlanNode;
xmlNodePtr metadataNode = NULL;
+ xmlNodePtr domain_node = NULL;
def = g_new0(virNetworkDef, 1);
}
}
- trustGuestRxFilters
- = virXPathString("string(./@trustGuestRxFilters)", ctxt);
- if (trustGuestRxFilters) {
- if ((def->trustGuestRxFilters
- = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid trustGuestRxFilters setting '%s' "
- "in network '%s'"),
- trustGuestRxFilters, def->name);
- return NULL;
- }
- }
+ if (virXMLPropTristateBool(ctxt->node, "trustGuestRxFilters",
+ VIR_XML_PROP_NONE,
+ &def->trustGuestRxFilters) < 0)
+ return NULL;
/* Parse network domain information */
- def->domain = virXPathString("string(./domain[1]/@name)", ctxt);
- localOnly = virXPathString("string(./domain[1]/@localOnly)", ctxt);
- if (localOnly) {
- def->domainLocalOnly = virTristateBoolTypeFromString(localOnly);
- if (def->domainLocalOnly <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid domain localOnly setting '%s' "
- "in network '%s'"),
- localOnly, def->name);
- return NULL;
- }
- }
+ domain_node = virXPathNode("./domain[1]", ctxt);
+ def->domain = virXMLPropString(domain_node, "name");
+ if (virXMLPropTristateBool(domain_node, "localOnly",
+ VIR_XML_PROP_NONE,
+ &def->domainLocalOnly) < 0)
+ return NULL;
if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) &&
virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, false) < 0)
typedef struct _virNetworkDNSDef virNetworkDNSDef;
struct _virNetworkDNSDef {
- int enable; /* enum virTristateBool */
- int forwardPlainNames; /* enum virTristateBool */
+ virTristateBool enable;
+ virTristateBool forwardPlainNames;
size_t ntxts;
virNetworkDNSTxtDef *txts;
size_t nhosts;
unsigned int prefix; /* ipv6 - only prefix allowed */
virSocketAddr netmask; /* ipv4 - either netmask or prefix specified */
- int localPTR; /* virTristateBool */
+ virTristateBool localPTR;
size_t nranges; /* Zero or more dhcp ranges */
virNetworkDHCPRangeDef *ranges;
virNetDevVPortProfile *virtPortProfile;
virNetDevBandwidth *bandwidth;
virNetDevVlan vlan;
- int trustGuestRxFilters; /* enum virTristateBool */
+ virTristateBool trustGuestRxFilters;
};
typedef struct _virNetworkDef virNetworkDef;
char *bridgeZone; /* name of firewalld zone for bridge */
int macTableManager; /* enum virNetworkBridgeMACTableManager */
char *domain;
- int domainLocalOnly; /* enum virTristateBool: yes disables dns forwarding */
+ virTristateBool domainLocalOnly; /* yes disables dns forwarding */
unsigned long delay; /* Bridge forward delay (ms) */
bool stp; /* Spanning tree protocol */
unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in config */
virPortGroupDef *portGroups;
virNetDevBandwidth *bandwidth;
virNetDevVlan vlan;
- int trustGuestRxFilters; /* enum virTristateBool */
+ virTristateBool trustGuestRxFilters;
virTristateBool isolatedPort;
/* Application-specific custom metadata */
virStoragePoolDefParseFeatures(virStoragePoolDef *def,
xmlXPathContextPtr ctxt)
{
- g_autofree char *cow = virXPathString("string(./features/cow/@state)", ctxt);
+ xmlNodePtr node = virXPathNode("./features/cow", ctxt);
+ virTristateBool val;
+ int rv;
- if (cow) {
- int val;
+ if ((rv = virXMLPropTristateBool(node, "state",
+ VIR_XML_PROP_NONE,
+ &val)) < 0) {
+ return -1;
+ } else if (rv > 0) {
if (def->type != VIR_STORAGE_POOL_FS &&
def->type != VIR_STORAGE_POOL_DIR) {
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("cow feature may only be used for 'fs' and 'dir' pools"));
return -1;
}
- if ((val = virTristateBoolTypeFromString(cow)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("invalid storage pool cow feature state '%s'"),
- cow);
- return -1;
- }
def->features.cow = val;
}
{
virStoragePRDef *prd;
virStoragePRDef *ret = NULL;
- g_autofree char *managed = NULL;
g_autofree char *type = NULL;
g_autofree char *path = NULL;
g_autofree char *mode = NULL;
prd = g_new0(virStoragePRDef, 1);
- if (!(managed = virXPathString("string(./@managed)", ctxt))) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("missing @managed attribute for <reservations/>"));
- goto cleanup;
- }
-
- if ((prd->managed = virTristateBoolTypeFromString(managed)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("invalid value for 'managed': %s"), managed);
+ if (virXMLPropTristateBool(ctxt->node, "managed",
+ VIR_XML_PROP_REQUIRED,
+ &prd->managed) < 0)
goto cleanup;
- }
type = virXPathString("string(./source[1]/@type)", ctxt);
path = virXPathString("string(./source[1]/@path)", ctxt);
typedef struct _virStoragePRDef virStoragePRDef;
struct _virStoragePRDef {
- int managed; /* enum virTristateBool */
+ virTristateBool managed;
char *path;
/* manager object alias */
xmlNodePtr vlanNode;
xmlNodePtr bandwidthNode;
xmlNodePtr addressNode;
- g_autofree char *trustGuestRxFilters = NULL;
+ xmlNodePtr rxfiltersNode = NULL;
+ xmlNodePtr plugNode = NULL;
g_autofree char *mac = NULL;
g_autofree char *macmgr = NULL;
g_autofree char *mode = NULL;
g_autofree char *plugtype = NULL;
- g_autofree char *managed = NULL;
g_autofree char *driver = NULL;
def = g_new0(virNetworkPortDef, 1);
if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0)
return NULL;
- trustGuestRxFilters
- = virXPathString("string(./rxfilters/@trustGuest)", ctxt);
- if (trustGuestRxFilters) {
- if ((def->trustGuestRxFilters
- = virTristateBoolTypeFromString(trustGuestRxFilters)) <= 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid guest rx filters trust setting '%s' "),
- trustGuestRxFilters);
- return NULL;
- }
- }
+ rxfiltersNode = virXPathNode("./rxfilters", ctxt);
+ if (virXMLPropTristateBool(rxfiltersNode, "trustGuest",
+ VIR_XML_PROP_NONE,
+ &def->trustGuestRxFilters) < 0)
+ return NULL;
+ plugNode = virXPathNode("./plug", ctxt);
plugtype = virXPathString("string(./plug/@type)", ctxt);
if (plugtype &&
break;
case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI:
- managed = virXPathString("string(./plug/@managed)", ctxt);
- if (managed &&
- (def->plug.hostdevpci.managed =
- virTristateBoolTypeFromString(managed)) < 0) {
- virReportError(VIR_ERR_XML_ERROR,
- _("Invalid managed setting '%s' in network port"), mode);
+ if (virXMLPropTristateBool(plugNode, "managed",
+ VIR_XML_PROP_NONE,
+ &def->plug.hostdevpci.managed) < 0)
return NULL;
- }
driver = virXPathString("string(./plug/driver/@name)", ctxt);
if (driver &&
(def->plug.hostdevpci.driver =
virNetDevBandwidth *bandwidth;
unsigned int class_id; /* class ID for bandwidth 'floor' */
virNetDevVlan vlan;
- int trustGuestRxFilters; /* enum virTristateBool */
+ virTristateBool trustGuestRxFilters;
virTristateBool isolatedPort;
int plugtype; /* virNetworkPortPlugType */
struct {
virPCIDeviceAddress addr; /* PCI Address of device */
int driver; /* virNetworkForwardDriverNameType */
- int managed;
+ virTristateBool managed;
} hostdevpci;
} plug;
};
for (i = 0; i < n; i++) {
g_autofree char *ftname = NULL;
- g_autofree char *removed = NULL;
virCPUx86Feature *feature;
+ virTristateBool rem;
if (!(ftname = virXMLPropString(nodes[i], "name"))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
return -1;
}
- if ((removed = virXMLPropString(nodes[i], "removed"))) {
- int rem;
-
- if ((rem = virTristateBoolTypeFromString(removed)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Invalid 'removed' attribute for feature %s "
- "in model %s"),
- ftname, model->name);
- return -1;
- }
+ if (virXMLPropTristateBool(nodes[i], "removed",
+ VIR_XML_PROP_NONE,
+ &rem) < 0)
+ return -1;
- if (rem == VIR_TRISTATE_BOOL_YES) {
- model->removedFeatures[nremoved++] = g_strdup(ftname);
- continue;
- }
+ if (rem == VIR_TRISTATE_BOOL_YES) {
+ model->removedFeatures[nremoved++] = g_strdup(ftname);
+ continue;
}
if (x86DataAdd(&model->data, &feature->data))
xmlXPathContextPtr ctxt,
const char *typeStr)
{
- g_autofree char *migratability = NULL;
xmlNodePtr hostCPUNode;
g_autofree xmlNodePtr *nodes = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
g_autofree char *xpath = g_strdup_printf("./hostCPU[@type='%s']", typeStr);
size_t i;
int n;
+ virTristateBool migratability;
int val;
if (!(hostCPUNode = virXPathNode(xpath, ctxt))) {
return -1;
}
- if (!(migratability = virXMLPropString(hostCPUNode, "migratability")) ||
- (val = virTristateBoolTypeFromString(migratability)) <= 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("invalid migratability value for host CPU model"));
+ if (virXMLPropTristateBool(hostCPUNode, "migratability",
+ VIR_XML_PROP_REQUIRED,
+ &migratability) < 0)
return -1;
- }
- hostCPU->migratability = val == VIR_TRISTATE_BOOL_YES;
+
+ virTristateBoolToBool(migratability, &hostCPU->migratability);
ctxt->node = hostCPUNode;
for (i = 0; i < n; i++) {
qemuMonitorCPUProperty *prop = hostCPU->props + i;
g_autofree char *type = NULL;
- g_autofree char *migratable = NULL;
ctxt->node = nodes[i];
break;
}
- if ((migratable = virXMLPropString(ctxt->node, "migratable"))) {
- if ((val = virTristateBoolTypeFromString(migratable)) <= 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown migratable value for '%s' host "
- "CPU model property"),
- prop->name);
- return -1;
- }
+ if (virXMLPropTristateBool(ctxt->node, "migratable",
+ VIR_XML_PROP_NONE,
+ &prop->migratable) < 0)
+ return -1;
- prop->migratable = val;
- }
}
}
qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt,
virTristateBool *allowReboot)
{
- int val;
- g_autofree char *valStr = NULL;
+ xmlNodePtr node = virXPathNode("./allowReboot", ctxt);
- if ((valStr = virXPathString("string(./allowReboot/@value)", ctxt))) {
- if ((val = virTristateBoolTypeFromString(valStr)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("invalid allowReboot value '%s'"), valStr);
- return -1;
- }
- *allowReboot = val;
- }
-
- return 0;
+ return virXMLPropTristateBool(node, "value",
+ VIR_XML_PROP_NONE,
+ allowReboot);
}