From nobody Mon Feb 9 01:06:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1620128489; cv=none; d=zohomail.com; s=zohoarc; b=JG+vaRMw0tUt1S9q31WpQLLgfYYGymNplpQjouvsscRP70+6OuTmbSlKn70QyhqTaiU9c412hU4b3E7SClRuZo5nmRXyPN5G0fzx6Zvip3OHcoybYRe71vExPdfynNhzT4QCuC4D3Gplm/xPfZrTPeDibuc4fSdfuOzNX+wS/j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128489; 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=hp5tGT9AWSwOnRD/UEVnGzVX/xIAaqtHA98TlMryRA4=; b=WBqJWQEYqJAS8MmOYMd/LrDDDVVGy6HjdA5nKgCyP9cjUAu4t9c1sVmbFr0dg/sBAvcTXIzfp5wrPmjr56aibULwv6HH6Lv1k50eYVnsaUrNzefAeDiCCvZk6wnvHHb59/KebPD35Z7L9053n+CFoU+pUOF7NZkbieZl6IRQaqM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1620128489659782.4947317645767; Tue, 4 May 2021 04:41:29 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-229-8VLpLh2RMciwrkINQRk5Wg-1; Tue, 04 May 2021 07:41:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 830D5195D586; Tue, 4 May 2021 11:41:19 +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 366D560C4A; Tue, 4 May 2021 11:41:19 +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 006A81801266; Tue, 4 May 2021 11:41:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 144Bf8sP000875 for ; Tue, 4 May 2021 07:41:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 151FE5D9DD; Tue, 4 May 2021 11:41:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 515C75D9D5 for ; Tue, 4 May 2021 11:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128488; 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=hp5tGT9AWSwOnRD/UEVnGzVX/xIAaqtHA98TlMryRA4=; b=faElUcWA6XXUml1ZoSyin2aFCefKt3Zft8BvDEOanZ5SVGVuQ5Zpcbf40kTK2Qzdggue96 XoysdB1yC+wUzP1uKdx5T7uQmyGp/+OT4JFEEEOCXXJPlqRAoVWwaG0RfooxAXJZH38lN8 sMAZ734L657sY3crjGKaQjeLx3SufXQ= X-MC-Unique: 8VLpLh2RMciwrkINQRk5Wg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 15/19] Refactoring virDomainSmartcardDefParseXML() to use XPath Date: Tue, 4 May 2021 13:40:09 +0200 Message-Id: <78a767ff9ac7bc9f04b9f67ab14c64530c6d912d.1620127676.git.khanicov@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Kristina Hanicova --- src/conf/domain_conf.c | 59 ++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d7fd6794f..2511778b15 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11642,12 +11642,14 @@ virDomainSmartcardDefParseXML(virDomainXMLOption = *xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr cur; g_autoptr(virDomainSmartcardDef) def =3D NULL; - size_t i; g_autofree char *mode =3D NULL; g_autofree char *type =3D NULL; + g_autofree xmlNodePtr *certificates =3D NULL; + int n =3D 0; + VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 + ctxt->node =3D node; def =3D g_new0(virDomainSmartcardDef, 1); =20 mode =3D virXMLPropString(node, "mode"); @@ -11668,42 +11670,32 @@ virDomainSmartcardDefParseXML(virDomainXMLOption = *xmlopt, break; =20 case VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES: - i =3D 0; - cur =3D node->children; - while (cur) { - if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "certificate")) { - if (i =3D=3D 3) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("host-certificates mode needs " - "exactly three certificates")); - return NULL; - } - if (!(def->data.cert.file[i] =3D virXMLNodeContentString(c= ur))) - return NULL; - - i++; - } else if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "database") && - !def->data.cert.database) { - if (!(def->data.cert.database =3D virXMLNodeContentString(= cur))) - return NULL; - - if (*def->data.cert.database !=3D '/') { - virReportError(VIR_ERR_XML_ERROR, - _("expecting absolute path: %s"), - def->data.cert.database); - return NULL; - } - } - cur =3D cur->next; - } - if (i < 3) { + n =3D virXPathNodeSet("./certificate", ctxt, &certificates); + if (n !=3D VIR_DOMAIN_SMARTCARD_NUM_CERTIFICATES) { virReportError(VIR_ERR_XML_ERROR, "%s", _("host-certificates mode needs " "exactly three certificates")); return NULL; } + + if (!(def->data.cert.file[0] =3D virXMLNodeContentString(certifica= tes[0])) || + !(def->data.cert.file[1] =3D virXMLNodeContentString(certifica= tes[1])) || + !(def->data.cert.file[2] =3D virXMLNodeContentString(certifica= tes[2]))) + return NULL; + + if (virXPathNode("./database", ctxt) && + !def->data.cert.database) { + if (!(def->data.cert.database =3D + virXPathString("string(./database/text())", ctxt))) + return NULL; + + if (*def->data.cert.database !=3D '/') { + virReportError(VIR_ERR_XML_ERROR, + _("expecting absolute path: %s"), + def->data.cert.database); + return NULL; + } + } break; =20 case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH: @@ -11725,7 +11717,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOption *x= mlopt, return NULL; } =20 - cur =3D node->children; if (virDomainChrSourceDefParseXML(def->data.passthru, node, flags, NULL, ctxt) < 0) return NULL; --=20 2.30.2