]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
* include/libvirt/virterror.h src/virterror.c src/xend_internal.c
authorDaniel Veillard <veillard@redhat.com>
Wed, 8 Nov 2006 16:55:20 +0000 (16:55 +0000)
committerDaniel Veillard <veillard@redhat.com>
Wed, 8 Nov 2006 16:55:20 +0000 (16:55 +0000)
  src/xml.c: give proper indication of the failures raised by the
  XML parser on not well formed XML, should fix rhbz#208545
Daniel

ChangeLog
include/libvirt/virterror.h
src/virterror.c
src/xend_internal.c
src/xml.c

index a103c59398b081abd3f5d0b4731fe49c10174f4e..324a5ccdccba5d9e971bacc1577f7096bccd2b05 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Nov  8 16:58:56 CET 2006 Daniel Veillard <veillard@redhat.com>
+
+       * include/libvirt/virterror.h src/virterror.c src/xend_internal.c
+         src/xml.c: give proper indication of the failures raised by the
+         XML parser on not well formed XML, should fix rhbz#208545
+
 Wed Nov  8 14:01:11 CET 2006 Daniel Veillard <veillard@redhat.com>
 
        * src/libvirt.c src/proxy_internal.c src/xs_internal.c: fix the
index 5c07cbef49ff7e248b6ce52504f60878d81e0894..e2d536919579f6a7f9a01fcee62d2ac5cd4c3b20 100644 (file)
@@ -112,7 +112,8 @@ typedef enum {
     VIR_ERR_READ_FAILED, /* failed to read a conf file */
     VIR_ERR_PARSE_FAILED, /* failed to parse a conf file */
     VIR_ERR_CONF_SYNTAX, /* failed to parse the syntax of a conf file */
-    VIR_ERR_WRITE_FAILED /* failed to write a conf file */
+    VIR_ERR_WRITE_FAILED, /* failed to write a conf file */
+    VIR_ERR_XML_DETAIL /* detail of an XML error */
 } virErrorNumber;
 
 /**
index f365b3d76152d257acad0ab64786333daac52c25..5d3a99a3c111996b5c6ba90fe4b0e9d5dfff495e 100644 (file)
@@ -253,6 +253,9 @@ virDefaultErrorFunc(virErrorPtr err)
         case VIR_FROM_XEN:
             dom = "Xen ";
             break;
+        case VIR_FROM_XML:
+            dom = "XML ";
+            break;
         case VIR_FROM_XEND:
             dom = "Xen Daemon ";
             break;
@@ -270,7 +273,11 @@ virDefaultErrorFunc(virErrorPtr err)
         domain = err->dom->name;
     }
     len = strlen(err->message);
-    if ((len == 0) || (err->message[len - 1] != '\n'))
+    if ((err->domain == VIR_FROM_XML) && (err->code == VIR_ERR_XML_DETAIL) &&
+        (err->int1 != 0))
+        fprintf(stderr, "libvir: %s%s %s: line %d: %s",
+                dom, lvl, domain, err->int1, err->message);
+    else if ((len == 0) || (err->message[len - 1] != '\n'))
         fprintf(stderr, "libvir: %s%s %s: %s\n",
                 dom, lvl, domain, err->message);
     else
@@ -569,6 +576,12 @@ __virErrorMsg(virErrorNumber error, const char *info)
            else
                errmsg = _("failed to write configuration file: %s");
             break;
+       case VIR_ERR_XML_DETAIL:
+           if (info == NULL)
+               errmsg = _("parser error");
+           else
+               errmsg = "%s";
+            break;
     }
     return (errmsg);
 }
index c1006cec6a0cdb83dd5963e11ecedd39dc193d5a..28f2ca121cfe30339c90ad180bb3d1ef29c3ed33 100644 (file)
@@ -2870,13 +2870,14 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
     }
 
     if ((xendConfigVersion = xend_get_config_version(conn)) < 0) {
-        virXendError(conn, VIR_ERR_INTERNAL_ERROR, "cannot determine xend config version");
+        virXendError(conn, VIR_ERR_INTERNAL_ERROR,
+                    "cannot determine xend config version");
         return (NULL);
     }
 
     sexpr = virDomainParseXMLDesc(xmlDesc, &name, xendConfigVersion);
     if ((sexpr == NULL) || (name == NULL)) {
-        virXendError(conn, VIR_ERR_XML_ERROR, "Failed to parse the XML domain description");
+        virXendError(conn, VIR_ERR_XML_ERROR, "domain");
         if (sexpr != NULL)
             free(sexpr);
         if (name != NULL)
index df8c8dc627460217d9d3ed6078bbf49161627107..21cc4fe2ced0ad2c87ac07978de9a9f3afc67820 100644 (file)
--- a/src/xml.c
+++ b/src/xml.c
@@ -910,6 +910,27 @@ virDomainParseXMLOSDescPV(xmlNodePtr node, virBufferPtr buf, xmlXPathContextPtr
     return (0);
 }
 
+/**
+ * virCatchXMLParseError:
+ * @ctx: the context
+ * @msg: the error message
+ * @...: extra arguments
+ *
+ * SAX callback on parsing errors, act as a gate for libvirt own
+ * error reporting.
+ */
+static void
+virCatchXMLParseError(void *ctx, const char *msg, ...) {
+    xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
+
+    if ((ctxt != NULL) && 
+        (ctxt->lastError.level == XML_ERR_FATAL) &&
+       (ctxt->lastError.message != NULL)) {
+        virXMLError(VIR_ERR_XML_DETAIL, ctxt->lastError.message,
+                   ctxt->lastError.line);
+    }
+}
+
 /**
  * virDomainParseXMLDiskDesc:
  * @node: node containing disk description
@@ -1168,6 +1189,7 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
     char *ret = NULL, *nam = NULL;
     virBuffer buf;
     xmlChar *prop;
+    xmlParserCtxtPtr pctxt;
     xmlXPathObjectPtr obj = NULL;
     xmlXPathObjectPtr tmpobj = NULL;
     xmlXPathContextPtr ctxt = NULL;
@@ -1184,9 +1206,16 @@ virDomainParseXMLDesc(const char *xmldesc, char **name, int xendConfigVersion)
     buf.size = 1000;
     buf.use = 0;
 
-    xml = xmlReadDoc((const xmlChar *) xmldesc, "domain.xml", NULL,
-                     XML_PARSE_NOENT | XML_PARSE_NONET |
-                     XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
+    pctxt = xmlNewParserCtxt();
+    if ((pctxt == NULL) || (pctxt->sax == NULL)) {
+        goto error;
+    }
+
+    pctxt->sax->error = virCatchXMLParseError;
+
+    xml = xmlCtxtReadDoc(pctxt, (const xmlChar *) xmldesc, "domain.xml", NULL,
+                         XML_PARSE_NOENT | XML_PARSE_NONET |
+                         XML_PARSE_NOWARNING);
     if (xml == NULL) {
         goto error;
     }