There is no point the use two different getters on the same listen
structure few lines apart.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/libxl/libxl_conf.c | 15 +++----
src/qemu/qemu_command.c | 98 ++++++++++++++++++++++++----------------------
src/qemu/qemu_migration.c | 9 +++--
src/vbox/vbox_common.c | 11 +++---
src/vmx/vmx.c | 7 ++--
src/vz/vz_sdk.c | 11 +++---
src/xenconfig/xen_common.c | 16 ++++----
src/xenconfig/xen_sxpr.c | 16 ++++----
src/xenconfig/xen_xl.c | 8 ++--
9 files changed, 99 insertions(+), 92 deletions(-)
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 82ba417..e1cf914 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1494,7 +1494,7 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
libxl_device_vfb *x_vfb)
{
unsigned short port;
- const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen = NULL;
libxl_device_vfb_init(x_vfb);
@@ -1521,11 +1521,11 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
}
x_vfb->vnc.display = l_vfb->data.vnc.port - LIBXL_VNC_PORT_MIN;
- listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0);
- if (listenAddr) {
+ if ((listen = virDomainGraphicsGetListen(l_vfb, 0)) &&
+ listen->address) {
/* libxl_device_vfb_init() does VIR_STRDUP("127.0.0.1") */
VIR_FREE(x_vfb->vnc.listen);
- if (VIR_STRDUP(x_vfb->vnc.listen, listenAddr) < 0)
+ if (VIR_STRDUP(x_vfb->vnc.listen, listen->address) < 0)
return -1;
}
if (VIR_STRDUP(x_vfb->vnc.passwd, l_vfb->data.vnc.auth.passwd) < 0)
@@ -1609,7 +1609,7 @@ libxlMakeBuildInfoVfb(virPortAllocatorPtr graphicsports,
for (i = 0; i < def->ngraphics; i++) {
virDomainGraphicsDefPtr l_vfb = def->graphics[i];
unsigned short port;
- const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen = NULL;
if (l_vfb->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE)
continue;
@@ -1623,8 +1623,9 @@ libxlMakeBuildInfoVfb(virPortAllocatorPtr graphicsports,
}
b_info->u.hvm.spice.port = l_vfb->data.spice.port;
- listenAddr = virDomainGraphicsListenGetAddress(l_vfb, 0);
- if (VIR_STRDUP(b_info->u.hvm.spice.host, listenAddr) < 0)
+ if ((listen = virDomainGraphicsGetListen(l_vfb, 0)) &&
+ listen->address &&
+ VIR_STRDUP(b_info->u.hvm.spice.host, listen->address) < 0)
return -1;
if (VIR_STRDUP(b_info->u.hvm.keymap, l_vfb->data.spice.keymap) < 0)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 140bf98..9335f63 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7223,7 +7223,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
const char *domainLibDir)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
- const char *listenNetwork;
+ virDomainGraphicsListenDefPtr listen = NULL;
const char *listenAddr = NULL;
char *netAddr = NULL;
bool escapeAddr;
@@ -7252,31 +7252,34 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg,
goto error;
}
- switch (virDomainGraphicsListenGetType(graphics, 0)) {
- case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
- listenAddr = virDomainGraphicsListenGetAddress(graphics, 0);
- break;
+ if ((listen = virDomainGraphicsGetListen(graphics, 0))) {
- case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
- listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0);
- if (!listenNetwork)
+ switch (listen->type) {
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
+ listenAddr = listen->address;
break;
- ret = networkGetNetworkAddress(listenNetwork, &netAddr);
- if (ret <= -2) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- "%s", _("network-based listen not possible,
"
- "network driver not present"));
- goto error;
- }
- if (ret < 0)
- goto error;
- listenAddr = netAddr;
- /* store the address we found in the <graphics> element so it
- * will show up in status. */
- if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0)
- goto error;
- break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
+ if (!listen->network)
+ break;
+
+ ret = networkGetNetworkAddress(listen->network, &netAddr);
+ if (ret <= -2) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("network-based listen not
possible, "
+ "network driver not present"));
+ goto error;
+ }
+ if (ret < 0)
+ goto error;
+
+ listenAddr = netAddr;
+ /* store the address we found in the <graphics> element so it
+ * will show up in status. */
+ if (VIR_STRDUP(listen->address, netAddr) < 0)
+ goto error;
+ break;
+ }
}
if (!listenAddr)
@@ -7367,7 +7370,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
virDomainGraphicsDefPtr graphics)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
- const char *listenNetwork;
+ virDomainGraphicsListenDefPtr listen = NULL;
const char *listenAddr = NULL;
char *netAddr = NULL;
int ret;
@@ -7406,31 +7409,34 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfigPtr cfg,
}
if (port > 0 || tlsPort > 0) {
- switch (virDomainGraphicsListenGetType(graphics, 0)) {
- case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
- listenAddr = virDomainGraphicsListenGetAddress(graphics, 0);
- break;
+ if ((listen = virDomainGraphicsGetListen(graphics, 0))) {
- case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
- listenNetwork = virDomainGraphicsListenGetNetwork(graphics, 0);
- if (!listenNetwork)
+ switch (listen->type) {
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS:
+ listenAddr = listen->address;
break;
- ret = networkGetNetworkAddress(listenNetwork, &netAddr);
- if (ret <= -2) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- "%s", _("network-based listen not possible,
"
- "network driver not present"));
- goto error;
- }
- if (ret < 0)
- goto error;
- listenAddr = netAddr;
- /* store the address we found in the <graphics> element so it will
- * show up in status. */
- if (VIR_STRDUP(graphics->listens[0].address, listenAddr) < 0)
- goto error;
- break;
+ case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK:
+ if (!listen->network)
+ break;
+
+ ret = networkGetNetworkAddress(listen->network, &netAddr);
+ if (ret <= -2) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ "%s", _("network-based listen not
possible, "
+ "network driver not present"));
+ goto error;
+ }
+ if (ret < 0)
+ goto error;
+
+ listenAddr = netAddr;
+ /* store the address we found in the <graphics> element so it will
+ * show up in status. */
+ if (VIR_STRDUP(listen->address, listenAddr) < 0)
+ goto error;
+ break;
+ }
}
if (!listenAddr)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 8d2ca3b..d0055a2 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -314,6 +314,7 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver,
{
qemuMigrationCookieGraphicsPtr mig = NULL;
const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen = virDomainGraphicsGetListen(def, 0);
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
if (VIR_ALLOC(mig) < 0)
@@ -322,8 +323,8 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver,
mig->type = def->type;
if (mig->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
mig->port = def->data.vnc.port;
- listenAddr = virDomainGraphicsListenGetAddress(def, 0);
- if (!listenAddr)
+
+ if (!listen || !(listenAddr = listen->address))
listenAddr = cfg->vncListen;
#ifdef WITH_GNUTLS
@@ -337,8 +338,8 @@ qemuMigrationCookieGraphicsAlloc(virQEMUDriverPtr driver,
mig->tlsPort = def->data.spice.tlsPort;
else
mig->tlsPort = -1;
- listenAddr = virDomainGraphicsListenGetAddress(def, 0);
- if (!listenAddr)
+
+ if (!listen || !(listenAddr = listen->address))
listenAddr = cfg->spiceListen;
#ifdef WITH_GNUTLS
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index ee3b9c5..9549cc7 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1578,6 +1578,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
char *guiDisplay = NULL;
char *sdlDisplay = NULL;
size_t i = 0;
+ virDomainGraphicsListenDefPtr listen;
for (i = 0; i < def->ngraphics; i++) {
IVRDxServer *VRDxServer = NULL;
@@ -1588,9 +1589,6 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
vrdpPresent = 1;
gVBoxAPI.UIMachine.GetVRDxServer(machine, &VRDxServer);
if (VRDxServer) {
- const char *listenAddr
- = virDomainGraphicsListenGetAddress(def->graphics[i], 0);
-
gVBoxAPI.UIVRDxServer.SetEnabled(VRDxServer, PR_TRUE);
VIR_DEBUG("VRDP Support turned ON.");
@@ -1608,14 +1606,15 @@ vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
VIR_DEBUG("VRDP set to allow multiple connection");
}
- if (listenAddr) {
+ if ((listen = virDomainGraphicsGetListen(def->graphics[i], 0))
&&
+ listen->address) {
PRUnichar *netAddressUtf16 = NULL;
- VBOX_UTF8_TO_UTF16(listenAddr, &netAddressUtf16);
+ VBOX_UTF8_TO_UTF16(listen->address, &netAddressUtf16);
gVBoxAPI.UIVRDxServer.SetNetAddress(data, VRDxServer,
netAddressUtf16);
VIR_DEBUG("VRDP listen address is set to: %s",
- listenAddr);
+ listen->address);
VBOX_UTF16_FREE(netAddressUtf16);
}
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index f6a4474..f5ad458 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -3403,7 +3403,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt,
virDomainDe
int
virVMXFormatVNC(virDomainGraphicsDefPtr def, virBufferPtr buffer)
{
- const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen;
if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid
argument"));
@@ -3425,9 +3425,10 @@ virVMXFormatVNC(virDomainGraphicsDefPtr def, virBufferPtr buffer)
def->data.vnc.port);
}
- if ((listenAddr = virDomainGraphicsListenGetAddress(def, 0))) {
+ if ((listen = virDomainGraphicsGetListen(def, 0)) &&
+ listen->address) {
virBufferAsprintf(buffer, "RemoteDisplay.vnc.ip = \"%s\"\n",
- listenAddr);
+ listen->address);
}
if (def->data.vnc.keymap != NULL) {
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 8691887..41d9ff0 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2238,7 +2238,7 @@ static int prlsdkCheckGraphicsUnsupportedParams(virDomainDefPtr
def)
}
if (gr->nListens == 1 &&
- virDomainGraphicsListenGetType(gr, 0) != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS)
{
+ gr->listens[0].type != VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("vz driver supports only address-based VNC
listening"));
return -1;
@@ -2472,9 +2472,9 @@ static int prlsdkCheckFSUnsupportedParams(virDomainFSDefPtr fs)
static int prlsdkApplyGraphicsParams(PRL_HANDLE sdkdom, virDomainDefPtr def)
{
virDomainGraphicsDefPtr gr;
+ virDomainGraphicsListenDefPtr listen;
PRL_RESULT pret;
int ret = -1;
- const char *listenAddr = NULL;
if (prlsdkCheckGraphicsUnsupportedParams(def))
return -1;
@@ -2495,11 +2495,10 @@ static int prlsdkApplyGraphicsParams(PRL_HANDLE sdkdom,
virDomainDefPtr def)
prlsdkCheckRetGoto(pret, cleanup);
}
- if (gr->nListens == 1) {
- listenAddr = virDomainGraphicsListenGetAddress(gr, 0);
- if (!listenAddr)
+ if ((listen = virDomainGraphicsGetListen(gr, 0))) {
+ if (!listen->address)
goto cleanup;
- pret = PrlVmCfg_SetVNCHostName(sdkdom, listenAddr);
+ pret = PrlVmCfg_SetVNCHostName(sdkdom, listen->address);
prlsdkCheckRetGoto(pret, cleanup);
}
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index db1e236..e92d4e1 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1628,7 +1628,7 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def)
def->graphics[0]->data.sdl.xauth) < 0)
return -1;
} else {
- const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen;
if (xenConfigSetInt(conf, "sdl", 0) < 0)
return -1;
@@ -1645,9 +1645,9 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def)
def->graphics[0]->data.vnc.port - 5900) <
0)
return -1;
- listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
- if (listenAddr &&
- xenConfigSetString(conf, "vnclisten", listenAddr) < 0)
+ if ((listen = virDomainGraphicsGetListen(def->graphics[0], 0))
&&
+ listen->address &&
+ xenConfigSetString(conf, "vnclisten", listen->address)
< 0)
return -1;
if (def->graphics[0]->data.vnc.auth.passwd &&
@@ -1674,8 +1674,8 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def)
virBufferAsprintf(&buf, ",xauthority=%s",
def->graphics[0]->data.sdl.xauth);
} else {
- const char *listenAddr
- = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
+ virDomainGraphicsListenDefPtr listen
+ = virDomainGraphicsGetListen(def->graphics[0], 0);
virBufferAddLit(&buf, "type=vnc");
virBufferAsprintf(&buf, ",vncunused=%d",
@@ -1683,8 +1683,8 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def)
if (!def->graphics[0]->data.vnc.autoport)
virBufferAsprintf(&buf, ",vncdisplay=%d",
def->graphics[0]->data.vnc.port - 5900);
- if (listenAddr)
- virBufferAsprintf(&buf, ",vnclisten=%s", listenAddr);
+ if (listen && listen->address)
+ virBufferAsprintf(&buf, ",vnclisten=%s",
listen->address);
if (def->graphics[0]->data.vnc.auth.passwd)
virBufferAsprintf(&buf, ",vncpasswd=%s",
def->graphics[0]->data.vnc.auth.passwd);
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 7d719b0..cde462d 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1523,7 +1523,7 @@ static int
xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def,
virBufferPtr buf)
{
- const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen;
if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_SDL &&
def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
@@ -1551,9 +1551,9 @@ xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def,
virBufferAsprintf(buf, "(vncdisplay %d)",
def->data.vnc.port-5900);
}
- listenAddr = virDomainGraphicsListenGetAddress(def, 0);
- if (listenAddr)
- virBufferAsprintf(buf, "(vnclisten '%s')", listenAddr);
+ if ((listen = virDomainGraphicsGetListen(def, 0)) &&
+ listen->address)
+ virBufferAsprintf(buf, "(vnclisten '%s')",
listen->address);
if (def->data.vnc.auth.passwd)
virBufferAsprintf(buf, "(vncpasswd '%s')",
def->data.vnc.auth.passwd);
if (def->data.vnc.keymap)
@@ -1579,7 +1579,7 @@ xenFormatSxprGraphicsNew(virDomainGraphicsDefPtr def,
static int
xenFormatSxprGraphicsOld(virDomainGraphicsDefPtr def, virBufferPtr buf)
{
- const char *listenAddr;
+ virDomainGraphicsListenDefPtr listen;
if (def->type != VIR_DOMAIN_GRAPHICS_TYPE_SDL &&
def->type != VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
@@ -1604,9 +1604,9 @@ xenFormatSxprGraphicsOld(virDomainGraphicsDefPtr def, virBufferPtr
buf)
virBufferAsprintf(buf, "(vncdisplay %d)",
def->data.vnc.port-5900);
}
- listenAddr = virDomainGraphicsListenGetAddress(def, 0);
- if (listenAddr)
- virBufferAsprintf(buf, "(vnclisten '%s')", listenAddr);
+ if ((listen = virDomainGraphicsGetListen(def, 0)) &&
+ listen->address)
+ virBufferAsprintf(buf, "(vnclisten '%s')",
listen->address);
if (def->data.vnc.auth.passwd)
virBufferAsprintf(buf, "(vncpasswd '%s')",
def->data.vnc.auth.passwd);
if (def->data.vnc.keymap)
diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 5478d9c..2631ec6 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -837,7 +837,7 @@ xenFormatXLDomainDisks(virConfPtr conf, virDomainDefPtr def)
static int
xenFormatXLSpice(virConfPtr conf, virDomainDefPtr def)
{
- const char *listenAddr = NULL;
+ virDomainGraphicsListenDefPtr listen;
virDomainGraphicsDefPtr graphics;
if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
@@ -854,9 +854,9 @@ xenFormatXLSpice(virConfPtr conf, virDomainDefPtr def)
if (xenConfigSetInt(conf, "spice", 1) < 0)
return -1;
- listenAddr = virDomainGraphicsListenGetAddress(graphics, 0);
- if (listenAddr &&
- xenConfigSetString(conf, "spicehost", listenAddr) < 0)
+ if ((listen = virDomainGraphicsGetListen(graphics, 0)) &&
+ listen->address &&
+ xenConfigSetString(conf, "spicehost", listen->address) <
0)
return -1;
if (xenConfigSetInt(conf, "spiceport",
--
2.7.4