提交 498d7833 编写于 作者: P Peter Krempa 提交者: Eric Blake

xml: Change virtual file names of xml documents parsed in memory

While parsing XML strings from memory, the previous convention in
libvirt was to set the virtual file name to "domain.xml" or something
similar. This could potentialy trick the user into looking for a file
named domain.xml on the disk in an attempt to fix the error.

This patch changes these filenames to something that can't be as easily
confused for a valid filename.

Examples of error messages:
---------------------------
Error while loading file from disk:

15:07:59.015: 527: error : catchXMLError:709 : /path/to/domain.xml:1: StartTag: invalid element name
<domain type='kvm'><
--------------------^

Error while parsing definition in memory:

15:08:43.581: 525: error : catchXMLError:709 : (domain definition):2: error parsing attribute name
  <name>vm1</name>
--^
上级 2acd4a16
......@@ -7461,7 +7461,7 @@ virDomainDefParse(const char *xmlStr,
xmlDocPtr xml;
virDomainDefPtr def = NULL;
if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
if ((xml = virXMLParse(filename, xmlStr, _("(domain definition)")))) {
def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml),
expectedVirtTypes, flags);
xmlFreeDoc(xml);
......
......@@ -641,7 +641,8 @@ caps_mockup(vahControl * ctl, const char *xmlStr)
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
if (!(xml = virXMLParseStringCtxt(xmlStr, "domain.xml", &ctxt))) {
if (!(xml = virXMLParseStringCtxt(xmlStr, _("(domain definition)"),
&ctxt))) {
goto cleanup;
}
......
......@@ -1306,7 +1306,7 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
flags = VIR_DOMAIN_AFFECT_CONFIG;
/* extract current network device description */
xml = virXMLParseStringCtxt(desc, "domain configuration", &ctxt);
xml = virXMLParseStringCtxt(desc, _("(domain definition)"), &ctxt);
VIR_FREE(desc);
if (!xml) {
vshError(ctl, _("Failed to parse domain description xml"));
......@@ -1453,7 +1453,7 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
xml = virXMLParseStringCtxt(desc, "domain configuration", &ctxt);
xml = virXMLParseStringCtxt(desc, _("(domain definition)"), &ctxt);
VIR_FREE(desc);
if (!xml) {
vshError(ctl, _("Failed to parse domain description xml"));
......@@ -1662,7 +1662,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
if (!xml)
goto cleanup;
xmldoc = virXMLParseStringCtxt(xml, "domain.xml", &ctxt);
xmldoc = virXMLParseStringCtxt(xml, _("(domain definition)"), &ctxt);
if (!xmldoc)
goto cleanup;
......@@ -3492,7 +3492,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
xml = virXMLParseStringCtxt(cap_xml, "node.xml", &ctxt);
xml = virXMLParseStringCtxt(cap_xml, _("(capabilities)"), &ctxt);
if (!xml) {
vshError(ctl, "%s", _("unable to get node capabilities"));
goto cleanup;
......@@ -9032,7 +9032,8 @@ cleanup:
}
static xmlChar *
makeCloneXML(const char *origxml, const char *newname) {
makeCloneXML(const char *origxml, const char *newname)
{
xmlDocPtr doc = NULL;
xmlXPathContextPtr ctxt = NULL;
......@@ -9040,7 +9041,7 @@ makeCloneXML(const char *origxml, const char *newname) {
xmlChar *newxml = NULL;
int size;
doc = virXMLParseStringCtxt(origxml, "domain.xml", &ctxt);
doc = virXMLParseStringCtxt(origxml, _("(volume definition)"), &ctxt);
if (!doc)
goto cleanup;
......@@ -10831,7 +10832,7 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml)
goto cleanup;
......@@ -10899,7 +10900,7 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml)
goto cleanup;
......@@ -11286,7 +11287,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get interface information"));
......@@ -11753,7 +11754,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
xml = virXMLParseStringCtxt(doc, "domain.xml", &ctxt);
xml = virXMLParseStringCtxt(doc, _("(domain definition)"), &ctxt);
VIR_FREE(doc);
if (!xml) {
vshError(ctl, "%s", _("Failed to get disk information"));
......@@ -13023,7 +13024,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (!doc)
continue;
xml = virXMLParseStringCtxt(doc, "domainsnapshot.xml", &ctxt);
xml = virXMLParseStringCtxt(doc, _("(domain snapshot)"), &ctxt);
if (!xml)
continue;
......@@ -13184,7 +13185,7 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
if (!xml)
goto cleanup;
xmldoc = virXMLParseStringCtxt(xml, "domainsnapshot.xml", &ctxt);
xmldoc = virXMLParseStringCtxt(xml, _("(domain snapshot)"), &ctxt);
if (!xmldoc)
goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册