From nobody Tue Feb 10 01:15:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1666621158; cv=none; d=zohomail.com; s=zohoarc; b=Hi4uyBHNO0+m/+7PmVpJTPhxGBecO8KGT7Zn7FCnl8eQEe1feUJvG1s5g+h+kNQL85ZiZUmJeOyyeeTZGpRqwOzS5P7P2+at6cSjn1FrnEUQNvrQ9iV8EupBHrPy3zF6Ol4DxfyVnVMe9bFBAbr5JH+2wPXPkMzHe9NeKFj4Ihw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666621158; 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=xy2k7Bh2F2SCV1+cZFZhflGEEFQgONOMbTf5f09qK0Q=; b=SJ7GHebO6F/SY4i5RMt7YZ32BHuBi0XaH+a5MylVeLQiR+GFFD6P1rVHxpi/yuPrTEz9GA5j0ImMr8rnHkdV/SilvjVEBjOsyiBNraVK1GG83OoH1JDQD0mp9xgQRVW2updaAUK4alslZ1fRvRU0viJwCu4O/cfGG9O6f5GLWqc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1666621158735534.794096715904; Mon, 24 Oct 2022 07:19:18 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-gyxEO4ZsPje3zZNd4IH_KA-1; Mon, 24 Oct 2022 10:15:55 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C6B25857F92; Mon, 24 Oct 2022 14:15:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3BF8C16922; Mon, 24 Oct 2022 14:15:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 98EA41946594; Mon, 24 Oct 2022 14:15:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D517B194658D for ; Mon, 24 Oct 2022 14:15:08 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C785C40C2140; Mon, 24 Oct 2022 14:15:08 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44BFE40C83AA for ; Mon, 24 Oct 2022 14:15:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666621157; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xy2k7Bh2F2SCV1+cZFZhflGEEFQgONOMbTf5f09qK0Q=; b=YL3shmOcXpKc4YcjzdhydlpOd6R4ICp+sRZPNu6nAz/zDiYX6SNio+p80D1HCv/n+E2uO0 mCDvsZAiKos+cNtTShHtF6iVUSYVvlFmn7Tr4kvwv7gPd0lZ2Cmuq9Y6P0uYWpg1YGcaV+ KTFFLId3F9mIAgaNJy1VToHmOVeh4NI= X-MC-Unique: gyxEO4ZsPje3zZNd4IH_KA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/43] util: xml: Extract XPath evaluation for strings Date: Mon, 24 Oct 2022 16:14:15 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666621159640100001 Content-Type: text/plain; charset="utf-8" Extract the internals of virXPathString which evaluate the XPath and validate that the returned object is a string into a new helper named 'virXPathEvalString'. The function will be later reused in the number XPath evaluation functions. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virxml.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index e771471dd7..aec475ccfd 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -60,6 +60,34 @@ virXMLXPathContextNew(xmlDocPtr xml) } +static xmlXPathObject * +virXPathEvalString(const char *xpath, + xmlXPathContextPtr ctxt) +{ + g_autoptr(xmlXPathObject) obj =3D NULL; + + if (!xpath) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing XPath expr= ession")); + return NULL; + } + + if (!ctxt) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing XPath cont= ext")); + return NULL; + } + + if (!(obj =3D xmlXPathEval(BAD_CAST xpath, ctxt))) + return NULL; + + if (obj->type !=3D XPATH_STRING || + !obj->stringval || + obj->stringval[0] =3D=3D '\0') + return NULL; + + return g_steal_pointer(&obj); +} + + /** * virXPathString: * @xpath: the XPath string to evaluate @@ -76,16 +104,9 @@ virXPathString(const char *xpath, { g_autoptr(xmlXPathObject) obj =3D NULL; - if ((ctxt =3D=3D NULL) || (xpath =3D=3D NULL)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Invalid parameter to virXPathString()")); + if (!(obj =3D virXPathEvalString(xpath, ctxt))) return NULL; - } - obj =3D xmlXPathEval(BAD_CAST xpath, ctxt); - if ((obj =3D=3D NULL) || (obj->type !=3D XPATH_STRING) || - (obj->stringval =3D=3D NULL) || (obj->stringval[0] =3D=3D 0)) { - return NULL; - } + return g_strdup((char *)obj->stringval); } --=20 2.37.3