conf: Move validation of virDomainGraphicsListenDef out of parser

In an effort to separate the validation steps from the Parse stage,
a few validation checks of virDomainGraphicsListenDef have been moved from
virDomainGraphicsListenDefParseXML() in domain_conf.c to
virDomainGraphicsDefListensValidate() in domain_validate.c

Signed-off-by: K Shiva <shiva_kr@riseup.net>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
K Shiva Kiran 2023-04-06 21:53:32 +05:30 committed by Michal Privoznik
parent d0ee8f37eb
commit 62f29b9f98
2 changed files with 31 additions and 35 deletions

View File

@ -10986,7 +10986,6 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node,
/** /**
* virDomainGraphicsListenDefParseXML: * virDomainGraphicsListenDefParseXML:
* @def: listen def pointer to be filled * @def: listen def pointer to be filled
* @graphics: graphics def pointer
* @node: xml node of <listen/> element * @node: xml node of <listen/> element
* @parent: xml node of <graphics/> element * @parent: xml node of <graphics/> element
* @flags: bit-wise or of VIR_DOMAIN_DEF_PARSE_* * @flags: bit-wise or of VIR_DOMAIN_DEF_PARSE_*
@ -10998,13 +10997,11 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node,
*/ */
static int static int
virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDef *def, virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDef *def,
virDomainGraphicsDef *graphics,
xmlNodePtr node, xmlNodePtr node,
xmlNodePtr parent, xmlNodePtr parent,
unsigned int flags) unsigned int flags)
{ {
int ret = -1; int ret = -1;
const char *graphicsType = virDomainGraphicsTypeToString(graphics->type);
g_autofree char *address = virXMLPropString(node, "address"); g_autofree char *address = virXMLPropString(node, "address");
g_autofree char *network = virXMLPropString(node, "network"); g_autofree char *network = virXMLPropString(node, "network");
g_autofree char *socketPath = virXMLPropString(node, "socket"); g_autofree char *socketPath = virXMLPropString(node, "socket");
@ -11021,31 +11018,6 @@ virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDef *def,
VIR_XML_PROP_REQUIRED, &def->type) < 0) VIR_XML_PROP_REQUIRED, &def->type) < 0)
goto error; goto error;
switch (def->type) {
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("listen type 'socket' is not available for graphics type '%1$s'"),
graphicsType);
goto error;
}
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("listen type 'none' is not available for graphics type '%1$s'"),
graphicsType);
goto error;
}
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
}
if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { if (def->type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
if (address && addressCompat && STRNEQ(address, addressCompat)) { if (address && addressCompat && STRNEQ(address, addressCompat)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -11148,7 +11120,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsDef *def,
def->listens = g_new0(virDomainGraphicsListenDef, nListens); def->listens = g_new0(virDomainGraphicsListenDef, nListens);
for (i = 0; i < nListens; i++) { for (i = 0; i < nListens; i++) {
if (virDomainGraphicsListenDefParseXML(&def->listens[i], def, if (virDomainGraphicsListenDefParseXML(&def->listens[i],
listenNodes[i], listenNodes[i],
i == 0 ? node : NULL, i == 0 ? node : NULL,
flags) < 0) flags) < 0)

View File

@ -2631,15 +2631,39 @@ static int
virDomainGraphicsDefListensValidate(const virDomainGraphicsDef *def) virDomainGraphicsDefListensValidate(const virDomainGraphicsDef *def)
{ {
size_t i; size_t i;
const char *graphicsType = virDomainGraphicsTypeToString(def->type);
for (i = 0; i < def->nListens; i++) { for (i = 0; i < def->nListens; i++) {
if (def->listens[i].type == VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && switch (def->listens[i].type) {
!def->listens[i].network) { case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
if (!def->listens[i].network) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("'network' attribute is required for " _("'network' attribute is required for listen type 'network'"));
"listen type 'network'"));
return -1; return -1;
} }
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET:
if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC &&
def->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("listen type 'socket' is not available for graphics type '%1$s'"),
graphicsType);
return -1;
}
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE:
if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE &&
def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("listen type 'none' is not available for graphics type '%1$s'"),
graphicsType);
return -1;
}
break;
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST:
break;
}
} }
return 0; return 0;