From: Kirill Shchetiniuk <kshcheti(a)redhat.com>
Previously, the RDP graphics definition parsing were implemented by
string parsing, the virDomainGraphicsDefParseXMLRDP function was
refactored to use the appropriate virXMLProp* utility functions.
Overall parsing logic was not changed and results the same output as before.
Moreover, 'replaceUser' and 'mutliUser' params type was changed from
bool to tristate type, to avoid unnecessary type convertions. The
virDomainGraphicsDefFormatRDP fucntion was also refactored according
to the type changes.
Signed-off-by: Kirill Shchetiniuk <kshcheti(a)redhat.com>
---
src/conf/domain_conf.c | 51 +++++++++++++++++++++-------------------
src/conf/domain_conf.h | 4 ++--
src/qemu/qemu_process.c | 4 ++--
src/qemu/qemu_validate.c | 4 ++--
src/vbox/vbox_common.c | 8 +++----
5 files changed, 37 insertions(+), 34 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 32a358d72c..201a4ded8b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11917,40 +11917,41 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDef *def,
xmlXPathContextPtr ctxt,
unsigned int flags)
{
- g_autofree char *port = virXMLPropString(node, "port");
- g_autofree char *autoport = virXMLPropString(node, "autoport");
- g_autofree char *replaceUser = virXMLPropString(node, "replaceUser");
- g_autofree char *multiUser = virXMLPropString(node, "multiUser");
+ virTristateBool autoport;
if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0)
return -1;
- if (port) {
- if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot parse rdp port %1$s"), port);
- return -1;
- }
- /* Legacy compat syntax, used -1 for auto-port */
- if (def->data.rdp.port == -1)
- def->data.rdp.autoport = true;
+ if (virXMLPropInt(node, "port", 10, VIR_XML_PROP_NONE,
+ &def->data.rdp.port, 0) < 0)
+ return -1;
- } else {
- def->data.rdp.port = 0;
+ if (def->data.rdp.port == -1) {
+ /* Legacy compat syntax, used -1 for auto-port */
def->data.rdp.autoport = true;
}
- if (STREQ_NULLABLE(autoport, "yes"))
+ if (def->data.rdp.port == 0) {
+ /* No port specified */
def->data.rdp.autoport = true;
+ }
+
+ if (virXMLPropTristateBool(node, "autoport", VIR_XML_PROP_NONE,
+ &autoport) < 0)
+ return -1;
+
+ virTristateBoolToBool(autoport, &def->data.rdp.autoport);
if (def->data.rdp.autoport && (flags &
VIR_DOMAIN_DEF_PARSE_INACTIVE))
def->data.rdp.port = 0;
- if (STREQ_NULLABLE(replaceUser, "yes"))
- def->data.rdp.replaceUser = true;
+ if (virXMLPropTristateBool(node, "replaceUser", VIR_XML_PROP_NONE,
+ &def->data.rdp.replaceUser))
+ return -1;
- if (STREQ_NULLABLE(multiUser, "yes"))
- def->data.rdp.multiUser = true;
+ if (virXMLPropTristateBool(node, "multiUser", VIR_XML_PROP_NONE,
+ &def->data.rdp.replaceUser))
+ return -1;
if (virDomainGraphicsAuthDefParseXML(node, &def->data.rdp.auth,
def->type) < 0)
@@ -26977,11 +26978,13 @@ virDomainGraphicsDefFormatRDP(virBuffer *attrBuf,
if (def->data.rdp.autoport)
virBufferAddLit(attrBuf, " autoport='yes'");
- if (def->data.rdp.replaceUser)
- virBufferAddLit(attrBuf, " replaceUser='yes'");
+ if (def->data.rdp.replaceUser != VIR_TRISTATE_BOOL_ABSENT)
+ virBufferAsprintf(attrBuf, " replaceUser='%s'",
+ virTristateBoolTypeToString(def->data.rdp.replaceUser));
- if (def->data.rdp.multiUser)
- virBufferAddLit(attrBuf, " multiUser='yes'");
+ if (def->data.rdp.multiUser != VIR_TRISTATE_BOOL_ABSENT)
+ virBufferAsprintf(attrBuf, " multiUser='%s'",
+ virTristateBoolTypeToString(def->data.rdp.multiUser));
virDomainGraphicsListenDefFormatAddr(attrBuf, glisten, flags);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8df404dc42..c909cfba3f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2043,8 +2043,8 @@ struct _virDomainGraphicsDef {
int port;
bool portReserved;
bool autoport;
- bool replaceUser;
- bool multiUser;
+ virTristateBool replaceUser;
+ virTristateBool multiUser;
virDomainGraphicsAuthDef auth;
} rdp;
struct {
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 54b84922d6..02cca5fb6b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5550,12 +5550,12 @@ qemuProcessStartValidateGraphics(virDomainObj *vm)
_("qemu-rdp does not support multiple listens for one
graphics device."));
return -1;
}
- if (graphics->data.rdp.multiUser) {
+ if (graphics->data.rdp.multiUser == VIR_TRISTATE_BOOL_YES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("qemu-rdp doesn't support the
'multiUser' attribute."));
return -1;
}
- if (graphics->data.rdp.replaceUser) {
+ if (graphics->data.rdp.replaceUser == VIR_TRISTATE_BOOL_YES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("qemu-rdp doesn't support the
'replaceUser' attribute."));
return -1;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index e45f636418..968533ccf3 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -4512,12 +4512,12 @@ qemuValidateDomainDeviceDefDBusGraphics(const virDomainGraphicsDef
*graphics,
static int
qemuValidateDomainDeviceDefRDPGraphics(const virDomainGraphicsDef *graphics)
{
- if (graphics->data.rdp.replaceUser) {
+ if (graphics->data.rdp.replaceUser == VIR_TRISTATE_BOOL_YES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("RDP doesn't support 'replaceUser'"));
return -1;
}
- if (graphics->data.rdp.multiUser) {
+ if (graphics->data.rdp.multiUser == VIR_TRISTATE_BOOL_YES) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("RDP doesn't support 'multiUser'"));
return -1;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 349ac832dc..929d452abd 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1703,13 +1703,13 @@ vboxAttachDisplay(virDomainDef *def, struct _vboxDriver *data,
IMachine *machine
gVBoxAPI.UIVRDEServer.SetPorts(data, VRDEServer, def->graphics[i]);
- if (def->graphics[i]->data.rdp.replaceUser) {
+ if (def->graphics[i]->data.rdp.replaceUser ==
VIR_TRISTATE_BOOL_YES) {
gVBoxAPI.UIVRDEServer.SetReuseSingleConnection(VRDEServer,
PR_TRUE);
VIR_DEBUG("VRDP set to reuse single connection");
}
- if (def->graphics[i]->data.rdp.multiUser) {
+ if (def->graphics[i]->data.rdp.multiUser == VIR_TRISTATE_BOOL_YES)
{
gVBoxAPI.UIVRDEServer.SetAllowMultiConnection(VRDEServer,
PR_TRUE);
VIR_DEBUG("VRDP set to allow multiple connection");
@@ -3611,12 +3611,11 @@ vboxDumpDisplay(virDomainDef *def, struct _vboxDriver *data,
IMachine *machine)
gVBoxAPI.UIVRDEServer.GetAllowMultiConnection(VRDEServer,
&allowMultiConnection);
if (allowMultiConnection)
- graphics->data.rdp.multiUser = true;
+ graphics->data.rdp.multiUser = VIR_TRISTATE_BOOL_YES;
gVBoxAPI.UIVRDEServer.GetReuseSingleConnection(VRDEServer,
&reuseSingleConnection);
if (reuseSingleConnection)
- graphics->data.rdp.replaceUser = true;
+ graphics->data.rdp.replaceUser = VIR_TRISTATE_BOOL_YES;
VIR_APPEND_ELEMENT(def->graphics, def->ngraphics, graphics);
}
--
2.49.0