Convert virDomainSoundDefFormat to use a separate buffer
for subelements.
---
src/conf/domain_conf.c | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ead94976d..6c4f2f398 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23158,38 +23158,32 @@ virDomainSoundDefFormat(virBufferPtr buf,
unsigned int flags)
{
const char *model = virDomainSoundModelTypeToString(def->model);
- bool children = false;
+ virBuffer childBuf = VIR_BUFFER_INITIALIZER;
size_t i;
+ virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2);
+
if (!model) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sound model %d"), def->model);
return -1;
}
- virBufferAsprintf(buf, "<sound model='%s'", model);
+ for (i = 0; i < def->ncodecs; i++)
+ virDomainSoundCodecDefFormat(&childBuf, def->codecs[i]);
- for (i = 0; i < def->ncodecs; i++) {
- if (!children) {
- virBufferAddLit(buf, ">\n");
- virBufferAdjustIndent(buf, 2);
- children = true;
- }
- virDomainSoundCodecDefFormat(buf, def->codecs[i]);
+ if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) {
+ virBufferFreeAndReset(&childBuf);
+ return -1;
}
- if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) {
- if (!children) {
- virBufferAddLit(buf, ">\n");
- virBufferAdjustIndent(buf, 2);
- children = true;
- }
- if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
- return -1;
- }
+ if (virBufferCheckError(&childBuf) < 0)
+ return -1;
- if (children) {
- virBufferAdjustIndent(buf, -2);
+ virBufferAsprintf(buf, "<sound model='%s'", model);
+ if (virBufferUse(&childBuf)) {
+ virBufferAddLit(buf, ">\n");
+ virBufferAddBuffer(buf, &childBuf);
virBufferAddLit(buf, "</sound>\n");
} else {
virBufferAddLit(buf, "/>\n");
--
2.13.0