Skip to content

Commit

Permalink
[ 1686170 ] sfcb:instance comparision in queries do not work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
sschuetz committed Mar 23, 2007
1 parent 0c55b9c commit f833628
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 11 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
2007-03-23 Sven Schuetz

* value.c, queryOperation.h, objectpath.c, instance.c,
queryOperation.c, objectpath.h, instance.h:
Fixed 1686170:instance comparision in queries do not work as expected

2007-03-20 Sven Schuetz

* queryParser.y, selectexp.c:
Expand Down
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -15,6 +15,7 @@ Bugs fixed:
- 1677195 Fixed crash in provider manager trace
- 1682045 Fixed compile error with gcc 4.1.3
- 1682388 Relaxed CMPIValue * alignment pickyness of sfcb
- 1686170 Fixed instance comparision in queries do not work as expected

Changes in 1.2.1
================
Expand Down
34 changes: 33 additions & 1 deletion instance.c
Expand Up @@ -57,7 +57,7 @@ CMPIObjectPath *internal_new_CMPIObjectPath(int mode, const char *nameSpace,
const char *className,
CMPIStatus * rc);
extern const char *ClObjectGetClString(ClObjectHdr * hdr, ClString * id);
//extern CMPIString *__oft_toString(CMPIObjectPath * cop, CMPIStatus * rc);
extern int sfcb_comp_CMPIValue(CMPIValue *val1, CMPIValue *val2, CMPIType type);

extern CMPIBroker *Broker;

Expand Down Expand Up @@ -734,6 +734,38 @@ const char *instGetClassName(CMPIInstance * ci)
return ClInstanceGetClassName(inst);
}

int instanceCompare(CMPIInstance *inst1, CMPIInstance *inst2)
{
int c,i;
CMPIStatus st = { CMPI_RC_OK, NULL };
CMPIData d1, d2;
CMPIString *propName;

c = inst1->ft->getPropertyCount(inst1, NULL);

if(c != inst2->ft->getPropertyCount(inst2, NULL)) {
/* property count not equal, instances cannot be identical */
return 1;
}

for(i = 0; i < c; i++) {
/* get property at position i, store the name in propName */
d1 = inst1->ft->getPropertyAt(inst1, i, &propName, NULL);
/* try to find the property in instance2 via the name just retrieved */
d2 = inst2->ft->getProperty(inst2, propName->ft->getCharPtr(propName, NULL), &st);

if(st.rc || /* property could not be retrieved, probably non existent*/
d1.type != d2.type || /* types differ */
sfcb_comp_CMPIValue(&d1.value, &d2.value, d1.type)) { /* values differ*/

/* instances not equal */
return 1;
}
}
/* passed all tests - instances seem to be identical */
return 0;
}

