mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-26 14:03:49 +03:00
domain_conf: cleanup virDomainGraphicsListensParseXML
Refactor the listen parser to use only one loop. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
ffce6090f6
commit
dc98a5bc59
@ -10692,86 +10692,69 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
|
|||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
int nListens;
|
|
||||||
xmlNodePtr *listenNodes = NULL;
|
xmlNodePtr *listenNodes = NULL;
|
||||||
char *listenAddr = NULL;
|
|
||||||
xmlNodePtr save = ctxt->node;
|
xmlNodePtr save = ctxt->node;
|
||||||
|
virDomainGraphicsListenDefPtr address = NULL;
|
||||||
|
char *listenAddr = NULL;
|
||||||
|
int nListens;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ||
|
|
||||||
def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP ||
|
|
||||||
def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
|
|
||||||
|
|
||||||
/* parse the <listen> subelements for graphics types that support it */
|
if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
|
||||||
nListens = virXPathNodeSet("./listen", ctxt, &listenNodes);
|
def->type != VIR_DOMAIN_GRAPHICS_TYPE_RDP &&
|
||||||
if (nListens < 0)
|
def->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
|
||||||
|
ret = 0;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* parse the <listen> subelements for graphics types that support it */
|
||||||
|
nListens = virXPathNodeSet("./listen", ctxt, &listenNodes);
|
||||||
|
if (nListens < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (nListens > 0) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (VIR_ALLOC_N(def->listens, nListens) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (nListens > 0) {
|
for (i = 0; i < nListens; i++) {
|
||||||
size_t i;
|
if (virDomainGraphicsListenDefParseXML(&def->listens[i],
|
||||||
|
listenNodes[i],
|
||||||
if (VIR_ALLOC_N(def->listens, nListens) < 0)
|
flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
for (i = 0; i < nListens; i++) {
|
if (!address &&
|
||||||
int rv = virDomainGraphicsListenDefParseXML(&def->listens[i],
|
def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS)
|
||||||
listenNodes[i],
|
address = &def->listens[i];
|
||||||
flags);
|
|
||||||
if (rv < 0)
|
def->nListens++;
|
||||||
goto error;
|
|
||||||
def->nListens++;
|
|
||||||
}
|
|
||||||
VIR_FREE(listenNodes);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* listen attribute of <graphics> is also supported by these,
|
|
||||||
* but must match the 'address' attribute of the first listen
|
|
||||||
* that is type='address' (if present) */
|
|
||||||
listenAddr = virXMLPropString(node, "listen");
|
|
||||||
if (listenAddr && !listenAddr[0])
|
|
||||||
VIR_FREE(listenAddr);
|
|
||||||
|
|
||||||
if (listenAddr) {
|
|
||||||
if (def->nListens == 0) {
|
|
||||||
/* There were no <listen> elements, so we can just
|
|
||||||
* directly set listenAddr as listens[0]->address */
|
|
||||||
if (virDomainGraphicsListenSetAddress(def, 0, listenAddr,
|
|
||||||
-1, true) < 0)
|
|
||||||
goto error;
|
|
||||||
} else {
|
|
||||||
/* There is at least 1 listen element, so we look for
|
|
||||||
* the first listen of type='address', and make sure
|
|
||||||
* its address matches the listen attribute from
|
|
||||||
* graphics. */
|
|
||||||
bool matched = false;
|
|
||||||
const char *found = NULL;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < nListens; i++) {
|
|
||||||
if (virDomainGraphicsListenGetType(def, i)
|
|
||||||
== VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
|
|
||||||
found = virDomainGraphicsListenGetAddress(def, i);
|
|
||||||
if (STREQ_NULLABLE(found, listenAddr))
|
|
||||||
matched = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found && !matched) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("graphics listen attribute %s must match address "
|
|
||||||
"attribute of first listen element (found %s)"),
|
|
||||||
listenAddr, found);
|
|
||||||
goto error;
|
|
||||||
} else if (!found) {
|
|
||||||
/* quietly ignore listen address if none of the listens
|
|
||||||
* are of type address */
|
|
||||||
VIR_FREE(listenAddr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
VIR_FREE(listenNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* listen attribute of <graphics> is also supported by these,
|
||||||
|
* but must match the 'address' attribute of the first listen
|
||||||
|
* that is type='address' (if present) */
|
||||||
|
listenAddr = virXMLPropString(node, "listen");
|
||||||
|
if (STREQ_NULLABLE(listenAddr, ""))
|
||||||
|
VIR_FREE(listenAddr);
|
||||||
|
|
||||||
|
if (address && STRNEQ_NULLABLE(address->address, listenAddr)) {
|
||||||
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
|
_("graphics listen attribute %s must match address "
|
||||||
|
"attribute of first listen element (found %s)"),
|
||||||
|
listenAddr, address->address);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There were no <listen> elements, so we can just
|
||||||
|
* directly set listenAddr as listens[0]->address */
|
||||||
|
if (listenAddr && def->nListens == 0 &&
|
||||||
|
virDomainGraphicsListenSetAddress(def, 0, listenAddr, -1, true) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
error:
|
error:
|
||||||
VIR_FREE(listenNodes);
|
VIR_FREE(listenNodes);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user