# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1195172367 28800
# Node ID 499034149a6bc4072ad76f06d107059613277d6a
# Parent ae4810e6764b1ea14df6f429eab972593e919e37
Add function to parse InstanceIDs.
This function currently supports InstanceIDs in the format <Org>:<LocalID>,
such as "Xen:Domain-0" for VSSD.
The functionality is based on the parsing from VSSDComponent, so the code for parsing the
InstanceID is replaced by the function.
Updated function so that it can return both the InstanceID prefix (org) and the localID.
The call has the option of supplying NULL for either argument.
Also added a wrapper function that takes a CMPIObjectPath ref, grabs the instanceID, and
then calls the parse_id() function.
Fixed memory leak.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r ae4810e6764b -r 499034149a6b libxkutil/misc_util.c
--- a/libxkutil/misc_util.c Thu Nov 15 09:49:47 2007 -0800
+++ b/libxkutil/misc_util.c Thu Nov 15 16:19:27 2007 -0800
@@ -371,6 +371,55 @@ bool domain_online(virDomainPtr dom)
(info.state == VIR_DOMAIN_RUNNING);
}
+int parse_id(char *id,
+ char **pfx,
+ char **name)
+{
+ int ret;
+ char *tmp_pfx;
+ char *tmp_name;
+
+ ret = sscanf(id, "%a[^:]:%as", &tmp_pfx, &tmp_name);
+ if (ret != 2) {
+ ret = 0;
+ goto out;
+ }
+
+ if (pfx)
+ *pfx = strdup(tmp_pfx);
+
+ if (name)
+ *name = strdup(tmp_name);
+
+ ret = 1;
+
+ out:
+ free(tmp_pfx);
+ free(tmp_name);
+
+ return ret;
+}
+
+bool parse_instanceid(const CMPIObjectPath *ref,
+ char **pfx,
+ char **name)
+{
+ int ret;
+ char *id = NULL;
+
+ id = cu_get_str_path(ref, "InstanceID");
+ if (id == NULL)
+ return false;
+
+ ret = parse_id(id, pfx, name);
+
+ free(id);
+
+ if (!ret)
+ return false;
+
+ return true;
+}
/*
* Local Variables:
diff -r ae4810e6764b -r 499034149a6b libxkutil/misc_util.h
--- a/libxkutil/misc_util.h Thu Nov 15 09:49:47 2007 -0800
+++ b/libxkutil/misc_util.h Thu Nov 15 16:19:27 2007 -0800
@@ -89,6 +89,9 @@ char *association_prefix(const char *pro
char *association_prefix(const char *provider_name);
bool match_pn_to_cn(const char *pn, const char *cn);
+int parse_id(char *id, char **pfx, char **name);
+bool parse_instanceid(const CMPIObjectPath *ref, char **pfx, char **name);
+
#define ASSOC_MATCH(pn, cn) \
if (!match_pn_to_cn((pn), (cn))) { \
return (CMPIStatus){CMPI_RC_OK, NULL}; \
diff -r ae4810e6764b -r 499034149a6b src/Virt_VSSDComponent.c
--- a/src/Virt_VSSDComponent.c Thu Nov 15 09:49:47 2007 -0800
+++ b/src/Virt_VSSDComponent.c Thu Nov 15 16:19:27 2007 -0800
@@ -41,10 +41,7 @@ static CMPIStatus vssd_to_rasd(const CMP
struct inst_list *list)
{
CMPIStatus s;
- char *id = NULL;
- char *pfx = NULL;
char *name = NULL;
- int ret;
int i = 0;
int types[] = {
CIM_RASD_TYPE_PROC,
@@ -56,19 +53,10 @@ static CMPIStatus vssd_to_rasd(const CMP
ASSOC_MATCH(info->provider_name, CLASSNAME(ref));
- id = cu_get_str_path(ref, "InstanceID");
- if (id == NULL) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Missing InstanceID");
- goto out;
- }
-
- ret = sscanf(id, "%a[^:]:%as", &pfx, &name);
- if (ret != 2) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Invalid InstanceID");
+ if (!parse_instanceid(ref, NULL, &name)) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_FAILED,
+ "Unable to get system name");
goto out;
}
@@ -83,8 +71,6 @@ static CMPIStatus vssd_to_rasd(const CMP
CMSetStatus(&s, CMPI_RC_OK);
out:
- free(id);
- free(pfx);
free(name);
return s;