# HG changeset patch
# User kaitlin(a)elm3b43.beaverton.ibm.com
# Date 1224553245 25200
# Node ID c41bd7c3175a970f7c674931ee27ef2a88b63b61
# Parent d62634a3121f2991ed800491b2966ed9b531d4c3
Have get_console_sap_by_name() parse Name attribute to determine session status
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r d62634a3121f -r c41bd7c3175a src/Virt_KVMRedirectionSAP.c
--- a/src/Virt_KVMRedirectionSAP.c Mon Oct 20 18:40:44 2008 -0700
+++ b/src/Virt_KVMRedirectionSAP.c Mon Oct 20 18:40:45 2008 -0700
@@ -113,6 +113,33 @@
static size_t get_vnc_hash_key(unsigned int key)
{
return key % VNC_PORT_MIN;
+}
+
+static int parse_sap_name(const char *name,
+ char **guest,
+ char **port,
+ char **remote_port)
+{
+ int ret;
+
+ ret = sscanf(name, "%a[^/]/%a[^:]:%as",
+ guest,
+ port,
+ remote_port);
+
+ if (ret != 3) {
+ free(*guest);
+ free(*port);
+ free(*remote_port);
+
+ *guest = NULL;
+ *port = NULL;
+ *remote_port = NULL;
+
+ return 0;
+ }
+
+ return 1;
}
static CMPIStatus port_to_str(unsigned int port,
@@ -459,14 +486,18 @@
CMPIStatus get_console_sap_by_name(const CMPIBroker *broker,
const CMPIObjectPath *ref,
- const char *name,
+ const char *id,
CMPIInstance **_inst)
{
virConnectPtr conn;
- virDomainPtr dom;
+ virDomainPtr dom = NULL;
CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIInstance *inst = NULL;
struct domain *dominfo = NULL;
+ char *name = NULL;
+ char *port = NULL;
+ char *remote_port = NULL;
+ int ret;
conn = connect_by_classname(broker, CLASSNAME(ref), &s);
if (conn == NULL) {
@@ -476,6 +507,14 @@
goto out;
}
+ ret = parse_sap_name(id, &name, &port, &remote_port);
+ if (ret != 1) {
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to parse instance name");
+ goto out;
+ }
+
dom = virDomainLookupByName(conn, name);
if (dom == NULL) {
cu_statusf(broker, &s,
@@ -489,19 +528,21 @@
cu_statusf(broker, &s,
CMPI_RC_ERR_FAILED,
"No console device for this guest");
+
+ goto out;
}
- inst = get_console_sap(_BROKER, ref, conn, dominfo, &s);
-
- virDomainFree(dom);
-
- if (s.rc != CMPI_RC_OK)
- goto out;
+ inst = get_console_sap(_BROKER, ref, conn, dominfo, remote_port, &s);
*_inst = inst;
out:
+ virDomainFree(dom);
virConnectClose(conn);
+
+ free(name);
+ free(port);
+ free(remote_port);
return s;
}
@@ -512,16 +553,16 @@
{
CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIInstance *inst = NULL;
- const char *sys = NULL;
+ const char *id = NULL;
- if (cu_get_str_path(reference, "System", &sys) != CMPI_RC_OK) {
+ if (cu_get_str_path(reference, "System", &id) != CMPI_RC_OK) {
cu_statusf(broker, &s,
CMPI_RC_ERR_NOT_FOUND,
- "No such instance (System)");
+ "No such instance (Name)");
goto out;
}
- s = get_console_sap_by_name(broker, reference, sys, &inst);
+ s = get_console_sap_by_name(broker, reference, id, &inst);
if (s.rc != CMPI_RC_OK)
goto out;