You need to sign in or sign up before continuing.
提交 3f05dc6d 编写于 作者: L Laine Stump

util: eliminate hardcoded indent in virConnectSysInfo formatting

This same set of functions is used by the qemu, xen, and lxc drivers'
connectSysInfo function.
上级 acca9134
/* /*
* virsysinfo.c: get SMBIOS/sysinfo information from the host * virsysinfo.c: get SMBIOS/sysinfo information from the host
* *
* Copyright (C) 2010-2013 Red Hat, Inc. * Copyright (C) 2010-2014 Red Hat, Inc.
* Copyright (C) 2010 Daniel Veillard * Copyright (C) 2010 Daniel Veillard
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -880,16 +880,18 @@ virSysinfoBIOSFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -880,16 +880,18 @@ virSysinfoBIOSFormat(virBufferPtr buf, virSysinfoDefPtr def)
!def->bios_date && !def->bios_release) !def->bios_date && !def->bios_release)
return; return;
virBufferAddLit(buf, " <bios>\n"); virBufferAddLit(buf, "<bios>\n");
virBufferEscapeString(buf, " <entry name='vendor'>%s</entry>\n", virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<entry name='vendor'>%s</entry>\n",
def->bios_vendor); def->bios_vendor);
virBufferEscapeString(buf, " <entry name='version'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
def->bios_version); def->bios_version);
virBufferEscapeString(buf, " <entry name='date'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='date'>%s</entry>\n",
def->bios_date); def->bios_date);
virBufferEscapeString(buf, " <entry name='release'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='release'>%s</entry>\n",
def->bios_release); def->bios_release);
virBufferAddLit(buf, " </bios>\n"); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</bios>\n");
} }
static void static void
...@@ -900,22 +902,24 @@ virSysinfoSystemFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -900,22 +902,24 @@ virSysinfoSystemFormat(virBufferPtr buf, virSysinfoDefPtr def)
!def->system_uuid && !def->system_sku && !def->system_family) !def->system_uuid && !def->system_sku && !def->system_family)
return; return;
virBufferAddLit(buf, " <system>\n"); virBufferAddLit(buf, "<system>\n");
virBufferEscapeString(buf, " <entry name='manufacturer'>%s</entry>\n", virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<entry name='manufacturer'>%s</entry>\n",
def->system_manufacturer); def->system_manufacturer);
virBufferEscapeString(buf, " <entry name='product'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='product'>%s</entry>\n",
def->system_product); def->system_product);
virBufferEscapeString(buf, " <entry name='version'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='version'>%s</entry>\n",
def->system_version); def->system_version);
virBufferEscapeString(buf, " <entry name='serial'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='serial'>%s</entry>\n",
def->system_serial); def->system_serial);
virBufferEscapeString(buf, " <entry name='uuid'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='uuid'>%s</entry>\n",
def->system_uuid); def->system_uuid);
virBufferEscapeString(buf, " <entry name='sku'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='sku'>%s</entry>\n",
def->system_sku); def->system_sku);
virBufferEscapeString(buf, " <entry name='family'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='family'>%s</entry>\n",
def->system_family); def->system_family);
virBufferAddLit(buf, " </system>\n"); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</system>\n");
} }
static void static void
...@@ -940,8 +944,8 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -940,8 +944,8 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
!processor->processor_part_number) !processor->processor_part_number)
continue; continue;
virBufferAddLit(buf, " <processor>\n"); virBufferAddLit(buf, "<processor>\n");
virBufferAdjustIndent(buf, 4); virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, virBufferEscapeString(buf,
"<entry name='socket_destination'>%s</entry>\n", "<entry name='socket_destination'>%s</entry>\n",
processor->processor_socket_destination); processor->processor_socket_destination);
...@@ -965,8 +969,8 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -965,8 +969,8 @@ virSysinfoProcessorFormat(virBufferPtr buf, virSysinfoDefPtr def)
processor->processor_serial_number); processor->processor_serial_number);
virBufferEscapeString(buf, "<entry name='part_number'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='part_number'>%s</entry>\n",
processor->processor_part_number); processor->processor_part_number);
virBufferAdjustIndent(buf, -4); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, " </processor>\n"); virBufferAddLit(buf, "</processor>\n");
} }
} }
...@@ -991,34 +995,36 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -991,34 +995,36 @@ virSysinfoMemoryFormat(virBufferPtr buf, virSysinfoDefPtr def)
!memory->memory_part_number) !memory->memory_part_number)
continue; continue;
virBufferAddLit(buf, " <memory_device>\n"); virBufferAddLit(buf, "<memory_device>\n");
virBufferEscapeString(buf, " <entry name='size'>%s</entry>\n", virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<entry name='size'>%s</entry>\n",
memory->memory_size); memory->memory_size);
virBufferEscapeString(buf, virBufferEscapeString(buf,
" <entry name='form_factor'>%s</entry>\n", "<entry name='form_factor'>%s</entry>\n",
memory->memory_form_factor); memory->memory_form_factor);
virBufferEscapeString(buf, " <entry name='locator'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='locator'>%s</entry>\n",
memory->memory_locator); memory->memory_locator);
virBufferEscapeString(buf, virBufferEscapeString(buf,
" <entry name='bank_locator'>%s</entry>\n", "<entry name='bank_locator'>%s</entry>\n",
memory->memory_bank_locator); memory->memory_bank_locator);
virBufferEscapeString(buf, " <entry name='type'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='type'>%s</entry>\n",
memory->memory_type); memory->memory_type);
virBufferEscapeString(buf, virBufferEscapeString(buf,
" <entry name='type_detail'>%s</entry>\n", "<entry name='type_detail'>%s</entry>\n",
memory->memory_type_detail); memory->memory_type_detail);
virBufferEscapeString(buf, " <entry name='speed'>%s</entry>\n", virBufferEscapeString(buf, "<entry name='speed'>%s</entry>\n",
memory->memory_speed); memory->memory_speed);
virBufferEscapeString(buf, virBufferEscapeString(buf,
" <entry name='manufacturer'>%s</entry>\n", "<entry name='manufacturer'>%s</entry>\n",
memory->memory_manufacturer); memory->memory_manufacturer);
virBufferEscapeString(buf, virBufferEscapeString(buf,
" <entry name='serial_number'>%s</entry>\n", "<entry name='serial_number'>%s</entry>\n",
memory->memory_serial_number); memory->memory_serial_number);
virBufferEscapeString(buf, virBufferEscapeString(buf,
" <entry name='part_number'>%s</entry>\n", "<entry name='part_number'>%s</entry>\n",
memory->memory_part_number); memory->memory_part_number);
virBufferAddLit(buf, " </memory_device>\n"); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</memory_device>\n");
} }
} }
...@@ -1043,12 +1049,14 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) ...@@ -1043,12 +1049,14 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
} }
virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type); virBufferAsprintf(buf, "<sysinfo type='%s'>\n", type);
virBufferAdjustIndent(buf, 2);
virSysinfoBIOSFormat(buf, def); virSysinfoBIOSFormat(buf, def);
virSysinfoSystemFormat(buf, def); virSysinfoSystemFormat(buf, def);
virSysinfoProcessorFormat(buf, def); virSysinfoProcessorFormat(buf, def);
virSysinfoMemoryFormat(buf, def); virSysinfoMemoryFormat(buf, def);
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</sysinfo>\n"); virBufferAddLit(buf, "</sysinfo>\n");
if (virBufferError(buf)) { if (virBufferError(buf)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册