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

util: sysinfo: Use virXMLFormatElement and infrastructure in virSysinfoFormat

It basically implements almost the same thing, so we can replace it with
existing helpers with a few tweaks.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 673f5e04
...@@ -1481,20 +1481,19 @@ virSysinfoOEMStringsFormat(virBufferPtr buf, virSysinfoOEMStringsDefPtr def) ...@@ -1481,20 +1481,19 @@ virSysinfoOEMStringsFormat(virBufferPtr buf, virSysinfoOEMStringsDefPtr def)
int int
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
{ {
virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; virBuffer childrenBuf = VIR_BUFFER_INITIALIZER;
const char *type = virSysinfoTypeToString(def->type); const char *type = virSysinfoTypeToString(def->type);
int indent = virBufferGetIndent(buf, false);
int ret = -1;
if (!type) { if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected sysinfo type model %d"), _("unexpected sysinfo type model %d"),
def->type); def->type);
virBufferFreeAndReset(buf); virBufferFreeAndReset(buf);
goto cleanup; return -1;
} }
virBufferAdjustIndent(&childrenBuf, indent + 2); virBufferSetChildIndent(&childrenBuf, buf);
virSysinfoBIOSFormat(&childrenBuf, def->bios); virSysinfoBIOSFormat(&childrenBuf, def->bios);
virSysinfoSystemFormat(&childrenBuf, def->system); virSysinfoSystemFormat(&childrenBuf, def->system);
...@@ -1504,22 +1503,17 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -1504,22 +1503,17 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
virSysinfoMemoryFormat(&childrenBuf, def); virSysinfoMemoryFormat(&childrenBuf, def);
virSysinfoOEMStringsFormat(&childrenBuf, def->oemStrings); virSysinfoOEMStringsFormat(&childrenBuf, def->oemStrings);
virBufferAsprintf(buf, "<sysinfo type='%s'", type); virBufferAsprintf(&attrBuf, " type='%s'", type);
if (virBufferUse(&childrenBuf)) {
virBufferAddLit(buf, ">\n"); if (virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf) < 0) {
virBufferAddBuffer(buf, &childrenBuf); virBufferFreeAndReset(buf);
virBufferAddLit(buf, "</sysinfo>\n"); return -1;
} else {
virBufferAddLit(buf, "/>\n");
} }
if (virBufferCheckError(buf) < 0) if (virBufferCheckError(buf) < 0)
goto cleanup; return -1;
ret = 0; return 0;
cleanup:
virBufferFreeAndReset(&childrenBuf);
return ret;
} }
#define CHECK_FIELD(name, desc) \ #define CHECK_FIELD(name, desc) \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册