From nobody Sun Feb 8 12:59:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1685705404; cv=none; d=zohomail.com; s=zohoarc; b=dPE3OkyGy5Z/5B1umv+DLdmbhLpUyrVXq0hkDFoHFvegcMY3xkOOpZfpMcEMLYD8Vor3OnwhZKKtrDvJQqFSyzd2hIgtIcyhmNp1wwv59aA3R+qfI4PIiH/JF8DTCL1ayzvz2w9attNKWc/2uVLEY9qXNM0AI1jVFYdPFqpHP+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685705404; 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; bh=3ILj8wQ92X6Q+jVvgRqyJDzdey76zahYEsZud1yVIlY=; b=VBCJreBNsmNPVOSvts2E01i4iTPedxfB9cYO7JJmAFf3YwZkSv/xx1SNznEYIkUVm59IDuSRcObdsQdAphI141MK5a1ZXi7PDtAKVCSaBIL452oL8wN0EkeiYUBTa0MLHVJA6LvYkvAXoWEe7lL2tU1jkwfQ+4t0XgUyQSd7YwQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1685705404684486.66988019608107; Fri, 2 Jun 2023 04:30:04 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-341-ZzddNHhnO2SVvuGbSfakLA-1; Fri, 02 Jun 2023 07:28:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4ADEE3C13926; Fri, 2 Jun 2023 11:28:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3681A2026D49; Fri, 2 Jun 2023 11:28:41 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 27F9B19465B6; Fri, 2 Jun 2023 11:28:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 81A3619465A2 for ; Fri, 2 Jun 2023 11:28:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 6E7A19E60; Fri, 2 Jun 2023 11:28:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE8DB8162 for ; Fri, 2 Jun 2023 11:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685705403; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3ILj8wQ92X6Q+jVvgRqyJDzdey76zahYEsZud1yVIlY=; b=SiR3T+IsZn1SuARW6awXifu7Mb8fisAm6mEu+Ts4cwmZH/ZZ2voEl3j8VdHH/Qr3uey8TW 00bge7Xk6QiW3A+P0y5AZMdEhXxpHLlgent+vAxiQnyPcd0fQR9aZBOm8lm2aPqOKvfCS3 uPDSCwfOzsDmyRD0mlKys4PkoIUtgYM= X-MC-Unique: ZzddNHhnO2SVvuGbSfakLA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/15] conf: nwfilter: Refactor virNWFilterFormatParamAttributes Date: Fri, 2 Jun 2023 13:28:25 +0200 Message-Id: <83b865b05f4cc8a07b9ce2ff0ef7f8490caed278.1685705273.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1685705406608100001 Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement and simplify the formatter. Signed-off-by: Peter Krempa --- src/conf/nwfilter_params.c | 45 ++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c index 496ed2f0b8..868baf7192 100644 --- a/src/conf/nwfilter_params.c +++ b/src/conf/nwfilter_params.c @@ -731,45 +731,34 @@ virNWFilterFormatParamAttributes(virBuffer *buf, GHashTable *table, const char *filterref) { - virHashKeyValuePair *items; - size_t i, j; - int card, numKeys; - - numKeys =3D virHashSize(table); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_autofree virHashKeyValuePair *items =3D NULL; + size_t i; + size_t nitems; - if (numKeys < 0) { + if (!(items =3D virHashGetItems(table, &nitems, true))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing filter parameter table")); return -1; } - items =3D virHashGetItems(table, NULL, true); - if (!items) - return -1; + virBufferAsprintf(&attrBuf, " filter=3D'%s'", filterref); - virBufferAsprintf(buf, "\n"); - virBufferAdjustIndent(buf, 2); - for (i =3D 0; i < numKeys; i++) { - const virNWFilterVarValue *value =3D items[i].value; + for (i =3D 0; i < nitems; i++) { + const virNWFilterVarValue *value =3D items[i].value; + size_t npar =3D virNWFilterVarValueGetCardinality(value); + size_t j; - card =3D virNWFilterVarValueGetCardinality(value); + for (j =3D 0; j < npar; j++) + virBufferAsprintf(&childBuf, + "\n", + (const char *)items[i].key, + virNWFilterVarValueGetNthValue(value, j)); - for (j =3D 0; j < card; j++) - virBufferAsprintf(buf, - "\n= ", - (const char *)items[i].key, - virNWFilterVarValueGetNthValue(value, j)= ); - - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); } - VIR_FREE(items); + virXMLFormatElement(buf, "filterref", &attrBuf, &childBuf); return 0; } --=20 2.40.1