mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
conf: clean up virDomainChrSourceDefParseXML
Tweak some conditions and use correct typecasts in enums.
This commit is contained in:
parent
795527548f
commit
0dd948cb2b
@ -6905,17 +6905,17 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
while (cur != NULL) {
|
while (cur != NULL) {
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
if (cur->type == XML_ELEMENT_NODE) {
|
||||||
if (xmlStrEqual(cur->name, BAD_CAST "source")) {
|
if (xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
if (mode == NULL)
|
if (!mode)
|
||||||
mode = virXMLPropString(cur, "mode");
|
mode = virXMLPropString(cur, "mode");
|
||||||
|
|
||||||
switch (def->type) {
|
switch ((enum virDomainChrType) def->type) {
|
||||||
case VIR_DOMAIN_CHR_TYPE_PTY:
|
case VIR_DOMAIN_CHR_TYPE_PTY:
|
||||||
case VIR_DOMAIN_CHR_TYPE_DEV:
|
case VIR_DOMAIN_CHR_TYPE_DEV:
|
||||||
case VIR_DOMAIN_CHR_TYPE_FILE:
|
case VIR_DOMAIN_CHR_TYPE_FILE:
|
||||||
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
||||||
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
||||||
/* PTY path is only parsed from live xml. */
|
/* PTY path is only parsed from live xml. */
|
||||||
if (path == NULL &&
|
if (!path &&
|
||||||
(def->type != VIR_DOMAIN_CHR_TYPE_PTY ||
|
(def->type != VIR_DOMAIN_CHR_TYPE_PTY ||
|
||||||
!(flags & VIR_DOMAIN_XML_INACTIVE)))
|
!(flags & VIR_DOMAIN_XML_INACTIVE)))
|
||||||
path = virXMLPropString(cur, "path");
|
path = virXMLPropString(cur, "path");
|
||||||
@ -6924,27 +6924,32 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||||
if (mode == NULL ||
|
if (!mode || STREQ(mode, "connect")) {
|
||||||
STREQ((const char *)mode, "connect")) {
|
if (!connectHost)
|
||||||
|
|
||||||
if (connectHost == NULL)
|
|
||||||
connectHost = virXMLPropString(cur, "host");
|
connectHost = virXMLPropString(cur, "host");
|
||||||
if (connectService == NULL)
|
if (!connectService)
|
||||||
connectService = virXMLPropString(cur, "service");
|
connectService = virXMLPropString(cur, "service");
|
||||||
} else if (STREQ((const char *)mode, "bind")) {
|
} else if (STREQ(mode, "bind")) {
|
||||||
if (bindHost == NULL)
|
if (!bindHost)
|
||||||
bindHost = virXMLPropString(cur, "host");
|
bindHost = virXMLPropString(cur, "host");
|
||||||
if (bindService == NULL)
|
if (!bindService)
|
||||||
bindService = virXMLPropString(cur, "service");
|
bindService = virXMLPropString(cur, "service");
|
||||||
} else {
|
} else {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unknown source mode '%s'"),
|
_("Unknown source mode '%s'"), mode);
|
||||||
mode);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (def->type == VIR_DOMAIN_CHR_TYPE_UDP)
|
if (def->type == VIR_DOMAIN_CHR_TYPE_UDP)
|
||||||
VIR_FREE(mode);
|
VIR_FREE(mode);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for an optional seclabel override in <source/>. */
|
/* Check for an optional seclabel override in <source/>. */
|
||||||
@ -6963,7 +6968,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
ctxt->node = saved_node;
|
ctxt->node = saved_node;
|
||||||
}
|
}
|
||||||
} else if (xmlStrEqual(cur->name, BAD_CAST "protocol")) {
|
} else if (xmlStrEqual(cur->name, BAD_CAST "protocol")) {
|
||||||
if (protocol == NULL)
|
if (!protocol)
|
||||||
protocol = virXMLPropString(cur, "type");
|
protocol = virXMLPropString(cur, "type");
|
||||||
} else {
|
} else {
|
||||||
remaining++;
|
remaining++;
|
||||||
@ -6972,11 +6977,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (def->type) {
|
switch ((enum virDomainChrType) def->type) {
|
||||||
|
case VIR_DOMAIN_CHR_TYPE_LAST:
|
||||||
case VIR_DOMAIN_CHR_TYPE_NULL:
|
case VIR_DOMAIN_CHR_TYPE_NULL:
|
||||||
/* Nada */
|
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
||||||
break;
|
case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_VC:
|
case VIR_DOMAIN_CHR_TYPE_VC:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -6984,7 +6989,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
case VIR_DOMAIN_CHR_TYPE_DEV:
|
case VIR_DOMAIN_CHR_TYPE_DEV:
|
||||||
case VIR_DOMAIN_CHR_TYPE_FILE:
|
case VIR_DOMAIN_CHR_TYPE_FILE:
|
||||||
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
||||||
if (path == NULL &&
|
if (!path &&
|
||||||
def->type != VIR_DOMAIN_CHR_TYPE_PTY) {
|
def->type != VIR_DOMAIN_CHR_TYPE_PTY) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source path attribute for char device"));
|
_("Missing source path attribute for char device"));
|
||||||
@ -6995,20 +7000,15 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
path = NULL;
|
path = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
|
|
||||||
/* Nada */
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_TCP:
|
case VIR_DOMAIN_CHR_TYPE_TCP:
|
||||||
if (mode == NULL ||
|
if (!mode || STREQ(mode, "connect")) {
|
||||||
STREQ(mode, "connect")) {
|
if (!connectHost) {
|
||||||
if (connectHost == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source host attribute for char device"));
|
_("Missing source host attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (connectService == NULL) {
|
|
||||||
|
if (!connectService) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source service attribute for char device"));
|
_("Missing source service attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -7020,12 +7020,13 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
connectService = NULL;
|
connectService = NULL;
|
||||||
def->data.tcp.listen = false;
|
def->data.tcp.listen = false;
|
||||||
} else {
|
} else {
|
||||||
if (bindHost == NULL) {
|
if (!bindHost) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source host attribute for char device"));
|
_("Missing source host attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (bindService == NULL) {
|
|
||||||
|
if (!bindService) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source service attribute for char device"));
|
_("Missing source service attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
@ -7038,7 +7039,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
def->data.tcp.listen = true;
|
def->data.tcp.listen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protocol == NULL)
|
if (!protocol)
|
||||||
def->data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW;
|
def->data.tcp.protocol = VIR_DOMAIN_CHR_TCP_PROTOCOL_RAW;
|
||||||
else if ((def->data.tcp.protocol =
|
else if ((def->data.tcp.protocol =
|
||||||
virDomainChrTcpProtocolTypeFromString(protocol)) < 0) {
|
virDomainChrTcpProtocolTypeFromString(protocol)) < 0) {
|
||||||
@ -7050,7 +7051,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_CHR_TYPE_UDP:
|
case VIR_DOMAIN_CHR_TYPE_UDP:
|
||||||
if (connectService == NULL) {
|
if (!connectService) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("Missing source service attribute for char device"));
|
_("Missing source service attribute for char device"));
|
||||||
goto error;
|
goto error;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user