domain_conf: split graphics xml parser into multiple functions

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2016-03-02 17:03:39 +01:00
parent dc98a5bc59
commit 537d32a2fd

View File

@ -10764,39 +10764,16 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def,
}
/* Parse the XML definition for a graphics device */
static virDomainGraphicsDefPtr
virDomainGraphicsDefParseXML(xmlNodePtr node,
xmlXPathContextPtr ctxt,
static int
virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
xmlNodePtr node,
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) {
char *port = virXMLPropString(node, "port");
char *websocket = virXMLPropString(node, "websocket");
char *sharePolicy = virXMLPropString(node, "sharePolicy");
char *autoport;
int ret = -1;
if (port) {
if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) {
@ -10859,7 +10836,17 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth,
def->type) < 0)
goto error;
} else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
ret = 0;
error:
return ret;
}
static int
virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def,
xmlNodePtr node)
{
char *fullscreen = virXMLPropString(node, "fullscreen");
if (fullscreen != NULL) {
@ -10871,7 +10858,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown fullscreen value '%s'"), fullscreen);
VIR_FREE(fullscreen);
goto error;
return -1;
}
VIR_FREE(fullscreen);
} else {
@ -10879,11 +10866,21 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
}
def->data.sdl.xauth = virXMLPropString(node, "xauth");
def->data.sdl.display = virXMLPropString(node, "display");
} else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) {
return 0;
}
static int
virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def,
xmlNodePtr node,
unsigned int flags)
{
char *port = virXMLPropString(node, "port");
char *autoport;
char *replaceUser;
char *multiUser;
int ret = -1;
if (port) {
if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) {
@ -10924,7 +10921,16 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
VIR_FREE(multiUser);
}
} else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) {
ret = 0;
error:
return ret;
}
static int
virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def,
xmlNodePtr node)
{
char *fullscreen = virXMLPropString(node, "fullscreen");
if (fullscreen != NULL) {
@ -10936,7 +10942,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown fullscreen value '%s'"), fullscreen);
VIR_FREE(fullscreen);
goto error;
return -1;
}
VIR_FREE(fullscreen);
} else {
@ -10944,13 +10950,22 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
}
def->data.desktop.display = virXMLPropString(node, "display");
} else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
return 0;
}
static int
virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def,
xmlNodePtr node,
unsigned int flags)
{
xmlNodePtr cur;
char *port = virXMLPropString(node, "port");
char *tlsPort;
char *autoport;
char *defaultMode;
int defaultModeVal;
int ret = -1;
if (port) {
if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) {
@ -11238,6 +11253,64 @@ virDomainGraphicsDefParseXML(xmlNodePtr node,
}
cur = cur->next;
}
ret = 0;
error:
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;
switch ((virDomainGraphicsType)def->type) {
case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
if (virDomainGraphicsDefParseXMLVNC(def, node, flags) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
if (virDomainGraphicsDefParseXMLSDL(def, node) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
if (virDomainGraphicsDefParseXMLRDP(def, node, flags) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
if (virDomainGraphicsDefParseXMLDesktop(def, node) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
if (virDomainGraphicsDefParseXMLSpice(def, node, flags) < 0)
goto error;
break;
case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
break;
}
cleanup: