1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-02-04 21:47:16 +03:00

domain_conf: introduce virDomainGraphicsListensParseXML

Move code, that parses graphics listens, to its own function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2016-03-02 16:27:02 +01:00
parent f037a955a7
commit ffce6090f6

View File

@ -10686,38 +10686,19 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def,
} }
/* Parse the XML definition for a graphics device */ static int
static virDomainGraphicsDefPtr virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
virDomainGraphicsDefParseXML(xmlNodePtr node, xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
unsigned int flags) unsigned int flags)
{ {
virDomainGraphicsDefPtr def;
char *type = NULL;
int nListens; int nListens;
xmlNodePtr *listenNodes = NULL; xmlNodePtr *listenNodes = NULL;
char *listenAddr = NULL; char *listenAddr = NULL;
xmlNodePtr save = ctxt->node; xmlNodePtr save = ctxt->node;
int ret = -1;
if (VIR_ALLOC(def) < 0)
return NULL;
ctxt->node = node; ctxt->node = node;
type = virXMLPropString(node, "type");
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing graphics device type"));
goto error;
}
if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown graphics device type '%s'"), type);
goto error;
}
if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC || if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC ||
def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP || def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP ||
def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@ -10734,10 +10715,10 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
goto error; goto error;
for (i = 0; i < nListens; i++) { for (i = 0; i < nListens; i++) {
int ret = virDomainGraphicsListenDefParseXML(&def->listens[i], int rv = virDomainGraphicsListenDefParseXML(&def->listens[i],
listenNodes[i], listenNodes[i],
flags); flags);
if (ret < 0) if (rv < 0)
goto error; goto error;
def->nListens++; def->nListens++;
} }
@ -10791,6 +10772,43 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
} }
} }
ret = 0;
error:
VIR_FREE(listenNodes);
VIR_FREE(listenAddr);
ctxt->node = save;
return ret;
}
/* Parse the XML definition for a graphics device */
static virDomainGraphicsDefPtr
virDomainGraphicsDefParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt,
unsigned int flags)
{
virDomainGraphicsDefPtr def;
char *type = NULL;
if (VIR_ALLOC(def) < 0)
return NULL;
type = virXMLPropString(node, "type");
if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("missing graphics device type"));
goto error;
}
if ((def->type = virDomainGraphicsTypeFromString(type)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown graphics device type '%s'"), type);
goto error;
}
if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0)
goto error;
if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
char *port = virXMLPropString(node, "port"); char *port = virXMLPropString(node, "port");
char *websocket = virXMLPropString(node, "websocket"); char *websocket = virXMLPropString(node, "websocket");
@ -11241,10 +11259,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
cleanup: cleanup:
VIR_FREE(type); VIR_FREE(type);
VIR_FREE(listenNodes);
VIR_FREE(listenAddr);
ctxt->node = save;
return def; return def;
error: error: