Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/conf/domain_conf.c | 130 +++++++------------------------------------
src/conf/interface_conf.c | 93 ++++--------------------------
src/conf/network_conf.c | 93 ++++--------------------------
src/conf/node_device_conf.c | 60 +------------------
src/conf/secret_conf.c | 56 ++----------------
src/conf/storage_conf.c | 110 +++---------------------------------
6 files changed, 65 insertions(+), 477 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4ffeb8a..cdd906e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4130,99 +4130,35 @@ error:
}
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
+static virDomainDefPtr
+virDomainDefParse(const char *xmlStr,
+ const char *filename,
+ virCapsPtr caps,
+ int flags)
{
- xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
- if (ctxt) {
- if (virGetLastError() == NULL &&
- ctxt->lastError.level == XML_ERR_FATAL &&
- ctxt->lastError.message != NULL) {
- virDomainReportError(VIR_ERR_XML_DETAIL,
- _("at line %d: %s"),
- ctxt->lastError.line,
- ctxt->lastError.message);
- }
+ xmlDocPtr xml;
+ virDomainDefPtr def = NULL;
+
+ if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
+ def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml), flags);
+ xmlFreeDoc(xml);
}
+
+ return def;
}
virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
const char *xmlStr,
int flags)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
- virDomainDefPtr def = NULL;
-
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "domain.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virDomainReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
-
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virDomainReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- def = virDomainDefParseNode(caps, xml, root, flags);
-
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
- return def;
+ return virDomainDefParse(xmlStr, NULL, caps, flags);
}
virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
- const char *filename, int flags)
+ const char *filename,
+ int flags)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
- virDomainDefPtr def = NULL;
-
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virDomainReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
-
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virDomainReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- def = virDomainDefParseNode(caps, xml, root, flags);
-
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
- return def;
+ return virDomainDefParse(NULL, filename, caps, flags);
}
@@ -4258,38 +4194,14 @@ cleanup:
virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
const char *filename)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
+ xmlDocPtr xml;
virDomainObjPtr obj = NULL;
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virDomainReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
+ if ((xml = virXMLParseFile(filename))) {
+ obj = virDomainObjParseNode(caps, xml, xmlDocGetRootElement(xml));
+ xmlFreeDoc(xml);
}
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virDomainReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- obj = virDomainObjParseNode(caps, xml, root);
-
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
return obj;
}
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index a0d2dfa..33875a8 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -853,96 +853,29 @@ cleanup:
return def;
}
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
- xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
- if (ctxt) {
- if (virGetLastError() == NULL &&
- ctxt->lastError.level == XML_ERR_FATAL &&
- ctxt->lastError.message != NULL) {
- virInterfaceReportError (VIR_ERR_XML_DETAIL,
- _("at line %d: %s"),
- ctxt->lastError.line,
- ctxt->lastError.message);
- }
- }
-}
-
-virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr)
+static virInterfaceDefPtr
+virInterfaceDefParse(const char *xmlStr,
+ const char *filename)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
+ xmlDocPtr xml;
virInterfaceDefPtr def = NULL;
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "interface.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virInterfaceReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
+ if ((xml = virXMLParse(filename, xmlStr, "interface.xml"))) {
+ def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
+ xmlFreeDoc(xml);
}
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- def = virInterfaceDefParseNode(xml, root);
-
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
return def;
}
-virInterfaceDefPtr virInterfaceDefParseFile(const char *filename)
+virInterfaceDefPtr virInterfaceDefParseString(const char *xmlStr)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
- virInterfaceDefPtr def = NULL;
-
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virInterfaceReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
-
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- def = virInterfaceDefParseNode(xml, root);
+ return virInterfaceDefParse(xmlStr, NULL);
+}
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
- return def;
+virInterfaceDefPtr virInterfaceDefParseFile(const char *filename)
+{
+ return virInterfaceDefParse(NULL, filename);
}
static int
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 6d3c3c0..014d2b8 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -504,96 +504,29 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
return NULL;
}
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
- xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
- if (ctxt) {
- if (virGetLastError() == NULL &&
- ctxt->lastError.level == XML_ERR_FATAL &&
- ctxt->lastError.message != NULL) {
- virNetworkReportError(VIR_ERR_XML_DETAIL,
- _("at line %d: %s"),
- ctxt->lastError.line,
- ctxt->lastError.message);
- }
- }
-}
-
-virNetworkDefPtr virNetworkDefParseString(const char *xmlStr)
+static virNetworkDefPtr
+virNetworkDefParse(const char *xmlStr,
+ const char *filename)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
+ xmlDocPtr xml;
virNetworkDefPtr def = NULL;
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr, "network.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virNetworkReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
-
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
+ if ((xml = virXMLParse(filename, xmlStr, "network.xml"))) {
+ def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml));
+ xmlFreeDoc(xml);
}
- def = virNetworkDefParseNode(xml, root);
-
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
return def;
}
-virNetworkDefPtr virNetworkDefParseFile(const char *filename)
+virNetworkDefPtr virNetworkDefParseString(const char *xmlStr)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
- virNetworkDefPtr def = NULL;
-
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (!xml) {
- if (virGetLastError() == NULL)
- virNetworkReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
-
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virNetworkReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- def = virNetworkDefParseNode(xml, root);
+ return virNetworkDefParse(xmlStr, NULL);
+}
-cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc (xml);
- return def;
+virNetworkDefPtr virNetworkDefParseFile(const char *filename)
+{
+ return virNetworkDefParse(NULL, filename);
}
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 09c0f41..7f2dac8 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1224,71 +1224,19 @@ cleanup:
return def;
}
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
- xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
- if (ctxt) {
- if (virGetLastError() == NULL &&
- ctxt->lastError.level == XML_ERR_FATAL &&
- ctxt->lastError.message != NULL) {
- virNodeDeviceReportError(VIR_ERR_XML_DETAIL,
- _("at line %d: %s"),
- ctxt->lastError.line,
- ctxt->lastError.message);
- }
- }
-}
-
-
-
static virNodeDeviceDefPtr
virNodeDeviceDefParse(const char *str,
const char *filename,
int create)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
+ xmlDocPtr xml;
virNodeDeviceDefPtr def = NULL;
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- if (filename) {
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- } else {
- xml = xmlCtxtReadDoc (pctxt, BAD_CAST str,
- "device.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ if ((xml = virXMLParse(filename, str, "device.xml"))) {
+ def = virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml), create);
+ xmlFreeDoc(xml);
}
- if (!xml) {
- if (virGetLastError() == NULL)
- virNodeDeviceReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
-
- if ((root = xmlDocGetRootElement(xml)) == NULL) {
- virNodeDeviceReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- def = virNodeDeviceDefParseNode(xml, root, create);
-
-cleanup:
- xmlFreeParserCtxt(pctxt);
- xmlFreeDoc(xml);
return def;
}
diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 946d425..bbdad89 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -187,62 +187,18 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
return ret;
}
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
- xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
- if (ctxt) {
- if (virGetLastError() == NULL &&
- ctxt->lastError.level == XML_ERR_FATAL &&
- ctxt->lastError.message != NULL) {
- virSecretReportError(VIR_ERR_XML_DETAIL, _("at line %d: %s"),
- ctxt->lastError.line, ctxt->lastError.message);
- }
- }
-}
-
static virSecretDefPtr
-virSecretDefParse(const char *xmlStr, const char *filename)
+virSecretDefParse(const char *xmlStr,
+ const char *filename)
{
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr root;
+ xmlDocPtr xml;
virSecretDefPtr ret = NULL;
- pctxt = xmlNewParserCtxt();
- if (pctxt == NULL || pctxt->sax == NULL)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- if (filename != NULL)
- xml = xmlCtxtReadFile(pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- else
- xml = xmlCtxtReadDoc(pctxt, BAD_CAST xmlStr, "secret.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- if (xml == NULL) {
- if (virGetLastError() == NULL)
- virSecretReportError(VIR_ERR_XML_ERROR, "%s",
- _("failed to parse xml document"));
- goto cleanup;
- }
-
- root = xmlDocGetRootElement(xml);
- if (root == NULL) {
- virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("missing root element"));
- goto cleanup;
+ if ((xml = virXMLParse(filename, xmlStr, "secret.xml"))) {
+ ret = secretXMLParseNode(xml, xmlDocGetRootElement(xml));
+ xmlFreeDoc(xml);
}
- ret = secretXMLParseNode(xml, root);
-
- cleanup:
- xmlFreeDoc(xml);
- xmlFreeParserCtxt(pctxt);
return ret;
}
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 19a1db9..bc60160 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -708,24 +708,6 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) {
return NULL;
}
-/* Called from SAX on parsing errors in the XML. */
-static void
-catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
-{
- xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
-
- if (ctxt) {
- if (virGetLastError() == NULL &&
- ctxt->lastError.level == XML_ERR_FATAL &&
- ctxt->lastError.message != NULL) {
- virStorageReportError (VIR_ERR_XML_DETAIL,
- _("at line %d: %s"),
- ctxt->lastError.line,
- ctxt->lastError.message);
- }
- }
-}
-
virStoragePoolDefPtr
virStoragePoolDefParseNode(xmlDocPtr xml,
xmlNodePtr root) {
@@ -755,52 +737,14 @@ static virStoragePoolDefPtr
virStoragePoolDefParse(const char *xmlStr,
const char *filename) {
virStoragePoolDefPtr ret = NULL;
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr node = NULL;
+ xmlDocPtr xml;
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- if (filename) {
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- } else {
- xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
- "storage.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
+ if ((xml = virXMLParse(filename, xmlStr, "storage.xml"))) {
+ ret = virStoragePoolDefParseNode(xml, xmlDocGetRootElement(xml));
+ xmlFreeDoc(xml);
}
- if (!xml) {
- if (virGetLastError() == NULL)
- virStorageReportError(VIR_ERR_XML_ERROR,
- "%s",_("failed to parse xml
document"));
- goto cleanup;
- }
-
- node = xmlDocGetRootElement(xml);
- if (node == NULL) {
- virStorageReportError(VIR_ERR_XML_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
- }
-
- ret = virStoragePoolDefParseNode(xml, node);
-
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc(xml);
-
return ret;
-
- cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc(xml);
- return NULL;
}
virStoragePoolDefPtr
@@ -1154,52 +1098,14 @@ virStorageVolDefParse(virStoragePoolDefPtr pool,
const char *xmlStr,
const char *filename) {
virStorageVolDefPtr ret = NULL;
- xmlParserCtxtPtr pctxt;
- xmlDocPtr xml = NULL;
- xmlNodePtr node = NULL;
-
- /* Set up a parser context so we can catch the details of XML errors. */
- pctxt = xmlNewParserCtxt ();
- if (!pctxt || !pctxt->sax)
- goto cleanup;
- pctxt->sax->error = catchXMLError;
-
- if (filename) {
- xml = xmlCtxtReadFile (pctxt, filename, NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- } else {
- xml = xmlCtxtReadDoc (pctxt, BAD_CAST xmlStr,
- "storage.xml", NULL,
- XML_PARSE_NOENT | XML_PARSE_NONET |
- XML_PARSE_NOWARNING);
- }
-
- if (!xml) {
- if (virGetLastError() == NULL)
- virStorageReportError(VIR_ERR_XML_ERROR,
- "%s", _("failed to parse xml
document"));
- goto cleanup;
- }
+ xmlDocPtr xml;
- node = xmlDocGetRootElement(xml);
- if (node == NULL) {
- virStorageReportError(VIR_ERR_XML_ERROR,
- "%s", _("missing root element"));
- goto cleanup;
+ if ((xml = virXMLParse(filename, xmlStr, "storage.xml"))) {
+ ret = virStorageVolDefParseNode(pool, xml, xmlDocGetRootElement(xml));
+ xmlFreeDoc(xml);
}
- ret = virStorageVolDefParseNode(pool, xml, node);
-
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc(xml);
-
return ret;
-
- cleanup:
- xmlFreeParserCtxt (pctxt);
- xmlFreeDoc(xml);
- return NULL;
}
virStorageVolDefPtr
--
1.7.0