From nobody Fri May 3 08:33:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1501258775597331.0690908263381; Fri, 28 Jul 2017 09:19:35 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id A60515C15E; Fri, 28 Jul 2017 16:19:33 +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 227506F444; Fri, 28 Jul 2017 16:19:33 +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 7779B1805977; Fri, 28 Jul 2017 16:19:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6SGJTqh007505 for ; Fri, 28 Jul 2017 12:19:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8300D53CFB; Fri, 28 Jul 2017 16:19:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C0557093A for ; Fri, 28 Jul 2017 16:19:27 +0000 (UTC) Received: from mail-qk0-f180.google.com (mail-qk0-f180.google.com [209.85.220.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5ADBC4482C for ; Fri, 28 Jul 2017 16:19:26 +0000 (UTC) Received: by mail-qk0-f180.google.com with SMTP id x191so55002526qka.5 for ; Fri, 28 Jul 2017 09:19:26 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id c19sm5744501qkg.6.2017.07.28.09.19.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jul 2017 09:19:24 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A60515C15E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A60515C15E Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="M44/gtxJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5ADBC4482C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5ADBC4482C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=CJz25J6AW0ApRzi9eL+gVxVq1w+OfUq3oVQD9OItoWY=; b=M44/gtxJyEX1B1jl+7w2JSiaVaSfScTC+35MEAsulg7Yzs8QAL4VlKClASuUQTqOCy hoJS/duLrR8ISS5YoWmSvLi/UQaAgXv4iw0Um74Q2FbTtyYzY9LcSSTzp29IjDX6WVHv UEsJLuxoEbMJGJkaozAQzIFC52Wnrq0UWqZVt8ZPLg+FH0SIWfemqGogkn3zwELHH77M X/JTSuaef/1qnPfvCdQ1mAmvBiME9ZH0LvvK8jF89pzeBEFnhhp/2PTQ182yXzkufutT LN5JCPrYPGLzz+mx+WVyxFGrHlBnOhWzHFvjvXbv46KQ7BXGbzcSmWrsfSrzpJJSRxKg p+Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=CJz25J6AW0ApRzi9eL+gVxVq1w+OfUq3oVQD9OItoWY=; b=UNveBLTmLfwFesgNI3s/t/L/R3bQ4BT0kRNKNascE46oqDY7DCdgSaAf/VixbTX5sE CBXYpXqSoZSC8ASCMCBJCerhAI8CSY34ONQZpKgaV7Pvj58Zz5QPUgoe3uuXvrxSimZK YtLnYunjJ9oTcQg5RCXHRHbRcSvmvjh7En426GL/ut5RizU9ujBFOCnH5L1UcF9WHrEX dbeFGHcUhS06GyQhBqCqWQPhGqSV6PVgh6JDOaYpQFX2KTzJTZHPRBxNgtxwlmDNqtsK q7gazhEYjTMxkPgUSwEi4L/pW3fEJQ8yepGD76YhFLeC/YSd7I5xuyoiR8sC4vsjxzM+ oslg== X-Gm-Message-State: AIVw113N7ASZ86kXlywVZyg0DJHe+ySo+OntqG+9fTUXoZRQmlZhDd1u eioVbFgb3GpHzn2u3PE= X-Received: by 10.55.159.21 with SMTP id i21mr10203330qke.27.1501258765317; Fri, 28 Jul 2017 09:19:25 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Fri, 28 Jul 2017 12:19:19 -0400 Message-Id: <20170728161919.3513-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Jul 2017 16:19:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Jul 2017 16:19:26 +0000 (UTC) for IP:'209.85.220.180' DOMAIN:'mail-qk0-f180.google.com' HELO:'mail-qk0-f180.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: -0.331 (DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.220.180 mail-qk0-f180.google.com 209.85.220.180 mail-qk0-f180.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] hyperv: Reduce usage of libxml API functions 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Jul 2017 16:19:34 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Slight refactor of the WMI serialization code to minimize mixing openwsman and libxml2 APIs. The only usage of libxml2 APIs now is in creating CDATA blocks, because the openwsman API does not provide that functionality. --- src/hyperv/hyperv_wmi.c | 65 ++++++++++++---------------------------------= ---- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 57125ae..99efa1c 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -489,17 +489,14 @@ hypervSerializeSimpleParam(hypervParamPtr p, const ch= ar *resourceUri, =20 static int hypervSerializeEprParam(hypervParamPtr p, hypervPrivate *priv, - const char *resourceUri, WsXmlDocH doc, WsXmlNodeH *methodNode) + const char *resourceUri, WsXmlNodeH *methodNode) { int result =3D -1; WsXmlNodeH xmlNodeParam =3D NULL, xmlNodeTemp =3D NULL, xmlNodeAddr =3D NULL, xmlNodeRef =3D NULL; - xmlNodePtr xmlNodeAddrPtr =3D NULL, - xmlNodeRefPtr =3D NULL; WsXmlDocH xmlDocResponse =3D NULL; - xmlDocPtr docPtr =3D (xmlDocPtr) doc->parserDoc; WsXmlNsH ns =3D NULL; client_opt_t *options =3D NULL; filter_t *filter =3D NULL; @@ -573,11 +570,6 @@ hypervSerializeEprParam(hypervParamPtr p, hypervPrivat= e *priv, goto cleanup; } =20 - if (!(xmlNodeAddrPtr =3D xmlDocCopyNode((xmlNodePtr) xmlNodeAddr, docP= tr, 1))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not copy EPR= address")); - goto cleanup; - } - if (!(xmlNodeRef =3D ws_xml_get_child(xmlNodeTemp, 0, XML_NS_ADDRESSIN= G, WSA_REFERENCE_PARAMETERS))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -585,17 +577,11 @@ hypervSerializeEprParam(hypervParamPtr p, hypervPriva= te *priv, goto cleanup; } =20 - if (!(xmlNodeRefPtr =3D xmlDocCopyNode((xmlNodePtr) xmlNodeRef, docPtr= , 1))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not copy EPR item reference parameters")); - goto cleanup; - } - /* now build a new xml doc with the EPR node children */ if (!(xmlNodeParam =3D ws_xml_add_child(*methodNode, resourceUri, p->epr.name, NULL))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not add child node to xmlNodeParam")); + _("Could not add child node to methodNode")); goto cleanup; } =20 @@ -613,23 +599,8 @@ hypervSerializeEprParam(hypervParamPtr p, hypervPrivat= e *priv, goto cleanup; } =20 - if (xmlAddChild((xmlNodePtr) *methodNode, (xmlNodePtr) xmlNodeParam) = =3D=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not add child to xml parent node")); - goto cleanup; - } - - if (xmlAddChild((xmlNodePtr) xmlNodeParam, xmlNodeAddrPtr) =3D=3D NULL= ) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not add child to xml parent node")); - goto cleanup; - } - - if (xmlAddChild((xmlNodePtr) xmlNodeParam, xmlNodeRefPtr) =3D=3D NULL)= { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not add child to xml parent node")); - goto cleanup; - } + ws_xml_duplicate_tree(xmlNodeParam, xmlNodeAddr); + ws_xml_duplicate_tree(xmlNodeParam, xmlNodeRef); =20 /* we did it! */ result =3D 0; @@ -656,8 +627,7 @@ hypervSerializeEmbeddedParam(hypervParamPtr p, const ch= ar *resourceUri, xmlNodeArray =3D NULL; WsXmlDocH xmlDocTemp =3D NULL, xmlDocCdata =3D NULL; - xmlBufferPtr xmlBufferNode =3D NULL; - const xmlChar *xmlCharCdataContent =3D NULL; + char *xmlCharCdataContent =3D NULL; xmlNodePtr xmlNodeCdata =3D NULL; hypervWmiClassInfoPtr classInfo =3D p->embedded.info; virHashKeyValuePairPtr items =3D NULL; @@ -761,25 +731,22 @@ hypervSerializeEmbeddedParam(hypervParamPtr p, const = char *resourceUri, } =20 /* create CDATA node */ - xmlBufferNode =3D xmlBufferCreate(); - if (xmlNodeDump(xmlBufferNode, (xmlDocPtr) xmlDocTemp->parserDoc, - (xmlNodePtr) xmlNodeInstance, 0, 0) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Could not get root of temp XML doc")); - goto cleanup; - } + ws_xml_dump_memory_node_tree(xmlNodeInstance, &xmlCharCdataContent, &l= en); =20 - len =3D xmlBufferLength(xmlBufferNode); - xmlCharCdataContent =3D xmlBufferContent(xmlBufferNode); if (!(xmlNodeCdata =3D xmlNewCDataBlock((xmlDocPtr) xmlDocCdata, - xmlCharCdataContent, len))) { + (xmlChar *)xmlCharCdataContent, len))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not create CDATA element")); goto cleanup; } =20 - /* Add CDATA node to the doc root */ - if (!(xmlAddChild((xmlNodePtr) xmlNodeParam, xmlNodeCdata))) { + /* + * Add CDATA node to the doc root + * + * FIXME: there is no openwsman wrapper for xmlNewCDataBlock, so inste= ad + * silence clang by casting to a void pointer first + */ + if (!(xmlAddChild((xmlNodePtr)(void *)xmlNodeParam, xmlNodeCdata))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add CDATA to doc root")); goto cleanup; @@ -792,7 +759,7 @@ hypervSerializeEmbeddedParam(hypervParamPtr p, const ch= ar *resourceUri, VIR_FREE(items); ws_xml_destroy_doc(xmlDocCdata); ws_xml_destroy_doc(xmlDocTemp); - xmlBufferFree(xmlBufferNode); + ws_xml_free_memory(xmlCharCdataContent); return result; } =20 @@ -854,7 +821,7 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokePar= amsListPtr params, break; case HYPERV_EPR_PARAM: if (hypervSerializeEprParam(p, priv, params->resourceUri, - paramsDocRoot, &methodNode) < 0) + &methodNode) < 0) goto cleanup; break; case HYPERV_EMBEDDED_PARAM: --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list