/* needed for local client support as function tables differ */
void setInstanceLocalMode(int mode)
{
Expand Down
27 changes: 27 additions & 0 deletions instance.h
@@ -0,0 +1,27 @@
/*
* $id$
*
* © Copyright IBM Corp. 2007
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
* CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
*
* You can obtain a current copy of the Eclipse Public License from
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Sven Schuetz
*
* Description:
*
* instance utility functions
*
*/

#ifndef _INSTANCE_H
#define _INSTANCE_H

int instanceCompare(CMPIInstance *inst1, CMPIInstance *inst2);
const char *instGetClassName(CMPIInstance * ci);

#endif
18 changes: 17 additions & 1 deletion objectpath.c
Expand Up @@ -2,7 +2,7 @@
/*
* objectpath.c
*
* (C) Copyright IBM Corp. 2005
* © Copyright IBM Corp. 2005, 2007
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
Expand Down Expand Up @@ -712,3 +712,19 @@ char *normalizeObjectPathCharsDup(const CMPIObjectPath *cop)
sb->ft->release(sb);
return n;
}

int objectpathCompare(const CMPIObjectPath *cop1, const CMPIObjectPath *cop2)
{
UtilStringBuffer *sb1, *sb2;
int result;

sb1=normalizeObjectPathStrBuf(cop1);
sb2=normalizeObjectPathStrBuf(cop2);

result = strcmp(sb1->ft->getCharPtr(sb1), sb2->ft->getCharPtr(sb2));

sb1->ft->release(sb1);
sb2->ft->release(sb2);

return result;
}
6 changes: 4 additions & 2 deletions objectpath.h
@@ -1,6 +1,5 @@

/*
* constClass.h
* $id$
*
* © Copyright IBM Corp. 2007
*
Expand All @@ -22,8 +21,11 @@
#ifndef _OBJECTPATH_H
#define _OBJECTPATH_H

#include "utilft.h"

UtilStringBuffer *normalizeObjectPathStrBuf(const CMPIObjectPath * cop);
char *normalizeObjectPathChars(const CMPIObjectPath *cop);
char *normalizeObjectPathCharsDup(const CMPIObjectPath *cop);
int objectpathCompare(const CMPIObjectPath *cop1, const CMPIObjectPath *cop2);

#endif
17 changes: 12 additions & 5 deletions queryOperation.c
Expand Up @@ -27,6 +27,7 @@

#include "queryOperation.h"
#include "mlog.h"
#include "instance.h"

extern CMPIArray *TrackedCMPIArray(CMPICount size, CMPIType type, CMPIStatus * rc);
extern void sfcb_native_array_increase_size(CMPIArray * array, CMPICount increment);
Expand Down Expand Up @@ -258,25 +259,31 @@ static int propCompare(QLOperand* self, QLOperand* op,
return rc;
}

extern const char *instGetClassName(CMPIInstance * ci);
extern int isChild(const char *ns, const char *parent, const char* child);

static int instCompare(QLOperand* self, QLOperand* op, QLPropertySource* src)
{
CMPIInstance *ov;
char *sov;
QLOpd type=op->type;

sov=(char*)instGetClassName(self->inst);
if (type==QL_PropertyName) {
ov=getPropValue(op, src, &type).inst;
}
if (type==QL_Name) {
if (strcasecmp(sov,op->charsVal)==0) return 0;
return isChild(src->sns,sov,op->charsVal)!=0;
}
return isChild(src->sns,op->charsVal,sov)==0;
}
if (type==QL_Inst) {
return instanceCompare(self->inst, ov);
}
return -2;
}

static char* instToString(QLOperand* op)
{
return qsStrDup(NULL,"*** instace ***");
return qsStrDup(NULL,"*** instance ***");
}

static int nameCompare(QLOperand* self, QLOperand* op, QLPropertySource* src)
Expand Down
2 changes: 1 addition & 1 deletion queryOperation.h
Expand Up @@ -2,7 +2,7 @@
/*
* queryOperation.h
*
* (C) Copyright IBM Corp. 2005
* © Copyright IBM Corp. 2005, 2007
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
Expand Down
73 changes: 72 additions & 1 deletion value.c
Expand Up @@ -2,7 +2,7 @@
/*
* value.c
*
* (C) Copyright IBM Corp. 2005
* © Copyright IBM Corp. 2005, 2007
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
Expand All @@ -29,6 +29,8 @@
#include "constClass.h"
#include "qualifier.h"
#include "cmpidtx.h"
#include "instance.h"
#include "objectpath.h"

void sfcb_native_release_CMPIValue(CMPIType type, CMPIValue * val)
{
Expand Down Expand Up @@ -304,3 +306,72 @@ void sfcb_setAlignedValue(CMPIValue * target, const CMPIValue *source,
}
}
}

int sfcb_comp_CMPIValue(CMPIValue *val1, CMPIValue *val2, CMPIType type)
{
int c;
CMPIValue tempVal1, tempVal2;
CMPIString *s1, *s2;

if(type & CMPI_ARRAY) {
c = (val1->array)->ft->getSize(val1->array, NULL);
if(c != (val2->array)->ft->getSize(val2->array, NULL)) {
/* member count not equal -> CMPIValue cannot be equal */
return 1;
}
while(c--) {
tempVal1 = ((val1->array)->ft->getElementAt(val1->array, c-1, NULL)).value;
tempVal2 = ((val2->array)->ft->getElementAt(val2->array, c-1, NULL)).value;

if(sfcb_comp_CMPIValue(&tempVal1, &tempVal2, type & ~CMPI_ARRAY)) {
/* one element does not seem to be identical*/
return 1;
}
}
/* all tests passed - arrays identical */
return 0;
}
if(val1 && val2) {
switch(type) {
case CMPI_boolean:
case CMPI_uint8:
case CMPI_sint8:
if(val1->Byte != val2->Byte) return 1;
break;
case CMPI_char16:
case CMPI_uint16:
case CMPI_sint16:
if(val1->Short != val2->Short) return 1;
break;
case CMPI_uint32:
case CMPI_sint32:
if(val1->Int != val2->Int) return 1;
break;
case CMPI_real32:
if(val1->Float != val2->Float) return 1;
break;
case CMPI_uint64:
case CMPI_sint64:
if(val1->Long != val2->Long) return 1;
break;
case CMPI_real64:
if(val1->Double != val2->Double) return 1;
break;
case CMPI_instance:
return (instanceCompare(val1->inst, val2->inst));
case CMPI_ref:
return (objectpathCompare(val1->ref, val2->ref));
case CMPI_string:
return strcmp(val1->string->ft->getCharPtr(val1->string, NULL),
val2->string->ft->getCharPtr(val2->string, NULL));
case CMPI_dateTime:
s1 = val1->dateTime->ft->getStringFormat(val1->dateTime, NULL);
s2 = val2->dateTime->ft->getStringFormat(val2->dateTime, NULL);
return strcmp(s1->ft->getCharPtr(s1, NULL),
s2->ft->getCharPtr(s2, NULL));
default:
return 0;
}
}
return 0;
}

0 comments on commit f833628

Please sign in to comment.