From nobody Sun Feb 8 22:07:42 2026 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1583771060; cv=none; d=zohomail.com; s=zohoarc; b=UORE3VrH8FEqYgIRHC6ZuZZJy20q1LxmEQ7gt9fsaCnPpqar2fKEqIxvRXSnkQgjl3pig1MKzdRTzJ8KQsR1lcncHEP2wxGBitbv5gwYy93OrM6n4rf5YlYNY7jb9B1TSLAOkNVsIiU4MfM9FaoWGD4ZAvq83LZo4BJ5a0ayoaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583771060; 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=YxObQNXr2PX1sO/JnvHlRgy41q+NgoXBE4g2H87SSaY=; b=iQu414AWfdr9Gdunt7TwgAJHUYNXHnyNWZRkZ809danrFpoarXawzfNdGMC+QCJZqDDmpvwsL6Y/BL//UotGsWwu7A9bvzDy23BUnITUqQh4Y144OxlhUOY9labxgrWZVQ2scKJFqNIKDfim/+odCFYi3ABBcx5fZa5PYkrwEaI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1583771060212643.0756826162091; Mon, 9 Mar 2020 09:24:20 -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-155-SzpXnIkNOnesh5Gw6ESu1g-1; Mon, 09 Mar 2020 12:24:15 -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 970A5801E6C; Mon, 9 Mar 2020 16:24: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 7084C5C3F8; Mon, 9 Mar 2020 16:24: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 1FBE718034FB; Mon, 9 Mar 2020 16:24:06 +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 029GNeMd020912 for ; Mon, 9 Mar 2020 12:23:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 820D6909E9; Mon, 9 Mar 2020 16:23:40 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0992290779 for ; Mon, 9 Mar 2020 16:23:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583771059; 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=YxObQNXr2PX1sO/JnvHlRgy41q+NgoXBE4g2H87SSaY=; b=PJ3oGCRc+q1zHgEX7Kahs446HreFCCuEHHiRXLZinADJnVIX3h4hvLmOfxPBviO4mlqX/q zbcFvRSRzrHIMUSKhvTT4VWPSrjD+wY15EK3yTIHI4whGg1lwWOWvkYW3eBPymqvCWCRUA i9l6UNbLu5EtZEh8iA5F9wEuGFv2Mkk= X-MC-Unique: SzpXnIkNOnesh5Gw6ESu1g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 24/30] virstoragefile: Add JSON parser for 'sslverify', 'readahead', 'cookies' and 'timeout' Date: Mon, 9 Mar 2020 17:23:04 +0100 Message-Id: <09f4209798ed6de3bf0d351345a08a65ddb299f6.1583770683.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add support for parsing the recently added fields from backing file pseudo-protocol strings. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virstoragefile.c | 91 ++++++++++++++++++++++++++++++++++++++- tests/qemublocktest.c | 6 +++ tests/virstoragetest.c | 15 +++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 9e740419eb..efc4c60681 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3210,10 +3210,61 @@ virStorageSourceParseBackingJSONUriStr(virStorageSo= urcePtr src, } +static int +virStorageSourceParseBackingJSONUriCookies(virStorageSourcePtr src, + virJSONValuePtr json, + const char *jsonstr) +{ + const char *cookiestr; + VIR_AUTOSTRINGLIST cookies =3D NULL; + size_t ncookies =3D 0; + size_t i; + + if (!virJSONValueObjectHasKey(json, "cookie")) + return 0; + + if (!(cookiestr =3D virJSONValueObjectGetString(json, "cookie"))) { + virReportError(VIR_ERR_INVALID_ARG, + _("wrong format of 'cookie' field in backing store = definition '%s'"), + jsonstr); + return -1; + } + + if (!(cookies =3D virStringSplitCount(cookiestr, ";", 0, &ncookies))) + return -1; + + src->cookies =3D g_new0(virStorageNetCookieDefPtr, ncookies); + src->ncookies =3D ncookies; + + for (i =3D 0; i < ncookies; i++) { + char *cookiename =3D cookies[i]; + char *cookievalue; + + virSkipSpaces((const char **) &cookiename); + + if (!(cookievalue =3D strchr(cookiename, '=3D'))) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed http cookie '%s' in backing store = definition '%s'"), + cookies[i], jsonstr); + return -1; + } + + *cookievalue =3D '\0'; + cookievalue++; + + src->cookies[i] =3D g_new0(virStorageNetCookieDef, 1); + src->cookies[i]->name =3D g_strdup(cookiename); + src->cookies[i]->value =3D g_strdup(cookievalue); + } + + return 0; +} + + static int virStorageSourceParseBackingJSONUri(virStorageSourcePtr src, virJSONValuePtr json, - const char *jsonstr G_GNUC_UNUSED, + const char *jsonstr, int protocol) { const char *uri; @@ -3224,6 +3275,44 @@ virStorageSourceParseBackingJSONUri(virStorageSource= Ptr src, return -1; } + if (protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS || + protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_FTPS) { + if (virJSONValueObjectHasKey(json, "sslverify")) { + bool tmp; + + if (virJSONValueObjectGetBoolean(json, "sslverify", &tmp) < 0)= { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed 'sslverify' field in backing s= tore definition '%s'"), + jsonstr); + return -1; + } + + src->sslverify =3D virTristateBoolFromBool(tmp); + } + } + + if (protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTPS || + protocol =3D=3D VIR_STORAGE_NET_PROTOCOL_HTTP) { + if (virStorageSourceParseBackingJSONUriCookies(src, json, jsonstr)= < 0) + return -1; + } + + if (virJSONValueObjectHasKey(json, "readahead") && + virJSONValueObjectGetNumberUlong(json, "readahead", &src->readahea= d) < 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed 'readahead' field in backing store def= inition '%s'"), + jsonstr); + return -1; + } + + if (virJSONValueObjectHasKey(json, "timeout") && + virJSONValueObjectGetNumberUlong(json, "timeout", &src->timeout) <= 0) { + virReportError(VIR_ERR_INVALID_ARG, + _("malformed 'timeout' field in backing store defin= ition '%s'"), + jsonstr); + return -1; + } + return virStorageSourceParseBackingJSONUriStr(src, uri, protocol); } diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 7b7948d4c6..96a3c7fc41 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -917,6 +917,12 @@ mymain(void) TEST_JSON_FORMAT_NET("\n" " \n" "\n"); + TEST_JSON_FORMAT_NET("\n" + " \n" + " \n" + " \n" + " \n" + "\n"); TEST_JSON_FORMAT_NET("\= n" " \n" "\n"); diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 97c22d42af..b49dfd2598 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -1607,6 +1607,21 @@ mymain(void) " \n" "\n", 0); + TEST_BACKING_PARSE_FULL("json:{ \"file.cookie\": \"vmware_soap_session= =3D\\\"0c8db85112873a79b7ef74f294cb70ef7f\\\"\"," + "\"file.sslverify\": false," + "\"file.driver\": \"https\"," + "\"file.url\": \"https://host/folder/es= x6.5-rhel7.7-x86%5f64/esx6.5-rhel7.7-x86%5f64-flat.vmdk?dcPath=3Ddata&dsNam= e=3Desx6.5-matrix\"," + "\"file.timeout\": 2000" + "}", + "\n" + " \n" + " \n" + " \n" + " "= ;0c8db85112873a79b7ef74f294cb70ef7f"\n" + " \n" + " \n" + "\n", 0); + #endif /* WITH_YAJL */ cleanup: --=20 2.24.1