mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-29 12:01:16 +00:00
conf: nwfilter: Refactor virNWFilterFormatParamAttributes
Use virXMLFormatElement and simplify the formatter. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3a5f9a4041
commit
bc2c392bd1
@ -731,45 +731,34 @@ virNWFilterFormatParamAttributes(virBuffer *buf,
|
|||||||
GHashTable *table,
|
GHashTable *table,
|
||||||
const char *filterref)
|
const char *filterref)
|
||||||
{
|
{
|
||||||
virHashKeyValuePair *items;
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
size_t i, j;
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||||
int card, numKeys;
|
g_autofree virHashKeyValuePair *items = NULL;
|
||||||
|
size_t i;
|
||||||
|
size_t nitems;
|
||||||
|
|
||||||
numKeys = virHashSize(table);
|
if (!(items = virHashGetItems(table, &nitems, true))) {
|
||||||
|
|
||||||
if (numKeys < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("missing filter parameter table"));
|
_("missing filter parameter table"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
items = virHashGetItems(table, NULL, true);
|
virBufferAsprintf(&attrBuf, " filter='%s'", filterref);
|
||||||
if (!items)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
virBufferAsprintf(buf, "<filterref filter='%s'", filterref);
|
for (i = 0; i < nitems; i++) {
|
||||||
if (numKeys) {
|
const virNWFilterVarValue *value = items[i].value;
|
||||||
virBufferAddLit(buf, ">\n");
|
size_t npar = virNWFilterVarValueGetCardinality(value);
|
||||||
virBufferAdjustIndent(buf, 2);
|
size_t j;
|
||||||
for (i = 0; i < numKeys; i++) {
|
|
||||||
const virNWFilterVarValue *value = items[i].value;
|
|
||||||
|
|
||||||
card = virNWFilterVarValueGetCardinality(value);
|
for (j = 0; j < npar; j++)
|
||||||
|
virBufferAsprintf(&childBuf,
|
||||||
|
"<parameter name='%s' value='%s'/>\n",
|
||||||
|
(const char *)items[i].key,
|
||||||
|
virNWFilterVarValueGetNthValue(value, j));
|
||||||
|
|
||||||
for (j = 0; j < card; j++)
|
|
||||||
virBufferAsprintf(buf,
|
|
||||||
"<parameter name='%s' value='%s'/>\n",
|
|
||||||
(const char *)items[i].key,
|
|
||||||
virNWFilterVarValueGetNthValue(value, j));
|
|
||||||
|
|
||||||
}
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
|
||||||
virBufferAddLit(buf, "</filterref>\n");
|
|
||||||
} else {
|
|
||||||
virBufferAddLit(buf, "/>\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(items);
|
virXMLFormatElement(buf, "filterref", &attrBuf, &childBuf);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user