Anonymous avatar Anonymous committed a1d0e6f

adding recover_silently flag to structerror CVS branch

Comments (0)

Files changed (2)

     return $self->{XML_LIBXML_RECOVER};
 }
 
+sub recover_silently {
+    my $self = shift;
+    my $arg = shift;
+    (($arg == 1) ? $self->recover(2) : $self->recover($arg)) if ($arg);
+    return ($self->recover() == 2) ? 1 : 0;
+}
+
 sub expand_entities {
     my $self = shift;
     $self->{XML_LIBXML_EXPAND_ENTITIES} = shift if scalar @_;
 #ifdef HAVE_SERRORS
     if (LibXML_error_OK) {
       if ( recover ) {
-	warn("%s",SvPV_nolen(LibXML_error));
-	SvREFCNT_dec(LibXML_error);	
+	if ( recover == 1 ) {
+	    warn("%s",SvPV_nolen(LibXML_error));
+	}
+	SvREFCNT_dec(LibXML_error);
 	LibXML_error = saved_error;
       } else {
 	SV* perl_err_var;
 	sv_setsv(perl_err_var, LibXML_error);
 	LibXML_error = saved_error;
 	croak(Nullch);
-      }
-    } else {
-      LibXML_error = saved_error;
-    }
+       }
+   } else {
+     LibXML_error = saved_error;
+   }
 #else
     SV *my_error = sv_2mortal(LibXML_error);
     LibXML_error = saved_error;
     if ( SvCUR( my_error ) > 0 ) {
         if ( recover ) {
-            warn("%s", SvPV_nolen(my_error));
+            if ( recover == 1 ) {
+                warn("%s", SvPV_nolen(my_error));
+            }
         } else {
             croak("%s", SvPV_nolen(my_error));
         }
 LibXML_get_recover(HV * real_obj)
 {
     SV** item = hv_fetch( real_obj, "XML_LIBXML_RECOVER", 18, 0 );
-    return ( item != NULL && SvTRUE(*item) ) ? 1 : 0;
+    return ( item != NULL && SvTRUE(*item) ) ? SvIV(*item) : 0;
 }
 
 static SV *
 void *
 LibXML_input_open(char const * filename)
 {
-    SV * results;
+    SV * results = NULL;
     SV * global_cb;
     SV * callback = NULL;
 
         RETVAL = &PL_sv_undef;
         LibXML_init_error(&saved_error);
         real_obj = LibXML_init_parser(self);
+        recover = LibXML_get_recover(real_obj);
 
         {
             xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Couldn't create memory parser context: %s", strerror(errno));
             }
             xs_warn( "context created\n");
         {
             xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Couldn't create memory parser context: %s", strerror(errno));
             }
             xs_warn( "context created\n");
         RETVAL = &PL_sv_undef;
         LibXML_init_error(&saved_error);
         real_obj = LibXML_init_parser(self);
+        recover = LibXML_get_recover(real_obj);
 
         {
             int read_length;
 
             ctxt = xmlCreatePushParserCtxt(NULL, NULL, buffer, read_length, NULL);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Could not create xml push parser context: %s",
                       strerror(errno));
             }
         }
 
         if ( real_doc != NULL ) {
-            recover = LibXML_get_recover(real_obj);
 
             if ( directory == NULL ) {
                 SV * newURI = sv_2mortal(newSVpvf("unknown-%12.12d", (void*)real_doc));
             sax = PSaxGetHandler();
             ctxt = xmlCreatePushParserCtxt(sax, NULL, buffer, read_length, NULL);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Could not create xml push parser context: %s",
                       strerror(errno));
             }
         RETVAL = &PL_sv_undef;
         LibXML_init_error(&saved_error);
         real_obj = LibXML_init_parser(self);
+        recover = LibXML_get_recover(real_obj);
 
         {
             xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Couldn't create file parser context for file \"%s\": %s",
                       filename, strerror(errno));
             }
         }
 
         if ( real_doc != NULL ) {
-            recover = LibXML_get_recover(real_obj);
 
             if ( recover || ( well_formed &&
                               ( !xmlDoValidityCheckingDefaultValue
         {
             xmlParserCtxtPtr ctxt = xmlCreateFileParserCtxt(filename);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Couldn't create file parser context for file \"%s\": %s",
                       filename, strerror(errno));
             }
         RETVAL = &PL_sv_undef;
         LibXML_init_error(&saved_error);
         real_obj = LibXML_init_parser(self);
+        recover = LibXML_get_recover(real_obj);
 
         {
             int read_length;
             ctxt = htmlCreatePushParserCtxt(NULL, NULL, buffer, read_length,
                                             NULL, XML_CHAR_ENCODING_NONE);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Could not create html push parser context: %s",
                       strerror(errno));
             }
         }
 
         if ( real_doc != NULL ) {
-            recover = LibXML_get_recover(real_obj);
 
             {
                 SV * newURI = sv_2mortal(newSVpvf("unknown-%12.12d", (void*)real_doc));
         RETVAL = &PL_sv_undef;
         LibXML_init_error(&saved_error);
         real_obj = LibXML_init_parser(self);
+        recover = LibXML_get_recover(real_obj);
 
         {
             int read_length;
             ctxt = docbCreatePushParserCtxt(NULL, NULL, buffer, read_length, NULL,
                                             xmlParseCharEncoding((const char*)encoding));
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Could not create docbook SGML push parser context: %s",
                       strerror(errno));
             }
         }
 
         if ( real_doc != NULL ) {
-            recover = LibXML_get_recover(real_obj);
 
             {
                 SV * newURI = sv_2mortal(newSVpvf("unknown-%12.12d", (void*)real_doc));
         {
             docbParserCtxtPtr ctxt = docbCreateFileParserCtxt(filename, encoding);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Couldn't create file parser context for file \"%s\": %s",
                       filename, strerror(errno));
             }
         if ( chunk != NULL ) {
             xmlParserCtxtPtr ctxt = xmlCreateMemoryParserCtxt((const char*)ptr, len);
             if (ctxt == NULL) {
-                LibXML_report_error(saved_error, 1);
+                LibXML_report_error(saved_error, recover ? recover : 1);
                 croak("Couldn't create memory parser context: %s", strerror(errno));
             }
             xs_warn( "context created\n");
     PREINIT:
         SV * saved_error;
         xmlValidCtxt cvp;
-        xmlDtdPtr dtd;
+        xmlDtdPtr dtd = NULL;
         SV * dtd_sv;
     CODE:
         LibXML_init_error(&saved_error);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.