Can someone with more brane power than me go over these patches for
sanity?

-- 
<!-- Matt -->
<:->get a SMart net</:->
Spam trap - do not mail: [EMAIL PROTECTED]

---------- Forwarded message ----------
Date: Mon, 27 Jan 2003 17:04:28 +0100 (CET)
From: Michael Kroell <[EMAIL PROTECTED]>
To: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
Subject: AxKit.pm/Cache.pm next one

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


matt,

forget the two diffs hansjoerg and i sent to you this morning

this time i tweaked a little more. those two patches change the following:
* cache is saved transformed
* $cache->deliver is no more, content is delivered by AxKit::deliver_to_browser
* caching works, and does not croak with "Cannot call method no_cache on an 
undefined value"

concerns:
* memory, performance (<- copying to $xmlstring from pnotes)
* error handling (<- not tested, i.e what happens during processing errors)

rfc,
michael

- --
IT Services
University of Innsbruck

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBPjVYj3jN0CNeKmaIEQJ4AQCfWNbW8iiJTRcgINEnxc+Q9/mxJn8AoKAN
gyzk7Tl+0Za8MWZ6QSm5a0Ug
=WhIy
-----END PGP SIGNATURE-----
--- /mp_sie2/ci00/src/webserver/axkit/perl/apachecvs/xml-axkit/lib/AxKit.pm     
Mon Jan 27 10:29:11 2003
+++ AxKit.pm    Mon Jan 27 16:42:46 2003
@@ -1,4 +1,4 @@
-# $Id: AxKit.pm,v 1.36 2003/01/26 17:37:42 matts Exp $
+# $Id: AxKit.pm,v 1.34 2003/01/21 16:11:57 matts Exp $
 
 package AxKit;
 use strict;
@@ -109,7 +109,7 @@
 
         $func = sub {
             my $map = Apache::AxKit::CharsetConv->new("utf-8", $charset)
-                       || die "Charset $charset not supported by Iconv";
+            || die "Charset $charset not supported by Iconv";
 
             return map { $map->convert( $_ ) } ($outputfunc->(@_));
         };
@@ -313,7 +313,7 @@
     }
     elsif ($E->isa('Apache::AxKit::Exception::Retval')) {
         my $code = $E->{return_code};
-       AxKit::Debug(5, "aborting with code $code");
+        AxKit::Debug(5, "aborting with code $code");
         return $code;
     }
     
@@ -422,15 +422,16 @@
 
     $AxKit::Charset = $AxKit::Cfg->OutputCharset();
 
+    # Store in package variable for other modules
+    $AxKit::Cache = $cache;
+
     if (!$recreate) {
         AxKit::Debug(1, "delivering cached copy - all conditions met");
-        return $cache->deliver();
+        return OK;
     }
 
     AxKit::Debug(1, "some condition failed. recreating output");
 
-    # Store in package variable for other modules
-    $AxKit::Cache = $cache;
     
     # reconsecrate Apache request object (& STDOUT) into our own class
     bless $r, 'AxKit::Apache';
@@ -468,7 +469,7 @@
     save_dependencies($r, $cache);
     
     return $return_code;
