On 10/27/2011 03:07 PM, Stefan Berger wrote:
This patch modifies the NWFilter parameter parser to support multiple
elements with the same name and to internally build a list of items.
An example of the XML looks like this:

         <parameter name='TEST' value='10.1.2.3'/>
         <parameter name='TEST' value='10.2.3.4'/>
         <parameter name='TEST' value='10.1.1.1'/>

Oh, I see - you fixed parsing to allow multiple, more or less replacing the part of patch 1/4 that was trying to do [a,b,c] formatting. We might as well ditch that part of the earlier patch, rather than introducing it just to pull it back out.


The list of values is then stored in the newly introduced data type
virNWFilterVarValue.

The XML formatter is also adapted to print out all items in alphabetical
order sorted by 'name'.

This patch als fixes a bug in the XML schema on the way.

s/als/also/


-static void
-_formatParameterAttrs(void *payload, const void *name, void *data)
+static int
+virNWFilterFormatParameterNameSorter(const virHashKeyValuePairPtr a,
+                                     const virHashKeyValuePairPtr b)
  {
-    struct formatterParam *fp = (struct formatterParam *)data;
-    virNWFilterVarValuePtr value = payload;
-
-    virBufferAsprintf(fp->buf, "%s<parameter name='%s' value='",
-                      fp->indent,
-                      (const char *)name);
-    virNWFilterVarValuePrint(value, fp->buf);
-    virBufferAddLit(fp->buf, "'/>\n");
+    return strcmp((const char *)a->key, (const char *)b->key);
  }

-
  char *
  virNWFilterFormatParamAttributes(virNWFilterHashTablePtr table,
                                   const char *indent)
  {
      virBuffer buf = VIR_BUFFER_INITIALIZER;
-    struct formatterParam fp = {
-        .buf =&buf,
-        .indent = indent,
-    };
+    char **keys, *key;
+    int i, j, card, numKeys;
+    virNWFilterVarValuePtr value;
+
+    if (!table)
+        return NULL;
+
+    keys = (char **)virHashGetKeys(table->hashTable,
+                                   virNWFilterFormatParameterNameSorter);
+    if (!keys)
+        return NULL;
+
+    numKeys = virHashSize(table->hashTable);
+
+    for (i = 0; i<  numKeys; i++) {
+        value = virHashLookup(table->hashTable, keys[i]);
+        card = virNWFilterVarValueGetCardinality(value);
+
+        for (j = 0; j<  card; j++) {
+            virBufferAsprintf(&buf,
+                              "%s<parameter name='%s' value='%s'/>\n",
+                              indent, keys[i],
+                              virNWFilterVarValueGetNthValue(value, j));

Are the parameter values guaranteed to be safe to print, or do you need virBufferEscapeString()?

--
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to