From nobody Tue Feb 10 04:13:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190888; cv=none; d=zohomail.com; s=zohoarc; b=gMBxklpMbme+TwOHBiJyCRcHxFC/+9IzZgvu/SxanmlN2pjBOtrbdaSibQxCvxZzqab02UZvrfmAuQ2zG+fglXfCL7veBi9jexKNWMJkkzQ9FOfwyxcH7Bn/r78A/3Dcg31UUnZQT+H7JVopJBxGvSWQf1vzDXSCy1PTAPQAdQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190888; 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=fBpZLZu87x9DyDyEnvEuwNRjCR9vWDDPJHpx3Ckvf0g=; b=VkRqxIJzbx7LXxMeETC9YtEztnAV4hOdDUZkCHQ5A7tlGxE8FXHh9lMXelj2D2CtimbWnzJOD9b7P/kFM7tLKWrYrteMa6wFs2MJBB4N/hCsdal2C5GrNMLpVINUInLnOztmBYl8av+BSy9eiodJTYugjWZSfoX/M+T8alSiI/0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599190887888467.5233613074482; Thu, 3 Sep 2020 20:41:27 -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-193-M2xtXnhNO9Wbw6lDHL33CQ-1; Thu, 03 Sep 2020 23:41:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CC63801FC6; Fri, 4 Sep 2020 03:41:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 989A81A885; Fri, 4 Sep 2020 03:41:18 +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 9AF7379A27; Fri, 4 Sep 2020 03:41:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAEH030573 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 503D62157F5D; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B9922157F49 for ; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DB33800962 for ; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mail-m24147.qiye.163.com (mail-m24147.qiye.163.com [220.194.24.147]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-Fzb-DiBxPkixGo_TiJ33vA-1; Thu, 03 Sep 2020 23:41:07 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S46; Fri, 04 Sep 2020 11:35:58 +0800 (CST) X-MC-Unique: M2xtXnhNO9Wbw6lDHL33CQ-1 X-MC-Unique: Fzb-DiBxPkixGo_TiJ33vA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 44/46] conf: Extract error-checking code from virDomainGraphicsDefParseXML Date: Fri, 4 Sep 2020 11:35:36 +0800 Message-Id: <20200904033538.418579-45-shi_lei@massclouds.com> In-Reply-To: <20200904033538.418579-1-shi_lei@massclouds.com> References: <20200904033538.418579-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: JedpCgAHcNgStlFfYHYgCg--.1426S46 X-Coremail-Antispam: 1Uf129KBjvJXoW3Ar4DJFW8Cw4rGw48ZF18Zrb_yoWfXr4kpF 93XFW0qay5Gw1fGrsaqa109r4rWrnrX3y7Gr95Jw4jkrWUWrs3Aw10yay2qrnrJr48Zay3 ZF4xKr48ursIvFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_yxRPUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbihhOVT1sfnaG8swAAs4 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false; X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei --- src/conf/domain_conf.c | 184 +++++++++++++++++++++++------------------ 1 file changed, 103 insertions(+), 81 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 007ee44..60bea6f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14191,12 +14191,10 @@ virDomainGraphicsListensParseXML(virDomainGraphic= sDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - VIR_XPATH_NODE_AUTORESTORE(ctxt) - virDomainGraphicsListenDef newListen =3D {0}; int nListens; int ret =3D -1; g_autofree xmlNodePtr *listenNodes =3D NULL; - g_autofree char *socketPath =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); =20 ctxt->node =3D node; =20 @@ -14218,84 +14216,12 @@ virDomainGraphicsListensParseXML(virDomainGraphic= sDefPtr def, def, &flags) < 0) goto cleanup; =20 - if (i =3D=3D 0) { - g_autofree char *addressCompat =3D NULL; - g_autofree char *socketCompat =3D NULL; - - addressCompat =3D virXMLPropString(node, "listen"); - socketCompat =3D virXMLPropString(node, "socket"); - - if (listen->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_AD= DRESS) { - if (listen->address && addressCompat && STRNEQ(listen-= >address, addressCompat)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("graphics 'listen' attribute '%s'= must match " - "'address' attribute of first lis= ten element " - "(found '%s')"), addressCompat, l= isten->address); - goto cleanup; - } - - if (!listen->address) - listen->address =3D g_steal_pointer(&addressCompat= ); - } - - if (listen->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SO= CKET) { - if (listen->socket && socketCompat && STRNEQ(listen->s= ocket, socketCompat)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("graphics 'socket' attribute '%s'= must match " - "'socket' attribute of first list= en element " - "(found '%s')"), socketCompat, li= sten->socket); - goto cleanup; - } - - if (!listen->socket) - listen->socket =3D g_steal_pointer(&socketCompat); - } - } - def->nListens++; } } =20 - /* If no element was found in XML for backward compatibility - * we should try to parse 'listen' or 'socket' attribute from - * element. */ - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) - socketPath =3D virXMLPropString(node, "socket"); - - if (socketPath) { - newListen.type =3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET; - newListen.socket =3D g_steal_pointer(&socketPath); - } else { - newListen.type =3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; - newListen.address =3D virXMLPropString(node, "listen"); - if (STREQ_NULLABLE(newListen.address, "")) - VIR_FREE(newListen.address); - } - - /* If no element was found add a new one created by parsing - * element. */ - if (def->nListens =3D=3D 0) { - if (VIR_APPEND_ELEMENT(def->listens, def->nListens, newListen) < 0) - goto cleanup; - } else { - virDomainGraphicsListenDefPtr glisten =3D &def->listens[0]; - - /* If the first element is 'address' or 'network' and we= found - * 'socket' attribute inside element for backward - * compatibility we need to replace the first listen by - * element based on the 'socket' att= ribute. */ - if ((glisten->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS = || - glisten->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)= && - newListen.type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) { - virDomainGraphicsListenDefClear(glisten); - *glisten =3D newListen; - memset(&newListen, 0, sizeof(newListen)); - } - } - ret =3D 0; cleanup: - virDomainGraphicsListenDefClear(&newListen); return ret; } =20 @@ -14442,6 +14368,102 @@ virDomainNetDefNew(virDomainXMLOptionPtr xmlopt) } =20 =20 +static int +virDomainGraphicsDefParseXMLHook(xmlNodePtr node, + virDomainGraphicsDefPtr def, + const char *instname G_GNUC_UNUSED, + void *parent G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + int ret =3D -1; + virDomainGraphicsListenDef newListen =3D {0}; + g_autofree char *socketPath =3D NULL; + + if (def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC && + def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_RDP && + def->type !=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) + return 0; + + if (def->nListens > 0) { + virDomainGraphicsListenDefPtr listen =3D &def->listens[0]; + g_autofree char *addressCompat =3D NULL; + g_autofree char *socketCompat =3D NULL; + + addressCompat =3D virXMLPropString(node, "listen"); + socketCompat =3D virXMLPropString(node, "socket"); + + if (listen->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { + if (listen->address && addressCompat && STRNEQ(listen->address= , addressCompat)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("graphics 'listen' attribute '%s' must ma= tch " + "'address' attribute of first listen elem= ent " + "(found '%s')"), addressCompat, listen->a= ddress); + goto cleanup; + } + + if (!listen->address) + listen->address =3D g_steal_pointer(&addressCompat); + } + + if (listen->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) { + if (listen->socket && socketCompat && STRNEQ(listen->socket, s= ocketCompat)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("graphics 'socket' attribute '%s' must ma= tch " + "'socket' attribute of first listen eleme= nt " + "(found '%s')"), socketCompat, listen->so= cket); + goto cleanup; + } + + if (!listen->socket) + listen->socket =3D g_steal_pointer(&socketCompat); + } + } + + /* If no element was found in XML for backward compatibility + * we should try to parse 'listen' or 'socket' attribute from + * element. */ + if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) + socketPath =3D virXMLPropString(node, "socket"); + + if (socketPath) { + newListen.type =3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET; + newListen.socket =3D g_steal_pointer(&socketPath); + } else { + newListen.type =3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; + newListen.address =3D virXMLPropString(node, "listen"); + if (STREQ_NULLABLE(newListen.address, "")) + VIR_FREE(newListen.address); + } + + /* If no element was found add a new one created by parsing + * element. */ + if (def->nListens =3D=3D 0) { + if (VIR_APPEND_ELEMENT(def->listens, def->nListens, newListen) < 0) + goto cleanup; + } else { + virDomainGraphicsListenDefPtr glisten =3D &def->listens[0]; + + /* If the first element is 'address' or 'network' and we= found + * 'socket' attribute inside element for backward + * compatibility we need to replace the first listen by + * element based on the 'socket' att= ribute. */ + if ((glisten->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS = || + glisten->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)= && + newListen.type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) { + virDomainGraphicsListenDefClear(glisten); + *glisten =3D newListen; + memset(&newListen, 0, sizeof(newListen)); + } + } + + ret =3D 0; + + cleanup: + virDomainGraphicsListenDefClear(&newListen); + return ret; +} + + /* Parse the XML definition for a graphics device */ static virDomainGraphicsDefPtr virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt, @@ -14470,20 +14492,19 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPt= r xmlopt, } def->type =3D typeVal; =20 + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; + switch (def->type) { case VIR_DOMAIN_GRAPHICS_TYPE_VNC: if (virDomainGraphicsVNCDefParseXML(node, &def->data.vnc, NULL, de= f, &flags) < 0) goto error; - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SDL: if (virDomainGraphicsSDLDefParseXML(node, &def->data.sdl, NULL, de= f, NULL) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; if (virDomainGraphicsRDPDefParseXML(node, &def->data.rdp, NULL, de= f, &flags) < 0) goto error; break; @@ -14492,8 +14513,6 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; if (virDomainGraphicsSpiceDefParseXML(node, &def->data.spice, NULL= , def, &flags) < 0) goto error; break; @@ -14505,6 +14524,9 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, break; } =20 + if (virDomainGraphicsDefParseXMLHook(node, def, NULL, NULL, &flags) < = 0) + goto error; + return def; =20 error: --=20 2.25.1