提交 bafd2e94 编写于 作者: P Peter Krempa

qemu: block: Extract formatting of cookie string

Introduce qemuBlockStorageSourceGetCookieString which does the
concatenation so that we can reuse it later.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 7ba2208a
......@@ -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));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册