wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[bml] r109: revert Apache2 change

Committer: wisest-owl
revert Apache2 change
U   trunk/lib/Apache/BML.pm
Modified: trunk/lib/Apache/BML.pm
===================================================================
--- trunk/lib/Apache/BML.pm	2010-01-18 10:41:50 UTC (rev 108)
+++ trunk/lib/Apache/BML.pm	2010-01-18 11:02:13 UTC (rev 109)
@@ -19,7 +19,6 @@
 use Apache::Constants qw(:common REDIRECT HTTP_NOT_MODIFIED);
 use Apache::File ();
 use Apache::URI;
-use LJ::Request;
 use Digest::MD5;
 use File::Spec;
 BEGIN {
@@ -69,19 +68,21 @@
 
 sub handler
 {
-    my $r = $Apache::BML::r = LJ::Request->r;
+    my $r = shift;
 
+    $Apache::BML::r = $r;
+
     # determine what file we're supposed to work with:
-    my $file = Apache::BML::decide_file_and_stat();
+    my $file = Apache::BML::decide_file_and_stat($r);
 
-    # $file was stat'd by ecide_file_and_stat above, so use '_'
+    # $file was stat'd by decide_file_and_stat above, so use '_'
     unless (-e _) {
-        LJ::Request->log_error("File does not exist: $file");
+        $r->log_error("File does not exist: $file");
         return NOT_FOUND;
     }
 
     unless (-r _) {
-        LJ::Request->log_error("File permissions deny access: $file");
+        $r->log_error("File permissions deny access: $file");
         return FORBIDDEN;
     }
 
@@ -97,7 +98,7 @@
 
     # walk up directories, looking for _config.bml files, populating env
     my $dir = $file;
-    my $docroot = LJ::Request->document_root(); $docroot =~ s!/$!!;
+    my $docroot = $r->document_root(); $docroot =~ s!/$!!;
     my @dirconfs;
     my %confwant;  # file -> 1, if applicable config
 
@@ -140,7 +141,7 @@
     # wrapped in eval because Apache::FakeRequest doesn't have
     # pnotes support (as of 2004-04-26 at least)
     eval {
-        if (my $or = LJ::Request->pnotes('BMLEnvOverride')) {
+        if (my $or = $r->pnotes('BMLEnvOverride')) {
             while (my ($k, $v) = each %$or) {
                 $env->{$k} = $v;
             }
@@ -156,15 +157,15 @@
     }
 
     if (exists $env->{'HOOK-force_redirect'}) {
-        my $redirect_page = eval { $env->{'HOOK-force_redirect'}->(LJ::Request->uri); };
+        my $redirect_page = eval { $env->{'HOOK-force_redirect'}->($r->uri); };
         if (defined $redirect_page) {
-            LJ::Request->header_out(Location => $redirect_page);
+            $r->header_out(Location => $redirect_page);
             $Apache::BML::r = undef;  # no longer valid
             return REDIRECT;
         }
     }
 
-    # mod_rewrite
+    # mod_rewrite 
     if ( exists $env->{'HOOK-rewrite_filename'} ){
         eval {
             my $new_file = $env->{'HOOK-rewrite_filename'}->(req => $req, env => $env);
@@ -200,7 +201,7 @@
 
     # Read the source of the file
     unless (open F, $file) {
-        LJ::Request->log_error("Couldn't open $file for reading: $!");
+        $r->log_error("Couldn't open $file for reading: $!");
         $Apache::BML::r = undef;  # no longer valid
         return SERVER_ERROR;
     }
@@ -228,18 +229,15 @@
     # tied interface to BML::ml();
     *BMLCodeBlock::ML = *BML::ML;
 
-    my %gets  = LJ::Request->get_params;
-    my %posts = LJ::Request->post_params;
-
     # let BML code blocks see input
-    %BMLCodeBlock::GET  = ();
+    %BMLCodeBlock::GET = ();
     %BMLCodeBlock::POST = ();
     %BMLCodeBlock::FORM = ();  # whatever request method is
     my %input_target = ( GET  => [ \%BMLCodeBlock::GET  ],
                          POST => [ \%BMLCodeBlock::POST ], );
-    push @{$input_target{LJ::Request->method}}, \%BMLCodeBlock::FORM;
-    foreach my $id ([ [ %gets  ] => $input_target{'GET'}  ],
-                    [ [ %posts ] => $input_target{'POST'} ])
+    push @{$input_target{$r->method}}, \%BMLCodeBlock::FORM;
+    foreach my $id ([ [ $r->args    ] => $input_target{'GET'}  ],
+                    [ [ $r->content ] => $input_target{'POST'} ])
     {
         while (my ($k, $v) = splice @{$id->[0]}, 0, 2) {
             foreach my $dest (@{$id->[1]}) {
@@ -277,7 +275,7 @@
         return report_error($r, "<b>Error running codeblock_init_perl hook:</b><br />\n$@") if $@;
     }
 
-    my $scheme = LJ::Request->notes('bml_use_scheme') ||
+    my $scheme = $r->notes('bml_use_scheme') ||
         $env->{'ForceScheme'} ||
         $BMLCodeBlock::GET{'usescheme'} ||
         $BML::COOKIE{'BMLschemepref'};
@@ -299,7 +297,7 @@
     # now we've made the decision about what scheme to use
     # -- does a hook want to translate this into another scheme?
     if ($env->{'HOOK-scheme_translation'}) {
-        my $newscheme = eval {
+        my $newscheme = eval { 
             $env->{'HOOK-scheme_translation'}->($scheme);
         };
         $scheme = $newscheme if $newscheme;
@@ -311,8 +309,8 @@
         BML::set_scheme($scheme);
     }
 
-    my $uri = LJ::Request->uri;
-    my $path_info = LJ::Request->path_info;
+    my $uri = $r->uri;
+    my $path_info = $r->path_info;
     my $lang_scope = $uri;
     $lang_scope =~ s/$path_info$//;
     BML::set_language_scope($lang_scope);
@@ -333,11 +331,11 @@
     # force out any cookies we have set
     BML::send_cookies($req);
 
-    LJ::Request->register_cleanup(\&reset_codeblock) if $req->{'clean_package'};
+    $r->register_cleanup(\&reset_codeblock) if $req->{'clean_package'};
 
     # redirect, if set previously
     if ($req->{'location'}) {
-        LJ::Request->set_header_out(Location => $req->{'location'});
+        $r->header_out(Location => $req->{'location'});
         $Apache::BML::r = undef;  # no longer valid
         return REDIRECT;
     }
@@ -351,7 +349,7 @@
     }
     $etag = '"' . $etag . '"' if defined $etag;
 
-    my $ifnonematch = LJ::Request->header_in("If-None-Match");
+    my $ifnonematch = $r->header_in("If-None-Match");
     if (defined $ifnonematch && defined $etag && $etag eq $ifnonematch) {
         $Apache::BML::r = undef;  # no longer valid
         return HTTP_NOT_MODIFIED;
@@ -361,7 +359,7 @@
     unless ($env->{'NoHeaders'}) {
         eval {
             # this will fail while using Apache::FakeRequest, but that's okay.
-            LJ::Request->content_languages([ $rootlang ]);
+            $r->content_languages([ $rootlang ]);
         };
     }
 
@@ -373,7 +371,7 @@
 
     unless ($env->{'NoHeaders'})
     {
-        my $ims = LJ::Request->header_in("If-Modified-Since");
+        my $ims = $r->header_in("If-Modified-Since");
         if ($ims && ! $env->{'NoCache'} &&
             $ims eq $modtime_http)
         {
@@ -381,39 +379,39 @@
             return HTTP_NOT_MODIFIED;
         }
 
-        LJ::Request->content_type($content_type);
+        $r->content_type($content_type);
 
         if ($env->{'NoCache'}) {
-            LJ::Request->header_out("Cache-Control", "no-cache");
-            LJ::Request->no_cache(1);
+            $r->header_out("Cache-Control", "no-cache");
+            $r->no_cache(1);
         }
 
-        LJ::Request->header_out("Last-Modified", $modtime_http)
+        $r->header_out("Last-Modified", $modtime_http)
             if $env->{'Static'} || $req->{'want_last_modified'};
 
-        LJ::Request->header_out("Cache-Control", "private, proxy-revalidate");
-        LJ::Request->header_out("ETag", $etag) if defined $etag;
+        $r->header_out("Cache-Control", "private, proxy-revalidate");
+        $r->header_out("ETag", $etag) if defined $etag;
 
         # gzip encoding
         my $do_gzip = $env->{'DoGZIP'} && $Apache::BML::HAVE_ZLIB;
         $do_gzip = 0 if $do_gzip && $content_type !~ m!^text/html!;
-        $do_gzip = 0 if $do_gzip && LJ::Request->header_in("Accept-Encoding") !~ /gzip/;
+        $do_gzip = 0 if $do_gzip && $r->header_in("Accept-Encoding") !~ /gzip/;
         my $length = length($html);
         $do_gzip = 0 if $length < 500;
         if ($do_gzip) {
             my $pre_len = $length;
-            LJ::Request->notes("bytes_pregzip" => $pre_len);
+            $r->notes("bytes_pregzip" => $pre_len);
             $html = Compress::Zlib::memGzip($html);
             $length = length($html);
-            LJ::Request->header_out('Content-Encoding', 'gzip');
-            LJ::Request->header_out('Vary', 'Accept-Encoding');
+            $r->header_out('Content-Encoding', 'gzip');
+            $r->header_out('Vary', 'Accept-Encoding');
         }
-        LJ::Request->header_out('Content-length', $length);
+        $r->header_out('Content-length', $length);
 
-        LJ::Request->send_http_header();
+        $r->send_http_header();
     }
 
-    LJ::Request->print($html) unless $env->{'NoContent'} || LJ::Request->header_only;
+    $r->print($html) unless $env->{'NoContent'} || $r->header_only;
 
     $Apache::BML::r = undef;  # no longer valid
     return OK;
@@ -421,19 +419,20 @@
 
 sub decide_file_and_stat
 {
+    my $r = shift;
     my $file;
-    if (ref (LJ::Request->r) eq "Apache::FakeRequest") {
+    if (ref $r eq "Apache::FakeRequest") {
         # for testing.  FakeRequest's 'notes' method is busted, always returning
         # true.
-        $file = LJ::Request->filename;
+        $file = $r->filename;
         stat($file);
-    } elsif ($file = LJ::Request->notes("bml_filename")) {
+    } elsif ($file = $r->notes("bml_filename")) {
         # when another handler needs to invoke BML directly
         stat($file);
     } else {
         # normal case - $r->filename is already stat'd
-        $file = LJ::Request->filename;
-        LJ::Request->finfo;
+        $file = $r->filename;
+        $r->finfo;
     }
 
     return $file;
@@ -469,9 +468,9 @@
     my $r = shift;
     my $err = shift;
 
-    LJ::Request->content_type("text/html");
-    LJ::Request->send_http_header();
-    LJ::Request->print($err);
+    $r->content_type("text/html");
+    $r->send_http_header();
+    $r->print($err);
 
     return OK;  # TODO: something else?
 }
@@ -498,10 +497,10 @@
 
     # see which configs are denied
     my $r = $Apache::BML::r;
-    if (LJ::Request->dir_config("BML_denyconfig") && ! %DenyConfig) {
-        my $docroot = LJ::Request->document_root();
-        my $deny = LJ::Request->dir_config("BML_denyconfig");
-        $deny =~ s/(^\s+|\s+)$//g;
+    if ($r->dir_config("BML_denyconfig") && ! %DenyConfig) {
+        my $docroot = $r->document_root();
+        my $deny = $r->dir_config("BML_denyconfig");
+        $deny =~ s/^\s+//; $deny =~ s/\s+$//;
         my @denydir = split(/\s*\,\s*/, $deny);
         foreach $deny (@denydir) {
             $deny = dir_rel2abs($docroot, $deny);
@@ -783,7 +782,7 @@
                 if $req->{'lang'} eq 'debug';
             my $getter = $req->{'env'}->{'HOOK-ml_getter'};
             return "[ml_getter not defined]" unless $getter;
-            $code = LJ::Request->uri . $code
+            $code = $req->{'r'}->uri . $code
                 if rindex($code, '.', 0) == 0;
             return $getter->($req->{'lang'}, $code);
         }
@@ -1408,7 +1407,7 @@
     my $r = $Apache::BML::r;
     my $err = sub { $$error = $_[0]; return 0; };
 
-    my $size = LJ::Request->header_in("Content-length");
+    my $size = $r->header_in("Content-length");
     unless ($size) {
         return $err->("No content-length header: can't parse");
     }
@@ -1417,13 +1416,13 @@
     }
 
     my $sep;
-    unless (LJ::Request->header_in("Content-Type") =~ m!^multipart/form-data;\s*boundary=(\S+)!) {
+    unless ($r->header_in("Content-Type") =~ m!^multipart/form-data;\s*boundary=(\S+)!) {
         return $err->("[unknowntype] Unknown content type");
     }
     $sep = $1;
 
     my $content;
-    LJ::Request->read($content, $size);
+    $r->read($content, $size);
     my @lines = split(/\r\n/, $content);
     my $line = shift @lines;
     return $err->("[parse] Error parsing upload") unless $line eq "--$sep";
@@ -1471,14 +1470,14 @@
     };
 
     # size hook is optional
-    my $size = LJ::Request->header_in("Content-length");
+    my $size = $r->header_in("Content-length");
     if ($hooks->{size}) {
         $run_hook->('size', $size)
             or return 0;
     }
 
-    unless (LJ::Request->header_in("Content-Type") =~ m!^multipart/form-data;\s*boundary=(\S+)!) {
-        return $err->("No MIME boundary.  Bogus Content-type? " . LJ::Request->header_in("Content-Type"));
+    unless ($r->header_in("Content-Type") =~ m!^multipart/form-data;\s*boundary=(\S+)!) {
+        return $err->("No MIME boundary.  Bogus Content-type? " . $r->header_in("Content-Type"));
     }
     my $sep = "--$1";
     my $seplen = length($sep) + 2;  # plus \r\n
@@ -1498,7 +1497,7 @@
     while (1) {
         my $read = -1;
         if ($to_read) {
-            $read = LJ::Request->read($window,
+            $read = $r->read($window,
                              $to_read < $max_read ? $to_read : $max_read,
                              length($window));
             $to_read -= $read;
@@ -1765,7 +1764,7 @@
     # else fall back to the global one (for use in profiling/debugging)
     my $r;
     eval {
-        $r = LJ::Request->request;
+        $r = Apache->request;
     };
     $r ||= $Apache::BML::r;
     return $r;
@@ -1773,48 +1772,57 @@
 
 sub get_query_string
 {
-    return scalar(LJ::Request->args);
+    my $r = BML::get_request();
+    return scalar($r->args);
 }
 
 sub get_uri
 {
-    return LJ::Request->uri;
+    my $r = BML::get_request();
+    return $r->uri;
 }
 
 sub get_hostname
 {
-    return LJ::Request->hostname;
+    my $r = BML::get_request();
+    return $r->hostname;
 }
 
 sub get_method
 {
-    return LJ::Request->method;
+    my $r = BML::get_request();
+    return $r->method;
 }
 
 sub get_path_info
 {
-    return LJ::Request->path_info;
+    my $r = BML::get_request();
+    return $r->path_info;
 }
 
 sub get_remote_ip
 {
-    return LJ::Request->remote_ip;
+    my $r = BML::get_request();
+    return $r->connection()->remote_ip;
 }
 
 sub get_remote_host
 {
-    return LJ::Request->remote_host;
+    my $r = BML::get_request();
+    return $r->connection()->remote_host;
 }
 
 sub get_remote_user
 {
-    return LJ::Request->user;
+    my $r = BML::get_request();
+    return $r->connection()->user;
 }
 
 sub get_client_header
 {
     my $hdr = shift;
-    return LJ::Request->header_in($hdr);
+    my $r = BML::get_request();
+    return $r->header_in($hdr);
 }
 
 # <LJFUNC>
@@ -1829,7 +1837,7 @@
 sub self_link
 {
     my $newvars = shift;
-    my $link = LJ::Request->uri;
+    my $link = $Apache::BML::r->uri;
     my $form = \%BMLCodeBlock::FORM;
 
     $link .= "?";
@@ -1851,9 +1859,9 @@
     my ($code, $msg) = @_;
 
     my $r = $Apache::BML::r;
-    LJ::Request->status($code);
-    LJ::Request->content_type('text/html');
-    LJ::Request->print($msg);
+    $r->status($code);
+    $r->content_type('text/html');
+    $r->print($msg);
     finish_suppress_all();
     return;
 }
@@ -1960,8 +1968,8 @@
 {
     my ($lang, $getter) = @_;  # getter is optional
     my BML::Request $req = $Apache::BML::cur_req;
-    #my $r = BML::get_request();
-    LJ::Request->notes('langpref' => $lang);
+    my $r = BML::get_request();
+    $r->notes('langpref' => $lang);
 
     # don't rely on $req (the current BML request) being defined, as
     # we allow callers to use this interface directly from non-BML
@@ -2081,9 +2089,8 @@
     }
 
     foreach (values %{$req->{'cookies'}}) {
-        LJ::Request->add_header_out("Set-Cookie" => $_);
+        $req->{'r'}->err_headers_out->add("Set-Cookie" => $_);
     }
-
     $req->{'cookies'} = {};
     $req->{'env'}->{'SentCookies'} = 1;
 }
@@ -2246,7 +2253,7 @@
     # callers sometimes use %BML::COOKIE.
     my $r = BML::get_request();
     unless ($BML::COOKIES_PARSED) {
-        foreach (split(/;\s+/, LJ::Request->header_in("Cookie"))) {
+        foreach (split(/;\s+/, $r->header_in("Cookie"))) {
             next unless ($_ =~ /(.*)=(.*)/);
             my ($name, $value) = ($1, $2);
             my $dname  = BML::durl($name);

Tags: bml, pm, wisest-owl
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments