[Liblas-commits] hg-main-tree: install custom error handlers for libxml2

liblas-commits at liblas.org liblas-commits at liblas.org
Fri Apr 15 17:40:42 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/07bcedc54f8e
changeset: 580:07bcedc54f8e
user:      Howard Butler <hobu.inc at gmail.com>
date:      Fri Apr 15 16:40:36 2011 -0500
description:
install custom error handlers for libxml2

diffstat:

 include/libpc/drivers/oci/Schema.hpp |   3 ++-
 src/drivers/oci/Schema.cpp           |  28 +++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)

diffs (73 lines):

diff -r 1db3464d27dd -r 07bcedc54f8e include/libpc/drivers/oci/Schema.hpp
--- a/include/libpc/drivers/oci/Schema.hpp	Fri Apr 15 16:21:31 2011 -0500
+++ b/include/libpc/drivers/oci/Schema.hpp	Fri Apr 15 16:40:36 2011 -0500
@@ -41,6 +41,7 @@
 #include <libpc/drivers/oci/Reader.hpp>
 
 #include <string>
+#include <stdarg.h>
 
 #include <libxml/parser.h>
 #include <libxml/xmlschemas.h>
@@ -53,7 +54,7 @@
 namespace libpc { namespace drivers { namespace oci {
 
 
-void OCISchemaGenericErrorHandler (void * userData, xmlErrorPtr error);
+void OCISchemaGenericErrorHandler (void * ctx, const char* message, ...);
 void OCISchemaStructuredErrorHandler (void * userData, xmlErrorPtr error);
 
 class Schema
diff -r 1db3464d27dd -r 07bcedc54f8e src/drivers/oci/Schema.cpp
--- a/src/drivers/oci/Schema.cpp	Fri Apr 15 16:21:31 2011 -0500
+++ b/src/drivers/oci/Schema.cpp	Fri Apr 15 16:40:36 2011 -0500
@@ -43,16 +43,36 @@
 namespace libpc { namespace drivers { namespace oci {
 
 
-void OCISchemaGenericErrorHandler 
+void OCISchemaStructuredErrorHandler 
     (void * userData, xmlErrorPtr error)
 {
     std::ostringstream oss;
     
-    oss << "Generic XML error: '" << error->message <<"' ";
+    oss << "XML error: '" << error->message <<"' ";
     oss << "on line " << error->line;
     throw schema_error(oss.str());
 }
 
+void OCISchemaGenericErrorHandler 
+    (void * ctx, const char* message, ... )
+{
+    
+    const int ERROR_MESSAGE_SIZE = 256;
+    char error[ERROR_MESSAGE_SIZE];
+    va_list arg_ptr;
+
+    va_start(arg_ptr, message);
+    vsnprintf(error, ERROR_MESSAGE_SIZE, message, arg_ptr);
+    va_end(arg_ptr);
+
+    
+    std::ostringstream oss;
+    
+    oss << "XML error: '" << error <<"' ";
+    throw schema_error(oss.str());
+    
+}
+
 
 Schema::Schema(std::string xml, std::string xmlschema)
 
@@ -62,7 +82,9 @@
 
 
     
-        
+    xmlSetGenericErrorFunc(NULL, (xmlGenericErrorFunc) &OCISchemaGenericErrorHandler);
+    xmlSetStructuredErrorFunc(NULL, (xmlStructuredErrorFunc) & OCISchemaStructuredErrorHandler);
+
     // No network access
     // http://xmlsoft.org/html/libxml-parser.html#xmlParserOption
     m_doc = xmlReadMemory(&(xml[0]), xml.size(), "noname.xml", NULL, XML_PARSE_NONET);


More information about the Liblas-commits mailing list