
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1195082890 28800 # Node ID b4f0488c0d16a228a3c6fd6f23f7465cd3944123 # Parent 6dc0a1a05c60ad08738c7c48aa9fb6d7dd7cd8be 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. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 6dc0a1a05c60 -r b4f0488c0d16 libxkutil/misc_util.c --- a/libxkutil/misc_util.c Wed Nov 14 15:22:38 2007 -0800 +++ b/libxkutil/misc_util.c Wed Nov 14 15:28:10 2007 -0800 @@ -371,6 +371,27 @@ bool domain_online(virDomainPtr dom) (info.state == VIR_DOMAIN_RUNNING); } +bool parse_id(const CMPIObjectPath *ref, + char **name) +{ + char *id = NULL; + char *pfx = NULL; + int ret; + + id = cu_get_str_path(ref, "InstanceID"); + if (id == NULL) + return false; + + ret = sscanf(id, "%a[^:]:%as", &pfx, name); + + free(id); + free(pfx); + + if ((ret != 2) || (*name == NULL)) + return false; + + return true; +} /* * Local Variables: diff -r 6dc0a1a05c60 -r b4f0488c0d16 libxkutil/misc_util.h --- a/libxkutil/misc_util.h Wed Nov 14 15:22:38 2007 -0800 +++ b/libxkutil/misc_util.h Wed Nov 14 15:28:10 2007 -0800 @@ -89,6 +89,8 @@ char *association_prefix(const char *pro char *association_prefix(const char *provider_name); bool match_pn_to_cn(const char *pn, const char *cn); +bool parse_id(const CMPIObjectPath *ref, char **name); + #define ASSOC_MATCH(pn, cn) \ if (!match_pn_to_cn((pn), (cn))) { \ return (CMPIStatus){CMPI_RC_OK, NULL}; \ diff -r 6dc0a1a05c60 -r b4f0488c0d16 src/Virt_VSSDComponent.c --- a/src/Virt_VSSDComponent.c Wed Nov 14 15:22:38 2007 -0800 +++ b/src/Virt_VSSDComponent.c Wed Nov 14 15:28:10 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_id(ref, &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;