From nobody Tue May 7 16:33:20 2024 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=1599190918; cv=none; d=zohomail.com; s=zohoarc; b=UGGH7trhuKwuXMT49NvbrTID6OHLWGzz0vi/plITJi+KZ6m41V0lnf/X/MzN41LHsiiTa6oApDddaLP78iPnmkiQacjAK5ptm8BJ8wTyf9Msmb4r1XrpD1krUKny73fxkLK2zfzpRrTMXVRnD0kuTVWp1kmd/p9T+Tq2YsJU1Vw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190918; 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=RGO3VYU3oBRwD0yr5kemO3b2N3Gg1nOcfrFKVlUN4ms=; b=hYxcwRptEWq3BmF5uhc6YIRX9SrMBrkphBBqxgOurlAoEPE7VbJm7XzCSKIXkYaTMePmftgXn1CCgp53DenUbFra1fpANayZSjg5qeonjlJJbn3gFT17s+LY0mU8fous2JMP7+yr87js/gvks8ohXofnXAOjO8g+GAdApAOzm98= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599190918485209.03283297939004; Thu, 3 Sep 2020 20:41:58 -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-327-1nlMIYSoNqWOqsE0IL_GiQ-1; Thu, 03 Sep 2020 23:41:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DA5C85EE96; Fri, 4 Sep 2020 03:41:45 +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 DDEFC5C1C2; Fri, 4 Sep 2020 03:41:44 +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 AA3A01800FF5; Fri, 4 Sep 2020 03:41:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAMU030559 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F24D10379B; 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 1007EEE873 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 3C39A800962 for ; Fri, 4 Sep 2020 03:41:08 +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-166-nschr7QuOruTJCSzWaERjA-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S3; Fri, 04 Sep 2020 11:35:46 +0800 (CST) X-MC-Unique: 1nlMIYSoNqWOqsE0IL_GiQ-1 X-MC-Unique: nschr7QuOruTJCSzWaERjA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 01/46] scripts: Add a tool to generate xml parse/format functions Date: Fri, 4 Sep 2020 11:34:53 +0800 Message-Id: <20200904033538.418579-2-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--.1426S3 X-Coremail-Antispam: 1Uf129KBjvAXoWfKw13tw1DArWrKr1fXF4Dtwb_yoW7JF4fCo WfK3W8tF1rur43KrykKF97Wr1kur90gr47J3s3Gry5Wa1qqrW5u3WrZa13Wa90vr4UCr90 vr1Iva4fWF4DAFyfn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4iK9auUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiWhSVT1f4pvWJpQAAsE 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.79 on 10.11.54.5 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.16 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" This tool is used to generate parsexml/formatbuf functions. It is based on libclang and its python-binding. Some directives (such as genparse, xmlattr, etc.) need to be added on the declarations of structs to direct the tool. Signed-off-by: Shi Lei --- po/POTFILES.in | 1 + scripts/xmlgen/directive.py | 1115 +++++++++++++++++++++++++++++++++++ scripts/xmlgen/go | 7 + scripts/xmlgen/main.py | 439 ++++++++++++++ scripts/xmlgen/utils.py | 121 ++++ 5 files changed, 1683 insertions(+) create mode 100644 scripts/xmlgen/directive.py create mode 100755 scripts/xmlgen/go create mode 100755 scripts/xmlgen/main.py create mode 100644 scripts/xmlgen/utils.py diff --git a/po/POTFILES.in b/po/POTFILES.in index 3d6c20c..c9c0262 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -5,6 +5,7 @@ @BUILDDIR@src/admin/admin_server_dispatch_stubs.h @BUILDDIR@src/remote/remote_client_bodies.h @BUILDDIR@src/remote/remote_daemon_dispatch_stubs.h +@SRCDIR@scripts/xmlgen/directive.py @SRCDIR@src/access/viraccessdriverpolkit.c @SRCDIR@src/access/viraccessmanager.c @SRCDIR@src/admin/admin_server.c diff --git a/scripts/xmlgen/directive.py b/scripts/xmlgen/directive.py new file mode 100644 index 0000000..9b73931 --- /dev/null +++ b/scripts/xmlgen/directive.py @@ -0,0 +1,1115 @@ +# +# Copyright (C) 2020 Shandong Massclouds Co.,Ltd. +# +# 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 +# . +# + +import json +from collections import OrderedDict +from utils import singleton, dedup, Block, Terms, render + +BUILTIN_TYPES =3D { + 'String': {}, + 'Bool': {}, + 'Chars': { + 'conv': 'virStrcpyStatic(def->${name}, ${name}Str)' + }, + 'UChars': { + 'conv': 'virStrcpyStatic((char *)def->${name}, ${mdvar})' + }, + 'Int': { + 'fmt': '%d', + 'conv': 'virStrToLong_i(${mdvar}, NULL, 0, &def->${name})' + }, + 'UInt': { + 'fmt': '%u', + 'conv': 'virStrToLong_uip(${mdvar}, NULL, 0, &def->${name})' + }, + 'ULong': { + 'fmt': '%lu', + 'conv': 'virStrToLong_ulp(${mdvar}, NULL, 0, &def->${name})' + }, + 'ULongLong': { + 'fmt': '%llu', + 'conv': 'virStrToLong_ullp(${mdvar}, NULL, 0, &def->${name})' + }, + 'U8': { + 'fmt': '%u', + 'conv': 'virStrToLong_u8p(${mdvar}, NULL, 0, &def->${name})' + }, + 'U32': { + 'fmt': '%u', + 'conv': 'virStrToLong_uip(${mdvar}, NULL, 0, &def->${name})' + }, + 'Time': { + 'conv': 'virStrToTime(${mdvar}, &def->${name})' + }, +} + + +@singleton +class TypeTable(OrderedDict): + def __init__(self): + OrderedDict.__init__(self) + for name, kvs in BUILTIN_TYPES.items(): + kvs['name'] =3D name + kvs['meta'] =3D 'Builtin' + self[name] =3D kvs + + def register(self, kvs): + name =3D kvs['name'] + if name not in self: + self[name] =3D kvs + return name + + def get(self, name): + if name in self: + return self[name] + return {'meta': 'Struct', 'name': name, 'external': True} + + def check(self, name): + return name in self + + +T_NAMESPACE_PARSE =3D [ + 'if (xmlopt)', + ' def->ns =3D xmlopt->ns;', + 'if (def->ns.parse) {', + ' if (virXMLNamespaceRegister(ctxt, &def->ns) < 0)', + ' goto error;', + ' if ((def->ns.parse)(ctxt, &def->namespaceData) < 0)', + ' goto error;', + '}' +] + +T_NAMESPACE_FORMAT_BEGIN =3D [ + 'if (def->namespaceData && def->ns.format)', + ' virXMLNamespaceFormatNS(buf, &def->ns);' +] + +T_NAMESPACE_FORMAT_END =3D [ + 'if (def->namespaceData && def->ns.format) {', + ' if ((def->ns.format)(buf, def->namespaceData) < 0)', + ' return -1;', + '}' +] + + +def funcSignature(rtype, name, args): + alignment =3D ' ' * (len(name) + 1) + connector =3D ',\n' + alignment + + ret =3D [] + ret.append(rtype) + ret.append('%s(%s)' % (name, connector.join(args))) + return Block(ret) + + +def counterName(member): + if isinstance(member['array'], bool): + return 'n' + member['name'] + return member['array'] + + +def loop(count, block): + assert isinstance(block, list) and len(block) > 0 + lp =3D ' {' if len(block) > 1 else '' + + ret =3D Block() + ret.format('if (${count} > 0) {', count=3Dcount) + ret.format(' size_t i;') + ret.format(' for (i =3D 0; i < ${count}; i++)${lp}', count=3Dcount,= lp=3Dlp) + ret.mapfmt(' ${_each_line_}', block) + ret.format(' }' if lp else None) + ret.format('}') + return ret + + +def ispointer(member): + mtype =3D TypeTable().get(member['type']) + return member['pointer'] and not mtype.get('external') + + +def clearMember(member, pre_name=3DNone): + + # Callback for make_switch + def _switch_clear_cb(child, switch, _): + return clearMember(child, switch['name']) + + if member.get('xmlswitch'): + return makeSwitch(member, _switch_clear_cb, None) + + mtype =3D TypeTable().get(member['type']) + + if pre_name: + ref =3D 'def->%s.%s' % (pre_name, member['name']) + else: + ref =3D 'def->%s' % member['name'] + + if member.get('array'): + ref +=3D '[i]' + + ret =3D Block() + if mtype['meta'] =3D=3D 'Struct': + if ispointer(member): + ret.format('${tname}Clear(${ref});', tname=3Dmtype['name'], re= f=3Dref) + ret.format('g_free(${ref});', ref=3Dref) + ret.format('${ref} =3D NULL;', ref=3Dref) + else: + ret.format('${tname}Clear(&${ref});', tname=3Dmtype['name'], r= ef=3Dref) + elif mtype['name'] =3D=3D 'String': + ret.format('g_free(${ref});', ref=3Dref) + ret.format('${ref} =3D NULL;', ref=3Dref) + elif mtype['name'] in ['Chars', 'UChars']: + ret.format('memset(${ref}, 0, sizeof(${ref}));', ref=3Dref) + elif not member.get('array'): + ret.format('${ref} =3D 0;', ref=3Dref) + + if member.get('specified'): + assert not member.get('array'), "'specified' can't come with 'arra= y'." + if isinstance(member['specified'], str): + ret.format('def->${sname} =3D false;', sname=3Dmember['specifi= ed']) + else: + ret.format('${ref}_specified =3D false;', ref=3Dref) + + if member.get('array') and len(ret) > 0: + count =3D 'def->' + counterName(member) + ret =3D loop(count, ret) + ret.format('g_free(def->${name});', name=3Dmember['name']) + ret.format('def->${name} =3D 0;', name=3Dmember['name']) + ret.format('${count} =3D 0;', count=3Dcount) + + return ret + + +def makeClearFunc(writer, atype): + if 'genparse' not in atype: + return + + args =3D ['%sPtr def' % atype['name']] + signature =3D funcSignature('void', atype['name'] + 'Clear', args) + writer.write(atype, 'clearfunc', '.h', signature.output() + ';') + + ret =3D Block() + ret.extend(signature) + ret.format('{') + ret.format(' if (!def)') + ret.format(' return;') + ret.newline() + + delay_members =3D [] + for member in atype['members']: + if member.get('delay_clear'): + delay_members.append(member) + continue + + ret.mapfmt(' ${_each_line_}', clearMember(member)) + ret.newline() + + for member in delay_members: + ret.mapfmt(' ${_each_line_}', clearMember(member)) + ret.newline() + + if 'namespace' in atype: + ret.format(' if (def->namespaceData && def->ns.free)') + ret.format(' (def->ns.free)(def->namespaceData);') + else: + ret.pop() # Remove last newline + + ret.format('}') + writer.write(atype, 'clearfunc', '.c', ret.output()) + + +def reportInvalid(tname, mdvar): + ret =3D Block() + ret.append('virReportError(VIR_ERR_XML_ERROR,') + ret.append(" _(\"Invalid '%s' setting '%s' in '%s'\"),") + ret.format(' "${tname}", ${mdvar}, instname);', + tname=3Dtname, mdvar=3Dmdvar) + return ret + + +def reportMissing(tname): + ret =3D Block() + ret.append('virReportError(VIR_ERR_XML_ERROR,') + ret.append(" _(\"Missing '%s' setting in '%s'\"),") + ret.format(' "${tname}", instname);', tname=3Dtname) + return ret + + +def checkError(kind, cond, tname, mdvar): + if kind =3D=3D 'Invalid': + report =3D reportInvalid(tname, mdvar) + elif kind =3D=3D 'Missing': + report =3D reportMissing(tname) + else: + assert False, '%s is unsupported.' % kind + + ret =3D Block() + ret.format('if (${cond}) {', cond=3Dcond) + ret.mapfmt(' ${_each_line_}', report) + ret.append(' goto error;') + ret.append('}') + return ret + + +def parseMember(member, parent, tmpvars, pre_name=3DNone): + mtype =3D TypeTable().get(member['type']) + + # + # Helper functions + # + def _middle_var(member): + ret =3D member['name'].replace('.', '_') + if member.get('xmlgroup'): + ret =3D 'node' + elif mtype['name'] =3D=3D 'String': + ret =3D 'def->' + ret + elif member.get('xmlattr') or mtype['meta'] !=3D 'Struct': + ret +=3D 'Str' + else: + ret +=3D 'Node' + return ret + + def _read_xml_func(mdvar, tname): + if member.get('xmlattr'): + if '/' in tname: + funcname =3D 'virXMLChildPropString' + else: + funcname =3D 'virXMLPropString' + elif member.get('xmlelem'): + if mtype['meta'] =3D=3D 'Struct': + funcname =3D 'virXMLChildNode' + else: + funcname =3D 'virXMLChildNodeContent' + else: + return None + + return render('${mdvar} =3D ${funcname}(node, "${tname}");', + mdvar=3Dmdvar, funcname=3Dfuncname, tname=3Dtname) + + def _assign_struct(name, member, mdvar): + ret =3D Block() + if ispointer(member): + ret.format('def->${name} =3D g_new0(typeof(*def->${name}), 1);= ', + name=3Dname) + + func =3D mtype['name'] + 'ParseXML' + amp =3D '' if ispointer(member) else '&' + tmpl =3D '${func}(${mdvar}, ${amp}def->${name}, instname, def, opa= que)' + fn =3D render(tmpl, func=3Dfunc, mdvar=3Dmdvar, amp=3Damp, name=3D= name) + return if_cond(fn + ' < 0', ['goto error;']) + + def _assign_non_struct(name, member, mdvar): + if mtype['meta'] =3D=3D 'Enum': + typename =3D mtype['name'] + if not typename.endswith('Type'): + typename +=3D 'Type' + expr =3D render('(def->${name} =3D ${typename}FromString(${mdv= ar}))', + name=3Dname, typename=3Dtypename, mdvar=3Dmdvar) + expr +=3D ' <=3D 0' + elif mtype['name'] =3D=3D 'Bool': + truevalue =3D member.get('truevalue', 'yes') + expr =3D render('virStrToBool(${mdvar}, "${truth}", &def->${na= me})', + mdvar=3Dmdvar, truth=3Dtruevalue, name=3Dname) + expr +=3D ' < 0' + else: + builtin =3D BUILTIN_TYPES.get(mtype['name']) + assert builtin, mtype['name'] + tmpl =3D builtin.get('conv', None) + if tmpl: + expr =3D render(tmpl, name=3Dname, mdvar=3Dmdvar, tname=3D= tname) + expr +=3D ' < 0' + else: + return None + + return checkError('Invalid', expr, tname, mdvar) + + def _parse_array(name, member, tname): + num =3D 'n%sNodes' % Terms.upperInitial(tname) + tmpvars.append(num) + tmpvars.append('nodes') + count =3D counterName(member) + + if mtype['meta'] =3D=3D 'Struct': + item =3D _assign_struct(name + '[i]', member, 'tnode') + else: + item =3D ['def->%s[i] =3D virXMLNodeContentString(tnode);' % n= ame] + + ret =3D Block() + ret.format('${num} =3D virXMLChildNodeSet(node, "${tname}", &nodes= );', + num=3Dnum, tname=3Dtname) + ret.format('if (${num} > 0) {', num=3Dnum) + ret.format(' size_t i;') + ret.newline() + ret.format(' def->${name} =3D g_new0(typeof(*def->${name}), ${n= um});', + name=3Dname, num=3Dnum) + ret.format(' for (i =3D 0; i < ${num}; i++) {', num=3Dnum) + ret.format(' xmlNodePtr tnode =3D nodes[i];') + ret.mapfmt(' ${_each_line_}', item) + ret.format(' }') + ret.format(' def->${count} =3D ${num};', count=3Dcount, num=3Dn= um) + ret.format(' g_free(nodes);') + ret.format(' nodes =3D NULL;') + ret.format('} else if (${num} < 0) {', num=3Dnum) + ret.format(' virReportError(VIR_ERR_XML_ERROR,') + ret.format(' _("Invalid %s element found."),') + ret.format(' "${tname}");', tname=3Dtname) + ret.format(' goto error;') + + if member.get('required'): + ret.append('} else {') + ret.mapfmt(' ${_each_line_}', reportMissing(tname)) + ret.append(' goto error;') + + ret.append('}') + return ret + + # + # Main routine + # + if not member.get('xmlattr') and not member.get('xmlelem') \ + and not member.get('xmlgroup'): + return None + + if pre_name: + name =3D pre_name + '.' + member['name'] + else: + name =3D member['name'] + + tname =3D None + if member.get('xmlattr'): + tname =3D member['xmlattr'] + elif member.get('xmlelem'): + tname =3D member['xmlelem'] + + # For array member + if member.get('array'): + return _parse_array(name, member, tname) + + # For common member + mdvar =3D _middle_var(member) + if mdvar.endswith('Str') or mdvar.endswith('Node'): + tmpvars.append(mdvar) + + block =3D Block() + if tname: + block.append(_read_xml_func(mdvar, tname)) + if member.get('required'): + cond =3D render('${mdvar} =3D=3D NULL', mdvar=3Dmdvar) + block.extend(checkError('Missing', cond, tname, mdvar)) + + if mtype['meta'] =3D=3D 'Struct': + assignment =3D _assign_struct(name, member, mdvar) + else: + assignment =3D _assign_non_struct(name, member, mdvar) + if not assignment: + return block + + if member.get('specified'): + if isinstance(member['specified'], str): + assignment.format('def->${name} =3D true;', name=3Dmember['spe= cified']) + else: + assignment.format('def->${name}_specified =3D true;', name=3Dn= ame) + + if tname: + block.extend(if_cond(mdvar, assignment)) + else: + block.extend(assignment) + + return block + + +def makeParseFunc(writer, atype): + + # + # Helper functions + # + def _switch_parse_cb(child, switch, tmpvars): + return parseMember(child, atype, tmpvars, switch['name']) + + def _members_block(tmpvars): + block =3D Block() + for member in atype['members']: + if member.get('xmlswitch'): + block.extend(makeSwitch(member, _switch_parse_cb, tmpvars)) + else: + block.extend(parseMember(member, atype, tmpvars)) + block.newline() + return block + + def _post_hook(tmpvars): + if atype['genparse'] not in ['withhook', 'concisehook']: + return None + + args =3D ['node', 'def', 'instname', 'parent', 'opaque'] + if 'namespace' in atype: + args.append('ctxt') + args.append('xmlopt') + + if atype['genparse'] =3D=3D 'withhook': + args.extend(tmpvars) + if 'nodes' in args: + args.remove('nodes') + + funcname =3D atype['name'] + 'ParseXMLHook' + cond =3D '%s(%s) < 0' % (funcname, ', '.join(args)) + return if_cond(cond, ['goto error;']) + + def _handle_tmpvars(tmpvars): + args, heads, tails =3D [], [], [] + for var in tmpvars: + if var =3D=3D 'nodes': + heads.append('xmlNodePtr *nodes =3D NULL;') + tails.append('g_free(nodes);') + tails.append('nodes =3D NULL;') + elif var.endswith('Str'): + heads.append('g_autofree char *%s =3D NULL;' % var) + args.append('const char *%s' % var) + elif var.endswith('Node'): + heads.append('xmlNodePtr %s =3D NULL;' % var) + args.append('xmlNodePtr %s' % var) + else: + assert var.endswith('Nodes') and var.startswith('n') + heads.append('int %s =3D 0;' % var) + args.append('int %s' % var) + + if atype['genparse'] !=3D 'withhook': + args =3D [] + + if heads: + heads.append('') + + heads.append('if (!def)') + heads.append(' goto error;') + tails.append('%sClear(def);' % atype['name']) + return args, heads, tails + + # + # Composite + # + if 'genparse' not in atype: + return + + typename =3D atype['name'] + funcname =3D typename + 'ParseXML' + + # Declare virXXXParseXML + args =3D Block([ + 'xmlNodePtr node', + '%sPtr def' % typename, + 'const char *instname', + 'void *parent', + 'void *opaque' + ]) + + if 'namespace' in atype: + args.append('xmlXPathContextPtr ctxt') + args.append('virNetworkXMLOptionPtr xmlopt') + + signature =3D funcSignature('int', funcname, args) + writer.write(atype, 'parsefunc', '.h', signature.output() + ';') + + # Prepare for implementation + tmpvars =3D [] + parseblock =3D _members_block(tmpvars) + tmpvars =3D dedup(tmpvars) + tmpargs, headlines, cleanup =3D _handle_tmpvars(tmpvars) + posthook =3D _post_hook(tmpvars) + + if atype['genparse'] in ['withhook', 'concisehook']: + # Declare virXXXParseXMLHook + signature =3D funcSignature('int', funcname + 'Hook', args + tmpar= gs) + writer.write(atype, 'parsefunc', '.h', signature.output() + ';') + else: + # Without hook, instname, parent and opaque are unused. + args[2] +=3D ' G_GNUC_UNUSED' + args[3] +=3D ' G_GNUC_UNUSED' + args[4] +=3D ' G_GNUC_UNUSED' + + # Implement virXXXParseXML + impl =3D funcSignature('int', funcname, args) + impl.format('{') + impl.mapfmt(' ${_each_line_}', headlines) + impl.newline() + impl.mapfmt(' ${_each_line_}', parseblock) + + if posthook: + impl.mapfmt(' ${_each_line_}', posthook) + impl.newline() + + if 'namespace' in atype: + impl.extend(' ${_each_line_}', T_NAMESPACE_PARSE) + + impl.format(' return 0;') + impl.newline() + impl.format(' error:') + impl.mapfmt(' ${_each_line_}', cleanup) + impl.format(' return -1;') + impl.format('}') + + writer.write(atype, 'parsefunc', '.c', impl.output()) + + +def if_cond(condition, block): + assert isinstance(block, list) and len(block) > 0 + lp =3D ' {' if len(block) > 1 else '' + + ret =3D Block() + ret.format('if (${condition})${lp}', condition=3Dcondition, lp=3Dlp) + ret.mapfmt(' ${_each_line_}', block) + ret.format('}' if lp else None) + return ret + + +def formatMember(member, parent): + mtype =3D TypeTable().get(member['type']) + + # + # Helper functions. + # + def _checkOnCondition(var): + ret =3D None + if ispointer(member): + ret =3D var + elif member.get('specified'): + if isinstance(member['specified'], str): + ret =3D 'def->' + member['specified'] + else: + ret =3D var + '_specified' + if ret.startswith('&'): + ret =3D ret[1:] + elif mtype['meta'] =3D=3D 'Struct': + ret =3D '%sCheck(&%s, def, opaque)' % (mtype['name'], var) + elif member.get('required'): + pass + elif mtype['meta'] =3D=3D 'Enum': + ret =3D var + elif mtype['meta'] =3D=3D 'Builtin': + if mtype['name'] in ['Chars', 'UChars']: + ret =3D var + '[0]' + else: + ret =3D var + + if 'formatflag' in member: + flag =3D member['formatflag'] + if flag =3D=3D '_ALWAYS_': + return None + + exclusive =3D False + reverse =3D False + if flag[0] =3D=3D '%': + flag =3D flag[1:] + exclusive =3D True + if flag[0] =3D=3D '!': + flag =3D flag[1:] + reverse =3D True + cond =3D '(virXMLFlag(opaque) & %s)' % flag + if reverse: + cond =3D '!' + cond + + if ret and not exclusive: + ret =3D ret + ' && ' + cond + else: + ret =3D cond + + return ret + + def _handleMore(code): + counter =3D 'def->' + counterName(member) + return loop(counter, code), counter + + def _format(layout, var): + if mtype['meta'] =3D=3D 'Struct': + if not ispointer(member): + var =3D '&' + var + + fname =3D mtype['name'] + 'FormatBuf' + cond =3D '%s(buf, "%s", %s, def, opaque) < 0' % (fname, layout= , var) + return if_cond(cond, ['return -1;']) + elif mtype['meta'] =3D=3D 'Enum': + name =3D mtype['name'] + if not name.endswith('Type'): + name +=3D 'Type' + + ret =3D Block() + ret.format('const char *str =3D ${name}ToString(${var});', + name=3Dname, var=3Dvar) + ret.format('if (!str) {') + ret.format(' virReportError(VIR_ERR_INTERNAL_ERROR,') + ret.format(' _("Unknown %s type %d"),') + ret.format(' "${tname}", ${var});', + tname=3Dmember['xmlattr'], var=3Dvar) + ret.format(' return -1;') + ret.format('}') + ret.format('virBufferAsprintf(buf, "${layout}", str);', + layout=3Dlayout) + return ret + elif mtype['name'] =3D=3D 'Bool': + truevalue =3D member.get('truevalue', 'yes') + if truevalue =3D=3D 'yes': + var =3D '%s ? "yes" : "no"' % var + elif truevalue =3D=3D 'on': + var =3D '%s ? "on" : "off"' % var + else: + var =3D '%s ? "%s" : ""' % (var, truevalue) + return ['virBufferEscapeString(buf, "%s", %s);' % (layout, var= )] + elif mtype['name'] =3D=3D 'String': + return ['virBufferEscapeString(buf, "%s", %s);' % (layout, var= )] + elif mtype['name'] =3D=3D 'Time': + return ['virTimeFormatBuf(buf, "%s", %s);' % (layout, var)] + else: + return ['virBufferAsprintf(buf, "%s", %s);' % (layout, var)] + + def _handleAttr(tagname, var): + if 'xmlattr' not in member: + return None + + fmt =3D '%s' + if mtype['meta'] =3D=3D 'Builtin': + fmt =3D BUILTIN_TYPES[mtype['name']].get('fmt', '%s') + + layout =3D " %s=3D'%s'" % (tagname, fmt) + return _format(layout, var) + + def _handleElem(tagname, var): + if 'xmlattr' in member: + return None + + if mtype['meta'] !=3D 'Struct': + layout =3D '<%s>%%s\\n' % (tagname, tagname) + else: + layout =3D tagname + + code =3D _format(layout, var) + return code + + # + # Main routine + # + name =3D member['name'] + if member.get('array'): + name =3D name + '[i]' + var =3D 'def->' + name + + ret =3D None + if 'xmlattr' in member: + tagname =3D member['xmlattr'] + ret =3D _handleAttr(tagname, var) + else: + tagname =3D member['xmlelem'] + ret =3D _handleElem(tagname, var) + + if not ret: + return None, None + + if member.get('array'): + return _handleMore(ret) + + checks =3D _checkOnCondition(var) + if checks: + ret =3D if_cond(checks, ret) + + if checks: + if '&&' in checks or '||' in checks: + checks =3D '(%s)' % checks + + return ret, checks + + +def makeSwitch(switch, callback, opaque=3DNone): + assert switch.get('xmlswitch', None) and switch.get('switch_type', Non= e) + + captype =3D Terms.allcaps(switch['switch_type']) + block =3D Block() + block.format('switch (def->${etype}) {', etype=3Dswitch['xmlswitch']) + block.newline() + for child in switch['members']: + value =3D captype + '_' + Terms.allcaps(child['name']) + block.format('case ${value}:', value=3Dvalue) + block.mapfmt(' ${_each_line_}', callback(child, switch, opaque)) + block.format(' break;') + block.newline() + block.format('case ${captype}_NONE:', captype=3Dcaptype) + block.format('case ${captype}_LAST:', captype=3Dcaptype) + block.format(' break;') + block.format('}') + return block + + +def makeFormatFunc(writer, atype): + if 'genformat' not in atype: + return + + # + # Helper functions and classes. + # + def _handleHeads(tmpvars, typename, kind=3D''): + tmpvars =3D dedup(tmpvars) + heads =3D Block() + if tmpvars: + heads.mapfmt( + 'g_auto(virBuffer) ${_each_line_} =3D VIR_BUFFER_INITIALIZ= ER;', + tmpvars + ) + heads.newline() + + heads.format('if (!def || !buf)') + heads.format(' return 0;') + + if tmpvars: + funcname =3D typename + 'Format' + kind + 'Hook' + + heads.newline() + args =3D Block(['def', 'parent', 'opaque']) + args.mapfmt('&${_each_line_}', tmpvars) + heads.format('if (%s(%s) < 0)' % (funcname, ', '.join(args))) + heads.format(' return -1;') + + args =3D Block([ + 'const %s *def' % typename, + 'const void *parent', + 'const void *opaque' + ]) + args.mapfmt('virBufferPtr ${_each_line_}', tmpvars) + signature =3D funcSignature('int', funcname, args) + writer.write(atype, 'formatfunc', '.h', signature.output() + '= ;') + + args =3D [ + 'const %s *def' % typename, + 'const void *parent', + 'void *opaque', + 'bool value' + ] + funcname =3D typename + 'Check' + kind + 'Hook' + signature =3D funcSignature('bool', funcname, args) + writer.write(atype, 'formatfunc', '.h', signature.output() + '= ;') + + return '\n'.join(heads) + + def _format_group(child, switch, kind): + kind =3D kind if kind else '' + prefix =3D (switch['name'] + '.') if switch else '' + mtype =3D TypeTable().get(child['type']) + funcname =3D '%sFormat%s' % (mtype['name'], kind) + var =3D 'def->%s%s' % (prefix, child['name']) + if not ispointer(child): + var =3D '&' + var + r_check =3D '%sCheck%s(%s, def, opaque)' % (mtype['name'], kind, v= ar) + cond =3D '%s(buf, %s, def, opaque) < 0' % (funcname, var) + return if_cond(cond, ['return -1;']), r_check + + def _switch_format_cb(child, switch, kind): + return _format_group(child, switch, kind)[0] + + def _handle_wrap_attr(member): + wrap, member['xmlattr'] =3D member['xmlattr'].split('/') + ret, check =3D formatMember(member, atype) + return ret, check, wrap + + def _switch_check_cb(child, switch, kind): + return ['ret =3D %s;' % _format_group(child, switch, kind)[1]] + + def _prepare_member(member, atype): + wrap, attr, attr_chk, elem, elem_chk =3D None, None, None, None, N= one + if member.get('xmlswitch'): + attr =3D makeSwitch(member, _switch_format_cb, 'Attr') + elem =3D makeSwitch(member, _switch_format_cb, 'Elem') + basename =3D atype['name'] + Terms.upperInitial(member['name']) + attr_chk =3D '%sCheckAttr(def, opaque)' % basename + elem_chk =3D '%sCheckElem(def, opaque)' % basename + + # Declare virXXXCheck[Attr|Elem] for switch. + for kind in ['Attr', 'Elem']: + args =3D ['const %s *def' % atype['name'], 'void *opaque'] + decl =3D funcSignature('bool', basename + 'Check' + kind, = args) + writer.write(atype, 'formatfunc', '.h', decl.output() + ';= ') + + # Implement virXXXCheck[Attr|Elem] for switch. + checks =3D makeSwitch(member, _switch_check_cb, kind) + + args[1] +=3D ' G_GNUC_UNUSED' + impl =3D funcSignature('bool', basename + 'Check' + kind, = args) + impl.format('{') + impl.format(' bool ret =3D false;') + impl.format(' if (!def)') + impl.format(' return false;') + impl.newline() + impl.mapfmt(' ${_each_line_}', checks) + impl.newline() + impl.format(' return ret;') + impl.format('}') + writer.write(atype, 'formatfunc', '.c', impl.output()) + + elif member.get('xmlattr'): + if '/' in member['xmlattr']: + attr, attr_chk, wrap =3D _handle_wrap_attr(member) + else: + attr, attr_chk =3D formatMember(member, atype) + elif member.get('xmlelem'): + elem, elem_chk =3D formatMember(member, atype) + elif member.get('xmlgroup'): + attr, attr_chk =3D _format_group(member, None, 'Attr') + elem, elem_chk =3D _format_group(member, None, 'Elem') + return wrap, attr, attr_chk, elem, elem_chk + + def _prepare_hook(member): + assert member.get('xmlattr') or member.get('xmlelem') + buf =3D member['name'] + 'Buf' + ret =3D if_cond('virBufferUse(&%s)' % buf, + ['virBufferAddBuffer(buf, &%s);' % buf]) + return ret, buf + + class _WrapItem: + def __init__(self): + self.attrs =3D Block() + self.checks =3D [] + self.optional =3D True + self.pos =3D 0 + + def _prepare(): + attrs =3D Block() + elems =3D Block() + attr_checks =3D [] + elem_checks =3D [] + attr_hook_vars =3D [] + elem_hook_vars =3D [] + attrs_optional =3D True + elems_optional =3D True + wraps =3D OrderedDict() + for member in atype['members']: + if member.get('formathook'): + block, hookvar =3D _prepare_hook(member) + if member.get('xmlattr'): + attrs.extend(block) + attrs.newline(block) + attr_hook_vars.append(hookvar) + elif member.get('xmlelem'): + elems.extend(block) + elems.newline(block) + elem_hook_vars.append(hookvar) + else: + assert False, 'formathook is only with [xmlattr|xmlele= m].' + else: + wrap, attr, attr_chk, elem, elem_chk =3D \ + _prepare_member(member, atype) + if wrap: + item =3D wraps.setdefault(wrap, _WrapItem()) + item.pos =3D len(elems) + item.attrs.extend(attr) + item.attrs.newline() + item.checks.append(attr_chk) + if member.get('required'): + item.optional =3D False + continue + + attrs.extend(attr) + attrs.newline(attr) + elems.extend(elem) + elems.newline(elem) + if attr_chk: + attr_checks.append(attr_chk) + if elem_chk: + elem_checks.append(elem_chk) + if member.get('required'): + attrs_optional =3D False + + while wraps: + wrap, item =3D wraps.popitem() + lines =3D Block() + lines.format('virBufferAddLit(buf, "<${name}");', name=3Dwrap) + lines.newline() + lines.extend(item.attrs) + lines.format('virBufferAddLit(buf, "/>\\n");') + if item.optional: + elem_checks.extend(item.checks) + lines =3D if_cond(' || '.join(item.checks), lines) + lines.newline() + else: + elems_optional =3D False + + for line in reversed(lines): + elems.insert(item.pos, line) + + attr_checks =3D dedup(attr_checks) + elem_checks =3D dedup(elem_checks) + return (attrs, attr_checks, attrs_optional, attr_hook_vars, + elems, elem_checks, elems_optional, elem_hook_vars) + + def _check_null(optional, checks, has_hook, kind=3D''): + if not optional: + return None + + # Declare virXXXCheck[Attr|Elem] + typename =3D atype['name'] + funcname =3D typename + 'Check' + kind + args =3D [ + 'const %s *def' % typename, + 'const void *parent', + 'void *opaque' + ] + signature =3D funcSignature('bool', funcname, args) + writer.write(atype, 'formatfunc', '.h', signature.output() + ';') + + # Implement virXXXFormat[Attr|Elem] + check =3D ' || '.join(checks) if optional else 'true' + if not check: + check =3D 'true' + + if has_hook: + check =3D '%sCheck%sHook(def, parent, opaque, %s)' \ + % (typename, kind, check) + + args[1] +=3D ' G_GNUC_UNUSED' + args[2] +=3D ' G_GNUC_UNUSED' + + impl =3D funcSignature('bool', funcname, args) + impl.format('{') + impl.format(' if (!def)') + impl.format(' return false;') + impl.newline() + impl.format(' return ${check};', check=3Dcheck) + impl.format('}') + writer.write(atype, 'formatfunc', '.c', impl.output()) + + return if_cond('!%s(def, parent, opaque)' % funcname, ['return 0;'= ]) + + def _compose_full(attrs, attr_checks, attrs_optional, attr_hook_vars, + elems, elem_checks, elems_optional, elem_hook_vars): + has_hook =3D (attr_hook_vars or elem_hook_vars) + typename =3D atype['name'] + + # Declare virXXXFormatBuf + args =3D [ + 'virBufferPtr buf', + 'const char *name', + 'const %s *def' % typename, + 'const void *parent', + 'void *opaque' + ] + signature =3D funcSignature('int', typename + 'FormatBuf', args) + writer.write(atype, 'formatfunc', '.h', signature.output() + ';') + + # Implement virXXXFormatBuf + headlines =3D _handleHeads(attr_hook_vars + elem_hook_vars, typena= me) + checknull =3D _check_null(attrs_optional and elems_optional, + attr_checks + elem_checks, has_hook) + + args[3] +=3D ' G_GNUC_UNUSED' + args[4] +=3D ' G_GNUC_UNUSED' + + impl =3D funcSignature('int', typename + 'FormatBuf', args) + impl.format('{') + impl.mapfmt(' ${_each_line_}', headlines.split('\n')) + impl.newline() + + if checknull: + impl.mapfmt(' ${_each_line_}', checknull) + impl.newline() + + impl.format(' virBufferAsprintf(buf, "<%s", name);') + impl.newline() + + if 'namespace' in atype: + impl.mapfmt(' ${_each_line}', T_NAMESPACE_FORMAT_BEGIN) + + impl.mapfmt(' ${_each_line_}', attrs) + + if elems: + if attrs and elems_optional: + impl.format(' if (!(${checks})) {', + checks=3D' || '.join(elem_checks)) + impl.format(' virBufferAddLit(buf, "/>\\n");') + impl.format(' return 0;') + impl.format(' }') + impl.newline() + + if 'namespace' in atype: + impl.mapfmt(' ${_each_line}', T_NAMESPACE_FORMAT_END) + + impl.format(' virBufferAddLit(buf, ">\\n");') + impl.newline() + impl.format(' virBufferAdjustIndent(buf, 2);') + impl.newline() + impl.mapfmt(' ${_each_line_}', elems) + impl.format(' virBufferAdjustIndent(buf, -2);') + impl.format(' virBufferAsprintf(buf, "\\n", name);') + else: + impl.format(' virBufferAddLit(buf, "/>\\n");') + + impl.newline() + impl.format(' return 0;') + impl.format('}') + writer.write(atype, 'formatfunc', '.c', impl.output()) + + def _compose_part(kind, block, checks, optional, hook_vars): + typename =3D atype['name'] + funcname =3D typename + 'Format' + kind + headlines =3D _handleHeads(hook_vars, atype['name'], kind) + if not block: + block =3D ['/* empty */', ''] + + checknull =3D _check_null(optional, checks, len(hook_vars), kind) + + # Declare virXXXFormat[Attr|Elem] + args =3D [ + 'virBufferPtr buf', + 'const %s *def' % typename, + 'const void *parent', + 'void *opaque' + ] + signature =3D funcSignature('int', funcname, args) + writer.write(atype, 'formatfunc', '.h', signature.output() + ';') + + # Implement virXXXFormat[Attr|Elem] + args[2] +=3D ' G_GNUC_UNUSED' + args[3] +=3D ' G_GNUC_UNUSED' + + impl =3D funcSignature('int', funcname, args) + impl.format('{') + impl.mapfmt(' ${_each_line_}', headlines.split('\n')) + impl.newline() + + if checknull: + impl.mapfmt(' ${_each_line_}', checknull) + impl.newline() + + impl.mapfmt(' ${_each_line_}', block) + impl.format(' return 0;') + impl.format('}') + writer.write(atype, 'formatfunc', '.c', impl.output()) + + # + # Main routine of formating. + # + (attrs, attr_checks, attrs_optional, attr_hook_vars, + elems, elem_checks, elems_optional, elem_hook_vars) =3D _prepare() + + if atype['genformat'] in ['separate', 'onlyattrs', 'onlyelems']: + if atype['genformat'] in ['separate', 'onlyattrs']: + _compose_part('Attr', attrs, attr_checks, + attrs_optional, attr_hook_vars) + + if atype['genformat'] in ['separate', 'onlyelems']: + _compose_part('Elem', elems, elem_checks, + elems_optional, elem_hook_vars) + else: + _compose_full(attrs, attr_checks, attrs_optional, attr_hook_vars, + elems, elem_checks, elems_optional, elem_hook_vars) + + +def showDirective(atype): + print('\n[Directive]\n') + print(json.dumps(atype, indent=3D4)) diff --git a/scripts/xmlgen/go b/scripts/xmlgen/go new file mode 100755 index 0000000..3821ce0 --- /dev/null +++ b/scripts/xmlgen/go @@ -0,0 +1,7 @@ +# This is a command-line tool + +export PYTHONDONTWRITEBYTECODE=3D1 +WORK_DIR=3D$(cd $(dirname $0); pwd) +SRCDIR=3D"${WORK_DIR}/../../src" +BUILDDIR=3D"${WORK_DIR}/../../build/src" +${WORK_DIR}/main.py -s ${SRCDIR} -b ${BUILDDIR} $@ diff --git a/scripts/xmlgen/main.py b/scripts/xmlgen/main.py new file mode 100755 index 0000000..5054640 --- /dev/null +++ b/scripts/xmlgen/main.py @@ -0,0 +1,439 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 Shandong Massclouds Co.,Ltd. +# +# 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 +# . +# + +import os +import re +import sys +import argparse +from clang.cindex import Index, CursorKind +from clang.cindex import SourceLocation, SourceRange, TokenKind +from datetime import datetime +from directive import TypeTable, showDirective +from directive import makeClearFunc, makeParseFunc, makeFormatFunc +from utils import Terms + +TOOL_DESC =3D ''' +Generate xml parse/format functions based on directives. + +Subcommand:\n + list: List types. By default, only list structs tagged by + 'genparse'/'genformat'. When the option '-a' is specified, + list all types discovered by this tool.\n + show: Show the target type's directives and its code for preview. + Specify target type by its name. The option '-k' indicates + the kinds of code for preview.\n + generate: Generate code. To be called by Makefile. + It needs option -k to filter output. + +Option:\n + -k: Specify kinds to filter code output. More than one kind can be + specified, 'c' for clearfunc; 'p' for parsefunc; + 'f' for formatfunc.\n + The option '-k' is only valid for show and generate. +''' + +# Three builtin types need to be handled specially: +# 'char *' =3D> String +# 'char XXXX[...]' =3D> Chars +# 'unsigned char XXXX[...]' =3D> UChars +BUILTIN_MAP =3D { + 'bool': 'Bool', + 'char': 'Char', + 'unsigned char': 'UChar', + 'int': 'Int', + 'unsigned int': 'UInt', + 'long': 'Long', + 'unsigned long': 'ULong', + 'long long': 'LongLong', + 'unsigned long long': 'ULongLong', + 'uint8_t': 'U8', + 'uint32_t': 'U32', + 'time_t': 'Time', +} + + +def getBuiltinType(ctype, ptr=3DFalse, size=3DNone): + if ctype =3D=3D 'char': + if ptr: + return 'String' + elif size: + return 'Chars' + + if ctype =3D=3D 'unsigned char' and size: + return 'UChars' + + return BUILTIN_MAP.get(ctype, None) + + +def cursorLineExtent(cursor, tu): + loc =3D cursor.location + start =3D SourceLocation.from_position(tu, loc.file, loc.line, 1) + end =3D SourceLocation.from_position(tu, loc.file, loc.line, -1) + return SourceRange.from_locations(start, end) + + +def getTokens(cursor, tu): + return tu.get_tokens(extent=3DcursorLineExtent(cursor, tu)) + + +DIRECTIVES =3D [ + 'genparse', 'genformat', 'namespace', 'xmlattr', 'xmlelem', 'xmlgroup', + 'required', 'array', 'specified', 'truevalue', 'formathook', 'xmlswitc= h', + 'formatflag' +] + + +def createDirectives(text): + tlist =3D re.findall(r'/\*(.*)\*/', text) + if len(tlist) !=3D 1: + return None + + tlist =3D tlist[0].split(',') + if len(tlist) =3D=3D 0: + return None + + directives =3D {} + for item in tlist: + item =3D item.strip() + if ':' in item: + key, value =3D item.split(':') + else: + key, value =3D item, None + + if key in DIRECTIVES: + directives[key] =3D value + return directives + + +def getDirectives(tokens, cursor): + for token in tokens: + if token.location.column <=3D cursor.location.column: + continue + if token.kind =3D=3D TokenKind.COMMENT: + directive =3D createDirectives(token.spelling) + if directive: + return directive + return None + + +def determinType(kvs, tokens, cursor): + prefix =3D [] + kind =3D None + for token in tokens: + if token.location.column >=3D cursor.location.column: + break + if not kind: + kind =3D token.kind + prefix.append(token.spelling) + + suffix =3D [] + for token in tokens: + if token.spelling =3D=3D ';': + break + suffix.append(token.spelling) + + size =3D None + if len(suffix) =3D=3D 3 and suffix[0] =3D=3D '[' and suffix[2] =3D=3D = ']': + size =3D suffix[1] + + assert kind in [TokenKind.IDENTIFIER, TokenKind.KEYWORD], \ + 'Bad field "%s" (%s).' % (cursor.spelling, kind) + + assert prefix + typename =3D ' '.join(prefix) + + # For array, remove the most-outer pointer + if kvs.get('array'): + if typename.endswith('Ptr'): + typename =3D typename[:-3] + elif typename.endswith('*'): + typename =3D typename[:-1].strip() + + ptr =3D False + if typename.endswith('Ptr'): + typename =3D typename[:-3] + ptr =3D True + elif prefix[-1] =3D=3D '*': + typename =3D typename[:-1].strip() + ptr =3D True + + ret =3D getBuiltinType(typename, ptr, size) + if ret: + typename =3D ret + + kvs.update({'type': typename, 'pointer': ptr}) + if size: + kvs['size'] =3D size + return kvs + + +def analyseMember(cursor, tu): + dvs =3D getDirectives(getTokens(cursor, tu), cursor) + if not dvs: + return None + + kvs =3D {'name': cursor.spelling} + kvs.update(dvs) + + # Formalize member + for key in ['array', 'required', 'specified', 'formathook']: + if key in kvs and not kvs[key]: + kvs[key] =3D True + + if 'formatflag' in kvs: + assert kvs.get('formatflag'), 'Directive "formatflag" is None' + + for tag in ['xmlattr', 'xmlelem', 'xmlgroup']: + if tag in kvs: + if not kvs[tag]: + if kvs.get('array'): + kvs[tag] =3D Terms.singularize(kvs['name']) + else: + kvs[tag] =3D kvs['name'] + + return determinType(kvs, getTokens(cursor, tu), cursor) + + +def findMember(struct, name): + for member in struct['members']: + if member['name'] =3D=3D name: + return member + + return None + + +def analyseStruct(struct, cursor, tu): + tokens =3D getTokens(cursor, tu) + kvs =3D getDirectives(tokens, cursor) + if kvs: + path, _ =3D os.path.splitext(cursor.location.file.name) + path, filename =3D os.path.split(path) + _, dirname =3D os.path.split(path) + kvs['output'] =3D dirname + '/' + filename + struct.update(kvs) + + last_kind =3D None + inner_members =3D [] + for child in cursor.get_children(): + if inner_members: + if last_kind =3D=3D CursorKind.STRUCT_DECL: + # Flatten the members of embedded struct + for member in inner_members: + member['name'] =3D child.spelling + '.' + member['= name'] + struct['members'].append(member) + else: + # Embedded union + union =3D getDirectives(getTokens(child, tu), child) + if union and 'xmlswitch' in union: + switch =3D findMember(struct, union['xmlswitch']) + switch['delay_clear'] =3D True + union['switch_type'] =3D switch['type'] + union['name'] =3D child.spelling + union['members'] =3D inner_members + struct['members'].append(union) + struct['xmlswitch'] =3D union['xmlswitch'] + + inner_members =3D [] + last_kind =3D None + continue + + if child.kind in [CursorKind.STRUCT_DECL, CursorKind.UNION_DEC= L]: + last_kind =3D child.kind + for ichild in child.get_children(): + member =3D analyseMember(ichild, tu) + if member: + inner_members.append(member) + continue + + member =3D analyseMember(child, tu) + if member: + struct['members'].append(member) + + return struct + + +def discoverStructures(tu): + for cursor in tu.cursor.get_children(): + if cursor.kind =3D=3D CursorKind.STRUCT_DECL and cursor.is_definit= ion(): + # Detect structs + name =3D cursor.spelling + if not name: + continue + if name.startswith('_'): + name =3D name[1:] + if TypeTable().check(name): + continue + struct =3D {'name': name, 'meta': 'Struct', 'members': []} + analyseStruct(struct, cursor, tu) + TypeTable().register(struct) + elif cursor.kind =3D=3D CursorKind.TYPEDEF_DECL: + # Detect enums + # We can't seek out enums by CursorKind.ENUM_DECL, + # since almost all enums are anonymous. + token =3D cursor.get_tokens() + try: + next(token) # skip 'typedef' + if next(token).spelling =3D=3D 'enum': + if not TypeTable().check(cursor.spelling): + enum =3D {'name': cursor.spelling, 'meta': 'Enum'} + TypeTable().register(enum) + except StopIteration: + pass + + +class CodeWriter(object): + def __init__(self, args): + self._builddir =3D args.builddir + self._cmd =3D args.cmd + self._files =3D {} + self._filters =3D {} + self._filters['clearfunc'] =3D args.kinds and 'c' in args.kinds + self._filters['parsefunc'] =3D args.kinds and 'p' in args.kinds + self._filters['formatfunc'] =3D args.kinds and 'f' in args.kinds + if args.cmd =3D=3D 'show': + self._filters['target'] =3D args.target + + def _getFile(self, path, ext): + assert ext in ['.h', '.c'] + _, basename =3D os.path.split(path) + path =3D '%s.generated%s' % (path, ext) + f =3D self._files.get(path) + if f is None: + f =3D open(path, 'w') + f.write('/* Generated by scripts/xmlgen */\n\n') + if ext in ['.c']: + f.write('#include \n') + f.write('#include "%s.h"\n' % basename) + f.write('#include "viralloc.h"\n') + f.write('#include "virerror.h"\n') + f.write('#include "virstring.h"\n\n') + f.write('#define VIR_FROM_THIS VIR_FROM_NONE\n') + else: + f.write('#pragma once\n\n') + f.write('#include "internal.h"\n') + f.write('#include "virxml.h"\n') + self._files[path] =3D f + return f + + def write(self, atype, kind, extname, content): + if not self._filters[kind]: + return + + if self._cmd =3D=3D 'show': + target =3D self._filters['target'] + if not target or target =3D=3D atype['name']: + if extname =3D=3D '.h': + print('\n[.h]') + else: + print('\n[.c]') + print('\n' + content) + return + + assert self._cmd =3D=3D 'generate' + + if atype.get('output'): + lfs =3D '\n' if extname =3D=3D '.h' else '\n\n' + path =3D self._builddir + '/' + atype['output'] + f =3D self._getFile(path, extname) + f.write(lfs + content + '\n') + + def complete(self): + for name in self._files: + self._files[name].close() + self._files.clear() + + +def getHFiles(path): + retlist =3D [] + for fname in os.listdir(path): + if fname.endswith('.h'): + retlist.append(os.path.join(path, fname)) + return retlist + + +HELP_LIST =3D 'list structs tagged by "genparse"/"genformat"' +HELP_LIST_ALL =3D 'list all discovered types' + +if __name__ =3D=3D "__main__": + parser =3D argparse.ArgumentParser( + formatter_class=3Dargparse.RawDescriptionHelpFormatter, + description=3DTOOL_DESC) + parser.add_argument('-s', dest=3D'srcdir') + parser.add_argument('-b', dest=3D'builddir') + subparsers =3D parser.add_subparsers(dest=3D'cmd') + parser_list =3D subparsers.add_parser('list', help=3DHELP_LIST) + parser_list.add_argument('-a', dest=3D'list_all', action=3D'store_true= ', + default=3DFalse, help=3DHELP_LIST_ALL) + parser_show =3D subparsers.add_parser('show', help=3D'show target code= ') + parser_show.add_argument('target', help=3D'target for being previewed') + parser_show.add_argument('-k', dest=3D'kinds', + help=3D'kinds of code to be previewed') + parser_generate =3D subparsers.add_parser('generate', help=3D'generate= code') + parser_generate.add_argument('-k', dest=3D'kinds', + help=3D'kinds of code to be generated') + args =3D parser.parse_args() + + if not args.cmd or not args.srcdir or not args.builddir: + parser.print_help() + sys.exit(1) + + if args.cmd =3D=3D 'generate': + print('###### xmlgen: start ... ######') + if not args.kinds: + print("[dry run]: no kinds specified for 'generate'") + + timestamp =3D datetime.now() + + # Examine all *.h in "$(srcdir)/[util|conf]" + index =3D Index.create() + srcdir =3D args.srcdir + hfiles =3D getHFiles(srcdir + '/util') + getHFiles(srcdir + '/conf') + for hfile in hfiles: + tu =3D index.parse(hfile) + discoverStructures(tu) # find all structs and enums + + if args.cmd =3D=3D 'list': + print('%-64s %s' % ('TYPENAME', 'META')) + for name, kvs in TypeTable().items(): + if not args.list_all: + if not ('genparse' in kvs or 'genparse' in kvs): + continue + print('%-64s %s' % (name, kvs['meta'])) + sys.exit(0) + elif args.cmd =3D=3D 'show': + assert args.target, args + atype =3D TypeTable().get(args.target) + if not atype: + sys.exit(0) + showDirective(atype) + + writer =3D CodeWriter(args) + + for atype in TypeTable().values(): + makeClearFunc(writer, atype) + makeParseFunc(writer, atype) + makeFormatFunc(writer, atype) + + writer.complete() + + if args.cmd =3D=3D 'generate': + elapse =3D (datetime.now() - timestamp).microseconds + print('\n###### xmlgen: elapse %d(us) ######\n' % elapse) + + sys.exit(0) diff --git a/scripts/xmlgen/utils.py b/scripts/xmlgen/utils.py new file mode 100644 index 0000000..4ac1f39 --- /dev/null +++ b/scripts/xmlgen/utils.py @@ -0,0 +1,121 @@ +# +# Copyright (C) 2020 Shandong Massclouds Co.,Ltd. +# +# 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 +# . +# + +from string import Template + + +def singleton(cls): + _instances =3D {} + + def inner(): + if cls not in _instances: + _instances[cls] =3D cls() + return _instances[cls] + return inner + + +class Terms(object): + abbrs =3D ['uuid', 'pci', 'zpci', 'ptr', 'mac', 'mtu', 'dns', 'ip', 'd= hcp'] + plurals =3D {'addresses': 'address'} + caps =3D {'NET_DEV': 'NETDEV', 'MACTABLE': 'MAC_TABLE'} + + @classmethod + def _split(cls, word): + ret =3D [] + if not word: + return ret + head =3D 0 + for pos in range(1, len(word)): + if word[pos].isupper() and not word[pos - 1].isupper(): + ret.append(word[head:pos]) + head =3D pos + ret.append(word[head:]) + return ret + + @classmethod + def singularize(cls, name): + ret =3D cls.plurals.get(name, None) + if ret: + return ret + assert name.endswith('s') + return name[:-1] + + # Don't use str.capitalize() which force other letters to be lowercase. + @classmethod + def upperInitial(cls, word): + if not word: + return '' + if word in cls.abbrs: + return word.upper() + if len(word) > 0 and word[0].isupper(): + return word + return word[0].upper() + word[1:] + + @classmethod + def allcaps(cls, word): + if len(word) =3D=3D 0: + return word + parts =3D cls._split(word) + ret =3D '_'.join([part.upper() for part in parts]) + for key, value in cls.caps.items(): + ret =3D ret.replace('_%s_' % key, '_%s_' % value) + return ret + + +def render(template, **kwargs): + return Template(template).substitute(kwargs) + + +class Block(list): + def format(self, template, **args): + if template: + self.append(Template(template).substitute(**args)) + + def extend(self, block): + if isinstance(block, list): + super(Block, self).extend(block) + + # ${_each_line_} is the only legal key for template + # and represents each line of the block. + def mapfmt(self, template, block): + if not block or not template: + return + + assert isinstance(block, list), block + for line in block: + if line: + self.append(Template(template).substitute(_each_line_=3Dli= ne)) + else: + self.append('') + + def newline(self, condition=3DTrue): + if condition: + super(Block, self).append('') + + def output(self, connector=3D'\n'): + return connector.join(self) + + +def dedup(alist): + assert isinstance(alist, list) + ret =3D [] + for e in alist: + if e not in ret: + ret.append(e) + + return ret --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190963; cv=none; d=zohomail.com; s=zohoarc; b=DlRpYjXa37GnjpYR6RjJWB16l9PK5/BvcKHKOKvTPDnxD6elQDN7ANVFauQ3Dy3m4ovPcoNg+tqhnqGAMr27KULoQeRs7l4ZtHUrSmbRz9vRLiSTqIDxYQkhw76EjV6hN05JpV+nHPLT3LdWu7kVetWBehKJ+tbnN8TFKlgVCnQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190963; 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=QIkQtC+h83OXf6ruyjQY+HzAbpFB86TcbxQSinSUHGY=; b=nr0wPfLAp+DivilMhSX+NbRLyikosM7P8CaRpSN8ePYM6n0kd/R7w+krj8X7DDu6udsH3qTJd8dQMqYtuBotCeb8b/Ob8Ok688UOzvGhNBxQxiqNd2uzb2OqX+5m79EDGnfRfqgWeZChP6mRKaGSWU0IoSZQhHb3qEGxjIt5ib8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190963851247.6470952194236; Thu, 3 Sep 2020 20:42:43 -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-68-eEznUAuYP3GRzd0ygpTCGw-1; Thu, 03 Sep 2020 23:42:40 -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 0363B100670B; Fri, 4 Sep 2020 03:42:35 +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 D28F01002D60; Fri, 4 Sep 2020 03:42:34 +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 A005C1826D34; Fri, 4 Sep 2020 03:42:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAtT030588 for ; Thu, 3 Sep 2020 23:41:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3B0C200AF71; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBC9C2018033 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 B2C1F8F5E3F for ; Fri, 4 Sep 2020 03:41:07 +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-324-caFsLveRMcWbfIi0_s1mbg-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S4; Fri, 04 Sep 2020 11:35:48 +0800 (CST) X-MC-Unique: eEznUAuYP3GRzd0ygpTCGw-1 X-MC-Unique: caFsLveRMcWbfIi0_s1mbg-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 02/46] maint: Check python3-clang Date: Fri, 4 Sep 2020 11:34:54 +0800 Message-Id: <20200904033538.418579-3-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--.1426S4 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTR3EfYDUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbicQ6VT1lZvYiFAwAAsW 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.4 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.001 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make sure python3-clang has been installed. Signed-off-by: Shi Lei --- meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/meson.build b/meson.build index 1eadea3..f97a03b 100644 --- a/meson.build +++ b/meson.build @@ -2504,3 +2504,8 @@ if conf.has('WITH_QEMU') } summary(priv_summary, section: 'Privileges') endif + +py3_clang =3D run_command('python3', '-c', 'import clang.cindex;print("ok"= )') +if py3_clang.returncode() !=3D 0 + error('python3-clang is required.') +endif --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190941; cv=none; d=zohomail.com; s=zohoarc; b=dhCGI5iCjijC71wIRhvEWBLyzLfy9wpOvaSQI/127MK21sycpqTKfVuVUbVCvnxcFC5kXTRT/WbrxDnCFnXIaZxtj2NkmeuqFYieY2ygczu7PxUmJYIZXofHMzAh+Fzk2Bkzvx0S82skTBR1DctfdhujWvFNRTjYoLUw84vfmHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190941; 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=mcRLtnRAPf3KrhS/HXuPyfhEN255bssPKtZ6dqYQBDY=; b=UjKGdT9emmO3llv+tm/LO64rk7oTtpkXLBSVw7B8l9YJNnq6uK+LcF1V+358bnaFTNBry5fOyZ8vWDOmSf2mZlYyGIr/w23uF78ztz7Fgn0Kl5FSE6eWIraTVNvRl4asygRMTWg6Tzwex94M3ZLq5wvEwwdHfVQyJGs11Df9sEY= 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 159919094149923.177219738037593; Thu, 3 Sep 2020 20:42:21 -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-568-LsLDuosXNXOJog2eMrlBZg-1; Thu, 03 Sep 2020 23:42:02 -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 4A09688CE5B; Fri, 4 Sep 2020 03:41:52 +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 2730E6198B; Fri, 4 Sep 2020 03:41:52 +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 E9BFE972F3; Fri, 4 Sep 2020 03:41:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBK7030663 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 34EFD1037A8; Fri, 4 Sep 2020 03:41:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30B341037A0 for ; Fri, 4 Sep 2020 03:41:11 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 18476101A53F for ; Fri, 4 Sep 2020 03:41:11 +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-275-yDMm9QJMMM61SmjVtVgZ1Q-1; Thu, 03 Sep 2020 23:41:08 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S5; Fri, 04 Sep 2020 11:35:48 +0800 (CST) X-MC-Unique: LsLDuosXNXOJog2eMrlBZg-1 X-MC-Unique: yDMm9QJMMM61SmjVtVgZ1Q-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 03/46] maint: Call xmlgen automatically when c-head-files change Date: Fri, 4 Sep 2020 11:34:55 +0800 Message-Id: <20200904033538.418579-4-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--.1426S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw43Aw1Utr4DCry5XFWxtFb_yoW5Zw1kpa 1qqw15tFyUXr1fJrs3JF18XF4rGw1kG3W7tw43Ww13ZwsxXr10v3yakFyrKr47W3y0vF4F 9Fs5Ga4Fkr48JFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMq2NLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiUBSVT1f4qIyqaAAAsX 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.79 on 10.11.54.5 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.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei --- scripts/meson.build | 8 ++++++++ src/conf/meson.build | 39 +++++++++++++++++++++++++++++++++++++++ src/meson.build | 6 ++++++ tests/meson.build | 1 + tools/meson.build | 2 ++ 5 files changed, 56 insertions(+) diff --git a/scripts/meson.build b/scripts/meson.build index 59b3c9b..dad82a9 100644 --- a/scripts/meson.build +++ b/scripts/meson.build @@ -37,3 +37,11 @@ foreach name : scripts sname =3D name.split('.')[0].underscorify() set_variable('@0@_prog'.format(sname), find_program(name)) endforeach + +xmlgen_self =3D files( + 'xmlgen/main.py', + 'xmlgen/directive.py', + 'xmlgen/utils.py' +) + +set_variable('virxmlgen_prog', find_program('xmlgen/main.py')) diff --git a/src/conf/meson.build b/src/conf/meson.build index 03b90aa..d82bffc 100644 --- a/src/conf/meson.build +++ b/src/conf/meson.build @@ -1,3 +1,39 @@ +xmlgen_input =3D [ +] + +xmlgen_output =3D [] +foreach name : xmlgen_input + xmlgen_output +=3D '@0@.generated.c'.format(name.split('.')[0]) + xmlgen_output +=3D '@0@.generated.h'.format(name.split('.')[0]) +endforeach + +xmlgen_headers =3D [] +if xmlgen_output.length() > 0 + xmlgen_objects =3D custom_target( + 'virxmlgen', + input: xmlgen_self + xmlgen_input, + output: xmlgen_output, + command: [ + meson_python_prog, python3_prog.path(), '-B', virxmlgen_prog.path(), + '-s', meson.source_root() / 'src', + '-b', meson.build_root() / 'src', + 'generate', '-k', 'cpf', + ], + ) + + index =3D 0 + foreach header : xmlgen_objects.to_list() + if index % 2 =3D=3D 1 + xmlgen_headers +=3D header + endif + index +=3D 1 + endforeach +else + xmlgen_objects =3D [] +endif + +xmlgen_dep =3D declare_dependency(sources: xmlgen_headers) + netdev_conf_sources =3D [ 'netdev_bandwidth_conf.c', 'netdev_vlan_conf.c', @@ -87,6 +123,7 @@ device_conf_sources =3D [ virt_conf_lib =3D static_library( 'virt_conf', [ + xmlgen_objects, chrdev_conf_sources, cpu_conf_sources, device_conf_sources, @@ -108,3 +145,5 @@ virt_conf_lib =3D static_library( libvirt_libs +=3D virt_conf_lib =20 conf_inc_dir =3D include_directories('.') + +subdir_done() diff --git a/src/meson.build b/src/meson.build index 897b5ec..2362897 100644 --- a/src/meson.build +++ b/src/meson.build @@ -247,6 +247,12 @@ src_dep =3D declare_dependency( ) =20 subdir('conf') + +src_dep =3D declare_dependency( + dependencies: [ src_dep, xmlgen_dep ], + include_directories: [ conf_inc_dir ], +) + subdir('rpc') subdir('access') subdir('cpu') diff --git a/tests/meson.build b/tests/meson.build index ad13e2d..c23910b 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -17,6 +17,7 @@ tests_dep =3D declare_dependency( selinux_dep, xdr_dep, yajl_dep, + xmlgen_dep, ], include_directories: [ conf_inc_dir, diff --git a/tools/meson.build b/tools/meson.build index b8c6802..788eed0 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -5,11 +5,13 @@ tools_dep =3D declare_dependency( dependencies: [ libxml_dep, glib_dep, + xmlgen_dep, ], include_directories: [ libvirt_inc, src_inc_dir, util_inc_dir, + conf_inc_dir, top_inc_dir, ], link_args: ( --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190929; cv=none; d=zohomail.com; s=zohoarc; b=gVDTmrj/UjWE1dsRrkCqaJRwvH1nBOcRQe5byqKCf5WmsDznMTHHqUoH+lLr2KWQxWmHCrpKPmBj8DMcWIEY2ZYjTyCDuZMQ903IblMybEXiC2PBMEtBuk36hs9L2I9ixH060iUOQB7YMzgpxKtB0AOLQESG1AsQptSmTA3NqYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190929; 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=U4JxVLrjVgyIj0vhl3g1DLzmiHhMUKmSgxiL8q60vhk=; b=OfFEkZ2YcwnS0dzXPgtl90l3iJA7YOZX2yc7jT/9+Dz66n+ZtWEe7ZHpui0FEbbgF9Fqw2J+et01Igfu6Qm7Lw4/qDflEKQ7XbqpMo4hx/uYzEOmJ3huPrlWe4VvyB0qgjGjfN1GngRRAp4NWAYjzdSKL+zApALgapflLdgoYnQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190929710879.3277780059807; Thu, 3 Sep 2020 20:42:09 -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-210-j11aBe1lM0-ZZVWNP4Iwlw-1; Thu, 03 Sep 2020 23:42:05 -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 6FBD81084C9F; Fri, 4 Sep 2020 03:41:54 +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 4B8991002391; Fri, 4 Sep 2020 03:41:54 +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 17B58181A2E6; Fri, 4 Sep 2020 03:41:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAYH030574 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id A85A3117DB01; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FC6C117A976 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 395E3101A569 for ; Fri, 4 Sep 2020 03:41:08 +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-56-0OncxFzeMVKKblLJjzCc-Q-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S6; Fri, 04 Sep 2020 11:35:48 +0800 (CST) X-MC-Unique: j11aBe1lM0-ZZVWNP4Iwlw-1 X-MC-Unique: 0OncxFzeMVKKblLJjzCc-Q-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 04/46] util: Add some xml-helper-functions to cooperate with xmlgen Date: Fri, 4 Sep 2020 11:34:56 +0800 Message-Id: <20200904033538.418579-5-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--.1426S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxJFykXw1furWrCw1UtryUAwb_yoWrZFWUpF Z8tr95trn5J34fCrsa9r1xWrs8Zr4SqrW3Ww1furyDArWfXw45Jr4fAFyYgw18ArW8Wr1j qa1YgF15uF48KFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbihQWVT1sfnZ2FpQAAs+ 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.3 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.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 1) virXMLChildNode and virXMLChildNodeSet Parse xml without using xmlXPathContext. 2) virXMLChildPropString Support to parse attribute by path. 3) virXMLFlag Convert opaque to flag. Signed-off-by: Shi Lei --- src/libvirt_private.syms | 4 ++ src/util/virxml.c | 105 +++++++++++++++++++++++++++++++++++++++ src/util/virxml.h | 6 +++ 3 files changed, 115 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5736a2d..191eab0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3505,7 +3505,11 @@ virVsockSetGuestCid; virParseScaledValue; virXMLCheckIllegalChars; virXMLChildElementCount; +virXMLChildNode; +virXMLChildNodeSet; +virXMLChildPropString; virXMLExtractNamespaceXML; +virXMLFlag; virXMLFormatElement; virXMLNodeContentString; virXMLNodeNameEqual; diff --git a/src/util/virxml.c b/src/util/virxml.c index 5315d4f..a7d9a2c 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1481,3 +1481,108 @@ virParseScaledValue(const char *xpath, *val =3D bytes; return 1; } + + +/** + * virXMLChildNode: + * @node: Parent XML dom node pointer + * @name: Name of the child element + * + * Convenience function to return the child element of a XML node. + * + * Returns the pointer of child element node or NULL in case of failure. + * If there are many nodes match condition, it only returns the first node. + */ +xmlNodePtr +virXMLChildNode(xmlNodePtr node, const char *name) +{ + xmlNodePtr cur =3D node->children; + while (cur) { + if (cur->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, = name)) + return cur; + cur =3D cur->next; + } + return NULL; +} + + +/** + * virXMLChildPropString: + * @node: Parent XML dom node pointer + * @path: Path of the property (attribute) to get + * + * Convenience function to return copy of an attribute value by a path. + * Path consists of names of child elements and an attribute. + * The delimiter is '/'. + * + * E.g.: For , + * the path is 'son/grandSon/name' to get attribute 'name'. + * + * Returns the property (attribute) value as string or NULL in case of fai= lure. + * The caller is responsible for freeing the returned buffer. + */ +char * +virXMLChildPropString(xmlNodePtr node, const char *path) +{ + char *next; + char *sep; + xmlNodePtr tnode =3D node; + g_autofree char *tmp =3D NULL; + tmp =3D g_strdup(path); + + next =3D tmp; + while ((sep =3D strchr(next, '/'))) { + *sep =3D '\0'; + + if ((tnode =3D virXMLChildNode(tnode, next)) =3D=3D NULL) + return NULL; + + next =3D sep + 1; + } + + return virXMLPropString(tnode, next); +} + + +/** + * virXMLChildNodeSet: + * @node: Parent XML dom node pointer + * @name: Name of the children element + * @list: the returned list of nodes (or NULL if only count matters) + * + * Convenience function to evaluate a set of children elements + * + * Returns the number of nodes found in which case @list is set (and + * must be freed) or -1 if the evaluation failed. + */ +int +virXMLChildNodeSet(xmlNodePtr node, const char *name, xmlNodePtr **list) +{ + size_t count =3D 0; + xmlNodePtr cur =3D node->children; + + if (list !=3D NULL) + *list =3D NULL; + + while (cur) { + if (cur->type =3D=3D XML_ELEMENT_NODE && virXMLNodeNameEqual(cur, = name)) { + if (list !=3D NULL) { + if (VIR_APPEND_ELEMENT_COPY(*list, count, cur) < 0) + return -1; + } else { + count++; + } + } + cur =3D cur->next; + } + return count; +} + + +unsigned int +virXMLFlag(void *opaque) +{ + if (opaque) + return *((unsigned int *) opaque); + return 0; +} diff --git a/src/util/virxml.h b/src/util/virxml.h index 0301f15..85e8eed 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -79,6 +79,10 @@ char * virXMLPropStringLimit(xmlNodePtr node, char * virXMLNodeContentString(xmlNodePtr node); long virXMLChildElementCount(xmlNodePtr node); =20 +xmlNodePtr virXMLChildNode(xmlNodePtr node, const char *name); +int virXMLChildNodeSet(xmlNodePtr node, const char *name, xmlNodePtr **lis= t); +char * virXMLChildPropString(xmlNodePtr node, const char *path); + /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, const char *filename, @@ -279,3 +283,5 @@ int virParseScaledValue(const char *xpath, unsigned long long scale, unsigned long long max, bool required); + +unsigned int virXMLFlag(void *opaque); --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190946; cv=none; d=zohomail.com; s=zohoarc; b=S3iibnCyczN+a5UGOraaRJsGaFIviOFGfzC/AjCgRdF8/88qnY6qRzyWIuvOlJcgN4y/ogAvkki3wKrVCr8oAwMwR8MH1qYBb/XuSVaRpWOBEowx6XVBjIEEX9M/0PBNNnIZuq/X20n/pdDRGlOq2VyI7aATwKxy8oNlXLmw0rA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190946; 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=R9QmBNrVFCH/+UDB2qhdTuGz76t1fWxzKALt0ayWhhM=; b=gvTDdlowyVhDE68r2bvVDwaHvRgkoMgdvvoMJLZlMcstqfVijOK62TMSoFP09qlJiXzxXfMf/WnTZO/J7bLv921xInq/Q6B6qqaxT4OyQ0XSQ2FfIK56O/tn7t6EJ9O/0tFCXUeYetFZ15mhF16sLMbjb+ozVEn20gZiiSp+EEo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190946871758.959415474275; Thu, 3 Sep 2020 20:42:26 -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-139-IOY-o7pdNj6GDbO7MsElDQ-1; Thu, 03 Sep 2020 23:42:23 -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 C50EA100670C; Fri, 4 Sep 2020 03:42:15 +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 A0DE81001B2B; Fri, 4 Sep 2020 03:42: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 7004097309; Fri, 4 Sep 2020 03:42:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBAw030655 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id CB4E9202348A; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C07D2201EB53 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 2EBE9101A568 for ; Fri, 4 Sep 2020 03:41:08 +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-347-aMqHAvZhNYGMBHttNycUGA-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S7; Fri, 04 Sep 2020 11:35:48 +0800 (CST) X-MC-Unique: IOY-o7pdNj6GDbO7MsElDQ-1 X-MC-Unique: aMqHAvZhNYGMBHttNycUGA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 05/46] util: Add helper functions for 'bool' and 'time_t' and cooperate with xmlgen Date: Fri, 4 Sep 2020 11:34:57 +0800 Message-Id: <20200904033538.418579-6-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--.1426S7 X-Coremail-Antispam: 1Uf129KBjvJXoWxWw4fCw43uF4DtF4xGF4UJwb_yoW5ZFWUp3 97uFsxZrnYqwn3G3sFgF1kGr13Zr4FqrW3Xrsxuwn5GF4xAF1jyrn3JF9093y5WFZ7Gr4a yr95WryrCF98Jw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRoGQkUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiGxSVT1pchmm9CgAAsL 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.4 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.002 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei --- src/libvirt_private.syms | 3 +++ src/util/virstring.c | 57 ++++++++++++++++++++++++++++++++++++++++ src/util/virstring.h | 9 +++++++ 3 files changed, 69 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 191eab0..4ad9d1e 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3242,6 +3242,7 @@ virStringStripSuffix; virStringToUpper; virStringTrimOptionalNewline; virStrncpy; +virStrToBool; virStrToDouble; virStrToLong_i; virStrToLong_l; @@ -3252,6 +3253,8 @@ virStrToLong_ul; virStrToLong_ull; virStrToLong_ullp; virStrToLong_ulp; +virStrToTime; +virTimeFormatBuf; virTrimSpaces; =20 =20 diff --git a/src/util/virstring.c b/src/util/virstring.c index de2ef96..23ade40 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1349,3 +1349,60 @@ int virStringParseYesNo(const char *str, bool *resul= t) =20 return 0; } + + +int +virStrToBool(const char *str, const char *truevalue, bool *result) +{ + if (STREQ(str, truevalue)) + *result =3D true; + else + *result =3D false; + + return 0; +} + + +int virStrToTime(const char *str, time_t *result) +{ + g_autoptr(GDateTime) then =3D NULL; + g_autoptr(GTimeZone) tz =3D g_time_zone_new_utc(); + char *tmp; + int year, mon, mday, hour, min, sec; + + /* Expect: YYYY-MM-DDTHH:MM:SS (%d-%d-%dT%d:%d:%d) eg 2010-11-28T14:2= 9:01 */ + if (/* year */ + virStrToLong_i(str, &tmp, 10, &year) < 0 || *tmp !=3D '-' || + /* month */ + virStrToLong_i(tmp+1, &tmp, 10, &mon) < 0 || *tmp !=3D '-' || + /* day */ + virStrToLong_i(tmp+1, &tmp, 10, &mday) < 0 || *tmp !=3D 'T' || + /* hour */ + virStrToLong_i(tmp+1, &tmp, 10, &hour) < 0 || *tmp !=3D ':' || + /* minute */ + virStrToLong_i(tmp+1, &tmp, 10, &min) < 0 || *tmp !=3D ':' || + /* second */ + virStrToLong_i(tmp+1, &tmp, 10, &sec) < 0 || *tmp !=3D '\0') { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid time '%s', expect YYYY-MM-DDTHH:MM:SS"), + str); + return -1; + } + + then =3D g_date_time_new(tz, year, mon, mday, hour, min, sec); + *result =3D (time_t)g_date_time_to_unix(then); + return 0; +} + + +int +virTimeFormatBuf(virBufferPtr buf, const char *layout, const time_t time) +{ + g_autoptr(GDateTime) then =3D NULL; + g_autofree char *thenstr =3D NULL; + + then =3D g_date_time_new_from_unix_utc(time); + thenstr =3D g_date_time_format(then, "%Y-%m-%dT%H:%M:%S"); + virBufferAsprintf(buf, layout, thenstr); + return 0; +} diff --git a/src/util/virstring.h b/src/util/virstring.h index 561ce0c..658b575 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -19,6 +19,7 @@ #pragma once =20 #include "internal.h" +#include "virbuffer.h" =20 #define VIR_INT64_STR_BUFLEN 21 =20 @@ -179,6 +180,14 @@ int virStringParsePort(const char *str, int virStringParseYesNo(const char *str, bool *result) G_GNUC_WARN_UNUSED_RESULT; + +int virStrToBool(const char *str, const char *truevalue, bool *result); + +int virStrToTime(const char *str, time_t *result) + G_GNUC_WARN_UNUSED_RESULT; + +int virTimeFormatBuf(virBufferPtr buf, const char *layout, const time_t ti= me); + /** * VIR_AUTOSTRINGLIST: * --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190983; cv=none; d=zohomail.com; s=zohoarc; b=huWKACacqn8ptj+17wcdHq+O/XpC4lV4AZaN6m5wYiyLXGgz76FWXVZBJ9ye62HuByBpQ17E+R5eOdhw78Pej+IgpvxYUIgdM1T8zebQPeji0wj2hvqiHLIt8dVSBnNP+fuJ51V12TJkKY5zT6T1rGovdi5l+Jtq8NpZIMo2BLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190983; 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=dcttrjYHd0oQgyiIrujVj8p8waQekFhQphwnj+pw5YA=; b=YrV2lDtXFR+Q+SCNbiOxas3vIkD8GJnficbe4bfOwjQZGPcSLNV2aUG5+C3MnvLcGm+9WNNOS5d7qayc0k9DWlqfChHG12pjeSQr27cNFu+E803AIexLloHvH3Fe2gDgkN6DgtZQupYAnp2m1gxNBjJ0RGpQbxUteFTG9TBvjQg= 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 1599190983108236.95683992420902; Thu, 3 Sep 2020 20:43:03 -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-240-a3gsrfM-MVCfYX54jphWBQ-1; Thu, 03 Sep 2020 23:42:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A30A807344; Fri, 4 Sep 2020 03:42:20 +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 56B995C269; Fri, 4 Sep 2020 03:42:20 +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 23FC41826D30; Fri, 4 Sep 2020 03:42:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBFN030654 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 338431037A6; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F67CEE873 for ; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 16BAA811E79 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-1-soZ8Qcj8PKS3kUgIPItADg-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--.1426S8; Fri, 04 Sep 2020 11:35:48 +0800 (CST) X-MC-Unique: a3gsrfM-MVCfYX54jphWBQ-1 X-MC-Unique: soZ8Qcj8PKS3kUgIPItADg-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 06/46] util: Add parsexml/formatbuf helper functions for virSocketAddr Date: Fri, 4 Sep 2020 11:34:58 +0800 Message-Id: <20200904033538.418579-7-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--.1426S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxAw43Jw4xKryUuFyxtF47urg_yoWruw1xpF 15tr15XrW8tws3Zw4Iqr4Y9r1ftF18XayUXa47uw10qrs8J3W3t3ZFqFy3Gr1rJFWjyF1U XFn0krWkCF4UAaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMSoJLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiAxWVT1ill1IGlgAAsk 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.79 on 10.11.54.5 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.16 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" Implement the parsexml/formatbuf functions for virSocketAddr. Signed-off-by: Shi Lei --- src/libvirt_private.syms | 2 ++ src/util/virsocketaddr.c | 42 ++++++++++++++++++++++++++++++++++++++++ src/util/virsocketaddr.h | 26 +++++++++++++++++++++---- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4ad9d1e..6b5c664 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3074,6 +3074,7 @@ virSocketAddrBroadcastByPrefix; virSocketAddrCheckNetmask; virSocketAddrEqual; virSocketAddrFormat; +virSocketAddrFormatBuf; virSocketAddrFormatFull; virSocketAddrGetIPPrefix; virSocketAddrGetNumNetmaskBits; @@ -3091,6 +3092,7 @@ virSocketAddrParse; virSocketAddrParseAny; virSocketAddrParseIPv4; virSocketAddrParseIPv6; +virSocketAddrParseXML; virSocketAddrPrefixToNetmask; virSocketAddrPTRDomain; virSocketAddrResolveService; diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index e0eb76d..bbb3a81 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -157,6 +157,15 @@ int virSocketAddrParse(virSocketAddrPtr addr, const ch= ar *val, int family) return len; } =20 +int virSocketAddrParseXML(const char *val, + virSocketAddrPtr addr, + const char *instname G_GNUC_UNUSED, + void *parent G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + return virSocketAddrParse(addr, val, AF_UNSPEC); +} + /** * virSocketAddrParseAny: * @addr: where to store the return value, optional. @@ -1307,3 +1316,36 @@ virSocketAddrFree(virSocketAddrPtr addr) { VIR_FREE(addr); } + +void +virSocketAddrClear(virSocketAddrPtr addr) +{ + memset(addr, 0, sizeof(virSocketAddr)); +} + +int +virSocketAddrFormatBuf(virBufferPtr buf, + const char *fmt, + const virSocketAddr *addr, + const void *parent G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + g_autofree char *str =3D NULL; + if (!VIR_SOCKET_ADDR_VALID(addr)) + return 0; + + str =3D virSocketAddrFormatFull(addr, false, NULL); + if (!str) + return -1; + + virBufferAsprintf(buf, fmt, str); + return 0; +} + +bool +virSocketAddrCheck(const virSocketAddr *addr, + const void *parent G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + return VIR_SOCKET_ADDR_VALID(addr); +} diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index 6c08f8b..fa51d5c 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -18,11 +18,14 @@ =20 #pragma once =20 +#include "virbuffer.h" #include "virsocket.h" =20 #define VIR_LOOPBACK_IPV4_ADDR "127.0.0.1" =20 -typedef struct { +typedef struct _virSocketAddr virSocketAddr; +typedef virSocketAddr *virSocketAddrPtr; +struct _virSocketAddr { union { struct sockaddr sa; struct sockaddr_storage stor; @@ -33,7 +36,7 @@ typedef struct { #endif } data; socklen_t len; -} virSocketAddr; +}; =20 #define VIR_SOCKET_ADDR_VALID(s) \ ((s)->data.sa.sa_family !=3D AF_UNSPEC) @@ -50,8 +53,6 @@ typedef struct { #define VIR_SOCKET_ADDR_IPV4_ARPA "in-addr.arpa" #define VIR_SOCKET_ADDR_IPV6_ARPA "ip6.arpa" =20 -typedef virSocketAddr *virSocketAddrPtr; - typedef struct _virSocketAddrRange virSocketAddrRange; typedef virSocketAddrRange *virSocketAddrRangePtr; struct _virSocketAddrRange { @@ -70,6 +71,12 @@ int virSocketAddrParse(virSocketAddrPtr addr, const char *val, int family); =20 +int virSocketAddrParseXML(const char *val, + virSocketAddrPtr addr, + const char *instname, + void *parent, + void *opaque); + int virSocketAddrParseAny(virSocketAddrPtr addr, const char *val, int family, @@ -93,6 +100,12 @@ char *virSocketAddrFormatFull(const virSocketAddr *addr, bool withService, const char *separator); =20 +int virSocketAddrFormatBuf(virBufferPtr buf, + const char *fmt, + const virSocketAddr *addr, + const void *parent, + void *opaque); + char *virSocketAddrGetPath(virSocketAddrPtr addr); =20 int virSocketAddrSetPort(virSocketAddrPtr addr, int port); @@ -145,5 +158,10 @@ int virSocketAddrPTRDomain(const virSocketAddr *addr, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3); =20 void virSocketAddrFree(virSocketAddrPtr addr); +void virSocketAddrClear(virSocketAddrPtr addr); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSocketAddr, virSocketAddrFree); + +bool virSocketAddrCheck(const virSocketAddr *addr, + const void *parent, + void *opaque); --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190938; cv=none; d=zohomail.com; s=zohoarc; b=OV2YVGNTs7EIwplKyBVpaMhtmjBt3TrEyMLsBLhDdJxD2zORwRsUxp89hOjtBtnWd5BBh1VCG6RNWJZX12sVi2BtPh5BD6QNM40D01yVYkk7624SNarzNVtjcxPO5mU/UjBOyD7q0bZ7WCDkoN7qO+G21Vx68KbI+ciyK3zvgMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190938; 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=CaS+WR2N9+r+7LlCqgPK23uG+pjeWLpqcolO0XR1fTQ=; b=Kcwoi0RBnZv5cTX33fLRYAt+Ev+1A3YPffBQjCq7OxF3WEGpZfFxSsBaDCyDj/rWrNKhBbZIBWMJmcGaSYjHkOSB1Hwxf3c+CZIqSjOoepufRtofon7kKXO70oaaD22FGgYDUBXmvw/aS87Ecwp989gOurDh+AH3Kf0kSu33u7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190938901461.1358758830494; Thu, 3 Sep 2020 20:42:18 -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-497-8ubKfwzRPumGxKr2OVtE_A-1; Thu, 03 Sep 2020 23:42:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 021F01DE11; Fri, 4 Sep 2020 03:42:11 +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 D684C811A6; Fri, 4 Sep 2020 03:42:10 +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 A548E97305; Fri, 4 Sep 2020 03:42:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAJ5030578 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC472117DB04; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A32E4117A97A for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 A0BF218A070C for ; Fri, 4 Sep 2020 03:41:08 +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-250-rpqFdkuHNJWrtLw_znKYWw-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S9; Fri, 04 Sep 2020 11:35:49 +0800 (CST) X-MC-Unique: 8ubKfwzRPumGxKr2OVtE_A-1 X-MC-Unique: rpqFdkuHNJWrtLw_znKYWw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 07/46] conf: Extract error-checking code from virNetworkDNSTxtDefParseXML Date: Fri, 4 Sep 2020 11:34:59 +0800 Message-Id: <20200904033538.418579-8-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--.1426S9 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4itxhHDUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiVxWVT1f4py2YHAAAs5 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.3 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.15 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/network_conf.c | 49 ++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 2fcd498..9ca8f74 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -886,26 +886,26 @@ virNetworkDNSSrvDefParseXML(const char *networkName, =20 =20 static int -virNetworkDNSTxtDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSTxtDefPtr def, - bool partialOkay) +virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSTxtDefPtr def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque) { const char *bad =3D " ,"; + bool partialOkay =3D false; + + if (opaque) + partialOkay =3D *((bool *) opaque); =20 - if (!(def->name =3D virXMLPropString(node, "name"))) { - virReportError(VIR_ERR_XML_DETAIL, - _("missing required name attribute in DNS TXT recor= d " - "of network %s"), networkName); - goto error; - } if (strcspn(def->name, bad) !=3D strlen(def->name)) { virReportError(VIR_ERR_XML_DETAIL, _("prohibited character in DNS TXT record " "name '%s' of network %s"), def->name, networkNam= e); goto error; } - if (!(def->value =3D virXMLPropString(node, "value")) && !partialOkay)= { + + if (!def->value && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("missing required value attribute in DNS TXT reco= rd " "named '%s' of network %s"), def->name, networkNa= me); @@ -918,6 +918,33 @@ virNetworkDNSTxtDefParseXML(const char *networkName, "in DNS TXT record of network %s"), networkName); goto error; } + + return 0; + + error: + return -1; +} + + +static int +virNetworkDNSTxtDefParseXML(const char *networkName, + xmlNodePtr node, + virNetworkDNSTxtDefPtr def, + bool partialOkay) +{ + if (!(def->name =3D virXMLPropString(node, "name"))) { + virReportError(VIR_ERR_XML_DETAIL, + _("missing required name attribute in DNS TXT recor= d " + "of network %s"), networkName); + goto error; + } + + def->value =3D virXMLPropString(node, "value"); + + if (virNetworkDNSTxtDefParseXMLHook(node, def, networkName, + NULL, &partialOkay) < 0) + goto error; + return 0; =20 error: --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190929; cv=none; d=zohomail.com; s=zohoarc; b=cYenQwah5pWdGZldBZAFaKkvfXM8Y59yX1vO9aAUvX+CZ8g0wTrBrgqGURZhULqMz3e+MDskRIvc7JYpEzq+lelmW0iNMffVZh9nyV8NS2ERYIMG2aXRtBuq+lNXJVN8HL5iW0TZ4JMwU4KThd0OsdTCUsi587Wk0jMnFM9AWnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190929; 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=sR9J6CnoUNFoVd7gQUvaL+dKaVvb9plnwvKt3ozut74=; b=ZOrp+hxiFEr9KB9SttpBSf1uyRvqW90VXUSoyGKtQoTyc9L8LvCDShRGoCtBpVExd2YEsImgb/68hyUq3yXkapMFdsoeZPicVQEXWcS5kRjM3/MBWnpdp9JRrra8Wrt3XCajOZgq2szGMIR9JxnwXQHnRtTVG8KMV1nfTrKC90s= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1599190929029151.4839698762721; Thu, 3 Sep 2020 20:42:09 -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-578-4gGIb-o7ODi-YaPLh59prQ-1; Thu, 03 Sep 2020 23:42:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1585A185FD8C; Fri, 4 Sep 2020 03:41:59 +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 EB04E5C230; Fri, 4 Sep 2020 03:41:58 +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 BACD5181A71E; Fri, 4 Sep 2020 03:41:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAoE030596 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C8A0420235B7; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BF7802018039 for ; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 DC2BB811E82 for ; Fri, 4 Sep 2020 03:41:08 +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-380-d4-3m1yzPyu4RhbDb2M6DA-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S10; Fri, 04 Sep 2020 11:35:49 +0800 (CST) X-MC-Unique: 4gGIb-o7ODi-YaPLh59prQ-1 X-MC-Unique: d4-3m1yzPyu4RhbDb2M6DA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 08/46] conf: Replace virNetworkDNSTxtDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:00 +0800 Message-Id: <20200904033538.418579-9-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--.1426S10 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFW3Ar18uw4UZFWfAr43KFg_yoWrZr4DpF s8t3Wqya18WF4fK3y7Ar95Cr4DCw1kXw4Yk34fu347Aw4rZryxGrn3Cr18XrW5GryFyF43 CF1YqrZ8Gr4UJFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMq2NLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiDxyVT1nfQQWGgwAAsO 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.4 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.16 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 --- po/POTFILES.in | 1 + src/conf/meson.build | 1 + src/conf/network_conf.c | 45 ++++++----------------------------------- src/conf/network_conf.h | 8 +++++--- 4 files changed, 13 insertions(+), 42 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index c9c0262..0356f1e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -3,6 +3,7 @@ @BUILDDIR@src/access/viraccessapicheckqemu.c @BUILDDIR@src/admin/admin_client.h @BUILDDIR@src/admin/admin_server_dispatch_stubs.h +@BUILDDIR@src/conf/network_conf.generated.c @BUILDDIR@src/remote/remote_client_bodies.h @BUILDDIR@src/remote/remote_daemon_dispatch_stubs.h @SRCDIR@scripts/xmlgen/directive.py diff --git a/src/conf/meson.build b/src/conf/meson.build index d82bffc..0619ca6 100644 --- a/src/conf/meson.build +++ b/src/conf/meson.build @@ -1,4 +1,5 @@ xmlgen_input =3D [ + 'network_conf.h', ] =20 xmlgen_output =3D [] diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 9ca8f74..036df20 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,14 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def) } =20 =20 -static void -virNetworkDNSTxtDefClear(virNetworkDNSTxtDefPtr def) -{ - VIR_FREE(def->name); - VIR_FREE(def->value); -} - - static void virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def) { @@ -885,7 +877,7 @@ virNetworkDNSSrvDefParseXML(const char *networkName, } =20 =20 -static int +int virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSTxtDefPtr def, const char *networkName, @@ -926,33 +918,6 @@ virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC= _UNUSED, } =20 =20 -static int -virNetworkDNSTxtDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSTxtDefPtr def, - bool partialOkay) -{ - if (!(def->name =3D virXMLPropString(node, "name"))) { - virReportError(VIR_ERR_XML_DETAIL, - _("missing required name attribute in DNS TXT recor= d " - "of network %s"), networkName); - goto error; - } - - def->value =3D virXMLPropString(node, "value"); - - if (virNetworkDNSTxtDefParseXMLHook(node, def, networkName, - NULL, &partialOkay) < 0) - goto error; - - return 0; - - error: - virNetworkDNSTxtDefClear(def); - return -1; -} - - static int virNetworkDNSDefParseXML(const char *networkName, xmlNodePtr node, @@ -1080,8 +1045,8 @@ virNetworkDNSDefParseXML(const char *networkName, return -1; =20 for (i =3D 0; i < ntxts; i++) { - if (virNetworkDNSTxtDefParseXML(networkName, txtNodes[i], - &def->txts[def->ntxts], false)= < 0) { + if (virNetworkDNSTxtDefParseXML(txtNodes[i], &def->txts[def->n= txts], + networkName, def, NULL) < 0) { return -1; } def->ntxts++; @@ -3637,6 +3602,7 @@ virNetworkDefUpdateDNSTxt(virNetworkDefPtr def, virNetworkDNSTxtDef txt; bool isAdd =3D (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); + bool notAdd; =20 memset(&txt, 0, sizeof(txt)); =20 @@ -3650,7 +3616,8 @@ virNetworkDefUpdateDNSTxt(virNetworkDefPtr def, if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "txt") < 0) goto cleanup; =20 - if (virNetworkDNSTxtDefParseXML(def->name, ctxt->node, &txt, !isAdd) <= 0) + notAdd =3D !isAdd; + if (virNetworkDNSTxtDefParseXML(ctxt->node, &txt, def->name, def, ¬= Add) < 0) goto cleanup; =20 for (foundIdx =3D 0; foundIdx < dns->ntxts; foundIdx++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 34b9aa9..d5fd8cc 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -130,9 +130,9 @@ struct _virNetworkDHCPHostDef { =20 typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef; typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr; -struct _virNetworkDNSTxtDef { - char *name; - char *value; +struct _virNetworkDNSTxtDef { /* genparse:concisehook */ + char *name; /* xmlattr, required */ + char *value; /* xmlattr */ }; =20 typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef; @@ -443,3 +443,5 @@ virNetworkDefUpdateSection(virNetworkDefPtr def, unsigned int flags); /* virNetworkUpdateFlags = */ =20 VIR_ENUM_DECL(virNetworkTaint); + +#include "network_conf.generated.h" --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190907; cv=none; d=zohomail.com; s=zohoarc; b=UqPAHvXFnc587xQQ3vqthlJ6cOxY2ye7YAeAyMeSulDM9xBy/rEg/Pnj67F5Q1f0u0sB2yLSFsg+wITLUV+4/iQsb2Rab0rXm1NK7Yu9Pmfg2y/kyNcojz5cfWEkHkLLMm75RDO3hzVN3cfnrMt0cjiiYqPk0nszYB7uGr3Mt2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190907; 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=t9fOkLyK6ULsyE32sj8xV9bVPRqdrn+bh/o5K8t6AZk=; b=VpETktA+rzQ5XnlyGey96EWMpTYs4fRvHDw6B10xbG9VbM9Omt2ee9SiqtnT7fYuS7yssEvsA5rJxbN0k0ABsmmUWyJKMRfIWt7ublyUST1r2RCATq/e5cO8CjPSFL2wn1SyPzwhOteSo5BBe1/6Gjx/U7F2Kay2pAJigtWEGhk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599190907804879.3714322659747; Thu, 3 Sep 2020 20:41:47 -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-251-vlBsQcgfOwC3MqYWSFyLZw-1; Thu, 03 Sep 2020 23:41:45 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17134185A0F6; Fri, 4 Sep 2020 03:41:40 +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 EB2177E417; Fri, 4 Sep 2020 03:41:39 +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 B51A5A21EA; Fri, 4 Sep 2020 03:41:39 +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 0843f9NG030555 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD7EC2157F25; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B4E692157F49 for ; Fri, 4 Sep 2020 03:41:08 +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 387C918A070F for ; Fri, 4 Sep 2020 03:41:08 +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-112-0sKNz7bdOjS8i9Jh1R2rPQ-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S11; Fri, 04 Sep 2020 11:35:49 +0800 (CST) X-MC-Unique: vlBsQcgfOwC3MqYWSFyLZw-1 X-MC-Unique: 0sKNz7bdOjS8i9Jh1R2rPQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 09/46] conf: Generate virNetworkDNSTxtDefFormatBuf Date: Fri, 4 Sep 2020 11:35:01 +0800 Message-Id: <20200904033538.418579-10-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--.1426S11 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRX_-mUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiRhWVT1bdHZp3eQAAsL 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.79 on 10.5.11.11 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/network_conf.c | 4 ++-- src/conf/network_conf.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 036df20..7b17e44 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2219,8 +2219,8 @@ virNetworkDNSDefFormat(virBufferPtr buf, } =20 for (i =3D 0; i < def->ntxts; i++) { - virBufferEscapeString(buf, "txts[i].name); - virBufferEscapeString(buf, "value=3D'%s'/>\n", def->txts[i].value); + if (virNetworkDNSTxtDefFormatBuf(buf, "txt", &def->txts[i], def, N= ULL) < 0) + return -1; } =20 for (i =3D 0; i < def->nsrvs; i++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index d5fd8cc..338ac65 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -130,7 +130,7 @@ struct _virNetworkDHCPHostDef { =20 typedef struct _virNetworkDNSTxtDef virNetworkDNSTxtDef; typedef virNetworkDNSTxtDef *virNetworkDNSTxtDefPtr; -struct _virNetworkDNSTxtDef { /* genparse:concisehook */ +struct _virNetworkDNSTxtDef { /* genparse:concisehook, genformat */ char *name; /* xmlattr, required */ char *value; /* xmlattr */ }; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190925; cv=none; d=zohomail.com; s=zohoarc; b=l1dmfWGoIWH9VNO4k+Sq1oAEmNycas2lQzVrBp2TmmWh4qbOdsKvy1N0bIj+HfhHh6ZSOhGfeOIlAq1j66yxeQJNV77Y4JMNS7mHdgCHNsX71pMyS9i1YfWgX3Q1RVGKzdLjXV74dIlAeiQZlU8cYxcWNa7L+Vrmz+DYdIjqJXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190925; 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=jr/hdp/P5sezV1qnCGe6sP7+2BxuvibxIIX2rsB5DzM=; b=BJDf9CsBxCqxx7zg4V0GKzhUk5gIPtRGenjlhDuQx9OC82bbUzj0WwbB+k69wJ/ygj+CSvyW9zniNsmVFntH8anD45DGrHf6JFJKpqzpMphWe/0OvgQbAFGxAAl2gXTfNS2Hf3875ygkdm5+oLOOLq9Egjww73IIIr/7LKy2/Y8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190925291326.5876150323329; Thu, 3 Sep 2020 20:42:05 -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-246-1bS-ZGe8PQqAIbHNpn8-Gw-1; Thu, 03 Sep 2020 23:42:02 -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 DD25A800400; Fri, 4 Sep 2020 03:41:49 +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 B8D811002391; Fri, 4 Sep 2020 03:41:49 +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 878DC972F2; Fri, 4 Sep 2020 03:41:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAon030595 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C86C02023598; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBF51202450A for ; Fri, 4 Sep 2020 03:41:07 +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 AC894185A78B for ; Fri, 4 Sep 2020 03:41:07 +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-322-VFQx5voqOLaUoApUfzGDMA-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S12; Fri, 04 Sep 2020 11:35:50 +0800 (CST) X-MC-Unique: 1bS-ZGe8PQqAIbHNpn8-Gw-1 X-MC-Unique: VFQx5voqOLaUoApUfzGDMA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 10/46] conf: Extract error-checking code from virNetworkDNSSrvDefParseXML Date: Fri, 4 Sep 2020 11:35:02 +0800 Message-Id: <20200904033538.418579-11-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--.1426S12 X-Coremail-Antispam: 1Uf129KBjvJXoW3Jr4DXr4ktFWrKrWUWF4UJwb_yoW7trWfpF s5Ja98GrWrGr1fKrWjkFyrGw15Wrn5tr45C3s7Zas2k3y3Xwn7Cr47ZF1DW3y7Cry5Jr4a yFy3Zws5Wrn8Z3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbibBaVT1lZvWTTmQAAsz 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.4 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.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/network_conf.c | 107 +++++++++++++++++++++++++++++++--------- 1 file changed, 83 insertions(+), 24 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 7b17e44..dc39afb 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -767,23 +767,26 @@ virNetworkDNSHostDefParseXML(const char *networkName, "_-+/*" =20 static int -virNetworkDNSSrvDefParseXML(const char *networkName, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - virNetworkDNSSrvDefPtr def, - bool partialOkay) +virNetworkDNSSrvDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSSrvDefPtr def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *portStr, + const char *priorityStr, + const char *weightStr) { - int ret; - VIR_XPATH_NODE_AUTORESTORE(ctxt) - - ctxt->node =3D node; + bool partialOkay =3D false; + if (opaque) + partialOkay =3D *((bool *) opaque); =20 - if (!(def->service =3D virXMLPropString(node, "service")) && !partialO= kay) { + if (!def->service && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("missing required service attribute in DNS SRV re= cord " "of network '%s'"), networkName); goto error; } + if (def->service) { if (strlen(def->service) > DNS_RECORD_LENGTH_SRV) { virReportError(VIR_ERR_XML_DETAIL, @@ -801,13 +804,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, } } =20 - if (!(def->protocol =3D virXMLPropString(node, "protocol")) && !partia= lOkay) { + if (!def->protocol && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("missing required protocol attribute " "in DNS SRV record '%s' of network '%s'"), def->service, networkName); goto error; } + if (def->protocol && strspn(def->protocol, PROTOCOL_CHARS) < strlen(def->protocol)) { virReportError(VIR_ERR_XML_DETAIL, @@ -817,19 +821,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, goto error; } =20 - /* Following attributes are optional */ - def->domain =3D virXMLPropString(node, "domain"); - def->target =3D virXMLPropString(node, "target"); - - ret =3D virXPathUInt("string(./@port)", ctxt, &def->port); - if (ret >=3D 0 && !def->target) { + if (portStr && !def->target) { virReportError(VIR_ERR_XML_DETAIL, _("DNS SRV port attribute not permitted without " "target for service '%s' in network '%s'"), def->service, networkName); goto error; } - if (ret =3D=3D -2 || (ret >=3D 0 && (def->port < 1 || def->port > 6553= 5))) { + if (portStr && (def->port < 1 || def->port > 65535)) { virReportError(VIR_ERR_XML_DETAIL, _("invalid DNS SRV port attribute " "for service '%s' in network '%s'"), @@ -837,15 +836,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, goto error; } =20 - ret =3D virXPathUInt("string(./@priority)", ctxt, &def->priority); - if (ret >=3D 0 && !def->target) { + if (priorityStr && !def->target) { virReportError(VIR_ERR_XML_DETAIL, _("DNS SRV priority attribute not permitted without= " "target for service '%s' in network '%s'"), def->service, networkName); goto error; } - if (ret =3D=3D -2 || (ret >=3D 0 && def->priority > 65535)) { + if (priorityStr && def->priority > 65535) { virReportError(VIR_ERR_XML_DETAIL, _("Invalid DNS SRV priority attribute " "for service '%s' in network '%s'"), @@ -853,15 +851,14 @@ virNetworkDNSSrvDefParseXML(const char *networkName, goto error; } =20 - ret =3D virXPathUInt("string(./@weight)", ctxt, &def->weight); - if (ret >=3D 0 && !def->target) { + if (weightStr && !def->target) { virReportError(VIR_ERR_XML_DETAIL, _("DNS SRV weight attribute not permitted without " "target for service '%s' in network '%s'"), def->service, networkName); goto error; } - if (ret =3D=3D -2 || (ret >=3D 0 && def->weight > 65535)) { + if (weightStr && def->weight > 65535) { virReportError(VIR_ERR_XML_DETAIL, _("invalid DNS SRV weight attribute " "for service '%s' in network '%s'"), @@ -871,6 +868,68 @@ virNetworkDNSSrvDefParseXML(const char *networkName, =20 return 0; =20 + error: + return -1; +} + + +static int +virNetworkDNSSrvDefParseXML(const char *networkName, + xmlNodePtr node, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, + virNetworkDNSSrvDefPtr def, + bool partialOkay) +{ + g_autofree char *portStr =3D NULL; + g_autofree char *priorityStr =3D NULL; + g_autofree char *weightStr =3D NULL; + + def->service =3D virXMLPropString(node, "service"); + def->protocol =3D virXMLPropString(node, "protocol"); + + /* Following attributes are optional */ + def->domain =3D virXMLPropString(node, "domain"); + def->target =3D virXMLPropString(node, "target"); + + portStr =3D virXMLPropString(node, "port"); + if (portStr) { + if (virStrToLong_uip(portStr, NULL, 0, &def->port) < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid DNS SRV port attribute " + "for service '%s' in network '%s'"), + def->service, networkName); + goto error; + } + } + + priorityStr =3D virXMLPropString(node, "priority"); + if (priorityStr) { + if (virStrToLong_uip(priorityStr, NULL, 0, &def->priority) < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("Invalid DNS SRV priority attribute " + "for service '%s' in network '%s'"), + def->service, networkName); + goto error; + } + } + + weightStr =3D virXMLPropString(node, "weight"); + if (weightStr) { + if (virStrToLong_uip(weightStr, NULL, 0, &def->weight) < 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid DNS SRV weight attribute " + "for service '%s' in network '%s'"), + def->service, networkName); + goto error; + } + } + + if (virNetworkDNSSrvDefParseXMLHook(node, def, networkName, def, &part= ialOkay, + portStr, priorityStr, weightStr) <= 0) + goto error; + + return 0; + error: virNetworkDNSSrvDefClear(def); return -1; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190919; cv=none; d=zohomail.com; s=zohoarc; b=a0trJFpRgprCcaasuk26qFRfoeiX+debzHG1bpQdDrzbqc3HiWr2eEq6jwbKGTKXWZ5tDrkHSmUz92ghl9K97s+tJg7qUUSL3Gx+8KtXxmdfWuUT4VxOGnZsDAxDDXRtZnA33qZ3jWTYeZ1zk1CUsrS0loZrIt/DKpwZwJqjDCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190919; 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=a/G023oSuwaNF3FBWdFr16H1EYWALmnWc6e0GjKk7xg=; b=NWkoSEWdGRs2wBTNXSWAsH5UDGgCPUjl/SMAeKIlSidOD7yeBllWbNWgynhk9n8CeME6+Zi0Ho4WqGjbSguigCjwmI8lz/vH4F9nZnJpJMyse1y69FOMeQ/xsTAXDZrWN/b5u4cFFA2pOaspeO8s69joJrl0Yux+4t96QmUGyKs= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 159919091945868.2786954583263; Thu, 3 Sep 2020 20:41:59 -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-401-32NXe_bUN3WGNJjVr1mIXQ-1; Thu, 03 Sep 2020 23:41:56 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D1A3C1F1C0; Fri, 4 Sep 2020 03:41:49 +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 B2ED75D9DC; Fri, 4 Sep 2020 03:41:49 +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 7DB74181A07C; Fri, 4 Sep 2020 03:41:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBXV030653 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 017F8200AE6D; Fri, 4 Sep 2020 03:41:11 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBDF620244F7 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 B6E2E18A070E for ; Fri, 4 Sep 2020 03:41:07 +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-277-AIQ_8FlAMiGXS8x56M_OuQ-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S13; Fri, 04 Sep 2020 11:35:50 +0800 (CST) X-MC-Unique: 32NXe_bUN3WGNJjVr1mIXQ-1 X-MC-Unique: AIQ_8FlAMiGXS8x56M_OuQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 11/46] conf: Replace virNetworkDNSSrvDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:03 +0800 Message-Id: <20200904033538.418579-12-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--.1426S13 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF48tFy3XFWDXr15KF48Zwb_yoW7GryrpF n5JasrCFWrWr4rKFWjyrn5Cws8ur1kJw45C3s3Z34xC3y5Xr1xC34xZr18WrW5Gr9Yyr13 AFyavws8Gr4UZF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiHRaVT1pcibGQyQAAs2 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.4 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.14 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/network_conf.c | 83 +++-------------------------------------- src/conf/network_conf.h | 16 ++++---- 2 files changed, 14 insertions(+), 85 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index dc39afb..96664ab 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -183,16 +183,6 @@ virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def) } =20 =20 -static void -virNetworkDNSSrvDefClear(virNetworkDNSSrvDefPtr def) -{ - VIR_FREE(def->domain); - VIR_FREE(def->service); - VIR_FREE(def->protocol); - VIR_FREE(def->target); -} - - static void virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def) { @@ -766,7 +756,7 @@ virNetworkDNSHostDefParseXML(const char *networkName, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" \ "_-+/*" =20 -static int +int virNetworkDNSSrvDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSSrvDefPtr def, const char *networkName, @@ -873,69 +863,6 @@ virNetworkDNSSrvDefParseXMLHook(xmlNodePtr node G_GNUC= _UNUSED, } =20 =20 -static int -virNetworkDNSSrvDefParseXML(const char *networkName, - xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, - virNetworkDNSSrvDefPtr def, - bool partialOkay) -{ - g_autofree char *portStr =3D NULL; - g_autofree char *priorityStr =3D NULL; - g_autofree char *weightStr =3D NULL; - - def->service =3D virXMLPropString(node, "service"); - def->protocol =3D virXMLPropString(node, "protocol"); - - /* Following attributes are optional */ - def->domain =3D virXMLPropString(node, "domain"); - def->target =3D virXMLPropString(node, "target"); - - portStr =3D virXMLPropString(node, "port"); - if (portStr) { - if (virStrToLong_uip(portStr, NULL, 0, &def->port) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("invalid DNS SRV port attribute " - "for service '%s' in network '%s'"), - def->service, networkName); - goto error; - } - } - - priorityStr =3D virXMLPropString(node, "priority"); - if (priorityStr) { - if (virStrToLong_uip(priorityStr, NULL, 0, &def->priority) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("Invalid DNS SRV priority attribute " - "for service '%s' in network '%s'"), - def->service, networkName); - goto error; - } - } - - weightStr =3D virXMLPropString(node, "weight"); - if (weightStr) { - if (virStrToLong_uip(weightStr, NULL, 0, &def->weight) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("invalid DNS SRV weight attribute " - "for service '%s' in network '%s'"), - def->service, networkName); - goto error; - } - } - - if (virNetworkDNSSrvDefParseXMLHook(node, def, networkName, def, &part= ialOkay, - portStr, priorityStr, weightStr) <= 0) - goto error; - - return 0; - - error: - virNetworkDNSSrvDefClear(def); - return -1; -} - - int virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSTxtDefPtr def, @@ -1084,8 +1011,8 @@ virNetworkDNSDefParseXML(const char *networkName, return -1; =20 for (i =3D 0; i < nsrvs; i++) { - if (virNetworkDNSSrvDefParseXML(networkName, srvNodes[i], ctxt, - &def->srvs[def->nsrvs], false)= < 0) { + if (virNetworkDNSSrvDefParseXML(srvNodes[i], &def->srvs[def->n= srvs], + networkName, def, NULL) < 0) { return -1; } def->nsrvs++; @@ -3576,6 +3503,7 @@ virNetworkDefUpdateDNSSrv(virNetworkDefPtr def, bool isAdd =3D (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt =3D 0; + bool notAdd; =20 memset(&srv, 0, sizeof(srv)); =20 @@ -3589,7 +3517,8 @@ virNetworkDefUpdateDNSSrv(virNetworkDefPtr def, if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "srv") < 0) goto cleanup; =20 - if (virNetworkDNSSrvDefParseXML(def->name, ctxt->node, ctxt, &srv, !is= Add) < 0) + notAdd =3D !isAdd; + if (virNetworkDNSSrvDefParseXML(ctxt->node, &srv, def->name, def, ¬= Add) < 0) goto cleanup; =20 for (i =3D 0; i < dns->nsrvs; i++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 338ac65..3636698 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -137,14 +137,14 @@ struct _virNetworkDNSTxtDef { /* genparse:conciseho= ok, genformat */ =20 typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef; typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr; -struct _virNetworkDNSSrvDef { - char *domain; - char *service; - char *protocol; - char *target; - unsigned int port; - unsigned int priority; - unsigned int weight; +struct _virNetworkDNSSrvDef { /* genparse:withhook */ + char *service; /* xmlattr */ + char *protocol; /* xmlattr */ + char *domain; /* xmlattr */ + char *target; /* xmlattr */ + unsigned int port; /* xmlattr */ + unsigned int priority; /* xmlattr */ + unsigned int weight; /* xmlattr */ }; =20 typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190922; cv=none; d=zohomail.com; s=zohoarc; b=UCrCizr4UV4bdmAueD+GlZvGxLR6K+G3VJyOxiMeyx1O6EnzaHntfMKQhJcm39wD7xDsuUV2C1Z4vmEDIBjB03ZP5BrkfKsfEthTK9GvjUGXXsjG4HlvkYgqQNj+UZjWM6orIj4e9dInNA9Kk4FQjlqTt+Y4rpmiMVhzWD0ASCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190922; 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=A7AWTicSbEKfW5tv+FFKFF4Eiov+H3Qcsf9CFaMNFZo=; b=CKIli721Z7S/zCiWEp2asZUugB8ZrUxIgDzwTtxp3tV2XMJG5n0jRa0nyX4bg9rqvsA3gSYcg5ez4f0UzG01RLCZDmJWmxMPztmWsSmWeMiKQrCLa9LY06ktD+6AyNrneOkHPLZjqg077W9osx56UtocqZLlxZ1Phc6XG3uYftE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190922237325.33979571633347; Thu, 3 Sep 2020 20:42:02 -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-490-G-wnwo6VOHeA5MGPP4_U6Q-1; Thu, 03 Sep 2020 23:41:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA322871807; Fri, 4 Sep 2020 03:41:49 +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 B8E9A784A8; Fri, 4 Sep 2020 03:41:49 +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 8553A181A07D; Fri, 4 Sep 2020 03:41:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAwE030561 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21EE4103426; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 161EA1037A8 for ; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 E3E0C101A540 for ; Fri, 4 Sep 2020 03:41:08 +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-369-CcC26fSjMduxr2F3CgFTEw-1; Thu, 03 Sep 2020 23:41:06 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S14; Fri, 04 Sep 2020 11:35:50 +0800 (CST) X-MC-Unique: G-wnwo6VOHeA5MGPP4_U6Q-1 X-MC-Unique: CcC26fSjMduxr2F3CgFTEw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 12/46] conf: Generate virNetworkDNSSrvDefFormatBuf Date: Fri, 4 Sep 2020 11:35:04 +0800 Message-Id: <20200904033538.418579-13-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--.1426S14 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRX_-mUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiSBaVT1dqAihy0gAAsz 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.79 on 10.11.54.5 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.13 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/network_conf.c | 18 ++---------------- src/conf/network_conf.h | 2 +- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 96664ab..518f6da 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2211,22 +2211,8 @@ virNetworkDNSDefFormat(virBufferPtr buf, =20 for (i =3D 0; i < def->nsrvs; i++) { if (def->srvs[i].service && def->srvs[i].protocol) { - virBufferEscapeString(buf, "srvs[i].service); - virBufferEscapeString(buf, "protocol=3D'%s'", def->srvs[i].pro= tocol); - - if (def->srvs[i].domain) - virBufferEscapeString(buf, " domain=3D'%s'", def->srvs[i].= domain); - if (def->srvs[i].target) - virBufferEscapeString(buf, " target=3D'%s'", def->srvs[i].= target); - if (def->srvs[i].port) - virBufferAsprintf(buf, " port=3D'%d'", def->srvs[i].port); - if (def->srvs[i].priority) - virBufferAsprintf(buf, " priority=3D'%d'", def->srvs[i].pr= iority); - if (def->srvs[i].weight) - virBufferAsprintf(buf, " weight=3D'%d'", def->srvs[i].weig= ht); - - virBufferAddLit(buf, "/>\n"); + if (virNetworkDNSSrvDefFormatBuf(buf, "srv", &def->srvs[i], de= f, NULL) < 0) + return -1; } } =20 diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 3636698..041119e 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -137,7 +137,7 @@ struct _virNetworkDNSTxtDef { /* genparse:concisehook= , genformat */ =20 typedef struct _virNetworkDNSSrvDef virNetworkDNSSrvDef; typedef virNetworkDNSSrvDef *virNetworkDNSSrvDefPtr; -struct _virNetworkDNSSrvDef { /* genparse:withhook */ +struct _virNetworkDNSSrvDef { /* genparse:withhook, genformat */ char *service; /* xmlattr */ char *protocol; /* xmlattr */ char *domain; /* xmlattr */ --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190936; cv=none; d=zohomail.com; s=zohoarc; b=Dy1d9tJVWhrIM3w8troovWXMPwUbNYTZAimSLCpgT5qISSE2nKuY3Hry8qFrifKJHxm3U52k2950p72mC4uAYY2mbwh3IRaNlyUsR+MfKLb0kx9CjzOKmbFxMzEyeVhW9NQLgWDd0dUeOL33kZ4GMY/oJJclh/QwiMe9Vj8t3Js= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190936; 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=X+C8um3wZ5Ccw/DOmccdQzATybGwYII9i9rBxSuq83g=; b=Q9NpDqRYfF3ondK9gd5PF5zQgZCBwHHEephZmmynO6XYZ41iTwvCAK9QEVl6QPxQfmgA62Hs4GvcCgUAMsnSdhfgSjItF9Ki4sKztYMzcCppFNOLq7htQvhlbdiSABtxOwGYdKGIuOHeC6DrI7uz1KuLq+RTJ/LGS4dLHIHfhpg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599190936416461.3345119317229; Thu, 3 Sep 2020 20:42: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-403-5DRgDJueNC-pPGW_Dzzofw-1; Thu, 03 Sep 2020 23:42:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B01385EE94; Fri, 4 Sep 2020 03:42:08 +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 6E1405D9DC; Fri, 4 Sep 2020 03:42:08 +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 3C750181A884; Fri, 4 Sep 2020 03:42:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBgu030603 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id AF4D9117DB06; 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 A4F5B117A97D for ; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 5ECF5805B0E for ; Fri, 4 Sep 2020 03:41:09 +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-yfTSVrr0MHGk-8BQ6a-0LA-1; Thu, 03 Sep 2020 23:41:06 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S15; Fri, 04 Sep 2020 11:35:50 +0800 (CST) X-MC-Unique: 5DRgDJueNC-pPGW_Dzzofw-1 X-MC-Unique: yfTSVrr0MHGk-8BQ6a-0LA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 13/46] conf: Extract error-checking code from virNetworkDNSHostDefParseXML Date: Fri, 4 Sep 2020 11:35:05 +0800 Message-Id: <20200904033538.418579-14-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--.1426S15 X-Coremail-Antispam: 1Uf129KBjvJXoWxCF45WrWDtrW5JF4xAFy7KFg_yoW5GF4DpF 4fJa98JF4kWr1ak397KF10kw15Wrykt345Kryfuw1UZFy3Xw18Gws7ZFy3WasxGry5Xr4a yF4ayws8Gr4UA3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMq2NLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiEBeVT1nxrfy0RwAAsX 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.3 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.14 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/network_conf.c | 63 +++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 518f6da..44032e6 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -675,21 +675,57 @@ virNetworkDHCPDefParseXML(const char *networkName, =20 =20 static int -virNetworkDNSHostDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSHostDefPtr def, - bool partialOkay) +virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSHostDefPtr def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *ip, + int nHostnameNodes G_GNUC_UNUSED) { - xmlNodePtr cur; - g_autofree char *ip =3D NULL; + bool partialOkay =3D false; =20 - if (!(ip =3D virXMLPropString(node, "ip")) && !partialOkay) { + if (opaque) + partialOkay =3D *((bool *) opaque); + + if (!ip && !partialOkay) { virReportError(VIR_ERR_XML_DETAIL, _("Missing IP address in network '%s' DNS HOST reco= rd"), networkName); goto error; } =20 + if (def->nnames =3D=3D 0 && !partialOkay) { + virReportError(VIR_ERR_XML_DETAIL, + _("Missing hostname in network '%s' DNS HOST record= "), + networkName); + goto error; + } + + if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames =3D=3D 0) { + virReportError(VIR_ERR_XML_DETAIL, + _("Missing ip and hostname in network '%s' DNS HOST= record"), + networkName); + goto error; + } + + return 0; + + error: + return -1; +} + + +static int +virNetworkDNSHostDefParseXML(const char *networkName, + xmlNodePtr node, + virNetworkDNSHostDefPtr def, + bool partialOkay) +{ + xmlNodePtr cur; + g_autofree char *ip =3D NULL; + + ip =3D virXMLPropString(node, "ip"); if (ip && (virSocketAddrParse(&def->ip, ip, AF_UNSPEC) < 0)) { virReportError(VIR_ERR_XML_DETAIL, _("Invalid IP address in network '%s' DNS HOST reco= rd"), @@ -719,19 +755,10 @@ virNetworkDNSHostDefParseXML(const char *networkName, } cur =3D cur->next; } - if (def->nnames =3D=3D 0 && !partialOkay) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing hostname in network '%s' DNS HOST record= "), - networkName); - goto error; - } =20 - if (!VIR_SOCKET_ADDR_VALID(&def->ip) && def->nnames =3D=3D 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing ip and hostname in network '%s' DNS HOST= record"), - networkName); + if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, def, &par= tialOkay, + ip, def->nnames) < 0) goto error; - } =20 return 0; =20 --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190983; cv=none; d=zohomail.com; s=zohoarc; b=UQhylBixVMILmN4jSmyXAOcO2UWrjaQNS5JI9755FB40xdL3GsG7qaWWfWatipEXZ4iXbsB5ynyVrAG7n/o+j1pjOmEkyuTDhQWS9MLpEL0iUQfe++NLXfORb6A1YUEQFJCL0vQSbRZ1c/3LSkEPfLUGvb51j4Q+gG2+FnvTlos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190983; 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=uEZUDIdMqU2aPoHbEX298UaKIWdFeRPoBVmuJAjFeok=; b=TzC1xF5Y/gjUbBM8FpXq0VKX5LXXLZKRaNThOQ8Gls3QdrUDv/Jz/6K+GBAMtgR2ZmR9r/yQ0qGvUMwSQHzmMuZjKx6/AteYGGhZ9vI8g4t3lwQpFWvpa8bPjvpfAPAzSXdzks2kC5Gbl46L+jAGfTeoXr9JNE+a0qOP6iO4fRw= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599190983576111.64752674435442; Thu, 3 Sep 2020 20:43:03 -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-515-Ak5kWXsrPTOILiwt8D6rLA-1; Thu, 03 Sep 2020 23:42:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD29580733D; Fri, 4 Sep 2020 03:41:56 +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 ABD4A7C0B3; Fri, 4 Sep 2020 03:41:56 +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 796BA972FD; Fri, 4 Sep 2020 03:41:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fA3r030558 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A9DC1037A7; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1030D10379B for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 0D54488296A for ; Fri, 4 Sep 2020 03:41:07 +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-303-G09LXhwUP1ygiVZLLpVDCA-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S16; Fri, 04 Sep 2020 11:35:51 +0800 (CST) X-MC-Unique: Ak5kWXsrPTOILiwt8D6rLA-1 X-MC-Unique: G09LXhwUP1ygiVZLLpVDCA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 14/46] conf: Replace virNetworkDNSHostDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:06 +0800 Message-Id: <20200904033538.418579-15-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--.1426S16 X-Coremail-Antispam: 1Uf129KBjvJXoWxCrWxGFWUXF1DXrWrtw48tFb_yoWrWw13pF sxJa1DA3y8W3WfK3y2yr1SkrnxurykXw45Gryfuw13A3yUXr1xGws7uF1xWan8GryYyr15 AF4Yvws8GrW7JFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiihyVT1tVhJllTgAAs0 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.79 on 10.11.54.5 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.11 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/network_conf.c | 71 ++++------------------------------------- src/conf/network_conf.h | 6 ++-- 2 files changed, 9 insertions(+), 68 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 44032e6..e2d0297 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,15 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def) } =20 =20 -static void -virNetworkDNSHostDefClear(virNetworkDNSHostDefPtr def) -{ - while (def->nnames) - VIR_FREE(def->names[--def->nnames]); - VIR_FREE(def->names); -} - - static void virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def) { @@ -674,7 +665,7 @@ virNetworkDHCPDefParseXML(const char *networkName, } =20 =20 -static int +int virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSHostDefPtr def, const char *networkName, @@ -716,58 +707,6 @@ virNetworkDNSHostDefParseXMLHook(xmlNodePtr node G_GNU= C_UNUSED, } =20 =20 -static int -virNetworkDNSHostDefParseXML(const char *networkName, - xmlNodePtr node, - virNetworkDNSHostDefPtr def, - bool partialOkay) -{ - xmlNodePtr cur; - g_autofree char *ip =3D NULL; - - ip =3D virXMLPropString(node, "ip"); - if (ip && (virSocketAddrParse(&def->ip, ip, AF_UNSPEC) < 0)) { - virReportError(VIR_ERR_XML_DETAIL, - _("Invalid IP address in network '%s' DNS HOST reco= rd"), - networkName); - goto error; - } - - cur =3D node->children; - while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "hostname")) { - if (cur->children !=3D NULL) { - g_autofree char *name =3D virXMLNodeContentString(cur); - - if (!name) - goto error; - - if (!name[0]) { - virReportError(VIR_ERR_XML_DETAIL, - _("Missing hostname in network '%s' D= NS HOST record"), - networkName); - goto error; - } - if (VIR_APPEND_ELEMENT(def->names, def->nnames, name) < = 0) - goto error; - } - } - cur =3D cur->next; - } - - if (virNetworkDNSHostDefParseXMLHook(node, def, networkName, def, &par= tialOkay, - ip, def->nnames) < 0) - goto error; - - return 0; - - error: - virNetworkDNSHostDefClear(def); - return -1; -} - - /* This includes all characters used in the names of current * /etc/services and /etc/protocols files (on Fedora 20), except ".", * which we can't allow because it would conflict with the use of "." @@ -1018,8 +957,8 @@ virNetworkDNSDefParseXML(const char *networkName, return -1; =20 for (i =3D 0; i < nhosts; i++) { - if (virNetworkDNSHostDefParseXML(networkName, hostNodes[i], - &def->hosts[def->nhosts], fal= se) < 0) { + if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def= ->nhosts], + networkName, def, NULL) < 0) { return -1; } def->nhosts++; @@ -3421,6 +3360,7 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def, bool isAdd =3D (command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST || command =3D=3D VIR_NETWORK_UPDATE_COMMAND_ADD_LAST); int foundCt =3D 0; + bool notAdd; =20 memset(&host, 0, sizeof(host)); =20 @@ -3434,7 +3374,8 @@ virNetworkDefUpdateDNSHost(virNetworkDefPtr def, if (virNetworkDefUpdateCheckElementName(def, ctxt->node, "host") < 0) goto cleanup; =20 - if (virNetworkDNSHostDefParseXML(def->name, ctxt->node, &host, !isAdd)= < 0) + notAdd =3D !isAdd; + if (virNetworkDNSHostDefParseXML(ctxt->node, &host, def->name, def, &n= otAdd) < 0) goto cleanup; =20 for (i =3D 0; i < dns->nhosts; i++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 041119e..c30fd4f 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -149,10 +149,10 @@ struct _virNetworkDNSSrvDef { /* genparse:withhook,= genformat */ =20 typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef; typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr; -struct _virNetworkDNSHostDef { - virSocketAddr ip; +struct _virNetworkDNSHostDef { /* genparse:withhook */ + virSocketAddr ip; /* xmlattr */ size_t nnames; - char **names; + char **names; /* xmlelem:hostname, array */ }; =20 =20 --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190983; cv=none; d=zohomail.com; s=zohoarc; b=brfshb8DglyYmAbACuH/F6sP5cKQAKg6jcnDgcseVS3dhsM5WIo4yUp9jduycolKi5z5BoBfZ107d7XCyLGzcik7KP3pNS7DrlWyF9X0Xn8T1RKcUcuysh7ubV1pc2yNqLHukb5cWHCnxNIFISXnv6NHHCyLq+r3EWhdXXrAA3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190983; 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=bEekl/N6I0LAOTDm3NQk1Aoz/BNWE7LF/J/ugXCAz+Q=; b=GDo5J2dnqdiVgUOVQfvwhKOj8v/Ncor0WURfCLWXflBBjNJD//9TwHitvqmyvT80swwLVVeVxvOxbGMgv7yg6icbDueDdWPNOwSk062gxGlANndK0CMV5AWbZWHSBcvEz7CTJIlVHrV2YyiDU+XPa2mOz1CvfNa4+no9j3AEkL4= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599190983532617.2087052934374; Thu, 3 Sep 2020 20:43:03 -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-570-x-8hjWk1PX62kDzMpOKUAQ-1; Thu, 03 Sep 2020 23:42:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DB822FD0A; Fri, 4 Sep 2020 03:41:54 +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 6D9285D9DC; Fri, 4 Sep 2020 03:41:54 +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 3CD3D972F8; Fri, 4 Sep 2020 03:41:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBhU030658 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 776A3EE873; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72D031037BD for ; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 5AC25801223 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-528-MmwZNbmbPiqh1GKnmNVmSw-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--.1426S17; Fri, 04 Sep 2020 11:35:51 +0800 (CST) X-MC-Unique: x-8hjWk1PX62kDzMpOKUAQ-1 X-MC-Unique: MmwZNbmbPiqh1GKnmNVmSw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 15/46] conf: Generate virNetworkDNSHostDefFormatBuf Date: Fri, 4 Sep 2020 11:35:07 +0800 Message-Id: <20200904033538.418579-16-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--.1426S17 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4iuc_oDUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbicRGVT1lZvYiFEgAAsY 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.79 on 10.11.54.5 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.14 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/network_conf.c | 14 +++----------- src/conf/network_conf.h | 2 +- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index e2d0297..0ed2332 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2115,7 +2115,7 @@ static int virNetworkDNSDefFormat(virBufferPtr buf, const virNetworkDNSDef *def) { - size_t i, j; + size_t i; =20 if (!(def->enable || def->forwardPlainNames || def->nfwds || def->nhos= ts || def->nsrvs || def->ntxts)) @@ -2184,16 +2184,8 @@ virNetworkDNSDefFormat(virBufferPtr buf, =20 if (def->nhosts) { for (i =3D 0; i < def->nhosts; i++) { - g_autofree char *ip =3D virSocketAddrFormat(&def->hosts[i].ip); - - virBufferAsprintf(buf, "\n", ip); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < def->hosts[i].nnames; j++) - virBufferEscapeString(buf, "%s\n", - def->hosts[i].names[j]); - - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + if (virNetworkDNSHostDefFormatBuf(buf, "host", &def->hosts[i],= def, NULL) < 0) + return -1; } } virBufferAdjustIndent(buf, -2); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index c30fd4f..61863b0 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -149,7 +149,7 @@ struct _virNetworkDNSSrvDef { /* genparse:withhook, g= enformat */ =20 typedef struct _virNetworkDNSHostDef virNetworkDNSHostDef; typedef virNetworkDNSHostDef *virNetworkDNSHostDefPtr; -struct _virNetworkDNSHostDef { /* genparse:withhook */ +struct _virNetworkDNSHostDef { /* genparse:withhook, genformat */ virSocketAddr ip; /* xmlattr */ size_t nnames; char **names; /* xmlelem:hostname, array */ --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190908; cv=none; d=zohomail.com; s=zohoarc; b=SVEVXjNUD/Y8/5gKeWElvquh/YJ/gNxVIBli+Ab0VpOxW/wPmay2J0zQuSXTfr44Koqshs+gbHCiJixT/S6l1JAgHd6M5UcjUCam6LkEUZtrNhXSsNw/9K+R/F58L5BHh9jnXd/rzrYeZprlOukYH6EdXwsr1PRM6D7eHkBo6Ug= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190908; 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=PgpFbHsDsAuUJKzW+UHQqhFnd6ZHiTCPDT/GD2y/mIc=; b=Fb3qWW3K5nW6hb1jzFhkMc8ctSc2xBrPXkPMEXDFTrylUkjugLWT+WtrTnsoP1xv3evzuGc2JxBbMstJxNRTZyN2prOh08n8SW6BoLcMDNeUZPiQI+DbM/0gkPnrP6SQeeq2IpVOkFPPR4L70e037GS0IwhzzaT0G+UWvrPDHYc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1599190908166840.4224780770512; Thu, 3 Sep 2020 20:41:48 -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-506-xtUXawT5OmWHWPGKVoCe8A-1; Thu, 03 Sep 2020 23:41:45 -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 3B578801AB5; Fri, 4 Sep 2020 03:41:40 +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 186321002D61; Fri, 4 Sep 2020 03:41:40 +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 DCCE8A21EB; Fri, 4 Sep 2020 03:41:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAJ8030575 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id A8515117A97F; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FFBA117A977 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 B9EDE8F6E67 for ; Fri, 4 Sep 2020 03:41:07 +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-264-irgl4ealMqe5Fmyr2HjETQ-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S18; Fri, 04 Sep 2020 11:35:51 +0800 (CST) X-MC-Unique: xtUXawT5OmWHWPGKVoCe8A-1 X-MC-Unique: irgl4ealMqe5Fmyr2HjETQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 16/46] conf: Extract virNetworkDNSForwarderParseXML from virNetworkDNSParseXML Date: Fri, 4 Sep 2020 11:35:08 +0800 Message-Id: <20200904033538.418579-17-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--.1426S18 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRljgsUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiRxeVT1dqAg6p5gAAs0 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.3 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.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/network_conf.c | 68 +++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 0ed2332..2af537c 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -870,6 +870,52 @@ virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC= _UNUSED, } =20 =20 +static int +virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSForwarderPtr def, + const char *instname G_GNUC_UNUSED, + void *parent G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED, + const char *addr) +{ + if (!(addr || def->domain)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Invalid forwarder element, must contain " + "at least one of addr or domain")); + return -1; + } + + return 0; +} + + +static int +virNetworkDNSForwarderParseXML(xmlNodePtr node, + virNetworkDNSForwarderPtr def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque) +{ + g_autofree char *addr =3D virXMLPropString(node, "addr"); + + if (addr && virSocketAddrParse(&def->addr, addr, AF_UNSPEC) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid forwarder IP address '%s' " + "in network '%s'"), + addr, networkName); + return -1; + } + + def->domain =3D virXMLPropString(node, "domain"); + + if (virNetworkDNSForwarderParseXMLHook(node, def, networkName, def, op= aque, + addr) < 0) + return -1; + + return 0; +} + + static int virNetworkDNSDefParseXML(const char *networkName, xmlNodePtr node, @@ -924,23 +970,13 @@ virNetworkDNSDefParseXML(const char *networkName, return -1; =20 for (i =3D 0; i < nfwds; i++) { - g_autofree char *addr =3D virXMLPropString(fwdNodes[i], "addr"= ); - - if (addr && virSocketAddrParse(&def->forwarders[i].addr, - addr, AF_UNSPEC) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid forwarder IP address '%s' " - "in network '%s'"), - addr, networkName); + if (virNetworkDNSForwarderParseXML(fwdNodes[i], + &def->forwarders[i], + networkName, + def, + NULL) < 0) return -1; - } - def->forwarders[i].domain =3D virXMLPropString(fwdNodes[i], "d= omain"); - if (!(addr || def->forwarders[i].domain)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Invalid forwarder element, must contain " - "at least one of addr or domain")); - return -1; - } + def->nfwds++; } } --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190943; cv=none; d=zohomail.com; s=zohoarc; b=HqYJeOBE08/IGFdOhTa6ZahDpmqrjn46JNEktRgsv6ENumS0KIzGJkcT1JvEDKCSemhs5Fr41jv7Q70u7l5fHXpA88Aqazwl2IWnQIBZolG1Vj35m+OJh5dEHfGkk/2QdfV3JAMn8edDWjdcgQFNSiY9fBw0broiRCakZLstgAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190943; 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=ZwhYr11bzTW1azQhxhlZ9yOLwdDX1gdvWH+t3c2FrMg=; b=FobBbatm1pmnvR7IVKB7hHl7GvpojvUScP/KIE1+xsFzvjKbL0y9LEy/v0jPJeZ1OjVyOD/INu7WNw0vaFz/OD+Sxu2s67iTMSDiBglBgbcEU5GBl/ZjSpqQOl7PzRBnWlmAM/vHtflm0AXmfmq4DUCze6Id+O9isDcWeOalL3s= 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 1599190943820960.0190555487325; Thu, 3 Sep 2020 20:42:23 -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-108-49RWZ5FzMUGFdFN0YC2yGQ-1; Thu, 03 Sep 2020 23:42:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 849291005E7A; Fri, 4 Sep 2020 03:42:01 +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 645A37E417; Fri, 4 Sep 2020 03:42:01 +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 2DE14972FF; Fri, 4 Sep 2020 03:42:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBAX030606 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id B1F5A117DB07; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4E70117A97B for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 AC1D2811E78 for ; Fri, 4 Sep 2020 03:41:07 +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-575-Bvf146JmOAu6xiXrRf_PKw-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S19; Fri, 04 Sep 2020 11:35:51 +0800 (CST) X-MC-Unique: 49RWZ5FzMUGFdFN0YC2yGQ-1 X-MC-Unique: Bvf146JmOAu6xiXrRf_PKw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 17/46] conf: Replace virNetworkDNSForwarderParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:09 +0800 Message-Id: <20200904033538.418579-18-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--.1426S19 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRljgsUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiAReVT1ikUOGa1gAAsN 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.3 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.11 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/network_conf.c | 36 +----------------------------------- src/conf/network_conf.h | 6 +++--- 2 files changed, 4 insertions(+), 38 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 2af537c..608843d 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,13 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def) } =20 =20 -static void -virNetworkDNSForwarderClear(virNetworkDNSForwarderPtr def) -{ - VIR_FREE(def->domain); -} - - static void virNetworkDNSDefClear(virNetworkDNSDefPtr def) { @@ -870,7 +863,7 @@ virNetworkDNSTxtDefParseXMLHook(xmlNodePtr node G_GNUC_= UNUSED, } =20 =20 -static int +int virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSForwarderPtr def, const char *instname G_GNUC_UNUSED, @@ -889,33 +882,6 @@ virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_G= NUC_UNUSED, } =20 =20 -static int -virNetworkDNSForwarderParseXML(xmlNodePtr node, - virNetworkDNSForwarderPtr def, - const char *networkName, - void *parent G_GNUC_UNUSED, - void *opaque) -{ - g_autofree char *addr =3D virXMLPropString(node, "addr"); - - if (addr && virSocketAddrParse(&def->addr, addr, AF_UNSPEC) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid forwarder IP address '%s' " - "in network '%s'"), - addr, networkName); - return -1; - } - - def->domain =3D virXMLPropString(node, "domain"); - - if (virNetworkDNSForwarderParseXMLHook(node, def, networkName, def, op= aque, - addr) < 0) - return -1; - - return 0; -} - - static int virNetworkDNSDefParseXML(const char *networkName, xmlNodePtr node, diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 61863b0..881a9f2 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -158,9 +158,9 @@ struct _virNetworkDNSHostDef { /* genparse:withhook, g= enformat */ =20 typedef struct _virNetworkDNSForwarder virNetworkDNSForwarder; typedef virNetworkDNSForwarder *virNetworkDNSForwarderPtr; -struct _virNetworkDNSForwarder { - virSocketAddr addr; - char *domain; +struct _virNetworkDNSForwarder { /* genparse:withhook */ + virSocketAddr addr; /* xmlattr */ + char *domain; /* xmlattr */ }; =20 typedef struct _virNetworkDNSDef virNetworkDNSDef; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599191214; cv=none; d=zohomail.com; s=zohoarc; b=R/vyRVm4Mxs5MaaCt93WS8qgkOyXwtrW6kxk/adOq5sF/7mrJOc4rOPYsIR3atng0QrJOFEIoeo76r/2Hra9PRfdJhaCiTXoKm8Tbg+Gi5Sl4/csdUB9E/zjvbXDg/0PJF8eLXRr7+CtcpqpxnELrWe5MRjS/lmELjb/XLZF7FY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191214; 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=f8XnU/dunZ6e0qh7Hx0gGPnfFsOMv6YMSq4oWB+1s14=; b=MNNf1wSfciLJ+90+XatsMQ/AbIig9Xr0+daRnqEW/p8bhHrUiE2cpW2A55boRBcYe3yOkyMupTd3ynsfDXSOlAVHgXlDtqaoHb5/nAlEpsMsnJuhMCL9UFMXmPdNdDMf/GywHwvlX5PR2PHUQpZFHS7O2rlLoDKloAnEgjk5gZ4= 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 1599191214458183.17772443500405; Thu, 3 Sep 2020 20:46:54 -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-349-bahbSWe9MmWR-DD8PS5hkQ-1; Thu, 03 Sep 2020 23:46:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49841801AF2; Fri, 4 Sep 2020 03:46:46 +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 2A1F07E413; Fri, 4 Sep 2020 03:46:46 +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 EF789972E4; Fri, 4 Sep 2020 03:46:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843kcHl032379 for ; Thu, 3 Sep 2020 23:46:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id ACBA8117A977; Fri, 4 Sep 2020 03:46:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6626117A976 for ; Fri, 4 Sep 2020 03:46:36 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 47F0F87EF95 for ; Fri, 4 Sep 2020 03:46:36 +0000 (UTC) Received: from mail-proxy25223.qiye.163.com (mail-proxy25223.qiye.163.com [103.129.252.23]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-382-VqjLTQ8TNdiddj5wBgntBw-1; Thu, 03 Sep 2020 23:46:33 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S20; Fri, 04 Sep 2020 11:35:52 +0800 (CST) X-MC-Unique: bahbSWe9MmWR-DD8PS5hkQ-1 X-MC-Unique: VqjLTQ8TNdiddj5wBgntBw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 18/46] conf: Generate virNetworkDNSForwarderFormatBuf Date: Fri, 4 Sep 2020 11:35:10 +0800 Message-Id: <20200904033538.418579-19-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--.1426S20 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4itxhHDUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiRRiVT1bdHCRQvwAAsb 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.3 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.11 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/network_conf.c | 18 +++--------------- src/conf/network_conf.h | 4 ++-- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 608843d..437c2c6 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2155,21 +2155,9 @@ virNetworkDNSDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, 2); =20 for (i =3D 0; i < def->nfwds; i++) { - - virBufferAddLit(buf, "forwarders[i].domain) { - virBufferEscapeString(buf, " domain=3D'%s'", - def->forwarders[i].domain); - } - if (VIR_SOCKET_ADDR_VALID(&def->forwarders[i].addr)) { - g_autofree char *addr =3D virSocketAddrFormat(&def->forwarders= [i].addr); - - if (!addr) - return -1; - - virBufferAsprintf(buf, " addr=3D'%s'", addr); - } - virBufferAddLit(buf, "/>\n"); + if (virNetworkDNSForwarderFormatBuf(buf, "forwarder", + &def->forwarders[i], def, NULL= ) < 0) + return -1; } =20 for (i =3D 0; i < def->ntxts; i++) { diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 881a9f2..84b636e 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -158,9 +158,9 @@ struct _virNetworkDNSHostDef { /* genparse:withhook, g= enformat */ =20 typedef struct _virNetworkDNSForwarder virNetworkDNSForwarder; typedef virNetworkDNSForwarder *virNetworkDNSForwarderPtr; -struct _virNetworkDNSForwarder { /* genparse:withhook */ - virSocketAddr addr; /* xmlattr */ +struct _virNetworkDNSForwarder { /* genparse:withhook, genformat */ char *domain; /* xmlattr */ + virSocketAddr addr; /* xmlattr */ }; =20 typedef struct _virNetworkDNSDef virNetworkDNSDef; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190918; cv=none; d=zohomail.com; s=zohoarc; b=XhFr/bwhL40XcclD/SbL9BIpUd5WC1fidMHbpXwIYjGU3+KuMXXbxWtA1jiuWyuprb5itIHvK6VNBOYjBvgt/nmXV2/0pgF50wxCKzVwb2+4xdtmJh7cwzv/3HoSshIsjm9zmm9J0g4qJdO5G0pGiu63jWOKZV2K2BXL0S2gbVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190918; 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=wBuBrtmXGN58B47VXAWK/gOptId+iRKPWs8Jx3l3nEo=; b=FKNgyvO2v8SVsCAwj6QcPz7vIGr2zrpbBPFyi3BddPyRb6wuOmtIYVyf6Twd5X/f6H+8blI5menWT4zkGvyiWKmMeohGDuZfN/Xt0MZmNG7+LTMfN5schh/Llev1EpT0UdOq9dcwqjnZdBjQUTSzkl5JUAVdzMjIZm6lCPd9iW8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190918812950.6520511839501; Thu, 3 Sep 2020 20:41:58 -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-397-U8wyzQvGNWi1NeAXe40DYQ-1; Thu, 03 Sep 2020 23:41:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77F74801AFC; Fri, 4 Sep 2020 03:41:47 +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 58F74784A8; Fri, 4 Sep 2020 03:41:47 +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 18EEA181A06B; Fri, 4 Sep 2020 03:41:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAx7030576 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id AEB88117DB05; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A4EF1117A97C for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 39719811E7A for ; Fri, 4 Sep 2020 03:41:08 +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-436-QAVX9ngvMR-V3254uSarww-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S21; Fri, 04 Sep 2020 11:35:52 +0800 (CST) X-MC-Unique: U8wyzQvGNWi1NeAXe40DYQ-1 X-MC-Unique: QAVX9ngvMR-V3254uSarww-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 19/46] conf: Extract error-checking code from virNetworkDNSDefParseXML Date: Fri, 4 Sep 2020 11:35:11 +0800 Message-Id: <20200904033538.418579-20-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--.1426S21 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4iuc_oDUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiHxiVT1uyHTnxCwAAsq 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.3 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.13 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/network_conf.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 437c2c6..910d23f 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -882,6 +882,31 @@ virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_G= NUC_UNUSED, } =20 =20 +static int +virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virNetworkDNSDefPtr def, + const char *networkName, + void *parent G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED, + const char *enable G_GNUC_UNUSED, + const char *forwardPlainNames G_GNUC_UNUSED, + int ntxts, + int nhosts, + int nsrvs, + int nfwds) +{ + if (def->enable =3D=3D VIR_TRISTATE_BOOL_NO && + (nfwds || nhosts || nsrvs || ntxts)) { + virReportError(VIR_ERR_XML_ERROR, + _("Extra data in disabled network '%s'"), + networkName); + return -1; + } + + return 0; +} + + static int virNetworkDNSDefParseXML(const char *networkName, xmlNodePtr node, @@ -1007,13 +1032,10 @@ virNetworkDNSDefParseXML(const char *networkName, } } =20 - if (def->enable =3D=3D VIR_TRISTATE_BOOL_NO && - (nfwds || nhosts || nsrvs || ntxts)) { - virReportError(VIR_ERR_XML_ERROR, - _("Extra data in disabled network '%s'"), - networkName); + if (virNetworkDNSDefParseXMLHook(node, def, networkName, def, NULL, + enable, forwardPlainNames, + ntxts, nhosts, nsrvs, nfwds) < 0) return -1; - } =20 return 0; } --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190948; cv=none; d=zohomail.com; s=zohoarc; b=OxHd1MJz6b8ex2/Qbt72wXkJ6Zu2DF5mNM/j6huFFlcx/BCoj4c8y4zEez7ZsXyHyne7/il0yuc6qeRnZEtJquuW0b3jTtl0iar04QCcb8j+2Qdxd0oeGpKlwOMsRcS4S83JIPdUYWxnrGw+qsObrWy43ggHHQpRExKlhnqxoWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190948; 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=7Gz+DDlmirVZ3G1uQtz2SpFSErYzMzR8zpOvstK1icQ=; b=K8tKhJaOgn1YzEC8RZiRurjWypfZm4dXXmV8gp/kcvl5nwhxbLhYw/1OVuInXaONCnbFiIxLqTydPQLUR4ygAVy7H7CIJEOPcwdrtwVYnyIqy1EvV8revqj55izl5Cn8MPolCzn+ZfEQ++97CN1KTEtd1GKSECC54Jge11X8dNc= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599190948117393.3530812615787; Thu, 3 Sep 2020 20:42:28 -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-349-Wa-v1dGkO6uKKuosLZu2vg-1; Thu, 03 Sep 2020 23:42:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 246468712D3; Fri, 4 Sep 2020 03:42:18 +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 0116B811B9; Fri, 4 Sep 2020 03:42: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 C4A561826D2C; Fri, 4 Sep 2020 03:42:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBcX030659 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1B5211037B7; Fri, 4 Sep 2020 03:41:11 +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 16E5A1037A8 for ; Fri, 4 Sep 2020 03:41:11 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 F24D6800962 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-443-mdCdURFrNhSGhGRgE-bC3g-1; Thu, 03 Sep 2020 23:41:08 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S22; Fri, 04 Sep 2020 11:35:53 +0800 (CST) X-MC-Unique: Wa-v1dGkO6uKKuosLZu2vg-1 X-MC-Unique: mdCdURFrNhSGhGRgE-bC3g-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 20/46] conf: Replace virNetworkDNSDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:12 +0800 Message-Id: <20200904033538.418579-21-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--.1426S22 X-Coremail-Antispam: 1Uf129KBjvJXoW3Gr1fuFWDAF47WrW7XF1rtFb_yoWxXrW8p3 Z5J3Z0kFW8Wrn3K3yIvw4rtrs8uFykJr45KryxW3srA34UGr1fCr1furyIvF45WrW5Ar43 A3Waqrs8Gw4UJFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMSoJLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiWRmVT1f4pw-zGAAAs2 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.79 on 10.11.54.5 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.15 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/network_conf.c | 164 +--------------------------------------- src/conf/network_conf.h | 14 ++-- 2 files changed, 9 insertions(+), 169 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 910d23f..2f1a88b 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -174,32 +174,6 @@ virNetworkIPDefClear(virNetworkIPDefPtr def) } =20 =20 -static void -virNetworkDNSDefClear(virNetworkDNSDefPtr def) -{ - if (def->forwarders) { - while (def->nfwds) - virNetworkDNSForwarderClear(&def->forwarders[--def->nfwds]); - VIR_FREE(def->forwarders); - } - if (def->txts) { - while (def->ntxts) - virNetworkDNSTxtDefClear(&def->txts[--def->ntxts]); - VIR_FREE(def->txts); - } - if (def->hosts) { - while (def->nhosts) - virNetworkDNSHostDefClear(&def->hosts[--def->nhosts]); - VIR_FREE(def->hosts); - } - if (def->srvs) { - while (def->nsrvs) - virNetworkDNSSrvDefClear(&def->srvs[--def->nsrvs]); - VIR_FREE(def->srvs); - } -} - - static void virNetworkForwardDefClear(virNetworkForwardDefPtr def) { @@ -882,7 +856,7 @@ virNetworkDNSForwarderParseXMLHook(xmlNodePtr node G_GN= UC_UNUSED, } =20 =20 -static int +int virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virNetworkDNSDefPtr def, const char *networkName, @@ -907,140 +881,6 @@ virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_U= NUSED, } =20 =20 -static int -virNetworkDNSDefParseXML(const char *networkName, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - virNetworkDNSDefPtr def) -{ - g_autofree xmlNodePtr *hostNodes =3D NULL; - g_autofree xmlNodePtr *srvNodes =3D NULL; - g_autofree xmlNodePtr *txtNodes =3D NULL; - g_autofree xmlNodePtr *fwdNodes =3D NULL; - g_autofree char *forwardPlainNames =3D NULL; - g_autofree char *enable =3D NULL; - int nhosts, nsrvs, ntxts, nfwds; - size_t i; - VIR_XPATH_NODE_AUTORESTORE(ctxt) - - ctxt->node =3D node; - - enable =3D virXPathString("string(./@enable)", ctxt); - if (enable) { - def->enable =3D virTristateBoolTypeFromString(enable); - if (def->enable <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid dns enable setting '%s' " - "in network '%s'"), - enable, networkName); - return -1; - } - } - - forwardPlainNames =3D virXPathString("string(./@forwardPlainNames)", c= txt); - if (forwardPlainNames) { - def->forwardPlainNames =3D virTristateBoolTypeFromString(forwardPl= ainNames); - if (def->forwardPlainNames <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid dns forwardPlainNames setting '%s' " - "in network '%s'"), - forwardPlainNames, networkName); - return -1; - } - } - - nfwds =3D virXPathNodeSet("./forwarder", ctxt, &fwdNodes); - if (nfwds < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of ne= twork %s"), - networkName); - return -1; - } - if (nfwds > 0) { - if (VIR_ALLOC_N(def->forwarders, nfwds) < 0) - return -1; - - for (i =3D 0; i < nfwds; i++) { - if (virNetworkDNSForwarderParseXML(fwdNodes[i], - &def->forwarders[i], - networkName, - def, - NULL) < 0) - return -1; - - def->nfwds++; - } - } - - nhosts =3D virXPathNodeSet("./host", ctxt, &hostNodes); - if (nhosts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of network= %s"), - networkName); - return -1; - } - if (nhosts > 0) { - if (VIR_ALLOC_N(def->hosts, nhosts) < 0) - return -1; - - for (i =3D 0; i < nhosts; i++) { - if (virNetworkDNSHostDefParseXML(hostNodes[i], &def->hosts[def= ->nhosts], - networkName, def, NULL) < 0) { - return -1; - } - def->nhosts++; - } - } - - nsrvs =3D virXPathNodeSet("./srv", ctxt, &srvNodes); - if (nsrvs < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of network = %s"), - networkName); - return -1; - } - if (nsrvs > 0) { - if (VIR_ALLOC_N(def->srvs, nsrvs) < 0) - return -1; - - for (i =3D 0; i < nsrvs; i++) { - if (virNetworkDNSSrvDefParseXML(srvNodes[i], &def->srvs[def->n= srvs], - networkName, def, NULL) < 0) { - return -1; - } - def->nsrvs++; - } - } - - ntxts =3D virXPathNodeSet("./txt", ctxt, &txtNodes); - if (ntxts < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid element found in of network = %s"), - networkName); - return -1; - } - if (ntxts > 0) { - if (VIR_ALLOC_N(def->txts, ntxts) < 0) - return -1; - - for (i =3D 0; i < ntxts; i++) { - if (virNetworkDNSTxtDefParseXML(txtNodes[i], &def->txts[def->n= txts], - networkName, def, NULL) < 0) { - return -1; - } - def->ntxts++; - } - } - - if (virNetworkDNSDefParseXMLHook(node, def, networkName, def, NULL, - enable, forwardPlainNames, - ntxts, nhosts, nsrvs, nfwds) < 0) - return -1; - - return 0; -} - - static int virNetworkIPDefParseXML(const char *networkName, xmlNodePtr node, @@ -1812,7 +1652,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, =20 dnsNode =3D virXPathNode("./dns", ctxt); if (dnsNode !=3D NULL && - virNetworkDNSDefParseXML(def->name, dnsNode, ctxt, &def->dns) < 0)= { + virNetworkDNSDefParseXML(dnsNode, &def->dns, def->name, def, NULL)= < 0) { return NULL; } =20 diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 84b636e..45cfa4e 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -165,17 +165,17 @@ struct _virNetworkDNSForwarder { /* genparse:withh= ook, genformat */ =20 typedef struct _virNetworkDNSDef virNetworkDNSDef; typedef virNetworkDNSDef *virNetworkDNSDefPtr; -struct _virNetworkDNSDef { - int enable; /* enum virTristateBool */ - int forwardPlainNames; /* enum virTristateBool */ +struct _virNetworkDNSDef { /* genparse:withhook */ + virTristateBool enable; /* xmlattr */ + virTristateBool forwardPlainNames; /* xmlattr */ size_t ntxts; - virNetworkDNSTxtDefPtr txts; + virNetworkDNSTxtDefPtr txts; /* xmlelem, array */ size_t nhosts; - virNetworkDNSHostDefPtr hosts; + virNetworkDNSHostDefPtr hosts; /* xmlelem, array */ size_t nsrvs; - virNetworkDNSSrvDefPtr srvs; + virNetworkDNSSrvDefPtr srvs; /* xmlelem, array */ size_t nfwds; - virNetworkDNSForwarderPtr forwarders; + virNetworkDNSForwarderPtr forwarders; /* xmlelem, array:nfwds */ }; =20 typedef struct _virNetworkIPDef virNetworkIPDef; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191005; cv=none; d=zohomail.com; s=zohoarc; b=ENmelAUNw3A2SfcMzk92Nh13y//WSbTKgXmpS2qJalL0+Xb9HvDMRfSf6MwFiFafDTfgRUCS1W/V587dBdswhksNDCUrP3/+7aXtlrVisahStaVjbWyeqvWWDBzWyXqNR/ZJs91RXym8toGdPQ4bEB3MdJ4lM5tnPMWrDWA9pvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191005; 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=01bRZmZl7aKbGD7pBMDFx+OekbLhsTc++nHrN9hH5Yk=; b=C5IpRyGu24nqFdYfF8ZTI4SZV9n+jpwiJwcHgefmRt8SVBAsQ4WHZN/nThM/yIRplADQNGyydba83MKpUoEXeE201pbMEEQ/q6UDOVzkUy6CilbH5hVZhK8Yw9o8vLvbEZFGqJJ3akkl6Mu/snp3TFfJ/lmSeTCLqTsASmjem9Q= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 159919100525274.38642242887795; Thu, 3 Sep 2020 20:43:25 -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-299-FbDUTVJgO8aZLY6_QO8Wzw-1; Thu, 03 Sep 2020 23:43:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D40D8712FE; Fri, 4 Sep 2020 03:43:17 +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 E0CB47E419; Fri, 4 Sep 2020 03:43:16 +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 ABDE11826D02; Fri, 4 Sep 2020 03:43:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fEBh030745 for ; Thu, 3 Sep 2020 23:41:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 34AC3117DB03; Fri, 4 Sep 2020 03:41:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2FE2F117DB01 for ; Fri, 4 Sep 2020 03:41:14 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 140F3811E78 for ; Fri, 4 Sep 2020 03:41:11 +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-70-JoVy4TeOPlGe9pOW8ahFQQ-1; Thu, 03 Sep 2020 23:41:08 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S23; Fri, 04 Sep 2020 11:35:54 +0800 (CST) X-MC-Unique: FbDUTVJgO8aZLY6_QO8Wzw-1 X-MC-Unique: JoVy4TeOPlGe9pOW8ahFQQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 21/46] conf: Generate virNetworkDNSDefFormatBuf Date: Fri, 4 Sep 2020 11:35:13 +0800 Message-Id: <20200904033538.418579-22-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--.1426S23 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFW7CFy5ur4DKF47WF15Arb_yoWrAr4DpF nxt3WDCF4rWrnYqry2yw4fKrn8CFykJw4rGrZ7W347A3yUGr1SyFyfCFy0vF4rWryYkrW5 AF1Ygrs8J3y8GFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiThqVT1dqAj3HbAAAsn 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.3 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.11 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/network_conf.c | 77 ++--------------------------------------- src/conf/network_conf.h | 10 +++--- 2 files changed, 8 insertions(+), 79 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 2f1a88b..3a126d4 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -864,10 +864,10 @@ virNetworkDNSDefParseXMLHook(xmlNodePtr node G_GNUC_U= NUSED, void *opaque G_GNUC_UNUSED, const char *enable G_GNUC_UNUSED, const char *forwardPlainNames G_GNUC_UNUSED, + int nfwds, int ntxts, - int nhosts, int nsrvs, - int nfwds) + int nhosts) { if (def->enable =3D=3D VIR_TRISTATE_BOOL_NO && (nfwds || nhosts || nsrvs || ntxts)) { @@ -1975,77 +1975,6 @@ virNetworkDefParseNode(xmlDocPtr xml, } =20 =20 -static int -virNetworkDNSDefFormat(virBufferPtr buf, - const virNetworkDNSDef *def) -{ - size_t i; - - if (!(def->enable || def->forwardPlainNames || def->nfwds || def->nhos= ts || - def->nsrvs || def->ntxts)) - return 0; - - virBufferAddLit(buf, "enable) { - const char *fwd =3D virTristateBoolTypeToString(def->enable); - - if (!fwd) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown enable type %d in network"), - def->enable); - return -1; - } - virBufferAsprintf(buf, " enable=3D'%s'", fwd); - } - if (def->forwardPlainNames) { - const char *fwd =3D virTristateBoolTypeToString(def->forwardPlainN= ames); - - if (!fwd) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown forwardPlainNames type %d in network= "), - def->forwardPlainNames); - return -1; - } - virBufferAsprintf(buf, " forwardPlainNames=3D'%s'", fwd); - } - if (!(def->nfwds || def->nhosts || def->nsrvs || def->ntxts)) { - virBufferAddLit(buf, "/>\n"); - return 0; - } - - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - - for (i =3D 0; i < def->nfwds; i++) { - if (virNetworkDNSForwarderFormatBuf(buf, "forwarder", - &def->forwarders[i], def, NULL= ) < 0) - return -1; - } - - for (i =3D 0; i < def->ntxts; i++) { - if (virNetworkDNSTxtDefFormatBuf(buf, "txt", &def->txts[i], def, N= ULL) < 0) - return -1; - } - - for (i =3D 0; i < def->nsrvs; i++) { - if (def->srvs[i].service && def->srvs[i].protocol) { - if (virNetworkDNSSrvDefFormatBuf(buf, "srv", &def->srvs[i], de= f, NULL) < 0) - return -1; - } - } - - if (def->nhosts) { - for (i =3D 0; i < def->nhosts; i++) { - if (virNetworkDNSHostDefFormatBuf(buf, "host", &def->hosts[i],= def, NULL) < 0) - return -1; - } - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - return 0; -} - - static int virNetworkIPDefFormat(virBufferPtr buf, const virNetworkIPDef *def) @@ -2455,7 +2384,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } =20 - if (virNetworkDNSDefFormat(buf, &def->dns) < 0) + if (virNetworkDNSDefFormatBuf(buf, "dns", &def->dns, def, NULL) < 0) return -1; =20 if (virNetDevVlanFormat(&def->vlan, buf) < 0) diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 45cfa4e..60739bb 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -165,17 +165,17 @@ struct _virNetworkDNSForwarder { /* genparse:withh= ook, genformat */ =20 typedef struct _virNetworkDNSDef virNetworkDNSDef; typedef virNetworkDNSDef *virNetworkDNSDefPtr; -struct _virNetworkDNSDef { /* genparse:withhook */ +struct _virNetworkDNSDef { /* genparse:withhook, genformat */ virTristateBool enable; /* xmlattr */ virTristateBool forwardPlainNames; /* xmlattr */ + size_t nfwds; + virNetworkDNSForwarderPtr forwarders; /* xmlelem, array:nfwds */ size_t ntxts; virNetworkDNSTxtDefPtr txts; /* xmlelem, array */ - size_t nhosts; - virNetworkDNSHostDefPtr hosts; /* xmlelem, array */ size_t nsrvs; virNetworkDNSSrvDefPtr srvs; /* xmlelem, array */ - size_t nfwds; - virNetworkDNSForwarderPtr forwarders; /* xmlelem, array:nfwds */ + size_t nhosts; + virNetworkDNSHostDefPtr hosts; /* xmlelem, array */ }; =20 typedef struct _virNetworkIPDef virNetworkIPDef; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190929; cv=none; d=zohomail.com; s=zohoarc; b=BqvqqbbDVcWYKt+G1ZLS6vTYxbdvNr48wqT9fRjsnHqpAVRw9BNfHywcNecYk8BakPb+j0bdOmWwojx5Pxdr/Zj6s4zwDvPqtitzBR3GOJsN+ZOfmSqlfMKqzx2gNHJrO1EbpTrjXfNU3gHWfrUKP725Iwl5dso1dIzT1iC0VJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190929; 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=edKv48ByJXf6X2ZEGp2SIPJgiNmTqhrcc/RTXGv12Y8=; b=bViO4qV4xHjtomemfaCvWci/cdUYMHPyZ1zaLd8wKAs85EF1A81k2Vkkbj7yJsCY/D+u4WqEGjNXrn5plSECBfIfTTbo7/daMnhT4a/ksM+kcmDrtixUFfBE7HhhAfkIk5y1BVDVZAfJfYvul8TTzCTbv6Bv79dGy/zGgdHw9xo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190929036151.75936349073208; Thu, 3 Sep 2020 20:42:09 -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-508-J3u86wncOPWVOWwLJ_3Oyg-1; Thu, 03 Sep 2020 23:41:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0795585EE95; Fri, 4 Sep 2020 03:41:45 +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 D9AD57EED2; Fri, 4 Sep 2020 03:41:44 +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 A4A0B972E9; Fri, 4 Sep 2020 03:41:44 +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 0843fAPY030570 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD8812157F26; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2CD32157F45 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 9BED1101A53F for ; Fri, 4 Sep 2020 03:41:07 +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-359-vrWcSi-2NnGlduyZXNoMRA-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S24; Fri, 04 Sep 2020 11:35:54 +0800 (CST) X-MC-Unique: J3u86wncOPWVOWwLJ_3Oyg-1 X-MC-Unique: vrWcSi-2NnGlduyZXNoMRA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 22/46] conf: Extract embedded structs from virDomainGraphicsDef as standalone structs Date: Fri, 4 Sep 2020 11:35:14 +0800 Message-Id: <20200904033538.418579-23-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--.1426S24 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw1fAw17Wr4DKFW7ZFW3Awb_yoWrtF1UpF 9xZFW5KF48Xr43Gw48Wa1Uur47KFykGr1DJr1qvw1jqFWUJr4DAa4YqFn2v3WYkFsrZFyr uFZ3t3WUXF4xAFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMq2NLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiHxqVT1uyHTnxFAAAs3 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.79 on 10.5.11.13 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" Extract those embedded structs from virDomainGraphicsDef so that we can specify directives on them. Signed-off-by: Shi Lei --- src/conf/domain_conf.h | 112 ++++++++++++++++++++++------------------ src/conf/virconftypes.h | 18 +++++++ 2 files changed, 80 insertions(+), 50 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 14a3763..3d14aa1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1672,6 +1672,62 @@ struct _virDomainGraphicsListenDef { bool autoGenerated; }; =20 +struct _virDomainGraphicsSDLDef { + char *display; + char *xauth; + bool fullscreen; + virTristateBool gl; +}; + +struct _virDomainGraphicsVNCDef { + int port; + bool portReserved; + int websocket; + bool websocketGenerated; + bool autoport; + char *keymap; + virDomainGraphicsAuthDef auth; + int sharePolicy; +}; + +struct _virDomainGraphicsRDPDef { + int port; + bool autoport; + bool replaceUser; + bool multiUser; +}; + +struct _virDomainGraphicsDesktopDef { + char *display; + bool fullscreen; +}; + +struct _virDomainGraphicsSpiceDef { + int port; + int tlsPort; + bool portReserved; + bool tlsPortReserved; + virDomainGraphicsSpiceMouseMode mousemode; + char *keymap; + virDomainGraphicsAuthDef auth; + bool autoport; + int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST]; + virDomainGraphicsSpiceChannelMode defaultMode; + int image; + int jpeg; + int zlib; + int playback; + int streaming; + virTristateBool copypaste; + virTristateBool filetransfer; + virTristateBool gl; + char *rendernode; +}; + +struct _virDomainGraphicsEGLHeadlessDef { + char *rendernode; +}; + struct _virDomainGraphicsDef { virObjectPtr privateData; =20 @@ -1682,56 +1738,12 @@ struct _virDomainGraphicsDef { */ virDomainGraphicsType type; union { - struct { - int port; - bool portReserved; - int websocket; - bool websocketGenerated; - bool autoport; - char *keymap; - virDomainGraphicsAuthDef auth; - int sharePolicy; - } vnc; - struct { - char *display; - char *xauth; - bool fullscreen; - virTristateBool gl; - } sdl; - struct { - int port; - bool autoport; - bool replaceUser; - bool multiUser; - } rdp; - struct { - char *display; - bool fullscreen; - } desktop; - struct { - int port; - int tlsPort; - bool portReserved; - bool tlsPortReserved; - virDomainGraphicsSpiceMouseMode mousemode; - char *keymap; - virDomainGraphicsAuthDef auth; - bool autoport; - int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST]; - virDomainGraphicsSpiceChannelMode defaultMode; - int image; - int jpeg; - int zlib; - int playback; - int streaming; - virTristateBool copypaste; - virTristateBool filetransfer; - virTristateBool gl; - char *rendernode; - } spice; - struct { - char *rendernode; - } egl_headless; + virDomainGraphicsSDLDef sdl; + virDomainGraphicsVNCDef vnc; + virDomainGraphicsRDPDef rdp; + virDomainGraphicsDesktopDef desktop; + virDomainGraphicsSpiceDef spice; + virDomainGraphicsEGLHeadlessDef egl_headless; } data; /* nListens, listens, and *port are only useful if type is vnc, * rdp, or spice. They've been extracted from the union only to diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index 9042a2b..ae7c18d 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -362,3 +362,21 @@ typedef virDomainXMLPrivateDataCallbacks *virDomainXML= PrivateDataCallbacksPtr; =20 typedef struct _virDomainXenbusControllerOpts virDomainXenbusControllerOpt= s; typedef virDomainXenbusControllerOpts *virDomainXenbusControllerOptsPtr; + +typedef struct _virDomainGraphicsSDLDef virDomainGraphicsSDLDef; +typedef virDomainGraphicsSDLDef *virDomainGraphicsSDLDefPtr; + +typedef struct _virDomainGraphicsVNCDef virDomainGraphicsVNCDef; +typedef virDomainGraphicsVNCDef *virDomainGraphicsVNCDefPtr; + +typedef struct _virDomainGraphicsRDPDef virDomainGraphicsRDPDef; +typedef virDomainGraphicsRDPDef *virDomainGraphicsRDPDefPtr; + +typedef struct _virDomainGraphicsDesktopDef virDomainGraphicsDesktopDef; +typedef virDomainGraphicsDesktopDef *virDomainGraphicsDesktopDefPtr; + +typedef struct _virDomainGraphicsSpiceDef virDomainGraphicsSpiceDef; +typedef virDomainGraphicsSpiceDef *virDomainGraphicsSpiceDefPtr; + +typedef struct _virDomainGraphicsEGLHeadlessDef virDomainGraphicsEGLHeadle= ssDef; +typedef virDomainGraphicsEGLHeadlessDef *virDomainGraphicsEGLHeadlessDefPt= r; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190931; cv=none; d=zohomail.com; s=zohoarc; b=MRaKoGizg3ryQTIOp4UbL/s3w+sW0wlT3+2JEY03VdU4kr84qTpieRcqaqZH/FZYc4EMMVtER3hCHVHCVhBEtnhGjV9/9Moqu/3BMzgmQWODnCZ6LvbYh/ylgfWsjOCIMqzFtQUqqGe4q9VWhyMICXJgf/RZ9BA/vUZ76Yqmf1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190931; 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=A5xur7jZCrsqNId9Da9n96us8JP8C5fkf+iEpLSoQdI=; b=jWcagn4GviqWj6TkuuKdbH+pkpkAc2DhzpA6xjSnVEvdTu6ULm+8GgHHvhXIfT8VZqOKb7X57d25Aijo7UT5HG9FxIeLomqgXpxyoiFVGgBm2t2Swgyn0VqbUSuLYDS+1NSrfwA/UWop1F7yullzgseNc21sA4++AultQzH+Z8M= 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 1599190931616728.6737572155359; Thu, 3 Sep 2020 20:42:11 -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-161-V4RHXwixM_WwlsotvAOWEw-1; Thu, 03 Sep 2020 23:42:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D5CEC189E60A; Fri, 4 Sep 2020 03:42:03 +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 B78CF5D9DC; Fri, 4 Sep 2020 03:42:03 +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 88B6897303; Fri, 4 Sep 2020 03:42:03 +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 0843fABw030571 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C0D102157F45; Fri, 4 Sep 2020 03:41:09 +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 B64922157F4A for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 AC078800CAF for ; Fri, 4 Sep 2020 03:41:07 +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-575-MfoNm7JNOuunBIrlCGRkNw-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S25; Fri, 04 Sep 2020 11:35:54 +0800 (CST) X-MC-Unique: V4RHXwixM_WwlsotvAOWEw-1 X-MC-Unique: MfoNm7JNOuunBIrlCGRkNw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 23/46] conf: Replace virDomainGraphicsDefParseXMLSDL(hardcoded) with virDomainGraphicsSDLDefParseXML(generated) Date: Fri, 4 Sep 2020 11:35:15 +0800 Message-Id: <20200904033538.418579-24-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--.1426S25 X-Coremail-Antispam: 1Uf129KBjvJXoWxCFWrKryUAr1UZrW3urWrAFb_yoWrArW7pF n3W3Wayr48XFyfGayDKa4j9r4jk3yDWr4UGws5uanFqw1UZr4kCw1xZFn7XFyjgrWDZFWf AFySqayY9F4UArDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiWxqVT1f4pvfYVgAAsr 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.79 on 10.5.11.14 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 --- po/POTFILES.in | 1 + src/conf/domain_conf.c | 53 ++---------------------------------------- src/conf/domain_conf.h | 12 ++++++---- src/conf/meson.build | 1 + 4 files changed, 11 insertions(+), 56 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 0356f1e..4de0d14 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -3,6 +3,7 @@ @BUILDDIR@src/access/viraccessapicheckqemu.c @BUILDDIR@src/admin/admin_client.h @BUILDDIR@src/admin/admin_server_dispatch_stubs.h +@BUILDDIR@src/conf/domain_conf.generated.c @BUILDDIR@src/conf/network_conf.generated.c @BUILDDIR@src/remote/remote_client_bodies.h @BUILDDIR@src/remote/remote_daemon_dispatch_stubs.h diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 72ac4f4..c1f8847 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1826,8 +1826,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr= def) break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SDL: - VIR_FREE(def->data.sdl.display); - VIR_FREE(def->data.sdl.xauth); + virDomainGraphicsSDLDefClear(&def->data.sdl); break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_RDP: @@ -14514,54 +14513,6 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsD= efPtr def, } =20 =20 -static int -virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDefPtr def, - xmlNodePtr node, - xmlXPathContextPtr ctxt) -{ - VIR_XPATH_NODE_AUTORESTORE(ctxt) - int enableVal; - xmlNodePtr glNode; - g_autofree char *fullscreen =3D virXMLPropString(node, "fullscreen"); - g_autofree char *enable =3D NULL; - - ctxt->node =3D node; - - if (fullscreen !=3D NULL) { - if (virStringParseYesNo(fullscreen, &def->data.sdl.fullscreen) < 0= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown fullscreen value '%s'"), fullscreen); - return -1; - } - } else { - def->data.sdl.fullscreen =3D false; - } - - def->data.sdl.xauth =3D virXMLPropString(node, "xauth"); - def->data.sdl.display =3D virXMLPropString(node, "display"); - - glNode =3D virXPathNode("./gl", ctxt); - if (glNode) { - enable =3D virXMLPropString(glNode, "enable"); - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("sdl gl element missing enable")); - return -1; - } - - enableVal =3D virTristateBoolTypeFromString(enable); - if (enableVal < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } - def->data.sdl.gl =3D enableVal; - } - - return 0; -} - - static int virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, xmlNodePtr node, @@ -14990,7 +14941,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SDL: - if (virDomainGraphicsDefParseXMLSDL(def, node, ctxt) < 0) + if (virDomainGraphicsSDLDefParseXML(node, &def->data.sdl, NULL, de= f, NULL) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3d14aa1..13d2d4f 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1672,11 +1672,11 @@ struct _virDomainGraphicsListenDef { bool autoGenerated; }; =20 -struct _virDomainGraphicsSDLDef { - char *display; - char *xauth; - bool fullscreen; - virTristateBool gl; +struct _virDomainGraphicsSDLDef { /* genparse */ + char *display; /* xmlattr */ + char *xauth; /* xmlattr */ + bool fullscreen; /* xmlattr */ + virTristateBool gl; /* xmlattr:gl/enable */ }; =20 struct _virDomainGraphicsVNCDef { @@ -3916,3 +3916,5 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hos= tdev) bool virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); + +#include "domain_conf.generated.h" diff --git a/src/conf/meson.build b/src/conf/meson.build index 0619ca6..2796520 100644 --- a/src/conf/meson.build +++ b/src/conf/meson.build @@ -1,5 +1,6 @@ xmlgen_input =3D [ 'network_conf.h', + 'domain_conf.h', ] =20 xmlgen_output =3D [] --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191210; cv=none; d=zohomail.com; s=zohoarc; b=KM2ZJsLJbGL6AigMGmC0Dcz5dbe2Nzd8YV+W0Ov6jSt/UNvoMn8ooXhDKT7xNNmq6pp5yzjWD7Ht94VnlzC+Kdlw56Djmr6WnE0YFo2Ck5mdKxHY3sNMUxV3SdoU8QxIFizCBTwRorwB8ZLbigmdBOMZh+YR5exyXXRPpur8bCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191210; 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=JpnQmjieMJG3pkm9Lo20MrED2fM6C44Ba3LbuyPtC2M=; b=e7ARn8yXPX7FiDZDvv5YVje7kg+AXFi0rFVZVb+vetslV9XTUjoXPVEUct9TeAXjx7UqgykH4pAySNpvNebGhm5FreYPJYxjiJBfORQkuRWwjXvvfpost4Cgomj8GI4pEOov8aIslayG2QJTT6wgha6Rb6HHhqAwZkg9KhwiJpE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599191210774277.15511551156953; Thu, 3 Sep 2020 20:46:50 -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-246-06vE7AwiMwWfgez1uOOg_g-1; Thu, 03 Sep 2020 23:46:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E8361DDE8; Fri, 4 Sep 2020 03:46:40 +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 3E0B18118A; Fri, 4 Sep 2020 03:46:40 +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 B1BED1832FB6; Fri, 4 Sep 2020 03:46:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843kcx3032369 for ; Thu, 3 Sep 2020 23:46:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6040A202450A; Fri, 4 Sep 2020 03:46:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A379200AE6D for ; Fri, 4 Sep 2020 03:46:35 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 49C65185A78B for ; Fri, 4 Sep 2020 03:46:35 +0000 (UTC) Received: from mail-proxy25223.qiye.163.com (mail-proxy25223.qiye.163.com [103.129.252.23]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-398-2muEyAVUN2iAA_citFkFpg-1; Thu, 03 Sep 2020 23:46:32 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S26; Fri, 04 Sep 2020 11:35:54 +0800 (CST) X-MC-Unique: 06vE7AwiMwWfgez1uOOg_g-1 X-MC-Unique: 2muEyAVUN2iAA_citFkFpg-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 24/46] conf: Generate format functions for virDomainGraphicsSDLDef Date: Fri, 4 Sep 2020 11:35:16 +0800 Message-Id: <20200904033538.418579-25-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--.1426S26 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4iuc_oDUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiih+VT1tVhJllZAAAsd 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.4 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.15 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 | 20 +++++--------------- src/conf/domain_conf.h | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c1f8847..544b984 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28266,27 +28266,17 @@ virDomainGraphicsDefFormat(virBufferPtr buf, break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SDL: - if (def->data.sdl.display) - virBufferEscapeString(buf, " display=3D'%s'", - def->data.sdl.display); - - if (def->data.sdl.xauth) - virBufferEscapeString(buf, " xauth=3D'%s'", - def->data.sdl.xauth); - if (def->data.sdl.fullscreen) - virBufferAddLit(buf, " fullscreen=3D'yes'"); + if (virDomainGraphicsSDLDefFormatAttr(buf, &def->data.sdl, def, NU= LL) < 0) + return -1; =20 - if (!children && def->data.sdl.gl !=3D VIR_TRISTATE_BOOL_ABSENT) { + if (!children && virDomainGraphicsSDLDefCheckElem(&def->data.sdl, = def, NULL)) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); children =3D true; } =20 - if (def->data.sdl.gl !=3D VIR_TRISTATE_BOOL_ABSENT) { - virBufferAsprintf(buf, "data.sdl.gl= )); - virBufferAddLit(buf, "/>\n"); - } + if (virDomainGraphicsSDLDefFormatElem(buf, &def->data.sdl, def, NU= LL) < 0) + return -1; =20 break; =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 13d2d4f..e64a284 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1672,7 +1672,7 @@ struct _virDomainGraphicsListenDef { bool autoGenerated; }; =20 -struct _virDomainGraphicsSDLDef { /* genparse */ +struct _virDomainGraphicsSDLDef { /* genparse, genformat:separate */ char *display; /* xmlattr */ char *xauth; /* xmlattr */ bool fullscreen; /* xmlattr */ --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190929; cv=none; d=zohomail.com; s=zohoarc; b=m7EdYZBqFLstPI3cezVSQWNQ5MegBcv4Ih0RCnGtgjPY/Hswue+kf76PHZeE1Vin7ftB2T6h82r789qoJxWXPBUy1mt7VnydV94QnuV6zryVp0lPeooOY1xadbmywkUXzhGBh+ZCCLr9JKaPvXsESZrPOUecxfc8+nOAyHx9rAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190929; 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=z2OP2WbAg1y9nYkKKuxr0LoCA5geWGNCWabxBKVY588=; b=gK+y9BIEW5R6YNK2Vi14rdYO0wGGh9jRyWWhxhlWmNUXvAGTBSZMrH7tC96e2VcJX0yjdkZsfZY4RLUflfHgT6QfuYyDUH9XjDFOdz+mWQGGlbtennT2dx/bzHkKNW+ztYwClCFfYhr7fkgAiiOud7pSQfLR5O9HUqwkJA9KpFE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1599190929837526.1800527996245; Thu, 3 Sep 2020 20:42:09 -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-518-yvsVlXDoPh2DtW_k7ZrHVg-1; Thu, 03 Sep 2020 23:41:59 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 500A62FD05; Fri, 4 Sep 2020 03:41:52 +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 2D0335D9DC; Fri, 4 Sep 2020 03:41:52 +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 EBD74181A272; Fri, 4 Sep 2020 03:41:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBbX030652 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2456110379C; 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 172691037B7 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 ABE2E800969 for ; Fri, 4 Sep 2020 03:41:07 +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-405-HzKyQSA6M92U--msd2zQDA-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S27; Fri, 04 Sep 2020 11:35:55 +0800 (CST) X-MC-Unique: yvsVlXDoPh2DtW_k7ZrHVg-1 X-MC-Unique: HzKyQSA6M92U--msd2zQDA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 25/46] conf: Replace virDomainGraphicsAuthDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:17 +0800 Message-Id: <20200904033538.418579-26-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--.1426S27 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr48tw4fZrW3ZF17tFy7Jrb_yoWrtr17pa 13Zrs3ArWFqr43W3yv93Wq9wsF9F1kJr47Awn3uw4DAFyUGw4vyr1rJr1q934UKr95ZrW3 AFWSqa1YqF4vy37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiTxuVT1f4qM1mUgAAsw 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.79 on 10.11.54.5 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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.003 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 | 92 +++++------------------------------------- src/conf/domain_conf.h | 13 +++--- 2 files changed, 18 insertions(+), 87 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 544b984..1fd2a06 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1788,17 +1788,6 @@ bool virDomainObjTaint(virDomainObjPtr obj, } =20 =20 -static void -virDomainGraphicsAuthDefClear(virDomainGraphicsAuthDefPtr def) -{ - if (!def) - return; - - VIR_FREE(def->passwd); - - /* Don't free def */ -} - static void virDomainGraphicsListenDefClear(virDomainGraphicsListenDefPtr def) { @@ -14129,75 +14118,6 @@ virDomainTimerDefParseXML(xmlNodePtr node, } =20 =20 -static int -virDomainGraphicsAuthDefParseXML(xmlNodePtr node, - virDomainGraphicsAuthDefPtr def, - int type) -{ - g_autofree char *validTo =3D NULL; - g_autofree char *connected =3D virXMLPropString(node, "connected"); - - def->passwd =3D virXMLPropString(node, "passwd"); - - if (!def->passwd) - return 0; - - validTo =3D virXMLPropString(node, "passwdValidTo"); - if (validTo) { - g_autoptr(GDateTime) then =3D NULL; - g_autoptr(GTimeZone) tz =3D g_time_zone_new_utc(); - char *tmp; - int year, mon, mday, hour, min, sec; - - /* Expect: YYYY-MM-DDTHH:MM:SS (%d-%d-%dT%d:%d:%d) eg 2010-11-28T= 14:29:01 */ - if (/* year */ - virStrToLong_i(validTo, &tmp, 10, &year) < 0 || *tmp !=3D '-' = || - /* month */ - virStrToLong_i(tmp+1, &tmp, 10, &mon) < 0 || *tmp !=3D '-' || - /* day */ - virStrToLong_i(tmp+1, &tmp, 10, &mday) < 0 || *tmp !=3D 'T' || - /* hour */ - virStrToLong_i(tmp+1, &tmp, 10, &hour) < 0 || *tmp !=3D ':' || - /* minute */ - virStrToLong_i(tmp+1, &tmp, 10, &min) < 0 || *tmp !=3D ':' || - /* second */ - virStrToLong_i(tmp+1, &tmp, 10, &sec) < 0 || *tmp !=3D '\0') { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse password validity time '%s', ex= pect YYYY-MM-DDTHH:MM:SS"), - validTo); - VIR_FREE(def->passwd); - return -1; - } - - then =3D g_date_time_new(tz, year, mon, mday, hour, min, sec); - def->validTo =3D (time_t)g_date_time_to_unix(then); - def->expires =3D true; - } - - if (connected) { - int action =3D virDomainGraphicsAuthConnectedTypeFromString(connec= ted); - if (action <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown connected value %s"), - connected); - return -1; - } - - /* VNC supports connected=3D'keep' only */ - if (type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC && - action !=3D VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_KEEP) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("VNC supports connected=3D'keep' only")); - return -1; - } - - def->connected =3D action; - } - - return 0; -} - - /** * virDomainGraphicsListenDefParseXML: * @def: listen def pointer to be filled @@ -14506,9 +14426,17 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsD= efPtr def, def->data.vnc.keymap =3D virXMLPropString(node, "keymap"); =20 if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, - def->type) < 0) + NULL, def, NULL) < 0) return -1; =20 + /* VNC supports connected=3D'keep' only */ + if (def->data.vnc.auth.connected && + def->data.vnc.auth.connected !=3D VIR_DOMAIN_GRAPHICS_AUTH_CONNECT= ED_KEEP) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("VNC supports connected=3D'keep' only")); + return -1; + } + return 0; } =20 @@ -14644,7 +14572,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphics= DefPtr def, def->data.spice.keymap =3D virXMLPropString(node, "keymap"); =20 if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, - def->type) < 0) + NULL, def, NULL) < 0) return -1; =20 cur =3D node->children; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e64a284..616cbf4 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1573,11 +1573,14 @@ typedef enum { VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_LAST } virDomainGraphicsAuthConnectedType; =20 -struct _virDomainGraphicsAuthDef { - char *passwd; - bool expires; /* Whether there is an expiry time set */ - time_t validTo; /* seconds since epoch */ - int connected; /* action if connected */ +struct _virDomainGraphicsAuthDef { /* genparse */ + char *passwd; /* xmlattr */ + /* Whether there is an expiry time set */ + bool expires; + /* seconds since epoch */ + time_t validTo; /* xmlattr:passwdValidTo, specified:ex= pires */ + /* action if connected */ + virDomainGraphicsAuthConnectedType connected; /* xmlattr */ }; =20 typedef enum { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190934; cv=none; d=zohomail.com; s=zohoarc; b=RL2PUeUFqZHLzQt2Z2j13Dr+FL7arBnXonc//hPTInAcEkEqUlIuhC9+RlhnJtO9e7vDS71YOEyupG2hDZB2E0luweUtRKAdMA6ACb2+0gx3nIiWsPWIfpUbDwb67BmjrjYMYHR6w1iHT0v7NhqNxAux3/ld7f1aNEP2HcIHTA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190934; 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=XhMuqQzOrl1Nczr+CdDrge1W04Fdizgqvw4T90oXBMg=; b=CzQ+sycGoTri/T72GxeUXb6jOEmrt5cDxfUKQKAuFPK/B8wMnvLG67mGiNBgsnswuWRQ8SuEOJSUR0hO8OOO/yuglu7Or+Un8hvgJjs1zvuCNzvFI44aMlrPGGtWqa9ntKXxYQ2SjnXRmfwNMgP+PUJtCUvnJL6wPfOtzgceIw8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599190934355284.3710601988208; Thu, 3 Sep 2020 20:42:14 -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-357--TCdr8ZeOweVkccFkX3Uuw-1; Thu, 03 Sep 2020 23:42:11 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 389108712F6; Fri, 4 Sep 2020 03:42:06 +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 181965D9DC; Fri, 4 Sep 2020 03:42:06 +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 D8E32181A86E; Fri, 4 Sep 2020 03:42:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAkv030590 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id CB1E820235B9; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0BF1202451D for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 7E36180121F for ; Fri, 4 Sep 2020 03:41:08 +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-433-liuYVyAeO86NuOp95-1rgw-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S28; Fri, 04 Sep 2020 11:35:55 +0800 (CST) X-MC-Unique: -TCdr8ZeOweVkccFkX3Uuw-1 X-MC-Unique: liuYVyAeO86NuOp95-1rgw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 26/46] conf: Generate format functions for virDomainGraphicsAuthDef Date: Fri, 4 Sep 2020 11:35:18 +0800 Message-Id: <20200904033538.418579-27-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--.1426S28 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr47Xry5Zry3JF1rAr1kKrg_yoW5XF1UpF 13ZFZrCFs5Xr43Gw4qga90g39F9FyDCr47CrsIgw4UW3yUJr4kZa4xXry0vr1j9rZ3ZryF yFWSqa18Xa1kK37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zMSoJLUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiEBuVT1nxrfy0YAAAs8 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.4 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.14 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 | 30 ++---------------------------- src/conf/domain_conf.h | 4 ++-- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1fd2a06..be07b40 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28000,32 +28000,6 @@ virDomainTimerDefFormat(virBufferPtr buf, return 0; } =20 -static void -virDomainGraphicsAuthDefFormatAttr(virBufferPtr buf, - virDomainGraphicsAuthDefPtr def, - unsigned int flags) -{ - if (!def->passwd) - return; - - if (flags & VIR_DOMAIN_DEF_FORMAT_SECURE) - virBufferEscapeString(buf, " passwd=3D'%s'", - def->passwd); - - if (def->expires) { - g_autoptr(GDateTime) then =3D NULL; - g_autofree char *thenstr =3D NULL; - - then =3D g_date_time_new_from_unix_utc(def->validTo); - thenstr =3D g_date_time_format(then, "%Y-%m-%dT%H:%M:%S"); - virBufferAsprintf(buf, " passwdValidTo=3D'%s'", thenstr); - } - - if (def->connected) - virBufferEscapeString(buf, " connected=3D'%s'", - virDomainGraphicsAuthConnectedTypeToString(d= ef->connected)); -} - =20 static void virDomainGraphicsListenDefFormat(virBufferPtr buf, @@ -28190,7 +28164,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virDomainGraphicsVNCSharePolicyTypeToString( def->data.vnc.sharePolicy)); =20 - virDomainGraphicsAuthDefFormatAttr(buf, &def->data.vnc.auth, flags= ); + virDomainGraphicsAuthDefFormatAttr(buf, &def->data.vnc.auth, def, = &flags); break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SDL: @@ -28292,7 +28266,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " defaultMode=3D'%s'", virDomainGraphicsSpiceChannelModeTypeToString(def->data.spic= e.defaultMode)); =20 - virDomainGraphicsAuthDefFormatAttr(buf, &def->data.spice.auth, fla= gs); + virDomainGraphicsAuthDefFormatAttr(buf, &def->data.spice.auth, def= , &flags); break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 616cbf4..9724b02 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1573,8 +1573,8 @@ typedef enum { VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_LAST } virDomainGraphicsAuthConnectedType; =20 -struct _virDomainGraphicsAuthDef { /* genparse */ - char *passwd; /* xmlattr */ +struct _virDomainGraphicsAuthDef { /* genparse, genformat:separate */ + char *passwd; /* xmlattr, formatflag:VIR_DOMAIN_DEF_= FORMAT_SECURE */ /* Whether there is an expiry time set */ bool expires; /* seconds since epoch */ --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190941; cv=none; d=zohomail.com; s=zohoarc; b=lNqGGQhZbsR4QtsF0brj5mB3lpswhtAP2lhx2pLDJ2I+Bvkh5oGP5OJwvlqlM5F8OioLudz7vtLJS+Szv4CMsxQjHVmwR+tAeauRQyN74CYvk28I1cNTX7CeW4/oE1+cRaUt68eqx/ytRvSpyHDNek0Vg6F/OzakTLtYkywEi1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190941; 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=7l5n9iRoht5BXaoch4XP9rjLyzNFCTVIkCPMuN9yTYc=; b=K1pUMvTsFzFPmFYOWaV10rj19VIFi4+PRziiGDEap9eYcLOA+LeIVkJ5IvOgup6q39Jpi2/4XtkiVZIHCf/LnqWxsOTs8/Lg/810ER59nNDduSSwVf6652LcnM+4jN0c3fzoqABtYZlohrcRw0pYOb9UbDd6A7ipzAR88nA3IBI= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599190941446751.2062116932067; Thu, 3 Sep 2020 20:42:21 -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-65-89GrzH4hPpqnraqzrCNOQA-1; Thu, 03 Sep 2020 23:42:19 -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 5B19A800462; Fri, 4 Sep 2020 03:42:13 +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 390261A7C8; Fri, 4 Sep 2020 03:42:13 +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 05274181A894; Fri, 4 Sep 2020 03:42:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBRY030648 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21FE0103791; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1602C1037A0 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 39EBE80118B for ; Fri, 4 Sep 2020 03:41:08 +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-56-TEx1HvU4Pfu2PL2ihdEblw-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S29; Fri, 04 Sep 2020 11:35:55 +0800 (CST) X-MC-Unique: 89GrzH4hPpqnraqzrCNOQA-1 X-MC-Unique: TEx1HvU4Pfu2PL2ihdEblw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 27/46] conf: Extract error-checking code from virDomainGraphicsDefParseXMLVNC Date: Fri, 4 Sep 2020 11:35:19 +0800 Message-Id: <20200904033538.418579-28-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--.1426S29 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr47JF13Ar13Kw15Ww45Wrg_yoWrXF13pF s3XFZ8tFWYqrnxC392gan8uws0kF1kJwsrJrWfZ34DXrW5Grs5Aw4FqF1qgw1jkr97ZrW3 AF48KFWjgF4DZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEdcTPUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiQxuVT1bdHJ2LGwAAsY 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.79 on 10.11.54.5 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 | 77 +++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index be07b40..aedf278 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14356,10 +14356,55 @@ virDomainGraphicsListensParseXML(virDomainGraphic= sDefPtr def, } =20 =20 +static int +virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virDomainGraphicsVNCDefPtr def, + const char *instname G_GNUC_UNUSED, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *port, + const char *websocket G_GNUC_UNUSED, + const char *websocketGenerated G_GNUC_= UNUSED, + const char *autoport, + const char *sharePolicy G_GNUC_UNUSED) +{ + unsigned int flags =3D *((unsigned int *) opaque); + + /* Legacy compat syntax, used -1 for auto-port */ + if (port) { + if (def->port =3D=3D -1) { + if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) + def->port =3D 0; + if (autoport =3D=3D NULL) + def->autoport =3D true; + } + } else { + def->port =3D 0; + if (autoport =3D=3D NULL) + def->autoport =3D true; + } + + if (autoport) { + if (def->autoport && flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) + def->port =3D 0; + } + + /* VNC supports connected=3D'keep' only */ + if (def->auth.connected && + def->auth.connected !=3D VIR_DOMAIN_GRAPHICS_AUTH_CONNECTED_KEEP) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("VNC supports connected=3D'keep' only")); + return -1; + } + + return 0; +} + + static int virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, xmlNodePtr node, - xmlXPathContextPtr ctxt, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, unsigned int flags) { g_autofree char *port =3D virXMLPropString(node, "port"); @@ -14368,33 +14413,17 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphics= DefPtr def, g_autofree char *sharePolicy =3D virXMLPropString(node, "sharePolicy"); g_autofree char *autoport =3D virXMLPropString(node, "autoport"); =20 - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - return -1; - if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc port %s"), port); return -1; } - /* Legacy compat syntax, used -1 for auto-port */ - if (def->data.vnc.port =3D=3D -1) { - if (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) - def->data.vnc.port =3D 0; - def->data.vnc.autoport =3D true; - } - } else { - def->data.vnc.port =3D 0; - def->data.vnc.autoport =3D true; } =20 - if (autoport) { + if (autoport) ignore_value(virStringParseYesNo(autoport, &def->data.vnc.autoport= )); =20 - if (def->data.vnc.autoport && flags & VIR_DOMAIN_DEF_PARSE_INACTIV= E) - def->data.vnc.port =3D 0; - } - if (websocket) { if (virStrToLong_i(websocket, NULL, 10, @@ -14429,13 +14458,11 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphics= DefPtr def, NULL, def, NULL) < 0) return -1; =20 - /* VNC supports connected=3D'keep' only */ - if (def->data.vnc.auth.connected && - def->data.vnc.auth.connected !=3D VIR_DOMAIN_GRAPHICS_AUTH_CONNECT= ED_KEEP) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("VNC supports connected=3D'keep' only")); + if (virDomainGraphicsVNCDefParseXMLHook(node, &def->data.vnc, NULL, de= f, &flags, + port, websocket, + websocketGenerated, autoport, + sharePolicy) < 0) return -1; - } =20 return 0; } @@ -14867,6 +14894,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, case VIR_DOMAIN_GRAPHICS_TYPE_VNC: if (virDomainGraphicsDefParseXMLVNC(def, node, ctxt, 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) --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190907; cv=none; d=zohomail.com; s=zohoarc; b=LhyKPGrsi+sol+iOsL+uHSZsFyVw7UbcHIv6a5/VUGPziKQiIMaMjnBoPyEx0urZ6q6TBBuEg3ZkTPnyJ8opv/i+85kqNPvyauZTBOBl3aOE2zrMjuiWoYsdOer/mtb+TGrzQuoTz18aaIn+CYel6x2J9MWt4M1EiY6v/XNxwHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190907; 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=mDIlY3aEj1LE25cgzvJylaIscuJv3BolEdnkxe030bA=; b=G5ORpBabATscJxi+HoLXn5CRf4tvUFZabru+lWdfurobSJlc2xNA9CxRoYHgRtfIujaVB5+pS4wdbzaGV9n80k3Q0XBXlI4CeRRepUzUsGY/ut29rFxdM/zFFOp9taeRdOPkHifvSYXIgDdTJgb6FhasRxotmIsMlrldXsb08uk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1599190907767114.27684487728288; Thu, 3 Sep 2020 20:41:47 -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-218-FH3ZFFZAN-64xz3uq02hHQ-1; Thu, 03 Sep 2020 23:41:45 -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 B44E21084C80; Fri, 4 Sep 2020 03:41:39 +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 91E961002D5E; Fri, 4 Sep 2020 03:41:39 +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 5F9E8180B65D; Fri, 4 Sep 2020 03:41:39 +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 0843f9gL030556 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id B73072157F4B; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD7772157F23 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 B4270811E79 for ; Fri, 4 Sep 2020 03:41:07 +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-359-iMrISobINcSxWngFs2wuNA-1; Thu, 03 Sep 2020 23:41:04 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S30; Fri, 04 Sep 2020 11:35:55 +0800 (CST) X-MC-Unique: FH3ZFFZAN-64xz3uq02hHQ-1 X-MC-Unique: iMrISobINcSxWngFs2wuNA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 28/46] conf: Replace virDomainGraphicsDefParseXMLVNC(hardcoded) with virDomainGraphicsVNCDefParseXML(generated) Date: Fri, 4 Sep 2020 11:35:20 +0800 Message-Id: <20200904033538.418579-29-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--.1426S30 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr47GF13CF17XFWkKr1xXwb_yoWrWFykpF s3XF1fCrWFqrs5G3yv9a15uwsFkFyDGw47J348uw1UXrWUWrs5Cw1fZr1Ig3yUKrWIvFWf uFWSqr4jgF48AFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiSxuVT1dqAiiJlgAAsC 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.22 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 | 71 ++---------------------------------------- src/conf/domain_conf.h | 16 +++++----- 2 files changed, 10 insertions(+), 77 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index aedf278..54b4da9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14356,7 +14356,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, } =20 =20 -static int +int virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virDomainGraphicsVNCDefPtr def, const char *instname G_GNUC_UNUSED, @@ -14401,73 +14401,6 @@ virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr nod= e G_GNUC_UNUSED, } =20 =20 -static int -virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def, - xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, - unsigned int flags) -{ - g_autofree char *port =3D virXMLPropString(node, "port"); - g_autofree char *websocket =3D virXMLPropString(node, "websocket"); - g_autofree char *websocketGenerated =3D virXMLPropString(node, "websoc= ketGenerated"); - g_autofree char *sharePolicy =3D virXMLPropString(node, "sharePolicy"); - g_autofree char *autoport =3D virXMLPropString(node, "autoport"); - - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vnc port %s"), port); - return -1; - } - } - - if (autoport) - ignore_value(virStringParseYesNo(autoport, &def->data.vnc.autoport= )); - - if (websocket) { - if (virStrToLong_i(websocket, - NULL, 10, - &def->data.vnc.websocket) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse vnc WebSocket port %s"), websoc= ket); - return -1; - } - } - - if (websocketGenerated) - ignore_value(virStringParseYesNo(websocketGenerated, - &def->data.vnc.websocketGenerated)); - - if (sharePolicy) { - int policy =3D - virDomainGraphicsVNCSharePolicyTypeFromString(sharePolicy); - - if (policy < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown vnc display sharing policy '%s'"), - sharePolicy); - return -1; - } else { - def->data.vnc.sharePolicy =3D policy; - } - } - - def->data.vnc.keymap =3D virXMLPropString(node, "keymap"); - - if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, - NULL, def, NULL) < 0) - return -1; - - if (virDomainGraphicsVNCDefParseXMLHook(node, &def->data.vnc, NULL, de= f, &flags, - port, websocket, - websocketGenerated, autoport, - sharePolicy) < 0) - return -1; - - return 0; -} - - static int virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, xmlNodePtr node, @@ -14892,7 +14825,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, =20 switch (def->type) { case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - if (virDomainGraphicsDefParseXMLVNC(def, node, ctxt, flags) < 0) + if (virDomainGraphicsVNCDefParseXML(node, &def->data.vnc, NULL, de= f, &flags) < 0) goto error; if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) goto error; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 9724b02..e262246 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1682,15 +1682,15 @@ struct _virDomainGraphicsSDLDef { /* genparse, ge= nformat:separate */ virTristateBool gl; /* xmlattr:gl/enable */ }; =20 -struct _virDomainGraphicsVNCDef { - int port; +struct _virDomainGraphicsVNCDef { /* genparse:withhook */ + int port; /* xmlattr */ bool portReserved; - int websocket; - bool websocketGenerated; - bool autoport; - char *keymap; - virDomainGraphicsAuthDef auth; - int sharePolicy; + int websocket; /* xmlattr */ + bool websocketGenerated; /* xmlattr */ + bool autoport; /* xmlattr */ + char *keymap; /* xmlattr */ + virDomainGraphicsAuthDef auth; /* xmlgroup */ + virDomainGraphicsVNCSharePolicy sharePolicy; /* xmlattr */ }; =20 struct _virDomainGraphicsRDPDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190924; cv=none; d=zohomail.com; s=zohoarc; b=ZJIqyB1PZAY9Iv2WSE8wouEYF9CPHYvnqEdF26RzhHpdRsEiqUsCMOnYWrGMO1tfx6e6/YNbAmCdZZT2S1VSjgomeUZiDl57wYY9kQJbLR/1BiJHCbJ7D1rZKtzBd3NP2jaIvRBYamcMzf3ZP6XN/lhzT8N7PZU2IrgToI8+gQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190924; 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=lklo+k62qYCSD6g8ytKK1iwdHHrcKsrNXra7StHHE8E=; b=DXlKGJlrkvHiat5fSqQxKgOFZ858mWup0b9yNkoN7/kEuCqJK7SS9JWIcEs11QxHqp6fpIds6Xo+v85vb4T0lMotlU+Zl3Z5aRCplcYXzJls2P1AVOcerpAXGq+uWfkgbLbXLZB/OXoASVyvLrAmRuQ3lGY7mdF0ZUBftzK493I= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1599190924723802.7193258967025; Thu, 3 Sep 2020 20:42:04 -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-334-r2FD7ogLNyWAME22oa07ng-1; Thu, 03 Sep 2020 23:42:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 227581006719; Fri, 4 Sep 2020 03:41:52 +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 0055C5C26A; Fri, 4 Sep 2020 03:41:51 +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 C490C972F4; Fri, 4 Sep 2020 03:41:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fA64030584 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id C5398200BCF0; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBCF12018034 for ; Fri, 4 Sep 2020 03:41:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 A56068007A4 for ; Fri, 4 Sep 2020 03:41:07 +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-532-HHiI9DN-Mk-B3HpqlHrZfQ-1; Thu, 03 Sep 2020 23:41:03 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S31; Fri, 04 Sep 2020 11:35:55 +0800 (CST) X-MC-Unique: r2FD7ogLNyWAME22oa07ng-1 X-MC-Unique: HHiI9DN-Mk-B3HpqlHrZfQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 29/46] conf: Generate virDomainGraphicsVNCDefFormatAttr Date: Fri, 4 Sep 2020 11:35:21 +0800 Message-Id: <20200904033538.418579-30-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--.1426S31 X-Coremail-Antispam: 1Uf129KBjvJXoW3WFy8JFW3WryfZr1UKFy5CFg_yoW3AF43pF 43XFyUtrW5Xrn3Cr4kGa1YgwsYkFyDWwnrAr90qw1j9rW3Gr4rZw1Iqry0gw1jgr12vr9a yFWfKw4jgw4jvrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0piAnY3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiDByVT1f11eRsigAAs- 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.4 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.16 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 | 164 ++++++++++++++++++++++++++--------------- src/conf/domain_conf.h | 14 ++-- 2 files changed, 114 insertions(+), 64 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 54b4da9..ebd8ac3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14363,9 +14363,9 @@ virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr node= G_GNUC_UNUSED, void *parent G_GNUC_UNUSED, void *opaque, const char *port, + const char *autoport, const char *websocket G_GNUC_UNUSED, const char *websocketGenerated G_GNUC_= UNUSED, - const char *autoport, const char *sharePolicy G_GNUC_UNUSED) { unsigned int flags =3D *((unsigned int *) opaque); @@ -28049,6 +28049,110 @@ virDomainSpiceGLDefFormat(virBufferPtr buf, virDo= mainGraphicsDefPtr def) virBufferAddLit(buf, "/>\n"); } =20 +bool +virDomainGraphicsVNCDefCheckAttrHook(const virDomainGraphicsVNCDef *def G_= GNUC_UNUSED, + const void *parent, + void *opaque, + bool value) +{ + bool ret =3D false; + virDomainGraphicsDefPtr graphics =3D (virDomainGraphicsDefPtr) parent; + virDomainGraphicsListenDefPtr glisten =3D virDomainGraphicsGetListen(g= raphics, 0); + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + if (!glisten) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing listen element for graphics")); + return false; + } + + switch (glisten->type) { + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: + if (glisten->socket && + !((glisten->autoGenerated || glisten->fromConfig) && + (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE))) { + ret =3D true; + } + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + /* Always output 'autoport' under these conditions */ + ret =3D true; + break; + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: + break; + } + + return ret || value; +} + +int +virDomainGraphicsVNCDefFormatAttrHook(const virDomainGraphicsVNCDef *def, + const void *parent, + const void *opaque, + virBufferPtr portBuf, + virBufferPtr autoportBuf, + virBufferPtr websocketBuf, + virBufferPtr listenBuf, + virBufferPtr socketBuf) +{ + virDomainGraphicsDefPtr graphics =3D (virDomainGraphicsDefPtr) parent; + virDomainGraphicsListenDefPtr glisten =3D virDomainGraphicsGetListen(g= raphics, 0); + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + if (!glisten) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing listen element for graphics")); + return -1; + } + + switch (glisten->type) { + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: + /* To not break migration we shouldn't print the 'socket' attribute + * if it's auto-generated or if it's based on config option from + * qemu.conf. If the socket is provided by user we need to print = it + * into migratable XML. */ + if (glisten->socket && + !((glisten->autoGenerated || glisten->fromConfig) && + (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE))) { + virBufferEscapeString(socketBuf, " socket=3D'%s'", glisten->so= cket); + } + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + if (def->port && + (!def->autoport || !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))) + virBufferAsprintf(portBuf, " port=3D'%d'", + def->port); + else if (def->autoport) + virBufferAddLit(portBuf, " port=3D'-1'"); + + virBufferAsprintf(autoportBuf, " autoport=3D'%s'", + def->autoport ? "yes" : "no"); + + if (def->websocketGenerated && + (flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) + virBufferAddLit(websocketBuf, " websocket=3D'-1'"); + else if (def->websocket) + virBufferAsprintf(websocketBuf, " websocket=3D'%d'", def->webs= ocket); + + virDomainGraphicsListenDefFormatAddr(listenBuf, glisten, flags); + break; + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: + break; + } + + return 0; +} + static int virDomainGraphicsDefFormat(virBufferPtr buf, virDomainGraphicsDefPtr def, @@ -28069,64 +28173,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf, =20 switch (def->type) { case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - if (!glisten) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing listen element for graphics")); + if (virDomainGraphicsVNCDefFormatAttr(buf, &def->data.vnc, def, &f= lags) < 0) return -1; - } - - switch (glisten->type) { - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: - /* To not break migration we shouldn't print the 'socket' attr= ibute - * if it's auto-generated or if it's based on config option fr= om - * qemu.conf. If the socket is provided by user we need to pr= int it - * into migratable XML. */ - if (glisten->socket && - !((glisten->autoGenerated || glisten->fromConfig) && - (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE))) { - virBufferEscapeString(buf, " socket=3D'%s'", glisten->sock= et); - } - break; - - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: - if (def->data.vnc.port && - (!def->data.vnc.autoport || !(flags & VIR_DOMAIN_DEF_FORMA= T_INACTIVE))) - virBufferAsprintf(buf, " port=3D'%d'", - def->data.vnc.port); - else if (def->data.vnc.autoport) - virBufferAddLit(buf, " port=3D'-1'"); - - virBufferAsprintf(buf, " autoport=3D'%s'", - def->data.vnc.autoport ? "yes" : "no"); - - if (def->data.vnc.websocketGenerated && - (flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) - virBufferAddLit(buf, " websocket=3D'-1'"); - else if (def->data.vnc.websocket) - virBufferAsprintf(buf, " websocket=3D'%d'", def->data.vnc.= websocket); - - if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS) - virBufferAsprintf(buf, " websocketGenerated=3D'%s'", - def->data.vnc.websocketGenerated ? "yes"= : "no"); - - virDomainGraphicsListenDefFormatAddr(buf, glisten, flags); - break; - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: - break; - } - - if (def->data.vnc.keymap) - virBufferEscapeString(buf, " keymap=3D'%s'", - def->data.vnc.keymap); - - if (def->data.vnc.sharePolicy) - virBufferAsprintf(buf, " sharePolicy=3D'%s'", - virDomainGraphicsVNCSharePolicyTypeToString( - def->data.vnc.sharePolicy)); - - virDomainGraphicsAuthDefFormatAttr(buf, &def->data.vnc.auth, def, = &flags); break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SDL: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e262246..f4cc504 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1682,15 +1682,17 @@ struct _virDomainGraphicsSDLDef { /* genparse, ge= nformat:separate */ virTristateBool gl; /* xmlattr:gl/enable */ }; =20 -struct _virDomainGraphicsVNCDef { /* genparse:withhook */ - int port; /* xmlattr */ +struct _virDomainGraphicsVNCDef { /* genparse:withhook, genformat:separa= te */ + int port; /* xmlattr, formathook= */ bool portReserved; - int websocket; /* xmlattr */ - bool websocketGenerated; /* xmlattr */ - bool autoport; /* xmlattr */ + bool autoport; /* xmlattr, formathook= */ + int websocket; /* xmlattr, formathook= */ + bool websocketGenerated; /* xmlattr, formatflag= :%VIR_DOMAIN_DEF_FORMAT_STATUS */ + char *_listen; /* xmlattr:listen, for= mathook */ + char *_socket; /* xmlattr:socket, for= mathook */ char *keymap; /* xmlattr */ - virDomainGraphicsAuthDef auth; /* xmlgroup */ virDomainGraphicsVNCSharePolicy sharePolicy; /* xmlattr */ + virDomainGraphicsAuthDef auth; /* xmlgroup */ }; =20 struct _virDomainGraphicsRDPDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=LAkhUWWdDwtWylGqSN0AuJxwMdvmQOEY4WKET3zAqBcmH3/SZhhdu6x7tE6bwWcEwr4xaClwCnNX8HMrvOiOcQYf7+3ajgFklhkd0d6LO7zJ2nF4z1ipJ+fUPqt4jX0SPEjRoOf5TQIhsNhoO5wgg+CMERK51BGBukCopTemyeY= 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=SixPUAYbZkVDOCYIdAtlP3sbRgZmeK4amY1x/9zlzno=; b=Kpkd6apauGpHJ5sahM6sjZRlgdPvnEvOLxvy+GJYm0QTiQ61y22AnRUruTibi6Fa8EcNsUayYw568IwcoAR9OAYjglskVpT/rRwq3eGfWIk0sIlwjeKqYE8FUTyUHY6/k85oklI3QrKHQtdIv3uRAih99DDRxwshU197cjSN33A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190888965334.4650919566685; Thu, 3 Sep 2020 20:41:28 -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-103-TtFQFpc_PniK2mDF0oVvig-1; Thu, 03 Sep 2020 23:41:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A269880F041; 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 935F97EED5; 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 E633279DAE; Fri, 4 Sep 2020 03:41:11 +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 0843f99x030553 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id BACBE2166B27; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B14932157F25 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 7745E811E81 for ; Fri, 4 Sep 2020 03:41:08 +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-253-gM-VJkWxN9GueqXSGWzMqw-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S32; Fri, 04 Sep 2020 11:35:56 +0800 (CST) X-MC-Unique: TtFQFpc_PniK2mDF0oVvig-1 X-MC-Unique: gM-VJkWxN9GueqXSGWzMqw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 30/46] conf: Extract error-checking code from virDomainGraphicsDefParseXMLRDP Date: Fri, 4 Sep 2020 11:35:22 +0800 Message-Id: <20200904033538.418579-31-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--.1426S32 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr47JFyDAr17KrW5AFykuFg_yoW5ArW8pF s7X395GrW8Xrn3Cw4Ika1Uuws09an5Jrs2grZav3yjqrW3Grs5Ar1SvF4kuF1jkrykZ3y5 AF4SqryqgF47A3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEdcTPUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiCBqVT1kXPHhyswAAsD 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.79 on 10.5.11.13 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 | 52 ++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ebd8ac3..8842f2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14401,10 +14401,40 @@ virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr no= de G_GNUC_UNUSED, } =20 =20 +static int +virDomainGraphicsRDPDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virDomainGraphicsRDPDefPtr def, + const char *instname G_GNUC_UNUSED, + void *parent G_GNUC_UNUSED, + void *opaque, + const char *port, + const char *autoport G_GNUC_UNUSED, + const char *replaceUser G_GNUC_UNUSED, + const char *multiUser G_GNUC_UNUSED) +{ + unsigned int flags =3D *((unsigned int *) opaque); + + if (port) { + /* Legacy compat syntax, used -1 for auto-port */ + if (def->port =3D=3D -1) + def->autoport =3D true; + + } else { + def->port =3D 0; + def->autoport =3D true; + } + + if (def->autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + def->port =3D 0; + + return 0; +} + + static int virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, xmlNodePtr node, - xmlXPathContextPtr ctxt, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, unsigned int flags) { g_autofree char *port =3D virXMLPropString(node, "port"); @@ -14412,36 +14442,28 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphics= DefPtr def, g_autofree char *replaceUser =3D virXMLPropString(node, "replaceUser"); g_autofree char *multiUser =3D virXMLPropString(node, "multiUser"); =20 - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - return -1; - if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse rdp port %s"), port); return -1; } - /* Legacy compat syntax, used -1 for auto-port */ - if (def->data.rdp.port =3D=3D -1) - def->data.rdp.autoport =3D true; - - } else { - def->data.rdp.port =3D 0; - def->data.rdp.autoport =3D true; } =20 if (STREQ_NULLABLE(autoport, "yes")) def->data.rdp.autoport =3D true; =20 - if (def->data.rdp.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - def->data.rdp.port =3D 0; - if (STREQ_NULLABLE(replaceUser, "yes")) def->data.rdp.replaceUser =3D true; =20 if (STREQ_NULLABLE(multiUser, "yes")) def->data.rdp.multiUser =3D true; =20 + if (virDomainGraphicsRDPDefParseXMLHook(node, &def->data.rdp, + NULL, def, &flags, port, autop= ort, + replaceUser, multiUser) < 0) + return -1; + return 0; } =20 @@ -14835,6 +14857,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; if (virDomainGraphicsDefParseXMLRDP(def, node, ctxt, flags) < 0) goto error; break; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190924; cv=none; d=zohomail.com; s=zohoarc; b=dnvuGmBcSggZ1jrFKv2wuG38i80FI4rSccsF37RiK9oAyKdBIfWGRDAKqS5/SkQE0PyRZXJNPsqL6cPSwBd2z7zJwEa6y9XYs92in5pEBiqIlMM9QibPtqGMOBz2ESYsoUyw0dR5gzSp0OcyGshSGgzRizRZEe/TAB2Pw45klUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190924; 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=/CqmqjAyY0fC/Vl4uN9J7whxr/m9ssBlMlg3WnMXlgs=; b=cPcRGUn0txIhXLa09OD8aJyTe/eleebpA7Q3xcYhWlXBzA0PjnLSkR3pgcqjoEIquo8ggY0U4l+mtgcJkooKqS/qp+/vWgpKaO7IFeqS611MpIuj7jQrz70cFvC6zhlWbI1nqqaOSl0ByM+yAuKiofwwuKErywVJW+H1g7hHM2o= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190924122180.80756161755073; Thu, 3 Sep 2020 20:42:04 -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-295-LTjRaHefNIqd5y0WAJAsug-1; Thu, 03 Sep 2020 23:41:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84EFE10060EC; Fri, 4 Sep 2020 03:41:47 +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 66BBE7C0B3; Fri, 4 Sep 2020 03:41:47 +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 3325C972EC; Fri, 4 Sep 2020 03:41:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fBpJ030609 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id B250C117DB09; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A605F117A97E for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 3C260882978 for ; Fri, 4 Sep 2020 03:41:08 +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-403-5dtA7TVnMlKnYJtk0aN5kg-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S33; Fri, 04 Sep 2020 11:35:56 +0800 (CST) X-MC-Unique: LTjRaHefNIqd5y0WAJAsug-1 X-MC-Unique: 5dtA7TVnMlKnYJtk0aN5kg-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 31/46] conf: Replace virDomainGraphicsDefParseXMLRDP(hardcoded) with virDomainGraphicsRDPDefParseXML(generated) Date: Fri, 4 Sep 2020 11:35:23 +0800 Message-Id: <20200904033538.418579-32-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--.1426S33 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr45GF1xArWrXryDGrykXwb_yoW5Cry3pF s3Wa1xGr4rXrs5Gw4vka1j9wsF9as8Jr47Gr1ruw48tFW7Gr4kAr1fZr1I934jgry8Z34S kFWSq34UWF48AFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRoGQkUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiRhyVT1bdHZp3kQAAsq 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.3 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.11 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 | 41 ++--------------------------------------- src/conf/domain_conf.h | 10 +++++----- 2 files changed, 7 insertions(+), 44 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8842f2a..14bb4d3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14401,7 +14401,7 @@ virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr node= G_GNUC_UNUSED, } =20 =20 -static int +int virDomainGraphicsRDPDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virDomainGraphicsRDPDefPtr def, const char *instname G_GNUC_UNUSED, @@ -14431,43 +14431,6 @@ virDomainGraphicsRDPDefParseXMLHook(xmlNodePtr nod= e G_GNUC_UNUSED, } =20 =20 -static int -virDomainGraphicsDefParseXMLRDP(virDomainGraphicsDefPtr def, - xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, - unsigned int flags) -{ - g_autofree char *port =3D virXMLPropString(node, "port"); - g_autofree char *autoport =3D virXMLPropString(node, "autoport"); - g_autofree char *replaceUser =3D virXMLPropString(node, "replaceUser"); - g_autofree char *multiUser =3D virXMLPropString(node, "multiUser"); - - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse rdp port %s"), port); - return -1; - } - } - - if (STREQ_NULLABLE(autoport, "yes")) - def->data.rdp.autoport =3D true; - - if (STREQ_NULLABLE(replaceUser, "yes")) - def->data.rdp.replaceUser =3D true; - - if (STREQ_NULLABLE(multiUser, "yes")) - def->data.rdp.multiUser =3D true; - - if (virDomainGraphicsRDPDefParseXMLHook(node, &def->data.rdp, - NULL, def, &flags, port, autop= ort, - replaceUser, multiUser) < 0) - return -1; - - return 0; -} - - static int virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, xmlNodePtr node) @@ -14859,7 +14822,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, case VIR_DOMAIN_GRAPHICS_TYPE_RDP: if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) goto error; - if (virDomainGraphicsDefParseXMLRDP(def, node, ctxt, flags) < 0) + if (virDomainGraphicsRDPDefParseXML(node, &def->data.rdp, NULL, de= f, &flags) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f4cc504..3cdb5f8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1695,11 +1695,11 @@ struct _virDomainGraphicsVNCDef { /* genparse:wit= hhook, genformat:separate */ virDomainGraphicsAuthDef auth; /* xmlgroup */ }; =20 -struct _virDomainGraphicsRDPDef { - int port; - bool autoport; - bool replaceUser; - bool multiUser; +struct _virDomainGraphicsRDPDef { /* genparse:withhook */ + int port; /* xmlattr */ + bool autoport; /* xmlattr */ + bool replaceUser; /* xmlattr */ + bool multiUser; /* xmlattr */ }; =20 struct _virDomainGraphicsDesktopDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190916; cv=none; d=zohomail.com; s=zohoarc; b=awfvn05HzYpwYHoBs7TfgR1O1VyjSFQaD9/k6ZmtP6qUc+t3cp+uGlXn9uJ6DuoxwdFDs6eKRiW+QBcJBuzsb7o8sA6KO3Ws4ATmKxZz9P6VSPj8Wj5nP9o+iXO3LfrWKTZ/qRyf2vdiGgIC2/WCnTLrE9qPzvwO7uEq+0zDLy0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190916; 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=1sOcUko56nqeaPXtOYKKU7mIP1kl7s2DIQ77gPJHUww=; b=AAMCIcz2ELlbX9AVBOkV7VjpS57KsreXyyoBbiflSNE1+4oNDzRmJQbl/fnrnNLmb8/G1oUn0DRY4va9VS3sn91tj0DiP+Xyy8o01eAlMI8H2TwE/PcVmvg5b0/e6YtSGgpx6Qjq5BP6M73o+ahlXjZo4jg8yAvcO9FZ/h/yXa4= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190916522152.9114889995634; Thu, 3 Sep 2020 20:41:56 -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-461-9JIQQg1YNcOkxvf5Ot9PVw-1; Thu, 03 Sep 2020 23:41:53 -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 195A3801AFA; Fri, 4 Sep 2020 03:41:45 +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 E9EB719D61; Fri, 4 Sep 2020 03:41:44 +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 B77651800B72; Fri, 4 Sep 2020 03:41:44 +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 0843f9NA030554 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB3352157F23; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1DFA2157F26 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 398CA8007D9 for ; Fri, 4 Sep 2020 03:41:08 +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-46-tISeLCyXM3q80CkNCQs_DQ-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S34; Fri, 04 Sep 2020 11:35:56 +0800 (CST) X-MC-Unique: 9JIQQg1YNcOkxvf5Ot9PVw-1 X-MC-Unique: tISeLCyXM3q80CkNCQs_DQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 32/46] conf: Generate virDomainGraphicsRDPDefFormatAttr Date: Fri, 4 Sep 2020 11:35:24 +0800 Message-Id: <20200904033538.418579-33-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--.1426S34 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr48tryxWw1UKw15Ar1fZwb_yoWrZrWDpF 13WFWFyw48XrsxCr4xG3WjgwsIkFykXrnrAr9Iqw40vrWUJrs3ZryxWFy29r4agr1kZFyF yFWSqw1UWr4jyFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRoGQkUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiPRyVT1bdHaoh9AAAsS 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 | 86 +++++++++++++++++++++++++++++------------- src/conf/domain_conf.h | 3 +- 2 files changed, 61 insertions(+), 28 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 14bb4d3..7709d71 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27995,6 +27995,28 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf, } =20 =20 +static bool +virDomainGraphicsListenDefCheckAddr(virDomainGraphicsListenDefPtr glisten, + unsigned int flags) +{ + if (!glisten) + return false; + + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && glisten->fromConfig) + return false; + + if (glisten->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && + flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE | + VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)) + return false; + + if (glisten->address) + return true; + + return false; +} + + /** * virDomainGraphicsListenDefFormatAddr: * @buf: buffer where the output XML is written @@ -28009,19 +28031,10 @@ virDomainGraphicsListenDefFormatAddr(virBufferPtr= buf, virDomainGraphicsListenDefPtr glisten, unsigned int flags) { - if (!glisten) + if (!virDomainGraphicsListenDefCheckAddr(glisten, flags)) return; =20 - if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && glisten->fromConfig) - return; - - if (glisten->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && - flags & (VIR_DOMAIN_DEF_FORMAT_INACTIVE | - VIR_DOMAIN_DEF_FORMAT_MIGRATABLE)) - return; - - if (glisten->address) - virBufferAsprintf(buf, " listen=3D'%s'", glisten->address); + virBufferAsprintf(buf, " listen=3D'%s'", glisten->address); } =20 static void @@ -28180,22 +28193,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf, break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_RDP: - if (def->data.rdp.port) - virBufferAsprintf(buf, " port=3D'%d'", - def->data.rdp.port); - else if (def->data.rdp.autoport) - virBufferAddLit(buf, " port=3D'0'"); - - if (def->data.rdp.autoport) - virBufferAddLit(buf, " autoport=3D'yes'"); - - if (def->data.rdp.replaceUser) - virBufferAddLit(buf, " replaceUser=3D'yes'"); - - if (def->data.rdp.multiUser) - virBufferAddLit(buf, " multiUser=3D'yes'"); - - virDomainGraphicsListenDefFormatAddr(buf, glisten, flags); + if (virDomainGraphicsRDPDefFormatAttr(buf, &def->data.rdp, def, NU= LL)) + return -1; =20 break; =20 @@ -32943,3 +32942,36 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *= hostdev) hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO; } + + +bool +virDomainGraphicsRDPDefCheckAttrHook(const virDomainGraphicsRDPDef *def G_= GNUC_UNUSED, + const void *parent, + void *opaque, + bool value) +{ + virDomainGraphicsDefPtr graphic =3D (virDomainGraphicsDefPtr) parent; + virDomainGraphicsListenDefPtr glisten =3D &graphic->listens[0]; + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + return virDomainGraphicsListenDefCheckAddr(glisten, flags) || value; +} + + +int +virDomainGraphicsRDPDefFormatAttrHook(const virDomainGraphicsRDPDef *def G= _GNUC_UNUSED, + const void *parent, + const void *opaque, + virBufferPtr listenBuf) +{ + virDomainGraphicsDefPtr graphic =3D (virDomainGraphicsDefPtr) parent; + virDomainGraphicsListenDefPtr glisten =3D &graphic->listens[0]; + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + virDomainGraphicsListenDefFormatAddr(listenBuf, glisten, flags); + return 0; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3cdb5f8..1444257 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1695,11 +1695,12 @@ struct _virDomainGraphicsVNCDef { /* genparse:wit= hhook, genformat:separate */ virDomainGraphicsAuthDef auth; /* xmlgroup */ }; =20 -struct _virDomainGraphicsRDPDef { /* genparse:withhook */ +struct _virDomainGraphicsRDPDef { /* genparse:withhook, genformat:separa= te */ int port; /* xmlattr */ bool autoport; /* xmlattr */ bool replaceUser; /* xmlattr */ bool multiUser; /* xmlattr */ + char *_listen; /* xmlattr:listen, formathook */ }; =20 struct _virDomainGraphicsDesktopDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190970; cv=none; d=zohomail.com; s=zohoarc; b=DiRILgOebi9DA94Go1eVesO93W5CAQanQwi5TVp5sBmumB8KwnjX7GjS5Slq+Kfeia4XK/KRVDBXrBtpRFRbVguL4zSPYLzUbPfYCbPs9aavo8XlJMKJeyr+gfcGnBKIcgsQJccz87uAzpNSQXncPEPMkaOczkFlDNhtPXGIQNg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190970; 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=yh/ImPPNr2SI193NXNa96ZXro7Y9JDtLK4XH1ERlQDE=; b=VIZkWWDxe7RmEaVOgqEXUz/WkvQVVFaa6B96rert7eOa3gqD2w6XWa+BeexPMEIIRtxsMOfw6tAqKfg3r9GznnmkXDn4K1pOY3EjDjKalYoQMAxeuee3wnivPVPQQLAaZxAn/bVDOcNw254nq4MyUwYDK/lzD823lbijTOw+FYI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190970585958.3771335450532; Thu, 3 Sep 2020 20:42:50 -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-318-Vouzjes4N-K-HjfkiPU58A-1; Thu, 03 Sep 2020 23:42:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E80DE1006711; Fri, 4 Sep 2020 03:42:40 +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 C45D25D9F1; Fri, 4 Sep 2020 03:42:40 +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 94461972EC; Fri, 4 Sep 2020 03:42:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fNj0030889 for ; Thu, 3 Sep 2020 23:41:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id DC827103426; Fri, 4 Sep 2020 03:41:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7946EE873 for ; Fri, 4 Sep 2020 03:41:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 BED05811E78 for ; Fri, 4 Sep 2020 03:41:22 +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-45-ON_40iTPOxmDvqdrdwMF7Q-1; Thu, 03 Sep 2020 23:41:20 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S35; Fri, 04 Sep 2020 11:35:56 +0800 (CST) X-MC-Unique: Vouzjes4N-K-HjfkiPU58A-1 X-MC-Unique: ON_40iTPOxmDvqdrdwMF7Q-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 33/46] conf: Replace virDomainGraphicsDefParseXMLDesktop(hardcoded) with virDomainGraphicsDesktopDefParseXML(generated) Date: Fri, 4 Sep 2020 11:35:25 +0800 Message-Id: <20200904033538.418579-34-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--.1426S35 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvj4RjYLgUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiAxyVT1ill1IGvwAAsE 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.79 on 10.11.54.5 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.14 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 | 24 +----------------------- src/conf/domain_conf.h | 6 +++--- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7709d71..ad129e9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14431,28 +14431,6 @@ virDomainGraphicsRDPDefParseXMLHook(xmlNodePtr nod= e G_GNUC_UNUSED, } =20 =20 -static int -virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, - xmlNodePtr node) -{ - g_autofree char *fullscreen =3D virXMLPropString(node, "fullscreen"); - - if (fullscreen !=3D NULL) { - if (virStringParseYesNo(fullscreen, &def->data.desktop.fullscreen)= < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown fullscreen value '%s'"), fullscreen); - return -1; - } - } else { - def->data.desktop.fullscreen =3D false; - } - - def->data.desktop.display =3D virXMLPropString(node, "display"); - - return 0; -} - - static int virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, xmlNodePtr node, @@ -14826,7 +14804,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: - if (virDomainGraphicsDefParseXMLDesktop(def, node) < 0) + if (virDomainGraphicsDesktopDefParseXML(node, &def->data.desktop, = NULL, def, NULL) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1444257..ec08bdd 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1703,9 +1703,9 @@ struct _virDomainGraphicsRDPDef { /* genparse:withh= ook, genformat:separate */ char *_listen; /* xmlattr:listen, formathook */ }; =20 -struct _virDomainGraphicsDesktopDef { - char *display; - bool fullscreen; +struct _virDomainGraphicsDesktopDef { /* genparse */ + char *display; /* xmlattr */ + bool fullscreen; /* xmlattr */ }; =20 struct _virDomainGraphicsSpiceDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191210; cv=none; d=zohomail.com; s=zohoarc; b=grWOXKY4KYkskM97P75Ummsq+6yrflEIfknFg/CMMJLVVB4WZuW2KHEXFbnOiG0EyXQwqQfVvgHixPjARM0AWgTgWS2kRU43e6BXSIerTnHBKas41kd7o59OAZC3fB0iOLPNYRntjukBwHIbkBagllFfCniT+XMYW+FXvNMS/9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191210; 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=wLRtD+rrXDx3qZMOMhsFXdiZO6tIMdpHkgdFGsEioms=; b=bnaQ29urO5KRhs8QeOlunbg0ut7lO7d0MShzSiinKq5j/FiIqK0swN7W402P0nWJi3YgI2g9VUMg8PMqjKbyEVtVH5e6xgehxGu8AA0vcngJSiHZDhrbxUOYAEbHGCVEBynr9gbBowenJYod8Pwd4TPdbBLtgKcVSwszzJTNlHA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599191210042487.9222753753347; Thu, 3 Sep 2020 20:46:50 -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-531-9nzoHzr2P_Wyg4ypbzfg-A-1; Thu, 03 Sep 2020 23:46:46 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75A028015A5; Fri, 4 Sep 2020 03:46:40 +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 3C4D37EED4; Fri, 4 Sep 2020 03:46:40 +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 5E84D972E1; Fri, 4 Sep 2020 03:46:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843kcem032370 for ; Thu, 3 Sep 2020 23:46:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 60CDB202451D; Fri, 4 Sep 2020 03:46:38 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A89F20244F7 for ; Fri, 4 Sep 2020 03:46:35 +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 30256101A540 for ; Fri, 4 Sep 2020 03:46:35 +0000 (UTC) Received: from mail-proxy25222.qiye.163.com (mail-proxy25222.qiye.163.com [103.129.252.22]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-364-Bmj2IbepNCq6HFwDzleMUQ-1; Thu, 03 Sep 2020 23:46:32 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S36; Fri, 04 Sep 2020 11:35:56 +0800 (CST) X-MC-Unique: 9nzoHzr2P_Wyg4ypbzfg-A-1 X-MC-Unique: Bmj2IbepNCq6HFwDzleMUQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 34/46] conf: Generate virDomainGraphicsDesktopDefFormatAttr Date: Fri, 4 Sep 2020 11:35:26 +0800 Message-Id: <20200904033538.418579-35-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--.1426S36 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTR5CzNUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiUB2VT1f4qIyqjAAAs6 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.4 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.13 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 | 8 ++------ src/conf/domain_conf.h | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ad129e9..bc42068 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28177,12 +28177,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf, break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: - if (def->data.desktop.display) - virBufferEscapeString(buf, " display=3D'%s'", - def->data.desktop.display); - - if (def->data.desktop.fullscreen) - virBufferAddLit(buf, " fullscreen=3D'yes'"); + if (virDomainGraphicsDesktopDefFormatAttr(buf, &def->data.desktop,= def, NULL) < 0) + return -1; =20 break; =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ec08bdd..08af9e1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1703,7 +1703,7 @@ struct _virDomainGraphicsRDPDef { /* genparse:withh= ook, genformat:separate */ char *_listen; /* xmlattr:listen, formathook */ }; =20 -struct _virDomainGraphicsDesktopDef { /* genparse */ +struct _virDomainGraphicsDesktopDef { /* genparse, genformat:separate */ char *display; /* xmlattr */ bool fullscreen; /* xmlattr */ }; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190967; cv=none; d=zohomail.com; s=zohoarc; b=PeMVkfTFX1iQBUwGblmPBZqJ1pMpj27d6JAVztKPvpzfDCFF0bK0cNNB4YDgxyREM7MmTyWf9XnJVI87DzW4DwvoipkSSEDn4hnhh4gpWz3vSniEWJAfP5543bY9DyTzqJMrfR8SNYZrwZblGpe7WqMZtRol3eDFafsFzI7GxSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190967; 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=lwBn1/ImN0777VgRzdrmQxyf0zow2yFcNXWZ84P1Yak=; b=njouyPnh2qew4E3dkr8dVjnt8ayRP/42fcaDl/8Nhu87Gn55T+2hw8oOgxA9xR0EBMif+alWxhSVlHV1bhlI/Q1OJQ287jwgkaNaWXtW9eu8hxdKhMXqTLvso2xp/XAgoCMW1WigU0dGriVUaBQ39zioRSPAK9TZswRfQN9b6WA= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599190967942807.1576836814776; Thu, 3 Sep 2020 20:42:47 -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-89-fDxNyk3aN_CCatpEhUmADA-1; Thu, 03 Sep 2020 23:42:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A88A0801AFB; Fri, 4 Sep 2020 03:42:38 +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 877AC7C0B3; Fri, 4 Sep 2020 03:42:38 +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 59BE5972E2; Fri, 4 Sep 2020 03:42:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fLlk030861 for ; Thu, 3 Sep 2020 23:41:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF90DEE873; Fri, 4 Sep 2020 03:41:21 +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 C9F3C103426 for ; Fri, 4 Sep 2020 03:41:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 B4750800962 for ; Fri, 4 Sep 2020 03:41:21 +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-548-TnoQuJbPP6-YbF6tsQlJvw-1; Thu, 03 Sep 2020 23:41:18 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S37; Fri, 04 Sep 2020 11:35:57 +0800 (CST) X-MC-Unique: fDxNyk3aN_CCatpEhUmADA-1 X-MC-Unique: TnoQuJbPP6-YbF6tsQlJvw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 35/46] conf: Add virSpiceChannelDef to help to parse the member 'channels' of virDomainGraphicsSpiceDef Date: Fri, 4 Sep 2020 11:35:27 +0800 Message-Id: <20200904033538.418579-36-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--.1426S37 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRuksgUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbihhKVT1sfnaG8qgAAsg 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.79 on 10.11.54.5 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.11 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.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 08af9e1..df84763 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1708,6 +1708,13 @@ struct _virDomainGraphicsDesktopDef { /* genparse,= genformat:separate */ bool fullscreen; /* xmlattr */ }; =20 +typedef struct _virSpiceChannelDef virSpiceChannelDef; +typedef virSpiceChannelDef *virSpiceChannelDefPtr; +struct _virSpiceChannelDef { /* genparse, genformat */ + virDomainGraphicsSpiceChannelName name; /* xmlattr */ + virDomainGraphicsSpiceChannelMode mode; /* xmlattr */ +}; + struct _virDomainGraphicsSpiceDef { int port; int tlsPort; @@ -1717,7 +1724,12 @@ struct _virDomainGraphicsSpiceDef { char *keymap; virDomainGraphicsAuthDef auth; bool autoport; + + /* The shadow member _channels helps to parse channels. */ + size_t n_channels; + virSpiceChannelDefPtr _channels; int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST]; + virDomainGraphicsSpiceChannelMode defaultMode; int image; int jpeg; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190917; cv=none; d=zohomail.com; s=zohoarc; b=cMjnp+GniVIbEZ6xUWoun5OLojxllJeGTUoo4tgsGbwpzy8cHmFU/3UNAb9oPPPOsr/2isM2rNTQkBdIZT86cxcrjHZAll7RWKUwTOIDh00FX9dzGfuZyzmFW9jZDQ6lzpJe8pBLfyb8y12CtWJSRoXpuWYXjFDUVy8oTeKre/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190917; 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=pJdjrnjPjrCneuUi00YoV/tdo3UCy+le/hs6AKYsun0=; b=PX7m03oPH1xhQl0AZ9jw2NxGG38QsEb4ZXbkPpLRsvWd3JYPLzs6ABF9QB1v6EkDZLTP/k9Dic8v8vTVQ+fHD916LsS1EY+B9IIG606v+YZiGElqIbJGFH+h5MPScYzioCNyUSS1z6psd1OFOh3vOJcSPw7nT2gKVMj0JPEqWns= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 1599190917264251.17071991801276; Thu, 3 Sep 2020 20:41:57 -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-351-6H3xD1liOkqjWF1bMuDbXw-1; Thu, 03 Sep 2020 23:41:54 -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 B766C1084C9D; Fri, 4 Sep 2020 03:41:42 +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 942A127CC6; Fri, 4 Sep 2020 03:41:42 +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 615FC972E0; Fri, 4 Sep 2020 03:41:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fABM030560 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1F1A4FED37; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14F44103791 for ; Fri, 4 Sep 2020 03:41:08 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 43310811E7F for ; Fri, 4 Sep 2020 03:41:08 +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-568-1NvkgXNDMLSnQwA2wNnPMw-1; Thu, 03 Sep 2020 23:41:05 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S38; Fri, 04 Sep 2020 11:35:57 +0800 (CST) X-MC-Unique: 6H3xD1liOkqjWF1bMuDbXw-1 X-MC-Unique: 1NvkgXNDMLSnQwA2wNnPMw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 36/46] conf: Extract error-checking code from virDomainGraphicsDefParseXMLSpice Date: Fri, 4 Sep 2020 11:35:28 +0800 Message-Id: <20200904033538.418579-37-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--.1426S38 X-Coremail-Antispam: 1Uf129KBjvJXoWxWr4rAryUtw1rKr18AF15CFg_yoW5WFW3pF s5ZF4rKFW5XrnxCw409a1Duw4YgFykJF47CrZ3Z3yUtrW7Grs5Aryrur4vqr4jkFWxA3y3 AF4SqFsrWF4UAaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_yxRPUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiGx2VT1pchmm9OgAAsy 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.79 on 10.11.54.5 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 | 46 +++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bc42068..b3ec111 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14431,10 +14431,35 @@ virDomainGraphicsRDPDefParseXMLHook(xmlNodePtr no= de G_GNUC_UNUSED, } =20 =20 +static int +virDomainGraphicsSpiceDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virDomainGraphicsSpiceDefPtr def, + const char *instname G_GNUC_UNUSED, + void *parent G_GNUC_UNUSED, + void *opaque) +{ + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + if (def->port =3D=3D -1 && def->tlsPort =3D=3D -1) { + /* Legacy compat syntax, used -1 for auto-port */ + def->autoport =3D true; + } + + if (def->autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { + def->port =3D 0; + def->tlsPort =3D 0; + } + + return 0; +} + + static int virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, xmlNodePtr node, - xmlXPathContextPtr ctxt, + xmlXPathContextPtr ctxt G_GNUC_UNUSED, unsigned int flags) { xmlNodePtr cur; @@ -14444,9 +14469,6 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphics= DefPtr def, g_autofree char *autoport =3D virXMLPropString(node, "autoport"); g_autofree char *defaultMode =3D virXMLPropString(node, "defaultMode"); =20 - if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - return -1; - if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -14482,16 +14504,6 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphic= sDefPtr def, def->data.spice.defaultMode =3D defaultModeVal; } =20 - if (def->data.spice.port =3D=3D -1 && def->data.spice.tlsPort =3D=3D -= 1) { - /* Legacy compat syntax, used -1 for auto-port */ - def->data.spice.autoport =3D true; - } - - if (def->data.spice.autoport && (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE= )) { - def->data.spice.port =3D 0; - def->data.spice.tlsPort =3D 0; - } - def->data.spice.keymap =3D virXMLPropString(node, "keymap"); =20 if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, @@ -14701,6 +14713,10 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphic= sDefPtr def, cur =3D cur->next; } =20 + if (virDomainGraphicsSpiceDefParseXMLHook(node, &def->data.spice, NULL, + def, &flags) < 0) + return -1; + return 0; } =20 @@ -14808,6 +14824,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: + if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) + goto error; if (virDomainGraphicsDefParseXMLSpice(def, node, ctxt, flags) < 0) goto error; break; --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191044; cv=none; d=zohomail.com; s=zohoarc; b=BmN3mSpjkVZEfo8H7ds3YP0MTbBrjYV4lKgpeYvbYxvG3qcW7+q5WSLypMDz04oCCHaYVLhJV0JlCkPyhBlYMaeYsZx5Za4nHxXFZqe0x7+WBMcH19XRdz+Nc1HgT6e3wKCS199snP7166gyVsFcoPAVkFOb939H51JeNKk0pIU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191044; 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=qIZety1FoZ2/8fhfSWl+gMlqm3R1+DSjbLWBC3rX2pI=; b=NYy9S8C4dDgm/cPzt14xoxD/UzTbaS8pWn5uZGTCE+DHN4MtxKPSK0Qpdk/YtaAHcgYdDpNxwXj0XtoNP+eeaD2vESceo9gIuCD5Ax9rLVC5gY8OQKO5PlMM9dZW1ZrvpjTZF8mPJJLcOiqny36shkHfFJtn79ka4DD0KgdC/oE= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599191044234335.60674059674716; Thu, 3 Sep 2020 20:44:04 -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-288-pLLByZmkMWmQKDiNg2S66Q-1; Thu, 03 Sep 2020 23:43:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F158801AF3; Fri, 4 Sep 2020 03:43:24 +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 2ED355D9CC; Fri, 4 Sep 2020 03:43:24 +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 F2DE8972F4; Fri, 4 Sep 2020 03:43:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fOux030934 for ; Thu, 3 Sep 2020 23:41:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 51B3F202451D; Fri, 4 Sep 2020 03:41:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D50A202450A for ; Fri, 4 Sep 2020 03:41:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 2FCAD8F6E4A for ; Fri, 4 Sep 2020 03:41:24 +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-374-_q7KqGtAPoSLmJd42DREJw-1; Thu, 03 Sep 2020 23:41:21 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S39; Fri, 04 Sep 2020 11:35:57 +0800 (CST) X-MC-Unique: pLLByZmkMWmQKDiNg2S66Q-1 X-MC-Unique: _q7KqGtAPoSLmJd42DREJw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 37/46] conf: Replace virDomainGraphicsDefParseXMLSpice(hardcoded) with virDomainGraphicsSpiceDefParseXML(generated) Date: Fri, 4 Sep 2020 11:35:29 +0800 Message-Id: <20200904033538.418579-38-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--.1426S39 X-Coremail-Antispam: 1Uf129KBjvJXoWfGw45tr1UuF1ftrWkur4Uurg_yoWkuryfpF 98XFZ29FWrXrn8Gayv93WkKw13WFW8Jr48GrWvgw1DJ3W5Wr4kAF4Svr1vg3yjyrZrZws0 9F4fXayjqF1UtFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_yxRPUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiSR2VT1dqAgAfUAAAs+ 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.4 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.14 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 | 272 ++--------------------------------------- src/conf/domain_conf.h | 37 +++--- 2 files changed, 26 insertions(+), 283 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b3ec111..20d731b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -877,6 +877,7 @@ VIR_ENUM_IMPL(virDomainGraphicsVNCSharePolicy, =20 VIR_ENUM_IMPL(virDomainGraphicsSpiceChannelName, VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST, + "none", "main", "display", "inputs", @@ -14431,13 +14432,14 @@ virDomainGraphicsRDPDefParseXMLHook(xmlNodePtr no= de G_GNUC_UNUSED, } =20 =20 -static int +int virDomainGraphicsSpiceDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virDomainGraphicsSpiceDefPtr def, const char *instname G_GNUC_UNUSED, void *parent G_GNUC_UNUSED, void *opaque) { + size_t i; unsigned int flags =3D 0; if (opaque) flags =3D *((unsigned int *) opaque); @@ -14452,271 +14454,11 @@ virDomainGraphicsSpiceDefParseXMLHook(xmlNodePtr= node G_GNUC_UNUSED, def->tlsPort =3D 0; } =20 - return 0; -} - - -static int -virDomainGraphicsDefParseXMLSpice(virDomainGraphicsDefPtr def, - xmlNodePtr node, - xmlXPathContextPtr ctxt G_GNUC_UNUSED, - unsigned int flags) -{ - xmlNodePtr cur; - int defaultModeVal; - 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"); - - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse spice port %s"), port); - return -1; - } - } else { - def->data.spice.port =3D 0; - } - - if (tlsPort) { - if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < = 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse spice tlsPort %s"), tlsPort); - return -1; - } - } else { - def->data.spice.tlsPort =3D 0; - } - - if (STREQ_NULLABLE(autoport, "yes")) - def->data.spice.autoport =3D true; - - def->data.spice.defaultMode =3D VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE= _ANY; - - if (defaultMode) { - if ((defaultModeVal =3D virDomainGraphicsSpiceChannelModeTypeFromS= tring(defaultMode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown default spice channel mode %s"), - defaultMode); - return -1; - } - def->data.spice.defaultMode =3D defaultModeVal; - } - - def->data.spice.keymap =3D virXMLPropString(node, "keymap"); - - if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, - NULL, def, NULL) < 0) - return -1; - - 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 ((copypasteVal =3D - virTristateBoolTypeFromString(copypaste)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copy= paste); - return -1; - } - - def->data.spice.copypaste =3D copypasteVal; - } else if (virXMLNodeNameEqual(cur, "filetransfer")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); - - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice filetransfer missing enable")); - return -1; - } - - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } - - 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 (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice gl element missing enable")); - return -1; - } - - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } - - def->data.spice.gl =3D enableVal; - def->data.spice.rendernode =3D g_steal_pointer(&rendernode= ); - - } else if (virXMLNodeNameEqual(cur, "mouse")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); - - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice mouse missing mode")); - return -1; - } - - if ((modeVal =3D virDomainGraphicsSpiceMouseModeTypeFromSt= ring(mode)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown mouse mode value '%s'"), - mode); - return -1; - } - - def->data.spice.mousemode =3D modeVal; - } - } - cur =3D cur->next; + for (i =3D 0; i < def->n_channels; i++) { + int nameval =3D def->_channels[i].name; + def->channels[nameval] =3D def->_channels[i].mode; } =20 - if (virDomainGraphicsSpiceDefParseXMLHook(node, &def->data.spice, NULL, - def, &flags) < 0) - return -1; - return 0; } =20 @@ -14826,7 +14568,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) goto error; - if (virDomainGraphicsDefParseXMLSpice(def, node, ctxt, flags) < 0) + if (virDomainGraphicsSpiceDefParseXML(node, &def->data.spice, NULL= , def, &flags) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index df84763..f27f429 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1584,6 +1584,7 @@ struct _virDomainGraphicsAuthDef { /* genparse, genf= ormat:separate */ }; =20 typedef enum { + VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_NONE =3D 0, VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MAIN, VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_DISPLAY, VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_INPUT, @@ -1715,31 +1716,31 @@ struct _virSpiceChannelDef { /* genp= arse, genformat */ virDomainGraphicsSpiceChannelMode mode; /* xmlattr */ }; =20 -struct _virDomainGraphicsSpiceDef { - int port; - int tlsPort; +struct _virDomainGraphicsSpiceDef { /* genparse:concisehook */ + int port; /* xmlattr */ + int tlsPort; /* xmlattr */ bool portReserved; bool tlsPortReserved; - virDomainGraphicsSpiceMouseMode mousemode; - char *keymap; - virDomainGraphicsAuthDef auth; - bool autoport; + virDomainGraphicsSpiceMouseMode mousemode; /* xmlattr:mouse/mode */ + char *keymap; /* xmlattr */ + virDomainGraphicsAuthDef auth; /* xmlgroup */ + bool autoport; /* xmlattr */ =20 /* The shadow member _channels helps to parse channels. */ size_t n_channels; - virSpiceChannelDefPtr _channels; + virSpiceChannelDefPtr _channels; /* xmlelem:channel, array */ int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST]; =20 - virDomainGraphicsSpiceChannelMode defaultMode; - int image; - int jpeg; - int zlib; - int playback; - int streaming; - virTristateBool copypaste; - virTristateBool filetransfer; - virTristateBool gl; - char *rendernode; + virDomainGraphicsSpiceChannelMode defaultMode; /* xmlattr */ + virDomainGraphicsSpiceImageCompression image; /* xmlattr:image/compr= ession */ + virDomainGraphicsSpiceJpegCompression jpeg; /* xmlattr:jpeg/compre= ssion */ + virDomainGraphicsSpiceZlibCompression zlib; /* xmlattr:zlib/compre= ssion */ + virTristateSwitch playback; /* xmlattr:playback/co= mpression */ + virDomainGraphicsSpiceStreamingMode streaming; /* xmlattr:streaming/m= ode */ + virTristateBool copypaste; /* xmlattr:clipboard/copypaste */ + virTristateBool filetransfer; /* xmlattr:filetransfer/enable */ + virTristateBool gl; /* xmlattr:gl/enable */ + char *rendernode; /* xmlattr:gl/rendernode */ }; =20 struct _virDomainGraphicsEGLHeadlessDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=Yq/g2apXAKOWWpvDGQFqNlZuLIDzEZ/TZrOaLSWPochg0c1QldDT2iRlZ/2UJl/N7ZS+FY8sDDBV6Knwawa5r7rfFH2dK4qqSF96IPHVe7ppDTaMupjVwvENbIu9ehO3stbzr5Sfz//F3J5TVo7+BLZVUx27gUUqfG6TF5yO1GQ= 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=bBVz68ZVwnwmj2OQmNw2OH9ldZ3J+4+7nSAKzMNjXPg=; b=cYccThgETNuOAobkVTRJIXHnuopdxh6EyBQh3Klfp6TOTX76aIxQ1GnfNdeJLbG/3Gqhr8AiViK9z6aEAEaggu0G2Zo9pdLeokBhTog2YPHFiKlzmCRyIPb3axIR6lweI5wsNqeCENud9KJnac4htSzoZYPhrVKMyaU51TEXQ7Y= 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 1599190887893748.1194344403142; 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-319-jRZriDhsNkqx-CdCCpfXqw-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 5865085B67C; Fri, 4 Sep 2020 03: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 907011A7C8; 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 1BD6B180B656; Fri, 4 Sep 2020 03:41:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fAlm030577 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC262117DB03; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A00A9117A978 for ; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 629178F6E71 for ; Fri, 4 Sep 2020 03:41:09 +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-453-55YS8uIBMvy8ddQ87kMoKA-1; Thu, 03 Sep 2020 23:41:06 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S40; Fri, 04 Sep 2020 11:35:57 +0800 (CST) X-MC-Unique: jRZriDhsNkqx-CdCCpfXqw-1 X-MC-Unique: 55YS8uIBMvy8ddQ87kMoKA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 38/46] conf: Generate virDomainGraphicsSpiceDefFormatElem and virDomainGraphicsSpiceDefFormatAttr Date: Fri, 4 Sep 2020 11:35:30 +0800 Message-Id: <20200904033538.418579-39-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--.1426S40 X-Coremail-Antispam: 1Uf129KBjvJXoW3tF1DGFyDXr47WF1UtF1rCrg_yoWkJFy7pF 9xZFWjqF4UZrsxGr48Was0gw43KFykXrW7Cr9aqw1j9r45Gr4kurWag34v9r4YkFsrZas5 ZFWSqw4UXw4jyFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrgA3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiWR2VT1f4pw-zKQAAsD 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.3 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 | 206 ++++++++++++++++++----------------------- src/conf/domain_conf.h | 9 +- 2 files changed, 96 insertions(+), 119 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 20d731b..88e324e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27775,18 +27775,6 @@ virDomainGraphicsListenDefFormatAddr(virBufferPtr = buf, virBufferAsprintf(buf, " listen=3D'%s'", glisten->address); } =20 -static void -virDomainSpiceGLDefFormat(virBufferPtr buf, virDomainGraphicsDefPtr def) -{ - if (def->data.spice.gl =3D=3D VIR_TRISTATE_BOOL_ABSENT) - return; - - virBufferAsprintf(buf, "data.spice.gl)); - virBufferEscapeString(buf, " rendernode=3D'%s'", def->data.spice.rende= rnode); - virBufferAddLit(buf, "/>\n"); -} - bool virDomainGraphicsVNCDefCheckAttrHook(const virDomainGraphicsVNCDef *def G_= GNUC_UNUSED, const void *parent, @@ -27896,7 +27884,6 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virDomainGraphicsDefPtr def, unsigned int flags) { - virDomainGraphicsListenDefPtr glisten =3D virDomainGraphicsGetListen(d= ef, 0); const char *type =3D virDomainGraphicsTypeToString(def->type); bool children =3D false; size_t i; @@ -27943,60 +27930,9 @@ virDomainGraphicsDefFormat(virBufferPtr buf, break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: - if (!glisten) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing listen element for spice graphics")); + if (virDomainGraphicsSpiceDefFormatAttr(buf, &def->data.spice, def= , &flags) < 0) return -1; - } - - switch (glisten->type) { - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: - if (def->data.spice.port) - virBufferAsprintf(buf, " port=3D'%d'", - def->data.spice.port); - - if (def->data.spice.tlsPort) - virBufferAsprintf(buf, " tlsPort=3D'%d'", - def->data.spice.tlsPort); - - virBufferAsprintf(buf, " autoport=3D'%s'", - def->data.spice.autoport ? "yes" : "no"); - - virDomainGraphicsListenDefFormatAddr(buf, glisten, flags); - break; - - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: - if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) - virBufferAddStr(buf, " autoport=3D'no'"); - break; =20 - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: - /* If socket is auto-generated based on config option we don't - * add any listen element into migratable XML because the orig= inal - * listen type is "address". - * We need to set autoport to make sure that libvirt on destin= ation - * will parse it as listen type "address", without autoport it= is - * parsed as listen type "none". */ - if ((flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) && - glisten->fromConfig) { - virBufferAddStr(buf, " autoport=3D'yes'"); - } - break; - - case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: - break; - } - - if (def->data.spice.keymap) - virBufferEscapeString(buf, " keymap=3D'%s'", - def->data.spice.keymap); - - if (def->data.spice.defaultMode !=3D VIR_DOMAIN_GRAPHICS_SPICE_CHA= NNEL_MODE_ANY) - virBufferAsprintf(buf, " defaultMode=3D'%s'", - virDomainGraphicsSpiceChannelModeTypeToString(def->data.spic= e.defaultMode)); - - virDomainGraphicsAuthDefFormatAttr(buf, &def->data.spice.auth, def= , &flags); break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: @@ -28053,56 +27989,8 @@ virDomainGraphicsDefFormat(virBufferPtr buf, } =20 if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - for (i =3D 0; i < VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST; i++) { - int mode =3D def->data.spice.channels[i]; - if (mode =3D=3D VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY) - continue; - - if (!children) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children =3D true; - } - - virBufferAsprintf(buf, "\n", - virDomainGraphicsSpiceChannelNameTypeToStrin= g(i), - virDomainGraphicsSpiceChannelModeTypeToStrin= g(mode)); - } - if (!children && (def->data.spice.image || def->data.spice.jpeg || - def->data.spice.zlib || def->data.spice.playback= || - def->data.spice.streaming || def->data.spice.cop= ypaste || - def->data.spice.mousemode || def->data.spice.fil= etransfer || - def->data.spice.gl)) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children =3D true; - } - if (def->data.spice.image) - virBufferAsprintf(buf, "\n", - virDomainGraphicsSpiceImageCompressionTypeTo= String(def->data.spice.image)); - if (def->data.spice.jpeg) - virBufferAsprintf(buf, "\n", - virDomainGraphicsSpiceJpegCompressionTypeToS= tring(def->data.spice.jpeg)); - if (def->data.spice.zlib) - virBufferAsprintf(buf, "\n", - virDomainGraphicsSpiceZlibCompressionTypeToS= tring(def->data.spice.zlib)); - if (def->data.spice.playback) - virBufferAsprintf(buf, "\n", - virTristateSwitchTypeToString(def->data.spic= e.playback)); - if (def->data.spice.streaming) - virBufferAsprintf(buf, "\n", - virDomainGraphicsSpiceStreamingModeTypeToStr= ing(def->data.spice.streaming)); - if (def->data.spice.mousemode) - virBufferAsprintf(buf, "\n", - virDomainGraphicsSpiceMouseModeTypeToString(= def->data.spice.mousemode)); - if (def->data.spice.copypaste) - virBufferAsprintf(buf, "\n", - virTristateBoolTypeToString(def->data.spice.= copypaste)); - if (def->data.spice.filetransfer) - virBufferAsprintf(buf, "\n", - virTristateBoolTypeToString(def->data.spice.= filetransfer)); - - virDomainSpiceGLDefFormat(buf, def); + if (virDomainGraphicsSpiceDefFormatElem(buf, &def->data.spice, def= , NULL) < 0) + return -1; } =20 if (children) { @@ -32694,6 +32582,45 @@ virDomainGraphicsRDPDefCheckAttrHook(const virDoma= inGraphicsRDPDef *def G_GNUC_U } =20 =20 +bool +virDomainGraphicsSpiceDefCheckAttrHook(const virDomainGraphicsSpiceDef *de= f G_GNUC_UNUSED, + const void *parent, + void *opaque, + bool value) +{ + bool ret =3D false; + virDomainGraphicsDefPtr graphic =3D (virDomainGraphicsDefPtr) parent; + virDomainGraphicsListenDefPtr glisten =3D &graphic->listens[0]; + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + switch (glisten->type) { + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + ret =3D true; + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) + ret =3D true; + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: + if ((flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) && + glisten->fromConfig) { + ret =3D true; + } + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: + break; + } + + return ret || value; +} + + int virDomainGraphicsRDPDefFormatAttrHook(const virDomainGraphicsRDPDef *def G= _GNUC_UNUSED, const void *parent, @@ -32707,5 +32634,54 @@ virDomainGraphicsRDPDefFormatAttrHook(const virDom= ainGraphicsRDPDef *def G_GNUC_ flags =3D *((unsigned int *) opaque); =20 virDomainGraphicsListenDefFormatAddr(listenBuf, glisten, flags); + + return 0; +} + + +int +virDomainGraphicsSpiceDefFormatAttrHook(const virDomainGraphicsSpiceDef *d= ef, + const void *parent, + const void *opaque, + virBufferPtr autoportBuf, + virBufferPtr listenBuf) +{ + virDomainGraphicsDefPtr graphic =3D (virDomainGraphicsDefPtr) parent; + virDomainGraphicsListenDefPtr glisten =3D &graphic->listens[0]; + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + + switch (glisten->type) { + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + virBufferAsprintf(autoportBuf, " autoport=3D'%s'", + def->autoport ? "yes" : "no"); + + virDomainGraphicsListenDefFormatAddr(listenBuf, glisten, flags); + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) + virBufferAddStr(autoportBuf, " autoport=3D'no'"); + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: + /* If socket is auto-generated based on config option we don't + * add any listen element into migratable XML because the original + * listen type is "address". + * We need to set autoport to make sure that libvirt on destination + * will parse it as listen type "address", without autoport it is + * parsed as listen type "none". */ + if ((flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) && + glisten->fromConfig) { + virBufferAddStr(autoportBuf, " autoport=3D'yes'"); + } + break; + + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: + break; + } + return 0; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f27f429..ad84fe3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1716,27 +1716,28 @@ struct _virSpiceChannelDef { /* genp= arse, genformat */ virDomainGraphicsSpiceChannelMode mode; /* xmlattr */ }; =20 -struct _virDomainGraphicsSpiceDef { /* genparse:concisehook */ +struct _virDomainGraphicsSpiceDef { /* genparse:concisehook, genformat= :separate */ int port; /* xmlattr */ int tlsPort; /* xmlattr */ bool portReserved; bool tlsPortReserved; - virDomainGraphicsSpiceMouseMode mousemode; /* xmlattr:mouse/mode */ char *keymap; /* xmlattr */ + bool autoport; /* xmlattr, formathook */ + char *_listen; /* xmlattr:listen, formathook */ + virDomainGraphicsSpiceChannelMode defaultMode; /* xmlattr */ virDomainGraphicsAuthDef auth; /* xmlgroup */ - bool autoport; /* xmlattr */ =20 /* The shadow member _channels helps to parse channels. */ size_t n_channels; virSpiceChannelDefPtr _channels; /* xmlelem:channel, array */ int channels[VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST]; =20 - virDomainGraphicsSpiceChannelMode defaultMode; /* xmlattr */ virDomainGraphicsSpiceImageCompression image; /* xmlattr:image/compr= ession */ virDomainGraphicsSpiceJpegCompression jpeg; /* xmlattr:jpeg/compre= ssion */ virDomainGraphicsSpiceZlibCompression zlib; /* xmlattr:zlib/compre= ssion */ virTristateSwitch playback; /* xmlattr:playback/co= mpression */ virDomainGraphicsSpiceStreamingMode streaming; /* xmlattr:streaming/m= ode */ + virDomainGraphicsSpiceMouseMode mousemode; /* xmlattr:mouse/mode = */ virTristateBool copypaste; /* xmlattr:clipboard/copypaste */ virTristateBool filetransfer; /* xmlattr:filetransfer/enable */ virTristateBool gl; /* xmlattr:gl/enable */ --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191012; cv=none; d=zohomail.com; s=zohoarc; b=Ingj2kcwMDgS/OL1Ky+cf7crJ9aeqNsoF4Om4VrgMZjmnpFhQpU7CgdDXnUgR+dmrA6b1B23b+YoUVJb9olvMwbR+d4+jb3DNJdnKw9Mj5bDi7F8DFCrmkvz3cH9G7G9FoxUXIwlZL/tCLP0pnW4nlLafV8tpm9ULSkhrGkzTOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191012; 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=lvWav4VEbVYD0/5awM3KyFna0v70k7Z5GLvmwcZX3VI=; b=RSAs09wkExsMq/79dEwLlghU7uEfabEELcn1afSNG8PzgXvLhE1DNk7dNfXrpT7zLSFXPQ7cVx1R0/sYBxW2SWTV1wHq6lyLoFFENU7wQ3DIenJYIFwc4HfZuDsQ0Lrfq4KIEtG0ZADtxwd2A78jyz1Y9mUdTYJtCg/E0POmiVM= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599191012973150.11243818487446; Thu, 3 Sep 2020 20:43:32 -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-335-KulaHmyROMid3Zpu7tR9mA-1; Thu, 03 Sep 2020 23:43:30 -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 D81DF18B9EB7; Fri, 4 Sep 2020 03:43:24 +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 B51981A4D6; Fri, 4 Sep 2020 03:43:24 +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 82991972F8; Fri, 4 Sep 2020 03:43:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fMK5030885 for ; Thu, 3 Sep 2020 23:41:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id D30E9117DB03; Fri, 4 Sep 2020 03:41:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CC19A117DB01 for ; Fri, 4 Sep 2020 03:41:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (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 B42388F6E68 for ; Fri, 4 Sep 2020 03:41:22 +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-19-fBgFF1BzMGukAJQfqwWUUg-1; Thu, 03 Sep 2020 23:41:19 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S41; Fri, 04 Sep 2020 11:35:57 +0800 (CST) X-MC-Unique: KulaHmyROMid3Zpu7tR9mA-1 X-MC-Unique: fBgFF1BzMGukAJQfqwWUUg-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 39/46] conf: Replace virDomainGraphicsDefParseXMLEGLHeadless(hardcoded) with virDomainGraphicsEGLHeadlessDefParseXML(generated) Date: Fri, 4 Sep 2020 11:35:31 +0800 Message-Id: <20200904033538.418579-40-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--.1426S41 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRuksgUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiDwWVT1nfQQWGqwAAs- 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.3 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 | 19 +------------------ src/conf/domain_conf.h | 4 ++-- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 88e324e..f3b59ed 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14463,23 +14463,6 @@ virDomainGraphicsSpiceDefParseXMLHook(xmlNodePtr n= ode G_GNUC_UNUSED, } =20 =20 -static int -virDomainGraphicsDefParseXMLEGLHeadless(virDomainGraphicsDefPtr def, - xmlNodePtr node, - xmlXPathContextPtr ctxt) -{ - VIR_XPATH_NODE_AUTORESTORE(ctxt) - xmlNodePtr glNode; - - ctxt->node =3D node; - - if ((glNode =3D virXPathNode("./gl", ctxt))) - def->data.egl_headless.rendernode =3D virXMLPropString(glNode, - "rendernode"); - return 0; -} - - virDomainGraphicsDefPtr virDomainGraphicsDefNew(virDomainXMLOptionPtr xmlopt) { @@ -14572,7 +14555,7 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: - if (virDomainGraphicsDefParseXMLEGLHeadless(def, node, ctxt) < 0) + if (virDomainGraphicsEGLHeadlessDefParseXML(node, &def->data.egl_h= eadless, NULL, def, NULL) < 0) goto error; break; case VIR_DOMAIN_GRAPHICS_TYPE_LAST: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index ad84fe3..baa9166 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1744,8 +1744,8 @@ struct _virDomainGraphicsSpiceDef { /* genparse:c= oncisehook, genformat:separ char *rendernode; /* xmlattr:gl/rendernode */ }; =20 -struct _virDomainGraphicsEGLHeadlessDef { - char *rendernode; +struct _virDomainGraphicsEGLHeadlessDef { /* genparse */ + char *rendernode; /* xmlattr:gl/rendernode */ }; =20 struct _virDomainGraphicsDef { --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191007; cv=none; d=zohomail.com; s=zohoarc; b=nLH9209bRyagrztGimOGiGuEWfoBnoxeDBIx7PJAL8I2ZhWaz48UIu/vjj8U4ZuOQOMDAkWZxO8d9sqvhU15/czXkoGbOT/BedDdImpUwalGZNUiKvFiZpp+TTD5Qmbi5AdSxMxSwu2/ZHwVKGW+XHsR39Xs9SOvPI8iRyTg0dg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191007; 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=JkX4rLFC9U5ndj+2BjAcXMytIH9qxQk+Kd2w/MuYQOo=; b=It0k6qZTp8+X2ldwsx81dSsLQeERQ9iFFQA7PmDPIkxOS9PUb94lFso7OceMDHYEEvIsE+cHDG27xBgrJLfgM+Uh6y65miLZHGg9hgiKht0dMsUKbfFFFRzOfd9fQd8LSAHrlrCSQSxdM3GH6ragoeW1xUAJQok+9Gd+y6StIpk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1599191007282374.07850951583; Thu, 3 Sep 2020 20:43: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-440-bSOOSpp7Nl6MMasMm5Owfw-1; Thu, 03 Sep 2020 23:43:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A01D420ED; Fri, 4 Sep 2020 03:43: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 6AE9A7E418; Fri, 4 Sep 2020 03:43: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 3866A1826D3C; Fri, 4 Sep 2020 03:43:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fM9q030884 for ; Thu, 3 Sep 2020 23:41:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9C22200AE6D; Fri, 4 Sep 2020 03:41:22 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B3FCE200AF71 for ; Fri, 4 Sep 2020 03:41:22 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.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 9D5AB185A78B for ; Fri, 4 Sep 2020 03:41:22 +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-398-hmceonULNlaUtipCFjTqyA-1; Thu, 03 Sep 2020 23:41:19 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S42; Fri, 04 Sep 2020 11:35:57 +0800 (CST) X-MC-Unique: bSOOSpp7Nl6MMasMm5Owfw-1 X-MC-Unique: hmceonULNlaUtipCFjTqyA-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 40/46] conf: Generate virDomainGraphicsEGLHeadlessDefFormatElem Date: Fri, 4 Sep 2020 11:35:32 +0800 Message-Id: <20200904033538.418579-41-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--.1426S42 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRuksgUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiPR6VT1bdHaoh+gAAse 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.4 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.11 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 | 7 +++---- src/conf/domain_conf.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f3b59ed..0802c45 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27928,10 +27928,9 @@ virDomainGraphicsDefFormat(virBufferPtr buf, children =3D true; } =20 - virBufferAddLit(buf, "data.egl_headless.rendernode); - virBufferAddLit(buf, "/>\n"); + if (virDomainGraphicsEGLHeadlessDefFormatElem(buf, &def->data.egl_= headless, def, NULL) < 0) + return -1; + break; case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index baa9166..6273c40 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1744,7 +1744,7 @@ struct _virDomainGraphicsSpiceDef { /* genparse:c= oncisehook, genformat:separ char *rendernode; /* xmlattr:gl/rendernode */ }; =20 -struct _virDomainGraphicsEGLHeadlessDef { /* genparse */ +struct _virDomainGraphicsEGLHeadlessDef { /* genparse, genformat:separat= e */ char *rendernode; /* xmlattr:gl/rendernode */ }; =20 --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191015; cv=none; d=zohomail.com; s=zohoarc; b=RdhPVqMXJbYpC0g9VwKA7oKNq8bVS4lD2wTL+jXgcsDiu1QvlSUWMX3cGWOWwQuNm51pqEUTT1ubLbSnJLLb0v3Aq6AVu4RU9yFC24spMpLgTXVNjnuyFNGHHEkzZ9NUo+Qg9YfREb6HB3DF47v10Ioc3teH/DYNPVNAqEHr7Wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191015; 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=/mcRJfUctbwwMGypiRyEFprXtWqYRK5Zri+KLk7g5P0=; b=TdHSM4niyc0jpzHayzJIlcMsqK8XaZgFC04+NhEj9B6nQyIx+LcSNW7/5dihdl47jGuBdEucqvcgpL2vwhLtyp2LIHQ7EXY6qEsfZ3AeNp7S64DzXRA0q7OMwKyJy4LTyetHwG4N8IqlU9p1ZAMe6HFolOIeYOniAXmi0n/Bm7Q= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1599191015488578.3402508104302; Thu, 3 Sep 2020 20:43:35 -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-430-IfxZm-aAOGS8_RaYLi0DOQ-1; Thu, 03 Sep 2020 23:43:32 -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 A419B85B684; Fri, 4 Sep 2020 03:43:26 +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 815AF1002D5E; Fri, 4 Sep 2020 03:43:26 +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 514D297310; Fri, 4 Sep 2020 03:43:26 +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 0843fO3U030935 for ; Thu, 3 Sep 2020 23:41:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 53FFC2157F25; Fri, 4 Sep 2020 03:41:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F1B62166B27 for ; Fri, 4 Sep 2020 03:41:24 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 3188F8F6E68 for ; Fri, 4 Sep 2020 03:41:24 +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-488-kHBm9tRLOpitp0W5DG6eNQ-1; Thu, 03 Sep 2020 23:41:21 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S43; Fri, 04 Sep 2020 11:35:58 +0800 (CST) X-MC-Unique: IfxZm-aAOGS8_RaYLi0DOQ-1 X-MC-Unique: kHBm9tRLOpitp0W5DG6eNQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 41/46] conf: Extract error-checking code from virDomainGraphicsListenDefParseXML Date: Fri, 4 Sep 2020 11:35:33 +0800 Message-Id: <20200904033538.418579-42-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--.1426S43 X-Coremail-Antispam: 1Uf129KBjvJXoW3Ar4fuFWUXryxWw4rCF1rZwb_yoWfZF4UpF 95XF4DtF45Kr1fCrZaqa18Zw43WFykG39rWrZYqw12vrWUWr4xAr4I9a42gr17Gr18Za13 ZF10qr4j9r4ayF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrgA3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiVx6VT1f4py2YTgAAsg 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.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.003 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 | 207 ++++++++++++++++++++++++----------------- 1 file changed, 121 insertions(+), 86 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0802c45..d1602ab 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14119,55 +14119,19 @@ virDomainTimerDefParseXML(xmlNodePtr node, } =20 =20 -/** - * virDomainGraphicsListenDefParseXML: - * @def: listen def pointer to be filled - * @graphics: graphics def pointer - * @node: xml node of element - * @parent: xml node of element - * @flags: bit-wise or of VIR_DOMAIN_DEF_PARSE_* - * - * Parses current element from @node to @def. For backward - * compatibility the @parent element should contain node of el= ement - * for the first element in order to validate attributes from bo= th - * elements. - */ static int -virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, - virDomainGraphicsDefPtr graphics, - xmlNodePtr node, - xmlNodePtr parent, - unsigned int flags) +virDomainGraphicsListenDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, + virDomainGraphicsListenDefPtr def, + const char *instname G_GNUC_UNUSED, + void *parent, + void *opaque, + const char *type G_GNUC_UNUSED, + const char *fromConfig, + const char *autoGenerated) { - int ret =3D -1; + unsigned int flags =3D *((unsigned int *) opaque); + virDomainGraphicsDefPtr graphics =3D (virDomainGraphicsDefPtr) parent; const char *graphicsType =3D virDomainGraphicsTypeToString(graphics->t= ype); - int tmp, typeVal; - g_autofree char *type =3D virXMLPropString(node, "type"); - g_autofree char *address =3D virXMLPropString(node, "address"); - g_autofree char *network =3D virXMLPropString(node, "network"); - g_autofree char *socketPath =3D virXMLPropString(node, "socket"); - g_autofree char *fromConfig =3D virXMLPropString(node, "fromConfig"); - g_autofree char *autoGenerated =3D virXMLPropString(node, "autoGenerat= ed"); - g_autofree char *addressCompat =3D NULL; - g_autofree char *socketCompat =3D NULL; - - if (parent) { - addressCompat =3D virXMLPropString(parent, "listen"); - socketCompat =3D virXMLPropString(parent, "socket"); - } - - if (!type) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("graphics listen type must be specified")); - goto error; - } - - if ((typeVal =3D virDomainGraphicsListenTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown graphics listen type '%s'"), type); - goto error; - } - def->type =3D typeVal; =20 switch (def->type) { case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: @@ -14194,61 +14158,94 @@ virDomainGraphicsListenDefParseXML(virDomainGraph= icsListenDefPtr def, break; } =20 - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS) { - if (address && addressCompat && STRNEQ(address, addressCompat)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("graphics 'listen' attribute '%s' must match " - "'address' attribute of first listen element " - "(found '%s')"), addressCompat, address); - goto error; - } - - if (!address) - address =3D g_steal_pointer(&addressCompat); - } - - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) { - if (socketPath && socketCompat && STRNEQ(socketPath, socketCompat)= ) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("graphics 'socket' attribute '%s' must match " - "'socket' attribute of first listen element " - "(found '%s')"), socketCompat, socketPath); + if (def->address && def->address[0]) { + if (def->type !=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS && + (def->type !=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK || + (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) goto error; - } - - if (!socketPath) - socketPath =3D g_steal_pointer(&socketCompat); - } - - if (address && address[0] && - (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || - (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && - !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)))) { - def->address =3D g_steal_pointer(&address); } =20 - if (network && network[0]) { + if (def->network && def->network[0]) { if (def->type !=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK) { virReportError(VIR_ERR_XML_ERROR, "%s", _("'network' attribute is valid only for listen= " "type 'network'")); goto error; } - def->network =3D g_steal_pointer(&network); } =20 - if (socketPath && socketPath[0]) { + if (def->socket && def->socket[0]) { if (def->type !=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET) { virReportError(VIR_ERR_XML_ERROR, "%s", _("'socket' attribute is valid only for listen " "type 'socket'")); goto error; } - def->socket =3D g_steal_pointer(&socketPath); } =20 - if (fromConfig && - flags & VIR_DOMAIN_DEF_PARSE_STATUS) { + if (fromConfig && !(flags & VIR_DOMAIN_DEF_PARSE_STATUS)) + def->fromConfig =3D 0; + + if (autoGenerated && !(flags & VIR_DOMAIN_DEF_PARSE_STATUS)) + def->autoGenerated =3D false; + + return 0; + + error: + return -1; +} + + +/** + * virDomainGraphicsListenDefParseXML: + * @def: listen def pointer to be filled + * @graphics: graphics def pointer + * @node: xml node of element + * @flags: bit-wise or of VIR_DOMAIN_DEF_PARSE_* + * + * Parses current element from @node to @def. For backward + * compatibility the @parent element should contain node of el= ement + * for the first element in order to validate attributes from bo= th + * elements. + */ +static int +virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, + virDomainGraphicsDefPtr graphics, + xmlNodePtr node, + unsigned int flags) +{ + int ret =3D -1; + int tmp, typeVal; + g_autofree char *type =3D virXMLPropString(node, "type"); + g_autofree char *address =3D virXMLPropString(node, "address"); + g_autofree char *network =3D virXMLPropString(node, "network"); + g_autofree char *socketPath =3D virXMLPropString(node, "socket"); + g_autofree char *fromConfig =3D virXMLPropString(node, "fromConfig"); + g_autofree char *autoGenerated =3D virXMLPropString(node, "autoGenerat= ed"); + + if (!type) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("graphics listen type must be specified")); + goto error; + } + + if ((typeVal =3D virDomainGraphicsListenTypeFromString(type)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown graphics listen type '%s'"), type); + goto error; + } + def->type =3D typeVal; + + if (address && address[0]) + def->address =3D g_steal_pointer(&address); + + if (network && network[0]) + def->network =3D g_steal_pointer(&network); + + if (socketPath && socketPath[0]) + def->socket =3D g_steal_pointer(&socketPath); + + if (fromConfig) { if (virStrToLong_i(fromConfig, NULL, 10, &tmp) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid fromConfig value: %s"), @@ -14258,8 +14255,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphic= sListenDefPtr def, def->fromConfig =3D tmp !=3D 0; } =20 - if (autoGenerated && - flags & VIR_DOMAIN_DEF_PARSE_STATUS) { + if (autoGenerated) { if (virStringParseYesNo(autoGenerated, &def->autoGenerated) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid autoGenerated value: %s"), @@ -14268,6 +14264,11 @@ virDomainGraphicsListenDefParseXML(virDomainGraphi= csListenDefPtr def, } } =20 + if (virDomainGraphicsListenDefParseXMLHook(node, def, NULL, + graphics, &flags, type, + fromConfig, autoGenerated) = < 0) + goto error; + ret =3D 0; error: if (ret < 0) @@ -14303,12 +14304,46 @@ virDomainGraphicsListensParseXML(virDomainGraphic= sDefPtr def, goto cleanup; =20 for (i =3D 0; i < nListens; i++) { - if (virDomainGraphicsListenDefParseXML(&def->listens[i], def, + virDomainGraphicsListenDefPtr listen =3D &def->listens[i]; + if (virDomainGraphicsListenDefParseXML(listen, def, listenNodes[i], - i =3D=3D 0 ? node : NUL= L, 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 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190914; cv=none; d=zohomail.com; s=zohoarc; b=IjDOG2RrZuyPQ67bgBzaC7C7s2NZt5NMri5/YNpSKQGaTIEGF6QGGjXAm+JqCAxhKiQyT7NXUYk8wpTcXQRpKuyDIPaxhFjJErznKRlEi66/bFa3Eu1OZlJ0BLVRQRceuue+YA1NtT98e3v2V55JSlGelM6fsir4WEdl1dF8umY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190914; 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=DrRVheyXc7VvInr8xJFFeWqnoGqfoohGYcvAS3RDpsk=; b=BlToZBAEHv2dj5GICS/rcS/4Q6OWahRNd6t2Bv0brfIBunrt9cKOfPxhsaxFQxNcfR79jxlZ4p3ojCN0j5JrBVdqQmY7p9eIymdNNKl0VZXS9jEQkrE5vMcSYI3zhUmUXoUWPp7smzddhxTs7AnmxRHmyZzYnZ12rWFyTB0RrPg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599190914303399.3858723312162; Thu, 3 Sep 2020 20:41:54 -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-28-AK3LhwrnP8K9bov8RwhYSA-1; Thu, 03 Sep 2020 23:41:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8A74801AF8; Fri, 4 Sep 2020 03:41:42 +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 9469F78B34; Fri, 4 Sep 2020 03:41:42 +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 624BC972E1; Fri, 4 Sep 2020 03:41:42 +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 0843fA9V030572 for ; Thu, 3 Sep 2020 23:41:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3B5482157F4A; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 36A712157F49 for ; Fri, 4 Sep 2020 03:41:10 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 1802288296A 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-237-GGYgT49hNx2mcd6LOPKwnw-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--.1426S44; Fri, 04 Sep 2020 11:35:58 +0800 (CST) X-MC-Unique: AK3LhwrnP8K9bov8RwhYSA-1 X-MC-Unique: GGYgT49hNx2mcd6LOPKwnw-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 42/46] conf: Replace virDomainGraphicsListenDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:34 +0800 Message-Id: <20200904033538.418579-43-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--.1426S44 X-Coremail-Antispam: 1Uf129KBjvJXoW3XFWDKF1rCrWftr1kur4UJwb_yoWDGF4xpF yfXay8tF45XFn3Gr4vqa1j9rW2ka4qgrZrGrn0q3yjvr4UGrsrur1xtFy2gw17Wr18Zr1f Ca4I9r4DXa1FvF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrgA3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiUR6VT1f4qKEEJQAAsS 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.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.003 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 | 109 ++++--------------------------- src/conf/domain_conf.h | 18 ++--- src/qemu/qemu_command.c | 2 + src/qemu/qemu_hotplug.c | 1 + src/qemu/qemu_migration_cookie.c | 1 + src/qemu/qemu_process.c | 1 + src/qemu/qemu_validate.c | 1 + 7 files changed, 27 insertions(+), 106 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d1602ab..507679b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -853,6 +853,7 @@ VIR_ENUM_IMPL(virDomainGraphics, =20 VIR_ENUM_IMPL(virDomainGraphicsListen, VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST, + "dummy", "none", "address", "network", @@ -1789,19 +1790,6 @@ bool virDomainObjTaint(virDomainObjPtr obj, } =20 =20 -static void -virDomainGraphicsListenDefClear(virDomainGraphicsListenDefPtr def) -{ - if (!def) - return; - - VIR_FREE(def->address); - VIR_FREE(def->network); - VIR_FREE(def->socket); - return; -} - - void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) { size_t i; @@ -14119,7 +14107,7 @@ virDomainTimerDefParseXML(xmlNodePtr node, } =20 =20 -static int +int virDomainGraphicsListenDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virDomainGraphicsListenDefPtr def, const char *instname G_GNUC_UNUSED, @@ -14154,6 +14142,7 @@ virDomainGraphicsListenDefParseXMLHook(xmlNodePtr n= ode G_GNUC_UNUSED, break; case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } @@ -14196,87 +14185,6 @@ virDomainGraphicsListenDefParseXMLHook(xmlNodePtr = node G_GNUC_UNUSED, } =20 =20 -/** - * virDomainGraphicsListenDefParseXML: - * @def: listen def pointer to be filled - * @graphics: graphics def pointer - * @node: xml node of element - * @flags: bit-wise or of VIR_DOMAIN_DEF_PARSE_* - * - * Parses current element from @node to @def. For backward - * compatibility the @parent element should contain node of el= ement - * for the first element in order to validate attributes from bo= th - * elements. - */ -static int -virDomainGraphicsListenDefParseXML(virDomainGraphicsListenDefPtr def, - virDomainGraphicsDefPtr graphics, - xmlNodePtr node, - unsigned int flags) -{ - int ret =3D -1; - int tmp, typeVal; - g_autofree char *type =3D virXMLPropString(node, "type"); - g_autofree char *address =3D virXMLPropString(node, "address"); - g_autofree char *network =3D virXMLPropString(node, "network"); - g_autofree char *socketPath =3D virXMLPropString(node, "socket"); - g_autofree char *fromConfig =3D virXMLPropString(node, "fromConfig"); - g_autofree char *autoGenerated =3D virXMLPropString(node, "autoGenerat= ed"); - - if (!type) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("graphics listen type must be specified")); - goto error; - } - - if ((typeVal =3D virDomainGraphicsListenTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown graphics listen type '%s'"), type); - goto error; - } - def->type =3D typeVal; - - if (address && address[0]) - def->address =3D g_steal_pointer(&address); - - if (network && network[0]) - def->network =3D g_steal_pointer(&network); - - if (socketPath && socketPath[0]) - def->socket =3D g_steal_pointer(&socketPath); - - if (fromConfig) { - if (virStrToLong_i(fromConfig, NULL, 10, &tmp) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid fromConfig value: %s"), - fromConfig); - goto error; - } - def->fromConfig =3D tmp !=3D 0; - } - - if (autoGenerated) { - if (virStringParseYesNo(autoGenerated, &def->autoGenerated) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid autoGenerated value: %s"), - autoGenerated); - goto error; - } - } - - if (virDomainGraphicsListenDefParseXMLHook(node, def, NULL, - graphics, &flags, type, - fromConfig, autoGenerated) = < 0) - goto error; - - ret =3D 0; - error: - if (ret < 0) - virDomainGraphicsListenDefClear(def); - return ret; -} - - static int virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, xmlNodePtr node, @@ -14305,9 +14213,9 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, =20 for (i =3D 0; i < nListens; i++) { virDomainGraphicsListenDefPtr listen =3D &def->listens[i]; - if (virDomainGraphicsListenDefParseXML(listen, def, - listenNodes[i], - flags) < 0) + if (virDomainGraphicsListenDefParseXML(listenNodes[i], + listen, NULL, + def, &flags) < 0) goto cleanup; =20 if (i =3D=3D 0) { @@ -27827,6 +27735,7 @@ virDomainGraphicsVNCDefCheckAttrHook(const virDomai= nGraphicsVNCDef *def G_GNUC_U ret =3D true; break; case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } @@ -27890,6 +27799,7 @@ virDomainGraphicsVNCDefFormatAttrHook(const virDoma= inGraphicsVNCDef *def, virDomainGraphicsListenDefFormatAddr(listenBuf, glisten, flags); break; case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } @@ -27918,6 +27828,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, case VIR_DOMAIN_GRAPHICS_TYPE_VNC: if (virDomainGraphicsVNCDefFormatAttr(buf, &def->data.vnc, def, &f= lags) < 0) return -1; + break; =20 case VIR_DOMAIN_GRAPHICS_TYPE_SDL: @@ -32630,6 +32541,7 @@ virDomainGraphicsSpiceDefCheckAttrHook(const virDom= ainGraphicsSpiceDef *def G_GN } break; =20 + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } @@ -32696,6 +32608,7 @@ virDomainGraphicsSpiceDefFormatAttrHook(const virDo= mainGraphicsSpiceDef *def, } break; =20 + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6273c40..fc4aae2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1653,7 +1653,8 @@ typedef enum { } virDomainGraphicsSpiceStreamingMode; =20 typedef enum { - VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE =3D 0, + VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY =3D 0, + VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE, VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS, VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK, VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET, @@ -1667,13 +1668,14 @@ typedef enum { VIR_DOMAIN_HUB_TYPE_LAST } virDomainHubType; =20 -struct _virDomainGraphicsListenDef { - virDomainGraphicsListenType type; - char *address; - char *network; - char *socket; - bool fromConfig; /* true if the @address is config file originated = */ - bool autoGenerated; +struct _virDomainGraphicsListenDef { /* genparse:withhook */ + virDomainGraphicsListenType type; /* xmlattr */ + char *address; /* xmlattr */ + char *network; /* xmlattr */ + char *socket; /* xmlattr */ + /* true if the @address is config file originated */ + int fromConfig; /* xmlattr */ + bool autoGenerated; /* xmlattr */ }; =20 struct _virDomainGraphicsSDLDef { /* genparse, genformat:separate */ diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index bd98b0a..f60f1e8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7592,6 +7592,7 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPt= r cfg, virBufferAddLit(&opt, "none"); break; =20 + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } @@ -7718,6 +7719,7 @@ qemuBuildGraphicsSPICECommandLine(virQEMUDriverConfig= Ptr cfg, virBufferAddLit(&opt, "port=3D0,"); hasInsecure =3D true; break; + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e2c6e14..0588745 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4085,6 +4085,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, break; =20 case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: /* nada */ break; diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index cef2555..9a8e7ab 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -349,6 +349,7 @@ qemuMigrationCookieAddGraphics(qemuMigrationCookiePtr m= ig, =20 case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index cfe09d6..db1b47e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4926,6 +4926,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr drive= r, break; =20 case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 070f1c9..167cdc2 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -3293,6 +3293,7 @@ qemuValidateDomainDeviceDefSPICEGraphics(const virDom= ainGraphicsDef *graphics, =20 case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE: break; + case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_DUMMY: case VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_LAST: break; } --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599191043; cv=none; d=zohomail.com; s=zohoarc; b=fK1EBMYTruBa2VyV/6t5KcrnzlgPB71cuMDKEgMafkCX4iROg7pGeCdaPTKuWnP81uLlbsIJP/afRwVGQahZyirhW0G27s4/LtRTYa8P+KdJfbJb+ZbssnCFKg6y7Q/EbtOLalnPUke4w2ADqLHV1/R7cfgX0Y3IeqVXf78v4P8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599191043; 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=Zs79mJkfXr1YEUtrK/OSwdIFLS6KTjyjC10G3PbFVP8=; b=bkhML6CeWEmoldSMdd5fZKkctkuGlkBnUJvyqibYX13iK6FsXEmouvaGgsHyEolMwx2P2r0OhBtImfFnWRWl2hT+WPdpLFOGJvtr3gh84VLb5v0IviPfvP5gBRNfo9NQQ9LxINJN5eigoMGVEBmhwmOZt2jc51UQyJly9720xl8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599191043675433.0983791530641; Thu, 3 Sep 2020 20:44:03 -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-60-Z4tiT-WcPAaBkLe0Hb7jbA-1; Thu, 03 Sep 2020 23:43:27 -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 191FF8712FD; Fri, 4 Sep 2020 03:43:22 +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 EC69860C13; Fri, 4 Sep 2020 03:43:21 +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 BB54C972E6; Fri, 4 Sep 2020 03:43:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0843fOje030924 for ; Thu, 3 Sep 2020 23:41:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0F41E20244F7; Fri, 4 Sep 2020 03:41:24 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0A665200AE6E for ; Fri, 4 Sep 2020 03:41:24 +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 E3E88185A78B for ; Fri, 4 Sep 2020 03:41:23 +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-48-kMXm5xv8NGCvi8DCt3M65Q-1; Thu, 03 Sep 2020 23:41:21 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S45; Fri, 04 Sep 2020 11:35:58 +0800 (CST) X-MC-Unique: Z4tiT-WcPAaBkLe0Hb7jbA-1 X-MC-Unique: kMXm5xv8NGCvi8DCt3M65Q-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 43/46] conf: Generate virDomainGraphicsListenDefFormatBuf Date: Fri, 4 Sep 2020 11:35:35 +0800 Message-Id: <20200904033538.418579-44-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--.1426S45 X-Coremail-Antispam: 1Uf129KBjvJXoW3XFykWF43tF15GF17Cw1rZwb_yoWxCw48pF 4fXayUtayUJF1fArs7X3WqgrWF9F97XasrJr9Iqw1j9rWUGrWxZw1IgFyjvw13WF1kZFWS yFWSgw4Uuw4YvFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pRrgA3UUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiQx6VT1bdHJ2LIwAAsl 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.4 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.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 | 114 +++++++++++++++++++++++------------------ src/conf/domain_conf.h | 12 ++--- 2 files changed, 70 insertions(+), 56 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 507679b..007ee44 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27614,19 +27614,64 @@ virDomainTimerDefFormat(virBufferPtr buf, } =20 =20 -static void -virDomainGraphicsListenDefFormat(virBufferPtr buf, - virDomainGraphicsListenDefPtr def, - unsigned int flags) +static bool +virDomainGraphicsListenDefValid(const virDomainGraphicsListenDef *def, + const virDomainGraphicsDef *graphics, + unsigned int flags) { - /* If generating migratable XML, skip listen address - * dragged in from config file */ - if ((flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) && def->fromConfig) - return; + if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) { + /* If the listen is based on config options from qemu.conf we need + * to skip it. It's up to user to properly configure both hosts f= or + * migration. */ + if (def->fromConfig) + return false; + + /* If the socket is provided by user in the XML we need to skip th= is + * listen type to support migration back to old libvirt since old + * libvirt supports specifying socket path inside graphics element + * as 'socket' attribute. Auto-generated socket is a new feature + * thus we can generate it in the migrateble XML. */ + if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC && + def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET && + def->socket && !def->autoGenerated) + return false; + + /* The new listen type none is in the migratable XML represented as + * port=3D0 and autoport=3Dno because old libvirt support this + * configuration for spice. */ + if (graphics->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE && + def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NONE) + return false; + } + + return true; +} + + +bool +virDomainGraphicsListenDefCheckHook(const virDomainGraphicsListenDef *def, + const void *parent, + void *opaque, + bool value G_GNUC_UNUSED) +{ + virDomainGraphicsDefPtr graphics =3D (virDomainGraphicsDefPtr) parent; + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); + return virDomainGraphicsListenDefValid(def, graphics, flags); +} =20 - virBufferAddLit(buf, "type)); + +int +virDomainGraphicsListenDefFormatHook(const virDomainGraphicsListenDef *def, + const void *parent G_GNUC_UNUSED, + const void *opaque, + virBufferPtr addressBuf, + virBufferPtr socketBuf) +{ + unsigned int flags =3D 0; + if (opaque) + flags =3D *((unsigned int *) opaque); =20 if (def->address && (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || @@ -27634,28 +27679,17 @@ virDomainGraphicsListenDefFormat(virBufferPtr buf, !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)))) { /* address may also be set to show current status when type=3D'net= work', * but we don't want to print that if INACTIVE data is requested. = */ - virBufferAsprintf(buf, " address=3D'%s'", def->address); - } - - if (def->network && - (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK)) { - virBufferEscapeString(buf, " network=3D'%s'", def->network); + virBufferAsprintf(addressBuf, " address=3D'%s'", def->address); } =20 if (def->socket && def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET && !(def->autoGenerated && (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE))) { - virBufferEscapeString(buf, " socket=3D'%s'", def->socket); - } - - if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS) { - virBufferAsprintf(buf, " fromConfig=3D'%d'", def->fromConfig); - virBufferAsprintf(buf, " autoGenerated=3D'%s'", - def->autoGenerated ? "yes" : "no"); + virBufferEscapeString(socketBuf, " socket=3D'%s'", def->socket); } =20 - virBufferAddLit(buf, "/>\n"); + return 0; } =20 =20 @@ -27883,37 +27917,17 @@ virDomainGraphicsDefFormat(virBufferPtr buf, } =20 for (i =3D 0; i < def->nListens; i++) { - if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE) { - /* If the listen is based on config options from qemu.conf we = need - * to skip it. It's up to user to properly configure both hos= ts for - * migration. */ - if (def->listens[i].fromConfig) - continue; - - /* If the socket is provided by user in the XML we need to ski= p this - * listen type to support migration back to old libvirt since = old - * libvirt supports specifying socket path inside graphics ele= ment - * as 'socket' attribute. Auto-generated socket is a new feat= ure - * thus we can generate it in the migrateble XML. */ - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC && - def->listens[i].type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYP= E_SOCKET && - def->listens[i].socket && - !def->listens[i].autoGenerated) - continue; + if (!virDomainGraphicsListenDefValid(&def->listens[i], def, flags)) + continue; =20 - /* The new listen type none is in the migratable XML represent= ed as - * port=3D0 and autoport=3Dno because old libvirt support this - * configuration for spice. */ - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE && - def->listens[i].type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYP= E_NONE) - continue; - } if (!children) { virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); children =3D true; } - virDomainGraphicsListenDefFormat(buf, &def->listens[i], flags); + + virDomainGraphicsListenDefFormatBuf(buf, "listen", + &def->listens[i], def, &flags); } =20 if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index fc4aae2..d78cdbb 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1668,14 +1668,14 @@ typedef enum { VIR_DOMAIN_HUB_TYPE_LAST } virDomainHubType; =20 -struct _virDomainGraphicsListenDef { /* genparse:withhook */ +struct _virDomainGraphicsListenDef { /* genparse:withhook, genformat */ virDomainGraphicsListenType type; /* xmlattr */ - char *address; /* xmlattr */ - char *network; /* xmlattr */ - char *socket; /* xmlattr */ + char *address; /* xmlattr, formathook */ + char *network; /* xmlattr, formatflag:VIR_DOMAIN_= GRAPHICS_LISTEN_TYPE_NETWORK */ + char *socket; /* xmlattr, formathook */ /* true if the @address is config file originated */ - int fromConfig; /* xmlattr */ - bool autoGenerated; /* xmlattr */ + int fromConfig; /* xmlattr, formatflag:%VIR_DOMAIN= _DEF_FORMAT_STATUS */ + bool autoGenerated; /* xmlattr, formatflag:%VIR_DOMAIN= _DEF_FORMAT_STATUS */ }; =20 struct _virDomainGraphicsSDLDef { /* genparse, genformat:separate */ --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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 From nobody Tue May 7 16:33:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599190932; cv=none; d=zohomail.com; s=zohoarc; b=gX5aKuii7CFPRlrvAs1gSWXf6j0VrTpoTmrfE8VqKT41oRpQVwJHRdlg5qQwBkICHpCvsaz5lmrN4xMCJ68pcWrHYjsjYg6a7yMyHpatySUnQgVueEcFZwITjGdLuJoz6Nw522S6NNmjYuD/RinqA8qeYbhEBKFy8/Tc8CaytkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190932; 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=WPuZ1cm5dfQn51RgvTNWW7CWem8FfC48Z7qZVFkmNFY=; b=Rp+7uf0BxAJr45HqXYKnwcfY8hyMiMZ9KF0+ryaK5PGUpv1UIjiQM/F8dKdunSe5z51Ix/JK+D0MHVCVDY3D7B+AfvoXfd+w3kEZ8yUjJijRO7RcyDYfrI/J1JsAQ9XX0Og75V+o7lmdbFsIi57Zg+UBjlisHP5/94iGv6G4iIc= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599190932640587.5981259864528; Thu, 3 Sep 2020 20:42:12 -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-507-cXgreUs9NiWE6MwgTwezNQ-1; Thu, 03 Sep 2020 23:41:57 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8D37810060F1; Fri, 4 Sep 2020 03:41:47 +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 6A46B5D9DC; Fri, 4 Sep 2020 03:41:47 +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 369DA972ED; Fri, 4 Sep 2020 03:41:47 +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 0843f9XP030552 for ; Thu, 3 Sep 2020 23:41:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id B779B2157F4F; Fri, 4 Sep 2020 03:41:09 +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 AD5C62166B27 for ; Fri, 4 Sep 2020 03:41:09 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (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 47076805B05 for ; Fri, 4 Sep 2020 03:41:09 +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-576-Y9SpMov-NVWHFd9yC_iTaQ-1; Thu, 03 Sep 2020 23:41:06 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S47; Fri, 04 Sep 2020 11:35:59 +0800 (CST) X-MC-Unique: cXgreUs9NiWE6MwgTwezNQ-1 X-MC-Unique: Y9SpMov-NVWHFd9yC_iTaQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 45/46] conf: Replace virDomainGraphicsDefParseXML(hardcoded) with namesake(generated) Date: Fri, 4 Sep 2020 11:35:37 +0800 Message-Id: <20200904033538.418579-46-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--.1426S47 X-Coremail-Antispam: 1Uf129KBjvAXoW3uFWfCrWxtrWkKF4DZrWxCrg_yoW8JFWDAo W3ZF93tw4fXrWIvr48G397Jay8Aw4ayrW8tF4jgas5ta4kur48Kr1Uu345G34DJay7Aa4U CFs3Cw48trZ7Aw17n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjTRXxhpUUUUU X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiRR+VT1bdHCRQ4QAAsC 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.79 on 10.5.11.14 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 | 140 ++++++--------------------------------- src/conf/domain_conf.h | 21 +++--- src/qemu/qemu_command.c | 2 + src/qemu/qemu_driver.c | 2 + src/qemu/qemu_hotplug.c | 1 + src/qemu/qemu_process.c | 4 ++ src/qemu/qemu_validate.c | 1 + src/vmx/vmx.c | 1 + 8 files changed, 42 insertions(+), 130 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 60bea6f..61dc7b3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -843,6 +843,7 @@ VIR_ENUM_IMPL(virDomainInputModel, =20 VIR_ENUM_IMPL(virDomainGraphics, VIR_DOMAIN_GRAPHICS_TYPE_LAST, + "none", "sdl", "vnc", "rdp", @@ -1824,6 +1825,7 @@ void virDomainGraphicsDefFree(virDomainGraphicsDefPtr= def) VIR_FREE(def->data.egl_headless.rendernode); break; =20 + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -14185,47 +14187,6 @@ virDomainGraphicsListenDefParseXMLHook(xmlNodePtr = node G_GNUC_UNUSED, } =20 =20 -static int -virDomainGraphicsListensParseXML(virDomainGraphicsDefPtr def, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - unsigned int flags) -{ - int nListens; - int ret =3D -1; - g_autofree xmlNodePtr *listenNodes =3D NULL; - VIR_XPATH_NODE_AUTORESTORE(ctxt); - - ctxt->node =3D node; - - /* parse the subelements for graphics types that support it */ - nListens =3D virXPathNodeSet("./listen", ctxt, &listenNodes); - if (nListens < 0) - goto cleanup; - - if (nListens > 0) { - size_t i; - - if (VIR_ALLOC_N(def->listens, nListens) < 0) - goto cleanup; - - for (i =3D 0; i < nListens; i++) { - virDomainGraphicsListenDefPtr listen =3D &def->listens[i]; - if (virDomainGraphicsListenDefParseXML(listenNodes[i], - listen, NULL, - def, &flags) < 0) - goto cleanup; - - def->nListens++; - } - } - - ret =3D 0; - cleanup: - return ret; -} - - int virDomainGraphicsVNCDefParseXMLHook(xmlNodePtr node G_GNUC_UNUSED, virDomainGraphicsVNCDefPtr def, @@ -14368,7 +14329,7 @@ virDomainNetDefNew(virDomainXMLOptionPtr xmlopt) } =20 =20 -static int +int virDomainGraphicsDefParseXMLHook(xmlNodePtr node, virDomainGraphicsDefPtr def, const char *instname G_GNUC_UNUSED, @@ -14464,78 +14425,6 @@ virDomainGraphicsDefParseXMLHook(xmlNodePtr node, } =20 =20 -/* Parse the XML definition for a graphics device */ -static virDomainGraphicsDefPtr -virDomainGraphicsDefParseXML(virDomainXMLOptionPtr xmlopt, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - unsigned int flags) -{ - virDomainGraphicsDefPtr def; - int typeVal; - g_autofree char *type =3D NULL; - - if (!(def =3D virDomainGraphicsDefNew(xmlopt))) - return NULL; - - type =3D virXMLPropString(node, "type"); - if (!type) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing graphics device type")); - goto error; - } - - if ((typeVal =3D virDomainGraphicsTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown graphics device type '%s'"), type); - goto error; - } - def->type =3D typeVal; - - 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; - 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 (virDomainGraphicsRDPDefParseXML(node, &def->data.rdp, NULL, de= f, &flags) < 0) - goto error; - break; - case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: - if (virDomainGraphicsDesktopDefParseXML(node, &def->data.desktop, = NULL, def, NULL) < 0) - goto error; - break; - case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: - if (virDomainGraphicsSpiceDefParseXML(node, &def->data.spice, NULL= , def, &flags) < 0) - goto error; - break; - case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: - if (virDomainGraphicsEGLHeadlessDefParseXML(node, &def->data.egl_h= eadless, NULL, def, NULL) < 0) - goto error; - break; - case VIR_DOMAIN_GRAPHICS_TYPE_LAST: - break; - } - - if (virDomainGraphicsDefParseXMLHook(node, def, NULL, NULL, &flags) < = 0) - goto error; - - return def; - - error: - virDomainGraphicsDefFree(def); - def =3D NULL; - return NULL; -} - - static virDomainSoundCodecDefPtr virDomainSoundCodecDefParseXML(xmlNodePtr node) { @@ -16714,9 +16603,14 @@ virDomainDeviceDefParse(const char *xmlStr, return NULL; break; case VIR_DOMAIN_DEVICE_GRAPHICS: - if (!(dev->data.graphics =3D virDomainGraphicsDefParseXML(xmlopt, = node, - ctxt, flag= s))) + if (!(dev->data.graphics =3D virDomainGraphicsDefNew(xmlopt))) return NULL; + if (virDomainGraphicsDefParseXML(node, dev->data.graphics, NULL, + dev, &flags) < 0) { + virDomainGraphicsDefFree(dev->data.graphics); + dev->data.graphics =3D NULL; + return NULL; + } break; case VIR_DOMAIN_DEVICE_HUB: if (!(dev->data.hub =3D virDomainHubDefParseXML(xmlopt, node, flag= s))) @@ -21572,13 +21466,16 @@ virDomainDefParseXML(xmlDocPtr xml, if (n && VIR_ALLOC_N(def->graphics, n) < 0) goto error; for (i =3D 0; i < n; i++) { - virDomainGraphicsDefPtr graphics =3D virDomainGraphicsDefParseXML(= xmlopt, - no= des[i], - ct= xt, - fl= ags); + virDomainGraphicsDefPtr graphics =3D virDomainGraphicsDefNew(xmlop= t); if (!graphics) goto error; =20 + if (virDomainGraphicsDefParseXML(nodes[i], graphics, NULL, + def, &flags) < 0) { + virDomainGraphicsDefFree(graphics); + goto error; + } + def->graphics[def->ngraphics++] =3D graphics; } VIR_FREE(nodes); @@ -27934,6 +27831,7 @@ virDomainGraphicsDefFormat(virBufferPtr buf, return -1; =20 break; + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -32343,6 +32241,7 @@ virDomainGraphicsDefHasOpenGL(const virDomainDef *d= ef) case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: return true; =20 + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -32381,6 +32280,7 @@ virDomainGraphicsGetRenderNode(const virDomainGraph= icsDef *graphics) case VIR_DOMAIN_GRAPHICS_TYPE_VNC: case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index d78cdbb..b6d69fa 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1545,6 +1545,7 @@ struct _virDomainVideoDef { =20 /* graphics console modes */ typedef enum { + VIR_DOMAIN_GRAPHICS_TYPE_NONE =3D 0, VIR_DOMAIN_GRAPHICS_TYPE_SDL, VIR_DOMAIN_GRAPHICS_TYPE_VNC, VIR_DOMAIN_GRAPHICS_TYPE_RDP, @@ -1750,7 +1751,7 @@ struct _virDomainGraphicsEGLHeadlessDef { /* genpar= se, genformat:separate */ char *rendernode; /* xmlattr:gl/rendernode */ }; =20 -struct _virDomainGraphicsDef { +struct _virDomainGraphicsDef { /* genparse:concisehook */ virObjectPtr privateData; =20 /* Port value discipline: @@ -1758,20 +1759,20 @@ struct _virDomainGraphicsDef { * Value 0 means port wasn't specified in XML at all. * Positive value is actual port number given in XML. */ - virDomainGraphicsType type; + virDomainGraphicsType type; /* xmlattr */ union { - virDomainGraphicsSDLDef sdl; - virDomainGraphicsVNCDef vnc; - virDomainGraphicsRDPDef rdp; - virDomainGraphicsDesktopDef desktop; - virDomainGraphicsSpiceDef spice; - virDomainGraphicsEGLHeadlessDef egl_headless; - } data; + virDomainGraphicsSDLDef sdl; /* xmlgroup */ + virDomainGraphicsVNCDef vnc; /* xmlgroup */ + virDomainGraphicsRDPDef rdp; /* xmlgroup */ + virDomainGraphicsDesktopDef desktop; /* xmlgroup */ + virDomainGraphicsSpiceDef spice; /* xmlgroup */ + virDomainGraphicsEGLHeadlessDef egl_headless; /* xmlgroup */ + } data; /* xmlswitch:type */ /* nListens, listens, and *port are only useful if type is vnc, * rdp, or spice. They've been extracted from the union only to * simplify parsing code.*/ size_t nListens; - virDomainGraphicsListenDefPtr listens; + virDomainGraphicsListenDefPtr listens; /* xmlelem, array:nListens */ }; =20 typedef enum { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f60f1e8..272be28 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -7938,6 +7938,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfigPtr c= fg, case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: return -1; + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: default: virReportEnumRangeError(virDomainGraphicsType, graphics->type); @@ -9772,6 +9773,7 @@ qemuBuildCommandLineValidate(virQEMUDriverPtr driver, break; case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0d06812..922b9bb 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15681,6 +15681,7 @@ qemuDomainOpenGraphics(virDomainPtr dom, _("Can only open VNC or SPICE graphics backends, no= t %s"), virDomainGraphicsTypeToString(vm->def->graphics[idx= ]->type)); goto endjob; + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: default: virReportEnumRangeError(virDomainGraphicsType, @@ -15750,6 +15751,7 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom, _("Can only open VNC or SPICE graphics backends, no= t %s"), virDomainGraphicsTypeToString(vm->def->graphics[idx= ]->type)); goto cleanup; + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: default: virReportEnumRangeError(virDomainGraphicsType, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 0588745..d008035 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4191,6 +4191,7 @@ qemuDomainChangeGraphics(virQEMUDriverPtr driver, virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to change config on '%s' graphics type"),= type); break; + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: default: virReportEnumRangeError(virDomainGraphicsType, dev->type); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index db1b47e..c20988f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4687,6 +4687,7 @@ qemuProcessGraphicsReservePorts(virDomainGraphicsDefP= tr graphics, case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -4726,6 +4727,7 @@ qemuProcessGraphicsAllocatePorts(virQEMUDriverPtr dri= ver, case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -4882,6 +4884,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr drive= r, case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } @@ -5188,6 +5191,7 @@ qemuProcessStartValidateGraphics(virDomainObjPtr vm) case VIR_DOMAIN_GRAPHICS_TYPE_RDP: case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: break; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 167cdc2..1d7a492 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -3416,6 +3416,7 @@ qemuValidateDomainDeviceDefGraphics(const virDomainGr= aphicsDef *graphics, _("unsupported graphics type '%s'"), virDomainGraphicsTypeToString(graphics->type)); return -1; + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: default: return -1; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 4b1b04c..cfc88aa 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -3314,6 +3314,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOp= tionPtr xmlopt, virDomainDe virDomainGraphicsTypeToString(def->graphics[i]-= >type)); goto cleanup; =20 + case VIR_DOMAIN_GRAPHICS_TYPE_NONE: case VIR_DOMAIN_GRAPHICS_TYPE_LAST: default: virReportEnumRangeError(virDomainGraphicsType, def->graphics= [i]->type); --=20 2.25.1 From nobody Tue May 7 16:33:20 2024 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=1599190973; cv=none; d=zohomail.com; s=zohoarc; b=bq1zFrsyTxDanW0ViiTmpGO/Ru+LZhe17cpNvikBa4Kvjce1W2Bp7NmiVCYNQtcbu5gLGSKwkGSL/k8WyiKF1BRwN5NadHcRyP+nND0tJS5wqaXshdp5KAUrdI7q+qoznUkdQnIAElCWEVeAc4h3GnCqH7pmip3P5zeBlx1WxoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599190973; 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=eabqRHvtupEoK/MuKO7VpcJzrMgTD437mypfZcYreTE=; b=gMeDOYkSPUqdlupVEjNh6zXEjlKfslYVyPLxk7qSLpOPN6gMjBWmby8bbZulBDEUlL4aq7zDkzZXdlmE6pUWI+wL+wAe+KLK+u3JnAVM+nsx+nE1SzL+C5nFo1SaX8N+Anm/biRudnUtSGq9gWqKphtpe8Cq6y0MeCizlhnLpSw= 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 1599190973552795.2688582181684; Thu, 3 Sep 2020 20:42:53 -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-393-oR_6Oe99MdWU1cF3HsVPkg-1; Thu, 03 Sep 2020 23:42:50 -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 8BF7018A2269; Fri, 4 Sep 2020 03:42:43 +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 2029A60CC0; Fri, 4 Sep 2020 03:42:43 +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 E05161826D35; Fri, 4 Sep 2020 03:42:42 +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 0843fN87030911 for ; Thu, 3 Sep 2020 23:41:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 84F172157F25; Fri, 4 Sep 2020 03:41:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 801C52166B27 for ; Fri, 4 Sep 2020 03:41:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (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 640F880118B for ; Fri, 4 Sep 2020 03:41:23 +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-577-AjluPrZENkGudsgjBrfNTQ-1; Thu, 03 Sep 2020 23:41:20 -0400 Received: from localhost.localdomain (unknown [58.56.27.130]) by smtp4 (Coremail) with SMTP id JedpCgAHcNgStlFfYHYgCg--.1426S48; Fri, 04 Sep 2020 11:35:59 +0800 (CST) X-MC-Unique: oR_6Oe99MdWU1cF3HsVPkg-1 X-MC-Unique: AjluPrZENkGudsgjBrfNTQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [RFCv2 46/46] conf: Replace virDomainGraphicsDefFormat(hardcoded) with virDomainGraphicsDefFormatBuf(generated) Date: Fri, 4 Sep 2020 11:35:38 +0800 Message-Id: <20200904033538.418579-47-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--.1426S48 X-Coremail-Antispam: 1Uf129KBjvJXoWxtFWUtr1rKFy3Jry8ury3urg_yoWxZr1xpF y3ZFWUKFW5XFsxGr48Ka1Ygw47KFyDWr4DArZYq3yq9rW5Grs5AryxXry0vw1j9rW7Zryx CFWftw4UXa1IyFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0p_yxRPUUUUU= X-Originating-IP: [58.56.27.130] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiQh+VT1bdHGTX6QAAsK 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.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.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 | 152 ++--------------------------------------- src/conf/domain_conf.h | 14 ++-- 2 files changed, 15 insertions(+), 151 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 61dc7b3..64d6ae5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1793,47 +1793,10 @@ bool virDomainObjTaint(virDomainObjPtr obj, =20 void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def) { - size_t i; - if (!def) return; =20 - switch (def->type) { - case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - VIR_FREE(def->data.vnc.keymap); - virDomainGraphicsAuthDefClear(&def->data.vnc.auth); - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_SDL: - virDomainGraphicsSDLDefClear(&def->data.sdl); - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_RDP: - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: - VIR_FREE(def->data.desktop.display); - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: - VIR_FREE(def->data.spice.rendernode); - VIR_FREE(def->data.spice.keymap); - virDomainGraphicsAuthDefClear(&def->data.spice.auth); - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: - VIR_FREE(def->data.egl_headless.rendernode); - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_NONE: - case VIR_DOMAIN_GRAPHICS_TYPE_LAST: - break; - } - - for (i =3D 0; i < def->nListens; i++) - virDomainGraphicsListenDefClear(&def->listens[i]); - VIR_FREE(def->listens); - + virDomainGraphicsDefClear(def); virObjectUnref(def->privateData); VIR_FREE(def); } @@ -27760,111 +27723,6 @@ virDomainGraphicsVNCDefFormatAttrHook(const virDo= mainGraphicsVNCDef *def, return 0; } =20 -static int -virDomainGraphicsDefFormat(virBufferPtr buf, - virDomainGraphicsDefPtr def, - unsigned int flags) -{ - const char *type =3D virDomainGraphicsTypeToString(def->type); - bool children =3D false; - size_t i; - - if (!type) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected net type %d"), def->type); - return -1; - } - - virBufferAsprintf(buf, "type) { - case VIR_DOMAIN_GRAPHICS_TYPE_VNC: - if (virDomainGraphicsVNCDefFormatAttr(buf, &def->data.vnc, def, &f= lags) < 0) - return -1; - - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_SDL: - if (virDomainGraphicsSDLDefFormatAttr(buf, &def->data.sdl, def, NU= LL) < 0) - return -1; - - if (!children && virDomainGraphicsSDLDefCheckElem(&def->data.sdl, = def, NULL)) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children =3D true; - } - - if (virDomainGraphicsSDLDefFormatElem(buf, &def->data.sdl, def, NU= LL) < 0) - return -1; - - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_RDP: - if (virDomainGraphicsRDPDefFormatAttr(buf, &def->data.rdp, def, NU= LL)) - return -1; - - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: - if (virDomainGraphicsDesktopDefFormatAttr(buf, &def->data.desktop,= def, NULL) < 0) - return -1; - - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: - if (virDomainGraphicsSpiceDefFormatAttr(buf, &def->data.spice, def= , &flags) < 0) - return -1; - - break; - - case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: - if (!def->data.egl_headless.rendernode) - break; - - if (!children) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children =3D true; - } - - if (virDomainGraphicsEGLHeadlessDefFormatElem(buf, &def->data.egl_= headless, def, NULL) < 0) - return -1; - - break; - case VIR_DOMAIN_GRAPHICS_TYPE_NONE: - case VIR_DOMAIN_GRAPHICS_TYPE_LAST: - break; - } - - for (i =3D 0; i < def->nListens; i++) { - if (!virDomainGraphicsListenDefValid(&def->listens[i], def, flags)) - continue; - - if (!children) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children =3D true; - } - - virDomainGraphicsListenDefFormatBuf(buf, "listen", - &def->listens[i], def, &flags); - } - - if (def->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { - if (virDomainGraphicsSpiceDefFormatElem(buf, &def->data.spice, def= , NULL) < 0) - return -1; - } - - if (children) { - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } - - return 0; -} - =20 static int virDomainHostdevDefFormat(virBufferPtr buf, @@ -29539,7 +29397,9 @@ virDomainDefFormatInternalSetRootName(virDomainDefP= tr def, } =20 for (n =3D 0; n < def->ngraphics; n++) { - if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0) + if (virDomainGraphicsDefFormatBuf(buf, "graphics", + def->graphics[n], + def, &flags) < 0) return -1; } =20 @@ -30696,7 +30556,9 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, rc =3D virDomainControllerDefFormat(&buf, src->data.controller, fl= ags); break; case VIR_DOMAIN_DEVICE_GRAPHICS: - rc =3D virDomainGraphicsDefFormat(&buf, src->data.graphics, flags); + rc =3D virDomainGraphicsDefFormatBuf(&buf, "graphics", + src->data.graphics, + src, &flags); break; case VIR_DOMAIN_DEVICE_HUB: rc =3D virDomainHubDefFormat(&buf, src->data.hub, flags); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b6d69fa..166ba2a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1751,7 +1751,7 @@ struct _virDomainGraphicsEGLHeadlessDef { /* genpar= se, genformat:separate */ char *rendernode; /* xmlattr:gl/rendernode */ }; =20 -struct _virDomainGraphicsDef { /* genparse:concisehook */ +struct _virDomainGraphicsDef { /* genparse:concisehook, genformat */ virObjectPtr privateData; =20 /* Port value discipline: @@ -1760,6 +1760,13 @@ struct _virDomainGraphicsDef { /* genparse:conc= isehook */ * Positive value is actual port number given in XML. */ virDomainGraphicsType type; /* xmlattr */ + + /* nListens, listens, and *port are only useful if type is vnc, + * rdp, or spice. They've been extracted from the union only to + * simplify parsing code.*/ + size_t nListens; + virDomainGraphicsListenDefPtr listens; /* xmlelem, array:nListens */ + union { virDomainGraphicsSDLDef sdl; /* xmlgroup */ virDomainGraphicsVNCDef vnc; /* xmlgroup */ @@ -1768,11 +1775,6 @@ struct _virDomainGraphicsDef { /* genparse:conc= isehook */ virDomainGraphicsSpiceDef spice; /* xmlgroup */ virDomainGraphicsEGLHeadlessDef egl_headless; /* xmlgroup */ } data; /* xmlswitch:type */ - /* nListens, listens, and *port are only useful if type is vnc, - * rdp, or spice. They've been extracted from the union only to - * simplify parsing code.*/ - size_t nListens; - virDomainGraphicsListenDefPtr listens; /* xmlelem, array:nListens */ }; =20 typedef enum { --=20 2.25.1