--- xml-axkit/lib/AxKit.pm_orig	2003-09-04 22:59:48.000000000 +0200+++ xml-axkit/lib/AxKit.pm	2003-10-09 22:51:31.000000000 +0200@@ -172,8 +172,11 @@ sub fast_handler {     my $r = shift; -    local $SIG{__DIE__} = sub { AxKit::prep_exception(@_)->throw };-+    my $provider;+    my $res= eval {+	#local $SIG{__DIE__} = sub { AxKit::prep_exception(@_)->throw };+	# ^- cj: this doesn't make the exception handling chain work correctly.+	     # use Carp ();     # local $SIG{'USR2'} = sub {      #     Carp::confess("caught SIGUSR2!");@@ -198,12 +201,14 @@         return $plugin_ret;     } -    my $provider = Apache::AxKit::Provider->new_content_provider($r);+    $provider = Apache::AxKit::Provider->new_content_provider($r);      return $provider->decline(reason => "passthru set")             if ($r->notes('axkit_passthru') && $r->dir_config('AxFastPassthru'));      return main_handler($r, $provider);+    };+    return $@ ? do_process_error($r, $@, $provider) : $res; }  #########################################@@ -222,8 +227,11 @@ #     } #     ############################## -    local $SIG{__DIE__} = sub { AxKit::prep_exception(@_)->throw };-+    my $provider;+    my $res=    eval {+	# local $SIG{__DIE__} = sub { AxKit::prep_exception(@_)->throw };+	# ^- cj: this doesn't make the exception handling chain below work correctly.+	     # use Carp ();     # local $SIG{'USR2'} = sub {     #     Carp::confess("caught SIGUSR2!");@@ -252,12 +260,14 @@         return $plugin_ret;     } -    my $provider = Apache::AxKit::Provider->new_content_provider($r);+    $provider = Apache::AxKit::Provider->new_content_provider($r);      return $provider->decline(reason => "passthru set")             if ($r->notes('axkit_passthru') && $r->dir_config('AxFastPassthru'));      return main_handler($r, $provider);+    };+    return $@ ? do_process_error($r, $@, $provider) : $res; }  sub main_handler {@@ -290,29 +300,28 @@      local $AxKit::Cache; -    my $retcode = eval {-        # $r->header_out('X-AxKit-Version', $VERSION);--        chdir(File::Basename::dirname($r->filename));+    # $r->header_out('X-AxKit-Version', $VERSION); -        $AxKit::OrigType = $r->content_type('changeme');+    chdir(File::Basename::dirname($r->filename)); -        reset_depends();+    $AxKit::OrigType = $r->content_type('changeme'); -        my $result_code = run_axkit_engine($r, $provider);+    reset_depends(); -        # restore $r-        if (ref($r) eq 'AxKit::Apache') {-            bless $r, 'Apache';-            tie *STDOUT, 'Apache', $r;-        }+    my $result_code = run_axkit_engine($r, $provider); -        deliver_to_browser($r, $result_code);-    };-    my $E = $@;-    unless ($E) {-        return $retcode;+    # restore $r+    if (ref($r) eq 'AxKit::Apache') {+	bless $r, 'Apache';+	tie *STDOUT, 'Apache', $r;     }++    deliver_to_browser($r, $result_code);+}++sub do_process_error {+    my ($r, $E, $provider) = @_; # $provider might be undefined+    warn "CJ do_process_error with \$r=$r, \$E=$E, \$provider=$provider";          AxKit::Debug(5, "Caught an exception");     @@ -344,7 +353,7 @@         $r->send_http_header('text/xml');         return DONE if $r->method eq 'HEAD';         eval {-            my $fh = $provider->get_fh;+            my $fh = $provider->get_fh;  #cj: funny?: here $provider from before is used, but process_error creates it's own provider object.             $r->send_fd($fh);         };         if ($@) {@@ -366,6 +375,10 @@             $r->log->error("[AxKit] [Backtrace] " . $E->stacktrace);         } +	## cj: fetch cfg object if not already:+	$AxKit::Cfg = Apache::AxKit::ConfigReader->new($r)+	  unless $AxKit::Cfg; ## hrm, this somehow doesn't work as expected? cj+	         my $error_styles = $AxKit::Cfg->ErrorStyles;         if (@$error_styles) {             return process_error($r, $E, $error_styles);@@ -390,11 +403,94 @@         return SERVER_ERROR;     }     -    die "Unknown exception, " . (ref($E)?"type: ".ref($E):"message is: $E");+    # handle other exceptions nicely+    if (ref $E) {+	if (my $ref= $E->can("as_errorxml")) {+            # almost-copy from above+	    my $error_styles = $AxKit::Cfg->ErrorStyles;+            if (@$error_styles) {+		return process_xmlerror($r, &$ref($E), $error_styles);+            }+	    return SERVER_ERROR;+	} else {+	    # rethrow+	    if (my $ref= $E->can("rethrow") || $E->can("throw")) {+		&$ref($E)+	    } else {+		die $E+	    }+	}+    } else {+	#$@=$E;+	#die; # appends nice '...propagated' string++	warn "CJ: OTHER ERROR";+# 	# wrap into some xml++# 	## cj: fetch cfg object if not already:+# 	$AxKit::Cfg = Apache::AxKit::ConfigReader->new($r)+# 	  unless $AxKit::Cfg; ## hrm, this somehow doesn't work as expected? cj++# 	my $error_styles = $AxKit::Cfg->ErrorStyles;+# 	use Data::Dumper;+# 	warn Dumper $error_styles;+# 	if (@$error_styles) {+# 	    #return+# 	    my $res= process_xmlerror($r,+# 				      "<error><msg>".xml_fullescape($E)."</msg></error>"+# 				      , $error_styles);+# 	    warn "CJ: process_xmlerror gab '$res', whrenddem OK=".OK;+# 	    # hmm, -1, vs. 0 fr ok, scheint nicht gut zu gehen.+# 	    return $res;+# 	}+# 	warn "CJ: NO STYLES";+# 	return SERVER_ERROR;++	$r->content_type('text/html; charset="iso-8859-1"');+	#$r->print("<html><body><h1>Error:</h1><p>".xml_fullescape($E)."</p></body></html>");+	#return OK;+	# CRY+	$r->custom_response(SERVER_ERROR,"<html><body><h1>Error:</h1><pre>".xml_fullescape($E)."</pre></body></html>");+	return SERVER_ERROR;+    }+}++sub process_xmlerror { # added by pflanze; same as process_error except that $error is already made+    my ($r, $error, $error_styles) = @_;+    +    bless $r, 'AxKit::Apache';+    tie *STDOUT, 'AxKit::Apache', $r;++    $r->dir_config->set(AxNoCache => 1);+    $AxKit::Cache = Apache::AxKit::Cache->new($r, 'error', '', '', '');+    +    $r->content_type("text/html; charset=UTF-8"); # set a default for errors+    #    $r->content_type("text/html; charset=iso-8859-1"); # set a default for errors+    ## cj: ^- ntzt nix. parst eben trotzdem als iso++    my $provider = Apache::AxKit::Provider::Scalar->new(+							$r, $error, $error_styles+						       );++    $r->pnotes('xml_string', $error);++    eval {+        process_request($r, $provider, $error_styles);+        if (ref($r) eq 'AxKit::Apache') {+            bless $r, 'Apache';+            tie *STDOUT, 'Apache', $r;+        }+        deliver_to_browser($r);+    };+    if ($@) {+        $r->log->error("[AxKit] [FATAL] Error occured while processing Error XML: $@");+        return SERVER_ERROR;+    }     -    return DECLINED;+    return OK; } + sub run_axkit_engine {     my ($r, $provider, $no_output) = @_;     @@ -1076,6 +1172,23 @@     return $text; } +sub xml_fullescape { # do only return ascii+    use bytes;+    warn "CJ xml_fullescape";+    my $text = shift;+    $text =~ s/([<>'&"])+              /+              $escapes{$1}+              /egsx; # '+    #$text=~ s/([\0200-\0377])/ sprintf "\\0x\%x",$1 /se;+    my $f= chr(128); my $t=chr(255);## cj uglyyyyy +#    $text=~ s/([$f-$t])/ sprintf( "\\0x\%X",ord($1)) /seg; # sigh g wars+#    $text=~ s/([$f-$t])//sg;+    $text=~ s/([$f-$t])/<b>?<\/b>/sg;+    print STDERR "CJ xml_fullescape: RETURNING: '$text'\n";+    return $text;+}+ 1;  #########################################################################