From nobody Sun Feb 8 14:59:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1620128656; cv=none; d=zohomail.com; s=zohoarc; b=B4dN5y3TtlFpZMUycbNgqU4ECTXgbFxVh/R1rWgKLBI5DcghAh94Bbst9yP75jBF/L/nvOR4kcIQU+WhRXg+8uAecLnHQI5wEhjDGRPLJqRIYXs0XL7WBQtMFXA0Tmh0ltjmh4ZjaUcJXEcCb8ug6t+DhD9KOAiJewNex2oOFBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620128656; 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=xL+Ri2o3I9s+eH3ijchx6Ea6T1XxsstufRK0wlWC67E=; b=BmZuGZaWST+rTJlQWpThXW0/I6FuzJ3tua1KOWxoJoKDnMXY5qiFvpALl3PYkiIHtZEHPuQXVsACie+e9XjReDasmqfKlUiVwhOuxY3/Dm7+szzD6ElYZzR0sUXrUdRuVgCuSOTTScZEOK2DYwhVvbXNS4bZTd8bK4F5wGb8G5s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 162012865613371.86815524102133; Tue, 4 May 2021 04:44:16 -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-360-8uvwSfUjMWWCbtCLZAk2Lg-1; Tue, 04 May 2021 07:41:20 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43C2A805EF4; Tue, 4 May 2021 11:41:16 +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 A61C610190AA; Tue, 4 May 2021 11:41: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 6CE901801267; Tue, 4 May 2021 11:41:15 +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 144Bf9OR000897 for ; Tue, 4 May 2021 07:41:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93DDE5D9F0; Tue, 4 May 2021 11:41:09 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.195.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A54A25D9DE for ; Tue, 4 May 2021 11:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620128655; 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=xL+Ri2o3I9s+eH3ijchx6Ea6T1XxsstufRK0wlWC67E=; b=JuSyDo53i7yQLwRbB9mDCe5+wsK/ZdS+rReuZC1NKRLqch/jhOYan+DBpH0CCdb3JDkrM6 O1qLQSNYySxF0I3K5n8IHYPa30B+2kNnh6q7t9fyALj2LTTYCu5sv/hQRy0o1W7P/ze23n QPvOmHXel9sJcegJUELl3b00ALGB54w= X-MC-Unique: 8uvwSfUjMWWCbtCLZAk2Lg-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH v2 16/19] Refactoring virDomainGraphicsDefParseXMLSpice() to use XPath Date: Tue, 4 May 2021 13:40:10 +0200 Message-Id: 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.84 on 10.5.11.22 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 | 303 ++++++++++++++++------------------------- 1 file changed, 114 insertions(+), 189 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2511778b15..206816d76f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12690,12 +12690,29 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDef *def, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr cur; int defaultModeVal; + int nameval; + g_autofree xmlNodePtr *node_list =3D NULL; + int n =3D 0; + size_t i =3D 0; + int value =3D 0; g_autofree char *port =3D virXMLPropString(node, "port"); g_autofree char *tlsPort =3D virXMLPropString(node, "tlsPort"); g_autofree char *autoport =3D virXMLPropString(node, "autoport"); g_autofree char *defaultMode =3D virXMLPropString(node, "defaultMode"); + g_autofree char *compression =3D NULL; + g_autofree char *jpeg_compression =3D NULL; + g_autofree char *zlib_compression =3D NULL; + g_autofree char *playback_compression =3D NULL; + g_autofree char *streaming_mode =3D NULL; + g_autofree char *copypaste =3D NULL; + g_autofree char *filetransfer_enable =3D NULL; + g_autofree char *gl_enable =3D NULL; + g_autofree char *mouse_mode =3D NULL; + g_autofree char *rendernode =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt) + + ctxt->node =3D node; =20 if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) return -1; @@ -12751,207 +12768,115 @@ virDomainGraphicsDefParseXMLSpice(virDomainGrap= hicsDef *def, def->type) < 0) return -1; =20 - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (virXMLNodeNameEqual(cur, "channel")) { - int nameval, modeval; - g_autofree char *name =3D NULL; - g_autofree char *mode =3D NULL; - - name =3D virXMLPropString(cur, "name"); - mode =3D virXMLPropString(cur, "mode"); - - if (!name || !mode) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice channel missing name/mode")); - return -1; - } - - if ((nameval =3D virDomainGraphicsSpiceChannelNameTypeFrom= String(name)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel name %s"), - name); - return -1; - } - if ((modeval =3D virDomainGraphicsSpiceChannelModeTypeFrom= String(mode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel mode %s"), - mode); - return -1; - } - - def->data.spice.channels[nameval] =3D modeval; - } else if (virXMLNodeNameEqual(cur, "image")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice image missing compression")); - return -1; - } - - if ((compressionVal =3D - virDomainGraphicsSpiceImageCompressionTypeFromString(= compression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice image compression %s"), - compression); - return -1; - } - - def->data.spice.image =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "jpeg")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice jpeg missing compression")); - return -1; - } - - if ((compressionVal =3D - virDomainGraphicsSpiceJpegCompressionTypeFromString(c= ompression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice jpeg compression %s"), - compression); - return -1; - } - - def->data.spice.jpeg =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "zlib")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice zlib missing compression")); - return -1; - } - - if ((compressionVal =3D - virDomainGraphicsSpiceZlibCompressionTypeFromString(c= ompression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice zlib compression %s"), - compression); - return -1; - } - - def->data.spice.zlib =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "playback")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice playback missing compression")= ); - return -1; - } - - if ((compressionVal =3D - virTristateSwitchTypeFromString(compression)) <=3D 0)= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice playback compression")= ); - return -1; - } - - def->data.spice.playback =3D compressionVal; - } else if (virXMLNodeNameEqual(cur, "streaming")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); - - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice streaming missing mode")); - return -1; - } - if ((modeVal =3D - virDomainGraphicsSpiceStreamingModeTypeFromString(mod= e)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice streaming mode")); - return -1; - } - - def->data.spice.streaming =3D modeVal; - } else if (virXMLNodeNameEqual(cur, "clipboard")) { - int copypasteVal; - g_autofree char *copypaste =3D virXMLPropString(cur, "copy= paste"); - - if (!copypaste) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice clipboard missing copypaste")); - return -1; - } + if ((n =3D virXPathNodeSet("./channel", ctxt, &node_list)) < 0) + return -1; =20 - if ((copypasteVal =3D - virTristateBoolTypeFromString(copypaste)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copy= paste); - return -1; - } + for (i =3D 0; i < n; i++) { + g_autofree char *name =3D virXMLPropString(node_list[i], "name"); + g_autofree char *mode =3D virXMLPropString(node_list[i], "mode"); =20 - def->data.spice.copypaste =3D copypasteVal; - } else if (virXMLNodeNameEqual(cur, "filetransfer")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); + if ((nameval =3D virDomainGraphicsSpiceChannelNameTypeFromString(n= ame)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice channel name %s"), NULLSTR(nam= e)); + return -1; + } + if ((value =3D virDomainGraphicsSpiceChannelModeTypeFromString(mod= e)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice channel mode %s"), NULLSTR(mod= e)); + return -1; + } + def->data.spice.channels[nameval] =3D value; + } =20 - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice filetransfer missing enable")); - return -1; - } + if ((compression =3D virXPathString("string(./image/@compression)", ct= xt))) { + if ((value =3D + virDomainGraphicsSpiceImageCompressionTypeFromString(compressi= on)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice image compression %s"), compre= ssion); + return -1; + } + def->data.spice.image =3D value; + } =20 - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } + if ((jpeg_compression =3D virXPathString("string(./jpeg/@compression)"= , ctxt))) { + if ((value =3D + virDomainGraphicsSpiceJpegCompressionTypeFromString(jpeg_comp= ression)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice jpeg compression %s"), + jpeg_compression); + return -1; + } + def->data.spice.jpeg =3D value; + } =20 - def->data.spice.filetransfer =3D enableVal; - } else if (virXMLNodeNameEqual(cur, "gl")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); - g_autofree char *rendernode =3D virXMLPropString(cur, "ren= dernode"); + if ((zlib_compression =3D virXPathString("string(./zlib/@compression)"= , ctxt))) { + if ((value =3D + virDomainGraphicsSpiceZlibCompressionTypeFromString(zlib_comp= ression)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown spice zlib compression %s"), + zlib_compression); + return -1; + } + def->data.spice.zlib =3D value; + } =20 - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice gl element missing enable")); - return -1; - } + if ((playback_compression =3D virXPathString("string(./playback/@compr= ession)", ctxt))) { + if ((value =3D virTristateSwitchTypeFromString(playback_compressio= n)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown spice playback compression")); + return -1; + } + def->data.spice.playback =3D value; + } =20 - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } + if ((streaming_mode =3D virXPathString("string(./streaming/@mode)", ct= xt))) { + if ((value =3D + virDomainGraphicsSpiceStreamingModeTypeFromString(streaming_m= ode)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown spice streaming mode")); + return -1; + } + def->data.spice.streaming =3D value; + } =20 - def->data.spice.gl =3D enableVal; - def->data.spice.rendernode =3D g_steal_pointer(&rendernode= ); + if ((copypaste =3D virXPathString("string(./clipboard/@copypaste)", ct= xt))) { + if ((value =3D virTristateBoolTypeFromString(copypaste)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown copypaste value '%s'"), copypaste); + return -1; + } + def->data.spice.copypaste =3D value; + } =20 - } else if (virXMLNodeNameEqual(cur, "mouse")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); + if ((filetransfer_enable =3D virXPathString("string(./filetransfer/@en= able)", ctxt))) { + if ((value =3D virTristateBoolTypeFromString(filetransfer_enable))= <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown enable value '%s'"), + filetransfer_enable); + return -1; + } + def->data.spice.filetransfer =3D value; + } =20 - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice mouse missing mode")); - return -1; - } + if ((gl_enable =3D virXPathString("string(./gl/@enable)", ctxt))) { + rendernode =3D virXPathString("string(./gl/@rendernode)", ctxt); =20 - if ((modeVal =3D virDomainGraphicsSpiceMouseModeTypeFromSt= ring(mode)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown mouse mode value '%s'"), - mode); - return -1; - } + if ((value =3D virTristateBoolTypeFromString(gl_enable)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown enable value '%s'"), gl_enable); + return -1; + } + def->data.spice.gl =3D value; + def->data.spice.rendernode =3D g_steal_pointer(&rendernode); + } =20 - def->data.spice.mousemode =3D modeVal; - } + if ((mouse_mode =3D virXPathString("string(./mouse/@mode)", ctxt))) { + if ((value =3D virDomainGraphicsSpiceMouseModeTypeFromString(mouse= _mode)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown mouse mode value '%s'"), mouse_mode); + return -1; } - cur =3D cur->next; + def->data.spice.mousemode =3D value; } =20 return 0; --=20 2.30.2