Use a separate buffer for <input> subelements

Instead of figuring out upfront whether <input> will be a single
or a pair element, format the subelements into a separate buffer
and close <input/> early if this buffer is empty.
This commit is contained in:
Ján Tomko 2016-08-08 15:38:20 +02:00
parent a94d431dc4
commit 51219e11b8
1 changed files with 11 additions and 10 deletions

View File

@ -23036,6 +23036,7 @@ virDomainInputDefFormat(virBufferPtr buf,
{
const char *type = virDomainInputTypeToString(def->type);
const char *bus = virDomainInputBusTypeToString(def->bus);
virBuffer childbuf = VIR_BUFFER_INITIALIZER;
/* don't format keyboard into migratable XML for backward compatibility */
if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE &&
@ -23058,17 +23059,17 @@ virDomainInputDefFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<input type='%s' bus='%s'",
type, bus);
if (virDomainDeviceInfoNeedsFormat(&def->info, flags) ||
def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) {
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<source evdev='%s'/>\n", def->source.evdev);
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</input>\n");
} else {
virBufferAdjustIndent(&childbuf, virBufferGetIndent(buf, false) + 2);
virBufferEscapeString(&childbuf, "<source evdev='%s'/>\n", def->source.evdev);
if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0)
return -1;
if (!virBufferUse(&childbuf)) {
virBufferAddLit(buf, "/>\n");
} else {
virBufferAddLit(buf, ">\n");
virBufferAddBuffer(buf, &childbuf);
virBufferAddLit(buf, "</input>\n");
}
return 0;