From 7d0ff9430bfc03aaad83e28bd608725e0d970ea8 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 18 Aug 2017 17:12:59 +0200 Subject: [PATCH] conf: switch from while to for loop for chardev parsing This removes one level of indentation. Signed-off-by: Pavel Hrdina --- src/conf/domain_conf.c | 166 ++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6f0f038b77..d77983069a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10926,100 +10926,100 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def, char *haveTLS = NULL; char *tlsFromConfig = NULL; - while (cur != NULL) { - if (cur->type == XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "source")) { - if (!mode) - mode = virXMLPropString(cur, "mode"); - if (!haveTLS) - haveTLS = virXMLPropString(cur, "tls"); - if (!tlsFromConfig) - tlsFromConfig = virXMLPropString(cur, "tlsFromConfig"); - - switch ((virDomainChrType) def->type) { - case VIR_DOMAIN_CHR_TYPE_FILE: - case VIR_DOMAIN_CHR_TYPE_PTY: - case VIR_DOMAIN_CHR_TYPE_DEV: - case VIR_DOMAIN_CHR_TYPE_PIPE: - case VIR_DOMAIN_CHR_TYPE_UNIX: - if (!append && def->type == VIR_DOMAIN_CHR_TYPE_FILE) - append = virXMLPropString(cur, "append"); - /* PTY path is only parsed from live xml. */ - if (!path && - (def->type != VIR_DOMAIN_CHR_TYPE_PTY || - !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) - path = virXMLPropString(cur, "path"); + for (; cur; cur = cur->next) { + if (cur->type != XML_ELEMENT_NODE) + continue; - break; + if (virXMLNodeNameEqual(cur, "source")) { + if (!mode) + mode = virXMLPropString(cur, "mode"); + if (!haveTLS) + haveTLS = virXMLPropString(cur, "tls"); + if (!tlsFromConfig) + tlsFromConfig = virXMLPropString(cur, "tlsFromConfig"); + + switch ((virDomainChrType) def->type) { + case VIR_DOMAIN_CHR_TYPE_FILE: + case VIR_DOMAIN_CHR_TYPE_PTY: + case VIR_DOMAIN_CHR_TYPE_DEV: + case VIR_DOMAIN_CHR_TYPE_PIPE: + case VIR_DOMAIN_CHR_TYPE_UNIX: + if (!append && def->type == VIR_DOMAIN_CHR_TYPE_FILE) + append = virXMLPropString(cur, "append"); + /* PTY path is only parsed from live xml. */ + if (!path && + (def->type != VIR_DOMAIN_CHR_TYPE_PTY || + !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) + path = virXMLPropString(cur, "path"); - case VIR_DOMAIN_CHR_TYPE_UDP: - case VIR_DOMAIN_CHR_TYPE_TCP: - if (!mode || STREQ(mode, "connect")) { - if (!connectHost) - connectHost = virXMLPropString(cur, "host"); - if (!connectService) - connectService = virXMLPropString(cur, "service"); - } else if (STREQ(mode, "bind")) { - if (!bindHost) - bindHost = virXMLPropString(cur, "host"); - if (!bindService) - bindService = virXMLPropString(cur, "service"); - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown source mode '%s'"), mode); - goto error; - } + break; - if (def->type == VIR_DOMAIN_CHR_TYPE_UDP) - VIR_FREE(mode); - break; + case VIR_DOMAIN_CHR_TYPE_UDP: + case VIR_DOMAIN_CHR_TYPE_TCP: + if (!mode || STREQ(mode, "connect")) { + if (!connectHost) + connectHost = virXMLPropString(cur, "host"); + if (!connectService) + connectService = virXMLPropString(cur, "service"); + } else if (STREQ(mode, "bind")) { + if (!bindHost) + bindHost = virXMLPropString(cur, "host"); + if (!bindService) + bindService = virXMLPropString(cur, "service"); + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown source mode '%s'"), mode); + goto error; + } - case VIR_DOMAIN_CHR_TYPE_SPICEPORT: - if (!channel) - channel = virXMLPropString(cur, "channel"); - break; + if (def->type == VIR_DOMAIN_CHR_TYPE_UDP) + VIR_FREE(mode); + break; - case VIR_DOMAIN_CHR_TYPE_NMDM: - if (!master) - master = virXMLPropString(cur, "master"); - if (!slave) - slave = virXMLPropString(cur, "slave"); - break; + case VIR_DOMAIN_CHR_TYPE_SPICEPORT: + if (!channel) + channel = virXMLPropString(cur, "channel"); + break; - case VIR_DOMAIN_CHR_TYPE_LAST: - case VIR_DOMAIN_CHR_TYPE_NULL: - case VIR_DOMAIN_CHR_TYPE_VC: - case VIR_DOMAIN_CHR_TYPE_STDIO: - case VIR_DOMAIN_CHR_TYPE_SPICEVMC: - break; - } + case VIR_DOMAIN_CHR_TYPE_NMDM: + if (!master) + master = virXMLPropString(cur, "master"); + if (!slave) + slave = virXMLPropString(cur, "slave"); + break; - /* Check for an optional seclabel override in . */ - if (chr_def) { - xmlNodePtr saved_node = ctxt->node; - ctxt->node = cur; - if (virSecurityDeviceLabelDefParseXML(&def->seclabels, - &def->nseclabels, - vmSeclabels, - nvmSeclabels, - ctxt, - flags) < 0) { - ctxt->node = saved_node; - goto error; - } + case VIR_DOMAIN_CHR_TYPE_LAST: + case VIR_DOMAIN_CHR_TYPE_NULL: + case VIR_DOMAIN_CHR_TYPE_VC: + case VIR_DOMAIN_CHR_TYPE_STDIO: + case VIR_DOMAIN_CHR_TYPE_SPICEVMC: + break; + } + + /* Check for an optional seclabel override in . */ + if (chr_def) { + xmlNodePtr saved_node = ctxt->node; + ctxt->node = cur; + if (virSecurityDeviceLabelDefParseXML(&def->seclabels, + &def->nseclabels, + vmSeclabels, + nvmSeclabels, + ctxt, + flags) < 0) { ctxt->node = saved_node; + goto error; } - } else if (virXMLNodeNameEqual(cur, "log")) { - if (!logfile) - logfile = virXMLPropString(cur, "file"); - if (!logappend) - logappend = virXMLPropString(cur, "append"); - } else if (virXMLNodeNameEqual(cur, "protocol")) { - if (!protocol) - protocol = virXMLPropString(cur, "type"); + ctxt->node = saved_node; } + } else if (virXMLNodeNameEqual(cur, "log")) { + if (!logfile) + logfile = virXMLPropString(cur, "file"); + if (!logappend) + logappend = virXMLPropString(cur, "append"); + } else if (virXMLNodeNameEqual(cur, "protocol")) { + if (!protocol) + protocol = virXMLPropString(cur, "type"); } - cur = cur->next; } switch ((virDomainChrType) def->type) { -- GitLab