diff options
author | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2008-02-07 20:31:11 +0100 |
---|---|---|
committer | Arne Georg Gleditsch <argggh@lxr.linpro.no> | 2008-02-07 20:31:11 +0100 |
commit | 378a912bf79e1e5b6384b02b14919371ac0c4785 (patch) | |
tree | a7969b83c550188e093ac7e5b4aa5a6542908fd5 | |
parent | f5277f0a49bfb6eb48c27de4d644b2f9e2f94e4f (diff) |
Provisions for mod_perl use, take one.
-rw-r--r-- | cgi-bin/.htaccess | 8 | ||||
-rw-r--r-- | lib/LXRng/Cached.pm | 6 | ||||
-rw-r--r-- | lib/LXRng/Context.pm | 50 | ||||
-rw-r--r-- | lib/LXRng/Repo/Git.pm | 5 | ||||
-rw-r--r--[-rwxr-xr-x] | lib/LXRng/Web.pm (renamed from cgi-bin/lxr) | 83 | ||||
-rw-r--r-- | tmpl/header.tt2 | 13 | ||||
-rw-r--r-- | tmpl/popup_main.tt2 | 4 | ||||
-rw-r--r-- | tmpl/prefs.tt2 | 6 | ||||
-rw-r--r-- | tmpl/search_result.tt2 | 2 | ||||
-rw-r--r-- | tmpl/tree_list.tt2 | 9 | ||||
-rw-r--r-- | webroot/.htaccess | 20 | ||||
-rw-r--r-- | webroot/.static/css/lxrng.css (renamed from cgi-bin/css/lxrng.css) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/Makefile (renamed from cgi-bin/gfx/Makefile) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/close.png (renamed from cgi-bin/gfx/close.png) | bin | 802 -> 802 bytes | |||
-rw-r--r-- | webroot/.static/gfx/close.svg (renamed from cgi-bin/gfx/close.svg) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/diff.png (renamed from cgi-bin/gfx/diff.png) | bin | 605 -> 605 bytes | |||
-rw-r--r-- | webroot/.static/gfx/diff.svg (renamed from cgi-bin/gfx/diff.svg) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/left.png (renamed from cgi-bin/gfx/left.png) | bin | 585 -> 585 bytes | |||
-rw-r--r-- | webroot/.static/gfx/left.svg (renamed from cgi-bin/gfx/left.svg) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/print.png (renamed from cgi-bin/gfx/print.png) | bin | 355 -> 355 bytes | |||
-rw-r--r-- | webroot/.static/gfx/print.svg (renamed from cgi-bin/gfx/print.svg) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/right.png (renamed from cgi-bin/gfx/right.png) | bin | 586 -> 586 bytes | |||
-rw-r--r-- | webroot/.static/gfx/right.svg (renamed from cgi-bin/gfx/right.svg) | 0 | ||||
-rw-r--r-- | webroot/.static/gfx/rolldown.png (renamed from cgi-bin/gfx/rolldown.png) | bin | 536 -> 536 bytes | |||
-rw-r--r-- | webroot/.static/gfx/rolldown.svg (renamed from cgi-bin/gfx/rolldown.svg) | 0 | ||||
-rw-r--r-- | webroot/.static/js/lxrng-funcs.js (renamed from cgi-bin/js/lxrng-funcs.js) | 2 |
26 files changed, 122 insertions, 86 deletions
diff --git a/cgi-bin/.htaccess b/cgi-bin/.htaccess deleted file mode 100644 index 06615a1..0000000 --- a/cgi-bin/.htaccess +++ /dev/null @@ -1,8 +0,0 @@ -Options ExecCGI -<Files lxr> -SetHandler cgi-script -</Files> - -<Files prefs> -SetHandler cgi-script -</Files> diff --git a/lib/LXRng/Cached.pm b/lib/LXRng/Cached.pm index 9c30d82..f27d3c2 100644 --- a/lib/LXRng/Cached.pm +++ b/lib/LXRng/Cached.pm @@ -1,6 +1,8 @@ package LXRng::Cached; use strict; +use LXRng; + require Exporter; use vars qw($memcached @ISA @EXPORT); @ISA = qw(Exporter); @@ -12,9 +14,11 @@ BEGIN { require Digest::SHA1; }; if ($@ eq '') { + my $nspace = substr(Digest::SHA1::sha1_hex($LXRng::ROOT), 0, 8); + $memcached = Cache::Memcached->new({ 'servers' => ['127.0.0.1:11211'], - 'namespace' => 'lxrng'}); + 'namespace' => 'lxrng:$nspace'}); $memcached = undef unless ($memcached->set(':caching' => 1)) } diff --git a/lib/LXRng/Context.pm b/lib/LXRng/Context.pm index 93edc6f..585cb57 100644 --- a/lib/LXRng/Context.pm +++ b/lib/LXRng/Context.pm @@ -8,12 +8,21 @@ sub new { $self = bless({}, $self); + my $config = $self->read_config(); + if ($args{'query'}) { - # CGI::Simple appears to confuse '' with undef for SCRIPT_NAME. - # $$self{'req_url'} = $args{'query'}->url(); - $$self{'req_url'} = $args{'query'}->url(-base => 1); - $$self{'req_url'} =~ s,/*$,/,; - $ENV{'SCRIPT_NAME'} =~ m,^/?(.*), and $$self{'req_url'} .= $1; + # Argle. Both CGI and CGI::Simple seem to botch this up, in + # different ways. CGI breaks if SCRIPT_NAME contains regex + # metachars, and CGI::Simple does funny things if SCRIPT_NAME + # is the empty string. Do it by hand... + my $host = 'http'.($ENV{'HTTPS'} eq 'ON' ? 's' : '').'://'. + $ENV{'SERVER_NAME'}. + ($ENV{'SERVER_PORT'} == ($ENV{'HTTPS'} eq 'ON' ? 443 : 80) + ? '' : ':'.$ENV{'SERVER_PORT'}); + my $path = $ENV{'REQUEST_URI'}; + $path =~ s/\?.*//; + $path =~ s,/+,/,g; + $$self{'req_url'} = $host.$path; foreach my $p ($args{'query'}->param) { $$self{'params'}{$p} = [$args{'query'}->param($p)]; @@ -23,7 +32,17 @@ sub new { $$self{'prefs'} = { map { /^(.*?)(?:=(.*)|)$/; ($1 => $2) } @prefs }; } - @$self{'tree', 'path'} = $args{'query'}->path_info =~ m,([^/]+)/*(.*),; + foreach my $tree (keys %$config) { + my $base = $$config{$tree}{'base_url'}; + $base =~ s,^https?://[^/]+,,; + $base =~ s,/*$,/,; + + if ($path =~ m,^\Q$base\E(\Q$tree\E|)([+][^/]+|)(?:$|/)(.*),) { + @$self{'tree', 'path'} = ($1.$2, $3); + last; + } + } + $$self{'tree'} = $args{'query'}->param('tree') if $args{'query'}->param('tree'); } @@ -31,17 +50,16 @@ sub new { $$self{'tree'} = $args{'tree'}; } - if ($$self{'tree'} =~ s/[+](.*)$//) { + if ($$self{'tree'} =~ s/[+]([^+]*)$//) { $$self{'release'} = $1 if $1 ne '*'; } - if ($$self{'tree'}) { + if ($$self{'tree'} and $$self{'tree'} !~ /^[+]/) { my $tree = $$self{'tree'}; - my @config = $self->read_config(); die("No config for tree $tree") - unless ref($config[0]) eq 'HASH' and exists($config[0]{$tree}); + unless exists($$config{$tree}); - $$self{'config'} = $config[0]{$tree}; + $$self{'config'} = $$config{$tree}; $$self{'config'}{'usage'} ||= $$self{'config'}{'index'}; } @@ -69,7 +87,9 @@ sub read_config { join("", <$cfgfile>)); die($@) if $@; - return @config; + die("Bad configuration file format\n") + unless @config == 1 and ref($config[0]) eq 'HASH'; + return $config[0]; } else { die("Couldn't open configuration file \"$confpath\"."); @@ -160,12 +180,12 @@ sub base_url { $base = $$self{'req_url'}; } - $base =~ s,/+$,,; + $base =~ s,/*$,/,; return $base if $notree; - $base .= '/'.$self->vtree.'/'; - $base =~ s,//+$,/,; + $base .= $self->vtree.'/'; + $base =~ s,/+$,/,; return $base; } diff --git a/lib/LXRng/Repo/Git.pm b/lib/LXRng/Repo/Git.pm index 261f595..472c4c9 100644 --- a/lib/LXRng/Repo/Git.pm +++ b/lib/LXRng/Repo/Git.pm @@ -13,9 +13,10 @@ sub _git_cmd { my $git; my $pid = open($git, "-|"); die $! unless defined $pid; + # warn("git --git-dir=".$$self{'root'}." $cmd @args"); + if ($pid == 0) { - $ENV{'GIT_DIR'} = $$self{'root'}; - exec('git', $cmd, @args); + exec('git', '--git-dir='.$$self{'root'}, $cmd, @args); warn $!; kill(9, $$); } diff --git a/cgi-bin/lxr b/lib/LXRng/Web.pm index b134738..3f8fb04 100755..100644 --- a/cgi-bin/lxr +++ b/lib/LXRng/Web.pm @@ -1,14 +1,8 @@ -#!/usr/bin/perl +package LXRng::Web; use strict; -use FindBin; -use lib "$FindBin::Bin/../lib"; - -use CGI::Carp qw(fatalsToBrowser); -use IO::Handle; - -use LXRng ROOT => "$FindBin::Bin/.."; +use LXRng; use LXRng::Context; use LXRng::Lang; use LXRng::Parse::Simple; @@ -17,9 +11,9 @@ use LXRng::Markup::Dir; use Subst::Complex; use Template; +use IO::Handle; use Digest::SHA1 qw(sha1_hex); use CGI::Ajax; -use CGI::Simple qw(-newstyle_urls); use File::Temp qw(tempdir tempfile); use POSIX qw(waitpid); @@ -27,8 +21,7 @@ use constant PDF_LINELEN => 95; use constant PDF_CHARPTS => 6.6; use vars qw($has_gzip_io); -eval { require PerlIO::gzip; $has_gzip_io = 1; }; - +# eval { require PerlIO::gzip; $has_gzip_io = 1; }; # Return 1 if gzip compression of html is desired. @@ -126,8 +119,11 @@ sub print_markedup_file { sub print_tree_list { my ($context, $template) = @_; + my $base = $context->base_url(1); + $base =~ s,[+]trees/?$,,; $template->process('tree_list.tt2', - {'context' => $context}) + {'context' => $context, + 'base_url' => $base}) or die $template->error(); } @@ -421,7 +417,7 @@ sub handle_ajax_request { my ($query, $context, $template) = @_; my $gzip = do_compress_response($query); - $query->no_cache(1); + # $query->no_cache(1); FIXME -- not available with CGI.pm. print($query->header(-type => 'text/html', -charset => 'utf-8', -cache-control => 'no-store, no-cache, must-revalidate', @@ -472,18 +468,15 @@ sub handle_preferences { -cookie => $lxr_prefs)); my %template_args; - if (defined($context->param('return')) and $context->config) { - $template_args{'return'} = - $context->base_url.$query->param('return'); + if (defined($context->param('return'))) { + $template_args{'return'} = $query->param('return'); } else { - my $url = $query->url(-full => 1, -path => 1); - $url =~ s,/[+ ]prefs\b.*,/,; - $template_args{'return'} = $url; + $template_args{'return'} = $context->base_url(1); } $template->process('prefs_set.tt2', - \%template_args) + \%template_args) or die $template->error(); } else { @@ -494,8 +487,12 @@ sub handle_preferences { $nav = 'is_'.$context->prefs->{'navmethod'} if $context->prefs and $context->prefs->{'navmethod'} ne ''; + my $ret = $context->base_url(); + $ret =~ s,[+]prefs/?,,; + $ret .= $query->param('return') if $query->param('return'); + $template->process('prefs.tt2', - {'return' => $query->param('return'), + {'return' => $ret, $nav => 1}) or die $template->error(); } @@ -701,33 +698,33 @@ sub generate_pdf { } -# Initial request dispatch. - -my $query = CGI::Simple->new(); -my $context = LXRng::Context->new('query' => $query); -my $template = Template->new({'INCLUDE_PATH' => $LXRng::ROOT.'/tmpl/'}); +sub handle { + my ($self, $query) = @_; + my $context = LXRng::Context->new('query' => $query); + my $template = Template->new({'INCLUDE_PATH' => $LXRng::ROOT.'/tmpl/'}); -if ($context->param('fname')) { - handle_ajax_request($query, $context, $template); -} -else { - if ($context->path =~ /^[+ ]prefs$/) { - handle_preferences($query, $context, $template); - } - elsif ($context->path =~ /^[+ ]print=(.*)/) { - generate_pdf($query, $context, $template, $1); + if ($context->param('fname')) { + handle_ajax_request($query, $context, $template); } - else { - if ($context->path =~ - /^[+ ](search|code|ident|file|text|ambig)(?:=(.*)|)/) - { - search_result($context, $template, $query, - search($context, $template, $1, $2)); - $context->path(''); + else { + if ($context->path =~ /^[+ ]prefs$/) { + handle_preferences($query, $context, $template); + } + elsif ($context->path =~ /^[+ ]print=(.*)/) { + generate_pdf($query, $context, $template, $1); } else { - source($context, $template, $query); + if ($context->path =~ + /^[+ ](search|code|ident|file|text|ambig)(?:=(.*)|)/) + { + search_result($context, $template, $query, + search($context, $template, $1, $2)); + $context->path(''); + } + else { + source($context, $template, $query); + } } } } diff --git a/tmpl/header.tt2 b/tmpl/header.tt2 index 78be13f..2932823 100644 --- a/tmpl/header.tt2 +++ b/tmpl/header.tt2 @@ -15,6 +15,7 @@ document.write('<base href="' + base + '">'); } else { + document.write('<base href="[% base_url %]">'); document.write('<meta http-equiv="Refresh" content="1;+trees">'); use_ajax_navigation = 0; } @@ -23,8 +24,8 @@ [% IF !is_ajax %] <base href="[% base_url %]"> [% END %] - <script type="text/javascript" src="../../js/lxrng-funcs.js"></script> - <link rel="stylesheet" href="../../css/lxrng.css" type="text/css" title="LXRng"> + <script type="text/javascript" src="../.static/js/lxrng-funcs.js"></script> + <link rel="stylesheet" href="../.static/css/lxrng.css" type="text/css" title="LXRng"> [% javascript %] @@ -51,12 +52,12 @@ %]<a href="[% elem.path %]">[% elem.node %]</a>[% END %] </span> - <img src="../../gfx/rolldown.png" alt="History"> + <img src="../.static/gfx/rolldown.png" alt="History"> <span id="lxr_print" [% IF is_ajax || node.name.match('/$') %]style="display: none;"[% END %]> <form action="+print=[% node.name %]" method="post" id="print_form"> <button type="submit" class="print"> - <img src="../../gfx/print.png" alt="Print"> + <img src="../.static/gfx/print.png" alt="Print"> </button> </form> </span> @@ -66,7 +67,7 @@ <span class="lxr_version"> <a [% IF is_ajax %]href="#" onclick="return previous_version();"[% ELSE %] href="../[% context.tree %]+[% ver_prev %]/[% node.name %]"[% END %]> - <img src="../../gfx/left.png" alt="<<"></a> + <img src="../.static/gfx/left.png" alt="<<"></a> <form action="[% node.name %]" method="get"> <span id="ver_select"> [% INCLUDE release_select.tt2, context = context %] @@ -74,7 +75,7 @@ </form> <a [% IF is_ajax %]href="#" onclick="return next_version();"[% ELSE %] href="../[% context.tree %]+[% ver_next %]/[% node.name %]"[% END %]> - <img src="../../gfx/right.png" alt=">>"></a> + <img src="../.static/gfx/right.png" alt=">>"></a> </span> <span class="lxr_search"> diff --git a/tmpl/popup_main.tt2 b/tmpl/popup_main.tt2 index 11cfc73..e753088 100644 --- a/tmpl/popup_main.tt2 +++ b/tmpl/popup_main.tt2 @@ -5,8 +5,8 @@ <base href="[% base_url %]"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <script type="text/javascript" src="../../js/lxrng-funcs.js"></script> - <link rel="stylesheet" href="../../css/lxrng.css" type="text/css" title="LXRng"> + <script type="text/javascript" src="../.static/js/lxrng-funcs.js"></script> + <link rel="stylesheet" href="../.static/css/lxrng.css" type="text/css" title="LXRng"> <script type="text/javascript"> var use_ajax_navigation=[% IF is_ajax %]1[% ELSE %]0[% END %]; diff --git a/tmpl/prefs.tt2 b/tmpl/prefs.tt2 index a7fc223..a92061d 100644 --- a/tmpl/prefs.tt2 +++ b/tmpl/prefs.tt2 @@ -3,8 +3,8 @@ <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <script type="text/javascript" src="../../js/lxrng-funcs.js"></script> - <link rel="stylesheet" href="../../css/lxrng.css" type="text/css" title="LXRng"> + <script type="text/javascript" src="../.static/js/lxrng-funcs.js"></script> + <link rel="stylesheet" href="../.static/css/lxrng.css" type="text/css" title="LXRng"> <title id="title">LXR Preferences</title> </head> @@ -19,7 +19,7 @@ </span> <div class="lxr_menu"> - <span class="lxr_prefs"><a href="./[% return %]">Back</a></span> + <span class="lxr_prefs"><a href="[% return %]">Back</a></span> </div> <div class="headingbottom"></div> </div> diff --git a/tmpl/search_result.tt2 b/tmpl/search_result.tt2 index cc2af1c..7ba14f9 100644 --- a/tmpl/search_result.tt2 +++ b/tmpl/search_result.tt2 @@ -1,6 +1,6 @@ <span class="close-button"> <a href="#" onclick="return [% IF navtarget %]window.close();[% ELSE %]hide_search();[% END %]"> -<img border="0" src="../../gfx/close.png" alt="X"></a> +<img border="0" src="../.static/gfx/close.png" alt="X"></a> </span> [% IF search_type == "code" or (code_res and code_res.idents.0) %] diff --git a/tmpl/tree_list.tt2 b/tmpl/tree_list.tt2 index deb0237..ecbc50a 100644 --- a/tmpl/tree_list.tt2 +++ b/tmpl/tree_list.tt2 @@ -3,8 +3,9 @@ <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> - <script type="text/javascript" src="../js/lxrng-funcs.js"></script> - <link rel="stylesheet" href="../css/lxrng.css" type="text/css" title="LXRng"> + <base href="[% base_url %]"> + <script type="text/javascript" src=".static/js/lxrng-funcs.js"></script> + <link rel="stylesheet" href=".static/css/lxrng.css" type="text/css" title="LXRng"> <title id="title">LXR Inventory</title> </head> @@ -14,13 +15,13 @@ <div class="headingtop"></div> <span class="lxr_title"> - <span class="lxr_l">l</span><span class="lxr_x">x</span><span class="lxr_r">r</span> + <span class="lxr_logo">LXR</span> Inventory for this LXRng site </span> <div class="lxr_menu"> <span class="lxr_prefs"> - <a href="+trees/+prefs?return=..">Prefs</a> + <a href="+trees/+prefs">Prefs</a> </span> </div> <div class="headingbottom"></div> diff --git a/webroot/.htaccess b/webroot/.htaccess new file mode 100644 index 0000000..2c850e5 --- /dev/null +++ b/webroot/.htaccess @@ -0,0 +1,20 @@ +Options ExecCGI + + +<IfModule mod_perl.c> + PerlModule LXRng::ModPerl; + + <Files *> + SetHandler perl-script + PerlResponseHandler LXRng::ModPerl + </Files> +</IfModule> + + +<Files robots.txt> + SetHandler send-as-is +</Files> + +<Files favicon.ico> + SetHandler send-as-is +</Files> diff --git a/cgi-bin/css/lxrng.css b/webroot/.static/css/lxrng.css index f5d84c0..f5d84c0 100644 --- a/cgi-bin/css/lxrng.css +++ b/webroot/.static/css/lxrng.css diff --git a/cgi-bin/gfx/Makefile b/webroot/.static/gfx/Makefile index bef9f65..bef9f65 100644 --- a/cgi-bin/gfx/Makefile +++ b/webroot/.static/gfx/Makefile diff --git a/cgi-bin/gfx/close.png b/webroot/.static/gfx/close.png Binary files differindex cd4178f..cd4178f 100644 --- a/cgi-bin/gfx/close.png +++ b/webroot/.static/gfx/close.png diff --git a/cgi-bin/gfx/close.svg b/webroot/.static/gfx/close.svg index 2207f0f..2207f0f 100644 --- a/cgi-bin/gfx/close.svg +++ b/webroot/.static/gfx/close.svg diff --git a/cgi-bin/gfx/diff.png b/webroot/.static/gfx/diff.png Binary files differindex 73edeca..73edeca 100644 --- a/cgi-bin/gfx/diff.png +++ b/webroot/.static/gfx/diff.png diff --git a/cgi-bin/gfx/diff.svg b/webroot/.static/gfx/diff.svg index 46290d3..46290d3 100644 --- a/cgi-bin/gfx/diff.svg +++ b/webroot/.static/gfx/diff.svg diff --git a/cgi-bin/gfx/left.png b/webroot/.static/gfx/left.png Binary files differindex b01b78c..b01b78c 100644 --- a/cgi-bin/gfx/left.png +++ b/webroot/.static/gfx/left.png diff --git a/cgi-bin/gfx/left.svg b/webroot/.static/gfx/left.svg index 4a3b1df..4a3b1df 100644 --- a/cgi-bin/gfx/left.svg +++ b/webroot/.static/gfx/left.svg diff --git a/cgi-bin/gfx/print.png b/webroot/.static/gfx/print.png Binary files differindex 4e56c0e..4e56c0e 100644 --- a/cgi-bin/gfx/print.png +++ b/webroot/.static/gfx/print.png diff --git a/cgi-bin/gfx/print.svg b/webroot/.static/gfx/print.svg index b981609..b981609 100644 --- a/cgi-bin/gfx/print.svg +++ b/webroot/.static/gfx/print.svg diff --git a/cgi-bin/gfx/right.png b/webroot/.static/gfx/right.png Binary files differindex 439fe13..439fe13 100644 --- a/cgi-bin/gfx/right.png +++ b/webroot/.static/gfx/right.png diff --git a/cgi-bin/gfx/right.svg b/webroot/.static/gfx/right.svg index 07e8941..07e8941 100644 --- a/cgi-bin/gfx/right.svg +++ b/webroot/.static/gfx/right.svg diff --git a/cgi-bin/gfx/rolldown.png b/webroot/.static/gfx/rolldown.png Binary files differindex a2a15ca..a2a15ca 100644 --- a/cgi-bin/gfx/rolldown.png +++ b/webroot/.static/gfx/rolldown.png diff --git a/cgi-bin/gfx/rolldown.svg b/webroot/.static/gfx/rolldown.svg index 85697fb..85697fb 100644 --- a/cgi-bin/gfx/rolldown.svg +++ b/webroot/.static/gfx/rolldown.svg diff --git a/cgi-bin/js/lxrng-funcs.js b/webroot/.static/js/lxrng-funcs.js index fdd9b43..0a06da6 100644 --- a/cgi-bin/js/lxrng-funcs.js +++ b/webroot/.static/js/lxrng-funcs.js @@ -89,7 +89,7 @@ function ajax_jumpto_line() { function ajax_prefs() { if (use_ajax_navigation) { - var full_path = location.href.split(/#/)[0]; + var full_path = location.href.match(/(.*?)\/*#/)[1]; full_path = full_path + '/' + loaded_tree; if (loaded_ver) { full_path = full_path + '+' + loaded_ver; |