mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 23:37:42 +00:00
Use common XML parsing functions
This commit is contained in:
parent
26be7a0a24
commit
8d8815ea2a
@ -4168,99 +4168,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;
|
||||
xmlDocPtr xml;
|
||||
virDomainDefPtr def = NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -4296,38 +4232,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;
|
||||
}
|
||||
|
||||
|
@ -851,96 +851,29 @@ cleanup:
|
||||
return def;
|
||||
}
|
||||
|
||||
/* Called from SAX on parsing errors in the XML. */
|
||||
static void
|
||||
catchXMLError (void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
||||
static virInterfaceDefPtr
|
||||
virInterfaceDefParse(const char *xmlStr,
|
||||
const char *filename)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlDocPtr xml;
|
||||
virInterfaceDefPtr def = NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
if ((xml = virXMLParse(filename, xmlStr, "interface.xml"))) {
|
||||
def = virInterfaceDefParseNode(xml, xmlDocGetRootElement(xml));
|
||||
xmlFreeDoc(xml);
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
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 = 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 ((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;
|
||||
return virInterfaceDefParse(xmlStr, NULL);
|
||||
}
|
||||
|
||||
virInterfaceDefPtr virInterfaceDefParseFile(const char *filename)
|
||||
{
|
||||
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);
|
||||
|
||||
cleanup:
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
xmlFreeDoc (xml);
|
||||
return def;
|
||||
return virInterfaceDefParse(NULL, filename);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -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, ...)
|
||||
static virNetworkDefPtr
|
||||
virNetworkDefParse(const char *xmlStr,
|
||||
const char *filename)
|
||||
{
|
||||
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
|
||||
xmlDocPtr xml;
|
||||
virNetworkDefPtr def = NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
if ((xml = virXMLParse(filename, xmlStr, "network.xml"))) {
|
||||
def = virNetworkDefParseNode(xml, xmlDocGetRootElement(xml));
|
||||
xmlFreeDoc(xml);
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
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 = 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;
|
||||
}
|
||||
|
||||
def = virNetworkDefParseNode(xml, root);
|
||||
|
||||
cleanup:
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
xmlFreeDoc (xml);
|
||||
return def;
|
||||
return virNetworkDefParse(xmlStr, NULL);
|
||||
}
|
||||
|
||||
virNetworkDefPtr virNetworkDefParseFile(const char *filename)
|
||||
{
|
||||
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);
|
||||
|
||||
cleanup:
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
xmlFreeDoc (xml);
|
||||
return def;
|
||||
return virNetworkDefParse(NULL, filename);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
if ((xml = virXMLParse(filename, xmlStr, "secret.xml"))) {
|
||||
ret = secretXMLParseNode(xml, xmlDocGetRootElement(xml));
|
||||
xmlFreeDoc(xml);
|
||||
}
|
||||
|
||||
root = xmlDocGetRootElement(xml);
|
||||
if (root == NULL) {
|
||||
virSecretReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("missing root element"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = secretXMLParseNode(xml, root);
|
||||
|
||||
cleanup:
|
||||
xmlFreeDoc(xml);
|
||||
xmlFreeParserCtxt(pctxt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -717,24 +717,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) {
|
||||
@ -764,52 +746,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
|
||||
@ -1163,52 +1107,14 @@ virStorageVolDefParse(virStoragePoolDefPtr pool,
|
||||
const char *xmlStr,
|
||||
const char *filename) {
|
||||
virStorageVolDefPtr 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 = virStorageVolDefParseNode(pool, 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 = virStorageVolDefParseNode(pool, xml, node);
|
||||
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
xmlFreeDoc(xml);
|
||||
|
||||
return ret;
|
||||
|
||||
cleanup:
|
||||
xmlFreeParserCtxt (pctxt);
|
||||
xmlFreeDoc(xml);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virStorageVolDefPtr
|
||||
|
Loading…
x
Reference in New Issue
Block a user