summaryrefslogtreecommitdiff
path: root/SPICEConsoleAPI.cpp
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@redhat.com>2012-11-16 17:47:33 +0100
committerChristophe Fergeau <cfergeau@redhat.com>2012-11-16 17:47:33 +0100
commit9ac219de521a1eb0cff05e21ddca608773642d32 (patch)
tree593c24d7443d7bbe260f68cca478fc6a879c8754 /SPICEConsoleAPI.cpp
parentb5d38b70eb87f99c537b33b0fab14343d2339477 (diff)
Improve handling of port numbers
We now use an empty FB::variant when no port is set or an invalid port is set.
Diffstat (limited to 'SPICEConsoleAPI.cpp')
-rw-r--r--SPICEConsoleAPI.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/SPICEConsoleAPI.cpp b/SPICEConsoleAPI.cpp
index 8309ba9..6e3d053 100644
--- a/SPICEConsoleAPI.cpp
+++ b/SPICEConsoleAPI.cpp
@@ -91,21 +91,22 @@ bool SPICEConsoleAPI::createTrustStore(void)
void SPICEConsoleAPI::connect()
{
- int port = 0;
- int sport = 0;
try {
- port = getAttribute("port").cast<int>();
- sport = getAttribute("SecurePort").cast<int>();
+ FB::variant port = getAttribute("port");
+ FB::variant sport = getAttribute("sport");
+
+ if (!port.empty() && (port.convert_cast<int>() < 0)) {
+ setAttribute("port", FB::variant());
+ }
+ if (!sport.empty() && (sport.convert_cast<int>() < 0)) {
+ setAttribute("SecurePort", FB::variant());
+ }
} catch (FB::bad_variant_cast &e) {
- g_warning("invalid port/SecurePort value");
+ g_warning("invalid port/SecurePort value %s", e.what());
}
- if (port < 0)
- g_warning("invalid port: '%d'", port);
- if (sport < 0)
- g_warning("invalid secure port: '%d'", sport);
- if (port <= 0 && sport <= 0)
+ if (getAttribute("port").empty() && getAttribute("SecurePort").empty())
{
m_connected_status = 1;
fire_disconnected(m_connected_status);
@@ -135,10 +136,8 @@ void SPICEConsoleAPI::connect()
SendInit();
SendValue<std::string>(CONTROLLER_HOST, "hostIP");
- if (port > 0)
- SendMsg(CONTROLLER_PORT, (uint32_t)port);
- if (sport > 0)
- SendMsg(CONTROLLER_SPORT, (uint32_t)sport);
+ SendValue<unsigned int>(CONTROLLER_PORT, "port");
+ SendValue<unsigned int>(CONTROLLER_SPORT, "SecurePort");
/*
SendValue(CONTROLLER_FULL_SCREEN,
(m_fullscreen == PR_TRUE ? CONTROLLER_SET_FULL_SCREEN : 0) |