On 10/27/2011 06:13 AM, Daniel P. Berrange wrote:
On Mon, Oct 24, 2011 at 12:07:27PM -0400, Stefan Berger wrote:
NWFilters can be provided name-value pairs using the following
XML notiation:
<filterref filter='xyz'>
<parameter name='PORT' value='80'/>
<parameter name='VAL' value='abc'/>
</filterref>
The internal representation currently is so that a name is stored as a
string and the value as well. This patch now addresses the value part of it
and introduces a data structure for storing a value either as a simple
value or as an array for later support of lists (provided in python-like
notation ( [a,b,c] ).
This patch adjusts all code that was handling the values in hash tables
and makes it use the new data type.
Signed-off-by: Stefan Berger<stefanb@xxxxxxxxxxxxxxxxxx>
---
src/conf/domain_conf.c | 2
src/conf/nwfilter_params.c | 288 ++++++++++++++++++++++++++++--
src/conf/nwfilter_params.h | 38 +++
src/libvirt_private.syms | 3
src/nwfilter/nwfilter_ebiptables_driver.c | 15 +
src/nwfilter/nwfilter_gentech_driver.c | 27 ++
src/nwfilter/nwfilter_learnipaddr.c | 13 +
7 files changed, 365 insertions(+), 21 deletions(-)
+bool
+virNWFilterVarValueDelValue(virNWFilterVarValuePtr val, const char *value)
+{
+ unsigned int i;
+
+ switch (val->valType) {
+ case NWFILTER_VALUE_TYPE_SIMPLE:
+ return false;
+
+ case NWFILTER_VALUE_TYPE_ARRAY:
+ for (i = 0; i< val->u.array.nValues; i++) {
+ if (STREQ(value, val->u.array.values[i])) {
+ VIR_FREE(val->u.array.values[i]);
+ val->u.array.nValues--;
+ val->u.array.values[i] =
+ val->u.array.values[val->u.array.nValues];
+ return true;
This doesn't look right. Consider
| A | B | C | D | E |
And you're deleting 'B'. This code will result in a list
| A | C | C | D |
We had nValues = 5 here. We remove item at i=1. nValues = 4 now.
array[1] = array[4] = 'E' -> A | E | C | D.
But it's wrong since I should preserve the ordering of the elements. I
fixed it. Will post a v4. Thanks for the review.
Stefan
--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list