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;
|
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
|
bool
|
||||||
qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src);
|
qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src);
|
||||||
|
|
||||||
|
char *
|
||||||
|
qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src);
|
||||||
|
@ -1747,18 +1747,7 @@ qemuDomainSecretStorageSourcePrepareCookies(qemuDomainObjPrivatePtr priv,
|
|||||||
const char *aliasprotocol)
|
const char *aliasprotocol)
|
||||||
{
|
{
|
||||||
g_autofree char *secretalias = qemuAliasForSecret(aliasprotocol, "httpcookie");
|
g_autofree char *secretalias = qemuAliasForSecret(aliasprotocol, "httpcookie");
|
||||||
g_autofree char *cookies = NULL;
|
g_autofree char *cookies = qemuBlockStorageSourceGetCookieString(src);
|
||||||
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);
|
|
||||||
|
|
||||||
return qemuDomainSecretAESSetup(priv, secretalias, NULL,
|
return qemuDomainSecretAESSetup(priv, secretalias, NULL,
|
||||||
(uint8_t *) cookies, strlen(cookies));
|
(uint8_t *) cookies, strlen(cookies));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user