Signed-off-by: K Shiva Kiran <shiva_kr(a)riseup.net>
---
src/conf/nwfilter_conf.c | 30 ++++++++++++++++++++++++++++++
src/conf/nwfilter_conf.h | 5 +++++
2 files changed, 35 insertions(+)
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 35f6efbbe2..d03f78af4d 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -327,6 +327,10 @@ virNWFilterDefFree(virNWFilterDef *def)
g_free(def->filterEntries);
g_free(def->chainsuffix);
+ g_free(def->title);
+ g_free(def->description);
+ xmlFreeNode(def->metadata);
+
g_free(def);
}
@@ -2516,6 +2520,7 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
virNWFilterEntry *entry;
int chain_priority;
const char *name_prefix;
+ xmlNodePtr metadataNode = NULL;
ret = g_new0(virNWFilterDef, 1);
@@ -2582,6 +2587,23 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt)
}
}
+ /* Extract short description of filter (title) */
+ ret->title = virXPathString("string(./title[1])", ctxt);
+ if (ret->title && strchr(ret->title, '\n')) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("Network filter title can't contain newlines"));
+ return NULL;
+ }
+
+ /* Extract documentation if present */
+ ret->description = virXPathString("string(./description[1])", ctxt);
+
+ /* Extract custom metadata */
+ if ((metadataNode = virXPathNode("./metadata[1]", ctxt)) != NULL) {
+ ret->metadata = xmlCopyNode(metadataNode, 1);
+ virXMLNodeSanitizeNamespaces(ret->metadata);
+ }
+
curr = curr->children;
while (curr != NULL) {
@@ -2873,6 +2895,14 @@ virNWFilterDefFormat(const virNWFilterDef *def)
virUUIDFormat(def->uuid, uuid);
virBufferAsprintf(&buf, "<uuid>%s</uuid>\n", uuid);
+ virBufferEscapeString(&buf, "<title>%s</title>\n",
def->title);
+
+ virBufferEscapeString(&buf,
"<description>%s</description>\n",
+ def->description);
+
+ if (virXMLFormatMetadata(&buf, def->metadata) < 0)
+ return NULL;
+
for (i = 0; i < def->nentries; i++) {
if (virNWFilterEntryFormat(&buf, def->filterEntries[i]) < 0)
return NULL;
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 22c2fb51f0..34de6eab3d 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -517,6 +517,11 @@ struct _virNWFilterDef {
size_t nentries;
virNWFilterEntry **filterEntries;
+
+ /* User-defined metadata */
+ char* title;
+ char* description;
+ xmlNodePtr metadata;
};
--
2.42.0