[Libvirt-cim] [PATCH] compare_ref retrieves key count from internal data

Heidi Eckhart heidieck at linux.vnet.ibm.com
Wed Nov 14 09:05:04 UTC 2007


# HG changeset patch
# User Heidi Eckhart <heidieck at linux.vnet.ibm.com>
# Date 1195034692 -3600
# Node ID 785993875a6598c153829a3cfcb5e1088da9971a
# Parent  c3f816e3ab5ff2a17500d8b48ec601ade58da988
compare_ref retrieves key count from internal data

The cu_compare_ref retrieves the key count out of the
internal data struct now, instead of the client given
object path. Fixes the academical case that a client
does not submit the correct number of keys.
Signed-off-by: Heidi Eckhart <heidieck at linux.vnet.ibm.com>

diff -r c3f816e3ab5f -r 785993875a65 instance_util.c
--- a/instance_util.c	Tue Nov 13 15:33:06 2007 -0500
+++ b/instance_util.c	Wed Nov 14 11:04:52 2007 +0100
@@ -89,59 +89,59 @@ static bool _compare_data(const CMPIData
 }
 
 static bool _compare_classname(const CMPIObjectPath *ref,
-                               const CMPIInstance *inst)
+                               const CMPIObjectPath *op)
 {
         const char *ref_cn;
-        const char *inst_cn;
-        CMPIObjectPath *op;
-        CMPIStatus s;
-
-        op = CMGetObjectPath(inst, &s);
-        if ((op == NULL) || (s.rc != CMPI_RC_OK))
-                return false;
-
+        const char *op_cn;
+        
         ref_cn = CLASSNAME(ref);
         if (ref_cn == NULL)
                 return false;
-
-        inst_cn = CLASSNAME(op);
-        if (inst_cn == NULL)
+        
+        op_cn = CLASSNAME(op);
+        if (op_cn == NULL)
                 return false;
-
-        return STREQC(inst_cn, ref_cn);
+        
+        return STREQC(op_cn, ref_cn);
 }
 
 const char *cu_compare_ref(const CMPIObjectPath *ref,
                            const CMPIInstance *inst)
 {
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        CMPIObjectPath *op; 
+        const char *prop = NULL;
         int i;
-        CMPIStatus s;
         int count;
-        const char *prop = NULL;
 
-        count = CMGetKeyCount(ref, &s);
+        op = CMGetObjectPath(inst, &s);
+        if ((op == NULL) || (s.rc != CMPI_RC_OK))
+                return NULL;
+
+        if (!_compare_classname(ref, op))
+                return "CreationClassName";
+        
+        count = CMGetKeyCount(op, &s);
         if (s.rc != CMPI_RC_OK) {
                 CU_DEBUG("Unable to get key count");
                 return NULL;
         }
-
-        if (!_compare_classname(ref, inst))
-                return "CreationClassName";
-
+        CU_DEBUG("Number of keys: %i", count);
+        
         for (i = 0; i < count; i++) {
                 CMPIData kd, pd;
                 CMPIString *str;
 
-                kd = CMGetKeyAt(ref, i, &str, &s);
+                kd = CMGetKeyAt(op, i, &str, &s);
                 if (s.rc != CMPI_RC_OK) {
                         CU_DEBUG("Failed to get key %i", i);
                         goto out;
                 }
 
                 prop = CMGetCharPtr(str);
-                CU_DEBUG("Comparing key `%s'", prop);
+                CU_DEBUG("Comparing key %i: `%s'", i, prop);
 
-                pd = CMGetProperty(inst, prop, &s);
+                pd = CMGetKey(ref, prop, &s);
                 if (s.rc != CMPI_RC_OK) {
                         CU_DEBUG("Failed to get property `%s'", prop);
                         goto out;




More information about the Libvirt-cim mailing list