From nobody Sun Feb 8 16:34:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1563526156; cv=none; d=zoho.com; s=zohoarc; b=GR/wqAhmR8WNdGUvrIkN4TOYs/jKrDZCau2Wgq7oo5GdYB04D14Wv5Qxn0clMAZPC7XNMLwMBfezuhHN84u3aXRios3sC48eiFjqjNtUGmuqIR4SeS9dW2Pd3UkMFKDey0lNcxv0exBLYPctoutlG4prwx59nrZjOIqkFK7XXOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563526156; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=WgVIAfu8my27mZ/8BTOKnTbP7FT5EmB+Iac4zK8Jvpo=; b=gA0SW0XEgfJ2Q5u67j7D5JcnBw2sU41t8YQVbZcqE2JXtvpNTy76ojgZcjV9t0Jlbr3Om60ucbGypWO8JwoUgnLB9cHMvy7RgWDHKX71SPNSIxoRXqkLLAgHuZ2BLDNj3zSFx3PffHRWJJ5OZTAW1qUkEhuYMjzgC8mpa7/RPbg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156352615694532.11373615501998; Fri, 19 Jul 2019 01:49:16 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BC1B5D674; Fri, 19 Jul 2019 08:49:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38072101E1CC; Fri, 19 Jul 2019 08:49:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EEFAE18045DD; Fri, 19 Jul 2019 08:49:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6J8mo28005249 for ; Fri, 19 Jul 2019 04:48:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1FE7E6134E; Fri, 19 Jul 2019 08:48:50 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9BCE9601A9 for ; Fri, 19 Jul 2019 08:48:49 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 19 Jul 2019 10:48:33 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/14] tools: Separate nwfilter related completers into a file X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 19 Jul 2019 08:49:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Mixing all completers in one file does not support maintainability. Separate those completers which relate to nwfilter (e.g. they complete various nwfilter aspects) into virsh-completer-nwfilter.c Signed-off-by: Michal Privoznik --- tools/Makefile.am | 1 + tools/virsh-completer-nwfilter.c | 105 +++++++++++++++++++++++++++++++ tools/virsh-completer-nwfilter.h | 31 +++++++++ tools/virsh-completer.c | 80 ----------------------- tools/virsh-completer.h | 9 +-- 5 files changed, 138 insertions(+), 88 deletions(-) create mode 100644 tools/virsh-completer-nwfilter.c create mode 100644 tools/virsh-completer-nwfilter.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 22f476a1c2..513154729a 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -221,6 +221,7 @@ virsh_SOURCES =3D \ virsh-completer-interface.c virsh-completer-interface.h \ virsh-completer-network.c virsh-completer-network.h \ virsh-completer-nodedev.c virsh-completer-nodedev.h \ + virsh-completer-nwfilter.c virsh-completer-nwfilter.h \ virsh-completer-pool.c virsh-completer-pool.h \ virsh-completer-volume.c virsh-completer-volume.h \ virsh-console.c virsh-console.h \ diff --git a/tools/virsh-completer-nwfilter.c b/tools/virsh-completer-nwfil= ter.c new file mode 100644 index 0000000000..0942526f22 --- /dev/null +++ b/tools/virsh-completer-nwfilter.c @@ -0,0 +1,105 @@ +/* + * virsh-completer-nwfilter.c: virsh completer callbacks related to nwfilt= ers + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virsh-completer-nwfilter.h" +#include "viralloc.h" +#include "virsh.h" +#include "virstring.h" + +char ** +virshNWFilterNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNWFilterPtr *nwfilters =3D NULL; + int nnwfilters =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((nnwfilters =3D virConnectListAllNWFilters(priv->conn, &nwfilters,= flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nnwfilters; i++) { + const char *name =3D virNWFilterGetName(nwfilters[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nnwfilters; i++) + virNWFilterFree(nwfilters[i]); + VIR_FREE(nwfilters); + return ret; +} + + +char ** +virshNWFilterBindingNameCompleter(vshControl *ctl, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virNWFilterBindingPtr *bindings =3D NULL; + int nbindings =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if ((nbindings =3D virConnectListAllNWFilterBindings(priv->conn, &bind= ings, flags)) < 0) + return NULL; + + if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) + goto cleanup; + + for (i =3D 0; i < nbindings; i++) { + const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); + + if (VIR_STRDUP(tmp[i], name) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(ret, tmp); + + cleanup: + for (i =3D 0; i < nbindings; i++) + virNWFilterBindingFree(bindings[i]); + VIR_FREE(bindings); + return ret; +} diff --git a/tools/virsh-completer-nwfilter.h b/tools/virsh-completer-nwfil= ter.h new file mode 100644 index 0000000000..86e7df7da4 --- /dev/null +++ b/tools/virsh-completer-nwfilter.h @@ -0,0 +1,31 @@ +/* + * virsh-completer-nwfilter.h: virsh completer callbacks related to nwfilt= ers + * + * Copyright (C) 2019 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "vsh.h" + +char ** virshNWFilterNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + +char ** virshNWFilterBindingNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 0b99b3d578..174bd372ce 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -143,86 +143,6 @@ virshCommaStringListComplete(const char *input, } =20 =20 -char ** -virshNWFilterNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virNWFilterPtr *nwfilters =3D NULL; - int nnwfilters =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if ((nnwfilters =3D virConnectListAllNWFilters(priv->conn, &nwfilters,= flags)) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nnwfilters; i++) { - const char *name =3D virNWFilterGetName(nwfilters[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nnwfilters; i++) - virNWFilterFree(nwfilters[i]); - VIR_FREE(nwfilters); - return ret; -} - - -char ** -virshNWFilterBindingNameCompleter(vshControl *ctl, - const vshCmd *cmd ATTRIBUTE_UNUSED, - unsigned int flags) -{ - virshControlPtr priv =3D ctl->privData; - virNWFilterBindingPtr *bindings =3D NULL; - int nbindings =3D 0; - size_t i =3D 0; - char **ret =3D NULL; - VIR_AUTOSTRINGLIST tmp =3D NULL; - - virCheckFlags(0, NULL); - - if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - return NULL; - - if ((nbindings =3D virConnectListAllNWFilterBindings(priv->conn, &bind= ings, flags)) < 0) - return NULL; - - if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) - goto cleanup; - - for (i =3D 0; i < nbindings; i++) { - const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); - - if (VIR_STRDUP(tmp[i], name) < 0) - goto cleanup; - } - - VIR_STEAL_PTR(ret, tmp); - - cleanup: - for (i =3D 0; i < nbindings; i++) - virNWFilterBindingFree(bindings[i]); - VIR_FREE(bindings); - return ret; -} - - char ** virshSecretUUIDCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 39896c13c5..20bf73b4e5 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -26,20 +26,13 @@ #include "virsh-completer-interface.h" #include "virsh-completer-network.h" #include "virsh-completer-nodedev.h" +#include "virsh-completer-nwfilter.h" #include "virsh-completer-pool.h" #include "virsh-completer-volume.h" =20 char ** virshCommaStringListComplete(const char *input, const char **options); =20 -char ** virshNWFilterNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - -char ** virshNWFilterBindingNameCompleter(vshControl *ctl, - const vshCmd *cmd, - unsigned int flags); - char ** virshSecretUUIDCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list