nwfilter: utility function virNWFilterVarValueEqual

To detect if an interface's nwfilter has changed, we need to also
compare the filterparams, which is a hashtable of virNWFilterVarValue.
virHashEqual can do this nicely, but requires a pointer to a function
that will compare two of the items being stored in the hashes.
This commit is contained in:
Stefan Berger 2012-11-29 12:49:32 -05:00 committed by Laine Stump
parent 3738cf41f1
commit ab4139a493
3 changed files with 34 additions and 0 deletions

View File

@ -189,6 +189,37 @@ virNWFilterVarValueGetCardinality(const virNWFilterVarValuePtr val)
return 0;
}
bool
virNWFilterVarValueEqual(const virNWFilterVarValuePtr a,
const virNWFilterVarValuePtr b)
{
unsigned int card, i, j;
const char *s;
if (!a || !b)
return false;
card = virNWFilterVarValueGetCardinality(a);
if (card != virNWFilterVarValueGetCardinality(b))
return false;
/* brute force O(n^2) comparison */
for (i = 0; i < card; i++) {
bool eq = false;
s = virNWFilterVarValueGetNthValue(a, i);
for (j = 0; j < card; j++) {
if (STREQ_NULLABLE(s, virNWFilterVarValueGetNthValue(b, j))) {
eq = true;
break;
}
}
if (!eq)
return false;
}
return true;
}
int
virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value)
{

View File

@ -57,6 +57,8 @@ const char *virNWFilterVarValueGetSimple(const virNWFilterVarValuePtr val);
const char *virNWFilterVarValueGetNthValue(virNWFilterVarValuePtr val,
unsigned int idx);
unsigned int virNWFilterVarValueGetCardinality(const virNWFilterVarValuePtr);
bool virNWFilterVarValueEqual(const virNWFilterVarValuePtr a,
const virNWFilterVarValuePtr b);
int virNWFilterVarValueAddValue(virNWFilterVarValuePtr val, char *value);
int virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *value);

View File

@ -975,6 +975,7 @@ virNWFilterVarValueCopy;
virNWFilterVarValueCreateSimple;
virNWFilterVarValueCreateSimpleCopyValue;
virNWFilterVarValueDelValue;
virNWFilterVarValueEqual;
virNWFilterVarValueFree;
virNWFilterVarValueGetCardinality;
virNWFilterVarValueGetNthValue;