[PATCH 06/16] nwfilter: Introduce public API to retrieve user-defined metadata

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Introduces `virNWFilterGetMetadata()` to retrieve user defined
metadata fields, i.e `<title>`, `<description>` and `<metadata>`

Signed-off-by: K Shiva Kiran <shiva_kr@xxxxxxxxxx>
---
 include/libvirt/libvirt-nwfilter.h |  5 +++
 src/driver-nwfilter.h              |  6 +++
 src/libvirt-nwfilter.c             | 67 ++++++++++++++++++++++++++++++
 src/libvirt_public.syms            |  1 +
 4 files changed, 79 insertions(+)

diff --git a/include/libvirt/libvirt-nwfilter.h b/include/libvirt/libvirt-nwfilter.h
index ecab779665..2eed685300 100644
--- a/include/libvirt/libvirt-nwfilter.h
+++ b/include/libvirt/libvirt-nwfilter.h
@@ -181,4 +181,9 @@ int                     virNWFilterSetMetadata(virNWFilterPtr nwfilter,
                                                const char *uri,
                                                unsigned int flags);
 
+char *                  virNWFilterGetMetadata(virNWFilterPtr nwfilter,
+                                               int type,
+                                               const char *uri,
+                                               unsigned int flags);
+
 #endif /* LIBVIRT_NWFILTER_H */
diff --git a/src/driver-nwfilter.h b/src/driver-nwfilter.h
index 3426781fa0..8d38dbd23c 100644
--- a/src/driver-nwfilter.h
+++ b/src/driver-nwfilter.h
@@ -94,6 +94,11 @@ typedef int
                              const char *uri,
                              unsigned int flags);
 
+typedef char *
+(*virDrvNWFilterGetMetadata)(virNWFilterPtr nwfilter,
+                             int type,
+                             const char *uri,
+                             unsigned int flags);
 
 typedef struct _virNWFilterDriver virNWFilterDriver;
 
@@ -120,4 +125,5 @@ struct _virNWFilterDriver {
     virDrvNWFilterBindingDelete nwfilterBindingDelete;
     virDrvNWFilterBindingGetXMLDesc nwfilterBindingGetXMLDesc;
     virDrvNWFilterSetMetadata nwfilterSetMetadata;
+    virDrvNWFilterGetMetadata nwfilterGetMetadata;
 };
diff --git a/src/libvirt-nwfilter.c b/src/libvirt-nwfilter.c
index 0a0fbdd195..2340d87c4b 100644
--- a/src/libvirt-nwfilter.c
+++ b/src/libvirt-nwfilter.c
@@ -1007,3 +1007,70 @@ virNWFilterSetMetadata(virNWFilterPtr nwfilter,
     virDispatchError(nwfilter->conn);
     return -1;
 }
+
+
+/**
+ * virNWFilterGetMetadata:
+ * @nwfilter: a network filter object
+ * @type: type of metadata, from virNWFilterMetadataType
+ * @uri: XML namespace identifier
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieves the appropriate network filter element given by @type.
+ * If VIR_NWFILTER_METADATA_ELEMENT is requested parameter @uri
+ * must be set to the name of the namespace the requested elements
+ * belong to, otherwise must be NULL.
+ *
+ * If an element of the network filter XML is not present, the resulting
+ * error will be VIR_ERR_NO_NWFILTER_METADATA.  This method forms
+ * a shortcut for seeing information from virNWFilterSetMetadata()
+ * without having to go through virNWFilterGetXMLDesc().
+ *
+ * Returns the metadata string on success (caller must free),
+ * or NULL in case of failure.
+ *
+ * Since: 9.8.0
+ */
+char *
+virNWFilterGetMetadata(virNWFilterPtr nwfilter,
+                       int type,
+                       const char *uri,
+                       unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DEBUG("nwfilter=%p, type=%d, uri='%s', flags=0x%x",
+               nwfilter, type, NULLSTR(uri), flags);
+
+    virResetLastError();
+
+    virCheckNWFilterReturn(nwfilter, NULL);
+
+    switch (type) {
+    case VIR_NWFILTER_METADATA_TITLE:
+    case VIR_NWFILTER_METADATA_DESCRIPTION:
+        virCheckNullArgGoto(uri, error);
+        break;
+    case VIR_NWFILTER_METADATA_ELEMENT:
+        virCheckNonNullArgGoto(uri, error);
+        break;
+    default:
+        /* For future expansion */
+        break;
+    }
+
+    conn = nwfilter->conn;
+
+    if (conn->nwfilterDriver->nwfilterGetMetadata) {
+        char *ret;
+        if (!(ret = conn->nwfilterDriver->nwfilterGetMetadata(nwfilter, type, uri, flags)))
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+
+ error:
+    virDispatchError(nwfilter->conn);
+    return NULL;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 4e3b17b475..81cd9afc93 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -940,6 +940,7 @@ LIBVIRT_9.7.0 {
 
 LIBVIRT_9.8.0 {
     global:
+        virNWFilterGetMetadata;
         virNWFilterSetMetadata;
 } LIBVIRT_9.7.0;
 
-- 
2.42.0





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux