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 bcfcccd..84becb5 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -4312,3 +4312,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 b9acc0e..d357892 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -451,6 +451,14 @@ typedef int (*virNetworkObjListIterator)(virNetworkObjPtr dom,
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 8577006..3e7e389 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -572,6 +572,7 @@ virNetworkObjIsDuplicate;
virNetworkObjListExport;
virNetworkObjListForEach;
virNetworkObjListFree;
+virNetworkObjListGetNames;
virNetworkObjLock;
virNetworkObjReplacePersistentDef;
virNetworkObjSetDefTransient;
--
2.0.5