This prepares the code for other listen types.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/qemu/qemu_command.c | 57 ++++++++++++++++++++++---------------------------
1 file changed, 26 insertions(+), 31 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bca94fa..c6c1918 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7536,8 +7536,9 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
const char *listenAddr = NULL;
char *netAddr = NULL;
int ret;
- int defaultMode = graphics->data.spice.defaultMode;
size_t i;
+ bool hasSecure = false;
+ bool hasInsecure = false;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SPICE)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -7551,8 +7552,10 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
goto error;
}
- if (glisten->port > 0)
+ if (glisten->port > 0) {
virBufferAsprintf(&opt, "port=%u,", glisten->port);
+ hasInsecure = true;
+ }
if (glisten->tlsPort > 0) {
if (!cfg->spiceTLS) {
@@ -7562,6 +7565,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
goto error;
}
virBufferAsprintf(&opt, "tls-port=%u,", glisten->tlsPort);
+ hasSecure = true;
}
if (cfg->spiceSASL) {
@@ -7636,17 +7640,30 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
!cfg->spicePassword)
virBufferAddLit(&opt, "disable-ticketing,");
- if (glisten->tlsPort > 0)
+ if (hasSecure)
virBufferAsprintf(&opt, "x509-dir=%s,",
cfg->spiceTLSx509certdir);
- switch (defaultMode) {
+ switch (graphics->data.spice.defaultMode) {
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
+ if (!hasSecure) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("spice defaultMode secure requested in XML "
+ "configuration, but TLS is not available"));
+ goto error;
+ }
virBufferAddLit(&opt, "tls-channel=default,");
break;
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
+ if (!hasInsecure) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("spice defaultMode insecure requested in XML "
+ "configuration, but plaintext is not
available"));
+ goto error;
+ }
virBufferAddLit(&opt, "plaintext-channel=default,");
break;
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
+ case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_LAST:
/* nothing */
break;
}
@@ -7654,10 +7671,10 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
for (i = 0; i < VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST; i++) {
switch (graphics->data.spice.channels[i]) {
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
- if (glisten->tlsPort <= 0) {
+ if (!hasSecure) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("spice secure channels set in XML configuration,
"
- "but TLS port is not provided"));
+ _("spice secure channels set in XML "
+ "configuration, but TLS is not available"));
goto error;
}
virBufferAsprintf(&opt, "tls-channel=%s,",
@@ -7665,10 +7682,10 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
break;
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
- if (glisten->port <= 0) {
+ if (!hasInsecure) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("spice insecure channels set in XML "
- "configuration, but plain port is not
provided"));
+ "configuration, but plaintext is not
available"));
goto error;
}
virBufferAsprintf(&opt, "plaintext-channel=%s,",
@@ -7676,29 +7693,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
break;
case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
- switch (defaultMode) {
- case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE:
- if (glisten->tlsPort <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("spice defaultMode secure requested in XML
"
- "configuration but TLS port not
provided"));
- goto error;
- }
- break;
-
- case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE:
- if (glisten->port <= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("spice defaultMode insecure requested in XML
"
- "configuration but plain port not
provided"));
- goto error;
- }
- break;
-
- case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY:
- /* don't care */
break;
- }
}
}
--
2.8.2