This helper performs a conversion from a "yes|no" string
to a corresponding boolean, and several conversions were
already done, but there are still some omissions.
For most of the remaining usages in domain_conf.c only
"yes" is explicitly checked for. This means all other
values are implicitly handled as 'false'. In this case,
use virStringParseYesNo, but if it returns -1, don't
raise an error but set the bool value to false.
Cc: crobinso(a)redhat.com
Cc: berrange(a)redhat.com
Cc: abologna(a)redhat.com
Cc: laine(a)laine.org
Cc: phrdina(a)redhat.com
Cc: mkletzan(a)redhat.com
Cc: g.sho1500(a)gmail.com
Signed-off-by: Mao Zhongyi <maozhongyi(a)cmss.chinamobile.com>
Signed-off-by: Zhang Shengju <zhangshengju(a)cmss.chinamobile.com>
---
src/conf/domain_conf.c | 30 ++++++++++++++----------------
1 file changed, 14 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 10d6bf0eea..7420658726 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7601,8 +7601,8 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
}
if ((autoAddress = virXMLPropString(node, "autoAddress"))) {
- if (STREQ(autoAddress, "yes"))
- usbsrc->autoAddress = true;
+ if (virStringParseYesNo(autoAddress, &usbsrc->autoAddress) < 0)
+ usbsrc->autoAddress = false;
}
/* Product can validly be 0, so we need some extra help to determine
@@ -8168,8 +8168,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
* (e.g. <interface>) with type='hostdev')
*/
if ((managed = virXMLPropString(node, "managed")) != NULL) {
- if (STREQ(managed, "yes"))
- def->managed = true;
+ if (virStringParseYesNo(managed, &def->managed) < 0)
+ def->managed = false;
}
sgio = virXMLPropString(node, "sgio");
@@ -13807,9 +13807,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr
def,
if (autoGenerated &&
flags & VIR_DOMAIN_DEF_PARSE_STATUS) {
- if (STREQ(autoGenerated, "yes")) {
- def->autoGenerated = true;
- } else if (STRNEQ(autoGenerated, "no")) {
+ if (virStringParseYesNo(autoGenerated, &def->autoGenerated) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("Invalid autoGenerated value: %s"),
autoGenerated);
@@ -13939,12 +13937,11 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
}
if (autoport) {
- if (STREQ(autoport, "yes")) {
- if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)
- def->data.vnc.port = 0;
- def->data.vnc.autoport = true;
- } else {
+ if (virStringParseYesNo(autoport, &def->data.vnc.autoport) < 0) {
def->data.vnc.autoport = false;
+ } else {
+ if (def->data.vnc.autoport && flags &
VIR_DOMAIN_DEF_PARSE_INACTIVE)
+ def->data.vnc.port = 0;
}
}
@@ -13958,8 +13955,9 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
}
}
- if (websocketGenerated && STREQ(websocketGenerated, "yes"))
- def->data.vnc.websocketGenerated = true;
+ if (websocketGenerated &&
+ virStringParseYesNo(websocketGenerated,
&def->data.vnc.websocketGenerated))
+ def->data.vnc.websocketGenerated = false;
if (sharePolicy) {
int policy =
@@ -15479,8 +15477,8 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xmlopt,
heads = virXMLPropString(cur, "heads");
if ((primary = virXMLPropString(cur, "primary")) != NULL) {
- if (STREQ(primary, "yes"))
- def->primary = true;
+ if (virStringParseYesNo(primary, &def->primary) < 0)
+ def->primary = false;
VIR_FREE(primary);
}
--
2.17.1