An accessor following pattern laid out by virDomainObjList* APIs.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/network_conf.c | 38 ++++++++++++++++++++++++++++++++++++++
src/conf/network_conf.h | 8 ++++++++
src/libvirt_private.syms | 1 +
3 files changed, 47 insertions(+)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index cb54e56..fdf5907 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -4317,3 +4317,41 @@ virNetworkObjListForEach(virNetworkObjListPtr nets,
return ret;
}
+
+int
+virNetworkObjListGetNames(virNetworkObjListPtr nets,
+ bool active,
+ char **names,
+ int nnames,
+ virNetworkObjListFilter filter,
+ virConnectPtr conn)
+{
+ int got = 0;
+ size_t i;
+
+ for (i = 0; i < nets->count && got < nnames; i++) {
+ virNetworkObjPtr obj = nets->objs[i];
+ virNetworkObjLock(obj);
+ if (filter && !filter(conn, obj->def)) {
+ virNetworkObjUnlock(obj);
+ continue;
+ }
+
+ if ((active && virNetworkObjIsActive(obj)) ||
+ (!active && !virNetworkObjIsActive(obj))) {
+ if (VIR_STRDUP(names[got], obj->def->name) < 0) {
+ virNetworkObjUnlock(obj);
+ goto error;
+ }
+ got++;
+ }
+ virNetworkObjUnlock(obj);
+ }
+
+ return got;
+
+ error:
+ for (i = 0; i < got; i++)
+ VIR_FREE(names[i]);
+ return -1;
+}
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 749c7fb..598ddc2 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -451,6 +451,14 @@ typedef int (*virNetworkObjListIterator)(virNetworkObjPtr net,
int virNetworkObjListForEach(virNetworkObjListPtr nets,
virNetworkObjListIterator callback,
void *opaque);
+
+int virNetworkObjListGetNames(virNetworkObjListPtr nets,
+ bool active,
+ char **names,
+ int nnames,
+ virNetworkObjListFilter filter,
+ virConnectPtr conn);
+
/* for testing */
int
virNetworkDefUpdateSection(virNetworkDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a7285d8..f572592 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -571,6 +571,7 @@ virNetworkObjIsDuplicate;
virNetworkObjListExport;
virNetworkObjListForEach;
virNetworkObjListFree;
+virNetworkObjListGetNames;
virNetworkObjLock;
virNetworkObjReplacePersistentDef;
virNetworkObjSetDefTransient;
--
2.0.5