mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
use virDomainGraphicsGetListen instead of the other getters
There is no point the use two different getters on the same listen structure few lines apart. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
37b1f45066
commit
f53bb3eda9
@ -1424,7 +1424,7 @@ libxlMakeVfb(virPortAllocatorPtr graphicsports,
|
||||
libxl_device_vfb *x_vfb)
|
||||
{
|
||||
unsigned short port;
|
||||
const char *listenAddr;
|
||||
virDomainGraphicsListenDefPtr listen = NULL;
|
||||
|
||||
libxl_device_vfb_init(x_vfb);
|
||||
|
||||
@ -1451,11 +1451,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)
|
||||
@ -1539,7 +1539,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;
|
||||
@ -1553,8 +1553,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)
|
||||
|
@ -7219,7 +7219,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;
|
||||
@ -7248,31 +7248,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)
|
||||
@ -7363,7 +7366,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;
|
||||
@ -7402,31 +7405,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)
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -2478,7 +2478,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;
|
||||
@ -2712,9 +2712,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;
|
||||
@ -2735,11 +2735,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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user