-        
+
 }
 
 sub get_axkit_uri {
@@ -478,31 +479,12 @@
     
     my $apache = AxKit::Apache->request;
     my $r;
-    if ($uri =~ m|^axkit:(/.*)$|) {
-        my $blurb = $1;
-        # got "axkit:/..."
-        # first check if it's actually "axkit://host[:port]/..."
-        if ($blurb =~ m|^//(?:([\w\.-]+)(:\d+)?)?(/.*)$|) {
-            my $host = $1;
-            my $port = $2;
-            my $abs_uri = $3;
-            if ($host) {
-                throw Apache::AxKit::Exception (
-                    -text => "axkit://host[:port]/ requests not supported 
($uri)"
-                );
-            }
-            AxKit::Debug(4, "get_axkit_uri looking up abs (host): '$abs_uri'");
-            $r = $apache->lookup_uri(AxKit::FromUTF8($abs_uri));
-        }
-        else {
-            my $abs_uri = $blurb;
-            AxKit::Debug(4, "get_axkit_uri looking up abs: '$abs_uri'");
-            $r = $apache->lookup_uri(AxKit::FromUTF8($abs_uri));
-        }
+    if ($uri =~ /^axkit:\/(\/.*)$/) {
+        my $abs_uri = $1;
+        $r = $apache->lookup_uri(AxKit::FromUTF8($abs_uri));
     }
     elsif ($uri =~ /^axkit:(.*)$/) {
         my $rel_uri = $1;
-        AxKit::Debug(4, "get_axkit_uri looking up '$rel_uri'");
         $r = $apache->lookup_uri(AxKit::FromUTF8($rel_uri));
     }
     else {
@@ -514,47 +496,11 @@
 
     my $provider = Apache::AxKit::Provider->new_content_provider($r);
     
-    my $result_code = eval {
-        run_axkit_engine(
-            $r,
-            $provider,
-            1, # no output
-        );
-    };
-    if ($@) {
-        my $E = $@;
-        if ($E->isa('Apache::AxKit::Exception::Declined')) {
-            if ($AxKit::Cfg && $AxKit::Cfg->LogDeclines()) {
-                $r->log->warn("[AxKit] [DECLINED] $E->{reason}")
-                        if $E->{reason};
-            }
-            AxKit::Debug(4, "[DECLINED] From: $E->{-file} : $E->{-line}");
-            
-            my $str = '';
-            eval {
-                my $fh = $provider->get_fh;
-                local $/;
-                $str = <$fh>;
-                $r->pnotes('xml_string', $str);
-                $result_code = OK;
-            };
-            if ($@) {
-                eval {
-                    my $pstr = $provider->get_strref;
-                    $str = $$pstr;
-                    $r->pnotes('xml_string', $str);
-                    $result_code = OK;
-                };
-                if ($@) {
-                    $result_code = 'provider_declined';
-                }
-            }
-        }
-        else {
-            # Some other type of exception
-            $E->throw;
-        }
-    }
+    my $result_code = run_axkit_engine(
+        $r,
+        $provider,
+        1, # no output
+    );
     
     if ($result_code == OK) {
         # results now in $r->pnotes('xml_string') - probably...
@@ -720,7 +666,7 @@
                     $styleprovider,
                     $output_to_browser,
                     );
-           AxKit::Debug(5, "$mapto\::handler finished with code $retval");
+        AxKit::Debug(5, "$mapto\::handler finished with code $retval");
             $result_code = $retval if $retval != OK;
         }
         else {
@@ -864,100 +810,88 @@
 sub deliver_to_browser {
     my ($r, $result_code) = @_;
     $result_code ||= OK;
-    
-    AxKit::Debug(4, "delivering to browser");
+    my $got_cached;
+    my $xmlstring;
 
     if (length($r->pnotes('xml_string'))) {
         # ok, data is in xml_string
-        AxKit::Debug(4, "Delivering xml_string");
+        AxKit::Debug(5, "Delivering from xml_string pnote");
+        $xmlstring = $r->pnotes('xml_string');
     }
     elsif ($r->pnotes('dom_tree')) {
-        AxKit::Debug(4, "Delivering dom_tree");
-        $r->pnotes('xml_string', $r->pnotes('dom_tree')->toString );
+        AxKit::Debug(5, "Delivering from dom_tree pnote");
+        $xmlstring = $r->pnotes('dom_tree')->toString;
     }
     else {
-        AxKit::Debug(5, "Possible cache delivery coming up...");
-    }
-
-    if ($r->content_type eq 'changeme' && !$r->notes('axkit_passthru_type')) {
-        $AxKit::Cfg->AllowOutputCharset(1);
-        $r->content_type('text/html; charset=' . ($AxKit::Cfg->OutputCharset 
|| "UTF-8"));
-    }
-    elsif ($r->notes('axkit_passthru_type')) {
-        $r->content_type($AxKit::OrigType);
-    }
-
-    if (my $charset = $AxKit::Cfg->OutputCharset()) {
-        my $ct = $r->content_type;
-        $ct =~ s/charset=.*?(;|$)/charset=$charset/i;
-        $r->content_type($ct);
+        AxKit::Debug(5, "Cache delivery coming up...");
+        $xmlstring = $AxKit::Cache->read();
+        $got_cached++;
     }
 
-    if ($result_code != OK && $result_code != 200) {
-       # no caching - probably makes no sense, and will be turned off
-        # anyways, as currently only XSP pages allow to send custom responses
-       AxKit::Debug(4,"sending custom response: $result_code");
-        my ($transformer, $doit) = get_output_transformer();
-        if ($doit) {
-            
$r->custom_response($result_code,$transformer->($r->pnotes('xml_string') || 
''));
+    if (!$got_cached) {
+        if ($r->content_type eq 'changeme' && 
!$r->notes('axkit_passthru_type')) {
+            $AxKit::Cfg->AllowOutputCharset(1);
+            $r->content_type('text/html; charset=' . 
($AxKit::Cfg->OutputCharset || "UTF-8"));
         }
-        else {
-            $r->custom_response($result_code,$r->pnotes('xml_string') || '');
+        elsif ($r->notes('axkit_passthru_type')) {
+            $r->content_type($AxKit::OrigType);
         }
-        return $result_code;
-    }
 
-    if ($AxKit::Cache->no_cache() ||
-        lc($r->dir_config('Filter')) eq 'on' ||
-        $r->method() eq 'POST')
-    {
-        AxKit::Debug(4, "writing xml string to browser");
-        my ($transformer, $doit) = get_output_transformer();
-        if ($AxKit::Cfg->DoGzip) {
-            AxKit::Debug(4, 'Sending gzipped xml string to browser');
-            AxKit::Apache::send_http_header($r);
-            if ($doit) {
-                $r->print( unpack($]>5.00555?"U0A*":"A*", 
Compress::Zlib::memGzip( 
-                         $transformer->( $r->pnotes('xml_string') )
-                         ) ) );
-            }
-            else {
-                $r->print( unpack($]>5.00555?"U0A*":"A*", 
Compress::Zlib::memGzip( $r->pnotes('xml_string') ) ) );
-            }
+        if (my $charset = $AxKit::Cfg->OutputCharset()) {
+            my $ct = $r->content_type;
+            $ct =~ s/charset=.*?(;|$)/charset=$charset/i;
+            $r->content_type($ct);
         }
-        else {
-            AxKit::Apache::send_http_header($r);
+
+        if ($result_code != OK && $result_code != 200) {
+            # no caching - probably makes no sense, and will be turned off
+            # anyways, as currently only XSP pages allow to send custom 
responses
+            AxKit::Debug(4,"Sending custom response: $result_code");
+            my ($transformer, $doit) = get_output_transformer();
             if ($doit) {
-                $r->print(
-                        $transformer->( $r->pnotes('xml_string') )
-                        );
+                $r->custom_response($result_code,$transformer->($xmlstring || 
''));
             }
             else {
-                $r->print( $r->pnotes('xml_string') );
+                $r->custom_response($result_code,$xmlstring || '');
             }
+            return $result_code;
         }
-        return OK;
-    }
-    else {
-        AxKit::Debug(4, "writing xml string to cache and delivering to 
browser");
-        my $retval = eval {
-            $AxKit::Cache->write($r->pnotes('xml_string'));
-            $AxKit::Cache->deliver();
-        };
-        if (my $E = $@) {
-            if ($E->isa('Apache::AxKit::Exception::IO')) {
-                AxKit::Debug(1, "WARNING: Unable to write to AxCacheDir or 
.xmlstyle_cache");
-                AxKit::Apache::send_http_header($r);
-                $r->print( $r->pnotes('xml_string') );
-            }
-            else {
-                throw $E;
+
+        my ($transformer, $doit) = get_output_transformer();
+
+        if ($doit) {
+            $xmlstring = join('', $transformer->($xmlstring)); # hmmmmmm, not 
good
+        }
+
+        if ($AxKit::Cache->no_cache() ||
+            lc($r->dir_config('Filter')) eq 'on' ||
+            $r->method() eq 'POST') 
+        {
+            if ($AxKit::Cfg->DoGzip) {
+                AxKit::Debug(4, 'Sending gzipped xml string to browser');
+                $xmlstring = unpack($]>5.00555?"U0A*":"A*", 
Compress::Zlib::memGzip($xmlstring) );
             }
         }
         else {
-            return $retval;
+            AxKit::Debug(4, "Writing xml string to cache");
+            eval {
+                $AxKit::Cache->write($xmlstring);
+            };
+            if (my $E = $@) {
+                if ($E->isa('Apache::AxKit::Exception::IO')) {
+                    AxKit::Debug(1, "WARNING: Unable to write to AxCacheDir or 
.xmlstyle_cache");
+                }
+                else {
+                    throw $E;
+                }
+            }
         }
     }
+
+    AxKit::Debug(4, "Delivering to browser");
+    AxKit::Apache::send_http_header($r);
+    $r->print($xmlstring);
+    return OK;
 }
 
 sub prep_exception {
--- 
/mp_sie2/ci00/src/webserver/axkit/perl/apachecvs/xml-axkit/lib/Apache/AxKit/Cache.pm
        Thu Jan 23 09:35:08 2003
+++ Apache/AxKit/Cache.pm       Mon Jan 27 15:22:22 2003
@@ -197,56 +197,6 @@
     return '';
 }
 
-sub deliver {
-    my $self = shift;
-    return SERVER_ERROR if $self->{no_cache};
-    my $r = $self->{apache};
-
-    {
-        # get content-type
-        AxKit::Debug(4, "Cache: Getting content-type");
-        if (my $type = $self->get_type) {
-            AxKit::Debug(4, "Cache: setting content-type: $type");
-            $r->content_type($type);
-        }
-    }
-
-    if ($r->content_type eq 'changeme' && !$r->notes('axkit_passthru_type')) {
-        $AxKit::Cfg->AllowOutputCharset(1);
-        $r->content_type('text/html; charset=' . ($AxKit::Cfg->OutputCharset 
|| "UTF-8"));
-    }
-    elsif ($r->notes('axkit_passthru_type')) {
-        $r->content_type($AxKit::OrigType);
-    }
-
-
-    my ($transformer, $doit) = AxKit::get_output_transformer();
-
-    if ($doit) {
-        AxKit::Debug(4, "Cache: Transforming content and printing to browser");
-        $r->pnotes('xml_string',$self->read());
-        return OK; # upstream deliver_to_browser should handle the rest
-    }
-    else {
-        AxKit::Debug(4, "Cache: Sending untransformed content to browser");
-
-        # Make sure we unset PATH_INFO or wierd things can happen!
-        $ENV{PATH_INFO} = '';
-        $r->path_info('');
-
-        if ($self->{gzip} && $AxKit::Cfg->DoGzip) {
-            AxKit::Debug(4, 'Cache: Delivering gzipped output');
-            $r->filename($self->{file}.'.gz');
-        }
-        else {
-            $r->filename($self->{file});
-        }
-
-        return DECLINED;
-    }
-
-}
-
 sub reset {
     my $self = shift;
     unlink $self->{file};

Reply via email to