mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 15:27:47 +00:00
qemu: block: Extract formatting of cookie string
Introduce qemuBlockStorageSourceGetCookieString which does the concatenation so that we can reuse it later. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
7ba2208add
commit
bafd2e94fa
@ -3343,3 +3343,28 @@ qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuBlockStorageSourceGetCookieString:
|
||||
* @src: storage source
|
||||
*
|
||||
* Returns a properly formatted string representing cookies of @src in format
|
||||
* accepted by qemu.
|
||||
*/
|
||||
char *
|
||||
qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < src->ncookies; i++) {
|
||||
virStorageNetCookieDefPtr cookie = src->cookies[i];
|
||||
|
||||
virBufferAsprintf(&buf, "%s=%s; ", cookie->name, cookie->value);
|
||||
}
|
||||
|
||||
virBufferTrim(&buf, "; ");
|
||||
|
||||
return virBufferContentAndReset(&buf);
|
||||
}
|
||||
|
@ -258,3 +258,6 @@ qemuBlockReopenReadOnly(virDomainObjPtr vm,
|
||||
|
||||
bool
|
||||
qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src);
|
||||
|
||||
char *
|
||||
qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src);
|
||||
|
@ -1747,18 +1747,7 @@ qemuDomainSecretStorageSourcePrepareCookies(qemuDomainObjPrivatePtr priv,
|
||||
const char *aliasprotocol)
|
||||
{
|
||||
g_autofree char *secretalias = qemuAliasForSecret(aliasprotocol, "httpcookie");
|
||||
g_autofree char *cookies = NULL;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < src->ncookies; i++) {
|
||||
virStorageNetCookieDefPtr cookie = src->cookies[i];
|
||||
|
||||
virBufferAsprintf(&buf, "%s=%s; ", cookie->name, cookie->value);
|
||||
}
|
||||
|
||||
virBufferTrim(&buf, "; ");
|
||||
cookies = virBufferContentAndReset(&buf);
|
||||
g_autofree char *cookies = qemuBlockStorageSourceGetCookieString(src);
|
||||
|
||||
return qemuDomainSecretAESSetup(priv, secretalias, NULL,
|
||||
(uint8_t *) cookies, strlen(cookies));
|
||||
|
Loading…
Reference in New Issue
Block a user