conf: add validation and propagate flags into virInterfaceDefParse()

We need to know if validation flag is present in order to
validate given XML against schema in virXMLParse().

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Kristina Hanicova 2021-08-20 13:28:50 +02:00 committed by Ján Tomko
parent 609dfaf43e
commit 5e71d3ad57
6 changed files with 15 additions and 11 deletions

View File

@ -819,12 +819,14 @@ virInterfaceDefParseNode(xmlDocPtr xml,
static virInterfaceDef *
virInterfaceDefParse(const char *xmlStr,
const char *filename)
const char *filename,
unsigned int flags)
{
g_autoptr(xmlDoc) xml = NULL;
virInterfaceDef *def = NULL;
if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), NULL, false))) {
if ((xml = virXMLParse(filename, xmlStr, _("(interface_definition)"), "interface.rng",
flags & VIR_INTERFACE_DEFINE_VALIDATE))) {
def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
}
@ -833,16 +835,17 @@ virInterfaceDefParse(const char *xmlStr,
virInterfaceDef *
virInterfaceDefParseString(const char *xmlStr)
virInterfaceDefParseString(const char *xmlStr,
unsigned int flags)
{
return virInterfaceDefParse(xmlStr, NULL);
return virInterfaceDefParse(xmlStr, NULL, flags);
}
virInterfaceDef *
virInterfaceDefParseFile(const char *filename)
{
return virInterfaceDefParse(NULL, filename);
return virInterfaceDefParse(NULL, filename, 0);
}

View File

@ -155,7 +155,8 @@ void
virInterfaceDefFree(virInterfaceDef *def);
virInterfaceDef *
virInterfaceDefParseString(const char *xmlStr);
virInterfaceDefParseString(const char *xmlStr,
unsigned int flags);
virInterfaceDef *
virInterfaceDefParseFile(const char *filename);

View File

@ -373,7 +373,7 @@ virInterfaceObjListCloneCb(void *payload,
if (!(xml = virInterfaceDefFormat(srcObj->def)))
goto error;
if (!(backup = virInterfaceDefParseString(xml)))
if (!(backup = virInterfaceDefParseString(xml, 0)))
goto error;
VIR_FREE(xml);

View File

@ -862,7 +862,7 @@ static char *netcfInterfaceGetXMLDesc(virInterfacePtr ifinfo,
goto cleanup;
}
ifacedef = virInterfaceDefParseString(xmlstr);
ifacedef = virInterfaceDefParseString(xmlstr, 0);
if (!ifacedef) {
/* error was already reported */
goto cleanup;
@ -898,7 +898,7 @@ static virInterfacePtr netcfInterfaceDefineXML(virConnectPtr conn,
virObjectLock(driver);
ifacedef = virInterfaceDefParseString(xml);
ifacedef = virInterfaceDefParseString(xml, 0);
if (!ifacedef) {
/* error was already reported */
goto cleanup;

View File

@ -6159,7 +6159,7 @@ testInterfaceDefineXML(virConnectPtr conn,
virCheckFlags(0, NULL);
virObjectLock(privconn);
if ((def = virInterfaceDefParseString(xmlStr)) == NULL)
if ((def = virInterfaceDefParseString(xmlStr, 0)) == NULL)
goto cleanup;
if ((obj = virInterfaceObjListAssignDef(privconn->ifaces, def)) == NULL)

View File

@ -24,7 +24,7 @@ testCompareXMLToXMLFiles(const char *xml)
if (virTestLoadFile(xml, &xmlData) < 0)
goto fail;
if (!(dev = virInterfaceDefParseString(xmlData)))
if (!(dev = virInterfaceDefParseString(xmlData, 0)))
goto fail;
if (!(actual = virInterfaceDefFormat(dev)))