From patchwork Sun May 15 19:11:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 67814 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1206528qge; Sun, 15 May 2016 12:16:08 -0700 (PDT) X-Received: by 10.140.104.48 with SMTP id z45mr25764017qge.49.1463339768354; Sun, 15 May 2016 12:16:08 -0700 (PDT) Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id b1si20194508qge.47.2016.05.15.12.16.07 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 15 May 2016 12:16:08 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u4FJBZLE025273; Sun, 15 May 2016 15:11:35 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u4FJBWrC005998 for ; Sun, 15 May 2016 15:11:32 -0400 Received: from colepc.redhat.com (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4FJBVPi015799; Sun, 15 May 2016 15:11:32 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Sun, 15 May 2016 15:11:26 -0400 Message-Id: <91732e3293e52a92698aff3a474cd29bdb8249ef.1463339181.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Andrea Bolognani Subject: [libvirt] [PATCH v2 1/4] util: xml: add virXMLPropertyCount 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 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com Returns an integer count of the number of XML properties an element has. Will be used in future patches. --- src/libvirt_private.syms | 1 + src/util/virxml.c | 17 +++++++++++++++++ src/util/virxml.h | 1 + 3 files changed, 19 insertions(+) -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fb24808..40b70a1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2550,6 +2550,7 @@ virXMLExtractNamespaceXML; virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; +virXMLPropertyCount; virXMLPropString; virXMLSaveFile; virXMLValidateAgainstSchema; diff --git a/src/util/virxml.c b/src/util/virxml.c index 489bad8..86c021c 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -890,6 +890,23 @@ virXMLChildElementCount(xmlNodePtr node) return ret; } +/* Returns the number of node's properties, or -1 on error. */ +long +virXMLPropertyCount(xmlNodePtr node) +{ + long ret = 0; + xmlAttrPtr cur = NULL; + + if (!node || node->type != XML_ELEMENT_NODE) + return -1; + cur = node->properties; + while (cur) { + ret++; + cur = cur->next; + } + return ret; +} + /** * virXMLNodeToString: convert an XML node ptr to an XML string diff --git a/src/util/virxml.h b/src/util/virxml.h index b94de74..5cf082e 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -72,6 +72,7 @@ int virXPathNodeSet(const char *xpath, char * virXMLPropString(xmlNodePtr node, const char *name); long virXMLChildElementCount(xmlNodePtr node); +long virXMLPropertyCount(xmlNodePtr node); /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode,