mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
virstoragefile: Add JSON parser for 'sslverify', 'readahead', 'cookies' and 'timeout'
Add support for parsing the recently added fields from backing file pseudo-protocol strings. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
9cac141cd6
commit
77194db01c
@ -3210,10 +3210,61 @@ virStorageSourceParseBackingJSONUriStr(virStorageSourcePtr src,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virStorageSourceParseBackingJSONUriCookies(virStorageSourcePtr src,
|
||||
virJSONValuePtr json,
|
||||
const char *jsonstr)
|
||||
{
|
||||
const char *cookiestr;
|
||||
VIR_AUTOSTRINGLIST cookies = NULL;
|
||||
size_t ncookies = 0;
|
||||
size_t i;
|
||||
|
||||
if (!virJSONValueObjectHasKey(json, "cookie"))
|
||||
return 0;
|
||||
|
||||
if (!(cookiestr = virJSONValueObjectGetString(json, "cookie"))) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("wrong format of 'cookie' field in backing store definition '%s'"),
|
||||
jsonstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(cookies = virStringSplitCount(cookiestr, ";", 0, &ncookies)))
|
||||
return -1;
|
||||
|
||||
src->cookies = g_new0(virStorageNetCookieDefPtr, ncookies);
|
||||
src->ncookies = ncookies;
|
||||
|
||||
for (i = 0; i < ncookies; i++) {
|
||||
char *cookiename = cookies[i];
|
||||
char *cookievalue;
|
||||
|
||||
virSkipSpaces((const char **) &cookiename);
|
||||
|
||||
if (!(cookievalue = strchr(cookiename, '='))) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("malformed http cookie '%s' in backing store definition '%s'"),
|
||||
cookies[i], jsonstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*cookievalue = '\0';
|
||||
cookievalue++;
|
||||
|
||||
src->cookies[i] = g_new0(virStorageNetCookieDef, 1);
|
||||
src->cookies[i]->name = g_strdup(cookiename);
|
||||
src->cookies[i]->value = 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(virStorageSourcePtr src,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS ||
|
||||
protocol == 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 store definition '%s'"),
|
||||
jsonstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
src->sslverify = virTristateBoolFromBool(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
if (protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS ||
|
||||
protocol == VIR_STORAGE_NET_PROTOCOL_HTTP) {
|
||||
if (virStorageSourceParseBackingJSONUriCookies(src, json, jsonstr) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (virJSONValueObjectHasKey(json, "readahead") &&
|
||||
virJSONValueObjectGetNumberUlong(json, "readahead", &src->readahead) < 0) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("malformed 'readahead' field in backing store definition '%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 definition '%s'"),
|
||||
jsonstr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return virStorageSourceParseBackingJSONUriStr(src, uri, protocol);
|
||||
}
|
||||
|
||||
|
@ -917,6 +917,12 @@ mymain(void)
|
||||
TEST_JSON_FORMAT_NET("<source protocol='https' name='file'>\n"
|
||||
" <host name='example.com' port='432'/>\n"
|
||||
"</source>\n");
|
||||
TEST_JSON_FORMAT_NET("<source protocol='https' name='file'>\n"
|
||||
" <host name='example.com' port='432'/>\n"
|
||||
" <ssl verify='no'/>\n"
|
||||
" <readahead size='1024'/>\n"
|
||||
" <timeout seconds='1337'/>\n"
|
||||
"</source>\n");
|
||||
TEST_JSON_FORMAT_NET("<source protocol='gluster' name='vol/file'>\n"
|
||||
" <host name='example.com' port='24007'/>\n"
|
||||
"</source>\n");
|
||||
|
@ -1607,6 +1607,21 @@ mymain(void)
|
||||
" </slices>\n"
|
||||
"</source>\n", 0);
|
||||
|
||||
TEST_BACKING_PARSE_FULL("json:{ \"file.cookie\": \"vmware_soap_session=\\\"0c8db85112873a79b7ef74f294cb70ef7f\\\"\","
|
||||
"\"file.sslverify\": false,"
|
||||
"\"file.driver\": \"https\","
|
||||
"\"file.url\": \"https://host/folder/esx6.5-rhel7.7-x86%5f64/esx6.5-rhel7.7-x86%5f64-flat.vmdk?dcPath=data&dsName=esx6.5-matrix\","
|
||||
"\"file.timeout\": 2000"
|
||||
"}",
|
||||
"<source protocol='https' name='folder/esx6.5-rhel7.7-x86_64/esx6.5-rhel7.7-x86_64-flat.vmdk'>\n"
|
||||
" <host name='host' port='443'/>\n"
|
||||
" <ssl verify='no'/>\n"
|
||||
" <cookies>\n"
|
||||
" <cookie name='vmware_soap_session'>"0c8db85112873a79b7ef74f294cb70ef7f"</cookie>\n"
|
||||
" </cookies>\n"
|
||||
" <timeout seconds='2000'/>\n"
|
||||
"</source>\n", 0);
|
||||
|
||||
#endif /* WITH_YAJL */
|
||||
|
||||
cleanup:
|
||||
|
Loading…
Reference in New Issue
Block a user