Introduce qemuBlockStorageSourceGetCookieString which does the concatenation so that we can reuse it later. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_block.c | 25 +++++++++++++++++++++++++ src/qemu/qemu_block.h | 3 +++ src/qemu/qemu_domain.c | 13 +------------ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 3365ee677b..d9665ec4a0 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -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); +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index 9bffe20bfb..8b57ffd8a5 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -258,3 +258,6 @@ qemuBlockReopenReadOnly(virDomainObjPtr vm, bool qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src); + +char * +qemuBlockStorageSourceGetCookieString(virStorageSourcePtr src); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9cff36cb77..b55765c8ee 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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)); -- 2.24.1